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>
using namespace std;

int main(){
    int n;
    long int array[n][3];
    int count=0;

    cin>>n;

    if(n==0) goto Exit;
    for(int i=0;i<n;i++){
        cin>>array[i][0]>>array[i][1]>>array[i][2];
    }
    
    for(int i=0;i<n;i++){
        for(int j=1;i+j<n;j++){
            if(array[i][0]==array[i+j][0]){
                array[i][1]+=array[i+j][1];
                array[i][2]+=array[i+j][2];
                array[i+j][1]=0;
                array[i+j][2]=0;
            }
        }
    }

    for(int i=0;i<n;i++){
        if(array[i][1]*array[i][2]>=1000000){
            cout<<array[i][0]<<"\n";
            count++;
        }
    }

    Exit:
    ;

    if(count==0){
        cout<<"NA\n";
    }
}

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<string>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstring>
using namespace std;

int A[100000000];

int main(){
	int N,B,C;
	while(cin>>N,N){
		int cnt[4001]={};
		for(int i=0;i<N;i++){
			cin>>A[i]>>B>>C;
			cnt[A[i]] += B*C;
		}
		bool NAflag=true,used[4001]={};
		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) puts("NA");
	}
    return 0;
}

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

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;

int main() {
  int n;
  while(cin >> n, n) {
    int f=0;
    vector<ll> sum(4001);
    vector<int> ff(4001);
    REP(i,n) {
      ll a,b,c;
      cin >> a>>b>>c;
      sum[a] += b*c;
      if (ff[a]==0&&sum[a]>=1000000) {
        ff[a]++;
        if (f==0)
          f=1;
        cout << a << endl;
      }
    }
    if (f==0)
      cout << "NA" << endl;
  }
}

C++: #include <iostream>
#include <vector>
#include <map>
int main(){
  int n;

  while(std::cin>>n){
    if(!n)break;
    std::map<int,long long int> m;
    std::vector<int> v;
    //mlÛ¶vÛ¶
    for(;n;n--){
      int a,b,c;
      //aÔbP¿cÊ
      std::cin>>a>>b>>c;
      if(!m[a])v.push_back(a);
      m[a]+=b*c;
    }
    bool f = true;
    for(int i=0;i<v.size();i++){
      if(m[v[i]]>=1000000)f=false,std::cout<<v[i]<<std::endl;}
    if(f)std::cout<<"NA"<<std::endl;
  }
  return 0;
}

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

using namespace std;
#define ahaha push_back
#define hohoho make_pair 
int main(){
  int n,num,tanka,sell,flag=0,flag2=0;
  while(cin>>n,n!=0){
    vector<int> nu;
    vector<int> vi;
    vector<pair<int,int> > pii;
    for(int i=0;i<n;i++){
      cin>>num>>tanka>>sell;
      
      for(int j=0;j<vi.size();j++){
	if(num==vi[j]){
	  flag2=1;
	  break;
	}
      }
      if(flag2==0){
	for(int j=0;j<pii.size();j++){
	if(pii[j].first==num){
	  flag=1;
	  pii.ahaha(hohoho(num,((tanka*sell)+pii[i].second)));
	  if(((tanka*sell)+pii[i].second)>=1000000)
	    vi.ahaha(num);
	  break;
	}
      }
      if(flag==0){
	nu.ahaha(num);
	pii.ahaha(hohoho(num,tanka*sell));
	if(tanka*sell>=1000000)
	  vi.ahaha(num);
      }
    }
    }
    if(vi.empty())
      cout<<"NA"<<endl;
    else{
    for(int k=0;k<nu.size();k++){
      for(int l=0;l<vi.size();l++){
	if(nu[k]==vi[l])
	  cout<<nu[k]<<endl;
      }
    }
    }
  }
  return 0;
}

C++: #include <cstdio>
#include <map>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;

int n;

int main(){
	while(scanf("%d", &n),n){
		map<int,ll> m;
		map<int,ll>::iterator it;
		rep(i,n){
			int x; ll p, q;
			scanf("%d%lld%lld", &x, &p, &q);
			if(m.find(x) == m.end()) m[x] = p*q;
			else m[x] += p*q;
		}
		bool ok = true;
		for(it = m.begin(); it != m.end(); it++){
			if(it->second >= 1000000){
				ok = false;
				printf("%d\n", it->first);
			}
		}
		if(ok) printf("NA\n");
	}
}

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

#define MAX_N 4001

int main(void){
  int n;
  bool flag[MAX_N], f;
  unsigned long long man[MAX_N], price, figure;
  
  while(cin >> n, n){
    memset(flag, false, sizeof(flag));
    f = false;
    
    for(int i = 0 ; i < n ; i++){
      cin >> man[i] >> price >> figure;
      if(price * figure >= 1000000) flag[i] = true;
    }
    
    for(int i = 0 ; i < n ; i++){
      if(flag[i] == true){
	cout << man[i] << endl;
	f = true;
      }
    }
    if(f == false) cout << "NA" << endl;
  }
  return 0;
}

C++: #include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
const int target = 1000000;

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

C++: #include <vector>
#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() {}
    Mem(int _id, ll _c) { id = _id; _c = c; }
};

Mem array[40010];

int main(void) {
    while(cin >> n && n) {
        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;
                }
            }
        }
        bool hap = false;
        for(int i = 0; i < n; i++) {
            if(array[i].id && array[i].c >= MAX) {
                cout << array[i].id << endl;
                hap = true;
            }
        }
        if(!hap) {
            cout << "NA" << endl;
        }
    }
    return 0;
}

C++: #include<stdio.h>
#define u_int unsigned int

int main(void){
  u_int uri[4000];
  u_int i,n,flg;
  u_int id,tan,kazu;
  
  while(scanf("%u",&n)&&n!=0){
    for(i=0;i<4000;i++) uri[i]=0;
    for(i=0;i<n;i++){
      scanf("%u %u %u",&id,&tan,&kazu);
      uri[id-1]+=tan*kazu;
    }
    for(flg=0,i=0;i<4000;i++){
      if(uri[i]>=1000000){
        printf("%u\n",i+1);
        flg=1;
      }
    }
    if(flg==0) puts("NA");
  }
  return 0;
}