Problem:
Arithmetic Progressions
An arithmetic progression is a sequence of numbers $a_1, a_2, ..., a_k$ where the difference of consecutive members $a_{i+1} - a_i$ is a constant ($1 \leq i \leq k-1$). For example, the sequence 5, 8, 11, 14, 17 is an arithmetic progression of length 5 with the common difference 3.
In this problem, you are requested to find the longest arithmetic progression which can be formed selecting some numbers from a given set of numbers. For example, if the given set of numbers is {0, 1, 3, 5, 6, 9}, you can form arithmetic progressions such as 0, 3, 6, 9 with the common difference 3, or 9, 5, 1 with the common difference -4. In this case, the progressions 0, 3, 6, 9
and 9, 6, 3, 0 are the longest.
Input
The input consists of a single test case of the following format.
$n$
$v_1$ $v_2$ ... $v_n$
$n$ is the number of elements of the set, which is an integer satisfying $2 \leq n \leq 5000$. Each $v_i$ ($1 \leq i \leq n$) is an element of the set, which is an integer satisfying $0 \leq v_i \leq 10^9$. $v_i$'s are all different, i.e., $v_i \ne v_j$ if $i \ne j$.
Output
Output the length of the longest arithmetic progressions which can be formed selecting some numbers from the given set of numbers.
Sample Input 1
6
0 1 3 5 6 9
Sample Output 1
4
Sample Input 2
7
1 4 7 3 2 6 5
Sample Output 2
7
Sample Input 3
5
1 2 4 8 16
Sample Output 3
2

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using a2 = array<ll, 2>;
using a3 = array<ll, 3>;

bool chmin(auto& a, const auto& b) { return a > b ? a = b, 1 : 0; }
bool chmax(auto& a, const auto& b) { return a < b ? a = b, 1 : 0; }

const ll INF = 1e18;
ll mod = 998244353;

ifstream in;
ofstream out;

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    if (argc > 2) {
        in.open(argv[1]);
        cin.rdbuf(in.rdbuf());
        out.open(argv[2]);
        cout.rdbuf(out.rdbuf());
    }

    ll n;
    cin >> n;
    vector<int> v(n);
    for (auto& x : v) cin >> x;

    vector<ll> v_key;
    vector<ll> v_val;

    sort(v.begin(), v.end());
    int ans = 2;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            int diff = v[j] - v[i];
            ll key = diff * (1LL << 31) + v[i] % diff;
            v_key.push_back(key);
        }
    }

    sort(v_key.begin(), v_key.end());
    v_key.erase(unique(v_key.begin(), v_key.end()), v_key.end());
    v_val.assign(v_key.size(), -INF);
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            int diff = v[j] - v[i];
            ll key = diff * (1LL << 31) + v[i] % diff;
            ll idx = lower_bound(v_key.begin(), v_key.end(), key) - v_key.begin();
            ll now = v_val[idx];
            ll a = now / (1LL << 31);
            ll b = now % (1LL << 31);
            int add = (v[i] / diff - a == 1 ? b + 1 : 2);
            chmax(ans, add);
            v_val[idx] = (v[i] / diff) * (1LL << 31) + add;
        }
    }
    cout << ans << endl;
    return 0;
}
accuracy: 1
time_ms: 2960
memory_kb: 200580
final_rank: 19

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

int main(){
    ll n;
    cin >> n;
    vector<ll> v(n);
    unordered_set<ll> s;
    rep(i, n){
        cin >> v[i];
        s.insert(v[i]);
    }
    sort(v.begin(), v.end());
    ll ans = 1;
    for(ll i = 0; i < n - 1; i++){
        for(ll j = i + 1; j < n; j++){
            ll diff = v[j] - v[i];
            ll cnt = 1;
            while(s.count(v[i] + diff * cnt)){
                cnt++;
            }
            ans = max(cnt, ans);
        }
    }
    cout << ans << endl;
    return 0;
}
accuracy: 1
time_ms: 1220
memory_kb: 3660
final_rank: 6

