Harryxun/stf_run huggingface dataset:
import sys
H,W = map(int,input().split())
C = list(map(int,sys.stdin))
for i in C:
    print(C[i])
    print(C[i])


### FIXED CODE ###

import sys

H, W = sys.stdin.readline().split()
C = map(str, sys.stdin)
for i in C:
    print(i)
    print(i)
a, b, x = input().split()
a = int(a)
b = int(b)
c = int(c)
if a <= x and a + b >= x:
    print("YES")
else:
    print("NO")

### FIXED CODE ###

a, b, c = input().split()
a = int(a)
b = int(b)
c = int(c)
if a <= c and a + b >= c:
    print("YES")
else:
    print("NO")
N, M = map(int, input().split())

if M == 1:
	print(0)
elif M == 2:
	if N == 1:
		X_list = [int(_) for _ in list(input().split())]
		print(abs(X_list[0]-X_list[1]))
	else:
		print(0)
else:
	X_list = [int(_) for _ in list(input().split())]

	X_list.sort()
	X_list.reverse()

	X_diff_list = [X_list[i-1]-X_list[i] for i in range(1, M)]
	X_diff_list.sort()
	X_diff_list.reverse()

	answer = sum(X_diff_list)

	if N == 1:
		print(answer)
	else:
		for n in range(N-1):
			answer -= X_diff_list[n]
		print(answer)


### FIXED CODE ###

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

if M <= N:
	print(0)
elif M == 2:
	if N == 1:
		X_list = [int(_) for _ in list(input().split())]
		print(abs(X_list[0]-X_list[1]))
	else:
		print(0)
else:
	X_list = [int(_) for _ in list(input().split())]

	X_list.sort()
	X_list.reverse()

	X_diff_list = [X_list[i-1]-X_list[i] for i in range(1, M)]
	X_diff_list.sort()
	X_diff_list.reverse()

	answer = sum(X_diff_list)

	if N == 1:
		print(answer)
	else:
		for n in range(N-1):
			answer -= X_diff_list[n]
		print(answer)
n=int(input())
X=[]
Y=[]
A=[0]*n
for i in range(n):
  A[i]=int(input())
  a=A[i]
  x=[0]*a
  y=[0]*a
  for j in range(a):
    x[j],y[j]=[int(s) for s in input().split()]
  X.append(x)
  Y.append(y)
  
s=0
for i in range(2**n):
  c=0
  d=0
  B=[0]*n
  for j in range(n):
    if((i >> j) & 1):
      c=c+1
      B[j]=1
  for k in range(n):
    if B[k]==1:
      for j in range(A[k]):
        if Y[k][j]!=B[X[k][j]]:
          d=-1
          break
    if d<0:
      break
  if s<c:
    s=c
      
      
print(s)         




### FIXED CODE ###

n=int(input())
X=[]
Y=[]
A=[0]*n
for i in range(n):
  A[i]=int(input())
  a=A[i]
  x=[0]*a
  y=[0]*a
  for j in range(a):
    x[j],y[j]=[int(s) for s in input().split()]
  X.append(x)
  Y.append(y)
  
s=0
for i in range(2**n):
  c=0
  d=0
  B=[0]*n
  for j in range(n):
    if((i >> j) & 1):
      c=c+1
      B[j]=1
  for k in range(n):
    if B[k]==1:
      for j in range(A[k]):
        if Y[k][j]!=B[X[k][j]-1]:
          d=-1
          break
    if d<0:
      break
  if s<c and d==0:
    s=c
      
      
print(s)
def paths(i,j):

    if a[i][0][j]=='#':
        return 0
    if i==h-1 and j==w-1:
        return 1
    if i<h-1 and j<w-1:
        if dp[i][j]==-1:
          dp[i][j]=paths(i+1,j)+paths(i,j+1)
          return dp[i][j]
        else:
            return dp[i][j]
    elif i==h-1 and j<w-1:
        if dp[i][j]==-1:
           dp[i][j]=paths(i,j+1)
           return dp[i][j]
        else:
            return dp[i][j]
    elif i<h-1 and j==w-1:
        if dp[i][j]==-1:
           dp[i][j]=paths(i+1,j)
           return dp[i][j]
        else:
            return dp[i][j]


