Harryxun/stf_run huggingface dataset:
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

from collections import deque
from collections import Counter
import bisect
def main():
    N = I()
    A = LI()
    B = LI()
    A_cnt = Counter(A)
    B_cnt = Counter(B)
    for key in B_cnt.keys():
        x = A_cnt[key]
        if B_cnt[key] > N - x:
            print('No')
            exit()
    A_m = A_cnt.most_common()
    A_ = []
    C = deque()
    for a_m in A_m:
        a = a_m[0]
        A_ += [a] * a_m[1]
        if B_cnt[a] != 0:
            C.appendleft(a)
    ANS = []
    for i in range(N):
        x = C[0]
        if A_[i] != x:
            ANS.append((A_[i], x))
            B_cnt[x] -= 1
            if B_cnt[x] == 0:
                C.popleft()
        elif A_[i] == x:
            C.popleft()
            C.append(x)
            y = C[0]
            ANS.append((x, y))
            B_cnt[y] -= 1
            if B_cnt[y] == 0:
                C.popleft()

    ANS.sort(key=lambda tup: tup[0])
    ANS_ = []
    for ans in ANS:
        ANS_.append(ans[1])

    print('Yes')
    print(' '.join(map(str, ANS_)))

if __name__ == "__main__":
    main()


### FIXED CODE ###

import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

from collections import deque
from collections import Counter
import bisect
def main():
    N = I()
    A = LI()
    B = LI()
    A_cnt = Counter(A)
    B_cnt = Counter(B)
    for key in B_cnt.keys():
        x = A_cnt[key]
        if B_cnt[key] > N - x:
            print('No')
            exit()
    print('Yes')
    A_m = A_cnt.most_common()
    A_ = []
    for a_m in A_m:
        A_ += [a_m[0]] * a_m[1]
    B_m = deque(B_cnt.most_common())
    ANS = []
    for i in range(N):
        x = B_m[0][0]
        if A_[i] != x:
            ANS.append([A_[i], x])
            B_cnt[x] -= 1
            if B_cnt[x] == 0:
                B_m.popleft()
        elif A_[i] == x:
            if len(B_m) != 1:
                B_m.popleft()
                B_m.append((x, B_cnt[x]))
                y = B_m[0][0]
                ANS.append([x, y])
                B_cnt[y] -= 1
                if B_cnt[y] == 0:
                    B_m.popleft()
            else:
                for ans in ANS:
                    if ans[0] != x and ans[1] != x:
                        ANS.append([x, ans[1]])
                        ans[1] = x
                        break

    ANS.sort(key=lambda tup: tup[0])
    ANS_ = []
    for ans in ANS:
        ANS_.append(ans[1])
    print(' '.join(map(str, ANS_)))

if __name__ == "__main__":
    main()
l = raw_input().split()
N = int(l[0])
M = int(l[1])

BC = []

l = raw_input().split()
A = [int(x) for x in l]

for i in range(M):
    l = raw_input().split()
    bc = [int(l[0]), int(l[1])]
    BC.append(bc)

A.sort()
BC.sort(key = lambda x: -x[1])
# print(N, M, A, BC)

i0 = 0
i1 = 0
for i in range(N):
    # print(BC[i0])
    b = BC[i0][0]
    c = BC[i0][1]

    if A[i] < c:
        A[i] = c
        i1 += 1
    if i1 == b:
        i0 += 1
        i1 = 0
    # print(A)

# print(A)
print(sum(A))


### FIXED CODE ###

l = raw_input().split()
N = int(l[0])
M = int(l[1])

BC = []

l = raw_input().split()
A = [int(x) for x in l]

for i in range(M):
    l = raw_input().split()
    bc = [int(l[0]), int(l[1])]
    BC.append(bc)

A.sort()
BC.sort(key = lambda x: -x[1])
# print(N, M, A, BC)

i0 = 0
i1 = 0
for i in range(N):
    # print(BC[i0])
    b = BC[i0][0]
    c = BC[i0][1]

    if A[i] < c:
        A[i] = c
        i1 += 1
    if i1 == b:
        i0 += 1
        i1 = 0
    # print(A)
    if i0 == M:
        break

