Harryxun/stf_run huggingface dataset:
N,M=[int(x) for x in input().split()]
I=[[] for n in range(N)]
G=[n for n in range(N)]
W=[1 for n in range(N)]
E=[]

result=[]
ans = int(N * (N-1) / 2)

def union(i,g):
    if(G[i]!=g):
        G[i]=g
        for n in I[i]:
            union(n,g)

for m in range(M):
    A,B=[int(x) for x in input().split()]
    E.append((A-1,B-1))

for m in range(M):
    result.append(ans)
    if(ans>0):
        A,B=E.pop()
        Ga,Gb=G[A],G[B]
        if (Ga!=Gb):
            Wa,Wb=W[Ga],W[Gb]
            ans=ans-(Wa*Wb)
            if (Wb>Wa):
                union(Ga,Gb)
                W[Gb]=Wa+Wb
            else:
                union(Gb,Ga)
                W[Ga]=Wa+Wb
        I[A].append(B)
        I[B].append(A)

for r in reversed(result):
    print(r)


### FIXED CODE ###

N,M=[int(x) for x in input().split()]
G=[-1] * N
W=[0] * N
E=[]

result=[]
ans = int(N * (N-1) / 2)

def union(i,j):
    gi=find(i)
    gj=find(j)

    if(gi!=gj):
        if W[gi] > W[gj]:
            G[gi]+=G[gj]
            G[gj]=gi
        else:
            G[gj]+=G[gi]
            G[gi]=gj
            if W[gi]==W[gj]:
                W[gj]+=1

def find(i):
    if G[i]<0:
        return i;
    else:
        G[i]=find(G[i])
        return G[i]

for m in range(M):
    A,B=[int(x) for x in input().split()]
    E.append((A-1,B-1))

for m in range(M):
    result.append(ans)
    if(ans>0):
        A,B=E.pop()
        ga,gb=find(A),find(B)
        if (ga!=gb):
            ans=ans-(G[ga]*G[gb])
            union(A,B)

for r in reversed(result):
    print(r)
# coding: utf-8
import math
from decimal import Decimal

N = int(input())

votes = []

for _ in range(N):
    votes.append([Decimal(n) for n in input().split()])

befa = 1
befb = 1

for a, b in votes:
    kakeru = Decimal(max(math.ceil(befa / a), math.ceil(befb / b)))
    befa = a * kakeru
    befb = b * kakeru

print(int(befa)+int(befb))

### FIXED CODE ###

# coding: utf-8

colors = input().split()

bef = 0
count = 0
colors.sort()

for c in colors:
    if bef == 0:
        count += 1
        bef = c
    else:
        if c > bef:
            count += 1
            bef = c

