Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

s = input()
n = len(s)

while s != "":
    for i in range(n):
        if i == n-1:
            print(n)
            exit()
        if s[i]+s[i+1] == "ST":
            s = s[:i] + s[i+2:]
            n = len(s)
            break

print(0)

### FIXED CODE ###

s = input()
array = []

for char in s:
    if char == "S":
        array.append(char)
    elif char == "T":
        if len(array) == 0:
            array.append(char)
        elif array[-1] == "S":
            array.pop()
        else:
            array.append(char)
print(len(array))
### BUGGY CODE ###

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

ans = 0
for i in range(N+1):
    if i * R > N:
        break
    for j in range(N+1):
        if i * R + j * G > N:
            break
        for k in range(N+1):
            if i * R + j * G + B * k > N:
                break
            if i * R + j * G + B * k == N:
                ans += 1
                
print(ans)

### FIXED CODE ###

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

ans = 0

for g in range(N//G+1):
    for b in range(N//B+1):
        s = N-g*G-b*B
        if s < 0:
            break
        if s%R == 0:
            ans += 1

print(ans)
### BUGGY CODE ###

INF = float("inf")

H, N, *AB = map(int, open(0).read().split())

dp = [0] + [INF] * (H + max(AB[::2]))

for a, b in zip(*[iter(AB)] * 2):
    for i in range(a, len(dp)):
        if dp[i - a] != INF:
            dp[i] = min(dp[i], dp[i - a] + b)

print(min(dp[H:]))

### FIXED CODE ###

INF = float("inf")

H, N, *AB = map(int, open(0).read().split())

dp = [INF] * (H + 10 ** 4 + 10)
dp[0] = 0

for a, b in zip(*[iter(AB)] * 2):
    for i in range(a, len(dp)):
        if dp[i - a] != INF:
            dp[i] = min(dp[i], dp[i - a] + b)

print(min(dp[H:]))
### BUGGY CODE ###

import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

def main():
    n = int(input())
    res = 0
    for i in range(n):
        for j in range(n):
            for k in range(n):
                res += gcd(i+1, j+1, k+1)
    print(res)


if __name__ == '__main__':
    main()



### FIXED CODE ###

import numpy as np
from itertools import combinations

def main():
    k = int(input())
    res = 0
    memo = np.zeros((k+1, k+1), int)
    for i in range(1, k+1):
        for j in range(i, k+1):
            tmp = np.gcd(i,j)
            memo[i][j] = tmp
            memo[j][i] = tmp

    for i in range(1, k+1):
        res += i 

    for c in combinations(range(1,k+1),2):
        ab = memo[c[0], c[1]]
        res += ab * 6

    for c in combinations(range(1,k+1), 3):
        ab = memo[c[0], c[1]]
        abc = memo[ab, c[2]]
        res += abc * 6
    print(res)


if __name__ == '__main__':
    main()
### BUGGY CODE ###

import sys
input = sys.stdin.readline

n, m = [int(x) for x in input().split()]
g = [[] for _ in range(n)]

for _ in range(m):
    l, r, d = [int(x) for x in input().split()]
    l -= 1
    r -= 1
    g[l].append([r, d])
    g[r].append([l, -d])

visited = [0] * n

for i in range(n):
    if visited[i] != 0:
        continue
    d = [0] * n
    d[i] = 0
    stack = [i]
    while stack:
        u = stack.pop()
        visited[u] = 1
        for v, d_ in g[u]:
            visited[v] = 1
            if d[v] == 0:
                d[v] = d[u] + d_
            else:
                if d[v] != d[u] + d_:
                    print("No")
                    sys.exit()
        if g[u] and v != i:
            stack.append(v)
print("Yes")


### FIXED CODE ###

n, m = map(int, input().split())
ed = [[] for _ in range(n)]  # グラフ
v = [None] * n
for _ in range(m):
  l, r, d = map(int, input().split())
  ed[l-1].append((r-1, d))  # l -> r
  ed[r-1].append((l-1, -d))  # r -> l

visited = [False] * n  # 訪問フラグ（非連結の可能性の為）

def dfs(start):
  s = [start]
  v[start] = 0
  while s:
    label = s.pop()
    if visited[label] == False:
      visited[label] = True
      for to, dist in ed[label]:
        if v[to] is None:
          v[to] = v[label] + dist
          s.append(to)
        else:
          if v[to] != v[label] + dist:
            return False
  return True

is_exist = True
for i in range(n):
  if v[i] is None:
    if not dfs(i):
      print('No')
      is_exist = False
      break
if is_exist:
  print("Yes")
### BUGGY CODE ###

def sl_insert(vals:list, new_val):
    index = sl_indexof(vals, new_val)
    if index < 0:
        index = -index
    vals.insert(index, new_val)   
    return
def sl_remove(vals:list, new_val):
    index = sl_indexof(vals, new_val)
    if index < 0:
        return
    del vals[index]
    return

def sl_indexof(vals:list, new_val):
    l = 0
    r = len(vals)
    while l < r:
        m = (l + r) // 2
        if vals[m] == new_val:
            return m
        elif vals[m] < new_val:
            l = m + 1
        else:
            r = m
    return -l

n, q = map(int, input().split())
events = []

for i in range(n):
    s, t, x = map(int, input().split())
    if t >= x:
        events.append([t - x, 0, x])
        events.append([s - x, 1, x])
for i in range(q):
    d = int(input())
    events.append([d, 2, i])
events.sort()

dist = [-1] * q
walker = []
working = []
for t, kind, x in events:
    if kind == 0:
        sl_remove(working, x)
    elif kind == 1:
        sl_insert(working, x)
    elif any(working):
        dist[x] = working[0]
    else:
        walker.append(x)

for d in dist:
    print(d)

### FIXED CODE ###

from heapq import heappush, heappop


n, q = map(int, input().split())
events = []

for i in range(n):
    s, t, x = map(int, input().split())
    if t >= x:
        events.append([t - x, 0, x])
        events.append([s - x, 1, x])
for i in range(q):
    d = int(input())
    events.append([d, 2, i])
events.sort()

dist = [-1] * q
walker = []
working = set()
heap = []
for t, kind, x in events:
    if kind == 0:
        working.remove(x)
    elif kind == 1:
        working.add(x)
        heappush(heap, x)
    elif working:
        while not heap[0] in working:
            heappop(heap)
        dist[x] = heap[0]

for d in dist:
    print(d)
### BUGGY CODE ###

n = int(input())
p = list(map(int,input().split()))
c = 0
for i in range(1,n+1):
  if p[i-1] == min(p[:i]):
    c += 1
print(c)


### FIXED CODE ###

n = int(input())
p = list(map(int,input().split()))
c = 0
m = p[0]
for i in range(n):
    if p[i] <= m :
        m = p[i]
        c += 1
print(c)
### BUGGY CODE ###

def main():
    # input
    N, T = map(int, input().split())
    a, b = [], []
    a0_b = []
    for i in range(N):
        a_in, b_in = map(int, input().split())
        if a_in == 0:
            a0_b.append(b_in)
        else:
            a.append(a_in)
            b.append(b_in)
    L = len(a)

    # sort
    ab_ratio = [a[i] / (b[i] + 1) for i in range(L)]
    key = sorted(range(L), key=lambda x: -ab_ratio[x])
    a = [a[i] for i in key]
    b = [b[i] for i in key]
    a0_b.sort()

    # --- case a >= 1 --- #
    # dp[for i shops][passed j shops] := min time
    # j:29 for T < 10^9
    J_MAX = min(L + 1, 29)
    dp = [[float('inf') for _ in range(J_MAX)] for _ in range(L + 1)]
    dp[0][0] = 0
    for i in range(L):
        for j in range(J_MAX):
            if j > 0:
                dt = 1 + a[i] * (dp[i][j - 1] + 1) + b[i]
                if dp[i][j - 1] + dt <= T:
                    dp[i + 1][j] = min(dp[i][j], dp[i][j - 1] + dt)
                else:
                    dp[i + 1][j] = dp[i][j]
            else:
                dp[i + 1][j] = dp[i][j]

    # --- case a = 0 --- #
    ans = 0
    for i in range(J_MAX):
        if dp[L][i] == float('inf'):
            break
        else:
            time_cnt = dp[L][i]
            shop_cnt = i
            for t_b in a0_b:
                if time_cnt + 1 + t_b <= T:
                    time_cnt += 1 + t_b
                    shop_cnt += 1
            if ans < shop_cnt:
                ans = shop_cnt

    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
input = sys.stdin.readline


def main():
    # input
    N, T = map(int, input().split())
    a, b = [], []
    a0_b = []
    for i in range(N):
        a_in, b_in = map(int, input().split())
        if a_in == 0:
            a0_b.append(b_in)
        else:
            a.append(a_in)
            b.append(b_in)
    L = len(a)

    # sort
    ab_ratio = [a[i] / (b[i] + 1) for i in range(L)]
    key = sorted(range(L), key=lambda x: -ab_ratio[x])
    a = [a[i] for i in key]
    b = [b[i] for i in key]
    a0_b.sort()

    # --- case a >= 1 --- #
    # dp[for i shops][passed j shops] := min time
    # j:29 for T < 10^9
    J_MAX = min(L + 1, 29)
    dp = [[float('inf') for _ in range(J_MAX)] for _ in range(L + 1)]
    dp[0][0] = 0
    for i in range(L):
        for j in range(J_MAX):
            if j > 0:
                dt = 1 + a[i] * (dp[i][j - 1] + 1) + b[i]
                if dp[i][j - 1] + dt <= T:
                    dp[i + 1][j] = min(dp[i][j], dp[i][j - 1] + dt)
                else:
                    dp[i + 1][j] = dp[i][j]
            else:
                dp[i + 1][j] = dp[i][j]

    # --- case a = 0 --- #
    ans = 0
    for i in range(J_MAX):
        if dp[L][i] == float('inf'):
            break
        else:
            time_cnt = dp[L][i]
            shop_cnt = i
            for t_b in a0_b:
                if time_cnt + 1 + t_b <= T:
                    time_cnt += 1 + t_b
                    shop_cnt += 1
            if ans < shop_cnt:
                ans = shop_cnt

    print(ans)


if __name__ == '__main__':
    main()
### BUGGY CODE ###

import math

a, b, n = map(int, input().split())
ans = 0
for x in range(1, n+1):
    ans = max(ans, (math.floor(a * x / b) - a * math.floor(x / b)))
print(ans)

### FIXED CODE ###

import math

a, b, n = map(int, input().split())
x = min(b-1, n)
ans = math.floor(a * x / b) - a * math.floor(x / b)
print(ans)
### BUGGY CODE ###

import sys

N = int(sys.stdin.readline())

l = 0
r = N - 1

p = 0
print(p)
first = sys.stdin.readline().strip()
if first == "Vacant":
    sys.exit()
if first == "Male":
    second = "Female"
else:
    second = "Male"

while True:
    # pは偶数
    p = (l + r) // 2
    print(p)
    sex = sys.stdin.readline().strip()
    if sex == "Vacant":
        # print("end!")
        sys.exit()
    if p % 2 == 0:
        # pまでの間に空席がない場合は性別が同じ
        if sex == first:
            l = p + 1
        # ずれているので、そこまでに空席がある
        else:
            r = p
    else:
        if sex == second:
            l = p + 1
        else:
            r = p

### FIXED CODE ###

import sys

N = int(sys.stdin.readline())

l = 0
r = N - 1

p = 0
print(p, flush=True)
first = sys.stdin.readline().strip()
if first == "Vacant":
    sys.exit()
if first == "Male":
    second = "Female"
else:
    second = "Male"

while True:
    p = (l + r) // 2
    print(p, flush=True)
    sex = sys.stdin.readline().strip()
    if sex == "Vacant":
        # print("end!")
        sys.exit()
    if p % 2 == 0:
        # pまでの間に空席がない場合は性別が同じ
        if sex == first:
            l = p + 1
        # ずれているので、そこまでに空席がある
        else:
            r = p
    else:
        if sex == second:
            l = p + 1
        else:
            r = p
### BUGGY CODE ###

from collections import deque
n=int(input())
A=list(map(int,input().split()))
ans=deque()
for i in range(n):
  ans.append(1+A.index(i+1))
print(*ans)

### FIXED CODE ###


n=int(input())
A=list(map(int,input().split()))
ans=[0]*n
for i in range(n):
  ans[A[i]-1]=i+1
print(*ans)
### BUGGY CODE ###

S = input()


MOD = 10**9 + 7

# time complexity: O(|S|)
def focus_on_B():
    char_to_idx = {"A": 0,
                     "C": 1,
                     "?": 2}

    cuml = [[0] * 3 for _ in range(len(S))]
    num_A = num_C = num_q = 0
    for i, char in enumerate(S):
        if char == "A":
            num_A += 1
        elif char == "C":
            num_C += 1
        elif char == "?":
            num_q += 1
        cuml[i][0] = num_A
        cuml[i][1] = num_C
        cuml[i][2] = num_q

    num_combinations = 0
    for i in range(1, len(S) - 1):
        if S[i] in {"B", "?"}:
            A_L = cuml[i-1][0]
            Q_L = cuml[i-1][2]
            C_R = cuml[-1][1] - cuml[i][1]
            Q_R = cuml[-1][2] - cuml[i][2]
            left_pow = 3**Q_L
            right_pow = 3**Q_R
            num_combinations += (A_L * left_pow + Q_L * left_pow//3) * (C_R * right_pow + Q_R * right_pow//3)
            num_combinations %= MOD
        else:
            continue
    print(num_combinations)


focus_on_B()


### FIXED CODE ###

S = input()

MOD = 10**9 + 7
dp = [[0] * 4 for _ in range(len(S) + 1)]
dp[len(S)][3] = 1
for i in range(len(S))[::-1]:
    dp[i][3] = 3 * dp[i + 1][3] if S[i] == "?" else dp[i + 1][3]
    dp[i][3] %= MOD
    if S[i] == "?":
        dp[i][0] = (3 * dp[i + 1][0] + dp[i + 1][1]) % MOD
        dp[i][1] = (3 * dp[i + 1][1] + dp[i + 1][2]) % MOD
        dp[i][2] = (3 * dp[i + 1][2] + dp[i + 1][3]) % MOD
    else:
        dp[i][0] = (dp[i + 1][0] + int(S[i] == "A") * dp[i + 1][1]) % MOD
        dp[i][1] = (dp[i + 1][1] + int(S[i] == "B") * dp[i + 1][2]) % MOD
        dp[i][2] = (dp[i + 1][2] + int(S[i] == "C") * dp[i + 1][3]) % MOD
print(dp[0][0])
### BUGGY CODE ###

n = int(input())
s = input()
cnt = s.count('R')*s.count('G')*s.count('B')
for i in range(n-2):
    for j in range(i+1,n-1):
        if s[i] != s[j]:
            if 2*j-i <= n-1:
                if s[2*j-i] not in(s[i],s[j]):
                    cnt -= 1
print(cnt)

### FIXED CODE ###

n = int(input())
s = input()
cnt = s.count('R')*s.count('G')*s.count('B')
for i in range(n-2):
    for j in range(i+1,n-1):
        if s[i] != s[j]:
            if 2*j-i > n-1:
                break
            if s[2*j-i] not in(s[i],s[j]):
                cnt -= 1
print(cnt)
### BUGGY CODE ###

from bisect import *
N,M = map(int,input().split())
A = sorted(list(map(int,input().split())))

for m in range(M):
  A[-1]//=2
  A.insert(bisect_left(A,A[-1]),A[-1])
  A.pop()
  
print(sum(A))

### FIXED CODE ###

from heapq import *
N,M = map(int,input().split())
A = list(map(lambda x:-int(x),input().split()))
heapify(A)

for m in range(M):
  heappush(A,int(heappop(A)/2))

print(-sum(A))
### BUGGY CODE ###

H,W = map(int,input().split())
maze = []
for i in range(H):
  s = input()
  maze.append(s)
def distance(maze,H,W):
  wall = []
  for i in range(H):
    w = [-1]
    for j in range(W):
      if maze[i][j] == '#':
        w.append(j)
    w.append(W)
    wall.append(w)

  wd = [[0]*W for _ in range(H)]
  for i in range(H):
    w1 = 0
    for j in range(W):
      if maze[i][j] == '#':
        w1 = min(w1+1,len(wall[i])-1)
        continue
      wd[i][j] = j-wall[i][w1]-1+wall[i][w1+1]-j-1

  return wd

wd = distance(maze,H,W)
maze = [list(x) for x in zip(*maze)]
hd = distance(maze,W,H)
max_dist = 1

for i in range(H):
  for j in range(W):
    max_dist = max(max_dist,wd[i][j] + hd[j][i]+1)
print(max_dist)

### FIXED CODE ###

H,W = map(int,input().split())
maze = []
for i in range(H):
  s = input()
  maze.append(s)
def distance(maze,H,W):
  wall = []
  for i in range(H):
    w = [-1]
    for j in range(W):
      if maze[i][j] == '#':
        w.append(j)
    w.append(W)
    wall.append(w)

  wd = [[0]*W for _ in range(H)]
  for i in range(H):
    w1 = 0
    for j in range(W):
      if maze[i][j] == '#':
        w1 = min(w1+1,len(wall[i])-1)
        continue
      wd[i][j] = j-wall[i][w1]-1+wall[i][w1+1]-j-1

  return wd

wd = distance(maze,H,W)
maze = [list(x) for x in zip(*maze)]
hd = distance(maze,W,H)
max_dist = 1

for i in range(H):
  for j in range(W):
    max_dist = max(max_dist,wd[i][j] + hd[j][i]+1)
print(max_dist)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(1000000)


def main():
  N,Q = map(int,input().split())
  trees = [[] for _ in range(N+1)]
  values = [0 for _ in range(N+1)]
  
  for _ in range(N-1):
    parent,child = map(int,input().split())
    trees[parent].append(child)
    trees[child].append(parent)
  
  for _ in range(Q):
    node_num,value = map(int,input().split())
    values[node_num] += value
  
  def recursive_func(i,parent):
    for child in trees[i]:
      if child == parent:
        continue
      values[child] += values[i]
      recursive_func(child,i)
  
  recursive_func(1,-1)
  print(*values[1:])


if __name__ == "__main__":
  main()

### FIXED CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
n, q = map(int, input().split())

trees = [ [] for i in range(n+1) ]
for i in range(n-1):
    a, b = map(int, input().split())
    trees[a].append(b)
    trees[b].append(a)

values = [ 0 for i in range(n+1) ]
for i in range(q):
    p, x = map(int, input().split())
    values[p] += x
#print(values)

def dfs2(i, parent):
    for j in trees[i]:
        if j == parent: continue
        values[j] += values[i]
        dfs2(j, i)

dfs2(1, -1)
print(*values[1:])
### BUGGY CODE ###

n = int(input())
a = [0]*n
for i in range(n):
  a[i] = int(input())

x = sorted(set(a), reverse = True)
t = [0]*2
if len(x) > 1:
  t[0],t[1] = x[0],x[1]
else:
  t[0],t[1] = x[0],x[0]
  
max = t[0]  
for i in range(n):
  if a[i] == max:
    if a.count(max) > 1:
      print(max)
    else:
      print(t[1])
  else:
    print(max)
  

### FIXED CODE ###

n = int(input())
a = [0]*n
for i in range(n):
  a[i] = int(input())

x = sorted(set(a), reverse = True)
t = [0]*2
if len(x) > 1:
  t[0],t[1] = x[0],x[1]
else:
  t[0],t[1] = x[0],x[0]
  
max = t[0]
count= a.count(max)
for i in range(n):
  if a[i] == max:
    if count > 1:
      print(max)
    else:
      print(t[1])
  else:
    print(max)
### BUGGY CODE ###

N = int(input())
X = input()

plus = bin(int(X, 2)).count('1') + 1
minus = bin(int(X, 2)).count('1') - 1
if minus < 1:
  minus = 1

init_n = [0] * N
init_X = [0] * N
for i in range(N):
  X_list = list(X)
  if X_list[i] == '0':
    X_list[i] = '1'
    first = plus
  else:
    X_list[i] = '0'
    first = minus
  X_str = ''.join(X_list)
  init_n[i] = int(X_str, 2)
  init_X[i] = init_n[i] % first

for i in range(N):
  
  fn = 0
  n = init_n[i]
  if n != 0:
    n = init_X[i]
    fn += 1
  while n != 0:
    n = n % bin(n).count('1')
    fn += 1
  
  print(fn)
  

### FIXED CODE ###

N = int(input())
X = input()

X_int = int(X, 2)
cnt1 = bin(X_int).count('1')
pcXi01 = cnt1 + 1
pcXi10 = cnt1 - 1
zero_idx = N + 5
if cnt1 == 1:
  for i in range(N):
    if X[i] == '1':
      zero_idx = i

if pcXi10 < 1:
  pcXi10 = 1
Xmod01 = X_int % pcXi01
Xmod10 = X_int % pcXi10

tmp01 = [1]
tmp10 = [-1]
for i in range(N - 1):
  tmp01.append(tmp01[i]*2 % pcXi01)
  tmp10.append(tmp10[i]*2 % pcXi10)

init_n = [0] * N
next_n = [0] * N
for i in range(N):
  if X[i] == '0':
    next_n[i] = (Xmod01 + tmp01[N - 1 - i]) % pcXi01
  else:
    next_n[i] = (Xmod10 + tmp10[N - 1 - i]) % pcXi10

for i in range(N):
  fn = 0
  if i == zero_idx:
    print(0)
    continue

  n = next_n[i]
  fn += 1
  while n != 0:
    n = n % bin(n).count('1')
    fn += 1
  
  print(fn)
### BUGGY CODE ###

n = int(input())
a = list(map(int, [input() for _ in range(n)]))
ans = 0
for i in set(a):
  if a.count(i) % 2 == 1:
    ans += 1
print(ans)


### FIXED CODE ###

n = int(input())
s = set()
for i in range(n):
  a = input()
  if a in s:
    s.remove(a)
  else:
    s.add(a)
print(len(s))
### BUGGY CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N,M = map(int,readline().split())
A=[int(x) for x in readline().split()]
BC=[]
for i in range(M):
  BC +=[list(map(int,readline().split()))]
BC = sorted(BC, key=lambda x: x[1],reverse = True)
A=sorted(A)
for i in range(M):
  for j in range(BC[i][0]):
    A[j]=max(A[j],BC[i][1])
  A=sorted(A)
print(sum(A))

### FIXED CODE ###

N,M=map(int,input().split())
A=[int(x) for x in input().split()]
CB=[]
for i in range(M):
  B,C = map(int,input().split())
  CB +=[[C,B]]

for j in range(N):
  CB +=[[A[j],1]]

CB=sorted(CB,reverse = True)
count = 0
result =0

i=0
while count<N:
  count +=CB[i][1]
  result +=CB[i][0]*CB[i][1]
  i +=1

result -= (count-N)*(CB[i-1][0])
print(result)
### BUGGY CODE ###

import numpy as np

N, M  = [int(i) for i in input().split()]
A = []
for i in range(N):
    A.append([int(i) for i in input().split()])

A = np.array(A)
B = A[:,1]
A = A[:,0]

#print(N)
#print(M)
#print(A)
#print(B)
x = 0
cost = 0

while x < M:
    i = np.argmin(A)
    
    if x + B[i] <= M:
        cost += A[i] * B[i]
        x += B[i]
        A = np.delete(A, i)
        B= np.delete(B, i)
        #print(A)
        #print(B)
#        print(cost)
#        print(x)
    else:
        #print(A[i])
        #print(M-x)
        cost += A[i] * (M-x)
        x += (M-x)
        #print(cost)
        #print(x)


print(cost)

### FIXED CODE ###

import numpy as np

N, M  = [int(i) for i in input().split()]
A = []
for i in range(N):
    A.append([int(i) for i in input().split()])

A = np.array(A)
B = A[:,1]
A = A[:,0]

#print(N)
#print(M)
#print(A)
#print(B)
x = 0
cost = 0

p = np.argsort(A)
A = A[p]
B = B[p]
#print(A)
#print(B)

i = 0
#print(A)
#print(B)

while x < M:
    # i = np.argmin(A)
        #A = np.delete(A, i)
        #B= np.delete(B, i)
    
    if x + B[i] <= M:
        cost += A[i] * B[i]
        x += B[i]
        i += 1
        #print(A)
        #print(B)
    else:
        cost += A[i] * (M-x)
        x += (M-x)
        i += 1
        #print(A)
        #print(B)


print(cost)
### BUGGY CODE ###

# -*- coding: utf-8 -*-

# AtCoder Beginner Contest
# Problem C

if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))
    count = 0

    for x in set(a):
        elements_count = a.count(x)

        if elements_count >= x:
            count += elements_count - x
        else:
            count += elements_count

    print(count)


### FIXED CODE ###

# -*- coding: utf-8 -*-

# AtCoder Beginner Contest
# Problem C

if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))
    count = 0

    from collections import Counter
    counted_a = Counter(a)

    for x in counted_a:
            if counted_a[x] >= x:
                count += counted_a[x] - x
            else:
                count += counted_a[x]

    print(count)
