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 <cstdio>
#include <cmath>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <sstream>
#include <vector>
#include <string>
#include <iomanip>
#include <bitset>
using namespace std;
#define INF	100000000
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define lb lower_bound
#define ub upper_bound
#define SS stringstream
#define rep(i,n) for(int i = 0; i < n; i++)
#define sz(x) ((int)(x).size())
#define SORT(x) sort((x).begin(), (x).end())
#define RSORT(x) sort((x).begin(), (x).end(), greater<int>() )
#define clr(a,b) memset((a),(b),sizeof(a))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<P> Vp;
typedef priority_queue<P, vector<P>, greater<P> > PQ;

int n;

int main(){
	while(scanf("%d", &n)){
		if(n == 0) break;
		map<int,ll> m;
		map<int,ll>::iterator it;
		rep(i,n){
			int x,p,q; scanf("%d%d%d", &x, &p, &q);
			if(m.find(x) == m.end()) m[x] = (ll)p*q;
			else m[x] += (ll)p*q;
		}
		bool ok = true;
		for(it = m.begin(); it != m.end(); it++){
			if(it->second >= 1000000){
				ok = false;
				cout << it->first << endl;
			}
		}
		if(ok) cout << "NA" << endl;
	}
}

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

int main() {
  long long int n,ID,price,quantity,sales[4001] = {0},check,k,kaburi,rep[4001];
  while(cin >> n) {
    long long int sales[4001] = {0};
    if(n == 0) break;
    check = 0;k=0;
    for(int i=0;i<n;i++) {
      cin >> ID >> price >> quantity;
      //      cout << ID << " " << price << " " << quantity << endl;
      sales[ID] += price * quantity;
      kaburi = 0;
      for(int j=0;j<k;j++) {
        if(rep[j] == ID) {
          kaburi = 1;
        }
      }
      if((sales[ID] >= 1000000) && (kaburi == 0)){
        cout << ID << endl;
        check = 1;
        rep[k] = ID;
        k++;
      }
    }
    if(check == 0)
      cout << "NA" << endl;
  }
}

C++: #include<algorithm>
#include<iostream>
#include<cstdio>

using namespace std;

int main(void){
	int n;
	while(scanf("%d", &n),n){
		long long per[5000]={0};
		int num,t,s;
		int flg = 1;
		
		for(int i = 0; i < n; i++){
			scanf("%d%d%d", &num, &t, &s);
			per[num] += (long long)t * (long long)s;
		}
		for(int i = 0; i < 5000; i++){
			if(per[i] >= (long long)1000000){
				flg=0;
				printf("%d\n", i);
			}
		}
		if(flg)
			puts("NA");
	}
	return 0;
}

C++: #include<iostream>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<functional>
using namespace std;

int main(){
	int N;
	
	while(cin>>N,N){
		map<int,long long int> mp;
		vector <int> vi;
		queue<int >q;
		for(int i=0;i<N;i++){
			long long int num,tanka,suuryo;
			cin>>num>>tanka>>suuryo;
			if(mp[num]==0){
				vi.push_back(num);
			}
			mp[num]+=tanka*suuryo;
		}
		vector<int>::iterator it=vi.begin();
		for(;it!=vi.end();it++){
			if(mp[*it]>1000000){
				q.push(*it);
			}
		}
		if(q.empty()){
			cout<<"NA"<<endl;
		}
		else{
			int len=q.size();
			for(int i=0;i<len;i++){
				cout<<q.front()<<endl;
				q.pop();
			}
		}
	}
	return 0;
}

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

int main() {
	
	int n;
	
	while(cin >> n, n) {
		bool f = false;
		vector<int> IDs;
		unordered_map<int, long long> result;
		
		for(int i = 0; i < n; ++i) {
			int ID;
			long long price, number;
			cin >> ID >> price >> number;
			
			IDs.push_back(ID);
			result[ID] += price * number;
		}
		
		unordered_set<int> used;
		
		for(int ID : IDs) {
			if(used.count(ID)) continue;
			
			if(result[ID] >= 1000000) {
				cout << ID << endl;
				f = true;
			}
			used.insert(ID);
		}
		
		if(!f) {
			cout << "NA" << endl;
		}
		
	}
	
	return 0;
}

C++: #include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <complex>
#include <math.h>
//1000
#include <ctype.h>
using namespace std;long a,z,x,y,b[4001];bool s,p[4001];
int main(){
	while(cin>>a){
		if(a==0){break;}
	for(int aa=1;aa<=4000;aa++){
	b[aa]=0;p[aa]=false;}
	s=false;
	for(int i=0;i<a;i++){cin>>x>>y>>z;
	b[x]+=y*z;if(b[x]>=1000000&&p[x]==false){cout<<x<<endl;s=true;p[x]=true;}}
	if(s==false){cout<<"NA"<<endl;}}
return 0;}

C++: 
#include <iostream>
#include <math.h>

using namespace std;

int order[4000];

bool search(int);

class Member {
public:
	Member() {sum = 0; order = -1;}
	
	void add(long price, long num) {
		sum += price*num;
	}
	
	bool milion()
	{
		if (sum >= 1000000) return true;
		else return false;
	}
	
private:
	long long int sum;
	int id, order;
};


bool search(int num)
{
	for (int i=0; i<4000; i++) 
		if (order[i] == num ) return true;
	
	return false;
	
}

int main()
{
	int n, idx, memNum = 0;
	long price, num;
	bool nothing;

	
	ios::sync_with_stdio();
	
	while (1) {
		Member *member = new Member[4000];
		nothing =true;
		
		for (int i=0; i<4000; i++) order[i] = -1;
		
		if (cin >> n, !n) break;
		for (int i=0; i<n; i++) {
			scanf("%d %ld %ld", &idx, &price, &num);
			member[idx].add(price, num);
			if (!search(idx)) order[memNum++] = idx;
		}
		
		for (int i=0; i<4000 && order[i] > 0; i++) 
			if (member[order[i]].milion()) { cout << order[i] << endl; nothing = false; }
		if (nothing) cout << "NA" << endl;
	}
}

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

using namespace std;

int n;
long long id[4000];
unsigned long long value[4000];
unsigned long long number[4000];
map<unsigned long long, unsigned long long> total;

int main() {
  while(true){
    cin >> n;
    if(n==0){
        return 0;
    }
    for (int i = 0; i < n; i++) {
        cin >> id[i] >> value[i] >> number[i];
        if(total.find(id[i])==total.end()){
          total.insert(make_pair(id[i], 0));
        }
        total[id[i]] += value[i] * number[i];
    }
    vector<long long> v;
    if(!total.empty()) {
        map<unsigned long long, unsigned long long>::iterator it = total.begin();
        while (it != total.end()) {
            if ((*it).second >= 1000000) {
                v.push_back((*it).first);
            }
            ++it;
        }
    }
    if (v.empty()) {
        cout << "NA" << endl;
    }
    for (vector<long long>::iterator it = v.begin(); it != v.end(); ++it) {
        cout << *it << endl;
    }
    v.clear();
    total.clear();
  }
}