Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	stdin := bufio.NewScanner(os.Stdin)

	for stdin.Scan() {
		n, _ := strconv.Atoi(stdin.Text())
		if n == 0 {
			break
		}
		sales := make(map[string]int)
		existed := make(map[string]bool)
		order := make([]string, 4000)
		flg := false
		for i := 0; i < n; i++ {
			stdin.Scan()
			l := strings.Split(stdin.Text(), " ")
			e := l[0]
			p, _ := strconv.Atoi(l[1])
			q, _ := strconv.Atoi(l[2])
			sales[e] += p * q
			if !existed[e] {
				order = append(order, e)
				existed[e] = true
			}
		}
		for _, v := range order {
			if sales[v] >= 1000000 {
				fmt.Println(v)
				flg = true
			}
		}
		if flg == false {
			fmt.Println("NA")
		}
	}
}

C++: #define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>

using namespace std;

typedef long long ll;
typedef pair<double,double> P;

int main(){
	
	int num;
	vector<int> order;
	while(~scanf("%d",&num)){
		if(num==0) break;
		bool isok=false;
		map<int,int> val;		
		for(int i=0;i<num;i++){
			int n,p,q;
			scanf("%d %d %d",&n,&p,&q);
			val[n] += p*q;
			if(find(order.begin(),order.end(),n) == order.end()){
				order.push_back(n);
			}
		}

		for(vector<int>::iterator it = order.begin(); it != order.end(); it++){
			if(val[*it] >= 1000000){
				cout << *it << endl;
				isok=true;
			}
		}
		if(!isok) cout <<  "NA" << endl;
	}
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
int main() {
	std::vector<int> v;
	while (1) {
		int count=0;
		int n;
		std::cin >> n;
		if (n == 0) {
			break;
		}
		std::vector<std::vector<int>> a(n, std::vector<int>(3));
		
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < 3; ++j) {
				std::cin >> a[i][j];
			}
		}
		std::vector<int>num(n);
		for (int i = 0; i < n; ++i) {
			for (int j = 1; j < n; ++j) {
				if (a[i][0] == a[j][0]) {
					num[i] += a[i][1] * a[i][2] + a[j][1] * a[j][2];
					++count;
					break;
				}
			}
		}
		for (int i = 0; i < n; ++i) {
			if (count == 0) {
				v.push_back(0);
			}
			if (num[i] >= 1000000) {
				if (count >= 2) {
					sort(num.begin(), num.end());
				}
				v.push_back(num[i]);
			}
		}
	}
	for (int i = 0; i < v.size(); ++i) {
		if (v[i] == 0) {
			std::cout << "NA" << std::endl;
		}
		else {
			std::cout << v[i] << std::endl;
		}
	}
	return 0;
}

C++: ggggggggggggggggg

C++: #include <stdio.h>

int main(void)
{

	int n, a, b, No,data[4000];

	while(scanf("%d", &n), n != 0){
		bool check = false;
		for(int i = 0; i < 4000; i++)
			data[i] = 0;
		for(int i = 0; i < n; i++){
			scanf("%d %d %d", &No, &a, &b);
			data[No-1] += a*b;
			if(data[No-1] >= 1000000){
				printf("%d\n", No);
				data[No-1] = -1000000000;
				check = true;
			}
		}
		if(!check)
			printf("NA\n");

	}


	return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
int main() {
	int n;
	std::cin >> n;
	int x = 0;
	std::vector<int> A,B;
	while (n != 0) {
		int z = 0;
		++x;
		std::vector<int> m(n);
		std::vector<std::vector<int>> V(n, std::vector<int>(3));
		for (int i = 0;i < n;++i) {
			for (int j = 0;j < 3;++j) {
				std::cin >> V[i][j];
			}
		}
		for (int i = 0;i < n;++i) {
			m[i] = V[i][1] * V[i][2];
		}
		sort(V.begin(), V.end());
		for (int i = 0;i < n;i++) {
			for (int j = 0;j < n;++j) {
				if (i < j) {
					if (V[i][0] == V[j][0]) {
						m[i] += m[j];
						m[j] = 0;
					}
				}
			}
		}
		for (int i = 0;i < n;++i) {
			if (m[i] >= 1000000) {
				A.push_back(V[i][0]);
				z = 1;
			}
		}
		if (z == 0) {
			A.push_back(0);
		}
		std::cin >> n;
	}
	for (int i = 0;A.size()>i;++i) {
		if (A[i] == 0) 
			std::cout << "NA" << std::endl;
		else 
			std::cout << A[i] << std::endl;
	}
	return 0;
}

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[5000];
    int id_list[5000];
    bool id_flag;
    bool na_flag;
    
    while(cin>>n,n!=0){
        memset(data_list,0,sizeof(data_list));
        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;
            }
        }
        if(na_flag){
            cout<<"NA"<<endl;
        }
    }
    
    return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <math.h>
