Problem:
Best Matched Pair
You are working for a worldwide game company as an engineer in Tokyo. This company holds an annual event for all the staff members of the company every summer. This year's event will take place in Tokyo. You will participate in the event on the side of the organizing staff. And you have been assigned to plan a recreation game which all the participants will play at the same time.
After you had thought out various ideas, you designed the rules of the game as below.
Each player is given a positive integer before the start of the game.
Each player attempts to make a pair with another player in this game, and formed pairs compete with each other by comparing the products of two integers.
Each player can change the partner any number of times before the end of the game, but cannot have two or more partners at the same time.
At the end of the game, the pair with the largest product wins the game.
In addition, regarding the given integers, the next condition must be satisfied for making a pair.
The sequence of digits obtained by considering the product of the two integers of a pair as a string must be increasing and consecutive from left to right. For example, 2, 23, and 56789 meet this condition, but 21, 334, 135 or 89012 do not.
Setting the rules as above, you noticed that multiple pairs may be the winners who have the same product depending on the situation. However, you can find out what is the largest product of two integers when a set of integers is given.
Your task is, given a set of distinct integers which will be assigned to the players, to compute the largest possible product of two integers, satisfying the rules of the game mentioned above.
Input
The input consists of a single test case formatted as follows.
$N$
$a_1$ $a_2$ ... $a_N$
The first line contains a positive integer $N$ which indicates the number of the players of the game. $N$ is an integer between 1 and 1,000. The second line has $N$ positive integers that indicate the numbers given to the players. For $i = 1, 2, ... , N - 1$, there is a space between $a_i$ and $a_{i+1}$. $a_i$ is between 1 and 10,000 for $i = 1, 2, ..., N$, and if $i \ne j$, then $a_i \ne a_j$.
Output
Print the largest possible product of the two integers satisfying the conditions for making a pair. If any two players cannot make a pair, print -1.
Sample Input 1
2
1 2
Output for the Sample Input 1
2
Sample Input 2
3
3 22 115
Output for the Sample Input 2
345
Sample Input 3
2
1 11
Output for the Sample Input 3
-1
Sample Input 4
2
5 27
Output for the Sample Input 4
-1
Sample Input 5
2
17 53
Output for the Sample Input 5
-1
Sample Input 6
10
53 43 36 96 99 2 27 86 93 23
Output for the Sample Input 6
3456

Submitted solutions:

code_snippet: // AOJ #2780 Best Matched Pair
// 2025.3.14

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)

