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

from collections import deque
sx,sy,tx,ty = map(int,input().split())
ans_list = []
(tx,ty) = (tx-sx,ty-sy); (sx,sy) = (0,0)
H,W = ty+3,tx+3
visited = [[0]*(tx+3) for i in range(ty+3)]
d = [[1,0],[0,1],[-1,0],[0,-1]]
(sx,sy) = (sx+1,sy+1); (tx,ty) = (tx+1,ty+1)
def bfs(si,sj,gi,gj):
    tr = [[si,sj]]
    q = deque([[si,sj,tr]])
    while q:
        i,j,tr = q.popleft()
        if (i,j) == (gi,gj):
            return tr
        for di,dj in d:
            ni = i + di; nj = j + dj
            if 0 <= ni <= H-1 and 0 <= nj <= W-1 and visited[ni][nj] == 0:
                visited[ni][nj] = 1
                ntr = tr[:]; ntr.append([ni,nj])
                q.append([ni,nj,ntr])

def change(tr):
    def func(d):
        if d == (1,0):return "U"
        if d == (-1,0):return "D"
        if d == (0,-1):return "L"
        if d == (0,1):return "R"
    for i in range(len(tr)-1):
        (ni,nj) = (tr[i+1][0],tr[i+1][1])
        (i,j) = (tr[i][0],tr[i][1])
        d = (ni-i,nj-j)
        ans_list.append(func(d))

tr = []
for cnt in range(2):
    res = bfs(sy,sx,ty,tx)
    for k in range(1,len(res)):
        i,j = res[k][0],res[k][1]
        rei, rej = ty + sx - i, tx + sy - j
        res.append([rei,rej])
    if cnt == 0:
        tr += res
    else:
        tr += res[1:]
    visited = [[0]*W for i in range(H)]
    for i,j in tr:
        visited[i][j] = 1
    visited[ty][tx] = 0

change(tr)
ans = "".join(ans_list)
print(ans)

### FIXED CODE ###

sx,sy,tx,ty = map(int,input().split())
(tx,ty) = (tx-sx,ty-sy)
route1 = "U"*ty + "R"*tx
route2 = "D"*ty + "L"*tx
route3 = "L" + "U"*(ty+1) + "R"*(tx+1) + "D"
route4 = "R" + "D"*(ty+1) + "L"*(tx+1) + "U"
ans = route1 + route2 + route3 + route4
print(ans)
### BUGGY CODE ###

from sys import stdin

def main():
    s = [int(x) if x != "?" else "?" for x in stdin.readline().rstrip()]

    dp = [1] + [0]*12
    mul = 1
    mod = 10 ** 9 + 7
    s.reverse()

    for i in (range(0,len(s))):
        next_dp = [0]*13
        if s[i] == "?":
            for k in range(0, 10):
                for j in range(0, 13):
                    next_dp[(k*mul+j)%13] += dp[j]
                    next_dp[(k*mul+j)%13] %= mod

        else:
            k = s[i]
            for j in range(0, 13):
                    next_dp[(k*mul+j)%13] += dp[j]
                    next_dp[(k*mul+j)%13] %= mod

        mul = mul * 10 % 13
        dp = next_dp

    print(dp[5])

if __name__ == '__main__':
    main()


### FIXED CODE ###

from sys import stdin

def main():
    s = [int(x) if x != "?" else "?" for x in stdin.readline().rstrip()]

    dp = [1] + [0]*12
    mod = 10 ** 9 + 7

    for i in (range(0,len(s))):
        next_dp = [0]*13
        if s[i] == "?":
            for k in range(0, 10):
                for j in range(0, 13):
                    next_dp[(j*10+k)%13] += dp[j]
                    next_dp[(j*10+k)%13] %= mod

        else:
            k = s[i]
            for j in range(0, 13):
                    next_dp[(j*10+k)%13] += dp[j]
                    next_dp[(j*10+k)%13] %= mod

    #    mul = mul * 10 % 13
        dp = next_dp

    print(dp[5])

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

# 無理やり0.1度ずつ行先を回す。