# print(A)
print(sum(A))
s = input()
z = []

for i in s:
  if i=="B":
    z.pop()
  else:
    z.append(i)

print("".join(z))

### FIXED CODE ###

a = input()
b = []

for s in a:
  if s=="0" or s=="1":
    b.append(s)
  elif s=="B" and len(b)!=0:
    b.pop()
else:
  print("".join(b))
# -*- coding: utf-8 -*-
import sys
from collections import deque

N,M=map(int, sys.stdin.readline().split())
al=[ [] for _ in range(N+1) ]   #隣接リスト
rev_al=[ [] for _ in range(N+1) ]   #戻りを調べる用の隣接リスト
edge=[] #辺の集合
for _ in range(M):
    a,b,c=map(int, sys.stdin.readline().split())
    al[a].append(b)
    rev_al[b].append(a) #逆向きにも辺を張る
    edge.append((a,b,c))


go=[0 for _ in range(N+1)]
back=[0 for _ in range(N+1)]

#頂点１からNに行くまでに使用する頂点を調べる
q=deque()
q.append(1) #スタート地点
go[1]=1

while q:
    fro=q.popleft()
    for to in al[fro]:
        if go[to]==0:
            go[to]=1
            q.append(to)


#頂点Nから1に戻る際に使用する頂点を調べる
q=deque()
q.append(N) #スタート地点
back[N]=1

while q:
    fro=q.popleft()
    for to in rev_al[fro]:
        if back[to]==0:
            back[to]=1
            q.append(to)


new_edge=[]     #有効な辺のみ抽出

for a,b,c in edge:
    if go[a]==1 and back[b]==1:
        new_edge.append((a,b,c))


#ベルマンフォード
dp=[ float("-inf") for _ in range(N+1) ]
dp[1]=0

for i in range(N):
    for fro,to,cost in new_edge:
        alt=dp[fro]+cost
        if dp[to]<alt:
            if i==N-1:
                print float("inf")
                quit()
            dp[to]=alt

print dp[N]

### FIXED CODE ###

A,B,C=map(int,raw_input().split())
print "Yes" if A<=C and C<=B else "No"
import math
n = input()
print(math.ceil(n/2))

### FIXED CODE ###

import math
n = int(input())
print(math.ceil(n/2))
#!/usr/bin/env python

N,M=map(int,input().split())
path=[]
all_list=[]
count=0

for i in range(M):
    path.append(map(int,raw_input().split()))

NN=N*(N-1)/2
all_list=map(list,permutations(range(NN),2))
for i in all_list[i]:
    for j in path[j]:
        if all_list[i]==path[j]:
            count=count+1

print count

### FIXED CODE ###

#!/usr/bin/env python

numbers = raw_input().split()

A = int(numbers[0])
B = int(numbers[1])

if A == B :
   print "Draw"
elif A == 1:
   print "Alice"
elif B == 1:
   print "Bob"
elif A > B:
   print "Alice"
elif B > A:
   print "Bob"
import Numpy as np


### FIXED CODE ###

from statistics import pstdev
while input()!="0":
    lst=map(int,input().split())
    print(pstdev(lst))
N = int(input())
cities = [int(input()) for i in range(N)]

min_city = min(cities)
if N < min_city:
  print(5)
else:
  times = N//min_city
  print(5+times)

### FIXED CODE ###

N = int(input())
cities = [int(input()) for i in range(5)]

min_city = min(cities)
if N <= min_city:
  print(5)
else:
  times = N//min_city
  if N%min_city == 0:
    print(5+times-1)
  else:
    print(5+times)
k = int(input())
power = 0
cnt = 1
if k == 1:
  print(1)
elif k%2 == 0 or k%5 == 0:
  print(-1)
elif k%7 == 0:
  l = k/7
  a = 1
  while(true):
    a = (10*a)%l
    if a == 1:
      break
    cnt+= 1
  print(cnt)
else:
  a = 1
  l = 9*k
  while(True):
    a = (10*a)%l
    if a == 1:
      break
    cnt+=1
  print(cnt)

