Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def same(self, x, y):
        return self.find(x) == self.find(y)

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

relations = [[0 for j in range(N)] for i in range(N)]

tree = UnionFind(N)

for i in range(M):
    a, b = list(map(int, input().split()))
    relations[a-1][b-1] = 1
    relations[b-1][a-1] = 1
    tree.union(a-1, b-1)

for i in range(K):
    c, d = list(map(int, input().split()))
    relations[c-1][d-1] = 2
    relations[d-1][c-1] = 2

cnt = []

for i in range(N):
    cnt.append(0)
    for j in range(N):
        if i == j:
            continue
        if tree.same(i, j) and relations[i][j] == 0:
            cnt[-1] += 1

print(' '.join(list(map(str, cnt))))

Fixed submission:
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        return -self.parents[self.find(x)]

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

tree = UnionFind(N)
friends = [set() for i in range(N)]
blocks = [set() for i in range(N)]

for i in range(M):
    a, b = list(map(int, input().split()))
    friends[a-1].add(b-1)
    friends[b-1].add(a-1)
    tree.union(a-1, b-1)

for i in range(K):
    c, d = list(map(int, input().split()))
    blocks[c-1].add(d-1)
    blocks[d-1].add(c-1)

cnt = []

for i in range(N):
    group_size = tree.size(i)
    friend_cnt = len(friends[i])
    block_cnt = len([j for j in blocks[i] if tree.same(i, j)])
    cnt.append(group_size - friend_cnt - block_cnt - 1)

print(' '.join(list(map(str, cnt))))
Buggy python submission (verdict: Runtime Error):
集会は数直線上の任意の 整数値の座標 で開くことができ、座標 


Fixed submission:
N = int(input())
X = list(map(int, input().split()))
sum_min = 10**8

for i in range(min(X), max(X)+1):
    s = 0
    for j in range(N):
        s += (X[j] - i)**2
    
    if s < sum_min:
        sum_min = s

print(sum_min)
Buggy python submission (verdict: Runtime Error):
def zeroTrim(s):
    while s[0] == '0':
        if len(s) == 1:
            break
        s = s[1:]
    return s

N = input()
K = int(input())

def calc(N, K):
    digit = len(N)
    res = 0

    if K == 1:
        if digit > 1:
            res += (digit - 1) * 9
        res += int(N[0])
    elif K == 2:
        if digit > 2:
            res += 9 * 9 * (digit - 1) * (digit - 2) // 2
        for i in range(int(N[0])-1):
            res += calc('9'*(digit-1), 1)
        res += calc(zeroTrim(N[1:]), 1)
    else:
        if digit > 3:
            res += 9 * 9 * 9 * (digit - 1) * (digit - 2) * (digit - 3) // 6
        
        for i in range(int(N[0])-1):
            res += calc('9'*(digit-1), 2)
        res += calc(zeroTrim(N[1:]), 2)
    return res

print(calc(N, K))

Fixed submission:
def zeroTrim(s):
    while s[0] == '0':
        if len(s) == 1:
            break
        s = s[1:]
    return s

N = input()
K = int(input())

def calc(N, K):
    digit = len(N)
    res = 0

    if K == 1:
        if digit > 1:
            res += (digit - 1) * 9
        res += int(N[0])
    elif K == 2:
        if digit <= 1:
            return 0
        if digit > 2:
            res += 9 * 9 * (digit - 1) * (digit - 2) // 2
        for i in range(int(N[0])-1):
            res += calc('9'*(digit-1), 1)
        res += calc(zeroTrim(N[1:]), 1)
    else:
        if digit <= 2:
            return 0
        if digit > 3:
            res += 9 * 9 * 9 * (digit - 1) * (digit - 2) * (digit - 3) // 6
        
        for i in range(int(N[0])-1):
            res += calc('9'*(digit-1), 2)
        res += calc(zeroTrim(N[1:]), 2)
    return res

print(calc(N, K))
Buggy python submission (verdict: Time Limit Exceeded):
import math

H, N = list(map(int, input().split()))
A = [0]*N
B = [0]*N
for i in range(N):
    A[i], B[i] = list(map(int, input().split()))

dp = [0]*(H+1)

dp[0] = 0

for i in range(1,H+1):
    dp_min = math.inf
    for j in range(N):
        dp_min = min(dp_min, dp[max(0,i-A[j])] + B[j])
    dp[i] = dp_min

