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 <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10
#define MAX_N 20000
#define MAX_M 16

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int q1, b, c1, c2, q2;
P ans;

int main(){
	while (cin >> q1&&q1){
		cin >> b >> c1 >> c2 >> q2;
		ans = P(-1, -1);
		if (c2 < c1){
			FOR(i, 1, q2 + 1){
				if (q1 - i >= 0){
					if (i*c1 + (q1 - i)*c2 <= b){
						int co = (b - i*c1) / c2;
						if (ans.first < i&&co >= 0){
							ans = P(i, co);
						}
					}
				}
				else{
					if (i*c1 <= b){
						ans = P(i, 0);
					}
				}
			}
			if (ans.first >= 0 && ans.second >= 0)cout << ans.first << " " << ans.second << endl;
			else cout << "NA" << endl;
		}
		else{
			ans = P(0, 0);
			REP(i, q2){
				if (b - c2 >= 0){
					b -= c2;
					ans.first++;
				}
			}
			while (b - c1 >= 0){
				b -= c1;
				ans.second++;
			}
			if (ans.first + ans.second < q1)cout << "NA" << endl;
			else cout << ans.first << " " << ans.second << endl;
		}
	}
}

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

int main(){
	long long b,c1,c2,q1,q2,aizu,ord;
	bool flag;
	
	while(cin>>q1,q1){
		flag=false;
		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(aizu==0){cout<<"NA"<<endl;}
		else if((aizu+ord)<q1){
			for(int i=aizu-1;i>0;i--){
				if((b-c1*i)/c2>=q1-i){
					flag=true;
					cout<<i<<" "<<(b-c1*i)/c2<<endl;
					break;
				}
			}
			if(!flag){
				cout<<"NA"<<endl;
			}
		}else{
			cout<<aizu<<" "<<ord<<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 || arg <= 0) return false;
  if(qn+arg < q1) return false;
  if(arg > lim) 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 <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;
            while(y - x > 1){
                int z = (x + y + 1) / 2;
                if(b - z*c1 >= 0 && (b - z*c1) / c2 >= q1 - z)
                    x = z;
                else
                    y = z-1;
            }
            cout << x << ' ' << ((b - x*c1) / c2) << endl;
        }
    }
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int x,y;
    x=a/b;
    if(x>d)x=d;
    if(x==0){cout<<"NA"<<endl;continue;}
    a-=b*x;
    //cout<<x<<" "<<a<<endl;
    while(1){
      y=a/c;
      if(x+y>=n)break;
      x--;
      a+=b;
      if(!x)break;
    }
    if(!x)cout<<"NA"<<endl;
    else cout<<x<<" "<<y<<endl;
  }


}

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

int main()
{
  int q1,b,c1,c2,q2;
  for(;cin>>q1,q1;)
    {
      cin>>b>>c1>>c2>>q2;
      int ans1=-1,ans2;
      for(int i=1;i<=q2;i++)
	{
	  int money=b;
	  money-=i*c1;
	  if((money/c2)+i>=q1 && money>=0)
	    {
	      ans1=i;
	      ans2=money/c2;
	    }
	}
      if(ans1==-1)
	cout<<"NA"<<endl;
      else
	cout<<ans1<<" "<<ans2<<endl;
    }
}

C++: #include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF INT_MAX/3
#define ALL(a) (a).begin(),(a).end()
#define CLR(a) memset(a,0,sizeof(a))

typedef long long int ll;

using namespace std;

int main(){
    while(true){
	int a,b,c,d,e;
	cin >> a;
	if(a == 0)break;
	cin >> b >> c >> d >> e;
	int m1 = min(e,b / c); 
	int m = b/d;
	if(m == 0){
	    m = min(e,b/c);
	}
	REP(i,m1+1){
	    int tm,tm1;
	    tm = m;
	    tm1 = m1-i;
	    while((tm) * d + (tm1) * c > b){
		tm--;
		if(tm==0) {
		    break;
		}
	    }
	    if(tm+tm1 >= a) {
		m = tm;
		m1 = tm1;
		break;
	    }else if(i == m1){
		m = 0;
		m1 = 0;
	    }
	}
	if(m == 0 && m1 == 0) cout << "NA" << endl;
	else cout << m1 << " " << m << endl;
    }
    return 0;
}

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(c2*(q1-1)+c1>b)cout<<"NA"<<endl;
		else{
			t=c1==c2?1<<20:(b-q1*c2)/(c1-c2);
			d=min(q2,min(t,b/c1)),n=(b-c1*d)/c2;
			cout<<d<<" "<<n<<endl;
		}
	}
	return 0;
}