### FIXED CODE ###

k = int(input())
power = 0
cnt = 1
if k == 1 or k == 7:
  print(1)
elif k%2 == 0 or k%5 == 0:
  print(-1)
elif k%7 == 0:
  l = 9*k/7
  a = 1
  while(True):
    a = (10*a)%l
    if a == 1:
      break
    cnt+= 1
  print(cnt)
else:
  a = 1
  l = 9*k
  while(True):
    a = (10*a)%l
    if a == 1:
      break
    cnt+=1
  print(cnt)
n = int(input())
xy = []
renso = {}

for i in range(n):
    xin,yin = map(int,input().split())
    xy.append((xin,yin))

xy.sort()

for i in range(n):
    for j in range(i,n):
        if( i==j ):
            continue
        dx = xy[i][0]-xy[j][0]
        dy = xy[i][1]-xy[j][1]
        if renso.get((dx,dy))==None:
            renso[(dx,dy)]=1
        else:
            renso[(dx,dy)]=renso[(dx,dy)]+1

print(n-max(renso.values()))

### FIXED CODE ###

n = int(input())
xy = []
ans = []

for i in range(n):
    xin,yin = map(int,input().split())
    xy.append([xin,yin])

if n==1:
    print(1)
    exit(0)

xy.sort(key=lambda x:x[1])
xy.sort(key=lambda x:x[0])

for i in range(n):
    for j in range(n):
        if( i==j ):
            continue
        t = (xy[i][0]-xy[j][0],xy[i][1]-xy[j][1])
        ans.append(t)

res = [ans.count(e) for e in set(ans)]
print(n-max(res))
import numpy as np
n = int(input())
A = np.array([int(input()) for i in range(n)])
idxs = np.argsort(A)
m1 = A[idxs[-1]]
m2 = A[idxs[-2]]
if m1 == m2:
  for i in range(n):
    print(m1)
else:
  for i in range(n):
    if i != idx[-1]:
      print(m1)
    else:
   	  print(m2)

### FIXED CODE ###

import numpy as np
n = int(input())
A = np.array([int(input()) for i in range(n)])
idxs = np.argsort(A)
m1 = A[idxs[-1]]
m2 = A[idxs[-2]]
for i in range(n):
  if i != idxs[-1]:
    print(m1)
  else:
    print(m2)
import collections

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

c = collections.Counter(s)
max_num = list(c.values())[0]
d = []
for key,value in c.items():
  if value == max_num:
    d.append(key)
  else:
    break
    
for i in sorted(d):
  print(i)
  



### FIXED CODE ###

import collections

N = int(input())
s = [input() for i in range(N)]

c = collections.Counter(s)
max_num = max(c.values())
d = []
for key,value in c.items():
  if value == max_num:
    d.append(key)

for i in sorted(d):
  print(i)
N = int(input())
lis = list(map(int, input().split()))
H_lis = []
H = lis[0]
cnt = 0

for i in lis[1:]:
    if i <= H:
       cnt += 1
       H = i
       H_lis.append(cnt)
    else:
        H_lis.append(cnt)
        cnt = 0
        H = i

print(max(H_lis))

### FIXED CODE ###

N = int(input())
lis = list(map(int, input().split()))
H_lis = []
H = lis[0]
cnt = 0

if N == 1:
    print(0)
    exit()

for i in lis[1:]:
    if i <= H:
       cnt += 1
       H = i
       H_lis.append(cnt)
    else:
        H_lis.append(cnt)
        cnt = 0
        H = i

print(max(H_lis))
from sys import stdin

N = int(stdin.readline().rstrip())
A =  stdin.readline().rstrip()
B =  stdin.readline().rstrip()
C =  stdin.readline().rstrip()

str_len = len(A)

count = 0


for i in range(str_len):
    if A[i]==B[i]:
        if C[i]==B[i]:
            continue
        else:
            count = count + 1
    elif A[i]==C[i]:
        count = count + 1
    elif B[i]==C[i]:
        count = count + 1
    else:
        count = count + 2
