#include <iostream>
#include <fstream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <unordered_set>
#include <cassert>
using namespace std;
const string password = "e87d6a039dcd0c2c66437ed0def1339bf6ed5c5cabe0ab87fd0fc8511352acf8";
void output_message(double points, string message){
	cout << points << endl;
	if(message.size())cerr << message << endl;
	exit(0);
}

int main (int argc, char** argv) {
	if(argc < 4){ output_message(0, "Insufficient arguments!"); return 1; }
	fstream input(argv[1]), output(argv[2]), contestant(argv[3]);
	if(!input.is_open()){ output_message(0, "Couldn't open input file."); return 1; }
	if(!output.is_open()){ output_message(0, "Couldn't open output file."); return 1; }
	if(!contestant.is_open()){ output_message(0, "Couldn't open contestant file."); return 1; }
	string check;
	contestant >> check;
	if(check != password){ output_message(0, "Contestant wrote to cout."); return 1; }
	
	long long t,n;
	vector<long long> a;
	input >> t;
	if(t==-8) {
		input >> n;
		long long x=0;
		while(input >> x) a.push_back(x);
		assert(n==a.size());
		vector<long long> res;
		unordered_set<long long> s;
		long long ans=0,br=0;
		while(contestant >> x) {
			br++;
			if(x<0||x>n-1) {
				cout << 0 << endl;
				cerr << "Invalid index on subtask 8!" << endl;
				return 0;
			}
			s.insert(x);
			ans+=a[x];
		}
		if(s.size()!=br) {
			cout << 0 << endl;
			cerr << "Duplicate index on subtask 8!" << endl;
			return 0;
		}
		if(br==0) {
			cout << 0 << endl;
			return 0;
		}
		if(ans%n!=0) {
			cout << 0 << endl;
			return 0;
		}
		cout << 1 << endl;
		return 0;
	}
	
	long long res;
    if(!(contestant >> res)) output_message(0, "");
    long long correct;
    output >> correct;
	
    cout << (res==correct) << endl;
	exit(0);
	return 0;
}
