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++: // #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<iostream>
#include<cstdio>
#include<map>
using namespace std;
typedef long long ll;
int main(){
  int n,index[10000],inindex,val,num,couter;
  map<int,ll> List;
  while(true){
    scanf("%d",&n);
    if(n == 0)break;
    couter=0;
    List.clear();
    for(int i=0;i<n;i++){
      scanf("%d %d %d",&inindex,&val,&num);
      if(!List[inindex]){
	index[couter]=inindex;
	couter++;
      }
      List[inindex]+=val*num;
    }
    bool NAf=true;
    for(int i=0;i<couter;i++){
      if(List[index[i]] >= 1000000){
	printf("%d\n",index[i]);
	NAf=false;
      }
    }
    if(NAf)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])
{long TT=PT[j][1];PT[j][1]=PT[j-1][1];PT[j-1][1]=TT;
 long 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<map>
#include<string>
using namespace std;
typedef long long int ll;
int main(){
	for(;;){
		int n;
		cin >> n;
		if(n == 0) break;
		map<string, ll> mpa;
		for(int i = 0; i < n; i++){
			string e;
			int p, q;
			cin >> e;
			cin >> p >> q;
			mpa[e] += p * q;
		}
		map<string, ll>::iterator itr;
		bool flag = false;
		for(itr = mpa.begin(); itr != mpa.end(); itr++){
			if(itr->second >= 1e6){
				cout << itr->first << endl;
				flag = true;
			}
		}
		if(flag == false) cout << "NA" << endl;
	}
	return 0;
}

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

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

struct tEmploy{
	int num;
	int sold;
	tEmploy(){
		num = -1;
		sold = 0;
	}
};

int main(){
	while(1){
		tEmploy *emp;
		int n;
		cin >> n;
		if( n == 0 ){
			break;
		}

		emp = new tEmploy[n];
		for( int i=0; i<n; i++ ){
			int num, val, amo;
			cin >> num >> val >> amo;
			int j=0;
			for( ; j<n; j++ ){
				if( emp[j].num == num )	break;
			}
			if( j == n ){
				for( j=0; j<n; j++ ){
					if( emp[j].num == -1 ){
						emp[j].num = num;
						break;
					}
				}
			}
			emp[j].sold += val * amo;
		}

		bool exist = false;
		for( int i=0; (emp[i].num!=-1)&&(i<n); i++ ){
			cout << emp[i].num << endl;
			if( emp[i].sold >= 1000000 ){
				cout << emp[i].num << endl;
				exist = true;
			}
		}
		if( !exist ){
			cout << "NA" << endl;
		}

		delete[] emp;
		emp = 0;
	}
	
	return 0;
}

C++: #include<stdio.h>
int main(void){
	int n;
	long long int ban[4001],tan,suu;
	long long int bansum[4001],banf[4001],i;
	while(1){
		scanf("%d",&n);
		if(n==0){
			break;
		}
		for(i=1;i<=4000;i++){
			bansum[i]=banf[i]=0;
		}
		for(i=0;i<n;i++){
			scanf("%d %d %d",&ban[i],&tan,&suu);
			bansum[ban[i]]+=tan*suu;
		}
		int flg=0;
		for(i=0;i<n;i++){
			if(bansum[ban[i]]>=1000000 && banf[ban[i]]==0){
				printf("%d\n",ban[i]);
				banf[ban[i]]=1;
				flg=1;
			}
		}
		if(flg==0){
			printf("NA\n");
		}
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    map<int,long long int>in;
    vector<int>in2;
    rep(i,n){
      int a;
      long long int b,c;
      cin>>a>>b>>c;
      if(in[a])in[a]+=b*c;
      else {in[a]+=b*c;in2.pb(a);}
    }
    bool han=false;
    rep(i,in2.size())if(in[in2[i]]>=1000000){han=true;cout<<in2[i]<<endl;}
    if(!han)cout<<"NA"<<endl;
  }
}

C++: #include<bits/stdc++.h>

using namespace std;

int main()
{
  while(1){
    int n;
    cin>>n;
    if(n == 0){
      break;
    }

    vector<pair<int,int>> data;
    for(int i = 0;i < n;++i){
      int num,sa,ko;
      cin>>num;
      cin>>sa;
      cin>>ko;

      data.push_back(make_pair(num,sa * ko));
    }

    for(pair<int,int> e : data){
      if(e.second >= 1000000){
        cout<<e.first<<endl;
      }
    }
  }

  return 0;
}