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++: // 2011/01/12 Tazoe

#include <iostream>
using namespace std;

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

		int emp[4000][3];
		for(int i=0; i<4000; i++){
			emp[i][0] = i+1;
			emp[i][1] = 0;
			emp[i][2] = 5000;
		}

		int ord = 1;
		for(int i=0; i<n; i++){
			int id, p, q;
			cin >> id >> p >> q;
			emp[id-1][1] += p*q;
			if(emp[id-1][2]==5000){
				emp[id-1][2] = ord;
				ord++;
			}
		}

		for(int i=0; i<3999; i++)
			for(int j=i+1; j<4000; j++)
				if(emp[i][2]>emp[j][2]){
					int tmp1 = emp[i][0];
					int tmp2 = emp[i][1];
					int tmp3 = emp[i][2];
					emp[i][0] = emp[j][0];
					emp[i][1] = emp[j][1];
					emp[i][2] = emp[j][2];
					emp[j][0] = tmp1;
					emp[j][1] = tmp2;
					emp[j][2] = tmp3;
				}

		int cnt =0;
		for(int i=0; emp[i][2]!=5000&&i<4000; i++)
			if(emp[i][1]>=1000000){
				cout << emp[i][0] << endl;
				cnt++;
		}
		if(cnt==0)
			cout << "NA" << endl;
	}

	return 0;
}

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

int main(){

	int N,Q;
	while(1){int c=0;
	cin>>N;if(N==0)break;
	long long int n[4001][2]={};
	for(int i=0;i<N;i++){
		long long int x,y,z;
		cin>>x>>y>>z;
		if(n[x][0]+y*z<=1000000)n[x][0]+=y*z;
		else if(n[x][0]+y*z>1000000)n[x][0]=1000000;
		if(n[x][1]==0){c++;n[x][1]=c;}
	
	}
	for(int i=0;i<4001;i++){
		for(int j=i;j>i;j--){
			if(n[j][1]<n[j-1][1]){
				int t=n[j][0];n[j-1][0];n[j-1][0]=t;
				int T=n[j][1];n[j-1][1];n[j-1][1]=T;
			}
		}
	}
	bool f=false;
	for(int i=0;i<4001;i++){
		if(n[i][0]>=1000000){cout<<i<<endl;f=true;}
	}
	if(f==false)cout<<"NA"<<endl;

	}
	return 0;
}

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

int main()
{
	long long n,a,b,c;
	while(cin >> n, n)
	{
		vector<long long>  v;
		map<long long,long long> m;

		while(n--)
		{
			cin >> a >> b >> c;
			if(m.insert(pair<long long,long long>(a,b*c)).second)
			{
				v.push_back(a);
			}
			else
			{
				m[a] += b*c;
			}
		}

		bool f=true;
		for(int i=0; i<v.size(); i++)
		{
			if(m[v[i]]>=1000000)
			{
				f=false;
				cout << v[i] << endl;
			}
		}
		if(f) cout << "NA" << endl;
	}
	return 0;
}

C++: #include <stdio.h>

int output[49000];
int count=0;

void input(int);
int main(void){
	int n,i;
	while(true){
		scanf("%d",&n);
		if(n>0){
			input(n);
		}else{
			break;
		}
	}
	for(i=0;i<count;i++){
		if(output[i]!=0){
			printf("%d\n",output[i]);
		}else{
			printf("NA\n");
		}
	}
	
	return 0;
}
void input(int n){
	int nb = n;
	
	int e[4000];
	int p[1000000];
	int q[100000];
	int c[n];
	
	int i;
	
	for(i=0;i<n;i++){
		scanf("%d",&e[i]);
		scanf("%d",&p[i]);
		scanf("%d",&q[i]);
		c[i] = p[i]*q[i];
	}
	
	int j;
	
	for(i=0;i<n-1;i++){
		for(j=1;j<n;j++){
			if(e[i]==e[j]){
				c[i]=c[i]+c[j];
				c[j]=0;
			}
		}
	}
	int ch = 0;
	
	for(i=0;i<n-1;i++){
		if(c[i]>=1000000){
			output[count]=e[i];
			count++;
			ch = 1;
		}
	}
	if(ch == 0){
		output[count]=0;
		count++;
	}
}

