Harryxun/stf_run huggingface dataset:
N = int(input())
l = [0] * N
march = 'MARCH'
for i in range(N):
    S = input()
    for j in range(len(march)):
        if S[0] == march[j]:
            l[j] += 1

tmp = []
lenl = len(l)
for i in range(lenl):
    for j in range(i + 1, lenl):
        for k in range(j + 1, lenl):
           tmp.append(l[i]*l[j]*l[k])

print(sum(tmp))

### FIXED CODE ###

N = int(input())
march = 'MARCH'
l = [0] * len(march)
for i in range(N):
    S = input()
    for j in range(len(march)):
        if S[0] == march[j]:
            l[j] += 1

# print(l)
tmp = []
lenl = len(l)
for i in range(lenl):
    for j in range(i + 1, lenl):
        for k in range(j + 1, lenl):
           tmp.append(l[i]*l[j]*l[k])
# print('tmp',tmp)
print(sum(tmp))
s = list(input())
acgt = ["A", "C", "G", "T"]
cnt, ans = 0
for i in range(len(s)):
  if s[i] in acgt:
    cnt += 1
    if ans < cnt:
      ans = cnt
  else:
    cnt = 0
print(ans)


### FIXED CODE ###

s = list(input())
acgt = ["A", "C", "G", "T"]
cnt = 0
ans = 0
for i in range(len(s)):
  if s[i] in acgt:
    cnt += 1
    if (ans < cnt):
      ans = cnt
  else:
    cnt = 0
print(ans)
alph={chr(i) for i in range(97,123)}
s=input()
n=len(s)

if n<26:
  print(s+sorted(alph-set(s))[0])
else:
  for i in range(2,27):
    if s[-i]<s[-i+1]:
      break
    if i==26:
      print(-1)
      exit()
for j in sorted(s[i+1:]):
  if j>s[i]:break
print(s[:i]+j)

### FIXED CODE ###

a={chr(i) for i in range(97,123)}
s=input()
n=len(s)
if n<26:
  print(s+sorted(a-set(s))[0])
else:
  for i in range(2,27):
    if s[-i]<s[-i+1]:
      break
    if i==26:
      print(-1)
      exit()
  for j in sorted(s[-i+1:]):
    if j>s[-i]:break
  print(s[:-i]+j)
import sys
readline = sys.stdin.buffer.readline

from collections import Counter


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

S = sum(A)
C = Counter(A)

ans = []
for _ in range(Q):
    b, c = map(int, input().split())
    count = C[b]
    S += (c - b) * count
    C[b], C[c] = 0, C[c] + count
    ans.append(S)

print('\n'.join(map(str, ans)))

### FIXED CODE ###

#import numpy as np
from collections import Counter
from time import time

import sys
readline = sys.stdin.buffer.readline


N = int(input())
A = list(map(int, input().split()))
#A = np.random.randint(1, 10 ** 5 + 1, 10 ** 5)

S = sum(A)
C = Counter(A)

Q = int(input())
#Q = 10 ** 5

ans = []
s = time()
for _ in range(Q):
    b, c = map(int, input().split())
    #b, c = np.random.randint(1, 10 ** 5 + 1, 2)
    #b, c = 2, 5

    count = C[b]
    S = S + (c - b) * count

    C[c] += count
    C[b] = 0
    
    ans.append(S)

print('\n'.join(map(str, ans)))
#print('time: ', time() - s)
S = input()
N = len(S)

for i in range(N):
    if S[2*i] == 'R':
        print('No')
        break
    else S[2*i+1] == 'L':
        print('No')
        break

print('Yes')

### FIXED CODE ###

S = input()
N = len(S)
ans = 'Yes'

for i in range(N):   
    if S[i] == 'R' and (i+1)%2 == 0:
        ans = 'No'
        break
    elif S[i] == 'L' and (i+1)%2 == 1:
        ans ='No'
        break

print(ans)
D = int(input())
c = list(map(int,input().split()))
s = [list(map(int,input().split())) for _ in range(D)]
t = [int(input()) for _ in range(D)]

S = 0
last = [-1]*26
score = 0;
for d in range(D):
    S += s[d][t[d]]
    last[t[d]] = d
    for i in range(26):
        S-=c[i]*(d - last[i])
    score +=max(10**6+S,0)
    print(S)


