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>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <math.h>
#include <map>
#include <queue>
#include <string>
using namespace std;

typedef long long ll;

int n,a,b,N;
ll s[4000][2];
string d;

int main(){
    while(cin>>N){
	if(N==0)return 0;
	for(int i=0;i<4000;i++){
	    for(int j=0;j<2;j++){
		s[i][j]=0;
	    }
	}
	int m=0;
	for(int i=0;i<N;i++){
	    cin>>n>>a>>b;
	    int flag=0;
	    for(int j=0;j<m;j++)if(s[j][0]==n){s[j][1]+=(ll)a*(ll)b;flag=1;}
	    if(flag==0){s[m][0]=n;s[m][1]=a*b;m++;}
	}
	int flag2=0;
	for(int i=0;i<m;i++)if(s[i][1]>999999){cout<<s[i][0]<<endl;flag2=1;}
	if(flag2==0)cout<<"NA"<<endl;
    }
}

C++: #include<stdio.h>
#include<list>
class hoge{
 public:
  int num;
  long long int v;
  hoge(int n,int va){
    num=n;
    v=va;
  }
};


int main(){
  using namespace std;
  int i,n,v,c,num,flg;
  long long int a;
  list<hoge> ls;
  list<hoge>::iterator pos;
  do{
    scanf("%d",&n);
    if(!n) break;
    for(i=0;i<n;i++){
      scanf("%d %d %d",&num,&v,&c);
      pos=ls.begin();
      while(pos!=ls.end()){
	if((*pos).num==num){
	  a=v;
	  a*=c;
	  (*pos).v+=a;
	  break;
	}
	pos++;
      }
      if(pos==ls.end()){
	ls.push_back(*(new hoge(num,a)));       
      }
    }
    pos=ls.begin();
    flg=1;
    while(pos!=ls.end()){
      if((*pos).v>=1000000){
	printf("%d\n",(*pos).num);
	flg=0;
      }
      pos++;
    }
    if(flg) printf("NA\n");
    ls.clear();
  }while(1);
  return 0;
}

C++: // a.c.cpp : ??????????????? ??¢????????±????????§????????¨????????? ?????????????????????????????????
//

#include <stdio.h>
int main(void){
	int n;
	int ban, tan, suu;
	long long int bango[4001];
	int flg,i;
	while (1){
		for (i = 1; i <= 4000; i++){
			bango[i] = 0;
		}
		scanf_s("%d", &n);
		if (n == 0){
			break;
		}
		for (i = 0; i < n; i++){
			scanf_s("%d %d %d", &ban, &tan, &suu);
			bango[ban] += tan*suu;
		}
		flg = 0;
		for (i = 1; i <= 4000; i++){
			if (bango[i]>=1000000){
				printf("%d\n", i);
				flg = 1;
			}
		}
		if (!flg){
			printf("NA\n");
		}
	}
	return 0;
}

C++: #include <cstdio>
#include <cstring>
 
using namespace std;
 
int main(void){
    int n, id, value, num, buf[4000], bufnum, i, j;
    long long int yen[4000];
    bool f;
    while(1){
        scanf("%d",&n);
        if(n == 0){
            break;
        }
        memset(yen,0ll,sizeof(yen));
        bufnum = 0;
        for(i = 0;i < n;i++){
            scanf("%d%d%d",&id,&value,&num);
            for(j = 0;j < bufnum;j++){
                if(buf[j] == id){
                    break;
                }
            }
            if(j == bufnum){
                buf[bufnum++] = id;
            }
            yen[id - 1] += (long long int)value * num;
        }
        f = true;
        for(i = 0;i < bufnum;i++){
            if(yen[buf[i] - 1] >= 1000000ll){
                printf("%d\n",buf[i]);
                f = false;
            }
        }
        if(f){
            printf("NA\n");
        }
    }
    return 0;
}

