Harryxun/stf_run huggingface dataset:
import collections
N = int(input())
A = list(map(int,input().split()))
CA = collections.Counter(A)
S = 0
for i in CA.values():
    S += i*(i-1)//2
for x in range(A):
    print(S - A.count(x) + 1)

### FIXED CODE ###

import collections
N = int(input())
A = list(map(int,input().split()))
CA = collections.Counter(A)
S = 0
for i in CA.values():
    S += i*(i-1)//2
for x in A:
    print(S - CA[x] + 1)
s = list(input())

for i ==2:
   sum+=s[i]
print(sum)

### FIXED CODE ###

s = list(input())

j = []
for ss in s:
     j.append(int(ss))
print(sum(j))
def main():
    n = int(input())
    s = list(map(int,input().split()))
    r = []
    for i in range(n,0,-1):
        c = sum(x % i == 0 for x in r)
        c1 = c % 2
        if c1 != s[i-1]:
            r.append(str(i))
            
    print(len(r))
    print(" ".join(r))
    

if __name__ == "__main__":
    main()

### FIXED CODE ###

def main():
    n = int(input())
    s = list(map(int,input().split()))
    r = [0] * n
    for i in range(n,n//2,-1):
        if s[i-1] == 1:
            r[i-1] = 1
    for i in range(n//2,0,-1):
        p = n // i
        c = 0
        for j in range(1,p+1):
            if r[(j * i) - 1] == 1:
                c += 1
        if c % 2 != s[i-1]:
            r[i-1] = 1

    o = sum(r)
    print(o)
    if o > 0:
        u = []
        for i in range(len(r)):
            if r[i] == 1:
                u.append(str(i+1))
        print(" ".join(u))
    
if __name__ == "__main__":
    main()
n,k=map(int, input().split())
a=list(map(int, input().split()))
b=[False]*n
pos=0
for i in range(k):
    if b[pos]!=False:
        loop=i-b[pos]+1
        break
    b[pos]=i+1
    pos=a[pos]-1
    k-=1

for i in range(k%loop):
    pos=a[pos]-1
print(pos+1)

### FIXED CODE ###

n,k=map(int, input().split())
a=list(map(int, input().split()))
b=[False]*n
pos=0
for i in range(min(n,k)):
    if b[pos]!=False:
        loop=i-b[pos]+1
        break
    b[pos]=i+1
    pos=a[pos]-1
    k-=1
if k>0:
    for i in range(k%loop):
        pos=a[pos]-1
print(pos+1)
s = input()
t = input()
for i in range(s):
    s.insert(0, s.pop(-1))
    if s == t:
        print("Yes")
print("No")

### FIXED CODE ###

s = list(input())
t = list(input())
for i in range(len(s)):
    s.insert(0, s.pop(-1))
    if s == t:
        print("Yes")
        exit()
print("No")
L,R =(int(x) for x in input().split())
if(L<2019<R):
    print(1)
elif(L<=3 and R>=673):
    print(0)
else:
    if((L%2019)^2 < (R%2019)^2):
        if(((L+1)%2019)^2 < (R%2019)^2):
            print((L*(L+1))%2019)
        else:
            print((L*R)%2019)
    else:
        if((L%2019)^2 < ((R-1)%2019)^2):
            print((R*L%2019))
        else:
            print(((R+1)*R)%2019)


### FIXED CODE ###

N,A,B =(int(x) for x in input().split())
An = N*A
if(An < B):
    print(An)
else:
    print(B)
n,m=map(int,input().split())
ans=[0]*n
for i in range(m):
    s,c=map(int,input().split())
    ans[s-1]=c
    if c!=0 and ans[s-1]==0:
        ans[s-1]=c 
        pans="0"
    else:
        pans="-1"
                
ans = [str(i) for i in ans]
if pans != "-1":
    pans="".join(ans)
    if pans[0]=="0":
        pans='1' + pans[1:]
print(pans)

### FIXED CODE ###

n,m=map(int,input().split())
d=["a"]*n
ans=""
if n==1 and m==0:
    print(0)
    exit()
for i in range(m):
    s,c=map(str,input().split())
    if s=="1" and c=="0" and n==1:
        print(0)
        exit()
    s=int(s)
    if d[s-1]=="a" or d[s-1]==c:
        d[s-1]=c #置き換え
    else:
        ans="-1"
        print(ans)
        break
if d[0]!="0" and ans!="-1":
    if d[0]=="a" or d[0]=="0":
        print("".join(["1"]+d[1:]).replace("a","0"))
    else:
        print(("".join(d)).replace("a","0"))
elif d[0]=="0":
    print(-1)
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
for j in range(m):
  a[0] //= 2
  a.sort(reverse=True)
print(sum(a))

### FIXED CODE ###

s = input()
if s == "Sunny" :
  print("Cloudy")
elif s == "Cloudy" :
  print("Rainy")
else :
  print("Sunny")
while True:
    (H, W) = [int(i) for i in input().split()]
    if H == W == 0:
        break

    for a in range(H):
        for b in range(w):
            print('#', end='')
        print()
    print()

### FIXED CODE ###

while True:
    (a, op, b) = [int(i) if i.isdigit() else i for i in input().split()]
 
    if op == '?':
        break
    elif op == '+':
        print(a + b)
    elif op == '-':
        print(a - b)
    elif op == '*':
        print(a * b)
    elif op == '/':
        print(a // b)
#include <iostream>
#include <vector>
using namespace std;

int main(void) {
    int N;
    cin >> N;
    
    vector<string> v;
    string s;
    for(int i=0; i<N; i++) {
        cin >> s;
        v.push_back(s);
    }

    for(int i=0; i<v.size(); i++) {
        sort(v[i].begin(), v[i].end());
    }

    int result = 0;
    for(int i=0; i<v.size(); i++) {
        result += count(v.begin()+i, v.end(), v[i]);
    }
    
    cout << result << endl;
    
    return 0;
}


### FIXED CODE ###

N = int(input())

s = ["".join(sorted(input())) for i in range(N)]

count = 0
d = {}
for elm in s:
    if elm in d:
        count += d[elm]
        d[elm] += 1
    else:
        d[elm] = 1

print(count)
import math

N, M = map(int, input().split())
S = input()
T = input()

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

d = math.gcd(N,M)
l = lcm(N,M)

s = [0 for i in range(0,d)]
t = [0 for i in range(0,d)]

a = l//M
b = l//N

for i in range(0,d):
    s[i] = S[i*a]
    t[i] = T[i*b]

if s == t:
    print(l)
else:
    print(-1)

### FIXED CODE ###

N, M = map(int, input().split())
S = input()
T = input()

def gcd(m,n):
    x = max(m,n)
    y = min(m,n)
    if x%y == 0:
        return y
    else:
        while x%y != 0:
            z = x%y
            x = y
            y = z
        else:
            return z

def lcm(m,n):
    return int(m * n /gcd(m,n))

d = gcd(N,M)
l = lcm(N,M)

s = [0 for i in range(0,d)]
t = [0 for i in range(0,d)]

a = int(l/M)
b = int(l/N)

for i in range(0,d):
    s[i] = S[i*a]
    t[i] = T[i*b]

if s == t:
    print(l)
else:
    print(-1)
nums = [1,2,3]
a = int(input())
b = int(input())
c = 0

for i in nums:
  if i != a && i != b:
    c = i
    
print(c)

### FIXED CODE ###

nums = [1,2,3]
a = int(input())
b = int(input())
c = 0

for i in nums:
  if int(i) != a and int(i) != b:
    c = int(i)
    
print(c)
from scipy.special import comb
r1, c1, r2, c2 = map(int, input().split())
mod = 1000000007
hole = (comb(r2 + c2 + 2, r2 + 1, exact=True) - 1) % mod
rect1 = (comb(r2 + c1 - 1 + 2, r2 + 1, exact=True) - 1) % mod
rect2 = (comb(r1 - 1 + c2 + 2, r1, exact=True) - 1) % mod
duplicate = (comb(r1 + c1, r1, exact=True) - 1) % mod
ans = (hole - rect1 - rect2 + duplicate) % mod
print(ans)

### FIXED CODE ###

r1, c1, r2, c2 = map(int, input().split())

p = 10 ** 9 + 7
size = 1010000 * 2
f_list = [1] * size
for i in range(1, size):
    f_list[i] = (f_list[i - 1] * i) % p

def cmb(n, r):
    return f_list[n + r] * pow(f_list[n], p-2, p) * pow(f_list[r], p-2, p) % p

hole = cmb(r2 + 1, c2 + 1) - 1
rect1 = cmb(r2 + 1, c1) - 1
rect2 = cmb(r1, c2 + 1) - 1
duplicate = cmb(r1, c1) - 1
ans = (hole - rect1 - rect2 + duplicate) % p
print(ans)
N = int(input())
odd = 0

if N % 2 = 0:
  odd = N / 2
else:
  odd = (N + 1) / 2

print(odd / N)

### FIXED CODE ###

N = int(input())
odd = 0
 
if N % 2 == 0:
  odd = N / 2
else:
  odd = (N + 1) / 2
 
print(odd / N)
H,W = map(int,input().split())
S = [list(input()) for _ in range(H)]
from collections import deque
ans = 0
for i in range(H):
  for j in range(W):
    if S[i][j]=='#':
      continue
    inf = 10**5
    A = [[inf]*W for _ in range(H)]
    A[i][j]=0
    judge = [[False]*W for _ in range(H)]
    judge[i][j]=True
    q = deque([[i,j]])
    while q:
      a = q.popleft()
      x=a[0]
      y=a[1]
      b = A[x][y]
      for m in [[x-1,y],[x+1,y],[x,y-1],[x,y+1]]:
        h = m[0]
        w = m[1]
        if (h<0)or(h>H-1)or(w<0)or(w>W-1):
          continue
        if S[h][w]=='#':
          continue
        c = b+1
        if judge[h][w]:
          continue
        A[h][w]=c
        judge[h][w]=True
        q.append([h,w])
        
    A = [a for b in A for a in b if a!=inf]
    ans = max(ans,max(A))
    
print(ans)

### FIXED CODE ###

C = input()
print(chr(ord(C)+1))
from sys import stdin

gets = stdin.readline

@profile
def main():
    n = int(gets())
    flag = False
    for h in range(3500, 1, -1):
        nh = n*h
        for w in range(1, h+1):
            y = (4 * h * w - nh - n*w)
            if y > 0 and (nh % y == 0 or w % y == 0):
                print(h, w, (nh*w)//y)
                flag = True
                break
        if flag:
            break
    return


if __name__ == "__main__":
    main()


### FIXED CODE ###

from sys import stdin

gets = stdin.readline


def main():
    n = int(gets())
    h, w = 0, 0
    flag = False
    for _ in range(3500):
        h += 1
        w = 0
        for _ in range(3500):
            w += 1
            y = (4 * h * w - n * (h + w))
            if y > 0:
                modulo = n % y * h % y * w % y
                if modulo % y == 0:
                    print(h, w, (n*h*w)//y)
                    flag = True
                    break
        if flag:
            break
    return


if __name__ == "__main__":
    main()
a, b = int(rawinput())
if a > b:
	print "a > b"
elif a < b:
	print "a < b"
else:
	print "a == b"

### FIXED CODE ###

a, b = map(int, raw_input().split())
if a > b:
	print "a > b"
elif a < b:
	print "a < b"
else:
	print "a == b"
N = int(input())
A = set()
for i in range(N):
   A.add(input())
if len(A) == 3:
   print(“Three”)
else:
   print(“Four”)

### FIXED CODE ###

N = int(input())
A = set(input().split())
if len(A) == 3:
   print("Three")
else:
   print("Four")
n=int(input())
s=input()
k=int(input())
t=s[k]
c=''
for i in range(0,n):
    if s[i] != t:
        c += '*'
    else: c += s[i]

print(c)

### FIXED CODE ###

n=int(input())
s=input()
k=int(input())
t=s[k-1]
c=''
for i in range(0,n):
    if s[i] != t:
        c += '*'
    else: c += s[i]

print(c)
def inpl():
    return list(map(int, input().split()))


def f(a, b):
    if a == 0 and b == 0:
        return True
    elif a * b == 0:
        return False
    else:
        return True

S = input()

N = S.count('N')
W = S.count('W')
S = S.count('S')
E = E.count('E')

if f(N, S) is True and f(W, E) is True:
    print('Yes')
else:
    print('No')

### FIXED CODE ###

def inpl():
    return list(map(int, input().split()))


def f(a, b):
    if a == 0 and b == 0:
        return True
    elif a * b == 0:
        return False
    else:
        return True


S = input()
# print(S)
cN = S.count('N')
cW = S.count('W')
cS = S.count('S')
cE = S.count('E')

if f(cN, cS) is True and f(cW, cE) is True:
    print('Yes')
else:
    print('No')
from functools import lru_cache
MOD = 1000000007

def valid(s):
    f = 0
    if len(s) == 4:
        f = 1
        if (s[0] == 'A' and s[2:] == 'GC') or (s[0:2] == 'AG' and s[3] == 'C'):
            return 0
    return s[f:] != 'AGC' and s[f:] != 'ACG' and s[f:] != 'GAC'
    

@lru_cache(maxsize=None)
def dfs(n, s):
    if not valid(s):
        return 0

    if n == N:
        return 1

    f = len(s) == 4
    a = dfs(n+1, s[f:] + 'A')
    b = dfs(n+1, s[f:] + 'C')
    c = dfs(n+1, s[f:] + 'G')
    d = dfs(n+1, s[f:] + 'T')
    return (a + b + c + d) % MOD
    

N = int(input())
ans = dfs(0, '')
print(ans)


### FIXED CODE ###

ans = {}
ans['A'] = 'T'
ans['T'] = 'A'
ans['C'] = 'G'
ans['G'] = 'C'


s = input()
print(ans[s])
from math import gcd
mod = 10**9 + 7
n = int(input())
arr = [int(j) for j in input().split()]

prod = 1
l = 1
for x in arr:
	g = gcd(l, x)
	prod = l*x
	l = prod//g

su = 0
for x in arr:
	su += (l//x)
print(su%mod)


### FIXED CODE ###

import sys
sys.setrecursionlimit(100000000)
def gcd(a,b): 
    if (b == 0): 
         return a 
    return gcd(b, a%b) 


mod = 10**9 + 7

n = int(input())
arr = [int(j) for j in input().split()]

prod = 1
l = 1
for x in arr:
	g = gcd(l, x)
	prod = l*x
	l = prod//g

su = 0
for x in arr:
	su += (l//x)
print(su%mod)
n = int(input())
st = input()

r = st.count("R")

count = 0

for i in range(r):
    if st[i]=="W":
        count += 1

print(count)
            

        


### FIXED CODE ###

k = int(input())
m = 7%k

for i in range(1, 10**6+1):
    if m == 0:
        print(i)
        exit()
    else:
        m = (10 * m + 7) % k

print(-1)
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
gu = v[::2]
ki = v[1::2]
ans = 0
k,g = False,False

###全部同じなら全長の半分,
# 最頻値が同じなら2番目を比べる
if v.count(v[0]) == n
    ans += n // 2
else:
    kic = Counter(ki)
    guc = Counter(gu)
    k1 = kic.most_common(2)
    g1 = guc.most_common(2)
    if k1[0][0] == g1[0][0]:
        if k1[1][1] < g1[1][1]:
            g = True
        else:
            k = True

    kic = list(kic.values())
    guc = list(guc.values())
    kic.sort(reverse = True)
    guc.sort(reverse = True)
    if len(kic) != 1:
        if k:
            ans += kic[0]
            ans += sum(kic[2::])
        else:
            ans += sum(kic[1::]) 
    if len(guc) != 1:
        if g:
            ans += guc[0]
            ans += sum(guc[2::])
        else:
            ans += sum(guc[1::])

print(ans)

### FIXED CODE ###

from collections import Counter
n = int(input())
v = list(map(int, input().split()))
gu = v[::2]
ki = v[1::2]
ans = 0
k,g = False,False

if v.count(v[0]) == n:#全部同じ
    ans += n // 2
else:
    kic = Counter(ki)
    guc = Counter(gu)
    k1 = kic.most_common(2)
    g1 = guc.most_common(2)
    if k1[0][0] == g1[0][0]:
        if k1[1][1] < g1[1][1]:
            k = True
        else:
            g = True

    kic = list(kic.values())
    guc = list(guc.values())
    kic.sort(reverse = True)
    guc.sort(reverse = True)
    if len(kic) != 1:
        if g:
            ans += kic[0]
            ans += sum(kic[2::])
        else:
            ans += sum(kic[1::]) 
    if len(guc) != 1:
        if k:
            ans += guc[0]
            ans += sum(guc[2::])
        else:
            ans += sum(guc[1::])

print(ans)
a,b,c = list(map(int,input().split()))
if a==b+c or b==a+c or c==a+b :print('Yes')
  else:print('No')


### FIXED CODE ###

a,b,c = list(map(int,input().split()))
if a==b+c or b==a+c or c==a+b :print('Yes')
else:print('No')
N,K = map(int,input().split())
list = list(map(int,input().split()))
a = 1
list2=[]
begin = 0
time = 0
flag=False
while flag==False:
    a = list[a-1]
    for i,x in enumerate(list2):
        if x == a:
            begin=i
            time = len(list2)-begin
            flag=True
    list2.append(a)
if K<=begin:
    print(list2[K-1])
else:
    print(list2[begin:begin+time][(K-begin)%time-1])

### FIXED CODE ###

S=input()
T=input()
if S==T[:-1]:
    print("Yes")
else:
    print("No")
print('Yes' if all(input().count(t)>0 for t in 'abc') else 'No')

### FIXED CODE ###

a=input()
print('Yes' if all(a.count(t)>0 for t in 'abc') else 'No')
n = input()

count = 0

l = len(n)

#kisu
if l % 2:
  num = n[1:l]
  count += int(num) + 1
  l -= 1
#gusu
for i in range(l):
  tmp = 1
  if (i+1) % 2:
    for j in range(i+1):
      tmp *= 10
    tmp -= float(tmp) / float(10)
    count += tmp
    
print(int(count))

### FIXED CODE ###

n = input()

count = 0

l = len(n)

if l % 2:
  num = n[0:l]
  tmp = 1
  for i in range(l-1):
    tmp *= 10
  count += int(num) - tmp + 1
  l -= 1

for i in range(l):
  tmp = 1
  if (i+1) % 2:
    for j in range(i+1):
      tmp *= 10
    tmp -= int(float(tmp) / float(10))
    count += tmp
    
print(count)
S=int(input())
A=[0 for i in range(S+1)]
B=[0 for i in range(S+1)]
A[3]=1
B[3]=1
A[4]=1
B[4]=2
A[5]=1
B[5]=3
for i in range(6,S+1):
    A[i]=(B[i-3]+1)%(10**9+7)
    B[i]=(B[i-1]+A[i])%(10**9+7)
print(A[S])

### FIXED CODE ###

S=int(input())
A=[0 for i in range(max(S+1,10))]
B=[0 for i in range(max(S+1,10))]
A[3]=1
B[3]=1
A[4]=1
B[4]=2
A[5]=1
B[5]=3
for i in range(6,S+1):
    A[i]=(B[i-3]+1)%(10**9+7)
    B[i]=(B[i-1]+A[i])%(10**9+7)
print(A[S])
inputs = [int(x) for x in input().split(" ")]
A = inputs[0]
B = inputs[1]


if A > B:
	print("GREATER")
elif A < B:
	print("LESS")
else:
	print("EQUAL")

### FIXED CODE ###


A = int(input())
B = int(input())


if A > B:
	print("GREATER")
elif A < B:
	print("LESS")
else:
	print("EQUAL")
N=input()

for i in range(len(N)):
  if(N[i]=="1!):
     print("9", end="")
  if(N[i]=="9!):
     print("1", end="")


### FIXED CODE ###

N=input()
 
for i in range(len(N)):
  if(N[i]=="1"):
     print("9", end="")
  if(N[i]=="9"):
     print("1", end="")
# Vol0004.
import sys

def main():
    data = []
    lines = sys.stdin.readlines()
    fp.close()

    for line in lines:
        data.append(line.split())  # スペース区切りで放り込む
    # ax + by = c, dx + ey = fの解は、
    # x = (ce - bf) / (ae - bd), y = (af - cd) / (ae - bd).
    # これをround(float, 3)すれば答えが出る。
    N = len(data)
    for i in range(N):
        for k in range(6):
            data[i][k] = int(data[i][k])
        det = data[i][0] * data[i][4] - data[i][1] * data[i][3]
        gx = data[i][2] * data[i][4] - data[i][1] * data[i][5]
        gy = data[i][0] * data[i][5] - data[i][2] * data[i][3]
        if det < 0:
            det = -det;
            if gx != 0: gx = -gx
            if gy != 0: gy = -gy
        print("{0:.3f}".format(gx / det) + " " + "{0:.3f}".format(gy / det))

if __name__ == "__main__":
    main()

# 補足、0.1とか0.22でも3桁目まで表示しないとWrongになる。
# 表示するにはprint("{0:.nf}".format(数))ってやる(nのところは桁数)。
# さらに、0を負の数で割ると表示が-0.000になってしまうのでそこの処理も重要。


### FIXED CODE ###

# Vol0004.
import sys

def main():
    data = []
    lines = sys.stdin.readlines()

    for line in lines:
        data.append(line.split())  # スペース区切りで放り込む
    # ax + by = c, dx + ey = fの解は、
    # x = (ce - bf) / (ae - bd), y = (af - cd) / (ae - bd).
    # これをround(float, 3)すれば答えが出る。
    N = len(data)
    for i in range(N):
        for k in range(6):
            data[i][k] = int(data[i][k])
        det = data[i][0] * data[i][4] - data[i][1] * data[i][3]
        gx = data[i][2] * data[i][4] - data[i][1] * data[i][5]
        gy = data[i][0] * data[i][5] - data[i][2] * data[i][3]
        if det < 0:
            det = -det;
            if gx != 0: gx = -gx
            if gy != 0: gy = -gy
        print("{0:.3f}".format(gx / det) + " " + "{0:.3f}".format(gy / det))

if __name__ == "__main__":
    main()

# 補足、0.1とか0.22でも3桁目まで表示しないとWrongになる。
# 表示するにはprint("{0:.nf}".format(数))ってやる(nのところは桁数)。
# さらに、0を負の数で割ると表示が-0.000になってしまうのでそこの処理も重要。
import math
n = int(input())
circumference = 2 * pi * n
print(circumference)

### FIXED CODE ###

import math
n = int(input())
circumference = n * 2 * math.pi
print(circumference)
#  import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
import numpy as np


#  sys.setrecursionlimit(10**7)
#  inf = 10 ** 20
#  eps = 1.0 / 10**10
#  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 LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)

def main():
    N = I()
    h = LI()
    h = np.array(h)
    #  print(N, h)
    # 0以上の塊をみつける
    # その塊に水をやる
    # 以上を繰り返す
    count = 0
    while True:
        #  print(h)
        first_non_zero_idx = [idx for idx, i in enumerate(h) if i != 0]
        if len(first_non_zero_idx) == 0:
            # 終了
            print(count)
            return
        else:
            first_non_zero_idx = first_non_zero_idx[0]

        first_zero_idx = [idx for idx, i in enumerate(h) if idx > first_non_zero_idx and i == 0]
        if len(first_zero_idx) == 0:
            # 0がないので最後まで水をやる
            first_zero_idx = len(h)
        else:
            first_zero_idx = first_zero_idx[0]

        # 水をやる
        h[first_non_zero_idx:first_zero_idx] -= 1
        count += 1





main()


### FIXED CODE ###

import numpy as np
N = int(input())
h = list(map(int, input().split()))
diff = np.array([i for i in h])


# 右から見ていったときに、最小値までの数値と、それ以降昇順になっている値までに最小値を足す
# 以降それを繰り返す
def find_min_idx(l):
    # 0以外で最小の値を取得
    non_0_list = [i for i in l if i != 0]
    min_value = min(non_0_list)
    min_idx = np.where(l == min_value)[0][0]
    return min_idx


def get_min_value(l, min_idx):
    return l[min_idx]


def get_end_idx(l, min_idx, min_value):
    for idx, i in enumerate(l):
        if idx > min_idx:
            if i == 0:
                return idx - 1
            if i < min_value or i == 0:
                return idx - 1
    else:
        return len(l) - 1


def find_start_idx(l, min_idx):
    if len(l[:min_idx]) == 0:
        return 0
    for idx, i in enumerate(reversed(l[:min_idx])):
        if i == 0:
            return idx
    else:
        return len(l[:min_idx])-1


count = 0
while not all([i == 0 for i in diff]):
    #  print(count, diff)
    #  import pdb
    #  pdb.set_trace()
    min_idx = find_min_idx(diff)
    min_value = get_min_value(diff, min_idx)
    end_idx = get_end_idx(diff, min_idx, min_value)
    start_idx = find_start_idx(diff, min_idx)
    #  print('min_idx, end_idx, start_idx', min_idx, end_idx, start_idx)
    #  import pdb
    #  pdb.set_trace()
    for idx, i in enumerate(diff):
        if i == 0:
            continue

        if idx <= end_idx:
            if idx >= min_idx - start_idx - 1:
                diff[idx] -= min_value
            elif idx >= min_idx:
                diff[idx] -= min_value

    count += min_value

    #  print(count, diff, '\n')

print(count)
l = []
for i in range(N):
    s, p = input().split()
    l.append([s, int(p), i + 1])

l.sort(key = lambda x: (x[0], -x[1]))
for i in l:
    print(i[2])

### FIXED CODE ###

N = int(input())
l = []
for i in range(N):
    s, p = input().split()
    l.append([s, int(p), i + 1])

l.sort(key = lambda x: (x[0], -x[1]))
for i in l:
    print(i[2])
def D_Derangement(N, p):
    count = 0
    i = 0
    while i < N:
        if p[i] == i + 1:
            if p[i + 1] == i + 2:
                count += 1
                i += 2
                continue
            else:
                count += 1
                i += 1
                continue
        else:
            i += 1
            continue
    return count
 
N = int(input())
p = [int(i) for i in input().split()]
print(D_Derangement(N, p))

### FIXED CODE ###

def D_Derangement(N, p):
    count = 0
    i = 0
    while i < N:
        if p[i] == i + 1: #p_i=iなら
            count += 1
            i += 2
        else:
            i += 1
            continue
    return count
 
N = int(input())
p = [int(i) for i in input().split()]
print(D_Derangement(N, p))
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

dp = [0]*N

for i in range(N):
  dp[i] = min(A[i], B[i])
  A[i], B[i] -= dp[i]
  if rem==0:
    tmp = min(A[i+1], B[i])
    dp[i] += tmp
    A[i+1] -= tmp
print(sum(dp))


### FIXED CODE ###

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

dp = [0]*N #勇者が倒す数

for i in range(N):
  dp[i] = min(A[i], B[i])
  A[i] -= dp[i]
  B[i] -= dp[i]
  rem = A[i]
  if rem==0:
    tmp = min(A[i+1], B[i])
    dp[i] += tmp
    A[i+1] -= tmp
print(sum(dp))