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 <bits/stdc++.h>
using namespace std ;

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;

const int mod = 1000000007;
constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll l,n,m;
  while(cin>>l&&l){
    ll ans = 0;
    rep(i,12){
      cin >> n >> m;
      l -= n - m;
      if(l <= 0 && !ans){
        ans = i+1;
      }
    }
    if(!ans){
      cout << "NA"<<endl;
    }
    else{
      cout << ans << endl;
    }
  }
  return 0;
}

C++: #include<stdio.h>

int main ()
{
int M,N,w,m;
long R;
w=0;m=0;
while(1)
{
w=0;m=0;
scanf("%ld",&R);
if(R==0)break;
for(int i=0;i<12;i++){
scanf("%d %d",&M,&N);
w=w+(M-N);m++;
if(w>=R)break;
}
if(w>=R)printf("%d\n",m);
else printf("NA\n");
}
return 0;
}

C++: #include<stdio.h>

int main(){
	while(1){
		int to=0,ans=-1;
		bool f=true;
		int e;
		scanf("%d",&e);
		if(e==0)return 0;
		for(int i=0;i<12;i++){
			int a,b;
			scanf("%d %d",&a,&b);
			if(f)to+=a-b;
			if(f&&to>=e){
				ans=i+1;
				f=false;
			}
		}
		if(ans==-1)printf("NA\n");
		else printf("%d\n",ans);
	}
}

C++: #include <iostream>
using namespace std;
int main()
{
  for(;;){
    int L;
    cin >> L;
    if(L == 0) break;
    int count = 1;
    for(int i=0; i<12; i++){
      int in,out;
      cin >> in >> out;
      L -= in - out;
      if(L > 0) count++;
    }
    if(L > 0) cout << "NA" << endl;
    else cout << count << endl;
  }
  return 0;
}

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

int main(void)
{
  int L,m,n,a=0;
  while(1){
    cin >> L ;
    if(L == 0) break;
    else{
      for(int i =1  ; i <= 12;++i){
        cin >> m >> n;
        a += m-n;
        if(a >= L){
          cout << i << endl; 
        }
      }
      if(a < L) cout << "NA" << endl;
    }
  }
  return 0;
}

C++: #include<stdio.h>

int main(void){
	int L,M,N,k[12],i,kai;

	while(0==0){
		scanf("%d",&L);
		if(L==0) break;
		kai=0;
		for(i=1;i<13;i++){
			scanf("%d %d\n",&M,&N);
			k[i]=M-N;
		}
        for(i=1;i<13;i++){
			L-=k[i];
			  if(L<=0){
				  kai=i;
				  break;
			  }
		}
		if(kai==0) printf("NA\n");
	    else printf("%d\n",kai);
	}
  return 0;
}

C++: #include<iostream>
using namespace std;
int main()
{
	long L, M, N, sum, i, k;
	while(1)
	{	
		sum = 0;
		cin >> L;
		if ( L == 0 )break;
		else
		{
			k = 1;
			sum = 0;
			for ( i = 0; i < 12; i++ )
			{
				cin >> M >> N;
				sum = sum + (M - N);
				if ( sum <= L )k++;
			}
			if ( sum < L )cout << "NA" << endl;
			else cout << k << endl;
		}
	}	
	return 0;
}

C++: #include<stdio.h>
int main(void)
{
	int w,n,z[12],x[12],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[i],&x[i]);
	}
	for(i=0;i<12;i++){
			k+=z[i]-x[i];
//			printf("%d\n",k);
			c++;	
		if(k>=n) break;
	}	
	if(c==0||c>=12){
		printf("NA\n");
	}
	else{
		printf("%d\n",c);
	}
   }
	return	0;
}

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

int main()
{
	int sum;
	int m,n;
	int mon;
	bool flag;
	while(cin >> sum){
		if(sum==0)
			break;
		flag = false;
		for(int i=0;i<12;i++){
			cin >> m >> n;
			sum -= (m-n);
			if(flag==false && sum<=0){
				flag = true;
				mon = i+1;
			}
		}
		if(flag==false)
			cout << "NA" << endl;
		else
			cout << mon << 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(){
  string res="";
  int m=0;
  for(int i=0;i<data.size();i++){
    m+=data[i].first-data[i].second;
    if(!(m<l)){
      return res+char('0'+i+1);
    }
  }
  return "NA";
}

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

C++: #include <cstdio>
#include <iostream>
#include <stdlib.h>
#include <iomanip>
#include <string> 
#include <sstream>  
#include <vector> 
#include <time.h>
#include <algorithm>
using namespace std;

int main(){
    int P;
    while(cin >> P){
        if(P == 0)break;
        int Money  = 0,answer = 0;
        int M,N;
        for(int i = 1;12 >= i;i++){cin >> M >> N;Money = Money + M - N;if(Money > P and answer == 0){answer = i;}}
        if(answer == 0){
            cout << "NA" << endl;
        }else{
            cout << answer << endl;
        }
    }
}

C++: #include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include <string>
#include <complex>
#include <functional>
using namespace std;
typedef pair<int,int> P;
double dat[100][100];
int dp[1000001];//動的計画法
int prime[1000001];
int main(){
    int l;
    int m[12],n[12];
    while(cin>>l,l){
        int mn=0,ch=0;
        for(int i=0;i<12;i++){
            cin>>m[i]>>n[i];
        }
        for(int i=0;i<12;i++){
            mn+=(m[i]-n[i]);
            if(mn>=l){
                cout<<i+1<<endl;
                ch++;
                break;
            }
        }
        if(ch==0) cout<<"NA"<<endl;
    }
    return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <stack>
#include <list>

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,b,n) for(int i=b;i<n;i++)
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

const float PI = 3.1415926;
static const int INFTY = (1<<30);

using namespace std;

typedef long long ll;
typedef long double ld;

int month, M, N, L;

int main() {
  while(cin >> L, L) {
    month = 0;
    
    rep(i, 12) {
      cin >> M >> N;
      L -= M - N;
      if(L <= 0 && month == 0) {
        month = i + 1;
      }
    }

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