int Cin() {  // 整数の入力
	int n = 0; int c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

void Cout(int n) { // 整数の表示（出力）
	char b[30];
	if (!n) pc('0');
	else {
		if (n < 0) pc('-'), n = -n;
		int i = 0; while (n) b[i++] = n % 10 + '0', n /= 10;
		while (i--) pc(b[i]);
	}
	pc('\n');
}

bool valid(ll p) {
    string s = to_string(p);
    if(s.size() == 1) return true;
    for (size_t i = 0; i + 1 < s.size(); i++) {
        if(s[i+1] - s[i] != 1) return false;
    }
    return true;
}

int main(){
    int n = Cin();
    vector<int> v(n);
    for (int i = 0; i < n; i++) v[i] = Cin();

    ll ans = -1;
    for (int i = 0; i < n; i++){
        for (int j = i+1; j < n; j++){
            ll p = (ll)v[i] * v[j];
            if(valid(p)) ans = max(ans, p);
        }
    }
    Cout(ans);
    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 3508
final_rank: 4

code_snippet: // AOJ #2780 Best Matched Pair
// 2025.3.14

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

bool valid(ll p) {
    string s = to_string(p);
    if(s.size() == 1) return true;
    for (size_t i = 0; i + 1 < s.size(); i++) {
        if(s[i+1] - s[i] != 1) return false;
    }
    return true;
}

int main(){
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++) cin >> v[i];

    ll ans = -1;
    for (int i = 0; i < n; i++){
        for (int j = i+1; j < n; j++){
            ll p = (ll)v[i] * v[j];
            if(valid(p)) ans = max(ans, p);
        }
    }
    cout << ans << endl;
    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 3508
final_rank: 4

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(a) a.begin(),a.end()
#define reps(i, a, n) for (int i = (a); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)
#define rreps(i, a, n) for (int i = (a); i > (int)(n); i--)
const long long mod = 1000000007;
const long long INF = 1e18;
ll myceil(ll a, ll b) {return (a+b-1)/b;}


void solve() {
    int n;
    cin >> n;
    vector<ll> v(n);
    rep(i,n) {
        cin >> v[i];
    }

    sort(all(v));
    reverse(all(v));

    int ans = -1;

    rep(i,n) {
        reps(j,i+1,n) {
            int x = v[i]*v[j];
            if (x < ans) break;

            string s = to_string(v[i]*v[j]);
            rep(ind,s.length()-1) {
                if (s[ind] != s[ind+1]-1) break;

                if (ind == s.length()-2) ans = x;
            }
            if (s.length() == 1) ans = x;
        }
    }

    cout << ans << endl;
    return;
}


int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    int t = 1;
    //cin >> t;
    rep(i,t) {
        solve();
    }
}
accuracy: 1
time_ms: 20
memory_kb: 3536
final_rank: 14

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i,l,r) for(ll i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
int main(){
    int N;cin>>N;
    vector<ll>A(N);
    REP(i,N)cin>>A[i];
    ll ans=-1;
    REP(i,N)REP(j,i){
        string s=to_string(A[i]*A[j]);
        bool ok=1;
        REP(k,s.size()-1)if(s[k+1]-s[k]!=1)ok=0;
        if(ok)ans=max(ans,A[i]*A[j]);
    }
    cout<<ans<<endl;
    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 3532
final_rank: 11

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) sort(ALL(v)), (v).erase(unique(ALL(v)), (v).end())
#define SZ(v) (int)v.size()
#define MIN(v) *min_element(ALL(v))
#define MAX(v) *max_element(ALL(v))
#define LB(v, x) int(lower_bound(ALL(v), (x)) - (v).begin())
#define UB(v, x) int(upper_bound(ALL(v), (x)) - (v).begin())

using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long;
using i128 = __int128_t;
using u128 = __uint128_t;
const int inf = 0x3fffffff;
const ll INF = 0x1fffffffffffffff;

template <typename T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T, typename U> T ceil(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? (x + y - 1) / y : x / y);
}
template <typename T, typename U> T floor(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? x / y : (x - y + 1) / y);
}
template <typename T> int popcnt(T x) {
    return __builtin_popcountll(x);
}
template <typename T> int topbit(T x) {
    return (x == 0 ? -1 : 63 - __builtin_clzll(x));
}
template <typename T> int lowbit(T x) {
    return (x == 0 ? -1 : __builtin_ctzll(x));
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "P(" << p.first << ", " << p.second << ")";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &map_var) {
    os << "{";
    for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
        os << "(" << itr->first << ", " << itr->second << ")";
        itr++;
        if (itr != map_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
#ifdef LOCAL
#define show(...) _show(0, #__VA_ARGS__, __VA_ARGS__)
#else
#define show(...) true
#endif
template <typename T> void _show(int i, T name) {
    cerr << '\n';
}
template <typename T1, typename T2, typename... T3>
void _show(int i, const T1 &a, const T2 &b, const T3 &...c) {
    for (; a[i] != ',' && a[i] != '\0'; i++)
        cerr << a[i];
    cerr << ":" << b << " ";
    _show(i + 1, a, c...);
}

#include <unistd.h>

namespace fastio {
static constexpr uint32_t SZ = 1 << 17;
char ibuf[SZ];
char obuf[SZ];
char out[100];
// pointer of ibuf, obuf


uint32_t pil = 0, pir = 0, por = 0;

struct Pre {
    char num[10000][4];
    constexpr Pre() : num() {
        for (int i = 0; i < 10000; i++) {
            int n = i;
            for (int j = 3; j >= 0; j--) {
                num[i][j] = n % 10 | '0';
                n /= 10;
            }
        }
    }
} constexpr pre;

inline void load() {
    memmove(ibuf, ibuf + pil, pir - pil);
    pir = pir - pil + fread(ibuf + pir - pil, 1, SZ - pir + pil, stdin);
    pil = 0;
    if (pir < SZ)
        ibuf[pir++] = '\n';
}

inline void flush() {
    fwrite(obuf, 1, por, stdout);
    por = 0;
}

void rd(char &c) {
    do {
        if (pil + 1 > pir)
            load();
        c = ibuf[pil++];
    } while (isspace(c));
}

void rd(string &x) {
    x.clear();
    char c;
    do {
        if (pil + 1 > pir)
            load();
        c = ibuf[pil++];
    } while (isspace(c));
    do {
        x += c;
        if (pil == pir)
            load();
        c = ibuf[pil++];
    } while (!isspace(c));
}

template <typename T> void rd_real(T &x) {
    string s;
    rd(s);
    x = stod(s);
}

template <typename T> void rd_integer(T &x) {
    if (pil + 100 > pir)
        load();
    char c;
    do
        c = ibuf[pil++];
    while (c < '-');
    bool minus = 0;
    if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
        if (c == '-') {
            minus = 1, c = ibuf[pil++];
        }
    }
    x = 0;
    while ('0' <= c) {
        x = x * 10 + (c & 15), c = ibuf[pil++];
    }
    if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
        if (minus)
            x = -x;
    }
}

void rd(int &x) {
    rd_integer(x);
}
void rd(ll &x) {
    rd_integer(x);
}
void rd(i128 &x) {
    rd_integer(x);
}
void rd(uint &x) {
    rd_integer(x);
}
void rd(ull &x) {
    rd_integer(x);
}
void rd(u128 &x) {
    rd_integer(x);
}
void rd(double &x) {
    rd_real(x);
}
void rd(long double &x) {
    rd_real(x);
}

template <class T, class U> void rd(pair<T, U> &p) {
    return rd(p.first), rd(p.second);
}
template <size_t N = 0, typename T> void rd_tuple(T &t) {
    if constexpr (N < std::tuple_size<T>::value) {
        auto &x = std::get<N>(t);
        rd(x);
        rd_tuple<N + 1>(t);
    }
}
template <class... T> void rd(tuple<T...> &tpl) {
    rd_tuple(tpl);
}

template <size_t N = 0, typename T> void rd(array<T, N> &x) {
    for (auto &d : x)
        rd(d);
}
template <class T> void rd(vector<T> &x) {
    for (auto &d : x)
        rd(d);
}

void read() {}
template <class H, class... T> void read(H &h, T &...t) {
    rd(h), read(t...);
}

void wt(const char c) {
    if (por == SZ)
        flush();
    obuf[por++] = c;
}
void wt(const string s) {
    for (char c : s)
        wt(c);
}
void wt(const char *s) {
    size_t len = strlen(s);
    for (size_t i = 0; i < len; i++)
        wt(s[i]);
}

template <typename T> void wt_integer(T x) {
    if (por > SZ - 100)
        flush();
    if (x < 0) {
        obuf[por++] = '-', x = -x;
    }
    int outi;
    for (outi = 96; x >= 10000; outi -= 4) {
        memcpy(out + outi, pre.num[x % 10000], 4);
        x /= 10000;
    }
    if (x >= 1000) {
        memcpy(obuf + por, pre.num[x], 4);
        por += 4;
    } else if (x >= 100) {
        memcpy(obuf + por, pre.num[x] + 1, 3);
        por += 3;
    } else if (x >= 10) {
        int q = (x * 103) >> 10;
        obuf[por] = q | '0';
        obuf[por + 1] = (x - q * 10) | '0';
        por += 2;
    } else
        obuf[por++] = x | '0';
    memcpy(obuf + por, out + outi + 4, 96 - outi);
    por += 96 - outi;
}

template <typename T> void wt_real(T x) {
    ostringstream oss;
    oss << fixed << setprecision(15) << double(x);
    string s = oss.str();
    wt(s);
}

void wt(int x) {
    wt_integer(x);
}
void wt(ll x) {
    wt_integer(x);
}
void wt(i128 x) {
    wt_integer(x);
}
void wt(uint x) {
    wt_integer(x);
}
void wt(ull x) {
    wt_integer(x);
}
void wt(u128 x) {
    wt_integer(x);
}
void wt(double x) {
    wt_real(x);
}
void wt(long double x) {
    wt_real(x);
}

template <class T, class U> void wt(const pair<T, U> val) {
    wt(val.first);
    wt(' ');
    wt(val.second);
}
template <size_t N = 0, typename T> void wt_tuple(const T t) {
    if constexpr (N < std::tuple_size<T>::value) {
        if constexpr (N > 0) {
            wt(' ');
        }
        const auto x = std::get<N>(t);
        wt(x);
        wt_tuple<N + 1>(t);
    }
}
template <class... T> void wt(tuple<T...> tpl) {
    wt_tuple(tpl);
}
template <class T, size_t S> void wt(const array<T, S> val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
        if (i)
            wt(' ');
        wt(val[i]);
    }
}
template <class T> void wt(const vector<T> val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
        if (i)
            wt(' ');
        wt(val[i]);
    }
}

