Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

from bisect import bisect_left
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0
for k in range(29):
    b_k = [i%2**(k+1) for i in b]
    b_k.sort()
    cnt_one_kbit = 0
    for ai in a:
        ai %= 2**(k+1)
        left = bisect_left(b_k, 2*2**k-ai) - bisect_left(b_k, 2**k - ai)
        right = bisect_left(b_k, 4*2**k - ai) - bisect_left(b_k, 3*2**k - ai)
        cnt_one_kbit += left+ right
    if cnt_one_kbit % 2:
        ans += 2**k
print(ans)

### FIXED CODE ###

# 写経
# https://atcoder.jp/contests/arc092/submissions/5244389

from bisect import bisect_left

INF = float('inf')

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

def calc_bit(k):
    # これ以上の桁は不要
    mod = 1 << (k + 1)
    amod = [a & (mod - 1) for a in A]
    bmod = [b & (mod - 1) for b in B]
    amod.sort()
    bmod.sort()
    ret = 0

    # bmod + amod のうち k ビット目が 1 となる数
    # => (1 << k) 以上 (2 << k) 未満または (3 << k) 以上 (4 << k) 未満
    # しゃくとる
    b01 = bisect_left(bmod, (1 << k) - amod[0])
    b10 = bisect_left(bmod, (2 << k) - amod[0])
    b11 = bisect_left(bmod, (3 << k) - amod[0])
    for a in range(len(amod)):
        while b01 - 1 >= 0 and bmod[b01 - 1] >= (1 << k) - amod[a]:
            b01 -= 1
        while b10 - 1 >= 0 and bmod[b10 - 1] >= (2 << k) - amod[a]:
            b10 -= 1
        while b11 - 1 >= 0 and bmod[b11 - 1] >= (3 << k) - amod[a]:
            b11 -= 1
        # (1 << k) 以上 (2 << k) 未満
        ret += b10 - b01
        # (3 << k) 以上 (4 << k) 未満
        ret += N - b11

    return ret % 2


ans = 0
for i in range(30):
    ans += calc_bit(i) * (1<<i)
print(ans)
### BUGGY CODE ###

a, b, k = map(int,input().split())
xs = [x for x in range(a,b+1) if x < a+k or x > b-k]
for x in xs:
    print(x)

### FIXED CODE ###

a, b, k = map(int, input().split())
if b-a+1 < 2*k:
    for i in range(a,b+1):
        print(i)
    exit(0)
for i in range(a,a+k):
    print(i)
for i in range(b-k+1,b+1):
    print(i)
### BUGGY CODE ###

n=int(input())
b=list(map(int,input().split()))
ans=[]
while len(b)>0:
  for i in range(len(b),0,-1):
    if b[i-1]==i:
      ans.append(b.pop(i-1))
ans.reverse()
for i in range(n):
  print(ans[i])

### FIXED CODE ###

n=int(input())
b=list(map(int,input().split()))
ans=[]
count=0
while len(b)>0:
  count+=1
  for i in range(len(b),0,-1):
    if b[i-1]==i:
      ans.append(b.pop(i-1))
      break
  if count==101:
    print(-1)
    exit()
ans.reverse()
for i in range(n):
  print(ans[i])
### BUGGY CODE ###

from math import gcd
n = int(input())
ans = 0
for i in range(1, n+1):
    for j in range(1, n+1):
        for k in range(1, n+1):
            a = gcd(i,j)
            ans+=gcd(a, k)
print(ans)


### FIXED CODE ###

from math import gcd
n = int(input())
ans = 0
for i in range(1, n+1):
    for j in range(1, n+1):
        for k in range(1, n+1):
            if i==j and j==k: ans+=i
            else:
                tmp = gcd(k, gcd(i,j))
                ans+=tmp
print(ans)
### BUGGY CODE ###

n = int(input())
s = list(map(int, input().rstrip()))
ans = [0] * 1000