code_snippet: #include<bits/stdc++.h>
// #include<atcoder/all>
// #include<boost/multiprecision/cpp_int.hpp>

using namespace std;
// using namespace atcoder;
// using bint = boost::multiprecision::cpp_int;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<ll>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using ve = vector<vector<int>>;
using vb = vector<bool>;
using vvb = vector<vb>;
#define rep(i,s,n) for(ll i = (ll)s;i < (ll)n;i++)
#define rrep(i,l,r) for(ll i = r-1;i >= l;i--)
#define ALL(x) (x).begin(),(x).end()
#define sz(c) ((ll)(c).size())
#define LB(A,x) (int)(lower_bound(A.begin(),A.end(),x)-A.begin())
#define UB(A,x) (int)(upper_bound(A.begin(),A.end(),x)-A.begin())
// #define MOD 1000000007
#define MOD 998244353
template<typename T>using min_priority_queue=priority_queue<T,vector<T>,greater<T>>;
template<typename T>ostream&operator<<(ostream&os,vector<T>&v){for(int i = 0;i < 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;}
template<typename T1,typename T2>ostream&operator<<(ostream&os,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> inline bool chmax(T &a,T b){if(a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a,T b){if(a > b){a = b;return true;}return false;}
ld dist(ld x1,ld y1,ld x2, ld y2){return sqrtl((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));}


int main(){
  
  ios_base::sync_with_stdio(0), cin.tie(0);
  int n;cin >> n;
  vi a(n);cin >> a;
  sort(ALL(a));
  vvi dp(n,vi(n,-1));
  vi cor(a);
  sort(ALL(cor));cor.erase(unique(ALL(cor)),cor.end());
  rep(i,1,n){
    vi idx(sz(cor),-1);
    rep(j,0,i){
      int k = LB(cor,2*a[j]-a[i]);
      if(k >= sz(cor) || cor[k] != 2*a[j]-a[i] || idx[k] == -1 || dp[j][idx[k]] == -1)chmax(dp[i][j],2ll);
      else chmax(dp[i][j],dp[j][idx[k]] + 1);
      idx[LB(cor,a[j])] = j;
    }
  }
  ll res = 0;
  rep(i,0,n)rep(j,0,n)chmax(res,dp[i][j]);
  cout << res << endl;
  

  return 0;
}
accuracy: 1
time_ms: 700
memory_kb: 198680
final_rank: 17

code_snippet: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, pair<ll, ll> > P3;
const ll MOD = 1000000007;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(1e5 + 5);
const double EPS = 1e-10;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()


int n, a[5005], dp[5005][5005]; // いまi番目その前にj番目を使ったときの最長

int main() {
    cin >> n;
    REP(i,n) cin >> a[i];
    sort(a,a+n);
    REP(i,n)fill(dp[i],dp[i]+n,2);
    REP(i,n){
        REP(j,i){
            int dif = a[i]-a[j], k;
            k = lower_bound(a,a+n,a[i]+dif) -a;
            if(k < n && a[k] == a[i]+dif){
                dp[k][i] = max(dp[k][i], dp[i][j] + 1);
            }
        }
    }
    int ans = 0;
    REP(i,n)REP(j,i) ans = max(ans, dp[i][j]);
    cout << ans << endl;
    return 0;
}
accuracy: 1
time_ms: 270
memory_kb: 101144
final_rank: 11

code_snippet: #include<bits/stdc++.h>
using namespace std;
const int N=5010;
int n,a[N],f[N][N],ans;
int main()
{
	ios::sync_with_stdio(0),cin.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	sort(a+1,a+n+1);
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<i;j++)
		{
			int k=lower_bound(a+1,a+j+1,a[j]*2-a[i])-a;
			if(a[j]-a[k]==a[i]-a[j]&&f[j][k]) f[i][j]=f[j][k]+1;
			else f[i][j]=2;
			ans=max(ans,f[i][j]);
		}
	} 
	cout<<ans<<"\n";
	return 0;
}
accuracy: 1
time_ms: 250
memory_kb: 99736
final_rank: 9

code_snippet: #include<bits/stdc++.h>
using namespace std;
const int N=5010;
int n,a[N],ans=1,f[N][N];
int main()
{
    ios::sync_with_stdio(0),cin.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i];
    sort(a+1,a+n+1);
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<i;j++) 
        {
            int k=lower_bound(a+1,a+j+1,a[j]*2-a[i])-a;
            if(k<j&&a[i]-a[j]==a[j]-a[k]) f[i][j]=f[j][k]+1;
            else f[i][j]=2;
            ans=max(ans,f[i][j]);
        }
    }
    cout<<ans<<"\n";
    return 0;
}
accuracy: 1
time_ms: 230
memory_kb: 99740
final_rank: 8

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