### FIXED CODE ###

D = int(input())
c = list(map(int,input().split()))
s = [list(map(int,input().split())) for _ in range(D)]
t = [int(input())-1 for _ in range(D)]

S = 0
last = [-1]*26
score = 0;
for d in range(D):
    S += s[d][t[d]]
    last[t[d]] = d
    for i in range(26):
        S-=c[i]*(d - last[i])
    score +=max(10**6+S,0)
    print(S)
S = input (　)

if S == 'sun':
    print(7)
elif S == 'MON':
    print(6)
elif S == 'TUE':
    print(5)
elif S == 'WED':
    print(4)
elif S == 'THU':
    print(3)
elif S == 'FRI':
    print(2)
elif S == 'SAT':
    print(1)


### FIXED CODE ###

S = input ()

if S == 'SUN':
    print(7)
elif S == 'MON':
    print(6)
elif S == 'TUE':
    print(5)
elif S == 'WED':
    print(4)
elif S == 'THU':
    print(3)
elif S == 'FRI':
    print(2)
elif S == 'SAT':
    print(1)
while True:
	a=raw_input()
	if a == "0 ? 0":
		break
	b=a.split()
	for i,c in enumerate(b):
		if i==0:
			x=int(c)
		elif i==1:
			y=c
		else:
			z=int(c)
	if y=='+':
		w=x+z
	elif y=='-':
		w=x-z
	elif y=='*':
		w=x*z
	elif y=='/':
		w=x/z
	print w

### FIXED CODE ###

while 1:
 try:print input()
 except:break