h,w=map(int,input().split())
a=[[]for _ in range(h)]
m=1000000007
for i in range(h):
   a[i].extend(input().split())
dp=[[-1 for _ in range(w)]for _ in range(h)]
print(paths(0,0)%m)


### FIXED CODE ###

import sys
sys.setrecursionlimit(20000)

def paths(i, j):

    if i == h - 1 and j == w - 1:
        return 1
    if a[i][0][j] == '#':
        return 0
    if i < h - 1 and j < w - 1:
        if dp[i][j] == -1:
            dp[i][j] = paths(i + 1, j) + paths(i, j + 1)
            return dp[i][j]
        else:
            return dp[i][j]
    elif i == h - 1 and j < w - 1:
        if dp[i][j] == -1:
            dp[i][j] = paths(i, j + 1)
            return dp[i][j]
        else:
            return dp[i][j]
    elif i < h - 1 and j == w - 1:
        if dp[i][j] == -1:
            dp[i][j] = paths(i + 1, j)
            return dp[i][j]
        else:
            return dp[i][j]


h, w = map(int, input().split())
a = [[] for _ in range(h)]
m = 1000000007
for i in range(h):
    a[i].append(input())
dp = [[-1 for _ in range(1000)] for _ in range(1000)]
print(paths(0, 0) % m)
n, k = map(int,input().split())
a = list(map(int,input().split()))
mod = 10**9 + 7

plus = []
minus = []

for i in a:
	if i >= 0:
		plus.append(i)
	else:
		minus.append(i)

plus.sort(key=lambda x:-x)
minus.sort()

#print(plus, minus)

"""
貪欲チックに求める
numplus … 前からnumplus番目まで掛け合わせる
numminus … 前からnumminus番目まで掛け合わせる

入力例2に合わせるのは場合分けが必要だが, minusは2個単位で管理する.
"""
numplus = k
numminus = 0

"""
kがplusを超える場合, うまく処理ができないのでリスト参照できる範囲まで下げる.
"""
while numplus > len(plus):
	numplus -= 2
	numminus += 2

if numplus < 0:
	numminus += numplus
	ans = 1
	tmp = sorted(a, key=lambda x:-x)
	for i in range(numminus):
		ans = ans * tmp[i] % mod
	print(ans)
	exit()

#print(numplus, numminus)

tmpplus = -1
tmpminus = -1

while numplus-1 >= 0 and numminus+1 < len(minus):
	if plus[numplus-1] * plus[numplus-2] <= minus[numminus] * minus[numminus+1]:
		numplus -= 2
		numminus += 2
		tmpminus = numminus
		tmpplus = numplus
	else:
		break

#print(tmpminus, tmpplus)

ans = 1
for i in range(numplus):
	ans = ans * plus[i] % mod
for i in range(numminus):
	ans = ans * minus[i] % mod
print(ans)

### FIXED CODE ###

n, k = map(int,input().split())
a = list(map(int,input().split()))
mod = 10**9 + 7

plus = []
minus = []

for i in a:
	if i >= 0:
		plus.append(i)
	else:
		minus.append(i)

plus.sort(key = lambda x:-x)
minus.sort()

#print(plus, minus)

"""
貪欲チックに求める
numplus … 前からnumplus番目まで掛け合わせる
numminus … 前からnumminus番目まで掛け合わせる

入力例2に合わせるのは場合分けが必要だが, minusは2個単位で管理する.
"""

numplus = k
numminus = 0

"""
kがplusを超える場合, うまく処理ができないのでリスト参照できる範囲まで下げる.
"""
while numplus > len(plus):
	numplus -= 2
	numminus += 2

#print(numplus, numminus)

while numplus-2 >= 0 and numminus+1 < len(minus):
	if plus[numplus-1] * plus[numplus-2] <= minus[numminus] * minus[numminus+1]:
		numplus -= 2
		numminus += 2
	else:
		break

#print(numplus, numminus)

ans = 1

