Harryxun/stf_run huggingface dataset:
from collections import Counter
from heapq import heappush, heappop
N = int(input())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))
ctall = Counter(As + Bs)
mcvalue, mccount = ctall.most_common(1)[0]

if mccount > N:
    print('No')
    exit()

print('Yes')
ctA = Counter(As)
ctB = Counter(Bs)

q = []
for k, v in ctA.items():
    if ctB[k] > 0:
        heappush(q, [-(ctA[k]+ctB[k]), k])
onlyBs = []
for k, v in ctB.items():
    if ctA[k] == 0:
        onlyBs += [k] * v

ans = []
for a in As:
    if q:
        ct, k = heappop(q)
        if a == k:
            if q:
                ct2, k2 = heappop(q)
                ctB[k2] -= 1
                ans.append(k2)
                if ctB[k2] > 0:
                    heappush(q, [ct2+1, k2])
            else:
                ans.append(onlyBs.pop())
            heappush(q, [ct+1, k])
        else:
            ctB[k] -= 1
            ans.append(k)
            if ctB[k] > 0:
                heappush(q, [ct+1, k])
    else:
        ans.append(onlyBs.pop())


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


### FIXED CODE ###

from collections import Counter
N = int(input())
As = input().split()
Bs = input().split()

allct = Counter(As + Bs)
if allct.most_common(1)[0][1] > N:
    print('No')
    exit()

lastInA = {}
firstInB = {}

for i, a in enumerate(As):
    lastInA[a] = i

for i, b in enumerate(Bs):
    if b not in firstInB:
        firstInB[b] = i

offset = 0
for k, v in lastInA.items():
    if k not in firstInB:
        continue
    tmp = v - firstInB[k] + 1
    offset = offset if offset > tmp else tmp

print('Yes')
print(' '.join(Bs[-offset:] + Bs[:-offset]))
import numpy as np
N=int(input())
A=np.array(list(map(int,input().split(' '))))
A=A-np.arange(N)
Amed=np.int(A.median())
err=[]
for b in (Amed,Amed+1):
    err.append(np.sum(np.abs(A-b)))
print(min(err))


### FIXED CODE ###

import numpy as np
N=int(input())
A=np.array(list(map(int,input().split(' '))))
A=A-np.arange(N)
Amed=np.int(np.median(A))
err=[]
for b in (Amed,Amed+1):
    err.append(np.sum(np.abs(A-b)))
