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  q1,b,q2,ans;
int c1,c2;
int L,R,M;

int  calcB(int A){
  int money = b-A*c1;
  if(money>=0)return money/c2;
  else return -1000;
}

  
bool check(int x){
  int A,B;
  A=x;
  B=calcB(A);
  if(B>=0&&A>0&&A+B>=q1)return true;
  else return false;
}

int main(){
  while(cin>>q1){
    ans=-1;
    if(q1==0)break;
    cin>>b>>c1>>c2>>q2;

    L=1;
    R=q2;
    M=(L+R)/2;

    while(L<=R){
      if(check(M)&&!check(M+1)){
	break;
      }else if(check(M)){
	L=M+1;
	M=(L+R)/2;
      }else{
	R=M-1;
	M=(L+R)/2;
      }
	
    }


    if(check(M)&&check(M+1)==false  || (M==q2&&check(M))){
      
      cout<<M<<' '<<calcB(M)<<endl;
    } else cout<<"NA"<<endl;
    
  }
  return 0;
}

C++: #include <iostream>
#include <sstream>
#include <vector>
#include <list>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

int main() {
    int q1, b, c1, c2, q2;
    while ( cin >> q1 && q1 ) {
        cin >> b >> c1 >> c2 >> q2;
        bool flag2 = true;
        for ( int i = q2; i >= 1; -- i ) {
            bool flag = false;
            int t = 0;
            for ( int j = 0; i * c1 + j * c2 <= b; ++ j ) {
                if ( i + j >= q1 ) {
                    t = j;
                    flag = true;
                }
            }
            if ( flag ) {
                cout << i << " " << t << endl;
                flag2 = false;
                break;
            }
        }
        if ( flag2 ) {
            cout << "NA" << endl;
        }
    }
    return 0;
}

C++: #include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip> 
#include <complex> 
#include <string>
#include <vector> 
#include <list>
#include <deque> 
#include <stack> 
#include <queue> 
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm> 
#include <numeric> 
#include <typeinfo> 
#include <cstdio>
#include <cstdlib> 
#include <cstring>
#include <cmath>
#include <climits> 
#include <ctime>
using namespace std;

//ツ可コツ古?q1ツ、ツ予ツ算 bツ、ツつアツづ個つィツ禿キツ可ョツつウツづアツづ?づ個嘉ッツ津δ地ツ鶏100ツグツδ可δ?づ個値ツ段 c1ツ、ツづ督づつつ、 ツづ個鶏ツ禿キ100ツグツδ可δ?づ個値ツ段 c2ツ、ツ嘉ッツ津δ地ツ鶏ツづーツ暗ェツ人ツつェツ板δつヲツづゥツ療環づ個湘」ツ古?q2 
//q1 b c1 c2 q2
int q1,b,c1,c2,q2;
int main(void){
	while(1){
		cin >> q1;
		if(q1==0)break;
		cin >> b >> c1 >> c2 >> q2;
		int ic=0;
		while(b>=c1 && ic<q2){
			ic++;
			b-=c1;
		}
		int nc=0;
		while(b>=c2){
			nc++;
			b-=c2;
		}
		while(ic+nc<q1){
			if(q1<=q2 || ic==0)break;
			ic--;
			b+=c1;
			while(b-c2>=0){
				nc++;
				b-=c2;
			}
		}
		if(ic+nc>=q1 && ic>0)cout << ic << " " << nc << endl;
		else cout << "NA" << 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 q1, b, c1, c2, q2;
	while (cin >> q1) {
		if (q1 == 0) {
			break;
		} 
		cin >> b >> c1 >> c2 >> q2;
		if (b < c1) {
			cout << "NA" << endl;
		} else {
			int counter = 0;
			while (q2 > 0 && b >= c1) {
				b -= c1;
				q1--;
				q2--;
				counter++;
			}
			int counter2 = 0;
			while (b >= c2) {
				b -= c2;
				q1--;
				counter2++;
			}
			if (q1 > 0) {
				while (q1 > 0) {
					counter--;
					b += c1;
					q1++;
					if (counter == 0) {
						break;
					}
					while (b >= c2) {
						b -= c2;
						q1--;
						counter2++;
					}
				}
				if (counter > 0) {
					cout << counter << " " << counter2 << endl;
				} else {
					cout << "NA" << endl;
				}
			} else {
				cout << counter << " " << counter2 << endl;
			}
		}
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

int main() {
	int q1, b, c1, c2, q2;
	while(cin >> q1, q1) {
	   cin >> b >> c1 >> c2 >> q2;
	   int aizu = min(b / c1, q2);
	   int money = b - aizu * c1;
	   int ordinal = money / c2;
	   if ( (b - c1) / c2 < q1 - 1 ) {
		   cout << "NA" << endl;
		   continue;
	   }
	   while (aizu + ordinal < q1) {
		   aizu--;
		   money = b - aizu * c1;
		   ordinal = money / c2;
		   money = b - aizu * c1 - ordinal * c2;
	   }
	   cout << aizu << ' ' << ordinal << endl;
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

int q1,badget,c1,c2,lower,upper,mid,lim;

bool s(int arg){
  int qn = (badget - arg * c1) / c2;
  if(qn < 0) return false;
  if(qn+arg < q1) return false;
  if(arg > lim) return false;
  if(badget - arg * c1 < 0) return false;
  return true;
}

int main(){

  while(cin >> q1 && q1){
    cin >> badget >> c1 >> c2 >> lim;
    lower = 0;
    upper = 1000000;

    //binary search
    while(upper - lower > 1){
      mid = (upper + lower) / 2;
      if(s(mid)){
	lower = mid;
      }else{
	upper = mid;
      }
    }
    if(lower == 0){
      cout << "NA" << endl;
    }else{
      cout << lower << " " << (badget - lower*c1)/c2 << endl;
    }
  }
}

C++: #include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;

int main() {
	int q1, b, c1, c2, q2;
	while (scanf("%d", &q1), q1) {
		scanf("%d%d%d%d", &b, &c1, &c2, &q2);
		for (int i = min(q2, b / c1); i >= 1; i--) {
			int d = (b - c1*i) / c2;
			if (i + d >= q1) {
				printf("%d %d\n", i, d);
				goto g;
			}
		}
		puts("NA");
	g:;
	}
}