using namespace std;
//make -f ../makefile SRC=
/*
WA on test 7 ??
*/


//------------------------------------------------------------------------------
bool DEBUG = false;
//const int64_t INF = 9223372036854775807L;
const int INF = 2147483647;

const int MAX_N = 5000;
static int vect[MAX_N];

//------------------------------------------------------------------------------
vector<int> AP(int N, int start, int diff)
{
    vector<int> R = { start };
    while (true)
    {
        auto it = lower_bound(vect+start, vect+N, vect[start]+diff);
        if (it == vect+N || *it > vect[start]+diff) break;
        start = distance(vect, it);
        R.push_back(start);
    }
    return R;
}

//------------------------------------------------------------------------------
int solve(int N)
{
    //--------------------------------------------------------------------------
    // base cases:
    if (N == 2) return 2;
    //--------------------------------------------------------------------------
    // init:
    sort(vect, vect+N);
    if (DEBUG) {printf("vect: "); for (int i=0; i<N; ++i) printf("%d ",vect[i]); printf("\n");}
    set<int> diffs;
    //--------------------------------------------------------------------------
    // compute:
    for (int i=0; i<N-1; ++i)
        for (int j=i+1; j<N; ++j)
            diffs.insert( vect[j]-vect[i] );

    vector<int> R;
    for (int diff: diffs)
    {
        for (int i=0; i<N; ++i)
        {
            if (N-i < R.size()) break;
            if (!R.empty() && binary_search(R.begin(), R.end(), i)) continue;
            vector<int> R1 = AP(N, i, diff);
            if (R1.size() > R.size()) R = R1;
        }
        
    }
    //--------------------------------------------------------------------------
    // report:
    int res = R.size();
    return res;
}

//------------------------------------------------------------------------------
void test()
{

}

//------------------------------------------------------------------------------
int main()
{
    //test(); return 0;
    //DEBUG = true;
    //--------------------------------------------------------------------------
    int N, num;
    num = scanf("%d ", &N);
    for (int i=0; i<N; ++i) num = scanf("%d ", &vect[i]);
    int res = solve(N);
    printf("%d\n", res);
    //--------------------------------------------------------------------------
    return 0;
}
//------------------------------------------------------------------------------
accuracy: 0.45454545454545453
time_ms: 4100
memory_kb: 15320
final_rank: 20

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define ALL(a) begin(a), end(a)
#define rep(i,j,k) for(int (i)=(j);(i)<(k);(i)++)
int main(){
	int N;
	cin>>N;
	vector<ll>A(N);
	rep(i,0,N)cin>>A[i];
	sort(ALL(A));
	unordered_set<ll> S;
	rep(i,0,N)S.insert(A[i]);
	ll ans=0;

	rep(i,0,N-1){
		rep(j,i+1,N){
			ll e=A[j]-A[i];
			ll f=A[i];
			ll g=1;
			while(1){
				if(S.find(f+e)!=S.end()){
					g++;
					f+=e;
				}else{
					break;
				}
			}
			ans=max(ans,g);
		}
	}
	cout<<ans<<endl;
	return 0;
}
accuracy: 1
time_ms: 280
memory_kb: 3840
final_rank: 1

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,l,n) for(int i=l;i<n;i++)
#define all(v) v.begin(), v.end()

