Language: C++

/**
SXR0aXAkI0JwbXptI3FhI3Z3I293bCNqY2IjUG0jMCNicG0jVHFkcXZvLyNCcG0jQW10bjBhY2phcWFicXZvLyNNYm16dml0MSNWdyNhdGN1am16I2tpdiNhbXF9bSNQcXUjVnd6I0F0bW14MSNQcWEjaXptI2l0dCNicHF2b2EjUXYjYnBtI3BtaWRtdmEjaXZsI3d2I21pemJwMSNFcHcjcWEjYnBtem0ja2l2I3F2Ym16a21sbSNRdiNQcWEjeHptYW12a20jbXtrbXhiI0lhI3BtI3htenVxYmJtYnBHI1BtI3N2d2VtYnAjRXBpYiMraXh4bWl6bWJwI2J3I1BxYSNrem1pYmN6bWEjSWEsI0ptbnd6bSN3eiNJbmJteiN3eiNKbXBxdmwjYnBtdTEjVnd6I2FwaXR0I2JwbXwja3d1eGlhYSNJY29wYiN3biNwcWEjc3Z3ZXRtbG9tI017a214YiNpYSNQbSNlcXR0bWJwMSNQcWEjYnB6d3ZtI2x3YnAjbXtibXZsI1dkbXojYnBtI3BtaWRtdmEjSXZsI3d2I21pemJwLyNpdmwjUG0jbm1tdG1icCNWdyNuaWJxb2NtI3F2I29jaXpscXZvI0l2bCN4em1hbXpkcXZvI2JwbXUvI053eiNQbSNxYSNicG0jVXdhYiNQcW9wMSNCcG0jQWN4em11bSMrcXYjb3R3enwsMQ==
*/
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>

#define F first
#define S second
#define endl '\n'
#define deb(x) cout<<#x<<' '<<x<<endl;
#define pb push_back


#ifdef IZI_KATKA
#define int __int64_t
#else
#define int __int64
#endif

const long long MOD = 1e9 + 7;
const long long MAXN = 1e6 + 1;
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;


long long readInt() {
    bool minus1 = false;
    long long result = 0;
    char ch;
    ch = getchar();
    while (true) {
        if (ch == '-') break;
        if (ch >= '0' && ch <= '9') break;
        ch = getchar();
    }
    if (ch == '-') minus1 = true; else result = ch-'0';
    while (true) {
        ch = getchar();
        if (ch < '0' || ch > '9') break;
        result = result*10 + (ch - '0');
    }
    if (minus1)
        return -result;
    else
        return result;
}

int a[MAXN];
int b[MAXN];
vector <int> v[MAXN];

int dp[229];
int n;

bool check(ll mask) {
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j <= 50; j++) {
			dp[j] = 0;
		}	
		dp[a[i]] = 1;
		for (int j = 50; j > 0; j--) {
			if (((mask >> j) & 1) == 0) continue;
			for (int k = 50; k >= 0; k--) {
				dp[k % j] |= dp[k];
			}
		}
		if (!dp[b[i]]) {
			return false;		
		}
	}
	return true;
}

 main() {
	#ifdef IZI_KATKA
	assert(freopen("input", "r", stdin));
    assert(freopen("output", "w", stdout));
    #endif
    n = readInt();
    for (int i = 1; i <= n; i++) {
		a[i] = readInt();
    }
    for (int i = 1; i <= n; i++) {
    	b[i] = readInt();
    }
    ll mask = (1ll << 51) - 2;
	if (!check(mask)) {
		cout << -1;
		return 0;
	}
	for (int i = 50; i >= 1; i--) {
		mask ^= (1ll << i);
		if (!check(mask)) {
			mask ^= (1ll << i);
		}
	}
	cout << mask;
    return 0;
}

Compiler output:
a.cc:36:13: error: '__int64' was not declared in this scope; did you mean '__ynf64'?
   36 | #define int __int64
      |             ^~~~~~~
a.cc:44:14: note: in expansion of macro 'int'
   44 | typedef pair<int, int> pii;
      |              ^~~
a.cc:36:13: error: '__int64' was not declared in this scope; did you mean '__ynf64'?
   36 | #define int __int64
      |             ^~~~~~~
a.cc:44:19: note: in expansion of macro 'int'
   44 | typedef pair<int, int> pii;
      |                   ^~~
a.cc:44:22: error: template argument 1 is invalid
   44 | typedef pair<int, int> pii;
      |                      ^
a.cc:44:22: error: template argument 2 is invalid
a.cc:36:13: error: '__int64' does not name a type; did you mean '__int64_t'?
   36 | #define int __int64
      |             ^~~~~~~
a.cc:69:1: note: in expansion of macro 'int'
   69 | int a[MAXN];
      | ^~~
a.cc:36:13: error: '__int64' does not name a type; did you mean '__int64_t'?
   36 | #define int __int64
      |             ^~~~~~~
