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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
u729133443
|
p02873
|
python
|
s596672085
|
s793014217
| 371 | 311 | 22,308 | 8,220 |
Accepted
|
Accepted
| 16.17 |
from itertools import*
g=[(c>'<',len(list(m)))for c,m in groupby(eval(input()))]
n=len(g)
a=b=0
for i,(c,m)in enumerate(g):
a+=m*~-m//2+max(m,b)*c+m*(c^1)*(i>n-2)
b=m
print(a)
|
from itertools import*
a=b=0
for c,m in groupby(eval(input())):m=len(list(m));a+=m*-~m//2-min(m,b)*(c>'<');b=m
print(a)
| 8 | 4 | 180 | 116 |
from itertools import *
g = [(c > "<", len(list(m))) for c, m in groupby(eval(input()))]
n = len(g)
a = b = 0
for i, (c, m) in enumerate(g):
a += m * ~-m // 2 + max(m, b) * c + m * (c ^ 1) * (i > n - 2)
b = m
print(a)
|
from itertools import *
a = b = 0
for c, m in groupby(eval(input())):
m = len(list(m))
a += m * -~m // 2 - min(m, b) * (c > "<")
b = m
print(a)
| false | 50 |
[
"-g = [(c > \"<\", len(list(m))) for c, m in groupby(eval(input()))]",
"-n = len(g)",
"-for i, (c, m) in enumerate(g):",
"- a += m * ~-m // 2 + max(m, b) * c + m * (c ^ 1) * (i > n - 2)",
"+for c, m in groupby(eval(input())):",
"+ m = len(list(m))",
"+ a += m * -~m // 2 - min(m, b) * (c > \"<\")"
] | false | 0.103347 | 0.089257 | 1.157854 |
[
"s596672085",
"s793014217"
] |
u891635666
|
p02793
|
python
|
s642993086
|
s597786270
| 1,299 | 302 | 313,068 | 4,852 |
Accepted
|
Accepted
| 76.75 |
import collections
import sys
input = sys.stdin.readline
ri = lambda: int(eval(input()))
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]
def factorize_all(n):
factorizations = [None] * (n + 1)
factorizations[0] = dict()
factorizations[1] = dict()
for p in range(2, n + 1):
if factorizations[p] is None:
for k in range(1, n // p + 1):
if factorizations[k] is None:
continue
fs = factorizations[k].copy()
if p in fs:
fs[p] += 1
else:
fs[p] = 1
factorizations[k * p] = fs
return factorizations
MOD = 10**9 + 7
n = ri()
ls = ril()
if n == 1:
print((1))
exit()
factorizations = factorize_all(max(ls))
lcm = collections.Counter()
for x in ls:
counter = factorizations[x]
for p, k in list(counter.items()):
lcm[p] = max(lcm[p], k)
lcm_val = 1
for p, k in list(lcm.items()):
lcm_val *= pow(p, k, MOD)
lcm_val %= MOD
res = 0
for x in ls:
res += lcm_val * pow(x, MOD - 2, MOD)
res %= MOD
print(res)
|
import collections
import sys
input = sys.stdin.readline
ri = lambda: int(eval(input()))
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]
def eratosthenes(n):
sieve = [True for _ in range(n + 1)]
sieve[0] = False
sieve[1] = False
def _update(p):
if sieve[p]:
for i in range(p * 2, n + 1, p):
sieve[i] = False
if n > 1:
_update(2)
p = 3
while p * p <= n:
_update(p)
p += 2
return sieve
def factorize(n, primes):
import collections
if n < 2:
return dict()
counter = collections.Counter()
for p in primes:
while n % p == 0:
counter[p] += 1
n //= p
if n == 1:
break
if n > 1:
counter[n] += 1
return counter
MOD = 10**9 + 7
n = ri()
ls = ril()
if n == 1:
print((1))
exit()
sieve = eratosthenes(10**3)
primes = [x for x, b in enumerate(sieve) if b]
lcm = collections.Counter()
for x in ls:
counter = factorize(x, primes)
for p, k in list(counter.items()):
lcm[p] = max(lcm[p], k)
lcm_val = 1
for p, k in list(lcm.items()):
lcm_val *= pow(p, k, MOD)
lcm_val %= MOD
res = 0
for x in ls:
res += lcm_val * pow(x, MOD - 2, MOD)
res %= MOD
print(res)
| 58 | 76 | 1,390 | 1,565 |
import collections
import sys
input = sys.stdin.readline
ri = lambda: int(eval(input()))
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]
def factorize_all(n):
factorizations = [None] * (n + 1)
factorizations[0] = dict()
factorizations[1] = dict()
for p in range(2, n + 1):
if factorizations[p] is None:
for k in range(1, n // p + 1):
if factorizations[k] is None:
continue
fs = factorizations[k].copy()
if p in fs:
fs[p] += 1
else:
fs[p] = 1
factorizations[k * p] = fs
return factorizations
MOD = 10**9 + 7
n = ri()
ls = ril()
if n == 1:
print((1))
exit()
factorizations = factorize_all(max(ls))
lcm = collections.Counter()
for x in ls:
counter = factorizations[x]
for p, k in list(counter.items()):
lcm[p] = max(lcm[p], k)
lcm_val = 1
for p, k in list(lcm.items()):
lcm_val *= pow(p, k, MOD)
lcm_val %= MOD
res = 0
for x in ls:
res += lcm_val * pow(x, MOD - 2, MOD)
res %= MOD
print(res)
|
import collections
import sys
input = sys.stdin.readline
ri = lambda: int(eval(input()))
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]
def eratosthenes(n):
sieve = [True for _ in range(n + 1)]
sieve[0] = False
sieve[1] = False
def _update(p):
if sieve[p]:
for i in range(p * 2, n + 1, p):
sieve[i] = False
if n > 1:
_update(2)
p = 3
while p * p <= n:
_update(p)
p += 2
return sieve
def factorize(n, primes):
import collections
if n < 2:
return dict()
counter = collections.Counter()
for p in primes:
while n % p == 0:
counter[p] += 1
n //= p
if n == 1:
break
if n > 1:
counter[n] += 1
return counter
MOD = 10**9 + 7
n = ri()
ls = ril()
if n == 1:
print((1))
exit()
sieve = eratosthenes(10**3)
primes = [x for x, b in enumerate(sieve) if b]
lcm = collections.Counter()
for x in ls:
counter = factorize(x, primes)
for p, k in list(counter.items()):
lcm[p] = max(lcm[p], k)
lcm_val = 1
for p, k in list(lcm.items()):
lcm_val *= pow(p, k, MOD)
lcm_val %= MOD
res = 0
for x in ls:
res += lcm_val * pow(x, MOD - 2, MOD)
res %= MOD
print(res)
| false | 23.684211 |
[
"-def factorize_all(n):",
"- factorizations = [None] * (n + 1)",
"- factorizations[0] = dict()",
"- factorizations[1] = dict()",
"- for p in range(2, n + 1):",
"- if factorizations[p] is None:",
"- for k in range(1, n // p + 1):",
"- if factorizations[k] is None:",
"- continue",
"- fs = factorizations[k].copy()",
"- if p in fs:",
"- fs[p] += 1",
"- else:",
"- fs[p] = 1",
"- factorizations[k * p] = fs",
"- return factorizations",
"+def eratosthenes(n):",
"+ sieve = [True for _ in range(n + 1)]",
"+ sieve[0] = False",
"+ sieve[1] = False",
"+",
"+ def _update(p):",
"+ if sieve[p]:",
"+ for i in range(p * 2, n + 1, p):",
"+ sieve[i] = False",
"+",
"+ if n > 1:",
"+ _update(2)",
"+ p = 3",
"+ while p * p <= n:",
"+ _update(p)",
"+ p += 2",
"+ return sieve",
"+",
"+",
"+def factorize(n, primes):",
"+ import collections",
"+",
"+ if n < 2:",
"+ return dict()",
"+ counter = collections.Counter()",
"+ for p in primes:",
"+ while n % p == 0:",
"+ counter[p] += 1",
"+ n //= p",
"+ if n == 1:",
"+ break",
"+ if n > 1:",
"+ counter[n] += 1",
"+ return counter",
"-factorizations = factorize_all(max(ls))",
"+sieve = eratosthenes(10**3)",
"+primes = [x for x, b in enumerate(sieve) if b]",
"- counter = factorizations[x]",
"+ counter = factorize(x, primes)"
] | false | 0.547684 | 0.049188 | 11.134424 |
[
"s642993086",
"s597786270"
] |
u467736898
|
p02670
|
python
|
s137359451
|
s185250156
| 1,726 | 1,469 | 122,220 | 122,080 |
Accepted
|
Accepted
| 14.89 |
import numba
import numpy as np
N = int(eval(input()))
P = np.array([int(c)-1 for c in input().split()])
#from random import shuffle
#N = 500
#P = list(range(N*N))
#shuffle(P)
#P = np.array(P)
@numba.njit("i8(i8,i8[:])")
def proc(N, P):
ans = 0
Removed = np.zeros((500, 500), dtype=np.int8)
Mat = np.zeros((500, 500), dtype=np.int16)
Dy, Dx = [1,0,-1,0], [0,1,0,-1]
for y in range(N):
for x in range(N):
Mat[y, x] = min(y, N-1-y, x, N-1-x)
#print(Mat)
for i in range(N*N):
p = P[i]
y, x = divmod(p, N)
ans += Mat[y,x]
Removed[y,x] = 1
st = [(y, x)]
while st:
vy, vx = st.pop()
vr = Removed[vy,vx]
val = Mat[vy,vx]
#for dy, dx in zip(Dy, Dx):
for j in range(4):
uy, ux = vy + Dy[j], vx + Dx[j]
if not (0<=uy<N and 0<=ux<N):
continue
ur = Removed[uy,ux]
if vr:
if Mat[uy,ux] >= val+1:
Mat[uy,ux] = val
st.append((uy, ux))
else:
if Mat[uy,ux] >= val+2:
Mat[uy,ux] = val+1
st.append((uy, ux))
# for m in Mat:
# print(m)
return ans
print((proc(N, P)))
|
import numba
import numpy as np
N = int(eval(input()))
P = np.array([int(c)-1 for c in input().split()])
#from random import shuffle
#N = 500
#P = list(range(N*N))
#shuffle(P)
#P = np.array(P)
@numba.njit("i8(i8,i8[:])")
def proc(N, P):
ans = 0
Removed = np.zeros((500, 500), dtype=np.int8)
Mat = np.zeros((500, 500), dtype=np.int16)
Dy, Dx = [1,0,-1,0], [0,1,0,-1]
for y in range(N):
for x in range(N):
Mat[y, x] = min(y, N-1-y, x, N-1-x)
#print(Mat)
Buf = [(0, 0) for _ in range(1<<17)]
Buf_idx = 0
for i in range(N*N):
p = P[i]
y, x = divmod(p, N)
ans += Mat[y,x]
Removed[y,x] = 1
Buf[Buf_idx] = (y, x)
Buf_idx += 1
while Buf_idx:
Buf_idx -= 1
vy, vx = Buf[Buf_idx]
vr = Removed[vy,vx]
val = Mat[vy,vx]
#for dy, dx in zip(Dy, Dx):
for j in range(4):
uy, ux = vy + Dy[j], vx + Dx[j]
if not (0<=uy<N and 0<=ux<N):
continue
ur = Removed[uy,ux]
if vr:
if Mat[uy,ux] >= val+1:
Mat[uy,ux] = val
Buf[Buf_idx] = (uy, ux)
Buf_idx += 1
else:
if Mat[uy,ux] >= val+2:
Mat[uy,ux] = val+1
Buf[Buf_idx] = (uy, ux)
Buf_idx += 1
# for m in Mat:
# print(m)
return ans
print((proc(N, P)))
| 51 | 57 | 1,401 | 1,609 |
import numba
import numpy as np
N = int(eval(input()))
P = np.array([int(c) - 1 for c in input().split()])
# from random import shuffle
# N = 500
# P = list(range(N*N))
# shuffle(P)
# P = np.array(P)
@numba.njit("i8(i8,i8[:])")
def proc(N, P):
ans = 0
Removed = np.zeros((500, 500), dtype=np.int8)
Mat = np.zeros((500, 500), dtype=np.int16)
Dy, Dx = [1, 0, -1, 0], [0, 1, 0, -1]
for y in range(N):
for x in range(N):
Mat[y, x] = min(y, N - 1 - y, x, N - 1 - x)
# print(Mat)
for i in range(N * N):
p = P[i]
y, x = divmod(p, N)
ans += Mat[y, x]
Removed[y, x] = 1
st = [(y, x)]
while st:
vy, vx = st.pop()
vr = Removed[vy, vx]
val = Mat[vy, vx]
# for dy, dx in zip(Dy, Dx):
for j in range(4):
uy, ux = vy + Dy[j], vx + Dx[j]
if not (0 <= uy < N and 0 <= ux < N):
continue
ur = Removed[uy, ux]
if vr:
if Mat[uy, ux] >= val + 1:
Mat[uy, ux] = val
st.append((uy, ux))
else:
if Mat[uy, ux] >= val + 2:
Mat[uy, ux] = val + 1
st.append((uy, ux))
# for m in Mat:
# print(m)
return ans
print((proc(N, P)))
|
import numba
import numpy as np
N = int(eval(input()))
P = np.array([int(c) - 1 for c in input().split()])
# from random import shuffle
# N = 500
# P = list(range(N*N))
# shuffle(P)
# P = np.array(P)
@numba.njit("i8(i8,i8[:])")
def proc(N, P):
ans = 0
Removed = np.zeros((500, 500), dtype=np.int8)
Mat = np.zeros((500, 500), dtype=np.int16)
Dy, Dx = [1, 0, -1, 0], [0, 1, 0, -1]
for y in range(N):
for x in range(N):
Mat[y, x] = min(y, N - 1 - y, x, N - 1 - x)
# print(Mat)
Buf = [(0, 0) for _ in range(1 << 17)]
Buf_idx = 0
for i in range(N * N):
p = P[i]
y, x = divmod(p, N)
ans += Mat[y, x]
Removed[y, x] = 1
Buf[Buf_idx] = (y, x)
Buf_idx += 1
while Buf_idx:
Buf_idx -= 1
vy, vx = Buf[Buf_idx]
vr = Removed[vy, vx]
val = Mat[vy, vx]
# for dy, dx in zip(Dy, Dx):
for j in range(4):
uy, ux = vy + Dy[j], vx + Dx[j]
if not (0 <= uy < N and 0 <= ux < N):
continue
ur = Removed[uy, ux]
if vr:
if Mat[uy, ux] >= val + 1:
Mat[uy, ux] = val
Buf[Buf_idx] = (uy, ux)
Buf_idx += 1
else:
if Mat[uy, ux] >= val + 2:
Mat[uy, ux] = val + 1
Buf[Buf_idx] = (uy, ux)
Buf_idx += 1
# for m in Mat:
# print(m)
return ans
print((proc(N, P)))
| false | 10.526316 |
[
"+ Buf = [(0, 0) for _ in range(1 << 17)]",
"+ Buf_idx = 0",
"- st = [(y, x)]",
"- while st:",
"- vy, vx = st.pop()",
"+ Buf[Buf_idx] = (y, x)",
"+ Buf_idx += 1",
"+ while Buf_idx:",
"+ Buf_idx -= 1",
"+ vy, vx = Buf[Buf_idx]",
"- st.append((uy, ux))",
"+ Buf[Buf_idx] = (uy, ux)",
"+ Buf_idx += 1",
"- st.append((uy, ux))",
"+ Buf[Buf_idx] = (uy, ux)",
"+ Buf_idx += 1"
] | false | 0.046197 | 0.044399 | 1.040504 |
[
"s137359451",
"s185250156"
] |
u707498674
|
p02837
|
python
|
s105116339
|
s462313694
| 352 | 178 | 49,496 | 3,064 |
Accepted
|
Accepted
| 49.43 |
import sys
sys.setrecursionlimit(10**9)
N = int(eval(input()))
A = [[] for i in range(N)]
def check(target):
one_count = 0
cans = 0
for idx, flag in enumerate(target):
if flag == "1":
one_count += 1
for x, y in A[idx]:
if int(target[x]) != y:
return 0
cans = max(cans, one_count)
return cans
def dns(S):
ans = 0
if len(S) == N:
ans = max(ans, check(S))
else:
ans = max(dns(S+"0"), dns(S+"1"))
return ans
for i in range(N):
m = int(eval(input()))
for j in range(m):
x, y = list(map(int, input().split()))
x -= 1
A[i].append((x, y))
kotae = dns("")
print(kotae)
|
import sys
def input() : return sys.stdin.readline().strip()
def main():
ans = 0
N = int(eval(input()))
test = []
for _ in range(N):
A = int(eval(input()))
temp = [tuple(map(int, input().split())) for _ in range(A)]
test.append(temp)
# bit full search
print()
for bit in range(1<<N):
isOK = True
for i in range(N):
if bit & (1<<i):
for j, flag in test[i]:
j -= 1
if flag ^ ((bit>>j) & 1):
isOK = False
break
if isOK:
ans = max(ans, bin(bit).count("1"))
print(ans)
if __name__ == "__main__":
main()
| 37 | 31 | 744 | 753 |
import sys
sys.setrecursionlimit(10**9)
N = int(eval(input()))
A = [[] for i in range(N)]
def check(target):
one_count = 0
cans = 0
for idx, flag in enumerate(target):
if flag == "1":
one_count += 1
for x, y in A[idx]:
if int(target[x]) != y:
return 0
cans = max(cans, one_count)
return cans
def dns(S):
ans = 0
if len(S) == N:
ans = max(ans, check(S))
else:
ans = max(dns(S + "0"), dns(S + "1"))
return ans
for i in range(N):
m = int(eval(input()))
for j in range(m):
x, y = list(map(int, input().split()))
x -= 1
A[i].append((x, y))
kotae = dns("")
print(kotae)
|
import sys
def input():
return sys.stdin.readline().strip()
def main():
ans = 0
N = int(eval(input()))
test = []
for _ in range(N):
A = int(eval(input()))
temp = [tuple(map(int, input().split())) for _ in range(A)]
test.append(temp)
# bit full search
print()
for bit in range(1 << N):
isOK = True
for i in range(N):
if bit & (1 << i):
for j, flag in test[i]:
j -= 1
if flag ^ ((bit >> j) & 1):
isOK = False
break
if isOK:
ans = max(ans, bin(bit).count("1"))
print(ans)
if __name__ == "__main__":
main()
| false | 16.216216 |
[
"-sys.setrecursionlimit(10**9)",
"-N = int(eval(input()))",
"-A = [[] for i in range(N)]",
"+",
"+def input():",
"+ return sys.stdin.readline().strip()",
"-def check(target):",
"- one_count = 0",
"- cans = 0",
"- for idx, flag in enumerate(target):",
"- if flag == \"1\":",
"- one_count += 1",
"- for x, y in A[idx]:",
"- if int(target[x]) != y:",
"- return 0",
"- cans = max(cans, one_count)",
"- return cans",
"+def main():",
"+ ans = 0",
"+ N = int(eval(input()))",
"+ test = []",
"+ for _ in range(N):",
"+ A = int(eval(input()))",
"+ temp = [tuple(map(int, input().split())) for _ in range(A)]",
"+ test.append(temp)",
"+ # bit full search",
"+ print()",
"+ for bit in range(1 << N):",
"+ isOK = True",
"+ for i in range(N):",
"+ if bit & (1 << i):",
"+ for j, flag in test[i]:",
"+ j -= 1",
"+ if flag ^ ((bit >> j) & 1):",
"+ isOK = False",
"+ break",
"+ if isOK:",
"+ ans = max(ans, bin(bit).count(\"1\"))",
"+ print(ans)",
"-def dns(S):",
"- ans = 0",
"- if len(S) == N:",
"- ans = max(ans, check(S))",
"- else:",
"- ans = max(dns(S + \"0\"), dns(S + \"1\"))",
"- return ans",
"-",
"-",
"-for i in range(N):",
"- m = int(eval(input()))",
"- for j in range(m):",
"- x, y = list(map(int, input().split()))",
"- x -= 1",
"- A[i].append((x, y))",
"-kotae = dns(\"\")",
"-print(kotae)",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.049059 | 0.087508 | 0.56063 |
[
"s105116339",
"s462313694"
] |
u941753895
|
p02820
|
python
|
s239153744
|
s314855842
| 244 | 199 | 11,252 | 18,552 |
Accepted
|
Accepted
| 18.44 |
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy
sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return eval(input())
def main():
n,k=LI()
r,s,p=LI()
t=S()
dp=[[0 for _ in range(n+1)]for __ in range(3)]
for i in range(n):
hyoka=t[i]
dp[0][i+1]=max(dp[0][i],dp[1][i],dp[2][i])
dp[1][i+1]=max(dp[0][i],dp[1][i],dp[2][i])
dp[2][i+1]=max(dp[0][i],dp[1][i],dp[2][i])
if i-k<0:
if hyoka=='s':
dp[0][i+1]+=r
elif hyoka=='p':
dp[1][i+1]+=s
else:
dp[2][i+1]+=p
else:
if hyoka=='s':
if not (dp[0][i+1-k]>dp[1][i+1-k] and dp[0][i+1-k]>dp[2][i+1-k]):
dp[0][i+1]+=r
elif hyoka=='p':
if not (dp[1][i+1-k]>dp[2][i+1-k] and dp[1][i+1-k]>dp[0][i+1-k]):
dp[1][i+1]+=s
else:
if not (dp[2][i+1-k]>dp[0][i+1-k] and dp[2][i+1-k]>dp[1][i+1-k]):
dp[2][i+1]+=p
# for x in dp:
# print(x)
return max(dp[0][n],dp[1][n],dp[2][n])
# main()
print((main()))
|
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy
sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return eval(input())
def main():
n,k=LI()
r,s,p=LI()
t=S()
dp=[[0]*3 for _ in range(n+1)]
for i in range(n):
a=t[i]
b=max(dp[i])
for j in range(3):
dp[i+1][j]=b
if i+1<=k:
if a=='r':
dp[i+1][2]+=p
elif a=='s':
dp[i+1][0]+=r
else:
dp[i+1][1]+=s
else:
_a,_b,_c=dp[i+1-k]
if a=='r':
if not (_c>_a and _c>_b):
dp[i+1][2]+=p
elif a=='s':
if not (_a>_b and _a>_c):
dp[i+1][0]+=r
else:
if not (_b>_a and _b>_c):
dp[i+1][1]+=s
# print(dp)
return max(dp[n])
# main()
print((main()))
| 53 | 51 | 1,412 | 1,169 |
import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, queue, copy
sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI():
return [int(x) for x in sys.stdin.readline().split()]
def LI_():
return [int(x) - 1 for x in sys.stdin.readline().split()]
def I():
return int(sys.stdin.readline())
def LS():
return sys.stdin.readline().split()
def S():
return eval(input())
def main():
n, k = LI()
r, s, p = LI()
t = S()
dp = [[0 for _ in range(n + 1)] for __ in range(3)]
for i in range(n):
hyoka = t[i]
dp[0][i + 1] = max(dp[0][i], dp[1][i], dp[2][i])
dp[1][i + 1] = max(dp[0][i], dp[1][i], dp[2][i])
dp[2][i + 1] = max(dp[0][i], dp[1][i], dp[2][i])
if i - k < 0:
if hyoka == "s":
dp[0][i + 1] += r
elif hyoka == "p":
dp[1][i + 1] += s
else:
dp[2][i + 1] += p
else:
if hyoka == "s":
if not (
dp[0][i + 1 - k] > dp[1][i + 1 - k]
and dp[0][i + 1 - k] > dp[2][i + 1 - k]
):
dp[0][i + 1] += r
elif hyoka == "p":
if not (
dp[1][i + 1 - k] > dp[2][i + 1 - k]
and dp[1][i + 1 - k] > dp[0][i + 1 - k]
):
dp[1][i + 1] += s
else:
if not (
dp[2][i + 1 - k] > dp[0][i + 1 - k]
and dp[2][i + 1 - k] > dp[1][i + 1 - k]
):
dp[2][i + 1] += p
# for x in dp:
# print(x)
return max(dp[0][n], dp[1][n], dp[2][n])
# main()
print((main()))
|
import math, itertools, fractions, heapq, collections, bisect, sys, queue, copy
sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI():
return [int(x) for x in sys.stdin.readline().split()]
def LF():
return [float(x) for x in sys.stdin.readline().split()]
def I():
return int(sys.stdin.readline())
def F():
return float(sys.stdin.readline())
def LS():
return sys.stdin.readline().split()
def S():
return eval(input())
def main():
n, k = LI()
r, s, p = LI()
t = S()
dp = [[0] * 3 for _ in range(n + 1)]
for i in range(n):
a = t[i]
b = max(dp[i])
for j in range(3):
dp[i + 1][j] = b
if i + 1 <= k:
if a == "r":
dp[i + 1][2] += p
elif a == "s":
dp[i + 1][0] += r
else:
dp[i + 1][1] += s
else:
_a, _b, _c = dp[i + 1 - k]
if a == "r":
if not (_c > _a and _c > _b):
dp[i + 1][2] += p
elif a == "s":
if not (_a > _b and _a > _c):
dp[i + 1][0] += r
else:
if not (_b > _a and _b > _c):
dp[i + 1][1] += s
# print(dp)
return max(dp[n])
# main()
print((main()))
| false | 3.773585 |
[
"-import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, queue, copy",
"+import math, itertools, fractions, heapq, collections, bisect, sys, queue, copy",
"-def LI_():",
"- return [int(x) - 1 for x in sys.stdin.readline().split()]",
"+def LF():",
"+ return [float(x) for x in sys.stdin.readline().split()]",
"+",
"+",
"+def F():",
"+ return float(sys.stdin.readline())",
"- dp = [[0 for _ in range(n + 1)] for __ in range(3)]",
"+ dp = [[0] * 3 for _ in range(n + 1)]",
"- hyoka = t[i]",
"- dp[0][i + 1] = max(dp[0][i], dp[1][i], dp[2][i])",
"- dp[1][i + 1] = max(dp[0][i], dp[1][i], dp[2][i])",
"- dp[2][i + 1] = max(dp[0][i], dp[1][i], dp[2][i])",
"- if i - k < 0:",
"- if hyoka == \"s\":",
"- dp[0][i + 1] += r",
"- elif hyoka == \"p\":",
"- dp[1][i + 1] += s",
"+ a = t[i]",
"+ b = max(dp[i])",
"+ for j in range(3):",
"+ dp[i + 1][j] = b",
"+ if i + 1 <= k:",
"+ if a == \"r\":",
"+ dp[i + 1][2] += p",
"+ elif a == \"s\":",
"+ dp[i + 1][0] += r",
"- dp[2][i + 1] += p",
"+ dp[i + 1][1] += s",
"- if hyoka == \"s\":",
"- if not (",
"- dp[0][i + 1 - k] > dp[1][i + 1 - k]",
"- and dp[0][i + 1 - k] > dp[2][i + 1 - k]",
"- ):",
"- dp[0][i + 1] += r",
"- elif hyoka == \"p\":",
"- if not (",
"- dp[1][i + 1 - k] > dp[2][i + 1 - k]",
"- and dp[1][i + 1 - k] > dp[0][i + 1 - k]",
"- ):",
"- dp[1][i + 1] += s",
"+ _a, _b, _c = dp[i + 1 - k]",
"+ if a == \"r\":",
"+ if not (_c > _a and _c > _b):",
"+ dp[i + 1][2] += p",
"+ elif a == \"s\":",
"+ if not (_a > _b and _a > _c):",
"+ dp[i + 1][0] += r",
"- if not (",
"- dp[2][i + 1 - k] > dp[0][i + 1 - k]",
"- and dp[2][i + 1 - k] > dp[1][i + 1 - k]",
"- ):",
"- dp[2][i + 1] += p",
"- # for x in dp:",
"- # print(x)",
"- return max(dp[0][n], dp[1][n], dp[2][n])",
"+ if not (_b > _a and _b > _c):",
"+ dp[i + 1][1] += s",
"+ # print(dp)",
"+ return max(dp[n])"
] | false | 0.039635 | 0.061233 | 0.647281 |
[
"s239153744",
"s314855842"
] |
u603577460
|
p02361
|
python
|
s111711831
|
s608021288
| 4,450 | 1,900 | 85,892 | 93,380 |
Accepted
|
Accepted
| 57.3 |
import sys
def bellmanford(G,s):
n = len(G)
dist = [float("inf") for i in range(n)]
dist[s]=0
for k in range(n):
flag = False
for u in range(n):
for v in range(len(G[u])):
if dist[G[u][v][0]]>dist[u]+G[u][v][1]:
dist[G[u][v][0]]=dist[u]+G[u][v][1]
flag = True
if(not flag):break
for k in dist:
if(k==float("inf")):print("INF")
else:print(k)
def main():
T =[int(x) for x in sys.stdin.readline().strip().split()]
V = T[0]
E = T[1]
s = T[2]
G = [[] for i in range(V)]
for i in range(E):
line = [int(x) for x in sys.stdin.readline().strip().split()]
G[line[0]].append((line[1],line[2]))
bellmanford(G,s)
main()
|
import sys
import heapq
def Dj(G,s):
n = len(G)
dist = [float("inf") for i in range(n)]
vis = [-1 for i in range(n)]
li = [(0,s)]
dist[s]=0
heapq.heapify(li)
while len(li):
d,u = heapq.heappop(li)
if vis[u]==1:
continue
vis[u]=1
for v in G[u]:
if dist[v[1]]>dist[u] + v[0]:
dist[v[1]] = dist[u] + v[0]
heapq.heappush(li,(dist[u] + v[0],v[1]))
return dist
def main():
T = [int(x) for x in sys.stdin.readline().strip().split()]
V = T[0]
E = T[1]
S = T[2]
G = [[] for i in range(V)]
for i in range(E):
line = [int(x) for x in sys.stdin.readline().strip().split()]
G[line[0]].append((line[2],line[1]))
for k in Dj(G,S):
if k ==float("inf"):print("INF")
else:print(k)
main()
| 33 | 40 | 877 | 929 |
import sys
def bellmanford(G, s):
n = len(G)
dist = [float("inf") for i in range(n)]
dist[s] = 0
for k in range(n):
flag = False
for u in range(n):
for v in range(len(G[u])):
if dist[G[u][v][0]] > dist[u] + G[u][v][1]:
dist[G[u][v][0]] = dist[u] + G[u][v][1]
flag = True
if not flag:
break
for k in dist:
if k == float("inf"):
print("INF")
else:
print(k)
def main():
T = [int(x) for x in sys.stdin.readline().strip().split()]
V = T[0]
E = T[1]
s = T[2]
G = [[] for i in range(V)]
for i in range(E):
line = [int(x) for x in sys.stdin.readline().strip().split()]
G[line[0]].append((line[1], line[2]))
bellmanford(G, s)
main()
|
import sys
import heapq
def Dj(G, s):
n = len(G)
dist = [float("inf") for i in range(n)]
vis = [-1 for i in range(n)]
li = [(0, s)]
dist[s] = 0
heapq.heapify(li)
while len(li):
d, u = heapq.heappop(li)
if vis[u] == 1:
continue
vis[u] = 1
for v in G[u]:
if dist[v[1]] > dist[u] + v[0]:
dist[v[1]] = dist[u] + v[0]
heapq.heappush(li, (dist[u] + v[0], v[1]))
return dist
def main():
T = [int(x) for x in sys.stdin.readline().strip().split()]
V = T[0]
E = T[1]
S = T[2]
G = [[] for i in range(V)]
for i in range(E):
line = [int(x) for x in sys.stdin.readline().strip().split()]
G[line[0]].append((line[2], line[1]))
for k in Dj(G, S):
if k == float("inf"):
print("INF")
else:
print(k)
main()
| false | 17.5 |
[
"+import heapq",
"-def bellmanford(G, s):",
"+def Dj(G, s):",
"+ vis = [-1 for i in range(n)]",
"+ li = [(0, s)]",
"- for k in range(n):",
"- flag = False",
"- for u in range(n):",
"- for v in range(len(G[u])):",
"- if dist[G[u][v][0]] > dist[u] + G[u][v][1]:",
"- dist[G[u][v][0]] = dist[u] + G[u][v][1]",
"- flag = True",
"- if not flag:",
"- break",
"- for k in dist:",
"+ heapq.heapify(li)",
"+ while len(li):",
"+ d, u = heapq.heappop(li)",
"+ if vis[u] == 1:",
"+ continue",
"+ vis[u] = 1",
"+ for v in G[u]:",
"+ if dist[v[1]] > dist[u] + v[0]:",
"+ dist[v[1]] = dist[u] + v[0]",
"+ heapq.heappush(li, (dist[u] + v[0], v[1]))",
"+ return dist",
"+",
"+",
"+def main():",
"+ T = [int(x) for x in sys.stdin.readline().strip().split()]",
"+ V = T[0]",
"+ E = T[1]",
"+ S = T[2]",
"+ G = [[] for i in range(V)]",
"+ for i in range(E):",
"+ line = [int(x) for x in sys.stdin.readline().strip().split()]",
"+ G[line[0]].append((line[2], line[1]))",
"+ for k in Dj(G, S):",
"-def main():",
"- T = [int(x) for x in sys.stdin.readline().strip().split()]",
"- V = T[0]",
"- E = T[1]",
"- s = T[2]",
"- G = [[] for i in range(V)]",
"- for i in range(E):",
"- line = [int(x) for x in sys.stdin.readline().strip().split()]",
"- G[line[0]].append((line[1], line[2]))",
"- bellmanford(G, s)",
"-",
"-"
] | false | 0.034482 | 0.112063 | 0.307703 |
[
"s111711831",
"s608021288"
] |
u351654473
|
p02771
|
python
|
s989253793
|
s951220610
| 24 | 16 | 3,316 | 3,060 |
Accepted
|
Accepted
| 33.33 |
A, B, C = list(map(int,input().split()))
if A ==B and B == C:
print('No')
elif B == C:
print('Yes')
elif A == C:
print('Yes')
elif A == B:
print('Yes')
else:
print('No')
|
A, B, C = list(map(int,input().split()))
if A == B == C:
print('No')
elif B == C:
print('Yes')
elif A == C:
print('Yes')
elif A == B:
print('Yes')
else:
print('No')
| 11 | 11 | 193 | 188 |
A, B, C = list(map(int, input().split()))
if A == B and B == C:
print("No")
elif B == C:
print("Yes")
elif A == C:
print("Yes")
elif A == B:
print("Yes")
else:
print("No")
|
A, B, C = list(map(int, input().split()))
if A == B == C:
print("No")
elif B == C:
print("Yes")
elif A == C:
print("Yes")
elif A == B:
print("Yes")
else:
print("No")
| false | 0 |
[
"-if A == B and B == C:",
"+if A == B == C:"
] | false | 0.044768 | 0.037176 | 1.204212 |
[
"s989253793",
"s951220610"
] |
u054514819
|
p02631
|
python
|
s387583631
|
s297866255
| 189 | 145 | 36,180 | 114,308 |
Accepted
|
Accepted
| 23.28 |
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return list(map(int, input().split()))
sys.setrecursionlimit(10**9)
from collections import Counter
N = int(eval(input()))
As = list(mapint())
cum = 0
for a in As:
cum^=a
A = []
for a in As:
ans = cum^a
A.append(str(ans))
print((' '.join(A)))
|
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return list(map(int, input().split()))
sys.setrecursionlimit(10**9)
N = int(eval(input()))
As = list(mapint())
ALL = 0
for a in As:
ALL ^= a
ans = [ALL^a for a in As]
print((*ans))
| 17 | 13 | 332 | 258 |
import sys
def input():
return sys.stdin.readline().strip()
def mapint():
return list(map(int, input().split()))
sys.setrecursionlimit(10**9)
from collections import Counter
N = int(eval(input()))
As = list(mapint())
cum = 0
for a in As:
cum ^= a
A = []
for a in As:
ans = cum ^ a
A.append(str(ans))
print((" ".join(A)))
|
import sys
def input():
return sys.stdin.readline().strip()
def mapint():
return list(map(int, input().split()))
sys.setrecursionlimit(10**9)
N = int(eval(input()))
As = list(mapint())
ALL = 0
for a in As:
ALL ^= a
ans = [ALL ^ a for a in As]
print((*ans))
| false | 23.529412 |
[
"-from collections import Counter",
"-",
"-cum = 0",
"+ALL = 0",
"- cum ^= a",
"-A = []",
"-for a in As:",
"- ans = cum ^ a",
"- A.append(str(ans))",
"-print((\" \".join(A)))",
"+ ALL ^= a",
"+ans = [ALL ^ a for a in As]",
"+print((*ans))"
] | false | 0.120957 | 0.036952 | 3.273385 |
[
"s387583631",
"s297866255"
] |
u279493135
|
p03164
|
python
|
s363674353
|
s284892894
| 519 | 175 | 113,488 | 15,344 |
Accepted
|
Accepted
| 66.28 |
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, islice
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
def ZIP(n): return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
N, W = MAP()
w, v = ZIP(N)
max_v = sum(v)
dp = [INF]*(max_v+1)
dp[0] = 0
for w, v in zip(w, v):
for i in range(max_v, -1, -1):
if i-v >= 0:
dp[i] = min(dp[i], dp[i-v]+w)
ans = 0
for i in range(len(dp)):
if dp[i] <= W:
ans = i
print(ans)
|
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, islice
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import numpy as np
def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
def ZIP(n): return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
N, W = MAP()
w, v = ZIP(N)
max_v = 0
dp = np.full(1000*N+1, 10**18, dtype=np.int64)
dp[0] = 0
for w, v in zip(w, v):
np.minimum(dp[v:max_v+v+1], dp[:max_v+1]+w, out=dp[v:max_v+v+1])
max_v += v
print((np.where(dp <= W)[0].max()))
| 34 | 30 | 1,024 | 1,022 |
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, islice
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input():
return sys.stdin.readline().strip()
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST():
return list(map(int, input().split()))
def ZIP(n):
return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10**9)
INF = float("inf")
N, W = MAP()
w, v = ZIP(N)
max_v = sum(v)
dp = [INF] * (max_v + 1)
dp[0] = 0
for w, v in zip(w, v):
for i in range(max_v, -1, -1):
if i - v >= 0:
dp[i] = min(dp[i], dp[i - v] + w)
ans = 0
for i in range(len(dp)):
if dp[i] <= W:
ans = i
print(ans)
|
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, islice
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import numpy as np
def input():
return sys.stdin.readline().strip()
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST():
return list(map(int, input().split()))
def ZIP(n):
return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10**9)
INF = float("inf")
N, W = MAP()
w, v = ZIP(N)
max_v = 0
dp = np.full(1000 * N + 1, 10**18, dtype=np.int64)
dp[0] = 0
for w, v in zip(w, v):
np.minimum(dp[v : max_v + v + 1], dp[: max_v + 1] + w, out=dp[v : max_v + v + 1])
max_v += v
print((np.where(dp <= W)[0].max()))
| false | 11.764706 |
[
"+import numpy as np",
"-max_v = sum(v)",
"-dp = [INF] * (max_v + 1)",
"+max_v = 0",
"+dp = np.full(1000 * N + 1, 10**18, dtype=np.int64)",
"- for i in range(max_v, -1, -1):",
"- if i - v >= 0:",
"- dp[i] = min(dp[i], dp[i - v] + w)",
"-ans = 0",
"-for i in range(len(dp)):",
"- if dp[i] <= W:",
"- ans = i",
"-print(ans)",
"+ np.minimum(dp[v : max_v + v + 1], dp[: max_v + 1] + w, out=dp[v : max_v + v + 1])",
"+ max_v += v",
"+print((np.where(dp <= W)[0].max()))"
] | false | 0.035842 | 0.21898 | 0.163678 |
[
"s363674353",
"s284892894"
] |
u037430802
|
p03828
|
python
|
s601290347
|
s178886569
| 24 | 22 | 3,316 | 3,064 |
Accepted
|
Accepted
| 8.33 |
def getPrimeFactorsList(num):
pn = 2 #素数は2から
pflist = [] #素因数のリスト
while pn * pn <= num: #√numまで調べる
while num % pn == 0: #現在の素数で割り切れる範囲でループ
num = num / pn
pflist.append(pn)
pn += 1 #割り切れなくなったら次の素数へ
if num > 1:
pflist.append(int(num))
return pflist
mod = (10 ** 9 + 7)
N = int(eval(input()))
ans = 0
pf_dict = {}
#素因数がキー、割れる回数を値として用意し、最後に約数の個数を求める
for i in range(2, N+1):
pflist = getPrimeFactorsList(i)
pfset = set(pflist)
for j in pfset:
if j in pf_dict:
pf_dict[j] += pflist.count(j)
else:
pf_dict[j] = pflist.count(j)
#count *= (pflist.count(j) + 1)
count = 1
for v in list(pf_dict.values()):
count *= (v + 1)
print((count % mod))
|
N = int(eval(input()))
prime_dict = {}
while N > 1:
pn = 2
tmp = N
while pn * pn <= tmp:
while tmp % pn == 0:
tmp = tmp / pn
prime_dict[pn] = prime_dict.get(pn, 0) + 1
pn += 1
if tmp > 1:
prime_dict[tmp] = prime_dict.get(tmp, 0) + 1
N -= 1
cnt = 1
for key in list(prime_dict.keys()):
cnt *= prime_dict[key]+1
print((cnt % (10**9+7)))
| 34 | 21 | 725 | 383 |
def getPrimeFactorsList(num):
pn = 2 # 素数は2から
pflist = [] # 素因数のリスト
while pn * pn <= num: # √numまで調べる
while num % pn == 0: # 現在の素数で割り切れる範囲でループ
num = num / pn
pflist.append(pn)
pn += 1 # 割り切れなくなったら次の素数へ
if num > 1:
pflist.append(int(num))
return pflist
mod = 10**9 + 7
N = int(eval(input()))
ans = 0
pf_dict = {}
# 素因数がキー、割れる回数を値として用意し、最後に約数の個数を求める
for i in range(2, N + 1):
pflist = getPrimeFactorsList(i)
pfset = set(pflist)
for j in pfset:
if j in pf_dict:
pf_dict[j] += pflist.count(j)
else:
pf_dict[j] = pflist.count(j)
# count *= (pflist.count(j) + 1)
count = 1
for v in list(pf_dict.values()):
count *= v + 1
print((count % mod))
|
N = int(eval(input()))
prime_dict = {}
while N > 1:
pn = 2
tmp = N
while pn * pn <= tmp:
while tmp % pn == 0:
tmp = tmp / pn
prime_dict[pn] = prime_dict.get(pn, 0) + 1
pn += 1
if tmp > 1:
prime_dict[tmp] = prime_dict.get(tmp, 0) + 1
N -= 1
cnt = 1
for key in list(prime_dict.keys()):
cnt *= prime_dict[key] + 1
print((cnt % (10**9 + 7)))
| false | 38.235294 |
[
"-def getPrimeFactorsList(num):",
"- pn = 2 # 素数は2から",
"- pflist = [] # 素因数のリスト",
"- while pn * pn <= num: # √numまで調べる",
"- while num % pn == 0: # 現在の素数で割り切れる範囲でループ",
"- num = num / pn",
"- pflist.append(pn)",
"- pn += 1 # 割り切れなくなったら次の素数へ",
"- if num > 1:",
"- pflist.append(int(num))",
"- return pflist",
"-",
"-",
"-mod = 10**9 + 7",
"-ans = 0",
"-pf_dict = {}",
"-# 素因数がキー、割れる回数を値として用意し、最後に約数の個数を求める",
"-for i in range(2, N + 1):",
"- pflist = getPrimeFactorsList(i)",
"- pfset = set(pflist)",
"- for j in pfset:",
"- if j in pf_dict:",
"- pf_dict[j] += pflist.count(j)",
"- else:",
"- pf_dict[j] = pflist.count(j)",
"- # count *= (pflist.count(j) + 1)",
"-count = 1",
"-for v in list(pf_dict.values()):",
"- count *= v + 1",
"-print((count % mod))",
"+prime_dict = {}",
"+while N > 1:",
"+ pn = 2",
"+ tmp = N",
"+ while pn * pn <= tmp:",
"+ while tmp % pn == 0:",
"+ tmp = tmp / pn",
"+ prime_dict[pn] = prime_dict.get(pn, 0) + 1",
"+ pn += 1",
"+ if tmp > 1:",
"+ prime_dict[tmp] = prime_dict.get(tmp, 0) + 1",
"+ N -= 1",
"+cnt = 1",
"+for key in list(prime_dict.keys()):",
"+ cnt *= prime_dict[key] + 1",
"+print((cnt % (10**9 + 7)))"
] | false | 0.047988 | 0.108425 | 0.442589 |
[
"s601290347",
"s178886569"
] |
u671060652
|
p03220
|
python
|
s127400813
|
s097284113
| 289 | 73 | 64,364 | 62,488 |
Accepted
|
Accepted
| 74.74 |
import itertools
import math
import fractions
import functools
import copy
n = int(eval(input()))
t, a = list(map(int, input().split()))
h = list(map(int, input().split()))
minimum = 10**10
index = 0
for i in range(n):
minimum = min(minimum,abs(a-(t-h[i]*0.006)))
if minimum == abs(a-(t-h[i]*0.006)):
index = i
print((index+1))
|
def main():
n = int(eval(input()))
t, a = list(map(int, input().split()))
h = list(map(int, input().split()))
# s = input()
mini = 10**10
ans = 0
for i, x in enumerate(h):
c = t - x * 0.006
if abs(a - c) < mini:
mini = abs(a - c)
ans = i+1
print(ans)
if __name__ == '__main__':
main()
| 16 | 19 | 346 | 371 |
import itertools
import math
import fractions
import functools
import copy
n = int(eval(input()))
t, a = list(map(int, input().split()))
h = list(map(int, input().split()))
minimum = 10**10
index = 0
for i in range(n):
minimum = min(minimum, abs(a - (t - h[i] * 0.006)))
if minimum == abs(a - (t - h[i] * 0.006)):
index = i
print((index + 1))
|
def main():
n = int(eval(input()))
t, a = list(map(int, input().split()))
h = list(map(int, input().split()))
# s = input()
mini = 10**10
ans = 0
for i, x in enumerate(h):
c = t - x * 0.006
if abs(a - c) < mini:
mini = abs(a - c)
ans = i + 1
print(ans)
if __name__ == "__main__":
main()
| false | 15.789474 |
[
"-import itertools",
"-import math",
"-import fractions",
"-import functools",
"-import copy",
"+def main():",
"+ n = int(eval(input()))",
"+ t, a = list(map(int, input().split()))",
"+ h = list(map(int, input().split()))",
"+ # s = input()",
"+ mini = 10**10",
"+ ans = 0",
"+ for i, x in enumerate(h):",
"+ c = t - x * 0.006",
"+ if abs(a - c) < mini:",
"+ mini = abs(a - c)",
"+ ans = i + 1",
"+ print(ans)",
"-n = int(eval(input()))",
"-t, a = list(map(int, input().split()))",
"-h = list(map(int, input().split()))",
"-minimum = 10**10",
"-index = 0",
"-for i in range(n):",
"- minimum = min(minimum, abs(a - (t - h[i] * 0.006)))",
"- if minimum == abs(a - (t - h[i] * 0.006)):",
"- index = i",
"-print((index + 1))",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.05439 | 0.05416 | 1.004246 |
[
"s127400813",
"s097284113"
] |
u887207211
|
p03721
|
python
|
s400226645
|
s018958505
| 489 | 268 | 28,640 | 29,096 |
Accepted
|
Accepted
| 45.19 |
N, K = list(map(int,input().split()))
AB = sorted([list(map(int,input().split())) for _ in range(N)])
tmp = 0
for a, b in AB:
if(tmp < K-b):
tmp += b
else:
print(a)
break
|
import sys
stdin = sys.stdin
ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))
def main():
n, k = na()
ab = [na() for _ in range(n)]
ab.sort(key = lambda x: x[0])
cnt = 0
for a, b in ab:
cnt += b
if cnt >= k:
print(a)
return
main()
| 10 | 20 | 190 | 353 |
N, K = list(map(int, input().split()))
AB = sorted([list(map(int, input().split())) for _ in range(N)])
tmp = 0
for a, b in AB:
if tmp < K - b:
tmp += b
else:
print(a)
break
|
import sys
stdin = sys.stdin
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
def main():
n, k = na()
ab = [na() for _ in range(n)]
ab.sort(key=lambda x: x[0])
cnt = 0
for a, b in ab:
cnt += b
if cnt >= k:
print(a)
return
main()
| false | 50 |
[
"-N, K = list(map(int, input().split()))",
"-AB = sorted([list(map(int, input().split())) for _ in range(N)])",
"-tmp = 0",
"-for a, b in AB:",
"- if tmp < K - b:",
"- tmp += b",
"- else:",
"- print(a)",
"- break",
"+import sys",
"+",
"+stdin = sys.stdin",
"+ns = lambda: stdin.readline().rstrip()",
"+ni = lambda: int(ns())",
"+na = lambda: list(map(int, stdin.readline().split()))",
"+",
"+",
"+def main():",
"+ n, k = na()",
"+ ab = [na() for _ in range(n)]",
"+ ab.sort(key=lambda x: x[0])",
"+ cnt = 0",
"+ for a, b in ab:",
"+ cnt += b",
"+ if cnt >= k:",
"+ print(a)",
"+ return",
"+",
"+",
"+main()"
] | false | 0.038405 | 0.038268 | 1.003583 |
[
"s400226645",
"s018958505"
] |
u721316601
|
p03013
|
python
|
s995051147
|
s005258309
| 1,672 | 185 | 462,728 | 6,900 |
Accepted
|
Accepted
| 88.94 |
N, M = list(map(int, input().split()))
a = [int(eval(input())) for i in range(M)] + [10**20]
dp = [1] + [0 for i in range(N+2)]
next_a = a.pop(0)
for i in range(N):
if next_a == i:
dp[i] = 0
next_a = a.pop(0)
else:
dp[i+1] += dp[i]
dp[i+2] += dp[i]
print((dp[N]%1000000007))
|
MOD = 1000000007
N, M = list(map(int, input().split()))
N += 1
dp = [0] * N
dp[0] = 1
for i in range(M):
a = int(eval(input()))
dp[a] = -1
for i in range(N):
if dp[i] == -1: continue
dp[i] %= MOD
if i+1 < N and dp[i+1] != -1: dp[i+1] += dp[i]
if i+2 < N and dp[i+2] != -1: dp[i+2] += dp[i]
print((dp[-1] % MOD))
| 15 | 20 | 324 | 355 |
N, M = list(map(int, input().split()))
a = [int(eval(input())) for i in range(M)] + [10**20]
dp = [1] + [0 for i in range(N + 2)]
next_a = a.pop(0)
for i in range(N):
if next_a == i:
dp[i] = 0
next_a = a.pop(0)
else:
dp[i + 1] += dp[i]
dp[i + 2] += dp[i]
print((dp[N] % 1000000007))
|
MOD = 1000000007
N, M = list(map(int, input().split()))
N += 1
dp = [0] * N
dp[0] = 1
for i in range(M):
a = int(eval(input()))
dp[a] = -1
for i in range(N):
if dp[i] == -1:
continue
dp[i] %= MOD
if i + 1 < N and dp[i + 1] != -1:
dp[i + 1] += dp[i]
if i + 2 < N and dp[i + 2] != -1:
dp[i + 2] += dp[i]
print((dp[-1] % MOD))
| false | 25 |
[
"+MOD = 1000000007",
"-a = [int(eval(input())) for i in range(M)] + [10**20]",
"-dp = [1] + [0 for i in range(N + 2)]",
"-next_a = a.pop(0)",
"+N += 1",
"+dp = [0] * N",
"+dp[0] = 1",
"+for i in range(M):",
"+ a = int(eval(input()))",
"+ dp[a] = -1",
"- if next_a == i:",
"- dp[i] = 0",
"- next_a = a.pop(0)",
"- else:",
"+ if dp[i] == -1:",
"+ continue",
"+ dp[i] %= MOD",
"+ if i + 1 < N and dp[i + 1] != -1:",
"+ if i + 2 < N and dp[i + 2] != -1:",
"-print((dp[N] % 1000000007))",
"+print((dp[-1] % MOD))"
] | false | 0.078457 | 0.037447 | 2.095153 |
[
"s995051147",
"s005258309"
] |
u583507988
|
p03325
|
python
|
s075420802
|
s014466461
| 82 | 64 | 10,024 | 10,124 |
Accepted
|
Accepted
| 21.95 |
n = int(eval(input()))
a = list(map(int, input().split()))
ans = 0
for i in range(n):
if a[i]%2==0:
while a[i]%2==0:
a[i] //= 2
ans += 1
print(ans)
|
n=int(eval(input()))
a=list(map(int,input().split()))
ans=0
for i in a:
while i%2==0:
i=i//2
ans+=1
print(ans)
| 12 | 9 | 183 | 125 |
n = int(eval(input()))
a = list(map(int, input().split()))
ans = 0
for i in range(n):
if a[i] % 2 == 0:
while a[i] % 2 == 0:
a[i] //= 2
ans += 1
print(ans)
|
n = int(eval(input()))
a = list(map(int, input().split()))
ans = 0
for i in a:
while i % 2 == 0:
i = i // 2
ans += 1
print(ans)
| false | 25 |
[
"-for i in range(n):",
"- if a[i] % 2 == 0:",
"- while a[i] % 2 == 0:",
"- a[i] //= 2",
"- ans += 1",
"+for i in a:",
"+ while i % 2 == 0:",
"+ i = i // 2",
"+ ans += 1"
] | false | 0.091218 | 0.087067 | 1.047676 |
[
"s075420802",
"s014466461"
] |
u316386814
|
p02998
|
python
|
s648892063
|
s789989513
| 1,825 | 501 | 193,868 | 114,524 |
Accepted
|
Accepted
| 72.55 |
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def YesNo(x): return 'Yes' if x else 'No'
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return eval(input())
from collections import defaultdict
def main():
N = II()
edges = defaultdict(list)
for _ in range(N):
x, y = LI()
edges[x].append(-y)
edges[-y].append(x)
visited = defaultdict(int)
if max(len(li) for li in list(edges.values())) == 2 and N >= 10 ** 4:
m, p = 0, 0
for k in list(edges.keys()):
if k < 0:
m += 1
else:
p += 1
return m * p - N
def solve(v):
visited[v] = 1
ret = [v]
for u in edges[v]:
if not visited[u]:
ret += solve(u)
return ret
ans = -N
for node in edges:
if not visited[node]:
li = solve(node)
m, p = 0, 0
for z in li:
if z < 0:
m += 1
else:
p += 1
ans += m * p
return ans
print((main()))
|
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def YesNo(x): return 'Yes' if x else 'No'
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return eval(input())
from collections import defaultdict
def main():
N = II()
xy = []
for _ in range(N):
xy.append(LI())
xy2g = defaultdict(int)
g2xy = defaultdict(set)
for x, y in xy:
y = -y
gx = xy2g[x]
gy = xy2g[y]
if gx == gy != 0:
continue
elif gx != 0 != gy: # merge
if len(g2xy[gx]) < len(g2xy[gy]):
gx, gy = gy, gx
for xy in g2xy[gy]:
xy2g[xy] = gx
g2xy[gx] |= g2xy[gy]
g2xy[gy].clear()
else:
g = gx or gy or x
xy2g[x] = xy2g[y] = g
g2xy[g] |= {x, y}
ans = -N
for xys in list(g2xy.values()):
nx = sum(xy > 0 for xy in xys)
ny = len(xys) - nx
ans += nx * ny
return ans
print((main()))
| 50 | 45 | 1,397 | 1,281 |
import sys
sys.setrecursionlimit(10**7)
INF = 10**18
MOD = 10**9 + 7
def YesNo(x):
return "Yes" if x else "No"
def LI():
return [int(x) for x in sys.stdin.readline().split()]
def LI_():
return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF():
return [float(x) for x in sys.stdin.readline().split()]
def LS():
return sys.stdin.readline().split()
def II():
return int(sys.stdin.readline())
def SI():
return eval(input())
from collections import defaultdict
def main():
N = II()
edges = defaultdict(list)
for _ in range(N):
x, y = LI()
edges[x].append(-y)
edges[-y].append(x)
visited = defaultdict(int)
if max(len(li) for li in list(edges.values())) == 2 and N >= 10**4:
m, p = 0, 0
for k in list(edges.keys()):
if k < 0:
m += 1
else:
p += 1
return m * p - N
def solve(v):
visited[v] = 1
ret = [v]
for u in edges[v]:
if not visited[u]:
ret += solve(u)
return ret
ans = -N
for node in edges:
if not visited[node]:
li = solve(node)
m, p = 0, 0
for z in li:
if z < 0:
m += 1
else:
p += 1
ans += m * p
return ans
print((main()))
|
import sys
sys.setrecursionlimit(10**7)
INF = 10**18
MOD = 10**9 + 7
def YesNo(x):
return "Yes" if x else "No"
def LI():
return [int(x) for x in sys.stdin.readline().split()]
def LI_():
return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF():
return [float(x) for x in sys.stdin.readline().split()]
def LS():
return sys.stdin.readline().split()
def II():
return int(sys.stdin.readline())
def SI():
return eval(input())
from collections import defaultdict
def main():
N = II()
xy = []
for _ in range(N):
xy.append(LI())
xy2g = defaultdict(int)
g2xy = defaultdict(set)
for x, y in xy:
y = -y
gx = xy2g[x]
gy = xy2g[y]
if gx == gy != 0:
continue
elif gx != 0 != gy: # merge
if len(g2xy[gx]) < len(g2xy[gy]):
gx, gy = gy, gx
for xy in g2xy[gy]:
xy2g[xy] = gx
g2xy[gx] |= g2xy[gy]
g2xy[gy].clear()
else:
g = gx or gy or x
xy2g[x] = xy2g[y] = g
g2xy[g] |= {x, y}
ans = -N
for xys in list(g2xy.values()):
nx = sum(xy > 0 for xy in xys)
ny = len(xys) - nx
ans += nx * ny
return ans
print((main()))
| false | 10 |
[
"- edges = defaultdict(list)",
"+ xy = []",
"- x, y = LI()",
"- edges[x].append(-y)",
"- edges[-y].append(x)",
"- visited = defaultdict(int)",
"- if max(len(li) for li in list(edges.values())) == 2 and N >= 10**4:",
"- m, p = 0, 0",
"- for k in list(edges.keys()):",
"- if k < 0:",
"- m += 1",
"- else:",
"- p += 1",
"- return m * p - N",
"-",
"- def solve(v):",
"- visited[v] = 1",
"- ret = [v]",
"- for u in edges[v]:",
"- if not visited[u]:",
"- ret += solve(u)",
"- return ret",
"-",
"+ xy.append(LI())",
"+ xy2g = defaultdict(int)",
"+ g2xy = defaultdict(set)",
"+ for x, y in xy:",
"+ y = -y",
"+ gx = xy2g[x]",
"+ gy = xy2g[y]",
"+ if gx == gy != 0:",
"+ continue",
"+ elif gx != 0 != gy: # merge",
"+ if len(g2xy[gx]) < len(g2xy[gy]):",
"+ gx, gy = gy, gx",
"+ for xy in g2xy[gy]:",
"+ xy2g[xy] = gx",
"+ g2xy[gx] |= g2xy[gy]",
"+ g2xy[gy].clear()",
"+ else:",
"+ g = gx or gy or x",
"+ xy2g[x] = xy2g[y] = g",
"+ g2xy[g] |= {x, y}",
"- for node in edges:",
"- if not visited[node]:",
"- li = solve(node)",
"- m, p = 0, 0",
"- for z in li:",
"- if z < 0:",
"- m += 1",
"- else:",
"- p += 1",
"- ans += m * p",
"+ for xys in list(g2xy.values()):",
"+ nx = sum(xy > 0 for xy in xys)",
"+ ny = len(xys) - nx",
"+ ans += nx * ny"
] | false | 0.032938 | 0.033403 | 0.986074 |
[
"s648892063",
"s789989513"
] |
u605879293
|
p02259
|
python
|
s425688256
|
s067168870
| 30 | 20 | 5,616 | 5,612 |
Accepted
|
Accepted
| 33.33 |
def show(array):
for i in range(len(array)):
if i != len(array) - 1:
print(array[i], end=' ')
else:
print(array[i])
def bubbleSort(array):
flag = True
count = 0
while flag:
flag = False
for j in sorted(range(1, len(array)), reverse=True):
if array[j] < array[j - 1]:
array[j], array[j - 1] = [array[j - 1], array[j]]
flag = True
count += 1
show(array)
return count
input()
array = [int(x) for x in input().split()]
print(bubbleSort(array))
|
def bubbleSort(array):
n = len(array)
cnt = 0
flag = True
while flag:
flag = False
for i in range(n-1, 0, -1):
if array[i-1] > array[i]:
array[i-1], array[i] = array[i], array[i-1]
flag = True
cnt += 1
return (array, cnt)
n = int(eval(input()))
array = [int(x) for x in input().split()]
resultArray, cnt = bubbleSort(array)
print((*resultArray))
print(cnt)
| 27 | 20 | 612 | 467 |
def show(array):
for i in range(len(array)):
if i != len(array) - 1:
print(array[i], end=" ")
else:
print(array[i])
def bubbleSort(array):
flag = True
count = 0
while flag:
flag = False
for j in sorted(range(1, len(array)), reverse=True):
if array[j] < array[j - 1]:
array[j], array[j - 1] = [array[j - 1], array[j]]
flag = True
count += 1
show(array)
return count
input()
array = [int(x) for x in input().split()]
print(bubbleSort(array))
|
def bubbleSort(array):
n = len(array)
cnt = 0
flag = True
while flag:
flag = False
for i in range(n - 1, 0, -1):
if array[i - 1] > array[i]:
array[i - 1], array[i] = array[i], array[i - 1]
flag = True
cnt += 1
return (array, cnt)
n = int(eval(input()))
array = [int(x) for x in input().split()]
resultArray, cnt = bubbleSort(array)
print((*resultArray))
print(cnt)
| false | 25.925926 |
[
"-def show(array):",
"- for i in range(len(array)):",
"- if i != len(array) - 1:",
"- print(array[i], end=\" \")",
"- else:",
"- print(array[i])",
"+def bubbleSort(array):",
"+ n = len(array)",
"+ cnt = 0",
"+ flag = True",
"+ while flag:",
"+ flag = False",
"+ for i in range(n - 1, 0, -1):",
"+ if array[i - 1] > array[i]:",
"+ array[i - 1], array[i] = array[i], array[i - 1]",
"+ flag = True",
"+ cnt += 1",
"+ return (array, cnt)",
"-def bubbleSort(array):",
"- flag = True",
"- count = 0",
"- while flag:",
"- flag = False",
"- for j in sorted(range(1, len(array)), reverse=True):",
"- if array[j] < array[j - 1]:",
"- array[j], array[j - 1] = [array[j - 1], array[j]]",
"- flag = True",
"- count += 1",
"- show(array)",
"- return count",
"-",
"-",
"-input()",
"+n = int(eval(input()))",
"-print(bubbleSort(array))",
"+resultArray, cnt = bubbleSort(array)",
"+print((*resultArray))",
"+print(cnt)"
] | false | 0.039417 | 0.039135 | 1.007221 |
[
"s425688256",
"s067168870"
] |
u863442865
|
p03078
|
python
|
s575596303
|
s507331378
| 745 | 329 | 105,356 | 54,232 |
Accepted
|
Accepted
| 55.84 |
#xyzの全通り調べると間に合わない
#まず問題を分けよう
#先にxyだけ考えてみる
#xyの和をとってからそれとzの和をとるとき
#xyの和においてk番目以降の値を使うことは無い
#
def main():
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
#from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby
#from itertools import product
from bisect import bisect_left,bisect_right
import heapq
from math import floor, ceil
#from operator import itemgetter
#inf = 10**17
#mod = 10**9 + 7
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=1)
b.sort(reverse=1)
c.sort(reverse=1)
abc = []
for i in range(x):
for j in range(y):
if i*j>k:
continue
for t in range(z):
if i*j*t>k:
continue
abc.append(a[i]+b[j]+c[t])
abc.sort(reverse=1)
for i in range(k):
print((abc[i]))
if __name__ == '__main__':
main()
|
def main():
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
#from collections import defaultdict
from itertools import combinations, permutations, accumulate
#from itertools import product
from bisect import bisect_left,bisect_right
import heapq
from math import floor, ceil
#from operator import itemgetter
#inf = 10**17
#mod = 10**9 + 7
x,y,z,n = 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=1)
b.sort(reverse=1)
c.sort(reverse=1)
res = []
hq = [[-(a[0]+b[0]+c[0]), 0, 0, 0]]
heapq.heapify(hq)
check = set([(0, 0, 0)])
for _ in range(n):
cost, i, j, k = heapq.heappop(hq)
res.append(-cost)
if i+1<x and not (i+1, j, k) in check:
heapq.heappush(hq, [-(a[i+1]+b[j]+c[k]), i+1, j, k])
check.add((i+1, j, k))
if j+1<y and not (i, j+1, k) in check:
heapq.heappush(hq, [-(a[i]+b[j+1]+c[k]), i, j+1, k])
check.add((i, j+1, k))
if k+1<z and not (i, j, k+1) in check:
heapq.heappush(hq, [-(a[i]+b[j]+c[k+1]), i, j, k+1])
check.add((i, j, k+1))
for i in res:
print(i)
if __name__ == '__main__':
main()
| 45 | 44 | 1,172 | 1,429 |
# xyzの全通り調べると間に合わない
# まず問題を分けよう
# 先にxyだけ考えてみる
# xyの和をとってからそれとzの和をとるとき
# xyの和においてk番目以降の値を使うことは無い
#
def main():
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
# from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby
# from itertools import product
from bisect import bisect_left, bisect_right
import heapq
from math import floor, ceil
# from operator import itemgetter
# inf = 10**17
# mod = 10**9 + 7
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=1)
b.sort(reverse=1)
c.sort(reverse=1)
abc = []
for i in range(x):
for j in range(y):
if i * j > k:
continue
for t in range(z):
if i * j * t > k:
continue
abc.append(a[i] + b[j] + c[t])
abc.sort(reverse=1)
for i in range(k):
print((abc[i]))
if __name__ == "__main__":
main()
|
def main():
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
# from collections import defaultdict
from itertools import combinations, permutations, accumulate
# from itertools import product
from bisect import bisect_left, bisect_right
import heapq
from math import floor, ceil
# from operator import itemgetter
# inf = 10**17
# mod = 10**9 + 7
x, y, z, n = 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=1)
b.sort(reverse=1)
c.sort(reverse=1)
res = []
hq = [[-(a[0] + b[0] + c[0]), 0, 0, 0]]
heapq.heapify(hq)
check = set([(0, 0, 0)])
for _ in range(n):
cost, i, j, k = heapq.heappop(hq)
res.append(-cost)
if i + 1 < x and not (i + 1, j, k) in check:
heapq.heappush(hq, [-(a[i + 1] + b[j] + c[k]), i + 1, j, k])
check.add((i + 1, j, k))
if j + 1 < y and not (i, j + 1, k) in check:
heapq.heappush(hq, [-(a[i] + b[j + 1] + c[k]), i, j + 1, k])
check.add((i, j + 1, k))
if k + 1 < z and not (i, j, k + 1) in check:
heapq.heappush(hq, [-(a[i] + b[j] + c[k + 1]), i, j, k + 1])
check.add((i, j, k + 1))
for i in res:
print(i)
if __name__ == "__main__":
main()
| false | 2.222222 |
[
"-# xyzの全通り調べると間に合わない",
"-# まず問題を分けよう",
"-# 先にxyだけ考えてみる",
"-# xyの和をとってからそれとzの和をとるとき",
"-# xyの和においてk番目以降の値を使うことは無い",
"-#",
"- from itertools import combinations, permutations, accumulate, groupby",
"+ from itertools import combinations, permutations, accumulate",
"- x, y, z, k = list(map(int, input().split()))",
"+ x, y, z, n = list(map(int, input().split()))",
"- abc = []",
"- for i in range(x):",
"- for j in range(y):",
"- if i * j > k:",
"- continue",
"- for t in range(z):",
"- if i * j * t > k:",
"- continue",
"- abc.append(a[i] + b[j] + c[t])",
"- abc.sort(reverse=1)",
"- for i in range(k):",
"- print((abc[i]))",
"+ res = []",
"+ hq = [[-(a[0] + b[0] + c[0]), 0, 0, 0]]",
"+ heapq.heapify(hq)",
"+ check = set([(0, 0, 0)])",
"+ for _ in range(n):",
"+ cost, i, j, k = heapq.heappop(hq)",
"+ res.append(-cost)",
"+ if i + 1 < x and not (i + 1, j, k) in check:",
"+ heapq.heappush(hq, [-(a[i + 1] + b[j] + c[k]), i + 1, j, k])",
"+ check.add((i + 1, j, k))",
"+ if j + 1 < y and not (i, j + 1, k) in check:",
"+ heapq.heappush(hq, [-(a[i] + b[j + 1] + c[k]), i, j + 1, k])",
"+ check.add((i, j + 1, k))",
"+ if k + 1 < z and not (i, j, k + 1) in check:",
"+ heapq.heappush(hq, [-(a[i] + b[j] + c[k + 1]), i, j, k + 1])",
"+ check.add((i, j, k + 1))",
"+ for i in res:",
"+ print(i)"
] | false | 0.041631 | 0.042662 | 0.975823 |
[
"s575596303",
"s507331378"
] |
u816488327
|
p02843
|
python
|
s842782207
|
s242741997
| 51 | 18 | 3,064 | 2,940 |
Accepted
|
Accepted
| 64.71 |
def solve():
X = int(eval(input()))
if X < 100:
return 0
upper1 = X // 100
for p1 in range(0, 100 * upper1 + 1, 100):
rest1 = X - p1
if rest1 == 0:
return 1
upper2 = rest1 // 101
for p2 in range(0, 101 * upper2 + 1, 101):
rest2 = rest1 - p2
if rest2 == 0:
return 1
upper3 = rest2 // 102
for p3 in range(0, 102 * upper3 + 1, 102):
rest3 = rest2 - p3
if rest3 == 0:
return 1
upper4 = rest3 // 103
for p4 in range(0, 103 * upper4 + 1, 103):
rest4 = rest3 - p4
if rest4 == 0:
return 1
upper5 = rest4 // 104
for p5 in range(0, 104 * upper5 + 1, 104):
rest5 = rest4 - p5
if rest5 == 0:
return 1
upper6 = rest5 // 105
for p6 in range(0, 105 * upper6 + 1, 105):
rest6 = rest5 - p6
if rest6 == 0:
return 1
else:
return 0
print((solve()))
|
X = int(eval(input()))
if X >= 2000:
print((1))
else:
for n in range(1, 20):
if 100 * n <= X <= 105 * n:
print((1))
break
else:
print((0))
| 40 | 11 | 1,314 | 189 |
def solve():
X = int(eval(input()))
if X < 100:
return 0
upper1 = X // 100
for p1 in range(0, 100 * upper1 + 1, 100):
rest1 = X - p1
if rest1 == 0:
return 1
upper2 = rest1 // 101
for p2 in range(0, 101 * upper2 + 1, 101):
rest2 = rest1 - p2
if rest2 == 0:
return 1
upper3 = rest2 // 102
for p3 in range(0, 102 * upper3 + 1, 102):
rest3 = rest2 - p3
if rest3 == 0:
return 1
upper4 = rest3 // 103
for p4 in range(0, 103 * upper4 + 1, 103):
rest4 = rest3 - p4
if rest4 == 0:
return 1
upper5 = rest4 // 104
for p5 in range(0, 104 * upper5 + 1, 104):
rest5 = rest4 - p5
if rest5 == 0:
return 1
upper6 = rest5 // 105
for p6 in range(0, 105 * upper6 + 1, 105):
rest6 = rest5 - p6
if rest6 == 0:
return 1
else:
return 0
print((solve()))
|
X = int(eval(input()))
if X >= 2000:
print((1))
else:
for n in range(1, 20):
if 100 * n <= X <= 105 * n:
print((1))
break
else:
print((0))
| false | 72.5 |
[
"-def solve():",
"- X = int(eval(input()))",
"- if X < 100:",
"- return 0",
"- upper1 = X // 100",
"- for p1 in range(0, 100 * upper1 + 1, 100):",
"- rest1 = X - p1",
"- if rest1 == 0:",
"- return 1",
"- upper2 = rest1 // 101",
"- for p2 in range(0, 101 * upper2 + 1, 101):",
"- rest2 = rest1 - p2",
"- if rest2 == 0:",
"- return 1",
"- upper3 = rest2 // 102",
"- for p3 in range(0, 102 * upper3 + 1, 102):",
"- rest3 = rest2 - p3",
"- if rest3 == 0:",
"- return 1",
"- upper4 = rest3 // 103",
"- for p4 in range(0, 103 * upper4 + 1, 103):",
"- rest4 = rest3 - p4",
"- if rest4 == 0:",
"- return 1",
"- upper5 = rest4 // 104",
"- for p5 in range(0, 104 * upper5 + 1, 104):",
"- rest5 = rest4 - p5",
"- if rest5 == 0:",
"- return 1",
"- upper6 = rest5 // 105",
"- for p6 in range(0, 105 * upper6 + 1, 105):",
"- rest6 = rest5 - p6",
"- if rest6 == 0:",
"- return 1",
"+X = int(eval(input()))",
"+if X >= 2000:",
"+ print((1))",
"+else:",
"+ for n in range(1, 20):",
"+ if 100 * n <= X <= 105 * n:",
"+ print((1))",
"+ break",
"- return 0",
"-",
"-",
"-print((solve()))",
"+ print((0))"
] | false | 0.042391 | 0.041554 | 1.020125 |
[
"s842782207",
"s242741997"
] |
u014333473
|
p04029
|
python
|
s934686680
|
s877083008
| 27 | 23 | 8,876 | 8,924 |
Accepted
|
Accepted
| 14.81 |
print((sum([i for i in range(1,int(eval(input()))+1)])))
|
n=int(eval(input()));print(((n*(n+1))//2))
| 1 | 1 | 48 | 34 |
print((sum([i for i in range(1, int(eval(input())) + 1)])))
|
n = int(eval(input()))
print(((n * (n + 1)) // 2))
| false | 0 |
[
"-print((sum([i for i in range(1, int(eval(input())) + 1)])))",
"+n = int(eval(input()))",
"+print(((n * (n + 1)) // 2))"
] | false | 0.048637 | 0.120775 | 0.402712 |
[
"s934686680",
"s877083008"
] |
u562935282
|
p02727
|
python
|
s445543241
|
s620906002
| 294 | 251 | 24,240 | 23,328 |
Accepted
|
Accepted
| 14.63 |
def main():
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, = list(map(int, input().split()))
pool = p[:X] + q[:Y] + r
pool.sort(reverse=True)
ret = sum(pool[:X + Y])
print(ret)
if __name__ == '__main__':
main()
|
x, y, a, b, c = list(map(int, input().split()))
*p, = list(map(int, input().split()))
*q, = list(map(int, input().split()))
*r, = list(map(int, input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
pool = p[:x] + q[:y] + r
pool.sort(reverse=True)
pool = pool[:x + y]
ans = sum(pool)
print(ans)
| 14 | 14 | 364 | 292 |
def main():
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,) = list(map(int, input().split()))
pool = p[:X] + q[:Y] + r
pool.sort(reverse=True)
ret = sum(pool[: X + Y])
print(ret)
if __name__ == "__main__":
main()
|
x, y, a, b, c = list(map(int, input().split()))
(*p,) = list(map(int, input().split()))
(*q,) = list(map(int, input().split()))
(*r,) = list(map(int, input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
pool = p[:x] + q[:y] + r
pool.sort(reverse=True)
pool = pool[: x + y]
ans = sum(pool)
print(ans)
| false | 0 |
[
"-def main():",
"- 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,) = list(map(int, input().split()))",
"- pool = p[:X] + q[:Y] + r",
"- pool.sort(reverse=True)",
"- ret = sum(pool[: X + Y])",
"- print(ret)",
"-",
"-",
"-if __name__ == \"__main__\":",
"- main()",
"+x, y, a, b, c = list(map(int, input().split()))",
"+(*p,) = list(map(int, input().split()))",
"+(*q,) = list(map(int, input().split()))",
"+(*r,) = list(map(int, input().split()))",
"+p.sort(reverse=True)",
"+q.sort(reverse=True)",
"+pool = p[:x] + q[:y] + r",
"+pool.sort(reverse=True)",
"+pool = pool[: x + y]",
"+ans = sum(pool)",
"+print(ans)"
] | false | 0.068469 | 0.082385 | 0.831079 |
[
"s445543241",
"s620906002"
] |
u573754721
|
p02898
|
python
|
s537265608
|
s367113960
| 70 | 48 | 11,916 | 11,912 |
Accepted
|
Accepted
| 31.43 |
n,k=list(map(int,input().split()))
L=list(map(int,input().split()))
L.sort()
for i in range(n):
if L[i]>=k:
print((n-i))
exit()
print((0))
|
n,k=list(map(int,input().split()))
L=list(map(int,input().split()))
print((sum(x>=k for x in L)))
| 9 | 3 | 167 | 91 |
n, k = list(map(int, input().split()))
L = list(map(int, input().split()))
L.sort()
for i in range(n):
if L[i] >= k:
print((n - i))
exit()
print((0))
|
n, k = list(map(int, input().split()))
L = list(map(int, input().split()))
print((sum(x >= k for x in L)))
| false | 66.666667 |
[
"-L.sort()",
"-for i in range(n):",
"- if L[i] >= k:",
"- print((n - i))",
"- exit()",
"-print((0))",
"+print((sum(x >= k for x in L)))"
] | false | 0.037909 | 0.047177 | 0.803535 |
[
"s537265608",
"s367113960"
] |
u695811449
|
p02716
|
python
|
s658734358
|
s886325712
| 587 | 529 | 156,532 | 188,528 |
Accepted
|
Accepted
| 9.88 |
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
N=int(eval(input()))
A=list(map(int,input().split()))
SUM=[0]*(N+1)
for i in range(N-1,-1,-1):
SUM[i]=SUM[i+1]
if (N-i)%2==1:
SUM[i]+=A[i]
#print(SUM)
ADICT=dict()
def calc(i,select):
if ADICT.get((i,select))!=None:
return ADICT.get((i,select))
rest=N-i
if rest==0 or select==0:
ADICT[(i,select)]=0
return 0
if rest%2==1 and rest//2+1==select:
ADICT[(i,select)]=SUM[i]
return SUM[i]
elif rest%2==0 and rest//2==select:
ADICT[(i,select)]=max(calc(i+1,select),A[i]+calc(i+2,select-1))
return ADICT[(i,select)]
elif rest%2==1 and rest//2==select:
ADICT[(i,select)]=max(calc(i+1,select),A[i]+calc(i+2,select-1))
return ADICT[(i,select)]
print((calc(0,N//2)))
|
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
N=int(eval(input()))
A=list(map(int,input().split()))
SUM=[0]*(N+1)
for i in range(N-1,-1,-1):
SUM[i]=SUM[i+1]
if (N-i)%2==1:
SUM[i]+=A[i]
#print(SUM)
from functools import lru_cache
@lru_cache(maxsize=None)
def calc(i,select):
rest=N-i
if rest==0 or select==0:
return 0
if rest%2==1 and rest//2+1==select:
return SUM[i]
elif rest%2==0 and rest//2==select:
return max(calc(i+1,select),A[i]+calc(i+2,select-1))
elif rest%2==1 and rest//2==select:
return max(calc(i+1,select),A[i]+calc(i+2,select-1))
print((calc(0,N//2)))
| 42 | 36 | 888 | 711 |
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
N = int(eval(input()))
A = list(map(int, input().split()))
SUM = [0] * (N + 1)
for i in range(N - 1, -1, -1):
SUM[i] = SUM[i + 1]
if (N - i) % 2 == 1:
SUM[i] += A[i]
# print(SUM)
ADICT = dict()
def calc(i, select):
if ADICT.get((i, select)) != None:
return ADICT.get((i, select))
rest = N - i
if rest == 0 or select == 0:
ADICT[(i, select)] = 0
return 0
if rest % 2 == 1 and rest // 2 + 1 == select:
ADICT[(i, select)] = SUM[i]
return SUM[i]
elif rest % 2 == 0 and rest // 2 == select:
ADICT[(i, select)] = max(calc(i + 1, select), A[i] + calc(i + 2, select - 1))
return ADICT[(i, select)]
elif rest % 2 == 1 and rest // 2 == select:
ADICT[(i, select)] = max(calc(i + 1, select), A[i] + calc(i + 2, select - 1))
return ADICT[(i, select)]
print((calc(0, N // 2)))
|
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
N = int(eval(input()))
A = list(map(int, input().split()))
SUM = [0] * (N + 1)
for i in range(N - 1, -1, -1):
SUM[i] = SUM[i + 1]
if (N - i) % 2 == 1:
SUM[i] += A[i]
# print(SUM)
from functools import lru_cache
@lru_cache(maxsize=None)
def calc(i, select):
rest = N - i
if rest == 0 or select == 0:
return 0
if rest % 2 == 1 and rest // 2 + 1 == select:
return SUM[i]
elif rest % 2 == 0 and rest // 2 == select:
return max(calc(i + 1, select), A[i] + calc(i + 2, select - 1))
elif rest % 2 == 1 and rest // 2 == select:
return max(calc(i + 1, select), A[i] + calc(i + 2, select - 1))
print((calc(0, N // 2)))
| false | 14.285714 |
[
"-ADICT = dict()",
"+from functools import lru_cache",
"+@lru_cache(maxsize=None)",
"- if ADICT.get((i, select)) != None:",
"- return ADICT.get((i, select))",
"- ADICT[(i, select)] = 0",
"- ADICT[(i, select)] = SUM[i]",
"- ADICT[(i, select)] = max(calc(i + 1, select), A[i] + calc(i + 2, select - 1))",
"- return ADICT[(i, select)]",
"+ return max(calc(i + 1, select), A[i] + calc(i + 2, select - 1))",
"- ADICT[(i, select)] = max(calc(i + 1, select), A[i] + calc(i + 2, select - 1))",
"- return ADICT[(i, select)]",
"+ return max(calc(i + 1, select), A[i] + calc(i + 2, select - 1))"
] | false | 0.045169 | 0.044469 | 1.01574 |
[
"s658734358",
"s886325712"
] |
u127499732
|
p03162
|
python
|
s656340375
|
s020072103
| 431 | 217 | 3,064 | 37,128 |
Accepted
|
Accepted
| 49.65 |
n=int(eval(input()))
ma,mb,mc=0,0,0
for _ in range(n):
a,b,c=list(map(int,input().split()))
x,y,z=ma,mb,mc
ma=a+max([y,z])
mb=b+max([z,x])
mc=c+max([x,y])
print((max([ma,mb,mc])))
|
def main():
n, *abc = list(map(int, open(0).read().split()))
dp = [[0, 0, 0] for _ in range(n + 1)]
for i, (a, b, c) in enumerate(zip(abc[::3], abc[1::3], abc[2::3]), 1):
x, y, z = dp[i - 1]
dp[i] = [a + max(y, z), b + max(z, x), c + max(x, y)]
ans = max(dp[-1])
print(ans)
if __name__ == '__main__':
main()
| 9 | 13 | 183 | 357 |
n = int(eval(input()))
ma, mb, mc = 0, 0, 0
for _ in range(n):
a, b, c = list(map(int, input().split()))
x, y, z = ma, mb, mc
ma = a + max([y, z])
mb = b + max([z, x])
mc = c + max([x, y])
print((max([ma, mb, mc])))
|
def main():
n, *abc = list(map(int, open(0).read().split()))
dp = [[0, 0, 0] for _ in range(n + 1)]
for i, (a, b, c) in enumerate(zip(abc[::3], abc[1::3], abc[2::3]), 1):
x, y, z = dp[i - 1]
dp[i] = [a + max(y, z), b + max(z, x), c + max(x, y)]
ans = max(dp[-1])
print(ans)
if __name__ == "__main__":
main()
| false | 30.769231 |
[
"-n = int(eval(input()))",
"-ma, mb, mc = 0, 0, 0",
"-for _ in range(n):",
"- a, b, c = list(map(int, input().split()))",
"- x, y, z = ma, mb, mc",
"- ma = a + max([y, z])",
"- mb = b + max([z, x])",
"- mc = c + max([x, y])",
"-print((max([ma, mb, mc])))",
"+def main():",
"+ n, *abc = list(map(int, open(0).read().split()))",
"+ dp = [[0, 0, 0] for _ in range(n + 1)]",
"+ for i, (a, b, c) in enumerate(zip(abc[::3], abc[1::3], abc[2::3]), 1):",
"+ x, y, z = dp[i - 1]",
"+ dp[i] = [a + max(y, z), b + max(z, x), c + max(x, y)]",
"+ ans = max(dp[-1])",
"+ print(ans)",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.046798 | 0.087276 | 0.53621 |
[
"s656340375",
"s020072103"
] |
u048945791
|
p03295
|
python
|
s001761181
|
s081005678
| 227 | 209 | 18,188 | 23,716 |
Accepted
|
Accepted
| 7.93 |
import sys
N, M = list(map(int, input().split()))
ab = [tuple(map(int, sys.stdin.readline().split())) for _ in range(M)]
ab.sort(key = lambda x : x[1])
ans = 0
last = -1
for a, b in ab:
if a < last:
continue
else:
ans += 1
last = b
print(ans)
|
import sys
N, M = list(map(int, input().split()))
ab = [tuple(map(int, line.split())) for line in sys.stdin.readlines()]
ab.sort(key = lambda x : x[1])
ans = 0
last = -1
for a, b in ab:
if a < last:
continue
else:
ans += 1
last = b
print(ans)
| 16 | 16 | 286 | 286 |
import sys
N, M = list(map(int, input().split()))
ab = [tuple(map(int, sys.stdin.readline().split())) for _ in range(M)]
ab.sort(key=lambda x: x[1])
ans = 0
last = -1
for a, b in ab:
if a < last:
continue
else:
ans += 1
last = b
print(ans)
|
import sys
N, M = list(map(int, input().split()))
ab = [tuple(map(int, line.split())) for line in sys.stdin.readlines()]
ab.sort(key=lambda x: x[1])
ans = 0
last = -1
for a, b in ab:
if a < last:
continue
else:
ans += 1
last = b
print(ans)
| false | 0 |
[
"-ab = [tuple(map(int, sys.stdin.readline().split())) for _ in range(M)]",
"+ab = [tuple(map(int, line.split())) for line in sys.stdin.readlines()]"
] | false | 0.099277 | 0.038285 | 2.593114 |
[
"s001761181",
"s081005678"
] |
u731436822
|
p02584
|
python
|
s029837668
|
s710016880
| 30 | 27 | 9,180 | 9,088 |
Accepted
|
Accepted
| 10 |
# ABC172 C - Walking Takahashi
X,K,D=list(map(int,input().split()))
q=abs(X)//D
if q>K:
print((abs(X)-K*D))
else:
if (K-q)%2==0:
print((abs(X)-q*D))
else:
print((abs(abs(X)-(q+1)*D)))
|
# ABC172 C - Walking Takahashi
X,K,D=list(map(int,input().split()))
X=abs(X)
q=X//D
if q>K:
print((X-K*D))
else:
if (K-q)%2==0:
print((X-q*D))
else:
print((-X+(q+1)*D))
| 11 | 12 | 210 | 196 |
# ABC172 C - Walking Takahashi
X, K, D = list(map(int, input().split()))
q = abs(X) // D
if q > K:
print((abs(X) - K * D))
else:
if (K - q) % 2 == 0:
print((abs(X) - q * D))
else:
print((abs(abs(X) - (q + 1) * D)))
|
# ABC172 C - Walking Takahashi
X, K, D = list(map(int, input().split()))
X = abs(X)
q = X // D
if q > K:
print((X - K * D))
else:
if (K - q) % 2 == 0:
print((X - q * D))
else:
print((-X + (q + 1) * D))
| false | 8.333333 |
[
"-q = abs(X) // D",
"+X = abs(X)",
"+q = X // D",
"- print((abs(X) - K * D))",
"+ print((X - K * D))",
"- print((abs(X) - q * D))",
"+ print((X - q * D))",
"- print((abs(abs(X) - (q + 1) * D)))",
"+ print((-X + (q + 1) * D))"
] | false | 0.04297 | 0.042762 | 1.004868 |
[
"s029837668",
"s710016880"
] |
u529012223
|
p03137
|
python
|
s204144101
|
s824754347
| 261 | 191 | 23,000 | 23,052 |
Accepted
|
Accepted
| 26.82 |
import numpy as np
N, M = list(map(int, input().split()))
X = list(map(int, input().split()))
X_sort = np.array(sorted(X))[::-1]
X_diff = X_sort[:M-1] - X_sort[1:]
X_diff_sort = sorted(X_diff)[::-1]
print((max(sum(X_diff_sort[N-1:]), 0)))
|
import numpy as np
N, M = list(map(int, input().split()))
X = list(map(int, input().split()))
X = np.array(X)
X_sorted = np.sort(X)[::-1]
X_diff = X_sorted[:-1] - X_sorted[1:]
X_diff_sorted = np.sort(X_diff)[::-1]
print((X_sorted[0] - X_sorted[-1] - X_diff_sorted[:N-1].sum()))
| 10 | 11 | 242 | 282 |
import numpy as np
N, M = list(map(int, input().split()))
X = list(map(int, input().split()))
X_sort = np.array(sorted(X))[::-1]
X_diff = X_sort[: M - 1] - X_sort[1:]
X_diff_sort = sorted(X_diff)[::-1]
print((max(sum(X_diff_sort[N - 1 :]), 0)))
|
import numpy as np
N, M = list(map(int, input().split()))
X = list(map(int, input().split()))
X = np.array(X)
X_sorted = np.sort(X)[::-1]
X_diff = X_sorted[:-1] - X_sorted[1:]
X_diff_sorted = np.sort(X_diff)[::-1]
print((X_sorted[0] - X_sorted[-1] - X_diff_sorted[: N - 1].sum()))
| false | 9.090909 |
[
"-X_sort = np.array(sorted(X))[::-1]",
"-X_diff = X_sort[: M - 1] - X_sort[1:]",
"-X_diff_sort = sorted(X_diff)[::-1]",
"-print((max(sum(X_diff_sort[N - 1 :]), 0)))",
"+X = np.array(X)",
"+X_sorted = np.sort(X)[::-1]",
"+X_diff = X_sorted[:-1] - X_sorted[1:]",
"+X_diff_sorted = np.sort(X_diff)[::-1]",
"+print((X_sorted[0] - X_sorted[-1] - X_diff_sorted[: N - 1].sum()))"
] | false | 0.203263 | 0.285555 | 0.711819 |
[
"s204144101",
"s824754347"
] |
u644907318
|
p04021
|
python
|
s593176328
|
s257083757
| 694 | 271 | 66,264 | 89,248 |
Accepted
|
Accepted
| 60.95 |
N = int(eval(input()))
A = sorted(list({int(eval(input())):i for i in range(N)}.items()),key=lambda x:x[0])
cnt = 0
for i in range(N):
j = A[i][1]
if i%2!=j%2:
cnt += 1
print((cnt//2))
|
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
A = [(A[i],i) for i in range(N)]
A = sorted(A,key=lambda x:x[0])
cnt = 0
for i in range(N):
a,j = A[i]
if (i-j)%2==1:
cnt += 1
print((cnt//2))
| 8 | 10 | 193 | 219 |
N = int(eval(input()))
A = sorted(list({int(eval(input())): i for i in range(N)}.items()), key=lambda x: x[0])
cnt = 0
for i in range(N):
j = A[i][1]
if i % 2 != j % 2:
cnt += 1
print((cnt // 2))
|
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
A = [(A[i], i) for i in range(N)]
A = sorted(A, key=lambda x: x[0])
cnt = 0
for i in range(N):
a, j = A[i]
if (i - j) % 2 == 1:
cnt += 1
print((cnt // 2))
| false | 20 |
[
"-A = sorted(list({int(eval(input())): i for i in range(N)}.items()), key=lambda x: x[0])",
"+A = [int(eval(input())) for _ in range(N)]",
"+A = [(A[i], i) for i in range(N)]",
"+A = sorted(A, key=lambda x: x[0])",
"- j = A[i][1]",
"- if i % 2 != j % 2:",
"+ a, j = A[i]",
"+ if (i - j) % 2 == 1:"
] | false | 0.043491 | 0.043678 | 0.995715 |
[
"s593176328",
"s257083757"
] |
u647766105
|
p00478
|
python
|
s079551761
|
s297543281
| 20 | 10 | 4,204 | 4,200 |
Accepted
|
Accepted
| 50 |
s = input()
score = 0
for u in range(eval(input())):
ss = input()
if len((ss+ss).split(s)) > 1:
score += 1
print(score)
|
s = input()
score = 0
for u in range(eval(input())):
ss = input()
if s in ss*2:
score += 1
print(score)
| 7 | 7 | 143 | 127 |
s = input()
score = 0
for u in range(eval(input())):
ss = input()
if len((ss + ss).split(s)) > 1:
score += 1
print(score)
|
s = input()
score = 0
for u in range(eval(input())):
ss = input()
if s in ss * 2:
score += 1
print(score)
| false | 0 |
[
"- if len((ss + ss).split(s)) > 1:",
"+ if s in ss * 2:"
] | false | 0.050838 | 0.048063 | 1.057744 |
[
"s079551761",
"s297543281"
] |
u531631168
|
p03785
|
python
|
s662479734
|
s369589235
| 379 | 177 | 20,828 | 14,040 |
Accepted
|
Accepted
| 53.3 |
from collections import Counter
n, c, k = list(map(int, input().split()))
time_people = Counter([int(eval(input())) for _ in range(n)])
times = sorted(time_people.keys())
ans = 0
left = 0
right = 0
while time_people[times[-1]] > 0:
space = c
while times[left] + k >= times[right] and space > 0:
new_passenger = min(c, time_people[times[right]])
space -= new_passenger
time_people[times[right]] -= new_passenger
if right >= len(times):
break
if time_people[times[right]] == 0:
right += 1
if right == len(times):
break
ans += 1
while left < len(times) and time_people[times[left]] <= 0:
left += 1
print(ans)
|
n, c, k = list(map(int, input().split()))
T = sorted([int(eval(input())) for _ in range(n)])
ans = 1
first = T[0]
pas = 0
for t in T:
pas += 1
if t > first + k or pas > c:
ans += 1
pas = 1
first = t
print(ans)
| 23 | 12 | 731 | 240 |
from collections import Counter
n, c, k = list(map(int, input().split()))
time_people = Counter([int(eval(input())) for _ in range(n)])
times = sorted(time_people.keys())
ans = 0
left = 0
right = 0
while time_people[times[-1]] > 0:
space = c
while times[left] + k >= times[right] and space > 0:
new_passenger = min(c, time_people[times[right]])
space -= new_passenger
time_people[times[right]] -= new_passenger
if right >= len(times):
break
if time_people[times[right]] == 0:
right += 1
if right == len(times):
break
ans += 1
while left < len(times) and time_people[times[left]] <= 0:
left += 1
print(ans)
|
n, c, k = list(map(int, input().split()))
T = sorted([int(eval(input())) for _ in range(n)])
ans = 1
first = T[0]
pas = 0
for t in T:
pas += 1
if t > first + k or pas > c:
ans += 1
pas = 1
first = t
print(ans)
| false | 47.826087 |
[
"-from collections import Counter",
"-",
"-time_people = Counter([int(eval(input())) for _ in range(n)])",
"-times = sorted(time_people.keys())",
"-ans = 0",
"-left = 0",
"-right = 0",
"-while time_people[times[-1]] > 0:",
"- space = c",
"- while times[left] + k >= times[right] and space > 0:",
"- new_passenger = min(c, time_people[times[right]])",
"- space -= new_passenger",
"- time_people[times[right]] -= new_passenger",
"- if right >= len(times):",
"- break",
"- if time_people[times[right]] == 0:",
"- right += 1",
"- if right == len(times):",
"- break",
"- ans += 1",
"- while left < len(times) and time_people[times[left]] <= 0:",
"- left += 1",
"+T = sorted([int(eval(input())) for _ in range(n)])",
"+ans = 1",
"+first = T[0]",
"+pas = 0",
"+for t in T:",
"+ pas += 1",
"+ if t > first + k or pas > c:",
"+ ans += 1",
"+ pas = 1",
"+ first = t"
] | false | 0.047794 | 0.04819 | 0.991768 |
[
"s662479734",
"s369589235"
] |
u392319141
|
p02703
|
python
|
s626912517
|
s064481548
| 1,833 | 906 | 100,460 | 25,864 |
Accepted
|
Accepted
| 50.57 |
from heapq import heappush, heappop
N, M, S = list(map(int, input().split()))
mxCost = 0
edges = [[] for _ in range(N)]
for _ in range(M):
fr, to, cost, dist = list(map(int, input().split()))
mxCost = max(mxCost, cost)
fr -= 1
to -= 1
edges[fr].append((to, dist, cost))
edges[to].append((fr, dist, cost))
for i in range(N):
C, D = list(map(int, input().split()))
edges[i].append((i, D, -C))
que = [(0, S, 0)]
mxCost *= (N - 1)
minDsit = [[10**18] * (mxCost + 1) for _ in range(N)]
minDsit[0][0] = 0
while que:
dist, s, now = heappop(que)
for to, d, c in edges[now]:
cost = min(mxCost, s - c)
if cost < 0 or minDsit[to][cost] <= dist + d:
continue
minDsit[to][cost] = dist + d
que.append((dist + d, cost, to))
for dist in minDsit[1:]:
print((min(dist)))
|
from heapq import heappush, heappop
N, M, S = list(map(int, input().split()))
mxCost = 0
edges = [[] for _ in range(N)]
for _ in range(M):
fr, to, cost, dist = list(map(int, input().split()))
mxCost = max(mxCost, cost)
fr -= 1
to -= 1
edges[fr].append((to, dist, cost))
edges[to].append((fr, dist, cost))
for i in range(N):
C, D = list(map(int, input().split()))
edges[i].append((i, D, -C))
que = [(0, S, 0)]
mxCost *= (N - 1)
minDsit = [[10**18] * (mxCost + 1) for _ in range(N)]
minDsit[0][0] = 0
while que:
dist, s, now = heappop(que)
for to, d, c in edges[now]:
cost = min(mxCost, s - c)
if cost < 0 or minDsit[to][cost] <= dist + d:
continue
minDsit[to][cost] = dist + d
heappush(que, (dist + d, cost, to))
for dist in minDsit[1:]:
print((min(dist)))
| 35 | 35 | 862 | 865 |
from heapq import heappush, heappop
N, M, S = list(map(int, input().split()))
mxCost = 0
edges = [[] for _ in range(N)]
for _ in range(M):
fr, to, cost, dist = list(map(int, input().split()))
mxCost = max(mxCost, cost)
fr -= 1
to -= 1
edges[fr].append((to, dist, cost))
edges[to].append((fr, dist, cost))
for i in range(N):
C, D = list(map(int, input().split()))
edges[i].append((i, D, -C))
que = [(0, S, 0)]
mxCost *= N - 1
minDsit = [[10**18] * (mxCost + 1) for _ in range(N)]
minDsit[0][0] = 0
while que:
dist, s, now = heappop(que)
for to, d, c in edges[now]:
cost = min(mxCost, s - c)
if cost < 0 or minDsit[to][cost] <= dist + d:
continue
minDsit[to][cost] = dist + d
que.append((dist + d, cost, to))
for dist in minDsit[1:]:
print((min(dist)))
|
from heapq import heappush, heappop
N, M, S = list(map(int, input().split()))
mxCost = 0
edges = [[] for _ in range(N)]
for _ in range(M):
fr, to, cost, dist = list(map(int, input().split()))
mxCost = max(mxCost, cost)
fr -= 1
to -= 1
edges[fr].append((to, dist, cost))
edges[to].append((fr, dist, cost))
for i in range(N):
C, D = list(map(int, input().split()))
edges[i].append((i, D, -C))
que = [(0, S, 0)]
mxCost *= N - 1
minDsit = [[10**18] * (mxCost + 1) for _ in range(N)]
minDsit[0][0] = 0
while que:
dist, s, now = heappop(que)
for to, d, c in edges[now]:
cost = min(mxCost, s - c)
if cost < 0 or minDsit[to][cost] <= dist + d:
continue
minDsit[to][cost] = dist + d
heappush(que, (dist + d, cost, to))
for dist in minDsit[1:]:
print((min(dist)))
| false | 0 |
[
"- que.append((dist + d, cost, to))",
"+ heappush(que, (dist + d, cost, to))"
] | false | 0.222304 | 0.054643 | 4.068284 |
[
"s626912517",
"s064481548"
] |
u133936772
|
p02971
|
python
|
s832310737
|
s716543313
| 609 | 166 | 14,112 | 18,908 |
Accepted
|
Accepted
| 72.74 |
n=int(eval(input()))
l=[int(eval(input())) for _ in range(n)]
s=sorted(l)
a,b=s[-1],s[-2]
for i in l: print(([b,a][a>i]))
|
n,*l=list(map(int,open(0)))
s=sorted(l)
for i in l: print((s[(i<s[-1])-2]))
| 5 | 3 | 111 | 69 |
n = int(eval(input()))
l = [int(eval(input())) for _ in range(n)]
s = sorted(l)
a, b = s[-1], s[-2]
for i in l:
print(([b, a][a > i]))
|
n, *l = list(map(int, open(0)))
s = sorted(l)
for i in l:
print((s[(i < s[-1]) - 2]))
| false | 40 |
[
"-n = int(eval(input()))",
"-l = [int(eval(input())) for _ in range(n)]",
"+n, *l = list(map(int, open(0)))",
"-a, b = s[-1], s[-2]",
"- print(([b, a][a > i]))",
"+ print((s[(i < s[-1]) - 2]))"
] | false | 0.118304 | 0.049209 | 2.404109 |
[
"s832310737",
"s716543313"
] |
u780475861
|
p02971
|
python
|
s261401237
|
s716314688
| 171 | 126 | 25,148 | 25,136 |
Accepted
|
Accepted
| 26.32 |
import sys
def main():
n, *lst = map(int, sys.stdin.read().split())
max1 = max(lst)
idx = lst.index(max1)
max2 = max(lst[:idx] + lst[idx+1:])
if max2 < max1:
print(*[max1 if j != max1 else max2 for j in lst], sep='\n')
else:
print(*[max1]*n, sep='\n')
if __name__ == '__main__':
main()
|
import sys
def main():
n, *lst = list(map(int, sys.stdin.read().split()))
max1 = max(lst)
idx = lst.index(max1)
max2 = max(lst[:idx] + lst[idx+1:])
print(('\n'.join(str(max1) if j != max1 else str(max2) for j in lst)))
if __name__ == '__main__':
main()
| 16 | 13 | 331 | 273 |
import sys
def main():
n, *lst = map(int, sys.stdin.read().split())
max1 = max(lst)
idx = lst.index(max1)
max2 = max(lst[:idx] + lst[idx + 1 :])
if max2 < max1:
print(*[max1 if j != max1 else max2 for j in lst], sep="\n")
else:
print(*[max1] * n, sep="\n")
if __name__ == "__main__":
main()
|
import sys
def main():
n, *lst = list(map(int, sys.stdin.read().split()))
max1 = max(lst)
idx = lst.index(max1)
max2 = max(lst[:idx] + lst[idx + 1 :])
print(("\n".join(str(max1) if j != max1 else str(max2) for j in lst)))
if __name__ == "__main__":
main()
| false | 18.75 |
[
"- n, *lst = map(int, sys.stdin.read().split())",
"+ n, *lst = list(map(int, sys.stdin.read().split()))",
"- if max2 < max1:",
"- print(*[max1 if j != max1 else max2 for j in lst], sep=\"\\n\")",
"- else:",
"- print(*[max1] * n, sep=\"\\n\")",
"+ print((\"\\n\".join(str(max1) if j != max1 else str(max2) for j in lst)))"
] | false | 0.070115 | 0.038202 | 1.835391 |
[
"s261401237",
"s716314688"
] |
u497596438
|
p03261
|
python
|
s030402570
|
s423154446
| 185 | 169 | 38,384 | 38,492 |
Accepted
|
Accepted
| 8.65 |
#S=input()
N=int(eval(input()))
#N,M,X,Y=map(int,input().split())
W=[]
can=True
for i in range(N):
w=eval(input())
if i==0:
W.append(w)
e=w[-1]
continue
s=w[0]
if e==s and not(w in W):
W.append(w)
e=w[-1]
continue
else:
can=False
break
if can:
print("Yes")
else:
print("No")
|
N=int(eval(input()))
N-=1
w=eval(input())
f=w[-1]
word={w}
for i in range(N):
w=eval(input())
ini=w[0]
if w in word:
print("No")
quit()
if ini!=f:
print("No")
quit()
word.add(w)
f=w[-1]
print("Yes")
| 23 | 17 | 376 | 253 |
# S=input()
N = int(eval(input()))
# N,M,X,Y=map(int,input().split())
W = []
can = True
for i in range(N):
w = eval(input())
if i == 0:
W.append(w)
e = w[-1]
continue
s = w[0]
if e == s and not (w in W):
W.append(w)
e = w[-1]
continue
else:
can = False
break
if can:
print("Yes")
else:
print("No")
|
N = int(eval(input()))
N -= 1
w = eval(input())
f = w[-1]
word = {w}
for i in range(N):
w = eval(input())
ini = w[0]
if w in word:
print("No")
quit()
if ini != f:
print("No")
quit()
word.add(w)
f = w[-1]
print("Yes")
| false | 26.086957 |
[
"-# S=input()",
"-# N,M,X,Y=map(int,input().split())",
"-W = []",
"-can = True",
"+N -= 1",
"+w = eval(input())",
"+f = w[-1]",
"+word = {w}",
"- if i == 0:",
"- W.append(w)",
"- e = w[-1]",
"- continue",
"- s = w[0]",
"- if e == s and not (w in W):",
"- W.append(w)",
"- e = w[-1]",
"- continue",
"- else:",
"- can = False",
"- break",
"-if can:",
"- print(\"Yes\")",
"-else:",
"- print(\"No\")",
"+ ini = w[0]",
"+ if w in word:",
"+ print(\"No\")",
"+ quit()",
"+ if ini != f:",
"+ print(\"No\")",
"+ quit()",
"+ word.add(w)",
"+ f = w[-1]",
"+print(\"Yes\")"
] | false | 0.044072 | 0.044197 | 0.997182 |
[
"s030402570",
"s423154446"
] |
u025501820
|
p02888
|
python
|
s594526292
|
s794385702
| 1,673 | 513 | 3,188 | 44,268 |
Accepted
|
Accepted
| 69.34 |
import math
N = int(eval(input()))
L = sorted(list(map(int, input().split())))
ans = 0
for a in range(N - 2):
b = a + 1
c = a + 2
while c < N and b < N - 1:
if L[c] >= L[a] + L[b]:
ans += c - 1 - b
b += 1
if b == c:
c += 1
else:
if c == N - 1:
ans += (c - b) * (c - b + 1) // 2
break
else:
c += 1
print(ans)
|
N = int(eval(input()))
L = sorted(list(map(int, input().split())))
ans = 0
for i in range(0, N - 2):
a = L[i]
for j in range(i + 1, N - 1):
b = L[j]
ok = j + 1
ng = N - 1
if L[ng] < a + b:
ans += ng - j
continue
if L[ok] >= a + b:
continue
while ok + 1 < ng:
c = (ok + ng) // 2
if L[c] < a + b:
ok = c
else:
ng = c
ans += ok - j
print(ans)
| 23 | 22 | 495 | 522 |
import math
N = int(eval(input()))
L = sorted(list(map(int, input().split())))
ans = 0
for a in range(N - 2):
b = a + 1
c = a + 2
while c < N and b < N - 1:
if L[c] >= L[a] + L[b]:
ans += c - 1 - b
b += 1
if b == c:
c += 1
else:
if c == N - 1:
ans += (c - b) * (c - b + 1) // 2
break
else:
c += 1
print(ans)
|
N = int(eval(input()))
L = sorted(list(map(int, input().split())))
ans = 0
for i in range(0, N - 2):
a = L[i]
for j in range(i + 1, N - 1):
b = L[j]
ok = j + 1
ng = N - 1
if L[ng] < a + b:
ans += ng - j
continue
if L[ok] >= a + b:
continue
while ok + 1 < ng:
c = (ok + ng) // 2
if L[c] < a + b:
ok = c
else:
ng = c
ans += ok - j
print(ans)
| false | 4.347826 |
[
"-import math",
"-",
"-for a in range(N - 2):",
"- b = a + 1",
"- c = a + 2",
"- while c < N and b < N - 1:",
"- if L[c] >= L[a] + L[b]:",
"- ans += c - 1 - b",
"- b += 1",
"- if b == c:",
"- c += 1",
"- else:",
"- if c == N - 1:",
"- ans += (c - b) * (c - b + 1) // 2",
"- break",
"+for i in range(0, N - 2):",
"+ a = L[i]",
"+ for j in range(i + 1, N - 1):",
"+ b = L[j]",
"+ ok = j + 1",
"+ ng = N - 1",
"+ if L[ng] < a + b:",
"+ ans += ng - j",
"+ continue",
"+ if L[ok] >= a + b:",
"+ continue",
"+ while ok + 1 < ng:",
"+ c = (ok + ng) // 2",
"+ if L[c] < a + b:",
"+ ok = c",
"- c += 1",
"+ ng = c",
"+ ans += ok - j"
] | false | 0.036355 | 0.06199 | 0.586457 |
[
"s594526292",
"s794385702"
] |
u556589653
|
p02718
|
python
|
s995518900
|
s546511971
| 36 | 33 | 9,856 | 9,924 |
Accepted
|
Accepted
| 8.33 |
from decimal import Decimal
n,m = list(map(int,input().split()))
A = list(map(int,input().split()))
border = float(sum(A)*(1/(4*m)))
border2 = str(border)
border3 = Decimal(border2)
ans = 0
judge = 0
for i in range(n):
if A[i] >= border3:
ans+=1
if ans >= m:
print("Yes")
else:
print("No")
|
from decimal import Decimal
n,m = list(map(int,input().split()))
A = list(map(int,input().split()))
border = float(sum(A)/(4*m))
border2 = str(border)
border3 = Decimal(border2)
ans = 0
judge = 0
for i in range(n):
if A[i] >= border3:
ans+=1
if ans >= m:
print("Yes")
else:
print("No")
| 15 | 15 | 307 | 304 |
from decimal import Decimal
n, m = list(map(int, input().split()))
A = list(map(int, input().split()))
border = float(sum(A) * (1 / (4 * m)))
border2 = str(border)
border3 = Decimal(border2)
ans = 0
judge = 0
for i in range(n):
if A[i] >= border3:
ans += 1
if ans >= m:
print("Yes")
else:
print("No")
|
from decimal import Decimal
n, m = list(map(int, input().split()))
A = list(map(int, input().split()))
border = float(sum(A) / (4 * m))
border2 = str(border)
border3 = Decimal(border2)
ans = 0
judge = 0
for i in range(n):
if A[i] >= border3:
ans += 1
if ans >= m:
print("Yes")
else:
print("No")
| false | 0 |
[
"-border = float(sum(A) * (1 / (4 * m)))",
"+border = float(sum(A) / (4 * m))"
] | false | 0.048757 | 0.04799 | 1.015991 |
[
"s995518900",
"s546511971"
] |
u467736898
|
p02710
|
python
|
s475322823
|
s175012409
| 783 | 556 | 98,808 | 100,864 |
Accepted
|
Accepted
| 28.99 |
# tolist つけ忘れ
# https://atcoder.jp/contests/abc163/submissions/16271142
def numba_compile(numba_config):
import os, sys
if sys.argv[-1] == "ONLINE_JUDGE":
from numba import njit
from numba.pycc import CC
cc = CC("my_module")
for func, signature in numba_config:
globals()[func.__name__] = njit(signature)(func)
cc.export(func.__name__, signature)(func)
cc.compile()
exit()
elif os.name == "posix":
exec(f"from my_module import {','.join(func.__name__ for func, _ in numba_config)}")
for func, _ in numba_config:
globals()[func.__name__] = vars()[func.__name__]
else:
from numba import njit
for func, signature in numba_config:
globals()[func.__name__] = njit(signature, cache=True)(func)
print("compiled!", file=sys.stderr)
import numpy as np
def eular_tour(G, root):
# G は破壊的に有向木にされる
# グラフは 1-indexed が良い
n = len(G)
stack = [root]
tour = [0] * 0
firsts = np.full(n, -100, dtype=np.int64)
lasts = np.full(n, -100, dtype=np.int64)
parents = np.full(n, -100, dtype=np.int64)
while stack:
v = stack.pop()
if firsts[v] >= 0:
lasts[v] = len(tour)
tour.append(-v) # 帰りがけの辺の表現をマイナス以外にしたい場合ここを変える
continue
firsts[v] = len(tour)
tour.append(v)
stack.append(v)
for u in G[v]:
G[u].remove(v)
parents[u] = v
stack.append(u)
tour = np.array(tour, dtype=np.int64)
return tour, firsts, lasts, parents
def solve(N, C, AB):
G = [[0]*0 for _ in range(N+1)]
for i in range(N-1):
a, b = AB[i]
G[a].append(b)
G[b].append(a)
tour, firsts, lasts, parents = eular_tour(G, 1)
Siz = lasts - firsts + 1 >> 1
Cnt = np.zeros(N+1, dtype=np.int64)
Ans = np.zeros(N+1, dtype=np.int64)
Cnt_old = np.empty_like(Cnt)
Siz_tmp = np.full_like(Cnt, 1)
for v in tour:
if v >= 0:
p = parents[v]
if p != -100:
Cnt[C[p]] = N - Siz[v] # 上を塞ぐ
color = C[v]
Cnt_old[v] = Cnt[color]
else:
v = -v
Ans[C[v]] += N - Siz_tmp[v] + 1 - Cnt_old[v]
Cnt[C[v]] = Cnt_old[v] + Siz_tmp[v]
p = parents[v]
if p != -100:
Siz_tmp[p] += Siz[v]
Ans[C[p]] += Siz[v] * (N - Siz_tmp[p] + 1 - Cnt_old[p])
return Ans[1:]
numba_compile([
[eular_tour, "Tuple((i8[:],i8[:],i8[:],i8[:]))(List(List(i8)),i8)"],
[solve, "i8[:](i8,i8[:],i8[:,:])"],
])
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(505050)
N = int(input())
C = np.array(["0"] + input().split(), dtype=np.int64)
AB = np.array([list(map(int, input().split())) for _ in range(N-1)], dtype=np.int64)
Ans = solve(N, C, AB)
print("\n".join(map(str, Ans.tolist())))
|
# 入力のみ
# 入力をいい感じに
def numba_compile(numba_config):
import os, sys
if sys.argv[-1] == "ONLINE_JUDGE":
from numba import njit
from numba.pycc import CC
cc = CC("my_module")
for func, signature in numba_config:
globals()[func.__name__] = njit(signature)(func)
cc.export(func.__name__, signature)(func)
cc.compile()
exit()
elif os.name == "posix":
exec(f"from my_module import {','.join(func.__name__ for func, _ in numba_config)}")
for func, _ in numba_config:
globals()[func.__name__] = vars()[func.__name__]
else:
from numba import njit
for func, signature in numba_config:
globals()[func.__name__] = njit(signature, cache=True)(func)
print("compiled!", file=sys.stderr)
import numpy as np
def eular_tour(G, root):
# G は破壊的に有向木にされる
# グラフは 1-indexed が良い
n = len(G)
stack = [root]
tour = [0] * 0
firsts = np.full(n, -100, dtype=np.int64)
lasts = np.full(n, -100, dtype=np.int64)
parents = np.full(n, -100, dtype=np.int64)
while stack:
v = stack.pop()
if firsts[v] >= 0:
lasts[v] = len(tour)
tour.append(-v) # 帰りがけの辺の表現をマイナス以外にしたい場合ここを変える
continue
firsts[v] = len(tour)
tour.append(v)
stack.append(v)
for u in G[v]:
G[u].remove(v)
parents[u] = v
stack.append(u)
tour = np.array(tour, dtype=np.int64)
return tour, firsts, lasts, parents
def solve(N, C, AB):
G = [[0]*0 for _ in range(N+1)]
for i in range(N-1):
a, b = AB[i]
G[a].append(b)
G[b].append(a)
tour, firsts, lasts, parents = eular_tour(G, 1)
Siz = lasts - firsts + 1 >> 1
Cnt = np.zeros(N+1, dtype=np.int64)
Ans = np.zeros(N+1, dtype=np.int64)
Cnt_old = np.empty_like(Cnt)
Siz_tmp = np.full_like(Cnt, 1)
for v in tour:
if v >= 0:
p = parents[v]
if p != -100:
Cnt[C[p]] = N - Siz[v] # 上を塞ぐ
color = C[v]
Cnt_old[v] = Cnt[color]
else:
v = -v
Ans[C[v]] += N - Siz_tmp[v] + 1 - Cnt_old[v]
Cnt[C[v]] = Cnt_old[v] + Siz_tmp[v]
p = parents[v]
if p != -100:
Siz_tmp[p] += Siz[v]
Ans[C[p]] += Siz[v] * (N - Siz_tmp[p] + 1 - Cnt_old[p])
return Ans[1:]
numba_compile([
[eular_tour, "Tuple((i8[:],i8[:],i8[:],i8[:]))(List(List(i8)),i8)"],
[solve, "i8[:](i8,i8[:],i8[:,:])"],
])
import sys
def main():
input = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
N = int(input())
C = np.empty(N+1, dtype=np.int64)
C[1:] = input().split()
AB = np.array(read().split(), dtype=np.int64).reshape(N-1, 2)
Ans = solve(N, C, AB)
print("\n".join(map(str, Ans.tolist())))
main()
| 99 | 103 | 3,040 | 3,022 |
# tolist つけ忘れ
# https://atcoder.jp/contests/abc163/submissions/16271142
def numba_compile(numba_config):
import os, sys
if sys.argv[-1] == "ONLINE_JUDGE":
from numba import njit
from numba.pycc import CC
cc = CC("my_module")
for func, signature in numba_config:
globals()[func.__name__] = njit(signature)(func)
cc.export(func.__name__, signature)(func)
cc.compile()
exit()
elif os.name == "posix":
exec(
f"from my_module import {','.join(func.__name__ for func, _ in numba_config)}"
)
for func, _ in numba_config:
globals()[func.__name__] = vars()[func.__name__]
else:
from numba import njit
for func, signature in numba_config:
globals()[func.__name__] = njit(signature, cache=True)(func)
print("compiled!", file=sys.stderr)
import numpy as np
def eular_tour(G, root):
# G は破壊的に有向木にされる
# グラフは 1-indexed が良い
n = len(G)
stack = [root]
tour = [0] * 0
firsts = np.full(n, -100, dtype=np.int64)
lasts = np.full(n, -100, dtype=np.int64)
parents = np.full(n, -100, dtype=np.int64)
while stack:
v = stack.pop()
if firsts[v] >= 0:
lasts[v] = len(tour)
tour.append(-v) # 帰りがけの辺の表現をマイナス以外にしたい場合ここを変える
continue
firsts[v] = len(tour)
tour.append(v)
stack.append(v)
for u in G[v]:
G[u].remove(v)
parents[u] = v
stack.append(u)
tour = np.array(tour, dtype=np.int64)
return tour, firsts, lasts, parents
def solve(N, C, AB):
G = [[0] * 0 for _ in range(N + 1)]
for i in range(N - 1):
a, b = AB[i]
G[a].append(b)
G[b].append(a)
tour, firsts, lasts, parents = eular_tour(G, 1)
Siz = lasts - firsts + 1 >> 1
Cnt = np.zeros(N + 1, dtype=np.int64)
Ans = np.zeros(N + 1, dtype=np.int64)
Cnt_old = np.empty_like(Cnt)
Siz_tmp = np.full_like(Cnt, 1)
for v in tour:
if v >= 0:
p = parents[v]
if p != -100:
Cnt[C[p]] = N - Siz[v] # 上を塞ぐ
color = C[v]
Cnt_old[v] = Cnt[color]
else:
v = -v
Ans[C[v]] += N - Siz_tmp[v] + 1 - Cnt_old[v]
Cnt[C[v]] = Cnt_old[v] + Siz_tmp[v]
p = parents[v]
if p != -100:
Siz_tmp[p] += Siz[v]
Ans[C[p]] += Siz[v] * (N - Siz_tmp[p] + 1 - Cnt_old[p])
return Ans[1:]
numba_compile(
[
[eular_tour, "Tuple((i8[:],i8[:],i8[:],i8[:]))(List(List(i8)),i8)"],
[solve, "i8[:](i8,i8[:],i8[:,:])"],
]
)
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(505050)
N = int(input())
C = np.array(["0"] + input().split(), dtype=np.int64)
AB = np.array([list(map(int, input().split())) for _ in range(N - 1)], dtype=np.int64)
Ans = solve(N, C, AB)
print("\n".join(map(str, Ans.tolist())))
|
# 入力のみ
# 入力をいい感じに
def numba_compile(numba_config):
import os, sys
if sys.argv[-1] == "ONLINE_JUDGE":
from numba import njit
from numba.pycc import CC
cc = CC("my_module")
for func, signature in numba_config:
globals()[func.__name__] = njit(signature)(func)
cc.export(func.__name__, signature)(func)
cc.compile()
exit()
elif os.name == "posix":
exec(
f"from my_module import {','.join(func.__name__ for func, _ in numba_config)}"
)
for func, _ in numba_config:
globals()[func.__name__] = vars()[func.__name__]
else:
from numba import njit
for func, signature in numba_config:
globals()[func.__name__] = njit(signature, cache=True)(func)
print("compiled!", file=sys.stderr)
import numpy as np
def eular_tour(G, root):
# G は破壊的に有向木にされる
# グラフは 1-indexed が良い
n = len(G)
stack = [root]
tour = [0] * 0
firsts = np.full(n, -100, dtype=np.int64)
lasts = np.full(n, -100, dtype=np.int64)
parents = np.full(n, -100, dtype=np.int64)
while stack:
v = stack.pop()
if firsts[v] >= 0:
lasts[v] = len(tour)
tour.append(-v) # 帰りがけの辺の表現をマイナス以外にしたい場合ここを変える
continue
firsts[v] = len(tour)
tour.append(v)
stack.append(v)
for u in G[v]:
G[u].remove(v)
parents[u] = v
stack.append(u)
tour = np.array(tour, dtype=np.int64)
return tour, firsts, lasts, parents
def solve(N, C, AB):
G = [[0] * 0 for _ in range(N + 1)]
for i in range(N - 1):
a, b = AB[i]
G[a].append(b)
G[b].append(a)
tour, firsts, lasts, parents = eular_tour(G, 1)
Siz = lasts - firsts + 1 >> 1
Cnt = np.zeros(N + 1, dtype=np.int64)
Ans = np.zeros(N + 1, dtype=np.int64)
Cnt_old = np.empty_like(Cnt)
Siz_tmp = np.full_like(Cnt, 1)
for v in tour:
if v >= 0:
p = parents[v]
if p != -100:
Cnt[C[p]] = N - Siz[v] # 上を塞ぐ
color = C[v]
Cnt_old[v] = Cnt[color]
else:
v = -v
Ans[C[v]] += N - Siz_tmp[v] + 1 - Cnt_old[v]
Cnt[C[v]] = Cnt_old[v] + Siz_tmp[v]
p = parents[v]
if p != -100:
Siz_tmp[p] += Siz[v]
Ans[C[p]] += Siz[v] * (N - Siz_tmp[p] + 1 - Cnt_old[p])
return Ans[1:]
numba_compile(
[
[eular_tour, "Tuple((i8[:],i8[:],i8[:],i8[:]))(List(List(i8)),i8)"],
[solve, "i8[:](i8,i8[:],i8[:,:])"],
]
)
import sys
def main():
input = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
N = int(input())
C = np.empty(N + 1, dtype=np.int64)
C[1:] = input().split()
AB = np.array(read().split(), dtype=np.int64).reshape(N - 1, 2)
Ans = solve(N, C, AB)
print("\n".join(map(str, Ans.tolist())))
main()
| false | 3.883495 |
[
"-# tolist つけ忘れ",
"-# https://atcoder.jp/contests/abc163/submissions/16271142",
"+# 入力のみ",
"+# 入力をいい感じに",
"-input = sys.stdin.buffer.readline",
"-sys.setrecursionlimit(505050)",
"-N = int(input())",
"-C = np.array([\"0\"] + input().split(), dtype=np.int64)",
"-AB = np.array([list(map(int, input().split())) for _ in range(N - 1)], dtype=np.int64)",
"-Ans = solve(N, C, AB)",
"-print(\"\\n\".join(map(str, Ans.tolist())))",
"+",
"+def main():",
"+ input = sys.stdin.buffer.readline",
"+ read = sys.stdin.buffer.read",
"+ N = int(input())",
"+ C = np.empty(N + 1, dtype=np.int64)",
"+ C[1:] = input().split()",
"+ AB = np.array(read().split(), dtype=np.int64).reshape(N - 1, 2)",
"+ Ans = solve(N, C, AB)",
"+ print(\"\\n\".join(map(str, Ans.tolist())))",
"+",
"+",
"+main()"
] | false | 0.239312 | 0.301443 | 0.793888 |
[
"s475322823",
"s175012409"
] |
u981931040
|
p03545
|
python
|
s064223422
|
s297512702
| 164 | 20 | 38,256 | 3,064 |
Accepted
|
Accepted
| 87.8 |
S = eval(input())
for i in range(2 ** len(S) - 1):
work = S
for j in range(1 ,len(S)):
if i >> (j - 1) & 1:
work = work[:2 * j - 1] + "+" + work[2 * j - 1:]
else:
work = work[:2 * j - 1] + "-" + work[2 * j - 1:]
if eval(work) == 7:
print(("{0}=7".format(work)))
exit()
|
N = list(input())
num = list(map(lambda x: int(x) , N))
for i in range(8):
sum_val = num[0]
for j in range(3):
if i >> j & 1:
sum_val += num[j + 1]
else:
sum_val -= num[j + 1]
if sum_val == 7:
print(num[0] , end = '')
for j in range(3):
if i >> j & 1:
print("+" , end = '')
else:
print("-",end = '')
print(num[j + 1] , end = '')
print('=7')
exit()
| 11 | 19 | 338 | 518 |
S = eval(input())
for i in range(2 ** len(S) - 1):
work = S
for j in range(1, len(S)):
if i >> (j - 1) & 1:
work = work[: 2 * j - 1] + "+" + work[2 * j - 1 :]
else:
work = work[: 2 * j - 1] + "-" + work[2 * j - 1 :]
if eval(work) == 7:
print(("{0}=7".format(work)))
exit()
|
N = list(input())
num = list(map(lambda x: int(x), N))
for i in range(8):
sum_val = num[0]
for j in range(3):
if i >> j & 1:
sum_val += num[j + 1]
else:
sum_val -= num[j + 1]
if sum_val == 7:
print(num[0], end="")
for j in range(3):
if i >> j & 1:
print("+", end="")
else:
print("-", end="")
print(num[j + 1], end="")
print("=7")
exit()
| false | 42.105263 |
[
"-S = eval(input())",
"-for i in range(2 ** len(S) - 1):",
"- work = S",
"- for j in range(1, len(S)):",
"- if i >> (j - 1) & 1:",
"- work = work[: 2 * j - 1] + \"+\" + work[2 * j - 1 :]",
"+N = list(input())",
"+num = list(map(lambda x: int(x), N))",
"+for i in range(8):",
"+ sum_val = num[0]",
"+ for j in range(3):",
"+ if i >> j & 1:",
"+ sum_val += num[j + 1]",
"- work = work[: 2 * j - 1] + \"-\" + work[2 * j - 1 :]",
"- if eval(work) == 7:",
"- print((\"{0}=7\".format(work)))",
"+ sum_val -= num[j + 1]",
"+ if sum_val == 7:",
"+ print(num[0], end=\"\")",
"+ for j in range(3):",
"+ if i >> j & 1:",
"+ print(\"+\", end=\"\")",
"+ else:",
"+ print(\"-\", end=\"\")",
"+ print(num[j + 1], end=\"\")",
"+ print(\"=7\")"
] | false | 0.062416 | 0.121564 | 0.513445 |
[
"s064223422",
"s297512702"
] |
u922901775
|
p03566
|
python
|
s110753832
|
s380963858
| 1,991 | 1,150 | 15,232 | 46,484 |
Accepted
|
Accepted
| 42.24 |
#!/usr/bin/env python3
import sys
import numpy as np
def solve(N: int, T: "List[int]", V: "List[int]"):
t_period = [0 for i in range(N+1)]
for i in range(N):
t_period[i+1] = t_period[i] + T[i]*2
limit = np.zeros((t_period[N]+1,))
for i in range(1, N):
limit[t_period[i]] = min((V[i-1], V[i]))
for i in range(N):
limit[t_period[i]+1:t_period[i+1]] = V[i]
speed = np.zeros((t_period[N]+1,))
for v in range(1, 201):
speed[v:t_period[N]+1-v] = np.min(
[limit[v:t_period[N]+1-v], speed[v-1:t_period[N]-v]+0.5, speed[v+1:t_period[N]+2-v]+0.5],
axis=0
)
total = 0
for t in range(t_period[N]):
total += (speed[t] + speed[t+1]) * 0.5 * 0.5
print(total)
return
# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template)
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
t = [ int(next(tokens)) for _ in range(N) ] # type: "List[int]"
v = [ int(next(tokens)) for _ in range(N) ] # type: "List[int]"
solve(N, t, v)
if __name__ == '__main__':
main()
|
#!/usr/bin/env python3
import sys
import numpy as np
def solve(N: int, T: "List[int]", V: "List[int]"):
t_period = [0 for i in range(N+1)]
for i in range(N):
t_period[i+1] = t_period[i] + T[i]*2
V = [0] + V + [0]
limit = np.zeros((N+2,t_period[N]+1))
line = np.arange(0, t_period[N]/2+0.5, 0.5)
for i in range(N+2):
if i == 0:
l, r = 0, 0
elif i == N+1:
l, r = t_period[N], t_period[N]
else:
l, r = t_period[i-1], t_period[i]
limit[i] = np.max([-line + l * 0.5, line * 0, line - r * 0.5], axis=0) + V[i]
speed = np.min(limit, axis=0)
total = 0
for t in range(t_period[N]):
total += (speed[t] + speed[t+1]) * 0.5 * 0.5
print(total)
return
# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template)
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
t = [ int(next(tokens)) for _ in range(N) ] # type: "List[int]"
v = [ int(next(tokens)) for _ in range(N) ] # type: "List[int]"
solve(N, t, v)
if __name__ == '__main__':
main()
| 47 | 46 | 1,400 | 1,384 |
#!/usr/bin/env python3
import sys
import numpy as np
def solve(N: int, T: "List[int]", V: "List[int]"):
t_period = [0 for i in range(N + 1)]
for i in range(N):
t_period[i + 1] = t_period[i] + T[i] * 2
limit = np.zeros((t_period[N] + 1,))
for i in range(1, N):
limit[t_period[i]] = min((V[i - 1], V[i]))
for i in range(N):
limit[t_period[i] + 1 : t_period[i + 1]] = V[i]
speed = np.zeros((t_period[N] + 1,))
for v in range(1, 201):
speed[v : t_period[N] + 1 - v] = np.min(
[
limit[v : t_period[N] + 1 - v],
speed[v - 1 : t_period[N] - v] + 0.5,
speed[v + 1 : t_period[N] + 2 - v] + 0.5,
],
axis=0,
)
total = 0
for t in range(t_period[N]):
total += (speed[t] + speed[t + 1]) * 0.5 * 0.5
print(total)
return
# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template)
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
t = [int(next(tokens)) for _ in range(N)] # type: "List[int]"
v = [int(next(tokens)) for _ in range(N)] # type: "List[int]"
solve(N, t, v)
if __name__ == "__main__":
main()
|
#!/usr/bin/env python3
import sys
import numpy as np
def solve(N: int, T: "List[int]", V: "List[int]"):
t_period = [0 for i in range(N + 1)]
for i in range(N):
t_period[i + 1] = t_period[i] + T[i] * 2
V = [0] + V + [0]
limit = np.zeros((N + 2, t_period[N] + 1))
line = np.arange(0, t_period[N] / 2 + 0.5, 0.5)
for i in range(N + 2):
if i == 0:
l, r = 0, 0
elif i == N + 1:
l, r = t_period[N], t_period[N]
else:
l, r = t_period[i - 1], t_period[i]
limit[i] = np.max([-line + l * 0.5, line * 0, line - r * 0.5], axis=0) + V[i]
speed = np.min(limit, axis=0)
total = 0
for t in range(t_period[N]):
total += (speed[t] + speed[t + 1]) * 0.5 * 0.5
print(total)
return
# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template)
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
t = [int(next(tokens)) for _ in range(N)] # type: "List[int]"
v = [int(next(tokens)) for _ in range(N)] # type: "List[int]"
solve(N, t, v)
if __name__ == "__main__":
main()
| false | 2.12766 |
[
"- limit = np.zeros((t_period[N] + 1,))",
"- for i in range(1, N):",
"- limit[t_period[i]] = min((V[i - 1], V[i]))",
"- for i in range(N):",
"- limit[t_period[i] + 1 : t_period[i + 1]] = V[i]",
"- speed = np.zeros((t_period[N] + 1,))",
"- for v in range(1, 201):",
"- speed[v : t_period[N] + 1 - v] = np.min(",
"- [",
"- limit[v : t_period[N] + 1 - v],",
"- speed[v - 1 : t_period[N] - v] + 0.5,",
"- speed[v + 1 : t_period[N] + 2 - v] + 0.5,",
"- ],",
"- axis=0,",
"- )",
"+ V = [0] + V + [0]",
"+ limit = np.zeros((N + 2, t_period[N] + 1))",
"+ line = np.arange(0, t_period[N] / 2 + 0.5, 0.5)",
"+ for i in range(N + 2):",
"+ if i == 0:",
"+ l, r = 0, 0",
"+ elif i == N + 1:",
"+ l, r = t_period[N], t_period[N]",
"+ else:",
"+ l, r = t_period[i - 1], t_period[i]",
"+ limit[i] = np.max([-line + l * 0.5, line * 0, line - r * 0.5], axis=0) + V[i]",
"+ speed = np.min(limit, axis=0)"
] | false | 0.497525 | 0.549498 | 0.905418 |
[
"s110753832",
"s380963858"
] |
u131811591
|
p02376
|
python
|
s478735245
|
s153730840
| 50 | 30 | 6,336 | 6,336 |
Accepted
|
Accepted
| 40 |
import sys
from collections import deque
class MaxFlow:
class Edge:
def __init__(self, to, cap, rev):
self.to, self.cap, self.rev = to, cap, rev
def __init__(self, node_size, inf):
self._node = node_size
self._inf = inf
self._level = [-1]*self._node
self._iter = [0]*self._node
self._graph = [[] for _ in range(self._node)]
def add_edge(self, from_, to, cap):
self._graph[from_].append(self.Edge(to, cap, len(self._graph[to])))
self._graph[to].append(self.Edge(from_, 0, len(self._graph[from_])-1))
def bfs(self, start):
for i in range(self._node):
self._level[i] = -1
que = deque()
self._level[start] = 0
que.append(start)
while que:
cur_vertex = que.popleft()
for e in self._graph[cur_vertex]:
if self._level[e.to] < 0 < e.cap:
self._level[e.to] = self._level[cur_vertex] + 1
que.append(e.to)
def dfs(self, cur_vertex, end_vertex, flow):
if cur_vertex == end_vertex:
return flow
for e in self._graph[cur_vertex][self._iter[cur_vertex]:len(self._graph[cur_vertex])]:
if e.cap > 0 and self._level[cur_vertex] < self._level[e.to]:
flowed = self.dfs(e.to, end_vertex, min(flow, e.cap))
if flowed > 0:
e.cap -= flowed
self._graph[e.to][e.rev].cap += flowed
return flowed
return 0
def solve(self, source, sink):
flow = 0
while True:
self.bfs(source)
if self._level[sink] < 0:
return flow
for i in range(self._node):
self._iter[i] = 0
while True:
f = self.dfs(source, sink, self._inf)
if f == 0:
break
flow += f
def main():
n, m = list(map(int, sys.stdin.readline().split()))
mf = MaxFlow(n, 10 ** 4)
for _ in range(m):
u, v, c = list(map(int, sys.stdin.readline().split()))
mf.add_edge(u, v, c)
print((mf.solve(0, n - 1)))
if __name__ == '__main__':
main()
|
import sys
from collections import deque
class MaxFlow:
class Edge:
def __init__(self, to, cap, rev):
self.to, self.cap, self.rev = to, cap, rev
def __init__(self, node_size, inf):
self._node = node_size
self._inf = inf
self._level = [-1]*self._node
self._iter = [0]*self._node
self._graph = [[] for _ in range(self._node)]
def add_edge(self, from_, to, cap):
self._graph[from_].append(self.Edge(to, cap, len(self._graph[to])))
self._graph[to].append(self.Edge(from_, 0, len(self._graph[from_])-1))
def bfs(self, start):
self._level = [-1]*self._node
que = deque()
self._level[start] = 0
que.append(start)
while que:
cur_vertex = que.popleft()
for e in self._graph[cur_vertex]:
if e.cap > 0 > self._level[e.to]:
self._level[e.to] = self._level[cur_vertex] + 1
que.append(e.to)
def dfs(self, cur_vertex, end_vertex, flow):
if cur_vertex == end_vertex:
return flow
while self._iter[cur_vertex] < len(self._graph[cur_vertex]):
e = self._graph[cur_vertex][self._iter[cur_vertex]]
if e.cap > 0 and self._level[cur_vertex] < self._level[e.to]:
flowed = self.dfs(e.to, end_vertex, min(flow, e.cap))
if flowed > 0:
e.cap -= flowed
self._graph[e.to][e.rev].cap += flowed
return flowed
self._iter[cur_vertex] += 1
return 0
def solve(self, source, sink):
flow = 0
while True:
self.bfs(source)
if self._level[sink] < 0:
return flow
self._iter = [0]*self._node
while True:
f = self.dfs(source, sink, self._inf)
if f == 0:
break
flow += f
if __name__ == '__main__':
n, m = list(map(int, sys.stdin.readline().split()))
mf = MaxFlow(n, 10**10)
for _ in range(m):
u, v, c = list(map(int, sys.stdin.readline().split()))
mf.add_edge(u, v, c)
print((mf.solve(0, n-1)))
| 71 | 66 | 2,292 | 2,275 |
import sys
from collections import deque
class MaxFlow:
class Edge:
def __init__(self, to, cap, rev):
self.to, self.cap, self.rev = to, cap, rev
def __init__(self, node_size, inf):
self._node = node_size
self._inf = inf
self._level = [-1] * self._node
self._iter = [0] * self._node
self._graph = [[] for _ in range(self._node)]
def add_edge(self, from_, to, cap):
self._graph[from_].append(self.Edge(to, cap, len(self._graph[to])))
self._graph[to].append(self.Edge(from_, 0, len(self._graph[from_]) - 1))
def bfs(self, start):
for i in range(self._node):
self._level[i] = -1
que = deque()
self._level[start] = 0
que.append(start)
while que:
cur_vertex = que.popleft()
for e in self._graph[cur_vertex]:
if self._level[e.to] < 0 < e.cap:
self._level[e.to] = self._level[cur_vertex] + 1
que.append(e.to)
def dfs(self, cur_vertex, end_vertex, flow):
if cur_vertex == end_vertex:
return flow
for e in self._graph[cur_vertex][
self._iter[cur_vertex] : len(self._graph[cur_vertex])
]:
if e.cap > 0 and self._level[cur_vertex] < self._level[e.to]:
flowed = self.dfs(e.to, end_vertex, min(flow, e.cap))
if flowed > 0:
e.cap -= flowed
self._graph[e.to][e.rev].cap += flowed
return flowed
return 0
def solve(self, source, sink):
flow = 0
while True:
self.bfs(source)
if self._level[sink] < 0:
return flow
for i in range(self._node):
self._iter[i] = 0
while True:
f = self.dfs(source, sink, self._inf)
if f == 0:
break
flow += f
def main():
n, m = list(map(int, sys.stdin.readline().split()))
mf = MaxFlow(n, 10**4)
for _ in range(m):
u, v, c = list(map(int, sys.stdin.readline().split()))
mf.add_edge(u, v, c)
print((mf.solve(0, n - 1)))
if __name__ == "__main__":
main()
|
import sys
from collections import deque
class MaxFlow:
class Edge:
def __init__(self, to, cap, rev):
self.to, self.cap, self.rev = to, cap, rev
def __init__(self, node_size, inf):
self._node = node_size
self._inf = inf
self._level = [-1] * self._node
self._iter = [0] * self._node
self._graph = [[] for _ in range(self._node)]
def add_edge(self, from_, to, cap):
self._graph[from_].append(self.Edge(to, cap, len(self._graph[to])))
self._graph[to].append(self.Edge(from_, 0, len(self._graph[from_]) - 1))
def bfs(self, start):
self._level = [-1] * self._node
que = deque()
self._level[start] = 0
que.append(start)
while que:
cur_vertex = que.popleft()
for e in self._graph[cur_vertex]:
if e.cap > 0 > self._level[e.to]:
self._level[e.to] = self._level[cur_vertex] + 1
que.append(e.to)
def dfs(self, cur_vertex, end_vertex, flow):
if cur_vertex == end_vertex:
return flow
while self._iter[cur_vertex] < len(self._graph[cur_vertex]):
e = self._graph[cur_vertex][self._iter[cur_vertex]]
if e.cap > 0 and self._level[cur_vertex] < self._level[e.to]:
flowed = self.dfs(e.to, end_vertex, min(flow, e.cap))
if flowed > 0:
e.cap -= flowed
self._graph[e.to][e.rev].cap += flowed
return flowed
self._iter[cur_vertex] += 1
return 0
def solve(self, source, sink):
flow = 0
while True:
self.bfs(source)
if self._level[sink] < 0:
return flow
self._iter = [0] * self._node
while True:
f = self.dfs(source, sink, self._inf)
if f == 0:
break
flow += f
if __name__ == "__main__":
n, m = list(map(int, sys.stdin.readline().split()))
mf = MaxFlow(n, 10**10)
for _ in range(m):
u, v, c = list(map(int, sys.stdin.readline().split()))
mf.add_edge(u, v, c)
print((mf.solve(0, n - 1)))
| false | 7.042254 |
[
"- for i in range(self._node):",
"- self._level[i] = -1",
"+ self._level = [-1] * self._node",
"- if self._level[e.to] < 0 < e.cap:",
"+ if e.cap > 0 > self._level[e.to]:",
"- for e in self._graph[cur_vertex][",
"- self._iter[cur_vertex] : len(self._graph[cur_vertex])",
"- ]:",
"+ while self._iter[cur_vertex] < len(self._graph[cur_vertex]):",
"+ e = self._graph[cur_vertex][self._iter[cur_vertex]]",
"+ self._iter[cur_vertex] += 1",
"- for i in range(self._node):",
"- self._iter[i] = 0",
"+ self._iter = [0] * self._node",
"-def main():",
"+if __name__ == \"__main__\":",
"- mf = MaxFlow(n, 10**4)",
"+ mf = MaxFlow(n, 10**10)",
"-",
"-",
"-if __name__ == \"__main__\":",
"- main()"
] | false | 0.036992 | 0.036902 | 1.002419 |
[
"s478735245",
"s153730840"
] |
u884323674
|
p03835
|
python
|
s494630950
|
s746312534
| 1,669 | 1,212 | 3,060 | 9,036 |
Accepted
|
Accepted
| 27.38 |
K, S = list(map(int, input().split()))
count = 0
for i in range(K+1):
for j in range(K+1):
k = S - (i + j)
if 0 <= k <= K:
count += 1
print(count)
|
K, S = list(map(int, input().split()))
ans = 0
for x in range(K+1):
for y in range(K+1):
z = S- (x + y)
if 0 <= z <= K:
ans += 1
print(ans)
| 10 | 10 | 195 | 176 |
K, S = list(map(int, input().split()))
count = 0
for i in range(K + 1):
for j in range(K + 1):
k = S - (i + j)
if 0 <= k <= K:
count += 1
print(count)
|
K, S = list(map(int, input().split()))
ans = 0
for x in range(K + 1):
for y in range(K + 1):
z = S - (x + y)
if 0 <= z <= K:
ans += 1
print(ans)
| false | 0 |
[
"-count = 0",
"-for i in range(K + 1):",
"- for j in range(K + 1):",
"- k = S - (i + j)",
"- if 0 <= k <= K:",
"- count += 1",
"-print(count)",
"+ans = 0",
"+for x in range(K + 1):",
"+ for y in range(K + 1):",
"+ z = S - (x + y)",
"+ if 0 <= z <= K:",
"+ ans += 1",
"+print(ans)"
] | false | 0.040283 | 0.035976 | 1.119734 |
[
"s494630950",
"s746312534"
] |
u256868077
|
p03826
|
python
|
s436099247
|
s928552986
| 20 | 17 | 3,060 | 2,940 |
Accepted
|
Accepted
| 15 |
a,b,c,d=list(map(int,input().split()))
if a*b >= c*d:
print((a*b))
else:
print((c*d))
|
a,b,c,d=list(map(int,input().split()))
print((max(a*b,c*d)))
| 5 | 2 | 83 | 54 |
a, b, c, d = list(map(int, input().split()))
if a * b >= c * d:
print((a * b))
else:
print((c * d))
|
a, b, c, d = list(map(int, input().split()))
print((max(a * b, c * d)))
| false | 60 |
[
"-if a * b >= c * d:",
"- print((a * b))",
"-else:",
"- print((c * d))",
"+print((max(a * b, c * d)))"
] | false | 0.034276 | 0.037409 | 0.916251 |
[
"s436099247",
"s928552986"
] |
u644907318
|
p03659
|
python
|
s336880278
|
s053586378
| 218 | 128 | 24,832 | 100,536 |
Accepted
|
Accepted
| 41.28 |
N = int(eval(input()))
A = list(map(int,input().split()))
B = [0]
for i in range(N):
B.append(B[i]+A[i])
dmin = 10**15
for i in range(1,N):
dmin = min(dmin,abs(B[N]-2*B[i]))
print(dmin)
|
N = int(eval(input()))
A = list(map(int,input().split()))
B = [0 for _ in range(N+1)]
for i in range(1,N+1):
B[i] = B[i-1]+A[i-1]
cmin = 10**15
for i in range(1,N):
cmin = min(cmin,abs(2*B[i]-B[N]))
print(cmin)
| 9 | 9 | 195 | 220 |
N = int(eval(input()))
A = list(map(int, input().split()))
B = [0]
for i in range(N):
B.append(B[i] + A[i])
dmin = 10**15
for i in range(1, N):
dmin = min(dmin, abs(B[N] - 2 * B[i]))
print(dmin)
|
N = int(eval(input()))
A = list(map(int, input().split()))
B = [0 for _ in range(N + 1)]
for i in range(1, N + 1):
B[i] = B[i - 1] + A[i - 1]
cmin = 10**15
for i in range(1, N):
cmin = min(cmin, abs(2 * B[i] - B[N]))
print(cmin)
| false | 0 |
[
"-B = [0]",
"-for i in range(N):",
"- B.append(B[i] + A[i])",
"-dmin = 10**15",
"+B = [0 for _ in range(N + 1)]",
"+for i in range(1, N + 1):",
"+ B[i] = B[i - 1] + A[i - 1]",
"+cmin = 10**15",
"- dmin = min(dmin, abs(B[N] - 2 * B[i]))",
"-print(dmin)",
"+ cmin = min(cmin, abs(2 * B[i] - B[N]))",
"+print(cmin)"
] | false | 0.042058 | 0.04212 | 0.998537 |
[
"s336880278",
"s053586378"
] |
u925626880
|
p03448
|
python
|
s726194290
|
s898553298
| 45 | 32 | 3,060 | 3,060 |
Accepted
|
Accepted
| 28.89 |
a = int(eval(input())) # 500
b = int(eval(input())) # 100
c = int(eval(input())) # 50
x = int(eval(input()))
ans = 0
for i in range(a+1):
I = i*500
for j in range(b+1):
J = j*100
for k in range(c+1):
K = k*50
if I+J+K == x:
ans +=1
print(ans)
|
def main():
a = int(eval(input())) # 500
b = int(eval(input())) # 100
c = int(eval(input())) # 50
x = int(eval(input()))
ans = 0
for i in range(a+1):
I = i*500
for j in range(b+1):
J = j*100
for k in range(c+1):
K = k*50
if I+J+K == x:
ans +=1
print(ans)
if __name__ == '__main__':
main()
| 17 | 21 | 303 | 414 |
a = int(eval(input())) # 500
b = int(eval(input())) # 100
c = int(eval(input())) # 50
x = int(eval(input()))
ans = 0
for i in range(a + 1):
I = i * 500
for j in range(b + 1):
J = j * 100
for k in range(c + 1):
K = k * 50
if I + J + K == x:
ans += 1
print(ans)
|
def main():
a = int(eval(input())) # 500
b = int(eval(input())) # 100
c = int(eval(input())) # 50
x = int(eval(input()))
ans = 0
for i in range(a + 1):
I = i * 500
for j in range(b + 1):
J = j * 100
for k in range(c + 1):
K = k * 50
if I + J + K == x:
ans += 1
print(ans)
if __name__ == "__main__":
main()
| false | 19.047619 |
[
"-a = int(eval(input())) # 500",
"-b = int(eval(input())) # 100",
"-c = int(eval(input())) # 50",
"-x = int(eval(input()))",
"-ans = 0",
"-for i in range(a + 1):",
"- I = i * 500",
"- for j in range(b + 1):",
"- J = j * 100",
"- for k in range(c + 1):",
"- K = k * 50",
"- if I + J + K == x:",
"- ans += 1",
"-print(ans)",
"+def main():",
"+ a = int(eval(input())) # 500",
"+ b = int(eval(input())) # 100",
"+ c = int(eval(input())) # 50",
"+ x = int(eval(input()))",
"+ ans = 0",
"+ for i in range(a + 1):",
"+ I = i * 500",
"+ for j in range(b + 1):",
"+ J = j * 100",
"+ for k in range(c + 1):",
"+ K = k * 50",
"+ if I + J + K == x:",
"+ ans += 1",
"+ print(ans)",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.110822 | 0.007733 | 14.331065 |
[
"s726194290",
"s898553298"
] |
u347640436
|
p03074
|
python
|
s391351887
|
s185087598
| 109 | 74 | 5,152 | 7,164 |
Accepted
|
Accepted
| 32.11 |
# しゃくとり法
N, K = list(map(int, input().split()))
S = list(map(int, eval(input())))
j = 1
r = 0
t = []
for i in range(N):
if S[i] == j:
r += 1
else:
t.append(r)
r = 1
j ^= 1
t.append(r)
if j == 0:
t.append(0)
if K >= (len(t) - 1) // 2:
print((sum(t)))
else:
result = sum(t[:2 * K + 1])
j = result
i = 2
while i + 2 * K < len(t):
j += t[i + 2 * K - 1] + t[i + 2 * K] - (t[i - 2] + t[i - 1])
result = max(result, j)
i += 2
print(result)
|
# 累積和
from sys import exit
N, K = list(map(int, input().split()))
S = eval(input())
p = '1'
count = 0
cs = []
for c in S:
if c != p:
cs.append(count)
p = c
count = 1
else:
count += 1
cs.append(count)
if p == '0':
cs.append(0)
if len(cs) < 2 * K:
print(N)
exit()
for i in range(1, len(cs)):
cs[i] += cs[i - 1]
result = cs[2 * K]
for i in range(2, len(cs) - 2 * K, 2):
t = cs[2 * K + i] - cs[i - 1]
if t > result:
result = t
print(result)
| 29 | 33 | 541 | 498 |
# しゃくとり法
N, K = list(map(int, input().split()))
S = list(map(int, eval(input())))
j = 1
r = 0
t = []
for i in range(N):
if S[i] == j:
r += 1
else:
t.append(r)
r = 1
j ^= 1
t.append(r)
if j == 0:
t.append(0)
if K >= (len(t) - 1) // 2:
print((sum(t)))
else:
result = sum(t[: 2 * K + 1])
j = result
i = 2
while i + 2 * K < len(t):
j += t[i + 2 * K - 1] + t[i + 2 * K] - (t[i - 2] + t[i - 1])
result = max(result, j)
i += 2
print(result)
|
# 累積和
from sys import exit
N, K = list(map(int, input().split()))
S = eval(input())
p = "1"
count = 0
cs = []
for c in S:
if c != p:
cs.append(count)
p = c
count = 1
else:
count += 1
cs.append(count)
if p == "0":
cs.append(0)
if len(cs) < 2 * K:
print(N)
exit()
for i in range(1, len(cs)):
cs[i] += cs[i - 1]
result = cs[2 * K]
for i in range(2, len(cs) - 2 * K, 2):
t = cs[2 * K + i] - cs[i - 1]
if t > result:
result = t
print(result)
| false | 12.121212 |
[
"-# しゃくとり法",
"+# 累積和",
"+from sys import exit",
"+",
"-S = list(map(int, eval(input())))",
"-j = 1",
"-r = 0",
"-t = []",
"-for i in range(N):",
"- if S[i] == j:",
"- r += 1",
"+S = eval(input())",
"+p = \"1\"",
"+count = 0",
"+cs = []",
"+for c in S:",
"+ if c != p:",
"+ cs.append(count)",
"+ p = c",
"+ count = 1",
"- t.append(r)",
"- r = 1",
"- j ^= 1",
"-t.append(r)",
"-if j == 0:",
"- t.append(0)",
"-if K >= (len(t) - 1) // 2:",
"- print((sum(t)))",
"-else:",
"- result = sum(t[: 2 * K + 1])",
"- j = result",
"- i = 2",
"- while i + 2 * K < len(t):",
"- j += t[i + 2 * K - 1] + t[i + 2 * K] - (t[i - 2] + t[i - 1])",
"- result = max(result, j)",
"- i += 2",
"- print(result)",
"+ count += 1",
"+cs.append(count)",
"+if p == \"0\":",
"+ cs.append(0)",
"+if len(cs) < 2 * K:",
"+ print(N)",
"+ exit()",
"+for i in range(1, len(cs)):",
"+ cs[i] += cs[i - 1]",
"+result = cs[2 * K]",
"+for i in range(2, len(cs) - 2 * K, 2):",
"+ t = cs[2 * K + i] - cs[i - 1]",
"+ if t > result:",
"+ result = t",
"+print(result)"
] | false | 0.007023 | 0.061453 | 0.114277 |
[
"s391351887",
"s185087598"
] |
u186206732
|
p03162
|
python
|
s664164970
|
s935693074
| 444 | 399 | 14,980 | 14,996 |
Accepted
|
Accepted
| 10.14 |
n = int(eval(input()))
a = [0]
b = [0]
c = [0]
for i in range(n):
aa,bb,cc = list(map(int,input().split()))
a.append(max(b[i] + aa, c[i] + aa))
b.append(max(a[i] + bb, c[i] + bb))
c.append(max(a[i] + cc, b[i] + cc))
print((max(a[-1], b[-1], c[-1])))
|
def main():
n = int(eval(input()))
a = [0]
b = [0]
c = [0]
for i in range(n):
aa,bb,cc = list(map(int,input().split()))
a.append(max(b[i] + aa, c[i] + aa))
b.append(max(a[i] + bb, c[i] + bb))
c.append(max(a[i] + cc, b[i] + cc))
print((max(a[-1], b[-1], c[-1])))
main()
| 12 | 15 | 269 | 307 |
n = int(eval(input()))
a = [0]
b = [0]
c = [0]
for i in range(n):
aa, bb, cc = list(map(int, input().split()))
a.append(max(b[i] + aa, c[i] + aa))
b.append(max(a[i] + bb, c[i] + bb))
c.append(max(a[i] + cc, b[i] + cc))
print((max(a[-1], b[-1], c[-1])))
|
def main():
n = int(eval(input()))
a = [0]
b = [0]
c = [0]
for i in range(n):
aa, bb, cc = list(map(int, input().split()))
a.append(max(b[i] + aa, c[i] + aa))
b.append(max(a[i] + bb, c[i] + bb))
c.append(max(a[i] + cc, b[i] + cc))
print((max(a[-1], b[-1], c[-1])))
main()
| false | 20 |
[
"-n = int(eval(input()))",
"-a = [0]",
"-b = [0]",
"-c = [0]",
"-for i in range(n):",
"- aa, bb, cc = list(map(int, input().split()))",
"- a.append(max(b[i] + aa, c[i] + aa))",
"- b.append(max(a[i] + bb, c[i] + bb))",
"- c.append(max(a[i] + cc, b[i] + cc))",
"-print((max(a[-1], b[-1], c[-1])))",
"+def main():",
"+ n = int(eval(input()))",
"+ a = [0]",
"+ b = [0]",
"+ c = [0]",
"+ for i in range(n):",
"+ aa, bb, cc = list(map(int, input().split()))",
"+ a.append(max(b[i] + aa, c[i] + aa))",
"+ b.append(max(a[i] + bb, c[i] + bb))",
"+ c.append(max(a[i] + cc, b[i] + cc))",
"+ print((max(a[-1], b[-1], c[-1])))",
"+",
"+",
"+main()"
] | false | 0.09441 | 0.068737 | 1.373503 |
[
"s664164970",
"s935693074"
] |
u436484848
|
p04006
|
python
|
s487233596
|
s061936492
| 754 | 662 | 3,316 | 3,316 |
Accepted
|
Accepted
| 12.2 |
def read():
return [int(i) for i in input().split(" ")]
N, x = read()
A = read()
ans = sum(A)
tempcost = ans
BC = A[:]
for i in range(1, N):
BC = [BC[j - 1] if BC[j - 1] < BC[j] else BC[j] for j in range(N)]
tempcost = x * i + sum(BC)
if(ans > tempcost):
ans = tempcost
else:
break
print(ans)
|
def read():
return [int(i) for i in input().split(" ")]
N, x = read()
A = read()
ans = sum(A)
tempcost = ans
BC = A[:]
xt = 0
for i in range(1, N):
xt += x
BC = [BC[j - 1] if BC[j - 1] < BC[j] else BC[j] for j in range(N)]
tempcost = xt + sum(BC)
if(ans > tempcost):
ans = tempcost
else:
break
print(ans)
| 15 | 17 | 317 | 332 |
def read():
return [int(i) for i in input().split(" ")]
N, x = read()
A = read()
ans = sum(A)
tempcost = ans
BC = A[:]
for i in range(1, N):
BC = [BC[j - 1] if BC[j - 1] < BC[j] else BC[j] for j in range(N)]
tempcost = x * i + sum(BC)
if ans > tempcost:
ans = tempcost
else:
break
print(ans)
|
def read():
return [int(i) for i in input().split(" ")]
N, x = read()
A = read()
ans = sum(A)
tempcost = ans
BC = A[:]
xt = 0
for i in range(1, N):
xt += x
BC = [BC[j - 1] if BC[j - 1] < BC[j] else BC[j] for j in range(N)]
tempcost = xt + sum(BC)
if ans > tempcost:
ans = tempcost
else:
break
print(ans)
| false | 11.764706 |
[
"+xt = 0",
"+ xt += x",
"- tempcost = x * i + sum(BC)",
"+ tempcost = xt + sum(BC)"
] | false | 0.11985 | 0.08744 | 1.370652 |
[
"s487233596",
"s061936492"
] |
u808427016
|
p03661
|
python
|
s462563491
|
s728101630
| 184 | 162 | 30,028 | 24,168 |
Accepted
|
Accepted
| 11.96 |
import itertools
N = int(eval(input()))
A = [int(_) for _ in input().split()]
ts = list(itertools.accumulate(A))
total = ts[-1]
total_half = total / 2
r = sorted(ts[:-1], key=lambda x:abs(x - total_half))[0]
print((abs(total - r - r)))
|
import itertools
N = int(eval(input()))
A = [int(_) for _ in input().split()]
ts = list(itertools.accumulate(A))
total = ts[-1]
r = list(itertools.accumulate((abs(total - t * 2) for t in ts[:-1]), min))[-1]
print(r)
| 11 | 11 | 241 | 224 |
import itertools
N = int(eval(input()))
A = [int(_) for _ in input().split()]
ts = list(itertools.accumulate(A))
total = ts[-1]
total_half = total / 2
r = sorted(ts[:-1], key=lambda x: abs(x - total_half))[0]
print((abs(total - r - r)))
|
import itertools
N = int(eval(input()))
A = [int(_) for _ in input().split()]
ts = list(itertools.accumulate(A))
total = ts[-1]
r = list(itertools.accumulate((abs(total - t * 2) for t in ts[:-1]), min))[-1]
print(r)
| false | 0 |
[
"-total_half = total / 2",
"-r = sorted(ts[:-1], key=lambda x: abs(x - total_half))[0]",
"-print((abs(total - r - r)))",
"+r = list(itertools.accumulate((abs(total - t * 2) for t in ts[:-1]), min))[-1]",
"+print(r)"
] | false | 0.046609 | 0.047779 | 0.9755 |
[
"s462563491",
"s728101630"
] |
u631277801
|
p03503
|
python
|
s290642478
|
s238977588
| 282 | 60 | 3,064 | 3,064 |
Accepted
|
Accepted
| 78.72 |
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**5)
def li(): return list(map(int, stdin.readline().split()))
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return list(map(float, stdin.readline().split()))
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())
n = ni()
f = [int("".join(ls()), 2) for _ in range(n)]
p = [list(li()) for _ in range(n)]
# bit全探索
ans = -float("inf")
for bit in range(1, 1<<10):
profit = 0
for i,fi in enumerate(f):
both = 0
for mask in range(10):
if bit&(1<<mask) and fi&(1<<mask):
both += 1
profit += p[i][both]
ans = max(ans, profit)
print(ans)
|
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**5)
def li(): return list(map(int, stdin.readline().split()))
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return list(map(float, stdin.readline().split()))
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())
n = ni()
f = [int("".join(ls()), 2) for _ in range(n)]
p = [list(li()) for _ in range(n)]
def dfs(cur:int, depth:int):
if depth == 10:
if cur == 0:
return -float("inf")
else:
return sum([p[i][bin(cur&fi).count("1")] for i, fi in enumerate(f)])
else:
return max(dfs(cur+(1<<depth), depth+1),
dfs(cur, depth+1))
print((dfs(0,0)))
| 35 | 30 | 884 | 881 |
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**5)
def li():
return list(map(int, stdin.readline().split()))
def li_():
return [int(x) - 1 for x in stdin.readline().split()]
def lf():
return list(map(float, stdin.readline().split()))
def ls():
return stdin.readline().split()
def ns():
return stdin.readline().rstrip()
def lc():
return list(ns())
def ni():
return int(stdin.readline())
def nf():
return float(stdin.readline())
n = ni()
f = [int("".join(ls()), 2) for _ in range(n)]
p = [list(li()) for _ in range(n)]
# bit全探索
ans = -float("inf")
for bit in range(1, 1 << 10):
profit = 0
for i, fi in enumerate(f):
both = 0
for mask in range(10):
if bit & (1 << mask) and fi & (1 << mask):
both += 1
profit += p[i][both]
ans = max(ans, profit)
print(ans)
|
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**5)
def li():
return list(map(int, stdin.readline().split()))
def li_():
return [int(x) - 1 for x in stdin.readline().split()]
def lf():
return list(map(float, stdin.readline().split()))
def ls():
return stdin.readline().split()
def ns():
return stdin.readline().rstrip()
def lc():
return list(ns())
def ni():
return int(stdin.readline())
def nf():
return float(stdin.readline())
n = ni()
f = [int("".join(ls()), 2) for _ in range(n)]
p = [list(li()) for _ in range(n)]
def dfs(cur: int, depth: int):
if depth == 10:
if cur == 0:
return -float("inf")
else:
return sum([p[i][bin(cur & fi).count("1")] for i, fi in enumerate(f)])
else:
return max(dfs(cur + (1 << depth), depth + 1), dfs(cur, depth + 1))
print((dfs(0, 0)))
| false | 14.285714 |
[
"-# bit全探索",
"-ans = -float(\"inf\")",
"-for bit in range(1, 1 << 10):",
"- profit = 0",
"- for i, fi in enumerate(f):",
"- both = 0",
"- for mask in range(10):",
"- if bit & (1 << mask) and fi & (1 << mask):",
"- both += 1",
"- profit += p[i][both]",
"- ans = max(ans, profit)",
"-print(ans)",
"+",
"+",
"+def dfs(cur: int, depth: int):",
"+ if depth == 10:",
"+ if cur == 0:",
"+ return -float(\"inf\")",
"+ else:",
"+ return sum([p[i][bin(cur & fi).count(\"1\")] for i, fi in enumerate(f)])",
"+ else:",
"+ return max(dfs(cur + (1 << depth), depth + 1), dfs(cur, depth + 1))",
"+",
"+",
"+print((dfs(0, 0)))"
] | false | 0.103393 | 0.062793 | 1.646555 |
[
"s290642478",
"s238977588"
] |
u259755734
|
p02969
|
python
|
s887254292
|
s412079476
| 24 | 17 | 3,060 | 2,940 |
Accepted
|
Accepted
| 29.17 |
print((3 * int(eval(input()))**2))
|
r=int(eval(input()))
print((3*r*r))
| 1 | 2 | 26 | 28 |
print((3 * int(eval(input())) ** 2))
|
r = int(eval(input()))
print((3 * r * r))
| false | 50 |
[
"-print((3 * int(eval(input())) ** 2))",
"+r = int(eval(input()))",
"+print((3 * r * r))"
] | false | 0.059167 | 0.037621 | 1.572727 |
[
"s887254292",
"s412079476"
] |
u186838327
|
p02820
|
python
|
s041503090
|
s577470949
| 95 | 79 | 3,444 | 68,828 |
Accepted
|
Accepted
| 16.84 |
n, k = list(map(int, input().split()))
r, s, p = list(map(int, input().split()))
t = str(eval(input()))
t_ = ''
ans = 0
for i in range(n):
if i < k:
if t[i] == 'r':
t_ += 'p'
ans += p
elif t[i] == 's':
t_ += 'r'
ans += r
else:
t_ += 's'
ans += s
elif i+k <= n-1:
if t[i] == 'r':
if t_[i-k] != 'p':
t_ += 'p'
ans += p
else:
if t[i+k] == 'p':
t_ += 'r'
else:
t_ += 's'
elif t[i] == 's':
if t_[i-k] != 'r':
t_ += 'r'
ans += r
else:
if t[i+k] == 'p':
t_ += 'p'
else:
t_ += 's'
else:
if t_[i-k] != 's':
t_ += 's'
ans += s
else:
if t[i+k] == 's':
t_ += 'p'
else:
t_ += 'r'
else:
if t[i] == 'r':
if t_[i-k] != 'p':
t_ += 'p'
ans += p
else:
if t[i-k] == 'r':
t_ += 's'
else:
t_ += 'r'
elif t[i] == 's':
if t_[i-k] != 'r':
t_ += 'r'
ans += r
else:
if t[i-k] == 'p':
t_ += 's'
else:
t_ += 'p'
else:
if t_[i-k] != 's':
t_ += 's'
ans += s
else:
if t[i-k] == 'r':
t_ += 'p'
else:
t_ += 'r'
print(ans)
#print(t_)
|
n, k = list(map(int, input().split()))
r, s, p = list(map(int, input().split()))
t = str(eval(input()))
ans = 0
temp = [0]*n
for i in range(n):
if i <= k-1:
if t[i] == 'r':
ans += p
elif t[i] == 's':
ans += r
else:
ans += s
else:
if t[i-k] == t[i]:
if temp[i-k] == 0:
temp[i] = -1
else:
if t[i] == 'r':
ans += p
elif t[i] == 's':
ans += r
else:
ans += s
temp[i] = 0
else:
if t[i] == 'r':
ans += p
elif t[i] == 's':
ans += r
else:
ans += s
temp[i] = 0
#print(i, ans)
print(ans)
| 76 | 37 | 1,882 | 845 |
n, k = list(map(int, input().split()))
r, s, p = list(map(int, input().split()))
t = str(eval(input()))
t_ = ""
ans = 0
for i in range(n):
if i < k:
if t[i] == "r":
t_ += "p"
ans += p
elif t[i] == "s":
t_ += "r"
ans += r
else:
t_ += "s"
ans += s
elif i + k <= n - 1:
if t[i] == "r":
if t_[i - k] != "p":
t_ += "p"
ans += p
else:
if t[i + k] == "p":
t_ += "r"
else:
t_ += "s"
elif t[i] == "s":
if t_[i - k] != "r":
t_ += "r"
ans += r
else:
if t[i + k] == "p":
t_ += "p"
else:
t_ += "s"
else:
if t_[i - k] != "s":
t_ += "s"
ans += s
else:
if t[i + k] == "s":
t_ += "p"
else:
t_ += "r"
else:
if t[i] == "r":
if t_[i - k] != "p":
t_ += "p"
ans += p
else:
if t[i - k] == "r":
t_ += "s"
else:
t_ += "r"
elif t[i] == "s":
if t_[i - k] != "r":
t_ += "r"
ans += r
else:
if t[i - k] == "p":
t_ += "s"
else:
t_ += "p"
else:
if t_[i - k] != "s":
t_ += "s"
ans += s
else:
if t[i - k] == "r":
t_ += "p"
else:
t_ += "r"
print(ans)
# print(t_)
|
n, k = list(map(int, input().split()))
r, s, p = list(map(int, input().split()))
t = str(eval(input()))
ans = 0
temp = [0] * n
for i in range(n):
if i <= k - 1:
if t[i] == "r":
ans += p
elif t[i] == "s":
ans += r
else:
ans += s
else:
if t[i - k] == t[i]:
if temp[i - k] == 0:
temp[i] = -1
else:
if t[i] == "r":
ans += p
elif t[i] == "s":
ans += r
else:
ans += s
temp[i] = 0
else:
if t[i] == "r":
ans += p
elif t[i] == "s":
ans += r
else:
ans += s
temp[i] = 0
# print(i, ans)
print(ans)
| false | 51.315789 |
[
"-t_ = \"\"",
"+temp = [0] * n",
"- if i < k:",
"+ if i <= k - 1:",
"- t_ += \"p\"",
"- t_ += \"r\"",
"- t_ += \"s\"",
"- elif i + k <= n - 1:",
"- if t[i] == \"r\":",
"- if t_[i - k] != \"p\":",
"- t_ += \"p\"",
"+ else:",
"+ if t[i - k] == t[i]:",
"+ if temp[i - k] == 0:",
"+ temp[i] = -1",
"+ else:",
"+ if t[i] == \"r\":",
"+ ans += p",
"+ elif t[i] == \"s\":",
"+ ans += r",
"+ else:",
"+ ans += s",
"+ temp[i] = 0",
"+ else:",
"+ if t[i] == \"r\":",
"- else:",
"- if t[i + k] == \"p\":",
"- t_ += \"r\"",
"- else:",
"- t_ += \"s\"",
"- elif t[i] == \"s\":",
"- if t_[i - k] != \"r\":",
"- t_ += \"r\"",
"+ elif t[i] == \"s\":",
"- if t[i + k] == \"p\":",
"- t_ += \"p\"",
"- else:",
"- t_ += \"s\"",
"- else:",
"- if t_[i - k] != \"s\":",
"- t_ += \"s\"",
"- else:",
"- if t[i + k] == \"s\":",
"- t_ += \"p\"",
"- else:",
"- t_ += \"r\"",
"- else:",
"- if t[i] == \"r\":",
"- if t_[i - k] != \"p\":",
"- t_ += \"p\"",
"- ans += p",
"- else:",
"- if t[i - k] == \"r\":",
"- t_ += \"s\"",
"- else:",
"- t_ += \"r\"",
"- elif t[i] == \"s\":",
"- if t_[i - k] != \"r\":",
"- t_ += \"r\"",
"- ans += r",
"- else:",
"- if t[i - k] == \"p\":",
"- t_ += \"s\"",
"- else:",
"- t_ += \"p\"",
"- else:",
"- if t_[i - k] != \"s\":",
"- t_ += \"s\"",
"- ans += s",
"- else:",
"- if t[i - k] == \"r\":",
"- t_ += \"p\"",
"- else:",
"- t_ += \"r\"",
"+ temp[i] = 0",
"+ # print(i, ans)",
"-# print(t_)"
] | false | 0.037133 | 0.037167 | 0.99909 |
[
"s041503090",
"s577470949"
] |
u634046173
|
p03687
|
python
|
s774811321
|
s165046461
| 73 | 66 | 67,856 | 65,868 |
Accepted
|
Accepted
| 9.59 |
import collections
s = eval(input())
ls = len(s)
c = collections.Counter(s)
mi = ls
valuePlaces = []
for v,k in list(c.items()):
co = 0
valuePlaces.clear()
for i in range(ls):
if s[i] == v:
valuePlaces.append(i)
ushiro = ls-valuePlaces[-1]-1
#print(ushiro,v)
maxLen = 0
len_vp = len(valuePlaces)
#print(len_vp)
for i in range(len_vp):
start = valuePlaces[i]
if i == 0:
goal = -1
else:
goal = valuePlaces[i-1]
maxLen = max(start-goal-1,maxLen)
mi = min (mi,max(maxLen,ushiro))
print(mi)
|
import collections
s = eval(input())
ls = len(s)
c = set(s)
mi = ls
valuePlaces = []
for v in c:
co = 0
valuePlaces.clear()
for i in range(ls):
if s[i] == v:
valuePlaces.append(i)
ushiro = ls-valuePlaces[-1]-1
maxLen = 0
len_vp = len(valuePlaces)
for i in range(len_vp):
start = valuePlaces[i]
if i == 0:
goal = -1
else:
goal = valuePlaces[i-1]
maxLen = max(start-goal-1,maxLen)
mi = min (mi,max(maxLen,ushiro))
print(mi)
| 29 | 24 | 621 | 546 |
import collections
s = eval(input())
ls = len(s)
c = collections.Counter(s)
mi = ls
valuePlaces = []
for v, k in list(c.items()):
co = 0
valuePlaces.clear()
for i in range(ls):
if s[i] == v:
valuePlaces.append(i)
ushiro = ls - valuePlaces[-1] - 1
# print(ushiro,v)
maxLen = 0
len_vp = len(valuePlaces)
# print(len_vp)
for i in range(len_vp):
start = valuePlaces[i]
if i == 0:
goal = -1
else:
goal = valuePlaces[i - 1]
maxLen = max(start - goal - 1, maxLen)
mi = min(mi, max(maxLen, ushiro))
print(mi)
|
import collections
s = eval(input())
ls = len(s)
c = set(s)
mi = ls
valuePlaces = []
for v in c:
co = 0
valuePlaces.clear()
for i in range(ls):
if s[i] == v:
valuePlaces.append(i)
ushiro = ls - valuePlaces[-1] - 1
maxLen = 0
len_vp = len(valuePlaces)
for i in range(len_vp):
start = valuePlaces[i]
if i == 0:
goal = -1
else:
goal = valuePlaces[i - 1]
maxLen = max(start - goal - 1, maxLen)
mi = min(mi, max(maxLen, ushiro))
print(mi)
| false | 17.241379 |
[
"-c = collections.Counter(s)",
"+c = set(s)",
"-for v, k in list(c.items()):",
"+for v in c:",
"- # print(ushiro,v)",
"- # print(len_vp)"
] | false | 0.042648 | 0.04105 | 1.038939 |
[
"s774811321",
"s165046461"
] |
u350667455
|
p02657
|
python
|
s738140778
|
s370425666
| 24 | 21 | 9,156 | 9,100 |
Accepted
|
Accepted
| 12.5 |
A,B = list(map(int, input().split()))
print((A*B))
|
A,B = input().split()
import math
A=int(A)
B=float(B)
print((math.floor(A*B)))
| 2 | 5 | 43 | 80 |
A, B = list(map(int, input().split()))
print((A * B))
|
A, B = input().split()
import math
A = int(A)
B = float(B)
print((math.floor(A * B)))
| false | 60 |
[
"-A, B = list(map(int, input().split()))",
"-print((A * B))",
"+A, B = input().split()",
"+import math",
"+",
"+A = int(A)",
"+B = float(B)",
"+print((math.floor(A * B)))"
] | false | 0.084778 | 0.039278 | 2.158433 |
[
"s738140778",
"s370425666"
] |
u186838327
|
p02661
|
python
|
s416884764
|
s527809592
| 464 | 351 | 25,424 | 104,532 |
Accepted
|
Accepted
| 24.35 |
n = int(eval(input()))
A = [0]*n
B = [0]*n
for i in range(n):
a, b = list(map(int, input().split()))
A[i] = a
B[i] = b
A.sort()
B.sort()
if n%2 == 1:
ans = B[n//2]-A[n//2]+1
else:
ans = B[n//2-1]+B[n//2]-(A[n//2-1]+A[n//2])+1
print(ans)
|
n = int(eval(input()))
A = []
B = []
for i in range(n):
a, b = list(map(int, input().split()))
A.append(a)
B.append(b)
A.sort()
B.sort()
if n%2 == 1:
ans = B[n//2]-A[n//2]+1
else:
x = A[n//2-1]+A[n//2]
y = B[n//2-1]+B[n//2]
ans = y-x+1
print(ans)
| 16 | 17 | 262 | 280 |
n = int(eval(input()))
A = [0] * n
B = [0] * n
for i in range(n):
a, b = list(map(int, input().split()))
A[i] = a
B[i] = b
A.sort()
B.sort()
if n % 2 == 1:
ans = B[n // 2] - A[n // 2] + 1
else:
ans = B[n // 2 - 1] + B[n // 2] - (A[n // 2 - 1] + A[n // 2]) + 1
print(ans)
|
n = int(eval(input()))
A = []
B = []
for i in range(n):
a, b = list(map(int, input().split()))
A.append(a)
B.append(b)
A.sort()
B.sort()
if n % 2 == 1:
ans = B[n // 2] - A[n // 2] + 1
else:
x = A[n // 2 - 1] + A[n // 2]
y = B[n // 2 - 1] + B[n // 2]
ans = y - x + 1
print(ans)
| false | 5.882353 |
[
"-A = [0] * n",
"-B = [0] * n",
"+A = []",
"+B = []",
"- A[i] = a",
"- B[i] = b",
"+ A.append(a)",
"+ B.append(b)",
"- ans = B[n // 2 - 1] + B[n // 2] - (A[n // 2 - 1] + A[n // 2]) + 1",
"+ x = A[n // 2 - 1] + A[n // 2]",
"+ y = B[n // 2 - 1] + B[n // 2]",
"+ ans = y - x + 1"
] | false | 0.07665 | 0.03842 | 1.995042 |
[
"s416884764",
"s527809592"
] |
u548464743
|
p02844
|
python
|
s013950905
|
s225314112
| 166 | 29 | 10,264 | 9,116 |
Accepted
|
Accepted
| 82.53 |
n = int(eval(input()))
num_list = list(map(int,eval(input())))
cnt = 0
for i in range(10):
if i not in num_list:
continue
else:
first_pwd = num_list.index(i)
new_num_list = num_list[first_pwd + 1:]
for j in range(10):
if j not in new_num_list:
continue
else:
second_pwd = new_num_list.index(j)
new_new_num_list = new_num_list[second_pwd+1:]
for k in range(10):
if k not in new_new_num_list:
continue
else:
cnt += 1
print(cnt)
|
n=int(eval(input()))
s=eval(input())
ans=0
for i in range(10):
if str(i) in s[:-2]:
s1=s.index(str(i))
for j in range(10):
if str(j) in s[s1+1:-1]:
s2=s[s1+1:].index(str(j))+s1+1
for k in range(10):
if str(k) in s[s2+1:]:
ans+=1
print(ans)
| 24 | 16 | 655 | 354 |
n = int(eval(input()))
num_list = list(map(int, eval(input())))
cnt = 0
for i in range(10):
if i not in num_list:
continue
else:
first_pwd = num_list.index(i)
new_num_list = num_list[first_pwd + 1 :]
for j in range(10):
if j not in new_num_list:
continue
else:
second_pwd = new_num_list.index(j)
new_new_num_list = new_num_list[second_pwd + 1 :]
for k in range(10):
if k not in new_new_num_list:
continue
else:
cnt += 1
print(cnt)
|
n = int(eval(input()))
s = eval(input())
ans = 0
for i in range(10):
if str(i) in s[:-2]:
s1 = s.index(str(i))
for j in range(10):
if str(j) in s[s1 + 1 : -1]:
s2 = s[s1 + 1 :].index(str(j)) + s1 + 1
for k in range(10):
if str(k) in s[s2 + 1 :]:
ans += 1
print(ans)
| false | 33.333333 |
[
"-num_list = list(map(int, eval(input())))",
"-cnt = 0",
"+s = eval(input())",
"+ans = 0",
"- if i not in num_list:",
"- continue",
"- else:",
"- first_pwd = num_list.index(i)",
"- new_num_list = num_list[first_pwd + 1 :]",
"+ if str(i) in s[:-2]:",
"+ s1 = s.index(str(i))",
"- if j not in new_num_list:",
"- continue",
"- else:",
"- second_pwd = new_num_list.index(j)",
"- new_new_num_list = new_num_list[second_pwd + 1 :]",
"+ if str(j) in s[s1 + 1 : -1]:",
"+ s2 = s[s1 + 1 :].index(str(j)) + s1 + 1",
"- if k not in new_new_num_list:",
"- continue",
"- else:",
"- cnt += 1",
"-print(cnt)",
"+ if str(k) in s[s2 + 1 :]:",
"+ ans += 1",
"+print(ans)"
] | false | 0.046259 | 0.046106 | 1.003313 |
[
"s013950905",
"s225314112"
] |
u893063840
|
p03634
|
python
|
s500918228
|
s694025058
| 1,497 | 1,357 | 178,392 | 89,312 |
Accepted
|
Accepted
| 9.35 |
import sys
sys.setrecursionlimit(10 ** 6)
class Tree:
WHITE = 0
GRAY = -1
BLACK = 1
def __init__(self, adj):
n = len(adj)
self.adj = adj
self.colors = [self.WHITE] * n
self.depths = [-1] * n
self.depth = 0
def init(self):
self.__init__(self.adj)
def dfs(self, u):
if self.colors[u] == self.BLACK:
return
self.colors[u] = self.GRAY
self.depths[u] = self.depth
for v, w in self.adj[u]:
if self.colors[v] == self.WHITE:
self.depth += w
self.dfs(v)
self.depth -= w
self.colors[u] = self.BLACK
n = int(eval(input()))
abc = [list(map(int, input().split())) for _ in range(n - 1)]
q, k = list(map(int, input().split()))
xy = [list(map(int, input().split())) for _ in range(q)]
adj = [[] for _ in range(n)]
for a, b, c in abc:
a -= 1
b -= 1
adj[a].append([b, c])
adj[b].append([a, c])
tree = Tree(adj)
tree.dfs(k-1)
for x, y in xy:
x -= 1
y -= 1
ans = tree.depths[x] + tree.depths[y]
print(ans)
|
n = int(eval(input()))
abc = [list(map(int, input().split())) for _ in range(n - 1)]
q, k = list(map(int, input().split()))
xy = [list(map(int, input().split())) for _ in range(q)]
adj = [[] for _ in range(n)]
for a, b, c in abc:
a -= 1
b -= 1
adj[a].append([b, c])
adj[b].append([a, c])
def dfs(s):
d = [-1] * n
d[s] = 0
stack = [s]
while stack:
u = stack.pop()
for v, c in adj[u]:
if d[v] == -1:
d[v] = d[u] + c
stack.append(v)
return d
depths = dfs(k-1)
for x, y in xy:
x -= 1
y -= 1
ans = depths[x] + depths[y]
print(ans)
| 55 | 35 | 1,134 | 584 |
import sys
sys.setrecursionlimit(10**6)
class Tree:
WHITE = 0
GRAY = -1
BLACK = 1
def __init__(self, adj):
n = len(adj)
self.adj = adj
self.colors = [self.WHITE] * n
self.depths = [-1] * n
self.depth = 0
def init(self):
self.__init__(self.adj)
def dfs(self, u):
if self.colors[u] == self.BLACK:
return
self.colors[u] = self.GRAY
self.depths[u] = self.depth
for v, w in self.adj[u]:
if self.colors[v] == self.WHITE:
self.depth += w
self.dfs(v)
self.depth -= w
self.colors[u] = self.BLACK
n = int(eval(input()))
abc = [list(map(int, input().split())) for _ in range(n - 1)]
q, k = list(map(int, input().split()))
xy = [list(map(int, input().split())) for _ in range(q)]
adj = [[] for _ in range(n)]
for a, b, c in abc:
a -= 1
b -= 1
adj[a].append([b, c])
adj[b].append([a, c])
tree = Tree(adj)
tree.dfs(k - 1)
for x, y in xy:
x -= 1
y -= 1
ans = tree.depths[x] + tree.depths[y]
print(ans)
|
n = int(eval(input()))
abc = [list(map(int, input().split())) for _ in range(n - 1)]
q, k = list(map(int, input().split()))
xy = [list(map(int, input().split())) for _ in range(q)]
adj = [[] for _ in range(n)]
for a, b, c in abc:
a -= 1
b -= 1
adj[a].append([b, c])
adj[b].append([a, c])
def dfs(s):
d = [-1] * n
d[s] = 0
stack = [s]
while stack:
u = stack.pop()
for v, c in adj[u]:
if d[v] == -1:
d[v] = d[u] + c
stack.append(v)
return d
depths = dfs(k - 1)
for x, y in xy:
x -= 1
y -= 1
ans = depths[x] + depths[y]
print(ans)
| false | 36.363636 |
[
"-import sys",
"-",
"-sys.setrecursionlimit(10**6)",
"-",
"-",
"-class Tree:",
"- WHITE = 0",
"- GRAY = -1",
"- BLACK = 1",
"-",
"- def __init__(self, adj):",
"- n = len(adj)",
"- self.adj = adj",
"- self.colors = [self.WHITE] * n",
"- self.depths = [-1] * n",
"- self.depth = 0",
"-",
"- def init(self):",
"- self.__init__(self.adj)",
"-",
"- def dfs(self, u):",
"- if self.colors[u] == self.BLACK:",
"- return",
"- self.colors[u] = self.GRAY",
"- self.depths[u] = self.depth",
"- for v, w in self.adj[u]:",
"- if self.colors[v] == self.WHITE:",
"- self.depth += w",
"- self.dfs(v)",
"- self.depth -= w",
"- self.colors[u] = self.BLACK",
"-",
"-",
"-tree = Tree(adj)",
"-tree.dfs(k - 1)",
"+",
"+",
"+def dfs(s):",
"+ d = [-1] * n",
"+ d[s] = 0",
"+ stack = [s]",
"+ while stack:",
"+ u = stack.pop()",
"+ for v, c in adj[u]:",
"+ if d[v] == -1:",
"+ d[v] = d[u] + c",
"+ stack.append(v)",
"+ return d",
"+",
"+",
"+depths = dfs(k - 1)",
"- ans = tree.depths[x] + tree.depths[y]",
"+ ans = depths[x] + depths[y]"
] | false | 0.094762 | 0.09267 | 1.022569 |
[
"s500918228",
"s694025058"
] |
u033627628
|
p03086
|
python
|
s969539496
|
s367459050
| 19 | 17 | 3,060 | 2,940 |
Accepted
|
Accepted
| 10.53 |
s=eval(input())
ans=0
start=-1
for i in range(len(s)):
if not s[i] in "ACGT":
ans=max(ans,i-start-1)
start=i
i+=1
ans=max(ans,i-start-1)
print(ans)
|
s=eval(input())
ans=0
cnt=0
for c in s:
if c in "ATCG":
cnt+=1
else:
cnt=0
ans=max(ans,cnt)
print(ans)
| 10 | 10 | 174 | 134 |
s = eval(input())
ans = 0
start = -1
for i in range(len(s)):
if not s[i] in "ACGT":
ans = max(ans, i - start - 1)
start = i
i += 1
ans = max(ans, i - start - 1)
print(ans)
|
s = eval(input())
ans = 0
cnt = 0
for c in s:
if c in "ATCG":
cnt += 1
else:
cnt = 0
ans = max(ans, cnt)
print(ans)
| false | 0 |
[
"-start = -1",
"-for i in range(len(s)):",
"- if not s[i] in \"ACGT\":",
"- ans = max(ans, i - start - 1)",
"- start = i",
"- i += 1",
"-ans = max(ans, i - start - 1)",
"+cnt = 0",
"+for c in s:",
"+ if c in \"ATCG\":",
"+ cnt += 1",
"+ else:",
"+ cnt = 0",
"+ ans = max(ans, cnt)"
] | false | 0.048126 | 0.049373 | 0.974737 |
[
"s969539496",
"s367459050"
] |
u628335443
|
p02780
|
python
|
s780503814
|
s369624155
| 174 | 128 | 25,060 | 25,152 |
Accepted
|
Accepted
| 26.44 |
n, k = list(map(int, input().split()))
p = list(map(int, input().split()))
max_sum_k = 0
cum_sum = [0] * (n+1)
cum_sum[0] = 0
cum_sum[1] = p[0]
for i in range(2, n+1):
cum_sum[i] = p[i-1] + cum_sum[i-1]
for i in range(k, n + 1):
sum_p = cum_sum[i] - cum_sum[i-k]
if sum_p > max_sum_k:
max_sum_k = sum_p
max_ex = (k + max_sum_k) / 2
print(max_ex)
|
from itertools import accumulate
n, k = list(map(int, input().split()))
p = list(map(int, input().split()))
max_sum_k = 0
cum_sum = [0] + list(accumulate(p))
for i in range(k-1, n + 1):
sum_p = cum_sum[i] - cum_sum[i-k]
if sum_p > max_sum_k:
max_sum_k = sum_p
max_ex = (k + max_sum_k) / 2
print(max_ex)
| 16 | 14 | 377 | 329 |
n, k = list(map(int, input().split()))
p = list(map(int, input().split()))
max_sum_k = 0
cum_sum = [0] * (n + 1)
cum_sum[0] = 0
cum_sum[1] = p[0]
for i in range(2, n + 1):
cum_sum[i] = p[i - 1] + cum_sum[i - 1]
for i in range(k, n + 1):
sum_p = cum_sum[i] - cum_sum[i - k]
if sum_p > max_sum_k:
max_sum_k = sum_p
max_ex = (k + max_sum_k) / 2
print(max_ex)
|
from itertools import accumulate
n, k = list(map(int, input().split()))
p = list(map(int, input().split()))
max_sum_k = 0
cum_sum = [0] + list(accumulate(p))
for i in range(k - 1, n + 1):
sum_p = cum_sum[i] - cum_sum[i - k]
if sum_p > max_sum_k:
max_sum_k = sum_p
max_ex = (k + max_sum_k) / 2
print(max_ex)
| false | 12.5 |
[
"+from itertools import accumulate",
"+",
"-cum_sum = [0] * (n + 1)",
"-cum_sum[0] = 0",
"-cum_sum[1] = p[0]",
"-for i in range(2, n + 1):",
"- cum_sum[i] = p[i - 1] + cum_sum[i - 1]",
"-for i in range(k, n + 1):",
"+cum_sum = [0] + list(accumulate(p))",
"+for i in range(k - 1, n + 1):"
] | false | 0.042646 | 0.186873 | 0.228207 |
[
"s780503814",
"s369624155"
] |
u835283937
|
p02714
|
python
|
s477059761
|
s754613296
| 1,830 | 1,448 | 9,192 | 9,152 |
Accepted
|
Accepted
| 20.87 |
def main5():
N = int(eval(input()))
S = list(eval(input()))
r = g = b = 0
for c in S:
if c == "R":
r += 1
if c == "G":
g += 1
if c == "B":
b += 1
tmp = 0
for i in range(len(S)):
for j in range(len(S)):
if i < j:
k = 2*j - i
if k < len(S) and S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
tmp += 1
ans = r*g*b - tmp
print(ans)
if __name__ == "__main__":
main5()
|
def main5():
N = int(eval(input()))
S = list(eval(input()))
r = g = b = 0
for c in S:
if c == "R":
r += 1
if c == "G":
g += 1
if c == "B":
b += 1
tmp = 0
for i in range(len(S)):
for j in range(i + 1, len(S)):
k = 2*j - i
if k < len(S) and S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
tmp += 1
ans = r*g*b - tmp
print(ans)
if __name__ == "__main__":
main5()
| 27 | 26 | 554 | 526 |
def main5():
N = int(eval(input()))
S = list(eval(input()))
r = g = b = 0
for c in S:
if c == "R":
r += 1
if c == "G":
g += 1
if c == "B":
b += 1
tmp = 0
for i in range(len(S)):
for j in range(len(S)):
if i < j:
k = 2 * j - i
if k < len(S) and S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
tmp += 1
ans = r * g * b - tmp
print(ans)
if __name__ == "__main__":
main5()
|
def main5():
N = int(eval(input()))
S = list(eval(input()))
r = g = b = 0
for c in S:
if c == "R":
r += 1
if c == "G":
g += 1
if c == "B":
b += 1
tmp = 0
for i in range(len(S)):
for j in range(i + 1, len(S)):
k = 2 * j - i
if k < len(S) and S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
tmp += 1
ans = r * g * b - tmp
print(ans)
if __name__ == "__main__":
main5()
| false | 3.703704 |
[
"- for j in range(len(S)):",
"- if i < j:",
"- k = 2 * j - i",
"- if k < len(S) and S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:",
"- tmp += 1",
"+ for j in range(i + 1, len(S)):",
"+ k = 2 * j - i",
"+ if k < len(S) and S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:",
"+ tmp += 1"
] | false | 0.038089 | 0.036908 | 1.031989 |
[
"s477059761",
"s754613296"
] |
u017810624
|
p02599
|
python
|
s523884994
|
s290719300
| 1,899 | 1,690 | 245,224 | 232,524 |
Accepted
|
Accepted
| 11.01 |
n,q=list(map(int,input().split()))
c=list(map(int,input().split()))
l=[list(map(int,input().split())) for i in range(q)]
for i in range(q):
l[i].append(i)
l.sort(key=lambda x:x[1])
L=[-1]*(5*10**5+1)
class Bit:
def __init__(self,n):
self.size=n
self.tree=[0]*(n + 1)
self.depth=n.bit_length()
def sum(self,i):
s=0
while i>0:
s+=self.tree[i]
i-=i&-i
return s
def add(self,i,x):
while i<=self.size:
self.tree[i]+=x
i+=i&-i
BIT=Bit(n+1)
ans=[0]*q
ct=0
for i in range(q):
while ct<=l[i][1]:
if L[c[ct-1]-1]!=-1:
BIT.add(L[c[ct-1]-1],-1)
L[c[ct-1]-1]=ct+1
BIT.add(ct+1,1)
ct+=1
ans[l[i][2]]=BIT.sum(l[i][1]+1)-BIT.sum(l[i][0])
for i in range(q):
print((ans[i]))
|
import sys
input=sys.stdin.readline
n,q=list(map(int,input().split()))
c=list(map(int,input().split()))
l=[list(map(int,input().split())) for i in range(q)]
for i in range(q):
l[i].append(i)
l.sort(key=lambda x:x[1])
L=[-1]*(5*10**5+1)
class Bit:
def __init__(self,n):
self.size=n
self.tree=[0]*(n + 1)
self.depth=n.bit_length()
def sum(self,i):
s=0
while i>0:
s+=self.tree[i]
i-=i&-i
return s
def add(self,i,x):
while i<=self.size:
self.tree[i]+=x
i+=i&-i
BIT=Bit(n+1)
ans=[0]*q
ct=0
for i in range(q):
while ct<=l[i][1]:
if L[c[ct-1]-1]!=-1:
BIT.add(L[c[ct-1]-1],-1)
L[c[ct-1]-1]=ct+1
BIT.add(ct+1,1)
ct+=1
ans[l[i][2]]=BIT.sum(l[i][1]+1)-BIT.sum(l[i][0])
for i in range(q):
print((ans[i]))
| 42 | 44 | 784 | 822 |
n, q = list(map(int, input().split()))
c = list(map(int, input().split()))
l = [list(map(int, input().split())) for i in range(q)]
for i in range(q):
l[i].append(i)
l.sort(key=lambda x: x[1])
L = [-1] * (5 * 10**5 + 1)
class Bit:
def __init__(self, n):
self.size = n
self.tree = [0] * (n + 1)
self.depth = n.bit_length()
def sum(self, i):
s = 0
while i > 0:
s += self.tree[i]
i -= i & -i
return s
def add(self, i, x):
while i <= self.size:
self.tree[i] += x
i += i & -i
BIT = Bit(n + 1)
ans = [0] * q
ct = 0
for i in range(q):
while ct <= l[i][1]:
if L[c[ct - 1] - 1] != -1:
BIT.add(L[c[ct - 1] - 1], -1)
L[c[ct - 1] - 1] = ct + 1
BIT.add(ct + 1, 1)
ct += 1
ans[l[i][2]] = BIT.sum(l[i][1] + 1) - BIT.sum(l[i][0])
for i in range(q):
print((ans[i]))
|
import sys
input = sys.stdin.readline
n, q = list(map(int, input().split()))
c = list(map(int, input().split()))
l = [list(map(int, input().split())) for i in range(q)]
for i in range(q):
l[i].append(i)
l.sort(key=lambda x: x[1])
L = [-1] * (5 * 10**5 + 1)
class Bit:
def __init__(self, n):
self.size = n
self.tree = [0] * (n + 1)
self.depth = n.bit_length()
def sum(self, i):
s = 0
while i > 0:
s += self.tree[i]
i -= i & -i
return s
def add(self, i, x):
while i <= self.size:
self.tree[i] += x
i += i & -i
BIT = Bit(n + 1)
ans = [0] * q
ct = 0
for i in range(q):
while ct <= l[i][1]:
if L[c[ct - 1] - 1] != -1:
BIT.add(L[c[ct - 1] - 1], -1)
L[c[ct - 1] - 1] = ct + 1
BIT.add(ct + 1, 1)
ct += 1
ans[l[i][2]] = BIT.sum(l[i][1] + 1) - BIT.sum(l[i][0])
for i in range(q):
print((ans[i]))
| false | 4.545455 |
[
"+import sys",
"+",
"+input = sys.stdin.readline"
] | false | 0.065488 | 0.065316 | 1.002637 |
[
"s523884994",
"s290719300"
] |
u565149926
|
p03127
|
python
|
s777709554
|
s831912252
| 88 | 80 | 13,336 | 13,296 |
Accepted
|
Accepted
| 9.09 |
from fractions import gcd
N = eval(input())
ans = 0
for a in map(int, input().split()):
ans = gcd(ans, a)
print(ans)
|
import fractions, functools
N = eval(input())
print((functools.reduce(fractions.gcd, list(map(int, input().split())))))
| 7 | 3 | 122 | 108 |
from fractions import gcd
N = eval(input())
ans = 0
for a in map(int, input().split()):
ans = gcd(ans, a)
print(ans)
|
import fractions, functools
N = eval(input())
print((functools.reduce(fractions.gcd, list(map(int, input().split())))))
| false | 57.142857 |
[
"-from fractions import gcd",
"+import fractions, functools",
"-ans = 0",
"-for a in map(int, input().split()):",
"- ans = gcd(ans, a)",
"-print(ans)",
"+print((functools.reduce(fractions.gcd, list(map(int, input().split())))))"
] | false | 0.07717 | 0.040738 | 1.894296 |
[
"s777709554",
"s831912252"
] |
u678167152
|
p03945
|
python
|
s307913766
|
s602673524
| 47 | 18 | 3,188 | 3,188 |
Accepted
|
Accepted
| 61.7 |
S = eval(input())
c=1
for i in range(len(S)-1):
if S[i]!=S[i+1]:
c+=1
print((c-1))
|
def solve():
S = eval(input())
ans = S.count('BW')+S.count('WB')
return ans
print((solve()))
| 6 | 5 | 85 | 100 |
S = eval(input())
c = 1
for i in range(len(S) - 1):
if S[i] != S[i + 1]:
c += 1
print((c - 1))
|
def solve():
S = eval(input())
ans = S.count("BW") + S.count("WB")
return ans
print((solve()))
| false | 16.666667 |
[
"-S = eval(input())",
"-c = 1",
"-for i in range(len(S) - 1):",
"- if S[i] != S[i + 1]:",
"- c += 1",
"-print((c - 1))",
"+def solve():",
"+ S = eval(input())",
"+ ans = S.count(\"BW\") + S.count(\"WB\")",
"+ return ans",
"+",
"+",
"+print((solve()))"
] | false | 0.07571 | 0.04186 | 1.808667 |
[
"s307913766",
"s602673524"
] |
u952708174
|
p03167
|
python
|
s232631320
|
s526074496
| 1,443 | 374 | 43,732 | 43,612 |
Accepted
|
Accepted
| 74.08 |
def h_grid1(MOD=10**9 + 7):
H, W = [int(i) for i in input().split()]
Grid = [eval(input()) for _ in range(H)]
# path[r][c]: マス(r, c)に(0-based)到達する経路の数
path = [[0] * W for _ in range(H)]
path[0][0] = 1 # スタート地点は必ず到達できる
def can_reach(row, col):
return 0 <= row < H and 0 <= col < W and Grid[row][col] == '.'
for row in range(H):
for col in range(W):
if Grid[row][col] == '#':
continue
for nr, nc in ((row, col + 1), (row + 1, col)):
if can_reach(nr, nc):
path[nr][nc] += path[row][col]
path[nr][nc] %= MOD
return path[H - 1][W - 1]
print((h_grid1()))
|
def h_grid1(MOD=10**9 + 7):
H, W = [int(i) for i in input().split()]
Grid = ['#' * (W + 1)] + ['#' + eval(input()) for _ in range(H)] # 左と上を埋める
# path[r][c]: マス(r, c)に(0-based)到達する経路の数
path = [[0] * (W + 1) for _ in range(H + 1)]
path[0][1] = 1 # path[1][1] = 1 (スタート地点) とするための便宜上の代入
for row in range(1, H + 1):
for col in range(1, W + 1):
if Grid[row][col] == '.':
path[row][col] = (path[row - 1][col] + path[row][col - 1]) % MOD
return path[H][W]
print((h_grid1()))
| 22 | 15 | 710 | 542 |
def h_grid1(MOD=10**9 + 7):
H, W = [int(i) for i in input().split()]
Grid = [eval(input()) for _ in range(H)]
# path[r][c]: マス(r, c)に(0-based)到達する経路の数
path = [[0] * W for _ in range(H)]
path[0][0] = 1 # スタート地点は必ず到達できる
def can_reach(row, col):
return 0 <= row < H and 0 <= col < W and Grid[row][col] == "."
for row in range(H):
for col in range(W):
if Grid[row][col] == "#":
continue
for nr, nc in ((row, col + 1), (row + 1, col)):
if can_reach(nr, nc):
path[nr][nc] += path[row][col]
path[nr][nc] %= MOD
return path[H - 1][W - 1]
print((h_grid1()))
|
def h_grid1(MOD=10**9 + 7):
H, W = [int(i) for i in input().split()]
Grid = ["#" * (W + 1)] + ["#" + eval(input()) for _ in range(H)] # 左と上を埋める
# path[r][c]: マス(r, c)に(0-based)到達する経路の数
path = [[0] * (W + 1) for _ in range(H + 1)]
path[0][1] = 1 # path[1][1] = 1 (スタート地点) とするための便宜上の代入
for row in range(1, H + 1):
for col in range(1, W + 1):
if Grid[row][col] == ".":
path[row][col] = (path[row - 1][col] + path[row][col - 1]) % MOD
return path[H][W]
print((h_grid1()))
| false | 31.818182 |
[
"- Grid = [eval(input()) for _ in range(H)]",
"+ Grid = [\"#\" * (W + 1)] + [\"#\" + eval(input()) for _ in range(H)] # 左と上を埋める",
"- path = [[0] * W for _ in range(H)]",
"- path[0][0] = 1 # スタート地点は必ず到達できる",
"-",
"- def can_reach(row, col):",
"- return 0 <= row < H and 0 <= col < W and Grid[row][col] == \".\"",
"-",
"- for row in range(H):",
"- for col in range(W):",
"- if Grid[row][col] == \"#\":",
"- continue",
"- for nr, nc in ((row, col + 1), (row + 1, col)):",
"- if can_reach(nr, nc):",
"- path[nr][nc] += path[row][col]",
"- path[nr][nc] %= MOD",
"- return path[H - 1][W - 1]",
"+ path = [[0] * (W + 1) for _ in range(H + 1)]",
"+ path[0][1] = 1 # path[1][1] = 1 (スタート地点) とするための便宜上の代入",
"+ for row in range(1, H + 1):",
"+ for col in range(1, W + 1):",
"+ if Grid[row][col] == \".\":",
"+ path[row][col] = (path[row - 1][col] + path[row][col - 1]) % MOD",
"+ return path[H][W]"
] | false | 0.072338 | 0.031841 | 2.271863 |
[
"s232631320",
"s526074496"
] |
u598229387
|
p02936
|
python
|
s882890145
|
s690877535
| 1,906 | 1,381 | 124,236 | 124,240 |
Accepted
|
Accepted
| 27.54 |
n,q=list(map(int,input().split()))
ab=[[int(i) for i in input().split()] for j in range(n-1)]
px=[[int(i) for i in input().split()] for j in range(q)]
graph=[[] for i in range(n+1)]
for a,b in ab:
graph[a].append(b)
graph[b].append(a)
value=[0]*(n+1)
for p,x in px:
value[p]+=x
q=[(0,1)]
while q:
parent,child = q.pop()
value[child]+=value[parent]
for i in graph[child]:
if i==parent:
continue
q.append((child,i))
ans=' '.join(map(str,value[1:]))
print(ans)
|
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
n,q=list(map(int,input().split()))
ab=[[int(i) for i in input().split()] for j in range(n-1)]
px=[[int(i) for i in input().split()] for j in range(q)]
graph=[[] for i in range(n+1)]
for a,b in ab:
graph[a].append(b)
graph[b].append(a)
value=[0]*(n+1)
for p,x in px:
value[p]+=x
q=[(0,1)]
while q:
parent,child = q.pop()
value[child]+=value[parent]
for i in graph[child]:
if i==parent:
continue
q.append((child,i))
ans=' '.join(map(str,value[1:]))
print(ans)
| 25 | 28 | 544 | 616 |
n, q = list(map(int, input().split()))
ab = [[int(i) for i in input().split()] for j in range(n - 1)]
px = [[int(i) for i in input().split()] for j in range(q)]
graph = [[] for i in range(n + 1)]
for a, b in ab:
graph[a].append(b)
graph[b].append(a)
value = [0] * (n + 1)
for p, x in px:
value[p] += x
q = [(0, 1)]
while q:
parent, child = q.pop()
value[child] += value[parent]
for i in graph[child]:
if i == parent:
continue
q.append((child, i))
ans = " ".join(map(str, value[1:]))
print(ans)
|
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
n, q = list(map(int, input().split()))
ab = [[int(i) for i in input().split()] for j in range(n - 1)]
px = [[int(i) for i in input().split()] for j in range(q)]
graph = [[] for i in range(n + 1)]
for a, b in ab:
graph[a].append(b)
graph[b].append(a)
value = [0] * (n + 1)
for p, x in px:
value[p] += x
q = [(0, 1)]
while q:
parent, child = q.pop()
value[child] += value[parent]
for i in graph[child]:
if i == parent:
continue
q.append((child, i))
ans = " ".join(map(str, value[1:]))
print(ans)
| false | 10.714286 |
[
"+import sys",
"+",
"+input = sys.stdin.readline",
"+sys.setrecursionlimit(10**7)"
] | false | 0.037033 | 0.036619 | 1.011295 |
[
"s882890145",
"s690877535"
] |
u554954744
|
p03326
|
python
|
s954556957
|
s360177661
| 252 | 220 | 42,736 | 40,560 |
Accepted
|
Accepted
| 12.7 |
n, m = list(map(int, input().split()))
cakes = [list(map(int, input().split())) for _ in range(n)]
ans = 0
for i in range(2**3):
tmp_arr = []
for j in range(n):
tmp = 0
for k in range(3):
if (i>>k) & 1:
tmp += cakes[j][k]
else:
tmp -= cakes[j][k]
tmp_arr.append(tmp)
tmp_arr.sort(reverse=True)
ans = max(ans, sum(tmp_arr[:m]))
print(ans)
|
n, m = list(map(int, input().split()))
cakes = [list(map(int, input().split())) for _ in range(n)]
import itertools
ans = 0
for a, b, c in itertools.product([-1, 1], repeat=3):
li = []
for i in range(n):
x = a*cakes[i][0] + b*cakes[i][1] + c*cakes[i][2]
li.append(x)
li.sort(reverse=True)
ans = max(ans, sum(li[:m]))
print(ans)
| 17 | 14 | 444 | 368 |
n, m = list(map(int, input().split()))
cakes = [list(map(int, input().split())) for _ in range(n)]
ans = 0
for i in range(2**3):
tmp_arr = []
for j in range(n):
tmp = 0
for k in range(3):
if (i >> k) & 1:
tmp += cakes[j][k]
else:
tmp -= cakes[j][k]
tmp_arr.append(tmp)
tmp_arr.sort(reverse=True)
ans = max(ans, sum(tmp_arr[:m]))
print(ans)
|
n, m = list(map(int, input().split()))
cakes = [list(map(int, input().split())) for _ in range(n)]
import itertools
ans = 0
for a, b, c in itertools.product([-1, 1], repeat=3):
li = []
for i in range(n):
x = a * cakes[i][0] + b * cakes[i][1] + c * cakes[i][2]
li.append(x)
li.sort(reverse=True)
ans = max(ans, sum(li[:m]))
print(ans)
| false | 17.647059 |
[
"+import itertools",
"+",
"-for i in range(2**3):",
"- tmp_arr = []",
"- for j in range(n):",
"- tmp = 0",
"- for k in range(3):",
"- if (i >> k) & 1:",
"- tmp += cakes[j][k]",
"- else:",
"- tmp -= cakes[j][k]",
"- tmp_arr.append(tmp)",
"- tmp_arr.sort(reverse=True)",
"- ans = max(ans, sum(tmp_arr[:m]))",
"+for a, b, c in itertools.product([-1, 1], repeat=3):",
"+ li = []",
"+ for i in range(n):",
"+ x = a * cakes[i][0] + b * cakes[i][1] + c * cakes[i][2]",
"+ li.append(x)",
"+ li.sort(reverse=True)",
"+ ans = max(ans, sum(li[:m]))"
] | false | 0.038139 | 0.037979 | 1.004218 |
[
"s954556957",
"s360177661"
] |
u259755734
|
p02779
|
python
|
s038341780
|
s936293749
| 264 | 62 | 26,808 | 31,152 |
Accepted
|
Accepted
| 76.52 |
N = int(eval(input()))
A = list(map(int, input().split()))
B = list(set(A))
print(('YES' if sorted(A) == sorted(B) else 'NO'))
|
N = int(eval(input()))
print(('YES' if N == len(set(input().split())) else 'NO'))
| 4 | 2 | 121 | 74 |
N = int(eval(input()))
A = list(map(int, input().split()))
B = list(set(A))
print(("YES" if sorted(A) == sorted(B) else "NO"))
|
N = int(eval(input()))
print(("YES" if N == len(set(input().split())) else "NO"))
| false | 50 |
[
"-A = list(map(int, input().split()))",
"-B = list(set(A))",
"-print((\"YES\" if sorted(A) == sorted(B) else \"NO\"))",
"+print((\"YES\" if N == len(set(input().split())) else \"NO\"))"
] | false | 0.036449 | 0.034671 | 1.0513 |
[
"s038341780",
"s936293749"
] |
u197300260
|
p03814
|
python
|
s708109984
|
s575293171
| 29 | 23 | 3,516 | 4,012 |
Accepted
|
Accepted
| 20.69 |
# Problem https://atcoder.jp/contests/abc053/tasks/abc053_b
# Python 2nd Try
def solver(string):
result = 200000
aposi = 0
zposi = len(string)
for j in range(0, len(string), 1):
if string[j] == 'A':
aposi = j
break
for j in range(len(string)-1, -1, -1):
if string[j] == 'Z':
zposi = j
break
result = zposi - aposi + 1
return result
if __name__ == "__main__":
s = eval(input())
print(('{}'.format(solver(s))))
|
# Problem https://atcoder.jp/contests/abc053/tasks/abc053_b
# Python 3rd Try
import copy
def solver(givenstring):
result = 0
usestrA = copy.copy(givenstring)
usestrZ = copy.copy(givenstring)
# a position
apos = usestrA.index('A')+1
usestrrevZ = usestrZ[::-1]
zpos = len(givenstring) - usestrrevZ.index('Z')
result = zpos - apos + 1
return result
if __name__ == "__main__":
s = eval(input())
print(("{}".format(solver(s))))
| 23 | 20 | 527 | 478 |
# Problem https://atcoder.jp/contests/abc053/tasks/abc053_b
# Python 2nd Try
def solver(string):
result = 200000
aposi = 0
zposi = len(string)
for j in range(0, len(string), 1):
if string[j] == "A":
aposi = j
break
for j in range(len(string) - 1, -1, -1):
if string[j] == "Z":
zposi = j
break
result = zposi - aposi + 1
return result
if __name__ == "__main__":
s = eval(input())
print(("{}".format(solver(s))))
|
# Problem https://atcoder.jp/contests/abc053/tasks/abc053_b
# Python 3rd Try
import copy
def solver(givenstring):
result = 0
usestrA = copy.copy(givenstring)
usestrZ = copy.copy(givenstring)
# a position
apos = usestrA.index("A") + 1
usestrrevZ = usestrZ[::-1]
zpos = len(givenstring) - usestrrevZ.index("Z")
result = zpos - apos + 1
return result
if __name__ == "__main__":
s = eval(input())
print(("{}".format(solver(s))))
| false | 13.043478 |
[
"-# Python 2nd Try",
"-def solver(string):",
"- result = 200000",
"- aposi = 0",
"- zposi = len(string)",
"- for j in range(0, len(string), 1):",
"- if string[j] == \"A\":",
"- aposi = j",
"- break",
"- for j in range(len(string) - 1, -1, -1):",
"- if string[j] == \"Z\":",
"- zposi = j",
"- break",
"- result = zposi - aposi + 1",
"+# Python 3rd Try",
"+import copy",
"+",
"+",
"+def solver(givenstring):",
"+ result = 0",
"+ usestrA = copy.copy(givenstring)",
"+ usestrZ = copy.copy(givenstring)",
"+ # a position",
"+ apos = usestrA.index(\"A\") + 1",
"+ usestrrevZ = usestrZ[::-1]",
"+ zpos = len(givenstring) - usestrrevZ.index(\"Z\")",
"+ result = zpos - apos + 1"
] | false | 0.086824 | 0.048225 | 1.800372 |
[
"s708109984",
"s575293171"
] |
u859897687
|
p02969
|
python
|
s117184091
|
s141219197
| 173 | 17 | 38,384 | 2,940 |
Accepted
|
Accepted
| 90.17 |
r=int(eval(input()))
print((3*r*r))
|
a=int(eval(input()))
print((3*a*a))
| 2 | 2 | 28 | 28 |
r = int(eval(input()))
print((3 * r * r))
|
a = int(eval(input()))
print((3 * a * a))
| false | 0 |
[
"-r = int(eval(input()))",
"-print((3 * r * r))",
"+a = int(eval(input()))",
"+print((3 * a * a))"
] | false | 0.117019 | 0.037279 | 3.138969 |
[
"s117184091",
"s141219197"
] |
u989345508
|
p03944
|
python
|
s406906842
|
s603280555
| 43 | 17 | 3,188 | 3,064 |
Accepted
|
Accepted
| 60.47 |
w,h,n=input().split()
w,h,n=int(w),int(h),int(n)
s=[[0 for i in range(w)] for j in range(h)]
for i in range(n):
x,y,a=input().split()
x,y,a=int(x),int(y),int(a)
if a==1:
if x==0:
pass
else:
for j in range(h):
s[j][:x]=[1 for k in range(x)]
elif a==2:
if x==w:
pass
else:
for j in range(h):
s[j][x:]=[1 for k in range(w-x)]
elif a==3:
if y==0:
pass
else:
for j in range(y):
s[h-j-1]=[1 for k in range(w)]
else:
if y==h:
pass
else:
for j in range(h-y):
s[j]=[1 for k in range(w)]
c=0
for i in range(h):
for j in range(w):
if s[i][j]==0:
c+=1
#print(d)
#print(s)
print(c)
|
w,h,n=list(map(int,input().split()))
a1,a2,a3,a4=0,w,0,h
for i in range(n):
x,y,a=list(map(int,input().split()))
if a==1:
a1=max(a1,x)
elif a==2:
a2=min(a2,x)
elif a==3:
a3=max(a3,y)
else:
a4=min(a4,y)
print((max(a2-a1,0)*max(a4-a3,0)))
| 39 | 13 | 880 | 286 |
w, h, n = input().split()
w, h, n = int(w), int(h), int(n)
s = [[0 for i in range(w)] for j in range(h)]
for i in range(n):
x, y, a = input().split()
x, y, a = int(x), int(y), int(a)
if a == 1:
if x == 0:
pass
else:
for j in range(h):
s[j][:x] = [1 for k in range(x)]
elif a == 2:
if x == w:
pass
else:
for j in range(h):
s[j][x:] = [1 for k in range(w - x)]
elif a == 3:
if y == 0:
pass
else:
for j in range(y):
s[h - j - 1] = [1 for k in range(w)]
else:
if y == h:
pass
else:
for j in range(h - y):
s[j] = [1 for k in range(w)]
c = 0
for i in range(h):
for j in range(w):
if s[i][j] == 0:
c += 1
# print(d)
# print(s)
print(c)
|
w, h, n = list(map(int, input().split()))
a1, a2, a3, a4 = 0, w, 0, h
for i in range(n):
x, y, a = list(map(int, input().split()))
if a == 1:
a1 = max(a1, x)
elif a == 2:
a2 = min(a2, x)
elif a == 3:
a3 = max(a3, y)
else:
a4 = min(a4, y)
print((max(a2 - a1, 0) * max(a4 - a3, 0)))
| false | 66.666667 |
[
"-w, h, n = input().split()",
"-w, h, n = int(w), int(h), int(n)",
"-s = [[0 for i in range(w)] for j in range(h)]",
"+w, h, n = list(map(int, input().split()))",
"+a1, a2, a3, a4 = 0, w, 0, h",
"- x, y, a = input().split()",
"- x, y, a = int(x), int(y), int(a)",
"+ x, y, a = list(map(int, input().split()))",
"- if x == 0:",
"- pass",
"- else:",
"- for j in range(h):",
"- s[j][:x] = [1 for k in range(x)]",
"+ a1 = max(a1, x)",
"- if x == w:",
"- pass",
"- else:",
"- for j in range(h):",
"- s[j][x:] = [1 for k in range(w - x)]",
"+ a2 = min(a2, x)",
"- if y == 0:",
"- pass",
"- else:",
"- for j in range(y):",
"- s[h - j - 1] = [1 for k in range(w)]",
"+ a3 = max(a3, y)",
"- if y == h:",
"- pass",
"- else:",
"- for j in range(h - y):",
"- s[j] = [1 for k in range(w)]",
"-c = 0",
"-for i in range(h):",
"- for j in range(w):",
"- if s[i][j] == 0:",
"- c += 1",
"-# print(d)",
"-# print(s)",
"-print(c)",
"+ a4 = min(a4, y)",
"+print((max(a2 - a1, 0) * max(a4 - a3, 0)))"
] | false | 0.059059 | 0.03701 | 1.595771 |
[
"s406906842",
"s603280555"
] |
u811436126
|
p02796
|
python
|
s338629426
|
s309508463
| 629 | 550 | 42,208 | 42,584 |
Accepted
|
Accepted
| 12.56 |
n = int(eval(input()))
xl = [list(map(int, input().split())) for _ in range(n)]
lr = []
for i in range(n):
l = max(xl[i][0] - xl[i][1], 0)
r = max(xl[i][0] + xl[i][1], 0)
lr.append([r, l])
lr = sorted(lr)
keep = [False] * n
# print(lr)
cur = 0
for i in range(n):
if cur <= lr[i][1]:
keep[i] = True
cur = lr[i][0]
'''
for j in range(n - 1):
if keep[j]:
if lr[j][0] == lr[j + 1][0]:
keep[j + 1] = False
elif lr[j][0] < lr[j + 1][0]:# < lr[j][1]:
keep[j + 1] = False
'''
#print(keep)
ans = sum(1 for x in range(n) if keep[x])
print(ans)
|
n = int(eval(input()))
xl = [list(map(int, input().split())) for _ in range(n)]
lr = []
for i in range(n):
l = max(xl[i][0] - xl[i][1], 0)
r = max(xl[i][0] + xl[i][1], 0)
lr.append([l, r])
lr.sort(key=lambda x: x[1])
keep = [False] * n
cur = 0
for i in range(n):
if cur <= lr[i][0]:
keep[i] = True
cur = lr[i][1]
ans = sum(keep)
print(ans)
| 29 | 21 | 635 | 391 |
n = int(eval(input()))
xl = [list(map(int, input().split())) for _ in range(n)]
lr = []
for i in range(n):
l = max(xl[i][0] - xl[i][1], 0)
r = max(xl[i][0] + xl[i][1], 0)
lr.append([r, l])
lr = sorted(lr)
keep = [False] * n
# print(lr)
cur = 0
for i in range(n):
if cur <= lr[i][1]:
keep[i] = True
cur = lr[i][0]
"""
for j in range(n - 1):
if keep[j]:
if lr[j][0] == lr[j + 1][0]:
keep[j + 1] = False
elif lr[j][0] < lr[j + 1][0]:# < lr[j][1]:
keep[j + 1] = False
"""
# print(keep)
ans = sum(1 for x in range(n) if keep[x])
print(ans)
|
n = int(eval(input()))
xl = [list(map(int, input().split())) for _ in range(n)]
lr = []
for i in range(n):
l = max(xl[i][0] - xl[i][1], 0)
r = max(xl[i][0] + xl[i][1], 0)
lr.append([l, r])
lr.sort(key=lambda x: x[1])
keep = [False] * n
cur = 0
for i in range(n):
if cur <= lr[i][0]:
keep[i] = True
cur = lr[i][1]
ans = sum(keep)
print(ans)
| false | 27.586207 |
[
"- lr.append([r, l])",
"-lr = sorted(lr)",
"+ lr.append([l, r])",
"+lr.sort(key=lambda x: x[1])",
"-# print(lr)",
"- if cur <= lr[i][1]:",
"+ if cur <= lr[i][0]:",
"- cur = lr[i][0]",
"-\"\"\"",
"-for j in range(n - 1):",
"- if keep[j]:",
"- if lr[j][0] == lr[j + 1][0]:",
"- keep[j + 1] = False",
"- elif lr[j][0] < lr[j + 1][0]:# < lr[j][1]:",
"- keep[j + 1] = False",
"-\"\"\"",
"-# print(keep)",
"-ans = sum(1 for x in range(n) if keep[x])",
"+ cur = lr[i][1]",
"+ans = sum(keep)"
] | false | 0.04247 | 0.037108 | 1.144515 |
[
"s338629426",
"s309508463"
] |
u600402037
|
p02937
|
python
|
s382237840
|
s687455086
| 280 | 154 | 45,936 | 8,052 |
Accepted
|
Accepted
| 45 |
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
from collections import defaultdict
from bisect import bisect_left
S = input().rstrip()
T = input().rstrip()
LS = len(S)
index = defaultdict(list)
for i,s in enumerate(S):
index[s].append(i)
x = -1
for t in T:
arr = index[t]
if len(arr) == 0:
x = -2
break
y = (x+1) % LS
i = bisect_left(arr,y)
if i < len(arr):
next_x = (x+1) + arr[i] - y
else:
next_x = (x+1) + arr[0] - y + LS
x = next_x
print((x + 1))
|
# E - Strings of Impurity maspyさん
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
from collections import defaultdict
from bisect import bisect_left
S = input().rstrip()
T = input().rstrip()
LS = len(S)
index = defaultdict(list)
for i,s in enumerate(S):
index[s].append(i)
x = -1 #今みたところ 次はx+1から
for t in T:
arr = index[t]
if len(arr) == 0:
print((-1))
exit()
y = (x+1)%LS
i = bisect_left(arr,y)
if i < len(arr):
next_x = (x+1) + arr[i] - y
else:
next_x = (x+1) + arr[0] + LS - y
x = next_x
ans = x + 1
print(ans)
| 33 | 37 | 575 | 652 |
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import defaultdict
from bisect import bisect_left
S = input().rstrip()
T = input().rstrip()
LS = len(S)
index = defaultdict(list)
for i, s in enumerate(S):
index[s].append(i)
x = -1
for t in T:
arr = index[t]
if len(arr) == 0:
x = -2
break
y = (x + 1) % LS
i = bisect_left(arr, y)
if i < len(arr):
next_x = (x + 1) + arr[i] - y
else:
next_x = (x + 1) + arr[0] - y + LS
x = next_x
print((x + 1))
|
# E - Strings of Impurity maspyさん
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import defaultdict
from bisect import bisect_left
S = input().rstrip()
T = input().rstrip()
LS = len(S)
index = defaultdict(list)
for i, s in enumerate(S):
index[s].append(i)
x = -1 # 今みたところ 次はx+1から
for t in T:
arr = index[t]
if len(arr) == 0:
print((-1))
exit()
y = (x + 1) % LS
i = bisect_left(arr, y)
if i < len(arr):
next_x = (x + 1) + arr[i] - y
else:
next_x = (x + 1) + arr[0] + LS - y
x = next_x
ans = x + 1
print(ans)
| false | 10.810811 |
[
"+# E - Strings of Impurity maspyさん",
"-x = -1",
"+x = -1 # 今みたところ 次はx+1から",
"- x = -2",
"- break",
"+ print((-1))",
"+ exit()",
"- next_x = (x + 1) + arr[0] - y + LS",
"+ next_x = (x + 1) + arr[0] + LS - y",
"-print((x + 1))",
"+ans = x + 1",
"+print(ans)"
] | false | 0.037278 | 0.061799 | 0.603213 |
[
"s382237840",
"s687455086"
] |
u227082700
|
p02792
|
python
|
s195181957
|
s440288588
| 246 | 227 | 3,064 | 3,064 |
Accepted
|
Accepted
| 7.72 |
c=[10*[0]for _ in range(10)]
n=int(eval(input()))
for i in range(1,n+1):
a=int(str(i)[0])
b=int(str(i)[-1])
c[a][b]+=1
ans=0
for i in range(1,10):
for j in range(1,10):
ans+=c[i][j]*c[j][i]
print(ans)
|
n=int(eval(input()))
d=[10*[0]for _ in range(10)]
for i in range(1,n+1):d[int(str(i)[0])][int(str(i)[-1])]+=1
ans=0
for i in range(1,10):
for j in range(1,10):ans+=d[i][j]*d[j][i]
print(ans)
| 11 | 7 | 216 | 192 |
c = [10 * [0] for _ in range(10)]
n = int(eval(input()))
for i in range(1, n + 1):
a = int(str(i)[0])
b = int(str(i)[-1])
c[a][b] += 1
ans = 0
for i in range(1, 10):
for j in range(1, 10):
ans += c[i][j] * c[j][i]
print(ans)
|
n = int(eval(input()))
d = [10 * [0] for _ in range(10)]
for i in range(1, n + 1):
d[int(str(i)[0])][int(str(i)[-1])] += 1
ans = 0
for i in range(1, 10):
for j in range(1, 10):
ans += d[i][j] * d[j][i]
print(ans)
| false | 36.363636 |
[
"-c = [10 * [0] for _ in range(10)]",
"+d = [10 * [0] for _ in range(10)]",
"- a = int(str(i)[0])",
"- b = int(str(i)[-1])",
"- c[a][b] += 1",
"+ d[int(str(i)[0])][int(str(i)[-1])] += 1",
"- ans += c[i][j] * c[j][i]",
"+ ans += d[i][j] * d[j][i]"
] | false | 0.14442 | 0.154593 | 0.934192 |
[
"s195181957",
"s440288588"
] |
u001024152
|
p03699
|
python
|
s555511391
|
s854399917
| 212 | 20 | 3,064 | 3,316 |
Accepted
|
Accepted
| 90.57 |
import sys
N = int(eval(input()))
scores = [0]*(N*100+1)
scores[0] = 1
for _ in range(N):
a = int(eval(input()))
for i in reversed(list(range(len(scores)))):
if scores[i]>0 and 0<i+a<=N*100:
scores[i+a] += 1
for i in reversed(list(range(len(scores)))):
if scores[i] and i % 10 != 0:
print(i)
sys.exit()
print((0))
|
N = int(eval(input()))
a = list(int(eval(input())) for _ in range(N))
a.sort()
ans = sum(a)
if ans%10 > 0:
print(ans)
exit()
for ai in a:
if ai%10 > 0:
print((ans - ai))
break
else:
print((0))
| 17 | 14 | 378 | 223 |
import sys
N = int(eval(input()))
scores = [0] * (N * 100 + 1)
scores[0] = 1
for _ in range(N):
a = int(eval(input()))
for i in reversed(list(range(len(scores)))):
if scores[i] > 0 and 0 < i + a <= N * 100:
scores[i + a] += 1
for i in reversed(list(range(len(scores)))):
if scores[i] and i % 10 != 0:
print(i)
sys.exit()
print((0))
|
N = int(eval(input()))
a = list(int(eval(input())) for _ in range(N))
a.sort()
ans = sum(a)
if ans % 10 > 0:
print(ans)
exit()
for ai in a:
if ai % 10 > 0:
print((ans - ai))
break
else:
print((0))
| false | 17.647059 |
[
"-import sys",
"-",
"-scores = [0] * (N * 100 + 1)",
"-scores[0] = 1",
"-for _ in range(N):",
"- a = int(eval(input()))",
"- for i in reversed(list(range(len(scores)))):",
"- if scores[i] > 0 and 0 < i + a <= N * 100:",
"- scores[i + a] += 1",
"-for i in reversed(list(range(len(scores)))):",
"- if scores[i] and i % 10 != 0:",
"- print(i)",
"- sys.exit()",
"-print((0))",
"+a = list(int(eval(input())) for _ in range(N))",
"+a.sort()",
"+ans = sum(a)",
"+if ans % 10 > 0:",
"+ print(ans)",
"+ exit()",
"+for ai in a:",
"+ if ai % 10 > 0:",
"+ print((ans - ai))",
"+ break",
"+else:",
"+ print((0))"
] | false | 0.054499 | 0.033206 | 1.641243 |
[
"s555511391",
"s854399917"
] |
u396961814
|
p02900
|
python
|
s561770879
|
s085510318
| 174 | 63 | 3,064 | 3,064 |
Accepted
|
Accepted
| 63.79 |
A,B =[int(x) for x in input().split()]
def bunkai(n):
sosu= {1}
tmp = n
stop_flag = n
if tmp%2 == 0:
while tmp%2==0:
tmp //=2
sosu.add(2)
for i in range(3,n+1,2):
if tmp%i == 0:
while tmp%i==0:
tmp //=i
sosu.add(i)
stop_flag = tmp
if i > stop_flag:
break
else:
stop_flag = int(n/i)+1
if tmp!=1:
sosu.add(tmp)
if sosu==[1]:
sosu.add(n)
return sosu
def check_sosu(n,x):
ans=0
tmp = n
for i in x:
if (tmp % i) == 0:
ans+=1
return ans
ans = check_sosu(B,bunkai(A))
print(ans)
|
A,B =[int(x) for x in input().split()]
def bunkai(n):
sosu= {1}
tmp = n
if tmp%2 == 0:
while tmp%2==0:
tmp //=2
sosu.add(2)
for i in range(3,int(n**0.5)+1,2):
if tmp%i == 0:
while tmp%i==0:
tmp //=i
sosu.add(i)
if tmp!=1:
sosu.add(tmp)
if sosu==[1]:
sosu.add(n)
return sosu
def check_sosu(n,x):
ans=0
tmp = n
for i in x:
if (tmp % i) == 0:
ans+=1
return ans
ans = check_sosu(B,bunkai(A))
print(ans)
| 44 | 38 | 791 | 642 |
A, B = [int(x) for x in input().split()]
def bunkai(n):
sosu = {1}
tmp = n
stop_flag = n
if tmp % 2 == 0:
while tmp % 2 == 0:
tmp //= 2
sosu.add(2)
for i in range(3, n + 1, 2):
if tmp % i == 0:
while tmp % i == 0:
tmp //= i
sosu.add(i)
stop_flag = tmp
if i > stop_flag:
break
else:
stop_flag = int(n / i) + 1
if tmp != 1:
sosu.add(tmp)
if sosu == [1]:
sosu.add(n)
return sosu
def check_sosu(n, x):
ans = 0
tmp = n
for i in x:
if (tmp % i) == 0:
ans += 1
return ans
ans = check_sosu(B, bunkai(A))
print(ans)
|
A, B = [int(x) for x in input().split()]
def bunkai(n):
sosu = {1}
tmp = n
if tmp % 2 == 0:
while tmp % 2 == 0:
tmp //= 2
sosu.add(2)
for i in range(3, int(n**0.5) + 1, 2):
if tmp % i == 0:
while tmp % i == 0:
tmp //= i
sosu.add(i)
if tmp != 1:
sosu.add(tmp)
if sosu == [1]:
sosu.add(n)
return sosu
def check_sosu(n, x):
ans = 0
tmp = n
for i in x:
if (tmp % i) == 0:
ans += 1
return ans
ans = check_sosu(B, bunkai(A))
print(ans)
| false | 13.636364 |
[
"- stop_flag = n",
"- for i in range(3, n + 1, 2):",
"+ for i in range(3, int(n**0.5) + 1, 2):",
"- stop_flag = tmp",
"- if i > stop_flag:",
"- break",
"- else:",
"- stop_flag = int(n / i) + 1"
] | false | 0.049294 | 0.044371 | 1.110942 |
[
"s561770879",
"s085510318"
] |
u408791346
|
p03448
|
python
|
s953137059
|
s784658820
| 184 | 51 | 39,664 | 3,060 |
Accepted
|
Accepted
| 72.28 |
a = int(eval(input()))
b = int(eval(input()))
c = int(eval(input()))
x = int(eval(input()))
res = 0
for i in range(a+1):
for j in range(b+1):
for k in range(c+1):
total = i*500 + j*100 + k*50
if total == x:
res += 1
print(res)
|
a = int(eval(input()))
b = int(eval(input()))
c = int(eval(input()))
x = int(eval(input()))
ans = 0
for i in range(a+1):
for j in range(b+1):
for k in range(c+1):
if 500*i + 100*j + 50*k == x:
ans += 1
print(ans)
| 14 | 13 | 282 | 242 |
a = int(eval(input()))
b = int(eval(input()))
c = int(eval(input()))
x = int(eval(input()))
res = 0
for i in range(a + 1):
for j in range(b + 1):
for k in range(c + 1):
total = i * 500 + j * 100 + k * 50
if total == x:
res += 1
print(res)
|
a = int(eval(input()))
b = int(eval(input()))
c = int(eval(input()))
x = int(eval(input()))
ans = 0
for i in range(a + 1):
for j in range(b + 1):
for k in range(c + 1):
if 500 * i + 100 * j + 50 * k == x:
ans += 1
print(ans)
| false | 7.142857 |
[
"-res = 0",
"+ans = 0",
"- total = i * 500 + j * 100 + k * 50",
"- if total == x:",
"- res += 1",
"-print(res)",
"+ if 500 * i + 100 * j + 50 * k == x:",
"+ ans += 1",
"+print(ans)"
] | false | 0.128201 | 0.080549 | 1.591599 |
[
"s953137059",
"s784658820"
] |
u621935300
|
p03440
|
python
|
s416838297
|
s023876627
| 681 | 575 | 53,336 | 45,380 |
Accepted
|
Accepted
| 15.57 |
from collections import deque
from collections import defaultdict
import heapq
N,M=list(map(int, input().split()))
cost=list(map(int, input().split()))
if M==N-1:
print(0)
quit()
nl=[ [] for i in range(N) ]
for i in range(M):
x,y=list(map(int,input().split()))
nl[x].append(y)
nl[y].append(x)
d=[ None for i in range(N) ]
V=[ None for i in range(N) ]
group_cost=defaultdict(lambda: [])
def dfs(start):
q = deque([])
V[start]=start
d[start]=0
heapq.heappush(group_cost[start],cost[start])
q.append(start)
while len(q)!=0:
v=q.pop()
for i in nl[v]:
if V[i] is None:
V[i]=start
q.append(i)
heapq.heappush(group_cost[start],cost[i])
for i in range(N):
if V[i] is None:
dfs(i)
H = []
ans=0
for v in list(group_cost.values()):
v=sorted(v)
ans+=v[0]
H.append(v[1:])
nokori_cost=list(heapq.merge(*H))
if N < 2*(N-M-1):
print("Impossible")
elif M == N-1:
print(0)
else:
ans += sum(nokori_cost[:2*(N-M-1) - len(list(group_cost.keys()))])
print(ans)
|
from collections import deque
from collections import defaultdict
import heapq
N,M=list(map(int, input().split()))
cost=list(map(int, input().split()))
par=[i for i in range(N)]
def root(x):
if par[x]==x:
return x
else:
r=root(par[x])
par[x]=r
return r
def unite(x,y):
x=root(x)
y=root(y)
if x==y: return
par[x]=y
for i in range(M):
x,y=list(map(int,input().split()))
unite(x,y)
group_cost=defaultdict(lambda: [])
for i in range(N):
root(i)
group_cost[par[i]].append(cost[i])
H = []
ans=0
for v in list(group_cost.values()):
v=sorted(v)
ans+=v[0]
H.append(v[1:])
nokori_cost=list(heapq.merge(*H))
if N < 2*(N-M-1):
print("Impossible")
elif M == N-1:
print(0)
else:
ans += sum(nokori_cost[:2*(N-M-1) - len(list(group_cost.keys()))])
print(ans)
| 65 | 56 | 1,041 | 819 |
from collections import deque
from collections import defaultdict
import heapq
N, M = list(map(int, input().split()))
cost = list(map(int, input().split()))
if M == N - 1:
print(0)
quit()
nl = [[] for i in range(N)]
for i in range(M):
x, y = list(map(int, input().split()))
nl[x].append(y)
nl[y].append(x)
d = [None for i in range(N)]
V = [None for i in range(N)]
group_cost = defaultdict(lambda: [])
def dfs(start):
q = deque([])
V[start] = start
d[start] = 0
heapq.heappush(group_cost[start], cost[start])
q.append(start)
while len(q) != 0:
v = q.pop()
for i in nl[v]:
if V[i] is None:
V[i] = start
q.append(i)
heapq.heappush(group_cost[start], cost[i])
for i in range(N):
if V[i] is None:
dfs(i)
H = []
ans = 0
for v in list(group_cost.values()):
v = sorted(v)
ans += v[0]
H.append(v[1:])
nokori_cost = list(heapq.merge(*H))
if N < 2 * (N - M - 1):
print("Impossible")
elif M == N - 1:
print(0)
else:
ans += sum(nokori_cost[: 2 * (N - M - 1) - len(list(group_cost.keys()))])
print(ans)
|
from collections import deque
from collections import defaultdict
import heapq
N, M = list(map(int, input().split()))
cost = list(map(int, input().split()))
par = [i for i in range(N)]
def root(x):
if par[x] == x:
return x
else:
r = root(par[x])
par[x] = r
return r
def unite(x, y):
x = root(x)
y = root(y)
if x == y:
return
par[x] = y
for i in range(M):
x, y = list(map(int, input().split()))
unite(x, y)
group_cost = defaultdict(lambda: [])
for i in range(N):
root(i)
group_cost[par[i]].append(cost[i])
H = []
ans = 0
for v in list(group_cost.values()):
v = sorted(v)
ans += v[0]
H.append(v[1:])
nokori_cost = list(heapq.merge(*H))
if N < 2 * (N - M - 1):
print("Impossible")
elif M == N - 1:
print(0)
else:
ans += sum(nokori_cost[: 2 * (N - M - 1) - len(list(group_cost.keys()))])
print(ans)
| false | 13.846154 |
[
"-if M == N - 1:",
"- print(0)",
"- quit()",
"-nl = [[] for i in range(N)]",
"+par = [i for i in range(N)]",
"+",
"+",
"+def root(x):",
"+ if par[x] == x:",
"+ return x",
"+ else:",
"+ r = root(par[x])",
"+ par[x] = r",
"+ return r",
"+",
"+",
"+def unite(x, y):",
"+ x = root(x)",
"+ y = root(y)",
"+ if x == y:",
"+ return",
"+ par[x] = y",
"+",
"+",
"- nl[x].append(y)",
"- nl[y].append(x)",
"-d = [None for i in range(N)]",
"-V = [None for i in range(N)]",
"+ unite(x, y)",
"-",
"-",
"-def dfs(start):",
"- q = deque([])",
"- V[start] = start",
"- d[start] = 0",
"- heapq.heappush(group_cost[start], cost[start])",
"- q.append(start)",
"- while len(q) != 0:",
"- v = q.pop()",
"- for i in nl[v]:",
"- if V[i] is None:",
"- V[i] = start",
"- q.append(i)",
"- heapq.heappush(group_cost[start], cost[i])",
"-",
"-",
"- if V[i] is None:",
"- dfs(i)",
"+ root(i)",
"+ group_cost[par[i]].append(cost[i])"
] | false | 0.089482 | 0.064889 | 1.379004 |
[
"s416838297",
"s023876627"
] |
u347184682
|
p03739
|
python
|
s610336279
|
s344027267
| 146 | 111 | 20,580 | 20,692 |
Accepted
|
Accepted
| 23.97 |
import copy
n=int(eval(input()))
a=[int(x) for x in input().rstrip().split()]
ac=copy.deepcopy(a)
now=0
ans1=0
for i in range(n):
now+=a[i]
if i%2==0:
if now<=0:
ans1+=abs(now)+1
now=1
else:
if 0<=now:
ans1+=abs(now)+1
now=-1
now=0
ans2=0
for i in range(n):
now+=a[i]
if i%2==0:
if 0<=now:
ans2+=abs(now)+1
now=-1
else:
if now<=0:
ans2+=abs(now)+1
now=1
print((min(ans1,ans2)))
|
import copy
n=int(eval(input()))
a=[int(x) for x in input().rstrip().split()]
now=0
ans1=0
for i in range(n):
now+=a[i]
if i%2==0:
if now<=0:
ans1+=abs(now)+1
now=1
else:
if 0<=now:
ans1+=abs(now)+1
now=-1
now=0
ans2=0
for i in range(n):
now+=a[i]
if i%2==0:
if 0<=now:
ans2+=abs(now)+1
now=-1
else:
if now<=0:
ans2+=abs(now)+1
now=1
print((min(ans1,ans2)))
| 32 | 31 | 479 | 458 |
import copy
n = int(eval(input()))
a = [int(x) for x in input().rstrip().split()]
ac = copy.deepcopy(a)
now = 0
ans1 = 0
for i in range(n):
now += a[i]
if i % 2 == 0:
if now <= 0:
ans1 += abs(now) + 1
now = 1
else:
if 0 <= now:
ans1 += abs(now) + 1
now = -1
now = 0
ans2 = 0
for i in range(n):
now += a[i]
if i % 2 == 0:
if 0 <= now:
ans2 += abs(now) + 1
now = -1
else:
if now <= 0:
ans2 += abs(now) + 1
now = 1
print((min(ans1, ans2)))
|
import copy
n = int(eval(input()))
a = [int(x) for x in input().rstrip().split()]
now = 0
ans1 = 0
for i in range(n):
now += a[i]
if i % 2 == 0:
if now <= 0:
ans1 += abs(now) + 1
now = 1
else:
if 0 <= now:
ans1 += abs(now) + 1
now = -1
now = 0
ans2 = 0
for i in range(n):
now += a[i]
if i % 2 == 0:
if 0 <= now:
ans2 += abs(now) + 1
now = -1
else:
if now <= 0:
ans2 += abs(now) + 1
now = 1
print((min(ans1, ans2)))
| false | 3.125 |
[
"-ac = copy.deepcopy(a)"
] | false | 0.15165 | 0.041272 | 3.674385 |
[
"s610336279",
"s344027267"
] |
u496762077
|
p02928
|
python
|
s130785961
|
s687273497
| 639 | 439 | 3,188 | 3,188 |
Accepted
|
Accepted
| 31.3 |
n,k = list(map(int,input().split()))
a = list(map(int,input().split()))
ans1 = 0
ans3 = 0
for i in range(n-1):
for j in range(i+1,n):
if a[i]>a[j]:
ans1+=1
elif a[i]==a[j]:
ans3+=1
ans2 = (n*(n-1))//2 - ans1 - ans3
print(((ans1*((1+k)*k)//2+ans2*(k*(k-1))//2)%(10**9+7)))
|
n,k = list(map(int,input().split()))
a = list(map(int,input().split()))
inv = lambda w:sum([sum([a[i]>a[j] for j in range(i+1,n)]) for i in range(n-1)])
inv1 = lambda w:sum([sum([a[i]==a[j] for j in range(i+1,n)]) for i in range(n-1)])
ans1 = inv(a)
ans3 = inv1(a)
ans2 = (n*(n-1))//2 - ans1 - ans3
print(((ans1*((1+k)*k)//2+ans2*(k*(k-1))//2)%(10**9+7)))
| 12 | 8 | 318 | 354 |
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
ans1 = 0
ans3 = 0
for i in range(n - 1):
for j in range(i + 1, n):
if a[i] > a[j]:
ans1 += 1
elif a[i] == a[j]:
ans3 += 1
ans2 = (n * (n - 1)) // 2 - ans1 - ans3
print(((ans1 * ((1 + k) * k) // 2 + ans2 * (k * (k - 1)) // 2) % (10**9 + 7)))
|
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
inv = lambda w: sum([sum([a[i] > a[j] for j in range(i + 1, n)]) for i in range(n - 1)])
inv1 = lambda w: sum(
[sum([a[i] == a[j] for j in range(i + 1, n)]) for i in range(n - 1)]
)
ans1 = inv(a)
ans3 = inv1(a)
ans2 = (n * (n - 1)) // 2 - ans1 - ans3
print(((ans1 * ((1 + k) * k) // 2 + ans2 * (k * (k - 1)) // 2) % (10**9 + 7)))
| false | 33.333333 |
[
"-ans1 = 0",
"-ans3 = 0",
"-for i in range(n - 1):",
"- for j in range(i + 1, n):",
"- if a[i] > a[j]:",
"- ans1 += 1",
"- elif a[i] == a[j]:",
"- ans3 += 1",
"+inv = lambda w: sum([sum([a[i] > a[j] for j in range(i + 1, n)]) for i in range(n - 1)])",
"+inv1 = lambda w: sum(",
"+ [sum([a[i] == a[j] for j in range(i + 1, n)]) for i in range(n - 1)]",
"+)",
"+ans1 = inv(a)",
"+ans3 = inv1(a)"
] | false | 0.035664 | 0.115881 | 0.307766 |
[
"s130785961",
"s687273497"
] |
u492447501
|
p03308
|
python
|
s011829611
|
s125595437
| 19 | 17 | 3,060 | 2,940 |
Accepted
|
Accepted
| 10.53 |
N = int(eval(input()))
*A, = list(map(int, input().split()))
max = 0
for i in range(N):
for j in range(i+1,N):
temp = abs(A[i]-A[j])
if max < temp:
max = temp
print(max)
|
N = int(eval(input()))
*A, = list(map(int, input().split()))
A.sort()
print((abs(A[0]-A[N-1])))
| 11 | 5 | 201 | 86 |
N = int(eval(input()))
(*A,) = list(map(int, input().split()))
max = 0
for i in range(N):
for j in range(i + 1, N):
temp = abs(A[i] - A[j])
if max < temp:
max = temp
print(max)
|
N = int(eval(input()))
(*A,) = list(map(int, input().split()))
A.sort()
print((abs(A[0] - A[N - 1])))
| false | 54.545455 |
[
"-max = 0",
"-for i in range(N):",
"- for j in range(i + 1, N):",
"- temp = abs(A[i] - A[j])",
"- if max < temp:",
"- max = temp",
"-print(max)",
"+A.sort()",
"+print((abs(A[0] - A[N - 1])))"
] | false | 0.008774 | 0.042226 | 0.207793 |
[
"s011829611",
"s125595437"
] |
u477977638
|
p03436
|
python
|
s910996139
|
s947253828
| 179 | 73 | 39,408 | 71,088 |
Accepted
|
Accepted
| 59.22 |
import sys
input = sys.stdin.readline
#input = sys.stdin.buffer.readline
#sys.setrecursionlimit(10**9)
def RD(): return sys.stdin.read()
def II(): return int(eval(input()))
def MI(): return list(map(int,input().split()))
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode('utf-8')
#import numpy as np
from collections import deque
def main():
h,w=MI()
G=["#"]*(w+2)
for i in range(h):
G+=["#"]+list(input().rstrip())+["#"]
G+=["#"]*(w+2)
ans=0
#print(G)
for i in range((h+2)*(w+2)):
if G[i]==".":
ans+=1
Q=deque()
Q.append((w+3,1))
G[w+3]="#"
f=0
while Q:
#print(Q)
x,d=Q.popleft()
if x==(w+2)*(h+2)-(w+2)-2:
f=1
break
for dx in [-1,1,-w-2,w+2]:
if G[x+dx]==".":
Q.append((x+dx,d+1))
G[x+dx]="#"
if f==1:
print((ans-d))
else:
print((-1))
if __name__ == "__main__":
main()
|
import sys
input = sys.stdin.buffer.readline
#sys.setrecursionlimit(10**9)
#from functools import lru_cache
def RD(): return input().rstrip().decode()
def II(): return int(eval(input()))
def FI(): return float(eval(input()))
def MI(): return list(map(int,input().split()))
def MF(): return list(map(float,input().split()))
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()
from collections import deque
def main():
h,w=MI()
G=[]
G+=["#"]*(w+2)
for _ in range(h):
G+=["#"]+list(RD())+["#"]
G+=["#"]*(w+2)
cnt=G.count(".")
Q=deque()
Q.append([w+3,1])
G[w+3]=1
while Q:
now,d=Q.popleft()
for i in [1,-1,w+2,-w-2]:
if G[now+i]==".":
G[now+i]=d+1
Q.append([now+i,d+1])
ans=-1
if G[(w+2)*(h+2)-(w+4)]!=".":
ans=cnt-G[(w+2)*(h+2)-(w+4)]
print(ans)
if __name__ == "__main__":
main()
| 107 | 59 | 1,040 | 981 |
import sys
input = sys.stdin.readline
# input = sys.stdin.buffer.readline
# sys.setrecursionlimit(10**9)
def RD():
return sys.stdin.read()
def II():
return int(eval(input()))
def MI():
return list(map(int, input().split()))
def LI():
return list(map(int, input().split()))
def TI():
return tuple(map(int, input().split()))
# rstrip().decode('utf-8')
# import numpy as np
from collections import deque
def main():
h, w = MI()
G = ["#"] * (w + 2)
for i in range(h):
G += ["#"] + list(input().rstrip()) + ["#"]
G += ["#"] * (w + 2)
ans = 0
# print(G)
for i in range((h + 2) * (w + 2)):
if G[i] == ".":
ans += 1
Q = deque()
Q.append((w + 3, 1))
G[w + 3] = "#"
f = 0
while Q:
# print(Q)
x, d = Q.popleft()
if x == (w + 2) * (h + 2) - (w + 2) - 2:
f = 1
break
for dx in [-1, 1, -w - 2, w + 2]:
if G[x + dx] == ".":
Q.append((x + dx, d + 1))
G[x + dx] = "#"
if f == 1:
print((ans - d))
else:
print((-1))
if __name__ == "__main__":
main()
|
import sys
input = sys.stdin.buffer.readline
# sys.setrecursionlimit(10**9)
# from functools import lru_cache
def RD():
return input().rstrip().decode()
def II():
return int(eval(input()))
def FI():
return float(eval(input()))
def MI():
return list(map(int, input().split()))
def MF():
return list(map(float, input().split()))
def LI():
return list(map(int, input().split()))
def LF():
return list(map(float, input().split()))
def TI():
return tuple(map(int, input().split()))
# rstrip().decode()
from collections import deque
def main():
h, w = MI()
G = []
G += ["#"] * (w + 2)
for _ in range(h):
G += ["#"] + list(RD()) + ["#"]
G += ["#"] * (w + 2)
cnt = G.count(".")
Q = deque()
Q.append([w + 3, 1])
G[w + 3] = 1
while Q:
now, d = Q.popleft()
for i in [1, -1, w + 2, -w - 2]:
if G[now + i] == ".":
G[now + i] = d + 1
Q.append([now + i, d + 1])
ans = -1
if G[(w + 2) * (h + 2) - (w + 4)] != ".":
ans = cnt - G[(w + 2) * (h + 2) - (w + 4)]
print(ans)
if __name__ == "__main__":
main()
| false | 44.859813 |
[
"-input = sys.stdin.readline",
"-# input = sys.stdin.buffer.readline",
"+input = sys.stdin.buffer.readline",
"+# from functools import lru_cache",
"- return sys.stdin.read()",
"+ return input().rstrip().decode()",
"+def FI():",
"+ return float(eval(input()))",
"+",
"+",
"+",
"+",
"+def MF():",
"+ return list(map(float, input().split()))",
"+def LF():",
"+ return list(map(float, input().split()))",
"+",
"+",
"-# rstrip().decode('utf-8')",
"-# import numpy as np",
"+# rstrip().decode()",
"- G = [\"#\"] * (w + 2)",
"- for i in range(h):",
"- G += [\"#\"] + list(input().rstrip()) + [\"#\"]",
"+ G = []",
"- ans = 0",
"- # print(G)",
"- for i in range((h + 2) * (w + 2)):",
"- if G[i] == \".\":",
"- ans += 1",
"+ for _ in range(h):",
"+ G += [\"#\"] + list(RD()) + [\"#\"]",
"+ G += [\"#\"] * (w + 2)",
"+ cnt = G.count(\".\")",
"- Q.append((w + 3, 1))",
"- G[w + 3] = \"#\"",
"- f = 0",
"+ Q.append([w + 3, 1])",
"+ G[w + 3] = 1",
"- # print(Q)",
"- x, d = Q.popleft()",
"- if x == (w + 2) * (h + 2) - (w + 2) - 2:",
"- f = 1",
"- break",
"- for dx in [-1, 1, -w - 2, w + 2]:",
"- if G[x + dx] == \".\":",
"- Q.append((x + dx, d + 1))",
"- G[x + dx] = \"#\"",
"- if f == 1:",
"- print((ans - d))",
"- else:",
"- print((-1))",
"+ now, d = Q.popleft()",
"+ for i in [1, -1, w + 2, -w - 2]:",
"+ if G[now + i] == \".\":",
"+ G[now + i] = d + 1",
"+ Q.append([now + i, d + 1])",
"+ ans = -1",
"+ if G[(w + 2) * (h + 2) - (w + 4)] != \".\":",
"+ ans = cnt - G[(w + 2) * (h + 2) - (w + 4)]",
"+ print(ans)"
] | false | 0.039066 | 0.114649 | 0.340749 |
[
"s910996139",
"s947253828"
] |
u933341648
|
p03475
|
python
|
s677003912
|
s481627224
| 112 | 102 | 3,188 | 3,188 |
Accepted
|
Accepted
| 8.93 |
n = int(eval(input()))
station = [tuple(map(int, input().split())) for _ in range(n-1)]
for i in range(n-1):
res = 0
for j in range(i, n-1):
c, s, f = station[j]
if res == 0:
res += s + c
else:
res += max(s-res, ((res+(f-1))//f)*f - res) + c
print(res)
else:
print((0))
|
n = int(eval(input()))
station = [tuple(map(int, input().split())) for _ in range(n-1)]
for i in range(n):
res = 0
for j in range(i, n-1):
c, s, f = station[j]
res += max(s-res, ((res+(f-1))//f)*f - res) + c
print(res)
| 14 | 9 | 340 | 250 |
n = int(eval(input()))
station = [tuple(map(int, input().split())) for _ in range(n - 1)]
for i in range(n - 1):
res = 0
for j in range(i, n - 1):
c, s, f = station[j]
if res == 0:
res += s + c
else:
res += max(s - res, ((res + (f - 1)) // f) * f - res) + c
print(res)
else:
print((0))
|
n = int(eval(input()))
station = [tuple(map(int, input().split())) for _ in range(n - 1)]
for i in range(n):
res = 0
for j in range(i, n - 1):
c, s, f = station[j]
res += max(s - res, ((res + (f - 1)) // f) * f - res) + c
print(res)
| false | 35.714286 |
[
"-for i in range(n - 1):",
"+for i in range(n):",
"- if res == 0:",
"- res += s + c",
"- else:",
"- res += max(s - res, ((res + (f - 1)) // f) * f - res) + c",
"+ res += max(s - res, ((res + (f - 1)) // f) * f - res) + c",
"-else:",
"- print((0))"
] | false | 0.045803 | 0.044843 | 1.021404 |
[
"s677003912",
"s481627224"
] |
u811169796
|
p03353
|
python
|
s067102217
|
s239162074
| 102 | 44 | 41,840 | 5,052 |
Accepted
|
Accepted
| 56.86 |
s = eval(input())
k = int(eval(input()))
t = sorted(s)[min(k-1,len(s)-1)]
data = []
for i in range(len(s)):
if s[i] <= t:
data.append(s[i:])
data.sort()
if len(data) > k:
data = data[:k]
ndata = []
for ss in data:
for i in range(len(ss)):
ndata.append(ss[:i+1])
ndata = list(set(ndata))
ndata.sort()
print((ndata[k-1]))
|
s = eval(input())
k = int(eval(input()))
data = []
for i in range(len(s)):
for j in range(1,k+1):
data.append(s[i:min(i+j,len(s))])
data = list(set(data))
data.sort()
print((data[k-1]))
| 18 | 9 | 352 | 191 |
s = eval(input())
k = int(eval(input()))
t = sorted(s)[min(k - 1, len(s) - 1)]
data = []
for i in range(len(s)):
if s[i] <= t:
data.append(s[i:])
data.sort()
if len(data) > k:
data = data[:k]
ndata = []
for ss in data:
for i in range(len(ss)):
ndata.append(ss[: i + 1])
ndata = list(set(ndata))
ndata.sort()
print((ndata[k - 1]))
|
s = eval(input())
k = int(eval(input()))
data = []
for i in range(len(s)):
for j in range(1, k + 1):
data.append(s[i : min(i + j, len(s))])
data = list(set(data))
data.sort()
print((data[k - 1]))
| false | 50 |
[
"-t = sorted(s)[min(k - 1, len(s) - 1)]",
"- if s[i] <= t:",
"- data.append(s[i:])",
"+ for j in range(1, k + 1):",
"+ data.append(s[i : min(i + j, len(s))])",
"+data = list(set(data))",
"-if len(data) > k:",
"- data = data[:k]",
"-ndata = []",
"-for ss in data:",
"- for i in range(len(ss)):",
"- ndata.append(ss[: i + 1])",
"-ndata = list(set(ndata))",
"-ndata.sort()",
"-print((ndata[k - 1]))",
"+print((data[k - 1]))"
] | false | 0.097385 | 0.084502 | 1.152458 |
[
"s067102217",
"s239162074"
] |
u708255304
|
p02927
|
python
|
s829422281
|
s819687780
| 29 | 26 | 3,060 | 3,060 |
Accepted
|
Accepted
| 10.34 |
M, D = list(map(int, input().split()))
ans = 0
for i in range(1, M+1):
for j in range(1, D+1):
if len(str(j)) == 1:
continue
# 日付が二桁以上であることが確定
d1 = int(str(j)[0])
d2 = int(str(j)[1])
if d1 >= 2 and d2 >= 2:
if i == (d1*d2):
ans += 1
print(ans)
|
M, D = list(map(int, input().split()))
ans = 0
for i in range(1, M+1): # 月
for j in range(10, D+1): # 日付
d1 = int(str(j)[0])
d2 = int(str(j)[1])
if d1 > 1 and d2 > 1:
if i == (d1 * d2):
ans += 1
print(ans)
| 15 | 13 | 338 | 273 |
M, D = list(map(int, input().split()))
ans = 0
for i in range(1, M + 1):
for j in range(1, D + 1):
if len(str(j)) == 1:
continue
# 日付が二桁以上であることが確定
d1 = int(str(j)[0])
d2 = int(str(j)[1])
if d1 >= 2 and d2 >= 2:
if i == (d1 * d2):
ans += 1
print(ans)
|
M, D = list(map(int, input().split()))
ans = 0
for i in range(1, M + 1): # 月
for j in range(10, D + 1): # 日付
d1 = int(str(j)[0])
d2 = int(str(j)[1])
if d1 > 1 and d2 > 1:
if i == (d1 * d2):
ans += 1
print(ans)
| false | 13.333333 |
[
"-for i in range(1, M + 1):",
"- for j in range(1, D + 1):",
"- if len(str(j)) == 1:",
"- continue",
"- # 日付が二桁以上であることが確定",
"+for i in range(1, M + 1): # 月",
"+ for j in range(10, D + 1): # 日付",
"- if d1 >= 2 and d2 >= 2:",
"+ if d1 > 1 and d2 > 1:"
] | false | 0.151081 | 0.081542 | 1.852803 |
[
"s829422281",
"s819687780"
] |
u047796752
|
p02625
|
python
|
s160854871
|
s643463147
| 455 | 158 | 107,740 | 91,224 |
Accepted
|
Accepted
| 65.27 |
import sys
input = sys.stdin.readline
MAX = 5*10**5+100
MOD = 10**9+7
fact = [0]*MAX #fact[i]: i!
inv = [0]*MAX #inv[i]: iの逆元
finv = [0]*MAX #finv[i]: i!の逆元
fact[0] = 1
fact[1] = 1
finv[0] = 1
finv[1] = 1
inv[1] = 1
for i in range(2, MAX):
fact[i] = fact[i-1]*i%MOD
inv[i] = MOD-inv[MOD%i]*(MOD//i)%MOD
finv[i] = finv[i-1]*inv[i]%MOD
def C(n, r):
if n<r:
return 0
if n<0 or r<0:
return 0
return fact[n]*(finv[r]*finv[n-r]%MOD)%MOD
N, M = list(map(int, input().split()))
ans = (C(M, N)*fact[N])**2%MOD
for i in range(1, N+1):
if i%2==0:
ans += C(N, i)*C(M, i)*fact[i]*(C(M-i, N-i)*fact[N-i])**2
else:
ans -= C(N, i)*C(M, i)*fact[i]*(C(M-i, N-i)*fact[N-i])**2
ans %= MOD
print(ans)
|
MAX = 5*10**5+100
MOD = 10**9+7
fact = [0]*MAX #fact[i]: i!
inv = [0]*MAX #inv[i]: iの逆元
finv = [0]*MAX #finv[i]: i!の逆元
fact[0] = 1
fact[1] = 1
finv[0] = 1
finv[1] = 1
inv[1] = 1
for i in range(2, MAX):
fact[i] = fact[i-1]*i%MOD
inv[i] = MOD-inv[MOD%i]*(MOD//i)%MOD
finv[i] = finv[i-1]*inv[i]%MOD
def C(n, r):
if n<r:
return 0
if n<0 or r<0:
return 0
return fact[n]*(finv[r]*finv[n-r]%MOD)%MOD
N, M = list(map(int, input().split()))
ans = C(M, N)*fact[N]
for i in range(1, N+1):
if i%2==0:
ans += C(N, i)*C(M-i, N-i)*fact[N-i]
else:
ans -= C(N, i)*C(M-i, N-i)*fact[N-i]
ans %= MOD
ans = (ans*C(M, N))%MOD
ans = (ans*fact[N])%MOD
print(ans)
| 38 | 37 | 793 | 754 |
import sys
input = sys.stdin.readline
MAX = 5 * 10**5 + 100
MOD = 10**9 + 7
fact = [0] * MAX # fact[i]: i!
inv = [0] * MAX # inv[i]: iの逆元
finv = [0] * MAX # finv[i]: i!の逆元
fact[0] = 1
fact[1] = 1
finv[0] = 1
finv[1] = 1
inv[1] = 1
for i in range(2, MAX):
fact[i] = fact[i - 1] * i % MOD
inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
finv[i] = finv[i - 1] * inv[i] % MOD
def C(n, r):
if n < r:
return 0
if n < 0 or r < 0:
return 0
return fact[n] * (finv[r] * finv[n - r] % MOD) % MOD
N, M = list(map(int, input().split()))
ans = (C(M, N) * fact[N]) ** 2 % MOD
for i in range(1, N + 1):
if i % 2 == 0:
ans += C(N, i) * C(M, i) * fact[i] * (C(M - i, N - i) * fact[N - i]) ** 2
else:
ans -= C(N, i) * C(M, i) * fact[i] * (C(M - i, N - i) * fact[N - i]) ** 2
ans %= MOD
print(ans)
|
MAX = 5 * 10**5 + 100
MOD = 10**9 + 7
fact = [0] * MAX # fact[i]: i!
inv = [0] * MAX # inv[i]: iの逆元
finv = [0] * MAX # finv[i]: i!の逆元
fact[0] = 1
fact[1] = 1
finv[0] = 1
finv[1] = 1
inv[1] = 1
for i in range(2, MAX):
fact[i] = fact[i - 1] * i % MOD
inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
finv[i] = finv[i - 1] * inv[i] % MOD
def C(n, r):
if n < r:
return 0
if n < 0 or r < 0:
return 0
return fact[n] * (finv[r] * finv[n - r] % MOD) % MOD
N, M = list(map(int, input().split()))
ans = C(M, N) * fact[N]
for i in range(1, N + 1):
if i % 2 == 0:
ans += C(N, i) * C(M - i, N - i) * fact[N - i]
else:
ans -= C(N, i) * C(M - i, N - i) * fact[N - i]
ans %= MOD
ans = (ans * C(M, N)) % MOD
ans = (ans * fact[N]) % MOD
print(ans)
| false | 2.631579 |
[
"-import sys",
"-",
"-input = sys.stdin.readline",
"-ans = (C(M, N) * fact[N]) ** 2 % MOD",
"+ans = C(M, N) * fact[N]",
"- ans += C(N, i) * C(M, i) * fact[i] * (C(M - i, N - i) * fact[N - i]) ** 2",
"+ ans += C(N, i) * C(M - i, N - i) * fact[N - i]",
"- ans -= C(N, i) * C(M, i) * fact[i] * (C(M - i, N - i) * fact[N - i]) ** 2",
"+ ans -= C(N, i) * C(M - i, N - i) * fact[N - i]",
"+ans = (ans * C(M, N)) % MOD",
"+ans = (ans * fact[N]) % MOD"
] | false | 2.433616 | 2.057786 | 1.182638 |
[
"s160854871",
"s643463147"
] |
u094191970
|
p03475
|
python
|
s825965833
|
s576454915
| 228 | 105 | 42,732 | 3,188 |
Accepted
|
Accepted
| 53.95 |
n=int(eval(input()))
l=[list(map(int,input().split())) for i in range(n-1)]
for i in range(n-1):
ans=l[i][1]+l[i][0]
for j in range(i+1,n-1):
if ans<l[j][1]:
ans=l[j][1]+l[j][0]
else:
if ans%l[j][2]!=0:
ans+=l[j][2]-(ans%l[j][2])
ans+=l[j][0]
print(ans)
print((0))
|
n=int(eval(input()))
l=[list(map(int,input().split())) for i in range(n-1)]
for i in range(n-1):
t=l[i][1]
t+=l[i][0]
for j in range(i+1,n-1):
if t<l[j][1]:
t=l[j][1]
elif t%l[j][2]!=0:
t+=l[j][2]-t%l[j][2]
t+=l[j][0]
print(t)
print((0))
| 15 | 15 | 292 | 277 |
n = int(eval(input()))
l = [list(map(int, input().split())) for i in range(n - 1)]
for i in range(n - 1):
ans = l[i][1] + l[i][0]
for j in range(i + 1, n - 1):
if ans < l[j][1]:
ans = l[j][1] + l[j][0]
else:
if ans % l[j][2] != 0:
ans += l[j][2] - (ans % l[j][2])
ans += l[j][0]
print(ans)
print((0))
|
n = int(eval(input()))
l = [list(map(int, input().split())) for i in range(n - 1)]
for i in range(n - 1):
t = l[i][1]
t += l[i][0]
for j in range(i + 1, n - 1):
if t < l[j][1]:
t = l[j][1]
elif t % l[j][2] != 0:
t += l[j][2] - t % l[j][2]
t += l[j][0]
print(t)
print((0))
| false | 0 |
[
"- ans = l[i][1] + l[i][0]",
"+ t = l[i][1]",
"+ t += l[i][0]",
"- if ans < l[j][1]:",
"- ans = l[j][1] + l[j][0]",
"- else:",
"- if ans % l[j][2] != 0:",
"- ans += l[j][2] - (ans % l[j][2])",
"- ans += l[j][0]",
"- print(ans)",
"+ if t < l[j][1]:",
"+ t = l[j][1]",
"+ elif t % l[j][2] != 0:",
"+ t += l[j][2] - t % l[j][2]",
"+ t += l[j][0]",
"+ print(t)"
] | false | 0.039801 | 0.135748 | 0.2932 |
[
"s825965833",
"s576454915"
] |
u546285759
|
p00010
|
python
|
s366237897
|
s516115277
| 30 | 20 | 7,496 | 5,684 |
Accepted
|
Accepted
| 33.33 |
n = int(eval(input()))
for _ in range(n):
x1, y1, x2, y2, x3, y3 = list(map(float, input().split()))
a = pow(pow(x3-x2, 2) + pow(y3-y2, 2), 0.5)
b = pow(pow(x1-x3, 2) + pow(y1-y3, 2), 0.5)
c = pow(pow(x2-x1, 2) + pow(y2-y1, 2), 0.5)
cosA = (b**2+c**2-a**2) / (2*b*c)
sinA = 1-cosA**2
r = a / pow(sinA, 0.5) / 2
a, b, c = x1-x2, y1-y2, -(x1**2 + y1**2) + (x2**2 + y2**2)
d, e, f = x2-x3, y2-y3, -(x2**2 + y2**2) + (x3**2 + y3**2)
l = (c*e - b*f) / (e*a - b*d)
m = (c*d - a*f) / (b*d - a*e)
print(("{0:.3f} {1:.3f} {2:.3f}".format(-l/2, -m/2, r)))
|
n = int(eval(input()))
for _ in range(n):
x1, y1, x2, y2, x3, y3 = list(map(float, input().split()))
a = pow((x3-x2) ** 2 + (y3-y2) ** 2, 0.5)
b = pow((x3-x1) ** 2 + (y3-y1) ** 2, 0.5)
c = pow((x1-x2) ** 2 + (y1-y2) ** 2, 0.5)
cosA = (b**2 + c**2 - a**2) / (2*b*c)
sinA = pow(1 - cosA**2, 0.5)
R = a / sinA / 2
a, b, c = x1-x2, y1-y2, -(x1**2 + y1**2) + (x2**2 + y2**2)
d, e, f = x2-x3, y2-y3, -(x2**2 + y2**2) + (x3**2 + y3**2)
l = (c*e - b*f) / (e*a - b*d)
m = (c*d - a*f) / (b*d - a*e)
l, m = l*-0.5, m*-0.5
print(("{:.3f} {:.3f} {:.3f}".format(l, m, R)))
| 14 | 16 | 592 | 613 |
n = int(eval(input()))
for _ in range(n):
x1, y1, x2, y2, x3, y3 = list(map(float, input().split()))
a = pow(pow(x3 - x2, 2) + pow(y3 - y2, 2), 0.5)
b = pow(pow(x1 - x3, 2) + pow(y1 - y3, 2), 0.5)
c = pow(pow(x2 - x1, 2) + pow(y2 - y1, 2), 0.5)
cosA = (b**2 + c**2 - a**2) / (2 * b * c)
sinA = 1 - cosA**2
r = a / pow(sinA, 0.5) / 2
a, b, c = x1 - x2, y1 - y2, -(x1**2 + y1**2) + (x2**2 + y2**2)
d, e, f = x2 - x3, y2 - y3, -(x2**2 + y2**2) + (x3**2 + y3**2)
l = (c * e - b * f) / (e * a - b * d)
m = (c * d - a * f) / (b * d - a * e)
print(("{0:.3f} {1:.3f} {2:.3f}".format(-l / 2, -m / 2, r)))
|
n = int(eval(input()))
for _ in range(n):
x1, y1, x2, y2, x3, y3 = list(map(float, input().split()))
a = pow((x3 - x2) ** 2 + (y3 - y2) ** 2, 0.5)
b = pow((x3 - x1) ** 2 + (y3 - y1) ** 2, 0.5)
c = pow((x1 - x2) ** 2 + (y1 - y2) ** 2, 0.5)
cosA = (b**2 + c**2 - a**2) / (2 * b * c)
sinA = pow(1 - cosA**2, 0.5)
R = a / sinA / 2
a, b, c = x1 - x2, y1 - y2, -(x1**2 + y1**2) + (x2**2 + y2**2)
d, e, f = x2 - x3, y2 - y3, -(x2**2 + y2**2) + (x3**2 + y3**2)
l = (c * e - b * f) / (e * a - b * d)
m = (c * d - a * f) / (b * d - a * e)
l, m = l * -0.5, m * -0.5
print(("{:.3f} {:.3f} {:.3f}".format(l, m, R)))
| false | 12.5 |
[
"- a = pow(pow(x3 - x2, 2) + pow(y3 - y2, 2), 0.5)",
"- b = pow(pow(x1 - x3, 2) + pow(y1 - y3, 2), 0.5)",
"- c = pow(pow(x2 - x1, 2) + pow(y2 - y1, 2), 0.5)",
"+ a = pow((x3 - x2) ** 2 + (y3 - y2) ** 2, 0.5)",
"+ b = pow((x3 - x1) ** 2 + (y3 - y1) ** 2, 0.5)",
"+ c = pow((x1 - x2) ** 2 + (y1 - y2) ** 2, 0.5)",
"- sinA = 1 - cosA**2",
"- r = a / pow(sinA, 0.5) / 2",
"+ sinA = pow(1 - cosA**2, 0.5)",
"+ R = a / sinA / 2",
"- print((\"{0:.3f} {1:.3f} {2:.3f}\".format(-l / 2, -m / 2, r)))",
"+ l, m = l * -0.5, m * -0.5",
"+ print((\"{:.3f} {:.3f} {:.3f}\".format(l, m, R)))"
] | false | 0.047656 | 0.04795 | 0.99388 |
[
"s366237897",
"s516115277"
] |
u491763171
|
p00022
|
python
|
s916866619
|
s645525929
| 30 | 20 | 4,388 | 4,288 |
Accepted
|
Accepted
| 33.33 |
while 1:
n = eval(input())
if n == 0:
break
A = []
for i in range(n):
A.append(int(input()))
dp = [0] * len(A)
dp[0] = A[0]
for i in range(1, len(A)):
dp[i] = max(dp[i - 1] + A[i], A[i])
print(max(dp))
|
while 1:
n = int(input())
if n == 0:
break
A = [0] * n
for i in range(n):
A[i] = int(input())
for i in range(1, len(A)):
A[i] = max(A[i - 1] + A[i], A[i])
print(max(A))
| 13 | 10 | 269 | 234 |
while 1:
n = eval(input())
if n == 0:
break
A = []
for i in range(n):
A.append(int(input()))
dp = [0] * len(A)
dp[0] = A[0]
for i in range(1, len(A)):
dp[i] = max(dp[i - 1] + A[i], A[i])
print(max(dp))
|
while 1:
n = int(input())
if n == 0:
break
A = [0] * n
for i in range(n):
A[i] = int(input())
for i in range(1, len(A)):
A[i] = max(A[i - 1] + A[i], A[i])
print(max(A))
| false | 23.076923 |
[
"- n = eval(input())",
"+ n = int(input())",
"- A = []",
"+ A = [0] * n",
"- A.append(int(input()))",
"- dp = [0] * len(A)",
"- dp[0] = A[0]",
"+ A[i] = int(input())",
"- dp[i] = max(dp[i - 1] + A[i], A[i])",
"- print(max(dp))",
"+ A[i] = max(A[i - 1] + A[i], A[i])",
"+ print(max(A))"
] | false | 0.046351 | 0.14124 | 0.328169 |
[
"s916866619",
"s645525929"
] |
u360116509
|
p03074
|
python
|
s418844817
|
s304661614
| 96 | 85 | 4,092 | 7,884 |
Accepted
|
Accepted
| 11.46 |
def main():
N, K = list(map(int, input().split()))
S = eval(input())
nums = []
now = 1
cnt = 0
for s in S:
if int(s) == now:
cnt += 1
else:
nums.append(cnt)
now ^= 1
cnt = 1
if cnt > 0:
nums.append(cnt)
if len(nums) % 2 == 0:
nums.append(0)
add = 2 * K + 1
ans = 0
left = 0
right = 0
tmp = 0
for cnt in range(0, len(nums), 2):
nleft = cnt
nright = min(cnt + add, len(nums))
while nleft > left:
tmp -= nums[left]
left += 1
while nright > right:
tmp += nums[right]
right += 1
ans = max(tmp, ans)
print(ans)
main()
|
def main():
N, K = list(map(int, input().split()))
S = eval(input())
nums = []
now = 1
cnt = 0
for s in S:
if int(s) == now:
cnt += 1
else:
nums.append(cnt)
now ^= 1
cnt = 1
if cnt > 0:
nums.append(cnt)
if len(nums) % 2 == 0:
nums.append(0)
add = 2 * K + 1
sum = [0 for _ in range(len(nums) + 1)]
for i in range(len(nums)):
sum[i + 1] = sum[i] + nums[i]
ans = 0
for cnt in range(0, len(nums), 2):
left = cnt
right = min(cnt + add, len(nums))
tmp = sum[right] - sum[left]
ans = max(tmp, ans)
print(ans)
main()
| 36 | 31 | 765 | 705 |
def main():
N, K = list(map(int, input().split()))
S = eval(input())
nums = []
now = 1
cnt = 0
for s in S:
if int(s) == now:
cnt += 1
else:
nums.append(cnt)
now ^= 1
cnt = 1
if cnt > 0:
nums.append(cnt)
if len(nums) % 2 == 0:
nums.append(0)
add = 2 * K + 1
ans = 0
left = 0
right = 0
tmp = 0
for cnt in range(0, len(nums), 2):
nleft = cnt
nright = min(cnt + add, len(nums))
while nleft > left:
tmp -= nums[left]
left += 1
while nright > right:
tmp += nums[right]
right += 1
ans = max(tmp, ans)
print(ans)
main()
|
def main():
N, K = list(map(int, input().split()))
S = eval(input())
nums = []
now = 1
cnt = 0
for s in S:
if int(s) == now:
cnt += 1
else:
nums.append(cnt)
now ^= 1
cnt = 1
if cnt > 0:
nums.append(cnt)
if len(nums) % 2 == 0:
nums.append(0)
add = 2 * K + 1
sum = [0 for _ in range(len(nums) + 1)]
for i in range(len(nums)):
sum[i + 1] = sum[i] + nums[i]
ans = 0
for cnt in range(0, len(nums), 2):
left = cnt
right = min(cnt + add, len(nums))
tmp = sum[right] - sum[left]
ans = max(tmp, ans)
print(ans)
main()
| false | 13.888889 |
[
"+ sum = [0 for _ in range(len(nums) + 1)]",
"+ for i in range(len(nums)):",
"+ sum[i + 1] = sum[i] + nums[i]",
"- left = 0",
"- right = 0",
"- tmp = 0",
"- nleft = cnt",
"- nright = min(cnt + add, len(nums))",
"- while nleft > left:",
"- tmp -= nums[left]",
"- left += 1",
"- while nright > right:",
"- tmp += nums[right]",
"- right += 1",
"+ left = cnt",
"+ right = min(cnt + add, len(nums))",
"+ tmp = sum[right] - sum[left]"
] | false | 0.211079 | 0.046956 | 4.495214 |
[
"s418844817",
"s304661614"
] |
u224353074
|
p03161
|
python
|
s209249398
|
s420642851
| 1,837 | 356 | 22,780 | 52,448 |
Accepted
|
Accepted
| 80.62 |
import numpy as np
N, K = list(map(int, input().split()))
# H = np.array([int(h) for h in input().split()])
H = np.array(list(map(int, input().split())))
dp = np.zeros(N, dtype=int)
k = np.array([i for i in range(1, K+1)])
for n in range(1, N):
start = max(n-K, 0)
#if n < K:
# dp[n] = np.amin(dp[start] + np.abs(H[n]-H[start]))
#else:
# dp[n] = np.min(dp[n - k] + np.abs(H[n] - H[n - k]))
dp[n] = np.min(dp[start:n] + np.abs(H[n]-H[start:n]))
print((dp[N-1]))
|
N, K = list(map(int, input().split()))
H = list(map(int, input().split()))
INF = 10000000000
dp = [INF]*N
dp[0] = 0
for i in range(N):
for k in range(1, K+1):
if i + k < N:
dp[i + k] = min(dp[i + k], dp[i] + abs(H[i] - H[i + k]))
print((dp[N-1]))
| 17 | 13 | 499 | 277 |
import numpy as np
N, K = list(map(int, input().split()))
# H = np.array([int(h) for h in input().split()])
H = np.array(list(map(int, input().split())))
dp = np.zeros(N, dtype=int)
k = np.array([i for i in range(1, K + 1)])
for n in range(1, N):
start = max(n - K, 0)
# if n < K:
# dp[n] = np.amin(dp[start] + np.abs(H[n]-H[start]))
# else:
# dp[n] = np.min(dp[n - k] + np.abs(H[n] - H[n - k]))
dp[n] = np.min(dp[start:n] + np.abs(H[n] - H[start:n]))
print((dp[N - 1]))
|
N, K = list(map(int, input().split()))
H = list(map(int, input().split()))
INF = 10000000000
dp = [INF] * N
dp[0] = 0
for i in range(N):
for k in range(1, K + 1):
if i + k < N:
dp[i + k] = min(dp[i + k], dp[i] + abs(H[i] - H[i + k]))
print((dp[N - 1]))
| false | 23.529412 |
[
"-import numpy as np",
"-",
"-# H = np.array([int(h) for h in input().split()])",
"-H = np.array(list(map(int, input().split())))",
"-dp = np.zeros(N, dtype=int)",
"-k = np.array([i for i in range(1, K + 1)])",
"-for n in range(1, N):",
"- start = max(n - K, 0)",
"- # if n < K:",
"- # dp[n] = np.amin(dp[start] + np.abs(H[n]-H[start]))",
"- # else:",
"- # dp[n] = np.min(dp[n - k] + np.abs(H[n] - H[n - k]))",
"- dp[n] = np.min(dp[start:n] + np.abs(H[n] - H[start:n]))",
"+H = list(map(int, input().split()))",
"+INF = 10000000000",
"+dp = [INF] * N",
"+dp[0] = 0",
"+for i in range(N):",
"+ for k in range(1, K + 1):",
"+ if i + k < N:",
"+ dp[i + k] = min(dp[i + k], dp[i] + abs(H[i] - H[i + k]))"
] | false | 0.751136 | 0.123166 | 6.098556 |
[
"s209249398",
"s420642851"
] |
u347600233
|
p02899
|
python
|
s757734254
|
s423875313
| 194 | 147 | 13,880 | 29,280 |
Accepted
|
Accepted
| 24.23 |
n = int(input())
a = [int(i) for i in input().split()]
order = [0] * n
for i in range(n):
order[a[i] - 1] = i + 1
for i in range(n - 1):
print(str(order[i]), end=' ')
print(order[n - 1])
|
n = int(input())
a = sorted([(i, int(ai)) for i, ai in zip(range(1, n + 1), input().split())], key=lambda x: x[1])
for i in range(n):
print(a[i][0], end=' ')
| 8 | 4 | 201 | 164 |
n = int(input())
a = [int(i) for i in input().split()]
order = [0] * n
for i in range(n):
order[a[i] - 1] = i + 1
for i in range(n - 1):
print(str(order[i]), end=" ")
print(order[n - 1])
|
n = int(input())
a = sorted(
[(i, int(ai)) for i, ai in zip(range(1, n + 1), input().split())],
key=lambda x: x[1],
)
for i in range(n):
print(a[i][0], end=" ")
| false | 50 |
[
"-a = [int(i) for i in input().split()]",
"-order = [0] * n",
"+a = sorted(",
"+ [(i, int(ai)) for i, ai in zip(range(1, n + 1), input().split())],",
"+ key=lambda x: x[1],",
"+)",
"- order[a[i] - 1] = i + 1",
"-for i in range(n - 1):",
"- print(str(order[i]), end=\" \")",
"-print(order[n - 1])",
"+ print(a[i][0], end=\" \")"
] | false | 0.036338 | 0.056038 | 0.648446 |
[
"s757734254",
"s423875313"
] |
u027403702
|
p03814
|
python
|
s677002507
|
s539300090
| 73 | 18 | 3,512 | 3,500 |
Accepted
|
Accepted
| 75.34 |
s = eval(input())
i = 0
while i < len(s):
if s[i] == "A":
break
i += 1
j = 1
while j <= len(s):
if s[-j] == "Z":
break
j += 1
print(((len(s) - j) - i +1))
|
s = eval(input())
start = s.find("A")
end = s.rfind("Z")
print((end - start + 1))
| 12 | 4 | 189 | 76 |
s = eval(input())
i = 0
while i < len(s):
if s[i] == "A":
break
i += 1
j = 1
while j <= len(s):
if s[-j] == "Z":
break
j += 1
print(((len(s) - j) - i + 1))
|
s = eval(input())
start = s.find("A")
end = s.rfind("Z")
print((end - start + 1))
| false | 66.666667 |
[
"-i = 0",
"-while i < len(s):",
"- if s[i] == \"A\":",
"- break",
"- i += 1",
"-j = 1",
"-while j <= len(s):",
"- if s[-j] == \"Z\":",
"- break",
"- j += 1",
"-print(((len(s) - j) - i + 1))",
"+start = s.find(\"A\")",
"+end = s.rfind(\"Z\")",
"+print((end - start + 1))"
] | false | 0.037127 | 0.035493 | 1.046053 |
[
"s677002507",
"s539300090"
] |
u588341295
|
p03722
|
python
|
s591888690
|
s498443388
| 594 | 258 | 3,404 | 41,836 |
Accepted
|
Accepted
| 56.57 |
# -*- coding: utf-8 -*-
"""
・ベルマンフォード
"""
import sys
def input(): return sys.stdin.readline().strip()
sys.setrecursionlimit(10 ** 9)
N, M = list(map(int, input().split()))
edges = [None] * M
for i in range(M):
a, b, c = list(map(int, input().split()))
# 0-indexed
# コストの正負を逆転させれば最短経路問題として処理できる
edges[i] = (a-1, b-1, -c)
def bellman_ford(N: int, edges: list, start: int) -> list:
# 頂点[ある始点からの最短距離]
# (経路自体を知りたい時はここに前の頂点も持たせる)
verts = [float('inf')] * N
verts[start] = 0
# 各辺によるコストの置き換えを頂点数N-1回繰り返す
for i in range(N-1):
for src, dest, cost in edges:
verts[dest] = min(verts[src] + cost, verts[dest])
# 無限に減らせる場所がないか確認
for src, dest, cost in edges:
if verts[src] + cost < verts[dest]:
verts[dest] = verts[src] + cost
if dest == N-1:
# 頂点Nがそれに該当していたら空リストを返却
return []
# 問題なければ頂点リストを返却
return verts
verts = bellman_ford(N, edges, 0)
if not verts:
print('inf')
else:
# 正負を戻して出力
print((-verts[N-1]))
|
# -*- coding: utf-8 -*-
"""
参考:https://img.atcoder.jp/abc061/editorial.pdf
・ベルマンフォード
・負の閉路があっても、そこに頂点Nが含まれなければ今回はOK
って点に気付けなかったー。
"""
import sys
def input(): return sys.stdin.readline().strip()
sys.setrecursionlimit(10 ** 9)
N, M = list(map(int, input().split()))
edges = [None] * M
for i in range(M):
a, b, c = list(map(int, input().split()))
# 0-indexed
# コストの正負を逆転させれば最短経路問題として処理できる
edges[i] = (a-1, b-1, -c)
def bellman_ford(N: int, edges: list, start: int) -> list:
# 頂点[ある始点からの最短距離]
# (経路自体を知りたい時はここに前の頂点も持たせる)
verts = [float('inf')] * N
verts[start] = 0
# 各辺によるコストの置き換えを頂点数N-1回繰り返す
for i in range(N-1):
for src, dest, cost in edges:
if verts[dest] > verts[src] + cost:
verts[dest] = verts[src] + cost
# 無限に減らせる場所がないか確認
for i in range(N):
for src, dest, cost in edges:
if verts[dest] > verts[src] + cost:
verts[dest] = verts[src] + cost
if dest == N-1:
# 頂点Nがそれに該当していたら空リストを返却
return []
# 問題なければ頂点リストを返却
return verts
verts = bellman_ford(N, edges, 0)
if not verts:
print('inf')
else:
# 正負を戻して出力
print((-verts[N-1]))
| 44 | 49 | 1,080 | 1,259 |
# -*- coding: utf-8 -*-
"""
・ベルマンフォード
"""
import sys
def input():
return sys.stdin.readline().strip()
sys.setrecursionlimit(10**9)
N, M = list(map(int, input().split()))
edges = [None] * M
for i in range(M):
a, b, c = list(map(int, input().split()))
# 0-indexed
# コストの正負を逆転させれば最短経路問題として処理できる
edges[i] = (a - 1, b - 1, -c)
def bellman_ford(N: int, edges: list, start: int) -> list:
# 頂点[ある始点からの最短距離]
# (経路自体を知りたい時はここに前の頂点も持たせる)
verts = [float("inf")] * N
verts[start] = 0
# 各辺によるコストの置き換えを頂点数N-1回繰り返す
for i in range(N - 1):
for src, dest, cost in edges:
verts[dest] = min(verts[src] + cost, verts[dest])
# 無限に減らせる場所がないか確認
for src, dest, cost in edges:
if verts[src] + cost < verts[dest]:
verts[dest] = verts[src] + cost
if dest == N - 1:
# 頂点Nがそれに該当していたら空リストを返却
return []
# 問題なければ頂点リストを返却
return verts
verts = bellman_ford(N, edges, 0)
if not verts:
print("inf")
else:
# 正負を戻して出力
print((-verts[N - 1]))
|
# -*- coding: utf-8 -*-
"""
参考:https://img.atcoder.jp/abc061/editorial.pdf
・ベルマンフォード
・負の閉路があっても、そこに頂点Nが含まれなければ今回はOK
って点に気付けなかったー。
"""
import sys
def input():
return sys.stdin.readline().strip()
sys.setrecursionlimit(10**9)
N, M = list(map(int, input().split()))
edges = [None] * M
for i in range(M):
a, b, c = list(map(int, input().split()))
# 0-indexed
# コストの正負を逆転させれば最短経路問題として処理できる
edges[i] = (a - 1, b - 1, -c)
def bellman_ford(N: int, edges: list, start: int) -> list:
# 頂点[ある始点からの最短距離]
# (経路自体を知りたい時はここに前の頂点も持たせる)
verts = [float("inf")] * N
verts[start] = 0
# 各辺によるコストの置き換えを頂点数N-1回繰り返す
for i in range(N - 1):
for src, dest, cost in edges:
if verts[dest] > verts[src] + cost:
verts[dest] = verts[src] + cost
# 無限に減らせる場所がないか確認
for i in range(N):
for src, dest, cost in edges:
if verts[dest] > verts[src] + cost:
verts[dest] = verts[src] + cost
if dest == N - 1:
# 頂点Nがそれに該当していたら空リストを返却
return []
# 問題なければ頂点リストを返却
return verts
verts = bellman_ford(N, edges, 0)
if not verts:
print("inf")
else:
# 正負を戻して出力
print((-verts[N - 1]))
| false | 10.204082 |
[
"+参考:https://img.atcoder.jp/abc061/editorial.pdf",
"+・負の閉路があっても、そこに頂点Nが含まれなければ今回はOK",
"+ って点に気付けなかったー。",
"- verts[dest] = min(verts[src] + cost, verts[dest])",
"+ if verts[dest] > verts[src] + cost:",
"+ verts[dest] = verts[src] + cost",
"- for src, dest, cost in edges:",
"- if verts[src] + cost < verts[dest]:",
"- verts[dest] = verts[src] + cost",
"- if dest == N - 1:",
"- # 頂点Nがそれに該当していたら空リストを返却",
"- return []",
"+ for i in range(N):",
"+ for src, dest, cost in edges:",
"+ if verts[dest] > verts[src] + cost:",
"+ verts[dest] = verts[src] + cost",
"+ if dest == N - 1:",
"+ # 頂点Nがそれに該当していたら空リストを返却",
"+ return []"
] | false | 0.036662 | 0.035424 | 1.034946 |
[
"s591888690",
"s498443388"
] |
u785066634
|
p02817
|
python
|
s697117971
|
s973887908
| 19 | 17 | 3,060 | 2,940 |
Accepted
|
Accepted
| 10.53 |
b, c = list(map(str, input().split()))
print((c+b))
|
s,t=list(map(str,input().split()))
print((t+s))
| 3 | 3 | 46 | 42 |
b, c = list(map(str, input().split()))
print((c + b))
|
s, t = list(map(str, input().split()))
print((t + s))
| false | 0 |
[
"-b, c = list(map(str, input().split()))",
"-print((c + b))",
"+s, t = list(map(str, input().split()))",
"+print((t + s))"
] | false | 0.066108 | 0.048349 | 1.367302 |
[
"s697117971",
"s973887908"
] |
u925626880
|
p03478
|
python
|
s117740636
|
s715304873
| 30 | 27 | 2,940 | 2,940 |
Accepted
|
Accepted
| 10 |
# -*- coding: utf-8 -*-
n, a, b = list(map(int, input().split()))
s = 0
for i in range(1, n+1):
if a <= sum(map(int, str(i))) <=b:
s += i
print(s)
|
# -*- coding: utf-8 -*-
n, a, b = list(map(int, input().split()))
s = 0
print((sum(i if a <= sum(map(int, str(i))) <=b else 0
for i in range(1,n+1))))
| 11 | 8 | 173 | 170 |
# -*- coding: utf-8 -*-
n, a, b = list(map(int, input().split()))
s = 0
for i in range(1, n + 1):
if a <= sum(map(int, str(i))) <= b:
s += i
print(s)
|
# -*- coding: utf-8 -*-
n, a, b = list(map(int, input().split()))
s = 0
print((sum(i if a <= sum(map(int, str(i))) <= b else 0 for i in range(1, n + 1))))
| false | 27.272727 |
[
"-for i in range(1, n + 1):",
"- if a <= sum(map(int, str(i))) <= b:",
"- s += i",
"-print(s)",
"+print((sum(i if a <= sum(map(int, str(i))) <= b else 0 for i in range(1, n + 1))))"
] | false | 0.046819 | 0.047102 | 0.994006 |
[
"s117740636",
"s715304873"
] |
u374531474
|
p03592
|
python
|
s817534392
|
s149521687
| 317 | 18 | 2,940 | 2,940 |
Accepted
|
Accepted
| 94.32 |
N, M, K = list(map(int, input().split()))
ans = False
for n in range(N + 1):
for m in range(M + 1):
if n * (M - m) + m * (N - n) == K:
ans = True
break
else:
continue
break
print(('Yes' if ans else 'No'))
|
N, M, K = list(map(int, input().split()))
ans = False
for n in range(N + 1):
if 2 * n == N:
if M * n == K:
ans = True
break
else:
num = M * n - K
denom = 2 * n - N
if num % denom == 0 and 0 <= num // denom <= M:
ans = True
break
print(('Yes' if ans else 'No'))
| 12 | 15 | 261 | 356 |
N, M, K = list(map(int, input().split()))
ans = False
for n in range(N + 1):
for m in range(M + 1):
if n * (M - m) + m * (N - n) == K:
ans = True
break
else:
continue
break
print(("Yes" if ans else "No"))
|
N, M, K = list(map(int, input().split()))
ans = False
for n in range(N + 1):
if 2 * n == N:
if M * n == K:
ans = True
break
else:
num = M * n - K
denom = 2 * n - N
if num % denom == 0 and 0 <= num // denom <= M:
ans = True
break
print(("Yes" if ans else "No"))
| false | 20 |
[
"- for m in range(M + 1):",
"- if n * (M - m) + m * (N - n) == K:",
"+ if 2 * n == N:",
"+ if M * n == K:",
"- continue",
"- break",
"+ num = M * n - K",
"+ denom = 2 * n - N",
"+ if num % denom == 0 and 0 <= num // denom <= M:",
"+ ans = True",
"+ break"
] | false | 0.099521 | 0.035728 | 2.785522 |
[
"s817534392",
"s149521687"
] |
u133936772
|
p02947
|
python
|
s294280828
|
s127352936
| 404 | 346 | 10,640 | 19,404 |
Accepted
|
Accepted
| 14.36 |
n = int(eval(input()))
l = []
for i in range(n):
l.append(''.join(sorted(eval(input()))))
l.sort()
cnt = 0
ans = 0
for i in range(n-1):
if l[i+1] == l[i]:
cnt += 1
ans += cnt
else:
cnt = 0
print(ans)
|
n = int(eval(input()))
l = [''.join(sorted(eval(input()))) for _ in range(n)]
d = {}
ans = 0
for s in l:
if s in d:
d[s] += 1
ans += d[s]-1
else:
d[s] = 1
print(ans)
| 15 | 14 | 220 | 185 |
n = int(eval(input()))
l = []
for i in range(n):
l.append("".join(sorted(eval(input()))))
l.sort()
cnt = 0
ans = 0
for i in range(n - 1):
if l[i + 1] == l[i]:
cnt += 1
ans += cnt
else:
cnt = 0
print(ans)
|
n = int(eval(input()))
l = ["".join(sorted(eval(input()))) for _ in range(n)]
d = {}
ans = 0
for s in l:
if s in d:
d[s] += 1
ans += d[s] - 1
else:
d[s] = 1
print(ans)
| false | 6.666667 |
[
"-l = []",
"-for i in range(n):",
"- l.append(\"\".join(sorted(eval(input()))))",
"-l.sort()",
"-cnt = 0",
"+l = [\"\".join(sorted(eval(input()))) for _ in range(n)]",
"+d = {}",
"-for i in range(n - 1):",
"- if l[i + 1] == l[i]:",
"- cnt += 1",
"- ans += cnt",
"+for s in l:",
"+ if s in d:",
"+ d[s] += 1",
"+ ans += d[s] - 1",
"- cnt = 0",
"+ d[s] = 1"
] | false | 0.04423 | 0.111158 | 0.397904 |
[
"s294280828",
"s127352936"
] |
u879870653
|
p02981
|
python
|
s699795811
|
s286244680
| 20 | 17 | 3,316 | 2,940 |
Accepted
|
Accepted
| 15 |
N,A,B=list(map(int,input().split()));print((min(A*N,B)))
|
N, A, B = list(map(int,input().split()))
print((min(N*A, B)))
| 1 | 2 | 48 | 54 |
N, A, B = list(map(int, input().split()))
print((min(A * N, B)))
|
N, A, B = list(map(int, input().split()))
print((min(N * A, B)))
| false | 50 |
[
"-print((min(A * N, B)))",
"+print((min(N * A, B)))"
] | false | 0.147196 | 0.066814 | 2.203065 |
[
"s699795811",
"s286244680"
] |
u831244171
|
p02274
|
python
|
s725743611
|
s807182582
| 1,780 | 1,640 | 31,064 | 30,280 |
Accepted
|
Accepted
| 7.87 |
from collections import deque
def mergeSort(A,left,right):
middle = (left + right) // 2
if left + 1 < right:
mergeSort(A, left, middle)
mergeSort(A, middle, right)
merge(A,left,right,middle)
def merge(A,left,right,middle):
global count
L = deque(A[left:middle])
R = deque(A[middle:right])
L.append(float("inf"))
R.append(float("inf"))
for i in range(left,right):
if L[0] < R[0]:
A[i] = L.popleft()
else:
A[i] = R.popleft()
count += len(L) -1
count = 0
eval(input())
A = list(map(int,input().split()))
mergeSort(A,0,len(A))
print(count)
|
from _collections import deque
SENIAL = 1000000000
def mergeSort(A,left,right):
if left + 1 < right:
middle = (left + right) // 2
mergeSort(A, left, middle)
mergeSort(A, middle, right)
merge(A,left,right,middle)
def merge(A,left,right,middle):
global count
L = deque(A[left:middle])
R = deque(A[middle:right])
L.append(SENIAL)
R.append(SENIAL)
for i in range(left,right):
if L[0] < R[0]:
A[i] = L.popleft()
else:
A[i] = R.popleft()
count += len(L) -1
count = 0
eval(input())
A = list(map(int,input().split()))
mergeSort(A,0,len(A))
print(count)
| 28 | 27 | 694 | 696 |
from collections import deque
def mergeSort(A, left, right):
middle = (left + right) // 2
if left + 1 < right:
mergeSort(A, left, middle)
mergeSort(A, middle, right)
merge(A, left, right, middle)
def merge(A, left, right, middle):
global count
L = deque(A[left:middle])
R = deque(A[middle:right])
L.append(float("inf"))
R.append(float("inf"))
for i in range(left, right):
if L[0] < R[0]:
A[i] = L.popleft()
else:
A[i] = R.popleft()
count += len(L) - 1
count = 0
eval(input())
A = list(map(int, input().split()))
mergeSort(A, 0, len(A))
print(count)
|
from _collections import deque
SENIAL = 1000000000
def mergeSort(A, left, right):
if left + 1 < right:
middle = (left + right) // 2
mergeSort(A, left, middle)
mergeSort(A, middle, right)
merge(A, left, right, middle)
def merge(A, left, right, middle):
global count
L = deque(A[left:middle])
R = deque(A[middle:right])
L.append(SENIAL)
R.append(SENIAL)
for i in range(left, right):
if L[0] < R[0]:
A[i] = L.popleft()
else:
A[i] = R.popleft()
count += len(L) - 1
count = 0
eval(input())
A = list(map(int, input().split()))
mergeSort(A, 0, len(A))
print(count)
| false | 3.571429 |
[
"-from collections import deque",
"+from _collections import deque",
"+",
"+SENIAL = 1000000000",
"- middle = (left + right) // 2",
"+ middle = (left + right) // 2",
"- L.append(float(\"inf\"))",
"- R.append(float(\"inf\"))",
"+ L.append(SENIAL)",
"+ R.append(SENIAL)"
] | false | 0.039372 | 0.038359 | 1.026406 |
[
"s725743611",
"s807182582"
] |
u396495667
|
p03211
|
python
|
s395731784
|
s201907935
| 20 | 17 | 3,060 | 3,060 |
Accepted
|
Accepted
| 15 |
s = eval(input())
min = 100000000
for i in range(len(s)-2):
a = int(s[i:i+3])
dis = ((753-a)**2)**0.5
if dis <min:
min =dis
print((int(min)))
|
s = list(eval(input()))
a =''
l =[]
for i in range(2,len(s)):
a = s[i-2] + s[i-1] +s[i]
a_n = int(''.join(a))
b =abs(a_n-753)
l.append(b)
print((min(l)))
| 8 | 9 | 150 | 161 |
s = eval(input())
min = 100000000
for i in range(len(s) - 2):
a = int(s[i : i + 3])
dis = ((753 - a) ** 2) ** 0.5
if dis < min:
min = dis
print((int(min)))
|
s = list(eval(input()))
a = ""
l = []
for i in range(2, len(s)):
a = s[i - 2] + s[i - 1] + s[i]
a_n = int("".join(a))
b = abs(a_n - 753)
l.append(b)
print((min(l)))
| false | 11.111111 |
[
"-s = eval(input())",
"-min = 100000000",
"-for i in range(len(s) - 2):",
"- a = int(s[i : i + 3])",
"- dis = ((753 - a) ** 2) ** 0.5",
"- if dis < min:",
"- min = dis",
"-print((int(min)))",
"+s = list(eval(input()))",
"+a = \"\"",
"+l = []",
"+for i in range(2, len(s)):",
"+ a = s[i - 2] + s[i - 1] + s[i]",
"+ a_n = int(\"\".join(a))",
"+ b = abs(a_n - 753)",
"+ l.append(b)",
"+print((min(l)))"
] | false | 0.048487 | 0.049811 | 0.973422 |
[
"s395731784",
"s201907935"
] |
u368780724
|
p03033
|
python
|
s587488402
|
s905109284
| 1,895 | 1,665 | 142,584 | 131,736 |
Accepted
|
Accepted
| 12.14 |
import sys
from itertools import accumulate
from collections import Counter
from bisect import bisect as br, bisect_left as bl
from operator import itemgetter
class DammyMap:
#1-indexed
def __init__(self, A, B):
#Aに初期状態の要素をすべて入れる,Bは値域のリスト
self.X, self.comp = self.compress(B)
self.size = len(self.X)
self.tree = [0] * (self.size + 1)
self.p = 2**(self.size.bit_length() - 1)
self.dep = self.size.bit_length()
CA = Counter(A)
S = [0] + list(accumulate([CA[self.X[i]] for i in range(self.size)]))
for i in range(1, 1+self.size):
self.tree[i] = S[i] - S[i - (i&-i)]
def compress(self, L):
#座圧
L2 = list(set(L))
L2.sort()
C = {v : k for k, v in enumerate(L2, 1)}
# 1-indexed
return L2, C
def leng(self):
#今入っている個数を取得
return self.count(self.size)
def count(self, i):
#i(Bの元)以下の個数を取得
s = 0
while i > 0:
s += self.tree[i]
i -= i & -i
return s
def less(self, v):
#v(Bの元である必要はない)未満の個数を取得
i = bl(self.X, v)
s = 0
while i > 0:
s += self.tree[i]
i -= i & -i
return s
def leq(self, v):
#v(Bの元である必要はない)以下の個数を取得
i = br(self.X, v)
s = 0
while i > 0:
s += self.tree[i]
i -= i & -i
return s
def add(self, i, x):
#iをx個入れる,負のxで取り出す,iの個数以上取り出すとエラーを出さずにバグる
i = self.comp[i]
while i <= self.size:
self.tree[i] += x
i += i & -i
def get(self, v):
# v番目の値を取得
if v <= 0:
return -1
s = 0
k = self.p
for _ in range(self.dep):
if s + k <= self.size and self.tree[s+k] < v:
s += k
v -= self.tree[s]
k //= 2
return self.X[s]
def compress(L):
L2 = list(set(L))
L2.sort()
C = {v : k for k, v in enumerate(L2)}
return L2, C
N, Q = map(int, input().split())
stx = [tuple(map(int, sys.stdin.readline().split())) for _ in range(N)]
stx.sort(key = itemgetter(2))
D = [int(sys.stdin.readline()) for _ in range(Q)]
_, comp = compress(D)
T = DammyMap(D, D)
ans = [-1]*Q
for s, t, x in stx:
tl = T.less(s - x)
tr = T.less(t - x)
d = tr - tl
for _ in range(d):
i = T.get(tl + 1)
T.add(i, -1)
ans[comp[i]] = x
print(*ans, sep = '\n')
|
import sys
from itertools import accumulate
from collections import Counter
from bisect import bisect as br, bisect_left as bl
from operator import itemgetter
class DammyMap:
#1-indexed
def __init__(self, A, B):
#Aに初期状態の要素をすべて入れる,Bは値域のリスト
#self.X, self.comp = self.compress(B)
self.X = B[:]
self.comp = {v : k for k, v in enumerate(D, 1)}
self.size = len(self.X)
self.tree = [0] * (self.size + 1)
self.p = 2**(self.size.bit_length() - 1)
self.dep = self.size.bit_length()
CA = Counter(A)
S = [0] + list(accumulate([CA[self.X[i]] for i in range(self.size)]))
for i in range(1, 1+self.size):
self.tree[i] = S[i] - S[i - (i&-i)]
def compress(self, L):
#座圧
L2 = list(set(L))
L2.sort()
C = {v : k for k, v in enumerate(L2, 1)}
# 1-indexed
return L2, C
def leng(self):
#今入っている個数を取得
return self.count(self.size)
def count(self, i):
#i(Bの元)以下の個数を取得
s = 0
while i > 0:
s += self.tree[i]
i -= i & -i
return s
def less(self, v):
#v(Bの元である必要はない)未満の個数を取得
i = bl(self.X, v)
s = 0
while i > 0:
s += self.tree[i]
i -= i & -i
return s
def leq(self, v):
#v(Bの元である必要はない)以下の個数を取得
i = br(self.X, v)
s = 0
while i > 0:
s += self.tree[i]
i -= i & -i
return s
def add(self, i, x):
#iをx個入れる,負のxで取り出す,iの個数以上取り出すとエラーを出さずにバグる
i = self.comp[i]
while i <= self.size:
self.tree[i] += x
i += i & -i
def get(self, v):
# v番目の値を取得
if v <= 0:
return -1
s = 0
k = self.p
for _ in range(self.dep):
if s + k <= self.size and self.tree[s+k] < v:
s += k
v -= self.tree[s]
k //= 2
return self.X[s]
N, Q = map(int, input().split())
stx = [tuple(map(int, sys.stdin.readline().split())) for _ in range(N)]
stx.sort(key = itemgetter(2))
D = [int(sys.stdin.readline()) for _ in range(Q)]
T = DammyMap(D, D)
ans = [-1]*Q
for s, t, x in stx:
tl = T.less(s - x)
tr = T.less(t - x)
d = tr - tl
for _ in range(d):
i = T.get(tl + 1)
T.add(i, -1)
ans[T.comp[i]-1] = x
print(*ans, sep = '\n')
| 104 | 98 | 2,643 | 2,584 |
import sys
from itertools import accumulate
from collections import Counter
from bisect import bisect as br, bisect_left as bl
from operator import itemgetter
class DammyMap:
# 1-indexed
def __init__(self, A, B):
# Aに初期状態の要素をすべて入れる,Bは値域のリスト
self.X, self.comp = self.compress(B)
self.size = len(self.X)
self.tree = [0] * (self.size + 1)
self.p = 2 ** (self.size.bit_length() - 1)
self.dep = self.size.bit_length()
CA = Counter(A)
S = [0] + list(accumulate([CA[self.X[i]] for i in range(self.size)]))
for i in range(1, 1 + self.size):
self.tree[i] = S[i] - S[i - (i & -i)]
def compress(self, L):
# 座圧
L2 = list(set(L))
L2.sort()
C = {v: k for k, v in enumerate(L2, 1)}
# 1-indexed
return L2, C
def leng(self):
# 今入っている個数を取得
return self.count(self.size)
def count(self, i):
# i(Bの元)以下の個数を取得
s = 0
while i > 0:
s += self.tree[i]
i -= i & -i
return s
def less(self, v):
# v(Bの元である必要はない)未満の個数を取得
i = bl(self.X, v)
s = 0
while i > 0:
s += self.tree[i]
i -= i & -i
return s
def leq(self, v):
# v(Bの元である必要はない)以下の個数を取得
i = br(self.X, v)
s = 0
while i > 0:
s += self.tree[i]
i -= i & -i
return s
def add(self, i, x):
# iをx個入れる,負のxで取り出す,iの個数以上取り出すとエラーを出さずにバグる
i = self.comp[i]
while i <= self.size:
self.tree[i] += x
i += i & -i
def get(self, v):
# v番目の値を取得
if v <= 0:
return -1
s = 0
k = self.p
for _ in range(self.dep):
if s + k <= self.size and self.tree[s + k] < v:
s += k
v -= self.tree[s]
k //= 2
return self.X[s]
def compress(L):
L2 = list(set(L))
L2.sort()
C = {v: k for k, v in enumerate(L2)}
return L2, C
N, Q = map(int, input().split())
stx = [tuple(map(int, sys.stdin.readline().split())) for _ in range(N)]
stx.sort(key=itemgetter(2))
D = [int(sys.stdin.readline()) for _ in range(Q)]
_, comp = compress(D)
T = DammyMap(D, D)
ans = [-1] * Q
for s, t, x in stx:
tl = T.less(s - x)
tr = T.less(t - x)
d = tr - tl
for _ in range(d):
i = T.get(tl + 1)
T.add(i, -1)
ans[comp[i]] = x
print(*ans, sep="\n")
|
import sys
from itertools import accumulate
from collections import Counter
from bisect import bisect as br, bisect_left as bl
from operator import itemgetter
class DammyMap:
# 1-indexed
def __init__(self, A, B):
# Aに初期状態の要素をすべて入れる,Bは値域のリスト
# self.X, self.comp = self.compress(B)
self.X = B[:]
self.comp = {v: k for k, v in enumerate(D, 1)}
self.size = len(self.X)
self.tree = [0] * (self.size + 1)
self.p = 2 ** (self.size.bit_length() - 1)
self.dep = self.size.bit_length()
CA = Counter(A)
S = [0] + list(accumulate([CA[self.X[i]] for i in range(self.size)]))
for i in range(1, 1 + self.size):
self.tree[i] = S[i] - S[i - (i & -i)]
def compress(self, L):
# 座圧
L2 = list(set(L))
L2.sort()
C = {v: k for k, v in enumerate(L2, 1)}
# 1-indexed
return L2, C
def leng(self):
# 今入っている個数を取得
return self.count(self.size)
def count(self, i):
# i(Bの元)以下の個数を取得
s = 0
while i > 0:
s += self.tree[i]
i -= i & -i
return s
def less(self, v):
# v(Bの元である必要はない)未満の個数を取得
i = bl(self.X, v)
s = 0
while i > 0:
s += self.tree[i]
i -= i & -i
return s
def leq(self, v):
# v(Bの元である必要はない)以下の個数を取得
i = br(self.X, v)
s = 0
while i > 0:
s += self.tree[i]
i -= i & -i
return s
def add(self, i, x):
# iをx個入れる,負のxで取り出す,iの個数以上取り出すとエラーを出さずにバグる
i = self.comp[i]
while i <= self.size:
self.tree[i] += x
i += i & -i
def get(self, v):
# v番目の値を取得
if v <= 0:
return -1
s = 0
k = self.p
for _ in range(self.dep):
if s + k <= self.size and self.tree[s + k] < v:
s += k
v -= self.tree[s]
k //= 2
return self.X[s]
N, Q = map(int, input().split())
stx = [tuple(map(int, sys.stdin.readline().split())) for _ in range(N)]
stx.sort(key=itemgetter(2))
D = [int(sys.stdin.readline()) for _ in range(Q)]
T = DammyMap(D, D)
ans = [-1] * Q
for s, t, x in stx:
tl = T.less(s - x)
tr = T.less(t - x)
d = tr - tl
for _ in range(d):
i = T.get(tl + 1)
T.add(i, -1)
ans[T.comp[i] - 1] = x
print(*ans, sep="\n")
| false | 5.769231 |
[
"- self.X, self.comp = self.compress(B)",
"+ # self.X, self.comp = self.compress(B)",
"+ self.X = B[:]",
"+ self.comp = {v: k for k, v in enumerate(D, 1)}",
"-def compress(L):",
"- L2 = list(set(L))",
"- L2.sort()",
"- C = {v: k for k, v in enumerate(L2)}",
"- return L2, C",
"-",
"-",
"-_, comp = compress(D)",
"- ans[comp[i]] = x",
"+ ans[T.comp[i] - 1] = x"
] | false | 0.03836 | 0.038231 | 1.003365 |
[
"s587488402",
"s905109284"
] |
u113971909
|
p02550
|
python
|
s168825582
|
s766446255
| 89 | 78 | 13,124 | 13,312 |
Accepted
|
Accepted
| 12.36 |
#!/usr/bin python3
# -*- coding: utf-8 -*-
n, x, m = list(map(int, input().split()))
s = set([])
v = []
for i in range(m+1):
s.add(x)
v.append(x)
x = pow(x,2,m)
if x in s:
break
st = v.index(x)
lp = len(v)-st
lps = sum(v[st:])
k = (n-(st+lp)+(lp-1))//lp
ret = lps * k
n -= lp * k
ret += sum(v[:n])
print(ret)
|
#!/usr/bin python3
# -*- coding: utf-8 -*-
# ループを検索して計算量圧縮
# 0->1->...->st->st+1->...->st+lp-1-┐
# └─────────────────────┘
# lp
n, x, m = list(map(int, input().split()))
seen = set([])
seqs = []
for i in range(m+1):
seen.add(x)
seqs.append(x)
x = pow(x,2,m)
if x in seen:
break
start = seqs.index(x)
lp = len(seqs) - start
lpsum = sum(seqs[start:])
lptimes = (n-(start+lp)+(lp-1))//lp
ret_sum = lpsum * lptimes
n -= lp * lptimes
ret_sum += sum(seqs[:n])
ret_val = seqs[n-1]
print(ret_sum)
#print(ret_val)
| 23 | 31 | 352 | 592 |
#!/usr/bin python3
# -*- coding: utf-8 -*-
n, x, m = list(map(int, input().split()))
s = set([])
v = []
for i in range(m + 1):
s.add(x)
v.append(x)
x = pow(x, 2, m)
if x in s:
break
st = v.index(x)
lp = len(v) - st
lps = sum(v[st:])
k = (n - (st + lp) + (lp - 1)) // lp
ret = lps * k
n -= lp * k
ret += sum(v[:n])
print(ret)
|
#!/usr/bin python3
# -*- coding: utf-8 -*-
# ループを検索して計算量圧縮
# 0->1->...->st->st+1->...->st+lp-1-┐
# └─────────────────────┘
# lp
n, x, m = list(map(int, input().split()))
seen = set([])
seqs = []
for i in range(m + 1):
seen.add(x)
seqs.append(x)
x = pow(x, 2, m)
if x in seen:
break
start = seqs.index(x)
lp = len(seqs) - start
lpsum = sum(seqs[start:])
lptimes = (n - (start + lp) + (lp - 1)) // lp
ret_sum = lpsum * lptimes
n -= lp * lptimes
ret_sum += sum(seqs[:n])
ret_val = seqs[n - 1]
print(ret_sum)
# print(ret_val)
| false | 25.806452 |
[
"+# ループを検索して計算量圧縮",
"+# 0->1->...->st->st+1->...->st+lp-1-┐",
"+# └─────────────────────┘",
"+# lp",
"-s = set([])",
"-v = []",
"+seen = set([])",
"+seqs = []",
"- s.add(x)",
"- v.append(x)",
"+ seen.add(x)",
"+ seqs.append(x)",
"- if x in s:",
"+ if x in seen:",
"-st = v.index(x)",
"-lp = len(v) - st",
"-lps = sum(v[st:])",
"-k = (n - (st + lp) + (lp - 1)) // lp",
"-ret = lps * k",
"-n -= lp * k",
"-ret += sum(v[:n])",
"-print(ret)",
"+start = seqs.index(x)",
"+lp = len(seqs) - start",
"+lpsum = sum(seqs[start:])",
"+lptimes = (n - (start + lp) + (lp - 1)) // lp",
"+ret_sum = lpsum * lptimes",
"+n -= lp * lptimes",
"+ret_sum += sum(seqs[:n])",
"+ret_val = seqs[n - 1]",
"+print(ret_sum)",
"+# print(ret_val)"
] | false | 0.081979 | 0.085125 | 0.963046 |
[
"s168825582",
"s766446255"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.