ZhenlongDai/ACPR huggingface dataset:
Problem: p03427
Buggy submission (Python (3.8.2), verdict: Wrong Answer):

def maxf(n):
    a = list(map(int, list(n)))
    for i, item in enumerate(a):
        if i == 0 and item != 9:
            if a[i+1:] == [9]*(len(a)-1):break
            a[i] -=1
            a[i+1:] = [9]*(len(a)-1)
            break
        elif item != 9:
            a[i-1] -= 1
            a[i:] = [9]*(len(a)-i)
            break
    return a, sum(a)

print(maxf(input()))


Failing test case input:
60659243882

Expected output:
95


Actual output:
([5, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9], 95)


Fixed submission (verdict: Accepted):
def maxf(n):
    a = list(map(int, list(n)))
    for i, item in enumerate(a):
        if i == 0 and item != 9:
            if a[i+1:] == [9]*(len(a)-1):break
            a[i] -=1
            a[i+1:] = [9]*(len(a)-1)
            break
        elif item != 9:
            a[i-1] -= 1
            a[i:] = [9]*(len(a)-i)
            break
    return sum(a)

print(maxf(input()))

Problem: p03427
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
in0 = int(str(N)[0])
Nl = len(str(N))
print(9 * Nl) if (N + 1) % 10 * Nl == 0 else print(in0 - 1 + (Nl - 1) * 9)


Failing test case input:
9622586956629

Expected output:
116


Actual output:
117


Fixed submission (verdict: Accepted):
N = int(input())
in0 = int(str(N)[0])
Nl = len(str(N))
if (N + 1) % 10 ** (Nl-1) == 0:
    print(9 * (Nl - 1) + in0)
else:
    print(in0 - 1 + (Nl - 1) * 9)

Problem: p03427
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = list(map(str, input().split()))
print(max(sum([int(i) for i in N]), 9*(len(N)-1)+int(N[0])-1))


Failing test case input:
38747

Expected output:
38


Actual output:
38747


Fixed submission (verdict: Accepted):
N = list(map(str, input().rstrip()))
print(max(sum([int(i) for i in N]), 9*(len(N)-1)+int(N[0])-1))

Problem: p03427
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = list(map(int, list(input().strip())))
print(n)

total = sum(n)

for i in range(len(n)):
    subtotal = 0
    for j in range(i - 1):
        subtotal += n[j]
    subtotal += n[i] - 1
    for k in range(i + 1, len(n)):
        subtotal += 9

    total = max(total, subtotal)

print(total)


Failing test case input:
1972226448

Expected output:
81


Actual output:
[1, 9, 7, 2, 2, 2, 6, 4, 4, 8]
81


Fixed submission (verdict: Accepted):
n = list(map(int, list(input().strip())))

total = sum(n)

for i in range(len(n)):
    subtotal = 0
    for j in range(i - 1):
        subtotal += n[j]
    subtotal += n[i] - 1
    for k in range(i + 1, len(n)):
        subtotal += 9

    total = max(total, subtotal)

print(total)
Problem: p03427
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = input()
N_list = list(N)
N = int(N)
K = len(N_list)

ans = int(N_list[0])+(K-1)*9
ans_list = [N_list[0]] + ['9' for _ in range(K-1)]
ans_cand = int(''.join(ans_list))
print(ans_cand)
if N < ans_cand:
    print(ans - 1)
else:
    print(ans)

Failing test case input:
486488932393

Expected output:
102


Actual output:
499999999999
102


Fixed submission (verdict: Accepted):
N = input()
N_list = list(N)
N = int(N)
K = len(N_list)

ans = int(N_list[0])+(K-1)*9
ans_list = [N_list[0]] + ['9' for _ in range(K-1)]
ans_cand = int(''.join(ans_list))
if N < ans_cand:
    print(ans - 1)
else:
    print(ans)

Problem: p03427
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def main():
    N = input()
    tmp = 10 ** (len(N) - 1) - 1
    res_ = int(tmp)

    if tmp == 0:
        print(N)
        return

    for i in range(1, 10):
        j = i*10**len(N) + tmp
        if j <= int(N):
            res_ = j

    res = 0
    for x in str(res_):
        res += int(x)
    print(res)


if __name__ == '__main__':
    main()


Failing test case input:
432463594998478

Expected output:
129


Actual output:
126


Fixed submission (verdict: Accepted):
def main():
    N = input()
    tmp = 10 ** (len(N) - 1) - 1
    res_ = int(tmp)
    if tmp == 0:
        print(N)
        return

    for i in range(1, 10):
        if int(str(i) + str(tmp)) <= int(N):
            res_ = int(str(i) + str(tmp))

    res = 0
    for x in str(res_):
        res += int(x)
    print(res)


if __name__ == '__main__':
    main()

Problem: p03427
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = list(map(int, input().split()))
print(max(sum(n), n[0]-1+9*(len(n)-1)))

Failing test case input:
6928151062547

Expected output:
113


Actual output:
6928151062547


Fixed submission (verdict: Accepted):
ns = list(map(int, list(input())))
print(max(sum(ns), ns[0]-1 + 9*(len(ns)-1)))
Problem: p03427
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys

if __name__ == '__main__':
    
    
    
    n = input()

    ary = list(map(int, list(str(n))))

    
    if len(ary) == 1:
       print(sum(ary))
       sys.exit()

    
    if len(ary) == 2:
        if sum(ary) <= 9:
            print(9)
            sys.exit()
        else:
            print(sum(ary))
            sys.exit()

    
    ary[1:-1] = [9 for i in range(0, len(ary[1:-1]))]

    
    if ary[1:-1].count(9) != len(ary[1:-1]):
        ary[0] = ary[0] - 1

    
    if sum(ary[-2:]) < 18:
        ary[-2] = 8
        ary[-1] = 9

    print(ary)
    print(sum(ary))


Failing test case input:
812

Expected output:
25


Actual output:
[8, 8, 9]
25


Fixed submission (verdict: Accepted):
import sys

if __name__ == '__main__':
    
    
    
    n = input()

    ary = list(map(int, list(str(n))))

    
    if len(ary) == 1:
       print(sum(ary))
       sys.exit()

    
    if len(ary) == 2:
        if sum(ary) <= 9:
            print(9)
            sys.exit()
        else:
            print(sum(ary))
            sys.exit()

    
    if ary[1:-1].count(9) != len(ary[1:-1]):
        ary[0] = ary[0] - 1
        ary[-2] = 9
        ary[-1] = 9

    
    ary[1:-1] = [9 for i in range(0, len(ary[1:-1]))]

    
    if sum(ary[-2:]) < 18:
        ary[-2] = 8
        ary[-1] = 9

    
    print(sum(ary))

