Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	for scanner.Scan() {
		n, _ := strconv.Atoi(scanner.Text())
		if n == 0 {
			break
		}

		sales := make([]int, 4000)
		members := make([]int, 0)
		memberCheck := make(map[int]bool)

		for i := 0; i < n; i++ {
			scanner.Scan()
			input := strings.Split(scanner.Text(), " ")
			e, _ := strconv.Atoi(input[0])
			p, _ := strconv.Atoi(input[1])
			q, _ := strconv.Atoi(input[2])

			if e >= 1 && e <= 4000 && memberCheck[e] == false {
				members = append(members, e)
				memberCheck[e] = true
			}
			sales[e-1] += p * q
		}

		emptyFlag := true
		for _, v := range members {
			if sales[v-1] >= 1000000 {
				fmt.Println(v)
				emptyFlag = false
			}
		}

		if emptyFlag == true {
			fmt.Println("NA")
		}
	}
}

C++: #include <iostream>
#include <map>
#include <vector>
typedef long long ll;
using namespace std;
int main (int argc, char const* argv[]) {
  int N, id, price, num;
  const ll LIMIT = 1000000LL;
  while (true) {
    cin >> N;
    if (N == 0) break;
    map<int,pair<bool,ll> > dict;
    vector<int> id_list;
    for (int i = 0; i < N; i += 1) {
      cin >> id >> price >> num;
      ll tmp = (ll)price * (ll)num;
      // New
      if (dict.count(id) == 0) {
        if (LIMIT <= tmp) {
          dict.insert(make_pair(id,make_pair(true,0)));
        } else {
          dict.insert(make_pair(id,make_pair(false,tmp)));
        }
        id_list.push_back(id);
      // Add
      } else {
        if (dict[id].first) continue;
        if (LIMIT <= tmp + dict[id].second) {
          dict[id].first = true;
        } else {
          dict[id].second += tmp;
        }
      }
    }
    // Print
    bool printed = false;
    for (int i = 0; i < id_list.size(); i += 1) {
      if (dict[id_list[i]].first) {
        cout << id_list[i] << endl;
        printed = true;
      }
    }
    if (!printed) cout << "NA" << endl;
  }
  return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

int main()
{
	int n;
	while(cin >> n && n)
	{
		bool f = true;

		rep(i, n)
		{
			ll a, s, num;
			cin >> num >> a >> s;

			if(1000000 / a <= s)
			{
				f = false;
				cout << num << endl;
			}
		}

		if(f) cout << "NA" << endl;
	}
}

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

int main() {
	int num;
	int data_set = 0;
	bool do_continue = true;
	std::vector<string> result;

	while (do_continue) {
		cin >> num;
		if ((num == 0) || (data_set > 50)) {
			do_continue = false;
		}
		else {
			bool na_flg = true;
			data_set++;
			std::map<int, int> e;
			std::vector<int> employee;
			int fst, snd, thd;

			for (int i = 0; i < num; i++) {
				cin >> fst >> snd >> thd;
				employee.push_back(fst);
				if (e.count(employee[i])) {
					e[employee[i]] += snd * thd;
				}
				else {
					e[employee[i]] = snd * thd;
				}
			}

			for (unsigned int j = 0; j < employee.size(); j++) {
				if (e[employee[j]] >= 1000000) {
					na_flg = false;
					result.push_back(std::to_string(employee[j]));
				}
			}

			if (na_flg) {
				result.push_back("NA");
			}
		}
	}

	for (unsigned int i = 0; i < result.size()-1; i++) {
		cout << result[i] << endl;
	}


	return 0;
}

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

int main()
{
	int n;
	while(cin>>n&&n)
	{
		unsigned long long v[4001]={};
		vector<int> id,ans;
		for(int i=0;i<n;i++)
		{
			unsigned long long a,b,c;
			cin>>a>>b>>c;
			id.push_back(a);
			v[a]+=b*c;
		}
		for(int i=0;i<=4000;i++)
		{
			if(v[i]>=1000000)ans.push_back(i);
		}
		bool ok=true;
		for(int i=0;i<id.size();i++)
		{
			if(binary_search(ans.begin(),ans.end(),id[i]))
			{
				auto it=lower_bound(ans.begin(),ans.end(),id[i]);
				ans.erase(it);
				cout<<id[i]<<endl;
				ok=false;
			}
		}
		if(ok)cout<<"NA"<<endl;
	}
}

C++: #include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
int const MOD = 1000000007;
ll mod_pow(ll x, ll n) {return (!n)?1:(mod_pow((x*x)%MOD,n/2)*((n&1)?x:1))%MOD;}
int madd(int a, int b) {return (a + b) % MOD;}
int msub(int a, int b) {return (a - b + MOD) % MOD;}
int mmul(int a, int b) {return (a * b) % MOD;}
int minv(int a) {return mod_pow(a, MOD-2);}
int mdiv(int a, int b) {return mmul(a, minv(b));}

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

int rec[4010];
int n;
signed main() {
    while(cin >> n, n) {
        vector<int> v;
        memset(rec, 0, sizeof(rec));
        int cnt = 0;
        rep(i,0,n) {
            int e, p, q; cin >> e >> p >> q;
            rec[e] += p * q;
            auto itr = find(v.begin(), v.end(), e);
            if(itr == v.end()) v.push_back(e);
        }
        rep(i,0,v.size()) {
            if(rec[v[i]] >= 1000000) {
                cout << v[i] << endl;
                cnt++;
            }
        }
        if(!cnt) cout << "NA" << endl;
    }
    return 0;
}

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

int main()
{
	array<long long, 4000> ar = {};
	vector<long long> ans;
	int n,e,p,q;
	
	while (true) {
		cin >> n;
		ar.fill(0);
		if (!n) {
			break;
		}

		bool isNA = true;
		for (int i = 0; i < n; ++i) {
			cin >> e >> p >> q;
			ar[e] += p*q;
		}
		for (int i = 0; i < 4000;++i) {
			if (ar[i] >= 1000000) {
				ans.push_back(i);
				isNA = false;
			}
		}
		if (isNA) {
			ans.push_back(-1);
		}

	}

	for (auto it : ans) {
		if (it != -1) {
			cout << it << endl;
		}
		else {
			cout << "NA" << endl;
		}
	}
	return 0;
}