print(dp[H])

Fixed submission:
import math

H, N = list(map(int, input().split()))
A = [0]*N
B = [0]*N
for i in range(N):
    A[i], B[i] = list(map(int, input().split()))

dp = [0]*(H+1)

dp[0] = 0

for i in range(1,H+1):
    dp_min = math.inf
    for j in range(N):
        dp_min = min(dp_min, dp[max(0,i-A[j])] + B[j])
    dp[i] = dp_min

print(dp[H])
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

def BFS(tree):
    color_used = [set() for _ in range(N)]
    v_dist = [-1]*N

    queue = deque([0])
    v_dist[0] = 0

    while queue:
        v = queue.popleft()
        
        for n_v in tree[v]:
            if v_dist[n_v] < 0:
                v_dist[n_v] = v_dist[v] + 1
                if colors - color_used[v] == set():
                    c_max = max(colors)
                    colors.add(c_max+1)
                    color_used[v].add(c_max+1)
                    color_used[n_v].add(c_max+1)
                    coloring[v][n_v] = c_max + 1
                else:
                    d_color = (colors - color_used[v]).pop()
                    coloring[v][n_v] = d_color
                    color_used[v].add(d_color)
                    color_used[n_v].add(d_color)
                queue.append(n_v)

N = int(input())
tree = [[] for i in range(N)]
edges = []

for i in range(N - 1):
    edges.append(tuple(map(int, input().split())))
    tree[edges[-1][0] - 1].append(edges[-1][1] - 1)
    tree[edges[-1][1] - 1].append(edges[-1][0] - 1)

coloring = [[0]*N for _ in range(N)]
colors = set([1])

BFS(tree)

print(len(colors))

for edge in edges:
    print(coloring[edge[0] - 1][edge[1] - 1])

Fixed submission:
from collections import deque

N = int(input())
tree = [[] for i in range(N)]
edges = []

for i in range(N - 1):
    edges.append(tuple(map(int, input().split())))
    tree[edges[-1][0] - 1].append(edges[-1][1] - 1)
    tree[edges[-1][1] - 1].append(edges[-1][0] - 1)

coloring = {}
c_max = 1

color_used = [0]*N
v_dist = [-1]*N

queue = deque([0])
v_dist[0] = 0

while queue:
    v = queue.popleft()
    
    c = 1
    for n_v in tree[v]:
        if v_dist[n_v] < 0:
            v_dist[n_v] = v_dist[v] + 1

            if color_used[v] == c:
                c += 1
            
            coloring[(v, n_v)] = c
            coloring[(n_v, v)] = c
            color_used[n_v] = c
            queue.append(n_v)

            c += 1
    
    c_max = max(c_max, c)

print(c_max - 1)

for edge in edges:
    print(coloring[(edge[0]-1, edge[1]-1)])
Buggy python submission (verdict: Time Limit Exceeded):
import math

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

keys = []

for i in range(M):
    a, b = list(map(int, input().split()))
    key_bit = 0
    c = list(map(int, input().split()))
    for j in range(b):
        key_bit |= 1 << (c[j] - 1)
    keys.append([a, key_bit])

dp = [[math.inf]*(1 << N) for _ in range(M + 1)]

dp[0][0] = 0

for i in range(M):
    for j in range(1 << N):
        dp[i + 1][j] = dp[i][j]
        for k in range(1 << N):
            if k | keys[i][1] == j:
                dp[i + 1][j] = min(dp[i + 1][j], dp[i][k] + keys[i][0])

if dp[M][-1] == math.inf:
    print(-1)
else:
    print(dp[M][-1])


Fixed submission:
import math

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

keys = []

for i in range(M):
    a, b = list(map(int, input().split()))
    key_bit = 0
    c = list(map(int, input().split()))
    for j in range(b):
        key_bit |= 1 << (c[j] - 1)
    keys.append([a, key_bit])

dp = [math.inf]*(1 << N)

dp[0] = 0

for i in range(M):
    for j in range(1 << N):
        dp[j | keys[i][1]] = min(dp[j | keys[i][1]], dp[j] + keys[i][0])

if dp[-1] == math.inf:
    dp[-1] = -1

print(dp[-1])
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
A = list(map(int, input().split()))

for _ in range(M):
    max_i = A.index(max(A))
    A[max_i] >>= 1

print(sum(A))

