Harryxun/stf_run huggingface dataset:
class Dice(object):
 
    def __init__(self, d):

        self.rows = [d[0], d[4], d[5], d[1]]
        self.cols = [d[0], d[2], d[5], d[3]]
 
    def move_next_rows(self):
        temp = self.rows.pop(0)
        self.rows.append(temp)
        self.__update(self.cols, self.rows)

    def move_prev_rows(self):
        temp = self.rows.pop(3)
        self.rows.insert(0, temp)
        self.__update(self.cols, self.rows)
    
    def move_next_cols(self):
        temp = self.cols.pop(0)
        self.cols.append(temp)
        self.__update(self.rows, self.cols)
 
    def move_prev_cols(self):
        temp = self.cols.pop(3)
        self.cols.insert(0, temp)
        self.__update(self.rows, self.cols)

    def __update(self, x, y):
        x[0] = y[0]
        x[2] = y[2]
 
class DiceChecker(object):

    def __init__(self, dice1, dice2):
        self.dice1 = dice1
        self.dice2 = dice2
        self.dice1_top = self.dice1.rows[0]
        self.dice1_front = self.dice1.rows[3]
        
    def check_same_dice(self):

        is_same = False
        for _ in range(4):
            for _ in range(4):
                is_same_element = self.dice1.rows == self.dice2.rows and self.dice1.cols == self.dice2.cols
                if is_same_element:
                    is_same = True
                    break
                self.dice2.move_next_cols()
            else:     
                self.dice2.move_next_rows()
                continue
            break
        if is_same:
            print("Yes")
        else:
            print("No")
    
    def __find_num(self, x, dice):
        i = 0
        while x != dice.rows[0]:
            dice.move_next_rows()
            if i > 3:
                dice.move_next_cols()
                i = 0
            i+=1
    
    def __rot(self, dice):
        temp = dice.rows[1]
        dice.rows[1] = dice.rows[3]
        dice.rows[3] = temp

        temp = dice.cols[1]
        dice.cols[1] = dice.cols[3]
        dice.cols[3] = temp

        
d1 = list(map(int, input().split(" ")))
d2 = list(map(int, input().split(" ")))
dice1 = Dice(d1)
dice2 = Dice(d2)

dice_checker = DiceChecker(dice1, dice2)
dice_checker.check_same_dice()



### FIXED CODE ###

class Dice:

    def __init__(self):
        d = map(int, raw_input().split(" "))
        self.c = raw_input()
        self.rows = [d[0], d[4], d[5], d[1]]
        self.cols = [d[0], d[2], d[5], d[3]]

    def __move_next(self, x, y):
        temp = y.pop(0)
        y.append(temp)
        x[0] = y[0]
        x[2] = y[2]

    def __move_prev(self, x, y):
        temp = y.pop(3)
        y.insert(0, temp)
        x[0] = y[0]
        x[2] = y[2]

    def execute(self):
        for i in self.c:
            self.__move(i, self.rows, self.cols)

    def __move(self, com, x, y):
        if com == "N":
            self.__move_prev(y, x)
        elif com == "S":
            self.__move_next(y, x)
        elif com == "E":
            self.__move_prev(x, y)
        elif com == "W":
            self.__move_next(x, y)

    def print_top(self):
        print self.rows[0]

dice = Dice()
dice.execute()
dice.print_top()
N = int(input())
A = list(map(int,input().split()))
x = 0
count = 0
while True:
  for i in A:
    if i % 2 == 1:
      x == 1
  if x == 1:
    break
  else:
    A /= 2
    count += 1

print(count)

### FIXED CODE ###

import numpy as np
N = int(input())
A = list(map(int,input().split()))
A = np.array(A)
count = 0
while True:
  x = 0
  for i in A:
    if i % 2 == 1:
      x = 1
  if x == 1:
    break
  else:
    A = A / 2
    count += 1

print(count)
from collections import defaultdict
N,Q = map(int,input().split())

