fork download
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define int long long
  6.  
  7. int n;
  8. vector<int> a;
  9.  
  10. namespace sub1 { /// TONGCHAN_trau
  11. bool check() {
  12. if (n <= 1000) return true;
  13. else return false;
  14. }
  15.  
  16. void solve() {
  17. cerr << "run sub1: \n"; /// Nen viet 1 dong cerr de quan sat xem no co chay dc sub do hay ko?
  18. int sum = 0;
  19. for (int i = 1; i <= n; i++)
  20. sum += a[i];
  21. int ans = 0;
  22. for (int i = 1; i <= n; i++) {
  23. for (int j = i + 1; j <= n; j++) {
  24. if ((sum - a[i] - a[j]) % 2 == 0)
  25. ans++;
  26. }
  27. }
  28. cout << ans;
  29. }
  30. };
  31.  
  32. namespace sub2 { /// TONGCHAN.cpp
  33. bool check() {
  34. return n > 1000;
  35. }
  36.  
  37. int c,l,sum;
  38. void solve() {
  39. cerr << "run sub2: \n"; /// Nen viet 1 dong cerr de quan sat xem no co chay dc sub do hay ko?
  40. for (int i = 1; i <= n; i++) {
  41. sum+=a[i];
  42. if (a[i] % 2 == 0) c++;
  43. else l++;
  44. }
  45. if (sum % 2 == 0)
  46. cout << (c*(c-1)/2) + (l*(l-1)/2);
  47. else cout << c*l;
  48. }
  49. };
  50.  
  51. signed main() {
  52. freopen("TONGCHAN.INP", "r",stdin);
  53. freopen("TONGCHAN.OUT", "w", stdout);
  54. ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  55. cin >> n;
  56. a.resize(n + 1);
  57. for (int i = 1; i <= n; i++) {
  58. cin >> a[i];
  59. }
  60.  
  61. /// return sub2::solve(), 0; Neu nhu muon test tung sub
  62.  
  63. if (sub1::check()) return sub1::solve(), 0;
  64. if (sub2::check()) return sub2::solve(), 0;
  65. }
  66.  
Success #stdin #stdout #stderr 0.01s 5288KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
run sub1: