fork download
  1. #include<stdio.h>
  2. int mnw[7], mxw[7];
  3. int main() {
  4. int n, i, s = 0, x, ans = 0;
  5. scanf("%d", &n);
  6. for (i = 1; i <= n; i++) {
  7. scanf("%d", &x);
  8. s = (s + x) % 7;
  9. if (s != 0 && mnw[s] == 0)mnw[s] = i;
  10. mxw[s] = i;
  11. }
  12. for (i = 0; i < 7; i++)if (ans < mxw[i] - mnw[i])ans = mxw[i] - mnw[i];
  13. printf("%d", ans);
  14. return 0;
  15. }
Success #stdin #stdout 0s 4176KB
stdin
7
3
5
1
6
2
14
10
stdout
5