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

C++: #include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <complex>
#include <ctime>
#include <cstdlib>

using namespace std;

inline int to_int(string s) {int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string to_str(T x) {ostringstream sout; sout << x; return sout.str();}

typedef long long ll;

int main()
{
	int border;
	int a, b, sum, ans;
	bool ok;

	while(cin >> border ,border)
	{
		sum = 0;
		ok = false;
		for(int i = 1; i <= 12; i++)
		{
			cin >> a >> b;
			sum += (a - b);

			if(border <= sum && ok == false)
			{
				ok = true;
				ans = i;
			}
		}

		if(ok == true)
		{
			cout << ans << endl;
		}
		else
		{
			cout << "NA" << endl;
		}
	}
}

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

int main(){
  int L,M,N;

  while(cin >> L){
    if(L==0) break;
    int  money=0;
    bool flag = false;

    for(int i=0; i<12; i++){
      cin >> M >> N;
      money += M - N;

      if(L <= money && flag == false){
	cout << i+1 << endl;
	flag = true;
	continue;
      }
    }
    if(flag == false) cout << "NA" << 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 l, m[12], n[12];
	while (cin >> l && l != 0)
	{
		for (int i = 0; i < 12; i++)
			cin >> m[i] >> n[i];
		for (int i = 0; i < 12; i++)
		{
			l -= (m[i] - n[i]);
			if (l <= 0)
			{
				cout << i + 1 << endl;
				break;
			}
			if (i == 11)
				cout << "NA" << endl;
		}
	}

	return 0;
}

C++: #include <iostream>
#include <cstdio>
using namespace std;
int main(){
  int i ,j=0 ,n ,m ,L ,tmp ,savings=0;
  while( 1 ){  // 目標金額
    cin >> L;
    if( L == 0 ){
      break;
    }

    if( L == 0 ){
      break;
    }
    
    for( i=1 ; i<=12 ; i++ ){
      cin >> m >> n;       // 小遣い　使用金額
      savings = savings + ( m - n );
      if( savings >= L && j == 0 ){
	tmp = i;
	j++;
      }
    }
    
    if( j != 0 ){
      cout << tmp << endl;
    }

    else{
      cout << "NA" << endl;
    }
    savings = 0;
    j=0;
  }

  return 0;
}

C++: #include<iostream>
#include<algorithm>
#define MONTH 12
using namespace std;
int main() {
	long l;
	while (cin >> l){
		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;
	}
}

C++: // clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int l;
  while (cin >> l, l) {
    vi v(12);
    rep(i, 12) {
      int m, n;
      cin >> m >> n;
      v[i] = m - n;
    }
    int s = 0;
    rep(i, 12) {
      s += v[i];
      if (s >= l) {
        cout << i + 1 << endl;
        goto next;
      }
    }
    cout << "NA" << endl;
  next:;
  }
}