if numplus >= 0 and numminus >= 0 and numminus <= len(minus) and numplus <= len(plus):
	for i in range(numplus):
		ans = ans * plus[i] % mod
	for i in range(numminus):
		ans = ans * minus[i] % mod
else:
	"""
	これは, ansが負になる場合や, minusが1個だけの場合, minusしかない場合, plusしかない場合に使える.
	"""
	#print("ここに来ました！")
	tmp = sorted(a, key=lambda x:-x)
	for i in range(k):
		ans = ans * tmp[i]%mod

print(ans)
from heapq import heappop
from collections import defaultdict

class UnionFind:
    def __init__(self, size):
        self.data = [-1] * size
    def find(self, x):
        if self.data[x] < 0:
            return x
        else:
            self.data[x] = self.find(self.data[x])
            return self.data[x]
    def union(self, x, y):
        x, y = self.find(x), self.find(y)
        if x != y:
            if self.data[y] < self.data[x]:
                x, y = y, x
            self.data[x] += self.data[y]
            self.data[y] = x
        return (x != y)
    def same(self, x, y):
        return (self.find(x) == self.find(y))
    def size(self, x):
        return -self.data[self.find(x)]


N, M, *L = map(int, open(0).read().split())
A, XY = L[:N], L[N:]

uf = UnionFind(N)
for x, y in zip(*[iter(XY)] * 2):
    uf.union(x, y)

C = defaultdict(list)
for i, a in enumerate(A):
    C[uf.find(i)].append(a)

if len(C) < 2:
    print(0)
    quit()

D = [sorted(c) for c in C.values()]
s = sum(heappop(d) for d in D)

L = []
for d in D:
    L += d

if len(L) < len(D) - 2:
    print("Impossible")
else:
    print(s + sum(sorted(D)[:-2]))


### FIXED CODE ###

from heapq import heappop
from collections import defaultdict

class UnionFind:
    def __init__(self, size):
        self.data = [-1] * size
    def find(self, x):
        if self.data[x] < 0:
            return x
        else:
            self.data[x] = self.find(self.data[x])
            return self.data[x]
    def union(self, x, y):
        x, y = self.find(x), self.find(y)
        if x != y:
            if self.data[y] < self.data[x]:
                x, y = y, x
            self.data[x] += self.data[y]
            self.data[y] = x
        return (x != y)
    def same(self, x, y):
        return (self.find(x) == self.find(y))
    def size(self, x):
        return -self.data[self.find(x)]


N, M, *L = map(int, open(0).read().split())
A, XY = L[:N], L[N:]

uf = UnionFind(N)
for x, y in zip(*[iter(XY)] * 2):
    uf.union(x, y)

C = defaultdict(list)
for i, a in enumerate(A):
    C[uf.find(i)].append(a)

if len(C) < 2:
    print(0)
    quit()

D = [sorted(c) for c in C.values()]
s = sum(heappop(d) for d in D)

L = []
for d in D:
    L += d

if len(L) < len(D) - 2:
    print("Impossible")
else:
    print(s + sum(sorted(L)[:len(D) - 2]))
import math
import sys

sys.setrecursionlimit(100000000)
# 動的計画法とmemo化で解く。
N, X = map(int, input().split())
S = list(map(int, input().split()))
S.sort(reverse=True)


def memoize(f):  # メモ化関数
    table = [{} for _ in range(N+1)]

    def func(i, key):
        if key not in table[i]:
            table[i][key] = f(i, key)
        return table[i][key]
    return func


@memoize
def dfs(i, x):
    if i == N:
        return x
    else:
        p = 1/(N-i)
        return dfs(i+1, x % S[i]) * p + dfs(i+1, x) * (1-p)


print(int((dfs(0, X) * math.factorial(N))) % (10**9+7))


### FIXED CODE ###

import math
import sys

sys.setrecursionlimit(100000000)
# 動的計画法とmemo化で解く。
N, X = map(int, input().split())
S = list(map(int, input().split()))
S.sort(reverse=True)


def memoize(f):  # メモ化関数
    table = [{} for _ in range(N+1)]

    def func(i, key):
        if key not in table[i]:
            table[i][key] = f(i, key)
        return table[i][key]
    return func


