Problem:
親方の給料計算
ワシはパイプつなぎ組合の親方じゃ。職人を工事現場に派遣し、現場でパイプをつながせておる。去年は工事が増えて大儲けするかと思ったのじゃが、ちょっと給料の出し方がまずくてのぅ。ウチとしては大赤字になってしまったのじゃよ…。そこで、今年は職人たちへの給料の出し方を工夫したいのじゃ。
職人たちの給料は、工事の種類とこなした回数で決めておる。つまり、
職人の給料 ＝ 種類 1 の単価 × 種類 1 をこなした回数
+ 種類 2 の単価 × 種類 2 をこなした回数
....
+ 種類
M
の単価 × 種類
M
をこなした回数
となるのじゃ。これを計算するために、ウチでは、どの職人がどの種類の工事を何回こなしたかを次のような表に記録しておる。
例えば、上の表では、職人１が工事２を２回、工事４を１回こなしたことを示しておる。
職人たちがこなした仕事の回数はもう変えられんが、やつらは工事の単価を知らんので、単価をいろいろと変えながら皆の不満が出ぬよう給料を調整しようと思うておる。じゃが、ワシがこしらえたプログラムが今もって動かなくてのぅ。ちょっとみてくれんかね。
//省略
int i, j;
for ( i = 0; i < N; i++ ){
    c[i] = 0;
    for ( j = 0; j < M; j++ ){
        c[i] = c[i] + a[i][j]*b[j];
    }
}
//省略
N
は職人の数で
M
は工事の種類の数じゃ。変数
a[i][j]
に職人iが工事
j
をこなした回数を、
b[j]
に工事
j
の単価をいれて、
c[i]
に職人
i
の給料を格納しておる。合っているはずなのに、うんともすんとも言わん！そろそろ今年の給料を職人たちに払わないとまずいのじゃが・・・・・なんとかならんかのぅ。
それでは、職人のこなした仕事の回数と各工事の単価の情報が与えられたとき、各職人の給料を計算するプログラムを作成してください。
入力
入力は1つのデータセットからなる。入力データは以下の形式で与えられる。
N
M
s
1
t
1
e
1
s
2
t
2
e
2
:
0 0 0
L
b
11
b
12
...
b
1M
b
21
b
22
...
b
2M
:
b
L1
b
L2
...
b
LM
1行目は職人の数
N
(1 ≤
N
≤ 10000)と工事の種類の数
M
(1 ≤
M
≤ 10000)。
続いて、工事の記録として、職人の番号
s
i
(1 ≤
s
i
≤
N
) と工事の種類の番号
t
i
(1 ≤
t
i
≤
M
)、および職人
s
i
が工事
t
i
をこなした回数
e
i
(1 ≤
e
i
≤ 50000) からなる行が１行以上与えられる。工事の記録はゼロ３つの行で終わる。ただし、
e
i
の合計は 1 以上 50000 以下である。また、工事の記録には、どの職人と工事の種類の組も２度以上現れない。工事をこなした回数が 0 である職人と工事の種類の組は与えられない。
続く 1 行は給料の算出を行う回数
L
(1 ≤
L
≤ 100) 。
続く
L
行は、
i
回目の給料の算出に必要な、工事
j
の単価
b
ij
(0 ≤
b
ij
≤ 10000) の並び。
出力
以下の形式で、
i
回目の給料の算出によって得られた職人
j
の給料
c
ij
を順番に出力する。各給料の間は空白１つで区切る。
c
11
c
12
...
c
1N
c
21
c
22
...
c
2N
:
c
L1
c
L2
...
c
LN
入出力例
入力例
4 6
1 2 1
2 3 2
2 4 3
3 1 5
4 2 4
4 3 2
4 6 10
0 0 0
3
1 3 2 4 0 10
6 5 4 3 2 1
5 1 1 5 5 1
出力例
3 16 5 116
5 17 30 38
1 17 25 16

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, e) for (int i = (int)(s); i < (int)(e); ++i)

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	
	int N, M;
	cin >> N >> M;
	vector<int> S, T, E;
	while (true) {
		int s, t, e;
		cin >> s >> t >> e;
		if (s == 0 && t == 0 && e == 0) break;
		S.push_back(s - 1);
		T.push_back(t - 1);
		E.push_back(e);
	}
	
	int L;
	cin >> L;
	vector B(L, vector<ll>(M));
	rep(i, 0, L) rep(j, 0, M) cin >> B[i][j];
	
	vector C(L, vector<ll>(N));
	
	rep(i, 0, S.size()) {
		rep(j, 0, L) C[j][S[i]] += E[i]*B[j][T[i]];
	}
	
	rep(i, 0, L) {
		rep(j, 0, N) cout << C[i][j] << (j == N - 1 ? '\n' : ' ');
	}
}
accuracy: 1
time_ms: 120
memory_kb: 19324
final_rank: 17

code_snippet: #include <bits/stdc++.h>
using namespace std;

int main() {
    int N, M;
    cin >> N >> M;  // Number of craftsmen and job types

    vector<vector<pair<int, int>>> jobs(N);  // Store {type, count} pairs for each craftsman

    // Read the job records
    while (true) {
        int s, t, e;
        cin >> s >> t >> e;
        if (s == 0 && t == 0 && e == 0) break;
        s--; t--;  // To use 0-based indexing
        jobs[s].emplace_back(t, e);
    }

    int L;
    cin >> L;  // Number of salary queries

    // Process each salary query
    for (int query = 0; query < L; query++) {
        vector<int> unit_price(M);  // Unit prices for current query
        for (int i = 0; i < M; i++) {
            cin >> unit_price[i];
        }

        // Calculate salary for each craftsman
        vector<int> salary(N, 0);
        for (int i = 0; i < N; i++) {
            for (auto job : jobs[i]) {
                int job_type = job.first;
                int job_count = job.second;
                salary[i] += job_count * unit_price[job_type];
            }
        }

        // Output the salaries
        for (int i = 0; i < N; i++) {
            cout << salary[i] << (i == N - 1 ? "\n" : " ");
        }
    }

    return 0;
}
accuracy: 1
time_ms: 180
memory_kb: 4192
final_rank: 7

code_snippet: #line 1 "/opt/library/template.hpp"
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using i64 = long long;
using u32 = unsigned int;
using u64 = unsigned long long;
using i128 = __int128;
using u128 = unsigned __int128;
using f128 = __float128;

