Problem:


Score : 500 points

Problem Statement

For two sequences S and T of length N consisting of 0 and 1, let us define f(S, T) as follows:

Consider repeating the following operation on S so that S will be equal to T. f(S, T) is the minimum possible total cost of those operations.

Change S_i (from 0 to 1 or vice versa). The cost of this operation is D \times C_i, where D is the number of integers j such that S_j \neq T_j (1 \leq j \leq N) just before this change.

There are 2^N \times (2^N - 1) pairs (S, T) of different sequences of length N consisting of 0 and 1. Compute the sum of f(S, T) over all of those pairs, modulo (10^9+7).

Constraints

1 \leq N \leq 2 \times 10^5

1 \leq C_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
C_1 C_2 \cdots C_N

Output

Print the sum of f(S, T), modulo (10^9+7).

Sample Input 1

1
1000000000

Sample Output 1

999999993

There are two pairs (S, T) of different sequences of length 2 consisting of 0 and 1, as follows:

S = (0), T = (1): by changing S_1 to 1, we can have S = T at the cost of 1000000000, so f(S, T) = 1000000000.

S = (1), T = (0): by changing S_1 to 0, we can have S = T at the cost of 1000000000, so f(S, T) = 1000000000.

The sum of these is 2000000000, and we should print it modulo (10^9+7), that is, 999999993.

Sample Input 2

2
5 8

Sample Output 2

124

There are 12 pairs (S, T) of different sequences of length 3 consisting of 0 and 1, which include:

S = (0, 1), T = (1, 0)

In this case, if we first change S_1 to 1 then change S_2 to 0, the total cost is 5 \times 2 + 8 = 18. We cannot have S = T at a smaller cost, so f(S, T) = 18.

Sample Input 3

5
52 67 72 25 79

Sample Output 3

269312



Sample input:
1
1000000000


Sample output:
999999993

Submission status: Runtime Error

Solution code:
// {{{ by unolight
#include <bits/stdc++.h>
#include <unistd.h>
#pragma GCC diagnostic ignored "-Wunused-result"
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x),end(x)
#define RALL(x) rbegin(x),rend(x)
#define REP(i,n) for ( int i=0; i<int(n); i++ )
#define REP1(i,a,b) for ( int i=(a); i<=int(b); i++ )
#define MP make_pair
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef pair<int,int> PII;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;

template<class T> void _R( T &x ) { cin>>x; }
void _R( int &x ) { scanf("%d",&x); }
void _R( int64_t &x ) { scanf("%" PRId64,&x); }
void _R( double &x ) { scanf("%lf",&x); }
void _R( char &x ) { scanf(" %c",&x); }
void _R( char *x ) { scanf("%s",x); }
void R() {}
template<class T, class... U> void R( T& head, U&... tail ) { _R(head); R(tail...); }

template<class T> void _W( const T &x ) { cout<<x; }
void _W( const int &x ) { printf("%d",x); }
void _W( const int64_t &x ) { printf("%" PRId64,x); }
void _W( const double &x ) { printf("%.16f\n",x); }
void _W( const char &x ) { putchar(x); }
void _W( const char *x ) { printf("%s",x); }
template<class T> void _W( const vector<T> &x ) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W( const T& head, const U&... tail ) { _W(head); putchar(sizeof...(tail)?' ':'\n'); W(tail...); }

template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {
    sort(begin(v),end(v),f);
    v.resize(unique(begin(v),end(v))-begin(v));
}

template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

#ifdef UNO
template<class T> void _dump(const char *s, T &&head) { cerr << s << "=" << head << endl; }
template<class T, class... Args> void _dump(const char *s, T &&head, Args &&... tail) {
    for (int c = 0; *s != ',' || c != 0; cerr << *s++) {
        if (*s == '(' || *s == '[' || *s == '{') c++;
        if (*s == ')' || *s == ']' || *s == '}') c--;
    }
    cerr << "=" << head << ", ";
    _dump(s + 1, tail...);
}
#define dump(...) do { fprintf(stderr, "%s:%d - ", __PRETTY_FUNCTION__, __LINE__); _dump(#__VA_ARGS__, __VA_ARGS__); } while (0)