void print() {
    wt('\n');
}
template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) {
    wt(head);
    if (sizeof...(Tail))
        wt(' ');
    print(forward<Tail>(tail)...);
}
void __attribute__((destructor)) _d() {
    flush();
}
} // namespace fastio


using fastio::flush;
using fastio::print;
using fastio::read;

inline void first(bool i = true) {
    print(i ? "first" : "second");
}
inline void Alice(bool i = true) {
    print(i ? "Alice" : "Bob");
}
inline void Takahashi(bool i = true) {
    print(i ? "Takahashi" : "Aoki");
}
inline void yes(bool i = true) {
    print(i ? "yes" : "no");
}
inline void Yes(bool i = true) {
    print(i ? "Yes" : "No");
}
inline void No() {
    print("No");
}
inline void YES(bool i = true) {
    print(i ? "YES" : "NO");
}
inline void NO() {
    print("NO");
}
inline void Yay(bool i = true) {
    print(i ? "Yay!" : ":(");
}
inline void Possible(bool i = true) {
    print(i ? "Possible" : "Impossible");
}
inline void POSSIBLE(bool i = true) {
    print(i ? "POSSIBLE" : "IMPOSSIBLE");
}

/**
 * @brief Fast IO
 */

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i,0,N) cin >> A[i];
    int ANS = -1;
    rep(i,0,N) {
        rep(j,i+1,N) {
            int X = A[i] * A[j];
            string S = to_string(X);
            bool check = true;
            rep(k,0,S.size()-1) {
                if (S[k] + 1 != S[k+1]) check = false;
            }
            if (check) chmax(ANS,X);
        }
    }
    cout << ANS << endl;
}
accuracy: 1
time_ms: 20
memory_kb: 3584
final_rank: 18

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int n;
	cin >> n;
	VI a(n);
	int ans = -1;
	FOR (i, 0, n)
	{
		cin >> a[i];
		FOR (j, 0, i)
		{
			int x = a[i] * a[j];
			string s = to_string(x);
			bool ok = true;
			FOR (k, 0, SZ(s) - 1)
			{
				ok &= (s[k + 1] - s[k]) == 1;
			}
			if (ok)
				ans = max(ans, x);
		}
	}
	cout << ans << '\n';
	
	return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 3528
final_rank: 10

code_snippet: #include <bits/stdc++.h>
using namespace std;

int main() {
    int n; std::cin >> n;
    std::vector<int> a(n);
    for (auto& x : a) std::cin >> x;
    int ans{-1};
    for (int i{} ; i < n ; i++) for (int j{i + 1} ; j < n ; j++) {
        int v{a[i] * a[j]};
        std::string t{std::to_string(v)};
        bool ok{true};
        for (int i{1} ; i < (int)t.size() ; i++) {
            ok &= t[i] == t[i - 1] + 1;
        }
        if (ok) ans = std::max(ans, v);
    }
    std::cout << ans << '\n';
}
accuracy: 1
time_ms: 20
memory_kb: 3516
final_rank: 8

code_snippet: #include <bits/stdc++.h>

int main() {
    int n;
    std::cin >> n;
    std::vector<int> a(n);
    for (int i = 0; i < n; i++) std::cin >> a[i];
    int ans = -1;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            int mul = a[i] * a[j];
            std::string s = std::to_string(mul);
            bool flag = true;
            for (int k = 0; k + 1 < (int)s.size(); k++) {
                if (s[k] != s[k + 1] - 1) {
                    flag = false;
                    break;
                }
            }
            if (flag) {
                ans = std::max(ans, mul);
            }
        }
    }
    std::cout << ans << std::endl;
}
accuracy: 1
time_ms: 20
memory_kb: 3500
final_rank: 2

