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<long long> 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<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>m;
    vector<int>num;
    rep(i,n){
      int a,b,c;
      cin>>a>>b>>c;
      if(m.find(a)==m.end()){
	num.pb(a);
	m.insert(mp(a,b*c));
      }else{
	m[a]+=b*c;
      }
    }
    bool h=false;
    rep(i,num.size()){
      if(m[num[i]]>=1000000){
	cout<<num[i]<<endl;
	h=true;
      }
    }
    if(!h)cout<<"NA"<<endl;
  }
}

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

int main() {
    int i, N;
    long long p, q;

    while (cin >> N && N != 0) {
        cin.get();

        map<int, long long> sales;
        vector<int> sequence;        
        
        for (int n = 0; n != N; ++n) {
            cin >> i >> p >> q;
            if (!sales.count(i)) { 
                sequence.push_back(i);
            }
            sales[i] += p * q;
        }

        bool printNA = true;
        
        for (int i = 0; i != sequence.size(); ++i) {
            if (sales[sequence[i]] >= 1000000) {
                cout << sequence[i] << endl;
                printNA = false;
            }
        }

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

C++: #include <iostream>
#include <vector>
#include <cstring>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;


typedef long long ll;
typedef pair<int, bool> IB;

struct P{
	int id;
	int tanka;
	int kosuu;
};
ll shain[4001];
bool used[4001];
bool more[4001];
int main()
{
	int n;

	while (cin >> n && n ){
		vector<P> data (n );
		rep (i, n ){
			cin >> data[i].id >> data[i].tanka >> data[i].kosuu;
		} // end rep
		memset (shain, 0LL, sizeof (shain ) );
		memset (used, false, sizeof (used ) );
		memset (more, false, sizeof (more ) );
		rep (i, n ){
			ll total = (ll)data[i].tanka*(ll)data[i].kosuu;
			shain[data[i].id] += total;
		} // end if
		for (int i = 1; i <= 4000; i++ ){
			if (shain[i] >= 1000000LL ){
				more[i] = true;
			} // end if
		} // end for
		bool found = false;
		rep (i, n ){
			if (more[data[i].id] && !used[data[i].id] ){
				cout << data[i].id << endl;
				used[data[i].id] = true;
				if (!found )
					found = true;
			} // end if
		} // end rep
		if (!found ){
			cout << "NA" << endl;
		} // end if
	} // end loop
		
	return 0;
}

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

#define loop(v, f, l) for(int v = (f), v##_ = (l); v < v##_; ++v)

using namespace std;

typedef long long int lint;
static inline int in(){ int x; scanf("%d", &x); return (x); }
static inline lint lin(){ lint x; scanf("lld", &x); return (x); }

int main()
{
	list<int> staffList;
	map<int, lint> saleResult;
	int n;
	int staffNum;
	lint unitPrice;
	lint quantity;
	while( 1 )
	{
		n = in();
		if( n == 0 )break;

		staffList.clear();
		saleResult.clear();
		loop(i, 0, n)
		{
			staffNum = in();
			unitPrice = lin();
			quantity = lin();
			staffList.push_back(staffNum);
			saleResult[staffNum] += unitPrice * quantity;
		}
		bool flag = false;
		for(list<int>::iterator it = staffList.begin(); it != staffList.end(); it++)
		{
			if( saleResult[*it] >= 1000000 )
			{
				printf("%d\n", *it);
				saleResult[*it] = 0;
				flag = true;
			}
		}
		if( !flag )
		{
			cout << "NA" << endl;
		}
	}
	return (0);
}

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

using namespace std;

int findNum(vector<pair<int,int> > comm, int num) {
    for(int i=0; i<comm.size(); i++)  {
      if(comm[i].first == num) {
	return i;
      }
    }
    return comm.size();
  }

int main() {
  int n;
  cin>>n;
  while(n != 0) {
    int m = n;
    vector<pair<int,int> > comm;
    while(m--) {
      int num, price, unit;
      cin>>num>>price>>unit;
      int dataNum = findNum(comm, num);
      if(dataNum == comm.size()) {
        comm.push_back(make_pair(num, price*unit));
      }
      else {
        comm[dataNum].second += price*unit;
      }
    }

    bool flag = true;
    for(int i=0; i<comm.size(); i++) {
      if(comm[i].second >= 1000000) {
        cout<<comm[i].first<<endl;
        flag = false;
      }
    }
    if(flag == true) {
      cout<<"NA"<<endl;
    }
    cin>>n;
  }
}

C++: #include<stdio.h>
int main(void)
{
    int n,flg,j,i,a[1000];
	double b[1000],c[1000],d[1000];
	while(1){
	    scanf("%d",&n);
		if(n==0) break;
		for(i=0;i<n;i++){
		    scanf("%d %lf %lf",&a[i],&b[i],&c[i]);
		}
		for(i=0;i<n;i++){
		    d[i]=b[i]*c[i];
		}
		for(i=0;i<n-1;i++){
		    for(j=i+1;j<n;j++){
			    if(a[i]==a[j]){
				    d[i]=d[i]+d[j];
					d[j]=0;
				}
			}
		}
		flg=0;
		for(i=0;i<n;i++){
		    if(d[i]>=1000000){
			    printf("%d\n",a[i]);
				flg=1;
			}
		}
		if(flg==0) printf("NA\n");
	}
	return 0;
}

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

int main(){
	long long n,a,b,c;
	vector<long long >g;
	while(cin >> n && n){
		g.clear();
		for(int i=0;i<n;i++){
			cin >> a >> b >> c;
			if(b>10000&&c>10000)g.push_back(a);
			else if(b*c>=1000000)g.push_back(a);
		}
		if(!g.size())cout << "NA" << endl;
		for(int i=0;i<g.size();i++){
			cout << g[i] << endl;
		}
	}
}