c=input()
print(chr(ord(c)+1)

### FIXED CODE ###

c=input()
d=ord(c)+1
e=chr(d)
print(e)
import sys
import math

line = []
for l in sys.stdin:
    for i in l.split(' '):
    	line.append(float(i))
a = (line[0]-line[2])**2+(line[1]-line[3])**2
b = math.sqrt(a)
print ('%.4f' % b)

### FIXED CODE ###

import math

x1,y1,x2,y2 = map(float,raw_input().split())
a = math.sqrt((x1-x2)**2+(y1-y2)**2)
print '%f'%a
# cook your dish here
n,k=input().split()
n=int(n)
k=int(k)
l=list(map(int,input().split()))
for j in range(n):
	if l[k+j]>l[j]:
    	print("Yes")
	else:
      print("No")
    if k+j==n-1:
      break
      
   


    


### FIXED CODE ###

# cook your dish here
n,k=input().split()
n=int(n)
k=int(k)
l=list(map(int,input().split()))
for j in range(n):
    if k+j==n:
        break
    if l[k+j]>l[j]:
        print("Yes")
    else:
        print("No")
import numpy as np
import sys
sys.setrecursionlimit(10**5)
input = sys.stdin.readline

def dfs(v,G,visit):
    visit[v-1]=1    
    for next in G[v-1]:        
        if visit[next-1]:
            continue
        if dfs(next,G,visit) == True:
            return True  
 
N, M =map(int, input().split())
G  = [[] for _ in range(N)]
for i in range(M):
    a,b ,_= map(int, input().split())
    G[a-1].append(b)
    G[b-1].append(a)
 
count = 0

visit = np.array([0]*N)
for i in range(1,N+1):
  if visit[i-1]:
    continue
  if G[i-1]:  
    _ = dfs(i,G,visit)
  else:
    visit[i-1] = 1
  count += 1

print(count)

### FIXED CODE ###

import numpy as np
import sys
sys.setrecursionlimit(10**5+1)
input = sys.stdin.readline

def dfs(v,G,visit):
    visit[v-1]=1    
    for next in G[v-1]:        
        if visit[next-1]:
            continue
        _ = dfs(next,G,visit) 
 
N, M =map(int, input().split())
G  = [[] for _ in range(N)]
for i in range(M):
    a,b ,_= map(int, input().split())
    G[a-1].append(b)
    G[b-1].append(a)
 
count = 0

visit = np.array([0]*N)
for i in range(1,N+1):
  if visit[i-1]:
    continue
  if G[i-1]:  
    _ = dfs(i,G,visit)
  else:
    visit[i-1] = 1
  count += 1

print(count)
a,b,c=map(int,input().split());print('
NYoe s'[a<=c<=b::2])

### FIXED CODE ###

a,b,c=map(int,input().split());print('NYoe s'[a<=c<=b::2])
a,b=map(int,input().split())
ans=0
if a==b:
  print(0)
  exit()  
if b>0:
  if abs(a)<abs(b):
    if a<0:
      ans+=1
      ans+=b+a  
    else:
      ans+=b-a  
  else:
    raise "eerot"
    if a<0:
      ans+=abs(a)-b+1  #正
    else:
      ans+=a-b+1 #正
else:
  if abs(a)<abs(b):
    if a<0:  
      ans+=2
      ans+=a-b
    else:
      ans+=abs(b)-a
      ans+=1 
  else:
    if a<0:  #正
      ans+=b-a
    else:
      ans+=a+b+1  #正
print(ans) 

### FIXED CODE ###

a,b=map(int,input().split())
ans=0
if a==b:
  print(0)
  exit()  
if b>0:
  if abs(a)<abs(b):
    if a<0:
      ans+=1
      ans+=b+a  
    else:
      ans+=b-a  
  else:
    if a<0:
      ans+=abs(a)-b+1
    else:
      ans+=a-b+2
else:
  if abs(a)<abs(b):
    if a<0:  
      ans+=2
      ans+=a-b
    else:
      ans+=abs(b)-a
      ans+=1 
  else:
    if a<0:
      ans+=b-a
    else:
      ans+=a+b+1
print(ans)
h,w,d,*l=map(int,open(0).read().split())
s=h*w+1;x=[0]*s;y=[0]*s;k=[0]*s
for i,a in enumerate(l[:s]):x[a]=i//w;y[a]=i%w
for i in range(d+1,s-1):k[i]=k[i-d]+abs(x[i]-x[i-d])+abs(y[i]-y[i-d])
for l,r in zip(l[s::2],l[s+1::2]):print(k[r]-k[l])

### FIXED CODE ###

h,w,d,*l=map(int,open(0).read().split())
s=h*w
x=[0]*(s+1)
y=[0]*(s+1)
for i,a in enumerate(l[:s]):
	x[a]=i//w
	y[a]=i%w
ref=[0]*(s+1)
for i in range(d+1,s+1):
	ref[i]=ref[i-d]+abs(x[i]-x[i-d])+abs(y[i]-y[i-d])
for l,r in zip(l[s+1::2],l[s+2::2]):
	print(ref[r]-ref[l])
import math
n = int(input())
num = [int(input()) for i in range(5)]
print(int(4+math.ceil(n/min(min(num)))))

### FIXED CODE ###

import numpy as np
s = [int(i) for i in input()]

n = len(s)

list01 = [int(i%2) for i in range(n)]
list10 = [int((i+1)%2) for i in range(n)]

        
list_a = np.array(s) - np.array(list01)
list_b = np.array(s) - np.array(list10)

count0 = np.sum(list_a == 0)
count1 = np.sum(list_b == 0)
countmin = min((n-count0),(n-count1))
print(countmin)
from itertools import permutations as perm
import sys
import math
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
XY = np.array(read().split(), np.int64)
X = XY[0::2]
Y = XY[1::2]

res = 0
cnt = 0
for p in perm(range(N)):
    for i in range(N - 1):
        res += math.sqrt((X[p[i + 1]] - X[p[i]])**2 + (Y[p[i + 1]] - Y[p[i]])**2)
    cnt += 1    
print(res/cnt)

### FIXED CODE ###

import numpy as np
import sys
import math
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
XY = np.array(read().split(), np.int64)
X = XY[0::2]
Y = XY[1::2]

t = 0
for i in range(N):
    for j in range(i, N):
        t += math.sqrt((X[i] - X[j])**2 + (Y[i] - Y[j])**2)
print(2*t/N)
N, M = tuple(int(c) for c in input().split(' '))
A = tuple(int(c) for c in input().split(' '))
if len(sum(A)) > N:
  print(-1)
else:
  print(len(sum(A)) > N)

### FIXED CODE ###

N, M = tuple(int(c) for c in input().split(' '))
A = tuple(int(c) for c in input().split(' '))
if sum(A) > N:
  print(-1)
else:
  print(N - sum(A))
from itertools import*
n,c=map(int,input().split())
cost=[list(map(int,input().split()))for i in range(c)]
d=[[0]*c for i in range(3)]
for i in range(n):
    for j,v in enumerate(map(int,input().split())):
        d[(i+j)%3][v-1]+=1
print(min(sum(d[j][cmb[i]]*cost[i][j]for j in range(c)for i in range(3))for cmb in permutations(range(c),3)))

### FIXED CODE ###

from itertools import*
n,c=map(int,input().split())
cost=[list(map(int,input().split()))for i in range(c)]
d=[[0]*c for i in range(3)]
for i in range(n):
    for j,v in enumerate(map(int,input().split())):
        d[(i+j)%3][v-1]+=1
print(min(sum(cost[j][cmb[i]]*d[i][j]for j in range(c)for i in range(3))for cmb in permutations(range(c),3)))
s = input()
hi = 'hi'

if hi == s:
  return "Yes"
elif hi == hi * 2:
  return "Yes"
elif hi == hi * 3:
  return "Yes"
elif hi == hi ** 4:
  return "Yes"
elif hi == hi ** 5:
  retrn "Yes"
else:
  return "No"

### FIXED CODE ###

s = input()

if s == 'hi':
  print('Yes')
elif s == 'hihi':
  print('Yes')
elif s == 'hihihi':
  print('Yes')
elif s == 'hihihihi':
  print('Yes')
elif s == 'hihihihihi':
  print('Yes')
else:
  print('No')
a, b, c, d = map(int, input().split())
while a > 0 and c > 0:
  c -= b
  a -= d
if c <= 0:
  print('Yes')
else:
  print('No')

### FIXED CODE ###

S, W = map(int, input().split())
if S <= W:
  print('unsafe')
else:
  print('safe')
n = int(input())
di = [list(map(int, input().split(' '))) for _ in range(n)]
di.sort(reverse = True)
result = []
for i in range(n-1):
    result.append([di[i][0]-di[i+1][0], di[i][1]-di[i+1][1]])
result.sort()
counter = []
z = 1
c = 1
hantei = result[0]
while z <= n-1:
    if z < n-1:
        if hantei == result[z]:
            c += 1
            z += 1
        else:
            counter.append(c)
            c = 1
            hantei = result[z]
            z += 2
    else:
        counter.append(c)
        z += 1
print(n-max(counter))

### FIXED CODE ###

#from collections import defaultdict
n = int(input())
di = [list(map(int, input().split(' '))) for _ in range(n)]
result = {0:0}
#md = defaultdict(int)
for i in range(n):
    for j in range(n):
        if i == j:
            continue
        else:
            p = di[i][0] - di[j][0]
            q = di[i][1] - di[j][1]
            result[(p,q)] = result.get((p,q), 0)+1
            #md[(p,q)] += 1
#print(result)
print(n - max(result.values()))
#print(md)
#print(n - max(md.values()))
while(True):
    a = raw_input()
    b = raw_input()
    a = str(a)
    b = str(b)
    length = len(a)
    if a == b[0:length]:
        print("Yes")
    else:
        print("No")


### FIXED CODE ###

a = input()
b = input()
a = str(a)
b = str(b)
length = len(a)
if a == b[0:length]:
    print("Yes")
else:
    print("No")
a,b,c,d = map(int, input().split())

B-A = abs(b-a)
C-B = abs(c-b)
C-A = abs(c-a)

if B-A <= d and C-B <= d:
    print("Yes")
elif c-a =< d:
    print("Yes") 
else:
    ("No")


### FIXED CODE ###

a,b,c,d = map(int,input().split())
B_A = abs(b - a)
C_B = abs(c - b)
C_A = abs(c - a)
if B_A <= d and C_B <=d:
    print('Yes')
elif C_A <= d:
    print('Yes')
else:
    print('No')
a=input()
b=input()
c=6-a-b
print(c)

### FIXED CODE ###

a=input()
b=input()
c=6-a-b
print(c)
N,M = map(int,input().split())
if N = M:
		print('Yes')
else:
		print('No')

### FIXED CODE ###

N,M = map(int,input().split())
if N == M:
		print('Yes')
else:
		print('No')
h1,m1,h2,m2,k=list(map(int,input().split()))
if m1=m2:
    m=0
    h=h2-h1
elif m2-m1>0:
    m=m2-m1
    h=h2-h1
else:
    m=60-m1+m2
    h=h2-h1-1
ans=k-m+h*60
if ans<=0:
    print(0)
else:
    print(ans)



### FIXED CODE ###

h1,m1,h2,m2,k=list(map(int,input().split()))
if m1==m2:
    m=0
    h=h2-h1
elif m2-m1>0:
    m=m2-m1
    h=h2-h1
else:
    m=60-m1+m2
    h=h2-h1-1
ans=(k-(m+h*60))*(-1)
if ans<=0:
    print(0)
else:
    print(ans)
import sys
sys.setrecursionlimit(1500)
n=int(input())
arr=list(map(int,input().split()))
vis={}
def count(n):
    if n in vis:
        return vis[n]
    if n<2:
        return 0
    if n==2:
        vis[n]=(abs(arr[n-1]-arr[n-2])+count(n-1))
    if n>=3:
        vis[n]=min(abs(arr[n-1]-arr[n-2])+count(n-1),abs(arr[n-1]-arr[n-3])+count(n-2))
    return vis[n]
print(count(n-1))

### FIXED CODE ###

n=int(input())
arr=list(map(int,input().split()))
if n < 2:
  print(0)
vis = [0] * n
vis[0] = 0
vis[1] = abs(arr[0]-arr[1])
for i in range(2, n):
    step_1 = abs(arr[i]-arr[i-1]) + vis[i-1]
    step_2 = abs(arr[i]-arr[i-2]) + vis[i-2]
    vis[i] = min(step_1, step_2)
print(vis[-1])
# coding: utf-8
N, M = map(int, input().split())
d = {}
ans = ["0" for _ in range(N)]
for i in range(M):
    s, c = map(int, input().split())
    if s not in d.keys():
        d[s] = c
        ans[s-1] = str(c)
    else:
        if d[s] != c:
            ans = -1
            print(ans)
            exit()
ans = "".join(ans)
if ans[0] == "0" and 1 not in d.keys():
    ans[0] = "1"
if len(str(int(ans))) != N:
    ans = -1
print(ans)

### FIXED CODE ###

# coding: utf-8
N, M = map(int, input().split())
d = {}
ans = ["0" for _ in range(N)]
for i in range(M):
    s, c = map(int, input().split())
    if str(s) not in d.keys():
        d[str(s)] = c
        ans[s-1] = str(c)
    else:
        if d[str(s)] != c:
            print(-1)
            exit()
if N == 1:
    print("".join(ans))
    exit()
if "1" not in d.keys():
    ans[0] = "1"
ans = "".join(ans)
if ans[0] == "0" and N != 1:
    print(-1)
else:
    print(int(ans))
try:
  n = int(input())

  if n %2 ==1:
    print(0)
  else:
    mod = 10
    ans = n//mod
    x = n//mod
    while(x>0):
      mod *= 5
      x = n//mod
      ans+=x
print(ans)
except Exception as e:
  print(e)


### FIXED CODE ###

n = int(input())

if n %2 ==1:
  print(0)
else:
  mod = 10
  ans = 0
  x = 0
  while True:
    x = n//mod
    if x==0: break
    ans+=x
    mod *= 5
  print(ans)
from functools import lru_cache


@lru_cache(maxsize=None)
def popcount(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    x = x + (x >> 64)
    return x & 0x0000007f


@lru_cache(maxsize=None)
def rec(n):
    if n == 0:
        return 0
    else:
        return rec(n % popcnt(n)) + 1


n = int(input())
arr = input()

li = []

for i in range(n):
    tmp = arr[:i] + str(1 ^ int(arr[i])) + arr[i + 1:]
    li.append(int(tmp, 2))

for x in li:
    print(rec(x))

### FIXED CODE ###

from functools import lru_cache


def popcnt(x):
    return bin(x).count("1")


@lru_cache(maxsize=None)
def rec(n):
    if n == 0:
        return 0
    else:
        return rec(n % popcnt(n)) + 1


ret = [rec(x) for x in range(2 * 10**5 + 1)]


n = int(input())
arr = input()

ALL_ARR = int(arr, 2)

cnt = popcnt(int(arr, 2))
init_big = ALL_ARR % (cnt + 1)
if cnt == 1:
    init_small = 0
else:
    init_small = ALL_ARR % (cnt - 1)


li = [0] * n
for i in range(n):
    if arr[i] == "0":
        li[i] = (init_big + pow(2, n - i - 1, cnt + 1)) % (cnt + 1)
    elif ALL_ARR - (1 << (n - i - 1)) == 0 or cnt - 1 == 0:
        li[i] = "flg"
    else:
        li[i] = (init_small - pow(2, n - i - 1, cnt - 1)) % (cnt - 1)


ans = []

for x in li:
    if x == "flg":
        ans.append(0)
    else:
        ans.append(ret[x] + 1)

print(*ans, sep="\n")
N,M=map(int,input().split())
s=[]
c=[]
x=dict()
for i in range(M):
    a,b=map(int,input().split())
    s.append(a)
    c.append(b)
    if a in x:
        if b!=x[a]:
            print(-1)
            exit()
    else:
        x[a]=b
l=[]
if N!=1:
    if c[0]==0:
        print(-1)
        exit()

for i in range(N):
    if i==0:
        l.append(1)
    else:
        l.append(0)
for i in range(M):
    l[s[i]-1]=c[i]
ans=""
#print(l)

for i in range(N):
    ans=ans+str(l[i])
print(ans)

### FIXED CODE ###

N,M=map(int,input().split())
s=[]
c=[]
x=dict()
for i in range(M):
    a,b=map(int,input().split())
    s.append(a)
    c.append(b)

for i in range(M):
    if s[i] in x:
        if c[i]!=x[s[i]]:
            print(-1)
            exit()
    else:
        x[s[i]]=c[i]

if M==0:
    ans=""
    for i in range(N):
        if i==0:
            ans="1"
        else:
            ans=ans+"0"
    if N==1:
        print(0)
        exit()
    print(ans)
    exit()
l=[]
if N!=1:
    for i in range(M):
        if s[i]==1:
            if c[i]==0:
                print(-1)
                exit()


for i in range(N):
    if i==0:
        l.append(1)
    else:
        l.append(0)
if N==1:
    l=[]
    l.append(0)
for i in range(M):
    l[s[i]-1]=c[i]
ans=""
#print(l)

for i in range(N):
    ans=ans+str(l[i])
print(ans)
x,a,b=map(int,input().split())
print('A' if min(abs(a-x),abs(b-x)))==abs(a-x) else 'B')


### FIXED CODE ###

x,a,b=map(int,input().split())
print('A' if min(abs(a-x),abs(b-x))==abs(a-x) else 'B')
import sys


def solve(n, aaa):
    if n == 2:
        h, m = divmod(sum(aaa), 2)
        if m == 1 or h > aaa[0]:
            return -1
        return aaa[0] - h

    x = 0
    for a in aaa[2:]:
        x ^= a
    a0, a1 = aaa[:2]
    s = a0 + a1

    if s & 1 != x & 1:
        return -1

    p, q = 0, 0

    b = 1 << 40
    while b:
        bx = x & b
        if bx == 0:
            # print('bx', s)
            # print(f'{b:040b}')
            # print(f'{p:040b}')
            # print(f'{q:040b}')
            # print(f'{a0:040b}')
            # print(f'{a1:040b}')
            # print()
            if s >= 2 * b:
                if p + b <= a0:
                    p |= b
                    q |= b
                    s -= 2 * b
                else:
                    return -1
        else:
            if s < b:
                return -1
            if p + b <= a0 and q + b > a1:
                p |= b
            else:
                q |= b
            s -= b

        # print(f'{b:040b}')
        # print(f'{p:040b}')
        # print(f'{q:040b}')
        # print(f'{a0:040b}')
        # print(f'{a1:040b}')
        # print()

        b >>= 1

    if p == 0:
        return -1
    assert s == 0
    assert p ^ q == x
    assert a0 - p == q - a1
    return a0 - p


n, *aaa = map(int, sys.stdin.buffer.read().split())
ans = solve(n, aaa)
if ans == -1:
    raise RuntimeError
print(solve(n, aaa))


### FIXED CODE ###

import sys


def solve(n, aaa):
    if n == 2:
        h, m = divmod(sum(aaa), 2)
        if m == 1 or h > aaa[0]:
            return -1
        return aaa[0] - h

    x = 0
    for a in aaa[2:]:
        x ^= a
    a0, a1 = aaa[:2]
    s = a0 + a1

    if s & 1 != x & 1:
        return -1

    p, q = 0, 0

    b = 1 << 40
    swappable = []
    while b:
        bx = x & b
        if bx == 0:
            # print('bx=0', s)
            # print(f'{b:040b}')
            # print(f'{p:040b}')
            # print(f'{q:040b}')
            # print(f'{a0:040b}')
            # print(f'{a1:040b}')
            # print()
            if s >= 2 * b:
                if p | b <= a0:
                    p |= b
                    q |= b
                    s -= 2 * b
                elif swappable:
                    bs = swappable.pop()
                    p ^= bs
                    q ^= bs
                    p |= b
                    q |= b
                    s -= 2 * b
                else:
                    return -1
        else:
            if s < b:
                return -1
            if p | b <= a0 and q | b > a1:
                p |= b
                swappable.append(b)
            else:
                q |= b
            s -= b

            # print('bx=1', s)
            # print(f'{b:040b}')
            # print(f'{p:040b}')
            # print(f'{q:040b}')
            # print(f'{a0:040b}')
            # print(f'{a1:040b}')
            # print()

        b >>= 1

    if p == 0:
        return -1
    assert s == 0
    assert p ^ q == x
    assert a0 - p == q - a1
    return a0 - p


n, *aaa = map(int, sys.stdin.buffer.read().split())
print(solve(n, aaa))
s=input()
l = []
cnt = 0
for i in s:
    if i =='A'or i == 'C' or i == 'G' or i == 'T':
        cnt +=1
        l.append(cnt)
    else:
        cnt = 0
print(max(l))

### FIXED CODE ###

s=input()
l = [0]
cnt = 0
for i in s:
    if i =='A'or i == 'C' or i == 'G' or i == 'T':
        cnt +=1
        l.append(cnt)
    else:
        cnt = 0
print(max(l))
import math

A,B = map(int, input().split())
print(A * B // math.gcd(A, B))

### FIXED CODE ###

import fractions

A,B = map(int, input().split())
print(A * B // fractions.gcd(A, B))
def main():
    N = int(input())
    dp = [0]*N
    array = []
    sum = 0
    for i in range(N):
        array2 = list(map(int,input().split()))
        array.append(array2)
    num = [[0,0,0] for z in range(N)]
    dp[0] = max(array[0][n] for n in range(3))
    for m in range(3):
        if dp[0] == array[0][m]:
            num[0][m] = 1
    
    
    for z in range(3):
        if num[0][z] == 1:
            dp[1] = max(dp[1],max(array[1][1],array[1][2])+dp[0])
            num[1][z] = 1
    
    print(num)
    for j in range(2,N):
        dpj = []
        for z in range(3):
            if 1 == num[j-1][z]:
                num[j][z] = 1
                dpj.append(max(array[j][1],array[j][2])+dp[j-1])
        dp[j] = max(dpj)
    
    print(dp[-1])
    
main()

### FIXED CODE ###

def main():
    N = int(input())
    
    array = []
    
    for i in range(N):
        array2 = list(map(int,input().split()))
        array.append(array2)

    num = [[0,0,0] for z in range(N)]
    for m in range(3):
        num[0][m] = array[0][m]

    

    for j in range(1,N):
        
        for z in range(3):
            if z == 0:
                num[j][z] = array[j][z]+max(num[j-1][1],num[j-1][2])
                    
            if z == 1:
                num[j][z] =array[j][z]+max(num[j-1][0],num[j-1][2])
            if z == 2:
                num[j][z] =array[j][z]+max(num[j-1][1],num[j-1][0])
        
    
    print(max(num[-1]))
    
main()
n = int(input())
anagrams = ["".join(sorted(input())) for i in range(n)]
import pandas as pd
import math

print(sum([math.factorial(i-1) for i in pd.DataFrame(anagrams, columns=["word"]).groupby("word")["word"].count().values]))

### FIXED CODE ###

n = int(input())
anagrams = ["".join(sorted(input())) for i in range(n)]
from collections import defaultdict
d = defaultdict(list)
for i in range(n):
    d[anagrams[i]].append(i)
from scipy.misc import comb
cnt=0
for k, v in d.items():
    cnt+=comb(len(v), 2, exact=True)
print(cnt)