Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from collections import Counter

def rec(n, memo):
    if memo[n] != -1:
        return memo[n]
    
    if len(graph[n]) == 0:
        memo[n] = 0
        return 0
    
    else:
        cnt = Counter()
        for child in graph[n]:
            cnt[rec(child, memo)] += 1
            
        memo[n] = max(cnt.keys())+1 + (sum(cnt.values()) - len(cnt))
        return memo[n]

n = ni()
memo = [-1]*n
graph = [[] for _ in range(n)]
i = 1
for _ in range(n-1):
    ai = ni() - 1
    graph[ai].append(i)
    i += 1
    
print(rec(0, memo))


Fixed submission:
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

def dfs(v: int, graph: list) -> int:
    if graph[v] == []:
        return 0
    
    else:
        ret = -1
        cands = []
        for ch in graph[v]:
            cands.append(dfs(ch, graph))
            
        cands.sort(reverse=True)
        
        for idx, cand in enumerate(cands):
            ret = max(ret, idx+1 + cand)
            
        return ret
    

n = ni()
graph = [[] for _ in range(n)]

person = 1
for _ in range(n-1):
    ai = ni()-1
    graph[ai].append(person)
    
    person += 1
    
ans = dfs(0, graph)
print(ans)
Buggy python submission (verdict: Runtime Error):
import math

prime = {}

N = int(input())

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

isPrime = [True]*(N+1)
isPrime[0] = False
isPrime[1] = False
for i in range(2,int(math.sqrt(N))+2):
    if isPrime[i]:
        n = 2*i
        while n<=N:
            isPrime[n] = False
            n += i

for i in range(N+1):
    if isPrime[i]:
        prime[i] = 0

key_list = list(prime.keys())

for num in range(2,N+1):
    res = num
    idx = 0
    while res>1:
        k = key_list[idx]
        if res%k == 0:
            prime[k] += 1
            res = res//k
        else:
            idx += 1
    
ans = 1
for v in prime.values():
    ans *= (v+1) 
    ans = ans % (10**9+7)
    if ans==0:
        ans = 1
    
print(ans)
    

Fixed submission:
import sys
stdin = sys.stdin

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

a,b,c,d = li()

if a*b < c*d:
    print(c*d)
else:
    print(a*b)
Buggy python submission (verdict: Runtime Error):
from collections import deque

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

INF = float("inf")

dist = deque(X)

next_x = +1
i = 0
ans = 0
while len(dist) != 1:

    if A*abs(dist[i+next_x] - dist[i]) <= B:
        ans += A*abs(dist[i+next_x] - dist[i])
        if next_x == 1:
            dist.popleft()
            i = 0
        else:
            dist.pop()
            i = len(dist)
    else:
        ans += B
        if next_x == 1:
            dist.popleft()
            i = len(dist)-1
        else:
            dist.pop()
            i = 0
        
        next_x = -next_x
        
print(ans)

Fixed submission:
from collections import deque

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

INF = float("inf")

dist = deque(X)

next_x = +1
i = 0
ans = 0
while len(dist) != 1:

    if A*abs(dist[i+next_x] - dist[i]) <= B:
        ans += A*abs(dist[i+next_x] - dist[i])
        if next_x == 1:
            dist.popleft()
            i = 0
        else:
            dist.pop()
            i = len(dist)-1
    else:
        ans += B
        if next_x == 1:
            dist.popleft()
            i = len(dist)-1
        else:
            dist.pop()
            i = 0
        
        next_x = -next_x
        
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
MOD = 10**9 + 7
n = int(input())
ans = set()

def dfs(a:int, b:int, digit:int, memo:set):
    u = a^b
    v = a+b
    
    if u > n or v > n:
        return 0
    
    else:        
        if digit == 0:
            memo.add((u,v))
            return 0
            
        else:
            dfs(a+pow(2,digit-1), b+pow(2,digit-1), digit-1, memo)
            dfs(a+pow(2,digit-1), b, digit-1, memo)
            dfs(a, b, digit-1, memo)
            
dfs(0,0,60,ans)

print(len(ans) % MOD)


Fixed submission:
import sys
stdin = sys.stdin

def li(): return [int(x) for x in stdin.readline().split()]
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return [float(x) for x in stdin.readline().split()]
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(ns())
def nf(): return float(ns())