C++: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"
int main() {
	while (1) {
		int N; cin >> N;
		if (!N)break;
		map<int, long long int>mp;
		for (int i = 0; i < N; ++i) {
			long long int a, b, c; cin >> a >> b >> c;
			mp[a] += b*c;
		}
		bool flag = false;
		for (auto m : mp) {
			if (m.second >= 1000000) {
				cout << m.first << endl;
				flag = true;
			}
		}
		if (!flag)cout << "NA" << endl;
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
int main(void)
{
	int n;
	while(cin>>n){
		if(!n) break;
		long long number[4010];
		long long sales[4010];
		for(int i=0; i< n; i++){
			cin >> number[i];
			long long price;
			long long bnum;
			cin >> price >> bnum;
			sales[i] = price * bnum;
		}
		int count = 0;
		for(int i=0; i < n; i++){
			if(sales[i] >= 1000000){
				cout << number[i] << endl;
				count++;
			}
		}
		if(!count) cout << "NA" << endl;
	}
	return 0;
}

C++: #include <cstdio>
#include <cmath>

using namespace std;

int n, e, p, q;
bool b;

int main() {
  while(scanf("%d", &n), n) {
    b = true;
    for(int i = 0; i < n; i++) {
      scanf("%d %d %d", &e, &p, &q);
      if(p * q >= 1e6) {
        printf("%d\n", e);
        b = false;
      }
    }
    if(b) printf("NA\n");
  }
}

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-1; 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; i++)
		{
			if (total[i] >= 1000000)
			{
				cout << outid[i] << endl;
				flg = 1;
			}
		}

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

C++: #include<iostream>
#include<vector>
int main() {
	std::vector<int> a;
	while (true) {
		int n;
		int c = 0;
		std::cin >> n;
		if (n == 0) {
			break;
		}
		std::vector<int> v(n), w(n);
		int t, u;
		for (int i = 0; i < n; ++i) {
			std::cin >> w[i] >> t >> u;
			v[i] = t*u;
		}
		for (int i = 0; i < n; ++i) {
			for (int l = 0; l < n; ++l) {
				if ((v[i] == v[l]) && (i != l)) {
					v[i] += v[l];
					v.erase(v.begin() + l);
					n -= 1;
				}
			}
		}
		for (int i = 0; i < n; ++i) {
			if (v[i] >= 1000000) {
				a.push_back(w[i]);
				++c;
			}
			if ((c == 0) && (i == n - 1)) {
				a.push_back(0);
			}
		}
		v.clear();
		w.clear();
	}
	for (int i = 0; i < a.size(); ++i) {
		if (a[i] == 0)std::cout << "NA" << std::endl;
		else std::cout << a[i] << std::endl;
	}
	return 0;
}

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

int main(){
    int n;
    
    while(true){
        int cnt = 0;
        int s[4002]={0},gs[4002]={0};
        
        cin >> n;
        if(!n) break;
        
        int t,cost;
        int num;
        for(int i = 0 ; i < n ; i++){
            cin >> num >> t >> cost;
            s[num] += t*cost;
            gs[i] = num;
        }
        
       for(int i = 0 ; i < n ; i++){
            for(int j = i+1 ; j < n ; j++){
                if(gs[i]==gs[j]&&i < j){
                    gs[j] = 4001;
                }
            }
        }
        
        for(int i = 0 ; i < n ; i++){
            if(s[gs[i]] >= 1000000){
                cout << gs[i] << endl;
                cnt++;
            }
        }
        if(!cnt) cout << "NA" << endl;
    }
    
    return 0;
}