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 <vector>
#include <algorithm>
using namespace std;

int main(){
	
	int n , id , price , num, cnt;
	while(cin >> n , n!=0){
		vector<long long int> p(4001,0);
		vector<int> a;
		while(n--){
			cin>>id>>price>>num;
			if(find(a.begin(),a.end(),id)==a.end()) a.push_back(id);
			p[id]+=price*num;
			}
		cnt=0;	
		for(int i=0;i<a.size();i++){
			if(p[a[i]]>=1000000){
				cout << a[i] << endl; 
				cnt++;
			} 
		}
		if (cnt==0) cout << "NA" << endl;
	}
		return 0;
}

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

int main(){
	int n, s, m, No;
	int person[4001];
	bool flag;
	
	while( cin >> n, n){
		flag = true;		
		for(int i=0 ; i<4001 ; i++){
			person[i] = 0;
		}
		
		for(int i=0 ; i<n ; i++){
			cin >> No >> s >> m;
			person[No] += s*m; 
		}
		for(int i=0 ; i<4001 ; i++){
			if(person[i] >= 1000000){
				flag = false;
				cout << i << endl;
			}
		}
		
		if(flag){
			cout << "NA" << endl;
		}
	}
	
	return 0;
}

C++: #include <iostream>


using namespace std;
class MAN{
public:
	unsigned int uriage;
	short number;
};

int main(int argc, char const* argv[])
{
	MAN *person;
	int n;
	bool flag;

	while( cin >> n && n != 0 ){
		person  = new MAN[n];
		for( int i = 0;i < n;i++ ){
			int target;
			int a,b;
			cin >> target >> a >> b;

			int j;
			for( j = 0;j < i;j++ ){
				if( person[j].number == target ){
					person[j].uriage += a*b;
					break;
				}
			}
			if( j == i ){
				person[i].number = target;
				person[i].uriage = a * b;
			}
		}
		flag = false;
		for( int i = 0;i < n;i++ ){
			if( person[i].uriage >= 1000000 ){
				cout << person[i].number << endl;
				flag = true;
			}
		}
		if( flag == false ) cout << "NA" << endl;
		delete[] person;
	}

	return 0;
}

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

int main()
{
	array<long long, 4000> ar;
	vector<long long> ans;
	long long n;
	int e,p,q;
	
	while (true) {
		cin >> n;
		ar.fill(0);
		if (!n) {
			break;
		}

		bool isNA = true;
		for (int i = 0; i < n; ++i) {
			cin >> e >> p >> q;
			ar[e] += p*q;
		}
		for (int i = 0; i < 4000;++i) {
			if (ar[i] >= 1000000) {
				auto it = ans.begin();
				it = std::find(it, ans.end(), i);
				if (it == ans.end()) {
					ans.push_back(i);
				}
				isNA = false;
			}
		}
		if (isNA) {
			ans.push_back(-1);
		}

	}

	for (auto it : ans) {
		if (it != -1) {
			cout << it << endl;
		}
		else {
			cout << "NA" << endl;
		}
	}

	return 0;
}

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

int main()
{
	int n,id,sale,k,cnt,flg;
	while (1)
	{
		int outid[4001] = { 0 }, total[4001] = {0};
		cin >> n;
		if (n == 0)break;
		cnt = 0;
		flg = 0;
		for (int i = 0; i < n; i++)
		{
			cin >> id >> sale >> k;
			outid[i] = id;
			total[i] = sale*k;
		}

		for (int i = 0; i < n-1; i++)
		{
			for (int j = i+1; j < n; j++)
			{
				if (outid[i]==outid[j])
				{
					total[i] += total[j];
					cnt++;
				}
			}
		}

		for (int i = 0; i < n-cnt; i++)
		{
			if (total[i] >= 1000000)
			{
				cout << outid[i] << endl;
				flg = 1;
			}
		}

		if (flg==0)
		{
			cout << "NA" << endl;
		}
		
	}
	return 0;
}

C++: #include<cstdio>
#include<map>
#include<vector>
std::vector<std::pair<int, long long>> pq;
int main() {
	int n, i, e;
	long long p, q;
	bool match;
	while (true) {
		scanf("%d", &n);
		if (n == 0)break;
		for (i = 0; i < n; i++) {
			scanf("%d%lld%lld", &e, &p, &q);
			match = false;
			for (auto itr = pq.begin(); itr != pq.end(); itr++) {
				if (itr->first == e) {
					itr->second += p*q;
					match = true;
					break;
				}
			}
			if (!match)pq.push_back(std::make_pair(e, p*q));
		}
		match = false;
		for (auto itr = pq.begin(); itr != pq.end(); itr++) {
			if (itr->second >= 1000000) {
				printf("%d\n", itr->first);
				match = true;
			}
		}
		if (!match)printf("NA\n");
		pq.clear();
	}
	return 0;
}