Problem: p03427
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = input()
Dig = len(N)
num = None
if Dig == 1:
    print(N)
else:
    for i in range(Dig-1):
        if N[i] != str(9) and N[i+1] != str(9):
            num = i
            break
        else:
            continue
    list_num = list(N)
    if num:
        target = int(list_num[num]) -1
        ans = 9*(num -1) + target + 9*(Dig)
        print(ans)
    else:
        array = list(map(int,N))
        print(sum(array))
    

Failing test case input:
195117

Expected output:
45


Actual output:
67


Fixed submission (verdict: Accepted):
N = input()
Dig = len(N)
num = None
if Dig == 1:
    print(N)
else:
    for i in range(Dig-1):
        if N[i+1] != str(9):
            num = i
            break
        else:
            continue
    list_num = list(N)
    if not num == None:
        target = int(list_num[num]) -1
        array = list(map(int,N))
        ans = sum(array[:num]) + target + 9*(Dig-num-1)
        print(ans)
    else:
        array = list(map(int,N))
        print(sum(array))
Problem: p03427
Buggy submission (Python (3.4.3), verdict: Wrong Answer):



S = (input())

if S.count("9") == len(S):
    print(len(S)*9)

elif len(S) == 1:
    print(int(S))

elif S.count("9") == (len(S)-1):
    print((int(S[0])) + (len(S)-1)*9)

elif S[0] == "9":
    print(8 + ((len(S)-1)*9))
else:
    print((int(S[0])-1) + (len(S)-1)*9)

Failing test case input:
9995

Expected output:
35

Actual output:
36


Fixed submission (verdict: Accepted):



S = (input())

if S.count("9") == len(S):
    print(len(S)*9)

elif len(S) == 1:
    print(int(S))

elif S.count("9") == (len(S)-1) and (S[0]!="9"):
    print((int(S[0])) + (len(S)-1)*9)

elif S[0] == "9":
    print(8 + ((len(S)-1)*9))
else:
    print((int(S[0])-1) + (len(S)-1)*9)

Problem: p03427
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = list(input())
l = len(n)

for i in range(l):
    n[i] = int(n[i])

score = 0
p = True

if l == 1:
    print(n[0])
else:
    while p == True:
        for j in range(l):
            if n[j] != 9:
                if j == l-1:
                    score += 8
                else:
                    score += n[j] - 1
                    score += 9*(l-j-1)
                break
            else:
                score += 9
        p = False
    print(score)

Failing test case input:
979408779978155

Expected output:
134


Actual output:
132


Fixed submission (verdict: Accepted):
n = list(input())
l = len(n)

for i in range(l):
    n[i] = int(n[i])

score = 0

if l == 1:
    print(n[0])
else:
    if n.count(9) == l:
        score = sum(n)
    elif n.count(9) == l-1:
        if n[0] != 9:
            score += sum(n)
        else:
            score += 8 + 9*(l-1)
    else:
        if n[0] != 9:
            score += n[0]-1 + 9*(l-1)
        else:
            for j in range(l):
                if n[j] != 9:
                    n[j-1] = 8
                    score += 8 + 9*(l-1)
                    break
    print(score)

Problem: p03427
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = input(); a = 0; b = 0; c = 0
for i in range(len(n)):
    if n[i] != "9":
        if a == 0: a += 1; b = i; c = int(n[i])
        else: a += 1
if a == 0: print(9*len(n))
elif a == 1 and b == 0: print(c+9*(len(n)-1))
else: print(9*len(n)-1)

Failing test case input:
31754391545

Expected output:
92


Actual output:
98


Fixed submission (verdict: Accepted):
n = input(); a = 0; b = 0; c = int(n[0])
for i in range(len(n)):
    if n[i] != "9":
        if a == 0: a += 1; b = i
        else: a += 1
if a == 0: print(9*len(n))
elif a == 1 and b == 0: print(c+9*(len(n)-1))
else: print(c-1+9*(len(n)-1))
Problem: p03427
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = input()
Dig = len(N)
num = None
if Dig == 1:
    print(N)
else:
    for i in range(Dig-1):
        if N[i+1] != str(9):
            num = i
            break
        else:
            continue
    list_num = list(N)
    if not num == None:
        target = int(list_num[num]) -1
        ans = 9*(num) + target + 9*(Dig-num-1)
        print(ans)
    else:
        array = list(map(int,N))
        print(sum(array))

Failing test case input:
29339807685297

Expected output:
118


Actual output:
125


Fixed submission (verdict: Accepted):
N = input()
Dig = len(N)
num = None
if Dig == 1:
    print(N)
else:
    for i in range(Dig-1):
        if N[i+1] != str(9):
            num = i
            break
        else:
            continue
    list_num = list(N)
    if not num == None:
        target = int(list_num[num]) -1
        array = list(map(int,N))
        ans = sum(array[:num]) + target + 9*(Dig-num-1)
        print(ans)
    else:
        array = list(map(int,N))
        print(sum(array))

Problem: p03427
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
number = input()
length = len(number)
t = True
ans = 0
for i in range(length):
    if i > 0 and number[i] != '9':
        t = False
    ans += int(number[i])

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

Failing test case input:
825031311641

Expected output:
106


Actual output:
34


Fixed submission (verdict: Accepted):
number = input()
length = len(number)
t = True
ans = 0
for i in range(length):
    if i > 0 and number[i] != '9':
        t = False
    if i == 0:
        ans += int(number[i])
    else:
        ans += 9

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

Problem: p03427
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = input()

if set(list(n)) == {'9'}:
    print(len(list(n))*9)
    exit()

tmp = ''
for i in range(1,len(n)):
    if n[i] == '9':
        tmp += n[i-1]
        print(tmp)
    else:
        n[i]!= '9'
        tmp += str(int(n[i-1])-1) + '9'*(len(n)-i)
        break
else:
    tmp += '9'

ans=0
for i in range(len(tmp)):
    ans += int(tmp[i]) 

print(ans)


Failing test case input:
29243813

Expected output:
64


Actual output:
2
64


Fixed submission (verdict: Accepted):
n = input()

if len(list(n)) == 1:
    print(int(n))
    exit()

if set(list(n)) == {'9'}:
    print(len(list(n))*9)
    exit()

tmp = ''
for i in range(1,len(n)):
    if n[i] == '9':
        tmp += n[i-1]
    else:
        tmp += str(int(n[i-1])-1) + '9'*(len(n)-i)
        break
else:
    tmp += '9'

ans=0
for i in range(len(tmp)):
    ans += int(tmp[i]) 

print(ans)
Problem: p03427
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = input()
if len(s) == 1:
    print(s)
