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>
using namespace std;

int main() {
	long long int i, n, no[4000], tanka[4000], num[4000];
	bool flg=false;
	while (1) {
		flg=false;
		cin>>n;
		if (n==0) break;
		for (i=0; i<n; i++)
			cin>>no[i]>>tanka[i]>>num[i];
		for (i=0; i<n; i++) {
			if (tanka[i]*num[i]>=1000000)
				flg=true, cout<<no[i]<<endl;
		}
		if (flg==false) cout<<"NA"<<endl;
	}
	return 0;
}

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

int main() {
  int n;

  while(cin >> n, n) {
    vector<int> ans;
    int e, p, m;

    for(int i = 0; i < n; i++) {
      cin >> e >> p >> m;
      if(p*m >= 1000000) {
	bool b = true;
	auto it = ans.begin(); 
	while(it != ans.end()) {
	  if(*it == e) b = false;;
	  it++;
	}
	if(b) ans.push_back(e);
      }
    }
    

    if(ans.empty()) {
      cout << "NA" << endl;
    } else {
      auto it = ans.begin();
      while(it != ans.end()) {
	cout << *it << endl;
	it++;
      }
    }
  }
}

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

int main()
{
	int n;

	while (cin >> n, n){
		long long e[5000] = {0}, p, q, t;
		bool out = false, f = false;
		vector<int> s;
		for (int i = 0; i < n; i++){
			cin >> t >> p >> q;
			for (int j = 0; j < s.size(); j++){
				if (s[j] == t){
				 	f = true;
					break;
				}
			}
			if (f == false){
				s.push_back(t);
			}
			e[t] += p * q;
		}
		for (int i = 0; i < s.size(); i++){
			if (e[s[i]] >= 1000000){
				cout << s[i] << endl;
			  out = true;
			}
		}
		if (out == false) cout << "NA" << endl;
	}
	return (0);
}

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

using namespace std;

int n;
long long id[4000];
 long long value[4000];
 long long number[4000];
map<long long,  long long> total;

int main() {
  while(true){
    cin >> n;
    if(n==0){
        return 0;
    }
    vector<long long> v;
    for (int i = 0; i < n; i++) {
        cin >> id[i] >> value[i] >> number[i];
        if(total.find(id[i])==total.end()){
          total.insert(make_pair(id[i], 0));
        }
        total[id[i]] += value[i] * number[i];
        // if (total[id[i]] > 1000000 && find(v.begin(), v.end(), id[i]) == v.end()) {
        //   v.push_back(id[i]);
        // }
    }
    if(!total.empty()) {
        map< long long,  long long>::iterator it = total.begin();
        while (it != total.end()) {
            if ((*it).second >= 1000000) {
                v.push_back((*it).first);
            }
            ++it;
        }
    }
    if (v.empty()) {
        cout << "NA" << endl;
    }
    // for (vector<long long>::iterator it = v.begin(); it != v.end(); ++it) {
    //     cout << *it << endl;
    // }
    vector<long long> used;
    for(int i=0; i<n;i++){
      if(std::find(v.begin(), v.end(), id[i]) != v.end() && std::find(used.begin(), used.end(), id[i]) == used.end()){
        cout << id[i] << endl;
        used.push_back(id[i]);
      }
    }
    v.clear();
    total.clear();
  }
}

C++: #include<iostream>
#include<string>
using namespace std;
int a[4000];
bool check[4000];
int main(){
	int n;
	while(true){
	cin>>n;
	if(n==0)
		break;
	for(int i=0;i<4000;i++){
		a[i]=0;
		check[i]=true;
	}
	bool na=true;
	int b,c,d;
	for(int i=0;i<n;i++){
		cin>>b>>c>>d;
		a[b-1]+=c*d;
		if(a[b-1]>=1000000&&check[b-1]==true){
			check[b-1]=false;
			na=false;
			cout<<b<<endl;
		}
	}
	if(na==true)
		cout<<"NA"<<endl;
	}
	return 0;
}

C++: // #define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>	// istringstream
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;

#define MP make_pair
#define fastIO	cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
//for gcc (未test)
// #define FOREACH_IT(it,c)	for(typeof(c)::iterator it=(c).begin(); it!=(c).end(); ++it)
//for Visual Studio
#define foreach_it(type,it,c) for(type::iterator it=c.begin(); it!=c.end(); ++it)

// #defineの初利用にあたって参考にした http://peroon.hatenablog.com/entry/20091123/1258966199
// iteratorのforLoop                   http://bokko.hatenablog.com/entry/20090320/1237494217
// fastIO                              https://gist.github.com/rigibun/7905920

void solveAndOutput(map<int, long long> data, VI bangouList){
	int outputCount = 0;

	FOR(i, 0, bangouList.size()){
		if (data[bangouList[i]] >= 1000000){
			cout << bangouList[i] << endl;
			outputCount++;
		}
	}
	if (outputCount == 0)
		cout << "NA" << endl;
}

int main(){
	// sankou http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=97994#1

	long long n;
	// 重複なし、自動ソート
	map<int, long long> data;
	// 重複あり、ソートなし -> 重複するものは格納しないようにしたい.
	VI bangouList;
	fastIO;

	while (cin >> n, n){
		data.clear();
		bangouList.clear();
		while (n--){
			int bangou = 0, tanka = 0, suu = 0;
			cin >> bangou >> tanka >> suu;
			if(data[bangou] == 0)
				bangouList.push_back(bangou);
			data[bangou] += (tanka * suu);
		}
		solveAndOutput(data, bangouList);
	}
	return 0;
}

C++: #include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
using namespace std;
typedef long long ll;
int main(){
  while(1){
    ll i,b[4010],a[4010],n,e[4010],p,q,k=0;
    scanf("%lld\n",&n);
    if(n==0){
      return 0;
    }
    for(i=0;i<=4000;i++){
      a[i]=0,b[i]=0;
    }
    for(i=0;i<n;i++){
      scanf("%lld %lld %lld\n",&e[i],&p,&q);
      a[e[i]]+=p*q;
    }
    for(i=0;i<n;i++){
      if(b[e[i]]==0 && a[e[i]]>=1000000){
        b[e[i]]=1;
        printf("%lld\n",e[i]);
        k++;
      }
    }
    if(k==0){
      printf("NA\n");
    }
  }
  return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <stdio.h>
#include <string>
#include <string.h>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#include <vector>
#include <algorithm>

#define int64 long long int
using namespace std;

typedef pair<int, int> P;

int main()
{
	int n, num, val, sale, c;
	P data[4000];
	int flag[4001];
	bool na;
	while(1){
		na = true;
		memset(flag, 0, sizeof(int)*4001);
		c = 1;

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

		for(int i=0; i<n; i++){
			cin >> num >> val >> sale;
			if(!flag[num]){
				flag[num] = c;
				data[c].first = num, data[c].second = val * sale;
				c++;
			}else data[flag[num]].second += val * sale;
		}

		for(int i=1; i<c; i++){
			if(data[i].second >= 1000000){
				na = false;
				cout << data[i].first << endl;
			}
		}
		if(na) cout << "NA" << endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
long sum[4001],p,q;
int n,e;
main()
{
	while(cin>>n,n)
	{
		for(int i=0;i++<4000;)sum[i]=0;
		for(;n--;)
		{
			cin>>e>>p>>q;
			sum[e]+=p*q;
		}
		bool f=0;
		for(int i=0;i++<4000;)
		{
			if(sum[i]>=1e6)
			{
				f=1;
				cout<<i<<endl;
			}
		}
		if(!f)cout<<"NA"<<endl;
	}
}