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(void){
	int n;
	int a,b,c,d;
	int num[4001],tan[4001];
	bool flag=false;
	while(1){
		for(a=0;a<=4000;a++){
			num[a]=0;
			tan[a]=0;
		}
		cin >> n;
		if(n==0)break;
		for(a=0;a<n;a++){
			cin >> b >> c >> d;
			num[b]+=c,tan[b]+=d;
		}
		for(a=1;a<4000;a++){
			if(num[a]*tan[a]>=1000000)printf("%d\n",a),flag=true;
		}
		if(flag==false)printf("NA\n");
	}
	return 0;
}

C++: #include<algorithm>
#include<iostream>
#include<vector>
#include<stdio.h>
struct su{
	int num;
	int sum;
}p[1001];
using namespace std;
int main()
{
	int n,i2;
	int sn,x, y,l=0;
	while (1){
		l = 0;
		cin >> n;
		if (n == 0)break;
		for (int i = 0; i < n; i++){
			cin >> sn >> x >> y;
			for (i2 = 0; i2 < l; i2++){
				if (p[i2].num == sn){
					p[i2].sum += x*y;
					break;
				}
			}
			if (i2 == l){
				p[l].sum = 0;
				p[l].num = sn;
				p[l].sum += x*y;
				l++;
			}
		}
		int maxn = 0;
		int maxc = 0;
		for (int i = 0; i < l; i++){
			if (maxn < p[i].sum){
				swap(maxn, p[i].sum);
				maxc = p[i].num;
			}
		}
		if (maxn >= 1000000){
			cout << maxc << endl;
		}
		else
			cout << "NA" << endl;
	}
}

C++: 
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <math.h>
#include <utility>
#include <set>
#include <map>
#define INF 100000
#define rep(i,n) for(int i =0;i<n;i++)
using namespace std;
typedef long long int ll;

#define MAX 5000

int main(){
    for (;;) {
        int n;
        cin >> n;
        if(n==0) break;
        vector<ll> num(4001,0),pre(n,0),data(4001,0);
        for (int i=0; i<n; i++) {
            int a,b,c;
            cin >>a >>b >>c;
            data[a]+=b*c;
            if(num[a]==0) num[a]=i+1;
        }
        for (int k=0; k< 4001; k++) {
            if(num[k]!=0) pre[num[k]]=k;
        }
        ll ch=0;
        for (int j=0; j<n; j++) {
            if (data[pre[j]]>=1000000) {
                cout <<pre[j]<<endl;
                ch++;
            }
        }
        if(ch==0) cout << "NA"<<endl;
    }
}

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

int main()
{
	int n;
	int No;
	long long int value, num;
	long long int mas;

	int a[4000];
	while(true)
	{
		cin >> n;
		if(n == 0) break;

		int x = 0;
		for(int i=0; i<n; i++){
			cin >> No >> value >> num;
			mas = value*num;
			if(mas >= 1000000){
				a[x] = No;
				x++;
			}
		}

		if(x == 0)
			cout << "NA" << '\n';
		else
			for(int i=0; i<x; i++)
				cout << a[i] << '\n';
	}
	return 0;
}

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

int main(){
    int n, id, p, q;
    std::map<int, int> workers;
    std::map<int, int>::iterator it;
    
    while(std::cin >> n){
        if(!n)
            break;
            
        for(int i=0; i<n; i++){
            std::cin >> id >> p >> q;
            workers[id] += p * q;
        }
        
        bool found = false;
        for(it = workers.begin(); it != workers.end(); it++){
            if(it->second >= 1000000){
                if(found)
                    std::cout << ' ' << it->first;
                else{
                    std::cout << it->first;
                    found = true;
                }
            }
        }
        
        if(found)           
            std::cout << std::endl;
        else
            std::cout << "NA" << std::endl;
        workers.clear();
    }
    
    return 0;
}

C++: #include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define vi vector<int>
#define VS vector<string>
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back

using namespace std;

int main(){
    int n;
    while(cin >> n, n){
        map<int, long long> m;
        vector<int> v;
        for(int i=0; i < n; i++){
            int p, q, r;
            cin >> p >> q >> r;

            if(m[p] == 0) v.pb(p);
            m[p] += q*r;
        }
        bool isExist = false;
        for(int i=0; i < v.size(); i++){
            if(1000000 <= m[v[i]]){
                isExist = true;
                cout << v[i] << endl;
            }
        }
        if(!isExist) cout << "NA" << endl;
    }
}

C++: #include <cstdio>
#include <algorithm>

#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;

typedef long long ll;

int n;
int s[4000];
int sn;
int index[4001];
int id[4000];

int main(){
	while(1){
		scanf("%d", &n);
		if(n == 0){
			break;
		}

		fill(index, index + 4001, -1);

		rep(i, n){
			int a, x, y;
			scanf("%d%d%d", &a, &x, &y);

			if(index[a] == -1){
				index[a] = sn;
				id[sn] = a;
				s[sn++] = 0;
			}
			s[index[a]] = min(ll(1e6), s[index[a]] + ll(x) * y);
		}

		bool none = true;
		rep(i, sn){
			if(s[i] >= int(1e6)){
				printf("%d\n", id[i]);
				none = false;
			}
		}
		if(none){
			puts("NA");
		}

		sn = 0;
	}
	return 0;
}

C++: //include
//------------------------------------------
#include <iostream>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
using namespace std;

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(a);i>(b);i--)
#define REP(i,n)  FOR(i,0,n)

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//debug
//-------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

long long data[4001];

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

    int n;
    while(1) {
        cin >> n;
        if (!n) break;
        memset(data, 0, sizeof(data));
        REP(i, n) {
            int e;
            long long p, q;
            cin  >> e >> p >> q;
            data[e] += p * q;
        }
        int c = 0;
        FOR(i, 1, 4001) {
            if (data[i] >= 1000000) {
                cout << i << endl;
                ++c;
            }
        }

        if (!c) cout << "NA" << endl;
    }

    return 0;
}