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

N = int(input())
ts = list(map(int,input().split()))
vs = list(map(int,input().split()))

durs = [0]
for i in range(N):
    durs.append(durs[-1] + ts[i])
T = durs[-1]

maxv = [0.5*i for i in range(T)] + [0.5*i for i in range(T,-1,-1)]

for i in range(N):
    t1,t2 = durs[i],durs[i+1]
    for ti in range(2*T + 1):
        t = ti*0.5
        if t < t1:
            maxv[ti] = min(maxv[ti], vs[i] + (t1-t))
        elif t > t2:
            maxv[ti] = min(maxv[ti], vs[i] + (t-t2))
        else:
            maxv[ti] = min(maxv[ti], vs[i])

ans = 0.0
for i in range(2*T):
    ans += (maxv[i] + maxv[i+1]) * 0.25
print(ans)


### FIXED CODE ###

N = int(input())
ts = list(map(int,input().split()))
vs = list(map(int,input().split()))

maxv = [0]
for v,t in zip(vs,ts):
    maxv[-1] = min(maxv[-1], v)
    for ti in range(t*2):
        maxv.append(v)
T = len(maxv)

for i in range(T-1):
    maxv[i+1] = min(maxv[i+1], maxv[i] + 0.5)

maxv[-1] = 0
for i in reversed(range(T-1)):
    maxv[i] = min(maxv[i], maxv[i+1] + 0.5)

ans = 0.0
for i in range(T-1):
    ans += (maxv[i] + maxv[i+1]) * 0.25
print(ans)
### BUGGY CODE ###

s=input()
q=int(input())
for _ in range(q):
  L=list(input().split())
  if L[0]=='1':
    s=s[::-1]
  else:
    if L[1]=='1':
      t=L[2]+s
      s=t
    else:
      s+=L[2]
      
print(s)

### FIXED CODE ###

def main():
  from collections import deque
  s=input()
  q=int(input())
  turn = 2
  d=deque(s)

  for _ in [0]*q:
      query = input()
      if query[0] == "1":
          t = int(query)
          turn = 3 - turn
      else:
          t,f,c = map(str,query.split())
          if (int(f) + turn)% 2  == 0:
              d.append(c)
          else:
              d.appendleft(c)
  if turn == 2:
      print("".join(d))
  else:
      print("".join(list(d)[::-1]))
main()
### BUGGY CODE ###

N = int(input())
S = input()
dp = [[0] * (N + 1) for _ in range(N + 1)]
for i in range(N - 1, -1, -1):
    for j in range(N - 1, -1, -1):
        if S[i] != S[j]:
            dp[i][j] = 0
        else:
            dp[i][j] = dp[i + 1][j + 1] + 1
result = 0
for i in range(N):
    for j in range(i + 1, N):
        t = min(dp[i][j], j - i)
        result = max(result, t)
print(result)


### FIXED CODE ###

N = int(input())
S = input()

result = 0
for i in range(N - 1, 0, -1):
    if i <= result:
        break
    t = 0
    for j in range(N - i):
        if S[j] == S[j+i]:
            t += 1
            if t > result:
                result = t
            if result == i:
                break
        else:
            t = 0

print(result)
### BUGGY CODE ###

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

a = [int(input()) for i in range(M)]


for i in range(M - 1):
    if a[i] + 1 == a[i+1]:
        print(0)
        exit()

dp = [0] * (N + 1)

if N == 1 and M != 1:
    print(1)
    exit()
elif N == 1 and M == 1:
    print(0)
    exit()

if 1 in a and 2 in a:
    print(0)
    exit()

if 1 in a:
    dp[1] = 0
    dp[2] = 1
elif 2 in a:
    dp[1] = 1
    dp[2] = 0
else:
    dp[1] = 1
    dp[2] = 2

for i in range(3,N+1):
    if i in a:
        dp[i] = 0
        a.remove(i)
    else:
        dp[i] = (dp[i - 1] + dp[i - 2]) % 1000000007