code_snippet: #include<bits/stdc++.h>
using namespace std;
template<class T> bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;}
template<class T> bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;}

bool solve(){
    return true;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    // while(1){
    //     if(!solve()){
    //         return 0;
    //     }
    // }
    int N;
    cin>>N;
    vector<int>A(N);
    for(int i=0;i<N;i++)cin>>A[i];
    int ans=-1;
    for(int i=0;i<N-1;i++)for(int j=i+1;j<N;j++){
        string s=to_string(A[i]*A[j]);
        int n=s.size();
        bool ok=true;
        for(int k=0;k<n-1;k++){
            if(s[k+1]-s[k]!=1){
                ok=false;
                break;
            }
        }
        if(ok)chmax(ans,A[i]*A[j]);
    }
    cout<<ans<<"\n";
}
accuracy: 1
time_ms: 20
memory_kb: 3532
final_rank: 11

code_snippet: #include <iostream>
#include <vector>
using namespace std;

int main(){
    int n; cin >> n;
    vector<int> a(n);
    for(auto &it: a) cin >> it;

    int ans = -1;
    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            int x = a[i]*a[j];
            int y = x;
            vector<int> v;
            while(y > 0){
                v.emplace_back(y%10);
                y /= 10;
            }
            bool isok = true;
            for(int k = 1; k < v.size(); k++){
                if(v[k-1] != v[k]+1) isok = false;
            }
            if(isok && ans < x) ans = x;
        }
    }
    cout << ans << endl;
    return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 3444
final_rank: 1

code_snippet: #include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repn(i,end) for(int i = 0; i <= (int)(end); i++)
#define reps(i,start,end) for(int i = start; i < (int)(end); i++)
#define repsn(i,start,end) for(int i = start; i <= (int)(end); i++)
#define ll long long
#define print(t) cout << t << endl 
#define all(a)  (a).begin(),(a).end()
// << std::fixed << std::setprecision(0)
const ll INF = 1LL << 60;
 
template<class T> void chmin(T& a, T b){
 if(a > b){
  a = b;
 }
}
 
template<class T> void chmax(T& a, T b){
 if(a < b){
  a = b;
 }
}
  
ll lpow(ll x,ll n){
  ll ans = 1;
  while(n >0){
    if(n & 1)ans *= x;
    x *= x;
    n >>= 1;
  }
  return ans;
}
 
int main(){
  ll n;cin >> n;
  vector<ll> a(n);
  rep(i,n)cin >> a[i];
  sort(all(a));

  for(ll i = n-1;i >= 1;i--){
    for(ll j = i-1;j>= 0;j--){
      ll b = a[i] * a[j];
      string s = to_string(b);
      bool ok = true;
      rep(k,(int)s.size()-1){
        if(s[k+1] !=s[k] + 1){
          ok = false;
          break;
        }
      }
      if(ok){
        cout << b << endl;
        return 0;
      }

    }
  }
  cout << -1 << endl;
}
accuracy: 1
time_ms: 20
memory_kb: 3516
final_rank: 8

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REP(i, a, b) for (ll i = a; i < (ll)(b); i++)
#define all(v) v.begin(), v.end()
#define INF32 2147483647 //2.147483647×10^{9}:32bit整数のinf
#define INF 9223372036854775807 //9.223372036854775807×10^{18}:64bit整数のinf

int main(){
    ll N;
    cin>>N;
    vector<ll> a(N);
    rep(i,N){
        cin>>a[i];
    }
    ll ans=-1;
    string judge;
    bool flag;
    rep(i,N){
        REP(j,i+1,N){
            judge=to_string(a[i]*a[j]);
            flag=true;
            rep(k,judge.size()-1){
                if((judge[k+1]-'0')!=(judge[k]-'0'+1)){
                    flag=false;
                    break;
                }
            }
            if(flag&&stoll(judge)>ans)ans=stoll(judge);
        }
    }
    cout<<ans<<endl;
}
accuracy: 1
time_ms: 30
memory_kb: 3548
final_rank: 19

code_snippet: #line 2 "library/KowerKoint/base.hpp"

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>
using namespace std;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for(ll i = a; i < (ll)(b); i++)
#define ALL(a) (a).begin(),(a).end()
#define END(...) { print(__VA_ARGS__); return; }

using VI = vector<int>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
using ll = long long;
using VL = vector<ll>;
using VVL = vector<VL>;
using VVVL = vector<VVL>;
using VD = vector<double>;
using VVD = vector<VD>;
using VVVD = vector<VVD>;
using VS = vector<string>;
using VVS = vector<VS>;
using VVVS = vector<VVS>;
using VC = vector<char>;
using VVC = vector<VC>;
using VVVC = vector<VVC>;
using P = pair<int, int>;
using VP = vector<P>;
using VVP = vector<VP>;
using VVVP = vector<VVP>;
using LP = pair<ll, ll>;
using VLP = vector<LP>;
using VVLP = vector<VLP>;
using VVVLP = vector<VVLP>;

template <typename T>
using PQ = priority_queue<T>;
template <typename T>
using GPQ = priority_queue<T, vector<T>, greater<T>>;

constexpr int INF = 1001001001;
constexpr ll LINF = 1001001001001001001ll;
constexpr int DX[] = {1, 0, -1, 0};
constexpr int DY[] = {0, 1, 0, -1};

void print() { cout << '\n'; }
template<typename T>
void print(const T &t) { cout << t << '\n'; }
template<typename Head, typename... Tail>
void print(const Head &head, const Tail &... tail) {
    cout << head << ' ';
    print(tail...);
}

