Harryxun/stf_run huggingface dataset:
n = int(input())


sum = 0

for i in range(len(n)):
  sum += n[i]
  
if n % sum ==0:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

n = input()


sum = 0

for i in range(len(n)):
  sum += int(n[i])
  
if int(n) % sum ==0:
  print("Yes")
else:
  print("No")
while True:
    a,b,c = map(int, input().strip().split(' '))
    temp = 0
    if a == 0 and b == 0 and c == 0:
        break
    for i in range(1, c):
        for j in range(1, c):
            if i*(100+a)//100 + j*(100+a)//100 == c:
                if temp < i*(100+b)//100 + j*(100+b)//100:
                    temp = i*(100+b)//100 + j*(100+b)//100
    print(temp)


### FIXED CODE ###

while True:
    a,b,c = map(int, input().strip().split(' '))
    temp = 0
    if a == 0 and b == 0 and c == 0:
        break
    for i in range(1, c):
        for j in range(i, c):
            if i*(100+a)//100 + j*(100+a)//100 == c:
                if temp < i*(100+b)//100 + j*(100+b)//100:
                    temp = i*(100+b)//100 + j*(100+b)//100
    print(temp)
num = input().split()
participant = int(num[0])
init_point = int(num[1])
correct = int(num[2])

tmp = [init_point]*participant

for i in range(participant):
  answer_person = int(input())
  tmp[answer_person-1] += 1
  tmp -= 1
  
for item in tmp:
  if item>0: print("Yes")
  else: print("No")

### FIXED CODE ###

import sys

num = input().split()
participant = int(num[0])
init_point = int(num[1])
correct = int(num[2])

tmp = [0]*participant

for i in range(correct):
  answer_person = int(input())-1
  tmp[answer_person] += 1

for i in tmp:
  if i<=correct-init_point:
    print("No")
  else:
    print("Yes")
n, m = map(int, input().split())

a = [list(sorted(map(int, input().split()))) for i in range(m)]
a.sort()

x = 0
li_a = []

while a[x][0]== 1 and x < m:
    li_a.append(a[x][1])
    x += 1

a.sort(reverse=True, key=lambda x: x[1])

x = 0
li_b = []

while a[x][1] == n and x < m:
    li_b.append(a[x][0])
    x += 1

print("POSSIBLE" if set(li_a) & set(li_b) else "IMPOSSIBLE")

### FIXED CODE ###

n, m = map(int, input().split())

a = [list(sorted(map(int, input().split()))) for i in range(m)]
a.sort()

x = 0
li_a = []

while x < m and a[x][0]== 1:
    li_a.append(a[x][1])
    x += 1

a.sort(reverse=True, key=lambda x: x[1])

x = 0
li_b = []

while x < m and a[x][1] == n:
    li_b.append(a[x][0])
    x += 1

print("POSSIBLE" if set(li_a) & set(li_b) else "IMPOSSIBLE")
def solve(string):
    ins = string.split("\n")
    h, w = map(int, ins[0].split(" "))
    a = [list(map(int, _i.split(" "))) for _i in ins[1:]]
    move = []
    for i in range(h):
        for j in range(w):
            # if a[i][j] % 2 == 0:
                # continue
            a[i][j] -= 1
            if j < w - 1:
                # a[i][j + 1] += 1
                move.append("{} {} {} {}".format(i + 1, j + 1, i + 1, j + 2))
            elif i < h - 1:
                # a[i + 1][j] += 1
                move.append("{} {} {} {}".format(i + 1, j + 1, i + 2, j + 1))
    return "{}\n{}".format(len(move), "\n".join(move))


if __name__ == '__main__':
    line = input()
    tmp = [line]
    for _ in range(int(line[0])):
        tmp.append(input())
    print(solve('\n'.join(tmp)))


### FIXED CODE ###

h,w = map(int,input().split())
a = []
for i in range(h):
    tmp = list(map(lambda x:int(x)%2,input().split()))
    a.append(tmp)
result = []
 
for i in range(h):
    for j in range(w-1):
        if a[i][j] == 1:
            #a[i][j] == 0
            a[i][j+1] = 1 ^ a[i][j+1]
            result.append((i+1,j+1,i+1,j+2)) 
for i in range(h-1):
    if a[i][w-1] == 1:
        a[i+1][w-1] = 1 ^ a[i+1][w-1]
        result.append((i+1,w,i+2,w))