print(min(err))
N = input()
data = list(map(int(input().split()))
            
print ("11")

### FIXED CODE ###

import math

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


BIG = pow(10,9)+7

dp = [BIG]*(N+1)

dp[0] = 0

for i in range(N):
    for j in range(i+1,i+3):
        if j<N:
            dp[j] = min(dp[j], dp[i] + abs(data[i]-data[j]))
            
print(dp[N-1])
print(123)
return 0

### FIXED CODE ###

a = int(input())


hs = [int(x) for x in input().split()]

if a == 1:
  print(0)
  exit()
dp = [0]* len(hs)


dp[0] = 0
dp[1] = abs(hs[1] - hs[0])

for i in range(2, a):
  dp[i] = min(abs(hs[i-1]- hs[i]) + dp[i-1], abs(hs[i-2]- hs[i]) + dp[i-2] )
  
print(dp[-1])
s = int(input())
change = s % 1000
if change == 0:
    print(0):
else:
    print(1000-change)

### FIXED CODE ###

s = int(input())
change = s % 1000
if change == 0:
    print(0)
else:
    print(1000-change)
n = int(input())

li = [int(input()) for i in range(n)]
ls = sorted(li, reverse = True)

m1 = ls[0]

for i in range(1,n):
    if(ls[i] != m1):
        m2 = ls[i]
        break

for i in li:
    print(m1 if(i != m1) else m2)

### FIXED CODE ###

n = int(input())

li = [int(input()) for i in range(n)]
ls = sorted(li, reverse = True)

m1 = ls[0]
m2 = ls[1]
"""
for i in range(0,n):
    if(ls[i] != m1):
        m2 = ls[i]
        break
"""

for i in li:
    print(m1 if(i != m1) else m2)
import sys
import bisect  # 二分法

MAX_N = 200005
INF = 10**9 + 5

N = int(sys.stdin.readline())
A = [int(x) for x in sys.stdin.readline().split()]
E = [[] for _ in range(N)]  # 辺の情報

for _ in range(N-1):
    u, v = map(int, sys.stdin.readline().split())
    E[u-1].append(v-1)
    E[v-1].append(u-1)

lis = [INF] * N
lis[0] = 1
ans = [0] * N 

def dfs(u,r=-1):

    # u を訪れたときの処理
    i = bisect.bisect_left(lis, A[u])  # 
    old = lis[i]  # 書き換え前の値を一時保存
    lis[i] = A[u]

    for v in E[u]:
        if v == r: continue  # 親は無視

        dfs(v,u)
    
    ans[u] = bisect.bisect_left(lis,INF-1)
    lis[i] = old  # 書き換え前の状態に戻す

dfs(0)
for i in range(N):
    print(ans[i])

### FIXED CODE ###

import sys
import bisect  # 二分法


MAX_N = 200005
INF = 10**9 + 5

sys.setrecursionlimit(MAX_N)

N = int(sys.stdin.readline())
A = [int(x) for x in sys.stdin.readline().split()]
E = [[] for _ in range(N)]  # 辺の情報

for _ in range(N-1):
    u, v = map(int, sys.stdin.readline().split())
    E[u-1].append(v-1)
    E[v-1].append(u-1)

lis = [INF] * N
ans = [0] * N 

def dfs(u,r=-1):

    # u を訪れたときの処理
    i = bisect.bisect_left(lis, A[u])  # 
    old = lis[i]  # 書き換え前の値を一時保存
    lis[i] = A[u]

    for v in E[u]:
        if v == r: continue  # 親は無視

        dfs(v,u)
    
    ans[u] = bisect.bisect_left(lis,INF-1)
    lis[i] = old  # 書き換え前の状態に戻す

dfs(0)
for i in range(N):
    print(ans[i])
import collections
def main4():
    dd = collections.defaultdict(int)
    n = int(input())
    res = 0
    for i in range(n):
        s = input()
        s.sort()
        dd[''.join(s)]+=1
    for i in dd.values():
        res += (i*(i-1))//2
    print(res)

if __name__ == '__main__':
    main4()

### FIXED CODE ###

import collections
def main4():
    n = int(input())
    l = []
    for i in range(n):
        s = input()
        l.append((sorted(s)))
    l.sort()
    dd = collections.defaultdict(int)
    k = []
    for i in range(n):
        k.append(''.join(l[i]))
    res = 0
    for i in range(n):
        dd[k[i]]+=1
    for i in dd.values():
        res += (i*(i-1))//2
    print(res)

if __name__ == '__main__':
    main4()
from functools import reduce

def euclid(a, b):
    if a < b:
        a, b = (b, a)

    while True:
        r = a % b
        if r == 0:
            break
        a, b = (b, r)

    return b


if __name__ == '__main__':
    n, x = tuple(map(int, input().split()))
    points = [int(x) for x in input().split()]
    if not x in points:
        points.append(x)

    buf = [abs(points[i + 1] - points[i]) for i in range(len(points) - 1)]
    print(reduce(lambda a,b: euclid(a, b), bur))


### FIXED CODE ###

from functools import reduce

def euclid(a, b):
    if a < b:
        a, b = (b, a)

    while True:
        r = a % b
        if r == 0:
            break
        a, b = (b, r)

    return b


if __name__ == '__main__':
    n, x = tuple(map(int, input().split()))
    points = [int(x) for x in input().split()]

    buf = [abs(p - x) for p in points]
    print(reduce(lambda a,b: euclid(a, b), buf))
r_c_str=input().split()
r_c=list(map(lambda i :int(i),r_c_str))
r=r_c[0]
c=r_c[1]
s_str=[input() for i in range(r)]
s_str=[i.split() for i in s_str]
s=[]
for i in s_str:
    s.append(list(map(lambda j :int(j),i)))
for i in range(r):
    s[i].append(sum(s[i]))
s.append([0,0,0,0,0,0])
for i in range(c):
    for j in range(r):
        s[4][i]+=s[j][i]
s[-1][-1]+=sum(s[4])
for i in s:
    print(*i)


### FIXED CODE ###

r_c_str=input().split()
r_c=list(map(lambda i :int(i),r_c_str))
r=r_c[0]
c=r_c[1]
s_str=[input() for i in range(r)]
s_str=[i.split() for i in s_str]
s=[]
for i in s_str:
    s.append(list(map(lambda j :int(j),i)))
for i in range(r):
    s[i].append(sum(s[i]))
s.append([])
for i in range(c+1):
    s[-1].append(0)
for i in range(c):
    for j in range(r):
        s[r][i]+=s[j][i]
s[-1][-1]+=sum(s[r])
for i in s:
    print(*i)
from math import sqrt
n = int(input())
cnt = 0
for i in range(1, n):
    for i in range(2, int(sqrt(n)) + 1):
        if i % j == 0:
            continue
    cnt += 1
print(cnt)

### FIXED CODE ###

a = int(input())
s = input()
if a >= 3200:
    print(s)
else:
    print("red")
import itertools
K, N = map(int, input().split())
A = list(map(int, input().split()))

A_list = list(itertools.permutations(l, N))

print(A_list)

### FIXED CODE ###

K,N = map(int, input().split())
A = [int(a) for a in input().split()]

ans = A[-1]-A[0]
for i in range(N-1):
    ans = min(ans, K-A[i+1]+A[i])
print(ans)
print('dummy')

orders = {
    'North': (2, 6, 3, 4, 1, 5),
    'East': (4, 2, 1, 6, 5, 3),
    'West': (3, 2, 6, 1, 5, 4),
    'South': (5, 1, 3, 4, 6, 2),
    'Right': (1, 3, 5, 2, 4, 6),
    'Left': (1, 4, 2, 5, 3, 6)
}

while True:
    n = int(input())
    if not n:
        break
    dice = list(range(1, 7))
    top = 1

    while n:
        dice = [dice[s - 1] for s in orders[input()]]
        top += dice[0]
        n -= 1
    print(top)

### FIXED CODE ###

orders = {
    'North': (2, 6, 3, 4, 1, 5),
    'East': (4, 2, 1, 6, 5, 3),
    'West': (3, 2, 6, 1, 5, 4),
    'South': (5, 1, 3, 4, 6, 2),
    'Right': (1, 3, 5, 2, 4, 6),
    'Left': (1, 4, 2, 5, 3, 6)
}

while True:
    n = int(input())
    if not n:
        break
    dice = list(range(1, 7))
    top = 1

    while n:
        dice = [dice[s - 1] for s in orders[input().strip()]]
        top += dice[0]
        n -= 1
    print(top)
import sys
sys.setrecursionlimit(10**7)
def lmi(): return list(map(int, input().split()))

n, m = lmi()

l = [0] * (n+1)
l[0] = 1

a = int(input())
k = 1
for i in range(n+1):

    if i != a:
        if i == 1:
            l[i] = 1
        elif i >= 2:
            l[i] = l[i-1] + l[i-2]
            l[i] %= 1000000007
    else:
        k += 1
        if k <= m:
            a = int(input())



#print(l)
print(l[n] % 1000000007)


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)
def lmi(): return list(map(int, input().split()))