import math
import numpy as np

n = int(input())

eng_list = []

for _ in range(n):
    a = np.array(list(map(int, input().split())))
    eng_list.append(a)

# 角度
angles = []

for i in range(n):
    cos = (np.dot(eng_list[i], np.array([0, 1]))/(np.linalg.norm(eng_list[i])))
    angle = math.degrees(math.acos(cos))
    if eng_list[i][0] < 0:
        angle = 360 - angle
    angles.append(angle)


def hantei(a, b):
    coss = np.dot(a, b)/(np.linalg.norm(a)*np.linalg.norm(b))
    if coss > 1:
        coss = 1.0
    elif coss < -1:
        coss = -1.0
    angg = math.degrees(math.acos(coss))
    if angg < 90.0001:
        return True
    else:
        return False


def distance(a):
    dis = np.linalg.norm(a)
    return dis

pitch = 0.1 # 角度
dist = []

for ikisaki in np.arange(0, 360, pitch):
    dist_location = np.array([0, 0])
    for j in eng_list:
        i = np.array([math.cos(math.radians(ikisaki)), math.sin(math.radians(ikisaki))])
        if hantei(i, j):
            dist_location = dist_location + j
    dist.append(distance(dist_location))

print(max(dist))

### FIXED CODE ###

# 無理やり0.1度ずつ行先を回す。

import math
import numpy as np

n = int(input())

eng_list = []

for _ in range(n):
    a = np.array(list(map(int, input().split())))
    eng_list.append(a)

# 角度
angles = []

for i in range(n):
    cos = (np.dot(eng_list[i], np.array([0, 1]))/(np.linalg.norm(eng_list[i])))
    angle = math.degrees(math.acos(cos))
    if eng_list[i][0] < 0:
        angle = 360 - angle
    angles.append(angle)


def hantei(a, b):
    coss = np.dot(a, b)/(np.linalg.norm(a)*np.linalg.norm(b))
    if coss > 1:
        coss = 1.0
    elif coss < -1:
        coss = -1.0
    angg = math.degrees(math.acos(coss))
    if angg < 90.0001:
        return True
    else:
        return False


def distance(a):
    dis = np.linalg.norm(a)
    return dis

pitch = 1 # 角度
dist = []

for ikisaki in np.arange(0, 360, pitch):
    dist_location = np.array([0, 0])
    for j in eng_list:
        i = np.array([math.cos(math.radians(ikisaki)), math.sin(math.radians(ikisaki))])
        if hantei(i, j):
            dist_location = dist_location + j
    dist.append(distance(dist_location))

print(max(dist))
### BUGGY CODE ###

import numpy as np
N, S = map(int, input().split())
A = list(map(int, input().split()))
MOD = 998244353

DP = np.zeros((N+1, S+1), dtype=np.int64)#[[0]*(S+1) for _ in range(N+1)]
DP[0][0] = 1
for i in range(N):
  for j in range(S + 1):
    if j >= A[i]:
      DP[i + 1][j] = (DP[i][j] * 2 + DP[i][j - A[i]]) % MOD
    else:
      DP[i + 1][j] = (DP[i][j] * 2) % MOD
print(DP[-1][-1] % MOD)






### FIXED CODE ###

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

DP = [[0] * (S + 1) for i in range(N + 1)]
DP[0][0] = 1
for i in range(N):
  for j in range(S + 1):
    if j >= A[i]:
      DP[i + 1][j] = (DP[i][j] * 2 + DP[i][j - A[i]]) % MOD
    else:
      DP[i + 1][j] = (DP[i][j] * 2) % MOD

print(DP[-1][-1] % MOD)
### BUGGY CODE ###

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

n = int(input())
s = input()


rgb_list = ['R', 'G', 'B']
counter = 0

for p in range(n):
    for q in range(n - p):
        a = s[p]
        b = s[p + q]
        if a == b:
            continue
        current_list = [a, b]
        diff_list = list(set(rgb_list) - set(current_list))
        c = diff_list[0]
        nokori = s[p + q:]
        counter += nokori.count(c)
        if q < len(nokori) and nokori[q] == c:
            counter -= 1