else:
    t = set(s)
    if len(t) == 1 and "9" in t:
        print(len(s) * 9)
    elif len(t) == 2 and "9" in t:
        k = sorted(list(t))
        print((len(s) - 1) * 9 + int(k[0]))
    else:
        print(int(s[0]) + (len(s) - 1) * 9 - 1)

Failing test case input:
9995

Expected output:
35

Actual output:
32


Fixed submission (verdict: Accepted):
s = input()
if len(s) == 1:
    print(s)
else:
    t = set(s)
    if len(t) == 1 and "9" in t:
        print(len(s) * 9)
    elif len(t) == 2 and "9" in t and "0" not in t:
        if s[0] != "9":
            k = sorted(list(t))
            print((len(s) - 1) * 9 + int(k[0]))
        else:
            print((len(s) - 1) * 9 + 8)
    else:
        print(int(s[0]) + (len(s) - 1) * 9 - 1)

Problem: p03427
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
ans = ""
a = input()
num_len = len(a)
num = [k for k in a]
for i in range(1,num_len):
  if num[i] != "9":
    num[i-1]= chr(ord(num[i-1])-1)
    if num[i-1] == "0":
      num[i-1] = ""
    for j in range(i,num_len):
      num[j] = "9"
    break
for w in num:
  ans = ans + w
print(ans)

Failing test case input:
9622586956629

Expected output:
116


Actual output:
8999999999999


Fixed submission (verdict: Accepted):
ans = 0
a = input()
num_len = len(a)
num = [k for k in a]
for i in range(1,num_len):
  if num[i] != "9":
    num[i-1]= chr(ord(num[i-1])-1)
    for j in range(i,num_len):
      num[j] = "9"
    break
for w in num:
  ans = ans + int(w)
print(ans)

Problem: p03427
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = list(map(int, input().split()))
print(max((len(n)-1)*9 + n[0]-1, sum(n)))

Failing test case input:
7682704416

Expected output:
87


Actual output:
7682704416


Fixed submission (verdict: Accepted):
ns = list(map(int, list(input())))
print(max(sum(ns), ns[0]-1 + 9*(len(ns)-1)))

Problem: p03427
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = [int(i) for i in list(input())]
length = len(N)

for l in N[:1]:
    if not l==9:
        ans = (length-1)*9+(N[0]-1)
        print(ans)
        break
else:
    print(sum(N))


Failing test case input:
99367823906

Expected output:
98


Actual output:
62


Fixed submission (verdict: Accepted):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = [int(i) for i in list(input())]
length = len(N)

for l in N[1:]:
    if not l==9:
        ans = (length-1)*9+(N[0]-1)
        print(ans)
        break
else:
    print(sum(N))
Problem: p03427
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = input()
l = len(n)

if int(n)>=10:
    ans = 9*(l-1)+int(n[0])-1
    if n[0]=="9": ans+=1
else: ans = int(n)

print(ans)

Failing test case input:
99367823906

Expected output:
98


Actual output:
99


Fixed submission (verdict: Accepted):
n = input()
list = [10**i for i in range(1,20)]

if int(n)>=10:
    ans = 9*(len(n)-1)+int(n[0])-1
    if (int(n[1:])+1) in list: ans+=1
else: ans = int(n)

print(ans)

Problem: p03427
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from sys import exit, setrecursionlimit
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import bisect

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

setrecursionlimit(1000000)

N = input()

if len(N) == 1:
  print(int(N[0]))
else:
  if N[1] == '9':
    print(int(N[0]) + (len(N)-1)*9)
  else:
    print(int(N[0])-1 + (len(N)-1)*9)


Failing test case input:
195117

Expected output:
45


Actual output:
46


Fixed submission (verdict: Accepted):
from sys import exit, stderr, setrecursionlimit
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import bisect

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

setrecursionlimit(1000000)

N = [int(c) for c in input()]
L = len(N)

if all(N[i] == 9 for i in range(1, L)):
  print(sum(N))
else:
  print((N[0]-1) + 9 * (L-1))

Problem: p03427
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = input()
n0 = int(n[0])
ln = len(n)
if ln == 1:
  print(n0)
elif n[1:] == "9"*(ln-1):
  print(n0+9*(ln-1))
else:
  print(n0+9*(ln-1)-1)

print("9"*(ln-1))
print(n[1:-1])

Failing test case input:
9622586956629

Expected output:
116


Actual output:
116
999999999999
62258695662


Fixed submission (verdict: Accepted):
n = input()
n0 = int(n[0])
ln = len(n)
if ln == 1:
  print(n0)
elif n[1:] == "9"*(ln-1):
  print(n0+9*(ln-1))
else:
  print(n0+9*(ln-1)-1)
Problem: p03427
Buggy submission (Python (3.4.3), verdict: Wrong Answer):


N = int(input().split()[0])
n_list = [int(char) for char in str(N)]

if N % 10 == 0:
    ans = 9 * len(n_list[1:])
else:
    total_1 = sum(n_list)
    n_list_2 = n_list[:]
    target_idx = -1
    for i, n in enumerate(n_list):
        if n == 9:
            continue
        else:
            if n != 0:
                target_idx = i
            break
    if target_idx != -1:
        if target_idx == 0:
            n_list_2[0] = n_list[0] - 1
            if len(n_list) > 2:
                n_list_2[1:] = [9] * len(n_list_2[1:])
        else:
            n_list_2[target_idx - 1] = n_list[target_idx - 1] - 1
            n_list_2[target_idx:] = [9] * len(n_list_2[target_idx:])
    total_2 = sum(n_list_2)
    ans = max(total_2, total_1)

print(ans)


Failing test case input:
361209486590

Expected output:
101


Actual output:
99


Fixed submission (verdict: Accepted):


N = int(input().split()[0])
n_list = [int(char) for char in str(N)]

if n_list[0] == 1 and N % 10 == 0:
    ans = 9 * len(n_list[1:])
else:
    total_1 = sum(n_list)
    n_list_2 = n_list[:]
    target_idx = -1
    for i, n in enumerate(n_list):
        if n == 9:
            continue
        else:
            if n != 0:
                target_idx = i
            break
    if target_idx != -1:
        if target_idx == 0:
            n_list_2[0] = n_list[0] - 1
            if len(n_list) > 2:
                n_list_2[1:] = [9] * len(n_list_2[1:])
        else:
            n_list_2[target_idx - 1] = n_list[target_idx - 1] - 1
            n_list_2[target_idx:] = [9] * len(n_list_2[target_idx:])
    total_2 = sum(n_list_2)
    ans = max(total_2, total_1)

print(ans)

Problem: p03427
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = input()

tmp = ''
for i in range(1,len(n)):
    if n[i] == '9':
        tmp += '9'
    else:
        n[i]!= '9'
        tmp += str(int(n[i-1])-1) + '9'*(len(n)-i)
        break