template <class T>
constexpr T infty = 0;
template <>
constexpr int infty<int> = 1'000'001'000;
template <>
constexpr ll infty<ll> = ll(infty<int>) * infty<int> * 2;
template <>
constexpr u32 infty<u32> = infty<int>;
template <>
constexpr u64 infty<u64> = infty<ll>;
template <>
constexpr i128 infty<i128> = i128(infty<ll>) * infty<ll>;
template <>
constexpr double infty<double> = infty<ll>;
template <>
constexpr long double infty<long double> = infty<ll>;
#define inf infty<ll>

using pi = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vector<ll>>;
template <class T>
using vc = vector<T>;
template <class T>
using vvc = vector<vc<T>>;
template <class T>
using vvvc = vector<vvc<T>>;
template <class T>
using vvvvc = vector<vvvc<T>>;
template <class T>
using vvvvvc = vector<vvvvc<T>>;
template <class T>
using pq = priority_queue<T>;
template <class T>
using pqg = priority_queue<T, vector<T>, greater<T>>;

#define vv(type, name, h, ...) \
  vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define vvv(type, name, h, w, ...)   \
  vector<vector<vector<type>>> name( \
      h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
#define vvvv(type, name, a, b, c, ...)       \
  vector<vector<vector<vector<type>>>> name( \
      a, vector<vector<vector<type>>>(       \
             b, vector<vector<type>>(c, vector<type>(__VA_ARGS__))))

#define rep1(a) for (ll _ = 0; _ < (ll)(a); ++_)
#define rep2(i, a) for (ll i = 0; i < (ll)(a); ++i)
#define rep3(i, a, b) for (ll i = a; i < (ll)(b); ++i)
#define rep4(i, a, b, c) for (ll i = a; i < (ll)(b); i += (c))
#define rrep1(a) for (ll i = (a)-1; i >= (ll)(0); --i)
#define rrep2(i, a) for (ll i = (a)-1; i >= (ll)(0); --i)
#define rrep3(i, a, b) for (ll i = (b)-1; i >= (ll)(a); --i)
#define rrep4(i, a, b, c) for (ll i = (b)-1; i >= (ll)(a); i -= (c))
#define overload4(a, b, c, d, e, ...) e
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(...) overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)

#define all(x) (x).begin(),(x).end()
#define len(x) (ll)(x.size())
#define elif else if
#define bit(x, i) (((x)>>(i))&1)

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second

#define stoi stoll
#define abs llabs

#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define LB(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define UB(c, x) distance((c).begin(), upper_bound(all(c), (x)))
#define UNIQUE(x) \
  sort(all(x)), x.erase(unique(all(x)), x.end()), x.shrink_to_fit()

