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
sequence | 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
sequence |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
u517910772 | p03805 | python | s423210976 | s993156111 | 68 | 28 | 4,328 | 3,064 | Accepted | Accepted | 58.82 | def abc054_c_one_stroke_paths():
import copy
N, M = list(map(int, input().split()))
# create graph G
G = {}
for m in range(M):
a, z = list(map(int, input().split()))
G[a] = G.get(a, [])
G[a].append(z)
G[z] = G.get(z, [])
G[z].append(a)
# print(G)
# find all paths
if G.get(1, 0) == 0:
print((0))
return
paths = []
def solve(a, path):
path.append(a)
if len(path) == N:
paths.append(path)
return
for z in G.get(a):
p = copy.copy(path)
if z in p:
continue
solve(z, p)
solve(1, [])
# print(paths)
print((len(paths)))
##########
if __name__ == "__main__":
abc054_c_one_stroke_paths()
| def abc054_c_one_stroke_paths():
N, M = list(map(int, input().split()))
# create graph G
G = {}
for m in range(M):
a, z = list(map(int, input().split()))
G[a] = G.get(a, [])
G[a].append(z)
G[z] = G.get(z, [])
G[z].append(a)
# print(G)
# find all paths
if G.get(1, 0) == 0:
print((0))
return
def dfs(a, path):
path.append(a)
if len(path) == N:
return 1
paths = 0
for z in G.get(a):
if z in path:
continue
paths += dfs(z, path[:])
return paths
print((dfs(1, [])))
##########
if __name__ == "__main__":
abc054_c_one_stroke_paths()
| 41 | 38 | 823 | 746 | def abc054_c_one_stroke_paths():
import copy
N, M = list(map(int, input().split()))
# create graph G
G = {}
for m in range(M):
a, z = list(map(int, input().split()))
G[a] = G.get(a, [])
G[a].append(z)
G[z] = G.get(z, [])
G[z].append(a)
# print(G)
# find all paths
if G.get(1, 0) == 0:
print((0))
return
paths = []
def solve(a, path):
path.append(a)
if len(path) == N:
paths.append(path)
return
for z in G.get(a):
p = copy.copy(path)
if z in p:
continue
solve(z, p)
solve(1, [])
# print(paths)
print((len(paths)))
##########
if __name__ == "__main__":
abc054_c_one_stroke_paths()
| def abc054_c_one_stroke_paths():
N, M = list(map(int, input().split()))
# create graph G
G = {}
for m in range(M):
a, z = list(map(int, input().split()))
G[a] = G.get(a, [])
G[a].append(z)
G[z] = G.get(z, [])
G[z].append(a)
# print(G)
# find all paths
if G.get(1, 0) == 0:
print((0))
return
def dfs(a, path):
path.append(a)
if len(path) == N:
return 1
paths = 0
for z in G.get(a):
if z in path:
continue
paths += dfs(z, path[:])
return paths
print((dfs(1, [])))
##########
if __name__ == "__main__":
abc054_c_one_stroke_paths()
| false | 7.317073 | [
"- import copy",
"-",
"- paths = []",
"- def solve(a, path):",
"+ def dfs(a, path):",
"- paths.append(path)",
"- return",
"+ return 1",
"+ paths = 0",
"- p = copy.copy(path)",
"- if z in p:",
"+ if z in path:",
"- solve(z, p)",
"+ paths += dfs(z, path[:])",
"+ return paths",
"- solve(1, [])",
"- # print(paths)",
"- print((len(paths)))",
"+ print((dfs(1, [])))"
] | false | 0.075865 | 0.039852 | 1.903654 | [
"s423210976",
"s993156111"
] |
u744034042 | p03370 | python | s121758588 | s022217063 | 36 | 17 | 2,940 | 2,940 | Accepted | Accepted | 52.78 | n, x = list(map(int, input().split()))
m = [int(a) for a in [eval(input()) for i in range(n)]]
x = x - sum(m)
y = min(m)
while x >= y:
x -= y
n += 1
print(n) | n,x = list(map(int,input().split()))
m = [int(a) for a in [eval(input()) for i in range(n)]]
print((n + (x - sum(m))//min(m))) | 8 | 3 | 156 | 114 | n, x = list(map(int, input().split()))
m = [int(a) for a in [eval(input()) for i in range(n)]]
x = x - sum(m)
y = min(m)
while x >= y:
x -= y
n += 1
print(n)
| n, x = list(map(int, input().split()))
m = [int(a) for a in [eval(input()) for i in range(n)]]
print((n + (x - sum(m)) // min(m)))
| false | 62.5 | [
"-x = x - sum(m)",
"-y = min(m)",
"-while x >= y:",
"- x -= y",
"- n += 1",
"-print(n)",
"+print((n + (x - sum(m)) // min(m)))"
] | false | 0.093803 | 0.117953 | 0.795263 | [
"s121758588",
"s022217063"
] |
u047796752 | p02773 | python | s359779881 | s465932471 | 1,090 | 470 | 102,736 | 154,868 | Accepted | Accepted | 56.88 | from collections import Counter
N = int(eval(input()))
l = [eval(input()) for _ in range(N)]
cnt = Counter(l)
M = max(list(cnt.values()))
ans = []
for k in list(cnt.keys()):
if cnt[k]==M:
ans.append(k)
ans.sort()
for ans_i in ans:
print(ans_i) | from collections import Counter
N = int(eval(input()))
S = [eval(input()) for _ in range(N)]
cnt = Counter(S)
M = max(list(cnt.values()))
ans = []
for k, v in list(cnt.items()):
if v==M:
ans.append(k)
ans.sort()
for ans_i in ans:
print(ans_i) | 16 | 16 | 260 | 259 | from collections import Counter
N = int(eval(input()))
l = [eval(input()) for _ in range(N)]
cnt = Counter(l)
M = max(list(cnt.values()))
ans = []
for k in list(cnt.keys()):
if cnt[k] == M:
ans.append(k)
ans.sort()
for ans_i in ans:
print(ans_i)
| from collections import Counter
N = int(eval(input()))
S = [eval(input()) for _ in range(N)]
cnt = Counter(S)
M = max(list(cnt.values()))
ans = []
for k, v in list(cnt.items()):
if v == M:
ans.append(k)
ans.sort()
for ans_i in ans:
print(ans_i)
| false | 0 | [
"-l = [eval(input()) for _ in range(N)]",
"-cnt = Counter(l)",
"+S = [eval(input()) for _ in range(N)]",
"+cnt = Counter(S)",
"-for k in list(cnt.keys()):",
"- if cnt[k] == M:",
"+for k, v in list(cnt.items()):",
"+ if v == M:"
] | false | 0.045995 | 0.088422 | 0.520172 | [
"s359779881",
"s465932471"
] |
u197955752 | p03147 | python | s478984195 | s657292871 | 28 | 20 | 3,064 | 3,060 | Accepted | Accepted | 28.57 | N = int(eval(input()))
h = [int(x) for x in input().split()]
ans = 0
sum_height = sum(h)
while sum_height > 0:
i = 0
while i < N:
while i < N and h[i] == 0:
i += 1
if i < N:
ans += 1
while i < N and h[i] > 0:
h[i] -= 1
sum_height -= 1
i += 1
print(ans) | N = int(eval(input()))
h = [int(x) for x in input().split()]
ans = 0
sum_height = sum(h)
while sum_height > 0:
for i in range(N):
if h[i] == 0:
pos = False
continue
elif (i == 0 and h[i] > 0) or (i > 0 and not pos):
ans += 1
h[i] -= 1
sum_height -= 1
pos = True
print(ans)
| 18 | 17 | 357 | 365 | N = int(eval(input()))
h = [int(x) for x in input().split()]
ans = 0
sum_height = sum(h)
while sum_height > 0:
i = 0
while i < N:
while i < N and h[i] == 0:
i += 1
if i < N:
ans += 1
while i < N and h[i] > 0:
h[i] -= 1
sum_height -= 1
i += 1
print(ans)
| N = int(eval(input()))
h = [int(x) for x in input().split()]
ans = 0
sum_height = sum(h)
while sum_height > 0:
for i in range(N):
if h[i] == 0:
pos = False
continue
elif (i == 0 and h[i] > 0) or (i > 0 and not pos):
ans += 1
h[i] -= 1
sum_height -= 1
pos = True
print(ans)
| false | 5.555556 | [
"- i = 0",
"- while i < N:",
"- while i < N and h[i] == 0:",
"- i += 1",
"- if i < N:",
"+ for i in range(N):",
"+ if h[i] == 0:",
"+ pos = False",
"+ continue",
"+ elif (i == 0 and h[i] > 0) or (i > 0 and not pos):",
"- while i < N and h[i] > 0:",
"- h[i] -= 1",
"- sum_height -= 1",
"- i += 1",
"+ h[i] -= 1",
"+ sum_height -= 1",
"+ pos = True"
] | false | 0.144073 | 0.084976 | 1.695467 | [
"s478984195",
"s657292871"
] |
u341926204 | p03162 | python | s775914703 | s559323854 | 1,194 | 669 | 21,552 | 74,712 | Accepted | Accepted | 43.97 | import numpy as np
N = int(eval(input()))
ABC = np.zeros([N, 3])
for i in range(N):
ABC[i] = list(map(int, input().split()))
dp = np.zeros([N, 3])
dp[0] = ABC[0]
for i in range(N-1):
dp[i+1, 0] = max(dp[i, 1], dp[i, 2]) + ABC[i+1, 0]
dp[i+1, 1] = max(dp[i, 0], dp[i, 2]) + ABC[i+1, 1]
dp[i+1, 2] = max(dp[i, 0], dp[i, 1]) + ABC[i+1, 2]
print((int(max(dp[N-1])))) | N = int(eval(input()))
ABC = []
for i in range(N):
ABC.append(list(map(int, input().split())))
dp = [[0]*3 for _ in range(N)]
dp[0] = ABC[0]
for i in range(N-1):
dp[i+1][0] = max(dp[i][1], dp[i][2]) + ABC[i+1][0]
dp[i+1][1] = max(dp[i][0], dp[i][2]) + ABC[i+1][1]
dp[i+1][2] = max(dp[i][0], dp[i][1]) + ABC[i+1][2]
print((max(dp[N-1]))) | 14 | 13 | 385 | 358 | import numpy as np
N = int(eval(input()))
ABC = np.zeros([N, 3])
for i in range(N):
ABC[i] = list(map(int, input().split()))
dp = np.zeros([N, 3])
dp[0] = ABC[0]
for i in range(N - 1):
dp[i + 1, 0] = max(dp[i, 1], dp[i, 2]) + ABC[i + 1, 0]
dp[i + 1, 1] = max(dp[i, 0], dp[i, 2]) + ABC[i + 1, 1]
dp[i + 1, 2] = max(dp[i, 0], dp[i, 1]) + ABC[i + 1, 2]
print((int(max(dp[N - 1]))))
| N = int(eval(input()))
ABC = []
for i in range(N):
ABC.append(list(map(int, input().split())))
dp = [[0] * 3 for _ in range(N)]
dp[0] = ABC[0]
for i in range(N - 1):
dp[i + 1][0] = max(dp[i][1], dp[i][2]) + ABC[i + 1][0]
dp[i + 1][1] = max(dp[i][0], dp[i][2]) + ABC[i + 1][1]
dp[i + 1][2] = max(dp[i][0], dp[i][1]) + ABC[i + 1][2]
print((max(dp[N - 1])))
| false | 7.142857 | [
"-import numpy as np",
"-",
"-ABC = np.zeros([N, 3])",
"+ABC = []",
"- ABC[i] = list(map(int, input().split()))",
"-dp = np.zeros([N, 3])",
"+ ABC.append(list(map(int, input().split())))",
"+dp = [[0] * 3 for _ in range(N)]",
"- dp[i + 1, 0] = max(dp[i, 1], dp[i, 2]) + ABC[i + 1, 0]",
"- dp[i + 1, 1] = max(dp[i, 0], dp[i, 2]) + ABC[i + 1, 1]",
"- dp[i + 1, 2] = max(dp[i, 0], dp[i, 1]) + ABC[i + 1, 2]",
"-print((int(max(dp[N - 1]))))",
"+ dp[i + 1][0] = max(dp[i][1], dp[i][2]) + ABC[i + 1][0]",
"+ dp[i + 1][1] = max(dp[i][0], dp[i][2]) + ABC[i + 1][1]",
"+ dp[i + 1][2] = max(dp[i][0], dp[i][1]) + ABC[i + 1][2]",
"+print((max(dp[N - 1])))"
] | false | 0.503057 | 0.033963 | 14.81174 | [
"s775914703",
"s559323854"
] |
u600402037 | p02971 | python | s151900644 | s280873228 | 418 | 292 | 50,852 | 50,844 | Accepted | Accepted | 30.14 | import sys
import numpy as np
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N = ir()
A = np.zeros(N+2, np.int32)
A[1:-1] = np.array([ir() for _ in range(N)])
left_max = np.maximum.accumulate(A[:-2])
right_max = np.maximum.accumulate(A[::-1])[::-1][2:]
answer = np.maximum(left_max, right_max)
print(('\n'.join(answer.astype(str))))
| import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
N = int(readline())
A = np.zeros(N+2,np.int32)
A[1:-1] = np.array(read().split(),np.int32)
left_max = np.maximum.accumulate(A[:-2])
right_max = np.maximum.accumulate(A[::-1])[::-1][2:]
answer = np.maximum(left_max, right_max)
print(('\n'.join(answer.astype(str))))
| 15 | 15 | 409 | 417 | import sys
import numpy as np
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N = ir()
A = np.zeros(N + 2, np.int32)
A[1:-1] = np.array([ir() for _ in range(N)])
left_max = np.maximum.accumulate(A[:-2])
right_max = np.maximum.accumulate(A[::-1])[::-1][2:]
answer = np.maximum(left_max, right_max)
print(("\n".join(answer.astype(str))))
| import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
N = int(readline())
A = np.zeros(N + 2, np.int32)
A[1:-1] = np.array(read().split(), np.int32)
left_max = np.maximum.accumulate(A[:-2])
right_max = np.maximum.accumulate(A[::-1])[::-1][2:]
answer = np.maximum(left_max, right_max)
print(("\n".join(answer.astype(str))))
| false | 0 | [
"+",
"+read = sys.stdin.buffer.read",
"+readline = sys.stdin.buffer.readline",
"+readlines = sys.stdin.buffer.readlines",
"-sr = lambda: sys.stdin.readline().rstrip()",
"-ir = lambda: int(sr())",
"-lr = lambda: list(map(int, sr().split()))",
"-N = ir()",
"+N = int(readline())",
"-A[1:-1] = np.array([ir() for _ in range(N)])",
"+A[1:-1] = np.array(read().split(), np.int32)"
] | false | 0.49001 | 0.208008 | 2.355726 | [
"s151900644",
"s280873228"
] |
u006326793 | p02393 | python | s380570319 | s492823572 | 50 | 20 | 7,608 | 5,588 | Accepted | Accepted | 60 | # -*- coding utf-8 -*-
l = list(map(int,input().split()))
l.sort()
desc = "{0} {1} {2}".format(l[0],l[1],l[2])
print(desc) | # -*- coding: utf-8 -*-
l = list(map(int, input().split()))
l.sort()
l = list(map(str,l))
l = ' '.join(l)
print(l)
| 5 | 8 | 126 | 118 | # -*- coding utf-8 -*-
l = list(map(int, input().split()))
l.sort()
desc = "{0} {1} {2}".format(l[0], l[1], l[2])
print(desc)
| # -*- coding: utf-8 -*-
l = list(map(int, input().split()))
l.sort()
l = list(map(str, l))
l = " ".join(l)
print(l)
| false | 37.5 | [
"-# -*- coding utf-8 -*-",
"+# -*- coding: utf-8 -*-",
"-desc = \"{0} {1} {2}\".format(l[0], l[1], l[2])",
"-print(desc)",
"+l = list(map(str, l))",
"+l = \" \".join(l)",
"+print(l)"
] | false | 0.038561 | 0.03909 | 0.986468 | [
"s380570319",
"s492823572"
] |
u316584871 | p02379 | python | s000224252 | s074742193 | 30 | 20 | 5,652 | 5,648 | Accepted | Accepted | 33.33 | from math import sqrt
x1, y1, x2, y2 = list(map(float, input().split()))
r = sqrt((x1 - x2)**2 + (y1 - y2)**2 )
print(('{0:.5f}'.format(r)))
| from math import sqrt
x1, y1, x2, y2 = list(map(float, input().split()))
r = sqrt((x1 - x2)**2 + (y1 - y2)**2 )
print(r)
| 4 | 4 | 136 | 118 | from math import sqrt
x1, y1, x2, y2 = list(map(float, input().split()))
r = sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)
print(("{0:.5f}".format(r)))
| from math import sqrt
x1, y1, x2, y2 = list(map(float, input().split()))
r = sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)
print(r)
| false | 0 | [
"-print((\"{0:.5f}\".format(r)))",
"+print(r)"
] | false | 0.035601 | 0.032454 | 1.096945 | [
"s000224252",
"s074742193"
] |
u423002653 | p02814 | python | s133135292 | s278040891 | 635 | 186 | 13,136 | 45,720 | Accepted | Accepted | 70.71 | from fractions import gcd
def lcm(arr, n):
ans = arr[0]
for i in range(1, n):
ans = ((arr[i] * ans) // gcd(arr[i], ans))
return int(ans)
n, m = [int(x) for x in input().split()]
arr = [int(x) for x in input().split()]
v = []
for x in arr:
y = x
cnt = 0
while y % 2 == 0:
y = y // 2
cnt += 1
v.append(cnt)
mx = max(v)
mn = min(v)
if mx != mn:
print((0))
else:
strt = lcm(arr, n) // 2
if strt > m:
print((0))
else:
print((int(1 + int((m - strt)) // int((2 * strt)))))
| from fractions import gcd
def lcm(arr, n):
ans = arr[0]
for i in range(1, n):
ans = ((arr[i] * ans) // gcd(arr[i], ans))
return ans
n, m = [int(x) for x in input().split()]
arr = [int(x) for x in input().split()]
v = []
for x in arr:
y = x
cnt = 0
while y % 2 == 0:
y = y // 2
cnt += 1
v.append(cnt)
mx = max(v)
mn = min(v)
if mx != mn:
print(0)
else:
strt = lcm(arr, n) // 2
if strt > m:
print(0)
else:
print(1 + (m - strt) // (2 * strt))
| 27 | 27 | 579 | 556 | from fractions import gcd
def lcm(arr, n):
ans = arr[0]
for i in range(1, n):
ans = (arr[i] * ans) // gcd(arr[i], ans)
return int(ans)
n, m = [int(x) for x in input().split()]
arr = [int(x) for x in input().split()]
v = []
for x in arr:
y = x
cnt = 0
while y % 2 == 0:
y = y // 2
cnt += 1
v.append(cnt)
mx = max(v)
mn = min(v)
if mx != mn:
print((0))
else:
strt = lcm(arr, n) // 2
if strt > m:
print((0))
else:
print((int(1 + int((m - strt)) // int((2 * strt)))))
| from fractions import gcd
def lcm(arr, n):
ans = arr[0]
for i in range(1, n):
ans = (arr[i] * ans) // gcd(arr[i], ans)
return ans
n, m = [int(x) for x in input().split()]
arr = [int(x) for x in input().split()]
v = []
for x in arr:
y = x
cnt = 0
while y % 2 == 0:
y = y // 2
cnt += 1
v.append(cnt)
mx = max(v)
mn = min(v)
if mx != mn:
print(0)
else:
strt = lcm(arr, n) // 2
if strt > m:
print(0)
else:
print(1 + (m - strt) // (2 * strt))
| false | 0 | [
"- return int(ans)",
"+ return ans",
"- print((0))",
"+ print(0)",
"- print((0))",
"+ print(0)",
"- print((int(1 + int((m - strt)) // int((2 * strt)))))",
"+ print(1 + (m - strt) // (2 * strt))"
] | false | 0.198383 | 0.055422 | 3.579515 | [
"s133135292",
"s278040891"
] |
u585482323 | p02901 | python | s688666937 | s945734108 | 725 | 255 | 135,948 | 42,584 | Accepted | Accepted | 64.83 | #!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007
#A
def A():
n = I()
print(((n-(n>>1))/n))
return
#B
def B():
n,k = LI()
h = LI()
ans = 0
for i in h:
if i >= k:
ans += 1
print(ans)
return
#C
def C():
n = I()
a = LI()
b = [(a[i],i+1) for i in range(n)]
b.sort()
ans = [b[i][1] for i in range(n)]
print((*ans))
return
#D
def D():
def divisor(n):
if n < 4:
return set([n])
res = set([1])
i = 2
m = n
while i**2 <= n:
if m%i == 0:
while m%i == 0:
m //= i
res.add(i)
i += 1
res.add(m)
return res
a,b = LI()
if min(a,b) == 1:
print((1))
return
s = divisor(a)
t = divisor(b)
s &= t
print((len(s)))
return
#E
def E():
n,m = LI()
v = []
for i in range(m):
a,b = LI()
c = LI()
s = 0
for j in c:
s |= 1<<(j-1)
v.append((a,s))
l = 1<<n
dp = [[float("inf")]*l for i in range(m+1)]
dp[0][0] = 0
for i in range(m):
ni = i+1
a,c = v[i]
for b in range(l):
if dp[i][b] == float("inf"):
continue
nb = b|c
nd = dp[i][b]+a
if nd < dp[ni][nb]:
dp[ni][nb] = nd
nd = dp[i][b]
if nd < dp[ni][b]:
dp[ni][b] = nd
if dp[m][-1] == float("inf"):
print((-1))
else:
print((dp[m][-1]))
return
#F
def F():
return
#Solve
if __name__ == "__main__":
E()
| #!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007
def solve():
n,m = LI()
g = []
for _ in range(m):
a,_ = LI()
c = LI()
b = 0
for i in c:
b |= 1<<(i-1)
g.append((b,a))
B = 1<<n
dp = [float("inf")]*B
dp[0] = 0
for b in range(B):
for i,v in g:
nb = b|i
nd = dp[b]+v
if nd < dp[nb]:
dp[nb] = nd
ans = dp[-1]
if ans == float("inf"):
print((-1))
else:
print(ans)
return
#Solve
if __name__ == "__main__":
solve()
| 121 | 56 | 2,387 | 1,303 | #!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI():
return [int(x) for x in sys.stdin.readline().split()]
def I():
return int(sys.stdin.readline())
def LS():
return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007
# A
def A():
n = I()
print(((n - (n >> 1)) / n))
return
# B
def B():
n, k = LI()
h = LI()
ans = 0
for i in h:
if i >= k:
ans += 1
print(ans)
return
# C
def C():
n = I()
a = LI()
b = [(a[i], i + 1) for i in range(n)]
b.sort()
ans = [b[i][1] for i in range(n)]
print((*ans))
return
# D
def D():
def divisor(n):
if n < 4:
return set([n])
res = set([1])
i = 2
m = n
while i**2 <= n:
if m % i == 0:
while m % i == 0:
m //= i
res.add(i)
i += 1
res.add(m)
return res
a, b = LI()
if min(a, b) == 1:
print((1))
return
s = divisor(a)
t = divisor(b)
s &= t
print((len(s)))
return
# E
def E():
n, m = LI()
v = []
for i in range(m):
a, b = LI()
c = LI()
s = 0
for j in c:
s |= 1 << (j - 1)
v.append((a, s))
l = 1 << n
dp = [[float("inf")] * l for i in range(m + 1)]
dp[0][0] = 0
for i in range(m):
ni = i + 1
a, c = v[i]
for b in range(l):
if dp[i][b] == float("inf"):
continue
nb = b | c
nd = dp[i][b] + a
if nd < dp[ni][nb]:
dp[ni][nb] = nd
nd = dp[i][b]
if nd < dp[ni][b]:
dp[ni][b] = nd
if dp[m][-1] == float("inf"):
print((-1))
else:
print((dp[m][-1]))
return
# F
def F():
return
# Solve
if __name__ == "__main__":
E()
| #!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI():
return [int(x) for x in sys.stdin.buffer.readline().split()]
def I():
return int(sys.stdin.buffer.readline())
def LS():
return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007
def solve():
n, m = LI()
g = []
for _ in range(m):
a, _ = LI()
c = LI()
b = 0
for i in c:
b |= 1 << (i - 1)
g.append((b, a))
B = 1 << n
dp = [float("inf")] * B
dp[0] = 0
for b in range(B):
for i, v in g:
nb = b | i
nd = dp[b] + v
if nd < dp[nb]:
dp[nb] = nd
ans = dp[-1]
if ans == float("inf"):
print((-1))
else:
print(ans)
return
# Solve
if __name__ == "__main__":
solve()
| false | 53.719008 | [
"+from itertools import permutations, accumulate",
"-import random",
"- return [int(x) for x in sys.stdin.readline().split()]",
"+ return [int(x) for x in sys.stdin.buffer.readline().split()]",
"- return int(sys.stdin.readline())",
"+ return int(sys.stdin.buffer.readline())",
"-# A",
"-def A():",
"- n = I()",
"- print(((n - (n >> 1)) / n))",
"- return",
"-# B",
"-def B():",
"- n, k = LI()",
"- h = LI()",
"- ans = 0",
"- for i in h:",
"- if i >= k:",
"- ans += 1",
"- print(ans)",
"- return",
"-",
"-",
"-# C",
"-def C():",
"- n = I()",
"- a = LI()",
"- b = [(a[i], i + 1) for i in range(n)]",
"- b.sort()",
"- ans = [b[i][1] for i in range(n)]",
"- print((*ans))",
"- return",
"-",
"-",
"-# D",
"-def D():",
"- def divisor(n):",
"- if n < 4:",
"- return set([n])",
"- res = set([1])",
"- i = 2",
"- m = n",
"- while i**2 <= n:",
"- if m % i == 0:",
"- while m % i == 0:",
"- m //= i",
"- res.add(i)",
"- i += 1",
"- res.add(m)",
"- return res",
"-",
"- a, b = LI()",
"- if min(a, b) == 1:",
"- print((1))",
"- return",
"- s = divisor(a)",
"- t = divisor(b)",
"- s &= t",
"- print((len(s)))",
"- return",
"-",
"-",
"-# E",
"-def E():",
"+def solve():",
"- v = []",
"- for i in range(m):",
"- a, b = LI()",
"+ g = []",
"+ for _ in range(m):",
"+ a, _ = LI()",
"- s = 0",
"- for j in c:",
"- s |= 1 << (j - 1)",
"- v.append((a, s))",
"- l = 1 << n",
"- dp = [[float(\"inf\")] * l for i in range(m + 1)]",
"- dp[0][0] = 0",
"- for i in range(m):",
"- ni = i + 1",
"- a, c = v[i]",
"- for b in range(l):",
"- if dp[i][b] == float(\"inf\"):",
"- continue",
"- nb = b | c",
"- nd = dp[i][b] + a",
"- if nd < dp[ni][nb]:",
"- dp[ni][nb] = nd",
"- nd = dp[i][b]",
"- if nd < dp[ni][b]:",
"- dp[ni][b] = nd",
"- if dp[m][-1] == float(\"inf\"):",
"+ b = 0",
"+ for i in c:",
"+ b |= 1 << (i - 1)",
"+ g.append((b, a))",
"+ B = 1 << n",
"+ dp = [float(\"inf\")] * B",
"+ dp[0] = 0",
"+ for b in range(B):",
"+ for i, v in g:",
"+ nb = b | i",
"+ nd = dp[b] + v",
"+ if nd < dp[nb]:",
"+ dp[nb] = nd",
"+ ans = dp[-1]",
"+ if ans == float(\"inf\"):",
"- print((dp[m][-1]))",
"- return",
"-",
"-",
"-# F",
"-def F():",
"+ print(ans)",
"- E()",
"+ solve()"
] | false | 0.07068 | 0.042642 | 1.657523 | [
"s688666937",
"s945734108"
] |
u606045429 | p03569 | python | s048564178 | s901120376 | 84 | 70 | 4,212 | 4,212 | Accepted | Accepted | 16.67 | from collections import deque
S = eval(input())
ans = 0
Q = deque(S)
while len(Q) >= 2:
left = Q.popleft()
right = Q.pop()
if left != right:
if left == 'x':
Q.append(right)
ans += 1
elif right == 'x':
Q.appendleft(left)
ans += 1
else:
print((-1))
quit()
print(ans) | from collections import deque
S = eval(input())
ans = 0
Q = deque(S)
while len(Q) >= 2:
left, right = Q[0], Q[-1]
if left == right:
Q.popleft()
Q.pop()
elif left == 'x':
Q.popleft()
ans += 1
elif right == 'x':
Q.pop()
ans += 1
else:
print((-1))
quit()
print(ans) | 20 | 23 | 385 | 364 | from collections import deque
S = eval(input())
ans = 0
Q = deque(S)
while len(Q) >= 2:
left = Q.popleft()
right = Q.pop()
if left != right:
if left == "x":
Q.append(right)
ans += 1
elif right == "x":
Q.appendleft(left)
ans += 1
else:
print((-1))
quit()
print(ans)
| from collections import deque
S = eval(input())
ans = 0
Q = deque(S)
while len(Q) >= 2:
left, right = Q[0], Q[-1]
if left == right:
Q.popleft()
Q.pop()
elif left == "x":
Q.popleft()
ans += 1
elif right == "x":
Q.pop()
ans += 1
else:
print((-1))
quit()
print(ans)
| false | 13.043478 | [
"- left = Q.popleft()",
"- right = Q.pop()",
"- if left != right:",
"- if left == \"x\":",
"- Q.append(right)",
"- ans += 1",
"- elif right == \"x\":",
"- Q.appendleft(left)",
"- ans += 1",
"- else:",
"- print((-1))",
"- quit()",
"+ left, right = Q[0], Q[-1]",
"+ if left == right:",
"+ Q.popleft()",
"+ Q.pop()",
"+ elif left == \"x\":",
"+ Q.popleft()",
"+ ans += 1",
"+ elif right == \"x\":",
"+ Q.pop()",
"+ ans += 1",
"+ else:",
"+ print((-1))",
"+ quit()"
] | false | 0.041465 | 0.037078 | 1.118319 | [
"s048564178",
"s901120376"
] |
u380524497 | p03944 | python | s704696488 | s117406721 | 235 | 17 | 16,020 | 3,064 | Accepted | Accepted | 92.77 | import numpy as np
w, h, n = list(map(int, input().split()))
rectangle = np.ones((w, h))
for j in range(n):
x, y, a = list(map(int, input().split()))
if a == 1:
rectangle[:x, :] = 0
elif a == 2:
rectangle[x:, :] = 0
elif a == 3:
rectangle[:, :y] = 0
elif a == 4:
rectangle[:, y:] = 0
print((int(np.sum(rectangle))))
| w, h, n = list(map(int, input().split()))
min_x = 0
max_x = w
min_y = 0
max_y = h
for i in range(n):
x, y, a = list(map(int, input().split()))
if a == 1 and min_x < x:
min_x = x
if a == 2 and x < max_x:
max_x = x
if a == 3 and min_y < y:
min_y = y
if a == 4 and y < max_y:
max_y = y
ans = (max_x-min_x)*(max_y-min_y)
if max_x-min_x < 0 or max_y-min_y < 0:
ans = 0
print(ans) | 20 | 23 | 379 | 444 | import numpy as np
w, h, n = list(map(int, input().split()))
rectangle = np.ones((w, h))
for j in range(n):
x, y, a = list(map(int, input().split()))
if a == 1:
rectangle[:x, :] = 0
elif a == 2:
rectangle[x:, :] = 0
elif a == 3:
rectangle[:, :y] = 0
elif a == 4:
rectangle[:, y:] = 0
print((int(np.sum(rectangle))))
| w, h, n = list(map(int, input().split()))
min_x = 0
max_x = w
min_y = 0
max_y = h
for i in range(n):
x, y, a = list(map(int, input().split()))
if a == 1 and min_x < x:
min_x = x
if a == 2 and x < max_x:
max_x = x
if a == 3 and min_y < y:
min_y = y
if a == 4 and y < max_y:
max_y = y
ans = (max_x - min_x) * (max_y - min_y)
if max_x - min_x < 0 or max_y - min_y < 0:
ans = 0
print(ans)
| false | 13.043478 | [
"-import numpy as np",
"-",
"-rectangle = np.ones((w, h))",
"-for j in range(n):",
"+min_x = 0",
"+max_x = w",
"+min_y = 0",
"+max_y = h",
"+for i in range(n):",
"- if a == 1:",
"- rectangle[:x, :] = 0",
"- elif a == 2:",
"- rectangle[x:, :] = 0",
"- elif a == 3:",
"- rectangle[:, :y] = 0",
"- elif a == 4:",
"- rectangle[:, y:] = 0",
"-print((int(np.sum(rectangle))))",
"+ if a == 1 and min_x < x:",
"+ min_x = x",
"+ if a == 2 and x < max_x:",
"+ max_x = x",
"+ if a == 3 and min_y < y:",
"+ min_y = y",
"+ if a == 4 and y < max_y:",
"+ max_y = y",
"+ans = (max_x - min_x) * (max_y - min_y)",
"+if max_x - min_x < 0 or max_y - min_y < 0:",
"+ ans = 0",
"+print(ans)"
] | false | 0.443121 | 0.037212 | 11.907947 | [
"s704696488",
"s117406721"
] |
u597455618 | p02560 | python | s822400853 | s532584932 | 847 | 632 | 9,264 | 106,380 | Accepted | Accepted | 25.38 | import sys
def floor_sum(n, m, a, b):
ans = n*(b//m)
b %= m
while True:
ans += (n-1)*n*(a//m)//2
a %= m
if a*n+b < m:
return ans
y_max = (a*n + b)//m
b -= y_max*m # now we have x_max = -(b//a)
ans += (n + b//a)*y_max
n = y_max
b %= a
m, a = a, m
input = sys.stdin.buffer.readline
t = int(eval(input()))
for _ in range(t):
n, m, a, b = list(map(int, input().split()))
print((floor_sum(n, m, a, b)))
| import sys
from numba import njit, i8
@njit((i8, i8, i8, i8), cache=True)
def floor_sum(n, m, a, b):
ans = n*(b//m)
b %= m
while True:
ans += (n-1)*n*(a//m)//2
a %= m
if a*n+b < m:
return ans
y_max = (a*n + b)//m
b -= y_max*m # now we have x_max = -(b//a)
ans += (n + b//a)*y_max
b %= a
m, a, n = a, m, y_max
input = sys.stdin.buffer.readline
t = int(eval(input()))
for _ in range(t):
n, m, a, b = list(map(int, input().split()))
print((floor_sum(n, m, a, b)))
| 24 | 25 | 516 | 572 | import sys
def floor_sum(n, m, a, b):
ans = n * (b // m)
b %= m
while True:
ans += (n - 1) * n * (a // m) // 2
a %= m
if a * n + b < m:
return ans
y_max = (a * n + b) // m
b -= y_max * m # now we have x_max = -(b//a)
ans += (n + b // a) * y_max
n = y_max
b %= a
m, a = a, m
input = sys.stdin.buffer.readline
t = int(eval(input()))
for _ in range(t):
n, m, a, b = list(map(int, input().split()))
print((floor_sum(n, m, a, b)))
| import sys
from numba import njit, i8
@njit((i8, i8, i8, i8), cache=True)
def floor_sum(n, m, a, b):
ans = n * (b // m)
b %= m
while True:
ans += (n - 1) * n * (a // m) // 2
a %= m
if a * n + b < m:
return ans
y_max = (a * n + b) // m
b -= y_max * m # now we have x_max = -(b//a)
ans += (n + b // a) * y_max
b %= a
m, a, n = a, m, y_max
input = sys.stdin.buffer.readline
t = int(eval(input()))
for _ in range(t):
n, m, a, b = list(map(int, input().split()))
print((floor_sum(n, m, a, b)))
| false | 4 | [
"+from numba import njit, i8",
"+@njit((i8, i8, i8, i8), cache=True)",
"- n = y_max",
"- m, a = a, m",
"+ m, a, n = a, m, y_max"
] | false | 0.096233 | 0.103117 | 0.933236 | [
"s822400853",
"s532584932"
] |
u089142196 | p02713 | python | s642196245 | s375907151 | 490 | 191 | 67,768 | 67,724 | Accepted | Accepted | 61.02 | from math import gcd
K=int(eval(input()))
sum=0
for i in range(1,K+1):
for j in range(1,K+1):
for k in range(1,K+1):
tmp= gcd(i,j)
sum += gcd(tmp,k)
print(sum)
| from math import gcd
K=int(eval(input()))
sum=0
for i in range(1,K+1):
for j in range(1,K+1):
tmp= gcd(i,j)
for k in range(1,K+1):
sum += gcd(tmp,k)
print(sum)
| 12 | 12 | 192 | 196 | from math import gcd
K = int(eval(input()))
sum = 0
for i in range(1, K + 1):
for j in range(1, K + 1):
for k in range(1, K + 1):
tmp = gcd(i, j)
sum += gcd(tmp, k)
print(sum)
| from math import gcd
K = int(eval(input()))
sum = 0
for i in range(1, K + 1):
for j in range(1, K + 1):
tmp = gcd(i, j)
for k in range(1, K + 1):
sum += gcd(tmp, k)
print(sum)
| false | 0 | [
"+ tmp = gcd(i, j)",
"- tmp = gcd(i, j)"
] | false | 0.038397 | 0.215076 | 0.178526 | [
"s642196245",
"s375907151"
] |
u389910364 | p03128 | python | s990159996 | s014244150 | 305 | 105 | 5,396 | 5,600 | Accepted | Accepted | 65.57 | n, _ = list(map(int, input().split()))
numbers = list(map(int, input().split()))
reqs = {
1: 2,
2: 5,
3: 5,
4: 4,
5: 5,
6: 6,
7: 3,
8: 7,
9: 6,
}
memo = {}
def max_counts(a, b):
"""
a と b 大きい方を返す
:param a: solve() の返り値
:param b: solve() の返り値
:return:
"""
if a is None:
return b
if b is None:
return a
# 桁数は大きいほうが大きい
if sum(a) > sum(b):
return a
if sum(a) < sum(b):
return b
# 桁数が同じなら、大きい数字の多いほうが大きい
for a_c, b_c in zip(reversed(a), reversed(b)):
if a_c > b_c:
return a
if a_c < b_c:
return b
return a
# https://atcoder.jp/contests/abc118/submissions/4911280
# DP 版
memo[0] = [0 for _ in range(10)]
for i in range(n):
if i in memo:
for num in numbers:
next_n = i + reqs[num]
next_counts = memo[next_n] if next_n in memo else None
if next_n <= n:
memo[next_n] = max_counts(
next_counts,
memo[i][:num] + [memo[i][num] + 1] + memo[i][num + 1:]
)
ans = ''
for num in range(9, 0, -1):
for _ in range(memo[n][num]):
ans += str(num)
print(ans)
| import os
import sys
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
N, M = list(map(int, sys.stdin.buffer.readline().split()))
A = list(map(int, sys.stdin.buffer.readline().split()))
requires = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
# dp[i][0]: i 個のマッチ棒を使って作れる整数の最大の桁数
# dp[i][1][-j]: j を何個作るか
dp = [(0, [0] * 9) for _ in range(N + 10)]
for i in range(N):
d, counts = dp[i]
if i > 0 and d == 0:
continue
for a in A:
cnts = counts[:]
cnts[-a] += 1
dp[i + requires[a]] = max(dp[i + requires[a]], (d + 1, cnts))
ans = ''
for i, cnt in enumerate(dp[N][1]):
ans += str(9 - i) * cnt
print(ans)
| 61 | 32 | 1,292 | 779 | n, _ = list(map(int, input().split()))
numbers = list(map(int, input().split()))
reqs = {
1: 2,
2: 5,
3: 5,
4: 4,
5: 5,
6: 6,
7: 3,
8: 7,
9: 6,
}
memo = {}
def max_counts(a, b):
"""
a と b 大きい方を返す
:param a: solve() の返り値
:param b: solve() の返り値
:return:
"""
if a is None:
return b
if b is None:
return a
# 桁数は大きいほうが大きい
if sum(a) > sum(b):
return a
if sum(a) < sum(b):
return b
# 桁数が同じなら、大きい数字の多いほうが大きい
for a_c, b_c in zip(reversed(a), reversed(b)):
if a_c > b_c:
return a
if a_c < b_c:
return b
return a
# https://atcoder.jp/contests/abc118/submissions/4911280
# DP 版
memo[0] = [0 for _ in range(10)]
for i in range(n):
if i in memo:
for num in numbers:
next_n = i + reqs[num]
next_counts = memo[next_n] if next_n in memo else None
if next_n <= n:
memo[next_n] = max_counts(
next_counts, memo[i][:num] + [memo[i][num] + 1] + memo[i][num + 1 :]
)
ans = ""
for num in range(9, 0, -1):
for _ in range(memo[n][num]):
ans += str(num)
print(ans)
| import os
import sys
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
N, M = list(map(int, sys.stdin.buffer.readline().split()))
A = list(map(int, sys.stdin.buffer.readline().split()))
requires = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
# dp[i][0]: i 個のマッチ棒を使って作れる整数の最大の桁数
# dp[i][1][-j]: j を何個作るか
dp = [(0, [0] * 9) for _ in range(N + 10)]
for i in range(N):
d, counts = dp[i]
if i > 0 and d == 0:
continue
for a in A:
cnts = counts[:]
cnts[-a] += 1
dp[i + requires[a]] = max(dp[i + requires[a]], (d + 1, cnts))
ans = ""
for i, cnt in enumerate(dp[N][1]):
ans += str(9 - i) * cnt
print(ans)
| false | 47.540984 | [
"-n, _ = list(map(int, input().split()))",
"-numbers = list(map(int, input().split()))",
"-reqs = {",
"- 1: 2,",
"- 2: 5,",
"- 3: 5,",
"- 4: 4,",
"- 5: 5,",
"- 6: 6,",
"- 7: 3,",
"- 8: 7,",
"- 9: 6,",
"-}",
"-memo = {}",
"+import os",
"+import sys",
"-",
"-def max_counts(a, b):",
"- \"\"\"",
"- a と b 大きい方を返す",
"- :param a: solve() の返り値",
"- :param b: solve() の返り値",
"- :return:",
"- \"\"\"",
"- if a is None:",
"- return b",
"- if b is None:",
"- return a",
"- # 桁数は大きいほうが大きい",
"- if sum(a) > sum(b):",
"- return a",
"- if sum(a) < sum(b):",
"- return b",
"- # 桁数が同じなら、大きい数字の多いほうが大きい",
"- for a_c, b_c in zip(reversed(a), reversed(b)):",
"- if a_c > b_c:",
"- return a",
"- if a_c < b_c:",
"- return b",
"- return a",
"-",
"-",
"-# https://atcoder.jp/contests/abc118/submissions/4911280",
"-# DP 版",
"-memo[0] = [0 for _ in range(10)]",
"-for i in range(n):",
"- if i in memo:",
"- for num in numbers:",
"- next_n = i + reqs[num]",
"- next_counts = memo[next_n] if next_n in memo else None",
"- if next_n <= n:",
"- memo[next_n] = max_counts(",
"- next_counts, memo[i][:num] + [memo[i][num] + 1] + memo[i][num + 1 :]",
"- )",
"+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",
"+N, M = list(map(int, sys.stdin.buffer.readline().split()))",
"+A = list(map(int, sys.stdin.buffer.readline().split()))",
"+requires = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]",
"+# dp[i][0]: i 個のマッチ棒を使って作れる整数の最大の桁数",
"+# dp[i][1][-j]: j を何個作るか",
"+dp = [(0, [0] * 9) for _ in range(N + 10)]",
"+for i in range(N):",
"+ d, counts = dp[i]",
"+ if i > 0 and d == 0:",
"+ continue",
"+ for a in A:",
"+ cnts = counts[:]",
"+ cnts[-a] += 1",
"+ dp[i + requires[a]] = max(dp[i + requires[a]], (d + 1, cnts))",
"-for num in range(9, 0, -1):",
"- for _ in range(memo[n][num]):",
"- ans += str(num)",
"+for i, cnt in enumerate(dp[N][1]):",
"+ ans += str(9 - i) * cnt"
] | false | 0.036698 | 0.041752 | 0.878942 | [
"s990159996",
"s014244150"
] |
u745223262 | p03612 | python | s607706688 | s014074955 | 85 | 78 | 14,008 | 14,008 | Accepted | Accepted | 8.24 | n = int(eval(input()))
p = list(map(int, input().split()))
cnt = 0
for i in range(n):
if p[i] == i + 1:
if i == 0:
p[i], p[i + 1] = p[i + 1], p[i]
elif i == n-1:
p[i], p[i - 1] = p[i - 1], p[i]
else:
if p[i - 1] == i + 1:
p[i], p[i - 1] = p[i - 1], p[i]
else:
p[i], p[i + 1] = p[i + 1], p[i]
cnt += 1
print(cnt) | n = int(eval(input()))
p = list(map(int, input().split()))
cnt = 0
for i in range(n):
if p[i] == i + 1:
if i == 0:
p[i], p[i + 1] = p[i + 1], p[i]
elif i == n-1:
p[i], p[i - 1] = p[i - 1], p[i]
else:
p[i], p[i + 1] = p[i + 1], p[i]
cnt += 1
print(cnt) | 18 | 16 | 440 | 348 | n = int(eval(input()))
p = list(map(int, input().split()))
cnt = 0
for i in range(n):
if p[i] == i + 1:
if i == 0:
p[i], p[i + 1] = p[i + 1], p[i]
elif i == n - 1:
p[i], p[i - 1] = p[i - 1], p[i]
else:
if p[i - 1] == i + 1:
p[i], p[i - 1] = p[i - 1], p[i]
else:
p[i], p[i + 1] = p[i + 1], p[i]
cnt += 1
print(cnt)
| n = int(eval(input()))
p = list(map(int, input().split()))
cnt = 0
for i in range(n):
if p[i] == i + 1:
if i == 0:
p[i], p[i + 1] = p[i + 1], p[i]
elif i == n - 1:
p[i], p[i - 1] = p[i - 1], p[i]
else:
p[i], p[i + 1] = p[i + 1], p[i]
cnt += 1
print(cnt)
| false | 11.111111 | [
"- if p[i - 1] == i + 1:",
"- p[i], p[i - 1] = p[i - 1], p[i]",
"- else:",
"- p[i], p[i + 1] = p[i + 1], p[i]",
"+ p[i], p[i + 1] = p[i + 1], p[i]"
] | false | 0.034638 | 0.036543 | 0.947869 | [
"s607706688",
"s014074955"
] |
u020604402 | p02761 | python | s009371142 | s400943102 | 170 | 18 | 38,384 | 3,064 | Accepted | Accepted | 89.41 | N , M = list(map(int,input().split()))
L = []
for _ in range(M):
m = tuple(map(int,input().split()))
L.append(m)
if N == 1:
for ans in range(0,10):
ans = str(ans)
for x in L:
if ans[x[0] - 1] != str(x[1]):
break
else:
print(ans)
exit()
print((-1))
exit()
else:
for ans in range(10 ** (N - 1),10 ** N ):
ans = str(ans)
for x in L:
if ans[x[0] - 1] != str(x[1]):
break
else:
print(ans)
exit()
print((-1))
exit()
| N, M = list(map(int,input().split()))
L = []
for _ in range(M):
m = tuple(map(int,input().split()))
L.append(m)
if(N == 1): lower = 0
else: lower = 10 ** (N - 1)
for ans in range(lower, 10 ** N ):
ans = str(ans)
for x in L:
if ans[x[0] - 1] != str(x[1]):
break
else: #一度もbreakされてない == 矛盾なし
print(ans)
exit()
#ねえよ
print((-1))
| 28 | 20 | 612 | 402 | N, M = list(map(int, input().split()))
L = []
for _ in range(M):
m = tuple(map(int, input().split()))
L.append(m)
if N == 1:
for ans in range(0, 10):
ans = str(ans)
for x in L:
if ans[x[0] - 1] != str(x[1]):
break
else:
print(ans)
exit()
print((-1))
exit()
else:
for ans in range(10 ** (N - 1), 10**N):
ans = str(ans)
for x in L:
if ans[x[0] - 1] != str(x[1]):
break
else:
print(ans)
exit()
print((-1))
exit()
| N, M = list(map(int, input().split()))
L = []
for _ in range(M):
m = tuple(map(int, input().split()))
L.append(m)
if N == 1:
lower = 0
else:
lower = 10 ** (N - 1)
for ans in range(lower, 10**N):
ans = str(ans)
for x in L:
if ans[x[0] - 1] != str(x[1]):
break
else: # 一度もbreakされてない == 矛盾なし
print(ans)
exit()
# ねえよ
print((-1))
| false | 28.571429 | [
"- for ans in range(0, 10):",
"- ans = str(ans)",
"- for x in L:",
"- if ans[x[0] - 1] != str(x[1]):",
"- break",
"- else:",
"- print(ans)",
"- exit()",
"- print((-1))",
"- exit()",
"+ lower = 0",
"- for ans in range(10 ** (N - 1), 10**N):",
"- ans = str(ans)",
"- for x in L:",
"- if ans[x[0] - 1] != str(x[1]):",
"- break",
"- else:",
"- print(ans)",
"- exit()",
"- print((-1))",
"- exit()",
"+ lower = 10 ** (N - 1)",
"+for ans in range(lower, 10**N):",
"+ ans = str(ans)",
"+ for x in L:",
"+ if ans[x[0] - 1] != str(x[1]):",
"+ break",
"+ else: # 一度もbreakされてない == 矛盾なし",
"+ print(ans)",
"+ exit()",
"+# ねえよ",
"+print((-1))"
] | false | 0.176931 | 0.044129 | 4.009433 | [
"s009371142",
"s400943102"
] |
u853728588 | p02628 | python | s112334883 | s638372349 | 29 | 23 | 9,248 | 9,104 | Accepted | Accepted | 20.69 | n, k = list(map(int,input().split()))
p = list(map(int,input().split()))
p.sort()
print((sum(p[0:k])))
| n, k = list(map(int, input().split()))
p = list(map(int, input().split()))
p.sort()
total = 0
for i in range(k):
total += p[i]
print(total) | 5 | 7 | 100 | 141 | n, k = list(map(int, input().split()))
p = list(map(int, input().split()))
p.sort()
print((sum(p[0:k])))
| n, k = list(map(int, input().split()))
p = list(map(int, input().split()))
p.sort()
total = 0
for i in range(k):
total += p[i]
print(total)
| false | 28.571429 | [
"-print((sum(p[0:k])))",
"+total = 0",
"+for i in range(k):",
"+ total += p[i]",
"+print(total)"
] | false | 0.040548 | 0.107888 | 0.37583 | [
"s112334883",
"s638372349"
] |
u989345508 | p03488 | python | s432883967 | s633342491 | 200 | 183 | 41,200 | 41,072 | Accepted | Accepted | 8.5 | from sys import exit
s=eval(input())
x,y=list(map(int,input().split()))
def groupby(a):
a2=[[a[0],1]]
for i in range(1,len(a)):
if a2[-1][0]==a[i]:
a2[-1][1]+=1
else:
a2.append([a[i],1])
return a2
s=groupby(s)
a,b=[],[]
turn=True
if s[0][0]=="F":
x-=s[0][1]
s.pop(0)
for i in s:
if i[0]=="F":
if turn:
a.append(i[1])
else:
b.append(i[1])
else:
if i[1]%2==1:
turn=not turn
a.sort(reverse=True)
b.sort(reverse=True)
for i in a:
if x>0:
x-=i
else:
x+=i
for i in b:
if y>0:
y-=i
else:
y+=i
if x!=0 or y!=0:
print("No")
else:
print("Yes") | from sys import exit
s=eval(input())
x,y=list(map(int,input().split()))
def groupby(a):
a2=[[a[0],1]]
for i in range(1,len(a)):
if a2[-1][0]==a[i]:
a2[-1][1]+=1
else:
a2.append([a[i],1])
return a2
s=groupby(s)
a,b=[],[]
turn=True
#初めまっすぐの場合
if s[0][0]=="F":
x-=s[0][1]
s.pop(0)
for i in s:
if i[0]=="F":
if turn:
a.append(i[1])
else:
b.append(i[1])
elif i[1]%2==1:
turn=not turn
a.sort(reverse=True)
b.sort(reverse=True)
for i in a:
x=abs(x)-abs(i)
if x!=0:
print("No")
exit()
for i in b:
y=abs(y)-abs(i)
if y!=0:
print("No")
exit()
print("Yes") | 43 | 40 | 748 | 713 | from sys import exit
s = eval(input())
x, y = list(map(int, input().split()))
def groupby(a):
a2 = [[a[0], 1]]
for i in range(1, len(a)):
if a2[-1][0] == a[i]:
a2[-1][1] += 1
else:
a2.append([a[i], 1])
return a2
s = groupby(s)
a, b = [], []
turn = True
if s[0][0] == "F":
x -= s[0][1]
s.pop(0)
for i in s:
if i[0] == "F":
if turn:
a.append(i[1])
else:
b.append(i[1])
else:
if i[1] % 2 == 1:
turn = not turn
a.sort(reverse=True)
b.sort(reverse=True)
for i in a:
if x > 0:
x -= i
else:
x += i
for i in b:
if y > 0:
y -= i
else:
y += i
if x != 0 or y != 0:
print("No")
else:
print("Yes")
| from sys import exit
s = eval(input())
x, y = list(map(int, input().split()))
def groupby(a):
a2 = [[a[0], 1]]
for i in range(1, len(a)):
if a2[-1][0] == a[i]:
a2[-1][1] += 1
else:
a2.append([a[i], 1])
return a2
s = groupby(s)
a, b = [], []
turn = True
# 初めまっすぐの場合
if s[0][0] == "F":
x -= s[0][1]
s.pop(0)
for i in s:
if i[0] == "F":
if turn:
a.append(i[1])
else:
b.append(i[1])
elif i[1] % 2 == 1:
turn = not turn
a.sort(reverse=True)
b.sort(reverse=True)
for i in a:
x = abs(x) - abs(i)
if x != 0:
print("No")
exit()
for i in b:
y = abs(y) - abs(i)
if y != 0:
print("No")
exit()
print("Yes")
| false | 6.976744 | [
"+# 初めまっすぐの場合",
"- else:",
"- if i[1] % 2 == 1:",
"- turn = not turn",
"+ elif i[1] % 2 == 1:",
"+ turn = not turn",
"- if x > 0:",
"- x -= i",
"- else:",
"- x += i",
"+ x = abs(x) - abs(i)",
"+if x != 0:",
"+ print(\"No\")",
"+ exit()",
"- if y > 0:",
"- y -= i",
"- else:",
"- y += i",
"-if x != 0 or y != 0:",
"+ y = abs(y) - abs(i)",
"+if y != 0:",
"-else:",
"- print(\"Yes\")",
"+ exit()",
"+print(\"Yes\")"
] | false | 0.048768 | 0.006899 | 7.069056 | [
"s432883967",
"s633342491"
] |
u735008991 | p02861 | python | s139686547 | s762687791 | 368 | 202 | 4,528 | 42,588 | Accepted | Accepted | 45.11 | import math
import itertools
def dist(a, b):
return math.sqrt((a[0]-b[0])**2 + (a[1] - b[1])**2)
def length(P, p):
total = 0
for i in range(len(p)-1):
total += dist(P[p[i]], P[p[i+1]])
return total
N = int(eval(input()))
P = [list(map(int, input().split())) for _ in range(N)]
print((sum([length(P, p)
for p in itertools.permutations(list(range(N)))]) / math.factorial(N)))
| import itertools
import math
def dist(a, b):
return math.sqrt((a[0] - b[0])**2 + (a[1] - b[1])**2)
N = int(eval(input()))
C = [tuple(map(int, input().split())) for _ in range(N)]
s = 0
for per in itertools.permutations(C):
for i in range(N-1):
s += dist(per[i], per[i+1])
print((s / len(list(itertools.permutations(C)))))
| 20 | 17 | 421 | 352 | import math
import itertools
def dist(a, b):
return math.sqrt((a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2)
def length(P, p):
total = 0
for i in range(len(p) - 1):
total += dist(P[p[i]], P[p[i + 1]])
return total
N = int(eval(input()))
P = [list(map(int, input().split())) for _ in range(N)]
print(
(
sum([length(P, p) for p in itertools.permutations(list(range(N)))])
/ math.factorial(N)
)
)
| import itertools
import math
def dist(a, b):
return math.sqrt((a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2)
N = int(eval(input()))
C = [tuple(map(int, input().split())) for _ in range(N)]
s = 0
for per in itertools.permutations(C):
for i in range(N - 1):
s += dist(per[i], per[i + 1])
print((s / len(list(itertools.permutations(C)))))
| false | 15 | [
"+import itertools",
"-import itertools",
"-def length(P, p):",
"- total = 0",
"- for i in range(len(p) - 1):",
"- total += dist(P[p[i]], P[p[i + 1]])",
"- return total",
"-",
"-",
"-P = [list(map(int, input().split())) for _ in range(N)]",
"-print(",
"- (",
"- sum([length(P, p) for p in itertools.permutations(list(range(N)))])",
"- / math.factorial(N)",
"- )",
"-)",
"+C = [tuple(map(int, input().split())) for _ in range(N)]",
"+s = 0",
"+for per in itertools.permutations(C):",
"+ for i in range(N - 1):",
"+ s += dist(per[i], per[i + 1])",
"+print((s / len(list(itertools.permutations(C)))))"
] | false | 0.038927 | 0.039865 | 0.976461 | [
"s139686547",
"s762687791"
] |
u844646164 | p03575 | python | s898579996 | s213652356 | 188 | 36 | 76,076 | 9,264 | Accepted | Accepted | 80.85 | import heapq
N, M = list(map(int, input().split()))
ab = [list([int(x)-1 for x in input().split()]) for _ in range(M)]
ans = 0
def dijkstra(s, graph, n):
dist = [float('inf')]*n
dist[s] = 0
num = [0]*n
num[s] = 1
q = [[0, s]]
heapq.heapify(q)
while q:
c, u = heapq.heappop(q)
if dist[u] < c:
continue
for v, weight in graph[u]:
if dist[v] > dist[u] + weight:
dist[v] = dist[u] + weight
num[v] = num[u]
heapq.heappush(q, [dist[v], v])
elif dist[v] == dist[u] + weight:
num[v] += num[u]
return dist, num
for i in range(M):
graph = [[] for _ in range(N)]
for j in range(M):
if i != j:
a, b = ab[j]
graph[a] += [[b, 1]]
graph[b] += [[a, 1]]
for j in range(N):
d, _ = dijkstra(j, graph, N)
if max(d) == float('inf'):
ans += 1
break
print(ans)
| import sys
sys.setrecursionlimit(1000000000)
N, M = list(map(int, input().split()))
graph = [[0]*N for _ in range(N)]
visited = [0]*N
ab = []
ans = 0
def dfs(u):
visited[u] = 1
for v in range(N):
if graph[u][v] == 1 and visited[v] == 0:
dfs(v)
for _ in range(M):
a, b = [int(x)-1 for x in input().split()]
graph[a][b] = 1
graph[b][a] = 1
ab += [[a, b]]
for _ in range(M):
a, b = ab.pop(0)
graph[a][b] = 0
graph[b][a] = 0
for i in range(N):
visited[i] = 0
dfs(0)
if sum(visited) != N:
ans += 1
graph[a][b] = 1
graph[b][a] = 1
print(ans) | 39 | 37 | 903 | 627 | import heapq
N, M = list(map(int, input().split()))
ab = [list([int(x) - 1 for x in input().split()]) for _ in range(M)]
ans = 0
def dijkstra(s, graph, n):
dist = [float("inf")] * n
dist[s] = 0
num = [0] * n
num[s] = 1
q = [[0, s]]
heapq.heapify(q)
while q:
c, u = heapq.heappop(q)
if dist[u] < c:
continue
for v, weight in graph[u]:
if dist[v] > dist[u] + weight:
dist[v] = dist[u] + weight
num[v] = num[u]
heapq.heappush(q, [dist[v], v])
elif dist[v] == dist[u] + weight:
num[v] += num[u]
return dist, num
for i in range(M):
graph = [[] for _ in range(N)]
for j in range(M):
if i != j:
a, b = ab[j]
graph[a] += [[b, 1]]
graph[b] += [[a, 1]]
for j in range(N):
d, _ = dijkstra(j, graph, N)
if max(d) == float("inf"):
ans += 1
break
print(ans)
| import sys
sys.setrecursionlimit(1000000000)
N, M = list(map(int, input().split()))
graph = [[0] * N for _ in range(N)]
visited = [0] * N
ab = []
ans = 0
def dfs(u):
visited[u] = 1
for v in range(N):
if graph[u][v] == 1 and visited[v] == 0:
dfs(v)
for _ in range(M):
a, b = [int(x) - 1 for x in input().split()]
graph[a][b] = 1
graph[b][a] = 1
ab += [[a, b]]
for _ in range(M):
a, b = ab.pop(0)
graph[a][b] = 0
graph[b][a] = 0
for i in range(N):
visited[i] = 0
dfs(0)
if sum(visited) != N:
ans += 1
graph[a][b] = 1
graph[b][a] = 1
print(ans)
| false | 5.128205 | [
"-import heapq",
"+import sys",
"+sys.setrecursionlimit(1000000000)",
"-ab = [list([int(x) - 1 for x in input().split()]) for _ in range(M)]",
"+graph = [[0] * N for _ in range(N)]",
"+visited = [0] * N",
"+ab = []",
"-def dijkstra(s, graph, n):",
"- dist = [float(\"inf\")] * n",
"- dist[s] = 0",
"- num = [0] * n",
"- num[s] = 1",
"- q = [[0, s]]",
"- heapq.heapify(q)",
"- while q:",
"- c, u = heapq.heappop(q)",
"- if dist[u] < c:",
"- continue",
"- for v, weight in graph[u]:",
"- if dist[v] > dist[u] + weight:",
"- dist[v] = dist[u] + weight",
"- num[v] = num[u]",
"- heapq.heappush(q, [dist[v], v])",
"- elif dist[v] == dist[u] + weight:",
"- num[v] += num[u]",
"- return dist, num",
"+def dfs(u):",
"+ visited[u] = 1",
"+ for v in range(N):",
"+ if graph[u][v] == 1 and visited[v] == 0:",
"+ dfs(v)",
"-for i in range(M):",
"- graph = [[] for _ in range(N)]",
"- for j in range(M):",
"- if i != j:",
"- a, b = ab[j]",
"- graph[a] += [[b, 1]]",
"- graph[b] += [[a, 1]]",
"- for j in range(N):",
"- d, _ = dijkstra(j, graph, N)",
"- if max(d) == float(\"inf\"):",
"- ans += 1",
"- break",
"+for _ in range(M):",
"+ a, b = [int(x) - 1 for x in input().split()]",
"+ graph[a][b] = 1",
"+ graph[b][a] = 1",
"+ ab += [[a, b]]",
"+for _ in range(M):",
"+ a, b = ab.pop(0)",
"+ graph[a][b] = 0",
"+ graph[b][a] = 0",
"+ for i in range(N):",
"+ visited[i] = 0",
"+ dfs(0)",
"+ if sum(visited) != N:",
"+ ans += 1",
"+ graph[a][b] = 1",
"+ graph[b][a] = 1"
] | false | 0.075812 | 0.036441 | 2.080392 | [
"s898579996",
"s213652356"
] |
u952708174 | p03250 | python | s184758088 | s681382484 | 20 | 18 | 3,316 | 2,940 | Accepted | Accepted | 10 | I = [int(i) for i in input().split()]
I.sort(reverse=True)
a, b, c = list(map(str, I))
ans = int(a + b) + int(c)
print(ans) | a, b, c = sorted([i for i in input().split()], reverse=True)
print((int(a + b) + int(c))) | 5 | 2 | 121 | 88 | I = [int(i) for i in input().split()]
I.sort(reverse=True)
a, b, c = list(map(str, I))
ans = int(a + b) + int(c)
print(ans)
| a, b, c = sorted([i for i in input().split()], reverse=True)
print((int(a + b) + int(c)))
| false | 60 | [
"-I = [int(i) for i in input().split()]",
"-I.sort(reverse=True)",
"-a, b, c = list(map(str, I))",
"-ans = int(a + b) + int(c)",
"-print(ans)",
"+a, b, c = sorted([i for i in input().split()], reverse=True)",
"+print((int(a + b) + int(c)))"
] | false | 0.044006 | 0.043956 | 1.001143 | [
"s184758088",
"s681382484"
] |
u954153335 | p02731 | python | s458617197 | s936628918 | 34 | 17 | 5,076 | 2,940 | Accepted | Accepted | 50 | from decimal import*
l=Decimal(eval(input()))
ans=(l/3)**3
print(ans)
| l=float(eval(input()))
ans=(l/3)**3
print(ans)
| 4 | 3 | 67 | 43 | from decimal import *
l = Decimal(eval(input()))
ans = (l / 3) ** 3
print(ans)
| l = float(eval(input()))
ans = (l / 3) ** 3
print(ans)
| false | 25 | [
"-from decimal import *",
"-",
"-l = Decimal(eval(input()))",
"+l = float(eval(input()))"
] | false | 0.037621 | 0.036875 | 1.020212 | [
"s458617197",
"s936628918"
] |
u102242691 | p03827 | python | s275489170 | s934564768 | 25 | 18 | 3,316 | 2,940 | Accepted | Accepted | 28 |
n = int(eval(input()))
s = list(eval(input()))
ans = 0
l = [0]
for i in range(n):
if s[i] == "I":
ans += 1
l.append(ans)
elif s[i] == "D":
ans -= 1
l.append(ans)
print((max(l)))
|
n = int(eval(input()))
s = list(eval(input()))
max = 0
count = 0
for i in range(n):
if s[i] == "I":
count += 1
if max < count:
max = count
elif s[i] == "D":
count -= 1
print(max)
| 16 | 14 | 223 | 226 | n = int(eval(input()))
s = list(eval(input()))
ans = 0
l = [0]
for i in range(n):
if s[i] == "I":
ans += 1
l.append(ans)
elif s[i] == "D":
ans -= 1
l.append(ans)
print((max(l)))
| n = int(eval(input()))
s = list(eval(input()))
max = 0
count = 0
for i in range(n):
if s[i] == "I":
count += 1
if max < count:
max = count
elif s[i] == "D":
count -= 1
print(max)
| false | 12.5 | [
"-ans = 0",
"-l = [0]",
"+max = 0",
"+count = 0",
"- ans += 1",
"- l.append(ans)",
"+ count += 1",
"+ if max < count:",
"+ max = count",
"- ans -= 1",
"- l.append(ans)",
"-print((max(l)))",
"+ count -= 1",
"+print(max)"
] | false | 0.072891 | 0.039211 | 1.858963 | [
"s275489170",
"s934564768"
] |
u325282913 | p02695 | python | s298846218 | s815543762 | 986 | 298 | 9,604 | 83,728 | Accepted | Accepted | 69.78 | import sys
sys.setrecursionlimit(10**7)
N, M, Q = list(map(int, input().split()))
arr = [list(map(int, input().split())) for _ in range(Q)]
ans = set()
def generate_arr(target):
if len(target) == N:
tmp = 0
for item in arr:
if target[item[1]-1] - target[item[0]-1] == item[2]:
tmp += item[3]
ans.add(tmp)
return
for i in range(target[-1],M+1):
next_target = target.copy()
next_target.append(i)
generate_arr(next_target)
for i in range(1,M+1):
generate_arr([i])
print((max(ans))) | target = []
def dfs(A):
if len(A) == N:
tmp = 0
for a, b, c, d in arr:
if A[b-1] - A[a-1] == c:
tmp += d
target.append(tmp)
return
start = 1
if len(A) != 0:
start = A[-1]
for v in range(start,M+1):
A.append(v)
dfs(A)
A.pop()
N, M, Q = list(map(int, input().split()))
arr = [list(map(int, input().split())) for _ in range(Q)]
dfs([])
print((max(target))) | 22 | 20 | 593 | 472 | import sys
sys.setrecursionlimit(10**7)
N, M, Q = list(map(int, input().split()))
arr = [list(map(int, input().split())) for _ in range(Q)]
ans = set()
def generate_arr(target):
if len(target) == N:
tmp = 0
for item in arr:
if target[item[1] - 1] - target[item[0] - 1] == item[2]:
tmp += item[3]
ans.add(tmp)
return
for i in range(target[-1], M + 1):
next_target = target.copy()
next_target.append(i)
generate_arr(next_target)
for i in range(1, M + 1):
generate_arr([i])
print((max(ans)))
| target = []
def dfs(A):
if len(A) == N:
tmp = 0
for a, b, c, d in arr:
if A[b - 1] - A[a - 1] == c:
tmp += d
target.append(tmp)
return
start = 1
if len(A) != 0:
start = A[-1]
for v in range(start, M + 1):
A.append(v)
dfs(A)
A.pop()
N, M, Q = list(map(int, input().split()))
arr = [list(map(int, input().split())) for _ in range(Q)]
dfs([])
print((max(target)))
| false | 9.090909 | [
"-import sys",
"+target = []",
"-sys.setrecursionlimit(10**7)",
"+",
"+def dfs(A):",
"+ if len(A) == N:",
"+ tmp = 0",
"+ for a, b, c, d in arr:",
"+ if A[b - 1] - A[a - 1] == c:",
"+ tmp += d",
"+ target.append(tmp)",
"+ return",
"+ start = 1",
"+ if len(A) != 0:",
"+ start = A[-1]",
"+ for v in range(start, M + 1):",
"+ A.append(v)",
"+ dfs(A)",
"+ A.pop()",
"+",
"+",
"-ans = set()",
"-",
"-",
"-def generate_arr(target):",
"- if len(target) == N:",
"- tmp = 0",
"- for item in arr:",
"- if target[item[1] - 1] - target[item[0] - 1] == item[2]:",
"- tmp += item[3]",
"- ans.add(tmp)",
"- return",
"- for i in range(target[-1], M + 1):",
"- next_target = target.copy()",
"- next_target.append(i)",
"- generate_arr(next_target)",
"-",
"-",
"-for i in range(1, M + 1):",
"- generate_arr([i])",
"-print((max(ans)))",
"+dfs([])",
"+print((max(target)))"
] | false | 0.052067 | 0.087652 | 0.594019 | [
"s298846218",
"s815543762"
] |
u366959492 | p03045 | python | s006198250 | s106000578 | 984 | 641 | 78,552 | 75,864 | Accepted | Accepted | 34.86 | n,m=list(map(int,input().split()))
class UnionFind():
def __init__(self,n):
self.n=n
self.root=[-1]*(n+1)
self.rnk=[0]*(n+1)
def Find_Root(self,x):
if self.root[x]<0:
return x
else:
self.root[x]=self.Find_Root(self.root[x])
return self.root[x]
def Unite(self,x,y):
x=self.Find_Root(x)
y=self.Find_Root(y)
if x==y:
return
elif self.rnk[x]>self.rnk[y]:
self.root[x]+=self.root[y]
self.root[y]=x
else:
self.root[y]+=self.root[x]
self.root[x]=y
if self.rnk[x]==self.rnk[y]:
self.rnk[y]+=1
def isSameGroup(self,x,y):
return self.Find_Root(x)==self.Find_Root(y)
def Count(self,x):
return -self.root[self.Find_Root(x)]
uf=UnionFind(n)
for _ in range(m):
x,y,z=list(map(int,input().split()))
uf.Unite(x,y)
ans=set()
for i in range(1,n+1):
ans.add(uf.Find_Root(i))
print((len(ans)))
| n,m=list(map(int,input().split()))
import sys
input=sys.stdin.readline
class UnionFind():
def __init__(self,n):
self.n=n
self.root=[-1]*(n+1)
self.rnk=[0]*(n+1)
def Find_Root(self,x):
if self.root[x]<0:
return x
else:
self.root[x]=self.Find_Root(self.root[x])
return self.root[x]
def Unite(self,x,y):
x=self.Find_Root(x)
y=self.Find_Root(y)
if x==y:
return
elif self.rnk[x]>self.rnk[y]:
self.root[x]+=self.root[y]
self.root[y]=x
else:
self.root[y]+=self.root[x]
self.root[x]=y
if self.rnk[x]==self.rnk[y]:
self.rnk[y]+=1
def isSameGroup(self,x,y):
return self.Find_Root(x)==self.Find_Root(y)
def Count(self,x):
return -self.root[self.Find_Root(x)]
uf=UnionFind(n)
for _ in range(m):
x,y,z=list(map(int,input().split()))
x-=1
y-=1
uf.Unite(x,y)
r=[0]*n
for i in range(n):
r[i]=uf.Find_Root(i)
s=set(r)
print((len(s)))
| 42 | 48 | 1,058 | 1,116 | n, m = list(map(int, input().split()))
class UnionFind:
def __init__(self, n):
self.n = n
self.root = [-1] * (n + 1)
self.rnk = [0] * (n + 1)
def Find_Root(self, x):
if self.root[x] < 0:
return x
else:
self.root[x] = self.Find_Root(self.root[x])
return self.root[x]
def Unite(self, x, y):
x = self.Find_Root(x)
y = self.Find_Root(y)
if x == y:
return
elif self.rnk[x] > self.rnk[y]:
self.root[x] += self.root[y]
self.root[y] = x
else:
self.root[y] += self.root[x]
self.root[x] = y
if self.rnk[x] == self.rnk[y]:
self.rnk[y] += 1
def isSameGroup(self, x, y):
return self.Find_Root(x) == self.Find_Root(y)
def Count(self, x):
return -self.root[self.Find_Root(x)]
uf = UnionFind(n)
for _ in range(m):
x, y, z = list(map(int, input().split()))
uf.Unite(x, y)
ans = set()
for i in range(1, n + 1):
ans.add(uf.Find_Root(i))
print((len(ans)))
| n, m = list(map(int, input().split()))
import sys
input = sys.stdin.readline
class UnionFind:
def __init__(self, n):
self.n = n
self.root = [-1] * (n + 1)
self.rnk = [0] * (n + 1)
def Find_Root(self, x):
if self.root[x] < 0:
return x
else:
self.root[x] = self.Find_Root(self.root[x])
return self.root[x]
def Unite(self, x, y):
x = self.Find_Root(x)
y = self.Find_Root(y)
if x == y:
return
elif self.rnk[x] > self.rnk[y]:
self.root[x] += self.root[y]
self.root[y] = x
else:
self.root[y] += self.root[x]
self.root[x] = y
if self.rnk[x] == self.rnk[y]:
self.rnk[y] += 1
def isSameGroup(self, x, y):
return self.Find_Root(x) == self.Find_Root(y)
def Count(self, x):
return -self.root[self.Find_Root(x)]
uf = UnionFind(n)
for _ in range(m):
x, y, z = list(map(int, input().split()))
x -= 1
y -= 1
uf.Unite(x, y)
r = [0] * n
for i in range(n):
r[i] = uf.Find_Root(i)
s = set(r)
print((len(s)))
| false | 12.5 | [
"+import sys",
"+",
"+input = sys.stdin.readline",
"+ x -= 1",
"+ y -= 1",
"-ans = set()",
"-for i in range(1, n + 1):",
"- ans.add(uf.Find_Root(i))",
"-print((len(ans)))",
"+r = [0] * n",
"+for i in range(n):",
"+ r[i] = uf.Find_Root(i)",
"+s = set(r)",
"+print((len(s)))"
] | false | 0.043764 | 0.042352 | 1.033351 | [
"s006198250",
"s106000578"
] |
u970197315 | p03208 | python | s923580277 | s453417578 | 386 | 243 | 16,724 | 7,384 | Accepted | Accepted | 37.05 | # ABC115 C - Christmas Eve
import numpy as np
N,K = list(map(int,input().split()))
H = [int(eval(input())) for _ in range(N)]
ans = 10**10
H.sort()
for i in range(N-K+1):
t = H[i+K-1] - H[i]
ans = min(ans,t)
print(ans) | n,k=list(map(int,input().split()))
h=[int(eval(input())) for i in range(n)]
h.sort()
ans=10**12
for i in range(n-k+1):
min_h=h[i+k-1]-h[i]
ans=min(ans,min_h)
print(ans)
| 12 | 11 | 227 | 178 | # ABC115 C - Christmas Eve
import numpy as np
N, K = list(map(int, input().split()))
H = [int(eval(input())) for _ in range(N)]
ans = 10**10
H.sort()
for i in range(N - K + 1):
t = H[i + K - 1] - H[i]
ans = min(ans, t)
print(ans)
| n, k = list(map(int, input().split()))
h = [int(eval(input())) for i in range(n)]
h.sort()
ans = 10**12
for i in range(n - k + 1):
min_h = h[i + k - 1] - h[i]
ans = min(ans, min_h)
print(ans)
| false | 8.333333 | [
"-# ABC115 C - Christmas Eve",
"-import numpy as np",
"-",
"-N, K = list(map(int, input().split()))",
"-H = [int(eval(input())) for _ in range(N)]",
"-ans = 10**10",
"-H.sort()",
"-for i in range(N - K + 1):",
"- t = H[i + K - 1] - H[i]",
"- ans = min(ans, t)",
"+n, k = list(map(int, input().split()))",
"+h = [int(eval(input())) for i in range(n)]",
"+h.sort()",
"+ans = 10**12",
"+for i in range(n - k + 1):",
"+ min_h = h[i + k - 1] - h[i]",
"+ ans = min(ans, min_h)"
] | false | 0.035734 | 0.036879 | 0.968931 | [
"s923580277",
"s453417578"
] |
u674052742 | p02813 | python | s050013302 | s713692300 | 225 | 29 | 42,352 | 3,064 | Accepted | Accepted | 87.11 | # -*- coding: utf-8 -*-
"""
Created on Thu May 7 03:09:14 2020
@author: Kanaru Sato
"""
import itertools as it
n = int(eval(input()))
l = []
for i in range(1,n+1):
l.append(i)
p = list(map(int, input().split()))
q = list(map(int, input().split()))
count = 0
for sequence in it.permutations(l,n):
if list(sequence) == p:
pnum = count
if list(sequence) == q:
qnum = count
count += 1
print((abs(pnum-qnum))) | # -*- coding: utf-8 -*-
"""
Created on Sun May 17 19:16:09 2020
@author: Kanaru Sato
"""
import itertools
n = int(eval(input()))
p = tuple(map(int,input().split()))
q = tuple(map(int,input().split()))
nums = [i+1 for i in range(n)]
count = 0
for perm in itertools.permutations(nums):
count += 1
if p == perm:
pcount = count
if q == perm:
qcount = count
print((abs(pcount-qcount))) | 24 | 23 | 456 | 427 | # -*- coding: utf-8 -*-
"""
Created on Thu May 7 03:09:14 2020
@author: Kanaru Sato
"""
import itertools as it
n = int(eval(input()))
l = []
for i in range(1, n + 1):
l.append(i)
p = list(map(int, input().split()))
q = list(map(int, input().split()))
count = 0
for sequence in it.permutations(l, n):
if list(sequence) == p:
pnum = count
if list(sequence) == q:
qnum = count
count += 1
print((abs(pnum - qnum)))
| # -*- coding: utf-8 -*-
"""
Created on Sun May 17 19:16:09 2020
@author: Kanaru Sato
"""
import itertools
n = int(eval(input()))
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
nums = [i + 1 for i in range(n)]
count = 0
for perm in itertools.permutations(nums):
count += 1
if p == perm:
pcount = count
if q == perm:
qcount = count
print((abs(pcount - qcount)))
| false | 4.166667 | [
"-Created on Thu May 7 03:09:14 2020",
"+Created on Sun May 17 19:16:09 2020",
"-import itertools as it",
"+import itertools",
"-l = []",
"-for i in range(1, n + 1):",
"- l.append(i)",
"-p = list(map(int, input().split()))",
"-q = list(map(int, input().split()))",
"+p = tuple(map(int, input().split()))",
"+q = tuple(map(int, input().split()))",
"+nums = [i + 1 for i in range(n)]",
"-for sequence in it.permutations(l, n):",
"- if list(sequence) == p:",
"- pnum = count",
"- if list(sequence) == q:",
"- qnum = count",
"+for perm in itertools.permutations(nums):",
"-print((abs(pnum - qnum)))",
"+ if p == perm:",
"+ pcount = count",
"+ if q == perm:",
"+ qcount = count",
"+print((abs(pcount - qcount)))"
] | false | 0.044101 | 0.039824 | 1.107403 | [
"s050013302",
"s713692300"
] |
u798803522 | p00189 | python | s534121910 | s911437819 | 40 | 30 | 7,784 | 7,796 | Accepted | Accepted | 25 | import sys
from sys import stdin
input = stdin.readline
road = int(eval(input()))
while road > 0:
answer = [[float("inf") if n != m else 0 for n in range(10)] for m in range(10)]
city = 0
for _ in range(road):
c1, c2, w = (int(n) for n in input().split(" "))
answer[c1][c2] = w
answer[c2][c1] = w
city = max(city, c1, c2)
city += 1
for i in range(city):
for j in range(city):
for k in range(city):
answer[j][k] = min(answer[j][k], answer[j][i] + answer[i][k])
sum_ans = [-1 , float("inf")]
for i in range(city):
if sum(answer[i][:city]) < sum_ans[1]:
sum_ans = [i, sum(answer[i][:city])]
print((*sum_ans))
road = int(eval(input())) | road = int(eval(input()))
while road > 0:
answer = [[float("inf") if n != m else 0 for n in range(10)] for m in range(10)]
city = 0
for _ in range(road):
c1, c2, w = (int(n) for n in input().split(" "))
answer[c1][c2] = w
answer[c2][c1] = w
city = max(city, c1, c2)
city += 1
for i in range(city):
for j in range(city):
for k in range(city):
answer[j][k] = min(answer[j][k], answer[j][i] + answer[i][k])
sum_ans = [-1 , float("inf")]
for i in range(city):
if sum(answer[i][:city]) < sum_ans[1]:
sum_ans = [i, sum(answer[i][:city])]
print((*sum_ans))
road = int(eval(input())) | 24 | 20 | 765 | 704 | import sys
from sys import stdin
input = stdin.readline
road = int(eval(input()))
while road > 0:
answer = [[float("inf") if n != m else 0 for n in range(10)] for m in range(10)]
city = 0
for _ in range(road):
c1, c2, w = (int(n) for n in input().split(" "))
answer[c1][c2] = w
answer[c2][c1] = w
city = max(city, c1, c2)
city += 1
for i in range(city):
for j in range(city):
for k in range(city):
answer[j][k] = min(answer[j][k], answer[j][i] + answer[i][k])
sum_ans = [-1, float("inf")]
for i in range(city):
if sum(answer[i][:city]) < sum_ans[1]:
sum_ans = [i, sum(answer[i][:city])]
print((*sum_ans))
road = int(eval(input()))
| road = int(eval(input()))
while road > 0:
answer = [[float("inf") if n != m else 0 for n in range(10)] for m in range(10)]
city = 0
for _ in range(road):
c1, c2, w = (int(n) for n in input().split(" "))
answer[c1][c2] = w
answer[c2][c1] = w
city = max(city, c1, c2)
city += 1
for i in range(city):
for j in range(city):
for k in range(city):
answer[j][k] = min(answer[j][k], answer[j][i] + answer[i][k])
sum_ans = [-1, float("inf")]
for i in range(city):
if sum(answer[i][:city]) < sum_ans[1]:
sum_ans = [i, sum(answer[i][:city])]
print((*sum_ans))
road = int(eval(input()))
| false | 16.666667 | [
"-import sys",
"-from sys import stdin",
"-",
"-input = stdin.readline"
] | false | 0.0432 | 0.034643 | 1.247015 | [
"s534121910",
"s911437819"
] |
u941407962 | p03212 | python | s430192348 | s515255015 | 344 | 287 | 9,424 | 7,752 | Accepted | Accepted | 16.57 | N=int(eval(input()))
f=lambda c:sum([list([z+y for z in f(c-1)]) for y in '357'],[]) if c!=0 else ['']
print((sum([len(list([y for y in list([len(set(sorted(x))) for x in [z for z in f(e+1) if int(z)<=N]]) if y==3])) for e in range(10)])))
| N=int(eval(input()))
r=filter
f=lambda c:sum([[z+y for z in f(c-1)]for y in'357'],[]) if c!=0 else ['']
print((sum([len(r(lambda y:y==3,[len(set(sorted(x))) for x in r(lambda z:int(z)<=N,f(e+1))]))for e in range(10)])))
| 3 | 4 | 242 | 221 | N = int(eval(input()))
f = (
lambda c: sum([list([z + y for z in f(c - 1)]) for y in "357"], [])
if c != 0
else [""]
)
print(
(
sum(
[
len(
list(
[
y
for y in list(
[
len(set(sorted(x)))
for x in [z for z in f(e + 1) if int(z) <= N]
]
)
if y == 3
]
)
)
for e in range(10)
]
)
)
)
| N = int(eval(input()))
r = filter
f = lambda c: sum([[z + y for z in f(c - 1)] for y in "357"], []) if c != 0 else [""]
print(
(
sum(
[
len(
r(
lambda y: y == 3,
[
len(set(sorted(x)))
for x in r(lambda z: int(z) <= N, f(e + 1))
],
)
)
for e in range(10)
]
)
)
)
| false | 25 | [
"-f = (",
"- lambda c: sum([list([z + y for z in f(c - 1)]) for y in \"357\"], [])",
"- if c != 0",
"- else [\"\"]",
"-)",
"+r = filter",
"+f = lambda c: sum([[z + y for z in f(c - 1)] for y in \"357\"], []) if c != 0 else [\"\"]",
"- list(",
"+ r(",
"+ lambda y: y == 3,",
"- y",
"- for y in list(",
"- [",
"- len(set(sorted(x)))",
"- for x in [z for z in f(e + 1) if int(z) <= N]",
"- ]",
"- )",
"- if y == 3",
"- ]",
"+ len(set(sorted(x)))",
"+ for x in r(lambda z: int(z) <= N, f(e + 1))",
"+ ],"
] | false | 0.491272 | 0.048717 | 10.084283 | [
"s430192348",
"s515255015"
] |
u261103969 | p02629 | python | s136946058 | s096003247 | 73 | 27 | 61,880 | 9,192 | Accepted | Accepted | 63.01 | import sys
readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)
def main():
n = int(readline())
chars = "abcdefghijklmnopqrstuvwxyz"
res = ""
for i in range(1, 100):
x = n % 26
if x == 0:
x = 26
res += chars[x - 1]
n -= x
n //= 26
if n == 0:
break
print((res[::-1]))
if __name__ == '__main__':
main()
| n = int(eval(input()))
chars = "Xabcdefghijklmnopqrstuvwxyz" # x番目がほしいときにchars[x-1]としたくないので、chars[0]は使わないことにします
res = ""
n_rem = n
while True:
x = n_rem % 26
# 余りが0、zの場合は、26にします
if x == 0:
x = 26
res += chars[x]
# xを引いて、26で割ります
n_rem -= x
n_rem //= 26
# 0なら終了します
if n_rem == 0:
break
# 0桁目が先頭で、最後の桁が末尾になっているので、反転させます
print((res[::-1])) | 27 | 23 | 472 | 407 | import sys
readline = sys.stdin.readline
MOD = 10**9 + 7
INF = float("INF")
sys.setrecursionlimit(10**5)
def main():
n = int(readline())
chars = "abcdefghijklmnopqrstuvwxyz"
res = ""
for i in range(1, 100):
x = n % 26
if x == 0:
x = 26
res += chars[x - 1]
n -= x
n //= 26
if n == 0:
break
print((res[::-1]))
if __name__ == "__main__":
main()
| n = int(eval(input()))
chars = (
"Xabcdefghijklmnopqrstuvwxyz" # x番目がほしいときにchars[x-1]としたくないので、chars[0]は使わないことにします
)
res = ""
n_rem = n
while True:
x = n_rem % 26
# 余りが0、zの場合は、26にします
if x == 0:
x = 26
res += chars[x]
# xを引いて、26で割ります
n_rem -= x
n_rem //= 26
# 0なら終了します
if n_rem == 0:
break
# 0桁目が先頭で、最後の桁が末尾になっているので、反転させます
print((res[::-1]))
| false | 14.814815 | [
"-import sys",
"-",
"-readline = sys.stdin.readline",
"-MOD = 10**9 + 7",
"-INF = float(\"INF\")",
"-sys.setrecursionlimit(10**5)",
"-",
"-",
"-def main():",
"- n = int(readline())",
"- chars = \"abcdefghijklmnopqrstuvwxyz\"",
"- res = \"\"",
"- for i in range(1, 100):",
"- x = n % 26",
"- if x == 0:",
"- x = 26",
"- res += chars[x - 1]",
"- n -= x",
"- n //= 26",
"- if n == 0:",
"- break",
"- print((res[::-1]))",
"-",
"-",
"-if __name__ == \"__main__\":",
"- main()",
"+n = int(eval(input()))",
"+chars = (",
"+ \"Xabcdefghijklmnopqrstuvwxyz\" # x番目がほしいときにchars[x-1]としたくないので、chars[0]は使わないことにします",
"+)",
"+res = \"\"",
"+n_rem = n",
"+while True:",
"+ x = n_rem % 26",
"+ # 余りが0、zの場合は、26にします",
"+ if x == 0:",
"+ x = 26",
"+ res += chars[x]",
"+ # xを引いて、26で割ります",
"+ n_rem -= x",
"+ n_rem //= 26",
"+ # 0なら終了します",
"+ if n_rem == 0:",
"+ break",
"+# 0桁目が先頭で、最後の桁が末尾になっているので、反転させます",
"+print((res[::-1]))"
] | false | 0.0354 | 0.03526 | 1.00395 | [
"s136946058",
"s096003247"
] |
u596536048 | p03555 | python | s507074742 | s826534806 | 26 | 24 | 9,052 | 8,732 | Accepted | Accepted | 7.69 | word1, word2 = [eval(input()) for i in range(2)]
if word1[0] == word2[2] and word1[1] == word2[1] and word1[2] == word2[0]:
print('YES')
else:
print('NO') | C1, C2 = [eval(input()) for i in range(2)]
print(('YES' if C1 == C2[::-1] else 'NO')) | 5 | 2 | 160 | 78 | word1, word2 = [eval(input()) for i in range(2)]
if word1[0] == word2[2] and word1[1] == word2[1] and word1[2] == word2[0]:
print("YES")
else:
print("NO")
| C1, C2 = [eval(input()) for i in range(2)]
print(("YES" if C1 == C2[::-1] else "NO"))
| false | 60 | [
"-word1, word2 = [eval(input()) for i in range(2)]",
"-if word1[0] == word2[2] and word1[1] == word2[1] and word1[2] == word2[0]:",
"- print(\"YES\")",
"-else:",
"- print(\"NO\")",
"+C1, C2 = [eval(input()) for i in range(2)]",
"+print((\"YES\" if C1 == C2[::-1] else \"NO\"))"
] | false | 0.091225 | 0.045155 | 2.020264 | [
"s507074742",
"s826534806"
] |
u624696727 | p03166 | python | s191766885 | s951288516 | 421 | 346 | 59,056 | 23,036 | Accepted | Accepted | 17.81 | import sys
sys.setrecursionlimit(10**5+10)
input = sys.stdin.readline
N,M = list(map(int, input().split()))
lst_edge = [[] for _ in range(N)]
for _ in range(M):
x,y = list(map(int, input().split()))
lst_edge[x-1].append(y-1)
dp = [-1] * N
def rec(v):
if dp[v] != -1:
return dp[v]
ans = 0
lst_nv = lst_edge[v]
for nv in lst_nv:
ans = max(ans, rec(nv)+1)
dp[v] = ans
return dp[v]
ans = 0
for v in range(N):
ans = max(ans,rec(v))
print(ans) | import sys
import collections
input = sys.stdin.readline
def chmax(a,b):
if a>b :
return a
return b
N,M = list(map(int, input().split()))
lst_edge = [[] for _ in range(N)]
deg = [0]*N
for _ in range(M):
x,y = list(map(int, input().split()))
lst_edge[x-1].append(y-1)
deg[y-1] += 1
que = collections.deque()
for v in range(N):
if deg[v] == 0:
que.append(v)
dp = [0]*N
while que:
v = que.popleft()
for nv in lst_edge[v]:
deg[nv] -= 1
if(deg[nv] == 0):
que.append(nv)
dp[nv] = chmax(dp[nv], dp[v]+1)
print((max(dp))) | 27 | 33 | 469 | 560 | import sys
sys.setrecursionlimit(10**5 + 10)
input = sys.stdin.readline
N, M = list(map(int, input().split()))
lst_edge = [[] for _ in range(N)]
for _ in range(M):
x, y = list(map(int, input().split()))
lst_edge[x - 1].append(y - 1)
dp = [-1] * N
def rec(v):
if dp[v] != -1:
return dp[v]
ans = 0
lst_nv = lst_edge[v]
for nv in lst_nv:
ans = max(ans, rec(nv) + 1)
dp[v] = ans
return dp[v]
ans = 0
for v in range(N):
ans = max(ans, rec(v))
print(ans)
| import sys
import collections
input = sys.stdin.readline
def chmax(a, b):
if a > b:
return a
return b
N, M = list(map(int, input().split()))
lst_edge = [[] for _ in range(N)]
deg = [0] * N
for _ in range(M):
x, y = list(map(int, input().split()))
lst_edge[x - 1].append(y - 1)
deg[y - 1] += 1
que = collections.deque()
for v in range(N):
if deg[v] == 0:
que.append(v)
dp = [0] * N
while que:
v = que.popleft()
for nv in lst_edge[v]:
deg[nv] -= 1
if deg[nv] == 0:
que.append(nv)
dp[nv] = chmax(dp[nv], dp[v] + 1)
print((max(dp)))
| false | 18.181818 | [
"+import collections",
"-sys.setrecursionlimit(10**5 + 10)",
"+",
"+",
"+def chmax(a, b):",
"+ if a > b:",
"+ return a",
"+ return b",
"+",
"+",
"+deg = [0] * N",
"-dp = [-1] * N",
"-",
"-",
"-def rec(v):",
"- if dp[v] != -1:",
"- return dp[v]",
"- ans = 0",
"- lst_nv = lst_edge[v]",
"- for nv in lst_nv:",
"- ans = max(ans, rec(nv) + 1)",
"- dp[v] = ans",
"- return dp[v]",
"-",
"-",
"-ans = 0",
"+ deg[y - 1] += 1",
"+que = collections.deque()",
"- ans = max(ans, rec(v))",
"-print(ans)",
"+ if deg[v] == 0:",
"+ que.append(v)",
"+dp = [0] * N",
"+while que:",
"+ v = que.popleft()",
"+ for nv in lst_edge[v]:",
"+ deg[nv] -= 1",
"+ if deg[nv] == 0:",
"+ que.append(nv)",
"+ dp[nv] = chmax(dp[nv], dp[v] + 1)",
"+print((max(dp)))"
] | false | 0.047315 | 0.047389 | 0.998427 | [
"s191766885",
"s951288516"
] |
u597374218 | p02622 | python | s546446962 | s484465793 | 68 | 58 | 9,404 | 9,548 | Accepted | Accepted | 14.71 | S=eval(input())
T=eval(input())
count=0
for i in range(len(S)):
if S[i]!=T[i]:
count+=1
print(count) | S = eval(input())
T = eval(input())
count = 0
for s, t in zip(S, T):
if s != t:
count += 1
print(count) | 7 | 7 | 106 | 109 | S = eval(input())
T = eval(input())
count = 0
for i in range(len(S)):
if S[i] != T[i]:
count += 1
print(count)
| S = eval(input())
T = eval(input())
count = 0
for s, t in zip(S, T):
if s != t:
count += 1
print(count)
| false | 0 | [
"-for i in range(len(S)):",
"- if S[i] != T[i]:",
"+for s, t in zip(S, T):",
"+ if s != t:"
] | false | 0.047271 | 0.048135 | 0.982047 | [
"s546446962",
"s484465793"
] |
u673361376 | p02995 | python | s259213174 | s402971355 | 286 | 37 | 64,364 | 5,088 | Accepted | Accepted | 87.06 | from fractions import gcd
def get_num(div):
num = (B)//div - (A-1)//div
return num
A,B,C,D = list(map(int,input().split()))
print((B-A+1-get_num(C)-get_num(D)+get_num(C*D//gcd(C,D)))) | from fractions import gcd
A, B, C, D = list(map(int,input().split()))
total = B - A + 1
divC = B//C - (A-1)//C
divD = B//D - (A-1)//D
lcm = int(C * D / gcd(C, D))
divCD = B//lcm - (A-1)//lcm
print((total - divC - divD + divCD))
| 8 | 8 | 188 | 227 | from fractions import gcd
def get_num(div):
num = (B) // div - (A - 1) // div
return num
A, B, C, D = list(map(int, input().split()))
print((B - A + 1 - get_num(C) - get_num(D) + get_num(C * D // gcd(C, D))))
| from fractions import gcd
A, B, C, D = list(map(int, input().split()))
total = B - A + 1
divC = B // C - (A - 1) // C
divD = B // D - (A - 1) // D
lcm = int(C * D / gcd(C, D))
divCD = B // lcm - (A - 1) // lcm
print((total - divC - divD + divCD))
| false | 0 | [
"-",
"-def get_num(div):",
"- num = (B) // div - (A - 1) // div",
"- return num",
"-",
"-",
"-print((B - A + 1 - get_num(C) - get_num(D) + get_num(C * D // gcd(C, D))))",
"+total = B - A + 1",
"+divC = B // C - (A - 1) // C",
"+divD = B // D - (A - 1) // D",
"+lcm = int(C * D / gcd(C, D))",
"+divCD = B // lcm - (A - 1) // lcm",
"+print((total - divC - divD + divCD))"
] | false | 0.115907 | 0.135292 | 0.856717 | [
"s259213174",
"s402971355"
] |
u644907318 | p02861 | python | s438669038 | s501967271 | 98 | 89 | 74,508 | 74,328 | Accepted | Accepted | 9.18 | from itertools import permutations
def dist(x,y):
return ((x[0]-y[0])**2+(x[1]-y[1])**2)**0.5
N = int(eval(input()))
X = [list(map(int,input().split())) for _ in range(N)]
cnt = 0
for z in permutations(list(range(N)),N):
for i in range(1,N):
cnt += dist(X[z[i]],X[z[i-1]])
k = 1
for i in range(2,N+1):
k = k*i
print((cnt/k)) | from itertools import permutations
import math
def dist(x,y):
return ((x[0]-y[0])**2+(x[1]-y[1])**2)**0.5
N = int(eval(input()))
X = [list(map(int,input().split())) for _ in range(N)]
A = [[0 for _ in range(N)] for _ in range(N)]
for i in range(N):
for j in range(N):
A[i][j] = dist(X[i],X[j])
tot = 0
for x in permutations(list(range(N)),N):
cnt = 0
for i in range(1,N):
cnt += A[x[i-1]][x[i]]
tot += cnt
print((tot/math.factorial(N))) | 13 | 18 | 342 | 476 | from itertools import permutations
def dist(x, y):
return ((x[0] - y[0]) ** 2 + (x[1] - y[1]) ** 2) ** 0.5
N = int(eval(input()))
X = [list(map(int, input().split())) for _ in range(N)]
cnt = 0
for z in permutations(list(range(N)), N):
for i in range(1, N):
cnt += dist(X[z[i]], X[z[i - 1]])
k = 1
for i in range(2, N + 1):
k = k * i
print((cnt / k))
| from itertools import permutations
import math
def dist(x, y):
return ((x[0] - y[0]) ** 2 + (x[1] - y[1]) ** 2) ** 0.5
N = int(eval(input()))
X = [list(map(int, input().split())) for _ in range(N)]
A = [[0 for _ in range(N)] for _ in range(N)]
for i in range(N):
for j in range(N):
A[i][j] = dist(X[i], X[j])
tot = 0
for x in permutations(list(range(N)), N):
cnt = 0
for i in range(1, N):
cnt += A[x[i - 1]][x[i]]
tot += cnt
print((tot / math.factorial(N)))
| false | 27.777778 | [
"+import math",
"-cnt = 0",
"-for z in permutations(list(range(N)), N):",
"+A = [[0 for _ in range(N)] for _ in range(N)]",
"+for i in range(N):",
"+ for j in range(N):",
"+ A[i][j] = dist(X[i], X[j])",
"+tot = 0",
"+for x in permutations(list(range(N)), N):",
"+ cnt = 0",
"- cnt += dist(X[z[i]], X[z[i - 1]])",
"-k = 1",
"-for i in range(2, N + 1):",
"- k = k * i",
"-print((cnt / k))",
"+ cnt += A[x[i - 1]][x[i]]",
"+ tot += cnt",
"+print((tot / math.factorial(N)))"
] | false | 0.040338 | 0.040895 | 0.986393 | [
"s438669038",
"s501967271"
] |
u588341295 | p03703 | python | s741704313 | s381430182 | 1,579 | 515 | 53,168 | 111,616 | Accepted | Accepted | 67.38 | # -*- coding: utf-8 -*-
import sys
from itertools import accumulate
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 ** 7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
class BIT:
def __init__(self, n):
# 0-indexed
nv = 1
while nv < n:
nv *= 2
self.size = nv
self.tree = [0] * nv
def sum(self, i):
""" [0, i]を合計する """
s = 0
i += 1
while i > 0:
s += self.tree[i-1]
i -= i & -i
return s
def add(self, i, x):
""" 値の追加:添字i, 値x """
i += 1
while i <= self.size:
self.tree[i-1] += x
i += i & -i
def get(self, l, r=None):
""" 区間和の取得 [l, r) """
# 引数が1つなら一点の値を取得
if r is None: r = l + 1
res = 0
if r: res += self.sum(r-1)
if l: res -= self.sum(l-1)
return res
N, K = MAP()
# 予め-Kした状態で用意しておく
A = [a-K for a in LIST(N)]
# 累積和
acc = [0] + list(accumulate(A))
# 座標圧縮
zip_acc = {}
for i, a in enumerate(sorted(set(acc))):
zip_acc[a] = i
bit = BIT(len(zip_acc))
cnt = 0
for a in acc:
# 自分より左にある、自分の値以下の数(転倒数の数え上げ)
cnt += bit.sum(zip_acc[a])
bit.add(zip_acc[a], 1)
print(cnt)
| # -*- coding: utf-8 -*-
import sys
from itertools import accumulate
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 ** 7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
class BIT:
def __init__(self, n):
# 0-indexed
nv = 1
while nv < n:
nv *= 2
self.size = nv
self.tree = [0] * nv
def sum(self, i):
""" [0, i]を合計する """
s = 0
i += 1
while i > 0:
s += self.tree[i-1]
i -= i & -i
return s
def add(self, i, x):
""" 値の追加:添字i, 値x """
i += 1
while i <= self.size:
self.tree[i-1] += x
i += i & -i
def get(self, l, r=None):
""" 区間和の取得 [l, r) """
# 引数が1つなら一点の値を取得
if r is None: r = l + 1
res = 0
if r: res += self.sum(r-1)
if l: res -= self.sum(l-1)
return res
def compress(A):
""" 座標圧縮 """
zipped, unzipped = {}, {}
for i, a in enumerate(sorted(set(A))):
zipped[a] = i
unzipped[i] = a
return zipped, unzipped
N, K = MAP()
# 予め-Kした状態で用意しておく
A = [a-K for a in LIST(N)]
# 累積和
acc = [0] + list(accumulate(A))
# 座標圧縮
zipped, _ = compress(acc)
bit = BIT(len(zipped))
cnt = 0
for a in acc:
# 自分より左にある、自分の値以下の数(転倒数の数え上げ)
cnt += bit.sum(zipped[a])
bit.add(zipped[a], 1)
print(cnt)
| 74 | 81 | 1,832 | 1,972 | # -*- coding: utf-8 -*-
import sys
from itertools import accumulate
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**7)
INF = 10**18
MOD = 10**9 + 7
class BIT:
def __init__(self, n):
# 0-indexed
nv = 1
while nv < n:
nv *= 2
self.size = nv
self.tree = [0] * nv
def sum(self, i):
"""[0, i]を合計する"""
s = 0
i += 1
while i > 0:
s += self.tree[i - 1]
i -= i & -i
return s
def add(self, i, x):
"""値の追加:添字i, 値x"""
i += 1
while i <= self.size:
self.tree[i - 1] += x
i += i & -i
def get(self, l, r=None):
"""区間和の取得 [l, r)"""
# 引数が1つなら一点の値を取得
if r is None:
r = l + 1
res = 0
if r:
res += self.sum(r - 1)
if l:
res -= self.sum(l - 1)
return res
N, K = MAP()
# 予め-Kした状態で用意しておく
A = [a - K for a in LIST(N)]
# 累積和
acc = [0] + list(accumulate(A))
# 座標圧縮
zip_acc = {}
for i, a in enumerate(sorted(set(acc))):
zip_acc[a] = i
bit = BIT(len(zip_acc))
cnt = 0
for a in acc:
# 自分より左にある、自分の値以下の数(転倒数の数え上げ)
cnt += bit.sum(zip_acc[a])
bit.add(zip_acc[a], 1)
print(cnt)
| # -*- coding: utf-8 -*-
import sys
from itertools import accumulate
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**7)
INF = 10**18
MOD = 10**9 + 7
class BIT:
def __init__(self, n):
# 0-indexed
nv = 1
while nv < n:
nv *= 2
self.size = nv
self.tree = [0] * nv
def sum(self, i):
"""[0, i]を合計する"""
s = 0
i += 1
while i > 0:
s += self.tree[i - 1]
i -= i & -i
return s
def add(self, i, x):
"""値の追加:添字i, 値x"""
i += 1
while i <= self.size:
self.tree[i - 1] += x
i += i & -i
def get(self, l, r=None):
"""区間和の取得 [l, r)"""
# 引数が1つなら一点の値を取得
if r is None:
r = l + 1
res = 0
if r:
res += self.sum(r - 1)
if l:
res -= self.sum(l - 1)
return res
def compress(A):
"""座標圧縮"""
zipped, unzipped = {}, {}
for i, a in enumerate(sorted(set(A))):
zipped[a] = i
unzipped[i] = a
return zipped, unzipped
N, K = MAP()
# 予め-Kした状態で用意しておく
A = [a - K for a in LIST(N)]
# 累積和
acc = [0] + list(accumulate(A))
# 座標圧縮
zipped, _ = compress(acc)
bit = BIT(len(zipped))
cnt = 0
for a in acc:
# 自分より左にある、自分の値以下の数(転倒数の数え上げ)
cnt += bit.sum(zipped[a])
bit.add(zipped[a], 1)
print(cnt)
| false | 8.641975 | [
"+def compress(A):",
"+ \"\"\"座標圧縮\"\"\"",
"+ zipped, unzipped = {}, {}",
"+ for i, a in enumerate(sorted(set(A))):",
"+ zipped[a] = i",
"+ unzipped[i] = a",
"+ return zipped, unzipped",
"+",
"+",
"-zip_acc = {}",
"-for i, a in enumerate(sorted(set(acc))):",
"- zip_acc[a] = i",
"-bit = BIT(len(zip_acc))",
"+zipped, _ = compress(acc)",
"+bit = BIT(len(zipped))",
"- cnt += bit.sum(zip_acc[a])",
"- bit.add(zip_acc[a], 1)",
"+ cnt += bit.sum(zipped[a])",
"+ bit.add(zipped[a], 1)"
] | false | 0.043617 | 0.050313 | 0.866914 | [
"s741704313",
"s381430182"
] |
u058781705 | p03293 | python | s011995681 | s175388023 | 71 | 64 | 61,876 | 62,112 | Accepted | Accepted | 9.86 | def rolling(str, n):
return str[n:len(str)] + str[:n]
S = eval(input())
T = eval(input())
for i in range(len(S)):
if rolling(S, i) == T:
print("Yes")
exit()
print("No")
| S = list(eval(input()))
T = list(eval(input()))
def rolling(str, n):
return str[n:len(str)] + str[:n]
for i in range(len(S)):
if S == rolling(T, i):
print("Yes")
exit()
print("No")
| 12 | 14 | 195 | 211 | def rolling(str, n):
return str[n : len(str)] + str[:n]
S = eval(input())
T = eval(input())
for i in range(len(S)):
if rolling(S, i) == T:
print("Yes")
exit()
print("No")
| S = list(eval(input()))
T = list(eval(input()))
def rolling(str, n):
return str[n : len(str)] + str[:n]
for i in range(len(S)):
if S == rolling(T, i):
print("Yes")
exit()
print("No")
| false | 14.285714 | [
"+S = list(eval(input()))",
"+T = list(eval(input()))",
"+",
"+",
"-S = eval(input())",
"-T = eval(input())",
"- if rolling(S, i) == T:",
"+ if S == rolling(T, i):"
] | false | 0.054035 | 0.081334 | 0.664363 | [
"s011995681",
"s175388023"
] |
u606045429 | p02773 | python | s769969169 | s093346969 | 453 | 413 | 45,300 | 38,392 | Accepted | Accepted | 8.83 | from collections import Counter
N, *S = open(0).read().split()
C = Counter(S).most_common()
ma = C[0][1]
ans = sorted(k for k, v in C if v == ma)
for a in ans:
print(a) | from collections import Counter
N, *S = open(0).read().split()
C = Counter(S)
ma = max(C.values())
ans = sorted(k for k, v in list(C.items()) if v == ma)
for a in ans:
print(a) | 11 | 11 | 186 | 188 | from collections import Counter
N, *S = open(0).read().split()
C = Counter(S).most_common()
ma = C[0][1]
ans = sorted(k for k, v in C if v == ma)
for a in ans:
print(a)
| from collections import Counter
N, *S = open(0).read().split()
C = Counter(S)
ma = max(C.values())
ans = sorted(k for k, v in list(C.items()) if v == ma)
for a in ans:
print(a)
| false | 0 | [
"-C = Counter(S).most_common()",
"-ma = C[0][1]",
"-ans = sorted(k for k, v in C if v == ma)",
"+C = Counter(S)",
"+ma = max(C.values())",
"+ans = sorted(k for k, v in list(C.items()) if v == ma)"
] | false | 0.087883 | 0.035841 | 2.45205 | [
"s769969169",
"s093346969"
] |
u156815136 | p03240 | python | s539147230 | s226437936 | 57 | 50 | 5,148 | 10,364 | Accepted | Accepted | 12.28 | from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
# d = m - k[i] - k[j]
# if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
def readInts():
return list(map(int,input().split()))
def I():
return int(eval(input()))
n = I()
x = [];y=[];h=[]
sh = -1
for i in range(n):
xa,ya,ha = readInts()
x.append(xa);y.append(ya);h.append(ha);
if ha > 0:
sh = i
# CxとCyを特定しておく すべてにおいて合致するかを考える
resx = -1;resy =-1;resh=-1;
for Cx in range(101):
for Cy in range(101):
ok = True
H = h[sh] + abs(x[sh] - Cx) + abs(y[sh] - Cy)
# 全操作して合致するようにする
for i in range(n):
if h[i] == 0:
if H > abs(x[i] - Cx) + abs(y[i] - Cy):
ok = False
break
elif h[i] > 0:
if H -h[i] != abs(x[i] - Cx) + abs(y[i] - Cy):
ok = False
break
if ok:
resx = Cx;resy = Cy;resh = H;
print((resx,resy,resh))
| #from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
#import bisect
#
# d = m - k[i] - k[j]
# if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
return list(map(int,input().split()))
def I():
return int(eval(input()))
n = I()
X = [];Y = [];H = []
for i in range(n):
x,y,h = readInts()
X.append(x)
Y.append(y)
H.append(h)
if h > 0:
si = i
resx=-1;resy=-1;resh=-1;
for cx in range(101):
for cy in range(101):
judge = True
h = H[si] + abs(X[si] - cx) + abs(Y[si] - cy)
for i in range(n):
if H[i] == 0:
if h > abs(X[i] - cx) + abs(Y[i] - cy):
judge ^=True
break
else:
if h - H[i] != abs(X[i]-cx) + abs(Y[i]-cy):
judge ^= True
break
if judge:
resx =cx;resy=cy;resh=h;
print((resx,resy,resh))
| 54 | 53 | 1,360 | 1,360 | from statistics import median
# import collections
# aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
# d = m - k[i] - k[j]
# if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
def readInts():
return list(map(int, input().split()))
def I():
return int(eval(input()))
n = I()
x = []
y = []
h = []
sh = -1
for i in range(n):
xa, ya, ha = readInts()
x.append(xa)
y.append(ya)
h.append(ha)
if ha > 0:
sh = i
# CxとCyを特定しておく すべてにおいて合致するかを考える
resx = -1
resy = -1
resh = -1
for Cx in range(101):
for Cy in range(101):
ok = True
H = h[sh] + abs(x[sh] - Cx) + abs(y[sh] - Cy)
# 全操作して合致するようにする
for i in range(n):
if h[i] == 0:
if H > abs(x[i] - Cx) + abs(y[i] - Cy):
ok = False
break
elif h[i] > 0:
if H - h[i] != abs(x[i] - Cx) + abs(y[i] - Cy):
ok = False
break
if ok:
resx = Cx
resy = Cy
resh = H
print((resx, resy, resh))
| # from statistics import median
# import collections
# aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations, permutations, accumulate # (string,3) 3回
# from collections import deque
from collections import deque, defaultdict, Counter
import decimal
# import bisect
#
# d = m - k[i] - k[j]
# if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
# mod = 9982443453
def readInts():
return list(map(int, input().split()))
def I():
return int(eval(input()))
n = I()
X = []
Y = []
H = []
for i in range(n):
x, y, h = readInts()
X.append(x)
Y.append(y)
H.append(h)
if h > 0:
si = i
resx = -1
resy = -1
resh = -1
for cx in range(101):
for cy in range(101):
judge = True
h = H[si] + abs(X[si] - cx) + abs(Y[si] - cy)
for i in range(n):
if H[i] == 0:
if h > abs(X[i] - cx) + abs(Y[i] - cy):
judge ^= True
break
else:
if h - H[i] != abs(X[i] - cx) + abs(Y[i] - cy):
judge ^= True
break
if judge:
resx = cx
resy = cy
resh = h
print((resx, resy, resh))
| false | 1.851852 | [
"-from statistics import median",
"-",
"+# from statistics import median",
"-from itertools import combinations # (string,3) 3回",
"-from collections import deque",
"-from collections import defaultdict",
"-import bisect",
"+from itertools import combinations, permutations, accumulate # (string,3) 3回",
"+# from collections import deque",
"+from collections import deque, defaultdict, Counter",
"+import decimal",
"+",
"+# import bisect",
"-",
"-",
"+# mod = 9982443453",
"-x = []",
"-y = []",
"-h = []",
"-sh = -1",
"+X = []",
"+Y = []",
"+H = []",
"- xa, ya, ha = readInts()",
"- x.append(xa)",
"- y.append(ya)",
"- h.append(ha)",
"- if ha > 0:",
"- sh = i",
"-# CxとCyを特定しておく すべてにおいて合致するかを考える",
"+ x, y, h = readInts()",
"+ X.append(x)",
"+ Y.append(y)",
"+ H.append(h)",
"+ if h > 0:",
"+ si = i",
"-for Cx in range(101):",
"- for Cy in range(101):",
"- ok = True",
"- H = h[sh] + abs(x[sh] - Cx) + abs(y[sh] - Cy)",
"- # 全操作して合致するようにする",
"+for cx in range(101):",
"+ for cy in range(101):",
"+ judge = True",
"+ h = H[si] + abs(X[si] - cx) + abs(Y[si] - cy)",
"- if h[i] == 0:",
"- if H > abs(x[i] - Cx) + abs(y[i] - Cy):",
"- ok = False",
"+ if H[i] == 0:",
"+ if h > abs(X[i] - cx) + abs(Y[i] - cy):",
"+ judge ^= True",
"- elif h[i] > 0:",
"- if H - h[i] != abs(x[i] - Cx) + abs(y[i] - Cy):",
"- ok = False",
"+ else:",
"+ if h - H[i] != abs(X[i] - cx) + abs(Y[i] - cy):",
"+ judge ^= True",
"- if ok:",
"- resx = Cx",
"- resy = Cy",
"- resh = H",
"+ if judge:",
"+ resx = cx",
"+ resy = cy",
"+ resh = h"
] | false | 0.075444 | 0.07055 | 1.069366 | [
"s539147230",
"s226437936"
] |
u562935282 | p02623 | python | s542193091 | s136854902 | 214 | 186 | 40,564 | 50,672 | Accepted | Accepted | 13.08 | def main():
N, M, K = list(map(int, input().split()))
*A, = list(map(int, input().split()))
*B, = list(map(int, input().split()))
s = 0
j = 0
while j < len(B) and s + B[j] <= K:
s += B[j]
j += 1
ans = cnt = j
j -= 1
for x in A:
while j >= 0 and s + x > K:
s -= B[j]
j -= 1
cnt -= 1
if s + x > K:
break
s += x
cnt += 1
if ans < cnt:
ans = cnt
print(ans)
if __name__ == '__main__':
main()
| # 解説
def main():
N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
def accumulate(a):
s = 0
yield s
for x in a:
s += x
yield s
*A, = accumulate(A)
*B, = accumulate(B)
ans = 0
j = M
for i, x in enumerate(A):
if x > K: break
while B[j] > K - x: j -= 1
ans = max(ans, i + j)
print(ans)
if __name__ == '__main__':
main()
| 30 | 30 | 563 | 516 | def main():
N, M, K = list(map(int, input().split()))
(*A,) = list(map(int, input().split()))
(*B,) = list(map(int, input().split()))
s = 0
j = 0
while j < len(B) and s + B[j] <= K:
s += B[j]
j += 1
ans = cnt = j
j -= 1
for x in A:
while j >= 0 and s + x > K:
s -= B[j]
j -= 1
cnt -= 1
if s + x > K:
break
s += x
cnt += 1
if ans < cnt:
ans = cnt
print(ans)
if __name__ == "__main__":
main()
| # 解説
def main():
N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
def accumulate(a):
s = 0
yield s
for x in a:
s += x
yield s
(*A,) = accumulate(A)
(*B,) = accumulate(B)
ans = 0
j = M
for i, x in enumerate(A):
if x > K:
break
while B[j] > K - x:
j -= 1
ans = max(ans, i + j)
print(ans)
if __name__ == "__main__":
main()
| false | 0 | [
"+# 解説",
"- (*A,) = list(map(int, input().split()))",
"- (*B,) = list(map(int, input().split()))",
"- s = 0",
"- j = 0",
"- while j < len(B) and s + B[j] <= K:",
"- s += B[j]",
"- j += 1",
"- ans = cnt = j",
"- j -= 1",
"- for x in A:",
"- while j >= 0 and s + x > K:",
"- s -= B[j]",
"+ A = list(map(int, input().split()))",
"+ B = list(map(int, input().split()))",
"+",
"+ def accumulate(a):",
"+ s = 0",
"+ yield s",
"+ for x in a:",
"+ s += x",
"+ yield s",
"+",
"+ (*A,) = accumulate(A)",
"+ (*B,) = accumulate(B)",
"+ ans = 0",
"+ j = M",
"+ for i, x in enumerate(A):",
"+ if x > K:",
"+ break",
"+ while B[j] > K - x:",
"- cnt -= 1",
"- if s + x > K:",
"- break",
"- s += x",
"- cnt += 1",
"- if ans < cnt:",
"- ans = cnt",
"+ ans = max(ans, i + j)"
] | false | 0.043877 | 0.070454 | 0.622776 | [
"s542193091",
"s136854902"
] |
u945359338 | p02658 | python | s767020893 | s835958845 | 94 | 76 | 21,528 | 21,700 | Accepted | Accepted | 19.15 | N = int(eval(input()))
A = list(map(int, input().split()))
ans = 1
l = 0;
flag = 0
for i in range(N):
if A[i]== 0:
print((0))
exit(0)
l+=(len(str(A[i])) -1)
if l>18:
flag=1
continue
ans*=A[i]
if ans > 1000000000000000000:
flag = 1
if flag == 0:
print(ans)
else :
print((-1)) | N=int(eval(input()))
A=list(map(int, input().split()))
A=sorted(A)
if A[0] == 0:
print((0))
exit(0)
ans = 1
for i in range(N):
ans*=A[i]
if(ans>1000000000000000000):
print((-1))
exit(0)
print(ans) | 25 | 14 | 365 | 216 | N = int(eval(input()))
A = list(map(int, input().split()))
ans = 1
l = 0
flag = 0
for i in range(N):
if A[i] == 0:
print((0))
exit(0)
l += len(str(A[i])) - 1
if l > 18:
flag = 1
continue
ans *= A[i]
if ans > 1000000000000000000:
flag = 1
if flag == 0:
print(ans)
else:
print((-1))
| N = int(eval(input()))
A = list(map(int, input().split()))
A = sorted(A)
if A[0] == 0:
print((0))
exit(0)
ans = 1
for i in range(N):
ans *= A[i]
if ans > 1000000000000000000:
print((-1))
exit(0)
print(ans)
| false | 44 | [
"+A = sorted(A)",
"+if A[0] == 0:",
"+ print((0))",
"+ exit(0)",
"-l = 0",
"-flag = 0",
"- if A[i] == 0:",
"- print((0))",
"- exit(0)",
"- l += len(str(A[i])) - 1",
"- if l > 18:",
"- flag = 1",
"- continue",
"- flag = 1",
"-if flag == 0:",
"- print(ans)",
"-else:",
"- print((-1))",
"+ print((-1))",
"+ exit(0)",
"+print(ans)"
] | false | 0.040941 | 0.0914 | 0.447931 | [
"s767020893",
"s835958845"
] |
u977389981 | p03012 | python | s055712013 | s525267912 | 167 | 18 | 38,512 | 3,060 | Accepted | Accepted | 89.22 | N = int(eval(input()))
W = [int(i) for i in input().split()]
A = sum(W)
ans = float('inf')
for i in range(N):
tmp = abs(sum(W[: i]) - (A - sum(W[: i])))
ans = min(ans, tmp)
print(ans) | n = int(eval(input()))
W = list(map(int, input().split()))
diff = float('inf')
for i in range(1, n):
x = abs(sum(W[: i]) - sum(W[i :]))
if x < diff:
diff = x
print(diff) | 10 | 10 | 200 | 198 | N = int(eval(input()))
W = [int(i) for i in input().split()]
A = sum(W)
ans = float("inf")
for i in range(N):
tmp = abs(sum(W[:i]) - (A - sum(W[:i])))
ans = min(ans, tmp)
print(ans)
| n = int(eval(input()))
W = list(map(int, input().split()))
diff = float("inf")
for i in range(1, n):
x = abs(sum(W[:i]) - sum(W[i:]))
if x < diff:
diff = x
print(diff)
| false | 0 | [
"-N = int(eval(input()))",
"-W = [int(i) for i in input().split()]",
"-A = sum(W)",
"-ans = float(\"inf\")",
"-for i in range(N):",
"- tmp = abs(sum(W[:i]) - (A - sum(W[:i])))",
"- ans = min(ans, tmp)",
"-print(ans)",
"+n = int(eval(input()))",
"+W = list(map(int, input().split()))",
"+diff = float(\"inf\")",
"+for i in range(1, n):",
"+ x = abs(sum(W[:i]) - sum(W[i:]))",
"+ if x < diff:",
"+ diff = x",
"+print(diff)"
] | false | 0.047329 | 0.04111 | 1.151297 | [
"s055712013",
"s525267912"
] |
u940139461 | p03699 | python | s520654678 | s918478565 | 169 | 72 | 38,456 | 62,436 | Accepted | Accepted | 57.4 | n = int(eval(input()))
nums = []
for _ in range(n):
nums.append(int(eval(input())))
nums.sort()
ans = sum(nums)
if ans % 10 != 0:
print(ans)
else:
for num in nums:
t = ans - num
if t % 10 != 0:
print(t)
break
else:
print((0)) | import sys
n = int(eval(input()))
nums = []
for _ in range(n):
nums.append(int(eval(input())))
s = sum(nums)
if s % 10 != 0:
print(s)
else:
nums.sort()
for num in nums:
t = s - num
if t % 10 != 0:
print(t)
break
else:
print((0)) | 16 | 18 | 290 | 300 | n = int(eval(input()))
nums = []
for _ in range(n):
nums.append(int(eval(input())))
nums.sort()
ans = sum(nums)
if ans % 10 != 0:
print(ans)
else:
for num in nums:
t = ans - num
if t % 10 != 0:
print(t)
break
else:
print((0))
| import sys
n = int(eval(input()))
nums = []
for _ in range(n):
nums.append(int(eval(input())))
s = sum(nums)
if s % 10 != 0:
print(s)
else:
nums.sort()
for num in nums:
t = s - num
if t % 10 != 0:
print(t)
break
else:
print((0))
| false | 11.111111 | [
"+import sys",
"+",
"-nums.sort()",
"-ans = sum(nums)",
"-if ans % 10 != 0:",
"- print(ans)",
"+s = sum(nums)",
"+if s % 10 != 0:",
"+ print(s)",
"+ nums.sort()",
"- t = ans - num",
"+ t = s - num"
] | false | 0.088423 | 0.037555 | 2.354487 | [
"s520654678",
"s918478565"
] |
u707808519 | p02601 | python | s041230857 | s249940177 | 37 | 29 | 9,108 | 9,144 | Accepted | Accepted | 21.62 | a, b, c = list(map(int, input().split()))
K = int(eval(input()))
while K > 0:
if a >= b:
b *= 2
elif b >= c:
c *= 2
K -= 1
if a < b < c:
print('Yes')
else:
print('No') | A, B, C = list(map(int, input().split()))
K = int(eval(input()))
ans = 0
while B <= A:
B *= 2
ans += 1
while C <= B:
C *= 2
ans += 1
if ans <= K:
print('Yes')
else:
print('No') | 14 | 14 | 207 | 202 | a, b, c = list(map(int, input().split()))
K = int(eval(input()))
while K > 0:
if a >= b:
b *= 2
elif b >= c:
c *= 2
K -= 1
if a < b < c:
print("Yes")
else:
print("No")
| A, B, C = list(map(int, input().split()))
K = int(eval(input()))
ans = 0
while B <= A:
B *= 2
ans += 1
while C <= B:
C *= 2
ans += 1
if ans <= K:
print("Yes")
else:
print("No")
| false | 0 | [
"-a, b, c = list(map(int, input().split()))",
"+A, B, C = list(map(int, input().split()))",
"-while K > 0:",
"- if a >= b:",
"- b *= 2",
"- elif b >= c:",
"- c *= 2",
"- K -= 1",
"-if a < b < c:",
"+ans = 0",
"+while B <= A:",
"+ B *= 2",
"+ ans += 1",
"+while C <= B:",
"+ C *= 2",
"+ ans += 1",
"+if ans <= K:"
] | false | 0.058368 | 0.088308 | 0.660962 | [
"s041230857",
"s249940177"
] |
u604774382 | p02407 | python | s876044985 | s030178445 | 30 | 20 | 6,728 | 4,192 | Accepted | Accepted | 33.33 | import sys
n = int( sys.stdin.readline() )
nums = sys.stdin.readline().rstrip().split( " " )
nums.reverse()
output = []
for i in range( n ):
output.append( nums[i] )
if i < (n-1):
output.append( " " )
print(( "".join( output ) )) | import sys
n = int( sys.stdin.readline() )
nums = sys.stdin.readline().rstrip().split( " " )
nums.reverse()
print(( " ".join( nums ) )) | 11 | 6 | 242 | 139 | import sys
n = int(sys.stdin.readline())
nums = sys.stdin.readline().rstrip().split(" ")
nums.reverse()
output = []
for i in range(n):
output.append(nums[i])
if i < (n - 1):
output.append(" ")
print(("".join(output)))
| import sys
n = int(sys.stdin.readline())
nums = sys.stdin.readline().rstrip().split(" ")
nums.reverse()
print((" ".join(nums)))
| false | 45.454545 | [
"-output = []",
"-for i in range(n):",
"- output.append(nums[i])",
"- if i < (n - 1):",
"- output.append(\" \")",
"-print((\"\".join(output)))",
"+print((\" \".join(nums)))"
] | false | 0.033374 | 0.035595 | 0.937604 | [
"s876044985",
"s030178445"
] |
u707614029 | p02812 | python | s579984542 | s574369008 | 27 | 23 | 9,048 | 8,960 | Accepted | Accepted | 14.81 | n = int(eval(input()))
s = eval(input())
cnt = 0
for i in range(n-2):
if s[i:i+3] == 'ABC':
cnt += 1
print(cnt)
| _ = eval(input())
print((input().count('ABC')))
| 7 | 2 | 118 | 41 | n = int(eval(input()))
s = eval(input())
cnt = 0
for i in range(n - 2):
if s[i : i + 3] == "ABC":
cnt += 1
print(cnt)
| _ = eval(input())
print((input().count("ABC")))
| false | 71.428571 | [
"-n = int(eval(input()))",
"-s = eval(input())",
"-cnt = 0",
"-for i in range(n - 2):",
"- if s[i : i + 3] == \"ABC\":",
"- cnt += 1",
"-print(cnt)",
"+_ = eval(input())",
"+print((input().count(\"ABC\")))"
] | false | 0.066876 | 0.066994 | 0.99824 | [
"s579984542",
"s574369008"
] |
u678167152 | p02788 | python | s625853956 | s715671080 | 1,603 | 1,256 | 75,992 | 109,500 | Accepted | Accepted | 21.65 | N, D, A = list(map(int, input().split()))
Monster = [0]*N
for i in range(N):
Monster[i] = list(map(int, input().split()))
Monster.sort(key=lambda x:x[0])
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from collections import deque
d = deque()
damage = 0
ans = 0
for i in range(N):
while len(d)>0:
a = d.popleft()
if a[0]==i:
damage -= a[1]
else:
d.appendleft(a)
break
Monster[i][1] -= damage
count = -(-max(Monster[i][1],0)//A)
ans += count
right = Monster[i][0]+2*D
ind = bisect(Monster,[right,10**9+1])
damage += A*count
d.append([ind,A*count])
print(ans) | from bisect import *
def solve():
ans = 0
N, D, A = list(map(int, input().split()))
B = [list(map(int, input().split())) for _ in range(N)]
B.sort()
lasts = [0]*(N+1)
now = 0
for i,((x,h),l) in enumerate(zip(B,lasts)):
now -= l
atack = max(0,-(-(h-now)//A))
ans += atack
damage = atack*A
now += damage
last = x+2*D
ind = bisect_right(B,[last+1,0])
lasts[ind] += damage
return ans
print((solve())) | 31 | 19 | 723 | 454 | N, D, A = list(map(int, input().split()))
Monster = [0] * N
for i in range(N):
Monster[i] = list(map(int, input().split()))
Monster.sort(key=lambda x: x[0])
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from collections import deque
d = deque()
damage = 0
ans = 0
for i in range(N):
while len(d) > 0:
a = d.popleft()
if a[0] == i:
damage -= a[1]
else:
d.appendleft(a)
break
Monster[i][1] -= damage
count = -(-max(Monster[i][1], 0) // A)
ans += count
right = Monster[i][0] + 2 * D
ind = bisect(Monster, [right, 10**9 + 1])
damage += A * count
d.append([ind, A * count])
print(ans)
| from bisect import *
def solve():
ans = 0
N, D, A = list(map(int, input().split()))
B = [list(map(int, input().split())) for _ in range(N)]
B.sort()
lasts = [0] * (N + 1)
now = 0
for i, ((x, h), l) in enumerate(zip(B, lasts)):
now -= l
atack = max(0, -(-(h - now) // A))
ans += atack
damage = atack * A
now += damage
last = x + 2 * D
ind = bisect_right(B, [last + 1, 0])
lasts[ind] += damage
return ans
print((solve()))
| false | 38.709677 | [
"-N, D, A = list(map(int, input().split()))",
"-Monster = [0] * N",
"-for i in range(N):",
"- Monster[i] = list(map(int, input().split()))",
"-Monster.sort(key=lambda x: x[0])",
"-from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort",
"-from collections import deque",
"+from bisect import *",
"-d = deque()",
"-damage = 0",
"-ans = 0",
"-for i in range(N):",
"- while len(d) > 0:",
"- a = d.popleft()",
"- if a[0] == i:",
"- damage -= a[1]",
"- else:",
"- d.appendleft(a)",
"- break",
"- Monster[i][1] -= damage",
"- count = -(-max(Monster[i][1], 0) // A)",
"- ans += count",
"- right = Monster[i][0] + 2 * D",
"- ind = bisect(Monster, [right, 10**9 + 1])",
"- damage += A * count",
"- d.append([ind, A * count])",
"-print(ans)",
"+",
"+def solve():",
"+ ans = 0",
"+ N, D, A = list(map(int, input().split()))",
"+ B = [list(map(int, input().split())) for _ in range(N)]",
"+ B.sort()",
"+ lasts = [0] * (N + 1)",
"+ now = 0",
"+ for i, ((x, h), l) in enumerate(zip(B, lasts)):",
"+ now -= l",
"+ atack = max(0, -(-(h - now) // A))",
"+ ans += atack",
"+ damage = atack * A",
"+ now += damage",
"+ last = x + 2 * D",
"+ ind = bisect_right(B, [last + 1, 0])",
"+ lasts[ind] += damage",
"+ return ans",
"+",
"+",
"+print((solve()))"
] | false | 0.107768 | 0.044577 | 2.417577 | [
"s625853956",
"s715671080"
] |
u554198876 | p02412 | python | s663255493 | s799019147 | 800 | 50 | 7,744 | 7,712 | Accepted | Accepted | 93.75 | from itertools import combinations
while True:
n, x = [int(i) for i in input().split()]
if n == x == 0: break
count = 0
array = set(range(1, n+1))
for ele in combinations(array, 3):
if sum(ele) == x:
count += 1
print(count) | while True:
n,x = [int(i) for i in input().split()]
if n == 0 and x == 0: break
count = 0
# 3????????°?????????????°????x//3?????????x//3 * 3 == x ?????????????°????x//3??\?????§?????????????????????
for a in range(1, x//3):
# 3????????°?????????????????????x//2?????????x//2 * 2 == x ?????????????????????x//2??\?????§?????????????????????
for b in range(a+1,x//2):
c = x - (a + b)
if b < c <= n:
count += 1
print(count) | 10 | 12 | 277 | 512 | from itertools import combinations
while True:
n, x = [int(i) for i in input().split()]
if n == x == 0:
break
count = 0
array = set(range(1, n + 1))
for ele in combinations(array, 3):
if sum(ele) == x:
count += 1
print(count)
| while True:
n, x = [int(i) for i in input().split()]
if n == 0 and x == 0:
break
count = 0
# 3????????°?????????????°????x//3?????????x//3 * 3 == x ?????????????°????x//3??\?????§?????????????????????
for a in range(1, x // 3):
# 3????????°?????????????????????x//2?????????x//2 * 2 == x ?????????????????????x//2??\?????§?????????????????????
for b in range(a + 1, x // 2):
c = x - (a + b)
if b < c <= n:
count += 1
print(count)
| false | 16.666667 | [
"-from itertools import combinations",
"-",
"- if n == x == 0:",
"+ if n == 0 and x == 0:",
"- array = set(range(1, n + 1))",
"- for ele in combinations(array, 3):",
"- if sum(ele) == x:",
"- count += 1",
"+ # 3????????°?????????????°????x//3?????????x//3 * 3 == x ?????????????°????x//3??\\?????§?????????????????????",
"+ for a in range(1, x // 3):",
"+ # 3????????°?????????????????????x//2?????????x//2 * 2 == x ?????????????????????x//2??\\?????§?????????????????????",
"+ for b in range(a + 1, x // 2):",
"+ c = x - (a + b)",
"+ if b < c <= n:",
"+ count += 1"
] | false | 0.040961 | 0.036946 | 1.10867 | [
"s663255493",
"s799019147"
] |
u940102677 | p02898 | python | s772167013 | s332138822 | 485 | 52 | 20,988 | 11,916 | Accepted | Accepted | 89.28 | import numpy as np
n,k = list(map(int,input().split()))
h = np.array(list(map(int,input().split())))
print((sum(h >= k))) | n,k = list(map(int,input().split()))
h = list(map(int,input().split()))
c = 0
for x in h:
c += (x >= k)
print(c) | 4 | 6 | 116 | 113 | import numpy as np
n, k = list(map(int, input().split()))
h = np.array(list(map(int, input().split())))
print((sum(h >= k)))
| n, k = list(map(int, input().split()))
h = list(map(int, input().split()))
c = 0
for x in h:
c += x >= k
print(c)
| false | 33.333333 | [
"-import numpy as np",
"-",
"-h = np.array(list(map(int, input().split())))",
"-print((sum(h >= k)))",
"+h = list(map(int, input().split()))",
"+c = 0",
"+for x in h:",
"+ c += x >= k",
"+print(c)"
] | false | 0.700624 | 0.045101 | 15.534615 | [
"s772167013",
"s332138822"
] |
u509392332 | p02753 | python | s778364791 | s936516831 | 19 | 17 | 2,940 | 2,940 | Accepted | Accepted | 10.53 | S = list(i for i in eval(input()))
if 'A' in S and 'B' in S:
print('Yes')
else:
print('No') | S = eval(input())
S_list = [i for i in S]
S_set = set(S_list)
if len(S_set) == 2:
print('Yes')
else:
print('No') | 6 | 9 | 95 | 120 | S = list(i for i in eval(input()))
if "A" in S and "B" in S:
print("Yes")
else:
print("No")
| S = eval(input())
S_list = [i for i in S]
S_set = set(S_list)
if len(S_set) == 2:
print("Yes")
else:
print("No")
| false | 33.333333 | [
"-S = list(i for i in eval(input()))",
"-if \"A\" in S and \"B\" in S:",
"+S = eval(input())",
"+S_list = [i for i in S]",
"+S_set = set(S_list)",
"+if len(S_set) == 2:"
] | false | 0.042676 | 0.04364 | 0.977908 | [
"s778364791",
"s936516831"
] |
u729133443 | p02790 | python | s687644352 | s954955187 | 165 | 17 | 38,256 | 2,940 | Accepted | Accepted | 89.7 | a,b=input().split()
print((min(a*int(b),b*int(a)))) | _,a,b=sorted(eval(input()));print((a*int(b))) | 2 | 1 | 50 | 37 | a, b = input().split()
print((min(a * int(b), b * int(a))))
| _, a, b = sorted(eval(input()))
print((a * int(b)))
| false | 50 | [
"-a, b = input().split()",
"-print((min(a * int(b), b * int(a))))",
"+_, a, b = sorted(eval(input()))",
"+print((a * int(b)))"
] | false | 0.071228 | 0.038296 | 1.859943 | [
"s687644352",
"s954955187"
] |
u953237709 | p03061 | python | s879185532 | s222313784 | 258 | 211 | 63,856 | 14,076 | Accepted | Accepted | 18.22 | def gcd(x, y):
while (y):
x, y = y, x % y
return x
n = int(eval(input()))
a = list(map(int, input().split()))
fromLeft = [0] * n
fromLeft[0] = a[0]
fromRight = [0] * n
fromRight[0] = a[n - 1]
for i in range(1, n):
fromLeft[i] = gcd(fromLeft[i - 1], a[i])
fromRight[i] = gcd(fromRight[i - 1], a[n - i - 1])
ret = fromLeft[n - 1]
for i in range(n):
if i == 0:
curGcd = fromRight[n - 2]
elif i == n - 1:
curGcd = fromLeft[n - 2]
else:
curGcd = gcd(fromLeft[i - 1], fromRight[n - i - 2])
ret = max(ret, curGcd)
print(ret) | n = int(eval(input()))
a = list(map(int, input().split()))
def gcd(a, b):
while b:
a, b = b, a % b
return a
fromLeft = [a[0]] + [None] * (n - 1)
for i in range(1, n):
fromLeft[i] = gcd(fromLeft[i - 1], a[i])
fromRight = [None] * (n - 1) + [a[-1]]
for i in range(n - 2, -1, -1):
fromRight[i] = gcd(fromRight[i + 1], a[i])
ret = 1
for repr in range(n):
if repr == 0:
curGcd = fromRight[repr + 1]
elif repr == n - 1:
curGcd = fromLeft[repr - 1]
else:
curGcd = gcd(fromLeft[repr - 1], fromRight[repr + 1])
ret = max(ret, curGcd)
print(ret)
| 24 | 24 | 599 | 619 | def gcd(x, y):
while y:
x, y = y, x % y
return x
n = int(eval(input()))
a = list(map(int, input().split()))
fromLeft = [0] * n
fromLeft[0] = a[0]
fromRight = [0] * n
fromRight[0] = a[n - 1]
for i in range(1, n):
fromLeft[i] = gcd(fromLeft[i - 1], a[i])
fromRight[i] = gcd(fromRight[i - 1], a[n - i - 1])
ret = fromLeft[n - 1]
for i in range(n):
if i == 0:
curGcd = fromRight[n - 2]
elif i == n - 1:
curGcd = fromLeft[n - 2]
else:
curGcd = gcd(fromLeft[i - 1], fromRight[n - i - 2])
ret = max(ret, curGcd)
print(ret)
| n = int(eval(input()))
a = list(map(int, input().split()))
def gcd(a, b):
while b:
a, b = b, a % b
return a
fromLeft = [a[0]] + [None] * (n - 1)
for i in range(1, n):
fromLeft[i] = gcd(fromLeft[i - 1], a[i])
fromRight = [None] * (n - 1) + [a[-1]]
for i in range(n - 2, -1, -1):
fromRight[i] = gcd(fromRight[i + 1], a[i])
ret = 1
for repr in range(n):
if repr == 0:
curGcd = fromRight[repr + 1]
elif repr == n - 1:
curGcd = fromLeft[repr - 1]
else:
curGcd = gcd(fromLeft[repr - 1], fromRight[repr + 1])
ret = max(ret, curGcd)
print(ret)
| false | 0 | [
"-def gcd(x, y):",
"- while y:",
"- x, y = y, x % y",
"- return x",
"+n = int(eval(input()))",
"+a = list(map(int, input().split()))",
"-n = int(eval(input()))",
"-a = list(map(int, input().split()))",
"-fromLeft = [0] * n",
"-fromLeft[0] = a[0]",
"-fromRight = [0] * n",
"-fromRight[0] = a[n - 1]",
"+def gcd(a, b):",
"+ while b:",
"+ a, b = b, a % b",
"+ return a",
"+",
"+",
"+fromLeft = [a[0]] + [None] * (n - 1)",
"- fromRight[i] = gcd(fromRight[i - 1], a[n - i - 1])",
"-ret = fromLeft[n - 1]",
"-for i in range(n):",
"- if i == 0:",
"- curGcd = fromRight[n - 2]",
"- elif i == n - 1:",
"- curGcd = fromLeft[n - 2]",
"+fromRight = [None] * (n - 1) + [a[-1]]",
"+for i in range(n - 2, -1, -1):",
"+ fromRight[i] = gcd(fromRight[i + 1], a[i])",
"+ret = 1",
"+for repr in range(n):",
"+ if repr == 0:",
"+ curGcd = fromRight[repr + 1]",
"+ elif repr == n - 1:",
"+ curGcd = fromLeft[repr - 1]",
"- curGcd = gcd(fromLeft[i - 1], fromRight[n - i - 2])",
"+ curGcd = gcd(fromLeft[repr - 1], fromRight[repr + 1])"
] | false | 0.135425 | 0.105349 | 1.285494 | [
"s879185532",
"s222313784"
] |
u917382715 | p03478 | python | s809945585 | s134150711 | 37 | 30 | 3,060 | 3,060 | Accepted | Accepted | 18.92 | n, a, b = list(map(int, input().split()))
ans = 0
for i in range(n+1):
if a <= sum(list(map(int, list(str(i))))) <= b:
ans += i
print(ans)
| n, a, b = list(map(int, input().split()))
sum = 0
for i in range(n + 1):
sum2 = 0
j = i
while j != 0:
sum2 += j % 10
j = j // 10
if sum2 >= a and sum2 <= b:
sum += i
print(sum) | 6 | 13 | 150 | 224 | n, a, b = list(map(int, input().split()))
ans = 0
for i in range(n + 1):
if a <= sum(list(map(int, list(str(i))))) <= b:
ans += i
print(ans)
| n, a, b = list(map(int, input().split()))
sum = 0
for i in range(n + 1):
sum2 = 0
j = i
while j != 0:
sum2 += j % 10
j = j // 10
if sum2 >= a and sum2 <= b:
sum += i
print(sum)
| false | 53.846154 | [
"-ans = 0",
"+sum = 0",
"- if a <= sum(list(map(int, list(str(i))))) <= b:",
"- ans += i",
"-print(ans)",
"+ sum2 = 0",
"+ j = i",
"+ while j != 0:",
"+ sum2 += j % 10",
"+ j = j // 10",
"+ if sum2 >= a and sum2 <= b:",
"+ sum += i",
"+print(sum)"
] | false | 0.059622 | 0.055715 | 1.070113 | [
"s809945585",
"s134150711"
] |
u912237403 | p02397 | python | s890819444 | s350862140 | 30 | 20 | 4,236 | 4,204 | Accepted | Accepted | 33.33 | import sys
for line in sys.stdin:
a,b = line.split()
a,b = int(a),int(b)
if a == 0 and b == 0: break
if b<a: a,b = b,a
print('%d %d' %(a, b)) | while True:
a, b = sorted(map(int, input().split()))
if (a, b) == (0, 0): break
print(a, b) | 7 | 4 | 166 | 109 | import sys
for line in sys.stdin:
a, b = line.split()
a, b = int(a), int(b)
if a == 0 and b == 0:
break
if b < a:
a, b = b, a
print("%d %d" % (a, b))
| while True:
a, b = sorted(map(int, input().split()))
if (a, b) == (0, 0):
break
print(a, b)
| false | 42.857143 | [
"-import sys",
"-",
"-for line in sys.stdin:",
"- a, b = line.split()",
"- a, b = int(a), int(b)",
"- if a == 0 and b == 0:",
"+while True:",
"+ a, b = sorted(map(int, input().split()))",
"+ if (a, b) == (0, 0):",
"- if b < a:",
"- a, b = b, a",
"- print(\"%d %d\" % (a, b))",
"+ print(a, b)"
] | false | 0.050849 | 0.066341 | 0.766476 | [
"s890819444",
"s350862140"
] |
u934442292 | p03048 | python | s186320530 | s314686202 | 881 | 18 | 2,940 | 3,060 | Accepted | Accepted | 97.96 | import sys
input = sys.stdin.readline
def main():
R, G, B, N = list(map(int, input().split()))
ans = 0
for r in range(N // R + 1):
gGbB = N - r * R
for g in range(gGbB // G + 1):
bB = gGbB - g * G
if bB % B == 0:
ans += 1
print(ans)
if __name__ == "__main__":
main()
| import sys
input = sys.stdin.readline
def main():
R, G, B, N = list(map(int, input().split()))
dp = [0] * (N + 1)
dp[0] = 1
for c in [R, G, B]:
for i in range(N - c + 1):
dp[i + c] += dp[i]
ans = dp[N]
print(ans)
if __name__ == "__main__":
main()
| 21 | 20 | 368 | 315 | import sys
input = sys.stdin.readline
def main():
R, G, B, N = list(map(int, input().split()))
ans = 0
for r in range(N // R + 1):
gGbB = N - r * R
for g in range(gGbB // G + 1):
bB = gGbB - g * G
if bB % B == 0:
ans += 1
print(ans)
if __name__ == "__main__":
main()
| import sys
input = sys.stdin.readline
def main():
R, G, B, N = list(map(int, input().split()))
dp = [0] * (N + 1)
dp[0] = 1
for c in [R, G, B]:
for i in range(N - c + 1):
dp[i + c] += dp[i]
ans = dp[N]
print(ans)
if __name__ == "__main__":
main()
| false | 4.761905 | [
"- ans = 0",
"- for r in range(N // R + 1):",
"- gGbB = N - r * R",
"- for g in range(gGbB // G + 1):",
"- bB = gGbB - g * G",
"- if bB % B == 0:",
"- ans += 1",
"+ dp = [0] * (N + 1)",
"+ dp[0] = 1",
"+ for c in [R, G, B]:",
"+ for i in range(N - c + 1):",
"+ dp[i + c] += dp[i]",
"+ ans = dp[N]"
] | false | 0.15004 | 0.042162 | 3.558658 | [
"s186320530",
"s314686202"
] |
u506858457 | p03162 | python | s111036507 | s021944283 | 1,226 | 1,056 | 47,636 | 47,344 | Accepted | Accepted | 13.87 | N=int(eval(input()))
L = [list(map(int, input().split())) for i in range(N)]
dp=[[0 for j in range(3)] for i in range(N)]
ans=0
for i in range(N):
for P in range(3):
for PY in range(3):
if P==PY:
continue
elif i==0:
dp[i][P]=L[i][P]
ans=max(ans,dp[i][P])
else:
dp[i][P]=max(dp[i][P],dp[i-1][PY]+L[i][P])
ans=max(ans,dp[i][P])
'''
for i in range(3):
ans=max(ans,dp[N-1][i])
'''
print(ans)
| N=int(eval(input()))
L = [list(map(int, input().split())) for i in range(N)]
dp=[[0 for j in range(3)] for i in range(N)]
for i in range(N):
for P in range(3):
for PY in range(3):
if P==PY:
continue
elif i==0:
dp[i][P]=L[i][P]
else:
dp[i][P]=max(dp[i][P],dp[i-1][PY]+L[i][P])
ans=0
for i in range(3):
ans=max(ans,dp[N-1][i])
print(ans) | 21 | 17 | 470 | 396 | N = int(eval(input()))
L = [list(map(int, input().split())) for i in range(N)]
dp = [[0 for j in range(3)] for i in range(N)]
ans = 0
for i in range(N):
for P in range(3):
for PY in range(3):
if P == PY:
continue
elif i == 0:
dp[i][P] = L[i][P]
ans = max(ans, dp[i][P])
else:
dp[i][P] = max(dp[i][P], dp[i - 1][PY] + L[i][P])
ans = max(ans, dp[i][P])
"""
for i in range(3):
ans=max(ans,dp[N-1][i])
"""
print(ans)
| N = int(eval(input()))
L = [list(map(int, input().split())) for i in range(N)]
dp = [[0 for j in range(3)] for i in range(N)]
for i in range(N):
for P in range(3):
for PY in range(3):
if P == PY:
continue
elif i == 0:
dp[i][P] = L[i][P]
else:
dp[i][P] = max(dp[i][P], dp[i - 1][PY] + L[i][P])
ans = 0
for i in range(3):
ans = max(ans, dp[N - 1][i])
print(ans)
| false | 19.047619 | [
"-ans = 0",
"- ans = max(ans, dp[i][P])",
"- ans = max(ans, dp[i][P])",
"-\"\"\"",
"+ans = 0",
"- ans=max(ans,dp[N-1][i])",
"-\"\"\"",
"+ ans = max(ans, dp[N - 1][i])"
] | false | 0.033166 | 0.042301 | 0.784064 | [
"s111036507",
"s021944283"
] |
u640319601 | p03240 | python | s737036875 | s818759352 | 405 | 33 | 3,064 | 3,064 | Accepted | Accepted | 91.85 | N = int(eval(input()))
l = [list(map(int, input().split())) for _ in range(N)]
for x, y, h in l:
if h == 0:
continue
for Cx in range(0, 101):
for Cy in range(0, 101):
H = abs(Cx-x) + abs(Cy-y) + h
if all([hh == max(H - abs(Cx-xx) - abs(Cy-yy), 0) for xx, yy, hh in l]):
print((Cx, Cy, H))
exit() | N = int(eval(input()))
l = [list(map(int, input().split())) for _ in range(N)]
for x, y, h in l:
if h == 0:
continue
for Cx in range(0, 101):
for Cy in range(0, 101):
H = abs(Cx-x) + abs(Cy-y) + h
if all(hh == max(H - abs(Cx-xx) - abs(Cy-yy), 0) for xx, yy, hh in l):
print((Cx, Cy, H))
exit()
| 12 | 13 | 379 | 395 | N = int(eval(input()))
l = [list(map(int, input().split())) for _ in range(N)]
for x, y, h in l:
if h == 0:
continue
for Cx in range(0, 101):
for Cy in range(0, 101):
H = abs(Cx - x) + abs(Cy - y) + h
if all([hh == max(H - abs(Cx - xx) - abs(Cy - yy), 0) for xx, yy, hh in l]):
print((Cx, Cy, H))
exit()
| N = int(eval(input()))
l = [list(map(int, input().split())) for _ in range(N)]
for x, y, h in l:
if h == 0:
continue
for Cx in range(0, 101):
for Cy in range(0, 101):
H = abs(Cx - x) + abs(Cy - y) + h
if all(hh == max(H - abs(Cx - xx) - abs(Cy - yy), 0) for xx, yy, hh in l):
print((Cx, Cy, H))
exit()
| false | 7.692308 | [
"- if all([hh == max(H - abs(Cx - xx) - abs(Cy - yy), 0) for xx, yy, hh in l]):",
"+ if all(hh == max(H - abs(Cx - xx) - abs(Cy - yy), 0) for xx, yy, hh in l):"
] | false | 0.048721 | 0.038682 | 1.259532 | [
"s737036875",
"s818759352"
] |
u392319141 | p03557 | python | s881859193 | s161453214 | 439 | 350 | 40,876 | 22,968 | Accepted | Accepted | 20.27 | from bisect import bisect_left
from collections import defaultdict
N = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
B.sort()
AB = defaultdict(int)
for b in B:
AB[b] = bisect_left(A, b)
sumAB = defaultdict(int)
sumAB[0] = 0
s = 0
for b in B:
s += AB[b]
sumAB[b] = s
B.insert(0, 0)
ans = 0
for c in C:
r = bisect_left(B, c)
ans += sumAB[B[r - 1]]
print(ans) | import sys
import heapq
from operator import itemgetter
from collections import deque, defaultdict, Counter
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
MOD = 10**9 + 7
INF = float('inf')
def sol():
N = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
C.sort()
ans = 0
for b in B:
a = bisect_left(A, b)
c = bisect_right(C, b)
ans += a * (N - c)
print(ans)
sol() | 30 | 28 | 496 | 592 | from bisect import bisect_left
from collections import defaultdict
N = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
B.sort()
AB = defaultdict(int)
for b in B:
AB[b] = bisect_left(A, b)
sumAB = defaultdict(int)
sumAB[0] = 0
s = 0
for b in B:
s += AB[b]
sumAB[b] = s
B.insert(0, 0)
ans = 0
for c in C:
r = bisect_left(B, c)
ans += sumAB[B[r - 1]]
print(ans)
| import sys
import heapq
from operator import itemgetter
from collections import deque, defaultdict, Counter
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
MOD = 10**9 + 7
INF = float("inf")
def sol():
N = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
C.sort()
ans = 0
for b in B:
a = bisect_left(A, b)
c = bisect_right(C, b)
ans += a * (N - c)
print(ans)
sol()
| false | 6.666667 | [
"-from bisect import bisect_left",
"-from collections import defaultdict",
"+import sys",
"+import heapq",
"+from operator import itemgetter",
"+from collections import deque, defaultdict, Counter",
"+from bisect import bisect_left, bisect_right",
"-N = int(eval(input()))",
"-A = list(map(int, input().split()))",
"-B = list(map(int, input().split()))",
"-C = list(map(int, input().split()))",
"-A.sort()",
"-B.sort()",
"-AB = defaultdict(int)",
"-for b in B:",
"- AB[b] = bisect_left(A, b)",
"-sumAB = defaultdict(int)",
"-sumAB[0] = 0",
"-s = 0",
"-for b in B:",
"- s += AB[b]",
"- sumAB[b] = s",
"-B.insert(0, 0)",
"-ans = 0",
"-for c in C:",
"- r = bisect_left(B, c)",
"- ans += sumAB[B[r - 1]]",
"-print(ans)",
"+input = sys.stdin.readline",
"+sys.setrecursionlimit(10**7)",
"+MOD = 10**9 + 7",
"+INF = float(\"inf\")",
"+",
"+",
"+def sol():",
"+ N = int(eval(input()))",
"+ A = list(map(int, input().split()))",
"+ B = list(map(int, input().split()))",
"+ C = list(map(int, input().split()))",
"+ A.sort()",
"+ C.sort()",
"+ ans = 0",
"+ for b in B:",
"+ a = bisect_left(A, b)",
"+ c = bisect_right(C, b)",
"+ ans += a * (N - c)",
"+ print(ans)",
"+",
"+",
"+sol()"
] | false | 0.045244 | 0.126761 | 0.35692 | [
"s881859193",
"s161453214"
] |
u022407960 | p02366 | python | s229192755 | s805095937 | 180 | 160 | 23,568 | 23,608 | Accepted | Accepted | 11.11 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
input:
5 4
0 1
1 2
2 3
3 4
output:
1
2
3
"""
import sys
sys.setrecursionlimit(int(3e6))
UNVISITED, VISITED_IN_STACK, POPPED_OUT = 0, 1, 2
def generate_adj_table(_v_info):
for v_detail in _v_info:
v_from, v_to = map(int, v_detail)
init_adj_table[v_from].append(v_to)
# undirected graph
init_adj_table[v_to].append(v_from)
return init_adj_table
def graph_dfs(current, prev):
global timer
pre_v[current] = lowest_v[current] = timer
timer += 1
color[current] = VISITED_IN_STACK
for adj in adj_table[current]:
if color[adj] is UNVISITED:
parent_v[adj] = current
# recursive dfs
graph_dfs(adj, current)
lowest_v[current] = min(lowest_v[current], lowest_v[adj])
elif adj is not prev:
lowest_v[current] = min(lowest_v[current], pre_v[adj])
return None
def art_points():
graph_dfs(dfs_root, -1)
np = 0
for v in range(1, vertices):
parent = parent_v[v]
if parent is dfs_root:
np += 1
elif pre_v[parent] <= lowest_v[v]:
art_set.add(parent)
if np > 1:
art_set.add(dfs_root)
return art_set
if __name__ == '__main__':
_input = sys.stdin.readlines()
vertices, edges = map(int, _input[0].split())
v_info = map(lambda x: x.split(), _input[1:])
pre_v, parent_v, lowest_v = ([float('inf')] * vertices for _ in range(3))
init_adj_table = tuple([] for _ in range(vertices))
timer = 1
# root
dfs_root = 0
art_set = set()
color = [UNVISITED] * vertices
adj_table = generate_adj_table(v_info)
res = art_points()
# print('parent', parent_v, 'preorder', pre_v, 'postorder', lowest_v)
if not res:
pass
else:
print(*sorted(res), sep='\n')
| #!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
input:
5 4
0 1
1 2
2 3
3 4
output:
1
2
3
"""
import sys
sys.setrecursionlimit(int(3e6))
UNVISITED, VISITED_IN_STACK, POPPED_OUT = 0, 1, 2
def generate_adj_table(_v_info):
for v_detail in _v_info:
v_from, v_to = map(int, v_detail)
init_adj_table[v_from].append(v_to)
# undirected graph
init_adj_table[v_to].append(v_from)
return init_adj_table
def graph_dfs(current, prev):
global timer
pre_v[current] = lowest_v[current] = timer
timer += 1
color[current] = VISITED_IN_STACK
for adj in adj_table[current]:
if color[adj] is UNVISITED:
parent_v[adj] = current
# recursive dfs
graph_dfs(adj, current)
lowest_v[current] = min(lowest_v[current], lowest_v[adj])
elif adj is not prev:
lowest_v[current] = min(lowest_v[current], pre_v[adj])
return None
def art_points():
graph_dfs(dfs_root, -1)
np = 0
for v in range(1, vertices):
parent = parent_v[v]
if parent is dfs_root:
np += 1
elif pre_v[parent] <= lowest_v[v]:
art_set.add(parent)
if np > 1:
art_set.add(dfs_root)
return art_set
if __name__ == '__main__':
_input = sys.stdin.readlines()
vertices, edges = map(int, _input[0].split())
v_info = map(lambda x: x.split(), _input[1:])
pre_v, parent_v, lowest_v = ([float('inf')] * vertices for _ in range(3))
init_adj_table = tuple([] for _ in range(vertices))
timer = 0
# root
dfs_root = 0
art_set = set()
color = [UNVISITED] * vertices
adj_table = generate_adj_table(v_info)
res = art_points()
# print('parent', parent_v, 'preorder', pre_v, 'postorder', lowest_v)
if res:
print(*sorted(res), sep='\n')
| 90 | 88 | 1,963 | 1,934 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
input:
5 4
0 1
1 2
2 3
3 4
output:
1
2
3
"""
import sys
sys.setrecursionlimit(int(3e6))
UNVISITED, VISITED_IN_STACK, POPPED_OUT = 0, 1, 2
def generate_adj_table(_v_info):
for v_detail in _v_info:
v_from, v_to = map(int, v_detail)
init_adj_table[v_from].append(v_to)
# undirected graph
init_adj_table[v_to].append(v_from)
return init_adj_table
def graph_dfs(current, prev):
global timer
pre_v[current] = lowest_v[current] = timer
timer += 1
color[current] = VISITED_IN_STACK
for adj in adj_table[current]:
if color[adj] is UNVISITED:
parent_v[adj] = current
# recursive dfs
graph_dfs(adj, current)
lowest_v[current] = min(lowest_v[current], lowest_v[adj])
elif adj is not prev:
lowest_v[current] = min(lowest_v[current], pre_v[adj])
return None
def art_points():
graph_dfs(dfs_root, -1)
np = 0
for v in range(1, vertices):
parent = parent_v[v]
if parent is dfs_root:
np += 1
elif pre_v[parent] <= lowest_v[v]:
art_set.add(parent)
if np > 1:
art_set.add(dfs_root)
return art_set
if __name__ == "__main__":
_input = sys.stdin.readlines()
vertices, edges = map(int, _input[0].split())
v_info = map(lambda x: x.split(), _input[1:])
pre_v, parent_v, lowest_v = ([float("inf")] * vertices for _ in range(3))
init_adj_table = tuple([] for _ in range(vertices))
timer = 1
# root
dfs_root = 0
art_set = set()
color = [UNVISITED] * vertices
adj_table = generate_adj_table(v_info)
res = art_points()
# print('parent', parent_v, 'preorder', pre_v, 'postorder', lowest_v)
if not res:
pass
else:
print(*sorted(res), sep="\n")
| #!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
input:
5 4
0 1
1 2
2 3
3 4
output:
1
2
3
"""
import sys
sys.setrecursionlimit(int(3e6))
UNVISITED, VISITED_IN_STACK, POPPED_OUT = 0, 1, 2
def generate_adj_table(_v_info):
for v_detail in _v_info:
v_from, v_to = map(int, v_detail)
init_adj_table[v_from].append(v_to)
# undirected graph
init_adj_table[v_to].append(v_from)
return init_adj_table
def graph_dfs(current, prev):
global timer
pre_v[current] = lowest_v[current] = timer
timer += 1
color[current] = VISITED_IN_STACK
for adj in adj_table[current]:
if color[adj] is UNVISITED:
parent_v[adj] = current
# recursive dfs
graph_dfs(adj, current)
lowest_v[current] = min(lowest_v[current], lowest_v[adj])
elif adj is not prev:
lowest_v[current] = min(lowest_v[current], pre_v[adj])
return None
def art_points():
graph_dfs(dfs_root, -1)
np = 0
for v in range(1, vertices):
parent = parent_v[v]
if parent is dfs_root:
np += 1
elif pre_v[parent] <= lowest_v[v]:
art_set.add(parent)
if np > 1:
art_set.add(dfs_root)
return art_set
if __name__ == "__main__":
_input = sys.stdin.readlines()
vertices, edges = map(int, _input[0].split())
v_info = map(lambda x: x.split(), _input[1:])
pre_v, parent_v, lowest_v = ([float("inf")] * vertices for _ in range(3))
init_adj_table = tuple([] for _ in range(vertices))
timer = 0
# root
dfs_root = 0
art_set = set()
color = [UNVISITED] * vertices
adj_table = generate_adj_table(v_info)
res = art_points()
# print('parent', parent_v, 'preorder', pre_v, 'postorder', lowest_v)
if res:
print(*sorted(res), sep="\n")
| false | 2.222222 | [
"- timer = 1",
"+ timer = 0",
"- if not res:",
"- pass",
"- else:",
"+ if res:"
] | false | 0.046888 | 0.049632 | 0.944722 | [
"s229192755",
"s805095937"
] |
u102461423 | p03375 | python | s442383407 | s220053232 | 1,312 | 975 | 223,556 | 293,928 | Accepted | Accepted | 25.69 | import sys
input = sys.stdin.readline
import numpy as np
N,MOD = list(map(int,input().split()))
"""
余事象を調べる。包除の原理を使う。
A[n] = (1,2,...,n)が1杯以下、他は何でも良い
B[n,l] : (1,2,...,n) をlグループに分ける方法の個数
A[n]
・0杯のグループあり
・なし
"""
B = np.zeros((N+1,N+1), dtype=np.int64)
B[0,0] = 1
for n in range(1,N+1):
# 1番を単独で使う
B[n,1:] = B[n-1,:-1]
# 1番をどこかに混ぜてもらう
B[n,1:] += B[n-1,1:] * np.arange(1,N+1) % MOD
B[n] %= MOD
# 2^{kl}
pow_2 = np.ones((N+1,N+1), dtype=np.int64)
for n in range(1,N+1):
pow_2[1,n] = 2 * pow_2[1,n-1] % MOD
for n in range(2,N+1):
pow_2[n] = pow_2[n-1] * pow_2[1] % MOD
A = np.zeros(N+1, dtype=np.int64)
for n in range(N+1):
A[n] = (pow(2,pow(2,N-n,MOD-1),MOD) * B[n,1:] % MOD * (pow_2[N-n,1:] + pow_2[N-n,:-1] * np.arange(1,N+1) % MOD) % MOD).sum() % MOD
comb = np.zeros((N+1,N+1),dtype = np.int64)
comb[:,0] = 1
for n in range(1,N+1):
comb[n,1:] = (comb[n-1,1:] + comb[n-1,:-1]) % MOD
A[::2] *= (-1)
A *= comb[N]
A %= MOD
answer = pow(2,pow(2,N,MOD-1),MOD) - A.sum()
answer %= MOD
print(answer)
| import sys
input = sys.stdin.readline
import numpy as np
N,MOD = list(map(int,input().split()))
"""
余事象を調べる。包除の原理を使う。
A[n] = (1,2,...,n)が1杯以下、他は何でも良い
B[n,l] : (1,2,...,n) をlグループに分ける方法の個数
A[n]
・0杯のグループあり
・なし
"""
B = np.zeros((N+1,N+1), dtype=np.int64)
B[0,0] = 1
for n in range(1,N+1):
# 1番を単独で使う
B[n,1:] = B[n-1,:-1]
# 1番をどこかに混ぜてもらう
B[n,1:] += B[n-1,1:] * np.arange(1,N+1) % MOD
B[n] %= MOD
# 2^{kl}
pow_2 = np.ones((N+1,N+1), dtype=np.int64)
for n in range(1,N+1):
pow_2[1,n] = 2 * pow_2[1,n-1] % MOD
for n in range(2,N+1):
pow_2[n] = pow_2[n-1] * pow_2[1] % MOD
pow_pow = np.zeros(N+1, dtype = np.int64)
pow_pow[0] = 2
for n in range(1,N+1):
pow_pow[n] = pow_pow[n-1] ** 2 % MOD
A = (B[:,1:] * (pow_2[::-1,1:] + pow_2[::-1,:-1] * np.arange(1,N+1) % MOD) % MOD).sum(axis = 1)
A %= MOD
A *= pow_pow[::-1]
A %= MOD
fact = [1] * (N+1)
fact_inv = [1] * (N+1)
for n in range(1,N+1):
fact[n] = fact[n-1] * n % MOD
fact_inv[N] = pow(fact[N],MOD-2,MOD)
for n in range(N,0,-1):
fact_inv[n-1] = fact_inv[n] * n % MOD
fact = np.array(fact, dtype = np.int64)
fact_inv = np.array(fact_inv, dtype = np.int64)
comb = fact_inv * fact_inv[::-1] % MOD * fact[N] % MOD
A[::2] *= (-1)
A *= comb
A %= MOD
answer = pow(2,pow(2,N,MOD-1),MOD) - A.sum()
answer %= MOD
print(answer) | 47 | 59 | 1,075 | 1,358 | import sys
input = sys.stdin.readline
import numpy as np
N, MOD = list(map(int, input().split()))
"""
余事象を調べる。包除の原理を使う。
A[n] = (1,2,...,n)が1杯以下、他は何でも良い
B[n,l] : (1,2,...,n) をlグループに分ける方法の個数
A[n]
・0杯のグループあり
・なし
"""
B = np.zeros((N + 1, N + 1), dtype=np.int64)
B[0, 0] = 1
for n in range(1, N + 1):
# 1番を単独で使う
B[n, 1:] = B[n - 1, :-1]
# 1番をどこかに混ぜてもらう
B[n, 1:] += B[n - 1, 1:] * np.arange(1, N + 1) % MOD
B[n] %= MOD
# 2^{kl}
pow_2 = np.ones((N + 1, N + 1), dtype=np.int64)
for n in range(1, N + 1):
pow_2[1, n] = 2 * pow_2[1, n - 1] % MOD
for n in range(2, N + 1):
pow_2[n] = pow_2[n - 1] * pow_2[1] % MOD
A = np.zeros(N + 1, dtype=np.int64)
for n in range(N + 1):
A[n] = (
pow(2, pow(2, N - n, MOD - 1), MOD)
* B[n, 1:]
% MOD
* (pow_2[N - n, 1:] + pow_2[N - n, :-1] * np.arange(1, N + 1) % MOD)
% MOD
).sum() % MOD
comb = np.zeros((N + 1, N + 1), dtype=np.int64)
comb[:, 0] = 1
for n in range(1, N + 1):
comb[n, 1:] = (comb[n - 1, 1:] + comb[n - 1, :-1]) % MOD
A[::2] *= -1
A *= comb[N]
A %= MOD
answer = pow(2, pow(2, N, MOD - 1), MOD) - A.sum()
answer %= MOD
print(answer)
| import sys
input = sys.stdin.readline
import numpy as np
N, MOD = list(map(int, input().split()))
"""
余事象を調べる。包除の原理を使う。
A[n] = (1,2,...,n)が1杯以下、他は何でも良い
B[n,l] : (1,2,...,n) をlグループに分ける方法の個数
A[n]
・0杯のグループあり
・なし
"""
B = np.zeros((N + 1, N + 1), dtype=np.int64)
B[0, 0] = 1
for n in range(1, N + 1):
# 1番を単独で使う
B[n, 1:] = B[n - 1, :-1]
# 1番をどこかに混ぜてもらう
B[n, 1:] += B[n - 1, 1:] * np.arange(1, N + 1) % MOD
B[n] %= MOD
# 2^{kl}
pow_2 = np.ones((N + 1, N + 1), dtype=np.int64)
for n in range(1, N + 1):
pow_2[1, n] = 2 * pow_2[1, n - 1] % MOD
for n in range(2, N + 1):
pow_2[n] = pow_2[n - 1] * pow_2[1] % MOD
pow_pow = np.zeros(N + 1, dtype=np.int64)
pow_pow[0] = 2
for n in range(1, N + 1):
pow_pow[n] = pow_pow[n - 1] ** 2 % MOD
A = (
B[:, 1:] * (pow_2[::-1, 1:] + pow_2[::-1, :-1] * np.arange(1, N + 1) % MOD) % MOD
).sum(axis=1)
A %= MOD
A *= pow_pow[::-1]
A %= MOD
fact = [1] * (N + 1)
fact_inv = [1] * (N + 1)
for n in range(1, N + 1):
fact[n] = fact[n - 1] * n % MOD
fact_inv[N] = pow(fact[N], MOD - 2, MOD)
for n in range(N, 0, -1):
fact_inv[n - 1] = fact_inv[n] * n % MOD
fact = np.array(fact, dtype=np.int64)
fact_inv = np.array(fact_inv, dtype=np.int64)
comb = fact_inv * fact_inv[::-1] % MOD * fact[N] % MOD
A[::2] *= -1
A *= comb
A %= MOD
answer = pow(2, pow(2, N, MOD - 1), MOD) - A.sum()
answer %= MOD
print(answer)
| false | 20.338983 | [
"-A = np.zeros(N + 1, dtype=np.int64)",
"-for n in range(N + 1):",
"- A[n] = (",
"- pow(2, pow(2, N - n, MOD - 1), MOD)",
"- * B[n, 1:]",
"- % MOD",
"- * (pow_2[N - n, 1:] + pow_2[N - n, :-1] * np.arange(1, N + 1) % MOD)",
"- % MOD",
"- ).sum() % MOD",
"-comb = np.zeros((N + 1, N + 1), dtype=np.int64)",
"-comb[:, 0] = 1",
"+pow_pow = np.zeros(N + 1, dtype=np.int64)",
"+pow_pow[0] = 2",
"- comb[n, 1:] = (comb[n - 1, 1:] + comb[n - 1, :-1]) % MOD",
"+ pow_pow[n] = pow_pow[n - 1] ** 2 % MOD",
"+A = (",
"+ B[:, 1:] * (pow_2[::-1, 1:] + pow_2[::-1, :-1] * np.arange(1, N + 1) % MOD) % MOD",
"+).sum(axis=1)",
"+A %= MOD",
"+A *= pow_pow[::-1]",
"+A %= MOD",
"+fact = [1] * (N + 1)",
"+fact_inv = [1] * (N + 1)",
"+for n in range(1, N + 1):",
"+ fact[n] = fact[n - 1] * n % MOD",
"+fact_inv[N] = pow(fact[N], MOD - 2, MOD)",
"+for n in range(N, 0, -1):",
"+ fact_inv[n - 1] = fact_inv[n] * n % MOD",
"+fact = np.array(fact, dtype=np.int64)",
"+fact_inv = np.array(fact_inv, dtype=np.int64)",
"+comb = fact_inv * fact_inv[::-1] % MOD * fact[N] % MOD",
"-A *= comb[N]",
"+A *= comb"
] | false | 0.578291 | 0.229408 | 2.520798 | [
"s442383407",
"s220053232"
] |
u488401358 | p03032 | python | s885246709 | s114697961 | 302 | 164 | 50,268 | 83,572 | Accepted | Accepted | 45.7 | import copy,heapq
N,K=list(map(int,input().split()))
V=list(map(int,input().split()))
ans=0
left=copy.copy(V)
for i in range(1,N):
left[i]+=left[i-1]
right=copy.copy(V)
for i in range(1,N):
right[-i-1]+=right[-i]
for i in range(0,N+1):
for j in range(0,N-i+1):
dispose=K-i-j
if 0>dispose:
continue
test=0
q=[]
if i>0:
test+=left[i-1]
q+=V[:i]
if j>0:
test+=right[-j]
q+=V[N-j:N]
heapq.heapify(q)
while dispose>0 and q:
x=heapq.heappop(q)
if 0>x:
test-=x
dispose-=1
else:
break
ans=max(ans,test)
print(ans)
| import random
N,K=list(map(int,input().split()))
V=list(map(int,input().split()))
if K==0:
print((0))
exit()
if 0:
V=[random.randint(-10**7,10**7) for i in range(N)]
ans=-float("inf")
for i in range(N+1):
for j in range(N-i+1):
if i+j>K:
continue
tmp=[V[k] for k in range(i)]
for k in range(j):
tmp.append(V[-1-k])
tmp.sort()
rest=K-i-j
minus=0
base=sum(tmp)
for k in range(min(rest,len(tmp))):
if tmp[k]<0:
minus+=tmp[k]
else:
break
test=base-minus
ans=max(ans,test)
print(ans)
| 37 | 34 | 768 | 686 | import copy, heapq
N, K = list(map(int, input().split()))
V = list(map(int, input().split()))
ans = 0
left = copy.copy(V)
for i in range(1, N):
left[i] += left[i - 1]
right = copy.copy(V)
for i in range(1, N):
right[-i - 1] += right[-i]
for i in range(0, N + 1):
for j in range(0, N - i + 1):
dispose = K - i - j
if 0 > dispose:
continue
test = 0
q = []
if i > 0:
test += left[i - 1]
q += V[:i]
if j > 0:
test += right[-j]
q += V[N - j : N]
heapq.heapify(q)
while dispose > 0 and q:
x = heapq.heappop(q)
if 0 > x:
test -= x
dispose -= 1
else:
break
ans = max(ans, test)
print(ans)
| import random
N, K = list(map(int, input().split()))
V = list(map(int, input().split()))
if K == 0:
print((0))
exit()
if 0:
V = [random.randint(-(10**7), 10**7) for i in range(N)]
ans = -float("inf")
for i in range(N + 1):
for j in range(N - i + 1):
if i + j > K:
continue
tmp = [V[k] for k in range(i)]
for k in range(j):
tmp.append(V[-1 - k])
tmp.sort()
rest = K - i - j
minus = 0
base = sum(tmp)
for k in range(min(rest, len(tmp))):
if tmp[k] < 0:
minus += tmp[k]
else:
break
test = base - minus
ans = max(ans, test)
print(ans)
| false | 8.108108 | [
"-import copy, heapq",
"+import random",
"-ans = 0",
"-left = copy.copy(V)",
"-for i in range(1, N):",
"- left[i] += left[i - 1]",
"-right = copy.copy(V)",
"-for i in range(1, N):",
"- right[-i - 1] += right[-i]",
"-for i in range(0, N + 1):",
"- for j in range(0, N - i + 1):",
"- dispose = K - i - j",
"- if 0 > dispose:",
"+if K == 0:",
"+ print((0))",
"+ exit()",
"+if 0:",
"+ V = [random.randint(-(10**7), 10**7) for i in range(N)]",
"+ans = -float(\"inf\")",
"+for i in range(N + 1):",
"+ for j in range(N - i + 1):",
"+ if i + j > K:",
"- test = 0",
"- q = []",
"- if i > 0:",
"- test += left[i - 1]",
"- q += V[:i]",
"- if j > 0:",
"- test += right[-j]",
"- q += V[N - j : N]",
"- heapq.heapify(q)",
"- while dispose > 0 and q:",
"- x = heapq.heappop(q)",
"- if 0 > x:",
"- test -= x",
"- dispose -= 1",
"+ tmp = [V[k] for k in range(i)]",
"+ for k in range(j):",
"+ tmp.append(V[-1 - k])",
"+ tmp.sort()",
"+ rest = K - i - j",
"+ minus = 0",
"+ base = sum(tmp)",
"+ for k in range(min(rest, len(tmp))):",
"+ if tmp[k] < 0:",
"+ minus += tmp[k]",
"+ test = base - minus"
] | false | 0.038326 | 0.122409 | 0.313094 | [
"s885246709",
"s114697961"
] |
u659159398 | p02714 | python | s848276797 | s407539702 | 875 | 164 | 72,644 | 68,972 | Accepted | Accepted | 81.26 | n = int(eval(input()))
s = eval(input())
rinds, ginds, binds = [], [], []
for i in range(n):
if s[i] == 'R': rinds.append(i)
elif s[i] == 'G': ginds.append(i)
else: binds.append(i)
rlen, glen, blen = len(rinds), len(ginds), len(binds)
def binsearch_same(binds, blen, dist, i):
lo, hi = 0, blen-1
while lo<=hi:
mid = lo + (hi-lo)//2
d = binds[mid] - i
if dist == d:
return True
elif d < dist:
lo = mid + 1
else:
hi = mid - 1
return False
ans = 0
for i in rinds:
for j in ginds:
dist = abs(i-j)
i_ = min(i, j)
j_ = max(i, j)
ans += blen
# i' < j' < k
if binsearch_same(binds, blen, dist, j_):
ans -= 1
# i'< k < j'
if dist%2==0 and binsearch_same(binds, blen, dist//2, i_):
ans -= 1
# # k < i' < j'
if binsearch_same(binds, blen, -dist, i_):
ans -= 1
print(ans)
| n = int(eval(input()))
s = eval(input())
rinds, ginds, binds = [], [], set()
for i in range(n):
if s[i] == 'R': rinds.append(i)
elif s[i] == 'G': ginds.append(i)
else: binds.add(i)
rlen, glen, blen = len(rinds), len(ginds), len(binds)
ans = 0
for i in rinds:
for j in ginds:
dist = abs(i-j)
i_ = min(i, j)
j_ = max(i, j)
ans += blen
# i' < j' < k
if j_ + dist in binds:
ans -= 1
if dist%2==0 and i_ + dist//2 in binds:
ans -= 1
if i_ - dist in binds:
ans -= 1
# if binsearch_same(binds, blen, dist, j_):
# ans -= 1
# # i'< k < j'
# if dist%2==0 and binsearch_same(binds, blen, dist//2, i_):
# ans -= 1
# # # k < i' < j'
# if binsearch_same(binds, blen, -dist, i_):
# ans -= 1
print(ans)
# n = input()
# print('Yes' if '7' in n else 'No')
# n = int(input())
# ans = 0
# for i in range(1, n+1):
# if i%3 == 0 or i%5==0:
# pass
# else:
# ans += i
# print(ans)
# k = int(input())
# def gcd(a, b):
# if b == 0:
# return a
# return gcd(b, a%b)
# ans = 0
# for a in range(1, k+1):
# for b in range(1, k+1):
# for c in range(1, k+1):
# ans += gcd(gcd(a, b), c)
# print(ans) | 50 | 79 | 1,031 | 1,415 | n = int(eval(input()))
s = eval(input())
rinds, ginds, binds = [], [], []
for i in range(n):
if s[i] == "R":
rinds.append(i)
elif s[i] == "G":
ginds.append(i)
else:
binds.append(i)
rlen, glen, blen = len(rinds), len(ginds), len(binds)
def binsearch_same(binds, blen, dist, i):
lo, hi = 0, blen - 1
while lo <= hi:
mid = lo + (hi - lo) // 2
d = binds[mid] - i
if dist == d:
return True
elif d < dist:
lo = mid + 1
else:
hi = mid - 1
return False
ans = 0
for i in rinds:
for j in ginds:
dist = abs(i - j)
i_ = min(i, j)
j_ = max(i, j)
ans += blen
# i' < j' < k
if binsearch_same(binds, blen, dist, j_):
ans -= 1
# i'< k < j'
if dist % 2 == 0 and binsearch_same(binds, blen, dist // 2, i_):
ans -= 1
# # k < i' < j'
if binsearch_same(binds, blen, -dist, i_):
ans -= 1
print(ans)
| n = int(eval(input()))
s = eval(input())
rinds, ginds, binds = [], [], set()
for i in range(n):
if s[i] == "R":
rinds.append(i)
elif s[i] == "G":
ginds.append(i)
else:
binds.add(i)
rlen, glen, blen = len(rinds), len(ginds), len(binds)
ans = 0
for i in rinds:
for j in ginds:
dist = abs(i - j)
i_ = min(i, j)
j_ = max(i, j)
ans += blen
# i' < j' < k
if j_ + dist in binds:
ans -= 1
if dist % 2 == 0 and i_ + dist // 2 in binds:
ans -= 1
if i_ - dist in binds:
ans -= 1
# if binsearch_same(binds, blen, dist, j_):
# ans -= 1
# # i'< k < j'
# if dist%2==0 and binsearch_same(binds, blen, dist//2, i_):
# ans -= 1
# # # k < i' < j'
# if binsearch_same(binds, blen, -dist, i_):
# ans -= 1
print(ans)
# n = input()
# print('Yes' if '7' in n else 'No')
# n = int(input())
# ans = 0
# for i in range(1, n+1):
# if i%3 == 0 or i%5==0:
# pass
# else:
# ans += i
# print(ans)
# k = int(input())
# def gcd(a, b):
# if b == 0:
# return a
# return gcd(b, a%b)
# ans = 0
# for a in range(1, k+1):
# for b in range(1, k+1):
# for c in range(1, k+1):
# ans += gcd(gcd(a, b), c)
# print(ans)
| false | 36.708861 | [
"-rinds, ginds, binds = [], [], []",
"+rinds, ginds, binds = [], [], set()",
"- binds.append(i)",
"+ binds.add(i)",
"-",
"-",
"-def binsearch_same(binds, blen, dist, i):",
"- lo, hi = 0, blen - 1",
"- while lo <= hi:",
"- mid = lo + (hi - lo) // 2",
"- d = binds[mid] - i",
"- if dist == d:",
"- return True",
"- elif d < dist:",
"- lo = mid + 1",
"- else:",
"- hi = mid - 1",
"- return False",
"-",
"-",
"- if binsearch_same(binds, blen, dist, j_):",
"+ if j_ + dist in binds:",
"- # i'< k < j'",
"- if dist % 2 == 0 and binsearch_same(binds, blen, dist // 2, i_):",
"+ if dist % 2 == 0 and i_ + dist // 2 in binds:",
"- # # k < i' < j'",
"- if binsearch_same(binds, blen, -dist, i_):",
"+ if i_ - dist in binds:",
"+ # if binsearch_same(binds, blen, dist, j_):",
"+ # ans -= 1",
"+ # # i'< k < j'",
"+ # if dist%2==0 and binsearch_same(binds, blen, dist//2, i_):",
"+ # ans -= 1",
"+ # # # k < i' < j'",
"+ # if binsearch_same(binds, blen, -dist, i_):",
"+ # ans -= 1",
"+# n = input()",
"+# print('Yes' if '7' in n else 'No')",
"+# n = int(input())",
"+# ans = 0",
"+# for i in range(1, n+1):",
"+# if i%3 == 0 or i%5==0:",
"+# pass",
"+# else:",
"+# ans += i",
"+# print(ans)",
"+# k = int(input())",
"+# def gcd(a, b):",
"+# if b == 0:",
"+# return a",
"+# return gcd(b, a%b)",
"+# ans = 0",
"+# for a in range(1, k+1):",
"+# for b in range(1, k+1):",
"+# for c in range(1, k+1):",
"+# ans += gcd(gcd(a, b), c)",
"+# print(ans)"
] | false | 0.040743 | 0.036433 | 1.1183 | [
"s848276797",
"s407539702"
] |
u883048396 | p03946 | python | s126990505 | s085913789 | 118 | 81 | 15,060 | 14,252 | Accepted | Accepted | 31.36 |
iN,iT = [int(_) for _ in input().split()]
aA = [int(_) for _ in input().split()]
iL = len(aA)
aMaxD = [0]
iMin = aA[0]
iV = 0
def checkMax(aMaxD,iMaxD):
if aMaxD[0] < iMaxD:
aMaxD = [iMaxD]
elif aMaxD[0] == iMaxD:
aMaxD.append(iMaxD)
return aMaxD
for i in range(1,iL):
iB = aA[i-1]
iN = aA[i]
if iB - iN > 0:
if iV >= 0:
aMaxD = checkMax(aMaxD,iB-iMin)
iV = -1
elif iB - iN < 0:
if iV <= 0:
iMin = min(iB,iMin)
iV = 1
aMaxD = checkMax(aMaxD,aA[-1] - iMin)
print(( len(aMaxD) ))
| def 解():
iN,iT = [int(_) for _ in input().split()]
aA = [int(_) for _ in input().split()]
iL = len(aA)
aMaxD = [0]
iMin = aA[0]
iV = 0
def checkMax(aMaxD,iMaxD):
if aMaxD[0] < iMaxD:
aMaxD = [iMaxD]
elif aMaxD[0] == iMaxD:
aMaxD.append(iMaxD)
return aMaxD
iB = aA[0]
for iN in aA[1:]:
if iB - iN > 0:
if iV >= 0:
aMaxD = checkMax(aMaxD,iB-iMin)
iV = -1
elif iB - iN < 0:
if iV <= 0:
iMin = min(iB,iMin)
iV = 1
iB = iN
aMaxD = checkMax(aMaxD,aA[-1] - iMin)
print(( len(aMaxD) ))
解()
| 29 | 30 | 608 | 708 | iN, iT = [int(_) for _ in input().split()]
aA = [int(_) for _ in input().split()]
iL = len(aA)
aMaxD = [0]
iMin = aA[0]
iV = 0
def checkMax(aMaxD, iMaxD):
if aMaxD[0] < iMaxD:
aMaxD = [iMaxD]
elif aMaxD[0] == iMaxD:
aMaxD.append(iMaxD)
return aMaxD
for i in range(1, iL):
iB = aA[i - 1]
iN = aA[i]
if iB - iN > 0:
if iV >= 0:
aMaxD = checkMax(aMaxD, iB - iMin)
iV = -1
elif iB - iN < 0:
if iV <= 0:
iMin = min(iB, iMin)
iV = 1
aMaxD = checkMax(aMaxD, aA[-1] - iMin)
print((len(aMaxD)))
| def 解():
iN, iT = [int(_) for _ in input().split()]
aA = [int(_) for _ in input().split()]
iL = len(aA)
aMaxD = [0]
iMin = aA[0]
iV = 0
def checkMax(aMaxD, iMaxD):
if aMaxD[0] < iMaxD:
aMaxD = [iMaxD]
elif aMaxD[0] == iMaxD:
aMaxD.append(iMaxD)
return aMaxD
iB = aA[0]
for iN in aA[1:]:
if iB - iN > 0:
if iV >= 0:
aMaxD = checkMax(aMaxD, iB - iMin)
iV = -1
elif iB - iN < 0:
if iV <= 0:
iMin = min(iB, iMin)
iV = 1
iB = iN
aMaxD = checkMax(aMaxD, aA[-1] - iMin)
print((len(aMaxD)))
解()
| false | 3.333333 | [
"-iN, iT = [int(_) for _ in input().split()]",
"-aA = [int(_) for _ in input().split()]",
"-iL = len(aA)",
"-aMaxD = [0]",
"-iMin = aA[0]",
"-iV = 0",
"+def 解():",
"+ iN, iT = [int(_) for _ in input().split()]",
"+ aA = [int(_) for _ in input().split()]",
"+ iL = len(aA)",
"+ aMaxD = [0]",
"+ iMin = aA[0]",
"+ iV = 0",
"+",
"+ def checkMax(aMaxD, iMaxD):",
"+ if aMaxD[0] < iMaxD:",
"+ aMaxD = [iMaxD]",
"+ elif aMaxD[0] == iMaxD:",
"+ aMaxD.append(iMaxD)",
"+ return aMaxD",
"+",
"+ iB = aA[0]",
"+ for iN in aA[1:]:",
"+ if iB - iN > 0:",
"+ if iV >= 0:",
"+ aMaxD = checkMax(aMaxD, iB - iMin)",
"+ iV = -1",
"+ elif iB - iN < 0:",
"+ if iV <= 0:",
"+ iMin = min(iB, iMin)",
"+ iV = 1",
"+ iB = iN",
"+ aMaxD = checkMax(aMaxD, aA[-1] - iMin)",
"+ print((len(aMaxD)))",
"-def checkMax(aMaxD, iMaxD):",
"- if aMaxD[0] < iMaxD:",
"- aMaxD = [iMaxD]",
"- elif aMaxD[0] == iMaxD:",
"- aMaxD.append(iMaxD)",
"- return aMaxD",
"-",
"-",
"-for i in range(1, iL):",
"- iB = aA[i - 1]",
"- iN = aA[i]",
"- if iB - iN > 0:",
"- if iV >= 0:",
"- aMaxD = checkMax(aMaxD, iB - iMin)",
"- iV = -1",
"- elif iB - iN < 0:",
"- if iV <= 0:",
"- iMin = min(iB, iMin)",
"- iV = 1",
"-aMaxD = checkMax(aMaxD, aA[-1] - iMin)",
"-print((len(aMaxD)))",
"+解()"
] | false | 0.039996 | 0.109827 | 0.364169 | [
"s126990505",
"s085913789"
] |
u188138642 | p02886 | python | s416765897 | s106643360 | 34 | 27 | 9,012 | 9,060 | Accepted | Accepted | 20.59 | from itertools import combinations
n = int(eval(input()))
d = list(map(int, input().split()))
ans = 0
d = combinations(d, 2)
for i, j in d:
ans += i*j
print(ans)
| from itertools import combinations
n = int(eval(input()))
d = list(map(int, input().split()))
ans = 0
sum = sum(d)
for i in d:
sum -= i
ans += i*sum
print(ans) | 9 | 10 | 169 | 171 | from itertools import combinations
n = int(eval(input()))
d = list(map(int, input().split()))
ans = 0
d = combinations(d, 2)
for i, j in d:
ans += i * j
print(ans)
| from itertools import combinations
n = int(eval(input()))
d = list(map(int, input().split()))
ans = 0
sum = sum(d)
for i in d:
sum -= i
ans += i * sum
print(ans)
| false | 10 | [
"-d = combinations(d, 2)",
"-for i, j in d:",
"- ans += i * j",
"+sum = sum(d)",
"+for i in d:",
"+ sum -= i",
"+ ans += i * sum"
] | false | 0.041936 | 0.046202 | 0.907662 | [
"s416765897",
"s106643360"
] |
u099300051 | p02646 | python | s604764746 | s411827729 | 23 | 20 | 9,056 | 9,060 | Accepted | Accepted | 13.04 | a, v = list(map(int, input().split()))
b, w = list(map(int, input().split()))
t = int(eval(input()))
print(('YES' if abs(b-a) <= (v-w) * t else 'NO'))
| A,V=list(map(int,input().split()))
B,W=list(map(int,input().split()))
T=int(eval(input()))
v=V-W
l=abs(A-B)
if l<=v*T:
print("YES")
else:
print("NO")
| 5 | 9 | 136 | 144 | a, v = list(map(int, input().split()))
b, w = list(map(int, input().split()))
t = int(eval(input()))
print(("YES" if abs(b - a) <= (v - w) * t else "NO"))
| A, V = list(map(int, input().split()))
B, W = list(map(int, input().split()))
T = int(eval(input()))
v = V - W
l = abs(A - B)
if l <= v * T:
print("YES")
else:
print("NO")
| false | 44.444444 | [
"-a, v = list(map(int, input().split()))",
"-b, w = list(map(int, input().split()))",
"-t = int(eval(input()))",
"-print((\"YES\" if abs(b - a) <= (v - w) * t else \"NO\"))",
"+A, V = list(map(int, input().split()))",
"+B, W = list(map(int, input().split()))",
"+T = int(eval(input()))",
"+v = V - W",
"+l = abs(A - B)",
"+if l <= v * T:",
"+ print(\"YES\")",
"+else:",
"+ print(\"NO\")"
] | false | 0.035109 | 0.037502 | 0.936201 | [
"s604764746",
"s411827729"
] |
u882359130 | p03252 | python | s474477131 | s288529486 | 496 | 148 | 22,744 | 3,760 | Accepted | Accepted | 70.16 | S = eval(input())
T = eval(input())
SS = [s for s in S]
SS_set = list(set(SS))
CS = []
for c in SS_set:
C_idx_in_S = [i for i, x in enumerate(SS) if x==c]
if len(C_idx_in_S) > 1:
CS.append(C_idx_in_S)
TT = [t for t in T]
TT_set = list(set(TT))
CT = []
for c in TT_set:
C_idx_in_T = [i for i, x in enumerate(TT) if x==c]
if len(C_idx_in_T) > 1:
CT.append(C_idx_in_T)
if len(CS) == len(CT):
for i in CS:
if i in CT:
continue
else:
print("No")
break
else:
print("Yes")
else:
print("No") | #解説
S = eval(input())
T = eval(input())
start = [-1]*26
goal = [-1]*26
for i in range(len(S)):
a = ord(S[i]) - ord("a")
b = ord(T[i]) - ord("a")
if start[a] != -1 or goal[b] != -1:
if start[a] != b or goal[b] != a:
print("No")
break
else:
start[a] = b
goal[b] = a
else:
print("Yes") | 30 | 20 | 555 | 328 | S = eval(input())
T = eval(input())
SS = [s for s in S]
SS_set = list(set(SS))
CS = []
for c in SS_set:
C_idx_in_S = [i for i, x in enumerate(SS) if x == c]
if len(C_idx_in_S) > 1:
CS.append(C_idx_in_S)
TT = [t for t in T]
TT_set = list(set(TT))
CT = []
for c in TT_set:
C_idx_in_T = [i for i, x in enumerate(TT) if x == c]
if len(C_idx_in_T) > 1:
CT.append(C_idx_in_T)
if len(CS) == len(CT):
for i in CS:
if i in CT:
continue
else:
print("No")
break
else:
print("Yes")
else:
print("No")
| # 解説
S = eval(input())
T = eval(input())
start = [-1] * 26
goal = [-1] * 26
for i in range(len(S)):
a = ord(S[i]) - ord("a")
b = ord(T[i]) - ord("a")
if start[a] != -1 or goal[b] != -1:
if start[a] != b or goal[b] != a:
print("No")
break
else:
start[a] = b
goal[b] = a
else:
print("Yes")
| false | 33.333333 | [
"+# 解説",
"-SS = [s for s in S]",
"-SS_set = list(set(SS))",
"-CS = []",
"-for c in SS_set:",
"- C_idx_in_S = [i for i, x in enumerate(SS) if x == c]",
"- if len(C_idx_in_S) > 1:",
"- CS.append(C_idx_in_S)",
"-TT = [t for t in T]",
"-TT_set = list(set(TT))",
"-CT = []",
"-for c in TT_set:",
"- C_idx_in_T = [i for i, x in enumerate(TT) if x == c]",
"- if len(C_idx_in_T) > 1:",
"- CT.append(C_idx_in_T)",
"-if len(CS) == len(CT):",
"- for i in CS:",
"- if i in CT:",
"- continue",
"- else:",
"+start = [-1] * 26",
"+goal = [-1] * 26",
"+for i in range(len(S)):",
"+ a = ord(S[i]) - ord(\"a\")",
"+ b = ord(T[i]) - ord(\"a\")",
"+ if start[a] != -1 or goal[b] != -1:",
"+ if start[a] != b or goal[b] != a:",
"- print(\"Yes\")",
"+ start[a] = b",
"+ goal[b] = a",
"- print(\"No\")",
"+ print(\"Yes\")"
] | false | 0.047834 | 0.047661 | 1.003631 | [
"s474477131",
"s288529486"
] |
u111365362 | p02990 | python | s025083912 | s803621561 | 23 | 21 | 3,316 | 3,316 | Accepted | Accepted | 8.7 | n,k = list(map(int,input().split()))
m = 10**9+7
a = 1
b = n-k+1
print((a*b%m))
for i in range(2,k+1):
a *= k+1-i
a //= i-1
at = a%m
b *= n-k+2-i
b //= i
bt = b%m
print((at*bt%m)) | n,k = list(map(int,input().split()))
m = 10**9+7
b = 1
r = n-k+1
print((b*r%m))
for i in range(2,k+1):
b *= k-i+1
b //= i-1
r *= n-k-i+2
r //= i
print((b*r%m)) | 13 | 11 | 201 | 169 | n, k = list(map(int, input().split()))
m = 10**9 + 7
a = 1
b = n - k + 1
print((a * b % m))
for i in range(2, k + 1):
a *= k + 1 - i
a //= i - 1
at = a % m
b *= n - k + 2 - i
b //= i
bt = b % m
print((at * bt % m))
| n, k = list(map(int, input().split()))
m = 10**9 + 7
b = 1
r = n - k + 1
print((b * r % m))
for i in range(2, k + 1):
b *= k - i + 1
b //= i - 1
r *= n - k - i + 2
r //= i
print((b * r % m))
| false | 15.384615 | [
"-a = 1",
"-b = n - k + 1",
"-print((a * b % m))",
"+b = 1",
"+r = n - k + 1",
"+print((b * r % m))",
"- a *= k + 1 - i",
"- a //= i - 1",
"- at = a % m",
"- b *= n - k + 2 - i",
"- b //= i",
"- bt = b % m",
"- print((at * bt % m))",
"+ b *= k - i + 1",
"+ b //= i - 1",
"+ r *= n - k - i + 2",
"+ r //= i",
"+ print((b * r % m))"
] | false | 0.04264 | 0.042074 | 1.013462 | [
"s025083912",
"s803621561"
] |
u298297089 | p02995 | python | s600777215 | s339212347 | 40 | 35 | 5,048 | 5,076 | Accepted | Accepted | 12.5 | import fractions
A, B, C, D = list(map(int, input().split()))
total = B - A + 1
Cdiv = B // C - (A-1) // C
Ddiv = B // D - (A-1) // D
cddiv = (C*D)//fractions.gcd(C,D)
CDdiv = B // (cddiv) - (A-1) // (cddiv)
print((total - Cdiv - Ddiv + CDdiv))
| from fractions import gcd
A,B,C,D = list(map(int, input().split()))
E = (C*D) // gcd(C,D)
x = (A-1) // C
y = (A-1) // D
z = (A-1) // E
xx = B // C
yy = B // D
zz = B // E
Cdiv = xx-x
Ddiv = yy-y
Ediv = zz-z
tmp = xx-x + yy-y - (zz-z)
total = B-A+1
print((int(total - Cdiv - Ddiv + Ediv)))
| 9 | 18 | 247 | 301 | import fractions
A, B, C, D = list(map(int, input().split()))
total = B - A + 1
Cdiv = B // C - (A - 1) // C
Ddiv = B // D - (A - 1) // D
cddiv = (C * D) // fractions.gcd(C, D)
CDdiv = B // (cddiv) - (A - 1) // (cddiv)
print((total - Cdiv - Ddiv + CDdiv))
| from fractions import gcd
A, B, C, D = list(map(int, input().split()))
E = (C * D) // gcd(C, D)
x = (A - 1) // C
y = (A - 1) // D
z = (A - 1) // E
xx = B // C
yy = B // D
zz = B // E
Cdiv = xx - x
Ddiv = yy - y
Ediv = zz - z
tmp = xx - x + yy - y - (zz - z)
total = B - A + 1
print((int(total - Cdiv - Ddiv + Ediv)))
| false | 50 | [
"-import fractions",
"+from fractions import gcd",
"+E = (C * D) // gcd(C, D)",
"+x = (A - 1) // C",
"+y = (A - 1) // D",
"+z = (A - 1) // E",
"+xx = B // C",
"+yy = B // D",
"+zz = B // E",
"+Cdiv = xx - x",
"+Ddiv = yy - y",
"+Ediv = zz - z",
"+tmp = xx - x + yy - y - (zz - z)",
"-Cdiv = B // C - (A - 1) // C",
"-Ddiv = B // D - (A - 1) // D",
"-cddiv = (C * D) // fractions.gcd(C, D)",
"-CDdiv = B // (cddiv) - (A - 1) // (cddiv)",
"-print((total - Cdiv - Ddiv + CDdiv))",
"+print((int(total - Cdiv - Ddiv + Ediv)))"
] | false | 0.053354 | 0.053956 | 0.988837 | [
"s600777215",
"s339212347"
] |
u075304271 | p02603 | python | s797441671 | s796331000 | 122 | 42 | 77,456 | 10,448 | Accepted | Accepted | 65.57 | import math
import collections
import fractions
import itertools
import functools
import operator
import bisect
def divis(l):
seq = []
beg, end = 0, 0
le = len(l)
for i in range(1,le):
end = i
if l[i] < l[i-1]:
seq.append(l[beg:end])
beg = i
seq.append(l[beg:end+1])
return seq
def solve():
n = int(eval(input()))
a = list(map(int, input().split()))
divia = divis(a)
saihu = 1000
for i in divia:
saihu += (i[-1]-i[0])*(saihu//i[0])
print(saihu)
return 0
if __name__ == "__main__":
solve() | import math
import collections
import fractions
import itertools
import functools
import operator
def divis(l):
seq = []
beg, end = 0, 0
le = len(l)
for i in range(1,le):
end = i
if l[i] < l[i-1]:
seq.append(l[beg:end])
beg = i
seq.append(l[beg:end+1])
return seq
def solve():
n = int(eval(input()))
a = list(map(int, input().split()))
a = divis(a)
yosan = 1000
for i in a:
yosan += (i[-1]-i[0])*(yosan//i[0])
print(yosan)
return 0
if __name__ == "__main__":
solve() | 32 | 31 | 620 | 597 | import math
import collections
import fractions
import itertools
import functools
import operator
import bisect
def divis(l):
seq = []
beg, end = 0, 0
le = len(l)
for i in range(1, le):
end = i
if l[i] < l[i - 1]:
seq.append(l[beg:end])
beg = i
seq.append(l[beg : end + 1])
return seq
def solve():
n = int(eval(input()))
a = list(map(int, input().split()))
divia = divis(a)
saihu = 1000
for i in divia:
saihu += (i[-1] - i[0]) * (saihu // i[0])
print(saihu)
return 0
if __name__ == "__main__":
solve()
| import math
import collections
import fractions
import itertools
import functools
import operator
def divis(l):
seq = []
beg, end = 0, 0
le = len(l)
for i in range(1, le):
end = i
if l[i] < l[i - 1]:
seq.append(l[beg:end])
beg = i
seq.append(l[beg : end + 1])
return seq
def solve():
n = int(eval(input()))
a = list(map(int, input().split()))
a = divis(a)
yosan = 1000
for i in a:
yosan += (i[-1] - i[0]) * (yosan // i[0])
print(yosan)
return 0
if __name__ == "__main__":
solve()
| false | 3.125 | [
"-import bisect",
"- divia = divis(a)",
"- saihu = 1000",
"- for i in divia:",
"- saihu += (i[-1] - i[0]) * (saihu // i[0])",
"- print(saihu)",
"+ a = divis(a)",
"+ yosan = 1000",
"+ for i in a:",
"+ yosan += (i[-1] - i[0]) * (yosan // i[0])",
"+ print(yosan)"
] | false | 0.03499 | 0.034739 | 1.007227 | [
"s797441671",
"s796331000"
] |
u488127128 | p03796 | python | s539397344 | s735468002 | 38 | 34 | 2,940 | 2,940 | Accepted | Accepted | 10.53 | N = int(eval(input()))
a = 1
for n in range(2,N+1):
a = a*n % (10**9+7)
print(a) | import math
N = int(eval(input()))
a = 1
for n in range(2,N+1):
a = a*n % (10**9+7)
print(a) | 5 | 6 | 82 | 95 | N = int(eval(input()))
a = 1
for n in range(2, N + 1):
a = a * n % (10**9 + 7)
print(a)
| import math
N = int(eval(input()))
a = 1
for n in range(2, N + 1):
a = a * n % (10**9 + 7)
print(a)
| false | 16.666667 | [
"+import math",
"+"
] | false | 0.061577 | 0.081583 | 0.754776 | [
"s539397344",
"s735468002"
] |
u130900604 | p02707 | python | s770685545 | s335884551 | 196 | 170 | 34,096 | 36,364 | Accepted | Accepted | 13.27 | from collections import Counter
def LI():return list(map(int,input().split()))
n=int(eval(input()))
a=LI()
c=Counter(a)
for i in range(1,n+1):
ans=c[i]
print(ans)
| from collections import*
n,*a=list(map(int,open(0).read().split()));c=Counter(a)
for i in range(n):print((c[i+1])) | 12 | 3 | 180 | 108 | from collections import Counter
def LI():
return list(map(int, input().split()))
n = int(eval(input()))
a = LI()
c = Counter(a)
for i in range(1, n + 1):
ans = c[i]
print(ans)
| from collections import *
n, *a = list(map(int, open(0).read().split()))
c = Counter(a)
for i in range(n):
print((c[i + 1]))
| false | 75 | [
"-from collections import Counter",
"+from collections import *",
"-",
"-def LI():",
"- return list(map(int, input().split()))",
"-",
"-",
"-n = int(eval(input()))",
"-a = LI()",
"+n, *a = list(map(int, open(0).read().split()))",
"-for i in range(1, n + 1):",
"- ans = c[i]",
"- print(ans)",
"+for i in range(n):",
"+ print((c[i + 1]))"
] | false | 0.034806 | 0.041793 | 0.832817 | [
"s770685545",
"s335884551"
] |
u891635666 | p03241 | python | s575573951 | s764660547 | 29 | 21 | 3,664 | 3,060 | Accepted | Accepted | 27.59 | import collections
import itertools
import math
def eratosthenes(n):
sieve = [True for _ in range(n + 1)]
sieve[0] = False
sieve[1] = False
def _update(p):
if sieve[p]:
for i in range(p * 2, n + 1, p):
sieve[i] = False
_update(2)
p = 3
while p * p <= n:
_update(p)
p += 2
return sieve
n, m = list(map(int, input().split()))
m2 = math.ceil(math.sqrt(m)) + 1
sieve = eratosthenes(m2)
counter = collections.Counter()
mm = m
for k in range(2, m2):
if sieve[k] and m % k == 0:
while mm % k == 0:
mm //= k
counter[k] += 1
if mm > 1:
counter[mm] += 1
es = [list(range(k + 1)) for k in list(counter.values())]
res = 1
for ks in itertools.product(*es):
x = 1
for p, k in zip(list(counter.keys()), ks):
x *= p**k
if x <= m // n:
res = max(res, x)
print(res) | import math
n, m = list(map(int, input().split()))
mm = m // n
res = []
for k in range(int(math.sqrt(m)), 0, -1):
if m % k == 0:
if k > mm:
continue
if m // k <= mm:
k = m // k
res.append(k)
print((max(res))) | 46 | 13 | 928 | 265 | import collections
import itertools
import math
def eratosthenes(n):
sieve = [True for _ in range(n + 1)]
sieve[0] = False
sieve[1] = False
def _update(p):
if sieve[p]:
for i in range(p * 2, n + 1, p):
sieve[i] = False
_update(2)
p = 3
while p * p <= n:
_update(p)
p += 2
return sieve
n, m = list(map(int, input().split()))
m2 = math.ceil(math.sqrt(m)) + 1
sieve = eratosthenes(m2)
counter = collections.Counter()
mm = m
for k in range(2, m2):
if sieve[k] and m % k == 0:
while mm % k == 0:
mm //= k
counter[k] += 1
if mm > 1:
counter[mm] += 1
es = [list(range(k + 1)) for k in list(counter.values())]
res = 1
for ks in itertools.product(*es):
x = 1
for p, k in zip(list(counter.keys()), ks):
x *= p**k
if x <= m // n:
res = max(res, x)
print(res)
| import math
n, m = list(map(int, input().split()))
mm = m // n
res = []
for k in range(int(math.sqrt(m)), 0, -1):
if m % k == 0:
if k > mm:
continue
if m // k <= mm:
k = m // k
res.append(k)
print((max(res)))
| false | 71.73913 | [
"-import collections",
"-import itertools",
"-",
"-def eratosthenes(n):",
"- sieve = [True for _ in range(n + 1)]",
"- sieve[0] = False",
"- sieve[1] = False",
"-",
"- def _update(p):",
"- if sieve[p]:",
"- for i in range(p * 2, n + 1, p):",
"- sieve[i] = False",
"-",
"- _update(2)",
"- p = 3",
"- while p * p <= n:",
"- _update(p)",
"- p += 2",
"- return sieve",
"-",
"-",
"-m2 = math.ceil(math.sqrt(m)) + 1",
"-sieve = eratosthenes(m2)",
"-counter = collections.Counter()",
"-mm = m",
"-for k in range(2, m2):",
"- if sieve[k] and m % k == 0:",
"- while mm % k == 0:",
"- mm //= k",
"- counter[k] += 1",
"-if mm > 1:",
"- counter[mm] += 1",
"-es = [list(range(k + 1)) for k in list(counter.values())]",
"-res = 1",
"-for ks in itertools.product(*es):",
"- x = 1",
"- for p, k in zip(list(counter.keys()), ks):",
"- x *= p**k",
"- if x <= m // n:",
"- res = max(res, x)",
"-print(res)",
"+mm = m // n",
"+res = []",
"+for k in range(int(math.sqrt(m)), 0, -1):",
"+ if m % k == 0:",
"+ if k > mm:",
"+ continue",
"+ if m // k <= mm:",
"+ k = m // k",
"+ res.append(k)",
"+print((max(res)))"
] | false | 0.1481 | 0.190594 | 0.777044 | [
"s575573951",
"s764660547"
] |
u094191970 | p03031 | python | s150979160 | s789449983 | 48 | 44 | 3,064 | 3,064 | Accepted | Accepted | 8.33 | n,m=list(map(int,input().split()))
l=[list(map(int,input().split())) for i in range(m)]
p=list(map(int,input().split()))
ans=0
for i in range(2**n):
num=0
#ある電球
for j in range(m):
cnt=0
#ある電球に接続されている各スイッチ
for k in range(1,l[j][0]+1):
if (i>>l[j][k]-1) & 1:
cnt+=1
if cnt%2==p[j]:
num+=1
if num==m:
ans+=1
print(ans) | n,m=list(map(int,input().split()))
k=[list(map(int,input().split())) for i in range(m)]
p=list(map(int,input().split()))
cnt=0
for i in range(2**n):
l=[0 for j in range(n)]
for j in range(n):
if (i>>j)&1:
l[j]=1
t_cnt=0
for j in range(m):
on_l=0
for x in k[j][1:]:
x-=1
if l[x]==1:
on_l+=1
if on_l%2==p[j]:
t_cnt+=1
if t_cnt==m:
cnt+=1
print(cnt) | 20 | 25 | 378 | 430 | n, m = list(map(int, input().split()))
l = [list(map(int, input().split())) for i in range(m)]
p = list(map(int, input().split()))
ans = 0
for i in range(2**n):
num = 0
# ある電球
for j in range(m):
cnt = 0
# ある電球に接続されている各スイッチ
for k in range(1, l[j][0] + 1):
if (i >> l[j][k] - 1) & 1:
cnt += 1
if cnt % 2 == p[j]:
num += 1
if num == m:
ans += 1
print(ans)
| n, m = list(map(int, input().split()))
k = [list(map(int, input().split())) for i in range(m)]
p = list(map(int, input().split()))
cnt = 0
for i in range(2**n):
l = [0 for j in range(n)]
for j in range(n):
if (i >> j) & 1:
l[j] = 1
t_cnt = 0
for j in range(m):
on_l = 0
for x in k[j][1:]:
x -= 1
if l[x] == 1:
on_l += 1
if on_l % 2 == p[j]:
t_cnt += 1
if t_cnt == m:
cnt += 1
print(cnt)
| false | 20 | [
"-l = [list(map(int, input().split())) for i in range(m)]",
"+k = [list(map(int, input().split())) for i in range(m)]",
"-ans = 0",
"+cnt = 0",
"- num = 0",
"- # ある電球",
"+ l = [0 for j in range(n)]",
"+ for j in range(n):",
"+ if (i >> j) & 1:",
"+ l[j] = 1",
"+ t_cnt = 0",
"- cnt = 0",
"- # ある電球に接続されている各スイッチ",
"- for k in range(1, l[j][0] + 1):",
"- if (i >> l[j][k] - 1) & 1:",
"- cnt += 1",
"- if cnt % 2 == p[j]:",
"- num += 1",
"- if num == m:",
"- ans += 1",
"-print(ans)",
"+ on_l = 0",
"+ for x in k[j][1:]:",
"+ x -= 1",
"+ if l[x] == 1:",
"+ on_l += 1",
"+ if on_l % 2 == p[j]:",
"+ t_cnt += 1",
"+ if t_cnt == m:",
"+ cnt += 1",
"+print(cnt)"
] | false | 0.075877 | 0.044873 | 1.690933 | [
"s150979160",
"s789449983"
] |
u344065503 | p03557 | python | s567597465 | s513149574 | 455 | 231 | 107,108 | 29,396 | Accepted | Accepted | 49.23 | import bisect
n=eval(input())
a=sorted(list(map(int,input().split())))
b=sorted(list(map(int,input().split())))
c=sorted(list(map(int,input().split())))
ans=0
for B in b:
ans+=(bisect.bisect_left(a,B))*(len(c)-(bisect.bisect_right(c,B)))
print(ans) | import bisect
n=int(eval(input()))
a=sorted(list(map(int,input().split())))
b=sorted(list(map(int,input().split())))
c=sorted(list(map(int,input().split())))
ans=0
for i in b:
A=bisect.bisect_left(a,i)
C=bisect.bisect(c,i)
ans+=A*(n-C)
print(ans)
| 9 | 11 | 252 | 258 | import bisect
n = eval(input())
a = sorted(list(map(int, input().split())))
b = sorted(list(map(int, input().split())))
c = sorted(list(map(int, input().split())))
ans = 0
for B in b:
ans += (bisect.bisect_left(a, B)) * (len(c) - (bisect.bisect_right(c, B)))
print(ans)
| import bisect
n = int(eval(input()))
a = sorted(list(map(int, input().split())))
b = sorted(list(map(int, input().split())))
c = sorted(list(map(int, input().split())))
ans = 0
for i in b:
A = bisect.bisect_left(a, i)
C = bisect.bisect(c, i)
ans += A * (n - C)
print(ans)
| false | 18.181818 | [
"-n = eval(input())",
"+n = int(eval(input()))",
"-for B in b:",
"- ans += (bisect.bisect_left(a, B)) * (len(c) - (bisect.bisect_right(c, B)))",
"+for i in b:",
"+ A = bisect.bisect_left(a, i)",
"+ C = bisect.bisect(c, i)",
"+ ans += A * (n - C)"
] | false | 0.04843 | 0.12745 | 0.379995 | [
"s567597465",
"s513149574"
] |
u888092736 | p04034 | python | s640671142 | s274365973 | 178 | 109 | 41,712 | 31,724 | Accepted | Accepted | 38.76 | N, M, *xy = list(map(int, open(0).read().split()))
boxes = [{"count": 1, "red": False} for _ in range(N)]
boxes[0]["red"] = True
for x, y in zip(*[iter(xy)] * 2):
x -= 1
y -= 1
if boxes[x]["red"]:
boxes[y]["red"] = True
if boxes[x]["count"] == 1:
boxes[x]["red"] = False
boxes[x]["count"] -= 1
boxes[y]["count"] += 1
print((sum(b["red"] for b in boxes)))
| N, M, *xy = list(map(int, open(0).read().split()))
boxes = [1] * N
is_red = [0] * N
is_red[0] = 1
for x, y in zip(*[iter(xy)] * 2):
x -= 1
y -= 1
boxes[x] -= 1
boxes[y] += 1
if is_red[x]:
if boxes[x] == 0:
is_red[x] = 0
is_red[y] = 1
print((sum(is_red)))
| 14 | 15 | 409 | 310 | N, M, *xy = list(map(int, open(0).read().split()))
boxes = [{"count": 1, "red": False} for _ in range(N)]
boxes[0]["red"] = True
for x, y in zip(*[iter(xy)] * 2):
x -= 1
y -= 1
if boxes[x]["red"]:
boxes[y]["red"] = True
if boxes[x]["count"] == 1:
boxes[x]["red"] = False
boxes[x]["count"] -= 1
boxes[y]["count"] += 1
print((sum(b["red"] for b in boxes)))
| N, M, *xy = list(map(int, open(0).read().split()))
boxes = [1] * N
is_red = [0] * N
is_red[0] = 1
for x, y in zip(*[iter(xy)] * 2):
x -= 1
y -= 1
boxes[x] -= 1
boxes[y] += 1
if is_red[x]:
if boxes[x] == 0:
is_red[x] = 0
is_red[y] = 1
print((sum(is_red)))
| false | 6.666667 | [
"-boxes = [{\"count\": 1, \"red\": False} for _ in range(N)]",
"-boxes[0][\"red\"] = True",
"+boxes = [1] * N",
"+is_red = [0] * N",
"+is_red[0] = 1",
"- if boxes[x][\"red\"]:",
"- boxes[y][\"red\"] = True",
"- if boxes[x][\"count\"] == 1:",
"- boxes[x][\"red\"] = False",
"- boxes[x][\"count\"] -= 1",
"- boxes[y][\"count\"] += 1",
"-print((sum(b[\"red\"] for b in boxes)))",
"+ boxes[x] -= 1",
"+ boxes[y] += 1",
"+ if is_red[x]:",
"+ if boxes[x] == 0:",
"+ is_red[x] = 0",
"+ is_red[y] = 1",
"+print((sum(is_red)))"
] | false | 0.03863 | 0.120108 | 0.321629 | [
"s640671142",
"s274365973"
] |
u620708171 | p03171 | python | s316358277 | s789088253 | 283 | 238 | 42,076 | 39,920 | Accepted | Accepted | 15.9 | def deque(a):
n = len(a)
cur = [(x, 0) for x in a]
nxt = [(0, 0)] * n
for l in range(2, n + 1):
for i in range(n - l + 1):
j = i + l - 1
x, y = cur[i]
z, t = cur[i + 1]
if a[i] + t - z > a[j] + y - x:
nxt[i] = (a[i] + t, z)
else:
nxt[i] = (a[j] + y, x)
cur, nxt = nxt, cur
return cur[0][0] - cur[0][1]
def main():
eval(input()) # n
a = [int(x) for x in input().split()]
return deque(a)
print((main()))
| def deque(a):
n = len(a)
cur = a[:]
nxt = [0] * (n - 1)
for l in range(2, n + 1):
for i in range(n - l + 1):
j = i + l - 1
nxt[i] = max(a[i] - cur[i + 1], a[j] - cur[i])
cur, nxt = nxt, cur
return cur[0]
def main():
eval(input()) # n
a = [int(x) for x in input().split()]
return deque(a)
print((main()))
| 24 | 19 | 562 | 391 | def deque(a):
n = len(a)
cur = [(x, 0) for x in a]
nxt = [(0, 0)] * n
for l in range(2, n + 1):
for i in range(n - l + 1):
j = i + l - 1
x, y = cur[i]
z, t = cur[i + 1]
if a[i] + t - z > a[j] + y - x:
nxt[i] = (a[i] + t, z)
else:
nxt[i] = (a[j] + y, x)
cur, nxt = nxt, cur
return cur[0][0] - cur[0][1]
def main():
eval(input()) # n
a = [int(x) for x in input().split()]
return deque(a)
print((main()))
| def deque(a):
n = len(a)
cur = a[:]
nxt = [0] * (n - 1)
for l in range(2, n + 1):
for i in range(n - l + 1):
j = i + l - 1
nxt[i] = max(a[i] - cur[i + 1], a[j] - cur[i])
cur, nxt = nxt, cur
return cur[0]
def main():
eval(input()) # n
a = [int(x) for x in input().split()]
return deque(a)
print((main()))
| false | 20.833333 | [
"- cur = [(x, 0) for x in a]",
"- nxt = [(0, 0)] * n",
"+ cur = a[:]",
"+ nxt = [0] * (n - 1)",
"- x, y = cur[i]",
"- z, t = cur[i + 1]",
"- if a[i] + t - z > a[j] + y - x:",
"- nxt[i] = (a[i] + t, z)",
"- else:",
"- nxt[i] = (a[j] + y, x)",
"+ nxt[i] = max(a[i] - cur[i + 1], a[j] - cur[i])",
"- return cur[0][0] - cur[0][1]",
"+ return cur[0]"
] | false | 0.13721 | 0.094942 | 1.445186 | [
"s316358277",
"s789088253"
] |
u363768711 | p03611 | python | s162714952 | s854132273 | 140 | 90 | 20,036 | 14,336 | Accepted | Accepted | 35.71 | from collections import defaultdict
n = int(eval(input()))
a_lis = list(map(int,input().split()))
A_dict = defaultdict(int)
for i in a_lis:
A_dict[i] += 1
max_cnt = 0
for j in range(1, 10**5):
tmp = A_dict[j-1]+A_dict[j]+A_dict[j+1]
max_cnt = max(max_cnt, tmp)
print(max_cnt) | from collections import defaultdict
n = int(eval(input()))
ans = 0
a_lis = list(map(int,input().split()))
A_dict = [0]*(10**5+1)
for i in a_lis:
A_dict[i] += 1
for j in range(1,10**5):
tmp = A_dict[j-1]+A_dict[j]+A_dict[j+1]
if tmp > ans:
ans = tmp
print(ans) | 16 | 16 | 297 | 282 | from collections import defaultdict
n = int(eval(input()))
a_lis = list(map(int, input().split()))
A_dict = defaultdict(int)
for i in a_lis:
A_dict[i] += 1
max_cnt = 0
for j in range(1, 10**5):
tmp = A_dict[j - 1] + A_dict[j] + A_dict[j + 1]
max_cnt = max(max_cnt, tmp)
print(max_cnt)
| from collections import defaultdict
n = int(eval(input()))
ans = 0
a_lis = list(map(int, input().split()))
A_dict = [0] * (10**5 + 1)
for i in a_lis:
A_dict[i] += 1
for j in range(1, 10**5):
tmp = A_dict[j - 1] + A_dict[j] + A_dict[j + 1]
if tmp > ans:
ans = tmp
print(ans)
| false | 0 | [
"+ans = 0",
"-A_dict = defaultdict(int)",
"+A_dict = [0] * (10**5 + 1)",
"-max_cnt = 0",
"- max_cnt = max(max_cnt, tmp)",
"-print(max_cnt)",
"+ if tmp > ans:",
"+ ans = tmp",
"+print(ans)"
] | false | 0.127937 | 0.108903 | 1.174778 | [
"s162714952",
"s854132273"
] |
u634046173 | p02983 | python | s206998526 | s559850676 | 200 | 70 | 65,796 | 65,428 | Accepted | Accepted | 65 | L, R = list(map(int, input().split()))
target = R+1
if R - L > 10000:
target = L + 10000
mi = 2019
for i in range(L,target):
for j in range(i+1,target):
mi = min(mi,(i*j)%2019)
print(mi) | L, R = list(map(int, input().split()))
target = R+1
if R - L > 2019:
target = L + 2019
mi = 2019
for i in range(L,target):
for j in range(i+1,target):
mi = min(mi,(i*j)%2019)
print(mi)
| 9 | 9 | 204 | 203 | L, R = list(map(int, input().split()))
target = R + 1
if R - L > 10000:
target = L + 10000
mi = 2019
for i in range(L, target):
for j in range(i + 1, target):
mi = min(mi, (i * j) % 2019)
print(mi)
| L, R = list(map(int, input().split()))
target = R + 1
if R - L > 2019:
target = L + 2019
mi = 2019
for i in range(L, target):
for j in range(i + 1, target):
mi = min(mi, (i * j) % 2019)
print(mi)
| false | 0 | [
"-if R - L > 10000:",
"- target = L + 10000",
"+if R - L > 2019:",
"+ target = L + 2019"
] | false | 0.111527 | 0.075128 | 1.484487 | [
"s206998526",
"s559850676"
] |
u821262411 | p03607 | python | s352712114 | s249904612 | 225 | 203 | 11,488 | 11,884 | Accepted | Accepted | 9.78 | n=int(eval(input()))
buff=[]
ans=1
for i in range(n):
buff.append(eval(input()))
a=sorted(buff)
for i in range(1,n):
if a[i] == a[i-1]:
a[i-1]= -1
a[i]= -1
if ans>0:
ans -= 1
else:
ans += 1
print(ans)
| n=int(eval(input()))
buff=set()
for i in range(n):
a=int(eval(input()))
if a in buff:
buff.remove(a)
else:
buff.add(a)
print((len(buff))) | 18 | 10 | 265 | 161 | n = int(eval(input()))
buff = []
ans = 1
for i in range(n):
buff.append(eval(input()))
a = sorted(buff)
for i in range(1, n):
if a[i] == a[i - 1]:
a[i - 1] = -1
a[i] = -1
if ans > 0:
ans -= 1
else:
ans += 1
print(ans)
| n = int(eval(input()))
buff = set()
for i in range(n):
a = int(eval(input()))
if a in buff:
buff.remove(a)
else:
buff.add(a)
print((len(buff)))
| false | 44.444444 | [
"-buff = []",
"-ans = 1",
"+buff = set()",
"- buff.append(eval(input()))",
"-a = sorted(buff)",
"-for i in range(1, n):",
"- if a[i] == a[i - 1]:",
"- a[i - 1] = -1",
"- a[i] = -1",
"- if ans > 0:",
"- ans -= 1",
"+ a = int(eval(input()))",
"+ if a in buff:",
"+ buff.remove(a)",
"- ans += 1",
"-print(ans)",
"+ buff.add(a)",
"+print((len(buff)))"
] | false | 0.088768 | 0.08561 | 1.036877 | [
"s352712114",
"s249904612"
] |
u818349438 | p02837 | python | s491539867 | s929539525 | 1,441 | 116 | 52,444 | 3,188 | Accepted | Accepted | 91.95 | n = int(eval(input()))
a = [0]*n
x = [[0] *n for i in range(n)]
y = [[0] *n for i in range(n)]
ans = 0
for i in range(n):
a[i] = int(eval(input()))
for j in range(a[i]):
x[i][j],y[i][j] = list(map(int,input().split()))
x[i][j]-=1
def honest(i,j):
return (i>>j)%2 ==1
def check(m):
for i in range(n):
if not honest(m,i) :continue
for j in range(a[i]):
if y[i][j] == 1 and honest(m,x[i][j]) == 0:
return False
if y[i][j] == 0 and honest(m,x[i][j]) == 1:
return False
return True
def count(c):
cnt = 0
for i in range(c//2+5):
cnt+= (c >> i)%2
return cnt
for i in range(2**n):
if check(i):
ans = max(ans,count(i))
print(ans)
| import sys
sys.setrecursionlimit(10**7)
n = int(eval(input()))
people = []
shogens = [[]for i in range(n)]
def check():
for i in range(n):
if i not in people:continue
for shogen in shogens[i]:
person = shogen[0]
honest = shogen[1]
if honest and person not in people:return False
if (not honest) and person in people:return False
return True
for i in range(n):
a = int(eval(input()))
for j in range(a):
p,q = list(map(int,input().split()))
p -= 1
shogens[i].append((p,q))
def dfs(d,people):
if d == n:
if check():
return len(people)
else:
return 0
res = dfs(d+1,people)
people.append(d)
res = max(res,dfs(d+1,people))
people.pop()
return res
print((dfs(0,people)))
| 35 | 39 | 818 | 929 | n = int(eval(input()))
a = [0] * n
x = [[0] * n for i in range(n)]
y = [[0] * n for i in range(n)]
ans = 0
for i in range(n):
a[i] = int(eval(input()))
for j in range(a[i]):
x[i][j], y[i][j] = list(map(int, input().split()))
x[i][j] -= 1
def honest(i, j):
return (i >> j) % 2 == 1
def check(m):
for i in range(n):
if not honest(m, i):
continue
for j in range(a[i]):
if y[i][j] == 1 and honest(m, x[i][j]) == 0:
return False
if y[i][j] == 0 and honest(m, x[i][j]) == 1:
return False
return True
def count(c):
cnt = 0
for i in range(c // 2 + 5):
cnt += (c >> i) % 2
return cnt
for i in range(2**n):
if check(i):
ans = max(ans, count(i))
print(ans)
| import sys
sys.setrecursionlimit(10**7)
n = int(eval(input()))
people = []
shogens = [[] for i in range(n)]
def check():
for i in range(n):
if i not in people:
continue
for shogen in shogens[i]:
person = shogen[0]
honest = shogen[1]
if honest and person not in people:
return False
if (not honest) and person in people:
return False
return True
for i in range(n):
a = int(eval(input()))
for j in range(a):
p, q = list(map(int, input().split()))
p -= 1
shogens[i].append((p, q))
def dfs(d, people):
if d == n:
if check():
return len(people)
else:
return 0
res = dfs(d + 1, people)
people.append(d)
res = max(res, dfs(d + 1, people))
people.pop()
return res
print((dfs(0, people)))
| false | 10.25641 | [
"+import sys",
"+",
"+sys.setrecursionlimit(10**7)",
"-a = [0] * n",
"-x = [[0] * n for i in range(n)]",
"-y = [[0] * n for i in range(n)]",
"-ans = 0",
"-for i in range(n):",
"- a[i] = int(eval(input()))",
"- for j in range(a[i]):",
"- x[i][j], y[i][j] = list(map(int, input().split()))",
"- x[i][j] -= 1",
"+people = []",
"+shogens = [[] for i in range(n)]",
"-def honest(i, j):",
"- return (i >> j) % 2 == 1",
"-",
"-",
"-def check(m):",
"+def check():",
"- if not honest(m, i):",
"+ if i not in people:",
"- for j in range(a[i]):",
"- if y[i][j] == 1 and honest(m, x[i][j]) == 0:",
"+ for shogen in shogens[i]:",
"+ person = shogen[0]",
"+ honest = shogen[1]",
"+ if honest and person not in people:",
"- if y[i][j] == 0 and honest(m, x[i][j]) == 1:",
"+ if (not honest) and person in people:",
"-def count(c):",
"- cnt = 0",
"- for i in range(c // 2 + 5):",
"- cnt += (c >> i) % 2",
"- return cnt",
"+for i in range(n):",
"+ a = int(eval(input()))",
"+ for j in range(a):",
"+ p, q = list(map(int, input().split()))",
"+ p -= 1",
"+ shogens[i].append((p, q))",
"-for i in range(2**n):",
"- if check(i):",
"- ans = max(ans, count(i))",
"-print(ans)",
"+def dfs(d, people):",
"+ if d == n:",
"+ if check():",
"+ return len(people)",
"+ else:",
"+ return 0",
"+ res = dfs(d + 1, people)",
"+ people.append(d)",
"+ res = max(res, dfs(d + 1, people))",
"+ people.pop()",
"+ return res",
"+",
"+",
"+print((dfs(0, people)))"
] | false | 0.08244 | 0.034171 | 2.412598 | [
"s491539867",
"s929539525"
] |
u272075541 | p02819 | python | s723641518 | s273338363 | 233 | 172 | 3,304 | 9,556 | Accepted | Accepted | 26.18 | # -*- coding: utf-8 -*-
################ DANGER ################
test = ""
test = \
"""
"""
########################################
test = list(reversed(test.strip().splitlines()))
if test:
def input2():
return test.pop()
else:
def input2():
return input()
########################################
n = int(input2())
def primes(n):
ps = [2]
for odd in range(3, n + 1, 2):
for p in ps:
if odd % p == 0:
break
if p ** 2 > odd:
ps.append(odd)
break
return ps
def isprime(n):
last = int(n**.5)
for m in primes(last):
if n % m == 0:
return False
return True
def nextprime(n):
if n in primes(n):
return n
elif n == 1:
return 2
else:
i = n
while not isprime(i):
i += 1
return i
print(nextprime(n))
| # -*- coding: utf-8 -*-
# Next Prime
import sys
TEST_INPUT = \
"""
100000
"""
TEST_OUTPUT = \
"""
100003
"""
def primes(n):
if n == 0 or n == 1: return []
ps = [2]
for odd in range(3, n + 1, 2):
for p in ps:
if odd % p == 0:
break
if p ** 2 > odd:
ps.append(odd)
break
return ps
def isprime(n):
if n == 0 or n == 1: return False
last = int(n**.5)
for m in primes(last):
if n % m == 0:
return False
return True
def nextprime(n):
if n in primes(n):
return n
else:
i = n
while not isprime(i):
i += 1
return i
def main(stdin):
n = int(stdin)
print(nextprime(n))
if __name__ == "__main__":
main(sys.stdin.read().strip())
| 53 | 62 | 974 | 900 | # -*- coding: utf-8 -*-
################ DANGER ################
test = ""
test = """
"""
########################################
test = list(reversed(test.strip().splitlines()))
if test:
def input2():
return test.pop()
else:
def input2():
return input()
########################################
n = int(input2())
def primes(n):
ps = [2]
for odd in range(3, n + 1, 2):
for p in ps:
if odd % p == 0:
break
if p**2 > odd:
ps.append(odd)
break
return ps
def isprime(n):
last = int(n**0.5)
for m in primes(last):
if n % m == 0:
return False
return True
def nextprime(n):
if n in primes(n):
return n
elif n == 1:
return 2
else:
i = n
while not isprime(i):
i += 1
return i
print(nextprime(n))
| # -*- coding: utf-8 -*-
# Next Prime
import sys
TEST_INPUT = """
100000
"""
TEST_OUTPUT = """
100003
"""
def primes(n):
if n == 0 or n == 1:
return []
ps = [2]
for odd in range(3, n + 1, 2):
for p in ps:
if odd % p == 0:
break
if p**2 > odd:
ps.append(odd)
break
return ps
def isprime(n):
if n == 0 or n == 1:
return False
last = int(n**0.5)
for m in primes(last):
if n % m == 0:
return False
return True
def nextprime(n):
if n in primes(n):
return n
else:
i = n
while not isprime(i):
i += 1
return i
def main(stdin):
n = int(stdin)
print(nextprime(n))
if __name__ == "__main__":
main(sys.stdin.read().strip())
| false | 14.516129 | [
"-################ DANGER ################",
"-test = \"\"",
"-test = \"\"\"",
"+# Next Prime",
"+import sys",
"+",
"+TEST_INPUT = \"\"\"",
"+100000",
"-########################################",
"-test = list(reversed(test.strip().splitlines()))",
"-if test:",
"-",
"- def input2():",
"- return test.pop()",
"-",
"-else:",
"-",
"- def input2():",
"- return input()",
"-",
"-",
"-########################################",
"-n = int(input2())",
"+TEST_OUTPUT = \"\"\"",
"+100003",
"+\"\"\"",
"+ if n == 0 or n == 1:",
"+ return []",
"+ if n == 0 or n == 1:",
"+ return False",
"- elif n == 1:",
"- return 2",
"-print(nextprime(n))",
"+def main(stdin):",
"+ n = int(stdin)",
"+ print(nextprime(n))",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main(sys.stdin.read().strip())"
] | false | 0.034248 | 0.036338 | 0.942467 | [
"s723641518",
"s273338363"
] |
u066253157 | p03624 | python | s329954765 | s015584234 | 67 | 49 | 5,312 | 4,920 | Accepted | Accepted | 26.87 | S = eval(input())
import string
S = list(sorted(S))
T = string.ascii_lowercase
for t in T:
if t not in S:
print(t)
break
else:
print("None") | S = eval(input())
import string
letters = string.ascii_lowercase
S = set(sorted(S))
for l in letters:
if l not in S:
print(l)
break
else:
print("None") | 14 | 14 | 183 | 186 | S = eval(input())
import string
S = list(sorted(S))
T = string.ascii_lowercase
for t in T:
if t not in S:
print(t)
break
else:
print("None")
| S = eval(input())
import string
letters = string.ascii_lowercase
S = set(sorted(S))
for l in letters:
if l not in S:
print(l)
break
else:
print("None")
| false | 0 | [
"-S = list(sorted(S))",
"-T = string.ascii_lowercase",
"-for t in T:",
"- if t not in S:",
"- print(t)",
"+letters = string.ascii_lowercase",
"+S = set(sorted(S))",
"+for l in letters:",
"+ if l not in S:",
"+ print(l)"
] | false | 0.037571 | 0.075108 | 0.500232 | [
"s329954765",
"s015584234"
] |
u674588203 | p03617 | python | s502695862 | s891290508 | 30 | 27 | 9,296 | 9,152 | Accepted | Accepted | 10 | # AtCoder Grand Contest 019
# A - Ice Tea Store
def f(Q,H,S,D,N,M):
QQ=Q
QH=H/2
QS=S/4
QD=D/8
if N==0:
return M
if N==1:
if QQ==min(QQ,QH,QS):
return M+(4*Q)
if QH==min(QQ,QH,QS):
return M+(2*H)
if QS==min(QQ,QH,QS):
return M+(S)
else:
if QQ==min(QQ,QH,QS,QD):
return M+4*Q*N
if QH==min(QQ,QH,QS,QD):
return M+2*H*N
if QS==min(QQ,QH,QS,QD):
return M+S*N
if QD==min(QQ,QH,QS,QD):
if N%2==0:
return M+(N//2)*D
else:
return f(Q,H,S,D,1,M+(N//2)*D)
Q,H,S,D=list(map(int,input().split()))
N=int(eval(input()))
print((f(Q,H,S,D,N,0))) | Q,H,S,D=list(map(int,input().split()))
N=int(eval(input()))
one=min (4*Q,2*H,S)
if N==1:
print(one)
else :
if 2*one<=D:
print((N*one))
else:
if N%2==0:
print(((N//2)*D))
else:
print(((N//2)*D+one)) | 44 | 14 | 826 | 253 | # AtCoder Grand Contest 019
# A - Ice Tea Store
def f(Q, H, S, D, N, M):
QQ = Q
QH = H / 2
QS = S / 4
QD = D / 8
if N == 0:
return M
if N == 1:
if QQ == min(QQ, QH, QS):
return M + (4 * Q)
if QH == min(QQ, QH, QS):
return M + (2 * H)
if QS == min(QQ, QH, QS):
return M + (S)
else:
if QQ == min(QQ, QH, QS, QD):
return M + 4 * Q * N
if QH == min(QQ, QH, QS, QD):
return M + 2 * H * N
if QS == min(QQ, QH, QS, QD):
return M + S * N
if QD == min(QQ, QH, QS, QD):
if N % 2 == 0:
return M + (N // 2) * D
else:
return f(Q, H, S, D, 1, M + (N // 2) * D)
Q, H, S, D = list(map(int, input().split()))
N = int(eval(input()))
print((f(Q, H, S, D, N, 0)))
| Q, H, S, D = list(map(int, input().split()))
N = int(eval(input()))
one = min(4 * Q, 2 * H, S)
if N == 1:
print(one)
else:
if 2 * one <= D:
print((N * one))
else:
if N % 2 == 0:
print(((N // 2) * D))
else:
print(((N // 2) * D + one))
| false | 68.181818 | [
"-# AtCoder Grand Contest 019",
"-# A - Ice Tea Store",
"-def f(Q, H, S, D, N, M):",
"- QQ = Q",
"- QH = H / 2",
"- QS = S / 4",
"- QD = D / 8",
"- if N == 0:",
"- return M",
"- if N == 1:",
"- if QQ == min(QQ, QH, QS):",
"- return M + (4 * Q)",
"- if QH == min(QQ, QH, QS):",
"- return M + (2 * H)",
"- if QS == min(QQ, QH, QS):",
"- return M + (S)",
"- else:",
"- if QQ == min(QQ, QH, QS, QD):",
"- return M + 4 * Q * N",
"- if QH == min(QQ, QH, QS, QD):",
"- return M + 2 * H * N",
"- if QS == min(QQ, QH, QS, QD):",
"- return M + S * N",
"- if QD == min(QQ, QH, QS, QD):",
"- if N % 2 == 0:",
"- return M + (N // 2) * D",
"- else:",
"- return f(Q, H, S, D, 1, M + (N // 2) * D)",
"-",
"-",
"-print((f(Q, H, S, D, N, 0)))",
"+one = min(4 * Q, 2 * H, S)",
"+if N == 1:",
"+ print(one)",
"+else:",
"+ if 2 * one <= D:",
"+ print((N * one))",
"+ else:",
"+ if N % 2 == 0:",
"+ print(((N // 2) * D))",
"+ else:",
"+ print(((N // 2) * D + one))"
] | false | 0.03662 | 0.034503 | 1.061355 | [
"s502695862",
"s891290508"
] |
u131406572 | p03160 | python | s608425216 | s662909549 | 241 | 146 | 52,208 | 13,928 | Accepted | Accepted | 39.42 | n=int(eval(input()))
h=list(map(int,input().split()))
min_cost=[0]*n
min_cost[0]=0
min_cost[1]=abs(h[1]-h[0])
for i in range(2,n):
min_cost[i]=min(min_cost[i-1]+abs(h[i]-h[i-1]),min_cost[i-2]+abs(h[i]-h[i-2]))
print((min_cost[-1])) | #dp-a
n=int(eval(input()))
h=list(map(int,input().split()))
dp=[0]*n
for i in range(n):
if i==0:dp[0]=0
elif i==1:dp[1]=abs(h[0]-h[1])
else:
dp[i]=min(dp[i-2]+abs(h[i]-h[i-2]),dp[i-1]+abs(h[i]-h[i-1]))
print((dp[n-1])) | 8 | 10 | 234 | 239 | n = int(eval(input()))
h = list(map(int, input().split()))
min_cost = [0] * n
min_cost[0] = 0
min_cost[1] = abs(h[1] - h[0])
for i in range(2, n):
min_cost[i] = min(
min_cost[i - 1] + abs(h[i] - h[i - 1]), min_cost[i - 2] + abs(h[i] - h[i - 2])
)
print((min_cost[-1]))
| # dp-a
n = int(eval(input()))
h = list(map(int, input().split()))
dp = [0] * n
for i in range(n):
if i == 0:
dp[0] = 0
elif i == 1:
dp[1] = abs(h[0] - h[1])
else:
dp[i] = min(dp[i - 2] + abs(h[i] - h[i - 2]), dp[i - 1] + abs(h[i] - h[i - 1]))
print((dp[n - 1]))
| false | 20 | [
"+# dp-a",
"-min_cost = [0] * n",
"-min_cost[0] = 0",
"-min_cost[1] = abs(h[1] - h[0])",
"-for i in range(2, n):",
"- min_cost[i] = min(",
"- min_cost[i - 1] + abs(h[i] - h[i - 1]), min_cost[i - 2] + abs(h[i] - h[i - 2])",
"- )",
"-print((min_cost[-1]))",
"+dp = [0] * n",
"+for i in range(n):",
"+ if i == 0:",
"+ dp[0] = 0",
"+ elif i == 1:",
"+ dp[1] = abs(h[0] - h[1])",
"+ else:",
"+ dp[i] = min(dp[i - 2] + abs(h[i] - h[i - 2]), dp[i - 1] + abs(h[i] - h[i - 1]))",
"+print((dp[n - 1]))"
] | false | 0.038183 | 0.03795 | 1.006122 | [
"s608425216",
"s662909549"
] |
u280552586 | p03363 | python | s090822216 | s015827582 | 230 | 211 | 43,208 | 43,336 | Accepted | Accepted | 8.26 | from collections import Counter
n = int(eval(input()))
A = list(map(int, input().split()))
cum_sum = [0] * (n+1)
for i in range(n):
cum_sum[i+1] = cum_sum[i] + A[i]
C = Counter(cum_sum[1:])
ans = 0
for k, v in list(C.items()):
if k == 0:
ans += v + (v*(v-1)//2)
else:
ans += (v*(v-1)//2)
print(ans)
| from collections import Counter
n = int(eval(input()))
A = list(map(int, input().split()))
cum_sum = [0] * (n+1)
for i in range(n):
cum_sum[i+1] = cum_sum[i] + A[i]
C = Counter(cum_sum[1:])
ans = C[0]
for k, v in list(C.items()):
ans += (v*(v-1)//2)
print(ans)
| 15 | 12 | 330 | 269 | from collections import Counter
n = int(eval(input()))
A = list(map(int, input().split()))
cum_sum = [0] * (n + 1)
for i in range(n):
cum_sum[i + 1] = cum_sum[i] + A[i]
C = Counter(cum_sum[1:])
ans = 0
for k, v in list(C.items()):
if k == 0:
ans += v + (v * (v - 1) // 2)
else:
ans += v * (v - 1) // 2
print(ans)
| from collections import Counter
n = int(eval(input()))
A = list(map(int, input().split()))
cum_sum = [0] * (n + 1)
for i in range(n):
cum_sum[i + 1] = cum_sum[i] + A[i]
C = Counter(cum_sum[1:])
ans = C[0]
for k, v in list(C.items()):
ans += v * (v - 1) // 2
print(ans)
| false | 20 | [
"-ans = 0",
"+ans = C[0]",
"- if k == 0:",
"- ans += v + (v * (v - 1) // 2)",
"- else:",
"- ans += v * (v - 1) // 2",
"+ ans += v * (v - 1) // 2"
] | false | 0.107009 | 0.118583 | 0.902399 | [
"s090822216",
"s015827582"
] |
u177411511 | p03835 | python | s313352116 | s789147695 | 1,519 | 258 | 3,896 | 42,108 | Accepted | Accepted | 83.02 | import sys
import copy
import string
from _bisect import *
from collections import *
from operator import itemgetter
from math import factorial
"""
from fractions import gcd
def lcm(x, y):
return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()
k, s = na()
ct = 0
for x in range(k+1):
for y in range(k+1):
z = s - x - y
if 0 <= z <= k:
ct += 1
print(ct)
| import sys
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()
k, s = na()
ct = 0
for x in range(k+1):
for y in range(k+1):
z = s - x - y
if 0 <= z <= k:
ct += 1
print(ct)
| 34 | 24 | 534 | 311 | import sys
import copy
import string
from _bisect import *
from collections import *
from operator import itemgetter
from math import factorial
"""
from fractions import gcd
def lcm(x, y):
return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()
k, s = na()
ct = 0
for x in range(k + 1):
for y in range(k + 1):
z = s - x - y
if 0 <= z <= k:
ct += 1
print(ct)
| import sys
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()
k, s = na()
ct = 0
for x in range(k + 1):
for y in range(k + 1):
z = s - x - y
if 0 <= z <= k:
ct += 1
print(ct)
| false | 29.411765 | [
"-import copy",
"-import string",
"-from _bisect import *",
"-from collections import *",
"-from operator import itemgetter",
"-from math import factorial",
"-\"\"\"",
"-from fractions import gcd",
"-def lcm(x, y):",
"- return (x * y) // gcd(x, y)",
"-\"\"\""
] | false | 0.083941 | 0.04465 | 1.87998 | [
"s313352116",
"s789147695"
] |
u499381410 | p03822 | python | s872704239 | s755005567 | 682 | 388 | 240,304 | 65,848 | Accepted | Accepted | 43.11 | from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gamma, log
from operator import mul
from functools import reduce
from copy import deepcopy
sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7
n = I()
G = [[] for _ in range(n)]
win_against = [[] for _ in range(n)]
A = IR(n - 1)
for i in range(n - 1):
win_against[A[i] - 1] += [i + 1]
def f(x):
ret = 0
s = sorted([f(u) for u in win_against[x]])
for k in range(1, len(win_against[x]) + 1):
ret = max(ret, s.pop() + k)
return ret
print((f(0)))
| from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gamma, log
from operator import mul
from functools import reduce
from copy import deepcopy
sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7
n = I()
G = [[] for _ in range(n)]
win_against = [[] for _ in range(n)]
A = [-1]
for i in range(n - 1):
a = I()
A += [a - 1]
win_against[a - 1] += [i + 1]
in_degree = [len(i) for i in win_against]
dp = [0] * n
dq = deque()
for i in range(n):
if not in_degree[i]:
dq += ([i])
order = []
while dq:
x = dq.popleft()
order += [x]
if x == 0:
break
in_degree[A[x]] -= 1
if in_degree[A[x]] == 0:
dq += [A[x]]
for i in order:
ret = 0
s = sorted([dp[k] for k in win_against[i]])
for l in range(1, len(win_against[i]) + 1):
ret = max(ret, l + s.pop())
dp[i] = ret
print((dp[0]))
| 43 | 64 | 1,422 | 1,772 | from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gamma, log
from operator import mul
from functools import reduce
from copy import deepcopy
sys.setrecursionlimit(2147483647)
INF = 10**20
def LI():
return list(map(int, sys.stdin.buffer.readline().split()))
def I():
return int(sys.stdin.buffer.readline())
def LS():
return sys.stdin.buffer.readline().rstrip().decode("utf-8").split()
def S():
return sys.stdin.buffer.readline().rstrip().decode("utf-8")
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
def SRL(n):
return [list(S()) for i in range(n)]
def MSRL(n):
return [[int(j) for j in list(S())] for i in range(n)]
mod = 10**9 + 7
n = I()
G = [[] for _ in range(n)]
win_against = [[] for _ in range(n)]
A = IR(n - 1)
for i in range(n - 1):
win_against[A[i] - 1] += [i + 1]
def f(x):
ret = 0
s = sorted([f(u) for u in win_against[x]])
for k in range(1, len(win_against[x]) + 1):
ret = max(ret, s.pop() + k)
return ret
print((f(0)))
| from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gamma, log
from operator import mul
from functools import reduce
from copy import deepcopy
sys.setrecursionlimit(2147483647)
INF = 10**20
def LI():
return list(map(int, sys.stdin.buffer.readline().split()))
def I():
return int(sys.stdin.buffer.readline())
def LS():
return sys.stdin.buffer.readline().rstrip().decode("utf-8").split()
def S():
return sys.stdin.buffer.readline().rstrip().decode("utf-8")
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
def SRL(n):
return [list(S()) for i in range(n)]
def MSRL(n):
return [[int(j) for j in list(S())] for i in range(n)]
mod = 10**9 + 7
n = I()
G = [[] for _ in range(n)]
win_against = [[] for _ in range(n)]
A = [-1]
for i in range(n - 1):
a = I()
A += [a - 1]
win_against[a - 1] += [i + 1]
in_degree = [len(i) for i in win_against]
dp = [0] * n
dq = deque()
for i in range(n):
if not in_degree[i]:
dq += [i]
order = []
while dq:
x = dq.popleft()
order += [x]
if x == 0:
break
in_degree[A[x]] -= 1
if in_degree[A[x]] == 0:
dq += [A[x]]
for i in order:
ret = 0
s = sorted([dp[k] for k in win_against[i]])
for l in range(1, len(win_against[i]) + 1):
ret = max(ret, l + s.pop())
dp[i] = ret
print((dp[0]))
| false | 32.8125 | [
"-A = IR(n - 1)",
"+A = [-1]",
"- win_against[A[i] - 1] += [i + 1]",
"-",
"-",
"-def f(x):",
"+ a = I()",
"+ A += [a - 1]",
"+ win_against[a - 1] += [i + 1]",
"+in_degree = [len(i) for i in win_against]",
"+dp = [0] * n",
"+dq = deque()",
"+for i in range(n):",
"+ if not in_degree[i]:",
"+ dq += [i]",
"+order = []",
"+while dq:",
"+ x = dq.popleft()",
"+ order += [x]",
"+ if x == 0:",
"+ break",
"+ in_degree[A[x]] -= 1",
"+ if in_degree[A[x]] == 0:",
"+ dq += [A[x]]",
"+for i in order:",
"- s = sorted([f(u) for u in win_against[x]])",
"- for k in range(1, len(win_against[x]) + 1):",
"- ret = max(ret, s.pop() + k)",
"- return ret",
"-",
"-",
"-print((f(0)))",
"+ s = sorted([dp[k] for k in win_against[i]])",
"+ for l in range(1, len(win_against[i]) + 1):",
"+ ret = max(ret, l + s.pop())",
"+ dp[i] = ret",
"+print((dp[0]))"
] | false | 0.107822 | 0.044348 | 2.431261 | [
"s872704239",
"s755005567"
] |
u802963389 | p03645 | python | s083441253 | s351316264 | 1,076 | 754 | 91,736 | 58,884 | Accepted | Accepted | 29.93 | N, M = list(map(int, input().split()))
ab = [sorted(list(map(int, input().split()))) for _ in range(M)]
fst = []
scnd = {}
for i in ab:
if i[0]==1:
fst.append(i[1])
if N in i:
idx = i.index(N)
scnd[i[1-idx]] = 0
#print(scnd,fst)
for j in fst:
if j in scnd:
print("POSSIBLE")
exit()
print("IMPOSSIBLE")
| n, m = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(m)]
cont_1 = set()
cont_n = set()
for ab in AB:
a, b = ab
if 1 in ab:
cont_1.add(a)
cont_1.add(b)
if n in ab:
cont_n.add(a)
cont_n.add(b)
if cont_1 & cont_n:
print("POSSIBLE")
else:
print("IMPOSSIBLE") | 21 | 19 | 352 | 334 | N, M = list(map(int, input().split()))
ab = [sorted(list(map(int, input().split()))) for _ in range(M)]
fst = []
scnd = {}
for i in ab:
if i[0] == 1:
fst.append(i[1])
if N in i:
idx = i.index(N)
scnd[i[1 - idx]] = 0
# print(scnd,fst)
for j in fst:
if j in scnd:
print("POSSIBLE")
exit()
print("IMPOSSIBLE")
| n, m = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(m)]
cont_1 = set()
cont_n = set()
for ab in AB:
a, b = ab
if 1 in ab:
cont_1.add(a)
cont_1.add(b)
if n in ab:
cont_n.add(a)
cont_n.add(b)
if cont_1 & cont_n:
print("POSSIBLE")
else:
print("IMPOSSIBLE")
| false | 9.52381 | [
"-N, M = list(map(int, input().split()))",
"-ab = [sorted(list(map(int, input().split()))) for _ in range(M)]",
"-fst = []",
"-scnd = {}",
"-for i in ab:",
"- if i[0] == 1:",
"- fst.append(i[1])",
"- if N in i:",
"- idx = i.index(N)",
"- scnd[i[1 - idx]] = 0",
"-# print(scnd,fst)",
"-for j in fst:",
"- if j in scnd:",
"- print(\"POSSIBLE\")",
"- exit()",
"-print(\"IMPOSSIBLE\")",
"+n, m = list(map(int, input().split()))",
"+AB = [list(map(int, input().split())) for _ in range(m)]",
"+cont_1 = set()",
"+cont_n = set()",
"+for ab in AB:",
"+ a, b = ab",
"+ if 1 in ab:",
"+ cont_1.add(a)",
"+ cont_1.add(b)",
"+ if n in ab:",
"+ cont_n.add(a)",
"+ cont_n.add(b)",
"+if cont_1 & cont_n:",
"+ print(\"POSSIBLE\")",
"+else:",
"+ print(\"IMPOSSIBLE\")"
] | false | 0.054764 | 0.050981 | 1.074204 | [
"s083441253",
"s351316264"
] |
u932465688 | p03127 | python | s492956813 | s984030433 | 258 | 112 | 14,224 | 15,020 | Accepted | Accepted | 56.59 | N = int(eval(input()))
L = list(map(int,input().split()))
L.sort()
def gcd(x,y):
while y != 0:
k = x
x = y
y = k%y
return x
G = gcd(L[0],L[1])
for i in range(1,N-1):
if G >= gcd(L[i],L[i+1]):
G = gcd(L[i],L[i+1])
print(G) | N = int(eval(input()))
L = list(map(int,input().split()))
L.sort()
def gcd(x,y):
while y != 0:
k = x
x = y
y = k%y
return x
cur = L[0]
for i in range(N):
cur = gcd(cur,L[i])
print(cur) | 14 | 13 | 250 | 209 | N = int(eval(input()))
L = list(map(int, input().split()))
L.sort()
def gcd(x, y):
while y != 0:
k = x
x = y
y = k % y
return x
G = gcd(L[0], L[1])
for i in range(1, N - 1):
if G >= gcd(L[i], L[i + 1]):
G = gcd(L[i], L[i + 1])
print(G)
| N = int(eval(input()))
L = list(map(int, input().split()))
L.sort()
def gcd(x, y):
while y != 0:
k = x
x = y
y = k % y
return x
cur = L[0]
for i in range(N):
cur = gcd(cur, L[i])
print(cur)
| false | 7.142857 | [
"-G = gcd(L[0], L[1])",
"-for i in range(1, N - 1):",
"- if G >= gcd(L[i], L[i + 1]):",
"- G = gcd(L[i], L[i + 1])",
"-print(G)",
"+cur = L[0]",
"+for i in range(N):",
"+ cur = gcd(cur, L[i])",
"+print(cur)"
] | false | 0.037788 | 0.037774 | 1.000389 | [
"s492956813",
"s984030433"
] |
u811817592 | p02756 | python | s768822522 | s113286058 | 1,929 | 731 | 4,600 | 4,596 | Accepted | Accepted | 62.1 | # -*- coding: utf-8 -*-
S = str(eval(input()))
Q = int(eval(input()))
rev_flag = 1
head_str = ""
tail_str = ""
for _ in range(Q):
query = list(map(str, input().split()))
if query[0] == "1":
rev_flag *= -1
else:
h_or_t_flag = 1 if query[1] == "1" else -1
h_or_t_flag *= rev_flag
if h_or_t_flag == 1:
head_str = query[2] + head_str
else:
tail_str += query[2]
ans = head_str + S + tail_str
print((ans if rev_flag == 1 else ans[::-1])) | # -*- coding: utf-8 -*-
S = str(eval(input()))
Q = int(eval(input()))
rev_flag = 1
head_str = ""
tail_str = ""
for _ in range(Q):
query = list(map(str, input().split()))
if query[0] == "1":
rev_flag *= -1
else:
h_or_t_flag = 1 if query[1] == "1" else -1
h_or_t_flag *= rev_flag
if h_or_t_flag == 1:
head_str += query[2]
else:
tail_str += query[2]
ans = head_str[::-1] + S + tail_str
print((ans if rev_flag == 1 else ans[::-1])) | 22 | 22 | 525 | 521 | # -*- coding: utf-8 -*-
S = str(eval(input()))
Q = int(eval(input()))
rev_flag = 1
head_str = ""
tail_str = ""
for _ in range(Q):
query = list(map(str, input().split()))
if query[0] == "1":
rev_flag *= -1
else:
h_or_t_flag = 1 if query[1] == "1" else -1
h_or_t_flag *= rev_flag
if h_or_t_flag == 1:
head_str = query[2] + head_str
else:
tail_str += query[2]
ans = head_str + S + tail_str
print((ans if rev_flag == 1 else ans[::-1]))
| # -*- coding: utf-8 -*-
S = str(eval(input()))
Q = int(eval(input()))
rev_flag = 1
head_str = ""
tail_str = ""
for _ in range(Q):
query = list(map(str, input().split()))
if query[0] == "1":
rev_flag *= -1
else:
h_or_t_flag = 1 if query[1] == "1" else -1
h_or_t_flag *= rev_flag
if h_or_t_flag == 1:
head_str += query[2]
else:
tail_str += query[2]
ans = head_str[::-1] + S + tail_str
print((ans if rev_flag == 1 else ans[::-1]))
| false | 0 | [
"- head_str = query[2] + head_str",
"+ head_str += query[2]",
"-ans = head_str + S + tail_str",
"+ans = head_str[::-1] + S + tail_str"
] | false | 0.075483 | 0.046315 | 1.629758 | [
"s768822522",
"s113286058"
] |
u906501980 | p03354 | python | s191827523 | s008450991 | 579 | 514 | 28,900 | 28,900 | Accepted | Accepted | 11.23 | N, M = list(map(int, input().split()))
p = [int(i) for i in input().split()]
graph = [[] for _ in range(N+1)]
group = [0]*(N+1)
ans = 0
for _ in range(M):
x, y = (int(i) for i in input().split())
graph[x].append(y)
graph[y].append(x)
for i, num in enumerate(p, 1):
space = [i]
for point in space:
if group[point]:
continue
group[point] = i
space.extend(graph[point])
ans += (group[num] == group[i])
print(ans) | N, M = list(map(int, input().split()))
p = [int(i) for i in input().split()]
graph = [[] for _ in range(N+1)]
group = [0]*(N+1)
ans = 0
for _ in range(M):
x, y = list(map(int, input().split()))
graph[x].append(y)
graph[y].append(x)
for i, num in enumerate(p, 1):
space = [i]
for point in space:
if not group[point]:
group[point] = i
space.extend(graph[point])
ans += (group[num] == group[i])
print(ans) | 18 | 17 | 480 | 462 | N, M = list(map(int, input().split()))
p = [int(i) for i in input().split()]
graph = [[] for _ in range(N + 1)]
group = [0] * (N + 1)
ans = 0
for _ in range(M):
x, y = (int(i) for i in input().split())
graph[x].append(y)
graph[y].append(x)
for i, num in enumerate(p, 1):
space = [i]
for point in space:
if group[point]:
continue
group[point] = i
space.extend(graph[point])
ans += group[num] == group[i]
print(ans)
| N, M = list(map(int, input().split()))
p = [int(i) for i in input().split()]
graph = [[] for _ in range(N + 1)]
group = [0] * (N + 1)
ans = 0
for _ in range(M):
x, y = list(map(int, input().split()))
graph[x].append(y)
graph[y].append(x)
for i, num in enumerate(p, 1):
space = [i]
for point in space:
if not group[point]:
group[point] = i
space.extend(graph[point])
ans += group[num] == group[i]
print(ans)
| false | 5.555556 | [
"- x, y = (int(i) for i in input().split())",
"+ x, y = list(map(int, input().split()))",
"- if group[point]:",
"- continue",
"- group[point] = i",
"- space.extend(graph[point])",
"+ if not group[point]:",
"+ group[point] = i",
"+ space.extend(graph[point])"
] | false | 0.075565 | 0.038442 | 1.96569 | [
"s191827523",
"s008450991"
] |
u888092736 | p02819 | python | s754108946 | s003761573 | 105 | 17 | 7,496 | 2,940 | Accepted | Accepted | 83.81 | from bisect import bisect_left
def get_primes(n):
prime = []
limit = n ** 0.5
data = [i + 1 for i in range(1, n)]
while True:
p = data[0]
if limit <= p:
return prime + data
prime.append(p)
data = [e for e in data if e % p != 0]
X = int(eval(input()))
primes = get_primes(10 ** 5 + 3)
print((primes[bisect_left(primes, X)]))
| X = int(eval(input()))
while any(X % i == 0 for i in range(2, int(X ** 0.5) + 1)):
X += 1
print(X) | 18 | 4 | 397 | 99 | from bisect import bisect_left
def get_primes(n):
prime = []
limit = n**0.5
data = [i + 1 for i in range(1, n)]
while True:
p = data[0]
if limit <= p:
return prime + data
prime.append(p)
data = [e for e in data if e % p != 0]
X = int(eval(input()))
primes = get_primes(10**5 + 3)
print((primes[bisect_left(primes, X)]))
| X = int(eval(input()))
while any(X % i == 0 for i in range(2, int(X**0.5) + 1)):
X += 1
print(X)
| false | 77.777778 | [
"-from bisect import bisect_left",
"-",
"-",
"-def get_primes(n):",
"- prime = []",
"- limit = n**0.5",
"- data = [i + 1 for i in range(1, n)]",
"- while True:",
"- p = data[0]",
"- if limit <= p:",
"- return prime + data",
"- prime.append(p)",
"- data = [e for e in data if e % p != 0]",
"-",
"-",
"-primes = get_primes(10**5 + 3)",
"-print((primes[bisect_left(primes, X)]))",
"+while any(X % i == 0 for i in range(2, int(X**0.5) + 1)):",
"+ X += 1",
"+print(X)"
] | false | 0.106464 | 0.036961 | 2.880407 | [
"s754108946",
"s003761573"
] |
u367701763 | p02813 | python | s004757451 | s106985709 | 192 | 84 | 42,864 | 82,188 | Accepted | Accepted | 56.25 | from itertools import permutations
from collections import defaultdict
N = int(eval(input()))
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
res = 0
loop = 0
d = defaultdict(int)
for perm in permutations(list(range(1,N+1))):
d[perm] = loop
loop += 1
res = abs(d[P] - d[Q])
print(res) | from itertools import *
N = int(eval(input()))
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
dic = dict()
i = 0
for a in permutations(list(range(1,N+1)),N):
dic[a] = i
i += 1
print((abs(dic[P]-dic[Q]))) | 19 | 10 | 330 | 233 | from itertools import permutations
from collections import defaultdict
N = int(eval(input()))
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
res = 0
loop = 0
d = defaultdict(int)
for perm in permutations(list(range(1, N + 1))):
d[perm] = loop
loop += 1
res = abs(d[P] - d[Q])
print(res)
| from itertools import *
N = int(eval(input()))
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
dic = dict()
i = 0
for a in permutations(list(range(1, N + 1)), N):
dic[a] = i
i += 1
print((abs(dic[P] - dic[Q])))
| false | 47.368421 | [
"-from itertools import permutations",
"-from collections import defaultdict",
"+from itertools import *",
"-res = 0",
"-loop = 0",
"-d = defaultdict(int)",
"-for perm in permutations(list(range(1, N + 1))):",
"- d[perm] = loop",
"- loop += 1",
"-res = abs(d[P] - d[Q])",
"-print(res)",
"+dic = dict()",
"+i = 0",
"+for a in permutations(list(range(1, N + 1)), N):",
"+ dic[a] = i",
"+ i += 1",
"+print((abs(dic[P] - dic[Q])))"
] | false | 0.077302 | 0.171527 | 0.450672 | [
"s004757451",
"s106985709"
] |
u320567105 | p03146 | python | s538581688 | s360080936 | 64 | 17 | 11,160 | 3,060 | Accepted | Accepted | 73.44 | ri = lambda: int(eval(input()))
rl = lambda: list(map(int,input().split()))
def f(n):
if n%2 == 0:
return n/2
else:
return 3*n+1
s = ri()
t = [0 for _ in range(1000000)]
ans = 0
a = s
for i in range(1,1000000):
if t[int(a)] == 1:
ans = i
break
else:
t[int(a)] = 1
a = f(a)
print(ans) | ri = lambda: int(eval(input()))
rl = lambda: list(map(int,input().split()))
def f(n):
if n%2==0:
return n//2
else:
return 3*n+1
s = ri()
used = set()
ans = 1
while True:
if s in used:
break
used.add(s)
ans += 1
s = f(s)
print(ans) | 24 | 20 | 365 | 294 | ri = lambda: int(eval(input()))
rl = lambda: list(map(int, input().split()))
def f(n):
if n % 2 == 0:
return n / 2
else:
return 3 * n + 1
s = ri()
t = [0 for _ in range(1000000)]
ans = 0
a = s
for i in range(1, 1000000):
if t[int(a)] == 1:
ans = i
break
else:
t[int(a)] = 1
a = f(a)
print(ans)
| ri = lambda: int(eval(input()))
rl = lambda: list(map(int, input().split()))
def f(n):
if n % 2 == 0:
return n // 2
else:
return 3 * n + 1
s = ri()
used = set()
ans = 1
while True:
if s in used:
break
used.add(s)
ans += 1
s = f(s)
print(ans)
| false | 16.666667 | [
"- return n / 2",
"+ return n // 2",
"-t = [0 for _ in range(1000000)]",
"-ans = 0",
"-a = s",
"-for i in range(1, 1000000):",
"- if t[int(a)] == 1:",
"- ans = i",
"+used = set()",
"+ans = 1",
"+while True:",
"+ if s in used:",
"- else:",
"- t[int(a)] = 1",
"- a = f(a)",
"+ used.add(s)",
"+ ans += 1",
"+ s = f(s)"
] | false | 0.092532 | 0.041193 | 2.246286 | [
"s538581688",
"s360080936"
] |
u933341648 | p03262 | python | s971008453 | s142914748 | 82 | 61 | 11,096 | 11,180 | Accepted | Accepted | 25.61 | def gcd(a, b):
while a > 0:
if a < b:
a, b = b, a
a = a % b
return b
n, x = list(map(int, input().split()))
town = list(map(int, input().split()))
distance = (abs(x-y) for y in town)
res = next(distance)
for d in distance:
res = gcd(res, d)
print(res)
| def gcd(a, b):
while a > 0:
if a < b:
a, b = b, a
a = a % b
return b
n, x = list(map(int, input().split()))
town = list(map(int, input().split()))
distance = (abs(x-y) for y in town)
res = next(distance)
for d in distance:
if d % res != 0:
res = gcd(res, d)
print(res)
| 16 | 17 | 298 | 324 | def gcd(a, b):
while a > 0:
if a < b:
a, b = b, a
a = a % b
return b
n, x = list(map(int, input().split()))
town = list(map(int, input().split()))
distance = (abs(x - y) for y in town)
res = next(distance)
for d in distance:
res = gcd(res, d)
print(res)
| def gcd(a, b):
while a > 0:
if a < b:
a, b = b, a
a = a % b
return b
n, x = list(map(int, input().split()))
town = list(map(int, input().split()))
distance = (abs(x - y) for y in town)
res = next(distance)
for d in distance:
if d % res != 0:
res = gcd(res, d)
print(res)
| false | 5.882353 | [
"- res = gcd(res, d)",
"+ if d % res != 0:",
"+ res = gcd(res, d)"
] | false | 0.040472 | 0.037669 | 1.074399 | [
"s971008453",
"s142914748"
] |
u488127128 | p03107 | python | s380266743 | s239660328 | 45 | 18 | 3,956 | 3,188 | Accepted | Accepted | 60 | S = eval(input())
a = []
for s in S:
if not a:
a.append(s)
continue
if s != a[-1]:
a.pop()
else:
a.append(s)
print((len(S)-len(a))) | s = eval(input())
a = s.count('0')
b = len(s) - a
print((min(a,b)*2)) | 11 | 4 | 177 | 64 | S = eval(input())
a = []
for s in S:
if not a:
a.append(s)
continue
if s != a[-1]:
a.pop()
else:
a.append(s)
print((len(S) - len(a)))
| s = eval(input())
a = s.count("0")
b = len(s) - a
print((min(a, b) * 2))
| false | 63.636364 | [
"-S = eval(input())",
"-a = []",
"-for s in S:",
"- if not a:",
"- a.append(s)",
"- continue",
"- if s != a[-1]:",
"- a.pop()",
"- else:",
"- a.append(s)",
"-print((len(S) - len(a)))",
"+s = eval(input())",
"+a = s.count(\"0\")",
"+b = len(s) - a",
"+print((min(a, b) * 2))"
] | false | 0.035617 | 0.035747 | 0.996359 | [
"s380266743",
"s239660328"
] |
u645250356 | p02781 | python | s309318458 | s178491794 | 301 | 141 | 66,156 | 77,224 | Accepted | Accepted | 53.16 | from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,pprint,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
n = inp()
K = inp()
s = list(str(n))
l = len(s)
dp = [[[0 for _ in range(2)] for j in range(4)] for i in range(l+5)]
dp[0][0][0] = 1
for i in range(l):
nd = int(s[i])
# print(nd)
for j in range(4):
for k in range(2):
for d in range(10):
ni = i+1; nj = j; nk = k
if d>0: nj += 1
if nj >= 4: continue
if k == 0:
if d < nd: nk += 1
elif d > nd: continue
dp[ni][nj][nk] += dp[i][j][k]
# print(dp)
print((sum(dp[l][K]))) | from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right
import sys,math,itertools,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
s = eval(input())
n = len(s)
K = inp()
dp = [[[0 for i in range(5)] for j in range(2)] for k in range(n+1)]
# dp[i][j][k] j:0 kaku j:1 mikaku , k:kosuu
dp[0][1][0] = 1
for i,x in enumerate(s):
x = int(x)
for k in range(4):
dp[i+1][0][k] += dp[i][0][k]
dp[i+1][0][k+1] += dp[i][0][k]*9 + dp[i][1][k]*max(0,(x-1))
if x != 0:
dp[i+1][0][k] += dp[i][1][k]
dp[i+1][1][k+1] = dp[i][1][k]
if k == 0: dp[i+1][1][k] = 0
else:
dp[i+1][1][k] = dp[i][1][k]
for j in range(2):
dp[i+1][j][k] %= mod
# print(dp[i+1][0])
# print(dp[i+1][1])
# print()
print((dp[-1][0][K] + dp[-1][1][K]))
| 33 | 35 | 914 | 1,058 | from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heapify
import sys, bisect, math, itertools, pprint, fractions
sys.setrecursionlimit(10**8)
mod = 10**9 + 7
INF = float("inf")
def inp():
return int(sys.stdin.readline())
def inpl():
return list(map(int, sys.stdin.readline().split()))
n = inp()
K = inp()
s = list(str(n))
l = len(s)
dp = [[[0 for _ in range(2)] for j in range(4)] for i in range(l + 5)]
dp[0][0][0] = 1
for i in range(l):
nd = int(s[i])
# print(nd)
for j in range(4):
for k in range(2):
for d in range(10):
ni = i + 1
nj = j
nk = k
if d > 0:
nj += 1
if nj >= 4:
continue
if k == 0:
if d < nd:
nk += 1
elif d > nd:
continue
dp[ni][nj][nk] += dp[i][j][k]
# print(dp)
print((sum(dp[l][K])))
| from collections import Counter, defaultdict, deque
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right
import sys, math, itertools, fractions
sys.setrecursionlimit(10**8)
mod = 10**9 + 7
INF = float("inf")
def inp():
return int(sys.stdin.readline())
def inpl():
return list(map(int, sys.stdin.readline().split()))
s = eval(input())
n = len(s)
K = inp()
dp = [[[0 for i in range(5)] for j in range(2)] for k in range(n + 1)]
# dp[i][j][k] j:0 kaku j:1 mikaku , k:kosuu
dp[0][1][0] = 1
for i, x in enumerate(s):
x = int(x)
for k in range(4):
dp[i + 1][0][k] += dp[i][0][k]
dp[i + 1][0][k + 1] += dp[i][0][k] * 9 + dp[i][1][k] * max(0, (x - 1))
if x != 0:
dp[i + 1][0][k] += dp[i][1][k]
dp[i + 1][1][k + 1] = dp[i][1][k]
if k == 0:
dp[i + 1][1][k] = 0
else:
dp[i + 1][1][k] = dp[i][1][k]
for j in range(2):
dp[i + 1][j][k] %= mod
# print(dp[i+1][0])
# print(dp[i+1][1])
# print()
print((dp[-1][0][K] + dp[-1][1][K]))
| false | 5.714286 | [
"-from heapq import heappop, heappush, heapify",
"-import sys, bisect, math, itertools, pprint, fractions",
"+from heapq import heappop, heappush",
"+from bisect import bisect_left, bisect_right",
"+import sys, math, itertools, fractions",
"-n = inp()",
"+s = eval(input())",
"+n = len(s)",
"-s = list(str(n))",
"-l = len(s)",
"-dp = [[[0 for _ in range(2)] for j in range(4)] for i in range(l + 5)]",
"-dp[0][0][0] = 1",
"-for i in range(l):",
"- nd = int(s[i])",
"- # print(nd)",
"- for j in range(4):",
"- for k in range(2):",
"- for d in range(10):",
"- ni = i + 1",
"- nj = j",
"- nk = k",
"- if d > 0:",
"- nj += 1",
"- if nj >= 4:",
"- continue",
"- if k == 0:",
"- if d < nd:",
"- nk += 1",
"- elif d > nd:",
"- continue",
"- dp[ni][nj][nk] += dp[i][j][k]",
"-# print(dp)",
"-print((sum(dp[l][K])))",
"+dp = [[[0 for i in range(5)] for j in range(2)] for k in range(n + 1)]",
"+# dp[i][j][k] j:0 kaku j:1 mikaku , k:kosuu",
"+dp[0][1][0] = 1",
"+for i, x in enumerate(s):",
"+ x = int(x)",
"+ for k in range(4):",
"+ dp[i + 1][0][k] += dp[i][0][k]",
"+ dp[i + 1][0][k + 1] += dp[i][0][k] * 9 + dp[i][1][k] * max(0, (x - 1))",
"+ if x != 0:",
"+ dp[i + 1][0][k] += dp[i][1][k]",
"+ dp[i + 1][1][k + 1] = dp[i][1][k]",
"+ if k == 0:",
"+ dp[i + 1][1][k] = 0",
"+ else:",
"+ dp[i + 1][1][k] = dp[i][1][k]",
"+ for j in range(2):",
"+ dp[i + 1][j][k] %= mod",
"+ # print(dp[i+1][0])",
"+ # print(dp[i+1][1])",
"+ # print()",
"+print((dp[-1][0][K] + dp[-1][1][K]))"
] | false | 0.068365 | 0.033037 | 2.069345 | [
"s309318458",
"s178491794"
] |
u124498235 | p03231 | python | s009752150 | s641192478 | 106 | 29 | 22,068 | 9,224 | Accepted | Accepted | 72.64 | from collections import defaultdict
import math
n,m = list(map(int, input().split()))
s = eval(input())
t = eval(input())
ans = int((n*m)/math.gcd(n,m))
d = defaultdict(int)
if n > m:
for i in range(n):
if i == 0:
d[1] = s[i]
else:
d[i*int(ans/n)+1] = s[i]
ng = 0
for i in range(m):
if i == 0:
if d[1] != t[i]:
ng += 1
else:
if d[i*int(ans/m)+1] != 0 and d[i*int(ans/m)+1] != t[i]:
ng += 1
else:
for i in range(m):
if i == 0:
d[1] = t[i]
else:
d[i*int(ans/m)+1] = t[i]
ng = 0
for i in range(n):
if i == 0:
if d[1] != s[i]:
ng += 1
else:
if d[i*int(ans/n)+1] != 0 and d[i*int(ans/n)+1] != s[i]:
ng += 1
if ng > 0:
print((-1))
else:
print (ans) | import math
n,m = list(map(int, input().split()))
s = eval(input())
t = eval(input())
ans = int((n*m)/math.gcd(n,m))
g = math.gcd(n,m)
for i in range(g):
if s[i*(n//g)] != t[i*(m//g)]:
print((-1))
exit()
print (ans) | 40 | 12 | 791 | 218 | from collections import defaultdict
import math
n, m = list(map(int, input().split()))
s = eval(input())
t = eval(input())
ans = int((n * m) / math.gcd(n, m))
d = defaultdict(int)
if n > m:
for i in range(n):
if i == 0:
d[1] = s[i]
else:
d[i * int(ans / n) + 1] = s[i]
ng = 0
for i in range(m):
if i == 0:
if d[1] != t[i]:
ng += 1
else:
if d[i * int(ans / m) + 1] != 0 and d[i * int(ans / m) + 1] != t[i]:
ng += 1
else:
for i in range(m):
if i == 0:
d[1] = t[i]
else:
d[i * int(ans / m) + 1] = t[i]
ng = 0
for i in range(n):
if i == 0:
if d[1] != s[i]:
ng += 1
else:
if d[i * int(ans / n) + 1] != 0 and d[i * int(ans / n) + 1] != s[i]:
ng += 1
if ng > 0:
print((-1))
else:
print(ans)
| import math
n, m = list(map(int, input().split()))
s = eval(input())
t = eval(input())
ans = int((n * m) / math.gcd(n, m))
g = math.gcd(n, m)
for i in range(g):
if s[i * (n // g)] != t[i * (m // g)]:
print((-1))
exit()
print(ans)
| false | 70 | [
"-from collections import defaultdict",
"-d = defaultdict(int)",
"-if n > m:",
"- for i in range(n):",
"- if i == 0:",
"- d[1] = s[i]",
"- else:",
"- d[i * int(ans / n) + 1] = s[i]",
"- ng = 0",
"- for i in range(m):",
"- if i == 0:",
"- if d[1] != t[i]:",
"- ng += 1",
"- else:",
"- if d[i * int(ans / m) + 1] != 0 and d[i * int(ans / m) + 1] != t[i]:",
"- ng += 1",
"-else:",
"- for i in range(m):",
"- if i == 0:",
"- d[1] = t[i]",
"- else:",
"- d[i * int(ans / m) + 1] = t[i]",
"- ng = 0",
"- for i in range(n):",
"- if i == 0:",
"- if d[1] != s[i]:",
"- ng += 1",
"- else:",
"- if d[i * int(ans / n) + 1] != 0 and d[i * int(ans / n) + 1] != s[i]:",
"- ng += 1",
"-if ng > 0:",
"- print((-1))",
"-else:",
"- print(ans)",
"+g = math.gcd(n, m)",
"+for i in range(g):",
"+ if s[i * (n // g)] != t[i * (m // g)]:",
"+ print((-1))",
"+ exit()",
"+print(ans)"
] | false | 0.038076 | 0.036664 | 1.038513 | [
"s009752150",
"s641192478"
] |
u223904637 | p03510 | python | s792764582 | s881183214 | 1,278 | 984 | 98,516 | 91,732 | Accepted | Accepted | 23 |
#####segfunc######
def segfunc(x,y):
return max(x,y)
def init(init_val):
#set_val
for i in range(n):
seg[i+num-1]=init_val[i]
#built
for i in range(num-2,-1,-1):
seg[i]=segfunc(seg[2*i+1],seg[2*i+2])
def update(k,x):
k+=num-1
seg[k]=x
while k+1:
k=(k-1)//2
seg[k]=segfunc(seg[k*2+1],seg[k*2+2])
def query(p,q):
if q<=p:
return ide_ele
p+=num-1
q+=num-2
res=ide_ele
while q-p>1:
if p&1==0:
res=segfunc(res,seg[p])
if q&1==1:
res=segfunc(res,seg[q])
q-=1
p=p//2
q=(q-1)//2
if p==q:
res=segfunc(res,seg[p])
else:
res=segfunc(segfunc(res,seg[p]),seg[q])
return res
ide_ele=-10**30
n=int(eval(input()))
num=2**(n-1).bit_length()
seg=[ide_ele]*2*num
x=[]
s=[]
for i in range(n):
p,q=list(map(int,input().split()))
x.append(p)
s.append(q)
r=[0]
for i in range(n):
r.append(r[-1]+s[i])
b=[]
for i in range(n):
b.append(r[i+1]-x[i])
init(b)
ans=0
for i in range(n):
ans=max(ans,query(i,n)-(r[i]-x[i]))
print(ans) | n=int(eval(input()))
x=[]
s=[]
for i in range(n):
p,q=list(map(int,input().split()))
x.append(p)
s.append(q)
r=[0]
for i in range(n):
r.append(r[-1]+s[i])
b=[]
for i in range(n):
b.append(r[i+1]-x[i])
a=[-10**30]*n
a[-1]=b[-1]
for i in range(n-1):
a[n-i-2]=max(a[n-i-1],b[n-i-2])
ans=0
for i in range(n):
ans=max(ans,a[i]-(r[i]-x[i]))
print(ans) | 61 | 23 | 1,372 | 385 | #####segfunc######
def segfunc(x, y):
return max(x, y)
def init(init_val):
# set_val
for i in range(n):
seg[i + num - 1] = init_val[i]
# built
for i in range(num - 2, -1, -1):
seg[i] = segfunc(seg[2 * i + 1], seg[2 * i + 2])
def update(k, x):
k += num - 1
seg[k] = x
while k + 1:
k = (k - 1) // 2
seg[k] = segfunc(seg[k * 2 + 1], seg[k * 2 + 2])
def query(p, q):
if q <= p:
return ide_ele
p += num - 1
q += num - 2
res = ide_ele
while q - p > 1:
if p & 1 == 0:
res = segfunc(res, seg[p])
if q & 1 == 1:
res = segfunc(res, seg[q])
q -= 1
p = p // 2
q = (q - 1) // 2
if p == q:
res = segfunc(res, seg[p])
else:
res = segfunc(segfunc(res, seg[p]), seg[q])
return res
ide_ele = -(10**30)
n = int(eval(input()))
num = 2 ** (n - 1).bit_length()
seg = [ide_ele] * 2 * num
x = []
s = []
for i in range(n):
p, q = list(map(int, input().split()))
x.append(p)
s.append(q)
r = [0]
for i in range(n):
r.append(r[-1] + s[i])
b = []
for i in range(n):
b.append(r[i + 1] - x[i])
init(b)
ans = 0
for i in range(n):
ans = max(ans, query(i, n) - (r[i] - x[i]))
print(ans)
| n = int(eval(input()))
x = []
s = []
for i in range(n):
p, q = list(map(int, input().split()))
x.append(p)
s.append(q)
r = [0]
for i in range(n):
r.append(r[-1] + s[i])
b = []
for i in range(n):
b.append(r[i + 1] - x[i])
a = [-(10**30)] * n
a[-1] = b[-1]
for i in range(n - 1):
a[n - i - 2] = max(a[n - i - 1], b[n - i - 2])
ans = 0
for i in range(n):
ans = max(ans, a[i] - (r[i] - x[i]))
print(ans)
| false | 62.295082 | [
"-#####segfunc######",
"-def segfunc(x, y):",
"- return max(x, y)",
"-",
"-",
"-def init(init_val):",
"- # set_val",
"- for i in range(n):",
"- seg[i + num - 1] = init_val[i]",
"- # built",
"- for i in range(num - 2, -1, -1):",
"- seg[i] = segfunc(seg[2 * i + 1], seg[2 * i + 2])",
"-",
"-",
"-def update(k, x):",
"- k += num - 1",
"- seg[k] = x",
"- while k + 1:",
"- k = (k - 1) // 2",
"- seg[k] = segfunc(seg[k * 2 + 1], seg[k * 2 + 2])",
"-",
"-",
"-def query(p, q):",
"- if q <= p:",
"- return ide_ele",
"- p += num - 1",
"- q += num - 2",
"- res = ide_ele",
"- while q - p > 1:",
"- if p & 1 == 0:",
"- res = segfunc(res, seg[p])",
"- if q & 1 == 1:",
"- res = segfunc(res, seg[q])",
"- q -= 1",
"- p = p // 2",
"- q = (q - 1) // 2",
"- if p == q:",
"- res = segfunc(res, seg[p])",
"- else:",
"- res = segfunc(segfunc(res, seg[p]), seg[q])",
"- return res",
"-",
"-",
"-ide_ele = -(10**30)",
"-num = 2 ** (n - 1).bit_length()",
"-seg = [ide_ele] * 2 * num",
"-init(b)",
"+a = [-(10**30)] * n",
"+a[-1] = b[-1]",
"+for i in range(n - 1):",
"+ a[n - i - 2] = max(a[n - i - 1], b[n - i - 2])",
"- ans = max(ans, query(i, n) - (r[i] - x[i]))",
"+ ans = max(ans, a[i] - (r[i] - x[i]))"
] | false | 0.047348 | 0.04782 | 0.990142 | [
"s792764582",
"s881183214"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.