print(dp[N])

### FIXED CODE ###

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

a = [int(input()) for i in range(M)]


for i in range(M - 1):
    if a[i] + 1 == a[i+1]:
        print(0)
        exit()

dp = [0] * (N + 1)
flag_a = [0] * (N + 1)

for i in range(M):
    flag_a[a[i]] = -1


if N == 1 and M != 1:
    print(1)
    exit()
elif N == 1 and M == 1:
    print(0)
    exit()

if 1 in a and 2 in a:
    print(0)
    exit()

if 1 in a:
    dp[1] = 0
    dp[2] = 1
elif 2 in a:
    dp[1] = 1
    dp[2] = 0
else:
    dp[1] = 1
    dp[2] = 2

for i in range(3,N+1):
    if flag_a[i] == -1:
        dp[i] = 0
    else:
        dp[i] = (dp[i - 1] + dp[i - 2]) % 1000000007

print(dp[N])
### BUGGY CODE ###

n = int(input())
ans = 0

for i in range(1,n):
    ans += i

print(ans)

### FIXED CODE ###

n = int(input())
ans = n * (n - 1) // 2

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

import numpy as np

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

A = np.zeros(N, dtype = int)
B = np.zeros(N, dtype = int)

for i in range(N):
    A[i],B[i] = map(int,input().split())
    
dp = np.full(H+1, np.inf)
dp[0] = 0
for i in range(1,H+1):
    dp[i] = min([dp[max(i-A[j],0)] + B[j] for j in range(N)])
            
print(int(dp[H]))

### FIXED CODE ###

import numpy as np

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

A = np.zeros(N, dtype = int)
B = np.zeros(N, dtype = int)

for i in range(N):
    A[i],B[i] = map(int,input().split())
    
dp = np.full(H+1, np.inf)

dp[0] = 0
for i in range(1,H+1):
    dp[i] = np.amin( dp[np.maximum(i-A,0)] + B )

print(int(dp[H]))
### BUGGY CODE ###

n,q=map(int,input().split())
c=list(map(int,input().split()))
lr=[list(map(int,input().split())) for _ in range(q)]
lri=[[lr[i][0],lr[i][1],i] for i in range(q)]
lri.sort(key=lambda x:x[1])
def segfunc(x, y):
  return x+y
#################

#####ide_ele#####
ide_ele=0
#################

class SegTree:
  """
  init(init_val, ide_ele): 配列init_valで初期化 O(N)
  update(k, x): k番目の値をxに更新 O(logN)
  query(l, r): 区間[l, r)をsegfuncしたものを返す O(logN)
  """
  def __init__(self, init_val, segfunc=segfunc, ide_ele=ide_ele):
    """
    init_val: 配列の初期値
    segfunc: 区間にしたい操作
    ide_ele: 単位元
    n: 要素数
    num: n以上の最小の2のべき乗
    tree: セグメント木(1-index)
    """
    n = len(init_val)
    self.segfunc = segfunc
    self.ide_ele = ide_ele
    self.num = 1 << (n - 1).bit_length()
    self.tree = [ide_ele] * 2 * self.num
    # 配列の値を葉にセット
    for i in range(n):
      self.tree[self.num + i] = init_val[i]
    # 構築していく
    for i in range(self.num - 1, 0, -1):
      self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])

  def update(self, k, x):
    """
    k番目の値をxに更新
    k: index(0-index)
    x: update value
    """
    k += self.num
    self.tree[k] = x
    while k > 1:
      self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
      k >>= 1

  def query(self, l, r):
    """
    [l, r)のsegfuncしたものを得る
    l: index(0-index)
    r: index(0-index)
    """
    res = self.ide_ele

    l += self.num
    r += self.num
    while l < r:
      if l & 1:
        res = self.segfunc(res, self.tree[l])
        l += 1
      if r & 1:
        res = self.segfunc(res, self.tree[r - 1])
      l >>= 1
      r >>= 1
    return res
