Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	for scanner.Scan() {
		n, _ := strconv.Atoi(scanner.Text())
		if n == 0 {
			break
		}

		sales := make([]int, 4000)
		members := make([]int, 0)
		memberCheck := make(map[int]bool)

		for i := 0; i < n; i++ {
			scanner.Scan()
			input := strings.Split(scanner.Text(), " ")
			e, _ := strconv.Atoi(input[0])
			p, _ := strconv.Atoi(input[1])
			q, _ := strconv.Atoi(input[2])

			if e >= 1 && e <= 4000 && memberCheck[e] == false {
				members = append(members, e)
				memberCheck[e] = true
			}
			sales[e-1] += p * q
		}

		emptyFlag := true
		for _, v := range members {
			if sales[v-1] >= 1000000 {
				fmt.Println(v)
				emptyFlag = false
			}
		}

		if emptyFlag == true {
			fmt.Println("NA")
		}
	}
}

C++: #include<iostream>

using namespace std;


int main(){

	int all[4001] = {};
	int code, a, b, n, i,j;

	while (1){
		j = 0;
		for (i = 0; i < 4001; i++){
			all[i] = 0;
		}


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

		for (i = 0; i < n; i++){
			cin >> code >> a >> b;
			all[code] += a*b;
			
		}

		for (i = 0; i < 4001; i++){
			if (all[i] >= 1000000){
				cout << i << endl;
				j++;
			}
		}

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

	}
}

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

int main(){
	long long int n, a, b, c;
	int flag;
	map<int, long long int> m;
	vector<int> v;
	while (cin >> n, n){
		m.clear();
		v.clear();
		flag = 0;
		for (int i = 0; i < n; i++){
			cin >> a >> b >> c;
			if(m[a] == 0) v.push_back(a);
			m[a] += b * c;
		}
		for (int i = 0; i < v.size(); i++){
			if (m[v[i]] >= 1000000ll){
				flag = 1;
				cout << v[i] << endl;
			}
		}
		if (!flag) cout << "NA" << endl;
	}
	return 0;
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    map<int, long> mp;
    vector<int> vec;
    while (cin >> n && n != 0) {
        for (int i = 0; i < n; i++) {
            int id, p, q;
            cin >> id >> p >> q;
            mp[id] += p * q;
        }
        for (auto m : mp)
            if (m.second >= 1000000) vec.push_back(m.first);

        if (vec.size() == 0)
            cout << "NA" << endl;
        else {
            for (auto v : vec) cout << v << endl;
        }

        mp.clear();
        vec.clear();
    }
    return EXIT_SUCCESS;
}

C++: #include<iostream>
using namespace std;
int ans[4000];

