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

import sys
readline = sys.stdin.readline
from math import log2
N, M = map(int, readline().split())
A = [list(map(int, readline().split())) for i in range(N)]
B = max(max(Ai) for Ai in A)
if M == 1:
    if N == 1 or all(A[i][0] < A[i+1][0] for i in range(N-1)):
        print("0")
    else:
        print("-1")
    exit(0)
logB = log2(B)
logBi = int(logB)
INF = 10**18
def gen(P, t):
    if t <= logB:
        for k in range(t):
            for i in range(M-1):
                P[i+1] += P[i]
    else:
        for k in range(t):
            for i in range(min(logBi+2, M-1)):
                P[i+1] += P[i]
        for i in range(logBi+2, M):
            P[i] = INF
T = [0]*N
ans = 0
P = [0]*M
for i in range(N-1):
    a0, a1 = A[i][:2]
    b0, b1 = A[i+1][:2]
    if a0 < b0:
        continue
    if a0 > b0:
        ans = -1
        break
    t0 = T[i]
    v = max(t0*a0 + a1 - b1, 0)
    if v % b0 > 0:
        T[i+1] = t1 = (v + b0-1) // b0
        ans += t1
        continue

    t1 = v // b0
    if t0 <= t1:
        P[:] = A[i+1]
        gen(P, t1 - t0)
        if P <= A[i]:
            t1 += 1
    else:
        P[:] = A[i]
        gen(P, t0 - t1)
        if A[i+1] <= P:
            t1 += 1
    T[i+1] = t1
    ans += t1
print(ans)

### FIXED CODE ###

import sys
readline = sys.stdin.readline
from math import log2
from itertools import accumulate
N, M = map(int, readline().split())
A = [list(map(int, readline().split())) for i in range(N)]
B = max(max(Ai) for Ai in A)
if M == 1:
    if N == 1 or all(A[i][0] < A[i+1][0] for i in range(N-1)):
        print("0")
    else:
        print("-1")
    exit(0)
logB = log2(B)
logBi = int(logB)
INF = 10**18
INFL = [INF]*(M - logBi-2)
def gen(P, t, L = min(logBi+2, M)):
    if t <= logB:
        for k in range(t):
            P[:] = accumulate(P)
    else:
        V = [1]*L
        for k in range(1, L):
            V[k] = V[k-1] * (t + k - 1)//k

        for i in range(L-1, 0, -1):
            P[i] += sum(P[j] * V[i-j] for j in range(i))
        if logBi+2 < M:
            P[logBi+2:] = INFL
T = [0]*N
ans = 0
P = [0]*M
for i in range(N-1):
    a0, a1 = A[i][:2]
    b0, b1 = A[i+1][:2]
    if a0 < b0:
        continue
    if a0 > b0:
        ans = -1
        break
    t0 = T[i]
    v = max(t0*a0 + a1 - b1, 0)
    if v % b0 > 0:
        T[i+1] = t1 = (v + b0-1) // b0
        ans += t1
        continue

    t1 = v // b0
    if t0 <= t1:
        P[:] = A[i+1]
        gen(P, t1 - t0)
        if P <= A[i]:
            t1 += 1
    else:
        P[:] = A[i]
        gen(P, t0 - t1)
        if A[i+1] <= P:
            t1 += 1
    T[i+1] = t1
    ans += t1
print(ans)
### BUGGY CODE ###

a,b = (int(i) for i in input().split())

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
  
def is_prime(n):
  for p in range(2, n):
    if n % p == 0:
      return False
  return True

cnt = 0

def divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors
  
list = divisors(gcd(a,b))
for i in list:
  if is_prime(i):
    cnt += 1
print(cnt)

### FIXED CODE ###

a,b = (int(i) for i in input().split())

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
  
def is_prime(n):
  for p in range(2, n):
    if n % p == 0:
      return False
  return True

cnt = 0

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
  
list = prime_factorize(gcd(a,b))

print(len(set(list))+1)
### BUGGY CODE ###

N = int(input())

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

num = 0
for n in set(lis):
    num += lis.count(n) % 2

print(num)


### FIXED CODE ###

import collections

N = int(input())

def mod2(n):
    a = n % 2
    return a

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

count = collections.Counter(lis)

print(sum(map(mod2, count.values())))
### BUGGY CODE ###

s = input()
q = int(input())

rev = 0