for i in range(1000):
    if i < 10:
        x, y, z = 0, 0, i
    elif i < 100:
        x, y, z = 0, i // 10, i % 10
    else:
        x = i // 100
        y = (i - x * 100) // 10
        z = i % 10
    flg = 0
    for a in range(len(s) - 2):
        if flg == 1:
            break
        elif x != s[a]:
            continue
        else:
            for b in range(a + 1, len(s) - 1):
                if flg == 1:
                    break
                elif y != s[b]:
                    continue
                else:
                    for c in range(b + 1, len(s)):
                        if z != s[c]:
                            continue
                        else:
                            ans[x * 100 + y * 10 + z] = 1
                            flg = 1
                            break

print(sum(ans))

### FIXED CODE ###

n = int(input())
s = list(map(int, input().rstrip()))

ans = 0
for i in range(10):
    if i in s[:n - 2]:
        x = s.index(i)

        for j in range(10):
            if j in s[x + 1:n - 1]:
                y = x + s[x + 1:n - 1].index(j) + 1

                for k in range(10):
                    if k in s[y + 1:]:
                        ans += 1

print(ans)
### BUGGY CODE ###

#入力
n, W=map(int, input().split())
w,v=[],[]
for i in range(n):
  a,b=map(int,input().split())
  w.append(a)
  v.append(b)

# i番目以降から重さの総和がj 以下になるように選んだ時の重量
def rec(i,j):
  #既に計算されているなら、メモdp[][]を受け取る
  if dp[i][j]>=0:
    return dp[i][j]
  if i==n:#もう品物がないから終わり
    res=0
  elif w[i]>j:#i番目の荷物は入らないから次へ
    res= rec(i+1,j)
  else:#i番目の荷物が入る場合と入らない場合の両方を試す
    res=max(rec(i+1,j), rec(i+1,j-w[i]) +v[i])
  dp[i][j]=res
  return res

dp=[[-1 for i in range(W+1)] for j in range(n+1)]#メモの初期化
print(rec(0,W))

### FIXED CODE ###

N, W = map(int, input().split())

value_table = [[] for i in range(4)]
for i in range(N):
    w, v = map(int,input().split())
    if i == 0:
        w1 = w
    value_table[w-w1] += [v]

[value_table[i].sort(reverse=True) for i in range(4)]

ans = 0
value_table_ruiseki = [[0] for i in range(4)]
for i in range(4):
    for v in value_table[i]:
        value_table_ruiseki[i] += [value_table_ruiseki[i][-1] + v]

ans = 0
for i, iv in enumerate(value_table_ruiseki[0]):
    for j, jv in enumerate(value_table_ruiseki[1]):
        for k, kv in enumerate(value_table_ruiseki[2]):
            for ell, ellv in enumerate(value_table_ruiseki[3]):
                weight = i*w1 + j*(w1+1) + k*(w1+2) + ell*(w1+3)
                value = iv + jv + kv + ellv
                if weight <=W:
                    ans = max(ans, value)

print(ans)
### BUGGY CODE ###

n = int(input())

list = [1,2,3,4,5,6,7,8,9]

for i in range(n):
  x = list[0]
  mod_x = x%10
 # print(i,"番目　",x)
  list.pop(0)
  if mod_x != 0:
    list.append(10*x + (x%10) -1)
  list.append(10*x + (x%10))
  if mod_x != 9:
    list.append(10*x + (x%10) + 1)
print(x)


### FIXED CODE ###

import queue
n = int(input())
q = queue.Queue()
for i in range(9):
    q.put(i+1)
for i in range(n):
  x = q.get()
  mod_x, mul_x = x%10, 10*x
  if mod_x != 0: q.put(mul_x+mod_x-1)
  q.put(mul_x+mod_x)
  if mod_x != 9: q.put(mul_x+mod_x+1)
print(x)
### BUGGY CODE ###

import math

def combination(n, k):
    return math.factorial(n) // math.factorial(k) // math.factorial(n - k)


