Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N, C = map(int, input().split())
D = [list(map(int, input().split())) for i in range(C)]
c = [list(map(int, input().split())) for i in range(N)]

cost0 = []
cost1 = []
cost2 = []
indices = [2, 0, 1]
for color in range(C):
  cost = [0, 0, 0]
  for i in range(N):
    idx = indices[i%3]
    for j in range(N):
      cost[idx] += D[c[i][j]-1][color]
      idx = (idx + 1) % 3
  cost0.append([cost[0], color])
  cost1.append([cost[1], color])
  cost2.append([cost[2], color])

cost0.sort()
cost1.sort()
cost2.sort()
ans = float('inf')
for i in range(3):
  for j in range(3):
    for k in range(3):
      if len(set([cost0[i][1], cost1[j][1], cost2[k][1]])) == 3:
        ans = min(ans, cost0[i][0]+cost1[j][0]+cost2[k][0])

print(ans)

Fixed submission:
N, C = map(int, input().split())
D = [list(map(int, input().split())) for i in range(C)]
c = [list(map(int, input().split())) for i in range(N)]

cost0 = []
cost1 = []
cost2 = []
indices = [2, 0, 1]
for color in range(C):
  cost = [0, 0, 0]
  for i in range(N):
    idx = indices[i%3]
    for j in range(N):
      cost[idx] += D[c[i][j]-1][color]
      idx = (idx + 1) % 3
  cost0.append([cost[0], color])
  cost1.append([cost[1], color])
  cost2.append([cost[2], color])

cost0.sort()
cost1.sort()
cost2.sort()
ans = float('inf')
for i in range(3):
  for j in range(3):
    for k in range(3):
      if len(set([cost0[i][1], cost1[j][1], cost2[k][1]])) == 3:
        ans = min(ans, cost0[i][0]+cost1[j][0]+cost2[k][0])

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools

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

# 全探索だと間に合わない
# 一旦実装だけしてみる
corres = list(itertools.permutations(range(C), 3))
ans = float('inf')
indices = [2, 0, 1]
for corr in corres:
  cost = 0
  for i in range(N):
    idx = indices[i%3]
    for j in range(N):
      cost += D[c[i][j]-1][corr[idx]]
      idx = (idx + 1) % 3
  ans = min(ans, cost)

print(ans)

Fixed submission:
N, C = map(int, input().split())
D = [list(map(int, input().split())) for i in range(C)]
c = [list(map(int, input().split())) for i in range(N)]

cost0 = []
cost1 = []
cost2 = []
indices = [2, 0, 1]
for color in range(C):
  cost = [0, 0, 0]
  for i in range(N):
    idx = indices[i%3]
    for j in range(N):
      cost[idx] += D[c[i][j]-1][color]
      idx = (idx + 1) % 3
  cost0.append([cost[0], color])
  cost1.append([cost[1], color])
  cost2.append([cost[2], color])

cost0.sort()
cost1.sort()
cost2.sort()
ans = float('inf')
for i in range(3):
  for j in range(3):
    for k in range(3):
      if len(set([cost0[i][1], cost1[j][1], cost2[k][1]])) == 3:
        ans = min(ans, cost0[i][0]+cost1[j][0]+cost2[k][0])

print(ans)
Buggy python submission (verdict: Runtime Error):
ABC = sorted(map(int, input().split()))
K = int(input().split())
print(sum(ABC[:2] + ABC[-1:]*2**K))

Fixed submission:
ABC = sorted(map(int, input().split()))
K = int(input())
print(sum(ABC[:2] + ABC[-1:]*2**K))
Buggy python submission (verdict: Runtime Error):
N, X = map(intm input().split())
m = [int(input()) for i in range(N)]
X -= sum(m)
ans = N
ans += X // min(m)
print(ans)

Fixed submission:
N, X = map(int, input().split())
m = [int(input()) for i in range(N)]
X -= sum(m)
ans = N
ans += X // min(m)
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = [0] + list(map(int, input().split()))
diff = []
for i in range(N):
  diff.append(abs(A[i]-A[i+1]))

