Language: C++

//g++ -std=c++14 test.cpp -o test.out
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
using namespace std;
 
#define LL long long int
const LL INF = (LL)(1e18)+1;
const LL mod = 1000000007ll;

template <int mod>
struct ModInt {
  int x;
  ModInt() : x(0) {}
  ModInt(int64_t y)
      : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
  ModInt &operator+=(const ModInt &p) {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }
  ModInt &operator-=(const ModInt &p) {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }
  ModInt &operator*=(const ModInt &p) {
    x = (int)(1LL * x * p.x % mod);
    return *this;
  }
  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }
  ModInt operator-() const { return ModInt(-x); }
  ModInt operator+(const ModInt &p) const {
    return ModInt(*this) += p;
  }
  ModInt operator-(const ModInt &p) const {
    return ModInt(*this) -= p;
  }
  ModInt operator*(const ModInt &p) const {
    return ModInt(*this) *= p;
  }
  ModInt operator/(const ModInt &p) const {
    return ModInt(*this) /= p;
  }
  bool operator==(const ModInt &p) const {
    return x == p.x;
  }
  bool operator!=(const ModInt &p) const {
    return x != p.x;
  }
  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }
  ModInt pow(int64_t n) const {
    ModInt ans(1), mul(x);
    while(n) {
      if(n & 1) ans *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ans;
  }
  friend ostream &operator<<(ostream &os, const ModInt &p) {
    return os << p.x;
  }
  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt<mod>(t);
    return (is);
  }
  static int get_mod() { return mod; }
};

LL N;
LL C[200000];

ModInt<mod> ans = 0;
 
void solve(){
	int pow2[200001];
	pow2[0] = 1;
	for(int i=1;i<=N;i++){
		pow2[i] = pow2[i-1]<<1;
		pow2[i]%=mod;
	}
	sort(C,C+N);
	//Sの変更箇所だけを見れば良いのでS xor T をXとおいたとき、Xの01の配列ごとに計算すれば良い
	//例えばX = 0....0とかなら変更箇所0、つまりコスト0
	//まずS=0に固定してansを求め、最後に2^Nをかける
	for(int i=0;i<N;i++){
		int r = N-1-i;//今見ている桁
		ModInt<mod> digit = r;
		ModInt<mod> cost = C[i];
		//diff_bit_numberはr桁目を見ているとき、反転させたいビットがいくつあるかを表す
		//diff_bit_number = (pow2[r] + r*pow2[r-1]) * pow2[i]
		ModInt<mod> diff_bit_number = pow2[r];
		if(digit>0) diff_bit_number += (digit*pow2[r-1]);
		diff_bit_number *= pow2[i];
		ans += (cost*diff_bit_number);
	}
	ans *= pow2[N];
}
 
int main(){
	cin >> N;
	for(int i=0;i<N;i++) cin >> C[i];
 
	solve();

	cout << ans << endl;
	return 0;
}

Compiler output:
a.cc: In function 'void solve()':
a.cc:115:25: error: no match for 'operator>' (operand types are 'ModInt<1000000007>' and 'int')
  115 |                 if(digit>0) diff_bit_number += (digit*pow2[r-1]);
      |                    ~~~~~^~
      |                    |     |
      |                    |     int
      |                    ModInt<1000000007>
In file included from /usr/include/c++/14/bits/stl_algobase.h:64,
                 from /usr/include/c++/14/bits/specfun.h:43,
                 from /usr/include/c++/14/cmath:3906,
                 from /usr/include/c++/14/math.h:36,
                 from a.cc:4:
/usr/include/c++/14/bits/stl_pair.h:1058:5: note: candidate: 'template<class _T1, class _T2> constexpr bool std::operator>(const pair<_T1, _T2>&, const pair<_T1, _T2>&)'
 1058 |     operator>(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:1058:5: note:   template argument deduction/substitution failed:
a.cc:115:26: note:   'ModInt<1000000007>' is not derived from 'const std::pair<_T1, _T2>'
  115 |                 if(digit>0) diff_bit_number += (digit*pow2[r-1]);
      |                          ^
In file included from /usr/include/c++/14/bits/stl_algobase.h:67:
/usr/include/c++/14/bits/stl_iterator.h:462:5: note: candidate: 'template<class _Iterator> constexpr bool std::operator>(const reverse_iterator<_Iterator>&, const reverse_iterator<_Iterator>&)'
  462 |     operator>(const reverse_iterator<_Iterator>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:462:5: note:   template argument deduction/substitution failed:
a.cc:115:26: note:   'ModInt<1000000007>' is not derived from 'const std::reverse_iterator<_Iterator>'
  115 |                 if(digit>0) diff_bit_number += (digit*pow2[r-1]);
      |                          ^
/usr/include/c++/14/bits/stl_iterator.h:507:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr bool std::operator>(const reverse_iterator<_Iterator>&, const reverse_iterator<_IteratorR>&)'
  507 |     operator>(const reverse_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:507:5: note:   template argument deduction/substitution failed:
a.cc:115:26: note:   'ModInt<1000000007>' is not derived from 'const std::reverse_iterator<_Iterator>'
  115 |                 if(digit>0) diff_bit_number += (digit*pow2[r-1]);
      |                          ^
/usr/include/c++/14/bits/stl_iterator.h:1714:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr bool std::operator>(const move_iterator<_IteratorL>&, const move_iterator<_IteratorR>&)'
 1714 |     operator>(const move_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1714:5: note:   template argument deduction/substitution failed:
a.cc:115:26: note:   'ModInt<1000000007>' is not derived from 'const std::move_iterator<_IteratorL>'
  115 |                 if(digit>0) diff_bit_number += (digit*pow2[r-1]);
      |                          ^
/usr/include/c++/14/bits/stl_iterator.h:1774:5: note: candidate: 'template<class _Iterator> constexpr bool std::operator>(const move_iterator<_IteratorL>&, const move_iterator<_IteratorL>&)'
 1774 |     operator>(const move_iterator<_Iterator>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1774:5: note:   template argument deduction/substitution failed:
a.cc:115:26: note:   'ModInt<1000000007>' is not derived from 'const std::move_iterator<_IteratorL>'
  115 |                 if(digit>0) diff_bit_number += (digit*pow2[r-1]);
      |                          ^
In file included from /usr/include/c++/14/functional:53,
                 from a.cc:7:
/usr/include/c++/14/tuple:2619:5: note: candidate: 'template<class ... _TElements, class ... _UElements> constexpr bool std::operator>(const tuple<_UTypes ...>&, const tuple<_Elements ...>&)'
 2619 |     operator>(const tuple<_TElements...>& __t,
      |     ^~~~~~~~
/usr/include/c++/14/tuple:2619:5: note:   template argument deduction/substitution failed:
a.cc:115:26: note:   'ModInt<1000000007>' is not derived from 'const std::tuple<_UTypes ...>'
  115 |                 if(digit>0) diff_bit_number += (digit*pow2[r-1]);
      |                          ^
In file included from /usr/include/c++/14/vector:66,
                 from /usr/include/c++/14/functional:64:
/usr/include/c++/14/bits/stl_vector.h:2102:5: note: candidate: 'template<class _Tp, class _Alloc> bool std::operator>(const vector<_Tp, _Alloc>&, const vector<_Tp, _Alloc>&)'
 2102 |     operator>(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y)
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:2102:5: note:   template argument deduction/substitution failed:
a.cc:115:26: note:   'ModInt<1000000007>' is not derived from 'const std::vector<_Tp, _Alloc>'
  115 |                 if(digit>0) diff_bit_number += (digit*pow2[r-1]);
      |                          ^
In file included from /usr/include/c++/14/functional:65:
/usr/include/c++/14/array:349:5: note: candidate: 'template<class _Tp, long unsigned int _Nm> bool std::operator>(const array<_Tp, _Nm>&, const array<_Tp, _Nm>&)'
  349 |     operator>(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two)
      |     ^~~~~~~~
/usr/include/c++/14/array:349:5: note:   template argument deduction/substitution failed:
a.cc:115:26: note:   'ModInt<1000000007>' is not derived from 'const std::array<_Tp, _Nm>'
  115 |                 if(digit>0) diff_bit_number += (digit*pow2[r-1]);
      |                          ^
In file included from /usr/include/c++/14/bits/basic_string.h:47,
                 from /usr/include/c++/14/string:54,
                 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:8:
/usr/include/c++/14/string_view:695:5: note: candidate: 'template<class _CharT, class _Traits> constexpr bool std::operator>(basic_string_view<_CharT, _Traits>, basic_string_view<_CharT, _Traits>)'
  695 |     operator> (basic_string_view<_CharT, _Traits> __x,
      |     ^~~~~~~~
/usr/include/c++/14/string_view:695:5: note:   template argument deduction/substitution failed:
a.cc:115:26: note:   'ModInt<1000000007>' is not derived from 'std::basic_string_view<_CharT, _Traits>'
  115 |                 if(digit>0) diff_bit_number += (digit*pow2[r-1]);
      |                          ^
/usr/include/c++/14/string_view:702:5: note: candidate: 'template<class _CharT, class _Traits> constexpr bool std::operator>(basic_string_view<_CharT, _Traits>, __type_identity_t<basic_string_view<_CharT, _Traits> >)'
  702 |     operator> (basic_string_view<_CharT, _Traits> __x,
      |     ^~~~~~~~
/usr/include/c++/14/string_view:702:5: note:   template argument deduction/substitution failed:
a.cc:115:26: note:   'ModInt<1000000007>' is not derived from 'std::basic_string_view<_CharT, _Traits>'
  115 |                 if(digit>0) diff_bit_number += (digit*pow2[r-1]);
      |                          ^
/usr/include/c++/14/string_view:710:5: note: candidate: 'template<class _CharT, class _Traits> constexpr bool std::operator>(__type_identity_t<basic_string_view<_CharT, _Traits> >, basic_string_view<_CharT, _Traits>)'
  710 |     operator> (__type_identity_t<basic_string_view<_CharT, _Traits>> __x,
      |     ^~~~~~~~
/usr/include/c++/14/string_view:710:5: note:   template argument deduction/substitution failed:
a.cc:115:26: note:   mismatched types 'std::basic_string_view<_CharT, _Traits>' and 'int'
  115 |                 if(digit>0) diff_bit_number += (digit*pow2[r-1]);
      |                          ^
/usr/include/c++/14/bits/basic_string.h:3915:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> bool std::operator>(const __cxx11::basic_string<_CharT, _Traits, _Allocator>&, const __cxx11::basic_string<_CharT, _Traits, _Allocator>&)'
 3915 |     operator>(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3915:5: note:   template argument deduction/substitution failed:
a.cc:115:26: note:   'ModInt<1000000007>' is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
  115 |                 if(digit>0) diff_bit_number += (digit*pow2[r-1]);
      |                          ^
/usr/include/c++/14/bits/basic_string.h:3929:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> bool std::operator>(const __cxx11::basic_string<_CharT, _Traits, _Allocator>&, const _CharT*)'
 3929 |     operator>(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3929:5: note:   template argument deduction/substitution failed:
a.cc:115:26: note:   'ModInt<1000000007>' is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
  115 |                 if(digit>0) diff_bit_number += (digit*pow2[r-1]);
      |                          ^
/usr/include/c++/14/bits/basic_string.h:3942:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> bool std::operator>(const _CharT*, const __cxx11::basic_string<_CharT, _Traits, _Allocator>&)'
 3942 |     operator>(const _CharT* __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3942:5: note:   template argument deduction/substitution failed:
a.cc:115:26: note:   mismatched types 'const _CharT*' and 'ModInt<1000000007>'
  115 |                 if(digit>0) diff_bit_number += (digit*pow2[r-1]);
      |                          ^
In file included from /usr/include/c++/14/deque:66,
                 from /usr/include/c++/14/queue:62,
                 from a.cc:11:
/usr/include/c++/14/bits/stl_deque.h:2349:5: note: candidate: 'template<class _Tp, class _Alloc> bool std::operator>(const deque<_Tp, _Alloc>&, const deque<_Tp, _Alloc>&)'
 2349 |     operator>(const deque<_Tp, _Alloc>& __x, const deque<_Tp, _Alloc>& __y)
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_deque.h:2349:5: note