n, m = lmi()

l = [0] * (n+1)
l[0] = 1

a = 0
if m != 0:
    a = int(input())
k = 1
for i in range(n+1):

    if i != a:
        if i == 1:
            l[i] = 1
        elif i >= 2:
            l[i] = l[i-1] + l[i-2]
            l[i] %= 1000000007
    else:
        k += 1
        if k <= m:
            a = int(input())



#print(l)
print(l[n] % 1000000007)
n,m = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]

breakFlag = False
for i in range(1,m-1):
    if a[i]%2==1:
        if a[0]%2==1:
            if a[len(a)-1]%2==1:
                print("Impossible")
                breakFlag = True
                break
            else:
                a[i],a[len(a)-1] = a[len(a)-1],a[i]
        else:
            a[i],a[0] = a[0],a[i]

if breakFlag==False:
    ans = ''.join([str(s)+" " for s in a])
    print(ans[:-1])
    if a[len(a)-1]==1:
        print(m-1)
        a.pop()
        a[0]+=1
    else:
        print(m)
        a[0]+=1
        a[len(a)-1] -= 1
    ans = ''.join([str(s)+" " for s in a])
    print(ans[:-1])

### FIXED CODE ###

n,m = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]

breakFlag = False
for i in range(1,m-1):
    if a[i]%2==1:
        if a[0]%2==1:
            if a[len(a)-1]%2==1:
                print("Impossible")
                breakFlag = True
                break
            else:
                a[i],a[len(a)-1] = a[len(a)-1],a[i]
        else:
            a[i],a[0] = a[0],a[i]

if breakFlag==False:
    ans = ''.join([str(s)+" " for s in a])
    print(ans[:-1])
    if m==1:
        if a[0]>1:
            a[0]-=1
            a.append(1)
            print(m+1)
        else:
            print(m)
    else:
        if a[len(a)-1]==1:
            print(m-1)
            a.pop()
            a[0]+=1
        else:
            print(m)
            a[0]+=1
            a[len(a)-1] -= 1
    ans = ''.join([str(s)+" " for s in a])
    print(ans[:-1])
