Go: package main

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

var sc = bufio.NewScanner(os.Stdin)

func readLineToInt() []int {
    sc.Scan()
    line := strings.Split(sc.Text(), " ")
    length := len(line)
    var intLine []int
    for i := 0; i < length; i++ {
        n, _ := strconv.Atoi(line[i])
        intLine = append(intLine, n)
    }
    return intLine
}

func readInt() int {
    sc.Scan()
    line := strings.Split(sc.Text(), " ")
    n, _ := strconv.Atoi(line[0])
    return n
}

func main() {
    wht := readLineToInt()
    _, h, _ := wht[0], wht[1], wht[2]
    p := readInt()
    var xSave []int
    var ySave []int
    for i := 0; i < p; i++ {
        xyt := readLineToInt()
        xSave = append(xSave, xyt[0])
        ySave = append(ySave, xyt[1])
    }
    var mp [][]int
    for i := 0; i < h; i++ {
        mp = append(mp, readLineToInt())
    }
    ans := 0
    for i := 0; i < p; i++ {
        x, y := xSave[i], ySave[i]
        if mp[y][x] == 1 {
            ans++
        }
    }
    fmt.Println(ans)
}

C++: #include <iostream>
#define rep(i,n) for(int i =0;i<n;i++)

using namespace std;


int main(){

  int array[51][51] ={0}; 
  bool check[51][51] = {false};
  int x[100],y[100],t[100];
  int p,W,H,T;
  int answer =0;

  cin >>W >> H >> T;
  cin >>p;
  rep(i,p)
    cin >> x[i] >> y[i] >> t[i];
  rep(i,H){
    rep(j,W){
      int n;
      cin >> n;
      if(n==1)
	{
	  check[i][j]= true;
	}
    }
  }
  rep(k,p)
    {
	//cout<<x[k]<<y[k]<<endl;
      //if(check[y[k]][x[k]] == true)
	//cout<<"out"<<endl;
	array[y[k]][x[k]]++;

    }
  rep(i,H){
    rep(j,W)
    {
      if(check[i][j])
	answer =answer + array[i][j];
	//cout<<answer;
	
    }
}
    
  cout << answer << endl;
  return 0;

}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <sstream>
#include <string>
#include <complex>
#include <cstdio>
using namespace std;

int v[50][50];
int main(){
	int h,w,t;
	int p;
	cin >> w >> h >> t >> p;
	
	for(int i = 0 ; i < p ; i++){
		int x,y,z;
		cin >> x >> y >> z;
		if( z <= p ) v[y][x]++;
	}
	int sum = 0;
	for(int i = 0 ; i < h ; i++){
		for(int j = 0 ; j < w ; j++){
			int s;
			cin >> s;
			sum += s * v[i][j];
		}
	}
	cout << sum << endl;

}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<utility>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef vector<int> vec;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define stop char nyaa;cin>>nyaa;

void solve() {
	int w, h, t; cin >> w >> h >> t;
	int p; cin >> p;
	vector<pair<int, P>> v;
	rep(i, p) {
		int x, y, T; cin >> x >> y >> T;
		v.push_back({ T,{x,y} });
	}
	sort(v.begin(), v.end());
	vector<vector<bool>> b(h);
	rep(i, h) {
		b[i].resize(w, false);
		rep(j, w) {
			char tt; cin >> tt;
			if (tt == '1')b[i][j] = true;
		}
	}
	vector<vector<int>> c(h);
	rep(i, h)c[i].resize(w, 0);
	rep(i, v.size()) {
		if (v[i].first > t)break;
		P p = v[i].second;
		int x = p.first, y = p.second;
		swap(x, y);
		if (b[x][y])c[x][y]++;
	}
	int ans = 0;
	rep(i, h) {
		rep(j, w) {
			ans += c[i][j];
		}
	}
	cout << ans << endl;
}
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	solve();
	//stop
		return 0;
}

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

#define REP(i, k, n) for(int i = k; i < n; i++)
#define rep(i, n) for(int i = 0; i < n; i++) 

using namespace std;