@memoize
def dfs(i, x):
    if i == N:
        return x
    else:
        return dfs(i+1, x % S[i]) + dfs(i+1, x) * (N-i-1)


print(dfs(0, X) % (10**9+7))
_n = int(raw_input())
_a = [int(x) in x for raw_input().split()]

_flg = 1
cnt = 0

while _flg:
    _flg = 0
    for i in reversed(range(1, _n)):
        if _a[i] < _a[i-1]:
            _a[i], _a[i-1] = _a[i-1], _a[i]
            cnt += 1
            _flg = 1

print(" ".join(_a))
print(cnt)

### FIXED CODE ###

_n = int(raw_input())
_a = [int(x) for x in raw_input().split()]

_flg = 1
cnt = 0

while _flg:
    _flg = 0
    for i in reversed(range(1, _n)):
        if _a[i] < _a[i-1]:
            _a[i], _a[i-1] = _a[i-1], _a[i]
            cnt += 1
            _flg = 1

print(" ".join([str(x) for x in _a]))
print(cnt)
def main():
    nm = map(int, raw_input().split())
    A = []
    B = []
    flag = False
    for i in range(nm[0]):
        A.append(raw_input())
    for i in range(nm[1]):
        B.append(raw_input())

    for i in range(nm[0]):
        for j in range(nm[0]):
            if j + nm[1] <= nm[0]:
                for k in range(nm[1]):
                    for l in range(nm[1]):
                        if(A[i+k][j+l] == B[k][l]):
                            flag = True
                        else:
                            flag = False
                            break 
                    if flag == False:
                        break
            if flag:
                 break
        if flag:
            break
    if flag:
        return "Yes"
    else:
        return "No"    
print main()

### FIXED CODE ###

def main():
    nm = map(int, raw_input().split())
    A = []
    B = []
    flag = False
    for i in range(nm[0]):
        A.append(raw_input())
    for i in range(nm[1]):
        B.append(raw_input())

    for i in range(nm[0]):
      if i + nm[1] <= nm[0]:
        for j in range(nm[0]):
            if j + nm[1] <= nm[0]:
                for k in range(nm[1]):
                    for l in range(nm[1]):
                        if(A[i+k][j+l] == B[k][l]):
                            flag = True
                        else:
                            flag = False
                            break 
                    if flag == False:
                        break
            else:
                break
            if flag:
                 break
        if flag:
            break
      else:
          break
       
    if flag:
        return "Yes"
    else:
        return "No"    
print main()
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
k=i1()


x=list(range(1,10))

y=[]
z=[]
for i in range(1,15):
 for j in range(1,10):
  y.append((10**i*(j+1)-1)/(j+i*9))
  z.append(10**i*(j+1)-1)
for i in range(len(z)-1):
  s=z[i]+1
  x.append(z[i])
  while s/sum(list(map(int, list(str(s)))))<=y[i+1]:
        x.append(s)
        s+=1

for i in range(k):
  print(x[i])

### FIXED CODE ###

def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
x=[]
k=i1()
for s in range(1,10):
 x.append([s/sum(list(map(int, list(str(s))))),s])

for i in range(1,1000):
 for j in range(1,15):
   s=10**j*i+10**j-1
   x.append([s/sum(list(map(int, list(str(s))))),s])

y=sorted(x)
m=0
n=0
for i,j in y:
  if n>k-1:
     break
  if j>10**15:
     break
  if j>m:
     m=j
     print(j)
     n+=1
import numpy as np
N=int(input())
xy=np.array([list(map(int,input().split())) for i in range(N)])
print(sum(np.linalg.norm(i-j) for i in xy for j in xy)/N)

### FIXED CODE ###

import itertools
n=int(input())
a=[]
for i in range(n):
  x,y=map(int,input().split())
  a.append((x,y))
num=0
count=0
for i in itertools.permutations(range(n),n):
  s=list(i)
  num+=1
  for j in range(n-1):
    count+=((a[s[j+1]][0]-a[s[j]][0])**2+(a[s[j+1]][1]-a[s[j]][1])**2)**(0.5)
