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

			bool found = false;
			for (unsigned int i = 0; i < data.size(); ++i) {
				if (data[i].first == id) {
					data[i].second += g;
					found = true;
				}
			}
			if (!found) data.push_back(elemType(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 <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <set>
#include <cmath>
#include <map>


int main(int,char**){
	typedef std::map<short,unsigned long long> Data;
	
	int n;
	while(std::cin>>n){
		if(!n) break;
		bool ex(0);
		Data tbl;
		std::vector<int> seq;
		while(n--){
			int Cnum,at,num;
			std::cin >>Cnum>>at>>num;
			if(tbl[Cnum]==0) seq.push_back(Cnum);
			tbl[Cnum]+=at*num;
		}
		for(std::vector<int>::const_iterator it=seq.begin();it!=seq.end();++it){
			if(tbl[*it]>=1000000){ std::cout<< *it << std::endl; ex=1;}
		}
		if(!ex) std::cout << "NA"<<std::endl;
	}

	return 0;
}

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

int main(){
 int id,price,num,count;
 int sameid[4000];
 bool isBe=false,isSame=false;

 while(true){
  cin>>count;
  if(count==0){
   break;
  }
  for(int i=0;i<count;i++){
   cin>>id>>price>>num;
   sameid[i]=id;
   for(int j=0;j<=i;j++){
    if(j==i){
     break;
    }
    if(id==sameid[j]){
      isSame=true;
      break;
    }
   }
   if(price*num>=1000000&&!isSame){
    cout<<id<<'\n';
    isBe=true;
   }
   isSame=false;
  }
  if(!isBe){
   cout<<"NA\n";
  }
  count=0;
  isBe=false;
  for(int i=0;i<count;i++){
   sameid[i]=0;
  }
 }
 return 0;
}

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


int main(void)
{
	int n;

	while(cin >> n,n){
		int d[4000];
		bool f = false;
		fill(d,d+4000,0);

		int no,m,k;
		for(int i = 0; i < n; i++){
			cin >> no >> m >> k;
			d[no-1] += m*k;
		}

		for(int i = 0; i < 4000;i++)
			if(d[i] >= 1000000){
				cout << i+1 << endl;
				f = 1;
			}
		if(!f)
			cout << "NA" << endl;
	}

	

	return 0;
}

C++: #include<iostream>
#include<vector>
#include<map>
using namespace std;
main(){
  //mlÛ¶vÛ¶
  long long a,b,c,n,f;
  //aÔbP¿cÊ
  while(cin>>n,n){
		map<int,long long> m;
		vector<int> v;
		f=1;
    for(;n;n--){
			cin>>a>>b>>c
      if(!m[a])v.push_back(a);
      m[a] += b*c;
    }
    
    for(int i=0;i<v.size();i++){
			if(m[v[i]]>999999)f=0,cout<<v[i]<<endl;}
    if(f)cout<<"NA"<<endl;
  }
}

C++: #include<iostream>
using namespace std;
long long t[4000],z,b,c;
int n,a,s[4000],u[4000],cnt;
void change(int x,int y){
  int tmp;
  long long TMP;
  TMP=t[x];t[x]=t[y];t[y]=TMP;
  tmp=s[x];s[x]=s[y];s[y]=tmp;
  tmp=u[x];u[x]=u[y];u[y]=tmp;
}
void init(){
  for(int i=0;i<4000;i++){
    t[i]=0;
    s[i]=u[i]=4001;
  }
  cnt=0;
}
int main(){
  while(1){
    cin>>n;
    if(n==0)break;
    init();
    for(int i=0;i<n;i++){
      cin>>a>>b>>c;
      a--;
      u[a]=a;
      z=b*c;
      t[a]=t[a]+z;
      if(s[a]==4001)s[a]=i;
    }
    for(int i=3999;i>0;i--){
      for(int j=0;j<i;j++){
	if(s[j]>s[j+1]){
	  change(j,j+1);
	}
      }
    }
    for(int i=3999;i>0;i--){
      for(int j=0;j<i;j++){
	if(t[j]<t[j+1]){
	  change(j,j+1);
	}
      }
    }
    cnt=0;
    for(int i=0;i<4000;i++){
      if(t[i]>=1000000){
	cout<<u[i]+1<<endl;
	cnt=1;
      }else{
	break;
      }
    }
    if(cnt==0)cout<<"NA"<<endl;
    
  }
  
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <map>
#include <set>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#define rep(i,l,n) for(lint i=l;i<n;i++)
#define rer(i,l,n) for(lint i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define pb(a) push_back(a)
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef vector<lint> vli;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

int main(){
	while (1){
		queue<int> q;
		lint d[4010] = {};
		int n;
		cin >> n;
		if (n == 0) break;
		int a, b, c;
		rep(i, 0, n){
			cin >> a >> b >> c;
			if (d[a] == 0){
				q.push(a);
			}
			d[a] += b*c;
		}
		int ct = 0;
		while (!q.empty()){
			int x = q.front(); q.pop();
			if (d[x] >= 1000000){
				o(x); ct++;
			}
		}
		if (ct == 0){
			o("NA");
		}
	}

}

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{};
		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](long long sell,long long e){ 
				if (sell>=1000000) {
				std::cout << e << std::endl;
				isna = false;
				}});
		if (isna) {
			std::cout << "NA" << std::endl;
		}

	}
	return 0;
}

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

int main(){
    int n;
    
    while(true){
        int cnt = 0;
        unsigned long long int s[4002]={0},gs[4002]={0};
        
        cin >> n;
        if(!n) break;
        
        int t,cost;
        int num;
        for(int i = 0 ; i < n ; i++){
            cin >> num >> t >> cost;
            s[num] += t*cost;
            gs[i] = num;
        }
        
       for(int i = 0 ; i < n ; i++){
            for(int j = i+1 ; j < n ; j++){
                if(gs[i]==gs[j]&&i < j){
                    gs[j] = 4001;
                }
            }
        }
        
        for(int i = 0 ; i < n ; i++){
            if(s[gs[i]] >= 1000000){
                cout << gs[i] << endl;
                cnt++;
            }
        }
        if(!cnt) cout << "NA" << endl;
    }
    
    return 0;
}

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

int main()
{
	int n,id,sale,k,cnt;
	int outid[4001];
	while (1)
	{
		cin >> n;
		if (n == 0)break;
		cnt = 0;
		for (int i = 0; i < n; i++)
		{
			cin >> id >> sale >> k;
			if (sale*k >= 1000000)
			{
				cnt++;
				outid[cnt] = id;
			}
		}
		if (cnt==0)
		{
			cout << "NA" << endl;
		}
		else
		{
			for (int i = 1; i <= cnt; i++)
			{
				cout << outid[i] << endl;
			}
		}
	}
	return 0;
}