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 <algorithm>
#include <cmath>
#include <cassert>

using namespace std;

void failed() {
  cout << "NA" << endl;
}

int main() {
  
  int Q1, B, C1, C2, Q2;
  
  while(cin >> Q1 >> B >> C1 >> C2 >> Q2) {
    
    if(Q1 == 0) break;
    
    assert(Q2 >= 1);
    
    /*
    if(B/C1 == 0) {
      failed(); continue;
    }
    */
    
    int AizuCh = min(B/C1, Q2);
    if(AizuCh <= 0) { failed(); continue; }
    int NCh = 0;
    for(;;) {
      
      NCh = (B - AizuCh*C1)/C2;
      
      /*
      if(B - (NCh+1)*C2 - AizuCh*C1 >= 0) {
        NCh = (B - AizuCh*C1)/C2;
      }
      */
      if(AizuCh + NCh >= Q1) {
        cout << AizuCh << ' ' << NCh << endl; break;
      }
      /*
      else if(B - (NCh+1)*C2 - (AizuCh-1)*C1 >= 0) {
        NCh ++, AizuCh --;
      }
      */
      else AizuCh --;
      
      if(AizuCh <= 0) { failed(); break; }
    }
    
  }
  
  return 0;
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
int main(){
    while(1){
        int q1, b, c1, c2, q2;
        cin >> q1;
        if(q1 == 0) break;
        cin >> b >> c1 >> c2 >> q2;

        int n1 = min(b/c1,q2);
        int n2 = max((b-n1*c1)/c2,0);
        while(1){
            if(n1 <= 0) {
                cout << "NA" << endl;
                break;
            }
            if( q1 <= n1 + n2 ) {
                cout << n1 << ' ' << n2 << endl;
                break;
            }
            n1--;
            n2 = (b-n1*c1)/c2;
        }
    }
    return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <sstream>
#include <climits>
#include <cfloat>
#include <complex>

using namespace std;

int main()
{
	int q1, b, c1, c2, q2;
	while (scanf("%d %d %d %d %d", &q1, &b, &c1, &c2, &q2), q1)
	{
		int aizu = 0, normal;
		for (int i = min(q2, b/c1); i > 0; --i)
		{
			int t = (b - i*c1) / c2;
			if (i + t >= q1)
			{
				aizu = i;
				normal = t;
				break;
			}
		}
		if (aizu)
			printf("%d %d\n", aizu, normal);
		else
			puts("NA");
	}

	return 0;
}

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

int a,b,c,d,e,f;

int main(){
	while(cin>>a){
		if(a==0){break;}
		cin>>b>>c>>d>>e;
		if(a<=e){
			f=b/c;
			if(f>=a){cout<<f<<' '<<"0"<<endl;goto E;}
			else{goto F;}
		}
		if(c*e+d*(a-e)<=b){
			while(true){
				if(c*e+d*(a-e)>b){
					cout<<e<<' '<<a-e-1<<endl;
					goto E;
				}
				a++;
			}
		}
		else{
			while(true){
				if(a-e<0){break;}
				if(c*e+d*(a-e)<=b){
					cout<<e<<' '<<a-e<<endl;
					goto E;
				}
				e--;
			}
		}
		F:;
		cout<<"NA"<<endl;
		E:;
	}
}

C++: #include <iostream>

using namespace std;

int main()
{
  long 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 < 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;
}

C++: #include <stdio.h>

int main(void)
{
	int q1, zidori, hutuu, q2, yosan;
	int ans;
	
	while (1){
		scanf("%d", &q1);
		if (q1 == 0){
			break;
		}
		scanf("%d%d%d%d",  &yosan, &zidori, &hutuu, &q2);
		
		ans = -1;
		for (int i = q2; i >= 1; i--){
			int mon = yosan;
			mon -= zidori * i;
			if (mon >= 0 && (i + mon / hutuu) >= q1){
				ans = i;
				break;
			}
		}
		
		if (ans == -1){
			printf("NA\n");
		}
		else {
			printf("%d %d\n", ans, (yosan - ans * zidori) / hutuu);
		}
	}
	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;
            int tmp = 0;
            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;
                ++ tmp;
                if(tmp > 1000)
                    break;
            }
            cout << x << ' ' << ((b - x*c1) / c2) << endl;
        }
    }
}

C++: #include <cstdio>
int q1, b, c1, c2, q2;
int main() {
  while (scanf("%d", &q1)) {
	if (q1 == 0) break;
	scanf("%d%d%d%d",&b,&c1,&c2,&q2);
	int jidori = b / c1;
	jidori = (jidori < q2 ? jidori : q2);
	b -= jidori * c1;
	int normal = b / c2;
	b -= normal * c2;
	while (jidori + normal < q1) {
	  jidori--; b += c1;
	  int temp = b / c2;
	  normal += temp;
	  b -= c2 * temp;
	}
	if (jidori <= 0) puts("NA");
	else printf("%d %d\n",jidori,normal);
  }
}

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;
      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;
}