for _ in range(q):
    t = [x for x in input().split()]
    if t[0] == "1":
        rev += 1
    else:
        if t[1] == "1" and rev % 2 == 0:
            s = "".join([t[2],s])
        elif t[1] == "2" and rev % 2 != 0:
            s = "".join([t[2],s])
        else:
            s = "".join([s,t[2]])

if rev % 2 == 0:
    print(s)
else:
    print(s[::-1])


### FIXED CODE ###

from collections import deque
s = deque(input())
q = int(input())

rev = False

for _ in range(q):
    t = [x for x in input().split()]
    if t[0] == "1":
        rev = not rev
    else:
        if t[1] == "1":
            s.append(t[2]) if rev else s.appendleft(t[2])
        else:
            s.appendleft(t[2]) if rev else s.append(t[2])

if rev:
    s.reverse()
print("".join(s))
### BUGGY CODE ###

N = int(input())
S = list(input())
ans = 0
number = set(S)
snumber = list(number)
for i in snumber:
    for j in snumber:
        for k in snumber:
            n = 0
            code = []
            while i != S[n] and n < N-3:
                n += 1
            code.append(S[n])
            n += 1
            while j != S[n] and n < N-2:
                n += 1
            code.append(S[n])
            n += 1
            while k != S[n] and n < N-1:
                n += 1
            code.append(S[n])
            if code[0] == i and code[1] == j and code[2] == k:
                ans += 1
print(ans)


### FIXED CODE ###

N = int(input())
S = list(input())
ans = 0
snumber = [str(i) for i in range(10)]
for i in snumber:
    for j in snumber:
        for k in snumber:
            n = 0
            code = []
            while i != S[n] and n < N-3:
                n += 1
            if S[n] != i:
                break
            n += 1
            while j != S[n] and n < N-2:
                n += 1
            if S[n] != j:
                break
            n += 1
            while k != S[n] and n < N-1:
                n += 1
            if S[n] == k:
                ans += 1
print(ans)
### BUGGY CODE ###

S=input()
ans=""
for i in range(len(S)):
    ans=S[i]+ans
Q=int(input())
tmp=0
r=[]
l=[]

for i in range(Q):
    que=input().split()
    if que[0]=='1':
        tmp=1-tmp
    if que[0]=='2':
        if que[1]=='1':
            if tmp==0:
                #S=que[2]+S
                l.append(que[2])
                #ans=ans+que[2]
            else:
                #S=S+que[2]
                r.append(que[2])
                #ans=que[2]+ans

        else:
            if tmp==0:
                #S=S+que[2]
                r.append(que[2])
                #ans=que[2]+ans
            else:
                #S=que[2]+S
                l.append(que[2])
                #ans=ans+que[2]
#print(que)
"""
for i in range(Q):
    if que[i][0]=='1':
        tmp=1-tmp
    if que[i][0]=='2':
        if que[i][1]=='1':
            if tmp==0:
                S=que[i][2]+S
            else:
                S=S+que[i][2]
        else:
            if tmp==0:
                S=S+que[i][2]
            else:
                S=que[i][2]+S
"""
#print(tmp)
for i in range(len(r)):
    S=S+r[i]
    ans=r[i]+ans
for i in range(len(l)):
    S=l[i]+S
    ans=ans+l[i]
if tmp==1:
    print(ans)
    exit()

print(S)

### FIXED CODE ###

from collections import deque
S=deque(input())
ans=""
Q=int(input())
tmp=0
r=[]
l=[]

for i in range(Q):
    que=input().split()
    if que[0]=='1':
        tmp=1-tmp
    if que[0]=='2':
        if que[1]=='1':
            if tmp==0:
                #S=que[2]+S
                #l.append(que[2])
                #ans=ans+que[2]
                S.appendleft(que[2])
            else:
                #S=S+que[2]
                #r.append(que[2])
                #ans=que[2]+ans
                S.append(que[2])
        else:
            if tmp==0:
                #S=S+que[2]
                #r.append(que[2])
                #ans=que[2]+ans
                S.append(que[2])
            else:
                #S=que[2]+S
                #l.append(que[2])
                #ans=ans+que[2]
                S.appendleft(que[2])
