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 <vector>
#include <iostream>
#include <map>
#include <algorithm>
#include <stdio.h>

using namespace std;

typedef long long ll;

int n, id, p, q;

const ll MAX = 1000000;

struct Mem {
    int id;
    ll c;
};

Mem array[40010];

int main(void) {
    while(cin >> n && n) {
        bool hap = false;
        for(int i = 0; i < n; i++) {
            cin >> array[i].id >> p >> q;
            array[i].c = p * q;
        }
        for(int i = 0; i < n - 1; i++) {
            for(int j = i + 1; j < n; j++) {
                if(array[i].id == array[j].id && array[j].id) {
                    array[i].c += array[j].c;
                    array[j].id = 0;
                }
            }
        }
        for(int i = 0; i < n; i++) {
            if(array[i].id && array[i].c >= MAX) {
                cout << array[i].id << endl;
                hap = false;
            }
        }
        if(hap) {
            cout << "NA" << endl;
        }
    }
    return 0;
}

C++: #include<iostream>
#include<cstring>
#include<vector>
using namespace std;
long long sales[4010];
#define foreach(r,p,it) for(r::iterator it=p.begin();it!=p.end();++it)

int main()
{
    int n;
    while(cin>>n)
    {
        if(n==0)break;
        vector<int> shains;
        shains.clear();
    
        memset(sales,0,sizeof(sales));
        int num,tanka,kazu;

        for(int i=0;i<n;i++)
        {
            cin>>num>>tanka>>kazu;
            sales[num] += tanka*kazu;
            int f=0;
            for(int j=0;j<shains.size();j++)
            {
                if(shains[j] == num){f=1;break;}
            }
            if(f==0) shains.push_back(num);
        }
        int na = 0;
        for(int i=0;i<shains.size();i++)
        {
            //cout <<"NUMBER"<<*it <<endl;
            if(sales[shains[i]] >= 1000000){cout<<shains[i]<<endl;na=1;}
        }
        if(na==0)cout<< "NA"<<endl;
    }
    return 0;
}

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

int main(){
	long long int total[4000],n,a,b,c;
	while(1){
		scanf("%lld",&n);
		if(n==0)break;
		memset(total,0,sizeof(total));
		while(n--){
			scanf("%lld%lld%lld",&a,&b,&c);
			total[a-1]=total[a-1]+b*c;
		}
		int res=0;
		for(int i=0;i<4000;i++){
			if(total[i]>=1000000){
				res=1;
				printf("%d\n",i+1);
			}
		}
		if(res) continue;
		else printf("NA\n");
	}
	return 0;
}

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

#define TAR 1000000

int main() {
	int n,num,ch;
	unsigned long t,k;
	while(cin >> n){
		ch = 0;
		while(n){
			scanf("%d %ld %ld",&num,&t,&k);
			if(k!=0){
				if(t > TAR/k){
					ch++;
				}else if((t == TAR/k)&&(TAR == k*t)){
					ch++;
				}
				if(((--n)==0)&&(ch==0)){
					cout << "NA" << endl;
				}
			}
		}
	}
	return 0;
}

C++: #include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string.h>
#include<math.h>
#include<cstring>
using namespace std;
#define Norma 1000000

int main(){
	while(1){
		long long sale[4001],a,b,c,i,j,n;
		int k=0;
		cin>>n;
		if(n==0)break;
		for(i=0;i<4001;i++){
			sale[i]=0;
		}
		for(i=0;i<n;i++){
			cin>>a>>b>>c;
			if(sale[a]>=0){
				sale[a]+=b*c;
				if(sale[a]>=Norma){
					cout<<a<<endl;
					sale[a]=-1;
					k++;
				}
			}
		}
		if(k==0){
			cout<<"NA"<<endl;
		}
	}
	return 0;
}

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

int loop(int h, int u);
void disp(vector<int> ve);

int main(){
    int id, h, u, n;
    while(cin >>n){
        if(n == 0) break;
        bool flg = false;
        vector<int> ve;
        for(int i = 0; i < n; i++){
            cin >>id >>h >>u;
            if(loop(h, u)){
                ve.push_back(id);
                flg = true;
            }
        }
        if(ve.size() == 0){
            cout <<"NA" <<endl;
        } else{
            disp(ve);
        }
    }
    return 0;
}

int loop(int h, int u){
    int sum = 0;
    for(int i = 0; i < u; i++){
        sum += h;
        if(sum >= 1000000){
            return 1;
        }
    }
    return 0;
}

void disp(vector<int> ve){
    for(int i = 0; i < ve.size(); i++){
        cout <<ve[i] <<endl;
    }
}

C++: // clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int n;
  while (cin >> n, n) {
    map<int, int> t;
    while (n--) {
      int i, p, q;
      cin >> i >> p >> q;
      t[i] += p * q;
    }
    bool f = true;
    for (auto &x : t) {
      if (x.se >= 1000000) {
        f = false;
        cout << x.fi << endl;
        x.se = 0;
      }
    }
    if (f) cout << "NA" << endl;
  }
}

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

int main(){
	int n;

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

		long long int buf[3];
		for(int i=0;i<n;i++){
			cin >> buf[0] >> buf[1] >> buf[2];
			long long int a = buf[1] * buf[2];
			if(a >= 1000000){
				user[usercount] = buf[0];
				usercount++;
			}
		}

		for(int i=0;i<usercount;i++){
			cout << user[i] << endl;
		}
		if(usercount == 0){
			cout << "NA" << endl;
		}
	}
}

C++: #include <iostream>
#include <map>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;

void solve()
{
	int N;
	while(cin >> N, N)
	{
		set<int> Set;
		vector<int> ID(N);
		map<int, unsigned long long int> Map;
		bool Flag = false;
		unsigned long long int b, c;
		for(int i = 0; i < N; ++i)
		{
			cin >> ID[i] >> b >> c;
			Map[ID[i]] += b * c;
		}
		for(int i = 0; i < N; ++i)
		{
			if(Map[ID[i]] >= 1000000)
			{
				if(!Set.count(ID[i]))
				{
					cout << ID[i] << endl;
					Set.insert(ID[i]);
					Flag = true;
				}
			}
		}
		if(!Flag)
		{
			cout << "NA" << endl;
		}
	}
}

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