Harryxun/stf_run huggingface dataset:
from collections import defaultdict, deque
N = int(input())
es = defaultdict(list)
se = defaultdict(list)
ins = [0]*(N*(N-1)//2)
dp = [-1]*(N*(N-1)//2)
ID = [[0]*N for i in range(N)]
count = 0
for i in range(N):
  for j in range(N):
    if i<j:
      ID[i][j] = count
      count += 1
def TP_sort(E, ins):
  q = deque([int(v1) for v1 in range(len(ins)) if ins[v1]==0])
  res = []
  while q:
    p = q.popleft()
    res += [p]
    for c in E[p]:
      ins[c] -= 1
      if ins[c]==0:
        q.append(c)
  for i in ins:
    if i>0:
      return -1
  return res

def dfs(e):
  if dp[e]!=-1:
    return dp[e]
  m = 0
  for ex in se[e]:
    x = dfs(ex)
    if x>m:
      m = x
  dp[e] = m+1
  return m+1

for i in range(N):
  inf = [int(i)-1 for i in input().split()]
  for j in range(N-2):
    x = min(i, inf[j])
    y = max(i, inf[j])
    nx = min(i, inf[j+1])
    ny = max(i, inf[j+1])
    t = ID[x][y]
    nt = ID[nx][ny]
    es[t] += [nt]
    se[nt] += [t]
    ins[nt] += 1
ls = TP_sort(es, ins.copy())
if ls==-1:
  print(-1)
else:
  for i in range(len(ins)):
    if ins[i]==0:
      dp[i] = 0
  print(dfs(ls[-1])+1)

### FIXED CODE ###

N = int(input())
es = [[] for i in range(N)]
cand = set()
for i in range(N):
  es[i] = [int(i)-1 for i in input().split()][::-1]
def check(i):
  if es[i]==[]:
    return
  j = es[i][-1]
  if es[j]==[]:
    return
  if es[j][-1]==i:
    cand.add(i)
    cand.add(j)

for i in range(N):
  check(i)
day = 0
while cand:
  day += 1
  precand = cand.copy()
  cand = set()
  for i in precand:
    x = es[i].pop()
  for i in precand:
    check(i)
for i in range(N):
  if len(es[i])!=0:
    print(-1)
    break
else:
  print(day)
from collections import Counter

n = int(input())
v = list(map(int, input().split(' ')))

v1 = v[::2]
v2 = v[1::2]

counter1 = Counter(v1)
x1 = counter1.most_common(2)
counter2 = Counter(v2)
x2 = counter2.most_common(2)

n = n//2
ans = 0
if x1[0][0] == x2[0][0]:
    if x1[0][1] > x2[0][1]:
        ans = (n - x1[0][1]) + (n - x2[1][1])
    else:
        ans =  (n - x2[0][1]) + (n - x1[1][1])
else:
    ans = (n - x1[0][1]) + (n - x2[0][1])
print(ans)

### FIXED CODE ###

from collections import Counter

n = int(input())
v = list(map(int, input().split(' ')))

v1 = v[::2]
v2 = v[1::2]

counter1 = dict(Counter(v1))
counter2 = dict(Counter(v2))
x1 = max(counter1, key=counter1.get)
x2 = max(counter2, key=counter2.get)
x1_c = counter1[x1]
x2_c = counter2[x2]
del counter1[x1]
del counter2[x2]
y1_c = 0
y2_c = 0
if len(counter1) != 0:
    y1_c = max(counter1.values())
if len(counter2) != 0:
    y2_c = max(counter2.values())

n = n//2
ans = 0
if x1 == x2:
    ans = min((n - x1_c) + (n - y2_c), (n - y1_c) + (n - x2_c))
    """
    if x1_c > x2_c:
        ans = (n - x1_c) + (n - y2_c)
    else:
        ans =  (n - y1_c) + (n - x2_c)
    """
else:
    ans = (n - x1_c) + (n - x2_c)

print(ans)
N, B = map(int,input().split())
R = N-B
T = 1000000007
ans = 1


c1 = 1
c2 = R +1

print(c1*c2%T)

i = 2
while(True):
	c1 = c1 * (B-1-i+2) / (i-1)
	c2 = c2 * (R+1-i +1) / i
	if c1>0 and c2 > 0:
		print(int(c1*c2)%T)
	else:
		break
	i += 1

### FIXED CODE ###

import sys
N, B = map(int,input().split())
R = N-B
T = 1000000007
def combination(n, r):
	if r == 0 or r == n:
		return 1
	elif r == 1:
		return n
	else:
		return(combination(n-1, r-1) + combination(n-1, r))
def generating_combination(n):
	T = 1000000007
	C = C = [[0 for i in range(n+1)] for j in range(n+1)]
	C[0][0] = 1
	C[1][0] = 1
	C[1][1] = 1
	for i in range(2,n+1):
		C[i][0] = 1
		C[i][i] = 1
		for j in range(1,i):
			C[i][j] = (C[i-1][j-1] + C[i-1][j])%T
	return(C)

D = generating_combination(2000)
i = 1
for i in range(1,B+1):
	print((D[B-1][i-1]*D[R+1][i])%T)
	i += 1
n, k = int(input().split())
a = list(map(int, input().split()))
for i in range(n-k-1):
    ab = a[i]*a[k-1+i]
    aa = a[i+1]*a[k+i]
    if aa > ab:
        print("Yes")
    else:
        print("No")




    
    


### FIXED CODE ###

n, k = map(int, input().split())
a = list(map(int, input().split()))
for i in range(n-k):
    ab = a[i]
    aa = a[k+i]
    if aa > ab:
        print("Yes")
    else:
        print("No")
from collections import defaultdict
from collections import deque

s=input()
n=len(s)
dd = defaultdict(int)
q = deque()
ans=0
for i in range(4):
    q.append(s[i])
if(int(''.join(q))%2019)==0:
    ans+=1

for i in range(0, n-3):
    for j in range(5, n+1, 3):
        if i+j<n+1:
            dd[(i,i+j)]+=1
            if(int(s[i:i+j])%2019==0) and dd[(i,i+j)]==1:
                ans+=1
            if j>n-4:
                for k in range(3):
                    if i+j+k<n:
                        dd[(i,i+j+k)]+=1
                        if int(s[i:i+j+k])%2019==0 and dd[(i,i+j+k)]==1:
                            ans+=1

print(ans)


### FIXED CODE ###

from collections import defaultdict
dd = defaultdict(int)
S = list(input().rstrip())
tmp = 0
dd[0]+=1
r=1
for s in S[::-1]:
    tmp+=int(s)*r
    r*=10

    tmp%=2019
    r%=2019
    dd[tmp]+=1
su=0
for i in dd.values():
    su+=(i*(i-1))//2
print(su)
b=input()
if b=A:
    print('T')
elif b=T:
    print('A')
elif b=C:
    print('G')
else:
    print('C')


### FIXED CODE ###

b=input()
if b=='A':
    print('T')
elif b=='T':
    print('A')
elif b=='C':
    print('G')
else:
    print('C')
def chkp(i,j):
	tmp=j+1
	count=1
	while tmp<W and s[i][tmp]==".":
		count+=1
		tmp+=1
	return count

def chkv(i,j):
	tmp=i+1
	count=1
	while tmp<H and s[tmp][j]==".":
		count+=1
		tmp+=1
	return count

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

p=[[0 for j in range(W)] for i in range(H)]
v=[[0 for j in range(W)] for i in range(H)]

for i in range(H):
	if W==1:
		if s[i][j]==".": p[i][0]=1
	else:
		if s[i][0]==".": p[i][0]=chkp(i,0)
		for j in range(1,W):
			if s[i][j]==".":
				if s[i][j-1]==".": p[i][j]=p[i][j-1]
				else: p[i][j]=chkp(i,j)

for j in range(W):
	if H==1:
		if s[i][j]==".": v[0][j]=1
	else:
		if s[0][j]==".": v[0][j]=chkv(0,j)
		for i in range(1,H):
			if s[i][j]==".":
				if s[i-1][j]==".": v[i][j]=v[i-1][j]
				else: v[i][j]=chkv(i,j)

print(max( max(v[i][j]+p[i][j] for j in range(W)) for i in range(H)  ))

### FIXED CODE ###

h,w=map(int,input().split())
ans=[[-3]*w for _ in range(h)]
s=[input() for _ in range(h)]
for i in range(h):
    tmp=0
    for j in range(w):
        if s[i][j]=="#": tmp=0
        else: tmp+=1
        ans[i][j]+=tmp
    tmp=0
    for j in range(w-1,-1,-1):
        if s[i][j]=="#": tmp=0
        else: tmp+=1
        ans[i][j]+=tmp

for j in range(w):
    tmp=0
    for i in range(h):
        if s[i][j]=="#": tmp=0
        else: tmp+=1
        ans[i][j]+=tmp
    tmp=0
    for i in range(h-1,-1,-1):
        if s[i][j]=="#": tmp=0
        else: tmp+=1
        ans[i][j]+=tmp

print(max( max(ans[i]) for i in range(h) ))
import itertools

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

candidate = list(range(a, b+1, 1))
if n == 1:
    if a == b:
        print(1)
    else:
        print(0)
elif n == 2:
    print(a)
elif n >= 3:
    c = list(itertools.combinations_with_replacement(candidate, n-2))
    suml = []
    for i in c:
        suml.append(sum(i) + 4 + 6)
    sum_set = set(suml)
    print(len(sum_set))

### FIXED CODE ###

import itertools

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

if n == 1:
    if a == b:
        print(1)
    else:
        print(0)
elif n == 2:
    print(1)
elif n >= 3:
    if a > b:
        print(0)
    else:
        smin = a * n + (b-a)
        smax = b * n - (b-a)
        print(smax-smin+1)
X =int(input())
def f(n):
    for i in range(2,int(n**0.5)+1):
        if n%i == 0:
            return False
    return True
for i in range(X,100004):
    if f(i):
        return(i)
        break


### FIXED CODE ###

X =int(input())
def f(n):
    for i in range(2,int(n**0.5)+1):
        if n%i == 0:
            return False
    return True
for i in range(X,100004):
    if f(i):
        print(i)
        break
h,w=map(int,input().split());w+=2
print('#'*w)
for _ in[0]*h:print('#'+input()+'#')
print('#'*w)

### FIXED CODE ###

x,y=map(int,input().split());a=[4,6,9,11];b=[1,3,5,7,8,10,12];print(['No','Yes'][int(x in a)*(y in a)+ int(x in b)*(y in b)])
# C Streamline
n,m = map(int,input().split())
Xs = list(map(int,input().split()))

if n >= m:
    print('0')
    exit()

Xs.sort()
XsDist = []

for i in range(len(Xs)):
    if not i == 0:
        XsDist.append(Xs[i] - Xs[i-1])

XsDist.sort()
print(sum(XsDist[:n+1]))

### FIXED CODE ###

t,x = map(int,input().split())
print(t / x)
def d(n,r):
  return factorial(n)//factorial(r)//factorial(n-r)

if N<K:
  print(0)
else:  
  a=N//K
  ans=a
  if K%2==1:
    if a>=2:
      ans+=d(a,2)*6
    if a>=3:
      ans+=a*(a-1)*(a-2)
    print(ans)
  else:    
    if K*a+K//2<=N:
      b=a+1
    if a>=2:
      ans+=d(a,2)*6
      print(ans)
    if a>=3:
      ans+=a*(a-1)*(a-2)
    if b>=2:
      ans+=b+d(b,2)*6
    if b>=3:
      ans+=b*(b-1)*(b-2)

    print(ans)

### FIXED CODE ###

N,K=map(int,input().split())
a=N//K
if K%2==1:
  print(a**3)
else:
  if N>=(a+0.5)*K:
    print(a**3+(a+1)**3)
  else:
    print((a**3)*2)
import math

q = int(input())
a = [0] * q
b = [0] * q

for i in range(0, q):
    a[i], b[i] = [int(i) for i in input().split(" ")]

for i in range(0, q):
    mi = min(a[i], b[i])
    mx = max(a[i], b[i])
    p = mi * mx - 1
    s = p**(1/2)
    c = 2 * math.floor(s - 1)
    if mi <= math.floor(s - 1):
        c -= 1
    if math.floor(p / math.floor(s)) > math.floor(s):
        if math.floor(s) == mi:
            c += 1
        else:
            c += 2
    elif math.floor(p / math.floor(s)) == math.floor(s) and math.floor(s) != mi:
        c += 1
    print(c)

### FIXED CODE ###

import math

q = int(input())
a = [0] * q
b = [0] * q

for i in range(0, q):
    a[i], b[i] = [int(i) for i in input().split(" ")]
    
def sqrt_int(n):
    s = math.floor(n**(1/2)) - 1
    while s * s <= n:
        s += 1
    return s - 1

for i in range(0, q):
    mi = min(a[i], b[i])
    mx = max(a[i], b[i])
    p = mi * mx - 1
    s = math.floor(p**(1/2))
    c = 2 * (s - 1)
    if s == 0:
        print(0)
        continue
    if mi <= s - 1:
        c -= 1
    r = p // s
    if r > s:
        if s == mi:
            c += 1
        else:
            c += 2
    elif r == s and s != mi:
        c += 1
    print(c)
SD = input()
T = input()

for i, ch in enumerate(T):
    if ch in SD:
        n = SD.find(ch)
        flag = True
        c = 0
        for j in range(n-1, n-i, -1):
            if j < 0:
                flag = False
                break
            if SD[j] != '?' and SD[j] != T[i-c]:
                flag = False
                break
            flag = True
            c += 1
        if flag:
            c = 0
            for j in range(n+1, n+len(T)-i):
                if j > len(SD)-1:
                    flag = False
                    break
                if SD[j] != '?' and SD[j] != T[i+c]:
                    flag = False
                    break
                flag = True
                c += 1
        if flag:
            remP = SD[:n-i]
            remA = SD[n+1+len(T)-i:]
            for j, rc in enumerate(remP):
                if rc == '?':
                    remP = remP[:j] + 'a' + remP[j+1:]
            for j, rc in enumerate(remA):
            	if rc == '?:
              		remA = remA[:j] + 'a' + remA[j+1:]
            print(remP+T+remA)
            quit()
print('UNRESTORABLE')


### FIXED CODE ###

S = input()
T = input()
c = 0
idx = 0
ans = []
for i, s in enumerate(S):
    if s == T[0] or s == '?':
        tmp = S[i:min(i+len(T), len(S))]
        flg = True
        if len(T) != len(tmp):
            continue
        for j, c in enumerate(tmp):
            if c != T[j] and c != '?':
                flg = False
                break
        if flg:
            ans.append((S[:i] + T + S[i+len(T):]).replace('?', 'a'))
if len(ans) == 0:
    print('UNRESTORABLE')
else:
    ans.sort()
    print(ans[0])
A, B, C, D = input().split()
value = (min(B, D) - max(A, C))
print(value if value > 0 else "0")



### FIXED CODE ###

A, B, C, D = map(int, input().split())
value = min(B, D) - max(A, C)
print(value if value > 0 else "0")
def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    [N, M] = list(map(lambda x: int(x), inputs[0].split()))
    broke_steps = list(map(lambda x: int(x), inputs[1:]))

    prev = broke_steps[0]
    for broke_step in broke_steps[1:]:
        if broke_step - prev == 1:
            return 0

    SSSS = 1000000007

    patterns = [1]
    for i, step in enumerate(range(1, N + 1)):
        if step in broke_steps:
            ap = 0
        elif i == 0:
            ap = 1
        else:
            ap = (patterns[i] + patterns[i - 1]) % SSSS
        patterns.append(ap)

    return patterns[-1]


if __name__ == "__main__":
    first = input()
    [N, M] = list(map(lambda x: int(x), first.split()))
    inputs_str = inputs(M)
    inputs_str.insert(0, first)
    ret = solve(inputs_str)
    print(ret)


### FIXED CODE ###

def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    [N, M] = list(map(lambda x: int(x), inputs[0].split()))
    broke_steps = {}
    for b in map(lambda x: int(x), inputs[1:]):
        broke_steps[b] = True

    SSSS = 1000000007

    patterns = [1]
    for step in range(1, N + 1):
        if step in broke_steps:
            ap = 0
        elif step == 1:
            ap = 1
        else:
            ap = (patterns[step - 1] + patterns[step - 2]) % SSSS
        patterns.append(ap)

    return patterns[-1]


if __name__ == "__main__":
    first = input()
    [N, M] = list(map(lambda x: int(x), first.split()))
    inputs_str = inputs(M)
    inputs_str.insert(0, first)
    ret = solve(inputs_str)
    print(ret)
import math

def dist(p1, p2):
    return math.sqrt((p1[0] - p2[0])**2 + (p1[1] - p2[1])**2)

def intersection(o1,o2):
    a  = 2*(o2[0] - o1[0])
    b  = 2*(o2[1] - o1[1])
    c  = (o1[0] - o2[0])*(o1[0] + o2[0]) + (o1[1] - o2[1])*(o1[1] + o2[1])
    a2 = a**2 + b**2
    b2 = a*c + a*b*o1[1] - b**2*o1[0]
    c2 = b**2*(o1[0]**2 + o1[1]**2 - 1) + c**2 + 2*b*c*o1[1]
    x1 = (-b2 + math.sqrt(b2**2 - a2*c2))/a2
    x2 = (-b2 - math.sqrt(b2**2 - a2*c2))/a2
    if abs(b) == 0:
        y1 = o1[1] + math.sqrt(1 - (x1 - o1[0])**2)
        y2 = o1[1] - math.sqrt(1 - (x1 - o1[0])**2)
    else:
        y1 = -(a*x1 + c)/b
        y2 = -(a*x2 + c)/b
    return [x1, y1], [x2, y2]

while True:
    n = int(input())
    if n == 0:
        break
    p = []
    for i in range(n):
        p.append(list(map(float, input().split(","))))
    ans = 1
    for i in range(n - 1):
        for j in range(i + 1, n):
            if dist(p[i], p[j]) > 2:
                continue
            p1, p2 = intersection(p[i], p[j])
            cnt1 = 0
            cnt2 = 0
            for k in range(n):
                if dist(p1, p[k]) <= 1:
                    cnt1 += 1
                if dist(p2, p[k]) <= 1:
                    cnt2 += 1
            ans = max([ans, cnt1, cnt2])
    print(ans)



### FIXED CODE ###

import math

def dist(p1, p2):
    return math.sqrt((p1[0] - p2[0])**2 + (p1[1] - p2[1])**2)

def intersection(o1,o2):
    if dist(o1,o2) > 2:
        p1, p2 =  [None, None], [None, None]
    elif dist(o1,o2) == 2:
        p1, p2 =  [(o1[0] + o2[0])/2, (o1[1] + o2[1])/2], [None, None]
    else:
        m = [(o1[0] + o2[0])/2, (o1[1] + o2[1])/2]
        v = [m[0] - o1[0], m[1] - o1[1]]
        v_abs = dist(v,[0,0])
        w = [v[1], -v[0]]
        w_abs = dist(w,[0,0])
        n = [w[0]/w_abs, w[1]/w_abs]
        l = math.sqrt(1 - v_abs**2)
        p1 = [m[0] + l*n[0], m[1] + l*n[1]]
        p2 = [m[0] - l*n[0], m[1] - l*n[1]]
    return p1, p2
err = 1.0e-6
while True:
    n = int(input())
    if n == 0:
        break
    p = []
    for i in range(n):
        p.append(list(map(float, input().split(","))))
    ans = 1
    for i in range(n - 1):
        for j in range(i + 1, n):
            p1, p2 = intersection(p[i], p[j])
            cnt1 = 0
            cnt2 = 0
            for k in range(n):
                if p1[0] and dist(p1, p[k]) <= 1 + err:
                    cnt1 += 1
                if p2[0] and dist(p2, p[k]) <= 1 + err:
                    cnt2 += 1
            ans = max([ans, cnt1, cnt2])
    print(ans)
S = input('=')

if S == 'ABC':
    print('ARC')
else S == 'ARC':
    print('ABC')


### FIXED CODE ###

s = input()
a = ["ABC", "ARC"]
print(a[(a.index(s)+1)%len(a)])
import itertools as it

def li():
    return [int(x) for x in input().split()]

N, K = li()
P = [0] + li()
C = [0] + li()

def get_cycle(start_i):
    cycle = []
    i = start_i
    while True:
        i = P[i]
        if i == start_i:
            break
        cycle.append(i)
    cycle.append(start_i)
    return cycle

max_scores = []
for start_i in range(1,N+1):
    cycle = get_cycle(start_i)
    # 累積和
    scores = it.accumulate([0]+[C[i] for i in cycle])
    cycle_len = len(cycle)
    score_per_cycle = scores[cycle_len]
    # 1cycle以下の場合は全て調べればよし
    if K <= len(cycle):
        max_score = max(scores[1:K+1])
        max_scores.append(max_score)
        continue
    # 1サイクルごとのスコアがマイナスならサイクルを回らないのがハイスコア
    if score_per_cycle <= 0:
        max_score = max(scores[1:])
        max_scores.append(max_score)
        continue
    # 1サイクルごとのスコアがプラスなら限界までサイクルを回るのがハイスコア
    # ラスト1cycleのスコアを調べる
    scores_last_cycle = []
    for move in range(K-cycle_len+1, K+1):
        # 何周したか
        loop_cnt = move // cycle_len
        # あまり
        rest_move = move % cycle_len
        # スコア = 1周ごとのスコア * 何周したか + あまり
        score = loop_cnt * score_per_cycle + scores[rest_move]
        scores_last_cycle.append(score)

    max_scores.append(max(scores_last_cycle))

print(max(max_scores))



### FIXED CODE ###

def li():
    return [int(x) for x in input().split()]

N, K = li()
P = [0] + li()
C = [0] + li()

def get_cycle(start_i):
    cycle = []
    i = start_i
    while True:
        i = P[i]
        if i == start_i:
            break
        cycle.append(i)
    cycle.append(start_i)
    return cycle

def get_cycle_scores(cycle):
    score = 0
    scores = [score]
    for i in cycle:
        score += C[i]
        scores.append(score)
    return scores

max_scores = []
for start_i in range(1,N+1):
    cycle = get_cycle(start_i)
    scores = get_cycle_scores(cycle)
    cycle_len = len(cycle)
    score_per_cycle = scores[cycle_len]
    # 1cycle以下の場合は全て調べればよし
    if K <= len(cycle):
        max_score = max(scores[move] for move in range(1, K+1))
        max_scores.append(max_score)
        continue
    # 1サイクルごとのスコアがマイナスならサイクルを回らないのがハイスコア
    if score_per_cycle <= 0:
        max_score = max(scores[move] for move in range(1, cycle_len+1))
        max_scores.append(max_score)
        continue
    # 1サイクルごとのスコアがプラスなら限界までサイクルを回るのがハイスコア
    # ラスト1cycleのスコアを調べる
    scores_last_cycle = []
    for move in range(K-cycle_len+1, K+1):
        # 何周したか
        loop_cnt = move // cycle_len
        # あまり
        rest_move = move % cycle_len
        # スコア = 1周ごとのスコア * 何周したか + あまり
        score = loop_cnt * score_per_cycle + scores[rest_move]
        scores_last_cycle.append(score)

    max_scores.append(max(scores_last_cycle))

print(max(max_scores))
def initBoard(rowSize, colSize):
    board = list()
    for i  in range(rowSize):
        col = [1]*colSize
        board.append(col)
    return board

def canFlip(i, j):
    return i >= 0 and i < rowSize and j >= 0 and j < colSize

def flip(board, i, j):
    if board[i][j] == 0:
        board[i][j] = 1
    elif board[i][j] == 1:
        board[i][j] = 0

def process(board, i, j):
    if canFlip(i, j):
        flip(board, i, j)
    if canFlip(i-1, j+1):
        flip(board, i-1, j+1)
    if canFlip(i, j+1):
        flip(board, i, j+1)
    if canFlip(i+1, j+1):
        flip(board, i+1, j+1)
    if canFlip(i-1, j):
        flip(board, i-1, j)
    if canFlip(i+1, j):
        flip(board, i+1, j)
    if canFlip(i-1, j-1):
        flip(board, i-1, j-1)
    if canFlip(i, j-1):
        flip(board, i, j-1)
    if canFlip(i+1, j-1):
        flip(board, i+1, j-1)

def countBack(board):
    count = 0
    for i in range(len(board)):
        for j in range(len(board[0])):
            if board[i][j] == 0: count += 1
    return count

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

rowSize = N
colSize = M
board = initBoard(rowSize, colSize)
for i in range(N):
    for j in range(M):
        process(board, i, j)
print(countBack(board))

### FIXED CODE ###

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

if M > N:
    tmp = M
    M = N
    N = tmp

if N == 1 and M == 1: print(1)
elif M == 1: print(N-2)
else: print((N-2)*(M-2))
from fructions import gcd

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

if c%gcd(a, b):
  print("NO")
else:
  print("YES")

### FIXED CODE ###

from fractions import gcd

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

if c%gcd(a, b):
  print("NO")
else:
  print("YES")
n, x = map(int,input().split())
ans = [-1]*(2*n - 1)
if x == 1 or x == 2*n - 1:
    print('No')
else:
    if n == 3:
        if x == 3:
            print('No')
        else:
            print(1 + '¥n' + 2 + '¥n' + 3)
    else:
        print('Yes')
        t = 0
        if x == 2:
            ans[n - 3] = 4
            ans[n - 2] = 1
            ans[n - 1] = 2
            ans[n] = 3
            t, i = 1, 0
            for rep in range(10**6):
                if i >= 2*n - 1:
                    break
                if ans[i] == -1:
                    if t < x - 2 or t > x + 1:
                        ans[i] = t
                        i += 1
                    t += 1 
                else:
                    i += 1
            for i in range(1,2*n):
                if ans[t] == -1 and i > 5:
                    ans[t] = i
                    t += 1
        else:
            ans[n - 3] = x - 2
            ans[n - 2] = x + 1
            ans[n - 1] = x
            ans[n] = x - 1
            t, i = 1, 0
            for rep in range(10**6):
                if i >= 2*n - 1:
                    break
                if ans[i] == -1:
                    if t < x - 2 or t > x + 1:
                        ans[i] = t
                        i += 1
                    t += 1 
                else:
                    i += 1

        for i in ans:
            print(i)

### FIXED CODE ###

n, x = map(int,input().split())
ans = [-1]*(2*n - 1)
if x == 1 or x == 2*n - 1:
    print('No')
else:
    if n == 2:
        if x == 3:
            print('No')
        else:
            print('Yes')
            print('1\n2\n3')
    else:
        print('Yes')
        t = 0
        if x == 2:
            ans[n - 3] = 4
            ans[n - 2] = 1
            ans[n - 1] = 2
            ans[n] = 3
            t, i = 1, 0
            for rep in range(10**6):
                if i >= 2*n - 1:
                    break
                if ans[i] == -1:
                    if t > 4:
                        ans[i] = t
                        i += 1
                    t += 1 
                else:
                    i += 1
        else:
            ans[n - 3] = x - 2
            ans[n - 2] = x + 1
            ans[n - 1] = x
            ans[n] = x - 1
            t, i = 1, 0
            for rep in range(10**6):
                if i >= 2*n - 1:
                    break
                if ans[i] == -1:
                    if t < x - 2 or t > x + 1:
                        ans[i] = t
                        i += 1
                    t += 1 
                else:
                    i += 1

        for i in ans:
            print(i)
n = int(input())-65
s = input()
ans = ''
for x in s:
    ans += chr((ord(x)+n)%26 + 65)
print(ans

### FIXED CODE ###

n = int(input())-65
s = input()
ans = ''
for x in s:
    ans += chr((ord(x)+n)%26 + 65)
print(ans)
for i in range(N):
  a = list(input())
  a.sort()
  s.append(a)

duplicate_list = duplicates(s)

for i in range (len(duplicate_list)):
  for j in range (s.count(duplicate_list[i])):
    count += j

print(count)

### FIXED CODE ###

from collections import defaultdict

N = int(input())
s = defaultdict(lambda:0)
count=0

for i in range(N):
  a = "".join(sorted(input()))
  s[a] +=1
  
  if s[a] >1:
    count += s[a]-1
print(count)