Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

S = input()
Q = int(input())
query_list = []
for i in range(Q):
    query_list.append(input())
# print(S, Q, query_list)

result = list(S)
reverse_flag = False

for i in range(Q):
    # print(i + 1)
    q = query_list[i]
    # print(q)
    t = int(q[0])
    if t == 1:
        reverse_flag = not reverse_flag
    else:
        t, f, c = q.split()
        f = int(f)
        c = list(c)
        if f == 1:
            if reverse_flag:
                result = result + c
            else:
                result = c + result
        else:
            if reverse_flag:
                result = c + result
            else:
                result = result + c
    # print(t, f, c, result)
    # print("--------")
if reverse_flag:
    result = result[::-1]
#result = str(result)
result = "".join(result)
print(result)

### FIXED CODE ###

S = input()
Q = int(input())
query_list = []
for i in range(Q):
    query_list.append(input())
# print(S, Q, query_list)

M = 10 ** 6
start_position = int(M / 2)
left_position = start_position
right_position = start_position + len(S)
result = ["-"] * M
for i in range(len(S)):
    # print(i + left_position)
    result[i + left_position] = S[i]

# result = "".join(result[left_position:right_position])
# print(result)
# exit(0)
reverse_flag = False

for i in range(Q):
    # print(i + 1)
    # print(result[left_position:right_position])
    q = query_list[i]
    # print(q)
    t = int(q[0])
    if t == 1:
        reverse_flag = not reverse_flag
    else:
        t, f, c = q.split()
        f = int(f)
        c = c
        if f == 1:
            if reverse_flag:
                result[right_position] = c
                right_position += 1
            else:
                result[left_position - 1] = c
                left_position -= 1
        else:
            if reverse_flag:
                result[left_position - 1] = c
                left_position -= 1
            else:
                result[right_position] = c
                right_position += 1
    # print(t, f, c, result)
    # print("--------")
    #print(result[left_position:right_position])
# result = str(result)
# result = "".join(result)
# print(result)
# print(result[left_position:right_position])

result = "".join(result[left_position:right_position])
if reverse_flag:
    result = result[::-1]
print(result)
### BUGGY CODE ###

import itertools

N = int(input())

def g(x, y, z):
    g_xyz = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x
    return g_xyz

list_ans = []

for target in range(1, N + 1):
    # print(f"\n---- target = {target} ----")
    N2 = int(target ** (1 /2) / 2) + 1
    b = 0
    for x in range(1, N2 + 1):
        for y in range(x, N2 + 1):
            for z in range(y, N2 + 1):
            #   print("x, y, z, g(x, y, z) =", x, y, z, g(x, y, z))
              if g(x, y, z) == target:
                #   print("  -> OK!")
                  tmp = ["".join(map(str, v)) for v in itertools.permutations([x, y, z])]
                  a = set(tmp)
                  b = len(a)
    list_ans.append(b)

for i in list_ans:
    print(i)

### FIXED CODE ###

def g(x, y, z):
    g_xyz = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x
    return g_xyz


N = int(input())
ans_list = [0 for _ in range(60000)]
for x in range(1, 100):
  for y in range(1, 100):
      for z in range(1, 100):
          ans_list[g(x=x, y=y, z=z) - 1] += 1
           
for i in range(N):
    print(ans_list[i])
### BUGGY CODE ###

if __name__ == "__main__":
    from itertools import permutations
    N, M, R = map(int, input().split())
    rs = map(lambda x: int(x) - 1, input().split())
    dist, ans = [[10**9 for _ in range(N)] for _ in range(N)], 10**9
    for _ in range(M):
        v1, v2, d = map(int, input().split())
        dist[v1-1][v2-1] = dist[v2-1][v1-1] = d
    for i in range(N):
        dist[i][i] = 0
    for k in range(N):
        for i in range(N):
            for j in range(N):
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
    for r in permutations(rs):
        t = 0
        for i in range(R-1):
            t += dist[r[i]][r[i+1]]
        ans = min(t, ans)
    print(ans)

