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

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
int main()
{
  int d;
  cin >> d;
  vector<int> c(26);
  int i,j;
  rep(i,26) cin >> c[i];
  vector<vector<int>> s(d,vector<int>(26));
  rep(i,d)rep(j,26) cin >> s[i][j]; 
  vector<int> t(d);
  rep(i,d)
  {
    cin >> t[i];
    t[i]--;
  }
  vector<int> las(26,0);
  int kans = 0;
  rep(i,d)
  {
    las[t[i]] = i+1;
    kans += s[i][t[i]];
    rep(j,26)
    {
      kans -= c[j]*(i+1-las[j]);
    }
    cout << kans << "\n";
  }
}
