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<algorithm>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
using namespace std;
int inf = 1000000000;

int main(void) {

  int n;
  while(cin >> n){
    if( n == 0 ) break;
    vector<long long int> ans;
    vector<long long int> u(4001, 0);
    for(int i=0; i<n; i++){
      long long int e, p, q;
      cin >> e >> p >> q;
      u[e] += p*q;
      // if( p * q >= 1000000 ) ans.push_back(e);
    }
    for(int i=0; i<4001; i++){
      if( u[i] >= 1000000 ) ans.push_back(i);
    }
    if( ans.size() == 0 ) cout << "NA" << endl;
    else for(int i=0; i<ans.size(); i++) cout << ans[i] << endl;
  }

  return 0;
}

// EOF

C++: 
int main(){

	long all[4001] = {};
	long code, a, b, n, i,j;

	while (1){
		j = 0;
		for (i = 0; i < 4001; i++){
			all[i] = 0;
		}


		cin >> n;
		if (n == 0){
			break;
		}

		for (i = 0; i < n; i++){
			cin >> code >> a >> b;
			all[code] += a*b;
			
		}

		for (i = 0; i < 4001; i++){
			if (all[i] >= 1000000){
				cout << i << endl;
				j++;
			}
		}

		if (j == 0){
			cout << "NA" << endl;
		}

	}
}

C++: #include<stdio.h>

int main(){
	long kazu,data[4000][3];
	long R[4000];
	long kaunto=0;
	long i,j;
	long number=0;
	
	scanf("%d",&kazu);
	while(kazu!=0){
		for(i=0;i<4000;i++){
			R[i]=0;
		}
		for(i=0;i<4000;i++){
			data[i][0]=i+1;
		}
		for(i=0;i<4000;i++){
			for(j=1;j<3;j++){
				data[i][j]=0;
			}
		}
		
		for(i=0;i<kazu;i++){
			scanf("%d",&number);
			scanf("%d %d",&data[number-1][1],&data[number-1][2]);
		}
		
		for(i=0;i<4000;i++){
			if(data[i][1]*data[i][2]>=1000000){
				R[kaunto]=data[i][0];
				kaunto++;
			}
		}
		
		kaunto=0;
		while(R[kaunto]!='\0'){
			printf("%d\n",R[kaunto]);
			kaunto++;
		}
		if(R[0]=='\0'){
			printf("NA\n");
		}
		
		kaunto=0;
		
		scanf("%d",&kazu);
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <math.h>
#include <map>
#include <queue>
#include <string>
using namespace std;

typedef long long ll;

int n,a,b,N;
ll s[4000][2];
string d;

int main(){
    while(cin>>N){
	if(N==0)return 0;
	for(int i=0;i<4000;i++){
	    for(int j=0;j<2;j++){
		s[i][j]=0;
	    }
	}
	int m=0;
	for(int i=0;i<N;i++){
	    cin>>n>>a>>b;
	    int flag=0;
	    for(int j=0;j<m;j++)if(s[j][0]==n){s[j][1]+=(ll)a*b;flag=1;}
	    if(flag==0){s[m][0]=n;s[m][1]=a*b;m++;}
	}
	int flag2=0;
	for(int i=0;i<m;i++)if(s[i][1]>999999){cout<<s[i][0]<<endl;flag2=1;}
	if(flag2==0)cout<<"NA"<<endl;
    }
}

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

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

		while(n--)
		{
			cin >> a >> b >> c;
			if(m.insert(pair<int,int>(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] << endl;
			}
		}
		if(f) cout << "NA" << endl;
	}
	return 0;
}

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

int main(){
  int n,i,p,q,f;
  for(;scanf("%d",&n),n;){
    map<int,int>m;
    vector<int>v;
    for(;n--;){
      scanf("%d%d%d",&i,&p,&q);
      if(m.find(i)==m.end())v.push_back(i);
      m[i]+=p*q;
    }
    for(f=i=0;i<v.size();i++){
      if(m[v[i]]>=1000000)printf("%d\n",v[i]),f=1;
    }
    if(!f)puts("NA");
  }
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
ll sums[4000];
bool used[4000];
int main()
{
	int n;
	while(cin>>n,n) 
	{
		vector<int> order;
		bool f=false;
		int num;
		int a,b;
		fill(sums,sums+4000,0);
		fill(used,used+4000,0);
		for(int i = 0; i < n; ++i)
		{
			cin>>num>>a>>b;
			sums[num-1]+=(ll)a*b;
			order.push_back(num-1);
		}
		for(int i = 0; i < order.size(); ++i)
		{
			if(!used[order[i]]&&sums[order[i]]>=1000000)
			{
				cout<<order[i]+1<<endl;
				f=true;
				used[order[i]]=true;
			}
		}
		if(!f) cout<<"NA"<<endl;
	}
  return 0;
}

C++: #include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int dx[] = { -1, 0, 1, 0 }; const int dy[] = { 0, 1, 0, -1 };
struct salary{
	int no;
	long long int sell;
};

int main() {
	
	int n;
	while(cin>>n,n){
		vector<salary> vs;
		set<int> si;
		REP(i, n){
			int no;
			long long int v,sum;
			cin >> no >> v >> sum;
			if (si.find(no) == si.end()){
				vs.push_back({ no, (long long int)(v*sum) });
				si.insert(no);
			}
			else
				REP(j, vs.size()){
				if (vs[j].no == no)
					vs[j].sell += (long long int)(v*sum);
			}
		}
		bool b = false;
		REP(j, vs.size()){
			if (vs[j].sell >= 1000000){
				cout << vs[j].no << endl;
				b = true;
			}
		}
		if (!b)
			cout <<"NA" << endl;
	}
}

C++: #include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <cfloat>
#include <map>
using namespace std;
int main(){
	
	int n;
	
	while(cin>>n,n!=0){
		int a,b,c;
		int f=0;
		long long int s[4001]={0};
		
		for(int i=0;i<n;i++){
			cin>>a>>b>>c;
			s[a]+=b*c;
		}
		for(int i=1;i<4000;i++){
			if(s[i]>=1000000){
				cout<<i<<endl;
				f=1;
			}
			
		}
		if(f!=1)
			cout<<"NA"<<endl;
	
	}
	
}

C++: #include <bits/stdc++.h>
using namespace std;

int main()
{
  int n;
  while (cin >> n, n){
    bool f = false;
    map<int, long> mil;
    vector<int> vi;
    int e, p, q;
    for (int i = 0; i < n; i++){
      cin >> e >> p >> q;
      if (mil[e] == 0) vi.push_back(e);
      mil[e] += p * q;
    }

    int m = vi.size();
    for (int i = 0; i < m; i++){
      if (mil[vi[i]] >= 1000000) {
        cout << vi[i] << "\n";
        f = true;
      }
    }
    if (!f) cout << "NA\n";
  }
}

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

int main(){
    long long size, id, price, quantity;
    bool noone = true;
    while (1){
	cin >> size;
	if (!size) break;
	for (int i = 0; i < size; i++){
	    cin >> id >> price >> quantity;
	    if (price * quantity >= 1000000){
		cout << id << endl;
		noone = false;
	    }
	}
	if (noone) cout << "NA" << endl;
	noone = true;
    }
}