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<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<string>
#include <vector>
#include <map>
#include<cstdlib>
#include<iomanip>
#include<queue>


using namespace std;

void Solution()
{
   	int n;
    
    long long number, perPrice, amount;
    
    bool isUsed;
    //long long valueCheck[4000];
    vector<long long> valueCheck(4001, 0);
    queue<int> que;
    
    while(true)
    {
        isUsed = false;
        
        cin>>n;
        
        if (n == 0)
        {
            break;
        }
        
        while(n--)
        {
            cin>>number>>perPrice>>amount;
            
            valueCheck[number] += perPrice * amount;
            que.push(number);
        }
        
        while (!que.empty())
        {
            if (valueCheck[que.front()] >= 1000000)
            {
                cout<<que.front()<<endl;
                isUsed = true;
            }
            
            valueCheck[que.front()] = 0;
            que.pop();
        }
        
        if (!isUsed)
        {
            cout<<"NA"<<endl;
        }
        
//            if ( valueCheck >= 1000000)
//            {
//                cout<<number<<endl;
//            }
//            else
//            {
//                count++;
//            }
//            
//            if (count == m)
//            {
//                cout<<"NA"<<endl;
//            }
        
    }
}

int main()
{
    Solution();
    return 0;
}

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

struct DATA{
        int id;
        double sales;
};

int main()
{

        while(1){
                int n;
                cin >> n;
                if(!n) break;
                
                list<struct DATA> sales_list;
                for(int i=0; i<n; i++){
                        int id;
                        double p, q;
                        cin >> id >> p >> q;
                        int flag = 0;
                        for(list<struct DATA>::iterator i=sales_list.begin(); i!=sales_list.end(); i++){
                                if(i->id==id){
                                        i->sales += p*q;
                                        flag = 1;
                                        break;
                                }
                        }
                        if(!flag){
                                struct DATA d;
                                d.id = id;
                                d.sales = p*q;
                                sales_list.push_back(d);
                        }
                }
                
                int flag = 0;
                for(list<struct DATA>::iterator i=sales_list.begin(); i!=sales_list.end(); i++){
                        if( i->sales >= 1000000 ){
                                cout << i->id << endl;
                                flag = 1;
                        }
                }
                if(!flag) cout << "NA" << endl;
        }

        return 0;
}

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

int main()
{
    int n, no;
    long long yen, num;
    long long total[4001];
    std::queue<int> que;
    
    for (int i = 0; i < 4001; ++i) {
        total[i] = 0;
    }

    std::cin >> n;
    
    while (n != 0) {
        
        bool update = false;
        /*input*/
        for (int i = 0; i < n; ++i) {
            scanf("%d %lld %lld", &no, &yen, &num);
            total[no] += yen * num;
            que.push(no);
        }
        /*output*/
        while (!que.empty()) {
            if (total[que.front()] >= 1000000) {
                std::cout << que.front() << std::endl;
                update = true;
            }
            total[que.front()] = 0;
            que.pop();
        }
        if (!update) {
            std::cout << "NA" << std::endl;
        }
        std::cin >> n;
    }
    
    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

int main(void){
    int i,l,k;
    int n;
    long long id,c,q;
    long long data_list[4001];
    int id_list[4000];
    bool id_flag;
    bool na_flag;
    
    while(cin>>n,n!=0){
        k=0;
        memset(data_list,0,sizeof(data_list));
        for(l=0;l<n;l++){
            cin>>id>>c>>q;
            if(data_list[id]+(c*q)>=1000000)data_list[id]=1000000;
            else{
                data_list[id]+=(c*q);
            }
            id_flag=true;
            for(i=0;i<k+1;i++){
                if(id_list[i]==id){
                    id_flag=false;
                }
            }
            
            if(id_flag){
                id_list[k]=id;
            k++;
            }
        }
        na_flag=true;
        for(l=0;l<k;l++){
            if(data_list[id_list[l]]>=1000000){
                cout<<id_list[l]<<endl;
                na_flag=false;
            }
        }
        if(na_flag){
            cout<<"NA"<<endl;
        }
    }
    return(0);
}

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

int main() {
	int num;						//1???????????????????????\????????°
	int data_set = 0;				//???????????????????????°
	bool do_continue = true;		//??????????????°
	std::vector<string> result;		//??????

	while (do_continue) {
		cin >> num;		//???????????°??\???
		if ((num == 0) || (data_set > 50)) {
			do_continue = false;
		}
		else {
			bool na_flg = true;				//NA????????°
			data_set++;						//?????????????????????
			std::map<int, int> e;			//??????
			std::vector<int> employee;
			int fst, snd, thd;

			for (int i = 0; i < num; i++) {
				cin >> fst >> snd >> thd;
				employee.push_back(fst);
				//????????????????????´???
				if (e.count(employee[i])) {
					e[employee[i]] += snd * thd;
				}
				//??°???????????????
				else {
					e[employee[i]] = snd * thd;
				}
			}

			//1000000??\???????????????????´?
			for (unsigned int j = 0; j < employee.size(); j++) {
				if (e[employee[j]] >= 1000000) {
					na_flg = false;
					result.push_back(std::to_string(employee[j]));
				}
			}

			//NA??????
			if (na_flg) {
				result.push_back("NA");
			}
		}
	}

	for (unsigned int i = 0; i < result.size()-1; i++) {
		cout << result[i] << endl;
	}

	//while (1);

	return 0;
}

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

int main(int argc, char **argv)
{
	int i, n, size = 0, flag, pri = 1, max;
	double p, q;
	double *sum = (double *)calloc(4000, sizeof(double));
	int *pr = (int *)calloc(4000, sizeof(int));
	int *id = (int *)calloc(4000, 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;
}