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 <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;
int main(){	
	int n;
	while(cin>>n){
	      if(n==0) return 0;
	      vector<int> id;
	      vector<long long> sale(4001,-1);
	      int x,y,z;
	      for(int i=0;i<n;i++){
		cin>>x>>y>>z;
               if(sale[x]==-1){
                  sale[x]=0;
		  id.push_back(x);}
	       sale[x]+=(long long )y*z;
	       }
               bool na = true;
	       for(int i=0;i<(int)id.size();i++){
                     if(sale[id[i]] >= 1000000){                          
				cout<<id[i]<<endl;
				na = false;
		     }
		}
		if(na) cout<<"NA"<<endl;
	}

}

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

typedef struct{
	int sum;
	int pr;
} data;

int main(int argc, char **argv)
{
	int i, p, q, n, size = 0, flag, pri = 1, max;
	data *sarray = (data *)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 > sarray[i].sum || pri != sarray[i].pr){
						sarray[i].sum = p*q;
						sarray[i].pr = pri;
					}
					flag = 1;
					break;
				}
			}
		
			if(flag == 0){
				id[size] = i;
				sarray[i].sum = p*q;
				sarray[i].pr = pri;
				size++;
			}
		}

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

C++: #include<iostream>
#include<cstdio>
#include<cmath>
#include<map>
using namespace std;
int main(){
int n;
while(cin>>n,n){
long long ta[5000]={0},x[5000]={0};
int cnt=0,a,b,c;
	for(int i=0;i<n;i++){
	cin>>a>>b>>c;
	ta[a]+=b*c;
	bool f=1;
	for(int j=0;j<i;j++)if(x[j]==a)f=0;
	if(f)x[cnt++]=a;
	}
	bool f=1;
	for(int i=0;i<n;i++){
	if(ta[x[i]]>=1000000){cout<<x[i]<<endl;f=0;}
	}
	if(f)cout<<"NA"<<endl;
}
	return 0;
}

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

int main()
{
	int em[4000];
	int num,i,id,p,q,flag;
	cin>>num;

	while(num!=0){
    flag =0;

	for(i=0;i<4000;i++){
		em[i]=0;
	}

	for(i=0;i<=num-1;i++){
	    cin>>id >>p >>q;
		em[id]+=p*q;
	}

	for(i=0;i<4000;i++){
		if(em[i]>=1000000){
			cout<<i<<"\n";
		    flag =1;
		}
	}
	if(flag!=1)
		cout<<"NA\n";
	cin >>num;

	}
	return 0;
		
}

C++: #include <iostream>
#include <map>
using namespace std;
int main() {
  int n, e;
  long p, q;
  map<int, long> mp;
  map<int, long>::iterator itr;

  while(cin >> n) {
	if(n == 0) break;

	for(int i = 0; i < n; ++i) {
	  cin >> e >> p >> q;
	  itr = mp.find(e);
	  if(itr != mp.end()) {// found
		mp[e] += p * q;
	  }
	  else {// not found
		mp[e] = p * q;
	  }
	}

	bool isNA = true;
	for(itr = mp.begin(); itr != mp.end(); ++itr) {
	  if(itr->second >= 1000000) {
		cout << itr->first << endl;
		isNA = false;
	  }
	}
	if(isNA) {
	  cout << "NA" << endl;
	}

	mp.clear();
  }
  return 0;
}

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

int main( void )
{
	int n;
	while ( cin >> n && n != 0 )
	{
		vector <int> visited;
		map <int, long long> profit;
		bool exist = false;
		for ( int i = 0; i < min(n, 4000); i++ )
		{
			int no, p, q;
			cin >> no >> p >> q;

			profit[no] += (long long)p * q;

			if ( find( visited.begin(), visited.end(), no ) == visited.end() && profit[no] >= 1000000L )
			{
				exist = true;
				visited.push_back( no );
			}
		}

		if ( exist )
		{
			for ( vector <int>::iterator it = visited.begin(); it != visited.end(); it++ )
			{
				cout << *it << endl;
			}
		}
		else
			cout << "NA" << endl;
	}

	return 0;
}

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

int main(){
	int n;
	while(std::cin>>n){
		std::vector<int> v;
		if(!n)return 0;
		for(;n;n--){
			long long int num,price,quantity;
			std::cin>>num>>price>>quantity;
			if(price*quantity>=1000000){
				std::vector<int>::iterator it = std::find(v.begin(),v.end(),num);
				if(it==v.end())
					v.push_back(num);
			}
		}
		if(!v.size())std::cout<<"NA"<<std::endl;
		else{
		std::vector<int>::iterator it = v.begin();
		while(it!=v.end()){
			std::cout<<*it<<std::endl;
			it++;
		}
		}
	}
}

C++: #include <iostream>

using namespace std;

int main()
{
    while(1)
    {
        int i=0;
         cin>>i;
        if(i==0)
            break;
        else
        {
            int na=0;
       
            int h[4001];
            for(int k=0;k<=4000;k++)
            {
                h[k]=0;
            }
            for(int kp=1;kp<=i;kp++)
            {
                int j=0;int l=0;int m=0;
                cin>>j>>l>>m;
                h[j]+=(l*m);

            }
            for(int kk=1;kk<=4000;kk++)
            {
                if(h[kk]>=1000000)
                {
                    cout<<kk<<endl;
                    na++;
                }

            }
            if(na==0)
            {
                cout<<"NA"<<endl;
            }

        }
    }

    return 0;
}

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

typedef long long ll;
typedef queue<int> qi;

const int lim = 1000000;

int main()
{
    int n; ll en, price, qty;
    while(cin >> n && n) {
        if (n == 0) break;

        int check[4001] = {0};
        qi que;

        for(int i=0; i < n; ++i) {
            cin >> en >> price >> qty;

            if (check[en] >= 0) {
                check[en] += price*qty;
            }

            if (check[en] >= lim) {
                que.push(en);
                check[en]=-1;
            }
        }

        if (que.empty()) {
            cout << "NA" << endl;
        } else {
            for(int i=0,len=que.size(); i < len; ++i) {
                cout << que.front() << endl;
                que.pop();
            }
        }
    }

    return 0;
}

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

int main() {
  int num = 0;
  while (cin >> num, num) {
    vector<int> order;
    long data[4000] = { 0 };
    // ??\???
    for (int i = 0; i < num; i++) {
      int id, price, sold_num;
      cin >> id >> price >> sold_num;
      for (int i = 0; i < order.size(); i++) {
        if (order[i] == id) {
          break;
        }
        if (i == order.size() - 1) {
          order.push_back(id);
        }
      }
      if (order.size() == 0) {
        order.push_back(id);
      }
      data[id] += price*sold_num;
    }
    // ??????
    int count = 0;
    for (int i = 0; i < order.size(); i++) {
      if (data[order[i]] >= 1000000) {
        cout << order[i] << endl;
        count++;
      }
    }
    if (count == 0) {
      cout << "NA" << endl;
    }
  }
}