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 <cstdio>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <functional>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <typeinfo>
#define PI 3.14159265359
#define INF 99999999
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(n) rep(i, n)
#define EPS 1e-10
#define pb push_back
#define mp make_pair
typedef long long ll;
using namespace std;
typedef pair<int, int> P;

bool isLeap(int y);
ll gcd(ll a, ll b);
ll lcm(ll a, ll b);
double distanceAB(double xa, double ya, double xb, double yb);
void trace(int A[], int N);

/*
class Target
{
public:
	vector <string> draw(int n)
	{

	}
};
*/



int main()
{
	int n, id, price, num;
	map<int, ll> tbl;
	vector<int> vi;
	
	while (cin >> n, n)
	{
		tbl.clear();
		vi.clear();
		rep(i, n)
		{
			cin >> id >> price >> num;
			if (tbl.find(id) == tbl.end()) vi.push_back(id);
			tbl[id] += (ll)price * num;
		}
		bool flag = false;
		rep(i, vi.size())
		{
			if (tbl[vi[i]] >= 1000000)
			{
				cout << vi[i] << endl;
				flag = true;
			}
		}
		if (!flag) cout << "NA" << endl;
	}
	
	return 0;
}


bool isLeap(int y)
{
	return y % 400 == 0
						? true : y % 100 == 0
						? false : y % 4 == 0
						? true : false;
}

ll gcd(ll a, ll b)
{
	return (b > 0) ? gcd(b, a % b) : a;
}

ll lcm(ll a, ll b)
{
	return a / gcd(a, b) * b;
}

void trace(int A[], int N)
{
	REP(N)
	{
		if (i > 0) cout << " ";
		cout << A[i];
	}
	cout << endl;
}

double distanceAB(double xa, double ya, double xb, double yb)
{
	return sqrt((xb-xa)*(xb-xa) + (yb-ya)*(yb-ya));
}

C++: #include<stdio.h>
int main(void)
{
	int ct,num[4001],tanka[4001],kosu[4001],many[4001];
	while(scanf("%d",&ct)){
		if(ct==0){
			return 0;
		}
		for(int f1=0;f1<ct;f1++){
			scanf("%d %d %d",&num[f1],&tanka[f1],&kosu[f1]);
			many[f1]=tanka[f1]*kosu[f1];
		}
		for(int f1=0;f1<ct;f1++){
			for(int f2=0;f2<ct;f2++){
				if((num[f1]==num[f2])&&f1!=f2){
					many[f1]=many[f1]+many[f2];
					num[f2]=-1;
					many[f2]=-1;
				}
			}
		}
		int flg=0;
		for(int f1=0;f1<ct;f1++){
			if(many[f1]>=1000000){
				printf("%d\n",num[f1]);
				flg=1;
			}
		}
		if(flg==0){
			printf("NA\n");
		}
	}
	return 0;
}

C++: #include<cstdio>

int main(){
int a,i,fl;
unsigned long int b,c;
while(1){
scanf("%d",&i);
if(i==0) return 0;
fl=0;
for(int j=0;j<i;j++){


 scanf("%d",&a);
 scanf("%ld",&b);
 scanf("%ld",&c);
if(a*c>=1000000) {
 fl=1;
 printf("%d\n",a);
}
}
if(fl==0) printf("NA\n");
}
}

C++: #include<stdio.h>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <iterator>
#include <list>
#include <map>     
#include <numeric>
#include <utility>
#include <queue>
#include <set>
#include <sstream>
#include <iomanip>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
#define rep(a,t) for(int a=0;a<t;++a) 
#define forever while(true)
#define Sort(a) sort(a.begin(),a.end())
#define Reverse(a) reverse(a.begin(),a.end())
#define pb push_back
#define int_maxvalue numeric_limits<int>::max()
ll mod = 1e9 + 7;
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	while (1) {
		int n;
		cin >> n;
		if (n == 0) { break; }
		ll a[4001];
		rep(i, 4001) { a[i] = 0; }
		bool flag = false;
		rep(i, n) {
			ll d, p, q;
			cin >>  d >> p >> q;
			if (a[d] < 1000000) {
				if (p*q >= 1000000) {
					a[d] = 1000000;
				}
				else {
					a[d] += p*q;
				}
			}
			if (a[i] >= 1000000) {
				flag = true;
				cout << i << endl;
			}
		}
		/*for (int i = 1; i < 4001; i++) {
			if (a[i] >= 1000000) {
				flag = true;
				cout << i << endl;
			}
		}*/
		if (!flag) { cout << "NA" << endl; }
	}
	return 0;
}

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