#ifdef DEBUG
void dbg() { cerr << '\n'; }
template<typename T>
void dbg(const T &t) { cerr << t << '\n'; }
template<typename Head, typename... Tail>
void dbg(const Head &head, const Tail &... tail) {
    cerr << head << ' ';
    dbg(tail...);
}
#else
template<typename... Args>
void dbg(const Args &... args) {}
#endif

template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 >& p) {
    os << p.first << " " << p.second;
    return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
    is >> p.first >> p.second;
    return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
    for(int i = 0; i < (int) v.size(); i++) {
        os << v[i] << (i + 1 != (int) v.size() ? " " : "");
    }
    return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
    for(T &in : v) is >> in;
    return is;
}

template<typename T>
vector<vector<T>> split(typename vector<T>::const_iterator begin, typename vector<T>::const_iterator end, T val) {
    vector<vector<T>> res;
    vector<T> cur;
    for(auto it = begin; it != end; it++) {
        if(*it == val) {
            res.push_back(cur);
            cur.clear();
        } else cur.push_back(val);
    }
    res.push_back(cur);
    return res;
}

vector<string> split(typename string::const_iterator begin, typename string::const_iterator end, char val) {
    vector<string> res;
    string cur = "";
    for(auto it = begin; it != end; it++) {
        if(*it == val) {
            res.push_back(cur);
            cur.clear();
        } else cur.push_back(val);
    }
    res.push_back(cur);
    return res;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template <typename T>
pair<VI, vector<T>> compress(const vector<T> &a) {
    int n = a.size();
    vector<T> x;
    REP(i, n) x.push_back(a[i]);
    sort(ALL(x)); x.erase(unique(ALL(x)), x.end());
    VI res(n);
    REP(i, n) res[i] = lower_bound(ALL(x), a[i]) - x.begin();
    return make_pair(res, x);
}

template <typename It>
auto rle(It begin, It end) {
    vector<pair<typename It::value_type, int>> res;
    if(begin == end) return res;
    auto pre = *begin;
    int num = 1;
    for(auto it = begin + 1; it != end; it++) {
        if(pre != *it) {
            res.emplace_back(pre, num);
            pre = *it;
            num = 1;
        } else num++;
    }
    res.emplace_back(pre, num);
    return res;
}

vector<pair<char, int>> rle(string s) {
    return rle(ALL(s));
}

template <typename T>
pair<vector<T>, vector<T>> factorial(int n) {
    vector<T> res(n+1), rev(n+1);
    res[0] = 1;
    REP(i, n) res[i+1] = res[i] * (i+1);
    rev[n] = 1 / res[n];
    for(int i = n; i > 0; i--) {
        rev[i-1] = rev[i] * i;
    }
    return make_pair(res, rev);
}
#line 3 "library/KowerKoint/internal_operator.hpp"

namespace internal_operator {
    template <typename T>
    T default_add(T a, T b) { return a + b; }
    template <typename T>
    T default_sub(T a, T b) { return a - b; }
    template <typename T>
    T zero() { return T(0); }
    template <typename T>
    T default_div(T a, T b) { return a / b; }
    template <typename T>
    T default_mult(T a, T b) { return a * b; }
    template <typename T>
    T one() { return T(1); }
    template <typename T>
    T default_xor(T a, T b) { return a ^ b; }
    template <typename T>
    T default_and(T a, T b) { return a & b; }
    template <typename T>
    T default_or(T a, T b) { return a | b; }
    ll mod3() { return 998244353LL; }
    ll mod7() { return 1000000007LL; }
    ll mod9() { return 1000000009LL; }
    template <typename T>
    T default_max(T a, T b) { return max(a, b); }
    template <typename T>
    T default_min(T a, T b) { return min(a, b); }
}

#line 3 "library/KowerKoint/integer.hpp"

ll kth_root(ll x, ll k) {
    if(k == 1) return x;
    ll res = 0;
    for(int i = 31; i >= 0; i--) {
        bool over = false;
        ll tmp = 1;
        ll nxt = res | 1LL << i;
        REP(i, k) {
            if(tmp > x / nxt) {
                over = true;
                break;
            }
            tmp *= nxt;
        }
        if(!over) res = nxt;
    }
    return res;
}

ll sqrt(ll x) {
    return kth_root(x, 2);
}

struct Prime {
    VI sieved;
    VL primes;

    Prime() {}
    Prime(ll n) {
        expand(n);
    }

    void expand(ll n) {
        ll sz = (ll)sieved.size() - 1;
        if(n <= sz) return;
        sieved.resize(n+1);
        sieved[0] = sieved[1] = 1;
        primes.clear();
        primes.push_back(2);
        for(ll d = 4; d <= n; d += 2) sieved[d] = 1;
        FOR(d, 3, n+1) {
            if(!sieved[d]) {
                primes.push_back(d);
                for(ll i = d*d; i <= n; i += d*2) sieved[i] = 1;
            }
        }
    }

    bool is_prime(ll n) {
        assert(n > 0);
        if(n <= (ll)sieved.size() - 1) return !sieved[n];
        for(ll d = 2; d*d <= n; d++) {
            if(n % d == 0) return false;
        }
        return true;
    }

    VL least_prime_factors(ll n) {
        assert(n > 0);
        VL lpfs(n+1, -1), primes;
        FOR(d, 2, n+1) {
            if(lpfs[d] == -1) {
                lpfs[d] = d;
                primes.push_back(d);
            }
            for(ll p : primes) {
                if(p * d > n || p > lpfs[d]) break;
                lpfs[p*d] = p;
            }
        }
        return lpfs;
    }

    VL prime_list(ll n) {
        assert(n > 0);
        expand(n);
        return VL(primes.begin(), upper_bound(ALL(primes), n));
    }

    vector<pair<ll, int>> prime_factor(ll n) {
        assert(n > 0);
        vector<pair<ll, int>> factor;
        expand(sqrt(n));
        for(ll prime : primes) {
            if(prime * prime > n) break;
            int cnt = 0;
            while(n % prime == 0) {
                n /= prime;
                cnt++;
            }
            if(cnt) factor.emplace_back(prime, cnt);
        }
        if(n > 1) factor.emplace_back(n, 1);
        return factor;
    }


    VL divisor(ll n) {
        assert(n > 0);
        auto factor = prime_factor(n);
        VL res = {1};
        for(auto [prime, cnt] : factor) {
            int sz = res.size();
            res.resize(sz * (cnt+1));
            REP(i, sz*cnt) res[sz+i] = res[i] * prime;
            REP(i, cnt) inplace_merge(res.begin(), res.begin() + sz*(i+1), res.begin() + sz*(i+2));
        }
        return res;
    }
};

ll extgcd(ll a, ll b, ll& x, ll& y) {
    x = 1, y = 0;
    ll nx = 0, ny = 1;
    while(b) {
        ll q = a / b;
        tie(a, b) = LP(b, a % b);
        tie(x, nx) = LP(nx, x - nx*q);
        tie(y, ny) = LP(ny, y - ny*q);
    }
    return a;
}

ll inv_mod(ll n, ll m) {
    ll x, y;
    assert(extgcd(n, m, x, y) == 1);
    x %= m;
    if(x < 0) x += m;
    return x;
}

ll pow_mod(ll a, ll n, ll m) {
    if(n == 0) return 1LL;
    if(n < 0) return inv_mod(pow_mod(a, -n, m), m);
    ll res = 1;
    while(n) {
        if(n & 1) {
            res *= a;
            res %= m;
        }
        n >>= 1;
        a *= a;
        a %= m;
    }
    return res;
}

#line 5 "library/KowerKoint/modint.hpp"

template <ll (*mod)()>
struct Modint {
    ll val;
    
    Modint(): val(0) {}

    Modint(ll x): val(x) {
        val %= mod();
        if(val < 0) val += mod();
    }

    Modint& operator+=(const Modint& r) {
        val += r.val;
        if(val >= mod()) val -= mod();
        return *this;
    }
    friend Modint operator+(const Modint& l, const Modint& r) {
        return Modint(l) += r;
    }

    Modint& operator-=(const Modint& r) {
        val -= r.val;
        if(val < 0) val += mod();
        return *this;
    }
    friend Modint operator-(const Modint& l, const Modint& r) {
        return Modint(l) -= r;
    }

    Modint& operator*=(const Modint& r) {
        val *= r.val;
        val %= mod();
        return *this;
    }
    Modint operator*(const Modint& r) {
        return (Modint(*this) *= r);
    }
    friend Modint operator*(const Modint& l, const Modint& r) {
        return Modint(l) *= r;
    }

    Modint pow(ll n) const {
        return Modint(pow_mod(val, n, mod()));
    }

    Modint inv() const {
        return Modint(inv_mod(val, mod()));
    }

    Modint& operator/=(const Modint& r) {
        return (*this *= r.inv());
    }
    friend Modint operator/(const Modint& l, const Modint& r) {
        return Modint(l) /= r;
    }

    Modint& operator^=(const ll n) {
        val = pow_mod(val, n, mod());
        return *this;
    }
    Modint operator^(const ll n) {
        return this->pow(n);
    }

    Modint operator+() const { return *this; }
    Modint operator-() const { return Modint() - *this; }

    Modint& operator++() {
        val++;
        if(val == mod()) val = 0LL;
        return *this;
    }
    Modint& operator++(int) {
        Modint res(*this);
        ++*this;
        return res;
    }

    Modint& operator--() {
        if(val == 0LL) val = mod();
        val--;
        return *this;
    }
    Modint& operator--(int) {
        Modint res(*this);
        --*this;
        return res;
    }

    friend bool operator==(const Modint& l, const Modint& r) {
        return l.val == r.val;
    }
    friend bool operator!=(const Modint& l, const Modint& r) {
        return l.val != r.val;
    }

    static pair<vector<Modint>, vector<Modint>> factorial(int n) {
        vector<Modint> fact(n+1), rfact(n+1);
        fact[0] = 1;
        REP(i, n) fact[i+1] = fact[i] * (i+1);
        rfact[n] = 1 / fact[n];
        for(int i = n-1; i >= 0; i--) rfact[i] = rfact[i+1] * (i+1);
        return {fact, rfact};
    }

    friend istream& operator>>(istream& is, Modint& mi) {
        is >> mi.val;
        return is;
    }

    friend ostream& operator<<(ostream& os, const Modint& mi) {
        os << mi.val;
        return os;
    }
};

using MI3 = Modint<internal_operator::mod3>;
using V3 = vector<MI3>;
using VV3 = vector<V3>;
using VVV3 = vector<VV3>;
using MI7 = Modint<internal_operator::mod7>;
using V7 = vector<MI7>;
using VV7 = vector<V7>;
using VVV7 = vector<VV7>;
using MI9 = Modint<internal_operator::mod9>;
using V9 = vector<MI9>;
using VV9 = vector<V9>;
using VVV9 = vector<VV9>;
#line 3 "library/KowerKoint/counting.hpp"

template <typename T>
struct Counting {
    vector<T> fact, ifact;

    Counting() {}
    Counting(ll n) {
        expand(n);
    }

    void expand(ll n) {
        ll sz = (ll)fact.size();
        if(sz > n) return;
        fact.resize(n+1);
        ifact.resize(n+1);
        fact[0] = 1;
        FOR(i, max(1LL, sz), n+1) fact[i] = fact[i-1] * i;
        ifact[n] = 1 / fact[n];
        for(ll i = n-1; i >= sz; i--) ifact[i] = ifact[i+1] * (i+1);
    }

    T permutation(ll n, ll r) {
        assert(n >= r);
        assert(r >= 0);
        expand(n);
        return fact[n] * ifact[n-r];
    }

    T combination(ll n, ll r) {
        assert(n >= r);
        assert(r >= 0);
        expand(n);
        return fact[n] * ifact[r] * ifact[n-r];
    }

    T stirling(ll n, ll k) {
        assert(n >= k);
        assert(k >= 0);
        if(n == 0) return 1;
        T res = 0;
        int sign = k%2? -1 : 1;
        expand(k);
        REP(i, k+1) {
            res += sign * ifact[i] * ifact[k-i] * T(i).pow(n);
            sign *= -1;
        }
        return res;
    }

    vector<vector<T>> stirling_table(ll n, ll k) {
        assert(n >= 0 && k >= 0);
        vector<vector<T>> res(n+1, vector<T>(k+1));
        res[0][0] = 1;
        FOR(i, 1, n+1) FOR(j, 1, k+1) {
            res[i][j] = res[i-1][j-1] + j * res[i-1][j];
        }
        return res;
    }

    T bell(ll n, ll k) {
        assert(n >= 0 && k >= 0);
        expand(k);
        vector<T> tmp(k+1);
        int sign = 1;
        tmp[0] = 1;
        FOR(i, 1, k+1) {
            sign *= -1;
            tmp[i] = tmp[i-1] + sign * ifact[i];
        }
        T res = 0;
        REP(i, k+1) {
            res += T(i).pow(n) * ifact[i] * tmp[k-i];
        }
        return res;
    }

    vector<vector<T>> partition_table(ll n) {
        assert(n >= 0);
        vector<vector<T>> res(n+1, vector<T>(n+1));
        REP(i, n+1) res[0][i] = 1;
        FOR(i, 1, n+1) FOR(j, 1, n+1) {
            res[i][j] = res[i][j-1] + (i<j? 0 : res[i-j][j]);
        }
        return res;
    }
};
#line 2 "Contests/Dummy/main.cpp"

/* #include <atcoder/all> */
/* using namespace atcoder; */
/* #include "KowerKoint/expansion/ac-library/all.hpp" */

void solve(){
    int n; cin >> n;
    VL a(n); cin >> a;
    ll ans = -1;
    REP(i, n) REP(j, i) {
        ll tmp = a[i] * a[j];
        string s = to_string(tmp);
        bool ok = true;
        REP(i, s.length()-1) ok &= s[i]+1 == s[i+1];
        if(ok) chmax(ans, tmp);
    }
    print(ans);
}

// generated by oj-template v4.7.2 (https://github.com/online-judge-tools/template-generator)
int main() {
    // Fasterize input/output script
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(100);
    // scanf/printf user should delete this fasterize input/output script

    int t = 1;
    //cin >> t; // comment out if solving multi testcase
    for(int testCase = 1;testCase <= t;++testCase){
        solve();
    }
    return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 3528
final_rank: 17

code_snippet: #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
typedef long long ll;
using namespace std;

int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);

    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];

    int ans = -1;
    for (int i = 0; i < N; ++i) {
        for (int j = i + 1; j < N; ++j) {
            string s = to_string(A[i] * A[j]);

            bool flag = true;
            rep(k, s.size() - 1) {
                if (s[k] + 1 != s[k + 1]) {
                    flag = false;
                    break;
                }
            }
            if (flag)
                ans = max(ans, A[i] * A[j]);
        }
    }
    cout << ans << "\n";

    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 3556