Fixed submission:
import heapq

N, M = map(int, input().split())
A = list(map(lambda x: int(x)*(-1), input().split()))

heapq.heapify(A)

for _ in range(M):
  v = heapq.heappop(A) * (-1)
  heapq.heappush(A, -(v >> 1))

print(-sum(A))
Buggy python submission (verdict: Time Limit Exceeded):
def Z_Algorithm(S):
    N = len(S)
    Z = [0]*N
    Z[0] = N
    
    i = 1   #左
    j = 0   #差分

    while i < N:
        while i + j < N and S[j] == S[j + i]:
            j += 1
        Z[i] = j

        if j == 0:
            i += 1
            continue

        k = 1   # 差分
        while k < j and k + Z[k] < j:
            Z[i + k] = Z[k]
            k += 1
        
        i += k
        j -= k
    
    return Z

def calc(S):
    N = len(S)
    Z = Z_Algorithm(S)

    res = 0
    for i in range(N):
        res = max(res, min(Z[i], i))
    
    return res

N = int(input())
S = input()

res = 0

for i in range(N):
    res = max(res, calc(S[i:]))

print(res)

Fixed submission:
def Z_Algorithm(S):
    N = len(S)
    Z = [0]*N
    Z[0] = N
    
    i = 1   #左
    j = 0   #差分

    while i < N:
        while i + j < N and S[j] == S[j + i]:
            j += 1
        Z[i] = j

        if j == 0:
            i += 1
            continue

        k = 1   # 差分
        while k < j and k + Z[k] < j:
            Z[i + k] = Z[k]
            k += 1
        
        i += k
        j -= k
    
    return Z

def calc(S):
    N = len(S)
    Z = Z_Algorithm(S)

    res = 0
    for i in range(N):
        res = max(res, min(Z[i], i))
    
    return res

N = int(input())
S = input()

res = 0

for i in range(N):
    res = max(res, calc(S[i:]))

print(res)
Buggy python submission (verdict: Time Limit Exceeded):
L, R = map(int, input().split())
p = 2019

if L - R >= p:
    print(0)
else:
    res = p
    for i in range(L, R):
        for j in range(i + 1, R + 1):
            res = min(res, i * j % p)
    print(res)

Fixed submission:
L, R = map(int, input().split())
p = 2019

if R - L >= p:
    print(0)
else:
    res = p
    for i in range(L, R):
        for j in range(i + 1, R + 1):
            res = min(res, i * j % p)
    print(res)

Buggy python submission (verdict: Time Limit Exceeded):
L, R = map(int, input().split())
p = 2019

if L - R >= p:
    print(0)
else:
    res = p
    for i in range(L, R):
        for j in range(i + 1, R + 1):
            res = min(res, i * j % p)
    print(res)

Fixed submission:
L, R = map(int, input().split())
p = 2019

if R - L >= p:
    print(0)
else:
    res = p
    for i in range(L, R):
        for j in range(i + 1, R + 1):
            res = min(res, i * j % p)
    print(res)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

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

coef_mat = np.matrix([[1 if (i == j or i + 1 == j or (i + 1 == N and j == 0)) else 0 for j in range(N) ] for i in range(N)])**(-1)
vec = np.matrix([A]).T
res = coef_mat @ vec

for i in range(N):
    print(int(res[i, 0]) * 2)

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

s = sum([A[i] * (-1) ** i for i in range(N)])

for i in range(1, N + 1):
    print(s)
    s = 2 * A[i - 1] - s
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
nums = list(map(int, input().split()))
ans = 0
mod = 10**9 + 7
for i in range(n-1):
    for j in range(i+1, n):
        ans += nums[i] * nums[j]
        ans %= mod
print(ans)


Fixed submission:
n = int(input())
nums = list(map(int, input().split()))
ans = 0
mod = 10**9 + 7
pres = [0]
for i in nums:
    pres.append(pres[-1] + i)
for i in range(n):
    temp = nums[i] * (pres[n] - pres[i+1])
    ans += temp
    ans %= mod
print(ans)
Buggy python submission (verdict: Runtime Error):
from math import gcd
from functools import reduce

M = 10 ** 6
ret = [0] * M
n = int(input())
nums = list(map(int, input().split()))
flag = 1
for i in nums:
    ret[i] += 1
for i in range(2, M):
    if sum(ret[i::i]) > 1:
        flag = 0
        break