int main() {
	int W, H, T;
	cin >> W >> H >> T;

	int p;
	cin >> p;

	vector<int> x(p), y(p), t(p);
	rep(i, p) {
		cin >> x[i] >> y[i] >> t[i];
	}

	vector< vector<int> > s(H, vector<int>(W));
	rep(i, H) {
		rep(j, W) {
			cin >> s[i][j];
		}
	}

	vector< vector<int> > cnt(H, vector<int>(W));
	rep(i, p) {
		if(t[i] <= T) {
			if(s[y[i]][x[i]]) {
				cnt[y[i]][x[i]]++;
			}
		}
	}

	int ans = 0;
	rep(i, H) {
		rep(j, W) {
			ans += cnt[i][j];
		}
	}

	cout << ans << endl;

	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <sstream>
#include <string>
#include <complex>
#include <cstdio>
using namespace std;

int v[50][50];
int main(){
	int h,w,t;
	int p;
	cin >> w >> h >> t >> p;
	
	for(int i = 0 ; i < p ; i++){
		int x,y,z;
		cin >> x >> y >> z;
		if( z < p ) v[y][x]++;
	}
	int sum = 0;
	for(int i = 0 ; i < h ; i++){
		for(int j = 0 ; j < w ; j++){
			int s;
			cin >> s;
			sum += s * v[i][j];
		}
	}
	cout << sum << endl;

}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

int f[50][50];
int main()
{
    int W,H,T,p;
    cin >>W >>H >>T >>p;

    vector<int> x(p),y(p),t(p);
    rep(i,p) cin >>x[i] >>y[i] >>t[i];

    rep(i,H)rep(j,W)
    {
        cin >>f[i][j];
        --f[i][j];
    }

    rep(i,p)if(f[y[i]][x[i]]!=-1) ++f[y[i]][x[i]];

    int ans = 0;
    rep(i,H)rep(j,W)if(f[i][j]!=-1) ans += f[i][j];
    cout << ans << endl;
    return 0;
}

C++: #include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


int main(){

	int W,H,T;
	scanf("%d %d %d",&W,&H,&T);

	int table[H][W];
	for(int row = 0; row < H; row++){
		for(int col = 0; col < W; col++){
			table[row][col] = 0;
		}
	}

	int P;
	scanf("%d",&P);

	int x,y,t;

	for(int loop = 0; loop < P; loop++){
		scanf("%d %d %d",&x,&y,&t);
		table[y][x]++;
	}

	int ans = 0;
	int tmp;

	for(int row = 0; row < H; row++){
		for(int col = 0; col < W; col++){
			scanf("%d",&tmp);
			ans += table[row][col]*tmp;
		}
	}

	printf("%d\n",ans);

	return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
const double PI  = 3.1415926535897932384626433832795028841971;
const int    INF = 100000000;
const double EPS = 1e-10;
const int    MOD = 1000000007;
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int w,h,t,p;
int x[50],y[50],z[50];
int m[50][50];

int main(){
	cin >> w >> h >> t >> p;
    rep(i,p) cin >> x[i] >> y[i] >> z[i];
    rep(i,h){
        rep(j,w){
            int tmp;
            cin >> tmp;
            if(tmp) m[i][j] = 0;
            else m[i][j] = -1;
        }
    }
    int ans = 0;
    rep(i,p){
        if(m[y[i]][x[i]] != -1 && z[i] <= t){
           ans++;
        }
    }
    cout << ans << endl;
}

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

int main(){
    int w,h,t;
    int p,tx,ty,tt;
    int s[50][50];
    int total=0;
    
    for (int i=0;i<50;i++)
        for (int j=0;j<50;j++)
            s[i][j]=0;
    
    cin >> w >> h >> t;
    cin >> p;
    
    for (int i=0; i<p;i++){
        cin >> tx >> ty >> tt;
        s[tx][ty]++;
    }
    
    for (int y=0;y<h;y++){
        for (int x=0;x<w;x++){
            cin >> t;
            if (t) total+=s[x][y];
        }
    }
    cout << total << endl;
    return 0;
}

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

int main(){
  int w,h,t,ha[51][51]={0},x,y,tt,p,u,sum=0;
  cin>>w>>h>>t>>p;
  for(int i=0;i<p;i++){
    cin>>x>>y>>tt;
    if(tt<=t)ha[x][y]++;
  }
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin>>u;
      if(u==1)sum+=ha[j][i];
    }
  }
  cout<<sum<<endl;
  return 0;
}