st=SegTree([0]*(n+1))
dc={}
ans=[0]*q
j=0
for i in range(n):
  x=c[i]
  if x in dc:
    st.update(dc[x],0)
    st.update(i+1,1)
    dc[x]=i+1
  else:
    st.update(i+1,1)
    dc[x]=i+1
  while j<q and i+1==lri[j][1]:
    l,r,k=lri[j]
    ans[k]=st.query(l,r+1)
    j+=1
print(*ans,sep='\n')


### FIXED CODE ###


import sys
input = sys.stdin.readline
def main():
  n,q=map(int,input().split())
  c=list(map(int,input().split()))
  lr=[list(map(int,input().split())) for _ in range(q)]
  lri=[[lr[i][0],lr[i][1],i] for i in range(q)]
  lri.sort(key=lambda x:x[1])
  
  class BIT:
      def __init__(self, n):
          self.n = n
          self.data = [0]*(n+1)
          self.el = [0]*(n+1)
      def sum(self, i):
          s = 0
          while i > 0:
              s += self.data[i]
              i -= i & -i
          return s
      def add(self, i, x):
          # assert i > 0
          self.el[i] += x
          while i <= self.n:
              self.data[i] += x
              i += i & -i
      def get(self, i, j=None):
          if j is None:
              return self.el[i]
          return self.sum(j) - self.sum(i)

  bt=BIT(n+1)
  dc={}
  ans=[0]*q
  j=0
  for i in range(n):
    x=c[i]
    if x in dc:
      bt.add(dc[x],-1)
    bt.add(i+1,1)
    dc[x]=i+1
    while j<q and i+1==lri[j][1]:
      l,r,k=lri[j]
      ans[k]=bt.get(l-1,r)
      j+=1
    if j==q:break
  print(*ans,sep='\n')


if __name__=='__main__':
  #import datetime
  #print(datetime.datetime.now())
  main()
  #print(datetime.datetime.now())
### BUGGY CODE ###

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

B = []
if(n%2 == 0):
  p = n//2
  for i in range(p):
   B.insert(0,str(A[2*i+1]))
   B.append(str(A[2*i]))
elif(n%2 == 1):
  p = n//2 
  for i in range(p):
   B.insert(0,str(A[2*i]))
   B.append(str(A[2*i+1]))
  B.insert(0,str(A[2*p]))
  
b = ' '.join(B)
print(b)

### FIXED CODE ###

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

B = []
if(n%2 == 1):
  p = n//2
  B.append(str(A[2*p]))
  for i in range(p):
   B.append(str(A[2*(p-1-i)]))
  for i in range(p):
    B.append(str(A[2*i+1]))

elif(n%2 == 0):
  p = n//2 
  for i in range(p):
   B.append(str(A[2*(p-1-i)+1]))
  for i in range(p):
    B.append(str(A[2*i]))

b = ' '.join(B) 
print(b)
### BUGGY CODE ###

def powmod(x, y, mod):
    if y == 0:
        return 1
    return (((powmod(x, y >> 1, mod) ** 2) % mod) * x ** (y & 1)) % mod


n = int(input())
a = tuple(map(int, input().split()))
mod = 10**9 + 7
cnt = [0] * 60
for i in range(n):
    r = a[i]
    for j in range(60):
        if r & 1:
            cnt[j] += 1
        r >>= 1

ans = 0
for i in range(60):
    ans += powmod(2, i, mod) * cnt[i] * (n-cnt[i])
    ans %= mod
print(ans)

### FIXED CODE ###

def powmod(x, y, mod):
    if y == 0:
        return 1
    return (((powmod(x, y >> 1, mod) ** 2) % mod) * x ** (y & 1)) % mod