### FIXED CODE ###

from itertools import permutations
N, M, R = map(int, input().split())
rs = map(lambda x: int(x) - 1, input().split())
dist = [[10**9 for _ in range(N)] for _ in range(N)]
for _ in range(M):
    v1, v2, d = map(int, input().split())
    dist[v1-1][v2-1] = dist[v2-1][v1-1] = d
for i in range(N):
    dist[i][i] = 0
for k in range(N):
    for i in range(N):
        for j in range(N):
            dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
ans = 10**9
for r in permutations(rs):
    t = 0
    for i in range(R-1):
        t += dist[r[i]][r[i+1]]
        if t > 10**9:
            break
    ans = min(t, ans)
print(ans)
### BUGGY CODE ###

N, Q = map(int, input().split())
S = input()

ac_place = [False] * N
for i in range(N - 1):
    if(S[i] == 'A' and S[i + 1] == 'C'):
        ac_place[i] = True

for i in range(Q):
    l, r = map(int, input().split())
    s = ac_place[l - 1: r - 1] 
    print(sum(s))

### FIXED CODE ###

N, Q = map(int, input().split())
S = input()

ac = [0] * (N + 1)
for i in range(N - 1):
    ac[i + 1] = ac[i] + (1 if S[i] == 'A' and S[i + 1] == 'C' else 0)
for i in range(Q):
    l, r = map(int, input().split())
    print(ac[r-1] - ac[l-1])
### BUGGY CODE ###

X = int(input())
l = []
for i in range(1, int(X ** 0.5) + 1):
  j = 2
  while i ** j <= X:
    j += 1
  l.append(i ** j)
l.sort()
print(l[-1])


### FIXED CODE ###

X = int(input())
l = []
if X < 4:
  print(1)
else:
  for i in range(2, int(X ** 0.5) + 1):
    j = 2
    while i ** j <= X:
      l.append(i ** j)
      j += 1
  l.sort()
  print(l[-1])
### BUGGY CODE ###

n, a, b = map(int, input().split())
ans = 0
count = 0
while(count < n):
  if count%(a+b) < a:
    ans+=1
  count+=1
print(ans)

### FIXED CODE ###

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

