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

while True:
    n, m = map(int, input().split())
    if not n:
        break

    ps = {int(input()) for _ in range(n)}
    ss = [False] * (m + 1)
    min_p, max_p = 1e8, 0
    for p in ps:
        ss[p] = True
        if min_p > p: min_p = p
        if max_p < p: max_p = p

    max_s = 0

    for t in range(1, 4):
        new_ss = [False] * (m + 1)
        for i in range(min(m, max_p * t), min_p * t - 1, -1):
            if ss[i]:
                for p in ps:
                    if i + p <= m:
                        new_ss[i + p] = True

        ss = new_ss

        p = m
        while p:
            if ss[p]:
                if max_s < p:
                    max_s = p
                break

    print(max_s)

### FIXED CODE ###

from bisect import bisect_right

while True:
    n, m = map(int, input().split())
    if not n:
        break

    ps = [0] + sorted(int(input()) for _ in range(n))

    p2 = set()
    for i, pi in enumerate(ps):
        for pj in ps[i:]:
            if pi + pj > m:
                break
            p2.add(pi + pj)

    p2 = sorted(p2)

    print(max(pi + p2[bisect_right(p2, m - pi) - 1] for pi in p2))
### BUGGY CODE ###

import heapq

n= int(input())
s=[input() for i in range(n)]

ss = list(set(s))
ss.sort()
li = []
heapq.heapify(li)
for i in ss:
    ans = s.count(i)
    heapq.heappush(li,(-ans,i))

for i in range(len(ss)):
    amount,st = heapq.heappop(li)
    if(i==0):
        print(st)
        ri=amount
        continue
    
    if(ri==amount):
        print(st)
    else:
        break

### FIXED CODE ###

import collections

n= int(input())
s=[input() for i in range(n)]

li = collections.Counter(s)
ma= max(li.values())

ans= [i for i,j in li.items() if(j==ma)]
print("\n".join(sorted(ans)))
### BUGGY CODE ###

import sys
sys.setrecursionlimit(5000)

readline = sys.stdin.readline

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

# dp[i][j] = 左端がi、右端がjの状態でのX - Yの最高得点
# dp[0][-1] = 0
# 奇数回目の処理では、
# dp[i][j] = max(dp[i-1][j] + A[i],dp[i][j - 1] + A[j])
# 偶数回目の処理では、
# dp[i][j] = min(dp[i - 1][j]) + A[i],dp[i][j - 1] + A[j])

from functools import lru_cache

@lru_cache(maxsize=3000)
def f(i,j):
  # 左端がi,右端がjのとき、これから取ることが出来る最大値 右端は含まない[i:j)
  if j - i == 1:
    if (N - (j - i)) % 2 == 0:
      return A[i]
    else:
      return -A[i]
  if (N - (j - i)) % 2 == 0:
    # 先手の場合
    return max(f(i + 1,j) + A[i],f(i,j - 1) + A[j - 1])
  else:
    return min(f(i + 1,j) - A[i],f(i,j - 1) - A[j - 1])
  
print(f(0,N))

### FIXED CODE ###

import sys
readline = sys.stdin.readline

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

# dp[i][j] = 元の数列の中の連続する区間i～jに対して、最終局面に行った時のX-Yの最大値

dp = [[0] * (N + 1) for i in range(N + 1)]
  
for length in range(1, N + 1):
  for i in range(N - length + 1):
    j = i + length
    
    if (N - length) % 2 == 0: # 先手番
      dp[i][j] = max(dp[i + 1][j] + A[i], dp[i][j - 1] + A[j - 1])
      
    else: # 後手番
      dp[i][j] = min(dp[i + 1][j] - A[i], dp[i][j - 1] - A[j - 1])

print(dp[0][N])
### BUGGY CODE ###

def main():
    n, s = map(int, input().split())
    a = list(map(int, input().split()))
    mod = 998244353
    dp = [[0]*(s+1) for _ in range(n+1)]
    dp[0][0] = 1
    for i in range(1, n+1):
        ai = a[i-1]
        for j in range(s+1):
            dp[i][j] += dp[i-1][j]*2
            if j >= ai:
                dp[i][j] += dp[i-1][j-ai]
            dp[i][j] %= mod
    print(dp[n][s])
        

