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;

int main(){
    int n;
    while( cin >> n, n ){
        vector< long long int > ls(4001, 0);
        bool NA = true;
        for(int i = 0; i < n; i++){
            int a, b, c;
            cin >> a >> b >> c;
            if( ls[a] >= 0 ){
                ls[a] += b*c;
                if( ls[a] >= 1000000){
                    cout << a << endl;
                    NA = false;
                    ls[a] = -1;
                }
            }
        }
        if( NA ) cout << "NA" << endl;
    }
    return 0;
}

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

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

class meb{
public:
	int num;
	unsigned long long tanka;
	unsigned long long count;
	unsigned long long sum;
};

int main(){
	int n;
	while(1){
		int cc=0;
		cin>>n;
		meb st[n];
		if(n==0)break;
		for(int i=0;i<n;i++){
			cin>>st[i].num>>st[i].tanka>>st[i].count;
		}
		for(int k=0;k<n;k++){
			st[k].sum=st[k].tanka*st[k].count;
		}
		for(int j=0;j<n;j++){
			for(int l=j+1;l<n;l++){
				if(st[j].num==st[l].num){
					(st[j].sum)=(st[j].sum)+(st[l].sum);
					st[l].sum=0;
				}
			}
		}
		for(int a=0;a<n;a++){
			if(st[a].sum>=1000000)cout<<st[a].num<<endl;
			else cc++;
		}
		if(cc==n)cout<<"NA"<<endl;
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
int main( void )
{
	int n;
	while ( cin >> n && n )
	{
		int no;
		int price;
		int deal;

		bool f = true;
		for ( int i = 0; i < n; i++ )
		{
			cin >> no >> price >> deal;
			if ( price * deal >= 1000000 )
			{
				cout << no << endl;
				f = false;
			}
		}

		if ( f )
			cout << "NA" << endl;

	}

	return 0;
}

C++: #include <iostream>
using namespace std;
 
int main() {
	while(1){
int s[4000];int i;int w;int j;
w=0;
for(int y = 0;y<4000;y++){
	s[y]= 0;
}
cin>>i;
if(i==0){break;}
for(int y = 1;y<=i;y++){
	int a,b,c;
	cin>>a>>b>>c;
	int g = 1000000 - s[a-1];
	if(g%b==0){j = g/b;}
	else{j = (g/b)+1;}
	if(j<c){s[a-1]=1000001;}
	else{s[a-1]=s[a-1]+b*c;}
}
for(int y = 0;y<4000;y++){
	if(s[y]>=1000000){
		cout << y+1<<endl;
		w=1;
		}
}
if(w==0){cout << "NA" << endl;}
}
	return 0;
}

C++: # include <iostream>
# include <vector>
# include <cstring>

int n;
int a[3];
std::vector<std::pair<int, int>> vec;
bool x[4001];

int main() {
	while (1) {
		std::cin >> n;
		if (n == 0)
			break;
		int count = 0;
		vec.clear();
		std::memset(x, false, sizeof(x));

		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < 3; ++j)
				std::cin >> a[j];
			if (x[a[0]]) {
				for (int k = 0; k < vec.size(); ++k) {
					if (vec[k].first == a[0])
						vec[k].second += a[1] * a[2];
				}
			}
			else {
				vec.push_back(std::make_pair(a[0], a[1] * a[2]));
				x[a[0]] = true;
			}
		}
		for (auto it = vec.begin(); it != vec.end(); ++it) {
			if ((*it).second >= 1000000) {
				std::cout << (*it).first << std::endl;
				++count;
			}
		}
		if (count==0)
			std::cout << "NA" << std::endl;
	}
	return 0;
}

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

using ll = long long;
using ull = unsigned long long;

const double PI = acos(-1);
const int inf = 2e9;
const long long INF = 2e18;
const long long MOD = 1e9+7;

#define sx(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define REP(i,n) for (int i = 0; i < n; i++)
#define ALL(a) begin(a),end(a)