print(count)
N = int(input())
print(sum(range(N))

### FIXED CODE ###

N = int(input())
print(sum(range(N)))
a = input()
b = 0
c = 0
i = 0
while i < a :
    if a[i] == "A" :
        b = b + 1
    if a[i] == "B" :
        c = c + 1
    i = i + 1
if (b > 0) and (c > 0) :
    print("Yes")
else:
    print("No")

### FIXED CODE ###

a = input()
b = 0
c = 0
i = 0
while i < len(a) :
    if a[i] == "A" :
        b = b + 1
    if a[i] == "B" :
        c = c + 1
    i = i + 1
if (b > 0) and (c > 0) :
    print("Yes")
else:
    print("No")
def main():
    d, n = map(int, input().split())
    counter = 0
    for _ in range(n):
        x, y = map(int, input().split())
        if x**2 + y**2 <= d:
            counter += 1
    return print(str(counter))

main()

### FIXED CODE ###

def main():
    n, d = map(int, input().split())
    counter = 0
    for _ in range(n):
        x, y = map(int, input().split())
        if x**2 + y**2 <= d**2:
            counter += 1
    return print(counter)
 
main()
print(imput().count"1")

### FIXED CODE ###

print(input().count("1"))
import math
n=int(input())
arr=list(map(int,input().split()))
dic={}
for c in arr:
    dic.setdefault(c,0)
    dic[c]+=1
ans=True
#n is odd 5(4 2 0 2 4)
if n%2!=0:
    for c in range(2,n-1,2):
        if dic[c]!=2:
            ans=False
            break
    if dic[0]!=1:
        ans=False
#n is even 8 (7 5 1 1 7 3 5 3)        
else:
    for c in range(1,n-1,2):
        if dic[c]!=2:
            ans=False
if ans and n!=0:
    print(2**math.floor(n/2)%((10**9)+7))
else:
    print(0)
  

### FIXED CODE ###

N=int(input())
l=list(map(int,input().split()))
a=1
if N%2==0:
    if len(l)!=len(set(l))*2:
        a=0
else:
    if l.count(0) == 1:
        l.remove(0)
        if len(l) != 2*len(set(l)):
            a = 0
    else:
        a=0
if a:
      print((2**(N//2))%(10**9+7))
else:
      print(0)
n = int(input())
f = True

if n%7 == 0:
    print("Yes")
    f = False

while(n > 0)and(f):
    if(n%4 == 0):
        print("Yes")
        f = False
    n -= 7
if(f):
    print("No")

### FIXED CODE ###

n,k = map(int,input().split())
print(-(-(n%k) // k))
N = int(input())
A = list(map(int, input().split()))

import numpy as np

a = np.zeros((N, N))
for i in range(N-1):
    a[i][i] = 1
    a[i][i+1] = 1
a[-1][-1] = 1
a[-1][0] = 1
b = np.array(A) * 2
X = np.linalg.solve(a, b)
X = map(int, X)
print(" ".join(map(str, X)))

### FIXED CODE ###

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

x = [None] * N
x[0] = sum(A) - 2 * sum([a for a in A[1::2]])
for i in range(N-1):
    x[i+1] = 2 * A[i] - x[i]
print(" ".join(map(str, x)))
A = int(input())
B = int(input())
C = int(input())
X = int(input())
count = 0
for i in range(A):
    for n in range(B):
        for m in range(C):
        if i*500+n*100+m*50==X:
        count += 1
print(count)

### FIXED CODE ###

A = int(input())
B = int(input())
C = int(input())
X = int(input())
count = 0
for a in range(A+1):
    for b in range(B+1):
        for c in range(C+1):
            if a*500+b*100+c*50==X:
                count += 1
print(count)
import numpy as np
 
N = int(input())
A = list(map(np.int64, input().split()))
 
A = np.array(A)
 
ans = np.prod(A)
 
 
if ans >10**18:
  print(-1)
else:
  print(ans)

### FIXED CODE ###

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

print(A*B)
import sys
import math
input_list=sys.argv[0:]
H=int(input_list[1])
A=int(input_list[2])
Q=math.ceil(H/A)
print(Q)

### FIXED CODE ###

import math
str = input()
str_list=str.split()
H=int(str_list[0])
A=int(str_list[1])
Q=math.ceil(H/A)
print(Q)
n,w=map(int,input().split())
wv=[list(map(int,input().split())) for _ in range(n)]
#wv.sort()
dp=[[0]*(w+1) for _ in range(n)]
for i in range(1,w+1):
    if i<wv[0][0]:
        dp[0][i]=0
    else:
        dp[0][i]=wv[0][1]
for i in range(1,n):
    for j in range(1,w+1):
        if wv[i][0]>j:
            dp[i][j]=dp[i-1][j]
        else:
            wleft=j-wv[i][0]
            dp[i][j]=max(wv[i][1]+dp[i-1][wleft],dp[i-1][j])
print(dp[-1][-1])

### FIXED CODE ###

n=int(input())
l=list(map(int,input().split()))
dp=[0 for i in range(n)]
dp[0]=0
dp[1]=abs(l[0]-l[1])
for i in range(2,n):
    dp[i]=min(dp[i-1]+abs(l[i]-l[i-1]),dp[i-2]+abs(l[i]-l[i-2]))
#print(l,dp)
print(dp[-1])
import math
N,K=map(int,input().split())
A=list(map(int,input().split()))
def check(x):
  if x==0:
    return 0
  else:
    t=0
    for i in range(N):
      t+=math.ceil(A[i]/x)-1
    if t<=K:
      return 10
    else:
      return 0
low=0
high=max(A)
sig=(low+high)//2
while True:
  if check(sig)==10:
    if check(sig-1)==0:
      ans=sig
      break
    else:
      high=sig-1
      sig=(low+high)//2
  else:
    low=sig+1
    sig=(high+low)//2
print(ans)


### FIXED CODE ###

X=int(input())
if X>=30:
  print("Yes")
else:
  print("No")
while True:
  try:
    a, b = map(int, input.split(" "))
    print(len(str(a + b)))
     
  expect: break


### FIXED CODE ###

while True:
  try:
    a, b = map(int, input().split(" "))
    print(len(str(a + b)))

  except:
    break
import math
N,D,A=map(int,input().split())
l=[]
for i in range(N):
  k=tuple(map(int,input().split()))
  l.append(k)
l.sort(key=itemgetter(0))
S=[0]*N
ma=[0]*N
tmp=N-1
for i in reversed(range(N)):
  x=l[i][0]
  for j in reversed(range(0,tmp)):
    if abs(l[j][0]-(x-D))>D:
      ma[i]=j+1
      tmp=j+1
      break
  else:
    ma[i]=0
    tmp=0
ans=0
S[0]=math.ceil(l[0][1]/A)
for i in range(1,N):
  h=l[i][1]
  left=S[ma[i]-1] if ma[i]>0 else 0
  right=S[i-1]
  sum_=(right-left)*A
  if h<=sum_:
    S[i]=S[i-1]
    continue
  time=math.ceil((h-sum_)/A)
  S[i]=time+S[i-1]
print(S[N-1])

### FIXED CODE ###

import math
N,D,A=map(int,input().split())
l=[]
for i in range(N):
  k=list(map(int,input().split()))
  l.append(k)
l.sort()
S=[0]*N
ma=[0]*N
tmp=N-1
for i in reversed(range(N)):
  x=l[i][0]
  for j in reversed(range(0,tmp)):
    if abs(l[j][0]-(x-D))>D:
      ma[i]=j+1
      tmp=j+1
      break
  else:
    ma[i]=0
    tmp=0
ans=0
S[0]=math.ceil(l[0][1]/A)
for i in range(1,N):
  h=l[i][1]
  left=S[ma[i]-1] if ma[i]>0 else 0
  right=S[i-1]
  sum_=(right-left)*A
  if h<=sum_:
    S[i]=S[i-1]
    continue
  time=math.ceil((h-sum_)/A)
  S[i]=time+S[i-1]
print(S[N-1])
d, t, s = input().split()
if int(s) * int(t) >= d:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

d, t, s = input().split()
if int(s) * int(t) >= int(d):
    print("Yes")
else:
    print("No")
S = {i: input() for i in "abc"}
n = "a"
while S[n]:
  n = S[n].pop(0)
  
print(n.upper())

### FIXED CODE ###

A = input()
B = input()
C = input()
n = A[0]
A = A[1:]
while True:
  if n == "a":
    if len(A) == 0:
      print("A")
      break
    n = A[0]
    A = A[1:]

  elif n == "b":
    if len(B) == 0:
      print("B") 
      break
    n = B[0]
    B = B[1:]
  else:
    if len(C) == 0:
      print("C")
      break
    n = C[0]
    C = C[1:]
import sys
from collections import defaultdict

n, m = tuple(map(int, sys.stdin.buffer.readline().split()))
L = tuple(tuple(map(int, sys.stdin.buffer.readline().split())) for _ in range(m))

# print(n, m)
# print(L)

X = [n + 1] * (n + 1)
X[1] = 0
Y = [0] * (n + 1)
d = defaultdict(set)
for a, b in L:
    d[a].add(b)
    d[b].add(a)
# print(d)
def search(i):
    for b in d[i]:
        point = X[i] + 1
        # print(f' {X[i]}')
        if point < X[b]:
            # print(i, b, X)
            X[b] = point
            Y[b] = i
            search(b)
    
search(1)
s = X[0]
try:
    X.index(X[0], 1)
except ValueError:
    print('Yes')
    # for v in X[2:]:
    #     print(v)
    for v in Y[2:]:
        print(v)
else:
    print('No')

### FIXED CODE ###

import sys
from collections import defaultdict, deque

n, m = tuple(map(int, sys.stdin.buffer.readline().split()))
L = tuple(tuple(map(int, sys.stdin.buffer.readline().split())) for _ in range(m))

# print(n, m)
# print(L)

X = [n + 1] * (n + 1)
Y = [0] * (n + 1)
d = defaultdict(set)
for a, b in L:
    d[a].add(b)
    d[b].add(a)
# print(d)

X0 = X[0]
X[1] = 0
qu = deque([1])
while qu:
  i = qu.popleft()
  cost = X[i]
  for b in d[i]:
    if X[b] == X0:
      X[b] = cost + 1
      qu.append(b)

# print(X)
s = X[0]
try:
    X.index(X[0], 1)
except ValueError:
    print('Yes')
    # for v in X[2:]:
    #     print(v)
    for i in range(2, n + 1):
      c = X[i]
      for v in d[i]:
        # print(i, c, v, X[v], c - 1== X[v])
        if c - 1 == X[v]:
          Y[i] = v
          break
    for v in Y[2:]:
        print(v)
else:
    print('No')
S = input()
T = input()
count = 0
for i in range(len(S)):
  if S[i] != T[i]:
    count++
print(count)

### FIXED CODE ###

S = input()
T = input()
count = 0
i = 0
for i in range(len(S)):
  if S[i]!= T[i]:
    count += 1
print(count)
N, Y = map(int, input().split())

for x in range(N+1):
    for y in range(N-x+1):
        if 10000*x + 5000*y + 1000*(N-x-y)==Y:
            print(x+""+y+""+(N-x-y))
            exit()
print("-1 "+"-1 "+"-1")

### FIXED CODE ###

N, Y = map(int, input().split())

for x in range(N+1):
    for y in range(N-x+1):
        if 10000*x + 5000*y + 1000*(N-x-y)==Y:
            print("{} {} {}".format(x, y,(N-x-y)))
            exit()
print("-1 "+"-1 "+"-1")
import sys
def input():
    return sys.stdin.readline()[:-1]
n=int(input())
ab=[list(map(int,input().split())) for i in range(n-1)]
ki=[[] for i in range(n+1)]
for i in range(n-1):
    ki[ab[i][0]].append(ab[i][1])
    ki[ab[i][1]].append(ab[i][0])
# print(ki)
kyori=[[0,0] for i in range(n+1)]
def tansaku(m, dis, hito):
    if not ki[m]:
        kyori[m][hito]=dis
        return
    elif kyori[m][hito]!=0:
        return
    else:
        kyori[m][hito]=dis
        for i in range(len(ki[m])):
            tansaku(ki[m][i], dis+1, hito)
tansaku(1,1,0)
tansaku(n,1,1)
fe,su=0,0

for i in range(1,n+1):
    if kyori[i][0]<=kyori[i][1]:
        fe+=1
    else:
        su+=1

if fe>su:
    print("Fennec")
else:
    print("Snuke")

### FIXED CODE ###

import sys
sys.setrecursionlimit(2000000)
def input():
    return sys.stdin.readline()[:-1]
n=int(input())
ab=[list(map(int,input().split())) for i in range(n-1)]
ki=[[] for i in range(n+1)]
for i in range(n-1):
    ki[ab[i][0]].append(ab[i][1])
    ki[ab[i][1]].append(ab[i][0])
# print(ki)
kyori=[[float("INF"), float("INF")] for i in range(n+1)]
def tansaku(m, dis, hito):
    q=[[m,dis]]
    while q:
        po=q.pop()
        for i in ki[po[0]]:
            if kyori[i][hito]>po[1]:
                kyori[i][hito]=po[1]
                q.append([i,po[1]+1])

tansaku(1,1,0)
tansaku(n,1,1)
fe,su=0,0

for i in range(1,n+1):
    if kyori[i][0]<=kyori[i][1]:
        fe+=1
    else:
        su+=1

if fe>su:
    print("Fennec")
else:
    print("Snuke")
n = int(input())
ac = 0
wa = 0
tle = 0
re = 0
for i in range(n):
  k = input().upper()
  if k == 'AC':
    ac +=1
  elif k == 'WA':
    wa +=1
  elif k == 'TLE':
    tle +=1
  elif k == 'RE':
    re +=1
    
print('AC x ' + ac + '\n' + 'WA x ' + wa + '\n' + 'TLE x ' + tle + '\n' + 'RE x ' + re)

### FIXED CODE ###

n = int(input())
ac = 0
wa = 0
tle = 0
re = 0
for i in range(n):
  k = input().upper()
  if k == 'AC':
    ac +=1
  elif k == 'WA':
    wa +=1
  elif k == 'TLE':
    tle +=1
  elif k == 'RE':
    re +=1
    
print('{} x {}'.format('AC',ac))
print('{} x {}'.format('WA',wa))
print('{} x {}'.format('TLE',tle))
print('{} x {}'.format('RE',re))
n, k = map(int, input().split())
a = list(map(int, input().split()))
result = max(a)
left = 1
right = result
med = left + (right - left) // 2
while left <= right:
    counter = sum([(x - 1) // med for x in a])
    if counter <= k:
        result = med
        right = med - 1
    else:
        left = med + 1
    med = left + (right - left) // 2
print(result)

### FIXED CODE ###

n = int(input())
s = input()
number_of_W_in_prefix = [0]
number_of_R_in_suffix = [0]
for i in range(n):
    number_of_W_in_prefix.append(number_of_W_in_prefix[i] + (s[i] == 'W'))
    number_of_R_in_suffix.append(number_of_R_in_suffix[i] + (s[n - i - 1] == 'R'))
result = n
for k in range(n + 1):
    result = min(result, max(number_of_W_in_prefix[k], number_of_R_in_suffix[n - k]))
print(result)
a,b,c = map(int,input().split())

L = [[0] for _ in range(a)] + [[1] for _ in range(b)] + [[2] for _ in range(c)]
while len(L) > 1:
  L[0] += L.pop()
  L.sort()
print(''.join(('a','b','c')[i] for i in L[0]))

### FIXED CODE ###

print(input()[:-8])
N = int(input())
P = list(map(int, input().split()))

ans = 0
# print(P)

for i in range(N):
    if P[i] != int(i + 1):
        continue
    else:
        P[i], P[i + 1] = P[i + 1], P[i]
        # print(i + 1, P)
        ans += 1

print(ans)


### FIXED CODE ###

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

ans = 0
# print(P)

for i in range(N - 1):
    if P[i] != int(i + 1):
        continue
    else:
        P[i], P[i + 1] = P[i + 1], P[i]
        # print(i + 1, P)
        ans += 1


# 最後を見てなかった！！！！
if P[-1] == N:
    ans += 1

print(ans)
s = str(input())
 
if s == "SUN":
  print(7)
elif s == "MON":
  print(6)
elif s == "TUE":
  print(5)
elif s == "WED":
  print(4)
elif s == "THU":
  print(3)
elif s == "FRI":
  print(2)
else s == "SUT":
  print(1)

### FIXED CODE ###

s = str(input())
 
if s == "SUN":
  print(7)
elif s == "MON":
  print(6)
elif s == "TUE":
  print(5)
elif s == "WED":
  print(4)
elif s == "THU":
  print(3)
elif s == "FRI":
  print(2)
else:
  print(1)
a=input()
if int(a[0]) + int(a[1]) >= int(a[2]):
  print("Yes")
else:
  print("No")

### FIXED CODE ###

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

if A+B>=C:
  print("Yes")
else:
  print("No")
from math import hypot

x1, y1, x2, y2 = map(int, input().strip().split())
print(hypot(x2 - x1, y2 - y1))

### FIXED CODE ###

from math import hypot

x1, y1, x2, y2 = map(float, input().strip().split())
print(hypot(x2 - x1, y2 - y1))
s = input()
num = len(s)
l, r = 0, num-1

for i in range(num//2):
    if s[l] == s[r]:
        l += 1
        r -= 1
    else:
        if s[l] == 'x' or s[r] == 'x':
            ans += 1
            l += 1
        else:
            print(-1)
            break
print(ans)
    


### FIXED CODE ###

import sys
s = input()
num = len(s)
l, r = 0, num-1
ans = 0

while l < r:
    if s[l] == s[r]:
        l += 1
        r -= 1
    else:
        ans += 1
        if s[l] == 'x':
            l += 1
        elif s[r] == 'x':
            r -= 1
        else:
            print(-1)
            sys.exit()
print(ans)
N = int(input())
A = list(map(int, input().split()))

ans = []

l1 = A[0::2]
l2 = A[1::2]
if N % 2 == 0:
    l2 = l2[::-1]
    ans = l2+l1
else:
    l1 = l1[::-1]
    ans = l1+l2

print(" ".join(ans))


### FIXED CODE ###

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

ans = []
if N % 2 == 0:
    l1 = A[0::2]
    l2 = A[1::2]
    l2 = l2[::-1]
    ans = l2+l1
else:
    l1 = A[0::2]
    l2 = A[1::2]
    l1 = l1[::-1]
    ans = l1+l2

print(" ".join(list(map(str, ans))))
_ = input()
S = input().lstrip('.').rstrip('#')
n = len(S)

x = 0
y = S.count('.')
c = min(n-y, y)
for i in range(n):
  t = S[i]=='#':
  x += t
  y -= t
  c = min(c, x+y)
print(c)


### FIXED CODE ###

_ = input()
S = input().lstrip('.').rstrip('#')
n = len(S)
A = list(S)

x = 0
y = S.count('.')
ans = min(n-y, y)
for i in range(n):
  if S[i] == '#':
    x += 1
  else:
    y -= 1
  ans = min(ans, x + y)
print(ans)
X,Y=map(int,input().split())
dev = int(Y/X)
work = 1
for i in range(74):
  tmp = pow(2,i)
  if tmp <= dev and dev < tmp*2:
    work +=i
    break
print(work)

### FIXED CODE ###

A,B,C,D=map(int,input().split())
if A+B==C+D:
  print('Balanced')
elif A+B>C+D:
  print('Left')
else:
  print('Right')
from fractions import gcd
import functools
import math

n = int(input())
a = list(map(int,input().split()))
l = []
m = []
l.append(0)
m.append(0)
for i in range(n):
    l.append(math.gcd(l[i],a[i]))
    m.append(math.gcd(m[i],a[-(i+1)]))
b = [math.gcd(l[i],m[-(i+2)]) for i in range(n)]
print(max(b))

### FIXED CODE ###

import fractions
n = int(input())
a = list(map(int,input().split()))
l = []
m = []
l.append(0)
m.append(0)
for i in range(n):
    l.append(fractions.gcd(l[i],a[i]))
    m.append(fractions.gcd(m[i],a[-(i+1)]))
b = [fractions.gcd(l[i],m[-(i+2)]) for i in range(n)]
print(max(b))
a, b, c = map(float, input().split())
if c-a-b>0 and 4ab<(c-a-b)**2
    print("Yes")
else:
    print("No")

### FIXED CODE ###

a,b,c=map(int,input().split())
if c-a-b>0 and (c-a-b)**2>4*a*b:  
    print("Yes")
else:
    print("No")
n, g = map(int, input().split())
List = [list(map(int, input().split())) for i in rage(n)]

ans = 0
a = 0
res = 0

max_score = [(i+1)*100*List[i][0]+List[i][1] for i in range(n-1, -1, -1)] #全て答えたときのスコアを算出
score = [(i+1)*100 for i in range(n-1, -1, -1)] #各レベルの点数を算出しておく

while(ans + max_score[a] <= g):
    ans += max_score[a]
    a += 1

for i in range(a):
    res += List[n - a][0]
    
rest = g - ans
x = -(-rest // score[a])
    
print(res + x)

### FIXED CODE ###

n, g = map(int, input().split())
List = [list(map(int, input().split())) for i in range(n)]

ans = []

max_score = [(i+1)*100*List[i][0]+List[i][1] for i in range(n-1, -1, -1)] #全て答えたときのスコアを算出(逆順)
score = [(i+1)*100 for i in range(n-1, -1, -1)] #各レベルの点数を算出しておく(逆順)
howmany = [List[i][0] for i in range(n-1, -1, -1)] #回数も逆順に出しておく

for i in range(2**n):
    s = 0
    m = 0
    max = 0 #残りの中で最も得点の単位が大きいもの
    for j in range(n):
        if((i >> j) & 1):
            max += 1
            s += max_score[j]
            m += howmany[j]
    if(s >= g):
        ans.append(m)
    else:
        if(max < n):
            rest = g - s
            k = -(-rest // score[max]) #最も得点の単位の高い問題を何問解くか
            if(k < howmany[max]):
                m += k
                ans.append(m)

print(min(ans))
S = [a for a in input()]
N = [int(a) for a in S]
M = [-N[i] for i in range(1,4)]
S.insert(1, '+')
S.insert(3, '+')
S.insert(5, '+')

if sum(N) == 7:
    S = S
    print(''.join(S) + '=7')
    exit()

for i in range(1, 4):
    N[i] = -N[i]

    if sum(N) == 7:
        S[2 * i - 1] = '-'
        print(''.join(S) + '=7')
        exit()

for i in range(1, 4):
    M[i] = -M[i]
    if sum(M) == 7:
        S[2 * i - 1] = '+'
        print(''.join(S) + '=7')
        exit()

if N[0] + N[1] - N[2] - N[3] == 7:
    S[3] = '-'
    S[5] = '-'
elif N[0] - N[1] + N[2] - N[3] == 7:
    S[1] = '-'
    S[5] = '-'
elif N[0] - N[1] - N[2] + N[3] == 7:
    S[1] = '-'
    S[5] = '-'
print(''.join(S) + '=7')

### FIXED CODE ###

S = [a for a in input()]
N = [int(a) for a in S]
M = [N[0]] + [-N[i] for i in range(1,4)]

S.insert(1, '+')
S.insert(3, '+')
S.insert(5, '+')

if sum(N) == 7:
    S = S
    print(''.join(S) + '=7')
    exit()

for i in range(1, 4):
    N[i] = -N[i]
    
    if sum(N) == 7:
        
        S[2 * i - 1] = '-'
        print(''.join(S) + '=7')
        exit()
    else: N[i] = -N[i]

for i in range(1, 4):
    S[1], S[3], S[5] = '-', '-', '-'
    
    M[i] = -M[i]
    
    if sum(M) == 7:
        S[2 * i - 1] = '+'
        print(''.join(S) + '=7')
        exit()
    else:
      M[i] = -M[i]
while(1):
  H,W = map(int, raw_input().split())
  if H==0 and W==0:
    break
  for i in range(H):
    if i == 0 or i == H-1:
      print "#"*w
    else:
      print "#" + "."*(W-2)" + "#"
  print ""

### FIXED CODE ###

while(1):
  H,W = map(int, raw_input().split())
  if H == 0 and W == 0:
    break
  for i in range(H):
    if i == 0 or i == H-1:
      print "#"*W
    else:
      print "#" + "."*(W-2) + "#"
  print ""
n,q = map(int, input().split())
tree = [set() for i in range(n+1)]
for _ in range(n-1):
  a,b = map(int, input().split())
  tree[a].add(b)
  tree[b].add(a)
lazy = [0]*(n+1)
ans = [0]*(n+1)
cnt = 0

for _ in range(q):
  x,v = map(int, input().split())
  lazy[x] += v

def dfs(v,p,tree):
  ans[v] += lazy[v]
  for x in tree[v]:
    if x == p:
      continue
    lazy[x] += lazy[v]
    dfs(x,v,tree)
  lazy[v] = 0
  return

dfs(1,0,tree)

print(" ".join(map(str,ans[1:])))


### FIXED CODE ###

n,q = map(int, input().split())
tree = [set() for i in range(n+1)]
for _ in range(n-1):
  a,b = map(int, input().split())
  tree[a].add(b)
  tree[b].add(a)
lazy = [0]*(n+1)
cnt = 0

for _ in range(q):
  x,v = map(int, input().split())
  lazy[x] += v

que = [(1,0)]
while que:
  v,p = que.pop()
  for x in tree[v]:
    if x == p:
      continue
    lazy[x] += lazy[v]
    que.append((x,v))

print(" ".join(map(str,lazy[1:])))
import  collections 
N = int(input())
list_a = [input() for i in range(N)]
dict_a = collections.Counter(list_a)


list_ans = []

list_ans.append(dict_a.most_common()[0][0])
while True:
    if dict_a.most_common()[0][1] == dict_a.most_common()[i][1]:
        list_ans.append(dict_a.most_common()[i][0])
    else:
            break

list_ans.sort()
for i in range (0,len(list_ans)):
    print(list_ans[i])

### FIXED CODE ###

N = int(input())
S = [input() for i in range(N)]
dictionary = {}
for word in S:
    if word in dictionary:
        dictionary[word] += 1
    else:
        dictionary[word] = 1

maximum = max(dictionary.values())
for key, value in sorted(dictionary.items()):
    if value == maximum:
        print(key)
S, W = map(int,input().split())
if S>W:
  print("safe")
else S<=W:
  print("unsafe")

### FIXED CODE ###

S, W = map(int,input().split())
print("safe"if S>W else"unsafe")
from collections import deque
N,K=map(int,input().split())
A=list(map(int,input().split()))
A.sort(reverse=True)
d=deque(A)


l=[]
if K%2==0 or (K%2==1 and A[0]>0):
  for i in range(K//2):
    if d[0]*d[1]>=d[-1]*d[-2] and d[2]>0:
      l.append(d.popleft())
      l.append(d.popleft())
    else:
      l.append(d.pop())
      l.append(d.pop())
  if K%2==1:
    l.append(d[0])
else:
  for i in range(K):
    l.append(d.popleft())
      
ans=1
for i in l:
  ans*=i
print(ans%(10**9+7))

### FIXED CODE ###

from collections import deque
N,K=map(int,input().split())
A=list(map(int,input().split()))
A.sort(reverse=True)
d=deque(A)
import time
l=[]
if K%2==0 or (K%2==1 and A[0]>=0):
  for i in range(K//2):
    if d[0]*d[1]>d[-1]*d[-2] and (i==K//2-1 or (len(d)>2 and  d[2]>0)):
      l.append(d.popleft())
      l.append(d.popleft())
    else:
      l.append(d.pop())
      l.append(d.pop())
  if K%2==1:
    l.append(d[0])
else:
  for i in range(K):
    l.append(d.popleft())
      
ans=1
for i in l:
  ans*=i
  ans%=10**9+7
print(ans)