final_rank: 16

code_snippet: //GIVE ME AC!!!!!!!!!!!!!!!!!
//#pragma GCC target("avx")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using vl=vector<ll>;
using vi=vector<int>;
using vs=vector<string>;
using vc=vector<char>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using vvc=vector<vc>;
using vd=vector<double>;
using vp=vector<P>;
using vb=vector<bool>;
#define overload4(_1,_2,_3,_4,name,...) name
#define overload3(_1,_2,_3,name,...) name
#define rep1(a) for(__typeof(a) i=0;i<a;i++)
#define rep2(i,a) for(__typeof(a) i=0;i<a;i++)
#define rep3(i,a,b) for(__typeof(a) i=a;i<b;i++)
#define rep4(i,a,b,c) for(__typeof(a) i=a;i<b;i+=c)
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep1(a) for(__typeof(a) i=(a)-1;i>=0;i--)
#define rrep2(i,a) for(__typeof(a) i=(a)-1;i>=0;i--)
#define rrep3(i,a,b) for(__typeof(a) i=(b)-1;i>=(a);i--)
#define rrep(...) overload3(__VA_ARGS__,rrep3,rrep2,rrep1)(__VA_ARGS__)
#define all1(i) begin(i),end(i)
#define all2(i,a) begin(i),begin(i)+a
#define all3(i,a,b) begin(i)+a,begin(i)+b
#define all(...) overload3(__VA_ARGS__,all3,all2,all1)(__VA_ARGS__)
#define rall(n) (n).rbegin(),(n).rend()
#define pb push_back
#define eb emplace_back
#define MtSaka ios::sync_with_stdio(0);cin.tie(0);cout<<fixed<<setprecision(12)
#define max_(a) *max_element(all(a))
#define min_(a) *min_element(all(a))
#define INT(...) int __VA_ARGS__;scan(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;scan(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;scan(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;scan(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;scan(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__;scan(__VA_ARGS__)
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const ll inf=2e18;
const ll MOD=1000000007;
const ll mod=998244353;
const double pi=acos(-1);
template<typename T1,typename T2 >
ostream &operator<<(ostream&os,const pair<T1,T2>&p){os<<p.first<<" "<<p.second;return os;}
template<typename T1,typename T2>
istream &operator>>(istream&is,pair<T1,T2>&p){is>>p.first>>p.second;return is;}
template<typename T>
ostream &operator<<(ostream&os,const vector<T>&v){for(int i=0;i<(int)v.size();i++){os<<v[i]<<(i+1!=v.size()?" ":"");}return os;}
template<typename T>
istream &operator>>(istream&is,vector<T>&v){for(T &in:v){is>>in;}return is;}
void scan(){}
template<class Head,class... Tail>
void scan(Head&head,Tail&... tail){cin>>head;scan(tail...);}
template<class T>
void print(const T &t){cout<<t<<'\n';}
template<class Head, class... Tail>
void print(const Head &head, const Tail &... tail){cout<<head<<' ';print(tail...);}
template<class... T>
void fin(const T &... a){print(a...);exit(0);}
template<typename T>
T sum_(vector<T>a){return accumulate(all(a),T(0));}
template<typename T1,typename T2>
inline bool chmax(T1&a,T2 b){return a<b&&(a=b,true);}
template<typename T1,typename T2>
inline bool chmin(T1&a,T2 b){return a>b&&(a=b,true);}
int main(){
  LL(n);
  vl a(n);
  scan(a);
  ll ans=-1;
  rep(i,n)rep(j,i+1,n){
    ll now=a[i]*a[j];
    string s=to_string(now);
    rep(i,s.size()-1){
      if(s[i]+1!=s[i+1])now=-1;
    }
    chmax(ans,now);
  }
  print(ans);
}
accuracy: 1
time_ms: 20
memory_kb: 3512
final_rank: 7

