Harryxun/stf_run huggingface dataset:
N= int(input())
words=[]
words.append(input())
ans="Yes"
for i in range(1,N):
    next=input()
    for word in words:
        if (next==word or  words[i-1][-1]==next[0]):
            ans = "No"
            break
        else:
            words.append(next)
print(ans)

### FIXED CODE ###

#print#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
from collections import Counter
def resolve():
    N,=pin()
    s=set()
    prev=""
    for i in range(N):
        temp=input()
        if temp in s:
            print("No")
            return
        if i>0 and temp[0]!=prev[-1]:
            print("No")
            return
        s.add(temp)
        prev=temp
    print("Yes")
#%%submit!
resolve()
N=input()
S=input()
T=input()

strings=[]
for i in range(int(N)):
    strings.append(S[i]+T[i])
    
print(''.join(strings))

### FIXED CODE ###

N=input()
S,T=input().split()
strings=[]
for i in range(int(N)):
    strings.append(S[i]+T[i])
print(''.join(strings))
from collections import defaultdict


class UnionFind:
    def __init__(self, n):
        self.root = list(range(n + 1))
        self.size = [1] * (n + 1)

    def find(self, x):
        root = self.root
        while root[x] != x:
            root[x] = root[root[x]]
            x = root[x]
        return x

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        sx, sy = self.size[x], self.size[y]
        if sx < sy:
            self.root[x] = y
            self.size[y] += sx
        else:
            self.root[y] = x
            self.size[x] += sy


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


uf = UnionFind(n)

friends = defaultdict(set)
block = defaultdict(set)
chain = defaultdict(set)

for _ in range(m):
    a, b = map(int, input().split())
    friends[a].add(b)
    friends[b].add(a)
    uf.union(a, b)

for _ in range(k):
    c, d = map(int, input().split())
    block[c].add(d)
    block[d].add(c)

for i in range(1, n + 1):
    for j in range(1, n + 1):
        if uf.find(i) == uf.find(j):
            chain[i].add(j)
            chain[j].add(i)

ans = []
for i in range(1, n + 1):
    ans.append(len(chain[i] - friends[i] - block[i] - 1))

print(*ans)

### FIXED CODE ###

