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 <cstdio>
 
int main()
{
    int q1, b, c1, c2, q2;
 
    while (scanf("%d", &q1), q1) {
	scanf("%d %d %d %d" ,&b ,&c1 ,&c2 ,&q2);
 
	int cnt1 = b / c1;
	if (cnt1 > q2) {
	    cnt1 = q2;
	}
	b -= cnt1 * c1;
 
	int cnt2 = b / c2;
	if (cnt2 < 0) {
	    cnt2 = 0;
	}
	b -= cnt2 * c2;
 
	while (true) {
	    if (cnt1 + cnt2 >= q1 || cnt1 <= 0) {     
		break;  
	    } 
	    cnt1--;
	    b += c1;
 
	    b += cnt2 * c2;
	    cnt2 = b / c2;
	    b -= cnt2 * c2;
	}
 
	if (cnt1 <= 0) {
	    puts("NA");
	} else {
	    printf("%d %d\n" ,cnt1 ,cnt2);
	}
    }
    return 0;
}

C++: #include<iostream>
using namespace std;
int q1,b,c1,c2,q2;
main()
{
	while(cin>>q1,q1)
	{
		cin>>b>>c1>>c2>>q2;
		bool flag=1;
		for(;q2;q2--)
		{
			int now=b-q2*c1,x;
			if(now>=0)x=now/c2;
			else x=0;
			if(x+q2>=q1&&now>=0)
			{
				cout<<q2<<" "<<x<<endl;
				flag=0;
				break;
			}
		}
		if(flag)cout<<"NA"<<endl;
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  int q1, b, c1, c2, q2;
  while(cin >> q1, q1){
    cin >> b >> c1 >> c2 >> q2;

    int jibard = min( q2, b / c1);
    b -= jibard * c1;

    int nobard = b / c2;
    b -= nobard * c2;

    while( jibard && jibard + nobard < q1){
      jibard--;
      b += c1;
      int nextnb = b / c2;
      nobard += nextnb;
      b -= nextnb * c2;
    }

    if(jibard) cout << jibard << " " << nobard << endl;
    else cout << "NA" << endl;
  }
}

C++: #include<iostream>
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;break;}}return 0;}

C++: #include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    while(1){
        int a,b,c,d,e;
        cin>>a;
        if(a==0)break;
        cin>>b>>c>>d>>e;
        if(b<c+d*(a-1)){
            puts("NA");
            continue;
        }
        for(int i=e;1<=i;i--){
            if(a<i){
                if(c*i<=b){
                    cout<<i<<' '<<(b-c*i)/d<<endl;
                    break;
                }
            }
            else{
                if(c*i+d*(a-i)<=b){
                    cout<<i<<' '<<(b-c*i)/d<<endl;
                    break;
                }
            }
        }
    }
    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 || (aizu+ord)<q1){
			for(int i=aizu-1;i>0;i--){
				if((c1*i+c2*(q1-i))<b){
					cout<<i<<" "<<q1-i<<endl;
					break;
				}
			}
			cout<<"NA"<<endl;
		}else{
			cout<<aizu<<" "<<ord<<endl;
			continue;
		}
	}
	return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
main(){
  while(1){
    int q1;
    scanf("%d",&q1);
    if(!q1) break;
    int b,c1,c2,q2;
    scanf("%d %d %d %d",&b,&c1,&c2,&q2);
    int res1=0,res2=0;

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

    int st=1,ed=q2;
    while(st<=ed){
      int h=(st+ed)/2;
      int x=b;
      x -= c1*h;
      if(x < 0){
	ed = h-1;
	continue;
      }
      int 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("%d %d\n",res1,res2);
  }
}

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+1<=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+1<=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 + 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;
    cin >> q1;
    }
  }
  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(e>=0){
				if(c*e+d*(a-e)<=b){
					cout<<e<<' '<<a-e<<endl;
					goto E;
				}
				e--;
			}
		}
		F:;
		cout<<"NA"<<endl;
		E:;
	}
}

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;
		long long one = min(q2,b/c1) , two = 0;
		long long cur = b - c1 * one;
		while(one+two<q1 && one > 0){
			if(cur<c2) one-- , cur += c1;
			while(cur - c2 >= 0){
				two++;
				cur -= c2;
			}	
		}
		if(one == 0 || cur < 0 || one+two < q1){
			cout << "NA" << endl;
		}else{
			cout << one << " " << two << endl;
		}
	}
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <sstream>
#include <cmath>
#include <queue>

using namespace std;

int main(){
	
	while(true){
		
		long long int b, c1, c2, q1, q2;
		
		cin >> q1;
		
		if(q1 == 0){
			break;
		}
		
		cin >> b >> c1 >> c2 >> q2;
		
		long long 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 || ans1 + ans2 < q1){
			cout << "NA" << endl;
		}else{
			cout << ans1 << " " << ans2 << endl;
		}
		
		//cout << ans1 << " " << ans2 << endl;
	}
	
	return 0;
}