# coding: utf-8
import time
import re
import math
import fractions

def main():
    list=[int(input()) for a in range(5)]
    index=0
    mn=1e9
    for a in range(len(list)):
        if list[a]<mn:
            mn=list[a]
            index=a
    print(sum(map(lambda x:math.ceil(x/10)*10),list)-(10-mn%10))

    
    
start=time.time()
main()
#print("処理速度 {}sec".format(time.time()-start))
#"YNeos"[True::2]
#A=list(map(int,input().split()))
#A,B,C=map(int,input().split())
#n=int(input())
# global n,A,s,memo,mx,mn,L,B


### FIXED CODE ###

# coding: utf-8
import time
import re
import math
import fractions

def main():
    lst=[int(input()) for a in range(5)]
    index=0
    mx=0
    total=0
    for a in range(len(lst)):
        if math.ceil(lst[a]/10)*10-lst[a]>mx:
            mx=math.ceil(lst[a]/10)*10-lst[a]
            index=a
    #print(index)
    for a in range(len(lst)):
        if a==index:
            total+=lst[a]
        else:
            total+=math.ceil(lst[a]/10)*10
    print(total)
    
start=time.time()
main()
#print("処理速度 {}sec".format(time.time()-start))
#"YNeos"[True::2]
#A=list(map(int,input().split()))
#A,B,C=map(int,input().split())
#n=int(input())
# global n,A,s,memo,mx,mn,L,B
N,X = map(int, input().split())
List = [int(x) for x in input().split()]
 
import math
List.append(X)
List.sort()
 
distance = []
for i in range(N):
    distance.append(List[i+1]-List[i])
 
d_min = min(distance)
 
num_list = []
 
c = 1
while c <= math.sqrt(d_min):
    if d_min%c == 0:
        num_list.append(c)
    c += 1
 
num_list2 = [1]*len(num_list)
for i in range(len(num_list)):
    num_list2[len(num_list)-i-1] = int(d_min/num_list[i])
 
num_list = num_list + num_list2
 
num_list.append(d_min)
j = len(num_list)-1
c2 = 0
while j >= 0:
    for k in range(len(distance)):
        if distance[k]%num_list[j] == 0:
            c2 += 1
    if c2 == len(distance):
        ans = num_list[j]
        j = 0
    j -= 1
 
print(ans)

### FIXED CODE ###

N,X = map(int, input().split())
List = [int(x) for x in input().split()]
 
import math
List.append(X)
List.sort()
 
distance = []
for i in range(N):
    distance.append(List[i+1]-List[i])
 
d_min = min(distance)
 
num_list = []
 
c = 1
while c <= math.sqrt(d_min):
    if d_min%c == 0:
        num_list.append(c)
    c += 1
 
num_list2 = [0]*len(num_list)
for i in range(len(num_list)):
    num_list2[len(num_list)-i-1] = int(d_min/num_list[i])
 
num_list = num_list + num_list2

num_list.append(d_min)

j = len(num_list)-1

while j >= 0:
    c2 = 0
    for k in range(len(distance)):
        if distance[k]%num_list[j] == 0:
            c2 += 1
    if c2 == len(distance):
        ans = num_list[j]
        j = 0
    j -= 1
 
