CodeEff/ECCO huggingface dataset:
# Original solution
import heapq

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

uvab = [list(map(int, input().split())) for _ in range(M)]
cd = [list(map(int, input().split())) for _ in range(N)]

for i in range(M):
    uvab[i][0] -= 1
    uvab[i][1] -= 1

railways = [[] for _ in range(N)]
max_a = 0
for u, v, a, b in uvab:
    railways[u].append((v, a, b))
    railways[v].append((u, a, b))
    max_a = max(max_a, a)
del uvab

max_silver = max_a * (N - 1)

ans = [-1] * N
d = dict()
d[(S, 0)] = 0  # silver, station
Q = [(0, S, 0)]  # time, silver, station
sum_reached = 0
reached = [False] * N

while Q:
    t, sv, st = heapq.heappop(Q)
    if not reached[st]:
        ans[st] = t
        reached[st] = True
        sum_reached += 1
        if sum_reached == N:
            break

    new_key = (sv + cd[st][0], st)
    new_value = t + cd[st][1]
    if new_key not in d or d[new_key] > new_value:
        d[new_key] = t + cd[st][1]
        heapq.heappush(Q, (new_value, *new_key))

    for dist, a, b in railways[st]:
        if sv >= a:
            new_key = (sv - a, dist)
            new_value = t + b
            if new_key not in d or d[new_key] > new_value:
                d[new_key] = new_value
                heapq.heappush(Q, (new_value, *new_key))

print(*ans[1:], sep="\n")


# Optimized solution
import heapq

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

uvab = [list(map(int, input().split())) for _ in range(M)]
cd = [list(map(int, input().split())) for _ in range(N)]

for i in range(M):
    uvab[i][0] -= 1
    uvab[i][1] -= 1

railways = [[] for _ in range(N)]
max_a = 0
for u, v, a, b in uvab:
    railways[u].append((v, a, b))
    railways[v].append((u, a, b))
    max_a = max(max_a, a)
del uvab

max_silver = max_a * (N - 1)

ans = [-1] * N
d = dict()
d[(S, 0)] = 0  # silver, station
Q = [(0, S, 0)]  # time, silver, station
sum_reached = 0
reached = [False] * N

while Q:
    t, sv, st = heapq.heappop(Q)
    if not reached[st]:
        ans[st] = t
        reached[st] = True
        sum_reached += 1
        if sum_reached == N:
            break

    new_key = (min(max_silver, sv + cd[st][0]), st)
    new_value = t + cd[st][1]
    if new_key not in d or d[new_key] > new_value:
        d[new_key] = t + cd[st][1]
        heapq.heappush(Q, (new_value, *new_key))

    for dist, a, b in railways[st]:
        if sv >= a:
            new_key = (sv - a, dist)
            new_value = t + b
            if new_key not in d or d[new_key] > new_value:
                d[new_key] = new_value
                heapq.heappush(Q, (new_value, *new_key))

print(*ans[1:], sep="\n")
# Original solution
from queue import PriorityQueue
from collections import defaultdict

n, m, s = list(map(int, input().split()))
graph = defaultdict(dict)
for i in range(m):
    u, v, a, b = list(map(int, input().split()))
    graph[u][v] = (a, b)
    graph[v][u] = (a, b)

town = [None]*(n+1)
for i in range(n):
    c, d = list(map(int, input().split()))
    town[i+1] = (c, d)

if s >= 2501:
    s = 2501
x = (1, s)
cost = 0
visit = set()
pq = PriorityQueue()
pq.put((cost, x), block=False)
ans = [1000000000000000]*(n+1)
while not pq.empty():
    cost, x = pq.get_nowait()
    if x in visit:
        continue
    visit.add(x)
    p, m = x
    ans[p] = min(ans[p], cost)
    c, d = town[p]
    if m <= 2501:
        pq.put((cost+d, (p, m+c)), block=False)
    for q, edge in list(graph[p].items()):
        a, b = edge
        if m-a >= 0:
            pq.put((cost+b, (q, m-a)), block=False)