#print(que)
"""
for i in range(Q):
    if que[i][0]=='1':
        tmp=1-tmp
    if que[i][0]=='2':
        if que[i][1]=='1':
            if tmp==0:
                S=que[i][2]+S
            else:
                S=S+que[i][2]
        else:
            if tmp==0:
                S=S+que[i][2]
            else:
                S=que[i][2]+S
"""
#print(tmp)
"""
for i in range(len(r)):
    S=S+r[i]
    ans=r[i]+ans
for i in range(len(l)):
    S=l[i]+S
    ans=ans+l[i]
"""
if tmp==1:
    print("".join(reversed(S)))
    exit()

print("".join(S))
### BUGGY CODE ###

# -*- coding: utf-8 -*-
"""
Created on Sun Jul 17 16:53:19 2016

@author: Yasuhiro_2
"""

def checkSorted(A):
    check = True
    a = A[0]
    for e in A:
        if a > e:
            check = False
            break
        else:
            a = e
    return check
        

def insertionSort(A, n, g, cnt):
    for i in range(g, n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j+g] = A[j]
            j -= g
            cnt += 1
        A[j+g] = v
    return [cnt, A]
    
def shellSort(A, n):
    cnt = 0
    m = 0
    G = []          
    while checkSorted(A) == False:
        g = 1
        for i in range(n):
            j = i
            tmp = g
            while j < n:
                if A[i] > A[j]:
                    g = j - i
                j += tmp
        G.append(g)
        m += 1
        A = insertionSort(A, n, g, cnt)
        cnt = A[0]
        A = A[1]
    if m == 0:
        m = 1
        G = [1]
    return [m, G, cnt, A]
            
        
            

if __name__ == '__main__':   
    n = int(input())
    A = []
    for i in range(n):
        A.append(int(input()))
    results = shellSort(A, n)
    m = results[0]
    G = results[1]
    cnt = results[2]
    Ar = results[3]
    print(m)
    gs = ''
    for g in G:
        gs = gs + str(g) + ' '
    print(gs[:-1])
    print(cnt)
    for a in Ar:
        print(a)
    
    

### FIXED CODE ###

# -*- coding: utf-8 -*-
"""
Created on Sun Jul 17 16:53:19 2016

@author: Yasuhiro_2
"""

def checkSorted(A):
    check = True
    a = A[0]
    for e in A:
        if a > e:
            check = False
            break
        else:
            a = e
    return check
        

def insertionSort(A, n, g, cnt):
    for i in range(g, n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j+g] = A[j]
            j -= g
            cnt += 1
        A[j+g] = v
    return [cnt, A]

"""
def shellSort(A, n):
    cnt = 0
    m = 0
    G = []          
    while checkSorted(A) == False:
        g = 1
        for i in range(n):
            j = i
            tmp = g
            while j < n:
                if A[i] > A[j]:
                    g = j - i
                j += tmp
        G.append(g)
        m += 1
        A = insertionSort(A, n, g, cnt)
        cnt = A[0]
        A = A[1]
    if m == 0:
        m = 1
        G = [1]
    return [m, G, cnt, A]
"""
def shellSort(A, n):
    cnt = 0
    m = 1
    G = [1]
    while G[-1] < n:
        G.append(3*G[-1] + 1)
        m += 1
    if m > 1:
        G = G[:-1]
        G.reverse()
        m -= 1
    
    for g in G:
        A = insertionSort(A, n, g, cnt)
        cnt = A[0]
        A = A[1]

    return [m, G, cnt, A]

            

if __name__ == '__main__':   
    n = int(input())
    A = []
    for i in range(n):
        A.append(int(input()))
    results = shellSort(A, n)
    m = results[0]
    G = results[1]
    cnt = results[2]
    Ar = results[3]
    print(m)
    gs = ''
    for g in G:
        gs = gs + str(g) + ' '
    print(gs[:-1])
    print(cnt)
    for a in Ar:
        print(a)
### BUGGY CODE ###

from heapq import nlargest
from itertools import accumulate

n = int(input())
aaa = list(map(int, input().split()))
n2 = 1 << n
mask = n2 - 1

a0 = aaa[0]
dp = [[0, a] for a in aaa]

for j in range(n):
    b = 1 << j
    c = i = mask ^ b
    while i:
        dp[i | b] = nlargest(2, dp[i] + dp[i | b])
        i = (i - 1) & c
    dp[b] = nlargest(2, dp[0] + dp[b])

ans = list(accumulate(map(sum, dp[1:]), func=max))
print(*ans)


### FIXED CODE ###

n = int(input())
aaa = list(map(int, input().split()))
n2 = 1 << n
dp = [[a, 0] for a in aaa]

