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

int main(){
  int D;
  cin>>D;

  vector<int64_t> c(27,0);
  for(int i=1;i<=26;++i) cin>>c[i];

  vector<vector<int64_t>> s(D+1,vector<int64_t>(27,0));
  for(int i=1;i<=D;++i){
    for(int j=1;j<=26;++j){
      cin>>s[i][j];
    }
  }

  vector<int> t(D+1);
  for(int i=1;i<=D;++i) cin>>t[i];

  int64_t score=0;
  vector<vector<int>> last(D+1,vector<int>(27,0));

  for(int i=1;i<=D;++i){
    score += s[i][t[i]];
    for(int j=1;j<=26;++j){
      if(j!=t[i]) last[i][j]=last[i-1][j];
      else last[i][j]=i;
      score -= c[j]*(i-last[i][j]);
    }
    cout<<score<<endl;
  }

}