Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	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
			}
		}
		fmt.Println("NA")
	}
}

C++: #include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <limits>
#include <sstream>

using namespace std;

int main (void)
{
	for (long u = 0; u < 1000; u++)
	{
		long long n;
		long a[13],b[13];

		cin >> n;
		if (n == 0)
		{
			break;
		}

		for (int i = 0; i < 12; i++)
		{
			cin >> a[i] >> b[i];
		}

		int p = 0;

		for (int i = 0; i < 12; i++)
		{
			p += a[i] - b[i];
			if (p >= n)
			{
				cout << i + 1 << endl;
				break;
			}
			if (i == 11)
			{
				cout << "NA" << endl;
				break;
			}
		}
	}
}

C++: #include <iostream>

using namespace std;

int main() {

	int j, l, m, n, t;

	while(cin >> l) {
		if(l==0)
			break;
		t=0;
		j=0;
		for(int i=1; i<=12; i++) {
			cin >> m >> n;
			t+=m-n;
			if(t>=l&&j==0) 
				j=i;
		}
		if(t>=l)
			cout << j << endl;
		else
			cout << "NA" << endl;
	}

	return 0;

}

C++: #include<iostream>
using namespace std;
int main() {
	int month[1001];
	long m, n, l, y = 0, k = 0;
	int x;
	for (int i = 0; i < 1001; i++){
		month[i] = 0;
	}
	for (int i = 0;; i++){
		k = 0;
		cin >> l;
		if (l == 0){
			x = i;
			break;
		}
		for (int j = 0; j < 12; j++){
			cin >> m >> n;
			y += (m - n);
			if (y >= l&&k == 0) {
				k = j;
				month[i] = k;
			}
		}
	}
	for (int i = 0; i < x; i++){
		if (month[i] == 0){
			cout << "NA";
		}
		else cout << month[i]+1;
		cout << endl;
	}
}

C++: #include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

ll l;
int main() {
  while (scanf("%lld", &l), l) {
    int ans = -1;
    ll sum = 0;
    REP(i, 12) {
      ll m, n;
      scanf("%lld %lld", &m, &n);
      sum += m - n;
      if (sum >= l && ans == -1) { ans = i; }
    }
    if (ans == -1) {
      puts("NA");
    } else {
      printf("%d\n", ans + 1);
    }
  }
}

C++: #include<stdio.h>
int main(){
	int L,M,N,t=0,c=0,i;
	for(;;t=0,c=0){
		scanf("%d",&L);
		if(L==0)break;
		for(i=0;i<12;i++){
			scanf("%d%d", &M, &N);
			t+=M-N;
			if(t>=L&&c==0)c=i;
		}
		if(c!=0)printf("%d\n",c+1);
		else puts("NA");
	}
	return 0;
}

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

int main() {
    int L;
    while ( cin >> L && L ) {
        int answer = -1;
        int sum = 0;
        for ( int i = 1; i <= 12; ++ i ) {
            int M, N;
            cin >> M >> N;
            sum += M - N;
            if ( sum >= L && answer == -1 ) {
                answer = i;
            }
        }
        if ( answer == -1 ) {
            cout << "NA" << endl;
        } else {
            cout << answer << endl;
        }
    }
    return 0;
}

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

int l;
typedef pair<int,int> pii;
vector<pii> data;
void init(){
  data.clear();
}


bool input(){
  if(!(cin>>l))return false;
  if(l==0)return false;
  for(int i=0;i<12;i++){
    int m,n;
    cin>>m>>n;
    data.push_back(pii(m,n));
  }
  return true;
}

string solve(){
  int res=0;
  int m=0;
  for(int i=0;i<data.size();i++){
    m+=data[i].first-data[i].second;
    if(!(m<l)){
      return ""+char(i+'0');
    }
  }
  return "NA";
}

int main(){
  while(init(),input()){cout<<solve()<<endl;}
}

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

int main() {
    while (true) {
        int L;
        cin >> L;
        if (L == 0) {
            break;
        }
        int saving = 0;
        int result = 0;
        for (int i = 0; i < 12; i++) {
            int M, N;
            cin >> M >> N;
            saving += M - N;
            if (L <= saving && result == 0) {
                result = i + 1;
            }
        }
        if (result > 0) {
            cout << result << endl;
        } else {
            cout << "NA" << endl;
        }
    }
}

C++: #include <iostream>

using namespace std;

int main() {
  for (;;) {
    int L, M[12], N[12];
    cin >> L;
    if (!L) return 0;
    int r = 0;
    for (int i = 0; i < 12; i++)
      cin >> M[i] >> N[i];
    for (int i = 0; i < 12; i++) {
      r += M[i] - N[i];
      if (r >= L) {
        cout << i + 1 << endl;
        break;
      }
    }
    if (r < L)
      cout << "NA" << endl;
  }
}

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 l, m, n;
	while (scanf("%d", &l), l)
	{
		int ans = 0;
		for (int i = 0; i < 12; ++i)
		{
			int t;
			scanf("%d %d", &m, &n);
			l -= m - n;
			if (l <= 0 && !ans)
				ans = i+1;
		}
		if (ans)
			printf("%d\n", ans);
		else
			puts("NA");
	}

	return 0;
}

C++: #include <cstdio>

#define REP(a, n) for (int i = (a); i < n; i++)

using namespace std;

int main()
{
  int l, m, n;
  
  while (scanf("%d", &l), l != 0){
    int sum = 0, month = 1;
    bool flag = true;
    REP(0, 12){
      scanf("%d%d", &m, &n);
      sum += m - n;
      if (sum >= l) flag = false;
      if (flag) month++;
    }
  
    if (month <= 12) printf("%d\n", month);
    else printf("NA\n");
  }

  return (0);
}

C++: #include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)

const int INF = 10000000;
using namespace std;
typedef long long  ll;

/** Problem0206 : Next Trip **/
int main()
{
	int L, a, b, sum, ans;
	while (cin>>L) {
		ans=0; sum=0;
		rep(i, 12) {
			cin >> a >> b;
			sum+=a-b;
			
			if (ans>0) continue;
			
			if (sum>=L) {
				ans = i+1;
			}
		}
		if (ans>0)
			cout << ans << endl;
		else
			cout << "NA" << endl;
	}
	return 0;
}

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

C++: #include <iostream>

using namespace std;

int main() {
	int L;
    while(1){
        cin>>L;
        if(!L)break;
        
        int A[12],M,N;
        for(int i=0;i<12;i++){
            cin>>M>>N;
            A[i] = M-N;
        }
        
        int sum=0;
        for(int i=0;i<13;i++){
            if(i == 12){
                cout<<"NA"<<endl;
                break;
            }
            sum += A[i];
            if(sum >= L){
                cout<<i+1<<endl;
                break;
            }
        }
    }
	return 0;
}