Harryxun/stf_run huggingface dataset:
N = int(input())
S = input()
list_S = list(S)
N1 = 0
X = list_S.count('.')

if num == X:
    print('0')
else:
    for N in list_S:
        if list_S[N1] == '.':
            N1 += 1
        else:
            list_SS = list_S[N1:]
            X1 = list_SS.count('.')
            print(X1)
            break

### FIXED CODE ###

N = int(input())
S = input()                                                      
list_S = list(S)
N1 = 0
list_X =[]
X = list_S.count('.')
list_X.append(X)
    
for color in list_S:
    if list_S[N1] == '.':
        X -= 1
        list_X.append(X)
        N1 +=1
    else:
        X += 1
        list_X.append(X)
        N1 +=1

X = list_S.count('#') 
list_X.append(X)

X_MIN = min(list_X)
print(X_MIN)
n, m = list(map(int, input().split()))
def cutterl(l, lst) :
    if lst == [] :
        return []
    elif lst[0] < l :
        return cutterl(l, lst[1:])
    else :
        return lst
def cutterr(r, lst) :
    if lst == [] :
        return []
    elif r < lst[-1] :
        return cutterr(r, lst[:-1])
    else :
        return lst
nlist = list(map(lambda x : x + 1, range(n)))
llist=[]
rlist=[]
for i in range(m) :
    l, r = list(map(int, input().split()))
    llist.append(l)
    rlist.append(r)
nlist = cutterl(max(llist), nlist)
nlist = cutterr(min(rlist), nlist)
print(len(nlist))

### FIXED CODE ###

n, m = list(map(int, input().split()))
llist = []
rlist = []
for i in range(m) :
    l, r = list(map(int, input().split()))
    llist.append(l)
    rlist.append(r)
ll = max(llist)
rr = min(rlist)
print(max(0, min(rr, n)-ll+1))
import sys
from math import log2, ceil, floor

fin = sys.stdin.readline
A, B = [int(elem) for elem in fin().split()]
if A == B:
    print(A)
    exit(0)

# O(lg(max{A, B}))
result = 0
num_bits = floor(log2(B))
for d in range(num_bits + 1):
    base = 1 << (d + 1)
    mod_A = A % base
    mod_B = B % base

    parity = ((base >> 1) - max(0, mod_A - (base >> 1)) + max(0, mod_B - ((base >> 1) - 1))) % 2
    if parity:
        result |= 1 << d

print(result)


### FIXED CODE ###

import sys
from math import log, ceil, floor

fin = sys.stdin.readline
A, B = [int(elem) for elem in fin().split()]

def partial_f(n):
    if n == 0:
        return 0
    return ((n + 1) >> 1) & 1 if n & 1 else n | ((n >> 1) & 1)


print(partial_f(A - 1) ^ partial_f(B))
s = raw_input()
def cal(s):
	a= 0
	for idx in range(len(s)/2):
		if s[2*idx]==s[2*idx +1]:
			continue
		else:
			a = 1
			s = s[2*(idx+1):]
			break

	if a:
		return cal(s)
	else:
		return s

print(len(cal(s)))

### FIXED CODE ###

ipt = raw_input()
l = ""
for s in ipt:
    if not l:
        l += s
    elif l[-1]+s == "ST":
        l = l[:-1]
    else:
        l += s
print len(l)
a=int(input())
b=int(input())
x=a*b
y=2*a+2*b
print(x)
print(y)


### FIXED CODE ###

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

x=a*b
y=2*(a+b)

print(x,y)
A=[]
for i in range(0,3):
    k=list(map(int,input().split(' ')))
    A.append(k)
n=int(input())
b=[]
for i in range(0,n+1):
    b.append(int(input()))
for i in range(0,2):
    if (A[1][i] and A[2][i] and A[0][i]) in b:
        print('Yes')
        quit()
    if (A[i][1] and A[i][2] and A[i][0]) in b:
        print('Yes')
        quit()
if (A[0][0] and A[2][2] and A[1][1]) in b:
    print('Yes')
    quit()
if (A[0][2] and A[2][0] and A[1][1]) in b:
    print('Yes')
    quit()
print('No')

### FIXED CODE ###

A=[]
for i in range(0,3):
    k=list(map(int,input().split(' ')))
    A.append(k)
