Problem:
Score : 500 points

Problem Statement

In CODE FESTIVAL XXXX, there are N+1 participants from all over the world, including Takahashi.

Takahashi checked and found that the time gap (defined below) between the local times in his city and the i-th person's city was D_i hours.
The time gap between two cities is defined as follows. For two cities A and B, if the local time in city B is d o'clock at the moment when the local time in city A is 0 o'clock, then the time gap between these two cities is defined to be min(d,24-d) hours.
Here, we are using 24-hour notation.
That is, the local time in the i-th person's city is either d o'clock or 24-d o'clock at the moment when the local time in Takahashi's city is 0 o'clock, for example.

Then, for each pair of two people chosen from the N+1 people, he wrote out the time gap between their cities. Let the smallest time gap among them be s hours.

Find the maximum possible value of s.

Constraints

1 \leq N \leq 50

0 \leq D_i \leq 12

All input values are integers.

Input

Input is given from Standard Input in the following format:

N
D_1 D_2 ... D_N

Output

Print the maximum possible value of s.

Sample Input 1

3
7 12 8

Sample Output 1

4

For example, consider the situation where it is 7, 12 and 16 o'clock in each person's city at the moment when it is 0 o'clock in Takahashi's city. In this case, the time gap between the second and third persons' cities is 4 hours.

Sample Input 2

2
11 11

Sample Output 2

2

Sample Input 3

1
0

Sample Output 3

0

Note that Takahashi himself is also a participant.

Solution in C++ (GCC 9.2.1) (judge verdict: Accepted)

#pragma GCC diagnostic ignored "-Wunused-variable" 
#include <bits/stdc++.h>
using namespace std;

#define BOOST
#ifdef BOOST
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
using namespace boost;
using ml = multiprecision::cpp_int;
using md = multiprecision::cpp_dec_float_100;
#endif

/***** type *****/
using ll = long long;
using ld = long double;
using pll = pair<long long, long long>;
template <class T> using vt = vector<T>;
template <class T> using vvt = vector<vector<T>>;
template <class T> using vvvt = vector<vector<vector<T>>>;
/***** define *****/
#define all(c) (c).begin(), (c).end()            // begin to end
#define coutld cout << fixed << setprecision(10) // cout double
#define output(x) do { cout << x << endl; exit(0); } while(0)
#define rep(i, b, e) for (ll i = b; i < e; i++)  // repeat
#define repr(i, b, e) for (ll i = b; e < i; i--) // repeat reverse
#define fori(i, ...) if (ll i = -1) for(__VA_ARGS__) if (i++, 1)
#define each(i, e, c) fori (i, auto&& e: c)      // for each
/***** const value *****/
#define llong_max 9223372036854775807            // 9 * 10^18
#define ldbl_max 1.79769e+308                    // 1.7 * 10^308
#define pi 3.1415926535897932                    // 3.14 ...
/***** lambda *****/
auto Ceil = [] // if (a % b != 0) return a / b + 1;
(auto x) { return (ll)ceil(x); };
auto Count = [] // long long count value
(auto b, auto e, auto x) { return (ll)count(b, e, x); };
auto CtoL = [] // char to number
(auto c) { return (ll)c - (ll)'0'; };
auto LtoC = [] // number to char
(auto n) { return (char)('0' + n); };
auto Pow = [] // long long pow
(auto a, auto b) { return (ll)pow(a, b); };
auto Pow2 = [] // long long pow2
(auto n) { return (1LL << n); };
auto Pow10 = [] // long long pow10
(auto n) { return (ll)pow(10, n); };
auto Size = []  // long long collection size
(auto& c) { return (ll)(c).size(); };
auto Sum = [] // long long accumulate
(auto b, auto e) { return accumulate(b, e, 0LL); };

