CodeEff/ECCO huggingface dataset:
# Original solution
from math import floor, ceil, gcd

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

if a%c == 0: c_m_min = a
else: c_m_min = a + c - a%c
c_m_max = b - b%c
c_cnt = (c_m_max - c_m_min)//c + 1
if c_m_min > b or c_m_max < a : c_cnt = 0

if a%d == 0: d_m_min = a
else: d_m_min = a + d - a%d
d_m_max = b - b%d
d_cnt = (d_m_max - d_m_min)//d + 1
if d_m_min > b or d_m_max < a : d_cnt = 0

cd = c*d//gcd(c,d)
if a%cd == 0: cd_m_min = a
else: cd_m_min = a + cd - a%cd
cd_m_max = b - b%cd
cd_cnt = (cd_m_max - cd_m_min)//cd + 1
if cd_m_min > b or cd_m_max < a : cd_cnt = 0


ans = b - a + 1 - c_cnt - d_cnt + cd_cnt
print(ans)

# Optimized solution
from math import gcd

def lcm(x,y):
    return (x * y) // gcd(x, y)

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

a_cnt = 0
a_cnt = (b//c) - ((a-1)//c)
b_cnt = (b//d) - ((a-1)//d)

lcmab = lcm(c,d)
ab_cnt = (b//lcmab) - ((a-1)//lcmab)

ans = (b-a+1) - a_cnt -b_cnt + ab_cnt
print(ans)
# Original solution
#@k0gane_p 
a, b, c, d = [int(i) for i in input().split()]
def gcd(x,y):#最大公約数
    while y:
        x,y = y, x%y
    return x
def lcm(x,y):#最小公倍数
    return x*y // gcd (x,y)
def count(A,B,C):#A以下で、BでもCでも割り切れない個数
    D=A//B
    E=A//C
    F=A // lcm(B,C)
    return A-D-E+F
ans = count(b, c, d) - count(a, c, d)
#A以上B以下の整数のうち、CでもDでも割り切れないものの個数
if(a % c != 0 and a % d != 0):
    ans += 1#AがCでもDでも割り切れないなら、足す１
print(ans)

# Optimized solution
#@k0gane_p 
a, b, c, d = [int(i) for i in input().split()]
def gcd(x,y):#最大公約数
    while y:
        x,y = y, x%y
    return x
def lcm(x,y):#最小公倍数
    return x*y // gcd (x,y)
def count(A,B,C):#A以下で、BでもCでも割り切れない個数
    D=A//B
    E=A//C
    F=A // lcm(B,C)
    return A-D-E+F
ans = count(b, c, d) - count(a-1, c, d)
#A以上B以下の整数のうち、CでもDでも割り切れないものの個数
#if(a % c != 0 and a % d != 0):
    #ans += 1#AがCでもDでも割り切れないなら、足す１
print(ans)
# Original solution
#@k0gane_p 
a, b, c, d = [int(i) for i in input().split()]
def gcd(x,y):#最大公約数
    while y:
        x,y = y, x%y
    return x
def lcm(x,y):#最小公倍数
    return x*y // gcd (x,y)
def count(A,B,C):#A以下で、BでもCでも割り切れない個数
    D=A//B
    E=A//C
    F=A // lcm(B,C)
    return A-D-E+F
ans = count(b, c, d) - count(a-1, c, d)
#A以上B以下の整数のうち、CでもDでも割り切れないものの個数
#if(a % c != 0 and a % d != 0):
    #ans += 1#AがCでもDでも割り切れないなら、足す１
print(ans)

# Optimized solution
#@k0gane_p 
a, b, c, d = [int(i) for i in input().split()]
def gcd(x,y):#最大公約数
    while y:
        x,y = y, x%y
    return x
def lcm(x,y):#最小公倍数
    return x*y // gcd (x,y)
def count(A,B,C):#A以下で、BでもCでも割り切れない個数
    D=A//B
    E=A//C
    F=A // lcm(B,C)#Fは両方で割り切れる、最小公倍数で割り切れる
    return A-D-E+F#包除原理
ans = count(b, c, d) - count(a-1, c, d)
#A以上B以下の整数のうち、CでもDでも割り切れないものの個数
#Aを引く１することで、A以上が分かる
#if(a % c != 0 and a % d != 0):
    #ans += 1#AがCでもDでも割り切れないなら、足す１
print(ans)
# Original solution
#!/usr/bin/env python3
import sys
import math
import decimal
import itertools
from itertools import product
from functools import reduce
def input():
    return sys.stdin.readline()[:-1]
def sort_zip(a:list, b:list):
    z = list(zip(a, b))
    z = sorted(z)
    a, b = list(zip(*z))
    a = list(a)
    b = list(b)
    return a, b

def warikirenai(n, warukazu):
    return n - n // warukazu
def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)
def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def main():
    A, B, C, D = list(map(int, input().split()))

    ansA = 0
    ansA += warikirenai(A - 1, C)
    ansA += warikirenai(A - 1, D)
    ansA -= warikirenai(A - 1, lcm(C, D))

    ansB = 0
    ansB += warikirenai(B, C)
    ansB += warikirenai(B, D)
    ansB -= warikirenai(B, lcm(C, D))

    print((ansB - ansA))


if __name__ == '__main__':
    main()


# Optimized solution
#!/usr/bin/env python3
import sys
import math
import decimal
import itertools
from itertools import product
from functools import reduce
def input():
    return sys.stdin.readline()[:-1]
def sort_zip(a:list, b:list):
    z = list(zip(a, b))
    z = sorted(z)
    a, b = list(zip(*z))
    a = list(a)
    b = list(b)
    return a, b


def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)
def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)
def warikirenai(n, c, d):
    num =  n - n // c
    num += n - n // d
    num -= n - n // lcm(c, d)
    return num