for j in range(n):
    b = 1 << j
    for i in range(n2):
        if not i & b:
            dpi, dpk = dp[i], dp[i | b]
            if dpk[0] < dpi[0]:
                dpk[1] = max(dpk[0], dpi[1])
                dpk[0] = dpi[0]
            elif dpk[1] < dpi[0]:
                dpk[1] = dpi[0]

ans = []
tmp = 0
for a in dp[1:]:
    tmp = max(tmp, a[0] + a[1])
    ans.append(tmp)
print(*ans)
### BUGGY CODE ###

N = int(input())
 
ans = 1
for val in input().split():
    ans = ans * int(val)

if(ans > 10 **18):
    print(-1)
else:
    print(ans)

### FIXED CODE ###

import sys

N = int(input())

An = [int(_) for _ in input().split()]
An.sort()

ans = 1

for val in An:
    # 0がきたらすぐに抜ける
    if(int(val) == 0):
        print(0)
        sys.exit()
    ans *= val
    # ansが10^18を超えた時点で-1にする
    if(ans > 10 **18):
        print(-1)
        sys.exit()

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

def prime_number(x):
    if x==2 or x==3:
        return True
    else:
        if x%2==0 or x%3==0:
            return False
        else:
            divisor_lst = [1,x]
            for i in range(1,x+1):
                if i not in divisor_lst and x%i==0:
                    return False
                    break
            else:
                return True

n = int(input())

if prime_number(n):
    print(n-1)
else:
    i = 1
    j = n//i
    divisor_lst = []
    while i<=j:
        i += 1
        j = n//i
        if n%i==0:
            divisor_lst.append([i,j])

    n_x = divisor_lst[-1][0]
    n_y = divisor_lst[-1][1]
    print(n_x+n_y-2)

### FIXED CODE ###

n = int(input())

need_lst = []
for i in range(1,int(n**(1/2)+1)):
    if n%i==0:
        need = i+n//i
        need_lst.append(need-2)

print(min(need_lst))
### BUGGY CODE ###

import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, m = map(int, input().split())
    S = list(map(int, input().split()))
    T = list(map(int, input().split()))

    dp = [[0] * (m + 1) for _ in range(n + 1)]
    dp[0][0] = 1
    for i in range(n + 1):
        for j in range(m + 1):
            if i - 1 >= 0:
                dp[i][j] += dp[i - 1][j]
            if j - 1 >= 0:
                dp[i][j] += dp[i][j - 1]
            if i - 1 >= 0 and j - 1 >= 0:
                dp[i][j] -= dp[i - 1][j - 1]
                if S[i - 1] == T[j - 1]:
                    dp[i][j] += dp[i - 1][j - 1]
            dp[i][j] %= mod
    print(dp[-1][-1])


if __name__ == '__main__':
    resolve()


### FIXED CODE ###

import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, m = map(int, input().split())
    S = list(map(int, input().split()))
    T = list(map(int, input().split()))

    dp = [[0] * (m + 1) for _ in range(n + 1)]
    dp[0][0] = 1
    for i in range(n + 1):
        for j in range(m + 1):
            if i - 1 >= 0:
                dp[i][j] += dp[i - 1][j]
            if j - 1 >= 0:
                dp[i][j] += dp[i][j - 1]
            if i - 1 >= 0 and j - 1 >= 0:
                dp[i][j] -= dp[i - 1][j - 1]
                if S[i - 1] == T[j - 1]:
                    dp[i][j] += dp[i - 1][j - 1]
            dp[i][j] %= mod
    print(dp[-1][-1])


if __name__ == '__main__':
    resolve()
### BUGGY CODE ###

N, K = map(int, input().split())
P = list(map(lambda x: (int(x)+1)/2, input().split()))

ans = 0
for i in range(N-K+1):
    a = sum(P[i:i+K])
    ans = a if a > ans else ans
print(ans)


### FIXED CODE ###

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

ans = sum(P[0:K])
tmp = sum(P[0:K])

for i in range(1, N-K+1):
    tmp = tmp - P[i-1] + P[i+K-1]
    ans = max(tmp, ans)
print((ans + K)/2)
### BUGGY CODE ###

import sys
import collections
sys.setrecursionlimit(1000000)
n, q = map(int, input().split())
cost = collections.deque([])
tree = collections.deque([])
level = collections.deque([])
parent = collections.deque([])

for i in range(210000):
    tree.append(collections.deque([]))
