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

import sys
fastinput = sys.stdin.readline
N,D,A = [int(i) for i in fastinput().split()]
preXH = [[int(i) for i in fastinput().split()] for j in range(N)]
preXH.sort()
XH = [[x,h//A + bool(h%A)] for x,h in preXH]
ans = 0
DP = [0]*N#ダメイジの合計
for n,d in enumerate(DP):
    if d<XH[n][1]:#殺しきれてない
        bonu = XH[n][1]-d
        ans += bonu
        reach = XH[n][0] + 2*D
        for m in range(n,N):
            if XH[m][0] <= reach:
                DP[m] += bonu
            else:break
print(ans)

### FIXED CODE ###

import sys
fastinput = sys.stdin.readline
N,D,A = [int(i) for i in fastinput().split()]
preXH = [[int(i) for i in fastinput().split()] for j in range(N)]
preXH.sort()
XH = [[x,h//A + bool(h%A)] for x,h in preXH]
X = [x for x,h in XH]+[100000000000000000]
Diff = [X[m+1]-X[m] for m in range(N)]
reach = []
count = 0
l = X[0]
r = X[0]+2*D
for m in range(1,N+1):
    while r<X[m]:#l一個すすめる
        reach.append(m-1)
        r += Diff[count]
        count += 1

damage = 0
ans = 0
DIFF = [0]*N#ダメイジのdiff
for n,d in enumerate(DIFF):
    damage += d
    if damage<XH[n][1]:#殺しきれてない
        bonu = XH[n][1]-damage
        damage += bonu
        ans += bonu
        if reach[n]<N-1:DIFF[reach[n]+1] -= bonu
print(ans)
### BUGGY CODE ###

import sys
def input():
    return sys.stdin.readline()[:-1]

def main():
    N = int(input())
    A = list(map(int, input().split()))
    
    A_dict = {}
    for a in A:
        if a in A_dict.keys():
            A_dict[a] += 1
        else:
            A_dict[a] = 1

    black_list = []
    ans = 0
    for a in sorted(A_dict.keys()):
        for b in black_list:
            if a % b == 0:
                break
        else:
            if A_dict[a] == 1:
                ans += 1
            black_list.append(a)
    print(ans)
main()

### FIXED CODE ###

def main():
    N = int(input())
    A = list(map(int, input().split()))

    A_dict = {}
    for a in A:
        if a in A_dict.keys():
            A_dict[a] += 1
        else:
            A_dict[a] = 1

    A_list = sorted(A_dict.keys())
    limit = A_list[-1]

    sieve = {i: True for i in A_dict.keys()}

    for a in A_list:
        if not sieve[a]:
            continue
        for i in range(2*a, limit+1, a):
            if i in sieve:
                sieve[i] = False

    print(sum([1 for i in sieve.keys() if sieve[i] and (A_dict[i]==1)]))
main()
### BUGGY CODE ###

import sys
import heapq
input = sys.stdin.readline


def main():
    N, M = map(int, input().split())
    W = []
    for i in range(N):
        a, b = map(int, input().split())
        W.append((-b, a))

    ans = 0
    for i in range(1, M+1):
        ab = list(filter(lambda x: x[1] <= i, W))
        if len(ab) == 0:
            continue
        heapq.heapify(ab)
        ans -= ab[0][0]
        W.remove(ab[0])

    print(ans)
    return


if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys
import heapq


def input(): return sys.stdin.readline().strip()


def main():
    N, M = map(int, input().split())

    w = [[] for _ in range(10 ** 5 + 1)]
    for _ in range(N):
        a, b = map(int, input().split())
        w[a].append(b)

    ans = 0
    hq = []
    for i in range(1, M+1):
        for x in w[i]:
            heapq.heappush(hq, -x)

        if not hq:
            continue

        ans += -heapq.heappop(hq)

    print(ans)


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

n = int(input())
a = []
for _ in range(n):
   x = int(input())
   if x in a:
      a.pop(a.index(x))
   else:
      a.append(x)
print(len(a))


### FIXED CODE ###

n = int(input())
a = [int(input()) for _ in range(n)]
a.sort()

y = a[0]
c = 1
ans = 0
for i in range(1, n):
   if (a[i] == y):
      c += 1
   else:
      if (c % 2 == 1):
         ans += 1
      y = a[i]
      c = 1

if (c % 2 == 1):
   ans += 1

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

#典型dp
n,t=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(n)]
ab.sort(key=lambda x:x[0])
m=ab[-1][0]
dp=[0]*(t+m)

for i in range(n):
    dp_sub=[0]*(t+m)
    for j in range(t):
        if j==0:
            #print(ab[i][1])
            dp_sub[ab[i][0]]=ab[i][1]
        else:
            if dp[j]!=0:
                #print(ab[i][0])
                #print()
                dp_sub[j+ab[i][0]]=dp[j]+ab[i][1]
    for j in range(t+m):
        dp[j]=max(dp[j],dp_sub[j])
print(max(dp))
#print(len(dp))


### FIXED CODE ###

n,t=map(int,input().split())
dish=[list(map(int,input().split())) for i in range(n)]
dish.sort()
dp=[0]*6001
for i in range(n):
    a,b=dish[i]
    for j in range(t-1,-1,-1):
        dp[j+a]=max(dp[j+a],dp[j]+b)
print(max(dp))
### BUGGY CODE ###

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

p = len(format(max(A), 'b'))
digit = '0' + str(p) + 'b'
#S = list(map(format, A, digit))

r = [0] * p
for a in A:
  for j in range(p):
    s = format(a, digit)
    r[j] += int(s[j])

res = 0
for j in range(p):
  res += r[j] * (N - r[j]) * (2 ** (p-1-j))

print(res % (10**9 + 7))

### FIXED CODE ###

import numpy as np 
N = int(input())
A = np.fromstring(input(), dtype = np.int64, sep = ' ')

res = 0
for bit in range(60):
  c = int((A & 1).sum())
  res += c * (N - c) * (1 << bit)
  A >>= 1

print(res % 1000000007)
### BUGGY CODE ###

import numpy as np

MOD = 1000000007;

dp=np.zeros(13*2,dtype='int64')

s = [int(x) if x!="?" else -1 for x in input()]

n=len(s)

r=np.zeros(13,dtype='int64')
c=s[0]

if (c!=-1):
	r[c]=1
else:
	for i in range(10):r[i]=1

for i in range(1,n):
	dp.fill(0)
	for j in range(13):dp[j*10%13]+=(r[j]%MOD)
	dp[13:26]=dp[0:13]
	c=s[i]
	r.fill(0)
	if (c==-1):
		w=np.sum(dp[4:14])
		for j in range(13):
			r[j]+=w
			w+=dp[j+1]
			w-=dp[4+j]
	else:
		r+=dp[13-c:26-c]
print (r[5]%MOD)


### FIXED CODE ###

MOD = 1000000007;

s = [int(x) if x!="?" else -1 for x in input()]

n=len(s)

r=[0]*13

c=s[0]
if (c!=-1):
	r[c]=1
else:
	for i in range(10):r[i]=1

for i in range(1,n):
	dp=[0]*26
	for j in range(13):dp[j*10%13]+=(r[j]%MOD)
	dp[13:26]=dp[0:13]
	c=s[i]
	r=[0]*13
	if (c==-1):
		w=sum(dp[4:14])
		for j in range(13):
				r[j]+=w
				w=w+dp[j+1]-dp[4+j]
	else:
		for j in range(13):
			r[j]+=dp[13-c+j]
print (r[5]%MOD)
### BUGGY CODE ###

from itertools import chain

H, W, D = list(map(int, input().split()))
A = [list(map(int, input().split())) for _ in range(H)]
Q = int(input())
exam = [list(map(int, input().split())) for _ in range(Q)]

flat_a = list(chain.from_iterable(A))

S = [0] * (H*W)
for i in reversed(range(H*W-D)):
    tmp1 = flat_a.index(i+1)
    tmp2 = flat_a.index(i+D+1)
    S[i] = abs(tmp1%W - tmp2%W) + abs(tmp1//W - tmp2//W) + S[i + D]

for L, R in exam:
    print(S[L-1] - S[R-1])



### FIXED CODE ###

from itertools import chain

H, W, D = list(map(int, input().split()))
A = [list(map(int, input().split())) for _ in range(H)]
Q = int(input())
exam = [list(map(int, input().split())) for _ in range(Q)]

x_a = [0] * (H*W)
y_a = [0] * (H*W)

for i, ax in enumerate(A):
    for j, ay in enumerate(ax):
        x_a[ay-1] = i
        y_a[ay-1] = j

S = [0] * (H*W)
for i in reversed(range(H*W-D)):
    S[i] = abs(x_a[i] - x_a[i+D]) + abs(y_a[i] - y_a[i+D]) + S[i + D]

for L, R in exam:
    print(S[L-1] - S[R-1])
### BUGGY CODE ###

#%%
n, a = map(int, input().split())
x = list(map(int, input().split()))
x.insert(0, 0)

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

for i in range(1, n+1):
    for j in range(0, n+1):
        for k in range(0, max(x)*n+1):
            if i == 0:
                pass
            else:
                if j == 0:
                    dp[i][j][k] = dp[i-1][j][k]
                else:
                    if k < x[i]:
                        dp[i][j][k] = dp[i-1][j][k]
                    else:
                        dp[i][j][k] = dp[i-1][j][k] + dp[i-1][j-1][k-x[i]] 
                        #print(x[i])

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


#for i in range(n+1):
#    print(dp[i])

### FIXED CODE ###

#%%
n, a = map(int, input().split())
x = list(map(int, input().split()))
x.insert(0, 0)

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

for i in range(1, n+1):
    for j in range(0, n+1):
        for k in range(0, max(x)*n+1):
            if i == 0:
                pass
            else:
                if j == 0:
                    dp[i][j][k] = dp[i-1][j][k]
                else:
                    if k < x[i]:
                        dp[i][j][k] = dp[i-1][j][k]
                    else:
                        dp[i][j][k] = dp[i-1][j][k] + dp[i-1][j-1][k-x[i]] 
                        #print(x[i])

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


#for i in range(n+1):
#    print(dp[i])
### BUGGY CODE ###

n,x,y=map(int, input().split())
count=[0]*n

def push(a,b,q,distance):
    if distance[a-1]==-1:
        distance[a-1]=b
        q.append(a)

    return (q,distance)

for i in range (1,n+1):
    distance=[-1]*n
    q=[]
    q.append(i)
    distance[i-1]=0
    while len(q) > 0:
        a=q.pop(0)
        if a>=2:
            q,distance=push(a-1,distance[a-1]+1,q,distance)
        if a<=n-1:
            q, distance = push(a + 1, distance[a-1] + 1, q, distance)
        if a==x:
            q, distance = push(y, distance[a-1] + 1, q, distance)
        if a==y:
            q, distance = push(x, distance[a-1] + 1, q, distance)

    for i in range(n):
        count[distance[i]]+=1

for i in range (1,n):
    print(count[i]//2)

### FIXED CODE ###

n,x,y=map(int, input().split())
count=[0]*n

def push(a,b,q,distance):
    if distance[a-1]==-1:
        distance[a-1]=b
        q.append(a)

    return (q,distance)

for i in range (1,n+1):
    distance=[-1]*n
    q=[]
    q.append(i)
    distance[i-1]=0
    while len(q) > 0:
        a=q.pop(0)
        if a>=2:
            q,distance=push(a-1,distance[a-1]+1,q,distance)
        if a<=n-1:
            q, distance = push(a + 1, distance[a-1] + 1, q, distance)
        if a==x:
            q, distance = push(y, distance[a-1] + 1, q, distance)
        if a==y:
            q, distance = push(x, distance[a-1] + 1, q, distance)

    for i in range(n):
        count[distance[i]]+=1

for i in range (1,n):
    print(count[i]//2)
### BUGGY CODE ###

#!/usr/bin/env python3
#ABC98 D

import sys
input = sys.stdin.readline
def d():
    n = int(input())
    a = list(map(int,input().split()))
    ans = 0
    for l in range(n):
        s = 0
        for r in range(l,n):
            if not s & a[r]:
                s += a[r]
                ans += 1
            else:
                break

    print(ans)

if __name__ == '__main__':
    d()


### FIXED CODE ###

#!/usr/bin/env python3
#ABC98 D

import sys
input = sys.stdin.readline
def d():
    n = int(input())
    a = list(map(int,input().split()))
    ans = 0
    l = 0
    r = 0
    s = 0
    while l < n and r < n:
        while s&a[r] == 0:
            s += a[r]
            r += 1
            ans += r-l
            if r == n:
                break
        if l==r:
            s += a[r]
            r += 1
        s -= a[l]
        l += 1
    print(ans)

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

n = int(input())
s=['']*n
sn=[0]*n
l=0

for _ in range(n):
  t = input()
  for i in range(l):
    if t == s[i]:
      sn[i]+=1
      break
      continue
  s[l]=t
  sn[l]+=1
  l+=1
m=max(sn)
ans=[]
for i in range(l):
  if sn[i]==m:
    ans.append(s[i])
ans.sort()
for i in range(len(ans)):
  print(ans[i])

### FIXED CODE ###

n = int(input())
s=[input() for _ in range(n)]
s.sort()

c=1
m=0
for i in range(n-1):
  if s[i]==s[i+1]:
    c+=1
  else:
    if c > m:
      ans=[s[i]]
      m=c
      c=1
    elif c==m:
      ans.append(s[i])
      c=1
    else:
      c=1
if c > m:
  ans=[s[n-1]]
elif c==m:
   ans.append(s[n-1])
for i in range(len(ans)):
  print(ans[i])
### BUGGY CODE ###

n=int(input())
# s=input()
# a,b=map(int,input().split())
# h=list(map(int,input().split()))
l=sorted(list(map(int,input().split())))

# mod=10**9+7
# n=20
# fact=[1]
# for i in range(n):
#     fact+=fact[-1]*(i+1)%mod,
# print(fact)
# print(l)
# ほんと？
from bisect import bisect_left,bisect_right
ans=0
for i in range(n):
    for j in range(i+1,n):
        a=l[i]
        b=l[j]
        ll=l[j+1:]
        # print(ll)
        # abs(a-b)<c<a+bをみたすcは何個？
        ans+=bisect_left(ll,a+b) # -bisect_right(ll,b-a)
print(ans)

### FIXED CODE ###

import bisect
 
n=int(input())
l=sorted(list(map(int,input().split())))
ans=0
 
for i in range(n):
  for j in range(i+1,n):
    temp=l[i]+l[j]
    ans+=(bisect.bisect_left(l,temp)-j-1)
print(ans)
### BUGGY CODE ###

from collections import defaultdict
import heapq


class Dijkstra:
    """
    dijkstraの最短経路問題を解く
    input:
        S: start node
        mat : mat[a][b] = edge_weight(a,b)
    """

    def __init__(self, start, num_node, mat):
        """
        mat: mat[a][b] = edge_weight(a,b)
        num_node: num of nodes
        dist: dist from start_node
        prev: 最短経路において、一つ前のノードを記憶。経路復元に使う?
        """
        self.start_node = start
        self.mat = mat
        self.num_node = num_node
        self.dist = [float('inf')]*num_node
        self.prev = defaultdict(lambda: None)

        # dist form S to S = 0
        self.dist[start] = 0

    def calc_dist(self):
        """
        最短経路 distを計算する
        Q: content (dist_from_start,node)
        Qはheapqとして使う。dist_from_startの小さい順になる
        """
        Q = []
        heapq.heappush(Q, (0, self.start_node))
        while Q:
            dist_to_node, node = heapq.heappop(Q)
            # 現在の値よりも大きくて、更新にならない場合
            if self.dist[node] < dist_to_node:
                continue

            # 次のホップを計算する
            for nex in range(self.num_node):
                weight = self.mat[node][nex]
                cand = dist_to_node + weight

                if self.dist[nex] > cand:  # update
                    self.dist[nex] = cand
                    self.prev[nex] = node
                    heapq.heappush(Q, (cand, nex))

    def get_dist(self, d):
        """
            startからdまでの距離を返す
            これの前にcalc()を実行しておく
            たどり着けない場合は、float('inf')がかえる
        """
        return self.dist[d]
    def get_path(self,dst):
        """
        startからdstまでのpathをlistでreturn
        valifyしてないので怪しい
        """
        cur=dst
        ret=[cur]
        while cur!=self.start_node:
            cur=self.prev[cur]
            ret.append(cur)
        return list(reversed(ret))

N,M = map(int,input().split())
edges=[list(map(lambda x:int(x)-1,input().split())) for _ in range(M)]

grid=[[float("inf")]*N for _ in range(N)]

for a,b in edges:
    grid[a][b]=1
    grid[b][a]=1

D = Dijkstra(0,N,grid)
D.calc_dist()

ans=[]
for i in range(1,N):
    ans.append(D.prev[i]+1)
print("Yes")
print("\n".join(map(str,ans)))


### FIXED CODE ###

N,M = map(int,input().split())
edges=[list(map(lambda x:int(x)-1,input().split())) for _ in range(M)]

adj=[set() for _ in range(N)]

for a,b in edges:
    adj[a].add(b)
    adj[b].add(a)

start=0
dst=[-1]*N
visited={0}

Q={start}

while Q:
    tmp=set()
    for cur in Q:
        for nex in adj[cur]:
            if nex in visited:
                continue
            dst[nex]=cur
            visited.add(nex)
            tmp.add(nex)
    Q=tmp

print("Yes")
print("\n".join(map(str,[v+1 for v in dst[1:]])))
### BUGGY CODE ###

#!/usr/bin/env python3

N = int(input().split()[0])
a_list = list(map(int, input().split()))


mod = 10 ** 9 + 7
total = 0
for i, a in enumerate(a_list):
    for j in range(len(a_list) - (i + 1)):
        total += (a * a_list[i + 1 + j]) % mod
total = total % mod
ans = total
print(ans)


### FIXED CODE ###

#!/usr/bin/env python3

N = int(input().split()[0])
a_list = list(map(int, input().split()))

mod = 10 ** 9 + 7
sum_a = sum(a_list)
total = 0
for i, a in enumerate(a_list):
    total += (a * (sum_a - a)) % mod
    sum_a -= a
total = total % mod
ans = total
print(ans)
### BUGGY CODE ###

N=int(input())
S=input()
L=[1 if s=='W' else 0 for s in S]
ans=set()

for i in range(N):
    W,E=sum(L[:i+1]),N-i-1-sum(L[i:])
    ans.add(W+E)

print(min(ans))

### FIXED CODE ###

N=int(input())
S=input()
A=[0]*N
A[0]=S[1:].count('E')
for i in range(1,N):
    if S[i-1]=='W':
        A[i]=A[i-1]+1
    else:
        A[i]=A[i-1]
    if S[i]=='E':
        A[i]-=1
print(min(A))
### BUGGY CODE ###

import re

N = int(input())

ans = 0
for i in range(1, N+1):
    n = i
    flags = 0
    while True:
        flags |= 1 << (n % 10)
        n //= 10
        if n == 0:
            break
    if flags == 0xA8:
        ans += 1

print(ans)


### FIXED CODE ###

def keta(n, elements):
    results = elements
    for i in range(n - 1):
        results = [r * 10 + e for e in elements for r in results]
    return results

N = int(input())

num753 = set()
for i in range(3,10):
    n1 = keta(i, set([3, 5, 7]))
    n2 = keta(i, set([3, 5]))
    n3 = keta(i, set([5, 7]))
    n4 = keta(i, set([3, 7]))
    num753 |= set(n1) - set(n2) - set(n3) - set(n4)
num753 = sorted(num753)

ans = 0
for i in num753:
    if i <= N:
        ans += 1
print(ans)
### BUGGY CODE ###

import numpy as np

def receive_shopping_plan():
    num_commodity, num_coupon = input().split(' ')
    num_commodity, num_coupon = int(num_commodity), int(num_coupon)
    return num_commodity, num_coupon

def calc_minimized_sum(num_commodity, num_coupon):
    prices = np.array(input().split(' '), dtype=np.uint32)
    for _ in range(num_coupon):
        prices[prices.argmax()] //= 2
    print(prices.sum())

if __name__ == '__main__':
    num_commodity, num_coupon = receive_shopping_plan()
    calc_minimized_sum(num_commodity, num_coupon)


### FIXED CODE ###

import heapq

def receive_shopping_plan():
    num_commodity, num_coupon = input().split(' ')
    num_commodity, num_coupon = int(num_commodity), int(num_coupon)
    return num_commodity, num_coupon

def calc_minimized_sum(num_commodity, num_coupon):
    prices = list(map(lambda x: int(x) * -1 , input().split(' ')))
    heapq.heapify(prices)
    for _ in range(num_coupon):
        max_price = heapq.heappop(prices) // (2*-1)
        heapq.heappush(prices, max_price*-1)

    print(sum(prices)*-1)

if __name__ == '__main__':
    num_commodity, num_coupon = receive_shopping_plan()
    calc_minimized_sum(num_commodity, num_coupon)
### BUGGY CODE ###

N = int(input())

S = []
for i in range(N):
    S.append(input())
    
V = []
for i in S:
    V.append(S.count(i))

W = []
for i in range(N):
    if V[i] == max(V):
        W.append(S[i])

W = list(dict.fromkeys(W))
W.sort()

for i in W:
    print(i)

### FIXED CODE ###

import collections as clcts

N = int(input())

V = []
for i in range(N):
    V.append(input())

P = clcts.Counter(V)

W = max(P.values())
A = [i for i, j in P.items() if j == W]
A.sort()

for i in A:
    print(i)
### BUGGY CODE ###

N = int(input())
S = input()
R = 0
G = 0
B = 0
notToAllow = 0


for i in range(0,N):
    if S[i] == "R":
        R = R + 1
    elif S[i] == "G":
        G = G + 1
    else:
        B = B + 1

total = R*G*B

for i in range(0,N):
    for j in range(0,(N//2)+1):
        if(j+j+i < N) and (j+j < N) and (i+j < N):
            if ((S[i] != S[i+j]) and (S[i] != S[i+j+j]) and (S[i+j] != S[i+j+j])):
                notToAllow = notToAllow + 1

print(R*G*B - notToAllow)


### FIXED CODE ###

N = int(input())
S = input()
R = 0
G = 0
B = 0
notToAllow = 0


for i in range(0,N):
    if S[i] == "R":
        R = R + 1
    elif S[i] == "G":
        G = G + 1
    else:
        B = B + 1

total = R*G*B

for i in range(0,N):
    for j in range(0,(N//2)+1):
        if(j+j+i < N):
            if ((S[i] != S[i+j])):
                if(S[i] != S[i+j+j]):
                    if(S[i+j] != S[i+j+j]):
                        notToAllow = notToAllow + 1

print(R*G*B - notToAllow)
### BUGGY CODE ###

Q = int(input())

n = 10 ** 5
is_prime = [True for i in range(n)]

is_prime[0], is_prime[1] = False, False
for i in range(2, n):
    if is_prime[i]:
        j = 2 * i
        while j < n:
            is_prime[j] = False
            j += i

for i in range(Q):
    l, r = map(int, input().split())
    rec = 0
    for j in range(l, r + 1):
        if is_prime[j] and is_prime[(j + 1) // 2]:
            rec += 1
    print(rec)


### FIXED CODE ###

Q = int(input())

n = 10 ** 5
is_prime = [True for i in range(n)]
is_prime[0], is_prime[1] = False, False
for i in range(2, n):
    if is_prime[i]:
        j = 2 * i
        while j < n:
            is_prime[j] = False
            j += i

like_num = [0 for i in range(n)]
rec = 0
for i in range(1, n, 2):
    if is_prime[i] and is_prime[(i + 1) // 2]:
        rec += 1
    like_num[i] = rec

for i in range(Q):
    l, r = map(int, input().split())
    if l == 1:
        print(like_num[r])
    else:
        print(like_num[r] - like_num[l - 2])
### BUGGY CODE ###

s = input()
cnt = 0
tmp = ''
hit = True
while(hit):
	hit = False
	for i in range(1, len(s)):
		if s[i-1:i+1] == '01' or s[i-1:i+1] == '10':
			tmp = s[0:i-1] + s[i+1: ]
			cnt += 2
			hit = True
			s = tmp
			break
            
print (cnt)

### FIXED CODE ###

s = input()
cnt = 0
idx = 1
tmp = ''
hit = True
while(hit):
	hit = False
	for i in range(idx, len(s)):
		if s[i-1:i+1] == '01' or s[i-1:i+1] == '10':
			tmp = s[0:i-1] + s[i+1: ]
			cnt += 2
			idx = i - 1 if i > 1 else 1
			hit = True
			s = tmp
			break
            
print (cnt)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
N = int(input())
A = [int(input()) for i in range(N)]
temp = 0

for i in range(N):
	if A[i] != max(A):
		print(max(A))
	else:
		temp = A[i]
		del A[i]
		print(max(A))
		A.insert(i,temp)
		temp = 0

### FIXED CODE ###

# -*- coding: utf-8 -*-
N = int(input())
A = [int(input()) for i in range(N)]
Am = max(A)
Asm = sorted(A)[-2]

for i in range(N):
	if A[i] != Am:
		print(Am)
	else:
		print(Asm)
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
b = []
for i in range(n):
    if i % 2 == 0:
        b.append(a[i])
    else:
        b.insert(0, a[i])

if n % 2 != 0:
    b.reverse()
for i in b:
    print(i, end=" ")


### FIXED CODE ###

from collections import deque

n = int(input())
a = list(map(int, input().split()))
b = deque()
for i in range(n):
    if i % 2 == 0:
        b.append(a[i])
    else:
        b.appendleft(a[i])

if n % 2 != 0:
    for i in reversed(b):
        print(i, end=" ")
else:
    for i in b:
        print(i, end=" ")
### BUGGY CODE ###

n,y = map(int,input().split())
from itertools import combinations_with_replacement

ls = list(combinations_with_replacement([1000,5000,10000],n))

flg =0
for i in ls:
    if sum(i)==y:
        print(i.count(10000),i.count(5000),i.count(1000))
        flg =1
        break

    else:
        pass

if flg ==1:
    pass
else:
    print("-1 -1 -1")

### FIXED CODE ###

n,y = map(int,input().split())
flg=0

for i in range(n+1):
    for j in range(n-i+1):
        ans = 10000*i + 5000*j + 1000*(n-i-j)
        if  ans == y:
            print(i,j,n-i-j)
            flg = 1
            break
    else:
        continue
    break


if flg == 0:
    print("-1 -1 -1")
else:
    pass
### BUGGY CODE ###

K = int(input())
c = 1
i = 1
while c != K:
  i += 1
  S = str(i)
  l = len(S) - 1
  for j in range(l):
    if abs(int(S[j]) - int(S[j+1])) > 1:
      break
  else:
    c += 1    
print(i)

### FIXED CODE ###

K = int(input())
A = [1, 2, 3, 4, 5, 6, 7, 8, 9]
for i in range(K):
  x = A[i]
  if x % 10 != 0:
    A.append(10 * x + (x % 10) - 1)
  A.append(10 * x + (x % 10))
  if x % 10 != 9:
    A.append(10 * x + (x % 10) + 1)
else:
  print(A[i])
### BUGGY CODE ###

def myAnswer(N:int,P:list) -> int:
   total = 0
   for i in range(N):
      if(min(P[:i+1])>= P[i]):
         total+=1
   return total

def modelAnswer():
   tmp=1
def main():
   N = int(input())
   P = list(map(int,input().split()))
   print(myAnswer(N,P[:]))

if __name__ == '__main__':
   main()

### FIXED CODE ###

import sys
input = sys.stdin.readline

N=int(input())
P = list(map(int,input().split()))


cnt=1
M=P[0]#現在の最小値
for i in range(1,N):
    if(M > P[i]):#Pの値が現在の最小値より小さかったら最小値を更新しcnt++する
        M=P[i]
        cnt+=1



print(cnt)