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<bits/stdc++.h>
using namespace std;

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    int W,H,T,P;
    cin>>W>>H>>T>>P;
    int x[50],y[50],t[50];rep(i,P)cin>>x[i]>>y[i]>>t[i];

    int s[50][50];
    rep(i,H)rep(j,W)cin>>s[i][j];
    int ans=0;
    rep(i,P){
        ans+=s[y[i]][x[i]];
    }
    cout<<ans<<endl;
    return 0;
}

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

int main(){
    int w,h,tim;
    int p;
    cin >> w >> h >> tim;
    cin >> p;
    int hei[50][50]={{}};
    for(int i=0;i<p;i++){
        int x,y,t;
        cin >> x >> y >> t;
        hei[x][y]++;
    }
    int sum=0;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            int a;
            cin >> a;
            //cout << hei[j][i] << " ";
            if(a)sum+=hei[j][i];
        }
      //  cout << endl;
   }
    cout << sum << endl;
}

C++: /*  -*- coding: utf-8 -*-
 *
 * 1587.cc: Plants
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_W = 50;
const int MAX_H = 50;

/* typedef */

/* global variables */

int flds[MAX_H][MAX_W];

/* subroutines */

/* main */

int main() {
  int w, h, t, p;
  scanf("%d%d%d%d", &w, &h, &t, &p);

  for (int i = 0; i < p; i++) {
    int xi, yi, ti;
    scanf("%d%d%d", &xi, &yi, &ti);
    flds[yi][xi]++;
  }

  int sum = 0;
  for (int y = 0; y < h; y++)
    for (int x = 0; x < w; x++) {
      int s;
      scanf("%d", &s);
      if (s) sum += flds[y][x];
    }

  printf("%d\n", sum);
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back

using ll=long long;
using pii=pair<int,int>;
using vi=vector<int>;

int read(){
	int i;
	scanf("%d",&i);
	return i;
}

int s[51][51];
int g[51][51];

int main(){
	int w=read(),h=read(),T=read(),p=read();
	REP(i,p){
		int x=read(),y=read(),t=read();
		g[y][x]++;
	}
	REP(i,h)
		REP(j,w)
			s[i][j]=read();
	int ans=0;
	REP(i,h)REP(j,w)ans+=g[i][j]*s[i][j];
	cout<<ans<<endl;
}

C++: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) { }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};



int main() {
	int W,H,T;cin>>W>>H>>T;
	int Q;cin>>Q;
	vector<vector<int>>field(H,vector<int>(W));
	while (Q--) {
		int x,y,t;cin>>x>>y>>t;
		field[y][x]++;
	}
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			int a;cin>>a;
			field[i][j]*=a;
		}
	}
	int ans = accumulate(field.begin(), field.end(), 0,
		[](const int a, const vector<int>&v) {
		return a+accumulate(v.begin(),v.end(),0);
	});
	cout<<ans<<endl;
	return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;

#define int long long

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define omajinai ios::sync_with_stdio(false);cin.tie(0)
#define rep(i,x) for(int i=0;i<(int)(x);++i)
#define rep1(i,x) for(int i=1;i<=(int)(x);++i)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

template<typename T>T& max(T&a,T&b){if(a>=b)return a;return b;}
template<typename T>T& min(T&a,T&b){if(a<b)return a;return b;}
template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>T get(){T a;cin>>a;return a;}
template<typename T>T rev(T a){reverse(all(a));return a;}
template<typename T>vector<T>&sort(vector<T>&a){sort(all(a));return a;}

const int inf = 1e9;
const ll linf = 3e18;
const double eps = 1e-9;

int cnt[55][55];
vpii mp[55];

signed main()
{ // #define int long long ?????????????????§scanf???????????¨???????????????????????\?????????????????????
    int W, H, T; cin >> W >> H >> T;

    int p; cin >> p;

    rep(i, p) {
        int x, y, t; cin >> x >> y >> t;
        mp[t].PB(pii(y, x));
    }

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

    int ans = 0;

    rep(i, T) {
        rep(j, mp[i].size()) {
            pii p = mp[i][j];

            if (cnt[p.fst][p.scd]) {
                cnt[p.fst][p.scd] += 1;
            }
        }
    }
    rep(i, H) rep(j, W) if (cnt[i][j] > 0) ans += cnt[i][j] - 1;

    cout << ans << endl;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << x << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 60


int main(){
  int w,h,T,p;
  int x[SIZE],y[SIZE],t[SIZE];
  int a[SIZE][SIZE];
  
  scanf("%d%d%d%d",&w,&h,&T,&p);

  for(int i=0;i<p;i++){
    scanf("%d%d%d",x+i,y+i,t+i);
  }

  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      scanf("%d",a[i]+j);
    }
  }

  for(int i=0;i<p;i++){
    if(a[y[i]][x[i]]) a[y[i]][x[i]]++;
  }

  int ans = 0;
  
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      ans += max(0,a[i][j]-1);
    }
  }

  printf("%d\n",ans);
  
  return 0;
}