Harryxun/stf_run huggingface dataset:
#解説参照
n,k,q=map(int, input().split())
*a,=map(int, input().split())
a+=[0]
ans=10**10
for i in range(n):
    ai=a[i]
    tmp=[10**10]##15行目でtmp[:0]になるから
    tmp2=[]
    for j in range(n+1):
        if i==j:
            continue
        if a[j]<ai:
            tmp.sort()
            if len(tmp)>=k+1:
                tmp2+=tmp[:-k]
            tmp=[]
        else:
            tmp.append(a[j])
            #print("test",tmp)
    tmp2.sort()
#    print(tmp,tmp2)
    if len(tmp2)>=q-1:    
#        print("test2")
        ans=min(ans,tmp2[q-2]-ai)
print(ans)

### FIXED CODE ###

n,k,q=map(int, input().split())
if q==1:
    print(0)
    exit()
*a,=map(int, input().split())
a+=[-1]
ans=10**10
for i in range(n):
    ai=a[i]
    tmp=[10**11]##15行目でtmp[:0]になるから
    tmp2=[ai]
    for j in range(n+1):
        if i==j:
            continue
        if a[j]<ai:
            tmp.sort()
            if len(tmp)>=k+1:
                tmp2+=tmp[:-k]
            tmp=[10**11]###
        else:
            tmp.append(a[j])
            #print("test",tmp)
    tmp2.sort()
#    print(tmp,tmp2)
    if len(tmp2)>=q:    
#        print("test2")
        ans=min(ans,tmp2[q-1]-ai)
print(ans)
from collections import deque
import sys
input = sys.stdin.readline

n=int(input())
s=deque([])
cnt=0
for _ in range(n):
    s.append(input().sort())
for i in range(n):
    for j in range(n):
        if i<j:
            if s[i]==s[j]:
                cnt+=1
print(cnt)

### FIXED CODE ###

n=int(input())
L=[[] for _ in range(n)]
ans=0
for i in range(n):
    L[i]=sorted(list(input()))
L=sorted(L)
tmp=1
ans=0
for i in range(n-1):
    if L[i]==L[i+1]:
        tmp+=1
    else:
        ans+=tmp*(tmp-1)//2
        tmp=1
ans+=tmp*(tmp-1)//2
print(ans)
def find(tab, a):
    if tab[0][a]==-1:
        return a
    tab[0][a] = find(tab, tab[0][a])
    return tab[0][a]

def union(tab, a, b):
    p1, p2 = find(tab, a), find(tab, b)
    if p1 != p2:
        tab[0][p1] = p2
        tab[1][p2] += tab[1][p1]

def size(tab, a):
    return tab[1][a]

N, M = [int(a) for a in input().split(" ")]
ABs = [[int(a) for a in input().split(" ")] for i in range(M)]
tab = [[-1]*N, [1]*N]
arr = []

