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;
int main(){
	int q1, b, c1, c2, q2;
	while(cin >> q1, q1) {
		cin >> b >> c1 >> c2 >> q2;
		int k1, k2;
		bool f = 1;
		k1 = b/c1;
		if(k1>q2) k1 = q2;
		for(int i = k1; i>0; --i) {
			k2 = (b-c1*i)/c2;
			if(i+k2>=q1) {
				cout << i << " " << k2 << endl;
				f = 0;
				break;
			}
		}
		if(f) cout << "NA" << endl;
	}
}

C++: #define _USE_MATH_DEFINES
#define INF 10000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>

using namespace std;

typedef long long ll;
typedef pair<int,string> P;

static const double eps = 1e-8;

int main(){
	int q1;
	while(~scanf("%d",&q1)){
		if(q1==0) break;
		int b,c1,c2,q2;
		//1:aize chiken 2:normal chiken
		scanf("%d %d %d %d",&b,&c1,&c2,&q2);
		for(int i=q2;i>=1;i--){
			int cost = i*c1;

			int ub = 1000000;
			int lb = 0;

			for(int j=0;j<20;j++){
				int md = (ub+lb)/2;
				if(cost + md*c2 <=b) lb = md;
				else ub = md;
			}

			if(lb+i >= q1 && cost + lb*c2 <=b){
				printf("%d %d\n",i,lb);
				goto next;
			}
		}
		printf("NA\n");
next:;
	}
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> PI;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define MP make_pair
#define PB push_back

ll q1,b,c1,c2,q2;

main(){
  while(cin>>q1,q1){
    cin>>b>>c1>>c2>>q2;

    if(c1<=c2){
      ll aizu=b/c1,n=0;
      b-=aizu*c1;
      if(aizu>q2){
        b+=(aizu-q2)*c1;
        aizu=q2;
        n=b/c2;
      }
      if(aizu+n<q1 || aizu<1){
        puts("NA");
        goto END;
      }
      cout<<aizu<<" "<<n;
    }else{
      if(b<c1){
        puts("NA");
        goto END;
      }
      ll aizu=1,n=(b-c1)/c2;
      b-=c1+n*c2;
      if(aizu+n<q1){
        puts("NA");
        goto END;
      }

      while(aizu+n>=q1 && aizu<=q2 && n>=0){
        while(b<c1){
          n--;
          b+=c2;
        }
        ++aizu;
        b-=c1;
      }

      --aizu;
      b+=c1;
      n+=b/c2;
      if(aizu<1 || aizu+n<q1 || aizu>q2 || n<0){
        puts("NA");
      }else{
        cout<<aizu<<" "<<n<<endl;
      }
    }
END:;
  }
}

C++: #include<iostream>
using namespace std;
main(){
  int max,min,mid;
  int q1,q2,b,c1,c2;
  int aizumoney,sosomoney,sosonum;
  while(1){
    cin>>q1;
    if(q1==0)break;
    cin>>b>>c1>>c2>>q2;
    //会津地鶏二分探索
    min=0;
    max=q2;
    while(min<=max){
      mid=(max+min)/2;
      aizumoney=mid*c1;
      sosomoney=b-aizumoney;
      sosonum=sosomoney/c2;
      // cout<<min<<" "<<max<<" "<<mid<<" "<<aizumoney<<" "<<sosomoney<<" "<<sosonum<<endl;
      if(mid+sosonum>=q1&&mid>0&&sosonum>=0&&sosomoney>=0||mid<=0){
	//cout<<"OK"<<endl;
	min=mid+1;
      }
      else{
	//cout<<"NG"<<endl;
	max=mid-1;
      }
    }
    mid=(max+min)/2;
    aizumoney=mid*c1;
    sosomoney=b-aizumoney;
    sosonum=sosomoney/c2; 
    //cout<<min<<" "<<max<<" "<<mid<<" "<<aizumoney<<" "<<sosomoney<<" "<<sosonum<<endl;
    if(mid+sosonum>=q1&&mid>0&&sosonum>=0&&sosomoney>=0){
      cout<<mid<<" "<<sosonum<<endl;
    }
    else{
      cout<<"NA"<<endl;
    }
  }
}

C++: #include<vector>
#include<list>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i,j;
  int a,b,c,d,e;
  for(;;){
    cin>>a;
    if(a==0)
      break;
    cin>>b>>c>>d>>e;
    if(c*e>b){
      if(b/c+(b-b/c*c)/d<a){
	i=b/c;
	j=a-i;
	while(i>0&&i*c+j*d>b){
	  i--;
	  j++;
	}
	if(i)
	  cout<<i<<" "<<j<<endl;
	else
	  cout<<"NA"<<endl;
      }else{
	if(b/c)
	  cout<<b/c<<" "<<(b-b/c*c)/d<<endl;
	else
	  cout<<"NA"<<endl;
      }
    }else{
      if(e+(b-c*e)/d<a){
	i=e;
	j=a-i;
	while(i>0&&i*c+j*d>b){
	  i--;
	  j++;
	}
	if(i)
	  cout<<i<<" "<<j<<endl;
	else
	  cout<<"NA"<<endl;
      }else{
	if(e)
	  cout<<e<<" "<<(b-c*e)/d<<endl;
	else
	  cout<<"NA"<<endl;
      }
    }
  }
  return 0;
}

C++: #include <iostream>

using namespace std;

int q1,b,c1,c2,q2;

int check(int x){
	int y=(b-c1*x)/c2;
	if(b-c1*x<0) return -1; //y>=0ツづづ按つ「ツづつィツつゥツつオツつ「
	if(q1>(x+y)) return -1;
	if(q2<x) return -1;
	if(y<0) return -1;
	return y;
}

int main(){
	int x,y;
	while(1){
		scanf("%d",&q1);if(q1==0) return 0;
		scanf("%d %d %d %d",&b,&c1,&c2,&q2);
		for(x=q2;x>0;x--){
			if((y=check(x))!=-1){
				printf("%d %d\n",x,y);
			}
		}
		if(x==0)puts("NA");
	}
	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;
    
    stringstream ss; ss << "Q: " << Q1 << " B: " << B << " C1: " << C1 << " C2: " << C2 << " Q2: " << Q2;
    
    assert(Q2 >= 1 && ss.str());
    
    /*
    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>
using namespace std;
 
int main(){
	long long int q1,b,c1,c2,q2,now;
 
	while(cin >> q1 && q1){
 
		cin >> b >> c1 >> c2 >> q2;
 
		/*ツ全ツづ地ツ鶏ツづ可シツ津ィ*/
		now = q2*c1;
 
		/*ツ必ツ要ツ湘ーツ個渉づーツ鳴楪つスツつキツづヲツつ、ツづ可地ツ鶏ツづ個青板づーツ陳イツ静淞つオツづつ「ツつュ*/
		while(now>b){
			now -= c1;
			q2--;
		}
		
		while(q2+(b-now)/c2 < q1 && q2 > 0){
			now -= c1;
			q2--;
		}
 
		if(q2>0){
			cout << q2 << " " << (b-now)/c2 << endl;
		}else{
			cout << "NA" << endl;
		}
	}
}