Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math

mod = 10**9+7

N,M = map(int,input().split())
tree = [[] for i in range(N)]
for i in range(M):
    X,Y,Z = map(int,input().split())
    X -= 1
    Y -= 1
    tree[X] += [Y]
    tree[Y] += [X]

# print(tree)
used = [0 for i in range(N)]

def dfs(node,p):
    used[node] = 1
    # print(tree[node])
    for new in tree[node]:
        if new == p or used[new] == 1:continue
        dfs(new,node)

cnt = 0
while sum(used) < len(used):
    for i in range(N):
        if used[i] == 0:
            dfs(i,-1)
            cnt += 1

ans = N - (sum(used) - cnt)
print(ans)


Fixed submission:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000


N,M = map(int,input().split())
tree = [[] for i in range(N)]
for i in range(M):
    X,Y,Z = map(int,input().split())
    X -= 1
    Y -= 1
    tree[X] += [Y]
    tree[Y] += [X]

# print(tree)
used = [0 for i in range(N)]

def dfs(node,p):
    used[node] = 1
    # print(tree[node])
    for new in tree[node]:
        if new == p or used[new] == 1:continue
        dfs(new,node)

cnt = 0
while sum(used) < len(used):
    for i in range(N):
        if used[i] == 0:
            dfs(i,-1)
            cnt += 1

ans = N - (sum(used) - cnt)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections
from decimal import Decimal # 10進数で考慮できる

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

H, W = LI()
A = []
for i in range(H):
    a = list(str(input()))
    A.append(a)
# 複数のスタート地点が存在してもqueに突っ込むことで同様の効果が得られる．
visited = [[-1 for i in range(W)] for j in range(H)]

for i in range(H):
    for j in range(W):
        if A[i][j] == "#":
            d.append((i,j))
            visited[i][j] = 0

moves = [[0,1],[1,0],[-1,0],[0,-1]]
cnt = 0
while len(d) > 0:
    X, Y = d.popleft()
    cnt = visited[X][Y]
    for x, y in moves:
        n_X = X + x
        n_Y = Y + y
        if 0 <= n_X < H and 0 <= n_Y< W:
            if visited[n_X][n_Y] == -1:
                visited[n_X][n_Y] = cnt + 1
                d.append((n_X, n_Y))
print(cnt)


Fixed submission:
#!/usr/bin/env python3
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections
from decimal import Decimal # 10進数で考慮できる

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

H, W = LI()
A = [[] for i in range(H)]
for i in range(H):
    a = list(str(input()))
    A[i] = a
# 複数のスタート地点が存在してもqueに突っ込むことで同様の効果が得られる．
visited = [[-1 for i in range(W)] for j in range(H)]

for i in range(H):
    for j in range(W):
        if A[i][j] == "#":
            d.append((i,j))
            visited[i][j] = 0

moves = [[0,1],[1,0],[-1,0],[0,-1]]
cnt = 0
while len(d) > 0:
    X, Y = d.popleft()
    cnt = visited[X][Y]
    for x, y in moves:
        n_X = X + x
        n_Y = Y + y
        if 0 <= n_X < H and 0 <= n_Y< W:
            if visited[n_X][n_Y] == -1:
                visited[n_X][n_Y] = cnt + 1
                d.append((n_X, n_Y))
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import fractions
from functools import reduce

N = int(input())
A = [int(i) for i in input().split()]

def gcd(nums):
    return reduce(fractions.gcd,nums)

ans = 1
for i in range(N):
    a = copy.deepcopy(A)
    a.remove(A[i])
    ans = max(ans,gcd(a))

print(ans)


Fixed submission:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import fractions
from functools import reduce



N = int(input())
A = [int(i) for i in input().split()]

def gcd(nums):
    return reduce(fractions.gcd,nums)

ans = 1
A.sort()
gcd1 = gcd(A)
for i in range(N):
    A[i] //= gcd1

ans *= gcd1

gcd2 = A[0]
for i in range(1,N):
    gcd2 = fractions.gcd(gcd2,A[i])
    if gcd2 == 1:
        key = i
        break