ll popcnt(ll x) { return __builtin_popcountll(x); }
ll popcnt(u64 x) { return __builtin_popcountll(x); }
ll popcnt_mod_2(ll x) { return __builtin_parityll(x); }
ll popcnt_mod_2(u64 x) { return __builtin_parityll(x); }
ll topbit(ll x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
ll topbit(u64 x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
ll lowbit(ll x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }
ll lowbit(u64 x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }

template <typename T>
T floor(T a, T b) {
  return a / b - (a % b && (a ^ b) < 0);
}
template <typename T>
T ceil(T x, T y) {
  return floor(x + y - 1, y);
}
template <typename T>
T bmod(T x, T y) {
  return x - y * floor(x, y);
}
template <typename T>
pair<T, T> divmod(T x, T y) {
  T q = floor(x, y);
  return {q, x - q * y};
}

template<typename T> T SUM(const vector<T> &A) {
  T s = 0; for (auto &&a: A) s += a;
  return s;
}

template <typename T>
T POP(queue<T> &que) {
  T a = que.front();
  que.pop();
  return a;
}
template <typename T>
T POP(deque<T> &que) {
  T a = que.front();
  que.pop_front();
  return a;
}
template <typename T>
T POP(pq<T> &que) {
  T a = que.top();
  que.pop();
  return a;
}
template <typename T>
T POP(pqg<T> &que) {
  T a = que.top();
  que.pop();
  return a;
}
template <typename T>
T POP(vc<T> &que) {
  T a = que.back();
  que.pop_back();
  return a;
}

template <typename F>
ll binary_search(F check, ll ok, ll ng, bool check_ok = true) {
  if (check_ok) assert(check(ok));
  while (abs(ok - ng) > 1) {
    auto x = (ng + ok) / 2;
    (check(x) ? ok : ng) = x;
  }
  return ok;
}
template <typename F>
f128 binary_search_real(F check, f128 ok, f128 ng, ll iter = 100) {
  rep(iter) {
    f128 x = (ok + ng) / 2;
    (check(x) ? ok : ng) = x;
  }
  return (ok + ng) / 2;
}

// ? は -1
vc<int> s_to_vi(const string &S, char first_char) {
  vc<int> A(S.size());
  rep(i, S.size()) { A[i] = (S[i] != '?' ? S[i] - first_char : -1); }
  return A;
}

template <typename T, typename U>
vc<T> cumsum(vc<U> &A, ll off = 1) {
  ll N = A.size();
  vc<T> B(N + 1);
  rep(i, N) { B[i + 1] = B[i] + A[i]; }
  if (off == 0) B.erase(B.begin());
  return B;
}

// stable sort
template <typename T>
vi argsort(const vector<T> &A) {
  vi ids(len(A));
  iota(all(ids), 0);
  sort(all(ids),
       [&](ll i, ll j) { return (A[i] == A[j] ? i < j : A[i] < A[j]); });
  return ids;
}

// A[I[0]], A[I[1]], ...
template <typename T>
vc<T> rearrange(const vc<T> &A, const vi &I) {
  vc<T> B(len(I));
  rep(i, len(I)) B[i] = A[I[i]];
  return B;
}

template<typename T> inline bool chmax(T &a, T b) {return ((a<b)?(a=b,true):(false));}
template<typename T> inline bool chmin(T &a, T b) {return ((a>b)?(a=b,true):(false));}

inline void wt(const char c) { cout << c; }
inline void wt(const string s) { cout << s; }
inline void wt(const char *s) { cout << s; }

template <typename T>
void wt_integer(T x) {
  cout << (x);
}
template <typename T>
void wt_real(T x) {
  cout << fixed << setprecision(15) << (long double)(x);
}
template <typename T>
void wt_integer128(T x) {
  char buf[64];
  char *d = end(buf);
  d--; *d = '\0';
  __uint128_t tmp = ((x < 0)? -x : x);
  do {
    d--; *d = char(tmp%10 + '0'); tmp /= 10;
  } while (tmp);
  if (x < 0) {
    d--; *d = '-';
  }
  cout << d;
}

inline void wt(int x) { wt_integer(x); }
inline void wt(ll x) { wt_integer(x); }
inline void wt(i128 x) { wt_integer128(x); }
inline void wt(u32 x) { wt_integer(x); }
inline void wt(u64 x) { wt_integer(x); }
inline void wt(u128 x) { wt_integer128(x); }
inline void wt(double x) { wt_real(x); }
inline void wt(long double x) { wt_real(x); }
inline void wt(f128 x) { wt_real(x); }

template <class T, class U>
void wt(const pair<T, U> val) {
  wt(val.first); wt(' '); wt(val.second);
}
template <size_t N = 0, typename T>
void wt_tuple(const T t) {
  if constexpr (N < std::tuple_size<T>::value) {
    if constexpr (N > 0) { wt(' '); }
    const auto x = std::get<N>(t);
    wt(x);
    wt_tuple<N + 1>(t);
  }
}
template <class... T>
void wt(tuple<T...> tpl) {
  wt_tuple(tpl);
}
template <class T, size_t S>
void wt(const array<T, S> val) {
  auto n = val.size();
  for (size_t i = 0; i < n; i++) {
    if (i) wt(' ');
    wt(val[i]);
  }
}
template <class T>
void wt(const vector<T> val) {
  auto n = val.size();
  for (size_t i = 0; i < n; i++) {
    if (i) wt(' ');
    wt(val[i]);
  }
}

void print() { wt('\n'); }
template <class Head, class... Tail>
void print(Head &&head, Tail &&... tail) {
  wt(head);
  if (sizeof...(Tail)) wt(' ');
  print(forward<Tail>(tail)...);
}

void YES(bool t = 1) { print(t ? "YES" : "NO"); }
void NO(bool t = 1) { YES(!t); }
void Yes(bool t = 1) { print(t ? "Yes" : "No"); }
void No(bool t = 1) { Yes(!t); }
void yes(bool t = 1) { print(t ? "yes" : "no"); }
void no(bool t = 1) { yes(!t); }
void onez(bool t = 1) { print(t ? 1 : 0); }
#define endl '\n'
#define dump(x) {cerr << #x " = " << x << '\n';}
#line 2 "main.cpp"

int solve();
int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  while (!solve()) {break;}
  return 0;
}

int solve() {
  ll N, M, s, t, e, L, b;
  cin >> N >> M;
  vvc<pi> te(M);
  while (true) {
    cin >> s >> t >> e;
    if (s == 0 and t == 0 and e == 0) break;
    s--; t--;
    te[t].eb(mp(s, e));
  }
  cin >> L;
  rep(L) {
    vi salary(N, 0);
    rep(i, M) {
      cin >> b;
      rep(j, len(te[i])) {
        salary[te[i][j].fi] += b * te[i][j].se;
      }
    }
    print(salary);
  }
  return 0;
}
accuracy: 1
time_ms: 90
memory_kb: 4984
final_rank: 2

code_snippet: #include <bits/stdc++.h>
using namespace std;
int main(void){
 int a,b;
 cin>>a>>b;
 int x[a];
 int y[b];
 map<pair<int,int>,int> t;
 while(true){
     int c,d,e;
     cin>>c>>d>>e;
     if(c==d&&d==e&&e==0){
         break;
     }
     pair<int,int> f=make_pair(c,d);
     t[f]=e;
 }
 int r;
 cin>>r;
 for(int i=0;i<r;i+=1){
     for(int j=0;j<a;j+=1){
         x[j]=0;
     }
     for(int j=0;j<b;j+=1){
         cin>>y[j];
     }
     for(auto p:t){
         x[p.first.first-1]+=y[p.first.second-1]*p.second;
     }
     for(int j=0;j<a;j+=1){
         cout<<x[j];
         if(j<a-1){
             cout<<" ";
         }
     }
     cout<<endl;
 }
}
accuracy: 1
time_ms: 260
memory_kb: 6620
final_rank: 15

code_snippet: #include <bits/stdc++.h>
using namespace std;
int main(void){
 int a,b;
 cin>>a>>b;
 int x[a][b];
 int y[b];
 for(int i=0;i<a;i+=1){
     for(int j=0;j<b;j+=1){
         x[i][j]=0;
     }
 }
 while(true){
     int c,d,e;
     cin>>c>>d>>e;
     if(c==d&&d==e&&e==0){
         break;
     }
     x[c-1][d-1]=e;
 }
 int r;
 cin>>r;
 for(int i=0;i<r;i+=1){
     for(int j=0;j<b;j+=1){
         cin>>y[j];
     }
     for(int j=0;j<a;j+=1){
         int w=0;
         for(int k=0;k<b;k+=1){
             w+=x[j][k]*y[k];
         }
         cout<<w;
         if(j<a-1){
             cout<<" ";
         }
     }
     cout<<endl;
 }
}
accuracy: 0.8
time_ms: 1310
memory_kb: 101016
final_rank: 20

code_snippet: #include <iostream>
#include <vector>


int main()
{
	size_t n, m;
	std::cin >> n >> m;
	std::vector<std::vector<std::pair<size_t, int>>> records(n);
	for (; ; ) {
		size_t s, t;
		int e;
		std::cin >> s >> t >> e;
		if (s == 0 && t == 0 && e == 0) {
			break;
		}
		records[s - 1].emplace_back(t - 1, e);
	}

	size_t l;
	std::cin >> l;
	for (auto i = size_t(0); i < l; ++i) {
		std::vector<int> b(m);
		for (auto j = size_t(0); j < m; ++j) {
			std::cin >> b[j];
		}

		for (auto j = size_t(0); j < n; ++j) {
			auto c = 0;
			for (const auto& a : records[j]) {
				c += a.second * b[a.first];
			}
			if (j > 0) {
				std::cout << " ";
			}
			std::cout << c;
		}
		std::cout << std::endl;
	}

	return 0;
}
accuracy: 1
time_ms: 180
memory_kb: 4696
final_rank: 8

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
  int N, M, s, t, e, L;
  cin >> N >> M;
  vector<vector<pair<int,ll>>> tb(N);
  while(cin >> s >> t >> e, s){
    tb[--s].emplace_back(--t, e);
  }
  cin >> L;
  while(L--){
    vector<ll> ans(N), cost(M);
    for(auto &&v:cost)cin >> v;
    for(int i = 0; i < N; i++){
      for(int j = 0; j < tb[i].size(); j++){
        ans[i] += cost[tb[i][j].first] * tb[i][j].second;
      }
      if(i)cout << " ";
      cout << ans[i];
    }
    cout << '\n';
  }
}
accuracy: 1
time_ms: 180
memory_kb: 4832
final_rank: 9