tree = defaultdict(list)
for i in range(N-1):
    a,b = map(int,input().split())
    tree[a].append(b)

adds = defaultdict(int)
for q in range(Q):
    p,x = map(int,input().split())
    adds[p] += x

def dig(i,tmp):
    tmp += adds[i]
    ans[i] = tmp
    if tree[i]:
        for v in tree[i]: dig(v,tmp)

ans = defaultdict(int)
tmp = 0
dig(1,tmp)

for i in range(1,N+1):
    print(ans[i], end=' ')
print()

### FIXED CODE ###

from queue import deque
N,Q = map(int,input().split())
tree = [[] for i in range(N+1)]
for i in range(N-1):
    a,b = map(int,input().split())
    tree[a].append(b)
    tree[b].append(a)

ans = {i+1:0 for i in range(N)}
for i in range(Q):
    p,x = map(int,input().split())
    ans[p] += x

checked = [False for i in range(N+1)]
myq = deque()
myq.append(1)

while myq:
    v = myq.pop()
    checked[v] = True
    for n in tree[v]:
        if not checked[n]:
            ans[n] += ans[v]
            myq.append(n)
print(' '.join(str(ans[i]) for i in range(1,N+1)))
while True:
    points = list(map(int,input().split()))
    if points==[-1,-1,-1]: break
    sum_pt = sum(points[0:2])
    if points[0]==-1 or points[1]==-1 or sum_pt<30: print('F')
    elif sum_pt<50 and point[2]<50: print('D')
    elif sum_pt<65: print('C')
    elif sum_pt<80: print('B')
    else: print('A')

### FIXED CODE ###

while True:
    points = list(map(int,input().split()))
    if points==[-1,-1,-1]: break
    sum_pt = sum(points[0:2])
    if points[0]==-1 or points[1]==-1 or sum_pt<30: print('F')
    elif sum_pt<50 and points[2]<50: print('D')
    elif sum_pt<65: print('C')
    elif sum_pt<80: print('B')
    else: print('A')
li = list(map(int, input().split()))
li.sort(*, key = None, reverse = True)
for i in range(len(li)):
    a = li[i]
    b = li[i +1]]
print(a -b)

### FIXED CODE ###

n = int(input())
l = list(map(int, input().split()))
l.sort(reverse = True)
i = 0
a = 0
b = 0
while i < n: 
    a = a +l[i]
    i += 2
i = 1
while i < n:
    b = b +l[i]
    i += 2
print(a -b)
A, B = input().split()
N = max(len(A), len(B))
A, B = A.zfill(N), B.zfill(B)
if A == B:
  print("EQUAL")
if A > B:
  print("GREATER")
if A < B:
  print("LESS")


### FIXED CODE ###

A = int(input())
B = int(input())
if A == B:
  print("EQUAL")
if A > B:
  print("GREATER")
if A < B:
  print("LESS")
n = input()
a = list(map(int,[input() for i in range(5)]))
print(floar(n / min(a)) + 5) 


### FIXED CODE ###

import math
n=int(input())
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
miti=[a,b,c,d,e]
mini=min(miti)
retu=math.ceil(n/mini)
print(4+retu)
import sys

def split(g, n):
  gl = g[:-1]
  gr = g[1:]
  sub = [[(b - a), i+1] for a, b, i in zip(gl, gr, range(len(gl)))]
  sub = sorted(sub, key = lambda x: -x[0])
  j = []
  for i in range(n-1):
    j.append(sub[i][1])
  j = sorted(j)
  jl = [0] + j[:-1]
  res = []
  for l, r in zip(jl, j):
    s = g[l:r]
    res.append(s)
  R = j[-1]
  res.append(g[R:])
  print(res)
  return res


def main():
  input = sys.stdin.readline
  N, M = map(int, input().split())
  g = [int(a) for a in input().split()]
  g = sorted(g)
  ans = 0
  if N < M:
    sp = split(g, N)
    for s in sp:
      if len(s) <= 0:
        continue
      ans += s[-1] - s[0]
  print(ans)