print(count/num)
def pr(data,next,head,tail):
    i = head
    while(1):
        if i == -1:
            print("")
            break
        print(data[i],end = "")
        i = next[i]
        if i != -1 :
            print(" ",end="")

def ins_f(data,next,prev,x,head,tail):
    size = len(data)
    if head != -1 :
        data.append(x)
        size += 1
        next.append(head)
        prev.append(-1)
        prev[head] = size -1
        head = size -1
    else :
        data.append(x)
        size += 1
        next.append(-1)
        prev.append(-1)
        tail = size-1
        head = size-1
    return head,tail

def dl(data,next,prev,x,head,tail):
    i = head
    while(1):
        if data[i] == x:
            if i == head:
                head = dl_f(next,prev,head)
                break
            elif i == tail:
                tail = dl_l(next,prev,tail)
                break
            else :
                prev[next[i]] = prev[i]
                next[prev[i]] = next[i]
                break
        elif i == tail:
            break
        i = next[i]
    return head,tail

def dl_f(next,prev,head,tail):
    if head == -1:
        return head
    elif next[head] == -1:
        head = -1
        tail = -1
    else:
        prev[next[head]] = -1
        head = next[head]
    return head,tail

def dl_l(next,prev,head,tail):
    if tail == -1:
        return tail
    elif prev[tail] == -1:
        head = -1
        tail = -1
    else:
        next[prev[tail]] = -1
        tail = prev[tail]
    return head,tail

n = int(input())
data = []
next = []
prev = []
head = -1
tail = -1
size = len(data)

for i in range(n):
    x = input().split()
    if x[0] == "insert":
        head,tail = ins_f(data,next,prev,x[1],head,tail)
    elif x[0] == "delete":
        head,tail = dl(data,next,prev,x[1],head,tail)
    elif x[0] == "deleteFirst":
        head,tail = dl_f(next,prev,head,tail)
    elif x[0] == "deleteLast":
        head,tail = dl_l(next,prev,head,tail)
pr(data,next,head,tail)



### FIXED CODE ###

from collections import deque

def pr(a):
    for i in range(len(a)):
        if i == len(a)-1:
            print(a[i])
        else:
            print(a[i],end = " ")

n = int(input())
q = deque()
for i in range(n):
    x = input()
    l = len(x)
    if x[0] == "i":
        q.insert(0,x[7:])
    elif x[6] == " ":
        try:
            q.remove(x[7:])
        except:
            pass
    elif l > 10:
        q.popleft()
    elif l > 6:
        q.pop()

print(*q)
s = list(input())
ACGT = ['A', 'C', 'G', 'T']

count = 0
result = []
for w in s:
    if w in ACGT:
        count += 1
    else:
        result.append(count)
        count = 0

print(max(result))

### FIXED CODE ###

s = list(input())
ACGT = ['A', 'C', 'G', 'T']

count = 0
result = []
for w in s:
    if w in ACGT:
        count += 1
    else:
        result.append(count)
        count = 0
result.append(count)

print(max(result))
# -*- coding: utf-8 -*-
import math
a,b = map(int,input().split())

ans = a * b // math.gcd(a,b)
print(ans)


### FIXED CODE ###

# -*- coding: utf-8 -*-
a,b = map(int,input().split())

def gcd(a,b):
    x = max(a,b)
    y = min(a,b)
    if x % y == 0:
        return y
    else:
        while True:
            if x % y != 0:
                z = x % y
                x = y
                y = z
            else:
                break
        return z


def lcm(a,b):
    return a * b // gcd(a,b)

ans = lcm(a,b)
print(ans)
n,m=map(int,input().split())
w=[]
if n<99:
    print(w[1])
for i in range(m):
    a,b=map(int,input().split())
    w.append((a,b))
w.sort(reverse=True)
d=[]
for i in range(m):
    a,b=w.pop()
    if i==0:
        d.append([a,b])
    else:
        if d[-1][1]<=a:
            d.append([a,b])
        elif d[-1][1]>b:
            d[-1][1]=b
