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 <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
	int n;
	while (scanf("%d",&n)&&n!=0) {
		vector<int> sales(4000, 0);
		vector<int> log;
		long long int prc, mnt;
		int num;
		for (int i=0; i<n; i++) {
			scanf("%d%d%d",&num,&prc,&mnt);
			if (log.empty()||find(log.begin(),log.end(),num)==log.end()) {
				log.push_back(num-1);
			}
			sales[num-1] += prc * mnt;
		}
		bool flag = true;
		for (int i=0; i<log.size(); i++) {
			printf("%d ", sales[log[i]]);
			if (sales[log[i]]>=1000000) {
				flag = false;
				printf("%d\n", log[i]+1);
			}
		}
		if (flag) printf("NA\n");
	}
}

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

int A[1000000];

int main()
{
    long long N,B,C;
    while(cin >> N,N){
        long long cnt[4001]={};
        bool NAflag=true,used[4001]={};
        for(int i=0;i<N;i++){
            cin>>A[i]>>B>>C;
            cnt[A[i]] += B*C;

        }
        for(int i=0;i<N;i++){
            if(cnt[A[i]]>=1000000 && used[A[i]]==false){
                printf("%d\n",A[i]);
                used[A[i]]=true;
                NAflag=false;
            }
        }
        if(NAflag==true){
            cout<<"NA"<<endl;
        }
    }
    return 0;
}

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

using namespace std;
const int target = 1000000;
vector<int> heros;

int main()
{
	int data;
	while (1)
	{
		scanf_s("%d", &data);
		if (data == 0)break;
		bool hero = false;
		for (int i = 0; i < data; i++)
		{
			int num, sell, cnt;
			scanf_s("%d %d %d", &num, &sell, &cnt);
			if (sell*cnt >= target)
			{
				bool already = false;
				for (int j = 0; j < heros.size(); j++)
				{
					if (heros[j] == num)
						already = true;
				}
				if (already == false)
				{
					printf("%d\n", num);
					heros.push_back(num);
					hero = true;
				}
			}
		}
		if (hero==false)
			printf("NA\n");
	}
	return 0;
}

C++: #include <cstdio>
#include <iostream>
#include <vector>
#include <utility>
typedef long long ll;
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); ++i)
int main() {
	int n;
	while(scanf("%d\n", &n), n){
		vector<pair<int, ll> > v;
		rep(i,n) {
			int x, y, z;
			cin >> x >> y >> z;
			bool f = false;
			for(int j = 0; j < v.size(); ++j) {
				if(v[j].first == x) {
					v[j].second += (ll) y * z;
					f = true;
					break;
				}
			}
			if(!f) {
				v.push_back(make_pair(x, (ll)(y * z)));
			}
		}
		bool flag = false;
		for(int j = 0; j < v.size(); ++j) {
			if(v[j].second >= 1000000) {
				flag = true;
				cout << v[j].first << endl;
			}
		}
		if(!flag) cout << "NA" << endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define LOOP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define MP make_pair
#define FIR first
#define SEC second
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=1000000009;

signed main(){
  int n;
  while(cin>>n,n){
    map<int,int> M;
    REP(i,n){
      int e,p,q;
      cin>>e>>p>>q;
      M[e]+=p*q;
    }
    bool f=false;
    for(auto itr=M.begin();itr!=M.end();itr++){
      if((itr->second)>=1000000){
        cout<<(itr->first)<<endl;
        f=true;
      }
    }
    if(!f)cout<<"NA"<<endl;
  }
  return 0;
}

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

int main(){
	int N;
	
	while(cin>>N,N){
		long long int lli[4001]={0,} ;
		vector <int> vi;
		queue<int >q;
		for(int i=0;i<N;i++){
			int num,tanka,suuryo;
			cin>>num>>tanka>>suuryo;
			if(lli[num]==0){
				vi.push_back(num);
			}
			lli[num]+=tanka*suuryo;
		}
		vector<int>::iterator it=vi.begin();
		for(;it!=vi.end();it++){
			if(lli[*it]>=1000000){
				q.push(*it);
			}
		}
		if(q.empty()){
			cout<<"NA"<<endl;
		}
		else{
			int len=q.size();
			for(int i=0;i<len;i++){
				cout<<q.front()<<endl;
				q.pop();
			}
		}
	}
	return 0;
}

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

int main(){
    int n, a, b, c, d = 0, com[4001] = {};
    cin >> n;
    if(n != 0){
    for(int i = 0;i < n;i++){
       cin >> a >> b >> c;
       com[a] += b * c;
      }
    for(int j = 1;j < 4001;j++){
       if(com[j] < 1000000) continue;
       cout << com[j] << endl;
       d++;
      }    
    if(d == 0) cout << "NA" << endl;
     }
    return 0;
   }

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

using namespace std;

int main() {
  for (;;) {
    int n;
    cin >> n;
    if (!n) return 0;
    pair<int, pair<int, long long> > es[4001];
    for (int i = 1; i <= 4000; i++) {
      es[i].first = 5000;
      es[i].second.first = i;
      es[i].second.second = 0;
    }
    for (int i = 0; i < n; i++) {
      int id;
      long long v, c;
      cin >> id >> v >> c;
      es[id].first = min(es[id].first, i);
      es[id].second.second += v * c;
    }
    sort(es+1, es+4001);
    bool f = false;
    for (int i = 1; i <= 4000; i++)
      if (es[i].second.second >= 1000000) {
        f = true;
        cout << es[i].second.first << endl;
      }
    if (!f)
      cout << "NA" << endl;
  }
}

C++: #include<cstdio>
#include<algorithm>
#include<iostream>
#include<functional>
using namespace std;
long long int p[114514],x,y,z;
int main(void)
{
	int i,j,k,f,n,cnt;
	while(1) {
		cin>>n;
		f=0,cnt=0;
		if(!n)break;
		for(i=0;i<4001;i++) p[i]=0;
		for(i=0;i<n;i++) {
			cin>>x>>y>>z;
			p[x]+=(y*z);
		}
	
		for(i=0;i<4001;i++) {
			if(p[i]>=1000000) {
				cout<<i<<endl;
				f=1;
			}
		}
		if(f==0) cout<<"NA"<<endl;
	}
	return 0;
}

C++: #include <stdio.h>

int main(void) {

  int n;

  int id;
  unsigned long long unit,amount;
  int answer[4000];

  int i,j,flag;
  int a,aflag;


  while(1) {

    scanf("%d",&n);

    if(n==0) break;

    flag=0;
    a=0;

    for(i=0;i<n;i++) {

      scanf("%d %llu %llu",&id,&unit,&amount);
      //printf("%ld",unit*amount);
      if(unit*amount>=1000000) {

	aflag=0;

	for(j=0;j<a;j++) {

	  if(id==answer[j]) aflag=1;

	}
 
	if(aflag==0) answer[a++]=id;

	flag=1;

      }

    }

    if(flag==0) printf("NA\n");

    else {

      for(i=0;i<a;i++) printf("%ld\n",answer[i]);

    }

  }

  return 0;

}