a.cc:70:1: note: in expansion of macro 'int'
   70 | int b[MAXN];
      | ^~~
a.cc:36:13: error: '__int64' was not declared in this scope; did you mean '__ynf64'?
   36 | #define int __int64
      |             ^~~~~~~
a.cc:71:9: note: in expansion of macro 'int'
   71 | vector <int> v[MAXN];
      |         ^~~
a.cc:71:12: error: template argument 1 is invalid
   71 | vector <int> v[MAXN];
      |            ^
a.cc:71:12: error: template argument 2 is invalid
a.cc:36:13: error: '__int64' does not name a type; did you mean '__int64_t'?
   36 | #define int __int64
      |             ^~~~~~~
a.cc:73:1: note: in expansion of macro 'int'
   73 | int dp[229];
      | ^~~
a.cc:36:13: error: '__int64' does not name a type; did you mean '__int64_t'?
   36 | #define int __int64
      |             ^~~~~~~
a.cc:74:1: note: in expansion of macro 'int'
   74 | int n;
      | ^~~
a.cc: In function 'bool check(ll)':
a.cc:36:13: error: '__int64' was not declared in this scope; did you mean '__ynf64'?
   36 | #define int __int64
      |             ^~~~~~~
a.cc:77:14: note: in expansion of macro 'int'
   77 |         for (int i = 1; i <= n; i++) {
      |              ^~~
a.cc:77:25: error: 'i' was not declared in this scope
   77 |         for (int i = 1; i <= n; i++) {
      |                         ^
a.cc:77:30: error: 'n' was not declared in this scope; did you mean 'yn'?
   77 |         for (int i = 1; i <= n; i++) {
      |                              ^
      |                              yn
a.cc:78:26: error: expected ';' before 'j'
   78 |                 for (int j = 0; j <= 50; j++) {
      |                          ^
a.cc:78:33: error: 'j' was not declared in this scope
   78 |                 for (int j = 0; j <= 50; j++) {
      |                                 ^
a.cc:79:25: error: 'dp' was not declared in this scope
   79 |                         dp[j] = 0;
      |                         ^~
a.cc:81:17: error: 'dp' was not declared in this scope
   81 |                 dp[a[i]] = 1;
      |                 ^~
a.cc:81:20: error: 'a' was not declared in this scope
   81 |                 dp[a[i]] = 1;
      |                    ^
a.cc:82:26: error: expected ';' before 'j'
   82 |                 for (int j = 50; j > 0; j--) {
      |                          ^
a.cc:82:34: error: 'j' was not declared in this scope
   82 |                 for (int j = 50; j > 0; j--) {
      |                                  ^
a.cc:84:34: error: expected ';' before 'k'
   84 |                         for (int k = 50; k >= 0; k--) {
      |                                  ^
a.cc:84:42: error: 'k' was not declared in this scope
   84 |                         for (int k = 50; k >= 0; k--) {
      |                                          ^
a.cc:88:25: error: 'b' was not declared in this scope
   88 |                 if (!dp[b[i]]) {
      |                         ^
a.cc: At global scope:
a.cc:95:2: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   95 |  main() {
      |  ^~~~
a.cc: In function 'int main()':
a.cc:100:5: error: 'n' was not declared in this scope; did you mean 'yn'?
  100 |     n = readInt();
      |     ^
      |     yn
a.cc:36:13: error: '__int64' was not declared in this scope; did you mean '__ynf64'?
   36 | #define int __int64
      |             ^~~~~~~
a.cc:101:10: note: in expansion of macro 'int'
  101 |     for (int i = 1; i <= n; i++) {
      |          ^~~
a.cc:101:21: error: 'i' was not declared in this scope
  101 |     for (int i = 1; i <= n; i++) {
      |                     ^
a.cc:102:17: error: 'a' was not declared in this scope
  102 |                 a[i] = readInt();
      |                 ^
a.cc:36:13: error: '__int64' was not declared in this scope; did you mean '__ynf64'?
   36 | #define int __int64
      |             ^~~~~~~
a.cc:104:10: note: in expansion of macro 'int'
  104 |     for (int i = 1; i <= n; i++) {
      |          ^~~
a.cc:104:21: error: 'i' was not declared in this scope
  104 |     for (int i = 1; i <= n; i++) {
      |                     ^
a.cc:105:9: error: 'b' was not declared in this scope
  105 |         b[i] = readInt();
      |         ^
a.cc:36:13: error: '__int64' was not declared in this scope; did you mean '__ynf64'?
   36 | #define int __int64
      |             ^~~~~~~
a.cc:112:14: note: in expansion of macro 'int'
  112 |         for (int i = 50; i >= 1; i--) {
      |              ^~~
a.cc:112:26: error: 'i' was not declared in this scope
  112 |         for (int i = 50; i >= 1; i--) {
      |                          ^