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 <cstdio>
#include <algorithm>
#include <vector>
#include <sstream>
#include <cmath>
#include <queue>

using namespace std;

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){
			while(true){
			}
			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<vector>
using namespace std;
typedef unsigned long long ull; 

class AOJ0186{
private:
  int q1,b,c1,c2,q2;
public:

  AOJ0186(int a,int b,int c,int d,int f):q1(a),b(b),c1(c),c2(d),q2(f){}
  ~AOJ0186(){}


  void run(){
    int aizu_meet,meet;

    bool ok = false;
    int preb = b;
    
    for(int i=q2;i>=1;i--){
      aizu_meet = meet = 0,b = preb;
      if(i*c1 > b)continue;
      aizu_meet = i;
      b -= (c1*i);
      meet = b/c2;
      //cout << "i =" << i << endl;
      //cout << aizu_meet << ' ' << meet << ", b = " << b << endl;
      if(aizu_meet+meet < q1)continue;
      if(aizu_meet == 0)continue;
      ok = true;
      cout << aizu_meet << ' ' << meet << endl;
      //cout << "i = " << i << endl;

      break;
    }
 if(!ok)cout << "NA" << endl;


   


  }


};

int main(){
  int q;
  while(true){
    cin >> q;
      if(q == 0)break;
    int B,c,cc,qq;
    cin >> B >> c >> cc >> qq;
    AOJ0186 ans = AOJ0186(q,B,c,cc,qq);
    ans.run();


  }
  return 0;
}

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

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

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

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

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

	cin >> q1;

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

		x = q2;

		while (c1 * x + c2 * (q1 - x) > b || c1 * x > b)
			x--;

		if (x <= 0)
			cout << "NA" << endl;
		else {
			y = q1 - x;

			while (c1 * x + c2 * y < b)
				y++;

			if (c1 * x + c2 * y > b)
				y--;

			cout << x << " " << y << endl;
		}

		cin >> q1;
	}

	return 0;
}

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

int main(){
  int want, money, c1, c2, meat;
  
  while(cin >> want){
    if(want == 0) break;
    cin >> money >> c1 >> c2 >> meat;
    
    int ans1 = money / c1;
    if(ans1 > meat){
      ans1 = meat;
    }
    int budget = ans1 * c1; // テ、ツコツ暗ァツョツ療・ツ??」ツ?ァテ」ツ?ァテ」ツ?催」ツつ凝」ツ??」ツ?妥・ツ慊ーテゥツカツ湘」ツつ津ィツイツキテ」ツ?」テ」ツ?淌・ツ?、テヲツョツオ
    //cout << budget << endl;      
    
    int ans2 = 0;
   
    int sale = money - budget;
    
    while(1){
      
      if(ans1 + ans2 >= want) break;
      if(ans1 == 0) break;
      int buy_normal = sale / c2;
      ans2 += buy_normal; //テ・ツ慊ーテゥツカツ湘」ツつ津・ツ」ツイテ」ツ?」テ」ツ?ヲテ」ツ?ァテ」ツ?催」ツ?淌」ツ?甘ゥツ?妥」ツ?ァテ」ツ?ァテ」ツ?催」ツつ凝」ツ??」ツ?妥ゥツカツ湘ィツつ嘉」ツつ津ィツイツキテ」ツ??テ・ツ?凝ヲツ閉ーテッツシツ?
      if(ans1 + ans2 >= want) break;
      ans1--; // テ、ツクツ?」ツ?、テ・ツ」ツイテ」ツつ?
      sale += c1; // テ・ツ」ツイテ」ツ?」テ」ツ?ヲティツイツーテ」ツ?」テ」ツ?淌」ツ?甘ゥツ??
      //cout << sale << ' ';
      budget -= c1; // テ、ツコツ暗ァツョツ療・ツ??」ツ?ォテ・ツ渉偲」ツ?セテ」ツつ嘉」ツ?崚」ツつ凝」ツつ暗」ツ??」ツ?ォテ・ツシツ陛」ツ??
     
      //cout << '-' << buy_normal*c2;
      sale -= buy_normal * c2;     
      //cout << '=' << sale << endl;
      budget += ans2 * c2;
      //cout << "ans1 = " << ans1 << ", ans2 = " << ans2 << endl;
    }
    if(ans1 == 0) cout << "NA" << endl;
    
    else cout << ans1 << ' ' << ans2 << endl;
  }
  return 0;
}

C++: #define _USE_MATH_DEFINES
#include<cstdio>
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<cmath>
#include<climits>
using namespace std;

int main(){
	int Q1, B, C1, C2, Q2;
	while(cin >> Q1 >> B >> C1 >> C2 >> Q2, Q1){
	
		int ans1 = -1, ans2;
		for(int i = 1; i <= Q2; i++){
			int common = (B - i*C1)/C2;
			if(B - i*C1 < 0) break;
			if(i + common >= Q1) ans1 = i, ans2 = common;
			//printf("%d, %d\n", i, common);
		}
		if(ans1 == -1) puts("\tNA");
		else printf("\t%d %d\n", ans1, ans2);
	}
	return 0;
}

C++: #include <stdio.h>

int max(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);

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

C++: #include <iostream>

using namespace std;

void solve()
{
	long long int q1, b, c1, c2, q2;
	while(cin >> q1, q1)
	{
		cin >> b >> c1 >>  c2 >>  q2;
		if(b / c1 > q1 && b / c1 <= q2)
		{
			cout << b / c1 << " " << 0 << endl;
		}
		else
		{
			long long int chicken = (q1 * c1 - b) / (c1 - c2) + 1;
			long long int aizu_chicken = q1 - chicken;
			bool flag = true;
			if(aizu_chicken <= 0)
			{
				cout << "NA" << endl;
				flag = false;
			}
			if(flag)
			{
				if(aizu_chicken > q2)
				{
					aizu_chicken = q2;
					chicken = (b - c1 * q2) / c2;
				}
				cout << aizu_chicken << " " << chicken << endl;
			}
		}
	}
}

int main()
{
	solve();
	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 >> B >> C1 >> C2 >> Q2) {
    if(Q1 == 0) break;
    
    if(B/C1 == 0) {
      failed(); continue;
    }
    
    int AizuCh = min(B/C1, Q2);
    int NCh = 0;
    for(;;) {
      
      if(AizuCh + NCh >= Q1) {
        cout << AizuCh << ' ' << NCh << endl; break;
      }
      else if(B - (NCh+1)*C2 - AizuCh*C1 >= 0) {
        NCh += (B - NCh*C2 - AizuCh*C1)/C2;
      }
      else if(B - (NCh+1)*C2 - (AizuCh-1)*C1 >= 0) {
        NCh ++, AizuCh --;
      }
      
      if(AizuCh <= 0) { failed(); break; }
    }
    
  }
  
  return 0;
}