print(len(d))


### FIXED CODE ###

n,m=map(int,input().split())
w=[]
for i in range(m):
    a,b=map(int,input().split())
    w.append((a,b))
w.sort(reverse=True)
d=[]
for i in range(m):
    a,b=w.pop()
    if i==0:
        d.append([a,b])
    else:
        if d[-1][1]<=a:
            d.append([a,b])
        elif d[-1][1]>b:
            d[-1][1]=b
print(len(d))
n,k = map(int,input().split())
output = []

for i in range(k):
  d = int(input())
  l = list(map(int,input().split()))
  output.append(l)

print(n - len(set(output)))

### FIXED CODE ###

n,k = map(int,input().split())
ans = [1]*n

for i in range(k):
  d = int(input())
  for j in list(map(int,input().split())):
    ans[j-1] = 0

print(ans.count(1))
# 02
import sys
import math


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


n, m = LI()
s = S()
t = S()

gcd = math.gcd(n, m)
l = n * m // gcd
d_s = l // n
d_t = l // m

x = list('*' * l)
is_ok = True
for i in range(n):
    x[d_s * i] = s[i]
for i in range(m):
    if x[d_t * i] != '*' and x[d_t * i] != t[i]:
        is_ok = False
        break
    x[d_t * i] = t[i]
if is_ok:
    ans = len(x)
    print(ans)
else:
    print(-1)


### FIXED CODE ###

# 02
import sys
import math


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


n, m = LI()
s = S()
t = S()

gcd = math.gcd(n, m)
lcm = n * m // gcd
i_s = n // gcd
i_t = m // gcd
for i in range(gcd):
    if s[i*i_s] != t[i*i_t]:
        print(-1)
        exit()
print(lcm)
x = input().split(" ")
command = x[1]
N = x[0]
N = command.lower(x[1])
print(N)

### FIXED CODE ###

n,k=map(int,input().split())
s = input()
 
s = list(s)
s[k - 1] = s[k-1].lower()
s = "".join(s)
print(s)
N = int(input())
A = [None for _ in range(N)]
B = [None for _ in range(N)]
endflg = [0 for _ in range(N)]
for i in range(N):
  A[i],B[i] = map(int,input().split())
time = 0

limit = max(B) + 1

for i in range(N):
  Pb = B.index(min(B))
  if time + A[Pb] <= B[Pb]:
    endflg[Pb] = 1
    B[Pb] = limit
    time = time + A[Pb]
  else:
    break
    
if endflg == [1 for _ in range(N)]:
  print("Yes")
else:
  print("No")
  

### FIXED CODE ###

S = input()
A = [int(S[0]),int(S[1]),int(S[2]),int(S[3])]

flg = 0
for i in range(len(A) - 1):
  if A[i] == A[i + 1]:
    flg = 1
    break

if flg:
  print("Bad")
else:
  print("Good")
import math

a,b,x = map(int,input().split())

if x <= a*a*b/2:
    S = x/a
    f = 2*S/b
    print(math.degrees(math.atan(b/f)))
else:
    S = a*b- x/a
    f = 2*S/a
    print(90-math.degrees(math.atan(a/f)))

### FIXED CODE ###

import math

a,b,x = map(int,input().split())

if x == a**2 * b:
    print(0)
    exit()

if x <= a*a*b/2:
    S = x/a
    f = 2*S/b
    print(math.degrees(math.atan(b/f)))
else:
    S = a*b- x/a
    f = 2*S/a
    print(90-math.degrees(math.atan(a/f)))
m,n = int(input())
if n == m:
  print('Yes')
else:
  print('No')

### FIXED CODE ###

n = input().split(' ')
if n[1] == n[0]:
    print('Yes')
else:
    print('No')
from numpy import pi
r = float(input())
print(round(r * r * pi, 7), round(2 * pi * r, 7))

### FIXED CODE ###

from math import pi
r = float(input())
print(round(r * r * pi, 7), round(2 * pi * r, 7))
ab = list(map(int,input().split()))

if ab in 2:
  print("No")
else:
  print("Yes")

### FIXED CODE ###