ans=0
for i in range(len(tmp)):
    ans += int(tmp[i]) 

print(ans)


Failing test case input:
4974

Expected output:
30


Actual output:
35


Fixed submission (verdict: Accepted):
n = input()

if len(list(n)) == 1:
    print(int(n))
    exit()

if set(list(n)) == {'9'}:
    print(len(list(n))*9)
    exit()

tmp = ''
for i in range(1,len(n)):
    if n[i] == '9':
        tmp += n[i-1]
    else:
        tmp += str(int(n[i-1])-1) + '9'*(len(n)-i)
        break
else:
    tmp += '9'

ans=0
for i in range(len(tmp)):
    ans += int(tmp[i]) 

print(ans)

Problem: p03427
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N=list(map(int,input()))
L=len(N)

ans1=9*(L-1)
ans2=sum(N)
for i in range(L-1):
    if N[i]>N[i+1]:
        N[i]=N[i]-1
        for j in range(i+1,L):
            N[j]=9
        break

ans3=sum(N)

print(max(ans1,ans2,ans3))

Failing test case input:
8874258397

Expected output:
88


Actual output:
87


Fixed submission (verdict: Accepted):
N=list(map(int,input()))
L=len(N)

ans1=9*(L-1)+N[0]-1

for i in range(L-1):
    if N[i]>N[i+1]:
        N[i]=N[i]-1
        for j in range(i+1,L):
            N[j]=9
        break

ans2=sum(N)

print(max(ans1,ans2))
Problem: p03427
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
X = list(map(int,input()))
print(X)
sn = []
for i in range(len(X)):
  sn.append(sum(X[0:i+1]))
ssn = []
for i in range(len(X)):
  ssn.append(sn[i]-1 + 9*(len(X)-1-i))
print(max(ssn))

Failing test case input:
595158033928

Expected output:
103


Actual output:
[5, 9, 5, 1, 5, 8, 0, 3, 3, 9, 2, 8]
103


Fixed submission (verdict: Accepted):
X = list(map(int,input()))
sn = []
for i in range(len(X)):
  sn.append(sum(X[0:i+1]))
ssn = []
for i in range(len(X)):
  if (sn[i] != 0):
    ssn.append(sn[i]-1 + 9*(len(X)-1-i))
ssn.append(sum(X))
print(max(ssn))

Problem: p03427
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = input()
Dig = len(N)
num = None
if Dig == 1:
    print(N)
else:
    for i in range(Dig-1):
        if N[i+1] != str(9):
            num = i
            print(num)
            break
        else:
            continue
    list_num = list(N)
    if not num == None:
        target = int(list_num[num]) -1
        array = list(map(int,N))
        print(target)
        ans = sum(array[:num]) + target + 9*(Dig-num-1)
        print(ans)
    else:
        array = list(map(int,N))
        print(sum(array))

Failing test case input:
5097659651

Expected output:
85


Actual output:
0
4
85


Fixed submission (verdict: Accepted):
N = input()
Dig = len(N)
num = None
if Dig == 1:
    print(N)
else:
    for i in range(Dig-1):
        if N[i+1] != str(9):
            num = i
            break
        else:
            continue
    list_num = list(N)
    if not num == None:
        target = int(list_num[num]) -1
        array = list(map(int,N))
        ans = sum(array[:num]) + target + 9*(Dig-num-1)
        print(ans)
    else:
        array = list(map(int,N))
        print(sum(array))

Problem: p03427
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
 
for i in range(10):
	if n >= int(str(i) + '9'*(len(str(n))-1)):
		print(i + 9*(len(str(n))-1))
		break
		

Failing test case input:
635750078564

Expected output:
104


Actual output:
99


Fixed submission (verdict: Accepted):
n = int(input())
 
for i in range(10)[::-1]:
	if n >= int(str(i) + '9'*(len(str(n))-1)):
		print(i + 9*(len(str(n))-1))
		break

Problem: p03427
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = input(); a = 0; b = 0; c = 0
for i in range(len(n)):
    if n[i] != "9":
        if a == 0: a += 1; b = i; c = int(n[i])
        else: a += 1
if a == 0: print(9*len(n))
elif a == 1 and b == 0: print(c+9*(len(n)-1))
else: print(c-1+9*(len(n)-1))

Failing test case input:
979408779978155

Expected output:
134


Actual output:
132


Fixed submission (verdict: Accepted):
n = input(); a = 0; b = 0; c = int(n[0])
for i in range(len(n)):
    if n[i] != "9":
        if a == 0: a += 1; b = i
        else: a += 1
if a == 0: print(9*len(n))
elif a == 1 and b == 0: print(c+9*(len(n)-1))
else: print(c-1+9*(len(n)-1))
Problem: p03427
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = list(input())
l = len(n)

for i in range(l):
    n[i] = int(n[i])

score = 0
p = True

if l == 1:
    print(n[0])
else:
    while p == True:
        for j in range(l):
            if n[j] != 9:
                p = False
                score += n[j] - 1
                score += 9*(l-j-1)
                break
            else:
                score += 9
        p = False
    print(score)

Failing test case input:
9995

Expected output:
35

Actual output:
31


Fixed submission (verdict: Accepted):
n = list(input())
l = len(n)

for i in range(l):
    n[i] = int(n[i])

score = 0

if l == 1:
    print(n[0])
else:
    if n.count(9) == l:
        score = sum(n)
    elif n.count(9) == l-1:
        if n[0] != 9:
            score += sum(n)
        else:
            score += 8 + 9*(l-1)
    else:
        if n[0] != 9:
            score += n[0]-1 + 9*(l-1)
        else:
            for j in range(l):
                if n[j] != 9:
                    n[j-1] = 8
                    score += 8 + 9*(l-1)
                    break
    print(score)

Problem: p03427
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = input()
Dig = len(N)
num = None
if Dig == 1:
    print(N)
else:
    for i in range(Dig-1):
        if N[i] != str(9) and N[i+1] != str(9):
            num = i
            print(num)
            break
        else:
            continue
    list_num = list(N)
    if num:
        target = int(list_num[num]) -1
        ans = 9*(num -1) + target + 9*(Dig)
        print(ans)
    else:
        array = list(map(int,N))
        print(sum(array))
    

Failing test case input:
208775777

Expected output:
73


Actual output:
0
50


Fixed submission (verdict: Accepted):
N = input()
Dig = len(N)
num = None
if Dig == 1:
    print(N)
else:
    for i in range(Dig-1):
        if N[i+1] != str(9):
            num = i
            break
        else:
            continue
    list_num = list(N)
    if not num == None:
        target = int(list_num[num]) -1
        array = list(map(int,N))
        ans = sum(array[:num]) + target + 9*(Dig-num-1)
        print(ans)
    else:
        array = list(map(int,N))
        print(sum(array))