/***** operator *****/
template <class T, class S> pair<T, S> operator + (pair<T, S> l, pair<T, S> r)
{	// pair<T, S> + pair<T, S>
	return { l.first + r.first, l.second + r.second };
}
template <class T, class S> pair<T, S> operator - (pair<T, S> l, pair<T, S> r)
{	// pair<T, S> - pair<T, S>
	return { l.first - r.first, l.second - r.second };
}

/***** template *****/
template <class T> void MakeVVT
(ll ys, ll xs, vvt<T>& v, T fill = T())
{	// vector<vector<T>> resize + fill
	v.resize(ys); rep(y, 0, ys) v[y].resize(xs, fill);
}
template <class T> void MakeVVVT
(ll zs, ll ys, ll xs, vvvt<T>& v, T fill = T())
{	// vector<vector<vector<T>>> resize + fill
	v.resize(zs); rep(z, 0, zs) MakeVVT(ys, xs, v[z], fill);
}
template <class T> void InputVVT
(ll ys, ll xs, vvt<T>& v, T fix = T())
{	// input vector<vector<T>> (T != struct) + fix
	MakeVVT(ys, xs, v, fix);
	rep(y, 0, ys) rep(x, 0, xs) { cin >> v[y][x]; v[y][x] += fix; }
}
template <class T> void InputVVVT
(ll zs, ll ys, ll xs, vvvt<T>& v, T fix = T())
{	// input vector<vector<vector<T>>> (T != struct) + fix
	v.resize(zs); rep(z, 0, zs) InputVVT(ys, xs, v[z], fix);
}

/**************************************/
/********** BEGIN OF NYA LIB **********/
/**************************************/

namespace NyaGadget {}

namespace NyaGadget
{
	/***** Bit操作ライブラリ *****/

	struct NT_NyaaBit
	{
		/**
		@brief 1になっているビットの数を取得する
		@note flipをtrueにすると0になっているビットの数を返す。
		**/
		static long long Count(long long x, bool flip = false)
		{
			long long sum = 0;
			for (auto i = 0LL; i < Size(x); ++i) sum += Test(x, i, flip);
			return sum;
		}

		/**
		@brief bit列を整数に変換する
		**/
		static long long ToLL(std::string bit)
		{
			long long res = 0;
			long long maxSize = (long long)bit.size();
			for (auto i = 0LL; i < maxSize; ++i) if (bit[i] == '1') res += (1LL << (maxSize - i - 1));
			return res;
		}

		/**
		@brief 文字列に変換する
		**/
		static std::string ToString(long long x, bool flip = false)
		{
			std::string res;
			if (!flip) for (auto i = Size(x) - 1; -1 < i; --i) res += (char)('0' + Test(x, i));
			else       for (auto i = 0LL; i < Size(x); ++i)    res += (char)('0' + Test(x, i));
			return res;
		}

		/**
		@brief 文字列に変換する
		@note maxSize桁の文字列に変換する。
		**/
		static std::string ToString(long long maxSize, long long x, bool flip = false)
		{
			std::string res;
			for (auto i = 0LL; i < (maxSize - Size(x)); i++)   res += '0';
			if (!flip) for (auto i = Size(x) - 1; -1 < i; --i) res += (char)('0' + Test(x, i));
			else       for (auto i = 0LL; i < Size(x); ++i)    res += (char)('0' + Test(x, i));
			return res;
		}

		/**
		@brief 半開区間で1になっているビットの数を取得する
		@note
		値xの半開区間[b, e)でビットが1になっている数を返す。
		flipをtrueにすると0になっているビットの数を返す。
		**/
		static long long RangeCount(long long x, long long b, long long e, bool flip = false)
		{
			long long sum = 0;
			for (auto i = b; i < e; i++) sum += Test(x, i, flip);
			return sum;
		}

		/**
		@brief nビット左シフト
		**/
		static long long Shift(long long x, long long n)
		{
			return (x << n);
		}

