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 <vector>

using namespace std;

typedef long long ll;

int main(){

	int n;
	while(cin>>n&&n!=0){
//		vector<pair<int,int> > v;
		ll info[4001];
		bool appeared[4001];
		fill(info,info+4001,0);
		fill(appeared,appeared+4001,false);
		vector<int> numList;
		for(int i = 0; i < n; i++){
			int num;
			int val;
			int ko;
			cin>>num>>val>>ko;
			if(!appeared[num]){
				appeared[num]=true;
				numList.push_back(num);
			}

			info[num]+=val*ko;
		}

		bool f=false;
		for(int i = 0; i < numList.size(); i++){
			if(info[numList[i]]>=1000000){
				cout<<numList[i]<<endl;
				f=true;
			}
		}
		if(!f)
			cout<<"NA"<<endl;
	}

	return 0;
}

C++: //Name: Sale Reult
//Level: 1
//Category: やるだけ
//Note:

#include <iostream>
#include <map>
#include <vector>

using namespace std;

bool solve() {
    int N;
    if(!(cin >> N)) return false;
    if(!N) return false;

    map<int,int> res;
    vector<int> ord;
    for(int i = 0; i < N; ++i) {
        int id, v, c;
        cin >> id >> v >> c;
        res[id] += v*c;
        ord.push_back(id);
    }

    bool exist = false;
    for(int id : ord) {
        if(res[id] >= 1000000) {
            cout << id << endl;
            res[id] = 0;
            exist = true;
        }
    }
    if(!exist) cout << "NA" << endl;
    return true;
}

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

    while(solve()) ;
    return 0;
}

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

struct data{
	int id;
	int value;
	int num;
};