int main() {
    int n;cin >> n;
    vector<int> v(n);
    rep(i, n)cin >> v[i];
    sort(all(v));
    const int inf = 1e9;
    vector<vector<int>> dp(n, vector<int>(n, -inf));
    int ans = 1;

    rep(i, n) {
        rep(j, i) {
            int k = (lower_bound(all(v), v[j] * 2 - v[i]) - v.begin()); 
            if (k < n and v[k] == v[j] * 2 - v[i]) dp[i][j] = max(dp[i][j], dp[j][k] + 1);
            else dp[i][j] = max(dp[i][j], 2);
            ans = max(ans, dp[i][j]);
        }
    }

    cout << ans << endl;
}
accuracy: 1
time_ms: 310
memory_kb: 101028
final_rank: 13

code_snippet: #include<bits/stdc++.h>
#define rep(i,s,n) for (int i = (int)(s); i < (int)(n); i++)
#define all(v) begin(v),end(v)
using namespace std;
using ll = long long;
bool chmin(auto &a, auto b){ return a > b ? a = b, 1 : 0; }
bool chmax(auto &a, auto b){ return a < b ? a = b, 1 : 0; }

typedef array<int,3> ar;

int main() {
    cin.tie(0)->sync_with_stdio(0);
    int n; cin >> n;
    vector<int> a(n);
    rep(i,0,n) cin >> a[i];
    sort(all(a));

    vector<ar> x;
    x.reserve(n * (n-1) / 2);
    rep(i,0,n) {
        rep(j,0,i) {
            int v = a[i] - a[j];
            x.push_back(ar{v, a[j] % v, a[j]});
        }
    }
    sort(all(x));

    int memo1 = x[0][0]; // v
    int memo2 = x[0][1]; // last % v
    int tmp = x[0][2] - x[0][0];
    int now = 1;
    int ans = 0;
    rep(i,0,(int)x.size()) {
        auto [p, q, r] = x[i];
        if (memo1 == p && memo2 == q && tmp + p == r) {
            now += 1;
            tmp = r;
        } else {
            chmax(ans, now);
            memo1 = p;
            memo2 = q;
            tmp = r;
            now = 2;
        }
    }
    chmax(ans, now);
    cout << ans << '\n';
}
accuracy: 1
time_ms: 1580
memory_kb: 149904
final_rank: 16

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

inline bool is_number(char c) {
    return ('0' <= c && c <= '9');
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<long long> A(N);
    for(int i = 0; i < N; i++) {
        cin >> A[i];
    }
    sort(A.begin(), A.end());
    vector dp(N, vector(N, 0));
    int ans = 0;
    for(int i = 0; i < N; i++) {
        for(int j = i + 1; j < N; j++) {
            auto it = lower_bound(A.begin(), A.end(), 2 * A[i] - A[j]);
            int k = it - A.begin();
            dp[i][j] = max(2, dp[i][j]);
            if(A[k] - A[i] == A[i] - A[j]) dp[i][j] = max(dp[i][j], dp[k][i] + 1);
            ans = max(ans, dp[i][j]);
        }
    }

    cout << ans << "\n";

    return 0;
}
accuracy: 1
time_ms: 250
memory_kb: 101248
final_rank: 10

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define ALL(v) v.begin(),v.end()
#define dbg(x) cerr << #x << ": " << x << endl;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) cin >> a[i];
    sort(a.begin(), a.end());
    vector<vector<int>> dp(n, vector<int> (n, 2));
    for (int i = 0; i < n; ++i)
    {
        for (int j = i + 1; j < n; ++j)
        {
            auto id = lower_bound(a.begin(), a.end(), 2 * a[j] - a[i]) - a.begin();
            if (a[id] == 2 * a[j] - a[i]) dp[j][id] = max(dp[j][id], dp[i][j] + 1);
        }
    }
    int ans = 0;
    for (int i = 0; i < n; ++i) for (int j = i + 1; j < n; ++j) ans = max(ans, dp[i][j]);
    cout << ans << endl;
}
accuracy: 1
time_ms: 300
memory_kb: 101024
final_rank: 12