MOD = 10**9+7

n = ni()
n_bit = len(bin(n)[2:])

dp = [[0]*4 for _ in range(n_bit+1)]
dp[0][0] = 1

for bit in range(n_bit):
    digit = int(bin(n)[2+bit:2+bit+1])
    
    if digit:
        dp[bit+1][0] = (dp[bit][0]) % MOD
        dp[bit+1][1] = (dp[bit][0] + dp[bit][1]) % MOD
        dp[bit+1][2] = (dp[bit][1]) % MOD
        dp[bit+1][3] = (dp[bit][1] + 3*dp[bit][2] + 3*dp[bit][3]) % MOD
        
    else:
        dp[bit+1][0] = (dp[bit][0] + dp[bit][1]) % MOD
        dp[bit+1][1] = (dp[bit][1]) % MOD
        dp[bit+1][2] = (dp[bit][1] + dp[bit][2]) % MOD
        dp[bit+1][3] = (2*dp[bit][2] + 3*dp[bit][3]) % MOD
        
print(sum(dp[n_bit]) % MOD)
Buggy python submission (verdict: Runtime Error):
from bisect import bisect_right

sum_list = []
nm = 1
sm = 1
while sm <= 10**7:
    sum_list.append(sm)
    nm += 1
    sm += nm
    
n = int(input())

k = bisect_right(sum_list, n)

ans_set = set([i for i in range(1,k+2)])
ans_set.remove(sum_list[k] - n)
ans = list(ans_set)

for a in ans:
    print(a)

Fixed submission:
from bisect import bisect_right

sum_list = []
nm = 1
sm = 1
while sm <= 10**8:
    sum_list.append(sm)
    nm += 1
    sm += nm
    
n = int(input())

k = bisect_right(sum_list, n)

ans_set = set([i for i in range(1,k+2)])
ans_set.remove(sum_list[k] - n)
ans = list(ans_set)

for a in ans:
    print(a)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
import sys
sdin = sys.stdin.readline

n,t = map(int, sdin().split())
a = list(map(int, sdin().split()))

# iまででの最高と最低
diff_list = [] # iを含むiまでの最低
max_list = [] # iを含まないiからの最高

mini = max(a)
maxi = max(a)

# iまでの最低と最高を更新
for i in range(n-1):
    if a[i] < mini:
        mini = a[i]
    
    if a[i] == maxi:
        maxi = max(a[i+1:])
        
    diff_list.append(maxi-a[i])
    
cnt = Counter(diff_list)

# 最大値の個数
print(cnt[max(cnt.keys())])
    

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


a_min = float("inf")
a_max = 0
a_diff = 0

ans = 0
a_diff = -1

for a in A:

    hasModefied = False
    if a_min > a:
        a_min = a
        a_max = a
    if a_max < a:
        a_max = a
        hasModefied = True
        
    if hasModefied:
        if a_diff == a_max-a_min:
            ans += 1
        elif a_diff < a_max-a_min:
            a_diff = a_max - a_min
            ans = 1
            
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

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


a_min = float("inf")
a_max = 0
a_diff = 0

counter = Counter([])

for a in A:
    hasModefied = False
    if a_min > a:
        a_min = a
        a_max = a
    if a_max < a:
        a_max = a
        hasModefied = True
        
    if hasModefied:        
        a_diff = a_max - a_min
        counter += {a_diff: 1}

keys = list(counter.keys())
max_key = max(keys)
print(counter[max_key])

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


a_min = float("inf")
a_max = 0
a_diff = 0

ans = 0
a_diff = -1

for a in A:

    hasModefied = False
    if a_min > a:
        a_min = a
        a_max = a
    if a_max < a:
        a_max = a
        hasModefied = True
        
    if hasModefied:
        if a_diff == a_max-a_min:
            ans += 1
        elif a_diff < a_max-a_min:
            a_diff = a_max - a_min
            ans = 1
            
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**7) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

N, x = li()

if x == 1 or x == 2*N-1:
    print('No')
    
