Language: C++

//#define NDEBUG
#define _CRT_SECURE_NO_WARNINGS
#include <cassert>
#include <cstdint>
#include <utility>
#include <vector>

class UnionFind {

public:
	using size_type = std::uint_fast32_t;

private:
	std::vector<std::pair<bool, size_type>> tree;

public:
	UnionFind(const size_type size) : tree(size, std::make_pair(1, 1)) {}
	size_type find(const size_type x) {
		assert(x < tree.size());
		if (tree[x].first)
			return x;
		return tree[x].second = find(tree[x].second);
	}
	bool unite(size_type x, size_type y) {
		assert(x < tree.size());
		assert(y < tree.size());
		x = find(x);
		y = find(y);
		if (x == y)
			return false;
		if (tree[x].second < tree[y].second)
			std::swap(x, y);
		tree[x].second += tree[y].second;
		tree[y] = std::make_pair(0, x);
		return true;
	}
	bool same(const size_type x, const size_type y) {
		assert(x < tree.size());
		assert(y < tree.size());
		return find(x) == find(y);
	}
	size_type size(const size_type x) {
		assert(x < tree.size());
		return tree[find(x)].second;
	}
};
#include <algorithm>
#include <array>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <limits>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <type_traits>
#include <utility>
#include <vector>
constexpr double PI = 3.1415926535897932;

using int32 = std::int_fast32_t;
using int64 = std::int_fast64_t;
using uint32 = std::uint_fast32_t;
using uint64 = std::uint_fast64_t;
using intl32 = std::int_least32_t;
using intl64 = std::int_least64_t;
using uintl32 = std::uint_least32_t;
using uintl64 = std::uint_least64_t;

const char *yes(bool c) { return c ? "yes" : "no"; }
const char *Yes(bool c) { return c ? "Yes" : "No"; }
const char *YES(bool c) { return c ? "YES" : "NO"; }
const char *pos(bool c) { return c ? "possible" : "impossible"; }
const char *Pos(bool c) { return c ? "Possible" : "Impossible"; }
const char *POS(bool c) { return c ? "POSSIBLE" : "IMPOSSIBLE"; }
template<class T>bool bmaxi(T&a, const T&b) { if (b < a)return 0;a = b;return 1; }
template<class T>bool bmini(T&a, const T&b) { if (a < b)return 0;a = b;return 1; }
template<class T>bool nmaxi(T&a, const T&b) { if (a < b) { a = b;return 1; }return 0; }
template<class T>bool nmini(T&a, const T&b) { if (b < a) { a = b;return 1; }return 0; }
template<typename T>auto scan(T&d)->typename std::enable_if<std::is_signed<T>::value>::type
{
	d = 0;int c = fgetc(stdin);bool f = 0;while (c < '0' || '9' < c) { if (c == '-')f = 1;c = fgetc(stdin); }
	while (c != ' '&&c != '\n') { d = d * 10 + c - '0';c = fgetc(stdin); }if (f)d = -d;
}
template<typename T>auto scan(T&d)->typename std::enable_if<!std::is_signed<T>::value>::type
{
	d = 0;int c = fgetc(stdin);while (c == ' ' || c == '\n')c = fgetc(stdin);
	while (c != ' '&&c != '\n') { d = d * 10 + c - '0';c = fgetc(stdin); }
}
void scan(char&d) { d = fgetc(stdin);while (d == ' ' || d == '\n')d = fgetc(stdin); }
void scan(double&d) { scanf("%lf", &d); }void scan(std::string&d) {
	d.clear();int c = fgetc(stdin);
	while (c == ' ' || c == '\n')c = fgetc(stdin);while (c != ' '&&c != '\n') { d.push_back(c);c = fgetc(stdin); }
}
template<typename F, typename...R>void scan(F&f, R&...r) { scan(f);scan(r...); }
template<typename T>T input() { T d;scan(d);return d; }
template <typename T>auto print(T d)->typename std::enable_if<std::is_signed<T>::value>::type
{
	static int c[20];int i = 0;bool f = 0;if (d < 0) { f = 1;d = -d; }while (d) { c[i++] = d % 10;d /= 10; }
	if (!i)c[i++] = 0;if (f)fputc('-', stdout);while (i--)fputc(c[i] + '0', stdout);
}
template<typename T>auto print(T d)->typename std::enable_if<!std::is_signed<T>::value>::type
{
	static int c[20];int i = 0;while (d) { c[i++] = d % 10;d /= 10; }
	if (!i)c[i++] = 0;while (i--)fputc(c[i] + '0', stdout);
}
template<>void print<char>(char d) { fputc(d, stdout); }
template<>void print<double>(double d) { printf("%f", d); }
void print(const char *c) { while (*c != '\0')fputc(*(c++), stdout); }void print() {}
template<typename F, typename...R>void print(F f, R...r) { print(f);print(r...); }
template<typename...R>void println(R...r) { print(r...);fputc('\n', stdout); }
template<typename...R>int END(R...r) { println(r...);return 0; }
uint32 G[51][51];
bool r[51];
bool able(const uint32 a, const uint32 b,const uint32 not) {
	if (a == b)return true;
	r[a] = 1;
	for (uint32 i = 1;i <=50;++i) {
		if (i == not)continue;
		if (r[G[a][i]])continue;
		if (able(G[a][i], b, not)) return true;
	}
	return false;
}
int main(void) {
	const auto n = input<uint32>();
	std::vector<uint32> a(n), b(n);
	for (auto &x : a)scan(x);
	for (auto &x : b)scan(x);
	{
		bool f = 0;
		for (uint32 i = 0;i < n;++i) {
			if (a[i]!=b[i]&&a[i] <= b[i]*2) f = 1;
		}
		if (f)return END("-1");
	}
	std::vector<uint32> use;
	for (uint32 i = 0;i <= 50;++i) {
		for (uint32 j = 1;j <= 50;++j) {
			G[i][j] = i % j;
		}
	}
	for (uint32 i = 50;i;--i) {
		bool f = 0;
		for (uint32 j = 0;j < n;++j) {
			for (auto &x : r)x = 0;
			if (!able(a[j], b[j], i))f = 1;
		}
		if (f)use.push_back(i);
		else {
			for (uint32 j = 0;j <= 50;++j)
				G[j][i] = j;
		}
	}
	uint64 ans = 0;
	for (const auto x : use) {
		ans += (uint64)1 << x;
	}
	println(ans);
	return 0;
}

Compiler output:
a.cc:124:55: error: expected ',' or '...' before 'not' token
  124 | bool able(const uint32 a, const uint32 b,const uint32 not) {
      |                                                       ^~~
a.cc: In function 'bool able(uint32, uint32, uint32)':
a.cc:128:29: error: expected primary-expression before ')' token
  128 |                 if (i == not)continue;
      |                             ^
a.cc:130:41: error: expected primary-expression before ')' token
  130 |                 if (able(G[a][i], b, not)) return true;
      |                                         ^