fork(1) download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int t, n, a, c, b, y, x, najw;
  6.  
  7. int main()
  8. {
  9. ios_base::sync_with_stdio(0);
  10. cin>>t;
  11. while(t--)
  12. {
  13. najw=0;
  14. y=1;
  15. x=2;
  16. cin>>n;
  17. cin>>a;
  18.  
  19. if(n==1)
  20. {
  21. cout<<"1"<<endl;
  22. continue;
  23. }
  24. cin>>b; n-=2;
  25. while(a==b&&n!=0)
  26. {
  27. cin>>b;
  28. x++;
  29. y++;
  30. }
  31. if(!n)
  32. {
  33. cout<<x<<endl; continue;
  34. }
  35. while(n--)
  36. {
  37. cin>>c;
  38. if(b==c)
  39. {
  40. x++;
  41. y++;
  42. }
  43. else if(c==a)
  44. {
  45. y=1;
  46. x++;
  47. a=b;
  48. b=c;
  49. }
  50.  
  51. else
  52. {
  53. if(x>najw)
  54. najw=x;
  55.  
  56. x=y+1;
  57. y=1;
  58. a=b;
  59. b=c;
  60. }
  61. }
  62. if(x>najw)
  63. najw=x;
  64. cout<<najw<<endl;
  65.  
  66.  
  67. }
  68. return 0;
  69. }
  70.  
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
Standard output is empty