if n%(a+b) == 0:
  print(n//(a+b)*a)
else:
  tmp = n%(a+b)
  if tmp >= a:
    print(n//(a+b)*a + a)
  elif tmp < a:
    print(n//(a+b)*a + tmp)
  else:
    print(n//(a+b)*a)
### BUGGY CODE ###

import collections
n = int(input())
l = [input() for i in range(n)]
ans = []


c = collections.Counter(l)

ans = [j[0] for j in c.items() if j[1] == max(c.values())]

ans.sort()

print('\n'.join(map(str, ans)))

### FIXED CODE ###

n = int(input())

d = {}

for i in range(n):
    a = input()
    if a in d:
        d[a] += 1
    else:
        d[a] = 1

m = max(d.values())
d = sorted(d.items())

for j in d:
    if j[1] == m:
        print(j[0])
### BUGGY CODE ###

s = input()

res = 0
for i in range(len(s)):
    for k in range(i+4, len(s)+1):
        if int(s[i:k]) % 2019 == 0:
            res += 1

print(res)


### FIXED CODE ###

s = input()[::-1]

res = 0
cnt = {0: 1}
now = 0
p = 1
for i in range(len(s)):
    now = (now + (10 * p) * int(s[i])) % 2019
    cnt[now] = cnt.get(now, 0) + 1
    p = (p * 10) % 2019

print(sum(cnt[k] * (cnt[k] - 1) // 2 for k in cnt))
### BUGGY CODE ###

N = int(input())
A = tuple(map(int,input().split()))
d = []
d_append = d.append
num = 10**9 + 7
for i in range(N-1):
    #print(i)
    for j in range(i+1,N):
        #print(j)
        b = A[i] ^ A[j]
        #b %= num
        d_append(b)
print(sum(d)%num)


### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
mod = 10**9 + 7
ans = 0
for k in range(60):
    A_0 = 0
    A_1 = 0
    for i in range(N):
        if A[i]>>k&1:
            A_1 += 1
        else:
            A_0 += 1
    num = A_1 * A_0
    ans += (num * 2 ** k)
ans %=  mod
print(ans)
### BUGGY CODE ###

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

p = 1
for i in range(N):
  p*=arr[i]
    
if p > pow(10,18):
  print(-1)
else:
  print(p)


### FIXED CODE ###

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

if 0 in arr:
  print(0)
else:
  p = 1
  for i in arr:
    p *= i
    if p>1000000000000000000:
      p = -1
      break
  print(p)
### BUGGY CODE ###

N,M=map(int,input().split())
passable=set(range(1,N+1))
for m in range(M):
    L,R=map(int,input().split())
    passable=passable&set(range(L,R+1))
print(len(passable))

### FIXED CODE ###

N,M=map(int,input().split())
L=[]
R=[]
for m in range(M):
    Lm,Rm=map(int,input().split())
    L.append(Lm)
    R.append(Rm)
maxL=max(L)
minR=min(R)
print(max(minR-maxL+1,0))
### BUGGY CODE ###

N,K = map(int,input().split())
a = list(map(int,input().split()))

ans = []
g = 0
for i in range(N-K+1):
  k = 1
  for s in range(K):
    k *= a[s+i] 
  ans.append(k)
  if len(ans)>1:
    if ans[0]<ans[1]:
      print("Yes")
    else:
      print("No")
    del ans[0]

### FIXED CODE ###

N,K = map(int,input().split())
a = list(map(int,input().split()))


for i in range(N-K):
  if a[i]<a[i+K]:
    print("Yes")
  else:
    print("No")
### BUGGY CODE ###

import sys
input=sys.stdin.readline

R,C,K=map(int,input().split())
rcv=[list(map(int,input().split())) for _ in range(K)]

MAP=[[0 for _ in range(C+2)] for _ in range(R+2)]
DP=[[[0 for _ in range(3)] for _ in range(C+2)] for _ in range(R+2)]
for r,c,v in rcv:
    MAP[r-1][c-1]=v

for i in range(R):
    for j in range(C):
        for k in range(3):
            if k==0:
                DP[i][j][k]=max(DP[i][j-1][k],DP[i-1][j][k]+MAP[i][j],
                                DP[i-1][j][k+1]+MAP[i][j],
                                DP[i-1][j][k+2]+MAP[i][j])
            else:
                DP[i][j][k]=max(DP[i][j-1][k],DP[i][j-1][k-1]+MAP[i][j])

ans=0
for i in range(R):
    for j in range(C):
        ans=max(ans,max(DP[i][j]))
print(ans)

### FIXED CODE ###

import sys
input = sys.stdin.readline

R,C,K=map(int,input().split())
J=[tuple(map(int,input().split())) for i in range(K)]

#DP0=[[0]*(C+2) for i in range(R+2)]
DP1=[[0]*(C+2) for i in range(R+2)]
DP2=[[0]*(C+2) for i in range(R+2)]
DP3=[[0]*(C+2) for i in range(R+2)]

MAP=[[0]*C for i in range(R)]

for x,y,v in J:
    MAP[x-1][y-1]=v

for i in range(R):
    for j in range(C):
        DP1[i][j]=max(DP1[i][j-1],DP1[i-1][j]+MAP[i][j],DP2[i-1][j]+MAP[i][j],DP3[i-1][j]+MAP[i][j])
        DP2[i][j]=max(DP2[i][j-1],DP1[i][j-1]+MAP[i][j])
        DP3[i][j]=max(DP3[i][j-1],DP2[i][j-1]+MAP[i][j])

ANS=0
for i in range(R):
    for j in range(C):
        ANS=max(ANS,DP1[i][j],DP2[i][j],DP3[i][j])
print(ANS)
### BUGGY CODE ###

h,w = list(map(int,input().split()))
sx, sy = list(map(int,input().split()))
gx, gy = list(map(int,input().split()))
maze = [list(input()) for _ in range(h)]
sx -= 1; sy -= 1; gx -= 1; gy -= 1

mx = [0,1,0,-1]
my = [1,0,-1,0]
mazemap = [[10**9]*w for _ in range(h)]
from collections import deque
q = deque()
nq = deque()
q.append([sx,sy,0])

while q or nq:
    x,y,z = q.popleft() if q else nq.popleft()
    if x == gx and y == gy:
        ans = z
        break
    for i in range(4):
        nx = x + mx[i]; ny = y + my[i]
        if 0 <= nx < h and 0 <= ny < w and maze[nx][ny] != "#" and mazemap[nx][ny] > z:
            q.append([nx,ny,z])
            mazemap[nx][ny] = z
    for i in range(-2,3):
        for j in range(-2,3):
            nx = x+i; ny = y+j
            if 0 <= nx < h and 0 <= ny < w and maze[nx][ny] != "#" and mazemap[nx][ny] > z+1:
                nq.append([nx,ny,z+1])
                mazemap[nx][ny] = z+1
else:
    ans = -1

print(ans)

### FIXED CODE ###

h,w = list(map(int,input().split()))
sx, sy = list(map(int,input().split()))
gx, gy = list(map(int,input().split()))
maze = [list(input()) for _ in range(h)]
sx -= 1; sy -= 1; gx -= 1; gy -= 1

mx = [0,1,0,-1]
my = [1,0,-1,0]
mazemap = [[10**9]*w for _ in range(h)]
from collections import deque
q = deque()
nq = deque()
q.append([sx,sy,0])

while q or nq:
    x,y,z = q.popleft() if q else nq.popleft()
    if x == gx and y == gy:
        ans = z
        break
    for i in range(4):
        nx = x + mx[i]; ny = y + my[i]
        if 0 <= nx < h and 0 <= ny < w and maze[nx][ny] != "#" and mazemap[nx][ny] > z:
            q.append([nx,ny,z])
            mazemap[nx][ny] = z
        for i in range(-2,3):
            for j in range(-2,3):
                nx = x+i; ny = y+j
                if 0 <= nx < h and 0 <= ny < w and maze[nx][ny] != "#" and mazemap[nx][ny] > z+1:
                    nq.append([nx,ny,z+1])
                    mazemap[nx][ny] = z+1
else:
    ans = -1

print(ans)
### BUGGY CODE ###

import sys

def solve():
    input = sys.stdin.readline
    R, C, K = map(int, input().split())
    item = [[0 for _ in range(C)] for r in range(R)]
    for _ in range(K):
        r, c, k = map(int, input().split())
        item[r-1][c-1] = k
    
    DP = [[[-1 for _ in range(4)] for r in range(C)] for i in range(R)]
    DP[0][0][0] = 0
    for r in range(R):
        for c in range(C):
            for i in range(4):
                if DP[r][c][i] > -1:
                    if r + 1 < R: 
                        DP[r+1][c][0] = max(DP[r+1][c][0], DP[r][c][i])
                    if c + 1 < C: 
                        DP[r][c+1][i] = max(DP[r][c+1][i], DP[r][c][i])
                    if i < 3 and item[r][c] > 0:
                        if r + 1 < R: DP[r+1][c][0] = max(DP[r+1][c][0], DP[r][c][i] + item[r][c])
                        if c + 1 < C: DP[r][c+1][i+1] = max(DP[r][c+1][i+1], DP[r][c][i] + item[r][c])

    ans = DP[R-1][C-1][3]
    for i in range(3): ans = max(ans, DP[R-1][C-1][i] + item[R-1][C-1])
    print(ans)

if __name__ == "__main__":
    solve()


### FIXED CODE ###

import sys

def solve():
    input = sys.stdin.readline
    R, C, K = map(int, input().split())
    item = [[0 for _ in range(C)] for r in range(R)]
    for _ in range(K):
        r, c, k = map(int, input().split())
        item[r-1][c-1] = k
    
    DP = [[[-1 for _ in range(C)] for r in range(R)] for i in range(4)]
    DP[0][0][0] = 0
    for r in range(R):
        for c in range(C):
            for i in range(4):
                if DP[i][r][c] > -1:
                    if r + 1 < R: 
                        DP[0][r+1][c] = max(DP[0][r+1][c], DP[i][r][c])
                    if c + 1 < C: 
                        DP[i][r][c+1] = max(DP[i][r][c+1], DP[i][r][c])
                    if i < 3 and item[r][c] > 0:
                        if r + 1 < R: DP[0][r+1][c] = max(DP[0][r+1][c], DP[i][r][c] + item[r][c])
                        if c + 1 < C: DP[i+1][r][c+1] = max(DP[i+1][r][c+1], DP[i][r][c] + item[r][c])

    ans = DP[3][R-1][C-1]
    for i in range(3): ans = max(ans, DP[i][R-1][C-1] + item[R-1][C-1])
    print(ans)
    return 0

if __name__ == "__main__":
    solve()
### BUGGY CODE ###

mod=10**9+7

n=int(input())

a=list(map(int,input().split()))

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

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

lcma=1

for i in range(n):
    lcma=lcm(lcma,a[i])

ans=0

for i in range(n):
    ans=(ans+lcma//a[i]%mod)%mod

print(ans)



### FIXED CODE ###

mod=10**9+7

n=int(input())

a=list(map(int,input().split()))

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

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

lcma=1

for i in range(n):
    lcma=lcm(lcma,a[i])

ans=0

for i in range(n):
    ans=(ans+lcma//a[i])

print(ans%mod)
### BUGGY CODE ###

def solve():
    mod = 10**9+7
    L = input()
    N = len(L)
    dp = [[0]*2 for _ in range(N)]
    dp[0][0] = 1
    dp[0][1] = 2
    for i in range(1, N):
        if L[i]=='0':
            dp[i][0]=dp[i-1][0]*3
            dp[i][1] = dp[i-1][1]
        else:
            dp[i][0]=dp[i-1][0]*3+dp[i-1][1]
            dp[i][1] = dp[i-1][1]*2
    print((dp[N-1][0]+dp[N-1][1])%mod)
solve()

### FIXED CODE ###

def solve():
    mod = 10**9+7
    L = input()
    N = len(L)
    dp = [0]*2
    dp[0] = 1
    dp[1] = 2
    for i in range(1, N):
        if L[i]=='0':
            dp[0], dp[1]=dp[0]*3, dp[1]
        else:
            dp[0], dp[1]=dp[0]*3+dp[1], dp[1]*2
    print((dp[0]+dp[1])%mod)
solve()
### BUGGY CODE ###

import sys
from bisect import bisect_left
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

H, N = map(int, readline().split())
m = map(int, read().split())
AB = zip(m, m)

INF = 10**18

dp = [INF] * (H + 1)
dp[0] = 0
for a, b in AB:
    for n in range(H + 1):
        k = max(0, n - a)
        acc = dp[k] + b
        if acc < dp[n]:
            dp[n] = acc

print(dp[H])

### FIXED CODE ###

import sys
from bisect import bisect_left
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

H, N = map(int, readline().split())
m = map(int, read().split())
AB = zip(m, m)

INF = 10**18

dp = [INF] * (H + (10**4))
dp[0] = 0
for a, b in AB:
    for n in range(H):
        if dp[n + a] > dp[n] + b:
            dp[n + a] = dp[n] + b

print(min(dp[H:]))
### BUGGY CODE ###

n, m = list(map(int, input().split()))
hs =  list(map(int, input().split()))
roads = []
ans = 0
badpeaks = []
for i in range(m):
    roads += [list(map(int, input().split()))]
for i in range(1, n+1):
    if i in badpeaks:
        continue
    judge = 1
    for road in roads:
        if i in road:
            j = 0
            if road[0] == i:
                j = road[1]
            else:
                j = road[0]
            if hs[j-1] >= hs[i-1]:
                judge = 0
            else:
                badpeaks += [j]
    ans += judge
print(ans)

### FIXED CODE ###

n, m = list(map(int, input().split()))
hs =  list(map(int, input().split()))
ans = [1]*n
roads = []
for i in range(m):
    roads += [list(map(int, input().split()))]
for road in roads:
    if hs[road[0]-1] <= hs[road[1]-1]:
        ans[road[0]-1] = 0
    if hs[road[0]-1] >= hs[road[1]-1]:
        ans[road[1]-1] = 0
print(ans.count(1))
### BUGGY CODE ###

def gcd(a, b):
  while b > 0:
    a, b = b, a%b
  return a

N,M = map(int,input().split(" "))
S = input()
T = input()
N = len(S)
M = len(T)
x = gcd(N,M)
Answer = int(N*M/x)

X = [0 for i in range(Answer)]

for i in range(N):
    X[int(i*Answer/N)] = S[i]

for i in range(M):
    if (X[int(i*Answer/M)] == 0)or(X[int(i*Answer/M)] == T[i]):
        continue
    else:
        print(-1)
        exit()
print(Answer)


### FIXED CODE ###

def gcd(a, b):
  while b > 0:
    a, b = b, a%b
  return a

N,M = map(int,input().split(" "))
S = input()
T = input()
N = len(S)
M = len(T)
x = gcd(N,M)
y = int(N*M/x)

for i in range(x):
    if S[int(i*y/M)] == T[int(i*y/N)]:
        continue
    else:
        print(-1)
        exit()
print(y)
### BUGGY CODE ###

from collections import deque

def main():
    h,w=map(int,input().split())
    maze=[list(input()) for i in range(h)]
    d=[[float("inf")]*w for i in range(h)]
    que=deque([])
    dd=((1,0),(0,1),(-1,0),(0,-1))
    for i in range(h):
        for j in range(w):
            if maze[i][j]=="#":
                que.append((i,j))           
                d[i][j]=0
    ans=0
    while que:
        p=que.popleft()
        ans=d[p[0]][p[1]]
        for dx,dy in dd:
            nx=p[0]+dx
            ny=p[1]+dy
            if 0<=nx and nx<h and 0<=ny and ny<w and maze[nx][ny]!="#" and d[nx][ny]==float("inf"):
                d[nx][ny]=ans+1
                que.append((nx,ny))  
    return ans
if __name__=='__main__':
    print(main())

### FIXED CODE ###

from collections import deque

def main():
    h,w=map(int,input().split())
    maze=[list(input()) for i in range(h)]
    d=[[-1]*w for i in range(h)]
    que=deque([])
    dd=((1,0),(0,1),(-1,0),(0,-1))
    for i in range(h):
        for j in range(w):
            if maze[i][j]=="#":
                que.append((i,j))           
                d[i][j]=0
    ans=0
    while que:
        p=que.popleft()
        ans=d[p[0]][p[1]]
        for dx,dy in dd:
            nx=p[0]+dx
            ny=p[1]+dy
            if 0<=nx and nx<h and 0<=ny and ny<w and maze[nx][ny]!="#" and d[nx][ny]==-1:
                d[nx][ny]=ans+1
                que.append((nx,ny))  
    return ans
if __name__=='__main__':
    print(main())
### BUGGY CODE ###

import itertools
N, K = [int(_) for _ in input().split()]
XY = [[int(_) for _ in input().split()] for _ in range(N)]
X, Y = sorted([x for x, y in XY]), sorted([y for x, y in XY])
ans = float('inf')
for x1, x2 in itertools.combinations(X, 2):
    for y1, y2 in itertools.combinations(Y, 2):
        k = sum([x1 <= XY[i][0] <= x2 and y1 <= XY[i][1] <= y2 for i in range(N)])
        if k >= K:
            ans = min(ans, (x2 - x1) * (y2 - y1))
print(ans)

### FIXED CODE ###

import itertools
N, K = [int(_) for _ in input().split()]
XY = [[int(_) for _ in input().split()] for _ in range(N)]
X, Y = [x for x, y in XY], [y for x, y in XY]
X_s, Y_s = sorted(X), sorted(Y)
ans = float('inf')
for x1, x2 in itertools.combinations(X_s, 2):
    for y1, y2 in itertools.combinations(Y_s, 2):
        k = sum([x1 <= X[i] <= x2 and y1 <= Y[i] <= y2 for i in range(N)])
        if k >= K:
            ans = min(ans, (x2 - x1) * (y2 - y1))
print(ans)
### BUGGY CODE ###

N = int(input())
t = list(map(int,input().split()))
v = list(map(int,input().split()))
T = sum(t)*2
vt = [min(i/2,(T-i)/2) for i in range(T+1)]
ts = 0
te = 0
for i in range(N):
    te += t[i]*2
    vi = v[i]
    vt = [min(vtj,vi+((-(j-ts)/2) if j<ts else ((j-te)/2) if j>te else 0)) for j,vtj in enumerate(vt)]
    ts = te
print(sum(vt)/2)

### FIXED CODE ###

N = int(input())
t = list(map(int,input().split()))
v = list(map(int,input().split()))
T = sum(t)*2
vt = [min(i/2,(T-i)/2) for i in range(T+1)]
ts = 0
te = 0
for i in range(N):
    te += t[i]*2
    for j in range(T+1):
        vt[j] = min(vt[j],v[i]+max(0,-(j-ts)/2,(j-te)/2))
    ts = te
print(sum(vt)/2)
### BUGGY CODE ###

import fractions

def lcm(x,y):
  return x * y // fractions.gcd(x,y)


mod = 10**9+7


N = int(input())

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

g = 1

for i in range(N):
    g = lcm(g,A[i])

ans = 0

for i in range(N):
    ans += g // A[i]
    ans %= mod

print (ans)
    


### FIXED CODE ###

import fractions

def lcm(x,y):
  return x // fractions.gcd(x,y) * y


mod = 10**9+7


N = int(input())

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

B = 0
for i in A:
    B += pow(i,mod-2,mod)
    B %= mod

g = 1

for i in range(N):
    g = lcm(g,A[i])

print (g * B % mod)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
N, M, Q = map(int, input().split())
LR = [list(map(int, input().split())) for _ in range(M)]
PQ = [list(map(int, input().split())) for _ in range(Q)]

#X[l][r]はlからrをちょうど走る電車の数
X = [[0 for _ in range(N+1)] for _ in range(N+1)]
for l, r in LR:
    X[l][r] += 1
cum = [[0 for _ in range(N+1)] for _ in range(N+1)]
for i in range(1, N+1):
    for j in range(1, N+1):
        cum[i][j] = cum[i][j-1] + X[i][j]

outputs = []
for p, q in PQ:
    ans = 0
    for i in range(p, q+1):
        ans += cum[i][q] - cum[i][p-1]
    outputs.append(ans)

print('\n'.join(map(str, outputs)))


### FIXED CODE ###

N, M, Q = map(int, input().split())
LR = [list(map(int, input().split())) for _ in range(M)]
PQ = [list(map(int, input().split())) for _ in range(Q)]

#X[l][r]はlからrをちょうど走る電車の数
X = [[0 for _ in range(N+1)] for _ in range(N+1)]
for l, r in LR:
    X[l][r] += 1
cum = [[0 for _ in range(N+1)] for _ in range(N+1)]
for i in range(1, N+1):
    for j in range(1, N+1):
        cum[i][j] = cum[i][j-1] + X[i][j]

for p, q in PQ:
    ans = 0
    for i in range(p, q+1):
        ans += cum[i][q] - cum[i][p-1]
    print(ans)