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 <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+1){
			if(id[a[i]]>=1000000){
				cout<<a[i]<<endl;
				id[a[i]]=0;
				f=false;
			}
		}
		if(f) cout<<"NA"<<endl;
	}
	return 0;
}

C++: #include <stdio.h>

struct employees
{
	int i;
	int p;
	int q;
};

int main(void)
{
	int n, m, x, y, z;
	struct employees number[4000] = {0};

	scanf("%d", &m);
	n = 0;
	while (scanf("%d %d %d", &x, &y, &z) != EOF)
	{
		if (x == 0)
			break;
		if (x <= 4000 && y <= 1000000 && z <= 100000)
		{
			number[n].i = x;
			number[n].p = y;
			number[n].q = z;
			n++;
		}
		if (m <= n)
			break;
	}
	for (n = 0, m = 0; n < 4000; n++)
	{
		if (number[n].i == 0)
			break;
		if (number[n].q * number[n].p >= 1000000)
		{
			printf("%d\n", number[n].i);
			m++;
		}
	}
	if (m == 0)
			printf("NA\n");

	return 0;
}

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

int main() {
	int n;
	while(std::cin >> n){
		if(!n){
			return 0;
		}
		std::vector<std::pair<int, long long> > sales;
		while(n--){
			int id, unit, num;
			std::cin >> id >> unit >> num;
			int i = 0;
			for(; i < sales.size(); i++){
				if(sales.at(i).first == id){
					sales.at(i).second += (long long)unit * num;
					break;
				}
			}
			if(i == sales.size()){
				std::pair<int, long long> worker;
				worker.first = id;
				worker.second = (long long)unit * num;
				sales.push_back(worker);
			}
		}
		bool found = false;
		for(int i = 0; i < sales.size(); i++){
			if(sales.at(i).second >= 1000000){
				found = true;
				std::cout << sales.at(i).first << std::endl;
			}
		}
		if(!found){
			std::cout << "NA" << std::endl;
		}
	}
	return 0;
}

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

struct Saler
{
	int Number;
	int Saled;
};

int main(){
	struct Saler* sl;
	int n, a, b, c, i;
	bool isFound;
	
loop:
	scanf("%d", &n);		// データ個数
	if(n == 0) goto end_scope;
	sl = (struct Saler*)malloc(sizeof(struct Saler) * n);
	memset(sl, 0, sizeof(struct Saler)*n);
	for(int j = 0; j < n; j++)
	{
		scanf("%d %d %d", &a, &b, &c);
		for(i = 0; i < n; i++)
		{
			if(sl[i].Number == 0)
			{
				sl[i].Number = a;
				sl[i].Saled = b * c;
				break;
			}
			else if(sl[i].Number == a)
			{
				sl[i].Saled += b * c;
				break;
			}
		}
	}
	isFound = false;
	for(int j = 0; j < n; j++)
	{
		if(sl[j].Saled > 1000000)
		{
			cout << sl[j].Number << endl;
			isFound = true;
		}
	}
	!isFound && (cout << "NA" << endl);
	free(sl);
	goto loop;
end_scope:
    return 0;
}

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

int main(){
	int n, s, m, No;
	bool flag;
	
	while( cin >> n, n){
		flag = true;
		
		for(int i=0 ; i<n ; i++){
			cin >> No >> s >> m;
			if( s*m >= 1000000){
				flag = false;
				cout << No << endl;
			}
		}
		if(flag){
			cout << "NA" << endl;
		}
	}
	
	return 0;
}

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

using namespace std;

typedef pair<int,long long> pii;

#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<=k;i++)


int main(){
	int n,cnt,b,s,f;
	long long t,c;
	for(;;){
		scanf("%d",&n);
		if(n==0)break;
		cnt=0;
		vector<pii> v;
		rep(i,n){
			scanf("%d%d%d",&b,&t,&c);
			s=v.size();
			f=1;
			rep(i,s)if(v[i].first==b){
				v[i].second += t*c;
				f=0;
			}
			if(f)v.push_back(pii(b,t*c));
		}
		s=v.size();
		rep(i,s)if(v[i].second >= 1000000){
			printf("%d\n",v[i].first);
			cnt++;
		}
		if(cnt==0)puts("NA");
	}
	return 0;
}

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;
}