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;
		
		while(true){
		}
		
		int ans1, ans2;
		
		if(c1 <= c2){
			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<stdio.h>
#include<algorithm>
using std::swap;
int main()
{
	int q1,q2,c1,c2,b,x,y,f;
	while(scanf("%d%d%d%d%d",&q1,&b,&c1,&c2,&q2)>1)
	{
		if(c1<c2)f=1,swap(c1,c2);
		else f=0;
		x=1;
		while(y=(b-x*c1)/c2, b>=x*c1&&x<q2&&x+y>=q1)
			++x;
		if(b<x*c1 || x+y<q1) --x,y=(b-x*c1)/c2;	
		if(f)swap(x,y);
		if(!x||x+y<q1)puts("NA");
		else printf("%d %d\n",x,y);
	}
	return 0;
}

C++: g#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);
	   if (aizu == 0) {
		   cout << "NA" << endl;
		   continue;
	   }
	   int money = b - aizu * c1;
	   int ordinal = money / c2;

	   bool possible = true;
	   while (aizu + ordinal < q1) {
		   aizu--;
		   if (aizu == 0) {
			   cout << "NA" << endl;
			   possible = false;
			   break;
		   }
		   money = b - aizu * c1;
		   ordinal = money / c2;
		   money = b - aizu * c1 - ordinal * c2;
	   }
	   if (possible) cout << aizu << ' ' << ordinal << endl;
	}
	return 0;
}

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(b<m*q1) f=true;
    
    if(c1<=c2){
      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{
    ll s=c1-c2,sum=0;
    sum=q1*m;
    bool f1=false;
    while(b-sum>=s*(x1+1)&&x1<q2) {
      x1++; 
      if(x1>=q1) {
        f1=true;
        break;
      }
      //cout << b-sum<<":"<<s*x1<<endl;
      //cout << x1<<":"<<c1*x1<<endl;
    }
    if(f1)
    while(b>=c1*(x1+1)&&x1<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;
    cin >> q1;
    }
  }
  return 0;
}

C++: #include <cstdio>

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

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

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

  while(1){
    cin >> q1;
    if(!q1)break;
    cin >> b >> c1 >> c2 >> q2;

    int k1,k2;

    k1 = b/c1;
      if(k1>q2)k1 = q2;
      for(i=k1;i>0;i--){
	k2 = (b-c1*i)/c2;
	if(i+k2>=q1){
	  cout << i << " " << k2 << endl;
	  break;
	}
      }
      if(!i)cout << "NA" << endl;
  }
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

int main(){
	long long q1,b,c1,c2,q2;
	while(cin >> q1 , q1){
		cin >> b >> c1 >> c2 >> q2;
		
		b -= c1 * q2;
		while(b<0){
			b += c1;
			q2--;
		}
		while(q2 + (b/c2) < q1 && q2>0){
			q2--;
			b += c1;
		}
		if(q2 > 0){
			cout << q2 << " " << (b/c2) << endl;
		}else{
			cout << "NA" << endl;
		}
	}
}

C++: #include <iostream>

using namespace std;

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

  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;
    }
    if(s+t < q1){
      q1 -= (s+t);
      f = (float)c1/c2;
      a = 1;
      while(f < (float)q1){
	f += f;
	a++;
      }
      s -= a;
      cost -= c1*a;
      cost += ((int)f*c2);
      t += (int)f;
      while(cost+c2 <= b){
	t++; 
	cost += c2;
      }
    }
    cout << s << " " << t << endl;
  }

  return 0;
}

C++: #include <iostream>

using namespace std;

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

  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;
    }
    if(s+t < q1){
      q1 -= (s+t);
      f = (float)c1/c2;
      a = 1;
      while(f < (float)q1){
	f += f;
	a++;
      }
      s -= a;
      cost -= c1*a;
      cost += ((int)f*c2);
      t += (int)f;
      while(cost+c2 <= b){
	t++; 
	cost += c2;
      }
      if(s+t < q1){
	cout << "NA" << endl;
	continue;
      }
    }
    cout << s << " " << t << endl;
  }

  return 0;
}