n=int(input())

t = list(map(int,input().split()))

a1 = max(t)

ans = 0

memo = 0

for i in t:
    if ans <= combination(a1,i):
        ans = combination(a1,i)
        memo = i
print(a1, memo)

### FIXED CODE ###

n=int(input())
 
t = list(map(int,input().split()))
t.sort()
a1 = max(t)
 
ans = 100000000000000
 
memo = 0

for i in t:
    if ans > abs(a1/2-i):
        ans = abs(a1/2-i)
        memo = i
print(a1, memo)
### BUGGY CODE ###

from collections import deque

n = int(input())
d = deque()
for _i in range(n):
    line = input().split()
    order = line[0]
    if order in ('insert', 'delete'):
        key = int(line[1])
    if order == 'insert':
        d.appendleft(key)
    elif order == 'delete':
        try:
            d.remove(key)
        except ValueError:
            pass
    elif order == 'deleteFirst':
        d.popleft()
    elif order == 'deleteLast':
        d.pop()
    else:
        raise ValueError('Invalid order: {order}')

i = 0
while True:
    try:
        if i == 0:
            print(d.popleft(), end='')
        else:
            print(f' {d.popleft()}', end='')
        i += 1
    except IndexError:
        break
print()


### FIXED CODE ###

from collections import deque

n = int(input())
d = deque()
for _i in range(n):
    order = input()
    if order == 'deleteFirst':
        d.popleft()
    elif order == 'deleteLast':
        d.pop()
    else:
        order, key = order.split()
        if order == 'insert':
            d.appendleft(key)
        elif order == 'delete':
            try:
                d.remove(key)
            except ValueError:
                pass
        else:
            raise ValueError('Invalid order: {order}')

print(' '.join(d))
### BUGGY CODE ###

n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
pa, pb = [0] * (n+1), [0] * (m+1)
for i in range(n):
    pa[i+1] = pa[i] + a[i]
for i in range(m):
    pb[i+1] = pb[i] + b[i]
m = 0
for i in range(len(pa)):
    if pa[i] > k:
        break
    v = k - pa[i]
    for j in range(len(pb)):
        if pb[j] > v:
            m = max(m, i+j-1)
            break
    else:
        m = max(m, i+j)
print(m)


### FIXED CODE ###

n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
pa, pb = [0] * (n+1), [0] * (m+1)
for i in range(n):
    pa[i+1] = pa[i] + a[i]
for i in range(m):
    pb[i+1] = pb[i] + b[i]
mx = 0
j = m
for i in range(n+1):
    if pa[i] > k:
        break
    v = k - pa[i]
    while pb[j] > v:
        j -= 1
    mx = max(mx, i+j)
print(mx)
### BUGGY CODE ###

import sys
input=lambda :sys.stdin.readline().rstrip()
n, m = map(int, input().split())

key = [0]*n
for _ in range(m):
    l, r = map(int, input().split())
    for i in range(l-1, r):
        key[i] = key[i]+1
print(len([i for i in key if i == m]))

### FIXED CODE ###

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

L = []
R = []
L_append = L.append
R_append = R.append
for l, r in LR:
    L.append(l)
    R.append(r)

min_R = min(R)
max_L = max(L)
if min_R >= max_L:
  ans = min_R +1 - max_L
else:
  ans = 0
  
print(ans)
### BUGGY CODE ###

s = list(input())
n = int(input())
flag = True
for _ in range(n):
    q = list(map(str, input().split()))
    if len(q) == 1:
        if flag:
            flag = False
        else:
            flag = True
    if len(q) == 3:
        if q[1] == "1":
            if flag:
                s = list(q[2])+s
            else:
                s = s+list(q[2])
        else:
            if flag:
                s = s+list(q[2])
            else:
                s = list(q[2])+s
if flag == False:
    s.reverse()
print("".join(s))

### FIXED CODE ###