print(counter)

### FIXED CODE ###

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

n = int(input())
s = input()

r_cnt = s.count('R')
g_cnt = s.count('G')
b_cnt = s.count('B')

counter = r_cnt * g_cnt * b_cnt

for i in range(n):
    for p in range(n):
        j = i + p
        k = j + p
        if k >= n:
            break
        if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
            counter -= 1
print(counter)
### BUGGY CODE ###

N = int(input())
a = []
maximum = 0
minimum = 10 ** 5
for i in input().split():
    a.append(int(i))
    maximum = max(maximum, int(i))
    minimum = min(minimum, int(i))
max_count = 0
for X in range(minimum, maximum+1):
    count = 0
    for num in a:
        if X-1 <= num <= X+1:
            count += 1
    max_count = max(max_count, count)
print(max_count)

### FIXED CODE ###

def dic_counter(dic, num):
    if num in dic:
        dic[num] += 1
    else:
        dic[num] = 1

N = int(input())
dic = {}
for i in input().split():
    dic_counter(dic, int(i)-1)
    dic_counter(dic, int(i))
    dic_counter(dic, int(i)+1)
for _, value in sorted(dic.items(), key=lambda x: -x[1]):
    print(value)
    break
### BUGGY CODE ###

def f(n):
  cnt = 0
  for i in range(n):
    for j in range(n):
      for k in range(n):
        if (i+1)**2 + (j+1)**2 + (k+1)**2 + (i+1)*(j+1) + (j+1)*(k+1) + (k+1)*(i+1) == n:
          cnt += 1
  return cnt
    
N = int(input())
for i in range(N):
  print(f(i+1))

### FIXED CODE ###

n = int(input())
a = [0]*n
cnt = 0
for i in range(1,100):
  for j in range(1,100):
    for k in range(1,100):
      b = i**2 + j**2 + k**2 + i*j + j*k + k*i
      if b <= n:
        a[b-1] += 1

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

n,k=map(int,input().split())
p=list(map(int,input().split()))
box=[0]*(n-k+1)
for i in range(0,n-k+1):
    aa=0
    if i==0:
        for j in range(0,k):
          aa+=p[j]+1
    if i>0 and p[i-1]<p[i+k-1]:
        for j in range(0,k):
          aa+=p[i+j]+1
    box[i]=aa
print(max(box)/2)

### FIXED CODE ###

n,k=map(int,input().split())
p=list(map(int,input().split()))

s=0
for i in range(k):
    s += (p[i]+1)/2

ans=s

for i in range(n-k):

    s += (p[i+k]-p[i])/2

    if s>ans:
        ans=s
print(ans)
### BUGGY CODE ###

import sys

H,W=map(int,next(sys.stdin).split())

xs=[[0]*(W+2) for _ in range(H+2)]
ys=[[0]*(W+2) for _ in range(H+2)]
for i in range(1,H+1):
    row=next(sys.stdin)
    for j in range(1,W+1):
        if row[j-1]!='.':continue
        xs[i][j]=1+xs[i][j-1]
        ys[i][j]=1+ys[i-1][j]

ans=0
for i in range(H,0,-1):
    for j in range(W,0,-1):
        if xs[i][j]==0:continue
        x=xs[i][j]=max(xs[i][j],xs[i][j+1])
        y=ys[i][j]=max(ys[i][j],ys[i+1][j])
        ans=max(ans,x+y-1)

print(ans)


### FIXED CODE ###

import sys

H,W=map(int,next(sys.stdin).split())

xs=[[0]*(W+2) for _ in range(H+2)]
ys=[[0]*(W+2) for _ in range(H+2)]
for i in range(1,H+1):
    row=next(sys.stdin)
    for j in range(1,W+1):
        if row[j-1]!='.': continue
        xs[i][j]=1+xs[i][j-1]
        ys[i][j]=1+ys[i-1][j]