Problem: p03427
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = input()
N_row = len(N)
while True:
  if N_row == 1:
    print(int(N))
    break
  else:
    N = list(N)
    a = int(N[0])
    b = int(N[-1])
    for i in range(N_row):
      if not int(N[i]) == 9:
        sum = (a-1) + 9*(N_row-1)  
        print(sum)
        break
      else:
        sum = a + 9*(N_row-1)
        print(sum)
        break
    break

Failing test case input:
979408779978155

Expected output:
134


Actual output:
135


Fixed submission (verdict: Accepted):
N = input()
N_row = len(N)
while True:
  if N_row == 1:
    print(int(N))
    break
  else:
    N = list(N)
    a = int(N[0])
    b = int(N[-1])
    for i in range(1, N_row):
      if not int(N[i]) == 9:
        sum = (a-1) + 9*(N_row-1) 
        print(sum)
        break
    else:
      sum = a + 9*(N_row-1)
      print(sum)
      break
  break
Problem: p03427
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())

def digit_sum_simple(n):
    
    max_sum = -1

    for i in range(10**(len(str(n))-1)-1, n+1):
        
        i_parts = []
        for i_part in str(i):
            i_parts.append(int(i_part))

        this_sum = sum(i_parts)
        
        if max_sum < this_sum:
            max_sum = this_sum
            max_sum_i = i

    return max_sum

def digit_sum_temp(n):
    
    max_sum, one_num_max_sum = divmod(n+1, 10)
    if 0 <= n < 9:
        return one_num_max_sum-1
    else:
        return max_sum+8

print(digit_sum_temp(n))

Failing test case input:
17693906

Expected output:
63


Actual output:
1769398


Fixed submission (verdict: Accepted):
n = int(input())

def digit_sum_simple(n):
    
    max_sum = -1

    for i in range(10**(len(str(n))-1)-1, n+1):
        
        i_parts = []
        for i_part in str(i):
            i_parts.append(int(i_part))

        this_sum = sum(i_parts)
        
        if max_sum < this_sum:
            max_sum = this_sum
            max_sum_i = i

    return max_sum, max_sum_i

def digit_sum_temp(n):
    max_sum_i = int(str(int(str(n+1)[0])-1) + "9"*(len(str(n+1))-1))
    max_sum = sum([int(j) for j in str(max_sum_i)])

    return max_sum

print(digit_sum_temp(n))

Problem: p03427
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = list(input())

if len(n) == 1:
    print(n[0])
elif n[0] == '1':
    print(9 * (len(n) - 1))
elif n.count('9') == len(n):
    print(9 * len(n))
elif n.count('9') == len(n) - 1:
    if n[0] != 9:
        print((int(n[0])) + (9 * (len(n) - 1)))
    else:
        print(9 * (len(n) - 1) + 8)
else:
    print((int(n[0]) - 1 ) + (9 * (len(n) - 1))) 

Failing test case input:
9995

Expected output:
35

Actual output:
36


Fixed submission (verdict: Accepted):
n = list(input())

if len(n) == 1:
    print(n[0])
elif n[0] == '1':
    if n.count('9') == len(n) - 1:
        print(1 + 9 * (len(n) - 1))
    else:
        print(9 * (len(n) - 1))
elif n.count('9') == len(n):
    print(9 * len(n))
elif n.count('9') == len(n) - 1:
    if n[0] != '9':
        print((int(n[0])) + (9 * (len(n) - 1)))
    else:
        print(9 * (len(n) - 1) + 8)
else:
    print((int(n[0]) - 1 ) + (9 * (len(n) - 1)))

Problem: p03427
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def main():
    n = input()
    sum = 0
    for i, c in enumerate(n):
        if c == '9':
            sum += 9
        elif i == len(n) - 1:
            sum += int(c)
        else:
            sum += int(c) - 1
            sum += 9 * (len(n) - i - 1)
            print(sum)
            return
    print(sum)


if __name__ == '__main__':
    main()


Failing test case input:
93936078956105

Expected output:
125


Actual output:
119


Fixed submission (verdict: Accepted):
def main():
    n = input()
    if len(n) == 1:
        print(n)
        return
    if set(n[1:]) == {'9'}:
        print(int(n[0]) + 9 * (len(n) - 1))
        return

    for i, c in enumerate(n):
        if c != '9':
            print(9 * (len(n) - 1) + int(n[0]) - 1)
            return
    else:
        print(9 * len(n))


if __name__ == '__main__':
    main()
Problem: p03427
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def solve():
    N = list(map(int, list(input())))
    print(N)

    res = 0
    for i in range(len(N)):
        tmp = 0
        for j in range(len(N)):
            if j <= i-1:
                tmp += N[j]
            elif j==i:
                tmp += N[j]-1
            else:
                tmp += 9
        res = max(res, tmp)

    print(res)


if __name__ == "__main__":
    solve()




Failing test case input:
9995

Expected output:
35

Actual output:
[9, 9, 9, 5]
35


Fixed submission (verdict: Accepted):
def solve():
    I = input()
    N = list(map(int, list(I)))

    res = sum(N)

    for i in range(len(N)):
        tmp = 0
        for j in range(len(N)):
            if j <= i-1:
                tmp += N[j]
            elif j==i:
                tmp += N[j]-1
            else:
                tmp += 9
        res = max(res, tmp)

    print(res)


if __name__ == "__main__":
    solve()

Problem: p03427
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N=input()

if len(N)==1:
    print(N)
    exit()

def calc(str):
    l=list(map(int,str))
    all=sum(l)
    
    return all

cand1=str(int(N)-int(N[-1])-1)
cand2=str(int(N[0])*10**(len(N)-1)-1)

print(cand1,cand2,N)
print(max(calc(cand1),calc(cand2),calc(N)))

Failing test case input:
292707137157503

Expected output:
127


Actual output:
292707137157499 199999999999999 292707137157503
127


Fixed submission (verdict: Accepted):
N=input()

if len(N)==1:
    print(N)
    exit()

def calc(str):
    l=list(map(int,str))
    all=sum(l)
    
    return all

cand1=str(int(N)-int(N[-1])-1)
cand2=str(int(N[0])*10**(len(N)-1)-1)

print(max(calc(cand1),calc(cand2),calc(N)))

Problem: p03427
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N=int(input())
S=str(N)
flag=False 

for i in range(1,len(S)):
    
    if S[i]!="9":
        flag=False
        break
else:
    flag=True

if flag:
    print(N)
else:
    top=int(S[0])-1
    if top==0:
        top_s=""
    else:
        top_s=str(top)
    nokori = str(9)*(len(S)-1)
    print(top_s+nokori)

