Given a number as integer s, find the sum of all the elements present in all possible subsequences of s. 
Example 1:
Input:  S = "123" 
Output: 24
Explanation: {1}, {2}, {3}, {1, 2}, {2, 3}
{1, 3}, {1, 2, 3} are all possible sub-
sequences
Example 2:
Input:  S = "5"
Output: 5
Explanation: {5} is the only possible 
sub sequence
User Task:
Your task is to complete the function subsequnceSum() which takes a single string as inputs and returns the sum. You need not take any input or print anything.
Expected Time Complexity: O(|s|)
Expected Auxiliary Space: O(1)
Constraints:
1 <= |S| <= 20

Source: geeksforgeeks | Difficulty: EASY
Tags: String algorithms

Data structures

Starter code: #User function Template for python3
class Solution:
	def subsequenceSum(self, s):
		# code here

Solutions:
class Solution:

	def subsequenceSum(self, s):
		su = 0
		op = 2 ** (len(s) - 1)
		for i in s:
			su += int(i) * op
		return su


class Solution:

	def subsequenceSum(self, s):
		c = 0
		for i in s:
			c += int(i) * 2 ** (len(s) - 1)
		return c


class Solution:

	def subsequenceSum(self, s):
		r = 2 ** (len(s) - 1)
		s = map(int, list(s))
		r *= sum(s)
		return r


class Solution:

	def subsequenceSum(self, s):
		l = len(s) - 1
		sumo = 0
		for i in s:
			sumo = sumo + int(i) * 2 ** l
		return sumo


from itertools import combinations

class Solution:

	def subsequenceSum(self, s):
		r = 2 ** (len(s) - 1)
		s = map(int, list(s))
		r *= sum(s)
		return r


from itertools import combinations

class Solution:

	def subsequenceSum(self, s):
		ans = list(s)
		summ = 0
		for i in range(1, len(ans) + 1):
			p = tuple(combinations(ans, i))
			for i in p:
				for j in i:
					summ = summ + int(j)
		return summ


class Solution:

	def subsequenceSum(self, s):
		n = 2 ** (len(s) - 1)
		sum = 0
		for i in s:
			sum += int(i)
		res = n * sum
		return res


from itertools import combinations

class Solution:

	def subsequenceSum(self, s):
		x = 2 ** (len(s) - 1)
		summ = 0
		for i in s:
			summ += int(i)
		return x * summ


class Solution:

	def subsequenceSum(self, s):
		sum = 0
		for ch in s:
			sum = sum + int(ch) * 2 ** (len(s) - 1)
		return sum


import math

class Solution:

	def subsequenceSum(self, s):
		res = 0
		l = len(s)
		for i in range(len(s)):
			res += math.pow(2, l - 1) * int(s[i])
		return int(res)


class Solution:

	def subsequenceSum(self, s):
		S = 0
		for i in range(0, len(s)):
			S += int(s[i])
		return S * pow(2, len(s) - 1)


class Solution:

	def subsequenceSum(self, s):
		l = len(s)
		ans = 0
		d = 2 ** (l - 1)
		for i in s:
			ans += int(i) * d
		return ans


class Solution:

	def subsequenceSum(self, s):
		length = len(s)
		ans = 0
		for ch in s:
			ans += int(ch) * 2 ** (length - 1)
		return ans


class Solution:

	def subsequenceSum(self, s):
		a = list(s)
		sum = 0
		for i in range(len(a)):
			sum += int(a[i])
		return sum * (1 << len(a) - 1)


class Solution:

	def subsequenceSum(self, s):
		a = 2 ** (len(s) - 1)
		b = map(int, list(s))
		d = a * sum(b)
		return d


import math

class Solution:

	def subsequenceSum(self, s):
		ss = 0
		for x in s:
			ss += int(x)
		res = int(math.pow(2, len(s) - 1) * ss)
		return res


class Solution:

	def subsequenceSum(self, s):
		sumx = 0
		n = len(s) - 1
		k = 2 ** n
		for i in s:
			sumx += int(i) * k
		return sumx
if __name__ == '__main__':
	T = int(input())
	for i in range(T):
		s = input()
		ob = Solution()
		answer = ob.subsequenceSum(s)
		print(answer)


class Solution:

	def subsequenceSum(self, s):
		r = 2 ** (len(s) - 1)
		s = map(int, list(s))
		r *= sum(s)
		return r
if __name__ == '__main__':
	T = int(input())
	for i in range(T):
		s = input()
		ob = Solution()
		answer = ob.subsequenceSum(s)
		print(answer)


class Solution:

	def subsequenceSum(self, s):
		lst = list(map(lambda x: int(x), list(str(s))))
		return sum(lst) * 2 ** (len(lst) - 1)
if __name__ == '__main__':
	T = int(input())
	for i in range(T):
		s = input()
		ob = Solution()
		answer = ob.subsequenceSum(s)
		print(answer)


class Solution:

	def subsequenceSum(self, s):
		a = 0
		for i in s:
			a += int(i)
		n = len(s)
		d = a * pow(2, n - 1)
		return d
if __name__ == '__main__':
	T = int(input())
	for i in range(T):
		s = input()
		ob = Solution()
		answer = ob.subsequenceSum(s)
		print(answer)


class Solution:

	def subsequenceSum(self, s):
		size = len(s) - 1
		sumo = 0
		for i in s:
			sumo += int(i) * 2 ** size
		return sumo
if __name__ == '__main__':
	T = int(input())
	for i in range(T):
		s = input()
		ob = Solution()
		answer = ob.subsequenceSum(s)
		print(answer)


class Solution:

	def subsequenceSum(self, s):
		x = 2 ** (len(s) - 1)
		sum = 0
		for i in s:
			sum += int(i) * x
		return sum


class Solution:

	def subsequenceSum(self, s):
		S = ''
		count = 0
		sum1 = 0
		for i in s:
			if i == '0':
				count += 1
			else:
				S = S + i
		n = len(S)
		for i in S:
			sum1 = sum1 + int(i) * 2 ** (n - 1)
		sum1 = 2 ** count * sum1
		return sum1


class Solution:

	def subsequenceSum(self, s):
		n = len(s)
		times = 2 ** (n - 1)
		ans = 0
		for x in s:
			ans += int(x) * times
		return ans


class Solution:

	def subsequenceSum(self, s):
		n = len(s)
		k = 0
		for i in range(n):
			k += int(s[i])
		return 2 ** (n - 1) * k


class Solution:

	def subsequenceSum(self, s):
		l = len(s) - 1
		x = 2 ** l
		su = 0
		for i in range(len(s)):
			if len(s) > 1:
				su += int(s[i]) * x
			else:
				su = int(s)
		return su