Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	for scanner.Scan() {
		n, _ := strconv.Atoi(scanner.Text())
		if n == 0 {
			break
		}

		sales := make([]int, 4000)
		members := make([]int, 0)
		memberCheck := make(map[int]bool)

		for i := 0; i < n; i++ {
			scanner.Scan()
			input := strings.Split(scanner.Text(), " ")
			e, _ := strconv.Atoi(input[0])
			p, _ := strconv.Atoi(input[1])
			q, _ := strconv.Atoi(input[2])

			if e >= 1 && e <= 4000 && memberCheck[e] == false {
				members = append(members, e)
				memberCheck[e] = true
			}
			sales[e-1] += p * q
		}

		emptyFlag := true
		for _, v := range members {
			if sales[v-1] >= 1000000 {
				fmt.Println(v)
				emptyFlag = false
			}
		}

		if emptyFlag == true {
			fmt.Println("NA")
		}
	}
}

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

int main(){
  int n ,flag=0 ,num[4001] ,price[4001] ,earnings[4001] ,total[4001] ,overlap;
  while( true ){
    cin >> n;
    if( n == 0 ){
      break;
    }
    for( int i=0 ; i<n ; i++ ){ // 入力と合計を計算
      cin >> num[i] >> price[i] >> earnings[i];
      total[i] = price[i] * earnings[i];
    }

    for( int i=0 ; i<n ; i++ ){ // 重複を無くす
      overlap = num[i]; // 重複したかの判定
      for( int j=0 ; j<n ; j++ ){
	if( num[j] == overlap && i != j ){ // 重複したか
	  total[i] += total[j];
	  num[j] = -1;
	  total[j] = 0;
	}
      }
    }

    for( int i=0 ; i<n ; i++ ){ // 出力
      if( total[i] >= 1000000 ){
	cout << num[i] << endl;
	flag = 1;
      }
    }

    if( flag == 0 ){ // いなかったら
      cout << "NA" << endl;
    }
    flag = 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){
      long long 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 <vector>

typedef long long __int64;
#define NOS (4000)

int main()
{
	const __int64 threshold = 1000000;
//	const __int64 NOS = 4000;
	int n;
	
	while (std::cin >> n, n) {
		std::vector<int> inputStaff(n);
		__int64 staff[NOS] = {0};
		
		while (n--) {
			int id;
			__int64 unit, quantity;
			std::cin >> id >> unit >> quantity;
			staff[id - 1] += unit * quantity;
			if (std::find(inputStaff.begin(), inputStaff.end(), id) == inputStaff.end()) inputStaff.push_back(id);
		}
		
		bool naFlag = true;
		std::vector<int>::iterator it = inputStaff.begin(), eit = inputStaff.end();
		for (; it != eit; ++it) {
			if (staff[*it - 1] >= threshold)  {
				naFlag = false;
				std::cout << *it << std::endl;
			}
		}
		if (naFlag) std::cout << "NA" << std::endl;
	}
	
	return 0;
}

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

int main(){

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

		typedef std::vector<std::pair<long, long> > dataType;
		dataType data;
		for (int i = 0; i < cnt; ++i) {
			int id, price, amount;
			cin >> id >> price >> amount;
			int g = price * amount;

			bool found = false;
			for (int i = 0; i < data.size(); ++i) {
				if (data[i].first == id) {
					data[i].second += g;
					found = true;
				}
			}
			if (!found) data.push_back(std::pair<int, int>(id, g));
		}
		bool bHitted = false;
		for (dataType::iterator it = data.begin(); it != data.end(); ++it) {
			if (it->second >= 1000000) {
				cout << it->first << "\n";
				bHitted = true;
			}
		}
		if (!bHitted) {
			cout << "NA\n";
		}
	}
	return 0;
}

C++: #include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
    int n;
    while(cin>>n,n){
        long long int syain,kakaku,kosuu,syains[5000]={0};
        long long int bango[5000]={0},flag[5000]={0};
        for(int i=0;i<n;i++){
            cin>>syain>>kakaku>>kosuu;
            bango[i]=syain;
            syains[syain]+=kakaku*kosuu;
        }
        for(int i=0;i<5000;i++){
            if(syains[bango[i]]>=1000000){
                if(flag[bango[i]]==0){
                        cout<<bango[i]<<endl;
                        flag[bango[i]]=1;
                }
            }
        }

    }
    return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
void shoki();
vector<long long> num(4001,0);
int n,ban,tanka,kazu,i,j;
int main(){

	bool y=false;
	while(1){
		cin>>n;
		if(n==0){
			break;
		}
		int count=0;
		for(i=0;i<n;i++){
			cin>>ban>>tanka>>kazu;
			num[ban]+=tanka*kazu;
		}
		//sort(num.begin(),num.end());
		for(int k=0;k<4001;k++){
			if(num[k]==0){
				continue;
			}
			if(num[k]>=1000000){
				y=true;
				cout<<k<<endl;
			}
		}
		if(y==false){
			cout<<"NA"<<endl;
		}
		y=false;
		shoki();
	}
	return 0;
}
void shoki(){
	for(int i=0;i<4000;i++){
		num[i]=0;
	}
}

C++: #include<iostream>
using namespace std;
int main(){
  int data[2][4000],n,i,f,id,a,b;
  while(1){
    cin>>n;
    if(n==0) break;
    for(i=0; i<4000; i++) data[0][i]=-1,data[1][i]=0;
    for(i=0;i<n;i++){
      cin>>id>>a>>b;
      for(f=0;f<i+1;f++){
	if(data[0][f]==id){
	  data[1][f]+=(a*b);
	  break;
	}else if(data[0][f]==-1){
	  data[0][f]=id;
	  data[1][f]=a*b;
	  break;
	}
      }
    }
    for(i=0,f=0;i<n;i++){
      if(data[1][i]>=1000000)cout<<data[0][i]<<"\n",f=1;
      if(data[0][i]==-1)break;
      // cout<<"id : "<<data[0][i]<<" sale: "<<data[1][i]<<endl;
    }
    if(f==0)cout<<"NA"<<endl;
  }
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int n,num,mon,cont,a[4001],nacount;
  while(scanf("%d",&n)!=EOF){
    if(n==0){break;}
    for(int i=0;i<4001;i++){
      a[i]=0;
    }
    nacount=0;
    for(int i=0;i<n;i++){
      cin>>num>>mon>>cont;
      a[num]+=mon*cont;
    }
    for(int i=0;i<4000;i++){
      if(a[i]>=1000000){
	cout<<i<<endl;
	nacount++;
      }
    }if(nacount==0){
      cout<<"NA"<<endl;
    }
  }
  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <sstream>
#include <vector>
#include <string>
#include <iomanip>
#include <bitset>
using namespace std;
#define INF	100000000
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define lb lower_bound
#define ub upper_bound
#define SS stringstream
#define rep(i,n) for(int i = 0; i < n; i++)
#define sz(x) ((int)(x).size())
#define SORT(x) sort((x).begin(), (x).end())
#define RSORT(x) sort((x).begin(), (x).end(), greater<int>() )
#define clr(a,b) memset((a),(b),sizeof(a))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<P> Vp;
typedef priority_queue<P, vector<P>, greater<P> > PQ;

int n;

int main(){
	while(scanf("%d", &n)){
		if(n == 0) break;
		map<int,ll> m;
		map<int,ll>::iterator it;
		rep(i,n){
			int x,p,q; scanf("%d%d%d", &x, &p, &q);
			if(m.find(x) == m.end()) m[x] = p*q;
			else m[x] += p*q;
		}
		bool ok = true;
		for(it = m.begin(); it != m.end(); it++){
			if(it->second >= 1000000){
				ok = false;
				cout << it->first << endl;
			}
		}
		if(ok) cout << "NA" << endl;
	}
}