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

using namespace std;

int main(void){
    int i,l,k;
    int n;
    long long id,c,q;
    long long data_list[4001]={0};
    int id_list[4000];
    bool id_flag;
    bool na_flag;
    
    while(cin>>n,n!=0){
        k=0;
        for(l=0;l<n;l++){
            data_list[id]+=(c*q);
            cin>>id>>c>>q;
            id_flag=true;
            for(i=0;i<=k+1;i++){
                if(id_list[i]==id){
                    id_flag=false;
                }
            }
            if(id_flag){
                id_list[k]=id;
                k++;
            }
        }
        na_flag=true;
        for(l=0;l<k;l++){
            if(data_list[id_list[l]]>=1000000){
                cout<<id_list[l]<<endl;
                na_flag=false;
                data_list[l]=0;
            }
        }
        if(na_flag){
            cout<<"NA"<<endl;
        }
    }
    
    return 0;
}

C++: #include <iostream>

using namespace std;

int main()
{
    while(1)
    {
        int i=0;
        int na=0;
        cin>>i;
        if(i==0)
            break;
        else
        {
            for(int k=0;k<i;k++)
            {
                int j=0;int l=0;int m=0;
                cin>>j>>l>>m;
                if(l*m>=1000000)
                {
                    cout<<j<<endl;
                    na=1;
                }
            }
            if(na==0)
            {
                cout<<"NA"<<endl;
            }

        }
    }

    return 0;
}

C++: #include<stdio.h>
#include<string.h>
#include<math.h>
int main(void)
{
	long long int g[1001],s[1001],d[1001],f[1001];
	int j,i,k,a,h[1001];
	while(1){
		scanf("%d",&a);
		if(a==0) break;
		for(i=0;i<a;i++){
			h[i]=0;
			g[i]=0;
		}
		for(i=0;i<a;i++){
			scanf("%lld %lld %lld",&s[i],&d[i],&f[i]);
			if(d[i]*f[i]>=1000000) h[i]=1;
			if(d[i]==1000000&&f[i]>=1) h[i]=1;
			if(f[i]==100000&&d[i]>=10) h[i]=1;
			if(h[i]==0) g[i]=d[i]*f[i];
			else g[i]=0;
		}
		for(i=0;i<a;i++){
			for(j=i+1;j<a;j++){
				if(g[i]>=1000000&&h[i]==0){
					h[i]=1;
				}
				if(s[i]==s[j]){
					if(h[i]==0){
						g[i]+=g[j];
						g[j]=0;
					}
					else g[j]=0;
				}
				if(g[i]>=1000000&&h[i]==0){
					h[i]=1;
				}
			}
		}
		k=0;
		for(i=0;i<a;i++){
			if(h[i]==1){
				printf("%lld\n",s[i]);
				k=1;
			}
		}
		if(k==0) printf("NA\n");
	}
	return 0;
}

C++: #include <iostream>
#include <map>
using namespace std;
int main() {
  int n, e;
  long long int p, q;
  map<int, long long int> mp;
  map<int, long long int>::iterator itr;

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

	for(int i = 0; i < n; ++i) {
	  cin >> e >> p >> q;
	  if(mp.find(e) != mp.end()) {// found
		mp[e] += p * q;
	  }
	  else {// not found
		mp[e] = p * q;
	  }
	}

	bool isNA = true;
	for(itr = mp.begin(); itr != mp.end(); ++itr) {
	  if(itr->second >= 1000000) {
		cout << itr->first << endl;
		isNA = false;
	  }
	}
	if(isNA) {
	  cout << "NA" << endl;
	}

	mp.clear();
  }
  return 0;
}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

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

ll cost[4010];
signed main(void)
{
  while(true) {
    int n;
    cin >> n;
    if(!n) break;
    REP(i, 4010) cost[i] = 0;
    VI v;
    REP(i, n) {
      ll e, p, q;
      cin >> e >> p >> q;
      if(cost[e] < 1000000 && cost[e]+p*q>=1000000) {
        v.PB(e);
        cost[e] = 1000000;
      } else if(cost[e] < 1000000) {
        cost[e] += p*q;
      }
    }
    if(v.size() == 0) cout << "NA" << endl;
    REP(i, v.size()) cout << v[i] << endl;
  }

  return 0;
}

C++: #include <stdio.h>

struct {
  int i; 
  long v;
} d[50][4000];

int main() {
  int i, j, k;
  int p, n, f;
  int id, v1, v2;

  for (i = 0; scanf("%d", &n), n != 0; i++) {
    p = 0;
    for (j = 0; j < n; j++)
      d[i][j].v = 0;
    for (j = 0; j < n; j++) {
      f = 0;
      scanf("%d %d %d", &id, &v1, &v2);      
      for (k = 0; k < j; k++) {
        if (id == d[i][k].i) {
          d[i][k].v += v1 * v2;
          f = 1;
          break;
        }
      }
      if (f == 0) {
        d[i][p].i = id;
        d[i][p].v = v1 * v2;
        p++;
      }
    }
  }

  n = i;
  for (i = 0; i < n; i++) {
    f = 0;
    for (j = 0; j < 50; j++) {
      if (d[i][j].v >= 1000000) {
        f = 1;
        printf("%d\n", d[i][j].i);
      }
    }
    if (f == 0)
      printf("NA\n");
  }
  return 0;
}

C++: #include <bits/stdc++.h>
#define INT(name) int name; scanf("%d",&name);
#define VINT(name,n) vector<int> name(n); for(int i = 0;i < n;i++) scanf("%d",&name[i]);

using namespace std;

int main(int argc, char const *argv[]){
	vector<unsigned long long> data(4000);
	int i;
	long long a,b,c;
	bool check;

	cin >> i;
	while(i){

		for(int j = 0;j < 4000;j++){
			data[j] = 0;
		}


		for(int j = 0;j < i;j++){
			cin >> a >> b >> c;
			data[a - 1] += (long long)b * c;
		}


		check = false;

		for(int j = 0;j < 4000;j++){
			if(data[j] >= 1000000){
				printf("%d\n",j+1);
				check = true;
			}
		}

		if(!check) printf("NA\n");

		cin >> i;
	}

	return 0;
}

C++: #include <bits/stdc++.h>
#define HIGH 1000000
#define MEMBER_NUM 4001
#define INF -1
using namespace std;
typedef long long ll;
int main(void) {
    int n;
    while(cin >> n, n != 0) {
        ll data[MEMBER_NUM];
        memset(data, INF, sizeof(data));
        for(int r = 0; r < n; r++) {
            int no;
            ll tanka, quantity;
            cin >> no >> tanka >> quantity;
            if(data[no] != INF) {
                data[no] += tanka*quantity;
            } else {
                data[no] = tanka*quantity;
            }
        }
        bool update = false;
        for(int r = 0; r < MEMBER_NUM; r++) {
            if(data[r] >= HIGH) {
                cout << r << endl;
                update = true;
            }
        }
        if(!update) cout << "NA" << endl;
    }
    return(0);
}

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