C++: #include<stdio.h>
#include<list>
class hoge{
 public:
  int num;
  int v;
  bool ov;
  hoge(int n,int v,int c){    
    num=n;
    ov=false;
    set(v,c);
  }
  void set(int va,int c);
  bool isOV(){ return ov; };
};
void hoge::set(int va,int c){
  unsigned long long int i=va;
  i*=c;
  if(ov)
    return ;
  if(i>=(1000000-v)){
    ov=true;
    return ;
  }
  v+=i;
}

int main(){
  using namespace std;
  int i,n,v,c,num,flg;
  long long int a;
  list<hoge> ls;
  list<hoge>::iterator pos;
  do{
    scanf("%d",&n);
    if(!n) break;
    for(i=0;i<n;i++){
      scanf("%d %d %d",&num,&v,&c);
      pos=ls.begin();
      while(pos!=ls.end()){
	if((*pos).num==num){
	  (*pos).set(v,c);
	  break;
	}
	pos++;
      }
      if(pos==ls.end()){
	ls.push_back(*(new hoge(num,v,c)));       
      }
    }
    pos=ls.begin();
    flg=1;
    while(pos!=ls.end()){
      if((*pos).isOV()){
	printf("%d\n",(*pos).num);
	flg=0;
      }
      pos++;
    }
    if(flg) printf("NA\n");
    ls.clear();
  }while(1);
  return 0;
}

C++: 
#include <stdio.h>
#include <iostream>
#include <map>
#include <set>
using namespace std;

typedef long long int ll;

ll solve(ll N);

int main(void) {

	ll N = 1;
	while(true) {
		cin >> N;
		if( N == 0 ) { break; }
		solve(N);
	}

	return 0;
}

ll solve( ll N ) {

	map<int, ll> m;
	set<int> s;

	for( int i = 0; i < N; i++ ) {
		int id;
		ll ps, q;
		cin >> id >> ps >> q;
		if( m.find(id) == m.end() ) {
			m[id] = ps*q;
		} else {
			m[id] += ps*q;
		}
		if( m[id] >= 1000000 ) 
			s.insert(id);
			
	}

	if( s.size() == 0 ) {
		cout << "NA" << endl;
	} else {
		for( auto it = s.begin(); it != s.end(); ++it ) {
			cout << (*it) << endl;
		}
	}
	return 0;
}

C++: #include <cmath>
#include <ctime>
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <numeric>
#include <utility>
#include <iomanip>
#include <cstdio>
#include <cctype>
#include <queue>
#include <complex>
#include <climits>

typedef long long ll;

using namespace std;

int main(void){
	int N;
	int id,p,q;
	while(cin >> N){
		queue<int> que;
		map<int, int> map;
		int check = 0;
		if(!N) break;
		for(int i=0; i<N; ++i){
			cin >> id >> p >> q;
			if(map.find(id) == map.end()){
				map[id] = p*q;
				que.push(id);
			} else {
				map[id] += p*q;
			}
		}
		while(que.size()){
			if(map[que.front()] >= 1000000){
				cout << que.front() << endl;
				check = 1;
			}
			que.pop();
		}
		if(check == 0) cout << "NA" << endl;
	}

	return 0;
}

C++: #include <iostream>
using namespace std;
struct {long long int sum; bool flg;} p[4000];
int main()
{
	int a, b, c, n, i;
	while (cin >> n && n)
	{
		int m = 0;
		for (i = 0; i < 4000; i++)
			p[i].sum = 0, p[i].flg = false;
		for (i = 0; i < n; i++)
		{
			cin >> a >> b >> c;
			p[a-1].sum += b*c;
		}
		for (i = 0; i < 4000; i++)
		{
			if (p[i].sum >= 1000000)
			{
				p[i].flg = true;
				m++;
			}
		}
		if (m <= 0)
			cout << "NA" << endl;
		else
			for (i = 0; i < 4000; i++)
				if (p[i].flg)
					cout << i+1 << endl;
	}
}