code_snippet: #include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
//const int mod = 1000000007;
//const int mod = 998244353;

int main()
{
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, 0, n) cin >> a[i];
    sort(a.rbegin(), a.rend());
    ll ans = -1;
    rep(i, 0, n){
        rep(j, i+1, n){
            ll tmp = a[i]*a[j];
            string s = to_string(tmp);
            bool flag = true;
            rep(k, 0, s.size()-1){
                if(s[k] + 1 != s[k+1]) flag = false;
            }
            if(flag) ans = max(ans, tmp);
        }
    }
    cout << ans << endl;
    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 3548
final_rank: 15

code_snippet: #include<bits/stdc++.h>
using namespace std;

using ll = long long;
const int INF = 1e9;
const ll inf = 1LL<<60;

int main() {
  int n; cin >> n;
  vector<int> a(n);
  for (int i=0; i<n; i++) cin >> a[i];
  auto f = [](int x) -> bool {
    string s = to_string(x);
    for (int i=1; i<s.size(); i++) {
      if (s[i] - '0' != s[i-1] - '0' + 1) return false;
    }
    return true;
  };
  int ans = -1;
  for (int i=0; i<n; i++) for (int j=i+1; j<n; j++) if (f(a[i]*a[j])) ans = max(ans, a[i]*a[j]);
  cout << ans << endl;
}
accuracy: 1
time_ms: 20
memory_kb: 3508
final_rank: 4