from collections import deque
s = deque(list(input()))
n = int(input())
flag = True
for _ in range(n):
    q = list(map(str, input().split()))
    if len(q) == 1:
        if flag:
            flag = False
        else:
            flag = True
    if len(q) == 3:
        if (q[1] == "1" and flag == False) or (q[1] == "2" and flag):
            s.append(q[2])
        else:
            s.appendleft(q[2])
if flag == False:
    s.reverse()
print("".join(s))
### BUGGY CODE ###

import sys
from bisect import *
from collections import *
from copy import deepcopy
from heapq import *
from itertools import *
from math import *
from operator import *
from pprint import *
import numpy as np

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

def main():
    """ main """
    H,W = map(int, input().split())
    grid = [list(input().rstrip()) for _ in range(H)]
    q = []
    visited = [[False]*W for _ in range(H)]
    for y in range(H):
        for x in range(W):
            if grid[y][x] == '#':
                q.append((y,x))
                visited[y][x] = True
    ans = -1
    while q:
        ans += 1
        new_q = []
        for y,x in q:
            for dy,dx in [(1,0),(-1,0),(0,1),(0,-1)]:
                ny = y+dy
                nx = x+dx
                if 0<=ny<H and 0<=nx<W and not visited[ny][nx] and grid[ny][nx] == '.':
                    new_q.append((ny,nx))
                    visited[ny][nx] = True
        if new_q:
            q = new_q[:]
        else:
            break
    print(ans)

if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    H, W = map(int,input().split())
    visited = [[False]*W for _ in range(H)]
    q = []
    for y in range(H):
        S = input()
        for x, s in enumerate(S):
            if s == "#":
                q.append((y, x))
                visited[y][x] = True

    ans = -1
    while q:
        ans += 1
        nq = []
        for y, x in q:
            if 0 < x and not visited[y][x-1]:
                visited[y][x-1] = True
                nq.append((y,x-1))
            if x < W-1 and not visited[y][x+1]:
                visited[y][x+1] = True
                nq.append((y,x+1))
            if 0 < y and not visited[y-1][x]:
                visited[y-1][x] = True
                nq.append((y-1, x))
            if y < H-1 and not visited[y+1][x]:
                visited[y+1][x] = True
                nq.append((y+1,x))
        if nq:
            q = nq
        else:
            break

    print(ans)

if __name__ == '__main__':
    main()
### BUGGY CODE ###

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

for i in range(n):
    tmp = x[:i]+x[i+1:]
