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++: #include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>

using namespace std;

inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}

typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EACH(t,i,c) for(t::iretator i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,n-1)

const double EPS = 1e-10;
const double PI = acos(-1.0);

int main() {
	int n;
	int ban, tan, suu;
	vector<ll> table(4001, 0);
	vi check(4001, 0);

	while(cin >> n, n) {
		bool flag = true;

		REP(i, 4001) {
			table[i] = 0;
		}

		REP(i, n) {
			cin >> ban >> tan >> suu;
			
			if(!check[ban]) {
				table[ban] += tan*suu;
			}
			if(table[ban] >= 1000000) {
				check[ban] = 1;
			}
		}

		REP(i, 4001) {
			if(check[i]) {
				cout << i << endl;
				check[i] = 0;
				flag = false;
			}
		}
		if(flag) {
			cout << "NA" << endl;
		}
	}

	return 0;
}

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

using namespace std;

int main(){
	int n;
	while(scanf("%d",&n) && n){
		int a,b,c;
		map<int,long> list;
		vector<int> people;
		for(int i=0;i<n;i++){
			scanf("%d %d %d",&a,&b,&c);
			people.push_back(a);
			list[a] += b * c;
		}
		vector<int>::iterator it;
		bool flag = true;
		for(it = people.begin();it != people.end();it++){
			
			if(list[*it] >= 1000000){
				printf("%d\n",*it);
				flag = false;
			}
			
			list[*it] = 0;
		}
		if(flag){
			printf("NA\n");
		}
	}
}

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

long long int sale[4001];

int main(){
	int p;
	while(cin >> p, p){
		for(int i=0; i < 4001; i++) sale[i] = 0;
		int id, price, num, result=0;

		for(int i=0; i < p; i++){
			cin >> id >> price >> num;
			sale[id] += price * num;
		}
		for(int i=0; i < 4001; i++){
			if(1000000 <= sale[i]){
				cout << i << endl;
				result++;
			}
		}
		if(result == 0) cout << "NA" << endl;
	}
}

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

int main(){
    while(1){
        long long sale[4001], a, b, c, i, j, n;
        int k = 0;
        cin >> n;
        if(n == 0)break;
        for(i = 0; i < 4001; i++){
            sale[i] = 0;
        }
        for(i = 0; i < n; i++){
            cin >> a >> b >> c;
            if(sale[a] >= 0){
                sale[a] += b*c;
                if(sale[a] >= 1000000){
                    cout << a << endl;
                    sale[a] = -1;
                    k++;
                }
            }
        }
        if(k == 0){
            cout << "NA" << endl;
        }
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
using namespace std;
typedef long long ll;
int main() {
    int n;
    while (cin >> n && n) {
        unordered_map<int, int> pos;
        vector<pair<int, ll>> res(4001);
        for (int i=1; i<=n; ++i) {
            int no;
            ll price, quantity;
            cin >> no >> price >> quantity;
            if ( ! pos[no]) {
                pos[no] = i;
                res[pos[no]].first = no;
            }
            res[pos[no]].second += price * quantity;
        }

        bool NA = true;
        for (int i=0; i<(int)res.size(); ++i) {
            if (res[i].second >= 1000000) {
                cout << res[i].first << endl;
                NA = false;
            }
        }
        if (NA)
            cout << "NA" << endl;
    }
    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;
		int cnt=0;
		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){
				cout<<*it<<endl;
				cnt++;
			}
		}
		if(cnt==0){
			cout<<"NA"<<endl;
		}
	}
	return 0;
}

C++: #include <stdio.h>
#include <map>
#include <set>

using namespace std;

int main(){
	while(1){
		int n;
		scanf("%d", &n);
		if(n==0){
			puts("NA");
			break;
		}

		map<int,int> m;
		map<int,int>::iterator it;
		set<int> v;
		int a,b,c;
		for(int i=0;i<n;i++){
			scanf("%d%d%d", &a,&b,&c);
			if((it=m.find(a)) != m.end()){
				m[a] += b*c;
			}else {
				m.insert(pair<int,int>(a,b*c));
			}

			if(m[a] >= 1000000 && v.find(a) == v.end()){
				printf("%d\n", a);
				v.insert(a);
			}
		}
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  int n,num,flag=0,flag2=0;
  long long tanka,sell;
  while(cin>>n,n!=0){
    flag=0;flag2=0;
    vector<int> nu;
    vector<int> vi;
    vector<pair<int,long long> > pii;
    for(int i=0;i<n;i++){
      cin>>num>>tanka>>sell;
      for(int j=0;j<vi.size();j++){
	if(num==vi[j]){
	  flag2=1;
	  break;
	}
      }
      if(flag2==0){
	flag=0;
	for(int j=0;j<pii.size();j++){
	  if(pii[j].first==num){
	    flag=1;
	    pii.push_back(make_pair(num,((tanka*sell)+pii[j].second)));
	    if(((tanka*sell)+pii[i].second)>=1000000)
	      vi.push_back(num);
	    break;
	  }
	}
	if(flag==0){
	  nu.push_back(num);
	  pii.push_back(make_pair(num,tanka*sell));
	  if(tanka*sell>=1000000)
	    vi.push_back(num);
	}
      }
    }
    if(vi.empty())
      cout<<"NA"<<endl;
    else{
      for(int k=0;k<nu.size();k++){
	for(int l=0;l<vi.size();l++){
	  if(nu[k]==vi[l])
	    cout<<nu[k]<<endl;
	}
      }
    }
  }
  return 0;
}

C++: #include<stdio.h>
#include<string.h>
#include<math.h>
int main(void)
{
	long long int g[1001];
	int j,i,k,a,s[1001],d[1001],f[1001],h[1001];
	while(1){
		scanf("%d",&a);
		if(a==0) break;
		for(i=0;i<a;i++){
			scanf("%d %d %d",&s[i],&d[i],&f[i]);
			g[i]=d[i]*f[i];
		}
		for(i=0;i<a;i++) h[i]=0;
		for(i=0;i<a;i++){
			for(j=i+1;j<a;j++){
				if(g[i]>=1000000&&h[i]==0){
					h[i]=1;
				}
				if(s[i]==s[j]){
					if(h[i]==0){
						g[i]+=g[j];
						g[j]=0;
						s[j]=0;
					}
					else{
						g[j]=0;
						s[j]=0;
					}
				}
				if(g[i]>=1000000&&h[i]==0){
					h[i]=1;
				}
			}
		}
		k=0;
		for(i=0;i<a;i++){
			if(h[i]==1){
				printf("%d\n",s[i]);
				k=1;
			}
		}
		if(k==0) printf("NA\n");
	}
	return 0;
}