if __name__ == '__main__':
  main()

### FIXED CODE ###

import sys

def main():
  input = sys.stdin.readline
  N, M = map(int, input().split())
  ans = 0
  if N < M:
    g = [int(a) for a in input().split()]
    g = sorted(g)
    L = g[:-1]
    R = g[1:]
    sub = [b - a for a, b in zip(L, R)]
    sub = sorted(sub)
    ans = sum(sub[:(M-N)])
  print(ans)


if __name__ == '__main__':
  main()
N = int(input())

point = []
dist = []

for _ in range(N) :
    x, y = map(int, input().split())
    point.append((x, y))
    dist.append(abs(x) + abs(y))

distSort = sorted(dist)
maxDist = distSort[-1]

for d in distSort :
    if (maxDist - d) % 2 == 1 :  # 実現不可能
        print(-1)
        break
else :  # 実現可能
    print(maxDist) # 腕の数
    out = [1] * maxDist
    print(*out)

    for i, (x, y) in enumerate(point) :
        if x < 0 :
            holizon = ['L'] * abs(x)
        elif x > 0 :
            holizon = ['R'] * abs(x)
        else :
            holizon = ['']

        if y < 0 :
            vertical = ['D'] * abs(y)
        elif y > 0 :
            vertical = ['U'] * abs(y)
        else :
            vertical = ['']

        last = ['']
        R = (maxDist - dist[i]) // 2
        if R > 0 :
            last = ['LR'] * R
        print(''.join(holizon + vertical + last))



### FIXED CODE ###

N=int(input())

point = []
parity = {}
for _ in range(N) :
    x, y = map(int, input().split())
    point.append((x, y))
    parity[(x + y) % 2] = 1

if len(set(parity)) == 2 :
    print('-1')
else :
    m = 38
    parity = 1 if (1 in parity) else 0
    print(m + 1 - parity)
    if parity == 1 :  # 距離が奇数
        print(*[1 << i for i in range(m)])
    else :
        print(1, *[1 << i for i in range(m)])

    def arm(x, y, m) :
        if abs(x) >= abs(y) :
            if x >= 0 :
                return ('R', x - (1<<m), y)
            else :
                return ('L', x + (1<<m), y)
        else :
            if y >= 0 :
                return ('U', x, y - (1<<m))
            else :
                return ('D', x, y + (1<<m))

    for x, y in point :
        ans = []
        for i in range(m-1, -1, -1) :
            mode, x, y = arm(x, y, i)
            ans.append(mode)
        if parity == 0 :  # 偶数の場合一つ足す
            if x == 1 :
                ans.append('R')
            elif x == -1 :
                ans.append('L')
            elif y == 1 :
                ans.append('U')
            elif y == -1 :
                ans.append('D')
        print(''.join(ans[::-1]))
import heapq
n,m,l=map(int,input().split())
edge=[[] for i in range(n)]
for i in range(m):
  a,b,c=map(int,input().split())
  edge[a-1].append([c,b-1])
  edge[b-1].append([c,a-1])

def f(s):
  d=[float("inf")]*n
  used=[True]*n
  d[s]=0
  used[s]=False
  edgelist=[]
  ans=0
  cur=l
  for c,e in edge[s]:
    heapq.heappush(edgelist,c*10**3+e)
  while edgelist:
    minedge=heapq.heappop(edgelist)
    v=minedge[0]%(10**3)
    ans,cur=minedge[0]//(10**13),(minedge[0]%(10**13))//(10**3)
    used[v]=False
    d[v]=ans
    
    for e in edge[v]:
      if used[e[1]]:
        if e[0]>l:
          continue
        elif e[0]+cur>l:
          heapq.heappush(edgelist,(ans+1)*10**13+e[0]*10**3+e[1])
        else:
          heapq.heappush(edgelist,(ans)*10**13+(e[0]+cur)*10**3+e[1])
  return d
