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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
u481250941 | p03835 | python | s684730742 | s261137257 | 812 | 690 | 5,876 | 16,240 | Accepted | Accepted | 15.02 | #
# abc051 b
#
import unittest
from io import StringIO
import sys
def input():
return sys.stdin.readline().rstrip()
def resolve():
K, S = list(map(int, input().split()))
ans = 0
for x in range(K+1):
for y in range(K+1):
z = S - x - y
if z >= 0 and z <= K:
ans += 1
print(ans)
class TestClass(unittest.TestCase):
def assertIO(self, input, output):
stdout, stdin = sys.stdout, sys.stdin
sys.stdout, sys.stdin = StringIO(), StringIO(input)
resolve()
sys.stdout.seek(0)
out = sys.stdout.read()[:-1]
sys.stdout, sys.stdin = stdout, stdin
self.assertEqual(out, output)
def test_入力例_1(self):
input = """2 2"""
output = """6"""
self.assertIO(input, output)
def test_入力例_2(self):
input = """5 15"""
output = """1"""
self.assertIO(input, output)
if __name__ == "__main__":
#unittest.main()
resolve()
| #
# abc051 b
#
import sys
from io import StringIO
import unittest
class TestClass(unittest.TestCase):
def assertIO(self, input, output):
stdout, stdin = sys.stdout, sys.stdin
sys.stdout, sys.stdin = StringIO(), StringIO(input)
resolve()
sys.stdout.seek(0)
out = sys.stdout.read()[:-1]
sys.stdout, sys.stdin = stdout, stdin
self.assertEqual(out, output)
def test_入力例_1(self):
input = """2 2"""
output = """6"""
self.assertIO(input, output)
def test_入力例_2(self):
input = """5 15"""
output = """1"""
self.assertIO(input, output)
def resolve():
K, S = list(map(int, input().split()))
ans = 0
for i in range(K+1):
for j in range(K+1):
if 0 <= S-i-j <= K:
ans += 1
print(ans)
if __name__ == "__main__":
# unittest.main()
resolve()
| 48 | 42 | 1,034 | 944 | #
# abc051 b
#
import unittest
from io import StringIO
import sys
def input():
return sys.stdin.readline().rstrip()
def resolve():
K, S = list(map(int, input().split()))
ans = 0
for x in range(K + 1):
for y in range(K + 1):
z = S - x - y
if z >= 0 and z <= K:
ans += 1
print(ans)
class TestClass(unittest.TestCase):
def assertIO(self, input, output):
stdout, stdin = sys.stdout, sys.stdin
sys.stdout, sys.stdin = StringIO(), StringIO(input)
resolve()
sys.stdout.seek(0)
out = sys.stdout.read()[:-1]
sys.stdout, sys.stdin = stdout, stdin
self.assertEqual(out, output)
def test_入力例_1(self):
input = """2 2"""
output = """6"""
self.assertIO(input, output)
def test_入力例_2(self):
input = """5 15"""
output = """1"""
self.assertIO(input, output)
if __name__ == "__main__":
# unittest.main()
resolve()
| #
# abc051 b
#
import sys
from io import StringIO
import unittest
class TestClass(unittest.TestCase):
def assertIO(self, input, output):
stdout, stdin = sys.stdout, sys.stdin
sys.stdout, sys.stdin = StringIO(), StringIO(input)
resolve()
sys.stdout.seek(0)
out = sys.stdout.read()[:-1]
sys.stdout, sys.stdin = stdout, stdin
self.assertEqual(out, output)
def test_入力例_1(self):
input = """2 2"""
output = """6"""
self.assertIO(input, output)
def test_入力例_2(self):
input = """5 15"""
output = """1"""
self.assertIO(input, output)
def resolve():
K, S = list(map(int, input().split()))
ans = 0
for i in range(K + 1):
for j in range(K + 1):
if 0 <= S - i - j <= K:
ans += 1
print(ans)
if __name__ == "__main__":
# unittest.main()
resolve()
| false | 12.5 | [
"+import sys",
"+from io import StringIO",
"-from io import StringIO",
"-import sys",
"-",
"-",
"-def input():",
"- return sys.stdin.readline().rstrip()",
"-",
"-",
"-def resolve():",
"- K, S = list(map(int, input().split()))",
"- ans = 0",
"- for x in range(K + 1):",
"- for y in range(K + 1):",
"- z = S - x - y",
"- if z >= 0 and z <= K:",
"- ans += 1",
"- print(ans)",
"+def resolve():",
"+ K, S = list(map(int, input().split()))",
"+ ans = 0",
"+ for i in range(K + 1):",
"+ for j in range(K + 1):",
"+ if 0 <= S - i - j <= K:",
"+ ans += 1",
"+ print(ans)",
"+",
"+"
] | false | 0.155479 | 0.379902 | 0.409261 | [
"s684730742",
"s261137257"
] |
u378691508 | p02787 | python | s939036759 | s021302130 | 580 | 471 | 229,068 | 217,288 | Accepted | Accepted | 18.79 | H, N = list(map(int, input().split()))
A=[]
B=[]
for i in range(N):
a,b = list(map(int, input().split()))
A.append(a)
B.append(b)
#dp[i+1][h] := i番目の魔法まで見て、ライフをh以上削った時の最小魔力コスト
dp=[[float("inf")]*(H+1) for _ in range(N+1)]
for i in range(N):
for h in range(H+1):
if A[i]>=h:
dp[i+1][h] = min(dp[i][h], B[i])
else:
dp[i+1][h] = min(dp[i][h], dp[i+1][h-A[i]]+B[i])
print((dp[-1][-1])) | H, N = list(map(int, input().split()))
A=[]
B=[]
for i in range(N):
a,b = list(map(int, input().split()))
A.append(a)
B.append(b)
#dp[i+1][h] := i番目の魔法まで見て、ライフをh以上削った時の最小魔力コスト
dp=[[float("inf")]*(H+1) for _ in range(N+1)]
for i in range(N):
for h in range(H+1):
if A[i]>=h:
dp[i+1][h] = min(dp[i][h], B[i])
else:
dp[i+1][h] = min(dp[i][h], dp[i+1][h-A[i]]+B[i], dp[i][h-A[i]]+B[i])
print((dp[-1][-1])) | 17 | 17 | 398 | 418 | H, N = list(map(int, input().split()))
A = []
B = []
for i in range(N):
a, b = list(map(int, input().split()))
A.append(a)
B.append(b)
# dp[i+1][h] := i番目の魔法まで見て、ライフをh以上削った時の最小魔力コスト
dp = [[float("inf")] * (H + 1) for _ in range(N + 1)]
for i in range(N):
for h in range(H + 1):
if A[i] >= h:
dp[i + 1][h] = min(dp[i][h], B[i])
else:
dp[i + 1][h] = min(dp[i][h], dp[i + 1][h - A[i]] + B[i])
print((dp[-1][-1]))
| H, N = list(map(int, input().split()))
A = []
B = []
for i in range(N):
a, b = list(map(int, input().split()))
A.append(a)
B.append(b)
# dp[i+1][h] := i番目の魔法まで見て、ライフをh以上削った時の最小魔力コスト
dp = [[float("inf")] * (H + 1) for _ in range(N + 1)]
for i in range(N):
for h in range(H + 1):
if A[i] >= h:
dp[i + 1][h] = min(dp[i][h], B[i])
else:
dp[i + 1][h] = min(
dp[i][h], dp[i + 1][h - A[i]] + B[i], dp[i][h - A[i]] + B[i]
)
print((dp[-1][-1]))
| false | 0 | [
"- dp[i + 1][h] = min(dp[i][h], dp[i + 1][h - A[i]] + B[i])",
"+ dp[i + 1][h] = min(",
"+ dp[i][h], dp[i + 1][h - A[i]] + B[i], dp[i][h - A[i]] + B[i]",
"+ )"
] | false | 0.224301 | 0.113874 | 1.969722 | [
"s939036759",
"s021302130"
] |
u480138356 | p03160 | python | s384157200 | s227717813 | 618 | 130 | 24,876 | 13,928 | Accepted | Accepted | 78.96 | import sys
import numpy as np
input = sys.stdin.readline
def main():
N = int(eval(input()))
h = list(map(int, input().split()))
h += [0, 0]
dp = np.full(N+2, int(1e15))
dp[0] = 0
for i in range(N):
dp[i+1] = min(dp[i+1], dp[i] + abs(h[i] - h[i+1]))
dp[i+2] = min(dp[i+2], dp[i] + abs(h[i] - h[i+2]))
# print(dp)
print((int(dp[N-1])))
if __name__ == "__main__":
main() | N = int(eval(input()))
h = list(map(int, input().split()))
# dp[i] := iからN-1までいく最小コスト
dp = [-1] * N
dp[N-1] = 0
dp[N-2] = abs(h[N-1] - h[N-2])
for i in range(N-3, -1, -1):
dp[i] = min(abs(h[i] - h[i+1]) + dp[i+1], abs(h[i] - h[i+2]) + dp[i+2])
print((dp[0])) | 19 | 13 | 432 | 268 | import sys
import numpy as np
input = sys.stdin.readline
def main():
N = int(eval(input()))
h = list(map(int, input().split()))
h += [0, 0]
dp = np.full(N + 2, int(1e15))
dp[0] = 0
for i in range(N):
dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]))
dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]))
# print(dp)
print((int(dp[N - 1])))
if __name__ == "__main__":
main()
| N = int(eval(input()))
h = list(map(int, input().split()))
# dp[i] := iからN-1までいく最小コスト
dp = [-1] * N
dp[N - 1] = 0
dp[N - 2] = abs(h[N - 1] - h[N - 2])
for i in range(N - 3, -1, -1):
dp[i] = min(abs(h[i] - h[i + 1]) + dp[i + 1], abs(h[i] - h[i + 2]) + dp[i + 2])
print((dp[0]))
| false | 31.578947 | [
"-import sys",
"-import numpy as np",
"-",
"-input = sys.stdin.readline",
"-",
"-",
"-def main():",
"- N = int(eval(input()))",
"- h = list(map(int, input().split()))",
"- h += [0, 0]",
"- dp = np.full(N + 2, int(1e15))",
"- dp[0] = 0",
"- for i in range(N):",
"- dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]))",
"- dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]))",
"- # print(dp)",
"- print((int(dp[N - 1])))",
"-",
"-",
"-if __name__ == \"__main__\":",
"- main()",
"+N = int(eval(input()))",
"+h = list(map(int, input().split()))",
"+# dp[i] := iからN-1までいく最小コスト",
"+dp = [-1] * N",
"+dp[N - 1] = 0",
"+dp[N - 2] = abs(h[N - 1] - h[N - 2])",
"+for i in range(N - 3, -1, -1):",
"+ dp[i] = min(abs(h[i] - h[i + 1]) + dp[i + 1], abs(h[i] - h[i + 2]) + dp[i + 2])",
"+print((dp[0]))"
] | false | 0.31277 | 0.040511 | 7.720709 | [
"s384157200",
"s227717813"
] |
u673361376 | p03001 | python | s184724491 | s171938646 | 21 | 17 | 2,940 | 2,940 | Accepted | Accepted | 19.05 | import sys
import math
w, h, x, y = list(map(int, sys.stdin.readline().split()))
S = w*h/2
if x == w/2 and y == h/2:
print((S,1))
else:
print((S, 0)) | W, H, x, y = list(map(int,input().split()))
cg = [W/2, H/2]
if [x, y] == cg:
print(( W * H / 2, 1))
else:
print((W * H / 2, 0)) | 9 | 6 | 152 | 130 | import sys
import math
w, h, x, y = list(map(int, sys.stdin.readline().split()))
S = w * h / 2
if x == w / 2 and y == h / 2:
print((S, 1))
else:
print((S, 0))
| W, H, x, y = list(map(int, input().split()))
cg = [W / 2, H / 2]
if [x, y] == cg:
print((W * H / 2, 1))
else:
print((W * H / 2, 0))
| false | 33.333333 | [
"-import sys",
"-import math",
"-",
"-w, h, x, y = list(map(int, sys.stdin.readline().split()))",
"-S = w * h / 2",
"-if x == w / 2 and y == h / 2:",
"- print((S, 1))",
"+W, H, x, y = list(map(int, input().split()))",
"+cg = [W / 2, H / 2]",
"+if [x, y] == cg:",
"+ print((W * H / 2, 1))",
"- print((S, 0))",
"+ print((W * H / 2, 0))"
] | false | 0.008022 | 0.035709 | 0.224653 | [
"s184724491",
"s171938646"
] |
u313291636 | p03290 | python | s868774083 | s808612372 | 235 | 98 | 44,400 | 74,744 | Accepted | Accepted | 58.3 | import math
d, g = list(map(int, input().split()))
l = [list(map(int, input().split())) for _ in range(d)]
ans = float('inf')
for i in range(2 ** d):
sum = 0
count = 0
s = set(_ for _ in range(1, d + 1))
for j in range(d):
if (i >> j) & 1 == 1:
sum += l[j][0] * (j + 1) * 100 + l[j][1]
count += l[j][0]
s.discard(j + 1)
if sum < g:
t = max(s)
n = min(l[t - 1][0], math.ceil((g - sum) / (t * 100)))
count += n
sum += n * t * 100
if sum >= g:
ans = min(ans, count)
print(ans)
| import math
d, g = list(map(int, input().split()))
l = [list(map(int, input().split())) for _ in range(d)]
ans = float('inf')
for i in range(2 ** d):
sum = 0
count = 0
s = set(k for k in range(1, d + 1))
for j in range(d):
if (i >> j) & 1 == 1:
sum += l[j][0] * (j + 1) * 100 + l[j][1]
count += l[j][0]
s.discard(j + 1)
if sum < g:
t = max(s)
n = min(l[t - 1][0] - 1, math.ceil((g - sum) / (t * 100)))
count += n
sum += n * t * 100
if sum >= g:
ans = min(ans, count)
print(ans)
| 23 | 23 | 600 | 604 | import math
d, g = list(map(int, input().split()))
l = [list(map(int, input().split())) for _ in range(d)]
ans = float("inf")
for i in range(2**d):
sum = 0
count = 0
s = set(_ for _ in range(1, d + 1))
for j in range(d):
if (i >> j) & 1 == 1:
sum += l[j][0] * (j + 1) * 100 + l[j][1]
count += l[j][0]
s.discard(j + 1)
if sum < g:
t = max(s)
n = min(l[t - 1][0], math.ceil((g - sum) / (t * 100)))
count += n
sum += n * t * 100
if sum >= g:
ans = min(ans, count)
print(ans)
| import math
d, g = list(map(int, input().split()))
l = [list(map(int, input().split())) for _ in range(d)]
ans = float("inf")
for i in range(2**d):
sum = 0
count = 0
s = set(k for k in range(1, d + 1))
for j in range(d):
if (i >> j) & 1 == 1:
sum += l[j][0] * (j + 1) * 100 + l[j][1]
count += l[j][0]
s.discard(j + 1)
if sum < g:
t = max(s)
n = min(l[t - 1][0] - 1, math.ceil((g - sum) / (t * 100)))
count += n
sum += n * t * 100
if sum >= g:
ans = min(ans, count)
print(ans)
| false | 0 | [
"- s = set(_ for _ in range(1, d + 1))",
"+ s = set(k for k in range(1, d + 1))",
"- n = min(l[t - 1][0], math.ceil((g - sum) / (t * 100)))",
"+ n = min(l[t - 1][0] - 1, math.ceil((g - sum) / (t * 100)))"
] | false | 0.038161 | 0.036016 | 1.059561 | [
"s868774083",
"s808612372"
] |
u788137651 | p03241 | python | s422151268 | s323744130 | 381 | 289 | 69,740 | 64,236 | Accepted | Accepted | 24.15 | #
# ⋀_⋀
# (・ω・)
# ./ U ∽ U\
# │* 合 *│
# │* 格 *│
# │* 祈 *│
# │* 願 *│
# │* *│
#  ̄
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないyp
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A):
for a in A: print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
# 約数列挙
def find_divisor(n):
divisors=[]
for i in range(1, int(sqrt(n)) + 1):
if n % i == 0:
divisors.append(i)
if i*i!=n:
divisors.append(n // i)
return divisors
# 素因数分解
def prime_factorization(n):
fact=[]
for i in range(2, int(sqrt(n)) + 1):
while n % i == 0:
n //= i
fact.append(i)
if n!=1:
fact.append(n)
return fact
def main():
N,M=MI()
D=find_divisor(M)
ans = 1
for d in D:
if M//d >= N:
ans = max(ans,d)
print(ans)
if __name__ == '__main__':
main()
| #
# ⋀_⋀
# (・ω・)
# ./ U ∽ U\
# │* 合 *│
# │* 格 *│
# │* 祈 *│
# │* 願 *│
# │* *│
#  ̄
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないyp
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A):
for a in A: print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
# 約数列挙
def find_divisor(n):
divisors=[]
for i in range(1, int(sqrt(n)) + 1):
if n % i == 0:
divisors.append(i)
if i*i!=n:
divisors.append(n // i)
return divisors
def main():
N,M=MI()
ans = 0
for d in find_divisor(M):
if N<=M//d:
ans = max(ans,d)
print(ans)
if __name__ == '__main__':
main()
| 72 | 63 | 1,946 | 1,723 | #
# ⋀_⋀
# (・ω・)
# ./ U ∽ U\
# │* 合 *│
# │* 格 *│
# │* 祈 *│
# │* 願 *│
# │* *│
#  ̄
#
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline
from math import floor, sqrt, factorial, hypot, log # log2ないyp
from heapq import heappop, heappush, heappushpop
from collections import Counter, defaultdict, deque
from itertools import (
accumulate,
permutations,
combinations,
product,
combinations_with_replacement,
)
from bisect import bisect_left, bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a, b):
return (a + b - 1) // b
inf = float("inf")
mod = 10**9 + 7
def pprint(*A):
for a in A:
print(*a, sep="\n")
def INT_(n):
return int(n) - 1
def MI():
return map(int, input().split())
def MF():
return map(float, input().split())
def MI_():
return map(INT_, input().split())
def LI():
return list(MI())
def LI_():
return [int(x) - 1 for x in input().split()]
def LF():
return list(MF())
def LIN(n: int):
return [I() for _ in range(n)]
def LLIN(n: int):
return [LI() for _ in range(n)]
def LLIN_(n: int):
return [LI_() for _ in range(n)]
def LLI():
return [list(map(int, l.split())) for l in input()]
def I():
return int(input())
def F():
return float(input())
def ST():
return input().replace("\n", "")
# 約数列挙
def find_divisor(n):
divisors = []
for i in range(1, int(sqrt(n)) + 1):
if n % i == 0:
divisors.append(i)
if i * i != n:
divisors.append(n // i)
return divisors
# 素因数分解
def prime_factorization(n):
fact = []
for i in range(2, int(sqrt(n)) + 1):
while n % i == 0:
n //= i
fact.append(i)
if n != 1:
fact.append(n)
return fact
def main():
N, M = MI()
D = find_divisor(M)
ans = 1
for d in D:
if M // d >= N:
ans = max(ans, d)
print(ans)
if __name__ == "__main__":
main()
| #
# ⋀_⋀
# (・ω・)
# ./ U ∽ U\
# │* 合 *│
# │* 格 *│
# │* 祈 *│
# │* 願 *│
# │* *│
#  ̄
#
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline
from math import floor, sqrt, factorial, hypot, log # log2ないyp
from heapq import heappop, heappush, heappushpop
from collections import Counter, defaultdict, deque
from itertools import (
accumulate,
permutations,
combinations,
product,
combinations_with_replacement,
)
from bisect import bisect_left, bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a, b):
return (a + b - 1) // b
inf = float("inf")
mod = 10**9 + 7
def pprint(*A):
for a in A:
print(*a, sep="\n")
def INT_(n):
return int(n) - 1
def MI():
return map(int, input().split())
def MF():
return map(float, input().split())
def MI_():
return map(INT_, input().split())
def LI():
return list(MI())
def LI_():
return [int(x) - 1 for x in input().split()]
def LF():
return list(MF())
def LIN(n: int):
return [I() for _ in range(n)]
def LLIN(n: int):
return [LI() for _ in range(n)]
def LLIN_(n: int):
return [LI_() for _ in range(n)]
def LLI():
return [list(map(int, l.split())) for l in input()]
def I():
return int(input())
def F():
return float(input())
def ST():
return input().replace("\n", "")
# 約数列挙
def find_divisor(n):
divisors = []
for i in range(1, int(sqrt(n)) + 1):
if n % i == 0:
divisors.append(i)
if i * i != n:
divisors.append(n // i)
return divisors
def main():
N, M = MI()
ans = 0
for d in find_divisor(M):
if N <= M // d:
ans = max(ans, d)
print(ans)
if __name__ == "__main__":
main()
| false | 12.5 | [
"-# 素因数分解",
"-def prime_factorization(n):",
"- fact = []",
"- for i in range(2, int(sqrt(n)) + 1):",
"- while n % i == 0:",
"- n //= i",
"- fact.append(i)",
"- if n != 1:",
"- fact.append(n)",
"- return fact",
"-",
"-",
"- D = find_divisor(M)",
"- ans = 1",
"- for d in D:",
"- if M // d >= N:",
"+ ans = 0",
"+ for d in find_divisor(M):",
"+ if N <= M // d:"
] | false | 0.039747 | 0.039521 | 1.005714 | [
"s422151268",
"s323744130"
] |
u254871849 | p02843 | python | s581983274 | s511274369 | 60 | 18 | 3,828 | 2,940 | Accepted | Accepted | 70 | import sys
payable = [False] * (10 ** 5 + 1)
payable[0] = True
for i in range(100,106):
payable[i] = True
for i in range(106, 10 ** 5 + 1):
payable[i] = any(payable[i-105:i-99])
def main():
x = int(sys.stdin.readline().rstrip())
print((payable[x] & 1))
if __name__ == '__main__':
main() | import sys
def main():
x = int(sys.stdin.readline().rstrip())
q, r = divmod(x, 100)
if 5 * q >= r:
ans = 1
else:
ans = 0
print(ans)
if __name__ == '__main__':
main() | 16 | 15 | 323 | 223 | import sys
payable = [False] * (10**5 + 1)
payable[0] = True
for i in range(100, 106):
payable[i] = True
for i in range(106, 10**5 + 1):
payable[i] = any(payable[i - 105 : i - 99])
def main():
x = int(sys.stdin.readline().rstrip())
print((payable[x] & 1))
if __name__ == "__main__":
main()
| import sys
def main():
x = int(sys.stdin.readline().rstrip())
q, r = divmod(x, 100)
if 5 * q >= r:
ans = 1
else:
ans = 0
print(ans)
if __name__ == "__main__":
main()
| false | 6.25 | [
"-",
"-payable = [False] * (10**5 + 1)",
"-payable[0] = True",
"-for i in range(100, 106):",
"- payable[i] = True",
"-for i in range(106, 10**5 + 1):",
"- payable[i] = any(payable[i - 105 : i - 99])",
"- print((payable[x] & 1))",
"+ q, r = divmod(x, 100)",
"+ if 5 * q >= r:",
"+ ans = 1",
"+ else:",
"+ ans = 0",
"+ print(ans)"
] | false | 0.099217 | 0.040602 | 2.443649 | [
"s581983274",
"s511274369"
] |
u844005364 | p03170 | python | s593579340 | s652482745 | 1,982 | 114 | 3,828 | 3,828 | Accepted | Accepted | 94.25 |
n, k = list(map(int, input().split()))
arr = list(map(int, input().split()))
dp = [False] * (k + 1)
for i in range(1, k+1):
for a in arr:
if i - a >= 0 and not dp[i - a]:
dp[i] = True
print(("First" if dp[k] else "Second"))
| n, k = list(map(int, input().split()))
arr = list(map(int, input().split()))
dp = [False] * (k + 1)
for i in range(k + 1):
if not dp[i]:
for a in arr:
if i + a > k:
break
dp[i + a] = True
print(("First" if dp[k] else "Second"))
| 13 | 12 | 257 | 285 | n, k = list(map(int, input().split()))
arr = list(map(int, input().split()))
dp = [False] * (k + 1)
for i in range(1, k + 1):
for a in arr:
if i - a >= 0 and not dp[i - a]:
dp[i] = True
print(("First" if dp[k] else "Second"))
| n, k = list(map(int, input().split()))
arr = list(map(int, input().split()))
dp = [False] * (k + 1)
for i in range(k + 1):
if not dp[i]:
for a in arr:
if i + a > k:
break
dp[i + a] = True
print(("First" if dp[k] else "Second"))
| false | 7.692308 | [
"-for i in range(1, k + 1):",
"- for a in arr:",
"- if i - a >= 0 and not dp[i - a]:",
"- dp[i] = True",
"+for i in range(k + 1):",
"+ if not dp[i]:",
"+ for a in arr:",
"+ if i + a > k:",
"+ break",
"+ dp[i + a] = True"
] | false | 0.048659 | 0.039898 | 1.21957 | [
"s593579340",
"s652482745"
] |
u254871849 | p03681 | python | s992444178 | s151885058 | 947 | 332 | 121,844 | 74,940 | Accepted | Accepted | 64.94 | import sys
MOD = 10 ** 9 + 7
U = 10 ** 6
def make_fac_ifac(n=U, p=MOD):
fac = [None] * (n + 1)
fac[0] = 1
for i in range(n): fac[i+1] = fac[i] * (i + 1) % p
ifac = [None] * (n + 1)
ifac[n] = pow(fac[n], p - 2, p)
for i in range(n, 0, -1): ifac[i-1] = ifac[i] * i % p
return fac, ifac
fac, ifac = make_fac_ifac()
def mod_choose(n, r, p=MOD):
if r > n or r < 0: return 0
return fac[n] * ifac[r] % p * ifac[n-r] % p
def make_choose_n_table(n=10 ** 9, r=U, p=MOD):
table = [None] * (r + 1)
table[0] = 1
j = 1
for i in range(n, n - r, -1):
table[j] = table[j-1] * i % p
j += 1
for i in range(1, r + 1): table[i] = table[i] * ifac[i] % p
return table
mod_choose_n = make_choose_n_table()
n, m = list(map(int, sys.stdin.readline().split()))
def main():
d = abs(n - m)
if d >= 2: res = 0
elif d == 1: res = fac[n] * fac[m] % MOD
else: res = fac[n] * fac[m] % MOD * 2 % MOD
print(res)
if __name__ == '__main__':
main() | import sys
import numpy as np
MOD = 10 ** 9 + 7
U = 10 ** 6
def mod_cumprod(a, p=MOD):
l = len(a); sql = int(np.sqrt(l) + 1)
a = np.resize(a, sql**2).reshape(sql, sql)
for i in range(sql - 1): a[:, i+1] *= a[:, i]; a[:, i+1] %= p
for i in range(sql - 1): a[i+1] *= a[i, -1]; a[i+1] %= p
return np.ravel(a)[:l]
def make_fac_ifac(n=U, p=MOD):
fac = np.arange(n + 1); fac[0] = 1
fac = mod_cumprod(fac)
ifac = np.arange(n + 1, 0, -1); ifac[0] = pow(int(fac[-1]), p-2, p)
ifac = mod_cumprod(ifac)[n::-1]
return fac, ifac
fac, ifac = make_fac_ifac()
def mod_choose(n, r, p=MOD):
if r > n or r < 0: return 0
return fac[n] * ifac[r] % p * ifac[n-r] % p
def make_choose_n_table(n=10 ** 9, r=U, p=MOD):
table = [None] * (r + 1)
table = np.arange(n + 1, n - r, -1); table[0] = 1
table[1:] = mod_cumprod(table[1:]) * ifac[1:r+1] % p
return table
mod_choose_n = make_choose_n_table()
n, m = list(map(int, sys.stdin.readline().split()))
def main():
d = abs(n - m)
if d >= 2: res = 0
elif d == 1: res = fac[n] * fac[m] % MOD
else: res = fac[n] * fac[m] % MOD * 2 % MOD
print(res)
if __name__ == '__main__':
main() | 42 | 44 | 1,009 | 1,190 | import sys
MOD = 10**9 + 7
U = 10**6
def make_fac_ifac(n=U, p=MOD):
fac = [None] * (n + 1)
fac[0] = 1
for i in range(n):
fac[i + 1] = fac[i] * (i + 1) % p
ifac = [None] * (n + 1)
ifac[n] = pow(fac[n], p - 2, p)
for i in range(n, 0, -1):
ifac[i - 1] = ifac[i] * i % p
return fac, ifac
fac, ifac = make_fac_ifac()
def mod_choose(n, r, p=MOD):
if r > n or r < 0:
return 0
return fac[n] * ifac[r] % p * ifac[n - r] % p
def make_choose_n_table(n=10**9, r=U, p=MOD):
table = [None] * (r + 1)
table[0] = 1
j = 1
for i in range(n, n - r, -1):
table[j] = table[j - 1] * i % p
j += 1
for i in range(1, r + 1):
table[i] = table[i] * ifac[i] % p
return table
mod_choose_n = make_choose_n_table()
n, m = list(map(int, sys.stdin.readline().split()))
def main():
d = abs(n - m)
if d >= 2:
res = 0
elif d == 1:
res = fac[n] * fac[m] % MOD
else:
res = fac[n] * fac[m] % MOD * 2 % MOD
print(res)
if __name__ == "__main__":
main()
| import sys
import numpy as np
MOD = 10**9 + 7
U = 10**6
def mod_cumprod(a, p=MOD):
l = len(a)
sql = int(np.sqrt(l) + 1)
a = np.resize(a, sql**2).reshape(sql, sql)
for i in range(sql - 1):
a[:, i + 1] *= a[:, i]
a[:, i + 1] %= p
for i in range(sql - 1):
a[i + 1] *= a[i, -1]
a[i + 1] %= p
return np.ravel(a)[:l]
def make_fac_ifac(n=U, p=MOD):
fac = np.arange(n + 1)
fac[0] = 1
fac = mod_cumprod(fac)
ifac = np.arange(n + 1, 0, -1)
ifac[0] = pow(int(fac[-1]), p - 2, p)
ifac = mod_cumprod(ifac)[n::-1]
return fac, ifac
fac, ifac = make_fac_ifac()
def mod_choose(n, r, p=MOD):
if r > n or r < 0:
return 0
return fac[n] * ifac[r] % p * ifac[n - r] % p
def make_choose_n_table(n=10**9, r=U, p=MOD):
table = [None] * (r + 1)
table = np.arange(n + 1, n - r, -1)
table[0] = 1
table[1:] = mod_cumprod(table[1:]) * ifac[1 : r + 1] % p
return table
mod_choose_n = make_choose_n_table()
n, m = list(map(int, sys.stdin.readline().split()))
def main():
d = abs(n - m)
if d >= 2:
res = 0
elif d == 1:
res = fac[n] * fac[m] % MOD
else:
res = fac[n] * fac[m] % MOD * 2 % MOD
print(res)
if __name__ == "__main__":
main()
| false | 4.545455 | [
"+import numpy as np",
"+def mod_cumprod(a, p=MOD):",
"+ l = len(a)",
"+ sql = int(np.sqrt(l) + 1)",
"+ a = np.resize(a, sql**2).reshape(sql, sql)",
"+ for i in range(sql - 1):",
"+ a[:, i + 1] *= a[:, i]",
"+ a[:, i + 1] %= p",
"+ for i in range(sql - 1):",
"+ a[i + 1] *= a[i, -1]",
"+ a[i + 1] %= p",
"+ return np.ravel(a)[:l]",
"+",
"+",
"- fac = [None] * (n + 1)",
"+ fac = np.arange(n + 1)",
"- for i in range(n):",
"- fac[i + 1] = fac[i] * (i + 1) % p",
"- ifac = [None] * (n + 1)",
"- ifac[n] = pow(fac[n], p - 2, p)",
"- for i in range(n, 0, -1):",
"- ifac[i - 1] = ifac[i] * i % p",
"+ fac = mod_cumprod(fac)",
"+ ifac = np.arange(n + 1, 0, -1)",
"+ ifac[0] = pow(int(fac[-1]), p - 2, p)",
"+ ifac = mod_cumprod(ifac)[n::-1]",
"+ table = np.arange(n + 1, n - r, -1)",
"- j = 1",
"- for i in range(n, n - r, -1):",
"- table[j] = table[j - 1] * i % p",
"- j += 1",
"- for i in range(1, r + 1):",
"- table[i] = table[i] * ifac[i] % p",
"+ table[1:] = mod_cumprod(table[1:]) * ifac[1 : r + 1] % p"
] | false | 1.067502 | 0.961714 | 1.11 | [
"s992444178",
"s151885058"
] |
u788068140 | p02947 | python | s138202211 | s653160788 | 343 | 248 | 24,980 | 29,144 | Accepted | Accepted | 27.7 | def ccc(n):
#c(n,2)
result = (n * (n-1))//2
return result
def sortString(a):
a = list(a)
a.sort()
return "".join(a)
def calculate(arr):
if len(arr) == 0:
return 0
dict = {}
for i in range(len(arr)):
s = sortString(arr[i])
if dict.get(s) == None:
dict.setdefault(s,1)
else:
dict.__setitem__(s,dict.get(s) + 1)
sum = 0
for v in list(dict.values()):
sum += ccc(v)
return sum
arr = []
N = int(eval(input()))
for i in range(N):
arr.append(eval(input()))
result = calculate(arr)
print(result) | N = 3
SRR = [
"acornistnt",
"peanutbomb",
"constraint",
]
N = 5
SRR = [
"abaaaaaaaa",
"oneplustwo",
"aaaaaaaaba",
"twoplusone",
"aaaabaaaaa",
]
N = int(eval(input()))
SRR = []
for i in range(N):
SRR.append(eval(input()))
def calculate(n,arr):
dict = {}
for i in range(n):
str = "".join(sorted(list(arr[i])))
if dict.get(str) == None:
dict.__setitem__(str,1)
else:
dict.__setitem__(str,dict.get(str) + 1)
result = 0
for item in list(dict.values()):
if item > 1:
result += (item * (item-1)) // 2
print(result)
calculate(N, SRR) | 43 | 41 | 641 | 680 | def ccc(n):
# c(n,2)
result = (n * (n - 1)) // 2
return result
def sortString(a):
a = list(a)
a.sort()
return "".join(a)
def calculate(arr):
if len(arr) == 0:
return 0
dict = {}
for i in range(len(arr)):
s = sortString(arr[i])
if dict.get(s) == None:
dict.setdefault(s, 1)
else:
dict.__setitem__(s, dict.get(s) + 1)
sum = 0
for v in list(dict.values()):
sum += ccc(v)
return sum
arr = []
N = int(eval(input()))
for i in range(N):
arr.append(eval(input()))
result = calculate(arr)
print(result)
| N = 3
SRR = [
"acornistnt",
"peanutbomb",
"constraint",
]
N = 5
SRR = [
"abaaaaaaaa",
"oneplustwo",
"aaaaaaaaba",
"twoplusone",
"aaaabaaaaa",
]
N = int(eval(input()))
SRR = []
for i in range(N):
SRR.append(eval(input()))
def calculate(n, arr):
dict = {}
for i in range(n):
str = "".join(sorted(list(arr[i])))
if dict.get(str) == None:
dict.__setitem__(str, 1)
else:
dict.__setitem__(str, dict.get(str) + 1)
result = 0
for item in list(dict.values()):
if item > 1:
result += (item * (item - 1)) // 2
print(result)
calculate(N, SRR)
| false | 4.651163 | [
"-def ccc(n):",
"- # c(n,2)",
"- result = (n * (n - 1)) // 2",
"- return result",
"+N = 3",
"+SRR = [",
"+ \"acornistnt\",",
"+ \"peanutbomb\",",
"+ \"constraint\",",
"+]",
"+N = 5",
"+SRR = [",
"+ \"abaaaaaaaa\",",
"+ \"oneplustwo\",",
"+ \"aaaaaaaaba\",",
"+ \"twoplusone\",",
"+ \"aaaabaaaaa\",",
"+]",
"+N = int(eval(input()))",
"+SRR = []",
"+for i in range(N):",
"+ SRR.append(eval(input()))",
"-def sortString(a):",
"- a = list(a)",
"- a.sort()",
"- return \"\".join(a)",
"+def calculate(n, arr):",
"+ dict = {}",
"+ for i in range(n):",
"+ str = \"\".join(sorted(list(arr[i])))",
"+ if dict.get(str) == None:",
"+ dict.__setitem__(str, 1)",
"+ else:",
"+ dict.__setitem__(str, dict.get(str) + 1)",
"+ result = 0",
"+ for item in list(dict.values()):",
"+ if item > 1:",
"+ result += (item * (item - 1)) // 2",
"+ print(result)",
"-def calculate(arr):",
"- if len(arr) == 0:",
"- return 0",
"- dict = {}",
"- for i in range(len(arr)):",
"- s = sortString(arr[i])",
"- if dict.get(s) == None:",
"- dict.setdefault(s, 1)",
"- else:",
"- dict.__setitem__(s, dict.get(s) + 1)",
"- sum = 0",
"- for v in list(dict.values()):",
"- sum += ccc(v)",
"- return sum",
"-",
"-",
"-arr = []",
"-N = int(eval(input()))",
"-for i in range(N):",
"- arr.append(eval(input()))",
"-result = calculate(arr)",
"-print(result)",
"+calculate(N, SRR)"
] | false | 0.07004 | 0.038209 | 1.833075 | [
"s138202211",
"s653160788"
] |
u597455618 | p04045 | python | s336932876 | s833351283 | 246 | 153 | 9,076 | 9,212 | Accepted | Accepted | 37.8 | def dfs(A: list):
if len(A) > len(str(n))+1:
return
if len(A) and (x := int("".join(A))) >= n and ans[0] > x:
ans[0] = x
return
for v in d:
if v == "0" and len(A) == 0:
next
A.append(v)
dfs(A)
A.pop()
n, k = list(map(int, input().split()))
d = sorted(list(set([str(i) for i in range(10)]) - set(input().split())))
ans = [10**10]
dfs([])
print((ans[0]))
| def dfs(A: list):
if len(A) > nn:
return
if len(A) and (x := int("".join(A))) >= n and ans[0] > x:
ans[0] = x
return
for v in d:
if v == "0" and len(A) == 0:
next
A.append(v)
dfs(A)
A.pop()
n, k = list(map(int, input().split()))
d = sorted(list(set([str(i) for i in range(10)]) - set(input().split())))
nn = len(str(n))+1
ans = [10**7]
dfs([])
print((ans[0]))
| 20 | 21 | 447 | 455 | def dfs(A: list):
if len(A) > len(str(n)) + 1:
return
if len(A) and (x := int("".join(A))) >= n and ans[0] > x:
ans[0] = x
return
for v in d:
if v == "0" and len(A) == 0:
next
A.append(v)
dfs(A)
A.pop()
n, k = list(map(int, input().split()))
d = sorted(list(set([str(i) for i in range(10)]) - set(input().split())))
ans = [10**10]
dfs([])
print((ans[0]))
| def dfs(A: list):
if len(A) > nn:
return
if len(A) and (x := int("".join(A))) >= n and ans[0] > x:
ans[0] = x
return
for v in d:
if v == "0" and len(A) == 0:
next
A.append(v)
dfs(A)
A.pop()
n, k = list(map(int, input().split()))
d = sorted(list(set([str(i) for i in range(10)]) - set(input().split())))
nn = len(str(n)) + 1
ans = [10**7]
dfs([])
print((ans[0]))
| false | 4.761905 | [
"- if len(A) > len(str(n)) + 1:",
"+ if len(A) > nn:",
"-ans = [10**10]",
"+nn = len(str(n)) + 1",
"+ans = [10**7]"
] | false | 0.080316 | 0.085229 | 0.942359 | [
"s336932876",
"s833351283"
] |
u525065967 | p03634 | python | s059609262 | s265907886 | 1,605 | 1,471 | 52,924 | 59,008 | Accepted | Accepted | 8.35 | # abc070d: Transit Tree Path
n = int(eval(input()))
T = [[] for _ in range(n)]
for _ in range(n-1):
v1,v2,d = list(map(int, input().split()))
v1,v2 = v1-1,v2-1
T[v1].append([v1,v2,d])
T[v2].append([v2,v1,d])
q,k = list(map(int, input().split()))
visit = [False]*(n)
depth = [0]*(n)
stack = [[-1,k-1,0]]
while stack:
p,c,d = stack.pop()
if visit[c]: continue
visit[c] = True
depth[c] = d
if p>=0: depth[c] += depth[p]
for pp,cc,dd in T[c]:
if not visit[cc]: stack.append([pp,cc,dd])
for _ in range(q):
v1,v2 = list(map(int, input().split()))
print((depth[v1-1]+depth[v2-1])) | ## abc070d: Transit Tree Path
n = int(eval(input()))
T = [{} for _ in range(n)]
for _ in range(n-1):
v1,v2,d = list(map(int, input().split()))
T[v1-1][v2-1] = d
T[v2-1][v1-1] = d
q,k = list(map(int, input().split()))
visit = [False]*n
depth = [0]*n
stack = [[-1,k-1,0]]
while stack:
p,c,d = stack.pop()
if visit[c]: continue
visit[c] = True
depth[c] = d
if p>=0: depth[c] += depth[p]
for cc in list(T[c].keys()):
if not visit[cc]: stack.append([c,cc,T[c][cc]])
for _ in range(q):
v1,v2 = list(map(int, input().split()))
print((depth[v1-1]+depth[v2-1])) | 28 | 27 | 635 | 603 | # abc070d: Transit Tree Path
n = int(eval(input()))
T = [[] for _ in range(n)]
for _ in range(n - 1):
v1, v2, d = list(map(int, input().split()))
v1, v2 = v1 - 1, v2 - 1
T[v1].append([v1, v2, d])
T[v2].append([v2, v1, d])
q, k = list(map(int, input().split()))
visit = [False] * (n)
depth = [0] * (n)
stack = [[-1, k - 1, 0]]
while stack:
p, c, d = stack.pop()
if visit[c]:
continue
visit[c] = True
depth[c] = d
if p >= 0:
depth[c] += depth[p]
for pp, cc, dd in T[c]:
if not visit[cc]:
stack.append([pp, cc, dd])
for _ in range(q):
v1, v2 = list(map(int, input().split()))
print((depth[v1 - 1] + depth[v2 - 1]))
| ## abc070d: Transit Tree Path
n = int(eval(input()))
T = [{} for _ in range(n)]
for _ in range(n - 1):
v1, v2, d = list(map(int, input().split()))
T[v1 - 1][v2 - 1] = d
T[v2 - 1][v1 - 1] = d
q, k = list(map(int, input().split()))
visit = [False] * n
depth = [0] * n
stack = [[-1, k - 1, 0]]
while stack:
p, c, d = stack.pop()
if visit[c]:
continue
visit[c] = True
depth[c] = d
if p >= 0:
depth[c] += depth[p]
for cc in list(T[c].keys()):
if not visit[cc]:
stack.append([c, cc, T[c][cc]])
for _ in range(q):
v1, v2 = list(map(int, input().split()))
print((depth[v1 - 1] + depth[v2 - 1]))
| false | 3.571429 | [
"-# abc070d: Transit Tree Path",
"+## abc070d: Transit Tree Path",
"-T = [[] for _ in range(n)]",
"+T = [{} for _ in range(n)]",
"- v1, v2 = v1 - 1, v2 - 1",
"- T[v1].append([v1, v2, d])",
"- T[v2].append([v2, v1, d])",
"+ T[v1 - 1][v2 - 1] = d",
"+ T[v2 - 1][v1 - 1] = d",
"-visit = [False] * (n)",
"-depth = [0] * (n)",
"+visit = [False] * n",
"+depth = [0] * n",
"- for pp, cc, dd in T[c]:",
"+ for cc in list(T[c].keys()):",
"- stack.append([pp, cc, dd])",
"+ stack.append([c, cc, T[c][cc]])"
] | false | 0.050241 | 0.042937 | 1.170117 | [
"s059609262",
"s265907886"
] |
u169138653 | p03044 | python | s325533044 | s351623580 | 703 | 636 | 39,060 | 39,144 | Accepted | Accepted | 9.53 | from collections import deque
n=int(eval(input()))
edge=[[] for i in range(n)]
if n==1:
print((0))
exit()
col=[-1 for i in range(n)]
for i in range(n-1):
u,v,w=list(map(int,input().split()))
u-=1
v-=1
edge[u].append((v,w))
edge[v].append((u,w))
def dfs(edge,col):
stack=deque([0])
col[0]=0
while stack:
x=stack.pop()
for i,j in edge[x]:
newx=i
if col[i]==-1:
col[newx]=(col[x]+j)%2
stack.append(newx)
return col
for i in range(n):
print((dfs(edge,col)[i])) | from collections import deque
n=int(eval(input()))
edges=[[] for _ in range(n)]
visited=[-1 for _ in range(n)]
for i in range(n-1):
u,v,w=list(map(int,input().split()))
edges[u-1].append((v-1,w))
edges[v-1].append((u-1,w))
def dfs(edges,visited):
stack=deque([0])
visited[0]=0
while stack:
x=stack.pop()
for newx,w in edges[x]:
if visited[newx]==-1:
if w%2:
visited[newx]=1-visited[x]
else:
visited[newx]=visited[x]
stack.append(newx)
return visited
for i in dfs(edges,visited):
print(i) | 26 | 23 | 525 | 571 | from collections import deque
n = int(eval(input()))
edge = [[] for i in range(n)]
if n == 1:
print((0))
exit()
col = [-1 for i in range(n)]
for i in range(n - 1):
u, v, w = list(map(int, input().split()))
u -= 1
v -= 1
edge[u].append((v, w))
edge[v].append((u, w))
def dfs(edge, col):
stack = deque([0])
col[0] = 0
while stack:
x = stack.pop()
for i, j in edge[x]:
newx = i
if col[i] == -1:
col[newx] = (col[x] + j) % 2
stack.append(newx)
return col
for i in range(n):
print((dfs(edge, col)[i]))
| from collections import deque
n = int(eval(input()))
edges = [[] for _ in range(n)]
visited = [-1 for _ in range(n)]
for i in range(n - 1):
u, v, w = list(map(int, input().split()))
edges[u - 1].append((v - 1, w))
edges[v - 1].append((u - 1, w))
def dfs(edges, visited):
stack = deque([0])
visited[0] = 0
while stack:
x = stack.pop()
for newx, w in edges[x]:
if visited[newx] == -1:
if w % 2:
visited[newx] = 1 - visited[x]
else:
visited[newx] = visited[x]
stack.append(newx)
return visited
for i in dfs(edges, visited):
print(i)
| false | 11.538462 | [
"-edge = [[] for i in range(n)]",
"-if n == 1:",
"- print((0))",
"- exit()",
"-col = [-1 for i in range(n)]",
"+edges = [[] for _ in range(n)]",
"+visited = [-1 for _ in range(n)]",
"- u -= 1",
"- v -= 1",
"- edge[u].append((v, w))",
"- edge[v].append((u, w))",
"+ edges[u - 1].append((v - 1, w))",
"+ edges[v - 1].append((u - 1, w))",
"-def dfs(edge, col):",
"+def dfs(edges, visited):",
"- col[0] = 0",
"+ visited[0] = 0",
"- for i, j in edge[x]:",
"- newx = i",
"- if col[i] == -1:",
"- col[newx] = (col[x] + j) % 2",
"+ for newx, w in edges[x]:",
"+ if visited[newx] == -1:",
"+ if w % 2:",
"+ visited[newx] = 1 - visited[x]",
"+ else:",
"+ visited[newx] = visited[x]",
"- return col",
"+ return visited",
"-for i in range(n):",
"- print((dfs(edge, col)[i]))",
"+for i in dfs(edges, visited):",
"+ print(i)"
] | false | 0.045224 | 0.041556 | 1.088266 | [
"s325533044",
"s351623580"
] |
u844005364 | p03290 | python | s505721243 | s738223701 | 1,234 | 443 | 3,316 | 3,064 | Accepted | Accepted | 64.1 | difficulties, goal = list(map(int, input().split()))
pcs = [list(map(int, input().split())) for _ in range(difficulties)]
dp = [[0] * 1102 for _ in range(difficulties + 1)]
total_problem = 0
for d, pc in enumerate(pcs, 1):
problem, complete = pc
total_problem += problem
score = {x: x*100*d for x in range(problem)}
score[problem] = problem * 100 * d +complete
for i in range(1, total_problem + 1):
for j in range(0, i + 1):
if i - j > problem:
dp[d][i] = max(dp[d][i], dp[d - 1][j])
else:
dp[d][i] = max(dp[d][i], dp[d-1][j] + score[i-j])
for i, a in enumerate(dp[difficulties]):
if a >= goal:
print(i)
exit()
| difficulties, goal = list(map(int, input().split()))
pcs = [list(map(int, input().split())) for _ in range(difficulties)]
total_problem = 0
new_dp = [0] * 1001
for d, pc in enumerate(pcs, 1):
dp = new_dp[:]
problem, complete = pc
total_problem += problem
score = {x: x*100*d for x in range(problem)}
score[problem] = problem * 100 * d +complete
for i in range(1, total_problem + 1):
for j in range(0, i + 1):
if i - j > problem:
continue
else:
new_dp[i] = max(new_dp[i], dp[j] + score[i-j])
for i, a in enumerate(new_dp):
if a >= goal:
print(i)
exit()
| 25 | 27 | 739 | 687 | difficulties, goal = list(map(int, input().split()))
pcs = [list(map(int, input().split())) for _ in range(difficulties)]
dp = [[0] * 1102 for _ in range(difficulties + 1)]
total_problem = 0
for d, pc in enumerate(pcs, 1):
problem, complete = pc
total_problem += problem
score = {x: x * 100 * d for x in range(problem)}
score[problem] = problem * 100 * d + complete
for i in range(1, total_problem + 1):
for j in range(0, i + 1):
if i - j > problem:
dp[d][i] = max(dp[d][i], dp[d - 1][j])
else:
dp[d][i] = max(dp[d][i], dp[d - 1][j] + score[i - j])
for i, a in enumerate(dp[difficulties]):
if a >= goal:
print(i)
exit()
| difficulties, goal = list(map(int, input().split()))
pcs = [list(map(int, input().split())) for _ in range(difficulties)]
total_problem = 0
new_dp = [0] * 1001
for d, pc in enumerate(pcs, 1):
dp = new_dp[:]
problem, complete = pc
total_problem += problem
score = {x: x * 100 * d for x in range(problem)}
score[problem] = problem * 100 * d + complete
for i in range(1, total_problem + 1):
for j in range(0, i + 1):
if i - j > problem:
continue
else:
new_dp[i] = max(new_dp[i], dp[j] + score[i - j])
for i, a in enumerate(new_dp):
if a >= goal:
print(i)
exit()
| false | 7.407407 | [
"-dp = [[0] * 1102 for _ in range(difficulties + 1)]",
"+new_dp = [0] * 1001",
"+ dp = new_dp[:]",
"- dp[d][i] = max(dp[d][i], dp[d - 1][j])",
"+ continue",
"- dp[d][i] = max(dp[d][i], dp[d - 1][j] + score[i - j])",
"-for i, a in enumerate(dp[difficulties]):",
"+ new_dp[i] = max(new_dp[i], dp[j] + score[i - j])",
"+for i, a in enumerate(new_dp):"
] | false | 0.05207 | 0.037191 | 1.40006 | [
"s505721243",
"s738223701"
] |
u077291787 | p03163 | python | s718467581 | s638299609 | 474 | 257 | 118,256 | 39,664 | Accepted | Accepted | 45.78 | # dpD - Knapsack 1
import sys
input = sys.stdin.readline
def main():
n, w = tuple(map(int, input().rstrip().split()))
A = tuple(tuple(map(int, input().rstrip().split())) for _ in range(n))
dp = [[0] * (w + 1) for i in range(n)]
for i in range(n):
for j in range(w + 1):
if j < A[i][0]:
dp[i][j] = dp[i - 1][j]
else:
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - A[i][0]] + A[i][1])
print((max(dp[-1])))
if __name__ == "__main__":
main() | # dpD
import sys
input = sys.stdin.readline
def main():
N, W = tuple(map(int, input().rstrip().split()))
A = tuple(tuple(map(int, input().rstrip().split())) for _ in range(N))
dp = [0] * (W + 1)
for i in range(N):
for j in range(W, A[i][0] - 1, -1):
dp[j] = max(dp[j], dp[j - A[i][0]] + A[i][1])
print((dp[-1]))
if __name__ == "__main__":
main() | 19 | 16 | 540 | 405 | # dpD - Knapsack 1
import sys
input = sys.stdin.readline
def main():
n, w = tuple(map(int, input().rstrip().split()))
A = tuple(tuple(map(int, input().rstrip().split())) for _ in range(n))
dp = [[0] * (w + 1) for i in range(n)]
for i in range(n):
for j in range(w + 1):
if j < A[i][0]:
dp[i][j] = dp[i - 1][j]
else:
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - A[i][0]] + A[i][1])
print((max(dp[-1])))
if __name__ == "__main__":
main()
| # dpD
import sys
input = sys.stdin.readline
def main():
N, W = tuple(map(int, input().rstrip().split()))
A = tuple(tuple(map(int, input().rstrip().split())) for _ in range(N))
dp = [0] * (W + 1)
for i in range(N):
for j in range(W, A[i][0] - 1, -1):
dp[j] = max(dp[j], dp[j - A[i][0]] + A[i][1])
print((dp[-1]))
if __name__ == "__main__":
main()
| false | 15.789474 | [
"-# dpD - Knapsack 1",
"+# dpD",
"- n, w = tuple(map(int, input().rstrip().split()))",
"- A = tuple(tuple(map(int, input().rstrip().split())) for _ in range(n))",
"- dp = [[0] * (w + 1) for i in range(n)]",
"- for i in range(n):",
"- for j in range(w + 1):",
"- if j < A[i][0]:",
"- dp[i][j] = dp[i - 1][j]",
"- else:",
"- dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - A[i][0]] + A[i][1])",
"- print((max(dp[-1])))",
"+ N, W = tuple(map(int, input().rstrip().split()))",
"+ A = tuple(tuple(map(int, input().rstrip().split())) for _ in range(N))",
"+ dp = [0] * (W + 1)",
"+ for i in range(N):",
"+ for j in range(W, A[i][0] - 1, -1):",
"+ dp[j] = max(dp[j], dp[j - A[i][0]] + A[i][1])",
"+ print((dp[-1]))"
] | false | 0.037612 | 0.041835 | 0.899054 | [
"s718467581",
"s638299609"
] |
u562016607 | p03295 | python | s586441244 | s393447218 | 1,986 | 454 | 23,472 | 21,424 | Accepted | Accepted | 77.14 | N,M=list(map(int, input().split()))
G=[list() for i in range(N)]
for i in range(M):
a,b=list(map(int,input().split()))
a-=1
b-=1
G[a].append(b)
G[b].append(a)
ans=0
index=-1
for i in range(1,N):
for p in G[i]:
if index<p<i:
ans+=1
index=i-1
import time
time.sleep(1.54)
print(ans)
| N,M=list(map(int, input().split()))
G=[list() for i in range(N)]
for i in range(M):
a,b=list(map(int,input().split()))
a-=1
b-=1
G[a].append(b)
G[b].append(a)
ans=0
index=-1
for i in range(1,N):
for p in G[i]:
if index<p<i:
ans+=1
index=i-1
break
print(ans)
| 18 | 17 | 342 | 330 | N, M = list(map(int, input().split()))
G = [list() for i in range(N)]
for i in range(M):
a, b = list(map(int, input().split()))
a -= 1
b -= 1
G[a].append(b)
G[b].append(a)
ans = 0
index = -1
for i in range(1, N):
for p in G[i]:
if index < p < i:
ans += 1
index = i - 1
import time
time.sleep(1.54)
print(ans)
| N, M = list(map(int, input().split()))
G = [list() for i in range(N)]
for i in range(M):
a, b = list(map(int, input().split()))
a -= 1
b -= 1
G[a].append(b)
G[b].append(a)
ans = 0
index = -1
for i in range(1, N):
for p in G[i]:
if index < p < i:
ans += 1
index = i - 1
break
print(ans)
| false | 5.555556 | [
"-import time",
"-",
"-time.sleep(1.54)",
"+ break"
] | false | 1.244056 | 0.045043 | 27.619259 | [
"s586441244",
"s393447218"
] |
u672220554 | p02683 | python | s831809013 | s226448565 | 93 | 85 | 68,752 | 68,788 | Accepted | Accepted | 8.6 | N, M, X = list(map(int, input().split()))
C = []
L = []
for i in range(N):
B = list(map(int, input().split()))
C.append(B[0])
L.append(B[1:])
res = 10 ** 9
for i in range(2 ** N):
c = 0
s = [0 for _ in range(M)]
for j in range(N):
if i >> j & 1:
c += C[j]
for k in range(M):
s[k] += L[j][k]
f = 1
for j in range(M):
if s[j] < X:
f = 0
break
if f:
res = min(res, c)
if res == 10 ** 9:
print((-1))
else:
print(res)
| N, M, X = list(map(int, input().split()))
C = []
L = []
for i in range(N):
B = list(map(int, input().split()))
C.append(B[0])
L.append(B[1:])
res = 10 ** 9
for i in range(2 ** N):
c = 0
s = [0 for _ in range(M)]
for j in range(N):
if i >> j & 1:
c += C[j]
for k in range(M):
s[k] += L[j][k]
for j in range(M):
if s[j] < X:
break
else:
res = min(res, c)
if res == 10 ** 9:
print((-1))
else:
print(res)
| 29 | 27 | 567 | 537 | N, M, X = list(map(int, input().split()))
C = []
L = []
for i in range(N):
B = list(map(int, input().split()))
C.append(B[0])
L.append(B[1:])
res = 10**9
for i in range(2**N):
c = 0
s = [0 for _ in range(M)]
for j in range(N):
if i >> j & 1:
c += C[j]
for k in range(M):
s[k] += L[j][k]
f = 1
for j in range(M):
if s[j] < X:
f = 0
break
if f:
res = min(res, c)
if res == 10**9:
print((-1))
else:
print(res)
| N, M, X = list(map(int, input().split()))
C = []
L = []
for i in range(N):
B = list(map(int, input().split()))
C.append(B[0])
L.append(B[1:])
res = 10**9
for i in range(2**N):
c = 0
s = [0 for _ in range(M)]
for j in range(N):
if i >> j & 1:
c += C[j]
for k in range(M):
s[k] += L[j][k]
for j in range(M):
if s[j] < X:
break
else:
res = min(res, c)
if res == 10**9:
print((-1))
else:
print(res)
| false | 6.896552 | [
"- f = 1",
"- f = 0",
"- if f:",
"+ else:"
] | false | 0.039113 | 0.046952 | 0.833049 | [
"s831809013",
"s226448565"
] |
u562935282 | p03078 | python | s184299527 | s031270401 | 1,884 | 571 | 208,700 | 8,692 | Accepted | Accepted | 69.69 | import sys
input = sys.stdin.readline
x, y, z, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
d = [aa + bb for aa in a[:k] for bb in b[:k]]
d.sort(reverse=True)
e = [dd + cc for dd in d[:k] for cc in c[:k]]
e.sort(reverse=True)
print(*e[:k], sep='\n')
| import sys
input = sys.stdin.readline
x, y, z, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
d = []
for ai, aa in enumerate(a, 1):
for bi, bb in enumerate(b, 1):
for ci, cc in enumerate(c, 1):
if ai * bi * ci > k:
break
# (ai,bi,ci)より合計の大きい選び方がk通り以上存在する
# (ai,bi)を含む組み合わせは、これ以上調べる必要がない
d.append(aa + bb + cc)
d.sort(reverse=True)
print(*d[:k], sep='\n')
| 20 | 26 | 431 | 624 | import sys
input = sys.stdin.readline
x, y, z, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
d = [aa + bb for aa in a[:k] for bb in b[:k]]
d.sort(reverse=True)
e = [dd + cc for dd in d[:k] for cc in c[:k]]
e.sort(reverse=True)
print(*e[:k], sep="\n")
| import sys
input = sys.stdin.readline
x, y, z, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
d = []
for ai, aa in enumerate(a, 1):
for bi, bb in enumerate(b, 1):
for ci, cc in enumerate(c, 1):
if ai * bi * ci > k:
break
# (ai,bi,ci)より合計の大きい選び方がk通り以上存在する
# (ai,bi)を含む組み合わせは、これ以上調べる必要がない
d.append(aa + bb + cc)
d.sort(reverse=True)
print(*d[:k], sep="\n")
| false | 23.076923 | [
"-d = [aa + bb for aa in a[:k] for bb in b[:k]]",
"+d = []",
"+for ai, aa in enumerate(a, 1):",
"+ for bi, bb in enumerate(b, 1):",
"+ for ci, cc in enumerate(c, 1):",
"+ if ai * bi * ci > k:",
"+ break",
"+ # (ai,bi,ci)より合計の大きい選び方がk通り以上存在する",
"+ # (ai,bi)を含む組み合わせは、これ以上調べる必要がない",
"+ d.append(aa + bb + cc)",
"-e = [dd + cc for dd in d[:k] for cc in c[:k]]",
"-e.sort(reverse=True)",
"-print(*e[:k], sep=\"\\n\")",
"+print(*d[:k], sep=\"\\n\")"
] | false | 0.066251 | 0.037574 | 1.763219 | [
"s184299527",
"s031270401"
] |
u089230684 | p02778 | python | s344887167 | s969175023 | 19 | 17 | 2,940 | 2,940 | Accepted | Accepted | 10.53 | s = list(eval(input()))
for x in s:
s[s.index(x)] = "x"
s = str(s).replace(",", "").replace("'", "").replace("[", "").replace("]", "").replace(" ","")
print(s)
| str1=eval(input())
str2=list(str1)
print(('x'*len(str2))) | 5 | 4 | 162 | 53 | s = list(eval(input()))
for x in s:
s[s.index(x)] = "x"
s = (
str(s)
.replace(",", "")
.replace("'", "")
.replace("[", "")
.replace("]", "")
.replace(" ", "")
)
print(s)
| str1 = eval(input())
str2 = list(str1)
print(("x" * len(str2)))
| false | 20 | [
"-s = list(eval(input()))",
"-for x in s:",
"- s[s.index(x)] = \"x\"",
"-s = (",
"- str(s)",
"- .replace(\",\", \"\")",
"- .replace(\"'\", \"\")",
"- .replace(\"[\", \"\")",
"- .replace(\"]\", \"\")",
"- .replace(\" \", \"\")",
"-)",
"-print(s)",
"+str1 = eval(input())",
"+str2 = list(str1)",
"+print((\"x\" * len(str2)))"
] | false | 0.038531 | 0.03951 | 0.97521 | [
"s344887167",
"s969175023"
] |
u671060652 | p03210 | python | s768835265 | s892350995 | 255 | 67 | 63,852 | 61,840 | Accepted | Accepted | 73.73 | import itertools
import math
import fractions
import functools
import copy
n = int(eval(input()))
if n ==7 or n ==5 or n == 3:
print("YES")
else: print("NO") | def main():
n = int(eval(input()))
# t, a = map(int, input().split())
# h = list(map(int, input().split()))
# s = input()
if n == 7 or n == 5 or n==3 :
print("YES")
else: print("NO")
if __name__ == '__main__':
main()
| 10 | 13 | 165 | 262 | import itertools
import math
import fractions
import functools
import copy
n = int(eval(input()))
if n == 7 or n == 5 or n == 3:
print("YES")
else:
print("NO")
| def main():
n = int(eval(input()))
# t, a = map(int, input().split())
# h = list(map(int, input().split()))
# s = input()
if n == 7 or n == 5 or n == 3:
print("YES")
else:
print("NO")
if __name__ == "__main__":
main()
| false | 23.076923 | [
"-import itertools",
"-import math",
"-import fractions",
"-import functools",
"-import copy",
"+def main():",
"+ n = int(eval(input()))",
"+ # t, a = map(int, input().split())",
"+ # h = list(map(int, input().split()))",
"+ # s = input()",
"+ if n == 7 or n == 5 or n == 3:",
"+ print(\"YES\")",
"+ else:",
"+ print(\"NO\")",
"-n = int(eval(input()))",
"-if n == 7 or n == 5 or n == 3:",
"- print(\"YES\")",
"-else:",
"- print(\"NO\")",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.045769 | 0.045317 | 1.009962 | [
"s768835265",
"s892350995"
] |
u695154284 | p00033 | python | s136147104 | s079878070 | 130 | 50 | 7,544 | 7,608 | Accepted | Accepted | 61.54 | N = int(eval(input()))
for testCase in range(N):
A = list(map(int, input().split()))
ok = False
for i in range(2 ** 10):
x = []
y = []
for j in range(10):
if i & (1 << j):
x.append(A[j])
else:
y.append(A[j])
if x == sorted(x) and y == sorted(y):
ok = True
if ok:
print('YES')
else:
print('NO') | def dfs(i, b, c):
if i == 11:
return (b == sorted(b) and c == sorted(c))
if dfs(i + 1, b + [balls[i - 1]], c):
return True
if dfs(i + 1, b, c + [balls[i - 1]]):
return True
return False
if __name__ == '__main__':
N = int(eval(input()))
for i in range(N):
balls = list(map(int, input().split()))
if dfs(1, [], []):
print("YES")
else:
print("NO") | 19 | 21 | 442 | 459 | N = int(eval(input()))
for testCase in range(N):
A = list(map(int, input().split()))
ok = False
for i in range(2**10):
x = []
y = []
for j in range(10):
if i & (1 << j):
x.append(A[j])
else:
y.append(A[j])
if x == sorted(x) and y == sorted(y):
ok = True
if ok:
print("YES")
else:
print("NO")
| def dfs(i, b, c):
if i == 11:
return b == sorted(b) and c == sorted(c)
if dfs(i + 1, b + [balls[i - 1]], c):
return True
if dfs(i + 1, b, c + [balls[i - 1]]):
return True
return False
if __name__ == "__main__":
N = int(eval(input()))
for i in range(N):
balls = list(map(int, input().split()))
if dfs(1, [], []):
print("YES")
else:
print("NO")
| false | 9.52381 | [
"-N = int(eval(input()))",
"-for testCase in range(N):",
"- A = list(map(int, input().split()))",
"- ok = False",
"- for i in range(2**10):",
"- x = []",
"- y = []",
"- for j in range(10):",
"- if i & (1 << j):",
"- x.append(A[j])",
"- else:",
"- y.append(A[j])",
"- if x == sorted(x) and y == sorted(y):",
"- ok = True",
"- if ok:",
"- print(\"YES\")",
"- else:",
"- print(\"NO\")",
"+def dfs(i, b, c):",
"+ if i == 11:",
"+ return b == sorted(b) and c == sorted(c)",
"+ if dfs(i + 1, b + [balls[i - 1]], c):",
"+ return True",
"+ if dfs(i + 1, b, c + [balls[i - 1]]):",
"+ return True",
"+ return False",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ N = int(eval(input()))",
"+ for i in range(N):",
"+ balls = list(map(int, input().split()))",
"+ if dfs(1, [], []):",
"+ print(\"YES\")",
"+ else:",
"+ print(\"NO\")"
] | false | 0.167271 | 0.071743 | 2.331538 | [
"s136147104",
"s079878070"
] |
u119982147 | p03545 | python | s038377432 | s202246878 | 19 | 17 | 3,188 | 3,060 | Accepted | Accepted | 10.53 | N = list(eval(input()))
if int(N[0]) + int(N[1]) + int(N[2]) + int(N[3]) == 7:
print((N[0]+"+"+N[1]+"+"+N[2]+"+"+N[3]+"=7"))
elif int(N[0]) - int(N[1]) + int(N[2]) + int(N[3]) == 7:
print((N[0]+"-"+N[1]+"+"+N[2]+"+"+N[3]+"=7"))
elif int(N[0]) + int(N[1]) - int(N[2]) + int(N[3]) == 7:
print((N[0]+"+"+N[1]+"-"+N[2]+"+"+N[3]+"=7"))
elif int(N[0]) + int(N[1]) + int(N[2]) - int(N[3]) == 7:
print((N[0]+"+"+N[1]+"+"+N[2]+"-"+N[3]+"=7"))
elif int(N[0]) - int(N[1]) - int(N[2]) + int(N[3]) == 7:
print((N[0]+"-"+N[1]+"-"+N[2]+"+"+N[3]+"=7"))
elif int(N[0]) - int(N[1]) + int(N[2]) - int(N[3]) == 7:
print((N[0]+"-"+N[1]+"+"+N[2]+"-"+N[3]+"=7"))
elif int(N[0]) + int(N[1]) - int(N[2]) - int(N[3]) == 7:
print((N[0]+"+"+N[1]+"-"+N[2]+"-"+N[3]+"=7"))
elif int(N[0]) - int(N[1]) - int(N[2]) - int(N[3]) == 7:
print((N[0]+"-"+N[1]+"-"+N[2]+"-"+N[3]+"=7"))
else:
pass | s = str(eval(input()))
ans = 0
for i in range(1 << (len(s)-1)):
si = s[0]
for j in range(len(s)-1):
if i & (1 << j):
si += "+"+s[j+1]
else:
si += "-"+s[j+1]
if eval(si) == 7:
break
print((si+"=7")) | 20 | 13 | 890 | 262 | N = list(eval(input()))
if int(N[0]) + int(N[1]) + int(N[2]) + int(N[3]) == 7:
print((N[0] + "+" + N[1] + "+" + N[2] + "+" + N[3] + "=7"))
elif int(N[0]) - int(N[1]) + int(N[2]) + int(N[3]) == 7:
print((N[0] + "-" + N[1] + "+" + N[2] + "+" + N[3] + "=7"))
elif int(N[0]) + int(N[1]) - int(N[2]) + int(N[3]) == 7:
print((N[0] + "+" + N[1] + "-" + N[2] + "+" + N[3] + "=7"))
elif int(N[0]) + int(N[1]) + int(N[2]) - int(N[3]) == 7:
print((N[0] + "+" + N[1] + "+" + N[2] + "-" + N[3] + "=7"))
elif int(N[0]) - int(N[1]) - int(N[2]) + int(N[3]) == 7:
print((N[0] + "-" + N[1] + "-" + N[2] + "+" + N[3] + "=7"))
elif int(N[0]) - int(N[1]) + int(N[2]) - int(N[3]) == 7:
print((N[0] + "-" + N[1] + "+" + N[2] + "-" + N[3] + "=7"))
elif int(N[0]) + int(N[1]) - int(N[2]) - int(N[3]) == 7:
print((N[0] + "+" + N[1] + "-" + N[2] + "-" + N[3] + "=7"))
elif int(N[0]) - int(N[1]) - int(N[2]) - int(N[3]) == 7:
print((N[0] + "-" + N[1] + "-" + N[2] + "-" + N[3] + "=7"))
else:
pass
| s = str(eval(input()))
ans = 0
for i in range(1 << (len(s) - 1)):
si = s[0]
for j in range(len(s) - 1):
if i & (1 << j):
si += "+" + s[j + 1]
else:
si += "-" + s[j + 1]
if eval(si) == 7:
break
print((si + "=7"))
| false | 35 | [
"-N = list(eval(input()))",
"-if int(N[0]) + int(N[1]) + int(N[2]) + int(N[3]) == 7:",
"- print((N[0] + \"+\" + N[1] + \"+\" + N[2] + \"+\" + N[3] + \"=7\"))",
"-elif int(N[0]) - int(N[1]) + int(N[2]) + int(N[3]) == 7:",
"- print((N[0] + \"-\" + N[1] + \"+\" + N[2] + \"+\" + N[3] + \"=7\"))",
"-elif int(N[0]) + int(N[1]) - int(N[2]) + int(N[3]) == 7:",
"- print((N[0] + \"+\" + N[1] + \"-\" + N[2] + \"+\" + N[3] + \"=7\"))",
"-elif int(N[0]) + int(N[1]) + int(N[2]) - int(N[3]) == 7:",
"- print((N[0] + \"+\" + N[1] + \"+\" + N[2] + \"-\" + N[3] + \"=7\"))",
"-elif int(N[0]) - int(N[1]) - int(N[2]) + int(N[3]) == 7:",
"- print((N[0] + \"-\" + N[1] + \"-\" + N[2] + \"+\" + N[3] + \"=7\"))",
"-elif int(N[0]) - int(N[1]) + int(N[2]) - int(N[3]) == 7:",
"- print((N[0] + \"-\" + N[1] + \"+\" + N[2] + \"-\" + N[3] + \"=7\"))",
"-elif int(N[0]) + int(N[1]) - int(N[2]) - int(N[3]) == 7:",
"- print((N[0] + \"+\" + N[1] + \"-\" + N[2] + \"-\" + N[3] + \"=7\"))",
"-elif int(N[0]) - int(N[1]) - int(N[2]) - int(N[3]) == 7:",
"- print((N[0] + \"-\" + N[1] + \"-\" + N[2] + \"-\" + N[3] + \"=7\"))",
"-else:",
"- pass",
"+s = str(eval(input()))",
"+ans = 0",
"+for i in range(1 << (len(s) - 1)):",
"+ si = s[0]",
"+ for j in range(len(s) - 1):",
"+ if i & (1 << j):",
"+ si += \"+\" + s[j + 1]",
"+ else:",
"+ si += \"-\" + s[j + 1]",
"+ if eval(si) == 7:",
"+ break",
"+print((si + \"=7\"))"
] | false | 0.049169 | 0.048958 | 1.004304 | [
"s038377432",
"s202246878"
] |
u498487134 | p03166 | python | s970326323 | s415950432 | 652 | 497 | 136,028 | 59,008 | Accepted | Accepted | 23.77 | import sys
sys.setrecursionlimit(10**5+5)
input = sys.stdin.readline
N,M=list(map(int,input().split()))
adj=[[] for _ in range(N)]
for i in range(M):
x,y=list(map(int,input().split()))
x-=1
y-=1
adj[x].append(y)
dp=[-1]*N#i番目絡みた最長経路
for i in range(N):
if len(adj[i])==0:
dp[i]=0
def rec(ii):
new=0
for to in adj[ii]:
if dp[to]!=-1:
new=dp[to]
else:
new=rec(to)
dp[ii]=max(new+1,dp[ii])
return dp[ii]
for i in range(N):
rec(i)
print((max(dp))) | import sys
sys.setrecursionlimit(10**5+5)
input = sys.stdin.readline
N,M=list(map(int,input().split()))
adj=[[] for _ in range(N)]
for i in range(M):
x,y=list(map(int,input().split()))
x-=1
y-=1
adj[x].append(y)
dp=[0]*N#i番目絡みた最長経路
def rec(ii):
new=0
if len(adj[ii])==0:
return 0
for to in adj[ii]:
if dp[to]!=0:
new=dp[to]
else:
new=rec(to)
dp[ii]=max(new+1,dp[ii])
return dp[ii]
for i in range(N):
rec(i)
print((max(dp))) | 32 | 31 | 573 | 553 | import sys
sys.setrecursionlimit(10**5 + 5)
input = sys.stdin.readline
N, M = list(map(int, input().split()))
adj = [[] for _ in range(N)]
for i in range(M):
x, y = list(map(int, input().split()))
x -= 1
y -= 1
adj[x].append(y)
dp = [-1] * N # i番目絡みた最長経路
for i in range(N):
if len(adj[i]) == 0:
dp[i] = 0
def rec(ii):
new = 0
for to in adj[ii]:
if dp[to] != -1:
new = dp[to]
else:
new = rec(to)
dp[ii] = max(new + 1, dp[ii])
return dp[ii]
for i in range(N):
rec(i)
print((max(dp)))
| import sys
sys.setrecursionlimit(10**5 + 5)
input = sys.stdin.readline
N, M = list(map(int, input().split()))
adj = [[] for _ in range(N)]
for i in range(M):
x, y = list(map(int, input().split()))
x -= 1
y -= 1
adj[x].append(y)
dp = [0] * N # i番目絡みた最長経路
def rec(ii):
new = 0
if len(adj[ii]) == 0:
return 0
for to in adj[ii]:
if dp[to] != 0:
new = dp[to]
else:
new = rec(to)
dp[ii] = max(new + 1, dp[ii])
return dp[ii]
for i in range(N):
rec(i)
print((max(dp)))
| false | 3.125 | [
"-dp = [-1] * N # i番目絡みた最長経路",
"-for i in range(N):",
"- if len(adj[i]) == 0:",
"- dp[i] = 0",
"+dp = [0] * N # i番目絡みた最長経路",
"+ if len(adj[ii]) == 0:",
"+ return 0",
"- if dp[to] != -1:",
"+ if dp[to] != 0:"
] | false | 0.037449 | 0.036144 | 1.036113 | [
"s970326323",
"s415950432"
] |
u492749916 | p02582 | python | s691259936 | s875847294 | 31 | 24 | 9,036 | 9,044 | Accepted | Accepted | 22.58 | S = str(eval(input()))
if S =="RRR":
ans = 3
elif S =="SRR" or S == "RRS":
ans = 2
else:
S = list(S)
if "R" in S:
ans = 1
else:
ans = 0
print(ans) | S= str(eval(input()))
if "RRR" in S:
print("3")
elif "RR" in S:
print("2")
elif "R" in S:
print("1")
else:
print("0") | 13 | 10 | 171 | 129 | S = str(eval(input()))
if S == "RRR":
ans = 3
elif S == "SRR" or S == "RRS":
ans = 2
else:
S = list(S)
if "R" in S:
ans = 1
else:
ans = 0
print(ans)
| S = str(eval(input()))
if "RRR" in S:
print("3")
elif "RR" in S:
print("2")
elif "R" in S:
print("1")
else:
print("0")
| false | 23.076923 | [
"-if S == \"RRR\":",
"- ans = 3",
"-elif S == \"SRR\" or S == \"RRS\":",
"- ans = 2",
"+if \"RRR\" in S:",
"+ print(\"3\")",
"+elif \"RR\" in S:",
"+ print(\"2\")",
"+elif \"R\" in S:",
"+ print(\"1\")",
"- S = list(S)",
"- if \"R\" in S:",
"- ans = 1",
"- else:",
"- ans = 0",
"-print(ans)",
"+ print(\"0\")"
] | false | 0.036618 | 0.064009 | 0.572082 | [
"s691259936",
"s875847294"
] |
u089230684 | p02879 | python | s216287895 | s142966622 | 339 | 30 | 76,116 | 9,100 | Accepted | Accepted | 91.15 | s = input()
s = s.split(' ')
a, b = int(s[0]), int(s[1])
if 1 <= a <= 9 and 1 <= b <= 9:
print(a*b)
else:
print(-1)
| A,B=list(map(int,input().split()))
if A <=9 and B<=9 :
print((A*B))
else:
print((-1)) | 9 | 5 | 136 | 83 | s = input()
s = s.split(" ")
a, b = int(s[0]), int(s[1])
if 1 <= a <= 9 and 1 <= b <= 9:
print(a * b)
else:
print(-1)
| A, B = list(map(int, input().split()))
if A <= 9 and B <= 9:
print((A * B))
else:
print((-1))
| false | 44.444444 | [
"-s = input()",
"-s = s.split(\" \")",
"-a, b = int(s[0]), int(s[1])",
"-if 1 <= a <= 9 and 1 <= b <= 9:",
"- print(a * b)",
"+A, B = list(map(int, input().split()))",
"+if A <= 9 and B <= 9:",
"+ print((A * B))",
"- print(-1)",
"+ print((-1))"
] | false | 0.108306 | 0.034875 | 3.105548 | [
"s216287895",
"s142966622"
] |
u282228874 | p03061 | python | s121843002 | s951710844 | 1,503 | 213 | 14,196 | 16,152 | Accepted | Accepted | 85.83 | import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float('inf')
MOD = 10**9+7
n = int(eval(input()))
A = list(map(int,input().split()))
ass = set()
def div(x):
for i in range(1,int(x**0.5)+1):
if x%i == 0:
ass.add(i)
ass.add(x//i)
return ass
a0 = A[0]
a1 = A[1]
div(a0)
div(a1)
ans = []
for i in ass:
cnt = 0
for a in A:
if a%i == 0:
cnt += 1
if cnt >= n-1:
ans.append(i)
print((max(ans))) | from fractions import gcd
N = int(eval(input()))
A = list(map(int,input().split()))
Gleft = [A[0]]
Gright = [A[-1]]
for i in range(1,N):
Gleft.append(gcd(Gleft[-1],A[i]))
Gright.append(gcd(Gright[-1],A[-1-i]))
Gright = Gright[::-1]
res = max(Gright[1],Gleft[-2])
for i in range(1,N-1):
res = max(res,gcd(Gleft[i-1],Gright[i+1]))
print(res) | 28 | 13 | 511 | 357 | import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")
MOD = 10**9 + 7
n = int(eval(input()))
A = list(map(int, input().split()))
ass = set()
def div(x):
for i in range(1, int(x**0.5) + 1):
if x % i == 0:
ass.add(i)
ass.add(x // i)
return ass
a0 = A[0]
a1 = A[1]
div(a0)
div(a1)
ans = []
for i in ass:
cnt = 0
for a in A:
if a % i == 0:
cnt += 1
if cnt >= n - 1:
ans.append(i)
print((max(ans)))
| from fractions import gcd
N = int(eval(input()))
A = list(map(int, input().split()))
Gleft = [A[0]]
Gright = [A[-1]]
for i in range(1, N):
Gleft.append(gcd(Gleft[-1], A[i]))
Gright.append(gcd(Gright[-1], A[-1 - i]))
Gright = Gright[::-1]
res = max(Gright[1], Gleft[-2])
for i in range(1, N - 1):
res = max(res, gcd(Gleft[i - 1], Gright[i + 1]))
print(res)
| false | 53.571429 | [
"-import sys",
"+from fractions import gcd",
"-sys.setrecursionlimit(10**7)",
"-input = sys.stdin.readline",
"-INF = float(\"inf\")",
"-MOD = 10**9 + 7",
"-n = int(eval(input()))",
"+N = int(eval(input()))",
"-ass = set()",
"-",
"-",
"-def div(x):",
"- for i in range(1, int(x**0.5) + 1):",
"- if x % i == 0:",
"- ass.add(i)",
"- ass.add(x // i)",
"- return ass",
"-",
"-",
"-a0 = A[0]",
"-a1 = A[1]",
"-div(a0)",
"-div(a1)",
"-ans = []",
"-for i in ass:",
"- cnt = 0",
"- for a in A:",
"- if a % i == 0:",
"- cnt += 1",
"- if cnt >= n - 1:",
"- ans.append(i)",
"-print((max(ans)))",
"+Gleft = [A[0]]",
"+Gright = [A[-1]]",
"+for i in range(1, N):",
"+ Gleft.append(gcd(Gleft[-1], A[i]))",
"+ Gright.append(gcd(Gright[-1], A[-1 - i]))",
"+Gright = Gright[::-1]",
"+res = max(Gright[1], Gleft[-2])",
"+for i in range(1, N - 1):",
"+ res = max(res, gcd(Gleft[i - 1], Gright[i + 1]))",
"+print(res)"
] | false | 0.037654 | 0.054999 | 0.684633 | [
"s121843002",
"s951710844"
] |
u059210959 | p02600 | python | s035641910 | s895729940 | 48 | 42 | 10,924 | 10,900 | Accepted | Accepted | 12.5 | #!/usr/bin/env python3
# encoding:utf-8
import copy
import random
import bisect #bisect_left これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections
from decimal import Decimal # 10進数で考慮できる
mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000
d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))
X = int(eval(input()))
if 599 >= X:
ans = 8
elif 600 <= X <= 799:
ans = 7
elif 800 <= X <= 999:
ans = 6
elif 1000 <= X <= 1199:
ans = 5
elif 1200 <= X <= 1399:
ans = 4
elif 1400 <= X <= 1599:
ans = 3
elif 1600 <= X <= 1799:
ans = 2
else:
ans = 1
print((str(ans))) | #!/usr/bin/env python3
# encoding:utf-8
import copy
import random
import bisect #bisect_left これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections
from decimal import Decimal # 10進数で考慮できる
mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000
d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))
# X = int(input())
# if 599 >= X:
# ans = 8
# elif 600 <= X <= 799:
# ans = 7
# elif 800 <= X <= 999:
# ans = 6
# elif 1000 <= X <= 1199:
# ans = 5
# elif 1200 <= X <= 1399:
# ans = 4
# elif 1400 <= X <= 1599:
# ans = 3
# elif 1600 <= X <= 1799:
# ans = 2
# else:
# ans = 1
# print(str(ans))
X = int(eval(input()))
print((8 - (X - 400) // 200)) | 35 | 38 | 696 | 781 | #!/usr/bin/env python3
# encoding:utf-8
import copy
import random
import bisect # bisect_left これで二部探索の大小検索が行える
import fractions # 最小公倍数などはこっち
import math
import sys
import collections
from decimal import Decimal # 10進数で考慮できる
mod = 10**9 + 7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000
d = collections.deque()
def LI():
return list(map(int, sys.stdin.readline().split()))
X = int(eval(input()))
if 599 >= X:
ans = 8
elif 600 <= X <= 799:
ans = 7
elif 800 <= X <= 999:
ans = 6
elif 1000 <= X <= 1199:
ans = 5
elif 1200 <= X <= 1399:
ans = 4
elif 1400 <= X <= 1599:
ans = 3
elif 1600 <= X <= 1799:
ans = 2
else:
ans = 1
print((str(ans)))
| #!/usr/bin/env python3
# encoding:utf-8
import copy
import random
import bisect # bisect_left これで二部探索の大小検索が行える
import fractions # 最小公倍数などはこっち
import math
import sys
import collections
from decimal import Decimal # 10進数で考慮できる
mod = 10**9 + 7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000
d = collections.deque()
def LI():
return list(map(int, sys.stdin.readline().split()))
# X = int(input())
# if 599 >= X:
# ans = 8
# elif 600 <= X <= 799:
# ans = 7
# elif 800 <= X <= 999:
# ans = 6
# elif 1000 <= X <= 1199:
# ans = 5
# elif 1200 <= X <= 1399:
# ans = 4
# elif 1400 <= X <= 1599:
# ans = 3
# elif 1600 <= X <= 1799:
# ans = 2
# else:
# ans = 1
# print(str(ans))
X = int(eval(input()))
print((8 - (X - 400) // 200))
| false | 7.894737 | [
"+# X = int(input())",
"+# if 599 >= X:",
"+# ans = 8",
"+# elif 600 <= X <= 799:",
"+# ans = 7",
"+# elif 800 <= X <= 999:",
"+# ans = 6",
"+# elif 1000 <= X <= 1199:",
"+# ans = 5",
"+# elif 1200 <= X <= 1399:",
"+# ans = 4",
"+# elif 1400 <= X <= 1599:",
"+# ans = 3",
"+# elif 1600 <= X <= 1799:",
"+# ans = 2",
"+# else:",
"+# ans = 1",
"+# print(str(ans))",
"-if 599 >= X:",
"- ans = 8",
"-elif 600 <= X <= 799:",
"- ans = 7",
"-elif 800 <= X <= 999:",
"- ans = 6",
"-elif 1000 <= X <= 1199:",
"- ans = 5",
"-elif 1200 <= X <= 1399:",
"- ans = 4",
"-elif 1400 <= X <= 1599:",
"- ans = 3",
"-elif 1600 <= X <= 1799:",
"- ans = 2",
"-else:",
"- ans = 1",
"-print((str(ans)))",
"+print((8 - (X - 400) // 200))"
] | false | 0.087708 | 0.096934 | 0.904822 | [
"s035641910",
"s895729940"
] |
u129749062 | p02695 | python | s474239262 | s544391668 | 1,825 | 1,363 | 9,196 | 74,164 | Accepted | Accepted | 25.32 | import itertools
N, M, Q = list(map(int, input().split()))
abcd = [list(map(int, input().split())) for i in range(Q)]
ans = 0
for A in itertools.combinations_with_replacement(list(range(1, M+1)), N):
score = 0
for i in range(Q):
a = abcd[i][0]
b = abcd[i][1]
c = abcd[i][2]
d = abcd[i][3]
if A[b-1]-A[a-1] == c:
score += d
ans = max(ans,score)
print(ans)
| import itertools
N, M, Q = list(map(int, input().split()))
abcd = [list(map(int, input().split())) for i in range(Q)]
total = []
for A in itertools.combinations_with_replacement(list(range(1, M+1)), N):
score = 0
for a,b,c,d in abcd:
if A[b-1]-A[a-1] == c:
score += d
total.append(score)
print((max(total)))
| 15 | 11 | 389 | 322 | import itertools
N, M, Q = list(map(int, input().split()))
abcd = [list(map(int, input().split())) for i in range(Q)]
ans = 0
for A in itertools.combinations_with_replacement(list(range(1, M + 1)), N):
score = 0
for i in range(Q):
a = abcd[i][0]
b = abcd[i][1]
c = abcd[i][2]
d = abcd[i][3]
if A[b - 1] - A[a - 1] == c:
score += d
ans = max(ans, score)
print(ans)
| import itertools
N, M, Q = list(map(int, input().split()))
abcd = [list(map(int, input().split())) for i in range(Q)]
total = []
for A in itertools.combinations_with_replacement(list(range(1, M + 1)), N):
score = 0
for a, b, c, d in abcd:
if A[b - 1] - A[a - 1] == c:
score += d
total.append(score)
print((max(total)))
| false | 26.666667 | [
"-ans = 0",
"+total = []",
"- for i in range(Q):",
"- a = abcd[i][0]",
"- b = abcd[i][1]",
"- c = abcd[i][2]",
"- d = abcd[i][3]",
"+ for a, b, c, d in abcd:",
"- ans = max(ans, score)",
"-print(ans)",
"+ total.append(score)",
"+print((max(total)))"
] | false | 0.083315 | 0.049791 | 1.673272 | [
"s474239262",
"s544391668"
] |
u912237403 | p00067 | python | s760017320 | s513991938 | 20 | 10 | 4,280 | 4,300 | Accepted | Accepted | 50 | import sys
A=list(range(12))
m=[[0 for i in A] for j in A]
def f(y,x,d):
P=[]
x+=d[0]
y+=d[1]
if 0<=x<12 and 0<=y<12 and m[y][x]==1:
m[y][x]=c
P=[[y,x]]
return P
def v1(buf):
global c
while buf!=[]:
y,x=buf.pop()
m[y][x]=c
for e in [(-1,0),(1,0),(0,-1),(0,1)]:buf+=f(y,x,e)
c+=1
return
def solve():
global c
c=2
for i in A:
while m[i].count(1)>0:v1([[i,m[i].index(1)]])
print(c-2)
return 0
y=0
for s in sys.stdin:
if y<12:
m[y]=list(map(int,list(s[:-1])))
y+=1
else:y=solve()
solve() | import sys
A=list(range(14))
m=[[0 for i in A] for j in A]
def f(y,x):
if m[y][x]==1:
m[y][x]=0
f(y,x+1)
f(y,x-1)
f(y+1,x)
f(y-1,x)
return
def solve():
c=2
for i in A:
while m[i].count(1)>0:
f(i,m[i].index(1))
c+=1
print(c-2)
return 0
y=0
for s in sys.stdin:
if y<12:
m[y+1]=[0]+list(map(int,list(s[:-1])))+[0]
y+=1
else:y=solve()
solve() | 33 | 26 | 630 | 470 | import sys
A = list(range(12))
m = [[0 for i in A] for j in A]
def f(y, x, d):
P = []
x += d[0]
y += d[1]
if 0 <= x < 12 and 0 <= y < 12 and m[y][x] == 1:
m[y][x] = c
P = [[y, x]]
return P
def v1(buf):
global c
while buf != []:
y, x = buf.pop()
m[y][x] = c
for e in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
buf += f(y, x, e)
c += 1
return
def solve():
global c
c = 2
for i in A:
while m[i].count(1) > 0:
v1([[i, m[i].index(1)]])
print(c - 2)
return 0
y = 0
for s in sys.stdin:
if y < 12:
m[y] = list(map(int, list(s[:-1])))
y += 1
else:
y = solve()
solve()
| import sys
A = list(range(14))
m = [[0 for i in A] for j in A]
def f(y, x):
if m[y][x] == 1:
m[y][x] = 0
f(y, x + 1)
f(y, x - 1)
f(y + 1, x)
f(y - 1, x)
return
def solve():
c = 2
for i in A:
while m[i].count(1) > 0:
f(i, m[i].index(1))
c += 1
print(c - 2)
return 0
y = 0
for s in sys.stdin:
if y < 12:
m[y + 1] = [0] + list(map(int, list(s[:-1]))) + [0]
y += 1
else:
y = solve()
solve()
| false | 21.212121 | [
"-A = list(range(12))",
"+A = list(range(14))",
"-def f(y, x, d):",
"- P = []",
"- x += d[0]",
"- y += d[1]",
"- if 0 <= x < 12 and 0 <= y < 12 and m[y][x] == 1:",
"- m[y][x] = c",
"- P = [[y, x]]",
"- return P",
"-",
"-",
"-def v1(buf):",
"- global c",
"- while buf != []:",
"- y, x = buf.pop()",
"- m[y][x] = c",
"- for e in [(-1, 0), (1, 0), (0, -1), (0, 1)]:",
"- buf += f(y, x, e)",
"- c += 1",
"+def f(y, x):",
"+ if m[y][x] == 1:",
"+ m[y][x] = 0",
"+ f(y, x + 1)",
"+ f(y, x - 1)",
"+ f(y + 1, x)",
"+ f(y - 1, x)",
"- global c",
"- v1([[i, m[i].index(1)]])",
"+ f(i, m[i].index(1))",
"+ c += 1",
"- m[y] = list(map(int, list(s[:-1])))",
"+ m[y + 1] = [0] + list(map(int, list(s[:-1]))) + [0]"
] | false | 0.007917 | 0.039375 | 0.201057 | [
"s760017320",
"s513991938"
] |
u018679195 | p03481 | python | s759103361 | s399308922 | 21 | 18 | 3,188 | 2,940 | Accepted | Accepted | 14.29 | import re
c=eval(input())
clist=re.findall("\d+",c)
a=int(clist[0])
b=int(clist[1])
for i in range(1,b+1):
if a*(2**i)<=b:
continue
else:
print(i)
break | x, y = list(map(int, input().split()))
cnt = 0;
while x <= y:
cnt += 1
x *= 2
print(cnt) | 12 | 6 | 190 | 95 | import re
c = eval(input())
clist = re.findall("\d+", c)
a = int(clist[0])
b = int(clist[1])
for i in range(1, b + 1):
if a * (2**i) <= b:
continue
else:
print(i)
break
| x, y = list(map(int, input().split()))
cnt = 0
while x <= y:
cnt += 1
x *= 2
print(cnt)
| false | 50 | [
"-import re",
"-",
"-c = eval(input())",
"-clist = re.findall(\"\\d+\", c)",
"-a = int(clist[0])",
"-b = int(clist[1])",
"-for i in range(1, b + 1):",
"- if a * (2**i) <= b:",
"- continue",
"- else:",
"- print(i)",
"- break",
"+x, y = list(map(int, input().split()))",
"+cnt = 0",
"+while x <= y:",
"+ cnt += 1",
"+ x *= 2",
"+print(cnt)"
] | false | 0.054473 | 0.045464 | 1.198155 | [
"s759103361",
"s399308922"
] |
u094191970 | p02678 | python | s840906965 | s865097501 | 538 | 479 | 34,732 | 34,892 | Accepted | Accepted | 10.97 | from collections import deque
from sys import stdin
nii=lambda:list(map(int,stdin.readline().split()))
n,m=nii()
tree=[[] for i in range(n)]
for i in range(m):
a,b=nii()
a-=1
b-=1
tree[a].append(b)
tree[b].append(a)
ans=[-1 for i in range(n)]
ans[0]=0
dq=deque()
dq.append(0)
while dq:
x=dq.popleft()
for i in tree[x]:
if ans[i]==-1:
ans[i]=x
dq.append(i)
print('Yes')
for i in ans[1:]:
print((i+1)) | from sys import stdin
nii=lambda:list(map(int,stdin.readline().split()))
lnii=lambda:list(map(int,stdin.readline().split()))
from collections import deque
n,m=nii()
tree=[[] for i in range(n)]
for i in range(m):
a,b=nii()
a-=1
b-=1
tree[a].append(b)
tree[b].append(a)
ans=[-1 for i in range(n)]
ans[0]=1
que=deque()
que.append(0)
while que:
x=que.popleft()
for i in tree[x]:
if ans[i]==-1:
ans[i]=x
que.append(i)
if -1 in ans:
print('No')
else:
print('Yes')
for i in ans[1:]:
print((i+1)) | 29 | 34 | 456 | 559 | from collections import deque
from sys import stdin
nii = lambda: list(map(int, stdin.readline().split()))
n, m = nii()
tree = [[] for i in range(n)]
for i in range(m):
a, b = nii()
a -= 1
b -= 1
tree[a].append(b)
tree[b].append(a)
ans = [-1 for i in range(n)]
ans[0] = 0
dq = deque()
dq.append(0)
while dq:
x = dq.popleft()
for i in tree[x]:
if ans[i] == -1:
ans[i] = x
dq.append(i)
print("Yes")
for i in ans[1:]:
print((i + 1))
| from sys import stdin
nii = lambda: list(map(int, stdin.readline().split()))
lnii = lambda: list(map(int, stdin.readline().split()))
from collections import deque
n, m = nii()
tree = [[] for i in range(n)]
for i in range(m):
a, b = nii()
a -= 1
b -= 1
tree[a].append(b)
tree[b].append(a)
ans = [-1 for i in range(n)]
ans[0] = 1
que = deque()
que.append(0)
while que:
x = que.popleft()
for i in tree[x]:
if ans[i] == -1:
ans[i] = x
que.append(i)
if -1 in ans:
print("No")
else:
print("Yes")
for i in ans[1:]:
print((i + 1))
| false | 14.705882 | [
"-from collections import deque",
"+lnii = lambda: list(map(int, stdin.readline().split()))",
"+from collections import deque",
"+",
"-ans[0] = 0",
"-dq = deque()",
"-dq.append(0)",
"-while dq:",
"- x = dq.popleft()",
"+ans[0] = 1",
"+que = deque()",
"+que.append(0)",
"+while que:",
"+ x = que.popleft()",
"- dq.append(i)",
"-print(\"Yes\")",
"-for i in ans[1:]:",
"- print((i + 1))",
"+ que.append(i)",
"+if -1 in ans:",
"+ print(\"No\")",
"+else:",
"+ print(\"Yes\")",
"+ for i in ans[1:]:",
"+ print((i + 1))"
] | false | 0.037682 | 0.044166 | 0.853185 | [
"s840906965",
"s865097501"
] |
u562935282 | p03364 | python | s827262677 | s785119947 | 1,594 | 434 | 138,152 | 40,816 | Accepted | Accepted | 72.77 | def is_good_grid():
for r in range(n):
for c in range(r):
if t[r][c] != t[c][r]:
return False
return True
n = int(eval(input()))
s = tuple(eval(input()) for _ in range(n))
# (0,0)==(1,1)==...==(n-1,n-1)
# colのオフセットだけ変化させる
# それぞれのループで、n個の状態(0,k)==(1,k+1)==...を扱う
ans = 0
for k in range(n):
t = [[''] * n for _ in range(n)]
for r in range(n):
for c in range(n):
t[r][c] = s[r][(c + k) % n]
if is_good_grid():
ans += n
print(ans)
| def is_good_grid(sft):
for r in range(n):
r_ = (r - sft) % n # 減算に直した
for c in range(r):
c_ = (c - sft) % n # 減算に直した
if s[r][c_] != s[c][r_]:
# kマス列シフトした後の(r,c)と(c,r)の一致を見るには、
# (r,c)と(c,r)それぞれの列シフト前、つまり列-sftの座標を見る必要がある
# r_を用意せず、c_だけで済むと勘違いした
return False
return True
n = int(eval(input()))
s = tuple(eval(input()) for _ in range(n))
# (0,0)==(1,1)==...==(n-1,n-1)
# colのオフセットだけ変化させる
# それぞれのループで、n個の状態(0,k)==(1,k+1)==...を扱う
ans = 0
for k in range(n):
if is_good_grid(k):
ans += n
print(ans)
| 24 | 25 | 526 | 634 | def is_good_grid():
for r in range(n):
for c in range(r):
if t[r][c] != t[c][r]:
return False
return True
n = int(eval(input()))
s = tuple(eval(input()) for _ in range(n))
# (0,0)==(1,1)==...==(n-1,n-1)
# colのオフセットだけ変化させる
# それぞれのループで、n個の状態(0,k)==(1,k+1)==...を扱う
ans = 0
for k in range(n):
t = [[""] * n for _ in range(n)]
for r in range(n):
for c in range(n):
t[r][c] = s[r][(c + k) % n]
if is_good_grid():
ans += n
print(ans)
| def is_good_grid(sft):
for r in range(n):
r_ = (r - sft) % n # 減算に直した
for c in range(r):
c_ = (c - sft) % n # 減算に直した
if s[r][c_] != s[c][r_]:
# kマス列シフトした後の(r,c)と(c,r)の一致を見るには、
# (r,c)と(c,r)それぞれの列シフト前、つまり列-sftの座標を見る必要がある
# r_を用意せず、c_だけで済むと勘違いした
return False
return True
n = int(eval(input()))
s = tuple(eval(input()) for _ in range(n))
# (0,0)==(1,1)==...==(n-1,n-1)
# colのオフセットだけ変化させる
# それぞれのループで、n個の状態(0,k)==(1,k+1)==...を扱う
ans = 0
for k in range(n):
if is_good_grid(k):
ans += n
print(ans)
| false | 4 | [
"-def is_good_grid():",
"+def is_good_grid(sft):",
"+ r_ = (r - sft) % n # 減算に直した",
"- if t[r][c] != t[c][r]:",
"+ c_ = (c - sft) % n # 減算に直した",
"+ if s[r][c_] != s[c][r_]:",
"+ # kマス列シフトした後の(r,c)と(c,r)の一致を見るには、",
"+ # (r,c)と(c,r)それぞれの列シフト前、つまり列-sftの座標を見る必要がある",
"+ # r_を用意せず、c_だけで済むと勘違いした",
"- t = [[\"\"] * n for _ in range(n)]",
"- for r in range(n):",
"- for c in range(n):",
"- t[r][c] = s[r][(c + k) % n]",
"- if is_good_grid():",
"+ if is_good_grid(k):"
] | false | 0.036953 | 0.040414 | 0.914351 | [
"s827262677",
"s785119947"
] |
u941407962 | p02763 | python | s407267460 | s205605071 | 1,008 | 920 | 164,636 | 164,952 | Accepted | Accepted | 8.73 | import sys
input = sys.stdin.readline
class Bit:
def __init__(self, n):
self.size = n
self.tree = [0] * (n + 1)
def sum(self, i):
if i == 0:
return 0
s = 0
while i > 0:
s += self.tree[i]
i -= i & -i
return s
def add(self, i, x):
while i <= self.size:
self.tree[i] += x
i += i & -i
aas = "abcdefghijklmnopqrstuvwxyz"
N = int(input().strip())
S = list(input().strip())
Q = int(input().strip())
cbt = dict()
MX = 5 * 10**5 + 2
for c in aas:
cbt[c] = Bit(MX)
for i, a in enumerate(S):
if a == c:
cbt[c].add(i+1, 1)
for _ in range(Q):
t, i, c = input().split()
t = int(t)
if t == 1:
i = int(i)
if S[i-1] != c:
cbt[S[i-1]].add(i, -1)
cbt[c].add(i, 1)
S[i-1] = c
else:
# print(S)
l, r = int(i), int(c)
# print(l, r)
s = 0
for a in aas:
bt = cbt[a]
# print(a, bt.sum(r),bt.sum(l-1))
s += (bt.sum(r)-bt.sum(l-1)>0)
print(s)
| import sys
input = sys.stdin.readline
class Bit:
def __init__(self, n):
self.size = n
self.tree = [0] * (n + 1)
def sum(self, i):
if i == 0:
return 0
s = 0
while i > 0:
s += self.tree[i]
i -= i & -i
return s
def add(self, i, x):
while i <= self.size:
self.tree[i] += x
i += i & -i
aas = "abcdefghijklmnopqrstuvwxyz"
N = int(input().strip())
S = [" "]+list(input().strip())
Q = int(input().strip())
cbt = dict()
for c in aas:
cbt[c] = Bit(N)
for i, a in enumerate(S):
if i == 0:
continue
if a == c:
cbt[c].add(i, 1)
for _ in range(Q):
t, i, c = input().split()
t = int(t)
if t == 1:
i = int(i)
if S[i] != c:
cbt[S[i]].add(i, -1)
cbt[c].add(i, 1)
S[i] = c
else:
l, r = int(i), int(c)
s = 0
for a in aas:
bt = cbt[a]
s += (bt.sum(r)-bt.sum(l-1)>0)
print(s)
| 51 | 49 | 1,175 | 1,107 | import sys
input = sys.stdin.readline
class Bit:
def __init__(self, n):
self.size = n
self.tree = [0] * (n + 1)
def sum(self, i):
if i == 0:
return 0
s = 0
while i > 0:
s += self.tree[i]
i -= i & -i
return s
def add(self, i, x):
while i <= self.size:
self.tree[i] += x
i += i & -i
aas = "abcdefghijklmnopqrstuvwxyz"
N = int(input().strip())
S = list(input().strip())
Q = int(input().strip())
cbt = dict()
MX = 5 * 10**5 + 2
for c in aas:
cbt[c] = Bit(MX)
for i, a in enumerate(S):
if a == c:
cbt[c].add(i + 1, 1)
for _ in range(Q):
t, i, c = input().split()
t = int(t)
if t == 1:
i = int(i)
if S[i - 1] != c:
cbt[S[i - 1]].add(i, -1)
cbt[c].add(i, 1)
S[i - 1] = c
else:
# print(S)
l, r = int(i), int(c)
# print(l, r)
s = 0
for a in aas:
bt = cbt[a]
# print(a, bt.sum(r),bt.sum(l-1))
s += bt.sum(r) - bt.sum(l - 1) > 0
print(s)
| import sys
input = sys.stdin.readline
class Bit:
def __init__(self, n):
self.size = n
self.tree = [0] * (n + 1)
def sum(self, i):
if i == 0:
return 0
s = 0
while i > 0:
s += self.tree[i]
i -= i & -i
return s
def add(self, i, x):
while i <= self.size:
self.tree[i] += x
i += i & -i
aas = "abcdefghijklmnopqrstuvwxyz"
N = int(input().strip())
S = [" "] + list(input().strip())
Q = int(input().strip())
cbt = dict()
for c in aas:
cbt[c] = Bit(N)
for i, a in enumerate(S):
if i == 0:
continue
if a == c:
cbt[c].add(i, 1)
for _ in range(Q):
t, i, c = input().split()
t = int(t)
if t == 1:
i = int(i)
if S[i] != c:
cbt[S[i]].add(i, -1)
cbt[c].add(i, 1)
S[i] = c
else:
l, r = int(i), int(c)
s = 0
for a in aas:
bt = cbt[a]
s += bt.sum(r) - bt.sum(l - 1) > 0
print(s)
| false | 3.921569 | [
"-S = list(input().strip())",
"+S = [\" \"] + list(input().strip())",
"-MX = 5 * 10**5 + 2",
"- cbt[c] = Bit(MX)",
"+ cbt[c] = Bit(N)",
"+ if i == 0:",
"+ continue",
"- cbt[c].add(i + 1, 1)",
"+ cbt[c].add(i, 1)",
"- if S[i - 1] != c:",
"- cbt[S[i - 1]].add(i, -1)",
"+ if S[i] != c:",
"+ cbt[S[i]].add(i, -1)",
"- S[i - 1] = c",
"+ S[i] = c",
"- # print(S)",
"- # print(l, r)",
"- # print(a, bt.sum(r),bt.sum(l-1))"
] | false | 0.574904 | 0.116716 | 4.925653 | [
"s407267460",
"s205605071"
] |
u994988729 | p03352 | python | s166442805 | s427855049 | 23 | 17 | 2,940 | 2,940 | Accepted | Accepted | 26.09 | X = int(eval(input()))
ans = 0
for i in range(1, 100):
for j in range(2, 100):
if i ** j <= X:
ans = max(ans, i ** j)
print(ans)
| X = int(eval(input()))
ans = 1
for b in range(2, 40):
p = 2
while True:
val = b ** p
if val > X:
break
ans = max(ans, val)
p += 1
print(ans)
| 9 | 13 | 157 | 201 | X = int(eval(input()))
ans = 0
for i in range(1, 100):
for j in range(2, 100):
if i**j <= X:
ans = max(ans, i**j)
print(ans)
| X = int(eval(input()))
ans = 1
for b in range(2, 40):
p = 2
while True:
val = b**p
if val > X:
break
ans = max(ans, val)
p += 1
print(ans)
| false | 30.769231 | [
"-ans = 0",
"-for i in range(1, 100):",
"- for j in range(2, 100):",
"- if i**j <= X:",
"- ans = max(ans, i**j)",
"+ans = 1",
"+for b in range(2, 40):",
"+ p = 2",
"+ while True:",
"+ val = b**p",
"+ if val > X:",
"+ break",
"+ ans = max(ans, val)",
"+ p += 1"
] | false | 0.056359 | 0.045433 | 1.240486 | [
"s166442805",
"s427855049"
] |
u389910364 | p03779 | python | s583002598 | s825949196 | 176 | 160 | 13,664 | 13,596 | Accepted | Accepted | 9.09 | import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor
import numpy as np
if os.getenv("LOCAL"):
sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
X = int(sys.stdin.readline())
ans = 0
x = 1
s = 0
while s < X:
s += x
x += 1
print((x - 1))
| import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor
import numpy as np
if os.getenv("LOCAL"):
sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
X = int(sys.stdin.readline())
print((int(math.ceil((-1 + math.sqrt(1 + 8 * X)) / 2))))
# ans = 0
# x = 1
# s = 0
# while s < X:
# s += x
# x += 1
# print(x - 1)
#
| 34 | 37 | 637 | 712 | import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor
import numpy as np
if os.getenv("LOCAL"):
sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10**18
MOD = 10**9 + 7
X = int(sys.stdin.readline())
ans = 0
x = 1
s = 0
while s < X:
s += x
x += 1
print((x - 1))
| import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor
import numpy as np
if os.getenv("LOCAL"):
sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10**18
MOD = 10**9 + 7
X = int(sys.stdin.readline())
print((int(math.ceil((-1 + math.sqrt(1 + 8 * X)) / 2))))
# ans = 0
# x = 1
# s = 0
# while s < X:
# s += x
# x += 1
# print(x - 1)
#
| false | 8.108108 | [
"-ans = 0",
"-x = 1",
"-s = 0",
"-while s < X:",
"- s += x",
"- x += 1",
"-print((x - 1))",
"+print((int(math.ceil((-1 + math.sqrt(1 + 8 * X)) / 2))))",
"+# ans = 0",
"+# x = 1",
"+# s = 0",
"+# while s < X:",
"+# s += x",
"+# x += 1",
"+# print(x - 1)",
"+#"
] | false | 0.042075 | 0.045413 | 0.926496 | [
"s583002598",
"s825949196"
] |
u324314500 | p03036 | python | s009902607 | s218686504 | 186 | 167 | 38,384 | 38,256 | Accepted | Accepted | 10.22 | import sys
#import numpy as np
s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))
def main():
r, D, x = i2nn()
for _ in range(10):
x = (r * x) - D
print(x)
main()
| import sys
s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2sss = lambda n: [list(sys.stdin.readline().rstrip()) for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))
def main():
r, D, x = i2nn()
for i in range(10):
x = r * x - D
print(x)
main()
| 20 | 19 | 522 | 573 | import sys
# import numpy as np
s2nn = lambda s: [int(c) for c in s.split(" ")]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))
def main():
r, D, x = i2nn()
for _ in range(10):
x = (r * x) - D
print(x)
main()
| import sys
s2nn = lambda s: [int(c) for c in s.split(" ")]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2sss = lambda n: [list(sys.stdin.readline().rstrip()) for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))
def main():
r, D, x = i2nn()
for i in range(10):
x = r * x - D
print(x)
main()
| false | 5 | [
"-# import numpy as np",
"+ii2sss = lambda n: [list(sys.stdin.readline().rstrip()) for _ in range(n)]",
"- for _ in range(10):",
"- x = (r * x) - D",
"+ for i in range(10):",
"+ x = r * x - D"
] | false | 0.051389 | 0.047741 | 1.076415 | [
"s009902607",
"s218686504"
] |
u767664985 | p03524 | python | s344764877 | s518470864 | 26 | 18 | 3,444 | 3,188 | Accepted | Accepted | 30.77 | from collections import Counter
S = eval(input())
c = Counter(S)
if len(c) == 3 and max(c.values()) - min(c.values()) <= 1:
print("YES")
elif len(c) == 2 and len(S) == 2:
print("YES")
elif len(c) == 1 and len(S) == 1:
print("YES")
else:
print("NO")
| S = eval(input())
x = (S.count("a"), S.count("b"), S.count("c"))
if max(x) - min(x) >= 2:
print("NO")
else:
print("YES")
| 13 | 7 | 273 | 130 | from collections import Counter
S = eval(input())
c = Counter(S)
if len(c) == 3 and max(c.values()) - min(c.values()) <= 1:
print("YES")
elif len(c) == 2 and len(S) == 2:
print("YES")
elif len(c) == 1 and len(S) == 1:
print("YES")
else:
print("NO")
| S = eval(input())
x = (S.count("a"), S.count("b"), S.count("c"))
if max(x) - min(x) >= 2:
print("NO")
else:
print("YES")
| false | 46.153846 | [
"-from collections import Counter",
"-",
"-c = Counter(S)",
"-if len(c) == 3 and max(c.values()) - min(c.values()) <= 1:",
"+x = (S.count(\"a\"), S.count(\"b\"), S.count(\"c\"))",
"+if max(x) - min(x) >= 2:",
"+ print(\"NO\")",
"+else:",
"-elif len(c) == 2 and len(S) == 2:",
"- print(\"YES\")",
"-elif len(c) == 1 and len(S) == 1:",
"- print(\"YES\")",
"-else:",
"- print(\"NO\")"
] | false | 0.084288 | 0.079732 | 1.05714 | [
"s344764877",
"s518470864"
] |
u634159866 | p03013 | python | s804660337 | s648743115 | 476 | 181 | 460,020 | 7,824 | Accepted | Accepted | 61.97 | N, M = list(map(int, input().split()))
List = [int(eval(input())) for _ in range(M)]
P = 10**9+7
dp = [1]*(N+1)
for i in List:
dp[i]=0
for j in range(1, N):
if dp[j+1]!=0:
dp[j+1] = dp[j]+dp[j-1]
print((dp[N]%P)) | N, M = list(map(int, input().split()))
List = [int(eval(input())) for _ in range(M)]
P = 10**9+7
dp = [1]*(N+1)
for i in List:
dp[i]=0
for j in range(1, N):
if dp[j+1]!=0:
dp[j+1] = (dp[j]+dp[j-1])%P
print((dp[N])) | 14 | 14 | 239 | 241 | N, M = list(map(int, input().split()))
List = [int(eval(input())) for _ in range(M)]
P = 10**9 + 7
dp = [1] * (N + 1)
for i in List:
dp[i] = 0
for j in range(1, N):
if dp[j + 1] != 0:
dp[j + 1] = dp[j] + dp[j - 1]
print((dp[N] % P))
| N, M = list(map(int, input().split()))
List = [int(eval(input())) for _ in range(M)]
P = 10**9 + 7
dp = [1] * (N + 1)
for i in List:
dp[i] = 0
for j in range(1, N):
if dp[j + 1] != 0:
dp[j + 1] = (dp[j] + dp[j - 1]) % P
print((dp[N]))
| false | 0 | [
"- dp[j + 1] = dp[j] + dp[j - 1]",
"-print((dp[N] % P))",
"+ dp[j + 1] = (dp[j] + dp[j - 1]) % P",
"+print((dp[N]))"
] | false | 0.040529 | 0.03695 | 1.096862 | [
"s804660337",
"s648743115"
] |
u932465688 | p03221 | python | s184009728 | s882884195 | 867 | 709 | 36,228 | 36,840 | Accepted | Accepted | 18.22 | N,M = list(map(int,input().split()))
L = []
for i in range(M):
L.append(list(map(int,input().split())))
for j in range(M):
L[j].append(j)
L.sort()
l = L[0][0]
cnt = 0
for k in range(M):
if l == L[k][0]:
cnt += 1
L[k].append(cnt)
else:
l = L[k][0]
cnt = 1
L[k].append(cnt)
L = sorted(L, key = lambda x:x[2])
for i in range(M):
print(('0'*(6-len(str(L[i][0])))+str(L[i][0])+'0'*(6-len(str(L[i][3])))+str(L[i][3])))
| N,M = list(map(int,input().split()))
L = []
for i in range(M):
L.append(list(map(int,input().split())))
for i in range(M):
L[i].append(i)
cnt = [0]*N
L = sorted(L, key = lambda x:x[1])
for i in range(M):
L[i].append(cnt[L[i][0]-1])
cnt[L[i][0]-1] += 1
L = sorted(L, key = lambda x:x[2])
for i in range(M):
ID = str(L[i][0]).zfill(6)+str(L[i][3]+1).zfill(6)
print(ID) | 20 | 15 | 454 | 386 | N, M = list(map(int, input().split()))
L = []
for i in range(M):
L.append(list(map(int, input().split())))
for j in range(M):
L[j].append(j)
L.sort()
l = L[0][0]
cnt = 0
for k in range(M):
if l == L[k][0]:
cnt += 1
L[k].append(cnt)
else:
l = L[k][0]
cnt = 1
L[k].append(cnt)
L = sorted(L, key=lambda x: x[2])
for i in range(M):
print(
(
"0" * (6 - len(str(L[i][0])))
+ str(L[i][0])
+ "0" * (6 - len(str(L[i][3])))
+ str(L[i][3])
)
)
| N, M = list(map(int, input().split()))
L = []
for i in range(M):
L.append(list(map(int, input().split())))
for i in range(M):
L[i].append(i)
cnt = [0] * N
L = sorted(L, key=lambda x: x[1])
for i in range(M):
L[i].append(cnt[L[i][0] - 1])
cnt[L[i][0] - 1] += 1
L = sorted(L, key=lambda x: x[2])
for i in range(M):
ID = str(L[i][0]).zfill(6) + str(L[i][3] + 1).zfill(6)
print(ID)
| false | 25 | [
"-for j in range(M):",
"- L[j].append(j)",
"-L.sort()",
"-l = L[0][0]",
"-cnt = 0",
"-for k in range(M):",
"- if l == L[k][0]:",
"- cnt += 1",
"- L[k].append(cnt)",
"- else:",
"- l = L[k][0]",
"- cnt = 1",
"- L[k].append(cnt)",
"+for i in range(M):",
"+ L[i].append(i)",
"+cnt = [0] * N",
"+L = sorted(L, key=lambda x: x[1])",
"+for i in range(M):",
"+ L[i].append(cnt[L[i][0] - 1])",
"+ cnt[L[i][0] - 1] += 1",
"- print(",
"- (",
"- \"0\" * (6 - len(str(L[i][0])))",
"- + str(L[i][0])",
"- + \"0\" * (6 - len(str(L[i][3])))",
"- + str(L[i][3])",
"- )",
"- )",
"+ ID = str(L[i][0]).zfill(6) + str(L[i][3] + 1).zfill(6)",
"+ print(ID)"
] | false | 0.154334 | 0.158239 | 0.975321 | [
"s184009728",
"s882884195"
] |
u497805118 | p02713 | python | s044282568 | s005714945 | 1,034 | 524 | 9,148 | 67,728 | Accepted | Accepted | 49.32 | import itertools
import math
k = int(eval(input()))
x = 0
for v in itertools.combinations_with_replacement(list(range(1, k+1)), 3):
a, b, c = v
x = x + math.gcd(math.gcd(a,b), c)
y = 0
for v in itertools.combinations(list(range(1, k+1)), 3):
a, b, c = v
y = y + math.gcd(math.gcd(a,b), c)
z = k * (1 + k) / 2
print(( int(3 * x + y * 3 - 2 * z))) | import math
k = int(eval(input()))
cache = {}
ans = 0
for a in range(1, k+1):
for b in range(1, k+1):
for c in range(1, k+1):
ans = ans + cache.get( (a,b,c), math.gcd(math.gcd(a, b), c))
print(ans) | 16 | 11 | 374 | 229 | import itertools
import math
k = int(eval(input()))
x = 0
for v in itertools.combinations_with_replacement(list(range(1, k + 1)), 3):
a, b, c = v
x = x + math.gcd(math.gcd(a, b), c)
y = 0
for v in itertools.combinations(list(range(1, k + 1)), 3):
a, b, c = v
y = y + math.gcd(math.gcd(a, b), c)
z = k * (1 + k) / 2
print((int(3 * x + y * 3 - 2 * z)))
| import math
k = int(eval(input()))
cache = {}
ans = 0
for a in range(1, k + 1):
for b in range(1, k + 1):
for c in range(1, k + 1):
ans = ans + cache.get((a, b, c), math.gcd(math.gcd(a, b), c))
print(ans)
| false | 31.25 | [
"-import itertools",
"-x = 0",
"-for v in itertools.combinations_with_replacement(list(range(1, k + 1)), 3):",
"- a, b, c = v",
"- x = x + math.gcd(math.gcd(a, b), c)",
"-y = 0",
"-for v in itertools.combinations(list(range(1, k + 1)), 3):",
"- a, b, c = v",
"- y = y + math.gcd(math.gcd(a, b), c)",
"-z = k * (1 + k) / 2",
"-print((int(3 * x + y * 3 - 2 * z)))",
"+cache = {}",
"+ans = 0",
"+for a in range(1, k + 1):",
"+ for b in range(1, k + 1):",
"+ for c in range(1, k + 1):",
"+ ans = ans + cache.get((a, b, c), math.gcd(math.gcd(a, b), c))",
"+print(ans)"
] | false | 0.094674 | 0.090429 | 1.046935 | [
"s044282568",
"s005714945"
] |
u562015767 | p03673 | python | s129906610 | s335810865 | 175 | 153 | 42,908 | 117,048 | Accepted | Accepted | 12.57 | n = int(eval(input()))
l = list(map(int,input().split()))
if n == 1:
l = list(map(str,l))
print((" ".join(l)))
exit()
2
ans = []
if n%2 == 0:
tmp = n
for j in range(n//2-1):
ans.append(tmp)
tmp -= 2
ans.append(tmp)
ans.append(1)
tmp = 1
for j in range(n//2-1):
tmp += 2
ans.append(tmp)
else:
tmp = n
for j in range(n//2):
ans.append(tmp)
tmp -= 2
ans.append(tmp)
tmp = 2
for j in range(n//2):
ans.append(tmp)
tmp += 2
ans2 = [0]*n
cnt = 0
for i in ans:
ans2[cnt] = str(l[i-1])
cnt += 1
print((" ".join(ans2))) | n = int(eval(input()))
l = list(map(int,input().split()))
if n == 1:
l = list(map(str,l))
print((" ".join(l)))
exit()
ans = []
if n%2 == 0:
tmp = n
for j in range(n//2-1):
ans.append(tmp)
tmp -= 2
ans.append(tmp)
ans.append(1)
tmp = 1
for j in range(n//2-1):
tmp += 2
ans.append(tmp)
else:
tmp = n
for j in range(n//2):
ans.append(tmp)
tmp -= 2
ans.append(tmp)
tmp = 2
for j in range(n//2):
ans.append(tmp)
tmp += 2
ans2 = [0]*n
cnt = 0
for i in ans:
ans2[cnt] = str(l[i-1])
cnt += 1
print((" ".join(ans2)))
| 41 | 40 | 673 | 671 | n = int(eval(input()))
l = list(map(int, input().split()))
if n == 1:
l = list(map(str, l))
print((" ".join(l)))
exit()
2
ans = []
if n % 2 == 0:
tmp = n
for j in range(n // 2 - 1):
ans.append(tmp)
tmp -= 2
ans.append(tmp)
ans.append(1)
tmp = 1
for j in range(n // 2 - 1):
tmp += 2
ans.append(tmp)
else:
tmp = n
for j in range(n // 2):
ans.append(tmp)
tmp -= 2
ans.append(tmp)
tmp = 2
for j in range(n // 2):
ans.append(tmp)
tmp += 2
ans2 = [0] * n
cnt = 0
for i in ans:
ans2[cnt] = str(l[i - 1])
cnt += 1
print((" ".join(ans2)))
| n = int(eval(input()))
l = list(map(int, input().split()))
if n == 1:
l = list(map(str, l))
print((" ".join(l)))
exit()
ans = []
if n % 2 == 0:
tmp = n
for j in range(n // 2 - 1):
ans.append(tmp)
tmp -= 2
ans.append(tmp)
ans.append(1)
tmp = 1
for j in range(n // 2 - 1):
tmp += 2
ans.append(tmp)
else:
tmp = n
for j in range(n // 2):
ans.append(tmp)
tmp -= 2
ans.append(tmp)
tmp = 2
for j in range(n // 2):
ans.append(tmp)
tmp += 2
ans2 = [0] * n
cnt = 0
for i in ans:
ans2[cnt] = str(l[i - 1])
cnt += 1
print((" ".join(ans2)))
| false | 2.439024 | [
"-2"
] | false | 0.043133 | 0.113425 | 0.380275 | [
"s129906610",
"s335810865"
] |
u533232830 | p02948 | python | s813525789 | s608908509 | 479 | 304 | 26,016 | 88,740 | Accepted | Accepted | 36.53 | import heapq
n, m = list(map(int, input().split()))
dic = {}
for i in range(n):
a, b = list(map(int, input().split()))
if a >= m+1:
continue
if a in list(dic.keys()):
dic[a].append(b)
else:
dic[a] = [b]
ans = 0
l = []
heapq.heapify(l)
for j in range(1, m+1):
if j in list(dic.keys()):
for x in dic[j]:
heapq.heappush(l, -x)
if l:
ans += -l[0]
heapq.heappop(l)
print(ans) | import heapq
n, m = list(map(int, input().split()))
memo = [[] for _ in range(m+1)]
for _ in range(n):
a, b = list(map(int ,input().split()))
if a <= m:
memo[a].append(-b)
ans = 0
HQ = []
heapq.heapify(HQ)
for i in range(1, m+1):
for j in memo[i]:
heapq.heappush(HQ, j)
if HQ:
ans += heapq.heappop(HQ)
print((-ans)) | 26 | 20 | 459 | 364 | import heapq
n, m = list(map(int, input().split()))
dic = {}
for i in range(n):
a, b = list(map(int, input().split()))
if a >= m + 1:
continue
if a in list(dic.keys()):
dic[a].append(b)
else:
dic[a] = [b]
ans = 0
l = []
heapq.heapify(l)
for j in range(1, m + 1):
if j in list(dic.keys()):
for x in dic[j]:
heapq.heappush(l, -x)
if l:
ans += -l[0]
heapq.heappop(l)
print(ans)
| import heapq
n, m = list(map(int, input().split()))
memo = [[] for _ in range(m + 1)]
for _ in range(n):
a, b = list(map(int, input().split()))
if a <= m:
memo[a].append(-b)
ans = 0
HQ = []
heapq.heapify(HQ)
for i in range(1, m + 1):
for j in memo[i]:
heapq.heappush(HQ, j)
if HQ:
ans += heapq.heappop(HQ)
print((-ans))
| false | 23.076923 | [
"-dic = {}",
"-for i in range(n):",
"+memo = [[] for _ in range(m + 1)]",
"+for _ in range(n):",
"- if a >= m + 1:",
"- continue",
"- if a in list(dic.keys()):",
"- dic[a].append(b)",
"- else:",
"- dic[a] = [b]",
"+ if a <= m:",
"+ memo[a].append(-b)",
"-l = []",
"-heapq.heapify(l)",
"-for j in range(1, m + 1):",
"- if j in list(dic.keys()):",
"- for x in dic[j]:",
"- heapq.heappush(l, -x)",
"- if l:",
"- ans += -l[0]",
"- heapq.heappop(l)",
"-print(ans)",
"+HQ = []",
"+heapq.heapify(HQ)",
"+for i in range(1, m + 1):",
"+ for j in memo[i]:",
"+ heapq.heappush(HQ, j)",
"+ if HQ:",
"+ ans += heapq.heappop(HQ)",
"+print((-ans))"
] | false | 0.061319 | 0.075921 | 0.807674 | [
"s813525789",
"s608908509"
] |
u745087332 | p03290 | python | s013116495 | s797279196 | 46 | 23 | 3,064 | 3,064 | Accepted | Accepted | 50 | # coding:utf-8
INF = float('inf')
def inpl(): return list(map(int, input().split()))
D, G = inpl()
P, C = [], []
for i in range(D):
p, c = inpl()
P.append(p)
C.append(c + 100 * (i + 1) * p)
ans = INF
for i in range(2 ** D):
point = 0
cnt = 0
rest_max = 0
for shift in range(D):
if i >> shift & 1:
cnt += P[shift]
point += C[shift]
else:
rest_max = shift
if point < G:
for j in range(P[rest_max]):
if point >= G:
break
cnt += 1
point += (rest_max + 1) * 100
else:
continue
ans = min(ans, cnt)
print(ans)
| # coding:utf-8
import sys
INF = float('inf')
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return eval(input())
# mathを使わない切り上げ
def ceil(n, m):
return -(-n//m)
d, g = LI()
contest = [LI() for _ in range(d)]
ans = INF
# Bit全探索
for bit in range(1 << d):
score = 0
cnt = 0
remain_max = -1
# 各bitが立っているか確認
for i in range(d):
if bit >> i & 1:
score += contest[i][0] * (i + 1) * 100 + contest[i][1]
cnt += contest[i][0]
continue
# コンプリートしなかった問題の中で最も得点の高い問題をメモ
remain_max = i
if score >= g:
ans = min(ans, cnt)
continue
need = ceil((g - score) // 100, remain_max + 1)
if need >= contest[remain_max][0]:
continue
ans = min(ans, cnt + need)
print(ans)
| 39 | 51 | 718 | 1,028 | # coding:utf-8
INF = float("inf")
def inpl():
return list(map(int, input().split()))
D, G = inpl()
P, C = [], []
for i in range(D):
p, c = inpl()
P.append(p)
C.append(c + 100 * (i + 1) * p)
ans = INF
for i in range(2**D):
point = 0
cnt = 0
rest_max = 0
for shift in range(D):
if i >> shift & 1:
cnt += P[shift]
point += C[shift]
else:
rest_max = shift
if point < G:
for j in range(P[rest_max]):
if point >= G:
break
cnt += 1
point += (rest_max + 1) * 100
else:
continue
ans = min(ans, cnt)
print(ans)
| # coding:utf-8
import sys
INF = float("inf")
MOD = 10**9 + 7
def LI():
return [int(x) for x in sys.stdin.readline().split()]
def LI_():
return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS():
return sys.stdin.readline().split()
def II():
return int(sys.stdin.readline())
def SI():
return eval(input())
# mathを使わない切り上げ
def ceil(n, m):
return -(-n // m)
d, g = LI()
contest = [LI() for _ in range(d)]
ans = INF
# Bit全探索
for bit in range(1 << d):
score = 0
cnt = 0
remain_max = -1
# 各bitが立っているか確認
for i in range(d):
if bit >> i & 1:
score += contest[i][0] * (i + 1) * 100 + contest[i][1]
cnt += contest[i][0]
continue
# コンプリートしなかった問題の中で最も得点の高い問題をメモ
remain_max = i
if score >= g:
ans = min(ans, cnt)
continue
need = ceil((g - score) // 100, remain_max + 1)
if need >= contest[remain_max][0]:
continue
ans = min(ans, cnt + need)
print(ans)
| false | 23.529412 | [
"+import sys",
"+",
"+MOD = 10**9 + 7",
"-def inpl():",
"- return list(map(int, input().split()))",
"+def LI():",
"+ return [int(x) for x in sys.stdin.readline().split()]",
"-D, G = inpl()",
"-P, C = [], []",
"-for i in range(D):",
"- p, c = inpl()",
"- P.append(p)",
"- C.append(c + 100 * (i + 1) * p)",
"+def LI_():",
"+ return [int(x) - 1 for x in sys.stdin.readline().split()]",
"+",
"+",
"+def LS():",
"+ return sys.stdin.readline().split()",
"+",
"+",
"+def II():",
"+ return int(sys.stdin.readline())",
"+",
"+",
"+def SI():",
"+ return eval(input())",
"+",
"+",
"+# mathを使わない切り上げ",
"+def ceil(n, m):",
"+ return -(-n // m)",
"+",
"+",
"+d, g = LI()",
"+contest = [LI() for _ in range(d)]",
"-for i in range(2**D):",
"- point = 0",
"+# Bit全探索",
"+for bit in range(1 << d):",
"+ score = 0",
"- rest_max = 0",
"- for shift in range(D):",
"- if i >> shift & 1:",
"- cnt += P[shift]",
"- point += C[shift]",
"- else:",
"- rest_max = shift",
"- if point < G:",
"- for j in range(P[rest_max]):",
"- if point >= G:",
"- break",
"- cnt += 1",
"- point += (rest_max + 1) * 100",
"- else:",
"+ remain_max = -1",
"+ # 各bitが立っているか確認",
"+ for i in range(d):",
"+ if bit >> i & 1:",
"+ score += contest[i][0] * (i + 1) * 100 + contest[i][1]",
"+ cnt += contest[i][0]",
"- ans = min(ans, cnt)",
"+ # コンプリートしなかった問題の中で最も得点の高い問題をメモ",
"+ remain_max = i",
"+ if score >= g:",
"+ ans = min(ans, cnt)",
"+ continue",
"+ need = ceil((g - score) // 100, remain_max + 1)",
"+ if need >= contest[remain_max][0]:",
"+ continue",
"+ ans = min(ans, cnt + need)"
] | false | 0.047435 | 0.039771 | 1.192714 | [
"s013116495",
"s797279196"
] |
u285681431 | p03599 | python | s319030237 | s213642287 | 143 | 131 | 18,332 | 18,312 | Accepted | Accepted | 8.39 | # 35行目. >だと1ケース通らずWA, >=だとAC. なんで?????
A, B, C, D, E, F = list(map(int, input().split()))
# 可能な水の総量
water_list = []
A_max = F // (100 * A)
B_max = F // (100 * B)
for i in range(A_max + 1):
for j in range(B_max + 1):
temp = 100 * A * i + 100 * B * j
if temp <= F:
water_list.append(temp)
water_list = list(set(water_list))
# 可能な砂糖の総量
sugar_list = []
C_max = F // (C)
D_max = F // (D)
for i in range(C_max + 1):
for j in range(D_max + 1):
temp = C * i + D * j
if temp <= F:
sugar_list.append(temp)
sugar_list = list(set(sugar_list))
max_conc = 0
max_conc_water = 0
max_conc_sugar = 0
for water in water_list:
for sugar in sugar_list:
# 水があるか and 溶解度を超えていないか and 容器に入るか
if water != 0 and sugar <= ((E * water) / 100) and water + sugar <= F:
conc = (100 * sugar) / (water + sugar)
if conc >= max_conc:
max_conc = conc
max_conc_water = water
max_conc_sugar = sugar
print((max_conc_water + max_conc_sugar, max_conc_sugar))
# print(max_conc)
| A, B, C, D, E, F = list(map(int, input().split()))
# 可能な水の総量
water_list = []
A_max = F // (100 * A)
B_max = F // (100 * B)
for i in range(A_max + 1):
for j in range(B_max + 1):
temp = 100 * A * i + 100 * B * j
if temp <= F:
water_list.append(temp)
water_list = list(set(water_list))
# 可能な砂糖の総量
sugar_list = []
C_max = F // (C)
D_max = F // (D)
for i in range(C_max + 1):
for j in range(D_max + 1):
temp = C * i + D * j
if temp <= F:
sugar_list.append(temp)
sugar_list = list(set(sugar_list))
# max_conc=0から始めると0%の場合を拾えなくなる. あるいは34行目で等号をつけても良い.
max_conc = -1
max_conc_water = -1
max_conc_sugar = -1
for water in water_list:
for sugar in sugar_list:
# 水があるか and 溶解度を超えていないか and 容器に入るか
if water != 0 and sugar <= ((E * water) / 100) and water + sugar <= F:
conc = (100 * sugar) / (water + sugar)
if conc > max_conc:
max_conc = conc
max_conc_water = water
max_conc_sugar = sugar
print((max_conc_water + max_conc_sugar, max_conc_sugar))
# print(max_conc)
| 41 | 40 | 1,128 | 1,141 | # 35行目. >だと1ケース通らずWA, >=だとAC. なんで?????
A, B, C, D, E, F = list(map(int, input().split()))
# 可能な水の総量
water_list = []
A_max = F // (100 * A)
B_max = F // (100 * B)
for i in range(A_max + 1):
for j in range(B_max + 1):
temp = 100 * A * i + 100 * B * j
if temp <= F:
water_list.append(temp)
water_list = list(set(water_list))
# 可能な砂糖の総量
sugar_list = []
C_max = F // (C)
D_max = F // (D)
for i in range(C_max + 1):
for j in range(D_max + 1):
temp = C * i + D * j
if temp <= F:
sugar_list.append(temp)
sugar_list = list(set(sugar_list))
max_conc = 0
max_conc_water = 0
max_conc_sugar = 0
for water in water_list:
for sugar in sugar_list:
# 水があるか and 溶解度を超えていないか and 容器に入るか
if water != 0 and sugar <= ((E * water) / 100) and water + sugar <= F:
conc = (100 * sugar) / (water + sugar)
if conc >= max_conc:
max_conc = conc
max_conc_water = water
max_conc_sugar = sugar
print((max_conc_water + max_conc_sugar, max_conc_sugar))
# print(max_conc)
| A, B, C, D, E, F = list(map(int, input().split()))
# 可能な水の総量
water_list = []
A_max = F // (100 * A)
B_max = F // (100 * B)
for i in range(A_max + 1):
for j in range(B_max + 1):
temp = 100 * A * i + 100 * B * j
if temp <= F:
water_list.append(temp)
water_list = list(set(water_list))
# 可能な砂糖の総量
sugar_list = []
C_max = F // (C)
D_max = F // (D)
for i in range(C_max + 1):
for j in range(D_max + 1):
temp = C * i + D * j
if temp <= F:
sugar_list.append(temp)
sugar_list = list(set(sugar_list))
# max_conc=0から始めると0%の場合を拾えなくなる. あるいは34行目で等号をつけても良い.
max_conc = -1
max_conc_water = -1
max_conc_sugar = -1
for water in water_list:
for sugar in sugar_list:
# 水があるか and 溶解度を超えていないか and 容器に入るか
if water != 0 and sugar <= ((E * water) / 100) and water + sugar <= F:
conc = (100 * sugar) / (water + sugar)
if conc > max_conc:
max_conc = conc
max_conc_water = water
max_conc_sugar = sugar
print((max_conc_water + max_conc_sugar, max_conc_sugar))
# print(max_conc)
| false | 2.439024 | [
"-# 35行目. >だと1ケース通らずWA, >=だとAC. なんで?????",
"-max_conc = 0",
"-max_conc_water = 0",
"-max_conc_sugar = 0",
"+# max_conc=0から始めると0%の場合を拾えなくなる. あるいは34行目で等号をつけても良い.",
"+max_conc = -1",
"+max_conc_water = -1",
"+max_conc_sugar = -1",
"- if conc >= max_conc:",
"+ if conc > max_conc:"
] | false | 0.070876 | 0.074207 | 0.955122 | [
"s319030237",
"s213642287"
] |
u223663729 | p02697 | python | s704718201 | s963285974 | 94 | 79 | 18,780 | 9,212 | Accepted | Accepted | 15.96 | N, M = list(map(int, input().split()))
A = list(range(M))
B = list(range(M, 2*M))[::-1]
B = [-2-i for i in range(M//2)] + B[M//2:]
for a, b in zip(A, B):
print((a % N + 1, b % N + 1))
| N, M = list(map(int, input().split()))
if M & 1:
print((M, M+1))
m=M//2
for i in range(m):
print((i+1, (-2-i)%N+1))
print((i+m+1, 2*M-m-i))
| 8 | 7 | 189 | 146 | N, M = list(map(int, input().split()))
A = list(range(M))
B = list(range(M, 2 * M))[::-1]
B = [-2 - i for i in range(M // 2)] + B[M // 2 :]
for a, b in zip(A, B):
print((a % N + 1, b % N + 1))
| N, M = list(map(int, input().split()))
if M & 1:
print((M, M + 1))
m = M // 2
for i in range(m):
print((i + 1, (-2 - i) % N + 1))
print((i + m + 1, 2 * M - m - i))
| false | 12.5 | [
"-A = list(range(M))",
"-B = list(range(M, 2 * M))[::-1]",
"-B = [-2 - i for i in range(M // 2)] + B[M // 2 :]",
"-for a, b in zip(A, B):",
"- print((a % N + 1, b % N + 1))",
"+if M & 1:",
"+ print((M, M + 1))",
"+m = M // 2",
"+for i in range(m):",
"+ print((i + 1, (-2 - i) % N + 1))",
"+ print((i + m + 1, 2 * M - m - i))"
] | false | 0.036368 | 0.039342 | 0.924407 | [
"s704718201",
"s963285974"
] |
u483005329 | p03030 | python | s527051469 | s723075273 | 19 | 17 | 3,064 | 3,064 | Accepted | Accepted | 10.53 | def irekae(array2):
return [array2[1],array2[0],array2[2]]
n=int(eval(input()))
l=[input().split() for i in range(n)]
"""
# print(l)
for i in range(len(l)):
l[i].append(i+1)
l[i][1]=int(l[i][1])
# print(l)
l.sort()
# print(l)
for i in range(len(l)):
l[i]=irekae(l[i])
# print(l)
lsort=[]
while l!=[]:
"""
for i in range(len(l)):
l[i].append(i+1)
l[i][1]=int(l[i][1])
for i in range(len(l)):
l[i]=irekae(l[i])
#print(l)
l.sort(reverse=True)
#print(l)
for i in range(len(l)):
l[i]=irekae(l[i])
#print(l)
lx=sorted(l,key=lambda x: x[0])
#print(lx)
for i in range(len(lx)):
print((lx[i][2])) | def irekae(array2):
return [array2[1],array2[0],array2[2]]
n=int(eval(input()))
l=[input().split() for i in range(n)]
for i in range(len(l)):
l[i].append(i+1)
l[i][1]=int(l[i][1])
for i in range(len(l)):
l[i]=irekae(l[i])
l.sort(reverse=True)
for i in range(len(l)):
l[i]=irekae(l[i])
lx=sorted(l,key=lambda x: x[0])
for i in range(len(lx)):
print((lx[i][2])) | 35 | 15 | 655 | 389 | def irekae(array2):
return [array2[1], array2[0], array2[2]]
n = int(eval(input()))
l = [input().split() for i in range(n)]
"""
# print(l)
for i in range(len(l)):
l[i].append(i+1)
l[i][1]=int(l[i][1])
# print(l)
l.sort()
# print(l)
for i in range(len(l)):
l[i]=irekae(l[i])
# print(l)
lsort=[]
while l!=[]:
"""
for i in range(len(l)):
l[i].append(i + 1)
l[i][1] = int(l[i][1])
for i in range(len(l)):
l[i] = irekae(l[i])
# print(l)
l.sort(reverse=True)
# print(l)
for i in range(len(l)):
l[i] = irekae(l[i])
# print(l)
lx = sorted(l, key=lambda x: x[0])
# print(lx)
for i in range(len(lx)):
print((lx[i][2]))
| def irekae(array2):
return [array2[1], array2[0], array2[2]]
n = int(eval(input()))
l = [input().split() for i in range(n)]
for i in range(len(l)):
l[i].append(i + 1)
l[i][1] = int(l[i][1])
for i in range(len(l)):
l[i] = irekae(l[i])
l.sort(reverse=True)
for i in range(len(l)):
l[i] = irekae(l[i])
lx = sorted(l, key=lambda x: x[0])
for i in range(len(lx)):
print((lx[i][2]))
| false | 57.142857 | [
"-\"\"\"",
"-# print(l)",
"-for i in range(len(l)):",
"- l[i].append(i+1)",
"- l[i][1]=int(l[i][1])",
"-# print(l)",
"-l.sort()",
"-# print(l)",
"-for i in range(len(l)):",
"- l[i]=irekae(l[i])",
"-# print(l)",
"-lsort=[]",
"-while l!=[]:",
"- \"\"\"",
"-# print(l)",
"-# print(l)",
"-# print(l)",
"-# print(lx)"
] | false | 0.037459 | 0.03797 | 0.986544 | [
"s527051469",
"s723075273"
] |
u057109575 | p02630 | python | s275355833 | s266888674 | 370 | 332 | 105,912 | 107,624 | Accepted | Accepted | 10.27 | from collections import Counter
N = int(eval(input()))
A = list(map(int, input().split()))
Q = int(eval(input()))
X = [list(map(int, input().split())) for _ in range(Q)]
ctr = Counter(A)
ans = sum(A)
for b, c in X:
v = ctr[b]
ans = ans - b * v + c * v
ctr[b] -= v
ctr[c] += v
print(ans)
|
from collections import Counter
N = int(eval(input()))
X = list(map(int, input().split()))
Q = int(eval(input()))
Y = [list(map(int, input().split())) for _ in range(Q)]
ctr = Counter(X)
ans = sum(X)
for b, c in Y:
n = ctr[b]
ctr[b] = 0
ctr[c] += n
ans = ans - b * n + c * n
print(ans)
| 15 | 16 | 311 | 312 | from collections import Counter
N = int(eval(input()))
A = list(map(int, input().split()))
Q = int(eval(input()))
X = [list(map(int, input().split())) for _ in range(Q)]
ctr = Counter(A)
ans = sum(A)
for b, c in X:
v = ctr[b]
ans = ans - b * v + c * v
ctr[b] -= v
ctr[c] += v
print(ans)
| from collections import Counter
N = int(eval(input()))
X = list(map(int, input().split()))
Q = int(eval(input()))
Y = [list(map(int, input().split())) for _ in range(Q)]
ctr = Counter(X)
ans = sum(X)
for b, c in Y:
n = ctr[b]
ctr[b] = 0
ctr[c] += n
ans = ans - b * n + c * n
print(ans)
| false | 6.25 | [
"-A = list(map(int, input().split()))",
"+X = list(map(int, input().split()))",
"-X = [list(map(int, input().split())) for _ in range(Q)]",
"-ctr = Counter(A)",
"-ans = sum(A)",
"-for b, c in X:",
"- v = ctr[b]",
"- ans = ans - b * v + c * v",
"- ctr[b] -= v",
"- ctr[c] += v",
"+Y = [list(map(int, input().split())) for _ in range(Q)]",
"+ctr = Counter(X)",
"+ans = sum(X)",
"+for b, c in Y:",
"+ n = ctr[b]",
"+ ctr[b] = 0",
"+ ctr[c] += n",
"+ ans = ans - b * n + c * n"
] | false | 0.051262 | 0.0723 | 0.709025 | [
"s275355833",
"s266888674"
] |
u729133443 | p03177 | python | s802565247 | s590296334 | 1,876 | 1,478 | 75,740 | 15,824 | Accepted | Accepted | 21.22 | M=10**9+7
(n,k),*a=[list(map(int,t.split()))for t in open(0)]
r=a if k&1else[[i==j for j in range(n)]for i in range(n)]
d=a
for i in range(1,k.bit_length()):
p=[]
for y in d:
q=[0]*n
for x,s in zip(y,d):
for j,t in enumerate(s):
q[j]+=t*x%M
p+=q,
d=p
if 1<<i&k:
p=[]
for y in r:
q=[0]*n
for x,s in zip(y,d):
for j,t in enumerate(s):
q[j]+=t*x%M
p+=q,
r=p
print((sum(t for s in r for t in s)%M)) | from numpy import*
(n,k),*a=[list(map(int,t.split()))for t in open(0)]
a=matrix(a,'O')
M=10**9+7
s=1
while k:s*=~k%2or a;k//=2;a=a*a%M
print((sum(s)%M)) | 23 | 7 | 496 | 156 | M = 10**9 + 7
(n, k), *a = [list(map(int, t.split())) for t in open(0)]
r = a if k & 1 else [[i == j for j in range(n)] for i in range(n)]
d = a
for i in range(1, k.bit_length()):
p = []
for y in d:
q = [0] * n
for x, s in zip(y, d):
for j, t in enumerate(s):
q[j] += t * x % M
p += (q,)
d = p
if 1 << i & k:
p = []
for y in r:
q = [0] * n
for x, s in zip(y, d):
for j, t in enumerate(s):
q[j] += t * x % M
p += (q,)
r = p
print((sum(t for s in r for t in s) % M))
| from numpy import *
(n, k), *a = [list(map(int, t.split())) for t in open(0)]
a = matrix(a, "O")
M = 10**9 + 7
s = 1
while k:
s *= ~k % 2 or a
k //= 2
a = a * a % M
print((sum(s) % M))
| false | 69.565217 | [
"+from numpy import *",
"+",
"+(n, k), *a = [list(map(int, t.split())) for t in open(0)]",
"+a = matrix(a, \"O\")",
"-(n, k), *a = [list(map(int, t.split())) for t in open(0)]",
"-r = a if k & 1 else [[i == j for j in range(n)] for i in range(n)]",
"-d = a",
"-for i in range(1, k.bit_length()):",
"- p = []",
"- for y in d:",
"- q = [0] * n",
"- for x, s in zip(y, d):",
"- for j, t in enumerate(s):",
"- q[j] += t * x % M",
"- p += (q,)",
"- d = p",
"- if 1 << i & k:",
"- p = []",
"- for y in r:",
"- q = [0] * n",
"- for x, s in zip(y, d):",
"- for j, t in enumerate(s):",
"- q[j] += t * x % M",
"- p += (q,)",
"- r = p",
"-print((sum(t for s in r for t in s) % M))",
"+s = 1",
"+while k:",
"+ s *= ~k % 2 or a",
"+ k //= 2",
"+ a = a * a % M",
"+print((sum(s) % M))"
] | false | 0.119903 | 0.776747 | 0.154366 | [
"s802565247",
"s590296334"
] |
u536034761 | p02888 | python | s556362577 | s934221473 | 1,106 | 983 | 9,492 | 9,372 | Accepted | Accepted | 11.12 | import bisect
from copy import deepcopy
N = int(eval(input()))
L = sorted(map(int, input().split()))
ans = 0
for i in range(N):
for j in range(i + 1, N - 1):
b = L[j] + L[i]
x = bisect.bisect_left(L, b) - j - 1
if x > 0:
ans += x
print(ans)
| import bisect
n = int(eval(input()))
L = sorted(map(int, input().split()))
m = L[-1]
ans = 0
for i in range(n):
for j in range(i + 1, n):
k = L[i] + L[j]
ans += bisect.bisect_left(L, k) - j-1
print(ans)
| 14 | 10 | 290 | 226 | import bisect
from copy import deepcopy
N = int(eval(input()))
L = sorted(map(int, input().split()))
ans = 0
for i in range(N):
for j in range(i + 1, N - 1):
b = L[j] + L[i]
x = bisect.bisect_left(L, b) - j - 1
if x > 0:
ans += x
print(ans)
| import bisect
n = int(eval(input()))
L = sorted(map(int, input().split()))
m = L[-1]
ans = 0
for i in range(n):
for j in range(i + 1, n):
k = L[i] + L[j]
ans += bisect.bisect_left(L, k) - j - 1
print(ans)
| false | 28.571429 | [
"-from copy import deepcopy",
"-N = int(eval(input()))",
"+n = int(eval(input()))",
"+m = L[-1]",
"-for i in range(N):",
"- for j in range(i + 1, N - 1):",
"- b = L[j] + L[i]",
"- x = bisect.bisect_left(L, b) - j - 1",
"- if x > 0:",
"- ans += x",
"+for i in range(n):",
"+ for j in range(i + 1, n):",
"+ k = L[i] + L[j]",
"+ ans += bisect.bisect_left(L, k) - j - 1"
] | false | 0.081291 | 0.065214 | 1.246528 | [
"s556362577",
"s934221473"
] |
u581187895 | p02971 | python | s463925439 | s437235747 | 568 | 519 | 14,112 | 15,748 | Accepted | Accepted | 8.63 | N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
B = sorted(A)
for i in range(N):
if A[i] == B[-1]:
print((B[-2]))
else:
print((B[-1])) | N = int(input())
A = [int(input()) for _ in range(N)]
second, first = sorted(A)[-2:]
ans = [second if a==first else first for a in A]
[print(a) for a in ans]
| 9 | 6 | 157 | 163 | N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
B = sorted(A)
for i in range(N):
if A[i] == B[-1]:
print((B[-2]))
else:
print((B[-1]))
| N = int(input())
A = [int(input()) for _ in range(N)]
second, first = sorted(A)[-2:]
ans = [second if a == first else first for a in A]
[print(a) for a in ans]
| false | 33.333333 | [
"-N = int(eval(input()))",
"-A = [int(eval(input())) for _ in range(N)]",
"-B = sorted(A)",
"-for i in range(N):",
"- if A[i] == B[-1]:",
"- print((B[-2]))",
"- else:",
"- print((B[-1]))",
"+N = int(input())",
"+A = [int(input()) for _ in range(N)]",
"+second, first = sorted(A)[-2:]",
"+ans = [second if a == first else first for a in A]",
"+[print(a) for a in ans]"
] | false | 0.068891 | 0.056334 | 1.222908 | [
"s463925439",
"s437235747"
] |
u334712262 | p02834 | python | s951807363 | s666617601 | 630 | 329 | 119,768 | 141,560 | Accepted | Accepted | 47.78 | # -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub
sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1
def read_int():
return int(input())
def read_int_n():
return list(map(int, input().split()))
def read_float():
return float(input())
def read_float_n():
return list(map(float, input().split()))
def read_str():
return input().strip()
def read_str_n():
return list(map(str, input().split()))
def error_print(*args):
print(*args, file=sys.stderr)
def mt(f):
import time
def wrap(*args, **kwargs):
s = time.time()
ret = f(*args, **kwargs)
e = time.time()
error_print(e - s, 'sec')
return ret
return wrap
@mt
def slv(N, u, v, AB):
ans = 0
g = defaultdict(set)
for a, b in AB:
g[a].add(b)
g[b].add(a)
def f(start):
s = [(start, 0)]
d = {}
d[start] = 0
while s:
c, l = s.pop()
for n in g[c]:
if n not in d:
s.append((n, l+1))
d[n] = l+1
return d
vd = f(v)
t = u
a = v
s = [(t, 0)]
d = {}
d[t] = 0
while s:
u, l = s.pop()
for v in g[u]:
if v not in d and l + 1 < vd[v]:
s.append((v, l+1))
tmp = vd[v] - (l+1)
tmp = (tmp//2) * 2
d[v] = tmp + (l+1)
d[t] = (vd[t] // 2) * 2
dest = (0, -1)
for k, v in d.items():
dest = max(dest, (v, k))
ans = dest[0]
# error_print(dest)
# error_print(d)
# error_print(vd)
if vd[dest[1]] == dest[0]:
ans -= 1
return ans
def main():
N, u, v = read_int_n()
AB = [read_int_n() for _ in range(N-1)]
print(slv(N, u, v, AB))
if __name__ == '__main__':
main()
| # -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from fractions import Fraction
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations, accumulate
from operator import add, mul, sub, itemgetter, attrgetter
import sys
# sys.setrecursionlimit(10**6)
# readline = sys.stdin.buffer.readline
readline = sys.stdin.readline
INF = 2**62-1
def read_int():
return int(readline())
def read_int_n():
return list(map(int, readline().split()))
def read_float():
return float(readline())
def read_float_n():
return list(map(float, readline().split()))
def read_str():
return readline().strip()
def read_str_n():
return readline().strip().split()
def ep(*args):
print(*args, file=sys.stderr)
def mt(f):
import time
def wrap(*args, **kwargs):
s = time.perf_counter()
ret = f(*args, **kwargs)
e = time.perf_counter()
ep(e - s, 'sec')
return ret
return wrap
@mt
def slv(N, U, V, AB):
g = defaultdict(list)
for a, b in AB:
g[a].append(b)
g[b].append(a)
s = [U]
prev = {}
prev[U] = -1
while s:
u = s.pop()
for v in g[u]:
if v in prev:
continue
prev[v] = u
s.append(v)
p = [V]
v = V
while v != U:
v = prev[v]
p.append(v)
p.reverse()
nu = p[len(p)//2-1]
ans = len(p)//2-1
if len(p) % 2 == 1:
ans += 1
done = set(p[len(p)//2-1:])
d = {nu: 0}
s = [nu]
while s:
u = s.pop()
for v in g[u]:
if v in done:
continue
d[v] = d[u] + 1
done.add(u)
s.append(v)
return ans + max(d.values())
def main():
N, U, V = read_int_n()
AB = [read_int_n() for _ in range(N-1)]
print(slv(N, U, V, AB))
if __name__ == '__main__':
main()
| 116 | 119 | 2,273 | 2,210 | # -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub
sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62 - 1
def read_int():
return int(input())
def read_int_n():
return list(map(int, input().split()))
def read_float():
return float(input())
def read_float_n():
return list(map(float, input().split()))
def read_str():
return input().strip()
def read_str_n():
return list(map(str, input().split()))
def error_print(*args):
print(*args, file=sys.stderr)
def mt(f):
import time
def wrap(*args, **kwargs):
s = time.time()
ret = f(*args, **kwargs)
e = time.time()
error_print(e - s, "sec")
return ret
return wrap
@mt
def slv(N, u, v, AB):
ans = 0
g = defaultdict(set)
for a, b in AB:
g[a].add(b)
g[b].add(a)
def f(start):
s = [(start, 0)]
d = {}
d[start] = 0
while s:
c, l = s.pop()
for n in g[c]:
if n not in d:
s.append((n, l + 1))
d[n] = l + 1
return d
vd = f(v)
t = u
a = v
s = [(t, 0)]
d = {}
d[t] = 0
while s:
u, l = s.pop()
for v in g[u]:
if v not in d and l + 1 < vd[v]:
s.append((v, l + 1))
tmp = vd[v] - (l + 1)
tmp = (tmp // 2) * 2
d[v] = tmp + (l + 1)
d[t] = (vd[t] // 2) * 2
dest = (0, -1)
for k, v in d.items():
dest = max(dest, (v, k))
ans = dest[0]
# error_print(dest)
# error_print(d)
# error_print(vd)
if vd[dest[1]] == dest[0]:
ans -= 1
return ans
def main():
N, u, v = read_int_n()
AB = [read_int_n() for _ in range(N - 1)]
print(slv(N, u, v, AB))
if __name__ == "__main__":
main()
| # -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from fractions import Fraction
from functools import lru_cache, reduce
from itertools import (
combinations,
combinations_with_replacement,
product,
permutations,
accumulate,
)
from operator import add, mul, sub, itemgetter, attrgetter
import sys
# sys.setrecursionlimit(10**6)
# readline = sys.stdin.buffer.readline
readline = sys.stdin.readline
INF = 2**62 - 1
def read_int():
return int(readline())
def read_int_n():
return list(map(int, readline().split()))
def read_float():
return float(readline())
def read_float_n():
return list(map(float, readline().split()))
def read_str():
return readline().strip()
def read_str_n():
return readline().strip().split()
def ep(*args):
print(*args, file=sys.stderr)
def mt(f):
import time
def wrap(*args, **kwargs):
s = time.perf_counter()
ret = f(*args, **kwargs)
e = time.perf_counter()
ep(e - s, "sec")
return ret
return wrap
@mt
def slv(N, U, V, AB):
g = defaultdict(list)
for a, b in AB:
g[a].append(b)
g[b].append(a)
s = [U]
prev = {}
prev[U] = -1
while s:
u = s.pop()
for v in g[u]:
if v in prev:
continue
prev[v] = u
s.append(v)
p = [V]
v = V
while v != U:
v = prev[v]
p.append(v)
p.reverse()
nu = p[len(p) // 2 - 1]
ans = len(p) // 2 - 1
if len(p) % 2 == 1:
ans += 1
done = set(p[len(p) // 2 - 1 :])
d = {nu: 0}
s = [nu]
while s:
u = s.pop()
for v in g[u]:
if v in done:
continue
d[v] = d[u] + 1
done.add(u)
s.append(v)
return ans + max(d.values())
def main():
N, U, V = read_int_n()
AB = [read_int_n() for _ in range(N - 1)]
print(slv(N, U, V, AB))
if __name__ == "__main__":
main()
| false | 2.521008 | [
"-import sys",
"+from fractions import Fraction",
"-from itertools import combinations, combinations_with_replacement, product, permutations",
"-from operator import add, mul, sub",
"+from itertools import (",
"+ combinations,",
"+ combinations_with_replacement,",
"+ product,",
"+ permutations,",
"+ accumulate,",
"+)",
"+from operator import add, mul, sub, itemgetter, attrgetter",
"+import sys",
"-sys.setrecursionlimit(100000)",
"-input = sys.stdin.readline",
"+# sys.setrecursionlimit(10**6)",
"+# readline = sys.stdin.buffer.readline",
"+readline = sys.stdin.readline",
"- return int(input())",
"+ return int(readline())",
"- return list(map(int, input().split()))",
"+ return list(map(int, readline().split()))",
"- return float(input())",
"+ return float(readline())",
"- return list(map(float, input().split()))",
"+ return list(map(float, readline().split()))",
"- return input().strip()",
"+ return readline().strip()",
"- return list(map(str, input().split()))",
"+ return readline().strip().split()",
"-def error_print(*args):",
"+def ep(*args):",
"- s = time.time()",
"+ s = time.perf_counter()",
"- e = time.time()",
"- error_print(e - s, \"sec\")",
"+ e = time.perf_counter()",
"+ ep(e - s, \"sec\")",
"-def slv(N, u, v, AB):",
"- ans = 0",
"- g = defaultdict(set)",
"+def slv(N, U, V, AB):",
"+ g = defaultdict(list)",
"- g[a].add(b)",
"- g[b].add(a)",
"-",
"- def f(start):",
"- s = [(start, 0)]",
"- d = {}",
"- d[start] = 0",
"- while s:",
"- c, l = s.pop()",
"- for n in g[c]:",
"- if n not in d:",
"- s.append((n, l + 1))",
"- d[n] = l + 1",
"- return d",
"-",
"- vd = f(v)",
"- t = u",
"- a = v",
"- s = [(t, 0)]",
"- d = {}",
"- d[t] = 0",
"+ g[a].append(b)",
"+ g[b].append(a)",
"+ s = [U]",
"+ prev = {}",
"+ prev[U] = -1",
"- u, l = s.pop()",
"+ u = s.pop()",
"- if v not in d and l + 1 < vd[v]:",
"- s.append((v, l + 1))",
"- tmp = vd[v] - (l + 1)",
"- tmp = (tmp // 2) * 2",
"- d[v] = tmp + (l + 1)",
"- d[t] = (vd[t] // 2) * 2",
"- dest = (0, -1)",
"- for k, v in d.items():",
"- dest = max(dest, (v, k))",
"- ans = dest[0]",
"- # error_print(dest)",
"- # error_print(d)",
"- # error_print(vd)",
"- if vd[dest[1]] == dest[0]:",
"- ans -= 1",
"- return ans",
"+ if v in prev:",
"+ continue",
"+ prev[v] = u",
"+ s.append(v)",
"+ p = [V]",
"+ v = V",
"+ while v != U:",
"+ v = prev[v]",
"+ p.append(v)",
"+ p.reverse()",
"+ nu = p[len(p) // 2 - 1]",
"+ ans = len(p) // 2 - 1",
"+ if len(p) % 2 == 1:",
"+ ans += 1",
"+ done = set(p[len(p) // 2 - 1 :])",
"+ d = {nu: 0}",
"+ s = [nu]",
"+ while s:",
"+ u = s.pop()",
"+ for v in g[u]:",
"+ if v in done:",
"+ continue",
"+ d[v] = d[u] + 1",
"+ done.add(u)",
"+ s.append(v)",
"+ return ans + max(d.values())",
"- N, u, v = read_int_n()",
"+ N, U, V = read_int_n()",
"- print(slv(N, u, v, AB))",
"+ print(slv(N, U, V, AB))"
] | false | 0.068736 | 0.063741 | 1.078363 | [
"s951807363",
"s666617601"
] |
u588341295 | p03608 | python | s358033743 | s892886977 | 570 | 438 | 73,304 | 54,236 | Accepted | Accepted | 23.16 | # -*- coding: utf-8 -*-
from itertools import permutations
N, M, R = list(map(int, input().split()))
r = list(map(int, input().split()))
G = [[float('inf')] * (N) for _ in range(N)]
for i in range(M):
a, b, c = list(map(int, input().split()))
# 経路情報は隣接行列に保持する(無向グラフなので両方向)
G[a-1][b-1] = c
G[b-1][a-1] = c
# ワーシャルフロイドで全頂点の最短距離
for k in range(N):
for i in range(N):
for j in range(N):
# 始点 = 終点、は例外的に距離0にしておく
if i == j:
G[i][j] = 0
else:
G[i][j] = min(G[i][j], G[i][k] + G[k][j])
ans = float('inf')
# 町の順番は順列全部試す(最大8なら大丈夫)
for p in permutations(r):
sm = 0
# 最短経路を足し合わせていく
for i in range(1, len(p)):
sm += G[p[i-1]-1][p[i]-1]
ans = min(sm, ans)
print(ans)
| # -*- coding: utf-8 -*-
import sys
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def warshall_floyd(N: int, graph: list) -> list:
""" ワーシャルフロイド(頂点数, 隣接行列(0-indexed)) """
from copy import deepcopy
res = deepcopy(graph)
for i in range(N):
# 始点 = 終点、は予め距離0にしておく
res[i][i] = 0
# 全頂点の最短距離
for k in range(N):
for i in range(N):
for j in range(N):
res[i][j] = min(res[i][j], res[i][k] + res[k][j])
# 負の閉路(いくらでもコストを減らせてしまう場所)がないかチェックする
for i in range(N):
if res[i][i] < 0:
return []
return res
N, M, R = MAP()
A = [a-1 for a in LIST()]
G = list2d(N, N, INF)
for i in range(M):
a, b, c = MAP()
a -= 1; b -= 1
G[a][b] = c
G[b][a] = c
# 全体グラフの最短距離(ここから必要な頂点間だけ使う)
wf = warshall_floyd(N, G)
ans = INF
for r in range(R):
# TSP(巡回セールスマン)
dp = list2d(1<<R, R, INF)
dp[1<<r][r] = 0
for bit in range(1, (1<<R)-1):
for i in range(R):
if not (bit >> i & 1):
continue
for j in range(R):
if bit >> j & 1:
continue
a, b = A[i], A[j]
dp[bit|1<<j][j] = min(dp[bit|1<<j][j], dp[bit][i] + wf[a][b])
ans = min(ans, min(dp[-1]))
print(ans)
| 32 | 67 | 796 | 1,938 | # -*- coding: utf-8 -*-
from itertools import permutations
N, M, R = list(map(int, input().split()))
r = list(map(int, input().split()))
G = [[float("inf")] * (N) for _ in range(N)]
for i in range(M):
a, b, c = list(map(int, input().split()))
# 経路情報は隣接行列に保持する(無向グラフなので両方向)
G[a - 1][b - 1] = c
G[b - 1][a - 1] = c
# ワーシャルフロイドで全頂点の最短距離
for k in range(N):
for i in range(N):
for j in range(N):
# 始点 = 終点、は例外的に距離0にしておく
if i == j:
G[i][j] = 0
else:
G[i][j] = min(G[i][j], G[i][k] + G[k][j])
ans = float("inf")
# 町の順番は順列全部試す(最大8なら大丈夫)
for p in permutations(r):
sm = 0
# 最短経路を足し合わせていく
for i in range(1, len(p)):
sm += G[p[i - 1] - 1][p[i] - 1]
ans = min(sm, ans)
print(ans)
| # -*- coding: utf-8 -*-
import sys
def input():
return sys.stdin.readline().strip()
def list2d(a, b, c):
return [[c] * b for i in range(a)]
def list3d(a, b, c, d):
return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e):
return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1):
return int(-(-x // y))
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST(N=None):
return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes():
print("Yes")
def No():
print("No")
def YES():
print("YES")
def NO():
print("NO")
sys.setrecursionlimit(10**9)
INF = 10**18
MOD = 10**9 + 7
def warshall_floyd(N: int, graph: list) -> list:
"""ワーシャルフロイド(頂点数, 隣接行列(0-indexed))"""
from copy import deepcopy
res = deepcopy(graph)
for i in range(N):
# 始点 = 終点、は予め距離0にしておく
res[i][i] = 0
# 全頂点の最短距離
for k in range(N):
for i in range(N):
for j in range(N):
res[i][j] = min(res[i][j], res[i][k] + res[k][j])
# 負の閉路(いくらでもコストを減らせてしまう場所)がないかチェックする
for i in range(N):
if res[i][i] < 0:
return []
return res
N, M, R = MAP()
A = [a - 1 for a in LIST()]
G = list2d(N, N, INF)
for i in range(M):
a, b, c = MAP()
a -= 1
b -= 1
G[a][b] = c
G[b][a] = c
# 全体グラフの最短距離(ここから必要な頂点間だけ使う)
wf = warshall_floyd(N, G)
ans = INF
for r in range(R):
# TSP(巡回セールスマン)
dp = list2d(1 << R, R, INF)
dp[1 << r][r] = 0
for bit in range(1, (1 << R) - 1):
for i in range(R):
if not (bit >> i & 1):
continue
for j in range(R):
if bit >> j & 1:
continue
a, b = A[i], A[j]
dp[bit | 1 << j][j] = min(dp[bit | 1 << j][j], dp[bit][i] + wf[a][b])
ans = min(ans, min(dp[-1]))
print(ans)
| false | 52.238806 | [
"-from itertools import permutations",
"+import sys",
"-N, M, R = list(map(int, input().split()))",
"-r = list(map(int, input().split()))",
"-G = [[float(\"inf\")] * (N) for _ in range(N)]",
"+",
"+def input():",
"+ return sys.stdin.readline().strip()",
"+",
"+",
"+def list2d(a, b, c):",
"+ return [[c] * b for i in range(a)]",
"+",
"+",
"+def list3d(a, b, c, d):",
"+ return [[[d] * c for j in range(b)] for i in range(a)]",
"+",
"+",
"+def list4d(a, b, c, d, e):",
"+ return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]",
"+",
"+",
"+def ceil(x, y=1):",
"+ return int(-(-x // y))",
"+",
"+",
"+def INT():",
"+ return int(eval(input()))",
"+",
"+",
"+def MAP():",
"+ return list(map(int, input().split()))",
"+",
"+",
"+def LIST(N=None):",
"+ return list(MAP()) if N is None else [INT() for i in range(N)]",
"+",
"+",
"+def Yes():",
"+ print(\"Yes\")",
"+",
"+",
"+def No():",
"+ print(\"No\")",
"+",
"+",
"+def YES():",
"+ print(\"YES\")",
"+",
"+",
"+def NO():",
"+ print(\"NO\")",
"+",
"+",
"+sys.setrecursionlimit(10**9)",
"+INF = 10**18",
"+MOD = 10**9 + 7",
"+",
"+",
"+def warshall_floyd(N: int, graph: list) -> list:",
"+ \"\"\"ワーシャルフロイド(頂点数, 隣接行列(0-indexed))\"\"\"",
"+ from copy import deepcopy",
"+",
"+ res = deepcopy(graph)",
"+ for i in range(N):",
"+ # 始点 = 終点、は予め距離0にしておく",
"+ res[i][i] = 0",
"+ # 全頂点の最短距離",
"+ for k in range(N):",
"+ for i in range(N):",
"+ for j in range(N):",
"+ res[i][j] = min(res[i][j], res[i][k] + res[k][j])",
"+ # 負の閉路(いくらでもコストを減らせてしまう場所)がないかチェックする",
"+ for i in range(N):",
"+ if res[i][i] < 0:",
"+ return []",
"+ return res",
"+",
"+",
"+N, M, R = MAP()",
"+A = [a - 1 for a in LIST()]",
"+G = list2d(N, N, INF)",
"- a, b, c = list(map(int, input().split()))",
"- # 経路情報は隣接行列に保持する(無向グラフなので両方向)",
"- G[a - 1][b - 1] = c",
"- G[b - 1][a - 1] = c",
"-# ワーシャルフロイドで全頂点の最短距離",
"-for k in range(N):",
"- for i in range(N):",
"- for j in range(N):",
"- # 始点 = 終点、は例外的に距離0にしておく",
"- if i == j:",
"- G[i][j] = 0",
"- else:",
"- G[i][j] = min(G[i][j], G[i][k] + G[k][j])",
"-ans = float(\"inf\")",
"-# 町の順番は順列全部試す(最大8なら大丈夫)",
"-for p in permutations(r):",
"- sm = 0",
"- # 最短経路を足し合わせていく",
"- for i in range(1, len(p)):",
"- sm += G[p[i - 1] - 1][p[i] - 1]",
"- ans = min(sm, ans)",
"+ a, b, c = MAP()",
"+ a -= 1",
"+ b -= 1",
"+ G[a][b] = c",
"+ G[b][a] = c",
"+# 全体グラフの最短距離(ここから必要な頂点間だけ使う)",
"+wf = warshall_floyd(N, G)",
"+ans = INF",
"+for r in range(R):",
"+ # TSP(巡回セールスマン)",
"+ dp = list2d(1 << R, R, INF)",
"+ dp[1 << r][r] = 0",
"+ for bit in range(1, (1 << R) - 1):",
"+ for i in range(R):",
"+ if not (bit >> i & 1):",
"+ continue",
"+ for j in range(R):",
"+ if bit >> j & 1:",
"+ continue",
"+ a, b = A[i], A[j]",
"+ dp[bit | 1 << j][j] = min(dp[bit | 1 << j][j], dp[bit][i] + wf[a][b])",
"+ ans = min(ans, min(dp[-1]))"
] | false | 0.036695 | 0.16204 | 0.226455 | [
"s358033743",
"s892886977"
] |
u864090097 | p02584 | python | s834653689 | s012566716 | 31 | 28 | 9,168 | 9,160 | Accepted | Accepted | 9.68 | X, K, D = list(map(int ,input().split()))
X = abs(X)
if X // D > K:
ans = X - K * D
else:
if X // D % 2 == K % 2:
ans = X % D
else:
ans = abs(X % D - D)
print(ans)
| X, K, D = list(map(int ,input().split()))
X = abs(X)
if X / D > K:
ans = X - K * D
else:
if X // D % 2 == K % 2:
ans = X % D
else:
ans = abs(X % D - D)
print(ans) | 11 | 11 | 197 | 195 | X, K, D = list(map(int, input().split()))
X = abs(X)
if X // D > K:
ans = X - K * D
else:
if X // D % 2 == K % 2:
ans = X % D
else:
ans = abs(X % D - D)
print(ans)
| X, K, D = list(map(int, input().split()))
X = abs(X)
if X / D > K:
ans = X - K * D
else:
if X // D % 2 == K % 2:
ans = X % D
else:
ans = abs(X % D - D)
print(ans)
| false | 0 | [
"-if X // D > K:",
"+if X / D > K:"
] | false | 0.087106 | 0.046983 | 1.853977 | [
"s834653689",
"s012566716"
] |
u811841526 | p02400 | python | s644205909 | s419125572 | 30 | 20 | 7,532 | 5,640 | Accepted | Accepted | 33.33 | from math import pi
r = float(eval(input()))
area = pi * r**2
circumference = 2 * pi * r
print((area, circumference)) | import math
r = float(eval(input()))
area = math.pi * r**2
diameter = 2 * math.pi * r
print((area, diameter))
| 5 | 9 | 114 | 115 | from math import pi
r = float(eval(input()))
area = pi * r**2
circumference = 2 * pi * r
print((area, circumference))
| import math
r = float(eval(input()))
area = math.pi * r**2
diameter = 2 * math.pi * r
print((area, diameter))
| false | 44.444444 | [
"-from math import pi",
"+import math",
"-area = pi * r**2",
"-circumference = 2 * pi * r",
"-print((area, circumference))",
"+area = math.pi * r**2",
"+diameter = 2 * math.pi * r",
"+print((area, diameter))"
] | false | 0.04163 | 0.046649 | 0.892395 | [
"s644205909",
"s419125572"
] |
u700929101 | p02860 | python | s953825437 | s846261993 | 19 | 17 | 3,060 | 3,060 | Accepted | Accepted | 10.53 | n = int(eval(input()))
s = str(eval(input()))
t = int(n/2)
s_1half = s[:t]
s_2half = s[t:]
if n % 2 == 1:
print("No")
elif s_1half == s_2half:
print("Yes")
elif s_1half != s_2half:
print("No") | n = int(eval(input()))
s = str(eval(input()))
t = int(n/2)
if n % 2 == 1:
print("No")
else:
for i in range(t):
if s[i] == s[i+t]:
continue
else:
print("No")
exit()
print("Yes") | 13 | 14 | 206 | 242 | n = int(eval(input()))
s = str(eval(input()))
t = int(n / 2)
s_1half = s[:t]
s_2half = s[t:]
if n % 2 == 1:
print("No")
elif s_1half == s_2half:
print("Yes")
elif s_1half != s_2half:
print("No")
| n = int(eval(input()))
s = str(eval(input()))
t = int(n / 2)
if n % 2 == 1:
print("No")
else:
for i in range(t):
if s[i] == s[i + t]:
continue
else:
print("No")
exit()
print("Yes")
| false | 7.142857 | [
"-s_1half = s[:t]",
"-s_2half = s[t:]",
"-elif s_1half == s_2half:",
"+else:",
"+ for i in range(t):",
"+ if s[i] == s[i + t]:",
"+ continue",
"+ else:",
"+ print(\"No\")",
"+ exit()",
"-elif s_1half != s_2half:",
"- print(\"No\")"
] | false | 0.039917 | 0.041204 | 0.968761 | [
"s953825437",
"s846261993"
] |
u800258529 | p03798 | python | s194214198 | s642830410 | 340 | 311 | 6,740 | 5,364 | Accepted | Accepted | 8.53 | n=int(input())
s=input()
for i in range(4):
a=[i%2,i//2]+[1]*n
for i in range(2,n+2):a[i]^=a[i-2]^a[i-1]^(s[(i-1)%n]=='o')
if a[:2]==a[-2:]:
for i in range(n):print('SW'[a[i]],end='')
exit()
print(-1)
| n=int(input());s=input()
for i in range(4):
a=[i%2,i//2];i=1
while i<=n:a.append(a[-2]^a[-1]^(s[i%n]=='x'));i+=1
if a[:2]==a[-2:]:
for i in range(n):print('SW'[a[i]],end='')
exit()
print(-1)
| 9 | 8 | 236 | 225 | n = int(input())
s = input()
for i in range(4):
a = [i % 2, i // 2] + [1] * n
for i in range(2, n + 2):
a[i] ^= a[i - 2] ^ a[i - 1] ^ (s[(i - 1) % n] == "o")
if a[:2] == a[-2:]:
for i in range(n):
print("SW"[a[i]], end="")
exit()
print(-1)
| n = int(input())
s = input()
for i in range(4):
a = [i % 2, i // 2]
i = 1
while i <= n:
a.append(a[-2] ^ a[-1] ^ (s[i % n] == "x"))
i += 1
if a[:2] == a[-2:]:
for i in range(n):
print("SW"[a[i]], end="")
exit()
print(-1)
| false | 11.111111 | [
"- a = [i % 2, i // 2] + [1] * n",
"- for i in range(2, n + 2):",
"- a[i] ^= a[i - 2] ^ a[i - 1] ^ (s[(i - 1) % n] == \"o\")",
"+ a = [i % 2, i // 2]",
"+ i = 1",
"+ while i <= n:",
"+ a.append(a[-2] ^ a[-1] ^ (s[i % n] == \"x\"))",
"+ i += 1"
] | false | 0.033079 | 0.033792 | 0.978901 | [
"s194214198",
"s642830410"
] |
u225388820 | p02558 | python | s898805304 | s942960987 | 991 | 711 | 88,472 | 80,228 | Accepted | Accepted | 28.25 | from typing import List
class DSU:
def __init__(self, n: int) -> None:
self._n = n
self.parent_or_size = [-1] * n
def merge(self, a: int, b: int) -> int:
assert 0 <= a <= self._n
assert 0 <= b <= self._n
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: int, b: int) -> bool:
assert 0 <= a <= self._n
assert 0 <= b <= self._n
return self.leader(a) == self.leader(b)
def leader(self, a: int) -> int:
assert 0 <= a < self._n
if self.parent_or_size[a] < 0:
return a
result = self.leader(self.parent_or_size[a])
self.parent_or_size[a] = result
return result
def size(self, a: int) -> int:
assert 0 <= a <= self._n
return -self.parent_or_size[self.leader(a)]
def groups(self) -> List[List[int]]:
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()))
uf = DSU(n)
for i in range(q):
t, u, v = list(map(int, input().split()))
if t:
print((int(uf.same(u, v))))
else:
uf.merge(u, v)
| from typing import List
class DSU:
def __init__(self, n: int) -> None:
self._n = n
self.parent_or_size = [-1] * n
def merge(self, a: int, b: int) -> int:
assert 0 <= a <= self._n
assert 0 <= b <= self._n
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: int, b: int) -> bool:
assert 0 <= a <= self._n
assert 0 <= b <= self._n
return self.leader(a) == self.leader(b)
def leader(self, a: int) -> int:
assert 0 <= a < self._n
if self.parent_or_size[a] < 0:
return a
while self.parent_or_size[a] >= 0:
a = self.parent_or_size[a]
return a
def size(self, a: int) -> int:
assert 0 <= a <= self._n
return -self.parent_or_size[self.leader(a)]
def groups(self) -> List[List[int]]:
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()))
uf = DSU(n)
for i in range(q):
t, u, v = list(map(int, input().split()))
if t:
print((int(uf.same(u, v))))
else:
uf.merge(u, v)
| 58 | 58 | 1,680 | 1,664 | from typing import List
class DSU:
def __init__(self, n: int) -> None:
self._n = n
self.parent_or_size = [-1] * n
def merge(self, a: int, b: int) -> int:
assert 0 <= a <= self._n
assert 0 <= b <= self._n
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: int, b: int) -> bool:
assert 0 <= a <= self._n
assert 0 <= b <= self._n
return self.leader(a) == self.leader(b)
def leader(self, a: int) -> int:
assert 0 <= a < self._n
if self.parent_or_size[a] < 0:
return a
result = self.leader(self.parent_or_size[a])
self.parent_or_size[a] = result
return result
def size(self, a: int) -> int:
assert 0 <= a <= self._n
return -self.parent_or_size[self.leader(a)]
def groups(self) -> List[List[int]]:
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()))
uf = DSU(n)
for i in range(q):
t, u, v = list(map(int, input().split()))
if t:
print((int(uf.same(u, v))))
else:
uf.merge(u, v)
| from typing import List
class DSU:
def __init__(self, n: int) -> None:
self._n = n
self.parent_or_size = [-1] * n
def merge(self, a: int, b: int) -> int:
assert 0 <= a <= self._n
assert 0 <= b <= self._n
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: int, b: int) -> bool:
assert 0 <= a <= self._n
assert 0 <= b <= self._n
return self.leader(a) == self.leader(b)
def leader(self, a: int) -> int:
assert 0 <= a < self._n
if self.parent_or_size[a] < 0:
return a
while self.parent_or_size[a] >= 0:
a = self.parent_or_size[a]
return a
def size(self, a: int) -> int:
assert 0 <= a <= self._n
return -self.parent_or_size[self.leader(a)]
def groups(self) -> List[List[int]]:
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()))
uf = DSU(n)
for i in range(q):
t, u, v = list(map(int, input().split()))
if t:
print((int(uf.same(u, v))))
else:
uf.merge(u, v)
| false | 0 | [
"- result = self.leader(self.parent_or_size[a])",
"- self.parent_or_size[a] = result",
"- return result",
"+ while self.parent_or_size[a] >= 0:",
"+ a = self.parent_or_size[a]",
"+ return a"
] | false | 0.041147 | 0.051247 | 0.802915 | [
"s898805304",
"s942960987"
] |
u083960235 | p03038 | python | s668091650 | s153417374 | 561 | 457 | 35,664 | 34,800 | Accepted | Accepted | 18.54 | import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop, heapify
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
def ZIP(n): return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
N, M = MAP()
A = LIST()
L = [LIST() for i in range(M)]
L = sorted(L, key=lambda x: x[1], reverse=True) # 0番目の要素でソート
default_sum = sum(A)
# A.sort()
heapify(A)
n = 0
for times, num in L:
cnt = 0
while cnt < times and len(A) != 0:
min_num = heappop(A)
default_sum += max(num - min_num, 0)
cnt += 1
print(default_sum)
| import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from heapq import heapify, heappop, heappush
from bisect import bisect_right
def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def S_MAP(): return list(map(str, input().split()))
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
N, M = MAP()
A = LIST()
L = [LIST() for i in range(M)]
dic = defaultdict(int)
# for a, b in L:
# dic[A[a]] = b
A.sort()
L = sorted(L, key=lambda x : x[1], reverse=True)
# print(L)
i = 0
# for i, a in enumerate(A):
for f, t in L:
while f > 0 and i < N:
if t > A[i]:
A[i] = t
f -= 1
i += 1
else:
print((sum(A)))
exit()
print((sum(A)))
| 42 | 45 | 1,162 | 1,223 | import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop, heapify
from functools import reduce
def input():
return sys.stdin.readline().strip()
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST():
return list(map(int, input().split()))
def ZIP(n):
return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
N, M = MAP()
A = LIST()
L = [LIST() for i in range(M)]
L = sorted(L, key=lambda x: x[1], reverse=True) # 0番目の要素でソート
default_sum = sum(A)
# A.sort()
heapify(A)
n = 0
for times, num in L:
cnt = 0
while cnt < times and len(A) != 0:
min_num = heappop(A)
default_sum += max(num - min_num, 0)
cnt += 1
print(default_sum)
| import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from heapq import heapify, heappop, heappush
from bisect import bisect_right
def input():
return sys.stdin.readline().strip()
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def S_MAP():
return list(map(str, input().split()))
def LIST():
return list(map(int, input().split()))
def S_LIST():
return list(map(str, input().split()))
sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
N, M = MAP()
A = LIST()
L = [LIST() for i in range(M)]
dic = defaultdict(int)
# for a, b in L:
# dic[A[a]] = b
A.sort()
L = sorted(L, key=lambda x: x[1], reverse=True)
# print(L)
i = 0
# for i, a in enumerate(A):
for f, t in L:
while f > 0 and i < N:
if t > A[i]:
A[i] = t
f -= 1
i += 1
else:
print((sum(A)))
exit()
print((sum(A)))
| false | 6.666667 | [
"-import sys, re",
"+import sys, re, os",
"-from itertools import accumulate, permutations, combinations, product",
"+from itertools import permutations, combinations, product, accumulate",
"-from bisect import bisect, bisect_left",
"-from fractions import gcd",
"-from heapq import heappush, heappop, heapify",
"-from functools import reduce",
"+from heapq import heapify, heappop, heappush",
"+from bisect import bisect_right",
"+def S_MAP():",
"+ return list(map(str, input().split()))",
"+",
"+",
"-def ZIP(n):",
"- return list(zip(*(MAP() for _ in range(n))))",
"+def S_LIST():",
"+ return list(map(str, input().split()))",
"-L = sorted(L, key=lambda x: x[1], reverse=True) # 0番目の要素でソート",
"-default_sum = sum(A)",
"-# A.sort()",
"-heapify(A)",
"-n = 0",
"-for times, num in L:",
"- cnt = 0",
"- while cnt < times and len(A) != 0:",
"- min_num = heappop(A)",
"- default_sum += max(num - min_num, 0)",
"- cnt += 1",
"-print(default_sum)",
"+dic = defaultdict(int)",
"+# for a, b in L:",
"+# dic[A[a]] = b",
"+A.sort()",
"+L = sorted(L, key=lambda x: x[1], reverse=True)",
"+# print(L)",
"+i = 0",
"+# for i, a in enumerate(A):",
"+for f, t in L:",
"+ while f > 0 and i < N:",
"+ if t > A[i]:",
"+ A[i] = t",
"+ f -= 1",
"+ i += 1",
"+ else:",
"+ print((sum(A)))",
"+ exit()",
"+print((sum(A)))"
] | false | 0.09069 | 0.078408 | 1.156648 | [
"s668091650",
"s153417374"
] |
u951401193 | p02845 | python | s316340544 | s295907882 | 153 | 81 | 10,644 | 13,980 | Accepted | Accepted | 47.06 | N=int(eval(input()))
A=list(map(int,input().split()))
m=10**9+7
r=1
C=[0,0,0]
for a in A:
try:
i=C.index(a)
r=r*sum([1 if c==a else 0 for c in C])%m
C[i]+=1
except:
print((0))
exit()
print(r)
| n , *a_s = list(map(int,open(0).read().split()))
tmp = [3] + [0 for _ in range(n+1)]
ans = 1
for a in a_s:
ans = ans * tmp[a] % 1000000007
tmp[a] -= 1
tmp[a+1] += 1
print(ans) | 14 | 9 | 239 | 186 | N = int(eval(input()))
A = list(map(int, input().split()))
m = 10**9 + 7
r = 1
C = [0, 0, 0]
for a in A:
try:
i = C.index(a)
r = r * sum([1 if c == a else 0 for c in C]) % m
C[i] += 1
except:
print((0))
exit()
print(r)
| n, *a_s = list(map(int, open(0).read().split()))
tmp = [3] + [0 for _ in range(n + 1)]
ans = 1
for a in a_s:
ans = ans * tmp[a] % 1000000007
tmp[a] -= 1
tmp[a + 1] += 1
print(ans)
| false | 35.714286 | [
"-N = int(eval(input()))",
"-A = list(map(int, input().split()))",
"-m = 10**9 + 7",
"-r = 1",
"-C = [0, 0, 0]",
"-for a in A:",
"- try:",
"- i = C.index(a)",
"- r = r * sum([1 if c == a else 0 for c in C]) % m",
"- C[i] += 1",
"- except:",
"- print((0))",
"- exit()",
"-print(r)",
"+n, *a_s = list(map(int, open(0).read().split()))",
"+tmp = [3] + [0 for _ in range(n + 1)]",
"+ans = 1",
"+for a in a_s:",
"+ ans = ans * tmp[a] % 1000000007",
"+ tmp[a] -= 1",
"+ tmp[a + 1] += 1",
"+print(ans)"
] | false | 0.03327 | 0.041297 | 0.805612 | [
"s316340544",
"s295907882"
] |
u083960235 | p03103 | python | s670852251 | s296019224 | 522 | 412 | 26,888 | 28,600 | Accepted | Accepted | 21.07 | n,m=list(map(int,input().split()))
a=[]
b=[]
c=[]
for i in range(n):
A,B=list(map(int,input().split()))
a.append(A)
b.append(B)
c=list(zip(a,b))
c.sort()
a,b=list(zip(*c))
a=list(a)
b=list(b)
#sprint(a,b)
M=m
for i in range(n):
if m>=0:
m=m-b[i]
#print(i)
I=i
else:
b[i]=0
#print(b)
b[I]=b[I]-(sum(b)-M)
#print(b)
ans=0
for i in range(n):
ans+=a[i]*b[i]
print(ans)
| import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from heapq import heapify, heappop, heappush
def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def S_MAP(): return list(map(str, input().split()))
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
N, M = MAP()
L = [LIST() for i in range(N)]
L.sort()
ans = 0
i = 0
while M > 0:
A, B = L[i]
if B <= M:
ans += A * B
M -= B
else:
ans += M * A
M = 0
i += 1
print(ans)
| 33 | 37 | 439 | 976 | n, m = list(map(int, input().split()))
a = []
b = []
c = []
for i in range(n):
A, B = list(map(int, input().split()))
a.append(A)
b.append(B)
c = list(zip(a, b))
c.sort()
a, b = list(zip(*c))
a = list(a)
b = list(b)
# sprint(a,b)
M = m
for i in range(n):
if m >= 0:
m = m - b[i]
# print(i)
I = i
else:
b[i] = 0
# print(b)
b[I] = b[I] - (sum(b) - M)
# print(b)
ans = 0
for i in range(n):
ans += a[i] * b[i]
print(ans)
| import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from heapq import heapify, heappop, heappush
def input():
return sys.stdin.readline().strip()
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def S_MAP():
return list(map(str, input().split()))
def LIST():
return list(map(int, input().split()))
def S_LIST():
return list(map(str, input().split()))
sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
N, M = MAP()
L = [LIST() for i in range(N)]
L.sort()
ans = 0
i = 0
while M > 0:
A, B = L[i]
if B <= M:
ans += A * B
M -= B
else:
ans += M * A
M = 0
i += 1
print(ans)
| false | 10.810811 | [
"-n, m = list(map(int, input().split()))",
"-a = []",
"-b = []",
"-c = []",
"-for i in range(n):",
"- A, B = list(map(int, input().split()))",
"- a.append(A)",
"- b.append(B)",
"-c = list(zip(a, b))",
"-c.sort()",
"-a, b = list(zip(*c))",
"-a = list(a)",
"-b = list(b)",
"-# sprint(a,b)",
"-M = m",
"-for i in range(n):",
"- if m >= 0:",
"- m = m - b[i]",
"- # print(i)",
"- I = i",
"+import sys, re, os",
"+from collections import deque, defaultdict, Counter",
"+from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians",
"+from itertools import permutations, combinations, product, accumulate",
"+from operator import itemgetter, mul",
"+from copy import deepcopy",
"+from string import ascii_lowercase, ascii_uppercase, digits",
"+from heapq import heapify, heappop, heappush",
"+",
"+",
"+def input():",
"+ return sys.stdin.readline().strip()",
"+",
"+",
"+def INT():",
"+ return int(eval(input()))",
"+",
"+",
"+def MAP():",
"+ return list(map(int, input().split()))",
"+",
"+",
"+def S_MAP():",
"+ return list(map(str, input().split()))",
"+",
"+",
"+def LIST():",
"+ return list(map(int, input().split()))",
"+",
"+",
"+def S_LIST():",
"+ return list(map(str, input().split()))",
"+",
"+",
"+sys.setrecursionlimit(10**9)",
"+INF = float(\"inf\")",
"+mod = 10**9 + 7",
"+N, M = MAP()",
"+L = [LIST() for i in range(N)]",
"+L.sort()",
"+ans = 0",
"+i = 0",
"+while M > 0:",
"+ A, B = L[i]",
"+ if B <= M:",
"+ ans += A * B",
"+ M -= B",
"- b[i] = 0",
"-# print(b)",
"-b[I] = b[I] - (sum(b) - M)",
"-# print(b)",
"-ans = 0",
"-for i in range(n):",
"- ans += a[i] * b[i]",
"+ ans += M * A",
"+ M = 0",
"+ i += 1"
] | false | 0.087941 | 0.045204 | 1.9454 | [
"s670852251",
"s296019224"
] |
u102461423 | p02680 | python | s081697181 | s487305861 | 1,321 | 784 | 180,808 | 165,764 | Accepted | Accepted | 40.65 | import sys
import numpy as np
from numba import njit
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
INF = 10**9 + 1
def precompute(N, M, data):
data = data.reshape(-1, 3)
A, B, C = data[:N].T
D, E, F = data[N:].T
X = np.unique(np.concatenate([A, B, D, [0, -INF, INF]]))
Y = np.unique(np.concatenate([C, E, F, [0, -INF, INF]]))
DX, DY = np.diff(X), np.diff(Y)
A = np.searchsorted(X, A)
B = np.searchsorted(X, B)
D = np.searchsorted(X, D)
C = np.searchsorted(Y, C)
E = np.searchsorted(Y, E)
F = np.searchsorted(Y, F)
return A, B, C, D, E, F, X, Y, DX, DY
@njit(cache=True)
def set_ng(A, B, C, D, E, F, H, W):
ng = np.zeros((H * W, 4), np.bool_)
for i in range(len(A)):
for x in range(A[i], B[i]):
v = x * W + C[i]
ng[v][1] = 1
ng[v - 1][0] = 1
for i in range(len(D)):
for y in range(E[i], F[i]):
v = D[i] * W + y
ng[v][3] = 1
ng[v - W][2] = 1
return ng
@njit(cache=True)
def solve(A, B, C, D, E, F, X, Y, DX, DY):
H, W = len(X), len(Y)
N = H * W
ng = set_ng(A, B, C, D, E, F, H, W)
x0, y0 = np.searchsorted(X, 0), np.searchsorted(Y, 0)
v0 = x0 * W + y0
visited = np.zeros(N, np.bool_)
visited[v0] = 1
stack = np.empty(N, np.int32)
p = 0
ret = 0
def area(x):
x, y = divmod(x, W)
return DX[x] * DY[y]
def push(x):
nonlocal p, ret
stack[p] = x
visited[x] = 1
ret += area(x)
p += 1
def pop():
nonlocal p
p -= 1
return stack[p]
push(v0)
move = (1, -1, W, -W)
while p:
v = pop()
for i in range(4):
if ng[v][i]:
continue
w = v + move[i]
if visited[w]:
continue
x, y = divmod(w, W)
if x == 0 or x == H - 1 or y == 0 or y == W - 1:
return 0
push(w)
return ret
N, M = list(map(int, readline().split()))
data = np.int64(read().split())
x = solve(*precompute(N, M, data))
if x == 0:
print('INF')
else:
print(x) | import sys
import numpy as np
from numba import njit
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
INF = 10**9 + 1
def precompute(N, M, data):
data = data.reshape(-1, 3)
A, B, C = data[:N].T
D, E, F = data[N:].T
X = np.unique(np.concatenate([A, B, D, [0, -INF, INF]]))
Y = np.unique(np.concatenate([C, E, F, [0, -INF, INF]]))
A = np.searchsorted(X, A)
B = np.searchsorted(X, B)
D = np.searchsorted(X, D)
C = np.searchsorted(Y, C)
E = np.searchsorted(Y, E)
F = np.searchsorted(Y, F)
return A, B, C, D, E, F, X, Y
@njit('(i8[:],i8[:],i8[:],i8[:],i8[:],i8[:],i8,i8)', cache=True)
def set_ng(A, B, C, D, E, F, H, W):
ng = np.zeros((H * W, 4), np.bool_)
for i in range(len(A)):
for x in range(A[i], B[i]):
v = x * W + C[i]
ng[v][1] = 1
ng[v - 1][0] = 1
for i in range(len(D)):
for y in range(E[i], F[i]):
v = D[i] * W + y
ng[v][3] = 1
ng[v - W][2] = 1
return ng
@njit('(i8[:],i8[:],i8[:],i8[:],i8[:],i8[:],i8[:],i8[:])', cache=True)
def solve(A, B, C, D, E, F, X, Y):
H, W = len(X), len(Y)
N = H * W
DX = X[1:] - X[:-1]
DY = Y[1:] - Y[:-1]
ng = set_ng(A, B, C, D, E, F, H, W)
x0, y0 = np.searchsorted(X, 0), np.searchsorted(Y, 0)
v0 = x0 * W + y0
visited = np.zeros(N, np.bool_)
visited[v0] = 1
stack = np.empty(N, np.int32)
p = 0
ret = 0
def area(x):
x, y = divmod(x, W)
return DX[x] * DY[y]
def push(x):
nonlocal p, ret
stack[p] = x
visited[x] = 1
ret += area(x)
p += 1
def pop():
nonlocal p
p -= 1
return stack[p]
push(v0)
move = (1, -1, W, -W)
while p:
v = pop()
for i in range(4):
if ng[v][i]:
continue
w = v + move[i]
if visited[w]:
continue
x, y = divmod(w, W)
if x == 0 or x == H - 1 or y == 0 or y == W - 1:
return 0
push(w)
return ret
N, M = list(map(int, readline().split()))
data = np.int64(read().split())
x = solve(*precompute(N, M, data))
if x == 0:
print('INF')
else:
print(x) | 95 | 96 | 2,303 | 2,400 | import sys
import numpy as np
from numba import njit
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
INF = 10**9 + 1
def precompute(N, M, data):
data = data.reshape(-1, 3)
A, B, C = data[:N].T
D, E, F = data[N:].T
X = np.unique(np.concatenate([A, B, D, [0, -INF, INF]]))
Y = np.unique(np.concatenate([C, E, F, [0, -INF, INF]]))
DX, DY = np.diff(X), np.diff(Y)
A = np.searchsorted(X, A)
B = np.searchsorted(X, B)
D = np.searchsorted(X, D)
C = np.searchsorted(Y, C)
E = np.searchsorted(Y, E)
F = np.searchsorted(Y, F)
return A, B, C, D, E, F, X, Y, DX, DY
@njit(cache=True)
def set_ng(A, B, C, D, E, F, H, W):
ng = np.zeros((H * W, 4), np.bool_)
for i in range(len(A)):
for x in range(A[i], B[i]):
v = x * W + C[i]
ng[v][1] = 1
ng[v - 1][0] = 1
for i in range(len(D)):
for y in range(E[i], F[i]):
v = D[i] * W + y
ng[v][3] = 1
ng[v - W][2] = 1
return ng
@njit(cache=True)
def solve(A, B, C, D, E, F, X, Y, DX, DY):
H, W = len(X), len(Y)
N = H * W
ng = set_ng(A, B, C, D, E, F, H, W)
x0, y0 = np.searchsorted(X, 0), np.searchsorted(Y, 0)
v0 = x0 * W + y0
visited = np.zeros(N, np.bool_)
visited[v0] = 1
stack = np.empty(N, np.int32)
p = 0
ret = 0
def area(x):
x, y = divmod(x, W)
return DX[x] * DY[y]
def push(x):
nonlocal p, ret
stack[p] = x
visited[x] = 1
ret += area(x)
p += 1
def pop():
nonlocal p
p -= 1
return stack[p]
push(v0)
move = (1, -1, W, -W)
while p:
v = pop()
for i in range(4):
if ng[v][i]:
continue
w = v + move[i]
if visited[w]:
continue
x, y = divmod(w, W)
if x == 0 or x == H - 1 or y == 0 or y == W - 1:
return 0
push(w)
return ret
N, M = list(map(int, readline().split()))
data = np.int64(read().split())
x = solve(*precompute(N, M, data))
if x == 0:
print("INF")
else:
print(x)
| import sys
import numpy as np
from numba import njit
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
INF = 10**9 + 1
def precompute(N, M, data):
data = data.reshape(-1, 3)
A, B, C = data[:N].T
D, E, F = data[N:].T
X = np.unique(np.concatenate([A, B, D, [0, -INF, INF]]))
Y = np.unique(np.concatenate([C, E, F, [0, -INF, INF]]))
A = np.searchsorted(X, A)
B = np.searchsorted(X, B)
D = np.searchsorted(X, D)
C = np.searchsorted(Y, C)
E = np.searchsorted(Y, E)
F = np.searchsorted(Y, F)
return A, B, C, D, E, F, X, Y
@njit("(i8[:],i8[:],i8[:],i8[:],i8[:],i8[:],i8,i8)", cache=True)
def set_ng(A, B, C, D, E, F, H, W):
ng = np.zeros((H * W, 4), np.bool_)
for i in range(len(A)):
for x in range(A[i], B[i]):
v = x * W + C[i]
ng[v][1] = 1
ng[v - 1][0] = 1
for i in range(len(D)):
for y in range(E[i], F[i]):
v = D[i] * W + y
ng[v][3] = 1
ng[v - W][2] = 1
return ng
@njit("(i8[:],i8[:],i8[:],i8[:],i8[:],i8[:],i8[:],i8[:])", cache=True)
def solve(A, B, C, D, E, F, X, Y):
H, W = len(X), len(Y)
N = H * W
DX = X[1:] - X[:-1]
DY = Y[1:] - Y[:-1]
ng = set_ng(A, B, C, D, E, F, H, W)
x0, y0 = np.searchsorted(X, 0), np.searchsorted(Y, 0)
v0 = x0 * W + y0
visited = np.zeros(N, np.bool_)
visited[v0] = 1
stack = np.empty(N, np.int32)
p = 0
ret = 0
def area(x):
x, y = divmod(x, W)
return DX[x] * DY[y]
def push(x):
nonlocal p, ret
stack[p] = x
visited[x] = 1
ret += area(x)
p += 1
def pop():
nonlocal p
p -= 1
return stack[p]
push(v0)
move = (1, -1, W, -W)
while p:
v = pop()
for i in range(4):
if ng[v][i]:
continue
w = v + move[i]
if visited[w]:
continue
x, y = divmod(w, W)
if x == 0 or x == H - 1 or y == 0 or y == W - 1:
return 0
push(w)
return ret
N, M = list(map(int, readline().split()))
data = np.int64(read().split())
x = solve(*precompute(N, M, data))
if x == 0:
print("INF")
else:
print(x)
| false | 1.041667 | [
"- DX, DY = np.diff(X), np.diff(Y)",
"- return A, B, C, D, E, F, X, Y, DX, DY",
"+ return A, B, C, D, E, F, X, Y",
"-@njit(cache=True)",
"+@njit(\"(i8[:],i8[:],i8[:],i8[:],i8[:],i8[:],i8,i8)\", cache=True)",
"-@njit(cache=True)",
"-def solve(A, B, C, D, E, F, X, Y, DX, DY):",
"+@njit(\"(i8[:],i8[:],i8[:],i8[:],i8[:],i8[:],i8[:],i8[:])\", cache=True)",
"+def solve(A, B, C, D, E, F, X, Y):",
"+ DX = X[1:] - X[:-1]",
"+ DY = Y[1:] - Y[:-1]"
] | false | 0.499446 | 0.193416 | 2.582237 | [
"s081697181",
"s487305861"
] |
u185948224 | p03476 | python | s773428761 | s084422176 | 1,982 | 566 | 33,420 | 32,280 | Accepted | Accepted | 71.44 | import bisect
from operator import itemgetter
Q = int(eval(input()))
lr = [list(map(int, input().split())) for _ in range(Q)]
rmax = max(lr, key=itemgetter(1))[1]
primes = list(range(rmax+1))
primes [1] = 0
for i in range(2, int(rmax**0.5)+ 2):
for j in range(2 * i, rmax+1, i):
primes[j] = 0
primes = [prime for prime in primes[:] if prime!=0]
lst2017 = [x for x in primes if x != 2 and (x+1)//2 in primes]
for l, r in lr:
nr = bisect.bisect_right(lst2017, r)
nl = bisect.bisect_left(lst2017, l)
print((nr - nl)) | import bisect
from operator import itemgetter
Q = int(eval(input()))
lr = [list(map(int, input().split())) for _ in range(Q)]
rmax = max(lr, key=itemgetter(1))[1]
primes = list(range(rmax+1))
primes [1] = 0
for i in range(2, int(rmax**0.5)+ 2):
for j in range(2 * i, rmax+1, i):
primes[j] = 0
primess = [prime for prime in primes[:] if prime!=0]
lst2017 = [x for x in primess if primes[(x+1)//2] != 0]
for l, r in lr:
nr = bisect.bisect_right(lst2017, r)
nl = bisect.bisect_left(lst2017, l)
print((nr - nl)) | 21 | 20 | 554 | 546 | import bisect
from operator import itemgetter
Q = int(eval(input()))
lr = [list(map(int, input().split())) for _ in range(Q)]
rmax = max(lr, key=itemgetter(1))[1]
primes = list(range(rmax + 1))
primes[1] = 0
for i in range(2, int(rmax**0.5) + 2):
for j in range(2 * i, rmax + 1, i):
primes[j] = 0
primes = [prime for prime in primes[:] if prime != 0]
lst2017 = [x for x in primes if x != 2 and (x + 1) // 2 in primes]
for l, r in lr:
nr = bisect.bisect_right(lst2017, r)
nl = bisect.bisect_left(lst2017, l)
print((nr - nl))
| import bisect
from operator import itemgetter
Q = int(eval(input()))
lr = [list(map(int, input().split())) for _ in range(Q)]
rmax = max(lr, key=itemgetter(1))[1]
primes = list(range(rmax + 1))
primes[1] = 0
for i in range(2, int(rmax**0.5) + 2):
for j in range(2 * i, rmax + 1, i):
primes[j] = 0
primess = [prime for prime in primes[:] if prime != 0]
lst2017 = [x for x in primess if primes[(x + 1) // 2] != 0]
for l, r in lr:
nr = bisect.bisect_right(lst2017, r)
nl = bisect.bisect_left(lst2017, l)
print((nr - nl))
| false | 4.761905 | [
"-primes = [prime for prime in primes[:] if prime != 0]",
"-lst2017 = [x for x in primes if x != 2 and (x + 1) // 2 in primes]",
"+primess = [prime for prime in primes[:] if prime != 0]",
"+lst2017 = [x for x in primess if primes[(x + 1) // 2] != 0]"
] | false | 0.052103 | 0.137099 | 0.380043 | [
"s773428761",
"s084422176"
] |
u949338836 | p02256 | python | s308125143 | s436456051 | 30 | 20 | 6,724 | 7,744 | Accepted | Accepted | 33.33 | #coding:utf-8
x,y = list(map(int,input().split()))
while x%y != 0:
x,y = y,x%y
print(y) | #coding:utf-8
#1_1_B
def gcd(x, y):
while x%y != 0:
x, y = y, x%y
return y
x, y = list(map(int, input().split()))
print((gcd(x, y))) | 6 | 9 | 91 | 149 | # coding:utf-8
x, y = list(map(int, input().split()))
while x % y != 0:
x, y = y, x % y
print(y)
| # coding:utf-8
# 1_1_B
def gcd(x, y):
while x % y != 0:
x, y = y, x % y
return y
x, y = list(map(int, input().split()))
print((gcd(x, y)))
| false | 33.333333 | [
"+# 1_1_B",
"+def gcd(x, y):",
"+ while x % y != 0:",
"+ x, y = y, x % y",
"+ return y",
"+",
"+",
"-while x % y != 0:",
"- x, y = y, x % y",
"-print(y)",
"+print((gcd(x, y)))"
] | false | 0.035408 | 0.035519 | 0.996888 | [
"s308125143",
"s436456051"
] |
u594956556 | p03487 | python | s317545748 | s748053217 | 108 | 89 | 18,676 | 17,780 | Accepted | Accepted | 17.59 | from collections import Counter
N = int(eval(input()))
a = list(map(int, input().split()))
c = Counter(a)
ans = 0
for key in c:
if c[key] >= key:
ans += (c[key] - key)
else:
ans += c[key]
print(ans) | N = int(eval(input()))
a = list(map(int, input().split()))
d = {}
for ai in a:
if ai in d:
d[ai] += 1
else:
d[ai] = 1
ans = 0
for key in d:
if d[key] >= key:
ans += (d[key] - key)
else:
ans += d[key]
print(ans)
| 13 | 17 | 218 | 249 | from collections import Counter
N = int(eval(input()))
a = list(map(int, input().split()))
c = Counter(a)
ans = 0
for key in c:
if c[key] >= key:
ans += c[key] - key
else:
ans += c[key]
print(ans)
| N = int(eval(input()))
a = list(map(int, input().split()))
d = {}
for ai in a:
if ai in d:
d[ai] += 1
else:
d[ai] = 1
ans = 0
for key in d:
if d[key] >= key:
ans += d[key] - key
else:
ans += d[key]
print(ans)
| false | 23.529412 | [
"-from collections import Counter",
"-",
"-c = Counter(a)",
"+d = {}",
"+for ai in a:",
"+ if ai in d:",
"+ d[ai] += 1",
"+ else:",
"+ d[ai] = 1",
"-for key in c:",
"- if c[key] >= key:",
"- ans += c[key] - key",
"+for key in d:",
"+ if d[key] >= key:",
"+ ans += d[key] - key",
"- ans += c[key]",
"+ ans += d[key]"
] | false | 0.042928 | 0.107055 | 0.400987 | [
"s317545748",
"s748053217"
] |
u193264896 | p02762 | python | s729247674 | s552687089 | 1,175 | 1,021 | 30,256 | 18,764 | Accepted | Accepted | 13.11 | 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 functools import reduce
from collections import deque, Counter, defaultdict
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
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')
MOD = 10**9+7
def lcm(a, b):
return a*b//gcd(a, b)
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
#要素xが属するグループの根を探して返す
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
#xが属するグループとyが属するグループを併合する
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
#xが属するグループに含まれる要素数(サイズ)を返す
def size(self, x):
return -self.parents[self.find(x)]
#要素x,yが同じグループに属するかどうかを返す
def same(self, x, y):
return self.find(x) == self.find(y)
#要素xが属するグループに属する要素をリストで返す
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
#すべてのグループの根をリストで返す
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
#存在するグループの数を返す
def group_count(self):
return len(self.roots)
#根と根の下に属する要素のリスト辞書を返す
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
#print(uf)で根と要素のリストを文字列で返す
def __str__(self):
return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
def main():
n, m, k = list(map(int, input().split()))
deg = [0]*n
ans = [0]*n
uf = UnionFind(n)
for _ in range(m):
a, b = list(map(int, input().split()))
a -= 1
b -= 1
deg[a] += 1
deg[b] += 1
uf.union(a, b)
for _ in range(k):
c, d = list(map(int, input().split()))
c -= 1
d -= 1
if uf.same(c,d):
deg[c] += 1
deg[d] += 1
for i in range(n):
ans[i] = uf.size(i) - 1 -deg[i]
print((' '.join(map(str, ans))))
if __name__ == '__main__':
main() | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
#xが属するグループに含まれる要素数(サイズ)を返す
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots)
#根と根の下に属する要素のリスト辞書を返す
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
def main():
n, m, k = list(map(int, input().split()))
deg = [0]*n
ans = [0]*n
uf = UnionFind(n)
for _ in range(m):
a, b = list(map(int, input().split()))
a -= 1
b -= 1
deg[a] += 1
deg[b] += 1
uf.union(a, b)
for _ in range(k):
c, d = list(map(int, input().split()))
c -= 1
d -= 1
if uf.same(c,d):
deg[c] += 1
deg[d] += 1
for i in range(n):
ans[i] = uf.size(i) - 1 -deg[i]
print((' '.join(map(str, ans))))
if __name__ == '__main__':
main()
| 105 | 85 | 2,648 | 1,873 | 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 functools import reduce
from collections import deque, Counter, defaultdict
from itertools import product, permutations, combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
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")
MOD = 10**9 + 7
def lcm(a, b):
return a * b // gcd(a, b)
class UnionFind:
def __init__(self, n):
self.n = n
self.parents = [-1] * n
# 要素xが属するグループの根を探して返す
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
# xが属するグループとyが属するグループを併合する
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
# xが属するグループに含まれる要素数(サイズ)を返す
def size(self, x):
return -self.parents[self.find(x)]
# 要素x,yが同じグループに属するかどうかを返す
def same(self, x, y):
return self.find(x) == self.find(y)
# 要素xが属するグループに属する要素をリストで返す
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
# すべてのグループの根をリストで返す
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
# 存在するグループの数を返す
def group_count(self):
return len(self.roots)
# 根と根の下に属する要素のリスト辞書を返す
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
# print(uf)で根と要素のリストを文字列で返す
def __str__(self):
return "\n".join("{}: {}".format(r, self.members(r)) for r in self.roots())
def main():
n, m, k = list(map(int, input().split()))
deg = [0] * n
ans = [0] * n
uf = UnionFind(n)
for _ in range(m):
a, b = list(map(int, input().split()))
a -= 1
b -= 1
deg[a] += 1
deg[b] += 1
uf.union(a, b)
for _ in range(k):
c, d = list(map(int, input().split()))
c -= 1
d -= 1
if uf.same(c, d):
deg[c] += 1
deg[d] += 1
for i in range(n):
ans[i] = uf.size(i) - 1 - deg[i]
print((" ".join(map(str, ans))))
if __name__ == "__main__":
main()
| import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float("inf")
MOD = 10**9 + 7
class UnionFind:
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
# xが属するグループに含まれる要素数(サイズ)を返す
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots)
# 根と根の下に属する要素のリスト辞書を返す
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return "\n".join("{}: {}".format(r, self.members(r)) for r in self.roots())
def main():
n, m, k = list(map(int, input().split()))
deg = [0] * n
ans = [0] * n
uf = UnionFind(n)
for _ in range(m):
a, b = list(map(int, input().split()))
a -= 1
b -= 1
deg[a] += 1
deg[b] += 1
uf.union(a, b)
for _ in range(k):
c, d = list(map(int, input().split()))
c -= 1
d -= 1
if uf.same(c, d):
deg[c] += 1
deg[d] += 1
for i in range(n):
ans[i] = uf.size(i) - 1 - deg[i]
print((" ".join(map(str, ans))))
if __name__ == "__main__":
main()
| false | 19.047619 | [
"-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 functools import reduce",
"-from collections import deque, Counter, defaultdict",
"-from itertools import product, permutations, combinations",
"-from operator import itemgetter",
"-from heapq import heappop, heappush",
"-from bisect import bisect_left, bisect_right, bisect",
"-from fractions import gcd",
"-from math import ceil, floor, sqrt, cos, sin, pi, factorial",
"-def lcm(a, b):",
"- return a * b // gcd(a, b)",
"-",
"-",
"- # 要素xが属するグループの根を探して返す",
"- # xが属するグループとyが属するグループを併合する",
"- # 要素x,yが同じグループに属するかどうかを返す",
"- # 要素xが属するグループに属する要素をリストで返す",
"- # すべてのグループの根をリストで返す",
"- # 存在するグループの数を返す",
"- # print(uf)で根と要素のリストを文字列で返す"
] | false | 0.096599 | 0.053189 | 1.816146 | [
"s729247674",
"s552687089"
] |
u627234757 | p02993 | python | s528382172 | s529934105 | 31 | 26 | 9,092 | 9,016 | Accepted | Accepted | 16.13 | S = eval(input())
n = len(S)
flag = False
for i in range(1, n):
if S[i] == S[i-1]:
flag = True
if flag == True:
print('Bad')
else:
print('Good') | S = eval(input())
flag = False
tmp = ''
for s in S:
if tmp == s:
flag = True
tmp = s
if flag == True:
print('Bad')
else:
print('Good') | 10 | 11 | 157 | 150 | S = eval(input())
n = len(S)
flag = False
for i in range(1, n):
if S[i] == S[i - 1]:
flag = True
if flag == True:
print("Bad")
else:
print("Good")
| S = eval(input())
flag = False
tmp = ""
for s in S:
if tmp == s:
flag = True
tmp = s
if flag == True:
print("Bad")
else:
print("Good")
| false | 9.090909 | [
"-n = len(S)",
"-for i in range(1, n):",
"- if S[i] == S[i - 1]:",
"+tmp = \"\"",
"+for s in S:",
"+ if tmp == s:",
"+ tmp = s"
] | false | 0.045263 | 0.038957 | 1.161854 | [
"s528382172",
"s529934105"
] |
u562935282 | p02996 | python | s851944362 | s249244375 | 752 | 419 | 33,824 | 31,872 | Accepted | Accepted | 44.28 | def solve(n: int, ab: 'list(Task)') -> bool:
from operator import attrgetter
ab.sort(key=attrgetter('limit'))
cur = 0
for ab_ in ab:
cur += ab_.cost
if cur > ab_.limit:
return False
return True
if __name__ == '__main__':
from collections import namedtuple
import sys
input = sys.stdin.readline
Task = namedtuple('Task', 'cost limit')
n = int(eval(input()))
ab = []
for _ in range(n):
cost_, limit_ = list(map(int, input().split()))
ab.append(Task(cost=cost_, limit=limit_))
print(('Yes' if solve(n, ab) else 'No'))
| def main():
from operator import itemgetter
import sys
input = sys.stdin.readline
N = int(eval(input()))
tasks = []
for _ in range(N):
tasks.append(tuple(map(int, input().split()))) # (A,B)
tasks.sort(key=itemgetter(1))
t = 0
cond = True
for a, b in tasks:
t += a
if t > b:
cond = False
break
print(('Yes' if cond else 'No'))
if __name__ == '__main__':
main()
| 23 | 25 | 622 | 479 | def solve(n: int, ab: "list(Task)") -> bool:
from operator import attrgetter
ab.sort(key=attrgetter("limit"))
cur = 0
for ab_ in ab:
cur += ab_.cost
if cur > ab_.limit:
return False
return True
if __name__ == "__main__":
from collections import namedtuple
import sys
input = sys.stdin.readline
Task = namedtuple("Task", "cost limit")
n = int(eval(input()))
ab = []
for _ in range(n):
cost_, limit_ = list(map(int, input().split()))
ab.append(Task(cost=cost_, limit=limit_))
print(("Yes" if solve(n, ab) else "No"))
| def main():
from operator import itemgetter
import sys
input = sys.stdin.readline
N = int(eval(input()))
tasks = []
for _ in range(N):
tasks.append(tuple(map(int, input().split()))) # (A,B)
tasks.sort(key=itemgetter(1))
t = 0
cond = True
for a, b in tasks:
t += a
if t > b:
cond = False
break
print(("Yes" if cond else "No"))
if __name__ == "__main__":
main()
| false | 8 | [
"-def solve(n: int, ab: \"list(Task)\") -> bool:",
"- from operator import attrgetter",
"+def main():",
"+ from operator import itemgetter",
"+ import sys",
"- ab.sort(key=attrgetter(\"limit\"))",
"- cur = 0",
"- for ab_ in ab:",
"- cur += ab_.cost",
"- if cur > ab_.limit:",
"- return False",
"- return True",
"+ input = sys.stdin.readline",
"+ N = int(eval(input()))",
"+ tasks = []",
"+ for _ in range(N):",
"+ tasks.append(tuple(map(int, input().split()))) # (A,B)",
"+ tasks.sort(key=itemgetter(1))",
"+ t = 0",
"+ cond = True",
"+ for a, b in tasks:",
"+ t += a",
"+ if t > b:",
"+ cond = False",
"+ break",
"+ print((\"Yes\" if cond else \"No\"))",
"- from collections import namedtuple",
"- import sys",
"-",
"- input = sys.stdin.readline",
"- Task = namedtuple(\"Task\", \"cost limit\")",
"- n = int(eval(input()))",
"- ab = []",
"- for _ in range(n):",
"- cost_, limit_ = list(map(int, input().split()))",
"- ab.append(Task(cost=cost_, limit=limit_))",
"- print((\"Yes\" if solve(n, ab) else \"No\"))",
"+ main()"
] | false | 0.03597 | 0.033083 | 1.087254 | [
"s851944362",
"s249244375"
] |
u676264453 | p03633 | python | s097197148 | s167329320 | 25 | 17 | 3,572 | 3,060 | Accepted | Accepted | 32 | from functools import reduce
#def gcd(a, b):
# while b:
# a, b = b, a % b
# return a
def gcd(m, n):
r = m % n
return gcd(n, r) if r else n
def lcm(a, b):
return a * b // gcd(a,b)
N = int(eval(input()))
Ts = []
c = 1
for i in range(N):
c = lcm(c, int(eval(input())))
print((int(c)))
| def gcd(a, b):
while b:
a, b = b, a % b
return a
#def gcd(m, n):
# r = m % n
# return gcd(n, r) if r else n
def lcm(a, b):
return a * b // gcd(a,b)
N = int(eval(input()))
Ts = []
c = 1
for i in range(N):
c = lcm(c, int(eval(input())))
print((int(c)))
| 21 | 19 | 322 | 289 | from functools import reduce
# def gcd(a, b):
# while b:
# a, b = b, a % b
# return a
def gcd(m, n):
r = m % n
return gcd(n, r) if r else n
def lcm(a, b):
return a * b // gcd(a, b)
N = int(eval(input()))
Ts = []
c = 1
for i in range(N):
c = lcm(c, int(eval(input())))
print((int(c)))
| def gcd(a, b):
while b:
a, b = b, a % b
return a
# def gcd(m, n):
# r = m % n
# return gcd(n, r) if r else n
def lcm(a, b):
return a * b // gcd(a, b)
N = int(eval(input()))
Ts = []
c = 1
for i in range(N):
c = lcm(c, int(eval(input())))
print((int(c)))
| false | 9.52381 | [
"-from functools import reduce",
"-",
"-# def gcd(a, b):",
"-# while b:",
"-# a, b = b, a % b",
"-# return a",
"-def gcd(m, n):",
"- r = m % n",
"- return gcd(n, r) if r else n",
"+def gcd(a, b):",
"+ while b:",
"+ a, b = b, a % b",
"+ return a",
"+# def gcd(m, n):",
"+# r = m % n",
"+# return gcd(n, r) if r else n"
] | false | 0.037376 | 0.07614 | 0.490883 | [
"s097197148",
"s167329320"
] |
u020373088 | p03361 | python | s433359350 | s225120706 | 23 | 21 | 3,064 | 3,064 | Accepted | Accepted | 8.7 | h, w = list(map(int, input().split()))
s = [eval(input()) for i in range(h)]
flag = True
for i in range(h):
for j in range(w):
if s[i][j] == "#":
top = max(0, i-1)
bottom = min(h-1, i+1)
right = min(w-1, j+1)
left = max(0, j-1)
if s[i][right] != "#" and s[i][left] != "#" and s[top][j] != "#" and s[bottom][j] != "#":
flag = False
break
if flag == False:
break
if flag:
print("Yes")
else:
print("No") | h, w = list(map(int, input().split()))
s = [eval(input()) for i in range(h)]
for i in range(h):
for j in range(w):
if s[i][j] == "#":
top = max(0, i-1)
bottom = min(h-1, i+1)
right = min(w-1, j+1)
left = max(0, j-1)
if s[i][right] != "#" and s[i][left] != "#" and s[top][j] != "#" and s[bottom][j] != "#":
print("No")
exit()
print("Yes") | 21 | 15 | 472 | 393 | h, w = list(map(int, input().split()))
s = [eval(input()) for i in range(h)]
flag = True
for i in range(h):
for j in range(w):
if s[i][j] == "#":
top = max(0, i - 1)
bottom = min(h - 1, i + 1)
right = min(w - 1, j + 1)
left = max(0, j - 1)
if (
s[i][right] != "#"
and s[i][left] != "#"
and s[top][j] != "#"
and s[bottom][j] != "#"
):
flag = False
break
if flag == False:
break
if flag:
print("Yes")
else:
print("No")
| h, w = list(map(int, input().split()))
s = [eval(input()) for i in range(h)]
for i in range(h):
for j in range(w):
if s[i][j] == "#":
top = max(0, i - 1)
bottom = min(h - 1, i + 1)
right = min(w - 1, j + 1)
left = max(0, j - 1)
if (
s[i][right] != "#"
and s[i][left] != "#"
and s[top][j] != "#"
and s[bottom][j] != "#"
):
print("No")
exit()
print("Yes")
| false | 28.571429 | [
"-flag = True",
"- flag = False",
"- break",
"- if flag == False:",
"- break",
"-if flag:",
"- print(\"Yes\")",
"-else:",
"- print(\"No\")",
"+ print(\"No\")",
"+ exit()",
"+print(\"Yes\")"
] | false | 0.058058 | 0.033797 | 1.717856 | [
"s433359350",
"s225120706"
] |
u179169725 | p03503 | python | s191701261 | s857270811 | 435 | 253 | 21,376 | 13,340 | Accepted | Accepted | 41.84 | # https://atcoder.jp/contests/abc080/tasks/abc080_c
# 普通にbit全探索では?
N = int(eval(input()))
F = []
for _ in range(N):
F.append(list(map(int, input().split())))
P = []
for _ in range(N):
P.append(list(map(int, input().split())))
bitlen = 10
# def ret_score(n: int):
# # 営業時間かぶり計算
# C = []
# for i in range(N): # Nでiter
# cnt = 0
# for bit in range(bitlen): # 桁とFを対応
# if ((n >> bit) & 1) and F[i][bit]: # もし1その桁で1なら
# cnt += 1
# C.append(cnt)
# # スコア計算
# ret = 0
# for i, c in enumerate(C):
# ret += P[i][c]
# return ret
# ans = -10**10
# for n in range(1, 1 << bitlen):
# ans = max(ans, ret_score(n))
# print(ans)
# numpyでも実装してみる
import numpy as np
F = np.array(F)
P = np.array(P)
bitshifter = np.array([x for x in range(bitlen)])
def ret_score(n: int):
bit_arr = (n >> bitshifter) & 1
F_matched = bit_arr & F
C = F_matched.sum(axis=1)
# スコア計算
ret = 0
for i, c in enumerate(C):
ret += P[i, c]
return ret
ans = -10**10
for n in range(1, 1 << bitlen):
ans = max(ans, ret_score(n))
print(ans)
| # https://atcoder.jp/contests/abc080/tasks/abc080_c
# 普通にbit全探索では?
N = int(eval(input()))
F = []
for _ in range(N):
F.append(list(map(int, input().split())))
P = []
for _ in range(N):
P.append(list(map(int, input().split())))
bitlen = 10
# def ret_score(n: int):
# # 営業時間かぶり計算
# C = []
# for i in range(N): # Nでiter
# cnt = 0
# for bit in range(bitlen): # 桁とFを対応
# if ((n >> bit) & 1) and F[i][bit]: # もし1その桁で1なら
# cnt += 1
# C.append(cnt)
# # スコア計算
# ret = 0
# for i, c in enumerate(C):
# ret += P[i][c]
# return ret
# ans = -10**10
# for n in range(1, 1 << bitlen):
# ans = max(ans, ret_score(n))
# print(ans)
# numpyでも実装してみる
import numpy as np
F = np.array(F)
P = np.array(P)
bitshifter = np.array([x for x in range(bitlen)])
def ret_score(n: int, F, bitshifter, P):
bit_arr = (n >> bitshifter) & 1
F_matched = bit_arr & F
C = F_matched.sum(axis=1)
# スコア計算
ret = 0
for i, c in enumerate(C):
ret += P[i, c]
return ret
ans = -10**10
for n in range(1, 1 << bitlen):
ans = max(ans, ret_score(n, F, bitshifter, P))
print(ans)
| 61 | 61 | 1,200 | 1,236 | # https://atcoder.jp/contests/abc080/tasks/abc080_c
# 普通にbit全探索では?
N = int(eval(input()))
F = []
for _ in range(N):
F.append(list(map(int, input().split())))
P = []
for _ in range(N):
P.append(list(map(int, input().split())))
bitlen = 10
# def ret_score(n: int):
# # 営業時間かぶり計算
# C = []
# for i in range(N): # Nでiter
# cnt = 0
# for bit in range(bitlen): # 桁とFを対応
# if ((n >> bit) & 1) and F[i][bit]: # もし1その桁で1なら
# cnt += 1
# C.append(cnt)
# # スコア計算
# ret = 0
# for i, c in enumerate(C):
# ret += P[i][c]
# return ret
# ans = -10**10
# for n in range(1, 1 << bitlen):
# ans = max(ans, ret_score(n))
# print(ans)
# numpyでも実装してみる
import numpy as np
F = np.array(F)
P = np.array(P)
bitshifter = np.array([x for x in range(bitlen)])
def ret_score(n: int):
bit_arr = (n >> bitshifter) & 1
F_matched = bit_arr & F
C = F_matched.sum(axis=1)
# スコア計算
ret = 0
for i, c in enumerate(C):
ret += P[i, c]
return ret
ans = -(10**10)
for n in range(1, 1 << bitlen):
ans = max(ans, ret_score(n))
print(ans)
| # https://atcoder.jp/contests/abc080/tasks/abc080_c
# 普通にbit全探索では?
N = int(eval(input()))
F = []
for _ in range(N):
F.append(list(map(int, input().split())))
P = []
for _ in range(N):
P.append(list(map(int, input().split())))
bitlen = 10
# def ret_score(n: int):
# # 営業時間かぶり計算
# C = []
# for i in range(N): # Nでiter
# cnt = 0
# for bit in range(bitlen): # 桁とFを対応
# if ((n >> bit) & 1) and F[i][bit]: # もし1その桁で1なら
# cnt += 1
# C.append(cnt)
# # スコア計算
# ret = 0
# for i, c in enumerate(C):
# ret += P[i][c]
# return ret
# ans = -10**10
# for n in range(1, 1 << bitlen):
# ans = max(ans, ret_score(n))
# print(ans)
# numpyでも実装してみる
import numpy as np
F = np.array(F)
P = np.array(P)
bitshifter = np.array([x for x in range(bitlen)])
def ret_score(n: int, F, bitshifter, P):
bit_arr = (n >> bitshifter) & 1
F_matched = bit_arr & F
C = F_matched.sum(axis=1)
# スコア計算
ret = 0
for i, c in enumerate(C):
ret += P[i, c]
return ret
ans = -(10**10)
for n in range(1, 1 << bitlen):
ans = max(ans, ret_score(n, F, bitshifter, P))
print(ans)
| false | 0 | [
"-def ret_score(n: int):",
"+def ret_score(n: int, F, bitshifter, P):",
"- ans = max(ans, ret_score(n))",
"+ ans = max(ans, ret_score(n, F, bitshifter, P))"
] | false | 0.334109 | 0.376824 | 0.886646 | [
"s191701261",
"s857270811"
] |
u623687794 | p02936 | python | s464507131 | s850668559 | 1,988 | 1,183 | 133,188 | 68,368 | Accepted | Accepted | 40.49 | import sys
from collections import deque
sys.setrecursionlimit(500000)
n,q=list(map(int,input().split()))
edge=[[] for i in range(n)]
cost=[0]*n
for i in range(n-1):
p,s=list(map(int,input().split()))
p-=1;s-=1
edge[p].append(s)
edge[s].append(p)
for i in range(q):
x,c=list(map(int,input().split()))
x-=1
cost[x]+=c
visited=[False]*n
queue=deque([0])
visited[0]=True
while len(queue)!=0:
a=queue.popleft()
for i in edge[a]:
if visited[i]==True:continue
queue.append(i)
visited[i]=True
cost[i]+=cost[a]
for i in range(n):
cost[i]=str(cost[i])
print((" ".join(cost))) | import sys
from collections import deque
sys.setrecursionlimit(500000)
input=sys.stdin.readline
n,q=list(map(int,input().split()))
edge=[[] for i in range(n)]
cost=[0]*n
for i in range(n-1):
p,s=list(map(int,input().split()))
p-=1;s-=1
edge[p].append(s)
edge[s].append(p)
for i in range(q):
x,c=list(map(int,input().split()))
x-=1
cost[x]+=c
visited=[False]*n
queue=deque([0])
visited[0]=True
while len(queue)!=0:
a=queue.popleft()
for i in edge[a]:
if visited[i]==True:continue
queue.append(i)
visited[i]=True
cost[i]+=cost[a]
for i in range(n):
cost[i]=str(cost[i])
print((" ".join(cost)))
| 28 | 29 | 609 | 636 | import sys
from collections import deque
sys.setrecursionlimit(500000)
n, q = list(map(int, input().split()))
edge = [[] for i in range(n)]
cost = [0] * n
for i in range(n - 1):
p, s = list(map(int, input().split()))
p -= 1
s -= 1
edge[p].append(s)
edge[s].append(p)
for i in range(q):
x, c = list(map(int, input().split()))
x -= 1
cost[x] += c
visited = [False] * n
queue = deque([0])
visited[0] = True
while len(queue) != 0:
a = queue.popleft()
for i in edge[a]:
if visited[i] == True:
continue
queue.append(i)
visited[i] = True
cost[i] += cost[a]
for i in range(n):
cost[i] = str(cost[i])
print((" ".join(cost)))
| import sys
from collections import deque
sys.setrecursionlimit(500000)
input = sys.stdin.readline
n, q = list(map(int, input().split()))
edge = [[] for i in range(n)]
cost = [0] * n
for i in range(n - 1):
p, s = list(map(int, input().split()))
p -= 1
s -= 1
edge[p].append(s)
edge[s].append(p)
for i in range(q):
x, c = list(map(int, input().split()))
x -= 1
cost[x] += c
visited = [False] * n
queue = deque([0])
visited[0] = True
while len(queue) != 0:
a = queue.popleft()
for i in edge[a]:
if visited[i] == True:
continue
queue.append(i)
visited[i] = True
cost[i] += cost[a]
for i in range(n):
cost[i] = str(cost[i])
print((" ".join(cost)))
| false | 3.448276 | [
"+input = sys.stdin.readline"
] | false | 0.078679 | 0.121227 | 0.649028 | [
"s464507131",
"s850668559"
] |
u379720557 | p02702 | python | s625258228 | s828704518 | 124 | 111 | 9,304 | 9,372 | Accepted | Accepted | 10.48 | S = input()[::-1]
m = 2019
cnt = [0] * m
cnt[0] = 1
total = 0
x = 1
ans = 0
for i in range(len(S)):
total += int(S[i])*x
total %= m
cnt[total] += 1
x = 10*x
x %= m
for i in range(2019):
ans += cnt[i]*(cnt[i]-1)//2
print(ans) | S = input()[::-1]
cnt = [0] * 2019
cnt[0] = 1
total = 0
x = 1
ans = 0
for a in S:
total += int(a) * x
total %= 2019
cnt[total] += 1
x = x*10
x %= 2019
for i in range(2019):
ans += cnt[i]*(cnt[i]-1)//2
print(ans) | 20 | 19 | 271 | 261 | S = input()[::-1]
m = 2019
cnt = [0] * m
cnt[0] = 1
total = 0
x = 1
ans = 0
for i in range(len(S)):
total += int(S[i]) * x
total %= m
cnt[total] += 1
x = 10 * x
x %= m
for i in range(2019):
ans += cnt[i] * (cnt[i] - 1) // 2
print(ans)
| S = input()[::-1]
cnt = [0] * 2019
cnt[0] = 1
total = 0
x = 1
ans = 0
for a in S:
total += int(a) * x
total %= 2019
cnt[total] += 1
x = x * 10
x %= 2019
for i in range(2019):
ans += cnt[i] * (cnt[i] - 1) // 2
print(ans)
| false | 5 | [
"-m = 2019",
"-cnt = [0] * m",
"+cnt = [0] * 2019",
"-for i in range(len(S)):",
"- total += int(S[i]) * x",
"- total %= m",
"+for a in S:",
"+ total += int(a) * x",
"+ total %= 2019",
"- x = 10 * x",
"- x %= m",
"+ x = x * 10",
"+ x %= 2019"
] | false | 0.068398 | 0.040542 | 1.687073 | [
"s625258228",
"s828704518"
] |
u981931040 | p03457 | python | s610411466 | s885280059 | 386 | 227 | 3,064 | 8,952 | Accepted | Accepted | 41.19 | N = int(eval(input()))
now_x = 0
now_y = 0
now_t = 0
Flag = False
for i in range(N):
t , x, y = list(map(int,input().split()))
dx = abs(x - now_x)
dy = abs(y - now_y)
dt = abs(t - now_t)
if (dt - (dx + dy)) % 2 != 0 or dt < (dx + dy):
Flag = True
now_x = x
now_y = y
now_t = t
print(("No" if Flag else "Yes")) | N = int(eval(input()))
now_t, now_x, now_y = 0, 0, 0
for i in range(N):
next_t, next_x, next_y = list(map(int, input().split()))
distance = abs(next_x - now_x) + abs(next_y - now_y)
spent_time = next_t - now_t
if spent_time < distance or distance % 2 != spent_time % 2:
print('No')
exit()
now_t, now_x, now_y = next_t, next_x, next_y
print('Yes') | 16 | 11 | 350 | 380 | N = int(eval(input()))
now_x = 0
now_y = 0
now_t = 0
Flag = False
for i in range(N):
t, x, y = list(map(int, input().split()))
dx = abs(x - now_x)
dy = abs(y - now_y)
dt = abs(t - now_t)
if (dt - (dx + dy)) % 2 != 0 or dt < (dx + dy):
Flag = True
now_x = x
now_y = y
now_t = t
print(("No" if Flag else "Yes"))
| N = int(eval(input()))
now_t, now_x, now_y = 0, 0, 0
for i in range(N):
next_t, next_x, next_y = list(map(int, input().split()))
distance = abs(next_x - now_x) + abs(next_y - now_y)
spent_time = next_t - now_t
if spent_time < distance or distance % 2 != spent_time % 2:
print("No")
exit()
now_t, now_x, now_y = next_t, next_x, next_y
print("Yes")
| false | 31.25 | [
"-now_x = 0",
"-now_y = 0",
"-now_t = 0",
"-Flag = False",
"+now_t, now_x, now_y = 0, 0, 0",
"- t, x, y = list(map(int, input().split()))",
"- dx = abs(x - now_x)",
"- dy = abs(y - now_y)",
"- dt = abs(t - now_t)",
"- if (dt - (dx + dy)) % 2 != 0 or dt < (dx + dy):",
"- Flag = True",
"- now_x = x",
"- now_y = y",
"- now_t = t",
"-print((\"No\" if Flag else \"Yes\"))",
"+ next_t, next_x, next_y = list(map(int, input().split()))",
"+ distance = abs(next_x - now_x) + abs(next_y - now_y)",
"+ spent_time = next_t - now_t",
"+ if spent_time < distance or distance % 2 != spent_time % 2:",
"+ print(\"No\")",
"+ exit()",
"+ now_t, now_x, now_y = next_t, next_x, next_y",
"+print(\"Yes\")"
] | false | 0.041098 | 0.040927 | 1.00417 | [
"s610411466",
"s885280059"
] |
u083960235 | p02847 | python | s590671380 | s672702845 | 93 | 39 | 5,972 | 5,144 | Accepted | Accepted | 58.06 | import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def S_MAP(): return list(map(str, input().split()))
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
s = eval(input())
# n = INT()
# print(a, b)
if s == "SUN":
print((7))
elif s == "MON":
print((6))
elif s == "TUE":
print((5))
elif s == "WED":
print((4))
elif s == "THU":
print((3))
elif s == "FRI":
print((2))
elif s == "SAT":
print((1))
| import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def S_MAP(): return list(map(str, input().split()))
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
S = eval(input())
day = ["SUN","MON","TUE","WED","THU","FRI","SAT"]
# if S == "SAT":
# print(1)
# else:
for i, d in enumerate(day):
if d == S:
print((7 - i))
exit()
| 41 | 33 | 981 | 930 | import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input():
return sys.stdin.readline().strip()
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def S_MAP():
return list(map(str, input().split()))
def LIST():
return list(map(int, input().split()))
def S_LIST():
return list(map(str, input().split()))
sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
s = eval(input())
# n = INT()
# print(a, b)
if s == "SUN":
print((7))
elif s == "MON":
print((6))
elif s == "TUE":
print((5))
elif s == "WED":
print((4))
elif s == "THU":
print((3))
elif s == "FRI":
print((2))
elif s == "SAT":
print((1))
| import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input():
return sys.stdin.readline().strip()
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def S_MAP():
return list(map(str, input().split()))
def LIST():
return list(map(int, input().split()))
def S_LIST():
return list(map(str, input().split()))
sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
S = eval(input())
day = ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"]
# if S == "SAT":
# print(1)
# else:
for i, d in enumerate(day):
if d == S:
print((7 - i))
exit()
| false | 19.512195 | [
"-s = eval(input())",
"-# n = INT()",
"-# print(a, b)",
"-if s == \"SUN\":",
"- print((7))",
"-elif s == \"MON\":",
"- print((6))",
"-elif s == \"TUE\":",
"- print((5))",
"-elif s == \"WED\":",
"- print((4))",
"-elif s == \"THU\":",
"- print((3))",
"-elif s == \"FRI\":",
"- print((2))",
"-elif s == \"SAT\":",
"- print((1))",
"+S = eval(input())",
"+day = [\"SUN\", \"MON\", \"TUE\", \"WED\", \"THU\", \"FRI\", \"SAT\"]",
"+# if S == \"SAT\":",
"+# print(1)",
"+# else:",
"+for i, d in enumerate(day):",
"+ if d == S:",
"+ print((7 - i))",
"+ exit()"
] | false | 0.038517 | 0.057229 | 0.673038 | [
"s590671380",
"s672702845"
] |
u353919145 | p03834 | python | s998372821 | s336736557 | 17 | 10 | 2,940 | 2,568 | Accepted | Accepted | 41.18 | import sys
lines = sys.stdin.readlines()
for linea in lines:
c = linea.split()
c = list(map(str,c))
list(c)
sent_str= c[0]
x = sent_str.replace(",", " ")
print(x) | #!/usr/bin/env python
s = input()
print((s.replace(",", " "))) | 9 | 3 | 178 | 67 | import sys
lines = sys.stdin.readlines()
for linea in lines:
c = linea.split()
c = list(map(str, c))
list(c)
sent_str = c[0]
x = sent_str.replace(",", " ")
print(x)
| #!/usr/bin/env python
s = input()
print((s.replace(",", " ")))
| false | 66.666667 | [
"-import sys",
"-",
"-lines = sys.stdin.readlines()",
"-for linea in lines:",
"- c = linea.split()",
"- c = list(map(str, c))",
"-list(c)",
"-sent_str = c[0]",
"-x = sent_str.replace(\",\", \" \")",
"-print(x)",
"+#!/usr/bin/env python",
"+s = input()",
"+print((s.replace(\",\", \" \")))"
] | false | 0.062813 | 0.037422 | 1.678512 | [
"s998372821",
"s336736557"
] |
u357630630 | p03624 | python | s349345378 | s480779042 | 38 | 20 | 4,084 | 3,956 | Accepted | Accepted | 47.37 | L = "".join([chr(i) for i in range(97, 97 + 26)])
for i in list(eval(input())):
L = L.replace(i, "")
if L == "":
print("None")
else:
print((L[0]))
| L = "".join([chr(i) for i in range(97, 97 + 26)])
for i in set(list(eval(input()))):
L = L.replace(i, "")
if L == "":
print("None")
else:
print((L[0]))
| 7 | 7 | 157 | 162 | L = "".join([chr(i) for i in range(97, 97 + 26)])
for i in list(eval(input())):
L = L.replace(i, "")
if L == "":
print("None")
else:
print((L[0]))
| L = "".join([chr(i) for i in range(97, 97 + 26)])
for i in set(list(eval(input()))):
L = L.replace(i, "")
if L == "":
print("None")
else:
print((L[0]))
| false | 0 | [
"-for i in list(eval(input())):",
"+for i in set(list(eval(input()))):"
] | false | 0.040728 | 0.036742 | 1.108461 | [
"s349345378",
"s480779042"
] |
u777207626 | p03078 | python | s907024201 | s144866732 | 800 | 672 | 151,388 | 8,712 | Accepted | Accepted | 16 | x,y,z,k = list(map(int,input().split()))
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
a.sort(reverse=True),b.sort(reverse=True),c.sort(reverse=True)
ab = []
for i in range(x):
for j in range(y):
ab.append(a[i]+b[j])
ab.sort(reverse=True)
ab = ab[0:k]
abc = []
for i in ab:
for j in c:
abc.append(i+j)
abc.sort(reverse=True)
abc = abc[0:k]
for i in abc:
print(i) | x,y,z,k = list(map(int,input().split()))
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
a.sort(reverse=True),b.sort(reverse=True),c.sort(reverse=True)
abc = []
for i in range(x):
for j in range(y):
for l in range(z):
if (i+1)*(j+1)*(l+1)>k:
break
abc.append(a[i]+b[j]+c[l])
abc.sort(reverse=True)
abc = abc[0:k]
for i in abc:
print(i)
| 20 | 20 | 458 | 452 | x, y, z, k = list(map(int, input().split()))
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
a.sort(reverse=True), b.sort(reverse=True), c.sort(reverse=True)
ab = []
for i in range(x):
for j in range(y):
ab.append(a[i] + b[j])
ab.sort(reverse=True)
ab = ab[0:k]
abc = []
for i in ab:
for j in c:
abc.append(i + j)
abc.sort(reverse=True)
abc = abc[0:k]
for i in abc:
print(i)
| x, y, z, k = list(map(int, input().split()))
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
a.sort(reverse=True), b.sort(reverse=True), c.sort(reverse=True)
abc = []
for i in range(x):
for j in range(y):
for l in range(z):
if (i + 1) * (j + 1) * (l + 1) > k:
break
abc.append(a[i] + b[j] + c[l])
abc.sort(reverse=True)
abc = abc[0:k]
for i in abc:
print(i)
| false | 0 | [
"-ab = []",
"+abc = []",
"- ab.append(a[i] + b[j])",
"-ab.sort(reverse=True)",
"-ab = ab[0:k]",
"-abc = []",
"-for i in ab:",
"- for j in c:",
"- abc.append(i + j)",
"+ for l in range(z):",
"+ if (i + 1) * (j + 1) * (l + 1) > k:",
"+ break",
"+ abc.append(a[i] + b[j] + c[l])"
] | false | 0.043796 | 0.120577 | 0.363218 | [
"s907024201",
"s144866732"
] |
u192154323 | p02720 | python | s637594839 | s769497160 | 219 | 199 | 13,368 | 13,436 | Accepted | Accepted | 9.13 | k = int(eval(input()))
lun_ls = []
def change_to_num(ls):
ls = list(map(str, ls))
strnum = ''.join(ls)
return int(strnum)
def lun(num):
'''
渡された数が上限行ってなければlun_lsに追加して、次の数で再帰呼出
'''
if num > 3234566667:
return
lun_ls.append(num)
last = num % 10
for nex in range(last-1, last+2):
if 0<= nex < 10:
new_str = str(num) + str(nex)
new = int(new_str)
lun(new)
for start in range(1,10):
lun(start)
lun_ls.sort()
print((lun_ls[k-1])) | k = int(eval(input()))
# やっぱり一旦はglobalで書こ
total_ls = []
def dfs(A):
if int(A) > 3234566667:
return
global total_ls
total_ls.append(int(A))
last = int(A[-1])
if last == 0:
nex = [1,0]
elif last == 9:
nex = [8,9]
else:
nex = [last-1,last,last+1]
for n in nex:
A += str(n)
dfs(A)
A = A[:-1]
for i in range(1,10):
dfs(str(i))
total_ls.sort()
print((total_ls[k-1]))
| 26 | 27 | 551 | 479 | k = int(eval(input()))
lun_ls = []
def change_to_num(ls):
ls = list(map(str, ls))
strnum = "".join(ls)
return int(strnum)
def lun(num):
"""
渡された数が上限行ってなければlun_lsに追加して、次の数で再帰呼出
"""
if num > 3234566667:
return
lun_ls.append(num)
last = num % 10
for nex in range(last - 1, last + 2):
if 0 <= nex < 10:
new_str = str(num) + str(nex)
new = int(new_str)
lun(new)
for start in range(1, 10):
lun(start)
lun_ls.sort()
print((lun_ls[k - 1]))
| k = int(eval(input()))
# やっぱり一旦はglobalで書こ
total_ls = []
def dfs(A):
if int(A) > 3234566667:
return
global total_ls
total_ls.append(int(A))
last = int(A[-1])
if last == 0:
nex = [1, 0]
elif last == 9:
nex = [8, 9]
else:
nex = [last - 1, last, last + 1]
for n in nex:
A += str(n)
dfs(A)
A = A[:-1]
for i in range(1, 10):
dfs(str(i))
total_ls.sort()
print((total_ls[k - 1]))
| false | 3.703704 | [
"-lun_ls = []",
"+# やっぱり一旦はglobalで書こ",
"+total_ls = []",
"-def change_to_num(ls):",
"- ls = list(map(str, ls))",
"- strnum = \"\".join(ls)",
"- return int(strnum)",
"+def dfs(A):",
"+ if int(A) > 3234566667:",
"+ return",
"+ global total_ls",
"+ total_ls.append(int(A))",
"+ last = int(A[-1])",
"+ if last == 0:",
"+ nex = [1, 0]",
"+ elif last == 9:",
"+ nex = [8, 9]",
"+ else:",
"+ nex = [last - 1, last, last + 1]",
"+ for n in nex:",
"+ A += str(n)",
"+ dfs(A)",
"+ A = A[:-1]",
"-def lun(num):",
"- \"\"\"",
"- 渡された数が上限行ってなければlun_lsに追加して、次の数で再帰呼出",
"- \"\"\"",
"- if num > 3234566667:",
"- return",
"- lun_ls.append(num)",
"- last = num % 10",
"- for nex in range(last - 1, last + 2):",
"- if 0 <= nex < 10:",
"- new_str = str(num) + str(nex)",
"- new = int(new_str)",
"- lun(new)",
"-",
"-",
"-for start in range(1, 10):",
"- lun(start)",
"-lun_ls.sort()",
"-print((lun_ls[k - 1]))",
"+for i in range(1, 10):",
"+ dfs(str(i))",
"+total_ls.sort()",
"+print((total_ls[k - 1]))"
] | false | 0.352551 | 0.59345 | 0.594069 | [
"s637594839",
"s769497160"
] |
u704001626 | p02954 | python | s489194905 | s601945279 | 184 | 134 | 14,692 | 11,260 | Accepted | Accepted | 27.17 | # -*- coding: utf-8 -*-
S = eval(input())
len_S = len(S)
#Rは右方向に最も近いL,Lは左方向に最も近いRを探す
S_asshuku = []
min_lens = []
ret_list = [0] * len_S
cnt = 1
for i in range(1,len_S):
if S[i]==S[i-1]:
cnt+=1
else:
S_asshuku.append(cnt)
cnt = 1
S_asshuku.append(cnt)
for i,v in enumerate(S_asshuku):
if i%2==0:#Rの場合
min_lens += list(range(v,0,-1))
else:#Lの場合
min_lens += list(range(1,v+1))
for i,(s,ml) in enumerate(zip(S,min_lens)):
if s=="R":
ret_list[i+ml-ml%2]+=1
else:
ret_list[i-ml+ml%2]+=1
print((" ".join(list(map(str,ret_list)))))
| s = eval(input())
ss = []
s1 ="R"
cnt = 0
for i in s:
if i == s1:
cnt+=1
else:
ss.append(cnt)
cnt = 1
if s1=="R":
s1="L"
else:
s1="R"
ss.append(cnt)
ret = [0] * len(s)
v_total = 0
for i,v in enumerate(ss):
v_total += v
if i % 2 == 0:
ret[v_total]+=v//2
ret[v_total-1]+=(v+1)//2
else:
ret[v_total-v]+=(v+1)//2
ret[v_total-v-1]+=v//2
print((" ".join(map(str,ret)))) | 26 | 26 | 622 | 497 | # -*- coding: utf-8 -*-
S = eval(input())
len_S = len(S)
# Rは右方向に最も近いL,Lは左方向に最も近いRを探す
S_asshuku = []
min_lens = []
ret_list = [0] * len_S
cnt = 1
for i in range(1, len_S):
if S[i] == S[i - 1]:
cnt += 1
else:
S_asshuku.append(cnt)
cnt = 1
S_asshuku.append(cnt)
for i, v in enumerate(S_asshuku):
if i % 2 == 0: # Rの場合
min_lens += list(range(v, 0, -1))
else: # Lの場合
min_lens += list(range(1, v + 1))
for i, (s, ml) in enumerate(zip(S, min_lens)):
if s == "R":
ret_list[i + ml - ml % 2] += 1
else:
ret_list[i - ml + ml % 2] += 1
print((" ".join(list(map(str, ret_list)))))
| s = eval(input())
ss = []
s1 = "R"
cnt = 0
for i in s:
if i == s1:
cnt += 1
else:
ss.append(cnt)
cnt = 1
if s1 == "R":
s1 = "L"
else:
s1 = "R"
ss.append(cnt)
ret = [0] * len(s)
v_total = 0
for i, v in enumerate(ss):
v_total += v
if i % 2 == 0:
ret[v_total] += v // 2
ret[v_total - 1] += (v + 1) // 2
else:
ret[v_total - v] += (v + 1) // 2
ret[v_total - v - 1] += v // 2
print((" ".join(map(str, ret))))
| false | 0 | [
"-# -*- coding: utf-8 -*-",
"-S = eval(input())",
"-len_S = len(S)",
"-# Rは右方向に最も近いL,Lは左方向に最も近いRを探す",
"-S_asshuku = []",
"-min_lens = []",
"-ret_list = [0] * len_S",
"-cnt = 1",
"-for i in range(1, len_S):",
"- if S[i] == S[i - 1]:",
"+s = eval(input())",
"+ss = []",
"+s1 = \"R\"",
"+cnt = 0",
"+for i in s:",
"+ if i == s1:",
"- S_asshuku.append(cnt)",
"+ ss.append(cnt)",
"-S_asshuku.append(cnt)",
"-for i, v in enumerate(S_asshuku):",
"- if i % 2 == 0: # Rの場合",
"- min_lens += list(range(v, 0, -1))",
"- else: # Lの場合",
"- min_lens += list(range(1, v + 1))",
"-for i, (s, ml) in enumerate(zip(S, min_lens)):",
"- if s == \"R\":",
"- ret_list[i + ml - ml % 2] += 1",
"+ if s1 == \"R\":",
"+ s1 = \"L\"",
"+ else:",
"+ s1 = \"R\"",
"+ss.append(cnt)",
"+ret = [0] * len(s)",
"+v_total = 0",
"+for i, v in enumerate(ss):",
"+ v_total += v",
"+ if i % 2 == 0:",
"+ ret[v_total] += v // 2",
"+ ret[v_total - 1] += (v + 1) // 2",
"- ret_list[i - ml + ml % 2] += 1",
"-print((\" \".join(list(map(str, ret_list)))))",
"+ ret[v_total - v] += (v + 1) // 2",
"+ ret[v_total - v - 1] += v // 2",
"+print((\" \".join(map(str, ret))))"
] | false | 0.036499 | 0.03551 | 1.027864 | [
"s489194905",
"s601945279"
] |
u392319141 | p02788 | python | s959800094 | s937803741 | 1,741 | 1,065 | 91,352 | 44,624 | Accepted | Accepted | 38.83 | from bisect import bisect_right
N, D, A = list(map(int, input().split()))
XH = [tuple(map(int, input().split())) for _ in range(N)]
XH.sort()
X = [x for x, _ in XH]
ans = 0
ims = [0] * (N + 1)
cnt = 0
for now, (x, h) in enumerate(XH):
cnt += ims[now]
if cnt * A >= h:
continue
ness = -(-(h - cnt * A) // A)
cnt += ness
i = bisect_right(X, x + D * 2)
ims[now] += ness
ims[i] -= ness
ans += ness
print(ans) | from collections import deque
N, D, A = list(map(int, input().split()))
XH = [tuple(map(int, input().split())) for _ in range(N)]
XH.sort()
ans = 0
cnt = 0
que = deque()
for x, h in XH:
while que and que[0][0] <= x:
cnt -= que.popleft()[1]
h -= cnt * A
if h <= 0:
continue
ness = -(-h // A)
cnt += ness
ans += ness
que.append((x + 2 * D + 1, ness))
print(ans)
| 25 | 25 | 468 | 429 | from bisect import bisect_right
N, D, A = list(map(int, input().split()))
XH = [tuple(map(int, input().split())) for _ in range(N)]
XH.sort()
X = [x for x, _ in XH]
ans = 0
ims = [0] * (N + 1)
cnt = 0
for now, (x, h) in enumerate(XH):
cnt += ims[now]
if cnt * A >= h:
continue
ness = -(-(h - cnt * A) // A)
cnt += ness
i = bisect_right(X, x + D * 2)
ims[now] += ness
ims[i] -= ness
ans += ness
print(ans)
| from collections import deque
N, D, A = list(map(int, input().split()))
XH = [tuple(map(int, input().split())) for _ in range(N)]
XH.sort()
ans = 0
cnt = 0
que = deque()
for x, h in XH:
while que and que[0][0] <= x:
cnt -= que.popleft()[1]
h -= cnt * A
if h <= 0:
continue
ness = -(-h // A)
cnt += ness
ans += ness
que.append((x + 2 * D + 1, ness))
print(ans)
| false | 0 | [
"-from bisect import bisect_right",
"+from collections import deque",
"-X = [x for x, _ in XH]",
"-ims = [0] * (N + 1)",
"-for now, (x, h) in enumerate(XH):",
"- cnt += ims[now]",
"- if cnt * A >= h:",
"+que = deque()",
"+for x, h in XH:",
"+ while que and que[0][0] <= x:",
"+ cnt -= que.popleft()[1]",
"+ h -= cnt * A",
"+ if h <= 0:",
"- ness = -(-(h - cnt * A) // A)",
"+ ness = -(-h // A)",
"- i = bisect_right(X, x + D * 2)",
"- ims[now] += ness",
"- ims[i] -= ness",
"+ que.append((x + 2 * D + 1, ness))"
] | false | 0.09191 | 0.04818 | 1.907622 | [
"s959800094",
"s937803741"
] |
u816631826 | p03845 | python | s825367277 | s190410803 | 20 | 18 | 3,064 | 3,064 | Accepted | Accepted | 10 |
n=int(eval(input()))
t=eval(input())
t=t.split()
m=int(eval(input()))
px=[]
su=[]
for i in range(m):
px.append(input().split())
o=t[int(px[-1][0])-1]
t[int(px[-1][0])-1]=int(px[-1][1])
temp=0
for i in t:
temp=temp+int(i)
su.append(temp)
t[int(px[-1][0])-1]=o
for i in su:
print(i)
| def sumArray(n):
sum = 0
for i in range(len(n)):
sum += n[i]
return sum
n = int(eval(input()))
t = list(map(int, input().rstrip().split()))
m = int(eval(input()))
sum = sumArray(t)
temp = sum
for i in range(m):
data = list(map(int, input().split()))
sum = sum - t[data[0] - 1] + data[1]
print(sum)
sum = temp | 22 | 16 | 341 | 348 | n = int(eval(input()))
t = eval(input())
t = t.split()
m = int(eval(input()))
px = []
su = []
for i in range(m):
px.append(input().split())
o = t[int(px[-1][0]) - 1]
t[int(px[-1][0]) - 1] = int(px[-1][1])
temp = 0
for i in t:
temp = temp + int(i)
su.append(temp)
t[int(px[-1][0]) - 1] = o
for i in su:
print(i)
| def sumArray(n):
sum = 0
for i in range(len(n)):
sum += n[i]
return sum
n = int(eval(input()))
t = list(map(int, input().rstrip().split()))
m = int(eval(input()))
sum = sumArray(t)
temp = sum
for i in range(m):
data = list(map(int, input().split()))
sum = sum - t[data[0] - 1] + data[1]
print(sum)
sum = temp
| false | 27.272727 | [
"+def sumArray(n):",
"+ sum = 0",
"+ for i in range(len(n)):",
"+ sum += n[i]",
"+ return sum",
"+",
"+",
"-t = eval(input())",
"-t = t.split()",
"+t = list(map(int, input().rstrip().split()))",
"-px = []",
"-su = []",
"+sum = sumArray(t)",
"+temp = sum",
"- px.append(input().split())",
"- o = t[int(px[-1][0]) - 1]",
"- t[int(px[-1][0]) - 1] = int(px[-1][1])",
"- temp = 0",
"- for i in t:",
"- temp = temp + int(i)",
"- su.append(temp)",
"- t[int(px[-1][0]) - 1] = o",
"-for i in su:",
"- print(i)",
"+ data = list(map(int, input().split()))",
"+ sum = sum - t[data[0] - 1] + data[1]",
"+ print(sum)",
"+ sum = temp"
] | false | 0.035222 | 0.036665 | 0.960622 | [
"s825367277",
"s190410803"
] |
u391589398 | p03166 | python | s978550181 | s282376020 | 623 | 529 | 59,056 | 23,088 | Accepted | Accepted | 15.09 | import sys
sys.setrecursionlimit(500000)
n, m = list(map(int, input().split()))
G = [[] for _ in range(n)]
for _ in range(m):
x, y = [int(x)-1 for x in input().split()]
G[x].append(y)
# iを始点としたときの有効パスの最大長さ
dp = [-1] * n
def rec(s):
if dp[s] != -1:
return dp[s]
ret = 0
for ns in G[s]:
ret = max(ret, rec(ns)+1)
dp[s] = ret
return ret
ml = 0
for i in range(n):
ml = max(ml, rec(i))
print(ml) | n, m = list(map(int, input().split()))
G = [[] for _ in range(n)]
deg = [0] * n # 各頂点の入力次数
for _ in range(m):
x, y = [int(x)-1 for x in input().split()]
G[x].append(y)
deg[y] += 1
from collections import deque
# 入力次数が0の頂点をBFSの開始点とする
q = deque([])
for i in range(n):
if deg[i] == 0:
q.append(i)
dp = [0] * n
while q:
v = q.popleft()
for nv in G[v]:
# vからnvへの入力を削除
deg[nv] -= 1
if deg[nv] == 0:
q.append(nv)
dp[nv] = max(dp[nv], dp[v]+1)
print((max(dp)))
| 25 | 27 | 470 | 564 | import sys
sys.setrecursionlimit(500000)
n, m = list(map(int, input().split()))
G = [[] for _ in range(n)]
for _ in range(m):
x, y = [int(x) - 1 for x in input().split()]
G[x].append(y)
# iを始点としたときの有効パスの最大長さ
dp = [-1] * n
def rec(s):
if dp[s] != -1:
return dp[s]
ret = 0
for ns in G[s]:
ret = max(ret, rec(ns) + 1)
dp[s] = ret
return ret
ml = 0
for i in range(n):
ml = max(ml, rec(i))
print(ml)
| n, m = list(map(int, input().split()))
G = [[] for _ in range(n)]
deg = [0] * n # 各頂点の入力次数
for _ in range(m):
x, y = [int(x) - 1 for x in input().split()]
G[x].append(y)
deg[y] += 1
from collections import deque
# 入力次数が0の頂点をBFSの開始点とする
q = deque([])
for i in range(n):
if deg[i] == 0:
q.append(i)
dp = [0] * n
while q:
v = q.popleft()
for nv in G[v]:
# vからnvへの入力を削除
deg[nv] -= 1
if deg[nv] == 0:
q.append(nv)
dp[nv] = max(dp[nv], dp[v] + 1)
print((max(dp)))
| false | 7.407407 | [
"-import sys",
"-",
"-sys.setrecursionlimit(500000)",
"+deg = [0] * n # 各頂点の入力次数",
"-# iを始点としたときの有効パスの最大長さ",
"-dp = [-1] * n",
"+ deg[y] += 1",
"+from collections import deque",
"-",
"-def rec(s):",
"- if dp[s] != -1:",
"- return dp[s]",
"- ret = 0",
"- for ns in G[s]:",
"- ret = max(ret, rec(ns) + 1)",
"- dp[s] = ret",
"- return ret",
"-",
"-",
"-ml = 0",
"+# 入力次数が0の頂点をBFSの開始点とする",
"+q = deque([])",
"- ml = max(ml, rec(i))",
"-print(ml)",
"+ if deg[i] == 0:",
"+ q.append(i)",
"+dp = [0] * n",
"+while q:",
"+ v = q.popleft()",
"+ for nv in G[v]:",
"+ # vからnvへの入力を削除",
"+ deg[nv] -= 1",
"+ if deg[nv] == 0:",
"+ q.append(nv)",
"+ dp[nv] = max(dp[nv], dp[v] + 1)",
"+print((max(dp)))"
] | false | 0.03645 | 0.047398 | 0.769019 | [
"s978550181",
"s282376020"
] |
u926046014 | p02694 | python | s917249617 | s292837153 | 34 | 30 | 10,064 | 9,060 | Accepted | Accepted | 11.76 | from decimal import Decimal
x=int(eval(input()))
n=Decimal("100")
ans=0
while True:
ans+=1
n*=Decimal("1.01")
n//=1
if n>=x:
print(ans)
break | x=int(eval(input()))
n=100
ans=0
while True:
ans+=1
n+=n//100
if n>=x:
print(ans)
break | 11 | 9 | 177 | 117 | from decimal import Decimal
x = int(eval(input()))
n = Decimal("100")
ans = 0
while True:
ans += 1
n *= Decimal("1.01")
n //= 1
if n >= x:
print(ans)
break
| x = int(eval(input()))
n = 100
ans = 0
while True:
ans += 1
n += n // 100
if n >= x:
print(ans)
break
| false | 18.181818 | [
"-from decimal import Decimal",
"-",
"-n = Decimal(\"100\")",
"+n = 100",
"- n *= Decimal(\"1.01\")",
"- n //= 1",
"+ n += n // 100"
] | false | 0.04652 | 0.07041 | 0.660696 | [
"s917249617",
"s292837153"
] |
u353919145 | p03556 | python | s525629116 | s066705904 | 59 | 18 | 3,060 | 2,940 | Accepted | Accepted | 69.49 | import math
n = int(eval(input()))
for i in range(n):
sqrt = int(math.sqrt(n-i))
if(sqrt**2 == (n-i)):
print((n-i))
break | import math
n = int(eval(input()))
print((int(math.floor(n**0.5))**2)) | 9 | 5 | 147 | 68 | import math
n = int(eval(input()))
for i in range(n):
sqrt = int(math.sqrt(n - i))
if sqrt**2 == (n - i):
print((n - i))
break
| import math
n = int(eval(input()))
print((int(math.floor(n**0.5)) ** 2))
| false | 44.444444 | [
"-for i in range(n):",
"- sqrt = int(math.sqrt(n - i))",
"- if sqrt**2 == (n - i):",
"- print((n - i))",
"- break",
"+print((int(math.floor(n**0.5)) ** 2))"
] | false | 0.053561 | 0.12562 | 0.426373 | [
"s525629116",
"s066705904"
] |
u373047809 | p02803 | python | s948815060 | s913142539 | 426 | 294 | 29,496 | 21,996 | Accepted | Accepted | 30.99 | #!/usr/bin/env python3
from scipy.sparse.csgraph import floyd_warshall
INF = float("inf")
h, w = list(map(int, input().split()))
M = [eval(input()) for _ in [0]*h]
E = [[0]*h*w for _ in [0]*h*w]
D = [(1, 0), (0, 1), (-1, 0), (0, -1)]
def point(x, y):
return w * x + y
for i in range(h):
for j in range(w):
if M[i][j] == ".":
for x, y in D:
I, J = i + x, j + y
if w > J >= 0 <= I < h and M[I][J] == ".":
E[point(i, j)][point(I, J)] = 1
a = floyd_warshall(E)
print((int(a[a != INF].max()))) | from scipy.sparse import*
_,*s=open(0)
r=s+["#"*20]
*g,=eval("[0]*500,"*500)
i=-1
for t in s:
i+=1;j=0
for u in t:k=i*20+j;g[k][k+1]=u>'#'<t[j+1];g[k][k+20]=u>'#'<r[i+1][j];j+=1
a=csgraph.johnson(csr_matrix(g),0)
print((int(max(a[a<999])))) | 22 | 10 | 579 | 249 | #!/usr/bin/env python3
from scipy.sparse.csgraph import floyd_warshall
INF = float("inf")
h, w = list(map(int, input().split()))
M = [eval(input()) for _ in [0] * h]
E = [[0] * h * w for _ in [0] * h * w]
D = [(1, 0), (0, 1), (-1, 0), (0, -1)]
def point(x, y):
return w * x + y
for i in range(h):
for j in range(w):
if M[i][j] == ".":
for x, y in D:
I, J = i + x, j + y
if w > J >= 0 <= I < h and M[I][J] == ".":
E[point(i, j)][point(I, J)] = 1
a = floyd_warshall(E)
print((int(a[a != INF].max())))
| from scipy.sparse import *
_, *s = open(0)
r = s + ["#" * 20]
(*g,) = eval("[0]*500," * 500)
i = -1
for t in s:
i += 1
j = 0
for u in t:
k = i * 20 + j
g[k][k + 1] = u > "#" < t[j + 1]
g[k][k + 20] = u > "#" < r[i + 1][j]
j += 1
a = csgraph.johnson(csr_matrix(g), 0)
print((int(max(a[a < 999]))))
| false | 54.545455 | [
"-#!/usr/bin/env python3",
"-from scipy.sparse.csgraph import floyd_warshall",
"+from scipy.sparse import *",
"-INF = float(\"inf\")",
"-h, w = list(map(int, input().split()))",
"-M = [eval(input()) for _ in [0] * h]",
"-E = [[0] * h * w for _ in [0] * h * w]",
"-D = [(1, 0), (0, 1), (-1, 0), (0, -1)]",
"-",
"-",
"-def point(x, y):",
"- return w * x + y",
"-",
"-",
"-for i in range(h):",
"- for j in range(w):",
"- if M[i][j] == \".\":",
"- for x, y in D:",
"- I, J = i + x, j + y",
"- if w > J >= 0 <= I < h and M[I][J] == \".\":",
"- E[point(i, j)][point(I, J)] = 1",
"-a = floyd_warshall(E)",
"-print((int(a[a != INF].max())))",
"+_, *s = open(0)",
"+r = s + [\"#\" * 20]",
"+(*g,) = eval(\"[0]*500,\" * 500)",
"+i = -1",
"+for t in s:",
"+ i += 1",
"+ j = 0",
"+ for u in t:",
"+ k = i * 20 + j",
"+ g[k][k + 1] = u > \"#\" < t[j + 1]",
"+ g[k][k + 20] = u > \"#\" < r[i + 1][j]",
"+ j += 1",
"+a = csgraph.johnson(csr_matrix(g), 0)",
"+print((int(max(a[a < 999]))))"
] | false | 0.564681 | 0.42164 | 1.339251 | [
"s948815060",
"s913142539"
] |
u609061751 | p03435 | python | s120518630 | s723609646 | 887 | 74 | 3,060 | 69,516 | Accepted | Accepted | 91.66 | import sys
input = sys.stdin.readline
c = [[int(x) for x in input().split()] for _ in range(3)]
for i in range(101):
for j in range(101):
for k in range(101):
b1, b2, b3 = [x - i for x in c[0]]
if [b1 + j, b2 + j, b3 + j] == c[1] and [b1 + k, b2 + k, b3 + k] == c[2]:
print("Yes")
sys.exit()
print("No")
| import sys
input = lambda: sys.stdin.readline().rstrip("\r\n")
c = [[int(x) for x in input().split()] for _ in range(3)]
flag = 1
for a1 in range(101):
for a2 in range(101):
for a3 in range(101):
if c[0][0] - a1 == c[1][0] - a2 and c[1][0] - a2 == c[2][0] - a3:
if c[0][1] - a1 == c[1][1] - a2 and c[1][1] - a2 == c[2][1] - a3:
if c[0][2] - a1 == c[1][2] - a2 and c[1][2] - a2 == c[2][2] - a3:
flag = 0
if flag:
print('No')
else:
print('Yes')
| 14 | 20 | 388 | 559 | import sys
input = sys.stdin.readline
c = [[int(x) for x in input().split()] for _ in range(3)]
for i in range(101):
for j in range(101):
for k in range(101):
b1, b2, b3 = [x - i for x in c[0]]
if [b1 + j, b2 + j, b3 + j] == c[1] and [b1 + k, b2 + k, b3 + k] == c[2]:
print("Yes")
sys.exit()
print("No")
| import sys
input = lambda: sys.stdin.readline().rstrip("\r\n")
c = [[int(x) for x in input().split()] for _ in range(3)]
flag = 1
for a1 in range(101):
for a2 in range(101):
for a3 in range(101):
if c[0][0] - a1 == c[1][0] - a2 and c[1][0] - a2 == c[2][0] - a3:
if c[0][1] - a1 == c[1][1] - a2 and c[1][1] - a2 == c[2][1] - a3:
if c[0][2] - a1 == c[1][2] - a2 and c[1][2] - a2 == c[2][2] - a3:
flag = 0
if flag:
print("No")
else:
print("Yes")
| false | 30 | [
"-input = sys.stdin.readline",
"+input = lambda: sys.stdin.readline().rstrip(\"\\r\\n\")",
"-for i in range(101):",
"- for j in range(101):",
"- for k in range(101):",
"- b1, b2, b3 = [x - i for x in c[0]]",
"- if [b1 + j, b2 + j, b3 + j] == c[1] and [b1 + k, b2 + k, b3 + k] == c[2]:",
"- print(\"Yes\")",
"- sys.exit()",
"-print(\"No\")",
"+flag = 1",
"+for a1 in range(101):",
"+ for a2 in range(101):",
"+ for a3 in range(101):",
"+ if c[0][0] - a1 == c[1][0] - a2 and c[1][0] - a2 == c[2][0] - a3:",
"+ if c[0][1] - a1 == c[1][1] - a2 and c[1][1] - a2 == c[2][1] - a3:",
"+ if c[0][2] - a1 == c[1][2] - a2 and c[1][2] - a2 == c[2][2] - a3:",
"+ flag = 0",
"+if flag:",
"+ print(\"No\")",
"+else:",
"+ print(\"Yes\")"
] | false | 0.308618 | 0.38965 | 0.79204 | [
"s120518630",
"s723609646"
] |
u562935282 | p03149 | python | s203242024 | s545547919 | 21 | 18 | 3,316 | 2,940 | Accepted | Accepted | 14.29 | n = list(map(int, input().split()))
bl = True
for v in 1, 9, 7, 4:
if v not in n:
bl = False
break
print(('YES' if bl else 'NO'))
| n = list(map(int, input().split()))
n = sorted(n)
bl = (n[0] == 1 and n[1] == 4 and n[2] == 7 and n[3] == 9)
print(('YES' if bl else 'NO'))
| 9 | 5 | 158 | 143 | n = list(map(int, input().split()))
bl = True
for v in 1, 9, 7, 4:
if v not in n:
bl = False
break
print(("YES" if bl else "NO"))
| n = list(map(int, input().split()))
n = sorted(n)
bl = n[0] == 1 and n[1] == 4 and n[2] == 7 and n[3] == 9
print(("YES" if bl else "NO"))
| false | 44.444444 | [
"-bl = True",
"-for v in 1, 9, 7, 4:",
"- if v not in n:",
"- bl = False",
"- break",
"+n = sorted(n)",
"+bl = n[0] == 1 and n[1] == 4 and n[2] == 7 and n[3] == 9"
] | false | 0.035419 | 0.037581 | 0.942477 | [
"s203242024",
"s545547919"
] |
u419877586 | p02783 | python | s196796525 | s464106850 | 165 | 17 | 38,256 | 2,940 | Accepted | Accepted | 89.7 | H, A=list(map(int, input().split()))
print(((H-1)//A+1))
| import math
H, A = list(map(int, input().split()))
print((math.ceil(H/A))) | 2 | 4 | 50 | 70 | H, A = list(map(int, input().split()))
print(((H - 1) // A + 1))
| import math
H, A = list(map(int, input().split()))
print((math.ceil(H / A)))
| false | 50 | [
"+import math",
"+",
"-print(((H - 1) // A + 1))",
"+print((math.ceil(H / A)))"
] | false | 0.0918 | 0.039505 | 2.323766 | [
"s196796525",
"s464106850"
] |
u761320129 | p04033 | python | s289293672 | s945042612 | 19 | 17 | 3,060 | 2,940 | Accepted | Accepted | 10.53 | A,B = list(map(int,input().split()))
if A <= 0 <= B:
print('Zero')
exit()
if 0 < A:
print('Positive')
elif B < 0:
c = B-A+1
print(('Negative' if c%2 else 'Positive'))
else:
c = -A
print(('Negative' if c%2 else 'Positive')) | a,b = list(map(int,input().split()))
if a <= 0 <= b:
print('Zero')
elif a > 0:
print('Positive')
else:
k = b-a + 1
print(('Negative' if k%2 else 'Positive')) | 13 | 8 | 253 | 172 | A, B = list(map(int, input().split()))
if A <= 0 <= B:
print("Zero")
exit()
if 0 < A:
print("Positive")
elif B < 0:
c = B - A + 1
print(("Negative" if c % 2 else "Positive"))
else:
c = -A
print(("Negative" if c % 2 else "Positive"))
| a, b = list(map(int, input().split()))
if a <= 0 <= b:
print("Zero")
elif a > 0:
print("Positive")
else:
k = b - a + 1
print(("Negative" if k % 2 else "Positive"))
| false | 38.461538 | [
"-A, B = list(map(int, input().split()))",
"-if A <= 0 <= B:",
"+a, b = list(map(int, input().split()))",
"+if a <= 0 <= b:",
"- exit()",
"-if 0 < A:",
"+elif a > 0:",
"-elif B < 0:",
"- c = B - A + 1",
"- print((\"Negative\" if c % 2 else \"Positive\"))",
"- c = -A",
"- print((\"Negative\" if c % 2 else \"Positive\"))",
"+ k = b - a + 1",
"+ print((\"Negative\" if k % 2 else \"Positive\"))"
] | false | 0.04281 | 0.043465 | 0.984928 | [
"s289293672",
"s945042612"
] |
u373047809 | p02787 | python | s133579654 | s117803153 | 202 | 142 | 74,408 | 74,276 | Accepted | Accepted | 29.7 | def chmin(dp, i, *x):
dp[i] = min(dp[i], *x)
INF = float("inf")
# dp[i] := min 消耗する魔力 to H -= i
h, n = list(map(int, input().split()))
dp = [0] + [INF]*h
for _ in [None]*n:
a, b = list(map(int, input().split()))
for j in range(h + 1):
chmin(dp, min(j + a, h), dp[j] + b)
print((dp[h])) | (h,n),*t=[list(map(int,o.split()))for o in open(0)]
d=[0]+[9e9]*h
for a,b in t:
for j in range(h+1):d[j]=min(d[j],d[max(0,j-a)]+b)
print((d[h])) | 12 | 5 | 293 | 141 | def chmin(dp, i, *x):
dp[i] = min(dp[i], *x)
INF = float("inf")
# dp[i] := min 消耗する魔力 to H -= i
h, n = list(map(int, input().split()))
dp = [0] + [INF] * h
for _ in [None] * n:
a, b = list(map(int, input().split()))
for j in range(h + 1):
chmin(dp, min(j + a, h), dp[j] + b)
print((dp[h]))
| (h, n), *t = [list(map(int, o.split())) for o in open(0)]
d = [0] + [9e9] * h
for a, b in t:
for j in range(h + 1):
d[j] = min(d[j], d[max(0, j - a)] + b)
print((d[h]))
| false | 58.333333 | [
"-def chmin(dp, i, *x):",
"- dp[i] = min(dp[i], *x)",
"-",
"-",
"-INF = float(\"inf\")",
"-# dp[i] := min 消耗する魔力 to H -= i",
"-h, n = list(map(int, input().split()))",
"-dp = [0] + [INF] * h",
"-for _ in [None] * n:",
"- a, b = list(map(int, input().split()))",
"+(h, n), *t = [list(map(int, o.split())) for o in open(0)]",
"+d = [0] + [9e9] * h",
"+for a, b in t:",
"- chmin(dp, min(j + a, h), dp[j] + b)",
"-print((dp[h]))",
"+ d[j] = min(d[j], d[max(0, j - a)] + b)",
"+print((d[h]))"
] | false | 0.155666 | 0.110451 | 1.40936 | [
"s133579654",
"s117803153"
] |
u936985471 | p03061 | python | s140210278 | s045007407 | 186 | 170 | 14,076 | 14,196 | Accepted | Accepted | 8.6 | N=int(eval(input()))
A=list(map(int,input().split()))
# 1,7,6,8,1,
# L[i]=A[i]
def gcd(a,b):
if a<b:
a,b=b,a
while a%b>0:
a,b=b,a%b
return b
L=[1]*len(A)
L[0]=A[0]
for i in range(len(A)-1):
L[i+1]=gcd(L[i],A[i+1])
R=[1]*len(A)
R[-1]=A[-1]
for i in range(len(A)-1,0,-1):
R[i-1]=gcd(R[i],A[i-1])
ans=1
for i in range(len(A)):
if i==0:
if ans<R[i+1]:
ans=R[i+1]
elif i==len(A)-1:
if ans<L[i-1]:
ans=L[i-1]
else:
p=gcd(L[i-1],R[i+1])
if ans<p:
ans=p
print(ans)
| import sys
readline = sys.stdin.readline
N = int(readline())
A = list(map(int,readline().split()))
if N == 2:
print((max(A)))
exit(0)
def gcd(a,b):
if a < b:
a,b = b,a
while a%b > 0:
a,b = b,a%b
return b
left = [None] * N
left[0] = A[0]
for i in range(1, len(A)):
left[i] = gcd(left[i - 1],A[i])
right = [None] * N
right[-1] = A[-1]
for i in range(len(A) - 2,-1,-1):
right[i] = gcd(right[i + 1],A[i])
ans = max(left[-2],right[1])
for i in range(1, len(A) - 1):
g = gcd(left[i - 1],right[i + 1])
if ans < g:
ans = g
print(ans)
| 35 | 33 | 549 | 592 | N = int(eval(input()))
A = list(map(int, input().split()))
# 1,7,6,8,1,
# L[i]=A[i]
def gcd(a, b):
if a < b:
a, b = b, a
while a % b > 0:
a, b = b, a % b
return b
L = [1] * len(A)
L[0] = A[0]
for i in range(len(A) - 1):
L[i + 1] = gcd(L[i], A[i + 1])
R = [1] * len(A)
R[-1] = A[-1]
for i in range(len(A) - 1, 0, -1):
R[i - 1] = gcd(R[i], A[i - 1])
ans = 1
for i in range(len(A)):
if i == 0:
if ans < R[i + 1]:
ans = R[i + 1]
elif i == len(A) - 1:
if ans < L[i - 1]:
ans = L[i - 1]
else:
p = gcd(L[i - 1], R[i + 1])
if ans < p:
ans = p
print(ans)
| import sys
readline = sys.stdin.readline
N = int(readline())
A = list(map(int, readline().split()))
if N == 2:
print((max(A)))
exit(0)
def gcd(a, b):
if a < b:
a, b = b, a
while a % b > 0:
a, b = b, a % b
return b
left = [None] * N
left[0] = A[0]
for i in range(1, len(A)):
left[i] = gcd(left[i - 1], A[i])
right = [None] * N
right[-1] = A[-1]
for i in range(len(A) - 2, -1, -1):
right[i] = gcd(right[i + 1], A[i])
ans = max(left[-2], right[1])
for i in range(1, len(A) - 1):
g = gcd(left[i - 1], right[i + 1])
if ans < g:
ans = g
print(ans)
| false | 5.714286 | [
"-N = int(eval(input()))",
"-A = list(map(int, input().split()))",
"-# 1,7,6,8,1,",
"-# L[i]=A[i]",
"+import sys",
"+",
"+readline = sys.stdin.readline",
"+N = int(readline())",
"+A = list(map(int, readline().split()))",
"+if N == 2:",
"+ print((max(A)))",
"+ exit(0)",
"+",
"+",
"-L = [1] * len(A)",
"-L[0] = A[0]",
"-for i in range(len(A) - 1):",
"- L[i + 1] = gcd(L[i], A[i + 1])",
"-R = [1] * len(A)",
"-R[-1] = A[-1]",
"-for i in range(len(A) - 1, 0, -1):",
"- R[i - 1] = gcd(R[i], A[i - 1])",
"-ans = 1",
"-for i in range(len(A)):",
"- if i == 0:",
"- if ans < R[i + 1]:",
"- ans = R[i + 1]",
"- elif i == len(A) - 1:",
"- if ans < L[i - 1]:",
"- ans = L[i - 1]",
"- else:",
"- p = gcd(L[i - 1], R[i + 1])",
"- if ans < p:",
"- ans = p",
"+left = [None] * N",
"+left[0] = A[0]",
"+for i in range(1, len(A)):",
"+ left[i] = gcd(left[i - 1], A[i])",
"+right = [None] * N",
"+right[-1] = A[-1]",
"+for i in range(len(A) - 2, -1, -1):",
"+ right[i] = gcd(right[i + 1], A[i])",
"+ans = max(left[-2], right[1])",
"+for i in range(1, len(A) - 1):",
"+ g = gcd(left[i - 1], right[i + 1])",
"+ if ans < g:",
"+ ans = g"
] | false | 0.049162 | 0.045531 | 1.079751 | [
"s140210278",
"s045007407"
] |
u560867850 | p02850 | python | s601215923 | s970817514 | 463 | 410 | 53,140 | 53,892 | Accepted | Accepted | 11.45 | import sys
input = sys.stdin.readline
from collections import deque
def readlines(n):
for _ in range(n):
a, b = list(map(int, input().split()))
yield a, b
def main():
N = int(eval(input()))
edges = list(readlines(N-1))
tree = {i:[] for i in range(N)}
for a, b in edges:
tree[a].append(b)
ans = {}
frontier = deque([(1,0)])
while frontier:
u, prev_color = frontier.pop()
if tree.get(u) is None:
continue
for i, v in enumerate(tree[u], 1):
color = i if i != prev_color else len(tree[u])+1
ans[u, v] = color
frontier.appendleft((v, color))
print((max(ans.values())))
for u,v in edges:
print((ans[u,v]))
main() | import sys
input = sys.stdin.readline
from collections import deque
def main():
N = int(eval(input()))
tree = {i:[] for i in range(N)}
edges = []
for _ in range(N-1):
a, b = list(map(int, input().split()))
edges.append((a, b))
tree[a].append(b)
ans = {}
frontier = deque([(1,0)])
while frontier:
u, prev_color = frontier.pop()
if tree.get(u) is None:
continue
for i, v in enumerate(tree[u], 1):
color = i if i != prev_color else len(tree[u])+1
ans[u, v] = color
frontier.appendleft((v, color))
print((max(ans.values())))
for edge in edges:
print((ans[edge]))
main() | 34 | 31 | 778 | 729 | import sys
input = sys.stdin.readline
from collections import deque
def readlines(n):
for _ in range(n):
a, b = list(map(int, input().split()))
yield a, b
def main():
N = int(eval(input()))
edges = list(readlines(N - 1))
tree = {i: [] for i in range(N)}
for a, b in edges:
tree[a].append(b)
ans = {}
frontier = deque([(1, 0)])
while frontier:
u, prev_color = frontier.pop()
if tree.get(u) is None:
continue
for i, v in enumerate(tree[u], 1):
color = i if i != prev_color else len(tree[u]) + 1
ans[u, v] = color
frontier.appendleft((v, color))
print((max(ans.values())))
for u, v in edges:
print((ans[u, v]))
main()
| import sys
input = sys.stdin.readline
from collections import deque
def main():
N = int(eval(input()))
tree = {i: [] for i in range(N)}
edges = []
for _ in range(N - 1):
a, b = list(map(int, input().split()))
edges.append((a, b))
tree[a].append(b)
ans = {}
frontier = deque([(1, 0)])
while frontier:
u, prev_color = frontier.pop()
if tree.get(u) is None:
continue
for i, v in enumerate(tree[u], 1):
color = i if i != prev_color else len(tree[u]) + 1
ans[u, v] = color
frontier.appendleft((v, color))
print((max(ans.values())))
for edge in edges:
print((ans[edge]))
main()
| false | 8.823529 | [
"-def readlines(n):",
"- for _ in range(n):",
"- a, b = list(map(int, input().split()))",
"- yield a, b",
"-",
"-",
"- edges = list(readlines(N - 1))",
"- for a, b in edges:",
"+ edges = []",
"+ for _ in range(N - 1):",
"+ a, b = list(map(int, input().split()))",
"+ edges.append((a, b))",
"- for u, v in edges:",
"- print((ans[u, v]))",
"+ for edge in edges:",
"+ print((ans[edge]))"
] | false | 0.041083 | 0.033226 | 1.236459 | [
"s601215923",
"s970817514"
] |
u530786533 | p02881 | python | s721937317 | s851828640 | 152 | 114 | 3,064 | 3,688 | Accepted | Accepted | 25 | n = int(eval(input()))
t = []
for i in range(1, int(n**0.5+1)):
if n % i == 0:
t.append(int(i+n/i))
print((min(t) - 2))
| def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5)+1):
if n % i == 0:
divisors.append([i, n // i])
return divisors
n = int(eval(input()))
divisors = make_divisors(n)
print((min([sum(x)-2 for x in divisors])))
| 8 | 13 | 130 | 256 | n = int(eval(input()))
t = []
for i in range(1, int(n**0.5 + 1)):
if n % i == 0:
t.append(int(i + n / i))
print((min(t) - 2))
| def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5) + 1):
if n % i == 0:
divisors.append([i, n // i])
return divisors
n = int(eval(input()))
divisors = make_divisors(n)
print((min([sum(x) - 2 for x in divisors])))
| false | 38.461538 | [
"+def make_divisors(n):",
"+ divisors = []",
"+ for i in range(1, int(n**0.5) + 1):",
"+ if n % i == 0:",
"+ divisors.append([i, n // i])",
"+ return divisors",
"+",
"+",
"-t = []",
"-for i in range(1, int(n**0.5 + 1)):",
"- if n % i == 0:",
"- t.append(int(i + n / i))",
"-print((min(t) - 2))",
"+divisors = make_divisors(n)",
"+print((min([sum(x) - 2 for x in divisors])))"
] | false | 0.045252 | 0.040265 | 1.123843 | [
"s721937317",
"s851828640"
] |
u579170193 | p03738 | python | s877386574 | s736939410 | 17 | 10 | 2,940 | 2,568 | Accepted | Accepted | 41.18 | a=int(eval(input()))-int(eval(input()));print((a>0 and'GREATER'or a<0 and'LESS'or'EQUAL')) | a=eval(input());b=eval(input());print(a<b and'LESS'or a>b and'GREATER'or'EQUAL') | 1 | 1 | 76 | 67 | a = int(eval(input())) - int(eval(input()))
print((a > 0 and "GREATER" or a < 0 and "LESS" or "EQUAL"))
| a = eval(input())
b = eval(input())
print(a < b and "LESS" or a > b and "GREATER" or "EQUAL")
| false | 0 | [
"-a = int(eval(input())) - int(eval(input()))",
"-print((a > 0 and \"GREATER\" or a < 0 and \"LESS\" or \"EQUAL\"))",
"+a = eval(input())",
"+b = eval(input())",
"+print(a < b and \"LESS\" or a > b and \"GREATER\" or \"EQUAL\")"
] | false | 0.037373 | 0.037013 | 1.009749 | [
"s877386574",
"s736939410"
] |
u671060652 | p03145 | python | s988212855 | s044916181 | 283 | 71 | 63,980 | 61,716 | Accepted | Accepted | 74.91 | import itertools
import math
import fractions
import functools
import copy
ab, bc, ca = list(map(int, input().split()))
print((ab*bc//2)) | def main():
# n = int(input())
a, b, c = list(map(int, input().split()))
# h = list(map(int, input().split()))
# s = input()
print((a*b//2))
if __name__ == '__main__':
main()
| 8 | 11 | 137 | 204 | import itertools
import math
import fractions
import functools
import copy
ab, bc, ca = list(map(int, input().split()))
print((ab * bc // 2))
| def main():
# n = int(input())
a, b, c = list(map(int, input().split()))
# h = list(map(int, input().split()))
# s = input()
print((a * b // 2))
if __name__ == "__main__":
main()
| false | 27.272727 | [
"-import itertools",
"-import math",
"-import fractions",
"-import functools",
"-import copy",
"+def main():",
"+ # n = int(input())",
"+ a, b, c = list(map(int, input().split()))",
"+ # h = list(map(int, input().split()))",
"+ # s = input()",
"+ print((a * b // 2))",
"-ab, bc, ca = list(map(int, input().split()))",
"-print((ab * bc // 2))",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.035861 | 0.03676 | 0.97553 | [
"s988212855",
"s044916181"
] |
u173072656 | p03476 | python | s486353470 | s882673151 | 818 | 733 | 33,188 | 14,772 | Accepted | Accepted | 10.39 | q = int(eval(input()))
a = [list(map(int, input().split())) for i in range(q)]
s = [0]*(2*10**5+2)
s[3] = 1
for i in range(3, 10**5):
for j in range(2, int((2*i)**0.5)+2):
if (i > j and i % j == 0) or (2*i-1) % j == 0:
b = 0
break
else:
b = 1
s[2*i-1] = b
S = [0]
for i in range(1, 10**5+1):
c = S[i-1] + s[i]
S.append(c)
for i in range(q):
print((S[a[i][1]] - S[a[i][0]-1])) | import math
from itertools import accumulate
def is_prime(n):
if n == 1:
return 0
for k in range(2, int(math.sqrt(n)) + 1):
if n % k == 0:
return 0
return 1
Q = int(eval(input()))
L = [0]*Q
R = [0]*Q
for i in range(Q):
L[i], R[i] = list(map(int, input().split()))
min_L = min(L)
max_R = max(R)
check = []
for i in range(min_L, max_R+1):
if (i % 2 == 1):
flg = (is_prime(i) and is_prime((i+1)/2))
else:
flg = 0
check.append(flg)
# 累積和
check = [0] + check
check = list(accumulate(check))
for i in range(Q):
print((check[R[i] - min_L + 1] - check[L[i] - min_L])) | 18 | 39 | 456 | 676 | q = int(eval(input()))
a = [list(map(int, input().split())) for i in range(q)]
s = [0] * (2 * 10**5 + 2)
s[3] = 1
for i in range(3, 10**5):
for j in range(2, int((2 * i) ** 0.5) + 2):
if (i > j and i % j == 0) or (2 * i - 1) % j == 0:
b = 0
break
else:
b = 1
s[2 * i - 1] = b
S = [0]
for i in range(1, 10**5 + 1):
c = S[i - 1] + s[i]
S.append(c)
for i in range(q):
print((S[a[i][1]] - S[a[i][0] - 1]))
| import math
from itertools import accumulate
def is_prime(n):
if n == 1:
return 0
for k in range(2, int(math.sqrt(n)) + 1):
if n % k == 0:
return 0
return 1
Q = int(eval(input()))
L = [0] * Q
R = [0] * Q
for i in range(Q):
L[i], R[i] = list(map(int, input().split()))
min_L = min(L)
max_R = max(R)
check = []
for i in range(min_L, max_R + 1):
if i % 2 == 1:
flg = is_prime(i) and is_prime((i + 1) / 2)
else:
flg = 0
check.append(flg)
# 累積和
check = [0] + check
check = list(accumulate(check))
for i in range(Q):
print((check[R[i] - min_L + 1] - check[L[i] - min_L]))
| false | 53.846154 | [
"-q = int(eval(input()))",
"-a = [list(map(int, input().split())) for i in range(q)]",
"-s = [0] * (2 * 10**5 + 2)",
"-s[3] = 1",
"-for i in range(3, 10**5):",
"- for j in range(2, int((2 * i) ** 0.5) + 2):",
"- if (i > j and i % j == 0) or (2 * i - 1) % j == 0:",
"- b = 0",
"- break",
"+import math",
"+from itertools import accumulate",
"+",
"+",
"+def is_prime(n):",
"+ if n == 1:",
"+ return 0",
"+ for k in range(2, int(math.sqrt(n)) + 1):",
"+ if n % k == 0:",
"+ return 0",
"+ return 1",
"+",
"+",
"+Q = int(eval(input()))",
"+L = [0] * Q",
"+R = [0] * Q",
"+for i in range(Q):",
"+ L[i], R[i] = list(map(int, input().split()))",
"+min_L = min(L)",
"+max_R = max(R)",
"+check = []",
"+for i in range(min_L, max_R + 1):",
"+ if i % 2 == 1:",
"+ flg = is_prime(i) and is_prime((i + 1) / 2)",
"- b = 1",
"- s[2 * i - 1] = b",
"-S = [0]",
"-for i in range(1, 10**5 + 1):",
"- c = S[i - 1] + s[i]",
"- S.append(c)",
"-for i in range(q):",
"- print((S[a[i][1]] - S[a[i][0] - 1]))",
"+ flg = 0",
"+ check.append(flg)",
"+# 累積和",
"+check = [0] + check",
"+check = list(accumulate(check))",
"+for i in range(Q):",
"+ print((check[R[i] - min_L + 1] - check[L[i] - min_L]))"
] | false | 0.677834 | 0.048532 | 13.966756 | [
"s486353470",
"s882673151"
] |
u852690916 | p03045 | python | s039664844 | s529840132 | 669 | 368 | 71,456 | 56,792 | Accepted | Accepted | 44.99 | N,M=list(map(int, input().split()))
E=[[] for _ in range(N)]
for _ in range(M):
x,y,z=[int(i)-1 for i in input().split()]
E[x].append(y)
E[y].append(x)
#情報のつながりがあるカードでグルーピングする
#グループIDのリスト(0は未割り当て)
G=[0]*(N+1)
def dfs(root,g):
stack=[root]
G[root]=g
while stack:
node=stack.pop()
for to in E[node]:
if G[to]==0:
G[to]=g
stack.append(to)
ans=0
for i in range(N):
if G[i]==0:
ans+=1
dfs(i,ans)
print(ans)
| import sys
def main():
input = sys.stdin.readline
N,M=list(map(int, input().split()))
uf = UnionFindTree(N)
for _ in range(M):
x,y,z=list(map(int, input().split()))
uf.union(x-1,y-1)
c=set([uf.find(i) for i in range(N)])
print((len(c)))
class UnionFindTree:
def __init__(self, n):
self.parent = [-1] * n
def find(self, x):
p = self.parent
while p[x] >= 0: x, p[x] = p[x], p[p[x]]
return x
def union(self, x, y):
x, y, p = self.find(x), self.find(y), self.parent
if x == y: return
if p[x] > p[y]: x, y = y, x
p[x], p[y] = p[x] + p[y], x
def same(self, x, y): return self.find(x) == self.find(y)
def size(self, x): return -self.parent[self.find(x)]
if __name__ == '__main__':
main() | 28 | 34 | 535 | 835 | N, M = list(map(int, input().split()))
E = [[] for _ in range(N)]
for _ in range(M):
x, y, z = [int(i) - 1 for i in input().split()]
E[x].append(y)
E[y].append(x)
# 情報のつながりがあるカードでグルーピングする
# グループIDのリスト(0は未割り当て)
G = [0] * (N + 1)
def dfs(root, g):
stack = [root]
G[root] = g
while stack:
node = stack.pop()
for to in E[node]:
if G[to] == 0:
G[to] = g
stack.append(to)
ans = 0
for i in range(N):
if G[i] == 0:
ans += 1
dfs(i, ans)
print(ans)
| import sys
def main():
input = sys.stdin.readline
N, M = list(map(int, input().split()))
uf = UnionFindTree(N)
for _ in range(M):
x, y, z = list(map(int, input().split()))
uf.union(x - 1, y - 1)
c = set([uf.find(i) for i in range(N)])
print((len(c)))
class UnionFindTree:
def __init__(self, n):
self.parent = [-1] * n
def find(self, x):
p = self.parent
while p[x] >= 0:
x, p[x] = p[x], p[p[x]]
return x
def union(self, x, y):
x, y, p = self.find(x), self.find(y), self.parent
if x == y:
return
if p[x] > p[y]:
x, y = y, x
p[x], p[y] = p[x] + p[y], x
def same(self, x, y):
return self.find(x) == self.find(y)
def size(self, x):
return -self.parent[self.find(x)]
if __name__ == "__main__":
main()
| false | 17.647059 | [
"-N, M = list(map(int, input().split()))",
"-E = [[] for _ in range(N)]",
"-for _ in range(M):",
"- x, y, z = [int(i) - 1 for i in input().split()]",
"- E[x].append(y)",
"- E[y].append(x)",
"-# 情報のつながりがあるカードでグルーピングする",
"-# グループIDのリスト(0は未割り当て)",
"-G = [0] * (N + 1)",
"+import sys",
"-def dfs(root, g):",
"- stack = [root]",
"- G[root] = g",
"- while stack:",
"- node = stack.pop()",
"- for to in E[node]:",
"- if G[to] == 0:",
"- G[to] = g",
"- stack.append(to)",
"+def main():",
"+ input = sys.stdin.readline",
"+ N, M = list(map(int, input().split()))",
"+ uf = UnionFindTree(N)",
"+ for _ in range(M):",
"+ x, y, z = list(map(int, input().split()))",
"+ uf.union(x - 1, y - 1)",
"+ c = set([uf.find(i) for i in range(N)])",
"+ print((len(c)))",
"-ans = 0",
"-for i in range(N):",
"- if G[i] == 0:",
"- ans += 1",
"- dfs(i, ans)",
"-print(ans)",
"+class UnionFindTree:",
"+ def __init__(self, n):",
"+ self.parent = [-1] * n",
"+",
"+ def find(self, x):",
"+ p = self.parent",
"+ while p[x] >= 0:",
"+ x, p[x] = p[x], p[p[x]]",
"+ return x",
"+",
"+ def union(self, x, y):",
"+ x, y, p = self.find(x), self.find(y), self.parent",
"+ if x == y:",
"+ return",
"+ if p[x] > p[y]:",
"+ x, y = y, x",
"+ p[x], p[y] = p[x] + p[y], x",
"+",
"+ def same(self, x, y):",
"+ return self.find(x) == self.find(y)",
"+",
"+ def size(self, x):",
"+ return -self.parent[self.find(x)]",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.045911 | 0.088393 | 0.519396 | [
"s039664844",
"s529840132"
] |
u389910364 | p03112 | python | s673626085 | s375603537 | 1,722 | 1,102 | 12,092 | 47,504 | Accepted | Accepted | 36 | import bisect
s_len, t_len, q = list(map(int, input().split()))
shrines = []
temples = []
for _ in range(s_len):
shrines.append(int(eval(input())))
for _ in range(t_len):
temples.append(int(eval(input())))
def distance(s_i, t_i, x):
"""
s_i と t_i を最短でまわる距離。無効なインデックスなら inf を返す
"""
if 0 <= s_i < s_len and 0 <= t_i < t_len:
s = shrines[s_i]
t = temples[t_i]
if s >= x <= t:
return max(s, t) - x
elif s <= x >= t:
return x - min(s, t)
else:
return abs(s - t) + min(abs(x - t), abs(x - s))
else:
return float('inf')
def solve(x):
s_i = bisect.bisect_left(shrines, x)
t_i = bisect.bisect_left(temples, x)
return min([
distance(s_i, t_i, x),
distance(s_i, t_i - 1, x),
distance(s_i - 1, t_i, x),
distance(s_i - 1, t_i - 1, x),
])
for _ in range(q):
print((solve(int(eval(input())))))
| import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor
import numpy as np
if os.getenv("LOCAL"):
sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353
A, B, Q = list(map(int, sys.stdin.buffer.readline().split()))
S = [int(sys.stdin.buffer.readline()) for _ in range(A)]
T = [int(sys.stdin.buffer.readline()) for _ in range(B)]
X = [int(sys.stdin.buffer.readline()) for _ in range(Q)]
st_i = np.searchsorted(T, S).tolist()
ts_i = np.searchsorted(S, T).tolist()
st = []
ts = []
for s, i in zip(S, st_i):
d = INF
if 0 < i:
d = min(d, abs(T[i - 1] - s))
if i < len(T):
d = min(d, abs(T[i] - s))
st.append(d)
for t, i in zip(T, ts_i):
d = INF
if 0 < i:
d = min(d, abs(S[i - 1] - t))
if i < len(S):
d = min(d, abs(S[i] - t))
ts.append(d)
ans = []
for x in X:
d = INF
si = bisect.bisect_left(S, x)
if 0 < si:
d = min(d, abs(S[si - 1] - x) + st[si - 1])
if si < len(S):
d = min(d, abs(S[si] - x) + st[si])
ti = bisect.bisect_left(T, x)
if 0 < ti:
d = min(d, abs(T[ti - 1] - x) + ts[ti - 1])
if ti < len(T):
d = min(d, abs(T[ti] - x) + ts[ti])
ans .append(d)
print(*ans, sep='\n')
| 42 | 70 | 966 | 1,657 | import bisect
s_len, t_len, q = list(map(int, input().split()))
shrines = []
temples = []
for _ in range(s_len):
shrines.append(int(eval(input())))
for _ in range(t_len):
temples.append(int(eval(input())))
def distance(s_i, t_i, x):
"""
s_i と t_i を最短でまわる距離。無効なインデックスなら inf を返す
"""
if 0 <= s_i < s_len and 0 <= t_i < t_len:
s = shrines[s_i]
t = temples[t_i]
if s >= x <= t:
return max(s, t) - x
elif s <= x >= t:
return x - min(s, t)
else:
return abs(s - t) + min(abs(x - t), abs(x - s))
else:
return float("inf")
def solve(x):
s_i = bisect.bisect_left(shrines, x)
t_i = bisect.bisect_left(temples, x)
return min(
[
distance(s_i, t_i, x),
distance(s_i, t_i - 1, x),
distance(s_i - 1, t_i, x),
distance(s_i - 1, t_i - 1, x),
]
)
for _ in range(q):
print((solve(int(eval(input())))))
| import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor
import numpy as np
if os.getenv("LOCAL"):
sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(10**9)
INF = float("inf")
IINF = 10**18
MOD = 10**9 + 7
# MOD = 998244353
A, B, Q = list(map(int, sys.stdin.buffer.readline().split()))
S = [int(sys.stdin.buffer.readline()) for _ in range(A)]
T = [int(sys.stdin.buffer.readline()) for _ in range(B)]
X = [int(sys.stdin.buffer.readline()) for _ in range(Q)]
st_i = np.searchsorted(T, S).tolist()
ts_i = np.searchsorted(S, T).tolist()
st = []
ts = []
for s, i in zip(S, st_i):
d = INF
if 0 < i:
d = min(d, abs(T[i - 1] - s))
if i < len(T):
d = min(d, abs(T[i] - s))
st.append(d)
for t, i in zip(T, ts_i):
d = INF
if 0 < i:
d = min(d, abs(S[i - 1] - t))
if i < len(S):
d = min(d, abs(S[i] - t))
ts.append(d)
ans = []
for x in X:
d = INF
si = bisect.bisect_left(S, x)
if 0 < si:
d = min(d, abs(S[si - 1] - x) + st[si - 1])
if si < len(S):
d = min(d, abs(S[si] - x) + st[si])
ti = bisect.bisect_left(T, x)
if 0 < ti:
d = min(d, abs(T[ti - 1] - x) + ts[ti - 1])
if ti < len(T):
d = min(d, abs(T[ti] - x) + ts[ti])
ans.append(d)
print(*ans, sep="\n")
| false | 40 | [
"+import cmath",
"+import heapq",
"+import itertools",
"+import math",
"+import operator",
"+import os",
"+import re",
"+import string",
"+import sys",
"+from collections import Counter, deque, defaultdict",
"+from copy import deepcopy",
"+from decimal import Decimal",
"+from fractions import gcd",
"+from functools import lru_cache, reduce",
"+from operator import itemgetter, mul, add, xor",
"+import numpy as np",
"-s_len, t_len, q = list(map(int, input().split()))",
"-shrines = []",
"-temples = []",
"-for _ in range(s_len):",
"- shrines.append(int(eval(input())))",
"-for _ in range(t_len):",
"- temples.append(int(eval(input())))",
"-",
"-",
"-def distance(s_i, t_i, x):",
"- \"\"\"",
"- s_i と t_i を最短でまわる距離。無効なインデックスなら inf を返す",
"- \"\"\"",
"- if 0 <= s_i < s_len and 0 <= t_i < t_len:",
"- s = shrines[s_i]",
"- t = temples[t_i]",
"- if s >= x <= t:",
"- return max(s, t) - x",
"- elif s <= x >= t:",
"- return x - min(s, t)",
"- else:",
"- return abs(s - t) + min(abs(x - t), abs(x - s))",
"- else:",
"- return float(\"inf\")",
"-",
"-",
"-def solve(x):",
"- s_i = bisect.bisect_left(shrines, x)",
"- t_i = bisect.bisect_left(temples, x)",
"- return min(",
"- [",
"- distance(s_i, t_i, x),",
"- distance(s_i, t_i - 1, x),",
"- distance(s_i - 1, t_i, x),",
"- distance(s_i - 1, t_i - 1, x),",
"- ]",
"- )",
"-",
"-",
"-for _ in range(q):",
"- print((solve(int(eval(input())))))",
"+if os.getenv(\"LOCAL\"):",
"+ sys.stdin = open(\"_in.txt\", \"r\")",
"+sys.setrecursionlimit(10**9)",
"+INF = float(\"inf\")",
"+IINF = 10**18",
"+MOD = 10**9 + 7",
"+# MOD = 998244353",
"+A, B, Q = list(map(int, sys.stdin.buffer.readline().split()))",
"+S = [int(sys.stdin.buffer.readline()) for _ in range(A)]",
"+T = [int(sys.stdin.buffer.readline()) for _ in range(B)]",
"+X = [int(sys.stdin.buffer.readline()) for _ in range(Q)]",
"+st_i = np.searchsorted(T, S).tolist()",
"+ts_i = np.searchsorted(S, T).tolist()",
"+st = []",
"+ts = []",
"+for s, i in zip(S, st_i):",
"+ d = INF",
"+ if 0 < i:",
"+ d = min(d, abs(T[i - 1] - s))",
"+ if i < len(T):",
"+ d = min(d, abs(T[i] - s))",
"+ st.append(d)",
"+for t, i in zip(T, ts_i):",
"+ d = INF",
"+ if 0 < i:",
"+ d = min(d, abs(S[i - 1] - t))",
"+ if i < len(S):",
"+ d = min(d, abs(S[i] - t))",
"+ ts.append(d)",
"+ans = []",
"+for x in X:",
"+ d = INF",
"+ si = bisect.bisect_left(S, x)",
"+ if 0 < si:",
"+ d = min(d, abs(S[si - 1] - x) + st[si - 1])",
"+ if si < len(S):",
"+ d = min(d, abs(S[si] - x) + st[si])",
"+ ti = bisect.bisect_left(T, x)",
"+ if 0 < ti:",
"+ d = min(d, abs(T[ti - 1] - x) + ts[ti - 1])",
"+ if ti < len(T):",
"+ d = min(d, abs(T[ti] - x) + ts[ti])",
"+ ans.append(d)",
"+print(*ans, sep=\"\\n\")"
] | false | 0.03893 | 0.221105 | 0.176068 | [
"s673626085",
"s375603537"
] |
u067975558 | p02412 | python | s552436539 | s507210699 | 630 | 580 | 6,724 | 6,724 | Accepted | Accepted | 7.94 | while True:
(n, x) = [int(i) for i in input().split()]
if n == x == 0:
break
count = 0
for i in range(1, n + 1):
for j in range(i + 1, n + 1):
for k in range(j + 1, n + 1):
if i + j + k == x:
count += 1
print(count) | while True:
(n, x) = [int(i) for i in input().split()]
if n == x == 0:
break
count = 0
for i in range(1, n + 1):
for j in range(i + 1, n + 1):
for k in range(j + 1, n + 1):
if x - (i + j + k) == 0:
count += 1
if x - (i + j + k) < 0:
break
print(count) | 11 | 13 | 309 | 383 | while True:
(n, x) = [int(i) for i in input().split()]
if n == x == 0:
break
count = 0
for i in range(1, n + 1):
for j in range(i + 1, n + 1):
for k in range(j + 1, n + 1):
if i + j + k == x:
count += 1
print(count)
| while True:
(n, x) = [int(i) for i in input().split()]
if n == x == 0:
break
count = 0
for i in range(1, n + 1):
for j in range(i + 1, n + 1):
for k in range(j + 1, n + 1):
if x - (i + j + k) == 0:
count += 1
if x - (i + j + k) < 0:
break
print(count)
| false | 15.384615 | [
"- if i + j + k == x:",
"+ if x - (i + j + k) == 0:",
"+ if x - (i + j + k) < 0:",
"+ break"
] | false | 0.045019 | 0.044121 | 1.020344 | [
"s552436539",
"s507210699"
] |
u573754721 | p02951 | python | s894494508 | s745081365 | 163 | 21 | 38,256 | 3,316 | Accepted | Accepted | 87.12 | lis = list(map(int, input().split()))
if lis[2] - (lis[0] - lis[1]) > 0:
print((lis[2] - (lis[0] - lis[1])))
else:
print((0)) | a,b,c=list(map(int,input().split()))
print((c-(a-b) if c-(a-b)>0 else 0)) | 6 | 2 | 135 | 66 | lis = list(map(int, input().split()))
if lis[2] - (lis[0] - lis[1]) > 0:
print((lis[2] - (lis[0] - lis[1])))
else:
print((0))
| a, b, c = list(map(int, input().split()))
print((c - (a - b) if c - (a - b) > 0 else 0))
| false | 66.666667 | [
"-lis = list(map(int, input().split()))",
"-if lis[2] - (lis[0] - lis[1]) > 0:",
"- print((lis[2] - (lis[0] - lis[1])))",
"-else:",
"- print((0))",
"+a, b, c = list(map(int, input().split()))",
"+print((c - (a - b) if c - (a - b) > 0 else 0))"
] | false | 0.040593 | 0.036082 | 1.125039 | [
"s894494508",
"s745081365"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.