def main():
    A, B, C, D = list(map(int, input().split()))

    print((warikirenai(B, C, D) - warikirenai(A - 1, C, D)))


if __name__ == '__main__':
    main()
# Original solution
import sys
from collections import Counter, deque, defaultdict
from itertools import accumulate, permutations, combinations, takewhile, compress, cycle
from functools import reduce
from math import ceil, floor, log10, log2, factorial
from pprint import pprint

sys.setrecursionlimit(1000000)
# MOD = 10 ** 9 + 7
# N = int(input())
# A = [int(x) for x in input().split()]
# V = [[0] * 100 for _ in range(100)]
# A = [int(input()) for _ in range(N)]

A, B, C, D = [int(x) for x in input().split()]


def gcd(x, y):
    while (y):
        x, y = y, x % y
    return x


def lcm(x, y):
    return (x * y) // gcd(x, y)


def f(a, b, c):
    if a % c == 0:
        a1 = a // c
    else:
        a1 = a // c + 1
    b1 = b // c
    r = b1 - a1 + 1
    return r


# c = (B - A + 1) // C
# d = (B - A + 1) // D
# cd = (B - A + 1) // (C * D)

c = f(A, B, C)
d = f(A, B, D)
cd = f(A, B, lcm(C, D))

n = B - A + 1
print((n - c - d + cd))


# Optimized solution
import sys
from collections import Counter, deque, defaultdict
from itertools import accumulate, permutations, combinations, takewhile, compress, cycle
from functools import reduce
from math import ceil, floor, log10, log2, factorial
from pprint import pprint

sys.setrecursionlimit(1000000)
# MOD = 10 ** 9 + 7
# N = int(input())
# A = [int(x) for x in input().split()]
# V = [[0] * 100 for _ in range(100)]
# A = [int(input()) for _ in range(N)]

A, B, C, D = [int(x) for x in input().split()]


def gcb(a, b):
    # a, b = max([a, b]), min([a, b])
    return a if b == 0 else gcb(b, a % b)


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