n = int(input())
a = tuple(map(int, input().split()))
mod = 10**9 + 7
cnt = [0] * 60
for i in range(n):
    r = a[i]
    for j in range(60):
        if r & 1:
            cnt[j] += 1
        r >>= 1

ans = 0
for i in range(60):
    ans += powmod(2, i, mod) * cnt[i] * (n-cnt[i])
    ans %= mod
print(ans)
### BUGGY CODE ###

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

def aa():
    if a == b and a == c and a % 2 == 0:
        return -1
    else:
        A = [a-b, b-c, c-a]
        j = 0
        while True:
            for i in range(3):
                if A[i] % 2 == 1:
                    return j
                else:
                    A[i] //= 2
            j += 1

print(aa())

### FIXED CODE ###

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

def aa():
    if a == b and a == c:
        if a % 2 == 0:
            return -1
        else:
            return 0
    else:
        A = [a-b, b-c, c-a]
        j = 0
        while True:
            for i in range(3):
                if A[i] % 2 == 1:
                    return j
                else:
                    A[i] //= 2
            j += 1

print(aa())
### BUGGY CODE ###

# -*- coding: utf-8 -*-

import bisect

n = int(input())

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

A.sort()
B.sort()
C.sort()

Bc, Cc = [0]*n, [0]*n
Bp, Cp = 0, 0

for i in range(n):
    index = bisect.bisect_right(B, A[i])
    Bc[i] = n - index
    index = bisect.bisect_right(C, B[i])
    Cc[i] = n - index

Ccs = [sum(Cc[i:]) for i in range(n)]

count = 0
for bc in Bc:
    if bc > 0:
        count += Ccs[n-bc]

print(count)


### FIXED CODE ###

# -*- coding: utf-8 -*-
 
import bisect
 
n = int(input())
 
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
 
A.sort()
B.sort()
C.sort()
 
Ac, Cc = [0]*n, [0]*n
# Ap, Cp = 0, 0
 
for i in range(n):
    Ac[i] = bisect.bisect_left(A, B[i])#[Ap:], B[i])
    # Ac[i], Ap = index + Ap, index + Ap
    Cc[i] = n - bisect.bisect_right(C, B[i])#[Cp:], B[i])
    # Cc[i], Cp = n - index - Cp, index + Cp
 
 
count = 0
for i in range(n):
    count += Ac[i]*Cc[i]
 
print(count)
### BUGGY CODE ###

import itertools

N,K=map(int,input().split())
A=list(map(int,input().split()))
mod=10**9+7

NOW=[0]*(K+1)
NOW[0]=1#そこまでi個使ったときの場合の数


for a in A:
    NEXT=[0]*(K+1)
    NOWSUM=list(itertools.accumulate(NOW))
    NEXT=[now%mod for now in NOWSUM]
    #print(NEXT)

    for j in range(a+1,K+1):
        NEXT[j]-=NOWSUM[j-a-1]


    NOW=NEXT
    #print(NOWSUM,NOW)

print(NOW[K]%mod)

### FIXED CODE ###

N,K=map(int,input().split())
A=list(map(int,input().split()))
mod=10**9+7

NOW=[0]*(K+1)
NOW[0]=1#そこまでi個使ったときの場合の数


for i in range(N):
    NEXT=[0]*(K+1)
    NOWSUM=[0]
    for n in NOW:
        NOWSUM.append(NOWSUM[-1]+n)
        
    for j in range(K+1):
        NEXT[j]=(NEXT[j]+NOWSUM[j+1]-NOWSUM[max(0,j-A[i])])%mod

    NOW=NEXT
    #print(NOWSUM,NOW)

print(NOW[K])
### BUGGY CODE ###

# coding:utf-8

import sys

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    n = II()
    B = [SI() for _ in range(n)]

    res = 0
    for i in range(n):
        is_good = 1
        for h in range(n):
            for w in range(h + 1, n):
                if B[h][(w + i) % n] != B[w][(h + i) % n]:
                    is_good = 0

        if is_good:
            res += n

    return res