int main(){
	int n;
	int need;
	while(cin >> n){
		if(n == 0) break;
		int count = 0;
		for(int i = 0; i < n; i++){
			data d;
			cin >> d.id >>
				d.value >> d.num;
			need = 1000000 % d.value == 0 ? 1000000 / d.value : 1000000 / d.value + 1;
			if(d.num >= need){
				cout << d.id << endl;
				count++;
			}
		}
		if(!count) cout << "NA" << endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int data[2][10000],n,i,f,id,a,b;
  while(1){
    cin>>n;
    if(n==0) break;
    for(i=0; i<10000; i++) data[0][i]=0,data[1][i]=0;
    for(i=0;i<n;i++){
      cin>>id>>a>>b;
      for(f=0;f<i+1;f++){
	if(data[0][f]==id){
	  data[1][f]+=a*b,f=-1;
	  break;
	}else if(data[0][f]==0){
	  data[0][f]=id;
	  data[1][f]=a*b;
	}
      }
    }
    for(i=0,f=0;i<n;i++)
      if(data[1][i]>999999)cout<<data[0][i]<<"\n",f=1;
    if(f==0)cout<<"NA"<<"\n";
  }
}

C++: #include<iostream>
#include<map>
#include<algorithm>
using namespace std;
main(){
 while(1){
  int n,a,b,c;
  cin>>n;
  if(n==0) break;
  map<long,int> m;
  for(;n>0;n--){
   cin>>a>>b>>c;
   m.insert(map<long,int>((long)b*c,a));
  }
  m.sort();
  cout<<(m.begin()).first<<endl;
 }
 cout<<"NA"<<endl;
}

C++: //AOJ 0100
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cctype>
using namespace std;
#define MAX_N 100
 
unsigned long long int a[4001] = {0}, b, i, j, k, ans, n;
char str[1000];
 
int sort(const void *a, const void *b){
  return *(int*)a - *(int*)b;
}
 
int main(){
  while(scanf("%lld", &n) != 0){
    if(n == 0) return 0;
    ans = 0;
    for(i = 0; i < 4001; i++)
      a[i] = 0;
    for(i = 0; i < n; i++){
      scanf("%lld %lld %lld", &b, &k, &j);
      if(a[b] >= 1000000) continue;
      a[b] += k * j;
      if(a[b] >= 1000000){
    printf("%lld\n", b);
    ans++;
      }
    }
    if(ans == 0) printf("NA\n");
  }
  return 0;
}

C++: #include<stdio.h>

int main(){
int N;
int n,m,p;
long P[4001][3]={};
long PT[4001][4]={};

while(1){
scanf("%d",&N);if(N==0)break;

for(int i=1;i<=N;i++){
scanf("%d %d %d",&n,&m,&p);
P[n][0]+=m*p;if(P[n][1]==0)P[n][1]=i;
}
int c=0;
for(int i=0;i<4000;i++)
if(1000000<=P[i][0]){PT[c][0]=P[i][0];PT[c][1]=P[i][1];PT[c][2]=i;c++;}

for(int i=0;i<c;i++)
for(int j=c-1;j>i;j--)
if(PT[j][1]<PT[j-1][1])
{int TT=PT[j][1];PT[j][1]=PT[j-1][1];PT[j-1][1]=TT;
 int TTT=PT[j][2];PT[j][2]=PT[j-1][2];PT[j-1][2]=TTT;}

for(int i=0;i<c;i++)
printf("%ld\n",PT[i][2]);
if(c==0)printf("NA\n");
for(int i=0;i<4000;i++)
{P[i][0]=0;P[i][1]=0;P[i][2]=0;
 PT[i][0]=0;PT[i][1]=0;PT[i][2]=0;PT[i][3]=0;}

}
return  0;
}

C++: #include <iostream>
#include <string.h>

using namespace std;

int N, M;

int main() {
	int goal = 1000000;

	for (; cin >> N;) {
		if (!N) break;
		int v[4000];
		memset(v, 0, sizeof(v));
		for (int i = 0; i < N; i++) {
			long long  e, p, q;
			cin >> e >> p >> q;
			v[e - 1] += p*q;
		}
		bool flag = false;
		for (int i = 0; i < 4000; i++) {
			if (v[i] >= goal) {
				flag = true;
				cout << i + 1 << endl;

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

	return 0;
}

C++: 
#include<iostream>
#include<string>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<algorithm>
#include<complex>
using namespace std ;
typedef vector<int> vi ;
typedef vector<vi> vvi ;
typedef vector<string> vs ;
typedef pair<int, int> pii; 
typedef long long ll ;

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
#define all(a) (a).begin(),(a).end()


int main(void){
	int n;	
	while(cin>>n,n){
		vector<vector<ll> > num(n,vector<ll>(3,0));
		rep(i,n){
			//cout<<num[i][0]<<" "<<num[i][1]<<endl;
			cin>>num[i][0];
			int item,code;
			rep(j,i){
				if(num[i][0]==num[j][0]){
					num[j][1]+=item*code;
					num[i][2]=1;
				}
			}
			cin>>item>>code;
			if(!num[i][2])num[i][1]+=item*code;
		}
		//cout<<"star"<<endl;
		int cnt=0;
		rep(i,n){
			if(num[i][1]>=1000000){cout<<num[i][0]<<endl;cnt++;}
		}
		if(!cnt)cout<<"NA"<<endl;
		//cout<<"NO"<<n<<endl<<endl;;
	}
}

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

struct data {
	int ID;
	long total;
	int order;

	data() {
		ID = -1;
		total = 0;
		order = 100000;
	}

	data(int n) {
		ID = n;
		total = 0;
		order = 100000;
	}

	bool operator<(const data d) const {
		return order < d.order;
	}
};

int main() {
	int n;

	while(cin >> n, n) {
		int ID, price, sale;
		data table[4096];
		bool flag = false;
		int order_count = 0;

		getchar();
		for(int i = 0; i < sizeof(table) / sizeof(table[0]); i++) {
			table[i] = data(i);
		}

		for(int i = 0; i < n; i++) {
			char in[128];
			char ID_s[32], price_s[32], sale_s[32];
			int j, k;

			// input
			// /*
			fgets(in, 120, stdin);
			for(j = 0,k = 0; in[j + k] != ' ' && in[j + k] != ';'; k++)
				ID_s[k] = in[j + k];
			ID_s[k] = '\0';
			j = k + 1;
			for(k = 0; in[j + k] != ' ' && in[j + k] != ';'; k++)
				price_s[k] = in[j + k];
			price_s[k] = '\0';
			j += k + 1;
			for(k = 0; in[j + k] != ' ' && in[j + k] != ';' && in[j + k] && in[j + k] != '\n'; k++)
				sale_s[k] = in[j + k];
			sale_s[k] = '\0';

			ID = atoi(ID_s);
			price = atoi(price_s);
			sale = atoi(sale_s);
			// */

			// cin >> ID >> price >> sale;
			if(table[ID].order == 100000) {
				table[ID].order = order_count;
				order_count++;
			}

			table[ID].total += price * sale;
		}

		sort(table, table + 4096);

		for(int i = 0; i < order_count; i++) {
			if(table[i].total >= 1000000) {
				cout << table[i].ID << endl;
				flag = true;
			}
		}

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

	return 0;
}