Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N = int(input())

w = "MARCH"
count = {key: 0 for key in w}

for i in range(N):
    S = input()
    c = S[0]
    if c in w:
        count[c] += 1

ans = 0

for i in range(N):
    for j in range(i + 1, N):
        for k in range(j + 1, N):
            ans += count[w[i]] * count[w[j]] * count[w[k]]

print(ans)


Fixed submission:
N = int(input())

w = "MARCH"
count = {key: 0 for key in w}

for i in range(N):
    S = input()
    c = S[0]
    if c in w:
        count[c] += 1

ans = 0
M = len(w)

for i in range(M):
    for j in range(i + 1, M):
        for k in range(j + 1, M):
            ans += count[w[i]] * count[w[j]] * count[w[k]]

print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = [int(input()) for _ in range(N)]

paper = [0] * 100000

for a in A:
    paper[a - 1] += 1

ans = len(list(filter(lambda x: x % 2 == 1, paper)))
print(ans)


Fixed submission:
N = int(input())
A = [int(input()) for _ in range(N)]

paper = {}

for a in A:
    paper.setdefault(a - 1, 0)
    paper[a - 1] += 1

ans = len(list(filter(lambda x: x % 2 == 1, paper.values())))
print(ans)
Buggy python submission (verdict: Runtime Error):
K, S = map(int, input().split())
count = 0

for x in range(K + 1):
    for y in range(K + 1):
        z = S - (x + y)
        if 0 <= z and z <= K:
            count += 1

print(count)


Fixed submission:
s = input()

print(s.replace(",", " "))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

# C - Sum of product of pairs
N = int(input())
A = list(map(int, input().split()))
ans = 0

for i in range(N):
  for j in range(i + 1, N):
    ans += (A[i] * A[j]) % (10 ** 9 + 7)

print(ans % (10 ** 9 + 7))

Fixed submission:
import sys
input = sys.stdin.readline

# C - Sum of product of pairs
N = int(input())
A = list(map(int, input().split()))

sum_ = sum(A)
ans = 0

for i in range(N):
  sum_ -= A[i]
  ans += A[i] * sum_
  ans %= (10 ** 9 + 7)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

# C - Marks
N, K = map(int, input().split())
A = list(map(int, input().split()))
score = 1

for i in range(N):
	if i < K:
		score *= A[i]
	else:
		new_score = score * A[i] // A[i-K]
		
		if new_score > score:
			print('Yes')
		else:
			print('No')
		
		score = new_score

Fixed submission:
import sys
input = sys.stdin.readline

# C - Marks
N, K = map(int, input().split())
A = list(map(int, input().split()))

for i in range(N):
	if i >= K:
		
		if A[i] > A[i - K]:
			print('Yes')
		else:
			print('No')
Buggy python submission (verdict: Time Limit Exceeded):
# D - Road to Millionaire
def sell(asset, price):
  return price * asset[1] + asset[0]


def buy(money, price):
  stock = money // price
  remainder = money % price
  
  return (remainder, stock)


import copy

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

# タプルのset
assets = [(1000, 0)]


for i in range(N - 1):
  assets_copy = copy.deepcopy(assets)
  money = 0
  
  for a in assets_copy:
    money = max(money, sell(a, A[i]))  
  
    assets.append((money, 0))
    assets.append(buy(money, A[i]))

ans = 0

for a in assets:
  ans = max(ans, sell(a, A[N - 1]))

print(ans)

Fixed submission:
# D - Road to Millionaire
def sell(price):
  global money
  global stock
  
  money += price * stock
  stock = 0


def buy(price):
  global money
  global stock

  stock += money // price
  money %= price


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

money = 1000
stock = 0

for i in range(N - 1):
  if A[i] < A[i + 1]:
    sell(A[i])
    buy(A[i])
  elif A[i + 1] < A[i]:
    sell(A[i])

sell(A[N - 1])

print(money)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

# C - Tsundoku
def get_total_time(n):
	totals = [0] * (n + 1)
	arr = input().split()
	
	for i in range(n):
		totals[i + 1] = totals[i] + int(arr[i])
	
	return totals


n, m, k = map(int, input().split())
a_sum = get_total_time(n)
b_sum = get_total_time(m)
ans = 0