Ans=[[] for i in range(n)]
for i in range(n):
  Ans[i]=f(i)
q=int(input())
for _ in range(q):
  s,t=map(int,input().split())
  print(-1 if Ans[s-1][t-1]==float("inf") else Ans[s-1][t-1])

### FIXED CODE ###


from scipy.sparse.csgraph import floyd_warshall
n,m,l=map(int,input().split())
table=[[0]*n for i in range(n)]
for i in range(m):
    a,b,c=map(int,input().split())
    table[a-1][b-1]=c
    table[b-1][a-1]=c
d=floyd_warshall(csgraph=table, directed=False, return_predecessors=False)

table2=[[0]*n for i in range(n)]
for i in range(n):
  for j in range(i+1,n):
    if d[i][j]<=l:
      table2[i][j]=1
      table2[j][i]=1
d2=floyd_warshall(csgraph=table2, directed=False, return_predecessors=False)
q=int(input())
for _ in range(q):
  s,t=map(int,input().split())
  if d2[s-1][t-1]==float("inf"):
    print(-1)
  else:
    print(int(d2[s-1][t-1])-1)
d=[0]*101

while True:
    try:
        n=input()
        d[n]+=1
    except:
        break

tmp=max(d)
for i in range(101):
    if d[i]=tmp: print i

### FIXED CODE ###

import sys
n = 101
D = [0]*n

for s in sys.stdin: D[int(s)] += 1
tmp = max(D)
i = 0
for e in D:
    if e==tmp: print i
    i += 1
def main():
    import collections
    import sys
    sys.setrecursionlimit(50000)
    input = sys.stdin.readline
    N=int(input())
    S=input()
    if N<=3:
        print(0)
    else:
        str_list=list(S[:N])
        result=0
        c=collections.Counter(str_list)
        RGB_list=c.most_common()

        list1=[i for i, x in enumerate(str_list) if x == RGB_list[0][0]]
        list2=[i for i, x in enumerate(str_list) if x == RGB_list[1][0]]
        list3=[i for i, x in enumerate(str_list) if x == RGB_list[2][0]]
        list23=[]
        if RGB_list[2][0]==0 or RGB_list[1][0]==0:
            print(0)
        else:
            for i in list3:
                for j in list2:
                    list23+=[2*i-j,2*j-i,(i+j)/2]
            c1=collections.Counter(list23)
            for k in list1:
                for l in c1.keys():
                    if k==l:
                        result+=c1[l]
            print(int(RGB_list[0][1]*RGB_list[1][1]*RGB_list[2][1]-result))

if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    import collections
    import sys
    sys.setrecursionlimit(5000000)
    input = sys.stdin.readline
    N=int(input())
    S=input()
    if N<=3:
        print(0)
    else:
        str_list=list(S[:N])
        result=0
        c=collections.Counter(str_list)
        RGB_list=c.most_common()

        if len(c)<3:
            print(0)

        else:

            list1=[i for i, x in enumerate(str_list) if x == RGB_list[0][0]]
            list2=[i for i, x in enumerate(str_list) if x == RGB_list[1][0]]
            list3=[i for i, x in enumerate(str_list) if x == RGB_list[2][0]]
            list23=[]

        
            for i in list3:
                for j in list2:
                    list23+=[2*i-j,2*j-i,(i+j)/2]
            c1=collections.Counter(list23)
            for k in list1:
                for l in c1.keys():
                    if k==l:
                        result+=c1[l]
            print(int(RGB_list[0][1]*RGB_list[1][1]*RGB_list[2][1]-result))

if __name__ == '__main__':
    main()
N,R = map(int,input())

print( R if N >10 else R - 100*(10-N))

### FIXED CODE ###

N,R = map(int,input().split())

print( R if N >= 10 else R + 100*(10-N))
A = int(input())
B = int(input())

OP = input(plus_minus)

if OP == "-":
    print(int(A) + int(B))