if __name__ == "__main__":
    main()

### FIXED CODE ###

def main():
    n, s = map(int, input().split())
    a = list(map(int, input().split()))
    mod = 998244353
    dp = [[0]*(3001) for _ in range(n+1)]
    dp[0][0] = 1
    for i in range(1, n+1):
        ai = a[i-1]
        for j in range(ai):
            dp[i][j] += dp[i-1][j]*2
            dp[i][j] %= mod
        for j in range(ai, 3001):
            dp[i][j] += dp[i-1][j]*2 + dp[i-1][j-ai]
            dp[i][j] %= mod
    print(dp[n][s])

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

N = int(input())
a = list(map(int, input().split()))
a.sort()

ans = 1
can = 1
for i in range(N):
    ans = ans * a[i]
    if(ans>1000000000000000000):
        can = 0

if(can==1):
    print(ans)
else:
    print(-1)


### FIXED CODE ###

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

ans = 1
can = 1
zero = 0

if 0 in a:
    zero = 1
    ans = 0

if(zero==0):
    for i in range(N):
        ans = ans * a[i]
        if(ans>1000000000000000000):
            can = 0
            break

if(can==1):
    print(ans)
else:
    print(-1)
### BUGGY CODE ###

N = int(input())
R = [tuple([int(x) for x in input().split()]) for _ in range(N)]
B = [tuple([int(x) for x in input().split()]) for _ in range(N)]

xl = [set() for _ in range(2 * N + 1)]
yl = [set() for _ in range(2 * N + 1)]

for b in B:
    x, y = b
    for i in range(x):
        xl[i].add(b)
    for j in range(y):
        yl[j].add(b)

cands = []
for r in R:
    x, y = r
    s = xl[x].intersection(yl[y])
    cands.append([r, len(s), s])

def f(cands, used, n):
    if not cands:
        return n
    ret = 0
    hd, tl = cands[0], cands[1:]
    r, _, s = hd
    for t in s - used:
        u = used.union({t})
        ret = max(ret, f(tl, u, n + 1))
    ret = max(ret, f(tl, used, n))
    return ret

import operator
cands.sort(key=operator.itemgetter(1))
print(f(cands, set(), 0))

### FIXED CODE ###

N = int(input())
R = [[int(x) for x in input().split()] for _ in range(N)]
B = [[int(x) for x in input().split()] for _ in range(N)]

import operator
R.sort(key=operator.itemgetter(1), reverse=True)
B.sort()

ans = 0
for b in B:
    xb, yb = b
    for r in R:
        xr, yr = r
        if xr < xb and yr < yb:
            ans += 1
            R.remove(r)
            break
print(ans)
### BUGGY CODE ###

import io
import sys
from functools import lru_cache

sys.setrecursionlimit(10000)


def IN_S():
  return input()


def IN_I():
  return int(input())


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


def IN_L_S():
  return list(map(str, input().split()))


def STR_SPLIT(s, n):
  for l in range(0, len(s), n):
    yield s[0 + l:n + l]


def T_IN():
  global test_str
  sys.stdin = io.StringIO(test_str[1:-1])


test_str = '''
2000 3
'''


def MAIN():
  # T_IN()
  A()


def A():
  n, k = IN_L_I()

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

    red = 0
    red += f(n - k, i - 1)
    red += f(n - k, i)
    red += f(n - k, i)
    red += f(n - k, i + 1)

    res = int((blue * red) % (10 ** 9 + 7))
    print(res)
  return None


def f(x: int, y: int):
  if x < y:
    return 0
  if x == y == 0:
    return 1
  if y < 1:
    return 0
  return f2(x - y, y)


def f2(x: int, y: int):
  return c(x + y - 1, y - 1)


def c(a: int, b: int):
  global hoge
  return pascal(a, b)


@lru_cache()
def pascal(x, y):
  if x == 0 or y == 0 or x == y:
    return 1
  else:
    return (pascal(x - 1, y - 1) + pascal(x - 1, y)) % (10 ** 9 + 7)