else:
    ans = [0]*(2*N-1)
    ans[N-1] = x
    
    if x == 2:
        ans[N-2] = x+2
        ans[N] = x-1
        ans[N+1] = x+1
        used = [x-1,x,x+1,x+2]
        
    else:
        ans[N-2] = x-1
        ans[N] = x+1
        ans[N+1] = x-2
        used = [x-2,x-1,x,x+1]
    
    rem = []
    for i in range(1,2*N):
        if i in used:
            continue
        else:
            rem.append(i)
            
    rem = rem[::-1]
    
    for i in range(2*N-1):
        if N-2 <= i <= N+1:
            continue
        
        else:
            ans[i] = rem.pop()
            
    print('Yes')
    for ai in ans:
        print(ai)

Fixed submission:
import sys
stdin = sys.stdin

def li(): return [int(x) for x in stdin.readline().split()]
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return [float(x) for x in stdin.readline().split()]
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(ns())
def nf(): return float(ns())

n,x = li()

if n == 2 and x == 2:
    print("Yes")
    for i in range(1,4):
        print(i)
        
elif (n == 2 and x == 1) or (n == 2 and x == 3):
    print("No")

elif x == 1 or x == 2*n-1:
    print("No")

elif x == 2:
    ans = [i for i in range(1,x-1)] + [i for i in range(x+3, 2*n)]
    ans = ans[:n-2] + [x+2, x, x-1, x+1] + ans[n-2:]
    
    print("Yes")
    for ai in ans:
        print(ai)
    
else:
    ans = [i for i in range(1,x-2)] + [i for i in range(x+2, 2*n)]
    ans = ans[:n-2] + [x-1, x, x+1, x-2] + ans[n-2:]
    
    print("Yes")
    for ai in ans:
        print(ai)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

ans = 0

for i in range(n):
  a[i] -= 1

for i in range(n):
  for j in range(i+1, n):
    if a[i] == j and a[j] == i:
      ans += 1
      
print(ans)

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

ans = 0

for i in range(n):
  a[i] -= 1

for i in range(n):
  if a[a[i]] == i:
    ans += 1
      