if flag:
    print("pairwise coprime")
elif reduce(gcd, nums) == 1:
    print("setwise coprime")
else:
    print("not coprime")

Fixed submission:
from math import gcd
from functools import reduce
def main():
    N = int(input())
    A = list(map(int, input().split()))

    M = 10**6+1
    mp = [0]*M
    for a in A:
        mp[a] += 1

    pairwise = 1
    for i in range(2,M):
        if sum(mp[i::i])>1:
            pairwise = 0
            break

    if pairwise:
        print('pairwise coprime')
    elif reduce(gcd, A) == 1:
        print('setwise coprime')
    else:
        print('not coprime')

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
r, l, m = map(int, input().split())
rr, ll = [0] * r, [0] * l
tt = [[0] * l for i in range(r)]
for i in range(m):
    hi, wi = map(int, input().split())
    rr[hi-1] += 1
    ll[wi-1] += 1
    tt[hi-1][wi-1] = 1
i = rr.index(max(rr))
flag = max(ll)
ans = max(rr)
for j in range(l):
    if ll[j] == flag and tt[i][j] != 1:
        ans += flag
        print(ans)
        exit()

print(ans + flag - 1)


Fixed submission:
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  H,W,M=LI()
  h=[0]*H
  w=[0]*W
  d={}
  for _ in range(M):
    a,b=LI()
    a-=1
    b-=1
    h[a]+=1
    w[b]+=1
    d[(a,b)]=1

  h_koho=[]
  w_koho=[]

  h_max=max(h)
  w_max=max(w)

  for i,x in enumerate(h):
    if x==h_max:
      h_koho.append(i)
  for i,x in enumerate(w):
    if x==w_max:
      w_koho.append(i)

  for x in h_koho:
    for y in w_koho:
      if (x,y) not in d:
        return h_max+w_max

  return h_max+w_max-1

# main()
print(main())
Buggy python submission (verdict: Time Limit Exceeded):
x, k, d = [int(i) for i in input().split()]
x = abs(x)
if k * d <= x:
    print(x - k*d)
else:
    while x - d > 0:
        x -= d
        k -= 1
    if k & 1:
        print(d - x)
    else:
        print(x)

Fixed submission:
x, k, d = [int(i) for i in input().split()]
x = abs(x)
if k * d <= x:
    print(x - k*d)
else:
    t = x
    x %= d
    k = k - (t - x)//d
    if k & 1:
        print(abs(d - x))
    else:
        print(x)
Buggy python submission (verdict: Time Limit Exceeded):
num = int(input())
temp = num
ans = 1
while temp > 10:
    temp %= 10
# print(temp)
if temp in [1, 3, 7, 9]:
    sa = 7
    while True:
        if sa % num == 0:
            print(ans)
            break
        else:
            sa *= 10
            sa += 7
            ans += 1
else:
    print(-1) 

Fixed submission:
num = int(input())
temp = num
ans = 1
while temp > 10:
    temp %= 10
# print(temp)
if temp in [1, 3, 7, 9]:
    sa = 7
    while True:
        if sa % num == 0:
            print(ans)
            break
        else:
            sa *= 10
            sa += 7
            sa %= num
            ans += 1
else:
    print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
import heapq 
import math

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

lst = []
for i in range(n):
  lst.append([-a[i], 1])
  
heapq.heapify(lst)

for i in range(k):
  pop = heapq.heappop(lst)
  pop = [pop[0]*(pop[1])/(pop[1]+1), pop[1]+1]
  heapq.heappush(lst, pop)
  
pop = heapq.heappop(lst)
print(math.ceil(-pop[0]))

Fixed submission:
n, k = map(int, input().split())
log = list(map(int, input().split()))

left = 0
right = 10**9

