fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. using ll = long long;
  5.  
  6. int main() {
  7.  
  8. int n;
  9. cin >> n;
  10.  
  11. vector<ll> a(n);
  12. for (auto &x : a)
  13. cin >> x;
  14.  
  15. if (n <= 1) {
  16. cout << n << '\n';
  17. return 0;
  18. }
  19.  
  20. ll diff = a[1] - a[0];
  21. int len = 2;
  22. int ans = 2;
  23.  
  24. for (int i = 2; i < n; i++) {
  25. ll currDiff = a[i] - a[i - 1];
  26.  
  27. if (currDiff == diff) {
  28. len++;
  29. } else {
  30. diff = currDiff;
  31. len = 2;
  32. }
  33.  
  34. ans = max(ans, len);
  35. }
  36.  
  37. cout << ans << '\n';
  38.  
  39. return 0;
  40. }
Success #stdin #stdout 0s 5312KB
stdin
Standard input is empty
stdout
0