elif OP == "+":
    print(int(A) - int(B))


### FIXED CODE ###

A, op, B= input().split()


if op =="+":
    print(int(A) + int(B))
elif op =="-":
    print(int(A)-int(B))
a, b = map(int, input().split())
if b == 1:
  print(0)
else:
  ans = 1
  while True:
    if ans * a - (ans-1) >= b:
   	  break
 	ans += 1
  print(ans)

### FIXED CODE ###

a, b = map(int, input().split())
if b == 1:
  print(0)
else:
  ans = 1
  while True:
    if ans * a - (ans-1) >= b:
   	  break
    ans += 1
  print(ans)
N,M = map(int,input().split())
p = [list(map(int,input().split())) for _ in range(M)]
dp = [-1]*N
ip = [[] for _ in range(N)]
for i in range(M):
  ip[p[i][1]-1].append(p[i][0]-1)

#閉路がないため同じ頂点は通らない
#i番目の頂点に到達するまでの最長手数をメモ化再帰で求める

def maxpath(i):
  if dp[i] != -1:
    return dp[i]
  a = 0
  for el in ip[i]:
    a = max(a,maxpath(el)+1)
  dp[i] = a
  return a
  
for i in range(N):
  maxpath(i)

print(max(dp))

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)

N,M = map(int,input().split())
p = [list(map(int,input().split())) for _ in range(M)]
dp = [-1]*N
ip = [[] for _ in range(N)]
for i in range(M):
  ip[p[i][1]-1].append(p[i][0]-1)

#閉路がないため同じ頂点は通らない
#i番目の頂点に到達するまでの最長手数をメモ化再帰で求める

def maxpath(i):
  if dp[i] != -1:
    return dp[i]
  a = 0
  for el in ip[i]:
    a = max(a,maxpath(el)+1)
  dp[i] = a
  return a
  
for i in range(N):
  maxpath(i)

print(max(dp))
N=int(input())
A=list(map(int, input().split()))
Q=int(input())
B=[list(map(int, input().split())) for _ in range(Q)]
D={}
ma=0
for i in A:
  ma+=i
  if i not in D:
    D[i]=1
  else:
    D[i]+=1
    
for b,c in B:
  if b in D:
    f=D[b]
    t=D[c]
    D[c]=f+t
    D[b]=0
    ma+=(c-b)*f
    print(ma)

### FIXED CODE ###

N=int(input())
A=list(map(int, input().split()))
Q=int(input())
B=[list(map(int, input().split())) for _ in range(Q)]
D={}
ma=0
for i in A:
  ma+=i
  if i not in D:
    D[i]=1
  else:
    D[i]+=1
    
for b,c in B:
  if b in D:
    f=D[b]
    if c in D:
      t=D[c]
    else:
      t=0
    
    D[c]=f+t
    D[b]=0
    ma+=(c-b)*f
  print(ma)
N = int(input())
S = input()

if len(set(S)) == 1:
    print(0)
    quit()

a = S.count(".")
b = S.count("#")
ans2 = min(a,b)

ans = 0

if S[0] == "#":
    i = 1
    while True:
        if S[i] == ".":
            ans = i
            S = S[i:]
            break
        else:
            i += 1
else:
    flag = False
    for i in S:
        if i == "#":
            flag = True
        if flag and i == ".":
            break
    else:
        print(0)
        quit()

if S[-1] == ".":
    i = 2
    while True:
        if S[-i] == "#":
            ans += (i-1)
            S = S[:-i+1]
            break
        else:
            i += 1


for i in range(len(S)):
    if S[i] == "#":
        S = S[i:]
        break
for i in range(1, len(S)+1):
    if S[-i] == ".":
        S = S[:-(i-1)]
        break

print(min(min(S.count("."), S.count("#")) + ans, ans2))


### FIXED CODE ###

N = int(input())
S = input()
 
left = 0
right = S.count(".")
ans = right

