Harryxun/stf_run huggingface dataset:
str = input()
minDistance = N
black = "#"
white = "."

for i in range(N):
    distance = 0
    loopnum = 0
    while (distance < minDistance and loopnum < N):
        for j in range(0, i):
            if str[j] == black:
                distance += 1
                loopnum += 1
            else:
                loopnum += 1
        for k in range(i, N - 1):
            if str[k] == white:
                distance += 1
                loopnum += 1
            else:
                loopnum += 1
    print("{}".format(distance))
    if (loopnum >= N-1):
        minDistance = distance

print("{}".format(minDistance))

### FIXED CODE ###

# 今のままだと駄目
"""
ある境目を考える。境目より左が全て白、境目より右が全て黒でなくてはいけない。
ゆえに、境目より左の黒の数と境目より右の白の数を数えれば、その境目における「変更が必要な石の数」がわかる。
よって、境目を端から端まで動かしてその中で最小の「変更が必要な石の数」を求めればよい。
"""
N = int(input())
str = input()
minDistance = 0

black = "#"
white = "."
leftblack = 0
rightwhite = 0

for i in range(N):
    if str[i] == white:
        rightwhite += 1

minDistance += rightwhite

for j in range(0, N):
    if str[j] == black:
        leftblack += 1
    else:
        rightwhite -= 1
    if leftblack + rightwhite < minDistance:
        minDistance = leftblack+rightwhite

print("{}".format(minDistance))
N,A,B=map(int(),input().split())
K=A*int(N/(A+B))
amari=N%(A+B)
i=1
while ((amari-i)>0):
  i=i+1
K=K+i
  

### FIXED CODE ###

N,A,B=map(int,input().split())
K=A*int(N/(A+B))
amari=N%(A+B)
if (amari>=A):
  i=A
elif (amari<A):
  i=amari
K=K+i
print(K)
ソースコード
N=int(input())
T, A = list(map(int, input().split()))
H = list(map(int, input().split()))
temp = [abs(1000*T - 6*x - 1000*A) for x in H]
m = min(temp)
i = temp.index(m)
print(i+1)

### FIXED CODE ###

N=int(input())
T, A = list(map(int, input().split()))
H = list(map(int, input().split()))
temp = [abs(1000*T - 6*x - 1000*A) for x in H]
m = min(temp)
i = temp.index(m)
print(i+1)
x=int(input(''))
if x%1000=0:
  print(0)
else:
  print(1000-x%1000)
  

### FIXED CODE ###

x=int(input(''))
if x%1000==0:
  print(0)
else:
  print(1000-x%1000)
import math