a = copy.deepcopy(A)
a.remove(A[0])
if gcd(a)!=1:
    ans *= gcd(a)
    print(ans)
    exit()

a = copy.deepcopy(A)
a.remove(A[key])
if gcd(a)!=1:
    ans *= gcd(a)
    print(ans)
    exit()
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# encoding:utf-8
import copy
import numpy as np
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import math


N,K = map(int,input().split())
S = str(input())

now,cnt = 1,0
Nums = []
for i in range(N):
    if S[i] == str(now):
        cnt += 1
    else:
        Nums.append(cnt)
        cnt = 1
        now = 1 - now

if cnt!=0:
    Nums.append(cnt)

if len(Nums)%2==0:
    Nums.append(0)

#累積和
ans = 0
Add = 2*K+1
for i in range(N):
    if i%2==0:
        left = i
        right = i+Add
        tmp = sum(Nums[left:right])
        ans = max(tmp,ans)
print(ans)


Fixed submission:
# encoding:utf-8
import copy
import numpy as np
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import math


N,K = map(int,input().split())
S = str(input())

now,cnt = 1,0
Nums = []
for i in range(N):
    if S[i] == str(now):
        cnt += 1
    else:
        Nums.append(cnt)
        cnt = 1
        now = 1 - now

if cnt!=0:
    Nums.append(cnt)

if len(Nums)%2==0:
    Nums.append(0)

#累積和
Sums = [0]
tmp = 0
for i in range(len(Nums)):
    tmp += Nums[i]
    Sums.append(tmp)
# print(Nums)
# print(Sums)
ans = 0
Add = 2*K+1
for i in range(len(Sums)):
    if i%2==0:
        left = i
        right = min(i+Add,len(Sums)-1)
        tmp = Sums[right]-Sums[left]
        ans = max(tmp,ans)
print(ans)
Buggy python submission (verdict: Runtime Error):
# encoding:utf-8
import copy
import numpy as np
import random
import pandas as pd
import torch

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

cds = []
for i in range(1,min(a,b)+1):
    if a%i==0 and b%i==0:
        cds.append(i)

cds.reverse()
print(cds[k-1])


Fixed submission:
# encoding:utf-8
import copy
import numpy as np
import random


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

cds = []
for i in range(1,min(a,b)+1):
    if ((a%i==0) and (b%i==0)):
        cds.append(i)

cds.reverse()
print(cds[k-1])
Buggy python submission (verdict: Runtime Error):
# encoding:utf-8
import copy
import numpy as np
import random
import pandas as pd
import torch


s = list(str(input()))

escape = False
begin = len(s)

def rem(s):
    for i in range(1,len(s)):
        # print(s)
        if s[i-1] != s[i]:
            s.pop(i)
            s.pop(i-1)
            break
    return s


for i in range(10**4):
    s = rem(s)

end = len(s)
print(begin-end)


Fixed submission:
# encoding:utf-8
import copy
import numpy as np
import random
# import pandas as pd
# import torch


s = list(str(input()))


count = [0,0]
for i in range(len(s)):
    count[int(s[i])] += 1

ans = 2*min(count[0],count[1])
#
print(ans)
# escape = False
# begin = len(s)
#
# def rem(s):
#     for i in range(1,len(s)):
#         # print(s)
#         if s[i-1] != s[i]:
#             s.pop(i)
#             s.pop(i-1)
#             break
#     return s
#
#
# pre = len(s)
# proceed = 0
# while proceed != pre:
#     pre = len(s)
#     s = rem(s)
#     after = len(s)
#
# end = len(s)
# print(begin-end)
Buggy python submission (verdict: Runtime Error):
# encoding:utf-8

import copy
import numpy as np
import random

a = []
b = []

for i in range(3):
    a_now,b_now = map(int, input().split())
    a.append(a_now)
    b.append(b_now)

town_dic = {1:0,2:0,3:0,4:0}

for i in range(3):
    town_dic[a[i]] += 1
    town_dic[b[i]] += 1