print(ans//2)
Buggy python submission (verdict: Runtime Error):
# 入力
import sys
stdin = sys.stdin

def li(): return [int(x) for x in stdin.readline().split()]
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return [float(x) for x in stdin.readline().split()]
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(ns())
def nf(): return float(ns())

# ここから処理
s = ns()
k = ni()

chl = list(s)
res = k

for i, c in enumerate(chl):
    if res >= ord("z") - ord(c) + 1:
        chl[i] = "a"
        res -= (ord("z") - ord(c) + 1)

chl[-1] = chr(ord(chl[-1]) + res)

print("".join(chl))

Fixed submission:
# 入力
import sys
stdin = sys.stdin

def li(): return [int(x) for x in stdin.readline().split()]
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return [float(x) for x in stdin.readline().split()]
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(ns())
def nf(): return float(ns())

# ここから処理
s = ns()
k = ni()

chl = list(s)
res = k

for i, c in enumerate(chl):
    if c == "a":
        continue
    
    elif res >= ord("z") - ord(c) + 1:
        chl[i] = "a"
        res -= (ord("z") - ord(c) + 1)

chl[-1] = chr(ord(chl[-1]) + res%26)

print("".join(chl))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sdin = sys.stdin.readline

h, w, n = map(int, sdin().split())
ab = []
for _ in range(n):
    ab.append(tuple(map(int, sdin().split())))
    
# フィールドを作って塗る
field = [[0 for _ in range(w+1)] for _ in range(h+1)]

x = [-1,-1,-1, 0, 0, 0, 1, 1, 1]
y = [-1, 0, 1,-1, 0, 1,-1, 0, 1]

for a, b in ab:
    for dx,dy in zip(x, y):
        if a+dx > 0 and a+dx <= h and b+dy > 0 and b+dy <= w:
            field[a+dx][b+dy] += 1
            
# 数え上げる
for j in range(10):
    row = [field[r][2:w].count(j) for r in range(2,h)]
    print(sum(row))    
    

Fixed submission:
from collections import Counter
from collections import defaultdict
import sys

sdin = sys.stdin.readline

H,W,N = map(int, sdin().split())
AB = []
for i in range(N):
    AB.append(tuple(map(int, sdin().split())))
    
grid_num = (min(H,W)-2)*(max(H,W)-2)
    
AB = [(a-1,b-1) for a,b in AB]

dic = defaultdict(int)

for a,b in AB:
    for h in range(-1,2):
        if a+h < 1 or a+h > H-2:
            continue
        
        for w in range(-1,2):
            if b+w < 1 or b+w > W-2:
                continue
            
            dic[(a+h,b+w)] += 1
            

cnt = Counter(dic.values())

for i in range(10):
    if i==0:
        print(grid_num - sum(cnt.values()))
    elif not i in cnt.keys():
        print(0)
    else:
        print(cnt[i])

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

h, w, n = map(int, sdin().split())
ab = []
for _ in range(n):
    ab.append(tuple(map(int, sdin().split())))
    
# フィールドを作って塗る
field = [[0 for _ in range(w+1)] for _ in range(h+1)]

x = [-1,-1,-1, 0, 0, 0, 1, 1, 1]
y = [-1, 0, 1,-1, 0, 1,-1, 0, 1]

for a, b in ab:
    for dx,dy in zip(x, y):
        if a+dx > 0 and a+dx <= h and b+dy > 0 and b+dy <= w:
            field[a+dx][b+dy] += 1
            
# 数え上げる
for j in range(10):
    row = [field[r][2:w].count(j) for r in range(2,h)]
    print(sum(row))    
    

Fixed submission:
from collections import Counter
from collections import defaultdict
import sys

sdin = sys.stdin.readline

H,W,N = map(int, sdin().split())
AB = []
for i in range(N):
    AB.append(tuple(map(int, sdin().split())))
    
grid_num = (min(H,W)-2)*(max(H,W)-2)
    
AB = [(a-1,b-1) for a,b in AB]

dic = defaultdict(int)

for a,b in AB:
    for h in range(-1,2):
        if a+h < 1 or a+h > H-2:
            continue
        
        for w in range(-1,2):
            if b+w < 1 or b+w > W-2:
                continue
            
            dic[(a+h,b+w)] += 1
            

cnt = Counter(dic.values())

for i in range(10):
    if i==0:
        print(grid_num - sum(cnt.values()))
    elif not i in cnt.keys():
        print(0)
    else:
        print(cnt[i])
Buggy python submission (verdict: Time Limit Exceeded):
import sys
stdin = sys.stdin

def li(): return [int(x) for x in stdin.readline().split()]
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return [float(x) for x in stdin.readline().split()]
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(ns())
def nf(): return float(ns())

n,x = li()
a = li()

a = a+a

INF = float("inf")

# 区間内最小を探す
itv_min = [[INF for _ in range(2*n)] for _ in range(n)]
for st in range(n):
    mn = a[st]
    itv_min[st][st] = mn
    for ed in range(st+1,st+n):
        mn = min(mn, a[ed])
        itv_min[st][ed] = mn

# 魔法を唱える回数を固定
ans = INF
for k in range(n):
    temp = 0
    for st in range(n):
        temp += itv_min[st][st+k]
        
    ans = min(ans, temp+k*x)

print(ans)

Fixed submission:
import sys
stdin = sys.stdin

def li(): return [int(x) for x in stdin.readline().split()]
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return [float(x) for x in stdin.readline().split()]
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(ns())
def nf(): return float(ns())

n,x = li()
a = li()

mins = [ai for ai in a]
a2 = a+a

ans = sum(mins)
for k in range(n):
    for i in range(n):
        mins[i] = min(mins[i],a2[i+k])
    
    temp = sum(mins)    
    ans = min(ans, temp + k*x)
    
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n, a = li()
x = list(li())

dp = [[[0]*(n*max(x)+1) for _ in range(n+1)] for _ in range(n+1)]
dp[0][0][0] = 1

for i in range(1, n+1):
    for j in range(n+1):
        for k in range(n*max(x) + 1):
            dp[i][j][k] += (dp[i-1][j-1][k-x[i-1]] if (j-1 >= 0 and k-x[i-1] >= 0) else 0)\
                            + dp[i-1][j][k]

ans = 0
for i in range(1,n+1):
    ans += dp[n][i][a*i]

print(ans)

Fixed submission:
import collections

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

for i in range(N):
    X[i] -= A

sums = collections.Counter([0,X[0]])

for i in X[1:]:
    c = collections.Counter()
    for p,q in sums.items():
        c[i+p] = q
    sums += c

print(sums[0]-1)

Buggy python submission (verdict: Time Limit Exceeded):
N, A = map(int, input().split())
X = list(map(int, input().split()))
X = [0] + X

dp = [[[0 for _ in range(50*N+1)] for _ in range(N+1)] for _ in range(N+1)]

dp[0][0][0] = 1
for limit in range(1,N+1):
    for num in range(limit+1):
        for summ in range(50*N+1):
            if summ-X[limit] < 0:
                dp[limit][num][summ] = dp[limit-1][num][summ]
            else:
                dp[limit][num][summ] = dp[limit-1][num][summ] + \
                                       dp[limit-1][num-1][summ-X[limit]]
         
ans = 0                           
for i in range(1,N+1):
    ans += dp[N][i][A*i]

print(ans)      

Fixed submission:
import collections

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

for i in range(N):
    X[i] -= A

sums = collections.Counter([0,X[0]])

for i in X[1:]:
    c = collections.Counter()
    for p,q in sums.items():
        c[i+p] = q
    sums += c

print(sums[0]-1)

Buggy python submission (verdict: Time Limit Exceeded):
ans = 0
N, A = map(int, input().split())
X1 = list(map(int, input().split()))
a = 0

def dfs(total, loop, card_num, target_mean):
    global ans
    global N
    
    if loop == N:
        if total/card_num == target_mean:
            ans += 1
        return 0
    else:
        dfs(total        , loop+1, card_num  , target_mean)
        dfs(total+X[loop], loop+1, card_num+1, target_mean)
 
X = X1.copy()
for i in range(N):
    dfs(X[0], 1, 1, A)
    X.pop(0)
    N = len(X)
print(ans)

Fixed submission:
import collections

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

for i in range(N):
    X[i] -= A

sums = collections.Counter([0,X[0]])

for i in X[1:]:
    c = collections.Counter()
    for p,q in sums.items():
        c[i+p] = q
    sums += c

print(sums[0]-1)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
stdin = sys.stdin

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())


