#include<iostream> #define MAX 4123 usingnamespacestd;
int data[MAX]; int dp[MAX][MAX];
intmain() { int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> data[i]; }
int ans = 1; for (int i = 1; i <= n; i++) { int k = -1; for (int j = 1; j < i; j++) { if (k == -1) dp[i][j] = 2; else dp[i][j] = dp[j][k] + 1; if (data[i] == data[j]) k = j; if (ans < dp[i][j]) ans = dp[i][j]; } } cout << ans; }
set<int> check; vector<int> store; int data[41234]; int n;
intscan(int a, int b) { int judge = 0; int sum = 0; for (int i = 0; i < n; i++) { if (judge == 0 && (data[i] == a || data[i] == b) || data[i] == judge) { if (data[i] == a) { judge = b; } if (data[i] == b) { judge = a; } sum++; } } return sum; }
intmain() { cin >> n; for (int i = 0; i < n; i++) { cin >> data[i]; if (check.count(data[i]) == 0) { check.insert(data[i]); store.push_back(data[i]); } } int ans = 0; for (int i = 0; i < store.size(); i++) { for (int j = i; j < store.size(); j++) { int t = scan(data[i], data[j]); ans = ans > t? ans:t; } } cout << ans; }