for i in range(2, n+1):
    print((ans[i]))

# Optimized solution
from queue import PriorityQueue
from collections import defaultdict
from heapq import heappush, heappop

n, m, s = list(map(int, input().split()))
graph = defaultdict(dict)
for i in range(m):
    u, v, a, b = list(map(int, input().split()))
    graph[u][v] = (a, b)
    graph[v][u] = (a, b)

town = [None]*(n+1)
for i in range(n):
    c, d = list(map(int, input().split()))
    town[i+1] = (c, d)

if s >= 2501:
    s = 2501
x = (1, s)
cost = 0
visit = set()
heap = []
heappush(heap, (cost, x))
ans = [None]*(n+1)
check = 0
while len(heap) > 0:
    cost, x = heappop(heap)
    if x in visit:
        continue
    visit.add(x)
    p, m = x
    if ans[p] is None:
        ans[p] = cost
        check += 1
        if check >= n:
            break
    c, d = town[p]
    if m <= 2501:
        heappush(heap, (cost+d, (p, m+c)))
    for q, edge in list(graph[p].items()):
        a, b = edge
        if m-a >= 0:
            heappush(heap, (cost+b, (q, m-a)))
for i in range(2, n+1):
    print((ans[i]))
# Original solution
import heapq

def main():
    N, M, S = list(map(int, input().split()))
    AB = [[] for _ in range(N)]
    maxA = 0
    for _ in range(M):
        u, v, a, b = list(map(int, input().split()))
        AB[u - 1].append((a, b, v - 1))
        AB[v - 1].append((a, b, u - 1))
        maxA = max(maxA, a)
    for i in range(N):
        AB[i].sort()

    CD = [tuple(map(int, input().split())) for _ in range(N)]
    maxS = N * maxA
    cur = [(0, 0, S)]  # (time, station, silver)
    T = [-1] * N
    tc = N
    while tc:
        t, u, s = heapq.heappop(cur)
        if T[u] == -1:
            T[u] = t
            tc -= 1
        ma = maxS
        for a, b, v in AB[u]:
            if s < a:
                break
            heapq.heappush(cur, (t + b, v, s - a))
        if s != maxS:
            c, d = CD[u]
            heapq.heappush(cur, (t + d, u, min(s + c, maxS)))
    print(('\n'.join(map(str, T[1:]))))

main()


# Optimized solution
import heapq