level = collections.deque([-1] * 200100)
parent = collections.deque([-1] * 200100)
cost = collections.deque([0] * 200100)

for loop in range(n - 1):
    a, b = map(int, input().split())
    tree[a].append(b)
    tree[b].append(a)

for loop in range(q):
    p, x = map(int, input().split())
    cost[p] += x

def make_level(index, lev, pp):
    level[index] = lev
    parent[index] = pp
    for next in tree[index]:
        if level[next] != -1:
            continue
        cost[next] += cost[index]
        make_level(next, lev + 1, index)

make_level(1, 0, -1)

print(" ".join(list(map(str, cost))[1:n+1]))

### FIXED CODE ###

edge = []
n, q = map(int, input().split())
for _ in range(n+100):
    edge.append([])
for _ in range(n-1):
    a,b = map(int, input().split())
    edge[a].append(b)
    edge[b].append(a)
res = [0] * (n+1)
cost = [0] * (n+1)
for _ in range(q):
    a,b = map(int, input().split())
    res[a] += b

import collections
q = collections.deque([[1, 0]])
used = [False] * (n+1)
while len(q) > 0:
    #print(q)
    curnode, cost = q.popleft()
    res[curnode] += cost
    used[curnode] = True
    for i in range(len(edge[curnode])):
        nnext = edge[curnode][i]
        if used[nnext] is True:
            continue
        else:
            q.append([nnext, res[curnode]])
res=res[1:]
print(" ".join(list(map(str, res))))
### BUGGY CODE ###

L,R=map(int,input().split())
A=[]
for i in range(L,R+1):
  for j in range(i+1,R+1):
    A.append((i*j)%2019)
print(min(A))

### FIXED CODE ###

L,R=map(int,input().split())
A=[]
R=min(R,L+2019)
for i in range(L,R+1):
  for j in range(i+1,R+1):
    A.append((i*j)%2019)
print(min(A))
### BUGGY CODE ###

import sys
input = sys.stdin.readline
import math
sys.setrecursionlimit(20000)
INT_MAX = 2**31 - 1
def update(tree,x,y,N):
    # offset
    #x += int(N/2)
    x += N - 1
    tree[x] = y
    # segment tree no update suru
    while True:
        if(x <= 0):
            break
        x = math.floor((x - 1)/2)
        left = x*2+1
        right = x*2+2
        tree[x] = min(tree[left],tree[right])

def find(tree,x,y,k,l,r):

    if (r <= x or y <= l):
        return INT_MAX - 1
    # sita wo mite itte mitukatta toki (intersect)
    if ( x <= l and r <= y):
        return tree[k]
    # sita ni sagaru
    v_left = find(tree, x, y, k*2 + 1, l, int((l+r)/2))
    v_right = find(tree, x, y, k*2 + 2, int((l+r)/2), r)
    return min(v_left, v_right)

if __name__ == '__main__':
    _N,k = map(int, input().split())
    arr = list(map(int,input().split()))
    N = 1
    res = []
    while True:
        if(N >= _N):
            break
        N *= 2
    #N = 2*N - 1 - 1
    if not (N == 1):
        A_bin_tree = [INT_MAX]*(2*N - 1)
    else:
        A_bin_tree = [INT_MAX]
    for i in range(k):
        update(A_bin_tree,i,arr[i],N)

    for i in range(_N-k):
        res.append(find(A_bin_tree,i,i+k,0,0,N))
        update(A_bin_tree,i+k,arr[i+k],N)

    res.append(find(A_bin_tree,_N-k,_N,0,0,N))
    print(" ".join([str(r) for r in res]))



### FIXED CODE ###

INTMAX = (1<<31) - 1

def ans():
    for i in range(k):
        x = i + OFS
        A[x] = arr[i]
        while True:
            if(x <= 0):
                break
            x = (x - 1)//2
            l = A[x*2+1]
            r = A[x*2+2]
            A[x] = l if l < r else r#min(tree[left],tree[right])
    res = []
    c = 0
    for i in range(_N-k):
        res.append(A[0])
        x = c + OFS
        A[x] = arr[i+k]
        while True:
            if(x <= 0):
                break
            x = (x - 1)//2
            l = A[x*2+1]
            r = A[x*2+2]
            A[x] = l if l < r else r
        c += 1
        if(c == k):
            c = 0
    res.append(A[0])
    print(*res)

_N,k = map(int, input().split())
*arr, = map(int,input().split())
if(k==1):
    print(*arr)