code_snippet: // #pragma GCC target("avx2")
#pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
// #include<atcoder/modint>
// #include<sys/time.h>
using namespace std;

const int M = 1000000007;
const long long LM = 1LL << 60;
using P = pair<int, int>;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    vector<vector<int>> dp(n, vector<int>(n));
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0, k = 0; j < i; ++j) {
            while (a[k] < a[j] * 2 - a[i]) {
                ++k;
            }
            if (a[k] == a[j] * 2 - a[i]) {
                dp[i][j] = dp[j][k] + 1;
                ans = max(ans, dp[i][j]);
            }
        }
    }
    cout << ans + 2 << '\n';

    return 0;
}
accuracy: 1
time_ms: 90
memory_kb: 100876
final_rank: 7

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> V(N);
    rep(i,0,N) cin >> V[i];
    sort(ALL(V));
    vector<int> mp;
    rep(i,0,N) {
        rep(j,i+1,N) {
            mp.push_back(V[j]-V[i]);
        }
    }
    UNIQUE(mp);
    int ID = mp.size();
    vector<pair<int,int>> G;
    rep(i,0,N) {
        rep(j,i+1,N) {
            int X = LB(mp,V[j]-V[i]);
            G.push_back({X,i*5000+j});
        }
    }
    sort(ALL(G));
    int ANS = 0;
    int L = 0, R;
    vector<int> DP(N,0);
    rep(i,0,ID) {
        R = L;
        while(R < G.size() && G[R].first == i) {
            R++;
        }
        rep(j,L,R) {
            auto [_,Q] = G[j];
            pair<int,int> P = {Q/5000,Q%5000};
            DP[P.second] = DP[P.first] + 1;
            chmax(ANS,DP[P.second]);
        }
        rep(j,L,R) {
            auto [_,Q] = G[j];
            pair<int,int> P = {Q/5000,Q%5000};
            DP[P.first] = DP[P.second] = 0;
        }
        L = R;
    }
    cout << ANS + 1 << endl;
}
accuracy: 1
time_ms: 2830
memory_kb: 185748
final_rank: 18

code_snippet: #include <bits/stdc++.h>
//#include <atcoder/all>
using ll = long long;
const int MOD = 1000000007;
const int Mod = 998244353;
const int MAX = 1000000005;
const long long INF = 1000000000000000005LL;
using namespace std;
//using namespace atcoder;



int main() {
    ios::sync_with_stdio(0); cin.tie();
    int n;
    cin >> n;
    vector<int> A(n);
    for (int i = 0; i < n; i++) cin >> A[i];
    sort(A.begin(), A.end());
    vector<vector<bool>> done(n, vector<bool>(n));
    int ans = 2;
    for (int i = 0; i < n-1; i++) {
        for (int j = i+1; j < n; j++) {
            if (done[i][j] != 0) continue;
            int d = A[j] - A[i], now = j, len = 2;
            while (1) {
                auto itr = lower_bound(A.begin(), A.end(), A[now]+d);
                if (itr == A.end() || *itr != A[now]+d) break;
                len++;
                int nxt = (int)(itr - A.begin());
                done[now][nxt] = true;
                now = nxt;
            }
            ans = max(ans, len);
        }
    }
    cout << ans << endl;
}
accuracy: 1
time_ms: 360
memory_kb: 6548
final_rank: 2

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];
    std::sort(a.begin(), a.end());
    std::vector checked(n, std::vector<bool>(n));
    std::set<std::pair<int, int>> s;
    for (int i = 0; i < n; i++) s.emplace(a[i], i);

    int ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            if (checked[i][j]) continue;
            checked[i][j] = true;
            int diff = a[j] - a[i];
            int val = a[j];
            int now = 2;
            int from = j;
            while (true) {
                auto it = s.lower_bound({val + diff, -1});
                if (it == s.end()) break;
                auto [v, to] = *it;
                if (v == val + diff) {
                    if (checked[from][to]) break;
                    checked[from][to] = true;
                    val += diff;
                    now++;
                    from = to;
                } else {
                    break;
                }
            }
            ans = std::max(ans, now);
        }
    }
    std::cout << ans << std::endl;
}
accuracy: 1
time_ms: 450
memory_kb: 6808
final_rank: 3

