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 <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back


int main() {
    int q1,b,c1,c2,q2;
    while(cin>>q1){
        if(q1==0)break;
        cin>>b>>c1>>c2>>q2;
        
        int x=-1,y=-1;
        for(int i=q2;i>0;i--){
            int niku=( b-(i*c1) )/c2;
            if(niku+i>=q1 && i*c1+niku*c2<=b &&niku>=0){
                x=i;y=niku;
                break;
            }
        }
        
        if( x==-1 && y==-1 )cout<<"NA"<<endl;
        else cout<<x<<" "<<y<<endl;
    }

    return 0;
}

C++: #include <vector>
#include <algorithm>
#include <functional>
#include <iostream>
#include <cmath>
#include <string>

using namespace std;

int main()
{
    int b, c1, c2, q1, q2;
    while(cin >> q1 && q1) {
        cin >> b >> c1 >> c2 >> q2;
        int a, a1, a2, d;
        a = b / c1;
        bool ok = false;
        for(int i = 0; !ok && i < a1; i++) {
            a1 = a - i;
            if(a1 > q2) a1 = q2;
            a2 = (b - a1 * c1) / c2;
            if(a1 + a2 >= q1) ok = true;
        }
        
        if(ok) {
            cout << a1 << " " << a2 << endl;
        } else {
            cout << "NA" << endl;
        }
        
    }
    return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int main()
{
	int q1,b,c1,c2,q2;
	while(cin >> q1 && q1)
	{
		cin >> b >> c1 >> c2 >> q2;
		
		if(c1 + c2 * (q1 - 1) > b) cout << "NA" << endl;
		else
		{
			int cnt = 1,cnt_2 = q1 - 1,res = c1 + c2 * (q1 - 1);

			while(res + c1 - c2 <= b && cnt_2 > 0)
			{
				if(cnt < q2)
				{
					res += c1 - c2;
					cnt++;
					cnt_2--;
				}
				else break;
			}

			if(cnt < q2)
			{
				while(res + c1 <= b && cnt < q2)
				{
					res += c1;
					cnt++;					
				}
			}

			while(res + c2 <= b)
			{
				res += c2;
				cnt_2++;
			}

			cout << cnt << " " << cnt_2 << endl;
		}
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

#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()
const int INF = 1<<30;

int main() {
  int q1,b,c1,c2,q2;
  while(cin >> q1, q1) {
    cin >> b >> c1 >> c2 >> q2;
    int a1 = min(q2,b/c1);
    int a2 = (b-a1*c1) / c2;
    
//    printf("[%d,%d]\n",a1,a2);
    while(a1 + a2 < q1) {
      a1--;
      if (a1 == 0) {
        break;
      }
      while(a1 * c1 + a2 * c2 <= b)
        a2++;
      a2--;
    }
    if (a1 == 0)
      cout << "NA";
    else
      cout << a1 << " " << a2;
    cout << endl;
    
  }
}

C++: #include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    while(cin>>n,n){
        long long int have,price[2],up;
        cin>>have>>price[0]>>price[1]>>up;
        bool kawa=0;
        for(int i=up;i>0;i--){
            if(have<price[0]*i)continue;
            for(int j=max(n-i,0);;j++){
                if(have-price[0]*i-price[1]*j<0){
                    if(i+j-1>=n){
                        kawa=1;
                        have=j-1;
                    }
                    break;
                }
            }
            if(kawa){
                cout<<i<<" "<<have<<endl;
            }
        }
        if(!kawa)cout<<"NA\n";
    }
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <bitset>
using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pii;

#define rep(i,n) for(int i=0; i<n; i++)
#define repa(i,s,e) for(int i=s; i<=e; i++)
#define repd(i,s,e) for(int i=s; i>=e; i--)

int q1, b, c1, c2, q2, a1, a2;
bool ok;

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

		a1 = a2 = 0;
		ok = false;
		repd(i,q2,0) {
			a1 = i;
			if(a1 * c1 > b) continue;
			a2 = (b - c1 * a1) / c2;
			if(a1 + a2 >= q1 && a1 >= 1) {
				ok = true;
				break;
			}
		}
		if(ok) printf("%d %d\n", a1, a2);
		else printf("NA\n");
	}
}

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;r=1;}}}

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){
			for(int i=f;i<=e;i++){
				f=i;
				if(c*f+d*(a-f)>b){
					cout<<e<<' '<<a-e-1<<endl;
					goto E;
				}
			}
			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 <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF INT_MAX/3
#define ALL(a) (a).begin(),(a).end()
#define CLR(a) memset(a,0,sizeof(a))

typedef long long int ll;

using namespace std;

int main(){
    while(true){
	int a,b,c,d,e;
	cin >> a;
	if(a == 0)break;
	cin >> b >> c >> d >> e;
	int m1 = min(e,b / c); 
	int m = b/d;
	if(m == 0){
	    m = min(e,b/c);
	}
	REP(i,m1+1){
	    int tm,tm1;
	    tm = m;
	    tm1 = m1-i;
	    while((tm) * d + (tm1) * c > b){
		tm--;
		//printf("a = %d b = %d budget = %d\n",m*d,m1*c,b);
		if(tm==0) {
		    m = tm;
		    m1 = tm1;
		    break;
		}
	    }
	    if(tm+tm1 >= a) {
		m = tm;
		m1 = tm1;
		break;
	    }else if(i == m1){
		m = 0;
		m1 = 0;
	    }
	}
	if(m == 0 && m1 == 0) cout << "NA" << endl;
	else cout << m1 << " " << m << endl;
    }
    return 0;
}