### BUGGY CODE ###

from itertools import combinations as c
N = int(input())
S = list(list(input()))

count = 0
for i, j, k in c(range(N), 3):
  if j - i != k - j and S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
    count += 1

print(count)


### FIXED CODE ###

import sys
input = sys.stdin.readline

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

ans = S.count("R") * S.count("G") * S.count("B")
for i in range(N-2):
  for j in range(i+1, N-1):
    k = 2 * j - i
    if k < N:
      A, B, C = S[i], S[j], S[k]
      if A != B and B != C and C != A: ans -= 1

print(ans)
### BUGGY CODE ###

s = input()

q = int(input())
r = 0
b = ""
c = ""
for i in range(q):
    A = list(input().split())
    if A[0] == '1':
        r += 1
    else:
        if (A[1] == '1' and r % 2 == 0) or (A[1] != '1' and r % 2 != 0):
            b = A[2] + b
        else:
            c = c + A[2]
# s = b + s + c
if r % 2 == 0:
    print(b+s+c)
else:
    # print(s[::-1])
    print(c[::-1] + s[::-1] + b[::-1])


### FIXED CODE ###

from collections import deque

s = deque(input())

q = int(input())
r = 0
for _ in range(q):
    A = list(input().split())
    if A[0] == '1':
        r = (r + 1)%2
    else:
        if (A[1] == '1' and r % 2 == 0) or (A[1] == '2' and r % 2 == 1):
            s.appendleft(A[2])
        else:
            s.append(A[2])

if r == 1:
    s.reverse()
print("".join(s))
### BUGGY CODE ###

n = int(input())
A = list(map(int,input().split()))
for i in range(n):
  print(A.index(i+1) + 1,end=" ")

### FIXED CODE ###

import numpy as np
n = int(input())
a = list(map(int,input().split()))
line = np.ndarray((n,2),np.int64)
for i in range(n):
  line[i][0] = i + 1
  line[i][1] = a[i]

s = sorted(line,key=lambda x:x[1])
for i in range(n):
  print(s[i][0])