print(main())


### FIXED CODE ###

# coding:utf-8

import sys
# from collections import Counter, defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    n = II()
    B = [SI() for _ in range(n)]

    res = 0
    for i in range(n):
        is_good = 1
        for h in range(n):
            for w in range(h + 1, n):
                if B[h][(w + i) % n] != B[w][(h + i) % n]:
                    is_good = 0
                    break

            if not is_good:
                break

        if is_good:
            res += n

    return res


print(main())
### BUGGY CODE ###

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

even=[x for x in a if x%2==0]
ans=0
while even!=[]:
    delval=0
    even[0]//=2
    len_even=len(even)
    for i in range(len_even):
        if i==0:
            if even[i]%2!=0:
                del even[i]
                delval+=1
        else:
            if (even[i-delval]*3)%2!=0:
                del even[i-delval]
                delval+=1
            else:
                even[i-delval]*=3
    ans+=1
print(ans)

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
ans=0
for i in a:
    buf=i
    ans+=format(buf,'b')[::-1].find('1')
print(ans)
### BUGGY CODE ###

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

i_count = 0
flag = True
for i in range(N):
  flag = True
  for j in range(i):
    if P[i] > P[j]:
      flag = False
      break

  if flag:
    i_count+=1

print(i_count)
  
	

### FIXED CODE ###

import sys
sysinput = sys.stdin.readline

N = int(sysinput())
P = list(map(int, sysinput().split()))
memo_mini = N
i_count = 0
for i in range(0, N):
  if memo_mini >= P[i]:
      i_count +=1
      memo_mini = P[i]
  else:
    pass
  
print(i_count)
### BUGGY CODE ###

def judge(x,y,z):
    return ((x+y) > z) and ((x + z) > y) and ((y + z) > x)



def calculate(arr):
    N = len(arr)

    if N == 0:
        return 0

    if N < 3:
        return 0

    count = 0
    for x_index in range(N-2):
        for y_index in range(x_index+1,N-1):
            for z_index in range(y_index+1,N):
                if judge(arr[x_index],arr[y_index],arr[z_index]):
                    count = count + 1

    return count

N = input()
L = input().split(' ')
arr = []
for i in L:
    arr.append(int(i))

result = calculate(arr)
print(result)

### FIXED CODE ###

import bisect

N = int(input())

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

def calculate(n,arr):
    arr = sorted(arr)
    sum = 0
    for i in range(n-1):
        for j in range(i+1,n):
            mmm = arr[j] + arr[i] - 1
            nnn = bisect.bisect_right(arr,mmm)
            sum = sum + nnn - (j + 1)

    print(sum)


calculate(N,ARR)
### BUGGY CODE ###

N = int(input())
S = list(input() for i in range(N))  #スペース抜きの単語を複数行

import collections
A = collections.Counter(S)

C = [i for i in A if A[i] == max(A.values())]
C = sorted(C)
 
for i in C:
    print(i)

### FIXED CODE ###

N = int(input())
S = list(input() for i in range(N))  #スペース抜きの単語を複数行

A = {}
for i in S:
    A.setdefault(i, 1)
    A[i] += 1

B = max(A.values())
C = [i for i in A if A[i] == B]
C = sorted(C)

for i in C:
    print(i)
### BUGGY CODE ###

h,w=map(int,input().split())
s=[]
for i in range(h):
    s.append(list(input()))


def search(i,j):
    ansij=1
    y=i
    x=j
    while(0<x and s[y][x-1]=='.'):
        ansij+=1
        x-=1
    y=i
    x=j
    while(x<w-1 and s[y][x+1]=='.'):
        ansij+=1
        x+=1
    y=i
    x=j
    while(0<y and s[y-1][x]=='.'):
        ansij+=1
        y-=1
    y=i
    x=j
    while(y<h-1 and s[y+1][x]=='.'):
        ansij+=1
        y+=1
    return ansij


