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<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
main(){
  while(1){
    ll q1;
    scanf("%lld",&q1);
    if(!q1) break;
    ll b,c1,c2,q2;
    scanf("%lld %lld %lld %lld",&b,&c1,&c2,&q2);
    ll res1=0,res2=0;

    if(c1<=c2){
      if(b >= c1*q2){
	b-=c1*q2;
	res1 = q2;
      }else{
	res1 = b/c1;
	b-=(b/c1)*c1;
      }
      res2 = b/c2;
      if(res1 + res2 < q1 || res1==0) puts("NA");
      else printf("%lld %lld\n",res1,res2);
      continue;
    }

    ll st=1,ed=q2;
    while(st<=ed){
      ll h=(st+ed)/2;
      ll x=b;
      x -= c1*h;
      if(x < 0){
	ed = h-1;
	continue;
      }
      ll t2 = (x/c2);
      x -= t2*c2;
      if( x>=0 && h+t2>=q1 ){
	res1 = h;
	res2 = t2;
	st = h+1;
      }else{
	ed = h-1;
      }
    }
    if(!res1 && !res2) puts("NA");
    else printf("%lld %lld\n",res1,res2);
  }
}

C++: #include <iostream>

using namespace std;

typedef long long int lli;

int main()
{
	lli m, n, p, q, s, t, u, v;
	
	while(cin >> n && n){
		cin >> s >> t >> u >> v;
		
		while(v > 0){
			if((s-t*v) >= 0 && (s-t*v)/u+v >= n){
				break;
			}
			v--;
		}
		
		if(v == 0){
			cout << "NA" << endl;
		} else {
			cout << v << " " << ((s-t*v)/u) << endl;
		}
	}
	
	return 0;
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int count=0,count2=0,b,c1,d=0,i,j,q1,c2,q2,y=0;
  while(1){
    j=0;
    y=0;
    count=0;
    count2=0;
    cin >> q1;
    if(q1==0){
      break;
    }
    cin >> b >> c1 >> c2 >> q2;
    if(b<c1){
      cout << "NA" <<endl;
      continue;
    }
    while(b>=c1){
      b=b-c1;
      count++;
      if(count >= q2){
	break;
      }
    }
    if(b<c2 && count<q1){
      cout << "NA" <<endl;
      continue;
    }
    if(b>=c2){
      while(b>=c2){
	b=b-c2;
	count2++;
      }
    }
    if(count+count2<q1){
      while(1){
	d=0;
	count--;
	if(count<=0){
	  cout << "NA" << endl;
	  j=1;
	  break;
	}
	b=b+c1;
	while(b-c2*d>0){
	  count2++;
	  b=b-c2;
	  d++;
	  if(count+count2>=q1){
	    y=1;
	    break;
	  }
	}
	if(y==1){
	  break;
	}
      }
    }
    if(j==0){
      cout << count << " " << count2 <<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;

int 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 <iostream>
using namespace std;

main() {
  while(1) {
    int q1, b, c1, c2, q2;
    cin >> q1;
    if(q1 == 0) break;
    cin >> b >> c1 >> c2 >> q2;
    int aizu;
    int normal;

    aizu = b / c1;
    if(aizu > q2) aizu = q2;
    bool flag = false;
    while(aizu >= 1) {
      normal = (b - aizu * c1) / c2;
      if(aizu + normal >= q1) {
        flag = true;
        break;
      }
      aizu--;
    }

    if(!flag) cout << "NA" << endl;
    else      cout << aizu << ' ' << normal << 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) / d + 1 < 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 <bits/stdc++.h>
using namespace std;
int q,b,c1,c2,limit;

int check(int M){
  int B=b,cnt=M;
  B-=c1*M;
  if(B<0) return 0;
  cnt+=(B/c2);
  return (cnt>=q);
}

int main(){
  while(cin>>q,q){;
    cin>>b>>c1>>c2>>limit;

    int L=0,M,R=limit+1;
    while(L<R) {
      M=(R+L)/2;
      if(!check(M)) R=M;
      else L=M+1;
    }
    if(L==0) cout <<"NA"<<endl;
    else cout <<(L-1)<<" "<<((b-(L-1)*c1)/c2)<<endl;
    
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

int main() {
  for(int q1, b, c1, c2, q2; cin >> q1 >> b >> c1 >> c2 >> q2 && q1;) {
    try {
      for(int s = q2; s > 0; --s) {
        int rem = b - s * c1;
        if(rem < 0) continue;
        int t = rem / c2;
        if(s+t >= q1) {
          cout << s << " " << t << endl;
          throw 0;
        }
      }
      cout << "NA" << endl;
    } catch(...) {}
  }
  return 0;
}

C++: #include<cstdio>
#include<algorithm>
#include<vector>
#include<iostream>
#include<string>
#include<cstring>
#include<sstream>
#include<queue>
using namespace std;
int main(){
    int q1,b,c1,c2,q2;
    while(cin>>q1,q1){
        cin>>b>>c1>>c2>>q2;
        int x,y;
        x=min(b/c1,q2);
        b-=c1*x;
        y=b/c2;
        if(x+y<q1||x==0)cout<<"NA"<<endl;
        else cout<<x<<" "<<y<<endl;
    }
    return 0;
}

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

int main()
{
	int q1,money,c1,c2,q2;
	while(cin >> q1){
		if(!q1)
			break;
			cin >> money >> c1 >> c2 >> q2;
			int zidori = min(money/c1,q2);
			int now = money - zidori*c1;
			int hutuu = q1-zidori;
			if(hutuu < 0)
				hutuu = 0;
			int kakaku = zidori*c1 + hutuu*c2;
			while(kakaku > money){
				zidori--;
				hutuu++;
				kakaku -= c1-c2;
			}
			while(kakaku < money){
				if(kakaku+c2 < money){
					kakaku += c2;
					hutuu++;
				}
				else
					break;
			}
			if(zidori <= 0)
				cout << "NA" << endl;
			else
				cout << zidori << " " << hutuu << endl;
	}
	return 0;
}