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

int main(void)
{
	int q1, b, c1, c2, q2;
	
	while(1){
		scanf("%d", &q1);
		if (q1 == 0) break;
		scanf("%d %d %d %d", &b, &c1, &c2, &q2);
		
		if (c1 <= c2){
			int x = min(b/c1, q2);
			int y = ((b - x) * c1) / c2;
			if ((x + y) < q1){
				printf("NA\n");
			}
			else {
				printf("%d %d\n", x, y);
			}
		}
		else {
			int x = min(min(((b - c2) * q1) / (c1 - c2), q2), (b / c1));
			int y = ((b - x) * c1) / c2;
			if(x <= 0){
				printf("NA\n");
			}
			else {
				printf("%d %d\n", x, y);
			}
		}
	}
	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--;
	b=b+c1;
	if(count<=0){
	  cout << "NA" << endl;
	  j=1;
	  break;
	}
	if(count+count2>=q1){
	  break;
	}
	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 <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> PI;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define MP make_pair
#define PB push_back

ll q1,b,c1,c2,q2;

bool can(ll ai){
  ll zan=b-ai*c1;
  ll ji=zan/c2;
  if(ai>q2 || ai<1)return false;
  if(ai+ji<q1)return false;
  if(zan<0)return false;
  return true;
}

main(){
  while(cin>>q1,q1){
    cin>>b>>c1>>c2>>q2;

    ll l=0,r=1000000;
    while(l+1<r){
      ll mid=(l+r)/2;
      //cout<<l<<" "<<mid<<" "<<r<<endl;
      if(can(mid))l=mid;
      else r=mid;
    }
    if(can(l)){
      cout<<l<<" "<<(b-l*c1)/c2<<endl;
    }else puts("NA");
  }
}

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

int main(){
	int n;
	while(cin >> n , n){
		int need , ans = 0;
		vector<int> d(n);
		rep(i,n) cin >> d[i];
		
		cin >> need;
		int l = 0 , r = n-1;
		while( l !=  r ){
			ans++;
			int m = (l+r)/2;
			if(d[m] > need) r = m-1;
			else if(d[m] < need) l = m+1;
			else {ans--;break;}
		}
		cout << ans+1 << endl;
	}
}

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

int q1,q2,b,c1,c2,ans1,ans2;

bool solve(){
	ans1 = q2;
	ans2 = 0;
	while(ans1*c1 + ans2*c2 <= b)
		ans2++;
	if(ans2)
		ans2--;
	if(ans1 + ans2 >= q1 && ans1*c1 + ans2*c2 <= b)
		return true;
	while(true){
		ans1--;
		while(true){
			ans2++;
			if(ans1*c1 + ans2*c2 > b){
				ans2--;
				break;
			}
		}
		if((ans1*c1 + ans2*c2 <= b && ans1 + ans2 >= q1) || ans1 == 0)
			break;
	}
	if(!ans1 || ans1 + ans2 < q1)
		return false;
	else
		return true;
}

int main(){
	while(true){
		cin >> q1;
		if(!q1)
			return 0;
		cin >> b >> c1 >> c2 >> q2;
		if(solve())
			cout << ans1 << ' ' << ans2 << endl;
		else
			cout << "NA" << 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) {
	  if (jidori <= 0) break;
	  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>
#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;
    
    if((int)(B/C1) == 0) {
      failed(); continue;
    }
    
    int AizuCh = min(B/C1, Q2);
    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 <vector>
#include <algorithm>

using namespace std;

int main(){

	int q1,b,c1,c2,q2;
	while(cin>>q1>>b>>c1>>c2>>q2&&q1!=0){
		// Ü¸ïÃ{÷ðAé¾¯¤
		int aizu=min(b/c1,q2);
		if(aizu==0){
			cout<<"NA"<<endl;
			continue;
		}
		int left = b-aizu*c1;
		// ÉÊÌ{÷ðãÀÜÅ¤
		int usu=left/c2;
		left-=usu*c2;
		// »ÝÌóÔÅðð½µÄ¢é©
		if(aizu+usu>=q1){
			cout<<aizu<<" "<<usu<<endl;
		}
		// ½µÄ¢È©Á½êAaizu÷ðèAusu÷ð+
		else{
			bool f=false;
			for(int i = aizu-1; i >= 1; i--){
				aizu=i;
				left+=c1;
				int tmp=left/c2;
				left-=tmp*c2;
				usu+=tmp;
				if(aizu+usu>=q1){
					f=true;
					cout<<aizu<<" "<<usu<<endl;
					break;
				}
			}
			if(!f){
				cout<<"NA"<<endl;
			}
		}
	}

	return 0;
}

C++: #include <iostream>

using namespace std;

int q1, b, c1, c2, q2;

int check (int x )
{
	int y = (b - c1*x)/c2;

	if (x + y < q1 ) return -1;
	if (y < 0 ) return -1;
	if (b - c1*x < 0 ) return -1;
	
	return y;
}

int main()
{
	while (cin >> q1 >> b >> c1 >> c2 >> q2 && q1 ){

		int x, y;
		for (x = q2; x > 0; x-- ){
			if ( (y = check (x ) ) != -1 ){
				cout << x << ' ' << y << endl;
				break;
			} // end if
		} // end for

		if (x == 0 ){
			cout << "NA" << endl;
		} // end if

	} // end while

	return 0;
}