n=int(input())
b=[]
for i in range(0,n):
    b.append(int(input()))
for i in range(0,3):
    if (A[1][i] in b and A[2][i] in b and A[0][i] in b):
        print('Yes')
        quit()
    if (A[i][1] in b and A[i][2] in b and A[i][0] in b):
        print('Yes')
        quit()
if (A[0][0] in b and A[2][2] in b and A[1][1] in b):
    print('Yes')
    quit()
if (A[0][2] in b and A[2][0] in b and A[1][1] in b):
    print('Yes')
    quit()
print('No')
A,B,N = map(int,input().split())
res = 0
ans = 0
for i in range(1,N+1):
    res_bar = math.floor((A*i)/B)-A*math.floor(i/B)
    if res_bar > res:
        res = res_bar
        ans = i
print(ans)

### FIXED CODE ###

import math
 
a, b, n = map(int, input().split())
ans = 0
tmp = 0
 
if n > b - 1:
    n = b-1
 
ans = math.floor(a*n/b) - a*math.floor(n/b)
 
print(ans)
N=int(input())
alise=0
bob=0
a_list=list(map(int,input().split()))
a_sort=sorted(a_list)[::-1]
for i in range(N//2+N%2):
    alise+=a_sort.pop(0)
    bob+=a_sort.pop(0)
print(alise-bob)

### FIXED CODE ###

N=int(input())
alise=0
bob=0
a_list=list(map(int,input().split()))
a_sort=sorted(a_list)
for i in range(N,0,-2):
    alise+=a_sort[i-1]
for i in range(N-1,0,-2):
    bob+=a_sort[i-1]
print(alise-bob)
a, b = map(int, input().split())

print(ceil((a + b)/2))

### FIXED CODE ###

import math
a, b = map(int, input().split())

print(math.ceil((a + b)/2))
def main():
    from math import gcd

    A, B, K = map(int, input().split())

    g = gcd(A, B)
    rt = int(pow(g, 0.5))

    divisors = set()
    for d in range(1, rt + 1):
        if g % d == 0:
            divisors.add(d)
            divisors.add(g // d)

    ans = sorted(divisors, reverse=True)[K - 1]
    print(ans)


if __name__ == '__main__':
    main()

# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())


### FIXED CODE ###

a, b, k = map(int, input().split())
cnt = 0
for i in sorted(range(1, 100 + 1), reverse=True):
    if a % i == 0 and b % i == 0:
        cnt += 1
        if cnt == k:
            print(i)
            exit()
# Union Find 木
from sys import setrecursionlimit


def find(parent, i):
    t = parent[i]
    if t < 0:
        return i
    t = find(parent, t)
    parent[i] = t
    return t


def unite(parent, i, j):
    i = find(parent, i)
    j = find(parent, j)
    if i == j:
        return
    if i < j:
        parent[i] += parent[j]
        parent[j] = i
    else:
        parent[j] += parent[i]
        parent[i] = j


setrecursionlimit(10 ** 6)

N, M = map(int, input().split())
LRD = [tuple(map(int, input().split())) for _ in range(M)]
LRD.sort()

parent = [-1] * (N + 1)
for L, R, D in LRD:
    unite(parent, L, R)

d = {}
for i in range(1, N + 1):
    if parent[i] < 0:
        d[i] = 0

q = []
for L, R, D in LRD:
    if L > R:
        L, R = R, L
        D = -D
    q.append(L, R, D)

while q:
    nq = []
    for L, R, D in q:
        if L in d and R in d:
            if d[L] + D != d[R]:
                print('No')
                exit()
        elif L in d:
            d[R] = d[L] + D
        elif R in d:
            d[L] = d[R] - D
        else:
            nq.append((L, R, D))
    q = nq
print('Yes')


### FIXED CODE ###

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

links = [[] for _ in range(N + 1)]
for _ in range(M):
    L, R, D = map(int, input().split())
    links[L].append((R, D))
    links[R].append((L, -D))

t = [None] * (N + 1)
for i in range(1, N + 1):
    if t[i] is not None:
        continue
    t[i] = 0
    s = [i]
    while s:
        j = s.pop()
        for k, l in links[j]:
            if t[k] is None:
                t[k] = t[j] + l
                s.append(k)
            else:
                if t[k] != t[j] + l:
                    print('No')
                    exit()
print('Yes')
n = int(input())
nums = list(map(int, input().split()))
chk = True
for i in nums:
    if i%2==0:
        if i%3==0 and i%5==0:
            pass
        else:
            chk = False:
    else:
        pass
if chk == True:
    print('APPROVED')
else:
    print('DENIED')

### FIXED CODE ###

n = int(input())
nums = list(map(int, input().split()))
chk = True
for i in nums:
    if i%2==0:
        if i%3==0 or i%5==0:
            pass
        else:
            chk = False
    else:
        pass
if chk == True:
    print('APPROVED')
else:
    print('DENIED')
8 3 4

### FIXED CODE ###

n, a, b = list(map(int, input().split()))
result = 0
if a + b != 0:
  roop = n // (a +b)
  extra = n - roop*(a+b)
  result = a*roop
  if extra >= a:
    result += a
  else:
    result += extra
print(result)
N=int(input())
A=list(map(int,input().split()))
l=(abs(i)  for i in A)
cnt=0
for i in A:
    if(i<0):
        cnt+=1
if cnt%2==0:
    print(sum(l))
else:
    print(sum(l)-2*min(l))

### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))
l=[abs(i)  for i in A]
cnt=0
for i in A:
    if(i<0):
        cnt+=1
if cnt%2==0:
    print(sum(l))
else:
    print(sum(l)-2*min(l))
n, m, k = map(int, input().split())
MOD = 998244353

def modpow(a, n, p):
  if n == 1:
    return a % p 
  elif n % 2 == 1:
    return a * modpow(a, n-1, p) % p
  else:
    return modpow(a, n//2, p) **2 % p

bunsi = 1
for i in range(n-1-k+1, n):
  bunsi = bunsi * i % MOD

bunbo = 1
for i in range(1, k+1):
  bunbo = bunbo * i % MOD

comb = bunsi * modpow(bunbo, MOD-2, MOD) % MOD
print(m * modpow(m-1, n-1-k, MOD)*modpow(m, k, MOD)*comb % MOD)

### FIXED CODE ###

n, m, k = map(int, input().split())
MOD = 998244353

def modpow(a, n, p):
  if n == 0:
    return 1
  if n == 1:
    return a % p 
  elif n % 2 == 1:
    return a * modpow(a, n-1, p) % p
  else:
    return modpow(a, n//2, p) **2 % p
dp = [0]*(k+1)
dp[0] = m* modpow(m-1, n-1, MOD) % MOD
bunsi = 1
bunbo = 1
for j in range(1, k+1):
  bunsi = bunsi * (n-j) % MOD
  bunbo = bunbo * j % MOD

  comb = bunsi * modpow(bunbo, MOD-2, MOD) % MOD
  dp[j] = (m * modpow(m-1, n-1-j, MOD)*comb % MOD + dp[j-1]) % MOD
print(dp[k])
T, X = int(input())
print(T / X)

### FIXED CODE ###

T, X = map(int, input().split())
print(T / X)
N = int(input())
H = [int(s) for s in input().split()]
if N == 1:
  print('Yes')
else:
  Hc = H.copy()
  Hc[0] = Hc[0]-1
  flg = 'Yes'
  for i in range(N-1):
    if Hc[i+1] - Hc[i] >= 1:
      Hc[i+1] = Hc[i+1] - 1
    elif Hc[i+1] - Hc[i] < 0:
      flg = 'No'
  print(flg)

### FIXED CODE ###

N = int(input())
H = [int(s) for s in input().split()]
if N == 1:
  print('Yes')
else:
  Hc = H.copy()
  Hc[0] = Hc[0]-1
  flg = 'Yes'
  for i in range(N-1):
    if Hc[i+1] - Hc[i] >= 1:
      Hc[i+1] = Hc[i+1] - 1
    elif Hc[i+1] - Hc[i] < 0:
      flg = 'No'
  print(flg)
a = 0
for i in range(len(S)):
  a = (a + int(S[len(S)-i-1])*A[i]) %2019
  X.append(a)

X.sort()
flag =1
n = 0

    



### FIXED CODE ###

S = str(input())

#10**nのmod計算
A = []
p =1
for i in range(len(S)):
  A.append(p)
  p = p*10%2019

#左からi文字以降の数字列のmod計算
X = []
a = 0
for i in range(len(S)):
  a = (a + int(S[len(S)-i-1])*A[i]) %2019
  X.append(a)
X.sort()
flag =1
n = 0

#modが同じになる組み合わせ、またはもともとmodが0になる数字列の個数の総和計算
for i in range(len(X)-1):
  if X[i]==0:
    n +=1
  if X[i]==X[i+1]:
    flag += 1
  else:
    n += int(flag*(flag-1)/2)
    flag = 1
n += int(flag*(flag-1)/2)
if X[len(X)-1]==0:
  n +=1
print(n)
N, L = map(int, input().split())

aji_sum = 1 / 2 * N * (N + 2*L - 1)

if L < 0 and L + N > 0:
    eat_a = 0
elif L < 0 and L + N < 0:
    eat_a = L + N
elif L > 0 and L + N > 0:
    eat_a = L
print(int(aji_sum - eat_a))

### FIXED CODE ###

import numpy as np

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

aji_sum = 1 / 2 * N * (N + 2*L - 1)
aji_arr = np.ones(N) * L
aji_arr += np.arange(N)

eat_a = aji_arr[np.argmin(np.abs(aji_arr))]
    
print(int(aji_sum - eat_a))
print(x if x%y==0 else -1)

### FIXED CODE ###

x,y=map(int,input().split())
print(x if x%y!=0 else -1)
h,w = map(int, input().split())
power = [list(map(int,input().split())) for i in range(10)]

#ワーシャルフロイド法
for i in range(10):
    for j in range(10):
        for k in range(10):
            power[j][k] = min([power[j][k], power[j][i] + power[i][k])

ans = 0
for i in range(h):
    wall = list(map(int, input().split()))
    for item in wall:
        if item < 0:
            continue
        ans += power[item][1]

print(ans)



### FIXED CODE ###

h,w = map(int, input().split())
power = [list(map(int,input().split())) for i in range(10)]

#ワーシャルフロイド法
for i in range(10):
    for j in range(10):
        for k in range(10):
            power[j][k] = min(power[j][k], power[j][i] + power[i][k])

ans = 0
for i in range(h):
    wall = list(map(int, input().split()))
    for item in wall:
        if item < 0:
            continue
        ans += power[item][1]

print(ans)
a,b,c = int(input())
if a==b==c or a!=b!=c:
	print('No')
else:
	print('Yes')

### FIXED CODE ###

a,b,c = map(int,input().split())
if a==b==c:
	print('No')
elif a!=b and b!=c and c!=a:
    print('No')
else:
	print('Yes')
a = str(input())
s = a + a**2 + a**3
print(s)

### FIXED CODE ###

a = int(input())
n = a + a**2 + a**3
print(n)
N = int(input())
A = list(map(int, input().split()))
A = [[a,i] for a,i in zip(A,range(N))]
A = sorted(A,reverse=True)

dp = [[0]*(N+1) for _ in range(N+1)]
ans = 0

for n in range(0,N+1):
    for y in range(0,n+1):
        x = n-y
        a = A[n-1]
        ind = a[1]
        if x==0 and y==0:
            dp[x][y] = 0
        elif x==0:
            dp[x][y] = dp[x][y-1] + a[0]*abs(ind-((N-1)-(y-1)))
        elif y==0:
            dp[x][y] = dp[x-1][y]+a[0]*abs(ind-(x-1))
        else:
            dp[x][y] = max(dp[x-1][y]+a[0]*abs(ind-(x-1)),dp[x][y-1] + a[0]*abs(ind-((N-1)-(y-1))))
        ans = max(ans,dp[x][y])

print(ans)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
A = [[a,i] for a,i in zip(A,range(N))]
A = sorted(A,reverse=True)

dp = [[0]*(N+1) for _ in range(N+1)]
ans = 0

for n in range(0,N+1):
    for y in range(0,n+1):
        x = n-y
        a = A[n-1]
        ind = a[1]
        if x==0 and y==0:
            dp[x][y] = 0
        elif x==0:
            dp[x][y] = dp[x][y-1] + a[0]*abs(ind-((N-1)-(y-1)))
        elif y==0:
            dp[x][y] = dp[x-1][y]+a[0]*abs(ind-(x-1))
        else:
            dp[x][y] = max(dp[x-1][y]+a[0]*abs(ind-(x-1)),dp[x][y-1] + a[0]*abs(ind-((N-1)-(y-1))))
        ans = max(ans,dp[x][y])

print(ans)
def median_low(A):
    A.sort()
    b=A
    n = len(A)
    if n%2==1:
        med =b[n//2]
    else:
        x=b[n//2-1]
        y=b[n//2]
        med=(x+y)/2
        if med!=int(med):
            med=x
        else:
            med=int(med)
    return med


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

A = [v-i-1 for i,v in enumerate(A)]
x = median_low(A)

print(sum(abs(v - x) for v in A))



### FIXED CODE ###

N = int(input())
if N%2==0:
  print(N)
else:
  print(2*N)
N, T = map(int, input().split())
data = [list(map(int, input().split())) for i in range(N)
        
l = list[s for s in data if data.split([:1]) <= T
     
minl = t for t in min(l.split([0:])
      
print(minl)

### FIXED CODE ###

n,T = map(int,input().split())
mn = 1001
for i in range(n):
    c,t = map(int,input().split())
    if t <= T:
        mn = min(mn,c)

if mn == 1001:
    print("TLE")
else :
    print(mn)
import itertools

N = int(input())

# 頭文字Mグループ、頭文字Aグループ、のように分割する
# どの3つのグループから1人選ぶかを考える

n_initial_MARCH = [0]*5
match_initial = ["M", "A", "R", "C", "H"]
for _ in range(N):
    s = input()
    for idx in range(N):
        if s[0] == match_initial[idx]:
            n_initial_MARCH[idx] += 1

taken_indices = list(itertools.combinations([idx for idx in range(N) if n_initial_MARCH[idx] > 0], 3))

ans = 0

for groups in taken_indices:
    ans += n_initial_MARCH[groups[0]] * n_initial_MARCH[groups[1]] * n_initial_MARCH[groups[2]]

print(ans)

### FIXED CODE ###

import itertools

N = int(input())

# 頭文字Mグループ、頭文字Aグループ、のように分割する
# どの3つのグループから1人選ぶかを考える

n_initial_MARCH = [0]*5
match_initial = ["M", "A", "R", "C", "H"]
for _ in range(N):
    s = input()
    for idx in range(5):
        if s[0] == match_initial[idx]:
            n_initial_MARCH[idx] += 1

taken_indices = list(itertools.combinations([idx for idx in range(5) if n_initial_MARCH[idx] > 0], 3))

ans = 0

for groups in taken_indices:
    ans += n_initial_MARCH[groups[0]] * n_initial_MARCH[groups[1]] * n_initial_MARCH[groups[2]]

print(ans)
a,b,x = map(int,input().split())
a = range(a,b+1)
q = 0
for i in a:
  if a%i == 0:
    q += 1
    
print(q)

### FIXED CODE ###

def readinput():
    a,b,x=list(map(int,input().split()))
    return a,b,x
 
def main(a,b,x):
    ans = b//x - (a-1)//x
    return ans
 
if __name__=='__main__':
    a,b,x=readinput()
    ans=main(a,b,x)
    print(ans)
N=int(iput())
print(N%1000)

### FIXED CODE ###

N = int(input())
if N%1000 == 0:
	print(0)
else:
	print((N//1000 + 1)*1000-N)
import sys
from collections import Counter
from heapq import heapify, heappop, heappush
read = sys.stdin.read

N, K, *td = map(int, read().split())
dt = sorted(zip(td[1::2], td[::2]), reverse=True)

candidates = []
neta_group = Counter([j for i, j in dt[:K]])
variety = len(neta_group.keys())
points = sum([i for i, j in dt[:K]]) + variety ** 2
candidates.append(points)

if N == K:
    print(points)
    exit()

heap = [(-i, j) for i, j in dt[K:]]
heapify(heap)
satisfaction = dt[:K]
heapify(satisfaction)

while heap:
    taste, neta = heappop(heap)
    taste = -taste
    if not neta_group.get(neta):
        taste2, neta2 = heappop(satisfaction)
        if neta_group[neta2] == 1:
            heappush(heap, (-taste2, neta2))
        else:
            neta_group[neta2] -= 1
            neta_group[neta] = 1
            heappush(heap, (-taste, neta))
            points = points - taste2 + taste - variety ** 2 + (variety + 1) ** 2

            variety += 1
            candidates.append(points)

print(max(candidates))

### FIXED CODE ###

import sys
from operator import itemgetter
read = sys.stdin.read

N, K, *td = map(int, read().split())
td = sorted(zip(*[iter(td)] * 2), key=itemgetter(1), reverse=True)

stack = []
taste = 0
neta_group = set()
for t, d in td[:K]:
    taste += d
    if t in neta_group:
        stack.append(d)
    else:
        neta_group.add(t)

variety = len(neta_group)
candidates = [taste + variety ** 2]

if N == K:
    print(candidates[0])
    exit()

rest = list(reversed(td[K::]))

while rest and stack:
    t1, d1 = rest.pop()
    if t1 not in neta_group:
        neta_group.add(t1)
        d2 = stack.pop()
        variety += 1
        taste = taste - d2 + d1

        candidates.append(taste + variety ** 2)

print(max(candidates))
S = input()

S = list(map(S.split()))

flg = 0
temp = 0

for i in range(len(S)-1):
    if S[i] == S[i+1]:
        print(Bad)
        flg = 1
        break

if flg == 0:
    print(Good)


### FIXED CODE ###

S = input()

flg = 0
temp = 0

for i in range(len(S)-1):
    if S[i] == S[i+1]:
        print("Bad")
        flg = 1
        break

if flg == 0:
    print("Good")
n = int(input())
l = list(map(int,input().split()))
s = 1
f = 1
x = 1000000000000000000
for i in l:
	s *= i
	if s>x:
      	f = 0
  		print(-1)
        break
if f==1:
  print(s)

### FIXED CODE ###

n = int(input())
l = list(map(int,input().split()))
s = 1
f = 1
x = 1000000000000000000
l.sort()
if l[0]==0:
  print(0)
elif l[0]==1 and l[-1]==1:
  print(1)
else:
  l = l[::-1]
  for i in l:
      s *= i
      if s>x:
          print(-1)
          f = 0
          break
  if f==1:
    print(s)
a, b, m = map(int, input().split())
a1 = list(map(int, input().split()))
b1 = list(map(int, input().split()))

disc = [list(map(int, input().split())) for i in range(m)]
import numpy as np



from collections import deque
ans = []
ans = deque(ans)

for i in range(m):
    ans.append( a1[disc[i][0]-1] + b1[disc[i][1]-1] - disc[i][2] )

b2 = np.array(b1)
a2 = np.array(a1)
a2 = a2.reshape(a,1)

ans = list(ans)

print(min( min(ans), np.min(np.min(a2+b2) )))


### FIXED CODE ###

a, b, m = map(int, input().split())
a1 = list(map(int, input().split()))
b1 = list(map(int, input().split()))

disc = [list(map(int, input().split())) for i in range(m)]
import numpy as np


from collections import deque
ans = []

ans = deque(ans)

for i in range(m):
    ans.append( a1[disc[i][0]-1] + b1[disc[i][1]-1] - disc[i][2] )

ans = list(ans)

print(min( min(ans), min(a1)+min(b1) ))
N,K = map(int,input())
print(N-K+1)

### FIXED CODE ###

N,K = map(int,input().split())
print(N-K+1)
x = input()
if x = "A":
  print("T")
elif x = "T":
  print("A")
elif x = "C":
  print("D")
else x = "D":
  print("C")

### FIXED CODE ###

b = input()
if b == "A":
  print("T")
elif b == "T":
  print("A")
elif b == "C":
  print("G")
else:
  print("C")
N = int(input())
abc = [list(map(int, input().split())) for i in range(N)]

dp = [[-1]*3 for i in range(N)]
def dfs(i,j):
    if i == N:
        return 0
    if dp[i][j] != -1:
        return dp[i][j]
    else:
        if j==0:
            dp[i][j] = max(dfs(i+1,1)+abc[i][1], dfs(i+1,2)+abc[i][2])
        elif j==1:
            dp[i][j] = max(dfs(i+1,0)+abc[i][0], dfs(i+1,2)+abc[i][2])
        else:
            dp[i][j] = max(dfs(i+1,0)+abc[i][0], dfs(i+1,1)+abc[i][1])
        return dp[i][j]
print(max(dfs(0,0), dfs(0,1), dfs(0,2)))


### FIXED CODE ###

N = int(input())
abc = [list(map(int, input().split())) for i in range(N)]

dp = [[-1]*3 for i in range(N)]
import sys
sys.setrecursionlimit(10**9)
def dfs(i,j):
    if i == N:
        return 0
    if dp[i][j] != -1:
        return dp[i][j]
    else:
        if j==0:
            dp[i][j] = max(dfs(i+1,1)+abc[i][1], dfs(i+1,2)+abc[i][2])
        elif j==1:
            dp[i][j] = max(dfs(i+1,0)+abc[i][0], dfs(i+1,2)+abc[i][2])
        else:
            dp[i][j] = max(dfs(i+1,0)+abc[i][0], dfs(i+1,1)+abc[i][1])
        return dp[i][j]
print(max(dfs(0,0), dfs(0,1), dfs(0,2)))
N,A,B=map(int,input().split())
if (0<A+B<=10**18)and(0<N<=10**18)and(A>=0)and(B>=0):
    queue="a"*A+"b"*B
    while len(queue)<N:
        queue+="a"*A+"b"*B
    number=queue.count("a",0,N)
    print(number)
else:
    None

### FIXED CODE ###

N,A,B=map(int,input().split())
if (0<A+B<=10**18)and(0<N<=10**18)and(A>=0)and(B>=0):
    if N%(A+B)<=A:
        c=(N//(A+B))*A+N%(A+B)
        print(c)
    else:
        d=(N//(A+B))*A+A
        print(d)
n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(m)]

a = [[a[i][0], a[i][1], a[i][2]*(-1)] for i in range(m)]
point = [0] + ['inf']*(n-1)

for j in range(n):
  for i in range(m):
    
    if point[a[i][1]-1] == 'inf' or point[a[i][1]-1] > point[a[i][0]-1] + a[i][2]:
      point[a[i][1]-1] = point[a[i][0]-1] + a[i][2]
    
      if j == (n-1):
        point.append('inf')
        
        
if 'inf' in point:
  print('inf')
else:
  print(-point[n-1])
  
  

### FIXED CODE ###

import sys
INF=float('inf')
def Bellmanford(n,edges,r):
  d=[INF]*n
  d[r]=0    
  for i in range(n):
    for (u,v,c) in edges:
      if d[u]!=INF and d[u]+c<d[v]:
        d[v]=d[u]+c
        if i==n-1 and v==n-1:
          return 'inf'   
  return (-1)*d[n-1]

N,M=map(int, sys.stdin.readline().split())
Edges=[0]*M

for i in range(M):
  a,b,c=map(int, sys.stdin.readline().split())
  Edges[i]=(a-1,b-1,-c)
    
ans=Bellmanford(N,Edges,0)
print(ans)
n = input()                               #読み込むよ!
a = map(int,raw_input().split())
a.reverse()                               #reveres関数を使うよ!
print ' '.join(map(str,a))             #joinで結合だったよね!

### FIXED CODE ###

n = int(raw_input())
a = map(int,raw_input().split())
a.reverse()
print ' '.join(map(str,a))
def sieve(n):
    primes = [True] * n
    primes[0] = primes[1] = False
    for i in xrange(2, int(n ** 0.5) + 1):
        if primes[i]:
            for j in xrange(i * i, n, i):
                primes[j] = False
    return [i for i in xrange(n) if primes[i]]

prime_list = sieve(200000)
while 1:
    a = input()
    if a == 0:
        break
    prin
    t sum(prime_list[:a])

### FIXED CODE ###

def sieve(n):
    primes = [True] * n
    primes[0] = primes[1] = False
    for i in xrange(2, int(n ** 0.5) + 1):
        if primes[i]:
            for j in xrange(i * i, n, i):
                primes[j] = False
    return [i for i in xrange(n) if primes[i]]

prime_list = sieve(200000)
while 1:
    a = input()
    if a == 0:
        break
    print sum(prime_list[:a])