Harryxun/stf_run huggingface dataset:
import sys
from collections import deque
sys.setrecursionlimit(10 ** 5)
input = sys.stdin.readline


def main():
    N, Q = map(int, input().split())
    ans = deque([0] * N)
    con = [[] for i in range(N)]

    for _ in range(N - 1):
        p, c = map(int, input().split())
        con[p-1].append(c-1)
        con[c-1].append(p-1)

    for _ in range(Q):
        p, v = map(int, input().split())
        ans[p-1] += v

    stacks = deque()
    stacks.append((0, -1))

    while stacks:
        stack = stacks.pop()
        node, parent = stack[0], stack[1]

        children = con[node]
        for child in children:
            if child == parent:
                continue
            ans[child] += ans[node]
            stacks.append((child, node))

    print(*ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

n = int(input())
s = input()

if n >= 3200:
  print(s)
else:
  print('red')
from python.c import squares


h, w, k = map(int, input().split())
c = [input() for _ in range(h)]

count = 0
for binh in range(2**h):
    for binw in range(2**w):
        redh, redw = bin(binh)[2:], bin(binw)[2:]  # remove suffix '0x'
        squares = [list(row) for row in c]
        for rh in redh:
            for wh in range(w):
                squares[rh][wh] = '*'
        for rw in redw:
            for hw in range(h):
                squares[rw][hw] = '*'
        count += sum(row.count('#') for row in squares) == k

print(k)


### FIXED CODE ###

import itertools
import numpy as np

h, w, k = map(int, input().split())
c = [input() for _ in range(h)]

count = 0
for ph in itertools.product([0, 1], repeat=h):
    for pw in itertools.product([0, 1], repeat=w):
        squares = np.array([[1 if cell == '#' else -1 for cell in row] for row in c])
        squares[np.array(ph) == True, :] *= 0
        squares[:, np.array(pw) == True] *= 0
        if np.count_nonzero(squares == 1) == k:
            count += 1

print(count)
n,m = map(int,input().split())
k1 = list(list(map(int,input().split()))for i in range(m))
p = map(int,input().split())
s = list(k1[i][1:]for i in range(m))
ans = 0

for i in range(2**n):
    on = True
    for j in range(m):
        on = bin(s[j]&i)lcount('1')%2 == p[j]
        if not on:
            break
    ans += on
print(ans)

### FIXED CODE ###

n,m = map(int,input().split())
k_and_s = list(list(map(int,input().split()))for i in range(m))
p = list(map(int,input().split()))

k = []
s = []
switch = list([[0 for i in range(m)]for i in range(n)])
switch_1 = [0 for i in range(n)]
cnt = 0

for i in range(1,len(p)+1):
    if p[i-1] == 1:
        cnt += 2**(m-i)
    if i == m:
        p_1 = cnt

for i in range(m):
    k.append(k_and_s[i][0:1][0])
    s.append(k_and_s[i][1:])

for i in range(len(s)):
    for j in range(len(s[i])):
        switch[s[i][j]-1][i] = 1

for i in range(len(switch)):
    cnt = 0
    for j in range(1,len(switch[i])+1):
        if switch[i][j-1] == 1:
            cnt += 2**(m-j)
        if j == m:
            switch_1[i] = cnt

ans = 0
for i in range(1<<n):
    t = 0
    for j in range(n):
        if i >> j & 1 != 0:
            t ^= switch_1[j]
    if t==p_1:
        ans +=1
print(ans)
N = input()
if(N[1] == 2, 4, 5, 7, 9):
    print('hon')
elif(N[1] == 0, 1, 6, 8):
    print('pon')
elif(N[1] == 3):
    print('bon')

### FIXED CODE ###

N = list(input())
l = len(N)
if N[l-1] == '2' or N[l-1] == '4' or N[l-1] == '5' or N[l-1] == '7' or N[l-1] == '9':
    print('hon')
elif N[l-1] == '0' or N[l-1] == '1' or N[l-1] == '6' or N[l-1] == '8':
    print('pon')
elif N[l-1] == '3':
    print('bon')
a,b=input().split
x=int(a+b)
for i in range(1000):
  if i**2==x:
    print("Yes")
    exit()
print("No")

### FIXED CODE ###

a,b=input().split()
x=int(a+b)
for i in range(1000):
  if i**2==x:
    print("Yes")
    exit()
print("No")
a,b,c=input().split()
if a[-1]==b[0] and b[-1]==c[0]:
    print("YES")
else:
    print("NO"

### FIXED CODE ###

a,b,c=input().split()
if a[-1]==b[0] and b[-1]==c[0]:
    print("YES")
else:
    print("NO")
b == input()
print('A' if b == 'T')

### FIXED CODE ###

b = input()
if b == 'A':
  print('T')
elif b == 'T':
  print('A')
elif b == 'C':
  print('G')
else:
  print('C')
n = int(input())
A = list(map(int, input().split(' ')))
q = int(input())
M = list(map(int, input().split(' ')))

def rec(i, sum, m):
    if i == n:
        if sum == m:
            return True
        else:
            return False

    if sum > m:
        return False

    rst = rec(i+1, sum, m) or rec(i+1, sum + A[i], m)
    return rst

for m in M:
    if rec(0, 0, m):
        print('yes')
    else:
        print('no')



### FIXED CODE ###

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

# 上限と下限でフィルター
max_A = 0
min_A = float('inf')
for num in A:
    max_A += num
    if num < min_A:
        min_A = num

def rec(i, m):
    if m < 0:
        return False
    elif m == 0:
        return True
    if i >= n:
        return False

    rst = rec(i+1, m - A[i]) or rec(i+1, m)
    return rst

for m in M:
    if m < min_A or max_A < m:
        print('no')
    elif rec(0, m):
        print('yes')
    else:
        print('no')
l = []
l= list(map(int,input().split()))

if a == b and a == c
	print("Yes")
else:
  	print("No")

### FIXED CODE ###

l = []
l= list(map(int,input().split()))
a = l[0]
b = l[1]
c = l[2]

if a == b and a == c:
	print("Yes")
else:
  	print("No")
a = int(input())
b,c = map(int, input().split())
k = int(input())
n = 0

for s in range(k):
  if a > 0:
    n += 1
  elif b > 0:
    n += 0
  else:
    n -= 1
    
print(n)


### FIXED CODE ###

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

if k <= a:
  print(k)
elif a < k <= a+b:
  print(a)
elif a+b < k <= a+b+c:
  print(2*a + b - k)
N,M=map(int,input().split())

H=[0]+list(map(int,input().split()))

J={x:[] for x in range(1,N+1)}

for i in range(M):
    a,b=map(int,input().split())
    J[a].append(b)
    J[b].append(a)

S=0
for x in J:
    f=1
    for y in J[x]:
        if H[x]<=H[y]:
            f=0
    S+=f

print(S)


### FIXED CODE ###

def Binary_Search_Small_Count(A,x,equal=False,sort=False):
    """2分探索によって,x未満の要素の個数を調べる.

    A:リスト
    x:調べる要素
    sort:ソートをする必要があるかどうか(Trueで必要)
    equal:Trueのときはx"未満"がx"以下"になる
    """
    if sort:
        A.sort()

    if A[0]>x or ((not equal) and A[0]==x):
        return 0

    L,R=0,len(A)
    while R-L>1:
        C=L+(R-L)//2
        if A[C]<x or (equal and A[C]==x):
            L=C
        else:
            R=C

    return L+1

def Binary_Search_Equal_Count(A,x,sort=False):
    """2分探索によって,xの個数を調べる.

    A:リスト
    x:調べる要素
    sort:ソートをする必要があるかどうか(Trueで必要)
    equal:Trueのときはx"を超える"がx"以上"になる
    """

    if sort:
        A.sort()

    if x<A[0] or A[-1]<x:
        return 0

    X=Binary_Search_Small_Count(A,x,equal=True)
    Y=Binary_Search_Small_Count(A,x,equal=False)
    return X-Y
#================================================
N=int(input())
A=["*"]+list(map(int,input().split()))

B=[0]*N
for j in range(1,N+1):
    B[j-1]=j-A[j]
B.sort()

K=0
del A[0]
for i in range(1,N+1):
    K+=Binary_Search_Equal_Count(B,i+A[i-1],False)
print(K)
s = int(input())
w = int(input())
if w > s
	print("unsafe")
else
	print("safe")

### FIXED CODE ###

s, w = map(int, input().split())
if ( w >= s ):
    print("unsafe")
else:
    print("safe")
N = int(input())
A = list(int(input()) for k in range(N))

mx, mxn = sorted(A, reverse=True)[:2]

result = [mxn if x==mn else mx for x in A]
print('\n'.join(map(str, result)))

### FIXED CODE ###

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

sort = sorted(A, reverse=True)
mx = sort[0]
mxn = sort[1]

for i in range(N):
    if A[i] == mx:
        print(mxn)
    else:
        print(mx)
A, B = map(int, input().split())
if A == B:
  print('Draw')
else:
  if A == 1:
    print('Alice')
  elif B == 1:
    print('Bob')
  elif A < B:
    print('Bob')
  else B < A:
    print('Alice')

### FIXED CODE ###

A, B = map(int, input().split())
if A == B:
  print('Draw')
else:
  if A == 1:
    print('Alice')
  elif B == 1:
    print('Bob')
  elif A < B:
    print('Bob')
  elif B < A:
    print('Alice')
N = int(input())
A = list(map(int, input().split()))
# TLE
duplication = {}
ans = 0
for x in A:
    if x in duplication:
        continue
    count = A.count(x)
    if count > 1:
        duplication[x] = count
        ans += count*(count-1)//2
for x in A:
    # if x not in duplication:
    #     print(ans)
    # else:
    print(ans -(duplication[x]-1))

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
# TLE
def test():
    duplication = {}
    ans = 0
    for x in A:
        if x in duplication:
            continue
        count = A.count(x)
        if count > 1:
            duplication[x] = count
            ans += count*(count-1)//2
    for x in A:
        if x not in duplication:
            print(ans)
        else:
            print(ans -(duplication[x]-1))
from collections import defaultdict

sum = 0
count_dic = defaultdict(int)
for x in A:
    count_dic[x] +=1
for v in count_dic.values():
    sum += v*(v-1)//2
for x in A:
    print(sum -(count_dic[x]-1))
from decimal import Decimal
a= input().split() 
b=Decimal(a/3)
print(b*b*b)

### FIXED CODE ###

a= int(input())
b=float(a/3.00000000)
print(b*b*b)
import numpy as np
from itertools import accumulate

N = int(input())
s = input()
w = np.array(list(map(lambda x: 1 if x == 'W' else 0, s)))
e = np.array(list(map(lambda x: 1 if x == 'E' else 0, s)))
w = np.add.accumulate(w)
e = np.flip(np.add.accumulate(np.flip(e)))
# print(w)
# print(e)
ans = []
for i in range(N):
    num = 0
    if 0 < i: num += w[i - 1]
    if i < N - 1: num += e[i + 1]
    ans.append(num)
# print(ans)
print(min(ans))

### FIXED CODE ###

from itertools import accumulate
N = int(input())
s = input()
w = list(map(lambda x: 1 if x == 'W' else 0, s))
e = list(map(lambda x: 1 if x == 'E' else 0, s))
e.reverse()
w = list(accumulate(w))
e = list(accumulate(e))
e.reverse()
# print(w)
# print(e)
ans = []
for i in range(N):
    num = 0
    if 0 < i: num += w[i - 1]
    if i < N - 1: num += e[i + 1]
    ans.append(num)
# print(ans)
print(min(ans))
"""
the condition is straightforward.
each element of A and B must multiply to the same value.
to minimise the total of B, simply make that value as small
as possible (since A is fixed).

lcm(2, 3, 4) = 12
therefore B is
12/2, 12/3, 12/4
and the sum of B is
12/2 + 12/3 + 12/4

lcd of a list is loop: lcd(partial, new_value)
lcd(a, b) = ab / gcd(a, b)
"""

from fractions import gcd


def lcm(list_ints):
    lcm_ongoing = 1
    for val in list_ints:
        lcm_ongoing = int(round(val*lcm_ongoing/gcd(val, lcm_ongoing)))
    return lcm_ongoing


def flatten(N, A):
    # get lcm
    lcm_of_A = lcm(A)
    # get sum of lcm/values
    ans = sum(int(round(lcm_of_A/value)) for value in A)
    modulo_value = int(int(10e9)+7)
    return ans % modulo_value


if __name__ == "__main__":
    test1 = \
"""3
2 3 4"""
    test2 = \
"""5
12 12 12 12 12"""
    test3 = \
"""3
1000000 999999 999998"""
    test = test3
    # N = int(test.split("\n")[0])
    # A = list(map(int, test.split("\n")[1].split()))
    N = int(input())
    A = list(map(int, input().split()))
    print(flatten(N, A))

### FIXED CODE ###

"""
the condition is straightforward.
each element of A and B must multiply to the same value.
to minimise the total of B, simply make that value as small
as possible (since A is fixed).

lcm(2, 3, 4) = 12
therefore B is
12/2, 12/3, 12/4
and the sum of B is
12/2 + 12/3 + 12/4

lcd of a list is loop: lcd(partial, new_value)
lcd(a, b) = ab / gcd(a, b)
"""

from fractions import gcd


def lcm(list_ints):
    lcm_ongoing = 1
    for val in list_ints:
        lcm_ongoing = val*lcm_ongoing//gcd(val, lcm_ongoing)
    return lcm_ongoing


def flatten(N, A):
    # get lcm
    lcm_of_A = lcm(A)
    # get sum of lcm/values
    ans = sum(lcm_of_A//value for value in A)
    modulo_value = int(int(10e8)+7)
    return ans % modulo_value


if __name__ == "__main__":
    test1 = \
"""3
2 3 4"""
    test2 = \
"""5
12 12 12 12 12"""
    test3 = \
"""3
1000000 999999 999998"""
    test = test3
    # N = int(test.split("\n")[0])
    # A = list(map(int, test.split("\n")[1].split()))
    N = int(input())
    A = list(map(int, input().split()))
    print(flatten(N, A))
k,n=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
temp=a[0]+a[n-1]
for i in range(1,n):
  temp=max(ans,a[i]-i[i-1])
print(k-temp)

### FIXED CODE ###

k,n=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
temp=a[0]+k-a[n-1]
for i in range(1,n):
  temp=max(temp,a[i]-a[i-1])
print(k-temp)
import sys

n,m,x,y = map(int, sys.stdin.readline().split())
x_list = list(map(int, sys.stdin.readline().split()))
y_list = list(map(int, sys.stdin.readline().split()))

x_max = max(x_list)
y_min = min(y_list)

if y_min <= x_max
    print("War")
else:
    print("No War")

### FIXED CODE ###

N,M,X,Y = map(int,input().split())
x = max(X,max(list(map(int,input().split()))))
y = min(Y,min(list(map(int,input().split()))))
 
if y>x:
  print("No War")
else:
  print("War")
import collections
N,K,Q = map(int,input().split())

A=[]
for i in range(Q):
    A.append(int(input()))
    
jud = Q - K

ans_list = [0] * N

c = collections.Counter(A)
key = list(c.keys())
val = list(c.values())
for i in range(len(c)):
    ans_list[key[i]] = val[i]
#print(ans_list)

for i in range(N):
    if ans_list[i] > jud:
        print("Yes")
    else:
        print("No")

### FIXED CODE ###

import collections
N,K,Q = map(int,input().split())

A=[]
for i in range(Q):
    A.append(int(input()))
    
jud = Q - K

ans_list = [0] * N

c = collections.Counter(A)
key = list(c.keys())
val = list(c.values())
for i in range(len(c)):
  ans_list[key[i]-1] = val[i]

for i in range(len(c)):
    if val[i] > jud:
        ans_list[key[i]-1] +=1
for i in range(N):
    if ans_list[i] > jud:
        print("Yes")
    else:
        print("No")
#n = map(int,input().split())
mlist = list(map(int,input().split()))

i=0
while(True):
    i=i+1
    if mlist[i] % 2 == 0:
        mlist.append(mlist[i]/2)
    else:
        mlist.append(3*mlist[i]+1)
    for item in range(1,i):
        if mlist[0]==item:
            break
print(i)


### FIXED CODE ###

#n = map(int,input().split())
mlist = list(map(int,input().split()))

i=0
while(True):
    if mlist[i] % 2 == 0:
        mlist.append(mlist[i]/2)
    else:
        mlist.append(3*mlist[i]+1)
    
    breakFlg = False
    for num in range(0,i):
        if int(mlist[num])==int(mlist[i]):
            if num!=i:
                breakFlg = True
    i=i+1
    if(breakFlg):
        break
print(i)
import numpy as np
N = int(input())

ARR = []

for i in range(N):
    ARR.append([int(s) for s in input().split(" ")])

PRR = []

for i in range(N):
    PRR.append([int(s) for s in input().split(" ")])

def calculate(n, arr, prr):
    arr = np.array(arr)

    brr = []
    for i in range(1,2 ** 10):

        mask = np.zeros(10)
        for j in range(0, 10):
            m = i >> j & 1
            mask[9-j] = m
        s = np.count_nonzero((arr == mask) & (arr == 1),axis=1)

        sum = 0
        for _i in range(n):
            sum = sum + prr[_i][s[_i]]

        brr.append(sum)


    return brr

result = calculate(N, ARR, PRR)
print(max(result))




### FIXED CODE ###

n = int(input())

frr = []

for i in range(n):
    frr.append([int(s) for s in input().split(" ")])

prr = []

for i in range(n):
    prr.append([int(s) for s in input().split(" ")])

# n = 2
#
# frr = [
#     [1, 1, 1, 1, 1, 0, 0, 0, 0, 0],
#     [0, 0, 0, 0, 0, 1, 1, 1, 1, 1]
# ]
#
# prr = [
#     [0, -2, -2, -2, -2, -2, -1, -1, -1, -1, -1],
#     [0, -2, -2, -2, -2, -2, -1, -1, -1, -1, -1]
# ]


res = []
for i in range(1,2 ** 10):
    count = [0 for s in range(n)]

    mask = []
    for j in range(10):
        m =  i >> j & 1
        mask.append(m)
        if m == 1:
            for k in range(n):
                if frr[k][j] == 1:
                    count[k] = count[k] + 1

    mm = []
    for index,c in enumerate(count):
        mm.append(prr[index][c])

    res.append(sum(mm))

print(max(res))
a=int(input())
b=int(input())
if a+b==15:
    print("+")
elif a*b==15:
    print("*")
else:
    print("x")

### FIXED CODE ###

a,b=map(int,input().split())
if a+b==15:
    print("+")
elif a*b==15:
    print("*")
else:
    print("x")
def hoge(lst,i):
    if lst[i]==lst[i+1]:
        hoge(lst,i+1)
    if lst[i]>lst[i+1]:return True
    if lst[i]<lst[i+1]:return False

N = int(input())
H = list(map(int,input().split()))
det=0

for i in range(N-1):
    if H[i]-1>H[i+1]:
        det+=1
        print("No")
        break
    if i+2<=N-1:
        if H[i]>H[i+1] and H[i+1] > H[i+2]:
            det+=1
            print("No")
            break
        if hoge(H,i):
            det+=1
            print("No")
            break
if det==0:print("Yes")

### FIXED CODE ###


def hoge(lst,i):
    if lst[i]==lst[i+1] and len(lst)>i+2:
        return hoge(lst,i+1)
    if lst[i]>lst[i+1]:return True
    if lst[i]<lst[i+1]:return False

N = int(input())
H = list(map(int,input().split()))
det=0

for i in range(N-1):
    if H[i]-1>H[i+1]:
        det+=1
        print("No")
        break
    if i+2<=N-1:
        if H[i]>H[i+1] and H[i+1] > H[i+2]:
            det+=1
            print("No")
            break
        if H[i]>H[i+1] and hoge(H,i+1):
            det+=1
            print("No")
            break
if det==0:print("Yes")
N = int(input())
A = list(map(int, input().split(" ")))
A.sort()

n_pos = len([a for a in A if a > 0])
operations = []
if n_pos <= (N + 1) // 2:
    pos = [a for a in A if a > 0]
    neg = [a for a in A if a <= 0]
    tmp = pos[0]
    for i in range(n_pos-1):
        operations.append((neg[i], tmp))
        tmp = neg[i] - tmp
        operations.append((pos[i+1], tmp))
        tmp = pos[i+1] - tmp
        
    for i in range(n_pos-1, len(neg)):
        operations.append((tmp, neg[i]))
        tmp = tmp - neg[i]
else:
    neg = A[:N//2]
    pos = A[N//2:]
    if N % 2 == 1:
        tmp = pos[0]
        for i in range(N//2):
            operations.append((neg[i], tmp))
            tmp = neg[i] - tmp
            operations.append((pos[i+1], tmp))
            tmp = pos[i+1] - tmp
    else:
        operations.append((pos[0], neg[0]))
        tmp = pos[0] - neg[0]
        for i in range(1, N//2):
            operations.append((neg[i], tmp))
            tmp = neg[i] - tmp
            operations.append((pos[i], tmp))
            tmp = pos[i] - tmp

print(tmp)
for o in operations:
    print("{} {}".format(o[0], o[1]))

### FIXED CODE ###

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

n_pos = len([a for a in A if a > 0])
operations = []
if n_pos == 0:
    pos = [A[-1]]
    neg = A[:-1]
elif n_pos == N:
    pos = A[1:]
    neg = A[:1]
else:
    pos = [a for a in A if a > 0]
    neg = [a for a in A if a <= 0]
if len(pos) >= 2:
    tmp = neg[0]
    for i in range(len(pos)-1):
        operations.append((tmp, pos[i]))
        tmp = tmp - pos[i]
    operations.append((pos[-1], tmp))
    tmp = pos[-1] - tmp
    for i in range(1, len(neg)):
        operations.append((tmp, neg[i]))
        tmp = tmp - neg[i]
else:
    tmp = pos[0]
    for i in range(len(neg)):
        operations.append((tmp, neg[i]))
        tmp = tmp - neg[i]
print(tmp)
for o in operations:
    print("{} {}".format(o[0], o[1]))
S = input()
if S = "ABC":
  print("ARC")
else:
  print("ABC")

### FIXED CODE ###

S = input()
if S == "ABC":
  print("ARC")
else:
  print("ABC")
def main():
    N, L = map(int, input().split())
    a = sum([L + n for n in range(N)])
    if L > 0:
        print(a - a[0])
    elif abs(L) >= N:
        print(a - a[-1])
    else:
        print(a)


main()


### FIXED CODE ###

def main():
    N, L = map(int, input().split())
    a = [L + n for n in range(N)]
    if L > 0:
        print(sum(a) - a[0])
    elif abs(L) >= N:
        print(sum(a) - a[-1])
    else:
        print(sum(a))


main()
H,W = map(int,input().split())
field = [input() for x in range(H)]
vx = [0,0,1,-1]
vy = [1,-1,0,0]
reached = [[-1 for x in range(W)]for x in range(H)]
from collections import deque
def bfs(y,x):
    q = deque([[y,x]])
    reached[y][x] = 1

    while q:
        y,x = q.popleft()
        if [y,x] == [H-1,W-1]:
            return reached[y][x]
        for dy,dx in zip(vy,vx):
            ny,nx = y+dy,x+dx
            if not (0<=ny<H and 0<=nx<W):
                continue
            if field[ny][nx] == '.' and reached[ny][nx] == -1:
                q.append([ny,nx])
                reached[ny][nx] = reached[y][x] + 1
bk = 0
for x in field:
    for y in x:
        if y == '#':
            bk += 1
print(H*W-bfs(0,0)-bk)


### FIXED CODE ###

H,W = map(int,input().split())
field = [input() for x in range(H)]
vx = [0,0,1,-1]
vy = [1,-1,0,0]
reached = [[-1 for x in range(W)]for x in range(H)]
from collections import deque
def bfs(y,x):
    q = deque([[y,x]])
    reached[y][x] = 1

    while q:
        y,x = q.popleft()
        if [y,x] == [H-1,W-1]:
            return reached[y][x]
        for dy,dx in zip(vy,vx):
            ny,nx = y+dy,x+dx
            if not (0<=ny<H and 0<=nx<W):
                continue
            if field[ny][nx] == '.' and reached[ny][nx] == -1:
                q.append([ny,nx])
                reached[ny][nx] = reached[y][x] + 1
    return -1
bk = 0
for x in field:
    for y in x:
        if y == '#':
            bk += 1
ans = bfs(0,0)
if ans==-1:
    print(-1)
else:
    print(H*W-ans-bk)
n = int(input())
a = list(map(int, input().split()))
MOD = 10 ** 9 + 7

def extended_euclid(x, y):
    c0, c1 = x, y
    a0, a1 = 1, 0
    b0, b1 = 0, 1

    while c1 != 0:
        m = c0 % c1
        q = c0 // c1

        c0, c1 = c1, m
        a0, a1 = a1, (a0 - q * a1)
        b0, b1 = b1, (b0 - q * b1)

    # return c0, a0, b0
    return a0

def quotient(p, q): #p: 分子, q: 分母
	return (extended_euclid(q, MOD) * p) % MOD

def factorial(i):
	if i == 1:
		return 1
	else:
		return (factorial(i-1) * i) % MOD

inv_list = [1]
for i in range(2, n+1):
	inv_list.append((inv_list[-1] + quotient(1, i)) % MOD)

#print(inv_list)

ans = 0
for i in range(n):
	ans += ((inv_list[i] + inv_list[n-1-i] - 1) * a[i]) % MOD
	ans %= MOD
ans *= factorial(n)
ans %= MOD
print(ans)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)

n = int(input())
a = list(map(int, input().split()))
MOD = 10 ** 9 + 7

def extended_euclid(x, y):
    c0, c1 = x, y
    a0, a1 = 1, 0
    b0, b1 = 0, 1

    while c1 != 0:
        m = c0 % c1
        q = c0 // c1

        c0, c1 = c1, m
        a0, a1 = a1, (a0 - q * a1)
        b0, b1 = b1, (b0 - q * b1)

    # return c0, a0, b0
    return a0

def quotient(p, q): #p: 分子, q: 分母
	return (extended_euclid(q, MOD) * p) % MOD

def factorial(i):
	if i == 1:
		return 1
	else:
		return (factorial(i-1) * i) % MOD

inv_list = [1]
for i in range(2, n+1):
	inv_list.append((inv_list[-1] + quotient(1, i)) % MOD)

#print(inv_list[-1])
#print(factorial(n))

ans = 0
for i in range(n):
	ans += ((inv_list[i] + inv_list[n-1-i] - 1) * a[i]) % MOD
	ans %= MOD
ans *= factorial(n)
ans %= MOD
print(ans)
A, B = list(map(int, input().split()))

def calc_num(N):
  if N % 4 == 1:
    return (1, 0)
  if N % 4 == 2:
    return (N, 1)
  if N % 4 == 3:
    return (0, 0)
  return (N, 0)

A, subA = calc_num(A-1)
B, subB = calc_num(B)

A = [int(i) for i in str(bin(A)).split("b")[1]]
B = [int(i) for i in str(bin(B)).split("b")[1]]
A[-1] += subA
A[-1] %= 2
B[-1] += subB
B[-1] %= 2

if len(B) > len(A):
  temp = [0] * (len(B)-len(A))
  temp.extend(A)
  A = temp
#print(A)
#print(B)

res = [((A[i]+B[i])%2)*2**(len(A)-i-1) for i in range(len(A))]
#print(res)
print(sum(res))


### FIXED CODE ###

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

def calc_num(N):
  if N==0:
    return 0
  if N % 4 == 1:
    return 1
  if N % 4 == 2:
    return N ^ 1
  if N % 4 == 3:
    return 0
  return N ^ 0

A = calc_num(A-1)
B = calc_num(B)

print(A^B)
n=int(input())
s=input()
ans=0
w = s.count('.')
for i in range(0,n-1):
    if (s[i]=='#')&(s[i+1]=='.'):
        ans+=1
        s[i+1]='#'
print(min(ans,w,n-w))

### FIXED CODE ###

n=int(input())
s=input()
w = s.count('.')
b = 0
ans=w+b
for i in s:
    if i=='#':
        b+=1
    else:
        w-=1
    if ans>=b+w:
        ans=b+w
print(ans)