class UnionFind:
    def __init__(self, n):
        self.ps = [-1] * (n + 1)

    def find(self, x):
        if self.ps[x] < 0:
            return x
        else:
            self.ps[x] = self.find(self.ps[x])
            return self.ps[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return False
        if self.ps[x] > self.ps[y]:
            x, y = y, x
        self.ps[x] += self.ps[y]
        self.ps[y] = x
        return True

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        x = self.find(x)
        return -self.ps[x]


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


uf = UnionFind(n)

friends = [0] * (n + 1)
chain = [0] * (n + 1)

for _ in range(m):
    a, b = map(int, input().split())
    friends[a] += 1
    friends[b] += 1
    uf.union(a, b)

for _ in range(k):
    c, d = map(int, input().split())
    if uf.same(c, d):
        friends[c] += 1
        friends[d] += 1

ans = []
for i in range(1, n + 1):
    ans.append(uf.size(i) - friends[i] - 1)

print(*ans)
ary = list(map(int, input().split())).sort()

print(ary[0])

### FIXED CODE ###

ary=list(map(int, input().split()))
ary.sort()
print("{} {} {}".format(ary[0], ary[1], ary[2]))
n = int(input())
l = list(map(int, input().split()))

l0 = []
l1 = []
for i in range(n):
    if i%2==0:
        l0.append(l[i])
    else:
        l1.append((l[i]))

l0.sort()
l1.sort()

# print(l0)
# print(l1)

memo0 = [[1, l0[0]]]
memo1 = [[1, l1[0]]]
for i in range(1, n//2):
    if memo0[-1][1] == l0[i]:
        memo0[-1][0] += 1
    else:
        memo0.append([1, l0[i]])

    if memo1[-1][1] == l1[i]:
        memo1[-1][0] += 1
    else:
        memo1.append([1, l1[i]])

memo0.sort(reverse=True)
memo1.sort(reverse=True)

# print(memo0)
# print(memo1)

if memo0[0][1]!=memo1[0][1]:
    print(n-memo0[0][0]-memo1[0][0])
elif len(memo0)==1 and len(memo1)==1:
    print(n//2)
elif len(memo0)==1:
    print(n-memo0[0][0]-memo1[1][0])
elif len(memo1)==1:
    print(n-memo1[1][0]-memo1[0][0])
else:
    print(n-max(memo0[0][0]+memo1[1][0], memo1[1][0]+memo1[0][0])/0)

### FIXED CODE ###

n = int(input())
l = list(map(int, input().split()))

l0 = l[::2]
l1 = l[1::2]

l0.sort()
l1.sort()

# print(l0)
# print(l1)

memo0 = [[1, l0[0]]]
memo1 = [[1, l1[0]]]
for i in range(1, n//2):
    if memo0[-1][1] == l0[i]:
        memo0[-1][0] += 1
    else:
        memo0.append([1, l0[i]])

    if memo1[-1][1] == l1[i]:
        memo1[-1][0] += 1
    else:
        memo1.append([1, l1[i]])

memo0.sort(reverse=True)
memo1.sort(reverse=True)

memo0.append([0, -1])
memo1.append([0, -1])

# print(memo0)
# print(memo1)

if memo0[0][1]!=memo1[0][1]:
    print(n-memo0[0][0]-memo1[0][0])
else:
    ans1 = n- memo0[0][0]-memo1[1][0]
    ans2 = n- memo0[1][0]-memo1[0][0]
    print(min(ans1, ans2))
X, Y, Z = map(int, input().split())
ans = 1
length = Y+2Z
while True:
    if length > X:
        print(ans)
        break
    count += 1
    length += Y+Z


### FIXED CODE ###

X, Y, Z = map(int, input().split())
ans = 1
length = Y+2*Z
while True:
    if length+Y+Z > X:
        print(ans)
        break
    ans += 1
    length += Y+Z
S = input()

def dfs(p,a):
  if p == len(S):
    return 0
  if a > 0 and S[p] == 'g':
    return max(1+dfs(p+1,a-1),dfs(p+1,a+1))
  elif a > 0 and S[p] == 'p':
    return max(dfs(p+1,a-1),-1+dfs(p+1,a+1))
  elif a == 0 and S[p]  == 'g':
    return dfs(p+1,a+1)
  else:
    return -1+dfs(p+1,a+1)

print(dfs(0,0))

### FIXED CODE ###

S = input()

A = 'gp' * (len(S)//2)
if len(S) % 2 == 1:
  A += 'g'
ans = 0
for i in range(len(S)):
  if S[i] == 'p' and A[i] == 'g':
    ans -= 1
  elif S[i] == 'g' and A[i] == 'p':
    ans += 1
print(ans)
N, P = map(int, input().split())
S = input()
counter=0
def power_func(a,b,p):
	if b==0:
		return 1
    if b%2==0:
		d=power_func(a,b//2,p)
		return d*d %p
	if b%2==1:
		return (a*power_func(a,b-1,p ))%p
if P==2:
    counter = 0
    for i in range(len(S)):
        if S[i] in ['2','4','6','8','0']:
            counter+=i+1
elif P==5:
    counter = 0
    for i in range(len(S)):
        if S[i] in ['5','0']:
            counter+=i+1
else:
    list_a=[0]*P
    list_a[0]+=1
    temp=0
    for i in range(N):
      	M = power_func(10,N-i,P)
        temp=(int(S[i])*M+temp)%P
        counter+=list_a[temp]
        list_a[temp]+=1
print(counter)

### FIXED CODE ###

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

counter=0
def power_func(a,b,p):
    if b==0:
        return 1
    elif b%2==0:
        d=power_func(a,b//2,p)
        return d*d %p
    elif b%2==1:
        return (a*power_func(a,b-1,p ))%p
if P==2:
    counter = 0
    for i in range(len(S)):
        if S[i] in ['2','4','6','8','0']:
            counter+=i+1
elif P==5:
    counter = 0
    for i in range(len(S)):
        if S[i] in ['5','0']:
            counter+=i+1
else:
    list_a=[0]*P
    list_a[0]+=1
    temp=0
    for i in range(N):
        M = power_func(10,N-i,P)
        temp=(int(S[i])*M+temp)%P
        counter+=list_a[temp]
        list_a[temp]+=1
print(counter)
import numpy as np
n, m = [int(i) for i in input().split()]

e = np.zeros([n,n])



for _ in range(m):
    a, b = [int(i) for i in input().split()]
    e[a-1,b-1] = b-1
    e[b-1,a-1] = a-1

ans = np.ones(n-1)
next_cand = [0]
cout = 0
check = np.zeros(n-1)
for next_ in next_cand:
    connec = np.array([j for j in e[next_,:] if j !=0])
    for i in connec:
        i = int(i)
        if check[i-1] == 0:
            check[i-1] = 1
            cout +=1
            ans[i-1] = next_ +1
            next_cand.append(i)
            e[next_,:] = 0
            e[:,next_] = 0


print('Yes')

for i in ans:
    print(int(i))

### FIXED CODE ###

import numpy as np
from collections import deque
n, m = [int(i) for i in input().split()]

e = [ [] for i in range(n)]



for _ in range(m):
    a, b = [int(i) for i in input().split()]
    e[a-1].append(b-1)
    e[b-1].append(a-1)
    
    
q = deque()
q.append(0)
ans = np.ones(n-1)
check = np.zeros(n)

while len(q) > 0:
    # キューの先頭（左端）からnodeを取り出す
    node = q.popleft()

    if node is not None:
        check[node] = 2
        con = e[node]
        for i in con:
            if check[i] ==0:
                ans[i-1] = int(node) + 1
                q.append(i)
                check[i] = 1

        

print('Yes')

for i in ans:
    print(int(i))
n=int(input())
S=6
N=9
lst=[]
cnt=0
for i in range(16667):
  S*=6
  N*=9
  lst.append(S)
  lst.append(N)
while n>5:
  for i in len(lst):
    if lst[i]>n:
      n-=lst[i-1]
      cnt+=1
      break
print(cnt+n)


### FIXED CODE ###

n=int(input())
dp=[0]*100010

for i in range(1,100010):
  dp[i]=float('inf')
  
for i in range(1,100010):
  power6=1
  while power6<=i:
    dp[i]=min(dp[i-power6]+1,dp[i])
    power6*=6
  power9=1
  while power9<=i:
    dp[i]=min(dp[i-power9]+1,dp[i])
    power9*=9

print(dp[n])
n = int(input())
t = list(map(int,input().split()))
m = int(input())
for i in range(m):
    p,x = map(int,input().split())
print(sum[t]-t[p-1]+x)

### FIXED CODE ###

n = int(input())
t = list(map(int,input().split()))
m = int(input())
for i in range(m):
    p,x = map(int,input().split())
    print(sum(t)-t[p-1]+x)
while True:
    a,op,b=input().split()
    a,b=map(int,(a,b))        
    if op=='?':
        None
    elif op=='+':
        print(str(int(a+b)))
    elif op=='-':
        print(str(int(a-b)))
    elif op=='*':
        print(str(int(a*b)))
    else:
        print(str(int(a//b)))

### FIXED CODE ###

while True:
    a,op,b=input().split()
    a,b=map(int,(a,b))
    if op=='?':
        break
    elif op=='+':
        print(str(int(a+b)))
    elif op=='-':
        print(str(int(a-b)))
    elif op=='*':
        print(str(int(a*b)))
    else:
        print(str(int(a//b)))
a,b,c,d = map(int, input().split())
print(min([a,b])+min([c,d]))

### FIXED CODE ###

wk = [int(input()) for i in range(4)]
print(min(wk[0], wk[1])+min(wk[2], wk[3]))
h,n=map(int,input().split())
ab=[list(int,input().split()) for _ in range(n)]

max_a=max(a for a,_ in ab)

for i in range(0,h+max_a):
    if i==0:
        d[i]=0
    else:
        dp[i]=min(dp[i-a]+b for a,b in ab)
print(min(dp[h:])


### FIXED CODE ###

h, n = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]

max_a = max(a for a, _ in ab)
dp = [0] * (h+max_a)

for i in range(0, h+max_a):
    if i <= 0:
        dp[i] = 0
    else:
        dp[i] = min(dp[i-a] + b for a,b in ab) 

print(min(dp[h:]))
def solve(g):
    dp = [-1]*len(g)
    def _solve(f):
        if dp[f] == -1:
            sol = 0
            for c in g[f]:
                sol = max(sol, 1 + _solve(c))
            dp[f] = sol
        return dp[f]
    for f in range(len(g)):
        _solve(f)
    return max(dp)

n, m = map(int, input().split())
g = [[] for _ in range(n)]
for _ in range(m):
    f, t = map(int, input().split())
    g[f-1].append(t-1)

print(solve(g))

### FIXED CODE ###

import sys
sys.setrecursionlimit(10000)

def solve(g):
    dp = [-1]*len(g)
    def _solve(f):
        if dp[f] == -1:
            dp[f] = 0
            for c in g[f]:
                dp[f] = max(dp[f], 1 + _solve(c))
        return dp[f]
    for f in range(len(g)):
        _solve(f)
    # print(dp)
    return max(dp)

n, m = map(int, input().split())
g = [[] for _ in range(n)]
for _ in range(m):
    f, t = map(int, input().split())
    g[f-1].append(t-1)

print(solve(g))
import sys
input = sys.stdin.readline

n,m = map(int, input().split())
t = sorted([tuple(map(int, input().split())) for i in range(m)])
INF = 10 ** 18
dp = [0] + [INF] * (n-1) # 頂点1から、各頂点(1~n)までの最短距離
for l,r,c in t:
  for i in range(r,l,-1):
    if dp[l] + c < dp[i]:
      dp[i] = dp[l] + c
    else:
      break
ans = dp[n-1]
if ans == INF:
  print(-1)
else:
  print(ans)


### FIXED CODE ###

import sys
input = sys.stdin.readline

import heapq
N,M = map(int,input().split())
LRC = [tuple(map(int,input().split())) for i in range(M)]

es = [[] for i in range(N)]
for l,r,c in LRC:
    l,r = l-1,r-1
    es[l].append((r,c))
for i in range(N-1):
    es[i+1].append((i,0))

INF = 10 ** 18
dist = [INF]*N
dist[0] = 0
hq = [(0,0)]
heapq.heapify(hq)

while(hq):
    d,v = heapq.heappop(hq)
    if v==N-1:
        print(d)
        exit()
    for to,c in es[v]:
        if d+c >= dist[to]: continue
        dist[to] = d+c
        heapq.heappush(hq, (d+c, to))
print(-1)
N, L, T = map(int, input().split())
n = [[*map(int, input().split())] for _ in range(N)]
t = [X + (0, T, -T)[W] for X, W in n]
x = sorted(i % L for i in t)
s = sum(i // L for i in t) % N
for i in x[s:] + x[:s]: print(i)

### FIXED CODE ###

N, L, T = map(int, input().split())
n = [list(map(int, input().split())) for _ in range(N)]
t = [X + (0, T, -T)[W] for X, W in n]
l = sorted(i % L for i in t)
s = sum(i // L for i in t) % N
for i in l[s:] + l[:s]: print(i)
s, t = [input() for _ in range(2)]
jprint('Yes' if sorted(s) < sorted(t, reverse=True) else 'No')

### FIXED CODE ###

s, t = [input() for _ in range(2)]
print('Yes' if sorted(s) < sorted(t, reverse=True) else 'No')
count = 0
for _ in range(int(input())):
    n = int(input())
    count += 1 if (mod(2, n-1, n) == 1) else 0
print(count)


### FIXED CODE ###

f=lambda x: 1 if x == 2 or x == 3 or (x>3 and x&1==1 and pow(2, x-1, x)==1) else 0
print(sum(f(int(input())) for _ in range(int(input()))))
N=map(int,input().split())
count=0
while N<=0:
  if N%2!=0
  	count+=1
  else:
    pass
print(count//len(N))

### FIXED CODE ###

N = int(input())
count = 0
 
for i in range(1,N+1):
    if i % 2 == 1:
        count += 1

print(count/N)
mod = 10**9+7
N = int(input())
A = list(map(int, input().split()))
n = max(A).bit_length()
S = [0]*N
for i, a in enumerate(A):
    S[i]=S[i-1]^a
index = [[-1] for _ in range(2<<n)]
cumsum = [0]*(N+1)
for i, s in enumerate(S):
    index[s].append(i)
    cumsum[i] = cumsum[i-1]
    if s == 0:
        cumsum[i]+=1
ans = 0
if S[-1] == 0:
    print(1/0)
    for i in range(1, 1<<n):
        l = len(index[i])
        if l == 1:
            continue
        dp = [0]*(l-1)
        dp_cum = [0]*(l-1)
        for j, k in enumerate(index[i][1:]):
            dp[j] = (dp_cum[j-1]*(cumsum[k]-cumsum[index[i][j]])+1)%mod
            dp_cum[j] = (dp_cum[j-1]+dp[j])%mod
        ans+=dp_cum[-1]
        ans%=mod
    ans+=pow(2, cumsum[N-1]-1, mod)
    ans%=mod
else:
    l = len(index[S[-1]])
    dp = [0]*(l-1)
    dp_cum = [0]*(l-1)
    for j in range(l-1):
        k = index[S[-1]][j+1]
        p = index[S[-1]][j]
        dp[j] = dp_cum[j-1]*(cumsum[k]-cumsum[p])%mod+1
        dp_cum[j] = (dp_cum[j-1]*(cumsum[k]-cumsum[p])+dp[j])%mod
    ans = dp[-1]%mod
print(ans)

        



### FIXED CODE ###

from collections import defaultdict
from bisect import bisect_left as bisect
import sys
mod = 10**9+7
N = int(input())
A = list(map(int, input().split()))
S = [0]*(N+1)
zeros = []
count = defaultdict(list)
now = -1
for i in range(N):
    S[i] = S[i-1]^A[i]
    if S[i] == 0:
        zeros.append(i)
    else:
        count[S[i]].append(i)
if S[N-1] != 0:
    a = S[N-1]
    res = []
    cnt = 0
    for i in count[a]:
        res.append(bisect(zeros, i)-cnt)
        cnt+=res[-1]
    res0 = 1
    res1 = 0
    for c in res:
        res0 = res0+res1*c
        res1 = res1+res0
        res0%=mod
        res1%=mod
    print(res0)
    sys.exit()
ans = pow(2, len(zeros)-1, mod)
for a in count.keys():
    cnt = 0
    res = []
    for i in count[a]:
        res.append(bisect(zeros, i)-cnt)
        cnt+=res[-1]
    res0 = 1
    res1 = 0
    for c in res:
        res0 = res0+res1*c
        res1 = res1+res0
        res0%=mod
        res1%=mod
    ans+=res1
    ans%=mod
print(ans)
from collections import defaultdict, deque
from sys.stdin.buffer import readline

N, M = map(int, readline().split())
dic = defaultdict(list)
par = [i for i in range(N)]
rank = [0]*N
def find(x):
  if par[x]==x:
    return x
  else:
    par[x] = find(par[x])
    return par[x]
def unit(x, y):
  x = find(x)
  y = find(y)
  if x==y:
    return
  elif rank[x]<rank[y]:
    par[x] = y
    return
  elif rank[y]<rank[x]:
    par[y] = x
  else:
    par[y] = x
    rank[x] += 1

for i in range(M):
  l, r, d = map(int, readline().split())
  dic[l-1] += [(r-1,d)]
  dic[r-1] += [(l-1,-d)]
  unit(l-1, r-1)


dist = [-1]*N
m = []
for x in range(N):
  y = find(x)
  m += [(y,0)]
  dist[y] = 0
m = set(m)
stuck = deque(m)
while stuck:
  e, a = stuck.popleft()
  flag = False
  for c in dic[e]:
    p, d = c
    x = d + dist[e]
    if dist[p]==-1:
      dist[p] = x
      stuck += [(p, x)]
    elif dist[p]!=x:
      print('No')
      flag = True
      break
  if flag:
    break
else:
  print('Yes')

### FIXED CODE ###

from collections import defaultdict, deque
N, M = map(int, input().split())
used = [True]*N
dic = defaultdict(list)
for i in range(M):
  l, r, d = map(int,input().split())
  l -= 1
  r -= 1
  used[r] = False
  dic[l] += [(r,d)]

dist = [-1]*N
q = deque([])
for i in range(N):
  if used[i]:
    q += [i]
    dist[i] = 0

ans = True
while q:
  e = q.popleft()
  flag = False
  for p, d in dic[e]:
    if dist[p]==-1:
      dist[p] = d+dist[e]
      q += [p]
    elif dist[p]!=dist[e]+d:
      ans = False
      flag = True
      break
  if flag:
    break
if ans:
  if -1 not in dist:
    print('Yes')
  else:
    print('No')
else:
  print('No')
N, A, B = map(int, input().split())
a = []

while len(a) != N:
    a.append("b" * A)
    a.append("a" * B)

a = "".join(a)

b = a[0: N]

c = b.count("b")
print(c)


### FIXED CODE ###

n,a,b=map(int,input().split())
k=n//(a+b)
mod=n%(a+b)
ans=a*k
if mod >=a:
    ans +=a
else:
    ans +=mod
print(ans)
n = int(input())
d,x = map(int,input(),split())
count += x
a = []
for i in range(n):
  b = int(input())
  a.append(b)
  for j in range(n):
    if 1 + a[i]*j <= n:
      count += 1
print(count)

### FIXED CODE ###

n = int(input())
m, k = [int(_) for _ in input().split()]
    
for i in range(n):
    for j in range(1, m+1, int(input())):
        k += 1
print(k)
N, L = map(int, input().split())
S = [input() for i in range(N)]
s = sorted(S)
print(*s, sep='')

### FIXED CODE ###

A,B,C = map(int, input().split())
if A==5 and B==5 and C==7:
  print("YES")
elif A==5 and B==7 and C==5:
  print("YES")
elif A==7 and B==5 and C==5:
  print("YES")
else:
  print("NO")
a,b=list(map(int,input().split()))
c,d=list(map(int,input().split()))
x=a*b
print(x-a*c-b*)

### FIXED CODE ###

a,b=list(map(int,input().split()))
c,d=list(map(int,input().split()))
x=a*b
print(x-a*d-b*c+c*d)
# -*- coding: utf-8 -*-
import sys
import re
import numpy as np
from itertools import combinations


def answer(l):
    results = []
    for i, j in combinations(l, 2):
        v_a = np.array(i)
        v_b = np.array(j)
        results.append(np.linalg.norm(v_a - v_b))

    print(sum(float.is_integer(i) for i in results))


if __name__ == '__main__':
    rows = re.split('\n', sys.stdin.read())
    args = [list(map(int, row.split(' '))) for row in rows][1:]
    print(answer(args))


### FIXED CODE ###

# -*- coding: utf-8 -*-
import sys
import numpy as np
from itertools import combinations


def answer(l):
    results = []
    for i, j in combinations(l, 2):
        v_a = np.array(i)
        v_b = np.array(j)
        results.append(np.linalg.norm(v_a - v_b))
    return sum(float.is_integer(i) for i in results)


n, d = map(int, input().split())
coodinates = [[int(x) for x in input().split()] for _ in range(n)]
print(answer(coodinates))
import math


def f(n, base):
    X_dumy = base
    lis = []
    while X_dumy > 0:
        lis.append(X_dumy % n)
        X_dumy = int(X_dumy / n)
    return sum(lis)


def solve():
    N, S = int(input()), int(input())
    # print(N, S)

    if N == S:
        return N + 1

    for b in range(2, int(math.sqrt(N)) + 1):
        if f(b, N) == S:
            return b

    largest = N**2
    lowest = largest
    for p in range(1, int(math.sqrt(N)) + 1):
        b = int((N - S) / p + 1)
        if f(b, N) == S:
            lowest = min(lowest, b)

    if not lowest == largest:
        return lowest

    return -1


if __name__ == '__main__':
    res = solve()
    print(res)


### FIXED CODE ###

import math


def f(base, n):
    # 10進数 n を, base 進数に変換して各桁を足し合わせる
    total = 0
    while n > 0:
        # print('除', n // base, 'あまり', n % base)
        total += n % base
        n = n // base
    return total


def solve():
    N, S = int(input()), int(input())
    # print(N, S)

    if N == S:
        return N + 1

    for b in range(2, int(math.sqrt(N)) + 1):
        if f(b, N) == S:
            return b

    largest = N**2
    lowest = largest
    for p in range(1, int(math.sqrt(N)) + 1):
        b = int((N - S) / p + 1)
        if b > 1 and f(b, N) == S:
            lowest = min(lowest, b)

    if not lowest == largest:
        return lowest

    return -1


if __name__ == '__main__':
    res = solve()
    print(res)
N,M=map(int,input().split())
inp=[list(map(int,input().split())) for _ in range(N)]
g=[[] for _ in range(N)]
[g[a-1].append(b-1) for a,b in inp]
[g[b-1].append(a-1) for a,b in inp]

from itertools import permutations
seq=[i for i in range(N)]
test=list(permutations(seq))
cnt=0
for t in test:
    if t[0]==0:
        for i in range(len(t)-1):
            if t[i+1] not in g[t[i]]:
                break
        cnt+=1
print(cnt)

### FIXED CODE ###

N,M=map(int,input().split())
inp=[list(map(int,input().split())) for _ in range(M)]
g=[[] for _ in range(N)]
[g[a-1].append(b-1) for a,b in inp]
[g[b-1].append(a-1) for a,b in inp]
 
from itertools import permutations
seq=[i for i in range(N)]
test=list(permutations(seq))
cnt=0
for t in test:
    if t[0]==0:
        for i in range(N-1):
            if t[i+1] not in g[t[i]]:
                break
        else:
            cnt+=1
print(cnt)
import decimal
n = int(input())
a = list(map(int, input().split()))
ans = decimal.Decimal(1)
if 0 in a:
  print(-1)
else:
  for i in a:
    ans *= i
  if ans < (10 ** 18 + 1):
    print(ans)
  else:
    print(-1)


### FIXED CODE ###

a,b = list(map(int, input().split()))
print(a * b)
a = input()
sum = int(a)
for i in range(len(a)-1):
  sum += int(a[:i]) + int(a[i+1:])
print(int(sum))

### FIXED CODE ###

s = input()
n = len(s) - 1
answers = []
sl = [s[i] for i in range(len(s))]
for i in range(2 ** n):
    tmp = []
    for j in range(n):
        if ((i >> j) & 1):
            tmp.append(j)
    ll = ['*']*len(s)
    for k in tmp:
        ll[k] = '+'
    ans = []
    for k, _ in zip(sl, ll):
        ans.append(k)
        ans.append(_)
    ans = [_ for _ in ans if _ != '*']
    ans = ''.join(ans)
    ans = ans.split('+')
    ans = [int(_) for _ in ans if _ != '+']
    ans = sum(ans)
    answers.append(ans)
print(sum(answers))
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

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

soinsu = [0 for _ in range(1001)]
for i in range(n):
    lst = factorization(a[i])
    for ind, jousu in lst:
        soinsu[ind] = max(soinsu[ind], jousu)

ans = 0
for i in range(n):
    lst = factorization(a[i])
    copied_soinsu = soinsu.copy()
    for ind, jousu in lst:
        copied_soinsu[ind] -= jousu
    bi = 1
    for j in range(1001):
        bi = bi * (j**copied_soinsu[j]) % mod
    ans = (ans + bi) % mod

print(ans)

### FIXED CODE ###

import fractions
from functools import reduce

mod = 10**9 + 7

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

n = int(input())
a = list(map(int, input().split()))
a_ = []
for i in range(n):
    a_.append(pow(a[i], mod - 2, mod))

num_lcm = lcm(*a) % mod
ans = 0
for i in range(n):
    ans = (ans + num_lcm * a_[i] % mod) % mod

print(ans)