		/**
		@brief 値xのビットサイズを取得する
		**/
		static long long Size(long long x)
		{
			long long size = 0;
			while ((long long)(1LL << size) <= x) size++;
			return size;
		}

		/**
		@brief 任意桁のビットを取得する
		@note flipがtrueなら反転したビット値を返す。
		**/
		static long long Test(long long x, long long i, bool flip = false)
		{
			if (flip) return ((x & Shift(1, i)) != 0) ? 0 : 1;
			else return ((x & Shift(1, i)) != 0) ? 1 : 0;
		}

		/**
		@brief 任意桁のビットを10進数に変換して返す
		@note 値xのi桁目ビットを10進数に変換して返す。
		**/
		static long long To10(long long x, long long i)
		{
			return Test(x, i) * (long long)pow(2, i);
		}

		/**
		@brief ビット組み合わせテーブル
		@note
		ビットサイズN桁でm個が1となるビット列の集合を昇順で返す。
		例えばN=4,m=2なら{0011, 0101, 0110, ... 1100}を返す。
		**/
		static void CombinationTable(long long N, long long m, std::vector<std::string>& res)
		{
			if (N <= 0 || m < 0) return;

			long long c = (1LL << m) - 1;
			while (c < 1LL << N)
			{
				res.push_back(ToString(N, c));
				long long x = c & -c, y = c + x;
				c = ((c) & ~y) / x >> 1LL | y;
			}
		}

		/**
		@brief ビット組み合わせテーブル
		@note
		ビットサイズN桁でm個が1となるビット列の集合を昇順で返す。
		例えばN=4,m=2なら{3(0011), 5(0101), 6(0110), ... 12(1100)}を返す。
		計算量は不明だが、素直な実装より高速に動作する。
		**/
		static std::vector<long long> CombinationTable(long long N, long long m)
		{
			std::vector<long long> res;
			if (N <= 0 || m < 0) return res;

			long long c = (1LL << m) - 1;
			while (c < 1LL << N)
			{
				res.push_back(c);
				long long x = c & -c, y = c + x;
				c = ((c) & ~y) / x >> 1LL | y;
			}
			return res;
		}

		static std::vector<long long> LtoB(long long x, bool flip)
		{
			std::vector<long long> res;
			auto size = NT_NyaaBit::Size(x);
			for (auto i = 0LL; i < size; ++i)
			{
				if (flip && NT_NyaaBit::Test(x, i) == 1) res.push_back(i);
				else if (!flip && NT_NyaaBit::Test(x, i) == 0) res.push_back(i);
			}
			return res;
		}
	};
}

/**************************************/
/*********** END OF NYA LIB ***********/
/**************************************/

using namespace NyaGadget;
//using mll = NT_ModLL< 1000000007 >;
//using mll = ModLL< 998244353 >;

int main(void)
{
	ll N; cin >> N;
	vt<ll> D(N); each(i, e, D) cin >> e;

	map<ll, ll> freq;
	freq[0]++;
	each(i, e, D) freq[e]++;
	if (freq[0] == 2) output(0);
	rep(i, 0, 12) if (3 <= freq[i]) output(0);

	ll ans = 0;
	rep(i, 0, Pow2(12))
	{
		vt<ll> test;
		test.push_back(0);
		test.push_back(24);
		rep(j, 1, 13)
		{
			if (freq[j] == 1)
			{
				if (NT_NyaaBit::Test(i, j-1) == 1) test.push_back(24 - j), test.push_back(24 - j + 24);
				else test.push_back(j), test.push_back(j + 24);
			}
			else if (freq[j] == 2) test.push_back(j), test.push_back(24 - j), test.push_back(j + 24), test.push_back(24 - j + 24);
		}
		sort(all(test));
		ll minDiff = llong_max;
		rep(j, 1, Size(test)) minDiff = min(minDiff, test[j] - test[j - 1]);
		ans = max(ans, minDiff);
	}
	cout << ans;
	return 0;
}