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<bits/stdc++.h>
using namespace std;
int main(){
  int n,num,flag=0,flag2=0;
  long long tanka,sell;
  while(cin>>n,n!=0){
    vector<int> nu;
    vector<int> vi;
    vector<pair<int,long long> > pii;
    for(int i=0;i<n;i++){
      cin>>num>>tanka>>sell;
      for(int j=0;j<vi.size();j++){
	if(num==vi[j]){
	  flag2=1;
	  break;
	}
      }
      if(flag2==0){
	for(int j=0;j<pii.size();j++){
	if(pii[j].first==num){
	  flag=1;
	  pii.push_back(make_pair(num,((tanka*sell)+pii[j].second)));
	  if(((tanka*sell)+pii[i].second)>=1000000)
	    vi.push_back(num);
	  break;
	}
      }
      if(flag==0){
	nu.push_back(num);
	pii.push_back(make_pair(num,tanka*sell));
	if(tanka*sell>=1000000)
	  vi.push_back(num);
      }
    }
    }
    if(vi.empty())
      cout<<"NA"<<endl;
    else{
    for(int k=0;k<nu.size();k++){
      for(int l=0;l<vi.size();l++){
	if(nu[k]==vi[l])
	  cout<<nu[k]<<endl;
      }
    }
    }
  }
  return 0;
}

C++: #include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
map<int,ll> data;
int main(){
	int n;
	while(cin>>n,n){
		data.clear();
		std::vector<int> a;
		a.clear();
		rep(i, n){
			int e,c,s;
			cin>>e>>c>>s;
			if(data[e]==0){
				a.push_back(e);
				
			}
			data[e]+=(c*s);
		}
		bool flag =false;
		for(int i =0;i < a.size();i++){
			if(data[a[i]]>= 1000000){
				cout <<a[i]<<endl;
				flag =true;
			}
		}
		if(!flag){
			cout<<"NA"<<endl;
		}
	}
	return 0;
}

C++: #include<stdio.h>

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

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];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;}

for(int i=0;i<c;i++)
printf("%d\n",PT[i][1]);
}
return 0;
}

C++: #include<stdio.h>
#include<string.h>
#include<math.h>
int main(void)
{
	long long int g[1001],s[1001],d[1001],f[1001];
	int j,i,k,a,h[1001];
	while(1){
		scanf("%d",&a);
		if(a==0) break;
		for(i=0;i<a;i++){
			h[i]=0;
			g[i]=0;
		}
		for(i=0;i<a;i++){
			scanf("%lld %lld %lld",&s[i],&d[i],&f[i]);
			if(d[i]*f[i]>=1000000) h[i]=1;
			/*if(d[i]==1000000&&f[i]>=1) h[i]=1;
			if(f[i]==100000&&d[i]>=10) h[i]=1;*/
			if(h[i]==0) g[i]=d[i]*f[i];
			else g[i]=0;
		}
		for(i=0;i<a;i++){
			for(j=i+1;j<a;j++){
				if(g[i]>=1000000&&h[i]==0){
					h[i]=1;
				}
				if(s[i]==s[j]){
					if(h[i]==0){
						g[i]+=g[j];
						g[j]=0;
					}
					else g[j]=0;
				}
				if(g[i]>=1000000&&h[i]==0){
					h[i]=1;
				}
			}
		}
		k=0;
		for(i=0;i<a;i++){
			if(h[i]==1){
				printf("%lld\n",s[i]);
				k=1;
			}
		}
		if(k==0) printf("NA\n");
	}
	return 0;
}

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

long long member[4000];
vector<int> ach;

int main(void){
  int n;
  while(true){
    cin >> n;
    if(n == 0)  break;
    fill(member, member + 4000, 0);
    ach.clear();
    for(int i = 0; i < n; i++){
      int id, tanka, suryo;
      cin >> id >> tanka >> suryo;
      member[id] += tanka * suryo;
    }

    for(int i = 0; i < 4000; i++){
      if(member[i] >= 1000000){
        ach.push_back(i);
      }
    }

    if(ach.empty()){
      cout << "NA" << endl;
    }else{
      for(int i = 0; i < ach.size(); i++){
        cout << ach[i] << endl;
      }
    }
  }
  return 0;
}

C++: //AOJ0100
#include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<sstream>
#include<algorithm>
#include<cmath>
#include<map>
using namespace std;
#define int long long
void main(){
	int n;
	while(cin>>n,n!=0){
vector< pair<int,int> >ta;
ta.clear();
for(int i=0;i<n;i++){
int a,b,c;
cin>>a>>b>>c;
bool f=0;
int index=0;
for(int j=0;j<ta.size();j++)if(ta[j].first==a)f=1,index=j;
if(f==0)ta.push_back(pair<int,int>(a,b*c));
else ta[index].second+=b*c;
}
bool f=0;
for(int i=0;i<ta.size();i++){
	cout<<ta[i].first<<"   "<<ta[i].second<<endl;
	if(ta[i].second>=1000000){cout<<ta[i].first<<endl;;f=1;}
}
	if(!f)cout<<"NA"<<endl;
}
	return ;
}

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

int main() {
  int n;
  while (cin >> n) {
    if (n == 0) {break;};
    unsigned long int total[4000];
    for (int i = 0; i < 4000; i++) {
      total[i] = 0;
    }
    
    for (int i = 0; i < n; i++) {
      int a;
      unsigned long int b,c;
      cin >> a >> b >> c;
      total[a-1] += b*c;
    }
    
    bool NA = true;
    for (int i = 0; i < 4000; i++) {
      if ( total[i] >= 1000000) {
	cout << i+1 << endl;
	NA = false;
      }
    }
    if (NA) {
      cout << "NA" << endl;
    }
  }
  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("%ld %ld %ld",&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<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;
}