diff.append(abs(A[-1]))a

A += [0]
s = sum(diff)
for i in range(N):
  v = s - diff[i] - diff[i+1]
  v += abs(A[i] - A[i+2])
  print(v)

Fixed submission:
N = int(input())
A = [0] + list(map(int, input().split()))
diff = []
for i in range(N):
  diff.append(abs(A[i]-A[i+1]))

diff.append(abs(A[-1]))

A += [0]
s = sum(diff)
for i in range(N):
  v = s - diff[i] - diff[i+1]
  v += abs(A[i] - A[i+2])
  print(v)
Buggy python submission (verdict: Runtime Error):
N = int(input()) % 500
if A >= N:
  print('Yes')
else:
  print('No')

Fixed submission:
N = int(input()) % 500
if int(input()) >= N:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())

Map = [[[0]*K for i in range(K)] for j in range(2)]
for i in range(N):
  x, y, c = input().split()
  x, y = int(x), int(y)
  if c == 'B':
    c = 0
  else:
    c = 1
  nx, ny = x//K, y//K
  if (nx + ny) % 2:
    c = 1 - c
  x %= K
  y %= K
  Map[c][x][y] += 1

def get_v(c, x, y):
  global Map
  if x < 0 or y < 0:
    return 0
  else:
    return Map[c][x][y]

for c in range(2):
  for x in range(K):
    for y in range(K):
      Map[c][x][y] += get_v(c, x-1, y) + get_v(c, x, y-1) - get_v(c, x-1, y-1)

ans = 0
for x in range(K+1):
  for y in range(K+1):
    b2 = get_v(0, x-1, K-1) + get_v(0, K-1, y-1) - 2*get_v(0, x-1, y-1)
    w1 = get_v(1, x-1, K-1) + get_v(1, K-1, y-1) - 2*get_v(1, x-1, y-1)
    b1 = Map[0][K-1][K-1] - b2
    w2 = Map[1][K-1][K-1] - w1
    ans = max(ans, b1+w1, b2+w2)

print(ans)

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

Map = [[[0]*K for i in range(K)] for j in range(2)]
for i in range(N):
  x, y, c = input().split()
  x, y = int(x), int(y)
  if c == 'B':
    c = 0
  else:
    c = 1
  nx, ny = x//K, y//K
  if (nx + ny) % 2:
    c = 1 - c
  x %= K
  y %= K
  Map[c][x][y] += 1

def get_v(c, x, y):
  global Map
  if x < 0 or y < 0:
    return 0
  else:
    return Map[c][x][y]

for c in range(2):
  for x in range(K):
    for y in range(K):
      Map[c][x][y] += get_v(c, x-1, y) + get_v(c, x, y-1) - get_v(c, x-1, y-1)

ans = 0
for x in range(K+1):
  for y in range(K+1):
    b2 = get_v(0, x-1, K-1) + get_v(0, K-1, y-1) - 2*get_v(0, x-1, y-1)
    w1 = get_v(1, x-1, K-1) + get_v(1, K-1, y-1) - 2*get_v(1, x-1, y-1)
    b1 = Map[0][K-1][K-1] - b2
    w2 = Map[1][K-1][K-1] - w1
    ans = max(ans, b1+w1, b2+w2)

print(ans)
Buggy python submission (verdict: Runtime Error):
from collections import Counter

N = int(input())
c = Counter(list(map(int, input())))
ans = 0
for k in c:
  ans += d[k] - k if k <= d[k] else d[k]

print(ans)

Fixed submission:
from collections import Counter

N = int(input())
c = Counter(list(map(int, input().split())))
ans = 0
for k in c:
  ans += c[k] - k if k <= c[k] else c[k]

print(ans)
Buggy python submission (verdict: Runtime Error):
N = input()
f = sum(map(int, list(N)))
if N // f == 0:
  print('Yes')
else:
  print('No')

Fixed submission:
N = input()
f = sum(map(int, list(N)))
if int(N) % f == 0:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict

N = int(input())
D = list(map(int, input().split()))
kind = defaultdict(int)
for d in D:
  kind[d] += 1