MAIN()


### FIXED CODE ###

import io
import sys

sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7


def IN_S():
  return input()


def IN_I():
  return int(input())


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


def IN_L_S():
  return list(map(str, input().split()))


def STR_SPLIT(s, n):
  for l in range(0, len(s), n):
    yield s[0 + l:n + l]


def T_IN():
  global test_str
  sys.stdin = io.StringIO(test_str[1:-1])


test_str = '''
2000 3
'''


def MAIN():
  # T_IN()
  cmb_init(MOD)
  A()


def A():
  x = IN_L_I()
  n = x[0]
  k = x[1]

  res = []
  for i in range(1, k + 1):
    blue = f(k, i)

    # red = 0
    # red += f(n - k, i - 1)
    # red += f(n - k, i)
    # red += f(n - k, i)
    # red += f(n - k, i + 1)
    red = f2(n - k - (i - 1), i + 1)

    res.append((blue * red) % MOD)

  [print(i) for i in res]
  return None


def f(x: int, y: int):
  if x < y:
    return 0
  if x == y == 0:
    return 1
  if y < 1:
    return 0
  return f2(x - y, y)


def f2(x: int, y: int):
  return c(x + y - 1, y - 1)


def c(a: int, b: int):
  return cmb(a, b, MOD)


def track(func):
  def tracked(*args, **kwargs):
    result = func(*args, **kwargs)
    name = func.__name__
    arg_str = ",".join(repr(arg) for arg in args)
    print("%s(%s) -> %r" % (name, arg_str, result))
    return result

  return tracked


### CMB ###############################
def cmb(n, r, mod):
  if (r < 0 or r > n):
    return 0
  r = min(r, n - r)
  return g1[n] * g2[r] * g2[n - r] % mod


