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




int main(){
	int n;
	cin >> n;

	while(n != 0){
		vector < pair<long, long> > v(n);
		int num = 0;
		for (int i = 0; i < n; ++i){
			long long id, p, q;
			cin >> id >> p >> q;
			v[i] = make_pair(id, p * q);
		}

		sort(v.begin(), v.end());
		long long sum = v[0].second;

		for(int i = 1; i < n ; i++){
			if(v[i].first == v[i-1].first){
				if(i + 1 != n){
					sum += v[i].second;

				}else{
					sum += v[i].second;
					if(sum >= 1000000){
						cout << v[i].first << endl;
						num++;
					}
				}
			}else{
				if(sum >= 1000000){
					cout << v[i-1].first << endl;
					num++;
				}
				sum = v[i].second;
				if(sum >= 1000000){
					cout << v[i].first << endl;
					num++;
				}
			}
		}

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

		cin >> n;
	}

	return 0;
}

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

int main(void){
	int a,b,c;
	int n;
	while(cin>>n,n){
		lli m[4001];
		bool f=false;
		for(int i=0;i<=4000;i++)m[i]=0;
		while(n--){
			cin>>a>>b>>c;
			m[a]+=b*c;
			if(m[a]>=1000000)f=true;
		}
		if(f){
			for(int i=0;i<=4000;i++){
				if(m[i]>=1000000)cout<<i<<endl;
			}
		}else{
			cout<<"NA"<<endl;
		}
	}
	return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<algorithm>
#include<set>
using namespace std;
typedef long long int ll;

int main()
{
    for(;;){
		ll n,num,pr,co;
		cin >> n;
		if(n==0)return 0;
		ll a[4000];
		for(int i=0;i<4000;i++)a[i]=0;
		for(int i=0;i<n;i++){
			cin >> num >> pr >> co;
			a[num-1]+=pr*co;
		}
		bool f=true;
		for(int i=0;i<4000;i++){
			if(a[i]>=1000000){
				printf("%d\n",i+1);
				f=false;
			}
		}
		if(f)printf("NA\n");
	}
    return 0;
}

C++: #include<iostream>
#include<vector>
int main() {
	std::vector<int> a;
	while (true) {
		int n;
		int c = 0;
		std::cin >> n;
		if (n == 0) {
			break;
		}
		std::vector<int> v(n), w(n);
		int t, u;
		for (int i = 0; i < n; ++i) {
			std::cin >> w[i] >> t >> u;
			v[i] = t*u;
		}
		for (int i = 0; i < n; ++i) {
			for (int l = 0; l < n; ++l) {
				if ((v[i] == v[l]) && (i != l)) {
					v[i] += v[l];
					v.erase(v.begin() + l);
					n -= 1;
				}
			}
		}
		for (int i = 0; i < n; ++i) {
			if (v[i] >= 1000000) {
				a.push_back(w[i]);
				++c;
			}
			if ((c == 0) && (i == n - 1)) {
				a.push_back(0);
			}
		}
		v.clear();
		w.clear();
	}
	for (int i = 0; i < a.size(); ++i) {
		if (a[i] == 0)std::cout << "NA" << std::endl;
		else std::cout << a[i] << std::endl;
	}
	return 0;
}

C++: #include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <cmath>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define ITER( c ) __typeof( c ).begin()
#define REP( i, m, n ) for ( int i = m; i < n; i++ )
#define UREP( i, m, n ) for ( unsigned int i = m; i < n; i++ )
#define IREP( c, it ) for ( ITER(c) it = c.begin(); it != c.end(); ++it )
#define ALL( c ) c.begin(), c.end()
#define PB( n ) push_back( n );
#define MP( a, b ) make_pair( a, b )
#define fst first
#define snd second

int main()
{
	while ( true )
	{
		int n;
		cin >> n;

		if ( n == 0 )
		{
			break;
		}

		bool be = false;

		REP( i, 0, n )
		{
			ull a, b, c;
			cin >> a >> b >> c;

			if ( 1000000 <= b * c )
			{
				cout << a << endl;
				be = true;
			}
		}

		if ( !be )
		{
			cout << "NA" << endl;
		}
	}

	return 0;
}

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

int main(){
	int n,a,b,c,flag;
	map<int, long long int> m;
	while (cin >> n, n){
		m.clear();
		flag = 0;
		for (int i = 0; i < n; i++){
			cin >> a >> b >> c;
			m[a] += (long long int)b * (long long int)c;
		}
		map<int, long long int>::iterator it = m.begin();
		while (it != m.end()){
			if ((*it).second >= 1000000ll){
				flag = 1;
				cout << (*it).first << endl;
			}
			it++;
		}
		if (!flag) cout << "NA" << endl;
	}
	return 0;
}

C++: #include <stdio.h>
#include <iostream>
#include <algorithm>
#include <iomanip>

using namespace std;

long long int n,a,b,c;



int main(){
    
        
    while(cin >> n){
        if(n==0)break;
        
        long long int ans[4001]={0};
        int ans_n[4001]={0};
        
        bool flag=true;
        for(int i=0; i<n; i++){
            cin>>a>>b>>c;
            ans_n[i]=a;
            if(b>=1000&&c>=1000)ans[a]=1000000;
            else if(b>=1000000)ans[a]=1000000;
            else ans[a]+=b*c;
        }
        
        for(int i=0; i<n; i++){
            if(ans[ans_n[i]]>=1000000){
                cout<<ans_n[i]<<endl;
                ans[ans_n[i]]=0;
                flag=false;
            }
        }
        
        if(flag)cout<<"NA"<<endl;
    }
            
}

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

int main() {
	long long int i, j, n, no[4000], tanka[4000], num[4000];
	bool flg=false;
	while (1) {
		j=0;
		flg=false;
		cin>>n;
		if (n==0) break;
		for (i=0; i<n; i++)
			cin>>no[i]>>tanka[i]>>num[i];
		for (i=0; i<n; i++) {
			if (tanka[i]*num[i]>1000000)
				flg=true, cout<<no[i]<<endl;
		}
		if (flg==false) cout<<"NA"<<endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int n;
ll need = (int)1e6;

int main() {
	while (1) {
		cin >> n; if (n == 0) break;
		
		map<ll, ll> sum;
		vector<ll> ids;
		for (int i = 0; i < n; i++) {
			ll id, p, q; cin >> id >> p >> q;
			bool add = true;
			for (int j = 0; j < (int)ids.size(); j++) {
				if (ids[j] == id) add = false;
			}
			if (add) ids.push_back(id);
			sum[id] += (p * q);
		}
		
		bool na = true;
		for (int i = 0; i < (int)ids.size(); i++) {
			if (sum[ids[i]] >= need) {
				cout << ids[i] << endl;
				na = false;
			}
		}
		
		if (na) cout << "NA" << endl;
	}
	
	return 0;
}

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

int main(){
  int n;
  while(cin >> n, n){
    vector<int> num;
    vector<bool> used(n, false);
    map<int, long long> sales;
    int a, b, c;
    for(int i = 0;i < n;i++){
      cin >> a >> b >> c;
      num.push_back(a);
      sales[a] += b * c;
    }
    bool ok = false;
    for(int i = 0;i < n;i++){
      int p = num[i];
      if(used[p])continue;
      used[p] = true;
      if(sales[p] >= 1000000){
	cout << p << endl;
	ok = true;
      }
    }
    if(!ok)cout << "NA" << endl;
  }
  return 0;
}

C++: #include<iostream>
#include<cstring>
#include<map>
using namespace std;
int main(){
  long long ans[4000]={0};
  int n,number,money,many,over_many=0,over[4000]={0};
  while(1){
    cin >> n;
    if(n==0)break;
    over_many=0;
    memset(over,0,sizeof(over));
    memset(ans,0,sizeof(ans));
    for(int i=0;i<n;i++){
      cin >> number >> money >> many;
      ans[number]+=money*many;

      if(ans[number]>=1000000){
	if(over[number]==0){
	  over_many++;
	  over[number]=1;
	}
      }

    }
    if(over_many==0){
      cout << "NA" << endl;
    }
    else{
      for(int k=0,j=0;j<over_many;k++){
	if(over[k]==1){
	  cout << k << endl;
	  j++;
	}
      }
    }

  }
}