g = lcm(C, D)
c = B // C - (A - 1) // C
d = B // D - (A - 1) // D
cd = B // g - (A - 1) // g

print((B - A + 1 - c - d + cd))
# Original solution
import sys
from math import pi

def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while a % b > 0:
        a, b = b, a % b
    return b

def solve():
    input = sys.stdin.readline
    A, B, C, D = list(map(int, input().split()))
    cDiv = (B // C) - ((A - 1) // C)
    dDiv = (B // D) - ((A - 1) // D)
    cd = C * D // gcd(C, D)
    cdDiv = (B // cd) - ((A - 1) // cd)
    print(((B - A + 1) - (cDiv + dDiv - cdDiv)))
    

    return 0

if __name__ == "__main__":
    solve()

# Optimized solution
import sys

def lcm(a, b):
    a, b = max(a, b), min(a, b)
    c = a * b
    while a % b > 0:
        a, b = b, a % b
    return c // b

def solve():
    input = sys.stdin.readline
    A, B, C, D = list(map(int, input().split()))
    divC = B // C - (A - 1) // C
    divD = B // D - (A - 1) // D
    cd = lcm(C, D)
    divCD = B // cd - (A - 1) // cd
    print((B - A + 1 - (divC + divD - divCD)))


    return 0

if __name__ == "__main__":
    solve()
# Original solution
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a

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

a,b,c,d=list(map(int,input().split()))
a-=1
b_1=b//c
b_1+=b//d
b_1-=b//lcm(c,d)
a_1=a//c
a_1+=a//d
a_1-=a//lcm(c,d)
print(((b-b_1)-(a-a_1)))

# Optimized solution
a,b,c,d=list(map(int,input().split()))
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#a,bの最小公倍数
def lcm(a, b):
    return a * b // gcd (a, b)
a1=(a-1)//c
a2=b//c
b1=(a-1)//d
b2=b//d
new_lcm=lcm(c,d)
c1=(a-1)//new_lcm
c2=b//new_lcm
print(((b-a)+1-((a2-a1)+(b2-b1))+(c2-c1)))
#print(a1,a2,b1,b2,c1,c2)
# Original solution
A,B,C,D =list(map(int,input().split()))
x = C
y = D
while y>0:
    x,y = y,x%y
E = (C//x)*D
bc = B//C
bd = B//D
be = B//E
b = B-(bc+bd-be)
ac = (A-1)//C
ad = (A-1)//D
ae = (A-1)//E
a = A-1-(ac+ad-ae)
print((b-a))

# Optimized solution
def gcd(x,y):
    while y>0:
        x,y = y,x%y
    return x
A,B,C,D = list(map(int,input().split()))
c1 = B//C-(A-1)//C
d1 = B//D-(A-1)//D
E = (C//gcd(C,D))*D
e1 = B//E-(A-1)//E
print((B-A+1-c1-d1+e1))
# Original solution
from math import gcd
from decimal import Decimal as dec 
a, b, c, d = list(map(dec,input().split()))
if a % c ==0:
    c_explicit = b // c - a // c + 1
else:
    c_explicit = b // c - a // c 
if a % d ==0:
    d_explicit = b // d - a // d + 1
else:
    d_explicit = b // d - a // d 
e = gcd(int(c), int(d))
e = dec(e)
gcl = (c / e) * (d / e) * e
if a % gcl ==0:
    e_explicit = b // gcl - a // gcl + 1
else:
    e_explicit = b // gcl - a // gcl 
g = b - a + 1 - c_explicit - d_explicit + e_explicit
print(g)

# Optimized solution
from math import gcd as gcd
a, b, c, d = list(map(int,input().split()))
#cでわれるもの
s = gcd(c, d)
p = c * d // s
divide_c = b // c - (a - 1) // c
divide_d = b // d - (a - 1) // d
divide_cd = b // p - (a - 1) // p
print((int(b - a + 1 - divide_c - divide_d + divide_cd)))
# Original solution
import math
a, b, c, d = list(map(int, input().split()))

c_f = (a + c - 1) // c
c_e =  b // c
d_f = (a + d - 1) // d
d_e =  b // d

cd = c * d // math.gcd(c, d)
c_d_num = b // cd - (a + cd - 1) // cd + 1

num = b - a + 1 - (c_e - c_f + 1 + d_e - d_f + 1 - c_d_num)
 
print(num)

# Optimized solution
import math
a, b, c, d = list(map(int, input().split()))

def f(a, b, c):
    return b // c - (a + c - 1) // c + 1 

c_num = f(a, b, c)
d_num = f(a, b, d)

cp = c
dp = d
mod = 1
while mod > 0:
    mod = cp % dp
    cp = dp
    dp = mod

cd_num =  f(a, b, (c * d) // cp)
print((b - a + 1 - c_num - d_num + cd_num))
# Original solution
import math
from decimal import *
getcontext().prec = 50
a,b,c,d = list(map(int,input().split()))

from functools import reduce
def gcd(a,b):
  if a < b:
    a, b = b, a
  while a % b != 0:
    a, b = b, a % b
  return b

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

def lcm_list(numbers):
  return reduce(lcm_base, numbers, 1)

gcd = lcm_list([c,d])

def solve(n):
	start = n * math.ceil(Decimal(a) / Decimal(n))
	end = n * (Decimal(b) // Decimal(n))
	#print(start,end)
	return (end - start) // n + 1

#print(solve(c),solve(d),solve(gcd))
ans = solve(c) + solve(d) - solve(gcd)
#print(ans)
print((b - a - ans + 1))


# Optimized solution
from functools import reduce

def gcd(a,b):
  if a < b:
    a, b = b, a
  while a % b != 0:
    a, b = b, a % b
  return b

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

def lcm_list(numbers):
  return reduce(lcm_base, numbers, 1)

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

lcm = lcm_list([c,d])

res1 = a - 1 - ((a - 1) // c + (a - 1) // d - (a - 1) // lcm)
res2 = b - (b // c + b // d - b // lcm)

print((res2 - res1))
# Original solution
a, b, c, d = list(map(int, input().split()))
def gcd(a, b):
    if a == 0:
        return b
    return gcd(b % a, a)
def count(x, y):
    return x // y
cd = c * d // gcd(c, d)
print((b - a + 1 - count(b, c) + count(a - 1, c) - count(b, d) + count(a - 1, d) + count(b, cd) - count(a - 1, cd)))


# Optimized solution
a, b, c, d = list(map(int, input().split()))
def gcd(a, b):
    return b if a == 0 else gcd(b % a, a)
def lcm(a, b):
    return a // gcd(a, b) * b
def count(x):
    return x - (x // c) - (x // d) + (x // lcm(c, d))
print((count(b) - count(a - 1)))
# Original solution
def gcd(a,b):
	while b:
		a,b = b,a % b
	return a

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

a,b,c,d=list(map(int,input().split()))
e=lcm(c,d)

cc=(b//c)-((a-1)//c)
dd=(b//d)-((a-1)//d)
cd=(b//e)-((a-1)//e)
print(((b-a+1)-(cc+dd-cd)))

# Optimized solution
def gcd(a,b):
  while b:
    a,b=b,a%b
  return a

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


a,b,c,d=list(map(int,input().split()))
e=lcm(c,d)
print(((b-a+1)-(b//c-(a-1)//c)-(b//d-(a-1)//d)+(b//e-(a-1)//e)))
# Original solution
from math import gcd


def count_indivs(N):
    return N - (N // C + N // D - N // L)


A, B, C, D = list(map(int, input().split()))
L = C * D // gcd(C, D)
print((count_indivs(B) - count_indivs(A - 1)))


# Optimized solution
from math import gcd


def f(x):
    return x - (x // C + x // D - x // lcm)


A, B, C, D = list(map(int, input().split()))
lcm = C * D // gcd(C, D)
print((f(B) - f(A - 1)))
# Original solution
# -*- coding: utf-8 -*-
A, B, C, D = list(map(int, input().split()))
ans = 0
Am = 0
Bm = 0
df = 0
t = 0

def lcm(x, y):
	return (x * y) // gcd(x, y)

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

t = B - A + 1
Am = B // C - (A - 1) // C
Bm = B // D - (A - 1) // D
df = B // lcm(C, D) - (A - 1)//lcm(C, D)
ans = t - (Am + Bm) + df
print(ans)

# Optimized solution
# -*- coding: utf-8 -*-
A, B, C, D = list(map(int, input().split()))
ans = 0
Am = 0
Bm = 0
df = 0
t = 0

def lcm(x, y):
	return (x * y) // gcd(x, y)

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

t = B - A + 1
Am = (A - 1) // C + (A - 1) // D - (A - 1)//lcm(C, D)
Bm = B // C + B // D - B // lcm(C, D)
ans = t - (Bm - Am)

print(ans)
# Original solution
import sys
from math import gcd

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    A, B, C, D = list(map(int, readline().split()))

    G = C // gcd(C, D) * D
    c1, c2 = (A + C - 1) // C, B // C
    d1, d2 = (A + D - 1) // D, B // D
    g1, g2 = (A + G - 1) // G, B // G

    ans = (B - A + 1) - ((c2 - c1 + 1) + (d2 - d1 + 1) - (g2 - g1 + 1))
    print(ans)
    return


if __name__ == '__main__':
    main()


# Optimized solution
import sys
from math import gcd

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    A, B, C, D = list(map(int, readline().split()))

    L = C // gcd(C, D) * D
    c1, c2 = (A + C - 1) // C, B // C
    d1, d2 = (A + D - 1) // D, B // D
    l1, l2 = (A + L - 1) // L, B // L

    ans = (B - A + 1) - ((c2 - c1 + 1) + (d2 - d1 + 1) - (l2 - l1 + 1))
    print(ans)
    return


if __name__ == '__main__':
    main()
# Original solution
def solve():
    m, n = list(map(int, input().split()))
    print((m ** n % 1000000007))

solve()

# Optimized solution
def solve():
    m, n = list(map(int, input().split()))
    print((pow(m, n, 1000000007)))

solve()
# Original solution
MAX = 1000000007

m, n = [int(x) for x in input().split(' ')]
bi_n = bin(n)

ans = 1
dig = m
for i in range(len(bi_n)-1, 1, -1):
    if bi_n[i] == '1':
        ans *= dig
    dig *= dig
    if ans >= MAX:
        ans %= MAX

print(ans)


# Optimized solution
MAX = 1000000007

m, n = [int(x) for x in input().split(' ')]
bi_n = bin(n)

ans = 1
dig = m
for i in range(len(bi_n)-1, 1, -1):
    if bi_n[i] == '1': ans *= dig
    if ans >= MAX: ans %= MAX
    dig *= dig
    if dig >= MAX: dig %= MAX

print(ans)
# Original solution
m,n=list(map(int,input().split()))
print((m**n%1000000007))

# Optimized solution
m,n=list(map(int,input().split()))
print((pow(m,n,1000000007)))
# Original solution
M = (int)(1e9 + 7)
m, n = list(map(int, input().split()))
ans = 1;

for i in range(n):
    ans *= m
    ans %= M

print(ans)

# Optimized solution
mod = 1000000007
m, n = list(map(int, input().split()))
print((pow(m,n,mod)))
# Original solution
from math import *

def main():
    m, n = [int(_) for _ in input().split()]
    print((int((m ** n) % 1000000007)))

main()



# Optimized solution
def main():
    m, n = [int(_) for _ in input().split()]
    print((pow(m, n, 1000000007)))

main()
# Original solution
m, n = list(map(int, input().split()))
print((divmod(pow(m, n), 1000000007)[1]))

# Optimized solution
m, n = list(map(int, input().split()))
print((pow(m, n, 1000000007)))
# Original solution
def mpow(x,n):
    if n == 0:
        return 1
    if n % 4 == 0:
        return mpow(x**4,int(n/4))
    elif n%4 == 1:
        return mpow(x,int(n-1))*x
    elif n%4 == 2:
        return mpow(x,int(n-2))*x*x
    elif n%4 == 3:
        return mpow(x,int(n-3))*x*x*x
n,m = list(map(int,input().split()))
x = 1000000007
print((mpow(n,m)%x))

# Optimized solution
def mpow(x,n,mod):
    if n == 0:
        return 1
    if n % 4 == 0:
        return mpow((x**4)%mod,int(n/4),mod)
    elif n%4 == 1:
        return (mpow(x,int(n-1),mod)*x)%mod
    elif n%4 == 2:
        return (mpow(x,int(n-2),mod)*(x**2))%mod
    elif n%4 == 3:
        return (mpow(x,int(n-3),mod)*(x**3))%mod
n,m = list(map(int,input().split()))
mod = 1000000007
print((mpow(n,m,mod)))
# Original solution
m, n = list(map(int, input().split()))
mod = 1000000007
print((((m % mod) ** (n % mod)) % mod))



# Optimized solution
m, n = list(map(int, input().split()))
print((pow(m, n, 1000000007)))
# Original solution
m, n = list(map(int, input().split()))
p, q, d = 1, m, 1000000007

while True:
    if n & 1:
        p *= q
        p %= d
    n >>= 1
    if not n:
        break
    q *= q
    q %= d

print(p)

# Optimized solution
m, n = list(map(int, input().split()))
print((pow(m, n, int(1e9) + 7)))
# Original solution
m,n=list(map(int,input().split()))
print((m**n%(1000000007)))


# Optimized solution
m,n=list(map(int,input().split()))
print((pow(m,n,1000000007)))
# Original solution
m,n = list(map(int,input().split()))
k = m
for i in range(1,n):
    m *= k
    if m > 1000000007:
        m  %= 1000000007
        
print(m)

# Optimized solution
m,n = list(map(int,input().split()))

def amari(m,n):
    if n == 0:
        return 1
    
    if n % 2 == 0:
        return amari(m,n/2)**2%1000000007 
    else:
        return  m*amari(m,n-1)%1000000007 
print((amari(m,n)))
# Original solution
m,n=list(map(int,input().split()))
mn=m**n
if mn<=1000000007:
    print(mn)
else:
    print((mn%1000000007))


# Optimized solution
m,n=list(map(int,input().split()))
print((pow(m,n,1000000007)))
# Original solution
import sys

mod = 10**9 + 7

def solve():
    m, n = list(map(int, input().split()))

    ans = modpow(m, n, mod)

    print(ans)

def modpow(x, y, mod):
    res = 1

    while y:
        if y & 1:
            res = (res * x) % mod

        x = (x * x) % mod
        y >>= 1

    return res

if __name__ == '__main__':
    solve()

# Optimized solution
import sys

mod = 10**9 + 7

def solve():
    m, n = list(map(int, input().split()))
    print((pow(m, n, mod)))

if __name__ == '__main__':
    solve()
# Original solution
try:
    (m,n)  =  list(map(int,input().split()))
except:
    exit

r = pow(m,n) %  1000000007
print (r)


# Optimized solution
(m,n)  =  list(map(int,input().split()))

bi = str(format(n,"b"))
bi = bi[::-1]

c = 1
d = 1000000007

for i in bi:
    if ( i == "1"):
        c = ( c * m ) % d
    m = (m * m) %d
print (c)
# Original solution
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18

N=ri()
W=[0]*N
ans = 1
for i in range(N):
    W[i] = input()
    if i != 0 and W[i-1][-1] != W[i][0]:
        ans = 0

import collections
Wc = collections.Counter(W).most_common()
if Wc[0][1] != 1:
    ans = 0

yn(ans)


# Optimized solution
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18

N=ri()
W=[0]*N
ans = 1
for i in range(N):
    W[i] = input()
    if ans == 1 and i != 0 and W[i-1][-1] != W[i][0]:
        ans = 0

if ans == 1 and len(set(W)) != N:
    ans = 0

yn(ans)
# Original solution
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()

from collections import defaultdict

N = ni()
W = nsn(N)
d = defaultdict(int)

flag = True
for i in range(N):
    if i and W[i - 1][-1] != W[i][0]:
        flag = False
    if d[W[i]] >= 1:
        flag = False
    d[W[i]] += 1

print(("Yes" if flag else "No"))

# Optimized solution
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

n = ni()
w = nsn(n)

flag = True
dic = dict()
last = w[0][0]
for i in range(n):
    if dic.get(w[i], False):
        flag = False
    if last != w[i][0]:
        flag = False
    last = w[i][-1]
    dic[w[i]] = True

print(("Yes" if flag else "No"))
# Original solution
def slove():
    import sys
    import collections
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    lw = ""
    d = collections.defaultdict(list)
    for i in range(n):
        w = str(input().rstrip('\n'))
        if lw != "":
            if w[0] != lw or w in d:
                print("No")
                exit()
        lw = w[-1]
        d[w]
    print("Yes")


if __name__ == '__main__':
    slove()


# Optimized solution
def slove():
    import sys
    import collections
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    d = collections.defaultdict(int)
    s = [str(input().rstrip('\n')) for _ in range(n)]
    for i in range(n):
        if i != 0:
            if s[i][0] != s[i-1][-1] or s[i] in d:
                print("No")
                exit()
        d[s[i]]
    print("Yes")


if __name__ == '__main__':
    slove()
# Original solution
import sys
import collections


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n = int(input().rstrip('\n'))
    s = [str(input().rstrip('\n')) for _ in range(n)]
    d = collections.defaultdict(int)
    d[s[0]]
    b = True
    for i in range(1, n):
        if s[i] not in d:
            d[s[i]]
            if s[i][0] != s[i-1][-1]:
                b = False
                break
        else:
            b = False
            break
    print(("Yes" if b else "No"))


if __name__ == '__main__':
    solve()


# Optimized solution
import sys
import collections


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    d = collections.defaultdict(int)
    lstr = "1"
    for i in range(n):
        w = str(readline().rstrip().decode('utf-8'))
        if (w[0] == lstr or lstr == "1") and w not in d:
            d[w]
            lstr = w[-1]
        else:
            print("No")
            exit()
    print("Yes")


if __name__ == '__main__':
    solve()
# Original solution
x = int(eval(input()))
t = 1
ds = {0}
while True:
    dc = ds.copy()
    for d in dc:
        if d + t == x or d - t == x:
            break
        ds.add(d + t)
        ds.add(d - t)
    else:
        t += 1
        continue
    break

print(t)


# Optimized solution
from math import ceil, sqrt

x = int(eval(input()))
print((ceil((-1 + sqrt(8 * x + 1)) / 2)))
# Original solution
import math
import itertools
X = int(eval(input()))

P = [x for x in range(1, X+1)]
Q = itertools.accumulate(P)
for i, q in enumerate(Q):
    if q>=X:
        print((i+1))
        break

# Optimized solution
X = int(eval(input()))

for i in range(1, X+1):
    if i*(i+1)//2 >= X:
        print(i)
        break
# Original solution
x = int(eval(input()))
for i in range(1, x+1):
    if sum([j for j in range(1, i+1)]) >= x:
        print(i)
        break

# Optimized solution
x = int(eval(input()))
for i in range(1, x+1):
    if i * (i+1) / 2 >= x:
        print(i)
        break