Failing test case input:
3722

Expected output:
29


Actual output:
2999


Fixed submission (verdict: Accepted):
N=int(input())
S=str(N)
flag=False 

for i in range(1,len(S)):
    
    if S[i]!="9":
        flag=False
        break
else:
    flag=True

if flag:
    print( int(S[0]) + 9*(len(S)-1) )
else:
    top=int(S[0])-1
    print(top + 9*(len(S)-1))
Problem: p03427
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = input()
if len(s) == 1:
    print(s)
else:
    t = set(s)
    if len(t) == 1 and "9" in t:
        print(len(s) * 9)
    elif len(t) == 2 and "9" in t and "0" not in t:
        k = sorted(list(t))
        print((len(s) - 1) * 9 + int(k[0]))
    else:
        print(int(s[0]) + (len(s) - 1) * 9 - 1)

Failing test case input:
9995

Expected output:
35

Actual output:
32


Fixed submission (verdict: Accepted):
s = input()
if len(s) == 1:
    print(s)
else:
    t = set(s)
    if len(t) == 1 and "9" in t:
        print(len(s) * 9)
    elif len(t) == 2 and "9" in t and "0" not in t:
        if s[0] != "9":
            k = sorted(list(t))
            print((len(s) - 1) * 9 + int(k[0]))
        else:
            print((len(s) - 1) * 9 + 8)
    else:
        print(int(s[0]) + (len(s) - 1) * 9 - 1)

Problem: p03427
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N=input()
M=int(N[0:2])
L=len(N[2:])*9
K=0
for i in range(int(M+1)):
	j=str(i)
	if len(j)==1:
		K=max(K,(int(j)))
	else:
		K=max(K,(int(j[0])+int(j[1])))
print(K+L)

Failing test case input:
1909031865550

Expected output:
108


Actual output:
109


Fixed submission (verdict: Accepted):
N=input()
M=int(N[0:2])
L=len(N[2:])*9
K=0
sum=0
for i in range(len(N)):
	sum+=int(N[i])
K=0
if L>0:
	D=M
else:
	D=M+1
for i in range(D):
	j=str(i)
	if len(j)==1:
		K=max(K,(int(j)))
	else:
		K=max(K,(int(j[0])+int(j[1])))
print(max(sum,K+L))

Problem: p03427
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n=input()

l=len(n)
if int(n)>9:
  ans=[9]
else:
  print(int(n))
  exit()
tmp=n[l-1]
for i in range(2,l+1):
  
  if int(tmp) != 9:
    tmp=int(n[l-i])-1
    
  if i==l:
    ans.append(int(tmp))
  else:
    ans.append(9)
  
print(sum(ans))

Failing test case input:
359

Expected output:
20


Actual output:
27


Fixed submission (verdict: Accepted):
n=input()

l=len(n)
if int(n)>9:
  ans=[9]
else:
  print(int(n))
  exit()
tmp=n[l-1]
for i in range(2,l+1):
  
  if int(tmp) != 9:
    tmp=int(n[l-i])-1
    
  else:
    tmp=int(n[l-i])
  if i==l:
    ans.append(int(tmp))
  else:
    ans.append(9)
  
print(sum(ans))

Problem: p03427
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s=input()
print(max(int(s),int(s[0])-1+9*len(s)-9))

Failing test case input:
613

Expected output:
23


Actual output:
613


Fixed submission (verdict: Accepted):
s=input()
print(max(sum(map(int,list(s))),int(s[0])-1+9*len(s)-9))
Problem: p03427
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = input()
if int(s) < 10: print(s); exit()

ans = -1
for i in range(len(s)):
    t = s[:i]
    NINE = (len(s)-len(t))
    SUB = 0
    t+= '9' * NINE
    if int(s) < int(t): SUB = int('1' + '0' * NINE)
    t = max(int(t) - SUB, 0)
    ans = max(ans, sum(int(c) for c in str(t)))
    print(t)
print(ans)

Failing test case input:
61158

Expected output:
41


Actual output:
0
59999
60999
61099
61149
41


Fixed submission (verdict: Accepted):
s = input()
if int(s) < 10: print(s); exit()

ans = -1
for i in range(len(s)):
    t = s[:i]
    NINE = (len(s)-len(t))
    SUB = 0
    t+= '9' * NINE
    if int(s) < int(t): SUB = int('1' + '0' * NINE)
    t = max(int(t) - SUB, 0)
    ans = max(ans, sum(int(c) for c in str(t)))
print(ans)

Problem: p03427
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import bisect
N = int(input())
if len(str(N)) == 1:
    print(N)
    exit()
L = len(list(str(N)))-1
A = [10**(L)*i+10**(L)-1 for i in range(10)]  
n = bisect.bisect_left(A,N)-1
if N in A:
    n += 1
ans = [int(list(str(A[n]))[i]) for i in range(len(list(str(A[n]))))]
print(sum(ans))
print(A)

Failing test case input:
3052173209686

Expected output:
110


Actual output:
110
[999999999999, 1999999999999, 2999999999999, 3999999999999, 4999999999999, 5999999999999, 6999999999999, 7999999999999, 8999999999999, 9999999999999]


Fixed submission (verdict: Accepted):
import bisect
N = int(input())
if len(str(N)) == 1:
    print(N)
    exit()
L = len(list(str(N)))-1
A = [10**(L)*i+10**(L)-1 for i in range(10)]  
n = bisect.bisect_left(A,N)-1
if N in A:
    n += 1
ans = [int(list(str(A[n]))[i]) for i in range(len(list(str(A[n]))))]
print(sum(ans))

Problem: p03427
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
num = str(N)
for i in range(1,len(num)):
    if num[-i] != 9 and 0 < N - (int(num[-i]) + 1) * 10**(i-1):
        N -= (int(num[-i]) + 1) * 10**(i-1)
        num = str(N)

D = 0
for digit in str(N):
    D += int(digit)

print(D)


Failing test case input:
3052173209686

Expected output:
110


Actual output:
109


Fixed submission (verdict: Accepted):
N = int(input())
num = str(N)
for i in range(1,len(num)):
    if num[-i] != "9" and 0 < N - (int(num[-i]) + 1) * 10**(i-1):
        N -= (int(num[-i]) + 1) * 10**(i-1)
        num = str(N)

D = 0
for digit in str(N):
    D += int(digit)

print(D)

Problem: p03427
Buggy submission (Python (3.8.2), verdict: Wrong Answer):

N = input()
N_i = int(N)
N_s = list(N)


for i in range(0,17):
  if N_i < 10 ** i:
    break
flag = True
for j in range(0,i-1):
  if N_s[j] != "9":
    flag = False
    break

if flag == True:
  
   print(int(N_s[0])+9*(len(N_s)-1))