print(len(result))
for row in result:
    print("{} {} {} {}".format(row[0],row[1],row[2],row[3]))
N = int(input())
T = []
for i in range(N):
    T.append(int(input()))

T.sort()


def gcd(a, b):
    while (b != 0):
        tmp = a
        a = b
        b = tmp % b

    return a


def lcm(a, b):
    return int(a*b/gcd(a, b))


ans = T[0]
for t in T[1:]:
    ans = lcm(ans, t)
    # print(ans)

print(ans)


### FIXED CODE ###

N = int(input())
T = []
for i in range(N):
    T.append(int(input()))

T.sort()


def gcd(a, b):
    while (b != 0):
        tmp = a
        a = b
        b = tmp % b

    return a


def lcm(a, b):
    return (a*b)//gcd(a, b)


ans = T[0]
for t in T[1:]:
    ans = lcm(ans, t)
    # print(ans)

print(ans)
A, B, C, K = map(int, input().split())
result = 0

if A > K:
    print(K)
    exit

for i in range(K):
    if A > (i + 1):
        result += 1
        continue
    elif A == (i + 1):
        result += 1
        continue

    if B > (i + 1 - A):
        result += 0
        continue
    elif B == (i + 1 - A):
        result += 0
        continue

    if C > (i + 1 - A - B):
        result -= 1
        continue
    elif C == (i + 1 - A - B):
        result -= 1
        break
    else:
        break

print(result)


### FIXED CODE ###

s = input()
t = input()

if t.startswith(s) and str.isalpha(t):
    if len(t) == (len(s) + 1):
        print('Yes')
else:
    print('No')
n = raw_input()
A = map(int, raw_input().split())
q = raw_input()
m = map(int, raw_input().split())
??
def solve(i, m):
??if m == 0:
????return true
??if i >= n and m > 0:
????return false
??res = solve(i + 1, m) or solve(i + 1, m - A(i))
??return res
????
for j in range(0, q):
??if m == solve(0, m(j)):
????print "yes"
??else:
????print "no"

### FIXED CODE ###

n = input()
A = map(int, raw_input().split())
q = input()
m = map(int, raw_input().split())

def solve(i, m):
 if m == 0:
  return True
 if i >= n or m > sum(A):
  return False
 res = solve(i+1, m) or solve(i+1, m-A[i])
 return res

for j in range(0, q):
 if solve(0, m[j]):
  print 'yes'
 else:
  print 'no'