code_snippet: #include <bits/stdc++.h>
//#include <atcoder/all>
//using namespace atcoder;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
using namespace std;
 
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, int> pii;
typedef pair<long long, long long> PLL;
typedef pair<int, PII> TIII;
 
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
 
 
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()
 
#define MOD 1000000007
 
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) {if (a < b) {a = b; return true;} return false;}
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) {if (a > b) {a = b; return true;} return false;}
const double EPS = 1e-12, PI = acos(-1);
const double pi = 3.141592653589793238462643383279;
//ここから編集    
typedef string::const_iterator State;
ll GCD(ll a, ll b){
  return (b==0)?a:GCD(b, a%b);
}
ll LCM(ll a, ll b){
  return a/GCD(a, b) * b;
}
template< int mod >
struct ModInt {
  int x;
 
  ModInt() : x(0) {}
 
  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
 
  ModInt &operator+=(const ModInt &p) {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }
 
  ModInt &operator-=(const ModInt &p) {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }
 
  ModInt &operator*=(const ModInt &p) {
    x = (int) (1LL * x * p.x % mod);
    return *this;
  }
 
  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }
 
  ModInt operator-() const { return ModInt(-x); }
 
  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
 
  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
 
  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
 
  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
 
  bool operator==(const ModInt &p) const { return x == p.x; }
 
  bool operator!=(const ModInt &p) const { return x != p.x; }
 
  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }
 
  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }
 
  friend ostream &operator<<(ostream &os, const ModInt &p) {
    return os << p.x;
  }
 
  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt< mod >(t);
    return (is);
  }
 
  static int get_mod() { return mod; }
};
 
using modint = ModInt< 1000000007 >;
template< typename T >
struct Combination {
  vector< T > _fact, _rfact, _inv;
 
  Combination(int sz) : _fact(sz + 1), _rfact(sz + 1), _inv(sz + 1) {
    _fact[0] = _rfact[sz] = _inv[0] = 1;
    for(int i = 1; i <= sz; i++) _fact[i] = _fact[i - 1] * i;
    _rfact[sz] /= _fact[sz];
    for(int i = sz - 1; i >= 0; i--) _rfact[i] = _rfact[i + 1] * (i + 1);
    for(int i = 1; i <= sz; i++) _inv[i] = _rfact[i] * _fact[i - 1];
  }
 
  inline T fact(int k) const { return _fact[k]; }
 
  inline T rfact(int k) const { return _rfact[k]; }
 
  inline T inv(int k) const { return _inv[k]; }
 
  T P(int n, int r) const {
    if(r < 0 || n < r) return 0;
    return fact(n) * rfact(n - r);
  }
 
  T C(int p, int q) const {
    if(q < 0 || p < q) return 0;
    return fact(p) * rfact(q) * rfact(p - q);
  }
 
  T H(int n, int r) const {
    if(n < 0 || r < 0) return (0);
    return r == 0 ? 1 : C(n + r - 1, r);
  }
};
 
ll modpow(ll x, ll n, ll mod) {
  ll res = 1;
  while(n) {
    if(n&1) res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
} 
inline long long mod(long long a, long long m) {
    return (a % m + m) % m;
}
class UnionFind {
public:
    vector <ll> par; 
    vector <ll> siz; 
 
    vector <ll> maxv;
    UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
 
    ll root(ll x) { 
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
 
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }
 
    bool issame(ll x, ll y) { 
        return root(x) == root(y);
    }
 
    ll size(ll x) { 
        return siz[root(x)];
    }
};
int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  
  int n, m; cin >> n >> m;
  int s, t, e;
  vector<ll> ss, tt, ee;
  while(cin >> s >> t >> e) {
    if(s == 0 && t == 0 && e == 0) break;
    s--; t--;
    ss.push_back(s);
    tt.push_back(t);
    ee.push_back(e);
  }

  int L; cin >> L;
  vector<vector<ll>> ans(L, vector<ll>(n));
  vector<vector<ll>> b(L, vector<ll>(m));
  REP(i,L) {
    REP(j,m) cin >> b[i][j];
  }
  REP(i,ss.size()) {
    REP(j,L) {
      s = ss[i];
      t = tt[i];
      e = ee[i];
      ans[j][s] += b[j][t] * e;
    }
  }
  REP(i,L) {
    REP(j,n) {
      if(j) cout << " ";
      cout << ans[i][j];
    }
    cout << endl;
  }
  return 0;
}
accuracy: 1
time_ms: 120
memory_kb: 19796
final_rank: 18

code_snippet: #include <bits/stdc++.h>
using namespace std;
int main(){
  int N, M;
  cin >> N >> M;
  vector<int> s, t, e;
  int cnt = 0;
  while (true){
    int s2, t2, e2;
    cin >> s2 >> t2 >> e2;
    if (s2 == 0 && t2 == 0 && e2 ==0){
      break;
    }
    s2--;
    t2--;
    s.push_back(s2);
    t.push_back(t2);
    e.push_back(e2);
    cnt++;
  }
  int L;
  cin >> L;
  for (int i = 0; i < L; i++){
    vector<int> b(M);
    for (int j = 0; j < M; j++){
      cin >> b[j];
    }
    vector<int> c(N, 0);
    for (int j = 0; j < cnt; j++){
      c[s[j]] += b[t[j]] * e[j];
    }
    for (int j = 0; j < N; j++){
      cout << c[j];
      if (j < N - 1){
        cout << ' ';
      }
    }
    cout << endl;
  }
}
accuracy: 1
time_ms: 170
memory_kb: 3876
final_rank: 4

code_snippet: #include <bits/stdc++.h>
using namespace std;


// {{{