dic = dict()

n = ni()
a = []
for _ in range(n):
    a.append(ni())
    
b = sorted(a)

for i, ai in enumerate(a):
    dic[ai] = (i, b.index(ai))
    
cnt = 0
for ord1, ord2 in dic.values():
    if ord1%2 != ord2%2:
        cnt += 1
        
print(cnt // 2)

Fixed submission:
import sys
stdin = sys.stdin

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from bisect import bisect_left

dic = dict()

n = ni()
a = []
for _ in range(n):
    a.append(ni())
    
b = sorted(a)

for i, ai in enumerate(a):
    dic[ai] = (i, bisect_left(b,ai))
    
cnt = 0
for ord1, ord2 in dic.values():
    if ord1%2 != ord2%2:
        cnt += 1
        
print(cnt // 2)

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

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())


dic = dict()

n = ni()
a = []
for _ in range(n):
    a.append(ni())
    
b = sorted(a)

for i, ai in enumerate(a):
    dic[ai] = (i, b.index(ai))
    
cnt = 0
for ord1, ord2 in dic.values():
    if ord1%2 != ord2%2:
        cnt += 1
        
print(cnt // 2)

Fixed submission:
import sys
stdin = sys.stdin

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from bisect import bisect_left

dic = dict()

n = ni()
a = []
for _ in range(n):
    a.append(ni())
    
b = sorted(a)

for i, ai in enumerate(a):
    dic[ai] = (i, bisect_left(b,ai))
    
cnt = 0
for ord1, ord2 in dic.values():
    if ord1%2 != ord2%2:
        cnt += 1
        
print(cnt // 2)
Buggy python submission (verdict: Runtime Error):
n, k = map(int, raw_input().split())
if k % 2 == 1:
    print((n / k) ** 3)
else:
    print((n / k) ** 3 + ((n + k / 2) / k) ** 3)

Fixed submission:
n, k = map(int, raw_input().split())
if k % 2 == 1:
    print((n / k) ** 3)
else:
    print((n / k) ** 3 + ((n + k / 2) / k) ** 3)
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
l, r = list(map(int, [input().split() for i in range(m)]))

max_l = max(l)
min_r = min(r)
print(max(min_r - max_l, 0))
    

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

if a >= 13:
  print(b)
elif 6 <= a <= 12:
  print(int(b/2))
else:
  print(0)