for i in range(len(S)):
    if S[i] == ".":
        right -= 1
    else:
        left += 1

    ans = min(ans, left + right)
  
print(ans)
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n, k;
  cin >> n >> k;
  int l[k];
  rep(i, n) cin >> l[i];

  sort(l, l+n, greater<int>());
  int sum = 0;
  rep(i, k) sum += l[i];

  cout << sum << endl;

}


### FIXED CODE ###

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

l.sort(reverse = True)
sum = 0
for i in range(K) :
    sum += l[i]
print(sum)
import bisect

A,B,Q=map(int,input().split())
slist = []
for i in range(A):
  slist.append(int(input()))
#print(slist)
  
tlist = []
for i in range(B):
  tlist.append(int(input()))
#print(tlist)

for i in range(Q):
  x = int(input())
  min_dist = 10**11
  
  # x->s->t
  if x < slist[0]:
    si = [0]
  elif slist[-1] < x:
    si = [len(slist)-1]
  else:
	sl = bisect.bisect(slist,x)    
    si = [sl-1,sl]
  
  for index in si:
    s = slist[index]
    dist = abs(x-s)

    tl = bisect.bisect(tlist,s)
    if tl == 0:
      dist += abs(s-tlist[0])
    elif tl == len(tlist):
      dist += abs(s-tlist[len(tlist)-1])
    else:
      dist += min(abs(s-tlist[tl-1]),abs(s-tlist[tl]))
    
    if dist < min_dist:
      min_dist = dist

  # x->t->s
  if x < tlist[0]:
    ti = [0]
  elif tlist[-1] < x:
    ti = [len(tlist)-1]
  else:
	tl = bisect.bisect(tlist,x)    
    ti = [tl-1,tl]

  tl = bisect.bisect(tlist,x)
  if tl == 0:
    ti = [0]
  elif tl == len(tlist):
    ti = [tl-1]
  else:
    ti = [tl-1,tl]
  
  for index in ti:
    t = tlist[index]
    dist = abs(x-t)

    sl = bisect.bisect(slist,t)
    if sl == 0:
      dist += abs(t-slist[0])
    elif sl == len(slist):
      dist += abs(t-slist[len(slist)-1])
    else:
      dist += min(abs(t-slist[sl-1]),abs(t-slist[sl]))
    
    if dist < min_dist:
      min_dist = dist

  print(min_dist)


### FIXED CODE ###

import bisect

A,B,Q=map(int,input().split())
slist = []
for i in range(A):
  slist.append(int(input()))
#print(slist)

tlist = []
for i in range(B):
  tlist.append(int(input()))
#print(tlist)

for i in range(Q):
  x = int(input())
  min_dist = 10**11
  
  # x->s->t
  if x < slist[0]:
    si = [0]
  elif slist[-1] < x:
    si = [len(slist)-1]
  else:
    sl = bisect.bisect(slist,x)
    si = [sl-1,sl]
    
  for index in si:
    s = slist[index]
    dist = abs(x-s)

    if s < tlist[0]:
      dist += tlist[0]-s
    elif tlist[-1] < s:
      dist += s-tlist[-1]
    else:
      tl = bisect.bisect(tlist,s)  
      dist += min(s-tlist[tl-1],tlist[tl]-s)
    
    if dist < min_dist:
      min_dist = dist

  # x->t->s
  if x < tlist[0]:
    ti = [0]
  elif tlist[-1] < x:
    ti = [len(tlist)-1]
  else:
    tl = bisect.bisect(tlist,x)
    ti = [tl-1,tl]
    
  for index in ti:
    t = tlist[index]
    dist = abs(x-t)

    if t < slist[0]:
      dist += slist[0]-t
    elif slist[-1] < t:
      dist += t-slist[-1]
    else:
      sl = bisect.bisect(slist,t)
      dist += min(t-slist[sl-1],slist[sl]-t)
    
    if dist < min_dist:
      min_dist = dist

  print(min_dist)
mod=10**9+7