ans=0
for i in range(h):
    for j in range(w):
        if(s[i][j]=='.'):
            ansij=search(i, j)
            if(ans<ansij):
#                print(i,j,ansij)
                ans=ansij

print(ans)


### FIXED CODE ###

import numpy as np
h,w=map(int,input().split())
s=[]
for _ in range(h):
    si=input()
    si=si.replace('.', '1')
    si=si.replace('#', '0')
    s.append(list(map(int,si)))
s=np.array(s)

left=np.zeros((h,w))
right=np.zeros((h,w))
up=np.zeros((h,w))
down=np.zeros((h,w))

for i in range(w):
    if(i==0):
        left[:,i]=s[:,i]
        right[:,w-i-1]=s[:,w-i-1]
    else:
        left[:,i]=(left[:,i-1]+1)*s[:,i]
        right[:,w-i-1]=(right[:,w-i]+1)*s[:,w-i-1]

for i in range(h):
    if(i==0):
        down[i,:]=s[i,:]
        up[h-i-1,:]=s[h-i-1,:]
    else:
        down[i,:]=(down[i-1,:]+1)*s[i,:]
        up[h-i-1,:]=(up[h-i,:]+1)*s[h-i-1,:]

ans=left+right+up+down-3
print(int(np.max(ans)))
### BUGGY CODE ###

s=input()
ans=[0]*len(s)

for i in range(len(s)):
  while True:
    if s[i]=='L':
      if s[i]!=s[i-1]:
        ans[i]+=1
        
      else:
        i-=2
        
    if s[i]=='R':
      if s[i]!=s[i+1]:
        ans[i]+=1
        
      else:
        i+=2
        
ans=list(map(str,ans))

print(' '.join(ans))
        
    
      
        

### FIXED CODE ###

s=input()
ans=[1]*len(s)

for i in range(len(s)):
    if s[i]=='L':
      if s[i]==s[i-1]:
        ans[i-2]+=ans[i]
        ans[i]=0
        
    elif s[i]=='R':
      if s[i]==s[i+1]:
        ans[i+2]+=ans[i]
        ans[i]=0

for i in range(len(s)-1,-1,-1):
    if s[i]=='L':
      if s[i]==s[i-1]:
        ans[i-2]+=ans[i]
        ans[i]=0
        
    elif s[i]=='R':
      if s[i]==s[i+1]:
        ans[i+2]+=ans[i]
        ans[i]=0
        
        
ans=list(map(str,ans))

print(' '.join(ans))
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**6)
import numpy as np

def dfs(v, u, k):
    for i in d[v]:
        if i[0] == u:
            continue
        dnp[i[0]] = k + i[1]
        dfs(i[0], v, k + i[1])

N = int(input())
d = [[] for _ in range(N)]
for i in range(N - 1):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    d[a].append((b, c))
    d[b].append((a, c))
kkyori = [0] * N
dnp = np.array(kkyori)
Q, K = map(int, input().split())
dfs(K - 1, -1, 0)
for i in range(Q):
    x, y = map(int, input().split())
    print(dnp[x - 1] + dnp[y - 1])

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)

def dfs(v, u, k):
    for i in d[v]:
        if i[0] == u:
            continue
        kkyori[i[0]] = k + i[1]
        dfs(i[0], v, k + i[1])

N = int(input())
d = [[] for _ in range(N)]
for i in range(N - 1):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    d[a].append((b, c))
    d[b].append((a, c))
kkyori = [0] * N

Q, K = map(int, input().split())
dfs(K - 1, -1, 0)
for i in range(Q):
    x, y = map(int, input().split())
    print(kkyori[x - 1] + kkyori[y - 1])
### BUGGY CODE ###

n,m=map(int,input().split())
inf=10**12

ab=[]
cs=[]
for i in range(m):
    a,b=map(int,input().split())
    c=tuple(map(int,input().split()))
    ab.append((a,b))
    cs.append(c)