// clang-format off
#define len(x) (static_cast<int>((x).size()))
#define _over_load(_1,_2,_3,_4,NAME,...) NAME
#define range(...) _over_load(__VA_ARGS__, range4, range3, range2)(__VA_ARGS__)
#define range2(i, r) for ( int i = 0; i < static_cast<int>(r); (i) += 1)
#define range3(i, l, r) for ( int i = static_cast<int>(l); i < static_cast<int>(r); (i) += 1)
#define range4(i, l, r, step) for ( int i = static_cast<int>(l); i < static_cast<int>(r); (i) += (step))
#define rrange(...) _over_load(__VA_ARGS__, rrange4, rrange3, rrange2)(__VA_ARGS__)
#define rrange2(i, r) for ( int i = static_cast<int>(r) - 1; i >= 0; (i) -= 1)
#define rrange3(i, l, r) for ( int i = static_cast<int>(r) - 1; i >= static_cast<int>(l); (i) -= 1)
#define rrange4(i, l, r, step) for ( int i = static_cast<int>(r) - 1; i >= static_cast<int>(l); (i) -= (step))
#define whole(f, x, ...) ([&](decltype((x)) container) { return (f)( begin(container), end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)
#define debug(...) debug_function(#__VA_ARGS__, __VA_ARGS__)
template <typename T, typename... T2> void debug_function(string_view name, const T &a, T2 &&...rest) {
  stack<char> bs;
  string_view lbs = "({[<", rbs = ")}]>";
  int end = name.size();
  for ( int i = 0; i < len(name); i++ ) {
    if ( lbs.find(name[i]) != string::npos ) bs.push(name[i]);
    if ( rbs.find(name[i]) != string::npos and !bs.empty() ) bs.pop();
    if ( name[i] == ',' and bs.empty() ) {
      end = i;
      break;
    }
  }
  cerr << name.substr(0, end) << ":" << a;
  if constexpr ( sizeof...(rest) == 0 ) {
    cerr << '\n';
  } else {
    cerr << ' ';
    debug_function(name.substr(name.find_first_not_of(' ', end + 1)), forward<T2>(rest)...);
  }
}
template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b and (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b and (a = b, true); }
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << p.first << ' ' << p.second; return os; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, const map<T1, T2> &v) { for ( pair<T1, T2> x : v ) { os << "(" << x.first <<", " << x.second << ")" << (v.rbegin()->first == x.first ? "" : ", "); } return os; }
template <typename T> ostream &operator<<(ostream &os, queue<T> v) { if(!v.empty()) { os << v.front(); v.pop(); } while (!v.empty()) { os << " " << v.front(); v.pop(); } return os; }
template <typename T> ostream &operator<<(ostream &os, stack<T> v) { if(!v.empty()) { os << v.top(); v.pop(); } while (!v.empty()) { os << " " << v.top(); v.pop(); } return os; }
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { range(i, len(v)) { cout << v[i] << (i == len(v) - 1 ? "" : " "); } return os; }
template <typename T> ostream &operator<<(ostream &os, const deque<T> &v) { range(i, len(v)) { cout << v[i] << (i == len(v) - 1 ? "" : " "); } return os; }
template <typename T> ostream &operator<<(ostream &os, const set<T> &v) { bool is_f = true; for ( T x : v ) { os << (is_f ? "" : " ") << x; is_f = false; } return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }
struct IoSetup { IoSetup(int x = 15) { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;
using ull = unsigned long long;
using ll = long long;
using Pll = pair<ll, ll>;
using P = pair<int, int>;
constexpr ll INF64 = INT64_MAX / 2;
constexpr int INF32 = INT32_MAX / 2;
constexpr int dy[] = { 0, -1, 1, 0, -1, 1, -1, 1 };
constexpr int dx[] = { -1, 0, 0, 1, -1, -1, 1, 1 };
constexpr int mod998244353 = 998244353;
constexpr int mod1000000007 = static_cast<int>(1e9) + 7;
constexpr char newl = '\n';
// clang-format on

// }}}



int main() {
  int n,m;
  cin>>n>>m;

  vector<map<int,int>> cnts(n);
  while(1){
    int s,t,e;
    cin>>s>>t>>e;
    if(s==0 and t==0 and e==0) break;
    s--,t--;
    cnts[s][t]+=e;
  }

  int l;
  cin>>l;
  auto bs = make_vector(l,m,0LL);
  range(i,l){
    range(j,m){
      cin>>bs[i][j];
    }
  }

  range(i,l){
    auto cs = make_vector(n,0LL);
    range(j,n){
      for(auto [job,cnt]:cnts[j]){
        cs[j]+=cnt*bs[i][job];
      }
    }
    cout<<cs<<newl;
  }
}
accuracy: 1
time_ms: 130
memory_kb: 13764
final_rank: 12

code_snippet: #include <bits/stdc++.h>
using namespace std;


// {{{

// clang-format off
#define len(x) (static_cast<int>((x).size()))
#define _over_load(_1,_2,_3,_4,NAME,...) NAME
#define range(...) _over_load(__VA_ARGS__, range4, range3, range2)(__VA_ARGS__)
#define range2(i, r) for ( int i = 0; i < static_cast<int>(r); (i) += 1)
#define range3(i, l, r) for ( int i = static_cast<int>(l); i < static_cast<int>(r); (i) += 1)
#define range4(i, l, r, step) for ( int i = static_cast<int>(l); i < static_cast<int>(r); (i) += (step))
#define rrange(...) _over_load(__VA_ARGS__, rrange4, rrange3, rrange2)(__VA_ARGS__)
#define rrange2(i, r) for ( int i = static_cast<int>(r) - 1; i >= 0; (i) -= 1)
#define rrange3(i, l, r) for ( int i = static_cast<int>(r) - 1; i >= static_cast<int>(l); (i) -= 1)
#define rrange4(i, l, r, step) for ( int i = static_cast<int>(r) - 1; i >= static_cast<int>(l); (i) -= (step))
#define whole(f, x, ...) ([&](decltype((x)) container) { return (f)( begin(container), end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)
#define debug(...) debug_function(#__VA_ARGS__, __VA_ARGS__)
template <typename T, typename... T2> void debug_function(string_view name, const T &a, T2 &&...rest) {
  stack<char> bs;
  string_view lbs = "({[<", rbs = ")}]>";
  int end = name.size();
  for ( int i = 0; i < len(name); i++ ) {
    if ( lbs.find(name[i]) != string::npos ) bs.push(name[i]);
    if ( rbs.find(name[i]) != string::npos and !bs.empty() ) bs.pop();
    if ( name[i] == ',' and bs.empty() ) {
      end = i;
      break;
    }
  }
  cerr << name.substr(0, end) << ":" << a;
  if constexpr ( sizeof...(rest) == 0 ) {
    cerr << '\n';
  } else {
    cerr << ' ';
    debug_function(name.substr(name.find_first_not_of(' ', end + 1)), forward<T2>(rest)...);
  }
}
template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b and (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b and (a = b, true); }
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << p.first << ' ' << p.second; return os; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, const map<T1, T2> &v) { for ( pair<T1, T2> x : v ) { os << "(" << x.first <<", " << x.second << ")" << (v.rbegin()->first == x.first ? "" : ", "); } return os; }
template <typename T> ostream &operator<<(ostream &os, queue<T> v) { if(!v.empty()) { os << v.front(); v.pop(); } while (!v.empty()) { os << " " << v.front(); v.pop(); } return os; }
template <typename T> ostream &operator<<(ostream &os, stack<T> v) { if(!v.empty()) { os << v.top(); v.pop(); } while (!v.empty()) { os << " " << v.top(); v.pop(); } return os; }
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { range(i, len(v)) { cout << v[i] << (i == len(v) - 1 ? "" : " "); } return os; }
template <typename T> ostream &operator<<(ostream &os, const deque<T> &v) { range(i, len(v)) { cout << v[i] << (i == len(v) - 1 ? "" : " "); } return os; }
template <typename T> ostream &operator<<(ostream &os, const set<T> &v) { bool is_f = true; for ( T x : v ) { os << (is_f ? "" : " ") << x; is_f = false; } return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }
struct IoSetup { IoSetup(int x = 15) { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;
using ull = unsigned long long;
using ll = long long;
using Pll = pair<ll, ll>;
using P = pair<int, int>;
constexpr ll INF64 = INT64_MAX / 2;
constexpr int INF32 = INT32_MAX / 2;
constexpr int dy[] = { 0, -1, 1, 0, -1, 1, -1, 1 };
constexpr int dx[] = { -1, 0, 0, 1, -1, -1, 1, 1 };
constexpr int mod998244353 = 998244353;
constexpr int mod1000000007 = static_cast<int>(1e9) + 7;
constexpr char newl = '\n';
// clang-format on

// }}}



int main() {
  int n,m;
  cin>>n>>m;

  vector<map<int,int>> cnts(n);
  while(1){
    int s,t,e;
    cin>>s>>t>>e;
    if(s==0 and t==0 and e==0) break;
    s--,t--;
    cnts[s][t]+=e;
  }

  int l;
  cin>>l;
  auto bs = make_vector(l,m,0LL);
  range(i,l){
    range(j,m){
      cin>>bs[i][j];
    }
  }

  range(i,l){
    auto cs = make_vector(n,0LL);
    range(j,n){
      for(auto [job,cnt]:cnts[j]){
        cs[j]+=cnt*bs[i][job];
      }
    }
    range(j,n){
      if(j) cout<<' ';
      cout<<cs[j];
    }
    cout<<newl;
    // cout<<cs<<newl;
  }
}
accuracy: 1
time_ms: 130
memory_kb: 13724
final_rank: 10

code_snippet: #include <bits/stdc++.h>
using namespace std;


// {{{

// clang-format off
#define len(x) (static_cast<int>((x).size()))
#define _over_load(_1,_2,_3,_4,NAME,...) NAME
#define range(...) _over_load(__VA_ARGS__, range4, range3, range2)(__VA_ARGS__)
#define range2(i, r) for ( int i = 0; i < static_cast<int>(r); (i) += 1)
#define range3(i, l, r) for ( int i = static_cast<int>(l); i < static_cast<int>(r); (i) += 1)
#define range4(i, l, r, step) for ( int i = static_cast<int>(l); i < static_cast<int>(r); (i) += (step))
#define rrange(...) _over_load(__VA_ARGS__, rrange4, rrange3, rrange2)(__VA_ARGS__)
#define rrange2(i, r) for ( int i = static_cast<int>(r) - 1; i >= 0; (i) -= 1)
#define rrange3(i, l, r) for ( int i = static_cast<int>(r) - 1; i >= static_cast<int>(l); (i) -= 1)
#define rrange4(i, l, r, step) for ( int i = static_cast<int>(r) - 1; i >= static_cast<int>(l); (i) -= (step))
#define whole(f, x, ...) ([&](decltype((x)) container) { return (f)( begin(container), end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)
#define debug(...) debug_function(#__VA_ARGS__, __VA_ARGS__)
template <typename T, typename... T2> void debug_function(string_view name, const T &a, T2 &&...rest) {
  stack<char> bs;
  string_view lbs = "({[<", rbs = ")}]>";
  int end = name.size();
  for ( int i = 0; i < len(name); i++ ) {
    if ( lbs.find(name[i]) != string::npos ) bs.push(name[i]);
    if ( rbs.find(name[i]) != string::npos and !bs.empty() ) bs.pop();
    if ( name[i] == ',' and bs.empty() ) {
      end = i;
      break;
    }
  }
  cerr << name.substr(0, end) << ":" << a;
  if constexpr ( sizeof...(rest) == 0 ) {
    cerr << '\n';
  } else {
    cerr << ' ';
    debug_function(name.substr(name.find_first_not_of(' ', end + 1)), forward<T2>(rest)...);
  }
}
template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b and (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b and (a = b, true); }
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << p.first << ' ' << p.second; return os; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, const map<T1, T2> &v) { for ( pair<T1, T2> x : v ) { os << "(" << x.first <<", " << x.second << ")" << (v.rbegin()->first == x.first ? "" : ", "); } return os; }
template <typename T> ostream &operator<<(ostream &os, queue<T> v) { if(!v.empty()) { os << v.front(); v.pop(); } while (!v.empty()) { os << " " << v.front(); v.pop(); } return os; }
template <typename T> ostream &operator<<(ostream &os, stack<T> v) { if(!v.empty()) { os << v.top(); v.pop(); } while (!v.empty()) { os << " " << v.top(); v.pop(); } return os; }
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { range(i, len(v)) { cout << v[i] << (i == len(v) ? "" : " "); } return os; }
template <typename T> ostream &operator<<(ostream &os, const deque<T> &v) { range(i, len(v)) { cout << v[i] << (i == len(v) ? "" : " "); } return os; }
template <typename T> ostream &operator<<(ostream &os, const set<T> &v) { bool is_f = true; for ( T x : v ) { os << (is_f ? "" : " ") << x; is_f = false; } return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }
struct IoSetup { IoSetup(int x = 15) { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;
using ull = unsigned long long;
using ll = long long;
using Pll = pair<ll, ll>;
using P = pair<int, int>;
constexpr ll INF64 = INT64_MAX / 2;
constexpr int INF32 = INT32_MAX / 2;
constexpr int dy[] = { 0, -1, 1, 0, -1, 1, -1, 1 };
constexpr int dx[] = { -1, 0, 0, 1, -1, -1, 1, 1 };
constexpr int mod998244353 = 998244353;
constexpr int mod1000000007 = static_cast<int>(1e9) + 7;
constexpr char newl = '\n';
// clang-format on

// }}}



int main() {
  int n,m;
  cin>>n>>m;

  vector<map<int,int>> cnts(n);
  while(1){
    int s,t,e;
    cin>>s>>t>>e;
    if(s==0 and t==0 and e==0) break;
    s--,t--;
    cnts[s][t]+=e;
  }

  int l;
  cin>>l;
  auto bs = make_vector(l,m,0LL);
  range(i,l){
    range(j,m){
      cin>>bs[i][j];
    }
  }

  range(i,l){
    auto cs = make_vector(n,0LL);
    range(j,n){
      for(auto [job,cnt]:cnts[j]){
        cs[j]+=cnt*bs[i][job];
      }
    }
    range(j,n){
      if(j) cout<<' ';
      cout<<cs[j];
    }
    cout<<newl;
    // cout<<cs<<newl;
  }
}
accuracy: 1
time_ms: 130
memory_kb: 13736
final_rank: 11

code_snippet: #include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
struct d{
  int s,t,e;
};
int main(){
  int n,m;cin>>n>>m;
  vector<d> A;
  int s,t,e;
  while(cin>>s>>t>>e,s){
    s--;t--;
    A.push_back({s,t,e});
  }
  int l;cin>>l;
  for(int i = 0; l > i; i++){
    vector<int> C(m);
    vector<int> ret(n);
    for(int j = 0; m > j; j++){
      cin>>C[j];
    }
    for(int j = 0; A.size() > j; j++){
      ret[A[j].s] += C[A[j].t]*A[j].e;
    }
    for(int j = 0; n > j; j++){
      cout << ret[j];
      if(j+1 != n)cout << " ";
    }
    cout << endl;
  }

}
accuracy: 1
time_ms: 170
memory_kb: 4008
final_rank: 6

code_snippet: #include<bits/stdc++.h>
#define rep(i,a,...) for(int i = (a)*(strlen(#__VA_ARGS__)!=0);i<(int)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i)
#define per(i,a,...) for(int i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(int)(strlen(#__VA_ARGS__)?(a):0);--i)
#define foreach(i, n) for(auto &i:(n))
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
#define lambda(RES_TYPE, ...) (function<RES_TYPE(__VA_ARGS__)>)[&](__VA_ARGS__) -> RES_TYPE
#define method(FUNC_NAME, RES_TYPE, ...) function<RES_TYPE(__VA_ARGS__)> FUNC_NAME = lambda(RES_TYPE, __VA_ARGS__)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}
#ifdef DEBUG
#define debug(x) cout<<"LINE "<<__LINE__<<": "<<#x<<" = "<<x<<endl;
#else
#define debug(x) (void)0
#endif

namespace templates{
    ll modpow(ll x, ll b,ll mod=MOD){
        ll res = 1;
        while(b){
            if(b&1)res = res * x % mod;
            x = x * x % mod;
            b>>=1;
        }
        return res;
    }