for i in range(n + 1):
	if a_sum[i] > k:
		break
	else:
		for j in range(m + 1):
			if a_sum[i] + b_sum[j] > k:
				break
			else:
				ans = max(ans, i + j)

print(ans)

Fixed submission:
# C - Tsundoku
def calc_cusum(n):
	cusum = [0] * (n + 1)
	arr = input().split()
	
	for i in range(n):
		cusum[i + 1] = cusum[i] + int(arr[i])
	
	return cusum


def identify_position(i, j):
  global a
  global b
  global k
  global m
  
  if a[i] + b[j] > k:
    while j > 0:
      j -= 1
      
      if a[i] + b[j] <= k:
        break
  else:
    while j < m and a[i] + b[j+1]<= k:
      j += 1
  
  return j


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

ans = 0
j = 0

for i in range(n + 1):
  j = identify_position(i, j) 
  
  #print(a[i])
  #print(b[j])
  #print(i + j)
  
  if a[i] + b[j] <= k:
    ans = max(ans, i+j)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

# C - Tsundoku
def get_total_time(n):
	totals = [0] * (n + 1)
	arr = input().split()
	
	for i in range(n):
		totals[i + 1] = totals[i] + int(arr[i])
	
	return totals


n, m, k = map(int, input().split())
a_sum = get_total_time(n)
b_sum = get_total_time(m)
ans = 0

for i in range(n + 1):
	if a_sum[i] > k:
		break
	else:
		for j in range(m + 1):
			if a_sum[i] + b_sum[j] > k:
				break
			else:
				ans = max(ans, i + j)

print(ans)

Fixed submission:
# C - Tsundoku
def calc_cusum(n):
	cusum = [0] * (n + 1)
	arr = input().split()
	
	for i in range(n):
		cusum[i + 1] = cusum[i] + int(arr[i])
	
	return cusum


def identify_position(i, j):
  global a
  global b
  global k
  global m
  
  if a[i] + b[j] > k:
    while j > 0:
      j -= 1
      
      if a[i] + b[j] <= k:
        break
  else:
    while j < m and a[i] + b[j+1]<= k:
      j += 1
  
  return j


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

ans = 0
j = 0

for i in range(n + 1):
  j = identify_position(i, j) 
  
  #print(a[i])
  #print(b[j])
  #print(i + j)
  
  if a[i] + b[j] <= k:
    ans = max(ans, i+j)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

# D - Replacing
def get_sum(dic):
	sum = 0
	
	for k, v in dic.items():
		sum += k * v
	
	return sum


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

for ai in a:
	dic.setdefault(ai, 0)
	dic[ai] += 1

for i in range(q):
	b, c = map(int, input().split())

	count = dic.pop(b, 0)
	
	if count > 0:
		dic.setdefault(c, 0)
		dic[c] += count
	
	print(get_sum(dic))

Fixed submission:
import sys
input = sys.stdin.readline

# D - Replacing
def get_sum(dic):
	sum = 0
	
	for k, v in dic.items():
		sum += k * v
	
	return sum


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

for ai in a:
	dic.setdefault(ai, 0)
	dic[ai] += 1

for i in range(q):
	b, c = map(int, input().split())

	count = dic.pop(b, 0)
	
	if count > 0:
		dic.setdefault(c, 0)
		dic[c] += count

	if i == 0:	
		sum = get_sum(dic)
	else:
		sum += (c - b) * count
	
	print(sum)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

# D - Replacing
def get_sum(dic):
	sum = 0
	
	for k, v in dic.items():
		sum += k * v
	
	return sum


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

for ai in a:
	dic.setdefault(ai, 0)
	dic[ai] += 1

for i in range(q):
	b, c = map(int, input().split())

	count = dic.pop(b, 0)
	
	if count > 0:
		dic.setdefault(c, 0)
		dic[c] += count
	
	print(get_sum(dic))

Fixed submission:
import sys
input = sys.stdin.readline

# D - Replacing
def get_sum(dic):
	sum = 0
	
	for k, v in dic.items():
		sum += k * v
	
	return sum


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

for ai in a:
	dic.setdefault(ai, 0)
	dic[ai] += 1

for i in range(q):
	b, c = map(int, input().split())

	count = dic.pop(b, 0)
	
	if count > 0:
		dic.setdefault(c, 0)
		dic[c] += count

	if i == 0:	
		sum = get_sum(dic)
	else:
		sum += (c - b) * count
	
	print(sum)