def main():
    N, M, S = list(map(int, input().split()))
    AB = [[] for _ in range(N)]
    maxA = 0
    for _ in range(M):
        u, v, a, b = list(map(int, input().split()))
        AB[u - 1].append((a, b, v - 1))
        AB[v - 1].append((a, b, u - 1))
        maxA = max(maxA, a)
    for i in range(N):
        AB[i].sort()

    CD = [tuple(map(int, input().split())) for _ in range(N)]
    maxS = N * maxA
    cur = [(0, 0, S)]  # (time, station, silver)
    T = [-1] * N
    tc = N
    P = [-1] * N
    while tc:
        t, u, s = heapq.heappop(cur)
        if s <= P[u]:
            continue
        P[u] = s
        if T[u] == -1:
            T[u] = t
            tc -= 1
        for a, b, v in AB[u]:
            if s < a:
                break
            heapq.heappush(cur, (t + b, v, s - a))
        if s != maxS:
            c, d = CD[u]
            min_a = AB[u][0][0]
            k = max(1, (min_a - s + c  - 1) // c)
            heapq.heappush(cur, (t + k * d, u, min(s + k * c, maxS)))
    print(('\n'.join(map(str, T[1:]))))

main()
# Original solution
import heapq

def main():
    N, M, S = list(map(int, input().split()))
    AB = [[] for _ in range(N)]
    maxA = 0
    for _ in range(M):
        u, v, a, b = list(map(int, input().split()))
        AB[u - 1].append((a, b, v - 1))
        AB[v - 1].append((a, b, u - 1))
        maxA = max(maxA, a)
    for i in range(N):
        AB[i].sort()

    CD = [tuple(map(int, input().split())) for _ in range(N)]
    maxS = N * maxA
    cur = [(0, 0, S)]  # (time, station, silver)
    T = [-1] * N
    tc = N
    P = [-1] * N
    while tc:
        t, u, s = heapq.heappop(cur)
        if s <= P[u]:
            continue
        P[u] = s
        if T[u] == -1:
            T[u] = t
            tc -= 1
        for a, b, v in AB[u]:
            if s < a:
                break
            heapq.heappush(cur, (t + b, v, s - a))
        if s != maxS:
            c, d = CD[u]
            min_a = AB[u][0][0]
            k = max(1, (min_a - s + c  - 1) // c)
            heapq.heappush(cur, (t + k * d, u, min(s + k * c, maxS)))
    print(('\n'.join(map(str, T[1:]))))

main()


# Optimized solution
import heapq

def main():
    N, M, S = list(map(int, input().split()))
    AB = [[] for _ in range(N)]
    maxA = 0
    for _ in range(M):
        u, v, a, b = list(map(int, input().split()))
        AB[u - 1].append((a, b, v - 1))
        AB[v - 1].append((a, b, u - 1))
        maxA = max(maxA, a)
    for i in range(N):
        AB[i].sort()

    CD = [tuple(map(int, input().split())) for _ in range(N)]
    maxS = N * maxA
    cur = [(0, 0, S)]  # (time, station, silver)
    T = [-1] * N
    tc = N
    P = [-1] * N
    while tc:
        t, u, s = heapq.heappop(cur)
        if s <= P[u]:
            continue
        P[u] = s
        if T[u] == -1:
            T[u] = t
            tc -= 1
        for a, b, v in AB[u]:
            if s < a:
                break
            if P[v] < s - a:
                heapq.heappush(cur, (t + b, v, s - a))
        if s != maxS:
            c, d = CD[u]
            min_a = AB[u][0][0]
            k = max(1, (min_a - s + c  - 1) // c)
            heapq.heappush(cur, (t + k * d, u, min(s + k * c, maxS)))
    print(('\n'.join(map(str, T[1:]))))

main()
# Original solution
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math
    #from math import gcd

    inf = 10**17
    #mod = 10**9 + 7

    n,m,s = list(map(int, input().split()))
    s = min(s, 2500)
    # edge[i]:頂点iからの[行先, 必要な銀貨, 時間]
    edge = [[] for _ in range(n)] #頂点数, 場合によって変える
    for _ in range(m):
        a,b,c,d = list(map(int, input().split()))
        edge[a-1].append((b-1, c, d))
        edge[b-1].append((a-1, c, d))

    # 銀貨との交換を自己ループとする
    for i in range(n):
        c, d = list(map(int, input().split()))
        edge[i].append((i, -c, d))

    dp = [[inf]*2501 for _ in range(n)]
    dp[0][s] = 0
    # [時間, 所持金, 頂点]
    hq = [(0, s, 0)]
    heapify(hq)

    while hq:
        t, ginka, v = heappop(hq)
        if dp[v][ginka] < t:
            continue
        for nv, a, b in edge[v]:
            if ginka < a:
                continue
            ng = ginka - a
            if ng > 2500:
                ng = 2500
            for i in range(ng, -1, -1):
                if dp[nv][i] > t+b:
                    dp[nv][i] = t+b
                else:
                    break
            heappush(hq, (t+b, ng, nv))
    
    for i in range(1, n):
        print((min(dp[i])))

if __name__ == '__main__':
    main()

# Optimized solution

def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math
    #from math import gcd

    inf = 10**17
    #mod = 10**9 + 7

    n,m,s = list(map(int, input().split()))
    s = min(s, 2500)
    # edge[i]:頂点iからの[行先, 必要な銀貨, 時間]
    edge = [[] for _ in range(n)] #頂点数, 場合によって変える
    for _ in range(m):
        a,b,c,d = list(map(int, input().split()))
        edge[a-1].append((b-1, c, d))
        edge[b-1].append((a-1, c, d))

    # 銀貨との交換を自己ループとする
    for i in range(n):
        c, d = list(map(int, input().split()))
        edge[i].append((i, -c, d))

    dp = [[inf]*2501 for _ in range(n)]
    dp[0][s] = 0
    # [時間, 所持金, 頂点]
    hq = [(0, s, 0)]
    heapify(hq)

    while hq:
        t, ginka, v = heappop(hq)
        if dp[v][ginka] < t:
            continue
        for nv, a, b in edge[v]:
            if ginka < a:
                continue
            ng = ginka - a
            if ng > 2500:
                ng = 2500
            f = 0
            for i in range(ng, -1, -1):
                if dp[nv][i] > t+b:
                    dp[nv][i] = t+b
                    f = 1
                else:
                    break
            if f:
                heappush(hq, (t+b, ng, nv))
    
    for i in range(1, n):
        print((min(dp[i])))

if __name__ == '__main__':
    main()
# Original solution
# ABC 164 E 草案
import sys
sys.setrecursionlimit(10**6)

n,m,s= list(map(int, input().split()))
g= [list(map(int, input().split())) for i in range(m)]
# 両替所
c= [list(map(int, input().split())) for i in range(n)]

x=2501
# 作るグラフ (点,所有銀貨,必要時間)
gg=[[[] for i in range(x)] for i in range(n)]
for i in range(n):
    for j in range(x-1):
        # 金貨を銀貨に交換
        y=j+c[i][0]
        if y>=x-1:
            y=x-1
        gg[i][j].append((i,y,c[i][1]))


for i in range(1,x):
    for u,v,a,b in g:
        u-=1
        v-=1
        # 銀貨足りる時移動できる
        if i-a>=0:
            gg[v][i].append((u,i-a,b))
            gg[u][i].append((v,i-a,b))





#ダイクストラ法
from heapq import heappush, heappop

def dijkstra(edges, size, source,gold):
    # edge=探索するグラフ
    # size=グラフの点の数
    # source=スタート点
    distance = [[float('inf')  for i in range(x)] for i in range(n)]
    distance[source][gold] = 0
    visited = [[False  for i in range(x)] for i in range(n)]
    pq = []
    heappush(pq, (0, source,gold))
    while pq:
        dist_v, u,v = heappop(pq)
        visited[u][v] = True
        for u,v, weight in edges[u][v]:
            if not visited[u][v]:
                new_dist = dist_v + weight
                if distance[u][v] > new_dist:
                    distance[u][v] = new_dist
                    heappush(pq, (new_dist, u,v))
    return distance
s=min(2500,s)
ans=dijkstra(gg,n,0,s)

for i in range(1,n):
    print((min(ans[i])))

# Optimized solution
# ABC 164 E 草案
import sys
sys.setrecursionlimit(10**6)

n,m,s= list(map(int, input().split()))
g= [list(map(int, input().split())) for i in range(m)]
# 両替所
c= [list(map(int, input().split())) for i in range(n)]

x=2501
# 作るグラフ (点,所有銀貨,必要時間)
gg=[[[] for i in range(x)] for i in range(n)]
for i in range(n):
    for j in range(x-1):
        # 金貨を銀貨に交換
        y=j+c[i][0]
        if y>=x-1:
            y=x-1
        gg[i][j].append((i,y,c[i][1]))


for i in range(1,x):
    for u,v,a,b in g:
        u-=1
        v-=1
        # 銀貨足りる時移動できる
        if i-a>=0:
            gg[v][i].append((u,i-a,b))
            gg[u][i].append((v,i-a,b))





#ダイクストラ法
from heapq import heappush, heappop

def dijkstra(edges, size, source,gold):
    # edge=探索するグラフ
    # size=グラフの点の数
    # source=スタート点
    distance = [[float('inf')]*x for i in range(n)]
    distance[source][gold] = 0
    visited = [[False]*x for i in range(n)]
    pq = []
    heappush(pq, (0, source,gold))
    while pq:
        dist_v, u,v = heappop(pq)
        visited[u][v] = True
        for u,v, weight in edges[u][v]:
            if not visited[u][v]:
                new_dist = dist_v + weight
                if distance[u][v] > new_dist:
                    distance[u][v] = new_dist
                    heappush(pq, (new_dist, u,v))
    return distance
s=min(2500,s)
ans=dijkstra(gg,n,0,s)

for i in range(1,n):
    print((min(ans[i])))
# Original solution
while int(eval(input())) > 0:
    s = sorted(map(int, input().split()))
    print((min(abs(a - b) for (a, b) in zip(s, s[1:]))))

# Optimized solution
while True:
    if int(eval(input())) == 0:
        break
    s = sorted(map(int, input().split()))
    r = min(abs(x - y) for (x, y) in zip(s, s[1:]))
    print(r)
# Original solution
while True:
    n = int(eval(input()))
    if n==0: break
    l = list(map(int,input().split()))
    r = []
    for i in range(n):
        for j in range(i+1,n):
            r += [abs(l[i]-l[j])]
    print((min(r)))

# Optimized solution
while True:
    n = int(eval(input()))
    if n==0: break
    l = sorted(list(map(int,input().split())))
    r = []
    for i in range(n-1):
        r += [l[i+1]-l[i]]
    print((min(r)))
# Original solution
def f(x,y):
  global B
  B[y][x]^=1
  if y>0: B[y-1][x]^=1
  if y<9: B[y+1][x]^=1
  if x>0: B[y][x-1]^=1
  if x<9: B[y][x+1]^=1
  return (x,y)
R=list(range(10))
n=eval(input())
for _ in [0]*n:
  A=[list(map(int,input().split())) for _ in R]
  for p in range(1024):
    B=[e[:] for e in A]
    x=[]
    for j in R:
      a=[list(map(int,list(format(p,'010b')))),B[j-1]][j!=0]
      for i in R:
        if a[i]==1: x.append(f(i,j))
    if sum(B[9])==0: break
  for i,j in x: B[j][i]=1
  for e in B: print(" ".join(map(str,e)))

# Optimized solution
def f(x,y):
  global B
  B[y][x]^=1
  if y>0: B[y-1][x]^=1
  if y<9: B[y+1][x]^=1
  if x>0: B[y][x-1]^=1
  if x<9: B[y][x+1]^=1
  return (x,y)
R=list(range(10))
n=eval(input())
for _ in [0]*n:
  A=[list(map(int,input().split())) for _ in R]
  for p in range(1024):
    B=[e[:] for e in A]
    x=[]
    for j in R:
      if j==0: a=list(map(int,list(format(p,'010b'))))
      else: a=B[j-1]
      for i in R:
        if a[i]==1: x.append(f(i,j))
    if sum(B[9])==0: break
  for i,j in x: B[j][i]=1
  for e in B: print(" ".join(map(str,e)))
# Original solution
N = int(eval(input()))
A = list(map(int,input().split()))
ans = 0
for a in A:
    ans ^= a 
M = 2**60-1
b = M^ans
for i in range(N):
    A[i] &= b
A.sort(reverse=True)
for i in range(min(60,N)):
    a = A[i]
    if a == 0:
        break
    l = len(bin(a))
    for j in range(N):
        if j==i:
            continue
        if l==len(bin(A[j]%2**(l-2))):
            A[j] ^= a
        else:
            if i < j:
                break
    A.sort(reverse=True)
s = 0
for a in A:
    s ^= a
ans += 2*s
print(ans)

# Optimized solution
N = int(eval(input()))
A = list(map(int,input().split()))
ans = 0
for a in A:
    ans ^= a
M = 2**60-1
b = M^ans
for i in range(N):
    A[i] &= b
A.sort(reverse=True)
for i in range(min(60,N)):
    a = A[i]
    if a == 0:
        break
    l = len(bin(a))-3
    for j in range(N):
        if j==i:
            continue
        if A[j]//2**l%2==1:
            A[j] ^= a
        else:
            if i < j:
                break
    A.sort(reverse=True)
s = 0
for a in A:
    s ^= a
ans += 2*s
print(ans)
# Original solution
N=int(eval(input()))
alist=list(map(int,input().split()))

max_digit=60
mat=[]
sum_digit=[0]*max_digit
for a in alist:
  array=[]
  for j in range(max_digit):    
    m=a&1
    array.append(m)
    sum_digit[max_digit-1-j]+=m
    a>>=1
    
  array.reverse()
  mat.append(array)
#print(mat)
#print(sum_digit)

mat_red=[[mat[i][j] for j in range(max_digit) if sum_digit[j]%2==0 and sum_digit[j]!=0] for i in range(N)]
#print(mat_red)

pivot_set=set()
for j in range(len(mat_red[0])):
  pivot_row=-1
  for i in range(N):
    if mat_red[i][j]==1:
      if not i in pivot_set:
        pivot_row=i
        break    
  
  if pivot_row!=-1:
    for i in range(N):
      if i==pivot_row:
        continue
      if mat_red[i][j]==0:
        continue      
      for k in range(j,len(mat_red[0])):
        mat_red[i][k]^=mat_red[pivot_row][k]
        
    pivot_set.add(pivot_row)
  #print(j,pivot_row)
  #print(mat_red)
#print(mat_red)  

sum_digit_red=[0]*len(mat_red[0])
for i in range(N):
  for j in range(len(mat_red[0])):
    sum_digit_red[j]^=mat_red[i][j]
#print(sum_digit_red)

answer=0
cnt=0
for j in range(max_digit):
  if sum_digit[j]==0:
    continue
  if sum_digit[j]&1:
    answer+=2**(max_digit-1-j)
  else:
    if sum_digit_red[cnt]&1:
      answer+=2*2**(max_digit-1-j)
    cnt+=1
    
print(answer)

# Optimized solution
N=int(eval(input()))
alist=list(map(int,input().split()))
alist.sort(reverse=True)

max_digit=60
mat=[]
sum_digit=[0]*max_digit
for a in alist:
  array=[]
  for j in range(max_digit):    
    m=a&1
    array.append(m)
    sum_digit[max_digit-1-j]+=m
    a>>=1
    
  array.reverse()
  mat.append(array)
#print(mat)
#print(sum_digit)

mat_red=[[mat[i][j] for j in range(max_digit) if sum_digit[j]%2==0 and sum_digit[j]!=0] for i in range(N)]
#print(mat_red)

pivot_set=set()
for j in range(len(mat_red[0])):
  pivot_row=-1
  for i in range(N):
    if mat_red[i][j]==1 and not i in pivot_set:
      pivot_row=i
      break
  else:
    continue
  
  for i in range(N):
    if i==pivot_row:
      continue
    if mat_red[i][j]==0:
      continue      
    for k in range(j,len(mat_red[0])):
      mat_red[i][k]^=mat_red[pivot_row][k]
      
  pivot_set.add(pivot_row)
  #print(j,pivot_row)
  #print(mat_red)
#print(mat_red)  

sum_digit_red=[0]*len(mat_red[0])
for i in range(N):
  for j in range(len(mat_red[0])):
    sum_digit_red[j]^=mat_red[i][j]
#print(sum_digit_red)

answer=0
cnt=0
for j in range(max_digit):
  if sum_digit[j]==0:
    continue
  if sum_digit[j]&1:
    answer+=2**(max_digit-1-j)
  else:
    if sum_digit_red[cnt]&1:
      answer+=2**(max_digit-j)
    cnt+=1
    
print(answer)
# Original solution
n=int(eval(input()))
a=list(map(int,input().split()))
ans=0
for i in a:
    ans^=i
k=~ans
for i in range(n):
    a[i]&=k
rank=0
# 掃き出し法
for i in range(59,-1,-1):
    for j in range(rank,n):
        if a[j]>>i&1:
            break
    if j==n:
        continue
    if j>rank:
        # a[rank]のi番目のbitを1にするswapでもいい
        a[rank]^=a[j]
    for j in range(rank+1,n):
        a[j]=min(a[j],a[j]^a[rank])
    res=0
    rank+=1
for i in a:
    res=max(res,res^i)
print((ans+2*res))

# Optimized solution
n=int(eval(input()))
a=list(map(int,input().split()))
ans=0
for i in a:
    ans^=i
k=~ans
for i in range(n):
    a[i]&=k
rank=0
# 掃き出し法
for i in range(59,-1,-1):
    for j in range(rank,n):
        if a[j]>>i&1:
            break
    if j==n:
        continue
    if j>rank:
        # a[rank]のi番目のbitを1にするswapでもいい
        a[rank]^=a[j]
    for j in range(rank+1,n):
        a[j]=min(a[j],a[j]^a[rank])
    rank+=1
res=0
for i in a:
    res=max(res,res^i)
print((ans+2*res))
# Original solution
n = int(eval(input()))
A = list(map(int, input().split()))

not_important = 0
for a in A:
    not_important ^= a

for i in range(n):
    A[i] &= ~not_important

A.sort()
rank = 0
for digit in range(60, -1, -1):
    check_bit = 1 << digit

    for i in range(rank, n):
        if A[i] & check_bit:
            A[rank], A[i] = A[i], A[rank]
            break
    else:
        continue

    for i in range(n):
        if i == rank: continue
        if A[i] & check_bit:
            A[i] ^= A[rank]

    rank += 1

ans = 0
for i in range(rank):
    ans ^= A[i]

print((ans*2 + not_important))

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

not_important = 0
for a in A:
    not_important ^= a

for i in range(n):
    A[i] &= ~not_important

A.sort(reverse=True)
rank = 0
for digit in range(60, -1, -1):
    check_bit = 1 << digit

    for i in range(rank, n):
        if A[i] & check_bit:
            A[rank], A[i] = A[i], A[rank]
            break
    else:
        continue

    for i in range(n):
        if i == rank: continue
        if A[i] & check_bit:
            A[i] ^= A[rank]

    rank += 1

ans = 0
for i in range(rank):
    ans ^= A[i]

print((ans*2 + not_important))
# Original solution
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=sys.stdin.readline
def resolve():
    n=int(eval(input()))
    A=list(map(int,input().split()))
    xor=0
    max_digit=0
    for a in A:
        xor^=a
        max_digit=max(max_digit,a.bit_length())
    # xorのうち、bitが立っていない部分だけでスクリーニング
    for i in range(n): A[i]&=(~xor)
    # このAに対してsweeping
    r=0 # Aのrank
    for d in reversed(list(range(max_digit))): # digit
        for i in range(r,n):
            if A[i]&(1<<d): # 候補のiをfixする
                for j in range(i+1,n): # sweep(確定してる奴は掃き出さなくてよい)
                    if A[j]&(1<<d): A[j]^=A[i]
                A[i],A[r]=A[r],A[i] # swap
                r+=1
                break
    # sweepしたAに対し、最上位bitから確定させていく
    x=0
    for i in range(r):
        d=A[i].bit_length()
        if not x&(1<<(d-1)):
            x^=A[i]
    print((xor+2*x))
resolve()

# Optimized solution
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
def resolve():
    n=int(eval(input()))
    A=list(map(int,input().split()))
    xor=0
    max_digit=0
    for a in A:
        xor^=a
        max_digit=max(max_digit,a.bit_length())
    # xorのうち、bitが立っていない部分だけでスクリーニング
    for i in range(n): A[i]&=(~xor)
    # このAに対してsweeping
    r=0 # Aのrank
    for d in reversed(list(range(max_digit))): # digit
        for i in range(r,n):
            if A[i]&(1<<d): # 候補のiをfixする
                for j in range(i+1,n): # sweep(確定してる奴は掃き出さなくてよい)
                    if A[j]&(1<<d): A[j]^=A[i]
                A[i],A[r]=A[r],A[i] # swap
                r+=1
                break
    # sweepしたAに対し、最上位bitから確定させていく
    x=0
    for i in range(r):
        d=A[i].bit_length()
        if not x&(1<<(d-1)):
            x^=A[i]
    print((xor+2*x))
resolve()