    ll modinv(ll x){
        return modpow(x, MOD-2);
    }

    bool was_output = false;

    void print();
    template <class t> void print(const vector<t> &);
    template <class t, class u> void print(const pair<t, u> &);
    template <class t> void print(const t&);
    template <class Head, class... Tail> void print(const Head&, const Tail&...);

    template <class t> void println(const vector<vector<t>>&);
    template <class t> void println(const vector<t>&);
    template <class t> void println(const t&);
    template <class Head, class... Tail> void println(const Head&, const Tail&...);
    void println();
    void newline();

    void print(){
        return;
    }

    template <class t>
    void print(const vector<t>&x){
        for(const t&i:x)print(i);
    }
    template <class t, class u>
    void print(const pair<t,u>&p){
        print(p.first);
        print(p.second);
    }
    template <class t>
    void print(const t&x){
        if(was_output)cout<<" ";
        cout<<x;
        was_output = true;
    }
    template <class Head, class... Tail>
    void print(const Head&head,const Tail&...tail){
        print(head);
        print(tail...);
    }

    template<class t>
    void println(const vector<vector<t>>&x){
        for(vector<t> i:x)println(i);
    }
    template<class t>
    void println(const vector<t>&x){
        for(const t&i:x)print(i);
        println();
    }
    template <class t>
    void println(const t&x){
        print(x);
        println();
    }
    void println(){
        if(was_output){
            cout << endl;
            was_output = false;
        }
    }
    template <class Head, class... Tail>
    void println(const Head&head,const Tail&...tail){
        print(head);
        println(tail...);
    }