code_snippet: #include <stdio.h>
#include <iostream>
#include <map>
#include <algorithm>

using namespace std;
#define ll long long

int n;
int v[5000];

map<int,int> llmap;

int main()
{

  cin>>n;
  for(int i=0;i<n;i++){
    cin>>v[i];
    llmap[v[i]]=10;
  }
  sort(v,v+n);

  int ans=2;
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      int sa = v[j]-v[i];
      int now=v[j];
      int anss=2;
      while(true){
        if(llmap.find(now+sa)==llmap.end())break;
        anss++;
        now+=sa;
      }
      ans=max(ans,anss);
    }
  }
  cout<<ans<<endl;

  return 0;
}
accuracy: 1
time_ms: 4560
memory_kb: 3692
final_rank: 15

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

int main() {
    int n; std::cin >> n;
    std::vector<int> v(n);
    for (auto& a : v) std::cin >> a;
    std::sort(v.begin(), v.end());
    std::map<int, int> map;
    for (int i{} ; i < n ; i++) map[v[i]] = i;
    std::vector table(n, std::vector<bool>(n));
    int ans{2};
    for (int i{} ; i < n ; i++) for (int j{i + 1} ; j < n ; j++) {
        if (table[i][j]) continue;
        table[i][j] = true;
        int d{v[j] - v[i]};
        int len{2}, now{v[j]}, idx{j};
        while (1) {
            auto it{map.find(now + d)};
            if (it == map.end()) break;
            table[idx][it->second] = true;
            len++;
            now = it->first;
            idx = it->second;
        }
        ans = std::max(ans, len);
    }
    std::cout << ans << '\n';
}
accuracy: 1
time_ms: 490
memory_kb: 6812
final_rank: 4

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

#define rep(i, s, n) for (int i = int(s); i < int(n); i++)
#define rrep(i, s, n) for (int i = int(n) - 1; i >= int(s); i--)
#define all(v) (v).begin(), (v).end()

using ll = long long;
using ull = unsigned long long;
using ld = long double;

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

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

using namespace std;
using uint = unsigned int;
const uint mx = 1u << 31;

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<uint> a(n);
    rep(i,0,n) cin >> a[i];
    //rep(i,0,n) a[i] = i+1;
    sort(all(a));
    unordered_set<uint> st;
    rep(i,0,n) st.insert(a[i]);
    int ans = 2;
    rep(i,0,n){
        rep(j,i+1,n){
            uint d = a[j] - a[i];
            int len = 2;
            for (uint s = a[i]+d+d; s < mx; s += d){
                if (st.find(s) == st.end()) break;
                len++;
            }
            chmax(ans,len);
        }
    }
    cout << ans << endl;
}
accuracy: 1
time_ms: 620
memory_kb: 3680
final_rank: 5

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

using ll=long long;

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

  sort(v.begin(),v.end());

  ll ans=2;
  for(ll i=0;i<n;++i){
    for(ll j=i+1;j<n;++j){
      ll d=v[j]-v[i];
      for(ll k=2;;++k){
        if(binary_search(v.begin(),v.end(),v[i]+d*k)){
          ans=max(ans,k+1);
        }else{
          break;
        }
      }
    }
  }
  cout<<ans<<endl;
}
accuracy: 1
time_ms: 3800
memory_kb: 3464
final_rank: 14