print(str(count))

### FIXED CODE ###

from sys import stdin

A, B, C = [int(x) for x in stdin.readline().rstrip().split()]




if B+C <= A:
    print(str(min(B,C)) + ' ' + str(0))
else:
    print(str(min(B,C)) + ' ' +str(B+C-A))
#また長さが1の時を考慮していない
#出来るだけループの外で計算する
n=int(input())
a=[int(input()) for i in range(n)]
m1=max(a)
m2=sorted(a,reverse=True)[1]
for i in range(n):
    if m==a[i]:
        print(m2)
    else:
        print(m1)


### FIXED CODE ###

#また長さが1の時を考慮していない
#出来るだけループの外で計算する
n=int(input())
a=[int(input()) for i in range(n)]
m1=max(a)
m2=sorted(a,reverse=True)[1]
for i in range(n):
    if m1==a[i]:
        print(m2)
    else:
        print(m1)
#n=int(input())
#A=[]
#X=[]
#Y=[]
#for i in range(n):
 # a=int(input())
 # A.append(a)
 # x=[]
 # y=[]
  #for j in range(a):
   # x1,y1=[int(s) for s in input().split()]
   # x.append(x1)
    #y.append(y1)
  #X.append(x)
  #Y.append(y)
  
c=0
#for i in range(n):
 # l=[1]*n
  #for j in range(i, n-i):
   # if l[j]==0:continue
    #for k in range(A[j]):
    　#　l[X[j][k]] *= Y[j][k]
  #if c<l.count(1):
   # c=l.count(1) 
  
        
  
print(c)  
  
  
  
  
  
  
  
  
  
  
  
  
  

### FIXED CODE ###

n=int(input())
X=[]
Y=[]
A=[0]*n
for i in range(n):
  A[i]=int(input())
  a=A[i]
  x=[0]*a
  y=[0]*a
  for j in range(a):
    x[j],y[j]=[int(s) for s in input().split()]
  X.append(x)
  Y.append(y)
  
s=0
for i in range(2**n):
  c=0
  d=0
  B=[0]*n
  for j in range(n):
    if((i >> j) & 1):
      c=c+1
      B[j]=1
  for k in range(n):
    if B[k]==1:
      for j in range(A[k]):
        if Y[k][j]!=B[X[k][j]-1]:
          d=-1
          break
    if d<0:
      break
  if s<c and d==0:
    s=c
      
      
print(s)
N=int(input())
book=[]
for i in range(N):
    s,p =input().split()
    book.append((s,int(p),i))
    
s=sorted(book, key=lambda x: ( x[0],-x[1]))
for i in range(N):
    print(s[i][2]+1)


### FIXED CODE ###