else:
   print(int(N_s[0])+9*(len(N_s)-1)-1)


Failing test case input:
9995

Expected output:
35

Actual output:
36


Fixed submission (verdict: Accepted):
N = input()
N_i = int(N)
N_s = list(N)


for i in range(0,17):
  if N_i < 10 ** i:
    break
flag = True
for j in range(1,i):
  if N_s[j] != "9":
    flag = False
    break

if flag == True:
  
   print(int(N_s[0])+9*(len(N_s)-1))
else:
   print(int(N_s[0])+9*(len(N_s)-1)-1)
Problem: p03427
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = input()
n = N

if len(N) == 1:
    print(N)
    exit()

if N[1:].count('9') == len(N)-1:
    print(N)
    exit()

if N[0]!='9' or any(map(lambda x:x!='9',N)):
    n = chr(ord(N[0])-1) + N[1:]



ans = int(n[0]+"9"*(len(n)-1))

print(int(N),ans)
if int(N) >= ans:
    print(sum([int(i) for i in str(ans)]))
else:
    print(sum([int(i) for i in str(ans)]) -1)


Failing test case input:
486488932393

Expected output:
102


Actual output:
486488932393 399999999999
102


Fixed submission (verdict: Accepted):
N = input()
n = N

if len(N) == 1:
    print(N)
    exit()

if N[1:].count('9') == len(N)-1:
    print(sum([int(i) for i in N]))
    exit()

if N[0]!='9' or any(map(lambda x:x!='9',N)):
    n = chr(ord(N[0])-1) + N[1:]



ans = int(n[0]+"9"*(len(n)-1))


if int(N) >= ans:
    print(sum([int(i) for i in str(ans)]))
else:
    print(sum([int(i) for i in str(ans)]) -1)

Problem: p03427
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = input()
i_N = int(N)
if len(N) == 1:
    print(N)
    exit()
ans = (len(N) - 1) * 9
if N[0] != '9':
    ans += int(N[0]) - 1
else:
    for i in range(1, len(N)):
        if N[i] != '9':
            ans += int(N[i - 1]) - 1
            break
    else:
        ans += 9
if ans > i_N:
    print(ans)
else:
    print(i_N)


Failing test case input:
46243

Expected output:
39


Actual output:
46243


Fixed submission (verdict: Accepted):
N = input()
i_N = 0
for i in range(len(N)):
    i_N += int(N[i])
if len(N) == 1:
    print(N)
    exit()
ans = (len(N) - 1) * 9
if N[0] != '9':
    ans += int(N[0]) - 1
else:
    for i in range(1, len(N)):
        if N[i] != '9':
            ans += int(N[i - 1]) - 1
            break
    else:
        ans += 9
if ans > i_N:
    print(ans)
else:
    print(i_N)

Problem: p03427
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N=input()
S=[]
for i in range(len(N)):
    S.append(int(N[i]))
if int(N)<10:
    print(N)
elif int(N[0])!=9 and int(N[-1])!=9:
    print(9*(len(N)-1)+int(N[0])-1)
elif int(N[0])==9: print(9*len(N))
elif int(N[-1])==9: print(sum(S))


Failing test case input:
13486242447349

Expected output:
117


Actual output:
61


Fixed submission (verdict: Accepted):
N=input()
S=[]
for i in range(len(N)):
    S.append(int(N[i]))

T=sum(S)

if int(N)<10:
    print(N)
elif 9*(len(S)-1)+S[0]-1 >= T:
    print(9*(len(S)-1)+S[0]-1)
elif S[-1]==9: print(T)
elif S[0]==9: print(9*len(S))

Problem: p03427
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
len = len(str(N))
a = list(str(N))
b =0
for i in range(1,len)[::-1]:
  if a[i] == -1:
    a[i] == '9'
  if a[i] != '9':
    b += (int(a[i])+1) * (10**(len-1-i))
    a[i-1] = str(int(a[i-1])-1)
print(N-b)

Failing test case input:
794978750514868

Expected output:
132


Actual output:
699999999999999


Fixed submission (verdict: Accepted):
N = int(input())
len = len(str(N))
a = list(str(N))
b =0
for i in range(1,len)[::-1]:
  if a[i] == -1:
    a[i] == '9'
  if a[i] != '9':
    b += (int(a[i])+1) * (10**(len-1-i))
    a[i-1] = str(int(a[i-1])-1)
a = list(str(N-b))
b = 0
for i in a:
  b += int(i)
print(b)
Problem: p03576
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
[n,k]=i2()
x=[]
y=[]
for i in range(n):
 z=i2()
 x.append(z[0])
 y.append(z[1])
x.sort()
y.sort()
a=float("inf")
for i in range(n):
 for j in range(i,n):
  for kk in range(n):
    for l in range(kk,n):
      if min(j-i+1,l-kk+1)==k:
       a=min(a,(x[j]-x[i])*(y[l]-y[kk]))  
print(a)

Failing test case input:
4 3
-1000000000 -1000000000
1000000000 1001000000
-999999999 999999999
359410750 -533981871

Expected output:
2718821498640589250


Actual output:
2086670856492513250


Fixed submission (verdict: Accepted):
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
[n,k]=i2()
x=[]
y=[]
zz=[]
for i in range(n):
 z=i2()
 x.append([z[0],i])
 y.append([z[1],i])
 zz.append(z)
x.sort()
y.sort()
xx=[i[1] for i in x]
yy=[i[1] for i in y]
a=float("inf")
for i in range(n):
 for j in range(i,n):
  for kk in range(n):
   for l in range(kk,n):
     if len(set(xx[i:j+1])&set(yy[kk:l+1]))==k:
         a=min(a,(zz[xx[j]][0]-zz[xx[i]][0])*(zz[yy[l]][1]-zz[yy[kk]][1]))
print(a)

Problem: p03576
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N,K=map(int,input().split())
xy=[]
X=[]
Y=[]
for i in range(N):
    x,y=map(int,input().split())
    xy.append([x,y])
xy.sort()
X=[i[0] for i in xy]
Y=[i[1] for i in xy]
ans=10**30
for i in range(K,N+1):
    for j in range(N+1-i):
        X_=X[j:j+i]
        Y_=Y[j:j+i]
        a=max(X_)-min(X_)
        b=max(Y_)-min(Y_)
        ans=min(ans,a*b)
print(ans)


Failing test case input:
4 2
-285176710 -1000000000
1000010000 1101000110
-180621794 999999999
187396551 -1579906993

Expected output:
119243942244129134


Actual output:
209109831895445084


Fixed submission (verdict: Accepted):
N,K=map(int,input().split())
xy=[]
X=[]
Y=[]
for i in range(N):
    x,y=map(int,input().split())
    xy.append([x,y])