#include <map>
#include <queue>
#include <string>
using namespace std;

typedef long long ll;

int n,a,b,N;
ll s[4000][2];
string d;

int main(){
    while(cin>>N){
	if(N==0)return 0;
	for(int i=0;i<4000;i++){
	    for(int j=0;j<2;j++){
		s[i][j]=0;
	    }
	}
	int m=0;
	for(int i=0;i<N;i++){
	    cin>>n>>a>>b;
	    int flag=0;
	    for(int j=0;j<m;j++)if(s[j][0]==n){s[j][1]+=a*b;flag=1;}
	    if(flag==0){s[m][0]=n;s[m][1]=a*b;m++;}
	}
	int flag2=0;
	for(int i=0;i<m;i++)if(s[i][1]>999999){cout<<s[i][0]<<endl;flag2=1;}
	if(flag2==0)cout<<"NA"<<endl;
    }
}

C++: #include<iostream>
#include<vector>
using namespace std;
int main(){
	vector<int>  number;
	long long d,num,item,ko;
	while(cin>>d){
		if(d==0) break;
		for(int i=0;i<d;i++){
			cin>>num>>item>>ko;
			item *= ko;
			if(item>=1000000){
				number.push_back(num);
			}
		}
		if(number.size()==0) cout<<"NA"<<endl;
		else{
				for(int j=0;j<number.size();j++){
				cout<<number[j]<<endl;
			}
			number.clear();
		}
	}
}

C++: #include <iostream>
#include <string>
#include <map>
using namespace std;
int main(void){
	int n;
	while(cin >> n,n){
		map<int,int> name;
		long long int list[4001]={0};
		int a,b,c,j=0;
		for(int i=0;i<n ;i++){
			cin >> a >> b >> c;
			name[j]=a,j++;
			list[a]+=b*c;
		}
		bool check=true;
		for(int i=0;i<4000;i++)
			if(list[name[i]]>=1000000)
				cout << (name[i]) << endl,check=false,list[name[i]]=0;
		if(check)
			cout << "NA" << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

int main(){
  int n;
  while(cin >> n, n){
    int id, cnt=0;
    ll a, num, sum[5000];
    fill(sum, sum+5000, 0);
    vector<int> in;
    for(int i = 0; i < n ; i++){
      cin >> id >> a >> num;
      sum[id] += a*num;
      if(find(in.begin(), in.end(),id)==in.end()){
	in.push_back(id);
      }
    }

    for(int i = 0; i < in.size(); i++){
      if(sum[in[i]] >= 1000000){
	cout << sum[in[i]] << endl;
	cnt++;
	cout << in[i] << endl;
      }
    }
    if(!cnt) cout << "NA" << endl;
  }
  return 0;
}

C++: #include<cstdio>
#include<map>
#include<vector>
int main() {
	std::map<int, int> mp;
	std::vector<int> v;
	int n, i, e, p, q;
	while (true) {
		mp.clear();
		v.clear();
		scanf("%d", &n);
		if (n == 0)break;
		for (i = 0; i < n; i++) {
			scanf("%d%d%d", &e, &p, &q);
			if (mp.count(e) == 0) mp.emplace(e, p*q);
			else mp[e] += p*q;
		}
		for (std::map<int, int>::iterator itr = mp.begin(); itr != mp.end(); ++itr) {
			if (itr->second >= 1000000)v.push_back(itr->first);
		}
		if (v.size() == 0)printf("NA\n");
		else {
			for (std::vector<int>::iterator itr = v.begin(); itr != v.end(); ++itr) {
				printf("%d\n", *itr);
			}
		}
	}
	return 0;
}