int main(){
	int N;
	int e, p, q;
	int x;
	while (1){
		x = 0;
		cin >> N;
		if (N == 0)break;
		while (N>0){
			cin >> e >> p >> q;
			if (p*q >= 1000000){
				ans[x] = e;
				x++;
			}
			N--;
		}
		if (ans[0] == 0){ cout << "NA" << endl; }
		else for (int i = 0; i < N; i++)
		{
			if (ans[i] == 0)break;
			cout << ans[i] << endl;
		}
	}
	return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<ll, ll>P;

int main() {
	ll n;
	while (cin >> n, n) {
		map<ll, ll>mp;
		map<ll, ll>pos;
		rep(i, n) {
			ll e, p, q; cin >> e >> p >> q;
			mp[e] += p*q; pos[e] = i;
		}
		vector<P>v;
		for (P i : mp)v.push_back(i);
		sort(v.begin(), v.end(), [&](P a, P b) {return pos[a.first] <= pos[b.first]; });
		bool flag = true;
		for (P i : v) {
			if (i.second >= 1000000) {
				cout << i.first << endl;
				flag = false;
			}
		}
		if (flag)puts("NA");
	}
}

C++: #include <cstdio>
#include <map>
using namespace std;
typedef long long int lli;
typedef map<int, int> M;

int main() {
  lli sum[4000];
  int gid[4000];
  int n, i, j, p, q, lid;
  M m;
  bool b;

  while (1) {
    scanf("%d", &n);
    if (!n) break;
    m.clear();
    for (j=0; j<n; j++) sum[j] = 0;
    for (j=0; j<n; j++) {
      scanf("%d %d %d", &i, &p, &q);
      lid = j;
      pair<M::iterator, bool> res = m.insert(M::value_type(i, lid));
      if (!res.second) {
        M::iterator it = m.find(i);
        lid = it->second;
      }
      gid[lid] = i;
      sum[lid] += (lli)p*q;
    }
    b = false;
    for (j=0; j<(int)m.size(); j++) {
      if (sum[j] >= 1000000) {
        printf("%d\n", gid[j]);
        b = true;
      }
    }
    if (!b) {
      printf("NA\n");
    }
  }

  return 0;
}

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

using namespace std;

int main()
{
	int N, X, Y, Z;

	while (true)
	{
		cin >> N;

		if (N == 0) { break; }

		vector<long long> P(4001);

		for (int i = 0; i < N; i++)
		{
			cin >> X >> Y >> Z;

			P[X] += (long long)Y * Z;
		}

		int count_ = 0;

		for (int i = 1; i <= 4000; i++)
		{
			if (P[i] >= 1000000)
			{
				cout << i << endl; count_++;
			}
		}

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

	return 0;
}

C++: #include <iostream> 
#include <string> 
#include <vector> 
#include <cmath> 
#include <algorithm> 
#include <cstdlib> 

using namespace std;

int main()
{
	int n,a,f;
	long long b,c;

	while(1){
		f=1;
		cin>>n; if(n==0) return 0;

		for(int i=0;i<n;i++){
			cin>>a>>b>>c;
			if(b*c>=1000000){ cout<<a<<endl; f=0;}
		}
		if(f) cout<<"NA"<<endl;
	}
}

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

int main(){
	while(1){
        int n;
        cin >> n;
        if(n == 0) break;
        long long a[5000] = {0};
        long long int number;
        long long int jun[5000] = {0};
        long long tanka,kazu;
        for(int i = 0; i < n; i++){
            cin >> number >> tanka >> kazu;
            a[number] += tanka * kazu;
            jun[i] = number;
        }
        bool flg = 0;
        for(int i = n; i >= 0; i--){
            if(a[jun[i]] >= 1000000){
                cout << jun[i] << endl;
                a[jun[i]] = 0;
                flg = 1;
            }
        }


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

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

int main(){
	int n,a,b,c,flag;
	map<int, long long int> m;
	vector<int> v;
	while (cin >> n, n){
		m.clear();
		flag = 0;
		for (int i = 0; i < n; i++){
			cin >> a >> b >> c;
			if(m[a] == 0) v.push_back(a);
			m[a] += (long long int)b * (long long int)c;
		}
		for (int i = 0; i < v.size(); i++){
			if (m[v[i]] >= 1000000ll){
				flag = 1;
				cout << v[i] << endl;
			}
		}
		if (!flag) cout << "NA" << endl;
	}
	return 0;
}

C++: #include<stdio.h>
#include<math.h>
#include<string.h>


int main(){
	long long int uriage[4000][3],n,no,tanka,su,i,j,newflag,naflag;
	
	while(0<=scanf("%lld",&n)){
		if(n==0) break;
		
		memset(uriage,0,sizeof(uriage));
		
		for(i=0;i<n;i++){
			scanf("%lld%lld%lld",&no,&tanka,&su);
			
			newflag=0;
			
			for(j=0;j<n;j++){
				if(uriage[j][0]==no && uriage[j][2]==1){
					uriage[j][1]+=tanka*su;
					newflag=1;
					break;
				}
			}
			
			if(newflag==0){
				for(j=0;j<n;j++){
					if(uriage[j][2]==0){
						uriage[j][1]+=tanka*su;
						uriage[j][0]=no;
						uriage[j][2]=1;
						break;
					}
				}
			}
		}
		naflag=0;
		for(i=0;i<n;i++){
			if(uriage[i][2]==0)break;
			if(uriage[i][1]>=1000000){
				printf("%lld\n",uriage[i][0]);
				naflag=1;
			}
		}
		if(naflag==0)printf("NA\n");
	}
	return 0;
}