from fractions import gcd
a = int(input())
b = int(input())
print(a * b // gcd(a, b))

### FIXED CODE ###

from fractions import gcd
a, b = map(int, input().split())
print(a * b // gcd(a, b))
from math import gcd
N = int(input())
a = list(map(int, input().split()))

if N > 2:
    a.sort()
    diff = []
    for i in range(N-1):
        diff.append(a[i+1]-a[i])
    index = diff.index(min(diff))
    diff_ = diff[:]
    if index > 0:
        plus = diff[index-1] + diff[index]
        diff_[index-1] = plus
        diff_[index] = plus
    GCD = diff_[0]

    for i in range(N-1):
        GCD = gcd(diff_[i], GCD)

    if index < N-1:
        plus = diff[index] + diff[index+1]
        diff[index] = plus
        diff[index+1] = plus
    GCD2 = diff[0]
    for i in range(N-1):
        GCD2 = gcd(diff[i], GCD2)
    print(max(GCD, GCD2))
else:
    print(max(a))


### FIXED CODE ###

from fractions import gcd
N = int(input())
a = list(map(int, input().split()))
N0 = 2**(N-1).bit_length()
INF = 2**31-1
data = [INF]*(2*N0+1)
def update(k, x):
    k += N0-1
    data[k] = x
    while k >= 0:
        k = (k - 1) // 2
        if data[2*k+1] == INF:
            data[k] = data[2*k+2]
        elif data[2*k+2] == INF:
            data[k] = data[2*k+1]
        else:
            data[k] = gcd(data[2*k+1], data[2*k+2])

for i in range(N):
    update(i, a[i])

ans = 0
for i in range(N):
    update(i, INF)
    ans = max(ans, data[0])
    update(i, a[i])

print(ans)
a = int(input())
if a % 2 = 0:
  print(str(a/2))
else:
  print(str((a/2)+1))

### FIXED CODE ###

a = int(input())
if a % 2 == 0:
  print(str(int(a//2)))
else:
  print(str(int(a//2)+1))
n = int(input())
o = {""}
for i in range(n):
    a = len(o)
    op, ob = map(str, input().split())
    if op = "find"
        o.add(ob)
        if len(o) > a:
            print("no")
            o.discard(ob)
        else:
            print("yes")
    else:
        o.add(ob)


### FIXED CODE ###

n = int(input())
o = {""}
for i in range(n):
    a = len(o)
    op, ob = map(str, input().split())
    if op == "find":
        o.add(ob)
        if len(o) > a:
            print("no")
            o.discard(ob)
        else:
            print("yes")
    else:
        o.add(ob)
import sys,time
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    start = time.time()
    n,m = LI()
    e = [[] for _ in range(n)]
    for _ in range(m):
        l,r,d = LI()
        e[l-1].append((r-1,d))
        e[r-1].append((l-1,-d))

    b = [False] * n
    def g(i,c):
        if c == False:
            c = 0
        b[i] = c
        for r,d in e[i]:
            if b[r] != False:
                if b[r] != c+d:
                    return False
            else:
                if not g(r,c+d):
                    return False
        return True

    for i in range(n):
        if b[i] != False:
            continue
        if time.time() - start > 0.9:
            return 'Yes'
        if not g(i,False):
            return 'No'
    return 'Yes'


print(main())





### FIXED CODE ###

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n,m = LI()
    e = [[] for _ in range(n)]
    if m > 0:
        for _ in range(m):
            l,r,d = LI()
            e[l-1].append((r-1,d))
            e[r-1].append((l-1,-d))

    b = [None] * n

    for i in range(n):
        if not b[i] is None:
            continue
        b[i] = 0
        q = [i]
        qi = 0
        nq = []
        while True:
            if len(q) == qi:
                if not nq:
                    break
                q = nq
                qi = 0
                nq = []
            j = q[qi]
            qi += 1
            c = b[j]
            for r,d in e[j]:
                if b[r] is None:
                    b[r] = c+d
                    nq.append(r)
                else:
                    if b[r] != c+d:
                        return 'No'

    return 'Yes'


print(main())
N = int(input())
nums = list(map(int, input().split()))
count = [0]*N
nums.sort()
answer = N
for i in range(N):
  fNum = nums[i]
  for j in range(N):
    sNum = nums[j]
    if (sNum > fNum):
      break
    elif (i == j):
      continue
    else:
      if (fNum%sNum == 0):
      	answer -= 1
        break

print(answer)

    
  



### FIXED CODE ###

N = int(input())
nums = list(map(int, input().split()))
nums.sort()
div_length = max(nums)+1
divisible_list = {}
#initialize
for i in range(0, div_length):
  divisible_list[i] = 0

#count divisible numbers
for fNum in nums:
  for j in range(fNum, div_length, fNum):
   	divisible_list[j] += 1

#check for numbers
answer = 0
for num in nums:
  if (divisible_list[num] == 1):
    answer += 1
print(answer)
n = int(input())
T=[int(input()) for i in range(n)]
T = sorted(T,reverse=True)

for i in range(2,100):
  if T[0] % T[1] !=0:
    if sum(map(lambda x:T/2, T)) !=0:
      T[0] = T[0]*i
  else:
    print(T[0])
    exit()


### FIXED CODE ###

n = int(input())
T=[int(input()) for i in range(n)]


def euclid(a,b):
  r = a % b
  return euclid(b,r) if r else b

def lcm(a,b):
  return a * b //euclid(a,b)

num = T[0]
for i in range(1,n):
  num = lcm(num, T[i])
print(num)
N , T = map(int,input().split())
C=[]

for i in range(N):
    c , t = map(int,input().split())
    if t <= T :
        C.append(c)

C.sort()
print(C[0])

### FIXED CODE ###

N , T = map(int,input().split())
C=[]

for i in range(N):
    c ,t = map(int,input().split())
    if t <= T :
        C.append(c)

C.sort()
if len(C)==0:
    print('TLE')
else:
    print(C[0])
a, b = input().split()
if (a <= b):
    print(a)
else:
    print(a-1)

### FIXED CODE ###

a, b = map(int, input().split())
if (a <= b):
    print(a)
else:
    print(a-1)
a,b = map(int,input().split())

if (a%500) <= b:
  print("Yes")
else:
  print("No")


### FIXED CODE ###

a = int(input())
b = int(input())

if (a%500) <= b:
  print("Yes")
else:
  print("No")
from collections import deque
import sys
input = sys.stdin.readline
h,w=map(int, input().split(' '))
a = [input() for i in range(h)]
q = deque()
for i in range(h):
    for j in range(w):
        if a[i][j] == "#":
            a[i][j]=0
            q.append([i,j,0])
        else:
            a[i][j]=-1
while q:
    [s,t,cnt] = q.popleft()
    if s>0 and a[s-1][t] == -1:
        q.append([s-1,t,cnt+1])
        a[s-1][t] = cnt+1
    if s<h-1 and a[s+1][t] == -1:
        q.append([s+1,t,cnt+1])
        a[s+1][t] = cnt+1
    if t>0 and a[s][t-1] == -1:
        q.append([s,t-1,cnt+1])
        a[s][t-1] = cnt+1
    if t<w-1 and a[s][t+1] == -1:
        q.append([s,t+1,cnt+1])
        a[s][t+1] = cnt+1
ans = 0
for i in range(h):
    ans = max(ans,max(a[i]))
print(ans)


### FIXED CODE ###

from collections import deque
import sys
input = sys.stdin.readline
h,w=map(int, input().split(' '))
a = [input() for i in range(h)]
nl = [[] for i in range(h)]
q = deque()
for i in range(h):
    for j in range(w):
        if a[i][j] == "#":
            nl[i].append(0)
            q.append([i,j,0])
        else:
            nl[i].append(-1)
while q:
    [s,t,cnt] = q.popleft()
    if s>0 and nl[s-1][t] == -1:
        q.append([s-1,t,cnt+1])
        nl[s-1][t] = cnt+1
    if s<h-1 and nl[s+1][t] == -1:
        q.append([s+1,t,cnt+1])
        nl[s+1][t] = cnt+1
    if t>0 and nl[s][t-1] == -1:
        q.append([s,t-1,cnt+1])
        nl[s][t-1] = cnt+1
    if t<w-1 and nl[s][t+1] == -1:
        q.append([s,t+1,cnt+1])
        nl[s][t+1] = cnt+1
ans = 0
for i in range(h):
    ans = max(ans,max(nl[i]))
print(ans)
n,m=map(int,input().split())
ab=[[] for _ in range(m)]
for i in range(m):
    a,b=map(int,input().split())
    a-=1
    b-=1
    ab[a].append(b)
    ab[b].append(a)
queue=[0]
ans=[-1]*n
ans[0]=0
while queue:
    now_check=queue.pop(0)
    for i in ab[now_check]:
        if ans[i]==-1:
            queue.append(i)
            ans[i]=now_check
print('Yes')
for i in range(1,n):
    print(ans[i]+1)

### FIXED CODE ###

from sys import stdin
from collections import deque

n,m=map(int,input().split())
ab=[[] for _ in range(n)]
for i in range(m):
    a,b=map(int,stdin.readline().split())
    a-=1
    b-=1
    ab[a].append(b)
    ab[b].append(a)
queue=[0]
ans=[-1]*n
ans[0]=0
while len(queue)!=0:
    now_check=queue.pop(0)
    for i in ab[now_check]:
        if ans[i]==-1:
            queue.append(i)
            ans[i]=now_check
print('Yes')
for i in range(1,n):
    print(ans[i]+1)
r = 10000
sqrt = int(math.sqrt(r))
p = [1]*r
p[0] = 0
for i in range(1,sqrt):
    if p[i]:
        for j in range(2*i+1,r,i+1):
            p[j] = 0

while True:
    n = int(raw_input())
    if not n:
        break
    sum = 0
    for i in range(n):
        if p[i] == 1:
            sum += i
    print sum

### FIXED CODE ###

import math

r = 105000
sqrt = int(math.sqrt(r))
p = [1]*r
p[0] = 0
for i in range(1,sqrt):
    if p[i]:
        p[2*i+1::i+1] = [0 for x in range(2*i+1,r,i+1)]

s = [0 for i in range(11000)]
s[0] = 2
k = 1
for i in range(2,r):
    if p[i]:
        s[k] = i+1+s[k-1]
        k += 1
        
while True:
    n = int(raw_input())
    if not n:
        break
    print s[n-1]
import bisect
n,m = map(int,input().split())
one_li = []
to_n_li = []
for _ in range(m):
    a,b = map(int,input().split())
    if a == 1:
        one_li.append(b)
    if b == n:
        to_n_li.append(a)
#print(one_li,to_n_li)
for o in list(set(one_li)):
    index = bisect.bisect_left(to_n_li, o)
    if to_n_li[index] == o:
        print('POSSIBLE')
        exit()
else:
    print('IMPOSSIBLE')

### FIXED CODE ###

n,m = map(int,input().split())
one_li = []
to_n_li = []
for _ in range(m):
    a,b = map(int,input().split())
    if a == 1:
        one_li.append(b)
    if b == n:
        to_n_li.append(a)
ll = len(set(one_li) & set(to_n_li))
if ll == 0:
    print('IMPOSSIBLE')
else:
    print('POSSIBLE')
S = str(input())

red = S.count('0')
blue = S.count('1')
N = red + blue

if red > blue:
    ans = N - (red - blue)
elif blue < red:
    ans = N - (blue - red)
print(ans)

### FIXED CODE ###

S = input()

red = S.count('0')
blue = S.count('1')
N = 2 * min(red,blue)

print(N)
n = int(input())
q = list(map(int,input().split()))
alm = 0
for i in q:
  if i%2 == 0:
    alm = i
  	if alm%3 != 0 or alm%5 != 0:
    	print("DENIED")
        exit()

print("APPROVED")
  


### FIXED CODE ###

n = int(input())
q = list(map(int,input().split()))
ans = 0
count = 0
for i in q:
    if i%2 == 0:
        alm = i
        count += 1
        if alm%3 == 0 or alm%5 == 0:
            ans += 1
if ans == count:
    print("APPROVED")
else:
    print("DENIED")
import numpy as np
N = np.array(int(input()))
if N[-1] == 0:
  print(10)
else:
  print(N.sum())

### FIXED CODE ###

import numpy as np
N = input()
N = np.array([int(k) for k in N])
if N[-1] == 0:
  print(10)
else:
  print(N.sum())
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n,m = LI()
    a = [LI() for _ in range(m)]
    e = [set() for _ in range(n)]
    for l,r,d in a:
        e[l-1].add((r-1,d))
        e[r-1].add((l-1,-d))

    b = [False] * n
    def g(i,c):
        if c == False:
            c = 0
        b[i] = c
        for r,d in e[i]:
            if b[r] != False:
                if b[r] != c+d:
                    return False
            else:
                if not g(r,c+d):
                    return False
        return True

    for i in range(n):
        if b[i] != False:
            continue
        if not g(i,False):
            return 'No'
    return 'Yes'


print(main())





### FIXED CODE ###

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n,m = LI()
    e = [[] for _ in range(n)]
    if m > 0:
        for _ in range(m):
            l,r,d = LI()
            e[l-1].append((r-1,d))
            e[r-1].append((l-1,-d))

    b = [None] * n

    for i in range(n):
        if not b[i] is None:
            continue
        b[i] = 0
        q = [i]
        qi = 0
        nq = []
        while True:
            if len(q) == qi:
                if not nq:
                    break
                q = nq
                qi = 0
                nq = []
            j = q[qi]
            qi += 1
            c = b[j]
            for r,d in e[j]:
                if b[r] is None:
                    b[r] = c+d
                    nq.append(r)
                else:
                    if b[r] != c+d:
                        return 'No'

    return 'Yes'


print(main())
#文字列を受け取る
    s = input()

    #replaceで文字列を置き換え
    print(s.replace('2017', '2018', 1))
    #置き換え回数も指定できる。今回は必要なさそうだけど


### FIXED CODE ###

s = input()

print(s[0] + str(len(s)-2) + s[-1])
from collections import deque

n,m=map(int,input().split())
l=list(map(int,input().split()))
l=[i/2 for i in l]
if n==1:
  if (m//l[0])%2==0:
    print(int((m//l[0])/2))
  else:
    print(int((m//l[0]+1)/2))
  exit()
def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a

l=set(l)
a1=l.pop()
a2=l.pop()
g=gcd(a1,a2)
lcm=g*(a1/g)*(a2/g)
d=1
while l:
  a=l.pop()
  d=gcd(g,a)
  lcm=d*(a/d)*(g/d)
  g=lcm
  

if lcm>m:
  print(0)
  exit()
for a in l:
  if (lcm/a)%2==0:
    print(0)
    break
else:
  if (m//lcm)%2==0:
    print(int((m//lcm)/2))
  else:
    print(int((m//lcm+1)/2))

### FIXED CODE ###

#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
from fractions  import gcd
#input=sys.stdin.readline
#import bisect
n,m=map(int,input().split())
a=list(map(int,input().split()))

def lcm(a,b):
    g=math.gcd(a,b)
    return b*(a//g)
l=a[0]//2
for i in range(n):
    r=a[i]//2
    l=lcm(l,r)
for i in range(n):
    if (l//(a[i]//2))%2==0:
        print(0)
        exit()
res=m//l
print((res+1)//2)
a,b,c = input().split()

import math
 
a = int(a)
b = int(b)
c = int(c)
 
if math.isclose(math.sqrt(c) - math.sqrt(b) - math.sqrt(a), 0, abs_tol=1e-10):
    print('Yes')
else:
    print('No')

### FIXED CODE ###

a,b,c = map(int, input().split())

if 4 * a * b < (c - a- b)**2 and c - a- b > 0:
    print("Yes")
else:
    print("No")
n = int(input())
A = list(map(int,input().split()))

b = 1
B=[0]*(n+1)
count = 0
for i in range(n):
    B[i] = b
    if 2*(b - A[i]) < A[i+1]:
        count += 1
    b = 2*(b - A[i])

B[n] = b

j = 0
while A[n] > B[j]:
    j+=1

total = 0
for i in range(j):
    total += B[i]

s = A[n]
for i in range(n-1,j-1,-1):
    total += min(B[i],s+A[i])
    s+=A[i]

if count==0:
    print(total+A[n])
else:
    print('-1')

### FIXED CODE ###

n = int(input())
A = list(map(int,input().split()))

b = 1
B=[0]*(n+1)
count = 0

t=len(A)-1
for i in range(t):
    B[i] = b
    if 2*(b - A[i]) < A[i+1]:
        count += 1
        break
    b = 2*(b - A[i])
B[n] = b

if n == 0 and A[0] > 1:
    count += 1

j = 0
while count == 0 and A[t] > B[j]:
    if j == n:
        break
    j += 1

total = 0
for i in range(j):
    total += B[i]

s = A[t]
for i in range(t-1,j-1,-1):
    total += min(B[i],s+A[i])
    s+=A[i]

if count==0:
    print(total+A[t])
else:
    print('-1')
i = input().split("\n")
print(6 - int(i[0]) - int(i[1]))

### FIXED CODE ###

a = int(input())
b = int(input())
print(6 - a - b)
Q=int(input())
n=10100
is_prime=[1]*(n+10)
is_prime[0]=0
is_prime[1]=0
for i in range(2,n+1):
	for j in range(i*2,n+1,i):
		if is_prime[j]==False:
			continue
		is_prime[j]=0
a=[0]*(n+10)
for i in range(2,n+1):
	if is_prime[i]%2==0:
		continue
	if is_prime[i] and is_prime[int((i+1)/2)]:
		a[i]=1
s=[0]*(n+10)		
for i in range(n):
	s[i+1]=a[i]+s[i]
ans=[]
for i in range(Q):
	l,r=map(int,input().split())
	ans.append(s[r+1]-s[l])
print(*ans,sep='\n')

### FIXED CODE ###

Q=int(input())
n=100000
is_prime=[1]*(n+10)
is_prime[0]=0
is_prime[1]=0
for i in range(2,n+1):
	for j in range(i*2,n+1,i):
		if is_prime[j]==False:
			continue
		is_prime[j]=0
a=[0]*(n+10)
for j in range(2,n+1):
	if is_prime[j]%2==0:
		continue
	if is_prime[j] and is_prime[int((j+1)/2)]:
		a[j]=1
s=[0]*(n+10)		
for k in range(n):
	s[k+1]=a[k]+s[k]
ans=[]
for _ in range(Q):
	l,r=map(int,input().split())
	ans.append(s[r+1]-s[l])
print(*ans,sep='\n')
a,b = map(int,input().split())

if a>b:
  print("GREATER")

elif a == b:
  print("EQUAL")

else:
  print("LESS")

### FIXED CODE ###

a = int(input())
b = int(input())
if a>b:
  print("GREATER")
  
elif a == b:
  print("EQUAL")
  
else:
  print("LESS")