ab = list(map(int,input().split()))
 
if 2 in ab:
  print("No")
else:
  print("Yes")
S = ''

def we_love_abc()->int:
    global S
    ABC = 'ABC'

    dp = [0, 0, 0, 0]
    dp[3] = 1

    for c in reversed(S):
        if c == '?':
            m, m1 = 3, 3
        else:
            m, m1 = 1, 1

        for j in range(3):
            m2 = 1 if c == '?' or c == ABC[j] else 0
            dp[j] = m1 * dp[j] + m2 * dp[j+1]
        dp[3] = m * dp[3]

    return dp[0] % 1000000007


if __name__ == "__main__":
    S = input()
    ans = we_love_abc(S)
    print(ans)


### FIXED CODE ###

def we_love_abc(S: str)->int:
    ABC = 'ABC'
    MOD = 1000000007

    dp = [0, 0, 0, 0]
    dp[3] = 1

    for c in reversed(S):
        for j in range(3):
            m1 = 3 if c == '?' else 1
            m2 = 1 if c == '?' or c == ABC[j] else 0
            dp[j] = (m1 * dp[j] + m2 * dp[j+1]) % MOD
        dp[3] = (3 if c == '?' else 1) * dp[3]
        dp[3] %= MOD

    return dp[0] % MOD


if __name__ == "__main__":
    S = input()
    ans = we_love_abc(S)
    print(ans)
A = input()
B = input()
AA = "%-101s", A
BB = "%-101s", B
if AA == BB:
    print("EQUAL")
elif AA>BB:
    print("GREATER")
else:
    print("LESS")

### FIXED CODE ###

A, B, C = input().split()
print(A[0].upper()+B[0].upper()+C[0].upper())
H,N = map(int,input().split())
A = list(map(int,input().split()))

if sum(A)>=H:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

H,A = map(int,input().split())

if H%A==0:
  print(H//A)
else:
  print(H//A+1)
s = input()
K = int(input())
print(sorted(list(set([s[i:j+1] for i in range(len(s)) for j in range(i,len(s))])))[K-1])

### FIXED CODE ###

s = input()
K = int(input())
ls = []

for i in range(1,K+1):
    for j in range(len(s)):
        ls.append(s[j:j+i])
print(sorted(set(ls))[K-1])
a,b=map(int,input().split())
c=(b-1)//(a-1)
if c-int(c)=0:
  print(str(c))
  
else:
  print(c+1)
  


### FIXED CODE ###

a,b=map(int,input().split())
c=(b-1)/(a-1)
if c-int(c)==0:
  print(int(c))

else:
  print(int(c)+1)
s=input()
print(s.replace("?", "D")

### FIXED CODE ###

s=input()
print(s.replace("?", "D"))
x,n=map(int,input().split())
if n!=0:
  p=list(map(int,input().split()))
  c=[0]*100
  for i in p:
    c[i-1]+=1
  ans=0
  while True:
    if c[x-ans-1]==0:
      ans=x-ans
      break
    elif c[x+ans-1]==0:
      ans=x+ans
      break
    else:
      ans+=1
  print(ans)
else:
  print(x)

### FIXED CODE ###

x,n=map(int,input().split())
if n!=0:
  p=list(map(int,input().split()))
else:
  p=[]
ans=0
if x in p:
  low=x
  high=x
  while True:
    low-=1
    high+=1
    if low in p:
      if high in p:
        continue
      else:
        ans=high
        break
    else:
      ans=low
      break
  print(ans)
else:
  print(x)
a,b = map(int,input().spilit())
import math
if a==b:
  print(math.factorial(a)**2*2%(10**9+7))
elif abs(a-b)==1:
  print(math.factorial(a)*math.factorial(b))
else:
  print(0)

### FIXED CODE ###


a,b = map(int,input().split())
import math
if a==b:
  print((math.factorial(a)%(10**9+7))**2*2%(10**9+7))
elif abs(a-b)==1:
  print((math.factorial(max(a,b))%(10**9+7))*(math.factorial(min(a,b))%(10**9+7))%(10**9+7))
else:
  print(0)