Advertisement
OIQ

Untitled

OIQ
May 19th, 2021
875
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.37 KB | None
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.    
  8.     int n;
  9.     cin >> n;
  10.  
  11.     vector <int> a(n, 0);
  12.     vector <int> b(3, 0);
  13.  
  14.     for (int i = 0; i < n; i++)
  15.         cin >> a[i];
  16.  
  17.     long ans = 0;
  18.    
  19.     for (int i = 0; i < n; i++)
  20.         if (a[i] % 3 == 0) {
  21.             ans += i / 3;
  22.             b[i % 3]++;
  23.         }
  24.         else
  25.             ans += b[i % 3];
  26.  
  27.     cout << ans;
  28.  
  29.     return 0;
  30. }
Advertisement
RAW Paste Data Copied
Advertisement