n,a,b=map(int,input().split())
res=pow(2,n,mod)
res=(res-1)%mod

up=1
down=1
for i in range(1,b+1):
	up*=(n-i+1)
	up%mod
	down*=i
	if i==a:
		upa=up
		downa=down

nca=upa%mod
nca*=pow(downa,mod-2,mod)
nca%=mod
ncb=(up%mod)
ncb=*pow(down,mod-2,mod)
ncb%=mod
print((res-nca-ncb)%mod)

### FIXED CODE ###

mod=10**9+7

n,a,b=map(int,input().split())
res=pow(2,n,mod)
res=(res-1)%mod

ncb=1
for i in range(1,b+1):
	ncb*=(n-i+1)*pow(i,mod-2,mod)
	ncb%=mod
	if i==a:
		nca=ncb
		
print((res-nca-ncb)%mod)
n = int(input())
a = list(map(int, input().split()))

b = list(sorted(set(a)))

def count_inversion(ans):
    s = [0 for _ in range(2 * n)]

    def bit_add(i):
        x = i
        while x < 2 * n:
            s[x] += 1
            x += x & -x

    def bit_sum(i):
        x = i
        ret = 0
        while x > 0:
            ret += s[x]
            x -= x & -x
        return ret

    temp = [n for _ in range(n + 1)]
    temp[0] = n + 1
    for i in range(n):
        if a[i] >= b[ans]:
            temp[i + 1] = temp[i] + 1
        else:
            temp[i + 1] = temp[i] - 1
    res = 0
    for i in range(n + 1):
        x = temp[i]
        res += bit_sum(x)
        bit_add(x)
    return res

m = n * (n + 1) // 2

ans = 0

l = 0
r = len(b)
while 1:
    ans = (l + r) // 2
    if count_inversion(ans) * 2 >= m:
        l = ans
    else:
        r = ans
    if r - l <= 1:
        ans = l
        break

print(b[ans])


### FIXED CODE ###

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

if n == 1:
    print(a[0])
    exit()

b = list(sorted(set(a)))

def count_inversion(ans):
    s = [0 for _ in range(2 * n + 2) ]

    def bit_add(i):
        x = i
        while x < 2 * n:
            s[x] += 1
            x += x & -x

    def bit_sum(i):
        x = i
        ret = 0
        while x > 0:
            ret += s[x]
            x -= x & -x
        return ret

    temp = [n for _ in range(n + 1)]
    temp[0] = n + 1
    for i in range(n):
        if a[i] >= b[ans]:
            temp[i + 1] = temp[i] + 1
        else:
            temp[i + 1] = temp[i] - 1
    res = 0
    for i in range(n + 1):
        x = temp[i]
        res += bit_sum(x)
        bit_add(x)
    return res

m = n * (n + 1) // 2

ans = 0

l = 0
r = len(b)
while 1:
    ans = (l + r) // 2
    if count_inversion(ans) * 2 >= m:
        l = ans
    else:
        r = ans
    if r - l <= 1:
        ans = l
        break

print(b[ans])
#a
A,B = map(int,input().split)
if A*B%2==1:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

#a
A,B = map(int,input().split())
if A*B%2==1:
    print("Yes")
else:
    print("No")
ソースコード 

Copy
Copy
n, y =  map(int, input().split())
 
res_a = -1
res_b = -1
res_c = -1
 
for i in range(n):
  for j in range(n):
      if 10000*i + 5000*j + 1000*k == y and i+j+k == n:
        res_a, res_b, res_c = i, j, n-i-j
        break
        
print(res_a, res_b, res_c)

### FIXED CODE ###

n, y =  map(int, input().split())
 
res_a = -1
res_b = -1
res_c = -1
 
for i in range(n+1):
  for j in range(n+1):
      if 10000*i + 5000*j + 1000*(n-i-j) == y and i+j <= n:
        res_a, res_b, res_c = i, j, n-i-j
        break
        
print(res_a, res_b, res_c)