print(ans)
def main():
    N, A, B = map(int, input().split())

    if (A + B) % 2 == 0:
        print(abs(A - ((A + B) // 2)))
    else:
        Y = min(B - 1, N - A)

        c = 0
        if 1 < A:
            A1 = 1
            c += A - 1
        c += 1
        B1 = (B - c)
        X = abs(A1 - ((A1 + B1) // 2) + c)

        c = 0
        if B < N:
            B2 = N
            c += B - 1
        c += 1
        A2 = (A + c)
        Z = (abs(A2 - ((A2 + B2) // 2)) + c)

        print(min(Y, X, Z))


main()


### FIXED CODE ###

def main():
    N, A, B = map(int, input().split())

    if (A + B) % 2 == 0:
        print(abs(A - ((A + B) // 2)))
    else:
        Y = min(B - 1, N - A)

        c = 0
        if 1 < A:
            c += A - 1
        c += 1
        B1 = B - c
        A1 = 1
        X = abs(A1 - ((A1 + B1) // 2)) + c
        if B1 < A1:
            X = 9999999999999999999999999999

        c = 0
        if B < N:
            c += N - B
        c += 1
        A2 = A + c
        B2 = N
        Z = abs(A2 - ((A2 + B2) // 2)) + c
        if B2 < A2:
            Z = 9999999999999999999999999999

        print(min(Y, X, Z))


main()
S = input()
T = "ACGT"
ans = 0
for s in S:
    if s in T:
        cnt += 1
    else:
        if cnt > ans:
            ans = cnt
        cnt = 0
print(ans)

### FIXED CODE ###

S = input()
T = "ACGT"
ans = 0
cnt = 0
for s in S:
    if s in T:
        cnt += 1
    else:
        if cnt > ans:
            ans = cnt
        cnt = 0
if cnt>ans:
    ans = cnt
print(ans)
import sys

N, M = map(int, sys.stdin.readline().split())

A = list(map(int, sys.stdin.readline().split()))
action_list = []
B = []
for i in range(M):
    temp_B, temp_C = map(int, sys.stdin.readline().split())
    action_list.append([temp_B, temp_C])
    B.append(temp_B)
action_list.sort(key = lambda x:x[1])
action_list.reverse()

current_list = A
current_list.sort()

k = 0
ans_sum = 0
count = 0
action_count = 0
for i in range(sum(B)):
    if current_list[i] < action_list[k][1]:
        ans_sum += action_list[k][1]
        count += 1
        action_count += 1
        if action_count == action_list[k][0]:
            k += 1
            action_count = 0
    else:
        break
    if count > N:
        break

ans_sum += sum(current_list[count:])
print(ans_sum)

### FIXED CODE ###

import sys

N, M = map(int, sys.stdin.readline().split())

A = list(map(int, sys.stdin.readline().split()))
action_list = []
B = []
for i in range(M):
    temp_B, temp_C = map(int, sys.stdin.readline().split())
    action_list.append([temp_B, temp_C])
    B.append(temp_B)
action_list.sort(key = lambda x:x[1])
action_list.reverse()

current_list = A
current_list.sort()

k = 0
ans_sum = 0
count = 0
action_count = 0
if sum(B) < N:
    times = sum(B)
else:
    times = N
for i in range(times):
    if current_list[i] < action_list[k][1]:
        ans_sum += action_list[k][1]
        count += 1
        action_count += 1
        if action_count == action_list[k][0]:
            k += 1
            action_count = 0
    else:
        break
    if count > N:
        break

ans_sum += sum(current_list[count:])
print(ans_sum)
from math import gcd
from functools import reduce
N = int(input())
A = list(map(int, input().split()))
B = [i for i in range(N)]
MOD = 10 ** 9 + 7
def lcm(a,b):
    return a * b // gcd(a, b)
h = reduce(lcm, A)

for i in range(N):
    B[i] = (h // A[i] % MOD)

print(sum(B) % MOD)


### FIXED CODE ###

from fractions import gcd
from functools import reduce
N = int(input())
A = list(map(int, input().split()))
MOD = 10 ** 9 + 7

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

def modpow(a, n, mod): # a^n mod
    result = 1
    while n > 0:
        if n & 1: result = result * a % mod
        a = a * a % mod
        n >>= 1
    return result

h = reduce(lcm, A)
B = [h * modpow(A[i], MOD-2, MOD) for i in range(N)]
print(sum(B) % MOD)
from heapq import heapify, heappop, heappush


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

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

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

    def union(self, x, y):
        r1 = self._root(x)
        r2 = self._root(y)
        if r1 == r2:
            return
        d1 = self.table[r1]
        d2 = self.table[r2]
        if d1 <= d2:
            self.table[r2] = r1
            if d1 == d2:
                self.table[r1] -= 1
        else:
            self.table[r1] = r2


def solve(aa, uft):
    roots = {x: [] for x, r in enumerate(uft.table) if r < 0}
    if n < (len(roots) - 1) * 2:
        return 'Impossible'
    for x, a in enumerate(aa):
        roots[uft._root(x)].append((a, x))
    queue = []
    for l in roots.values():
        heapify(l)
        queue.append((l[0][0], l))
    heapify(queue)
    ans = 0
    while len(queue) > 1:
        a1, q1 = heappop(queue)
        a2, q2 = heappop(queue)
        ans += a1 + a2
        heappop(q1)
        heappop(q2)
        q1 += q2
        heapify(q1)
        heappush(queue, (q1[0][0], q1))
    return ans


n, m = map(int, input().split())
aa = list(map(int, input().split()))
uft = UnionFind(n)
for _ in range(m):
    uft.union(*map(int, input().split()))
print(solve(aa, uft))


### FIXED CODE ###

from collections import deque, defaultdict
from heapq import heapify, heappop, merge, heapreplace


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

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

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

    def union(self, x, y):
        r1 = self._root(x)
        r2 = self._root(y)
        if r1 == r2:
            return
        d1 = self.table[r1]
        d2 = self.table[r2]
        if d1 <= d2:
            self.table[r2] = r1
            if d1 == d2:
                self.table[r1] -= 1
        else:
            self.table[r1] = r2


def solve(aa, uft):
    roots = defaultdict(list)
    for x, a in enumerate(aa):
        roots[uft._root(x)].append(a)
    if len(roots) == 1:
        return 0
    if n < (len(roots) - 1) * 2:
        return 'Impossible'
    ans = 0
    queue = []
    for l in roots.values():
        l.sort()
        ans += l[0]
        queue.append(l[1:])
    lm = n - m - 2
    if lm > 0:
        mm = merge(*queue)
        for _ in range(lm):
            ans += next(mm)
    return ans


n, m = map(int, input().split())
aa = list(map(int, input().split()))
uft = UnionFind(n)
for _ in range(m):
    uft.union(*map(int, input().split()))
print(solve(aa, uft))
import math
from functools import reduce


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


N = int(input())
T = [int(input()) for i in range(N)]

ans = T[0]
for t in T[1:]:
    ans = lcm(ans, t)

print(ans)

### FIXED CODE ###

from fractions import gcd


def lcm(a):
    x = a[0]
    for i in range(1, len(a)):
        x = (x * a[i]) // gcd(x, a[i])
    return x


N = int(input())
T = [int(input()) for _ in range(N)]

ans = lcm(T)

print(ans)
S = input('S>')
T = input('T>')
A = int(input('A>'))
B = int(input('B>'))
U = input('U>')

if(U == S):
  print(A-1)
elif(T == U):
  print(B-1)

### FIXED CODE ###

S, T = input().split()
A, B = map(int, input().split())
U = input()
 
if S == U :
  print(str(A - 1) + ' ' + str(B))
elif T == U :
  print(str(A) + ' ' + str(B - 1))
n = int(input())
ans = 0
for i in range(1, n + 1):
	if i % 3 != 0 and i % 5 != 0:
    	ans += i
print(ans)

### FIXED CODE ###

n = int(input())
ans = 0
for i in range(1, n + 1):
    if i % 3 != 0 and i % 5 != 0:
        ans += i
print(ans)
N = int(input())
e = [[int(i) for i in input().split()] for i in range(N)]
mar=e[0][0]
mir=e[0][0]
mav=0
miv=0
mv=0
mmv=e[i][1]
for i in range(N):
    if e[i][0] > mar:
        mar =e[i][0]
        mmv=e[i][1]
print(mar+mmv)

### FIXED CODE ###

N = int(input())
e = [[int(i) for i in input().split()] for i in range(N)]
mar=e[0][0]
mmv=e[0][1]
for i in range(N):
    if e[i][0] > mar:
        mar =e[i][0]
        mmv=e[i][1]
print(mar+mmv)
import sys
N = int(input())

time_lis = [0] * N
profit = [0] * N
for n in range(N):
    time_lis[n] = list(map(int, input().split()))
for n in range(N):
    profit[n] = list(map(int, input().split()))

ans = 0
always_zero = True
for n in range(N):
    count_1 = len([i for i in time_lis[n] if i == 1])
    tmp= max(profit[n][:count_1 + 1])
    ans += tmp
    if profit[n].index(tmp) != 0:
        always_zero = False
if always_zero:
    max_prof = sorted([(item[0], item[1]) for item in profit], key=lambda x: -x[1])
    print(ans - max_prof[0] + max_prof[1])
    sys.exit()
print(ans)

### FIXED CODE ###

n=int(input())
F=[[] for i in range(10)]
for i in range(n):
    for j,f in enumerate(list(map(int,input().split()))):
        if f:
            F[j].append(i)
P=[list(map(int,input().split())) for i in range(n)]
ans=-float("inf")
for i in range(1,1024):
    l=[0]*n
    for j in range(10):
        if i>>j&1:
            for k in F[j]:
                l[k]+=1
    t=0
    for j,k in enumerate(l):
        t+=P[j][k]
    ans=max(ans,t)
print(ans)