ans=0
for i in range(H,0,-1):
    for j in range(W,0,-1):
        if xs[i][j]==0: continue
        x=xs[i][j]=max(xs[i][j],xs[i][j+1])
        y=ys[i][j]=max(ys[i][j],ys[i+1][j])
        ans=max(ans,x+y-1)

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

import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    s=input()
    new_s=""
    for ss in s:
        if ss!='x':
            new_s+=ss
    if new_s[::-1]!=new_s:
        print(-1)
        sys.exit()
    right=len(s)-1
    left=0
    ans=0
    while right-left>0:
        if s[right]!=s[left]:
            if s[right]=='x':
                ans+=1
                right-=1
            elif s[left]=='x':
                ans+=1
                left+=1
        else:
            right-=1
            left+=1
    print(ans)



if __name__=='__main__':
    main()

### FIXED CODE ###

import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    s=input()
    new_s=""
    for ss in s:
        if ss!='x':
            new_s+=ss
    if new_s[::-1]!=new_s:
        print(-1)
        sys.exit()
    right=len(s)-1
    left=0
    ans=0
    while right-left>0:
        if s[right]!=s[left]:
            if s[right]=='x':
                ans+=1
                right-=1
            elif s[left]=='x':
                ans+=1
                left+=1
        else:
            right-=1
            left+=1
    print(ans)



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

import fractions
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
N = int(input())
A = [int(x) for x in input().split()]
a = 1
MOD = 10**9+7
for i in A:
  a = lcm(a,i)