template<class Iter> ostream &_out(ostream &s, Iter b, Iter e) {
    s << "[";
    for (auto it = b; it != e; it++) s << (it == b ? "" : " ") << *it;
    return s << "]";
}

template<class A, class B> ostream &operator<<(ostream &s, const pair<A, B> &p) { return s << "(" << p.first << "," << p.second << ")"; }
template<class T> ostream &operator<<(ostream &s, const vector<T> &c) { return _out(s, ALL(c)); }
template<class T, size_t N> ostream &operator<<(ostream &s, const array<T, N> &c) { return _out(s, ALL(c)); }
template<class T> ostream &operator<<(ostream &s, const set<T> &c) { return _out(s, ALL(c)); }
template<class A, class B> ostream &operator<<(ostream &s, const map<A, B> &c) { return _out(s, ALL(c)); }
#else
#define dump(...)
#endif
// }}}

const int mod = 1000000007;
struct Mint {
    LL x; // typedef long long LL;
    Mint(LL x=0):x((x%mod+mod)%mod){}
    Mint operator-() const { return Mint(-x);}
    Mint& operator+=(const Mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    Mint& operator-=(const Mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    Mint& operator*=(const Mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    Mint operator+(const Mint a) const {
        Mint res(*this);
        return res+=a;
    }
    Mint operator-(const Mint a) const {
        Mint res(*this);
        return res-=a;
    }
    Mint operator*(const Mint a) const {
        Mint res(*this);
        return res*=a;
    }
    Mint pow(LL t) const {
        if (!t) return 1;
        Mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    // for prime mod
    Mint inv() const {
        return pow(mod-2);
    }
    Mint& operator/=(const Mint a) {
        return (*this) *= a.inv();
    }
    Mint operator/(const Mint a) const {
        Mint res(*this);
        return res/=a;
    }
};

istream& operator>>(istream&i,Mint&a){i>>a.x;return i;}
ostream& operator<<(ostream&o,const Mint&a){o<<a.x;return o;}

const int N = 2e5+5;
int n, A[N];
Mint ans = 0, pow2[N];

void init_pow2() {
  pow2[0] = 1;
  for(int i=1; i<=n; i++) pow2[i] = pow2[i-1]*2;
}

int main() {
  R(n);
  init_pow2();
  REP(i, n) R(A[i]);
  sort(A, A+n);
  for(int i=0; i<n; i++) {
    Mint left = pow2[i]*pow2[i];
    int m = n - i;
    // Mint right = pow2[m-1]*pow2[m]*m - pow2[m-2]*(m-1);
    Mint right = ( pow2[m]*m - pow2[m-1]*(m-1) ) * pow2[m-1];
    // cout << left << ' ' << m << ' ' << right << endl;
    ans += left * A[i] * right;
  }
  W(ans);
  return 0;
}

Submission status: Runtime Error

Solution code:
n=int(input())
c=list(map(int,input().split()))
mod=10**9+7
c.sort()
c.reverse()
ans=0
x=pow(2,n-2,mod)
for i in range(n):
  ans+=c[i]*(i+2)*x
  ans%=mod
ans*=pow(2,n,mod)
ans%=mod
print(ans)

Submission status: Runtime Error

Solution code:
MOD = 1000000007

N = int(input())
C = list(map(int,input().split()))

C.sort(reverse=True)

ans = 0

for i in range(N):
    ans += C[i]*(2+i)*pow(2,N-2,MOD)*pow(2,N,MOD)
    ans %= MOD

print(ans)

Submission status: Runtime Error

Solution code:
import sys
import math
import fractions
import bisect
import queue
import heapq
from collections import deque
sys.setrecursionlimit(4100000)

MOD = int(1e9+7)
PI = 3.14159265358979323846264338327950288
INF = 1e18

'''
1行のint
N, K = map(int, input().split())

1行のstring
S, T = input().split()

1行の整数配列
P = list(map(int,input().split()))

改行あり
x = []
y = []
for i in range(N):
    x1,y1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)

N行M列の初期化
dp = [[INF] * M for i in range(N)]

'''


N = int(input())
C = list(map(int,input().split()))

# コストの小さいものから更新していけばいい
C.sort()

# 2のべき乗は先に計算しておく
beki = []
for i in range(3*N+20):
    beki.append(int(math.pow(2, i))%MOD)


ans = 0
for i in range(N):
    ans += (C[i] * beki[2*N-2] * (N-i+1))%MOD
    

print(ans % MOD)

Submission status: Runtime Error

Solution code:
import sys
import math
import fractions
import bisect
import queue
import heapq
from collections import deque
sys.setrecursionlimit(4100000)

MOD = int(1e9+7)
PI = 3.14159265358979323846264338327950288
INF = 1e18

'''
1行のint
N, K = map(int, input().split())

1行のstring
S, T = input().split()

1行の整数配列
P = list(map(int,input().split()))

改行あり
x = []
y = []
for i in range(N):
    x1,y1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)

N行M列の初期化
dp = [[INF] * M for i in range(N)]

'''


N = int(input())
C = list(map(int,input().split()))

# コストの小さいものから更新していけばいい
C.sort()

# 2のべき乗は先に計算しておく
beki = []
for i in range(3*N+20):
    beki.append(int(math.pow(2, i)))


ans = 0
for i in range(N):
    ans += (C[i] * beki[2*N-2] * (N-i+1))
    

print(ans % MOD)

Submission status: Runtime Error

Solution code:
N = int(input())
C = list(map(int,input().split()))
C.sort(reverse=True)
MOD = 10**9+7

ans = 0
d = pow(2,N-2,MOD)
base = pow(2,N-1,MOD)
for i,c in enumerate(C):
    ans += c * (base + i*d)
ans *= pow(2,N,MOD)
ans %= MOD
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
C = list(map(int, input().split()))
MOD = 10 ** 9 + 7

C.sort()
C = [0] + C

answer = 0
for i in range(1, N + 1):
  answer = (answer + C[i] * (pow(2, N - 1, MOD) + pow(2, N - 2, MOD) * (N - i))) % MOD
answer = (answer * pow(2, N, MOD)) % MOD

print(answer)

Submission status: Runtime Error

Solution code:
n = int(input())
c = sorted([int(_) for _ in input().split()], reverse=True)
ans = 0
mod = 10**9+7
for i in range(n):
    ans += (c[i] * (pow(2, n-1, mod) + pow(2, n-2, mod) * i)) % mod
    ans %= mod
ans *= pow(2, n, mod)
ans %= mod
print(ans)

Submission status: Runtime Error

Solution code:
#E
n=int(input())
C=sorted(list(map(int,input().split())))
mod=10**9+7

def pow2(x): #2の累乗(mod 10**9+7)の定義
    if x == 0:
        return 1
    return pow2(x-1)*2%mod
    
sum=0
for i in range(n):
    l=i #その桁より左側の桁数(関係ないやつ)
    r=n-i #その桁より右側の個数(その桁自身も含む、1の個数を数えるやつ)
    if r==1:
        ans=pow2(l)
        ans=ans*C[i]%mod
        sum=(sum+ans)%mod
    else:
        ans=pow2(r-1)
        ans=(ans+pow2(r-2)*(r-1)%mod)%mod
        ans=ans*pow2(l)%mod
        ans=ans*C[i]%mod
        sum=(sum+ans)%mod
print((sum*pow2(n)%mod))

Submission status: Runtime Error

Solution code:
N = int(input())
list_c = list(map(int, input().split(" ")))
list_c.sort()

cost = 0
res = 0


for i, c in enumerate(list_c) :
  #for n_wrong in range(0, N-i) : # 自分より大きいコストの数　(Dに対応)
    #cost += (2 ** (N+i)) * c * combination(N-i-1, n_wrong) * (n_wrong+1)
  cost = (2 ** (N+i)) * c * (2**(N-i-2) * (N-i-1) + (2**(N-i-1)))
  res += int(cost)%(10**9+7)

print(res % (10**9+7))

Submission status: Runtime Error

Solution code:
import numpy as np
import math

N = int(input())
list_c = list(map(int, input().split(" ")))
list_c.sort()

def combination(n, r) : ## nCr
  return int(math.factorial(n) / (math.factorial(n-r) * math.factorial(r)))
  
cost = 0



for i, c in enumerate(list_c) :
  #for n_wrong in range(0, N-i) : # 自分より大きいコストの数　(Dに対応)
    #cost += (2 ** (N+i)) * c * combination(N-i-1, n_wrong) * (n_wrong+1)
    cost += (2 ** (N+i)) * c * (2**(N-i-2) * (N-i-1) + (2**(N-i-1)))

cost=int(cost)
print(cost % (10**9+7))

Submission status: Runtime Error

Solution code:
from collections import deque
N = int(input())
E = [[] for _ in range(N)]
for i in range(N-1):
  a,b = map(int,input().split())
  E[a-1].append(b-1)

C = [[] for _ in range(N)]
ans = []

for idx,edge in enumerate(E):
  c = 1
  for e in edge:
    if c in C[idx]:
      c += 1
    C[e].append(c)
    ans.append(c)
    c += 1
print(max(ans))
for i in ans:
  print(i)

Submission status: Runtime Error

Solution code:
import numpy as np
import math

N = int(input())
list_c = list(map(int, input().split(" ")))
list_c.sort()

def combination(n, r) : ## nCr
  return int(math.factorial(n) / (math.factorial(n-r) * math.factorial(r)))
  
cost = 0



for i, c in enumerate(list_c) :
  for n_wrong_left in range(0, i+1) : # 自分を含め、より小さいコストの数
    for n_wrong_right in range(0, N-i) : # 自分より大きいコストの数　(Dに対応)
      cost += (2 ** N) * c * combination(N-i-1, n_wrong_right) * combination(i, n_wrong_left) * (n_wrong_right+1)

print(cost % (10**9+7))

Submission status: Runtime Error

Solution code:
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

# from libs.debug import debug

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


N = int(sys.stdin.buffer.readline())
C = list(map(int, sys.stdin.buffer.readline().split()))
C.sort()

#
# @debug
# def f(S, T, C):
#     S = np.array(S, dtype=bool)
#     T = np.array(T, dtype=bool)
#     C = np.array(C, dtype=int)
#     costs = np.msort(C[S != T])
#     return int(np.dot(costs[::-1], np.arange(1, len(costs) + 1)))
#
#
# def test(N, C):
#     ans = 0
#     for s in itertools.product([True, False], repeat=N):
#         for t in itertools.product([True, False], repeat=N):
#             ans += f(s, t, C)
#             ans %= MOD
#     print(ans)
#
#
# test(N, C)

# R = np.zeros((N + 1, N), dtype=int)
# R[0] = 0
# R[1] = 1
# for r in range(2, N + 1):
#     for c in range(N):
#         R[r, c] = R[r - 1][:c].sum()
# print(R)
# print(R * np.arange(N + 1)[:, None])
# print(R * np.arange(N + 1)[:, None] * (2 ** np.arange(N)[::-1]))
# print(R * np.arange(N + 1)[:, None] * (2 ** np.arange(N)[::-1]) * np.msort(C)[::-1])
# print((R * np.arange(N + 1)[:, None] * (2 ** np.arange(N)[::-1]) * np.msort(C)[::-1]).sum())
# print((R * np.arange(N + 1)[:, None] * (2 ** np.arange(N)[::-1]) * np.msort(C)[::-1]).sum() * (2 ** N))
#
# print()
# print(R * np.arange(N + 1)[:, None] * (2 ** np.arange(N)[::-1]))
# print((R * np.arange(N + 1)[:, None] * (2 ** np.arange(N)[::-1])).sum(axis=0))
# print(np.diff((R * np.arange(N + 1)[:, None] * (2 ** np.arange(N)[::-1])).sum(axis=0)))

arr = np.full(N + 1, 2 ** (N - 2))
arr = arr.cumsum()[1:]
arr %= MOD
# print(arr)
ans = arr * np.msort(C)[::-1]
print(int(ans.sum() * pow(2, N, MOD)) % MOD)

Submission status: Runtime Error

Solution code:
mod=10**9+7
N=int(input())
C=[0]
C.extend(sorted(list(map(int,input().split())),reverse=True)) # 1-indexed

# print(C)

ans=0
for j in range(1,N+1):
    tmp=C[j]*(j+1)*int(pow(2,N-2,mod))%mod
    # print(tmp)
    ans=(ans+tmp)%mod
    # print(j,ans)
ans=ans*int(pow(2,N,mod))%mod

print(ans)

Submission status: Runtime Error

Solution code:
mod=10**9+7
N=int(input())
C=[0]
C.extend(sorted(list(map(int,input().split())),reverse=True)) # 1-indexed

# print(C)

ans=0
for j in range(1,N+1):
    tmp=C[j]*(j+1)*pow(2,N-2,mod)%mod
    # print(tmp)
    ans=(ans+tmp)%mod
    # print(j,ans)
ans=ans*pow(2,N,mod)%mod

print(ans)

Submission status: Runtime Error

Solution code:
mod=10**9+7
N=int(input())
C=[0]
C.extend(sorted(list(map(int,input().split())),reverse=True)) # 1-indexed

# print(C)

ans=0
for j in range(1,N+1):
    tmp=C[j]*(j+1)*pow(2,N-2,mod)%mod
    # print(tmp)
    ans=(ans+tmp)%tmp
    # print(j,ans)
ans=ans*pow(2,N,mod)%mod

print(ans)

Submission status: Runtime Error

Solution code:
mod=10**9+7
N=int(input())
C=[0]
C.extend(sorted(list(map(int,input().split())),reverse=True)) # 1-indexed

# print(C)

ans=0
for j in range(1,N+1):
    tmp=C[j]*(j+1)*pow(2,N-2,mod)%mod
    # print(tmp)
    ans+=tmp
    # print(j,ans)
ans=ans*pow(2,N,mod)%mod

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
C = list(map(int, input().split()))
C.sort(reverse = True)
#print(C)
sosu = 10 ** 9 + 7
K = [1 for i in range(N+1)]
for i in range(1, N+1):
    a = K[i-1] * 2 % sosu
    K[i] = a
ans = 0
for i in range(N):
    #for j in range(1,circle):##j番目に大きい
    #    kkk = c(i, j-1) * 2 ** (N-i-1)###i+1番目に大きいものがj番目に大きくなるような選び方
    #    ans += C[i] * kake * j * kkk
    ans += C[i] * K[N] * (2 ** i + i * 2 ** (i-1)) * K[N-i-1]
    ans %= sosu
print(int(ans))

Submission status: Runtime Error

Solution code:
N = int(input())
C = list(map(int, input().split()))
C.sort(reverse = True)
#print(C)
sosu = 10 ** 9 + 7
kake = (2 ** N) % sosu
ans = 0
for i in range(N):
    #for j in range(1,circle):##j番目に大きい
    #    kkk = c(i, j-1) * 2 ** (N-i-1)###i+1番目に大きいものがj番目に大きくなるような選び方
    #    ans += C[i] * kake * j * kkk
    ans += C[i] * kake * (2 ** i + i * 2 ** (i-1)) * 2 ** (N-i-1)
    ans %= sosu
print(int(ans))

Submission status: Runtime Error

Solution code:
N = int(input())
C = list(map(int, input().split()))
C.sort(reverse = True)
#print(C)
sosu = 10 ** 9 + 7
kake = 2 ** N
ans = 0
for i in range(N):
    #for j in range(1,circle):##j番目に大きい
    #    kkk = c(i, j-1) * 2 ** (N-i-1)###i+1番目に大きいものがj番目に大きくなるような選び方
    #    ans += C[i] * kake * j * kkk
    ans += C[i] * kake * (2 ** i + i * 2 ** (i-1)) * 2 ** (N-i-1)
    ans %= sosu
print(int(ans))

Submission status: Runtime Error

Solution code:
import sys

MOD = 10 ** 9 + 7

def make_table(size=10**6, p=MOD):
    fac = [None] * (size + 1)
    fac[0] = 1
    for i in range(size):
        fac[i+1] = fac[i] * (i + 1) % p
    ifac = [None] * (size + 1)
    ifac[size] = pow(fac[size], p-2, p)
    for i in range(size, 0, -1):
        ifac[i-1] = ifac[i] * i % p
    return fac, ifac

fac, ifac = make_table(10**5)

def comb(n, r, mod=MOD):
    if r > n or r < 0:
        return 0
    return fac[n] * ifac[r] % mod * ifac[n-r] % mod

n, *c = map(int, sys.stdin.read().split())

def main():
    c.sort()
    res = 0
    for i in range(n):
        cnt = 0
        for d in range(1, n+1):
            for j in range(d):
                cnt += comb(i, j) * comb(n-i-1, d-j-1) * (d - j) % MOD
        
        res += c[i] * cnt
        res %= MOD
    return res * 2 ** n % MOD

if __name__ == '__main__':
    ans = main()
    print(ans)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
mod = 10**9+7
a = list(map(int,input().split()))
a.sort()
ans = 0
const = pow(2,n,mod)
for i in range(n):
  ans = (ans + a[i]*const*(pow(2,n-1,mod)+pow(2,n-2,mod)*(n-i-1))%mod)%mod
print(ans)

Submission status: Runtime Error

Solution code:
def main():
    n=int(input())
    a=list(map(int,input().split()))
    mod=10**9+7
    if n==1:
        print(2*a[0]%mod)
        return
    a.sort(key=lambda x:-x)
    mod=10**9+7
    ans=sum([a[i]*(i+2))%mod for i in range(n)])
    ans=ans*pow(2,n,mod)*pow(2,n-2,mod)%mod
    print(ans)

main()

Submission status: Runtime Error

Solution code:
n=int(input())
c=list(map(int,input().split()))
c.sort(reverse=True)
res=0
ans=0
mod=10**9+7
p=pow(2,n*2-2,mod)
for i in range(n):
   ans+=(c[i]*(i+2)%mod)*p
prit(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
c = list(map(int, input().split()))

mod = 10**9 + 7
c.sort()
ans = 0

for i in range(n):
    ans += c[i] * pow(2, i, mod) % mod * (pow(2, n-i-2, mod) * (n-i-1) + pow(2, n-i-1, mod)) % mod * pow(2, n, mod) % mod
    ans %= mod

print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
c = list(map(int, input().split()))

mod = 10**9 + 7
c.sort()
ans = 0

for i in range(n):
    ans += c[i] * pow(2, i, mod) % mod * (pow(2, n-i-2, mod) * (n-i-1) + pow(2, n-i-1, mod) ) % mod * pow(2, n, mod) % mod
    ans %= mod

print(ans)

Submission status: Runtime Error

Solution code:
def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return(a)

def lcm(a, b):
    return a*b//gcd(a,b)
#import sys
#input = sys.stdin.readline
def main():
    N, M = map( int, input().split())
    A = list( map( int, input().split()))
    B = [a for a in A]
    T = 1
    L = 1
    C = [0]*N
    for i in range(N):
        for _ in range(30):
            if B[i]%2 == 0:
                B[i] //= 2
                C[i] += 1
            else:
                break
    p = C[0]
    for i in range(N-1):
        if p != C[i+1]:
            print(0)
            return
    q = pow(2,p)
    t = 1
    for i in range(N):
        t = lcm(t,A[i]//2)
    if t > M:
        print(0)
        return

    print((M-t)//t + 1)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

MOD = 1_000_000_000 + 7
N = int(readline())
C = np.array(read().split(), np.int64)

C.sort()

ans = (C * np.arange(N+1, 1, -1) % MOD).sum() % MOD
ans *= pow(2, N+N-2, MOD)

print(ans % MOD)

Submission status: Runtime Error

Solution code:
import sys
read = sys.stdin.buffer.read

import heapq
mod = 10**9+7
n, *clst = map(int, read().split())
if n == 1:
  print(2*clst[0] % mod)
  quit()
heapq.heapify(clst)
import numpy as np
clst=np.sort(clst)
d=2**(n-2)
start = 2**(n-1)+(n-1)*d
end = 2**(n-1)-1
q=np.arange(start,end,-d)

res=np.sum(clst*q)
print(2**n*res % mod)

Submission status: Runtime Error

Solution code:
import sys
read = sys.stdin.buffer.read

import heapq
mod = 10**9+7
n, *clst = map(int, read().split())
if n == 1:
  print(2*clst[0] % mod)
  quit()
heapq.heapify(clst)
import numpy as np
clst=np.sort(clst)
q=np.arange(2**(n-1)+(n-1)*2**(n-2),2**(n-1)-1,-2**(n-2))

res=np.sum(clst*q)
print(2**n*res % mod)

Submission status: Runtime Error

Solution code:
import heapq

N = int(input())
C = list(map(int, input().split()))

ans = 0

if N != 1:
    C = heapq.heapify(C)
    for i in range(N):
        c = heapq.heappop(C)
        ans += c * (N + 1 - i) * (2 ** (N - 2))
        ans %= 10 ** 9 + 7
    ans *= 2 ** N
else:
    ans = C[0] * 2

ans %= 10 ** 9 + 7

print(ans)

Submission status: Runtime Error

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import heapq
mod = 10**9+7
n, *clst = map(int, read().split())
if n == 1:
  print(2*clst[0] % mod)
  quit()
heapq.heapify(clst)
import numpy as np
clst=np.array(clst)
q=np.arange(2**(n-1)+(n-1)*2**(n-2),2**(n-1)-1,-2**(n-2))
res=np.sum(clst*q)
print(2**n*res % mod)

Submission status: Runtime Error

Solution code:
import fractions

N, M = map(int, input().split())
nums = list(map(int, input().split()))

# nums.sort()
# print(nums)

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

ans = lcm(nums[0], nums[1])

def hoge(nums, ans):
    for i in range(2, N):
        ans = lcm(ans, i)
    return ans

if 2 < N:
    ans = hoge(nums, ans)
print((M * 2) // (ans) - (M * 2) // ((ans) * 2)) if (ans)  <= (M * 2) else print(0)

Submission status: Runtime Error

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
mod = 10**9+7
n, *clst = map(int, read().split())
if n == 1:
  print(2*clst[0] % mod)
  quit()
import numpy as np
clst=np.array(clst)
clst=np.sort(clst)
q=np.arange(2**(n-2)+n*2**(n-2),2**(n-1)-1,-2**(n-2))
 
res = np.sum(clst*q)
print(2**n*res % mod)

Submission status: Runtime Error

Solution code:
n = int(input())
c = list(map(int, input().split()))

def f(x):
    if x == 0:
        return 1
    if x == 1:
        return x
    else:
        return x * f(x-1)

def comb(n, r):
    return f(n) // f(r) // f(n-r)

ret = 0
for i in range(1, n+1):
    cost = 0
    for j in range(1, i+1):
        if j != 0:
            cost += c[j-1]*i
    ret += 2*comb(n, i)*cost

print(int(ret % (1e9+7)))

Submission status: Runtime Error

Solution code:
MOD=10**9+7

N=int(input())
C=list(map(int, input().split()))
C.sort(reverse=True)
out=0
tmp1=pow(2, N-1, MOD)
tmp2=pow(2, N-2, MOD)
for i in range(N):
  out+=(tmp1+tmp2*i)*C[i]
  out%=MOD
  
out=out*pow(2, N, MOD)
print(int(out%MOD))

Submission status: Runtime Error

Solution code:
import fractions

N = int(input())
l = sorted([int(x) for x in input().split()])
for i in range(N):

Submission status: Runtime Error

Solution code:
import itertools
import math
N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
L = list(map(list,list(itertools.permutations(list(i for i in range(1,N+1)),N))))
a = L.index(P)
b = L.index(Q)
print(abs(a-b))

Submission status: Runtime Error

Solution code:
def get_gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a

def get_lcm(a, b):
    return a * b // get_gcd(a, b)


N, M  = map(int, input().split())
A     = list(map(int, input().split()))
A     = list(set(A))

B = A[0]

if sum([a % 2 != 0 for a in A]) > 0:
    print(0)
else:
    for b in A[1:]:
        B = get_lcm(B, b)
    print(max(0, int((M + 0.5 * B) // B)))

Submission status: Runtime Error

Solution code:
N=int(input())
C=[int(i) for i in input().split(" ")]
C=sorted(C,reverse=True)
retval=0
mod=10**9+7
for i,c in enumerate(C):
    retval+=c*(2**(2*N-i-1))*(2**i+i*2**(i-1))
    retval=retval%mod

print(int(retval))

Submission status: Runtime Error

Solution code:
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations,groupby
import sys
import bisect
import string
import math
import time
import random
def S_():
    return input()
def LS():
    return [i for i in input().split()]
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def NI(n):
    return [int(input()) for i in range(n)]
def NI_(n):
    return [int(input())-1 for i in range(n)]
def StoI():
    return [ord(i)-97 for i in input()]
def ItoS(nn):
    return chr(nn+97)
def LtoS(ls):
    return ''.join([chr(i+97) for i in ls])
def GI(V,E,Directed=False,index=0):
    org_inp=[]
    g=[[] for i in range(n)]
    for i in range(E):
        inp=LI()
        org_inp.append(inp)
        if index==0:
            inp[0]-=1
            inp[1]-=1
        if len(inp)==2:
            a,b=inp
            g[a].append(b)
            if not Directed:
                g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp
            aa=(inp[0],inp[2])
            bb=(inp[1],inp[2])
            g[a].append(bb)
            if not Directed:
                g[b].append(aa)
    return g,org_inp
def bit_combination(k,n=2):
    rt=[]
    for tb in range(n**k):
        s=[tb//(n**bt)%n for bt in range(k)]
        rt+=[s]
    return rt
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
u_alp=string.ascii_uppercase
ts=time.time()
#sys.setrecursionlimit(10**5)
input=lambda: sys.stdin.readline().rstrip()
import fractions

def ran_input():
    import random
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a

show_flg=False
show_flg=True

ans=0

n,m=LI()
a=sorted([int(i)//2 for i in input().split()])
b=[]
for i in range(n):
    if i==0:
        b.append(a[i])
        continue
    elif i!=b[-1]:
        b.append(a[i])
#a=LI()

'''
s=time.time()
n=10**4
b=[random.randint(10,10**8) for i in range(n)]
t=time.time()
show(t-s)
'''

lcm=b[0]
for i in range(1,n):
    lcm=(lcm//fractions.gcd(b[i],lcm))*b[i]

ans=(1+m//lcm)//2

fl=False
for i in b:
    t=lcm//i
    if t%2==0:
        fl=True
    
if lcm%2==0 and fl:
    ans=0
    
    
print(ans)

Submission status: Runtime Error

Solution code:
#T=(0,0,...,0)
#に変換するためのコストの2^N倍
N=int(input())
c=sorted([int(i) for i in input().split()])
mod=10**9+7
ans=0
for k in range(N):
    a1=pow(2,N-2,mod)
    a2=(N-k+1)
    tmp=(a1*a2)%mod
    ans+=(c[k]*tmp)%mod
    ans%=mod
    #print(k,tmp)
ans=ans*pow(2,N,mod)
ans%=mod
print(ans)