def cmb_init(mod):
  for i in range(2, N + 1):
    g1.append((g1[-1] * i) % mod)
    inverse.append((-inverse[mod % i] * (mod // i)) % mod)
    g2.append((g2[-1] * inverse[-1]) % mod)


N = 10 ** 4
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]

### CMB ###############################


MAIN()
### BUGGY CODE ###

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


### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
o =a[::2]
e =a[1::2]
if len(a)%2==0:
    ans = e[::-1]+o
elif len(a)==1:
    ans = a
else:
    ans = o[::-1]+e
print(' '.join(map(str,ans)))
### BUGGY CODE ###

n,s=map(int,input().split())
a=list(map(int,input().split()))
dp=[0]*(s+1)
mod=998244353
dp[0]=pow(2,n,mod)
for i in range(n):
  m=a[i]
  for j in range(s,m-1,-1):
    dp[j]+=dp[j-m]*pow(2,mod-2,mod)
    dp[j]%=mod
print(dp[s])

### FIXED CODE ###

n,s=map(int,input().split())
dp=[0]*(s+1)
mod=998244353
inv=pow(2,mod-2,mod)
dp[0]=pow(2,n,mod)
for i in list(map(int,input().split())):
  for j in range(s,i-1,-1):
    dp[j]=(dp[j]+dp[j-i]*inv)%mod
print(dp[s])
### BUGGY CODE ###

import copy
n = int(input())
a = list(map(int, input().split()))
a2 = copy.copy(a)
a2.sort()
for i in range(n):
    if a2.index(a[i]) <= n//2 - 1:
        print(a2[n//2])
    else:
        print(a2[n//2 - 1])

### FIXED CODE ###

import copy
n = int(input())
a = list(map(int, input().split()))
a2 = copy.copy(a)
a2.sort()
x = a2[n//2 - 1]
y = a2[n//2]
for i in a:
    if i <= x:
        print(y)
    else:
        print(x)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
import bisect

N,Q = (int(x) for x in input().split())

stop_arr = [tuple(map(int, input().split())) for _ in range(N)]
Q_arr = [int(input()) for _ in range(Q)]

stop_arr_ind = list(range(N))
stop_arr_ind.sort(key=lambda x:stop_arr[x][2], reverse=True)

ans_arr = [-1]*Q

for i in stop_arr_ind:
    s,t,x = stop_arr[i]
    q_start = bisect.bisect_left(Q_arr, s-x)
    q_stop = bisect.bisect_left(Q_arr, t-x)
    for i in range(q_start, q_stop):
        ans_arr[i] = x

print(*ans_arr, sep="\n")


### FIXED CODE ###

import bisect

N,Q = (int(x) for x in input().split())

stop_arr = [tuple(map(int, input().split())) for _ in range(N)]
Q_arr = [int(input()) for _ in range(Q)]

stop_arr_ind = list(range(N))
stop_arr_ind.sort(key=lambda x:stop_arr[x][2])
# stop_arr.sort(key=lambda x:x[2], reverse=True)
ans_arr = [-1]*Q
skip_arr = [-1]*(Q+1)

def update_skip(skip_arr, x):
    if skip_arr[x] == -1:
        return x
    x_dest = update_skip(skip_arr, skip_arr[x])
    skip_arr[x] = x_dest
    return x_dest

for i in stop_arr_ind:
    s,t,x = stop_arr[i]
    q_start = bisect.bisect_left(Q_arr, s-x)
    q_stop = bisect.bisect_left(Q_arr, t-x)
    l = q_start
    while l < q_stop:
        if skip_arr[l] == -1:
            skip_arr[l] = q_stop
            ans_arr[l] = x
            l += 1
        else:
            l = update_skip(skip_arr, l)

print(*ans_arr, sep="\n")
### BUGGY CODE ###

l = input().split(" ")
N = int(l[0])
M = int(l[1])

jobs = []
for i in range(0, N):
    l = input().split(" ")
    jobs.append((int(l[0]), int(l[1])))

jobs.sort(key=lambda x: x[0])
jobs.sort(key=lambda x: x[1], reverse=True)

incomes = 0
for i in range(M-1, -1, -1):
    allowed = M - i
    for j in range(0, len(jobs)):
        if jobs[j][0] <= allowed:
            incomes = incomes + jobs[j][1]
            jobs.pop(j)
            break

print(incomes)

### FIXED CODE ###

from heapq import heappush, heappop

n, m = map(int, input().split())

works = []
for i in range(0, n):
    a, b = map(int, input().split())
    if a > m:
        continue
    works.append((a, b))

works.sort(reverse=True)

q = []
ans = 0

for i in range(1, m + 1):
    while works and works[-1][0] <= i:
        a, b = works.pop()
        heappush(q, -b)
    if q:
        b = -heappop(q)
        ans += b

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

def main():
  N = int(input())
  A = list(input().split())
  D = list(set(A))
  for d in D:
    if A.count(d) >= 2: return "NO"
  return "YES"

print(main())

### FIXED CODE ###

from collections import Counter as c
N = int(input())
A = list(input().split())
if c(A).most_common()[0][1] == 1: print("YES")
else: print("NO")
### BUGGY CODE ###

n, m, k = map(int, input().split())

friend = [[] for _ in range(n)]
block = [[] for _ in range(n)]

for _ in range(m):
  a, b = map(int, input().split())
  friend[a-1].append(b-1)
  friend[b-1].append(a-1)
  
for _ in range(k):
  c, d = map(int, input().split())
  block[c-1].append(d-1)
  block[d-1].append(c-1)
  
groups = []
active = [True] * n
belong = [0] * n
g_index = 0
while any(active):
  idx = active.index(True)
  g = [idx]
  active[idx] = False
  belong[idx] = g_index
  stack = [idx]
  while stack:
    v = stack.pop()
    for i in friend[v]:
      if active[i]:
        stack.append(i)
        active[i] = False
        belong[i] = g_index
        g.append(i)
  groups.append(g)
  g_index += 1
  
for i in range(n):
  size = len(groups[belong[i]]) - 1
  for j in groups[belong[i]]:
    if j in friend[i] or j in block[i]:
      size -= 1
  print(size, end=' ')

### FIXED CODE ###

class UnionFind:
  def __init__(self, n: int):
    self.parent = list(range(n))
    self.size = [1] * n
    self.rank = [1] * n
    
  def find(self, i: int) -> int:
    if self.parent[i] != i:
      self.parent[i] = self.find(self.parent[i])
    return self.parent[i]
  
  def unite(self, i: int, j: int):
    ri = self.find(i)
    rj = self.find(j)
    if ri != rj:
      if self.rank[ri] < self.rank[rj]:
        self.parent[ri] = rj
        self.size[rj] += self.size[ri]
      else:
        self.parent[rj] = ri
        self.size[ri] += self.size[rj]
        if self.rank[ri] == self.rank[rj]:
          self.rank[ri] += 1


n, m, k = map(int, input().split())

n_friend = [1 for _ in range(n)]
block = [[] for _ in range(n)]
friendship = UnionFind(n)

for _ in range(m):
  a, b = map(int, input().split())
  n_friend[a-1] += 1
  n_friend[b-1] += 1
  friendship.unite(a-1, b-1)
  
for _ in range(k):
  c, d = map(int, input().split())
  block[c-1].append(d-1)
  block[d-1].append(c-1)
  
for i in range(n):
  r = friendship.find(i)
  cand = friendship.size[r] - n_friend[i]
  for j in block[i]:
    if r == friendship.find(j):
      cand -= 1
  print(cand, end=' ')
### BUGGY CODE ###

N = int(input())
M = N // 2 + 1
P = list(map(float,input().split()))
#print(P)
dp = [[0] * (N + 1) for i in range(N + 1)]
dp[0][0] = 1.0

for i in range(N):
  for j in range(i + 1):
    #print(P[i])
    dp[i + 1][j + 1] += dp[i][j] * P[i]
    dp[i + 1][j] += dp[i][j] * (1 - P[i])

print(sum(dp[-1][M:]))

### FIXED CODE ###

import numpy as np
import sys
buf = sys.stdin.buffer

N = int(buf.readline())
M = N // 2 + 1
P = np.array(buf.readline().split(),dtype = float)

dp = np.zeros([(N + 1),(N + 1)])
dp[0][0] = 1.0

for i in range(N):
  tmp = dp[i].copy()
  dp[i + 1] = tmp * (1 - P[i])
  tmp = np.roll(tmp,1)
  dp[i + 1] += tmp * P[i] 
  
print(sum(dp[-1][M:]))
### BUGGY CODE ###

import heapq
N, M = map(int,input().split())
A = list(map(int,input().split()))
heapq.heapify(A)
for n in range(M):
    B, C = map(int,input().split())
    for b in range(B):
        if C > A[0]:
            heapq.heappushpop(A,C)
        else:
            break
print (sum(A))



### FIXED CODE ###

import heapq
N, M = map(int,input().split())
A = list(map(int,input().split()))
heapq.heapify(A)
ls_BC = []
for m in range(M):
    ls_BC.append(list(map(int,input().split())))
#print(ls_BC)
ls_BC = sorted(ls_BC, key=lambda x: x[1],reverse=True)
#print(ls_BC)
for B,C in ls_BC:
    for b in range(B):
        if C > A[0]:
            heapq.heappushpop(A,C)
        else:
            break
print (sum(A))
### BUGGY CODE ###

from collections import deque

H, W = map(int, input().split())
grid = [input() for i in range(H)]

# 初期の黒('#')の位置からの距離
dist = [[-1]*W for _ in range(H)]

# '#'の位置をキューに追加（＝今回はこれが複数あるので、複数スタートとなる）
black_cells = deque()
for h in range(H):
    for w in range(W):
        if grid[h][w] == '#':
            black_cells.append((h, w))
            dist[h][w] = 0

def bfs(black_cells, dist):
    d = 0
    while black_cells:
        # キューとして使うのでpop()ではなくpopleft()
        h, w = black_cells.popleft()
        d = dist[h][w]
        for dy, dx in ((1, 0), (0, 1), (-1, 0), (0, -1)):
            new_h = h + dy
            new_w = w + dx
            if new_h < 0 or H <= new_h or new_w < 0 or W <= new_w:
                continue
            if dist[new_h][new_w] == -1:  # セルが白('.')であるのと同義
                dist[new_h][new_w] = d+1
                black_cells.append((new_h, new_w))
    return d

d = bfs(black_cells, dist)
print(d)

### FIXED CODE ###

from collections import deque

H, W = map(int, input().split())
grid = [input() for i in range(H)]

# 初期の黒('#')の位置からの距離
dist = [[-1]*W for _ in range(H)]

# '#'の位置をキューに追加（＝今回はこれが複数あるので、複数スタートとなる）
black_cells = deque()
for h in range(H):
    for w in range(W):
        if grid[h][w] == '#':
            black_cells.append((h, w))
            dist[h][w] = 0

def bfs(black_cells, dist):
    d = 0
    while black_cells:
        # キューとして使うのでpop()ではなくpopleft()
        h, w = black_cells.popleft()
        d = dist[h][w]
        for dy, dx in ((1, 0), (0, 1), (-1, 0), (0, -1)):
            new_h = h + dy
            new_w = w + dx
            if new_h < 0 or H <= new_h or new_w < 0 or W <= new_w:
                continue
            if dist[new_h][new_w] == -1:  # セルが白('.')であるのと同義
                dist[new_h][new_w] = d+1
                black_cells.append((new_h, new_w))
    return d

d = bfs(black_cells, dist)
print(d)
### BUGGY CODE ###

from operator import mul
from functools import reduce
R=10**9+7
def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom
K=int(input())
S=input()
N=len(S)

A=0
TF=[1]
TS=[1]
C=[]
for i in range(K+1):
    TF.append(TF[i]*25 %R)
    TS.append(TS[i]*26 %R)
    C.append(combinations_count(i+N-1, i) %R)
for i in range(K+1): # Sに含まれる文字を加えるときは、必ず後ろであると考え、S[N-1]の(Sの文字を除いた)位置をiとする
    A=(A+TF[i]*TS[K-i]*C[i]) %R
print(A)

### FIXED CODE ###

K=int(input())
S=input()
N=len(S)
p=10**9+7
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N+K ):
    fact.append((fact[-1] * i) % p) # [-1]は後ろから?
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return (fact[n] * factinv[r] * factinv[n-r]) % p
A=0
TF=[1]
TS=[1]
for i in range(K+1):
    TF.append(TF[i]*25 %p)
    TS.append(TS[i]*26 %p)
for i in range(K+1): # Sに含まれる文字を加えるときは、必ず後ろであると考え、S[N-1]の(Sの文字を除いた)位置をiとする
    A=(A+TF[i]*TS[K-i]*cmb(i+N-1,i,p)) %p
print(A)
### BUGGY CODE ###

L = []
S = str(input())
q = int(input())
Q = [[] for _ in range(q)] 

for i in range(len(S)):
    L.append(S[i])

for i in range(q):
    A = input().split()
    Q[i] = A

num = 0

for i in range(q):
    if Q[i][0] == '1':
        num ^= 1
    if Q[i][0] == '2':
        if num == 0:
            if Q[i][1] == '1':
                L.insert(0, Q[i][2])
            else:
                L.append(Q[i][2])
        else:
            if Q[i][1] == '2':
                L.insert(0, Q[i][2])
            else:
                L.append(Q[i][2])

if num:
    L.reverse()

print(''.join(L))

### FIXED CODE ###

from collections import deque

L = deque([])
S = str(input())
q = int(input())
Q = [[] for _ in range(q)] 

for i in range(len(S)):
    L.append(S[i])

for i in range(q):
    A = input().split()
    Q[i] = A

num = 0

for i in range(q):
    if Q[i][0] == '1':
        num ^= 1
    if Q[i][0] == '2':
        if num == 0:
            if Q[i][1] == '1':
                L.appendleft(Q[i][2])
            else:
                L.append(Q[i][2])
        else:
            if Q[i][1] == '2':
                L.appendleft(Q[i][2])
            else:
                L.append(Q[i][2])

if num:
    L.reverse()

print(''.join(L))
### BUGGY CODE ###

n = int(input())
h = list(map(int, input().split()))
kari = 0
honto = 0
for i in range(n-1):
    kari = 0
    for j in range(i,n-1):
        if h[j+1] <= h[j]:
            kari += 1
        else:
            break
    if honto < kari:
        honto = kari
print(honto)



### FIXED CODE ###

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

def low_elements(seq):
    count = 0
    for i in range(len(seq)):
        count += 1
        for j in range(i):
            if seq[j] < seq[i] :
                count -= 1
                break
    return count


n = int(input())
seq1 = list(map(int, input().split()))
print(low_elements((seq1)))

### FIXED CODE ###

def low_elements(seq):
    count = 1
    m = seq[0]
    for l in range(1, len(seq)):
        if seq[l] <= m:
            count += 1
            m = seq[l]
    return count


n = int(input())
seq1 = list(map(int, input().split()))
print(low_elements((seq1)))
### BUGGY CODE ###

n=int(input())
nums=input().split()
b=list()

for var in range(0,n):
    b.append(nums[var])
    b=b[::-1]

ans=" ".join(b)
print(ans)

### FIXED CODE ###

n=int(input())
nums=input().split()
n1=nums[::2]
n2=nums[1::2]

if len(nums)%2==0:
    ans=" ".join(n2[::-1])+" "+" ".join(n1)
else:
    ans = " ".join(n1[::-1]) + " " + " ".join(n2)

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

S = input()
n = 0
import re
re.sub('BB+',"BB",S)
re.sub("WW+",'WW',S)


while 'BWBWBW' in S:
    n += 6*S.count('BWBWBW')
    S = S.replace('BWBWBW','WB')
while 'BW' in S:
    n += S.count('BW')
    S = S.replace('BW','WB')
print(n)

### FIXED CODE ###

S = input()
n = 0
k = 0
m = len(S)
for i in range(m):
    if S[i] == 'B':
        n += m - (i+1) -k
        k += 1
print(n)
### BUGGY CODE ###

def lukas(n):
    if n==0:
        return 2
    elif n==1:
        return 1
    else:
        return lukas(n-1)+lukas(n-2)
n=int(input())
print(lukas(n))            

### FIXED CODE ###

n=int(input())
a=2
b=1
if n==1:
    print(b)
else:
    for i in range(2,n):
        if i%2==0:
            a=a+b
        else:
            b=a+b
    print(a+b)
### BUGGY CODE ###

M,N=input().split(' ')
M=int(M)
N=int(N)

res=1
if M==N:
    for i in range(1, M+1):
        res*=i
    res=res*res*2
elif abs(M-N)==1:
    for i in range(1, M+1):
        res*=i
    for i in range(1, N+1):
        res*=i
else:
    res=0

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


### FIXED CODE ###

from math import *
M,N=input().split(' ')
M=int(M)
N=int(N)

res=1
if M==N:
    res=factorial(M)
    res=res*res*2
elif M-N==1:
    res=factorial(N)
    res*=res*M
elif M-N==-1:
    res=factorial(M)
    res*=res*N
else:
    res=0

print(res%(10**9+7))
### BUGGY CODE ###

N, M = map(int, input().split())
li = []
for i in range(M):
  liin = input().split()
  li.append([int(liin[0]), liin[1]])

ans1, ans2 = 0, 0
done = []
miss = {}

for i in range(M):
  if li[i][0] in done:
    continue
  if li[i][1] == "AC":
    ans1 += 1
    done.append(li[i][0])
    if li[i][0] in miss:
      ans2 += miss[li[i][0]]
      del miss[li[i][0]]
  else: # "WA"
    if li[i][0] in miss:
      miss[li[i][0]] += 1
    else:
      miss[li[i][0]] = 1

print(ans1,ans2)

### FIXED CODE ###

N, M = map(int, input().split())
li = []
for i in range(M):
  liin = input().split()
  li.append([int(liin[0]), liin[1]])

ans1, ans2 = 0, 0
done = set([0])
miss = {}

for i in range(M):
  if li[i][0] in done:
    continue
  if li[i][1] == "AC":
    ans1 += 1
    done.add(li[i][0])
    if li[i][0] in miss:
      ans2 += miss[li[i][0]]
      del miss[li[i][0]]
  else: # "WA"
    if li[i][0] in miss:
      miss[li[i][0]] += 1
    else:
      miss[li[i][0]] = 1

print(ans1,ans2)