Go: package main

import (
	"bufio"
	"os"
	"strconv"
	"strings"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
Here:
	for scanner.Scan() {
		L, _ := strconv.Atoi(scanner.Text())
		if L == 0 {
			break
		}
		for i := 0; i < 12; i++ {
			scanner.Scan()
			buf := strings.Split(scanner.Text(), " ")
			M, _ := strconv.Atoi(buf[0])
			N, _ := strconv.Atoi(buf[1])
			L -= (M-N)
			if L <= 0 {
				fmt.Println(i+1)
				continue Here
			}
		}
		fmt.Println("NA")
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
int a,b,c,d,y,t,f;
int main(){
    while(1){
        f=0;
        t=0;
        d=0;
        cin>>a;
        if(a==0)return 0;
        for(y=1;y<13;y++){
            cin>>b>>c;
            d+=b-c;
            if(y==12&&d<a){t=13;}
            if(d>=a&&f==0){t=y;f++;}
        }
        if(t==13){cout<<"NA"<<endl;}else
                 {cout<<t<<endl; }
    }




}

C++: #include <cstdio>
#include <utility>
using namespace std;

#define gcu getchar_unlocked
int in(int c){int n=0;bool m=false;if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0');return m?-n:n;}
int in() {return in(gcu());}
bool scan(int &n){int c=gcu();return c==EOF?false:(n=in(c),true);}
bool scan(char &c){c=gcu();gcu();return c!=EOF;}
//bool scan(string &s){int c;s="";
//	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
template <typename head, typename... tail>
bool scan(head &h, tail&&... t){return scan(h) && scan(t...);}
#define pcu putchar_unlocked
#define vo inline void out
template <typename T>
vo(T n){static char buf[20];char *p=buf;
	if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10;
	while (p!=buf)pcu(*--p);}
vo(const char *s){while(*s)pcu(*s++);}
vo(char c){pcu(c);}
//vo(string &s){for (char c: s) pcu(c);}
template <typename head, typename... tail> vo(head&& h, tail&&... t){out(h);out(move(t)...);}
//template <typename T> vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);out('\n');}
#undef vo

int main() {
	for (int l; (l = in());) {
		int r = 0;
		for (int i = 1; i <= 12; i++) {
			int m = in(), n = in();
			if ((l -= m - n) <= 0 && !r)
				r = i;
		}
		if (r)
			out(r);
		else
			out("NA");
		out('\n');
	}
}

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

int main(void)
{
  while (true)
  {
    int expenses;
    cin >> expenses;
    if ( expenses == 0 ) break;
    int i;
    int sum = 0;
    for (i = 0; i < 12 && sum < expenses; i++)
    {
      int revenue, spending;
      cin >> revenue >> spending;
      sum += revenue - spending;
    }
    for (i = i; i < 12; i++)
    {
      int d,dm;
      cin >> d >> dm;
    }
    if (i == 12 && sum < expenses)
    {
      cout << "NA" << endl;
    }
    else
    {
      cout << i << endl;
    }
  }
  return 0;
}

C++: #include <iostream>
using namespace std;
int main()
{
	int l, m, n, s, r, i;
	while (cin >> l && l)
	{
		s = 0;
		r = 0;
		for (i = 0; i < 12; i++)
		{
			cin >> m >> n;
			s += m-n;
			if (!r && s >= l)
				r = i+1;
		}
		if (r == 0)
			cout << "NA" << endl;
		else
			cout << r << endl;
	}
}

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

int main(void)
{
  while (true)
  {
    int expenses;
    cin >> expenses;
    if ( expenses == 0 ) break;
    int i;
    int sum = 0;
    for (i = 0; i < 12 && sum < expenses; i++)
    {
      int revenue, spending;
      cin >> revenue >> spending;
      sum += revenue - spending;
    }
    if (i == 12 && sum < expenses)
    {
      cout << "NA" << endl;
    }
    else
    {
      cout << i << endl;
    }
    for (i = i; i < 12; i++)
    {
      int d,dm;
      cin >> d >> dm;
    }
  }
  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 l;
  while(cin >> l, l) {
    bool f = 0;
    int a[12], b[12];
    REP(i,12) {
      cin >> a[i] >> b[i];
    }
    REP(i,12) {
      l -= a[i]-b[i];
      if (l <= 0) {
        cout << i+1 << endl;
        f = 1;
        break;
      }
    }
    if (!f) {
      cout << "NA" << endl;
    }
  }
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(){
	int n,m,l,a,b;
	while(true){
	cin>>l;
	if(l==0)
		break;
	a=0;
	b=0;
	for(int i=1;i<=12;i++){
		cin>>m>>n;
		a+=m-n;
		if(a>=l&&b==0)
			b=i;
	}
	if(b==0)
		cout<<"NA"<<endl;
	else
		cout<<b<<endl;
	}
    return 0;
}

C++: #include <iostream>
#include <set>
#include <cstdio>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

using namespace std;

int main(){
  while(int l = getInt()){
    int sum = 0;
    int ans = 12;

    REP(i,12){
      int m = getInt();
      int n = getInt();

      sum += m - n;

      if(sum >= l)
	ans = min(ans, i);
    }

    if(ans == 12) puts("NA");
    else printf("%d\n", ans + 1);
  }
  return 0;
}

C++: #define _USE_MATH_DEFINES
#include<cstdio>
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<cmath>
#include<climits>
#include<map>
#include<string>
using namespace std;

int main(){
	int L, M, N;
	while(cin >> L, L){
		int sum = 0, ans = -1;
		for(int i = 1; i <= 12; i++){
			cin >> M >> N;
			sum += M - N;
			if(sum >= L && ans == -1) ans = i;
		}
		if(ans == -1) puts("NA");
		else printf("%d\n", ans);
	}
	return 0;
}

C++: #include<stdio.h>
int main(void)
{
	int w,n,z,x,i,k,c;
	while(1){
		scanf("%d",&n);
		 if(n==0) break;
	c=0;
	k=0;	 
	for(i=0;i<12;i++){
			scanf("%d %d",&z,&x);
			k+=z-x;
			if(k>=n){
				c++;
			}
	}
	if(k<n){
		printf("NA\n");
	}
	else{
		printf("%d\n",12-c+1);
	}
    }	
	return 0;
}

C++: #include<iostream>
#include<algorithm>
#define MONTH 12
using namespace std;
int main() {
	long l;
	while (cin >> l){
		if (l == 0)break;
		int n = 13;
		long sum = 0;
		for (int i = 0; i < MONTH; i++){
			long long a, b; cin >> a >> b;
			sum += a - b;
			if (sum >= l){
				n = min(n, i + 1);
			}
		}
		if (n == 13){
			cout << "NA";
		}
		else cout << n;
		cout << endl;
	}
	return 0;
}

C++: #include <cstdio>

int n;

int main(){
	while(scanf("%d", &n),n){
		int in, out, month = 0;
		bool ok = true;
		for(int i = 0; i < 12; i++){
			scanf("%d%d", &in, &out);
			n -= in-out;
			if(n <= 0 && month == 0) month = i+1;
		}
		if(n <= 0) printf("%d\n", month);
		else printf("NA\n");
	}
}

C++: #include <iostream>
#include <vector>
using namespace std;
int main(void)
{
	int cost,saving;
	vector< vector<int> > money(12,2);
	while(1){
		cin >> cost;
		if(cost==0) break;
		saving=0;
		for(int i=0;i<12;i++){
			cin >> money[i][0] >> money[i][1];
		}
		for(int i=0;i<12;i++){
			saving+=money[i][0]-money[i][1];
			if(cost<=saving){
				cout << i+1 << endl;
				break;
			}
		}
		if(cost<saving) cout << "NA" << endl;
		money.clear();
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

int main()
{

    int income,expense,month,tmp,cost;
    bool f;

    while(true){
        cin >> cost;
        if(cost == 0){
            break;
        }

        tmp = 0;
        f = false;
        month = 0;

        for(int i = 0; i < 12; ++i){
            income = 0;
            expense = 0;

            cin >> income >> expense;

            tmp += (income - expense);
//            cout << tmp << endl;
            if(tmp >= cost && !f){
                month = i+1;
                f = true;
//                cout << month << endl;
            }
        }

        if(month == 0){
            cout << "NA" << endl;
        }
        else{
            cout << month << endl;
        }
    }

}