else:
    N = 2**(_N-1).bit_length()
    A = [INTMAX]*(2*N)
    OFS = N - 1
    ans()
### BUGGY CODE ###

def band(i, j, x, y):
  res = 0
  if i <= x and y <= j:#p1
    res += x - i
    res += 1
    res += j - y
  elif i <= x and j <= x:#p2
    res += j - i
  elif y <= i and y <= j:#p3
    res += j - i
  else:
    if i <= x and x <= j and j <= y:#p4
      res += band(i, x, x, y)
      if j - x <= y - j + 1:
        res += j - x
      else:
        res += y - j + 1
    elif x <= i and i <= y and y <= j:#p5
      if y - i <= i - x + 1:
        res += y - i
      else:
        res += i - x + 1
      res += band(y, j, x, y)
    elif x <= i and i <= y and x <= j and j <= y:#p6
      if j - i <= i - x + y - j + 1:
        res += j - i
      else:
        res += i - x + y - j + 1
  return res

d = {}
n, x, y = list(map(int,input().split()))
for i in range(1, n+1):
  for j in range(1, n+1):
    if i < j:
      #print(str(i)+','+str(j)+'  '+str(band(i, j, x, y)))
      if band(i, j, x, y) in d:
        d[band(i, j, x, y)] += 1
      else:
        d[band(i, j, x, y)] = 1
for i in range(1,n):
  if i in d:
    print(d[i])
  else:
    print('0')

### FIXED CODE ###

n, x, y = list(map(int,input().split()))
d = [0 for i in range(n-1)] 
for i in range(1,n+1):
  for j in range(i+1,n+1):
    d[min([j-i, abs(x-i) + 1 + abs(j-y), abs(y-i) + 1 + abs(j-x)])-1] += 1

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

n,m = map(int,input().split())
l = []
for i in range(m):
    a,b = map(int,input().split())
    c = 0
    for j in map(int,input().split()):
        c += (1<<(j-1))
    l.append((c,a))

dp = dict()
tmp = [(0,0)]
while tmp != []:
    tmp2 = []
    for i in tmp:
        for j in l:
            if j[0] | i[0] != i[0]:
                ctmp = (j[0] | i[0] ,i[1] + j[1])
                if dp.get(ctmp[0],-1) == -1:
                    dp[ctmp[0]] = ctmp[1]
                    if ctmp[0] != 2**n - 1:
                        tmp2.append(ctmp)
                else:
                    if dp[ctmp[0]] > ctmp[1]:
                        dp[ctmp[0]] = ctmp[1]
                        if ctmp[0] != 2**n - 1:
                            tmp2.append(ctmp)                
    tmp = tmp2

print(dp.get(2**n-1,-1))


### FIXED CODE ###

n,m = map(int,input().split())
l = []
for i in range(m):
    a,b = map(int,input().split())
    c = 0
    for j in map(int,input().split()):
        c += (1<<(j-1))
    l.append((c,a))
dp = {0:0}
for i in l:
    items = list(dp.items())
    for j in items:
        ij = (i[0] | j[0], i[1] + j[1])
        if not dp.get(ij[0]):
            dp[ij[0]] = ij[1]
        else:
            if dp[ij[0]] > ij[1]:
                dp[ij[0]] = ij[1]

print(dp.get(2**n-1,-1))
### BUGGY CODE ###

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

count = 0
while True:
    if len(p) == 1:
        break
    num = p.pop(-1)
    if num <= min(p):
        count += 1
print(count+1)


### FIXED CODE ###

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

count = 0

m = p[0]
for i in range(len(p)):
    if m >= p[i]:
        count += 1
        m = p[i]

print(count)
### BUGGY CODE ###

import math
from functools import reduce
import itertools

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

K=int(input())

l = [i for i in range(1,K+1)]

temp_sum=0
for j in itertools.product(l, repeat=3):
    temp_sum+=gcd_list(list(j))

print(temp_sum)

### FIXED CODE ###

import math
from functools import reduce
import itertools
import numpy as np

K = int(input())



ans = 0
for i in range(1, K + 1):
    for j in range(i, K + 1):
        for k in range(j, K + 1):
            if i == j and j == k:
                dup_num = 1
            elif i == j or j == k:
                dup_num = 3
            else:
                dup_num = 6
            ans += math.gcd(math.gcd(i, j), k) * dup_num

print(ans)