text: Sum of squares of all Subsets of given Array | C # implementation of the approach ; Function to return ( 2 ^ P % mod ) ; Function to return the sum of squares of subsets ; Sqauaring the elements and adding it to ans ; Driver code
code: using System ; class GFG { static readonly int mod = ( int ) ( 1e9 + 7 ) ; static long power ( int p ) { long res = 1 ; for ( int i = 1 ; i <= p ; ++ i ) { res *= 2 ; res %= mod ; } return res % mod ; } static long subset_square_sum ( int [ ] A ) { int n = A . Length ; long ans = 0 ; foreach ( int i in A ) { ans += ( 1 * i * i ) % mod ; ans %= mod ; } return ( 1 * ans * power ( n - 1 ) ) % mod ; } public static void Main ( String [ ] args ) { int [ ] A = { 3 , 7 } ; Console . WriteLine ( subset_square_sum ( A ) ) ; } }