A,P = map(int, input().split())
print((3*A+P)//2)
def A(x):
  return x + x**2 + x**3


def B(s, t):
  ans = 0
  for i in range(len(s)):
    if s[i] != t[i]:
      ans += 1
  return ans


def C(n, m, k, a, b):
  ans = 0
  while k > 0:
    if a and b:
      if a[0] < b[0]:
        k -= a[0]
        a.pop()
      else:
        k -= b[0]
        b.pop()
    elif a:
      k -= a[0]
      a.pop()
    elif b:
      k -= b[0]
      b.pop()
    else:
      break
    if k >= 0:
      ans += 1
  return ans


def C2(n, m, k, a, b):

  def _dfs(pa, pb, acc_b, acc_t, k):
    go_a = _dfs(pa + 1, pb, acc_b + 1, acc_t + a[pa + 1], k)
    go_b = _dfs(pa, pb + 1, acc_b, acc_t, k)
    return go_a if go_a > go_b else go_b

  return _dfs(pa=0, pb=-1, acc_b=0, acc_t=0, k=k)


def C3(n, m, k, a, b):

  kl = [k]
  def _get_pa_init():
    pa = 0
    while pa < len(a):
      if kl[0] > a[pa]:
        kl[0] -= a[pa]
        pa += 1
      else:
        break
    return pa - 1

  pa = _get_pa_init()
  pb = -1

  k = kl[0]
  max_read = pa + pb + 2
  while True:
    while pb + 1 < len(b) and k >= b[pb + 1]:
      k -= b[pb + 1]
      pb += 1
    if pa <= -1 and k < b[pb + 1]:
      break
    # print(k, pa, pb, pa + pb + 2)
    if pa + pb + 2 > max_read:
      max_read = pa + pb + 2
    if pa > -1:
      pa -= 1
      k += a[pa + 1]
    # print(k, pa, pb, pa + pb + 2)
    if pa + pb + 2 > max_read:
      max_read = pa + pb + 2
    if pb >= len(b) - 1:
      break
  return max_read


def main():
  n, m, k = map(int, input().split())
  a = list(map(int, input().split()))
  b = list(map(int, input().split()))
  print(C3(n, m, k, a, b))


if __name__ == '__main__':
  main()


### FIXED CODE ###

def A(x):
  return x + x**2 + x**3


def B(s, t):
  ans = 0
  for i in range(len(s)):
    if s[i] != t[i]:
      ans += 1
  return ans


def C(n, m, k, a, b):

  def _get_acc(x):
    acc = [0]
    for idx in range(len(x)):
      acc.append(x[idx] + acc[idx])
    return acc

  acc_a = _get_acc(a)
  acc_b = _get_acc(b)

  pa = 0
  pb = 0

  while pa <= n and acc_a[pa] <= k:
    pa += 1
  pa -= 1

  max_num = 0
  while True:
    if pa < 0 or pb > m:
      break
    if acc_a[pa] + acc_b[pb] <= k:
      if max_num < pa + pb:
        max_num = pa + pb
      pb += 1
    else:
      pa -= 1

  return max_num


def main():
  n, m, k = map(int, input().split())
  a = list(map(int, input().split()))
  b = list(map(int, input().split()))
  print(C(n, m, k, a, b))


if __name__ == '__main__':
  main()
x,y = [ int(i) for i in input().split()]

if: ((x * y ) % 2) == 0
  print('Even')
  
else: 
  print('Odd')

### FIXED CODE ###

x,y = map(int,input().split())

result = x * y

if (result % 2) == 0 :
    print('Even')
else:
    print('Odd')
n = int(input())
lst = [[-1 for _ in range(n)] for _ in range(n)]
for _ in range(n):
    c = int(input())
    for c1 in range(c):
        x, y = map(int, input().split())
        x -= 1
        lst[_][x] = y

ans = 0
for bit in range(n**2 - 1):
    flg = True
    for a in range(n):
        if (bit >> a) & 1:
            for x in range(n):
                if lst[a][x] != -1 and ((bit >> x) & 1) != lst[a][x]:
                    flg = False
                    break
if flg:
  ans = max(ans, bin(bit).count('1'))
print(ans)
    

### FIXED CODE ###

a, b, c = map(int, input().split())
if a+b+c >= 22:
    print('bust')
else:
    print('win')
a = [input(),input(),input()]
def checkEqual(l,r,k):
    i = len(l)-k
    j = 0
    for a in range(k):
        x, y = i+a, j+a
        if l[x] != r[y]:
            if l[x]=='?' or r[y]=='?':
                continue
            return False
    return True

overLaps = [[[] for i in range(3)] for j in range(3)]
ij = [(0,1),(1,0),(1,2),(2,1),(0,2),(2,0)]
for i,j in ij:
    l = a[i]
    r = a[j]
    m = min(len(l),len(r))
    for k in range(m+1):
        if checkEqual(l,r,k):
            overLaps[i][j].append(k)

maxRe = 0
combs = [(0,1,2),(0,2,1),(1,0,2),(1,2,0),(2,0,1),(2,1,0)]
for x,y,z in combs:
    full = len(a[y])
    o1 = overLaps[x][y]
    o2 = overLaps[y][z]
    midOl = set(overLaps[x][z])
    for i in range(len(o1)-1,-1,-1):
        for j in range(len(o2)-1,-1,-1):
            re = o1[i] + o2[j]
            if re > full:
                if re-full not in midOl:
                    continue
            maxRe = max(re,maxRe)
    # i = len(o1)-1
    # j = len(o2)-1
    # if o1[i] + o2[j] <= full:
    #     re = o1[i] + o2[j]
    #     maxRe = max(re,maxRe)
    #     continue
    #
    # bar = full - o1[i]
    # while o2[j] > bar:
    #     j -= 1
    #     if j == 0:
    #         break
    # while j < len(o2):
    #     bar = full - o2[j]
    #     while o1[i] > bar:
    #         i -= 1
    #         if i<0:
    #             break
    #     if i<0:
    #         break
    #     re = o1[i] + o2[j]
    #     maxRe = max(re,maxRe)
    #     j += 1

ans = len(a[0])+len(a[1])+len(a[2])-maxRe
print(ans)

### FIXED CODE ###

A =  [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = int(input())
print(A[k-1])
digits = input('')
count = 0
if digits[0] == 1:
  count++
if digits[1] == 1:
  count++
if digits[2] == 1:
  count++
print count

### FIXED CODE ###

digits = list(input(''))
count = 0
if digits[0] == '1':
  count += 1
if digits[1] == '1':
  count += 1
if digits[2] == '1':
  count += 1
print(count)
# coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
read = sys.stdin.read

#n,*w = [int(i) for i in read().split()]
#n,*t = map(int,read().split())

#n = int(input())
#s = input()
h,n = [int(i) for i in readline().split()]

 
def div(m,a,b,dp): #divide by (1+bx^a) up to x^m
    for i in range(m-a+1):
        dp[i+a] = min(dp[i+a], dp[i]+b)
    for i in range(m-a+1,m):
        dp[-1] = min(dp[-1],dp[i]+b)
        #dp[i+c] += dp[i]


INF = 10**9+7
dp =[INF]*(h+1)
dp[0] = 0

for _ in range(n):
    a,b = [int(i) for i in readline().split()]
    div(h,a,b,dp)
    #print(a,b,dp)
 


print(dp[-1])


### FIXED CODE ###

# coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
read = sys.stdin.read

#n,*w = [int(i) for i in read().split()]
#n,*t = map(int,read().split())

#n = int(input())
#s = input()
h,n = [int(i) for i in readline().split()]

 
def div(m,a,b,dp): #divide by (1+bx^a) up to x^m
    for i in range(m-a+1):
        dp[i+a] = min(dp[i+a], dp[i]+b)
    for i in range(max(m-a+1,0),m):
        dp[-1] = min(dp[-1],dp[i]+b)
        #dp[i+c] += dp[i]


INF = 10**9+7
dp =[INF]*(h+1)
dp[0] = 0

for _ in range(n):
    a,b = [int(i) for i in readline().split()]
    div(h,a,b,dp)
    #print(a,b,dp)
 


print(dp[-1])
import bisect
h, w, k = map(int, input().split())
ls = [list(input()) for _ in range(h)]

idxls = [0]*k
a = 0
rawls = set([-1, h])
for i in range(h):
    for j in range(w):
        if ls[i][j] == '#':
            idxls[a] = [i, j]
            rawls.add(i)
            a += 1

ansls = [[0 for _ in range(w)] for _ in range(h)]

rawls = list(rawls)
rawls.sort()
diffls= [0]*(len(rawls)-1)
for i in range(len(rawls)-1):
    diffls[i] = rawls[i+1] - rawls[i]

#paint raw
a = 0
for i in rawls[1:-1]:
    for j in range(w):
        if ls[i][j] == '#':
            a += 1
        for k in range(diffls[i+1]):
            ansls[i+k][j] = max(a,1)

a = 0
i = rawls[1]
for j in range(w):
    if ls[i][j] == '#':
        a += 1
    for k in range(diffls[0]):
        ansls[i-k][j] = max(a,1)

for l in ansls:
    print(*l)

    







### FIXED CODE ###

h,w,k = map(int, input().split())
ls = [list(input()) for i in range(h)]
ansls = [[0]*w for _ in range(h)]
absent = []
idx = 1
for i in range(h):
    if ls[i] == ['.']*w:
        absent.append(i)
    else:
        count=0
        for j in range(w):
            if ls[i][j] == "#":
                if count>0:
                    idx+=1
                count+=1
            ansls[i][j] = idx
        idx+=1

for i in absent:
    idx = i
    while idx in absent:
        idx+=1
    if idx>=h:
        idx = i
        while idx in absent:
            idx-=1
    ansls[i] = ansls[idx]

for l in ansls:
    print(*l)
N=int(input())
sum=0
seats=[False for i in range(100000)]
for i in range(N):
  l,r=map(int,input.split())
  for j in range(l-1,r-1):
    seats[j]=True
print(sum(seats))

### FIXED CODE ###

N=int(input())
sl=[]
for i in range(N):
  sl.append(list(map(int,input().split())))
sl.sort()
sl_table = [True for i in range(len(sl))]

for i in range(N):
  for j in range(min(i+1,N),N):
    if sl[j][0]-sl[i][1]>0:
      break
    sl[i]=[min(min(sl[i]),min(sl[j])),max(max(sl[i]),max(sl[j]))]
    sl_table[j]=False

print(sum((s[1]-s[0]+1)*sl_table[i] for i,s in enumerate(sl)))
op = ["+", "-", "*"]
while True:
    a, b, c, d = map(str, raw_input().split())
    if a == 0 and c == 0:
        break
    n = [0,1,2,3]
    q = [str(a),str(b),str(c),str(d)]
    flag = 0
    for i in op:
        for j in op:
            for k in op:
                for ii in n:
                    m = [0,1,2,3]
                    m.remove(ii)
                    for jj in m:
                        l = [0,1,2,3]
                        l.remove(ii);l.remove(jj)
                        for kk in l:
                            o = [0,1,2,3]
                            o.remove(ii);o.remove(jj);o.remove(kk)
                            for ll in o:
                                if eval( "((("+q[ii]+k+q[jj]+")"+j+q[kk]+")"+i+q[ll]+")") == 10:
                                    print "(((",q[ii],k,q[jj],")",j,q[kk],")",i,q[ll],")"
                                    flag = 1
                                    break
                                if eval( "(("+q[ii]+k+q[jj]+")"+i+"("+q[kk]+j+q[ll]+"))" ) == 10:
                                    print "((",q[ii],k,q[jj],")",i,"(",q[kk],j,q[ll],"))"
                                    flag = 1
                                    break
                            if flag == 1:
                                break
                        if flag == 1:
                            break
                    if flag == 1:
                        break
                if flag == 1:
                    break
            if flag == 1:
                break
        if flag == 1:
            break
    if flag != 0:
        print 0

### FIXED CODE ###

op = ["+", "-", "*"]
while True:
    a, b, c, d = map(str, raw_input().split())
    if a == "0" and c == "0":
        break
    n = [0,1,2,3]
    q = [a,b,c,d]
    flag = 0
    for ii in n:
        m = [0,1,2,3]
        m.remove(ii)
        for jj in m:
            l = [0,1,2,3]
            l.remove(ii);l.remove(jj)
            for kk in l:
                o = [0,1,2,3]
                o.remove(ii);o.remove(jj);o.remove(kk)
                for ll in o:
                    for i in op:
                        for j in op:
                            for k in op:
                                if eval( "((("+q[ii]+k+q[jj]+")"+j+q[kk]+")"+i+q[ll]+")") == 10:
                                    print "(((",q[ii],k,q[jj],")",j,q[kk],")",i,q[ll],")"
                                    flag = 1
                                    break
                                if eval( "(("+q[ii]+k+q[jj]+")"+i+"("+q[kk]+j+q[ll]+"))" ) == 10:
                                    print "((",q[ii],k,q[jj],")",i,"(",q[kk],j,q[ll],"))"
                                    flag = 1
                                    break
                            if flag == 1:
                                break
                        if flag == 1:
                            break
                    if flag == 1:
                        break
                if flag == 1:
                    break
            if flag == 1:
                break
        if flag == 1:
            break
    if flag == 0:
        print 0