Language: C++

#include <iostream>
#include <unordered_map>

using namespace std;

int main()
{
  uint64_t n, m;
  cin >> n >> m;
  uint64_t a[n];
  for (auto i = 0; i < n; i++) {
    uint64_t v;
    cin >> v;
    a[i] = v;
  }
  uint64_t b[n + 1];
  b[0] = 0;
  uint64_t sum = 0;
  for (auto i = 0; i < n; i++) {
    sum += a[i];
    b[i + 1] = sum;
  }

  unordered_map<uint64_t, uint64_t> um;
  for (auto i = 0; i < n + 1; i++) {
    auto it = um.find(b[i] % m);
    if (it == end(um)) {
      um.insert(pair(b[i] % m, 1));
    } else {
      uint64_t v = it->second;
      um.erase(it);
      um.insert(pair(b[i] % m, v + 1));
    }
  }

  uint64_t ans = 0;
  for (auto&& e : um) {
    uint64_t v = e.second;
    ans += (v * v - v) / 2;
  }

  cout << ans << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:8:3: error: 'uint64_t' was not declared in this scope
    8 |   uint64_t n, m;
      |   ^~~~~~~~
a.cc:3:1: note: 'uint64_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
    2 | #include <unordered_map>
  +++ |+#include <cstdint>
    3 | 
a.cc:9:10: error: 'n' was not declared in this scope
    9 |   cin >> n >> m;
      |          ^
a.cc:9:15: error: 'm' was not declared in this scope; did you mean 'tm'?
    9 |   cin >> n >> m;
      |               ^
      |               tm
a.cc:10:11: error: expected ';' before 'a'
   10 |   uint64_t a[n];
      |           ^~
      |           ;
a.cc:12:13: error: expected ';' before 'v'
   12 |     uint64_t v;
      |             ^~
      |             ;
a.cc:13:12: error: 'v' was not declared in this scope
   13 |     cin >> v;
      |            ^
a.cc:14:5: error: 'a' was not declared in this scope
   14 |     a[i] = v;
      |     ^
a.cc:16:11: error: expected ';' before 'b'
   16 |   uint64_t b[n + 1];
      |           ^~
      |           ;
a.cc:17:3: error: 'b' was not declared in this scope
   17 |   b[0] = 0;
      |   ^
a.cc:18:11: error: expected ';' before 'sum'
   18 |   uint64_t sum = 0;
      |           ^~~~
      |           ;
a.cc:20:5: error: 'sum' was not declared in this scope
   20 |     sum += a[i];
      |     ^~~
a.cc:20:12: error: 'a' was not declared in this scope
   20 |     sum += a[i];
      |            ^
a.cc:24:35: error: template argument 3 is invalid
   24 |   unordered_map<uint64_t, uint64_t> um;
      |                                   ^
a.cc:24:35: error: template argument 4 is invalid
a.cc:24:35: error: template argument 5 is invalid
a.cc:26:18: error: request for member 'find' in 'um', which is of non-class type 'int'
   26 |     auto it = um.find(b[i] % m);
      |                  ^~~~
a.cc:27:18: error: no matching function for call to 'end(int&)'
   27 |     if (it == end(um)) {
      |               ~~~^~~~
In file included from /usr/include/c++/14/bits/range_access.h:36,
                 from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/initializer_list:99:5: note: candidate: 'template<class _Tp> constexpr const _Tp* std::end(initializer_list<_Tp>)'
   99 |     end(initializer_list<_Tp> __ils) noexcept
      |     ^~~
/usr/include/c++/14/initializer_list:99:5: note:   template argument deduction/substitution failed:
a.cc:27:18: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   27 |     if (it == end(um)) {
      |               ~~~^~~~
/usr/include/c++/14/bits/range_access.h:74:5: note: candidate: 'template<class _Container> constexpr decltype (__cont.end()) std::end(_Container&)'
   74 |     end(_Container& __cont) -> decltype(__cont.end())
      |     ^~~
/usr/include/c++/14/bits/range_access.h:74:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/range_access.h: In substitution of 'template<class _Container> constexpr decltype (__cont.end()) std::end(_Container&) [with _Container = int]':
a.cc:27:18:   required from here
   27 |     if (it == end(um)) {
      |               ~~~^~~~
/usr/include/c++/14/bits/range_access.h:74:48: error: request for member 'end' in '__cont', which is of non-class type 'int'
   74 |     end(_Container& __cont) -> decltype(__cont.end())
      |                                         ~~~~~~~^~~
/usr/include/c++/14/bits/range_access.h:85:5: note: candidate: 'template<class _Container> constexpr decltype (__cont.end()) std::end(const _Container&)'
   85 |     end(const _Container& __cont) -> decltype(__cont.end())
      |     ^~~
/usr/include/c++/14/bits/range_access.h:85:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/range_access.h: In substitution of 'template<class _Container> constexpr decltype (__cont.end()) std::end(const _Container&) [with _Container = int]':
a.cc:27:18:   required from here
   27 |     if (it == end(um)) {
      |               ~~~^~~~
/usr/include/c++/14/bits/range_access.h:85:54: error: request for member 'end' in '__cont', which is of non-class type 'const int'
   85 |     end(const _Container& __cont) -> decltype(__cont.end())
      |                                               ~~~~~~~^~~
/usr/include/c++/14/bits/range_access.h:106:5: note: candidate: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::end(_Tp (&)[_Nm])'
  106 |     end(_Tp (&__arr)[_Nm]) noexcept
      |     ^~~
/usr/include/c++/14/bits/range_access.h:106:5: note:   template argument deduction/substitution failed:
a.cc:27:18: note:   mismatched types '_Tp [_Nm]' and 'int'
   27 |     if (it == end(um)) {
      |               ~~~^~~~
/usr/include/c++/14/bits/range_access.h:115:31: note: candidate: 'template<class _Tp> _Tp* std::end(valarray<_Tp>&)'
  115 |   template<typename _Tp> _Tp* end(valarray<_Tp>&) noexcept;
      |                               ^~~
/usr/include/c++/14/bits/range_access.h:115:31: note:   template argument deduction/substitution failed:
a.cc:27:18: note:   mismatched types 'std::valarray<_Tp>' and 'int'
   27 |     if (it == end(um)) {
      |               ~~~^~~~
/usr/include/c++/14/bits/range_access.h:116:37: note: candidate: 'template<class _Tp> const _Tp* std::end(const valarray<_Tp>&)'
  116 |   template<typename _Tp> const _Tp* end(const valarray<_Tp>&) noexcept;
      |                                     ^~~
/usr/include/c++/14/bits/range_access.h:116:37: note:   template argument deduction/substitution failed:
a.cc:27:18: note:   mismatched types 'const std::valarray<_Tp>' and 'int'
   27 |     if (it == end(um)) {
      |               ~~~^~~~
a.cc:28:10: error: request for member 'insert' in 'um', which is of non-class type 'int'
   28 |       um.insert(pair(b[i] % m, 1));
      |          ^~~~~~
a.cc:30:15: error: expected ';' before 'v'
   30 |       uint64_t v = it->second;
      |               ^~
      |               ;
a.cc:31:10: error: request for member 'erase' in 'um', which is of non-class type 'int'
   31 |       um.erase(it);
      |          ^~~~~
a.cc:32:10: error: request for member 'insert' in 'um', which is of non-class type 'int'
   32 |       um.insert(pair(b[i] % m, v + 1));
      |          ^~~~~~
a.cc:32:32: error: 'v' was not declared in this scope
   32 |       um.insert(pair(b[i] % m, v + 1));
      |                                ^
a.cc:36:11: error: expected ';' before 'ans'
   36 |   uint64_t ans = 0;
      |           ^~~~
      |           ;
a.cc:37:19: error: 'begin' was not declared in this scope; did you mean 'std::begin'?
   37 |   for (auto&& e : um) {
      |                   ^~
      |                   std::begin
/usr/include/c++/14/bits/range_access.h:114:37: note: 'std::begin' declared here
  114 |   template<typename _Tp> const _Tp* begin(const valarray<_Tp>&) noexcept;
      |                                     ^~~~~
a.cc:37:19: error: 'end' was not declared in this scope; did you mean 'std::end'?
   37 |   for (auto&& e : um) {
      |                   ^~
      |                   std::end
/usr/include/c++/14/bits/range_access.h:116:37: note: 'std::end' declared here
  116 |   template<typename _Tp> const _Tp* end(const valarray<_Tp>&) noexcept;
      |                                     ^~~
a.cc:38:13: error: expected ';' before 'v'
   38 |     uint64_t v = e.second;
      |             ^~
      |             ;
a.cc:39:5: error: 'ans' was not declared in this scope; did you mean 'abs'?
   39 |     ans += (v * v - v) / 2;
      |     ^~~
      |     abs
a.cc:39:13: error: 'v' was not declared in this scope
   39 |     ans += (v * v - v) / 2;
      |             ^
a.cc:42:11: error: 'ans' was not declared in this scope; did you mean 'abs'?
   42 |   cout << ans << endl;
      |           ^~~
      |           abs