ans = 0
for i in A:
  ans += (a//i)%MOD
print(ans%MOD)

### FIXED CODE ###

import fractions
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
N = int(input())
A = [int(x) for x in input().split()]
a = 1
MOD = 10**9+7
for i in A:
  a = lcm(a,i)
ans = 0
for i in A:
  ans += (a//i)
print(ans%MOD)
### BUGGY CODE ###

while 1:
    math,greed,geo,dp,graph,other = map(int,raw_input().split())
    md,gg,go = math+dp,greed+graph,geo+other
    if md == gg == go == 0: break
    count = 0
    while md > 2 and gg > 2 and go > 2:
        md -= 1; gg -= 1; go -= 1
        count += 1
    print count + md/3 + gg/3 + go/3 + min(md%3,gg%3,go%3)

### FIXED CODE ###

while 1:
	N = map(int,raw_input().split())
	if sum(N) == 0: break
	a,b,c = N[0]+N[3],N[1]+N[4],N[2]+N[5]
	m = min(a,b,c)
	ans = 0
	for i in range(max(0,m-2),m+1):
		ans = max(ans,i+(a-i)/3+(b-i)/3+(c-i)/3)
	print ans
### BUGGY CODE ###

import numpy as np

N = int(input())
lisL = list(map(int,input().split()))
arrL = np.array(sorted(lisL))

ans = 0
for i in range(N):
    for j in range(i+1,N):
        a = arrL[i]
        b = arrL[j]
        ans += np.bincount((arrL[j+1:]< a+b),minlength=2)[1]

print(ans)

### FIXED CODE ###

import bisect

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

lisL.sort()
ans = 0
for i in range(N):
    for j in range(i+1,N):
        ab = lisL[i] + lisL[j]
        ans += bisect.bisect_left(lisL[j+1:],ab)

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

n = int(input())
a = list(map(int, input().split()))
b = []
for i in range(n):
  b.append(a[i])
  b = b[::-1]
s = ' '.join([str(e) for e in b])
print(s)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
b = [a[i] for i in range(n) if i % 2 == 0]
c = [a[i] for i in range(n) if i % 2 == 1]
if n % 2 == 0:
  d = c[::-1] + b
elif n % 2 == 1:
  d = b[::-1] + c
s = ' '.join([str(e) for e in d])
print(s)
### BUGGY CODE ###

#!/usr/bin/env python3


def main() -> None:
    N, K = rmi()
    A = rmi()
    route = []
    current = 1
    for n in range(N):
        if not current in route:
            route.append(current)
            current = A[current - 1]
        else:
            route.append(current)
            break
    dup = route[-1]
    dup_index = route.index(dup)
    roop_range = len(route) - dup_index - 1
    if K < dup_index:
        w(route[K])
    else:
        w(route[dup_index:][(K - dup_index) % roop_range])


def r() -> str:
    return input().strip()


def ri() -> int:
    return int(r())


def rmi(delim: str = ' ') -> tuple:
    return tuple(map(int, input().split(delim)))


def w(data) -> None:
    print(data)


def wm(*data, delim: str = ' ') -> None:
    print(delim.join(map(str, data)))


if __name__ == '__main__':
    import sys
    sys.setrecursionlimit(10 ** 9)
    main()


### FIXED CODE ###

#!/usr/bin/env python3


def main() -> None:
    N, K = rmi()
    A = rmi()
    route = []
    visited = [False] * N
    current = 1
    for n in range(N):
        route.append(current)
        if not visited[current - 1]:
            visited[current - 1] = True
            current = A[current - 1]
        else:
            break
    dup = route[-1]
    dup_index = route.index(dup)
    roop_range = len(route) - dup_index - 1
    if K < dup_index:
        w(route[K])
    else:
        w(route[dup_index:][(K - dup_index) % roop_range])


def r() -> str:
    return input().strip()


def ri() -> int:
    return int(r())


def rmi(delim: str = ' ') -> tuple:
    return tuple(map(int, input().split(delim)))


def w(data) -> None:
    print(data)


def wm(*data, delim: str = ' ') -> None:
    print(delim.join(map(str, data)))


if __name__ == '__main__':
    import sys
    sys.setrecursionlimit(10 ** 9)
    main()
### BUGGY CODE ###

N = int(input())
S = [input() for _ in range(N)]
 
T = sorted(set(S))
t = len(T)
l = [S.count(T[i]) for i in range(t)]
  
for i in range(t):
  if l[i] == max(l):
    print(T[i])

### FIXED CODE ###

from collections import Counter

N = int(input())
S = [input() for _ in range(N)]

S = Counter(S).most_common()
l = []
for i in S:
  if i[1] == S[0][1]: l.append(i[0])

l = sorted(l)
for i in l:
  print(i)
### BUGGY CODE ###

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

dp = [[0]*(M+1) for _ in range(N+1)]
accum = [[0]*(M+1) for _ in range(N+1)]
MOD = 10**9+7

for i in range(1, N+1):
    for j in range(1, M+1):
        dp[i][j] = 0 if S[i-1]!=T[j-1] else 1 + accum[i-1][j-1]
        accum[i][j] = accum[i-1][j]+accum[i][j-1]-accum[i-1][j-1]+dp[i][j]   

ans = (sum(map(sum, dp))+1)%MOD
print(ans)


### FIXED CODE ###

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

dp = [[0]*(M+1) for _ in range(N+1)]
accum = [[0]*(M+1) for _ in range(N+1)]
MOD = 10**9+7

for i in range(1, N+1):
    for j in range(1, M+1):
        dp[i][j] = 0 if S[i-1]!=T[j-1] else (1 + accum[i-1][j-1])%MOD
        accum[i][j] = (accum[i-1][j]+accum[i][j-1]-accum[i-1][j-1]+dp[i][j])%MOD     

ans = (sum(map(sum, dp))+1)%MOD
print(ans)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
LOCAL = len(sys.argv) > 1 and sys.argv[1] == 'LOCAL'


def dprint(*args):
  if LOCAL:
    print(*args)


n = int(input())
s = input()

rs, gs, bs = [], [], []
for l, c in enumerate(s):
  if c == 'R':
    rs.append(l)
  if c == 'G':
    gs.append(l)
  if c == 'B':
    bs.append(l)
sbs = set(bs)

ans = 0
for r in rs:
  for g in gs:
    m = min(r, g)
    M = max(r, g)
    notbs = [m - (M - m), M + (M - m)]
    if (M + m) % 2 == 0:
      notbs.append((M + m) // 2)
    dprint(m, M, notbs, bs)
    a = len(sbs - set(notbs))
    if a > 0:
      ans += a


print(ans)


### FIXED CODE ###

import sys
input = sys.stdin.readline
LOCAL = len(sys.argv) > 1 and sys.argv[1] == 'LOCAL'


def dprint(*args):
  if LOCAL:
    print(*args)


n = int(input())
s = input()

rs, gs, bs = [], [], []
for l, c in enumerate(s):
  if c == 'R':
    rs.append(l)
  if c == 'G':
    gs.append(l)
  if c == 'B':
    bs.append(l)
sbs = set(bs)

ans = 0
for r in rs:
  for g in gs:
    m = min(r, g)
    M = max(r, g)
    notbs = [m - (M - m), M + (M - m)]
    if (M + m) % 2 == 0:
      notbs.append((M + m) // 2)
    
    dprint(m, M, notbs, sbs)
    
    # a = len(sbs - set(notbs))

    a = len(sbs)
    for notb in notbs:
      if notb in sbs:
        a -= 1
    if a > 0:
      ans += a


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

n,k=map(int,input().split())
h=[int(input()) for i in range(n)]
h=sorted(h)
s=[]
for i in range(n-1):
    s.append(h[i+1]-h[i])
t=[]
for i in range(n-k+1):
    t.append(sum(s[i:i+k-1]))

print(min(t))

### FIXED CODE ###

n,k=map(int,input().split())
h=sorted(int(input()) for i in range(n))
ans=10**10
for i in range(n-k+1):
    ans=min(h[i+k-1]-h[i],ans)
print(ans)
### BUGGY CODE ###

n=int(input())
ans=0
for i in range(1,n):
    ans+=i
print(ans)
          

### FIXED CODE ###

n=int(input())
ans=n*(n-1)//2

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

n, m = map(int, input().split())
pros = sorted([list(map(int, input().split())) for _ in range(m)])
index = 0
covered = 0
right = 0
ans = 0
while True:
  a, b = pros[index]
  if a > covered + 1:
    covered = right
    ans += 1
    continue
  else:
    right = max(right, b)
    index += 1

  if covered == n:
    print(ans)
    break

  if index == m:
    covered = right
    ans += 1
    print(ans if covered == n else "Impossible")
    break



### FIXED CODE ###

n, m = map(int, input().split())
pros = sorted([list(map(int, input().split())) for _ in range(m)])
index = 0
covered = 0
right = 0
ans = 0
while True:
  a, b = pros[index]
  if a > covered + 1:
    if covered == right:
      print("Impossible")
      break
    covered = right
    ans += 1
    continue
  else:
    right = max(right, b)
    index += 1

  if covered == n:
    print(ans)
    break

  if index == m:
    covered = right
    ans += 1
    print(ans if covered == n else "Impossible")
    break
### BUGGY CODE ###

from collections import deque

n, m = map(int, input().split())
L = [[0] for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    L[a-1].append(b-1)
    L[b-1].append(a-1)
L[0][0] = 1
d = [0] * n
ans = [0] * n
dq = deque([0])
while len(dq) > 0:
    t = dq.popleft()
    for i in range(1, len(L[t])):
        if d[L[t][i]] == 0:
            d[L[t][i]] = d[t] + 1
            ans[L[t][i]] = t + 1
        else:
            if d[L[t][i]] > d[t] + 1:
                d[L[t][i]] = d[t] + 1
                ans[L[t][i]] = t + 1
        if L[L[t][i]][0] == 0:
            dq.append(L[t][i])
    else:
        L[t][0] = 1
print('Yes')
print(*ans[1:], sep='\n')


### FIXED CODE ###

from collections import deque
import sys
input = sys.stdin.readline

def main():
    n, m = map(int, input().split())
    L = [[0] for _ in range(n)]
    for _ in [0] * m:
        a, b = map(int, input().split())
        L[a-1].append(b-1)
        L[b-1].append(a-1)
    L[0][0] = 1
    ans = [0] * n
    dq = deque([0])
    while dq:
        t = dq.popleft()
        for i in range(1, len(L[t])):
            next = L[t][i]
            if ans[next] != 0:
                continue
            ans[next] = t + 1
            dq.append(next)
        else:
            L[t][0] = 1
    print('Yes')
    print(*ans[1:], sep='\n')

main()
### BUGGY CODE ###

k = int(input())
i = 1 #数回す用
c = 0 #ルンルン数カウント

if k > 13000:
    i = 34454557
    c = 13000

while c < k:
  j = str(i)
  if i < 13: #13未満なら
    c = c + 1 #ルンルン数
    #print(c, i)
  else: #それ以外なら
    x = 0
    for n in range(len(j)-1): #ルンルン数判定を行う
      if abs(int(j[n]) - int(j[n+1])) > 1:#桁の差が1より大きかったら
        x = 1
        break
    if x == 0:
      c = c + 1
      #print(c, i)
  i = i + 1 #iに1を足す

print(i-1)

### FIXED CODE ###

k = int(input())
lunlun = [1, 2, 3, 4, 5, 6, 7, 8, 9] #ルンルン数リスト

for i in range(k):
    x = lunlun[i]
    if x%10 != 0:
        lunlun.append(x*10+x%10-1)
    lunlun.append(x*10+x%10)
    if x%10 != 9:
        lunlun.append(x*10+x%10+1)
        #print(lunlun)
print(x)
### BUGGY CODE ###

n = int(input())
a_list = list(map(int, input().split()))
q = int(input())
a_sum = []
for _ in range(q):
    b,c = map(int, input().split())
    for i in sorted(a_list, reverse=True):
        if i == b:
            a_list.remove(b)
            a_list.append(c)
    a_sum.append(sum(a_list))


for i in a_sum:
    print(i)

### FIXED CODE ###

n = int(input())
a = [int(i) for i in input().split()]
q = int(input())
num = [0] * 100010
b = [0] * q
c = [0] * q
for i in range(q):
    b[i], c[i] = map(int, input().split())

for i in a:
    num[i] += 1

s = sum(a)

#print(num)
#print(b)
#print(c)


for i in range(q):
    s += (c[i]-b[i])*num[b[i]]
    num[c[i]] += num[b[i]]
    #print(num)
    num[b[i]] = 0
    #print(num,"\n")
    print(s)
### BUGGY CODE ###

import collections

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

ans = N
for i in range(1, len(S)):
  n = 0
  if (i == 1):
    right = collections.Counter(S[i:])
    if 'E' in dict(right).keys():
      n = dict(right)['E']
  elif (i > 1 and i < len(S)):
    left = collections.Counter(S[:i-1])
    right = collections.Counter(S[i:])
    if 'W' in dict(left).keys():
      n += dict(left)['W']
    if 'E' in dict(right).keys():
      n += dict(right)['E']
  else:
    left = collections.Counter(S[:i-1])
    if 'W' in dict(left).keys():
      n = dict(left)['W']
  if (n < ans):
    ans = n
print(ans)

### FIXED CODE ###

import copy

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

lst = []
lst.append({"W": 0, "E": 0})
for i in range(1,len(S)+1):
  res = {"W": 0, "E": 0}
  if S[i-1] == "W":
    res["W"] += lst[i-1]["W"] + 1
    res["E"] += lst[i-1]["E"]
  else:
    res["W"] += lst[i-1]["W"]
    res["E"] += lst[i-1]["E"] + 1
  lst.append(res)
ans = N
for i in range(1,len(lst)):
  n = 0
  if (i != len(lst)-1):
    n = lst[i-1]["W"] + (lst[-1]["E"] - lst[i]["E"])
  else:
    n = lst[i-1]["W"]
  if (n < ans):
    ans = n
print(ans)
### BUGGY CODE ###

n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [0]*n
dp[1] = abs(h[1]-h[0])
for i in range(2, n):
    dp[i] = min(dp[i-j]+abs(h[i]-h[i-j]) for j in range(1, min(i, k)+1))
print(dp[-1])


### FIXED CODE ###

n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [0]*n
dp[1] = abs(h[1]-h[0])
for i in range(2, n):
    dp[i] = min(dp[i-j]+abs(h[i]-h[i-j]) for j in range(1, min(i, k)+1))
print(dp[-1])