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>
#include<cstdio>
#include<vector>
#include<map>

using namespace std;

int main()
{
    while(1){
        int n;
        scanf(" %d",&n);
        if(n==0)break;

        vector<int> bangoulist;
        map<int,long long int> alldata;
        alldata.clear();
        for(int i=0;i<n;i++){
                int bangou,tanka,num;
                scanf(" %d %d %d",&bangou,&tanka,&num);
                if(alldata[bangou]!=0){
                        alldata[bangou]+=tanka*num;
                }else{
                        bangoulist.push_back(bangou);
                        alldata[bangou]=tanka*num;
                }
        }
        bool flag=true;
        for(int i=0;i<(int)bangoulist.size();i++){
                if(alldata[bangoulist[i]]>=1000000){
                        cout<<bangoulist[i]<<"\n";
                        flag=false;
                }
        }
        if(flag)cout<<"NA\n";
    }
    return 0;
}

C++: #include<iostream>
#include<map>
#include<vector>
#include<string>

using namespace std;
#define mp make_pair
int main(){
  int n;
  string a;
  long long b,c;
  map<string,long long> data;
  vector<string> id;
  while(true){
    id.clear();
    data.clear();
    cin>>n;
    if(!n)
      break;
    for(int i=0;i<n;i++){
      cin>>a>>b>>c;
      c*=b;
      if(data.find(a)==data.end()){
	data.insert(mp(a,c));
	id.push_back(a);
      }
      else{
	data[a]+=c;
      }
    }
    bool empty = true;
    for(int i=0;i<id.size();i++){
      if(data[id[i]]>=1000000){
	cout<<id[i]<<endl;
	empty = false;
      }
    }
    if (empty)
      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[4002][3]={};
	for(int i=0;i<4001;i++)
	{n[i][1]=0;n[i][2]=i;}

	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=4000;j>i;j--){
			if(n[j][1]<n[j-1][1]){
				int t=n[j][0];n[j][0]=n[j-1][0];n[j-1][0]=t;
				int T=n[j][1];n[j][1]=n[j-1][1];n[j-1][1]=T;
				int TT=n[j][2];n[j][2]=n[j-1][2];n[j-1][2]=TT;
			}
		}
	}
	bool f=false;
	for(int i=0;i<4001;i++){
		if(n[i][0]>=1000000){cout<<n[i][2]<<endl;f=true;}
	}
	if(f==false)cout<<"NA"<<endl;
	
	}
	return 0;
}

C++: #include <map>
#include <iostream>
#include <vector>
using namespace std;
int main(){
    map<int,long long int> emps;
    vector<int> ids;
    int id,cost,amount,n;
    while(cin >> n,n){
        for(int i=0;i<n;i++){
            cin >> id >> cost >> amount;
            if(emps.find(id)!=emps.end()){
                emps[id]+=cost*amount;
            }else{
                emps[id]=cost*amount;
                ids.push_back(id);
            }
        }
        sort(ids.begin(),ids.end());
        for(int i=0;i<ids.size();i++){
            if(emps.at(ids[i])>=1000000) cout << ids[i] << endl;
        }
    }
    return 0;
}

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

int main(){
  int n;//データ数
  while(cin >> n){
    long long arr[4001];
    long long selling;
    long long sales;
    long long num;
    int check=0;
    //社員は4000人未満
    memset(arr,0,sizeof(arr));
    if(n==0)
      break;
    for(int i=0;i<n;i++){
      cin >> num >> selling >> sales;
      arr[num]+=selling*sales;
    }
    for(int i=0;i<=4000;i++){
      if(arr[i]>=1000000){
        cout << i << endl;
        check++;
      }
    }
    if(check==0)
       cout << "NA" << endl;
    check=0;
  }
}

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

using namespace std;

int main(){
  long long n, i, p, q;
  while(true){
    cin >> n;
    if(n==0)
      break;

    map<int,int> mop;
    vector<int> ord;
    bool check = true;

    for(int j=0; j<n; j++){
      cin >> i >> p >> q;
      if(mop.find(i) == mop.end()){
	mop[i] = p*q;
	ord.push_back(i);
      }
      else if(mop[i] < 1000000){
	mop[i] += p*q;
      }
    }
    
    for(int j=0; j<ord.size(); j++){
      if(mop[ord[j]] >= 1000000){
	cout << ord[j] << endl;
	check = false;
      }
    }
    if(check)
      cout << "NA\n";
  }
  return 0;
}

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

int main()
{
	int n;
	
	while (cin >> n, n){
		bool num[4000] = {false}, flag = false;
		int sum[4000] = {0}, m, ex, a;
		int c_num[4000] = {0};
		int c = 0;
		
		for (int i = 0; i < n; i++){
			cin >> m >> ex >> a;
			sum[m] += ex * a;
			
			if (1000000 <= sum[m] && num[m] != true){
				num[m] = true;
				c_num[c] = m;
				c++;
				flag = true;
			}
		}
		
		if (flag){
			for (int i = 0; i < c; i++){
				cout << c_num[i] << endl;
			}
		}
		else {
			cout << "NA" << endl;
		}
	}
	
	return (0);
}

C++: #include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
using namespace std;
int inf = 1000000000;

int main(void) {

  int n;
  while(cin >> n){
    if( n == 0 ) break;
    vector<long long int> ans;
    vector<long long int> u(4001, 0);
    vector<bool> b(4001, false);
    vector<long long int> e(n);
    vector<long long int> p(n);
    vector<long long int> q(n);
    for(int i=0; i<n; i++){
      cin >> e[i] >> p[i] >> q[i];
      u[ e[i] ] += p[i]*q[i];
    }
    for(int i=0; i<n; i++){
      if( b[e[i]] ) continue;
      if( u[ e[i] ] >= 1000000 ){
        ans.push_back(e[i]);
        b[ e[i] ] = true;
      }
    }
    if( ans.size() == 0 ) cout << "NA" << endl;
    else for(int i=0; i<ans.size(); i++) cout << ans[i] << endl;
  }

  return 0;
}

// EOF

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];
	int judge[4001];
	
	while(scanf("%d",&n),n){
		
		for(i=0;i<n;i++){
			scanf("%d%lld%lld",&num[i],&tanka[i],&sale_num[i]);
		}
		
		//初期化
		k=0;
		for(j=0;j<=4001;j++){
			judge[j]=0;
			sale_all[j]=0;
		}
		
		//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;
}