Buggy python submission (verdict: Runtime Error):
# D - I hate Factorization
def meet_condition(i, j):
	pi = pows[i]
	pj = pows[j]
	
	if pi - pj == x:
		return i, j
	elif pi + pj == x:
		return i, -j


pows = []

for i in range(100):
	pows.append(pow(i, 5))

x = int(input())

for i in range(len(pows)):
	for j in range(len(pows)):
		if meet_condition(i, j) != None:
			a, b = meet_condition(i, j)
			print(a, b)
			sys.exit()

Fixed submission:
import sys
input = sys.stdin.readline

# D - I hate Factorization
def meet_condition(i, j):
	pi = pows[i]
	pj = pows[j]
	
	if pi - pj == x:
		return i, j
	elif pi + pj == x:
		return i, -j


pows = []

for i in range(200):
	pows.append(pow(i, 5))

x = int(input())

for i in range(len(pows)):
	for j in range(len(pows)):
		if meet_condition(i, j) != None:
			a, b = meet_condition(i, j)
			print(a, b)
			exit()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

# C - Many Requirements
import copy

n, m, q = map(int, input().split())
seq_arr = []

for i in range(1, m + 1):
	seq_arr.append([i])

for i in range(n):
	tmp_arr = []
	
	for s in seq_arr:
		for j in range(s[-1], m + 1):
			tmp_arr.append(s + [j])

	seq_arr = copy.deepcopy(tmp_arr)

queries = []

for i in range(q):
	a, b, c, d = map(int, input().split())
	queries.append([a-1, b-1, c, d])

ans = 0

for seq in seq_arr:
	sum = 0
	
	for query in queries:
		a, b, c, d = query
		
		if seq[b] - seq[a] == c:
			sum += d
			
	ans = max(ans, sum)

print(ans)

Fixed submission:
import sys
input = sys.stdin.readline

# C - Many Requirements
import copy

n, m, q = map(int, input().split())
seq_arr = []

for i in range(1, m + 1):
	seq_arr.append([i])

for i in range(n):
	tmp_arr = []
	
	for s in seq_arr:
		for j in range(s[-1], m + 1):
			tmp_arr.append(s + [j])

	seq_arr = copy.deepcopy(tmp_arr)

queries = []

for i in range(q):
	a, b, c, d = map(int, input().split())
	queries.append([a-1, b-1, c, d])

ans = 0

for seq in seq_arr:
	sum = 0
	
	for query in queries:
		a, b, c, d = query
		
		if seq[b] - seq[a] == c:
			sum += d
			
	ans = max(ans, sum)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

# C - management
N = int(input())
A = list(map(int, input().split()))

for i in range(1, N + 1):
	print(A.count(i))

Fixed submission:
import sys
input = sys.stdin.readline

# C - management
N = int(input())
A = list(map(int, input().split()))
dic = dict()

for i in range(1, N + 1):
	dic[i] = 0

for a in A:
	dic[a] += 1

for v in dic.values():
	print(v)
Buggy python submission (verdict: Runtime Error):
# C - Sum of gcd of Tuples (Easy)

import math

K = int(input())
ans = 0

for a in range(1, K + 1):
	for b in range(1, K + 1):
		ab = math.gcd(a, b)
		
		for c in range(1, K + 1):
			ans += math.gcd(ab, c))

print(ans)

Fixed submission:
# C - Sum of gcd of Tuples (Easy)

import math

K = int(input())
ans = 0

for a in range(1, K + 1):
	for b in range(1, K + 1):
		for c in range(1, K + 1):
			ans += math.gcd(a, math.gcd(b, c))

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# C - Sum of gcd of Tuples (Easy)

import math

K = int(input())
ans = 0

for a in range(1, K + 1):
	for b in range(1, K + 1):
		for c in range(1, K + 1):
			ans += math.gcd(a, math.gcd(b, c))

print(ans)

Fixed submission:
# C - Sum of gcd of Tuples (Easy)

import math

K = int(input())
ans = 0

for a in range(1, K + 1):
	for b in range(1, K + 1):
		for c in range(1, K + 1):
			ans += math.gcd(a, math.gcd(b, c))

print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
#import clipboard

