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<stdio.h>
#include<string>
#include<stdlib.h>
#include<math.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<string.h>

using namespace std;

typedef pair<int,long long> pii;

#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<=k;i++)


int main(){
	int n,cnt,b,t,c,s,f;
	for(;;){
		scanf("%d",&n);
		if(n==0)break;
		cnt=0;
		vector<pii> v;
		rep(i,n){
			scanf("%d%d%d",&b,&t,&c);
			s=v.size();
			f=1;
			rep(i,s)if(v[i].first==b){
				v[i].second += t*c;
				f=0;
			}
			if(f)v.push_back(pii(b,t*c));
		}
		s=v.size();
		rep(i,s)if(v[i].second >= 1000000){
			printf("%d\n",v[i].first);
			cnt++;
		}
		if(cnt==0)puts("NA");
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;


int n;
int index, a, b;
unsigned long long sum[5000];

int main(){
	while (cin >> n&&n){
		vector<ll> vi;
		fill(sum, sum + 5000, 0);
		REP(i, n){
			cin >> index >> a >> b;
			if (find(ALL(vi), index) == vi.end()){
				vi.push_back(index);
			}
			if (sum[index] >= 1000000)continue;
			sum[index] += a*b;
		}
		bool f = 1;
		REP(i, vi.size()){
			cout << sum[vi[i]] << endl;
			if (sum[vi[i]] >= 1000000){
				cout << vi[i] << endl;
				f = 0;
			}
		}
		if (f)cout << "NA" << endl;
	}
}

C++: #include<iostream>

using namespace std;

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

C++: #include <iostream>
#include <map>
#include <vector>
 
using namespace std;
 
int main() {
    ios::sync_with_stdio(false);
 
    int n, id; long long p, q;
    while (cin >> n && n) {
        map<int, int> ids;
        vector<pair<int, long long>> sum;
        for (int i=0; i<n; ++i) {
            cin >> id >> p >> q;
            if (ids.count(id)) {
                sum[ids[id]].second += p * q;
            } else {
                sum.push_back(make_pair(id, p * q));
                ids[id] = sum.size() - 1;
            }
        }
        bool na = true;
        for (auto x : sum) {
            if (1000000 <= x.second) {
                cout << x.first << endl;
                na = false;
            }
        }
        if (na) {
            cout << "NA" << endl;
        }
    }
 
    return 0;
}

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

int main() {
	int max,n;
	vector<int> id;
	vector<int> sum;
	vector<int> table;
	
	id.resize(4000);
	sum.resize(4000);
	table.resize(4000);
	
	while(cin>>n,n){
		int i,f;
		long long int a,b;
		max = 0;
		
		for(int j=0;j<4000;++j){
			id[j] = 0;
			sum[j] = 0;
			table[j] = 0;
		}
		
		for(;n;--n){
			cin>>i>>a>>b;
			
			if(table[i-1]==0){
				id[max]=i;
				table[i-1] = max+1;
				++max;
			}
			if(a*b>=1000000)sum[table[i-1]-1] = 1000000;
			else if(sum[table[i-1]-1]<1000000)sum[table[i-1]-1] += a*b;
			
		}
		f=0;
		for(int j=0;j<max;++j){
			if(sum[j]>=1000000){
				cout<<id[j]<<endl;
				f=1;
			}
		}
		if(!f)cout<<"NA"<<endl;
	}
	return 0;
}

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

using namespace std;

typedef long long int lli;

lli employees[4001];
bool checked[4001];

signed main()
{
	lli n;
	while (cin >> n, n) {
		for (lli i = 1; i <= 4000; ++i) employees[i] = checked[i] = false;

		vector<lli> ans;

		for (lli i = 0; i < n; ++i) {
			lli num, a, b; cin >> num >> a >> b;

			if (checked[num]) continue;

			employees[num] += a * b;

			if (employees[num] >= 1000000) {
				ans.push_back(num);
				checked[num] = true;
			}
		}

		if (ans.size()) {
			for (lli i = 0; i < ans.size(); ++i) {
				cout << ans[i] << endl;
			}
		} else {
			cout << "NA" << endl;
		}
	}
}

C++: #include <stdio.h>

int output[50000];
int count=0;

void input(int);
int main(void){
	int n,i;
	while(true){
		scanf("%d",&n);
		if(n>0){
			input(n);
		}else{
			break;
		}
	}
	for(i=0;i<count;i++){
		if(output[i]!=0){
			printf("%d\n",output[i]);
		}else{
			printf("NA\n");
		}
	}
	
	return 0;
}
void input(int ns){
	int e[4000];
	int p[1000000];
	int q[100000];
	int c[ns];
	
	int i;
	
	for(i=0;i<ns;i++){
		scanf("%d",&e[i]);
		scanf("%d",&p[i]);
		scanf("%d",&q[i]);
		c[i] = p[i]*q[i];
	}
	
	int j;
	
	for(i=0;i<ns-1;i++){
		for(j=1;j<ns;j++){
			if(e[i]==e[j]){
				c[i]=c[i]+c[j];
				c[j]=0;
			}
		}
	}
	int ch = 0;
	
	for(i=0;i<ns-1;i++){
		if(c[i]>=1000000){
			output[count]=e[i];
			count++;
			ch = 1;
		}
	}
	if(ch == 0){
		output[count]=0;
		count++;
	}
}

C++: #include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

typedef long long LL;

int main() {
	int n;
	while (cin >> n && n) {
		vector<LL> v;
		map<LL, LL> m;
		LL no, price, amount;
		int na = 1;
		for (int i = 0; i < n; i++) {
			cin >> no >> price >> amount;
			if (m.find(no) != m.end())
				m[no] += price * amount;
			else {
				m[no] = price * amount;
				v.push_back(no);
			}
		}
		vector<LL>::iterator it = v.begin();
		while (it != v.end()) {
			if (m[*it] >= 1000000) {
				cout << *it << endl;
				na = 0;
			}
			it++;
		}
		if (na)
			cout << "NA" << endl;
	}
	return 0;
}

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

int main(){
	int a,hoge;
	bool flag;
	while(1){
		cin >> a;
		if(a == 0) break;
		int number[a];
		int tanka[a];
		int ryo[a];
		int gokei[a];
		flag = false;
		for(int i=0;i<a;i++){
			cin >> number[i] >> tanka[i] >> ryo[i];
			gokei[i] = tanka[i] * ryo[i];
			if(gokei[i] >= 1000000){
				cout << number[i] << endl;
				flag = true;
			}
		}
		if(flag == false) cout << "NA" << endl;
	}
	return 0;
}