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 <string>
using namespace std;

int main()
{
	int n,id,sale,k,cnt,flg;
	while (1)
	{
		int outid[4001] = { 0 }, total[4001] = {0};
		cin >> n;
		if (n == 0)break;
		cnt = 0;
		flg = 0;
		for (int i = 0; i < n; i++)
		{
			cin >> id >> sale >> k;
			outid[i] = id;
			total[i] = sale*k;
		}

		for (int i = 0; i < n-1; i++)
		{
			for (int j = i+1; j < n; j++)
			{
				if (outid[i]==outid[j])
				{
					total[i] += total[j];
					cnt++;
				}
			}
		}

		for (int i = 0; i < n-cnt; i++)
		{
			if (total[i] >= 1000000)
			{
				cout << outid[i] << endl;
				flg = 1;
			}
		}

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

C++: #include<cstdio>
#include<map>
#include<vector>
std::vector<std::pair<int, long long>> pq;
int main() {
	int n, i, e;
	long long p, q;
	bool match;
	while (true) {
		scanf("%d", &n);
		if (n == 0)break;
		for (i = 0; i < n; i++) {
			scanf("%d%lld%lld", &e, &p, &q);
			match = false;
			for (auto itr = pq.begin(); itr != pq.end(); itr++) {
				if (itr->first == e) {
					itr->second += p*q;
					match = true;
					break;
				}
			}
			if (!match)pq.push_back(std::make_pair(e, p*q));
		}
		match = false;
		for (auto itr = pq.begin(); itr != pq.end(); itr++) {
			if (itr->second >= 1000000) {
				printf("%d\n", itr->first);
				match = true;
			}
		}
		if (!match)printf("NA\n");
		pq.clear();
	}
	return 0;
}

C++: #include<stdio.h>
#include<list>
class hoge{
 public:
  int num;
  int v;
  bool ov;
  hoge(int n,int v,int c){    
    num=n;
    ov=false;
    set(v,c);
  }
  void set(int va,int c);
  bool isOV(){ return ov; };
};
void hoge::set(int va,int c){
  unsigned long long int i=va;
  i*=c;
  if(ov)
    return ;
  if(i>=(1000000-v)){
    ov=true;
    return ;
  }
  v+=i;
}

int main(){
  using namespace std;
  int i,n,v,c,num,flg;
  long long int a;
  list<hoge> ls;
  list<hoge>::iterator pos;
  do{
    scanf("%d",&n);
    if(!n) break;
    for(i=0;i<n;i++){
      scanf("%d %d %d",&num,&v,&c);
      pos=ls.begin();
      while(pos!=ls.end()){
	if((*pos).num==num){
	  (*pos).set(v,c);
	  break;
	}
	pos++;
      }
      if(pos==ls.end()){
	ls.push_back(*(new hoge(num,v,c)));       
      }
    }
    pos=ls.begin();
    flg=1;
    while(pos!=ls.end()){
      if((*pos).isOV()){
	printf("%d\n",(*pos).num);
	flg=0;
      }
      pos++;
    }
    if(flg) printf("NA\n");
    ls.clear();
  }while(1);
  return 0;
}

C++: 
#include <stdio.h>
#include <iostream>
#include <map>
#include <set>
using namespace std;

typedef long long int ll;

ll solve(ll N);

int main(void) {

	ll N = 1;
	while(true) {
		cin >> N;
		if( N == 0 ) { break; }
		solve(N);
	}

	return 0;
}

ll solve( ll N ) {

	map<int, ll> m;
	set<int> s;

	for( int i = 0; i < N; i++ ) {
		int id;
		ll ps, q;
		cin >> id >> ps >> q;
		if( m.find(id) == m.end() ) {
			m[id] = ps*q;
		} else {
			m[id] += ps*q;
		}
		if( m[id] >= 1000000 ) 
			s.insert(id);
			
	}

	if( s.size() == 0 ) {
		cout << "NA" << endl;
	} else {
		for( auto it = s.begin(); it != s.end(); ++it ) {
			cout << (*it) << endl;
		}
	}
	return 0;
}

C++: #include <cmath>
#include <ctime>
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <numeric>
#include <utility>
#include <iomanip>
#include <cstdio>
#include <cctype>
#include <queue>
#include <complex>
#include <climits>

typedef long long ll;

using namespace std;

int main(void){
	int N;
	int id,p,q;
	while(cin >> N){
		queue<int> que;
		map<int, int> map;
		int check = 0;
		if(!N) break;
		for(int i=0; i<N; ++i){
			cin >> id >> p >> q;
			if(map.find(id) == map.end()){
				map[id] = p*q;
				que.push(id);
			} else {
				map[id] += p*q;
			}
		}
		while(que.size()){
			if(map[que.front()] >= 1000000){
				cout << que.front() << endl;
				check = 1;
			}
			que.pop();
		}
		if(check == 0) cout << "NA" << endl;
	}

	return 0;
}

C++: #include <iostream>
using namespace std;
struct {long long int sum; bool flg;} p[4000];
int main()
{
	int a, b, c, n, i;
	while (cin >> n && n)
	{
		int m = 0;
		for (i = 0; i < 4000; i++)
			p[i].sum = 0, p[i].flg = false;
		for (i = 0; i < n; i++)
		{
			cin >> a >> b >> c;
			p[a-1].sum += b*c;
		}
		for (i = 0; i < 4000; i++)
		{
			if (p[i].sum >= 1000000)
			{
				p[i].flg = true;
				m++;
			}
		}
		if (m <= 0)
			cout << "NA" << endl;
		else
			for (i = 0; i < 4000; i++)
				if (p[i].flg)
					cout << i+1 << endl;
	}
}

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

int main(){
	while(1){
		long n;
		map<int, long long> mp;
		
		scanf(" %ld", &n);
		if(n==0) break;
		
		for(long i=0; i<n; ++i){
			int num;
			long t, u;
			scanf(" %d %ld %ld", &num, &t, &u);
			
			if(mp.find(num)!=mp.end()) mp[num] += t*u;	
			else mp[num]=t*u;
				
		}		
		
		int count=0;
		for(map<int, long long>::iterator itr=mp.begin(); itr!=mp.end(); ++itr){
			if(itr->second>=1000000){
				printf("%d\n", itr->first);
				++count;
			}		
		}
		
		if(count==0) printf("NA\n");
	}	
}

C++: #include <stdio.h>
struct emp{
    int num;
    long long sale;
};
int main(){
    while(1){
        int n,num,count=0,c,flag1=0,flag2=0;
        long long p,q;
        struct emp e[4000];
        scanf("%d",&n);
        if(n==0) return 0;
        for(int i=0;i<n;i++){
            scanf("%d %lld %lld",&num,&p,&q);
            c=count;
            flag1=0;
            for(int j=0;j<count;j++){
                if(e[j].num==num) {
                    e[j].sale+=p*q;
                    flag1=1;
                    break;
                }
            }
            if(!flag1){
                e[count].num=num;
                e[count].sale=p*q;
                count++;
            }
        }
        for (int i=0; i<count; i++){
            if (e[i].sale>=1000000) {
                printf("%d\n",e[i].num);
                flag2=1;
            }
        }
        if(!flag2) printf("NA\n");
    }
}

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

int main() {
  int n;
  while (cin >> n) {
    if (n == 0) break;
    unsigned long int total[4000];
    for (int i = 0; i < 4000; i++) total[i] = 0;
    
    for (int i = 0; i < n; i++) {
      int a;
      unsigned long int b,c;
      cin >> a >> b >> c;
      total[a-1] += b*c;
    }
    
    bool NA = true;
    for (int i = 0; i < 4000; i++) {
      if ( total[i] >= 1000000) {
	cout << i+1 << endl;
	NA = false;
      }
    }
    if (NA) cout << "NA" << endl;
  }
  return 0;
}

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

using namespace std;

void solve()
{
	int N;
	while(cin >> N, N)
	{
		map<int, unsigned long long int> Map;
		bool Flag = false;
		unsigned long long int a, b, c;
		for(int i = 0; i < N; ++i)
		{
			cin >> a >> b >> c;
			Map[a] += b * c;
		}
		for(map<int, unsigned long long int>::iterator Ite = Map.begin(); Ite != Map.end(); ++Ite)
		{
			if(Ite->second >= 1000000)
			{
				cout << Ite->first << endl;
				Flag = true;
			}
		}
		if(!Flag)
		{
			cout << "NA" << endl;
		}
	}
}

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