user_id stringlengths 10 10 | problem_id stringlengths 6 6 | language stringclasses 1 value | submission_id_v0 stringlengths 10 10 | submission_id_v1 stringlengths 10 10 | cpu_time_v0 int64 10 38.3k | cpu_time_v1 int64 0 24.7k | memory_v0 int64 2.57k 1.02M | memory_v1 int64 2.57k 869k | status_v0 stringclasses 1 value | status_v1 stringclasses 1 value | improvement_frac float64 7.51 100 | input stringlengths 20 4.55k | target stringlengths 17 3.34k | code_v0_loc int64 1 148 | code_v1_loc int64 1 184 | code_v0_num_chars int64 13 4.55k | code_v1_num_chars int64 14 3.34k | code_v0_no_empty_lines stringlengths 21 6.88k | code_v1_no_empty_lines stringlengths 20 4.93k | code_same bool 1 class | relative_loc_diff_percent float64 0 79.8 | diff list | diff_only_import_comment bool 1 class | measured_runtime_v0 float64 0.01 4.45 | measured_runtime_v1 float64 0.01 4.31 | runtime_lift float64 0 359 | key list |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
u201928947 | p02554 | python | s297740817 | s002620890 | 82 | 29 | 61,552 | 9,076 | Accepted | Accepted | 64.63 | N = int(eval(input()))
mod = 10**9+7
ans = pow(10,N,mod)-2*pow(9,N,mod)+pow(8,N,mod)
print((ans % mod)) | N = int(eval(input()))
mod = 10**9+7
print(((pow(10,N,mod)-2*pow(9,N,mod)+pow(8,N,mod))%mod)) | 4 | 3 | 98 | 87 | N = int(eval(input()))
mod = 10**9 + 7
ans = pow(10, N, mod) - 2 * pow(9, N, mod) + pow(8, N, mod)
print((ans % mod))
| N = int(eval(input()))
mod = 10**9 + 7
print(((pow(10, N, mod) - 2 * pow(9, N, mod) + pow(8, N, mod)) % mod))
| false | 25 | [
"-ans = pow(10, N, mod) - 2 * pow(9, N, mod) + pow(8, N, mod)",
"-print((ans % mod))",
"+print(((pow(10, N, mod) - 2 * pow(9, N, mod) + pow(8, N, mod)) % mod))"
] | false | 0.07608 | 0.141837 | 0.536393 | [
"s297740817",
"s002620890"
] |
u280978334 | p02899 | python | s182637801 | s653828988 | 314 | 238 | 25,972 | 25,972 | Accepted | Accepted | 24.2 | from operator import itemgetter
def main():
N = int(input())
A = [[i,int(inp)] for i,inp in zip(range(N),input().split(' '))]
A.sort(key = itemgetter(1))
for i,a in A:
print(i+1,end = ' ')
return
main()
| from operator import itemgetter
def main():
N = int(eval(input()))
A = [[i,int(a)] for i,a in zip(list(range(N)),input().split())]
A.sort(key = itemgetter(1))
for i,a in A:
print((i+1))
main() | 9 | 10 | 240 | 213 | from operator import itemgetter
def main():
N = int(input())
A = [[i, int(inp)] for i, inp in zip(range(N), input().split(" "))]
A.sort(key=itemgetter(1))
for i, a in A:
print(i + 1, end=" ")
return
main()
| from operator import itemgetter
def main():
N = int(eval(input()))
A = [[i, int(a)] for i, a in zip(list(range(N)), input().split())]
A.sort(key=itemgetter(1))
for i, a in A:
print((i + 1))
main()
| false | 10 | [
"- N = int(input())",
"- A = [[i, int(inp)] for i, inp in zip(range(N), input().split(\" \"))]",
"+ N = int(eval(input()))",
"+ A = [[i, int(a)] for i, a in zip(list(range(N)), input().split())]",
"- print(i + 1, end=\" \")",
"- return",
"+ print((i + 1))"
] | false | 0.041209 | 0.038918 | 1.05888 | [
"s182637801",
"s653828988"
] |
u418149936 | p02755 | python | s643581589 | s797603169 | 31 | 28 | 9,060 | 9,136 | Accepted | Accepted | 9.68 | A, B = list(map(int, input().split(' ')))
for i in range(1, 1010):
if i * 8 // 100 == A and i * 10 // 100 == B:
print(i)
break
else:
print((-1)) | A, B = list(map(int, input().split(' ')))
for i in range(1, 1500):
if i * 8 // 100 == A and i * 10 // 100 == B:
print(i)
break
else:
print((-1)) | 7 | 7 | 166 | 166 | A, B = list(map(int, input().split(" ")))
for i in range(1, 1010):
if i * 8 // 100 == A and i * 10 // 100 == B:
print(i)
break
else:
print((-1))
| A, B = list(map(int, input().split(" ")))
for i in range(1, 1500):
if i * 8 // 100 == A and i * 10 // 100 == B:
print(i)
break
else:
print((-1))
| false | 0 | [
"-for i in range(1, 1010):",
"+for i in range(1, 1500):"
] | false | 0.036156 | 0.038415 | 0.941195 | [
"s643581589",
"s797603169"
] |
u052499405 | p02977 | python | s588032193 | s711272894 | 279 | 253 | 5,436 | 5,436 | Accepted | Accepted | 9.32 | n = int(eval(input()))
pow2s = [2**item for item in range(32)]
if n in pow2s:
print("No")
exit()
print("Yes")
print((n+1, n+2))
for i in range(3, n+1, 2):
print((1, i))
print((1, i - 1))
print((i, n + i - 1))
print((i - 1, n + i))
if n % 2 == 0:
upper = 1 << (n.bit_length() - 1)
lower = n ^ 1 ^ upper
print((upper, n))
print((lower, n + n)) | n=int(input())
p=print
if n in [2**i for i in range(32)]:
p("No")
exit()
p("Yes")
p(n+1,n+2)
for i in range(3,n+1,2):
p(1,i)
p(1,i-1)
p(i,n+i-1)
p(i-1,n+i)
if n%2==0:
u=1<<(n.bit_length()-1)
l=n^1^u
p(u,n)
p(l,n+n)
| 17 | 17 | 377 | 240 | n = int(eval(input()))
pow2s = [2**item for item in range(32)]
if n in pow2s:
print("No")
exit()
print("Yes")
print((n + 1, n + 2))
for i in range(3, n + 1, 2):
print((1, i))
print((1, i - 1))
print((i, n + i - 1))
print((i - 1, n + i))
if n % 2 == 0:
upper = 1 << (n.bit_length() - 1)
lower = n ^ 1 ^ upper
print((upper, n))
print((lower, n + n))
| n = int(input())
p = print
if n in [2**i for i in range(32)]:
p("No")
exit()
p("Yes")
p(n + 1, n + 2)
for i in range(3, n + 1, 2):
p(1, i)
p(1, i - 1)
p(i, n + i - 1)
p(i - 1, n + i)
if n % 2 == 0:
u = 1 << (n.bit_length() - 1)
l = n ^ 1 ^ u
p(u, n)
p(l, n + n)
| false | 0 | [
"-n = int(eval(input()))",
"-pow2s = [2**item for item in range(32)]",
"-if n in pow2s:",
"- print(\"No\")",
"+n = int(input())",
"+p = print",
"+if n in [2**i for i in range(32)]:",
"+ p(\"No\")",
"-print(\"Yes\")",
"-print((n + 1, n + 2))",
"+p(\"Yes\")",
"+p(n + 1, n + 2)",
"- pr... | false | 0.037179 | 0.03763 | 0.988012 | [
"s588032193",
"s711272894"
] |
u391731808 | p03714 | python | s099917504 | s876615694 | 354 | 314 | 38,292 | 38,676 | Accepted | Accepted | 11.3 | import heapq
N = int(eval(input()))
*A, = list(map(int,input().split()))
q = []
for a in A[:N]:
heapq.heappush(q,a)
S1 = [sum(q)]
for a in A[N:N*2]:
if a>q[0]:
S1.append(S1[-1] + a - q[0])
heapq.heapreplace(q,a)
else:
S1.append(S1[-1])
q = []
for a in A[2*N:]:
heapq.heappush(q,-a)
S2 = [sum(q)]
for a in A[N:N*2][::-1]:
if a<-q[0]:
S2.append(S2[-1] - a - q[0])
heapq.heapreplace(q,-a)
else:
S2.append(S2[-1])
S2 = S2[::-1]
print((max(list(map(sum,list(zip(S1,S2))))))) | N = int(eval(input()))
*A, = list(map(int,input().split()))
from heapq import *
B1 = []
hpu = heappush
hpp = heappushpop
for a in A[:N]:
hpu(B1,a)
S1 = [sum(B1)]
for a in A[N:2*N]:
S1.append(S1[-1]+ a - hpp(B1,a))
B2 = []
for a in A[2*N:]:
hpu(B2,-a)
S2 = [-sum(B2)]
for a in A[N:2*N][::-1]:
S2.append(S2[-1] + a + hpp(B2,-a))
print((max(S1[i]-S2[-i-1] for i in range(N+1)))) | 25 | 21 | 539 | 400 | import heapq
N = int(eval(input()))
(*A,) = list(map(int, input().split()))
q = []
for a in A[:N]:
heapq.heappush(q, a)
S1 = [sum(q)]
for a in A[N : N * 2]:
if a > q[0]:
S1.append(S1[-1] + a - q[0])
heapq.heapreplace(q, a)
else:
S1.append(S1[-1])
q = []
for a in A[2 * N :]:
heapq.heappush(q, -a)
S2 = [sum(q)]
for a in A[N : N * 2][::-1]:
if a < -q[0]:
S2.append(S2[-1] - a - q[0])
heapq.heapreplace(q, -a)
else:
S2.append(S2[-1])
S2 = S2[::-1]
print((max(list(map(sum, list(zip(S1, S2)))))))
| N = int(eval(input()))
(*A,) = list(map(int, input().split()))
from heapq import *
B1 = []
hpu = heappush
hpp = heappushpop
for a in A[:N]:
hpu(B1, a)
S1 = [sum(B1)]
for a in A[N : 2 * N]:
S1.append(S1[-1] + a - hpp(B1, a))
B2 = []
for a in A[2 * N :]:
hpu(B2, -a)
S2 = [-sum(B2)]
for a in A[N : 2 * N][::-1]:
S2.append(S2[-1] + a + hpp(B2, -a))
print((max(S1[i] - S2[-i - 1] for i in range(N + 1))))
| false | 16 | [
"-import heapq",
"-",
"-q = []",
"+from heapq import *",
"+",
"+B1 = []",
"+hpu = heappush",
"+hpp = heappushpop",
"- heapq.heappush(q, a)",
"-S1 = [sum(q)]",
"-for a in A[N : N * 2]:",
"- if a > q[0]:",
"- S1.append(S1[-1] + a - q[0])",
"- heapq.heapreplace(q, a)",
"... | false | 0.039916 | 0.040793 | 0.978502 | [
"s099917504",
"s876615694"
] |
u517447467 | p02702 | python | s892787136 | s489983244 | 157 | 135 | 16,568 | 16,588 | Accepted | Accepted | 14.01 | S = eval(input())
S = S[::-1]
d = 1
mods = [0]
counter = [0]*2019
counter[0] += 1
result = 0
for s in S:
s = int(s)
mods.append((mods[-1]+s*d)%2019)
counter[mods[-1]] += 1
result += counter[mods[-1]] - 1
d *= 10
d %= 2019
print(result) | S = eval(input())
S = S[::-1]
d = 1
mods = [0]
counter = [0]*2019
counter[0] += 1
for s in S:
s = int(s)
mods.append((mods[-1]+s*d)%2019)
counter[mods[-1]] += 1
d *= 10
d %= 2019
print((sum([i*(i-1)//2 for i in counter])))
| 16 | 14 | 257 | 239 | S = eval(input())
S = S[::-1]
d = 1
mods = [0]
counter = [0] * 2019
counter[0] += 1
result = 0
for s in S:
s = int(s)
mods.append((mods[-1] + s * d) % 2019)
counter[mods[-1]] += 1
result += counter[mods[-1]] - 1
d *= 10
d %= 2019
print(result)
| S = eval(input())
S = S[::-1]
d = 1
mods = [0]
counter = [0] * 2019
counter[0] += 1
for s in S:
s = int(s)
mods.append((mods[-1] + s * d) % 2019)
counter[mods[-1]] += 1
d *= 10
d %= 2019
print((sum([i * (i - 1) // 2 for i in counter])))
| false | 12.5 | [
"-result = 0",
"- result += counter[mods[-1]] - 1",
"-print(result)",
"+print((sum([i * (i - 1) // 2 for i in counter])))"
] | false | 0.038189 | 0.041116 | 0.928812 | [
"s892787136",
"s489983244"
] |
u812576525 | p03353 | python | s641312446 | s396802818 | 1,759 | 37 | 5,052 | 5,388 | Accepted | Accepted | 97.9 | S = eval(input())
K = int(eval(input()))
A = []
for i in range(len(S)):
for j in range(1,i + 6):
if S[i:j] != "":
A.append(S[i:j])
A = sorted(set(A))
print((A[K-1])) | S = eval(input())
K = int(eval(input()))
A = []
for i in range(len(S)):
for j in range(1,6):
a = S[i:i+j]
A.append(a)
#print(A)
A = set(A)
A = sorted(set(A))
print((A[K-1])) | 12 | 12 | 199 | 202 | S = eval(input())
K = int(eval(input()))
A = []
for i in range(len(S)):
for j in range(1, i + 6):
if S[i:j] != "":
A.append(S[i:j])
A = sorted(set(A))
print((A[K - 1]))
| S = eval(input())
K = int(eval(input()))
A = []
for i in range(len(S)):
for j in range(1, 6):
a = S[i : i + j]
A.append(a)
# print(A)
A = set(A)
A = sorted(set(A))
print((A[K - 1]))
| false | 0 | [
"- for j in range(1, i + 6):",
"- if S[i:j] != \"\":",
"- A.append(S[i:j])",
"+ for j in range(1, 6):",
"+ a = S[i : i + j]",
"+ A.append(a)",
"+ # print(A)",
"+A = set(A)"
] | false | 0.068 | 0.038295 | 1.775693 | [
"s641312446",
"s396802818"
] |
u170201762 | p03065 | python | s391706371 | s133879182 | 965 | 308 | 59,224 | 46,808 | Accepted | Accepted | 68.08 | def gcd(a, b):
while b:
a, b = b, a % b
return a
def prime_decomposition(n):
i = 2
d = {}
while i * i <= n:
while n % i == 0:
n //= i
if i not in d:
d[i] = 0
d[i] += 1
i += 1
if n > 1:
if n not in d:
d[n] = 1
return d
def eratosthenes(n):
if n < 2:
return []
prime = []
limit = n**0.5
numbers = [i for i in range(2,n+1)]
while True:
p = numbers[0]
if limit <= p:
return prime + numbers
prime.append(p)
numbers = [i for i in numbers if i%p != 0]
return prime
def ok(p):
if A[0]%p != 0:
return False
B = [A[i]%p for i in range(1,N+1)]
mod = [0]*(p-1)
for i in range(N):
mod[i%(p-1)] += B[i]
mod[i%(p-1)] %= p
return sum(mod)==0
N = int(eval(input()))
A = [int(eval(input())) for i in range(N+1)][::-1]
g = abs(A[0])
for a in A:
g = gcd(g,abs(a))
d = prime_decomposition(g)
ans = [p for p in d]
prime = eratosthenes(N+1)
for p in prime:
if ok(p):
ans.append(p)
ans = list(set(ans))
ans.sort()
for p in ans:
print(p) | def gcd(a, b):
while b:
a, b = b, a % b
return a
def prime_decomposition(n):
i = 2
d = {}
while i * i <= n:
while n % i == 0:
n //= i
if i not in d:
d[i] = 0
d[i] += 1
i += 1
if n > 1:
if n not in d:
d[n] = 1
return d
def eratosthenes(n):
if n < 2:
return []
prime = []
limit = n**0.5
numbers = [i for i in range(2,n+1)]
while True:
p = numbers[0]
if limit <= p:
return prime + numbers
prime.append(p)
numbers = [i for i in numbers if i%p != 0]
return prime
N = int(eval(input()))
A = [int(eval(input())) for i in range(N+1)]
g = abs(A[0])
for a in A:
g = gcd(g,abs(a))
d = prime_decomposition(g)
ans = [p for p in d]
prime = eratosthenes(N+1)
A.reverse()
for p in prime:
if A[0]%p != 0:
continue
for n in range(1,p):
s = 0
for k in range(int((N-n)/(p-1))+1):
s += A[n+k*(p-1)]
s %= p
if s != 0:
break
if s == 0:
ans.append(p)
ans = list(set(ans))
ans.sort()
for p in ans:
print(p)
| 63 | 61 | 1,173 | 1,170 | def gcd(a, b):
while b:
a, b = b, a % b
return a
def prime_decomposition(n):
i = 2
d = {}
while i * i <= n:
while n % i == 0:
n //= i
if i not in d:
d[i] = 0
d[i] += 1
i += 1
if n > 1:
if n not in d:
d[n] = 1
return d
def eratosthenes(n):
if n < 2:
return []
prime = []
limit = n**0.5
numbers = [i for i in range(2, n + 1)]
while True:
p = numbers[0]
if limit <= p:
return prime + numbers
prime.append(p)
numbers = [i for i in numbers if i % p != 0]
return prime
def ok(p):
if A[0] % p != 0:
return False
B = [A[i] % p for i in range(1, N + 1)]
mod = [0] * (p - 1)
for i in range(N):
mod[i % (p - 1)] += B[i]
mod[i % (p - 1)] %= p
return sum(mod) == 0
N = int(eval(input()))
A = [int(eval(input())) for i in range(N + 1)][::-1]
g = abs(A[0])
for a in A:
g = gcd(g, abs(a))
d = prime_decomposition(g)
ans = [p for p in d]
prime = eratosthenes(N + 1)
for p in prime:
if ok(p):
ans.append(p)
ans = list(set(ans))
ans.sort()
for p in ans:
print(p)
| def gcd(a, b):
while b:
a, b = b, a % b
return a
def prime_decomposition(n):
i = 2
d = {}
while i * i <= n:
while n % i == 0:
n //= i
if i not in d:
d[i] = 0
d[i] += 1
i += 1
if n > 1:
if n not in d:
d[n] = 1
return d
def eratosthenes(n):
if n < 2:
return []
prime = []
limit = n**0.5
numbers = [i for i in range(2, n + 1)]
while True:
p = numbers[0]
if limit <= p:
return prime + numbers
prime.append(p)
numbers = [i for i in numbers if i % p != 0]
return prime
N = int(eval(input()))
A = [int(eval(input())) for i in range(N + 1)]
g = abs(A[0])
for a in A:
g = gcd(g, abs(a))
d = prime_decomposition(g)
ans = [p for p in d]
prime = eratosthenes(N + 1)
A.reverse()
for p in prime:
if A[0] % p != 0:
continue
for n in range(1, p):
s = 0
for k in range(int((N - n) / (p - 1)) + 1):
s += A[n + k * (p - 1)]
s %= p
if s != 0:
break
if s == 0:
ans.append(p)
ans = list(set(ans))
ans.sort()
for p in ans:
print(p)
| false | 3.174603 | [
"-def ok(p):",
"- if A[0] % p != 0:",
"- return False",
"- B = [A[i] % p for i in range(1, N + 1)]",
"- mod = [0] * (p - 1)",
"- for i in range(N):",
"- mod[i % (p - 1)] += B[i]",
"- mod[i % (p - 1)] %= p",
"- return sum(mod) == 0",
"-",
"-",
"-A = [int(eval... | false | 0.058649 | 0.03785 | 1.549535 | [
"s391706371",
"s133879182"
] |
u753803401 | p04019 | python | s251535449 | s225394162 | 186 | 171 | 38,384 | 38,256 | Accepted | Accepted | 8.06 | def slove():
import sys
input = sys.stdin.readline
ss = str(input().rstrip('\n'))
n = 1 if ss.count("N") != 0 else 0
w = 1 if ss.count("W") != 0 else 0
s = 1 if ss.count("S") != 0 else 0
e = 1 if ss.count("E") != 0 else 0
if n == s and w == e:
print("Yes")
else:
print("No")
if __name__ == '__main__':
slove()
| def slove():
import sys
import collections
input = sys.stdin.readline
s = collections.Counter(str(input().rstrip('\n')))
if len(s) == 4:
print("Yes")
elif len(s) == 2:
if "N" in s and "S" in s:
print("Yes")
elif "E" in s and "W" in s:
print("Yes")
else:
print("No")
else:
print("No")
if __name__ == '__main__':
slove()
| 16 | 20 | 383 | 448 | def slove():
import sys
input = sys.stdin.readline
ss = str(input().rstrip("\n"))
n = 1 if ss.count("N") != 0 else 0
w = 1 if ss.count("W") != 0 else 0
s = 1 if ss.count("S") != 0 else 0
e = 1 if ss.count("E") != 0 else 0
if n == s and w == e:
print("Yes")
else:
print("No")
if __name__ == "__main__":
slove()
| def slove():
import sys
import collections
input = sys.stdin.readline
s = collections.Counter(str(input().rstrip("\n")))
if len(s) == 4:
print("Yes")
elif len(s) == 2:
if "N" in s and "S" in s:
print("Yes")
elif "E" in s and "W" in s:
print("Yes")
else:
print("No")
else:
print("No")
if __name__ == "__main__":
slove()
| false | 20 | [
"+ import collections",
"- ss = str(input().rstrip(\"\\n\"))",
"- n = 1 if ss.count(\"N\") != 0 else 0",
"- w = 1 if ss.count(\"W\") != 0 else 0",
"- s = 1 if ss.count(\"S\") != 0 else 0",
"- e = 1 if ss.count(\"E\") != 0 else 0",
"- if n == s and w == e:",
"+ s = collections.C... | false | 0.036089 | 0.073478 | 0.491158 | [
"s251535449",
"s225394162"
] |
u716530146 | p02973 | python | s590733437 | s785589744 | 431 | 186 | 46,940 | 8,192 | Accepted | Accepted | 56.84 | #!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1
n=int(eval(input()))
A=[int(eval(input())) for i in range(n)]
data=collections.deque()
for i, ai in enumerate(A):
k=bisect.bisect_left(data,ai)
if k==0:
data.appendleft(ai)
else:
data[k-1]=ai
print((len(data))) | #!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1
n = int(eval(input()))
A = [int(eval(input())) for i in range(n)]
dp = [-inf] * (10**5+10);dp[-1] = inf
for ai in A:
dp[bisect.bisect_left(dp,ai)-1] = ai
for di in dp:
if di != -inf:ans += 1
print((ans - 1)) | 16 | 14 | 455 | 426 | #!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode("utf-8")
inf = float("inf")
mod = 10**9 + 7
mans = inf
ans = 0
count = 0
pro = 1
n = int(eval(input()))
A = [int(eval(input())) for i in range(n)]
data = collections.deque()
for i, ai in enumerate(A):
k = bisect.bisect_left(data, ai)
if k == 0:
data.appendleft(ai)
else:
data[k - 1] = ai
print((len(data)))
| #!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode("utf-8")
inf = float("inf")
mod = 10**9 + 7
mans = inf
ans = 0
count = 0
pro = 1
n = int(eval(input()))
A = [int(eval(input())) for i in range(n)]
dp = [-inf] * (10**5 + 10)
dp[-1] = inf
for ai in A:
dp[bisect.bisect_left(dp, ai) - 1] = ai
for di in dp:
if di != -inf:
ans += 1
print((ans - 1))
| false | 12.5 | [
"-data = collections.deque()",
"-for i, ai in enumerate(A):",
"- k = bisect.bisect_left(data, ai)",
"- if k == 0:",
"- data.appendleft(ai)",
"- else:",
"- data[k - 1] = ai",
"-print((len(data)))",
"+dp = [-inf] * (10**5 + 10)",
"+dp[-1] = inf",
"+for ai in A:",
"+ dp[... | false | 0.065594 | 0.048958 | 1.339804 | [
"s590733437",
"s785589744"
] |
u994988729 | p03805 | python | s354652658 | s982727808 | 30 | 23 | 3,064 | 3,064 | Accepted | Accepted | 23.33 | n, m = list(map(int, input().split()))
edge = [[] for _ in range(n)]
for _ in range(m):
a, b = list(map(int, input().split()))
a -= 1
b -= 1
edge[a].append(b)
edge[b].append(a)
def dfs(v, seen, res):
seen[v] = True
if all(seen):
res += 1
for i in edge[v]:
if not seen[i]:
tmp = [tf for tf in seen]
res = dfs(i, tmp, res)
return res
visited = [False]*n
ans = dfs(0, visited, 0)
print(ans)
| import itertools
N, M = list(map(int, input().split()))
edge = [[] for _ in range(N+1)]
for _ in range(M):
a, b = list(map(int, input().split()))
edge[a].append(b)
edge[b].append(a)
def isOK(seq):
s = 1
for t in seq:
if t in edge[s]:
s = t
else:
return False
return True
ans = 0
for seq in itertools.permutations(list(range(2, N + 1))):
if isOK(seq):
ans += 1
print(ans)
| 26 | 25 | 483 | 458 | n, m = list(map(int, input().split()))
edge = [[] for _ in range(n)]
for _ in range(m):
a, b = list(map(int, input().split()))
a -= 1
b -= 1
edge[a].append(b)
edge[b].append(a)
def dfs(v, seen, res):
seen[v] = True
if all(seen):
res += 1
for i in edge[v]:
if not seen[i]:
tmp = [tf for tf in seen]
res = dfs(i, tmp, res)
return res
visited = [False] * n
ans = dfs(0, visited, 0)
print(ans)
| import itertools
N, M = list(map(int, input().split()))
edge = [[] for _ in range(N + 1)]
for _ in range(M):
a, b = list(map(int, input().split()))
edge[a].append(b)
edge[b].append(a)
def isOK(seq):
s = 1
for t in seq:
if t in edge[s]:
s = t
else:
return False
return True
ans = 0
for seq in itertools.permutations(list(range(2, N + 1))):
if isOK(seq):
ans += 1
print(ans)
| false | 3.846154 | [
"-n, m = list(map(int, input().split()))",
"-edge = [[] for _ in range(n)]",
"-for _ in range(m):",
"+import itertools",
"+",
"+N, M = list(map(int, input().split()))",
"+edge = [[] for _ in range(N + 1)]",
"+for _ in range(M):",
"- a -= 1",
"- b -= 1",
"-def dfs(v, seen, res):",
"- s... | false | 0.093713 | 0.207648 | 0.451306 | [
"s354652658",
"s982727808"
] |
u083960235 | p03612 | python | s572518061 | s150331056 | 92 | 84 | 15,956 | 15,928 | Accepted | Accepted | 8.7 | import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def S_MAP(): return list(map(str, input().split()))
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
N = INT()
A = LIST()
B = [i for i in range(1, N + 1)]
C = [0] * N
r = 0
ans = 0
while r < N:
if A[r] == r + 1:
ans += 1
r += 1
r += 1
print(ans)
exit()
for i in range(N):
if A[i] == B[i]:
C[i] = 1
# for i in range(N-1):
r = 0
pre_is_one = False
# 1の連続数を数える
conti_one = []
# print(C)
while r < N:
conti = 0
while C[r] == 1:
conti += 1
r += 1
# print(r)
if r >= N:
break
conti_one.append(conti)
# if C[r] == 1:
# ans += 1
# while C[r]
# r += 1
# if pre_is_one == True:
# ans -= 1
# pre_is_one = True
if r < N and C[r] == 0:
r += 1
# print(ans)
# print(conti_one)
ans = 0
for c in conti_one:
# print(c)
if c == 1:
ans += 1
elif c > 1:
ans += c - 1
print(ans)
| import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from heapq import heappop, heapify, heappush
def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def S_MAP(): return list(map(str, input().split()))
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
N = INT()
A = LIST()
ans = 0
i = 0
while i < N:
if A[i] == i + 1:
ans += 1
i += 1
i += 1
print(ans)
# for i in range(N):
# if A[i] == i + 1:
# ans += 1
# if i < N - 1:
# if A[i + 1] == i + 2:
# tmp += 1
# ans -= 1
# print(ans)
# print(tmp) | 79 | 43 | 1,644 | 1,122 | import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input():
return sys.stdin.readline().strip()
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def S_MAP():
return list(map(str, input().split()))
def LIST():
return list(map(int, input().split()))
def S_LIST():
return list(map(str, input().split()))
sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
N = INT()
A = LIST()
B = [i for i in range(1, N + 1)]
C = [0] * N
r = 0
ans = 0
while r < N:
if A[r] == r + 1:
ans += 1
r += 1
r += 1
print(ans)
exit()
for i in range(N):
if A[i] == B[i]:
C[i] = 1
# for i in range(N-1):
r = 0
pre_is_one = False
# 1の連続数を数える
conti_one = []
# print(C)
while r < N:
conti = 0
while C[r] == 1:
conti += 1
r += 1
# print(r)
if r >= N:
break
conti_one.append(conti)
# if C[r] == 1:
# ans += 1
# while C[r]
# r += 1
# if pre_is_one == True:
# ans -= 1
# pre_is_one = True
if r < N and C[r] == 0:
r += 1
# print(ans)
# print(conti_one)
ans = 0
for c in conti_one:
# print(c)
if c == 1:
ans += 1
elif c > 1:
ans += c - 1
print(ans)
| import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from heapq import heappop, heapify, heappush
def input():
return sys.stdin.readline().strip()
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def S_MAP():
return list(map(str, input().split()))
def LIST():
return list(map(int, input().split()))
def S_LIST():
return list(map(str, input().split()))
sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
N = INT()
A = LIST()
ans = 0
i = 0
while i < N:
if A[i] == i + 1:
ans += 1
i += 1
i += 1
print(ans)
# for i in range(N):
# if A[i] == i + 1:
# ans += 1
# if i < N - 1:
# if A[i + 1] == i + 2:
# tmp += 1
# ans -= 1
# print(ans)
# print(tmp)
| false | 45.56962 | [
"+from heapq import heappop, heapify, heappush",
"-B = [i for i in range(1, N + 1)]",
"-C = [0] * N",
"-r = 0",
"-while r < N:",
"- if A[r] == r + 1:",
"+i = 0",
"+while i < N:",
"+ if A[i] == i + 1:",
"- r += 1",
"- r += 1",
"+ i += 1",
"+ i += 1",
"-exit()",
"... | false | 0.038112 | 0.078392 | 0.486167 | [
"s572518061",
"s150331056"
] |
u659159398 | p02627 | python | s769207539 | s463920322 | 499 | 64 | 72,784 | 61,624 | Accepted | Accepted | 87.17 | from sys import stdin
from collections import defaultdict as dd
from collections import deque as dq
import itertools as it
from math import sqrt, log, log2
from fractions import Fraction
# n, k = map(int, input().split())
# nums = list(map(int, stdin.readline().split()))
# nums.sort()
# print(sum(nums[:k]))
n = eval(input())
if n.isupper():
print('A')
else:
print('a') | n = eval(input())
if n.isupper():
print('A')
else:
print('a') | 17 | 5 | 390 | 67 | from sys import stdin
from collections import defaultdict as dd
from collections import deque as dq
import itertools as it
from math import sqrt, log, log2
from fractions import Fraction
# n, k = map(int, input().split())
# nums = list(map(int, stdin.readline().split()))
# nums.sort()
# print(sum(nums[:k]))
n = eval(input())
if n.isupper():
print("A")
else:
print("a")
| n = eval(input())
if n.isupper():
print("A")
else:
print("a")
| false | 70.588235 | [
"-from sys import stdin",
"-from collections import defaultdict as dd",
"-from collections import deque as dq",
"-import itertools as it",
"-from math import sqrt, log, log2",
"-from fractions import Fraction",
"-",
"-# n, k = map(int, input().split())",
"-# nums = list(map(int, stdin.readline().spl... | false | 0.035536 | 0.035516 | 1.000542 | [
"s769207539",
"s463920322"
] |
u796942881 | p03043 | python | s534671551 | s666605334 | 22 | 18 | 3,188 | 3,060 | Accepted | Accepted | 18.18 | import math
def main():
N, K = list(map(int, input().split()))
print(((max(0, N - K + 1) + sum((
max(0, N - (math.ceil(K * (1 / 2) ** i)) + 1)
- max(0, N - (math.ceil(K * (1 / 2) ** (i - 1))) + 1)) * (1 / 2) ** i
for i in range(1, int(math.log2(K)) + 1 + 1))) / N))
return
main()
| import math
def main():
N, K = list(map(int, input().split()))
print(((max(0, N - K + 1) + sum(
max(0, N - (math.ceil(K * (1 / 2) ** i)) + 1) * (1 / 2) ** i
- max(0, N - (math.ceil(K * (1 / 2) ** (i - 1))) + 1) * (1 / 2) ** i
for i in range(1, int(math.log2(K)) + 1 + 1))) / N))
return
main()
| 13 | 13 | 324 | 337 | import math
def main():
N, K = list(map(int, input().split()))
print(
(
(
max(0, N - K + 1)
+ sum(
(
max(0, N - (math.ceil(K * (1 / 2) ** i)) + 1)
- max(0, N - (math.ceil(K * (1 / 2) ** (i - 1))) + 1)
)
* (1 / 2) ** i
for i in range(1, int(math.log2(K)) + 1 + 1)
)
)
/ N
)
)
return
main()
| import math
def main():
N, K = list(map(int, input().split()))
print(
(
(
max(0, N - K + 1)
+ sum(
max(0, N - (math.ceil(K * (1 / 2) ** i)) + 1) * (1 / 2) ** i
- max(0, N - (math.ceil(K * (1 / 2) ** (i - 1))) + 1) * (1 / 2) ** i
for i in range(1, int(math.log2(K)) + 1 + 1)
)
)
/ N
)
)
return
main()
| false | 0 | [
"- (",
"- max(0, N - (math.ceil(K * (1 / 2) ** i)) + 1)",
"- - max(0, N - (math.ceil(K * (1 / 2) ** (i - 1))) + 1)",
"- )",
"- * (1 / 2) ** i",
"+ max(0, N - (math.ceil(K * (1 / 2) ** ... | false | 0.048303 | 0.049012 | 0.985517 | [
"s534671551",
"s666605334"
] |
u767995501 | p03030 | python | s340041689 | s305832233 | 19 | 17 | 3,064 | 3,060 | Accepted | Accepted | 10.53 | n = int(eval(input()))
SP = []
for i in range(n):
s, p = input().split()
SP += [[s,int(p),i+1]]
SP.sort(key=lambda A:(A[0],-A[1]))
for sp in SP:
print((sp[2])) | N = int(eval(input()))
SP = []
for i in range(N):
s,p = input().split()
SP.append((s,-int(p),i+1))
SP.sort()
for s,p,i in SP:
print(i) | 8 | 11 | 167 | 149 | n = int(eval(input()))
SP = []
for i in range(n):
s, p = input().split()
SP += [[s, int(p), i + 1]]
SP.sort(key=lambda A: (A[0], -A[1]))
for sp in SP:
print((sp[2]))
| N = int(eval(input()))
SP = []
for i in range(N):
s, p = input().split()
SP.append((s, -int(p), i + 1))
SP.sort()
for s, p, i in SP:
print(i)
| false | 27.272727 | [
"-n = int(eval(input()))",
"+N = int(eval(input()))",
"-for i in range(n):",
"+for i in range(N):",
"- SP += [[s, int(p), i + 1]]",
"-SP.sort(key=lambda A: (A[0], -A[1]))",
"-for sp in SP:",
"- print((sp[2]))",
"+ SP.append((s, -int(p), i + 1))",
"+SP.sort()",
"+for s, p, i in SP:",
"... | false | 0.044557 | 0.044762 | 0.995425 | [
"s340041689",
"s305832233"
] |
u562935282 | p03128 | python | s939732654 | s799848019 | 62 | 52 | 3,436 | 3,676 | Accepted | Accepted | 16.13 | from operator import itemgetter
inf = 10 ** 4
n, m = list(map(int, input().split()))
a = tuple(map(int, input().split()))
use = [None, 2, 5, 5, 4, 5, 6, 3, 7, 6]
# use[i] : 数字iを作るのに必要なマッチの本数
use_num = {use[i]: i for i in range(1, 10) if i in a}
use_num = tuple(sorted(use_num.items()))
# 本数昇順
# print(use_num)
dp = [-inf] * (n + 1)
dp[0] = 0
# dp[j] : j本から構成できる桁数の最大値
for j in range(2, n + 1):
for use, number in use_num:
k = j - use
if k >= 0:
dp[j] = max(dp[j], dp[k] + 1)
# print(dp)
use_num = tuple(sorted(use_num, key=itemgetter(1), reverse=True))
# 数字降順
rest = n
ans = ''
while rest > 0:
for use, number in use_num:
k = rest - use
if (k >= 0) and (dp[k] == dp[rest] - 1):
ans += str(number)
rest -= use
break
print(ans) | inf = 1 << 20
need = -1, 2, 5, 5, 4, 5, 6, 3, 7, 6
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
d = {need[x]: x for x in sorted(a)} # sortedで昇順にすることで、同じ本数のとき最大値が残る
e = tuple(sorted(list(d.items()), key=lambda x: x[1], reverse=True)) # (必要本数,数字)
dp = [-inf] * (n + 1)
dp[0] = 0
# dp[k]:=k本で構成可能な最大桁数
for j in range(1, n + 1):
dp[j] = max((dp[j - cnt] for cnt, _ in e if j - cnt >= 0), default=-inf) + 1
ret = []
r = dp[n]
curr = n
while r > 0:
for cnt, num in e:
if curr - cnt >= 0 and dp[curr - cnt] == r - 1:
ret.append(num)
r -= 1
curr -= cnt
break
ret.sort(reverse=True)
print((''.join(map(str, ret))))
| 39 | 29 | 853 | 716 | from operator import itemgetter
inf = 10**4
n, m = list(map(int, input().split()))
a = tuple(map(int, input().split()))
use = [None, 2, 5, 5, 4, 5, 6, 3, 7, 6]
# use[i] : 数字iを作るのに必要なマッチの本数
use_num = {use[i]: i for i in range(1, 10) if i in a}
use_num = tuple(sorted(use_num.items()))
# 本数昇順
# print(use_num)
dp = [-inf] * (n + 1)
dp[0] = 0
# dp[j] : j本から構成できる桁数の最大値
for j in range(2, n + 1):
for use, number in use_num:
k = j - use
if k >= 0:
dp[j] = max(dp[j], dp[k] + 1)
# print(dp)
use_num = tuple(sorted(use_num, key=itemgetter(1), reverse=True))
# 数字降順
rest = n
ans = ""
while rest > 0:
for use, number in use_num:
k = rest - use
if (k >= 0) and (dp[k] == dp[rest] - 1):
ans += str(number)
rest -= use
break
print(ans)
| inf = 1 << 20
need = -1, 2, 5, 5, 4, 5, 6, 3, 7, 6
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
d = {need[x]: x for x in sorted(a)} # sortedで昇順にすることで、同じ本数のとき最大値が残る
e = tuple(sorted(list(d.items()), key=lambda x: x[1], reverse=True)) # (必要本数,数字)
dp = [-inf] * (n + 1)
dp[0] = 0
# dp[k]:=k本で構成可能な最大桁数
for j in range(1, n + 1):
dp[j] = max((dp[j - cnt] for cnt, _ in e if j - cnt >= 0), default=-inf) + 1
ret = []
r = dp[n]
curr = n
while r > 0:
for cnt, num in e:
if curr - cnt >= 0 and dp[curr - cnt] == r - 1:
ret.append(num)
r -= 1
curr -= cnt
break
ret.sort(reverse=True)
print(("".join(map(str, ret))))
| false | 25.641026 | [
"-from operator import itemgetter",
"-",
"-inf = 10**4",
"+inf = 1 << 20",
"+need = -1, 2, 5, 5, 4, 5, 6, 3, 7, 6",
"-a = tuple(map(int, input().split()))",
"-use = [None, 2, 5, 5, 4, 5, 6, 3, 7, 6]",
"-# use[i] : 数字iを作るのに必要なマッチの本数",
"-use_num = {use[i]: i for i in range(1, 10) if i in a}",
"-use_... | false | 0.043699 | 0.162254 | 0.269322 | [
"s939732654",
"s799848019"
] |
u150984829 | p02272 | python | s631376474 | s354916432 | 4,280 | 3,490 | 63,928 | 63,912 | Accepted | Accepted | 18.46 | def m(L,R):
global c
i=j=0
for _ in L[:-1]+R[:-1]:
if L[i]<R[j]:yield L[i];i+=1
else:yield R[j];j+=1
c+=1
def d(A):
s=len(A)//2
if len(A)>1:A[:]=m(d(A[:s])+[1e9],d(A[s:])+[1e9])
return A
c=0
eval(input())
print((*d(list(map(int,input().split())))))
print(c)
| def m(L,R):
global c;c+=len(L)+len(R)
T=[];j=0
for l in L:
while j<len(R)and R[j]<l:T+=[R[j]];j+=1
T+=[l]
while j<len(R):T+=[R[j]];j+=1
return T
def d(A):s=len(A)//2;return m(d(A[:s]),d(A[s:])) if len(A)>1 else A
c=0
eval(input())
print((*d(list(map(int,input().split())))))
print(c)
| 15 | 13 | 276 | 297 | def m(L, R):
global c
i = j = 0
for _ in L[:-1] + R[:-1]:
if L[i] < R[j]:
yield L[i]
i += 1
else:
yield R[j]
j += 1
c += 1
def d(A):
s = len(A) // 2
if len(A) > 1:
A[:] = m(d(A[:s]) + [1e9], d(A[s:]) + [1e9])
return A
c = 0
eval(input())
print((*d(list(map(int, input().split())))))
print(c)
| def m(L, R):
global c
c += len(L) + len(R)
T = []
j = 0
for l in L:
while j < len(R) and R[j] < l:
T += [R[j]]
j += 1
T += [l]
while j < len(R):
T += [R[j]]
j += 1
return T
def d(A):
s = len(A) // 2
return m(d(A[:s]), d(A[s:])) if len(A) > 1 else A
c = 0
eval(input())
print((*d(list(map(int, input().split())))))
print(c)
| false | 13.333333 | [
"- i = j = 0",
"- for _ in L[:-1] + R[:-1]:",
"- if L[i] < R[j]:",
"- yield L[i]",
"- i += 1",
"- else:",
"- yield R[j]",
"+ c += len(L) + len(R)",
"+ T = []",
"+ j = 0",
"+ for l in L:",
"+ while j < len(R) and R[j] < l:"... | false | 0.102712 | 0.047889 | 2.144786 | [
"s631376474",
"s354916432"
] |
u977389981 | p03295 | python | s094267284 | s291147764 | 531 | 448 | 23,584 | 23,584 | Accepted | Accepted | 15.63 | n, m = list(map(int, input().split()))
SG = sorted([[int(i) for i in input().split()] for i in range(m)], key = lambda x: x[1])
cnt = 1
b = SG[0][1]
for s, g in SG:
if s >= b:
b = g
cnt += 1
print(cnt) | n, m = list(map(int, input().split()))
A = sorted([[int(i) for i in input().split()] for i in range(m)], key = lambda x: x[1])
cnt = 0
posi = 0
for s, g in A:
if s >= posi:
posi = g
cnt += 1
print(cnt) | 11 | 11 | 235 | 235 | n, m = list(map(int, input().split()))
SG = sorted([[int(i) for i in input().split()] for i in range(m)], key=lambda x: x[1])
cnt = 1
b = SG[0][1]
for s, g in SG:
if s >= b:
b = g
cnt += 1
print(cnt)
| n, m = list(map(int, input().split()))
A = sorted([[int(i) for i in input().split()] for i in range(m)], key=lambda x: x[1])
cnt = 0
posi = 0
for s, g in A:
if s >= posi:
posi = g
cnt += 1
print(cnt)
| false | 0 | [
"-SG = sorted([[int(i) for i in input().split()] for i in range(m)], key=lambda x: x[1])",
"-cnt = 1",
"-b = SG[0][1]",
"-for s, g in SG:",
"- if s >= b:",
"- b = g",
"+A = sorted([[int(i) for i in input().split()] for i in range(m)], key=lambda x: x[1])",
"+cnt = 0",
"+posi = 0",
"+for ... | false | 0.03647 | 0.034684 | 1.051496 | [
"s094267284",
"s291147764"
] |
u765865533 | p02659 | python | s592485568 | s345811644 | 24 | 22 | 9,164 | 9,032 | Accepted | Accepted | 8.33 | a,b=list(map(str,input().split()))
tempb=int(float(b)*1000)
tempa=int(a)
print((int(tempa*tempb)//1000))
| a,b=list(map(float,input().split()))
tempb=int(float(b)*1000)
tempa=int(a)
print((int(tempa*tempb)//1000))
| 4 | 4 | 100 | 102 | a, b = list(map(str, input().split()))
tempb = int(float(b) * 1000)
tempa = int(a)
print((int(tempa * tempb) // 1000))
| a, b = list(map(float, input().split()))
tempb = int(float(b) * 1000)
tempa = int(a)
print((int(tempa * tempb) // 1000))
| false | 0 | [
"-a, b = list(map(str, input().split()))",
"+a, b = list(map(float, input().split()))"
] | false | 0.040194 | 0.096726 | 0.415547 | [
"s592485568",
"s345811644"
] |
u761320129 | p03837 | python | s562417548 | s884932319 | 568 | 455 | 3,444 | 9,348 | Accepted | Accepted | 19.89 | N,M = list(map(int,input().split()))
src = [tuple(map(int,input().split())) for i in range(M)]
INF = float('inf')
wf = [[INF]*N for i in range(N)]
for a,b,c in src:
a,b = a-1,b-1
wf[a][b] = wf[b][a] = c
for i in range(N):
wf[i][i] = 0
for k in range(N):
for i in range(N):
for j in range(N):
wf[i][j] = min(wf[i][j], wf[i][k] + wf[k][j])
ans = 0
for a,b,c in src:
a,b = a-1,b-1
if c != wf[a][b]:
ans += 1
print(ans) | N,M = list(map(int,input().split()))
ABC = [tuple(map(int,input().split())) for i in range(M)]
INF = float('inf')
ds = [[INF]*N for _ in range(N)]
for i in range(N):
ds[i][i] = 0
for a,b,c in ABC:
a,b = a-1,b-1
ds[a][b] = ds[b][a] = c
for k in range(N):
for i in range(N):
for j in range(N):
ds[i][j] = min(ds[i][j], ds[i][k]+ds[k][j])
ans = 0
for a,b,c in ABC:
a,b = a-1,b-1
if ds[a][b] < c:
ans += 1
print(ans) | 21 | 22 | 483 | 482 | N, M = list(map(int, input().split()))
src = [tuple(map(int, input().split())) for i in range(M)]
INF = float("inf")
wf = [[INF] * N for i in range(N)]
for a, b, c in src:
a, b = a - 1, b - 1
wf[a][b] = wf[b][a] = c
for i in range(N):
wf[i][i] = 0
for k in range(N):
for i in range(N):
for j in range(N):
wf[i][j] = min(wf[i][j], wf[i][k] + wf[k][j])
ans = 0
for a, b, c in src:
a, b = a - 1, b - 1
if c != wf[a][b]:
ans += 1
print(ans)
| N, M = list(map(int, input().split()))
ABC = [tuple(map(int, input().split())) for i in range(M)]
INF = float("inf")
ds = [[INF] * N for _ in range(N)]
for i in range(N):
ds[i][i] = 0
for a, b, c in ABC:
a, b = a - 1, b - 1
ds[a][b] = ds[b][a] = c
for k in range(N):
for i in range(N):
for j in range(N):
ds[i][j] = min(ds[i][j], ds[i][k] + ds[k][j])
ans = 0
for a, b, c in ABC:
a, b = a - 1, b - 1
if ds[a][b] < c:
ans += 1
print(ans)
| false | 4.545455 | [
"-src = [tuple(map(int, input().split())) for i in range(M)]",
"+ABC = [tuple(map(int, input().split())) for i in range(M)]",
"-wf = [[INF] * N for i in range(N)]",
"-for a, b, c in src:",
"+ds = [[INF] * N for _ in range(N)]",
"+for i in range(N):",
"+ ds[i][i] = 0",
"+for a, b, c in ABC:",
"- ... | false | 0.040147 | 0.044275 | 0.906759 | [
"s562417548",
"s884932319"
] |
u301461168 | p02390 | python | s021398379 | s500240916 | 40 | 20 | 8,124 | 7,652 | Accepted | Accepted | 50 | import datetime
n = int(input().rstrip())
#??????
int_hour = n // 3600
int_minute = (n % 3600) // 60
int_second = n- int_hour*3600 - int_minute * 60
# ??????????????????
print(int_hour,int_minute, int_second, sep=":" )
| n = int(input().rstrip())
#??????
int_hour = n // 3600
int_minute = (n % 3600) // 60
int_second = n- int_hour*3600 - int_minute * 60
# ??????????????????
print(int_hour,int_minute, int_second, sep=":" )
| 12 | 10 | 233 | 214 | import datetime
n = int(input().rstrip())
# ??????
int_hour = n // 3600
int_minute = (n % 3600) // 60
int_second = n - int_hour * 3600 - int_minute * 60
# ??????????????????
print(int_hour, int_minute, int_second, sep=":")
| n = int(input().rstrip())
# ??????
int_hour = n // 3600
int_minute = (n % 3600) // 60
int_second = n - int_hour * 3600 - int_minute * 60
# ??????????????????
print(int_hour, int_minute, int_second, sep=":")
| false | 16.666667 | [
"-import datetime",
"-"
] | false | 0.070077 | 0.070073 | 1.000055 | [
"s021398379",
"s500240916"
] |
u864197622 | p02728 | python | s597757892 | s439312416 | 1,236 | 875 | 136,484 | 126,000 | Accepted | Accepted | 29.21 | import sys
input = sys.stdin.readline
from collections import deque
nn = 200200
mod = 10**9+7
fa = [1] * (nn+1)
fainv = [1] * (nn+1)
inv = [1] * (nn+1)
for i in range(nn):
fa[i+1] = fa[i] * (i+1) % mod
fainv[-1] = pow(fa[-1], mod-2, mod)
for i in range(nn)[::-1]:
fainv[i] = fainv[i+1] * (i+1) % mod
for i in range(1, nn)[::-1]:
inv[i] = fainv[i] * fa[i-1]
N = int(input())
X = [[] for i in range(N)]
for i in range(N-1):
x, y = map(int, input().split())
X[x-1].append(y-1)
X[y-1].append(x-1)
P = [-1] * N
Q = deque([0])
R = []
while Q:
i = deque.popleft(Q)
R.append(i)
for a in X[i]:
if a != P[i]:
P[a] = i
X[a].remove(i)
deque.append(Q, a)
unit = 1
f = lambda a, b: a * b % mod
g_bu = lambda a, i=-1: a * inv[SI[i]] % mod
g_td = lambda a, i=-1: a * inv[N - SI[i]] % mod
SI = [1] * N
for i in R[1:][::-1]:
SI[P[i]] += SI[i]
BU = [unit] * N
TD = [unit] * N
for i in R[1:][::-1]:
BU[i] = g_bu(BU[i], i)
p = P[i]
BU[p] = f(BU[p], BU[i])
BU[0] = g_bu(BU[0], 0)
AX = [1] * N
for i in R:
ac = unit
for j in X[i]:
AX[j] = ac
ac = f(ac, BU[j])
ac = unit
for j in X[i][::-1]:
AX[j] = f(AX[j], ac)
TD[j] = g_td(f(TD[i], AX[j]), j)
ac = f(ac, BU[j])
print(*[BU[i] * SI[i] % mod * TD[i] % mod * fa[N - 1] % mod for i in range(N)], sep = "\n")
| import sys
input = sys.stdin.readline
from collections import deque
nn = 200200
mod = 10**9+7
fa = [1] * (nn+1)
fainv = [1] * (nn+1)
for i in range(nn):
fa[i+1] = fa[i] * (i+1) % mod
fainv[-1] = pow(fa[-1], mod-2, mod)
for i in range(nn)[::-1]:
fainv[i] = fainv[i+1] * (i+1) % mod
inv = lambda i: fainv[i] * fa[i-1] % mod
N = int(input())
X = [[] for i in range(N)]
for i in range(N-1):
x, y = map(int, input().split())
X[x-1].append(y-1)
X[y-1].append(x-1)
P = [-1] * N
Q = deque([0])
R = []
while Q:
i = deque.popleft(Q)
R.append(i)
for a in X[i]:
if a != P[i]:
P[a] = i
X[a].remove(i)
deque.append(Q, a)
unit = 1
f = lambda a, b: a * b % mod
g_bu = lambda a, i=-1: a * inv(SI[i]) % mod
g_td = lambda a, i=-1: a * inv(N - SI[i]) % mod
SI = [1] * N
for i in R[1:][::-1]:
SI[P[i]] += SI[i]
BU = [unit] * N
TD = [unit] * N
for i in R[1:][::-1]:
BU[i] = g_bu(BU[i], i)
p = P[i]
BU[p] = f(BU[p], BU[i])
BU[R[0]] = g_bu(BU[R[0]], R[0])
AX = [1] * N
for i in R:
ac = unit
for j in X[i]:
AX[j] = ac
ac = f(ac, BU[j])
ac = unit
for j in X[i][::-1]:
AX[j] = f(AX[j], ac)
TD[j] = g_td(f(TD[i], AX[j]), j)
ac = f(ac, BU[j])
print(*[BU[i] * SI[i] % mod * TD[i] % mod * fa[N - 1] % mod for i in range(N)], sep = "\n")
| 67 | 66 | 1,458 | 1,428 | import sys
input = sys.stdin.readline
from collections import deque
nn = 200200
mod = 10**9 + 7
fa = [1] * (nn + 1)
fainv = [1] * (nn + 1)
inv = [1] * (nn + 1)
for i in range(nn):
fa[i + 1] = fa[i] * (i + 1) % mod
fainv[-1] = pow(fa[-1], mod - 2, mod)
for i in range(nn)[::-1]:
fainv[i] = fainv[i + 1] * (i + 1) % mod
for i in range(1, nn)[::-1]:
inv[i] = fainv[i] * fa[i - 1]
N = int(input())
X = [[] for i in range(N)]
for i in range(N - 1):
x, y = map(int, input().split())
X[x - 1].append(y - 1)
X[y - 1].append(x - 1)
P = [-1] * N
Q = deque([0])
R = []
while Q:
i = deque.popleft(Q)
R.append(i)
for a in X[i]:
if a != P[i]:
P[a] = i
X[a].remove(i)
deque.append(Q, a)
unit = 1
f = lambda a, b: a * b % mod
g_bu = lambda a, i=-1: a * inv[SI[i]] % mod
g_td = lambda a, i=-1: a * inv[N - SI[i]] % mod
SI = [1] * N
for i in R[1:][::-1]:
SI[P[i]] += SI[i]
BU = [unit] * N
TD = [unit] * N
for i in R[1:][::-1]:
BU[i] = g_bu(BU[i], i)
p = P[i]
BU[p] = f(BU[p], BU[i])
BU[0] = g_bu(BU[0], 0)
AX = [1] * N
for i in R:
ac = unit
for j in X[i]:
AX[j] = ac
ac = f(ac, BU[j])
ac = unit
for j in X[i][::-1]:
AX[j] = f(AX[j], ac)
TD[j] = g_td(f(TD[i], AX[j]), j)
ac = f(ac, BU[j])
print(
*[BU[i] * SI[i] % mod * TD[i] % mod * fa[N - 1] % mod for i in range(N)], sep="\n"
)
| import sys
input = sys.stdin.readline
from collections import deque
nn = 200200
mod = 10**9 + 7
fa = [1] * (nn + 1)
fainv = [1] * (nn + 1)
for i in range(nn):
fa[i + 1] = fa[i] * (i + 1) % mod
fainv[-1] = pow(fa[-1], mod - 2, mod)
for i in range(nn)[::-1]:
fainv[i] = fainv[i + 1] * (i + 1) % mod
inv = lambda i: fainv[i] * fa[i - 1] % mod
N = int(input())
X = [[] for i in range(N)]
for i in range(N - 1):
x, y = map(int, input().split())
X[x - 1].append(y - 1)
X[y - 1].append(x - 1)
P = [-1] * N
Q = deque([0])
R = []
while Q:
i = deque.popleft(Q)
R.append(i)
for a in X[i]:
if a != P[i]:
P[a] = i
X[a].remove(i)
deque.append(Q, a)
unit = 1
f = lambda a, b: a * b % mod
g_bu = lambda a, i=-1: a * inv(SI[i]) % mod
g_td = lambda a, i=-1: a * inv(N - SI[i]) % mod
SI = [1] * N
for i in R[1:][::-1]:
SI[P[i]] += SI[i]
BU = [unit] * N
TD = [unit] * N
for i in R[1:][::-1]:
BU[i] = g_bu(BU[i], i)
p = P[i]
BU[p] = f(BU[p], BU[i])
BU[R[0]] = g_bu(BU[R[0]], R[0])
AX = [1] * N
for i in R:
ac = unit
for j in X[i]:
AX[j] = ac
ac = f(ac, BU[j])
ac = unit
for j in X[i][::-1]:
AX[j] = f(AX[j], ac)
TD[j] = g_td(f(TD[i], AX[j]), j)
ac = f(ac, BU[j])
print(
*[BU[i] * SI[i] % mod * TD[i] % mod * fa[N - 1] % mod for i in range(N)], sep="\n"
)
| false | 1.492537 | [
"-inv = [1] * (nn + 1)",
"-for i in range(1, nn)[::-1]:",
"- inv[i] = fainv[i] * fa[i - 1]",
"+inv = lambda i: fainv[i] * fa[i - 1] % mod",
"-g_bu = lambda a, i=-1: a * inv[SI[i]] % mod",
"-g_td = lambda a, i=-1: a * inv[N - SI[i]] % mod",
"+g_bu = lambda a, i=-1: a * inv(SI[i]) % mod",
"+g_td = la... | false | 0.323145 | 0.343007 | 0.942093 | [
"s597757892",
"s439312416"
] |
u131984977 | p02410 | python | s809575430 | s573100634 | 40 | 30 | 7,016 | 8,048 | Accepted | Accepted | 25 | (n, m) = [int(i) for i in input().split()]
A = []
b = []
for i in range(n):
A.append([int(j) for j in input().split()])
for i in range(m):
b.append(int(eval(input())))
for i in range(n):
s = 0
for j in range(m):
s += A[i][j] * b[j]
print(s) | n, m = [int(i) for i in input().split()]
matrix = []
for ni in range(n):
matrix.append([int(a) for a in input().split()])
vector = []
for mi in range(m):
vector.append(int(eval(input())))
for ni in range(n):
sum = 0
for mi in range(m):
sum += matrix[ni][mi] * vector[mi]
print(sum) | 14 | 16 | 277 | 322 | (n, m) = [int(i) for i in input().split()]
A = []
b = []
for i in range(n):
A.append([int(j) for j in input().split()])
for i in range(m):
b.append(int(eval(input())))
for i in range(n):
s = 0
for j in range(m):
s += A[i][j] * b[j]
print(s)
| n, m = [int(i) for i in input().split()]
matrix = []
for ni in range(n):
matrix.append([int(a) for a in input().split()])
vector = []
for mi in range(m):
vector.append(int(eval(input())))
for ni in range(n):
sum = 0
for mi in range(m):
sum += matrix[ni][mi] * vector[mi]
print(sum)
| false | 12.5 | [
"-(n, m) = [int(i) for i in input().split()]",
"-A = []",
"-b = []",
"-for i in range(n):",
"- A.append([int(j) for j in input().split()])",
"-for i in range(m):",
"- b.append(int(eval(input())))",
"-for i in range(n):",
"- s = 0",
"- for j in range(m):",
"- s += A[i][j] * b[j... | false | 0.042967 | 0.042824 | 1.00334 | [
"s809575430",
"s573100634"
] |
u092387689 | p02642 | python | s982814912 | s343166912 | 1,477 | 482 | 36,652 | 36,200 | Accepted | Accepted | 67.37 | n = int(eval(input()))
l = [int(x) for x in input().split()]
D = set() #Duplication
S = set() #all
for x in l:
if x in S:
D.add(x)
else:
S.add(x)
limit = 10**6+1
mp = [0]*(limit)
cnt = 0
S = sorted(S)
for x in S:
for y in range(x,limit,x):
mp[y] += 1
if(x in D):
continue
if(mp[x]==1):
cnt += 1
print(cnt)
| n = int(eval(input()))
l = [int(x) for x in input().split()]
D = set() #Duplication
S = set() #all
for x in l:
if x in S:
D.add(x)
else:
S.add(x)
M = max(S)
limit = M+1
mp = [0]*(limit)
cnt = 0
S = sorted(S)
for x in S:
for y in range(x,limit,x):
mp[y] += 1
if(x in D):
continue
if(mp[x]==1):
cnt += 1
print(cnt)
| 27 | 28 | 400 | 408 | n = int(eval(input()))
l = [int(x) for x in input().split()]
D = set() # Duplication
S = set() # all
for x in l:
if x in S:
D.add(x)
else:
S.add(x)
limit = 10**6 + 1
mp = [0] * (limit)
cnt = 0
S = sorted(S)
for x in S:
for y in range(x, limit, x):
mp[y] += 1
if x in D:
continue
if mp[x] == 1:
cnt += 1
print(cnt)
| n = int(eval(input()))
l = [int(x) for x in input().split()]
D = set() # Duplication
S = set() # all
for x in l:
if x in S:
D.add(x)
else:
S.add(x)
M = max(S)
limit = M + 1
mp = [0] * (limit)
cnt = 0
S = sorted(S)
for x in S:
for y in range(x, limit, x):
mp[y] += 1
if x in D:
continue
if mp[x] == 1:
cnt += 1
print(cnt)
| false | 3.571429 | [
"-limit = 10**6 + 1",
"+M = max(S)",
"+limit = M + 1"
] | false | 0.279174 | 0.066124 | 4.221962 | [
"s982814912",
"s343166912"
] |
u712284046 | p02716 | python | s082816838 | s636873814 | 208 | 173 | 31,704 | 31,624 | Accepted | Accepted | 16.83 | N = int(eval(input()))
A = list(map(int, input().split()))
DP_odd = [0, 0, A[0]]
DP_even = [0, max(A[0], A[1])]
if N >= 3:
DP_odd = [DP_even[0], max(DP_odd[1] + A[2], DP_even[1]), DP_odd[2] + A[2]]
for i in range(3, N):
if (i + 1) % 2 == 1:
DP_odd = [max(DP_odd[0] + A[i], DP_even[0]), max(DP_odd[1] + A[i], DP_even[1]), DP_odd[2] + A[i]]
else:
DP_even = [max(DP_even[0] + A[i], DP_odd[1]), max(DP_even[1] + A[i], DP_odd[2])]
if N % 2 == 1:
ans = DP_odd[1]
else:
ans = DP_even[1]
print(ans) | N = int(eval(input()))
A = list(map(int, input().split()))
DP_odd = [0, A[0]]
DP_even = [0, max(A[0], A[1])]
for i in range(2, N):
if (i + 1) % 2 == 1:
DP_odd = [max(DP_odd[0] + A[i], DP_even[1]), DP_odd[1] + A[i]]
else:
DP_even = [max(DP_even[0] + A[i], DP_odd[0]), max(DP_even[1] + A[i], DP_odd[1])]
if N % 2 == 1:
ans = DP_odd[0]
else:
ans = DP_even[1]
print(ans) | 21 | 18 | 549 | 417 | N = int(eval(input()))
A = list(map(int, input().split()))
DP_odd = [0, 0, A[0]]
DP_even = [0, max(A[0], A[1])]
if N >= 3:
DP_odd = [DP_even[0], max(DP_odd[1] + A[2], DP_even[1]), DP_odd[2] + A[2]]
for i in range(3, N):
if (i + 1) % 2 == 1:
DP_odd = [
max(DP_odd[0] + A[i], DP_even[0]),
max(DP_odd[1] + A[i], DP_even[1]),
DP_odd[2] + A[i],
]
else:
DP_even = [max(DP_even[0] + A[i], DP_odd[1]), max(DP_even[1] + A[i], DP_odd[2])]
if N % 2 == 1:
ans = DP_odd[1]
else:
ans = DP_even[1]
print(ans)
| N = int(eval(input()))
A = list(map(int, input().split()))
DP_odd = [0, A[0]]
DP_even = [0, max(A[0], A[1])]
for i in range(2, N):
if (i + 1) % 2 == 1:
DP_odd = [max(DP_odd[0] + A[i], DP_even[1]), DP_odd[1] + A[i]]
else:
DP_even = [max(DP_even[0] + A[i], DP_odd[0]), max(DP_even[1] + A[i], DP_odd[1])]
if N % 2 == 1:
ans = DP_odd[0]
else:
ans = DP_even[1]
print(ans)
| false | 14.285714 | [
"-DP_odd = [0, 0, A[0]]",
"+DP_odd = [0, A[0]]",
"-if N >= 3:",
"- DP_odd = [DP_even[0], max(DP_odd[1] + A[2], DP_even[1]), DP_odd[2] + A[2]]",
"-for i in range(3, N):",
"+for i in range(2, N):",
"- DP_odd = [",
"- max(DP_odd[0] + A[i], DP_even[0]),",
"- max(DP_odd[1]... | false | 0.045109 | 0.075482 | 0.59762 | [
"s082816838",
"s636873814"
] |
u241159583 | p03611 | python | s560273744 | s975711005 | 132 | 104 | 19,756 | 20,912 | Accepted | Accepted | 21.21 | n = int(eval(input()))
A = list(map(int, input().split()))
cnt = {}
for a in A:
if a-1 not in cnt: cnt[a-1] = 1
else: cnt[a-1] += 1
if a not in cnt: cnt[a] = 1
else: cnt[a] += 1
if a+1 not in cnt: cnt[a+1] = 1
else: cnt[a+1] += 1
print((max(cnt.values()))) | from collections import Counter
n = int(eval(input()))
a = list(map(int, input().split()))
A = Counter(a)
ans = 0
for x,y in list(A.items()):
z = y + A[x-1] + A[x+1]
ans = max(z, ans)
print(ans) | 11 | 9 | 282 | 198 | n = int(eval(input()))
A = list(map(int, input().split()))
cnt = {}
for a in A:
if a - 1 not in cnt:
cnt[a - 1] = 1
else:
cnt[a - 1] += 1
if a not in cnt:
cnt[a] = 1
else:
cnt[a] += 1
if a + 1 not in cnt:
cnt[a + 1] = 1
else:
cnt[a + 1] += 1
print((max(cnt.values())))
| from collections import Counter
n = int(eval(input()))
a = list(map(int, input().split()))
A = Counter(a)
ans = 0
for x, y in list(A.items()):
z = y + A[x - 1] + A[x + 1]
ans = max(z, ans)
print(ans)
| false | 18.181818 | [
"+from collections import Counter",
"+",
"-A = list(map(int, input().split()))",
"-cnt = {}",
"-for a in A:",
"- if a - 1 not in cnt:",
"- cnt[a - 1] = 1",
"- else:",
"- cnt[a - 1] += 1",
"- if a not in cnt:",
"- cnt[a] = 1",
"- else:",
"- cnt[a] += 1"... | false | 0.038636 | 0.041934 | 0.921352 | [
"s560273744",
"s975711005"
] |
u079022693 | p03611 | python | s150625962 | s066384957 | 117 | 82 | 14,244 | 13,864 | Accepted | Accepted | 29.91 | from sys import stdin
def main():
#入力
readline=stdin.readline
n=int(readline())
a=list(map(int,readline().split()))
d=dict()
for i in range(n):
if a[i] not in d:
d[a[i]]=1
else:
d[a[i]]+=1
cnt=0
for x in range(1,10**5+1):
if x-1 in d: s=d[x-1]
else: s=0
if x in d: t=d[x]
else: t=0
if x+1 in d: u=d[x+1]
else: u=0
cnt=max(cnt,s+t+u)
print(cnt)
if __name__=="__main__":
main() | from sys import stdin
def main():
#入力
readline=stdin.readline
n=int(readline())
a=list(map(int,readline().split()))
li=[0]*(10**5+2)
for i in range(n):
li[a[i]]+=1
cnt=0
for x in range(1,10**5+1):
cnt=max(cnt,li[x-1]+li[x]+li[x+1])
print(cnt)
if __name__=="__main__":
main() | 31 | 19 | 548 | 352 | from sys import stdin
def main():
# 入力
readline = stdin.readline
n = int(readline())
a = list(map(int, readline().split()))
d = dict()
for i in range(n):
if a[i] not in d:
d[a[i]] = 1
else:
d[a[i]] += 1
cnt = 0
for x in range(1, 10**5 + 1):
if x - 1 in d:
s = d[x - 1]
else:
s = 0
if x in d:
t = d[x]
else:
t = 0
if x + 1 in d:
u = d[x + 1]
else:
u = 0
cnt = max(cnt, s + t + u)
print(cnt)
if __name__ == "__main__":
main()
| from sys import stdin
def main():
# 入力
readline = stdin.readline
n = int(readline())
a = list(map(int, readline().split()))
li = [0] * (10**5 + 2)
for i in range(n):
li[a[i]] += 1
cnt = 0
for x in range(1, 10**5 + 1):
cnt = max(cnt, li[x - 1] + li[x] + li[x + 1])
print(cnt)
if __name__ == "__main__":
main()
| false | 38.709677 | [
"- d = dict()",
"+ li = [0] * (10**5 + 2)",
"- if a[i] not in d:",
"- d[a[i]] = 1",
"- else:",
"- d[a[i]] += 1",
"+ li[a[i]] += 1",
"- if x - 1 in d:",
"- s = d[x - 1]",
"- else:",
"- s = 0",
"- if x in... | false | 0.239285 | 0.085188 | 2.808904 | [
"s150625962",
"s066384957"
] |
u997521090 | p03128 | python | s512342336 | s560621312 | 101 | 85 | 4,344 | 4,100 | Accepted | Accepted | 15.84 | #!/usr/bin/env python
from collections import deque
import itertools as it
import sys
import math
sys.setrecursionlimit(1000000)
INF = 10 ** 18
N, M = list(map(int, input().split()))
c = [0,2,5,5,4,5,6,3,7,6]
A = sorted(map(int, input().split()))
D = [0] + [-1] * N * 9
a = [0, 0] * N
for i in range(1, N + 1):
for j in A:p=i-c[j];D[i],a[i]=[[D[i],a[i]],[D[p]+1,j]][min(p,D[p],D[p]+1-D[i])>=0]
S, p = "", N
while p:S,p=S+str(a[p]),p-c[a[p]]
print(S) | r=raw_input
N,M=r().split()
c=[0,2,5,5,4,5,6,3,7,6]
A=sorted(r().split())
N=int(N)
D,a=[0]+[-1]*N*9,[0,0]*N
for i in range(1, N + 1):
for j in A:
p=i-c[int(j)]
if min(p,D[p],D[p]+1-D[i])>=0:D[i],a[i]=D[p]+1,j
S=""
while N:S,N=S+a[N],N-c[int(a[N])]
print(S) | 24 | 13 | 481 | 272 | #!/usr/bin/env python
from collections import deque
import itertools as it
import sys
import math
sys.setrecursionlimit(1000000)
INF = 10**18
N, M = list(map(int, input().split()))
c = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
A = sorted(map(int, input().split()))
D = [0] + [-1] * N * 9
a = [0, 0] * N
for i in range(1, N + 1):
for j in A:
p = i - c[j]
D[i], a[i] = [[D[i], a[i]], [D[p] + 1, j]][min(p, D[p], D[p] + 1 - D[i]) >= 0]
S, p = "", N
while p:
S, p = S + str(a[p]), p - c[a[p]]
print(S)
| r = raw_input
N, M = r().split()
c = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
A = sorted(r().split())
N = int(N)
D, a = [0] + [-1] * N * 9, [0, 0] * N
for i in range(1, N + 1):
for j in A:
p = i - c[int(j)]
if min(p, D[p], D[p] + 1 - D[i]) >= 0:
D[i], a[i] = D[p] + 1, j
S = ""
while N:
S, N = S + a[N], N - c[int(a[N])]
print(S)
| false | 45.833333 | [
"-#!/usr/bin/env python",
"-from collections import deque",
"-import itertools as it",
"-import sys",
"-import math",
"-",
"-sys.setrecursionlimit(1000000)",
"-INF = 10**18",
"-N, M = list(map(int, input().split()))",
"+r = raw_input",
"+N, M = r().split()",
"-A = sorted(map(int, input().split... | false | 0.04525 | 0.043487 | 1.040555 | [
"s512342336",
"s560621312"
] |
u644907318 | p03609 | python | s701780354 | s304950657 | 169 | 64 | 38,256 | 61,684 | Accepted | Accepted | 62.13 | X,T = list(map(int,input().split()))
print((max(X-T,0))) | X,t = list(map(int,input().split()))
print((max(X-t,0))) | 2 | 2 | 49 | 49 | X, T = list(map(int, input().split()))
print((max(X - T, 0)))
| X, t = list(map(int, input().split()))
print((max(X - t, 0)))
| false | 0 | [
"-X, T = list(map(int, input().split()))",
"-print((max(X - T, 0)))",
"+X, t = list(map(int, input().split()))",
"+print((max(X - t, 0)))"
] | false | 0.033707 | 0.034501 | 0.976998 | [
"s701780354",
"s304950657"
] |
u572032237 | p03377 | python | s533855263 | s251098389 | 30 | 27 | 9,088 | 9,060 | Accepted | Accepted | 10 | a, b, x = list(map(int, input().split()))
if x - a > 0:
if a + b >= x:
print('YES')
else:
print('NO')
elif x == a:
print('YES')
else:
print('NO') | a, b, x = list(map(int, input().split()))
if x >= a and x <= a + b:
print('YES')
else:
print('NO') | 10 | 5 | 181 | 104 | a, b, x = list(map(int, input().split()))
if x - a > 0:
if a + b >= x:
print("YES")
else:
print("NO")
elif x == a:
print("YES")
else:
print("NO")
| a, b, x = list(map(int, input().split()))
if x >= a and x <= a + b:
print("YES")
else:
print("NO")
| false | 50 | [
"-if x - a > 0:",
"- if a + b >= x:",
"- print(\"YES\")",
"- else:",
"- print(\"NO\")",
"-elif x == a:",
"+if x >= a and x <= a + b:"
] | false | 0.038341 | 0.041114 | 0.932553 | [
"s533855263",
"s251098389"
] |
u848647227 | p03817 | python | s019754499 | s420171620 | 21 | 17 | 3,316 | 2,940 | Accepted | Accepted | 19.05 | a = int(eval(input()))
count = 0
if a % 11 < 7 and a % 11 != 0:
count += 1
elif a % 11 != 0:
count += 2
count += (a // 11) * 2
print(count)
| a = int(eval(input()))
x = (a // 11) * 2
if a % 11 > 6:
x += 2
elif a % 11 > 0:
x += 1
print(x) | 8 | 7 | 149 | 103 | a = int(eval(input()))
count = 0
if a % 11 < 7 and a % 11 != 0:
count += 1
elif a % 11 != 0:
count += 2
count += (a // 11) * 2
print(count)
| a = int(eval(input()))
x = (a // 11) * 2
if a % 11 > 6:
x += 2
elif a % 11 > 0:
x += 1
print(x)
| false | 12.5 | [
"-count = 0",
"-if a % 11 < 7 and a % 11 != 0:",
"- count += 1",
"-elif a % 11 != 0:",
"- count += 2",
"-count += (a // 11) * 2",
"-print(count)",
"+x = (a // 11) * 2",
"+if a % 11 > 6:",
"+ x += 2",
"+elif a % 11 > 0:",
"+ x += 1",
"+print(x)"
] | false | 0.04351 | 0.146718 | 0.296552 | [
"s019754499",
"s420171620"
] |
u894934980 | p02714 | python | s040099652 | s583876498 | 295 | 135 | 68,752 | 68,844 | Accepted | Accepted | 54.24 | import sys
import collections
N = int(eval(input()))
S = [ch for ch in eval(input())]
counter = collections.Counter(S)
if len(list(counter.keys())) != 3:
print((0))
sys.exit()
total = 1
for k, v in list(counter.items()):
total *= v
for i in range(len(S)):
l, r = i - 1, i + 1
while 0 <= l and r < len(S):
if len(set([S[i], S[l], S[r]])) == 3:
total -= 1
l -= 1
r += 1
print(total) | from collections import defaultdict
N = int(eval(input()))
S = eval(input())
counter = defaultdict(int)
for s in S:
counter[s] += 1
total = counter["R"] * counter["G"] * counter["B"]
for i in range(N):
for j in range(i, N):
k = j + (j - i)
if k >= N:
break
if S[i] != S[j] and S[j] != S[k] and S[i] != S[k]:
total -= 1
print(total) | 21 | 16 | 432 | 391 | import sys
import collections
N = int(eval(input()))
S = [ch for ch in eval(input())]
counter = collections.Counter(S)
if len(list(counter.keys())) != 3:
print((0))
sys.exit()
total = 1
for k, v in list(counter.items()):
total *= v
for i in range(len(S)):
l, r = i - 1, i + 1
while 0 <= l and r < len(S):
if len(set([S[i], S[l], S[r]])) == 3:
total -= 1
l -= 1
r += 1
print(total)
| from collections import defaultdict
N = int(eval(input()))
S = eval(input())
counter = defaultdict(int)
for s in S:
counter[s] += 1
total = counter["R"] * counter["G"] * counter["B"]
for i in range(N):
for j in range(i, N):
k = j + (j - i)
if k >= N:
break
if S[i] != S[j] and S[j] != S[k] and S[i] != S[k]:
total -= 1
print(total)
| false | 23.809524 | [
"-import sys",
"-import collections",
"+from collections import defaultdict",
"-S = [ch for ch in eval(input())]",
"-counter = collections.Counter(S)",
"-if len(list(counter.keys())) != 3:",
"- print((0))",
"- sys.exit()",
"-total = 1",
"-for k, v in list(counter.items()):",
"- total *=... | false | 0.046904 | 0.008126 | 5.772045 | [
"s040099652",
"s583876498"
] |
u620480037 | p03946 | python | s865503156 | s437636836 | 107 | 87 | 12,068 | 14,252 | Accepted | Accepted | 18.69 | NT=eval(input())
NT=NT.rstrip().split(" ")
N=int(NT[0])
T=int(NT[1])
cnt=0
sa=0
min=0
max=0
L=eval(input())
L=L.rstrip().split(" ")
min=int(L[0])
for i in range(1,len(L)):
if int(L[i])<min:
min=int(L[i])
s=int(L[i])-min
if s>sa:
sa=s
cnt=1
elif s==sa:
cnt+=1
#print(cnt,sa,max,min)
print(cnt)
| N,T=list(map(int,input().split()))
listA=list(map(int,input().split()))
max=-1
count=0
min=listA[0]
for i in range(N-1):
if listA[1+i]<min:
min=listA[1+i]
if listA[1+i]-min>max:
max=listA[1+i]-min
count=1
elif listA[1+i]-min==max:
count+=1
print(count) | 27 | 14 | 379 | 303 | NT = eval(input())
NT = NT.rstrip().split(" ")
N = int(NT[0])
T = int(NT[1])
cnt = 0
sa = 0
min = 0
max = 0
L = eval(input())
L = L.rstrip().split(" ")
min = int(L[0])
for i in range(1, len(L)):
if int(L[i]) < min:
min = int(L[i])
s = int(L[i]) - min
if s > sa:
sa = s
cnt = 1
elif s == sa:
cnt += 1
# print(cnt,sa,max,min)
print(cnt)
| N, T = list(map(int, input().split()))
listA = list(map(int, input().split()))
max = -1
count = 0
min = listA[0]
for i in range(N - 1):
if listA[1 + i] < min:
min = listA[1 + i]
if listA[1 + i] - min > max:
max = listA[1 + i] - min
count = 1
elif listA[1 + i] - min == max:
count += 1
print(count)
| false | 48.148148 | [
"-NT = eval(input())",
"-NT = NT.rstrip().split(\" \")",
"-N = int(NT[0])",
"-T = int(NT[1])",
"-cnt = 0",
"-sa = 0",
"-min = 0",
"-max = 0",
"-L = eval(input())",
"-L = L.rstrip().split(\" \")",
"-min = int(L[0])",
"-for i in range(1, len(L)):",
"- if int(L[i]) < min:",
"- min =... | false | 0.047722 | 0.051432 | 0.927874 | [
"s865503156",
"s437636836"
] |
u379959788 | p03111 | python | s320880062 | s623920862 | 434 | 71 | 3,064 | 3,064 | Accepted | Accepted | 83.64 | # ABC119C
# Synthetic Kadomatsu
Enter = list(map(int, input().split()))
N = Enter[0]
L = [int(eval(input())) for _ in range(N)]
ans = 10 ** 10
# 4 bist search
for i in range(4**N):
mask = i
NowCost = 0
Group = [[] * 4 for _ in range(4)]
for j in range(N-1, -1, -1):
Group[mask%4].append(L[j])
mask //= 4
if len(Group[0]) == 0 or len(Group[1]) == 0 or len(Group[2]) == 0:
continue
for j in range(3):
NowCost += 10 * (len(Group[j]) - 1)
NowCost += abs(sum(Group[j]) - Enter[j+1])
ans = min(ans, NowCost)
print(ans)
| N, A, B, C = list(map(int, input().split()))
L = [int(eval(input())) for _ in range(N)]
INF = 10 ** 9
def dfs(cur, a, b, c):
if cur == N:
if min(a, b, c) > 0:
return abs(a-A)+abs(b-B)+abs(c-C)-30
else:
return INF
ret1 = dfs(cur+1, a, b, c)
ret2 = dfs(cur+1, a+L[cur], b, c) + 10
ret3 = dfs(cur+1, a, b+L[cur], c) + 10
ret4 = dfs(cur+1, a, b, c+L[cur]) + 10
return min(ret1, ret2, ret3, ret4)
print((dfs(0,0,0,0)))
| 23 | 18 | 599 | 484 | # ABC119C
# Synthetic Kadomatsu
Enter = list(map(int, input().split()))
N = Enter[0]
L = [int(eval(input())) for _ in range(N)]
ans = 10**10
# 4 bist search
for i in range(4**N):
mask = i
NowCost = 0
Group = [[] * 4 for _ in range(4)]
for j in range(N - 1, -1, -1):
Group[mask % 4].append(L[j])
mask //= 4
if len(Group[0]) == 0 or len(Group[1]) == 0 or len(Group[2]) == 0:
continue
for j in range(3):
NowCost += 10 * (len(Group[j]) - 1)
NowCost += abs(sum(Group[j]) - Enter[j + 1])
ans = min(ans, NowCost)
print(ans)
| N, A, B, C = list(map(int, input().split()))
L = [int(eval(input())) for _ in range(N)]
INF = 10**9
def dfs(cur, a, b, c):
if cur == N:
if min(a, b, c) > 0:
return abs(a - A) + abs(b - B) + abs(c - C) - 30
else:
return INF
ret1 = dfs(cur + 1, a, b, c)
ret2 = dfs(cur + 1, a + L[cur], b, c) + 10
ret3 = dfs(cur + 1, a, b + L[cur], c) + 10
ret4 = dfs(cur + 1, a, b, c + L[cur]) + 10
return min(ret1, ret2, ret3, ret4)
print((dfs(0, 0, 0, 0)))
| false | 21.73913 | [
"-# ABC119C",
"-# Synthetic Kadomatsu",
"-Enter = list(map(int, input().split()))",
"-N = Enter[0]",
"+N, A, B, C = list(map(int, input().split()))",
"-ans = 10**10",
"-# 4 bist search",
"-for i in range(4**N):",
"- mask = i",
"- NowCost = 0",
"- Group = [[] * 4 for _ in range(4)]",
"... | false | 0.367955 | 0.057588 | 6.389457 | [
"s320880062",
"s623920862"
] |
u863044225 | p02651 | python | s192836080 | s767599973 | 117 | 85 | 9,112 | 73,916 | Accepted | Accepted | 27.35 | def solve():
n=int(eval(input()))
a=list(map(int,input().split()))
s=eval(input())
base=[]
for i in range(n-1,-1,-1):
v=a[i]
for x in base:
v=min(v,v^x)
if v:
if s[i]=='0':
base.append(v)
else:
return 1
return 0
t=int(eval(input()))
for _ in range(t):
print((solve())) | def solve():
n=int(eval(input()))
a=list(map(int,input().split()))
s=eval(input())
base=[]
for i in range(n-1,-1,-1):
v=a[i]
for x in base:
v=min(v,v^x)
if v:
if s[i]=='0':
base.append(v)
else:
return 1
return 0
def main():
t=int(eval(input()))
for _ in range(t):
print((solve()))
if __name__ == '__main__':
main() | 19 | 23 | 327 | 386 | def solve():
n = int(eval(input()))
a = list(map(int, input().split()))
s = eval(input())
base = []
for i in range(n - 1, -1, -1):
v = a[i]
for x in base:
v = min(v, v ^ x)
if v:
if s[i] == "0":
base.append(v)
else:
return 1
return 0
t = int(eval(input()))
for _ in range(t):
print((solve()))
| def solve():
n = int(eval(input()))
a = list(map(int, input().split()))
s = eval(input())
base = []
for i in range(n - 1, -1, -1):
v = a[i]
for x in base:
v = min(v, v ^ x)
if v:
if s[i] == "0":
base.append(v)
else:
return 1
return 0
def main():
t = int(eval(input()))
for _ in range(t):
print((solve()))
if __name__ == "__main__":
main()
| false | 17.391304 | [
"-t = int(eval(input()))",
"-for _ in range(t):",
"- print((solve()))",
"+def main():",
"+ t = int(eval(input()))",
"+ for _ in range(t):",
"+ print((solve()))",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.062169 | 0.067854 | 0.91623 | [
"s192836080",
"s767599973"
] |
u241159583 | p03796 | python | s852137353 | s171229990 | 47 | 42 | 8,880 | 9,108 | Accepted | Accepted | 10.64 | n = int(eval(input()))
p = 1
MOD = 10**9+7
for i in range(n): p = p*(i+1)%MOD
print(p) | n = int(eval(input()))
mod = 10 ** 9 + 7
power = 1
for i in range(1,n+1):
power = (power*i)%mod
print(power) | 5 | 6 | 84 | 111 | n = int(eval(input()))
p = 1
MOD = 10**9 + 7
for i in range(n):
p = p * (i + 1) % MOD
print(p)
| n = int(eval(input()))
mod = 10**9 + 7
power = 1
for i in range(1, n + 1):
power = (power * i) % mod
print(power)
| false | 16.666667 | [
"-p = 1",
"-MOD = 10**9 + 7",
"-for i in range(n):",
"- p = p * (i + 1) % MOD",
"-print(p)",
"+mod = 10**9 + 7",
"+power = 1",
"+for i in range(1, n + 1):",
"+ power = (power * i) % mod",
"+print(power)"
] | false | 0.055245 | 0.054366 | 1.016161 | [
"s852137353",
"s171229990"
] |
u140201022 | p02413 | python | s835017518 | s549353797 | 30 | 20 | 4,656 | 4,312 | Accepted | Accepted | 33.33 | #!/usr/bin/env python
# -*- coding:utf-8 -*-
import time
import sys
import io
import re
import math
#start = time.time()
start = time.clock()
l=[]
m=[]
s=[]
(r,c)=list(map(int, input().split()))
for i in range(r):
l.append(list(map(int, input().split())))
### ???????????則??\?????????
for cc in range(c):
a=0
for rr in range(r):
a+=int(l[rr][cc])
# print int(l[rr][cc])
s.append(a)
for j in range(r):
print(' '.join(map(str,l[j])),str(sum(l[j])))
print(' '.join(map(str,s)),str(sum(s))) | r,c=list(map(int,input().split()))
l=[]
for i in range(r):l.append(list(map(int,input().split())))
l.append([0]*(c+1))
for i in range(c+1):
for j in range(r):
if i==0:l[j].append(sum(l[j]))
l[-1][i]+=l[j][i]
for i in range(r+1):print(' '.join(map(str,l[i]))) | 25 | 9 | 539 | 280 | #!/usr/bin/env python
# -*- coding:utf-8 -*-
import time
import sys
import io
import re
import math
# start = time.time()
start = time.clock()
l = []
m = []
s = []
(r, c) = list(map(int, input().split()))
for i in range(r):
l.append(list(map(int, input().split())))
### ???????????則??\?????????
for cc in range(c):
a = 0
for rr in range(r):
a += int(l[rr][cc])
# print int(l[rr][cc])
s.append(a)
for j in range(r):
print(" ".join(map(str, l[j])), str(sum(l[j])))
print(" ".join(map(str, s)), str(sum(s)))
| r, c = list(map(int, input().split()))
l = []
for i in range(r):
l.append(list(map(int, input().split())))
l.append([0] * (c + 1))
for i in range(c + 1):
for j in range(r):
if i == 0:
l[j].append(sum(l[j]))
l[-1][i] += l[j][i]
for i in range(r + 1):
print(" ".join(map(str, l[i])))
| false | 64 | [
"-#!/usr/bin/env python",
"-# -*- coding:utf-8 -*-",
"-import time",
"-import sys",
"-import io",
"-import re",
"-import math",
"-",
"-# start = time.time()",
"-start = time.clock()",
"+r, c = list(map(int, input().split()))",
"-m = []",
"-s = []",
"-(r, c) = list(map(int, input().split())... | false | 0.008364 | 0.042655 | 0.196091 | [
"s835017518",
"s549353797"
] |
u931889893 | p03331 | python | s156203961 | s960094227 | 752 | 283 | 3,064 | 3,864 | Accepted | Accepted | 62.37 | N = int(eval(input()))
results = ''
for A in range(N + 1):
if A == 0:
continue
BBB = []
AAA = []
B = N - A
if B >= 1:
for b in range(len(str(B))):
BBB.append(int(str(B)[b]))
for a in range(len(str(A))):
AAA.append(int(str(A)[a]))
sums = sum(BBB) + sum(AAA)
if sums == 1:
print(A)
print(B)
print(AAA)
print(BBB)
if not results:
results = sums
else:
if results > sums:
results = sums
print(results) | # 記録
N = int(eval(input()))
results = []
for i in range(1,N):
results.append(sum(map(int,str(i))) + sum(map(int,str(N-i))))
print((min(results))) | 29 | 6 | 610 | 146 | N = int(eval(input()))
results = ""
for A in range(N + 1):
if A == 0:
continue
BBB = []
AAA = []
B = N - A
if B >= 1:
for b in range(len(str(B))):
BBB.append(int(str(B)[b]))
for a in range(len(str(A))):
AAA.append(int(str(A)[a]))
sums = sum(BBB) + sum(AAA)
if sums == 1:
print(A)
print(B)
print(AAA)
print(BBB)
if not results:
results = sums
else:
if results > sums:
results = sums
print(results)
| # 記録
N = int(eval(input()))
results = []
for i in range(1, N):
results.append(sum(map(int, str(i))) + sum(map(int, str(N - i))))
print((min(results)))
| false | 79.310345 | [
"+# 記録",
"-results = \"\"",
"-for A in range(N + 1):",
"- if A == 0:",
"- continue",
"- BBB = []",
"- AAA = []",
"- B = N - A",
"- if B >= 1:",
"- for b in range(len(str(B))):",
"- BBB.append(int(str(B)[b]))",
"- for a in range(len(str(A))):",
"... | false | 0.213733 | 0.338537 | 0.631343 | [
"s156203961",
"s960094227"
] |
u708255304 | p02763 | python | s232715172 | s648311810 | 990 | 831 | 165,956 | 51,624 | Accepted | Accepted | 16.06 | # Binary Indexed Treeを各アルファベットについてもつ (それぞれN+1の空間を保持し、1-indexで考える)
N = int(eval(input()))
S = list(eval(input()))
BITS = [[0]*(N+1) for _ in range(26)]
# 初期化を行おうと思ったが、これ自体に関数が必要である
# 値の加算
def ctoi(alphabet):
return ord(alphabet)-97
# 1~idxまでの文字に各文字がどれだけ出現するか
def BIT_query(idx):
res = [0]*26
for i in range(26):
p = idx
tmp = 0
while p > 0:
tmp += BITS[i][p]
p -= p & (-p)
res[i] = tmp
return res
def BIT_update(idx, alphabet, x): # idx: int, alphabet: str, x: int
while idx <= N:
BITS[ctoi(alphabet)][idx] += x
idx += idx&(-idx)
# 初期化を行う
for i in range(N):
BIT_update(i+1, S[i], 1)
# クエリを受け取っていく
Q = int(eval(input()))
for _ in range(Q):
type, a, b = list(map(str, input().split()))
if type == "1": # 更新のクエリなら
# このとき、aはindex, bは変更後の文字(str)である
a = int(a)
if S[a-1] == b:
continue
BIT_update(a, S[a-1], -1) # 減らす処理
BIT_update(a, b, 1) # 増やす処理
S[a-1] = b
elif type == "2": # 回答する必要があるクエリ
# このとき、aは左端, bは右端
a, b = int(a), int(b)
cnt1 = BIT_query(a-1)
cnt2 = BIT_query(b)
ans = 0
for i in range(26):
if cnt2[i] > cnt1[i]:
ans += 1
print(ans)
| """segfunc"""
# 論理和を返す
def segfunc(x, y):
return x | y
def init(init_val):
# set_val
for i in range(N):
seg[i-1+num] = init_val[i]
# built
for i in range(num-2, -1, -1): # 木の下の方から埋めていく, nではなくnumであることに注意
seg[i] = segfunc(seg[2*i+1], seg[2*i+2]) # 子のインデックス
# 更新
def update(k, x):
k += num-1 # 場所kに対するseg木の葉のindex?
seg[k] = x
while k:
k = (k-1)//2 # 親のノードのindexを取得
seg[k] = segfunc(seg[2*k+1], seg[2*k+2])
def query(p, q):
if q <= p: # 半開区間なので、等しくてもアウト?
return ide_ele
p += num-1
q += num-2 # 半開区間なので、q側を-2している?
res = ide_ele
while q-p > 1:
if p % 2 == 0:
res = segfunc(res, seg[p])
if q % 2 == 1:
res = segfunc(res, seg[q])
q -= 1
p = p//2
q = (q-1)//2
if p == q:
res = segfunc(res, seg[p])
else:
res = segfunc(segfunc(res, seg[p]), seg[q])
return res
# 単位元
ide_ele = 0
N = int(eval(input()))
ss = list(eval(input()))
s = []
for i in range(N):
s.append(1<<(ord(ss[i]))-97)
# num: n以上の最小の2のベキ乗
num = 2**(N-1).bit_length()
seg = [ide_ele]*2*num
init(s)
def popcnt(n):
c = (n & 0x5555555555555555) + ((n>>1) & 0x5555555555555555)
c = (c & 0x3333333333333333) + ((c>>2) & 0x3333333333333333)
c = (c & 0x0f0f0f0f0f0f0f0f) + ((c>>4) & 0x0f0f0f0f0f0f0f0f)
c = (c & 0x00ff00ff00ff00ff) + ((c>>8) & 0x00ff00ff00ff00ff)
c = (c & 0x0000ffff0000ffff) + ((c>>16) & 0x0000ffff0000ffff)
c = (c & 0x00000000ffffffff) + ((c>>32) & 0x00000000ffffffff)
return c
q = int(eval(input()))
for i in range(q):
qq, xx, yy = list(map(str, input().split()))
if qq == '1':
xx = int(xx)
update(xx-1,1<<(ord(yy)-97))
else:
xx, yy = int(xx), int(yy)
res = query(xx-1,yy)
print((popcnt(res)))
| 57 | 84 | 1,335 | 1,911 | # Binary Indexed Treeを各アルファベットについてもつ (それぞれN+1の空間を保持し、1-indexで考える)
N = int(eval(input()))
S = list(eval(input()))
BITS = [[0] * (N + 1) for _ in range(26)]
# 初期化を行おうと思ったが、これ自体に関数が必要である
# 値の加算
def ctoi(alphabet):
return ord(alphabet) - 97
# 1~idxまでの文字に各文字がどれだけ出現するか
def BIT_query(idx):
res = [0] * 26
for i in range(26):
p = idx
tmp = 0
while p > 0:
tmp += BITS[i][p]
p -= p & (-p)
res[i] = tmp
return res
def BIT_update(idx, alphabet, x): # idx: int, alphabet: str, x: int
while idx <= N:
BITS[ctoi(alphabet)][idx] += x
idx += idx & (-idx)
# 初期化を行う
for i in range(N):
BIT_update(i + 1, S[i], 1)
# クエリを受け取っていく
Q = int(eval(input()))
for _ in range(Q):
type, a, b = list(map(str, input().split()))
if type == "1": # 更新のクエリなら
# このとき、aはindex, bは変更後の文字(str)である
a = int(a)
if S[a - 1] == b:
continue
BIT_update(a, S[a - 1], -1) # 減らす処理
BIT_update(a, b, 1) # 増やす処理
S[a - 1] = b
elif type == "2": # 回答する必要があるクエリ
# このとき、aは左端, bは右端
a, b = int(a), int(b)
cnt1 = BIT_query(a - 1)
cnt2 = BIT_query(b)
ans = 0
for i in range(26):
if cnt2[i] > cnt1[i]:
ans += 1
print(ans)
| """segfunc"""
# 論理和を返す
def segfunc(x, y):
return x | y
def init(init_val):
# set_val
for i in range(N):
seg[i - 1 + num] = init_val[i]
# built
for i in range(num - 2, -1, -1): # 木の下の方から埋めていく, nではなくnumであることに注意
seg[i] = segfunc(seg[2 * i + 1], seg[2 * i + 2]) # 子のインデックス
# 更新
def update(k, x):
k += num - 1 # 場所kに対するseg木の葉のindex?
seg[k] = x
while k:
k = (k - 1) // 2 # 親のノードのindexを取得
seg[k] = segfunc(seg[2 * k + 1], seg[2 * k + 2])
def query(p, q):
if q <= p: # 半開区間なので、等しくてもアウト?
return ide_ele
p += num - 1
q += num - 2 # 半開区間なので、q側を-2している?
res = ide_ele
while q - p > 1:
if p % 2 == 0:
res = segfunc(res, seg[p])
if q % 2 == 1:
res = segfunc(res, seg[q])
q -= 1
p = p // 2
q = (q - 1) // 2
if p == q:
res = segfunc(res, seg[p])
else:
res = segfunc(segfunc(res, seg[p]), seg[q])
return res
# 単位元
ide_ele = 0
N = int(eval(input()))
ss = list(eval(input()))
s = []
for i in range(N):
s.append(1 << (ord(ss[i])) - 97)
# num: n以上の最小の2のベキ乗
num = 2 ** (N - 1).bit_length()
seg = [ide_ele] * 2 * num
init(s)
def popcnt(n):
c = (n & 0x5555555555555555) + ((n >> 1) & 0x5555555555555555)
c = (c & 0x3333333333333333) + ((c >> 2) & 0x3333333333333333)
c = (c & 0x0F0F0F0F0F0F0F0F) + ((c >> 4) & 0x0F0F0F0F0F0F0F0F)
c = (c & 0x00FF00FF00FF00FF) + ((c >> 8) & 0x00FF00FF00FF00FF)
c = (c & 0x0000FFFF0000FFFF) + ((c >> 16) & 0x0000FFFF0000FFFF)
c = (c & 0x00000000FFFFFFFF) + ((c >> 32) & 0x00000000FFFFFFFF)
return c
q = int(eval(input()))
for i in range(q):
qq, xx, yy = list(map(str, input().split()))
if qq == "1":
xx = int(xx)
update(xx - 1, 1 << (ord(yy) - 97))
else:
xx, yy = int(xx), int(yy)
res = query(xx - 1, yy)
print((popcnt(res)))
| false | 32.142857 | [
"-# Binary Indexed Treeを各アルファベットについてもつ (それぞれN+1の空間を保持し、1-indexで考える)",
"-N = int(eval(input()))",
"-S = list(eval(input()))",
"-BITS = [[0] * (N + 1) for _ in range(26)]",
"-# 初期化を行おうと思ったが、これ自体に関数が必要である",
"-# 値の加算",
"-def ctoi(alphabet):",
"- return ord(alphabet) - 97",
"+\"\"\"segfunc\"\"\"",
"... | false | 0.085537 | 0.050409 | 1.69685 | [
"s232715172",
"s648311810"
] |
u945181840 | p02955 | python | s694002362 | s795556369 | 299 | 257 | 20,520 | 12,516 | Accepted | Accepted | 14.05 | import numpy as np
# 約数の列挙
def make_divisors(n):
divisors = set()
for i in range(1, int(n ** 0.5) + 1):
if n % i == 0:
divisors.add(i)
divisors.add(n // i)
return sorted(list(divisors))
N, K, *A = list(map(int, open(0).read().split()))
A = np.array(A, np.int64)
d = make_divisors(A.sum())
for i in d[::-1]:
r = A % i
r = r[r != 0]
l = r.size
if l == 0:
print(i)
exit()
else:
n = np.arange(l - 1, 0, -1)
r.sort()
np.cumsum(r, out=r)
equal = np.where(r[:-1] == i * n - (r[-1] - r[:-1]))[0]
if np.any(r[equal] <= K):
print(i)
exit() | import numpy as np
# 約数の列挙
def make_divisors(n):
divisors = set()
for i in range(1, int(n ** 0.5) + 1):
if n % i == 0:
divisors.add(i)
divisors.add(n // i)
return sorted(list(divisors))
N, K, *A = list(map(int, open(0).read().split()))
A = np.array(A, np.int64)
d = make_divisors(A.sum())
for i in d[::-1]:
r = A % i
r = r[r != 0]
l = r.size
if l == 0:
print(i)
exit()
else:
n = np.arange(l - 1, 0, -1)
r.sort()
np.cumsum(r, out=r)
if np.any((r[:-1] == i * n - (r[-1] - r[:-1])) & (r[:-1] <= K)):
print(i)
exit()
| 33 | 32 | 681 | 660 | import numpy as np
# 約数の列挙
def make_divisors(n):
divisors = set()
for i in range(1, int(n**0.5) + 1):
if n % i == 0:
divisors.add(i)
divisors.add(n // i)
return sorted(list(divisors))
N, K, *A = list(map(int, open(0).read().split()))
A = np.array(A, np.int64)
d = make_divisors(A.sum())
for i in d[::-1]:
r = A % i
r = r[r != 0]
l = r.size
if l == 0:
print(i)
exit()
else:
n = np.arange(l - 1, 0, -1)
r.sort()
np.cumsum(r, out=r)
equal = np.where(r[:-1] == i * n - (r[-1] - r[:-1]))[0]
if np.any(r[equal] <= K):
print(i)
exit()
| import numpy as np
# 約数の列挙
def make_divisors(n):
divisors = set()
for i in range(1, int(n**0.5) + 1):
if n % i == 0:
divisors.add(i)
divisors.add(n // i)
return sorted(list(divisors))
N, K, *A = list(map(int, open(0).read().split()))
A = np.array(A, np.int64)
d = make_divisors(A.sum())
for i in d[::-1]:
r = A % i
r = r[r != 0]
l = r.size
if l == 0:
print(i)
exit()
else:
n = np.arange(l - 1, 0, -1)
r.sort()
np.cumsum(r, out=r)
if np.any((r[:-1] == i * n - (r[-1] - r[:-1])) & (r[:-1] <= K)):
print(i)
exit()
| false | 3.030303 | [
"- equal = np.where(r[:-1] == i * n - (r[-1] - r[:-1]))[0]",
"- if np.any(r[equal] <= K):",
"+ if np.any((r[:-1] == i * n - (r[-1] - r[:-1])) & (r[:-1] <= K)):"
] | false | 0.209863 | 0.180749 | 1.161074 | [
"s694002362",
"s795556369"
] |
u374531474 | p02793 | python | s355369374 | s605239953 | 1,894 | 199 | 6,100 | 51,828 | Accepted | Accepted | 89.49 | from fractions import gcd
from functools import reduce
MOD = 10 ** 9 + 7
N = int(eval(input()))
A = list(map(int, input().split()))
L = reduce(lambda x, y: x * y // gcd(x, y), A)
ans = 0
for i in range(N):
ans += L // A[i]
print((ans % MOD))
| from collections import Counter, defaultdict
MOD = 10 ** 9 + 7
N = int(eval(input()))
A = list(map(int, input().split()))
max_A = max(A)
f = list(range(max_A + 1))
for i in range(2, int(max_A ** 0.5) + 1):
if f[i] == i:
f[i::i] = [i] * (max_A // i)
def factors(x):
factor = defaultdict(int)
while x != 1:
factor[f[x]] += 1
x //= f[x]
return factor
L = defaultdict(int)
for i in range(N):
Ai = factors(A[i])
for p, index in list(Ai.items()):
L[p] = max(L[p], index)
lcm = 1
for p, index in list(L.items()):
if index == 0:
continue
lcm *= pow(p, index, MOD)
lcm %= MOD
ans = 0
for Ai in A:
ans += lcm * pow(Ai, MOD - 2, MOD)
ans %= MOD
print((ans % MOD))
| 13 | 38 | 253 | 761 | from fractions import gcd
from functools import reduce
MOD = 10**9 + 7
N = int(eval(input()))
A = list(map(int, input().split()))
L = reduce(lambda x, y: x * y // gcd(x, y), A)
ans = 0
for i in range(N):
ans += L // A[i]
print((ans % MOD))
| from collections import Counter, defaultdict
MOD = 10**9 + 7
N = int(eval(input()))
A = list(map(int, input().split()))
max_A = max(A)
f = list(range(max_A + 1))
for i in range(2, int(max_A**0.5) + 1):
if f[i] == i:
f[i::i] = [i] * (max_A // i)
def factors(x):
factor = defaultdict(int)
while x != 1:
factor[f[x]] += 1
x //= f[x]
return factor
L = defaultdict(int)
for i in range(N):
Ai = factors(A[i])
for p, index in list(Ai.items()):
L[p] = max(L[p], index)
lcm = 1
for p, index in list(L.items()):
if index == 0:
continue
lcm *= pow(p, index, MOD)
lcm %= MOD
ans = 0
for Ai in A:
ans += lcm * pow(Ai, MOD - 2, MOD)
ans %= MOD
print((ans % MOD))
| false | 65.789474 | [
"-from fractions import gcd",
"-from functools import reduce",
"+from collections import Counter, defaultdict",
"-L = reduce(lambda x, y: x * y // gcd(x, y), A)",
"+max_A = max(A)",
"+f = list(range(max_A + 1))",
"+for i in range(2, int(max_A**0.5) + 1):",
"+ if f[i] == i:",
"+ f[i::i] = [... | false | 0.124019 | 0.162285 | 0.764203 | [
"s355369374",
"s605239953"
] |
u200887663 | p02900 | python | s586510810 | s887487671 | 187 | 154 | 5,048 | 9,080 | Accepted | Accepted | 17.65 | a,b=list(map(int,input().split()))
#素因数分解した結果を2次元配列にして返す
def prime_factorize(n):
primelist=[]
a=2
while a*a<=n:
if n%a!=0:
a+=1
continue
ex=0
while n%a==0:
ex+=1
n=n//a
primelist.append([a,ex])
a+=1
if n!=1:
primelist.append([n,1])
return primelist
import fractions
g=fractions.gcd(a,b)
pfs=prime_factorize(g)
print((1+len(pfs))) | #n=int(input())
a,b=list(map(int,input().split()))
#l=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]
def prime_factorize(n):
n_origin=n+0
primelist=[]
a=2
while a*a<=n_origin:
if n%a!=0:
a+=1
continue
ex=0
while n%a==0:
ex+=1
n=n//a
primelist.append([a,ex])
a+=1
if n!=1:
primelist.append([n,1])
return primelist
import math
gcd=math.gcd(a,b)#最大公約数
primelist=prime_factorize(gcd)
print((len(primelist)+1))
| 26 | 27 | 466 | 584 | a, b = list(map(int, input().split()))
# 素因数分解した結果を2次元配列にして返す
def prime_factorize(n):
primelist = []
a = 2
while a * a <= n:
if n % a != 0:
a += 1
continue
ex = 0
while n % a == 0:
ex += 1
n = n // a
primelist.append([a, ex])
a += 1
if n != 1:
primelist.append([n, 1])
return primelist
import fractions
g = fractions.gcd(a, b)
pfs = prime_factorize(g)
print((1 + len(pfs)))
| # n=int(input())
a, b = list(map(int, input().split()))
# l=list(map(int,input().split()))
# l=[list(map(int,input().split())) for i in range(n)]
def prime_factorize(n):
n_origin = n + 0
primelist = []
a = 2
while a * a <= n_origin:
if n % a != 0:
a += 1
continue
ex = 0
while n % a == 0:
ex += 1
n = n // a
primelist.append([a, ex])
a += 1
if n != 1:
primelist.append([n, 1])
return primelist
import math
gcd = math.gcd(a, b) # 最大公約数
primelist = prime_factorize(gcd)
print((len(primelist) + 1))
| false | 3.703704 | [
"+# n=int(input())",
"-# 素因数分解した結果を2次元配列にして返す",
"+# l=list(map(int,input().split()))",
"+# l=[list(map(int,input().split())) for i in range(n)]",
"+ n_origin = n + 0",
"- while a * a <= n:",
"+ while a * a <= n_origin:",
"-import fractions",
"+import math",
"-g = fractions.gcd(a, b)",
"... | false | 0.00802 | 0.036796 | 0.217969 | [
"s586510810",
"s887487671"
] |
u157020659 | p02837 | python | s099611698 | s547554870 | 1,089 | 585 | 3,064 | 3,064 | Accepted | Accepted | 46.28 | n = int(eval(input()))
def make_remark_list(i, r):
# -1: 不明, 0: 嘘つき, 1: 真実
people = [-1] * n
people[i] = 1
for x, y in r:
people[x - 1] = y
return people
def check(x, y):
new_list = []
for a, b in zip(x, y):
a, b = min(a, b), max(a, b)
if (a, b) == (0, 1):
return False
elif (a, b) == (-1, 0):
new_list.append(0)
else:
new_list.append(max(a, b))
return new_list
remarks = []
for i in range(n):
a = int(eval(input()))
r = [tuple(map(int, input().split())) for _ in range(a)]
remarks.append(make_remark_list(i, r))
def max_count(r, cnt, i = 0):
tmp = r
for j, r_j in enumerate(remarks):
if j < i: continue
if tmp[j] == 0:
continue
elif tmp[j] == 1:
if check(tmp, r_j):
tmp = check(tmp, r_j)
cnt += 1
else:
cnt = 0
break
else:
tmp[j] = 1
if check(tmp, r_j):
cnt_1, tmp_1 = max_count(tmp, cnt, j)
tmp[j] = 0
cnt_0, tmp_0 = max_count(tmp, cnt, j)
if cnt_0 > cnt_1:
return cnt_0, tmp_0
else:
return cnt_1, tmp_1
else:
tmp[j] = 0
return cnt, tmp
r = [-1] * n
cnt, r = max_count(r, 0)
print(cnt) | def check(x, y):
for a, b in zip(x, y):
if a != b and b != -1:
return False
else:
return True
n = int(eval(input()))
remarks = []
cnt_max = 0
for _ in range(n):
a = int(eval(input()))
x = [tuple(map(int, input().split())) for i in range(a)]
r = [-1] * n
for i, j in x:
r[i - 1] = j
remarks.append(r)
for r in range(2 ** n):
r = list(bin(r)[2:].zfill(n))
r = [int(i) for i in r[:]]
cnt = 0
for i in range(n):
if r[i] == 1:
flag = check(r, remarks[i])
cnt += 1
if not flag:
cnt = 0
break
cnt_max = max(cnt, cnt_max)
print(cnt_max) | 61 | 31 | 1,479 | 708 | n = int(eval(input()))
def make_remark_list(i, r):
# -1: 不明, 0: 嘘つき, 1: 真実
people = [-1] * n
people[i] = 1
for x, y in r:
people[x - 1] = y
return people
def check(x, y):
new_list = []
for a, b in zip(x, y):
a, b = min(a, b), max(a, b)
if (a, b) == (0, 1):
return False
elif (a, b) == (-1, 0):
new_list.append(0)
else:
new_list.append(max(a, b))
return new_list
remarks = []
for i in range(n):
a = int(eval(input()))
r = [tuple(map(int, input().split())) for _ in range(a)]
remarks.append(make_remark_list(i, r))
def max_count(r, cnt, i=0):
tmp = r
for j, r_j in enumerate(remarks):
if j < i:
continue
if tmp[j] == 0:
continue
elif tmp[j] == 1:
if check(tmp, r_j):
tmp = check(tmp, r_j)
cnt += 1
else:
cnt = 0
break
else:
tmp[j] = 1
if check(tmp, r_j):
cnt_1, tmp_1 = max_count(tmp, cnt, j)
tmp[j] = 0
cnt_0, tmp_0 = max_count(tmp, cnt, j)
if cnt_0 > cnt_1:
return cnt_0, tmp_0
else:
return cnt_1, tmp_1
else:
tmp[j] = 0
return cnt, tmp
r = [-1] * n
cnt, r = max_count(r, 0)
print(cnt)
| def check(x, y):
for a, b in zip(x, y):
if a != b and b != -1:
return False
else:
return True
n = int(eval(input()))
remarks = []
cnt_max = 0
for _ in range(n):
a = int(eval(input()))
x = [tuple(map(int, input().split())) for i in range(a)]
r = [-1] * n
for i, j in x:
r[i - 1] = j
remarks.append(r)
for r in range(2**n):
r = list(bin(r)[2:].zfill(n))
r = [int(i) for i in r[:]]
cnt = 0
for i in range(n):
if r[i] == 1:
flag = check(r, remarks[i])
cnt += 1
if not flag:
cnt = 0
break
cnt_max = max(cnt, cnt_max)
print(cnt_max)
| false | 49.180328 | [
"-n = int(eval(input()))",
"+def check(x, y):",
"+ for a, b in zip(x, y):",
"+ if a != b and b != -1:",
"+ return False",
"+ else:",
"+ return True",
"-def make_remark_list(i, r):",
"- # -1: 不明, 0: 嘘つき, 1: 真実",
"- people = [-1] * n",
"- people[i] = 1",
"... | false | 0.070433 | 0.108851 | 0.647054 | [
"s099611698",
"s547554870"
] |
u347640436 | p03167 | python | s306957670 | s097297856 | 626 | 408 | 43,640 | 43,636 | Accepted | Accepted | 34.82 | # 配るDP
def main():
divisor = 10 ** 9 + 7
h, w = list(map(int, input().split()))
a = [eval(input()) for _ in range(h)]
dp = [[0] * w for _ in range(h)]
dp[0][0] = 1
for i in range(h):
ai = a[i]
dpi = dp[i]
if i + 1 < h:
ai1 = a[i + 1]
dpi1 = dp[i + 1]
for j in range(w):
if j + 1 < w and ai[j + 1] != '#':
dpi[j + 1] = (dpi[j + 1] + dpi[j]) % divisor
if i + 1 < h and ai1[j] != '#':
dpi1[j] = dpi[j]
print((dp[h - 1][w - 1]))
main()
| H, W = list(map(int, input().split()))
a = [eval(input()) for _ in range(H)]
dp = [[0] * W for _ in range(H)]
dp[0][0] = 1
for w in range(1, W):
if a[0][w] != '#':
dp[0][w] = dp[0][w - 1]
for h in range(1, H):
ah = a[h]
dph = dp[h]
dph1 = dp[h - 1]
if ah[0] != '#':
dph[0] = dph1[0]
for w in range(1, W):
if ah[w] != '#':
dph[w] = (dph[w - 1] + dph1[w]) % 1000000007
print((dp[H - 1][W - 1]))
| 20 | 20 | 515 | 431 | # 配るDP
def main():
divisor = 10**9 + 7
h, w = list(map(int, input().split()))
a = [eval(input()) for _ in range(h)]
dp = [[0] * w for _ in range(h)]
dp[0][0] = 1
for i in range(h):
ai = a[i]
dpi = dp[i]
if i + 1 < h:
ai1 = a[i + 1]
dpi1 = dp[i + 1]
for j in range(w):
if j + 1 < w and ai[j + 1] != "#":
dpi[j + 1] = (dpi[j + 1] + dpi[j]) % divisor
if i + 1 < h and ai1[j] != "#":
dpi1[j] = dpi[j]
print((dp[h - 1][w - 1]))
main()
| H, W = list(map(int, input().split()))
a = [eval(input()) for _ in range(H)]
dp = [[0] * W for _ in range(H)]
dp[0][0] = 1
for w in range(1, W):
if a[0][w] != "#":
dp[0][w] = dp[0][w - 1]
for h in range(1, H):
ah = a[h]
dph = dp[h]
dph1 = dp[h - 1]
if ah[0] != "#":
dph[0] = dph1[0]
for w in range(1, W):
if ah[w] != "#":
dph[w] = (dph[w - 1] + dph1[w]) % 1000000007
print((dp[H - 1][W - 1]))
| false | 0 | [
"-# 配るDP",
"-def main():",
"- divisor = 10**9 + 7",
"- h, w = list(map(int, input().split()))",
"- a = [eval(input()) for _ in range(h)]",
"- dp = [[0] * w for _ in range(h)]",
"- dp[0][0] = 1",
"- for i in range(h):",
"- ai = a[i]",
"- dpi = dp[i]",
"- if ... | false | 0.036194 | 0.03675 | 0.984855 | [
"s306957670",
"s097297856"
] |
u281303342 | p03200 | python | s981550723 | s940776540 | 81 | 57 | 3,500 | 3,500 | Accepted | Accepted | 29.63 | S = input()[::-1]
ans = 0
tmp = 0
bcnt = 0
N = len(S)
for i in range(N):
if S[i]=="W":
tmp += 1
else:
ans += tmp
bcnt += 1
tmp = i+1-bcnt
print(ans)
| S = eval(input())
# 逆順にする
S = S[::-1]
# 黒石より右にある白石の数だけ操作可能
ans = 0
white = 0
for i in range(len(S)):
if S[i]=="B":
ans += white
else:
white += 1
print(ans) | 14 | 15 | 203 | 190 | S = input()[::-1]
ans = 0
tmp = 0
bcnt = 0
N = len(S)
for i in range(N):
if S[i] == "W":
tmp += 1
else:
ans += tmp
bcnt += 1
tmp = i + 1 - bcnt
print(ans)
| S = eval(input())
# 逆順にする
S = S[::-1]
# 黒石より右にある白石の数だけ操作可能
ans = 0
white = 0
for i in range(len(S)):
if S[i] == "B":
ans += white
else:
white += 1
print(ans)
| false | 6.666667 | [
"-S = input()[::-1]",
"+S = eval(input())",
"+# 逆順にする",
"+S = S[::-1]",
"+# 黒石より右にある白石の数だけ操作可能",
"-tmp = 0",
"-bcnt = 0",
"-N = len(S)",
"-for i in range(N):",
"- if S[i] == \"W\":",
"- tmp += 1",
"+white = 0",
"+for i in range(len(S)):",
"+ if S[i] == \"B\":",
"+ ans... | false | 0.043854 | 0.044501 | 0.985474 | [
"s981550723",
"s940776540"
] |
u587482466 | p03078 | python | s769623001 | s389301565 | 701 | 505 | 98,496 | 105,480 | Accepted | Accepted | 27.96 | # -*- coding: utf-8 -*-
import itertools
import sys
import math
from functools import lru_cache
# 1整数
# n = int(input())
# 空白区切り2変数
from queue import Queue
from operator import mul
from functools import reduce
from queue import Queue
from operator import mul
from functools import reduce
from functools import lru_cache
input = sys.stdin.readline
# N個整数
x, y, z, k = list(map(int, input().split()))
# 1整数
# n = int(input())
# 空白区切りリスト整数
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
ll = [0] * 1000001
count = 0
for i in a:
for j in b:
ll[count] = i + j
count += 1
ll.sort(reverse=True)
ll = ll[0:3000]
c.sort(reverse=True)
lll = [0] * 3000001
count = 0
for i in ll:
for j in c:
lll[count] = i + j
count += 1
lll.sort(reverse=True)
for i in range(k):
print((lll[i]))
# 空白区切り文字列
# t, d = input().split()
| # -*- coding: utf-8 -*-
import itertools
import sys
import math
from functools import lru_cache
# 1整数
# n = int(input())
# 空白区切り2変数
from queue import Queue
from operator import mul
from functools import reduce
from queue import Queue
from operator import mul
from functools import reduce
from functools import lru_cache
input = sys.stdin.readline
# N個整数
x, y, z, kk = list(map(int, input().split()))
# 1整数
# n = int(input())
# 空白区切りリスト整数
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
ll = []
count = 0
for i in range(len(a)):
for j in range(len(b)):
if i * j > kk:
break
for k in range(len(c)):
if i * j * k > kk:
break
ll.append(a[i] + b[j] + c[k])
ll.sort(reverse=True)
for i in range(kk):
print((ll[i]))
# 空白区切り文字列
# t, d = input().split()
| 55 | 53 | 972 | 1,005 | # -*- coding: utf-8 -*-
import itertools
import sys
import math
from functools import lru_cache
# 1整数
# n = int(input())
# 空白区切り2変数
from queue import Queue
from operator import mul
from functools import reduce
from queue import Queue
from operator import mul
from functools import reduce
from functools import lru_cache
input = sys.stdin.readline
# N個整数
x, y, z, k = list(map(int, input().split()))
# 1整数
# n = int(input())
# 空白区切りリスト整数
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
ll = [0] * 1000001
count = 0
for i in a:
for j in b:
ll[count] = i + j
count += 1
ll.sort(reverse=True)
ll = ll[0:3000]
c.sort(reverse=True)
lll = [0] * 3000001
count = 0
for i in ll:
for j in c:
lll[count] = i + j
count += 1
lll.sort(reverse=True)
for i in range(k):
print((lll[i]))
# 空白区切り文字列
# t, d = input().split()
| # -*- coding: utf-8 -*-
import itertools
import sys
import math
from functools import lru_cache
# 1整数
# n = int(input())
# 空白区切り2変数
from queue import Queue
from operator import mul
from functools import reduce
from queue import Queue
from operator import mul
from functools import reduce
from functools import lru_cache
input = sys.stdin.readline
# N個整数
x, y, z, kk = list(map(int, input().split()))
# 1整数
# n = int(input())
# 空白区切りリスト整数
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
ll = []
count = 0
for i in range(len(a)):
for j in range(len(b)):
if i * j > kk:
break
for k in range(len(c)):
if i * j * k > kk:
break
ll.append(a[i] + b[j] + c[k])
ll.sort(reverse=True)
for i in range(kk):
print((ll[i]))
# 空白区切り文字列
# t, d = input().split()
| false | 3.636364 | [
"-x, y, z, k = list(map(int, input().split()))",
"+x, y, z, kk = list(map(int, input().split()))",
"-ll = [0] * 1000001",
"+a.sort(reverse=True)",
"+b.sort(reverse=True)",
"+c.sort(reverse=True)",
"+ll = []",
"-for i in a:",
"- for j in b:",
"- ll[count] = i + j",
"- count += 1"... | false | 0.239888 | 0.081262 | 2.95202 | [
"s769623001",
"s389301565"
] |
u801049006 | p03031 | python | s593632136 | s088813640 | 45 | 38 | 3,064 | 3,064 | Accepted | Accepted | 15.56 | N, M = list(map(int, input().split()))
ks = [list(map(int, input().split())) for _ in range(M)]
p = list(map(int, input().split()))
ans = 0
for i in range(1<<N):
flag = True
for j in range(M):
s = ks[j][1:]
count = 0
for v in s:
if i & (1<<(v-1)):
count += 1
if count % 2 != p[j]:
flag = False
if flag:
ans += 1
print(ans)
| n, m = list(map(int, input().split()))
s = []
for i in range(m):
s.append(list(map(int, input().split()))[1:])
p = list(map(int, input().split()))
ans = 0
for i in range(1<<n):
isOn = []
for j in range(n):
if i & (1<<j):
isOn.append(j+1)
flag = True
for j in range(m):
count = 0
for v in s[j]:
if v in isOn:
count += 1
if count % 2 != p[j]:
flag = False
if flag:
ans += 1
print(ans)
| 20 | 26 | 435 | 522 | N, M = list(map(int, input().split()))
ks = [list(map(int, input().split())) for _ in range(M)]
p = list(map(int, input().split()))
ans = 0
for i in range(1 << N):
flag = True
for j in range(M):
s = ks[j][1:]
count = 0
for v in s:
if i & (1 << (v - 1)):
count += 1
if count % 2 != p[j]:
flag = False
if flag:
ans += 1
print(ans)
| n, m = list(map(int, input().split()))
s = []
for i in range(m):
s.append(list(map(int, input().split()))[1:])
p = list(map(int, input().split()))
ans = 0
for i in range(1 << n):
isOn = []
for j in range(n):
if i & (1 << j):
isOn.append(j + 1)
flag = True
for j in range(m):
count = 0
for v in s[j]:
if v in isOn:
count += 1
if count % 2 != p[j]:
flag = False
if flag:
ans += 1
print(ans)
| false | 23.076923 | [
"-N, M = list(map(int, input().split()))",
"-ks = [list(map(int, input().split())) for _ in range(M)]",
"+n, m = list(map(int, input().split()))",
"+s = []",
"+for i in range(m):",
"+ s.append(list(map(int, input().split()))[1:])",
"-for i in range(1 << N):",
"+for i in range(1 << n):",
"+ isO... | false | 0.081743 | 0.043836 | 1.864714 | [
"s593632136",
"s088813640"
] |
u970308980 | p02727 | python | s996479886 | s607283204 | 459 | 313 | 23,360 | 23,360 | Accepted | Accepted | 31.81 | import heapq
X,Y,A,B,C = list(map(int, input().split()))
p = sorted(map(int, input().split()), reverse=True)
q = sorted(map(int, input().split()), reverse=True)
r = sorted(map(int, input().split()), reverse=True)
red = p[:X]
green = q[:Y]
nocolor = r
heapq.heapify(red)
heapq.heapify(green)
# heapq.heapify(nocolor)
for nc in nocolor:
R = heapq.heappop(red)
G = heapq.heappop(green)
heapq.heappush(red,R)
heapq.heappush(green,G)
if R > nc and G > nc:
break
elif nc > R and nc > G:
if R > G:
q = heapq.heappop(green)
heapq.heappush(green,nc)
else:
q = heapq.heappop(red)
heapq.heappush(red,nc)
elif nc > R:
q = heapq.heappop(red)
heapq.heappush(red,nc)
elif nc > G:
q = heapq.heappop(green)
heapq.heappush(green,nc)
print((sum(red)+sum(green))) | import heapq
X, Y, A, B, C = list(map(int, input().split()))
p = sorted(map(int, input().split()), reverse=True)
q = sorted(map(int, input().split()), reverse=True)
r = sorted(map(int, input().split()), reverse=True)
red = p[:X]
green = q[:Y]
nocolor = r
heapq.heapify(red)
heapq.heapify(green)
for nc in nocolor:
R = red[0]
G = green[0]
if R > nc and G > nc:
break
elif nc > R and nc > G:
if R > G:
q = heapq.heappop(green)
heapq.heappush(green, nc)
else:
q = heapq.heappop(red)
heapq.heappush(red, nc)
elif nc > R:
q = heapq.heappop(red)
heapq.heappush(red, nc)
elif nc > G:
q = heapq.heappop(green)
heapq.heappush(green, nc)
print((sum(red) + sum(green)))
| 40 | 35 | 918 | 819 | import heapq
X, Y, A, B, C = list(map(int, input().split()))
p = sorted(map(int, input().split()), reverse=True)
q = sorted(map(int, input().split()), reverse=True)
r = sorted(map(int, input().split()), reverse=True)
red = p[:X]
green = q[:Y]
nocolor = r
heapq.heapify(red)
heapq.heapify(green)
# heapq.heapify(nocolor)
for nc in nocolor:
R = heapq.heappop(red)
G = heapq.heappop(green)
heapq.heappush(red, R)
heapq.heappush(green, G)
if R > nc and G > nc:
break
elif nc > R and nc > G:
if R > G:
q = heapq.heappop(green)
heapq.heappush(green, nc)
else:
q = heapq.heappop(red)
heapq.heappush(red, nc)
elif nc > R:
q = heapq.heappop(red)
heapq.heappush(red, nc)
elif nc > G:
q = heapq.heappop(green)
heapq.heappush(green, nc)
print((sum(red) + sum(green)))
| import heapq
X, Y, A, B, C = list(map(int, input().split()))
p = sorted(map(int, input().split()), reverse=True)
q = sorted(map(int, input().split()), reverse=True)
r = sorted(map(int, input().split()), reverse=True)
red = p[:X]
green = q[:Y]
nocolor = r
heapq.heapify(red)
heapq.heapify(green)
for nc in nocolor:
R = red[0]
G = green[0]
if R > nc and G > nc:
break
elif nc > R and nc > G:
if R > G:
q = heapq.heappop(green)
heapq.heappush(green, nc)
else:
q = heapq.heappop(red)
heapq.heappush(red, nc)
elif nc > R:
q = heapq.heappop(red)
heapq.heappush(red, nc)
elif nc > G:
q = heapq.heappop(green)
heapq.heappush(green, nc)
print((sum(red) + sum(green)))
| false | 12.5 | [
"-# heapq.heapify(nocolor)",
"- R = heapq.heappop(red)",
"- G = heapq.heappop(green)",
"- heapq.heappush(red, R)",
"- heapq.heappush(green, G)",
"+ R = red[0]",
"+ G = green[0]"
] | false | 0.047354 | 0.047939 | 0.987799 | [
"s996479886",
"s607283204"
] |
u367701763 | p02586 | python | s434361397 | s118584693 | 1,653 | 556 | 148,244 | 147,084 | Accepted | Accepted | 66.36 | def max2(x,y):
return x if x > y else y
R, C, K = list(map(int, input().split()))
V = [[0]*R for _ in range(C)]
for _ in range(K):
r, c, v = list(map(int, input().split()))
V[c-1][r-1] = v
dp = [[0]*4 for _ in range(R)]
for j in range(R):
if V[0][j] != 0:
dp[j][1] = max2(dp[j - 1][1], dp[j - 1][0]) + V[0][j]
if j != 0:
dp[j][0] = max2(dp[j - 1][1], dp[j - 1][0])
for i in range(1,C):
for j in range(R):
v = V[i][j]
if v != 0:
if dp[j][2] != 0:
dp[j][3] = max2(dp[j][2] + v, dp[j][3])
if dp[j][1] != 0:
dp[j][2] = max2(dp[j][1] + v, dp[j][2])
dp[j][1] = max2(v, dp[j][1])
if j != 0:
if v != 0:
dp[j][1] = max2(max(dp[j - 1][k] for k in range(4)) + v, dp[j][1])
dp[j][0] = max2(max(dp[j - 1][k] for k in range(4)), dp[j][0])
print((max(dp[-1])))
| R, L, K = list(map(int, input().split()))
V = [[0]*R for _ in range(L)]
for _ in range(K):
r, c, v = list(map(int, input().split()))
V[c-1][r-1] = v
A, B, C, D = [[0]*(R+1) for _ in range(4)]
for i in range(L):
for j in range(R):
A[j] = max(A[j-1], B[j-1], C[j-1], D[j-1])
v = V[i][j]
if v != 0:
D[j], C[j], B[j] = max(C[j] + v, D[j]), max(B[j] + v, C[j]), max(A[j] + v, B[j])
print((max(A[-2], B[-2], C[-2], D[-2]))) | 29 | 14 | 934 | 465 | def max2(x, y):
return x if x > y else y
R, C, K = list(map(int, input().split()))
V = [[0] * R for _ in range(C)]
for _ in range(K):
r, c, v = list(map(int, input().split()))
V[c - 1][r - 1] = v
dp = [[0] * 4 for _ in range(R)]
for j in range(R):
if V[0][j] != 0:
dp[j][1] = max2(dp[j - 1][1], dp[j - 1][0]) + V[0][j]
if j != 0:
dp[j][0] = max2(dp[j - 1][1], dp[j - 1][0])
for i in range(1, C):
for j in range(R):
v = V[i][j]
if v != 0:
if dp[j][2] != 0:
dp[j][3] = max2(dp[j][2] + v, dp[j][3])
if dp[j][1] != 0:
dp[j][2] = max2(dp[j][1] + v, dp[j][2])
dp[j][1] = max2(v, dp[j][1])
if j != 0:
if v != 0:
dp[j][1] = max2(max(dp[j - 1][k] for k in range(4)) + v, dp[j][1])
dp[j][0] = max2(max(dp[j - 1][k] for k in range(4)), dp[j][0])
print((max(dp[-1])))
| R, L, K = list(map(int, input().split()))
V = [[0] * R for _ in range(L)]
for _ in range(K):
r, c, v = list(map(int, input().split()))
V[c - 1][r - 1] = v
A, B, C, D = [[0] * (R + 1) for _ in range(4)]
for i in range(L):
for j in range(R):
A[j] = max(A[j - 1], B[j - 1], C[j - 1], D[j - 1])
v = V[i][j]
if v != 0:
D[j], C[j], B[j] = (
max(C[j] + v, D[j]),
max(B[j] + v, C[j]),
max(A[j] + v, B[j]),
)
print((max(A[-2], B[-2], C[-2], D[-2])))
| false | 51.724138 | [
"-def max2(x, y):",
"- return x if x > y else y",
"-",
"-",
"-R, C, K = list(map(int, input().split()))",
"-V = [[0] * R for _ in range(C)]",
"+R, L, K = list(map(int, input().split()))",
"+V = [[0] * R for _ in range(L)]",
"-dp = [[0] * 4 for _ in range(R)]",
"-for j in range(R):",
"- if ... | false | 0.058741 | 0.035972 | 1.632954 | [
"s434361397",
"s118584693"
] |
u887207211 | p03400 | python | s276252714 | s968642205 | 20 | 18 | 3,060 | 3,060 | Accepted | Accepted | 10 | N = int(eval(input()))
D, X = list(map(int,input().split()))
A = [int(eval(input())) for _ in range(N)]
choco = X
for i in range(N):
for j in range(D):
if(j*A[i]+1 <= D):
choco += 1
print(choco) | N = int(eval(input()))
D, X = list(map(int,input().split()))
A = [int(eval(input())) for _ in range(N)]
choco = X
for a in A:
d = 0
x = 0
while d*a+1 <= D:
x += 1
d += 1
choco += x
print(choco) | 9 | 12 | 196 | 203 | N = int(eval(input()))
D, X = list(map(int, input().split()))
A = [int(eval(input())) for _ in range(N)]
choco = X
for i in range(N):
for j in range(D):
if j * A[i] + 1 <= D:
choco += 1
print(choco)
| N = int(eval(input()))
D, X = list(map(int, input().split()))
A = [int(eval(input())) for _ in range(N)]
choco = X
for a in A:
d = 0
x = 0
while d * a + 1 <= D:
x += 1
d += 1
choco += x
print(choco)
| false | 25 | [
"-for i in range(N):",
"- for j in range(D):",
"- if j * A[i] + 1 <= D:",
"- choco += 1",
"+for a in A:",
"+ d = 0",
"+ x = 0",
"+ while d * a + 1 <= D:",
"+ x += 1",
"+ d += 1",
"+ choco += x"
] | false | 0.225448 | 0.039557 | 5.699325 | [
"s276252714",
"s968642205"
] |
u546285759 | p00424 | python | s752255343 | s500435088 | 250 | 220 | 8,640 | 9,404 | Accepted | Accepted | 12 | while True:
n = int(eval(input()))
if n == 0:
break
d = {}
for _ in range(n):
a, b = input().split()
d[a] = b
m = int(eval(input()))
ans = []
for _ in range(m):
a = input().strip()
if a in list(d.keys()):
ans.append(d[a])
else:
ans.append(a)
print(("".join(ans))) | while True:
n = int(eval(input()))
if n == 0:
break
d = {}
for _ in range(n):
a, b = input().split()
d[a] = b
tmp = [input().strip() for _ in range(int(eval(input())))]
ans = [d[a] if a in list(d.keys()) else a for a in tmp]
print(("".join(ans))) | 17 | 11 | 363 | 288 | while True:
n = int(eval(input()))
if n == 0:
break
d = {}
for _ in range(n):
a, b = input().split()
d[a] = b
m = int(eval(input()))
ans = []
for _ in range(m):
a = input().strip()
if a in list(d.keys()):
ans.append(d[a])
else:
ans.append(a)
print(("".join(ans)))
| while True:
n = int(eval(input()))
if n == 0:
break
d = {}
for _ in range(n):
a, b = input().split()
d[a] = b
tmp = [input().strip() for _ in range(int(eval(input())))]
ans = [d[a] if a in list(d.keys()) else a for a in tmp]
print(("".join(ans)))
| false | 35.294118 | [
"- m = int(eval(input()))",
"- ans = []",
"- for _ in range(m):",
"- a = input().strip()",
"- if a in list(d.keys()):",
"- ans.append(d[a])",
"- else:",
"- ans.append(a)",
"+ tmp = [input().strip() for _ in range(int(eval(input())))]",
"+ a... | false | 0.034323 | 0.036179 | 0.948709 | [
"s752255343",
"s500435088"
] |
u163501259 | p02714 | python | s274408400 | s371080960 | 1,961 | 1,197 | 9,224 | 9,232 | Accepted | Accepted | 38.96 | import sys
input = sys.stdin.readline
N = int(eval(input()))
S = eval(input())
CNTR = 0
CNTG = 0
CNTB = 0
for i in range(N):
if S[i] == 'R':
CNTR += 1
if S[i] == 'G':
CNTG += 1
if S[i] == 'B':
CNTB += 1
CONB = CNTR * CNTG * CNTB
CNT = 0
for i in range(N):
for j in range(i,N):
if S[j] != S[i]:
k = j + (j-i)
if k > N-1:
continue
if S[k] != S[i] and S[k] != S[j]:
CNT += 1
print((CONB - CNT)) | import sys
input = sys.stdin.readline
def main():
N = int(eval(input()))
S = eval(input())
CNTR = 0
CNTG = 0
CNTB = 0
for i in range(N):
if S[i] == 'R':
CNTR += 1
if S[i] == 'G':
CNTG += 1
if S[i] == 'B':
CNTB += 1
CONB = CNTR * CNTG * CNTB
CNT = 0
for i in range(N):
for j in range(i,N):
if S[j] != S[i]:
k = j + (j-i)
if k > N-1:
continue
if S[k] != S[i] and S[k] != S[j]:
CNT += 1
print((CONB - CNT))
if __name__ == '__main__':
main() | 26 | 31 | 519 | 668 | import sys
input = sys.stdin.readline
N = int(eval(input()))
S = eval(input())
CNTR = 0
CNTG = 0
CNTB = 0
for i in range(N):
if S[i] == "R":
CNTR += 1
if S[i] == "G":
CNTG += 1
if S[i] == "B":
CNTB += 1
CONB = CNTR * CNTG * CNTB
CNT = 0
for i in range(N):
for j in range(i, N):
if S[j] != S[i]:
k = j + (j - i)
if k > N - 1:
continue
if S[k] != S[i] and S[k] != S[j]:
CNT += 1
print((CONB - CNT))
| import sys
input = sys.stdin.readline
def main():
N = int(eval(input()))
S = eval(input())
CNTR = 0
CNTG = 0
CNTB = 0
for i in range(N):
if S[i] == "R":
CNTR += 1
if S[i] == "G":
CNTG += 1
if S[i] == "B":
CNTB += 1
CONB = CNTR * CNTG * CNTB
CNT = 0
for i in range(N):
for j in range(i, N):
if S[j] != S[i]:
k = j + (j - i)
if k > N - 1:
continue
if S[k] != S[i] and S[k] != S[j]:
CNT += 1
print((CONB - CNT))
if __name__ == "__main__":
main()
| false | 16.129032 | [
"-N = int(eval(input()))",
"-S = eval(input())",
"-CNTR = 0",
"-CNTG = 0",
"-CNTB = 0",
"-for i in range(N):",
"- if S[i] == \"R\":",
"- CNTR += 1",
"- if S[i] == \"G\":",
"- CNTG += 1",
"- if S[i] == \"B\":",
"- CNTB += 1",
"-CONB = CNTR * CNTG * CNTB",
"-CNT... | false | 0.035699 | 0.035656 | 1.001204 | [
"s274408400",
"s371080960"
] |
u191874006 | p02555 | python | s696921807 | s318485312 | 133 | 70 | 94,444 | 67,508 | Accepted | Accepted | 47.37 | #!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
s = I()
n = s // 3
dp = [[0] * (s+1) for _ in range(n+1)]
dp[0][0] = 1
dp[0] = list(accumulate(dp[0]))
for i in range(n):
for j in range(3, s+1):
dp[i+1][j] += dp[i][j-3]
dp[i+1][j] %= mod
dp[i+1] = list(accumulate(dp[i+1]))
ans = 0
for i in range(1, n+1):
ans += dp[i][-1] - dp[i][-2]
ans %= mod
print(ans) | #!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def comb(n, k):
return fact[n] * pow(fact[n-k], mod-2, mod) * pow(fact[k], mod-2, mod) % mod
s = I()
n = s // 3
fact = [1] * (s+1)
for i in range(2, s+1):
fact[i] = i * fact[i-1]
fact[i] %= mod
ans = 0
for i in range(1, n+1):
t = 3*i
u = s - t
ans += comb(u + i - 1, i - 1)
ans %= mod
print(ans) | 35 | 37 | 915 | 903 | #!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop, heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float("inf")
def I():
return int(sys.stdin.readline())
def LI():
return list(map(int, sys.stdin.readline().split()))
s = I()
n = s // 3
dp = [[0] * (s + 1) for _ in range(n + 1)]
dp[0][0] = 1
dp[0] = list(accumulate(dp[0]))
for i in range(n):
for j in range(3, s + 1):
dp[i + 1][j] += dp[i][j - 3]
dp[i + 1][j] %= mod
dp[i + 1] = list(accumulate(dp[i + 1]))
ans = 0
for i in range(1, n + 1):
ans += dp[i][-1] - dp[i][-2]
ans %= mod
print(ans)
| #!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop, heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float("inf")
def I():
return int(sys.stdin.readline())
def LI():
return list(map(int, sys.stdin.readline().split()))
def comb(n, k):
return fact[n] * pow(fact[n - k], mod - 2, mod) * pow(fact[k], mod - 2, mod) % mod
s = I()
n = s // 3
fact = [1] * (s + 1)
for i in range(2, s + 1):
fact[i] = i * fact[i - 1]
fact[i] %= mod
ans = 0
for i in range(1, n + 1):
t = 3 * i
u = s - t
ans += comb(u + i - 1, i - 1)
ans %= mod
print(ans)
| false | 5.405405 | [
"+def comb(n, k):",
"+ return fact[n] * pow(fact[n - k], mod - 2, mod) * pow(fact[k], mod - 2, mod) % mod",
"+",
"+",
"-dp = [[0] * (s + 1) for _ in range(n + 1)]",
"-dp[0][0] = 1",
"-dp[0] = list(accumulate(dp[0]))",
"-for i in range(n):",
"- for j in range(3, s + 1):",
"- dp[i + 1][... | false | 0.349279 | 0.06461 | 5.405934 | [
"s696921807",
"s318485312"
] |
u970197315 | p03127 | python | s523622667 | s171590511 | 121 | 108 | 16,240 | 85,120 | Accepted | Accepted | 10.74 | from fractions import gcd
n=int(eval(input()))
a=list(map(int,input().split()))
ans=10**18
t=0
for i in range(1,n):
if i==1:
t=gcd(a[0],a[1])
ans=min(ans,t)
continue
t=gcd(t,a[i])
ans=min(t,ans)
print(ans)
| from math import gcd
n=int(eval(input()))
a=list(map(int,input().split()))
t=a[0]
for i in range(1,n):
t=gcd(t,a[i])
print(t)
| 14 | 7 | 232 | 128 | from fractions import gcd
n = int(eval(input()))
a = list(map(int, input().split()))
ans = 10**18
t = 0
for i in range(1, n):
if i == 1:
t = gcd(a[0], a[1])
ans = min(ans, t)
continue
t = gcd(t, a[i])
ans = min(t, ans)
print(ans)
| from math import gcd
n = int(eval(input()))
a = list(map(int, input().split()))
t = a[0]
for i in range(1, n):
t = gcd(t, a[i])
print(t)
| false | 50 | [
"-from fractions import gcd",
"+from math import gcd",
"-ans = 10**18",
"-t = 0",
"+t = a[0]",
"- if i == 1:",
"- t = gcd(a[0], a[1])",
"- ans = min(ans, t)",
"- continue",
"- ans = min(t, ans)",
"-print(ans)",
"+print(t)"
] | false | 0.055486 | 0.060754 | 0.913289 | [
"s523622667",
"s171590511"
] |
u888092736 | p03379 | python | s676295934 | s992841600 | 440 | 181 | 48,964 | 31,716 | Accepted | Accepted | 58.86 | N = int(eval(input()))
sorted_X = sorted([(v, i) for i, v in enumerate(map(int, input().split()))])
med_former = sorted_X[N // 2][0]
med_latter = sorted_X[N // 2 - 1][0]
ans = [-1] * N
for j, (v, i) in enumerate(sorted_X):
if j < N // 2:
ans[i] = med_former
else:
ans[i] = med_latter
print(("\n".join(map(str, ans))))
| N, *X = list(map(int, open(0).read().split()))
sorted_X = sorted(X)
median_l = sorted_X[N // 2 - 1]
median_r = sorted_X[N // 2]
for x in X:
if x < median_l:
print(median_r)
elif x == median_l:
print(median_r)
elif x == median_r:
print(median_l)
else:
print(median_l)
| 11 | 14 | 344 | 323 | N = int(eval(input()))
sorted_X = sorted([(v, i) for i, v in enumerate(map(int, input().split()))])
med_former = sorted_X[N // 2][0]
med_latter = sorted_X[N // 2 - 1][0]
ans = [-1] * N
for j, (v, i) in enumerate(sorted_X):
if j < N // 2:
ans[i] = med_former
else:
ans[i] = med_latter
print(("\n".join(map(str, ans))))
| N, *X = list(map(int, open(0).read().split()))
sorted_X = sorted(X)
median_l = sorted_X[N // 2 - 1]
median_r = sorted_X[N // 2]
for x in X:
if x < median_l:
print(median_r)
elif x == median_l:
print(median_r)
elif x == median_r:
print(median_l)
else:
print(median_l)
| false | 21.428571 | [
"-N = int(eval(input()))",
"-sorted_X = sorted([(v, i) for i, v in enumerate(map(int, input().split()))])",
"-med_former = sorted_X[N // 2][0]",
"-med_latter = sorted_X[N // 2 - 1][0]",
"-ans = [-1] * N",
"-for j, (v, i) in enumerate(sorted_X):",
"- if j < N // 2:",
"- ans[i] = med_former",
... | false | 0.046157 | 0.039171 | 1.178354 | [
"s676295934",
"s992841600"
] |
u652569315 | p03043 | python | s020153527 | s492524258 | 544 | 95 | 12,484 | 3,060 | Accepted | Accepted | 82.54 | def main():
import sys
input = sys.stdin.readline
import numpy as np
n,k=list(map(int,input().split()))
ans=0
for i in range(1,n+1):
ans+=1/pow(2,max(int(np.ceil(np.log2(k/i))),0))
print((ans/n))
if __name__=='__main__':
main() | def main():
import sys
input = sys.stdin.readline
import math
n,k=list(map(int,input().split()))
ans=0
for i in range(1,n+1):
ans+=1/pow(2,max(int(math.ceil(math.log2(k/i))),0))
print((ans/n))
if __name__=='__main__':
main() | 11 | 11 | 258 | 255 | def main():
import sys
input = sys.stdin.readline
import numpy as np
n, k = list(map(int, input().split()))
ans = 0
for i in range(1, n + 1):
ans += 1 / pow(2, max(int(np.ceil(np.log2(k / i))), 0))
print((ans / n))
if __name__ == "__main__":
main()
| def main():
import sys
input = sys.stdin.readline
import math
n, k = list(map(int, input().split()))
ans = 0
for i in range(1, n + 1):
ans += 1 / pow(2, max(int(math.ceil(math.log2(k / i))), 0))
print((ans / n))
if __name__ == "__main__":
main()
| false | 0 | [
"- import numpy as np",
"+ import math",
"- ans += 1 / pow(2, max(int(np.ceil(np.log2(k / i))), 0))",
"+ ans += 1 / pow(2, max(int(math.ceil(math.log2(k / i))), 0))"
] | false | 0.46094 | 0.089158 | 5.169947 | [
"s020153527",
"s492524258"
] |
u413165887 | p02726 | python | s721195007 | s381296270 | 1,974 | 359 | 3,444 | 46,300 | Accepted | Accepted | 81.81 | n, x, y = list(map(int, input().split()))
result = [0 for _i in range(n)]
for i in range(1, n):
for j in range(i+1, n+1):
le = min([j-i, abs(i-x)+1+abs(j-y), abs(i-y)+abs(j-y)])
result[le] += 1
for i in result[1:]:
print(i) | n, x, y = list(map(int, input().split()))
result = [0 for _i in range(n)]
for i in range(1, n):
for j in range(i+1, n+1):
result[min([j-i, abs(i-x)+1+abs(j-y), abs(i-y)+abs(j-y)])] += 1
for i in result[1:]:
print(i) | 9 | 8 | 250 | 233 | n, x, y = list(map(int, input().split()))
result = [0 for _i in range(n)]
for i in range(1, n):
for j in range(i + 1, n + 1):
le = min([j - i, abs(i - x) + 1 + abs(j - y), abs(i - y) + abs(j - y)])
result[le] += 1
for i in result[1:]:
print(i)
| n, x, y = list(map(int, input().split()))
result = [0 for _i in range(n)]
for i in range(1, n):
for j in range(i + 1, n + 1):
result[min([j - i, abs(i - x) + 1 + abs(j - y), abs(i - y) + abs(j - y)])] += 1
for i in result[1:]:
print(i)
| false | 11.111111 | [
"- le = min([j - i, abs(i - x) + 1 + abs(j - y), abs(i - y) + abs(j - y)])",
"- result[le] += 1",
"+ result[min([j - i, abs(i - x) + 1 + abs(j - y), abs(i - y) + abs(j - y)])] += 1"
] | false | 0.037705 | 0.158967 | 0.237187 | [
"s721195007",
"s381296270"
] |
u644907318 | p03600 | python | s822828792 | s041917646 | 813 | 369 | 45,420 | 74,696 | Accepted | Accepted | 54.61 | N = int(eval(input()))
A = [list(map(int,input().split())) for _ in range(N)]
cnt = 0
for i in range(N):
for j in range(N):
cnt += A[i][j]
flg = 0
B = [[0 for _ in range(N)] for _ in range(N)]
for k in range(N):
for i in range(N):
for j in range(N):
if A[i][j]>A[i][k]+A[k][j]:
flg = -1
break
elif A[i][j]==A[i][k]+A[k][j] and A[i][k]*A[k][j]>0 and B[i][j]==0:
cnt -= A[i][j]
B[i][j]=1
if flg==-1:break
if flg==-1:break
if flg==-1:
print((-1))
else:
print((cnt//2)) | N = int(eval(input()))
A = [[0 for _ in range(N+1)]]
for _ in range(N):
a = list(map(int,input().split()))
a.insert(0,0)
A.append(a)
tot = 0
for i in range(1,N):
for j in range(i,N+1):
tot += A[i][j]
for i in range(1,N):
for j in range(i+1,N+1):
for k in range(1,N+1):
if k!=i and k!=j:
if A[i][j]>A[i][k]+A[k][j]:
tot = -1
break
elif A[i][j]==A[i][k]+A[k][j]:
tot -= A[i][j]
break
if tot<0:break
if tot<0:break
print(tot) | 23 | 23 | 619 | 610 | N = int(eval(input()))
A = [list(map(int, input().split())) for _ in range(N)]
cnt = 0
for i in range(N):
for j in range(N):
cnt += A[i][j]
flg = 0
B = [[0 for _ in range(N)] for _ in range(N)]
for k in range(N):
for i in range(N):
for j in range(N):
if A[i][j] > A[i][k] + A[k][j]:
flg = -1
break
elif (
A[i][j] == A[i][k] + A[k][j] and A[i][k] * A[k][j] > 0 and B[i][j] == 0
):
cnt -= A[i][j]
B[i][j] = 1
if flg == -1:
break
if flg == -1:
break
if flg == -1:
print((-1))
else:
print((cnt // 2))
| N = int(eval(input()))
A = [[0 for _ in range(N + 1)]]
for _ in range(N):
a = list(map(int, input().split()))
a.insert(0, 0)
A.append(a)
tot = 0
for i in range(1, N):
for j in range(i, N + 1):
tot += A[i][j]
for i in range(1, N):
for j in range(i + 1, N + 1):
for k in range(1, N + 1):
if k != i and k != j:
if A[i][j] > A[i][k] + A[k][j]:
tot = -1
break
elif A[i][j] == A[i][k] + A[k][j]:
tot -= A[i][j]
break
if tot < 0:
break
if tot < 0:
break
print(tot)
| false | 0 | [
"-A = [list(map(int, input().split())) for _ in range(N)]",
"-cnt = 0",
"-for i in range(N):",
"- for j in range(N):",
"- cnt += A[i][j]",
"-flg = 0",
"-B = [[0 for _ in range(N)] for _ in range(N)]",
"-for k in range(N):",
"- for i in range(N):",
"- for j in range(N):",
"- ... | false | 0.079449 | 0.086668 | 0.916702 | [
"s822828792",
"s041917646"
] |
u330661451 | p03013 | python | s881266404 | s708447794 | 358 | 182 | 460,824 | 7,832 | Accepted | Accepted | 49.16 |
MOD = 1000000007
def main():
n,m = list(map(int,input().split()))
al = [False for _ in range(n+1)]
for i in range(m):
a = int(eval(input()))
al[a] = True
dp = [0 for _ in range(n+1)]
dp[0] = 1
dp[1] = 1 if al[1] == False else 0
for i in range(2,n+1):
if not al[i]:
dp[i] = dp[i-2] + dp[i-1]
print((dp[n] % MOD))
if __name__ == "__main__":
main() |
MOD = 1000000007
def main():
n,m = list(map(int,input().split()))
al = [False for _ in range(n+1)]
for i in range(m):
a = int(eval(input()))
al[a] = True
dp = [0 for _ in range(n+1)]
dp[0] = 1
dp[1] = 1 if al[1] == False else 0
for i in range(2,n+1):
if not al[i]:
dp[i] = (dp[i-2] + dp[i-1]) % MOD
print((dp[n]))
if __name__ == "__main__":
main() | 23 | 23 | 436 | 438 | MOD = 1000000007
def main():
n, m = list(map(int, input().split()))
al = [False for _ in range(n + 1)]
for i in range(m):
a = int(eval(input()))
al[a] = True
dp = [0 for _ in range(n + 1)]
dp[0] = 1
dp[1] = 1 if al[1] == False else 0
for i in range(2, n + 1):
if not al[i]:
dp[i] = dp[i - 2] + dp[i - 1]
print((dp[n] % MOD))
if __name__ == "__main__":
main()
| MOD = 1000000007
def main():
n, m = list(map(int, input().split()))
al = [False for _ in range(n + 1)]
for i in range(m):
a = int(eval(input()))
al[a] = True
dp = [0 for _ in range(n + 1)]
dp[0] = 1
dp[1] = 1 if al[1] == False else 0
for i in range(2, n + 1):
if not al[i]:
dp[i] = (dp[i - 2] + dp[i - 1]) % MOD
print((dp[n]))
if __name__ == "__main__":
main()
| false | 0 | [
"- dp[i] = dp[i - 2] + dp[i - 1]",
"- print((dp[n] % MOD))",
"+ dp[i] = (dp[i - 2] + dp[i - 1]) % MOD",
"+ print((dp[n]))"
] | false | 0.058221 | 0.035589 | 1.635927 | [
"s881266404",
"s708447794"
] |
u684120680 | p02936 | python | s222646411 | s148951005 | 1,804 | 943 | 65,272 | 92,900 | Accepted | Accepted | 47.73 | from collections import deque
n, q = [int(i) for i in input().split()]
tree = [[] for _ in range(n+1)]
for _ in range(n-1):
a, b = [int(i) for i in input().split()]
tree[a].append(b)
tree[b].append(a)
counter = [0] * (n+1)
for _ in range(q):
p, x = [int(i) for i in input().split()]
counter[p] += x
queue = deque([[0,1]])
while queue:
parent, node = queue.popleft()
for leaf in tree[node]:
if leaf == parent:
continue
counter[leaf] += counter[node]
queue.append([node, leaf])
print((*counter[1:]))
| # ABC138D - Ki
from collections import deque
def dfs() -> None:
# pop, appendまたはQueueライブラリだと間に合わない
queue = deque([[0,1]])
while queue:
parent, node = queue.popleft()
for leaf in T[node]:
if leaf == parent:
continue
counter[leaf] += counter[node]
queue.append([node, leaf])
def main():
# Ai (A[i][0]) may be not a parent of Bi (A[i][1])
global T, counter
N, Q, *A = list(map(int, open(0).read().split()))
E, P = A[: (N - 1) * 2], A[(N - 1) * 2 :]
T = [[] for _ in range(N + 1)]
for v, u in zip(*[iter(E)] * 2):
T[v].append(u), T[u].append(v)
counter = [0] * (N + 1)
for p, x in zip(*[iter(P)] * 2):
counter[p] += x # increase vertex p by x
dfs()
print((*counter[1:]))
if __name__ == "__main__":
main()
| 25 | 33 | 589 | 878 | from collections import deque
n, q = [int(i) for i in input().split()]
tree = [[] for _ in range(n + 1)]
for _ in range(n - 1):
a, b = [int(i) for i in input().split()]
tree[a].append(b)
tree[b].append(a)
counter = [0] * (n + 1)
for _ in range(q):
p, x = [int(i) for i in input().split()]
counter[p] += x
queue = deque([[0, 1]])
while queue:
parent, node = queue.popleft()
for leaf in tree[node]:
if leaf == parent:
continue
counter[leaf] += counter[node]
queue.append([node, leaf])
print((*counter[1:]))
| # ABC138D - Ki
from collections import deque
def dfs() -> None:
# pop, appendまたはQueueライブラリだと間に合わない
queue = deque([[0, 1]])
while queue:
parent, node = queue.popleft()
for leaf in T[node]:
if leaf == parent:
continue
counter[leaf] += counter[node]
queue.append([node, leaf])
def main():
# Ai (A[i][0]) may be not a parent of Bi (A[i][1])
global T, counter
N, Q, *A = list(map(int, open(0).read().split()))
E, P = A[: (N - 1) * 2], A[(N - 1) * 2 :]
T = [[] for _ in range(N + 1)]
for v, u in zip(*[iter(E)] * 2):
T[v].append(u), T[u].append(v)
counter = [0] * (N + 1)
for p, x in zip(*[iter(P)] * 2):
counter[p] += x # increase vertex p by x
dfs()
print((*counter[1:]))
if __name__ == "__main__":
main()
| false | 24.242424 | [
"+# ABC138D - Ki",
"-n, q = [int(i) for i in input().split()]",
"-tree = [[] for _ in range(n + 1)]",
"-for _ in range(n - 1):",
"- a, b = [int(i) for i in input().split()]",
"- tree[a].append(b)",
"- tree[b].append(a)",
"-counter = [0] * (n + 1)",
"-for _ in range(q):",
"- p, x = [int... | false | 0.213722 | 0.047191 | 4.52886 | [
"s222646411",
"s148951005"
] |
u357751375 | p03545 | python | s197870368 | s632881456 | 26 | 23 | 9,188 | 9,196 | Accepted | Accepted | 11.54 | s = list(eval(input()))
a = int(s[0])
b = int(s[1])
c = int(s[2])
d = int(s[3])
def p_mark(j):
if j % 2 == 0:
return '+'
else:
return '-'
for i in range(2 ** 3):
j = i
p = a
x = p_mark(j)
if x == '+':
p += b
else:
p -= b
j = j // 2
y = p_mark(j)
if y == '+':
p += c
else:
p -= c
j = j // 2
z = p_mark(j)
if z == '+':
p += d
else:
p -= d
if p == 7:
print((str(a) + x + str(b) + y + str(c) + z + str(d) + '=7'))
break | m = eval(input())
m = list(m)
m = list(map(int,m))
for i in range(2**3):
n = m[0]
x = i
t = []
for _ in range(3):
if x % 2 != 0:
n += m[_+1]
t.append('+')
else:
n -= m[_+1]
t.append('-')
x = x // 2
if n == 7:
l = [m[0],t[0],m[1],t[1],m[2],t[2],m[3],'=',7]
l = list(map(str,l))
print((''.join(l)))
break | 35 | 20 | 587 | 437 | s = list(eval(input()))
a = int(s[0])
b = int(s[1])
c = int(s[2])
d = int(s[3])
def p_mark(j):
if j % 2 == 0:
return "+"
else:
return "-"
for i in range(2**3):
j = i
p = a
x = p_mark(j)
if x == "+":
p += b
else:
p -= b
j = j // 2
y = p_mark(j)
if y == "+":
p += c
else:
p -= c
j = j // 2
z = p_mark(j)
if z == "+":
p += d
else:
p -= d
if p == 7:
print((str(a) + x + str(b) + y + str(c) + z + str(d) + "=7"))
break
| m = eval(input())
m = list(m)
m = list(map(int, m))
for i in range(2**3):
n = m[0]
x = i
t = []
for _ in range(3):
if x % 2 != 0:
n += m[_ + 1]
t.append("+")
else:
n -= m[_ + 1]
t.append("-")
x = x // 2
if n == 7:
l = [m[0], t[0], m[1], t[1], m[2], t[2], m[3], "=", 7]
l = list(map(str, l))
print(("".join(l)))
break
| false | 42.857143 | [
"-s = list(eval(input()))",
"-a = int(s[0])",
"-b = int(s[1])",
"-c = int(s[2])",
"-d = int(s[3])",
"-",
"-",
"-def p_mark(j):",
"- if j % 2 == 0:",
"- return \"+\"",
"- else:",
"- return \"-\"",
"-",
"-",
"+m = eval(input())",
"+m = list(m)",
"+m = list(map(int, ... | false | 0.037915 | 0.034518 | 1.098421 | [
"s197870368",
"s632881456"
] |
u366959492 | p03380 | python | s031030688 | s135127867 | 262 | 232 | 62,704 | 62,704 | Accepted | Accepted | 11.45 | n=int(eval(input()))
a=list(map(int,input().split()))
mx=max(a)
d=mx
ans=0
if n==2:
print((100,0))
exit()
for i in a:
if abs(i-mx/2)<d:
d=abs(i-mx/2)
ans=i
print((mx,ans))
| n=int(eval(input()))
a=list(map(int,input().split()))
mx=max(a)
d=mx/2
ans=0
for i in a:
if abs(i-mx/2)<d:
d=abs(i-mx/2)
ans=i
print((mx,ans)) | 14 | 10 | 190 | 153 | n = int(eval(input()))
a = list(map(int, input().split()))
mx = max(a)
d = mx
ans = 0
if n == 2:
print((100, 0))
exit()
for i in a:
if abs(i - mx / 2) < d:
d = abs(i - mx / 2)
ans = i
print((mx, ans))
| n = int(eval(input()))
a = list(map(int, input().split()))
mx = max(a)
d = mx / 2
ans = 0
for i in a:
if abs(i - mx / 2) < d:
d = abs(i - mx / 2)
ans = i
print((mx, ans))
| false | 28.571429 | [
"-d = mx",
"+d = mx / 2",
"-if n == 2:",
"- print((100, 0))",
"- exit()"
] | false | 0.087537 | 0.039038 | 2.242389 | [
"s031030688",
"s135127867"
] |
u644907318 | p04005 | python | s111808486 | s790865037 | 73 | 62 | 61,648 | 61,796 | Accepted | Accepted | 15.07 | A,B,C = list(map(int,input().split()))
N = A*B*C
cmin = N
cmin = min(cmin,abs(2*(A//2)*B*C-N))
cmin = min(cmin,abs(2*(B//2)*C*A-N))
cmin = min(cmin,abs(2*(C//2)*A*B-N))
print(cmin) | A,B,C = list(map(int,input().split()))
if A%2==0 or B%2==0 or C%2==0:
print((0))
else:
cmin = min(A*B,B*C,C*A)
print(cmin) | 7 | 6 | 180 | 131 | A, B, C = list(map(int, input().split()))
N = A * B * C
cmin = N
cmin = min(cmin, abs(2 * (A // 2) * B * C - N))
cmin = min(cmin, abs(2 * (B // 2) * C * A - N))
cmin = min(cmin, abs(2 * (C // 2) * A * B - N))
print(cmin)
| A, B, C = list(map(int, input().split()))
if A % 2 == 0 or B % 2 == 0 or C % 2 == 0:
print((0))
else:
cmin = min(A * B, B * C, C * A)
print(cmin)
| false | 14.285714 | [
"-N = A * B * C",
"-cmin = N",
"-cmin = min(cmin, abs(2 * (A // 2) * B * C - N))",
"-cmin = min(cmin, abs(2 * (B // 2) * C * A - N))",
"-cmin = min(cmin, abs(2 * (C // 2) * A * B - N))",
"-print(cmin)",
"+if A % 2 == 0 or B % 2 == 0 or C % 2 == 0:",
"+ print((0))",
"+else:",
"+ cmin = min(A ... | false | 0.046522 | 0.03949 | 1.178093 | [
"s111808486",
"s790865037"
] |
u197457087 | p03355 | python | s163989445 | s388935671 | 56 | 44 | 3,064 | 10,512 | Accepted | Accepted | 21.43 | s = str(eval(input()))
K = int(eval(input()))
T = []
#for i in range(1,min(K,len(s))):
# T.append(s[:i+1])
#print(T)
for i in range(len(s)): #i文字目スタート
for j in range(i+1,min(len(s)+1,i+K+1)): #j文字
temp = s[i:j]
if temp in T:
continue
if len(T) < K:
T.append(temp)
T.sort()
else:
Flag = False
for t in range(K):
if temp < T[t]:
#print(temp,T[t],T)
T.insert(t,temp)
Flag = True
break
if Flag:
T.pop()
print((T[K-1]))
| S = str(eval(input()))
K = int(eval(input()))
N = len(S)
L = set([])
for i in range(N):
temp = S[i]
L.add(temp)
for j in range(1,min(N-i,K)):
temp += S[i+j]
L.add(temp)
#print(L)
L = list(L)
L.sort()
print((L[K-1])) | 28 | 15 | 545 | 230 | s = str(eval(input()))
K = int(eval(input()))
T = []
# for i in range(1,min(K,len(s))):
# T.append(s[:i+1])
# print(T)
for i in range(len(s)): # i文字目スタート
for j in range(i + 1, min(len(s) + 1, i + K + 1)): # j文字
temp = s[i:j]
if temp in T:
continue
if len(T) < K:
T.append(temp)
T.sort()
else:
Flag = False
for t in range(K):
if temp < T[t]:
# print(temp,T[t],T)
T.insert(t, temp)
Flag = True
break
if Flag:
T.pop()
print((T[K - 1]))
| S = str(eval(input()))
K = int(eval(input()))
N = len(S)
L = set([])
for i in range(N):
temp = S[i]
L.add(temp)
for j in range(1, min(N - i, K)):
temp += S[i + j]
L.add(temp)
# print(L)
L = list(L)
L.sort()
print((L[K - 1]))
| false | 46.428571 | [
"-s = str(eval(input()))",
"+S = str(eval(input()))",
"-T = []",
"-# for i in range(1,min(K,len(s))):",
"-# T.append(s[:i+1])",
"-# print(T)",
"-for i in range(len(s)): # i文字目スタート",
"- for j in range(i + 1, min(len(s) + 1, i + K + 1)): # j文字",
"- temp = s[i:j]",
"- if temp in T... | false | 0.045421 | 0.039252 | 1.157158 | [
"s163989445",
"s388935671"
] |
u325264482 | p03069 | python | s595737000 | s272923595 | 153 | 134 | 29,176 | 29,176 | Accepted | Accepted | 12.42 | from itertools import accumulate
N = int(eval(input()))
S = eval(input())
black = [0 for _ in range(N)]
white = [0 for _ in range(N)]
for i, s in enumerate(S):
if s == '#':
black[i] = 1
else:
white[i] = 1
# 累積和
black = [0] + black
black = list(accumulate(black))
white = [0] + white[::-1]
white = list(accumulate(white))[::-1]
ans = []
for i in range(N+1):
ans.append(black[i] + white[i])
print((min(ans)))
| from itertools import accumulate
N = int(eval(input()))
S = eval(input())
black = [0]*N
white = [0]*N
for i, s in enumerate(S):
if s == '#':
black[i] = 1
else:
white[i] = 1
# 累積和
black = [0] + black
black = list(accumulate(black))
white = [0] + white[::-1]
white = list(accumulate(white))[::-1]
ans = []
for i in range(N+1):
ans.append(black[i] + white[i])
print((min(ans)))
| 26 | 26 | 453 | 421 | from itertools import accumulate
N = int(eval(input()))
S = eval(input())
black = [0 for _ in range(N)]
white = [0 for _ in range(N)]
for i, s in enumerate(S):
if s == "#":
black[i] = 1
else:
white[i] = 1
# 累積和
black = [0] + black
black = list(accumulate(black))
white = [0] + white[::-1]
white = list(accumulate(white))[::-1]
ans = []
for i in range(N + 1):
ans.append(black[i] + white[i])
print((min(ans)))
| from itertools import accumulate
N = int(eval(input()))
S = eval(input())
black = [0] * N
white = [0] * N
for i, s in enumerate(S):
if s == "#":
black[i] = 1
else:
white[i] = 1
# 累積和
black = [0] + black
black = list(accumulate(black))
white = [0] + white[::-1]
white = list(accumulate(white))[::-1]
ans = []
for i in range(N + 1):
ans.append(black[i] + white[i])
print((min(ans)))
| false | 0 | [
"-black = [0 for _ in range(N)]",
"-white = [0 for _ in range(N)]",
"+black = [0] * N",
"+white = [0] * N"
] | false | 0.073696 | 0.033991 | 2.168101 | [
"s595737000",
"s272923595"
] |
u133936772 | p02630 | python | s142773143 | s533929597 | 479 | 176 | 18,536 | 44,000 | Accepted | Accepted | 63.26 | f=lambda:list(map(int,input().split()))
f()
s,*l=[0]*100002
for i in f(): s+=i; l[i]+=1
q,=f()
for _ in range(q): b,c=f(); s+=(c-b)*l[b]; l[c]+=l[b]; l[b]=0; print(s) | n,*L=list(map(int,open(0).read().split()))
A,q,Q=L[:n],L[n],L[n+1:]
s,*l=[0]*100002
for i in A: s+=i; l[i]+=1
for b,c in zip(*[iter(Q)]*2): s+=(c-b)*l[b]; l[c]+=l[b]; l[b]=0; print(s) | 6 | 5 | 165 | 181 | f = lambda: list(map(int, input().split()))
f()
s, *l = [0] * 100002
for i in f():
s += i
l[i] += 1
(q,) = f()
for _ in range(q):
b, c = f()
s += (c - b) * l[b]
l[c] += l[b]
l[b] = 0
print(s)
| n, *L = list(map(int, open(0).read().split()))
A, q, Q = L[:n], L[n], L[n + 1 :]
s, *l = [0] * 100002
for i in A:
s += i
l[i] += 1
for b, c in zip(*[iter(Q)] * 2):
s += (c - b) * l[b]
l[c] += l[b]
l[b] = 0
print(s)
| false | 16.666667 | [
"-f = lambda: list(map(int, input().split()))",
"-f()",
"+n, *L = list(map(int, open(0).read().split()))",
"+A, q, Q = L[:n], L[n], L[n + 1 :]",
"-for i in f():",
"+for i in A:",
"-(q,) = f()",
"-for _ in range(q):",
"- b, c = f()",
"+for b, c in zip(*[iter(Q)] * 2):"
] | false | 0.085098 | 0.039158 | 2.173187 | [
"s142773143",
"s533929597"
] |
u620480037 | p02865 | python | s368138048 | s893562724 | 180 | 26 | 38,452 | 9,152 | Accepted | Accepted | 85.56 | N=int(eval(input()))
if N%2==0:
N-=1
print((N//2)) | N=int(eval(input()))
N-=1
print((N//2)) | 4 | 3 | 49 | 33 | N = int(eval(input()))
if N % 2 == 0:
N -= 1
print((N // 2))
| N = int(eval(input()))
N -= 1
print((N // 2))
| false | 25 | [
"-if N % 2 == 0:",
"- N -= 1",
"+N -= 1"
] | false | 0.09963 | 0.035873 | 2.777307 | [
"s368138048",
"s893562724"
] |
u562016607 | p03488 | python | s867951066 | s588072901 | 1,631 | 1,299 | 309,128 | 307,080 | Accepted | Accepted | 20.36 | st = input().split("T")
x, y = list(map(int, input().split()))
XL = []; YL = []; t = 0
for i in range(len(st)):
if i % 2 == 0:
XL.append(len(st[i]))
else:
YL.append(len(st[i]))
t += len(st[i])
if abs(x) + abs(y) > t:
print("No")
else:
T = max([abs(x), abs(y), t])
xx = [[False for j in range(2*T+1)] for i in range(len(XL)+1)]
yy = [[False for j in range(2*T+1)] for i in range(len(YL)+1)]
xx[0][T]=True
yy[0][T]=True
xx[1][T+XL[0]]=True
for i in range(2, len(XL)+1):
for j in range(2*T+1):
if j-XL[i-1] < 0:
xx[i][j]=xx[i-1][j+XL[i-1]]
elif j+XL[i-1] > 2*T:
xx[i][j]=xx[i-1][j-XL[i-1]]
else:
xx[i][j]=xx[i-1][j-XL[i-1]] or xx[i-1][j+XL[i-1]]
for i in range(1,len(YL)+1):
for j in range(2*T+1):
if j-YL[i-1] < 0:
yy[i][j]=yy[i-1][j+YL[i-1]]
elif j+YL[i-1] > 2*T:
yy[i][j]=yy[i-1][j-YL[i-1]]
else:
yy[i][j]=yy[i-1][j-YL[i-1]] or yy[i-1][j+YL[i-1]]
if xx[len(XL)][x+T] and yy[len(YL)][y+T]:
print("Yes")
else:
print("No")
| s=input().split("T")
x,y=list(map(int,input().split()))
A=[]
B=[]
for i,j in enumerate(s):
if i%2==0:
A.append(len(j))
else:
B.append(len(j))
T=max([sum(A),sum(B),abs(x),abs(y)])
X=len(A)
Y=len(B)
if abs(x)+abs(y)>sum(A)+sum(B):
print("No")
exit()
dpx=[[False for i in range(2*T+1)] for _ in range(X+1)]
dpy=[[False for i in range(2*T+1)] for _ in range(Y+1)]
dpx[0][T]=True
dpy[0][T]=True
for l in range(X):
for i in range(2*T+1):
if dpx[l][i]:
dpx[l+1][i+A[l]]=True
if l==0:
continue
dpx[l+1][i-A[l]]=True
for r in range(Y):
for i in range(2*T+1):
if dpy[r][i]:
dpy[r+1][i-B[r]]=True
dpy[r+1][i+B[r]]=True
if dpx[X][x+T] and dpy[Y][y+T]:
print("Yes")
else:
print("No")
| 40 | 36 | 1,231 | 841 | st = input().split("T")
x, y = list(map(int, input().split()))
XL = []
YL = []
t = 0
for i in range(len(st)):
if i % 2 == 0:
XL.append(len(st[i]))
else:
YL.append(len(st[i]))
t += len(st[i])
if abs(x) + abs(y) > t:
print("No")
else:
T = max([abs(x), abs(y), t])
xx = [[False for j in range(2 * T + 1)] for i in range(len(XL) + 1)]
yy = [[False for j in range(2 * T + 1)] for i in range(len(YL) + 1)]
xx[0][T] = True
yy[0][T] = True
xx[1][T + XL[0]] = True
for i in range(2, len(XL) + 1):
for j in range(2 * T + 1):
if j - XL[i - 1] < 0:
xx[i][j] = xx[i - 1][j + XL[i - 1]]
elif j + XL[i - 1] > 2 * T:
xx[i][j] = xx[i - 1][j - XL[i - 1]]
else:
xx[i][j] = xx[i - 1][j - XL[i - 1]] or xx[i - 1][j + XL[i - 1]]
for i in range(1, len(YL) + 1):
for j in range(2 * T + 1):
if j - YL[i - 1] < 0:
yy[i][j] = yy[i - 1][j + YL[i - 1]]
elif j + YL[i - 1] > 2 * T:
yy[i][j] = yy[i - 1][j - YL[i - 1]]
else:
yy[i][j] = yy[i - 1][j - YL[i - 1]] or yy[i - 1][j + YL[i - 1]]
if xx[len(XL)][x + T] and yy[len(YL)][y + T]:
print("Yes")
else:
print("No")
| s = input().split("T")
x, y = list(map(int, input().split()))
A = []
B = []
for i, j in enumerate(s):
if i % 2 == 0:
A.append(len(j))
else:
B.append(len(j))
T = max([sum(A), sum(B), abs(x), abs(y)])
X = len(A)
Y = len(B)
if abs(x) + abs(y) > sum(A) + sum(B):
print("No")
exit()
dpx = [[False for i in range(2 * T + 1)] for _ in range(X + 1)]
dpy = [[False for i in range(2 * T + 1)] for _ in range(Y + 1)]
dpx[0][T] = True
dpy[0][T] = True
for l in range(X):
for i in range(2 * T + 1):
if dpx[l][i]:
dpx[l + 1][i + A[l]] = True
if l == 0:
continue
dpx[l + 1][i - A[l]] = True
for r in range(Y):
for i in range(2 * T + 1):
if dpy[r][i]:
dpy[r + 1][i - B[r]] = True
dpy[r + 1][i + B[r]] = True
if dpx[X][x + T] and dpy[Y][y + T]:
print("Yes")
else:
print("No")
| false | 10 | [
"-st = input().split(\"T\")",
"+s = input().split(\"T\")",
"-XL = []",
"-YL = []",
"-t = 0",
"-for i in range(len(st)):",
"+A = []",
"+B = []",
"+for i, j in enumerate(s):",
"- XL.append(len(st[i]))",
"+ A.append(len(j))",
"- YL.append(len(st[i]))",
"- t += len(st[i])... | false | 0.041567 | 0.043212 | 0.961942 | [
"s867951066",
"s588072901"
] |
u848535504 | p02829 | python | s269631267 | s557991513 | 26 | 23 | 9,056 | 9,012 | Accepted | Accepted | 11.54 | A = int(eval(input()))
B = int(eval(input()))
if A == 1 and B == 3:
print((2))
elif A == 1 and B == 2:
print((3))
elif A == 2 and B == 1:
print((3))
elif A == 2 and B == 3:
print((1))
elif A == 3 and B == 1:
print((2))
elif A == 3 and B == 2:
print((1)) | A = int(eval(input()))
B = int(eval(input()))
print((6-A-B)) | 15 | 4 | 268 | 50 | A = int(eval(input()))
B = int(eval(input()))
if A == 1 and B == 3:
print((2))
elif A == 1 and B == 2:
print((3))
elif A == 2 and B == 1:
print((3))
elif A == 2 and B == 3:
print((1))
elif A == 3 and B == 1:
print((2))
elif A == 3 and B == 2:
print((1))
| A = int(eval(input()))
B = int(eval(input()))
print((6 - A - B))
| false | 73.333333 | [
"-if A == 1 and B == 3:",
"- print((2))",
"-elif A == 1 and B == 2:",
"- print((3))",
"-elif A == 2 and B == 1:",
"- print((3))",
"-elif A == 2 and B == 3:",
"- print((1))",
"-elif A == 3 and B == 1:",
"- print((2))",
"-elif A == 3 and B == 2:",
"- print((1))",
"+print((6 -... | false | 0.158159 | 0.191989 | 0.823796 | [
"s269631267",
"s557991513"
] |
u018679195 | p02923 | python | s482255734 | s082062642 | 106 | 77 | 14,228 | 14,224 | Accepted | Accepted | 27.36 | import sys
n = int(eval(input()))
a = []
b = input().split(" ")
for i in range(n):
a.append(int(b[i]))
if n == 1:
print((0))
sys.exit()
mx = 0
cnt = 0
for i in range(n-2, -1, -1):
if a[i] >= a[i+1]:
cnt += 1
mx = max(mx, cnt)
else:
cnt = 0
print(mx)
| n=int(eval(input()))
h=list(map(int,input().split()))
count=0
count_list=[0]
for i in range(n-1):
if h[i]>=h[i+1]:
count+=1
count_list.append(count)
else :
count=0
print((max(count_list))) | 22 | 16 | 278 | 234 | import sys
n = int(eval(input()))
a = []
b = input().split(" ")
for i in range(n):
a.append(int(b[i]))
if n == 1:
print((0))
sys.exit()
mx = 0
cnt = 0
for i in range(n - 2, -1, -1):
if a[i] >= a[i + 1]:
cnt += 1
mx = max(mx, cnt)
else:
cnt = 0
print(mx)
| n = int(eval(input()))
h = list(map(int, input().split()))
count = 0
count_list = [0]
for i in range(n - 1):
if h[i] >= h[i + 1]:
count += 1
count_list.append(count)
else:
count = 0
print((max(count_list)))
| false | 27.272727 | [
"-import sys",
"-",
"-a = []",
"-b = input().split(\" \")",
"-for i in range(n):",
"- a.append(int(b[i]))",
"-if n == 1:",
"- print((0))",
"- sys.exit()",
"-mx = 0",
"-cnt = 0",
"-for i in range(n - 2, -1, -1):",
"- if a[i] >= a[i + 1]:",
"- cnt += 1",
"- mx = m... | false | 0.035721 | 0.036518 | 0.978185 | [
"s482255734",
"s082062642"
] |
u255499778 | p03059 | python | s916366616 | s834758164 | 20 | 17 | 2,940 | 2,940 | Accepted | Accepted | 15 | a,b,t = list(map(int, input().split()))
c = t // a
print((c*b))
| a,b,t = list(map(int,input().split()))
print((t//a * b)) | 3 | 2 | 64 | 55 | a, b, t = list(map(int, input().split()))
c = t // a
print((c * b))
| a, b, t = list(map(int, input().split()))
print((t // a * b))
| false | 33.333333 | [
"-c = t // a",
"-print((c * b))",
"+print((t // a * b))"
] | false | 0.044678 | 0.041287 | 1.082117 | [
"s916366616",
"s834758164"
] |
u591295155 | p03161 | python | s110790733 | s045108826 | 1,719 | 473 | 13,980 | 56,672 | Accepted | Accepted | 72.48 | N,K = list(map(int,input().split()))
h = list(map(int,input().split()))
INF = 10**10
dp = [INF]*N
dp[0] = 0
for i,hi in enumerate(h):
if i == 0:
continue
s = i-K if i-K >= 0 else 0
dp[i] = min([dpk + abs(hi-hk) for dpk,hk in zip(dp[s:i],h[s:i])])
print((dp[-1])) | import sys
read = lambda: sys.stdin.readline().rstrip()
def main():
INF = 10 ** 20
n,k = list(map(int,input().split()))
h = tuple(map(int,read().split()))
dp = [INF]*(n+1)
dp[0] = 0
for i in range(1, n):
for j in range(1, k + 1):
if i - j < 0:
pass
else:
dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]))
print((dp[n-1]))
if __name__ == "__main__":
main() | 14 | 21 | 293 | 474 | N, K = list(map(int, input().split()))
h = list(map(int, input().split()))
INF = 10**10
dp = [INF] * N
dp[0] = 0
for i, hi in enumerate(h):
if i == 0:
continue
s = i - K if i - K >= 0 else 0
dp[i] = min([dpk + abs(hi - hk) for dpk, hk in zip(dp[s:i], h[s:i])])
print((dp[-1]))
| import sys
read = lambda: sys.stdin.readline().rstrip()
def main():
INF = 10**20
n, k = list(map(int, input().split()))
h = tuple(map(int, read().split()))
dp = [INF] * (n + 1)
dp[0] = 0
for i in range(1, n):
for j in range(1, k + 1):
if i - j < 0:
pass
else:
dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]))
print((dp[n - 1]))
if __name__ == "__main__":
main()
| false | 33.333333 | [
"-N, K = list(map(int, input().split()))",
"-h = list(map(int, input().split()))",
"-INF = 10**10",
"-dp = [INF] * N",
"-dp[0] = 0",
"-for i, hi in enumerate(h):",
"- if i == 0:",
"- continue",
"- s = i - K if i - K >= 0 else 0",
"- dp[i] = min([dpk + abs(hi - hk) for dpk, hk in zi... | false | 0.043643 | 0.037867 | 1.152549 | [
"s110790733",
"s045108826"
] |
u561083515 | p02936 | python | s008346341 | s081333512 | 1,967 | 1,677 | 62,156 | 61,976 | Accepted | Accepted | 14.74 | N,Q = map(int,input().split())
# 親の番号 < 子の番号
edge = [[] for _ in range(N)]
for _ in range(N-1):
a,b = map(int,input().split())
edge[a-1].append(b-1)
edge[b-1].append(a-1)
vertices = [0] * N
for _ in range(Q):
p,x = map(int,input().split())
vertices[p-1] += x
from collections import deque
que = deque([(-1,0)])
while que:
pre,now = que.popleft()
cost = vertices[now]
for e in edge[now]:
if e == pre:
continue
vertices[e] += cost
que.append((now,e))
print(*vertices, sep=" ")
| from collections import deque
N,Q = list(map(int, input().split()))
edge = [[] for _ in range(N)]
for _ in range(N - 1):
a,b = list(map(int, input().split()))
edge[a-1].append(b-1)
edge[b-1].append(a-1)
cnt = [0] * N
for _ in range(Q):
p,x = list(map(int, input().split()))
cnt[p - 1] += x
ans = [-1] * N
que = deque([0])
ans[0] = cnt[0]
while que:
v = que.popleft()
for w in edge[v]:
if ans[w] < 0:
ans[w] = ans[v] + cnt[w]
que.append(w)
print((*ans)) | 25 | 25 | 569 | 520 | N, Q = map(int, input().split())
# 親の番号 < 子の番号
edge = [[] for _ in range(N)]
for _ in range(N - 1):
a, b = map(int, input().split())
edge[a - 1].append(b - 1)
edge[b - 1].append(a - 1)
vertices = [0] * N
for _ in range(Q):
p, x = map(int, input().split())
vertices[p - 1] += x
from collections import deque
que = deque([(-1, 0)])
while que:
pre, now = que.popleft()
cost = vertices[now]
for e in edge[now]:
if e == pre:
continue
vertices[e] += cost
que.append((now, e))
print(*vertices, sep=" ")
| from collections import deque
N, Q = list(map(int, input().split()))
edge = [[] for _ in range(N)]
for _ in range(N - 1):
a, b = list(map(int, input().split()))
edge[a - 1].append(b - 1)
edge[b - 1].append(a - 1)
cnt = [0] * N
for _ in range(Q):
p, x = list(map(int, input().split()))
cnt[p - 1] += x
ans = [-1] * N
que = deque([0])
ans[0] = cnt[0]
while que:
v = que.popleft()
for w in edge[v]:
if ans[w] < 0:
ans[w] = ans[v] + cnt[w]
que.append(w)
print((*ans))
| false | 0 | [
"-N, Q = map(int, input().split())",
"-# 親の番号 < 子の番号",
"+from collections import deque",
"+",
"+N, Q = list(map(int, input().split()))",
"- a, b = map(int, input().split())",
"+ a, b = list(map(int, input().split()))",
"-vertices = [0] * N",
"+cnt = [0] * N",
"- p, x = map(int, input().sp... | false | 0.042177 | 0.043288 | 0.974323 | [
"s008346341",
"s081333512"
] |
u231095456 | p03078 | python | s636864120 | s030467572 | 1,069 | 44 | 230,824 | 10,332 | Accepted | Accepted | 95.88 | import heapq as hq
x,y,z,k = list(map(int,input().split()))
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
ab = []
for a in A:
for b in B:
hq.heappush(ab, -a-b)
abc = []
cnt = 0
while cnt < k and ab:
cnt += 1
a = hq.heappop(ab)
for b in C:
hq.heappush(abc, a-b)
cnt = 0
while cnt < k:
print((-hq.heappop(abc)))
cnt += 1 | import heapq as hq
x,y,z,K = list(map(int,input().split()))
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
abc = [(-(A[0]+B[0]+C[0]), 0,0,0)]
used = set((0,0,0))
while K > 0:
K -= 1
p,i,j,k = hq.heappop(abc)
print((-p))
for a,b,c in [(i+1,j,k), (i,j+1,k), (i,j,k+1)]:
if a < x and b < y and c < z and (a,b,c) not in used:
used.add((a,b,c))
hq.heappush(abc, (-(A[a]+B[b]+C[c]), a,b,c))
| 20 | 18 | 428 | 563 | import heapq as hq
x, y, z, k = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
ab = []
for a in A:
for b in B:
hq.heappush(ab, -a - b)
abc = []
cnt = 0
while cnt < k and ab:
cnt += 1
a = hq.heappop(ab)
for b in C:
hq.heappush(abc, a - b)
cnt = 0
while cnt < k:
print((-hq.heappop(abc)))
cnt += 1
| import heapq as hq
x, y, z, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
abc = [(-(A[0] + B[0] + C[0]), 0, 0, 0)]
used = set((0, 0, 0))
while K > 0:
K -= 1
p, i, j, k = hq.heappop(abc)
print((-p))
for a, b, c in [(i + 1, j, k), (i, j + 1, k), (i, j, k + 1)]:
if a < x and b < y and c < z and (a, b, c) not in used:
used.add((a, b, c))
hq.heappush(abc, (-(A[a] + B[b] + C[c]), a, b, c))
| false | 10 | [
"-x, y, z, k = list(map(int, input().split()))",
"+x, y, z, K = list(map(int, input().split()))",
"-ab = []",
"-for a in A:",
"- for b in B:",
"- hq.heappush(ab, -a - b)",
"-abc = []",
"-cnt = 0",
"-while cnt < k and ab:",
"- cnt += 1",
"- a = hq.heappop(ab)",
"- for b in C:... | false | 0.066644 | 0.037428 | 1.78059 | [
"s636864120",
"s030467572"
] |
u285681431 | p02586 | python | s327767971 | s618141633 | 2,118 | 1,713 | 474,296 | 473,140 | Accepted | Accepted | 19.12 | R, C, K = list(map(int, input().split()))
item = [[0 for _ in range(C + 1)] for _ in range(R + 1)]
for _ in range(K):
r, c, v = list(map(int, input().split()))
item[r][c] = v
# 多次元配列を生成する際、使いたい引数を逆順で書くと上手くいく
# dp = [[[0 for _ in range(4)] for _ in range(C + 1)] for _ in range(R + 1)]
# とするとTLEだった。(R+1)*4(C+1)だと通るみたいだが、あまり本質的ではない気がする。
# 以下ではdp0,dp1,dp2,dp3という4つの配列を作ることにする。
dp0 = [[0 for _ in range(C + 1)]for _ in range(R + 1)]
dp1 = [[0 for _ in range(C + 1)]for _ in range(R + 1)]
dp2 = [[0 for _ in range(C + 1)]for _ in range(R + 1)]
dp3 = [[0 for _ in range(C + 1)]for _ in range(R + 1)]
for i in range(R + 1):
for j in range(C + 1):
# 下に移動する場合、アイテムの個数はリセットされる
if i <= R - 1:
# 移動先のアイテムを取らない場合
dp0[i + 1][j] = max(dp0[i + 1][j],
dp0[i][j],
dp1[i][j],
dp2[i][j],
dp3[i][j])
# 移動先のアイテムを取る場合
dp1[i + 1][j] = max(dp1[i + 1][j],
dp0[i][j] + item[i + 1][j],
dp1[i][j] + item[i + 1][j],
dp2[i][j] + item[i + 1][j],
dp3[i][j] + item[i + 1][j])
# 右に移動する場合、アイテムの個数は維持される
if j <= C - 1:
dp0[i][j + 1] = max(dp0[i][j + 1],
dp0[i][j])
dp1[i][j + 1] = max(dp1[i][j + 1],
dp1[i][j])
dp2[i][j + 1] = max(dp2[i][j + 1],
dp2[i][j])
dp3[i][j + 1] = max(dp3[i][j + 1],
dp3[i][j])
# 現在のアイテム数が3未満(0 or 1 or 2)の場合、移動先のアイテムをとることが可能 [k + 1], now + item[i][j + 1])
dp1[i][j + 1] = max(dp1[i][j + 1],
dp0[i][j] + item[i][j + 1])
dp2[i][j + 1] = max(dp2[i][j + 1],
dp1[i][j] + item[i][j + 1])
dp3[i][j + 1] = max(dp3[i][j + 1],
dp2[i][j] + item[i][j + 1])
# 最終的にR行で取るアイテムの個数についてそれぞれ調べる、3個が最適とは限らない
ans = max(dp0[-1][-1], dp1[-1][-1], dp2[-1][-1], dp3[-1][-1])
print(ans)
| R, C, K = list(map(int, input().split()))
item = [[0 for _ in range(C + 1)] for _ in range(R + 1)]
for _ in range(K):
r, c, v = list(map(int, input().split()))
item[r][c] = v
# 多次元配列を生成する際、使いたい引数を逆順で書くと上手くいく
# dp = [[[0 for _ in range(4)] for _ in range(C + 1)] for _ in range(R + 1)]
# とするとTLEだった。(R+1)*4(C+1)だと通るみたいだが、あまり本質的ではない気がする。
# 以下ではdp0,dp1,dp2,dp3という4つの配列を作ることにする。
dp0 = [[0 for _ in range(C + 1)]for _ in range(R + 1)]
dp1 = [[0 for _ in range(C + 1)]for _ in range(R + 1)]
dp2 = [[0 for _ in range(C + 1)]for _ in range(R + 1)]
dp3 = [[0 for _ in range(C + 1)]for _ in range(R + 1)]
for i in range(R + 1):
for j in range(C + 1):
# 何度も使うので変数に格納しておく
# 以下を省略し、毎回配列を見に行く書き方をしたら少し遅くなった(400ms程度)
now0 = dp0[i][j]
now1 = dp1[i][j]
now2 = dp2[i][j]
now3 = dp3[i][j]
# 下に移動する場合、アイテムの個数はリセットされる
if i <= R - 1:
# 移動先のアイテムを取らない場合
dp0[i + 1][j] = max(dp0[i + 1][j],
now0,
now1,
now2,
now3)
# 移動先のアイテムを取る場合
dp1[i + 1][j] = max(dp1[i + 1][j],
now0 + item[i + 1][j],
now1 + item[i + 1][j],
now2 + item[i + 1][j],
now3 + item[i + 1][j])
# 右に移動する場合、アイテムの個数は維持される
if j <= C - 1:
# 移動先のアイテムを取らない場合
dp0[i][j + 1] = max(dp0[i][j + 1],
now0)
dp1[i][j + 1] = max(dp1[i][j + 1],
now1)
dp2[i][j + 1] = max(dp2[i][j + 1],
now2)
dp3[i][j + 1] = max(dp3[i][j + 1],
now3)
# 移動先のアイテムを取る場合
dp1[i][j + 1] = max(dp1[i][j + 1],
now0 + item[i][j + 1])
dp2[i][j + 1] = max(dp2[i][j + 1],
now1 + item[i][j + 1])
dp3[i][j + 1] = max(dp3[i][j + 1],
now2 + item[i][j + 1])
# 最終的にR行で取るアイテムの個数についてそれぞれ調べる、3個が最適とは限らない
ans = max(dp0[-1][-1],
dp1[-1][-1],
dp2[-1][-1],
dp3[-1][-1])
print(ans)
| 57 | 69 | 2,298 | 2,383 | R, C, K = list(map(int, input().split()))
item = [[0 for _ in range(C + 1)] for _ in range(R + 1)]
for _ in range(K):
r, c, v = list(map(int, input().split()))
item[r][c] = v
# 多次元配列を生成する際、使いたい引数を逆順で書くと上手くいく
# dp = [[[0 for _ in range(4)] for _ in range(C + 1)] for _ in range(R + 1)]
# とするとTLEだった。(R+1)*4(C+1)だと通るみたいだが、あまり本質的ではない気がする。
# 以下ではdp0,dp1,dp2,dp3という4つの配列を作ることにする。
dp0 = [[0 for _ in range(C + 1)] for _ in range(R + 1)]
dp1 = [[0 for _ in range(C + 1)] for _ in range(R + 1)]
dp2 = [[0 for _ in range(C + 1)] for _ in range(R + 1)]
dp3 = [[0 for _ in range(C + 1)] for _ in range(R + 1)]
for i in range(R + 1):
for j in range(C + 1):
# 下に移動する場合、アイテムの個数はリセットされる
if i <= R - 1:
# 移動先のアイテムを取らない場合
dp0[i + 1][j] = max(
dp0[i + 1][j], dp0[i][j], dp1[i][j], dp2[i][j], dp3[i][j]
)
# 移動先のアイテムを取る場合
dp1[i + 1][j] = max(
dp1[i + 1][j],
dp0[i][j] + item[i + 1][j],
dp1[i][j] + item[i + 1][j],
dp2[i][j] + item[i + 1][j],
dp3[i][j] + item[i + 1][j],
)
# 右に移動する場合、アイテムの個数は維持される
if j <= C - 1:
dp0[i][j + 1] = max(dp0[i][j + 1], dp0[i][j])
dp1[i][j + 1] = max(dp1[i][j + 1], dp1[i][j])
dp2[i][j + 1] = max(dp2[i][j + 1], dp2[i][j])
dp3[i][j + 1] = max(dp3[i][j + 1], dp3[i][j])
# 現在のアイテム数が3未満(0 or 1 or 2)の場合、移動先のアイテムをとることが可能 [k + 1], now + item[i][j + 1])
dp1[i][j + 1] = max(dp1[i][j + 1], dp0[i][j] + item[i][j + 1])
dp2[i][j + 1] = max(dp2[i][j + 1], dp1[i][j] + item[i][j + 1])
dp3[i][j + 1] = max(dp3[i][j + 1], dp2[i][j] + item[i][j + 1])
# 最終的にR行で取るアイテムの個数についてそれぞれ調べる、3個が最適とは限らない
ans = max(dp0[-1][-1], dp1[-1][-1], dp2[-1][-1], dp3[-1][-1])
print(ans)
| R, C, K = list(map(int, input().split()))
item = [[0 for _ in range(C + 1)] for _ in range(R + 1)]
for _ in range(K):
r, c, v = list(map(int, input().split()))
item[r][c] = v
# 多次元配列を生成する際、使いたい引数を逆順で書くと上手くいく
# dp = [[[0 for _ in range(4)] for _ in range(C + 1)] for _ in range(R + 1)]
# とするとTLEだった。(R+1)*4(C+1)だと通るみたいだが、あまり本質的ではない気がする。
# 以下ではdp0,dp1,dp2,dp3という4つの配列を作ることにする。
dp0 = [[0 for _ in range(C + 1)] for _ in range(R + 1)]
dp1 = [[0 for _ in range(C + 1)] for _ in range(R + 1)]
dp2 = [[0 for _ in range(C + 1)] for _ in range(R + 1)]
dp3 = [[0 for _ in range(C + 1)] for _ in range(R + 1)]
for i in range(R + 1):
for j in range(C + 1):
# 何度も使うので変数に格納しておく
# 以下を省略し、毎回配列を見に行く書き方をしたら少し遅くなった(400ms程度)
now0 = dp0[i][j]
now1 = dp1[i][j]
now2 = dp2[i][j]
now3 = dp3[i][j]
# 下に移動する場合、アイテムの個数はリセットされる
if i <= R - 1:
# 移動先のアイテムを取らない場合
dp0[i + 1][j] = max(dp0[i + 1][j], now0, now1, now2, now3)
# 移動先のアイテムを取る場合
dp1[i + 1][j] = max(
dp1[i + 1][j],
now0 + item[i + 1][j],
now1 + item[i + 1][j],
now2 + item[i + 1][j],
now3 + item[i + 1][j],
)
# 右に移動する場合、アイテムの個数は維持される
if j <= C - 1:
# 移動先のアイテムを取らない場合
dp0[i][j + 1] = max(dp0[i][j + 1], now0)
dp1[i][j + 1] = max(dp1[i][j + 1], now1)
dp2[i][j + 1] = max(dp2[i][j + 1], now2)
dp3[i][j + 1] = max(dp3[i][j + 1], now3)
# 移動先のアイテムを取る場合
dp1[i][j + 1] = max(dp1[i][j + 1], now0 + item[i][j + 1])
dp2[i][j + 1] = max(dp2[i][j + 1], now1 + item[i][j + 1])
dp3[i][j + 1] = max(dp3[i][j + 1], now2 + item[i][j + 1])
# 最終的にR行で取るアイテムの個数についてそれぞれ調べる、3個が最適とは限らない
ans = max(dp0[-1][-1], dp1[-1][-1], dp2[-1][-1], dp3[-1][-1])
print(ans)
| false | 17.391304 | [
"+ # 何度も使うので変数に格納しておく",
"+ # 以下を省略し、毎回配列を見に行く書き方をしたら少し遅くなった(400ms程度)",
"+ now0 = dp0[i][j]",
"+ now1 = dp1[i][j]",
"+ now2 = dp2[i][j]",
"+ now3 = dp3[i][j]",
"- dp0[i + 1][j] = max(",
"- dp0[i + 1][j], dp0[i][j], dp1[i][j], dp2[i][j]... | false | 0.032266 | 0.043104 | 0.748578 | [
"s327767971",
"s618141633"
] |
u415905784 | p03326 | python | s043975336 | s573029091 | 72 | 25 | 3,940 | 3,292 | Accepted | Accepted | 65.28 | import functools
[N, M] = [int(x) for x in input().split()]
XYZ = []
for i in range(N):
XYZ.append([int(x) for x in input().split()])
result = 0
for x in range(-1, 2, 2):
for y in range(-1, 2, 2):
for z in range(-1, 2, 2):
contribute = [x, y, z]
score = [functools.reduce(lambda a, b: a + b, [xyz[i] * contribute[i] for i in range(3)]) for xyz in XYZ]
score.sort(reverse=True)
S = functools.reduce(lambda a, b: a + b, score[:M]) if M else 0
result = max(result, S)
print(result) | N, M = list(map(int, input().split()))
Cakes = [[] for i in range(N)]
for i in range(N):
Cakes[i] = [int(x) for x in input().split()]
ans = 0
for s in range(8):
sx = 1 if s % 2 else -1
sy = 1 if s // 2 % 2 else -1
sz = 1 if s // 4 % 2 else -1
ans = max(sum(sorted([sx * x + sy * y + sz * z for x, y, z in Cakes], reverse=True)[:M]), ans)
print(ans) | 15 | 11 | 530 | 362 | import functools
[N, M] = [int(x) for x in input().split()]
XYZ = []
for i in range(N):
XYZ.append([int(x) for x in input().split()])
result = 0
for x in range(-1, 2, 2):
for y in range(-1, 2, 2):
for z in range(-1, 2, 2):
contribute = [x, y, z]
score = [
functools.reduce(
lambda a, b: a + b, [xyz[i] * contribute[i] for i in range(3)]
)
for xyz in XYZ
]
score.sort(reverse=True)
S = functools.reduce(lambda a, b: a + b, score[:M]) if M else 0
result = max(result, S)
print(result)
| N, M = list(map(int, input().split()))
Cakes = [[] for i in range(N)]
for i in range(N):
Cakes[i] = [int(x) for x in input().split()]
ans = 0
for s in range(8):
sx = 1 if s % 2 else -1
sy = 1 if s // 2 % 2 else -1
sz = 1 if s // 4 % 2 else -1
ans = max(
sum(sorted([sx * x + sy * y + sz * z for x, y, z in Cakes], reverse=True)[:M]),
ans,
)
print(ans)
| false | 26.666667 | [
"-import functools",
"-",
"-[N, M] = [int(x) for x in input().split()]",
"-XYZ = []",
"+N, M = list(map(int, input().split()))",
"+Cakes = [[] for i in range(N)]",
"- XYZ.append([int(x) for x in input().split()])",
"-result = 0",
"-for x in range(-1, 2, 2):",
"- for y in range(-1, 2, 2):",
... | false | 0.077183 | 0.104817 | 0.736362 | [
"s043975336",
"s573029091"
] |
u896741788 | p02684 | python | s170975072 | s359484745 | 1,692 | 1,558 | 32,176 | 32,256 | Accepted | Accepted | 7.92 | def f():
n,k=list(map(int,input().split()))
l=list(map(int,input().split()))
now=1
for i in range(k.bit_length()):
if k%2:now=l[now-1]
l=tuple(l[l[i]-1]for i in range(n))
k//=2
print(now)
if __name__ == "__main__":
f() | def f():
n,k=list(map(int,input().split()))
l=list(map(int,input().split()))
now=1
for d in range(k.bit_length()):
if k%2:now=l[now-1]
l=tuple(l[i-1]for i in l)
k//=2
print(now)
if __name__ == "__main__":
f()
| 12 | 11 | 272 | 261 | def f():
n, k = list(map(int, input().split()))
l = list(map(int, input().split()))
now = 1
for i in range(k.bit_length()):
if k % 2:
now = l[now - 1]
l = tuple(l[l[i] - 1] for i in range(n))
k //= 2
print(now)
if __name__ == "__main__":
f()
| def f():
n, k = list(map(int, input().split()))
l = list(map(int, input().split()))
now = 1
for d in range(k.bit_length()):
if k % 2:
now = l[now - 1]
l = tuple(l[i - 1] for i in l)
k //= 2
print(now)
if __name__ == "__main__":
f()
| false | 8.333333 | [
"- for i in range(k.bit_length()):",
"+ for d in range(k.bit_length()):",
"- l = tuple(l[l[i] - 1] for i in range(n))",
"+ l = tuple(l[i - 1] for i in l)"
] | false | 0.041173 | 0.03922 | 1.049817 | [
"s170975072",
"s359484745"
] |
u450904670 | p03854 | python | s071936880 | s743478612 | 68 | 22 | 3,188 | 3,444 | Accepted | Accepted | 67.65 | def main():
S = eval(input())
while len(S) >= 5:
if len(S) >= 7 and S[-7:] == "dreamer":
S = S[:-7]
continue
if len(S) >= 6 and S[-6:] == "eraser":
S = S[:-6]
continue
if S[-5:] == "dream" or S[-5:] == "erase":
S = S[:-5]
continue
break
if len(S) == 0:
print("YES")
else:
print("NO")
main() | import re
s = eval(input())
expression = ")eraser|dreamer|erase|dream("[::-1]
pattern = re.compile(expression)
ans = re.sub(pattern,"", s[::-1])
if ans == "":
print("YES")
else:
print("NO") | 24 | 9 | 449 | 196 | def main():
S = eval(input())
while len(S) >= 5:
if len(S) >= 7 and S[-7:] == "dreamer":
S = S[:-7]
continue
if len(S) >= 6 and S[-6:] == "eraser":
S = S[:-6]
continue
if S[-5:] == "dream" or S[-5:] == "erase":
S = S[:-5]
continue
break
if len(S) == 0:
print("YES")
else:
print("NO")
main()
| import re
s = eval(input())
expression = ")eraser|dreamer|erase|dream("[::-1]
pattern = re.compile(expression)
ans = re.sub(pattern, "", s[::-1])
if ans == "":
print("YES")
else:
print("NO")
| false | 62.5 | [
"-def main():",
"- S = eval(input())",
"- while len(S) >= 5:",
"- if len(S) >= 7 and S[-7:] == \"dreamer\":",
"- S = S[:-7]",
"- continue",
"- if len(S) >= 6 and S[-6:] == \"eraser\":",
"- S = S[:-6]",
"- continue",
"- if S[-5:... | false | 0.037498 | 0.043075 | 0.870525 | [
"s071936880",
"s743478612"
] |
u563595438 | p02787 | python | s547858048 | s729476944 | 733 | 617 | 134,280 | 125,504 | Accepted | Accepted | 15.83 | #n=int(input())
h,n=list(map(int,input().split()))
#a=list(map(int,input().split()))
l=[list(map(int,input().split())) for i in range(n)]
#l=[list(input().split()) for i in range(n)]
amax=0
for i in range(n):
if amax<l[i][0]:
amax=l[i][0]
ldp=[[0 for j in range(h+amax)]for i in range(n)]
for i in range(n):
for j in range(h+amax):
if i==0:
ldp[i][j]=-(-(j+1)//l[i][0])*l[i][1]
else:
if j>=l[i][0]:
ldp[i][j]=min(ldp[i-1][j],ldp[i][j-l[i][0]]+l[i][1])
else:
ldp[i][j]=min(ldp[i-1][j],l[i][1])
print((min(ldp[-1][h-1:]))) | #n=int(input())
h,n=list(map(int,input().split()))
#a=list(map(int,input().split()))
l=[list(map(int,input().split())) for i in range(n)]
#l=[list(input().split()) for i in range(n)]
ldp=[[0 for j in range(h)]for i in range(n)]
for i in range(n):
for j in range(h):
if i==0:
ldp[i][j]=-(-(j+1)//l[i][0])*l[i][1]
else:
if j>=l[i][0]:
ldp[i][j]=min(ldp[i-1][j],ldp[i][j-l[i][0]]+l[i][1])
else:
ldp[i][j]=min(ldp[i-1][j],l[i][1])
print((ldp[-1][-1]))
| 22 | 19 | 643 | 557 | # n=int(input())
h, n = list(map(int, input().split()))
# a=list(map(int,input().split()))
l = [list(map(int, input().split())) for i in range(n)]
# l=[list(input().split()) for i in range(n)]
amax = 0
for i in range(n):
if amax < l[i][0]:
amax = l[i][0]
ldp = [[0 for j in range(h + amax)] for i in range(n)]
for i in range(n):
for j in range(h + amax):
if i == 0:
ldp[i][j] = -(-(j + 1) // l[i][0]) * l[i][1]
else:
if j >= l[i][0]:
ldp[i][j] = min(ldp[i - 1][j], ldp[i][j - l[i][0]] + l[i][1])
else:
ldp[i][j] = min(ldp[i - 1][j], l[i][1])
print((min(ldp[-1][h - 1 :])))
| # n=int(input())
h, n = list(map(int, input().split()))
# a=list(map(int,input().split()))
l = [list(map(int, input().split())) for i in range(n)]
# l=[list(input().split()) for i in range(n)]
ldp = [[0 for j in range(h)] for i in range(n)]
for i in range(n):
for j in range(h):
if i == 0:
ldp[i][j] = -(-(j + 1) // l[i][0]) * l[i][1]
else:
if j >= l[i][0]:
ldp[i][j] = min(ldp[i - 1][j], ldp[i][j - l[i][0]] + l[i][1])
else:
ldp[i][j] = min(ldp[i - 1][j], l[i][1])
print((ldp[-1][-1]))
| false | 13.636364 | [
"-amax = 0",
"+ldp = [[0 for j in range(h)] for i in range(n)]",
"- if amax < l[i][0]:",
"- amax = l[i][0]",
"-ldp = [[0 for j in range(h + amax)] for i in range(n)]",
"-for i in range(n):",
"- for j in range(h + amax):",
"+ for j in range(h):",
"-print((min(ldp[-1][h - 1 :])))",
"... | false | 0.105439 | 0.491347 | 0.214592 | [
"s547858048",
"s729476944"
] |
u912237403 | p00012 | python | s482319853 | s588862989 | 20 | 10 | 4,244 | 4,244 | Accepted | Accepted | 50 | import sys
def side(p1, p2, p3): return (p3[1]-p1[1])*(p2[0]-p1[0])-(p2[1]-p1[1])*(p3[0]-p1[0])>0
for s in sys.stdin:
x = list(map(float, s.split()))
p1 = x[0:2]
p2 = x[2:4]
p3 = x[4:6]
p0 = x[6:]
print(["NO","YES"][(side(p1, p2, p0)==side(p2, p3, p0) and side(p2, p3, p0)==side(p3, p1, p0))]) | import sys
def side(p1, p2, p3): return (p3[1]-p1[1])*(p2[0]-p1[0])-(p2[1]-p1[1])*(p3[0]-p1[0])>0
for s in sys.stdin:
x = list(map(float, s.split()))
p1 = x[0:2]
p2 = x[2:4]
p3 = x[4:6]
p0 = x[6:]
print(["NO","YES"][(side(p1, p2, p0)==side(p2, p3, p0)==side(p3, p1, p0))]) | 10 | 10 | 309 | 288 | import sys
def side(p1, p2, p3):
return (p3[1] - p1[1]) * (p2[0] - p1[0]) - (p2[1] - p1[1]) * (p3[0] - p1[0]) > 0
for s in sys.stdin:
x = list(map(float, s.split()))
p1 = x[0:2]
p2 = x[2:4]
p3 = x[4:6]
p0 = x[6:]
print(
["NO", "YES"][
(
side(p1, p2, p0) == side(p2, p3, p0)
and side(p2, p3, p0) == side(p3, p1, p0)
)
]
)
| import sys
def side(p1, p2, p3):
return (p3[1] - p1[1]) * (p2[0] - p1[0]) - (p2[1] - p1[1]) * (p3[0] - p1[0]) > 0
for s in sys.stdin:
x = list(map(float, s.split()))
p1 = x[0:2]
p2 = x[2:4]
p3 = x[4:6]
p0 = x[6:]
print(["NO", "YES"][(side(p1, p2, p0) == side(p2, p3, p0) == side(p3, p1, p0))])
| false | 0 | [
"- print(",
"- [\"NO\", \"YES\"][",
"- (",
"- side(p1, p2, p0) == side(p2, p3, p0)",
"- and side(p2, p3, p0) == side(p3, p1, p0)",
"- )",
"- ]",
"- )",
"+ print([\"NO\", \"YES\"][(side(p1, p2, p0) == side(p2, p3, p0) == side(... | false | 0.121952 | 0.073038 | 1.669715 | [
"s482319853",
"s588862989"
] |
u875291233 | p03819 | python | s421554184 | s332015309 | 1,520 | 1,152 | 123,220 | 175,528 | Accepted | Accepted | 24.21 | # coding: utf-8
# Your code here!
import sys
input = sys.stdin.readline #文字列入力のときは注意
class Bit:
def __init__(self, n):
self.size = n
self.tree = [0] * (n + 1)
self.base = [0]* (n+1)
def sum(self, i):
s = 0
while i > 0:
s += self.tree[i]
i -= i & -i
return s
def add(self, i, x):
self.base[i] += x
while i <= self.size:
self.tree[i] += x
i += i & -i
def get(self, i):
return self.base[i]
class RangeUpdate:
def __init__(self, n):
self.p = Bit(n + 1)
self.q = Bit(n + 1)
def add(self, s, t, x):
t += 1
self.p.add(s, -x * s)
self.p.add(t, x * t)
self.q.add(s, x)
self.q.add(t, -x)
def sum(self, s, t):
t += 1
return self.p.sum(t) + self.q.sum(t) * t - \
self.p.sum(s) - self.q.sum(s) * s
# def get(self, s):
# return self.p.sum(s+1) + self.q.sum(s+1) * (s+1) - \
# self.p.sum(s) - self.q.sum(s) * s
def get(self, s):
return self.p.get(s+1) + self.q.get(s+1) * (s+1) + self.q.sum(s)
n,m = [int(i) for i in input().split()]
lr = [[int(i) for i in input().split()] for _ in range(n)]
lr.sort(key=lambda x: x[1]-x[0])
#print(lr)
omiyage = RangeUpdate(m+1)
index = 0
for d in range(1,m+1):
while(index < n and lr[index][1] - lr[index][0] < d):
omiyage.add(lr[index][0]+1, lr[index][1]+1, 1)
index+=1
ans = 0
pos = 0
while(pos <= m):
ans += omiyage.get(pos+1)
pos += d
ans += n-index
print(ans)
| class BIT: #0-indexed
def __init__(self, n):
self.size = n
self.tree = [0]*(n+1)
self.depth = n.bit_length()
self.n0 = 1<<self.depth
# self.element = [0]*(n+1)
def get_sum(self, i): #a_0 + ... + a_{i} #閉区間
s = 0; i += 1
while i > 0:
s += self.tree[i]
i -= i & -i
return s
def query(self,l,r): #a_l + ... + a_r 閉区間
return self.get_sum(r) - self.get_sum(l-1)
def add(self, i, x):
i += 1
while i <= self.size:
self.tree[i] += x
i += i & -i
# self.element[i] += x
#def get(self,i): return element[i]
def bisect_left(self,w):
#和が w 以上になる最小の index
#w が存在しない場合 self.size を返す
if w <= 0: return 0
x,k = 0,self.n0
for _ in range(self.depth):
k >>= 1
if x+k <= self.size and self.tree[x+k] < w:
w -= self.tree[x+k]
x += k
return x
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline
n,m,*lr = map(int,read().split())
mp = iter(lr)
dlr = [(r-l+1,l,r) for l,r in zip(mp,mp)]
dlr.sort(reverse=True)
ans = [0]*(m+1)
b = BIT(m+2)
for i in range(1,m+1):
while dlr and dlr[-1][0] < i:
d,l,r = dlr.pop()
b.add(l,1)
b.add(r+1,-1)
#print(i,l,r)
v = 0
for j in range(i,m+1,i):
v += b.get_sum(j)
#print(b.get_sum(1),b.get_sum(2),b.get_sum(3), b.get_sum(4))
ans[i] = len(dlr) + v
print(*ans[1:],sep="\n")
| 73 | 72 | 1,728 | 1,676 | # coding: utf-8
# Your code here!
import sys
input = sys.stdin.readline # 文字列入力のときは注意
class Bit:
def __init__(self, n):
self.size = n
self.tree = [0] * (n + 1)
self.base = [0] * (n + 1)
def sum(self, i):
s = 0
while i > 0:
s += self.tree[i]
i -= i & -i
return s
def add(self, i, x):
self.base[i] += x
while i <= self.size:
self.tree[i] += x
i += i & -i
def get(self, i):
return self.base[i]
class RangeUpdate:
def __init__(self, n):
self.p = Bit(n + 1)
self.q = Bit(n + 1)
def add(self, s, t, x):
t += 1
self.p.add(s, -x * s)
self.p.add(t, x * t)
self.q.add(s, x)
self.q.add(t, -x)
def sum(self, s, t):
t += 1
return self.p.sum(t) + self.q.sum(t) * t - self.p.sum(s) - self.q.sum(s) * s
# def get(self, s):
# return self.p.sum(s+1) + self.q.sum(s+1) * (s+1) - \
# self.p.sum(s) - self.q.sum(s) * s
def get(self, s):
return self.p.get(s + 1) + self.q.get(s + 1) * (s + 1) + self.q.sum(s)
n, m = [int(i) for i in input().split()]
lr = [[int(i) for i in input().split()] for _ in range(n)]
lr.sort(key=lambda x: x[1] - x[0])
# print(lr)
omiyage = RangeUpdate(m + 1)
index = 0
for d in range(1, m + 1):
while index < n and lr[index][1] - lr[index][0] < d:
omiyage.add(lr[index][0] + 1, lr[index][1] + 1, 1)
index += 1
ans = 0
pos = 0
while pos <= m:
ans += omiyage.get(pos + 1)
pos += d
ans += n - index
print(ans)
| class BIT: # 0-indexed
def __init__(self, n):
self.size = n
self.tree = [0] * (n + 1)
self.depth = n.bit_length()
self.n0 = 1 << self.depth
# self.element = [0]*(n+1)
def get_sum(self, i): # a_0 + ... + a_{i} #閉区間
s = 0
i += 1
while i > 0:
s += self.tree[i]
i -= i & -i
return s
def query(self, l, r): # a_l + ... + a_r 閉区間
return self.get_sum(r) - self.get_sum(l - 1)
def add(self, i, x):
i += 1
while i <= self.size:
self.tree[i] += x
i += i & -i
# self.element[i] += x
# def get(self,i): return element[i]
def bisect_left(self, w):
# 和が w 以上になる最小の index
# w が存在しない場合 self.size を返す
if w <= 0:
return 0
x, k = 0, self.n0
for _ in range(self.depth):
k >>= 1
if x + k <= self.size and self.tree[x + k] < w:
w -= self.tree[x + k]
x += k
return x
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline
n, m, *lr = map(int, read().split())
mp = iter(lr)
dlr = [(r - l + 1, l, r) for l, r in zip(mp, mp)]
dlr.sort(reverse=True)
ans = [0] * (m + 1)
b = BIT(m + 2)
for i in range(1, m + 1):
while dlr and dlr[-1][0] < i:
d, l, r = dlr.pop()
b.add(l, 1)
b.add(r + 1, -1)
# print(i,l,r)
v = 0
for j in range(i, m + 1, i):
v += b.get_sum(j)
# print(b.get_sum(1),b.get_sum(2),b.get_sum(3), b.get_sum(4))
ans[i] = len(dlr) + v
print(*ans[1:], sep="\n")
| false | 1.369863 | [
"-# coding: utf-8",
"-# Your code here!",
"-import sys",
"-",
"-input = sys.stdin.readline # 文字列入力のときは注意",
"-",
"-",
"-class Bit:",
"+class BIT: # 0-indexed",
"- self.base = [0] * (n + 1)",
"+ self.depth = n.bit_length()",
"+ self.n0 = 1 << self.depth",
"- def sum(s... | false | 0.076448 | 0.044785 | 1.706983 | [
"s421554184",
"s332015309"
] |
u952708174 | p02814 | python | s063715912 | s297793094 | 510 | 172 | 16,308 | 16,308 | Accepted | Accepted | 66.27 | from functools import reduce
def d_semi_common_multiple():
from fractions import gcd
from functools import reduce
N, M = [int(i) for i in input().split()]
A = [int(i) // 2 for i in input().split()] # 先に2で割っておく
def count_divide_2(n):
ret = 0
while n % 2 == 0:
ret += 1
n //= 2
return ret
def lcm(a, b):
return a * b // gcd(a, b)
# A の全要素について、2で割れる回数は等しいか?
tmp = count_divide_2(A[0])
for a in A:
if count_divide_2(a) != tmp:
return 0
t = reduce(lambda x, y: lcm(x, y), A)
return M // t - M // (2 * t)
print((d_semi_common_multiple())) | from functools import reduce
def d_semi_common_multiple():
from fractions import gcd
from functools import reduce
N, M = [int(i) for i in input().split()]
A = [int(i) // 2 for i in input().split()] # 先に2で割っておく
def count_divide_2(n):
"""n に含まれる因数 2 の指数"""
return (n & -n).bit_length()
def lcm(a, b):
return a * b // gcd(a, b)
# A の全要素について,2で割れる回数は等しいか?
tmp = count_divide_2(A[0])
for a in A:
if count_divide_2(a) != tmp:
return 0
t = reduce(lambda x, y: lcm(x, y), A)
return (M // t) - (M // (2 * t))
print((d_semi_common_multiple())) | 26 | 23 | 652 | 618 | from functools import reduce
def d_semi_common_multiple():
from fractions import gcd
from functools import reduce
N, M = [int(i) for i in input().split()]
A = [int(i) // 2 for i in input().split()] # 先に2で割っておく
def count_divide_2(n):
ret = 0
while n % 2 == 0:
ret += 1
n //= 2
return ret
def lcm(a, b):
return a * b // gcd(a, b)
# A の全要素について、2で割れる回数は等しいか?
tmp = count_divide_2(A[0])
for a in A:
if count_divide_2(a) != tmp:
return 0
t = reduce(lambda x, y: lcm(x, y), A)
return M // t - M // (2 * t)
print((d_semi_common_multiple()))
| from functools import reduce
def d_semi_common_multiple():
from fractions import gcd
from functools import reduce
N, M = [int(i) for i in input().split()]
A = [int(i) // 2 for i in input().split()] # 先に2で割っておく
def count_divide_2(n):
"""n に含まれる因数 2 の指数"""
return (n & -n).bit_length()
def lcm(a, b):
return a * b // gcd(a, b)
# A の全要素について,2で割れる回数は等しいか?
tmp = count_divide_2(A[0])
for a in A:
if count_divide_2(a) != tmp:
return 0
t = reduce(lambda x, y: lcm(x, y), A)
return (M // t) - (M // (2 * t))
print((d_semi_common_multiple()))
| false | 11.538462 | [
"- ret = 0",
"- while n % 2 == 0:",
"- ret += 1",
"- n //= 2",
"- return ret",
"+ \"\"\"n に含まれる因数 2 の指数\"\"\"",
"+ return (n & -n).bit_length()",
"- # A の全要素について、2で割れる回数は等しいか?",
"+ # A の全要素について,2で割れる回数は等しいか?",
"- return M // t - M /... | false | 0.109198 | 0.055757 | 1.958463 | [
"s063715912",
"s297793094"
] |
u227082700 | p02821 | python | s208865293 | s682757559 | 1,481 | 1,242 | 14,268 | 14,196 | Accepted | Accepted | 16.14 | n,m=list(map(int,input().split()))
a=list(map(int,input().split()))
for i in range(n):a[i]*=-1
a.sort()
from bisect import bisect_left,bisect_right
def check(mid):
mm=0
for i in range(n):
if -(a[i]+a[0])<mid:break
mm+=bisect_right(a,-(mid+a[i]))
return mm
ok=0
ng=10**10+7
while ng!=ok+1:
mid=(ok+ng)//2
if check(mid)>=m:ok=mid
else:ng=mid
b=[0]
for i in a:b.append(b[-1]+i)
ans=0
for i in range(n):
if -(a[i]+a[0])<ok:break
ind=bisect_right(a,-(ok+a[i]))
ans+=a[i]*ind
ans+=b[ind]
print((-(ans+(check(ok)-m)*ok))) | from bisect import bisect_right as br
n,m=list(map(int,input().split()))
a=list(map(int,input().split()))
for i in range(n):a[i]*=-1
a.sort()
b=[0]
for i in a:b.append(b[-1]+i)
ng=2*10**5+7
ok=-1
while ok+1!=ng:
mid=(ng+ok)//2
co=0
for i in a:co+=br(a,-(mid+i))
if co<m:ng=mid
else:ok=mid
ans=0
co=0
for i in a:
ind=br(a,-(ok+i)-1)
co+=ind
ans+=-b[ind]-i*ind
ans+=(m-co)*ok
print(ans) | 26 | 23 | 559 | 416 | n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
for i in range(n):
a[i] *= -1
a.sort()
from bisect import bisect_left, bisect_right
def check(mid):
mm = 0
for i in range(n):
if -(a[i] + a[0]) < mid:
break
mm += bisect_right(a, -(mid + a[i]))
return mm
ok = 0
ng = 10**10 + 7
while ng != ok + 1:
mid = (ok + ng) // 2
if check(mid) >= m:
ok = mid
else:
ng = mid
b = [0]
for i in a:
b.append(b[-1] + i)
ans = 0
for i in range(n):
if -(a[i] + a[0]) < ok:
break
ind = bisect_right(a, -(ok + a[i]))
ans += a[i] * ind
ans += b[ind]
print((-(ans + (check(ok) - m) * ok)))
| from bisect import bisect_right as br
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
for i in range(n):
a[i] *= -1
a.sort()
b = [0]
for i in a:
b.append(b[-1] + i)
ng = 2 * 10**5 + 7
ok = -1
while ok + 1 != ng:
mid = (ng + ok) // 2
co = 0
for i in a:
co += br(a, -(mid + i))
if co < m:
ng = mid
else:
ok = mid
ans = 0
co = 0
for i in a:
ind = br(a, -(ok + i) - 1)
co += ind
ans += -b[ind] - i * ind
ans += (m - co) * ok
print(ans)
| false | 11.538462 | [
"+from bisect import bisect_right as br",
"+",
"-from bisect import bisect_left, bisect_right",
"-",
"-",
"-def check(mid):",
"- mm = 0",
"- for i in range(n):",
"- if -(a[i] + a[0]) < mid:",
"- break",
"- mm += bisect_right(a, -(mid + a[i]))",
"- return mm",
... | false | 0.141487 | 0.10572 | 1.338323 | [
"s208865293",
"s682757559"
] |
u143492911 | p03721 | python | s239956188 | s188315917 | 442 | 381 | 29,144 | 18,948 | Accepted | Accepted | 13.8 | n,k=list(map(int,input().split()))
a=[list(map(int,input().split()))for i in range(n)]
a.sort(key=lambda x:x[0])
count=0
for i,j in a:
count+=j
if k<=count:
print(i)
exit() | n,k=list(map(int,input().split()))
t=[tuple(map(int,input().split()))for i in range(n)]
t=sorted(t,key=lambda t:t[0])
total=0
for i in range(n):
total+=t[i][1]
if k<=total:
print((t[i][0]))
exit()
| 9 | 9 | 198 | 221 | n, k = list(map(int, input().split()))
a = [list(map(int, input().split())) for i in range(n)]
a.sort(key=lambda x: x[0])
count = 0
for i, j in a:
count += j
if k <= count:
print(i)
exit()
| n, k = list(map(int, input().split()))
t = [tuple(map(int, input().split())) for i in range(n)]
t = sorted(t, key=lambda t: t[0])
total = 0
for i in range(n):
total += t[i][1]
if k <= total:
print((t[i][0]))
exit()
| false | 0 | [
"-a = [list(map(int, input().split())) for i in range(n)]",
"-a.sort(key=lambda x: x[0])",
"-count = 0",
"-for i, j in a:",
"- count += j",
"- if k <= count:",
"- print(i)",
"+t = [tuple(map(int, input().split())) for i in range(n)]",
"+t = sorted(t, key=lambda t: t[0])",
"+total = 0"... | false | 0.076579 | 0.008166 | 9.378189 | [
"s239956188",
"s188315917"
] |
u347640436 | p02606 | python | s036128873 | s388806923 | 30 | 27 | 9,148 | 9,128 | Accepted | Accepted | 10 | L, R, d = list(map(int, input().split()))
result = 0
for i in range(L, R + 1):
if i % d == 0:
result += 1
print(result)
| L, R, d = list(map(int, input().split()))
print((R // d - (L - 1) // d))
| 7 | 3 | 133 | 68 | L, R, d = list(map(int, input().split()))
result = 0
for i in range(L, R + 1):
if i % d == 0:
result += 1
print(result)
| L, R, d = list(map(int, input().split()))
print((R // d - (L - 1) // d))
| false | 57.142857 | [
"-result = 0",
"-for i in range(L, R + 1):",
"- if i % d == 0:",
"- result += 1",
"-print(result)",
"+print((R // d - (L - 1) // d))"
] | false | 0.264124 | 0.295595 | 0.893535 | [
"s036128873",
"s388806923"
] |
u342051078 | p03211 | python | s343381406 | s585830796 | 20 | 17 | 2,940 | 2,940 | Accepted | Accepted | 15 | s = str(eval(input()))
ans = 1000
for i in range(len(s)-2):
x = int(s[i:i+3])
ans = min(ans, abs(x-753))
print(ans)
| s = eval(input())
ans = []
for i in range(len(s) - 2):
ans.append(abs(int(s[i:i+3]) - 753))
print((min(ans))) | 7 | 5 | 125 | 109 | s = str(eval(input()))
ans = 1000
for i in range(len(s) - 2):
x = int(s[i : i + 3])
ans = min(ans, abs(x - 753))
print(ans)
| s = eval(input())
ans = []
for i in range(len(s) - 2):
ans.append(abs(int(s[i : i + 3]) - 753))
print((min(ans)))
| false | 28.571429 | [
"-s = str(eval(input()))",
"-ans = 1000",
"+s = eval(input())",
"+ans = []",
"- x = int(s[i : i + 3])",
"- ans = min(ans, abs(x - 753))",
"-print(ans)",
"+ ans.append(abs(int(s[i : i + 3]) - 753))",
"+print((min(ans)))"
] | false | 0.047812 | 0.045794 | 1.044071 | [
"s343381406",
"s585830796"
] |
u855710796 | p02900 | python | s244649970 | s937113917 | 1,227 | 201 | 66,392 | 38,512 | Accepted | Accepted | 83.62 | import fractions
A, B = list(map(int, input().split()))
g = fractions.gcd(A, B)
d = []
p = []
for i in range(1,int(pow(g, 0.5))+1):
if g % i == 0:
d.append(i)
if i != g//i:
d.append(g//i)
for i in d:
s = 0
for j in range(1,int(pow(i, 0.5))+1):
if i % j == 0:
s += 1
if s == 1:
p.append(i)
print((len(p)))
| A, B = list(map(int, input().split()))
def prime_decompose(x):
decomposed = []
for i in range(2,int(pow(x,0.5))+1):
while x % i == 0:
x //= i
decomposed.append(i)
if x > 1:
decomposed.append(x)
return decomposed
A_dec = set(prime_decompose(A))
B_dec = set(prime_decompose(B))
ans = 1
for a in A_dec:
if a in B_dec:
ans += 1
print(ans)
| 24 | 21 | 397 | 421 | import fractions
A, B = list(map(int, input().split()))
g = fractions.gcd(A, B)
d = []
p = []
for i in range(1, int(pow(g, 0.5)) + 1):
if g % i == 0:
d.append(i)
if i != g // i:
d.append(g // i)
for i in d:
s = 0
for j in range(1, int(pow(i, 0.5)) + 1):
if i % j == 0:
s += 1
if s == 1:
p.append(i)
print((len(p)))
| A, B = list(map(int, input().split()))
def prime_decompose(x):
decomposed = []
for i in range(2, int(pow(x, 0.5)) + 1):
while x % i == 0:
x //= i
decomposed.append(i)
if x > 1:
decomposed.append(x)
return decomposed
A_dec = set(prime_decompose(A))
B_dec = set(prime_decompose(B))
ans = 1
for a in A_dec:
if a in B_dec:
ans += 1
print(ans)
| false | 12.5 | [
"-import fractions",
"+A, B = list(map(int, input().split()))",
"-A, B = list(map(int, input().split()))",
"-g = fractions.gcd(A, B)",
"-d = []",
"-p = []",
"-for i in range(1, int(pow(g, 0.5)) + 1):",
"- if g % i == 0:",
"- d.append(i)",
"- if i != g // i:",
"- d.app... | false | 0.060585 | 0.086601 | 0.699594 | [
"s244649970",
"s937113917"
] |
u249218427 | p02588 | python | s954629077 | s577236627 | 1,728 | 1,507 | 41,136 | 41,128 | Accepted | Accepted | 12.79 | # -*- coding: utf-8 -*-
import numpy as np
N = int(eval(input()))
A = [eval(input()) for _ in range(N)]
def count(a):
if '.' in a:
c = a.split('.')
n = int(c[0]+c[1])
count2 = 9 - len(c[1])
count5 = 9 - len(c[1])
else:
n = int(a)
count2 = 9
count5 = 9
while n%2 == 0 and count2<18:
n //= 2
count2 += 1
while n%5 == 0 and count5<18:
n //= 5
count5 += 1
return count2,count5
Z = np.zeros((19,19), dtype=np.int64)
answer = 0
for a in A:
c2,c5 = count(a)
answer += Z[18-c2,18-c5]
Z[:c2+1,:c5+1] += 1
print(answer) | # -*- coding: utf-8 -*-
import numpy as np
N = int(eval(input()))
A = [eval(input()) for _ in range(N)]
def count(a):
if '.' in a:
c = a.split('.')
n = int(c[0]+c[1])
count2 = count5 = 9 - len(c[1])
else:
n = int(a)
count2 = count5 = 9
while n%2 == 0 and count2<18:
n //= 2
count2 += 1
while n%5 == 0 and count5<18:
n //= 5
count5 += 1
return count2,count5
Z = np.zeros((19,19), dtype=np.int64)
answer = 0
for a in A:
c2,c5 = count(a)
answer += Z[18-c2,18-c5]
Z[:c2+1,:c5+1] += 1
print(answer) | 32 | 30 | 592 | 566 | # -*- coding: utf-8 -*-
import numpy as np
N = int(eval(input()))
A = [eval(input()) for _ in range(N)]
def count(a):
if "." in a:
c = a.split(".")
n = int(c[0] + c[1])
count2 = 9 - len(c[1])
count5 = 9 - len(c[1])
else:
n = int(a)
count2 = 9
count5 = 9
while n % 2 == 0 and count2 < 18:
n //= 2
count2 += 1
while n % 5 == 0 and count5 < 18:
n //= 5
count5 += 1
return count2, count5
Z = np.zeros((19, 19), dtype=np.int64)
answer = 0
for a in A:
c2, c5 = count(a)
answer += Z[18 - c2, 18 - c5]
Z[: c2 + 1, : c5 + 1] += 1
print(answer)
| # -*- coding: utf-8 -*-
import numpy as np
N = int(eval(input()))
A = [eval(input()) for _ in range(N)]
def count(a):
if "." in a:
c = a.split(".")
n = int(c[0] + c[1])
count2 = count5 = 9 - len(c[1])
else:
n = int(a)
count2 = count5 = 9
while n % 2 == 0 and count2 < 18:
n //= 2
count2 += 1
while n % 5 == 0 and count5 < 18:
n //= 5
count5 += 1
return count2, count5
Z = np.zeros((19, 19), dtype=np.int64)
answer = 0
for a in A:
c2, c5 = count(a)
answer += Z[18 - c2, 18 - c5]
Z[: c2 + 1, : c5 + 1] += 1
print(answer)
| false | 6.25 | [
"- count2 = 9 - len(c[1])",
"- count5 = 9 - len(c[1])",
"+ count2 = count5 = 9 - len(c[1])",
"- count2 = 9",
"- count5 = 9",
"+ count2 = count5 = 9"
] | false | 0.206713 | 0.497744 | 0.415299 | [
"s954629077",
"s577236627"
] |
u215461917 | p03731 | python | s535504454 | s002448396 | 114 | 100 | 25,196 | 25,196 | Accepted | Accepted | 12.28 |
N, T = list(map(int, input().split()))
t = list(map(int, input().split()))
s, e = 0, 0
ans = 0
for i in range(N):
if t[i] <= e:
e = t[i] + T
else:
ans += e - s
s = t[i]
e = t[i] + T
ans += e - s
print(ans)
| def main() :
n,t = (int(i) for i in input().split())
ni = [int(i) for i in input().split()]
total = 0
for i in range(1,len(ni)) :
delta = ni[i] - ni[i-1]
if delta < t :
total += delta
else :
total += t
print((total+t))
main() | 16 | 17 | 238 | 282 | N, T = list(map(int, input().split()))
t = list(map(int, input().split()))
s, e = 0, 0
ans = 0
for i in range(N):
if t[i] <= e:
e = t[i] + T
else:
ans += e - s
s = t[i]
e = t[i] + T
ans += e - s
print(ans)
| def main():
n, t = (int(i) for i in input().split())
ni = [int(i) for i in input().split()]
total = 0
for i in range(1, len(ni)):
delta = ni[i] - ni[i - 1]
if delta < t:
total += delta
else:
total += t
print((total + t))
main()
| false | 5.882353 | [
"-N, T = list(map(int, input().split()))",
"-t = list(map(int, input().split()))",
"-s, e = 0, 0",
"-ans = 0",
"-for i in range(N):",
"- if t[i] <= e:",
"- e = t[i] + T",
"- else:",
"- ans += e - s",
"- s = t[i]",
"- e = t[i] + T",
"-ans += e - s",
"-print(a... | false | 0.035511 | 0.036179 | 0.981543 | [
"s535504454",
"s002448396"
] |
u638456847 | p02690 | python | s840719027 | s622534979 | 314 | 33 | 64,788 | 9,460 | Accepted | Accepted | 89.49 | from bisect import bisect_right
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
def main():
x = int(readline())
A = [i**5 for i in range(10**6)]
for b in A:
a = x + b
idx = bisect_right(A, a) - 1
if A[idx] == a:
print((int(pow(a, 0.2)), int(pow(b, 0.2))))
break
a = x - b
idx = bisect_right(A, a) - 1
if A[idx] == a:
print((int(pow(a, 0.2)), -int(pow(b, 0.2))))
break
if __name__ == "__main__":
main()
| from itertools import combinations_with_replacement
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
def main():
x = int(readline())
ab = [i**5 for i in range(10**3)]
C = combinations_with_replacement(ab, 2)
for a, b in C:
if a + b == x:
print((int(pow(b, 0.2)), -int(pow(a, 0.2))))
break
if b - a == x:
print((int(pow(b, 0.2)), int(pow(a, 0.2))))
break
if __name__ == "__main__":
main()
| 26 | 24 | 595 | 551 | from bisect import bisect_right
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
def main():
x = int(readline())
A = [i**5 for i in range(10**6)]
for b in A:
a = x + b
idx = bisect_right(A, a) - 1
if A[idx] == a:
print((int(pow(a, 0.2)), int(pow(b, 0.2))))
break
a = x - b
idx = bisect_right(A, a) - 1
if A[idx] == a:
print((int(pow(a, 0.2)), -int(pow(b, 0.2))))
break
if __name__ == "__main__":
main()
| from itertools import combinations_with_replacement
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
def main():
x = int(readline())
ab = [i**5 for i in range(10**3)]
C = combinations_with_replacement(ab, 2)
for a, b in C:
if a + b == x:
print((int(pow(b, 0.2)), -int(pow(a, 0.2))))
break
if b - a == x:
print((int(pow(b, 0.2)), int(pow(a, 0.2))))
break
if __name__ == "__main__":
main()
| false | 7.692308 | [
"-from bisect import bisect_right",
"+from itertools import combinations_with_replacement",
"- A = [i**5 for i in range(10**6)]",
"- for b in A:",
"- a = x + b",
"- idx = bisect_right(A, a) - 1",
"- if A[idx] == a:",
"- print((int(pow(a, 0.2)), int(pow(b, 0.2))))"... | false | 2.377754 | 0.12464 | 19.076972 | [
"s840719027",
"s622534979"
] |
u331226975 | p02732 | python | s672512665 | s312716047 | 422 | 337 | 26,140 | 26,780 | Accepted | Accepted | 20.14 | N = int(eval(input()))
A = list(map(int, input().split()))
# A_set = list(set(A))
# Ad = {a_set:A.count(a_set) for a_set in A_set}
Ad = {}
for i in A:
if not i in Ad:
Ad[i]=0
Ad[i] += 1
score_sum = sum([x*(x-1)/2 for x in list(Ad.values())])
for a in A:
print((int(score_sum - (Ad[a] - 1))))
| import collections
N = int(eval(input()))
A = list(map(int, input().split()))
Ad = dict(collections.Counter(A))
# A_set = list(set(A))
# Ad = {a_set:A.count(a_set) for a_set in A_set}
# Ad = {}
# for i in A:
# if not i in Ad:
# Ad[i]=0
# Ad[i] += 1
score_sum = sum([x*(x-1)/2 for x in list(Ad.values())])
for a in A:
print((int(score_sum - (Ad[a] - 1))))
| 15 | 18 | 313 | 380 | N = int(eval(input()))
A = list(map(int, input().split()))
# A_set = list(set(A))
# Ad = {a_set:A.count(a_set) for a_set in A_set}
Ad = {}
for i in A:
if not i in Ad:
Ad[i] = 0
Ad[i] += 1
score_sum = sum([x * (x - 1) / 2 for x in list(Ad.values())])
for a in A:
print((int(score_sum - (Ad[a] - 1))))
| import collections
N = int(eval(input()))
A = list(map(int, input().split()))
Ad = dict(collections.Counter(A))
# A_set = list(set(A))
# Ad = {a_set:A.count(a_set) for a_set in A_set}
# Ad = {}
# for i in A:
# if not i in Ad:
# Ad[i]=0
# Ad[i] += 1
score_sum = sum([x * (x - 1) / 2 for x in list(Ad.values())])
for a in A:
print((int(score_sum - (Ad[a] - 1))))
| false | 16.666667 | [
"+import collections",
"+",
"+Ad = dict(collections.Counter(A))",
"-Ad = {}",
"-for i in A:",
"- if not i in Ad:",
"- Ad[i] = 0",
"- Ad[i] += 1",
"+# Ad = {}",
"+# for i in A:",
"+# if not i in Ad:",
"+# Ad[i]=0",
"+# Ad[i] += 1"
] | false | 0.044437 | 0.043563 | 1.020054 | [
"s672512665",
"s312716047"
] |
u693391925 | p03721 | python | s361381989 | s186044574 | 472 | 319 | 29,144 | 5,748 | Accepted | Accepted | 32.42 | N, K = list(map(int, input().split()))
S = [list(map(int, input().split())) for _ in range(N)]
from operator import itemgetter
S.sort(key=itemgetter(0))
#timesは今何番目に大きいものを表しているか
times=0
#indexは今のインデックス
index=0
while True:
hoge = times+S[index][1]
if hoge < K:
times += S[index][1]
else:
re =S[index][0]
break
index += 1
print(re)
| N, K = list(map(int, input().split()))
li=[0]*100001
for i in range(N):
a,b = list(map(int, input().split()))
li[a] += b
tmp=0
for i in range(100001):
tmp += li[i]
if tmp >= K:
print(i)
break | 21 | 13 | 389 | 225 | N, K = list(map(int, input().split()))
S = [list(map(int, input().split())) for _ in range(N)]
from operator import itemgetter
S.sort(key=itemgetter(0))
# timesは今何番目に大きいものを表しているか
times = 0
# indexは今のインデックス
index = 0
while True:
hoge = times + S[index][1]
if hoge < K:
times += S[index][1]
else:
re = S[index][0]
break
index += 1
print(re)
| N, K = list(map(int, input().split()))
li = [0] * 100001
for i in range(N):
a, b = list(map(int, input().split()))
li[a] += b
tmp = 0
for i in range(100001):
tmp += li[i]
if tmp >= K:
print(i)
break
| false | 38.095238 | [
"-S = [list(map(int, input().split())) for _ in range(N)]",
"-from operator import itemgetter",
"-",
"-S.sort(key=itemgetter(0))",
"-# timesは今何番目に大きいものを表しているか",
"-times = 0",
"-# indexは今のインデックス",
"-index = 0",
"-while True:",
"- hoge = times + S[index][1]",
"- if hoge < K:",
"- ti... | false | 0.053768 | 0.038739 | 1.387973 | [
"s361381989",
"s186044574"
] |
u607155447 | p02712 | python | s151838467 | s670497530 | 145 | 31 | 9,164 | 8,976 | Accepted | Accepted | 78.62 | N = int(eval(input()))
ans = 0
for i in range(1,N+1):
if i%3 and i%5:
ans += i
print(ans) | N = int(eval(input()))
N3 = N//3
N5 = N//5
N15 = N//15
ans = N*(N+1)/2 - 3*N3*(N3+1)/2 -5*N5*(N5+1)/2 + 15*N15*(N15+1)/2
print((int(ans))) | 7 | 8 | 102 | 139 | N = int(eval(input()))
ans = 0
for i in range(1, N + 1):
if i % 3 and i % 5:
ans += i
print(ans)
| N = int(eval(input()))
N3 = N // 3
N5 = N // 5
N15 = N // 15
ans = (
N * (N + 1) / 2
- 3 * N3 * (N3 + 1) / 2
- 5 * N5 * (N5 + 1) / 2
+ 15 * N15 * (N15 + 1) / 2
)
print((int(ans)))
| false | 12.5 | [
"-ans = 0",
"-for i in range(1, N + 1):",
"- if i % 3 and i % 5:",
"- ans += i",
"-print(ans)",
"+N3 = N // 3",
"+N5 = N // 5",
"+N15 = N // 15",
"+ans = (",
"+ N * (N + 1) / 2",
"+ - 3 * N3 * (N3 + 1) / 2",
"+ - 5 * N5 * (N5 + 1) / 2",
"+ + 15 * N15 * (N15 + 1) / 2",
... | false | 0.278512 | 0.03764 | 7.399407 | [
"s151838467",
"s670497530"
] |
u761320129 | p03212 | python | s838249540 | s002207059 | 88 | 43 | 3,060 | 3,060 | Accepted | Accepted | 51.14 | import itertools
N = int(eval(input()))
D = len(str(N))
ans = 0
for d in range(3,D+1):
for ptn in itertools.product([3,5,7], repeat=d):
if len(set(ptn)) < 3: continue
n = int(''.join(map(str,ptn)))
if n <= N:
ans += 1
print(ans) | N = int(eval(input()))
from itertools import product
ans = 0
for n in range(3,10):
for ptn in product('753', repeat=n):
if '7' not in ptn: continue
if '5' not in ptn: continue
if '3' not in ptn: continue
v = int(''.join(ptn))
if v <= N:
ans += 1
print(ans) | 12 | 12 | 274 | 317 | import itertools
N = int(eval(input()))
D = len(str(N))
ans = 0
for d in range(3, D + 1):
for ptn in itertools.product([3, 5, 7], repeat=d):
if len(set(ptn)) < 3:
continue
n = int("".join(map(str, ptn)))
if n <= N:
ans += 1
print(ans)
| N = int(eval(input()))
from itertools import product
ans = 0
for n in range(3, 10):
for ptn in product("753", repeat=n):
if "7" not in ptn:
continue
if "5" not in ptn:
continue
if "3" not in ptn:
continue
v = int("".join(ptn))
if v <= N:
ans += 1
print(ans)
| false | 0 | [
"-import itertools",
"+N = int(eval(input()))",
"+from itertools import product",
"-N = int(eval(input()))",
"-D = len(str(N))",
"-for d in range(3, D + 1):",
"- for ptn in itertools.product([3, 5, 7], repeat=d):",
"- if len(set(ptn)) < 3:",
"+for n in range(3, 10):",
"+ for ptn in pr... | false | 0.063852 | 0.0854 | 0.747685 | [
"s838249540",
"s002207059"
] |
u888933875 | p03109 | python | s321414709 | s777755458 | 29 | 24 | 9,072 | 8,988 | Accepted | Accepted | 17.24 | s=eval(input())
s=int(s.replace("/",""))
print(("Heisei" if s<=20190430 else "TBD")) | s=eval(input())
s=int(s.replace("/",""))
print((["Heisei","TBD"][s>20190430])) | 3 | 3 | 78 | 72 | s = eval(input())
s = int(s.replace("/", ""))
print(("Heisei" if s <= 20190430 else "TBD"))
| s = eval(input())
s = int(s.replace("/", ""))
print((["Heisei", "TBD"][s > 20190430]))
| false | 0 | [
"-print((\"Heisei\" if s <= 20190430 else \"TBD\"))",
"+print(([\"Heisei\", \"TBD\"][s > 20190430]))"
] | false | 0.042231 | 0.041836 | 1.009449 | [
"s321414709",
"s777755458"
] |
u644907318 | p02760 | python | s888671175 | s388353128 | 174 | 65 | 38,384 | 62,172 | Accepted | Accepted | 62.64 | A = [list(map(int,input().split())) for _ in range(3)]
N = int(eval(input()))
B = [int(eval(input())) for _ in range(N)]
for i in range(3):
bng = 1
for j in range(3):
if A[i][j] in B:
continue
else:
bng = 0
break
if bng ==1:break
if bng==1:
print("Yes")
else:
for j in range(3):
bng = 1
for i in range(3):
if A[i][j] in B:
continue
else:
bng = 0
break
if bng==1:break
if bng==1:
print("Yes")
else:
if A[0][0] in B and A[1][1] in B and A[2][2] in B:
print("Yes")
elif A[0][2] in B and A[1][1] in B and A[2][0] in B:
print("Yes")
else:
print("No") | A = [list(map(int,input().split())) for _ in range(3)]
N = int(eval(input()))
B = [[0 for _ in range(3)] for _ in range(3)]
for _ in range(N):
b = int(eval(input()))
for i in range(3):
for j in range(3):
if A[i][j]==b:
B[i][j] = 1
flag = 0
for i in range(3):
if sum(B[i])==3:
flag = 1
break
for j in range(3):
cnt = 0
for i in range(3):
cnt += B[i][j]
if cnt==3:
flag = 1
break
if B[0][0]+B[1][1]+B[2][2]==3:
flag = 1
if B[2][0]+B[1][1]+B[0][2]==3:
flag = 1
if flag==1:
print("Yes")
else:
print("No") | 33 | 29 | 809 | 632 | A = [list(map(int, input().split())) for _ in range(3)]
N = int(eval(input()))
B = [int(eval(input())) for _ in range(N)]
for i in range(3):
bng = 1
for j in range(3):
if A[i][j] in B:
continue
else:
bng = 0
break
if bng == 1:
break
if bng == 1:
print("Yes")
else:
for j in range(3):
bng = 1
for i in range(3):
if A[i][j] in B:
continue
else:
bng = 0
break
if bng == 1:
break
if bng == 1:
print("Yes")
else:
if A[0][0] in B and A[1][1] in B and A[2][2] in B:
print("Yes")
elif A[0][2] in B and A[1][1] in B and A[2][0] in B:
print("Yes")
else:
print("No")
| A = [list(map(int, input().split())) for _ in range(3)]
N = int(eval(input()))
B = [[0 for _ in range(3)] for _ in range(3)]
for _ in range(N):
b = int(eval(input()))
for i in range(3):
for j in range(3):
if A[i][j] == b:
B[i][j] = 1
flag = 0
for i in range(3):
if sum(B[i]) == 3:
flag = 1
break
for j in range(3):
cnt = 0
for i in range(3):
cnt += B[i][j]
if cnt == 3:
flag = 1
break
if B[0][0] + B[1][1] + B[2][2] == 3:
flag = 1
if B[2][0] + B[1][1] + B[0][2] == 3:
flag = 1
if flag == 1:
print("Yes")
else:
print("No")
| false | 12.121212 | [
"-B = [int(eval(input())) for _ in range(N)]",
"+B = [[0 for _ in range(3)] for _ in range(3)]",
"+for _ in range(N):",
"+ b = int(eval(input()))",
"+ for i in range(3):",
"+ for j in range(3):",
"+ if A[i][j] == b:",
"+ B[i][j] = 1",
"+flag = 0",
"- bng =... | false | 0.035821 | 0.040004 | 0.895434 | [
"s888671175",
"s388353128"
] |
u872030436 | p03378 | python | s462822021 | s216586852 | 20 | 17 | 3,060 | 2,940 | Accepted | Accepted | 15 | N, M, X = list(map(int, input().split()))
A = list(map(int, input().split()))
a = [0 for _ in range(N+1)]
for n in A:
a[n] = 1
print((min(sum(a[:X]), sum(a[X+1:])))) | n,m,x=list(map(int,input().split()))
s=sum(int(i)<x for i in input().split())
print((min(s,m-s))) | 8 | 3 | 170 | 91 | N, M, X = list(map(int, input().split()))
A = list(map(int, input().split()))
a = [0 for _ in range(N + 1)]
for n in A:
a[n] = 1
print((min(sum(a[:X]), sum(a[X + 1 :]))))
| n, m, x = list(map(int, input().split()))
s = sum(int(i) < x for i in input().split())
print((min(s, m - s)))
| false | 62.5 | [
"-N, M, X = list(map(int, input().split()))",
"-A = list(map(int, input().split()))",
"-a = [0 for _ in range(N + 1)]",
"-for n in A:",
"- a[n] = 1",
"-print((min(sum(a[:X]), sum(a[X + 1 :]))))",
"+n, m, x = list(map(int, input().split()))",
"+s = sum(int(i) < x for i in input().split())",
"+prin... | false | 0.049496 | 0.047705 | 1.037544 | [
"s462822021",
"s216586852"
] |
u945228737 | p02703 | python | s418338363 | s581440104 | 761 | 699 | 28,204 | 28,156 | Accepted | Accepted | 8.15 | # 解説と提出#12551970を参考に作成
# 今いる都市と銀貨の所持数を状態として、
# ①その都市から移動可能な別の都市に移動する
# ②金貨を銀貨に交換する
# のどちらかを行い、実施後の(同都市・同所持銀貨枚数での)最小時間を計測していく。
# 最小時間が更新された場合、さらにその状態から①・②を行う。
# これによって全都市・全銀貨所持枚数毎の最小時間を割り出す。
# 都市の銀貨所持枚数毎の最小時間の中での最小時間がその都市へ行くための最小時間になる。
# ※1: 都市への移動は移動可能な枚数の銀貨を持っている場合のみ可能
# ※2: 銀貨の最大所持枚数は (N - 1) * max(Ai) とする
# -> 一番遠い都市に移動する場合にかかりうる最大の銀貨枚数
from heapq import heappop, heappush
def solve():
n, m, s = list(map(int, input().split()))
graph = [[] for _ in range(n)]
# グラフ作製
for _ in range(m):
u, v, a, b = list(map(int, input().split()))
graph[u - 1].append([v - 1, a, b])
graph[v - 1].append([u - 1, a, b])
ce = [[int(i) for i in input().split()] for _ in range(n)]
# 初期値マップ作製
maxSilver = 50 * 49 # max(a) * (n - 1)
inf = float('inf')
ns_map = [[inf] * (maxSilver + 1) for _ in range(n)]
# スタート時の値設定と探索
q = [[0, 0, min(maxSilver, s)]] # 累計時間, 都市, 所持銀貨
ns_map[0][min(maxSilver, s)] = 0 # スタート地点の時刻は0
while q:
ti, ni, si = heappop(q)
# 移動
for g in graph[ni]:
n2, ai, bi = g
if si >= ai and ns_map[n2][si - ai] > ti + bi:
ns_map[n2][si - ai] = ti + bi
# ★heapq で累計時間が少ない情報から先に処理するようにする.
# これによって処理速度が全然違う
heappush(q, [ti + bi, n2, si - ai])
# 換金
ci, di = ce[ni]
ti += di
si = min(si + ci, maxSilver)
if ns_map[ni][si] > ti:
ns_map[ni][si] = ti
heappush(q, [ti, ni, si])
for i in range(1, n):
print((min(ns_map[i])))
if __name__ == '__main__':
solve()
| # 解説と提出#12551970を参考に作成
# 今いる都市と銀貨の所持数を状態として、
# ①その都市から移動可能な別の都市に移動する
# ②金貨を銀貨に交換する
# のどちらかを行い、実施後の(同都市・同所持銀貨枚数での)最小時間を計測していく。
# 最小時間が更新された場合、さらにその状態から①・②を行う。
# これによって全都市・全銀貨所持枚数毎の最小時間を割り出す。
# 都市の銀貨所持枚数毎の最小時間の中での最小時間がその都市へ行くための最小時間になる。
# ※1: 都市への移動は移動可能な枚数の銀貨を持っている場合のみ可能
# ※2: 銀貨の最大所持枚数は (N - 1) * max(Ai) とする
# -> 一番遠い都市に移動する場合にかかりうる最大の銀貨枚数
from heapq import heappop, heappush
def solve():
n, m, s = list(map(int, input().split()))
graph = [[] for _ in range(n)]
# グラフ作製
max_a = 0
for _ in range(m):
u, v, a, b = list(map(int, input().split()))
graph[u - 1].append([v - 1, a, b])
graph[v - 1].append([u - 1, a, b])
max_a = max(max_a, a)
ce = [[int(i) for i in input().split()] for _ in range(n)]
# 初期値マップ作製
maxSilver = max_a * (n - 1) # max(a) * (n - 1)
inf = float('inf')
ns_map = [[inf] * (maxSilver + 1) for _ in range(n)]
# スタート時の値設定と探索
q = [[0, 0, min(maxSilver, s)]] # 累計時間, 都市, 所持銀貨
ns_map[0][min(maxSilver, s)] = 0 # スタート地点の時刻は0
while q:
ti, ni, si = heappop(q)
# 移動
for g in graph[ni]:
n2, ai, bi = g
if si >= ai and ns_map[n2][si - ai] > ti + bi:
ns_map[n2][si - ai] = ti + bi
# ★heapq で累計時間が少ない情報から先に処理するようにする.
# これによって処理速度が全然違う
heappush(q, [ti + bi, n2, si - ai])
# 換金
ci, di = ce[ni]
ti += di
si = min(si + ci, maxSilver)
if ns_map[ni][si] > ti:
ns_map[ni][si] = ti
heappush(q, [ti, ni, si])
for i in range(1, n):
print((min(ns_map[i])))
if __name__ == '__main__':
solve()
| 54 | 56 | 1,677 | 1,731 | # 解説と提出#12551970を参考に作成
# 今いる都市と銀貨の所持数を状態として、
# ①その都市から移動可能な別の都市に移動する
# ②金貨を銀貨に交換する
# のどちらかを行い、実施後の(同都市・同所持銀貨枚数での)最小時間を計測していく。
# 最小時間が更新された場合、さらにその状態から①・②を行う。
# これによって全都市・全銀貨所持枚数毎の最小時間を割り出す。
# 都市の銀貨所持枚数毎の最小時間の中での最小時間がその都市へ行くための最小時間になる。
# ※1: 都市への移動は移動可能な枚数の銀貨を持っている場合のみ可能
# ※2: 銀貨の最大所持枚数は (N - 1) * max(Ai) とする
# -> 一番遠い都市に移動する場合にかかりうる最大の銀貨枚数
from heapq import heappop, heappush
def solve():
n, m, s = list(map(int, input().split()))
graph = [[] for _ in range(n)]
# グラフ作製
for _ in range(m):
u, v, a, b = list(map(int, input().split()))
graph[u - 1].append([v - 1, a, b])
graph[v - 1].append([u - 1, a, b])
ce = [[int(i) for i in input().split()] for _ in range(n)]
# 初期値マップ作製
maxSilver = 50 * 49 # max(a) * (n - 1)
inf = float("inf")
ns_map = [[inf] * (maxSilver + 1) for _ in range(n)]
# スタート時の値設定と探索
q = [[0, 0, min(maxSilver, s)]] # 累計時間, 都市, 所持銀貨
ns_map[0][min(maxSilver, s)] = 0 # スタート地点の時刻は0
while q:
ti, ni, si = heappop(q)
# 移動
for g in graph[ni]:
n2, ai, bi = g
if si >= ai and ns_map[n2][si - ai] > ti + bi:
ns_map[n2][si - ai] = ti + bi
# ★heapq で累計時間が少ない情報から先に処理するようにする.
# これによって処理速度が全然違う
heappush(q, [ti + bi, n2, si - ai])
# 換金
ci, di = ce[ni]
ti += di
si = min(si + ci, maxSilver)
if ns_map[ni][si] > ti:
ns_map[ni][si] = ti
heappush(q, [ti, ni, si])
for i in range(1, n):
print((min(ns_map[i])))
if __name__ == "__main__":
solve()
| # 解説と提出#12551970を参考に作成
# 今いる都市と銀貨の所持数を状態として、
# ①その都市から移動可能な別の都市に移動する
# ②金貨を銀貨に交換する
# のどちらかを行い、実施後の(同都市・同所持銀貨枚数での)最小時間を計測していく。
# 最小時間が更新された場合、さらにその状態から①・②を行う。
# これによって全都市・全銀貨所持枚数毎の最小時間を割り出す。
# 都市の銀貨所持枚数毎の最小時間の中での最小時間がその都市へ行くための最小時間になる。
# ※1: 都市への移動は移動可能な枚数の銀貨を持っている場合のみ可能
# ※2: 銀貨の最大所持枚数は (N - 1) * max(Ai) とする
# -> 一番遠い都市に移動する場合にかかりうる最大の銀貨枚数
from heapq import heappop, heappush
def solve():
n, m, s = list(map(int, input().split()))
graph = [[] for _ in range(n)]
# グラフ作製
max_a = 0
for _ in range(m):
u, v, a, b = list(map(int, input().split()))
graph[u - 1].append([v - 1, a, b])
graph[v - 1].append([u - 1, a, b])
max_a = max(max_a, a)
ce = [[int(i) for i in input().split()] for _ in range(n)]
# 初期値マップ作製
maxSilver = max_a * (n - 1) # max(a) * (n - 1)
inf = float("inf")
ns_map = [[inf] * (maxSilver + 1) for _ in range(n)]
# スタート時の値設定と探索
q = [[0, 0, min(maxSilver, s)]] # 累計時間, 都市, 所持銀貨
ns_map[0][min(maxSilver, s)] = 0 # スタート地点の時刻は0
while q:
ti, ni, si = heappop(q)
# 移動
for g in graph[ni]:
n2, ai, bi = g
if si >= ai and ns_map[n2][si - ai] > ti + bi:
ns_map[n2][si - ai] = ti + bi
# ★heapq で累計時間が少ない情報から先に処理するようにする.
# これによって処理速度が全然違う
heappush(q, [ti + bi, n2, si - ai])
# 換金
ci, di = ce[ni]
ti += di
si = min(si + ci, maxSilver)
if ns_map[ni][si] > ti:
ns_map[ni][si] = ti
heappush(q, [ti, ni, si])
for i in range(1, n):
print((min(ns_map[i])))
if __name__ == "__main__":
solve()
| false | 3.571429 | [
"+ max_a = 0",
"+ max_a = max(max_a, a)",
"- maxSilver = 50 * 49 # max(a) * (n - 1)",
"+ maxSilver = max_a * (n - 1) # max(a) * (n - 1)"
] | false | 0.075443 | 0.077384 | 0.974921 | [
"s418338363",
"s581440104"
] |
u055687574 | p03845 | python | s409532877 | s416965344 | 38 | 22 | 3,444 | 3,444 | Accepted | Accepted | 42.11 | import copy
n = int(eval(input()))
t = list(map(int, input().split()))
n = int(eval(input()))
for i in range(n):
idx, value = list(map(int, input().split()))
T = copy.deepcopy(t)
t[idx - 1] = value
print((sum(t)))
t = copy.deepcopy(T)
| import copy
n = int(eval(input()))
t = list(map(int, input().split()))
sum_t = sum(t)
m = int(eval(input()))
for _ in range(m):
idx, value = list(map(int, input().split()))
print((sum_t - t[idx - 1] + value))
| 13 | 12 | 250 | 212 | import copy
n = int(eval(input()))
t = list(map(int, input().split()))
n = int(eval(input()))
for i in range(n):
idx, value = list(map(int, input().split()))
T = copy.deepcopy(t)
t[idx - 1] = value
print((sum(t)))
t = copy.deepcopy(T)
| import copy
n = int(eval(input()))
t = list(map(int, input().split()))
sum_t = sum(t)
m = int(eval(input()))
for _ in range(m):
idx, value = list(map(int, input().split()))
print((sum_t - t[idx - 1] + value))
| false | 7.692308 | [
"-n = int(eval(input()))",
"-for i in range(n):",
"+sum_t = sum(t)",
"+m = int(eval(input()))",
"+for _ in range(m):",
"- T = copy.deepcopy(t)",
"- t[idx - 1] = value",
"- print((sum(t)))",
"- t = copy.deepcopy(T)",
"+ print((sum_t - t[idx - 1] + value))"
] | false | 0.061975 | 0.056598 | 1.094998 | [
"s409532877",
"s416965344"
] |
u606045429 | p02883 | python | s556818631 | s666836472 | 418 | 362 | 53,188 | 26,172 | Accepted | Accepted | 13.4 | from numpy import array, int64, minimum
def main():
N, K, *I = list(map(int, open(0).read().split()))
A, F = array(I[:N], int64), array(I[N:], int64)
A.sort()
F.sort()
F = F[::-1]
sum_A = A.sum()
ng, ok = -1, 10 ** 12
while ng + 1 < ok:
mid = (ok + ng) // 2
if (sum_A - minimum(A, mid // F).sum()) <= K:
ok = mid
else:
ng = mid
print(ok)
if __name__ == '__main__':
main()
| from numpy import array, int64, minimum
from sys import stdin
def main():
input = stdin.buffer.readline
N, K = list(map(int, input().split()))
A, F = array(input().split(), int64), array(input().split(), int64)
A.sort()
F.sort()
F = F[::-1]
sum_A = A.sum()
ng, ok = -1, 10 ** 12
while ng + 1 < ok:
mid = (ok + ng) // 2
if (sum_A - minimum(A, mid // F).sum()) <= K:
ok = mid
else:
ng = mid
print(ok)
if __name__ == '__main__':
main()
| 25 | 28 | 485 | 554 | from numpy import array, int64, minimum
def main():
N, K, *I = list(map(int, open(0).read().split()))
A, F = array(I[:N], int64), array(I[N:], int64)
A.sort()
F.sort()
F = F[::-1]
sum_A = A.sum()
ng, ok = -1, 10**12
while ng + 1 < ok:
mid = (ok + ng) // 2
if (sum_A - minimum(A, mid // F).sum()) <= K:
ok = mid
else:
ng = mid
print(ok)
if __name__ == "__main__":
main()
| from numpy import array, int64, minimum
from sys import stdin
def main():
input = stdin.buffer.readline
N, K = list(map(int, input().split()))
A, F = array(input().split(), int64), array(input().split(), int64)
A.sort()
F.sort()
F = F[::-1]
sum_A = A.sum()
ng, ok = -1, 10**12
while ng + 1 < ok:
mid = (ok + ng) // 2
if (sum_A - minimum(A, mid // F).sum()) <= K:
ok = mid
else:
ng = mid
print(ok)
if __name__ == "__main__":
main()
| false | 10.714286 | [
"+from sys import stdin",
"- N, K, *I = list(map(int, open(0).read().split()))",
"- A, F = array(I[:N], int64), array(I[N:], int64)",
"+ input = stdin.buffer.readline",
"+ N, K = list(map(int, input().split()))",
"+ A, F = array(input().split(), int64), array(input().split(), int64)"
] | false | 0.37376 | 0.657227 | 0.568692 | [
"s556818631",
"s666836472"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.