answer = "YES"
for i in range(4):
    if town_dic[i+1] == 3:
        answer = "NO"


print(answer)


Fixed submission:
# encoding:utf-8

import copy
import numpy as np
import random

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

cookie = 1

if b-a < 2:
    cookie += k

else:
    k -= (a-cookie)
    cookie = a

    cookie += (k//2)*(b-a)

    if k % 2 == 1:
        cookie += 1
    else:
        pass

print(cookie)
Buggy python submission (verdict: Time Limit Exceeded):
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

N, K = LI()
H = LI()

dp = [mod for i in range(N)]
dp[0] = 0
for i in range(N):
    for j in range(min(K + 1, N - i)):
        # print(i, j)
        dp[i+j] = min(dp[i] + abs(H[i] - H[i + j]), dp[i+j])

print(dp[-1])

Fixed submission:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

N, K = LI()
H = LI()

dp = [mod for i in range(N)]
dp[0] = 0
for i in range(N):
    for j in range(min(K + 1, N - i)):
        # print(i, j)
        dp[i+j] = min(dp[i] + abs(H[i] - H[i + j]), dp[i+j])

print(dp[-1])
Buggy python submission (verdict: Runtime Error):
#encoding:utf-8

import math

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

def factorint(N):
    table = {}
    while(N > 1):
        for i in range(2,N+1):
            if N%i == 0:
                while N%i == 0:
                    N = N//i
                    if i in table.keys():
                        table[i] += 1
                    else:
                        table[i] = 1
                break
    return table
ans = 1
if N == 1:
    ans = P
elif 1 < N < 40:
    #Nが２以上なのでpをｓｑｒｔしても良い
    facters = factorint(P)
    # print(facters)

    ans = 1
    for key in facters.keys():
        if facters[key]/N >= 1:
            ans *= key**(facters[key]//N)
else:
    pass

print(int(ans))
# print(type(ans))


Fixed submission:
#encoding:utf-8

n = list(input())

count = 0
for i in range(4):
    if n[i] == "2":
        count += 1


print(count)
Buggy python submission (verdict: Time Limit Exceeded):
# encoding:utf-8

import copy
import numpy as np
import random

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

h = []
for i in range(n):
    h.append(int(input()))

h.sort()
# print(h)
max_tree = []
min_tree = []
ans = 10**9
for i in range(n-k+1):
    ans = min(max(h[i:i+k])-min(h[i:i+k]),ans)

print(ans)


Fixed submission:
# encoding:utf-8

import copy
import numpy as np
import random

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

h = []
for i in range(n):
    h.append(int(input()))

h.sort()
# print(h)
max_tree = []
min_tree = []
ans = 10**9
for i in range(n-k+1):
    ans = min(h[i+k-1]-h[i],ans)

print(ans)
Buggy python submission (verdict: Runtime Error):
#encoding utf-8

n = int(input())
data = []
for i in range(n):
    x,y,h=map(int,input().split())
    data.append([x,y,h])

def calH(cx,cy,data):
    return data[2]+abs(data[0]-cx)+abs(data[1]-cy)

def conh(temH,cx,cy,data):
    return temH-abs(data[0]-cx)-abs(data[1]-cy)


for i in range(101):
    for j in range(101):
        clear = 0
        count = 0
        for k in range(n):
            if clear == 0:
                temH = calH(i,j,data[k])
                if data[k][2] != 0:
                    clear = 1
                else:
                    if conh(temH,i,j,data[k]) < 0:
                        count += 1
                    else:
                        count += 1
                        clear = 1

        for k in range(count,n):
            print(k)
            ignore_flag = 0
            if data[k][2] == 0:
                if conh(temH,i,j,data[k]) < 0:
                    ignore_flag = 1
                    count += 1

            if ignore_flag == 0:
                if calH(i,j,data[k]) != temH:
                    break
                else:
                    count += 1
            if count == n:
                answer=[i,j,calH(i,j,data[0])]

print(answer[0],answer[1],answer[2])


Fixed submission:
#encoding utf-8

n = int(input())


if n == 1:
    print("Hello World")

elif n == 2:
    a = int(input())
    b = int(input())
    print(a+b)

Buggy python submission (verdict: Runtime Error):
#encoding utf-8

n = int(input())
data = []
for i in range(n):
    x,y,h=map(int,input().split())
    data.append([x,y,h])

def calH(cx,cy,data):
    return data[2]+abs(data[0]-cx)+abs(data[1]-cy)

def conh(temH,cx,cy,data):
    return temH-abs(data[0]-cx)-abs(data[1]-cy)


for i in range(101):
    for j in range(101):
        clear = 0
        count = 0
        for k in range(n):
            if clear == 0:
                temH = calH(i,j,data[k])
                if data[k][2] != 0:
                    clear = 1
                else:
                    if conh(temH,i,j,data[k]) < 0:
                        count += 1
                    else:
                        count += 1
                        clear = 1

        for k in range(count,n):
            print(k)
            ignore_flag = 0
            if data[k][2] == 0:
                if conh(temH,i,j,data[k]) < 0:
                    ignore_flag = 1
                    count += 1

            if ignore_flag == 0:
                if calH(i,j,data[k]) != temH:
                    break
                else:
                    count += 1
            if count == n:
                answer=[i,j,calH(i,j,data[0])]

print(answer[0],answer[1],answer[2])


Fixed submission:
#encoding utf-8

n = int(input())


if n == 1:
    print("Hello World")

elif n == 2:
    a = int(input())
    b = int(input())
    print(a+b)
Buggy python submission (verdict: Runtime Error):
#encoding utf-8
from collections import Counter
def main(n,v):
    odd = Counter(v[0::2]).most_common(2) + [(0,0)]
    even = Counter(v[1::2]).most_common(2) + [(0,0)]

    if odd[0][0] == even[0][0]:
        ans = min(n-odd[0][1]-even[1][1],
        n-odd[1][1]-even[0][1])
    else:
        ans = n-odd[0][1]-even[0][1]
    print(ans)


if __name__ == "__main__":
    n = int(input())
    v = list(int(i) for i in input().split())
    main(n,v)

Fixed submission:
#encoding utf-8

n = list(str(input()))

for i in range(len(n)):
    if n[i] == "1":
        n[i] = "to9"
    if n[i] == "9":
        n[i] = "to1"

for i in range(len(n)):
    if n[i] == "to9":
        n[i] = "9"
    elif n[i] == "to1":
        n[i] = "1"

print("".join(n))
Buggy python submission (verdict: Runtime Error):
a,b = int(input().split())

if a*b%2 == 0:
	print("No")
  
else:
	print("Yes")

Fixed submission:
a,b = map(int, input().split())

if a*b%2 == 0:
  print("No")

else:
  print("Yes")

Buggy python submission (verdict: Runtime Error):
a,b = int(input().split())


if a*b%2 == 0:
  print("No")
  
else:
  print("Yes")

Fixed submission:
a,b = map(int, input().split())

if a*b%2 == 0:
  print("No")

else:
  print("Yes")
Buggy python submission (verdict: Runtime Error):
# encoding utf-8

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

x = list(int(i) for i in input().split())


for i in range(N):
    if 0 <= x[i]:
        border = i
        break

len_run = 100000

if border == 0:
    len_run = min(abs(x[K-1]), len_run)

if border == N-1:
    len_run = min(abs(x[N-K]), len_run)

for i in range(K):
    if border-K+i >= 0 and border+i <= N:
        len_run = min(abs(2*x[border-K+i])+abs(x[border+i-1]), len_run)
        len_run = min(abs(x[border-K+i])+abs(2*x[border+i-1]), len_run)

print(len_run)













# #最終的に右に進む
# def right(K):
#     runlen = 0
#     y = x_pos
#     for i in range(len(x_neg)):
#         y.append(x_neg[i]*(-2))
#     y.sort()
#     max = y[K-1]
#     if max in x_pos:
#         runlen += max
#         y_neg = [i for i in x_neg if i >= (-max)/2]
#         runlen += y_neg[-1]*-2
#     else:
#         runlen += max/2
#         y_pos = [i for i in x_pos if i <= max]
#         runlen += y_pos[-1]
#     return runlen
#
#
# def left(K):
#     runlen = 0
#     z = []
#     for j in range(len(x_neg)):
#         z.append(x_neg[j]*-1)
#     for i in range(len(x_pos)):
#         z.append(x_pos[i]*(2))
#     z.sort()
#     max = -z[K-1]
#     if max in x_neg:
#         runlen -= max
#         z_pos = [i for i in x_pos if i <= (-max)/2]
#         runlen += z_pos[-1]*2
#     else:
#         runlen -= max/2
#         z_neg = [i for i in x_neg if i <= -max]
#         runlen += z_neg[-1]
#     return runlen
#
# if len(x_neg) == 0:
#     runlen = x[K-1]
# elif len(x_pos) == 0:
#     x.sort().reverse()
#     runlen = x[K-1]
# else:
#     runlen = min(right(K),left(K))
#     print(right(K),left(K))
#
# print(runlen)


Fixed submission:
#encoding utf 8

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

pos = list(int(i) for i in input().split())

ans = abs(pos[0])+abs(pos[0]-pos[k-1])

for i in range(n-k+1):
    val = 0
    val += abs(pos[i] - pos[i+k-1])
    val += min(abs(pos[i]), abs(pos[i+k-1]))

    if val < ans:
        ans = val
print(ans)
Buggy python submission (verdict: Runtime Error):
#encoding utf-8

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

area = (a-1)*(b-1)
print(area)


Fixed submission:
#encoding utf-8

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

area = (a-1)*(b-1)
print(area)
Buggy python submission (verdict: Runtime Error):
#encoding utf-8

n, m = map(int, input().split())
a = [int(i)%m for i in input().split()]

count = 0
for i in range(n):
    candy = a[i]
    if candy % m == 0:
        count += 1
    for rest in range(1,n-i):
        candy += a[i+rest]
        if candy % m == 0:
            count += 1

print(count)


Fixed submission:
#encoding utf-8

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

if n % k == 0:
    print("0")
else:
    print("1")
Buggy python submission (verdict: Time Limit Exceeded):
#encoding utf:8

n = int(input())
# num=[]
num = list(int(i) for i in input().split())
# for i in range(n):
#     num.append(int(input().split()))

#gcd 最大公約数
def gcd(a,b):
    gcd = 1
    list_a = []
    list_b = []
    for i in range(a):
        if a % (i+1) ==0:
            a = a/(i+1)
            list_a.append(i+1)
    for i in range(b):
        if b % (i+1) ==0:
            b = b/(i+1)
            list_b.append(i+1)
    # print(list_a,list_b)
    for num in range(len(list_a)):
        if list_a[num] in list_b:
            gcd = gcd * list_a[num]
    return int(gcd)

# lcm: 最小公倍数
def lcm(a,b):
    lcm = a*b/gcd(a,b)
    return int(lcm)

for i in range(n):
    if i == 0:
        a_lcm = lcm(num[0], num[1])
    a_lcm = lcm(a_lcm,num[i])

max = a_lcm-1
f=0
for i in range(len(num)):

    f += (max%num[i])
print(f)


Fixed submission:
n = int(input())
# num=[]
num = list(int(i) for i in input().split())

f = sum(num)-n
print(f)
Buggy python submission (verdict: Runtime Error):
n = int(input())
A = [int(i) for i in input().split()]
A=A.sort()
print(A[-1]-A[0])

Fixed submission:
#encoding: utf-8

n = int(input())
A = [int(i) for i in input().split()]
A.sort()
print(A[-1]-A[0])
Buggy python submission (verdict: Runtime Error):
#encoding:utf-8

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

if a<=8 and b<=8:
    print("Yay!")

else:
    print(":(")


Fixed submission:
#encoding:utf-8

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

if a<=8 and b<=8:
    print("Yay!")

else:
    print(":(")
Buggy python submission (verdict: Runtime Error):
d=int(input())

n=int(input())

r=(100**d)*n

print(r)


Fixed submission:
# encoding:utf-8

import copy
import numpy as np
import random

#n==100の時のコーナーケースに手間取った

d,n = map(int, input().split())
if n == 100:
    print(100**d*101)
    exit()
else:
    print(100**d*n)

Buggy python submission (verdict: Runtime Error):
#encoding:utf-8

d=int(input())

n=int(input())

r=(100**d)*n

print(r)


Fixed submission:
# encoding:utf-8

import copy
import numpy as np
import random

#n==100の時のコーナーケースに手間取った

d,n = map(int, input().split())
if n == 100:
    print(100**d*101)
    exit()
else:
    print(100**d*n)
Buggy python submission (verdict: Runtime Error):
#encoding utf-8


n = input()

if n > 999:
    print("ABD")

else:
    print("ABC")

Fixed submission:
#encoding utf-8


n = int(input())

if n > 999:
    print("ABD")

else:
    print("ABC")
Buggy python submission (verdict: Time Limit Exceeded):
# encoding:utf-8
import copy
import numpy as np
import random
import queue

n = int(input())

withdraws = [1]
price = 1
while True:
    price *= 6
    if price <= 10**5 and price <= n:
        withdraws.append(price)
    else:
        break

price = 1
while True:
    price *= 9
    if price <= 10**5 and price <= n:
        withdraws.append(price)
    else:
        break

money = 0
count = 0

que = queue.Queue()

que.put((0,0))
while not(que.empty()):
    money,count = que.get()
    # print(money,count)
    if money > n:
        pass
    else:
        for withdraw in withdraws:
            if money+withdraw == n:
                print(count+1)
                exit()
            else:
                next = (money+withdraw,count+1)
                que.put(next)


Fixed submission:
# encoding:utf-8
import copy
import numpy as np
import random
import queue

n = int(input())

withdraws = [1]
price = 1
while True:
    price *= 6
    if price <= 10**5 and price <= n:
        withdraws.append(price)
    else:
        break

price = 1
while True:
    price *= 9
    if price <= 10**5 and price <= n:
        withdraws.append(price)
    else:
        break


withdraws.sort(reverse = True)
# print(withdraws)
money = 0
count = 0


# 幅優先探索
'''
que = queue.Queue()

que.put((0,0))
memory = []
while not(que.empty()):
    money,count = que.get()
    print(money,count)
    if money > n:
        pass
    else:
        for withdraw in withdraws:
            if money+withdraw == n:
                print(count+1)
                exit()

            elif money+withdraw in memory:
                pass
            else:
                memory.append(money+withdraw)
                next = (money+withdraw,count+1)
                que.put(next)
'''

# 分割

ans = 10**10
if n < 6:
    ans = n
for i in range(n+1):
    t = i
    count = 0
    while t>0:
        count += t%6
        t = t//6
    t = n - i
    while t>0:
        count += t%9
        t = t//9
    # print(ans)
    ans =min(ans,count)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
#encoding utf-8

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

reverse = 3*10**5+1
for i in range(n):
    if i == 0:
        point = s[i+1:].count("E")
    elif i == n-1:
        point = s[:i-1].count("W")
    else:
        point = s[i+1:].count("E")+s[:i].count("W")
    # print(point)
    reverse = min(point, reverse)

print(reverse)


Fixed submission:
#encoding utf-8

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

reverse = 3*10**5+1
west = []
east = []
west_num = 0
east_num = 0
for i in range(len(s)):
    if s[i] == "W":
        west_num += 1
    elif s[i] == "E":
        east_num += 1
    west.append(west_num)
    east.append(east_num)
# print(west,east)
for i in range(n):
    if i == 0:
        point = east[-1]+east[0]
    elif i == n-1:
        point = west[i-1]
    else:
        point = east[-1]-east[i]+west[i-1]
    # print(point)
    reverse = min(point, reverse)

print(reverse)