#if sys.platform == 'ios':
#	input = clipboard.get()
#else: 
	input = input()

arr = input.split()

X, Y, Z = arr
print(Z, X, Y)

	

Fixed submission:
x, y, z = input().split()
print(z, x, y)

Buggy python submission (verdict: Runtime Error):
import sys
import clipboard

if sys.platform == 'ios':
	input = clipboard.get()
else:
	input = input()

arr = input.split()

X, Y, Z = arr
print(Z, X, Y)

	

Fixed submission:
x, y, z = input().split()
print(z, x, y)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

# C - Subarray Sum
n, k, s = map(int, input().split())
ans = ''
str_s = str(s)

if s < pow(10, 9):
	str_another = str(s + 1)
else:
	str_another = 1

for i in range(n):
	if i < k:
		ans += str_s + ' '
	else:
		ans += str_another + ' '

print(ans[:len(ans)-1])

Fixed submission:
import sys
input = sys.stdin.readline

# C - Subarray Sum
n, k, s = map(int, input().split())
ans = ''
str_s = str(s)

if s < pow(10, 9):
	str_another = str(s + 1)
else:
	str_another = '1'

for i in range(n):
	if i < k:
		ans += str_s + ' '
	else:
		ans += str_another + ' '

print(ans[:len(ans)-1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

# C - Subarray Sum
n, k, s = map(int, input().split())
arr = [s] * k

for i in range(n - k):
	arr.append(s + 1)

ans = ''

for a in arr:
	ans += str(a) + ' '

print(ans)

Fixed submission:
import sys
input = sys.stdin.readline

# C - Subarray Sum
n, k, s = map(int, input().split())
ans = ''
str_s = str(s)

if s < pow(10, 9):
	str_another = str(s + 1)
else:
	str_another = '1'

for i in range(n):
	if i < k:
		ans += str_s + ' '
	else:
		ans += str_another + ' '

print(ans[:len(ans)-1])
Buggy python submission (verdict: Runtime Error):
# B - Iron Bar Cutting
N = int(input())
A = [map(int, input().split())]

left = 0
right = sum(A)
ans = right

for a in A:
	left += a
	right -= a
	
	diff = abs(right - left)
	ans = min(ans, diff)
	
	if left > right:
		break

print(ans)

Fixed submission:
# B - Iron Bar Cutting
N = int(input())
A = list(map(int, input().split()))

left = 0
right = sum(A)
ans = right

for a in A:
	left += a
	right -= a
	
	diff = abs(right - left)
	ans = min(ans, diff)
	
	if left > right:
		break

print(ans)
Buggy python submission (verdict: Runtime Error):
import sys

# A - Connection and Disconnection
import string

S = input()
K = int(input())
T = S + S[0]

lower = string.ascii_lowercase
ans = 0
is_specila_case = False

for c in lower:
	key = c * 2
	ans += T.count(key)

	if T.endswith(key):
		is_specila_case = True

ans *= K

if is_specila_case:
	print(ans - 1)
else:
	print(ans)import sys

# A - Connection and Disconnection
import string

S = input()
K = int(input())
T = S + S[0]

lower = string.ascii_lowercase
ans = 0
is_specila_case = False

for c in lower:
	key = c * 2
	ans += T.count(key)

	if T.endswith(key):
		is_specila_case = True

ans *= K

if is_specila_case:
	print(ans - 1)
else:
	print(ans)

Fixed submission:
# A - Connection and Disconnection
def count(s, c):
	count_ = s.count(c*2)
	
	while c*3 in s:
		s = s.replace(c*3, c+'_'+c)
	
	while c*2 in s:
		s = s.replace(c*2, c+'_')
	
	return min(count_, s.count('_'))


def get_startswith(s, c):
	key = c
	
	while s.startswith(key+c):
		key += c
	
	return len(key)
	
	
def get_endswith(s, c):
	key = c
	
	while s.endswith(key+c):
		key += c
	
	return len(key)


import string

S = input()
K = int(input())

lower = string.ascii_lowercase
ans = 0

if S[0] == S[-1:]:
	start = get_startswith(S, S[0])
	end = get_endswith(S, S[0])	
	
	if start == end == len(S):
		print(len(S) * K // 2)
	else:
		ans = 0
		
		ans += start // 2
		ans += end // 2
		ans += ((start + end) // 2) * (K - 1)
		
		for c in lower:
			ans += count(S[start:len(S)-end], c) * K

		print(ans)	
else:
	for c in lower:
		ans += count(S, c)

	print(ans * K)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

# C - Lower
n = int(input())
h = list(map(int, input().split()))
ans = 0

for i in range(n):
	count = 0
	
	for j in range(i, n - 1):
		if h[j] >= h[j + 1]:
			count += 1
		else:
			break
	
	ans = max(ans, count)
#	print('スタート:' + str(i), count)

print(ans)

Fixed submission:
import sys
input = sys.stdin.readline

# C - Lower
n = int(input())
h = list(map(int, input().split()))
count = 0
ans = 0

for i in range(n - 1):
	if h[i] >= h[i + 1]:
		count += 1
	else:
		count = 0

	ans = max(ans, count)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

# C - Lower
n = int(input())
h = list(map(int, input().split()))
ans = 0

for i in range(n):
	count = 0
	
	for j in range(i, n - 1):
		if h[j] >= h[j + 1]:
			count += 1
		else:
			break
	
	ans = max(ans, count)
#	print('スタート:' + str(i), count)

print(ans)

Fixed submission:
import sys
input = sys.stdin.readline

# C - Lower
n = int(input())
h = list(map(int, input().split()))
count = 0
ans = 0

for i in range(n - 1):
	if h[i] >= h[i + 1]:
		count += 1
	else:
		count = 0

	ans = max(ans, count)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

# D - ModSum
n = int(input())
ans = 0

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

print(ans)

Fixed submission:
import sys
input = sys.stdin.readline

# D - ModSum
n = int(input())

if (n-1) % 2 == 0:
	ans = n * (n-1)//2
else:
	ans = (n-1) * n//2

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

# D - ModSum
n = int(input())
ans = 0

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

print(ans)

Fixed submission:
import sys
input = sys.stdin.readline

# D - ModSum
n = int(input())

if (n-1) % 2 == 0:
	ans = n * (n-1)//2
else:
	ans = (n-1) * n//2

print(ans)
Buggy python submission (verdict: Runtime Error):
# B - KEYENCE String
def is_keyence_string():
	for i in range(1, len(key)):
		left = key[:i]
		right = key[i-len(key):]
		
		if S.startswith(left) and S.endswith(right):
			return True
	
	return False


S = input().trim()
key = 'keyence'

if S.startswith(key):
	print('YES')
elif S.endswith(key):
	print('YES')
elif is_keyence_string():
	print('YES')
else:
	print('NO')

Fixed submission:
# B - KEYENCE String
def is_keyence_string():
	for i in range(1, len(key)):
		left = key[:i]
		right = key[i-len(key):]
		
		if S.startswith(left) and S.endswith(right):
			return True
	
	return False


S = input().strip()
key = 'keyence'

if S.startswith(key):
	print('YES')
elif S.endswith(key):
	print('YES')
elif is_keyence_string():
	print('YES')
else:
	print('NO')

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

# B - KEYENCE String
def is_keyence_string():
	i = 0

	for s in S:
		if s == key[i]:
			i += 1
			if i == len(key) and S.endswith('e'):
				return True

	return False


S = input()
key = 'keyence'

if S.find(key) > -1:
	print('YES')
elif is_keyence_string():
	print('YES')
else:
	print('NO')


Fixed submission:
# B - KEYENCE String
def is_keyence_string():
	for i in range(1, len(key)):
		left = key[:i]
		right = key[i-len(key):]
		
		if S.startswith(left) and S.endswith(right):
			return True
	
	return False


S = input().strip()
key = 'keyence'

if S.startswith(key):
	print('YES')
elif S.endswith(key):
	print('YES')
elif is_keyence_string():
	print('YES')
else:
	print('NO')
Buggy python submission (verdict: Time Limit Exceeded):
import sys

# A - Two Abbreviations
def get_lcm(a, b):
	import math
	return (a * b) // math.gcd(a, b)


def is_match(X, L):
  global M
  global T

  i = 0
  m = L//M * i

  while m + 1 < L:
    if m+1 in X.keys():
      if X[m+1] != T[i]:
        return False

    i += 1
    m = L//M * i

  return True


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

if S[0] != T[0]:
  print(-1)
else:
  lcm = get_lcm(N, M)

  for i in range(1, 100):
    L = lcm * i
    X = dict()

    j = 0
    n = L//N * j

    while n + 1 < L:
      X[n+1] = S[j]

      j += 1
      n = L//N * j

    if is_match(X, L):
      print(L)
      exit()

  print(-1)

Fixed submission:
import sys

# A - Two Abbreviations
def get_lcm(a, b):
	import math
	return (a * b) // math.gcd(a, b)


def is_match(X, L):
  global M
  global T

  i = 0
  m = L//M * i

  while m + 1 < L:
    if m+1 in X.keys():
      if X[m+1] != T[i]:
        return False

    i += 1
    m = L//M * i

  return True


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

if S[0] != T[0]:
  print(-1)
else:
  lcm = get_lcm(N, M)

  for i in range(1, 100):
    L = lcm * i
    X = dict()

    j = 0
    n = L//N * j

    while n + 1 < L:
      X[n+1] = S[j]

      j += 1
      n = L//N * j

    if is_match(X, L):
      print(L)
      exit()

  print(-1)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

# A - Digit Sum 2
def digit_sum(str_num):
	sum = 0	
	
	for i in range(len(str_num)):
		sum += int(str_num[i])
	
	return sum


N = input()
patterns = [N]

for i in range(len(N)-1):
	if N[i] != '0':
		left, right = '', ''  
				
		if i > 0:
			left = N[:i]
		
		n = int(N[i]) - 1
		
		if i < len(N) - 1:
			right = '9' * (len(N)-i-1) 
		
		patterns.append(left + str(n) + right)

ans = 0

for p in patterns:
	ans = max(ans, digit_sum(p))
	
print(ans)

Fixed submission:
import sys
#input = sys.stdin.readline

# A - Digit Sum 2
def digit_sum(str_num):
	sum = 0	
	
	for i in range(len(str_num)):
		sum += int(str_num[i])
	
	return sum


N = input()
patterns = [N]

for i in range(len(N)-1):
	if N[i] != '0':
		left, right = '', ''  
				
		if i > 0:
			left = N[:i]
		
		n = int(N[i]) - 1
		
		if i < len(N) - 1:
			right = '9' * (len(N)-i-1) 
		
		patterns.append(left + str(n) + right)

ans = 0

for p in patterns:
	ans = max(ans, digit_sum(p))
	
print(ans)
Buggy python submission (verdict: Runtime Error):
# B - Shift Only
import sys
import clipboard

# テストケースが複数行の場合、iOSだと一気に読み込んでしまうので
# 1行ずつ読み込むように、テキストファイルにいったんコピーする
if sys.platform == 'ios':
	sample = clipboard.get()
	file = open('input_file.txt', 'w')
	file.write(sample)
	file.close()
	sys.stdin = open('input_file.txt')
		
						
input()
A = list(map(int, input().split()))
count = 0
while all(a % 2 == 0 for a in A):
    A = [a/2 for a in A]
    count += 1
print(count)

Fixed submission:
input()
A = list(map(int, input().split()))
count = 0

while all(a % 2 == 0 for a in A):
    A = [a/2 for a in A]
    count += 1
print(count)
Buggy python submission (verdict: Runtime Error):
# B - Problem Set
n = int(input())
d = list(map(int, input().split()))
m = int(input())
t = list(map(int, input().split()))

dic = dict()

for di in d:
	if di in dic.keys():
		dic[di] += 1
	else:
		dic[di] = 1

for ti in t:
	if not ti in dic.keys():
		print('NO')
		sys.exit()
	elif dic[ti] < 1:
		print('NO')
		sys.exit()
	else:
		dic[ti] -= 1

print('YES')

Fixed submission:
# B - Problem Set
def is_create(dic_d, t):
	for ti in t:
		if not ti in dic_d.keys():
			return False
		elif dic[ti] == 0:
			return False
		else:
			dic[ti] -= 1	
	
	return True


n = int(input())
d = list(map(int, input().split()))
m = int(input())
t = list(map(int, input().split()))

dic = dict()

for di in d:
	if di in dic.keys():
		dic[di] += 1
	else:
		dic[di] = 1

if is_create(dic, t):
	print('YES')
else:
	print('NO')