class meb{
public:
	int num;
	int tanka;
	int count;
	int sum;
};

int main(){
	int n,m,t,c;
	while(1){
		int cc=0;
		cin>>n;
		meb st[n];
		if(n==0)return 0;
		for(int i=0;i<n;i++){
			cin>>st[i].num>>st[i].tanka>>st[i].count;
		}
		for(int k=0;k<n;k++){
			st[k].sum=st[k].tanka*st[k].count;
			cout<<st[k].sum<<endl;
		}
		for(int j=0;j<n;j++){
			for(int l=j+1;l<n;l++){
				if(st[j].num==st[l].num){
					(st[j].sum)=(st[j].sum)+(st[l].sum);
					st[l].sum=0;
				}
			}
		}
		for(int b=0;b<n;b++){
			cout<<st[b].num<<" "<<st[b].sum<<endl;
		}
		for(int a=0;a<n;a++){
			if(st[a].sum>=1000000)cout<<st[a].num<<endl;
			else cc++;
		}
		if(cc==n)cout<<"NA"<<endl;
	}
	return 0;
}

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

int main(){
    int n,i;
    while(cin>>n,n){
        map<int,long long>m;
        vector<int>vec;
        long long p,q,s=0;
        while(n--){
            cin>>i>>p>>q;
            if(!m[i])vec.push_back(i);
            m[i]+=p*q;
        }
//        for (map<int,long long>::iterator it=m.begin(); it!=m.end(); ++it){
//            if(it->second>=1000000){
//                s=1;
//                cout<<it->first<<endl;
//            }
//        }
        for (int i=0;i<vec.size();i++){
            if(m[vec[i]]>=1000000){
                s=1;
                cout<<vec[i]<<endl;
            }
        }
        if(!s)cout<<"NA"<<endl;
    }
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
int main() {
	int n;
	std::cin >> n;
	std::vector<int> A;
	while (n != 0) {
		std::vector<int> m(n);
		std::vector<std::vector<int>> V(n, std::vector<int>(3));
		for (int i = 0;i < n;++i) {
			for (int j = 0;j < 3;++j) {
				std::cin >> V[i][j];
			}
		}
		for (int i = 0;i < n;++i) {
			m[i] = V[i][1] * V[i][2];
		}
		sort(V.begin(), V.end());
		for (int i = 0;i < n;i++) {
			for (int j = 0;j < n;++j) {
				if (i < j) {
					if (V[i][0] == V[j][0]) {
						m[i] += m[j];
						m[j] = 0;
					}
				}
			}
		}
		for (int i = 0;i < n;++i) {
			if (m[i] >= 1000000) {
				A.push_back(V[i][0]);
			}
		}
		std::cin >> n;
	}
	return 0;
}

C++: #include<cstdio>
#include<cstring>

#define BUF 4000

typedef struct syaing
{
	int bango[BUF];
	int ne[BUF];
	int kazu[BUF];
} deta;

int main()
{
	deta f;
	int a,i,check[BUF],lek,kof[100000],nl=0;
	while(1)
	{
		memset(check,0,sizeof(int)*BUF);
		memset(f.bango,0,sizeof(int)*BUF);
		memset(f.kazu,0,sizeof(int)*BUF);
		memset(f.ne,0,sizeof(int)*BUF);
		lek=0;
		scanf("%d",&a);
		if(a==0)
			break;
		for(i=0;i<a;i++)
		{
			scanf("%d%d%d",&f.bango[i],&f.kazu[i],&f.ne[i]);
			if(f.kazu[i]*f.ne[i]>=1000000)
				check[i]=f.bango[i];
		}
		for(i=0;i<a;i++)
		{
			if(check[i]!=0)
			{
				lek++;
				kof[nl]=check[i];
				nl++;
			}
		}
		if(lek==0)
		{
			kof[nl]=0;
			nl++;
		}
	}
	for(i=0;i<nl;i++)
	{
		if(kof[i]==0)
			printf("NA\n");
		else
			printf("%d\n",kof[i]);
	}
	return 0;
}