Language: C++

#include <bits/stdc++.h>


using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)

typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 1 << 30;
const ll INFL = 1LL << 60;
const ll mod = 1000000007;




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

	VI a(n), b(n), c(n - 1);
	REP(i, n)cin >> a[i], a[i]--;
	REP(i, n)cin >> b[i];
	REP(i, n - 1)cin >> c[i];

	int ans = 0;

	REP(i, n) {
		ans += b[a[i]];
		if (i != 0 && a[i] == a[i - 1] + 1)ans += c[a[i - 1]];
	}


	cout << ans << endl;

}#include <bits/stdc++.h>


using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)

typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 1 << 30;
const ll INFL = 1LL << 60;
const ll mod = 1000000007;




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

	VI a(n), b(n), c(n - 1);
	REP(i, n)cin >> a[i], a[i]--;
	REP(i, n)cin >> b[i];
	REP(i, n - 1)cin >> c[i];

	int ans = 0;

	REP(i, n) {
		ans += b[a[i]];
		if (i != 0 && a[i] == a[i - 1] + 1)ans += c[a[i - 1]];
	}


	cout << ans << endl;

}#include <bits/stdc++.h>


using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)

typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 1 << 30;
const ll INFL = 1LL << 60;
const ll mod = 1000000007;




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

	VI a(n), b(n), c(n - 1);
	REP(i, n)cin >> a[i], a[i]--;
	REP(i, n)cin >> b[i];
	REP(i, n - 1)cin >> c[i];

	int ans = 0;

	REP(i, n) {
		ans += b[a[i]];
		if (i != 0 && a[i] == a[i - 1] + 1)ans += c[a[i - 1]];
	}


	cout << ans << endl;

}

Compiler output:
a.cc:49:2: error: stray '#' in program
   49 | }#include <bits/stdc++.h>
      |  ^
a.cc:97:2: error: stray '#' in program
   97 | }#include <bits/stdc++.h>
      |  ^
a.cc:49:3: error: 'include' does not name a type
   49 | }#include <bits/stdc++.h>
      |   ^~~~~~~
a.cc:69:24: error: redefinition of 'template<class T> bool chmax(T&, T)'
   69 | template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
      |                        ^~~~~
a.cc:21:24: note: 'template<class T> bool chmax(T&, T)' previously declared here
   21 | template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
      |                        ^~~~~
a.cc:70:24: error: redefinition of 'template<class T> bool chmin(T&, T)'
   70 | template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
      |                        ^~~~~
a.cc:22:24: note: 'template<class T> bool chmin(T&, T)' previously declared here
   22 | template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
      |                        ^~~~~
a.cc:71:12: error: redefinition of 'const int INF'
   71 | const int  INF = 1 << 30;
      |            ^~~
a.cc:23:12: note: 'const int INF' previously defined here
   23 | const int  INF = 1 << 30;
      |            ^~~
a.cc:72:10: error: redefinition of 'const ll INFL'
   72 | const ll INFL = 1LL << 60;
      |          ^~~~
a.cc:24:10: note: 'const ll INFL' previously defined here
   24 | const ll INFL = 1LL << 60;
      |          ^~~~
a.cc:73:10: error: redefinition of 'const ll mod'
   73 | const ll mod = 1000000007;
      |          ^~~
a.cc:25:10: note: 'const ll mod' previously defined here
   25 | const ll mod = 1000000007;
      |          ^~~
a.cc:78:5: error: redefinition of 'int main()'
   78 | int main() {
      |     ^~~~
a.cc:30:5: note: 'int main()' previously defined here
   30 | int main() {
      |     ^~~~
a.cc:97:3: error: 'include' does not name a type
   97 | }#include <bits/stdc++.h>
      |   ^~~~~~~
a.cc:117:24: error: redefinition of 'template<class T> bool chmax(T&, T)'
  117 | template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
      |                        ^~~~~
a.cc:21:24: note: 'template<class T> bool chmax(T&, T)' previously declared here
   21 | template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
      |                        ^~~~~
a.cc:118:24: error: redefinition of 'template<class T> bool chmin(T&, T)'
  118 | template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
      |                        ^~~~~
a.cc:22:24: note: 'template<class T> bool chmin(T&, T)' previously declared here
   22 | template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
      |                        ^~~~~
a.cc:119:12: error: redefinition of 'const int INF'
  119 | const int  INF = 1 << 30;
      |            ^~~
a.cc:23:12: note: 'const int INF' previously defined here
   23 | const int  INF = 1 << 30;
      |            ^~~
a.cc:120:10: error: redefinition of 'const ll INFL'
  120 | const ll INFL = 1LL << 60;
      |          ^~~~
a.cc:24:10: note: 'const ll INFL' previously defined here
   24 | const ll INFL = 1LL << 60;
      |          ^~~~
a.cc:121:10: error: redefinition of 'const ll mod'
  121 | const ll mod = 1000000007;
      |          ^~~
a.cc:25:10: note: 'const ll mod' previously defined here
   25 | const ll mod = 1000000007;
      |          ^~~
a.cc:126:5: error: redefinition of 'int main()'
  126 | int main() {
      |     ^~~~
a.cc:30:5: note: 'int main()' previously defined here
   30 | int main() {
      |     ^~~~