xy.sort()
X=[i[0] for i in xy]
Y=[i[1] for i in xy]
ans=10**30
for i in range(K,N+1):
    for j in range(N+1-i):
        X_=X[j:j+i]
        Y_=Y[j:j+i]
        Y_.sort()
        a=max(X_)-min(X_)
        for k in range(i-K+1):
            z=Y_[k:k+K]
            b=max(z)-min(z)
            ans=min(ans,a*b)
print(ans)
Problem: p03576
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N, K = map(int, input().split())
XY = [list(map(int, input().split())) for _ in range(N)]

XY.sort()


answer = []
for i in range(N):
  if i + K - 1 == N:
    break
  dx = XY[i + K - 1][0] - XY[i][0]
  y_max = -1
  y_min = 10 ** 15
  for x, y in XY[i: i + K]:
    y_max = max(y_max, y)
    y_min = min(y_min, y)
  dy = y_max - y_min
  answer.append(dx * dy)

print(min(answer))

Failing test case input:
4 2
-285176710 -1265818351
1000010001 1101000100
-180621794 165132749
153204588 -999999999

Expected output:
116529794181980896


Actual output:
149612972060607600


Fixed submission (verdict: Accepted):
N, K = map(int, input().split())
XY = [list(map(int, input().split())) for _ in range(N)]

XY.sort()


answer = []
for i in range(N):
  for k in range(K, N + 1):
    if i + k - 1 >= N:
      break
    dx = XY[i + k - 1][0] - XY[i][0]
    Y = []
    for x, y in XY[i: i + k]:
      Y.append(y)
    Y.sort()
    lenY = len(Y)
    for j in range(k):
      if j + K - 1 == lenY:
        break
      dy = Y[j + K - 1] - Y[j]
      answer.append(dx * dy)

print(min(answer))

Problem: p03576
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N, K = map(int, input().split())
XY = sorted([tuple(map(int, input().split())) for _ in range(N)])

ans = 10 ** 20
for xl in range(N):
    for xr in range(xl + 1, N):
        Ysub = sorted([y for x, y in XY[xl:xr + 1]])
        for i in range(xr - xl - K + 2):
            ans = min(ans, (XY[xr][0] - XY[xl][0]) * (max(Ysub) - min(Ysub)))

print(ans)


Failing test case input:
4 2
-1000000000 -1000000000
1000001000 1001010000
-88510709 1459564405
47904587 -999999999

Expected output:
1047904587


Actual output:
335522206202723584


Fixed submission (verdict: Accepted):
N, K = map(int, input().split())
XY = sorted([tuple(map(int, input().split())) for _ in range(N)])

ans = 10 ** 20
for xl in range(N):
    for xr in range(xl + 1, N):
        Ysub = sorted([y for x, y in XY[xl:xr + 1]])
        for i in range(xr - xl - K + 2):
            Yk = Ysub[i:i + K] + [XY[xr][1], XY[xl][1]]
            ans = min(ans, (XY[xr][0] - XY[xl][0]) * (max(Yk) - min(Yk)))

print(ans)

Problem: p03576
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,k=map(int,input().split())
z=sorted(list(map(int,input().split()))for _ in range(n))
a=10**30
for i,j in zip(range(n),range(k-1,n)):
    m,M=10**18,-10**18
    for(_,b)in z[i:j+1]:
        m=min(m,b)
        M=max(M,b)
    a=min(a,(M-m)*(z[j][0]-z[i][0]))
print(a)

Failing test case input:
4 2
-285176710 -1265818351
1000010001 1101000100
-180621794 165132749
153204588 -999999999

Expected output:
116529794181980896


Actual output:
149612972060607600


Fixed submission (verdict: Accepted):
n,k=map(int,input().split())
z=[list(map(int,input().split()))for _ in range(n)]
z.sort()
a=10**20
for i in range(n):
    for j in range(i+1,n):
        x=z[j][0]-z[i][0]
        l=sorted(t[1]for t in z[i:j+1])
        for u,v in zip(l,l[k-1:]):
            a=min(a,x*(v-u))
print(a)
Problem: p03576
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import sys
input = sys.stdin.readline
def inputs():return [int(x) for x in input().split()]
N,K = inputs()
xy = [inputs() for _ in range(N)]

xy = sorted(xy,key=lambda x: x[0])

ans = 10**20
for i in range(N-K+1):
  for j in range(i+K-1,N):
    
    xy1 = xy[i:j+1]
    
    xy1 = sorted(xy1,key=lambda x: x[1])
    ans = min(ans,(xy[j][0]-xy[i][0])*(xy1[K-1][1]-xy1[0][1]))
print(ans)
    
    

Failing test case input:
4 2
-1000000000 -1000000000
1000010000 1001000000
-185930883 999999999
195439962 -1679731405

Expected output:
1185942068940883


Actual output:
812578084963406610


Fixed submission (verdict: Accepted):
import sys
input = sys.stdin.readline
def inputs():return [int(x) for x in input().split()]
N,K = inputs()
xy = [inputs() for _ in range(N)]

xy = sorted(xy,key=lambda x: x[0])

ans = 10**20
for i in range(N-K+1):
  for j in range(i+K-1,N):
    
    xy1 = xy[i:j+1]
    
    xy1 = sorted(xy1,key=lambda x: x[1])
    mi = min(xy1[i+K-1][1]-xy1[i][1] for i in range(len(xy1)-K+1))
    ans = min(ans,(xy[j][0]-xy[i][0])*mi)
print(ans)

Problem: p03576
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N, K = map(int, input().split())
pos = sorted([tuple(map(int, input().split())) for _ in range(N)], key=lambda x: x[0])
ans = 10 ** 37
for i in range(N-K+1):
    max_y = (-1) * 10 ** 9 - 1
    min_y = 10 ** 9 + 1
    for j in range(K):
        y = pos[i+j][1]
        max_y = max(max_y, y)
        min_y = min(min_y, y)
    ans = min(ans, (pos[i+K-1][0] - pos[i][0]) * (max_y - min_y))
print(ans)


Failing test case input:
4 2
-270973418 -1000000000
1000110000 1011000000
-185930883 999999999
35685613 -1679731405

Expected output:
13046450899040883


Actual output:
170085069914957465


Fixed submission (verdict: Accepted):
from itertools import combinations
N, K = map(int, input().split())
dots = sorted([tuple(map(int, input().split())) for _ in range(N)], key=lambda x: x[0])

ans = 10 ** 37
for i in range(N):
    for j in range(i+K-1, N):
        width = dots[j][0] - dots[i][0]
        y = sorted([l for _, l in dots[i:j+1]])
        for a, b in zip(y, y[K-1:]):
            height = b - a
            ans = min(ans, width*height)

print(ans)