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
|
p03085
|
python
|
s511171130
|
s847991586
| 167 | 22 | 38,256 | 8,860 |
Accepted
|
Accepted
| 86.83 |
print(('TCG鬱A'[ord(eval(input()))%5]))
|
print(('TCG A'[ord(eval(input()))%5]))
| 1 | 1 | 30 | 30 |
print(("TCG鬱A"[ord(eval(input())) % 5]))
|
print(("TCG A"[ord(eval(input())) % 5]))
| false | 0 |
[
"-print((\"TCG鬱A\"[ord(eval(input())) % 5]))",
"+print((\"TCG A\"[ord(eval(input())) % 5]))"
] | false | 0.052437 | 0.037405 | 1.401874 |
[
"s511171130",
"s847991586"
] |
u979823197
|
p03295
|
python
|
s682387351
|
s510042765
| 472 | 303 | 21,268 | 92,804 |
Accepted
|
Accepted
| 35.81 |
N,M=list(map(int,input().split()))
ab=[]
for m in range(M):
[a,b]=[int(i) for i in input().split()]
ab.append([a,b])
ab.sort(key=lambda x:x[1])
count=[]
count.append(ab[0][1]-1)
for i in range(1,M):
if ab[i][0]<=count[-1]<ab[i][1]:
pass
elif ab[i][0]<=count[-1] and ab[i][1]-1==count[-1]:
count.remove(count[-1])
count.append(ab[i][1]-1)
else:
count.append(ab[i][1]-1)
print((len(count)))
|
n,m=list(map(int,input().split()))
B=[]
for _ in range(m):
a,b=list(map(int,input().split()))
B.append([a-1,b-1])
B=sorted(B,key=lambda x:x[1])
ans=m
for i in range(1,m):
if B[i][0]<B[i-1][1]:
ans-=1
B[i][1]=B[i-1][1]
print(ans)
| 17 | 14 | 422 | 251 |
N, M = list(map(int, input().split()))
ab = []
for m in range(M):
[a, b] = [int(i) for i in input().split()]
ab.append([a, b])
ab.sort(key=lambda x: x[1])
count = []
count.append(ab[0][1] - 1)
for i in range(1, M):
if ab[i][0] <= count[-1] < ab[i][1]:
pass
elif ab[i][0] <= count[-1] and ab[i][1] - 1 == count[-1]:
count.remove(count[-1])
count.append(ab[i][1] - 1)
else:
count.append(ab[i][1] - 1)
print((len(count)))
|
n, m = list(map(int, input().split()))
B = []
for _ in range(m):
a, b = list(map(int, input().split()))
B.append([a - 1, b - 1])
B = sorted(B, key=lambda x: x[1])
ans = m
for i in range(1, m):
if B[i][0] < B[i - 1][1]:
ans -= 1
B[i][1] = B[i - 1][1]
print(ans)
| false | 17.647059 |
[
"-N, M = list(map(int, input().split()))",
"-ab = []",
"-for m in range(M):",
"- [a, b] = [int(i) for i in input().split()]",
"- ab.append([a, b])",
"-ab.sort(key=lambda x: x[1])",
"-count = []",
"-count.append(ab[0][1] - 1)",
"-for i in range(1, M):",
"- if ab[i][0] <= count[-1] < ab[i][1]:",
"- pass",
"- elif ab[i][0] <= count[-1] and ab[i][1] - 1 == count[-1]:",
"- count.remove(count[-1])",
"- count.append(ab[i][1] - 1)",
"- else:",
"- count.append(ab[i][1] - 1)",
"-print((len(count)))",
"+n, m = list(map(int, input().split()))",
"+B = []",
"+for _ in range(m):",
"+ a, b = list(map(int, input().split()))",
"+ B.append([a - 1, b - 1])",
"+B = sorted(B, key=lambda x: x[1])",
"+ans = m",
"+for i in range(1, m):",
"+ if B[i][0] < B[i - 1][1]:",
"+ ans -= 1",
"+ B[i][1] = B[i - 1][1]",
"+print(ans)"
] | false | 0.04299 | 0.042635 | 1.008332 |
[
"s682387351",
"s510042765"
] |
u402342597
|
p02657
|
python
|
s581015592
|
s564636404
| 23 | 21 | 9,152 | 9,108 |
Accepted
|
Accepted
| 8.7 |
a, b= (int(x) for x in input().split())
print((a*b))
|
import math
a,b = [float(x) for x in input().split()]
a = int(a)
b = int(b*100)
print((int(math.floor(a*b)//100)))
| 3 | 5 | 53 | 116 |
a, b = (int(x) for x in input().split())
print((a * b))
|
import math
a, b = [float(x) for x in input().split()]
a = int(a)
b = int(b * 100)
print((int(math.floor(a * b) // 100)))
| false | 40 |
[
"-a, b = (int(x) for x in input().split())",
"-print((a * b))",
"+import math",
"+",
"+a, b = [float(x) for x in input().split()]",
"+a = int(a)",
"+b = int(b * 100)",
"+print((int(math.floor(a * b) // 100)))"
] | false | 0.036905 | 0.039902 | 0.924893 |
[
"s581015592",
"s564636404"
] |
u436173409
|
p02693
|
python
|
s483199884
|
s778865511
| 296 | 24 | 27,452 | 9,092 |
Accepted
|
Accepted
| 91.89 |
k = int(eval(input()))
a, b = [int(e) for e in input().split()]
import numpy as np
ab = np.zeros((b-a)+1)
ab[:] = a
for i in range(b-a):
ab[i+1:] +=1
if (ab % k == 0).sum() > 0:
print('OK')
else:
print('NG')
|
k = int(eval(input()))
a, b = [int(e) for e in input().split()]
ans='NG'
for i in range(a,b+1):
if i%k == 0:
ans='OK'
break
else:
pass
print(ans)
| 16 | 10 | 233 | 180 |
k = int(eval(input()))
a, b = [int(e) for e in input().split()]
import numpy as np
ab = np.zeros((b - a) + 1)
ab[:] = a
for i in range(b - a):
ab[i + 1 :] += 1
if (ab % k == 0).sum() > 0:
print("OK")
else:
print("NG")
|
k = int(eval(input()))
a, b = [int(e) for e in input().split()]
ans = "NG"
for i in range(a, b + 1):
if i % k == 0:
ans = "OK"
break
else:
pass
print(ans)
| false | 37.5 |
[
"-import numpy as np",
"-",
"-ab = np.zeros((b - a) + 1)",
"-ab[:] = a",
"-for i in range(b - a):",
"- ab[i + 1 :] += 1",
"-if (ab % k == 0).sum() > 0:",
"- print(\"OK\")",
"-else:",
"- print(\"NG\")",
"+ans = \"NG\"",
"+for i in range(a, b + 1):",
"+ if i % k == 0:",
"+ ans = \"OK\"",
"+ break",
"+ else:",
"+ pass",
"+print(ans)"
] | false | 0.224713 | 0.036871 | 6.094508 |
[
"s483199884",
"s778865511"
] |
u754022296
|
p02756
|
python
|
s569291238
|
s148871592
| 964 | 475 | 90,904 | 14,560 |
Accepted
|
Accepted
| 50.73 |
from collections import deque
s = deque(list(input()))
q = int(input())
f = 0
for _ in range(q):
l = input()
if l == "1":
f ^= 1
else:
a, b, c = l.split()
if f ^ (b=="1"):
s.appendleft(c)
else:
s.append(c)
if f:
ans = list(s)[::-1]
else:
ans = list(s)
print(*ans, sep="")
|
from collections import deque
def main():
s = deque(list(input()))
q = int(input())
f = 0
for _ in range(q):
l = input()
if l == "1":
f ^= 1
else:
a, b, c = l.split()
if f ^ (b=="1"):
s.appendleft(c)
else:
s.append(c)
if f:
ans = list(s)[::-1]
else:
ans = list(s)
print(*ans, sep="")
if __name__ == "__main__":
main()
| 19 | 22 | 327 | 414 |
from collections import deque
s = deque(list(input()))
q = int(input())
f = 0
for _ in range(q):
l = input()
if l == "1":
f ^= 1
else:
a, b, c = l.split()
if f ^ (b == "1"):
s.appendleft(c)
else:
s.append(c)
if f:
ans = list(s)[::-1]
else:
ans = list(s)
print(*ans, sep="")
|
from collections import deque
def main():
s = deque(list(input()))
q = int(input())
f = 0
for _ in range(q):
l = input()
if l == "1":
f ^= 1
else:
a, b, c = l.split()
if f ^ (b == "1"):
s.appendleft(c)
else:
s.append(c)
if f:
ans = list(s)[::-1]
else:
ans = list(s)
print(*ans, sep="")
if __name__ == "__main__":
main()
| false | 13.636364 |
[
"-s = deque(list(input()))",
"-q = int(input())",
"-f = 0",
"-for _ in range(q):",
"- l = input()",
"- if l == \"1\":",
"- f ^= 1",
"+",
"+def main():",
"+ s = deque(list(input()))",
"+ q = int(input())",
"+ f = 0",
"+ for _ in range(q):",
"+ l = input()",
"+ if l == \"1\":",
"+ f ^= 1",
"+ else:",
"+ a, b, c = l.split()",
"+ if f ^ (b == \"1\"):",
"+ s.appendleft(c)",
"+ else:",
"+ s.append(c)",
"+ if f:",
"+ ans = list(s)[::-1]",
"- a, b, c = l.split()",
"- if f ^ (b == \"1\"):",
"- s.appendleft(c)",
"- else:",
"- s.append(c)",
"-if f:",
"- ans = list(s)[::-1]",
"-else:",
"- ans = list(s)",
"-print(*ans, sep=\"\")",
"+ ans = list(s)",
"+ print(*ans, sep=\"\")",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.059298 | 0.007477 | 7.930495 |
[
"s569291238",
"s148871592"
] |
u724428568
|
p02832
|
python
|
s957321602
|
s350878539
| 121 | 92 | 26,140 | 26,140 |
Accepted
|
Accepted
| 23.97 |
N = int(eval(input()))
l = list(map(int, input().split()))
if l == [i+1 for i in range(N)]: # 1, 2, 3, ...
print((0))
elif 1 not in l:
print((-1))
else:
detected = 0
target = 1
for i in l:
if i == target:
detected += 1
target += 1
print((N - detected))
|
N = int(eval(input()))
l = list(map(int, input().split()))
if 1 not in l:
print((-1))
else:
detected = 0
for i in l:
if i == detected+1:
detected += 1
print((N - detected))
| 15 | 11 | 285 | 193 |
N = int(eval(input()))
l = list(map(int, input().split()))
if l == [i + 1 for i in range(N)]: # 1, 2, 3, ...
print((0))
elif 1 not in l:
print((-1))
else:
detected = 0
target = 1
for i in l:
if i == target:
detected += 1
target += 1
print((N - detected))
|
N = int(eval(input()))
l = list(map(int, input().split()))
if 1 not in l:
print((-1))
else:
detected = 0
for i in l:
if i == detected + 1:
detected += 1
print((N - detected))
| false | 26.666667 |
[
"-if l == [i + 1 for i in range(N)]: # 1, 2, 3, ...",
"- print((0))",
"-elif 1 not in l:",
"+if 1 not in l:",
"- target = 1",
"- if i == target:",
"+ if i == detected + 1:",
"- target += 1"
] | false | 0.041984 | 0.040337 | 1.040833 |
[
"s957321602",
"s350878539"
] |
u193264896
|
p02813
|
python
|
s218948531
|
s675053035
| 44 | 32 | 5,244 | 9,024 |
Accepted
|
Accepted
| 27.27 |
from collections import deque
from collections import Counter
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
#pypyではscipy, numpyは使えない
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
#from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
#import numpy as np
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
from datetime import datetime as dt
def main():
n = int(eval(input()))
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
l = [i for i in range(1,n+1)]
for i, junretsu in enumerate(permutations(l, n)):
if junretsu==p:
a = i
if junretsu==q:
b=i
print((abs(b-a)))
if __name__ == '__main__':
main()
|
import sys
read = sys.stdin.read
readline = sys.stdin.buffer.readline
from itertools import permutations
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7
def main():
N = int(readline())
P = tuple(map(int, readline().split()))
Q = tuple(map(int, readline().split()))
for i, A in enumerate(permutations(list(range(1,N+1)))):
if A == P:
p = i
if A == Q:
q = i
print((abs(p-q)))
if __name__ == '__main__':
main()
| 35 | 28 | 1,100 | 520 |
from collections import deque
from collections import Counter
from itertools import product, permutations, combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
# pypyではscipy, numpyは使えない
# from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
# from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
# import numpy as np
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi, factorial
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float("inf")
from datetime import datetime as dt
def main():
n = int(eval(input()))
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
l = [i for i in range(1, n + 1)]
for i, junretsu in enumerate(permutations(l, n)):
if junretsu == p:
a = i
if junretsu == q:
b = i
print((abs(b - a)))
if __name__ == "__main__":
main()
|
import sys
read = sys.stdin.read
readline = sys.stdin.buffer.readline
from itertools import permutations
sys.setrecursionlimit(10**8)
INF = float("inf")
MOD = 10**9 + 7
def main():
N = int(readline())
P = tuple(map(int, readline().split()))
Q = tuple(map(int, readline().split()))
for i, A in enumerate(permutations(list(range(1, N + 1)))):
if A == P:
p = i
if A == Q:
q = i
print((abs(p - q)))
if __name__ == "__main__":
main()
| false | 20 |
[
"-from collections import deque",
"-from collections import Counter",
"-from itertools import product, permutations, combinations",
"-from operator import itemgetter",
"-from heapq import heappop, heappush",
"-from bisect import bisect_left, bisect_right, bisect",
"-",
"-# pypyではscipy, numpyは使えない",
"-# from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree",
"-# from scipy.sparse import csr_matrix, coo_matrix, lil_matrix",
"-# import numpy as np",
"-from fractions import gcd",
"-from math import ceil, floor, sqrt, cos, sin, pi, factorial",
"-read = sys.stdin.buffer.read",
"+read = sys.stdin.read",
"-readlines = sys.stdin.buffer.readlines",
"+from itertools import permutations",
"+",
"-from datetime import datetime as dt",
"+MOD = 10**9 + 7",
"- n = int(eval(input()))",
"- p = tuple(map(int, input().split()))",
"- q = tuple(map(int, input().split()))",
"- l = [i for i in range(1, n + 1)]",
"- for i, junretsu in enumerate(permutations(l, n)):",
"- if junretsu == p:",
"- a = i",
"- if junretsu == q:",
"- b = i",
"- print((abs(b - a)))",
"+ N = int(readline())",
"+ P = tuple(map(int, readline().split()))",
"+ Q = tuple(map(int, readline().split()))",
"+ for i, A in enumerate(permutations(list(range(1, N + 1)))):",
"+ if A == P:",
"+ p = i",
"+ if A == Q:",
"+ q = i",
"+ print((abs(p - q)))"
] | false | 0.061304 | 0.041603 | 1.473528 |
[
"s218948531",
"s675053035"
] |
u600402037
|
p03274
|
python
|
s183987944
|
s258588037
| 164 | 93 | 14,564 | 14,480 |
Accepted
|
Accepted
| 43.29 |
# coding: utf-8
import sys
from bisect import bisect_left, bisect_right
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N, K = lr()
X = lr()
if 0 in X:
K -= 1
i = bisect_left(X, 0)
ne = X[:i]
i = bisect_right(X, 0)
po = X[i:]
INF = 10 ** 10
neg = [INF] * (K+1) # 左からK本選ぶ場合、K-1本選ぶ場合・・・0本選ぶ場合
neg[-1] = 0
pos = [INF] * (K+1)
pos[0] = 0
for j in range(len(ne)):
if -j-2 < -K-1:
break
neg[-j-2] = ne[-j-1]
for j in range(len(po)):
if j+1 > K:
break
pos[j+1] = po[j]
answer = INF
for j in range(K+1):
x = abs(neg[j]); y = abs(pos[j])
mi = min(x, y)
ma = max(x, y)
temp = mi * 2 + ma
if temp < answer:
answer = temp
print(answer)
# 52
|
# coding: utf-8
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N, K = lr()
X = lr()
answer = []
for i in range(N-K+1):
l = X[i]; r = X[i+K-1]
a = abs(l) + abs(r-l)
b = abs(r) + abs(l-r)
answer.append(min(a, b))
print((min(answer)))
# 03
| 42 | 18 | 799 | 342 |
# coding: utf-8
import sys
from bisect import bisect_left, bisect_right
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N, K = lr()
X = lr()
if 0 in X:
K -= 1
i = bisect_left(X, 0)
ne = X[:i]
i = bisect_right(X, 0)
po = X[i:]
INF = 10**10
neg = [INF] * (K + 1) # 左からK本選ぶ場合、K-1本選ぶ場合・・・0本選ぶ場合
neg[-1] = 0
pos = [INF] * (K + 1)
pos[0] = 0
for j in range(len(ne)):
if -j - 2 < -K - 1:
break
neg[-j - 2] = ne[-j - 1]
for j in range(len(po)):
if j + 1 > K:
break
pos[j + 1] = po[j]
answer = INF
for j in range(K + 1):
x = abs(neg[j])
y = abs(pos[j])
mi = min(x, y)
ma = max(x, y)
temp = mi * 2 + ma
if temp < answer:
answer = temp
print(answer)
# 52
|
# coding: utf-8
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N, K = lr()
X = lr()
answer = []
for i in range(N - K + 1):
l = X[i]
r = X[i + K - 1]
a = abs(l) + abs(r - l)
b = abs(r) + abs(l - r)
answer.append(min(a, b))
print((min(answer)))
# 03
| false | 57.142857 |
[
"-from bisect import bisect_left, bisect_right",
"-if 0 in X:",
"- K -= 1",
"-i = bisect_left(X, 0)",
"-ne = X[:i]",
"-i = bisect_right(X, 0)",
"-po = X[i:]",
"-INF = 10**10",
"-neg = [INF] * (K + 1) # 左からK本選ぶ場合、K-1本選ぶ場合・・・0本選ぶ場合",
"-neg[-1] = 0",
"-pos = [INF] * (K + 1)",
"-pos[0] = 0",
"-for j in range(len(ne)):",
"- if -j - 2 < -K - 1:",
"- break",
"- neg[-j - 2] = ne[-j - 1]",
"-for j in range(len(po)):",
"- if j + 1 > K:",
"- break",
"- pos[j + 1] = po[j]",
"-answer = INF",
"-for j in range(K + 1):",
"- x = abs(neg[j])",
"- y = abs(pos[j])",
"- mi = min(x, y)",
"- ma = max(x, y)",
"- temp = mi * 2 + ma",
"- if temp < answer:",
"- answer = temp",
"-print(answer)",
"-# 52",
"+answer = []",
"+for i in range(N - K + 1):",
"+ l = X[i]",
"+ r = X[i + K - 1]",
"+ a = abs(l) + abs(r - l)",
"+ b = abs(r) + abs(l - r)",
"+ answer.append(min(a, b))",
"+print((min(answer)))",
"+# 03"
] | false | 0.092125 | 0.041614 | 2.21377 |
[
"s183987944",
"s258588037"
] |
u419686324
|
p03241
|
python
|
s004994068
|
s328325116
| 361 | 31 | 3,572 | 4,188 |
Accepted
|
Accepted
| 91.41 |
N, M = list(map(int, input().split()))
import math
class PrimeUtils:
@staticmethod
def primes_sieve(n):
sieve = [True] * (n + 1)
for i in range(2, n + 1):
if sieve[i]:
for j in range(i + i, n + 1, i):
sieve[j] = False
return [i for i, x in enumerate(sieve[2:], 2) if x]
def f():
for p in PrimeUtils.primes_sieve(math.ceil(math.sqrt(M))):
if M % p == 0:
for x in range(N, (M//2) + 1):
if M % x == 0:
return M // x
else:
return 1
return 1
print((f()))
|
import math, collections, itertools, functools, operator
class PrimeUtils:
@staticmethod
def primes_sieve(n):
sieve = [True] * (n + 1)
for i in range(2, n + 1):
if sieve[i]:
for j in range(i + i, n + 1, i):
sieve[j] = False
return [i for i, x in enumerate(sieve[2:], 2) if x]
@staticmethod
# Prime Factor Decomposition
def pfd(n):
rn = math.ceil(math.sqrt(n))
primes = PrimeUtils.primes_sieve(rn)
factors = []
cur = n
for p in primes:
while True:
div, rem = divmod(cur, p)
if rem == 0:
factors.append(p)
cur = div
else:
break
if cur != 1 or not factors:
factors.append(cur)
return factors
@staticmethod
# Returns a list of factors
def factors(n):
pf = PrimeUtils.pfd(n)
pfc = collections.Counter(pf)
ppv = [[pow(p, i) for i in range(n+1)] for p,n in list(pfc.items())]
return [functools.reduce(operator.imul, x) for x in itertools.product(*ppv)]
N, M = list(map(int, input().split()))
for factor in sorted(PrimeUtils.factors(M)):
if N <= factor:
print((M // factor))
break
else:
print((1))
| 23 | 44 | 637 | 1,366 |
N, M = list(map(int, input().split()))
import math
class PrimeUtils:
@staticmethod
def primes_sieve(n):
sieve = [True] * (n + 1)
for i in range(2, n + 1):
if sieve[i]:
for j in range(i + i, n + 1, i):
sieve[j] = False
return [i for i, x in enumerate(sieve[2:], 2) if x]
def f():
for p in PrimeUtils.primes_sieve(math.ceil(math.sqrt(M))):
if M % p == 0:
for x in range(N, (M // 2) + 1):
if M % x == 0:
return M // x
else:
return 1
return 1
print((f()))
|
import math, collections, itertools, functools, operator
class PrimeUtils:
@staticmethod
def primes_sieve(n):
sieve = [True] * (n + 1)
for i in range(2, n + 1):
if sieve[i]:
for j in range(i + i, n + 1, i):
sieve[j] = False
return [i for i, x in enumerate(sieve[2:], 2) if x]
@staticmethod
# Prime Factor Decomposition
def pfd(n):
rn = math.ceil(math.sqrt(n))
primes = PrimeUtils.primes_sieve(rn)
factors = []
cur = n
for p in primes:
while True:
div, rem = divmod(cur, p)
if rem == 0:
factors.append(p)
cur = div
else:
break
if cur != 1 or not factors:
factors.append(cur)
return factors
@staticmethod
# Returns a list of factors
def factors(n):
pf = PrimeUtils.pfd(n)
pfc = collections.Counter(pf)
ppv = [[pow(p, i) for i in range(n + 1)] for p, n in list(pfc.items())]
return [functools.reduce(operator.imul, x) for x in itertools.product(*ppv)]
N, M = list(map(int, input().split()))
for factor in sorted(PrimeUtils.factors(M)):
if N <= factor:
print((M // factor))
break
else:
print((1))
| false | 47.727273 |
[
"-N, M = list(map(int, input().split()))",
"-import math",
"+import math, collections, itertools, functools, operator",
"+ @staticmethod",
"+ # Prime Factor Decomposition",
"+ def pfd(n):",
"+ rn = math.ceil(math.sqrt(n))",
"+ primes = PrimeUtils.primes_sieve(rn)",
"+ factors = []",
"+ cur = n",
"+ for p in primes:",
"+ while True:",
"+ div, rem = divmod(cur, p)",
"+ if rem == 0:",
"+ factors.append(p)",
"+ cur = div",
"+ else:",
"+ break",
"+ if cur != 1 or not factors:",
"+ factors.append(cur)",
"+ return factors",
"-def f():",
"- for p in PrimeUtils.primes_sieve(math.ceil(math.sqrt(M))):",
"- if M % p == 0:",
"- for x in range(N, (M // 2) + 1):",
"- if M % x == 0:",
"- return M // x",
"- else:",
"- return 1",
"- return 1",
"+ @staticmethod",
"+ # Returns a list of factors",
"+ def factors(n):",
"+ pf = PrimeUtils.pfd(n)",
"+ pfc = collections.Counter(pf)",
"+ ppv = [[pow(p, i) for i in range(n + 1)] for p, n in list(pfc.items())]",
"+ return [functools.reduce(operator.imul, x) for x in itertools.product(*ppv)]",
"-print((f()))",
"+N, M = list(map(int, input().split()))",
"+for factor in sorted(PrimeUtils.factors(M)):",
"+ if N <= factor:",
"+ print((M // factor))",
"+ break",
"+else:",
"+ print((1))"
] | false | 0.147275 | 0.042412 | 3.472522 |
[
"s004994068",
"s328325116"
] |
u788703383
|
p02684
|
python
|
s960540746
|
s362716661
| 180 | 137 | 32,400 | 31,064 |
Accepted
|
Accepted
| 23.89 |
n,k =list(map(int,input().split()))
a=list(map(int,input().split()))
a = [1] + a
def next(i):
return a[i]
z = [0] * (n+1)
place = 1
T = 0
interval = 0
if k < n:
for i in range(k):
place = next(place)
print(place);exit()
place = 0
k += 1
for i in range(n):
place = next(place)
if z[place] != 0:
interval = T - z[place] + 1
break
z[1] = 1
T += 1
z[place] = T
m = (k-z[place])%interval
for i in range(m):
place = next(place)
print(place)
|
import sys
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9 + 7
input = sys.stdin.readline
def inp():
return int(eval(input()))
def inpl():
return list(map(int,input().split()))
def inpm():
return list(map(int,input().split()))
n,k =list(map(int,input().split()))
a=[1] + inpl()
b=[-1] * (n+1); b[1] = 0
place = 1
turn = 0
while b[a[place]] == -1:
place = a[place]
turn += 1
b[place] = turn
r = (k - turn) % (b[place] - b[a[place]] + 1)
if k < turn:
print((b.index(k)))
else:
for _ in range(r):
place = a[place]
print(place)
| 30 | 33 | 523 | 598 |
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
a = [1] + a
def next(i):
return a[i]
z = [0] * (n + 1)
place = 1
T = 0
interval = 0
if k < n:
for i in range(k):
place = next(place)
print(place)
exit()
place = 0
k += 1
for i in range(n):
place = next(place)
if z[place] != 0:
interval = T - z[place] + 1
break
z[1] = 1
T += 1
z[place] = T
m = (k - z[place]) % interval
for i in range(m):
place = next(place)
print(place)
|
import sys
sys.setrecursionlimit(10**8)
INF = float("inf")
mod = 10**9 + 7
input = sys.stdin.readline
def inp():
return int(eval(input()))
def inpl():
return list(map(int, input().split()))
def inpm():
return list(map(int, input().split()))
n, k = list(map(int, input().split()))
a = [1] + inpl()
b = [-1] * (n + 1)
b[1] = 0
place = 1
turn = 0
while b[a[place]] == -1:
place = a[place]
turn += 1
b[place] = turn
r = (k - turn) % (b[place] - b[a[place]] + 1)
if k < turn:
print((b.index(k)))
else:
for _ in range(r):
place = a[place]
print(place)
| false | 9.090909 |
[
"-n, k = list(map(int, input().split()))",
"-a = list(map(int, input().split()))",
"-a = [1] + a",
"+import sys",
"+",
"+sys.setrecursionlimit(10**8)",
"+INF = float(\"inf\")",
"+mod = 10**9 + 7",
"+input = sys.stdin.readline",
"-def next(i):",
"- return a[i]",
"+def inp():",
"+ return int(eval(input()))",
"-z = [0] * (n + 1)",
"+def inpl():",
"+ return list(map(int, input().split()))",
"+",
"+",
"+def inpm():",
"+ return list(map(int, input().split()))",
"+",
"+",
"+n, k = list(map(int, input().split()))",
"+a = [1] + inpl()",
"+b = [-1] * (n + 1)",
"+b[1] = 0",
"-T = 0",
"-interval = 0",
"-if k < n:",
"- for i in range(k):",
"- place = next(place)",
"+turn = 0",
"+while b[a[place]] == -1:",
"+ place = a[place]",
"+ turn += 1",
"+ b[place] = turn",
"+r = (k - turn) % (b[place] - b[a[place]] + 1)",
"+if k < turn:",
"+ print((b.index(k)))",
"+else:",
"+ for _ in range(r):",
"+ place = a[place]",
"- exit()",
"-place = 0",
"-k += 1",
"-for i in range(n):",
"- place = next(place)",
"- if z[place] != 0:",
"- interval = T - z[place] + 1",
"- break",
"- z[1] = 1",
"- T += 1",
"- z[place] = T",
"-m = (k - z[place]) % interval",
"-for i in range(m):",
"- place = next(place)",
"-print(place)"
] | false | 0.05755 | 0.036371 | 1.582309 |
[
"s960540746",
"s362716661"
] |
u969190727
|
p03682
|
python
|
s962069143
|
s211683590
| 1,863 | 879 | 122,800 | 147,396 |
Accepted
|
Accepted
| 52.82 |
import sys
input = sys.stdin.readline
n=int(eval(input()))
Edge=[[] for i in range(n)]
XY=[]
append=XY.append
for i in range(n):
x,y=list(map(int,input().split()))
append([i,x,y])
XY.sort(key=lambda x:x[1])
for i in range(1,n):
n1,x1,y1=XY[i-1][0],XY[i-1][1],XY[i-1][2]
n2,x2,y2=XY[i][0],XY[i][1],XY[i][2]
Edge[n1].append([min(abs(x2-x1),abs(y2-y1)),n2])
Edge[n2].append([min(abs(x2-x1),abs(y2-y1)),n1])
XY.sort(key=lambda x:x[2])
for i in range(1,n):
n1,x1,y1=XY[i-1][0],XY[i-1][1],XY[i-1][2]
n2,x2,y2=XY[i][0],XY[i][1],XY[i][2]
Edge[n1].append([min(abs(x2-x1),abs(y2-y1)),n2])
Edge[n2].append([min(abs(x2-x1),abs(y2-y1)),n1])
import heapq
def prim_heap():
used=[True]*n
Edgelist=[]
for e in Edge[0]:
heapq.heappush(Edgelist,e)
used[0]=False
res=0
while len(Edgelist)!=0:
minedge=heapq.heappop(Edgelist)
if not used[minedge[1]]:
continue
v=minedge[1]
used[v]=False
for e in Edge[v]:
if used[e[1]]:
heapq.heappush(Edgelist,e)
res+=minedge[0]
return res
print((prim_heap()))
|
import sys
sys.setrecursionlimit(1000000)
input = sys.stdin.readline
def MST(n, E):
def par(m):
if UF[m] == m:
return m
ret = par(UF[m])
UF[m] = ret
return ret
UF = [i for i in range(n)]
E = sorted(E, key=lambda x: x[2])
ans = 0
for i, j, d in E:
if par(i) != par(j):
ans += d
UF[par(i)] = par(j)
return ans
N = int(eval(input()))
X = []
append=X.append
for i in range(N):
x, y = list(map(int, input().split()))
append((i, x, y))
F = []
Y = sorted(X, key = lambda x: x[1])
for i in range(len(Y)-1):
F.append((Y[i][0], Y[i+1][0], abs(Y[i+1][1]-Y[i][1])))
Y = sorted(X, key = lambda x: x[2])
for i in range(len(Y)-1):
F.append((Y[i][0], Y[i+1][0], abs(Y[i+1][2]-Y[i][2])))
print((MST(N, F)))
| 41 | 39 | 1,082 | 841 |
import sys
input = sys.stdin.readline
n = int(eval(input()))
Edge = [[] for i in range(n)]
XY = []
append = XY.append
for i in range(n):
x, y = list(map(int, input().split()))
append([i, x, y])
XY.sort(key=lambda x: x[1])
for i in range(1, n):
n1, x1, y1 = XY[i - 1][0], XY[i - 1][1], XY[i - 1][2]
n2, x2, y2 = XY[i][0], XY[i][1], XY[i][2]
Edge[n1].append([min(abs(x2 - x1), abs(y2 - y1)), n2])
Edge[n2].append([min(abs(x2 - x1), abs(y2 - y1)), n1])
XY.sort(key=lambda x: x[2])
for i in range(1, n):
n1, x1, y1 = XY[i - 1][0], XY[i - 1][1], XY[i - 1][2]
n2, x2, y2 = XY[i][0], XY[i][1], XY[i][2]
Edge[n1].append([min(abs(x2 - x1), abs(y2 - y1)), n2])
Edge[n2].append([min(abs(x2 - x1), abs(y2 - y1)), n1])
import heapq
def prim_heap():
used = [True] * n
Edgelist = []
for e in Edge[0]:
heapq.heappush(Edgelist, e)
used[0] = False
res = 0
while len(Edgelist) != 0:
minedge = heapq.heappop(Edgelist)
if not used[minedge[1]]:
continue
v = minedge[1]
used[v] = False
for e in Edge[v]:
if used[e[1]]:
heapq.heappush(Edgelist, e)
res += minedge[0]
return res
print((prim_heap()))
|
import sys
sys.setrecursionlimit(1000000)
input = sys.stdin.readline
def MST(n, E):
def par(m):
if UF[m] == m:
return m
ret = par(UF[m])
UF[m] = ret
return ret
UF = [i for i in range(n)]
E = sorted(E, key=lambda x: x[2])
ans = 0
for i, j, d in E:
if par(i) != par(j):
ans += d
UF[par(i)] = par(j)
return ans
N = int(eval(input()))
X = []
append = X.append
for i in range(N):
x, y = list(map(int, input().split()))
append((i, x, y))
F = []
Y = sorted(X, key=lambda x: x[1])
for i in range(len(Y) - 1):
F.append((Y[i][0], Y[i + 1][0], abs(Y[i + 1][1] - Y[i][1])))
Y = sorted(X, key=lambda x: x[2])
for i in range(len(Y) - 1):
F.append((Y[i][0], Y[i + 1][0], abs(Y[i + 1][2] - Y[i][2])))
print((MST(N, F)))
| false | 4.878049 |
[
"+sys.setrecursionlimit(1000000)",
"-n = int(eval(input()))",
"-Edge = [[] for i in range(n)]",
"-XY = []",
"-append = XY.append",
"-for i in range(n):",
"- x, y = list(map(int, input().split()))",
"- append([i, x, y])",
"-XY.sort(key=lambda x: x[1])",
"-for i in range(1, n):",
"- n1, x1, y1 = XY[i - 1][0], XY[i - 1][1], XY[i - 1][2]",
"- n2, x2, y2 = XY[i][0], XY[i][1], XY[i][2]",
"- Edge[n1].append([min(abs(x2 - x1), abs(y2 - y1)), n2])",
"- Edge[n2].append([min(abs(x2 - x1), abs(y2 - y1)), n1])",
"-XY.sort(key=lambda x: x[2])",
"-for i in range(1, n):",
"- n1, x1, y1 = XY[i - 1][0], XY[i - 1][1], XY[i - 1][2]",
"- n2, x2, y2 = XY[i][0], XY[i][1], XY[i][2]",
"- Edge[n1].append([min(abs(x2 - x1), abs(y2 - y1)), n2])",
"- Edge[n2].append([min(abs(x2 - x1), abs(y2 - y1)), n1])",
"-import heapq",
"-def prim_heap():",
"- used = [True] * n",
"- Edgelist = []",
"- for e in Edge[0]:",
"- heapq.heappush(Edgelist, e)",
"- used[0] = False",
"- res = 0",
"- while len(Edgelist) != 0:",
"- minedge = heapq.heappop(Edgelist)",
"- if not used[minedge[1]]:",
"- continue",
"- v = minedge[1]",
"- used[v] = False",
"- for e in Edge[v]:",
"- if used[e[1]]:",
"- heapq.heappush(Edgelist, e)",
"- res += minedge[0]",
"- return res",
"+def MST(n, E):",
"+ def par(m):",
"+ if UF[m] == m:",
"+ return m",
"+ ret = par(UF[m])",
"+ UF[m] = ret",
"+ return ret",
"+",
"+ UF = [i for i in range(n)]",
"+ E = sorted(E, key=lambda x: x[2])",
"+ ans = 0",
"+ for i, j, d in E:",
"+ if par(i) != par(j):",
"+ ans += d",
"+ UF[par(i)] = par(j)",
"+ return ans",
"-print((prim_heap()))",
"+N = int(eval(input()))",
"+X = []",
"+append = X.append",
"+for i in range(N):",
"+ x, y = list(map(int, input().split()))",
"+ append((i, x, y))",
"+F = []",
"+Y = sorted(X, key=lambda x: x[1])",
"+for i in range(len(Y) - 1):",
"+ F.append((Y[i][0], Y[i + 1][0], abs(Y[i + 1][1] - Y[i][1])))",
"+Y = sorted(X, key=lambda x: x[2])",
"+for i in range(len(Y) - 1):",
"+ F.append((Y[i][0], Y[i + 1][0], abs(Y[i + 1][2] - Y[i][2])))",
"+print((MST(N, F)))"
] | false | 0.042101 | 0.039973 | 1.053229 |
[
"s962069143",
"s211683590"
] |
u204842730
|
p02814
|
python
|
s069002689
|
s860706869
| 705 | 62 | 16,280 | 16,280 |
Accepted
|
Accepted
| 91.21 |
import fractions
import math
n,m = list(map(int,input().split()))
a = list(map(int, input().split()))
s = set(a)
c = set()
l = 1
k = (a[0] // 2) % 2
for i in a:
l = l * i // fractions.gcd(l,i)
if l // 2 > m:
ans = 0
break
count = 0
while True:
if (i>>count) % 2 == 0:
count += 1
else:
c.add(count)
break
if len(c) > 1:
ans = 0
break
else:
ans = (m + l // 2) // l
print(ans)
|
import fractions
import math
n,m = list(map(int,input().split()))
a = list(map(int, input().split()))
a = set(a)
c = set()
l = 1
for i in a:
l = l * i // fractions.gcd(l,i)
if l // 2 > m:
ans = 0
break
count = 0
while True:
if (i>>count) % 2 == 0:
count += 1
else:
c.add(count)
break
if len(c) > 1:
ans = 0
break
else:
ans = (m + l // 2) // l
print(ans)
| 27 | 26 | 502 | 481 |
import fractions
import math
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
s = set(a)
c = set()
l = 1
k = (a[0] // 2) % 2
for i in a:
l = l * i // fractions.gcd(l, i)
if l // 2 > m:
ans = 0
break
count = 0
while True:
if (i >> count) % 2 == 0:
count += 1
else:
c.add(count)
break
if len(c) > 1:
ans = 0
break
else:
ans = (m + l // 2) // l
print(ans)
|
import fractions
import math
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
a = set(a)
c = set()
l = 1
for i in a:
l = l * i // fractions.gcd(l, i)
if l // 2 > m:
ans = 0
break
count = 0
while True:
if (i >> count) % 2 == 0:
count += 1
else:
c.add(count)
break
if len(c) > 1:
ans = 0
break
else:
ans = (m + l // 2) // l
print(ans)
| false | 3.703704 |
[
"-s = set(a)",
"+a = set(a)",
"-k = (a[0] // 2) % 2"
] | false | 0.099542 | 0.043621 | 2.281962 |
[
"s069002689",
"s860706869"
] |
u633068244
|
p00239
|
python
|
s646540569
|
s124359545
| 140 | 110 | 4,516 | 4,488 |
Accepted
|
Accepted
| 21.43 |
while 1:
n=eval(input())
if n==0:break
s=[list(map(int,input().split())) for i in range(n)]
for i in range(n):
s[i].append(4*s[i][1]+9*s[i][2]+4*s[i][3])
r=list(map(int,input().split()))
flag=0
for i in s:
if i[1]<=r[0] and i[2]<=r[1] and i[3]<=r[2] and i[4]<=r[3]:
print(i[0])
flag=1
if flag==0:print("NA")
|
while 1:
n=eval(input())
if n==0:break
s=[list(map(int,input().split())) for i in range(n)]
r=list(map(int,input().split()))
flag=0
for i in s:
if i[1]<=r[0] and i[2]<=r[1] and i[3]<=r[2] and 4*(i[1]+i[3])+9*i[2]<=r[3]:
print(i[0])
flag=1
if flag==0:print("NA")
| 13 | 11 | 325 | 274 |
while 1:
n = eval(input())
if n == 0:
break
s = [list(map(int, input().split())) for i in range(n)]
for i in range(n):
s[i].append(4 * s[i][1] + 9 * s[i][2] + 4 * s[i][3])
r = list(map(int, input().split()))
flag = 0
for i in s:
if i[1] <= r[0] and i[2] <= r[1] and i[3] <= r[2] and i[4] <= r[3]:
print(i[0])
flag = 1
if flag == 0:
print("NA")
|
while 1:
n = eval(input())
if n == 0:
break
s = [list(map(int, input().split())) for i in range(n)]
r = list(map(int, input().split()))
flag = 0
for i in s:
if (
i[1] <= r[0]
and i[2] <= r[1]
and i[3] <= r[2]
and 4 * (i[1] + i[3]) + 9 * i[2] <= r[3]
):
print(i[0])
flag = 1
if flag == 0:
print("NA")
| false | 15.384615 |
[
"- for i in range(n):",
"- s[i].append(4 * s[i][1] + 9 * s[i][2] + 4 * s[i][3])",
"- if i[1] <= r[0] and i[2] <= r[1] and i[3] <= r[2] and i[4] <= r[3]:",
"+ if (",
"+ i[1] <= r[0]",
"+ and i[2] <= r[1]",
"+ and i[3] <= r[2]",
"+ and 4 * (i[1] + i[3]) + 9 * i[2] <= r[3]",
"+ ):"
] | false | 0.04206 | 0.041405 | 1.015805 |
[
"s646540569",
"s124359545"
] |
u612721349
|
p03493
|
python
|
s044527154
|
s360009735
| 164 | 17 | 38,256 | 2,940 |
Accepted
|
Accepted
| 89.63 |
print((input().count("1")))
|
s = eval(input())
print((s.count('1')))
| 1 | 2 | 25 | 32 |
print((input().count("1")))
|
s = eval(input())
print((s.count("1")))
| false | 50 |
[
"-print((input().count(\"1\")))",
"+s = eval(input())",
"+print((s.count(\"1\")))"
] | false | 0.19963 | 0.040231 | 4.962112 |
[
"s044527154",
"s360009735"
] |
u609061751
|
p03319
|
python
|
s868854092
|
s357959500
| 211 | 47 | 52,508 | 14,324 |
Accepted
|
Accepted
| 77.73 |
import sys
input = sys.stdin.readline
n, k = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
idx = a.index(1)
left = idx
right = n - (idx + 1)
ans = 10 ** 10
for i in range(k):
cnt = 1
left_ = left - i
right_ = right - (k - 1 - i)
cnt += left_//(k - 1) + right_//(k - 1) + int(not left_ % (k - 1) == 0) + int(not right_ % (k - 1) == 0)
ans = min(ans, cnt)
print(ans)
|
import sys
input = lambda: sys.stdin.readline().rstrip()
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
for i in range(n):
if a[i] == 1:
break
left = len(a[:i])
right = len(a[i + 1:])
ans = left // (k - 1) + right//(k - 1) + (left%(k-1) + right%(k-1))//(k-1) + int((left%(k-1) + right%(k-1))%(k - 1) != 0)
print(ans)
| 21 | 14 | 437 | 368 |
import sys
input = sys.stdin.readline
n, k = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
idx = a.index(1)
left = idx
right = n - (idx + 1)
ans = 10**10
for i in range(k):
cnt = 1
left_ = left - i
right_ = right - (k - 1 - i)
cnt += (
left_ // (k - 1)
+ right_ // (k - 1)
+ int(not left_ % (k - 1) == 0)
+ int(not right_ % (k - 1) == 0)
)
ans = min(ans, cnt)
print(ans)
|
import sys
input = lambda: sys.stdin.readline().rstrip()
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
for i in range(n):
if a[i] == 1:
break
left = len(a[:i])
right = len(a[i + 1 :])
ans = (
left // (k - 1)
+ right // (k - 1)
+ (left % (k - 1) + right % (k - 1)) // (k - 1)
+ int((left % (k - 1) + right % (k - 1)) % (k - 1) != 0)
)
print(ans)
| false | 33.333333 |
[
"-input = sys.stdin.readline",
"-n, k = [int(x) for x in input().split()]",
"-a = [int(x) for x in input().split()]",
"-idx = a.index(1)",
"-left = idx",
"-right = n - (idx + 1)",
"-ans = 10**10",
"-for i in range(k):",
"- cnt = 1",
"- left_ = left - i",
"- right_ = right - (k - 1 - i)",
"- cnt += (",
"- left_ // (k - 1)",
"- + right_ // (k - 1)",
"- + int(not left_ % (k - 1) == 0)",
"- + int(not right_ % (k - 1) == 0)",
"- )",
"- ans = min(ans, cnt)",
"+input = lambda: sys.stdin.readline().rstrip()",
"+n, k = list(map(int, input().split()))",
"+a = list(map(int, input().split()))",
"+for i in range(n):",
"+ if a[i] == 1:",
"+ break",
"+left = len(a[:i])",
"+right = len(a[i + 1 :])",
"+ans = (",
"+ left // (k - 1)",
"+ + right // (k - 1)",
"+ + (left % (k - 1) + right % (k - 1)) // (k - 1)",
"+ + int((left % (k - 1) + right % (k - 1)) % (k - 1) != 0)",
"+)"
] | false | 0.061462 | 0.081213 | 0.756798 |
[
"s868854092",
"s357959500"
] |
u076917070
|
p03294
|
python
|
s896482042
|
s685835164
| 176 | 18 | 5,344 | 3,316 |
Accepted
|
Accepted
| 89.77 |
import sys
input=sys.stdin.readline
import fractions
def lcm(x, y):
return (x * y) // fractions.gcd(x, y)
n = int(eval(input()))
a = list(map(int, input().split()))
m = a[0]
for i in a:
m = lcm(m, i)
x = 0
for i in a:
x += (m-1)%i
print(x)
|
import sys
input=sys.stdin.readline
int(eval(input()))
a = list(map(int, input().split()))
x = 0
for i in a:
x += i-1
print(x)
| 19 | 10 | 268 | 136 |
import sys
input = sys.stdin.readline
import fractions
def lcm(x, y):
return (x * y) // fractions.gcd(x, y)
n = int(eval(input()))
a = list(map(int, input().split()))
m = a[0]
for i in a:
m = lcm(m, i)
x = 0
for i in a:
x += (m - 1) % i
print(x)
|
import sys
input = sys.stdin.readline
int(eval(input()))
a = list(map(int, input().split()))
x = 0
for i in a:
x += i - 1
print(x)
| false | 47.368421 |
[
"-import fractions",
"-",
"-",
"-def lcm(x, y):",
"- return (x * y) // fractions.gcd(x, y)",
"-",
"-",
"-n = int(eval(input()))",
"+int(eval(input()))",
"-m = a[0]",
"-for i in a:",
"- m = lcm(m, i)",
"- x += (m - 1) % i",
"+ x += i - 1"
] | false | 0.050992 | 0.038831 | 1.313161 |
[
"s896482042",
"s685835164"
] |
u533039576
|
p02763
|
python
|
s863281432
|
s908102245
| 1,048 | 657 | 250,076 | 80,224 |
Accepted
|
Accepted
| 37.31 |
class BIT1():
"""
Binary Indexed Tree (1-indexed)
"""
def __init__(self, n):
self.n = n
self.bit = [0] * (self.n + 1)
self.data = [0] * (self.n + 1)
def add(self, idx, x):
# add x to idx-th element
# idx: 1-indexed
self.data[idx] += x
while idx <= self.n:
self.bit[idx] += x
idx += (idx & (-idx))
def sum(self, idx):
# get sum of [1, idx]
# idx: 1-indexed
s = 0
while idx:
s += self.bit[idx]
idx -= (idx & (-idx))
return s
n = int(eval(input()))
s = [ord(si) - ord('a') for si in list(eval(input()))]
bit_list = [BIT1(n + 1) for _ in range(26)]
for i in range(n):
bit_list[s[i]].add(i + 1, +1)
q = int(eval(input()))
for _ in range(q):
k, a, b = input().split()
k = int(k)
a = int(a)
if k == 1:
b = ord(b) - ord('a')
# type1: update
bit_list[s[a - 1]].add(a, -1)
bit_list[b].add(a, +1)
s[a - 1] = b
else:
# type2: calc
b = int(b)
a -= 1
cnt = 0
for bit_i in bit_list:
if bit_i.sum(b) - bit_i.sum(a) > 0:
cnt += 1
print(cnt)
|
class SegmentTree1():
"""
1-indexed Segment Tree
"""
def __init__(self, n_, ele_id, op_func):
self.n = 1 << (n_ - 1).bit_length() # size
self.data = [ele_id] * (2 * self.n) # binary tree (1-indexed)
self.ele_id = ele_id # identity element
self.op_func = op_func # binary operation of monoid
def __getitem__(self, i):
return self.data[i + self.n]
def build(self, data_init):
for i in range(len(data_init)):
self.data[i + self.n] = data_init[i] # set data in leaf
for i in reversed(list(range(self.n))):
self.data[i] = self.op_func(self.data[2 * i], self.data[2 * i + 1])
def update(self, i, x):
# change i-th element to x (i : 0-indexed)
i += self.n
self.data[i] = x
while i > 1:
i = i >> 1 # go to parenet-node
self.data[i] = self.op_func(self.data[2 * i], self.data[2 * i + 1])
def query(self, l, r):
# query for interval [l, r) (l, r : 0-indexed)
l += self.n
r += self.n
ret = self.ele_id
while l < r:
if l & 1: # right child
ret = self.op_func(ret, self.data[l])
l += 1
if r & 1: # right child
r -= 1
ret = self.op_func(ret, self.data[r])
# go to parent-nodes
l = l >> 1
r = r >> 1
return ret
n = int(eval(input()))
s = eval(input())
# construct segment tree
ele_id = 0
op_func = lambda a, b: a | b
st_bitset = SegmentTree1(n, ele_id, op_func)
st_bitset.build([1 << (ord(si) - ord('a')) for si in s])
# query
q = int(eval(input()))
for _ in range(q):
k, a, b = input().split()
k = int(k)
a = int(a)
if k == 1:
b = ord(b) - ord('a')
a -= 1
# type1: update
st_bitset.update(a, 1 << b)
else:
# type2: calc
b = int(b)
a -= 1
cnt = bin(st_bitset.query(a, b)).count('1')
print(cnt)
| 53 | 71 | 1,271 | 2,073 |
class BIT1:
"""
Binary Indexed Tree (1-indexed)
"""
def __init__(self, n):
self.n = n
self.bit = [0] * (self.n + 1)
self.data = [0] * (self.n + 1)
def add(self, idx, x):
# add x to idx-th element
# idx: 1-indexed
self.data[idx] += x
while idx <= self.n:
self.bit[idx] += x
idx += idx & (-idx)
def sum(self, idx):
# get sum of [1, idx]
# idx: 1-indexed
s = 0
while idx:
s += self.bit[idx]
idx -= idx & (-idx)
return s
n = int(eval(input()))
s = [ord(si) - ord("a") for si in list(eval(input()))]
bit_list = [BIT1(n + 1) for _ in range(26)]
for i in range(n):
bit_list[s[i]].add(i + 1, +1)
q = int(eval(input()))
for _ in range(q):
k, a, b = input().split()
k = int(k)
a = int(a)
if k == 1:
b = ord(b) - ord("a")
# type1: update
bit_list[s[a - 1]].add(a, -1)
bit_list[b].add(a, +1)
s[a - 1] = b
else:
# type2: calc
b = int(b)
a -= 1
cnt = 0
for bit_i in bit_list:
if bit_i.sum(b) - bit_i.sum(a) > 0:
cnt += 1
print(cnt)
|
class SegmentTree1:
"""
1-indexed Segment Tree
"""
def __init__(self, n_, ele_id, op_func):
self.n = 1 << (n_ - 1).bit_length() # size
self.data = [ele_id] * (2 * self.n) # binary tree (1-indexed)
self.ele_id = ele_id # identity element
self.op_func = op_func # binary operation of monoid
def __getitem__(self, i):
return self.data[i + self.n]
def build(self, data_init):
for i in range(len(data_init)):
self.data[i + self.n] = data_init[i] # set data in leaf
for i in reversed(list(range(self.n))):
self.data[i] = self.op_func(self.data[2 * i], self.data[2 * i + 1])
def update(self, i, x):
# change i-th element to x (i : 0-indexed)
i += self.n
self.data[i] = x
while i > 1:
i = i >> 1 # go to parenet-node
self.data[i] = self.op_func(self.data[2 * i], self.data[2 * i + 1])
def query(self, l, r):
# query for interval [l, r) (l, r : 0-indexed)
l += self.n
r += self.n
ret = self.ele_id
while l < r:
if l & 1: # right child
ret = self.op_func(ret, self.data[l])
l += 1
if r & 1: # right child
r -= 1
ret = self.op_func(ret, self.data[r])
# go to parent-nodes
l = l >> 1
r = r >> 1
return ret
n = int(eval(input()))
s = eval(input())
# construct segment tree
ele_id = 0
op_func = lambda a, b: a | b
st_bitset = SegmentTree1(n, ele_id, op_func)
st_bitset.build([1 << (ord(si) - ord("a")) for si in s])
# query
q = int(eval(input()))
for _ in range(q):
k, a, b = input().split()
k = int(k)
a = int(a)
if k == 1:
b = ord(b) - ord("a")
a -= 1
# type1: update
st_bitset.update(a, 1 << b)
else:
# type2: calc
b = int(b)
a -= 1
cnt = bin(st_bitset.query(a, b)).count("1")
print(cnt)
| false | 25.352113 |
[
"-class BIT1:",
"+class SegmentTree1:",
"- Binary Indexed Tree (1-indexed)",
"+ 1-indexed Segment Tree",
"- def __init__(self, n):",
"- self.n = n",
"- self.bit = [0] * (self.n + 1)",
"- self.data = [0] * (self.n + 1)",
"+ def __init__(self, n_, ele_id, op_func):",
"+ self.n = 1 << (n_ - 1).bit_length() # size",
"+ self.data = [ele_id] * (2 * self.n) # binary tree (1-indexed)",
"+ self.ele_id = ele_id # identity element",
"+ self.op_func = op_func # binary operation of monoid",
"- def add(self, idx, x):",
"- # add x to idx-th element",
"- # idx: 1-indexed",
"- self.data[idx] += x",
"- while idx <= self.n:",
"- self.bit[idx] += x",
"- idx += idx & (-idx)",
"+ def __getitem__(self, i):",
"+ return self.data[i + self.n]",
"- def sum(self, idx):",
"- # get sum of [1, idx]",
"- # idx: 1-indexed",
"- s = 0",
"- while idx:",
"- s += self.bit[idx]",
"- idx -= idx & (-idx)",
"- return s",
"+ def build(self, data_init):",
"+ for i in range(len(data_init)):",
"+ self.data[i + self.n] = data_init[i] # set data in leaf",
"+ for i in reversed(list(range(self.n))):",
"+ self.data[i] = self.op_func(self.data[2 * i], self.data[2 * i + 1])",
"+",
"+ def update(self, i, x):",
"+ # change i-th element to x (i : 0-indexed)",
"+ i += self.n",
"+ self.data[i] = x",
"+ while i > 1:",
"+ i = i >> 1 # go to parenet-node",
"+ self.data[i] = self.op_func(self.data[2 * i], self.data[2 * i + 1])",
"+",
"+ def query(self, l, r):",
"+ # query for interval [l, r) (l, r : 0-indexed)",
"+ l += self.n",
"+ r += self.n",
"+ ret = self.ele_id",
"+ while l < r:",
"+ if l & 1: # right child",
"+ ret = self.op_func(ret, self.data[l])",
"+ l += 1",
"+ if r & 1: # right child",
"+ r -= 1",
"+ ret = self.op_func(ret, self.data[r])",
"+ # go to parent-nodes",
"+ l = l >> 1",
"+ r = r >> 1",
"+ return ret",
"-s = [ord(si) - ord(\"a\") for si in list(eval(input()))]",
"-bit_list = [BIT1(n + 1) for _ in range(26)]",
"-for i in range(n):",
"- bit_list[s[i]].add(i + 1, +1)",
"+s = eval(input())",
"+# construct segment tree",
"+ele_id = 0",
"+op_func = lambda a, b: a | b",
"+st_bitset = SegmentTree1(n, ele_id, op_func)",
"+st_bitset.build([1 << (ord(si) - ord(\"a\")) for si in s])",
"+# query",
"+ a -= 1",
"- bit_list[s[a - 1]].add(a, -1)",
"- bit_list[b].add(a, +1)",
"- s[a - 1] = b",
"+ st_bitset.update(a, 1 << b)",
"- cnt = 0",
"- for bit_i in bit_list:",
"- if bit_i.sum(b) - bit_i.sum(a) > 0:",
"- cnt += 1",
"+ cnt = bin(st_bitset.query(a, b)).count(\"1\")"
] | false | 0.038048 | 0.047539 | 0.800344 |
[
"s863281432",
"s908102245"
] |
u799428010
|
p02628
|
python
|
s038536451
|
s685985230
| 28 | 25 | 9,076 | 9,156 |
Accepted
|
Accepted
| 10.71 |
a,b= list(map(int, input().split()))
p=list(map(int, input().split()))
X=sorted(p)[:b]
print((sum(X)))
|
N,K = list(map(int, input().split()))
P=sorted(list(map(int, input().split())),reverse=False)
print((sum(P[:K])))
| 4 | 3 | 91 | 107 |
a, b = list(map(int, input().split()))
p = list(map(int, input().split()))
X = sorted(p)[:b]
print((sum(X)))
|
N, K = list(map(int, input().split()))
P = sorted(list(map(int, input().split())), reverse=False)
print((sum(P[:K])))
| false | 25 |
[
"-a, b = list(map(int, input().split()))",
"-p = list(map(int, input().split()))",
"-X = sorted(p)[:b]",
"-print((sum(X)))",
"+N, K = list(map(int, input().split()))",
"+P = sorted(list(map(int, input().split())), reverse=False)",
"+print((sum(P[:K])))"
] | false | 0.042557 | 0.042544 | 1.000304 |
[
"s038536451",
"s685985230"
] |
u350997408
|
p02396
|
python
|
s744415490
|
s325991464
| 80 | 70 | 7,776 | 7,664 |
Accepted
|
Accepted
| 12.5 |
# coding: utf-8
import sys
line = sys.stdin
count = 1
for x in line :
if int(x) == 0 :
break
print('Case {0}: {1}'.format(count, x), end='')
count += 1
|
# coding: utf-8
import sys
line = sys.stdin
count = 1
for x in line :
if int(x) == 0 :
break
print(('Case {0}: {1}'.format(count, x.strip())))
count += 1
| 11 | 11 | 168 | 168 |
# coding: utf-8
import sys
line = sys.stdin
count = 1
for x in line:
if int(x) == 0:
break
print("Case {0}: {1}".format(count, x), end="")
count += 1
|
# coding: utf-8
import sys
line = sys.stdin
count = 1
for x in line:
if int(x) == 0:
break
print(("Case {0}: {1}".format(count, x.strip())))
count += 1
| false | 0 |
[
"- print(\"Case {0}: {1}\".format(count, x), end=\"\")",
"+ print((\"Case {0}: {1}\".format(count, x.strip())))"
] | false | 0.038129 | 0.085217 | 0.44744 |
[
"s744415490",
"s325991464"
] |
u567534852
|
p02972
|
python
|
s901944894
|
s354293825
| 292 | 270 | 13,116 | 13,112 |
Accepted
|
Accepted
| 7.53 |
n = int(eval(input()))
a = list(map(int, input().split()))
ball = [0]*n
for i in reversed(list(range(1, n+1))):
a[i-1] ^= sum(ball[i-1:n:i]) % 2
if a[i-1] == 1:
ball[i-1] =1
if sum(ball) > 0:
print((sum(ball)))
print((*[i+1 for i in range(n) if ball[i] > 0]))
else:
print((0))
|
n = int(eval(input()))
a = list(map(int, input().split()))
ball = [0]*n
for i in reversed(list(range(1, n+1))):
ball_in_or_not = a[i-1] ^ sum(ball[i-1:n:i]) % 2
if ball_in_or_not == 1:
ball[i-1] =1
if sum(ball) > 0:
print((sum(ball)))
print((*[i+1 for i in range(n) if ball[i] > 0]))
else:
print((0))
| 19 | 18 | 316 | 338 |
n = int(eval(input()))
a = list(map(int, input().split()))
ball = [0] * n
for i in reversed(list(range(1, n + 1))):
a[i - 1] ^= sum(ball[i - 1 : n : i]) % 2
if a[i - 1] == 1:
ball[i - 1] = 1
if sum(ball) > 0:
print((sum(ball)))
print((*[i + 1 for i in range(n) if ball[i] > 0]))
else:
print((0))
|
n = int(eval(input()))
a = list(map(int, input().split()))
ball = [0] * n
for i in reversed(list(range(1, n + 1))):
ball_in_or_not = a[i - 1] ^ sum(ball[i - 1 : n : i]) % 2
if ball_in_or_not == 1:
ball[i - 1] = 1
if sum(ball) > 0:
print((sum(ball)))
print((*[i + 1 for i in range(n) if ball[i] > 0]))
else:
print((0))
| false | 5.263158 |
[
"- a[i - 1] ^= sum(ball[i - 1 : n : i]) % 2",
"- if a[i - 1] == 1:",
"+ ball_in_or_not = a[i - 1] ^ sum(ball[i - 1 : n : i]) % 2",
"+ if ball_in_or_not == 1:"
] | false | 0.041416 | 0.040241 | 1.029186 |
[
"s901944894",
"s354293825"
] |
u571281863
|
p02678
|
python
|
s927856066
|
s847829581
| 651 | 409 | 44,552 | 56,668 |
Accepted
|
Accepted
| 37.17 |
from collections import deque
N,M=list(map(int,input().split()))
to=[[] for _ in range(N)]
for _ in range(M):
a,b=list(map(int,input().split()))
to[a-1].append(b-1)
to[b-1].append(a-1)
q=deque([0])
r=[None]*N
while q:
x=q.popleft()
for i in to[x]:
if r[i] is None:
q.append(i)
r[i]=x+1
print('Yes')
print(('\n'.join(map(str,r[1:]))))
|
from collections import deque
N,M,*AB=map(int,open(0).read().split())
to=[[] for _ in range(N)]
for a,b in zip(*[iter(AB)]*2):
to[a-1].append(b-1)
to[b-1].append(a-1)
q=deque([0])
r=[None]*N
while q:
x=q.popleft()
for i in to[x]:
if r[i] is None:
q.append(i)
r[i]=x+1
print("Yes",*r[1:],sep="\n")
| 17 | 15 | 361 | 334 |
from collections import deque
N, M = list(map(int, input().split()))
to = [[] for _ in range(N)]
for _ in range(M):
a, b = list(map(int, input().split()))
to[a - 1].append(b - 1)
to[b - 1].append(a - 1)
q = deque([0])
r = [None] * N
while q:
x = q.popleft()
for i in to[x]:
if r[i] is None:
q.append(i)
r[i] = x + 1
print("Yes")
print(("\n".join(map(str, r[1:]))))
|
from collections import deque
N, M, *AB = map(int, open(0).read().split())
to = [[] for _ in range(N)]
for a, b in zip(*[iter(AB)] * 2):
to[a - 1].append(b - 1)
to[b - 1].append(a - 1)
q = deque([0])
r = [None] * N
while q:
x = q.popleft()
for i in to[x]:
if r[i] is None:
q.append(i)
r[i] = x + 1
print("Yes", *r[1:], sep="\n")
| false | 11.764706 |
[
"-N, M = list(map(int, input().split()))",
"+N, M, *AB = map(int, open(0).read().split())",
"-for _ in range(M):",
"- a, b = list(map(int, input().split()))",
"+for a, b in zip(*[iter(AB)] * 2):",
"-print(\"Yes\")",
"-print((\"\\n\".join(map(str, r[1:]))))",
"+print(\"Yes\", *r[1:], sep=\"\\n\")"
] | false | 0.036675 | 0.036308 | 1.010109 |
[
"s927856066",
"s847829581"
] |
u467736898
|
p02868
|
python
|
s926866848
|
s276417145
| 1,010 | 719 | 72,024 | 103,724 |
Accepted
|
Accepted
| 28.81 |
# RMQ のパフォーマンステスト
class Rmq:
# 平方分割
# 値を変更すると元のリストの値も書き換わる
# 検証: http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=3990681
def __init__(self, a, sqrt_n=150, inf=(1<<31)-1):
self.sqrt_n = sqrt_n
if hasattr(a, "__iter__"):
from itertools import zip_longest
self.n = len(a)
self.layer0 = [min(values) for values in zip_longest(*[iter(a)]*sqrt_n, fillvalue=inf)]
self.layer1 = a
elif isinstance(a, int):
self.n = a
self.layer0 = [inf] * ((a - 1) // sqrt_n + 1)
self.layer1 = [inf] * a
else:
raise TypeError
def get_min(self, l, r):
sqrt_n = self.sqrt_n
parent_l, parent_r = l//sqrt_n+1, (r-1)//sqrt_n
if parent_l < parent_r:
return min(min(self.layer0[parent_l:parent_r]),
min(self.layer1[l:parent_l*sqrt_n]),
min(self.layer1[parent_r*sqrt_n:r]))
else:
return min(self.layer1[l:r])
def set_value(self, idx, val):
self.layer1[idx] = val
idx0 = idx // self.sqrt_n
idx1 = idx0 * self.sqrt_n
self.layer0[idx0] = min(self.layer1[idx1:idx1+self.sqrt_n])
def chmin(self, idx, val):
if self.layer1[idx] > val:
self.layer1[idx] = val
idx //= self.sqrt_n
self.layer0[idx] = min(self.layer0[idx], val)
def debug(self):
print(("layer0=", self.layer0))
print(("layer1=", self.layer1))
def __getitem__(self, item):
return self.layer1[item]
def __setitem__(self, key, value):
self.set_value(key, value)
from operator import itemgetter
N, M = list(map(int, input().split()))
LRC = [list(map(int, input().split())) for _ in range(M)]
LRC.sort(key=itemgetter(0))
idx_LRC = 0
q = []
inf = 10**18
seg = Rmq(N+1, inf=inf)
seg.set_value(1, 0)
for v in range(1, N + 1):
d = seg.get_min(v, N + 1)
while idx_LRC < M:
l, r, c = LRC[idx_LRC]
if l <= v:
seg.chmin(r, d+c)
idx_LRC += 1
else:
break
ans = seg[N]
print((ans if ans != inf else -1))
|
# いろいろ高速化
class Rmq:
# 平方分割
# 値を変更すると元のリストの値も書き換わる
# 検証: http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=3990681
def __init__(self, a, sqrt_n=150, inf=(1<<31)-1):
self.sqrt_n = sqrt_n
if hasattr(a, "__iter__"):
from itertools import zip_longest
self.n = len(a)
self.layer0 = [min(values) for values in zip_longest(*[iter(a)]*sqrt_n, fillvalue=inf)]
self.layer1 = a
elif isinstance(a, int):
self.n = a
self.layer0 = [inf] * ((a - 1) // sqrt_n + 1)
self.layer1 = [inf] * a
else:
raise TypeError
def get_min(self, l, r):
sqrt_n = self.sqrt_n
parent_l, parent_r = l//sqrt_n+1, (r-1)//sqrt_n
if parent_l < parent_r:
return min(min(self.layer0[parent_l:parent_r]),
min(self.layer1[l:parent_l*sqrt_n]),
min(self.layer1[parent_r*sqrt_n:r]))
else:
return min(self.layer1[l:r])
def set_value(self, idx, val):
self.layer1[idx] = val
idx0 = idx // self.sqrt_n
idx1 = idx0 * self.sqrt_n
self.layer0[idx0] = min(self.layer1[idx1:idx1+self.sqrt_n])
def chmin(self, idx, val):
if self.layer1[idx] > val:
self.layer1[idx] = val
idx //= self.sqrt_n
self.layer0[idx] = min(self.layer0[idx], val)
def debug(self):
print(("layer0=", self.layer0))
print(("layer1=", self.layer1))
def __getitem__(self, item):
return self.layer1[item]
def __setitem__(self, key, value):
self.set_value(key, value)
from operator import itemgetter
N, M, *LRC = list(map(int, open(0).read().split()))
LRC = list(zip(*[iter(LRC)]*3))
LRC.sort(key=itemgetter(0))
idx_LRC = 0
q = []
inf = 10**18
seg = Rmq(N+1, inf=inf)
seg.set_value(1, 0)
for v in range(1, N + 1):
d = seg.get_min(v, N + 1)
while idx_LRC < M:
l, r, c = LRC[idx_LRC]
if l <= v:
seg.chmin(r, d+c)
idx_LRC += 1
else:
break
ans = seg[N]
print((ans if ans != inf else -1))
| 76 | 76 | 2,237 | 2,216 |
# RMQ のパフォーマンステスト
class Rmq:
# 平方分割
# 値を変更すると元のリストの値も書き換わる
# 検証: http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=3990681
def __init__(self, a, sqrt_n=150, inf=(1 << 31) - 1):
self.sqrt_n = sqrt_n
if hasattr(a, "__iter__"):
from itertools import zip_longest
self.n = len(a)
self.layer0 = [
min(values)
for values in zip_longest(*[iter(a)] * sqrt_n, fillvalue=inf)
]
self.layer1 = a
elif isinstance(a, int):
self.n = a
self.layer0 = [inf] * ((a - 1) // sqrt_n + 1)
self.layer1 = [inf] * a
else:
raise TypeError
def get_min(self, l, r):
sqrt_n = self.sqrt_n
parent_l, parent_r = l // sqrt_n + 1, (r - 1) // sqrt_n
if parent_l < parent_r:
return min(
min(self.layer0[parent_l:parent_r]),
min(self.layer1[l : parent_l * sqrt_n]),
min(self.layer1[parent_r * sqrt_n : r]),
)
else:
return min(self.layer1[l:r])
def set_value(self, idx, val):
self.layer1[idx] = val
idx0 = idx // self.sqrt_n
idx1 = idx0 * self.sqrt_n
self.layer0[idx0] = min(self.layer1[idx1 : idx1 + self.sqrt_n])
def chmin(self, idx, val):
if self.layer1[idx] > val:
self.layer1[idx] = val
idx //= self.sqrt_n
self.layer0[idx] = min(self.layer0[idx], val)
def debug(self):
print(("layer0=", self.layer0))
print(("layer1=", self.layer1))
def __getitem__(self, item):
return self.layer1[item]
def __setitem__(self, key, value):
self.set_value(key, value)
from operator import itemgetter
N, M = list(map(int, input().split()))
LRC = [list(map(int, input().split())) for _ in range(M)]
LRC.sort(key=itemgetter(0))
idx_LRC = 0
q = []
inf = 10**18
seg = Rmq(N + 1, inf=inf)
seg.set_value(1, 0)
for v in range(1, N + 1):
d = seg.get_min(v, N + 1)
while idx_LRC < M:
l, r, c = LRC[idx_LRC]
if l <= v:
seg.chmin(r, d + c)
idx_LRC += 1
else:
break
ans = seg[N]
print((ans if ans != inf else -1))
|
# いろいろ高速化
class Rmq:
# 平方分割
# 値を変更すると元のリストの値も書き換わる
# 検証: http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=3990681
def __init__(self, a, sqrt_n=150, inf=(1 << 31) - 1):
self.sqrt_n = sqrt_n
if hasattr(a, "__iter__"):
from itertools import zip_longest
self.n = len(a)
self.layer0 = [
min(values)
for values in zip_longest(*[iter(a)] * sqrt_n, fillvalue=inf)
]
self.layer1 = a
elif isinstance(a, int):
self.n = a
self.layer0 = [inf] * ((a - 1) // sqrt_n + 1)
self.layer1 = [inf] * a
else:
raise TypeError
def get_min(self, l, r):
sqrt_n = self.sqrt_n
parent_l, parent_r = l // sqrt_n + 1, (r - 1) // sqrt_n
if parent_l < parent_r:
return min(
min(self.layer0[parent_l:parent_r]),
min(self.layer1[l : parent_l * sqrt_n]),
min(self.layer1[parent_r * sqrt_n : r]),
)
else:
return min(self.layer1[l:r])
def set_value(self, idx, val):
self.layer1[idx] = val
idx0 = idx // self.sqrt_n
idx1 = idx0 * self.sqrt_n
self.layer0[idx0] = min(self.layer1[idx1 : idx1 + self.sqrt_n])
def chmin(self, idx, val):
if self.layer1[idx] > val:
self.layer1[idx] = val
idx //= self.sqrt_n
self.layer0[idx] = min(self.layer0[idx], val)
def debug(self):
print(("layer0=", self.layer0))
print(("layer1=", self.layer1))
def __getitem__(self, item):
return self.layer1[item]
def __setitem__(self, key, value):
self.set_value(key, value)
from operator import itemgetter
N, M, *LRC = list(map(int, open(0).read().split()))
LRC = list(zip(*[iter(LRC)] * 3))
LRC.sort(key=itemgetter(0))
idx_LRC = 0
q = []
inf = 10**18
seg = Rmq(N + 1, inf=inf)
seg.set_value(1, 0)
for v in range(1, N + 1):
d = seg.get_min(v, N + 1)
while idx_LRC < M:
l, r, c = LRC[idx_LRC]
if l <= v:
seg.chmin(r, d + c)
idx_LRC += 1
else:
break
ans = seg[N]
print((ans if ans != inf else -1))
| false | 0 |
[
"-# RMQ のパフォーマンステスト",
"+# いろいろ高速化",
"-N, M = list(map(int, input().split()))",
"-LRC = [list(map(int, input().split())) for _ in range(M)]",
"+N, M, *LRC = list(map(int, open(0).read().split()))",
"+LRC = list(zip(*[iter(LRC)] * 3))"
] | false | 0.070302 | 0.03954 | 1.77799 |
[
"s926866848",
"s276417145"
] |
u943624079
|
p02888
|
python
|
s542026789
|
s955251451
| 1,968 | 761 | 3,188 | 44,124 |
Accepted
|
Accepted
| 61.33 |
N = int(eval(input()))
L = list(map(int, input().split()))
L.sort()
from bisect import bisect_left
cnt = 0
for i in range(0, N - 2):
for j in range(i + 1, N - 1):
t = L[i] + L[j]
idx = bisect_left(L, t, j + 1, len(L))
cnt += max(0, idx - j - 1)
print(cnt)
|
N = int(eval(input()))
L = list(map(int, input().split()))
L.sort()
from bisect import bisect_left
cnt = 0
for i in range(0,N-2):
for j in range(i+1,N-1):
t = L[i]+L[j]
idx = bisect_left(L,t,lo=j+1)
cnt += max(0,idx-j-1)
print(cnt)
| 13 | 12 | 292 | 253 |
N = int(eval(input()))
L = list(map(int, input().split()))
L.sort()
from bisect import bisect_left
cnt = 0
for i in range(0, N - 2):
for j in range(i + 1, N - 1):
t = L[i] + L[j]
idx = bisect_left(L, t, j + 1, len(L))
cnt += max(0, idx - j - 1)
print(cnt)
|
N = int(eval(input()))
L = list(map(int, input().split()))
L.sort()
from bisect import bisect_left
cnt = 0
for i in range(0, N - 2):
for j in range(i + 1, N - 1):
t = L[i] + L[j]
idx = bisect_left(L, t, lo=j + 1)
cnt += max(0, idx - j - 1)
print(cnt)
| false | 7.692308 |
[
"- idx = bisect_left(L, t, j + 1, len(L))",
"+ idx = bisect_left(L, t, lo=j + 1)"
] | false | 0.046501 | 0.045087 | 1.031358 |
[
"s542026789",
"s955251451"
] |
u571969099
|
p02558
|
python
|
s036554886
|
s035160527
| 656 | 252 | 76,220 | 74,256 |
Accepted
|
Accepted
| 61.59 |
class DSU:
def __init__(self, n):
self._n = n
self.parent_or_size = [-1] * n
def merge(self, a, b):
x, y = self.leader(a), self.leader(b)
if x == y:
return x
if -self.parent_or_size[x] < -self.parent_or_size[y]:
x, y = y, x
self.parent_or_size[x] += self.parent_or_size[y]
self.parent_or_size[y] = x
return x
def same(self, a, b):
return self.leader(a) == self.leader(b)
def leader(self, a):
while self.parent_or_size[a] >= 0:
a = self.parent_or_size[a]
return a
def size(self, a):
return -self.parent_or_size[self.leader(a)]
def groups(self):
leader_buf = [self.leader(i) for i in range(self._n)]
group_size = [0] * self._n
for i in leader_buf:
group_size[i] += 1
result = [[] for _ in range(self._n)]
for i in range(self._n):
result[leader_buf[i]].append(i)
result = [i for i in result if i]
return result
n, q = list(map(int, input().split()))
dsu = DSU(n)
for _ in range(q):
t, u, v = list(map(int, input().split()))
if t == 0:
dsu.merge(u, v)
else:
print((1 if dsu.same(u, v) else 0))
|
import sys
input = sys.stdin.readline
class DSU:
def __init__(self, n):
self._n = n
self.parent_or_size = [-1] * n
def merge(self, a, b):
x, y = self.leader(a), self.leader(b)
if x == y:
return x
if -self.parent_or_size[x] < -self.parent_or_size[y]:
x, y = y, x
self.parent_or_size[x] += self.parent_or_size[y]
self.parent_or_size[y] = x
return x
def same(self, a, b):
return self.leader(a) == self.leader(b)
def leader(self, a):
while self.parent_or_size[a] >= 0:
a = self.parent_or_size[a]
return a
def size(self, a):
return -self.parent_or_size[self.leader(a)]
def groups(self):
leader_buf = [self.leader(i) for i in range(self._n)]
group_size = [0] * self._n
for i in leader_buf:
group_size[i] += 1
result = [[] for _ in range(self._n)]
for i in range(self._n):
result[leader_buf[i]].append(i)
result = [i for i in result if i]
return result
n, q = list(map(int, input().split()))
dsu = DSU(n)
for _ in range(q):
t, u, v = list(map(int, input().split()))
if t == 0:
dsu.merge(u, v)
else:
print((1 if dsu.same(u, v) else 0))
| 47 | 50 | 1,294 | 1,336 |
class DSU:
def __init__(self, n):
self._n = n
self.parent_or_size = [-1] * n
def merge(self, a, b):
x, y = self.leader(a), self.leader(b)
if x == y:
return x
if -self.parent_or_size[x] < -self.parent_or_size[y]:
x, y = y, x
self.parent_or_size[x] += self.parent_or_size[y]
self.parent_or_size[y] = x
return x
def same(self, a, b):
return self.leader(a) == self.leader(b)
def leader(self, a):
while self.parent_or_size[a] >= 0:
a = self.parent_or_size[a]
return a
def size(self, a):
return -self.parent_or_size[self.leader(a)]
def groups(self):
leader_buf = [self.leader(i) for i in range(self._n)]
group_size = [0] * self._n
for i in leader_buf:
group_size[i] += 1
result = [[] for _ in range(self._n)]
for i in range(self._n):
result[leader_buf[i]].append(i)
result = [i for i in result if i]
return result
n, q = list(map(int, input().split()))
dsu = DSU(n)
for _ in range(q):
t, u, v = list(map(int, input().split()))
if t == 0:
dsu.merge(u, v)
else:
print((1 if dsu.same(u, v) else 0))
|
import sys
input = sys.stdin.readline
class DSU:
def __init__(self, n):
self._n = n
self.parent_or_size = [-1] * n
def merge(self, a, b):
x, y = self.leader(a), self.leader(b)
if x == y:
return x
if -self.parent_or_size[x] < -self.parent_or_size[y]:
x, y = y, x
self.parent_or_size[x] += self.parent_or_size[y]
self.parent_or_size[y] = x
return x
def same(self, a, b):
return self.leader(a) == self.leader(b)
def leader(self, a):
while self.parent_or_size[a] >= 0:
a = self.parent_or_size[a]
return a
def size(self, a):
return -self.parent_or_size[self.leader(a)]
def groups(self):
leader_buf = [self.leader(i) for i in range(self._n)]
group_size = [0] * self._n
for i in leader_buf:
group_size[i] += 1
result = [[] for _ in range(self._n)]
for i in range(self._n):
result[leader_buf[i]].append(i)
result = [i for i in result if i]
return result
n, q = list(map(int, input().split()))
dsu = DSU(n)
for _ in range(q):
t, u, v = list(map(int, input().split()))
if t == 0:
dsu.merge(u, v)
else:
print((1 if dsu.same(u, v) else 0))
| false | 6 |
[
"+import sys",
"+",
"+input = sys.stdin.readline",
"+",
"+"
] | false | 0.063309 | 0.038253 | 1.65499 |
[
"s036554886",
"s035160527"
] |
u633255271
|
p02762
|
python
|
s740345219
|
s205439657
| 1,382 | 1,144 | 39,216 | 13,420 |
Accepted
|
Accepted
| 17.22 |
import sys
sys.setrecursionlimit(1000000000)
class union_find:
def __init__(self, N):
self.par = [i for i in range(N)]
self.size = [1 for i in range(N)]
self.excluded = [0 for i in range(N)]
def root(self, a):
if self.par[a] == a:
return a
else:
# 経路圧縮
self.par[a] = self.root(self.par[a])
return self.par[a]
def same(self, a, b):
return self.root(a) == self.root(b)
def unite(self, a, b):
if not self.same(a, b):
self.size[self.root(b)] += self.get_union_size(a)
self.par[self.root(a)] = self.root(b)
def friend(self, a, b):
self.unite(a, b)
self.excluded[a] += 1
self.excluded[b] += 1
def block(self, a, b):
if self.same(a, b):
self.excluded[a] += 1
self.excluded[b] += 1
def get_union_size(self, a):
return self.size[self.root(a)]
def get_friend_sugestion_size(self, a):
return self.get_union_size(a) - 1 - self.excluded[a]
N, M, K = list(map(int, input().split()))
UF = union_find(N)
for i in range(M):
A, B = list(map(int, input().split()))
UF.friend(A-1, B-1)
for i in range(K):
A, B = list(map(int, input().split()))
UF.block(A-1, B-1)
print((*[UF.get_friend_sugestion_size(x) for x in range(N)]))
|
class union_find:
def __init__(self, N):
# par < 0 の時はsizeを格納
self.par = [-1 for i in range(N)]
self.excluded = [0 for i in range(N)]
def root(self, a):
if self.par[a] < 0:
return a
else:
# 経路圧縮
self.par[a] = self.root(self.par[a])
return self.par[a]
def unite(self, a, b):
ar = self.root(a)
br = self.root(b)
if ar == br:
return
if self.par[ar] > self.par[br]:
ar, br = br, ar
self.par[ar] += self.par[br]
self.par[br] = ar
def friend(self, a, b):
self.unite(a, b)
self.excluded[a] += 1
self.excluded[b] += 1
def block(self, a, b):
ar = self.root(a)
br = self.root(b)
if ar != br:
return
self.excluded[a] += 1
self.excluded[b] += 1
def get_friend_sugestion_size(self, a):
return -self.par[self.root(a)] - 1 - self.excluded[a]
N, M, K = list(map(int, input().split()))
UF = union_find(N)
for i in range(M):
A, B = list(map(int, input().split()))
UF.friend(A-1, B-1)
for i in range(K):
A, B = list(map(int, input().split()))
UF.block(A-1, B-1)
print((*[UF.get_friend_sugestion_size(x) for x in range(N)]))
| 50 | 49 | 1,415 | 1,342 |
import sys
sys.setrecursionlimit(1000000000)
class union_find:
def __init__(self, N):
self.par = [i for i in range(N)]
self.size = [1 for i in range(N)]
self.excluded = [0 for i in range(N)]
def root(self, a):
if self.par[a] == a:
return a
else:
# 経路圧縮
self.par[a] = self.root(self.par[a])
return self.par[a]
def same(self, a, b):
return self.root(a) == self.root(b)
def unite(self, a, b):
if not self.same(a, b):
self.size[self.root(b)] += self.get_union_size(a)
self.par[self.root(a)] = self.root(b)
def friend(self, a, b):
self.unite(a, b)
self.excluded[a] += 1
self.excluded[b] += 1
def block(self, a, b):
if self.same(a, b):
self.excluded[a] += 1
self.excluded[b] += 1
def get_union_size(self, a):
return self.size[self.root(a)]
def get_friend_sugestion_size(self, a):
return self.get_union_size(a) - 1 - self.excluded[a]
N, M, K = list(map(int, input().split()))
UF = union_find(N)
for i in range(M):
A, B = list(map(int, input().split()))
UF.friend(A - 1, B - 1)
for i in range(K):
A, B = list(map(int, input().split()))
UF.block(A - 1, B - 1)
print((*[UF.get_friend_sugestion_size(x) for x in range(N)]))
|
class union_find:
def __init__(self, N):
# par < 0 の時はsizeを格納
self.par = [-1 for i in range(N)]
self.excluded = [0 for i in range(N)]
def root(self, a):
if self.par[a] < 0:
return a
else:
# 経路圧縮
self.par[a] = self.root(self.par[a])
return self.par[a]
def unite(self, a, b):
ar = self.root(a)
br = self.root(b)
if ar == br:
return
if self.par[ar] > self.par[br]:
ar, br = br, ar
self.par[ar] += self.par[br]
self.par[br] = ar
def friend(self, a, b):
self.unite(a, b)
self.excluded[a] += 1
self.excluded[b] += 1
def block(self, a, b):
ar = self.root(a)
br = self.root(b)
if ar != br:
return
self.excluded[a] += 1
self.excluded[b] += 1
def get_friend_sugestion_size(self, a):
return -self.par[self.root(a)] - 1 - self.excluded[a]
N, M, K = list(map(int, input().split()))
UF = union_find(N)
for i in range(M):
A, B = list(map(int, input().split()))
UF.friend(A - 1, B - 1)
for i in range(K):
A, B = list(map(int, input().split()))
UF.block(A - 1, B - 1)
print((*[UF.get_friend_sugestion_size(x) for x in range(N)]))
| false | 2 |
[
"-import sys",
"-",
"-sys.setrecursionlimit(1000000000)",
"-",
"-",
"- self.par = [i for i in range(N)]",
"- self.size = [1 for i in range(N)]",
"+ # par < 0 の時はsizeを格納",
"+ self.par = [-1 for i in range(N)]",
"- if self.par[a] == a:",
"+ if self.par[a] < 0:",
"- def same(self, a, b):",
"- return self.root(a) == self.root(b)",
"-",
"- if not self.same(a, b):",
"- self.size[self.root(b)] += self.get_union_size(a)",
"- self.par[self.root(a)] = self.root(b)",
"+ ar = self.root(a)",
"+ br = self.root(b)",
"+ if ar == br:",
"+ return",
"+ if self.par[ar] > self.par[br]:",
"+ ar, br = br, ar",
"+ self.par[ar] += self.par[br]",
"+ self.par[br] = ar",
"- if self.same(a, b):",
"- self.excluded[a] += 1",
"- self.excluded[b] += 1",
"-",
"- def get_union_size(self, a):",
"- return self.size[self.root(a)]",
"+ ar = self.root(a)",
"+ br = self.root(b)",
"+ if ar != br:",
"+ return",
"+ self.excluded[a] += 1",
"+ self.excluded[b] += 1",
"- return self.get_union_size(a) - 1 - self.excluded[a]",
"+ return -self.par[self.root(a)] - 1 - self.excluded[a]"
] | false | 0.037586 | 0.037749 | 0.9957 |
[
"s740345219",
"s205439657"
] |
u780698286
|
p03371
|
python
|
s592644592
|
s277846076
| 212 | 190 | 9,084 | 9,108 |
Accepted
|
Accepted
| 10.38 |
a, b, c, x, y = list(map(int, input().split()))
ans = 10 ** 15
for i in range(max(x, y) * 2 + 1):
n = c * i * 2 + max(0, x - i) * a + max(0, y - i) * b
ans = min(ans, n)
print(ans)
|
a, b, c, x, y = list(map(int, input().split()))
ans = 10 ** 15
for i in range(max(x, y) * 2 + 1):
if x - i//2 < 0 and y - i//2 < 0:
n = c * i
elif x - i//2 < 0:
n = c * i + (y - i//2) * b
elif y - i//2 < 0:
n = c * i + (x - i//2) * a
else:
n = c * i + (x - i//2) * a + (y - i//2) * b
ans = min(ans, n)
print(ans)
| 6 | 13 | 185 | 348 |
a, b, c, x, y = list(map(int, input().split()))
ans = 10**15
for i in range(max(x, y) * 2 + 1):
n = c * i * 2 + max(0, x - i) * a + max(0, y - i) * b
ans = min(ans, n)
print(ans)
|
a, b, c, x, y = list(map(int, input().split()))
ans = 10**15
for i in range(max(x, y) * 2 + 1):
if x - i // 2 < 0 and y - i // 2 < 0:
n = c * i
elif x - i // 2 < 0:
n = c * i + (y - i // 2) * b
elif y - i // 2 < 0:
n = c * i + (x - i // 2) * a
else:
n = c * i + (x - i // 2) * a + (y - i // 2) * b
ans = min(ans, n)
print(ans)
| false | 53.846154 |
[
"- n = c * i * 2 + max(0, x - i) * a + max(0, y - i) * b",
"+ if x - i // 2 < 0 and y - i // 2 < 0:",
"+ n = c * i",
"+ elif x - i // 2 < 0:",
"+ n = c * i + (y - i // 2) * b",
"+ elif y - i // 2 < 0:",
"+ n = c * i + (x - i // 2) * a",
"+ else:",
"+ n = c * i + (x - i // 2) * a + (y - i // 2) * b"
] | false | 0.106274 | 0.104191 | 1.019989 |
[
"s592644592",
"s277846076"
] |
u906501980
|
p02678
|
python
|
s763878467
|
s586660681
| 597 | 471 | 41,544 | 98,656 |
Accepted
|
Accepted
| 21.11 |
from collections import deque
def main():
n, m = list(map(int, input().split()))
route = [[] for _ in range(n+1)]
ans = [None]*(n+1)
for _ in range(m):
a, b = list(map(int, input().split()))
route[a].append(b)
route[b].append(a)
q = deque([1])
while q:
parent = q.pop()
children = route[parent]
for child in children:
if ans[child] is None:
ans[child] = parent
q.appendleft(child)
print("Yes")
print(("\n".join(list(map(str, ans[2:])))))
if __name__ == "__main__":
main()
|
from collections import deque
def main():
n, m = list(map(int, input().split()))
route = [[] for _ in range(n+1)]
for _ in range(m):
a, b = list(map(int, input().split()))
route[a].append(b)
route[b].append(a)
ans = [None]*(n+1)
q = deque([1])
while q:
parent = q.pop()
children = route[parent]
for child in children:
if ans[child] is None:
ans[child] = parent
q.appendleft(child)
print("Yes")
print(("\n".join(list(map(str, ans[2:])))))
if __name__ == "__main__":
main()
| 23 | 23 | 609 | 609 |
from collections import deque
def main():
n, m = list(map(int, input().split()))
route = [[] for _ in range(n + 1)]
ans = [None] * (n + 1)
for _ in range(m):
a, b = list(map(int, input().split()))
route[a].append(b)
route[b].append(a)
q = deque([1])
while q:
parent = q.pop()
children = route[parent]
for child in children:
if ans[child] is None:
ans[child] = parent
q.appendleft(child)
print("Yes")
print(("\n".join(list(map(str, ans[2:])))))
if __name__ == "__main__":
main()
|
from collections import deque
def main():
n, m = list(map(int, input().split()))
route = [[] for _ in range(n + 1)]
for _ in range(m):
a, b = list(map(int, input().split()))
route[a].append(b)
route[b].append(a)
ans = [None] * (n + 1)
q = deque([1])
while q:
parent = q.pop()
children = route[parent]
for child in children:
if ans[child] is None:
ans[child] = parent
q.appendleft(child)
print("Yes")
print(("\n".join(list(map(str, ans[2:])))))
if __name__ == "__main__":
main()
| false | 0 |
[
"- ans = [None] * (n + 1)",
"+ ans = [None] * (n + 1)"
] | false | 0.044416 | 0.049382 | 0.899445 |
[
"s763878467",
"s586660681"
] |
u325282913
|
p03361
|
python
|
s384123224
|
s832171377
| 19 | 17 | 3,188 | 3,064 |
Accepted
|
Accepted
| 10.53 |
H, W = list(map(int, input().split()))
tmp = '.' * (W + 2)
matrix = [tmp] * (H + 2)
for i in range(1,H+1):
matrix[i] = '.' + eval(input()) + '.'
for i in range(1,H+1):
for k in range(1,W+1):
if matrix[i][k] == '.':
continue
elif matrix[i][k-1] == '.' and matrix[i][k+1] == '.' and matrix[i-1][k] == '.' and matrix[i+1][k] == '.':
print('No')
exit()
print('Yes')
|
H, W = list(map(int,input().split()))
grid = ['.'*(W+2)]
for _ in range(H):
tmp = eval(input())
tmp = '.' + tmp + '.'
grid.append(tmp)
grid.append('.'*(W+2))
for i in range(1,H+1):
for k in range(1,W+1):
if grid[i][k] == '.':
continue
if grid[i][k+1] != '#' and grid[i][k-1] != '#':
if grid[i+1][k] != '#' and grid[i-1][k] != '#':
print('No')
exit()
print('Yes')
| 13 | 16 | 421 | 453 |
H, W = list(map(int, input().split()))
tmp = "." * (W + 2)
matrix = [tmp] * (H + 2)
for i in range(1, H + 1):
matrix[i] = "." + eval(input()) + "."
for i in range(1, H + 1):
for k in range(1, W + 1):
if matrix[i][k] == ".":
continue
elif (
matrix[i][k - 1] == "."
and matrix[i][k + 1] == "."
and matrix[i - 1][k] == "."
and matrix[i + 1][k] == "."
):
print("No")
exit()
print("Yes")
|
H, W = list(map(int, input().split()))
grid = ["." * (W + 2)]
for _ in range(H):
tmp = eval(input())
tmp = "." + tmp + "."
grid.append(tmp)
grid.append("." * (W + 2))
for i in range(1, H + 1):
for k in range(1, W + 1):
if grid[i][k] == ".":
continue
if grid[i][k + 1] != "#" and grid[i][k - 1] != "#":
if grid[i + 1][k] != "#" and grid[i - 1][k] != "#":
print("No")
exit()
print("Yes")
| false | 18.75 |
[
"-tmp = \".\" * (W + 2)",
"-matrix = [tmp] * (H + 2)",
"-for i in range(1, H + 1):",
"- matrix[i] = \".\" + eval(input()) + \".\"",
"+grid = [\".\" * (W + 2)]",
"+for _ in range(H):",
"+ tmp = eval(input())",
"+ tmp = \".\" + tmp + \".\"",
"+ grid.append(tmp)",
"+grid.append(\".\" * (W + 2))",
"- if matrix[i][k] == \".\":",
"+ if grid[i][k] == \".\":",
"- elif (",
"- matrix[i][k - 1] == \".\"",
"- and matrix[i][k + 1] == \".\"",
"- and matrix[i - 1][k] == \".\"",
"- and matrix[i + 1][k] == \".\"",
"- ):",
"- print(\"No\")",
"- exit()",
"+ if grid[i][k + 1] != \"#\" and grid[i][k - 1] != \"#\":",
"+ if grid[i + 1][k] != \"#\" and grid[i - 1][k] != \"#\":",
"+ print(\"No\")",
"+ exit()"
] | false | 0.067632 | 0.068412 | 0.988597 |
[
"s384123224",
"s832171377"
] |
u440566786
|
p02834
|
python
|
s832909949
|
s134634374
| 526 | 438 | 71,224 | 66,616 |
Accepted
|
Accepted
| 16.73 |
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
n,x,y=list(map(int,input().split()))
x-=1; y-=1
E=[[] for _ in range(n)]
for _ in range(n-1):
u,v=list(map(int,input().split()))
u-=1; v-=1
E[u].append(v)
E[v].append(u)
# x から y への path を作る(depthも)
Q=[(x,-1)]
prev=[None]*n
prev[x]=-1
depth=[None]*n
depth[x]=0
while(Q):
v,p=Q.pop()
for nv in E[v]:
if(nv==p): continue
prev[nv]=v
depth[nv]=depth[v]+1
Q.append((nv,v))
z=y
path=[]
while(z!=-1):
path.append(z)
z=prev[z]
# y からの depth
Q=[(y,-1)]
depth2=[None]*n
depth2[y]=0
while(Q):
v,p=Q.pop()
for nv in E[v]:
if(nv==p): continue
depth2[nv]=depth2[v]+1
Q.append((nv,v))
k=len(path)
s,t=path[k//2-1],path[k//2]
Q=[(x,-1)]
can=[0]*n
can[x]=1
while(Q):
v,p=Q.pop()
for nv in E[v]:
if(nv==p): continue
if((v,nv)==(s,t) or (v,nv)==(t,s)): continue
can[nv]=1
Q.append((nv,v))
d1,z=max((depth2[v],v) for v in range(n) if(can[v]))
d2=depth[z]
# print(d1,d2)
# if((d1+d2)&1):
# d1-=1
print((d1-1))
resolve()
|
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
n,x,y=list(map(int,input().split()))
x-=1; y-=1
E=[[] for _ in range(n)]
for _ in range(n-1):
u,v=list(map(int,input().split()))
u-=1; v-=1
E[u].append(v)
E[v].append(u)
# x,y それぞれの depth を計算する
dx=[None]*n
dx[x]=0
Q=[(x,-1)]
while(Q):
v,p=Q.pop()
for nv in E[v]:
if(nv==p): continue
dx[nv]=dx[v]+1
Q.append((nv,v))
dy=[None]*n
dy[y]=0
Q=[(y,-1)]
while(Q):
v,p=Q.pop()
for nv in E[v]:
if(nv==p): continue
dy[nv]=dy[v]+1
Q.append((nv,v))
# x の方が y より近い点 v に対して、その1つ手前で捕まる
ans=0
for v in range(n):
if(dx[v]<dy[v]):
ans=max(ans,dy[v]-1)
print(ans)
resolve()
| 69 | 44 | 1,448 | 944 |
import sys
sys.setrecursionlimit(2147483647)
INF = float("inf")
MOD = 10**9 + 7
input = lambda: sys.stdin.readline().rstrip()
def resolve():
n, x, y = list(map(int, input().split()))
x -= 1
y -= 1
E = [[] for _ in range(n)]
for _ in range(n - 1):
u, v = list(map(int, input().split()))
u -= 1
v -= 1
E[u].append(v)
E[v].append(u)
# x から y への path を作る(depthも)
Q = [(x, -1)]
prev = [None] * n
prev[x] = -1
depth = [None] * n
depth[x] = 0
while Q:
v, p = Q.pop()
for nv in E[v]:
if nv == p:
continue
prev[nv] = v
depth[nv] = depth[v] + 1
Q.append((nv, v))
z = y
path = []
while z != -1:
path.append(z)
z = prev[z]
# y からの depth
Q = [(y, -1)]
depth2 = [None] * n
depth2[y] = 0
while Q:
v, p = Q.pop()
for nv in E[v]:
if nv == p:
continue
depth2[nv] = depth2[v] + 1
Q.append((nv, v))
k = len(path)
s, t = path[k // 2 - 1], path[k // 2]
Q = [(x, -1)]
can = [0] * n
can[x] = 1
while Q:
v, p = Q.pop()
for nv in E[v]:
if nv == p:
continue
if (v, nv) == (s, t) or (v, nv) == (t, s):
continue
can[nv] = 1
Q.append((nv, v))
d1, z = max((depth2[v], v) for v in range(n) if (can[v]))
d2 = depth[z]
# print(d1,d2)
# if((d1+d2)&1):
# d1-=1
print((d1 - 1))
resolve()
|
import sys
sys.setrecursionlimit(2147483647)
INF = float("inf")
MOD = 10**9 + 7
input = lambda: sys.stdin.readline().rstrip()
def resolve():
n, x, y = list(map(int, input().split()))
x -= 1
y -= 1
E = [[] for _ in range(n)]
for _ in range(n - 1):
u, v = list(map(int, input().split()))
u -= 1
v -= 1
E[u].append(v)
E[v].append(u)
# x,y それぞれの depth を計算する
dx = [None] * n
dx[x] = 0
Q = [(x, -1)]
while Q:
v, p = Q.pop()
for nv in E[v]:
if nv == p:
continue
dx[nv] = dx[v] + 1
Q.append((nv, v))
dy = [None] * n
dy[y] = 0
Q = [(y, -1)]
while Q:
v, p = Q.pop()
for nv in E[v]:
if nv == p:
continue
dy[nv] = dy[v] + 1
Q.append((nv, v))
# x の方が y より近い点 v に対して、その1つ手前で捕まる
ans = 0
for v in range(n):
if dx[v] < dy[v]:
ans = max(ans, dy[v] - 1)
print(ans)
resolve()
| false | 36.231884 |
[
"- # x から y への path を作る(depthも)",
"+ # x,y それぞれの depth を計算する",
"+ dx = [None] * n",
"+ dx[x] = 0",
"- prev = [None] * n",
"- prev[x] = -1",
"- depth = [None] * n",
"- depth[x] = 0",
"- prev[nv] = v",
"- depth[nv] = depth[v] + 1",
"+ dx[nv] = dx[v] + 1",
"- z = y",
"- path = []",
"- while z != -1:",
"- path.append(z)",
"- z = prev[z]",
"- # y からの depth",
"+ dy = [None] * n",
"+ dy[y] = 0",
"- depth2 = [None] * n",
"- depth2[y] = 0",
"- depth2[nv] = depth2[v] + 1",
"+ dy[nv] = dy[v] + 1",
"- k = len(path)",
"- s, t = path[k // 2 - 1], path[k // 2]",
"- Q = [(x, -1)]",
"- can = [0] * n",
"- can[x] = 1",
"- while Q:",
"- v, p = Q.pop()",
"- for nv in E[v]:",
"- if nv == p:",
"- continue",
"- if (v, nv) == (s, t) or (v, nv) == (t, s):",
"- continue",
"- can[nv] = 1",
"- Q.append((nv, v))",
"- d1, z = max((depth2[v], v) for v in range(n) if (can[v]))",
"- d2 = depth[z]",
"- # print(d1,d2)",
"- # if((d1+d2)&1):",
"- # d1-=1",
"- print((d1 - 1))",
"+ # x の方が y より近い点 v に対して、その1つ手前で捕まる",
"+ ans = 0",
"+ for v in range(n):",
"+ if dx[v] < dy[v]:",
"+ ans = max(ans, dy[v] - 1)",
"+ print(ans)"
] | false | 0.046698 | 0.046155 | 1.01177 |
[
"s832909949",
"s134634374"
] |
u941047297
|
p03625
|
python
|
s369891769
|
s666121459
| 243 | 76 | 68,760 | 22,316 |
Accepted
|
Accepted
| 68.72 |
from collections import Counter
def main():
n = int(eval(input()))
A = list(map(int, input().split()))
c = Counter(A)
l1, l2 = 0, 0
for k, v in list(c.items()):
if k > l1:
if v >= 4:
l1, l2 = k, k
elif 2 <= v <= 3:
l1, l2 = k, l1
else:
pass
elif l2 < k <= l1 and v >= 2:
l2 = k
print((l1 * l2))
if __name__ == '__main__':
main()
|
from collections import Counter
def main():
n = int(eval(input()))
A = list(map(int, input().split()))
c = Counter(A)
B = sorted([(k, v) for k, v in list(c.items()) if v >= 2], reverse = True, key = lambda x: x[0])
if len(B) < 2:
print((0))
elif B[0][1] >= 4:
print((B[0][0] ** 2))
else:
print((B[0][0] * B[1][0]))
if __name__ == '__main__':
main()
| 20 | 15 | 476 | 402 |
from collections import Counter
def main():
n = int(eval(input()))
A = list(map(int, input().split()))
c = Counter(A)
l1, l2 = 0, 0
for k, v in list(c.items()):
if k > l1:
if v >= 4:
l1, l2 = k, k
elif 2 <= v <= 3:
l1, l2 = k, l1
else:
pass
elif l2 < k <= l1 and v >= 2:
l2 = k
print((l1 * l2))
if __name__ == "__main__":
main()
|
from collections import Counter
def main():
n = int(eval(input()))
A = list(map(int, input().split()))
c = Counter(A)
B = sorted(
[(k, v) for k, v in list(c.items()) if v >= 2], reverse=True, key=lambda x: x[0]
)
if len(B) < 2:
print((0))
elif B[0][1] >= 4:
print((B[0][0] ** 2))
else:
print((B[0][0] * B[1][0]))
if __name__ == "__main__":
main()
| false | 25 |
[
"- l1, l2 = 0, 0",
"- for k, v in list(c.items()):",
"- if k > l1:",
"- if v >= 4:",
"- l1, l2 = k, k",
"- elif 2 <= v <= 3:",
"- l1, l2 = k, l1",
"- else:",
"- pass",
"- elif l2 < k <= l1 and v >= 2:",
"- l2 = k",
"- print((l1 * l2))",
"+ B = sorted(",
"+ [(k, v) for k, v in list(c.items()) if v >= 2], reverse=True, key=lambda x: x[0]",
"+ )",
"+ if len(B) < 2:",
"+ print((0))",
"+ elif B[0][1] >= 4:",
"+ print((B[0][0] ** 2))",
"+ else:",
"+ print((B[0][0] * B[1][0]))"
] | false | 0.094093 | 0.067704 | 1.389762 |
[
"s369891769",
"s666121459"
] |
u863370423
|
p04043
|
python
|
s194922777
|
s029873760
| 22 | 17 | 3,316 | 2,940 |
Accepted
|
Accepted
| 22.73 |
arr = list(map(int,input().split()))
b = [0]*10
for i in arr:
b[i-1] += 1
if (b[4]==2 and b[6]==1):
print("YES")
else:
print("NO")
|
a, b, c = list(map(int, input().split()))
if a==5 and b==5 and c==7 or a==5 and b==7 and c==5 or a==7 and b==5 and c==5:
print('YES')
else:
print('NO')
| 12 | 5 | 158 | 157 |
arr = list(map(int, input().split()))
b = [0] * 10
for i in arr:
b[i - 1] += 1
if b[4] == 2 and b[6] == 1:
print("YES")
else:
print("NO")
|
a, b, c = list(map(int, input().split()))
if (
a == 5
and b == 5
and c == 7
or a == 5
and b == 7
and c == 5
or a == 7
and b == 5
and c == 5
):
print("YES")
else:
print("NO")
| false | 58.333333 |
[
"-arr = list(map(int, input().split()))",
"-b = [0] * 10",
"-for i in arr:",
"- b[i - 1] += 1",
"-if b[4] == 2 and b[6] == 1:",
"+a, b, c = list(map(int, input().split()))",
"+if (",
"+ a == 5",
"+ and b == 5",
"+ and c == 7",
"+ or a == 5",
"+ and b == 7",
"+ and c == 5",
"+ or a == 7",
"+ and b == 5",
"+ and c == 5",
"+):"
] | false | 0.032503 | 0.032078 | 1.013241 |
[
"s194922777",
"s029873760"
] |
u761320129
|
p02792
|
python
|
s631376678
|
s397776675
| 197 | 139 | 3,064 | 9,200 |
Accepted
|
Accepted
| 29.44 |
N = int(eval(input()))
c = [[0]*10 for _ in range(10)]
for n in range(1,N+1):
s = str(n)
c[int(s[0])][int(s[-1])] += 1
ans = 0
for i in range(10):
for j in range(10):
ans += c[i][j] * c[j][i]
print(ans)
|
N = int(eval(input()))
dp = [[0]*10 for _ in range(10)]
for n in range(1,N+1):
s = str(n)
dp[int(s[0])][int(s[-1])] += 1
ans = 0
for i in range(10):
for j in range(10):
ans += dp[i][j] * dp[j][i]
print(ans)
| 12 | 13 | 229 | 235 |
N = int(eval(input()))
c = [[0] * 10 for _ in range(10)]
for n in range(1, N + 1):
s = str(n)
c[int(s[0])][int(s[-1])] += 1
ans = 0
for i in range(10):
for j in range(10):
ans += c[i][j] * c[j][i]
print(ans)
|
N = int(eval(input()))
dp = [[0] * 10 for _ in range(10)]
for n in range(1, N + 1):
s = str(n)
dp[int(s[0])][int(s[-1])] += 1
ans = 0
for i in range(10):
for j in range(10):
ans += dp[i][j] * dp[j][i]
print(ans)
| false | 7.692308 |
[
"-c = [[0] * 10 for _ in range(10)]",
"+dp = [[0] * 10 for _ in range(10)]",
"- c[int(s[0])][int(s[-1])] += 1",
"+ dp[int(s[0])][int(s[-1])] += 1",
"- ans += c[i][j] * c[j][i]",
"+ ans += dp[i][j] * dp[j][i]"
] | false | 0.187579 | 0.067695 | 2.770931 |
[
"s631376678",
"s397776675"
] |
u315078622
|
p02916
|
python
|
s846375234
|
s188739412
| 174 | 26 | 38,384 | 9,020 |
Accepted
|
Accepted
| 85.06 |
N = int(eval(input()))
A = [int(x)-1 for x in input().split()]
B = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]
ans = 0
for i, a in enumerate(A):
ans += B[a]
if i < N-1 and a + 1 == A[i+1]:
ans += C[a]
print(ans)
|
def main() -> None:
N = int(eval(input()))
A = [int(x)-1 for x in input().split()]
B = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]
ans = sum(B[a] for a in A)
for a1, a2 in zip(A, A[1:]):
if a1 + 1 == a2:
ans += C[a1]
print(ans)
if __name__ == '__main__':
main()
| 10 | 14 | 259 | 351 |
N = int(eval(input()))
A = [int(x) - 1 for x in input().split()]
B = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]
ans = 0
for i, a in enumerate(A):
ans += B[a]
if i < N - 1 and a + 1 == A[i + 1]:
ans += C[a]
print(ans)
|
def main() -> None:
N = int(eval(input()))
A = [int(x) - 1 for x in input().split()]
B = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]
ans = sum(B[a] for a in A)
for a1, a2 in zip(A, A[1:]):
if a1 + 1 == a2:
ans += C[a1]
print(ans)
if __name__ == "__main__":
main()
| false | 28.571429 |
[
"-N = int(eval(input()))",
"-A = [int(x) - 1 for x in input().split()]",
"-B = [int(x) for x in input().split()]",
"-C = [int(x) for x in input().split()]",
"-ans = 0",
"-for i, a in enumerate(A):",
"- ans += B[a]",
"- if i < N - 1 and a + 1 == A[i + 1]:",
"- ans += C[a]",
"-print(ans)",
"+def main() -> None:",
"+ N = int(eval(input()))",
"+ A = [int(x) - 1 for x in input().split()]",
"+ B = [int(x) for x in input().split()]",
"+ C = [int(x) for x in input().split()]",
"+ ans = sum(B[a] for a in A)",
"+ for a1, a2 in zip(A, A[1:]):",
"+ if a1 + 1 == a2:",
"+ ans += C[a1]",
"+ print(ans)",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.039826 | 0.040444 | 0.98471 |
[
"s846375234",
"s188739412"
] |
u445624660
|
p03472
|
python
|
s110344493
|
s058029356
| 361 | 317 | 8,652 | 30,044 |
Accepted
|
Accepted
| 12.19 |
# ai<=biなので基本的にbiが強い。最強のaiより弱いbiは使う必要がない
# 順番は関係ないので選びぬかれたbiを強いほうか使っていって、倒せなかったら最強のaiをHがなくなるまで使う
# これだとPypyでギリギリ間に合わん...
n, h = list(map(int, input().split()))
a, b = 0, []
for _ in range(n):
ai, bi = list(map(int, input().split()))
a = max(a, ai)
b.append(bi)
b = list(sorted(b))
l, r = 0, n
while r-l > 0:
mid = (l + r) // 2
if b[mid] >= a:
r = mid
else:
l = mid + 1
b = b[r:][::-1]
count = 0
for bi in b:
h -= bi
count += 1
if h <= 0:
break
if h > 0:
count += h // a if h % a == 0 else h // a + 1
print(count)
|
# Bを一回使えると考えると
# - Ai>BiであるBiを使う意味はない(Aiで殴ればいいので)
# - Ai>AjであるAjを使う意味はない(Aiで殴ればいいので)
# つまりA中最強のAiより上(i=j自身を含む)のBjを1度使い、あとはAiで殴る
n, h = list(map(int, input().split()))
power = [list(map(int, input().split())) for _ in range(n)]
maxa = sorted(power, key=lambda x : x[0], reverse=True)[0][0]
muscleb = sorted(list([x for x in power if x[1] >= maxa]), key = lambda x : x[1], reverse=True)
ans = 0
for m in muscleb:
ans += 1
h -= m[1]
if h <= 0:
print(ans)
exit()
additionala = h // maxa
if h % maxa != 0:
additionala += 1
print((additionala + ans))
| 31 | 19 | 599 | 591 |
# ai<=biなので基本的にbiが強い。最強のaiより弱いbiは使う必要がない
# 順番は関係ないので選びぬかれたbiを強いほうか使っていって、倒せなかったら最強のaiをHがなくなるまで使う
# これだとPypyでギリギリ間に合わん...
n, h = list(map(int, input().split()))
a, b = 0, []
for _ in range(n):
ai, bi = list(map(int, input().split()))
a = max(a, ai)
b.append(bi)
b = list(sorted(b))
l, r = 0, n
while r - l > 0:
mid = (l + r) // 2
if b[mid] >= a:
r = mid
else:
l = mid + 1
b = b[r:][::-1]
count = 0
for bi in b:
h -= bi
count += 1
if h <= 0:
break
if h > 0:
count += h // a if h % a == 0 else h // a + 1
print(count)
|
# Bを一回使えると考えると
# - Ai>BiであるBiを使う意味はない(Aiで殴ればいいので)
# - Ai>AjであるAjを使う意味はない(Aiで殴ればいいので)
# つまりA中最強のAiより上(i=j自身を含む)のBjを1度使い、あとはAiで殴る
n, h = list(map(int, input().split()))
power = [list(map(int, input().split())) for _ in range(n)]
maxa = sorted(power, key=lambda x: x[0], reverse=True)[0][0]
muscleb = sorted(
list([x for x in power if x[1] >= maxa]), key=lambda x: x[1], reverse=True
)
ans = 0
for m in muscleb:
ans += 1
h -= m[1]
if h <= 0:
print(ans)
exit()
additionala = h // maxa
if h % maxa != 0:
additionala += 1
print((additionala + ans))
| false | 38.709677 |
[
"-# ai<=biなので基本的にbiが強い。最強のaiより弱いbiは使う必要がない",
"-# 順番は関係ないので選びぬかれたbiを強いほうか使っていって、倒せなかったら最強のaiをHがなくなるまで使う",
"-# これだとPypyでギリギリ間に合わん...",
"+# Bを一回使えると考えると",
"+# - Ai>BiであるBiを使う意味はない(Aiで殴ればいいので)",
"+# - Ai>AjであるAjを使う意味はない(Aiで殴ればいいので)",
"+# つまりA中最強のAiより上(i=j自身を含む)のBjを1度使い、あとはAiで殴る",
"-a, b = 0, []",
"-for _ in range(n):",
"- ai, bi = list(map(int, input().split()))",
"- a = max(a, ai)",
"- b.append(bi)",
"-b = list(sorted(b))",
"-l, r = 0, n",
"-while r - l > 0:",
"- mid = (l + r) // 2",
"- if b[mid] >= a:",
"- r = mid",
"- else:",
"- l = mid + 1",
"-b = b[r:][::-1]",
"-count = 0",
"-for bi in b:",
"- h -= bi",
"- count += 1",
"+power = [list(map(int, input().split())) for _ in range(n)]",
"+maxa = sorted(power, key=lambda x: x[0], reverse=True)[0][0]",
"+muscleb = sorted(",
"+ list([x for x in power if x[1] >= maxa]), key=lambda x: x[1], reverse=True",
"+)",
"+ans = 0",
"+for m in muscleb:",
"+ ans += 1",
"+ h -= m[1]",
"- break",
"-if h > 0:",
"- count += h // a if h % a == 0 else h // a + 1",
"-print(count)",
"+ print(ans)",
"+ exit()",
"+additionala = h // maxa",
"+if h % maxa != 0:",
"+ additionala += 1",
"+print((additionala + ans))"
] | false | 0.041943 | 0.043183 | 0.971292 |
[
"s110344493",
"s058029356"
] |
u811967730
|
p02996
|
python
|
s007142067
|
s121471383
| 938 | 834 | 53,600 | 55,264 |
Accepted
|
Accepted
| 11.09 |
N = int(eval(input()))
task = [list(map(int, input().split())) for _ in range(N)]
task.sort(key=lambda x: x[1])
t = 0
ans = "Yes"
for i in range(N):
a = task[i][0]
b = task[i][1]
t += a
if t > b:
ans = "No"
break
print(ans)
|
N = int(eval(input()))
task = [list(map(int, input().split())) for _ in range(N)]
t = 0
ans = "Yes"
for a, b in sorted(task, key=lambda x: x[1]):
t += a
if t > b:
ans = "No"
break
print(ans)
| 17 | 13 | 270 | 224 |
N = int(eval(input()))
task = [list(map(int, input().split())) for _ in range(N)]
task.sort(key=lambda x: x[1])
t = 0
ans = "Yes"
for i in range(N):
a = task[i][0]
b = task[i][1]
t += a
if t > b:
ans = "No"
break
print(ans)
|
N = int(eval(input()))
task = [list(map(int, input().split())) for _ in range(N)]
t = 0
ans = "Yes"
for a, b in sorted(task, key=lambda x: x[1]):
t += a
if t > b:
ans = "No"
break
print(ans)
| false | 23.529412 |
[
"-task.sort(key=lambda x: x[1])",
"-for i in range(N):",
"- a = task[i][0]",
"- b = task[i][1]",
"+for a, b in sorted(task, key=lambda x: x[1]):"
] | false | 0.032001 | 0.0407 | 0.786265 |
[
"s007142067",
"s121471383"
] |
u254871849
|
p03126
|
python
|
s023898945
|
s007640132
| 20 | 18 | 3,188 | 3,060 |
Accepted
|
Accepted
| 10 |
# 2019-11-12 15:53:47(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# from scipy.misc import comb # float
# import numpy as np
def main():
nm, *lines = sys.stdin.readlines()
n, m = [int(x) for x in nm.split()]
likes = [[int(x) for x in line.split()] for line in lines]
menu = set(range(1, m+1))
res = menu
for i in range(n):
res &= set(likes[i][1:])
print((len(res)))
if __name__ == "__main__":
main()
|
import sys
n, m = list(map(int, sys.stdin.readline().split()))
g = [[int(x) for x in sys.stdin.readline().split()[1:]] for _ in range(n)]
def main():
res = set(range(1, m+1))
for a in g:
res &= set(a)
return len(res)
if __name__ == '__main__':
ans = main()
print(ans)
| 25 | 15 | 676 | 311 |
# 2019-11-12 15:53:47(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# from scipy.misc import comb # float
# import numpy as np
def main():
nm, *lines = sys.stdin.readlines()
n, m = [int(x) for x in nm.split()]
likes = [[int(x) for x in line.split()] for line in lines]
menu = set(range(1, m + 1))
res = menu
for i in range(n):
res &= set(likes[i][1:])
print((len(res)))
if __name__ == "__main__":
main()
|
import sys
n, m = list(map(int, sys.stdin.readline().split()))
g = [[int(x) for x in sys.stdin.readline().split()[1:]] for _ in range(n)]
def main():
res = set(range(1, m + 1))
for a in g:
res &= set(a)
return len(res)
if __name__ == "__main__":
ans = main()
print(ans)
| false | 40 |
[
"-# 2019-11-12 15:53:47(JST)",
"-# import collections",
"-# import math",
"-# from string import ascii_lowercase, ascii_uppercase, digits",
"-# from bisect import bisect_left as bi_l, bisect_right as bi_r",
"-# import itertools",
"-# from functools import reduce",
"-# import operator as op",
"-# from scipy.misc import comb # float",
"-# import numpy as np",
"+n, m = list(map(int, sys.stdin.readline().split()))",
"+g = [[int(x) for x in sys.stdin.readline().split()[1:]] for _ in range(n)]",
"+",
"+",
"- nm, *lines = sys.stdin.readlines()",
"- n, m = [int(x) for x in nm.split()]",
"- likes = [[int(x) for x in line.split()] for line in lines]",
"- menu = set(range(1, m + 1))",
"- res = menu",
"- for i in range(n):",
"- res &= set(likes[i][1:])",
"- print((len(res)))",
"+ res = set(range(1, m + 1))",
"+ for a in g:",
"+ res &= set(a)",
"+ return len(res)",
"- main()",
"+ ans = main()",
"+ print(ans)"
] | false | 0.043529 | 0.045169 | 0.963707 |
[
"s023898945",
"s007640132"
] |
u172035535
|
p03073
|
python
|
s227083972
|
s679341321
| 46 | 18 | 3,188 | 3,188 |
Accepted
|
Accepted
| 60.87 |
S = eval(input())
ans0 = 0
ans1 = 0
for i in range(len(S)):
if i%2 == 0:
if S[i] == '0':
ans1 += 1
else:
ans0 += 1
else:
if S[i] == '1':
ans1 += 1
else:
ans0 += 1
print((min(ans0,ans1)))
|
S = eval(input())
a = S[::2]
b = S[1::2]
A = a.count('0')+b.count('1')
print((min(A,len(S)-A)))
| 15 | 5 | 280 | 91 |
S = eval(input())
ans0 = 0
ans1 = 0
for i in range(len(S)):
if i % 2 == 0:
if S[i] == "0":
ans1 += 1
else:
ans0 += 1
else:
if S[i] == "1":
ans1 += 1
else:
ans0 += 1
print((min(ans0, ans1)))
|
S = eval(input())
a = S[::2]
b = S[1::2]
A = a.count("0") + b.count("1")
print((min(A, len(S) - A)))
| false | 66.666667 |
[
"-ans0 = 0",
"-ans1 = 0",
"-for i in range(len(S)):",
"- if i % 2 == 0:",
"- if S[i] == \"0\":",
"- ans1 += 1",
"- else:",
"- ans0 += 1",
"- else:",
"- if S[i] == \"1\":",
"- ans1 += 1",
"- else:",
"- ans0 += 1",
"-print((min(ans0, ans1)))",
"+a = S[::2]",
"+b = S[1::2]",
"+A = a.count(\"0\") + b.count(\"1\")",
"+print((min(A, len(S) - A)))"
] | false | 0.056276 | 0.032804 | 1.715518 |
[
"s227083972",
"s679341321"
] |
u681444474
|
p02853
|
python
|
s006761805
|
s637297214
| 202 | 19 | 38,256 | 3,064 |
Accepted
|
Accepted
| 90.59 |
X = list(map(int,input().split()))
c=100000
b=200000
a=300000
X.sort()
ans=0
cnt=0
for i in X:
if i==1:
ans+=a
cnt+=1
elif i==2:
ans+=b
elif i==3:
ans+=c
if cnt==2:
ans += 400000
print(ans)
|
# coding: utf-8
x, y = list(map(int,input().split()))
l1 = [1,2,3]
l2 = [300000,200000,100000]
ans = 0
if x in l1:
ans += l2[l1.index(x)]
if y in l1:
ans += l2[l1.index(y)]
if x == 1 and y == 1:
ans += 400000
print(ans)
| 18 | 18 | 254 | 252 |
X = list(map(int, input().split()))
c = 100000
b = 200000
a = 300000
X.sort()
ans = 0
cnt = 0
for i in X:
if i == 1:
ans += a
cnt += 1
elif i == 2:
ans += b
elif i == 3:
ans += c
if cnt == 2:
ans += 400000
print(ans)
|
# coding: utf-8
x, y = list(map(int, input().split()))
l1 = [1, 2, 3]
l2 = [300000, 200000, 100000]
ans = 0
if x in l1:
ans += l2[l1.index(x)]
if y in l1:
ans += l2[l1.index(y)]
if x == 1 and y == 1:
ans += 400000
print(ans)
| false | 0 |
[
"-X = list(map(int, input().split()))",
"-c = 100000",
"-b = 200000",
"-a = 300000",
"-X.sort()",
"+# coding: utf-8",
"+x, y = list(map(int, input().split()))",
"+l1 = [1, 2, 3]",
"+l2 = [300000, 200000, 100000]",
"-cnt = 0",
"-for i in X:",
"- if i == 1:",
"- ans += a",
"- cnt += 1",
"- elif i == 2:",
"- ans += b",
"- elif i == 3:",
"- ans += c",
"-if cnt == 2:",
"+if x in l1:",
"+ ans += l2[l1.index(x)]",
"+if y in l1:",
"+ ans += l2[l1.index(y)]",
"+if x == 1 and y == 1:"
] | false | 0.038902 | 0.04314 | 0.901775 |
[
"s006761805",
"s637297214"
] |
u141610915
|
p03112
|
python
|
s403345211
|
s517876048
| 1,696 | 583 | 14,848 | 95,784 |
Accepted
|
Accepted
| 65.62 |
from bisect import bisect_left as bl
A, B, Q = list(map(int, input().split()))
inf = 10 ** 11
Sh = [-1 * inf] + [int(eval(input())) for _ in range(A)] + [inf]
Te = [-1 * inf] + [int(eval(input())) for _ in range(B)] + [inf]
for _ in range(Q):
x = int(eval(input()))
b, d = bl(Sh, x), bl(Te, x)
res = inf
for S in [Sh[b - 1], Sh[b]]:
for T in [Te[d - 1], Te[d]]:
d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)
res = min(res, d1, d2)
print(res)
|
import sys
from bisect import bisect_left as bl
input = sys.stdin.readline
A, B, Q = list(map(int, input().split()))
a = [-10 ** 18] + [int(eval(input())) for _ in range(A)] + [10 ** 18]
b = [-10 ** 18] + [int(eval(input())) for _ in range(B)] + [10 ** 18]
for _ in range(Q):
x = int(eval(input()))
ra = bl(a, x)
rb = bl(b, x)
la = ra - 1
lb = rb - 1
res = 10 ** 18
res = min(res, max(abs(a[ra] - x), abs(b[rb] - x)))
res = min(res, max(abs(a[la] - x), abs(b[lb] - x)))
res = min(res, max(abs(a[la] - x), abs(b[rb] - x)) + min(abs(a[la] - x), abs(b[rb] - x)) * 2)
res = min(res, max(abs(a[ra] - x), abs(b[lb] - x)) + min(abs(a[ra] - x), abs(b[lb] - x)) * 2)
print(res)
| 14 | 18 | 468 | 683 |
from bisect import bisect_left as bl
A, B, Q = list(map(int, input().split()))
inf = 10**11
Sh = [-1 * inf] + [int(eval(input())) for _ in range(A)] + [inf]
Te = [-1 * inf] + [int(eval(input())) for _ in range(B)] + [inf]
for _ in range(Q):
x = int(eval(input()))
b, d = bl(Sh, x), bl(Te, x)
res = inf
for S in [Sh[b - 1], Sh[b]]:
for T in [Te[d - 1], Te[d]]:
d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)
res = min(res, d1, d2)
print(res)
|
import sys
from bisect import bisect_left as bl
input = sys.stdin.readline
A, B, Q = list(map(int, input().split()))
a = [-(10**18)] + [int(eval(input())) for _ in range(A)] + [10**18]
b = [-(10**18)] + [int(eval(input())) for _ in range(B)] + [10**18]
for _ in range(Q):
x = int(eval(input()))
ra = bl(a, x)
rb = bl(b, x)
la = ra - 1
lb = rb - 1
res = 10**18
res = min(res, max(abs(a[ra] - x), abs(b[rb] - x)))
res = min(res, max(abs(a[la] - x), abs(b[lb] - x)))
res = min(
res,
max(abs(a[la] - x), abs(b[rb] - x)) + min(abs(a[la] - x), abs(b[rb] - x)) * 2,
)
res = min(
res,
max(abs(a[ra] - x), abs(b[lb] - x)) + min(abs(a[ra] - x), abs(b[lb] - x)) * 2,
)
print(res)
| false | 22.222222 |
[
"+import sys",
"+input = sys.stdin.readline",
"-inf = 10**11",
"-Sh = [-1 * inf] + [int(eval(input())) for _ in range(A)] + [inf]",
"-Te = [-1 * inf] + [int(eval(input())) for _ in range(B)] + [inf]",
"+a = [-(10**18)] + [int(eval(input())) for _ in range(A)] + [10**18]",
"+b = [-(10**18)] + [int(eval(input())) for _ in range(B)] + [10**18]",
"- b, d = bl(Sh, x), bl(Te, x)",
"- res = inf",
"- for S in [Sh[b - 1], Sh[b]]:",
"- for T in [Te[d - 1], Te[d]]:",
"- d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)",
"- res = min(res, d1, d2)",
"+ ra = bl(a, x)",
"+ rb = bl(b, x)",
"+ la = ra - 1",
"+ lb = rb - 1",
"+ res = 10**18",
"+ res = min(res, max(abs(a[ra] - x), abs(b[rb] - x)))",
"+ res = min(res, max(abs(a[la] - x), abs(b[lb] - x)))",
"+ res = min(",
"+ res,",
"+ max(abs(a[la] - x), abs(b[rb] - x)) + min(abs(a[la] - x), abs(b[rb] - x)) * 2,",
"+ )",
"+ res = min(",
"+ res,",
"+ max(abs(a[ra] - x), abs(b[lb] - x)) + min(abs(a[ra] - x), abs(b[lb] - x)) * 2,",
"+ )"
] | false | 0.039516 | 0.047715 | 0.828184 |
[
"s403345211",
"s517876048"
] |
u423585790
|
p02696
|
python
|
s327712665
|
s447495422
| 669 | 60 | 76,768 | 62,004 |
Accepted
|
Accepted
| 91.03 |
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list([int(x)-1 for x in input().split()])
def II(): return int(eval(input()))
def IF(): return float(eval(input()))
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float("INF")
#solve
def solve():
a, b, n = LI()
print((min(b - 1, n) * a // b))
return
#main
if __name__ == '__main__':
solve()
|
a,b,n=list(map(int,input().split()))
def f(x):
return a*x//b-a*(x//b)
if n<b:
ans =f(n)
else:
t = n
u = b - 1
ans=max(f(t),f(u))
print(ans)
| 35 | 10 | 1,052 | 163 |
#!/usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI():
return list(map(int, input().split()))
def LF():
return list(map(float, input().split()))
def LI_():
return list([int(x) - 1 for x in input().split()])
def II():
return int(eval(input()))
def IF():
return float(eval(input()))
def S():
return input().rstrip()
def LS():
return S().split()
def IR(n):
return [II() for _ in range(n)]
def LIR(n):
return [LI() for _ in range(n)]
def FR(n):
return [IF() for _ in range(n)]
def LFR(n):
return [LI() for _ in range(n)]
def LIR_(n):
return [LI_() for _ in range(n)]
def SR(n):
return [S() for _ in range(n)]
def LSR(n):
return [LS() for _ in range(n)]
mod = 1000000007
inf = float("INF")
# solve
def solve():
a, b, n = LI()
print((min(b - 1, n) * a // b))
return
# main
if __name__ == "__main__":
solve()
|
a, b, n = list(map(int, input().split()))
def f(x):
return a * x // b - a * (x // b)
if n < b:
ans = f(n)
else:
t = n
u = b - 1
ans = max(f(t), f(u))
print(ans)
| false | 71.428571 |
[
"-#!/usr/bin/env python3",
"-from collections import defaultdict, deque",
"-from heapq import heappush, heappop",
"-from bisect import bisect_left, bisect_right",
"-import sys, random, itertools, math",
"-",
"-sys.setrecursionlimit(10**5)",
"-input = sys.stdin.readline",
"-sqrt = math.sqrt",
"+a, b, n = list(map(int, input().split()))",
"-def LI():",
"- return list(map(int, input().split()))",
"+def f(x):",
"+ return a * x // b - a * (x // b)",
"-def LF():",
"- return list(map(float, input().split()))",
"-",
"-",
"-def LI_():",
"- return list([int(x) - 1 for x in input().split()])",
"-",
"-",
"-def II():",
"- return int(eval(input()))",
"-",
"-",
"-def IF():",
"- return float(eval(input()))",
"-",
"-",
"-def S():",
"- return input().rstrip()",
"-",
"-",
"-def LS():",
"- return S().split()",
"-",
"-",
"-def IR(n):",
"- return [II() for _ in range(n)]",
"-",
"-",
"-def LIR(n):",
"- return [LI() for _ in range(n)]",
"-",
"-",
"-def FR(n):",
"- return [IF() for _ in range(n)]",
"-",
"-",
"-def LFR(n):",
"- return [LI() for _ in range(n)]",
"-",
"-",
"-def LIR_(n):",
"- return [LI_() for _ in range(n)]",
"-",
"-",
"-def SR(n):",
"- return [S() for _ in range(n)]",
"-",
"-",
"-def LSR(n):",
"- return [LS() for _ in range(n)]",
"-",
"-",
"-mod = 1000000007",
"-inf = float(\"INF\")",
"-# solve",
"-def solve():",
"- a, b, n = LI()",
"- print((min(b - 1, n) * a // b))",
"- return",
"-",
"-",
"-# main",
"-if __name__ == \"__main__\":",
"- solve()",
"+if n < b:",
"+ ans = f(n)",
"+else:",
"+ t = n",
"+ u = b - 1",
"+ ans = max(f(t), f(u))",
"+print(ans)"
] | false | 0.038572 | 0.035717 | 1.079915 |
[
"s327712665",
"s447495422"
] |
u775681539
|
p02708
|
python
|
s005209827
|
s448153178
| 119 | 69 | 27,184 | 83,520 |
Accepted
|
Accepted
| 42.02 |
MOD = int(1e9)+7
def main():
n, k = list(map(int, input().split()))
n += 1
a = [int(i) for i in range(n)]
s = [0]
for i in range(n):
s.append(s[i]+a[i])
ans = 0
for i in range(k, n+1):
ans += s[n]-s[n-i]-s[i]+1
ans %= MOD
print((ans%MOD))
main()
|
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def main():
N, K = list(map(int, readline().split()))
p = [int(i) for i in range(N+1)]
s = [0]
for i in range(N+1):
s.append(s[i]+p[i])
ans = 0
P = int(1e9)+7
for k in range(K, N+2):
ans += (s[-1]-s[-k-1])-(s[k]-s[0])+1
ans %= P
print(ans)
if __name__ == '__main__':
main()
| 15 | 19 | 309 | 463 |
MOD = int(1e9) + 7
def main():
n, k = list(map(int, input().split()))
n += 1
a = [int(i) for i in range(n)]
s = [0]
for i in range(n):
s.append(s[i] + a[i])
ans = 0
for i in range(k, n + 1):
ans += s[n] - s[n - i] - s[i] + 1
ans %= MOD
print((ans % MOD))
main()
|
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def main():
N, K = list(map(int, readline().split()))
p = [int(i) for i in range(N + 1)]
s = [0]
for i in range(N + 1):
s.append(s[i] + p[i])
ans = 0
P = int(1e9) + 7
for k in range(K, N + 2):
ans += (s[-1] - s[-k - 1]) - (s[k] - s[0]) + 1
ans %= P
print(ans)
if __name__ == "__main__":
main()
| false | 21.052632 |
[
"-MOD = int(1e9) + 7",
"+import sys",
"+",
"+read = sys.stdin.buffer.read",
"+readline = sys.stdin.buffer.readline",
"+readlines = sys.stdin.buffer.readlines",
"- n, k = list(map(int, input().split()))",
"- n += 1",
"- a = [int(i) for i in range(n)]",
"+ N, K = list(map(int, readline().split()))",
"+ p = [int(i) for i in range(N + 1)]",
"- for i in range(n):",
"- s.append(s[i] + a[i])",
"+ for i in range(N + 1):",
"+ s.append(s[i] + p[i])",
"- for i in range(k, n + 1):",
"- ans += s[n] - s[n - i] - s[i] + 1",
"- ans %= MOD",
"- print((ans % MOD))",
"+ P = int(1e9) + 7",
"+ for k in range(K, N + 2):",
"+ ans += (s[-1] - s[-k - 1]) - (s[k] - s[0]) + 1",
"+ ans %= P",
"+ print(ans)",
"-main()",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.157915 | 0.107203 | 1.473047 |
[
"s005209827",
"s448153178"
] |
u263830634
|
p03557
|
python
|
s171111113
|
s560060179
| 616 | 559 | 23,360 | 23,360 |
Accepted
|
Accepted
| 9.25 |
from bisect import bisect_left, bisect_right
N = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
C.sort()
ans = 0
#Bの中の数iに対して、Aの中でiより小さい数の個数と、Cの中でiより大きい数の個数の積を探索
for i in B:
ans += bisect_right(A, i-0.1) * (N-bisect_left(C, i+0.1))
print (ans)
|
import bisect
N = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
B.sort()
C.sort()
# print (A, B ,C)
ans = 0
for i in B:
# print (i)
# print (bisect.bisect_left(A, i-0.1))
ans += bisect.bisect_left(A, i-0.1) * (N-bisect.bisect_right(C, i+0.1))
print (ans)
| 16 | 18 | 349 | 370 |
from bisect import bisect_left, bisect_right
N = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
C.sort()
ans = 0
# Bの中の数iに対して、Aの中でiより小さい数の個数と、Cの中でiより大きい数の個数の積を探索
for i in B:
ans += bisect_right(A, i - 0.1) * (N - bisect_left(C, i + 0.1))
print(ans)
|
import bisect
N = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
B.sort()
C.sort()
# print (A, B ,C)
ans = 0
for i in B:
# print (i)
# print (bisect.bisect_left(A, i-0.1))
ans += bisect.bisect_left(A, i - 0.1) * (N - bisect.bisect_right(C, i + 0.1))
print(ans)
| false | 11.111111 |
[
"-from bisect import bisect_left, bisect_right",
"+import bisect",
"+B.sort()",
"+# print (A, B ,C)",
"-# Bの中の数iに対して、Aの中でiより小さい数の個数と、Cの中でiより大きい数の個数の積を探索",
"- ans += bisect_right(A, i - 0.1) * (N - bisect_left(C, i + 0.1))",
"+ # print (i)",
"+ # print (bisect.bisect_left(A, i-0.1))",
"+ ans += bisect.bisect_left(A, i - 0.1) * (N - bisect.bisect_right(C, i + 0.1))"
] | false | 0.04971 | 0.049499 | 1.004258 |
[
"s171111113",
"s560060179"
] |
u549161102
|
p02689
|
python
|
s264021006
|
s951067687
| 307 | 254 | 31,964 | 20,068 |
Accepted
|
Accepted
| 17.26 |
N,M = list(map(int, input().split()))
H = list(map(int, input().split()))
AB = [list(map(int, input().split())) for i in range(M)]
counts = [1]*N
for i in AB:
if H[i[0]-1] <= H[i[1]-1]:
counts[i[0]-1] -= 1
if H[i[0]-1] >= H[i[1]-1]:
counts[i[1]-1] -= 1
print((counts.count(1)))
|
N,M = list(map(int, input().split()))
H = list(map(int, input().split()))
L = []
for i in range(M):
a, b = list(map(int, input().split()))
if H[a-1] > H[b-1]:
L.append(b-1)
elif H[a-1] < H[b-1]:
L.append(a-1)
else:
L.append(a-1)
L.append(b-1)
print((N - len(set(L))))
| 11 | 13 | 292 | 290 |
N, M = list(map(int, input().split()))
H = list(map(int, input().split()))
AB = [list(map(int, input().split())) for i in range(M)]
counts = [1] * N
for i in AB:
if H[i[0] - 1] <= H[i[1] - 1]:
counts[i[0] - 1] -= 1
if H[i[0] - 1] >= H[i[1] - 1]:
counts[i[1] - 1] -= 1
print((counts.count(1)))
|
N, M = list(map(int, input().split()))
H = list(map(int, input().split()))
L = []
for i in range(M):
a, b = list(map(int, input().split()))
if H[a - 1] > H[b - 1]:
L.append(b - 1)
elif H[a - 1] < H[b - 1]:
L.append(a - 1)
else:
L.append(a - 1)
L.append(b - 1)
print((N - len(set(L))))
| false | 15.384615 |
[
"-AB = [list(map(int, input().split())) for i in range(M)]",
"-counts = [1] * N",
"-for i in AB:",
"- if H[i[0] - 1] <= H[i[1] - 1]:",
"- counts[i[0] - 1] -= 1",
"- if H[i[0] - 1] >= H[i[1] - 1]:",
"- counts[i[1] - 1] -= 1",
"-print((counts.count(1)))",
"+L = []",
"+for i in range(M):",
"+ a, b = list(map(int, input().split()))",
"+ if H[a - 1] > H[b - 1]:",
"+ L.append(b - 1)",
"+ elif H[a - 1] < H[b - 1]:",
"+ L.append(a - 1)",
"+ else:",
"+ L.append(a - 1)",
"+ L.append(b - 1)",
"+print((N - len(set(L))))"
] | false | 0.036947 | 0.072808 | 0.507456 |
[
"s264021006",
"s951067687"
] |
u935558307
|
p03565
|
python
|
s504379369
|
s431550527
| 20 | 17 | 3,188 | 3,064 |
Accepted
|
Accepted
| 15 |
import sys
s = eval(input())
t = eval(input())
for i in range(len(s)-len(t)+1):
if i == 0:
sub = s[-i-len(t):]
else:
sub = s[-i-len(t):-i]
for j in range(len(t)):
if sub[j]!=t[j] and sub[j]!="?":
break
else:
if i == 0:
s = s[:-i-len(t)]+t
else:
s = s[:-i-len(t)]+t+s[-i:]
s = s.replace("?","a")
print(s)
sys.exit()
continue
print("UNRESTORABLE")
|
import sys
s = eval(input())
t = eval(input())
lenS = len(s)
lenT = len(t)
for i in range(lenS-lenT,-1,-1):
sub = s[i:i+lenT]
for j in range(lenT):
if sub[j]!="?" and sub[j]!=t[j]:
break
else:
s=s.replace("?","a")
print((s[:i]+t+s[i+lenT:]))
sys.exit()
continue
print('UNRESTORABLE')
| 24 | 18 | 423 | 320 |
import sys
s = eval(input())
t = eval(input())
for i in range(len(s) - len(t) + 1):
if i == 0:
sub = s[-i - len(t) :]
else:
sub = s[-i - len(t) : -i]
for j in range(len(t)):
if sub[j] != t[j] and sub[j] != "?":
break
else:
if i == 0:
s = s[: -i - len(t)] + t
else:
s = s[: -i - len(t)] + t + s[-i:]
s = s.replace("?", "a")
print(s)
sys.exit()
continue
print("UNRESTORABLE")
|
import sys
s = eval(input())
t = eval(input())
lenS = len(s)
lenT = len(t)
for i in range(lenS - lenT, -1, -1):
sub = s[i : i + lenT]
for j in range(lenT):
if sub[j] != "?" and sub[j] != t[j]:
break
else:
s = s.replace("?", "a")
print((s[:i] + t + s[i + lenT :]))
sys.exit()
continue
print("UNRESTORABLE")
| false | 25 |
[
"-for i in range(len(s) - len(t) + 1):",
"- if i == 0:",
"- sub = s[-i - len(t) :]",
"- else:",
"- sub = s[-i - len(t) : -i]",
"- for j in range(len(t)):",
"- if sub[j] != t[j] and sub[j] != \"?\":",
"+lenS = len(s)",
"+lenT = len(t)",
"+for i in range(lenS - lenT, -1, -1):",
"+ sub = s[i : i + lenT]",
"+ for j in range(lenT):",
"+ if sub[j] != \"?\" and sub[j] != t[j]:",
"- if i == 0:",
"- s = s[: -i - len(t)] + t",
"- else:",
"- s = s[: -i - len(t)] + t + s[-i:]",
"- print(s)",
"+ print((s[:i] + t + s[i + lenT :]))"
] | false | 0.048618 | 0.040604 | 1.197369 |
[
"s504379369",
"s431550527"
] |
u794173881
|
p02787
|
python
|
s424131069
|
s958544159
| 1,812 | 378 | 44,404 | 42,972 |
Accepted
|
Accepted
| 79.14 |
h, n = list(map(int, input().split()))
info = [list(map(int, input().split())) for i in range(n)]
dp = [10**18] * (h + 1 + 10 ** 5)
dp[h + 10 ** 5] = 0
for i in range(n):
a, b = info[i]
for j in range(h + 1 + 10 ** 5)[::-1]:
if j - a >= 0:
dp[j - a] = min(dp[j] + b, dp[j - a])
print((min(dp[0:10**5 + 1])))
|
h, n = list(map(int, input().split()))
info = [list(map(int, input().split())) for i in range(n)]
INF = 10**18
dp = [INF] * (h + 1)
dp[h] = 0
for i in range(n):
a, b = info[i]
for j in range(h + 1)[::-1]:
dp[max(j - a, 0)] = min(dp[j] + b, dp[max(j - a, 0)])
print((dp[0]))
| 11 | 11 | 339 | 297 |
h, n = list(map(int, input().split()))
info = [list(map(int, input().split())) for i in range(n)]
dp = [10**18] * (h + 1 + 10**5)
dp[h + 10**5] = 0
for i in range(n):
a, b = info[i]
for j in range(h + 1 + 10**5)[::-1]:
if j - a >= 0:
dp[j - a] = min(dp[j] + b, dp[j - a])
print((min(dp[0 : 10**5 + 1])))
|
h, n = list(map(int, input().split()))
info = [list(map(int, input().split())) for i in range(n)]
INF = 10**18
dp = [INF] * (h + 1)
dp[h] = 0
for i in range(n):
a, b = info[i]
for j in range(h + 1)[::-1]:
dp[max(j - a, 0)] = min(dp[j] + b, dp[max(j - a, 0)])
print((dp[0]))
| false | 0 |
[
"-dp = [10**18] * (h + 1 + 10**5)",
"-dp[h + 10**5] = 0",
"+INF = 10**18",
"+dp = [INF] * (h + 1)",
"+dp[h] = 0",
"- for j in range(h + 1 + 10**5)[::-1]:",
"- if j - a >= 0:",
"- dp[j - a] = min(dp[j] + b, dp[j - a])",
"-print((min(dp[0 : 10**5 + 1])))",
"+ for j in range(h + 1)[::-1]:",
"+ dp[max(j - a, 0)] = min(dp[j] + b, dp[max(j - a, 0)])",
"+print((dp[0]))"
] | false | 2.018824 | 0.155939 | 12.946249 |
[
"s424131069",
"s958544159"
] |
u836939578
|
p02726
|
python
|
s758111889
|
s234928632
| 1,185 | 484 | 118,492 | 83,036 |
Accepted
|
Accepted
| 59.16 |
import sys
input = lambda: sys.stdin.readline().rstrip()
from collections import deque
N,X,Y = list(map(int, input().split()))
edges = [[] for _ in range(N)]
for i in range(N-1):
edges[i].append(i+1)
edges[i+1].append(i)
edges[X-1].append(Y-1)
edges[Y-1].append(X-1)
ans = [0] * (N-1)
queue = deque([])
def bfs(start):
queue.extend(edges[start])
visited = [False] * N
visited[start] = True
i = 0
while queue:
length = len(queue)
for l in range(length):
current = queue.popleft()
if not visited[current]:
ans[i] += 1
if edges[current]:
queue.extend(edges[current])
visited[current] = True
i += 1
for i in range(N):
bfs(i)
for i in ans:
print((i // 2))
|
import sys
input = lambda: sys.stdin.readline().rstrip()
from collections import deque
N,X,Y = list(map(int, input().split()))
queue = deque()
edges = [[] for _ in range(N)]
for i in range(N-1):
edges[i].append(i+1)
edges[i+1].append(i)
edges[X-1].append(Y-1)
edges[Y-1].append(X-1)
ans = [0] * N
for i in range(N):
visited = [0] * N
visited[i] = 1
queue.append((i,0))
while queue:
current, dist = queue.popleft()
ans[dist] += 1
for e in edges[current]:
if visited[e] != 1:
queue.append((e, dist+1))
visited[e] = 1
ans = ans[1:]
for a in ans:
print((a//2))
| 41 | 35 | 850 | 687 |
import sys
input = lambda: sys.stdin.readline().rstrip()
from collections import deque
N, X, Y = list(map(int, input().split()))
edges = [[] for _ in range(N)]
for i in range(N - 1):
edges[i].append(i + 1)
edges[i + 1].append(i)
edges[X - 1].append(Y - 1)
edges[Y - 1].append(X - 1)
ans = [0] * (N - 1)
queue = deque([])
def bfs(start):
queue.extend(edges[start])
visited = [False] * N
visited[start] = True
i = 0
while queue:
length = len(queue)
for l in range(length):
current = queue.popleft()
if not visited[current]:
ans[i] += 1
if edges[current]:
queue.extend(edges[current])
visited[current] = True
i += 1
for i in range(N):
bfs(i)
for i in ans:
print((i // 2))
|
import sys
input = lambda: sys.stdin.readline().rstrip()
from collections import deque
N, X, Y = list(map(int, input().split()))
queue = deque()
edges = [[] for _ in range(N)]
for i in range(N - 1):
edges[i].append(i + 1)
edges[i + 1].append(i)
edges[X - 1].append(Y - 1)
edges[Y - 1].append(X - 1)
ans = [0] * N
for i in range(N):
visited = [0] * N
visited[i] = 1
queue.append((i, 0))
while queue:
current, dist = queue.popleft()
ans[dist] += 1
for e in edges[current]:
if visited[e] != 1:
queue.append((e, dist + 1))
visited[e] = 1
ans = ans[1:]
for a in ans:
print((a // 2))
| false | 14.634146 |
[
"+queue = deque()",
"-ans = [0] * (N - 1)",
"-queue = deque([])",
"-",
"-",
"-def bfs(start):",
"- queue.extend(edges[start])",
"- visited = [False] * N",
"- visited[start] = True",
"- i = 0",
"+ans = [0] * N",
"+for i in range(N):",
"+ visited = [0] * N",
"+ visited[i] = 1",
"+ queue.append((i, 0))",
"- length = len(queue)",
"- for l in range(length):",
"- current = queue.popleft()",
"- if not visited[current]:",
"- ans[i] += 1",
"- if edges[current]:",
"- queue.extend(edges[current])",
"- visited[current] = True",
"- i += 1",
"-",
"-",
"-for i in range(N):",
"- bfs(i)",
"-for i in ans:",
"- print((i // 2))",
"+ current, dist = queue.popleft()",
"+ ans[dist] += 1",
"+ for e in edges[current]:",
"+ if visited[e] != 1:",
"+ queue.append((e, dist + 1))",
"+ visited[e] = 1",
"+ans = ans[1:]",
"+for a in ans:",
"+ print((a // 2))"
] | false | 0.090418 | 0.090185 | 1.002591 |
[
"s758111889",
"s234928632"
] |
u608088992
|
p03634
|
python
|
s851587897
|
s012991350
| 1,149 | 491 | 52,476 | 53,976 |
Accepted
|
Accepted
| 57.27 |
import heapq
N = int(eval(input()))
P = [[] for i in range(N)]
for i in range(N-1):
a, b, c = list(map(int, input().split()))
P[a-1].append((c, b-1))
P[b-1].append((c, a-1))
Q, K = list(map(int, input().split()))
C = [float("inf") for _ in range(N)]
V = [False for _ in range(N)]
C[K-1] = 0
H = [(0, K-1)]
heapq.heapify(H)
while H:
cost, node = heapq.heappop(H)
V[node] = True
for n in P[node]:
if V[n[1]] == False:
if n[0] + cost < C[n[1]]:
C[n[1]] = n[0] + cost
heapq.heappush(H, (n[0] + cost, n[1]))
Ans = []
for i in range(Q):
x, y = list(map(int, input().split()))
Ans.append(C[x-1]+C[y-1])
for i in range(Q):
print((Ans[i]))
|
import sys
from collections import deque
def solve():
input = sys.stdin.readline
N = int(eval(input()))
Edge = [[] for _ in range(N)]
for _ in range(N-1):
a, b, c = list(map(int, input().split()))
Edge[a-1].append((b-1, c))
Edge[b-1].append((a-1, c))
Q, K = list(map(int, input().split()))
q = deque()
Dist = [-1] * N
q.append((K-1, K-1, 0))
while q:
nowN, preN, nD = q.popleft()
if Dist[nowN] == -1:
Dist[nowN] = nD
for e, add in Edge[nowN]:
if e != preN: q.append((e, nowN, nD + add))
Ans = [None] * Q
for i in range(Q):
x, y = list(map(int, input().split()))
Ans[i] = str(Dist[x-1] + Dist[y-1])
print(("\n".join(Ans)))
return 0
if __name__ == "__main__":
solve()
| 28 | 31 | 721 | 824 |
import heapq
N = int(eval(input()))
P = [[] for i in range(N)]
for i in range(N - 1):
a, b, c = list(map(int, input().split()))
P[a - 1].append((c, b - 1))
P[b - 1].append((c, a - 1))
Q, K = list(map(int, input().split()))
C = [float("inf") for _ in range(N)]
V = [False for _ in range(N)]
C[K - 1] = 0
H = [(0, K - 1)]
heapq.heapify(H)
while H:
cost, node = heapq.heappop(H)
V[node] = True
for n in P[node]:
if V[n[1]] == False:
if n[0] + cost < C[n[1]]:
C[n[1]] = n[0] + cost
heapq.heappush(H, (n[0] + cost, n[1]))
Ans = []
for i in range(Q):
x, y = list(map(int, input().split()))
Ans.append(C[x - 1] + C[y - 1])
for i in range(Q):
print((Ans[i]))
|
import sys
from collections import deque
def solve():
input = sys.stdin.readline
N = int(eval(input()))
Edge = [[] for _ in range(N)]
for _ in range(N - 1):
a, b, c = list(map(int, input().split()))
Edge[a - 1].append((b - 1, c))
Edge[b - 1].append((a - 1, c))
Q, K = list(map(int, input().split()))
q = deque()
Dist = [-1] * N
q.append((K - 1, K - 1, 0))
while q:
nowN, preN, nD = q.popleft()
if Dist[nowN] == -1:
Dist[nowN] = nD
for e, add in Edge[nowN]:
if e != preN:
q.append((e, nowN, nD + add))
Ans = [None] * Q
for i in range(Q):
x, y = list(map(int, input().split()))
Ans[i] = str(Dist[x - 1] + Dist[y - 1])
print(("\n".join(Ans)))
return 0
if __name__ == "__main__":
solve()
| false | 9.677419 |
[
"-import heapq",
"+import sys",
"+from collections import deque",
"-N = int(eval(input()))",
"-P = [[] for i in range(N)]",
"-for i in range(N - 1):",
"- a, b, c = list(map(int, input().split()))",
"- P[a - 1].append((c, b - 1))",
"- P[b - 1].append((c, a - 1))",
"-Q, K = list(map(int, input().split()))",
"-C = [float(\"inf\") for _ in range(N)]",
"-V = [False for _ in range(N)]",
"-C[K - 1] = 0",
"-H = [(0, K - 1)]",
"-heapq.heapify(H)",
"-while H:",
"- cost, node = heapq.heappop(H)",
"- V[node] = True",
"- for n in P[node]:",
"- if V[n[1]] == False:",
"- if n[0] + cost < C[n[1]]:",
"- C[n[1]] = n[0] + cost",
"- heapq.heappush(H, (n[0] + cost, n[1]))",
"-Ans = []",
"-for i in range(Q):",
"- x, y = list(map(int, input().split()))",
"- Ans.append(C[x - 1] + C[y - 1])",
"-for i in range(Q):",
"- print((Ans[i]))",
"+",
"+def solve():",
"+ input = sys.stdin.readline",
"+ N = int(eval(input()))",
"+ Edge = [[] for _ in range(N)]",
"+ for _ in range(N - 1):",
"+ a, b, c = list(map(int, input().split()))",
"+ Edge[a - 1].append((b - 1, c))",
"+ Edge[b - 1].append((a - 1, c))",
"+ Q, K = list(map(int, input().split()))",
"+ q = deque()",
"+ Dist = [-1] * N",
"+ q.append((K - 1, K - 1, 0))",
"+ while q:",
"+ nowN, preN, nD = q.popleft()",
"+ if Dist[nowN] == -1:",
"+ Dist[nowN] = nD",
"+ for e, add in Edge[nowN]:",
"+ if e != preN:",
"+ q.append((e, nowN, nD + add))",
"+ Ans = [None] * Q",
"+ for i in range(Q):",
"+ x, y = list(map(int, input().split()))",
"+ Ans[i] = str(Dist[x - 1] + Dist[y - 1])",
"+ print((\"\\n\".join(Ans)))",
"+ return 0",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ solve()"
] | false | 0.044519 | 0.138098 | 0.322368 |
[
"s851587897",
"s012991350"
] |
u374099594
|
p03280
|
python
|
s872172022
|
s264668325
| 18 | 11 | 3,428 | 2,568 |
Accepted
|
Accepted
| 38.89 |
import subprocess
A,B = list(map(int, subprocess.check_output("dd").split()))
print((A-1)*(B-1))
|
import sys
A,B = list(map(int, sys.stdin.read().split()))
print((A-1)*(B-1))
| 3 | 3 | 92 | 71 |
import subprocess
A, B = list(map(int, subprocess.check_output("dd").split()))
print((A - 1) * (B - 1))
|
import sys
A, B = list(map(int, sys.stdin.read().split()))
print((A - 1) * (B - 1))
| false | 0 |
[
"-import subprocess",
"+import sys",
"-A, B = list(map(int, subprocess.check_output(\"dd\").split()))",
"+A, B = list(map(int, sys.stdin.read().split()))"
] | false | 0.045333 | 0.051501 | 0.880229 |
[
"s872172022",
"s264668325"
] |
u257162238
|
p03363
|
python
|
s945432742
|
s082539541
| 194 | 163 | 41,980 | 54,148 |
Accepted
|
Accepted
| 15.98 |
import sys
input = sys.stdin.readline
from itertools import accumulate
from collections import Counter
def read():
N = int(input().strip())
A = list(map(int, input().strip().split()))
return N, A
def solve(N, A):
S = accumulate(A)
C = Counter(S)
ans = 0
k = 0
for a in A:
ans += C[k]
k += a
C[k] -= 1
return ans
if __name__ == '__main__':
inputs = read()
outputs = solve(*inputs)
if outputs is not None:
print(("%s" % str(outputs)))
|
import sys
input = sys.stdin.readline
from itertools import accumulate
from collections import Counter
def read():
N = int(input().strip())
A = list(map(int, input().strip().split()))
return N, A
def solve(N, A):
S = [0] + list(accumulate(A)) + [10**9+1]
C = Counter(S)
ans = 0
for k, v in C.most_common():
if v >= 2:
ans += v * (v-1) // 2
return ans
if __name__ == '__main__':
inputs = read()
outputs = solve(*inputs)
if outputs is not None:
print(("%s" % str(outputs)))
| 29 | 27 | 545 | 574 |
import sys
input = sys.stdin.readline
from itertools import accumulate
from collections import Counter
def read():
N = int(input().strip())
A = list(map(int, input().strip().split()))
return N, A
def solve(N, A):
S = accumulate(A)
C = Counter(S)
ans = 0
k = 0
for a in A:
ans += C[k]
k += a
C[k] -= 1
return ans
if __name__ == "__main__":
inputs = read()
outputs = solve(*inputs)
if outputs is not None:
print(("%s" % str(outputs)))
|
import sys
input = sys.stdin.readline
from itertools import accumulate
from collections import Counter
def read():
N = int(input().strip())
A = list(map(int, input().strip().split()))
return N, A
def solve(N, A):
S = [0] + list(accumulate(A)) + [10**9 + 1]
C = Counter(S)
ans = 0
for k, v in C.most_common():
if v >= 2:
ans += v * (v - 1) // 2
return ans
if __name__ == "__main__":
inputs = read()
outputs = solve(*inputs)
if outputs is not None:
print(("%s" % str(outputs)))
| false | 6.896552 |
[
"- S = accumulate(A)",
"+ S = [0] + list(accumulate(A)) + [10**9 + 1]",
"- k = 0",
"- for a in A:",
"- ans += C[k]",
"- k += a",
"- C[k] -= 1",
"+ for k, v in C.most_common():",
"+ if v >= 2:",
"+ ans += v * (v - 1) // 2"
] | false | 0.114385 | 0.121489 | 0.941528 |
[
"s945432742",
"s082539541"
] |
u623814058
|
p03341
|
python
|
s600829652
|
s785651975
| 150 | 120 | 9,780 | 9,616 |
Accepted
|
Accepted
| 20 |
N=int(eval(input()))
S=eval(input())
import collections
tw=S.count('W')
te=S.count('E')
ans=float('inf')
cw=[0,0]
ce=[tw,te]
#print(cw,ce)
for i in S:
if i=='W':
ce[0]-=1
ans=min(ans,cw[0]+ce[1])
#print(cw,ce,cw[0]+ce[1])
cw[0]+=1
else:
ce[1]-=1
ans=min(ans,cw[0]+ce[1])
#print(cw,ce,cw[0]+ce[1])
cw[1]+=1
print(ans)
|
eval(input())
S=eval(input())
ans=float('inf')
cw=0
ce=S.count('E')
for i in S:
if i=='W':
ans=min(ans,cw+ce)
cw+=1
else:
ce-=1
ans=min(ans,cw+ce)
print(ans)
| 24 | 15 | 406 | 175 |
N = int(eval(input()))
S = eval(input())
import collections
tw = S.count("W")
te = S.count("E")
ans = float("inf")
cw = [0, 0]
ce = [tw, te]
# print(cw,ce)
for i in S:
if i == "W":
ce[0] -= 1
ans = min(ans, cw[0] + ce[1])
# print(cw,ce,cw[0]+ce[1])
cw[0] += 1
else:
ce[1] -= 1
ans = min(ans, cw[0] + ce[1])
# print(cw,ce,cw[0]+ce[1])
cw[1] += 1
print(ans)
|
eval(input())
S = eval(input())
ans = float("inf")
cw = 0
ce = S.count("E")
for i in S:
if i == "W":
ans = min(ans, cw + ce)
cw += 1
else:
ce -= 1
ans = min(ans, cw + ce)
print(ans)
| false | 37.5 |
[
"-N = int(eval(input()))",
"+eval(input())",
"-import collections",
"-",
"-tw = S.count(\"W\")",
"-te = S.count(\"E\")",
"-cw = [0, 0]",
"-ce = [tw, te]",
"-# print(cw,ce)",
"+cw = 0",
"+ce = S.count(\"E\")",
"- ce[0] -= 1",
"- ans = min(ans, cw[0] + ce[1])",
"- # print(cw,ce,cw[0]+ce[1])",
"- cw[0] += 1",
"+ ans = min(ans, cw + ce)",
"+ cw += 1",
"- ce[1] -= 1",
"- ans = min(ans, cw[0] + ce[1])",
"- # print(cw,ce,cw[0]+ce[1])",
"- cw[1] += 1",
"+ ce -= 1",
"+ ans = min(ans, cw + ce)"
] | false | 0.038281 | 0.063143 | 0.606264 |
[
"s600829652",
"s785651975"
] |
u350997995
|
p02861
|
python
|
s065414762
|
s907934392
| 407 | 314 | 3,064 | 3,316 |
Accepted
|
Accepted
| 22.85 |
import math
import itertools
N = int(eval(input()))
X = [list(map(int,input().split())) for i in range(N)]
l = [i for i in range(N)]
ans = 0
for v in itertools.permutations(l,N):
for i in range(N):
if i==0:x,y = X[v[i]]
else:
x2,y2 = X[v[i]]
ans+=math.sqrt((x-x2)**2+(y-y2)**2)
x,y = x2,y2
print((ans/math.factorial(N)))
|
from math import factorial as fac
from math import sqrt
from collections import deque
N = int(eval(input()))
X = []
for i in range(N):
x,y = list(map(int,input().split()))
X.append((x,y))
ans = 0
Q = deque()
for i in range(N):
Q.append((0,[i],X[i][0],X[i][1]))
while Q:
S,L,x,y = Q.pop()
if len(L)==N:
ans += S
continue
for i in range(N):
if not(i in L):
h,w = X[i]
Q.append((S+sqrt(pow(x-h,2)+pow(y-w,2)),L+[i],h,w))
print((ans/fac(N)))
| 15 | 22 | 383 | 516 |
import math
import itertools
N = int(eval(input()))
X = [list(map(int, input().split())) for i in range(N)]
l = [i for i in range(N)]
ans = 0
for v in itertools.permutations(l, N):
for i in range(N):
if i == 0:
x, y = X[v[i]]
else:
x2, y2 = X[v[i]]
ans += math.sqrt((x - x2) ** 2 + (y - y2) ** 2)
x, y = x2, y2
print((ans / math.factorial(N)))
|
from math import factorial as fac
from math import sqrt
from collections import deque
N = int(eval(input()))
X = []
for i in range(N):
x, y = list(map(int, input().split()))
X.append((x, y))
ans = 0
Q = deque()
for i in range(N):
Q.append((0, [i], X[i][0], X[i][1]))
while Q:
S, L, x, y = Q.pop()
if len(L) == N:
ans += S
continue
for i in range(N):
if not (i in L):
h, w = X[i]
Q.append((S + sqrt(pow(x - h, 2) + pow(y - w, 2)), L + [i], h, w))
print((ans / fac(N)))
| false | 31.818182 |
[
"-import math",
"-import itertools",
"+from math import factorial as fac",
"+from math import sqrt",
"+from collections import deque",
"-X = [list(map(int, input().split())) for i in range(N)]",
"-l = [i for i in range(N)]",
"+X = []",
"+for i in range(N):",
"+ x, y = list(map(int, input().split()))",
"+ X.append((x, y))",
"-for v in itertools.permutations(l, N):",
"+Q = deque()",
"+for i in range(N):",
"+ Q.append((0, [i], X[i][0], X[i][1]))",
"+while Q:",
"+ S, L, x, y = Q.pop()",
"+ if len(L) == N:",
"+ ans += S",
"+ continue",
"- if i == 0:",
"- x, y = X[v[i]]",
"- else:",
"- x2, y2 = X[v[i]]",
"- ans += math.sqrt((x - x2) ** 2 + (y - y2) ** 2)",
"- x, y = x2, y2",
"-print((ans / math.factorial(N)))",
"+ if not (i in L):",
"+ h, w = X[i]",
"+ Q.append((S + sqrt(pow(x - h, 2) + pow(y - w, 2)), L + [i], h, w))",
"+print((ans / fac(N)))"
] | false | 0.086175 | 0.089857 | 0.959023 |
[
"s065414762",
"s907934392"
] |
u098968285
|
p03312
|
python
|
s106633099
|
s144173758
| 1,347 | 1,071 | 101,636 | 93,432 |
Accepted
|
Accepted
| 20.49 |
def makelist(n, m):
return [[0 for _ in range(m)] for _ in range(n)]
N = int(eval(input()))
A = [0] + list(map(int, input().split()))
def check(mid, base): # b is max-value
if mid < base:
l = imos[mid-1]
r = imos[base-1] - imos[mid-1]
return abs(r-l)
else:
l = imos[mid] - imos[base-1]
r = imos[N] - imos[mid]
return abs(r-l)
def ternarySearchInt(small, big, i):
# 初期条件
if small == big:
return small
elif big - small == 1:
if check(small, i) <= check(big, i):
return small
else:
return big
def func(small, big):
midl = (big + small) // 2
midr = midl + 1
if big - small == 2: # 終了条件
mid = midl
if check(small, i) <= check(mid, i):
if check(small, i) <= check(big, i):
return small
else:
return big
else:
if check(mid, i) <= check(big, i):
return mid
else:
return big
else:
if check(midl, i) > check(midr, i):
return func(midl, big)
else:
return func(small, midr)
return func(small, big)
imos = [0]*(N+1)
for i in range(1, N+1):
imos[i] = imos[i-1] + A[i]
ans = int(1e18)
for i in range(3, N):
l = ternarySearchInt(1, i-1, i)
r = ternarySearchInt(i, N, i)
P = imos[l-1]
Q = imos[i-1] - P
R = imos[r] - imos[i-1]
S = imos[N] - imos[r]
hoge = [P,Q,R,S]
ans = min(ans, max(hoge) - min(hoge))
print(ans)
|
def makelist(n, m):
return [[0 for _ in range(m)] for _ in range(n)]
N = int(eval(input()))
A = [0] + list(map(int, input().split()))
def check(mid, base): # b is max-value
if mid < base:
l = imos[mid-1]
r = imos[base-1] - imos[mid-1]
return abs(r-l)
else:
l = imos[mid] - imos[base-1]
r = imos[N] - imos[mid]
return abs(r-l)
def ternarySearchInt(small, big, i):
if big - small <= 2: # 終了条件
mid = (big + small) // 2
if check(big, i) <= check(mid, i):
return big
else:
return small if check(small, i) <= check(mid, i) else mid
else:
midl = (big + small) // 2
midr = midl + 1
if check(midl, i) >= check(midr, i):
return ternarySearchInt(midl, big, i)
else:
return ternarySearchInt(small, midr, i)
imos = [0]*(N+1)
for i in range(1, N+1):
imos[i] = imos[i-1] + A[i]
ans = int(1e18)
for i in range(3, N):
l = ternarySearchInt(1, i-1, i)
r = ternarySearchInt(i, N, i)
P = imos[l-1]
Q = imos[i-1] - P
R = imos[r] - imos[i-1]
S = imos[N] - imos[r]
hoge = [P,Q,R,S]
ans = min(ans, max(hoge) - min(hoge))
print(ans)
| 72 | 55 | 1,727 | 1,294 |
def makelist(n, m):
return [[0 for _ in range(m)] for _ in range(n)]
N = int(eval(input()))
A = [0] + list(map(int, input().split()))
def check(mid, base): # b is max-value
if mid < base:
l = imos[mid - 1]
r = imos[base - 1] - imos[mid - 1]
return abs(r - l)
else:
l = imos[mid] - imos[base - 1]
r = imos[N] - imos[mid]
return abs(r - l)
def ternarySearchInt(small, big, i):
# 初期条件
if small == big:
return small
elif big - small == 1:
if check(small, i) <= check(big, i):
return small
else:
return big
def func(small, big):
midl = (big + small) // 2
midr = midl + 1
if big - small == 2: # 終了条件
mid = midl
if check(small, i) <= check(mid, i):
if check(small, i) <= check(big, i):
return small
else:
return big
else:
if check(mid, i) <= check(big, i):
return mid
else:
return big
else:
if check(midl, i) > check(midr, i):
return func(midl, big)
else:
return func(small, midr)
return func(small, big)
imos = [0] * (N + 1)
for i in range(1, N + 1):
imos[i] = imos[i - 1] + A[i]
ans = int(1e18)
for i in range(3, N):
l = ternarySearchInt(1, i - 1, i)
r = ternarySearchInt(i, N, i)
P = imos[l - 1]
Q = imos[i - 1] - P
R = imos[r] - imos[i - 1]
S = imos[N] - imos[r]
hoge = [P, Q, R, S]
ans = min(ans, max(hoge) - min(hoge))
print(ans)
|
def makelist(n, m):
return [[0 for _ in range(m)] for _ in range(n)]
N = int(eval(input()))
A = [0] + list(map(int, input().split()))
def check(mid, base): # b is max-value
if mid < base:
l = imos[mid - 1]
r = imos[base - 1] - imos[mid - 1]
return abs(r - l)
else:
l = imos[mid] - imos[base - 1]
r = imos[N] - imos[mid]
return abs(r - l)
def ternarySearchInt(small, big, i):
if big - small <= 2: # 終了条件
mid = (big + small) // 2
if check(big, i) <= check(mid, i):
return big
else:
return small if check(small, i) <= check(mid, i) else mid
else:
midl = (big + small) // 2
midr = midl + 1
if check(midl, i) >= check(midr, i):
return ternarySearchInt(midl, big, i)
else:
return ternarySearchInt(small, midr, i)
imos = [0] * (N + 1)
for i in range(1, N + 1):
imos[i] = imos[i - 1] + A[i]
ans = int(1e18)
for i in range(3, N):
l = ternarySearchInt(1, i - 1, i)
r = ternarySearchInt(i, N, i)
P = imos[l - 1]
Q = imos[i - 1] - P
R = imos[r] - imos[i - 1]
S = imos[N] - imos[r]
hoge = [P, Q, R, S]
ans = min(ans, max(hoge) - min(hoge))
print(ans)
| false | 23.611111 |
[
"- # 初期条件",
"- if small == big:",
"- return small",
"- elif big - small == 1:",
"- if check(small, i) <= check(big, i):",
"- return small",
"+ if big - small <= 2: # 終了条件",
"+ mid = (big + small) // 2",
"+ if check(big, i) <= check(mid, i):",
"+ return big",
"- return big",
"-",
"- def func(small, big):",
"+ return small if check(small, i) <= check(mid, i) else mid",
"+ else:",
"- if big - small == 2: # 終了条件",
"- mid = midl",
"- if check(small, i) <= check(mid, i):",
"- if check(small, i) <= check(big, i):",
"- return small",
"- else:",
"- return big",
"- else:",
"- if check(mid, i) <= check(big, i):",
"- return mid",
"- else:",
"- return big",
"+ if check(midl, i) >= check(midr, i):",
"+ return ternarySearchInt(midl, big, i)",
"- if check(midl, i) > check(midr, i):",
"- return func(midl, big)",
"- else:",
"- return func(small, midr)",
"-",
"- return func(small, big)",
"+ return ternarySearchInt(small, midr, i)"
] | false | 0.007599 | 0.089462 | 0.084941 |
[
"s106633099",
"s144173758"
] |
u027622859
|
p03637
|
python
|
s093735708
|
s388267103
| 71 | 65 | 15,020 | 15,020 |
Accepted
|
Accepted
| 8.45 |
N = int(eval(input()))
l = list(map(int, input().split()))
a, b, c = 0, 0, 0
for i in l:
if i % 4 == 0:
c += 1
elif i % 2 == 0:
b += 1
elif not i % 2 == 0:
a += 1
if b >= 1:
if c >= a:
print("Yes")
else:
print("No")
else:
if c+1 >= a:
print("Yes")
else:
print("No")
|
N = int(eval(input()))
l = list(map(int, input().split()))
a, b, c = 0, 0, 0
for i in l:
if i % 4 == 0:
c += 1
elif i % 2 == 0:
b += 1
else:
a += 1
if b >= 1:
if c >= a:
print("Yes")
else:
print("No")
else:
if c+1 >= a:
print("Yes")
else:
print("No")
| 22 | 22 | 366 | 351 |
N = int(eval(input()))
l = list(map(int, input().split()))
a, b, c = 0, 0, 0
for i in l:
if i % 4 == 0:
c += 1
elif i % 2 == 0:
b += 1
elif not i % 2 == 0:
a += 1
if b >= 1:
if c >= a:
print("Yes")
else:
print("No")
else:
if c + 1 >= a:
print("Yes")
else:
print("No")
|
N = int(eval(input()))
l = list(map(int, input().split()))
a, b, c = 0, 0, 0
for i in l:
if i % 4 == 0:
c += 1
elif i % 2 == 0:
b += 1
else:
a += 1
if b >= 1:
if c >= a:
print("Yes")
else:
print("No")
else:
if c + 1 >= a:
print("Yes")
else:
print("No")
| false | 0 |
[
"- elif not i % 2 == 0:",
"+ else:"
] | false | 0.057935 | 0.087157 | 0.664723 |
[
"s093735708",
"s388267103"
] |
u226155577
|
p03389
|
python
|
s295089624
|
s184495842
| 184 | 17 | 38,384 | 2,940 |
Accepted
|
Accepted
| 90.76 |
a, b, c= list(map(int, input().split()))
ans = 0
def calc(a, b):
if a < b:
r = b-a
if r % 2:
return r//2 + 2
return r//2
else:
return a-b
def solve(a, b, c):
return calc(a, c) + calc(b, c)
print((min(solve(a, b, c), solve(b, c, a), solve(c, a, b))))
|
a, b, c = sorted(map(int, input().split()))
a = c-a; b = c-b
p = a%2; q = b%2
if p and q:
print((a//2+b//2+1))
elif p or q:
print((a//2+b//2+2))
else:
print((a//2+b//2))
| 13 | 9 | 310 | 184 |
a, b, c = list(map(int, input().split()))
ans = 0
def calc(a, b):
if a < b:
r = b - a
if r % 2:
return r // 2 + 2
return r // 2
else:
return a - b
def solve(a, b, c):
return calc(a, c) + calc(b, c)
print((min(solve(a, b, c), solve(b, c, a), solve(c, a, b))))
|
a, b, c = sorted(map(int, input().split()))
a = c - a
b = c - b
p = a % 2
q = b % 2
if p and q:
print((a // 2 + b // 2 + 1))
elif p or q:
print((a // 2 + b // 2 + 2))
else:
print((a // 2 + b // 2))
| false | 30.769231 |
[
"-a, b, c = list(map(int, input().split()))",
"-ans = 0",
"-",
"-",
"-def calc(a, b):",
"- if a < b:",
"- r = b - a",
"- if r % 2:",
"- return r // 2 + 2",
"- return r // 2",
"- else:",
"- return a - b",
"-",
"-",
"-def solve(a, b, c):",
"- return calc(a, c) + calc(b, c)",
"-",
"-",
"-print((min(solve(a, b, c), solve(b, c, a), solve(c, a, b))))",
"+a, b, c = sorted(map(int, input().split()))",
"+a = c - a",
"+b = c - b",
"+p = a % 2",
"+q = b % 2",
"+if p and q:",
"+ print((a // 2 + b // 2 + 1))",
"+elif p or q:",
"+ print((a // 2 + b // 2 + 2))",
"+else:",
"+ print((a // 2 + b // 2))"
] | false | 0.080666 | 0.040584 | 1.987647 |
[
"s295089624",
"s184495842"
] |
u747602774
|
p03162
|
python
|
s223741624
|
s223617517
| 504 | 347 | 22,772 | 22,772 |
Accepted
|
Accepted
| 31.15 |
N = int(eval(input()))
dp = [[0]*3 for i in range(N)]
dp[0] = list(map(int,input().split()))
for i in range(1,N):
a,b,c = list(map(int,input().split()))
dp[i][0] = max(dp[i-1][1],dp[i-1][2]) + a
dp[i][1] = max(dp[i-1][0],dp[i-1][2]) + b
dp[i][2] = max(dp[i-1][0],dp[i-1][1]) + c
print((max(dp[N-1])))
|
import sys
readline = sys.stdin.readline
N = int(readline())
dp = [[0]*3 for i in range(N)]
dp[0] = list(map(int,readline().split()))
for i in range(1,N):
a,b,c = list(map(int,readline().split()))
dp[i][0] = max(dp[i-1][1],dp[i-1][2]) + a
dp[i][1] = max(dp[i-1][0],dp[i-1][2]) + b
dp[i][2] = max(dp[i-1][0],dp[i-1][1]) + c
print((max(dp[N-1])))
| 9 | 11 | 310 | 363 |
N = int(eval(input()))
dp = [[0] * 3 for i in range(N)]
dp[0] = list(map(int, input().split()))
for i in range(1, N):
a, b, c = list(map(int, input().split()))
dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a
dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + b
dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + c
print((max(dp[N - 1])))
|
import sys
readline = sys.stdin.readline
N = int(readline())
dp = [[0] * 3 for i in range(N)]
dp[0] = list(map(int, readline().split()))
for i in range(1, N):
a, b, c = list(map(int, readline().split()))
dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a
dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + b
dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + c
print((max(dp[N - 1])))
| false | 18.181818 |
[
"-N = int(eval(input()))",
"+import sys",
"+",
"+readline = sys.stdin.readline",
"+N = int(readline())",
"-dp[0] = list(map(int, input().split()))",
"+dp[0] = list(map(int, readline().split()))",
"- a, b, c = list(map(int, input().split()))",
"+ a, b, c = list(map(int, readline().split()))"
] | false | 0.135628 | 0.041597 | 3.260508 |
[
"s223741624",
"s223617517"
] |
u150984829
|
p02396
|
python
|
s446910744
|
s849976124
| 120 | 50 | 5,580 | 5,680 |
Accepted
|
Accepted
| 58.33 |
for i,a in enumerate(iter(input,'0'),1):print(f'Case {i}: {a}')
|
import sys
for i,a in enumerate(sys.stdin,1):
if a=='0\n':break
print(f'Case {i}: {a}',end='')
| 1 | 4 | 64 | 100 |
for i, a in enumerate(iter(input, "0"), 1):
print(f"Case {i}: {a}")
|
import sys
for i, a in enumerate(sys.stdin, 1):
if a == "0\n":
break
print(f"Case {i}: {a}", end="")
| false | 75 |
[
"-for i, a in enumerate(iter(input, \"0\"), 1):",
"- print(f\"Case {i}: {a}\")",
"+import sys",
"+",
"+for i, a in enumerate(sys.stdin, 1):",
"+ if a == \"0\\n\":",
"+ break",
"+ print(f\"Case {i}: {a}\", end=\"\")"
] | false | 0.006412 | 0.035354 | 0.181354 |
[
"s446910744",
"s849976124"
] |
u255673886
|
p03997
|
python
|
s714811153
|
s021177236
| 188 | 85 | 38,384 | 68,376 |
Accepted
|
Accepted
| 54.79 |
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
# from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
INF = float("inf")
def myinput():
return list(map(int,input().split()))
def mylistinput(n):
return [ list(myinput()) for _ in range(n) ]
def mycol(data,col):
return [ row[col] for row in data ]
def mysort(data,col,reverse_flag):
data.sort(key=lambda x:x[col],reverse=reverse_flag)
return data
def mymax(data):
M = -1*float("inf")
for i in range(len(data)):
m = max(data[i])
M = max(M,m)
return M
def mymin(data):
m = float("inf")
for i in range(len(data)):
M = min(data[i])
m = min(m,M)
return m
def mycount(ls,x):
# lsはソート済みであること
l = bisect_left(ls,x)
r = bisect_right(ls,x)
return (r-l)
def myoutput(ls,space=True):
if space:
if len(ls)==0:
print(" ")
elif type(ls[0])==str:
print((" ".join(ls)))
elif type(ls[0])==int:
print((" ".join(map(str,ls))))
else:
print("Output Error")
else:
if len(ls)==0:
print("")
elif type(ls[0])==str:
print(("".join(ls)))
elif type(ls[0])==int:
print(("".join(map(str,ls))))
else:
print("Output Error")
a = int(eval(input()))
b = int(eval(input()))
h = int(eval(input()))
ans = (a+b)*h/2
print((int(ans)))
|
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
# from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
INF = float("inf")
def myinput():
return list(map(int,input().split()))
def mylistinput(n):
return [ list(myinput()) for _ in range(n) ]
def mycol(data,col):
return [ row[col] for row in data ]
def mysort(data,col,reverse_flag):
data.sort(key=lambda x:x[col],reverse=reverse_flag)
return data
def mymax(data):
M = -1*float("inf")
for i in range(len(data)):
m = max(data[i])
M = max(M,m)
return M
def mymin(data):
m = float("inf")
for i in range(len(data)):
M = min(data[i])
m = min(m,M)
return m
def mycount(ls,x):
# lsはソート済みであること
l = bisect_left(ls,x)
r = bisect_right(ls,x)
return (r-l)
def myoutput(ls,space=True):
if space:
if len(ls)==0:
print(" ")
elif type(ls[0])==str:
print((" ".join(ls)))
elif type(ls[0])==int:
print((" ".join(map(str,ls))))
else:
print("Output Error")
else:
if len(ls)==0:
print("")
elif type(ls[0])==str:
print(("".join(ls)))
elif type(ls[0])==int:
print(("".join(map(str,ls))))
else:
print("Output Error")
def I():
return int(eval(input()))
def MI():
return list(map(int,input().split()))
def RI():
return list(map(int,input().split()))
def CI(n):
return [ int(eval(input())) for _ in range(n) ]
def LI(n):
return [ list(map(int,input().split())) for _ in range(n) ]
def S():
return eval(input())
def MS():
return input().split()
def RS():
return list(input().split())
def CS(n):
return [ eval(input()) for _ in range(n) ]
def LS(n):
return [ list(input().split()) for _ in range(n) ]
a = I()
b = I()
h = I()
ans = (a+b)*h//2
print(ans)
| 71 | 102 | 1,762 | 2,264 |
from collections import deque
from heapq import heapify, heappop, heappush, heappushpop
from copy import copy, deepcopy
from itertools import product, permutations, combinations, combinations_with_replacement
from collections import defaultdict, Counter
from bisect import bisect_left, bisect_right
# from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
INF = float("inf")
def myinput():
return list(map(int, input().split()))
def mylistinput(n):
return [list(myinput()) for _ in range(n)]
def mycol(data, col):
return [row[col] for row in data]
def mysort(data, col, reverse_flag):
data.sort(key=lambda x: x[col], reverse=reverse_flag)
return data
def mymax(data):
M = -1 * float("inf")
for i in range(len(data)):
m = max(data[i])
M = max(M, m)
return M
def mymin(data):
m = float("inf")
for i in range(len(data)):
M = min(data[i])
m = min(m, M)
return m
def mycount(ls, x):
# lsはソート済みであること
l = bisect_left(ls, x)
r = bisect_right(ls, x)
return r - l
def myoutput(ls, space=True):
if space:
if len(ls) == 0:
print(" ")
elif type(ls[0]) == str:
print((" ".join(ls)))
elif type(ls[0]) == int:
print((" ".join(map(str, ls))))
else:
print("Output Error")
else:
if len(ls) == 0:
print("")
elif type(ls[0]) == str:
print(("".join(ls)))
elif type(ls[0]) == int:
print(("".join(map(str, ls))))
else:
print("Output Error")
a = int(eval(input()))
b = int(eval(input()))
h = int(eval(input()))
ans = (a + b) * h / 2
print((int(ans)))
|
from collections import deque
from heapq import heapify, heappop, heappush, heappushpop
from copy import copy, deepcopy
from itertools import product, permutations, combinations, combinations_with_replacement
from collections import defaultdict, Counter
from bisect import bisect_left, bisect_right
# from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
INF = float("inf")
def myinput():
return list(map(int, input().split()))
def mylistinput(n):
return [list(myinput()) for _ in range(n)]
def mycol(data, col):
return [row[col] for row in data]
def mysort(data, col, reverse_flag):
data.sort(key=lambda x: x[col], reverse=reverse_flag)
return data
def mymax(data):
M = -1 * float("inf")
for i in range(len(data)):
m = max(data[i])
M = max(M, m)
return M
def mymin(data):
m = float("inf")
for i in range(len(data)):
M = min(data[i])
m = min(m, M)
return m
def mycount(ls, x):
# lsはソート済みであること
l = bisect_left(ls, x)
r = bisect_right(ls, x)
return r - l
def myoutput(ls, space=True):
if space:
if len(ls) == 0:
print(" ")
elif type(ls[0]) == str:
print((" ".join(ls)))
elif type(ls[0]) == int:
print((" ".join(map(str, ls))))
else:
print("Output Error")
else:
if len(ls) == 0:
print("")
elif type(ls[0]) == str:
print(("".join(ls)))
elif type(ls[0]) == int:
print(("".join(map(str, ls))))
else:
print("Output Error")
def I():
return int(eval(input()))
def MI():
return list(map(int, input().split()))
def RI():
return list(map(int, input().split()))
def CI(n):
return [int(eval(input())) for _ in range(n)]
def LI(n):
return [list(map(int, input().split())) for _ in range(n)]
def S():
return eval(input())
def MS():
return input().split()
def RS():
return list(input().split())
def CS(n):
return [eval(input()) for _ in range(n)]
def LS(n):
return [list(input().split()) for _ in range(n)]
a = I()
b = I()
h = I()
ans = (a + b) * h // 2
print(ans)
| false | 30.392157 |
[
"-a = int(eval(input()))",
"-b = int(eval(input()))",
"-h = int(eval(input()))",
"-ans = (a + b) * h / 2",
"-print((int(ans)))",
"+def I():",
"+ return int(eval(input()))",
"+",
"+",
"+def MI():",
"+ return list(map(int, input().split()))",
"+",
"+",
"+def RI():",
"+ return list(map(int, input().split()))",
"+",
"+",
"+def CI(n):",
"+ return [int(eval(input())) for _ in range(n)]",
"+",
"+",
"+def LI(n):",
"+ return [list(map(int, input().split())) for _ in range(n)]",
"+",
"+",
"+def S():",
"+ return eval(input())",
"+",
"+",
"+def MS():",
"+ return input().split()",
"+",
"+",
"+def RS():",
"+ return list(input().split())",
"+",
"+",
"+def CS(n):",
"+ return [eval(input()) for _ in range(n)]",
"+",
"+",
"+def LS(n):",
"+ return [list(input().split()) for _ in range(n)]",
"+",
"+",
"+a = I()",
"+b = I()",
"+h = I()",
"+ans = (a + b) * h // 2",
"+print(ans)"
] | false | 0.039948 | 0.04113 | 0.971253 |
[
"s714811153",
"s021177236"
] |
u794910686
|
p02837
|
python
|
s452925234
|
s550772819
| 1,301 | 319 | 3,064 | 3,064 |
Accepted
|
Accepted
| 75.48 |
def honestcount(i):
return bin(i).count("1")
def is_honest(i,j):
return (i>>j)%2 == 1
N = int(eval(input()))
A = [0] * N
shogens=[]
for i in range(N):
a = int(eval(input()))
shogen=[]
for j in range(a):
x,y = list(map(int, input().split()))
shogen.append((x-1,y))
shogens.append(shogen)
# print(shogens)
count=0
for i in range(1<<N):
is_ok =True
for j in range(N):
if not is_honest(i,j):
continue
for x,y in shogens[j]:
if y!=is_honest(i,x): is_ok=False
if is_ok:
count=max(count,honestcount(i))
print(count)
|
def honestcount(i):
return bin(i).count("1")
def is_honest(i,j):
return (i>>j)%2 == 1
N = int(eval(input()))
A = [0] * N
shogens=[]
for i in range(N):
a = int(eval(input()))
shogen=[]
for j in range(a):
x,y = list(map(int, input().split()))
shogen.append((x-1,y))
shogens.append(shogen)
# print(shogens)
count=0
for i in range(1<<N):
is_ok =True
for j in range(N):
if not is_honest(i,j):
continue
for x,y in shogens[j]:
if y!=is_honest(i,x):
is_ok=False
break
if is_ok:
count=max(count,honestcount(i))
print(count)
| 31 | 33 | 626 | 666 |
def honestcount(i):
return bin(i).count("1")
def is_honest(i, j):
return (i >> j) % 2 == 1
N = int(eval(input()))
A = [0] * N
shogens = []
for i in range(N):
a = int(eval(input()))
shogen = []
for j in range(a):
x, y = list(map(int, input().split()))
shogen.append((x - 1, y))
shogens.append(shogen)
# print(shogens)
count = 0
for i in range(1 << N):
is_ok = True
for j in range(N):
if not is_honest(i, j):
continue
for x, y in shogens[j]:
if y != is_honest(i, x):
is_ok = False
if is_ok:
count = max(count, honestcount(i))
print(count)
|
def honestcount(i):
return bin(i).count("1")
def is_honest(i, j):
return (i >> j) % 2 == 1
N = int(eval(input()))
A = [0] * N
shogens = []
for i in range(N):
a = int(eval(input()))
shogen = []
for j in range(a):
x, y = list(map(int, input().split()))
shogen.append((x - 1, y))
shogens.append(shogen)
# print(shogens)
count = 0
for i in range(1 << N):
is_ok = True
for j in range(N):
if not is_honest(i, j):
continue
for x, y in shogens[j]:
if y != is_honest(i, x):
is_ok = False
break
if is_ok:
count = max(count, honestcount(i))
print(count)
| false | 6.060606 |
[
"+ break"
] | false | 0.04215 | 0.036669 | 1.14948 |
[
"s452925234",
"s550772819"
] |
u514687406
|
p03834
|
python
|
s476648204
|
s342834700
| 26 | 22 | 9,080 | 8,928 |
Accepted
|
Accepted
| 15.38 |
# import sys; input = lambda: sys.stdin.readline()
s = eval(input())
s = s.replace(",", " ")
print(s)
|
print((" ".join(map(str, input().split(",")))))
| 4 | 1 | 98 | 45 |
# import sys; input = lambda: sys.stdin.readline()
s = eval(input())
s = s.replace(",", " ")
print(s)
|
print((" ".join(map(str, input().split(",")))))
| false | 75 |
[
"-# import sys; input = lambda: sys.stdin.readline()",
"-s = eval(input())",
"-s = s.replace(\",\", \" \")",
"-print(s)",
"+print((\" \".join(map(str, input().split(\",\")))))"
] | false | 0.043256 | 0.04721 | 0.916258 |
[
"s476648204",
"s342834700"
] |
u774539708
|
p02793
|
python
|
s015237563
|
s946772161
| 1,254 | 690 | 5,612 | 14,476 |
Accepted
|
Accepted
| 44.98 |
n=int(eval(input()))
A=list(map(int,input().split()))
mod=10**9+7
import fractions
def lcm(a,b):
return a*b//fractions.gcd(a,b)
def power(a):
T=[a]
while 2**(len(T))<mod:
T.append(T[-1]**2%mod)
b=bin(mod-2)
ans=1
for i in range(len(b)-2):
if int(b[-i-1])==1:
ans=ans*T[i]%mod
return ans
l=A[0]
for i in range(n-1):
l=lcm(l,A[i+1])
l%=mod
s=0
for i in range(n):
s+=l*power(A[i])%mod
s%=mod
print(s)
|
n=int(eval(input()))
A=list(map(int,input().split()))
mod=10**9+7
def inverse(a): #aに対し、a**(mod-2)、つまり逆元を返す
T=[a]
while 2**(len(T))<mod: #a**1,a**2.a**4,a**8,...を計算しておく
T.append(T[-1]**2%mod)
b=bin(mod-2) #mod-2を2進数表記にする
ans=1
for i in range(len(b)-2):
if int(b[-i-1])==1:
ans=ans*T[i]%mod
return ans
def make_eratosthenes(n): #エラストテネスの篩(最大の素因数を格納した配列)
A=[0]*n
A[0],A[1]=-1,-1
for i in range(2,n):
if A[i]==0:
j=i
while j<n:
A[j]=i
j+=i
return A
E=make_eratosthenes(10**6+5)
l={}
for a in A:
now=a
f=[] #素因数格納配列
while now>1:
f.append(E[now])
now//=E[now]
chk=0
for p in f:
if chk==p: #同じ素因数が複数あるときに飛ばす
continue
chk=p
if p in list(l.keys()): #辞書に素因数がある場合、個数の多いほう
l[p]=max(l[p],f.count(p))
else: #辞書にない場合新規追加
l[p]=f.count(p)
lcm=1
for k in l:
for i in range(l[k]):
lcm=lcm*k%mod
s=0
for i in range(n):
s+=lcm*inverse(A[i])%mod
s%=mod
print(s)
| 28 | 54 | 492 | 1,143 |
n = int(eval(input()))
A = list(map(int, input().split()))
mod = 10**9 + 7
import fractions
def lcm(a, b):
return a * b // fractions.gcd(a, b)
def power(a):
T = [a]
while 2 ** (len(T)) < mod:
T.append(T[-1] ** 2 % mod)
b = bin(mod - 2)
ans = 1
for i in range(len(b) - 2):
if int(b[-i - 1]) == 1:
ans = ans * T[i] % mod
return ans
l = A[0]
for i in range(n - 1):
l = lcm(l, A[i + 1])
l %= mod
s = 0
for i in range(n):
s += l * power(A[i]) % mod
s %= mod
print(s)
|
n = int(eval(input()))
A = list(map(int, input().split()))
mod = 10**9 + 7
def inverse(a): # aに対し、a**(mod-2)、つまり逆元を返す
T = [a]
while 2 ** (len(T)) < mod: # a**1,a**2.a**4,a**8,...を計算しておく
T.append(T[-1] ** 2 % mod)
b = bin(mod - 2) # mod-2を2進数表記にする
ans = 1
for i in range(len(b) - 2):
if int(b[-i - 1]) == 1:
ans = ans * T[i] % mod
return ans
def make_eratosthenes(n): # エラストテネスの篩(最大の素因数を格納した配列)
A = [0] * n
A[0], A[1] = -1, -1
for i in range(2, n):
if A[i] == 0:
j = i
while j < n:
A[j] = i
j += i
return A
E = make_eratosthenes(10**6 + 5)
l = {}
for a in A:
now = a
f = [] # 素因数格納配列
while now > 1:
f.append(E[now])
now //= E[now]
chk = 0
for p in f:
if chk == p: # 同じ素因数が複数あるときに飛ばす
continue
chk = p
if p in list(l.keys()): # 辞書に素因数がある場合、個数の多いほう
l[p] = max(l[p], f.count(p))
else: # 辞書にない場合新規追加
l[p] = f.count(p)
lcm = 1
for k in l:
for i in range(l[k]):
lcm = lcm * k % mod
s = 0
for i in range(n):
s += lcm * inverse(A[i]) % mod
s %= mod
print(s)
| false | 48.148148 |
[
"-import fractions",
"-def lcm(a, b):",
"- return a * b // fractions.gcd(a, b)",
"-",
"-",
"-def power(a):",
"+def inverse(a): # aに対し、a**(mod-2)、つまり逆元を返す",
"- while 2 ** (len(T)) < mod:",
"+ while 2 ** (len(T)) < mod: # a**1,a**2.a**4,a**8,...を計算しておく",
"- b = bin(mod - 2)",
"+ b = bin(mod - 2) # mod-2を2進数表記にする",
"-l = A[0]",
"-for i in range(n - 1):",
"- l = lcm(l, A[i + 1])",
"-l %= mod",
"+def make_eratosthenes(n): # エラストテネスの篩(最大の素因数を格納した配列)",
"+ A = [0] * n",
"+ A[0], A[1] = -1, -1",
"+ for i in range(2, n):",
"+ if A[i] == 0:",
"+ j = i",
"+ while j < n:",
"+ A[j] = i",
"+ j += i",
"+ return A",
"+",
"+",
"+E = make_eratosthenes(10**6 + 5)",
"+l = {}",
"+for a in A:",
"+ now = a",
"+ f = [] # 素因数格納配列",
"+ while now > 1:",
"+ f.append(E[now])",
"+ now //= E[now]",
"+ chk = 0",
"+ for p in f:",
"+ if chk == p: # 同じ素因数が複数あるときに飛ばす",
"+ continue",
"+ chk = p",
"+ if p in list(l.keys()): # 辞書に素因数がある場合、個数の多いほう",
"+ l[p] = max(l[p], f.count(p))",
"+ else: # 辞書にない場合新規追加",
"+ l[p] = f.count(p)",
"+lcm = 1",
"+for k in l:",
"+ for i in range(l[k]):",
"+ lcm = lcm * k % mod",
"- s += l * power(A[i]) % mod",
"+ s += lcm * inverse(A[i]) % mod"
] | false | 0.055521 | 0.757082 | 0.073335 |
[
"s015237563",
"s946772161"
] |
u654470292
|
p03488
|
python
|
s885039777
|
s073082033
| 556 | 490 | 175,960 | 167,260 |
Accepted
|
Accepted
| 11.87 |
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
return sys.stdin.readline()[:-1]
mod=pow(10,9)+7
s=eval(input())
x,y=list(map(int,input().split()))
lst=[[],[]]
cnt=0
tmp=0
for i in range(len(s)):
if s[i]=="F":
tmp+=1
else:
if cnt==0:
x-=tmp
else:
if tmp!=0:
lst[cnt%2].append(tmp)
tmp=0
cnt+=1
if cnt==0:
x-=tmp
elif tmp!=0:
lst[cnt%2].append(tmp)
sumx=sum(lst[0])
sumy=sum(lst[1])
# print(x,sumx)
if sumx<x or x<-sumx:
print("No")
exit()
if sumy<y or y<-sumy:
print("No")
exit()
dpx=[[0]*(sumx*2+1) for i in range(len(lst[0])+1)]
dpy=[[0]*(sumy*2+1) for i in range(len(lst[1])+1)]
dpx[0][sumx]=1
dpy[0][sumy]=1
for i in range(len(lst[0])):
for j in range(sumx*2+1):
if dpx[i][j]!=0:
dpx[i+1][j+lst[0][i]]+=1
dpx[i+1][j-lst[0][i]]+=1
for i in range(len(lst[1])):
for j in range(sumy*2+1):
if dpy[i][j]!=0:
dpy[i+1][j+lst[1][i]]+=1
dpy[i+1][j-lst[1][i]]+=1
# print(dpx)
# print(dpy)
if dpx[len(lst[0])][sumx+x]!=0 and dpy[len(lst[1])][sumy+y]!=0:
print("Yes")
else:
print("No")
|
import bisect
import copy
import heapq
import math
import sys
from collections import *
from itertools import accumulate, combinations, permutations, product
# from math import gcd
def input():
return sys.stdin.readline()[:-1]
def ruiseki(lst):
return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]
s=eval(input())
x,y=list(map(int,input().split()))
tate,yoko=[],[]
kaisi=0
tmp=0
flag=1
for i in range(len(s)):
if s[i]=="F":
tmp+=1
elif s[i]=="T":
if kaisi==0:
kaisi=1
x-=tmp
elif flag==0:
flag=1
yoko.append(tmp)
else:
flag=0
tate.append(tmp)
tmp=0
if kaisi==0:
kaisi=1
x-=tmp
elif flag==0:
flag=1
yoko.append(tmp)
else:
flag=0
tate.append(tmp)
if sum(yoko)==0 and sum(tate)==0:
if x==0 and y==0:
print("Yes")
else:
print("No")
quit()
# print(yoko,tate)
if abs(x)>sum(yoko) or abs(y)>sum(tate):
print("No")
quit()
yokolst=[[0]*(sum(yoko)*2+1) for i in range(len(yoko)+1)]
tatelst=[[0]*(sum(tate)*2+1) for i in range(len(tate)+1)]
yokolst[0][sum(yoko)]=1
tatelst[0][sum(tate)]=1
# print(yokolst)
# print(tatelst)
for i in range(len(tate)):
for j in range(len(tatelst[0])):
if tatelst[i][j]==1:
tatelst[i+1][j+tate[i]]=1
tatelst[i+1][j-tate[i]]=1
for i in range(len(yoko)):
for j in range(len(yokolst[0])):
if yokolst[i][j]==1:
yokolst[i+1][j+yoko[i]]=1
yokolst[i+1][j-yoko[i]]=1
# print(yokolst)
# print(tatelst)
if tatelst[-1][sum(tate)+y]==1 and yokolst[-1][sum(yoko)+x]==1:
print("Yes")
else:
print("No")
| 64 | 86 | 1,362 | 1,833 |
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations, accumulate, combinations, product
from fractions import gcd
def input():
return sys.stdin.readline()[:-1]
mod = pow(10, 9) + 7
s = eval(input())
x, y = list(map(int, input().split()))
lst = [[], []]
cnt = 0
tmp = 0
for i in range(len(s)):
if s[i] == "F":
tmp += 1
else:
if cnt == 0:
x -= tmp
else:
if tmp != 0:
lst[cnt % 2].append(tmp)
tmp = 0
cnt += 1
if cnt == 0:
x -= tmp
elif tmp != 0:
lst[cnt % 2].append(tmp)
sumx = sum(lst[0])
sumy = sum(lst[1])
# print(x,sumx)
if sumx < x or x < -sumx:
print("No")
exit()
if sumy < y or y < -sumy:
print("No")
exit()
dpx = [[0] * (sumx * 2 + 1) for i in range(len(lst[0]) + 1)]
dpy = [[0] * (sumy * 2 + 1) for i in range(len(lst[1]) + 1)]
dpx[0][sumx] = 1
dpy[0][sumy] = 1
for i in range(len(lst[0])):
for j in range(sumx * 2 + 1):
if dpx[i][j] != 0:
dpx[i + 1][j + lst[0][i]] += 1
dpx[i + 1][j - lst[0][i]] += 1
for i in range(len(lst[1])):
for j in range(sumy * 2 + 1):
if dpy[i][j] != 0:
dpy[i + 1][j + lst[1][i]] += 1
dpy[i + 1][j - lst[1][i]] += 1
# print(dpx)
# print(dpy)
if dpx[len(lst[0])][sumx + x] != 0 and dpy[len(lst[1])][sumy + y] != 0:
print("Yes")
else:
print("No")
|
import bisect
import copy
import heapq
import math
import sys
from collections import *
from itertools import accumulate, combinations, permutations, product
# from math import gcd
def input():
return sys.stdin.readline()[:-1]
def ruiseki(lst):
return [0] + list(accumulate(lst))
mod = pow(10, 9) + 7
al = [chr(ord("a") + i) for i in range(26)]
direction = [[1, 0], [0, 1], [-1, 0], [0, -1]]
s = eval(input())
x, y = list(map(int, input().split()))
tate, yoko = [], []
kaisi = 0
tmp = 0
flag = 1
for i in range(len(s)):
if s[i] == "F":
tmp += 1
elif s[i] == "T":
if kaisi == 0:
kaisi = 1
x -= tmp
elif flag == 0:
flag = 1
yoko.append(tmp)
else:
flag = 0
tate.append(tmp)
tmp = 0
if kaisi == 0:
kaisi = 1
x -= tmp
elif flag == 0:
flag = 1
yoko.append(tmp)
else:
flag = 0
tate.append(tmp)
if sum(yoko) == 0 and sum(tate) == 0:
if x == 0 and y == 0:
print("Yes")
else:
print("No")
quit()
# print(yoko,tate)
if abs(x) > sum(yoko) or abs(y) > sum(tate):
print("No")
quit()
yokolst = [[0] * (sum(yoko) * 2 + 1) for i in range(len(yoko) + 1)]
tatelst = [[0] * (sum(tate) * 2 + 1) for i in range(len(tate) + 1)]
yokolst[0][sum(yoko)] = 1
tatelst[0][sum(tate)] = 1
# print(yokolst)
# print(tatelst)
for i in range(len(tate)):
for j in range(len(tatelst[0])):
if tatelst[i][j] == 1:
tatelst[i + 1][j + tate[i]] = 1
tatelst[i + 1][j - tate[i]] = 1
for i in range(len(yoko)):
for j in range(len(yokolst[0])):
if yokolst[i][j] == 1:
yokolst[i + 1][j + yoko[i]] = 1
yokolst[i + 1][j - yoko[i]] = 1
# print(yokolst)
# print(tatelst)
if tatelst[-1][sum(tate) + y] == 1 and yokolst[-1][sum(yoko) + x] == 1:
print("Yes")
else:
print("No")
| false | 25.581395 |
[
"+import bisect",
"+import copy",
"+import heapq",
"+import math",
"-import heapq",
"-import math",
"-import bisect",
"-from itertools import permutations, accumulate, combinations, product",
"-from fractions import gcd",
"+from itertools import accumulate, combinations, permutations, product",
"-",
"+# from math import gcd",
"+def ruiseki(lst):",
"+ return [0] + list(accumulate(lst))",
"+",
"+",
"+al = [chr(ord(\"a\") + i) for i in range(26)]",
"+direction = [[1, 0], [0, 1], [-1, 0], [0, -1]]",
"-lst = [[], []]",
"-cnt = 0",
"+tate, yoko = [], []",
"+kaisi = 0",
"+flag = 1",
"+ elif s[i] == \"T\":",
"+ if kaisi == 0:",
"+ kaisi = 1",
"+ x -= tmp",
"+ elif flag == 0:",
"+ flag = 1",
"+ yoko.append(tmp)",
"+ else:",
"+ flag = 0",
"+ tate.append(tmp)",
"+ tmp = 0",
"+if kaisi == 0:",
"+ kaisi = 1",
"+ x -= tmp",
"+elif flag == 0:",
"+ flag = 1",
"+ yoko.append(tmp)",
"+else:",
"+ flag = 0",
"+ tate.append(tmp)",
"+if sum(yoko) == 0 and sum(tate) == 0:",
"+ if x == 0 and y == 0:",
"+ print(\"Yes\")",
"- if cnt == 0:",
"- x -= tmp",
"- else:",
"- if tmp != 0:",
"- lst[cnt % 2].append(tmp)",
"- tmp = 0",
"- cnt += 1",
"-if cnt == 0:",
"- x -= tmp",
"-elif tmp != 0:",
"- lst[cnt % 2].append(tmp)",
"-sumx = sum(lst[0])",
"-sumy = sum(lst[1])",
"-# print(x,sumx)",
"-if sumx < x or x < -sumx:",
"+ print(\"No\")",
"+ quit()",
"+# print(yoko,tate)",
"+if abs(x) > sum(yoko) or abs(y) > sum(tate):",
"- exit()",
"-if sumy < y or y < -sumy:",
"- print(\"No\")",
"- exit()",
"-dpx = [[0] * (sumx * 2 + 1) for i in range(len(lst[0]) + 1)]",
"-dpy = [[0] * (sumy * 2 + 1) for i in range(len(lst[1]) + 1)]",
"-dpx[0][sumx] = 1",
"-dpy[0][sumy] = 1",
"-for i in range(len(lst[0])):",
"- for j in range(sumx * 2 + 1):",
"- if dpx[i][j] != 0:",
"- dpx[i + 1][j + lst[0][i]] += 1",
"- dpx[i + 1][j - lst[0][i]] += 1",
"-for i in range(len(lst[1])):",
"- for j in range(sumy * 2 + 1):",
"- if dpy[i][j] != 0:",
"- dpy[i + 1][j + lst[1][i]] += 1",
"- dpy[i + 1][j - lst[1][i]] += 1",
"-# print(dpx)",
"-# print(dpy)",
"-if dpx[len(lst[0])][sumx + x] != 0 and dpy[len(lst[1])][sumy + y] != 0:",
"+ quit()",
"+yokolst = [[0] * (sum(yoko) * 2 + 1) for i in range(len(yoko) + 1)]",
"+tatelst = [[0] * (sum(tate) * 2 + 1) for i in range(len(tate) + 1)]",
"+yokolst[0][sum(yoko)] = 1",
"+tatelst[0][sum(tate)] = 1",
"+# print(yokolst)",
"+# print(tatelst)",
"+for i in range(len(tate)):",
"+ for j in range(len(tatelst[0])):",
"+ if tatelst[i][j] == 1:",
"+ tatelst[i + 1][j + tate[i]] = 1",
"+ tatelst[i + 1][j - tate[i]] = 1",
"+for i in range(len(yoko)):",
"+ for j in range(len(yokolst[0])):",
"+ if yokolst[i][j] == 1:",
"+ yokolst[i + 1][j + yoko[i]] = 1",
"+ yokolst[i + 1][j - yoko[i]] = 1",
"+# print(yokolst)",
"+# print(tatelst)",
"+if tatelst[-1][sum(tate) + y] == 1 and yokolst[-1][sum(yoko) + x] == 1:"
] | false | 0.049974 | 0.048566 | 1.028991 |
[
"s885039777",
"s073082033"
] |
u558867581
|
p02701
|
python
|
s606007217
|
s330111768
| 269 | 71 | 35,704 | 38,828 |
Accepted
|
Accepted
| 73.61 |
N = int(eval(input()))
S = [eval(input()) for i in range(N)]
S_uniqu = list(set(S))
print((len(S_uniqu)))
|
n, *s = open(0).read().split()
print((len(set(s))))
| 5 | 2 | 97 | 50 |
N = int(eval(input()))
S = [eval(input()) for i in range(N)]
S_uniqu = list(set(S))
print((len(S_uniqu)))
|
n, *s = open(0).read().split()
print((len(set(s))))
| false | 60 |
[
"-N = int(eval(input()))",
"-S = [eval(input()) for i in range(N)]",
"-S_uniqu = list(set(S))",
"-print((len(S_uniqu)))",
"+n, *s = open(0).read().split()",
"+print((len(set(s))))"
] | false | 0.037069 | 0.035573 | 1.042053 |
[
"s606007217",
"s330111768"
] |
u519939795
|
p02783
|
python
|
s284115711
|
s623128987
| 19 | 17 | 2,940 | 2,940 |
Accepted
|
Accepted
| 10.53 |
h,a=list(map(int,input().split()))
l=0
while h>0:
h = h-a
l += 1
print(l)
|
H, A = list(map(int, input().split()))
print((H//A if H % A == 0 else H//A+1))
| 6 | 2 | 80 | 71 |
h, a = list(map(int, input().split()))
l = 0
while h > 0:
h = h - a
l += 1
print(l)
|
H, A = list(map(int, input().split()))
print((H // A if H % A == 0 else H // A + 1))
| false | 66.666667 |
[
"-h, a = list(map(int, input().split()))",
"-l = 0",
"-while h > 0:",
"- h = h - a",
"- l += 1",
"-print(l)",
"+H, A = list(map(int, input().split()))",
"+print((H // A if H % A == 0 else H // A + 1))"
] | false | 0.040587 | 0.039403 | 1.030053 |
[
"s284115711",
"s623128987"
] |
u926678805
|
p03108
|
python
|
s799305764
|
s389293756
| 769 | 654 | 26,260 | 25,932 |
Accepted
|
Accepted
| 14.95 |
class UnionFind:
def __init__(self, n):
self.data=[-1 for i in range(n)]
def root(self,x):
if self.data[x]<0:
return x
else:
self.data[x]=self.root(self.data[x])
return self.data[x]
def uni(self,x,y):
x=self.root(x)
y=self.root(y)
if(x==y):
return
if self.data[y]<self.data[x]:
x,y=y,x
self.data[x]+= self.data[y]
self.data[y] = x
def same(self,x,y):
return self.root(x)==self.root(y)
def size(self,x):
return -self.data[self.root(x)]
n,m=map(int,input().split())
data=[]
for i in range(m):
a,b=map(int,input().split())
data.append((a,b))
data=data[::-1]
tmp=0
for i in range(n):
tmp+=i
ans=[tmp]
uf=UnionFind(n)
for i in range(m):
a,b=data[i]
if not uf.same(a-1,b-1):
x,y=uf.size(a-1),uf.size(b-1)
uf.uni(a-1,b-1)
ans.append(ans[-1]-x*y)
else:
ans.append(ans[-1])
print(*ans[:-1][::-1],sep='\n')
|
import sys
sys.setrecursionlimit(100000)
input=lambda : sys.stdin.readline().rstrip('\n')
class UnionFind:
def __init__(self, n):
self.data=[-1 for i in range(n)]
def root(self,x):
if self.data[x]<0:
return x
else:
self.data[x]=self.root(self.data[x])
return self.data[x]
def uni(self,x,y):
x=self.root(x)
y=self.root(y)
if(x==y):
return
if self.data[y]<self.data[x]:
x,y=y,x
self.data[x]+= self.data[y]
self.data[y] = x
def same(self,x,y):
return self.root(x)==self.root(y)
def size(self,x):
return -self.data[self.root(x)]
n,m=map(int,input().split())
data=[]
for i in range(m):
a,b=map(int,input().split())
data.append((a,b))
data=data[::-1]
tmp=0
for i in range(n):
tmp+=i
ans=[tmp]
uf=UnionFind(n)
for i in range(m):
a,b=data[i]
if not uf.same(a-1,b-1):
x,y=uf.size(a-1),uf.size(b-1)
uf.uni(a-1,b-1)
ans.append(ans[-1]-x*y)
else:
ans.append(ans[-1])
print(*ans[:-1][::-1],sep='\n')
| 47 | 51 | 1,072 | 1,171 |
class UnionFind:
def __init__(self, n):
self.data = [-1 for i in range(n)]
def root(self, x):
if self.data[x] < 0:
return x
else:
self.data[x] = self.root(self.data[x])
return self.data[x]
def uni(self, x, y):
x = self.root(x)
y = self.root(y)
if x == y:
return
if self.data[y] < self.data[x]:
x, y = y, x
self.data[x] += self.data[y]
self.data[y] = x
def same(self, x, y):
return self.root(x) == self.root(y)
def size(self, x):
return -self.data[self.root(x)]
n, m = map(int, input().split())
data = []
for i in range(m):
a, b = map(int, input().split())
data.append((a, b))
data = data[::-1]
tmp = 0
for i in range(n):
tmp += i
ans = [tmp]
uf = UnionFind(n)
for i in range(m):
a, b = data[i]
if not uf.same(a - 1, b - 1):
x, y = uf.size(a - 1), uf.size(b - 1)
uf.uni(a - 1, b - 1)
ans.append(ans[-1] - x * y)
else:
ans.append(ans[-1])
print(*ans[:-1][::-1], sep="\n")
|
import sys
sys.setrecursionlimit(100000)
input = lambda: sys.stdin.readline().rstrip("\n")
class UnionFind:
def __init__(self, n):
self.data = [-1 for i in range(n)]
def root(self, x):
if self.data[x] < 0:
return x
else:
self.data[x] = self.root(self.data[x])
return self.data[x]
def uni(self, x, y):
x = self.root(x)
y = self.root(y)
if x == y:
return
if self.data[y] < self.data[x]:
x, y = y, x
self.data[x] += self.data[y]
self.data[y] = x
def same(self, x, y):
return self.root(x) == self.root(y)
def size(self, x):
return -self.data[self.root(x)]
n, m = map(int, input().split())
data = []
for i in range(m):
a, b = map(int, input().split())
data.append((a, b))
data = data[::-1]
tmp = 0
for i in range(n):
tmp += i
ans = [tmp]
uf = UnionFind(n)
for i in range(m):
a, b = data[i]
if not uf.same(a - 1, b - 1):
x, y = uf.size(a - 1), uf.size(b - 1)
uf.uni(a - 1, b - 1)
ans.append(ans[-1] - x * y)
else:
ans.append(ans[-1])
print(*ans[:-1][::-1], sep="\n")
| false | 7.843137 |
[
"+import sys",
"+",
"+sys.setrecursionlimit(100000)",
"+input = lambda: sys.stdin.readline().rstrip(\"\\n\")",
"+",
"+"
] | false | 0.060421 | 0.071765 | 0.841923 |
[
"s799305764",
"s389293756"
] |
u347640436
|
p02793
|
python
|
s255645944
|
s523250169
| 316 | 287 | 49,856 | 49,688 |
Accepted
|
Accepted
| 9.18 |
# エラトステネスの篩, フェルマーの小定理
def make_prime_table(N):
sieve = list(range(N + 1))
sieve[0] = -1
sieve[1] = -1
for i in range(2, int(N ** 0.5) + 1):
if sieve[i] != i:
continue
for j in range(i * i, N + 1, i):
if sieve[j] == j:
sieve[j] = i
return sieve
N = int(eval(input()))
A = list(map(int, input().split()))
m = 1000000007
prime_table = make_prime_table(1000000)
lcm_factors = {}
for i in range(N):
t = []
a = A[i]
while a != 1:
if len(t) != 0 and t[-1][0] == prime_table[a]:
t[-1][1] += 1
else:
t.append([prime_table[a], 1])
a //= prime_table[a]
for k, v in t:
if k not in lcm_factors or lcm_factors[k] < v:
lcm_factors[k] = v
lcm = 1
for k in lcm_factors:
for i in range(lcm_factors[k]):
lcm *= k
lcm %= m
result = 0
for i in range(N):
result += lcm * pow(A[i], m - 2, m)
result %= m
print(result)
|
# エラトステネスの篩, フェルマーの小定理
def make_prime_table(n):
sieve = list(range(n + 1))
sieve[0] = -1
sieve[1] = -1
for i in range(2, int(n ** 0.5) + 1):
if sieve[i] != i:
continue
for j in range(i * i, n + 1, i):
if sieve[j] == j:
sieve[j] = i
return sieve
def prime_factorize(n):
result = []
while n != 1:
p = prime_table[n]
c = 0
while n % p == 0:
n //= p
c += 1
result.append((p, c))
return result
N = int(eval(input()))
A = list(map(int, input().split()))
m = 1000000007
prime_table = make_prime_table(10 ** 6)
lcm_factors = {}
for a in A:
for p, c in prime_factorize(a):
if p not in lcm_factors or lcm_factors[p] < c:
lcm_factors[p] = c
lcm = 1
for p in lcm_factors:
lcm *= pow(p, lcm_factors[p], m)
lcm %= m
result = 0
for i in range(N):
result += lcm * pow(A[i], m - 2, m)
result %= m
print(result)
| 46 | 49 | 1,030 | 1,029 |
# エラトステネスの篩, フェルマーの小定理
def make_prime_table(N):
sieve = list(range(N + 1))
sieve[0] = -1
sieve[1] = -1
for i in range(2, int(N**0.5) + 1):
if sieve[i] != i:
continue
for j in range(i * i, N + 1, i):
if sieve[j] == j:
sieve[j] = i
return sieve
N = int(eval(input()))
A = list(map(int, input().split()))
m = 1000000007
prime_table = make_prime_table(1000000)
lcm_factors = {}
for i in range(N):
t = []
a = A[i]
while a != 1:
if len(t) != 0 and t[-1][0] == prime_table[a]:
t[-1][1] += 1
else:
t.append([prime_table[a], 1])
a //= prime_table[a]
for k, v in t:
if k not in lcm_factors or lcm_factors[k] < v:
lcm_factors[k] = v
lcm = 1
for k in lcm_factors:
for i in range(lcm_factors[k]):
lcm *= k
lcm %= m
result = 0
for i in range(N):
result += lcm * pow(A[i], m - 2, m)
result %= m
print(result)
|
# エラトステネスの篩, フェルマーの小定理
def make_prime_table(n):
sieve = list(range(n + 1))
sieve[0] = -1
sieve[1] = -1
for i in range(2, int(n**0.5) + 1):
if sieve[i] != i:
continue
for j in range(i * i, n + 1, i):
if sieve[j] == j:
sieve[j] = i
return sieve
def prime_factorize(n):
result = []
while n != 1:
p = prime_table[n]
c = 0
while n % p == 0:
n //= p
c += 1
result.append((p, c))
return result
N = int(eval(input()))
A = list(map(int, input().split()))
m = 1000000007
prime_table = make_prime_table(10**6)
lcm_factors = {}
for a in A:
for p, c in prime_factorize(a):
if p not in lcm_factors or lcm_factors[p] < c:
lcm_factors[p] = c
lcm = 1
for p in lcm_factors:
lcm *= pow(p, lcm_factors[p], m)
lcm %= m
result = 0
for i in range(N):
result += lcm * pow(A[i], m - 2, m)
result %= m
print(result)
| false | 6.122449 |
[
"-def make_prime_table(N):",
"- sieve = list(range(N + 1))",
"+def make_prime_table(n):",
"+ sieve = list(range(n + 1))",
"- for i in range(2, int(N**0.5) + 1):",
"+ for i in range(2, int(n**0.5) + 1):",
"- for j in range(i * i, N + 1, i):",
"+ for j in range(i * i, n + 1, i):",
"+def prime_factorize(n):",
"+ result = []",
"+ while n != 1:",
"+ p = prime_table[n]",
"+ c = 0",
"+ while n % p == 0:",
"+ n //= p",
"+ c += 1",
"+ result.append((p, c))",
"+ return result",
"+",
"+",
"-prime_table = make_prime_table(1000000)",
"+prime_table = make_prime_table(10**6)",
"-for i in range(N):",
"- t = []",
"- a = A[i]",
"- while a != 1:",
"- if len(t) != 0 and t[-1][0] == prime_table[a]:",
"- t[-1][1] += 1",
"- else:",
"- t.append([prime_table[a], 1])",
"- a //= prime_table[a]",
"- for k, v in t:",
"- if k not in lcm_factors or lcm_factors[k] < v:",
"- lcm_factors[k] = v",
"+for a in A:",
"+ for p, c in prime_factorize(a):",
"+ if p not in lcm_factors or lcm_factors[p] < c:",
"+ lcm_factors[p] = c",
"-for k in lcm_factors:",
"- for i in range(lcm_factors[k]):",
"- lcm *= k",
"- lcm %= m",
"+for p in lcm_factors:",
"+ lcm *= pow(p, lcm_factors[p], m)",
"+ lcm %= m"
] | false | 0.694248 | 0.650227 | 1.067702 |
[
"s255645944",
"s523250169"
] |
u852517668
|
p03436
|
python
|
s895802565
|
s012859514
| 50 | 29 | 3,952 | 3,436 |
Accepted
|
Accepted
| 42 |
import queue
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
H, W = list(map(int, input().split()))
field = [eval(input()) for _ in range(H)]
dist = [[-1] * W for _ in range(H)]
que = queue.Queue()
que.put((0, 0))
dist[0][0] = 0
while not que.empty():
y, x = que.get()
for i in range(4):
ny, nx = y + dy[i], x + dx[i]
if nx < 0 or nx >= W or ny < 0 or ny >= H:
continue
if field[ny][nx] == '#':
continue
if dist[ny][nx] != -1:
continue
dist[ny][nx] = dist[y][x] + 1
que.put((ny, nx))
count = sum([f.count('#') for f in field])
if dist[H - 1][W - 1] != -1:
print((H * W - count - dist[H - 1][W - 1] - 1))
else:
print((-1))
|
from collections import deque
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
H, W = list(map(int, input().split()))
field = [eval(input()) for _ in range(H)]
dist = [[-1] * W for _ in range(H)]
que = deque()
que.append((0, 0))
dist[0][0] = 0
while len(que) > 0:
y, x = que.popleft()
for i in range(4):
ny, nx = y + dy[i], x + dx[i]
if nx < 0 or nx >= W or ny < 0 or ny >= H:
continue
if field[ny][nx] == '#':
continue
if dist[ny][nx] != -1:
continue
dist[ny][nx] = dist[y][x] + 1
que.append((ny, nx))
count = sum([f.count('#') for f in field])
if dist[H - 1][W - 1] != -1:
print((H * W - count - dist[H - 1][W - 1] - 1))
else:
print((-1))
| 31 | 31 | 691 | 708 |
import queue
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
H, W = list(map(int, input().split()))
field = [eval(input()) for _ in range(H)]
dist = [[-1] * W for _ in range(H)]
que = queue.Queue()
que.put((0, 0))
dist[0][0] = 0
while not que.empty():
y, x = que.get()
for i in range(4):
ny, nx = y + dy[i], x + dx[i]
if nx < 0 or nx >= W or ny < 0 or ny >= H:
continue
if field[ny][nx] == "#":
continue
if dist[ny][nx] != -1:
continue
dist[ny][nx] = dist[y][x] + 1
que.put((ny, nx))
count = sum([f.count("#") for f in field])
if dist[H - 1][W - 1] != -1:
print((H * W - count - dist[H - 1][W - 1] - 1))
else:
print((-1))
|
from collections import deque
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
H, W = list(map(int, input().split()))
field = [eval(input()) for _ in range(H)]
dist = [[-1] * W for _ in range(H)]
que = deque()
que.append((0, 0))
dist[0][0] = 0
while len(que) > 0:
y, x = que.popleft()
for i in range(4):
ny, nx = y + dy[i], x + dx[i]
if nx < 0 or nx >= W or ny < 0 or ny >= H:
continue
if field[ny][nx] == "#":
continue
if dist[ny][nx] != -1:
continue
dist[ny][nx] = dist[y][x] + 1
que.append((ny, nx))
count = sum([f.count("#") for f in field])
if dist[H - 1][W - 1] != -1:
print((H * W - count - dist[H - 1][W - 1] - 1))
else:
print((-1))
| false | 0 |
[
"-import queue",
"+from collections import deque",
"-que = queue.Queue()",
"-que.put((0, 0))",
"+que = deque()",
"+que.append((0, 0))",
"-while not que.empty():",
"- y, x = que.get()",
"+while len(que) > 0:",
"+ y, x = que.popleft()",
"- que.put((ny, nx))",
"+ que.append((ny, nx))"
] | false | 0.083485 | 0.060299 | 1.384512 |
[
"s895802565",
"s012859514"
] |
u790710233
|
p02582
|
python
|
s626312904
|
s671688220
| 31 | 25 | 8,952 | 9,016 |
Accepted
|
Accepted
| 19.35 |
s = input().split('S')
print((max(list(map(len, s)))))
|
print((max(list(map(len, input().split('S'))))))
| 2 | 1 | 48 | 41 |
s = input().split("S")
print((max(list(map(len, s)))))
|
print((max(list(map(len, input().split("S"))))))
| false | 50 |
[
"-s = input().split(\"S\")",
"-print((max(list(map(len, s)))))",
"+print((max(list(map(len, input().split(\"S\"))))))"
] | false | 0.038288 | 0.037229 | 1.028437 |
[
"s626312904",
"s671688220"
] |
u073852194
|
p03806
|
python
|
s950521916
|
s661925484
| 865 | 539 | 159,388 | 99,292 |
Accepted
|
Accepted
| 37.69 |
INF = 10**18
def solve(N, Ma, Mb, sol):
if N % 2 == 1:
sol.append((0, 0, 0))
N += 1
M = N // 2
sol1 = sol[:M]
sol2 = sol[M:]
S1 = []
D = dict()
res = INF
for i in range(2**M):
A1, B1, C1 = 0, 0, 0
A2, B2, C2 = 0, 0, 0
for j in range(M):
if (i >> j) & 1:
a1, b1, c1 = sol1[j]
a2, b2, c2 = sol2[j]
A1 += a1
B1 += b1
C1 += c1
A2 += a2
B2 += b2
C2 += c2
S1.append((A1, B1, C1))
x = Mb * A2 - Ma * B2
if x == 0 and C2 > 0:
res = min(res, C2)
if not x in D or 0 < C2 < D[x]:
D[x] = C2
for i in range(2**M):
a, b, c = S1[i]
x = Ma * b - Mb * a
if x == 0 and c > 0:
res = min(res, c)
if x in D and D[x] + c > 0:
res = min(res, D[x] + c)
return res
N, Ma, Mb = list(map(int, input().split()))
sol = [tuple(map(int, input().split())) for _ in range(N)]
res = solve(N, Ma, Mb, sol)
print((res if res != INF else -1))
|
INF = 10**18
N, Ma, Mb = list(map(int, input().split()))
dp = [[[INF for k in range(401)] for j in range(401)] for i in range(N + 1)]
dp[0][0][0] = 0
for i in range(N):
a, b, c = list(map(int, input().split()))
for j in range(400):
for k in range(400):
dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j][k])
if j + a <= 400 and k + b <= 400:
dp[i + 1][j + a][k + b] = min(dp[i + 1][j + a][k + b], dp[i][j][k] + c)
res = INF
for j in range(1, 401):
for k in range(1, 401):
if k * Ma == j * Mb:
res = min(res, dp[N][j][k])
print((res if res != INF else -1))
| 52 | 23 | 1,190 | 646 |
INF = 10**18
def solve(N, Ma, Mb, sol):
if N % 2 == 1:
sol.append((0, 0, 0))
N += 1
M = N // 2
sol1 = sol[:M]
sol2 = sol[M:]
S1 = []
D = dict()
res = INF
for i in range(2**M):
A1, B1, C1 = 0, 0, 0
A2, B2, C2 = 0, 0, 0
for j in range(M):
if (i >> j) & 1:
a1, b1, c1 = sol1[j]
a2, b2, c2 = sol2[j]
A1 += a1
B1 += b1
C1 += c1
A2 += a2
B2 += b2
C2 += c2
S1.append((A1, B1, C1))
x = Mb * A2 - Ma * B2
if x == 0 and C2 > 0:
res = min(res, C2)
if not x in D or 0 < C2 < D[x]:
D[x] = C2
for i in range(2**M):
a, b, c = S1[i]
x = Ma * b - Mb * a
if x == 0 and c > 0:
res = min(res, c)
if x in D and D[x] + c > 0:
res = min(res, D[x] + c)
return res
N, Ma, Mb = list(map(int, input().split()))
sol = [tuple(map(int, input().split())) for _ in range(N)]
res = solve(N, Ma, Mb, sol)
print((res if res != INF else -1))
|
INF = 10**18
N, Ma, Mb = list(map(int, input().split()))
dp = [[[INF for k in range(401)] for j in range(401)] for i in range(N + 1)]
dp[0][0][0] = 0
for i in range(N):
a, b, c = list(map(int, input().split()))
for j in range(400):
for k in range(400):
dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j][k])
if j + a <= 400 and k + b <= 400:
dp[i + 1][j + a][k + b] = min(dp[i + 1][j + a][k + b], dp[i][j][k] + c)
res = INF
for j in range(1, 401):
for k in range(1, 401):
if k * Ma == j * Mb:
res = min(res, dp[N][j][k])
print((res if res != INF else -1))
| false | 55.769231 |
[
"-",
"-",
"-def solve(N, Ma, Mb, sol):",
"- if N % 2 == 1:",
"- sol.append((0, 0, 0))",
"- N += 1",
"- M = N // 2",
"- sol1 = sol[:M]",
"- sol2 = sol[M:]",
"- S1 = []",
"- D = dict()",
"- res = INF",
"- for i in range(2**M):",
"- A1, B1, C1 = 0, 0, 0",
"- A2, B2, C2 = 0, 0, 0",
"- for j in range(M):",
"- if (i >> j) & 1:",
"- a1, b1, c1 = sol1[j]",
"- a2, b2, c2 = sol2[j]",
"- A1 += a1",
"- B1 += b1",
"- C1 += c1",
"- A2 += a2",
"- B2 += b2",
"- C2 += c2",
"- S1.append((A1, B1, C1))",
"- x = Mb * A2 - Ma * B2",
"- if x == 0 and C2 > 0:",
"- res = min(res, C2)",
"- if not x in D or 0 < C2 < D[x]:",
"- D[x] = C2",
"- for i in range(2**M):",
"- a, b, c = S1[i]",
"- x = Ma * b - Mb * a",
"- if x == 0 and c > 0:",
"- res = min(res, c)",
"- if x in D and D[x] + c > 0:",
"- res = min(res, D[x] + c)",
"- return res",
"-",
"-",
"-sol = [tuple(map(int, input().split())) for _ in range(N)]",
"-res = solve(N, Ma, Mb, sol)",
"+dp = [[[INF for k in range(401)] for j in range(401)] for i in range(N + 1)]",
"+dp[0][0][0] = 0",
"+for i in range(N):",
"+ a, b, c = list(map(int, input().split()))",
"+ for j in range(400):",
"+ for k in range(400):",
"+ dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j][k])",
"+ if j + a <= 400 and k + b <= 400:",
"+ dp[i + 1][j + a][k + b] = min(dp[i + 1][j + a][k + b], dp[i][j][k] + c)",
"+res = INF",
"+for j in range(1, 401):",
"+ for k in range(1, 401):",
"+ if k * Ma == j * Mb:",
"+ res = min(res, dp[N][j][k])"
] | false | 0.042788 | 0.689203 | 0.062083 |
[
"s950521916",
"s661925484"
] |
u808569469
|
p03610
|
python
|
s214710436
|
s532647090
| 45 | 28 | 9,380 | 9,016 |
Accepted
|
Accepted
| 37.78 |
s = eval(input())
s_odd = []
for i in range(0, len(s)):
if i % 2 == 0:
s_odd.append(s[i])
print(("".join(s_odd)))
|
S = str(eval(input()))
print((S[::2]))
| 8 | 2 | 127 | 31 |
s = eval(input())
s_odd = []
for i in range(0, len(s)):
if i % 2 == 0:
s_odd.append(s[i])
print(("".join(s_odd)))
|
S = str(eval(input()))
print((S[::2]))
| false | 75 |
[
"-s = eval(input())",
"-s_odd = []",
"-for i in range(0, len(s)):",
"- if i % 2 == 0:",
"- s_odd.append(s[i])",
"-print((\"\".join(s_odd)))",
"+S = str(eval(input()))",
"+print((S[::2]))"
] | false | 0.045777 | 0.04008 | 1.142136 |
[
"s214710436",
"s532647090"
] |
u244742296
|
p02386
|
python
|
s469081526
|
s189736107
| 260 | 190 | 6,824 | 6,812 |
Accepted
|
Accepted
| 26.92 |
class Dice(object):
def __init__(self, s1, s2, s3, s4, s5, s6):
self.s1 = s1
self.s2 = s2
self.s3 = s3
self.s4 = s4
self.s5 = s5
self.s6 = s6
def east(self):
prev_s6 = self.s6
self.s6 = self.s3
self.s3 = self.s1
self.s1 = self.s4
self.s4 = prev_s6
def west(self):
prev_s6 = self.s6
self.s6 = self.s4
self.s4 = self.s1
self.s1 = self.s3
self.s3 = prev_s6
def north(self):
prev_s6 = self.s6
self.s6 = self.s5
self.s5 = self.s1
self.s1 = self.s2
self.s2 = prev_s6
def south(self):
prev_s6 = self.s6
self.s6 = self.s2
self.s2 = self.s1
self.s1 = self.s5
self.s5 = prev_s6
def rotate(self):
prev_s2 = self.s2
self.s2 = self.s4
self.s4 = self.s5
self.s5 = self.s3
self.s3 = prev_s2
def top(self):
return self.s1
def front(self):
return self.s2
def right(self):
return self.s3
def isSameDice(self, anotherDice):
if self.s1 == anotherDice.s1 and \
self.s2 == anotherDice.s2 and \
self.s3 == anotherDice.s3 and \
self.s4 == anotherDice.s4 and \
self.s5 == anotherDice.s5 and \
self.s6 == anotherDice.s6:
return True
return False
dices = []
n = int(input())
for i in range(n):
s1, s2, s3, s4, s5, s6 = map(int, input().split())
dices.append(Dice(s1, s2, s3, s4, s5, s6))
flag = False
for i in range(n):
j = i+1
while j < n:
for k in range(6):
if k % 2 == 0:
dices[j].north()
else:
dices[j].west()
for l in range(4):
dices[j].rotate()
if dices[j].isSameDice(dices[i]):
flag = True
break
if flag:
break
if flag:
break
j += 1
if flag:
break
if flag:
print("No")
else:
print("Yes")
|
class Dice(object):
def __init__(self, s1, s2, s3, s4, s5, s6):
self.s1 = s1
self.s2 = s2
self.s3 = s3
self.s4 = s4
self.s5 = s5
self.s6 = s6
def east(self):
prev_s6 = self.s6
self.s6 = self.s3
self.s3 = self.s1
self.s1 = self.s4
self.s4 = prev_s6
def west(self):
prev_s6 = self.s6
self.s6 = self.s4
self.s4 = self.s1
self.s1 = self.s3
self.s3 = prev_s6
def north(self):
prev_s6 = self.s6
self.s6 = self.s5
self.s5 = self.s1
self.s1 = self.s2
self.s2 = prev_s6
def south(self):
prev_s6 = self.s6
self.s6 = self.s2
self.s2 = self.s1
self.s1 = self.s5
self.s5 = prev_s6
def rotate(self):
prev_s2 = self.s2
self.s2 = self.s4
self.s4 = self.s5
self.s5 = self.s3
self.s3 = prev_s2
def top(self):
return self.s1
def front(self):
return self.s2
def right(self):
return self.s3
def isSameDice(self, anotherDice):
for i in range(6):
if i % 2 == 0:
self.north()
else:
self.west()
for j in range(4):
self.rotate()
if self.s1 == anotherDice.s1 and \
self.s2 == anotherDice.s2 and \
self.s3 == anotherDice.s3 and \
self.s4 == anotherDice.s4 and \
self.s5 == anotherDice.s5 and \
self.s6 == anotherDice.s6:
return True
return False
dices = []
n = int(input())
for i in range(n):
s1, s2, s3, s4, s5, s6 = map(int, input().split())
dices.append(Dice(s1, s2, s3, s4, s5, s6))
flag = False
for i in range(n):
j = i+1
while j < n:
if dices[i].isSameDice(dices[j]):
flag = True
break
j += 1
if flag:
print("No")
else:
print("Yes")
| 89 | 82 | 2,196 | 2,103 |
class Dice(object):
def __init__(self, s1, s2, s3, s4, s5, s6):
self.s1 = s1
self.s2 = s2
self.s3 = s3
self.s4 = s4
self.s5 = s5
self.s6 = s6
def east(self):
prev_s6 = self.s6
self.s6 = self.s3
self.s3 = self.s1
self.s1 = self.s4
self.s4 = prev_s6
def west(self):
prev_s6 = self.s6
self.s6 = self.s4
self.s4 = self.s1
self.s1 = self.s3
self.s3 = prev_s6
def north(self):
prev_s6 = self.s6
self.s6 = self.s5
self.s5 = self.s1
self.s1 = self.s2
self.s2 = prev_s6
def south(self):
prev_s6 = self.s6
self.s6 = self.s2
self.s2 = self.s1
self.s1 = self.s5
self.s5 = prev_s6
def rotate(self):
prev_s2 = self.s2
self.s2 = self.s4
self.s4 = self.s5
self.s5 = self.s3
self.s3 = prev_s2
def top(self):
return self.s1
def front(self):
return self.s2
def right(self):
return self.s3
def isSameDice(self, anotherDice):
if (
self.s1 == anotherDice.s1
and self.s2 == anotherDice.s2
and self.s3 == anotherDice.s3
and self.s4 == anotherDice.s4
and self.s5 == anotherDice.s5
and self.s6 == anotherDice.s6
):
return True
return False
dices = []
n = int(input())
for i in range(n):
s1, s2, s3, s4, s5, s6 = map(int, input().split())
dices.append(Dice(s1, s2, s3, s4, s5, s6))
flag = False
for i in range(n):
j = i + 1
while j < n:
for k in range(6):
if k % 2 == 0:
dices[j].north()
else:
dices[j].west()
for l in range(4):
dices[j].rotate()
if dices[j].isSameDice(dices[i]):
flag = True
break
if flag:
break
if flag:
break
j += 1
if flag:
break
if flag:
print("No")
else:
print("Yes")
|
class Dice(object):
def __init__(self, s1, s2, s3, s4, s5, s6):
self.s1 = s1
self.s2 = s2
self.s3 = s3
self.s4 = s4
self.s5 = s5
self.s6 = s6
def east(self):
prev_s6 = self.s6
self.s6 = self.s3
self.s3 = self.s1
self.s1 = self.s4
self.s4 = prev_s6
def west(self):
prev_s6 = self.s6
self.s6 = self.s4
self.s4 = self.s1
self.s1 = self.s3
self.s3 = prev_s6
def north(self):
prev_s6 = self.s6
self.s6 = self.s5
self.s5 = self.s1
self.s1 = self.s2
self.s2 = prev_s6
def south(self):
prev_s6 = self.s6
self.s6 = self.s2
self.s2 = self.s1
self.s1 = self.s5
self.s5 = prev_s6
def rotate(self):
prev_s2 = self.s2
self.s2 = self.s4
self.s4 = self.s5
self.s5 = self.s3
self.s3 = prev_s2
def top(self):
return self.s1
def front(self):
return self.s2
def right(self):
return self.s3
def isSameDice(self, anotherDice):
for i in range(6):
if i % 2 == 0:
self.north()
else:
self.west()
for j in range(4):
self.rotate()
if (
self.s1 == anotherDice.s1
and self.s2 == anotherDice.s2
and self.s3 == anotherDice.s3
and self.s4 == anotherDice.s4
and self.s5 == anotherDice.s5
and self.s6 == anotherDice.s6
):
return True
return False
dices = []
n = int(input())
for i in range(n):
s1, s2, s3, s4, s5, s6 = map(int, input().split())
dices.append(Dice(s1, s2, s3, s4, s5, s6))
flag = False
for i in range(n):
j = i + 1
while j < n:
if dices[i].isSameDice(dices[j]):
flag = True
break
j += 1
if flag:
print("No")
else:
print("Yes")
| false | 7.865169 |
[
"- if (",
"- self.s1 == anotherDice.s1",
"- and self.s2 == anotherDice.s2",
"- and self.s3 == anotherDice.s3",
"- and self.s4 == anotherDice.s4",
"- and self.s5 == anotherDice.s5",
"- and self.s6 == anotherDice.s6",
"- ):",
"- return True",
"+ for i in range(6):",
"+ if i % 2 == 0:",
"+ self.north()",
"+ else:",
"+ self.west()",
"+ for j in range(4):",
"+ self.rotate()",
"+ if (",
"+ self.s1 == anotherDice.s1",
"+ and self.s2 == anotherDice.s2",
"+ and self.s3 == anotherDice.s3",
"+ and self.s4 == anotherDice.s4",
"+ and self.s5 == anotherDice.s5",
"+ and self.s6 == anotherDice.s6",
"+ ):",
"+ return True",
"- for k in range(6):",
"- if k % 2 == 0:",
"- dices[j].north()",
"- else:",
"- dices[j].west()",
"- for l in range(4):",
"- dices[j].rotate()",
"- if dices[j].isSameDice(dices[i]):",
"- flag = True",
"- break",
"- if flag:",
"- break",
"- if flag:",
"+ if dices[i].isSameDice(dices[j]):",
"+ flag = True",
"- if flag:",
"- break"
] | false | 0.042091 | 0.074448 | 0.565382 |
[
"s469081526",
"s189736107"
] |
u353895424
|
p02939
|
python
|
s050641475
|
s479023710
| 103 | 88 | 9,636 | 9,404 |
Accepted
|
Accepted
| 14.56 |
"""
aabbaa
aa b ba a
a ab b aa
"""
s = list(eval(input()))
n = len(s)
hst = []
sk = ""
for i in range(n):
sk += s[i]
if i == 0:
hst.append(sk)
sk = ""
elif hst[-1] != sk:
hst.append(sk)
sk = ""
print((len(hst)))
|
s = list(eval(input()))
n = len(s)
hst = ["#"]
sk = ""
for i in range(n):
sk += s[i]
if hst[-1] != sk:
hst.append(sk)
sk = ""
print((len(hst)-1))
| 22 | 13 | 272 | 176 |
"""
aabbaa
aa b ba a
a ab b aa
"""
s = list(eval(input()))
n = len(s)
hst = []
sk = ""
for i in range(n):
sk += s[i]
if i == 0:
hst.append(sk)
sk = ""
elif hst[-1] != sk:
hst.append(sk)
sk = ""
print((len(hst)))
|
s = list(eval(input()))
n = len(s)
hst = ["#"]
sk = ""
for i in range(n):
sk += s[i]
if hst[-1] != sk:
hst.append(sk)
sk = ""
print((len(hst) - 1))
| false | 40.909091 |
[
"-\"\"\"",
"-aabbaa",
"-aa b ba a",
"-a ab b aa",
"-\"\"\"",
"-hst = []",
"+hst = [\"#\"]",
"- if i == 0:",
"+ if hst[-1] != sk:",
"- elif hst[-1] != sk:",
"- hst.append(sk)",
"- sk = \"\"",
"-print((len(hst)))",
"+print((len(hst) - 1))"
] | false | 0.048502 | 0.10963 | 0.442417 |
[
"s050641475",
"s479023710"
] |
u010090035
|
p02831
|
python
|
s221915486
|
s023411233
| 35 | 17 | 5,048 | 3,064 |
Accepted
|
Accepted
| 51.43 |
from fractions import gcd
a,b=list(map(int,input().split()))
print((a*b//gcd(a,b)))
|
a,b=list(map(int,input().split()))
#a,bの最大公約数
def gcd(a,b):
if(b==0):
return a
else:
return gcd(b, a%b)
#a,bの最小公倍数
def lcm(a,b):
return a*b//gcd(a,b)
print((lcm(a,b)))
| 3 | 14 | 77 | 203 |
from fractions import gcd
a, b = list(map(int, input().split()))
print((a * b // gcd(a, b)))
|
a, b = list(map(int, input().split()))
# a,bの最大公約数
def gcd(a, b):
if b == 0:
return a
else:
return gcd(b, a % b)
# a,bの最小公倍数
def lcm(a, b):
return a * b // gcd(a, b)
print((lcm(a, b)))
| false | 78.571429 |
[
"-from fractions import gcd",
"+a, b = list(map(int, input().split()))",
"+# a,bの最大公約数",
"+def gcd(a, b):",
"+ if b == 0:",
"+ return a",
"+ else:",
"+ return gcd(b, a % b)",
"-a, b = list(map(int, input().split()))",
"-print((a * b // gcd(a, b)))",
"+",
"+# a,bの最小公倍数",
"+def lcm(a, b):",
"+ return a * b // gcd(a, b)",
"+",
"+",
"+print((lcm(a, b)))"
] | false | 0.046542 | 0.076896 | 0.605257 |
[
"s221915486",
"s023411233"
] |
u968404618
|
p03624
|
python
|
s997792366
|
s880051142
| 20 | 17 | 3,316 | 3,188 |
Accepted
|
Accepted
| 15 |
S = eval(input())
X= ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
ans = ''
for x in X:
if x not in S:
ans = x
break
if ans == '':
ans = 'None'
print(ans)
|
S = eval(input())
X = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
ans = ''
for x in X:
if x not in S:
ans = x
break
if ans:
print((ans[0]))
else:
print('None')
| 15 | 15 | 282 | 292 |
S = eval(input())
X = [
"a",
"b",
"c",
"d",
"e",
"f",
"g",
"h",
"i",
"j",
"k",
"l",
"m",
"n",
"o",
"p",
"q",
"r",
"s",
"t",
"u",
"v",
"w",
"x",
"y",
"z",
]
ans = ""
for x in X:
if x not in S:
ans = x
break
if ans == "":
ans = "None"
print(ans)
|
S = eval(input())
X = [
"a",
"b",
"c",
"d",
"e",
"f",
"g",
"h",
"i",
"j",
"k",
"l",
"m",
"n",
"o",
"p",
"q",
"r",
"s",
"t",
"u",
"v",
"w",
"x",
"y",
"z",
]
ans = ""
for x in X:
if x not in S:
ans = x
break
if ans:
print((ans[0]))
else:
print("None")
| false | 0 |
[
"-if ans == \"\":",
"- ans = \"None\"",
"-print(ans)",
"+if ans:",
"+ print((ans[0]))",
"+else:",
"+ print(\"None\")"
] | false | 0.043826 | 0.065305 | 0.6711 |
[
"s997792366",
"s880051142"
] |
u223133214
|
p02923
|
python
|
s329843958
|
s111525517
| 224 | 128 | 63,856 | 85,124 |
Accepted
|
Accepted
| 42.86 |
N = int(eval(input()))
H = list(map(int, input().split()))
ans = 0
cnt = 0
for i in range(0, N-1):
if H[i] >= H[i + 1]:
cnt += 1
ans = max(cnt, ans)
else:
cnt = 0
print(ans)
|
n = int(eval(input()))
H = list(map(int, input().split()))
ans = 0
H_r = H[::-1]
cnt = 0
for i in range(n - 1):
now = H_r[i]
nex = H_r[i + 1]
if now <= nex:
cnt += 1
ans = max(ans, cnt)
else:
cnt = 0
nex = now
print(ans)
| 12 | 17 | 212 | 277 |
N = int(eval(input()))
H = list(map(int, input().split()))
ans = 0
cnt = 0
for i in range(0, N - 1):
if H[i] >= H[i + 1]:
cnt += 1
ans = max(cnt, ans)
else:
cnt = 0
print(ans)
|
n = int(eval(input()))
H = list(map(int, input().split()))
ans = 0
H_r = H[::-1]
cnt = 0
for i in range(n - 1):
now = H_r[i]
nex = H_r[i + 1]
if now <= nex:
cnt += 1
ans = max(ans, cnt)
else:
cnt = 0
nex = now
print(ans)
| false | 29.411765 |
[
"-N = int(eval(input()))",
"+n = int(eval(input()))",
"+H_r = H[::-1]",
"-for i in range(0, N - 1):",
"- if H[i] >= H[i + 1]:",
"+for i in range(n - 1):",
"+ now = H_r[i]",
"+ nex = H_r[i + 1]",
"+ if now <= nex:",
"- ans = max(cnt, ans)",
"+ ans = max(ans, cnt)",
"+ nex = now"
] | false | 0.042483 | 0.084798 | 0.500991 |
[
"s329843958",
"s111525517"
] |
u086503932
|
p02681
|
python
|
s453659687
|
s920366460
| 23 | 21 | 9,084 | 8,980 |
Accepted
|
Accepted
| 8.7 |
#!/usr/bin/env python3
def main():
S = eval(input())
T = eval(input())
if S == T[:len(S)]:
print('Yes')
else:
print('No')
main()
|
#!/usr/bin/env python3
def main():
S = eval(input())
T = eval(input())
if S == T[:len(S)]:
print('Yes')
else:
print('No')
if __name__ == "__main__":
main()
| 12 | 13 | 163 | 195 |
#!/usr/bin/env python3
def main():
S = eval(input())
T = eval(input())
if S == T[: len(S)]:
print("Yes")
else:
print("No")
main()
|
#!/usr/bin/env python3
def main():
S = eval(input())
T = eval(input())
if S == T[: len(S)]:
print("Yes")
else:
print("No")
if __name__ == "__main__":
main()
| false | 7.692308 |
[
"-main()",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.037581 | 0.073324 | 0.512532 |
[
"s453659687",
"s920366460"
] |
u764600134
|
p03108
|
python
|
s700760308
|
s736216805
| 778 | 705 | 27,172 | 27,188 |
Accepted
|
Accepted
| 9.38 |
# -*- coding: utf-8 -*-
"""
D - Decayed Bridges
https://atcoder.jp/contests/abc120/tasks/abc120_d#
"""
import sys
class DisjointSet(object):
def __init__(self, n):
self.rank = []
self.p = []
self.size = []
for i in range(n+1):
self.makeSet(i)
def makeSet(self, x):
self.p.insert(x, x)
self.rank.insert(x, 0)
self.size.insert(x, 1)
def same(self, x, y):
return self.findSet(x) == self.findSet(y)
def unite(self, x, y):
self.link(self.findSet(x), self.findSet(y))
def link(self, x, y):
if self.rank[x] > self.rank[y]:
self.size[self.p[x]] += self.size[self.p[y]]
self.p[y] = self.findSet(x)
else:
self.size[self.p[y]] += self.size[self.p[x]]
self.p[x] = self.findSet(y)
if self.rank[x] == self.rank[y]:
self.rank[y] += 1
def findSet(self, x):
if x != self.p[x]:
self.p[x] = self.findSet(self.p[x])
return self.p[x]
def solve(bridges, N, M):
ans = [(N**2 - N)//2]
d = DisjointSet(N)
for f, t in reversed(bridges):
if d.same(f, t):
ans.append(ans[-1])
else:
n1 = d.size[d.p[f]]
n2 = d.size[d.p[t]]
ans.append(ans[-1] - (n1*n2))
d.unite(f, t)
return ans
def main(args):
N, M = list(map(int, input().split()))
bridges = []
for _ in range(M):
f, t = list(map(int, input().split()))
bridges.append([f, t])
ans = solve(bridges, N, M)
for a in (ans[::-1])[1:]:
print(a)
if __name__ == '__main__':
main(sys.argv[1:])
|
# -*- coding: utf-8 -*-
"""
D - Decayed Bridges
https://atcoder.jp/contests/abc120/tasks/abc120_d#
AC
"""
import sys
class DisjointSet(object):
def __init__(self, n):
self.rank = [0] * n
self.p = list(range(n))
self.size = [1] * n
def same(self, x, y):
return self.findSet(x) == self.findSet(y)
def unite(self, x, y):
self.link(self.findSet(x), self.findSet(y))
def link(self, x, y):
if self.rank[x] > self.rank[y]:
self.size[self.p[x]] += self.size[self.p[y]]
self.p[y] = self.findSet(x)
else:
self.size[self.p[y]] += self.size[self.p[x]]
self.p[x] = self.findSet(y)
if self.rank[x] == self.rank[y]:
self.rank[y] += 1
def findSet(self, x):
if x != self.p[x]:
self.p[x] = self.findSet(self.p[x])
return self.p[x]
def solve(bridges, N, M):
ans = [(N**2 - N)//2]
d = DisjointSet(N+1)
for f, t in reversed(bridges):
if d.same(f, t):
ans.append(ans[-1])
else:
n1 = d.size[d.p[f]]
n2 = d.size[d.p[t]]
ans.append(ans[-1] - (n1*n2))
d.unite(f, t)
return ans
def main(args):
N, M = list(map(int, input().split()))
bridges = []
for _ in range(M):
f, t = list(map(int, input().split()))
bridges.append([f, t])
ans = solve(bridges, N, M)
for a in (ans[::-1])[1:]:
print(a)
if __name__ == '__main__':
main(sys.argv[1:])
| 71 | 64 | 1,746 | 1,591 |
# -*- coding: utf-8 -*-
"""
D - Decayed Bridges
https://atcoder.jp/contests/abc120/tasks/abc120_d#
"""
import sys
class DisjointSet(object):
def __init__(self, n):
self.rank = []
self.p = []
self.size = []
for i in range(n + 1):
self.makeSet(i)
def makeSet(self, x):
self.p.insert(x, x)
self.rank.insert(x, 0)
self.size.insert(x, 1)
def same(self, x, y):
return self.findSet(x) == self.findSet(y)
def unite(self, x, y):
self.link(self.findSet(x), self.findSet(y))
def link(self, x, y):
if self.rank[x] > self.rank[y]:
self.size[self.p[x]] += self.size[self.p[y]]
self.p[y] = self.findSet(x)
else:
self.size[self.p[y]] += self.size[self.p[x]]
self.p[x] = self.findSet(y)
if self.rank[x] == self.rank[y]:
self.rank[y] += 1
def findSet(self, x):
if x != self.p[x]:
self.p[x] = self.findSet(self.p[x])
return self.p[x]
def solve(bridges, N, M):
ans = [(N**2 - N) // 2]
d = DisjointSet(N)
for f, t in reversed(bridges):
if d.same(f, t):
ans.append(ans[-1])
else:
n1 = d.size[d.p[f]]
n2 = d.size[d.p[t]]
ans.append(ans[-1] - (n1 * n2))
d.unite(f, t)
return ans
def main(args):
N, M = list(map(int, input().split()))
bridges = []
for _ in range(M):
f, t = list(map(int, input().split()))
bridges.append([f, t])
ans = solve(bridges, N, M)
for a in (ans[::-1])[1:]:
print(a)
if __name__ == "__main__":
main(sys.argv[1:])
|
# -*- coding: utf-8 -*-
"""
D - Decayed Bridges
https://atcoder.jp/contests/abc120/tasks/abc120_d#
AC
"""
import sys
class DisjointSet(object):
def __init__(self, n):
self.rank = [0] * n
self.p = list(range(n))
self.size = [1] * n
def same(self, x, y):
return self.findSet(x) == self.findSet(y)
def unite(self, x, y):
self.link(self.findSet(x), self.findSet(y))
def link(self, x, y):
if self.rank[x] > self.rank[y]:
self.size[self.p[x]] += self.size[self.p[y]]
self.p[y] = self.findSet(x)
else:
self.size[self.p[y]] += self.size[self.p[x]]
self.p[x] = self.findSet(y)
if self.rank[x] == self.rank[y]:
self.rank[y] += 1
def findSet(self, x):
if x != self.p[x]:
self.p[x] = self.findSet(self.p[x])
return self.p[x]
def solve(bridges, N, M):
ans = [(N**2 - N) // 2]
d = DisjointSet(N + 1)
for f, t in reversed(bridges):
if d.same(f, t):
ans.append(ans[-1])
else:
n1 = d.size[d.p[f]]
n2 = d.size[d.p[t]]
ans.append(ans[-1] - (n1 * n2))
d.unite(f, t)
return ans
def main(args):
N, M = list(map(int, input().split()))
bridges = []
for _ in range(M):
f, t = list(map(int, input().split()))
bridges.append([f, t])
ans = solve(bridges, N, M)
for a in (ans[::-1])[1:]:
print(a)
if __name__ == "__main__":
main(sys.argv[1:])
| false | 9.859155 |
[
"+AC",
"- self.rank = []",
"- self.p = []",
"- self.size = []",
"- for i in range(n + 1):",
"- self.makeSet(i)",
"-",
"- def makeSet(self, x):",
"- self.p.insert(x, x)",
"- self.rank.insert(x, 0)",
"- self.size.insert(x, 1)",
"+ self.rank = [0] * n",
"+ self.p = list(range(n))",
"+ self.size = [1] * n",
"- d = DisjointSet(N)",
"+ d = DisjointSet(N + 1)"
] | false | 0.083414 | 0.111205 | 0.750091 |
[
"s700760308",
"s736216805"
] |
u865741247
|
p03478
|
python
|
s725954863
|
s354171412
| 42 | 35 | 3,060 | 3,188 |
Accepted
|
Accepted
| 16.67 |
def ketanowa(p):
ans=0
p=str(p)
for i in p:
ans+=int(i)
return ans
def main():
temp=input().split(" ")
n=int(temp[0])
a=int(temp[1])
b=int(temp[2])
su=0
for i in range(n+1):
if a<=ketanowa(i) and ketanowa(i)<=b:
su+=i
print (su)
if __name__ == '__main__':
main()
|
a,b,c=input().split(" ")
nums=[]
ans=0
b=int(b)
c=int(c)
a=int(a)
for i in range(a+1):
nums.append(sum(list(map(int,str(i)))))
for j,n in enumerate(nums):
if b<=n and n<=c:
ans+=j
print(ans)
| 22 | 12 | 365 | 209 |
def ketanowa(p):
ans = 0
p = str(p)
for i in p:
ans += int(i)
return ans
def main():
temp = input().split(" ")
n = int(temp[0])
a = int(temp[1])
b = int(temp[2])
su = 0
for i in range(n + 1):
if a <= ketanowa(i) and ketanowa(i) <= b:
su += i
print(su)
if __name__ == "__main__":
main()
|
a, b, c = input().split(" ")
nums = []
ans = 0
b = int(b)
c = int(c)
a = int(a)
for i in range(a + 1):
nums.append(sum(list(map(int, str(i)))))
for j, n in enumerate(nums):
if b <= n and n <= c:
ans += j
print(ans)
| false | 45.454545 |
[
"-def ketanowa(p):",
"- ans = 0",
"- p = str(p)",
"- for i in p:",
"- ans += int(i)",
"- return ans",
"-",
"-",
"-def main():",
"- temp = input().split(\" \")",
"- n = int(temp[0])",
"- a = int(temp[1])",
"- b = int(temp[2])",
"- su = 0",
"- for i in range(n + 1):",
"- if a <= ketanowa(i) and ketanowa(i) <= b:",
"- su += i",
"- print(su)",
"-",
"-",
"-if __name__ == \"__main__\":",
"- main()",
"+a, b, c = input().split(\" \")",
"+nums = []",
"+ans = 0",
"+b = int(b)",
"+c = int(c)",
"+a = int(a)",
"+for i in range(a + 1):",
"+ nums.append(sum(list(map(int, str(i)))))",
"+for j, n in enumerate(nums):",
"+ if b <= n and n <= c:",
"+ ans += j",
"+print(ans)"
] | false | 0.043144 | 0.185459 | 0.232635 |
[
"s725954863",
"s354171412"
] |
u677523557
|
p03734
|
python
|
s352956042
|
s509317406
| 293 | 36 | 3,064 | 3,064 |
Accepted
|
Accepted
| 87.71 |
N, W = list(map(int, input().split()))
V = [[] for _ in range(4)]
for i in range(N):
w, v = list(map(int, input().split()))
if i == 0:
w0 = w
V[0].append(v)
else:
V[w-w0].append(v)
J = []
for i in range(4):
F = sorted(V[i], reverse=True)
G = [0]
for f in F:
G.append(f+G[-1])
J.append(G)
ans = 0
for s0 in range(len(J[0])):
for s1 in range(len(J[1])):
for s2 in range(len(J[2])):
for s3 in range(len(J[3])):
if s0*w0 + s1*(w0+1) + s2*(w0+2) + s3*(w0+3) > W:
continue
ans = max(ans, J[0][s0]+J[1][s1]+J[2][s2]+J[3][s3])
print(ans)
|
import sys
input = sys.stdin.readline
N, W = list(map(int, input().split()))
A = [[] for _ in range(4)]
for i in range(N):
w, v = list(map(int, input().split()))
if i == 0: w0 = w
A[w-w0].append(v)
B = [[0] for _ in range(4)]
for i in range(4):
A[i].sort(reverse=True)
b = 0
for a in A[i]:
b += a
B[i].append(b)
#print(B)
ans = 0
for n1, b1 in enumerate(B[0]):
for n2, b2 in enumerate(B[1]):
for n3, b3 in enumerate(B[2]):
n4 = min((W - n1*w0 - n2*(w0+1) - n3*(w0+2)) // (w0+3), len(B[3])-1)
if n4 < 0: continue
ans = max(ans, b1+b2+b3+B[3][n4])
print(ans)
| 27 | 27 | 681 | 661 |
N, W = list(map(int, input().split()))
V = [[] for _ in range(4)]
for i in range(N):
w, v = list(map(int, input().split()))
if i == 0:
w0 = w
V[0].append(v)
else:
V[w - w0].append(v)
J = []
for i in range(4):
F = sorted(V[i], reverse=True)
G = [0]
for f in F:
G.append(f + G[-1])
J.append(G)
ans = 0
for s0 in range(len(J[0])):
for s1 in range(len(J[1])):
for s2 in range(len(J[2])):
for s3 in range(len(J[3])):
if s0 * w0 + s1 * (w0 + 1) + s2 * (w0 + 2) + s3 * (w0 + 3) > W:
continue
ans = max(ans, J[0][s0] + J[1][s1] + J[2][s2] + J[3][s3])
print(ans)
|
import sys
input = sys.stdin.readline
N, W = list(map(int, input().split()))
A = [[] for _ in range(4)]
for i in range(N):
w, v = list(map(int, input().split()))
if i == 0:
w0 = w
A[w - w0].append(v)
B = [[0] for _ in range(4)]
for i in range(4):
A[i].sort(reverse=True)
b = 0
for a in A[i]:
b += a
B[i].append(b)
# print(B)
ans = 0
for n1, b1 in enumerate(B[0]):
for n2, b2 in enumerate(B[1]):
for n3, b3 in enumerate(B[2]):
n4 = min(
(W - n1 * w0 - n2 * (w0 + 1) - n3 * (w0 + 2)) // (w0 + 3), len(B[3]) - 1
)
if n4 < 0:
continue
ans = max(ans, b1 + b2 + b3 + B[3][n4])
print(ans)
| false | 0 |
[
"+import sys",
"+",
"+input = sys.stdin.readline",
"-V = [[] for _ in range(4)]",
"+A = [[] for _ in range(4)]",
"- V[0].append(v)",
"- else:",
"- V[w - w0].append(v)",
"-J = []",
"+ A[w - w0].append(v)",
"+B = [[0] for _ in range(4)]",
"- F = sorted(V[i], reverse=True)",
"- G = [0]",
"- for f in F:",
"- G.append(f + G[-1])",
"- J.append(G)",
"+ A[i].sort(reverse=True)",
"+ b = 0",
"+ for a in A[i]:",
"+ b += a",
"+ B[i].append(b)",
"+# print(B)",
"-for s0 in range(len(J[0])):",
"- for s1 in range(len(J[1])):",
"- for s2 in range(len(J[2])):",
"- for s3 in range(len(J[3])):",
"- if s0 * w0 + s1 * (w0 + 1) + s2 * (w0 + 2) + s3 * (w0 + 3) > W:",
"- continue",
"- ans = max(ans, J[0][s0] + J[1][s1] + J[2][s2] + J[3][s3])",
"+for n1, b1 in enumerate(B[0]):",
"+ for n2, b2 in enumerate(B[1]):",
"+ for n3, b3 in enumerate(B[2]):",
"+ n4 = min(",
"+ (W - n1 * w0 - n2 * (w0 + 1) - n3 * (w0 + 2)) // (w0 + 3), len(B[3]) - 1",
"+ )",
"+ if n4 < 0:",
"+ continue",
"+ ans = max(ans, b1 + b2 + b3 + B[3][n4])"
] | false | 0.036972 | 0.036418 | 1.015212 |
[
"s352956042",
"s509317406"
] |
u803617136
|
p02755
|
python
|
s493863139
|
s201900883
| 176 | 18 | 38,384 | 3,060 |
Accepted
|
Accepted
| 89.77 |
A, B = list(map(int, input().split()))
for n in range(1, 1001):
a = int(n * 0.08)
b = int(n * 0.1)
if A == a and B == b:
print(n)
exit()
print((-1))
|
a, b = list(map(int, input().split()))
ans = -1
for x in range(13, 1250):
if int(x * 0.08) == a and int(x * 0.1) == b:
ans = x
break
print(ans)
| 8 | 7 | 175 | 163 |
A, B = list(map(int, input().split()))
for n in range(1, 1001):
a = int(n * 0.08)
b = int(n * 0.1)
if A == a and B == b:
print(n)
exit()
print((-1))
|
a, b = list(map(int, input().split()))
ans = -1
for x in range(13, 1250):
if int(x * 0.08) == a and int(x * 0.1) == b:
ans = x
break
print(ans)
| false | 12.5 |
[
"-A, B = list(map(int, input().split()))",
"-for n in range(1, 1001):",
"- a = int(n * 0.08)",
"- b = int(n * 0.1)",
"- if A == a and B == b:",
"- print(n)",
"- exit()",
"-print((-1))",
"+a, b = list(map(int, input().split()))",
"+ans = -1",
"+for x in range(13, 1250):",
"+ if int(x * 0.08) == a and int(x * 0.1) == b:",
"+ ans = x",
"+ break",
"+print(ans)"
] | false | 0.041197 | 0.039303 | 1.048186 |
[
"s493863139",
"s201900883"
] |
u131411061
|
p02689
|
python
|
s366535686
|
s035298615
| 427 | 369 | 47,920 | 38,024 |
Accepted
|
Accepted
| 13.58 |
N,M = list(map(int,input().split()))
H = list(map(int,input().split()))
d = []
for i in range(M):
A,B = list(map(int,input().split()))
d.append((A-1,B-1))
cnt = 0
res = {}
for i in range(N):
res[i] = False
flag = {}
for i in range(N):
flag[i] = True
for i in d:
A = i[0]
B = i[1]
#print("H[A] > H[B]",H[A],H[B])
if H[A] > H[B] and flag[A] == True:
res[A] = True
else:
flag[A] = False
res[A] = False
#print("H[A] < H[B]",H[A],H[B])
if H[B] > H[A] and flag[B] == True:
res[B] = True
else:
flag[B] = False
res[B] = False
print((list(flag.values()).count(True)))
|
N,M = list(map(int,input().split()))
H = list(map(int,input().split()))
d = []
for i in range(M):
A,B = list(map(int,input().split()))
d.append((A-1,B-1))
cnt = 0
flag = {}
for i in range(N):
flag[i] = True
for i in d:
A = i[0]
B = i[1]
if not(H[A] > H[B] and flag[A] == True):
flag[A] = False
if not(H[B] > H[A] and flag[B] == True):
flag[B] = False
print((list(flag.values()).count(True)))
| 32 | 21 | 674 | 444 |
N, M = list(map(int, input().split()))
H = list(map(int, input().split()))
d = []
for i in range(M):
A, B = list(map(int, input().split()))
d.append((A - 1, B - 1))
cnt = 0
res = {}
for i in range(N):
res[i] = False
flag = {}
for i in range(N):
flag[i] = True
for i in d:
A = i[0]
B = i[1]
# print("H[A] > H[B]",H[A],H[B])
if H[A] > H[B] and flag[A] == True:
res[A] = True
else:
flag[A] = False
res[A] = False
# print("H[A] < H[B]",H[A],H[B])
if H[B] > H[A] and flag[B] == True:
res[B] = True
else:
flag[B] = False
res[B] = False
print((list(flag.values()).count(True)))
|
N, M = list(map(int, input().split()))
H = list(map(int, input().split()))
d = []
for i in range(M):
A, B = list(map(int, input().split()))
d.append((A - 1, B - 1))
cnt = 0
flag = {}
for i in range(N):
flag[i] = True
for i in d:
A = i[0]
B = i[1]
if not (H[A] > H[B] and flag[A] == True):
flag[A] = False
if not (H[B] > H[A] and flag[B] == True):
flag[B] = False
print((list(flag.values()).count(True)))
| false | 34.375 |
[
"-res = {}",
"-for i in range(N):",
"- res[i] = False",
"- # print(\"H[A] > H[B]\",H[A],H[B])",
"- if H[A] > H[B] and flag[A] == True:",
"- res[A] = True",
"- else:",
"+ if not (H[A] > H[B] and flag[A] == True):",
"- res[A] = False",
"- # print(\"H[A] < H[B]\",H[A],H[B])",
"- if H[B] > H[A] and flag[B] == True:",
"- res[B] = True",
"- else:",
"+ if not (H[B] > H[A] and flag[B] == True):",
"- res[B] = False"
] | false | 0.036628 | 0.038321 | 0.955832 |
[
"s366535686",
"s035298615"
] |
u780342333
|
p02393
|
python
|
s716156924
|
s319333671
| 30 | 20 | 7,676 | 5,572 |
Accepted
|
Accepted
| 33.33 |
nums = [int(x) for x in input().split(" ")]
nums.sort()
res = " ".join([str(n) for n in nums])
print(res)
|
l = list(map(int, input().split()))
l.sort()
print((*l))
| 4 | 3 | 108 | 57 |
nums = [int(x) for x in input().split(" ")]
nums.sort()
res = " ".join([str(n) for n in nums])
print(res)
|
l = list(map(int, input().split()))
l.sort()
print((*l))
| false | 25 |
[
"-nums = [int(x) for x in input().split(\" \")]",
"-nums.sort()",
"-res = \" \".join([str(n) for n in nums])",
"-print(res)",
"+l = list(map(int, input().split()))",
"+l.sort()",
"+print((*l))"
] | false | 0.040274 | 0.041054 | 0.980986 |
[
"s716156924",
"s319333671"
] |
u634046173
|
p02767
|
python
|
s437841363
|
s677533490
| 30 | 25 | 9,112 | 9,168 |
Accepted
|
Accepted
| 16.67 |
import math
N = int(eval(input()))
X = list(map(int,input().split()))
medf = math.floor(sum(X)/N)
medc = math.ceil(sum(X)/N)
cf = 0
cc = 0
for i in range(N):
cf += (X[i] - medf)**2
cc += (X[i] - medc)**2
print((min(cf,cc)))
|
import math
N = int(eval(input()))
X = list(map(int,input().split()))
med = int(sum(X)/N + 0.5)
c = 0
for i in range(N):
c += (X[i] - med)**2
print(c)
| 11 | 8 | 229 | 154 |
import math
N = int(eval(input()))
X = list(map(int, input().split()))
medf = math.floor(sum(X) / N)
medc = math.ceil(sum(X) / N)
cf = 0
cc = 0
for i in range(N):
cf += (X[i] - medf) ** 2
cc += (X[i] - medc) ** 2
print((min(cf, cc)))
|
import math
N = int(eval(input()))
X = list(map(int, input().split()))
med = int(sum(X) / N + 0.5)
c = 0
for i in range(N):
c += (X[i] - med) ** 2
print(c)
| false | 27.272727 |
[
"-medf = math.floor(sum(X) / N)",
"-medc = math.ceil(sum(X) / N)",
"-cf = 0",
"-cc = 0",
"+med = int(sum(X) / N + 0.5)",
"+c = 0",
"- cf += (X[i] - medf) ** 2",
"- cc += (X[i] - medc) ** 2",
"-print((min(cf, cc)))",
"+ c += (X[i] - med) ** 2",
"+print(c)"
] | false | 0.097965 | 0.041716 | 2.348375 |
[
"s437841363",
"s677533490"
] |
u803848678
|
p03695
|
python
|
s215345876
|
s369712862
| 21 | 18 | 3,316 | 3,060 |
Accepted
|
Accepted
| 14.29 |
n = int(eval(input()))
a = list(map(int, input().split()))
from collections import defaultdict
d = defaultdict(int)
over = 0
for i in a:
lv = i//400
if lv < 3200//400 and not d[lv]:
d[lv] = True
if lv >= 3200//400:
over += 1
syurui = sum(d.values())
print((max(1, syurui), syurui+over))
|
n = int(eval(input()))
a = list(map(int, input().split()))
d = [0]*8
over = 0
for i in a:
lv = i//400
if lv < 8:
d[lv] = 1
else:
over += 1
print((max(sum(d), 1), sum(d)+over))
| 14 | 12 | 320 | 207 |
n = int(eval(input()))
a = list(map(int, input().split()))
from collections import defaultdict
d = defaultdict(int)
over = 0
for i in a:
lv = i // 400
if lv < 3200 // 400 and not d[lv]:
d[lv] = True
if lv >= 3200 // 400:
over += 1
syurui = sum(d.values())
print((max(1, syurui), syurui + over))
|
n = int(eval(input()))
a = list(map(int, input().split()))
d = [0] * 8
over = 0
for i in a:
lv = i // 400
if lv < 8:
d[lv] = 1
else:
over += 1
print((max(sum(d), 1), sum(d) + over))
| false | 14.285714 |
[
"-from collections import defaultdict",
"-",
"-d = defaultdict(int)",
"+d = [0] * 8",
"- if lv < 3200 // 400 and not d[lv]:",
"- d[lv] = True",
"- if lv >= 3200 // 400:",
"+ if lv < 8:",
"+ d[lv] = 1",
"+ else:",
"-syurui = sum(d.values())",
"-print((max(1, syurui), syurui + over))",
"+print((max(sum(d), 1), sum(d) + over))"
] | false | 0.110794 | 0.04623 | 2.396608 |
[
"s215345876",
"s369712862"
] |
u914797917
|
p03624
|
python
|
s608126176
|
s265956230
| 20 | 18 | 3,188 | 3,188 |
Accepted
|
Accepted
| 10 |
s=eval(input())
for i in range(26):
if s.count(chr(ord('a')+i))==0:
print((chr(ord('a')+i)))
break
else:
print('None')
|
s=eval(input())
for i in range(26):
if not chr(ord('a')+i) in s:
print((chr(ord('a')+i)))
break
else:
print('None')
| 7 | 7 | 128 | 126 |
s = eval(input())
for i in range(26):
if s.count(chr(ord("a") + i)) == 0:
print((chr(ord("a") + i)))
break
else:
print("None")
|
s = eval(input())
for i in range(26):
if not chr(ord("a") + i) in s:
print((chr(ord("a") + i)))
break
else:
print("None")
| false | 0 |
[
"- if s.count(chr(ord(\"a\") + i)) == 0:",
"+ if not chr(ord(\"a\") + i) in s:"
] | false | 0.040674 | 0.040344 | 1.008178 |
[
"s608126176",
"s265956230"
] |
u987164499
|
p03378
|
python
|
s245047651
|
s710327739
| 152 | 17 | 12,436 | 3,060 |
Accepted
|
Accepted
| 88.82 |
from sys import stdin
import numpy as np
n,m,x= [int(x) for x in stdin.readline().rstrip().split()]
li = list(map(int,stdin.readline().rstrip().split()))
lin= [0]*(n+1)
for i in li:
lin[i] = 1
print((min(sum(lin[:x]),sum(lin[x+1:]))))
|
n,m,x = list(map(int,input().split()))
a = list(map(int,input().split()))
li = [0]*(n+1)
for i in a:
li[i] += 1
print((min(sum(li[:x+1]),sum(li[x:]))))
| 10 | 9 | 247 | 158 |
from sys import stdin
import numpy as np
n, m, x = [int(x) for x in stdin.readline().rstrip().split()]
li = list(map(int, stdin.readline().rstrip().split()))
lin = [0] * (n + 1)
for i in li:
lin[i] = 1
print((min(sum(lin[:x]), sum(lin[x + 1 :]))))
|
n, m, x = list(map(int, input().split()))
a = list(map(int, input().split()))
li = [0] * (n + 1)
for i in a:
li[i] += 1
print((min(sum(li[: x + 1]), sum(li[x:]))))
| false | 10 |
[
"-from sys import stdin",
"-import numpy as np",
"-",
"-n, m, x = [int(x) for x in stdin.readline().rstrip().split()]",
"-li = list(map(int, stdin.readline().rstrip().split()))",
"-lin = [0] * (n + 1)",
"-for i in li:",
"- lin[i] = 1",
"-print((min(sum(lin[:x]), sum(lin[x + 1 :]))))",
"+n, m, x = list(map(int, input().split()))",
"+a = list(map(int, input().split()))",
"+li = [0] * (n + 1)",
"+for i in a:",
"+ li[i] += 1",
"+print((min(sum(li[: x + 1]), sum(li[x:]))))"
] | false | 0.038471 | 0.038291 | 1.004695 |
[
"s245047651",
"s710327739"
] |
u191874006
|
p02945
|
python
|
s712348348
|
s877897113
| 164 | 135 | 38,256 | 65,540 |
Accepted
|
Accepted
| 17.68 |
#!/usr/bin/env python3
#ABC137 A
import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
a,b = LI()
print((max(a+b,a-b,a*b)))
|
#!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
a, b = LI()
print((max(a+b, a-b, a*b)))
| 20 | 21 | 513 | 598 |
#!/usr/bin/env python3
# ABC137 A
import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
def I():
return int(sys.stdin.readline())
def LI():
return list(map(int, sys.stdin.readline().split()))
a, b = LI()
print((max(a + b, a - b, a * b)))
|
#!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop, heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float("inf")
def I():
return int(sys.stdin.readline())
def LI():
return list(map(int, sys.stdin.readline().split()))
a, b = LI()
print((max(a + b, a - b, a * b)))
| false | 4.761905 |
[
"-# ABC137 A",
"-import bisect",
"+from bisect import bisect_right as br",
"+from bisect import bisect_left as bl",
"-sys.setrecursionlimit(1000000000)",
"-from heapq import heappush, heappop",
"+sys.setrecursionlimit(2147483647)",
"+from heapq import heappush, heappop, heappushpop",
"+inf = float(\"inf\")"
] | false | 0.048072 | 0.085992 | 0.559026 |
[
"s712348348",
"s877897113"
] |
u581187895
|
p02780
|
python
|
s295974275
|
s723376959
| 587 | 187 | 24,312 | 23,344 |
Accepted
|
Accepted
| 68.14 |
import numpy as np
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N, K = list(map(int, readline().split()))
A = np.array(readline().split(), dtype=np.int64)
A = np.array([(1+a)/2 for a in A])
Acum = np.zeros(N+1, np.float64)
Acum[1:] = A.cumsum()
x = Acum[K:] - Acum[:-K]
print((x.max()))
|
import numpy as np
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N, K = list(map(int, readline().split()))
A = np.array(readline().split(), dtype=np.int64) + 1
Acum = np.zeros(N+1, np.float64)
Acum[1:] = A.cumsum()
x = Acum[K:] - Acum[:-K]
print((x.max()/2))
| 15 | 15 | 367 | 339 |
import numpy as np
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N, K = list(map(int, readline().split()))
A = np.array(readline().split(), dtype=np.int64)
A = np.array([(1 + a) / 2 for a in A])
Acum = np.zeros(N + 1, np.float64)
Acum[1:] = A.cumsum()
x = Acum[K:] - Acum[:-K]
print((x.max()))
|
import numpy as np
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N, K = list(map(int, readline().split()))
A = np.array(readline().split(), dtype=np.int64) + 1
Acum = np.zeros(N + 1, np.float64)
Acum[1:] = A.cumsum()
x = Acum[K:] - Acum[:-K]
print((x.max() / 2))
| false | 0 |
[
"-A = np.array(readline().split(), dtype=np.int64)",
"-A = np.array([(1 + a) / 2 for a in A])",
"+A = np.array(readline().split(), dtype=np.int64) + 1",
"-print((x.max()))",
"+print((x.max() / 2))"
] | false | 0.200229 | 0.441117 | 0.453913 |
[
"s295974275",
"s723376959"
] |
u367701763
|
p03252
|
python
|
s268748223
|
s121870617
| 111 | 92 | 97,012 | 107,064 |
Accepted
|
Accepted
| 17.12 |
def ch(x):
return ord(x)-ord("a")
def dch(x):
return chr(x+ord("a"))
S = input().rstrip()
T = input().rstrip()
s0 = S[0]
cnt = 1
A1 = []
P = [-1]*26
k=0
for s in S[1:]:
if s==s0:
cnt += 1
else:
if P[ch(s0)] == -1:
P[ch(s0)] = k
k += 1
A1.append((P[ch(s0)], cnt))
else:
A1.append((P[ch(s0)], cnt))
cnt = 1
s0 = s
if cnt == 1:
if P[ch(s0)] == -1:
P[ch(s0)] = k
k += 1
A1.append((P[ch(s0)], cnt))
else:
A1.append((P[ch(s0)], cnt))
t0 = T[0]
cnt = 1
B1 = []
P = [-1]*26
k=0
for t in T[1:]:
if t==t0:
cnt += 1
else:
if P[ch(t0)] == -1:
P[ch(t0)] = k
k += 1
B1.append((P[ch(t0)], cnt))
else:
B1.append((P[ch(t0)], cnt))
cnt = 1
t0 = t
if cnt == 1:
if P[ch(t0)] == -1:
P[ch(t0)] = k
k += 1
B1.append((P[ch(t0)], cnt))
else:
B1.append((P[ch(t0)], cnt))
if A1==B1:
print("Yes")
else:
print("No")
|
def make_map(X):
X = list([ord(x) - ord("a") for x in X])
s = [-1]*26
res = [0]+[-1]*(len(X)-1)
cnt = 0
for i, x in enumerate(X):
if s[x] == -1:
s[x] = res[i] = cnt
cnt += 1
else:
res[i] = s[x]
return res
print(("Yes" if make_map(eval(input()))==make_map(eval(input())) else "No"))
| 64 | 13 | 1,136 | 360 |
def ch(x):
return ord(x) - ord("a")
def dch(x):
return chr(x + ord("a"))
S = input().rstrip()
T = input().rstrip()
s0 = S[0]
cnt = 1
A1 = []
P = [-1] * 26
k = 0
for s in S[1:]:
if s == s0:
cnt += 1
else:
if P[ch(s0)] == -1:
P[ch(s0)] = k
k += 1
A1.append((P[ch(s0)], cnt))
else:
A1.append((P[ch(s0)], cnt))
cnt = 1
s0 = s
if cnt == 1:
if P[ch(s0)] == -1:
P[ch(s0)] = k
k += 1
A1.append((P[ch(s0)], cnt))
else:
A1.append((P[ch(s0)], cnt))
t0 = T[0]
cnt = 1
B1 = []
P = [-1] * 26
k = 0
for t in T[1:]:
if t == t0:
cnt += 1
else:
if P[ch(t0)] == -1:
P[ch(t0)] = k
k += 1
B1.append((P[ch(t0)], cnt))
else:
B1.append((P[ch(t0)], cnt))
cnt = 1
t0 = t
if cnt == 1:
if P[ch(t0)] == -1:
P[ch(t0)] = k
k += 1
B1.append((P[ch(t0)], cnt))
else:
B1.append((P[ch(t0)], cnt))
if A1 == B1:
print("Yes")
else:
print("No")
|
def make_map(X):
X = list([ord(x) - ord("a") for x in X])
s = [-1] * 26
res = [0] + [-1] * (len(X) - 1)
cnt = 0
for i, x in enumerate(X):
if s[x] == -1:
s[x] = res[i] = cnt
cnt += 1
else:
res[i] = s[x]
return res
print(("Yes" if make_map(eval(input())) == make_map(eval(input())) else "No"))
| false | 79.6875 |
[
"-def ch(x):",
"- return ord(x) - ord(\"a\")",
"+def make_map(X):",
"+ X = list([ord(x) - ord(\"a\") for x in X])",
"+ s = [-1] * 26",
"+ res = [0] + [-1] * (len(X) - 1)",
"+ cnt = 0",
"+ for i, x in enumerate(X):",
"+ if s[x] == -1:",
"+ s[x] = res[i] = cnt",
"+ cnt += 1",
"+ else:",
"+ res[i] = s[x]",
"+ return res",
"-def dch(x):",
"- return chr(x + ord(\"a\"))",
"-",
"-",
"-S = input().rstrip()",
"-T = input().rstrip()",
"-s0 = S[0]",
"-cnt = 1",
"-A1 = []",
"-P = [-1] * 26",
"-k = 0",
"-for s in S[1:]:",
"- if s == s0:",
"- cnt += 1",
"- else:",
"- if P[ch(s0)] == -1:",
"- P[ch(s0)] = k",
"- k += 1",
"- A1.append((P[ch(s0)], cnt))",
"- else:",
"- A1.append((P[ch(s0)], cnt))",
"- cnt = 1",
"- s0 = s",
"-if cnt == 1:",
"- if P[ch(s0)] == -1:",
"- P[ch(s0)] = k",
"- k += 1",
"- A1.append((P[ch(s0)], cnt))",
"- else:",
"- A1.append((P[ch(s0)], cnt))",
"-t0 = T[0]",
"-cnt = 1",
"-B1 = []",
"-P = [-1] * 26",
"-k = 0",
"-for t in T[1:]:",
"- if t == t0:",
"- cnt += 1",
"- else:",
"- if P[ch(t0)] == -1:",
"- P[ch(t0)] = k",
"- k += 1",
"- B1.append((P[ch(t0)], cnt))",
"- else:",
"- B1.append((P[ch(t0)], cnt))",
"- cnt = 1",
"- t0 = t",
"-if cnt == 1:",
"- if P[ch(t0)] == -1:",
"- P[ch(t0)] = k",
"- k += 1",
"- B1.append((P[ch(t0)], cnt))",
"- else:",
"- B1.append((P[ch(t0)], cnt))",
"-if A1 == B1:",
"- print(\"Yes\")",
"-else:",
"- print(\"No\")",
"+print((\"Yes\" if make_map(eval(input())) == make_map(eval(input())) else \"No\"))"
] | false | 0.047084 | 0.035312 | 1.333376 |
[
"s268748223",
"s121870617"
] |
u852386636
|
p03244
|
python
|
s197416652
|
s933567780
| 91 | 81 | 34,748 | 31,960 |
Accepted
|
Accepted
| 10.99 |
import collections
n = int(eval(input()))
v = list(map(int, input().split()))
even_odd_length = n / 2
replace_total = 0
list_odd = v[0::2]
list_even = v[1::2]
dict_c_odd = dict(collections.Counter(list_odd))
dict_c_even = dict(collections.Counter(list_even))
dict_c_even_bk = dict_c_even.copy()
dict_c_odd_bk = dict_c_odd.copy()
replace_total_tmp = 0
replace_total_tmp2 = 0
max_count_c_odd = max(dict_c_odd.values())
max_count_c_even = max(dict_c_even.values())
max_count_c_even_bk = max_count_c_even
max_c_odd_keys = [k for k, v in list(dict_c_odd.items()) if v == max_count_c_odd]
max_c_even_keys = [k for k, v in list(dict_c_even.items()) if v == max_count_c_even]
if len(set(v)) == 1:
print((int(even_odd_length)))
else:
if max_c_odd_keys[0] in dict_c_even:
del dict_c_even[max_c_odd_keys[0]]
max_count_c_even = max(dict_c_even.values())
replace_total_tmp = (n - max_count_c_odd - max_count_c_even)
dict_c_even = dict_c_even_bk
max_count_c_even = max_count_c_even_bk
if max_c_even_keys[0] in dict_c_odd:
del dict_c_odd[max_c_even_keys[0]]
max_count_c_odd = max(dict_c_odd.values())
replace_total_tmp2 = (n - max_count_c_odd - max_count_c_even)
if replace_total_tmp >= replace_total_tmp2:
replace_total = replace_total_tmp2
else:
replace_total = replace_total_tmp
print(replace_total)
|
import collections
n = int(eval(input()))
v = list(map(int, input().split()))
even_odd_length = n / 2
replace_total = 0
list_odd = v[0::2]
list_even = v[1::2]
dict_c_odd = dict(collections.Counter(list_odd))
dict_c_even = dict(collections.Counter(list_even))
dict_c_even_bk = dict_c_even.copy()
replace_total_tmp = 0
replace_total_tmp2 = 0
max_count_c_odd = max(dict_c_odd.values())
max_count_c_even = max(dict_c_even.values())
max_count_c_even_bk = max_count_c_even
max_c_odd_keys = [k for k, v in list(dict_c_odd.items()) if v == max_count_c_odd]
max_c_even_keys = [k for k, v in list(dict_c_even.items()) if v == max_count_c_even]
if len(set(v)) == 1:
print((int(even_odd_length)))
else:
if max_c_odd_keys[0] in dict_c_even:
del dict_c_even[max_c_odd_keys[0]]
max_count_c_even = max(dict_c_even.values())
replace_total_tmp = (n - max_count_c_odd - max_count_c_even)
dict_c_even = dict_c_even_bk
max_count_c_even = max_count_c_even_bk
if max_c_even_keys[0] in dict_c_odd:
del dict_c_odd[max_c_even_keys[0]]
max_count_c_odd = max(dict_c_odd.values())
replace_total_tmp2 = (n - max_count_c_odd - max_count_c_even)
if replace_total_tmp >= replace_total_tmp2:
replace_total = replace_total_tmp2
else:
replace_total = replace_total_tmp
print(replace_total)
| 44 | 46 | 1,416 | 1,387 |
import collections
n = int(eval(input()))
v = list(map(int, input().split()))
even_odd_length = n / 2
replace_total = 0
list_odd = v[0::2]
list_even = v[1::2]
dict_c_odd = dict(collections.Counter(list_odd))
dict_c_even = dict(collections.Counter(list_even))
dict_c_even_bk = dict_c_even.copy()
dict_c_odd_bk = dict_c_odd.copy()
replace_total_tmp = 0
replace_total_tmp2 = 0
max_count_c_odd = max(dict_c_odd.values())
max_count_c_even = max(dict_c_even.values())
max_count_c_even_bk = max_count_c_even
max_c_odd_keys = [k for k, v in list(dict_c_odd.items()) if v == max_count_c_odd]
max_c_even_keys = [k for k, v in list(dict_c_even.items()) if v == max_count_c_even]
if len(set(v)) == 1:
print((int(even_odd_length)))
else:
if max_c_odd_keys[0] in dict_c_even:
del dict_c_even[max_c_odd_keys[0]]
max_count_c_even = max(dict_c_even.values())
replace_total_tmp = n - max_count_c_odd - max_count_c_even
dict_c_even = dict_c_even_bk
max_count_c_even = max_count_c_even_bk
if max_c_even_keys[0] in dict_c_odd:
del dict_c_odd[max_c_even_keys[0]]
max_count_c_odd = max(dict_c_odd.values())
replace_total_tmp2 = n - max_count_c_odd - max_count_c_even
if replace_total_tmp >= replace_total_tmp2:
replace_total = replace_total_tmp2
else:
replace_total = replace_total_tmp
print(replace_total)
|
import collections
n = int(eval(input()))
v = list(map(int, input().split()))
even_odd_length = n / 2
replace_total = 0
list_odd = v[0::2]
list_even = v[1::2]
dict_c_odd = dict(collections.Counter(list_odd))
dict_c_even = dict(collections.Counter(list_even))
dict_c_even_bk = dict_c_even.copy()
replace_total_tmp = 0
replace_total_tmp2 = 0
max_count_c_odd = max(dict_c_odd.values())
max_count_c_even = max(dict_c_even.values())
max_count_c_even_bk = max_count_c_even
max_c_odd_keys = [k for k, v in list(dict_c_odd.items()) if v == max_count_c_odd]
max_c_even_keys = [k for k, v in list(dict_c_even.items()) if v == max_count_c_even]
if len(set(v)) == 1:
print((int(even_odd_length)))
else:
if max_c_odd_keys[0] in dict_c_even:
del dict_c_even[max_c_odd_keys[0]]
max_count_c_even = max(dict_c_even.values())
replace_total_tmp = n - max_count_c_odd - max_count_c_even
dict_c_even = dict_c_even_bk
max_count_c_even = max_count_c_even_bk
if max_c_even_keys[0] in dict_c_odd:
del dict_c_odd[max_c_even_keys[0]]
max_count_c_odd = max(dict_c_odd.values())
replace_total_tmp2 = n - max_count_c_odd - max_count_c_even
if replace_total_tmp >= replace_total_tmp2:
replace_total = replace_total_tmp2
else:
replace_total = replace_total_tmp
print(replace_total)
| false | 4.347826 |
[
"-dict_c_odd_bk = dict_c_odd.copy()"
] | false | 0.04412 | 0.044094 | 1.000605 |
[
"s197416652",
"s933567780"
] |
u641446860
|
p03208
|
python
|
s911137509
|
s744639322
| 541 | 248 | 51,160 | 8,280 |
Accepted
|
Accepted
| 54.16 |
N, K = list(map(int, input().split()))
h = sorted([int(eval(input())) for _ in range(N)])
ans = float('inf')
for i in range(N-K+1):
ans = min(h[i+K-1] - h[i],ans)
print(ans)
|
N, K = list(map(int, input().split()))
h = [int(eval(input())) for _ in range(N)]
h = sorted(h)
ans = float('inf')
for i in range(N-K+1):
ans = min(h[i+K-1] - h[i], ans)
print(ans)
| 6 | 7 | 171 | 178 |
N, K = list(map(int, input().split()))
h = sorted([int(eval(input())) for _ in range(N)])
ans = float("inf")
for i in range(N - K + 1):
ans = min(h[i + K - 1] - h[i], ans)
print(ans)
|
N, K = list(map(int, input().split()))
h = [int(eval(input())) for _ in range(N)]
h = sorted(h)
ans = float("inf")
for i in range(N - K + 1):
ans = min(h[i + K - 1] - h[i], ans)
print(ans)
| false | 14.285714 |
[
"-h = sorted([int(eval(input())) for _ in range(N)])",
"+h = [int(eval(input())) for _ in range(N)]",
"+h = sorted(h)"
] | false | 0.078627 | 0.041637 | 1.888399 |
[
"s911137509",
"s744639322"
] |
u263830634
|
p02815
|
python
|
s469695365
|
s288495693
| 268 | 220 | 26,012 | 27,108 |
Accepted
|
Accepted
| 17.91 |
MOD = 10 ** 9 + 7
N = int(eval(input()))
C = list(map(int, input().split()))
C.sort()
if N == 1:
print((2 * C[0] % MOD))
exit()
lst = [0] * (N + 3)
lst[0] = 1
for i in range(1, N + 3):
lst[i] = (lst[i - 1] * 2) % MOD
ANS = 0
for i, c in enumerate(C):
ANS += c * (N + 1 - i)
ANS *= pow(2, N - 2, MOD)
ANS %= MOD
ANS *= pow(2, N, MOD)
print((ANS % MOD))
|
MOD = 10 ** 9 + 7
N = int(eval(input()))
C = list(map(int, input().split()))
C.sort()
if N == 1:
print((2 * C[0] % MOD))
exit()
ANS = 0
for i, c in enumerate(C):
ANS += c * (N + 1 - i)
ANS *= pow(2, N - 2, MOD)
ANS %= MOD
ANS *= pow(2, N, MOD)
print((ANS % MOD))
| 24 | 17 | 388 | 285 |
MOD = 10**9 + 7
N = int(eval(input()))
C = list(map(int, input().split()))
C.sort()
if N == 1:
print((2 * C[0] % MOD))
exit()
lst = [0] * (N + 3)
lst[0] = 1
for i in range(1, N + 3):
lst[i] = (lst[i - 1] * 2) % MOD
ANS = 0
for i, c in enumerate(C):
ANS += c * (N + 1 - i)
ANS *= pow(2, N - 2, MOD)
ANS %= MOD
ANS *= pow(2, N, MOD)
print((ANS % MOD))
|
MOD = 10**9 + 7
N = int(eval(input()))
C = list(map(int, input().split()))
C.sort()
if N == 1:
print((2 * C[0] % MOD))
exit()
ANS = 0
for i, c in enumerate(C):
ANS += c * (N + 1 - i)
ANS *= pow(2, N - 2, MOD)
ANS %= MOD
ANS *= pow(2, N, MOD)
print((ANS % MOD))
| false | 29.166667 |
[
"-lst = [0] * (N + 3)",
"-lst[0] = 1",
"-for i in range(1, N + 3):",
"- lst[i] = (lst[i - 1] * 2) % MOD"
] | false | 0.007587 | 0.038086 | 0.199208 |
[
"s469695365",
"s288495693"
] |
u597374218
|
p02759
|
python
|
s964013495
|
s846998052
| 25 | 23 | 9,084 | 9,148 |
Accepted
|
Accepted
| 8 |
import math
N=int(eval(input()))
print((math.ceil(N/2)))
|
N=int(eval(input()))
print((N//2+N%2))
| 3 | 2 | 50 | 31 |
import math
N = int(eval(input()))
print((math.ceil(N / 2)))
|
N = int(eval(input()))
print((N // 2 + N % 2))
| false | 33.333333 |
[
"-import math",
"-",
"-print((math.ceil(N / 2)))",
"+print((N // 2 + N % 2))"
] | false | 0.088472 | 0.036779 | 2.405499 |
[
"s964013495",
"s846998052"
] |
u630941334
|
p04015
|
python
|
s221195891
|
s637895782
| 1,743 | 1,557 | 58,484 | 54,088 |
Accepted
|
Accepted
| 10.67 |
def main():
N, A = list(map(int, input().split()))
x = list(map(int, input().split()))
x.insert(0, 0)
dp = [[[0 for _ in range(N * A + 1)] for _ in range(N + 1)] for _ in range(N + 1)]
for i in range(N + 1):
dp[i][0][0] = 1
for i in range(1, N + 1):
for j in range(1, i + 1):
for k in range(1, N * A + 1):
dp[i][j][k] = dp[i - 1][j][k]
if k >= x[i]:
dp[i][j][k] += dp[i - 1][j - 1][k - x[i]]
ans = 0
for j in range(1, N + 1):
ans += dp[N][j][A * j]
print(ans)
if __name__ == '__main__':
main()
|
def main():
N, A = list(map(int, input().split()))
x = list(map(int, input().split()))
x.insert(0, 0)
dp = [[[0] * (N * A + 1) for _ in range(N + 1)] for _ in range(N + 1)]
for i in range(N + 1):
dp[i][0][0] = 1
for i in range(1, N + 1):
for j in range(1, i + 1):
for k in range(1, N * A + 1):
dp[i][j][k] = dp[i - 1][j][k]
if k >= x[i]:
dp[i][j][k] += dp[i - 1][j - 1][k - x[i]]
ans = 0
for j in range(1, N + 1):
ans += dp[N][j][A * j]
print(ans)
if __name__ == '__main__':
main()
| 26 | 26 | 648 | 636 |
def main():
N, A = list(map(int, input().split()))
x = list(map(int, input().split()))
x.insert(0, 0)
dp = [[[0 for _ in range(N * A + 1)] for _ in range(N + 1)] for _ in range(N + 1)]
for i in range(N + 1):
dp[i][0][0] = 1
for i in range(1, N + 1):
for j in range(1, i + 1):
for k in range(1, N * A + 1):
dp[i][j][k] = dp[i - 1][j][k]
if k >= x[i]:
dp[i][j][k] += dp[i - 1][j - 1][k - x[i]]
ans = 0
for j in range(1, N + 1):
ans += dp[N][j][A * j]
print(ans)
if __name__ == "__main__":
main()
|
def main():
N, A = list(map(int, input().split()))
x = list(map(int, input().split()))
x.insert(0, 0)
dp = [[[0] * (N * A + 1) for _ in range(N + 1)] for _ in range(N + 1)]
for i in range(N + 1):
dp[i][0][0] = 1
for i in range(1, N + 1):
for j in range(1, i + 1):
for k in range(1, N * A + 1):
dp[i][j][k] = dp[i - 1][j][k]
if k >= x[i]:
dp[i][j][k] += dp[i - 1][j - 1][k - x[i]]
ans = 0
for j in range(1, N + 1):
ans += dp[N][j][A * j]
print(ans)
if __name__ == "__main__":
main()
| false | 0 |
[
"- dp = [[[0 for _ in range(N * A + 1)] for _ in range(N + 1)] for _ in range(N + 1)]",
"+ dp = [[[0] * (N * A + 1) for _ in range(N + 1)] for _ in range(N + 1)]"
] | false | 0.054961 | 0.129507 | 0.424384 |
[
"s221195891",
"s637895782"
] |
u843175622
|
p04045
|
python
|
s488036922
|
s520829394
| 505 | 398 | 107,288 | 92,760 |
Accepted
|
Accepted
| 21.19 |
import sys
import numpy as np
from numba import njit, i4
read = sys.stdin.readline
@njit((i4, i4, i4[:]), cache=True)
def main(n, k, a):
for i in np.arange(n, 100000):
ok = 1
j = i
while j:
m = j % 10
for l in a:
if m == l:
ok = 0
j //= 10
if ok:
print(i)
break
if __name__ == '__main__':
n, k = np.fromstring(read(), dtype=np.int32, sep=' ')
a = np.fromstring(read(), dtype=np.int32, sep=' ')
main(n, k, a)
|
import sys
import numpy as np
from numba import njit, i4
read = sys.stdin.readline
if sys.argv[-1] == 'ONLINE_JUDGE':
from numba.pycc import CC
cc = CC('unko')
@cc.export('main', '(i4, i4, i4[:])')
def main(n, k, a):
for i in np.arange(n, 100000):
ok = 1
j = i
while j:
m = j % 10
for l in a:
if m == l:
ok = 0
j //= 10
if ok:
print(i)
break
cc.compile()
exit()
if __name__ == '__main__':
from unko import main
n, k = np.fromstring(read(), dtype=np.int32, sep=' ')
a = np.fromstring(read(), dtype=np.int32, sep=' ')
main(n, k, a)
| 26 | 33 | 581 | 787 |
import sys
import numpy as np
from numba import njit, i4
read = sys.stdin.readline
@njit((i4, i4, i4[:]), cache=True)
def main(n, k, a):
for i in np.arange(n, 100000):
ok = 1
j = i
while j:
m = j % 10
for l in a:
if m == l:
ok = 0
j //= 10
if ok:
print(i)
break
if __name__ == "__main__":
n, k = np.fromstring(read(), dtype=np.int32, sep=" ")
a = np.fromstring(read(), dtype=np.int32, sep=" ")
main(n, k, a)
|
import sys
import numpy as np
from numba import njit, i4
read = sys.stdin.readline
if sys.argv[-1] == "ONLINE_JUDGE":
from numba.pycc import CC
cc = CC("unko")
@cc.export("main", "(i4, i4, i4[:])")
def main(n, k, a):
for i in np.arange(n, 100000):
ok = 1
j = i
while j:
m = j % 10
for l in a:
if m == l:
ok = 0
j //= 10
if ok:
print(i)
break
cc.compile()
exit()
if __name__ == "__main__":
from unko import main
n, k = np.fromstring(read(), dtype=np.int32, sep=" ")
a = np.fromstring(read(), dtype=np.int32, sep=" ")
main(n, k, a)
| false | 21.212121 |
[
"+if sys.argv[-1] == \"ONLINE_JUDGE\":",
"+ from numba.pycc import CC",
"+ cc = CC(\"unko\")",
"-@njit((i4, i4, i4[:]), cache=True)",
"-def main(n, k, a):",
"- for i in np.arange(n, 100000):",
"- ok = 1",
"- j = i",
"- while j:",
"- m = j % 10",
"- for l in a:",
"- if m == l:",
"- ok = 0",
"- j //= 10",
"- if ok:",
"- print(i)",
"- break",
"+ @cc.export(\"main\", \"(i4, i4, i4[:])\")",
"+ def main(n, k, a):",
"+ for i in np.arange(n, 100000):",
"+ ok = 1",
"+ j = i",
"+ while j:",
"+ m = j % 10",
"+ for l in a:",
"+ if m == l:",
"+ ok = 0",
"+ j //= 10",
"+ if ok:",
"+ print(i)",
"+ break",
"+ cc.compile()",
"+ exit()",
"+if __name__ == \"__main__\":",
"+ from unko import main",
"-if __name__ == \"__main__\":"
] | false | 0.431361 | 0.215417 | 2.002452 |
[
"s488036922",
"s520829394"
] |
u753803401
|
p03013
|
python
|
s156725159
|
s390737361
| 252 | 228 | 63,324 | 50,008 |
Accepted
|
Accepted
| 9.52 |
def slove():
import sys
input = sys.stdin.readline
n, m = list(map(int, input().rstrip('\n').split()))
a = dict([[int(input().rstrip('\n')), 0] for _ in range(m)])
x = [0] * (n + 1)
x[0] = 1 if 0 not in a else 0
x[1] = 1 if 1 not in a else 0
for i in range(2, n+1):
if i not in a:
x[i] = (x[i-1] + x[i-2]) % 1000000007
else:
x[i] = 0
print((x[-1]))
if __name__ == '__main__':
slove()
|
def slove():
import sys
input = sys.stdin.readline
mod = 10 ** 9 + 7
n, m = list(map(int, input().rstrip('\n').split()))
a = {int(input().rstrip('\n')): 0 for _ in range(m)}
dp = [0] * (n + 1)
dp[0] = 1 if 0 not in a else 0
dp[1] = 1 if 1 not in a else 0
for i in range(2, n + 1):
if i not in a:
dp[i] = (dp[i-1] + dp[i-2]) % mod
else:
dp[i] = 0
print((dp[-1]))
if __name__ == '__main__':
slove()
| 18 | 19 | 481 | 499 |
def slove():
import sys
input = sys.stdin.readline
n, m = list(map(int, input().rstrip("\n").split()))
a = dict([[int(input().rstrip("\n")), 0] for _ in range(m)])
x = [0] * (n + 1)
x[0] = 1 if 0 not in a else 0
x[1] = 1 if 1 not in a else 0
for i in range(2, n + 1):
if i not in a:
x[i] = (x[i - 1] + x[i - 2]) % 1000000007
else:
x[i] = 0
print((x[-1]))
if __name__ == "__main__":
slove()
|
def slove():
import sys
input = sys.stdin.readline
mod = 10**9 + 7
n, m = list(map(int, input().rstrip("\n").split()))
a = {int(input().rstrip("\n")): 0 for _ in range(m)}
dp = [0] * (n + 1)
dp[0] = 1 if 0 not in a else 0
dp[1] = 1 if 1 not in a else 0
for i in range(2, n + 1):
if i not in a:
dp[i] = (dp[i - 1] + dp[i - 2]) % mod
else:
dp[i] = 0
print((dp[-1]))
if __name__ == "__main__":
slove()
| false | 5.263158 |
[
"+ mod = 10**9 + 7",
"- a = dict([[int(input().rstrip(\"\\n\")), 0] for _ in range(m)])",
"- x = [0] * (n + 1)",
"- x[0] = 1 if 0 not in a else 0",
"- x[1] = 1 if 1 not in a else 0",
"+ a = {int(input().rstrip(\"\\n\")): 0 for _ in range(m)}",
"+ dp = [0] * (n + 1)",
"+ dp[0] = 1 if 0 not in a else 0",
"+ dp[1] = 1 if 1 not in a else 0",
"- x[i] = (x[i - 1] + x[i - 2]) % 1000000007",
"+ dp[i] = (dp[i - 1] + dp[i - 2]) % mod",
"- x[i] = 0",
"- print((x[-1]))",
"+ dp[i] = 0",
"+ print((dp[-1]))"
] | false | 0.067487 | 0.046779 | 1.442687 |
[
"s156725159",
"s390737361"
] |
u645250356
|
p03598
|
python
|
s809275550
|
s229135425
| 183 | 41 | 38,544 | 10,396 |
Accepted
|
Accepted
| 77.6 |
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))
n = inp()
k = inp()
x = inpl()
res = 0
for i in x:
res += min(i,abs(i-k))*2
print(res)
|
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
n = inp()
k = inp()
a = inpl()
res = 0
for i,x in enumerate(a):
res += min(abs(k-x)*2, x*2)
print(res)
| 16 | 16 | 454 | 435 |
from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heapify
import sys, bisect, math, itertools
sys.setrecursionlimit(10**8)
mod = 10**9 + 7
def inp():
return int(sys.stdin.readline())
def inpl():
return list(map(int, sys.stdin.readline().split()))
def inpln(n):
return list(int(sys.stdin.readline()) for i in range(n))
n = inp()
k = inp()
x = inpl()
res = 0
for i in x:
res += min(i, abs(i - k)) * 2
print(res)
|
from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heapify
import sys, bisect, math, itertools, fractions, pprint
sys.setrecursionlimit(10**8)
mod = 10**9 + 7
INF = float("inf")
def inp():
return int(sys.stdin.readline())
def inpl():
return list(map(int, sys.stdin.readline().split()))
n = inp()
k = inp()
a = inpl()
res = 0
for i, x in enumerate(a):
res += min(abs(k - x) * 2, x * 2)
print(res)
| false | 0 |
[
"-import sys, bisect, math, itertools",
"+import sys, bisect, math, itertools, fractions, pprint",
"+INF = float(\"inf\")",
"-def inpln(n):",
"- return list(int(sys.stdin.readline()) for i in range(n))",
"-",
"-",
"-x = inpl()",
"+a = inpl()",
"-for i in x:",
"- res += min(i, abs(i - k)) * 2",
"+for i, x in enumerate(a):",
"+ res += min(abs(k - x) * 2, x * 2)"
] | false | 0.035553 | 0.036028 | 0.986838 |
[
"s809275550",
"s229135425"
] |
u537782349
|
p03680
|
python
|
s035490999
|
s516448329
| 232 | 201 | 19,064 | 7,340 |
Accepted
|
Accepted
| 13.36 |
a = int(eval(input()))
b = [int(eval(input())) for _ in range(a)]
c = 1
d = 0
e = {}
while True:
d += 1
if b[c-1] == 2:
print(d)
exit()
else:
if (c-1) not in e:
e.setdefault((c-1), "")
else:
print((-1))
exit()
c = b[c - 1]
|
a = int(eval(input()))
b = [int(eval(input()))for _ in range(a)]
c = 0
d = 1
while True:
if b[d-1] == 2:
c += 1
break
elif c > a:
print((-1))
exit()
else:
d = b[d-1]
c += 1
print(c)
| 17 | 15 | 313 | 242 |
a = int(eval(input()))
b = [int(eval(input())) for _ in range(a)]
c = 1
d = 0
e = {}
while True:
d += 1
if b[c - 1] == 2:
print(d)
exit()
else:
if (c - 1) not in e:
e.setdefault((c - 1), "")
else:
print((-1))
exit()
c = b[c - 1]
|
a = int(eval(input()))
b = [int(eval(input())) for _ in range(a)]
c = 0
d = 1
while True:
if b[d - 1] == 2:
c += 1
break
elif c > a:
print((-1))
exit()
else:
d = b[d - 1]
c += 1
print(c)
| false | 11.764706 |
[
"-c = 1",
"-d = 0",
"-e = {}",
"+c = 0",
"+d = 1",
"- d += 1",
"- if b[c - 1] == 2:",
"- print(d)",
"+ if b[d - 1] == 2:",
"+ c += 1",
"+ break",
"+ elif c > a:",
"+ print((-1))",
"- if (c - 1) not in e:",
"- e.setdefault((c - 1), \"\")",
"- else:",
"- print((-1))",
"- exit()",
"- c = b[c - 1]",
"+ d = b[d - 1]",
"+ c += 1",
"+print(c)"
] | false | 0.105688 | 0.085067 | 1.242399 |
[
"s035490999",
"s516448329"
] |
u188827677
|
p02813
|
python
|
s094892407
|
s083938744
| 36 | 33 | 9,188 | 13,784 |
Accepted
|
Accepted
| 8.33 |
from itertools import permutations
n = int(eval(input()))
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
t = 0
x = 0
y = 0
for i in permutations(list(range(1,n+1)),n):
t += 1
if i == p: x = t
if i == q: y = t
print((abs(x-y)))
|
from itertools import permutations
n = int(eval(input()))
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
nums = list(permutations(list(range(1,n+1)), n))
print((abs(nums.index(q) - nums.index(p))))
| 14 | 7 | 260 | 217 |
from itertools import permutations
n = int(eval(input()))
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
t = 0
x = 0
y = 0
for i in permutations(list(range(1, n + 1)), n):
t += 1
if i == p:
x = t
if i == q:
y = t
print((abs(x - y)))
|
from itertools import permutations
n = int(eval(input()))
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
nums = list(permutations(list(range(1, n + 1)), n))
print((abs(nums.index(q) - nums.index(p))))
| false | 50 |
[
"-t = 0",
"-x = 0",
"-y = 0",
"-for i in permutations(list(range(1, n + 1)), n):",
"- t += 1",
"- if i == p:",
"- x = t",
"- if i == q:",
"- y = t",
"-print((abs(x - y)))",
"+nums = list(permutations(list(range(1, n + 1)), n))",
"+print((abs(nums.index(q) - nums.index(p))))"
] | false | 0.047643 | 0.121193 | 0.393114 |
[
"s094892407",
"s083938744"
] |
u057964173
|
p03281
|
python
|
s348956165
|
s327918423
| 182 | 17 | 38,384 | 3,060 |
Accepted
|
Accepted
| 90.66 |
import sys
def input(): return sys.stdin.readline().strip()
def resolve():
n=int(eval(input()))
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5)+1):
if n % i == 0:
# 約数の片割れをリストに
divisors.append(i)
# 平方数じゃなければ片割れの相方をリストに
if i != n // i:
divisors.append(n//i)
# divisors.sort() # sort必要なかったらコメントアウト
return len(divisors)
ans=0
for i in range(1,n+1,2):
if make_divisors(i)==8:
ans+=1
print(ans)
resolve()
|
import sys
def input(): return sys.stdin.readline().strip()
def resolve():
n=int(eval(input()))
if 1<=n<105:
print((0))
elif n<135:
print((1))
elif n<165:
print((2))
elif n<189:
print((3))
elif n<195:
print((4))
else:
print((5))
resolve()
| 23 | 18 | 653 | 314 |
import sys
def input():
return sys.stdin.readline().strip()
def resolve():
n = int(eval(input()))
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5) + 1):
if n % i == 0:
# 約数の片割れをリストに
divisors.append(i)
# 平方数じゃなければ片割れの相方をリストに
if i != n // i:
divisors.append(n // i)
# divisors.sort() # sort必要なかったらコメントアウト
return len(divisors)
ans = 0
for i in range(1, n + 1, 2):
if make_divisors(i) == 8:
ans += 1
print(ans)
resolve()
|
import sys
def input():
return sys.stdin.readline().strip()
def resolve():
n = int(eval(input()))
if 1 <= n < 105:
print((0))
elif n < 135:
print((1))
elif n < 165:
print((2))
elif n < 189:
print((3))
elif n < 195:
print((4))
else:
print((5))
resolve()
| false | 21.73913 |
[
"-",
"- def make_divisors(n):",
"- divisors = []",
"- for i in range(1, int(n**0.5) + 1):",
"- if n % i == 0:",
"- # 約数の片割れをリストに",
"- divisors.append(i)",
"- # 平方数じゃなければ片割れの相方をリストに",
"- if i != n // i:",
"- divisors.append(n // i)",
"- # divisors.sort() # sort必要なかったらコメントアウト",
"- return len(divisors)",
"-",
"- ans = 0",
"- for i in range(1, n + 1, 2):",
"- if make_divisors(i) == 8:",
"- ans += 1",
"- print(ans)",
"+ if 1 <= n < 105:",
"+ print((0))",
"+ elif n < 135:",
"+ print((1))",
"+ elif n < 165:",
"+ print((2))",
"+ elif n < 189:",
"+ print((3))",
"+ elif n < 195:",
"+ print((4))",
"+ else:",
"+ print((5))"
] | false | 0.038746 | 0.038964 | 0.994419 |
[
"s348956165",
"s327918423"
] |
u156815136
|
p03672
|
python
|
s648470902
|
s429050625
| 48 | 39 | 5,660 | 10,300 |
Accepted
|
Accepted
| 18.75 |
from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
# d = m - k[i] - k[j]
# if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
def readInts():
return list(map(int,input().split()))
def main():
S = eval(input())
sl = len(S)
S = S[:-1]
sl -= 1
while True:
if sl % 2 != 0:
S = S[:-1]
sl -= 1
else:
if S[:sl//2] == S[sl//2:]:
print(sl)
exit()
else:
S = S[:-1]
sl -=1
if __name__ == '__main__':
main()
|
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
# d = m - k[i] - k[j]
# if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
return list(map(int,input().split()))
def I():
return int(eval(input()))
S = eval(input())
lnS = len(S)
for i in range(lnS-1,-1,-1):
#print(S)
S = S[:i]
flag = True
if S[:len(S)//2] == S[len(S)//2:]:
print((len(S)))
exit()
| 42 | 37 | 926 | 849 |
from statistics import median
# import collections
# aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
# d = m - k[i] - k[j]
# if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
def readInts():
return list(map(int, input().split()))
def main():
S = eval(input())
sl = len(S)
S = S[:-1]
sl -= 1
while True:
if sl % 2 != 0:
S = S[:-1]
sl -= 1
else:
if S[: sl // 2] == S[sl // 2 :]:
print(sl)
exit()
else:
S = S[:-1]
sl -= 1
if __name__ == "__main__":
main()
|
# from statistics import median
# import collections
# aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations, permutations, accumulate # (string,3) 3回
# from collections import deque
from collections import deque, defaultdict, Counter
import decimal
import re
# import bisect
#
# d = m - k[i] - k[j]
# if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
# mod = 9982443453
def readInts():
return list(map(int, input().split()))
def I():
return int(eval(input()))
S = eval(input())
lnS = len(S)
for i in range(lnS - 1, -1, -1):
# print(S)
S = S[:i]
flag = True
if S[: len(S) // 2] == S[len(S) // 2 :]:
print((len(S)))
exit()
| false | 11.904762 |
[
"-from statistics import median",
"-",
"+# from statistics import median",
"-from itertools import combinations # (string,3) 3回",
"-from collections import deque",
"-from collections import defaultdict",
"-import bisect",
"+from itertools import combinations, permutations, accumulate # (string,3) 3回",
"+# from collections import deque",
"+from collections import deque, defaultdict, Counter",
"+import decimal",
"+import re",
"+",
"+# import bisect",
"-",
"-",
"+# mod = 9982443453",
"-def main():",
"- S = eval(input())",
"- sl = len(S)",
"- S = S[:-1]",
"- sl -= 1",
"- while True:",
"- if sl % 2 != 0:",
"- S = S[:-1]",
"- sl -= 1",
"- else:",
"- if S[: sl // 2] == S[sl // 2 :]:",
"- print(sl)",
"- exit()",
"- else:",
"- S = S[:-1]",
"- sl -= 1",
"+def I():",
"+ return int(eval(input()))",
"-if __name__ == \"__main__\":",
"- main()",
"+S = eval(input())",
"+lnS = len(S)",
"+for i in range(lnS - 1, -1, -1):",
"+ # print(S)",
"+ S = S[:i]",
"+ flag = True",
"+ if S[: len(S) // 2] == S[len(S) // 2 :]:",
"+ print((len(S)))",
"+ exit()"
] | false | 0.036703 | 0.036016 | 1.019057 |
[
"s648470902",
"s429050625"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.