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>
#include<map>
#include<algorithm>
using namespace std;
main(){
 while(1){
  int n,a,b,c;
  cin>>n;
  if(n==0) break;
  map<long,int> m;
  for(;n>0;n--){
   cin>>a>>b>>c;
   m.insert(map<long,int>((long)b*c,a));
  }
  m.sort();
  cout<<(m.begin()).first<<endl;
 }
 cout<<"NA"<<endl;
}

C++: //AOJ 0100
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cctype>
using namespace std;
#define MAX_N 100
 
unsigned long long int a[4001] = {0}, b, i, j, k, ans, n;
char str[1000];
 
int sort(const void *a, const void *b){
  return *(int*)a - *(int*)b;
}
 
int main(){
  while(scanf("%lld", &n) != 0){
    if(n == 0) return 0;
    ans = 0;
    for(i = 0; i < 4001; i++)
      a[i] = 0;
    for(i = 0; i < n; i++){
      scanf("%lld %lld %lld", &b, &k, &j);
      if(a[b] >= 1000000) continue;
      a[b] += k * j;
      if(a[b] >= 1000000){
    printf("%lld\n", b);
    ans++;
      }
    }
    if(ans == 0) printf("NA\n");
  }
  return 0;
}

C++: #include<stdio.h>

int main(){
int N;
int n,m,p;
long P[4001][3]={};
long PT[4001][4]={};

while(1){
scanf("%d",&N);if(N==0)break;

for(int i=1;i<=N;i++){
scanf("%d %d %d",&n,&m,&p);
P[n][0]+=m*p;if(P[n][1]==0)P[n][1]=i;
}
int c=0;
for(int i=0;i<4000;i++)
if(1000000<=P[i][0]){PT[c][0]=P[i][0];PT[c][1]=P[i][1];PT[c][2]=i;c++;}

for(int i=0;i<c;i++)
for(int j=c-1;j>i;j--)
if(PT[j][1]<PT[j-1][1])
{int TT=PT[j][1];PT[j][1]=PT[j-1][1];PT[j-1][1]=TT;
 int TTT=PT[j][2];PT[j][2]=PT[j-1][2];PT[j-1][2]=TTT;}

for(int i=0;i<c;i++)
printf("%ld\n",PT[i][2]);
if(c==0)printf("NA\n");
for(int i=0;i<4000;i++)
{P[i][0]=0;P[i][1]=0;P[i][2]=0;
 PT[i][0]=0;PT[i][1]=0;PT[i][2]=0;PT[i][3]=0;}

}
return  0;
}

C++: #include <iostream>
#include <string.h>

using namespace std;

int N, M;

int main() {
	int goal = 1000000;

	for (; cin >> N;) {
		if (!N) break;
		int v[4000];
		memset(v, 0, sizeof(v));
		for (int i = 0; i < N; i++) {
			long long  e, p, q;
			cin >> e >> p >> q;
			v[e - 1] += p*q;
		}
		bool flag = false;
		for (int i = 0; i < 4000; i++) {
			if (v[i] >= goal) {
				flag = true;
				cout << i + 1 << endl;

			}
		}
		if (!flag) cout << "NA" << endl;
	}

	return 0;
}

C++: 
#include<iostream>
#include<string>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<algorithm>
#include<complex>
using namespace std ;
typedef vector<int> vi ;
typedef vector<vi> vvi ;
typedef vector<string> vs ;
typedef pair<int, int> pii; 
typedef long long ll ;

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
#define all(a) (a).begin(),(a).end()


int main(void){
	int n;	
	while(cin>>n,n){
		vector<vector<ll> > num(n,vector<ll>(3,0));
		rep(i,n){
			//cout<<num[i][0]<<" "<<num[i][1]<<endl;
			cin>>num[i][0];
			int item,code;
			rep(j,i){
				if(num[i][0]==num[j][0]){
					num[j][1]+=item*code;
					num[i][2]=1;
				}
			}
			cin>>item>>code;
			if(!num[i][2])num[i][1]+=item*code;
		}
		//cout<<"star"<<endl;
		int cnt=0;
		rep(i,n){
			if(num[i][1]>=1000000){cout<<num[i][0]<<endl;cnt++;}
		}
		if(!cnt)cout<<"NA"<<endl;
		//cout<<"NO"<<n<<endl<<endl;;
	}
}

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

struct data {
	int ID;
	long total;
	int order;

	data() {
		ID = -1;
		total = 0;
		order = 100000;
	}

	data(int n) {
		ID = n;
		total = 0;
		order = 100000;
	}

	bool operator<(const data d) const {
		return order < d.order;
	}
};

int main() {
	int n;

	while(cin >> n, n) {
		int ID, price, sale;
		data table[4096];
		bool flag = false;
		int order_count = 0;

		getchar();
		for(int i = 0; i < sizeof(table) / sizeof(table[0]); i++) {
			table[i] = data(i);
		}

		for(int i = 0; i < n; i++) {
			char in[128];
			char ID_s[32], price_s[32], sale_s[32];
			int j, k;

			// input
			// /*
			fgets(in, 120, stdin);
			for(j = 0,k = 0; in[j + k] != ' ' && in[j + k] != ';'; k++)
				ID_s[k] = in[j + k];
			ID_s[k] = '\0';
			j = k + 1;
			for(k = 0; in[j + k] != ' ' && in[j + k] != ';'; k++)
				price_s[k] = in[j + k];
			price_s[k] = '\0';
			j += k + 1;
			for(k = 0; in[j + k] != ' ' && in[j + k] != ';' && in[j + k] && in[j + k] != '\n'; k++)
				sale_s[k] = in[j + k];
			sale_s[k] = '\0';

			ID = atoi(ID_s);
			price = atoi(price_s);
			sale = atoi(sale_s);
			// */

			// cin >> ID >> price >> sale;
			if(table[ID].order == 100000) {
				table[ID].order = order_count;
				order_count++;
			}

			table[ID].total += price * sale;
		}

		sort(table, table + 4096);

		for(int i = 0; i < order_count; i++) {
			if(table[i].total >= 1000000) {
				cout << table[i].ID << endl;
				flag = true;
			}
		}

		if(!flag)
			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

	int 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 <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    unsigned long long a[10000]={0},c=0,b[n],p,o,u;
    rep(i,n){
      cin>>p>>o>>u;
      a[p]+=o*u;
    }
    rep(i,4001){
      if(a[i]>=1000000){cout<<i<<endl;c++;}
    }
    if(!c)cout<<"NA"<<endl;
  }
}