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>
using namespace std;
const int MAXN = 4000;
typedef long long ll;
int i,p,q;
bool isfind;
map<int,ll> total;
int main(){
  int n;
  while(1){
    cin >> n;
    if(n == 0)return 0;
    for(int k = 0;k < n;k++){
      cin >> i >> p >> q;
      total[i] += p*q;
    }
    for(map<int, ll>::iterator i = total.begin(); i != total.end(); ++i){
      if(i->second >= 1000000){
	isfind = true;
	cout << i->first << endl;
      }
    }
    if(!isfind)cout << "NA" << endl;
    total.clear();
    isfind =false;
  }
  return 0;
}

C++: #include<iostream>
#include<cstring>
#include<vector>
using namespace std;
long long int sales[4010];
#define foreach(r,p,it) for(r::iterator it=p.begin();it!=p.end();++it)

int main()
{
    int n;
    while(cin>>n)
    {
        vector<int> shains;
        if(n==0)break;
    
        memset(sales,0,sizeof(sales));
        int num,tanka,kazu;

        for(int i=0;i<n;i++)
        {
            cin>>num>>tanka>>kazu;
            sales[num] += tanka*kazu;
            int f=0;
            foreach(vector<int>,shains,it)
            {
                if(*it == num){f=1;break;}
            }
            if(f==0) shains.push_back(num);
        }
        int na = 0;
        foreach(vector<int>,shains,it)
        {
            //cout <<"NUMBER"<<*it <<endl;
            if(sales[*it] >= 1000000){cout<<*it<<endl;na=1;}
        }
        if(na==0)cout<< "NA"<<endl;
    }
    return 0;
}

C++: #include <stdio.h>
 
 

 
int main(void){
	int i,j,k;
	int n,num[4000];
	long long int tanka[4000],sale_num[4000],sale_all[4001];
	bool judge[4001];
	
	while(scanf("%d",&n),n){
		
		//初期化

		k=0;
		for(j=0;j<=4001;j++){
			judge[j]=0;
			sale_all[j]=0;
		}
		
		for(i=0;i<n;i++){
			scanf("%d %lld %lld",&num[i],&tanka[i],&sale_num[i]);
		}
		
		
		//idに対応したsaleに+
		for(i=0;i<n;i++){
			sale_all[num[i]] = sale_all[num[i]] + tanka[i]*sale_num[i];
		}
		
		for(i=0;i<n;i++){
			if((sale_all[num[i]] >= 1000000)&&(judge[num[i]]==0)){
				printf("%d\n",num[i]);
				judge[num[i]]=1;
				k=1;
			}
		}
		
		if(k!=1)printf("NA\n");
	}
	
	return 0;
}

C++: #include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;
typedef long long int Int;
const int NORMA = 1000000;

int main() {
  int N;
  while(cin >>N && N){
    map<Int, Int> m;
    set<Int> s;
    vector<Int> v;
    REP(i, N){
      Int a, b, c; cin >>a >>b >>c;
      m[a] += b * c;
      if(s.find(a) == s.end()) v.push_back(a);
      s.insert(a);
    }
    vector<Int> ans;
    REP(i, v.size()) if(m[v[i]] >= NORMA) ans.push_back(v[i]);
    if(ans.size() == 0) cout <<"NA" <<endl;
    else REP(i, ans.size()) cout <<ans[i] <<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[n];
	int p[n];
	int q[n];
	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 <stdio.h>

struct employees
{
	int i;
	int q;
	int p;
};

int main(void)
{
	int n,m;
	struct employees number[4000];
	
	for (n = 0, m = 0; n < 4000; n++)
	{
		if (number[n].i == 0)
			break;
		if (number[n].q * number[n].p >= 1000000)
		{
			printf("%d\n", number[n].i);
			m++;
		}
		if (m == 0)
			printf("NA\n");
	}

	return 0;
}

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

#define SHINE_MAX 4000
#define ELITE 1000000
#define AHO "NA"

int shineN,eliteN;
int shineI[SHINE_MAX];	//??????????????????
long int shineU[SHINE_MAX];	//?£??????????

int dataN,num;
long int tanka,suryo;
int i,j;

int main(){
while(1){
	//??\???
	cin>>dataN;
	if(dataN==0){break;}
	shineN=0;
	for(j=0;j<dataN;j++){
	 cin>>num>>tanka>>suryo;num--;
	 //???????????????????????????????????¨??????????????????
	 for(i=0;i<shineN;i++){
	  if(shineI[i]==num){break;}
	 }
	 if(i==shineN){	//?????¨???????????£????????????
	  shineU[num]=0;
	  shineI[shineN]=num;
	  shineN++;
	 }
	 shineU[num]+=suryo*tanka;
	}
	//??????
	eliteN=0;
	for(j=0;j<shineN;j++){
	 i=shineI[j];
	 if(ELITE<=shineU[i]){
	  cout<<i+1<<endl;
	  eliteN++;
	 }
	}
	if(eliteN==0){cout<<AHO<<endl;}
}
return 0;
}

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

struct data{
  int a;
  long long total;
};

int main(){
  int i,j,n,c,a,yen,ko,f,f2;
  data d[4000];
  while(1){
    cin >> n;
    if(n == 0) break;
    c = 0;
    for(i=0;i<n;i++){
      cin >> a >> yen >> ko;
      f = 1;
      for(j=0;j<c;j++){
	if(a == d[j].a){
	  d[j].total += (long long) yen * ko;
	  f = 0;
	  break;
	}
      }
      if(f){
	d[c].a = a;
	d[c].total = (long long)yen * ko;
	c++;
      }
    }

    f2 = 1;
    for(i=0;i<c;i++){
      if(d[i].total >= 1000000){
	cout << d[i].a << endl;
	f2 = 0;
      }
    }
    if(f2) cout << "NA" << endl;

  }
  return 0;
}

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

#define ll long long

bool debug = true;

int main(void){
  map<int,ll> m;
  vector<int> order;
  int n;
  int no,amount,price;

  while(cin >> n){
	bool exist = false;
	if(!n) break;
	for(int i=0;i<n;i++){
	  cin >> no >> amount >> price;
	  if(find(order.begin(), order.end(), no) == order.end()){
		order.push_back(no);
		if(debug) cout << "pushed " << no << endl;
	  }
	  m[no] += (ll)amount*price;
	}
	for(int i=0;i<order.size();i++){
	  if(m[order[i]] >= 1e+6){
		cout << order[i] << endl;
		exist = true;
	  }
	}
	if(!exist) cout << "NA" << endl;
	m.clear();
	order.clear();
  }
}

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[5000]={0},c=0,p,o,u;
    rep(i,n){
      cin>>p>>o>>u;
      a[p]+=o*u;
      if(a[p]>=1000000){cout<<p<<endl;c++;}
    }
    if(!c)cout<<"NA"<<endl;
  }
}