Harryxun/stf_run huggingface dataset:
while True:
    H, W =[int(i) for i in input().split ]
    if H == W == 0:
       break
 
    for h in range(H):
        for w in range(W):
            if h == 0 or h == h -1 or w == 0 or w == W - 1:
               print('#', end=' ')
            else:
                print('.', end=' ')
 
        print()
 
    print()

### FIXED CODE ###

while True:
    H, W = [int(i) for i in input().split()]
    if H == W == 0:
        break
    for h in range(H):
        for w in range(W):
            if h == 0 or h == H - 1 or w == 0 or w == W - 1:
                print('#', end='')
            else:
                print('.', end='')
        print()
    print()
print(sum(range(1,int(input())+1))

### FIXED CODE ###

print(sum(range(int(input())+1)))
#16D8101023J 久保田凌弥 kubotarouxxx python3

(x,y)=int(input())

w=x*y
z=2*x+2*y

print(w,z)



### FIXED CODE ###

#16D8101023J 久保田凌弥 kubotarouxxx python3

x,y=map(int, input().split())
w=x*y
z=2*x+2*y

print(w,z)

#
N=int(input())
test_case=[input() for_in range(N)]
a=test_case.count('AC')
b=test_case.count('WA')
c=test_case.count('TLE')
d=test_case.count('RE')
print('AC x '+a)
print('WA x '+b)
print('TLE x '+c)
print('RE x '+d)

### FIXED CODE ###

N=int(input())
test_case=[input() for _ in range(N)]
a=test_case.count('AC')
b=test_case.count('WA')
c=test_case.count('TLE')
d=test_case.count('RE')
print('AC x '+ str(a))
print('WA x '+ str(b))
print('TLE x '+str(c))
print('RE x '+str(d))
n,k = map(int,input().split())
a = list(map(int,input().split()))
a_m = max(a)
tt = [-1] * a_m
tt[0] = 0
ans_l = []

i = 0
while True:
    if tt[a[i]-1] != -1:
        loop = i - tt[a[i]-1]
        k -= tt[a[i]-1]
        break
    tt[a[i]-1] = i + 1
    ans_l.append(a[i])
    i += 1

ans_c = k % loop
print(ans_l[ans_c+tt[a[i]-1]])


### FIXED CODE ###

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

num = 1
li = [1]
flag = [True] * n
flag[0] = False

for i in range(k):
    num = a[num-1]
    if flag[num-1]:
        li.append(num)
        flag[num-1] = False
    else:
        break

d = li.index(num)
ans = (k-d)%(len(li)-d)+d

print(li[ans])
a,b=map(int,input().split())
k=b-a
print(((1+k)*k)//2-b)


### FIXED CODE ###

N = int(input())
if N<1000:
    print("ABC")
elif N>=1000:
    print("ABD")
n, m= map(int, input().split())
high = list(map(int, input().split()))
ans = [0]*n
 
for i in range(m):
    a =list(map(int, input().split()))
    if high[a[0]-1] > high[a[1]-1]:
        if ans[a[0]-1] == 0:
            ans[a[0]-1] = 1
        ans[a[1]-1] = -1
    elif high[a[0]]-1 < high[a[1]-1]:
        if ans[a[1]-1] == 0:
            ans[a[1]-1] = 1
        ans[a[0]-1] = -1
    else:
        ans[a[1]-1] = -1
        ans[a[0]-1] = -1
print(ans.count(0) + ans.count(1))

### FIXED CODE ###

n, m= map(int, input().split())
high = list(map(int, input().split()))
ans = [1]*n

for i in range(m):
    a, b = map(int, input().split())
    if high[a-1] > high[b-1]:
        ans[b-1] = 0
    elif high[a-1] < high[b-1]:
        ans[a-1] = 0
    else:
        ans[a-1] = 0
        ans[b-1] = 0
print(sum(ans))
from collections import defaultdict

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

h = defaultdict(list)
for i in range(M):
    x, y = map(int, input().split())
    h[x-1].append(y-1)

dp = [0]*(N+1)


def dist(v):
    if dp[v] > 0:
        return dp[v]
    dp[v] = 0
    for nv in h[v]:
        dp[v] = max([dp[v], dist(nv)+1])
    return dp[v]


ans = 0
for v in range(N):
    ans = max([ans, dist(v)])

print(ans)


### FIXED CODE ###

from collections import defaultdict
import sys
sys.setrecursionlimit(10**8)

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

h = defaultdict(list)
for i in range(M):
    x, y = map(int, input().split())
    h[x-1].append(y-1)

dp = [0]*N


def dist(v):
    if dp[v] > 0:
        return dp[v]
    dp[v] = 0
    for nv in h[v]:
        dp[v] = max([dp[v], dist(nv)+1])
    return dp[v]


ans = 0
for v in range(N):
    ans = max([ans, dist(v)])

print(ans)
def main():
    n, k = map(int, input().split())

    mod = 10 ** 9 + 7
    fact = [1]
    for i in range(1, 2000):
        fact.append(fact[-1] * i)

    def comb(l, r):
        return fact[l] // fact[r] // fact[l - r]

    for i in range(1, k + 1):
        print((comb(n - k + 1, i) * comb(k - 1, i - 1)) % mod)


if __name__ == "__main__":
    main()


### FIXED CODE ###

def main():
    n, k = map(int, input().split())

    mod = 10 ** 9 + 7
    fact = [1]
    for i in range(1, 2001):
        fact.append(fact[-1] * i)

    def comb(l, r):
        return fact[l] // fact[r] // fact[l - r]

    for i in range(1, k + 1):
        print((comb(n - k + 1, i) * comb(k - 1, i - 1)) % mod)


if __name__ == "__main__":
    main()
n = int(input())
l = list(map(int, input().split()))
l = set(l)
#print(l)

from itertools import combinations
a = list(combinations(l, n-1))
#print(a)

from fractions import gcd
from functools import reduce

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

g = []
for i in range(len(a)):
    g.append(gcd_list(a[i]))

print(max(g))

### FIXED CODE ###

n = int(input())
l = list(map(int, input().split()))
#print(l)
l2 = list(reversed(l))
#print(l2)
#from itertools import combinations
#a = list(combinations(l, n-1))
#print(a)
from fractions import gcd
L, R = [0], [0]
for i in range(n):
    L.append(gcd(L[i],l[i]))
    R.append(gcd(R[i],l2[i]))
#print(L)
R = list(reversed(R))
#print(R)
g = []
for j in range(n):
    g.append(gcd(L[j],R[j+1]))
print(max(g))


#from functools import reduce

#def gcd_list(numbers):
#    return reduce(gcd, numbers)
n,k=int(input())
l=list(map(int,input().split()))
l.sort()
s=0
for i in range(k):
    s+=l[i]
print(s)
    

### FIXED CODE ###

n,k=map(int,input().split())
l=list(map(int,input().split()))
l1 = sorted(l, reverse=True)
s=0
for i in range(k):
    s+=l1[i]
print(s)
l = input()
volume = l/3**3
print(volume)

### FIXED CODE ###

l = int(input())
volume = (l/3)**3
print(volume)
import math

A,B,H,M =int(input()),int(input()),int(input()),int(input())
if 1<=A<=1000 and 1<=B<=1000 and 0<=H<=11 and 0<=M<=59:
    hw=(2*math.pi)/12
    mw=(2*math.pi)/60
    aw=hw*H+(hw/60)*M
    bw=mw*M
    rad=abs(bw-aw)
    print(math.sqrt(A**2+B**2-2*A*B*math.cos(rad)))
else: 
    print("各値の条件は次の通り:1<=A,B<=1000,0<=H<=11,0<=M<=59")
    print("あなたの入力:A={},B={},H={},M={}".format(A,B,H,M))

### FIXED CODE ###

import math

A,B,H,M =map(int, input().split())
if 1<=A<=1000 and 1<=B<=1000 and 0<=H<=11 and 0<=M<=59:
    hw=(2*math.pi)/(12*60*60) #時針の角速度[rad/s]
    mw=(2*math.pi)/(60*60) #分針の角速度[rad/s]
    time_h=H*60*60 #Hour時間[s] 
    time_m=M*60 #Min時間[s]
    aw=hw*(time_h+time_m) #Arad[rad] #最後の鬼門だった！！なるほどね！40min経ってる間に時針も進んでるから。。
    bw=mw*time_m #Brad[rad]
    rad=abs(bw-aw)
    # 正弦定理で出力結果を得る(a^2=b^2+c^2-2bccosθ)
    print(math.sqrt(A**2+B**2-2*A*B*math.cos(rad)))
    #確認用
    #print(time_h,time_m,aw,bw,rad) 
else: 
    print("各値の条件は次の通り:1<=A,B<=1000,0<=H<=11,0<=M<=59")
    print("あなたの入力:A={},B={},H={},M={}".format(A,B,H,M))
A,B,K = map(int,input().split())
tmp1 = list(range(A,A+min([len(list(range(A,B+1))),K])))
tmp2 = list(range(B-min([len(list(range(A,B+1))),K])+1,B+1))
ans = sorted(list(set(tmp1+tmp2)))
for i in range(len(ans)):
    print(ans[i])

### FIXED CODE ###

A,B,K = map(int,input().split())
if A == B:
    print(A)
else:
    if K > B - A:
        K = B - A
    tmp1 = list(range(A,A+K))
    tmp2 = list(range(B-K+1,B+1))
    ans = sorted(list(set(tmp1 + tmp2)))
    for i in ans:
        print(i)
import numpy as np
N, K = map(int,input().split())
H = np.array([int(input()) for _ in range(0, N)])
H = np.sort(H)
#print(H)
H_diff = abs(H[1:]-H[:-1])
#print(H_diff)
best = np.sum(H_diff[0, K-1])
for i in range(0, len(H_diff)-K+2):
    #print(i)
    if np.sum(H_diff[i:i+K-1]) < best:
        #print(H_diff[i:i+K-1])
        best = np.sum(H_diff[i:i+K-1])
#print('best:{}'.format(best))
print(best)

### FIXED CODE ###

import numpy as np
N, K = map(int,input().split())
H = np.array([int(input()) for _ in range(0, N)])
H = np.sort(H)
H_diff = np.diff(H)
best = int(np.min(np.convolve((H_diff), np.ones(K-1), mode='valid')))
print(best)
import itertools
N = int(input())
N_list = [i+1 for i in range(N)]
cumsum = list(itertools.accumulate(N_list))
aa = cumsum[-1]
t_list = [i for i in N_list if i%3 == 0 or i%5 == 0]
acumsum = list(itertools.accumulate(t_list))[-1]
print(aa - acumsum)

### FIXED CODE ###

import itertools
N = int(input())
N_list = [i+1 for i in range(N)]
cumsum = list(itertools.accumulate(N_list))
aa = cumsum[-1]
t_list = [i for i in N_list if i%3 == 0 or i%5 == 0]
if len(t_list) != 0:
    acumsum = list(itertools.accumulate(t_list))[-1]
else:
    acumsum = 0
print(aa - acumsum)
from collections import deque
n=int(input())
a=[list(map(lambda x:int(x)-1,input().split())) for _ in range(n)]
g = [[[] for _ in range(n)] for _ in range(n)]
h=[[0]*n for _ in range(n)]
for i in range(n):
	for j in range(1,n-1):
		maf = max(i,a[i][j-1])
		mif = min(i,a[i][j-1])
		mat = max(i,a[i][j])
		mit = min(i,a[i][j])
		g[mif][maf].append([mit,mat])
		h[mit][mat] += 1

st = deque([])
sj = deque([])
for i in range(n):
	for j in range(i+1,n):
		if h[i][j]==0:
			st.append([i,j])
			sj.append([i,j])
ans=[]
while(st):
	f = st.popleft()
	ans.append(f)
	for mi,ma in g[f[0]][f[1]]:
		h[mi][ma]-=1
		if h[mi][ma] == 0:
			st.append([mi,ma])

if len(ans)!=n*(n-1)//2:
	print(-1)
	exit()

dp = [[0]*n for _ in range(n)]
def dfs(x,y):
	if dp[x][y]:
		return dp[x][y]
	if g[x][y]==[]:
		dp[x][y]=1
		return dp[x][y]
	for e in g[x][y]:
		dp[x][y] = max(dfs(e[0],e[1])+1,dp[x][y])
	return dp[x][y]
maxx = 0
for edge in sj:
	maxx = max(maxx,dfs(edge[0],edge[1]))
print(maxx)

### FIXED CODE ###

n=int(input())
a=[[int(x)-1 for x in input().split()] for _ in range(n)]

cnt=0
id=[[0]*n for _ in range(n)]
for i in range(n):
	for j in range(i+1,n):
		id[i][j] = cnt
		cnt+=1
def toid(x,y):
	return id[x][y] if x<y else id[y][x]

for i in range(n):
	for j in range(n-1):
		a[i][j] = toid(i,a[i][j])

nedge = n*(n-1)//2
g=[[]for _ in range(nedge)]
to = [0]*nedge
for i in range(n):
	for j in range(1,n-1):
		g[a[i][j-1]].append(a[i][j])
		to[a[i][j]]+=1

from collections import deque

dp=[1]*nedge
q=deque([])
cnt = 0
for i in range(nedge):
	if to[i]==0:
		q.append(i)
		cnt+=1

ans = 1
while(q):
	e = q.popleft()
	for ne in g[e]:
		dp[ne] = max(dp[ne],dp[e]+1)
		to[ne]-=1
		if to[ne]==0:
			q.append(ne)
			cnt+=1
	ans = max(ans,dp[e])

if cnt != nedge:
	print(-1)
else:
	print(ans)
N = input()
A = list(map(int, input().split()))

tmp = min(A)
ans = 0
while all(a % 2 == 0 for a in A):
    A = all(a/2 for a in A)
    ans += 1
print(ans)

### FIXED CODE ###

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

tmp = min(A)
ans = 0
while all(a % 2 == 0 for a in A):
    A = [a/2 for a in A]
    ans += 1
print(ans)
import sys
sys.setrecursionlimit(200000+10)

N, M, K=map(int, input().split())
AB=[list(map(int, input().split())) for _ in range(M)]
CD=[list(map(int, input().split())) for _ in range(K)]
if M==0:
    print("haha")
else:
    AB.sort(key=lambda x:(x[0], x[1]))
    if K!=0:
        CD.sort(key=lambda x:(x[0], x[1]))

    fr=[[] for _ in range(N)] # friends relation
    br=[[] for _ in range(N)] # block relation

    AB.sort(key=lambda x:(x[0], x[1]))
    CD.sort(key=lambda x:(x[0], x[1]))
    for A, B in AB:
        A-=1
        B-=1
        fr[A].append(B)
        fr[B].append(A)
    for C, D in CD:
        C-=1
        D-=1
        br[C].append(D)
        br[D].append(C)

    counts=[0 for _ in range(N)]
    visited=[False for _ in range(N)]

    def dfs(u, p=-1, nodes=[]):
        visited[u]=True
        for n in nodes:
            if n not in fr[u] and n not in br[u]:
                counts[u]+=1
                counts[n]+=1
        nodes.append(u)
        for v in fr[u]:
            if v==p:
                continue
            if visited[v]:
                continue
            dfs(v, p=u, nodes=nodes)

    for i in range(N):
        if not visited[i]:
            dfs(i, p=-1, nodes=[])

print(*counts)


### FIXED CODE ###

# 小さい方の木を大きい方にくっつける O(logN)
# 経路縮約(メモ化) ならしO(logN)
# 両方やると、ならしO(α(N)) α: カルマン関数

# 実装
# 子: 親のID, 根: -サイズ (非負: 子, 負: 根)
# atcoder ABC 158 解説に詳細
class UnionFind():

    def __init__(self, n=0):
        self.d = [-1 for _ in range(N)] # 経路縮約のためのメモ
    
    def find(self, x): # xが所属するグループの親を返す
        if self.d[x]<0:
            return x
        res = self.find(self.d[x])
        self.d[x] = res # 経路縮約の箇所
        return res
    
    def unite(self, x, y): # x, yが所属するグループを結合する, 結合に成功したらTrue, すでに結合していたらFalse
        # まずx, yをそれぞれの親にする
        x = self.find(x)
        y = self.find(y) 
        if x==y:
            return False
        # xの方が大きい木になるようにする (サイズは負であることに注意)
        if self.d[x] > self.d[y]: 
            x, y = y, x
        self.d[x] += self.d[y]
        self.d[y] = x
        return True
    
    def same(self, x, y): # 同じ集合に属しているかどうかを判定する
        return self.find(x) == self.find(y)
    
    def size(self, x): # xが所属しているグループのサイズを返す
        return -self.d[self.find(x)]

N, M, K=map(int, input().split())
AB=[list(map(int, input().split())) for _ in range(M)]
CD=[list(map(int, input().split())) for _ in range(K)]

uf = UnionFind(N)
deg = [0 for _ in range(N)] # 友達関係にある人の個数(グラフにおける各頂点の次数)を保持
to = [[] for _ in range(N)] # ブロック関係にある人に枝を張る

# 友達関係
for i in range(M):
    a, b = AB[i]
    a-=1
    b-=1
    deg[a]+=1
    deg[b]+=1
    uf.unite(a, b)
# ブロック関係
for i in range(K):
    c, d = CD[i]
    c-=1
    d-=1
    to[c].append(d)
    to[d].append(c)
# 答え
ans=[0 for _ in range(N)]
for i in range(N):
    # 各人(頂点)の所属するグループのサイズから、自分自身と、直接の友達関係を引く
    ans[i]=uf.size(i)-1-deg[i]
    # 各人のブロック関係にある人が同じグループに所属している場合は、答えを-する
    for u in to[i]:
        if uf.same(i, u):
            ans[i]-=1
print(*ans)
a,b,c,d,e,f=map(int,input().split())
q=[[0,0]]
ans=0
while len(q)>0:
  x,y=pop(q)
  if x+y+100*a<=f:
    q.append([x+100*a,y])
  if x+y+100*b<=f:
    q.append([x+100*b,y])
  if y+c<=(x-y)*e/100 and x+y+c<=f:
    q.append([x+c,y+c])
    ans=max(ans,100*(y+c)/(x+y+c))
  if y+d<=(x-y)*e/100 and x+y+d<=f:
    q.append([x+d,y+d])
    ans=max(ans,100*(y+d)/(x+y+d))
print(ans)
    

### FIXED CODE ###

a,b,c,d,e,f=map(int,input().split())
aa=-1
ans=[0,0]
for i in range(0,f+1,a*100):
  for j in range(0,f+1-i,b*100):
    for k in range(0,int(e*(i+j)/100)+1,c):
      for l in range(0,int(e*(i+j)/100)+1-k,d):
        if i+j+k+l>f:
          continue
        if i+j>0 and aa<(k+l)/(i+j+k+l):
          aa=(k+l)/(i+j+k+l)
          ans=[i+j+k+l,k+l]
print(ans[0],ans[1])
n=input()
x=input().split()
print(x.[-1]-x.[0])

### FIXED CODE ###

input()
x=sorted(map(int,input().split()))
print(x[-1]-x[0])
k, a, b = map(int, input().split())
x=k+1
y=0
if b>a:
    c=b-a
    k=k-a-1
    y=c*(k//2-1)+b+(k%2)
print(max(x.y))

### FIXED CODE ###

k, a, b = map(int, input().split())
x=k+1
y=0
if b>a:
    c=b-a
    k-=a-1
    y=c*(k//2-1)+b+(k%2)
print(max(x,y))
a, b = map(int,input().split())
x = a + b
if x % 2 == 0:
    print(s / 2)
else:
    print('IMPOSSIBLE')

### FIXED CODE ###

a, b = map(int,input().split())
x = a + b
if x % 2 == 0:
    print(x // 2)
else:
    print('IMPOSSIBLE')
arr = list(input().split())
print(arr[0].[0] + arr[1].[0] + arr[2].[0])

### FIXED CODE ###

arr = list(input().split())
print(arr[0][0] + arr[1][0] + arr[2][0])
s = input()
k = s[::2]
g = s[1::2]
 
if (k == "R" or "U" or "D") and (g == "L" or "U" or "D":)
  print("Yes")
else:
  print("No")

### FIXED CODE ###

s=input()
if "L" in s[::2] or "R" in s[1::2]:
  print("No")
else:
  print("Yes")
A = input()
B = input()
C = input()

count5 = 0
count7 = 0

if A == 5:
    count5 = count5 + 1
elif A == 7:
    count7 = count7 + 1

if B == 5:
    count5 = count5 + 1
elif B == 7:
    count7 = count7 + 1
if C == 5:
    count5 = count5 + 1
elif C == 7:
    count7 = count7 + 1
    
if count5 == 2 and count7 == 1:
    print("YES")
else:
    print("NO")

### FIXED CODE ###

s = input().split()

count5 = 0
count7 = 0
 
if s[0] == "5":
    count5 = count5 + 1
if s[0] == "7":
    count7 = count7 + 1
if s[1] == "5":
    count5 = count5 + 1
if s[1] == "7":
    count7 = count7 + 1
if s[2] == "5":
    count5 = count5 + 1
if s[2] == "7":
    count7 = count7 + 1
    
if count5 == 2 and count7 == 1:
    print("YES")
else:
    print("NO")
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
string s,t;
ll a[200500], b[200500], pa[200500], pbb[200500];

int main() {
	//freopen("input.txt","r",stdin);
 	//freopen("output.txt","w",stdout);
    int n,m,x,i;
	ll tests=1;
	while (tests--)
	{
		cin >> n >> m >> x;
		for (i = 0; i < n; i++)
		{
			cin >> a[i];
			pa[i+1] = pa[i] + a[i];
		}
		for (i = 0; i < m; i++)
		{
			cin >> b[i];
			pbb[i+1] = pbb[i] + b[i];
		}
		int ans = 0;
		for (i = 0; i <= n; i++)
		{
			if (pa[i] <= x)
			   ans = max(ans, i+(int)(upper_bound(pbb, pbb+m+1, x-pa[i])-pbb-1));
			else
				break;
		}
		cout << ans << endl;
	}
    return 0;
}

### FIXED CODE ###

#dt = {} for i in x: dt[i] = dt.get(i,0)+1
import sys;input = sys.stdin.readline
inp,ip = lambda :int(input()),lambda :[int(w) for w in input().split()]

from bisect import bisect_right as bs
n,m,k = ip()
a = ip()
b = ip()
x = [0]*(n+1)
for i in range(n):
    x[i+1] = x[i]+a[i]
y = [0]*(m+1)
for i in range(m):
    y[i+1] = y[i]+b[i]
ans = 0
for i in range(n+1):
    if x[i] <= k:
        ans = max(ans,i+bs(y,k-x[i])-1)
    else:
        break
print(ans)
n = int(input())
m = set()
while n:
    x = int(input())
    if x in m:
        m.remove(x)
    else:
        m.add(x)
print(len(m))


### FIXED CODE ###

n = int(input())
m = set()
while n:
    x = int(input())
    if x in m:
        m.remove(x)
    else:
        m.add(x)
    n -= 1
print(len(m))
n,k = list(map(int, input().split()))
a = list(map(int, input().split()))

d = 1
b = [d]

for i in range(k):
    d = a[d-1]
    if b[0]==dn:
        break
    else:
        b.append(d)
 
print(b[k%len(b)])


### FIXED CODE ###

a = input()
b = input()
 
if (a==b[:len(a)]):
  print("Yes")
else:
  print("No")

#print(b[:len(a)-1])
a, b = map(int, input().split())
diff = b - a

def generate(n):
    if n == 1:
        return 1
    return generate(n-1) + n

generate(diff) - b

### FIXED CODE ###

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

tower = 0

for i in range(1, b - a + 1):
    tower += i

print(tower - b)
import sys
input = sys.stdin.readline
import math

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

print(int(A*B/math.gcd(A,B)))

### FIXED CODE ###

import sys
input = sys.stdin.readline

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

abs = 1
for i in list(range(1,min(A,B)+1))[::-1]:
    if A%i==0 and B%i==0:
        abs = i
        break

print(int(A*B/abs))
N = int(input())
A = [0 * N]
for i in range(N):
    A[i] = int(input()) - 1 # 配列に対応
index = 0
trials = -1
for i in range(N):
    index = A[index]
    if index == 1:
        trials = i + 1
        break
print(trials)

### FIXED CODE ###

N = int(input())
A = [0] * N
for i in range(N):
    A[i] = int(input()) - 1 # 配列に対応
index = 0
trials = -1
for i in range(N):
    index = A[index]
    if index == 1:
        trials = i + 1
        break
print(trials)
a = list(map(int,input().split(' ')))
A = int(a[0] * a[1])
S=int(2*(a[0] + a[1]))
print(str(A) + ' '+ str(S))


### FIXED CODE ###

a = list(map(int,input().split(' ')))
A = int(a[0] * a[1])
S=int(2*(a[0] + a[1]))
print(str(A) + ' '+ str(S))
N = int(input())
V = list(map(int, input().split()))
C = list(map(int, input().split()))

ans = 0

# 価値 - コスト > 0 のフィルタ
for i in range(N):
    s = V[i] - C[i]
    if s > 0:
        ans += s

print(ans)


### FIXED CODE ###

import math

a,b,t = list(map(int,input().split()))

print(math.floor(t / a) * b)
inf = 10**18
mod = 10**9+7

a,v = map(int, input().split())
b,w = map(int, input().split())
t = int(input())
if v-w == 0:
    print('NO')
if t >= abs(a-b)/(v-w):
    print('YES')
else:
    print('NO')

### FIXED CODE ###

inf = 10**18
mod = 10**9+7

a,v = map(int, input().split())
b,w = map(int, input().split())
t = int(input())
if v-w <= 0:
    print('NO')
else:
    if t >= abs(a-b)/(v-w):
        print('YES')
    else:
        print('NO')
A,B = list(map(int,input().split()))

print(max(0,(A - B*2))

### FIXED CODE ###

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

print(max(0,(A - B*2)))
x,n = map(int,input().split())
if n == 0:
  print(x)
  exit()
p = list(map(int,input().split()))
t = [i for i in range(1,101)]

p.sort()
diff = list(set(t) ^ set(p))

for i in range(len(diff)):
  diff[i] -= x

ans = diff[0]
for i in range(1,len(diff)):
  if abs(ans) > abs(diff[i]):
    ans = diff[i]
    
ans += x
print(ans)

### FIXED CODE ###

x,n = map(int,input().split())
if n == 0:
  print(x)
  exit()
p = list(map(int,input().split()))
t = [i for i in range(0,102)]

p.sort()
diff = list(set(t) ^ set(p))

for i in range(len(diff)):
  diff[i] -= x

ans = diff[0]
for i in range(1,len(diff)):
  if abs(ans) > abs(diff[i]):
    ans = diff[i]
    
ans += x
print(ans)
import numpy as np
n, m = map(int, raw_input().split())
 
a = [[0]*m for i in xrange(n)]
 
b = [0]*m
 
for i in xrange(n):
    tmp = map(int, raw_input().split())
    for j in xrange(m):
        a[i][j] = tmp[j]
for i in xrange(m):
    b[i] = input()
for i in xrange(n):
    tmp = 0
    for j in xrange(m):
        tmp += a[i][j] * b[j]
    print tmp

### FIXED CODE ###

n, m = map(int, raw_input().split())
 
a = [[0]*m for i in xrange(n)]
 
b = [0]*m
 
for i in xrange(n):
    tmp = map(int, raw_input().split())
    for j in xrange(m):
        a[i][j] = tmp[j]
for i in xrange(m):
    b[i] = input()
for i in xrange(n):
    tmp = 0
    for j in xrange(m):
        tmp += a[i][j] * b[j]
    print tmp
input_angle = int(input())
input_length = int(input())

length = input_length.split(' ')
length.sort()
sum = 0

for i in range(input_angle-1):
  sum += length[i]
  
if sum > length[-1]:
  print('Yes')
else:
  print('No')

### FIXED CODE ###

input_angle = int(input())
input_length = input()

_length = input_length.split(' ')
length = [int(l) for l in _length]
length.sort()
sum = 0

for i in range(input_angle-1):
  sum += int(length[i])
  
if int(length[-1]) < sum:
  print('Yes')
else:
  print('No')
import math


def inputIntList():
    return [int(s) for s in input().split()]


def inputInt():
    return int(input())


def main():
    N = inputInt()
    A = inputIntList()

    pattern = [0] * 4
    pattern[0] = 3

    ret = 1
    for a in A:
        ret *= pattern[a]
        pattern[a] -= 1

        pattern[a + 1] += 1
        # print(pattern)
    return ret


if __name__ == "__main__":
    print(main())


### FIXED CODE ###

import math


def inputIntList():
    return [int(s) for s in input().split()]


def inputInt():
    return int(input())


def main():
    N = inputInt()
    A = inputIntList()

    pattern = [0 for _ in range(N + 1)]
    pattern[0] = 3

    ret = 1
    for a in A:
        ret *= pattern[a]
        pattern[a] -= 1
        pattern[a + 1] += 1
        # print(pattern)
    return ret % 1000000007


if __name__ == "__main__":
    print(main())
n=list(input())

if (n[3]==n[4] and n[5]==n[6])
    print("Yes")
else:
    print("No")
    


### FIXED CODE ###

n=list(input())

if n[2]==n[3] and n[4]==n[5]:
    print("Yes")
else:
    print("No")
r = input()
g = input()
print(2*g - r)

### FIXED CODE ###

r = int(input())
g = int(input())
print(int(2*g - r))
n,k = map(int,input().split())
a = input().split()
b = [0]*n
d = {}
ind = 1
num = 0
while True:
    if b[ind-1] == 0:
        b[ind-1] = -1
        d[ind] = num
        num += 1
        ind = int(a[ind-1])
    else:
        loop = num-d[ind]
        sup = d[ind]
        break


for i in range((k-sup)%loop):
    ind = int(a[ind-1])
print(int(a[ind]))

### FIXED CODE ###

N, K = map(int, input().split())
A = list(map(int, input().split()))
# = [int(input()) for i in range(N)]
# = [list(map(int, input().split())) for i in range(N)]
next = 1
List = [-1]*N
 
for i in range(K):
    if List[next-1] == -1:
        List[next-1] = i
        next = A[next-1]
 
    else:
        loop = i - List[next-1]
        afterloop = (K-(i-loop))%loop
        print(List.index((i-loop) + afterloop)+1)
        exit()
 
print(next)
x = input()
y = input()
ans = 0
for i in range(len(x)):
  for j in range(len(y)):
    if i == j:
      if li[i] == li[j]:
        ans += 1
print(ans)


### FIXED CODE ###

x = input()
y = input()
ans = 0
for i in range(len(x)):
  for j in range(len(y)):
    if i == j:
      if x[i] == y[j]:
        ans += 1
print(ans)