#     print(tmp)
    print(sorted(tmp)[(n-1)//2])    

### FIXED CODE ###

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

x_s = sorted(x)
med2 = x_s[n//2]
med1 = x_s[n//2-1]
for i in range(n):
    if x[i]<=med1:
        print(med2)
    else:
        print(med1)
### BUGGY CODE ###

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

mod = 10**9 + 7
d = 1
total = 0
while d < (1 << 60):
  cnt = 0
  for each in A:
    cnt += str(bin(each & d)).count('1')
  total += cnt * (n-cnt) * d
  total %= mod
  d <<= 1
print(total)

### FIXED CODE ###

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

mod = 10**9 + 7
total = 0
for i in range(60):
  cnt = sum([1 for a in A if (a>>i & 1)])
  total += cnt * (n-cnt) * (1 << i)
  total %= mod
print(total)
### BUGGY CODE ###

import collections
n = int(input())
a = list(map(int, input().split()))
q = int(input())
dic = collections.Counter(a)
for i in range(q):
    b, c = map(int, input().split())
    if b in dic and c not in dic:
        dic[c] = dic[b]
        del dic[b]
    elif b in dic and c in dic:
        dic[c] += dic[b]
        del dic[b]
    sum_list = [x * y for (x, y) in dic.items()]
    print(sum(sum_list))


### FIXED CODE ###

import collections
n = int(input())
a = list(map(int, input().split()))
q = int(input())
dic = collections.Counter(a)
sum_list = [x * y for (x, y) in dic.items()]
sum = sum(sum_list)
for i in range(q):
    b, c = map(int, input().split())
    if b in dic and c not in dic:
        sum -= (b - c) * dic[b]
        print(sum)
        dic[c] = dic[b]
        del dic[b]
    elif b in dic and c in dic:
        sum -= (b - c) * dic[b]
        print(sum)
        dic[c] += dic[b]
        del dic[b]
    else:
        print(sum)
### BUGGY CODE ###

x,y,z,k=map(int,input().split());a,b,c=list(map(int,input().split())),list(map(int,input().split())),list(map(int,input().split()))
aa=[]
for i in a:
  for j in b:aa.append(i+j)
aa.sort(reverse=1)
aa=aa[:k+1]
s=[]
for i in aa:
  for j in c:s.append(i+j)
s.sort(reverse=1)
for i in range(k):print(s[i])

### FIXED CODE ###

from heapq import heappop,heappush;import sys;input=sys.stdin.readline
x,y,z,k=map(int,input().split());a,b,c=list(map(int,input().split())),list(map(int,input().split())),list(map(int,input().split()))
q,h,l=[],[],0
for i in a:
  for j in b:heappush(q,-(i+j));l+=1
for _ in range(min(l,k)):
  t=heappop(q)
  for i in c:heappush(h,t-i)
for i in range(k):print(-heappop(h))
### BUGGY CODE ###

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


ans = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        sum=l[i]+l[j]
        left=j
        right=n-1
        mid=(left+right)//2
        while right-left>1:
            if l[mid]>=sum:
                right = mid
            else:
                left = mid
            mid = (left+right)//2
        if l[mid+1]<sum:
            mid+=1
        ans+=mid-j
print(ans)


### FIXED CODE ###

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


ans = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        sum=l[i]+l[j]
        left=j
        right=n-1
        mid=(left+right)//2
        while right-left>1:
            if l[mid]>=sum:
                right = mid
            else:
                left = mid
            mid = (left+right)//2
        if l[mid+1]<sum:
            mid+=1
        ans+=mid-j
print(ans)
### BUGGY CODE ###

from collections import deque
H, W = map(int, input().split())
G = [input() for _ in range(H)]
dist = dict()
bn = 0
B = deque()
geta = 10**9+7
for i, g in enumerate(G):
    for j, f in enumerate(g):
        if f == '#':
            bn += 1
            B.append(i*geta + j)
visited = set(B)
for b in B:
    dist[b] = 0
while bn < H*W:
    if not B:
        break
    dh, dw = divmod(B.pop(), geta)
    dhw = dh * geta + dw
    for di, dj in ((1, 0), (-1, 0), (0, 1), (0, -1)):
        ni, nj = dh + di, dw + dj
        if not (0 <= ni <= H - 1) or not (0 <= nj <= W - 1):
            continue
        nij = ni * geta + nj
        if nij in visited or G[ni][nj] == '#':
            continue
        visited.add(nij)
        dist[nij] = 1 + dist[dhw]
        B.appendleft(nij)
print(max(dist.values()))

### FIXED CODE ###

from collections import deque
H, W = map(int, input().split())
G = [input() for _ in range(H)]
dist = [0]*(H*W)
bn = 0
B = deque()
geta = W
for i, g in enumerate(G):
    for j, f in enumerate(g):
        if f == '#':
            bn += 1
            B.append(i*geta + j)
visited = set(B)
while bn < H*W:
    if not B:
        break
    dh, dw = divmod(B.pop(), geta)
    dhw = dh * geta + dw
    for di, dj in ((1, 0), (-1, 0), (0, 1), (0, -1)):
        ni, nj = dh + di, dw + dj
        if not (0 <= ni <= H - 1) or not (0 <= nj <= W - 1):
            continue
        nij = ni * geta + nj
        if nij in visited or G[ni][nj] == '#':
            continue
        visited.add(nij)
        dist[nij] = 1 + dist[dhw]
        B.appendleft(nij)
print(max(dist))
### BUGGY CODE ###

ninnzuu = (int)(input())
joushi = list(map(int, input().split(" ")))
txt = ""
for i in range(1, ninnzuu + 1):
    print((str)(joushi.count(i)))

### FIXED CODE ###

ninnzuu = (int)(input())
joushi = list(map(int, input().split(" ")))
buka = [0 for i in range(ninnzuu)]
for i in range(ninnzuu - 1):
    buka[joushi[i]] += 1
for i in range(1, ninnzuu):
  print(buka[i])
print(0)
### BUGGY CODE ###

r, c, k = map(int, input().split())

dp = [[[0,0,0,0] for _j in range(c+1)] for _i in range(r)]
bord = [[0]*(c+1) for _i in range(r)]

for _i in range(k):
    _r, _c, _v = map(int, input().split())
    bord[_r-1][_c-1] = _v
            
for i in range(r):
    for j in range(c):
        dp[i][j][0] = max(dp[i-1][j])
        dp[i][j][1] = dp[i][j][0] + bord[i][j]
        for x in range(1, 4):
            dp[i][j][x] = max(
                dp[i][j][x],
                dp[i][j-1][x],
                dp[i][j-1][x-1]+bord[i][j],             
            )

print(max(dp[r-1][c-1]))

### FIXED CODE ###

r, c, k = map(int, input().split())

dp = [[[0,0,0,0] for _j in range(c+1)] for _i in range(2)]
bord = [[0]*(c+1) for _i in range(r)]

for _i in range(k):
    _r, _c, _v = map(int, input().split())
    bord[_r-1][_c-1] = _v
            
for i in range(r):
    for j in range(c):
        dp[1][j][0] = max(dp[0][j])
        dp[1][j][1] = max(
            dp[1][j][0] + bord[i][j],
            dp[1][j-1][1],
            dp[1][j-1][0]+bord[i][j]
        )

        dp[1][j][2] = max(
            dp[1][j-1][2],
            dp[1][j-1][1]+bord[i][j],             
        )
        dp[1][j][3] = max(
            dp[1][j-1][3],
            dp[1][j-1][2]+bord[i][j],             
        )

    dp[0] = dp[1][::]

print(max(dp[1][c-1]))
### BUGGY CODE ###

import sys
input = sys.stdin.readline

n = int(input())
Rp = {}
Lp = {}
Rm = {}
Lm = {}
U = []
R = []
L = []
D = []

for i in range(n):
    x,y,u = input().split()
    x,y = int(x), int(y)
    if u == "U":    
        U.append((x,y))
    elif u == "D":    
        D.append((x,y))
    elif u == "R":   
        if x+y in Rp:
            Rp[x+y].append((x,y))
        else:
            Rp[x+y] = [(x,y)]
        if x-y in Rm:
            Rm[x-y].append((x,y))
        else:
            Rm[x-y] = [(x,y)]
        R.append((y,x))
        
    else:
        if x+y in Lp:
            Lp[x+y].append((x,y))
        else:
            Lp[x+y] = [(x,y)]
        if x-y in Lm:
            Lm[x-y].append((x,y))
        else:
            Lm[x-y] = [(x,y)]
        L.append((y,x))

ans = float("INF")

for x,y in U:
    if x+y in Rp:
        for nx,ny in Rp[x+y]:
            if ny >= y:
                ans = min(ans,abs(ny-y)*10)
    if x-y in Lm:
        for nx,ny in Lm[x-y]:
            if ny >= y:
                ans = min(ans,abs(ny-y)*10)
for x,y in D:
    if x+y in Lp:
        for nx,ny in Lp[x+y]:
            if y >= ny:
                ans = min(ans,abs(ny-y)*10)
    if x-y in Rm:
        for nx,ny in Rm[x-y]:
            if y >= ny:
                ans = min(ans,abs(ny-y)*10)

def syaku(A,B):
    if A == [] or B == []:
        return float("INF")
    la = len(A)
    lb = len(B)
    count = float("INF")
    b = 0
    for i in range(la):
        x,y = A[i]
        if i > 0 and x == A[i-1][0]:
            if len(l) > 0:
                for nx,ny in l:
                    if y >= ny:
                        count = min(count, abs(y-ny)*5)
        else:
            l = []
            while b < lb and B[b][0] <= x:
                if B[b][0] == x:
                    if y >= B[b][1]:
                        count = min(count,abs(y-B[b][1])*5)
                    l.append(B[b])
                b += 1
    return count


D.sort()
U.sort()
L.sort()
R.sort()
ans = min(ans,syaku(D,U))
ans = min(ans,syaku(L,R))

if ans == float("INF"):
    print("SAFE")
else:
    print(ans)


### FIXED CODE ###

import sys
input = sys.stdin.readline
from collections import defaultdict
n = int(input())
UR = defaultdict(list)
UD = defaultdict(list)
UL = defaultdict(list)
DR = defaultdict(list)
DL = defaultdict(list)
RL = defaultdict(list)

for i in range(n):
    x,y,u = input().split()
    x,y = int(x), int(y)
    if u == "U":    
        UD[x].append((y,1))
        UR[x+y].append((x-y,0))
        UL[y-x].append((x+y,1))
    elif u == "D":    
        UD[x].append((y,0))
        DR[y-x].append((x+y,0))
        DL[x+y].append((x-y,1))
    elif u == "R":   
        RL[y].append((x,1))
        DR[y-x].append((x+y,1))
        UR[x+y].append((x-y,1))
        
    else:
        RL[y].append((x,0))
        UL[y-x].append((x+y,0))
        DL[x+y].append((x-y,0))

ans = float("INF")

for x in [UD, UL, UR, DR, DL, RL]:
    for v in x.values():
        V = sorted(v)

        for i in range(len(V)-1):
            if V[i][1] and not V[i+1][1]:
                ans = min(ans,V[i+1][0]-V[i][0])


if ans == float("INF"):
    print("SAFE")
else:
    print(ans*5)
### BUGGY CODE ###

from collections import deque
N = int(input())
a = list(map(int, input().split()))
b = deque()
ans = 0

for i in range(N):
  t = N-1-i
  k = N-i
  s = 0
  while k-1 < N:
    if k in b:
      s += 1
    k += t+1
  if (a[t]+s) % 2 == 1:
    b.appendleft(t+1)
    ans += 1
    
print(ans)
print(' '.join(map(str, b)))

### FIXED CODE ###

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

b = [0] * N
for i in range(N):
  tmp = 0
  n = N-i
  for j in range(n*2-1, N, n):
    if b[j] == 1:
      tmp += 1
  if a[n-1] != tmp%2:
    b[n-1] = 1

ans = []
for i in range(N):
  if b[i] == 1:
    ans.append(i+1)
if ans != []:
  print(len(ans))
  print(*ans)
else:
  print(0)
### BUGGY CODE ###

import math

H = int(input())
#H = list(map(int,input().split()))
#H = sorted(H,reverse=True)

mon_num = 1
attack_num = 0
for k in range(1000000000000):
    
    attack_num += mon_num
    
    H = math.floor(H/2)
    mon_num = mon_num*2
    
    
    if H == 1:
        attack_num += mon_num
        break
print(attack_num)
        
    

### FIXED CODE ###

import math
import sys
H = int(input())
#H = list(map(int,input().split()))
#H = sorted(H,reverse=True)

if H == 0:
    print(0)
    sys.exit()
elif H == 1:
    print(1)
    sys.exit()

mon_num = 1
attack_num = 0
for k in range(1000000000000):
    
    attack_num += mon_num
    
    H = math.floor(H/2)
    mon_num = mon_num*2
    
    
    if H == 1:
        attack_num += mon_num
        break
print(attack_num)