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 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(c1>b){cout<<"NA"<<endl;}
		else if((aizu+ord)<q1){
			for(int i=aizu-1;i>0;i--){
				if((c1*i+c2*(q1-i))<b){
					flag=true;
					cout<<i<<" "<<q1-i<<endl;
					break;
				}
			}
			if(!flag){
				cout<<"NA"<<endl;
			}
		}else{
			cout<<aizu<<" "<<ord<<endl;
		}
	}
	return 0;
}

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(x != y){
                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<cstdio>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<stack>
#include<functional>
#include<list>
#include<unordered_map>
#include<map>
#define int long long
using namespace std;

signed main() {
	int a, b, c, d, e;
	while (cin >> a, a) {
		cin >> b >> c >> d >> e;
		if (b / c < a&&b / d < a) { puts("NA"); continue; }
		int s = 1, g = e+1;
		while (g - s > 1) {//????´\??°?¶????K??°????????\???????????????
			int k = (s + g) / 2;
			int f = c*k;
			if (f > b) { g = k; continue; }
			f = b-f;
			f = f / d;
			if (k + f >= a) {
				s = k;
			}
			else {
				g = k;
			}
		}
		cout << s<<" "<<(b - (s*c))/d << endl;
	}
}

C++: #include<ios>
main(){for(int q,b,c,d,r,A,N;std::cin>>q>>b>>c>>d>>r,q;A?printf("%d %d\n",A,N):printf("NA\n"))for(A=0;r;r--){N=(b-r*c)/d;if(b>=r*c&&N+r>=q){A=r;r=1;}}}

C++: #include<iostream>
using namespace std;
typedef long long ll;
int main(){
  ll q1,b,c1,c2,q2;
  cin >> q1;
  while(q1!=0){
    cin >> b >> c1 >> c2 >> q2;
    ll x1=0,x2=0,m=min(c1,c2);
    bool f=false;
    //cout << b-min(c1,c2)*q1 << endl;
     
    if(c1<=c2){
      if(b<c1*q2+c2*(q1-q2)) f=true;
      while(b>=c1*(x1+1)&&x1<q2) x1++;
      while(b>=c1*x1+c2*(x2+1)) x2++;
      if(x1==0) f=true;
      if(f) cout << "NA" << endl;
      else cout << x1 << " " << x2 << endl;
      cin >> q1;
    }else{
      if(b<m*q1) f=true;
      ll s=c1-c2,sum=0;
      sum=q1*m;
      while(b-sum>=s*(x1+1)&&x1<q1&&x1<q2) {
        x1++; 
        //cout << b-sum<<":"<<s*x1<<endl;
        //cout << x1<<":"<<c1*x1<<endl;
      }
      if(x1==q1)
        while(b>=c1*(x1+1)&&x1 + 1<=q2) x1++;
      //while(b>=c1*x1+c2*(x2+1)) x2++;
       
      if(x1==0) f=true;
      x2=0;
      while(b>=c1*x1+c2*(x2+1)) x2++;
      if(f) cout << "NA" << endl;
      else cout << x1 << " " << x2 << endl;
      //cout << c1*x1+c2*x2 << endl;
      cin >> q1;
    }
  }
  return 0;
}

C++: #include <cstdio>

int main(void)
{
	long q1, b, c1, c2, q2;
	
	while (1){
		scanf("%ld", &q1);
		if (q1 == 0) break;
		scanf("%ld %ld %ld %ld", &b, &c1, &c2, &q2);
		
		if ((b < (c2 * (q1 - 1)) + c1) && (c2 < c1)){
			printf("NA\n");
			continue;
		}
		
		long aizu = 0, normal = 0;
		
		aizu = b / c1;
		b = b % c1;
		if (q2 < aizu){
			long over = aizu - q2;
			aizu -= over;
			b += (over * c1);
		}
//		printf("%ld %ld\n", aizu, b);
		
		normal = b / c2;
		b = b % c2;
//		printf("%ld %ld\n", normal, b);
		
		while ((aizu + normal) < q1){
			aizu--;
			b += c1;
			normal += (b / c2);
			b %= c2;
		}
		
		printf("%ld %ld\n", aizu, normal);
	}
	
	return (0);
}

C++: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <ctime>
#include <cassert>
#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 <iterator>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main()
{
	for(int q1,b,c1,c2,q2;cin>>q1>>b>>c1>>c2>>q2 && q1;){
		int a1=min(b/c1,q2);
		for(;;){
			if(a1==0){
				cout<<"NA"<<endl;
				break;
			}
			int a2=(b-a1*c1)/c2;
			if(a1+a2>=q1){
				cout<<a1<<" "<<a2<<endl;
				break;
			}
			a1--;
		}
	}
	
	return 0;
}

C++: #include <iostream>

using namespace std;

int main()
{
  int q1, b, c1, c2, q2, s, t, cost;

  while(1){
    cin >> q1;
    if(q1 == 0){
      break;
    }
    cin >> b >> c1 >> c2 >> q2;

    s = b / c1;
    if(s > q2){
      s = q2;
    }
    t = q1 - s;
    if(t < 0){
      t = 0;
    }
    cost = c1*s + c2*t;
    if(cost > b){
      while(s > 0 && cost > b){
	cost -= c1;
	s--;
      }
    }
    if(s <= 0){
      cout << "NA" << endl;
      continue;
    }
    while(cost+c2 <= b){
      t++; 
      cost+=c2;
    }
    cout << s << " " << t << endl;
  }

  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){cout<<"NA"<<endl;}
		else if((aizu+ord)<q1){
			for(int i=aizu-1;i>0;i--){
				bool flag=false;
				if((c1*i+c2*(q1-i))<b){
					flag=true;
					cout<<i<<" "<<(b-c1*i)/c2<<endl;
					break;
				}
			}
			if(!flag){
				cout<<"NA"<<endl;
			}
		}else{
			cout<<aizu<<" "<<ord<<endl;
		}
	}
	return 0;
}