dp=[inf]*(2**n)
dp[0]=0
for i in range(m):
    x=0
    for h in cs[i]:
        x+=2**(h-1)
    for j in range(2**n):
        dp[j|x]=min(dp[j|x],dp[j]+ab[i][0])
print(dp[-1] if dp[-1]!=inf else -1)

### FIXED CODE ###

n,m=map(int,input().split())
inf=10**12

ab=[]
cs=[]
for i in range(m):
    a,b=map(int,input().split())
    c=tuple(map(int,input().split()))
    ab.append((a,b))
    cs.append(c)
dp=[inf]*(2**n)
dp[0]=0
for i in range(m):
    x=0
    for h in cs[i]:
        x+=2**(h-1)
    for j in range(2**n):
        dp[j|x]=min(dp[j|x],dp[j]+ab[i][0])
print(dp[-1] if dp[-1]!=inf else -1)
### BUGGY CODE ###

import sys

N, K = map(int, sys.stdin.readline().split())
p = tuple(map(int, sys.stdin.readline().split()))

max = 0
ite = N - K
base = sum(p[0:K])
max = base
index = 0
for i in range(ite):
    tmp = base + p[i+K] - p[i]
    if tmp > max:
        max = tmp
        index = i+1
    base = tmp

#E = [None]*K
E = [sum(range(1, p[index+i]+1))/p[index+i] for i in range(K)]
"""
for i in range(K):
    E[i] = sum(range(1, p[index+i]+1))/p[index+i]
"""
print(sum(E))

### FIXED CODE ###

import sys

N, K = map(int, sys.stdin.readline().split())
p = tuple(map(int, sys.stdin.readline().split()))

max = 0
ite = N - K
base = sum(p[0:K])
max = base
index = 0
for i in range(ite):
    tmp = base + p[i+K] - p[i]
    if tmp > max:
        max = tmp
        index = i+1
    base = tmp

E = [(1+p[index+i])/2 for i in range(K)]
print(sum(E))
### BUGGY CODE ###

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

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

bc = []
for _ in range(m):
    b, c = (int(x) for x in input().split())
    bc.append([b,c])

bc = sorted(bc, key=lambda x: -x[1])

memo = []

limit = 0

for i in range(m):
    memo = memo + [bc[i][1]]*bc[i][0]
    limit += bc[i][0]
    if limit >= n:
        break

memo = a+memo

memo.sort(reverse=True)

ans = 0

for i in range(n):
    ans += memo[i]
print(ans)
    

### FIXED CODE ###

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

t = list(map(int,input().split()))
ab=[]
for _ in range(m):
    a, b = (int(x) for x in input().split())
    ab.append([a,b])

t.sort(reverse=True)
ab = sorted(ab, key=lambda x: -x[1])
count = 0
for i,j in ab:
    t += [j]*i
    count += i
    if n <= count:
        break

t.sort(reverse=True)
        
print(sum(t[:n]))
### BUGGY CODE ###

N=int(input())
D=list(map(int,input().split()))
M=int(input())
T=list(map(int,input().split()))

import  bisect

D.sort()
T.sort()
cnt=0
for i in range(M):

    if bisect.bisect_right(D,T[i])-bisect.bisect_left(D,T[i])>0:
        D.remove(D[bisect.bisect_right(D,T[i])-1])
        cnt+=1
    else:
        print("NO")
        exit()

if cnt==M:
    print("YES")

### FIXED CODE ###

N=int(input())
D=list(map(int,input().split()))
M=int(input())
T=list(map(int,input().split()))

import  bisect
from collections import  Counter
D.sort()
T.sort()
tmpa=Counter(D)
tmpt=Counter(T)
cnt=0
for i in range(M):
    hnt=T[i]
    v=True
    if tmpt[hnt]<=tmpa[hnt]:
        continue
    else:
        v=False
        print("NO")
        exit()

if v:
    print("YES")