def main():

    mod = 1000000007
    N = int(input())

    A = [0]
    B = [0]

    for n in range(N):
        a, b = map(int, input().split())
        A.append(a)
        B.append(b)

    calc = dict()

    for i in range(1, N + 1):
        r = math.gcd(A[i], B[i])
        m = 1
        if A[i] * B[i] < 0:
            m = -1

        k1 = (m * abs(A[i] // r), abs(B[i] // r))
        k2 = (-m * abs(B[i] // r), abs(A[i] // r))
        if calc.get(k1):
            calc[k1][0] += 1
        elif not calc.get(k2):
            calc[k1] = [1, 0]

    for i in range(1, N + 1):
        r = math.gcd(A[i], B[i])
        m = 1
        if A[i] * B[i] < 0:
            m = -1

        k2 = (-m * abs(B[i] // r), abs(A[i] // r))
        if calc.get(k2):
            calc[k2][1] += 1

    count = 0
    for k, v in calc.items():
        if not v[0] * v[1] == 0:
            count += v[0] + v[1]

    ans = pow(2, N - count, mod)
    for k, v in calc.items():
        if not v[0] * v[1] == 0:
            comb = (pow(2, v[0]) + pow(2, v[1]) - 1)
            ans = (ans * comb) % mod

    print(ans - 1)


if __name__ == '__main__':
    main()


### FIXED CODE ###

import math


def main():

    mod = 1000000007
    N = int(input())

    A = [0]
    B = [0]

    for n in range(N):
        a, b = map(int, input().split())
        A.append(a)
        B.append(b)

    calc = dict()
    non_count = 0

    for i in range(1, N + 1):

        if A[i] == 0 and B[i] == 0:
            non_count += 1
        elif A[i] == 0:
            k = (0, 1)
            if calc.get(k):
                calc[k][0] += 1
            else:
                calc[k] = [1, 0]
        elif B[i] == 0:
            k = (0, 1)
            if calc.get(k):
                calc[k][1] += 1
            else:
                calc[k] = [0, 1]
        else:
            r = math.gcd(A[i], B[i])
            m = 1
            if A[i] * B[i] < 0:
                m = -1
            k1 = (m * abs(A[i] // r), abs(B[i] // r))
            k2 = (-m * abs(B[i] // r), abs(A[i] // r))
            if calc.get(k1):
                calc[k1][0] += 1
            elif not calc.get(k2):
                calc[k1] = [1, 0]
            else:
                calc[k2][1] += 1

    N = N - non_count

    count = 0
    for k, v in calc.items():
        if not v[0] * v[1] == 0:
            count += v[0] + v[1]

    ans = pow(2, N - count, mod)
    for k, v in calc.items():
        if not v[0] * v[1] == 0:
            comb = (pow(2, v[0]) + pow(2, v[1]) - 1)
            ans = (ans * comb) % mod

    print((ans - 1 + non_count) % mod)


if __name__ == '__main__':
    main()
s = input()
q = int(input())
appendix = [[], []]
reverse = False
for _ in range(q):
  query = input().split()
  if query[0] == '1':
    reverse ^= True
  else:
    f = bool(int(query[1]) - 1)
    appendix[int(f ^ reverse)].append(query[2])
print(''.join(appendix[int(reverse)][::-1]) + s + ''.join(appendix[int(not reverse)])

### FIXED CODE ###

s = input()
q = int(input())
appendix = [[], []]
reverse = False
for _ in range(q):
  query = input().split()
  if query[0] == '1':
    reverse ^= True
  else:
    f = bool(int(query[1]) - 1)
    appendix[int(f ^ reverse)].append(query[2])
if reverse:
  print(''.join(appendix[1][::-1]) + s[::-1] + ''.join(appendix[0]))
else:
  print(''.join(appendix[0][::-1]) + s + ''.join(appendix[1]))
# utf-8:
import numpy as np


def main():
    n = int(raw_input())
    for i in range(n):
        sqrt = np.sqrt(n - i +1)
        if sqrt - int(sqrt) == 0:
            print(n - i)
            break


if __name__ == '__main__':
    main()


### FIXED CODE ###

# utf-8:
import math as np


def main():
    n = int(raw_input())
    a = int(np.sqrt(n))
    print(a * a)


if __name__ == '__main__':
    main()
N=input()
S=str(input())
K=int(input())
Target=S[K]
Ans=""
for i in range(0,len(S),1):
  if S[i]==S[K]:
    Ans+=str(S[i])
  elif S[i]!=S[K]:
    Ans+="*"

print(Ans)


### FIXED CODE ###

N=input()
S=str(input())
K=int(input())
Ans=""
for i in range(0,len(S),1):
  if S[i]==S[K-1]:
    Ans+=str(S[i])
  elif S[i]!=S[K-1]:
    Ans+="*"

print(Ans)
# -*- coding: utf-8 -*-
a,b = list(map(int,input().split()))
#最大公約数
import fractions
_gcd = fractions.gcd(a, b)

def primes(n):
    #2~nまでの素数を列挙
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]
pms = primes(_gcd) #sqrt(_gcd) までの素数を列挙
ret = 1
for i in pms:
    if _gcd%i==0:
        ret+=1
print(ret)

### FIXED CODE ###

# -*- coding: utf-8 -*-
a,b = list(map(int,input().split()))
#最大公約数

#最大公約数
import fractions
abgcd = fractions.gcd(a, b)

def prime_factorize(N):
    #素因数分解
    from collections import defaultdict
    factorize = defaultdict(int)
    while N%2 == 0:
        factorize[2]+=1
        N //= 2
    i=1
    while i*i <=N:
        i += 2
        if N%i: continue
        while N%i == 0:
            factorize[i] += 1
            N //= i
    if N!=1:factorize[N]=1
    return factorize

print(len(prime_factorize(abgcd).keys())+1)
from bisect import bisect_left
import string 

dic={c:[] for c in string.ascii_lowercase}
N=int(input())
S=list(input())
Q=int(input())
for i in range(len(S)):
  dic[S[i]].append(i+1)
  
for i in range(Q):
  a,b,c=map(str,input().split())
  if a=='1':
    if S[int(b)-1]==c:
      continue
    b=int(b)
    f=S[b-1]
    d=bisect_left(dic[f],b)
    e=bisect_left(dic[c],b)
    dic[f].pop(d)
    dic[c].insert(e,b)
  else:
    ans=0
    b,c=int(b),int(c)
    for j in string.ascii_lowercase:
      d=bisect_left(dic[j],b)
      if d<len(dic[j]):
        if dic[j][d]<=c:
          ans+=1
    print(ans)

### FIXED CODE ###

from bisect import bisect_left,bisect_right
import string 

dic = {c:[] for c in string.ascii_lowercase}

n = int(input())
s = list(input())
q = int(input())

for i,c in enumerate(s,start=1):
  dic[c].append(i)
  
for i in range(q):
  p,l,r = map(str,input().split())
  if p =='1':
    j = int(l)
    if r == s[j-1]:
      continue
    c = s[j-1]    
    dic[c].pop(bisect_left(dic[c],j))
    dic[r].insert(bisect_left(dic[r],j),j)
    s[j-1] = r
  else:
    ans = 0
    l = int(l)
    r = int(r)
    for c in string.ascii_lowercase:
      pl = bisect_left(dic[c],l)
      if pl < len(dic[c]):
        if dic[c][pl] <= r:
          ans += 1
    print(ans)
def comb(r):
    if r==0 or r==n:
        return 1
    if r==1 or r==n-1:
        return n
    if inv_fact_list[n-r]!=None:
        invnr=inv_fact_list[n-r]
    else:
        m=fact_list[n-r]
        invnr=1
        for i in range(30):
            if i!=23 and i!=26:
                invnr=(invnr*m)%998244353
            m=(m**2)%998244353
        inv_fact_list[n-r]=invnr
    if inv_fact_list[r]!=None:
        invr=inv_fact_list[r]
    else:
        m=fact_list[r]
        invr=1
        for i in range(30):
            if i!=23 and i!=26:
                invr=(invr*m)%998244353
            m=(m**2)%998244353
        inv_fact_list[r]=invr
    return (((fact_list[n]*invnr))*invr)%998244353

for i in range(1,300001):
    fact_list[i]=(fact_list[i-1]*i)%998244353

s=input().split()
n,a,b,k=int(s[0]),int(s[1]),int(s[2]),int(s[3])
res=0
if b>a:
    a,b=b,a
for i in range(n):
    if k-a*i<0:
        break
    if (k-a*i)%b==0 and 0<=(k-a*i)//b<=n:
        res=(res+comb(i)*comb((k-a*i)//b))%998244353
print(res)


### FIXED CODE ###

fact_list=[None]*300001
inv_fact_list=[None]*300001
fact_list[0]=1
inv_fact_list[0]=1
"""
def inv(n):
    if inv_fact_list[n]!=None:
        return inv_fact_list[n]
    m=fact_list[n]
    s=1
    for i in range(30):
        if i!=23 and i!=26:
            s=(s*m)%998244353
        m=(m**2)%998244353
    inv_fact_list[n]=s
    return s
def enc(n):
    if n==0:
        return "("
    s=""
    while n>0:
        s+=chr(n%86+40)
        n//=86
    return s
 
def dec(s):
    n=0
    for i in range(len(s)):
        n+=(86**i)*(ord(s[i])-40)
    return n
"""
def comb(n,r):
    if r==0 or r==n:
        return 1
    if r==1 or r==n-1:
        return n
    if inv_fact_list[n-r]!=None:
        invnr=inv_fact_list[n-r]
    else:
        m=fact_list[n-r]
        invnr=1
        for i in range(30):
            if i!=23 and i!=26:
                invnr=(invnr*m)%998244353
            m=(m**2)%998244353
        inv_fact_list[n-r]=invnr
    if inv_fact_list[r]!=None:
        invr=inv_fact_list[r]
    else:
        m=fact_list[r]
        invr=1
        for i in range(30):
            if i!=23 and i!=26:
                invr=(invr*m)%998244353
            m=(m**2)%998244353
        inv_fact_list[r]=invr
    return (((fact_list[n]*invnr)%998244353)*invr)%998244353
 
for i in range(1,300001):
    fact_list[i]=(fact_list[i-1]*i)%998244353
 
s=input().split()
n,a,b,k=int(s[0]),int(s[1]),int(s[2]),int(s[3])
res=0
for i in range(n+1):
    if k-a*i<0:
        break
    if (k-a*i)%b==0 and 0<=(k-a*i)//b<=n:
        res=(res+comb(n,i)*comb(n,(k-a*i)//b))%998244353
print(res)
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 998244353
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n = int(input())
# XD = [tuple(map(int,input().split())) for i in range(n)]
XD = [(-10**10,inf)]
for i in range(n):
  x,d = map(int,input().split())
  XD.append((x,d))
XD.sort()
visited = [0] * (n+1)
def dfs(node):
  visited[node] = 1
  res = 1
  for i in range(node+1,n+1):
    if XD[i][0] < XD[node][0] + XD[node][1]:
      if visited[i]:continue
      res *= dfs(i)
      res %= mod
    else: break
  # print(node,res+1)
  return res + 1
print((dfs(0)-1)%mod)
# print(visited)
# print(XD)
# dfs(1)

### FIXED CODE ###

#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 998244353
mans = inf ;ans = 0 ;count = 0 ;pro = 1
sys.setrecursionlimit(10**6)

n = int(input())
XD = [(-10**10,inf)]
for i in range(n):
  x,d = map(int,input().split())
  XD.append((x,d))
XD.sort()
visited = [0] * (n+1)
def dfs(node):
  visited[node] = 1
  res = 1
  i = node + 1
  while i < n+1:
    if XD[i][0] < XD[node][0] + XD[node][1]:
      if visited[i]:continue
      pro,i = dfs(i)
      res *= pro
      res %= mod
    else: break
  # print(node,res+1)
  return res + 1 , i
print((dfs(0)[0]-1)%mod)
# print(visited)
# print(XD)
# dfs(1)
import numpy as np
a,b,c,d=map(int, input().split())
 
while True:
    c=c-b
    if c<=0:
  		print("Yes")
  		exit()
	a=a-d
  	if a<=0:
  		print("No")
  		exit()

### FIXED CODE ###


a, b, c, d = map( int, input().split() )
#print( a, b, c, d )
 
for i in range( 200 ):
    c = c - b
    if c <= 0:
        print( "Yes" )
        exit()
 
    a = a - d
    if a <= 0:
        print( "No" )
        exit()
from fractions import gcd
# def lcm(a,b): return a*b//gcd(a,b)

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

n = int(input())

ans = 1
for i in range(n):
    t = int(input())
    ans = lcm(t, ans)
print(ans)

### FIXED CODE ###

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

n = int(input())

ans = 1
for i in range(n):
    t = int(input())
    ans = lcm(t, ans)
print(ans)
import math
pi = math.pi

r = int(input())
S = r ** 2 * pi
syu = 2 * pi * r

print(str("{0:.6f}".format(S)) + ' ' + str("{0:.6f}".format(syu)))

### FIXED CODE ###

import math
pi = math.pi

r = float(input())
S = r ** 2 * pi
syu = 2 * pi * r

print(str("{0:.6f}".format(S)) + ' ' + str("{0:.6f}".format(syu)))
# -*- coding: utf-8 -*-
import sys
from collections import deque,defaultdict

H,W,K=map(int, sys.stdin.readline().split())
ichigo=[]
tate_ichigo=set()
cnt=0
h_visit=[0 for h in range(H)]  #縦軸にイチゴがない箇所は0、ある箇所は1
L=[ [] for h in range(H) ]
for h in range(H):
    s=sys.stdin.readline().strip()
    for w,x in enumerate(s):
        if x==".":
            L[h].append(0)
        elif x=="#":
            cnt+=1
            L[h].append(cnt)
            ichigo.append((h,w))
            h_visit[h]=1
            tate_ichigo.add(h)

D=(1,-1)
for h,w in ichigo:
    num=L[h][w]
    Visit=defaultdict(lambda: 0) #訪問した頂点
    q=deque()
    q.append((h,w))
    Visit[(h,w)]=1

    while q:
        h,w=q.popleft()
        for dw in D:
            if 0<=w+dw<W:   #マスの横にはみださないように
                if L[h][w+dw]==0 and Visit[(h,w+dw)]==0:
                    Visit[(h,w+dw)]=1	#訪問済みVisitに1をセットする。4行上のpopleftの直後でVisitをセットすると同じ頂点がqに入り、TLEする
                    L[h][w+dw]=num
                    q.append((h,w+dw))

#1行全部0の行を、値ありの行で埋めるためのdfs
def dfs(h):
    if h==0 or h==H-1: return
    for dh in D:
        if h_visit[h+dh]==0:
            L[h+dh]=L[h]
            dfs(h+dh)

for h in tate_ichigo:
    dfs(h)

for l in L:
    for x in l:
        print x,
    print


### FIXED CODE ###

# -*- coding: utf-8 -*-
import sys
from collections import deque,defaultdict
sys.setrecursionlimit(10**5)

H,W,K=map(int, sys.stdin.readline().split())
ichigo=[]
cnt=0
h_visit=[0 for h in range(H)]  #縦軸にイチゴがない箇所は0、ある箇所は1

L=[ [] for h in range(H) ]
for h in range(H):
    s=sys.stdin.readline().strip()
    for w,x in enumerate(s):
        if x==".":
            L[h].append(0)
        elif x=="#":
            cnt+=1
            L[h].append(cnt)
            ichigo.append((h,w))
            h_visit[h]=1


D=(1,-1)

def yoko_dfs(h,w):  #縦座標、横座標
    for dw in D:
        if 0<=w+dw<=W-1 and L[h][w+dw]==0:
            L[h][w+dw]=L[h][w]
            yoko_dfs(h,w+dw)
    return

for h,w in ichigo:
    yoko_dfs(h,w)


def tate_dfs(h):  #縦座標
    for dh in D:
        if 0<=h+dh<=H-1:
            if h_visit[h+dh]==1: continue
            h_visit[h+dh]=1 #訪問済みにする
            L[h+dh]=L[h]
            tate_dfs(h+dh)

for h,w in ichigo:
    tate_dfs(h)

for l in L:
    for x in l:
        print x,
    print
N, M, X, Y = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
if max(x) < min(y):
    for i in range(max(x),min(y)+1):
        if max(x) < i <= min(y):
             print("No War")
             exit(1)
print("War")
             


### FIXED CODE ###

N, M, X, Y = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
for i in range(X, Y+1):
  if X < i <= Y and max(x) < i <= min(y):
    print("No War")
    exit()
print("War")
N=int(input())
a=map(int, input().split())
print("Four" if "Y" in a else "Three")


### FIXED CODE ###

N=int(input())
a=input().split()
print("Four" if "Y" in a else "Three")
n=int(input())
a=list(int,input())
sum=0
c=0
for i in range(n):
  if a[i]<0:
    a[i]=a[i]*-1:
      c=c+1
  sum=sum+a[i]
  if c%2==0:
    print(sum)
  else:
    print(sum-min(a)*2)

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
sum=0
c=0
for i in range(n):
  if a[i]<0:
    a[i]=a[i]*-1
    c=c+1
  sum=sum+a[i]
if c%2==0:
  print(sum)
else:
  print(sum-min(a)*2)
abcd = int(input())
A,B,C,D = abcd[0],abcd[1],abcd[2]abcd[3]
if A + B + C + D == 7:
  print('{}+{}+{}+{}=7'.format(A, B, C, D))
elif A + B + C - D == 7:
  print('{}+{}+{}-{}=7'.format(A, B, C, D))
elif A + B - C + D == 7:
  print('{}+{}-{}+{}=7'.format(A, B, C, D))
elif A + B - C - D == 7:
  print('{}+{}-{}-{}=7'.format(A, B, C, D))
elif A - B + C + D == 7:
  print('{}-{}+{}+{}=7'.format(A, B, C, D))
elif A - B + C - D == 7:
  print('{}-{}+{}-{}=7'.format(A, B, C, D))
elif A - B - C + D == 7:
  print('{}-{}-{}+{}=7'.format(A, B, C, D))
else:
  print('{}-{}-{}-{}=7'.format(A, B, C, D))


### FIXED CODE ###

abcd = input()
A,B,C,D = int(abcd[0]),int(abcd[1]),int(abcd[2]),int(abcd[3])    
if A + B + C + D == 7:
  print('{}+{}+{}+{}=7'.format(A, B, C, D))
elif A + B + C - D == 7:
  print('{}+{}+{}-{}=7'.format(A, B, C, D))
elif A + B - C + D == 7:
  print('{}+{}-{}+{}=7'.format(A, B, C, D))
elif A + B - C - D == 7:
  print('{}+{}-{}-{}=7'.format(A, B, C, D))
elif A - B + C + D == 7:
  print('{}-{}+{}+{}=7'.format(A, B, C, D))
elif A - B + C - D == 7:
  print('{}-{}+{}-{}=7'.format(A, B, C, D))
elif A - B - C + D == 7:
  print('{}-{}-{}+{}=7'.format(A, B, C, D))
else:
  print('{}-{}-{}-{}=7'.format(A, B, C, D))
a = int(input())
b = int(input())
h = int(input())

print(a*b*h/2)a = int(input())
b = int(input())
h = int(input())

print((a+b)*h/2)

### FIXED CODE ###

a = int(input())
b = int(input())
h = int(input())

print((a+b)*h//2)
s = input()

dict = {
  'SUN':7
  'MON':6
  'TUE':5
  'WED':4
  'THU':3
  'FRI':2
  'SAT':1
}

print(dict[s])

### FIXED CODE ###

s = input()

dict = {
    'SUN': 7,
    'MON': 6,
    'TUE': 5,
    'WED': 4,
    'THU': 3,
    'FRI': 2,
    'SAT': 1
}

print(dict[s])
N,P=map(int,input().split())
if N==1:
    print(P)
elif P==1:
    print(1)
else:
    ans=0
    for i in range(2,10**12+1):
        p=pow(i,N)
        if p<=P and P%p==0:
            ans=i
        elif p>P:
            break
print(ans)


### FIXED CODE ###

def hoge(p):
    ret = {}
    pp = 2
    while pp * pp <= p:
        while p % pp == 0:
            ret[pp] = ret[pp]+1 if pp in ret else 1
            p //= pp
        pp += 1
    if p != 1: ret[p] = 1
    return ret

N,P=map(int,input().split())
if N==1:
    print(P)
elif P==1:
    print(1)
else:
    ans = 1
    ret = hoge(P)
    for p,e in ret.items():
        ans *= max(1, p**(e//N))
    print(ans)
from math import factorial
from sympy import divisors

N = factorial(int(input()))

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

print(len(make_divisors(N)))

### FIXED CODE ###

from math import factorial
N = factorial(int(input()))
mod = 10**9 + 7
ans = 1
i = 2

while i*i <= N:
    cnt = 1
    while N%i == 0:
        cnt += 1
        N //= i
    ans *= cnt
    i += 1

if N != 1:
    ans *= 2
print(int(ans%mod))
class FixedSizeQueue:
    def __init__(self, n, init_val):
        self.queue = [init_val] * n #根にサイズを負の値で格納する。
        self.l = 0
        self.r = 0
        self.n = n
        self.size = 0
    def append(self, val):
        if self.size == self.n:
            raise IndexError('fixed-size-queue is full')
        self.queue[self.r] = val
        self.r = (self.r + 1) % self.n
        self.size += 1

    def popleft(self):
        if self.size == 0:
            raise IndexError('dequeue from empty queue')
        val = self.queue[self.l]
        self.l = (self.l + 1) % self.n
        self.size -= 1
        return val

    def pop(self):
        if self.size == 0:
            raise IndexError('dequeue from empty queue')
        val = self.queue[self.r - 1]
        self.r = (self.r - 1) % self.n
        self.size -= 1
        return val
    
    def get_size(self):
        return self.size
    
    def __bool__(self):
        return self.size != 0

def fast_bellman_ford(n, s, graph, edge_n, init_val): #どう？
    d = [init_val] * n
    d[s] = 0
    q = FixedSizeQueue(edge_n, 0)
    q.append(s)
    for _ in range(n):
        m = q.get_size()
        for _ in range(m):
            vf = q.popleft()
            for vt, w in graph[vf]:
                if d[vt] > d[vf] + w:
                    d[vt] = d[vf] + w
                    q.append(vt)
        if not q:
            break
    if q: #閉路の存在
        minus_inf = -float('inf')
        while q:
            m = q.get_size()
            for _ in range(m):
                vf = q.popleft()
                for vt, w in graph[vf]:
                    if d[vt] > d[vf] + w:
                        d[vt] = minus_inf
                        q.append(vt)
    return d

n, m = map(int, input().split())
graph = [[] for _ in range(n)]
for i in range(m):
    a, b, w = map(int, input().split())
    graph[a-1].append((b-1, -w))
d = fast_bellman_ford(n, 0, graph, 2 * m, float('inf'))
print(-d[-1] if d[-1] != -float('inf') else 'inf')


### FIXED CODE ###

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

edges = []
for i in range(m):
    a, b, w = map(int, input().split())
    edges.append((a-1, b-1, w))

init_val = -10 ** 9 * 1000
d = [init_val] * n
d[0] = 0
for _ in range(n):
    updated = False
    for a, b, w in edges:
        if d[a] != init_val and d[b] < d[a] + w:
            d[b] = d[a] + w
            updated = True
    if not updated:
        break
if updated: #閉路の存在
     for a, b, w in edges:
        if d[a] != init_val and d[b] < d[a] + w:
            d[b] = d[a] + w
            if b == n - 1:
                print('inf')
                quit()
print(d[n-1])
N, K = map(int, input().split(" "))
flag = [1 for i in range(N)]
for i in range(K):
  input()
  for j in map(int,input().split(" ")):
    flag[j-1] = 0
sum(flag)


### FIXED CODE ###

s = input()
if s == 'ABC':
    print('ARC')
else:
    print('ABC')
n, ma, mb = map(int, f.readline().split())
a, b, c = [], [], []
for _ in range(n):
    at, bt, ct = map(int, f.readline().split())
    a.append(at)
    b.append(bt)
    c.append(ct)
    
dp = [[float('inf') for _ in range(n*mb + 1)] for _ in range(n*ma + 1)]
dp[0][0] = 0
used = [[0, 0]]

for i in range(n):
    add_used = []
    for at, bt in used:
        if at+a[i] <= n and bt+b[i] <= n:
            if dp[at+a[i]][bt+b[i]] == float('inf'):
                add_used.append([at+a[i], bt+b[i]])
            
            dp[at+a[i]][bt+b[i]] = min(dp[at][bt]+c[i], dp[at+a[i]][bt+b[i]])
        
    used += add_used

if dp[-1][-1] == float('inf'):
    print(-1)
else :
    print(dp[-1][-1])

### FIXED CODE ###

import copy
n, ma, mb = map(int, input().split())
a, b, c = [0]*n, [0]*n, [0]*n
for i in range(n):
    a[i], b[i], c[i] = map(int, input().split())
   
dp = [[float('inf')] * (sum(b)+1) for _ in range(sum(a)+1)]
dp[0][0] = 0
step = set([(0, 0)])

for i in range(n):
    ai, bi = a[i], b[i]

    s = step.copy()
    tempdp = copy.deepcopy(dp)
    for si in s: 
        if dp[si[0]+ai][si[1]+bi] > dp[si[0]][si[1]] + c[i]:
            tempdp[si[0]+ai][si[1]+bi] = dp[si[0]][si[1]] + c[i]
            step.add((si[0]+ai, si[1]+bi))
        
    dp = tempdp[:]
#28 20

ans = float('inf')
for i in range(1, min(sum(a)//ma, sum(b)//mb)+1):
    ans = min(ans, dp[ma*i][mb*i])
    
if ans == float('inf'): print(-1)
else : print(ans)