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 <stdio.h>
#include <string>
#include <string.h>
#include <queue>
#include <cmath>

#define int64 long long int

using namespace std;
typedef pair<int, int> P;

int main()
{
    int flag[4001];
    int n, c, num, val, sale, na;
    P hoge[4001];
    
    while (1) {
        cin >> n;
        if(n == 0) break;
        
        c = 1;
        na = 1;
        memset(flag, 0, sizeof(int)*4001);
        
        for(int i=0; i<n; i++){
            cin >> num >> val >> sale;
            if(flag[num] == 0){
                flag[num] = c;
                hoge[c].first = num;
                hoge[c].second = val * sale;
                c++;
            } else {
                hoge[flag[num]].second += val * sale;
            }
        }
        for(int i=1; i<c; i++){
            if(hoge[i].second >= 1000000){
                na = 0;
                cout << hoge[i].first << endl;
            }
        }
        if(na == 1) cout << "NA" << endl;
    }
    return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int n;
  int t[5000]={0};
  long long sum[5000]={0};
  bool NA=true;
  while(cin>>n,n){
    NA=true;
    for(int i=0;i<5000;i++){
      t[i]=0; sum[i]=0;
    }
    int a,b,c;
    for(int i=0;i<n;i++){
      cin>>a>>b>>c;
      for(int j=0;j<5000;j++){
	if(t[j]==a)break;
	if(t[j]==0){t[j]=a;break;}
      }
      sum[a]+=b*c;
    }
    for(int i=0;i<5000;i++){
      if(sum[t[i]]>=1000000){
	cout<<t[i]<<endl; NA=false;
      }
    }
    if(NA)cout<<"NA"<<endl;
  }
}

C++: #include <iostream>

#define NUM_MAX 4000

using namespace std;

int main(void){
  int s[NUM_MAX];
  bool ss[NUM_MAX + 1];
  int n;
  int in1, in2, in3;

  while(true){
    
    cin >> n;

    if(n == 0) break;

    for(int i = 0; i < NUM_MAX; i++){
      s[i] = 0;
    }

    for(int i = 0; i < NUM_MAX + 1; i++){
      ss[i] = false;
    }

    for(int i = 0; i < n; i++){
      cin >> in1 >> in2 >> in3;
      s[in1] += in2 * in3;
      if(s[in1] >= 1000000){
	ss[in1] = true;
	ss[NUM_MAX] = true;
      }
    }
    
    if(!ss[NUM_MAX]){
      cout << "NA" << endl;
      continue;
    }
    
    for(int i = 0; i < NUM_MAX; i++){
      if(ss[i]){
	cout << i << endl;
      }
    }
  }

  return 0;
}

C++: #include<iostream>
#include<map>
#include<string>
using namespace std;
const int MAXN = 4020;
typedef long long ll;
int i,p,q;
bool isfind = false;
map<int,ll> total;

int main(){
  int n;
  while(1){
    cin >> n;
    if(n == 0)return 0;
    for(int k = 0;k < n;k++){
      cin >> i >> p >> q;
      total[i] += p*q;
    }
    for(map<int, ll>::iterator i = total.begin(); i != total.end(); ++i){
      if(i->second >= 1000000){
	isfind = true;
	cout << i->first << endl;
      }
    }
    if(!isfind)cout << "NA" << endl;
    total.clear();
    isfind =false;
  }
  return 0;
}

C++: #include<iostream>
#include<vector>;
using namespace std;
int main() {
	int n;
	while (cin >> n){
		if (n == 0)break;
		long long u[4010] = { 0 };
		vector<int>l;
		for (int i = 0; i < n; i++){
			long a, b, c;
			cin >> a >> b >> c;
			u[a] += b*c;
			if (u[a] >= 1000000 && find(l.begin(), l.end(), a) == l.end())l.push_back(a);
		}
		for (int i = 0; i < l.size(); i++){
			cout << l[i] << endl;
		}
		if (!l.size())cout << "NA" << endl;
	}
	return 0;
}

C++: /* {{{ Shinobu kawaii */
/*
  ______   __        _                  __                 
.' ____ \ [  |      (_)                [  |                
| (___ \_| | |--.   __   _ .--.   .--.  | |.--.   __   _   
 _.____`.  | .-. | [  | [ `.-. |/ .'`\ \| '/'`\ \[  | | |  
| \____) | | | | |  | |  | | | || \__. ||  \__/ | | \_/ |, 
 \______.'[___]|__][___][___||__]'.__.'[__;.__.'  '.__.'_/ 
                                                           
*/
/* }}} */
/* include {{{ */
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>
using namespace std;
/* }}} */

// #define int long long

/* cpp template {{{ */
/* short */
#define pb push_back
#define mp make_pair
#define print(x) cout << x << '\n'
#define Fi first
#define Se second

/* REPmacro */
#define REPS(i, a, n) for (int i = (a); i < (n); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = 1; i <= (n); i++)
#define DEPS(i, a, n) for (int i = (a); i >= n; i--)
#define DEP(i, n) for (int i = (n); i >= 0; i--)

/* typedef */
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef pair<int, int> pii;

/* const */
const int INF = 999999999;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool is_uruu(int y) {return (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0));}
inline bool inside(int y, int x, int H, int W) {return (y >= 0 && x >= 0 && y < H && x < W);}

/* }}} */

signed main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n;
  while (cin >> n, n){
    ll check[4001] = {0};
    REP(i, n){
      ll num, price, cnt;
      cin >> num >> price >> cnt;
      check[num] += price * cnt;
    }
    bool no = true;
    REP(i, 4001){
      if (check[i] >= 1e6){
        print(i);
        no = false;
      }
    }
    if (no) print("NA");
  }

  return (0);
}

C++: #include <iostream>
using namespace std;
int main()
{
	long long int n, no[4000], t[4000], num[4000], a[4000], i, j;
	while (cin >> n && n)
	{
		for (i = 0, j = 0; i < n; i++)
		{
			cin >> no[i] >> t[i] >> num[i];
			if (t[i] * num[i] >= 1000000)
				a[j] = no[i], j++;
		}
		if (j == 0)
			cout << "NA" << endl;
		else
			for (i = 0; i < j; i++)
				cout << a[i] << endl;
	}
	return 0;
}

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

int main()
{
	int n,id,sale,k,cnt,flg;
	while (1)
	{
		int outid[4001] = { 0 }, total[4001] = {0};
		cin >> n;
		if (n == 0)break;
		cnt = 0;
		flg = 0;
		for (int i = 0; i < n; i++)
		{
			cin >> id >> sale >> k;
			outid[i] = id;
			total[i] = sale*k;
		}

		for (int i = 0; i < n; i++)
		{
			for (int j = i+1; j < n; j++)
			{
				if (outid[i]==outid[j])
				{
					total[i] += total[j];
					cnt++;
				}
			}
		}

		for (int i = 0; i < n-cnt; i++)
		{
			if (total[i] >= 1000000)
			{
				cout << outid[i] << endl;
				flg = 1;
			}
		}

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

C++: #include<stdio.h>
#include<vector>
typedef long long ll;
int main()
{
	const int N=4001;
	int n,i,p,q;
	while(scanf("%d",&n),n)
	{
		ll e[N]={0};
		std::vector<int>d;
		while(n--)
		{
			scanf("%d%d%d",&i,&p,&q);
			if(!e[i])d.push_back(i);
			e[i]+=(ll)p*q;
		}
		for(i=n=0;i<d.size();++i)if(e[d[i]]>=1000000)n=printf("%d\n",d[i]);
		if(!n)puts("NA");
	}
	return 0;
}