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<stdio.h>
#include<iostream>
using namespace std;

int main(){

	int N,Q;
	while(1){
	cin>>N;if(N==0)break;
	long long int n[4001][2]={};
	for(int i=0;i<N;i++){
		int x,y,z;
		cin>>x>>y>>z;
		if(n[x][0]+y*z<=1000000)n[x][0]+=y*z;
		else if(n[x][0]+y*z>1000000)n[x][0]=1000000;
		if(n[x][1]==0)n[x][1]=i;
	
	}
	for(int i=0;i<4001;i++){
		for(int j=i;j>i;j--){
			if(n[j][1]<n[j-1][1]){
				int t=n[j][0];n[j-1][0];n[j-1][0]=t;
				int T=n[j][1];n[j-1][1];n[j-1][1]=T;
			}
		}
	}
	bool f=false;
	for(int i=0;i<4001;i++){
		if(n[i][0]>=1000000){cout<<i<<endl;f=true;}
	}
	if(f==false)cout<<"NA"<<endl;

	}
	return 0;
}

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

int main() {
    int i[4000], p, q, sum[4000];
    for (; ; ) {
        int n, count;
        cin>>n;
        if (n) {
            count = 0;
            for (int j = 0; j < n; j++) {
                cin>>i[j]>>p>>q;
                sum[j] = p * q;
                if (j == 0 && sum[j] >= 1000000) {
                    cout<<i[j]<<endl;
                    count++;
                }
                for (int k = 0 ; k < j; k++) {
                    if (i[k] == i[j]) {
                        if (sum[k] >= 1000000) {
                            break;
                        } else {
                            sum[k] += sum[j];
                            if (sum[k] >= 1000000) {
                                cout<<i[j]<<endl;
                                count++;
                            }
                            break;
                        }
                    }
                }
            }
            if (count == 0) {
                cout<<"NA"<<endl;
            }
        } else
            break;
    }
    return 0;
}

C++: #include <iostream>
#include <math.h>
using namespace std;
int main() {
	while (1) {
		/*for (int i = 0; i < n; i++) {
			e[i] = 0;
		}
		for (int i = 0; i < 4000; i++) {
			m[i] = 0;
			pr[i] = 0;
		}
		na = 1;*/
		int n = 0, p, q, na = 1, e[4000] = {}, pr[4000] = {};
		unsigned long long int m[4000] = {};

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

		for (int i = 0; i < n; i++) {
			cin >> e[i] >> p >> q;
			m[e[i] - 1] += p * q;
		}

		for (int i = n-1; i >= 0; i--) {
			if (m[e[i] - 1] >= 1000000 && pr[e[i] - 1] == 0) {
				cout << e[i] << endl;
				pr[e[i] - 1] = 1;
				na = 0;
			}
		}

		if (na)
			cout << "NA\n";

	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
long long n,a,b,c,f,i,s[4001];
while(cin>>n){
if(n==0)break;
for(i=1;i<=4000;i++)s[i]=0;
for(i=0;i<n;i++){
cin>>a>>b>>c;
s[a]+=b*c;
}
f=0;
for(i=1;i<=4000;i++)
if(s[i]>=1000000){cout<<i<<endl;f=1;}
if(f==0)cout<<"NA"<<endl;
}
return 0;
}

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

int main()
{
	int n,t2,t3;
	while(cin >> n && n)
	{
		int total[n][2];
		bool flag=false;
		for(int i=0;i<n;i++)
		{
			cin >> total[i][1] >> t2 >> t3;
			total[i][0] = t2*t3;
		}
		
		for(int i=0;i<n;i++)
		{
			if(total[i][0]>=1000000)
			{
				cout << total[i][1] << endl;
				flag=true;
			}
		}
		if(!flag)cout << "NA" << endl;
	}
}

C++: #include <bits/stdc++.h>
using namespace std ;

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<ll,ll> ;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,a,b,c;
  while(cin >> n && n){
    vector<pair<ll,ll>> v;
    vary(ll,v2,4001,0);
    vary(ll,t,4001,0);
    ll cnt=0;
    rep(i,n){
      cin >> a >> b >> c;
      if(v2[a] == 0){
        v.push_back(make_pair(cnt,a));
        ++cnt;
        v2[a] = 1;
      }
      t[a] += b * c;
    }
    bool f = false;
    REP(i,0,v.size()){
      if(t[v[i].se] >= 1000000){
        cout << v[i].se<<endl;
        f = true;
      }
    }
    if(!f) cout << "NA"<<endl;
  }
  return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  int n;
  while(1){
    cin>>n;
    if(n==0)break;
    vector<ll> v(4005,0);
    rep(i,n){
      ll e,p,q;
      cin>>e>>p>>q;
      v[e]+=p*q;
    }
    vi ans;
    rep(i,4005)
      if(v[i]>=1000000)ans.push_back(i);
    if(ans.size())
      rep(i,ans.size())cout<<ans[i]<<endl;
    else
      cout<<"NA"<<endl;
  }
}

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

int main(){
    int n,i;
    while(cin>>n,n){
        map<int,long long>m;
        long long p,q,s=0;
        while(n--){
            cin>>i>>p>>q;
            m[i]+=p*q;
        }
        for (map<int,long long>::iterator it=m.begin(); it!=m.end(); ++it){
            if(it->second>=1000000){
                s=1;
                cout<<it->first<<endl;
            }
        }
        if(!s)cout<<"NA"<<endl;
    }
}