C++: #include<stdio.h>
int main(void)
{
	int n=0;
	int i=0;
	int tanka[4001]={0};
	int hito[4001]={0};
	int flg=0;
	int uriage[4001]={0};
	int bangou[4001]={0};
	int ccc=0;
	while(true)
	{
		flg=0;
		ccc=0;
		scanf("%d",&n);
		if (n==0)
		{
			break;
		}
		for (i=1;i<=n;i++)
		{
			ccc++;
			scanf("%d %d %d",&bangou[ccc],&tanka[ccc],&uriage[ccc]);
		}
		for (i=1;i<=ccc;i++)
		{
			if (tanka[i]*uriage[i]>=1000000)
			{
				printf("%d\n",bangou[i]);
				flg=1;
			}
		}
		if (flg==0)
		{
			printf("NA\n");
		}
	}
return 0;
}

C++: #include "bits/stdc++.h"

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

using namespace std;

using LL = long long int;
using LD = long double;

using pii = pair<int, int>;
using pll = pair<LL, LL>;
using pdd = pair<double, double>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<LL>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vb>;

const int INF = (1 << 30) - 1;
const LL INF64 = ((LL)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

const int dy[] = { 0, 1, 0, -1 };
const int dx[] = { 1, 0, -1, 0 };

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
LL gcd(LL x, LL y) { return y ? gcd(y, x % y) : x; }

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

	int n;
	while (cin >> n) {
		if (n == 0) break;

		map<int, LL> mp;
		queue<int> que;
		vb d(4001);
		for (int i = 0; i < n; i++) {
			int e;
			LL p, q;
			cin >> e >> p >> q;

			if (!d[e]) {
				que.push(e);
				d[e] = true;
			}

			mp[e] += p * q;
		}

		queue<int> ans;
		while (!que.empty()) {
			if (mp[que.front()] >= 1000000) {
				ans.push(que.front());
			}
			que.pop();
		}

		if (ans.empty()) {
			cout << "NA" << endl;
		} else {
			while (!ans.empty()) {
				cout << ans.front() << endl; ans.pop();
			}
		}
	}
	return 0;
}

C++: #include "stdio.h"
#include "string.h"
long long N[4001];
int f[4001];
int main(){
    int x,n,p,i,j,c=0;
    scanf("%d",&i);
    while(i!=0){
        c=0;
        for(j=0;j<i;j++){
            scanf("%d%d%d",&x,&n,&p);
            if(N[x]!=-1){
                N[x]+=n*p;
                if(N[x]>=1000000){
                    f[c]=x;
                    c++;
                    N[x]=-1;
                }
            }
        }
        if(c==0)
            printf("NA\n");
        else 
            for(j=0;j<c;j++)printf("%d\n",f[j]);
        memset(N,0L,4001);
        memset(f,0,4001);
        scanf("%d",&i);
    }
    return 0;
}

C++: #include<iostream>
#include<map>
using namespace std;
int main(){
  int n;
  while(cin >>n,n){
    int a,b,c;
    map<int, int> sale;
    bool f = true;
    for(int i=0; i<n; i++){
      cin >>a>>b>>c;
      if(sale[a]+b*c > 1000000){sale[a] = 1000000;}
      else{sale[a]+=b*c;}
    }
    for(map<int,int>::iterator pos = sale.begin(); pos!=sale.end(); pos++){
      if(pos->second >= 1000000){cout <<pos->first<<endl;f = false;}
    }
    if(f){cout <<"NA"<<endl;}
  }
  return 0;
}

C++: #include <stdio.h> 

int main()
{
    int n;

    scanf("%d", &n);
    while (n != 0)  
    {   
        int i;
        bool flag = false;

        for (i=0; i<n; i++) 
        {   
            int id, price, num;
            scanf("%d %d %d", &id, &price, &num);
            //printf("%d %d %d\n", id, price, num);
    
            int quota = int(1000000 / price + 0.9999999);
            if (num >= quota)
            {   
                printf("%d\n", id);
                flag = true;
            }   
        }   
        if (flag == false) printf("%s\n", "NA");
    
        scanf("%d", &n);
    }   

    return 0;
}