M = int(input())
T = list(map(int, input().split()))
for t in T:
  d[t] -= 1
  if d[t] < 0:
    print('NO')
    quit()

print('YES')

Fixed submission:
from collections import defaultdict

N = int(input())
D = list(map(int, input().split()))
kind = defaultdict(int)
for d in D:
  kind[d] += 1

M = int(input())
T = list(map(int, input().split()))
for t in T:
  kind[t] -= 1
  if kind[t] < 0:
    print('NO')
    quit()

print('YES')
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

if N%2 == 0:
  print(N, N, N//2)
else:
  for h in range(3500, -1, -1):
    num = N*h*3501; diff_num = N*h
    dem = 4*h*3501 - N*(h+3501); diff_dem = 4*h - N
    for n in range(3500, -1, -1):
      num -= diff_num
      dem -= diff_dem
      if dem <= 0:
        break
      if num%dem == 0:
        print(h, n, num//dem)
        quit()

Fixed submission:
N = int(input())

if N%2 == 0:
  print(N, N, N//2)
else:
  for h in range(1, 3501):
    for n in range(1, 3501):
      num = N*h*n
      dem = 4*h*n - N*(h+n)
      if dem > 0 and num%dem == 0:
        print(h, n, num//dem)
        quit()

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

if N%2 == 0:
  print(N, N, N//2)
else:
  for h in range(3500, -1, -1):
    for n in range(3500, -1, -1):
      num = N*h*n
      dem = 4*h*n - N*(h+n)
      if dem <= 0:
        break
      if dem > 0 and num%dem == 0:
        print(h, n, num//dem)
        quit()

Fixed submission:
N = int(input())

if N%2 == 0:
  print(N, N, N//2)
else:
  for h in range(1, 3501):
    for n in range(1, 3501):
      num = N*h*n
      dem = 4*h*n - N*(h+n)
      if dem > 0 and num%dem == 0:
        print(h, n, num//dem)
        quit()

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

if N%2 == 0:
  print(N, N, N//2)
else:
  for h in range(1, 3501):
    for n in range(1, 3501):
      num = N*h*n
      dem = 4*h*n - N*(h+n)
      if dem > 0 and num%dem == 0:
        print(h, n, num//dem)
        quit()

Fixed submission:
N = int(input())

if N%2 == 0:
  print(N, N, N//2)
else:
  for h in range(1, 3501):
    for n in range(1, 3501):
      num = N*h*n
      dem = 4*h*n - N*(h+n)
      if dem > 0 and num%dem == 0:
        print(h, n, num//dem)
        quit()
Buggy python submission (verdict: Runtime Error):
N = int(input().split())
ans = 0
for i in range(N):
  l, r = map(int, input().split())
  ans += (r - l + 1)

print(ans)

Fixed submission:
N = int(input())
ans = 0
for i in range(N):
  l, r = map(int, input().split())
  ans += (r - l + 1)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

H, W, K = map(int, input().split())
A = [input() for h in range(H)]

for h in range(H):
  for w in range(W):
    if A[h][w] == 'S':
      sx, sy = h, w

INF = 1000
dist = [[INF for w in range(W)] for h in range(H)]
dist[sx][sy] = 0


dxy = [[1, 0], [0, 1], [-1, 0], [0, -1]]
start = []
d = deque([[sx, sy]])
while d:
  x, y = d.popleft()
  for dx, dy in dxy:
    xx = x + dx; yy = y + dy
    if 0<=xx<H and 0<=yy<W and dist[xx][yy]==INF:
      if A[xx][yy] == '.':
        dist[xx][yy] = dist[x][y] + 1
        d.append([xx, yy])
        if dist[xx][yy] <= K:
          start.append([xx, yy])

ans = min(-(-(H-1-sx)//K)+1, -(-sx//K)+1, -(-(W-1-sy)//K)+1, -(-sy//K)+1)
for x, y in start:
  ans = min(ans, -(-(W-1 - y)//K) + 1) # 右
  ans = min(ans, -(-y//K) + 1) # 左
  ans = min(ans, -(-(H-1 - x)//K) + 1) # 下
  ans = min(ans, -(-x//K) + 1) # 上

print(ans)

Fixed submission:
from collections import deque

H, W, K = map(int, input().split())
A = [input() for h in range(H)]

for h in range(H):
  for w in range(W):
    if A[h][w] == 'S':
      sx, sy = h, w

INF = 1000
dist = [[INF for w in range(W)] for h in range(H)]
dist[sx][sy] = 0


dxy = [[1, 0], [0, 1], [-1, 0], [0, -1]]
start = []
d = deque([[sx, sy]])
while d:
  x, y = d.popleft()
  for dx, dy in dxy:
    xx = x + dx; yy = y + dy
    if 0<=xx<H and 0<=yy<W and dist[xx][yy]==INF:
      if A[xx][yy] == '.':
        dist[xx][yy] = dist[x][y] + 1
        d.append([xx, yy])
        if dist[xx][yy] <= K:
          start.append([xx, yy])

ans = min(-(-(H-1-sx)//K)+1, -(-sx//K)+1, -(-(W-1-sy)//K)+1, -(-sy//K)+1)
for x, y in start:
  ans = min(ans, -(-(W-1 - y)//K) + 1) # 右
  ans = min(ans, -(-y//K) + 1) # 左
  ans = min(ans, -(-(H-1 - x)//K) + 1) # 下
  ans = min(ans, -(-x//K) + 1) # 上

print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
alpha = list('abcdefghijklmnopqrstuvwxyz')
num_s = dict(zip(alpha, [50]*len(alpha)))

for i in range(n):
  S = input()
  d = dict(zip(alpha, [0]*len(alpha)))
  for s in S:
    d[s] += 1
  for s in d:
    num_s[s] = min(num_s[s], d[s])

ans = ''
for s in num_s:
  ans += s*num_s[0]

print(''.join(sorted(ans)))

Fixed submission:
n = int(input())
alpha = list('abcdefghijklmnopqrstuvwxyz')
num_s = dict(zip(alpha, [50]*len(alpha)))

for i in range(n):
  S = input()
  d = dict(zip(alpha, [0]*len(alpha)))
  for s in S:
    d[s] += 1
  for s in d:
    num_s[s] = min(num_s[s], d[s])

ans = ''
for s in num_s:
  ans += s*num_s[s]

print(''.join(sorted(ans)))
Buggy python submission (verdict: Runtime Error):
def another(s):
  if s == 'D':
    return 'H'
  else:
    return 'D'

a, b = map(int, input().split())
if a == 'H':
  print(b)
else:
  print(another(b))

Fixed submission:
def another(s):
  if s == 'D':
    return 'H'
  else:
    return 'D'

a, b = input().split()
if a == 'H':
  print(b)
else:
  print(another(b))
Buggy python submission (verdict: Runtime Error):
W, a, b = map(int, input().split())
if a <= b <= a + W or a <= b + W <= a + W:
  prin(0)
  quit()

print(abs(a+W - b), abs(b+w - a))

Fixed submission:
W, a, b = map(int, input().split())
if a <= b <= a + W or a <= b + W <= a + W:
  print(0)
  quit()

print(min(abs(a+W - b), abs(b+W - a)))
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = list(map(int, input().split()))
B = []
for a in A:
  if a < K:
    B.append(a)

N = len(B)
B.sort(reverse=True)
check = [True] + [False]*N
dp = [[False]*(K+1) for i in range(N+1)]
dp[0][0] = True
for i, b in enumerate(B, 1):
  for j in range(K+1):
    dp[i][j] = dp[i-1][j]
    if K-b <= j <= K - 1 and dp[i][j]:
      check[i] = True
    if j >= b and dp[i-1][j-b]:
      dp[i][j] = True

ans = 0
for i in range(N, -1, -1):
  if check[i]:
    break
  ans += 1

print(ans)

Fixed submission:
N, K = map(int, input().split())
A = list(map(int, input().split()))
B = []
for a in A:
  if a < K:
    B.append(a)

N = len(B)
B.sort(reverse=True)
check = [True] + [False]*N
dp = [[False]*(K+1) for i in range(N+1)]
dp[0][0] = True
for i, b in enumerate(B, 1):
  for j in range(K+1):
    dp[i][j] = dp[i-1][j]
    if K-b <= j <= K - 1 and dp[i][j]:
      check[i] = True
    if j >= b and dp[i-1][j-b]:
      dp[i][j] = True

ans = 0
for i in range(N, -1, -1):
  if check[i]:
    break
  ans += 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, Ma, Mb = map(int, input().split())
abc = [list(map(int, input().split())) for i in range(N)]
INF = 10**5
n = 10*N + 1
dp = [[[INF]*n for i in range(n)] for j in range(N+1)]
dp[0][0][0] = 0

for i, (a, b, c) in enumerate(abc, 1):
  for j in range(n):
    for k in range(n):
      dp[i][j][k] = dp[i-1][j][k]
      if a <= j and b <= k:
        dp[i][j][k] = min(dp[i][j][k], dp[i-1][j-a][k-b]+c)

ans = INF
dp[-1][0][0] = INF
for j in range(n):
  for k in range(n):
    if j * Mb == k*Ma:
      ans = min(ans, dp[-1][j][k])

if ans < INF:
  print(ans)
else:
  print(-1)

Fixed submission:
N, Ma, Mb = map(int, input().split())
abc = [list(map(int, input().split())) for i in range(N)]
INF = 10**5
n = 10*N + 1
dp = [[[INF]*n for i in range(n)] for j in range(N+1)]
dp[0][0][0] = 0

for i, (a, b, c) in enumerate(abc, 1):
  for j in range(n):
    for k in range(n):
      dp[i][j][k] = dp[i-1][j][k]
      if a <= j and b <= k:
        dp[i][j][k] = min(dp[i][j][k], dp[i-1][j-a][k-b]+c)

ans = INF
dp[-1][0][0] = INF
for j in range(n):
  for k in range(n):
    if j * Mb == k*Ma:
      ans = min(ans, dp[-1][j][k])

if ans < INF:
  print(ans)
else:
  print(-1)
Buggy python submission (verdict: Runtime Error):
H, W = map(int, input().split())
A = [input() for i in range(H)]

visited = [[False]*W for i in range(H)]
visited[0][0] = True
d = [[0, 0], [-1, -1]]
while d:
  x, y, px, py = d.pop()
  num = 0
  flag = False
  for dx, dy in [[1, 0], [0, 1], [-1, 0], [0, -1]]:
    if 0<=x+dx<H and 0<=y+dy<W and [x+dx, y+dy]!=[px, py] and A[x+dx][y+dy]=='#' and not visited[x+dx][y+dy]:
      visited[x+dx][y+dy] = True
      num += 1
      d.append([x+dx, y+dy, x, y])
      if dx < 0 or dy < 0:
        flag = True
  if (num >= 2) or flag:
    print('Impossible')
    quit()

print('Possible')

Fixed submission:
H, W = map(int, input().split())
A = [input() for i in range(H)]

visited = [[False]*W for i in range(H)]
visited[0][0] = True
d = [[0, 0, -1, -1]]
while d:
  x, y, px, py = d.pop()
  num = 0
  flag = False
  for dx, dy in [[1, 0], [0, 1], [-1, 0], [0, -1]]:
    if 0<=x+dx<H and 0<=y+dy<W and [x+dx, y+dy]!=[px, py] and A[x+dx][y+dy]=='#' and not visited[x+dx][y+dy]:
      visited[x+dx][y+dy] = True
      num += 1
      d.append([x+dx, y+dy, x, y])
      if dx < 0 or dy < 0:
        flag = True
  if (num >= 2) or flag:
    print('Impossible')
    quit()

print('Possible')
Buggy python submission (verdict: Runtime Error):
N, x = map(int, input().split())

if x in [1, 2*N-1]:
  print('No')
else:
  print('Yes')
  if N == 2:
    print(*range(1, 4), sep='\n')
  else:
    ans = [0] * (2*N - 1)
    s = set(range(1, 2*N))
    if x >= N:
      ans[N-1] = x - 1; s.discard(x-1)
      ans[N] = x; s.discard(x)
      ans[N+1] = x + 1; s.discard(x+1)
      ans[N+2] = x - 2; s.discard(x-2)
    else:
      ans[N-1] = x + 1; s.discard(x+1)
      ans[N] = x; s.discard(x)
      ans[N+1] = x - 1; s.discard(x-1)
      ans[N+2] = x + 2; s.discard(x+2)
    for i in range(2*N-1):
      if ans[i]:
        continue
      ans[i] = s.pop()
    print(*ans, sep='\n')

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

if x in [1, 2*N-1]:
  print('No')
else:
  print('Yes')
  if N == 2:
    print(*range(1, 4), sep='\n')
  else:
    ans = [0] * (2*N - 1)
    s = set(range(1, 2*N))
    if x >= N:
      ans[N-2] = x - 1; s.discard(x-1)
      ans[N-1] = x; s.discard(x)
      ans[N] = x + 1; s.discard(x+1)
      ans[N+1] = x - 2; s.discard(x-2)
    else:
      ans[N-2] = x + 1; s.discard(x+1)
      ans[N-1] = x; s.discard(x)
      ans[N] = x - 1; s.discard(x-1)
      ans[N+1] = x + 2; s.discard(x+2)
    for i in range(2*N-1):
      if ans[i]:
        continue
      ans[i] = s.pop()
    print(*ans, sep='\n')
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

H, W, N = map(int, input().split())
ab = set(tuple(map(int, input().split())) for i in range(N))

dxy = {0:[0, 1, 2], 1:[-1, 0, 1], 2:[-2, -1, 0]}
num_all = (H - 2) * (W - 2)
num = [0] * 10
for a, b in ab:
  for i in range(3):
    Da = dxy[i]
    for j in range(3):
      n = 0
      flag = False
      Db = dxy[j]
      for da in Da:
        aa = a + da
        for db in Db:
          bb = b + db
          if aa < 1 or H < aa or bb < 1 or W < bb:
            flag = True
            break
          if (aa, bb) in ab:
            n += 1
        if flag:
          break
      if flag:
        continue
      num[n] += 1

for i in range(2, 10):
  num[i] //= i

num[0] = num_all - sum(num[1:])
print(*num, sep='\n')

Fixed submission:
H, W, N = map(int, input().split())
ab = set(tuple(map(int, input().split())) for i in range(N))

dxy = {0:[0, 1, 2], 1:[-1, 0, 1], 2:[-2, -1, 0]}
num_all = (H - 2) * (W - 2)
num = [0] * 10
for a, b in ab:
  for i in range(3):
    Da = dxy[i]
    for j in range(3):
      n = 0
      flag = False
      Db = dxy[j]
      for da in Da:
        aa = a + da
        for db in Db:
          bb = b + db
          if aa < 1 or H < aa or bb < 1 or W < bb:
            flag = True
            break
          if (aa, bb) in ab:
            n += 1
        if flag:
          break
      if flag:
        continue
      num[n] += 1

for i in range(2, 10):
  num[i] //= i

num[0] = num_all - sum(num[1:])
print(*num, sep='\n')
Buggy python submission (verdict: Time Limit Exceeded):
N, x = map(int, input().split())
A = list(map(int, input().split()))

min_time = A.copy()
ans = 10**15
for t in range(N):
  time = t*x
  for i in range(N):
    j = (i - t) % N
    min_time[i] = min(min_time[i], A[j])
    time += min_time[i]
  ans = min(ans, time)

print(ans)

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

min_time = [a for a in A]
ans = 10**15
for t in range(N):
  time = t*x
  for i in range(N):
    j = (i - t) % N
    min_time[i] = min(min_time[i], A[j])
    time += min_time[i]
  ans = min(ans, time)

print(ans)

Buggy python submission (verdict: Runtime Error):
N, x = map(int, input().split())
A = list(map(int, input().split()))

min_time = A.copy()
ans = 10**15
for t in range(N):
  time = t*x
  for i in range(N):
    j = (i - t) % N
    min_time[i] = min(min_time[i], A[j])
    time += min_time[i]
  ans = min(ans, time)

print(ans)

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

min_time = [a for a in A]
ans = 10**15
for t in range(N):
  time = t*x
  for i in range(N):
    j = (i - t) % N
    min_time[i] = min(min_time[i], A[j])
    time += min_time[i]
  ans = min(ans, time)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, A = map(int, input().split())
X = list(map(int, input().split()))
n = N * 50
dp = [[[0]*(n+1) for j in range(N+1)] for i in range(N+1)]
dp[0][0][0] = 1

for i, a in enumerate(X, 1):
  for j in range(N+1):
    for s in range(n+1):
      dp[i][j][s] = dp[i-1][j][s]
      if a <= s:
        dp[i][j][s] += dp[i-1][j-1][s-a]

ans = 0
for m in range(1, N+1):
  ans += dp[-1][m][A*m]

print(ans)

Fixed submission:
N, A = map(int, input().split())
X = list(map(int, input().split()))
n = N * 50
dp = [[[0]*(n+1) for j in range(N+1)] for i in range(N+1)]
dp[0][0][0] = 1

for i, a in enumerate(X, 1):
  for j in range(N+1):
    for s in range(n+1):
      dp[i][j][s] = dp[i-1][j][s]
      if a <= s:
        dp[i][j][s] += dp[i-1][j-1][s-a]

ans = 0
for m in range(1, N+1):
  ans += dp[-1][m][A*m]

print(ans)
Buggy python submission (verdict: Runtime Error):
S = input()
n = int('N' in S)
s = int('S' in S)
w = int('W' in W)
e = int('E' in E)

if n + s == 1 or w + e == 1:
  print('No')
else:
  print('Yes')

Fixed submission:
S = input()
n = int('N' in S)
s = int('S' in S)
w = int('W' in S)
e = int('E' in S)

if n + s == 1 or w + e == 1:
  print('No')
else:
  print('Yes')
Buggy python submission (verdict: Runtime Error):
# Import
from collections import deque
import math

# I/O
def read(): return input()
def read_int(): return int(input())
def read_array(type=int): return [type(i) for i in input().split()]
def read_tupple(type=None):
    tmp = input().split()
    if type is None: return map(int, tmp)
    assert len(tmp) == len(type)
    return [type[i](tmp[i]) for i in range(len(tmp))]

MOD = 998244353
N, S = read_tupple()
A = read_array()

dp = [[0 for j in range(S+1)] for i in range(N+1)]
dp[0][0] = 1
for i in range(N):
    for j in range(S+1):
        dp[i + 1][j] += 2 * dp[i][j]
        if j - A[i] >= 0:
            dp[i + 1][j] += dp[i][j - A[i]]
        
        while dp[i+1][j] > MOD:
			dp[i+1][j] -= MOD
        
print(dp[N][S])


Fixed submission:
# Import
from collections import deque
import math

# I/O
def read(): return input()
def read_int(): return int(input())
def read_array(type=int): return [type(i) for i in input().split()]
def read_tupple(type=None):
    tmp = input().split()
    if type is None: return map(int, tmp)
    assert len(tmp) == len(type)
    return [type[i](tmp[i]) for i in range(len(tmp))]

MOD = 998244353
N, S = read_tupple()
A = read_array()

dp = [[0 for j in range(S+1)] for i in range(N+1)]
dp[0][0] = 1
for i in range(N):
    for j in range(S+1):
        dp[i + 1][j] += 2 * dp[i][j]
        if j - A[i] >= 0:
            dp[i + 1][j] += dp[i][j - A[i]]
        
        while dp[i+1][j] > MOD:
            dp[i+1][j] -= MOD
        
print(dp[N][S])
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=map(int,input().split())
print(max(a)-min(a))

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
print(max(a)-min(a))
Buggy python submission (verdict: Runtime Error):
a,b=map(int,inout().split())
if a <= b:
  print(a)
else:
  print(a-1)

Fixed submission:
a,b=map(int,input().split())
if a <= b:
  print(a)
else:
  print(a-1)