    void newline(){
        was_output = true;
        println();
    }

    template<class t>
    istream& operator>>(istream&is, vector<t>&x){
        for(auto &i:x)is >> i;
        return is;
    }

    template<class t, class u>
    istream& operator>>(istream&is, pair<t, u>&x){
        is >> x.first >> x.second;
        return is;
    }

    template<class t>
    ostream& operator<<(ostream&os, vector<t> &v){
        os << "{";
        for(t &i:v){
            os << i << ", ";
        }
        os << "}";
        return os;
    }

    template<class t = long long>
    t in(){
        t res; cin >> res; return res;
    }

    template<class t>
    vector<t> sorted(vector<t> line,function<bool(t,t)> comp=[](t a,t b){return a<b;}){
        sort(line.begin(),line.end(),comp);
        return line;
    }

    template<class t>
    vector<t> reversed(vector<t> line){
        reverse(line.begin(),line.end());
        return line;
    }
    string reversed(string str){
        reverse(str.begin(),str.end());
        return str;
    }

    long long gcd(long long a,long long b){
        while(b){
            a %= b;
            swap(a,b);
        }
        return a;
    }

    long long lcm(long long a,long long b){
        return a / gcd(a,b) * b;
    }

    class output_initializer{
    public:
        output_initializer(){
            ios::sync_with_stdio(false);
            cin.tie(nullptr);
            cout << setprecision(20);
        }
    };output_initializer OUTPUT_INITIALIZER_INSTANCE = output_initializer();
}

using namespace templates;

vvector<ll> func(){
    int n =in();
    int m=in();
    map<pii,ll> di;
    while(true){
        int i=in();
        int j=in();
        ll v = in();
        if(max<ll>({i,j,v})==0)break;
        di[pii(i-1,j-1)] = v;
    }
    vvector<ll> res;
    int l = in();
    rep(_,l){
        vector<ll> money(m);
        foreach(i,money)i=in();
        vector<ll> add(n,0);
        foreach(i,di){
            add[i.first.first] += money[i.first.second] * i.second;
        }
        res.emplace_back(add);
    }
    return res;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    println(func());
    return 0;
}
accuracy: 1
time_ms: 160
memory_kb: 14160
final_rank: 14

code_snippet: #include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<list>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<iomanip>
#include<regex>
#include<random>
using namespace std;
#define int long long
#define uint unsigned long long
const int mod=1e9+7;
const int inf=mod*mod;
const double eps=1e-9;
signed main(){
	int n,m,s,t,e,l,b[10000];
	map<int,int>mp[10000];
	cin>>n>>m;
	while(cin>>s>>t>>e,e)
		mp[--s][--t]+=e;
	cin>>l;
	for(int i=0;i<l;i++){
		for(int j=0;j<m;j++)
			cin>>b[j];
		for(int j=0;j<n;j++){
			int ans=0;
			for(auto x:mp[j])
				ans+=b[x.first]*x.second;
			cout<<ans<<(j==n-1?'\n':' ');
		}
	}
}
accuracy: 1
time_ms: 230
memory_kb: 7032
final_rank: 13

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
    int n,m;
    cin >> n >> m;
    vector<int> a,b,c;
    while(1){
        int ai,bi,ci;
        cin >> ai >> bi >> ci;
        if(ci == 0) break;
        a.push_back(ai-1);
        b.push_back(bi-1);
        c.push_back(ci);
    }
    int l;
    cin >> l;
    for(int i=0; i<l; i++){
        vector<int> t(m);
        for(int i=0; i<m; i++){
            cin >> t[i];
        }
        vector<int> ans(n, 0);
        for(int i=0; i<(int)a.size(); i++){
            ans[a[i]] += c[i]*t[b[i]];
        }
        for(int i=0; i<n-1; i++){
            cout << ans[i] << " ";
        }
        cout << ans.back() << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 170
memory_kb: 3900
final_rank: 5

code_snippet: #include <iostream>
#include <map>
using namespace std;

int main(void){
  int N,M;
  cin>>N>>M;
  map<int,int> * A = new map<int,int>  [N];
  for(int i=0;i<N;i++){
    map<int, int> d;
    A[i] = d;
  }
  unsigned short s,t,e;
  while(cin>>s>>t>>e){
    if(s==0 and t==0 and e==0)break;
    A[s-1][t-1]=e;
  }
  int L;
  cin>>L;
  for(int _=0;_<L;_++){
    int* b = new int[M];
    for(int i=0;i<M;i++){
      cin>>b[i];
    }
    for(int i=0;i<N;i++){
      long c=0;
      for(auto iter=A[i].begin();iter!=A[i].end();iter++){
        auto key = iter->first;
        auto value = iter->second;
        c+=(long)value * (long)b[key];
      }
      if(i<N-1){
        cout<<c<<" ";
      }
      else{
        cout<<c<<endl;
      }
    }
  }
  return 0;
}
accuracy: 1
time_ms: 230
memory_kb: 10016
final_rank: 16

code_snippet: #include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
#define mod 1000000007
#define ad(a,b) a=(a+b)%mod;
#define X 5010
ll po(ll x,ll y){
	ll res=1;
	for(;y;y>>=1){
		if(y&1)res=res*x%mod;
		x=x*x%mod;
	}
	return res;
}
ll fac[X],ivf[X];
void init(){
	fac[0]=1;
	for(ll i=1;i<X;i++)fac[i]=fac[i-1]*i%mod;
	for(ll i=0;i<X;i++)ivf[i]=po(fac[i],mod-2);
}
ll C(ll n,ll k){
	return fac[n]*ivf[n-k]%mod*ivf[k]%mod;
}
int main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	ll n,m;
	vector<ll> typ[10010],cnt[10010];
	cin>>n>>m;
	while(1){
		ll s,t,e;
		cin>>s>>t>>e;
		if(s==0&&t==0&&e==0)break;
		typ[s].push_back(t);
		cnt[s].push_back(e);
	}
	ll l;
	cin>>l;
	while(l--){
		ll b[10010];
		for(int i=1;i<=m;i++)cin>>b[i];
		for(int i=1;i<=n;i++){
			if(i>1)cout<<" ";
			ll ans=0;
			rep(j,typ[i].size()){
				ans+=b[typ[i][j]]*cnt[i][j];
			}
			cout<<ans;
		}
		cout<<endl;
	}
}
accuracy: 1
time_ms: 110
memory_kb: 5248
final_rank: 3

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int i=(a);i<(n);++i)
#define eFOR(i,a,n) for(int i=(a);i<=(n);++i)
#define rFOR(i,a,n) for(int i=(n)-1;i>=(a);--i)
#define erFOR(i,a,n) for(int i=(n);i>=(a);--i)
#define each(i, a) for(auto &i : a)
#define SORT(a) sort(a.begin(),a.end())
#define rSORT(a) sort(a.rbegin(),a.rend())
#define fSORT(a,f) sort(a.begin(),a.end(),f)
#define all(a) a.begin(),a.end()
#define out(y,x) ((y)<0||h<=(y)||(x)<0||w<=(x))
#define tp(a,i) get<i>(a)
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define elif else if
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }
template<class T>inline void print(const T& a) { cout << a << "\n"; }
template<class T, class... Ts>inline void print(const T& a, const Ts&... ts) { cout << a << " "; print(ts...); }
template<class T>inline void print(const vector<T>& v) { for (int i = 0; i < v.size(); ++i)cout << v[i] << (i == v.size() - 1 ? "\n" : " "); }
template<class T>inline void print(const vector<vector<T>>& v) { for (auto& a : v)print(a); }
inline string reversed(const string& s) { string t = s; reverse(all(t)); return t; }

int main() {
    init();

    int n, m; cin >> n >> m;
    VI s, t, e;
    for (int x, y, z; cin >> x >> y >> z && x != 0;) {
        s.push_back(x - 1);
        t.push_back(y - 1);
        e.push_back(z);
    }
    int l; cin >> l;
    FOR(_, 0, l) {
        VI b(m); cin >> b;
        VI ans(n);
        FOR(j, 0, s.size())
            ans[s[j]] += b[t[j]] * e[j];
        print(ans);
    }

    return 0;
}
accuracy: 1
time_ms: 90
memory_kb: 3708
final_rank: 1

code_snippet: #include<string.h>
#include<iostream>
#include<string>
#include <vector>
#include<algorithm>
#include<map>

using namespace std;

int main()
{
	int N, M;
	cin >> N >> M;
	int s, t, e;
	map<pair<int, int>, int> c;
	cin >> s >> t >> e;
	while (s)
	{
		c[make_pair(s, t)] += e;
		cin >> s >> t >> e;
	}
	int L;
	cin >> L;
	int* b = new int[M + 1];
	for (int i = 0; i < L; i++)
	{
		for (int j = 1; j <= M; j++)
			cin >> b[j];
		int* rets = new int[N + 1];
		fill(rets, rets + N + 1, 0);
		for (auto p : c)
		{
			int _s = p.first.first;
			int _t = p.first.second;
			int _e = p.second;
			rets[_s] += b[_t] * _e;
		}
		cout << rets[1];
		for (int i = 2; i <= N; i++)
			cout << " " << rets[i];
		cout << endl;
	}
	//
	//cin >> N;
}
accuracy: 1
time_ms: 300
memory_kb: 10168
final_rank: 19