Go: package main

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

func main() {
	stdin := bufio.NewScanner(os.Stdin)

	for stdin.Scan() {
		n, _ := strconv.Atoi(stdin.Text())
		if n == 0 {
			break
		}
		sales := make(map[string]int)
		existed := make(map[string]bool)
		order := make([]string, 4000)
		flg := false
		for i := 0; i < n; i++ {
			stdin.Scan()
			l := strings.Split(stdin.Text(), " ")
			e := l[0]
			p, _ := strconv.Atoi(l[1])
			q, _ := strconv.Atoi(l[2])
			sales[e] += p * q
			if !existed[e] {
				order = append(order, e)
				existed[e] = true
			}
		}
		for _, v := range order {
			if sales[v] >= 1000000 {
				fmt.Println(v)
				flg = true
			}
		}
		if flg == false {
			fmt.Println("NA")
		}
	}
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <set>

using namespace std;

int main()
{
	while (1)
	{
		int a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0;
		int box[4000];
		for (int i = 0; i < 4000; i++)
		{
			box[i] = 0;
		}
		cin >> a;
		if (a == 0)
		{
			break;
		}
		for (int i = 0; i < a; i++)
		{
			cin >> b;
			cin >> c;
			cin >> d;
			box[b - 1] += c * d;
		}
		for (int i = 0; i < 4000; i++)
		{
			if (box[i] >= e)
			{
				e = box[i];
				f = b + 1;
			}
		}
		if (e <= 1000000)
		{
			cout << "NA" << endl;
		}
		else
		{
			cout << b << endl;
		}
	}
	
	return 0;
}

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

int main(){
	int n;
	while (cin >> n)
	{	bool f = false;
		int e[4000], p[4000], q[4000], t[4000];
		for (int i = 0; i < n; i++)
		{
			cin >> e[i];
			cin >> p[i];
			cin >> q[i];
			t[i] = p[i] * q[i];
		}

		for (int a = 0; a < n; a++)
		{
			if (t[a] >= 1000000)
			{
				cout << e[a] << endl;
				f = true;
			}
		
		
		}
		if (!f)
		{
			cout << "NA" << endl;
		}
	}
	return 0;
}

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

int main() {
	int n;
	while (cin >> n, n) {
		int e;
		long long p, q;
		long long number[4000];
		bool t[4000];
		queue<int>v;
		for (int i = 0;i < 4000;i++) {
			number[i] = 0;
			t[i] = false;
		}

		for (int i = 0;i < n;i++) {
			cin >> e >> p >> q;
			number[e - 1] += p*q;
			
			if (t[e - 1] == false) {
				if (number[e - 1] >= 1000000) {
					v.push(e);
					t[e - 1] = true;
				}
			}
		}

		int a = v.size();
		if (v.empty()) { cout << "NA" << endl; }
		else {
			for (int i = 0;i < a;i++) {
				cout << v.front() << endl;
				v.pop();
			}
		}
	}
	return 0;
}

C++: #include<iostream>
#include<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<unordered_map>
#include<queue>
#include<vector>
using namespace std;

#define int long long
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) {cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) {cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;

signed main() {
	int E[4010] = {};
	bool F[4010] = {};
	for (int n; cin >> n&&n;) {
		memset(E, 0, sizeof(E));
		memset(F, 0, sizeof(F));
		bool flag = true;
		rep(i, 0, n) {
			int e, p, q; cin >> e >> p >> q;
			E[e] += p*q;
			if (E[e] >= 1000000 && !F[e]) {
				flag = false;
				F[e] = true;
				cout << e << endl;
			}
		}
		if (flag)cout << "NA" << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
#include <cmath>
#include <complex>
#include <map>
using namespace std;

#define rep(i,n) for(int i=0;i<int(n);++i)

static const double PI=6*asin(0.5);
typedef complex<double> P;
typedef long long ll;


ll n;

int main(){
	while(cin>>n,n!=0){
		ll id[4005]={0};
		int a[8000]={0};
		
		int cou;
		rep(i,n){
			ll t1,t2,t3;
			cin>>t1>>t2>>t3;
			a[i]=t1;
			//if(id[t1]>0){
				id[t1]+=t2*t3;
			//}
			/*
			else{
				id[t1]=t2*t3;
			}
			*/
			cou=i;
		}
		bool f=true;
		rep(i,cou){
			if(id[a[i]]>=1000000){
				cout<<a[i]<<endl;
				id[a[i]]=0;
				f=false;
			}
		}
		if(f) cout<<"NA"<<endl;
	}
	return 0;
}

C++: #include <vector>
#include <string>
#include <utility>
#include <iostream>
#include <algorithm>
using namespace std;
using worker_t = pair<string,int>;

int main() {
	while (true) {
		int n; // number of workers
		cin >> n;
		if (n == 0) {
			break;
		}
		vector<worker_t> v;
		while (n--) {
			string i;
			int q,p;
			cin >> i >> q >> p;
			auto w_itr = find_if(v.begin(),v.end(),[i](worker_t w) { return w.first == i; });
			if (w_itr == v.end()) { // if the worker not exist
				v.push_back({i,q*p});
			} else {
				w_itr->second += q*p;
			}
		}
		int count = 0;
		for (auto itr = v.begin();itr != v.end();++itr) {
			if (itr->second >= 1000000) {
				cout << itr->first << endl;
				++count;
			}
		}
		if (count == 0) {
			cout << "NA" << endl;
		}
	}
}

C++: #include<iostream>
#include<cstdio>
#include<vector>

using namespace std;

struct data{
  int id;
  int  price;
  int  amount;
  long long rate;
};

int main(){
  int n=0;
  while(1){
    cin>>n;
    if(n==0){return 0;}
    vector<struct data> data(n);
    int c=0;
    for(int i=0;i<n;i++){
      scanf("%d %d %d",&data[i].id,&data[i].price,&data[i].amount);
      data[i].rate=data[i].price*data[i].amount;
    }
    vector<struct data> res(n);
    for(int i=0;i<n;i++){
      res[i].id=0;
      res[i].rate=0;
    }
    for(int i=0;i<n;i++){
      int find=0;
      for(int j=0;j<i;j++){
	if(data[i].id==res[j].id){
	  res[j].rate+=data[i].rate;
	  find=1;
	  break;
	}
      }
      if(find==0){
	res[i].id=data[i].id;
	res[i].rate=data[i].rate;
      }
    }
    for(int i=0;i<n;i++){
      if(res[i].id!=0&&res[i].rate>=1000000){
	cout<<data[i].id<<"\n";
	c++;
      }
    }
    if(c==0){
      cout<<"NA\n";
    }
  }
  return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
void shoki();
	vector<long long> num(3999,0);
	int n,ban,tanka,kazu,i,j;
int main(){
	bool y=false;
	for(j=0;j<50;j++){
		cin>>n;
		if(n==0){
			break;
		}
		int count=0;
		for(i=0;i<n;i++){
			cin>>ban>>tanka>>kazu;
			num[ban]+=tanka*kazu;
		}
		for(int k=0;k<3999;k++){
			if(num[k]==0){
				continue;
			}
			if(num[k]>=1000000){
				y=true;
				cout<<k<<endl;
			}
		}
		if(y==false){
			cout<<"NA"<<endl;
		}
		y=false;
		shoki();
	}
	return 0;
}
void shoki(){
	for(int i=0;i<3999;i++){
		num[i]=0;
	}
}

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

int main()
{
	long long n,a,b,c;
	while(cin >> n, n)
	{
		vector<long long>  v;
		map<long long,long long> m;

		while(n--)
		{
			cin >> a >> b >> c;
			if(m.insert(pair<long long,long long>(a,b*c)).second)
			{
				v.push_back(a);
			}
			else
			{
				m[a] += b*c;
			}
		}

		bool f=true;
		for(int i=0; i<v.size(); i++)
		{
			if(m[v[i]]>=1000000)
			{
				f=false;
				cout << v[i] << " " << m[v[i]] << endl;
			}
		}
		if(f) cout << "NA" << endl;
	}
	return 0;
}

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

int A[1000000];

signed main(){
	int N,B,C;
	while(cin>>N,N){
		int cnt[4001]={};
		bool NAflag=true,used[4001]={};
		for(int i=0;i<N;i++){
			cin>>A[i]>>B>>C;
			cnt[A[i]] += B*C;
		}
		for(int i=0;i<N;i++){
			if(cnt[A[i]]>=1000000 && used[A[i]]==false){
				printf("%d\n",A[i]); used[A[i]] = true; NAflag = false;
			}
		}
		if(NAflag==true) puts("NA");
	}
    return 0;
}