for a, b in reversed(ABs):
    a, b = (a-1, b-1)
    pa, pb = (find(tab, a), find(tab, b))
    na, nb = (size(tab, pa), size(tab, pb))
    if pa!=pb:
        dn = ((na+nb)*(na+nb-1)//2)-(na*(na-1)//2)-(nb*(nb-1)//2)
        arr.append(dn)
        union(tab, a, b)
    else:
        arr.append(0)

acc = 0
for cp in reversed(arr):
    acc += cp
    print(acc)


### FIXED CODE ###

import sys
sys.setrecursionlimit(100000)

def find(tab, a):
    if tab[0][a]==a:
        return a
    tab[0][a] = find(tab, tab[0][a])
    return tab[0][a]

def union(tab, a, b):
    p1, p2 = (find(tab, a), find(tab, b))
    if p1 != p2:
        tab[0][p1] = p2
        tab[1][p2] += tab[1][p1]

def size(tab, a):
    return tab[1][a]

N, M = [int(a) for a in input().split(" ")]
ABs = [[int(a) for a in input().split(" ")] for i in range(M)]
tab = [[i for i in range(N)], [1 for i in range(N)]]
arr = []

for a, b in reversed(ABs):
        a, b = (a-1, b-1)
        pa, pb = (find(tab, a), find(tab, b))
        na, nb = (size(tab, pa), size(tab, pb))
        if pa!=pb:
            dn = ((na+nb)*(na+nb-1)//2)-(na*(na-1)//2)-(nb*(nb-1)//2)
            arr.append(dn)
            union(tab, a, b)
        else:
            arr.append(0)

acc = 0
for cp in reversed(arr):
    acc += cp
    print(acc)
a,b=map(int,input().split())
ans = a+b if (b%a==0) else b-a
print(ans)


### FIXED CODE ###

# coding: utf-8
# Your code here!
# coding: utf-8
from fractions import gcd 
from functools import reduce
import sys
sys.setrecursionlimit(200000000)
from inspect import currentframe


# my functions here!
#標準エラー出力
def printargs2err(*args):
    names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' : '+repr(arg) for arg in args),file=sys.stderr)






def printglobals():
    for (symbol, value) in globals().items():
        print('symbol="%s"、value=%s' % (symbol, value),file=sys.stderr)
def printlocals():
    for (symbol, value) in locals().items():
        print('symbol="%s"、value=%s' % (symbol, value),file=sys.stderr)
#入力（後でいじる）
        
#input
def resolve():
    A=[0,1,2,3]
    A[int(input())]=0
    A[int(input())]=0
    print(sorted(A)[-1])
    #print([["NA","YYMM"],["MMYY","AMBIGUOUS"]][cMMYY][cYYMM])
#if __name__=="__main__":resolve()
"""
#printデバッグ消した？
#前の問題の結果見てないのに次の問題に行くの？
"""
"""
お前カッコ閉じるの忘れてるだろ
"""

import sys
from io import StringIO
import unittest

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """3
1"""
        output = """2"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """1