code_snippet: #include<bits/stdc++.h>
using namespace std;

using ll = long long;
const int INF = 1e9;
const ll inf = 1LL<<60;

int main() {
  int n; cin >> n;
  vector<int> a(n);
  for (int i=0; i<n; i++) cin >> a[i];
  auto f = [](int x) -> bool {
    string s = to_string(x);
    for (int i=1; i<s.size(); i++) {
      if (s[i-1] - '0' + 1 != s[i] - '0') return false;
    }
    return true;
  };
  int ans = -1;
  for (int i=0; i<n; i++) for (int j=i+1; j<n; j++) if (f(a[i]*a[j])) ans = max(ans, a[i]*a[j]);
  cout << ans << endl;
}
accuracy: 1
time_ms: 20
memory_kb: 3500
final_rank: 2

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1000000010
#define EPS 1e-9
#define F first
#define S second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"

typedef pair<int,int> PII;
typedef pair<int,string> PIS;
typedef pair<string,int> PSI;

template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b; 
    return true;
  }
  return false;
}

template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  vector<int> v(n);
  rep(i,n) cin>>v[i];
  sort(v.begin(),v.end(),greater<int>() );
  rep(i,n){
    repi(j,i+1,n){
      int num=v[i]*v[j];
      string s=to_string(num);
      char c=s[0];
      if(s.size()==1){cout<<num<<endl;return 0;}
      repi(j,1,s.size() ){
	if(s[j] != 1+s[j-1]) break;
	else if(j==s.size()-1){
	  cout<<num<<endl;
	  return 0;
	}
      }
    }
  }
  cout<<-1<<endl;

  return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 3532
final_rank: 11

code_snippet: #include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    int N; cin >> N;
    vector<int> a(N);
    rep(i,N) cin >> a[i];
    int ans = -1;
    rep(i,N)rep(j,N) if(i != j) {
        string s = to_string(a[i] * a[j]);
        bool ok = true;
        rep(k,s.size()-1) {
            if(s[k] + 1 != s[k + 1]) ok = false;
        }
        if(ok) ans = max(ans, stoi(s));
    }
    cout << ans << endl;
}
accuracy: 1
time_ms: 50
memory_kb: 3508
final_rank: 20