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<cstdio>
using namespace std;
int main(){
    int n;

    while(scanf("%d",&n),n){

        long long int mem[4500][3] = {{0}};
        long long int a,x,y;
        long long int cnt = 0;

        for(long long int i = 0;i < n; i++){
            scanf("%lld%lld%lld",&a,&x,&y);
            for(long long int j = 0;j < i; j++){
                if(mem[j][1] != a){
                   cnt++;
                }
                else {
                    mem[j][0] += x*y;
                    break;
                }
            }
            if(cnt == i){
                mem[i][0] += x*y;
                mem[i][1] = a;
                cnt = 0;
            }
        }

        bool flg = 0;
        for(int i = 0;i < n; i++){
            if(mem[i][0] >= 1000000){
                printf("%lld\n",mem[i][1]);
                flg = 1;
            }
        }
        if(flg == 0)printf("NA\n");
    }
    return 0;
}

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

int main(){
  int n;//データ数
  while(cin >> n){
    long long arr[4001];//社員番号
    int selling[n];//販売単科
    int sales[n];//売り上げ数量
    int num;
    int check=0;
    //社員は4000人未満
    memset(arr,0,sizeof(arr));
    if(n==0)
      break;
    for(int i=0;i<n;i++){
      cin >> num >> selling[i] >> sales[i];
      arr[num]+=selling[i]*sales[i];
    }
    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 "stdio.h"
#include "string.h"
long long N[4001];
int f[4001];
int main(){
    int x,n,p,i,j,c=0;
    scanf("%d",&i);
    while(i!=0){
        c=0;
        for(j=0;j<i;j++){
            scanf("%d%d%d",&x,&n,&p);
            if(N[x]!=-1){
                N[x]+=n*p;
                if(N[x]>=1000000){
                    f[c]=x;
                    c++;
                    N[x]=-1;
                }
            }
        }
        if(c==0)
            printf("NA\n");
        else 
            for(j=0;j<c;j++)printf("%d\n",f[j]);
        memset(N,0L,4001);
        memset(f,0,4001);
        scanf("%d",&i);
    }
    return 0;
}

C++: #include <iostream>
#include <array>

template<typename itr, typename func>
func for_each_withindex(itr fi, itr l, func f){
	unsigned i{};
	for(; fi!=l; ++fi,++i){
		f(*fi,i);
	}
	return f;
}

int main(int argc, char const* argv[])
{
	unsigned n{};
	while (std::cin >> n,n != 0) {
		unsigned long e{}, p{}, q{};
		bool isna{true};
		std::array<unsigned long,4001> es{};
		for (unsigned i = 0; i < n; i++) {
			std::cin >> e >> p >> q;
				es.at(e) += p * q;
		}
		for_each_withindex(es.begin(), es.end(), [&isna](auto sell,auto e){ 
				if (sell>=1e6) {
				std::cout << e << std::endl;
				isna = false;
				}});
		if (isna) {
			std::cout << "NA" << std::endl;
		}

	}
	return 0;
}

C++:  #include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 
 using namespace std;
 
 int arr[4000+5]={0};
 
 int main()
 {
   int n;
   while(cin>>n&&n)
   {
     int count=0;
     map<int,long long int> mm;
     bool flag=false;
     for(int i=0;i<n;i++)
     {
       int id,p,q;
       cin>>id>>p>>q;
       mm[id]+=(p*q);
       if(i==0) arr[count++]=id;
       int j;
       for(j=0;j<count;j++)     
       {
         if(arr[j]==id) break;        
       }   
       if(j==count) arr[count++]=id;
     }           
     for(int i=0;i<count;i++)
     {
       int kk=arr[i];
       if(mm[kk]>=1000000)
       { 
         cout<<arr[i]<<endl;
         flag=true;
       }        
     }
     if(!flag) cout<<"NA"<<endl;
   }
   //while(1);
   return 0;
 }

C++: #include <iostream>
#include <array>

template<typename itr, typename func>
func for_each_withindex(itr fi, itr l, func f){
	unsigned i{};
	for(; fi!=l; ++fi,++i){
		f(*fi,i);
	}
	return f;
}

int main(int argc, char const* argv[])
{
	unsigned n{};
	while (std::cin >> n,n != 0) {
		long long e{}, p{}, q{};
		bool isna{true};
		std::array<long long,4001> es{};
		std::array<bool,4001> esadup{};
		for (unsigned i = 0; i < n; i++) {
			std::cin >> e >> p >> q;
			es.at(e) += p * q;
			if (es.at(e) >= 1000000 && ! esadup.at(e)) {
				std::cout << e << std::endl;
				esadup.at(e) = true;
				isna = false;
			}
		}
		//for_each_withindex(es.begin(), es.end(), [&isna](long long sell,long long e){ 
		//		if (sell>=1000000) {
		//		std::cout << sell << ":";
		//		std::cout << e << std::endl;
		//		isna = false;
		//		}});
		if (isna) {
			std::cout << "NA" << std::endl;
		}

	}
	return 0;
}

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

int main(int argc, char **argv)
{
	int i, p, q, n, size = 0, flag, pri = 1, max;
	int *sum = (int *)calloc(4000, sizeof(int));
	int *pr = (int *)calloc(4000, sizeof(int));
	int *id = (int *)calloc(1000, sizeof(int));

	while(1){
		cin >> n;
		
		if(n == 0){
			cout << "NA" << endl;
			break;
		}
		
		while(n > 0){
			n--;
			cin >> i >> p >> q;
			flag = 0;
			for(int j = 0; j < size; j++){
				if(id[j] == i){
					if(p*q > sum[i] || pri != pr[i]){
						sum[i] = p*q;
						pr[i] = pri;
					}
					flag = 1;
					break;
				}
			}
		
			if(flag == 0){
				id[size] = i;
				sum[i] = p*q;
				pr[i] = pri;
				size++;
			}
		}

		max = id[0];
		for(int j = 1; j < size; j++){
			if(sum[max] < sum[id[j]]){
				max = id[j];
			}
		}
		
		cout << max << endl;
		
		pri++;
	}
	
	return 0;
}