2"""
        output = """3"""
        self.assertIO(input, output)

if __name__=="__main__":resolve()
d_list = [0]
N,X = input().split(" ")
l_list = input().split(" ")

for i in range(int(len(l_list))):
    num = int(d_list[i]) + int(l_list[i])
    d_list.append(num)
    

for i in range(int(len(d_list)-1)):
    if d_list[i]<=int(X)< d_list[i+1]:
        print(i+1)

    elif int(X)>d_list[-1]:
            print(int(d_list))

### FIXED CODE ###

lists = []
lists = input().split(" ")
if int(lists[0])<int(lists[1]):
  print(0)
else:
  print(10)
N = float(input())
if N % 2.0 == 1.0:
  print(((N + 1.0)/2.0)/N)
else:
  print((N/2.0/)N)

### FIXED CODE ###

N = int(input())
if N % 2 == 1:
  print((int(N/2) + 1)/N)
else:
  print(0.5)
n=input()
if n[len(n)-1]=="s":
  n.append("es")
else:
  n.append("s")
print("".join(n))

### FIXED CODE ###

n=list(input())
if n[len(n)-1]=="s":
  n.append("es")
else:
  n.append("s")
print("".join(n))
n, m = map(int, input().split())
s = []
k = []
for i in range(m):
    ipt = list(map(int, input().split()))
    k.append(ipt[0])
    s.append(ipt[1:])
p = list(map(int, input().split()))
cnt = 0
for sw in (list(format(i, f'0{n}b')) for i in range(2 ** n)):
    for i in range(m):
        if sum([int(sw[j - 1]) for j in s[i]]) % 2 != p[i]:
            break
    else:
        cnt += 1
print(cnt)

### FIXED CODE ###

n, m = map(int, input().split())
s = []
k = []
for i in range(m):
    ipt = list(map(int, input().split()))
    k.append(ipt[0])
    s.append(ipt[1:])
p = list(map(int, input().split()))
cnt = 0
for sw in (list(format(i, '0{}b'.format(n))) for i in range(2 ** n)):
    for i in range(m):
        if sum([int(sw[j - 1]) for j in s[i]]) % 2 != p[i]:
            break
    else:
        cnt += 1
print(cnt)
x,a,b=map(int,input().split())
if abs(x-a)>abs(x-b):
  print(B)
else:
  print(A)


### FIXED CODE ###

x,a,b=map(int,input().split())
if abs(x-a)>abs(x-b):
  print('B')
else:
  print('A')
n = int(input())
s, t = map(int, input().split())
 
answer_list = []
for i in range(n):
  answer_list.append(s[i])
  answer_list.append(t[i])

s = ''.join(answer_list)
print(s)

### FIXED CODE ###

n = int(input())
s, t = input().split()
 
answer_list = []
for i in range(n):
  answer_list.append(s[i])
  answer_list.append(t[i])

joint = ''.join(answer_list)
print(joint)
import sys
input = sys.stdin.readline
ri = lambda: int(input())
rl = lambda: [int(x) if x.isdecimal() else x for x in input().split()]
rl = lambda: list(input().split()))
rr = lambda N: [list(l) for l in zip(*[rl() for _ in range(N)])]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18
MOD = 10**9+7


N,Q=rl()
TT = []
now = set()
for _ in range(N):
    s,t,x = rl()
    TT.append((s-x-0.5,1,x))
    TT.append((t-x-0.5,-1,x))
for i in range(Q):
    d = ri()
    TT.append((d,0,i))


TT.sort()
mx = INF
mx_f = False
ans = [-1]*Q
for st,w,x in TT:
    if w > 0:
        now.add(x)
        if mx > x:
            mx = x
            mx_f = True
    elif w < 0:
        now.remove(x)
        if mx == x:
            mx_f = False
    elif len(now) > 0:
        if not mx_f:
            mx = min(now)
            mx_f = True
        ans[x] = mx
print(*ans,sep='\n')

### FIXED CODE ###

import sys
input = sys.stdin.readline
ri = lambda: int(input())
rl = lambda: [int(x) if x.isdecimal() else x for x in input().split()]
#rl = lambda: list(input().split()))
rr = lambda N: [list(l) for l in zip(*[rl() for _ in range(N)])]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18
MOD = 10**9+7


N,Q=rl()
TT = []
now = set()
for _ in range(N):
    s,t,x = rl()
    TT.append((s-x-0.5,1,x))
    TT.append((t-x-0.5,-1,x))
for i in range(Q):
    d = ri()
    TT.append((d,0,i))


TT.sort()
mx = INF
mx_f = False
ans = [-1]*Q
for st,w,x in TT:
    if w > 0:
        now.add(x)
        if mx > x:
            mx = x
            mx_f = True
    elif w < 0:
        now.remove(x)
        if mx == x:
            mx_f = False
    elif len(now) > 0:
        if not mx_f:
            mx = min(now)
            mx_f = True
        ans[x] = mx
print(*ans,sep='\n')
import math
def main():
    r = [int(i) for i in input().strip()]
    print ("%f %f" % (r ** 2 * math.pi,  2 * r * math.pi))

if __name__ == '__main__':
    main()

### FIXED CODE ###

import math
r = float(input())

s = r * r * math.pi
l = r * 2 * math.pi

print("{0:.5f} {1:.5f}".format(s, l))
S = input()
N = int(input())
count = 0
if N >= 3 and N <= 50:
	d = ''
	for j in S:
    	d += j
    	if len(d) == N:break
	a = d.split('ABC')
	for i in a:
    	if i == '':
        	count += 1
    	else: continue
print (count)

### FIXED CODE ###

N = int(input())
S = input()
print(S.count("ABC"))
d = {1:{1:'.',2:',',3:'!',4:'?',5:' '},
     2:{1:'a',2:'b',3:'c'},
     3:{1:'d',2:'e',3:'f'},
     4:{1:'g',2:'h',3:'i'},
     5:{1:'j',2:'k',3:'l'},
     6:{1:'m',2:'n',3:'o'},
     7:{1:'p',2:'q',3:'r',4:'s'},
     8:{1:'t',2:'u',3:'v'},
     9:{1:'w',2:'x',3:'y',4:'z'}
}
n = int(raw_input())
for i in range(n):
    mes = raw_input()
    mes = mes.split("0")
    mes=filter(lambda x:len(x)>0,mes)
    l=[]
    for e in mes:
        l.append([e[0], len(e)])
    res=""
    for e in l:
        i=int(e[0])
        if(i==1):
            if e[1]>5:x=e[1]%5
            else:x=e[1]
        elif(i==7 or i==9):
            if e[1]>4:x=e[1]%4
            else:x=e[1]
        else:
            if e[1]>3:x=e[1]%3
            else:x=e[1]
            res=res+d[i][x]

    print res

### FIXED CODE ###

d = {1:{1:'.',2:',',3:'!',4:'?',5:' '},
     2:{1:'a',2:'b',3:'c'},
     3:{1:'d',2:'e',3:'f'},
     4:{1:'g',2:'h',3:'i'},
     5:{1:'j',2:'k',3:'l'},
     6:{1:'m',2:'n',3:'o'},
     7:{1:'p',2:'q',3:'r',4:'s'},
     8:{1:'t',2:'u',3:'v'},
     9:{1:'w',2:'x',3:'y',4:'z'}
}
n = int(raw_input())
for i in range(n):
    mes = raw_input()
    mes = mes.split("0")
    mes=filter(lambda x:len(x)>0,mes)
    l=[]
    for e in mes:
        l.append([e[0], len(e)])
    res=""
    for e in l:
        i=int(e[0])
        if(i==1):
            if e[1]%5==0:x=5
            else:x=e[1]%5
        elif(i==7 or i==9):
            if e[1]%4==0:x=4
            else:x=e[1]%4
        else:
            if e[1]%3==0:x=3
            else:x=e[1]%3
        res=res+d[i][x]

    print res
w,s = list(map,int(input().split()))
if w >= s:
    print('unsafe')
else:
    print('safe')

### FIXED CODE ###

s,w = list(map(int,input().split()))
if w >= s:
    print('unsafe')
else:
    print('safe')
k = int(input())
curr = 7
for i in range(k):
  if curr%k:
    curr *= 10
    curr += 7
  else:
    print(i+1)
	break
else:
  print(-1)

### FIXED CODE ###

k = int(input())
curr = 7
for i in range(k):
  if curr%k:
    curr *= 10
    curr += 7
    curr %= k
  else:
    print(i+1)
    break
else:
  print(-1)
n, k = map(int, input().split())
s = input()

l_array = [0 for x in range(n)]
l_reverse = []
r_array = [0 for x in range(n)]
r_reverse = []

cnt = []
l_cnt = 0
r_cnt = 0
now = s[0]
for index, ss in enumerate(s):
    if ss == "L":
        if now == ss:
            l_cnt += 1
        else:
            cnt.append(r_cnt)
            r_cnt = 0
            l_cnt = 1
            now = "L"
    else:
        if now == ss:
            r_cnt += 1
        else:
            cnt.append(l_cnt)
            l_cnt = 0
            r_cnt = 1
            now = "R"
else:
    cnt.append(max(l_cnt, r_cnt))

len_cnt = len(cnt)
res = []
for i in range(0, len_cnt, 2):
    if i+1>=len_cnt: continue
    res.append(cnt[i]+cnt[i+1])
res = sorted(res, reverse=True)
ans = 0
for j in range(k):
    ans += res[j]
print(ans)


### FIXED CODE ###

n, k = map(int, input().split())
s = input()

cnt = 0
for i, j in zip(s, s[1:]):
    if i == j:
        cnt += 1
print(min(n-1, cnt+2*k))
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect# lower_bound etc
#import numpy as np
#from copy import deepcopy
#from collections import deque


def run():
    a,b,x = map(int, input().split())
    ans = 0
    if a == 0:
        a += 1
        ans = 1
    ans += b // x - (a-1) // x
    print(ans)

if __name__ == "__main__":

### FIXED CODE ###

# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect# lower_bound etc
#import numpy as np
#from copy import deepcopy
#from collections import deque


def run():
    a,b,x = map(int, input().split())
    ans = 0
    if a == 0:
        a += 1
        ans = 1
    ans += b // x - (a-1) // x
    print(ans)

if __name__ == "__main__":
    run()
#!/usr/bin/env python3
import sys
from collections import namedtuple
import functools

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(N: int, t: "List[int]", x: "List[int]", y: "List[int]"):
    for i in range(N):
        min_length = abs(x[i+1] - x[i]) + abs(y[i+1] - y[i])
        travel_time = t[i+1] - t[i]

        if min_length > travel_time:
            return NO
        elif min_length == travel_time:
            next
        elif (travel_time - min_length) % 2 == 0:
            next
        else:
            return NO

    return YES


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    t = [int()] * (N)  # type: "List[int]" 
    x = [int()] * (N)  # type: "List[int]" 
    y = [int()] * (N)  # type: "List[int]" 
    for i in range(N):
        t[i] = int(next(tokens))
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
    t.insert(0, 0)
    x.insert(0, 0)
    y.insert(0, 0)
    print(solve(N, t, x, y))

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys


def solve(S: str):
    for i in range(len(S) - 1):
        if S[i] == S[i+1]:
            return 'Bad'
    return 'Good'


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = str(next(tokens))  # type: str
    print(solve(S))

if __name__ == '__main__':
    main()
N=int(input())
a_list=list(map(int,input().split()))
if N%3!=0:
  print("No")
else:
    a=set(a_list)
    a=list(a)
    if 0 in a:
            b=a_list.pop(0)
            if len(b)==len(a_list)*2//3:
                print("Yes")
            else:
                print("No")
    else:
            a1=a[0]
            a2=a[1]
            a3=a[2]
            if a1 ^ a2 ==a3 and a1^a3==a2:
                if a_list.count(a1) ==a_list.count(a2) ==a_list.count(a3):
                    print("Yes")
                else:
                    print("No")
            else:
                print("No")

### FIXED CODE ###

import copy
N=int(input())
a_list=list(map(int,input().split()))
a=set(a_list)
a=list(a)
if 0 in a:
        if len(a) ==2:
            if a_list.count(0)==len(a_list)//3 or a_list.count(0)==len(a_list)//2:
                    print("Yes")
            else:
                    print("No")
        elif len(a)==1:
            print("Yes")
        else:
                print("No")
else:
        if len(a)==3:
            a1=a[0]
            a2=a[1]
            a3=a[2]
            if a1 ^ a2 ==a3 and a1^a3==a2 and a2^a3==a1:
                if a_list.count(a1) == a_list.count(a2) == a_list.count(a3):
                        print("Yes")
                else:
                        print("No")
            else:
                print("No")
        else:
            print("No")
import math

L, R = list(map(int, input().split()))
data = [x % 2019 for x in range(L, R+1)]
len_data = [x for x in range(len(data))]
mod_min = math.inf

for i in reversed(len_data):
    for j in range(i):
        mod = data[i] * data[j]
        mod_min = mod if mod_min > mod else mod_min

print(mod_min)

### FIXED CODE ###

l, r = list(map(int,input().split()))

if r - l >= 2019:
  print(0)
  
else:
  ll = l % 2019
  rr = r % 2019
  if rr < ll:
    print(0)
    
  else:
    keep = 2020
    for i in range(ll, rr+1):
      for j in range(i+1, rr+1):
        keep = min((i*j)%2019, keep)
    print(keep)
#!/usr/bin/env python3
N, M = map(int, input().split())
g = [[] for _ in range(N)]
rg = [[] for _ in range(N)]
for _ in range(N - 1 + M):
    A, B = (int(x) - 1 for x in input().split())
    g[A].append(B)
    rg[B].append(A)


def dfs(s):
    global ts
    global used
    used[s] = True
    for t in g[s]:
        if not used[t]:
            dfs(t)
    ts.append(s)


def tsort():
    global ts
    for i in range(N):
        dfs(i)
    ts = ts[::-1]


used = [False] * N
ts = []
tsort()

mp = [None] * N
for i, x in enumerate(ts):
    mp[x] = i

ans = [0] * N
for t in ts[1:]:
    if rg[t]:
        ans[t] = ts[max(mp[s] for s in rg[t])] + 1

for x in ans:
    print(x)


### FIXED CODE ###

#!/usr/bin/env python3
import sys
sys.setrecursionlimit(100000)
N, M = map(int, input().split())
g = [[] for _ in range(N)]
rg = [[] for _ in range(N)]
for _ in range(N - 1 + M):
    A, B = (int(x) - 1 for x in input().split())
    g[A].append(B)
    rg[B].append(A)


def dfs(s):
    global ts
    global used
    used[s] = True
    for t in g[s]:
        if not used[t]:
            dfs(t)
    ts.append(s)


def tsort():
    global ts
    for i in range(N):
        dfs(i)
    ts = ts[::-1]


used = [False] * N
ts = []
tsort()

mp = [None] * N
for i, x in enumerate(ts):
    mp[x] = i

ans = [0] * N
for t in ts[1:]:
    if rg[t]:
        ans[t] = ts[max(mp[s] for s in rg[t])] + 1

for x in ans:
    print(x)
import sys
import numpy as np

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

def int_to_bits(x):
    return [ 1 if 2**i & x != 0 else 0 for i in range(60) ]

def inv(x, MOD):
    return pow(x, MOD-2, MOD)

MOD = 10**9+7

debug = False

if debug:
    n = 50000
    A = list(range(n))
else:
    n,*A = get_all_int()




# ビットごとの出現回数 2**i
bits = [0] * 60

for a in A:
    for i in range(60):
        if 2**i & a != 0:
            bits[i] += 1

# log("bits:", bits)

ans = 0

for a in A:
    a_bits = int_to_bits(a)

    for i in range(60):
        ans += 2**i * abs(bits[i] - a_bits[i]*n)

    # a_dash = list(map(lambda a: a*(n-1), a_bits))

    # log("a_dash", a_dash)

    # bits_dash = [ bits[i] - a_bits[i] for i in range(60)]
    # log("bits_dash", bits_dash)
    # ans += sum( ( 2**i * abs(bits_dash[i]-2*a_dash[i])) for i in range(60) )

    # ans += sum( ( 2**i * abs(bits[i]-2*a_dash[i])) for i in range(60) )

    # for i in range(60):
    #     ans = (ans + 2**i * abs(bits_dash[i] - a_dash[i])) % MOD
    # log(a, ans)

print(ans//2 % MOD)


### FIXED CODE ###

import sys
import time

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

def int_to_bits(x):
    return [ 1 if 2**i & x != 0 else 0 for i in range(60) ]

def inv(x, MOD):
    return pow(x, MOD-2, MOD)

start = time.time()

MOD = 10**9+7

debug = False

if debug:
    n = 30 * 10000
    A = list(range(n))
else:
    n,*A = get_all_int()

# ビットごとの出現回数 2**i
bits = [0] * 60

for a in A:
    for i in range(60):
        if 2**i & a != 0:
            bits[i] += 1

# log("bits:", bits)
# log("bits.", time.time() - start)

# ans = 0

ans = sum(( pow(2, i, MOD) * bits[i] * (n-bits[i]) for i in range(60))) % MOD

# for a in A:
#     # a_bits = [ 1 if 2**i & a != 0 else 0 for i in range(60) ]

#     for i in range(60):
#         ans += 2**i * abs(bits[i] - (1 if 2**i & a != 0 else 0) *n)

#     # a_dash = list(map(lambda a: a*(n-1), a_bits))

#     # log("a_dash", a_dash)

#     # bits_dash = [ bits[i] - a_bits[i] for i in range(60)]
#     # log("bits_dash", bits_dash)
#     # ans += sum( ( 2**i * abs(bits_dash[i]-2*a_dash[i])) for i in range(60) )

#     # ans += sum( ( 2**i * abs(bits[i]-2*a_dash[i])) for i in range(60) )

#     # for i in range(60):
#     #     ans = (ans + 2**i * abs(bits_dash[i] - a_dash[i])) % MOD
#     # log(a, ans)

# print(ans//2 % MOD)
print(ans)
# log("end.", time.time() - start)
print('Yes' if ''join(sorted.input())=='abc' else 'No' )

### FIXED CODE ###

print('Yes' if ''.join(sorted(input()))=='abc' else 'No' )
n = int(input())
p = list(map(int, input().split()))

count = 0

for i in range(len(n)-1):
  if p[i]<p[i+1]<p[i+2] or p[i+2]<p[i+1]<p[i]:
    ans += 1
    
print(ans)

### FIXED CODE ###

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

count = 0

for i in range(n-2):
  if p[i]<p[i+1]<p[i+2] or p[i+2]<p[i+1]<p[i]:
    count += 1
    
print(count)
A, B, K = map(int, input().split())
C = 0
for i in range(min(A, B), 1, -1):
    if A%i == 0 and B%i == 0:
        C += 1
        if C == K:
            break
print(i)

### FIXED CODE ###

A, B, K = map(int, input().split())
c = []

for i in range(1, 101):
    if A % i == 0 and B % i == 0:
        c.append(i)
print(c[-K])
A, B = list(map(int, input().split()))
print(max(A + B, max(A - B.A * B)))


### FIXED CODE ###

A, B = list(map(int, input().split()))
print(max(A + B, max(A - B, A * B)))
a, b = map(int, raw_input().split())
axb = a * b
if axb % 2:
    print('Odd')
else:
    print('Even')


### FIXED CODE ###

a, b = map(int, raw_input().split())
if a * b % 2:
    print('Odd')
else:
    print('Even')
A,B,X=map(int,input().split())
if B<==X-A:
  print("YES")
eles:
  print("NO")

### FIXED CODE ###

A,B,X=map(int,input().split())
if A+B>=X and A<=X:
  print("YES")
else:
  print("NO")
n=input()
n_int = int(n)

if n_int<357:
  print(0)
else:
  counter__ = 0
  for k in range(3 ,len(n)+1):
    counter__ += recursive_f([])

    def recursive_f(A):
      if len(A) == k:     # Aはリスト[7,7,7]
        A_ = int("".join(map(str,A)))    # A_はint 777
        counter = 0
        # print(A_)
        if len(set(A)) == 3 and A_ <= n_int:
          counter += 1
          return counter

        counter_ = 0

        for i in [3,5,7]:
          A.append(i)
          counter_ += recursive_f(A)
          A.pop()

          return counter_
        
print(counter__)

### FIXED CODE ###

N = input()

def dfs(A):
    if int(A) > int(N):
        return 0
    if all(A.count(c) for c in "753") >0:
        ans = 1
    else:
        ans = 0
        
    for i in "357":
        A += i
        ans += dfs(A)
        A = A[:-1]
        
    return ans

print(dfs("0"))