int main(void) {
    int n;
    while (cin >> n, n) {
        vector<ull> s(4010, 0);
        REP(i,n) {
            ll e,p,q;
            cin >> e >> p >> q;
            s[e-1] += p*q;
        }
        bool flag = false;
        REP(i,4000) {
            if (s[i] >= 1000000) {
                cout << i + 1 << endl;
                flag = true;
            }
        }
        if (!flag) cout << "NA" << endl;
    }
    return 0;
}

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

int main()
{
	int n;
	
	while (cin >> n, n){
		bool num[4001] = {false}, flag = false;
		int sum[4001] = {0}, m, ex, a;
		
		for (int i = 0; i < n; i++){
			cin >> m >> ex >> a;
			sum[m] += ex * a;
			if (1000000 <= sum[m]){
				num[m] = true;
				flag = true;
			}
		}
		
		if (flag){
			for (int i = 1; i <= 4000; i++){
				if (num[i]){
					cout << i << endl;
				}
			}
		}
		else {
			cout << "NA" << endl;
		}
	}
	
	return (0);
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#define N 4001
using namespace std;
int main(){

  int n,b;
  int a,num[N],tanka,uriage,jun[N];
  bool judge,nnnn;

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

    judge = true;
    for(int i=0;i<N;i++){
      num[i] = 0;
    }

    for(int i=0,b=0;i<n;i++){
      nnnn = true;
      cin >> a >> tanka >> uriage;
      num[a] += tanka * uriage;
      for(int j=0;j<i;j++){
	if(jun[j]==a){
	  nnnn = false;
	  break;
	}
      }
      if(nnnn){
	jun[b] = a;
	b++;
      }
      else
	jun[b] = 0;
    }

    for(a=0;jun[a]!=0;a++){
      if(num[jun[a]]>=1000000){
	cout << jun[a] << endl;
	judge = false;
      }
    }
    if(judge)
      cout << "NA" << endl;
  }
  return 0;
}

C++: #include<iostream>
#include<vector>
using namespace std;
int main()
{
	int n;
	int number[4000];
	int tanka[4000];
	int ryou[4000];
	long goukei[4000];
	while(cin>>n,n){
		for(int i=0;i<n;i++){
			cin>>number[i];
			cin>>tanka[i];
			cin>>ryou[i];
			goukei[i]=tanka[i]*ryou[i];
		}
		for(int i=0;i<n-1;i++){
			for(int j=i+1;j<n;j++){
				if(number[i]==number[j]){
					goukei[i]+=goukei[j];
					goukei[j]=0;
					}
			}
		}
		int flag=-1;
		for(int i=0;i<n;i++){
			if(goukei[i]>=1000000){
				flag=0;
				cout<<number[i]<<endl;
				}
		}
		if(flag==-1)
			cout<<"NA"<<endl;
	}
}

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

struct Saler
{
	int Number;
	int Saled;
};

int main(){
	struct Saler* sl;
	int n, a, b, c, i;
	bool isFound;
	
loop:
	scanf("%d", &n);		// データ個数
	if(n == 0) goto end_scope;
	sl = (struct Saler*)malloc(sizeof(struct Saler) * (n + 1));
	memset(sl, sizeof(struct Saler)*n, 0);
	for(int j = 0; j < n; j++)
	{
		scanf("%d %d %d", &a, &b, &c);
		for(i = 0; i < n; i++)
		{
			if((sl+i)->Number == 0)
			{
				sl[i].Number = a;
				sl[i].Saled = b * c;
				break;
			}
			if((sl+i)->Number == a)
			{
				sl[i].Saled += b * c;
				break;
			}
		}
	}
	isFound = false;
	for(int j = 0; j < n; j++)
	{
		if(sl[j].Saled >= 1000000)
		{
			cout << sl[i].Number << endl;
			isFound = true;
		}
	}
	!isFound && (cout << "NA" << endl);
	free(sl);
end_scope:
    return 0;
}