while right - left > 1:
  
  mid = (left + right) // 2
  
  cut = 0
  for i in range(n):
    cut += -(log[i]//-mid)-1

  if cut > k:
    left = mid
  else:
    right = mid
    
print(right)
Buggy python submission (verdict: Time Limit Exceeded):
n, m, k = map(int, input().split())

MOD = 998244353

def mod(n):         
  return n % MOD

def modpow(a, n):   #mod(a**n)を高速で求める
    res = 1  
    digit = len(str(bin(n))) - 2
    for i in range(digit):
      if (n >> i) & 1:
        res *= mod(a)
        res = mod(res)
      a = mod(a**2)
    return mod(res)
  
def inverse(a):     #aの逆元を求める
  return modpow(a, MOD-2)

MAX = 1000000           #適当な数を入力
fac, finv, inv = [[0]*MAX for i in range(3)]
def combinit():     #MAXまでの下準備
  fac[0] = fac[1] = 1
  finv[0] = finv[1] = 1
  inv[1] = 1
  for i in range(2, MAX):
    fac[i] = fac[i - 1] * i % MOD
    inv[i] = MOD - inv[MOD%i] * (MOD // i) % MOD
    finv[i] = finv[i - 1] * inv[i] % MOD

def modcomb(n, k):      #mod(nCk)を計算、ただしn<MAX
  if (n < k):
    return 0
  if (n < 0 or k < 0):
    return 0
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD
combinit()          #下準備の実行 O(MAX)

ans = 0
for i in range(k+1):
  ans += mod(m*modpow(m-1, n-1-i)*modcomb(n-1, i))
  
print(mod(ans))

Fixed submission:
n, m, k = map(int, input().split())

MOD = 998244353

def mod(n):         
  return n % MOD

def modpow(a, n):   #mod(a**n)を高速で求める
    res = 1  
    digit = len(str(bin(n))) - 2
    for i in range(digit):
      if (n >> i) & 1:
        res *= mod(a)
        res = mod(res)
      a = mod(a**2)
    return mod(res)
  
def inverse(a):     #aの逆元を求める
  return modpow(a, MOD-2)

MAX = 1000000           #適当な数を入力
fac, finv, inv = [[0]*MAX for i in range(3)]
def combinit():     #MAXまでの下準備
  fac[0] = fac[1] = 1
  finv[0] = finv[1] = 1
  inv[1] = 1
  for i in range(2, MAX):
    fac[i] = fac[i - 1] * i % MOD
    inv[i] = MOD - inv[MOD%i] * (MOD // i) % MOD
    finv[i] = finv[i - 1] * inv[i] % MOD

def modcomb(n, k):      #mod(nCk)を計算、ただしn<MAX
  if (n < k):
    return 0
  if (n < 0 or k < 0):
    return 0
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD
combinit()          #下準備の実行 O(MAX)

ans = 0
for i in range(k+1):
  ans += mod(m*modpow(m-1, n-1-i)*modcomb(n-1, i))
  
print(mod(ans))
Buggy python submission (verdict: Time Limit Exceeded):
import sys

n = int(input())

def calc(a, b):
  return a**5 - b**5
  
for i in range(-10000, 10001):
  for j in range(-10000, 10001):
    if calc(i, j) == n:
      print(i, j)
      sys.exit()
    

Fixed submission:
import sys

n = int(input())

def calc(a, b):
  return a**5 - b**5
  
for i in range(-1000, 1001):
  for j in range(-1000, 1001):
    if calc(i, j) == n:
      print(i, j)
      sys.exit()
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = list(input())

rs = []
gs = []
bs = []

for i in range(n):
  if s[i] == "R":
    rs.append(i)
  elif s[i] == "G":
    gs.append(i)
  elif s[i] == "B":
    bs.append(i)

def binary(lst, d):
  low = 0
  high = len(lst) - 1
  while low <= high:
    mid = (low + high) // 2
    if lst[mid] == d:
      return True
    elif lst[mid] < d:
      low = mid + 1
    else:
      high = mid - 1
  return False

ans = len(rs)*len(gs)*len(bs)
for i in range(len(rs)):
  for j in range(len(gs)):
    dis = abs(rs[i] - gs[j])
    if (rs[i] + gs[j])%2 == 0:
      can1 = abs(rs[i] + gs[j])//2
      if binary(bs, can1):
      	ans -= 1
    if max(rs[i], gs[j]) + dis <= bs[-1]:
      can2 = max(rs[i], gs[j]) + dis
      if binary(bs, can2):
      	ans -= 1
    if min(rs[i], gs[j]) - dis >= 0:
      can3 = min(rs[i], gs[j]) - dis
      if binary(bs, can3):
      	ans -= 1
        
print(ans)

Fixed submission:
import sys

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

rs = []
gs = []
bs = []

for i in range(n):
  if s[i] == "R":
    rs.append(i)
  elif s[i] == "G":
    gs.append(i)
  elif s[i] == "B":
    bs.append(i)

def binary(lst, d):
  low = 0
  high = len(lst) - 1
  while low <= high:
    mid = (low + high) // 2
    if lst[mid] == d:
      return True
    elif lst[mid] < d:
      low = mid + 1
    else:
      high = mid - 1
  return False

ans = len(rs)*len(gs)*len(bs)
if len(bs) == 0:
  print(0)
  sys.exit()
for i in range(len(rs)):
  for j in range(len(gs)):
    dis = abs(rs[i] - gs[j])
    if (rs[i] + gs[j])%2 == 0:
      can1 = abs(rs[i] + gs[j])//2
      if binary(bs, can1):
      	ans -= 1
    if max(rs[i], gs[j]) + dis <= bs[-1]:
      can2 = max(rs[i], gs[j]) + dis
      if binary(bs, can2):
      	ans -= 1
    if min(rs[i], gs[j]) - dis > 0:
      can3 = min(rs[i], gs[j]) - dis
      if binary(bs, can3):
      	ans -= 1
        
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
List = list(map(int,input().split()))

def sm(lst, j, k):
  res = 0
  for i in range(j, j+k):
    res += lst[i]
  return res

def max(lst, k):
  res = sm(lst, 0, k)
  for i in range(1, N-k+1):
    if lst[i-1] < lst[i+k-1]:
      if res < sm(lst, i, k):
        res = sm(lst, i, k)
  res = (res+k)/2
  return res

print(max(List, K))

Fixed submission:
N,K = map(int,input().split())
List = list(map(int,input().split()))

def sm(lst, j, k):
  return lst[j+k]-lst[j]

def max(lst, k):
  sumlst = [0]
  for i in range(len(lst)):
    sumlst.append(sumlst[i]+lst[i])
  res = 0
  for i in range(N-k+1):
    if res < sm(sumlst, i, k):
      res = sm(sumlst, i, k)
  res = (res+k)/2
  return res

print(max(List, K))

Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
List = list(map(int,input().split()))

def sm(lst, j, k):
  res = 0
  for i in range(j, j+k):
    res += lst[i]
  return res

def max(lst, k):
  res = 0
  for i in range(N-k+1):
    if res < sm(lst, i, k):
      res = sm(lst, i, k)
  res = (res+k)/2
  return res

print(max(List, K))
    

Fixed submission:
N,K = map(int,input().split())
List = list(map(int,input().split()))

def sm(lst, j, k):
  return lst[j+k]-lst[j]

def max(lst, k):
  sumlst = [0]
  for i in range(len(lst)):
    sumlst.append(sumlst[i]+lst[i])
  res = 0
  for i in range(N-k+1):
    if res < sm(sumlst, i, k):
      res = sm(sumlst, i, k)
  res = (res+k)/2
  return res

print(max(List, K))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ans = 0

lst = [[0]*10 for i in range(10)]

for i in range(1, 10):
  for j in range(1, 10):
    for k in range(1, n+1):
      top = int(str(k)[0])
      bottom = k % 10
      if top == i and bottom == j:
        lst[i][j] += 1

ans = 0
for i in range(10):
  for j in range(10):
     ans += lst[i][j]*lst[j][i]

print(ans)

Fixed submission:
n = int(input())
ans = 0

for i in range(1, n+1):
  m = len(str(i))
  top = int(str(i)[0])
  bottom = i % 10
  counter = 0
  if bottom*top == 0:
    continue
  if top == bottom:
    counter += 1
  for j in range(1, 7):
    left = bottom*(10**j) + top
    right = bottom*(10**j) + top + 10**j - 10
 
    if n < left:
      break
    elif left <= n and n <= right:
      counter += (n - left) // 10 + 1
      break
    elif right < n:
      counter += 10**(j-1)
  ans += counter
  
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
X = int(input())

def notco(x, lst):
  for i in range(len(lst)):
    if x % lst[i] == 0:
      return False
  return True

def minp(x):
  primes = [2]
  i = 3
  while(primes[len(primes)-1] < x):
    if notco(i, primes):
      primes.append(i)
    i += 1
  return primes[len(primes)-1]

print(minp(X))

Fixed submission:
X = int(input())

def isprime(x):
  for i in range(2, x//2+1):
    if x % i == 0:
      return False
  return True

def minp(x):
  res = x
  while True:
    if isprime(res):
      return res
    res += 1

print(minp(X))