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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
u994988729 | p03807 | python | s480036236 | s957941419 | 57 | 42 | 14,108 | 14,112 | Accepted | Accepted | 26.32 | n=int(input())
a=list(map(int,input().split()))
even,odd=0,0
for i in a:
if i%2==0:
even+=1
else:
odd+=1
if odd==0:
print("YES")
elif even==0:
print("YES") if odd%2==0 else print("NO")
else:
if odd==1 and even==1:
print("NO")
else:
print("YES") if odd%2==0 else print("NO")
| n=int(eval(input()))
a=sum(list(map(int,input().split())))
if a%2==0:
print("YES")
else:
print("NO") | 20 | 6 | 360 | 103 | n = int(input())
a = list(map(int, input().split()))
even, odd = 0, 0
for i in a:
if i % 2 == 0:
even += 1
else:
odd += 1
if odd == 0:
print("YES")
elif even == 0:
print("YES") if odd % 2 == 0 else print("NO")
else:
if odd == 1 and even == 1:
print("NO")
else:
print("YES") if odd % 2 == 0 else print("NO")
| n = int(eval(input()))
a = sum(list(map(int, input().split())))
if a % 2 == 0:
print("YES")
else:
print("NO")
| false | 70 | [
"-n = int(input())",
"-a = list(map(int, input().split()))",
"-even, odd = 0, 0",
"-for i in a:",
"- if i % 2 == 0:",
"- even += 1",
"- else:",
"- odd += 1",
"-if odd == 0:",
"+n = int(eval(input()))",
"+a = sum(list(map(int, input().split())))",
"+if a % 2 == 0:",
"-elif even == 0:",
"- print(\"YES\") if odd % 2 == 0 else print(\"NO\")",
"- if odd == 1 and even == 1:",
"- print(\"NO\")",
"- else:",
"- print(\"YES\") if odd % 2 == 0 else print(\"NO\")",
"+ print(\"NO\")"
] | false | 0.105052 | 0.063293 | 1.659782 | [
"s480036236",
"s957941419"
] |
u780475861 | p02786 | python | s067381349 | s140296565 | 22 | 18 | 3,572 | 3,188 | Accepted | Accepted | 18.18 | import sys
from functools import lru_cache
sys.setrecursionlimit(1000000)
@lru_cache(maxsize=None)
def a(n):
if n == 1:
return 1
return 1 + 2 * a(n // 2)
print((a(int(eval(input())))))
| from math import log
h=int(eval(input()))
a=int(log(h,2))
print((pow(2,a+1)-1))
| 13 | 5 | 209 | 77 | import sys
from functools import lru_cache
sys.setrecursionlimit(1000000)
@lru_cache(maxsize=None)
def a(n):
if n == 1:
return 1
return 1 + 2 * a(n // 2)
print((a(int(eval(input())))))
| from math import log
h = int(eval(input()))
a = int(log(h, 2))
print((pow(2, a + 1) - 1))
| false | 61.538462 | [
"-import sys",
"-from functools import lru_cache",
"+from math import log",
"-sys.setrecursionlimit(1000000)",
"-",
"-",
"-@lru_cache(maxsize=None)",
"-def a(n):",
"- if n == 1:",
"- return 1",
"- return 1 + 2 * a(n // 2)",
"-",
"-",
"-print((a(int(eval(input())))))",
"+h = int(eval(input()))",
"+a = int(log(h, 2))",
"+print((pow(2, a + 1) - 1))"
] | false | 0.141098 | 0.113513 | 1.243009 | [
"s067381349",
"s140296565"
] |
u017810624 | p02804 | python | s898696425 | s837555341 | 879 | 363 | 98,088 | 20,056 | Accepted | Accepted | 58.7 | def cmb(n,r,mod):
if r<0 or r>n:
return 0
r=min(r,n-r)
return g1[n]*g2[r]*g2[n-r]%mod
n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
l=[]
l2=[]
for i in range(n):
l.append([a[i],i])
l.sort()
for i in range(n):
l2.append([l[i][1],i])
l2.sort()
mod=10**9+7
g1=[1,1]
g2=[1,1]
inverse=[0,1]
for i in range(2,n+1):
g1.append((g1[-1]*i)%mod)
inverse.append((-inverse[mod%i]*(mod//i))%mod)
g2.append((g2[-1]*inverse[-1])%mod)
ans=0
for i in range(n):
ans+=a[i]*cmb(l2[i][1],k-1,mod)
ans%=mod
for i in range(n):
ans-=a[i]*cmb(n-l2[i][1]-1,k-1,mod)
ans+=mod
ans%=mod
print(ans) | def cmb(n,r,mod):
if r<0 or r>n:
return 0
r=min(r,n-r)
return g1[n]*g2[r]*g2[n-r]%mod
n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
a.sort()
mod=10**9+7
g1=[1,1]
g2=[1,1]
inverse=[0,1]
for i in range(2,n+1):
g1.append((g1[-1]*i)%mod)
inverse.append((-inverse[mod%i]*(mod//i))%mod)
g2.append((g2[-1]*inverse[-1])%mod)
ans=0
for i in range(n):
ans+=a[i]*cmb(i,k-1,mod)
ans%=mod
for i in range(n):
ans-=a[i]*cmb(n-i-1,k-1,mod)
ans+=mod
ans%=mod
print(ans) | 36 | 29 | 654 | 530 | def cmb(n, r, mod):
if r < 0 or r > n:
return 0
r = min(r, n - r)
return g1[n] * g2[r] * g2[n - r] % mod
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
l = []
l2 = []
for i in range(n):
l.append([a[i], i])
l.sort()
for i in range(n):
l2.append([l[i][1], i])
l2.sort()
mod = 10**9 + 7
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
for i in range(2, n + 1):
g1.append((g1[-1] * i) % mod)
inverse.append((-inverse[mod % i] * (mod // i)) % mod)
g2.append((g2[-1] * inverse[-1]) % mod)
ans = 0
for i in range(n):
ans += a[i] * cmb(l2[i][1], k - 1, mod)
ans %= mod
for i in range(n):
ans -= a[i] * cmb(n - l2[i][1] - 1, k - 1, mod)
ans += mod
ans %= mod
print(ans)
| def cmb(n, r, mod):
if r < 0 or r > n:
return 0
r = min(r, n - r)
return g1[n] * g2[r] * g2[n - r] % mod
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
mod = 10**9 + 7
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
for i in range(2, n + 1):
g1.append((g1[-1] * i) % mod)
inverse.append((-inverse[mod % i] * (mod // i)) % mod)
g2.append((g2[-1] * inverse[-1]) % mod)
ans = 0
for i in range(n):
ans += a[i] * cmb(i, k - 1, mod)
ans %= mod
for i in range(n):
ans -= a[i] * cmb(n - i - 1, k - 1, mod)
ans += mod
ans %= mod
print(ans)
| false | 19.444444 | [
"-l = []",
"-l2 = []",
"-for i in range(n):",
"- l.append([a[i], i])",
"-l.sort()",
"-for i in range(n):",
"- l2.append([l[i][1], i])",
"-l2.sort()",
"+a.sort()",
"- ans += a[i] * cmb(l2[i][1], k - 1, mod)",
"+ ans += a[i] * cmb(i, k - 1, mod)",
"- ans -= a[i] * cmb(n - l2[i][1] - 1, k - 1, mod)",
"+ ans -= a[i] * cmb(n - i - 1, k - 1, mod)"
] | false | 0.036928 | 0.054275 | 0.680388 | [
"s898696425",
"s837555341"
] |
u347640436 | p02762 | python | s603437069 | s940959741 | 1,438 | 999 | 101,264 | 98,436 | Accepted | Accepted | 30.53 | from sys import setrecursionlimit
def find(parent, i):
t = parent[i]
if t < 0:
return i
t = find(parent, t)
parent[i] = t
return t
def unite(parent, i, j):
i = find(parent, i)
j = find(parent, j)
if i == j:
return
parent[j] += parent[i]
parent[i] = j
setrecursionlimit(10 ** 5)
N, M, K = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(M)]
CD = [list(map(int, input().split())) for _ in range(K)]
parent = [-1] * N
friends = [[] for _ in range(N)]
for A, B in AB:
unite(parent, A - 1, B - 1)
friends[A-1].append(B-1)
friends[B-1].append(A-1)
blocks = [[] for _ in range(N)]
for C, D in CD:
blocks[C-1].append(D-1)
blocks[D-1].append(C-1)
result = []
for i in range(N):
p = find(parent, i)
t = -parent[p] - 1
t -= len(friends[i])
for b in blocks[i]:
if p == find(parent, b):
t -= 1
result.append(t)
print((*result))
| # Union Find 木
from sys import setrecursionlimit
def find(parent, i):
t = parent[i]
if t < 0:
return i
t = find(parent, t)
parent[i] = t
return t
def unite(parent, i, j):
i = find(parent, i)
j = find(parent, j)
if i == j:
return
parent[j] += parent[i]
parent[i] = j
setrecursionlimit(10 ** 6)
N, M, K = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(M)]
CD = [list(map(int, input().split())) for _ in range(K)]
parent = [-1] * N
friends = [[] for _ in range(N)]
for A, B in AB:
unite(parent, A - 1, B - 1)
friends[A-1].append(B-1)
friends[B-1].append(A-1)
blocks = [[] for _ in range(N)]
for C, D in CD:
blocks[C-1].append(D-1)
blocks[D-1].append(C-1)
result = []
for i in range(N):
p = find(parent, i)
t = -parent[p] - 1
t -= len(friends[i])
for b in blocks[i]:
if p == find(parent, b):
t -= 1
result.append(t)
print((*result))
| 49 | 50 | 1,018 | 1,034 | from sys import setrecursionlimit
def find(parent, i):
t = parent[i]
if t < 0:
return i
t = find(parent, t)
parent[i] = t
return t
def unite(parent, i, j):
i = find(parent, i)
j = find(parent, j)
if i == j:
return
parent[j] += parent[i]
parent[i] = j
setrecursionlimit(10**5)
N, M, K = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(M)]
CD = [list(map(int, input().split())) for _ in range(K)]
parent = [-1] * N
friends = [[] for _ in range(N)]
for A, B in AB:
unite(parent, A - 1, B - 1)
friends[A - 1].append(B - 1)
friends[B - 1].append(A - 1)
blocks = [[] for _ in range(N)]
for C, D in CD:
blocks[C - 1].append(D - 1)
blocks[D - 1].append(C - 1)
result = []
for i in range(N):
p = find(parent, i)
t = -parent[p] - 1
t -= len(friends[i])
for b in blocks[i]:
if p == find(parent, b):
t -= 1
result.append(t)
print((*result))
| # Union Find 木
from sys import setrecursionlimit
def find(parent, i):
t = parent[i]
if t < 0:
return i
t = find(parent, t)
parent[i] = t
return t
def unite(parent, i, j):
i = find(parent, i)
j = find(parent, j)
if i == j:
return
parent[j] += parent[i]
parent[i] = j
setrecursionlimit(10**6)
N, M, K = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(M)]
CD = [list(map(int, input().split())) for _ in range(K)]
parent = [-1] * N
friends = [[] for _ in range(N)]
for A, B in AB:
unite(parent, A - 1, B - 1)
friends[A - 1].append(B - 1)
friends[B - 1].append(A - 1)
blocks = [[] for _ in range(N)]
for C, D in CD:
blocks[C - 1].append(D - 1)
blocks[D - 1].append(C - 1)
result = []
for i in range(N):
p = find(parent, i)
t = -parent[p] - 1
t -= len(friends[i])
for b in blocks[i]:
if p == find(parent, b):
t -= 1
result.append(t)
print((*result))
| false | 2 | [
"+# Union Find 木",
"-setrecursionlimit(10**5)",
"+setrecursionlimit(10**6)"
] | false | 0.057526 | 0.058689 | 0.980187 | [
"s603437069",
"s940959741"
] |
u125505541 | p03286 | python | s412898993 | s617304118 | 455 | 17 | 5,948 | 3,060 | Accepted | Accepted | 96.26 | import bisect
n = int(eval(input()))
ps = [0] * (1 << 16)
for i in range(1 << 16):
temp = 0
x = 1
for j in range(16):
if (i >> j) & 1:
# temp += (-2) ** (2 *j)
temp += x
x *= 4
ps[i] = temp
pattern1 = None
pattern2 = None
for i in range(1 << 16):
temp2 = 0
x = 2
for j in range(16):
if (i >> j) & 1:
# temp2 += (-2) ** (2 *j + 1)
temp2 += x
x *= 4
n2 = n + temp2
pattern1 = bisect.bisect_left(ps, n2)
if pattern1 != (1 << 16) and ps[pattern1] == n2:
pattern2 = bin(i)[2:].zfill(16)
pattern1 = bin(pattern1)[2:].zfill(16)
break
ans = ""
for i in range(16):
ans += pattern2[i]
ans += pattern1[i]
true_ans = ""
flag = False
for i in range(len(ans)):
if ans[i]=="1":
true_ans += "1"
flag = True
elif flag:
true_ans += "0"
if true_ans == "":
true_ans = "0"
print(true_ans) | n = int(eval(input()))
n2 = n
ans = ""
for i in range(100):
while n != 0:
r = (n % 2)
n = (n - r) // (-2)
ans = str(r) + ans
if n2==0:
print("0")
else:
print(ans) | 49 | 12 | 1,025 | 203 | import bisect
n = int(eval(input()))
ps = [0] * (1 << 16)
for i in range(1 << 16):
temp = 0
x = 1
for j in range(16):
if (i >> j) & 1:
# temp += (-2) ** (2 *j)
temp += x
x *= 4
ps[i] = temp
pattern1 = None
pattern2 = None
for i in range(1 << 16):
temp2 = 0
x = 2
for j in range(16):
if (i >> j) & 1:
# temp2 += (-2) ** (2 *j + 1)
temp2 += x
x *= 4
n2 = n + temp2
pattern1 = bisect.bisect_left(ps, n2)
if pattern1 != (1 << 16) and ps[pattern1] == n2:
pattern2 = bin(i)[2:].zfill(16)
pattern1 = bin(pattern1)[2:].zfill(16)
break
ans = ""
for i in range(16):
ans += pattern2[i]
ans += pattern1[i]
true_ans = ""
flag = False
for i in range(len(ans)):
if ans[i] == "1":
true_ans += "1"
flag = True
elif flag:
true_ans += "0"
if true_ans == "":
true_ans = "0"
print(true_ans)
| n = int(eval(input()))
n2 = n
ans = ""
for i in range(100):
while n != 0:
r = n % 2
n = (n - r) // (-2)
ans = str(r) + ans
if n2 == 0:
print("0")
else:
print(ans)
| false | 75.510204 | [
"-import bisect",
"-",
"-ps = [0] * (1 << 16)",
"-for i in range(1 << 16):",
"- temp = 0",
"- x = 1",
"- for j in range(16):",
"- if (i >> j) & 1:",
"- # temp += (-2) ** (2 *j)",
"- temp += x",
"- x *= 4",
"- ps[i] = temp",
"-pattern1 = None",
"-pattern2 = None",
"-for i in range(1 << 16):",
"- temp2 = 0",
"- x = 2",
"- for j in range(16):",
"- if (i >> j) & 1:",
"- # temp2 += (-2) ** (2 *j + 1)",
"- temp2 += x",
"- x *= 4",
"- n2 = n + temp2",
"- pattern1 = bisect.bisect_left(ps, n2)",
"- if pattern1 != (1 << 16) and ps[pattern1] == n2:",
"- pattern2 = bin(i)[2:].zfill(16)",
"- pattern1 = bin(pattern1)[2:].zfill(16)",
"- break",
"+n2 = n",
"-for i in range(16):",
"- ans += pattern2[i]",
"- ans += pattern1[i]",
"-true_ans = \"\"",
"-flag = False",
"-for i in range(len(ans)):",
"- if ans[i] == \"1\":",
"- true_ans += \"1\"",
"- flag = True",
"- elif flag:",
"- true_ans += \"0\"",
"-if true_ans == \"\":",
"- true_ans = \"0\"",
"-print(true_ans)",
"+for i in range(100):",
"+ while n != 0:",
"+ r = n % 2",
"+ n = (n - r) // (-2)",
"+ ans = str(r) + ans",
"+if n2 == 0:",
"+ print(\"0\")",
"+else:",
"+ print(ans)"
] | false | 1.545929 | 0.039412 | 39.224447 | [
"s412898993",
"s617304118"
] |
u906428167 | p02758 | python | s077294460 | s746089240 | 1,971 | 1,459 | 131,032 | 127,540 | Accepted | Accepted | 25.98 | from bisect import bisect_left
MOD = 998244353
n = int(eval(input()))
robot = []
pos = []
for i in range(n):
x, d = list(map(int, input().split()))
robot.append([x, x+d])
pos.append(x)
robot = sorted(robot, key=lambda y: y[0])
pos = sorted(pos)
def init(init_val):
for i in range(n):
MI[i+num-1] = init_val[i]
MA[i+num-1] = init_val[i]
for i in range(num-2, -1, -1):
MI[i] = min(MI[2*i+1], MI[2*i+2])
MA[i] = max(MA[2*i+1], MA[2*i+2])
def update(k, x):
k += num-1
MI[k] = x
MA[k] = x
while k+1:
k = (k-1)//2
MI[k] = min(MI[k*2+1], MI[k*2+2])
MA[k] = max(MA[k*2+1], MA[k*2+2])
def rangemin(p, q):
if q <= p:
return 1 << 100
p += num-1
q += num-2
res = 1 << 100
while q-p > 1:
if p & 1 == 0:
res = min(res, MI[p])
if q & 1 == 1:
res = min(res, MI[q])
q -= 1
p = p//2
q = (q-1)//2
if p == q:
res = min(res, MI[p])
else:
res = min(min(res, MI[p]), MI[q])
return res
def rangemax(p, q):
if q <= p:
return -1
p += num-1
q += num-2
res = -1
while q-p > 1:
if p & 1 == 0:
res = max(res, MA[p])
if q & 1 == 1:
res = max(res, MA[q])
q -= 1
p = p//2
q = (q-1)//2
if p == q:
res = max(res, MA[p])
else:
res = max(max(res, MA[p]), MA[q])
return res
# n:リスト長
num = 2**(n-1).bit_length()
MI = [1 << 100]*2*num
MA = [-1]*2*num
r = []
for x, d in robot:
r.append(bisect_left(pos, d))
init(r)
s = [0]*n
for x in range(n-1, -1, -1):
right_max = rangemax(x, r[x])
s[x] = right_max
update(x, right_max)
dp = [0]*(n+1)
dp[-1] = 1
for i in range(n-1, -1, -1):
dp[i] = dp[i+1]+dp[s[i]]
dp[i] %= MOD
print((dp[0]))
| from bisect import bisect_left
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
MOD = 998244353
n = int(eval(input()))
robot = []
pos = []
for i in range(n):
x, d = list(map(int, input().split()))
robot.append([x, x+d])
pos.append(x)
robot = sorted(robot, key=lambda y: y[0])
pos = sorted(pos)
def init(init_val):
for i in range(n):
MI[i+num-1] = init_val[i]
MA[i+num-1] = init_val[i]
for i in range(num-2, -1, -1):
MI[i] = min(MI[2*i+1], MI[2*i+2])
MA[i] = max(MA[2*i+1], MA[2*i+2])
def update(k, x):
k += num-1
MI[k] = x
MA[k] = x
while k+1:
k = (k-1)//2
MI[k] = min(MI[k*2+1], MI[k*2+2])
MA[k] = max(MA[k*2+1], MA[k*2+2])
def rangemax(p, q):
if q <= p:
return -1
p += num-1
q += num-2
res = -1
while q-p > 1:
if p & 1 == 0:
res = max(res, MA[p])
if q & 1 == 1:
res = max(res, MA[q])
q -= 1
p = p//2
q = (q-1)//2
if p == q:
res = max(res, MA[p])
else:
res = max(max(res, MA[p]), MA[q])
return res
# n:リスト長
num = 2**(n-1).bit_length()
MI = [1 << 100]*2*num
MA = [-1]*2*num
r = []
for x, d in robot:
r.append(bisect_left(pos, d))
init(r)
s = [0]*n
for x in range(n-1, -1, -1):
right_max = rangemax(x, r[x])
s[x] = right_max
update(x, right_max)
dp = [0]*(n+1)
dp[-1] = 1
for i in range(n-1, -1, -1):
dp[i] = dp[i+1]+dp[s[i]]
dp[i] %= MOD
print((dp[0]))
| 103 | 86 | 1,962 | 1,603 | from bisect import bisect_left
MOD = 998244353
n = int(eval(input()))
robot = []
pos = []
for i in range(n):
x, d = list(map(int, input().split()))
robot.append([x, x + d])
pos.append(x)
robot = sorted(robot, key=lambda y: y[0])
pos = sorted(pos)
def init(init_val):
for i in range(n):
MI[i + num - 1] = init_val[i]
MA[i + num - 1] = init_val[i]
for i in range(num - 2, -1, -1):
MI[i] = min(MI[2 * i + 1], MI[2 * i + 2])
MA[i] = max(MA[2 * i + 1], MA[2 * i + 2])
def update(k, x):
k += num - 1
MI[k] = x
MA[k] = x
while k + 1:
k = (k - 1) // 2
MI[k] = min(MI[k * 2 + 1], MI[k * 2 + 2])
MA[k] = max(MA[k * 2 + 1], MA[k * 2 + 2])
def rangemin(p, q):
if q <= p:
return 1 << 100
p += num - 1
q += num - 2
res = 1 << 100
while q - p > 1:
if p & 1 == 0:
res = min(res, MI[p])
if q & 1 == 1:
res = min(res, MI[q])
q -= 1
p = p // 2
q = (q - 1) // 2
if p == q:
res = min(res, MI[p])
else:
res = min(min(res, MI[p]), MI[q])
return res
def rangemax(p, q):
if q <= p:
return -1
p += num - 1
q += num - 2
res = -1
while q - p > 1:
if p & 1 == 0:
res = max(res, MA[p])
if q & 1 == 1:
res = max(res, MA[q])
q -= 1
p = p // 2
q = (q - 1) // 2
if p == q:
res = max(res, MA[p])
else:
res = max(max(res, MA[p]), MA[q])
return res
# n:リスト長
num = 2 ** (n - 1).bit_length()
MI = [1 << 100] * 2 * num
MA = [-1] * 2 * num
r = []
for x, d in robot:
r.append(bisect_left(pos, d))
init(r)
s = [0] * n
for x in range(n - 1, -1, -1):
right_max = rangemax(x, r[x])
s[x] = right_max
update(x, right_max)
dp = [0] * (n + 1)
dp[-1] = 1
for i in range(n - 1, -1, -1):
dp[i] = dp[i + 1] + dp[s[i]]
dp[i] %= MOD
print((dp[0]))
| from bisect import bisect_left
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
MOD = 998244353
n = int(eval(input()))
robot = []
pos = []
for i in range(n):
x, d = list(map(int, input().split()))
robot.append([x, x + d])
pos.append(x)
robot = sorted(robot, key=lambda y: y[0])
pos = sorted(pos)
def init(init_val):
for i in range(n):
MI[i + num - 1] = init_val[i]
MA[i + num - 1] = init_val[i]
for i in range(num - 2, -1, -1):
MI[i] = min(MI[2 * i + 1], MI[2 * i + 2])
MA[i] = max(MA[2 * i + 1], MA[2 * i + 2])
def update(k, x):
k += num - 1
MI[k] = x
MA[k] = x
while k + 1:
k = (k - 1) // 2
MI[k] = min(MI[k * 2 + 1], MI[k * 2 + 2])
MA[k] = max(MA[k * 2 + 1], MA[k * 2 + 2])
def rangemax(p, q):
if q <= p:
return -1
p += num - 1
q += num - 2
res = -1
while q - p > 1:
if p & 1 == 0:
res = max(res, MA[p])
if q & 1 == 1:
res = max(res, MA[q])
q -= 1
p = p // 2
q = (q - 1) // 2
if p == q:
res = max(res, MA[p])
else:
res = max(max(res, MA[p]), MA[q])
return res
# n:リスト長
num = 2 ** (n - 1).bit_length()
MI = [1 << 100] * 2 * num
MA = [-1] * 2 * num
r = []
for x, d in robot:
r.append(bisect_left(pos, d))
init(r)
s = [0] * n
for x in range(n - 1, -1, -1):
right_max = rangemax(x, r[x])
s[x] = right_max
update(x, right_max)
dp = [0] * (n + 1)
dp[-1] = 1
for i in range(n - 1, -1, -1):
dp[i] = dp[i + 1] + dp[s[i]]
dp[i] %= MOD
print((dp[0]))
| false | 16.504854 | [
"+import sys",
"+sys.setrecursionlimit(10**7)",
"+input = sys.stdin.readline",
"-",
"-",
"-def rangemin(p, q):",
"- if q <= p:",
"- return 1 << 100",
"- p += num - 1",
"- q += num - 2",
"- res = 1 << 100",
"- while q - p > 1:",
"- if p & 1 == 0:",
"- res = min(res, MI[p])",
"- if q & 1 == 1:",
"- res = min(res, MI[q])",
"- q -= 1",
"- p = p // 2",
"- q = (q - 1) // 2",
"- if p == q:",
"- res = min(res, MI[p])",
"- else:",
"- res = min(min(res, MI[p]), MI[q])",
"- return res"
] | false | 0.046903 | 0.046383 | 1.011223 | [
"s077294460",
"s746089240"
] |
u254871849 | p03286 | python | s103482862 | s150621759 | 20 | 17 | 3,064 | 3,060 | Accepted | Accepted | 15 | import sys
n = int(sys.stdin.readline().rstrip())
def base_convert(n, base):
res = []
b = abs(base)
while n:
q, r = divmod(n, b)
res.append(r)
n = b * q // base
try:
return int(''.join(list(map(str, res)))[::-1])
except:
return 0
def main():
return base_convert(n, -2)
if __name__ == '__main__':
ans = main()
print(ans) | import sys
n = int(sys.stdin.readline().rstrip())
def base_convert(n, b):
res = ''
while n:
r = abs(n % b)
res = str(r) + res
n = (n - r) // b
return int(res) if res else 0
def main():
return base_convert(n, -2)
if __name__ == '__main__':
ans = main()
print(ans) | 22 | 19 | 416 | 333 | import sys
n = int(sys.stdin.readline().rstrip())
def base_convert(n, base):
res = []
b = abs(base)
while n:
q, r = divmod(n, b)
res.append(r)
n = b * q // base
try:
return int("".join(list(map(str, res)))[::-1])
except:
return 0
def main():
return base_convert(n, -2)
if __name__ == "__main__":
ans = main()
print(ans)
| import sys
n = int(sys.stdin.readline().rstrip())
def base_convert(n, b):
res = ""
while n:
r = abs(n % b)
res = str(r) + res
n = (n - r) // b
return int(res) if res else 0
def main():
return base_convert(n, -2)
if __name__ == "__main__":
ans = main()
print(ans)
| false | 13.636364 | [
"-def base_convert(n, base):",
"- res = []",
"- b = abs(base)",
"+def base_convert(n, b):",
"+ res = \"\"",
"- q, r = divmod(n, b)",
"- res.append(r)",
"- n = b * q // base",
"- try:",
"- return int(\"\".join(list(map(str, res)))[::-1])",
"- except:",
"- return 0",
"+ r = abs(n % b)",
"+ res = str(r) + res",
"+ n = (n - r) // b",
"+ return int(res) if res else 0"
] | false | 0.008039 | 0.043366 | 0.185371 | [
"s103482862",
"s150621759"
] |
u975039852 | p02862 | python | s585666413 | s647303075 | 791 | 223 | 82,276 | 3,064 | Accepted | Accepted | 71.81 | x, y = list(map(int, input().split()))
mod = 1000000007
class Combination:
"""
O(n)の前計算を1回行うことで,O(1)でnCr mod mを求められる
n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
使用例:
comb = Combination(1000000)
print(comb(5, 3)) # 10
"""
def __init__(self, n_max, mod=10**9+7):
self.mod = mod
self.modinv = self.make_modinv_list(n_max)
self.fac, self.facinv = self.make_factorial_list(n_max)
def __call__(self, n, r):
return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod
def make_factorial_list(self, n):
# 階乗のリストと階乗のmod逆元のリストを返す O(n)
# self.make_modinv_list()が先に実行されている必要がある
fac = [1]
facinv = [1]
for i in range(1, n+1):
fac.append(fac[i-1] * i % self.mod)
facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
return fac, facinv
def make_modinv_list(self, n):
# 0からnまでのmod逆元のリストを返す O(n)
modinv = [0] * (n+1)
modinv[1] = 1
for i in range(2, n+1):
modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
return modinv
if (x + y) % 3 != 0:
print((0))
else:
n = (x + y) // 3
if n > x or n > y:
print((0))
else:
nx = x - n
comb = Combination(n)
print((comb(n, nx)))
| x, y = list(map(int, input().split()))
mod = 10**9+7
def inv(x):
return pow(x, mod-2, mod)
def fact(x):
f = 1
for i in range(1, x + 1):
f *= i
f %= mod
return f
def comb(n, r):
return (fact(n) * inv(fact(n-r)) * inv(fact(r))) % mod
if (x + y) % 3 != 0:
print((0))
else:
n = (x + y) // 3
if n > x or n > y:
print((0))
else:
nx = x - n
print((comb(n, nx)))
| 45 | 22 | 1,356 | 466 | x, y = list(map(int, input().split()))
mod = 1000000007
class Combination:
"""
O(n)の前計算を1回行うことで,O(1)でnCr mod mを求められる
n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
使用例:
comb = Combination(1000000)
print(comb(5, 3)) # 10
"""
def __init__(self, n_max, mod=10**9 + 7):
self.mod = mod
self.modinv = self.make_modinv_list(n_max)
self.fac, self.facinv = self.make_factorial_list(n_max)
def __call__(self, n, r):
return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n - r] % self.mod
def make_factorial_list(self, n):
# 階乗のリストと階乗のmod逆元のリストを返す O(n)
# self.make_modinv_list()が先に実行されている必要がある
fac = [1]
facinv = [1]
for i in range(1, n + 1):
fac.append(fac[i - 1] * i % self.mod)
facinv.append(facinv[i - 1] * self.modinv[i] % self.mod)
return fac, facinv
def make_modinv_list(self, n):
# 0からnまでのmod逆元のリストを返す O(n)
modinv = [0] * (n + 1)
modinv[1] = 1
for i in range(2, n + 1):
modinv[i] = self.mod - self.mod // i * modinv[self.mod % i] % self.mod
return modinv
if (x + y) % 3 != 0:
print((0))
else:
n = (x + y) // 3
if n > x or n > y:
print((0))
else:
nx = x - n
comb = Combination(n)
print((comb(n, nx)))
| x, y = list(map(int, input().split()))
mod = 10**9 + 7
def inv(x):
return pow(x, mod - 2, mod)
def fact(x):
f = 1
for i in range(1, x + 1):
f *= i
f %= mod
return f
def comb(n, r):
return (fact(n) * inv(fact(n - r)) * inv(fact(r))) % mod
if (x + y) % 3 != 0:
print((0))
else:
n = (x + y) // 3
if n > x or n > y:
print((0))
else:
nx = x - n
print((comb(n, nx)))
| false | 51.111111 | [
"-mod = 1000000007",
"+mod = 10**9 + 7",
"-class Combination:",
"- \"\"\"",
"- O(n)の前計算を1回行うことで,O(1)でnCr mod mを求められる",
"- n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)",
"- 使用例:",
"- comb = Combination(1000000)",
"- print(comb(5, 3)) # 10",
"- \"\"\"",
"+def inv(x):",
"+ return pow(x, mod - 2, mod)",
"- def __init__(self, n_max, mod=10**9 + 7):",
"- self.mod = mod",
"- self.modinv = self.make_modinv_list(n_max)",
"- self.fac, self.facinv = self.make_factorial_list(n_max)",
"- def __call__(self, n, r):",
"- return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n - r] % self.mod",
"+def fact(x):",
"+ f = 1",
"+ for i in range(1, x + 1):",
"+ f *= i",
"+ f %= mod",
"+ return f",
"- def make_factorial_list(self, n):",
"- # 階乗のリストと階乗のmod逆元のリストを返す O(n)",
"- # self.make_modinv_list()が先に実行されている必要がある",
"- fac = [1]",
"- facinv = [1]",
"- for i in range(1, n + 1):",
"- fac.append(fac[i - 1] * i % self.mod)",
"- facinv.append(facinv[i - 1] * self.modinv[i] % self.mod)",
"- return fac, facinv",
"- def make_modinv_list(self, n):",
"- # 0からnまでのmod逆元のリストを返す O(n)",
"- modinv = [0] * (n + 1)",
"- modinv[1] = 1",
"- for i in range(2, n + 1):",
"- modinv[i] = self.mod - self.mod // i * modinv[self.mod % i] % self.mod",
"- return modinv",
"+def comb(n, r):",
"+ return (fact(n) * inv(fact(n - r)) * inv(fact(r))) % mod",
"- comb = Combination(n)"
] | false | 0.317897 | 0.071598 | 4.440028 | [
"s585666413",
"s647303075"
] |
u151005508 | p03721 | python | s037809465 | s118763179 | 724 | 613 | 68,184 | 61,016 | Accepted | Accepted | 15.33 | N, K = list(map(int, input().split()))
ab=[]
for _ in range(N):
ab.append(tuple(map(int, input().split())))
ab=sorted(ab, key=lambda x:x[0])
#print(ab)
accum=[0]
for i in range(len(ab)):
accum.append(accum[i]+ab[i][1])
#print(accum)
for i in range(len(ab)):
#print(accum[i], accum[i+1])
if accum[i] < K <= accum[i+1]:
print((ab[i][0]))
break | N, K = list(map(int, input().split()))
ab=[]
for _ in range(N):
ab.append(tuple(map(int, input().split())))
num=[0]*(10**5+1)
for el in ab:
num[el[0]]+=el[1]
#print(num)
count=0
for i in range(10**5+1):
count+=num[i]
if count>=K:
print(i)
break
| 15 | 15 | 379 | 286 | N, K = list(map(int, input().split()))
ab = []
for _ in range(N):
ab.append(tuple(map(int, input().split())))
ab = sorted(ab, key=lambda x: x[0])
# print(ab)
accum = [0]
for i in range(len(ab)):
accum.append(accum[i] + ab[i][1])
# print(accum)
for i in range(len(ab)):
# print(accum[i], accum[i+1])
if accum[i] < K <= accum[i + 1]:
print((ab[i][0]))
break
| N, K = list(map(int, input().split()))
ab = []
for _ in range(N):
ab.append(tuple(map(int, input().split())))
num = [0] * (10**5 + 1)
for el in ab:
num[el[0]] += el[1]
# print(num)
count = 0
for i in range(10**5 + 1):
count += num[i]
if count >= K:
print(i)
break
| false | 0 | [
"-ab = sorted(ab, key=lambda x: x[0])",
"-# print(ab)",
"-accum = [0]",
"-for i in range(len(ab)):",
"- accum.append(accum[i] + ab[i][1])",
"-# print(accum)",
"-for i in range(len(ab)):",
"- # print(accum[i], accum[i+1])",
"- if accum[i] < K <= accum[i + 1]:",
"- print((ab[i][0]))",
"+num = [0] * (10**5 + 1)",
"+for el in ab:",
"+ num[el[0]] += el[1]",
"+# print(num)",
"+count = 0",
"+for i in range(10**5 + 1):",
"+ count += num[i]",
"+ if count >= K:",
"+ print(i)"
] | false | 0.068391 | 0.051158 | 1.336859 | [
"s037809465",
"s118763179"
] |
u729133443 | p03045 | python | s549034673 | s586570792 | 1,461 | 376 | 144,380 | 32,180 | Accepted | Accepted | 74.26 | r=lambda x:x if u[x]<0else r(u[x])
n,m,*t=list(map(int,open(0).read().split()))
u=[-1]*-~n
for x,y in zip(t[::3],t[1::3]):
x,y=sorted((r(x),r(y)))
if x!=y:u[x]+=u[y];u[y]=x
print((sum(i<0for i in u)-1)) | r=lambda x:x*(u[x]<0)or r(u[x])
n,m,*t=list(map(int,open(0).read().split()))
u=[-1]*-~n
for x,y in zip(t[::3],t[1::3]):
x,y=sorted((r(x),r(y)))
if x!=y:u[x]+=u[y];u[y]=x
print((sum(i<0for i in u)-1)) | 7 | 7 | 202 | 199 | r = lambda x: x if u[x] < 0 else r(u[x])
n, m, *t = list(map(int, open(0).read().split()))
u = [-1] * -~n
for x, y in zip(t[::3], t[1::3]):
x, y = sorted((r(x), r(y)))
if x != y:
u[x] += u[y]
u[y] = x
print((sum(i < 0 for i in u) - 1))
| r = lambda x: x * (u[x] < 0) or r(u[x])
n, m, *t = list(map(int, open(0).read().split()))
u = [-1] * -~n
for x, y in zip(t[::3], t[1::3]):
x, y = sorted((r(x), r(y)))
if x != y:
u[x] += u[y]
u[y] = x
print((sum(i < 0 for i in u) - 1))
| false | 0 | [
"-r = lambda x: x if u[x] < 0 else r(u[x])",
"+r = lambda x: x * (u[x] < 0) or r(u[x])"
] | false | 0.092271 | 0.047902 | 1.926254 | [
"s549034673",
"s586570792"
] |
u222668979 | p03608 | python | s334873173 | s849172838 | 228 | 204 | 78,436 | 73,492 | Accepted | Accepted | 10.53 | from copy import deepcopy
from itertools import permutations
def warshallfloyd(N, LIST): # ワーシャルフロイド法:全頂点対最短経路 O(n**3)
DIST = deepcopy(LIST)
for k in range(N):
for i in range(N):
for j in range(N):
DIST[i][j] = min(DIST[i][j], DIST[i][k] + DIST[k][j])
return DIST
n, m, r = list(map(int, input().split()))
town = list(map(int, input().split()))
abc = [list(map(int, input().split())) for _ in range(m)]
mat = [[10 ** 10] * n for _ in range(n)]
for i in range(n):
mat[i][i] = 0
for a, b, c in abc:
mat[a - 1][b - 1] = c
mat[b - 1][a - 1] = c
ans = float('inf')
dist = warshallfloyd(n, mat)
for route in permutations(town, r):
bfo, tmp = route[0], 0
for i in route[1:]:
tmp += dist[bfo - 1][i - 1]
bfo = i
ans = min(ans, tmp)
print(ans)
| from copy import deepcopy
from itertools import permutations
def warshallfloyd(N): # ワーシャルフロイド法:全頂点対最短経路 O(n**3)
DIST = deepcopy(mat)
for k in range(N):
for i in range(N):
for j in range(N):
DIST[i][j] = min(DIST[i][j], DIST[i][k] + DIST[k][j])
return DIST
n, m, r = list(map(int, input().split()))
town = list(map(int, input().split()))
abc = [list(map(int, input().split())) for _ in range(m)]
mat = [[10 ** 10] * n for _ in range(n)]
for i in range(n):
mat[i][i] = 0
for a, b, c in abc:
mat[a - 1][b - 1] = c
mat[b - 1][a - 1] = c
ans = float('inf')
dist = warshallfloyd(n)
for route in permutations(town, r):
bfo, tmp = route[0], 0
for i in route[1:]:
tmp += dist[bfo - 1][i - 1]
bfo = i
ans = min(ans, tmp)
print(ans)
| 33 | 33 | 856 | 844 | from copy import deepcopy
from itertools import permutations
def warshallfloyd(N, LIST): # ワーシャルフロイド法:全頂点対最短経路 O(n**3)
DIST = deepcopy(LIST)
for k in range(N):
for i in range(N):
for j in range(N):
DIST[i][j] = min(DIST[i][j], DIST[i][k] + DIST[k][j])
return DIST
n, m, r = list(map(int, input().split()))
town = list(map(int, input().split()))
abc = [list(map(int, input().split())) for _ in range(m)]
mat = [[10**10] * n for _ in range(n)]
for i in range(n):
mat[i][i] = 0
for a, b, c in abc:
mat[a - 1][b - 1] = c
mat[b - 1][a - 1] = c
ans = float("inf")
dist = warshallfloyd(n, mat)
for route in permutations(town, r):
bfo, tmp = route[0], 0
for i in route[1:]:
tmp += dist[bfo - 1][i - 1]
bfo = i
ans = min(ans, tmp)
print(ans)
| from copy import deepcopy
from itertools import permutations
def warshallfloyd(N): # ワーシャルフロイド法:全頂点対最短経路 O(n**3)
DIST = deepcopy(mat)
for k in range(N):
for i in range(N):
for j in range(N):
DIST[i][j] = min(DIST[i][j], DIST[i][k] + DIST[k][j])
return DIST
n, m, r = list(map(int, input().split()))
town = list(map(int, input().split()))
abc = [list(map(int, input().split())) for _ in range(m)]
mat = [[10**10] * n for _ in range(n)]
for i in range(n):
mat[i][i] = 0
for a, b, c in abc:
mat[a - 1][b - 1] = c
mat[b - 1][a - 1] = c
ans = float("inf")
dist = warshallfloyd(n)
for route in permutations(town, r):
bfo, tmp = route[0], 0
for i in route[1:]:
tmp += dist[bfo - 1][i - 1]
bfo = i
ans = min(ans, tmp)
print(ans)
| false | 0 | [
"-def warshallfloyd(N, LIST): # ワーシャルフロイド法:全頂点対最短経路 O(n**3)",
"- DIST = deepcopy(LIST)",
"+def warshallfloyd(N): # ワーシャルフロイド法:全頂点対最短経路 O(n**3)",
"+ DIST = deepcopy(mat)",
"-dist = warshallfloyd(n, mat)",
"+dist = warshallfloyd(n)"
] | false | 0.040842 | 0.040484 | 1.008855 | [
"s334873173",
"s849172838"
] |
u281303342 | p03408 | python | s214202316 | s328345698 | 22 | 20 | 3,316 | 3,316 | Accepted | Accepted | 9.09 | N = int(eval(input()))
S = [eval(input()) for _ in range(N)]
M = int(eval(input()))
T = [eval(input()) for _ in range(M)]
from collections import Counter
CS = Counter(S).most_common()
CT = Counter(T)
ans = 0
for cs in CS:
k,v = cs
ans = max(ans, v-CT[k])
print(ans)
| # Python3 (3.4.3)
import sys
input = sys.stdin.readline
# -------------------------------------------------------------
# function
# -------------------------------------------------------------
# -------------------------------------------------------------
# main
# -------------------------------------------------------------
N = int(eval(input()))
S = [input().rstrip() for _ in range(N)]
M = int(eval(input()))
T = [input().rstrip() for _ in range(M)]
from collections import defaultdict
dic = defaultdict(int)
for s in S:
dic[s] += 1
for t in T:
dic[t] -= 1
ans = 0
for v in list(dic.values()):
ans = max(ans, v)
print(ans) | 15 | 30 | 267 | 660 | N = int(eval(input()))
S = [eval(input()) for _ in range(N)]
M = int(eval(input()))
T = [eval(input()) for _ in range(M)]
from collections import Counter
CS = Counter(S).most_common()
CT = Counter(T)
ans = 0
for cs in CS:
k, v = cs
ans = max(ans, v - CT[k])
print(ans)
| # Python3 (3.4.3)
import sys
input = sys.stdin.readline
# -------------------------------------------------------------
# function
# -------------------------------------------------------------
# -------------------------------------------------------------
# main
# -------------------------------------------------------------
N = int(eval(input()))
S = [input().rstrip() for _ in range(N)]
M = int(eval(input()))
T = [input().rstrip() for _ in range(M)]
from collections import defaultdict
dic = defaultdict(int)
for s in S:
dic[s] += 1
for t in T:
dic[t] -= 1
ans = 0
for v in list(dic.values()):
ans = max(ans, v)
print(ans)
| false | 50 | [
"+# Python3 (3.4.3)",
"+import sys",
"+",
"+input = sys.stdin.readline",
"+# function",
"+# main",
"-S = [eval(input()) for _ in range(N)]",
"+S = [input().rstrip() for _ in range(N)]",
"-T = [eval(input()) for _ in range(M)]",
"-from collections import Counter",
"+T = [input().rstrip() for _ in range(M)]",
"+from collections import defaultdict",
"-CS = Counter(S).most_common()",
"-CT = Counter(T)",
"+dic = defaultdict(int)",
"+for s in S:",
"+ dic[s] += 1",
"+for t in T:",
"+ dic[t] -= 1",
"-for cs in CS:",
"- k, v = cs",
"- ans = max(ans, v - CT[k])",
"+for v in list(dic.values()):",
"+ ans = max(ans, v)"
] | false | 0.040108 | 0.050065 | 0.801126 | [
"s214202316",
"s328345698"
] |
u607563136 | p03805 | python | s320684624 | s181850759 | 44 | 36 | 9,220 | 9,108 | Accepted | Accepted | 18.18 | N,M = list(map(int,input().split()))
path = [[0]*(N+1) for _ in range(N+1)]
for i in range(M):
a,b = list(map(int,input().split()))
path[a][b] = 1
path[b][a] = 1
visited = [0]*(N+1)
def dfs(now,depth):
if visited[now]:
return 0
if depth == N:
return 1 # 最後まで探索したらはじめて+1
visited[now] = 1
total_paths = 0
for i in range(1,N+1):
if path[now][i]:
total_paths += dfs(i, depth + 1)
visited[now] = 0
return total_paths
print((dfs(1,1))) | def dfs(g,v,depth):
if seen[v]==True:return 0
if depth==n:return 1
seen[v] = True
paths = 0
for next_v in g[v]:
paths += dfs(g,next_v,depth+1)
seen[v] = False
return paths
n,m = list(map(int,input().split()))
g = [[]*(n+1) for _ in range(n+1)]
for _ in range(m):
a,b = list(map(int,input().split()))
g[a].append(b)
g[b].append(a)
seen = [False]*(n+1)
print((dfs(g,1,1))) | 30 | 22 | 558 | 442 | N, M = list(map(int, input().split()))
path = [[0] * (N + 1) for _ in range(N + 1)]
for i in range(M):
a, b = list(map(int, input().split()))
path[a][b] = 1
path[b][a] = 1
visited = [0] * (N + 1)
def dfs(now, depth):
if visited[now]:
return 0
if depth == N:
return 1 # 最後まで探索したらはじめて+1
visited[now] = 1
total_paths = 0
for i in range(1, N + 1):
if path[now][i]:
total_paths += dfs(i, depth + 1)
visited[now] = 0
return total_paths
print((dfs(1, 1)))
| def dfs(g, v, depth):
if seen[v] == True:
return 0
if depth == n:
return 1
seen[v] = True
paths = 0
for next_v in g[v]:
paths += dfs(g, next_v, depth + 1)
seen[v] = False
return paths
n, m = list(map(int, input().split()))
g = [[] * (n + 1) for _ in range(n + 1)]
for _ in range(m):
a, b = list(map(int, input().split()))
g[a].append(b)
g[b].append(a)
seen = [False] * (n + 1)
print((dfs(g, 1, 1)))
| false | 26.666667 | [
"-N, M = list(map(int, input().split()))",
"-path = [[0] * (N + 1) for _ in range(N + 1)]",
"-for i in range(M):",
"- a, b = list(map(int, input().split()))",
"- path[a][b] = 1",
"- path[b][a] = 1",
"-visited = [0] * (N + 1)",
"+def dfs(g, v, depth):",
"+ if seen[v] == True:",
"+ return 0",
"+ if depth == n:",
"+ return 1",
"+ seen[v] = True",
"+ paths = 0",
"+ for next_v in g[v]:",
"+ paths += dfs(g, next_v, depth + 1)",
"+ seen[v] = False",
"+ return paths",
"-def dfs(now, depth):",
"- if visited[now]:",
"- return 0",
"- if depth == N:",
"- return 1 # 最後まで探索したらはじめて+1",
"- visited[now] = 1",
"- total_paths = 0",
"- for i in range(1, N + 1):",
"- if path[now][i]:",
"- total_paths += dfs(i, depth + 1)",
"- visited[now] = 0",
"- return total_paths",
"-",
"-",
"-print((dfs(1, 1)))",
"+n, m = list(map(int, input().split()))",
"+g = [[] * (n + 1) for _ in range(n + 1)]",
"+for _ in range(m):",
"+ a, b = list(map(int, input().split()))",
"+ g[a].append(b)",
"+ g[b].append(a)",
"+seen = [False] * (n + 1)",
"+print((dfs(g, 1, 1)))"
] | false | 0.031656 | 0.036175 | 0.875094 | [
"s320684624",
"s181850759"
] |
u580697892 | p03262 | python | s567076175 | s003465201 | 109 | 92 | 14,748 | 16,304 | Accepted | Accepted | 15.6 | #coding: utf-8
from functools import reduce
def gcd(a, b):
if b == 0:
return max(a, b)
else:
return gcd(b, a%b)
N, X = list(map(int, input().split()))
x = list(map(int, input().split()))
x = [abs(X - x[i]) for i in range(N)]
print((reduce(gcd, x))) | #coding: utf-8
from functools import reduce
from fractions import gcd #py<=3.4
#from math import gcd # py >= 3.5
N, X = list(map(int, input().split()))
x = list(map(int, input().split()))
res = [abs(x[i] - X) for i in range(N)]
print((reduce(gcd, res))) | 12 | 8 | 276 | 258 | # coding: utf-8
from functools import reduce
def gcd(a, b):
if b == 0:
return max(a, b)
else:
return gcd(b, a % b)
N, X = list(map(int, input().split()))
x = list(map(int, input().split()))
x = [abs(X - x[i]) for i in range(N)]
print((reduce(gcd, x)))
| # coding: utf-8
from functools import reduce
from fractions import gcd # py<=3.4
# from math import gcd # py >= 3.5
N, X = list(map(int, input().split()))
x = list(map(int, input().split()))
res = [abs(x[i] - X) for i in range(N)]
print((reduce(gcd, res)))
| false | 33.333333 | [
"+from fractions import gcd # py<=3.4",
"-",
"-def gcd(a, b):",
"- if b == 0:",
"- return max(a, b)",
"- else:",
"- return gcd(b, a % b)",
"-",
"-",
"+# from math import gcd # py >= 3.5",
"-x = [abs(X - x[i]) for i in range(N)]",
"-print((reduce(gcd, x)))",
"+res = [abs(x[i] - X) for i in range(N)]",
"+print((reduce(gcd, res)))"
] | false | 0.03749 | 0.046963 | 0.798296 | [
"s567076175",
"s003465201"
] |
u350248178 | p03816 | python | s237723949 | s686575776 | 53 | 48 | 14,396 | 14,396 | Accepted | Accepted | 9.43 | n=int(eval(input()))
a=[int(j) for j in input().split()]
tmp=len(set(a))
while n>tmp:
n-=2
print(n) | n=int(eval(input()))
a=[int(j) for j in input().split()]
ans=len(set(a))
if (n-ans)%2==0:
print(ans)
else:
print((ans-1))
| 6 | 7 | 102 | 128 | n = int(eval(input()))
a = [int(j) for j in input().split()]
tmp = len(set(a))
while n > tmp:
n -= 2
print(n)
| n = int(eval(input()))
a = [int(j) for j in input().split()]
ans = len(set(a))
if (n - ans) % 2 == 0:
print(ans)
else:
print((ans - 1))
| false | 14.285714 | [
"-tmp = len(set(a))",
"-while n > tmp:",
"- n -= 2",
"-print(n)",
"+ans = len(set(a))",
"+if (n - ans) % 2 == 0:",
"+ print(ans)",
"+else:",
"+ print((ans - 1))"
] | false | 0.049133 | 0.048238 | 1.018557 | [
"s237723949",
"s686575776"
] |
u078042885 | p00728 | python | s954172329 | s162972366 | 30 | 20 | 7,692 | 7,568 | Accepted | Accepted | 33.33 | while 1:
n=int(eval(input()))
if n==0:break
print(((sum(sorted([int(eval(input())) for _ in range(n)])[1:-1]))//(n-2))) | while 1:
n=int(eval(input()))
if n<3:break
print(((sum(sorted([int(eval(input())) for _ in [0]*n])[1:-1]))//(n-2))) | 4 | 4 | 120 | 116 | while 1:
n = int(eval(input()))
if n == 0:
break
print(((sum(sorted([int(eval(input())) for _ in range(n)])[1:-1])) // (n - 2)))
| while 1:
n = int(eval(input()))
if n < 3:
break
print(((sum(sorted([int(eval(input())) for _ in [0] * n])[1:-1])) // (n - 2)))
| false | 0 | [
"- if n == 0:",
"+ if n < 3:",
"- print(((sum(sorted([int(eval(input())) for _ in range(n)])[1:-1])) // (n - 2)))",
"+ print(((sum(sorted([int(eval(input())) for _ in [0] * n])[1:-1])) // (n - 2)))"
] | false | 0.039911 | 0.044473 | 0.897407 | [
"s954172329",
"s162972366"
] |
u912237403 | p00040 | python | s231996323 | s708195413 | 30 | 20 | 4,424 | 4,276 | Accepted | Accepted | 33.33 | import string
A2Z="abcdefghijklmnopqrstuvwxyz"
R=list(range(26))
def decode(msg,L):
x=""
for c in msg: x+=(L[A2Z.index(c)] if "a"<=c<="z" else c)
return x
def affine(msg, a, b):
L="".join([A2Z[(i*a+b)%26]for i in R])
s = decode(msg,L)
return s
def rot(msg, a):
a = a % 26
L = A2Z[a:]+A2Z[:a]
s = decode(msg,L)
return s
def checkkey(s):
c0="t"
for i in R:
a = 0
x = affine(s,i,0)
c = A2Z.index(x[0])
if c!=19:
a = (19-c)%26
x = rot(x,a)
if x in['this','that']: return i,a
return -1,-1
n = eval(input())
while n:
n-=1
s = input()
for w in s.split():
if len(w)==4:
a,b = checkkey(w)
if a!=-1: break
print(affine(s,a,b)) | A2Z="abcdefghijklmnopqrstuvwxyz"
def affine(msg, a, b):
s=""
for c in msg: s+=(A2Z[(A2Z.index(c)*a+b)%26] if "a"<=c<="z" else c)
return s
def rot(msg, a):
a = a % 26
L = A2Z[a:]+A2Z[:a]
s=""
for c in msg: s+=(L[A2Z.index(c)] if "a"<=c<="z" else c)
return s
def checkkey(s):
c0="t"
for i in range(26):
a = 0
x = affine(s,i,0)
c = A2Z.index(x[0])
if c!=19:
a = (19-c)%26
x = rot(x,a)
if x in['this','that']: return i,a
return -1,-1
n = eval(input())
while n:
n-=1
s = input()
for w in s.split():
if len(w)==4:
a,b = checkkey(w)
if a!=-1: break
print(affine(s,a,b)) | 40 | 35 | 814 | 753 | import string
A2Z = "abcdefghijklmnopqrstuvwxyz"
R = list(range(26))
def decode(msg, L):
x = ""
for c in msg:
x += L[A2Z.index(c)] if "a" <= c <= "z" else c
return x
def affine(msg, a, b):
L = "".join([A2Z[(i * a + b) % 26] for i in R])
s = decode(msg, L)
return s
def rot(msg, a):
a = a % 26
L = A2Z[a:] + A2Z[:a]
s = decode(msg, L)
return s
def checkkey(s):
c0 = "t"
for i in R:
a = 0
x = affine(s, i, 0)
c = A2Z.index(x[0])
if c != 19:
a = (19 - c) % 26
x = rot(x, a)
if x in ["this", "that"]:
return i, a
return -1, -1
n = eval(input())
while n:
n -= 1
s = input()
for w in s.split():
if len(w) == 4:
a, b = checkkey(w)
if a != -1:
break
print(affine(s, a, b))
| A2Z = "abcdefghijklmnopqrstuvwxyz"
def affine(msg, a, b):
s = ""
for c in msg:
s += A2Z[(A2Z.index(c) * a + b) % 26] if "a" <= c <= "z" else c
return s
def rot(msg, a):
a = a % 26
L = A2Z[a:] + A2Z[:a]
s = ""
for c in msg:
s += L[A2Z.index(c)] if "a" <= c <= "z" else c
return s
def checkkey(s):
c0 = "t"
for i in range(26):
a = 0
x = affine(s, i, 0)
c = A2Z.index(x[0])
if c != 19:
a = (19 - c) % 26
x = rot(x, a)
if x in ["this", "that"]:
return i, a
return -1, -1
n = eval(input())
while n:
n -= 1
s = input()
for w in s.split():
if len(w) == 4:
a, b = checkkey(w)
if a != -1:
break
print(affine(s, a, b))
| false | 12.5 | [
"-import string",
"-",
"-R = list(range(26))",
"-",
"-",
"-def decode(msg, L):",
"- x = \"\"",
"- for c in msg:",
"- x += L[A2Z.index(c)] if \"a\" <= c <= \"z\" else c",
"- return x",
"- L = \"\".join([A2Z[(i * a + b) % 26] for i in R])",
"- s = decode(msg, L)",
"+ s = \"\"",
"+ for c in msg:",
"+ s += A2Z[(A2Z.index(c) * a + b) % 26] if \"a\" <= c <= \"z\" else c",
"- s = decode(msg, L)",
"+ s = \"\"",
"+ for c in msg:",
"+ s += L[A2Z.index(c)] if \"a\" <= c <= \"z\" else c",
"- for i in R:",
"+ for i in range(26):"
] | false | 0.051603 | 0.048916 | 1.054939 | [
"s231996323",
"s708195413"
] |
u654470292 | p02900 | python | s763474931 | s520852937 | 292 | 126 | 65,132 | 9,972 | Accepted | Accepted | 56.85 | import sys
from fractions import gcd
def input():
return sys.stdin.readline()[:-1]
a,b=list(map(int,input().split()))
tmp=gcd(a,b)
# print(tmp)
def factorization(n):
arr = []
temp = n
for i in range(2, int(-(-n**0.5//1))+1):
if temp%i==0:
cnt=0
while temp%i==0:
cnt+=1
temp //= i
arr.append([i, cnt])
if temp!=1:
arr.append([temp, 1])
if arr==[]:
arr.append([n, 1])
return arr
ans=factorization(tmp)
# print(ans)
if tmp==1:
print((1))
else:
print((len(ans)+1)) | import bisect, copy, heapq, math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
return sys.stdin.readline()[:-1]
def ruiseki(lst):
return [0]+list(accumulate(lst))
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]
a,b=list(map(int,input().split()))
g=math.gcd(a,b)
def factorization(n):
arr = []
temp = n
for i in range(2, int(-(-n**0.5//1))+1):
if temp%i==0:
cnt=0
while temp%i==0:
cnt+=1
temp //= i
arr.append([i, cnt])
if temp!=1:
arr.append([temp, 1])
if arr==[]:
arr.append([n, 1])
return arr
if g==1:
print((1))
else:
print((len(factorization(g))+1)) | 32 | 37 | 613 | 899 | import sys
from fractions import gcd
def input():
return sys.stdin.readline()[:-1]
a, b = list(map(int, input().split()))
tmp = gcd(a, b)
# print(tmp)
def factorization(n):
arr = []
temp = n
for i in range(2, int(-(-(n**0.5) // 1)) + 1):
if temp % i == 0:
cnt = 0
while temp % i == 0:
cnt += 1
temp //= i
arr.append([i, cnt])
if temp != 1:
arr.append([temp, 1])
if arr == []:
arr.append([n, 1])
return arr
ans = factorization(tmp)
# print(ans)
if tmp == 1:
print((1))
else:
print((len(ans) + 1))
| import bisect, copy, heapq, math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
return sys.stdin.readline()[:-1]
def ruiseki(lst):
return [0] + list(accumulate(lst))
sys.setrecursionlimit(5000000)
mod = pow(10, 9) + 7
al = [chr(ord("a") + i) for i in range(26)]
direction = [[1, 0], [0, 1], [-1, 0], [0, -1]]
a, b = list(map(int, input().split()))
g = math.gcd(a, b)
def factorization(n):
arr = []
temp = n
for i in range(2, int(-(-(n**0.5) // 1)) + 1):
if temp % i == 0:
cnt = 0
while temp % i == 0:
cnt += 1
temp //= i
arr.append([i, cnt])
if temp != 1:
arr.append([temp, 1])
if arr == []:
arr.append([n, 1])
return arr
if g == 1:
print((1))
else:
print((len(factorization(g)) + 1))
| false | 13.513514 | [
"+import bisect, copy, heapq, math",
"-from fractions import gcd",
"+from collections import *",
"+from functools import lru_cache",
"+from itertools import accumulate, combinations, permutations, product",
"+def ruiseki(lst):",
"+ return [0] + list(accumulate(lst))",
"+",
"+",
"+sys.setrecursionlimit(5000000)",
"+mod = pow(10, 9) + 7",
"+al = [chr(ord(\"a\") + i) for i in range(26)]",
"+direction = [[1, 0], [0, 1], [-1, 0], [0, -1]]",
"-tmp = gcd(a, b)",
"-# print(tmp)",
"+g = math.gcd(a, b)",
"+",
"+",
"-ans = factorization(tmp)",
"-# print(ans)",
"-if tmp == 1:",
"+if g == 1:",
"- print((len(ans) + 1))",
"+ print((len(factorization(g)) + 1))"
] | false | 0.04546 | 0.038376 | 1.184615 | [
"s763474931",
"s520852937"
] |
u959519702 | p03078 | python | s143073841 | s030321131 | 180 | 87 | 35,816 | 40,092 | Accepted | Accepted | 51.67 | def get_input():
X, Y, Z, K = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]
B = [int(_) for _ in input().split()]
C = [int(_) for _ in input().split()]
return X, Y, Z, K, A, B, C
def AddToQueue(_ele, _queue, _ijk_set, K):
if len(_queue) == 0:
_queue.append(_ele)
else:
cnt = 0
while cnt < len(_queue) and _queue[cnt][0] >= _ele[0]:
cnt += 1
ijk = (_ele[1], _ele[2], _ele[3])
if not (ijk in _ijk_set):
_queue.insert(cnt, _ele)
_ijk_set.add(ijk)
_queue = _queue[:K]
def solve3():
X, Y, Z, K, A, B, C = get_input()
A.sort(reverse = True)
B.sort(reverse = True)
C.sort(reverse = True)
ijk_set = set()
queue = [(A[0] + B[0] + C[0], 0, 0, 0)]
ijk_set.add((0, 0, 0))
for cnt in range(K):
ele, i, j, k = queue.pop(0)
print(ele)
if i + 1 < X:
AddToQueue((A[i+1] + B[j] + C[k], i+1, j, k), queue, ijk_set, K)
if j + 1 < Y:
AddToQueue((A[i] + B[j+1] + C[k], i, j+1, k), queue, ijk_set, K)
if k + 1 < Z:
AddToQueue((A[i] + B[j] + C[k+1], i, j, k+1), queue, ijk_set, K)
if __name__ == '__main__':
solve3()
| def get_input():
X, Y, Z, K = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]
B = [int(_) for _ in input().split()]
C = [int(_) for _ in input().split()]
return X, Y, Z, K, A, B, C
def solve2():
X, Y, Z, K, A, B, C = get_input()
A.sort(reverse = True)
B.sort(reverse = True)
C.sort(reverse = True)
sumABC = []
for i in range(X):
for j in range(Y):
if (i + 1) * (j + 1) > K:
break
for k in range(Z):
if (i + 1) * (j + 1) * (k + 1) > K:
break
sumABC.append(A[i] + B[j] + C[k])
sumABC.sort(reverse = True)
for i in range(K):
print(sumABC[i])
if __name__ == '__main__':
solve2() | 40 | 27 | 1,304 | 805 | def get_input():
X, Y, Z, K = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]
B = [int(_) for _ in input().split()]
C = [int(_) for _ in input().split()]
return X, Y, Z, K, A, B, C
def AddToQueue(_ele, _queue, _ijk_set, K):
if len(_queue) == 0:
_queue.append(_ele)
else:
cnt = 0
while cnt < len(_queue) and _queue[cnt][0] >= _ele[0]:
cnt += 1
ijk = (_ele[1], _ele[2], _ele[3])
if not (ijk in _ijk_set):
_queue.insert(cnt, _ele)
_ijk_set.add(ijk)
_queue = _queue[:K]
def solve3():
X, Y, Z, K, A, B, C = get_input()
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
ijk_set = set()
queue = [(A[0] + B[0] + C[0], 0, 0, 0)]
ijk_set.add((0, 0, 0))
for cnt in range(K):
ele, i, j, k = queue.pop(0)
print(ele)
if i + 1 < X:
AddToQueue((A[i + 1] + B[j] + C[k], i + 1, j, k), queue, ijk_set, K)
if j + 1 < Y:
AddToQueue((A[i] + B[j + 1] + C[k], i, j + 1, k), queue, ijk_set, K)
if k + 1 < Z:
AddToQueue((A[i] + B[j] + C[k + 1], i, j, k + 1), queue, ijk_set, K)
if __name__ == "__main__":
solve3()
| def get_input():
X, Y, Z, K = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]
B = [int(_) for _ in input().split()]
C = [int(_) for _ in input().split()]
return X, Y, Z, K, A, B, C
def solve2():
X, Y, Z, K, A, B, C = get_input()
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
sumABC = []
for i in range(X):
for j in range(Y):
if (i + 1) * (j + 1) > K:
break
for k in range(Z):
if (i + 1) * (j + 1) * (k + 1) > K:
break
sumABC.append(A[i] + B[j] + C[k])
sumABC.sort(reverse=True)
for i in range(K):
print(sumABC[i])
if __name__ == "__main__":
solve2()
| false | 32.5 | [
"-def AddToQueue(_ele, _queue, _ijk_set, K):",
"- if len(_queue) == 0:",
"- _queue.append(_ele)",
"- else:",
"- cnt = 0",
"- while cnt < len(_queue) and _queue[cnt][0] >= _ele[0]:",
"- cnt += 1",
"- ijk = (_ele[1], _ele[2], _ele[3])",
"- if not (ijk in _ijk_set):",
"- _queue.insert(cnt, _ele)",
"- _ijk_set.add(ijk)",
"- _queue = _queue[:K]",
"-",
"-",
"-def solve3():",
"+def solve2():",
"- ijk_set = set()",
"- queue = [(A[0] + B[0] + C[0], 0, 0, 0)]",
"- ijk_set.add((0, 0, 0))",
"- for cnt in range(K):",
"- ele, i, j, k = queue.pop(0)",
"- print(ele)",
"- if i + 1 < X:",
"- AddToQueue((A[i + 1] + B[j] + C[k], i + 1, j, k), queue, ijk_set, K)",
"- if j + 1 < Y:",
"- AddToQueue((A[i] + B[j + 1] + C[k], i, j + 1, k), queue, ijk_set, K)",
"- if k + 1 < Z:",
"- AddToQueue((A[i] + B[j] + C[k + 1], i, j, k + 1), queue, ijk_set, K)",
"+ sumABC = []",
"+ for i in range(X):",
"+ for j in range(Y):",
"+ if (i + 1) * (j + 1) > K:",
"+ break",
"+ for k in range(Z):",
"+ if (i + 1) * (j + 1) * (k + 1) > K:",
"+ break",
"+ sumABC.append(A[i] + B[j] + C[k])",
"+ sumABC.sort(reverse=True)",
"+ for i in range(K):",
"+ print(sumABC[i])",
"- solve3()",
"+ solve2()"
] | false | 0.037859 | 0.037858 | 1.000026 | [
"s143073841",
"s030321131"
] |
u585482323 | p02913 | python | s544593169 | s960712664 | 999 | 693 | 52,316 | 49,116 | Accepted | Accepted | 30.63 | #!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
def solve():
def Z_algorithm(s):
n = len(s)
z = [0]*n
z[0] = n
j = 0
for i in range(1,n):
while i+j < n and s[j] == s[i+j]:
j += 1
z[i] = j
if j == 0:
i += 1
continue
k = 1
while i+k < n and k+z[k] < j:
z[i+k] = z[k]
k += 1
i += k
j -= k
return z
n = I()
s = eval(input())
ans = 0
for i in range(n):
z = Z_algorithm(s[i:])
for j in range(i,n):
l = min(j-i,z[j-i])
if ans < l:
ans = l
print(ans)
return
#Solve
if __name__ == "__main__":
solve()
| #!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
def solve():
def Z_algorithm(s):
n = len(s)
z = [0]*n
z[0] = n
c = 1
for i in range(1,n):
if i+z[i-c] < c+z[c]:
z[i] = z[i-c]
else:
j = max(0,c+z[c]-i)
while i+j < n and s[j] == s[i+j]:
j += 1
z[i] = j
c = i
return z
n = I()
s = eval(input())
ans = 0
for i in range(n):
z = Z_algorithm(s[i:])
for j in range(i,n):
l = min(j-i,z[j-i])
if ans < l:
ans = l
print(ans)
return
#Solve
if __name__ == "__main__":
solve()
| 62 | 58 | 1,468 | 1,394 | #!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
def solve():
def Z_algorithm(s):
n = len(s)
z = [0] * n
z[0] = n
j = 0
for i in range(1, n):
while i + j < n and s[j] == s[i + j]:
j += 1
z[i] = j
if j == 0:
i += 1
continue
k = 1
while i + k < n and k + z[k] < j:
z[i + k] = z[k]
k += 1
i += k
j -= k
return z
n = I()
s = eval(input())
ans = 0
for i in range(n):
z = Z_algorithm(s[i:])
for j in range(i, n):
l = min(j - i, z[j - i])
if ans < l:
ans = l
print(ans)
return
# Solve
if __name__ == "__main__":
solve()
| #!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
def solve():
def Z_algorithm(s):
n = len(s)
z = [0] * n
z[0] = n
c = 1
for i in range(1, n):
if i + z[i - c] < c + z[c]:
z[i] = z[i - c]
else:
j = max(0, c + z[c] - i)
while i + j < n and s[j] == s[i + j]:
j += 1
z[i] = j
c = i
return z
n = I()
s = eval(input())
ans = 0
for i in range(n):
z = Z_algorithm(s[i:])
for j in range(i, n):
l = min(j - i, z[j - i])
if ans < l:
ans = l
print(ans)
return
# Solve
if __name__ == "__main__":
solve()
| false | 6.451613 | [
"- j = 0",
"+ c = 1",
"- while i + j < n and s[j] == s[i + j]:",
"- j += 1",
"- z[i] = j",
"- if j == 0:",
"- i += 1",
"- continue",
"- k = 1",
"- while i + k < n and k + z[k] < j:",
"- z[i + k] = z[k]",
"- k += 1",
"- i += k",
"- j -= k",
"+ if i + z[i - c] < c + z[c]:",
"+ z[i] = z[i - c]",
"+ else:",
"+ j = max(0, c + z[c] - i)",
"+ while i + j < n and s[j] == s[i + j]:",
"+ j += 1",
"+ z[i] = j",
"+ c = i"
] | false | 0.143409 | 0.036632 | 3.914907 | [
"s544593169",
"s960712664"
] |
u019584841 | p03777 | python | s923202705 | s104666289 | 19 | 17 | 2,940 | 2,940 | Accepted | Accepted | 10.53 | val = input().split()
print(("H" if val[0] == val[1] else "D"))
| a,b=input().split()
if a==b=="H" or a==b=="D":
print("H")
else:
print("D")
| 2 | 5 | 63 | 83 | val = input().split()
print(("H" if val[0] == val[1] else "D"))
| a, b = input().split()
if a == b == "H" or a == b == "D":
print("H")
else:
print("D")
| false | 60 | [
"-val = input().split()",
"-print((\"H\" if val[0] == val[1] else \"D\"))",
"+a, b = input().split()",
"+if a == b == \"H\" or a == b == \"D\":",
"+ print(\"H\")",
"+else:",
"+ print(\"D\")"
] | false | 0.045712 | 0.044874 | 1.018676 | [
"s923202705",
"s104666289"
] |
u620084012 | p03228 | python | s038713785 | s288306385 | 162 | 17 | 40,024 | 2,940 | Accepted | Accepted | 89.51 | A, B, K = list(map(int,input().split()))
for k in range(K):
if k%2 == 0:
if A%2 == 0:
A //= 2
B += A
else:
A -= 1
A //= 2
B += A
else:
if B%2 == 0:
B //= 2
A += B
else:
B -= 1
B //= 2
A += B
print((A,B)) | A, B, K = list(map(int,input().split()))
for k in range(K):
if k%2 == 0:
A, B = A//2, B+A//2
else:
A, B = A+B//2, B//2
print((A,B))
| 20 | 7 | 375 | 154 | A, B, K = list(map(int, input().split()))
for k in range(K):
if k % 2 == 0:
if A % 2 == 0:
A //= 2
B += A
else:
A -= 1
A //= 2
B += A
else:
if B % 2 == 0:
B //= 2
A += B
else:
B -= 1
B //= 2
A += B
print((A, B))
| A, B, K = list(map(int, input().split()))
for k in range(K):
if k % 2 == 0:
A, B = A // 2, B + A // 2
else:
A, B = A + B // 2, B // 2
print((A, B))
| false | 65 | [
"- if A % 2 == 0:",
"- A //= 2",
"- B += A",
"- else:",
"- A -= 1",
"- A //= 2",
"- B += A",
"+ A, B = A // 2, B + A // 2",
"- if B % 2 == 0:",
"- B //= 2",
"- A += B",
"- else:",
"- B -= 1",
"- B //= 2",
"- A += B",
"+ A, B = A + B // 2, B // 2"
] | false | 0.09993 | 0.084532 | 1.182152 | [
"s038713785",
"s288306385"
] |
u208133431 | p02584 | python | s262990954 | s239992867 | 33 | 26 | 9,136 | 9,128 | Accepted | Accepted | 21.21 | X,K,D=list(map(int,input().split()))
kai = 0
xy = abs(X)
if xy >= K*D:
kotae = abs(xy-(K*D))
if xy < K*D:
kai, mod = divmod(xy, D)
ds = kai*D
if (K-kai)%2==0:
kotae = abs(xy-ds)
if (K-kai)%2!=0:
kotae = abs(xy-ds-D)
print(kotae) | X,K,D=list(map(int,input().split()))
zettaitix = abs(X)
if zettaitix >= K*D:
kotae = abs(zettaitix-(K*D))
elif zettaitix < K*D:
kai, mod = divmod(zettaitix, D)
ds = kai*D
if (K-kai)%2==0:
kotae = abs(zettaitix-ds)
elif (K-kai)%2!=0:
kotae = abs(zettaitix-ds-D)
print(kotae) | 13 | 12 | 270 | 314 | X, K, D = list(map(int, input().split()))
kai = 0
xy = abs(X)
if xy >= K * D:
kotae = abs(xy - (K * D))
if xy < K * D:
kai, mod = divmod(xy, D)
ds = kai * D
if (K - kai) % 2 == 0:
kotae = abs(xy - ds)
if (K - kai) % 2 != 0:
kotae = abs(xy - ds - D)
print(kotae)
| X, K, D = list(map(int, input().split()))
zettaitix = abs(X)
if zettaitix >= K * D:
kotae = abs(zettaitix - (K * D))
elif zettaitix < K * D:
kai, mod = divmod(zettaitix, D)
ds = kai * D
if (K - kai) % 2 == 0:
kotae = abs(zettaitix - ds)
elif (K - kai) % 2 != 0:
kotae = abs(zettaitix - ds - D)
print(kotae)
| false | 7.692308 | [
"-kai = 0",
"-xy = abs(X)",
"-if xy >= K * D:",
"- kotae = abs(xy - (K * D))",
"-if xy < K * D:",
"- kai, mod = divmod(xy, D)",
"+zettaitix = abs(X)",
"+if zettaitix >= K * D:",
"+ kotae = abs(zettaitix - (K * D))",
"+elif zettaitix < K * D:",
"+ kai, mod = divmod(zettaitix, D)",
"- kotae = abs(xy - ds)",
"- if (K - kai) % 2 != 0:",
"- kotae = abs(xy - ds - D)",
"+ kotae = abs(zettaitix - ds)",
"+ elif (K - kai) % 2 != 0:",
"+ kotae = abs(zettaitix - ds - D)"
] | false | 0.042605 | 0.007602 | 5.60482 | [
"s262990954",
"s239992867"
] |
u274005011 | p02657 | python | s391480777 | s812859891 | 31 | 27 | 9,144 | 8,888 | Accepted | Accepted | 12.9 | X, Y = list(map(int, input().split()))
print(("{}".format(X*Y))) | a, b = input().split()
print((int(a)*int(b))) | 3 | 3 | 59 | 46 | X, Y = list(map(int, input().split()))
print(("{}".format(X * Y)))
| a, b = input().split()
print((int(a) * int(b)))
| false | 0 | [
"-X, Y = list(map(int, input().split()))",
"-print((\"{}\".format(X * Y)))",
"+a, b = input().split()",
"+print((int(a) * int(b)))"
] | false | 0.097979 | 0.064112 | 1.528247 | [
"s391480777",
"s812859891"
] |
u332385682 | p04013 | python | s312546045 | s698438862 | 814 | 537 | 62,960 | 4,084 | Accepted | Accepted | 34.03 | def solve():
N, A = list(map(int, input().split()))
x = [int(i) for i in input().split()]
# 3d DP
max_x = max(x)
dp = [[[0] * (max_x * N + 1) for j in range(N + 1)]
for i in range(N + 1)]
dp[0][0][0] = 1
for i in range(0, N):
for k in range(0, N + 1):
for y in range(max_x * N + 1):
if dp[i][k][y]:
dp[i + 1][k][y] += dp[i][k][y]
dp[i + 1][k + 1][y + x[i]] += dp[i][k][y]
cnt = 0
for k in range(1, N + 1):
for y in range(1, max_x * N + 1):
if y // k == A and y % k == 0:
cnt += dp[N][k][y]
print(cnt)
if __name__ == '__main__':
solve() | def solve():
N, A = list(map(int, input().split()))
x = [int(i) for i in input().split()]
lim = sum(x)
dp = [[0]*(lim + 1) for i in range(N + 1)]
dp[0][0] = 1
for i in range(N):
for k in range(i + 1, 0, -1):
for v in range(lim, x[i] - 1, -1):
dp[k][v] += dp[k - 1][v - x[i]]
ans = 0
for k in range(1, N + 1):
if k*A > lim:
break
ans += dp[k][k*A]
print(ans)
if __name__ == '__main__':
solve() | 29 | 25 | 779 | 552 | def solve():
N, A = list(map(int, input().split()))
x = [int(i) for i in input().split()]
# 3d DP
max_x = max(x)
dp = [[[0] * (max_x * N + 1) for j in range(N + 1)] for i in range(N + 1)]
dp[0][0][0] = 1
for i in range(0, N):
for k in range(0, N + 1):
for y in range(max_x * N + 1):
if dp[i][k][y]:
dp[i + 1][k][y] += dp[i][k][y]
dp[i + 1][k + 1][y + x[i]] += dp[i][k][y]
cnt = 0
for k in range(1, N + 1):
for y in range(1, max_x * N + 1):
if y // k == A and y % k == 0:
cnt += dp[N][k][y]
print(cnt)
if __name__ == "__main__":
solve()
| def solve():
N, A = list(map(int, input().split()))
x = [int(i) for i in input().split()]
lim = sum(x)
dp = [[0] * (lim + 1) for i in range(N + 1)]
dp[0][0] = 1
for i in range(N):
for k in range(i + 1, 0, -1):
for v in range(lim, x[i] - 1, -1):
dp[k][v] += dp[k - 1][v - x[i]]
ans = 0
for k in range(1, N + 1):
if k * A > lim:
break
ans += dp[k][k * A]
print(ans)
if __name__ == "__main__":
solve()
| false | 13.793103 | [
"- # 3d DP",
"- max_x = max(x)",
"- dp = [[[0] * (max_x * N + 1) for j in range(N + 1)] for i in range(N + 1)]",
"- dp[0][0][0] = 1",
"- for i in range(0, N):",
"- for k in range(0, N + 1):",
"- for y in range(max_x * N + 1):",
"- if dp[i][k][y]:",
"- dp[i + 1][k][y] += dp[i][k][y]",
"- dp[i + 1][k + 1][y + x[i]] += dp[i][k][y]",
"- cnt = 0",
"+ lim = sum(x)",
"+ dp = [[0] * (lim + 1) for i in range(N + 1)]",
"+ dp[0][0] = 1",
"+ for i in range(N):",
"+ for k in range(i + 1, 0, -1):",
"+ for v in range(lim, x[i] - 1, -1):",
"+ dp[k][v] += dp[k - 1][v - x[i]]",
"+ ans = 0",
"- for y in range(1, max_x * N + 1):",
"- if y // k == A and y % k == 0:",
"- cnt += dp[N][k][y]",
"- print(cnt)",
"+ if k * A > lim:",
"+ break",
"+ ans += dp[k][k * A]",
"+ print(ans)"
] | false | 0.048604 | 0.050114 | 0.969856 | [
"s312546045",
"s698438862"
] |
u176796545 | p03448 | python | s265113218 | s383915368 | 45 | 39 | 3,064 | 3,064 | Accepted | Accepted | 13.33 | A = int(eval(input()))
B = int(eval(input()))
C = int(eval(input()))
X = int(eval(input()))
count=0
for a in [a*500 for a in range(A + 1)]:
for j in range(B + 1):
for k in range(C + 1):
if a + 100*j + 50*k == X:
count += 1
print(count) | A = int(eval(input()))
B = int(eval(input()))
C = int(eval(input()))
X = int(eval(input()))
count=0
for a in [a*500 for a in range(A + 1)]:
for b in [b*100 for b in range(B + 1)]:
for k in range(C + 1):
if a + b + 50*k == X:
count += 1
print(count) | 11 | 11 | 261 | 274 | A = int(eval(input()))
B = int(eval(input()))
C = int(eval(input()))
X = int(eval(input()))
count = 0
for a in [a * 500 for a in range(A + 1)]:
for j in range(B + 1):
for k in range(C + 1):
if a + 100 * j + 50 * k == X:
count += 1
print(count)
| A = int(eval(input()))
B = int(eval(input()))
C = int(eval(input()))
X = int(eval(input()))
count = 0
for a in [a * 500 for a in range(A + 1)]:
for b in [b * 100 for b in range(B + 1)]:
for k in range(C + 1):
if a + b + 50 * k == X:
count += 1
print(count)
| false | 0 | [
"- for j in range(B + 1):",
"+ for b in [b * 100 for b in range(B + 1)]:",
"- if a + 100 * j + 50 * k == X:",
"+ if a + b + 50 * k == X:"
] | false | 0.089398 | 0.098173 | 0.910626 | [
"s265113218",
"s383915368"
] |
u083960235 | p03136 | python | s238556839 | s031253790 | 40 | 26 | 5,396 | 3,896 | Accepted | Accepted | 35 | import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def S_MAP(): return list(map(str, input().split()))
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
N = INT()
L = LIST()
m = max(L)
for i in range(N):
a = L[i]
# b = L[:i-1] + L[i:]
# print(L[:i-1] + L[i:])
if a == m:
if sum(L)-a > a:
print("Yes")
break
else:
print("No")
break | import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from heapq import heapify, heappop, heappush
def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def S_MAP(): return list(map(str, input().split()))
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
N = INT()
L = LIST()
l = sorted(L)
if l[-1] < sum(l[:-1]):
print("Yes")
else:
print("No") | 34 | 28 | 996 | 849 | import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input():
return sys.stdin.readline().strip()
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def S_MAP():
return list(map(str, input().split()))
def LIST():
return list(map(int, input().split()))
def S_LIST():
return list(map(str, input().split()))
sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
N = INT()
L = LIST()
m = max(L)
for i in range(N):
a = L[i]
# b = L[:i-1] + L[i:]
# print(L[:i-1] + L[i:])
if a == m:
if sum(L) - a > a:
print("Yes")
break
else:
print("No")
break
| import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from heapq import heapify, heappop, heappush
def input():
return sys.stdin.readline().strip()
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def S_MAP():
return list(map(str, input().split()))
def LIST():
return list(map(int, input().split()))
def S_LIST():
return list(map(str, input().split()))
sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
N = INT()
L = LIST()
l = sorted(L)
if l[-1] < sum(l[:-1]):
print("Yes")
else:
print("No")
| false | 17.647059 | [
"-from fractions import gcd",
"+from heapq import heapify, heappop, heappush",
"-m = max(L)",
"-for i in range(N):",
"- a = L[i]",
"- # b = L[:i-1] + L[i:]",
"- # print(L[:i-1] + L[i:])",
"- if a == m:",
"- if sum(L) - a > a:",
"- print(\"Yes\")",
"- break",
"- else:",
"- print(\"No\")",
"- break",
"+l = sorted(L)",
"+if l[-1] < sum(l[:-1]):",
"+ print(\"Yes\")",
"+else:",
"+ print(\"No\")"
] | false | 0.036904 | 0.035631 | 1.035731 | [
"s238556839",
"s031253790"
] |
u641357568 | p02397 | python | s884053698 | s259033329 | 60 | 50 | 5,608 | 5,608 | Accepted | Accepted | 16.67 | while(True):
i,j=input().split()
if i != '0' or j != '0':
if int(i) <= int(j):
print(('{} {}'.format(i,j)))
else:
print(('{} {}'.format(j,i)))
else:
break
| while(True):
i,j=input().split()
if i != '0' or j != '0':
if int(i) <= int(j):
print((i+' '+j))
else:
print((j+' '+i))
else:
break
| 10 | 10 | 225 | 201 | while True:
i, j = input().split()
if i != "0" or j != "0":
if int(i) <= int(j):
print(("{} {}".format(i, j)))
else:
print(("{} {}".format(j, i)))
else:
break
| while True:
i, j = input().split()
if i != "0" or j != "0":
if int(i) <= int(j):
print((i + " " + j))
else:
print((j + " " + i))
else:
break
| false | 0 | [
"- print((\"{} {}\".format(i, j)))",
"+ print((i + \" \" + j))",
"- print((\"{} {}\".format(j, i)))",
"+ print((j + \" \" + i))"
] | false | 0.170907 | 0.046313 | 3.690292 | [
"s884053698",
"s259033329"
] |
u912237403 | p00068 | python | s782930907 | s432451246 | 20 | 10 | 4,264 | 4,268 | Accepted | Accepted | 50 | import sys
def side(p1,p2):
global D
y1,x1=p1
y2,x2=p2
dy=y2-y1
dx=x2-x1
for p3 in D:
if p1!=p3 and p2!=p3 and (p3[1]-x1)*dy-dx*(p3[0]-y1)<0:return 0
else:return 1
while 1:
n=eval(input())
if n==0:break
D=sorted([list(eval(input())) for i in range(n)])
p=p1=D[0]
while 1:
for p2 in D:
if p1!=p2 and side(p1,p2):break
p1=p2
D.remove(p2)
if p2==p:break
print(len(D)) | import sys
def side(p1,p2):
global D
y1,x1=p1
y2,x2=p2
dy=y2-y1
dx=x2-x1
for p3 in D:
if p1==p3 or p2==p3:continue
if (p3[1]-x1)*dy-dx*(p3[0]-y1)<0:return 0
else:return 1
while 1:
n=eval(input())
if n==0:break
D=sorted([list(eval(input())) for i in range(n)])
p=p1=D[0]
while 1:
for p2 in D:
if p1!=p2 and side(p1,p2):break
p1=p2
D.remove(p2)
if p2==p:break
print(len(D)) | 23 | 24 | 427 | 439 | import sys
def side(p1, p2):
global D
y1, x1 = p1
y2, x2 = p2
dy = y2 - y1
dx = x2 - x1
for p3 in D:
if p1 != p3 and p2 != p3 and (p3[1] - x1) * dy - dx * (p3[0] - y1) < 0:
return 0
else:
return 1
while 1:
n = eval(input())
if n == 0:
break
D = sorted([list(eval(input())) for i in range(n)])
p = p1 = D[0]
while 1:
for p2 in D:
if p1 != p2 and side(p1, p2):
break
p1 = p2
D.remove(p2)
if p2 == p:
break
print(len(D))
| import sys
def side(p1, p2):
global D
y1, x1 = p1
y2, x2 = p2
dy = y2 - y1
dx = x2 - x1
for p3 in D:
if p1 == p3 or p2 == p3:
continue
if (p3[1] - x1) * dy - dx * (p3[0] - y1) < 0:
return 0
else:
return 1
while 1:
n = eval(input())
if n == 0:
break
D = sorted([list(eval(input())) for i in range(n)])
p = p1 = D[0]
while 1:
for p2 in D:
if p1 != p2 and side(p1, p2):
break
p1 = p2
D.remove(p2)
if p2 == p:
break
print(len(D))
| false | 4.166667 | [
"- if p1 != p3 and p2 != p3 and (p3[1] - x1) * dy - dx * (p3[0] - y1) < 0:",
"+ if p1 == p3 or p2 == p3:",
"+ continue",
"+ if (p3[1] - x1) * dy - dx * (p3[0] - y1) < 0:"
] | false | 0.061723 | 0.044241 | 1.395147 | [
"s782930907",
"s432451246"
] |
u305366205 | p02972 | python | s531536788 | s577623248 | 677 | 308 | 7,148 | 8,380 | Accepted | Accepted | 54.51 | n = int(input())
a = list(map(int, input().split()))
b = [0] * n
# 後ろからボールの有無を決定
for i in range(n - 1, -1, -1):
cnt = 0
for j in range(2 * (i + 1), n + 1, i + 1):
cnt += b[j - 1]
# 条件と異なるならボールを投入
if cnt % 2 != a[i]:
b[i] = 1
m = b.count(1)
print(m)
for i in range(n):
if b[i]:
print(i + 1, end=' ')
| n = int(input())
a = list(map(int, input().split()))
b = [0] * (n + 1)
# 後ろからボールの有無を決定
for i in range(n, 0, -1):
cnt = sum(b[::i])
# 条件と異なるならボールを投入
if cnt % 2 != a[i - 1]:
b[i] = 1
m = sum(b)
print(m)
for i in range(1, n + 1):
if b[i]:
print(i, end=' ')
| 16 | 14 | 358 | 299 | n = int(input())
a = list(map(int, input().split()))
b = [0] * n
# 後ろからボールの有無を決定
for i in range(n - 1, -1, -1):
cnt = 0
for j in range(2 * (i + 1), n + 1, i + 1):
cnt += b[j - 1]
# 条件と異なるならボールを投入
if cnt % 2 != a[i]:
b[i] = 1
m = b.count(1)
print(m)
for i in range(n):
if b[i]:
print(i + 1, end=" ")
| n = int(input())
a = list(map(int, input().split()))
b = [0] * (n + 1)
# 後ろからボールの有無を決定
for i in range(n, 0, -1):
cnt = sum(b[::i])
# 条件と異なるならボールを投入
if cnt % 2 != a[i - 1]:
b[i] = 1
m = sum(b)
print(m)
for i in range(1, n + 1):
if b[i]:
print(i, end=" ")
| false | 12.5 | [
"-b = [0] * n",
"+b = [0] * (n + 1)",
"-for i in range(n - 1, -1, -1):",
"- cnt = 0",
"- for j in range(2 * (i + 1), n + 1, i + 1):",
"- cnt += b[j - 1]",
"+for i in range(n, 0, -1):",
"+ cnt = sum(b[::i])",
"- if cnt % 2 != a[i]:",
"+ if cnt % 2 != a[i - 1]:",
"-m = b.count(1)",
"+m = sum(b)",
"-for i in range(n):",
"+for i in range(1, n + 1):",
"- print(i + 1, end=\" \")",
"+ print(i, end=\" \")"
] | false | 0.113825 | 0.047627 | 2.389945 | [
"s531536788",
"s577623248"
] |
u785989355 | p03640 | python | s418944291 | s938950481 | 30 | 26 | 3,700 | 3,700 | Accepted | Accepted | 13.33 | h,w=list(map(int,input().split()))
n=int(eval(input()))
a=list(map(int,input().split()))
ret=[["0" for i in range(w)]for j in range(h)]
x=0
y=0
for i in range(n):
for j in range(a[i]):
ret[y][x]=str(i+1)
if y&1:
if x==0:
y+=1
else:
x-=1
else:
if x==w-1:
y+=1
else:
x+=1
for i in range(h):
print((" ".join(ret[i]))) |
H,W = list(map(int,input().split()))
N = int(eval(input()))
a = list(map(int,input().split()))
ans = []
current_a=a[0]
current_id = 1
for i in range(H):
w_ans = []
for j in range(W):
if current_a == 0:
current_a = a[current_id]
current_id += 1
current_a -= 1
w_ans.append(str(current_id))
if i%2==1:
w_ans = w_ans[::-1]
ans.append(w_ans)
for i in range(H):
print((" ".join(ans[i])))
| 21 | 24 | 464 | 487 | h, w = list(map(int, input().split()))
n = int(eval(input()))
a = list(map(int, input().split()))
ret = [["0" for i in range(w)] for j in range(h)]
x = 0
y = 0
for i in range(n):
for j in range(a[i]):
ret[y][x] = str(i + 1)
if y & 1:
if x == 0:
y += 1
else:
x -= 1
else:
if x == w - 1:
y += 1
else:
x += 1
for i in range(h):
print((" ".join(ret[i])))
| H, W = list(map(int, input().split()))
N = int(eval(input()))
a = list(map(int, input().split()))
ans = []
current_a = a[0]
current_id = 1
for i in range(H):
w_ans = []
for j in range(W):
if current_a == 0:
current_a = a[current_id]
current_id += 1
current_a -= 1
w_ans.append(str(current_id))
if i % 2 == 1:
w_ans = w_ans[::-1]
ans.append(w_ans)
for i in range(H):
print((" ".join(ans[i])))
| false | 12.5 | [
"-h, w = list(map(int, input().split()))",
"-n = int(eval(input()))",
"+H, W = list(map(int, input().split()))",
"+N = int(eval(input()))",
"-ret = [[\"0\" for i in range(w)] for j in range(h)]",
"-x = 0",
"-y = 0",
"-for i in range(n):",
"- for j in range(a[i]):",
"- ret[y][x] = str(i + 1)",
"- if y & 1:",
"- if x == 0:",
"- y += 1",
"- else:",
"- x -= 1",
"- else:",
"- if x == w - 1:",
"- y += 1",
"- else:",
"- x += 1",
"-for i in range(h):",
"- print((\" \".join(ret[i])))",
"+ans = []",
"+current_a = a[0]",
"+current_id = 1",
"+for i in range(H):",
"+ w_ans = []",
"+ for j in range(W):",
"+ if current_a == 0:",
"+ current_a = a[current_id]",
"+ current_id += 1",
"+ current_a -= 1",
"+ w_ans.append(str(current_id))",
"+ if i % 2 == 1:",
"+ w_ans = w_ans[::-1]",
"+ ans.append(w_ans)",
"+for i in range(H):",
"+ print((\" \".join(ans[i])))"
] | false | 0.145395 | 0.107406 | 1.353693 | [
"s418944291",
"s938950481"
] |
u864197622 | p02803 | python | s035957147 | s781336231 | 326 | 141 | 3,948 | 3,316 | Accepted | Accepted | 56.75 | from collections import deque
H, W = list(map(int, input().split()))
X = [[1 if a == "#" else 0 for a in eval(input())] for _ in range(H)]
def BFS(i0=0):
Q = deque([i0])
D = [-1] * (H * W)
D[i0] = 0
while Q:
x = Q.popleft()
i, j = x // W, x % W
for di, dj in ((0, 1), (0, -1), (1, 0), (-1, 0)):
ni, nj = i + di, j + dj
if 0 <= ni < H and 0 <= nj < W:
if X[ni][nj] == 0:
y = ni * W + nj
if D[y] == -1:
D[y] = D[x] + 1
Q.append(y)
return D
ma = 0
for i in range(H):
for j in range(W):
if X[i][j] == 0:
ma = max(ma, max(BFS(i*W+j)))
print(ma) | from collections import deque
H, W = list(map(int, input().split()))
X = [1] * (W + 2)
for _ in range(H):
X += [1] + [1 if a == "#" else 0 for a in eval(input())] + [1]
X += [1] * (W + 2)
H, W = H+2, W+2
def BFS(i0=0):
Q = deque([i0])
D = [-1] * (H * W)
D[i0] = 0
while Q:
x = Q.popleft()
for y in (x+W, x-W, x+1, x-1):
if X[y] == 0:
if D[y] == -1:
D[y] = D[x] + 1
Q.append(y)
return D
ma = 0
for i in range(H):
for j in range(W):
if X[i*W+j] == 0:
ma = max(ma, max(BFS(i*W+j)))
print(ma) | 27 | 27 | 751 | 636 | from collections import deque
H, W = list(map(int, input().split()))
X = [[1 if a == "#" else 0 for a in eval(input())] for _ in range(H)]
def BFS(i0=0):
Q = deque([i0])
D = [-1] * (H * W)
D[i0] = 0
while Q:
x = Q.popleft()
i, j = x // W, x % W
for di, dj in ((0, 1), (0, -1), (1, 0), (-1, 0)):
ni, nj = i + di, j + dj
if 0 <= ni < H and 0 <= nj < W:
if X[ni][nj] == 0:
y = ni * W + nj
if D[y] == -1:
D[y] = D[x] + 1
Q.append(y)
return D
ma = 0
for i in range(H):
for j in range(W):
if X[i][j] == 0:
ma = max(ma, max(BFS(i * W + j)))
print(ma)
| from collections import deque
H, W = list(map(int, input().split()))
X = [1] * (W + 2)
for _ in range(H):
X += [1] + [1 if a == "#" else 0 for a in eval(input())] + [1]
X += [1] * (W + 2)
H, W = H + 2, W + 2
def BFS(i0=0):
Q = deque([i0])
D = [-1] * (H * W)
D[i0] = 0
while Q:
x = Q.popleft()
for y in (x + W, x - W, x + 1, x - 1):
if X[y] == 0:
if D[y] == -1:
D[y] = D[x] + 1
Q.append(y)
return D
ma = 0
for i in range(H):
for j in range(W):
if X[i * W + j] == 0:
ma = max(ma, max(BFS(i * W + j)))
print(ma)
| false | 0 | [
"-X = [[1 if a == \"#\" else 0 for a in eval(input())] for _ in range(H)]",
"+X = [1] * (W + 2)",
"+for _ in range(H):",
"+ X += [1] + [1 if a == \"#\" else 0 for a in eval(input())] + [1]",
"+X += [1] * (W + 2)",
"+H, W = H + 2, W + 2",
"- i, j = x // W, x % W",
"- for di, dj in ((0, 1), (0, -1), (1, 0), (-1, 0)):",
"- ni, nj = i + di, j + dj",
"- if 0 <= ni < H and 0 <= nj < W:",
"- if X[ni][nj] == 0:",
"- y = ni * W + nj",
"- if D[y] == -1:",
"- D[y] = D[x] + 1",
"- Q.append(y)",
"+ for y in (x + W, x - W, x + 1, x - 1):",
"+ if X[y] == 0:",
"+ if D[y] == -1:",
"+ D[y] = D[x] + 1",
"+ Q.append(y)",
"- if X[i][j] == 0:",
"+ if X[i * W + j] == 0:"
] | false | 0.033816 | 0.094052 | 0.359548 | [
"s035957147",
"s781336231"
] |
u941438707 | p02659 | python | s977830697 | s807691198 | 24 | 22 | 9,172 | 8,948 | Accepted | Accepted | 8.33 | a,b=list(map(str,input().split(" ")))
b,c=list(map(str,b.split(".")))
a=int(a)
b=int(b)
c=int(c)
print((a*b+a*c//100)) | a,b=list(map(int,input().replace(".","").split()))
print((a*b//100)) | 6 | 2 | 109 | 61 | a, b = list(map(str, input().split(" ")))
b, c = list(map(str, b.split(".")))
a = int(a)
b = int(b)
c = int(c)
print((a * b + a * c // 100))
| a, b = list(map(int, input().replace(".", "").split()))
print((a * b // 100))
| false | 66.666667 | [
"-a, b = list(map(str, input().split(\" \")))",
"-b, c = list(map(str, b.split(\".\")))",
"-a = int(a)",
"-b = int(b)",
"-c = int(c)",
"-print((a * b + a * c // 100))",
"+a, b = list(map(int, input().replace(\".\", \"\").split()))",
"+print((a * b // 100))"
] | false | 0.036004 | 0.036169 | 0.995437 | [
"s977830697",
"s807691198"
] |
u272028993 | p03702 | python | s499170806 | s825735083 | 158 | 124 | 34,332 | 35,688 | Accepted | Accepted | 21.52 | n,a,b=list(map(int,input().split()))
h=[int(input()) for _ in range(n)]
l=0
r=10**12
while r-l>1:
m=(r+l)/2
c=a-b
cnt=0
for i in range(n):
if h[i]-b*m<0:continue
if (h[i]-b*m)%c==0:
cnt+=(h[i]-b*m)/c
else:
cnt+=(h[i]-b*m)/c+1
if cnt<=m:
r=m
else:
l=m
print(r)
| def min_bs(l,r):
l-=1
while r-l>1:
m=(r+l)/2
if check(m):
r=m
else:
l=m
return r
def check(m):
cnt=0
for i in range(n):
if h[i]-b*m<=0:continue
cnt+=(h[i]-b*m-1)/(a-b)+1
return True if m>=cnt else False
n,a,b=list(map(int,input().split()))
h=[int(input()) for _ in range(n)]
print(min_bs(1,10**9)) | 19 | 20 | 369 | 409 | n, a, b = list(map(int, input().split()))
h = [int(input()) for _ in range(n)]
l = 0
r = 10**12
while r - l > 1:
m = (r + l) / 2
c = a - b
cnt = 0
for i in range(n):
if h[i] - b * m < 0:
continue
if (h[i] - b * m) % c == 0:
cnt += (h[i] - b * m) / c
else:
cnt += (h[i] - b * m) / c + 1
if cnt <= m:
r = m
else:
l = m
print(r)
| def min_bs(l, r):
l -= 1
while r - l > 1:
m = (r + l) / 2
if check(m):
r = m
else:
l = m
return r
def check(m):
cnt = 0
for i in range(n):
if h[i] - b * m <= 0:
continue
cnt += (h[i] - b * m - 1) / (a - b) + 1
return True if m >= cnt else False
n, a, b = list(map(int, input().split()))
h = [int(input()) for _ in range(n)]
print(min_bs(1, 10**9))
| false | 5 | [
"+def min_bs(l, r):",
"+ l -= 1",
"+ while r - l > 1:",
"+ m = (r + l) / 2",
"+ if check(m):",
"+ r = m",
"+ else:",
"+ l = m",
"+ return r",
"+",
"+",
"+def check(m):",
"+ cnt = 0",
"+ for i in range(n):",
"+ if h[i] - b * m <= 0:",
"+ continue",
"+ cnt += (h[i] - b * m - 1) / (a - b) + 1",
"+ return True if m >= cnt else False",
"+",
"+",
"-l = 0",
"-r = 10**12",
"-while r - l > 1:",
"- m = (r + l) / 2",
"- c = a - b",
"- cnt = 0",
"- for i in range(n):",
"- if h[i] - b * m < 0:",
"- continue",
"- if (h[i] - b * m) % c == 0:",
"- cnt += (h[i] - b * m) / c",
"- else:",
"- cnt += (h[i] - b * m) / c + 1",
"- if cnt <= m:",
"- r = m",
"- else:",
"- l = m",
"-print(r)",
"+print(min_bs(1, 10**9))"
] | false | 0.099105 | 0.103179 | 0.960519 | [
"s499170806",
"s825735083"
] |
u163703551 | p03732 | python | s870049372 | s046578848 | 1,450 | 317 | 3,188 | 3,188 | Accepted | Accepted | 78.14 | import sys
# sys.stdin = open('d1.in')
n, W = list(map(int, input().split()))
g = {}
w1 = 0
for i in range(n):
w, v = list(map(int, input().split()))
if i == 0:
w1 = w
for x in range(w, w + 4):
g[x] = []
g[w].append(v)
for w, values in list(g.items()):
values.sort(reverse=True)
res = 0
for a in range(len(g[w1]) + 1):
for b in range(len(g[w1 + 1]) + 1):
for c in range(len(g[w1 + 2]) + 1):
for d in range(len(g[w1 + 3]) + 1):
total_w = w1 * a + (w1 + 1) * b + (w1 + 2) * c + (w1 + 3) * d
if total_w > W:
continue
total_v = 0
for i in range(a):
total_v += g[w1][i]
for i in range(b):
total_v += g[w1 + 1][i]
for i in range(c):
total_v += g[w1 + 2][i]
for i in range(d):
total_v += g[w1 + 3][i]
if total_v > res:
res = total_v
print(res)
| import sys
# sys.stdin = open('d1.in')
n, W = list(map(int, input().split()))
g = {}
w1 = 0
for i in range(n):
w, v = list(map(int, input().split()))
if i == 0:
w1 = w
for x in range(w, w + 4):
g[x] = []
g[w].append(v)
for w, values in list(g.items()):
values.sort(reverse=True)
sg = {}
sg[w1] = {}
sg[w1 + 1] = {}
sg[w1 + 2] = {}
sg[w1 + 3] = {}
for a in range(len(g[w1]) + 1):
sg[w1][a] = sum(g[w1][:a])
for b in range(len(g[w1 + 1]) + 1):
sg[w1 + 1][b] = sum(g[w1 + 1][:b])
for c in range(len(g[w1 + 2]) + 1):
sg[w1 + 2][c] = sum(g[w1 + 2][:c])
for d in range(len(g[w1 + 3]) + 1):
sg[w1 + 3][d] = sum(g[w1 + 3][:d])
res = 0
for a in range(len(g[w1]) + 1):
for b in range(len(g[w1 + 1]) + 1):
for c in range(len(g[w1 + 2]) + 1):
for d in range(len(g[w1 + 3]) + 1):
total_w = w1 * a + (w1 + 1) * b + (w1 + 2) * c + (w1 + 3) * d
if total_w > W:
continue
total_v = sg[w1][a] + sg[w1 + 1][b] + sg[w1 + 2][c] + sg[w1 + 3][d]
if total_v > res:
res = total_v
print(res)
| 38 | 44 | 1,076 | 1,183 | import sys
# sys.stdin = open('d1.in')
n, W = list(map(int, input().split()))
g = {}
w1 = 0
for i in range(n):
w, v = list(map(int, input().split()))
if i == 0:
w1 = w
for x in range(w, w + 4):
g[x] = []
g[w].append(v)
for w, values in list(g.items()):
values.sort(reverse=True)
res = 0
for a in range(len(g[w1]) + 1):
for b in range(len(g[w1 + 1]) + 1):
for c in range(len(g[w1 + 2]) + 1):
for d in range(len(g[w1 + 3]) + 1):
total_w = w1 * a + (w1 + 1) * b + (w1 + 2) * c + (w1 + 3) * d
if total_w > W:
continue
total_v = 0
for i in range(a):
total_v += g[w1][i]
for i in range(b):
total_v += g[w1 + 1][i]
for i in range(c):
total_v += g[w1 + 2][i]
for i in range(d):
total_v += g[w1 + 3][i]
if total_v > res:
res = total_v
print(res)
| import sys
# sys.stdin = open('d1.in')
n, W = list(map(int, input().split()))
g = {}
w1 = 0
for i in range(n):
w, v = list(map(int, input().split()))
if i == 0:
w1 = w
for x in range(w, w + 4):
g[x] = []
g[w].append(v)
for w, values in list(g.items()):
values.sort(reverse=True)
sg = {}
sg[w1] = {}
sg[w1 + 1] = {}
sg[w1 + 2] = {}
sg[w1 + 3] = {}
for a in range(len(g[w1]) + 1):
sg[w1][a] = sum(g[w1][:a])
for b in range(len(g[w1 + 1]) + 1):
sg[w1 + 1][b] = sum(g[w1 + 1][:b])
for c in range(len(g[w1 + 2]) + 1):
sg[w1 + 2][c] = sum(g[w1 + 2][:c])
for d in range(len(g[w1 + 3]) + 1):
sg[w1 + 3][d] = sum(g[w1 + 3][:d])
res = 0
for a in range(len(g[w1]) + 1):
for b in range(len(g[w1 + 1]) + 1):
for c in range(len(g[w1 + 2]) + 1):
for d in range(len(g[w1 + 3]) + 1):
total_w = w1 * a + (w1 + 1) * b + (w1 + 2) * c + (w1 + 3) * d
if total_w > W:
continue
total_v = sg[w1][a] + sg[w1 + 1][b] + sg[w1 + 2][c] + sg[w1 + 3][d]
if total_v > res:
res = total_v
print(res)
| false | 13.636364 | [
"+sg = {}",
"+sg[w1] = {}",
"+sg[w1 + 1] = {}",
"+sg[w1 + 2] = {}",
"+sg[w1 + 3] = {}",
"+for a in range(len(g[w1]) + 1):",
"+ sg[w1][a] = sum(g[w1][:a])",
"+for b in range(len(g[w1 + 1]) + 1):",
"+ sg[w1 + 1][b] = sum(g[w1 + 1][:b])",
"+for c in range(len(g[w1 + 2]) + 1):",
"+ sg[w1 + 2][c] = sum(g[w1 + 2][:c])",
"+for d in range(len(g[w1 + 3]) + 1):",
"+ sg[w1 + 3][d] = sum(g[w1 + 3][:d])",
"- total_v = 0",
"- for i in range(a):",
"- total_v += g[w1][i]",
"- for i in range(b):",
"- total_v += g[w1 + 1][i]",
"- for i in range(c):",
"- total_v += g[w1 + 2][i]",
"- for i in range(d):",
"- total_v += g[w1 + 3][i]",
"+ total_v = sg[w1][a] + sg[w1 + 1][b] + sg[w1 + 2][c] + sg[w1 + 3][d]"
] | false | 0.038318 | 0.049985 | 0.766577 | [
"s870049372",
"s046578848"
] |
u597374218 | p02843 | python | s905881614 | s364172464 | 123 | 28 | 3,700 | 9,116 | Accepted | Accepted | 77.24 | X=int(eval(input()))
dp=[0]*(X+105)
dp[0]=1
for x in range(X):
if dp[x]==1:
for price in range(100,106):
dp[x+price]=1
print((dp[X])) | X=int(eval(input()))
div=X//100
mod=X%100
print((1 if 5*div>=mod else 0)) | 8 | 4 | 156 | 68 | X = int(eval(input()))
dp = [0] * (X + 105)
dp[0] = 1
for x in range(X):
if dp[x] == 1:
for price in range(100, 106):
dp[x + price] = 1
print((dp[X]))
| X = int(eval(input()))
div = X // 100
mod = X % 100
print((1 if 5 * div >= mod else 0))
| false | 50 | [
"-dp = [0] * (X + 105)",
"-dp[0] = 1",
"-for x in range(X):",
"- if dp[x] == 1:",
"- for price in range(100, 106):",
"- dp[x + price] = 1",
"-print((dp[X]))",
"+div = X // 100",
"+mod = X % 100",
"+print((1 if 5 * div >= mod else 0))"
] | false | 0.036322 | 0.036947 | 0.983098 | [
"s905881614",
"s364172464"
] |
u014333473 | p03836 | python | s195476739 | s519785820 | 29 | 26 | 9,196 | 9,172 | Accepted | Accepted | 10.34 | sx,sy,tx,ty=list(map(int,input().split()))
dx = tx - sx
dy = ty - sy
direction1 = 'U'*dy + 'R'*dx
direction2 = 'D'*dy + 'L'*dx
direction3 = 'L' + 'U'*(dy+1) + 'R'*(dx+1) + 'D'
direction4 = 'R' + 'D'*(dy+1) + 'L'*(dx+1) + 'U'
print((direction1+direction2+direction3+direction4)) | sx,sy,tx,ty=list(map(int,input().split()))
dx,dy=tx-sx,ty-sy
print((dy*'U'+dx*'R'+dy*'D'+(dx+1)*'L'+(dy+1)*'U'+(dx+1)*'R'+'D'+'R'+(dy+1)*'D'+(dx+1)*'L'+'U')) | 8 | 3 | 277 | 151 | sx, sy, tx, ty = list(map(int, input().split()))
dx = tx - sx
dy = ty - sy
direction1 = "U" * dy + "R" * dx
direction2 = "D" * dy + "L" * dx
direction3 = "L" + "U" * (dy + 1) + "R" * (dx + 1) + "D"
direction4 = "R" + "D" * (dy + 1) + "L" * (dx + 1) + "U"
print((direction1 + direction2 + direction3 + direction4))
| sx, sy, tx, ty = list(map(int, input().split()))
dx, dy = tx - sx, ty - sy
print(
(
dy * "U"
+ dx * "R"
+ dy * "D"
+ (dx + 1) * "L"
+ (dy + 1) * "U"
+ (dx + 1) * "R"
+ "D"
+ "R"
+ (dy + 1) * "D"
+ (dx + 1) * "L"
+ "U"
)
)
| false | 62.5 | [
"-dx = tx - sx",
"-dy = ty - sy",
"-direction1 = \"U\" * dy + \"R\" * dx",
"-direction2 = \"D\" * dy + \"L\" * dx",
"-direction3 = \"L\" + \"U\" * (dy + 1) + \"R\" * (dx + 1) + \"D\"",
"-direction4 = \"R\" + \"D\" * (dy + 1) + \"L\" * (dx + 1) + \"U\"",
"-print((direction1 + direction2 + direction3 + direction4))",
"+dx, dy = tx - sx, ty - sy",
"+print(",
"+ (",
"+ dy * \"U\"",
"+ + dx * \"R\"",
"+ + dy * \"D\"",
"+ + (dx + 1) * \"L\"",
"+ + (dy + 1) * \"U\"",
"+ + (dx + 1) * \"R\"",
"+ + \"D\"",
"+ + \"R\"",
"+ + (dy + 1) * \"D\"",
"+ + (dx + 1) * \"L\"",
"+ + \"U\"",
"+ )",
"+)"
] | false | 0.047299 | 0.049505 | 0.955445 | [
"s195476739",
"s519785820"
] |
u075012704 | p03806 | python | s641279108 | s861538213 | 700 | 348 | 133,212 | 143,412 | Accepted | Accepted | 50.29 | N, Ma, Mb = list(map(int, input().split()))
Drug = [list(map(int, input().split())) for i in range(N)]
dp = [[[float('inf')] * 401 for j in range(401)] for i in range(N + 1)]
dp[0][0][0] = 0
for i, (a, b, c) in enumerate(Drug):
for ma in range(401):
for mb in range(401):
if (ma + a < 401) and (mb + b < 401):
dp[i + 1][ma + a][mb + b] = min(dp[i + 1][ma + a][mb + b], dp[i][ma][mb] + c)
dp[i + 1][ma][mb] = min(dp[i + 1][ma][mb], dp[i][ma][mb])
ans = float('inf')
for i in range(1, 401):
if (Ma * i) < 401 and (Mb * i) < 401:
ans = min(ans, dp[-1][Ma * i][Mb * i])
else:
break
print((ans if ans != float('inf') else -1))
| N, Ma, Mb = list(map(int, input().split()))
Items = [list(map(int, input().split())) for _ in range(N)]
# dp[i][a][b] := i番目の薬品までみて、タイプA: xグラム, タイプB: yグラム を手に入れるために必要な最小費用
dp = [[[float('inf')] * 401 for j in range(401)] for i in range(N + 1)]
dp[0][0][0] = 0
for i, (a, b, c) in enumerate(Items):
for x in range(401):
for y in range(401):
dp[i + 1][x][y] = min(dp[i + 1][x][y], dp[i][x][y])
if x + a > 400 or y + b > 400:
continue
dp[i + 1][x + a][y + b] = min(dp[i + 1][x + a][y + b], dp[i][x][y] + c)
ans = float('inf')
i = 1
while Ma * i <= 400 and Mb * i <= 400:
ans = min(ans, dp[-1][Ma * i][Mb * i])
i += 1
print((ans if ans != float('inf') else -1))
| 21 | 20 | 714 | 743 | N, Ma, Mb = list(map(int, input().split()))
Drug = [list(map(int, input().split())) for i in range(N)]
dp = [[[float("inf")] * 401 for j in range(401)] for i in range(N + 1)]
dp[0][0][0] = 0
for i, (a, b, c) in enumerate(Drug):
for ma in range(401):
for mb in range(401):
if (ma + a < 401) and (mb + b < 401):
dp[i + 1][ma + a][mb + b] = min(
dp[i + 1][ma + a][mb + b], dp[i][ma][mb] + c
)
dp[i + 1][ma][mb] = min(dp[i + 1][ma][mb], dp[i][ma][mb])
ans = float("inf")
for i in range(1, 401):
if (Ma * i) < 401 and (Mb * i) < 401:
ans = min(ans, dp[-1][Ma * i][Mb * i])
else:
break
print((ans if ans != float("inf") else -1))
| N, Ma, Mb = list(map(int, input().split()))
Items = [list(map(int, input().split())) for _ in range(N)]
# dp[i][a][b] := i番目の薬品までみて、タイプA: xグラム, タイプB: yグラム を手に入れるために必要な最小費用
dp = [[[float("inf")] * 401 for j in range(401)] for i in range(N + 1)]
dp[0][0][0] = 0
for i, (a, b, c) in enumerate(Items):
for x in range(401):
for y in range(401):
dp[i + 1][x][y] = min(dp[i + 1][x][y], dp[i][x][y])
if x + a > 400 or y + b > 400:
continue
dp[i + 1][x + a][y + b] = min(dp[i + 1][x + a][y + b], dp[i][x][y] + c)
ans = float("inf")
i = 1
while Ma * i <= 400 and Mb * i <= 400:
ans = min(ans, dp[-1][Ma * i][Mb * i])
i += 1
print((ans if ans != float("inf") else -1))
| false | 4.761905 | [
"-Drug = [list(map(int, input().split())) for i in range(N)]",
"+Items = [list(map(int, input().split())) for _ in range(N)]",
"+# dp[i][a][b] := i番目の薬品までみて、タイプA: xグラム, タイプB: yグラム を手に入れるために必要な最小費用",
"-for i, (a, b, c) in enumerate(Drug):",
"- for ma in range(401):",
"- for mb in range(401):",
"- if (ma + a < 401) and (mb + b < 401):",
"- dp[i + 1][ma + a][mb + b] = min(",
"- dp[i + 1][ma + a][mb + b], dp[i][ma][mb] + c",
"- )",
"- dp[i + 1][ma][mb] = min(dp[i + 1][ma][mb], dp[i][ma][mb])",
"+for i, (a, b, c) in enumerate(Items):",
"+ for x in range(401):",
"+ for y in range(401):",
"+ dp[i + 1][x][y] = min(dp[i + 1][x][y], dp[i][x][y])",
"+ if x + a > 400 or y + b > 400:",
"+ continue",
"+ dp[i + 1][x + a][y + b] = min(dp[i + 1][x + a][y + b], dp[i][x][y] + c)",
"-for i in range(1, 401):",
"- if (Ma * i) < 401 and (Mb * i) < 401:",
"- ans = min(ans, dp[-1][Ma * i][Mb * i])",
"- else:",
"- break",
"+i = 1",
"+while Ma * i <= 400 and Mb * i <= 400:",
"+ ans = min(ans, dp[-1][Ma * i][Mb * i])",
"+ i += 1"
] | false | 1.150327 | 1.158937 | 0.99257 | [
"s641279108",
"s861538213"
] |
u864197622 | p03128 | python | s700148003 | s883256769 | 154 | 83 | 3,192 | 3,188 | Accepted | Accepted | 46.1 | def intlog10(n):
if n <= 0:
return -1
i = 0
while 10**i <= n:
i += 1
return i-1
N, M = list(map(int, input().split()))
A = [int(a) for a in input().split()]
L = [2, 5, 5, 4, 5, 6, 3, 7, 6]
B = [[A[i], L[A[i]-1]] for i in range(M)]
best = sorted(B, key = lambda x: x[1]*10-x[0])[0]
adj = 0
if N > 500:
adj = (N - 500)//best[1]
N -= best[1] * adj
X = [0] + [-10**9] * N
bpre = -1
ll = 1
for i in range(1, N+1):
if i > 50 and i < N-50:
X[i] = X[i-best[1]]*10 + best[0]
else:
for b in B:
if b[1] <= i:
if X[i-b[1]] == 0:
if b[0] > X[i]:
X[i] = b[0]
bpre = b
ll = 0
else:
if X[i-b[1]]*10 + b[0] < X[i-b[1]] + b[0] * (10**intlog10(X[i-b[1]])):
lll = 1
if max(X[i-b[1]]*10 + b[0], X[i-b[1]] + b[0] * (10**intlog10(X[i-b[1]]))) > X[i]:
X[i] = max(X[i-b[1]]*10 + b[0], X[i-b[1]] + b[0] * (10**intlog10(X[i-b[1]])))
ll = lll
bpre = b
ans = str(X[N])
if adj > 0:
ans = ans[:50] + str(best[0]) * adj + ans[50:]
print(ans)
# print(len(ans))
| def intlog10(n):
if n <= 0:
return -1
i = 0
while 10**i <= n:
i += 1
return i-1
N, M = list(map(int, input().split()))
A = [int(a) for a in input().split()]
L = [2, 5, 5, 4, 5, 6, 3, 7, 6]
B = [[A[i], L[A[i]-1]] for i in range(M)]
best = sorted(B, key = lambda x: x[1]*10-x[0])[0]
adj = 0
if N > 500:
adj = (N - 500)//best[1]
N -= best[1] * adj
X = [0] + [-10**9] * N
for i in range(1, N+1):
if i > 50 and i < N-50:
X[i] = X[i-best[1]]*10 + best[0]
else:
for b in B:
if b[1] <= i:
if X[i-b[1]] == 0:
X[i] = max(X[i], b[0])
else:
X[i] = max(X[i], X[i-b[1]]*10 + b[0], X[i-b[1]] + b[0] * (10**intlog10(X[i-b[1]])))
ans = str(X[N])
if adj > 0:
ans = ans[:50] + str(best[0]) * adj + ans[50:]
print(ans) | 53 | 38 | 1,345 | 892 | def intlog10(n):
if n <= 0:
return -1
i = 0
while 10**i <= n:
i += 1
return i - 1
N, M = list(map(int, input().split()))
A = [int(a) for a in input().split()]
L = [2, 5, 5, 4, 5, 6, 3, 7, 6]
B = [[A[i], L[A[i] - 1]] for i in range(M)]
best = sorted(B, key=lambda x: x[1] * 10 - x[0])[0]
adj = 0
if N > 500:
adj = (N - 500) // best[1]
N -= best[1] * adj
X = [0] + [-(10**9)] * N
bpre = -1
ll = 1
for i in range(1, N + 1):
if i > 50 and i < N - 50:
X[i] = X[i - best[1]] * 10 + best[0]
else:
for b in B:
if b[1] <= i:
if X[i - b[1]] == 0:
if b[0] > X[i]:
X[i] = b[0]
bpre = b
ll = 0
else:
if X[i - b[1]] * 10 + b[0] < X[i - b[1]] + b[0] * (
10 ** intlog10(X[i - b[1]])
):
lll = 1
if (
max(
X[i - b[1]] * 10 + b[0],
X[i - b[1]] + b[0] * (10 ** intlog10(X[i - b[1]])),
)
> X[i]
):
X[i] = max(
X[i - b[1]] * 10 + b[0],
X[i - b[1]] + b[0] * (10 ** intlog10(X[i - b[1]])),
)
ll = lll
bpre = b
ans = str(X[N])
if adj > 0:
ans = ans[:50] + str(best[0]) * adj + ans[50:]
print(ans)
# print(len(ans))
| def intlog10(n):
if n <= 0:
return -1
i = 0
while 10**i <= n:
i += 1
return i - 1
N, M = list(map(int, input().split()))
A = [int(a) for a in input().split()]
L = [2, 5, 5, 4, 5, 6, 3, 7, 6]
B = [[A[i], L[A[i] - 1]] for i in range(M)]
best = sorted(B, key=lambda x: x[1] * 10 - x[0])[0]
adj = 0
if N > 500:
adj = (N - 500) // best[1]
N -= best[1] * adj
X = [0] + [-(10**9)] * N
for i in range(1, N + 1):
if i > 50 and i < N - 50:
X[i] = X[i - best[1]] * 10 + best[0]
else:
for b in B:
if b[1] <= i:
if X[i - b[1]] == 0:
X[i] = max(X[i], b[0])
else:
X[i] = max(
X[i],
X[i - b[1]] * 10 + b[0],
X[i - b[1]] + b[0] * (10 ** intlog10(X[i - b[1]])),
)
ans = str(X[N])
if adj > 0:
ans = ans[:50] + str(best[0]) * adj + ans[50:]
print(ans)
| false | 28.301887 | [
"-bpre = -1",
"-ll = 1",
"- if b[0] > X[i]:",
"- X[i] = b[0]",
"- bpre = b",
"- ll = 0",
"+ X[i] = max(X[i], b[0])",
"- if X[i - b[1]] * 10 + b[0] < X[i - b[1]] + b[0] * (",
"- 10 ** intlog10(X[i - b[1]])",
"- ):",
"- lll = 1",
"- if (",
"- max(",
"- X[i - b[1]] * 10 + b[0],",
"- X[i - b[1]] + b[0] * (10 ** intlog10(X[i - b[1]])),",
"- )",
"- > X[i]",
"- ):",
"- X[i] = max(",
"- X[i - b[1]] * 10 + b[0],",
"- X[i - b[1]] + b[0] * (10 ** intlog10(X[i - b[1]])),",
"- )",
"- ll = lll",
"- bpre = b",
"+ X[i] = max(",
"+ X[i],",
"+ X[i - b[1]] * 10 + b[0],",
"+ X[i - b[1]] + b[0] * (10 ** intlog10(X[i - b[1]])),",
"+ )",
"-# print(len(ans))"
] | false | 0.035415 | 0.035138 | 1.007879 | [
"s700148003",
"s883256769"
] |
u312025627 | p03993 | python | s999827239 | s143647909 | 256 | 206 | 74,604 | 52,908 | Accepted | Accepted | 19.53 | def main():
N = int(eval(input()))
A = [int(i)-1 for i in input().split()]
edge = [set() for _ in range(N)]
for i, a in enumerate(A):
edge[i].add(a)
ans = 0
for i, a in enumerate(A):
if i in edge[a]:
ans += 1
print((ans//2))
if __name__ == '__main__':
main()
| def main():
N = int(eval(input()))
A = [int(i)-1 for i in input().split()]
ans = 0
for i, a in enumerate(A):
if A[a] == i:
ans += 1
print((ans//2))
if __name__ == '__main__':
main()
| 18 | 13 | 333 | 233 | def main():
N = int(eval(input()))
A = [int(i) - 1 for i in input().split()]
edge = [set() for _ in range(N)]
for i, a in enumerate(A):
edge[i].add(a)
ans = 0
for i, a in enumerate(A):
if i in edge[a]:
ans += 1
print((ans // 2))
if __name__ == "__main__":
main()
| def main():
N = int(eval(input()))
A = [int(i) - 1 for i in input().split()]
ans = 0
for i, a in enumerate(A):
if A[a] == i:
ans += 1
print((ans // 2))
if __name__ == "__main__":
main()
| false | 27.777778 | [
"- edge = [set() for _ in range(N)]",
"- for i, a in enumerate(A):",
"- edge[i].add(a)",
"- if i in edge[a]:",
"+ if A[a] == i:"
] | false | 0.057983 | 0.056453 | 1.027098 | [
"s999827239",
"s143647909"
] |
u094191970 | p02623 | python | s062900448 | s143000306 | 341 | 283 | 47,512 | 49,332 | Accepted | Accepted | 17.01 | from bisect import *
n,m,k=list(map(int,input().split()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
a_b=[0]
for i in range(1,n+1):
a_b.append(a_b[i-1]+a[i-1])
b_b=[0]
for i in range(1,m+1):
b_b.append(b_b[i-1]+b[i-1])
ans=0
for i in range(n+1):
t_ans=i
if a_b[i]>k:
break
t_ans+=bisect_right(b_b,k-a_b[i])-1
ans=max(ans,t_ans)
print(ans) | from sys import stdin
nii=lambda:list(map(int,stdin.readline().split()))
lnii=lambda:list(map(int,stdin.readline().split()))
from bisect import bisect_right
from itertools import accumulate
n,m,k=nii()
a=lnii()
b=lnii()
ar=[0]+list(accumulate(a))
br=list(accumulate(b))
ans=0
for i in range(n+1):
time=ar[i]
if time>k:
break
t_ans=i
inx=bisect_right(br,k-time)
t_ans+=inx
ans=max(ans,t_ans)
print(ans) | 23 | 22 | 398 | 434 | from bisect import *
n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a_b = [0]
for i in range(1, n + 1):
a_b.append(a_b[i - 1] + a[i - 1])
b_b = [0]
for i in range(1, m + 1):
b_b.append(b_b[i - 1] + b[i - 1])
ans = 0
for i in range(n + 1):
t_ans = i
if a_b[i] > k:
break
t_ans += bisect_right(b_b, k - a_b[i]) - 1
ans = max(ans, t_ans)
print(ans)
| from sys import stdin
nii = lambda: list(map(int, stdin.readline().split()))
lnii = lambda: list(map(int, stdin.readline().split()))
from bisect import bisect_right
from itertools import accumulate
n, m, k = nii()
a = lnii()
b = lnii()
ar = [0] + list(accumulate(a))
br = list(accumulate(b))
ans = 0
for i in range(n + 1):
time = ar[i]
if time > k:
break
t_ans = i
inx = bisect_right(br, k - time)
t_ans += inx
ans = max(ans, t_ans)
print(ans)
| false | 4.347826 | [
"-from bisect import *",
"+from sys import stdin",
"-n, m, k = list(map(int, input().split()))",
"-a = list(map(int, input().split()))",
"-b = list(map(int, input().split()))",
"-a_b = [0]",
"-for i in range(1, n + 1):",
"- a_b.append(a_b[i - 1] + a[i - 1])",
"-b_b = [0]",
"-for i in range(1, m + 1):",
"- b_b.append(b_b[i - 1] + b[i - 1])",
"+nii = lambda: list(map(int, stdin.readline().split()))",
"+lnii = lambda: list(map(int, stdin.readline().split()))",
"+from bisect import bisect_right",
"+from itertools import accumulate",
"+",
"+n, m, k = nii()",
"+a = lnii()",
"+b = lnii()",
"+ar = [0] + list(accumulate(a))",
"+br = list(accumulate(b))",
"+ time = ar[i]",
"+ if time > k:",
"+ break",
"- if a_b[i] > k:",
"- break",
"- t_ans += bisect_right(b_b, k - a_b[i]) - 1",
"+ inx = bisect_right(br, k - time)",
"+ t_ans += inx"
] | false | 0.039099 | 0.044327 | 0.882066 | [
"s062900448",
"s143000306"
] |
u774160580 | p02971 | python | s606894777 | s095687560 | 920 | 557 | 70,488 | 14,112 | Accepted | Accepted | 39.46 | def main():
N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]
A_sort = sorted(A)
if (A_sort[-1] == A_sort[-2]):
for i in range(N):
print((A_sort[-1]))
else:
for i in range(N):
if(A[i]==A_sort[-1]):
print((A_sort[-2]))
else:
print((A_sort[-1]))
main()
| N = int(eval(input()))
x = [int(eval(input())) for i in range(N)]
x_sort = sorted(x, reverse=True)
for i in range(N):
if x[i] == x_sort[0]:
print((x_sort[1]))
else:
print((x_sort[0]))
| 15 | 8 | 368 | 199 | def main():
N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]
A_sort = sorted(A)
if A_sort[-1] == A_sort[-2]:
for i in range(N):
print((A_sort[-1]))
else:
for i in range(N):
if A[i] == A_sort[-1]:
print((A_sort[-2]))
else:
print((A_sort[-1]))
main()
| N = int(eval(input()))
x = [int(eval(input())) for i in range(N)]
x_sort = sorted(x, reverse=True)
for i in range(N):
if x[i] == x_sort[0]:
print((x_sort[1]))
else:
print((x_sort[0]))
| false | 46.666667 | [
"-def main():",
"- N = int(eval(input()))",
"- A = [int(eval(input())) for i in range(N)]",
"- A_sort = sorted(A)",
"- if A_sort[-1] == A_sort[-2]:",
"- for i in range(N):",
"- print((A_sort[-1]))",
"+N = int(eval(input()))",
"+x = [int(eval(input())) for i in range(N)]",
"+x_sort = sorted(x, reverse=True)",
"+for i in range(N):",
"+ if x[i] == x_sort[0]:",
"+ print((x_sort[1]))",
"- for i in range(N):",
"- if A[i] == A_sort[-1]:",
"- print((A_sort[-2]))",
"- else:",
"- print((A_sort[-1]))",
"-",
"-",
"-main()",
"+ print((x_sort[0]))"
] | false | 0.044806 | 0.044285 | 1.011764 | [
"s606894777",
"s095687560"
] |
u991567869 | p02859 | python | s177401789 | s125817808 | 25 | 17 | 2,940 | 2,940 | Accepted | Accepted | 32 | r = int(eval(input()))
r = r**2
print(r) | r = int(eval(input()))
r = r*r
print(r) | 3 | 3 | 36 | 35 | r = int(eval(input()))
r = r**2
print(r)
| r = int(eval(input()))
r = r * r
print(r)
| false | 0 | [
"-r = r**2",
"+r = r * r"
] | false | 0.039932 | 0.046101 | 0.86618 | [
"s177401789",
"s125817808"
] |
u156163787 | p03633 | python | s106165066 | s330064177 | 282 | 172 | 66,028 | 38,384 | Accepted | Accepted | 39.01 | #from math import gcd
from fractions import gcd
n=int(eval(input()))
res=1
for _ in range(n):
x=int(eval(input()))
res=res//gcd(res,x)*x
print(res)
| from functools import reduce
def gcd(a,b):
while b:
a,b=b,a%b
return a
def lcm(a,b):
return a//gcd(a,b)*b
n=int(eval(input()))
a=[int(eval(input())) for _ in range(n)]
print((reduce(lcm,a)))
| 10 | 14 | 155 | 214 | # from math import gcd
from fractions import gcd
n = int(eval(input()))
res = 1
for _ in range(n):
x = int(eval(input()))
res = res // gcd(res, x) * x
print(res)
| from functools import reduce
def gcd(a, b):
while b:
a, b = b, a % b
return a
def lcm(a, b):
return a // gcd(a, b) * b
n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
print((reduce(lcm, a)))
| false | 28.571429 | [
"-# from math import gcd",
"-from fractions import gcd",
"+from functools import reduce",
"+",
"+",
"+def gcd(a, b):",
"+ while b:",
"+ a, b = b, a % b",
"+ return a",
"+",
"+",
"+def lcm(a, b):",
"+ return a // gcd(a, b) * b",
"+",
"-res = 1",
"-for _ in range(n):",
"- x = int(eval(input()))",
"- res = res // gcd(res, x) * x",
"-print(res)",
"+a = [int(eval(input())) for _ in range(n)]",
"+print((reduce(lcm, a)))"
] | false | 0.05313 | 0.036098 | 1.471834 | [
"s106165066",
"s330064177"
] |
u102461423 | p03185 | python | s883828840 | s388254572 | 549 | 506 | 41,540 | 41,540 | Accepted | Accepted | 7.83 | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from collections import deque
N,C,*H = list(map(int,read().split()))
class CHT:
"""
f_i = a_ix + b_i とする。f_i の追加および、min_i f(x) の取得ができるデータ構造。
ただし、傾き a_i は昇順に追加されなければならない。
また、クエリ x も昇順に実行されなければならない。
"""
def __init__(self):
self.funcs = deque()
def add(self,a,b):
funcs = self.funcs
while len(funcs) >= 2:
a1,b1 = funcs[-2]
a2,b2 = funcs[-1]
if (a2-a1)*(b-b2) < (b2-b1)*(a-a2):
break
funcs.pop()
funcs.append((a,b))
def query(self,x):
funcs = self.funcs
a,b = funcs[0]
y = a*x+b
while len(funcs) >= 2:
a2,b2 = self.funcs[1]
y2 = a2*x+b2
if y < y2:
break
y = y2
self.funcs.popleft()
return y
dp = [0] * N
cht = CHT()
h = H[0]
cht.add(-2*h, h*h)
for i,h in enumerate(H[1:],1):
x = cht.query(h) + h*h + C
dp[i] = x
cht.add(-2*h, h*h + x)
answer = dp[-1]
print(answer) | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from collections import deque
N,C,*H = list(map(int,read().split()))
class CHT:
"""
f_i = a_ix + b_i とする。f_i の追加および、min_i f(x) の取得ができるデータ構造。
ただし、傾き a_i は昇順に追加されなければならない。
また、クエリ x も昇順に実行されなければならない。
"""
def __init__(self):
self.funcs = deque()
def add(self,a,b):
funcs = self.funcs
while len(funcs) >= 2:
a1,b1 = funcs[-2]
a2,b2 = funcs[-1]
if (a2-a1)*(b-b2) < (b2-b1)*(a-a2):
break
funcs.pop()
funcs.append((a,b))
def query(self,x):
funcs = self.funcs
a,b = funcs[0]
y = a*x+b
while len(funcs) >= 2:
a2,b2 = self.funcs[1]
y2 = a2*x+b2
if y < y2:
break
y = y2
self.funcs.popleft()
return y
dp = [0] * N
cht = CHT()
h = H[0]
add = cht.add
query = cht.query
add(-2*h, h*h)
for i,h in enumerate(H[1:],1):
x = query(h) + h*h + C
dp[i] = x
add(-2*h, h*h + x)
answer = dp[-1]
print(answer)
| 53 | 56 | 1,187 | 1,212 | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from collections import deque
N, C, *H = list(map(int, read().split()))
class CHT:
"""
f_i = a_ix + b_i とする。f_i の追加および、min_i f(x) の取得ができるデータ構造。
ただし、傾き a_i は昇順に追加されなければならない。
また、クエリ x も昇順に実行されなければならない。
"""
def __init__(self):
self.funcs = deque()
def add(self, a, b):
funcs = self.funcs
while len(funcs) >= 2:
a1, b1 = funcs[-2]
a2, b2 = funcs[-1]
if (a2 - a1) * (b - b2) < (b2 - b1) * (a - a2):
break
funcs.pop()
funcs.append((a, b))
def query(self, x):
funcs = self.funcs
a, b = funcs[0]
y = a * x + b
while len(funcs) >= 2:
a2, b2 = self.funcs[1]
y2 = a2 * x + b2
if y < y2:
break
y = y2
self.funcs.popleft()
return y
dp = [0] * N
cht = CHT()
h = H[0]
cht.add(-2 * h, h * h)
for i, h in enumerate(H[1:], 1):
x = cht.query(h) + h * h + C
dp[i] = x
cht.add(-2 * h, h * h + x)
answer = dp[-1]
print(answer)
| import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from collections import deque
N, C, *H = list(map(int, read().split()))
class CHT:
"""
f_i = a_ix + b_i とする。f_i の追加および、min_i f(x) の取得ができるデータ構造。
ただし、傾き a_i は昇順に追加されなければならない。
また、クエリ x も昇順に実行されなければならない。
"""
def __init__(self):
self.funcs = deque()
def add(self, a, b):
funcs = self.funcs
while len(funcs) >= 2:
a1, b1 = funcs[-2]
a2, b2 = funcs[-1]
if (a2 - a1) * (b - b2) < (b2 - b1) * (a - a2):
break
funcs.pop()
funcs.append((a, b))
def query(self, x):
funcs = self.funcs
a, b = funcs[0]
y = a * x + b
while len(funcs) >= 2:
a2, b2 = self.funcs[1]
y2 = a2 * x + b2
if y < y2:
break
y = y2
self.funcs.popleft()
return y
dp = [0] * N
cht = CHT()
h = H[0]
add = cht.add
query = cht.query
add(-2 * h, h * h)
for i, h in enumerate(H[1:], 1):
x = query(h) + h * h + C
dp[i] = x
add(-2 * h, h * h + x)
answer = dp[-1]
print(answer)
| false | 5.357143 | [
"-cht.add(-2 * h, h * h)",
"+add = cht.add",
"+query = cht.query",
"+add(-2 * h, h * h)",
"- x = cht.query(h) + h * h + C",
"+ x = query(h) + h * h + C",
"- cht.add(-2 * h, h * h + x)",
"+ add(-2 * h, h * h + x)"
] | false | 0.0386 | 0.045879 | 0.841336 | [
"s883828840",
"s388254572"
] |
u760527120 | p03370 | python | s690838776 | s100146174 | 37 | 18 | 3,060 | 2,940 | Accepted | Accepted | 51.35 | N, X = list(map(int, input().split()))
M = [int(eval(input())) for _ in range(N)]
X -= sum(M)
m = min(M)
ans = len(M)
while X >= m:
X -= m
ans += 1
print(ans) | N, X = list(map(int, input().split()))
M = [int(eval(input())) for _ in range(N)]
print((len(M) + (X - sum(M)) // min(M))) | 9 | 3 | 164 | 116 | N, X = list(map(int, input().split()))
M = [int(eval(input())) for _ in range(N)]
X -= sum(M)
m = min(M)
ans = len(M)
while X >= m:
X -= m
ans += 1
print(ans)
| N, X = list(map(int, input().split()))
M = [int(eval(input())) for _ in range(N)]
print((len(M) + (X - sum(M)) // min(M)))
| false | 66.666667 | [
"-X -= sum(M)",
"-m = min(M)",
"-ans = len(M)",
"-while X >= m:",
"- X -= m",
"- ans += 1",
"-print(ans)",
"+print((len(M) + (X - sum(M)) // min(M)))"
] | false | 0.03342 | 0.039371 | 0.848849 | [
"s690838776",
"s100146174"
] |
u745087332 | p03209 | python | s536736604 | s321525215 | 22 | 20 | 3,316 | 3,064 | Accepted | Accepted | 9.09 | # coding:utf-8
import sys
input = sys.stdin.readline
INF = float('inf')
MOD = 10 ** 9 + 7
def inpl(): return list(map(int, input().split()))
N, X = inpl()
ALL, P = [1], [1]
for _ in range(N):
ALL.append(ALL[-1] * 2 + 3)
P.append(P[-1] * 2 + 1)
# | B (X = ALL[N])
# |
# | N - 1バーガー(上)
# |
# | P (X = ALL[N] // 2 + 1)
# |
# | N - 1バーガー(下)
# |
# | B (X = 1)
def func(N, X):
if N == 0:
return 1
if X == 1:
return 0
elif X == ALL[N]:
return P[N]
elif X == ALL[N] // 2 + 1:
return P[N] // 2 + 1
else:
if X < ALL[N] // 2 + 1: # 下のN - 1バーガー
return func(N - 1, X - 1)
else: # 上のN - 1バーガー
return func(N - 1, X - ALL[N] // 2 - 1) + P[N] // 2 + 1
print((func(N, X)))
| # coding:utf-8
import sys
input = sys.stdin.readline
INF = float('inf')
MOD = 10 ** 9 + 7
def inpl(): return list(map(int, input().split()))
N, X = inpl()
ALL, P = [1], [1]
for _ in range(N):
ALL.append(ALL[-1] * 2 + 3)
P.append(P[-1] * 2 + 1)
# | B (X = ALL[N])
# |
# | N - 1バーガー(上)
# |
# | P (X = ALL[N] // 2 + 1)
# |
# | N - 1バーガー(下)
# |
# | B (X = 1)
def func(N, X):
if N == 0: # レベル0バーガー
return 1
if X == 1: # 下のB
return 0
elif X == ALL[N]: # 上のB
return P[N]
elif X == ALL[N] // 2 + 1: # 真ん中のP
return P[N - 1] + 1
else:
if X < ALL[N] // 2 + 1: # 下のN - 1バーガー
return func(N - 1, X - 1)
else: # 上のN - 1バーガー
return func(N - 1, X - ALL[N] // 2 - 1) + P[N - 1] + 1
print((func(N, X)))
| 47 | 47 | 813 | 846 | # coding:utf-8
import sys
input = sys.stdin.readline
INF = float("inf")
MOD = 10**9 + 7
def inpl():
return list(map(int, input().split()))
N, X = inpl()
ALL, P = [1], [1]
for _ in range(N):
ALL.append(ALL[-1] * 2 + 3)
P.append(P[-1] * 2 + 1)
# | B (X = ALL[N])
# |
# | N - 1バーガー(上)
# |
# | P (X = ALL[N] // 2 + 1)
# |
# | N - 1バーガー(下)
# |
# | B (X = 1)
def func(N, X):
if N == 0:
return 1
if X == 1:
return 0
elif X == ALL[N]:
return P[N]
elif X == ALL[N] // 2 + 1:
return P[N] // 2 + 1
else:
if X < ALL[N] // 2 + 1: # 下のN - 1バーガー
return func(N - 1, X - 1)
else: # 上のN - 1バーガー
return func(N - 1, X - ALL[N] // 2 - 1) + P[N] // 2 + 1
print((func(N, X)))
| # coding:utf-8
import sys
input = sys.stdin.readline
INF = float("inf")
MOD = 10**9 + 7
def inpl():
return list(map(int, input().split()))
N, X = inpl()
ALL, P = [1], [1]
for _ in range(N):
ALL.append(ALL[-1] * 2 + 3)
P.append(P[-1] * 2 + 1)
# | B (X = ALL[N])
# |
# | N - 1バーガー(上)
# |
# | P (X = ALL[N] // 2 + 1)
# |
# | N - 1バーガー(下)
# |
# | B (X = 1)
def func(N, X):
if N == 0: # レベル0バーガー
return 1
if X == 1: # 下のB
return 0
elif X == ALL[N]: # 上のB
return P[N]
elif X == ALL[N] // 2 + 1: # 真ん中のP
return P[N - 1] + 1
else:
if X < ALL[N] // 2 + 1: # 下のN - 1バーガー
return func(N - 1, X - 1)
else: # 上のN - 1バーガー
return func(N - 1, X - ALL[N] // 2 - 1) + P[N - 1] + 1
print((func(N, X)))
| false | 0 | [
"- if N == 0:",
"+ if N == 0: # レベル0バーガー",
"- if X == 1:",
"+ if X == 1: # 下のB",
"- elif X == ALL[N]:",
"+ elif X == ALL[N]: # 上のB",
"- elif X == ALL[N] // 2 + 1:",
"- return P[N] // 2 + 1",
"+ elif X == ALL[N] // 2 + 1: # 真ん中のP",
"+ return P[N - 1] + 1",
"- return func(N - 1, X - ALL[N] // 2 - 1) + P[N] // 2 + 1",
"+ return func(N - 1, X - ALL[N] // 2 - 1) + P[N - 1] + 1"
] | false | 0.035717 | 0.040742 | 0.876682 | [
"s536736604",
"s321525215"
] |
u761320129 | p03588 | python | s287763108 | s470707338 | 391 | 208 | 18,776 | 22,504 | Accepted | Accepted | 46.8 | N = int(eval(input()))
src = [tuple(map(int,input().split())) for i in range(N)]
src.sort()
print((src[-1][0] + src[-1][1])) | N = int(eval(input()))
AB = [tuple(map(int,input().split())) for i in range(N)]
a,b = max(AB)
print((a+b)) | 5 | 4 | 121 | 101 | N = int(eval(input()))
src = [tuple(map(int, input().split())) for i in range(N)]
src.sort()
print((src[-1][0] + src[-1][1]))
| N = int(eval(input()))
AB = [tuple(map(int, input().split())) for i in range(N)]
a, b = max(AB)
print((a + b))
| false | 20 | [
"-src = [tuple(map(int, input().split())) for i in range(N)]",
"-src.sort()",
"-print((src[-1][0] + src[-1][1]))",
"+AB = [tuple(map(int, input().split())) for i in range(N)]",
"+a, b = max(AB)",
"+print((a + b))"
] | false | 0.038982 | 0.038691 | 1.007513 | [
"s287763108",
"s470707338"
] |
u894258749 | p02850 | python | s021777341 | s865528433 | 685 | 585 | 90,004 | 85,152 | Accepted | Accepted | 14.6 | import sys
sys.setrecursionlimit(10**9)
input = lambda: sys.stdin.readline().rstrip()
inpl = lambda: list(map(int,input().split()))
N = int(eval(input()))
edge = [set() for _ in range(N)]
ab = []
for i in range(N-1):
a, b = inpl()
a -= 1
b -= 1
ab.append((a,b))
edge[a].add(i)
edge[b].add(i)
K = 0
ans = [0]*(N-1)
def dfs(node, prev=0):
global K
c = 0
for i in edge[node]:
c += 1
if c == prev:
c += 1
a, b = ab[i]
if node == a:
x = b
else:
x = a
edge[x].remove(i)
ans[i] = c
dfs(x, c)
if c >= K:
K = c
dfs(0)
print(K)
for i in range(N-1):
print((ans[i]))
| import sys
input = lambda: sys.stdin.readline().rstrip()
inpl = lambda: list(map(int,input().split()))
N = int(eval(input()))
edge = [set() for _ in range(N)]
ab = []
for i in range(N-1):
a, b = inpl()
a -= 1
b -= 1
ab.append((a,b))
edge[a].add(i)
edge[b].add(i)
K = 0
ans = [0]*(N-1)
pool = [(0,0)]
while pool:
node, prev = pool.pop()
c = 0
for i in edge[node]:
c += 1
if c == prev:
c += 1
a, b = ab[i]
if node == a:
x = b
else:
x = a
edge[x].remove(i)
ans[i] = c
pool.append((x,c))
if c >= K:
K = c
print(K)
for i in range(N-1):
print((ans[i]))
| 39 | 38 | 739 | 730 | import sys
sys.setrecursionlimit(10**9)
input = lambda: sys.stdin.readline().rstrip()
inpl = lambda: list(map(int, input().split()))
N = int(eval(input()))
edge = [set() for _ in range(N)]
ab = []
for i in range(N - 1):
a, b = inpl()
a -= 1
b -= 1
ab.append((a, b))
edge[a].add(i)
edge[b].add(i)
K = 0
ans = [0] * (N - 1)
def dfs(node, prev=0):
global K
c = 0
for i in edge[node]:
c += 1
if c == prev:
c += 1
a, b = ab[i]
if node == a:
x = b
else:
x = a
edge[x].remove(i)
ans[i] = c
dfs(x, c)
if c >= K:
K = c
dfs(0)
print(K)
for i in range(N - 1):
print((ans[i]))
| import sys
input = lambda: sys.stdin.readline().rstrip()
inpl = lambda: list(map(int, input().split()))
N = int(eval(input()))
edge = [set() for _ in range(N)]
ab = []
for i in range(N - 1):
a, b = inpl()
a -= 1
b -= 1
ab.append((a, b))
edge[a].add(i)
edge[b].add(i)
K = 0
ans = [0] * (N - 1)
pool = [(0, 0)]
while pool:
node, prev = pool.pop()
c = 0
for i in edge[node]:
c += 1
if c == prev:
c += 1
a, b = ab[i]
if node == a:
x = b
else:
x = a
edge[x].remove(i)
ans[i] = c
pool.append((x, c))
if c >= K:
K = c
print(K)
for i in range(N - 1):
print((ans[i]))
| false | 2.564103 | [
"-sys.setrecursionlimit(10**9)",
"-",
"-",
"-def dfs(node, prev=0):",
"- global K",
"+pool = [(0, 0)]",
"+while pool:",
"+ node, prev = pool.pop()",
"- dfs(x, c)",
"+ pool.append((x, c))",
"-",
"-",
"-dfs(0)"
] | false | 0.048068 | 0.047678 | 1.008178 | [
"s021777341",
"s865528433"
] |
u075595666 | p02794 | python | s682048381 | s833697304 | 1,445 | 164 | 74,648 | 74,244 | Accepted | Accepted | 88.65 | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from collections import deque
n = int(readline())
g = [[] * n for i in range(n)]
for i in range(n-1):
u, v = list(map(int,readline().split()))
u -= 1
v -= 1
g[u].append(v)
g[v].append(u)
m = int(readline())
c = []
for i in range(m):
u, v = list(map(int,readline().split()))
u -= 1
v -= 1
que = deque()
que.append((u,set()))
chk = [False]*n
chk[u] = True
while que:
now,L = que.popleft()
if now == v:
c.append(L)
break
for i in g[now]:
if not chk[i]:
chk[i] = True
mi = min(now,i)
ma = max(now,i)
que.append((i,L|{mi*100+ma}))
import itertools
#print(c)
ans = 1<<(n-1)
for i in range(1,m+1):
for j in itertools.combinations(c,i):
K = set()
for k in j:
K |= k
l = len(K)
ans += pow(-1,i)*pow(2,n-1-l)
print(ans) | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from collections import deque,defaultdict
def all_bit_count(n):
c = (n & 0x5555555555555555) + ((n>>1) & 0x5555555555555555)
c = (c & 0x3333333333333333) + ((c>>2) & 0x3333333333333333)
c = (c & 0x0f0f0f0f0f0f0f0f) + ((c>>4) & 0x0f0f0f0f0f0f0f0f)
c = (c & 0x00ff00ff00ff00ff) + ((c>>8) & 0x00ff00ff00ff00ff)
c = (c & 0x0000ffff0000ffff) + ((c>>16) & 0x0000ffff0000ffff)
c = (c & 0x00000000ffffffff) + ((c>>32) & 0x00000000ffffffff)
return c
n = int(readline())
d = defaultdict(int)
cnt = 1
g = [[] * n for i in range(n)]
for i in range(n-1):
u, v = list(map(int,readline().split()))
u -= 1
v -= 1
g[u].append(v)
g[v].append(u)
m = int(readline())
c = []
for i in range(m):
u, v = list(map(int,readline().split()))
u -= 1
v -= 1
que = deque()
que.append((u,0))
chk = [False]*n
chk[u] = True
while que:
now,L = que.popleft()
if now == v:
c.append(L)
break
for i in g[now]:
if not chk[i]:
chk[i] = True
mi = min(now,i)
ma = max(now,i)
mm = mi*100+ma
if d[mm] == 0:
d[mm] = cnt
cnt += 1
que.append((i,L|(1<<d[mm])))
import itertools
ans = 1<<(n-1)
for i in range(1,m+1):
for j in itertools.combinations(c,i):
K = 0
for k in j:
K |= k
l = all_bit_count(K)
ans += pow(-1,i)*pow(2,n-1-l)
print(ans) | 49 | 64 | 1,036 | 1,615 | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from collections import deque
n = int(readline())
g = [[] * n for i in range(n)]
for i in range(n - 1):
u, v = list(map(int, readline().split()))
u -= 1
v -= 1
g[u].append(v)
g[v].append(u)
m = int(readline())
c = []
for i in range(m):
u, v = list(map(int, readline().split()))
u -= 1
v -= 1
que = deque()
que.append((u, set()))
chk = [False] * n
chk[u] = True
while que:
now, L = que.popleft()
if now == v:
c.append(L)
break
for i in g[now]:
if not chk[i]:
chk[i] = True
mi = min(now, i)
ma = max(now, i)
que.append((i, L | {mi * 100 + ma}))
import itertools
# print(c)
ans = 1 << (n - 1)
for i in range(1, m + 1):
for j in itertools.combinations(c, i):
K = set()
for k in j:
K |= k
l = len(K)
ans += pow(-1, i) * pow(2, n - 1 - l)
print(ans)
| import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from collections import deque, defaultdict
def all_bit_count(n):
c = (n & 0x5555555555555555) + ((n >> 1) & 0x5555555555555555)
c = (c & 0x3333333333333333) + ((c >> 2) & 0x3333333333333333)
c = (c & 0x0F0F0F0F0F0F0F0F) + ((c >> 4) & 0x0F0F0F0F0F0F0F0F)
c = (c & 0x00FF00FF00FF00FF) + ((c >> 8) & 0x00FF00FF00FF00FF)
c = (c & 0x0000FFFF0000FFFF) + ((c >> 16) & 0x0000FFFF0000FFFF)
c = (c & 0x00000000FFFFFFFF) + ((c >> 32) & 0x00000000FFFFFFFF)
return c
n = int(readline())
d = defaultdict(int)
cnt = 1
g = [[] * n for i in range(n)]
for i in range(n - 1):
u, v = list(map(int, readline().split()))
u -= 1
v -= 1
g[u].append(v)
g[v].append(u)
m = int(readline())
c = []
for i in range(m):
u, v = list(map(int, readline().split()))
u -= 1
v -= 1
que = deque()
que.append((u, 0))
chk = [False] * n
chk[u] = True
while que:
now, L = que.popleft()
if now == v:
c.append(L)
break
for i in g[now]:
if not chk[i]:
chk[i] = True
mi = min(now, i)
ma = max(now, i)
mm = mi * 100 + ma
if d[mm] == 0:
d[mm] = cnt
cnt += 1
que.append((i, L | (1 << d[mm])))
import itertools
ans = 1 << (n - 1)
for i in range(1, m + 1):
for j in itertools.combinations(c, i):
K = 0
for k in j:
K |= k
l = all_bit_count(K)
ans += pow(-1, i) * pow(2, n - 1 - l)
print(ans)
| false | 23.4375 | [
"-from collections import deque",
"+from collections import deque, defaultdict",
"+",
"+",
"+def all_bit_count(n):",
"+ c = (n & 0x5555555555555555) + ((n >> 1) & 0x5555555555555555)",
"+ c = (c & 0x3333333333333333) + ((c >> 2) & 0x3333333333333333)",
"+ c = (c & 0x0F0F0F0F0F0F0F0F) + ((c >> 4) & 0x0F0F0F0F0F0F0F0F)",
"+ c = (c & 0x00FF00FF00FF00FF) + ((c >> 8) & 0x00FF00FF00FF00FF)",
"+ c = (c & 0x0000FFFF0000FFFF) + ((c >> 16) & 0x0000FFFF0000FFFF)",
"+ c = (c & 0x00000000FFFFFFFF) + ((c >> 32) & 0x00000000FFFFFFFF)",
"+ return c",
"+",
"+d = defaultdict(int)",
"+cnt = 1",
"- que.append((u, set()))",
"+ que.append((u, 0))",
"- que.append((i, L | {mi * 100 + ma}))",
"+ mm = mi * 100 + ma",
"+ if d[mm] == 0:",
"+ d[mm] = cnt",
"+ cnt += 1",
"+ que.append((i, L | (1 << d[mm])))",
"-# print(c)",
"- K = set()",
"+ K = 0",
"- l = len(K)",
"+ l = all_bit_count(K)"
] | false | 0.079165 | 0.037178 | 2.129376 | [
"s682048381",
"s833697304"
] |
u863370423 | p02836 | python | s513554409 | s774420241 | 165 | 18 | 38,256 | 3,060 | Accepted | Accepted | 89.09 | s = eval(input())
res = 0
for i in range(len(s)//2):
res += int(s[i] != s[len(s)-i-1])
print(res)
| s = eval(input())
l1 = []
for x in s:
l1.append(x)
l2 = l1[:]
l2.reverse()
hugs = 0
for count in range(int(len(l1)/2)):
if l1[count] == l2[count]:
continue
else:
hugs += 1
print(hugs) | 5 | 13 | 100 | 217 | s = eval(input())
res = 0
for i in range(len(s) // 2):
res += int(s[i] != s[len(s) - i - 1])
print(res)
| s = eval(input())
l1 = []
for x in s:
l1.append(x)
l2 = l1[:]
l2.reverse()
hugs = 0
for count in range(int(len(l1) / 2)):
if l1[count] == l2[count]:
continue
else:
hugs += 1
print(hugs)
| false | 61.538462 | [
"-res = 0",
"-for i in range(len(s) // 2):",
"- res += int(s[i] != s[len(s) - i - 1])",
"-print(res)",
"+l1 = []",
"+for x in s:",
"+ l1.append(x)",
"+l2 = l1[:]",
"+l2.reverse()",
"+hugs = 0",
"+for count in range(int(len(l1) / 2)):",
"+ if l1[count] == l2[count]:",
"+ continue",
"+ else:",
"+ hugs += 1",
"+print(hugs)"
] | false | 0.035445 | 0.03661 | 0.968176 | [
"s513554409",
"s774420241"
] |
u670180528 | p03660 | python | s515344254 | s630902576 | 1,369 | 493 | 36,980 | 37,208 | Accepted | Accepted | 63.99 | n,*L=list(map(int,open(0).read().split()))
G=[[]for _ in range(n)]
db=[-1]*n;db[0]=0
dw=[-1]*n;dw[-1]=0
for a,b in zip(*[iter(L)]*2):
G[a-1]+=[b-1]
G[b-1]+=[a-1]
q=[0]
while q:
cur=q.pop(0)
for nxt in G[cur]:
if db[nxt]<0:
q.append(nxt)
db[nxt]=db[cur]+1
q=[n-1]
while q:
cur=q.pop(0)
for nxt in G[cur]:
if dw[nxt]<0:
q.append(nxt)
dw[nxt]=dw[cur]+1
b=w=0
for i,j in zip(db,dw):
if i<=j:b+=1
else:w+=1
if b<=w:print("Snuke")
else:print("Fennec") | from collections import deque
n,*L=list(map(int,open(0).read().split()))
G=[[]for _ in range(n)]
db=[-1]*n
dw=[-1]*n
for a,b in zip(*[iter(L)]*2):
G[a-1]+=[b-1]
G[b-1]+=[a-1]
q=deque([(0,0)])
while q:
cur,d=q.popleft()
db[cur]=d
for nxt in G[cur]:
if db[nxt]<0:
q.append((nxt,d+1))
q=deque([(n-1,0)])
while q:
cur,d=q.popleft()
dw[cur]=d
for nxt in G[cur]:
if dw[nxt]<0:
q.append((nxt,d+1))
b=w=0
for i,j in zip(db,dw):
if i<=j:b+=1
else:w+=1
if b<=w:
print("Snuke")
else:
print("Fennec") | 27 | 30 | 489 | 533 | n, *L = list(map(int, open(0).read().split()))
G = [[] for _ in range(n)]
db = [-1] * n
db[0] = 0
dw = [-1] * n
dw[-1] = 0
for a, b in zip(*[iter(L)] * 2):
G[a - 1] += [b - 1]
G[b - 1] += [a - 1]
q = [0]
while q:
cur = q.pop(0)
for nxt in G[cur]:
if db[nxt] < 0:
q.append(nxt)
db[nxt] = db[cur] + 1
q = [n - 1]
while q:
cur = q.pop(0)
for nxt in G[cur]:
if dw[nxt] < 0:
q.append(nxt)
dw[nxt] = dw[cur] + 1
b = w = 0
for i, j in zip(db, dw):
if i <= j:
b += 1
else:
w += 1
if b <= w:
print("Snuke")
else:
print("Fennec")
| from collections import deque
n, *L = list(map(int, open(0).read().split()))
G = [[] for _ in range(n)]
db = [-1] * n
dw = [-1] * n
for a, b in zip(*[iter(L)] * 2):
G[a - 1] += [b - 1]
G[b - 1] += [a - 1]
q = deque([(0, 0)])
while q:
cur, d = q.popleft()
db[cur] = d
for nxt in G[cur]:
if db[nxt] < 0:
q.append((nxt, d + 1))
q = deque([(n - 1, 0)])
while q:
cur, d = q.popleft()
dw[cur] = d
for nxt in G[cur]:
if dw[nxt] < 0:
q.append((nxt, d + 1))
b = w = 0
for i, j in zip(db, dw):
if i <= j:
b += 1
else:
w += 1
if b <= w:
print("Snuke")
else:
print("Fennec")
| false | 10 | [
"+from collections import deque",
"+",
"-db[0] = 0",
"-dw[-1] = 0",
"-q = [0]",
"+q = deque([(0, 0)])",
"- cur = q.pop(0)",
"+ cur, d = q.popleft()",
"+ db[cur] = d",
"- q.append(nxt)",
"- db[nxt] = db[cur] + 1",
"-q = [n - 1]",
"+ q.append((nxt, d + 1))",
"+q = deque([(n - 1, 0)])",
"- cur = q.pop(0)",
"+ cur, d = q.popleft()",
"+ dw[cur] = d",
"- q.append(nxt)",
"- dw[nxt] = dw[cur] + 1",
"+ q.append((nxt, d + 1))"
] | false | 0.044903 | 0.043873 | 1.023487 | [
"s515344254",
"s630902576"
] |
u513081876 | p03862 | python | s080346551 | s872393888 | 135 | 115 | 14,052 | 14,052 | Accepted | Accepted | 14.81 | N, x = list(map(int, input().split()))
a = list(map(int, input().split()))
ans = 0
for i in range(N-1):
if (a[i]+a[i+1]) > x and x < a[i] :
ans += a[i+1]+a[i]-x
a[i] = a[i]-(x-a[i+1])
a[i+1] = 0
elif (a[i]+a[i+1]) > x:
ans += a[i+1]+a[i]-x
a[i+1] = x-a[i]
print(ans) | N, x = list(map(int, input().split()))
A = [int(i) for i in input().split()]
A.insert(0, 0)
ans = 0
for i in range(N):
if A[i] + A[i+1] > x:
ans += abs(A[i+1]-(x-A[i]))
A[i+1] = x - A[i]
print(ans) | 16 | 10 | 359 | 221 | N, x = list(map(int, input().split()))
a = list(map(int, input().split()))
ans = 0
for i in range(N - 1):
if (a[i] + a[i + 1]) > x and x < a[i]:
ans += a[i + 1] + a[i] - x
a[i] = a[i] - (x - a[i + 1])
a[i + 1] = 0
elif (a[i] + a[i + 1]) > x:
ans += a[i + 1] + a[i] - x
a[i + 1] = x - a[i]
print(ans)
| N, x = list(map(int, input().split()))
A = [int(i) for i in input().split()]
A.insert(0, 0)
ans = 0
for i in range(N):
if A[i] + A[i + 1] > x:
ans += abs(A[i + 1] - (x - A[i]))
A[i + 1] = x - A[i]
print(ans)
| false | 37.5 | [
"-a = list(map(int, input().split()))",
"+A = [int(i) for i in input().split()]",
"+A.insert(0, 0)",
"-for i in range(N - 1):",
"- if (a[i] + a[i + 1]) > x and x < a[i]:",
"- ans += a[i + 1] + a[i] - x",
"- a[i] = a[i] - (x - a[i + 1])",
"- a[i + 1] = 0",
"- elif (a[i] + a[i + 1]) > x:",
"- ans += a[i + 1] + a[i] - x",
"- a[i + 1] = x - a[i]",
"+for i in range(N):",
"+ if A[i] + A[i + 1] > x:",
"+ ans += abs(A[i + 1] - (x - A[i]))",
"+ A[i + 1] = x - A[i]"
] | false | 0.079244 | 0.078023 | 1.015643 | [
"s080346551",
"s872393888"
] |
u692746605 | p03074 | python | s407291957 | s830066985 | 82 | 59 | 7,164 | 7,108 | Accepted | Accepted | 28.05 | n, k = list(map(int, input().split()))
s = eval(input())
c = 1
l = []
l += [0,0] if (s[0] == '0') else [0]
for i in range(1, n):
if s[i-1] != s[i]:
l += [c+l[-1]]; c = 1;
else:
c +=1
l += [c+l[-1]]
if s[-1] == '0':
l += [l[-1]]
ll = len(l)
pl = 2 * k + 1
if ll <= pl:
print(n)
else:
m = 0
for i in range(0, ll-pl+1, 2):
t = l[pl+i]-l[i]; m = t if (t > m) else m
print(m)
| n, k = list(map(int, input().split()))
s = eval(input())
l = [0,0] if (s[0] == '0') else [0]
for i in range(1, n):
if s[i-1] != s[i]:
l += [i];
l += [n] if (s[-1] == '1') else [n,n]
ll = len(l)
pl = 2 * k + 1
if ll <= pl:
print(n)
else:
print((max(l[pl+i]-l[i] for i in range(0, ll-pl+1, 2))))
| 27 | 13 | 442 | 313 | n, k = list(map(int, input().split()))
s = eval(input())
c = 1
l = []
l += [0, 0] if (s[0] == "0") else [0]
for i in range(1, n):
if s[i - 1] != s[i]:
l += [c + l[-1]]
c = 1
else:
c += 1
l += [c + l[-1]]
if s[-1] == "0":
l += [l[-1]]
ll = len(l)
pl = 2 * k + 1
if ll <= pl:
print(n)
else:
m = 0
for i in range(0, ll - pl + 1, 2):
t = l[pl + i] - l[i]
m = t if (t > m) else m
print(m)
| n, k = list(map(int, input().split()))
s = eval(input())
l = [0, 0] if (s[0] == "0") else [0]
for i in range(1, n):
if s[i - 1] != s[i]:
l += [i]
l += [n] if (s[-1] == "1") else [n, n]
ll = len(l)
pl = 2 * k + 1
if ll <= pl:
print(n)
else:
print((max(l[pl + i] - l[i] for i in range(0, ll - pl + 1, 2))))
| false | 51.851852 | [
"-c = 1",
"-l = []",
"-l += [0, 0] if (s[0] == \"0\") else [0]",
"+l = [0, 0] if (s[0] == \"0\") else [0]",
"- l += [c + l[-1]]",
"- c = 1",
"- else:",
"- c += 1",
"-l += [c + l[-1]]",
"-if s[-1] == \"0\":",
"- l += [l[-1]]",
"+ l += [i]",
"+l += [n] if (s[-1] == \"1\") else [n, n]",
"- m = 0",
"- for i in range(0, ll - pl + 1, 2):",
"- t = l[pl + i] - l[i]",
"- m = t if (t > m) else m",
"- print(m)",
"+ print((max(l[pl + i] - l[i] for i in range(0, ll - pl + 1, 2))))"
] | false | 0.042465 | 0.039636 | 1.071353 | [
"s407291957",
"s830066985"
] |
u813098295 | p03631 | python | s342232994 | s308517825 | 30 | 10 | 2,568 | 2,568 | Accepted | Accepted | 66.67 | N = input()
if N == N[::-1]:
print("Yes")
else:
print("No") | N = input()
print("Yes" if N == N[::-1] else "No") | 6 | 2 | 75 | 54 | N = input()
if N == N[::-1]:
print("Yes")
else:
print("No")
| N = input()
print("Yes" if N == N[::-1] else "No")
| false | 66.666667 | [
"-if N == N[::-1]:",
"- print(\"Yes\")",
"-else:",
"- print(\"No\")",
"+print(\"Yes\" if N == N[::-1] else \"No\")"
] | false | 0.132744 | 0.077857 | 1.704978 | [
"s342232994",
"s308517825"
] |
u599114793 | p02844 | python | s423538868 | s366336300 | 30 | 20 | 4,328 | 3,064 | Accepted | Accepted | 33.33 | import bisect
n = int(eval(input()))
s = eval(input())
count = 0
num_ind_list = []
for i in range(10):
num_ind_list.append([0])
for i in range(n):
num_ind_list[int(s[i])].append(i)
for i in range(10):
num_ind_list[i].append(30000)
for i in range(10):
if len(num_ind_list[i]) != 2:
for j in range(10):
b = bisect.bisect_right(num_ind_list[j], num_ind_list[i][1])
if num_ind_list[j][b] != 30000:
for k in range(10):
c = bisect.bisect_right(num_ind_list[k], num_ind_list[j][b])
if num_ind_list[k][c] != 30000: count += 1
print(count)
| n = int(eval(input()))
s = eval(input())
num_list = [str(i).zfill(3) for i in range(1000)]
ans = 0
for i in range(1000):
i100 = num_list[i][0]
i10 = num_list[i][1]
i1 = num_list[i][2]
count = 0
a = s.find(i100)
if a != -1:
count += 1
a += 1
b = s.find(i10, a)
if b != -1:
count += 1
b += 1
c = s.find(i1, b)
if c != -1:
count += 1
if count == 3:
ans += 1
print(ans)
| 20 | 23 | 642 | 468 | import bisect
n = int(eval(input()))
s = eval(input())
count = 0
num_ind_list = []
for i in range(10):
num_ind_list.append([0])
for i in range(n):
num_ind_list[int(s[i])].append(i)
for i in range(10):
num_ind_list[i].append(30000)
for i in range(10):
if len(num_ind_list[i]) != 2:
for j in range(10):
b = bisect.bisect_right(num_ind_list[j], num_ind_list[i][1])
if num_ind_list[j][b] != 30000:
for k in range(10):
c = bisect.bisect_right(num_ind_list[k], num_ind_list[j][b])
if num_ind_list[k][c] != 30000:
count += 1
print(count)
| n = int(eval(input()))
s = eval(input())
num_list = [str(i).zfill(3) for i in range(1000)]
ans = 0
for i in range(1000):
i100 = num_list[i][0]
i10 = num_list[i][1]
i1 = num_list[i][2]
count = 0
a = s.find(i100)
if a != -1:
count += 1
a += 1
b = s.find(i10, a)
if b != -1:
count += 1
b += 1
c = s.find(i1, b)
if c != -1:
count += 1
if count == 3:
ans += 1
print(ans)
| false | 13.043478 | [
"-import bisect",
"-",
"-count = 0",
"-num_ind_list = []",
"-for i in range(10):",
"- num_ind_list.append([0])",
"-for i in range(n):",
"- num_ind_list[int(s[i])].append(i)",
"-for i in range(10):",
"- num_ind_list[i].append(30000)",
"-for i in range(10):",
"- if len(num_ind_list[i]) != 2:",
"- for j in range(10):",
"- b = bisect.bisect_right(num_ind_list[j], num_ind_list[i][1])",
"- if num_ind_list[j][b] != 30000:",
"- for k in range(10):",
"- c = bisect.bisect_right(num_ind_list[k], num_ind_list[j][b])",
"- if num_ind_list[k][c] != 30000:",
"- count += 1",
"-print(count)",
"+num_list = [str(i).zfill(3) for i in range(1000)]",
"+ans = 0",
"+for i in range(1000):",
"+ i100 = num_list[i][0]",
"+ i10 = num_list[i][1]",
"+ i1 = num_list[i][2]",
"+ count = 0",
"+ a = s.find(i100)",
"+ if a != -1:",
"+ count += 1",
"+ a += 1",
"+ b = s.find(i10, a)",
"+ if b != -1:",
"+ count += 1",
"+ b += 1",
"+ c = s.find(i1, b)",
"+ if c != -1:",
"+ count += 1",
"+ if count == 3:",
"+ ans += 1",
"+print(ans)"
] | false | 0.04748 | 0.047143 | 1.007148 | [
"s423538868",
"s366336300"
] |
u073852194 | p03044 | python | s996146753 | s341831520 | 994 | 776 | 59,288 | 62,608 | Accepted | Accepted | 21.93 | n = int(eval(input()))
Edges = [list(map(int,input().split())) for i in range(n-1)]
for edge in Edges:
edge[0] -= 1
edge[1] -= 1
edge[2] %= 2
Graph = [[] for i in range(n)]
for edge in Edges:
Graph[edge[0]].append([edge[1],edge[2]])
Graph[edge[1]].append([edge[0],edge[2]])
Color = [-1 for i in range(n)]
Color[0] = 0
stack = [0]
while stack:
node = stack.pop()
for adj in Graph[node]:
if Color[adj[0]] == -1:
if adj[1] == 0:
Color[adj[0]] = Color[node]
elif Color[node] == 0:
Color[adj[0]] = 1
else:
Color[adj[0]] = 0
stack.append(adj[0])
for color in Color:
print(color)
| class Tree(): #weighted
def __init__(self, n, edge, indexed=1):
self.n = n
self.tree = [[] for _ in range(n)]
for e in edge:
self.tree[e[0] - indexed].append((e[1] - indexed, e[2]))
self.tree[e[1] - indexed].append((e[0] - indexed, e[2]))
def setroot(self, root):
self.root = root
self.parent = [None for _ in range(self.n)]
self.parent[root] = -1
self.depth = [None for _ in range(self.n)]
self.depth[root] = 0
self.distance = [None for _ in range(self.n)]
self.distance[root] = 0
self.order = []
self.order.append(root)
self.cost = [0 for _ in range(self.n)]
self.size = [1 for _ in range(self.n)]
stack = [root]
while stack:
node = stack.pop()
for adj, cost in self.tree[node]:
if self.parent[adj] is None:
self.parent[adj] = node
self.depth[adj] = self.depth[node] + 1
self.distance[adj] = self.distance[node] + cost
self.cost[adj] = cost
self.order.append(adj)
stack.append(adj)
for node in self.order[::-1]:
for adj, cost in self.tree[node]:
if self.parent[node] == adj:
continue
self.size[node] += self.size[adj]
import sys
input = sys.stdin.readline
N = int(eval(input()))
E = [tuple(map(int, input().split())) for _ in range(N - 1)]
t = Tree(N, E)
t.setroot(0)
for i in range(N):
if t.distance[i] % 2 == 0:
print((0))
else:
print((1)) | 31 | 50 | 738 | 1,702 | n = int(eval(input()))
Edges = [list(map(int, input().split())) for i in range(n - 1)]
for edge in Edges:
edge[0] -= 1
edge[1] -= 1
edge[2] %= 2
Graph = [[] for i in range(n)]
for edge in Edges:
Graph[edge[0]].append([edge[1], edge[2]])
Graph[edge[1]].append([edge[0], edge[2]])
Color = [-1 for i in range(n)]
Color[0] = 0
stack = [0]
while stack:
node = stack.pop()
for adj in Graph[node]:
if Color[adj[0]] == -1:
if adj[1] == 0:
Color[adj[0]] = Color[node]
elif Color[node] == 0:
Color[adj[0]] = 1
else:
Color[adj[0]] = 0
stack.append(adj[0])
for color in Color:
print(color)
| class Tree: # weighted
def __init__(self, n, edge, indexed=1):
self.n = n
self.tree = [[] for _ in range(n)]
for e in edge:
self.tree[e[0] - indexed].append((e[1] - indexed, e[2]))
self.tree[e[1] - indexed].append((e[0] - indexed, e[2]))
def setroot(self, root):
self.root = root
self.parent = [None for _ in range(self.n)]
self.parent[root] = -1
self.depth = [None for _ in range(self.n)]
self.depth[root] = 0
self.distance = [None for _ in range(self.n)]
self.distance[root] = 0
self.order = []
self.order.append(root)
self.cost = [0 for _ in range(self.n)]
self.size = [1 for _ in range(self.n)]
stack = [root]
while stack:
node = stack.pop()
for adj, cost in self.tree[node]:
if self.parent[adj] is None:
self.parent[adj] = node
self.depth[adj] = self.depth[node] + 1
self.distance[adj] = self.distance[node] + cost
self.cost[adj] = cost
self.order.append(adj)
stack.append(adj)
for node in self.order[::-1]:
for adj, cost in self.tree[node]:
if self.parent[node] == adj:
continue
self.size[node] += self.size[adj]
import sys
input = sys.stdin.readline
N = int(eval(input()))
E = [tuple(map(int, input().split())) for _ in range(N - 1)]
t = Tree(N, E)
t.setroot(0)
for i in range(N):
if t.distance[i] % 2 == 0:
print((0))
else:
print((1))
| false | 38 | [
"-n = int(eval(input()))",
"-Edges = [list(map(int, input().split())) for i in range(n - 1)]",
"-for edge in Edges:",
"- edge[0] -= 1",
"- edge[1] -= 1",
"- edge[2] %= 2",
"-Graph = [[] for i in range(n)]",
"-for edge in Edges:",
"- Graph[edge[0]].append([edge[1], edge[2]])",
"- Graph[edge[1]].append([edge[0], edge[2]])",
"-Color = [-1 for i in range(n)]",
"-Color[0] = 0",
"-stack = [0]",
"-while stack:",
"- node = stack.pop()",
"- for adj in Graph[node]:",
"- if Color[adj[0]] == -1:",
"- if adj[1] == 0:",
"- Color[adj[0]] = Color[node]",
"- elif Color[node] == 0:",
"- Color[adj[0]] = 1",
"- else:",
"- Color[adj[0]] = 0",
"- stack.append(adj[0])",
"-for color in Color:",
"- print(color)",
"+class Tree: # weighted",
"+ def __init__(self, n, edge, indexed=1):",
"+ self.n = n",
"+ self.tree = [[] for _ in range(n)]",
"+ for e in edge:",
"+ self.tree[e[0] - indexed].append((e[1] - indexed, e[2]))",
"+ self.tree[e[1] - indexed].append((e[0] - indexed, e[2]))",
"+",
"+ def setroot(self, root):",
"+ self.root = root",
"+ self.parent = [None for _ in range(self.n)]",
"+ self.parent[root] = -1",
"+ self.depth = [None for _ in range(self.n)]",
"+ self.depth[root] = 0",
"+ self.distance = [None for _ in range(self.n)]",
"+ self.distance[root] = 0",
"+ self.order = []",
"+ self.order.append(root)",
"+ self.cost = [0 for _ in range(self.n)]",
"+ self.size = [1 for _ in range(self.n)]",
"+ stack = [root]",
"+ while stack:",
"+ node = stack.pop()",
"+ for adj, cost in self.tree[node]:",
"+ if self.parent[adj] is None:",
"+ self.parent[adj] = node",
"+ self.depth[adj] = self.depth[node] + 1",
"+ self.distance[adj] = self.distance[node] + cost",
"+ self.cost[adj] = cost",
"+ self.order.append(adj)",
"+ stack.append(adj)",
"+ for node in self.order[::-1]:",
"+ for adj, cost in self.tree[node]:",
"+ if self.parent[node] == adj:",
"+ continue",
"+ self.size[node] += self.size[adj]",
"+",
"+",
"+import sys",
"+",
"+input = sys.stdin.readline",
"+N = int(eval(input()))",
"+E = [tuple(map(int, input().split())) for _ in range(N - 1)]",
"+t = Tree(N, E)",
"+t.setroot(0)",
"+for i in range(N):",
"+ if t.distance[i] % 2 == 0:",
"+ print((0))",
"+ else:",
"+ print((1))"
] | false | 0.037284 | 0.04327 | 0.861652 | [
"s996146753",
"s341831520"
] |
u513434790 | p02912 | python | s864870220 | s516350900 | 2,000 | 164 | 14,100 | 14,180 | Accepted | Accepted | 91.8 | N, M= list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort()
l = -1
r = A[-1] + 1
while r - l > 1:
m = (r + l) // 2
mc = 0
a = 0
for i in range(N):
s = A[i]
while m < s:
s //= 2
mc += 1
a += s
if mc <= M:
r = m
ans = a - (M - mc) * ((m // 2) + m % 2)
else:
l = m
print(ans) | import heapq
N, M= list(map(int, input().split()))
A = list(map(int, input().split()))
for i in range(N):
A[i] *= -1
heapq.heapify(A)
for i in range(M):
b = heapq.heappop(A) * (-1)
heapq.heappush(A, (b // 2) * (-1))
print((sum(A) * -1)) | 25 | 16 | 426 | 265 | N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort()
l = -1
r = A[-1] + 1
while r - l > 1:
m = (r + l) // 2
mc = 0
a = 0
for i in range(N):
s = A[i]
while m < s:
s //= 2
mc += 1
a += s
if mc <= M:
r = m
ans = a - (M - mc) * ((m // 2) + m % 2)
else:
l = m
print(ans)
| import heapq
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
for i in range(N):
A[i] *= -1
heapq.heapify(A)
for i in range(M):
b = heapq.heappop(A) * (-1)
heapq.heappush(A, (b // 2) * (-1))
print((sum(A) * -1))
| false | 36 | [
"+import heapq",
"+",
"-A.sort()",
"-l = -1",
"-r = A[-1] + 1",
"-while r - l > 1:",
"- m = (r + l) // 2",
"- mc = 0",
"- a = 0",
"- for i in range(N):",
"- s = A[i]",
"- while m < s:",
"- s //= 2",
"- mc += 1",
"- a += s",
"- if mc <= M:",
"- r = m",
"- ans = a - (M - mc) * ((m // 2) + m % 2)",
"- else:",
"- l = m",
"-print(ans)",
"+for i in range(N):",
"+ A[i] *= -1",
"+heapq.heapify(A)",
"+for i in range(M):",
"+ b = heapq.heappop(A) * (-1)",
"+ heapq.heappush(A, (b // 2) * (-1))",
"+print((sum(A) * -1))"
] | false | 0.22485 | 0.038379 | 5.858707 | [
"s864870220",
"s516350900"
] |
u888092736 | p03229 | python | s056177722 | s250364764 | 138 | 90 | 20,196 | 20,184 | Accepted | Accepted | 34.78 | def calc_score(li):
prev = li[0]
ret = 0
for el in li:
ret += abs(el - prev)
prev = el
return ret
N, *A = list(map(int, open(0).read().split()))
A = sorted(A)
if N % 2:
ans = 0
li = [0] * N
li[0] = A[N // 2]
for i in range(N // 2):
li[i * 2 + 1] = A[i + N // 2 + 1]
li[i * 2 + 2] = A[i]
ans = calc_score(li)
li[N - 1] = A[N // 2]
for i in range(N // 2):
li[i * 2] = A[i + N // 2 + 1]
li[i * 2 + 1] = A[i]
print((max(ans, calc_score(li))))
else:
li = [0] * N
for i in range(N // 2):
li[i * 2] = A[i + N // 2]
li[i * 2 + 1] = A[i]
print((calc_score(li)))
| N, *A = list(map(int, open(0).read().split()))
M = N // 2
A.sort()
ans = 0
if N % 2:
for i in range(1, M):
ans += A[i + M + 1] - A[i - 1]
ans += A[i + M + 1] - A[i]
ans += A[M + 1] - A[0]
ans = max(A[M + 1] - A[M] + ans, ans + A[M] - A[M - 1])
else:
ans += A[M] - A[0]
for i in range(1, M):
ans += A[i + M] - A[i - 1]
ans += A[i + M] - A[i]
print(ans)
| 30 | 16 | 698 | 413 | def calc_score(li):
prev = li[0]
ret = 0
for el in li:
ret += abs(el - prev)
prev = el
return ret
N, *A = list(map(int, open(0).read().split()))
A = sorted(A)
if N % 2:
ans = 0
li = [0] * N
li[0] = A[N // 2]
for i in range(N // 2):
li[i * 2 + 1] = A[i + N // 2 + 1]
li[i * 2 + 2] = A[i]
ans = calc_score(li)
li[N - 1] = A[N // 2]
for i in range(N // 2):
li[i * 2] = A[i + N // 2 + 1]
li[i * 2 + 1] = A[i]
print((max(ans, calc_score(li))))
else:
li = [0] * N
for i in range(N // 2):
li[i * 2] = A[i + N // 2]
li[i * 2 + 1] = A[i]
print((calc_score(li)))
| N, *A = list(map(int, open(0).read().split()))
M = N // 2
A.sort()
ans = 0
if N % 2:
for i in range(1, M):
ans += A[i + M + 1] - A[i - 1]
ans += A[i + M + 1] - A[i]
ans += A[M + 1] - A[0]
ans = max(A[M + 1] - A[M] + ans, ans + A[M] - A[M - 1])
else:
ans += A[M] - A[0]
for i in range(1, M):
ans += A[i + M] - A[i - 1]
ans += A[i + M] - A[i]
print(ans)
| false | 46.666667 | [
"-def calc_score(li):",
"- prev = li[0]",
"- ret = 0",
"- for el in li:",
"- ret += abs(el - prev)",
"- prev = el",
"- return ret",
"-",
"-",
"-A = sorted(A)",
"+M = N // 2",
"+A.sort()",
"+ans = 0",
"- ans = 0",
"- li = [0] * N",
"- li[0] = A[N // 2]",
"- for i in range(N // 2):",
"- li[i * 2 + 1] = A[i + N // 2 + 1]",
"- li[i * 2 + 2] = A[i]",
"- ans = calc_score(li)",
"- li[N - 1] = A[N // 2]",
"- for i in range(N // 2):",
"- li[i * 2] = A[i + N // 2 + 1]",
"- li[i * 2 + 1] = A[i]",
"- print((max(ans, calc_score(li))))",
"+ for i in range(1, M):",
"+ ans += A[i + M + 1] - A[i - 1]",
"+ ans += A[i + M + 1] - A[i]",
"+ ans += A[M + 1] - A[0]",
"+ ans = max(A[M + 1] - A[M] + ans, ans + A[M] - A[M - 1])",
"- li = [0] * N",
"- for i in range(N // 2):",
"- li[i * 2] = A[i + N // 2]",
"- li[i * 2 + 1] = A[i]",
"- print((calc_score(li)))",
"+ ans += A[M] - A[0]",
"+ for i in range(1, M):",
"+ ans += A[i + M] - A[i - 1]",
"+ ans += A[i + M] - A[i]",
"+print(ans)"
] | false | 0.03627 | 0.037421 | 0.969232 | [
"s056177722",
"s250364764"
] |
u282228874 | p03295 | python | s368056883 | s943152617 | 490 | 422 | 27,876 | 29,848 | Accepted | Accepted | 13.88 | N,M = list(map(int,input().split()))
L = [list(map(int,input().split())) for i in range(M)]
L.sort()
ans = 0
l,r = 0,0
for a,b in L:
l = a
if r <= a:
ans += 1
r = b
else:
r = min(r,b)
print(ans)
| N,M = list(map(int,input().split()))
L = sorted([list(map(int,input().split())) for i in range(M)],key = lambda x:x[1])
p,res = 0,0
for a,b in L:
if a > p:
p = b-1
res += 1
print(res)
| 13 | 8 | 237 | 205 | N, M = list(map(int, input().split()))
L = [list(map(int, input().split())) for i in range(M)]
L.sort()
ans = 0
l, r = 0, 0
for a, b in L:
l = a
if r <= a:
ans += 1
r = b
else:
r = min(r, b)
print(ans)
| N, M = list(map(int, input().split()))
L = sorted([list(map(int, input().split())) for i in range(M)], key=lambda x: x[1])
p, res = 0, 0
for a, b in L:
if a > p:
p = b - 1
res += 1
print(res)
| false | 38.461538 | [
"-L = [list(map(int, input().split())) for i in range(M)]",
"-L.sort()",
"-ans = 0",
"-l, r = 0, 0",
"+L = sorted([list(map(int, input().split())) for i in range(M)], key=lambda x: x[1])",
"+p, res = 0, 0",
"- l = a",
"- if r <= a:",
"- ans += 1",
"- r = b",
"- else:",
"- r = min(r, b)",
"-print(ans)",
"+ if a > p:",
"+ p = b - 1",
"+ res += 1",
"+print(res)"
] | false | 0.076745 | 0.08582 | 0.894252 | [
"s368056883",
"s943152617"
] |
u497596438 | p03605 | python | s919356051 | s189920586 | 171 | 17 | 38,256 | 2,940 | Accepted | Accepted | 90.06 | N=int(eval(input()))
if N//10==9 or N%10==9:
print("Yes")
else:
print("No") | N=eval(input())
if N[0]=="9" or N[1]=="9":
print("Yes")
else:
print("No")
| 5 | 5 | 81 | 80 | N = int(eval(input()))
if N // 10 == 9 or N % 10 == 9:
print("Yes")
else:
print("No")
| N = eval(input())
if N[0] == "9" or N[1] == "9":
print("Yes")
else:
print("No")
| false | 0 | [
"-N = int(eval(input()))",
"-if N // 10 == 9 or N % 10 == 9:",
"+N = eval(input())",
"+if N[0] == \"9\" or N[1] == \"9\":"
] | false | 0.03769 | 0.101381 | 0.371769 | [
"s919356051",
"s189920586"
] |
u163320134 | p02614 | python | s521633695 | s716837542 | 81 | 64 | 68,144 | 9,188 | Accepted | Accepted | 20.99 | h,w,k=list(map(int,input().split()))
board=[list(eval(input())) for _ in range(h)]
ans=0
for paint_h in range(2**h):
for paint_w in range(2**w):
cnt=0
for i in range(h):
for j in range(w):
if (paint_h>>i)&1==0 and (paint_w>>j)&1==0 and board[i][j]=='#':
cnt+=1
if cnt==k:
ans+=1
print(ans) | h,w,k=list(map(int,input().split()))
board=[list(eval(input())) for _ in range(h)]
ans=0
for paint_h in range(2**h):
for paint_w in range(2**w):
cnt=0
for i in range(h):
for j in range(w):
if (paint_h>>i)&1==0 and (paint_w>>j)&1==0:
if board[i][j]=='#':
cnt+=1
if cnt==k:
ans+=1
print(ans) | 13 | 14 | 333 | 346 | h, w, k = list(map(int, input().split()))
board = [list(eval(input())) for _ in range(h)]
ans = 0
for paint_h in range(2**h):
for paint_w in range(2**w):
cnt = 0
for i in range(h):
for j in range(w):
if (
(paint_h >> i) & 1 == 0
and (paint_w >> j) & 1 == 0
and board[i][j] == "#"
):
cnt += 1
if cnt == k:
ans += 1
print(ans)
| h, w, k = list(map(int, input().split()))
board = [list(eval(input())) for _ in range(h)]
ans = 0
for paint_h in range(2**h):
for paint_w in range(2**w):
cnt = 0
for i in range(h):
for j in range(w):
if (paint_h >> i) & 1 == 0 and (paint_w >> j) & 1 == 0:
if board[i][j] == "#":
cnt += 1
if cnt == k:
ans += 1
print(ans)
| false | 7.142857 | [
"- if (",
"- (paint_h >> i) & 1 == 0",
"- and (paint_w >> j) & 1 == 0",
"- and board[i][j] == \"#\"",
"- ):",
"- cnt += 1",
"+ if (paint_h >> i) & 1 == 0 and (paint_w >> j) & 1 == 0:",
"+ if board[i][j] == \"#\":",
"+ cnt += 1"
] | false | 0.036225 | 0.067015 | 0.540555 | [
"s521633695",
"s716837542"
] |
u113971909 | p02713 | python | s835270568 | s120713343 | 1,664 | 1,017 | 9,148 | 9,392 | Accepted | Accepted | 38.88 | #!/usr/bin python3
# -*- coding: utf-8 -*-
import sys
input = sys.stdin.readline
from math import gcd
def main():
K=int(eval(input()))
ret = 0
for a in range(K):
for b in range(K):
for c in range(K):
ret += gcd(gcd(a+1,b+1),c+1)
print(ret)
if __name__ == '__main__':
main() | #!/usr/bin python3
# -*- coding: utf-8 -*-
import sys
input = sys.stdin.readline
from math import gcd
def main():
K=int(eval(input()))
ret = 0
gc=[[-1]*K for _ in range(K)]
for a in range(K):
for b in range(K):
if gc[a][b]==-1:
gc[a][b]=gcd(a+1,b+1)
gc[b][a]=gc[a][b]
x=gc[a][b]
for c in range(K):
if gc[x-1][c]==-1:
gc[x-1][c]=gcd(x,c+1)
gc[c][x-1]=gc[x-1][c]
ret += gc[x-1][c]
print(ret)
if __name__ == '__main__':
main() | 18 | 27 | 343 | 619 | #!/usr/bin python3
# -*- coding: utf-8 -*-
import sys
input = sys.stdin.readline
from math import gcd
def main():
K = int(eval(input()))
ret = 0
for a in range(K):
for b in range(K):
for c in range(K):
ret += gcd(gcd(a + 1, b + 1), c + 1)
print(ret)
if __name__ == "__main__":
main()
| #!/usr/bin python3
# -*- coding: utf-8 -*-
import sys
input = sys.stdin.readline
from math import gcd
def main():
K = int(eval(input()))
ret = 0
gc = [[-1] * K for _ in range(K)]
for a in range(K):
for b in range(K):
if gc[a][b] == -1:
gc[a][b] = gcd(a + 1, b + 1)
gc[b][a] = gc[a][b]
x = gc[a][b]
for c in range(K):
if gc[x - 1][c] == -1:
gc[x - 1][c] = gcd(x, c + 1)
gc[c][x - 1] = gc[x - 1][c]
ret += gc[x - 1][c]
print(ret)
if __name__ == "__main__":
main()
| false | 33.333333 | [
"+ gc = [[-1] * K for _ in range(K)]",
"+ if gc[a][b] == -1:",
"+ gc[a][b] = gcd(a + 1, b + 1)",
"+ gc[b][a] = gc[a][b]",
"+ x = gc[a][b]",
"- ret += gcd(gcd(a + 1, b + 1), c + 1)",
"+ if gc[x - 1][c] == -1:",
"+ gc[x - 1][c] = gcd(x, c + 1)",
"+ gc[c][x - 1] = gc[x - 1][c]",
"+ ret += gc[x - 1][c]"
] | false | 0.050151 | 0.19594 | 0.255951 | [
"s835270568",
"s120713343"
] |
u238940874 | p03680 | python | s155683241 | s277842456 | 211 | 194 | 7,084 | 7,084 | Accepted | Accepted | 8.06 | n=int(eval(input()))
a=[]
for _ in range(n):
a.append(int(eval(input())))
t=0
for i in range(1,n+1):
t=a[t]-1
if t==1:
print(i)
break
else:
print((-1)) | n=int(eval(input()))
a=[int(eval(input()))for _ in range(n)]
b=0
for i in range(1,n+1):
b=a[b]-1
if b==1:
print(i)
exit()
else:
print((-1)) | 13 | 10 | 182 | 162 | n = int(eval(input()))
a = []
for _ in range(n):
a.append(int(eval(input())))
t = 0
for i in range(1, n + 1):
t = a[t] - 1
if t == 1:
print(i)
break
else:
print((-1))
| n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
b = 0
for i in range(1, n + 1):
b = a[b] - 1
if b == 1:
print(i)
exit()
else:
print((-1))
| false | 23.076923 | [
"-a = []",
"-for _ in range(n):",
"- a.append(int(eval(input())))",
"-t = 0",
"+a = [int(eval(input())) for _ in range(n)]",
"+b = 0",
"- t = a[t] - 1",
"- if t == 1:",
"+ b = a[b] - 1",
"+ if b == 1:",
"- break",
"+ exit()"
] | false | 0.036459 | 0.037008 | 0.985173 | [
"s155683241",
"s277842456"
] |
u215341636 | p02707 | python | s005850542 | s133001462 | 166 | 137 | 32,244 | 33,064 | Accepted | Accepted | 17.47 | n = int(eval(input()))
a = list(map(int, input().split()))
ans = [0] * n
for i in range(n - 1):
j = a[i]
ans[j - 1] += 1
for i in range(n):
print((ans[i])) | n = int(eval(input()))
a = list(map(int, input().split()))
ans = [0] * n
for i in range(n - 1):
j = a[i]
ans[j - 1] += 1
print(("\n".join( map( str, ans)))) | 10 | 9 | 164 | 162 | n = int(eval(input()))
a = list(map(int, input().split()))
ans = [0] * n
for i in range(n - 1):
j = a[i]
ans[j - 1] += 1
for i in range(n):
print((ans[i]))
| n = int(eval(input()))
a = list(map(int, input().split()))
ans = [0] * n
for i in range(n - 1):
j = a[i]
ans[j - 1] += 1
print(("\n".join(map(str, ans))))
| false | 10 | [
"-for i in range(n):",
"- print((ans[i]))",
"+print((\"\\n\".join(map(str, ans))))"
] | false | 0.082549 | 0.048237 | 1.711328 | [
"s005850542",
"s133001462"
] |
u703950586 | p03666 | python | s167669953 | s100358369 | 195 | 173 | 38,636 | 38,384 | Accepted | Accepted | 11.28 | import sys,queue,math,copy,itertools,bisect,collections,heapq
def main():
sys.setrecursionlimit(10**7)
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
n,a,b,c,d = LI()
x = int((b-a+d*(n-1))/(c+d))
if x < 0 or x > n-1:
print('NO')
return
z = c * x - d * (n-1-x)
if z <= b - a <= z + (d-c) * (n-1):
print('YES')
else:
print('NO')
if __name__ == '__main__':
main() | n,a,b,c,d = list(map(int,input().split()))
x = int((b-a+d*(n-1))/(c+d))
if x < 0 or x > n-1: s='NO'
else:
z = c * x - d * (n-1-x)
if z<=b-a<=z+(d-c)*(n-1):s='YES'
else:s='NO'
print(s) | 20 | 8 | 465 | 187 | import sys, queue, math, copy, itertools, bisect, collections, heapq
def main():
sys.setrecursionlimit(10**7)
LI = lambda: [int(x) for x in sys.stdin.readline().split()]
n, a, b, c, d = LI()
x = int((b - a + d * (n - 1)) / (c + d))
if x < 0 or x > n - 1:
print("NO")
return
z = c * x - d * (n - 1 - x)
if z <= b - a <= z + (d - c) * (n - 1):
print("YES")
else:
print("NO")
if __name__ == "__main__":
main()
| n, a, b, c, d = list(map(int, input().split()))
x = int((b - a + d * (n - 1)) / (c + d))
if x < 0 or x > n - 1:
s = "NO"
else:
z = c * x - d * (n - 1 - x)
if z <= b - a <= z + (d - c) * (n - 1):
s = "YES"
else:
s = "NO"
print(s)
| false | 60 | [
"-import sys, queue, math, copy, itertools, bisect, collections, heapq",
"-",
"-",
"-def main():",
"- sys.setrecursionlimit(10**7)",
"- LI = lambda: [int(x) for x in sys.stdin.readline().split()]",
"- n, a, b, c, d = LI()",
"- x = int((b - a + d * (n - 1)) / (c + d))",
"- if x < 0 or x > n - 1:",
"- print(\"NO\")",
"- return",
"+n, a, b, c, d = list(map(int, input().split()))",
"+x = int((b - a + d * (n - 1)) / (c + d))",
"+if x < 0 or x > n - 1:",
"+ s = \"NO\"",
"+else:",
"- print(\"YES\")",
"+ s = \"YES\"",
"- print(\"NO\")",
"-",
"-",
"-if __name__ == \"__main__\":",
"- main()",
"+ s = \"NO\"",
"+print(s)"
] | false | 0.038606 | 0.039639 | 0.973943 | [
"s167669953",
"s100358369"
] |
u429029348 | p02713 | python | s856240015 | s077816619 | 1,317 | 1,082 | 9,112 | 74,708 | Accepted | Accepted | 17.84 | import math
k=int(eval(input()))
ans=0
for i in range(1,k+1):
for j in range(1,k+1):
aa=math.gcd(i,j)
for l in range(1,k+1):
ans+=math.gcd(aa,l)
print(ans) | import math
from functools import reduce
k=int(eval(input()))
def gcd(*numbers):
return reduce(math.gcd,numbers)
ans=0
for i in range(1,k+1):
for j in range(1,k+1):
for l in range(1,k+1):
ans+=gcd(i,j,l)
print(ans) | 11 | 15 | 177 | 244 | import math
k = int(eval(input()))
ans = 0
for i in range(1, k + 1):
for j in range(1, k + 1):
aa = math.gcd(i, j)
for l in range(1, k + 1):
ans += math.gcd(aa, l)
print(ans)
| import math
from functools import reduce
k = int(eval(input()))
def gcd(*numbers):
return reduce(math.gcd, numbers)
ans = 0
for i in range(1, k + 1):
for j in range(1, k + 1):
for l in range(1, k + 1):
ans += gcd(i, j, l)
print(ans)
| false | 26.666667 | [
"+from functools import reduce",
"+",
"+",
"+def gcd(*numbers):",
"+ return reduce(math.gcd, numbers)",
"+",
"+",
"- aa = math.gcd(i, j)",
"- ans += math.gcd(aa, l)",
"+ ans += gcd(i, j, l)"
] | false | 0.132525 | 0.039635 | 3.343644 | [
"s856240015",
"s077816619"
] |
u359358631 | p02577 | python | s280436515 | s719960885 | 66 | 54 | 9,268 | 9,232 | Accepted | Accepted | 18.18 | def main():
N = eval(input())
ans = 0
for ch in N:
ans += int(ch)
if ans % 9 == 0:
print("Yes")
else:
print("No")
if __name__ == "__main__":
main()
| def main():
N = eval(input())
sum_all_digits = 0
for ch in N:
sum_all_digits += int(ch)
if sum_all_digits % 9 == 0:
ans = "Yes"
else:
ans = "No"
print(ans)
if __name__ == "__main__":
main()
| 14 | 17 | 206 | 257 | def main():
N = eval(input())
ans = 0
for ch in N:
ans += int(ch)
if ans % 9 == 0:
print("Yes")
else:
print("No")
if __name__ == "__main__":
main()
| def main():
N = eval(input())
sum_all_digits = 0
for ch in N:
sum_all_digits += int(ch)
if sum_all_digits % 9 == 0:
ans = "Yes"
else:
ans = "No"
print(ans)
if __name__ == "__main__":
main()
| false | 17.647059 | [
"- ans = 0",
"+ sum_all_digits = 0",
"- ans += int(ch)",
"- if ans % 9 == 0:",
"- print(\"Yes\")",
"+ sum_all_digits += int(ch)",
"+ if sum_all_digits % 9 == 0:",
"+ ans = \"Yes\"",
"- print(\"No\")",
"+ ans = \"No\"",
"+ print(ans)"
] | false | 0.048315 | 0.048767 | 0.990732 | [
"s280436515",
"s719960885"
] |
u804800128 | p02580 | python | s338195774 | s724355061 | 649 | 574 | 83,360 | 83,528 | Accepted | Accepted | 11.56 | import sys
input = sys.stdin.readline
h,w,m = list(map(int,input().split()))
h_array = [ 0 for i in range(h) ]
w_array = [ 0 for i in range(w) ]
ps = set()
for i in range(m):
hi,wi = [int(x) - 1 for x in input().split()]
h_array[hi] += 1
w_array[wi] += 1
ps.add( (hi,wi) )
h_great = max(h_array)
w_great = max(w_array)
h_greats = list()
w_greats = list()
for i , hi in enumerate(h_array):
if hi == h_great:
h_greats.append(i)
for i , wi in enumerate(w_array):
if wi == w_great:
w_greats.append(i)
ans = h_great + w_great
for _h in h_greats:
for _w in w_greats:
if (_h,_w) in ps:
continue
print(ans)
exit()
print((ans-1)) | import sys
input = sys.stdin.readline
def main():
h,w,m = list(map(int,input().split()))
h_array = [ 0 for _ in range(h) ]
w_array = [ 0 for _ in range(w) ]
ps = set()
for i in range(m):
hi,wi = [int(x) - 1 for x in input().split()]
h_array[hi] += 1
w_array[wi] += 1
ps.add( (hi,wi) )
h_great = max(h_array)
w_great = max(w_array)
h_greats = list()
w_greats = list()
for i , hi in enumerate(h_array):
if hi == h_great:
h_greats.append(i)
for i , wi in enumerate(w_array):
if wi == w_great:
w_greats.append(i)
ans = h_great + w_great
for _h in h_greats:
for _w in w_greats:
if (_h,_w) in ps:
continue
print(ans)
exit()
print((ans-1))
if __name__ == '__main__':
main() | 36 | 40 | 743 | 906 | import sys
input = sys.stdin.readline
h, w, m = list(map(int, input().split()))
h_array = [0 for i in range(h)]
w_array = [0 for i in range(w)]
ps = set()
for i in range(m):
hi, wi = [int(x) - 1 for x in input().split()]
h_array[hi] += 1
w_array[wi] += 1
ps.add((hi, wi))
h_great = max(h_array)
w_great = max(w_array)
h_greats = list()
w_greats = list()
for i, hi in enumerate(h_array):
if hi == h_great:
h_greats.append(i)
for i, wi in enumerate(w_array):
if wi == w_great:
w_greats.append(i)
ans = h_great + w_great
for _h in h_greats:
for _w in w_greats:
if (_h, _w) in ps:
continue
print(ans)
exit()
print((ans - 1))
| import sys
input = sys.stdin.readline
def main():
h, w, m = list(map(int, input().split()))
h_array = [0 for _ in range(h)]
w_array = [0 for _ in range(w)]
ps = set()
for i in range(m):
hi, wi = [int(x) - 1 for x in input().split()]
h_array[hi] += 1
w_array[wi] += 1
ps.add((hi, wi))
h_great = max(h_array)
w_great = max(w_array)
h_greats = list()
w_greats = list()
for i, hi in enumerate(h_array):
if hi == h_great:
h_greats.append(i)
for i, wi in enumerate(w_array):
if wi == w_great:
w_greats.append(i)
ans = h_great + w_great
for _h in h_greats:
for _w in w_greats:
if (_h, _w) in ps:
continue
print(ans)
exit()
print((ans - 1))
if __name__ == "__main__":
main()
| false | 10 | [
"-h, w, m = list(map(int, input().split()))",
"-h_array = [0 for i in range(h)]",
"-w_array = [0 for i in range(w)]",
"-ps = set()",
"-for i in range(m):",
"- hi, wi = [int(x) - 1 for x in input().split()]",
"- h_array[hi] += 1",
"- w_array[wi] += 1",
"- ps.add((hi, wi))",
"-h_great = max(h_array)",
"-w_great = max(w_array)",
"-h_greats = list()",
"-w_greats = list()",
"-for i, hi in enumerate(h_array):",
"- if hi == h_great:",
"- h_greats.append(i)",
"-for i, wi in enumerate(w_array):",
"- if wi == w_great:",
"- w_greats.append(i)",
"-ans = h_great + w_great",
"-for _h in h_greats:",
"- for _w in w_greats:",
"- if (_h, _w) in ps:",
"- continue",
"- print(ans)",
"- exit()",
"-print((ans - 1))",
"+",
"+",
"+def main():",
"+ h, w, m = list(map(int, input().split()))",
"+ h_array = [0 for _ in range(h)]",
"+ w_array = [0 for _ in range(w)]",
"+ ps = set()",
"+ for i in range(m):",
"+ hi, wi = [int(x) - 1 for x in input().split()]",
"+ h_array[hi] += 1",
"+ w_array[wi] += 1",
"+ ps.add((hi, wi))",
"+ h_great = max(h_array)",
"+ w_great = max(w_array)",
"+ h_greats = list()",
"+ w_greats = list()",
"+ for i, hi in enumerate(h_array):",
"+ if hi == h_great:",
"+ h_greats.append(i)",
"+ for i, wi in enumerate(w_array):",
"+ if wi == w_great:",
"+ w_greats.append(i)",
"+ ans = h_great + w_great",
"+ for _h in h_greats:",
"+ for _w in w_greats:",
"+ if (_h, _w) in ps:",
"+ continue",
"+ print(ans)",
"+ exit()",
"+ print((ans - 1))",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.037439 | 0.057451 | 0.651668 | [
"s338195774",
"s724355061"
] |
u126232616 | p03607 | python | s514449642 | s738705965 | 221 | 203 | 15,068 | 11,884 | Accepted | Accepted | 8.14 | n = int(eval(input()))
d = {}
for i in range(n):
a = int(eval(input()))
if a in d:
d[a] = not d[a]
else:
d[a] = True
ans = 0
for i in d:
if d[i]: ans += 1
print(ans) | n = int(eval(input()))
d = set()
for i in range(n):
a = int(eval(input()))
if a in d:
d.remove(a)
else:
d.add(a)
print((len(d))) | 12 | 9 | 196 | 150 | n = int(eval(input()))
d = {}
for i in range(n):
a = int(eval(input()))
if a in d:
d[a] = not d[a]
else:
d[a] = True
ans = 0
for i in d:
if d[i]:
ans += 1
print(ans)
| n = int(eval(input()))
d = set()
for i in range(n):
a = int(eval(input()))
if a in d:
d.remove(a)
else:
d.add(a)
print((len(d)))
| false | 25 | [
"-d = {}",
"+d = set()",
"- d[a] = not d[a]",
"+ d.remove(a)",
"- d[a] = True",
"-ans = 0",
"-for i in d:",
"- if d[i]:",
"- ans += 1",
"-print(ans)",
"+ d.add(a)",
"+print((len(d)))"
] | false | 0.008508 | 0.092838 | 0.091641 | [
"s514449642",
"s738705965"
] |
u887207211 | p03449 | python | s110303544 | s464564368 | 26 | 17 | 3,060 | 3,060 | Accepted | Accepted | 34.62 | N = int(eval(input()))
A = [list(map(int,input().split())) for _ in range(2)]
ma = 0
for i in range(N):
ma = max(ma, sum(A[0][0:i+1])+sum(A[1][i:]))
print(ma) | N = int(eval(input()))
A = [list(map(int,input().split())) for _ in range(2)]
candie = 0
for i in range(N):
candie = max(candie, sum(A[0][0:i+1]) + sum(A[1][i:]))
print(candie) | 7 | 6 | 161 | 177 | N = int(eval(input()))
A = [list(map(int, input().split())) for _ in range(2)]
ma = 0
for i in range(N):
ma = max(ma, sum(A[0][0 : i + 1]) + sum(A[1][i:]))
print(ma)
| N = int(eval(input()))
A = [list(map(int, input().split())) for _ in range(2)]
candie = 0
for i in range(N):
candie = max(candie, sum(A[0][0 : i + 1]) + sum(A[1][i:]))
print(candie)
| false | 14.285714 | [
"-ma = 0",
"+candie = 0",
"- ma = max(ma, sum(A[0][0 : i + 1]) + sum(A[1][i:]))",
"-print(ma)",
"+ candie = max(candie, sum(A[0][0 : i + 1]) + sum(A[1][i:]))",
"+print(candie)"
] | false | 0.040013 | 0.037896 | 1.055857 | [
"s110303544",
"s464564368"
] |
u585482323 | p02713 | python | s985809176 | s506752654 | 987 | 314 | 78,048 | 71,004 | Accepted | Accepted | 68.19 | #!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():
mem = defaultdict(lambda : None)
def gcd(a,b):
if mem[(a,b)] != None:
return mem[(a,b)]
if a == 0:
mem[(a,b)] = mem[(b,a)] = b
return b
mem[(a,b)] = mem[(b,a)] = gcd(b%a,a)
return mem[(a,b)]
k = I()
ans = 0
for a in range(1,k+1):
for b in range(1,k+1):
g = gcd(a,b)
for c in range(1,k+1):
ans += gcd(g,c)
print(ans)
return
#Solve
if __name__ == "__main__":
solve()
| #!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():
def gcd(a,b):
if a == 0:
return b
return gcd(b%a, a)
k = I()
ans = 0
for a in range(1,k+1):
for b in range(1,k+1):
g = gcd(a,b)
for c in range(1,k+1):
ans += gcd(g,c)
print(ans)
return
#Solve
if __name__ == "__main__":
solve()
| 50 | 45 | 1,292 | 1,105 | #!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():
mem = defaultdict(lambda: None)
def gcd(a, b):
if mem[(a, b)] != None:
return mem[(a, b)]
if a == 0:
mem[(a, b)] = mem[(b, a)] = b
return b
mem[(a, b)] = mem[(b, a)] = gcd(b % a, a)
return mem[(a, b)]
k = I()
ans = 0
for a in range(1, k + 1):
for b in range(1, k + 1):
g = gcd(a, b)
for c in range(1, k + 1):
ans += gcd(g, c)
print(ans)
return
# Solve
if __name__ == "__main__":
solve()
| #!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():
def gcd(a, b):
if a == 0:
return b
return gcd(b % a, a)
k = I()
ans = 0
for a in range(1, k + 1):
for b in range(1, k + 1):
g = gcd(a, b)
for c in range(1, k + 1):
ans += gcd(g, c)
print(ans)
return
# Solve
if __name__ == "__main__":
solve()
| false | 10 | [
"- mem = defaultdict(lambda: None)",
"-",
"- if mem[(a, b)] != None:",
"- return mem[(a, b)]",
"- mem[(a, b)] = mem[(b, a)] = b",
"- mem[(a, b)] = mem[(b, a)] = gcd(b % a, a)",
"- return mem[(a, b)]",
"+ return gcd(b % a, a)"
] | false | 0.045853 | 0.045961 | 0.997638 | [
"s985809176",
"s506752654"
] |
u250734103 | p02683 | python | s677875154 | s944257713 | 95 | 84 | 11,920 | 9,216 | Accepted | Accepted | 11.58 | N, M, X = list(map(int, input().split()))
CA = [list(map(int, input().split())) for i in range(N)]
set_list = []
for i in range(2 ** N):
select = []
for j in range(N):
if ((i >> j) & 1):
select.append(j)
if len(select) != 0:
set_list.append(select)
cost = []
for i in range(2 ** N - 1):
cost.append(sum([CA[set_list[i][j]][0] for j in range(len(set_list[i]))]))
skill = []
for i in range(2 ** N - 1):
tmp = [0]*M
for j in set_list[i]:
for k in range(M):
tmp[k] += CA[j][k+1]
skill.append(tmp)
pool = []
for i in range(2**N - 1):
flag = 0
for j in skill[i]:
if j < X:
flag = 1
if flag == 0:
pool.append(cost[i])
if len(pool) == 0:
print((-1))
else:
print((min(pool)))
| from itertools import combinations
N, M, X = list(map(int, input().split()))
C, A = [], []
for i in range(N):
c, *a = list(map(int, input().split()))
C.append(c)
A.append(a)
ans = float('INF')
for i in range(1,N+1):
for li in combinations(list(range(N)), i):
cost = 0
skill = [0] * M
for j in li:
cost += C[j]
for k in range(M):
skill[k] += A[j][k]
if all([s >= X for s in skill]):
ans = min(ans, cost)
if ans == float('INF'):
print((-1))
else:
print(ans) | 38 | 24 | 839 | 574 | N, M, X = list(map(int, input().split()))
CA = [list(map(int, input().split())) for i in range(N)]
set_list = []
for i in range(2**N):
select = []
for j in range(N):
if (i >> j) & 1:
select.append(j)
if len(select) != 0:
set_list.append(select)
cost = []
for i in range(2**N - 1):
cost.append(sum([CA[set_list[i][j]][0] for j in range(len(set_list[i]))]))
skill = []
for i in range(2**N - 1):
tmp = [0] * M
for j in set_list[i]:
for k in range(M):
tmp[k] += CA[j][k + 1]
skill.append(tmp)
pool = []
for i in range(2**N - 1):
flag = 0
for j in skill[i]:
if j < X:
flag = 1
if flag == 0:
pool.append(cost[i])
if len(pool) == 0:
print((-1))
else:
print((min(pool)))
| from itertools import combinations
N, M, X = list(map(int, input().split()))
C, A = [], []
for i in range(N):
c, *a = list(map(int, input().split()))
C.append(c)
A.append(a)
ans = float("INF")
for i in range(1, N + 1):
for li in combinations(list(range(N)), i):
cost = 0
skill = [0] * M
for j in li:
cost += C[j]
for k in range(M):
skill[k] += A[j][k]
if all([s >= X for s in skill]):
ans = min(ans, cost)
if ans == float("INF"):
print((-1))
else:
print(ans)
| false | 36.842105 | [
"+from itertools import combinations",
"+",
"-CA = [list(map(int, input().split())) for i in range(N)]",
"-set_list = []",
"-for i in range(2**N):",
"- select = []",
"- for j in range(N):",
"- if (i >> j) & 1:",
"- select.append(j)",
"- if len(select) != 0:",
"- set_list.append(select)",
"-cost = []",
"-for i in range(2**N - 1):",
"- cost.append(sum([CA[set_list[i][j]][0] for j in range(len(set_list[i]))]))",
"-skill = []",
"-for i in range(2**N - 1):",
"- tmp = [0] * M",
"- for j in set_list[i]:",
"- for k in range(M):",
"- tmp[k] += CA[j][k + 1]",
"- skill.append(tmp)",
"-pool = []",
"-for i in range(2**N - 1):",
"- flag = 0",
"- for j in skill[i]:",
"- if j < X:",
"- flag = 1",
"- if flag == 0:",
"- pool.append(cost[i])",
"-if len(pool) == 0:",
"+C, A = [], []",
"+for i in range(N):",
"+ c, *a = list(map(int, input().split()))",
"+ C.append(c)",
"+ A.append(a)",
"+ans = float(\"INF\")",
"+for i in range(1, N + 1):",
"+ for li in combinations(list(range(N)), i):",
"+ cost = 0",
"+ skill = [0] * M",
"+ for j in li:",
"+ cost += C[j]",
"+ for k in range(M):",
"+ skill[k] += A[j][k]",
"+ if all([s >= X for s in skill]):",
"+ ans = min(ans, cost)",
"+if ans == float(\"INF\"):",
"- print((min(pool)))",
"+ print(ans)"
] | false | 0.038933 | 0.03805 | 1.023224 | [
"s677875154",
"s944257713"
] |
u968166680 | p03853 | python | s458181657 | s955555033 | 28 | 25 | 9,184 | 9,104 | Accepted | Accepted | 10.71 | import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
H, W = map(int, readline().split())
C = [readline().strip() for _ in range(H)]
ans = [0] * (2 * H)
for i in range(2 * H):
ans[i] = C[i // 2]
print(*ans, sep='\n')
return
if __name__ == '__main__':
main()
| import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
H, W = list(map(int, readline().split()))
C = [readline().strip() for _ in range(H)]
for i in range(2 * H):
print((C[i // 2]))
return
if __name__ == '__main__':
main()
| 25 | 22 | 441 | 385 | import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60
MOD = 1000000007
def main():
H, W = map(int, readline().split())
C = [readline().strip() for _ in range(H)]
ans = [0] * (2 * H)
for i in range(2 * H):
ans[i] = C[i // 2]
print(*ans, sep="\n")
return
if __name__ == "__main__":
main()
| import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60
MOD = 1000000007
def main():
H, W = list(map(int, readline().split()))
C = [readline().strip() for _ in range(H)]
for i in range(2 * H):
print((C[i // 2]))
return
if __name__ == "__main__":
main()
| false | 12 | [
"- H, W = map(int, readline().split())",
"+ H, W = list(map(int, readline().split()))",
"- ans = [0] * (2 * H)",
"- ans[i] = C[i // 2]",
"- print(*ans, sep=\"\\n\")",
"+ print((C[i // 2]))"
] | false | 0.081706 | 0.073196 | 1.116274 | [
"s458181657",
"s955555033"
] |
u440180827 | p02382 | python | s642233865 | s354233224 | 30 | 20 | 7,804 | 7,868 | Accepted | Accepted | 33.33 | n = int(eval(input()))
x = list(map(int, input().split()))
y = list(map(int, input().split()))
tmp = [[0 for i in range(6)] for j in range(n+1)]
absDiff = abs(x[0]-y[0])
tmp[0][3] = tmp[0][0] = absDiff
tmp[0][4] = tmp[0][1] = absDiff ** 2
tmp[0][5] = tmp[0][2] = absDiff ** 3
max = absDiff
for i in range(1, n, 1):
absDiff = abs(x[i]-y[i])
tmp[i][0] = absDiff
tmp[i][1] = absDiff ** 2
tmp[i][2] = absDiff ** 3
tmp[i][3] = tmp[i-1][3] + tmp[i][0]
tmp[i][4] = tmp[i-1][4] + tmp[i][1]
tmp[i][5] = tmp[i-1][5] + tmp[i][2]
if absDiff > max:
max = absDiff
print((tmp[n-1][3]))
print((tmp[n-1][4] ** (1/2)))
print((tmp[n-1][5] ** (1/3)))
print(max) | n = int(eval(input()))
x = list(map(int, input().split()))
y = list(map(int, input().split()))
tmp = [[0 for i in range(6)] for j in range(n+1)]
absDiff = abs(x[0]-y[0])
tmp[0][3] = tmp[0][0] = absDiff
tmp[0][4] = tmp[0][1] = absDiff ** 2
tmp[0][5] = tmp[0][2] = absDiff ** 3
max = absDiff
for i in range(1, n, 1):
absDiff = abs(x[i]-y[i])
tmp[i][0] = absDiff
tmp[i][1] = absDiff ** 2
tmp[i][2] = tmp[i][1] * absDiff
tmp[i][3] = tmp[i-1][3] + tmp[i][0]
tmp[i][4] = tmp[i-1][4] + tmp[i][1]
tmp[i][5] = tmp[i-1][5] + tmp[i][2]
if absDiff > max:
max = absDiff
print((tmp[n-1][3]))
print((tmp[n-1][4] ** (1/2)))
print((tmp[n-1][5] ** (1/3)))
print(max) | 23 | 23 | 691 | 698 | n = int(eval(input()))
x = list(map(int, input().split()))
y = list(map(int, input().split()))
tmp = [[0 for i in range(6)] for j in range(n + 1)]
absDiff = abs(x[0] - y[0])
tmp[0][3] = tmp[0][0] = absDiff
tmp[0][4] = tmp[0][1] = absDiff**2
tmp[0][5] = tmp[0][2] = absDiff**3
max = absDiff
for i in range(1, n, 1):
absDiff = abs(x[i] - y[i])
tmp[i][0] = absDiff
tmp[i][1] = absDiff**2
tmp[i][2] = absDiff**3
tmp[i][3] = tmp[i - 1][3] + tmp[i][0]
tmp[i][4] = tmp[i - 1][4] + tmp[i][1]
tmp[i][5] = tmp[i - 1][5] + tmp[i][2]
if absDiff > max:
max = absDiff
print((tmp[n - 1][3]))
print((tmp[n - 1][4] ** (1 / 2)))
print((tmp[n - 1][5] ** (1 / 3)))
print(max)
| n = int(eval(input()))
x = list(map(int, input().split()))
y = list(map(int, input().split()))
tmp = [[0 for i in range(6)] for j in range(n + 1)]
absDiff = abs(x[0] - y[0])
tmp[0][3] = tmp[0][0] = absDiff
tmp[0][4] = tmp[0][1] = absDiff**2
tmp[0][5] = tmp[0][2] = absDiff**3
max = absDiff
for i in range(1, n, 1):
absDiff = abs(x[i] - y[i])
tmp[i][0] = absDiff
tmp[i][1] = absDiff**2
tmp[i][2] = tmp[i][1] * absDiff
tmp[i][3] = tmp[i - 1][3] + tmp[i][0]
tmp[i][4] = tmp[i - 1][4] + tmp[i][1]
tmp[i][5] = tmp[i - 1][5] + tmp[i][2]
if absDiff > max:
max = absDiff
print((tmp[n - 1][3]))
print((tmp[n - 1][4] ** (1 / 2)))
print((tmp[n - 1][5] ** (1 / 3)))
print(max)
| false | 0 | [
"- tmp[i][2] = absDiff**3",
"+ tmp[i][2] = tmp[i][1] * absDiff"
] | false | 0.034785 | 0.037857 | 0.918863 | [
"s642233865",
"s354233224"
] |
u644907318 | p03497 | python | s499205478 | s756419459 | 345 | 186 | 103,112 | 129,316 | Accepted | Accepted | 46.09 | N,K = list(map(int,input().split()))
A = list(map(int,input().split()))
C = {}
for i in range(N):
if A[i] not in C:
C[A[i]] = 0
C[A[i]] += 1
C = sorted(list(C.items()),key=lambda x:x[1],reverse=True)
n = len(C)
if n<=K:
cnt = 0
else:
cnt = 0
for i in range(K,n):
cnt += C[i][1]
print(cnt) | N,K = list(map(int,input().split()))
A = list(map(int,input().split()))
C = {}
for i in range(N):
a = A[i]
if a not in C:
C[a] = 0
C[a] += 1
C = sorted(list(C.items()),key=lambda x:x[1],reverse=True)
if len(C)<=K:
print((0))
else:
cnt = 0
for i in range(K,len(C)):
cnt += C[i][1]
print(cnt) | 16 | 16 | 333 | 341 | N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
C = {}
for i in range(N):
if A[i] not in C:
C[A[i]] = 0
C[A[i]] += 1
C = sorted(list(C.items()), key=lambda x: x[1], reverse=True)
n = len(C)
if n <= K:
cnt = 0
else:
cnt = 0
for i in range(K, n):
cnt += C[i][1]
print(cnt)
| N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
C = {}
for i in range(N):
a = A[i]
if a not in C:
C[a] = 0
C[a] += 1
C = sorted(list(C.items()), key=lambda x: x[1], reverse=True)
if len(C) <= K:
print((0))
else:
cnt = 0
for i in range(K, len(C)):
cnt += C[i][1]
print(cnt)
| false | 0 | [
"- if A[i] not in C:",
"- C[A[i]] = 0",
"- C[A[i]] += 1",
"+ a = A[i]",
"+ if a not in C:",
"+ C[a] = 0",
"+ C[a] += 1",
"-n = len(C)",
"-if n <= K:",
"- cnt = 0",
"+if len(C) <= K:",
"+ print((0))",
"- for i in range(K, n):",
"+ for i in range(K, len(C)):",
"-print(cnt)",
"+ print(cnt)"
] | false | 0.036777 | 0.036208 | 1.015707 | [
"s499205478",
"s756419459"
] |
u888092736 | p03103 | python | s694982566 | s440438106 | 408 | 287 | 17,000 | 16,976 | Accepted | Accepted | 29.66 | N, M = list(map(int, input().split()))
drinks = sorted(tuple(map(int, input().split())) for _ in range(N))
ans = 0
for A, B in drinks:
if M > B:
ans += A * B
M -= B
else:
ans += A * M
break
print(ans)
| import sys
def input():
return sys.stdin.readline().strip()
N, M = list(map(int, input().split()))
drinks = sorted(tuple(map(int, input().split())) for _ in range(N))
ans = 0
for A, B in drinks:
if M > B:
ans += A * B
M -= B
else:
ans += A * M
break
print(ans)
| 11 | 18 | 245 | 320 | N, M = list(map(int, input().split()))
drinks = sorted(tuple(map(int, input().split())) for _ in range(N))
ans = 0
for A, B in drinks:
if M > B:
ans += A * B
M -= B
else:
ans += A * M
break
print(ans)
| import sys
def input():
return sys.stdin.readline().strip()
N, M = list(map(int, input().split()))
drinks = sorted(tuple(map(int, input().split())) for _ in range(N))
ans = 0
for A, B in drinks:
if M > B:
ans += A * B
M -= B
else:
ans += A * M
break
print(ans)
| false | 38.888889 | [
"+import sys",
"+",
"+",
"+def input():",
"+ return sys.stdin.readline().strip()",
"+",
"+"
] | false | 0.038267 | 0.035638 | 1.073772 | [
"s694982566",
"s440438106"
] |
u923668099 | p00711 | python | s701824914 | s117743483 | 120 | 90 | 8,024 | 7,784 | Accepted | Accepted | 25 | import sys
from collections import deque
def solve():
while 1:
w, h = list(map(int, sys.stdin.readline().split()))
if w == h == 0:
return
room = [[False]*w for i in range(h)]
si = sj = -1
for i in range(h):
line = eval(input())
for j, ch in enumerate(line):
if ch == '@':
room[i][j] = True
si = i
sj = j
elif ch == '.':
room[i][j] = True
ans = bfs(w, h, room, si, sj)
print(ans)
dx = (1, 0, -1, 0,)
dy = (0, 1, 0, -1,)
def bfs(w, h, room, si, sj):
visited = [[False]*w for i in range(h)]
visited[si][sj] = True
q = deque([(si, sj)])
cnt = 1
while q:
ci, cj = q.popleft()
for k in range(len(dx)):
ni = ci + dy[k]
nj = cj + dx[k]
if 0 <= ni < h and 0 <= nj < w and room[ni][nj] and not visited[ni][nj]:
visited[ni][nj] = True
q.append((ni, nj))
cnt += 1
return cnt
if __name__ == '__main__':
solve() | import sys
cnt = 0
def solve():
while 1:
w, h = list(map(int, sys.stdin.readline().split()))
if w == h == 0:
return
room = [list(sys.stdin.readline().rstrip()) for i in range(h)]
for i in range(h):
if '@' in room[i]:
si = i
sj = room[i].index('@')
break
global cnt
cnt = 0
dfs(w, h, room, si, sj)
print(cnt)
def dfs(w, h, room, i, j):
if i < 0 or i >= h or j < 0 or j >= w or (room[i][j] == '#'):
return
global cnt
cnt += 1
room[i][j] = '#'
dfs(w, h, room, i + 1, j)
dfs(w, h, room, i - 1, j)
dfs(w, h, room, i, j + 1)
dfs(w, h, room, i, j - 1)
if __name__ == '__main__':
solve() | 54 | 39 | 1,189 | 805 | import sys
from collections import deque
def solve():
while 1:
w, h = list(map(int, sys.stdin.readline().split()))
if w == h == 0:
return
room = [[False] * w for i in range(h)]
si = sj = -1
for i in range(h):
line = eval(input())
for j, ch in enumerate(line):
if ch == "@":
room[i][j] = True
si = i
sj = j
elif ch == ".":
room[i][j] = True
ans = bfs(w, h, room, si, sj)
print(ans)
dx = (
1,
0,
-1,
0,
)
dy = (
0,
1,
0,
-1,
)
def bfs(w, h, room, si, sj):
visited = [[False] * w for i in range(h)]
visited[si][sj] = True
q = deque([(si, sj)])
cnt = 1
while q:
ci, cj = q.popleft()
for k in range(len(dx)):
ni = ci + dy[k]
nj = cj + dx[k]
if 0 <= ni < h and 0 <= nj < w and room[ni][nj] and not visited[ni][nj]:
visited[ni][nj] = True
q.append((ni, nj))
cnt += 1
return cnt
if __name__ == "__main__":
solve()
| import sys
cnt = 0
def solve():
while 1:
w, h = list(map(int, sys.stdin.readline().split()))
if w == h == 0:
return
room = [list(sys.stdin.readline().rstrip()) for i in range(h)]
for i in range(h):
if "@" in room[i]:
si = i
sj = room[i].index("@")
break
global cnt
cnt = 0
dfs(w, h, room, si, sj)
print(cnt)
def dfs(w, h, room, i, j):
if i < 0 or i >= h or j < 0 or j >= w or (room[i][j] == "#"):
return
global cnt
cnt += 1
room[i][j] = "#"
dfs(w, h, room, i + 1, j)
dfs(w, h, room, i - 1, j)
dfs(w, h, room, i, j + 1)
dfs(w, h, room, i, j - 1)
if __name__ == "__main__":
solve()
| false | 27.777778 | [
"-from collections import deque",
"+",
"+cnt = 0",
"- room = [[False] * w for i in range(h)]",
"- si = sj = -1",
"+ room = [list(sys.stdin.readline().rstrip()) for i in range(h)]",
"- line = eval(input())",
"- for j, ch in enumerate(line):",
"- if ch == \"@\":",
"- room[i][j] = True",
"- si = i",
"- sj = j",
"- elif ch == \".\":",
"- room[i][j] = True",
"- ans = bfs(w, h, room, si, sj)",
"- print(ans)",
"+ if \"@\" in room[i]:",
"+ si = i",
"+ sj = room[i].index(\"@\")",
"+ break",
"+ global cnt",
"+ cnt = 0",
"+ dfs(w, h, room, si, sj)",
"+ print(cnt)",
"-dx = (",
"- 1,",
"- 0,",
"- -1,",
"- 0,",
"-)",
"-dy = (",
"- 0,",
"- 1,",
"- 0,",
"- -1,",
"-)",
"-",
"-",
"-def bfs(w, h, room, si, sj):",
"- visited = [[False] * w for i in range(h)]",
"- visited[si][sj] = True",
"- q = deque([(si, sj)])",
"- cnt = 1",
"- while q:",
"- ci, cj = q.popleft()",
"- for k in range(len(dx)):",
"- ni = ci + dy[k]",
"- nj = cj + dx[k]",
"- if 0 <= ni < h and 0 <= nj < w and room[ni][nj] and not visited[ni][nj]:",
"- visited[ni][nj] = True",
"- q.append((ni, nj))",
"- cnt += 1",
"- return cnt",
"+def dfs(w, h, room, i, j):",
"+ if i < 0 or i >= h or j < 0 or j >= w or (room[i][j] == \"#\"):",
"+ return",
"+ global cnt",
"+ cnt += 1",
"+ room[i][j] = \"#\"",
"+ dfs(w, h, room, i + 1, j)",
"+ dfs(w, h, room, i - 1, j)",
"+ dfs(w, h, room, i, j + 1)",
"+ dfs(w, h, room, i, j - 1)"
] | false | 0.039284 | 0.0431 | 0.911457 | [
"s701824914",
"s117743483"
] |
u424209323 | p02234 | python | s304038934 | s466992438 | 80 | 60 | 6,480 | 6,472 | Accepted | Accepted | 25 | def mcm(M):
n = len(M)
m = [[0 for i in range(n)] for j in range(n)]
for l in range(2, n+1):
for i in range(0, n-l+1):
j = i + l - 1
def cost(i, k ,j):
return m[i][k] + m[k+1][j] + M[i][0]*M[k][1]*M[j][1]
m[i][j] = min(cost(i, k, j) for k in range(i, j))
return m[0][n-1]
n = eval(input())
M = []
for i in range(n):
M.append(list(map(int, input().split())))
print(mcm(M)) | def matrix(n):
x = [[0 for i in range(len(n))] for j in range(len(n))]
for l in range(2, len(n)+1):
for i in range(0, len(n)-l+1):
j = i + l - 1
x[i][j] = min(x[i][k] + x[k+1][j] + X[i][0]*X[k][1]*X[j][1] for k in range(i, j))
print(x[0][len(n)-1])
n = eval(input())
X = []
for i in range(n):
X.append(list(map(int, input().split())))
matrix(X) | 19 | 16 | 432 | 402 | def mcm(M):
n = len(M)
m = [[0 for i in range(n)] for j in range(n)]
for l in range(2, n + 1):
for i in range(0, n - l + 1):
j = i + l - 1
def cost(i, k, j):
return m[i][k] + m[k + 1][j] + M[i][0] * M[k][1] * M[j][1]
m[i][j] = min(cost(i, k, j) for k in range(i, j))
return m[0][n - 1]
n = eval(input())
M = []
for i in range(n):
M.append(list(map(int, input().split())))
print(mcm(M))
| def matrix(n):
x = [[0 for i in range(len(n))] for j in range(len(n))]
for l in range(2, len(n) + 1):
for i in range(0, len(n) - l + 1):
j = i + l - 1
x[i][j] = min(
x[i][k] + x[k + 1][j] + X[i][0] * X[k][1] * X[j][1] for k in range(i, j)
)
print(x[0][len(n) - 1])
n = eval(input())
X = []
for i in range(n):
X.append(list(map(int, input().split())))
matrix(X)
| false | 15.789474 | [
"-def mcm(M):",
"- n = len(M)",
"- m = [[0 for i in range(n)] for j in range(n)]",
"- for l in range(2, n + 1):",
"- for i in range(0, n - l + 1):",
"+def matrix(n):",
"+ x = [[0 for i in range(len(n))] for j in range(len(n))]",
"+ for l in range(2, len(n) + 1):",
"+ for i in range(0, len(n) - l + 1):",
"-",
"- def cost(i, k, j):",
"- return m[i][k] + m[k + 1][j] + M[i][0] * M[k][1] * M[j][1]",
"-",
"- m[i][j] = min(cost(i, k, j) for k in range(i, j))",
"- return m[0][n - 1]",
"+ x[i][j] = min(",
"+ x[i][k] + x[k + 1][j] + X[i][0] * X[k][1] * X[j][1] for k in range(i, j)",
"+ )",
"+ print(x[0][len(n) - 1])",
"-M = []",
"+X = []",
"- M.append(list(map(int, input().split())))",
"-print(mcm(M))",
"+ X.append(list(map(int, input().split())))",
"+matrix(X)"
] | false | 0.035834 | 0.038938 | 0.92028 | [
"s304038934",
"s466992438"
] |
u532966492 | p03111 | python | s022044881 | s577463136 | 699 | 70 | 3,064 | 3,064 | Accepted | Accepted | 89.99 | N,A,B,C=list(map(int,input().split()))
l=[int(eval(input())) for _ in range(N)]
ABC=[A,B,C]
def base2n(Num,n):
if Num<n:
return str(Num)
else:
return base2n(Num//n,n)+str(Num%n)
ans=10**6
for i in range(4**N):
i_4=("0"*N+base2n(i,4))[-N:]
Group=[[] for i in range(4)]
for j in range(N):
Group[int(i_4[j])-1].append(l[j])
if len(Group[0])*len(Group[1])*len(Group[2])!=0:
ans=min(ans,(N-3-len(Group[3]))*10+sum([abs(ABC[j] - sum(Group[j])) for j in range(3)]))
print(ans) | N,A,B,C=list(map(int,input().split()))
l=[int(eval(input())) for _ in range(N)]
inf=10**6
def dfs(cur,a,b,c):
if cur==N:
if min(a,b,c)>0:
return abs(A-a)+abs(B-b)+abs(C-c)-30
else:
return inf
else:
ret0=dfs(cur+1,a,b,c)
ret1=dfs(cur+1,a+l[cur],b,c)+10
ret2=dfs(cur+1,a,b+l[cur],c)+10
ret3=dfs(cur+1,a,b,c+l[cur])+10
return min(ret0,ret1,ret2,ret3)
print((dfs(0,0,0,0))) | 21 | 18 | 549 | 462 | N, A, B, C = list(map(int, input().split()))
l = [int(eval(input())) for _ in range(N)]
ABC = [A, B, C]
def base2n(Num, n):
if Num < n:
return str(Num)
else:
return base2n(Num // n, n) + str(Num % n)
ans = 10**6
for i in range(4**N):
i_4 = ("0" * N + base2n(i, 4))[-N:]
Group = [[] for i in range(4)]
for j in range(N):
Group[int(i_4[j]) - 1].append(l[j])
if len(Group[0]) * len(Group[1]) * len(Group[2]) != 0:
ans = min(
ans,
(N - 3 - len(Group[3])) * 10
+ sum([abs(ABC[j] - sum(Group[j])) for j in range(3)]),
)
print(ans)
| N, A, B, C = list(map(int, input().split()))
l = [int(eval(input())) for _ in range(N)]
inf = 10**6
def dfs(cur, a, b, c):
if cur == N:
if min(a, b, c) > 0:
return abs(A - a) + abs(B - b) + abs(C - c) - 30
else:
return inf
else:
ret0 = dfs(cur + 1, a, b, c)
ret1 = dfs(cur + 1, a + l[cur], b, c) + 10
ret2 = dfs(cur + 1, a, b + l[cur], c) + 10
ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10
return min(ret0, ret1, ret2, ret3)
print((dfs(0, 0, 0, 0)))
| false | 14.285714 | [
"-ABC = [A, B, C]",
"+inf = 10**6",
"-def base2n(Num, n):",
"- if Num < n:",
"- return str(Num)",
"+def dfs(cur, a, b, c):",
"+ if cur == N:",
"+ if min(a, b, c) > 0:",
"+ return abs(A - a) + abs(B - b) + abs(C - c) - 30",
"+ else:",
"+ return inf",
"- return base2n(Num // n, n) + str(Num % n)",
"+ ret0 = dfs(cur + 1, a, b, c)",
"+ ret1 = dfs(cur + 1, a + l[cur], b, c) + 10",
"+ ret2 = dfs(cur + 1, a, b + l[cur], c) + 10",
"+ ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10",
"+ return min(ret0, ret1, ret2, ret3)",
"-ans = 10**6",
"-for i in range(4**N):",
"- i_4 = (\"0\" * N + base2n(i, 4))[-N:]",
"- Group = [[] for i in range(4)]",
"- for j in range(N):",
"- Group[int(i_4[j]) - 1].append(l[j])",
"- if len(Group[0]) * len(Group[1]) * len(Group[2]) != 0:",
"- ans = min(",
"- ans,",
"- (N - 3 - len(Group[3])) * 10",
"- + sum([abs(ABC[j] - sum(Group[j])) for j in range(3)]),",
"- )",
"-print(ans)",
"+print((dfs(0, 0, 0, 0)))"
] | false | 1.659315 | 0.085183 | 19.479518 | [
"s022044881",
"s577463136"
] |
u389910364 | p02949 | python | s816426869 | s431521500 | 1,032 | 679 | 56,284 | 48,604 | Accepted | Accepted | 34.21 | import os
import sys
if os.getenv("LOCAL"):
sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
N, M, P = list(map(int, sys.stdin.readline().split()))
ABC = [list(map(int, sys.stdin.readline().split())) for _ in range(M)]
graph = [[] for _ in range(N)]
for a, b, c in ABC:
graph[a - 1].append((b - 1, P - c))
def can_go_from_0():
# 1 からのパスがある
ret = [False] * N
stack = [0]
while stack:
v = stack.pop()
ret[v] = True
for u, _ in graph[v]:
if not ret[u]:
ret[u] = True
stack.append(u)
return ret
def can_go_to_n():
revs = [[] for _ in range(N)]
for a, b, c in ABC:
revs[b - 1].append(a - 1)
# n へのパスがある
ret = [False] * N
stack = [N - 1]
while stack:
v = stack.pop()
ret[v] = True
for u in revs[v]:
if not ret[u]:
ret[u] = True
stack.append(u)
return ret
vertices = []
for i, (v1, v2) in enumerate(zip(can_go_from_0(), can_go_to_n())):
if v1 & v2:
vertices.append(i)
# bellman-ford
dist = [INF] * N
dist[0] = 0
for i in range(N):
for v in vertices:
for u, d in graph[v]:
dist[u] = min(dist[v] + d, dist[u])
# 使う頂点がまだアップデートされたらダメ
prev = dist[:]
for v in vertices:
for u, d in graph[v]:
dist[u] = min(dist[v] + d, dist[u])
updated = False
for v in vertices:
updated |= prev[v] != dist[v]
if updated or dist[N - 1] == INF:
print((-1))
else:
print((max(-dist[N - 1], 0)))
| import os
import sys
if os.getenv("LOCAL"):
sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
N, M, P = list(map(int, sys.stdin.readline().split()))
ABC = [list(map(int, sys.stdin.readline().split())) for _ in range(M)]
graph = [[] for _ in range(N)]
for a, b, c in ABC:
graph[a - 1].append((b - 1, P - c))
def bellman_ford(graph, from_v, to_v):
"""
到達できないなら INF、負閉路があったら -INF
:param list of (list of (int, int)) graph: (to, cap) の隣接リスト
:param int from_v:
:param int to_v:
:rtype: int
"""
def reachable(graph, from_v):
"""
graph 上で from_v から到達できるかどうかのリスト
:param graph:
:param from_v:
"""
ret = [False] * len(graph)
ret[from_v] = True
stack = [from_v]
while stack:
v = stack.pop()
for u, _ in graph[v]:
if not ret[u]:
ret[u] = True
stack.append(u)
return ret
# from_v から到達でき、かつ to_v へ到達できる頂点のみ考える
# これら以外には負閉路があっても関係ない
vertices = []
revs = [[] for _ in range(len(graph))]
for v, ud in enumerate(graph):
for u, d in ud:
revs[u].append((v, d))
for v, (r1, r2) in enumerate(zip(reachable(graph, from_v), reachable(revs, to_v))):
if r1 & r2:
vertices.append(v)
dist = [float('inf')] * len(graph)
dist[from_v] = 0
updated = True
for _ in range(len(graph) + 1):
updated = False
for v in vertices:
for u, d in graph[v]:
if dist[v] + d < dist[u]:
dist[u] = dist[v] + d
updated = True
if not updated:
break
return -float('inf') if updated else dist[to_v]
ans = -bellman_ford(graph, 0, N - 1)
if ans == INF or ans == -INF:
print((-1))
else:
print((max(0, ans)))
| 78 | 76 | 1,681 | 1,999 | import os
import sys
if os.getenv("LOCAL"):
sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10**18
MOD = 10**9 + 7
N, M, P = list(map(int, sys.stdin.readline().split()))
ABC = [list(map(int, sys.stdin.readline().split())) for _ in range(M)]
graph = [[] for _ in range(N)]
for a, b, c in ABC:
graph[a - 1].append((b - 1, P - c))
def can_go_from_0():
# 1 からのパスがある
ret = [False] * N
stack = [0]
while stack:
v = stack.pop()
ret[v] = True
for u, _ in graph[v]:
if not ret[u]:
ret[u] = True
stack.append(u)
return ret
def can_go_to_n():
revs = [[] for _ in range(N)]
for a, b, c in ABC:
revs[b - 1].append(a - 1)
# n へのパスがある
ret = [False] * N
stack = [N - 1]
while stack:
v = stack.pop()
ret[v] = True
for u in revs[v]:
if not ret[u]:
ret[u] = True
stack.append(u)
return ret
vertices = []
for i, (v1, v2) in enumerate(zip(can_go_from_0(), can_go_to_n())):
if v1 & v2:
vertices.append(i)
# bellman-ford
dist = [INF] * N
dist[0] = 0
for i in range(N):
for v in vertices:
for u, d in graph[v]:
dist[u] = min(dist[v] + d, dist[u])
# 使う頂点がまだアップデートされたらダメ
prev = dist[:]
for v in vertices:
for u, d in graph[v]:
dist[u] = min(dist[v] + d, dist[u])
updated = False
for v in vertices:
updated |= prev[v] != dist[v]
if updated or dist[N - 1] == INF:
print((-1))
else:
print((max(-dist[N - 1], 0)))
| import os
import sys
if os.getenv("LOCAL"):
sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10**18
MOD = 10**9 + 7
N, M, P = list(map(int, sys.stdin.readline().split()))
ABC = [list(map(int, sys.stdin.readline().split())) for _ in range(M)]
graph = [[] for _ in range(N)]
for a, b, c in ABC:
graph[a - 1].append((b - 1, P - c))
def bellman_ford(graph, from_v, to_v):
"""
到達できないなら INF、負閉路があったら -INF
:param list of (list of (int, int)) graph: (to, cap) の隣接リスト
:param int from_v:
:param int to_v:
:rtype: int
"""
def reachable(graph, from_v):
"""
graph 上で from_v から到達できるかどうかのリスト
:param graph:
:param from_v:
"""
ret = [False] * len(graph)
ret[from_v] = True
stack = [from_v]
while stack:
v = stack.pop()
for u, _ in graph[v]:
if not ret[u]:
ret[u] = True
stack.append(u)
return ret
# from_v から到達でき、かつ to_v へ到達できる頂点のみ考える
# これら以外には負閉路があっても関係ない
vertices = []
revs = [[] for _ in range(len(graph))]
for v, ud in enumerate(graph):
for u, d in ud:
revs[u].append((v, d))
for v, (r1, r2) in enumerate(zip(reachable(graph, from_v), reachable(revs, to_v))):
if r1 & r2:
vertices.append(v)
dist = [float("inf")] * len(graph)
dist[from_v] = 0
updated = True
for _ in range(len(graph) + 1):
updated = False
for v in vertices:
for u, d in graph[v]:
if dist[v] + d < dist[u]:
dist[u] = dist[v] + d
updated = True
if not updated:
break
return -float("inf") if updated else dist[to_v]
ans = -bellman_ford(graph, 0, N - 1)
if ans == INF or ans == -INF:
print((-1))
else:
print((max(0, ans)))
| false | 2.564103 | [
"-def can_go_from_0():",
"- # 1 からのパスがある",
"- ret = [False] * N",
"- stack = [0]",
"- while stack:",
"- v = stack.pop()",
"- ret[v] = True",
"- for u, _ in graph[v]:",
"- if not ret[u]:",
"- ret[u] = True",
"- stack.append(u)",
"- return ret",
"+def bellman_ford(graph, from_v, to_v):",
"+ \"\"\"",
"+ 到達できないなら INF、負閉路があったら -INF",
"+ :param list of (list of (int, int)) graph: (to, cap) の隣接リスト",
"+ :param int from_v:",
"+ :param int to_v:",
"+ :rtype: int",
"+ \"\"\"",
"+",
"+ def reachable(graph, from_v):",
"+ \"\"\"",
"+ graph 上で from_v から到達できるかどうかのリスト",
"+ :param graph:",
"+ :param from_v:",
"+ \"\"\"",
"+ ret = [False] * len(graph)",
"+ ret[from_v] = True",
"+ stack = [from_v]",
"+ while stack:",
"+ v = stack.pop()",
"+ for u, _ in graph[v]:",
"+ if not ret[u]:",
"+ ret[u] = True",
"+ stack.append(u)",
"+ return ret",
"+",
"+ # from_v から到達でき、かつ to_v へ到達できる頂点のみ考える",
"+ # これら以外には負閉路があっても関係ない",
"+ vertices = []",
"+ revs = [[] for _ in range(len(graph))]",
"+ for v, ud in enumerate(graph):",
"+ for u, d in ud:",
"+ revs[u].append((v, d))",
"+ for v, (r1, r2) in enumerate(zip(reachable(graph, from_v), reachable(revs, to_v))):",
"+ if r1 & r2:",
"+ vertices.append(v)",
"+ dist = [float(\"inf\")] * len(graph)",
"+ dist[from_v] = 0",
"+ updated = True",
"+ for _ in range(len(graph) + 1):",
"+ updated = False",
"+ for v in vertices:",
"+ for u, d in graph[v]:",
"+ if dist[v] + d < dist[u]:",
"+ dist[u] = dist[v] + d",
"+ updated = True",
"+ if not updated:",
"+ break",
"+ return -float(\"inf\") if updated else dist[to_v]",
"-def can_go_to_n():",
"- revs = [[] for _ in range(N)]",
"- for a, b, c in ABC:",
"- revs[b - 1].append(a - 1)",
"- # n へのパスがある",
"- ret = [False] * N",
"- stack = [N - 1]",
"- while stack:",
"- v = stack.pop()",
"- ret[v] = True",
"- for u in revs[v]:",
"- if not ret[u]:",
"- ret[u] = True",
"- stack.append(u)",
"- return ret",
"-",
"-",
"-vertices = []",
"-for i, (v1, v2) in enumerate(zip(can_go_from_0(), can_go_to_n())):",
"- if v1 & v2:",
"- vertices.append(i)",
"-# bellman-ford",
"-dist = [INF] * N",
"-dist[0] = 0",
"-for i in range(N):",
"- for v in vertices:",
"- for u, d in graph[v]:",
"- dist[u] = min(dist[v] + d, dist[u])",
"-# 使う頂点がまだアップデートされたらダメ",
"-prev = dist[:]",
"-for v in vertices:",
"- for u, d in graph[v]:",
"- dist[u] = min(dist[v] + d, dist[u])",
"-updated = False",
"-for v in vertices:",
"- updated |= prev[v] != dist[v]",
"-if updated or dist[N - 1] == INF:",
"+ans = -bellman_ford(graph, 0, N - 1)",
"+if ans == INF or ans == -INF:",
"- print((max(-dist[N - 1], 0)))",
"+ print((max(0, ans)))"
] | false | 0.069622 | 0.042749 | 1.628628 | [
"s816426869",
"s431521500"
] |
u787456042 | p02888 | python | s162996499 | s788714324 | 1,261 | 959 | 3,188 | 3,188 | Accepted | Accepted | 23.95 | from bisect import*;N,*L=list(map(int,open(0).read().split()));L.sort();print((sum(bisect_left(L,L[i]+L[j],j+1)-j-1for i in range(N)for j in range(i+1,N)))) | from bisect import*;N,*L=list(map(int,open(0).read().split()));L.sort();print((sum(j-bisect(L,L[i]-L[j],0,j)for i in range(N)for j in range(i)))) | 1 | 1 | 148 | 137 | from bisect import *
N, *L = list(map(int, open(0).read().split()))
L.sort()
print(
(
sum(
bisect_left(L, L[i] + L[j], j + 1) - j - 1
for i in range(N)
for j in range(i + 1, N)
)
)
)
| from bisect import *
N, *L = list(map(int, open(0).read().split()))
L.sort()
print((sum(j - bisect(L, L[i] - L[j], 0, j) for i in range(N) for j in range(i))))
| false | 0 | [
"-print(",
"- (",
"- sum(",
"- bisect_left(L, L[i] + L[j], j + 1) - j - 1",
"- for i in range(N)",
"- for j in range(i + 1, N)",
"- )",
"- )",
"-)",
"+print((sum(j - bisect(L, L[i] - L[j], 0, j) for i in range(N) for j in range(i))))"
] | false | 0.07013 | 0.071786 | 0.976929 | [
"s162996499",
"s788714324"
] |
u731235119 | p01140 | python | s276936887 | s852677823 | 10,420 | 7,890 | 99,216 | 98,528 | Accepted | Accepted | 24.28 | while 1 :
n, m = list(map(int,input().split(" ")))
if (n, m) == (0,0):
break
Lon = [0 for i in range(1000 * n + 1)]
Lat = [0 for i in range(1000 * m + 1)]
Lon_sum = [0]
Lat_sum = [0]
for i in range(0,n):
tmp_Lon_sum = [0]
h = int(input())
for j in Lon_sum:
Lon[j+h] += 1
tmp_Lon_sum += [j+h]
Lon_sum = tmp_Lon_sum
else :
Lon_max = Lon_sum[-1]
for i in range(0,m):
tmp_Lat_sum = [0]
w = int(input())
for j in Lat_sum:
Lat[j+w] += 1
tmp_Lat_sum += [j+w]
Lat_sum = tmp_Lat_sum
else :
Lat_max = Lat_sum[-1]
max_width = min(Lon_max,Lat_max)
print(sum([Lon[i]*Lat[i] for i in range(1,max_width+1)])) | while 1 :
n, m = list(map(int,input().split(" ")))
if (n, m) == (0,0):
break
Lon = [0 for i in range(1000 * n + 1)]
Lat = [0 for i in range(1000 * m + 1)]
Lon_sum = [0]
Lat_sum = [0]
for i in range(0,n):
h = int(input())
Lon_sum = [0] + [h + j for j in Lon_sum]
for j in Lon_sum:
Lon[j] += 1
for i in range(0,m):
w = int(input())
Lat_sum = [0] + [w + j for j in Lat_sum]
for j in Lat_sum:
Lat[j] += 1
Lat_max = Lat_sum[-1]
max_width = min(Lon_sum[-1],Lat_sum[-1])
print(sum([Lon[i]*Lat[i] for i in range(1,max_width+1)])) | 28 | 21 | 673 | 578 | while 1:
n, m = list(map(int, input().split(" ")))
if (n, m) == (0, 0):
break
Lon = [0 for i in range(1000 * n + 1)]
Lat = [0 for i in range(1000 * m + 1)]
Lon_sum = [0]
Lat_sum = [0]
for i in range(0, n):
tmp_Lon_sum = [0]
h = int(input())
for j in Lon_sum:
Lon[j + h] += 1
tmp_Lon_sum += [j + h]
Lon_sum = tmp_Lon_sum
else:
Lon_max = Lon_sum[-1]
for i in range(0, m):
tmp_Lat_sum = [0]
w = int(input())
for j in Lat_sum:
Lat[j + w] += 1
tmp_Lat_sum += [j + w]
Lat_sum = tmp_Lat_sum
else:
Lat_max = Lat_sum[-1]
max_width = min(Lon_max, Lat_max)
print(sum([Lon[i] * Lat[i] for i in range(1, max_width + 1)]))
| while 1:
n, m = list(map(int, input().split(" ")))
if (n, m) == (0, 0):
break
Lon = [0 for i in range(1000 * n + 1)]
Lat = [0 for i in range(1000 * m + 1)]
Lon_sum = [0]
Lat_sum = [0]
for i in range(0, n):
h = int(input())
Lon_sum = [0] + [h + j for j in Lon_sum]
for j in Lon_sum:
Lon[j] += 1
for i in range(0, m):
w = int(input())
Lat_sum = [0] + [w + j for j in Lat_sum]
for j in Lat_sum:
Lat[j] += 1
Lat_max = Lat_sum[-1]
max_width = min(Lon_sum[-1], Lat_sum[-1])
print(sum([Lon[i] * Lat[i] for i in range(1, max_width + 1)]))
| false | 25 | [
"- tmp_Lon_sum = [0]",
"+ Lon_sum = [0] + [h + j for j in Lon_sum]",
"- Lon[j + h] += 1",
"- tmp_Lon_sum += [j + h]",
"- Lon_sum = tmp_Lon_sum",
"- else:",
"- Lon_max = Lon_sum[-1]",
"+ Lon[j] += 1",
"- tmp_Lat_sum = [0]",
"+ Lat_sum = [0] + [w + j for j in Lat_sum]",
"- Lat[j + w] += 1",
"- tmp_Lat_sum += [j + w]",
"- Lat_sum = tmp_Lat_sum",
"- else:",
"+ Lat[j] += 1",
"- max_width = min(Lon_max, Lat_max)",
"+ max_width = min(Lon_sum[-1], Lat_sum[-1])"
] | false | 0.037438 | 0.036574 | 1.023629 | [
"s276936887",
"s852677823"
] |
u562935282 | p03958 | python | s720481037 | s606455020 | 24 | 17 | 3,060 | 2,940 | Accepted | Accepted | 29.17 | from heapq import heapify, heappush, heappop
k, t = list(map(int, input().split()))
*a, = (-int(x) for x in input().split())
heapify(a)
eaten = 0
while a:
to_eat = heappop(a)
to_eat += 1
if eaten:
heappush(a, eaten)
eaten = 0
if to_eat == 0:
continue
elif to_eat < 0:
eaten = to_eat
print((-eaten))
| # 解説を見た
k, t = list(map(int, input().split()))
*a, = (int(x) for x in input().split())
ma = max(a)
rest = k - ma
print((max(0, ma - rest - 1)))
# 最大の個数のケーキを並べる
# 間にほかのケーキを挟んでいく
# aaaaaa bbbb ccc d
# a[bc]a[bc]a[bc]a[b]a[d]a
# 間に1個ずつ入れたときの、aが連続する回数-1が答え
# 間に複数入ることはあるが、同じケーキが入ることはない(最大のケーキの間の数は、ほかのどのケーキの個数よりも多いから)
| 20 | 15 | 366 | 323 | from heapq import heapify, heappush, heappop
k, t = list(map(int, input().split()))
(*a,) = (-int(x) for x in input().split())
heapify(a)
eaten = 0
while a:
to_eat = heappop(a)
to_eat += 1
if eaten:
heappush(a, eaten)
eaten = 0
if to_eat == 0:
continue
elif to_eat < 0:
eaten = to_eat
print((-eaten))
| # 解説を見た
k, t = list(map(int, input().split()))
(*a,) = (int(x) for x in input().split())
ma = max(a)
rest = k - ma
print((max(0, ma - rest - 1)))
# 最大の個数のケーキを並べる
# 間にほかのケーキを挟んでいく
# aaaaaa bbbb ccc d
# a[bc]a[bc]a[bc]a[b]a[d]a
# 間に1個ずつ入れたときの、aが連続する回数-1が答え
# 間に複数入ることはあるが、同じケーキが入ることはない(最大のケーキの間の数は、ほかのどのケーキの個数よりも多いから)
| false | 25 | [
"-from heapq import heapify, heappush, heappop",
"-",
"+# 解説を見た",
"-(*a,) = (-int(x) for x in input().split())",
"-heapify(a)",
"-eaten = 0",
"-while a:",
"- to_eat = heappop(a)",
"- to_eat += 1",
"- if eaten:",
"- heappush(a, eaten)",
"- eaten = 0",
"- if to_eat == 0:",
"- continue",
"- elif to_eat < 0:",
"- eaten = to_eat",
"-print((-eaten))",
"+(*a,) = (int(x) for x in input().split())",
"+ma = max(a)",
"+rest = k - ma",
"+print((max(0, ma - rest - 1)))",
"+# 最大の個数のケーキを並べる",
"+# 間にほかのケーキを挟んでいく",
"+# aaaaaa bbbb ccc d",
"+# a[bc]a[bc]a[bc]a[b]a[d]a",
"+# 間に1個ずつ入れたときの、aが連続する回数-1が答え",
"+# 間に複数入ることはあるが、同じケーキが入ることはない(最大のケーキの間の数は、ほかのどのケーキの個数よりも多いから)"
] | false | 0.037154 | 0.05998 | 0.619444 | [
"s720481037",
"s606455020"
] |
u912237403 | p00008 | python | s562213812 | s226509603 | 60 | 30 | 4,208 | 4,212 | Accepted | Accepted | 50 | import sys
def f(a,b):
A=list(range(10))
if b==1:x=1 if a in A else 0
else:x=sum([f(a-e,b-1)for e in A])
return x
for n in map(int,sys.stdin):
print(f(n,4)) | import sys
def f(a,b):
A=list(range(10))
if b==1:x=1 if a in A else 0
elif a<0 or a>b*9:x=0
else:x=sum([f(a-e,b-1)for e in A])
return x
for n in map(int,sys.stdin):
print(f(n,4)) | 8 | 9 | 166 | 191 | import sys
def f(a, b):
A = list(range(10))
if b == 1:
x = 1 if a in A else 0
else:
x = sum([f(a - e, b - 1) for e in A])
return x
for n in map(int, sys.stdin):
print(f(n, 4))
| import sys
def f(a, b):
A = list(range(10))
if b == 1:
x = 1 if a in A else 0
elif a < 0 or a > b * 9:
x = 0
else:
x = sum([f(a - e, b - 1) for e in A])
return x
for n in map(int, sys.stdin):
print(f(n, 4))
| false | 11.111111 | [
"+ elif a < 0 or a > b * 9:",
"+ x = 0"
] | false | 0.04013 | 0.115902 | 0.346243 | [
"s562213812",
"s226509603"
] |
u620084012 | p03665 | python | s063757760 | s623378073 | 176 | 18 | 38,256 | 3,064 | Accepted | Accepted | 89.77 | N, P = list(map(int,input().split()))
A = list(map(int,input().split()))
B = [A[k]%2 for k in range(N)]
dp = [[0,0] for k in range(N+1)]
dp[0][0] = 1
for k in range(N):
if B[k] == 0:
dp[k+1][0] = dp[k][0]*2
dp[k+1][1] = dp[k][1]*2
else:
dp[k+1][0] = dp[k][0] + dp[k][1]
dp[k+1][1] = dp[k][0] + dp[k][1]
print((dp[N][P]))
| import math
N, P = list(map(int,input().split()))
A = list(map(int,input().split()))
B = [e%2 for e in A]
ans = pow(2,B.count(0))
def nCr(n,r):
return (math.factorial(n)//(math.factorial(r)*math.factorial(n-r)))
t = 0
for k in range(B.count(1)+1):
if k%2 == 0:
t += nCr(B.count(1),k)
print((ans*t if P == 0 else pow(2,N)-ans*t))
| 15 | 12 | 369 | 348 | N, P = list(map(int, input().split()))
A = list(map(int, input().split()))
B = [A[k] % 2 for k in range(N)]
dp = [[0, 0] for k in range(N + 1)]
dp[0][0] = 1
for k in range(N):
if B[k] == 0:
dp[k + 1][0] = dp[k][0] * 2
dp[k + 1][1] = dp[k][1] * 2
else:
dp[k + 1][0] = dp[k][0] + dp[k][1]
dp[k + 1][1] = dp[k][0] + dp[k][1]
print((dp[N][P]))
| import math
N, P = list(map(int, input().split()))
A = list(map(int, input().split()))
B = [e % 2 for e in A]
ans = pow(2, B.count(0))
def nCr(n, r):
return math.factorial(n) // (math.factorial(r) * math.factorial(n - r))
t = 0
for k in range(B.count(1) + 1):
if k % 2 == 0:
t += nCr(B.count(1), k)
print((ans * t if P == 0 else pow(2, N) - ans * t))
| false | 20 | [
"+import math",
"+",
"-B = [A[k] % 2 for k in range(N)]",
"-dp = [[0, 0] for k in range(N + 1)]",
"-dp[0][0] = 1",
"-for k in range(N):",
"- if B[k] == 0:",
"- dp[k + 1][0] = dp[k][0] * 2",
"- dp[k + 1][1] = dp[k][1] * 2",
"- else:",
"- dp[k + 1][0] = dp[k][0] + dp[k][1]",
"- dp[k + 1][1] = dp[k][0] + dp[k][1]",
"-print((dp[N][P]))",
"+B = [e % 2 for e in A]",
"+ans = pow(2, B.count(0))",
"+",
"+",
"+def nCr(n, r):",
"+ return math.factorial(n) // (math.factorial(r) * math.factorial(n - r))",
"+",
"+",
"+t = 0",
"+for k in range(B.count(1) + 1):",
"+ if k % 2 == 0:",
"+ t += nCr(B.count(1), k)",
"+print((ans * t if P == 0 else pow(2, N) - ans * t))"
] | false | 0.127021 | 0.039523 | 3.213811 | [
"s063757760",
"s623378073"
] |
u762420987 | p03470 | python | s528917651 | s966764461 | 21 | 17 | 3,316 | 2,940 | Accepted | Accepted | 19.05 | from collections import Counter
N = int(eval(input()))
dlist = Counter([int(eval(input())) for _ in range(N)])
print((len(list(dlist.items()))))
| print((len(set([int(eval(input())) for _ in range(int(eval(input())))]))))
| 4 | 1 | 128 | 61 | from collections import Counter
N = int(eval(input()))
dlist = Counter([int(eval(input())) for _ in range(N)])
print((len(list(dlist.items()))))
| print((len(set([int(eval(input())) for _ in range(int(eval(input())))]))))
| false | 75 | [
"-from collections import Counter",
"-",
"-N = int(eval(input()))",
"-dlist = Counter([int(eval(input())) for _ in range(N)])",
"-print((len(list(dlist.items()))))",
"+print((len(set([int(eval(input())) for _ in range(int(eval(input())))]))))"
] | false | 0.042469 | 0.040223 | 1.055853 | [
"s528917651",
"s966764461"
] |
u021019433 | p03053 | python | s214364473 | s393878086 | 579 | 524 | 132,432 | 132,432 | Accepted | Accepted | 9.5 | h, w = list(map(int, input().split()))
a = [list(eval(input())) for _ in range(h)]
d = (-1, 0), (1, 0), (0, -1), (0, 1)
p = [(i, j) for i in range(h) for j in range(w) if a[i][j] == '#']
n = h * w - len(p)
r = 0
while n:
r += 1
s = []
for i, j in p:
for di, dj in d:
di += i
dj += j
if 0 <= di < h and 0 <= dj < w and a[di][dj] == '.':
a[di][dj] = '#'
s.append((di, dj))
p = s
n -= len(p)
print(r)
| h, w = list(map(int, input().split()))
a = [list(eval(input())) for _ in range(h)]
d = (-1, 0), (1, 0), (0, -1), (0, 1)
p = [(i, j) for i in range(h) for j in range(w) if a[i][j] == '#']
def f():
s = []
for i, j in p:
for di, dj in d:
di += i
dj += j
if 0 <= di < h and 0 <= dj < w and a[di][dj] == '.':
a[di][dj] = '#'
s.append((di, dj))
return s
n = h * w - len(p)
r = 0
while n:
r += 1
p = f()
n -= len(p)
print(r)
| 19 | 23 | 500 | 530 | h, w = list(map(int, input().split()))
a = [list(eval(input())) for _ in range(h)]
d = (-1, 0), (1, 0), (0, -1), (0, 1)
p = [(i, j) for i in range(h) for j in range(w) if a[i][j] == "#"]
n = h * w - len(p)
r = 0
while n:
r += 1
s = []
for i, j in p:
for di, dj in d:
di += i
dj += j
if 0 <= di < h and 0 <= dj < w and a[di][dj] == ".":
a[di][dj] = "#"
s.append((di, dj))
p = s
n -= len(p)
print(r)
| h, w = list(map(int, input().split()))
a = [list(eval(input())) for _ in range(h)]
d = (-1, 0), (1, 0), (0, -1), (0, 1)
p = [(i, j) for i in range(h) for j in range(w) if a[i][j] == "#"]
def f():
s = []
for i, j in p:
for di, dj in d:
di += i
dj += j
if 0 <= di < h and 0 <= dj < w and a[di][dj] == ".":
a[di][dj] = "#"
s.append((di, dj))
return s
n = h * w - len(p)
r = 0
while n:
r += 1
p = f()
n -= len(p)
print(r)
| false | 17.391304 | [
"-n = h * w - len(p)",
"-r = 0",
"-while n:",
"- r += 1",
"+",
"+",
"+def f():",
"- p = s",
"+ return s",
"+",
"+",
"+n = h * w - len(p)",
"+r = 0",
"+while n:",
"+ r += 1",
"+ p = f()"
] | false | 0.038087 | 0.037131 | 1.025737 | [
"s214364473",
"s393878086"
] |
u156815136 | p03379 | python | s096139841 | s170650192 | 294 | 185 | 26,540 | 33,348 | Accepted | Accepted | 37.07 | #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
#mod = 9982443453
def readInts():
return list(map(int,input().split()))
def I():
return int(eval(input()))
n = I()
X = readInts()
nya = sorted(X)
m1 = nya[n//2-1];m2 = nya[n//2]
# このどちらか
# 適当に取り出して、そいつが中央値1以下ならm2,
for x in X:
if x <= m1:
print(m2)
else:
print(m1)
| #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, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
from sys import stdin
readline = stdin.readline
def readInts():
return list(map(int,readline().split()))
def readTuples():
return tuple(map(int,readline().split()))
def I():
return int(readline())
n = I()
X = readInts()
nya = sorted(X)
m1 = nya[n//2-1]
m2 = nya[n//2]
for x in X:
if x <= m1:
print(m2)
else:
print(m1)
| 37 | 48 | 795 | 1,082 | # 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
# mod = 9982443453
def readInts():
return list(map(int, input().split()))
def I():
return int(eval(input()))
n = I()
X = readInts()
nya = sorted(X)
m1 = nya[n // 2 - 1]
m2 = nya[n // 2]
# このどちらか
# 適当に取り出して、そいつが中央値1以下ならm2,
for x in X:
if x <= m1:
print(m2)
else:
print(m1)
| # 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, product # (string,3) 3回
# from collections import deque
from collections import deque, defaultdict, Counter
import decimal
import re
import math
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
# mod = 9982443453
# mod = 998244353
from sys import stdin
readline = stdin.readline
def readInts():
return list(map(int, readline().split()))
def readTuples():
return tuple(map(int, readline().split()))
def I():
return int(readline())
n = I()
X = readInts()
nya = sorted(X)
m1 = nya[n // 2 - 1]
m2 = nya[n // 2]
for x in X:
if x <= m1:
print(m2)
else:
print(m1)
| false | 22.916667 | [
"-# from fractions import gcd",
"-# from itertools import combinations # (string,3) 3回",
"+from fractions import gcd",
"+from itertools import combinations, permutations, accumulate, product # (string,3) 3回",
"+",
"-from collections import defaultdict",
"+from collections import deque, defaultdict, Counter",
"+import decimal",
"+import re",
"+import math",
"-# import bisect",
"-#",
"-# d = m - k[i] - k[j]",
"-# if kk[bisect.bisect_right(kk,d) - 1] == d:",
"+#",
"+#",
"+# my_round_int = lambda x:np.round((x*2 + 1)//2)",
"+# 四捨五入g",
"+#",
"+# インデックス系",
"+# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);",
"+# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);",
"+# mod = 998244353",
"+from sys import stdin",
"+",
"+readline = stdin.readline",
"+",
"+",
"- return list(map(int, input().split()))",
"+ return list(map(int, readline().split()))",
"+",
"+",
"+def readTuples():",
"+ return tuple(map(int, readline().split()))",
"- return int(eval(input()))",
"+ return int(readline())",
"-# このどちらか",
"-# 適当に取り出して、そいつが中央値1以下ならm2,"
] | false | 0.061179 | 0.205934 | 0.297083 | [
"s096139841",
"s170650192"
] |
u994988729 | p03862 | python | s285476582 | s556429037 | 201 | 132 | 14,672 | 14,540 | Accepted | Accepted | 34.33 | N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
ans = 0
for i in range(1, N):
candy = A[i] + A[i - 1]
# Kより少ないならそのまま
if candy < K:
continue
# 右にあるやつをたべる
r = min(A[i], candy - K)
candy -= r
A[i] -= r
ans += r
if candy < K:
continue
# 左にあるやつを食べる
l = min(A[i - 1], candy - K)
candy -= l
A[i - 1] -= l
ans += l
if candy < K:
continue
print(ans)
| N, x = list(map(int, input().split()))
A = list(map(int, input().split()))
ans = 0
for i in range(N - 1):
L = A[i]
R = A[i + 1]
eat = max(0, L + R - x)
ans += eat
A[i + 1] = max(0, R - eat)
print(ans) | 28 | 12 | 478 | 227 | N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
ans = 0
for i in range(1, N):
candy = A[i] + A[i - 1]
# Kより少ないならそのまま
if candy < K:
continue
# 右にあるやつをたべる
r = min(A[i], candy - K)
candy -= r
A[i] -= r
ans += r
if candy < K:
continue
# 左にあるやつを食べる
l = min(A[i - 1], candy - K)
candy -= l
A[i - 1] -= l
ans += l
if candy < K:
continue
print(ans)
| N, x = list(map(int, input().split()))
A = list(map(int, input().split()))
ans = 0
for i in range(N - 1):
L = A[i]
R = A[i + 1]
eat = max(0, L + R - x)
ans += eat
A[i + 1] = max(0, R - eat)
print(ans)
| false | 57.142857 | [
"-N, K = list(map(int, input().split()))",
"+N, x = list(map(int, input().split()))",
"-for i in range(1, N):",
"- candy = A[i] + A[i - 1]",
"- # Kより少ないならそのまま",
"- if candy < K:",
"- continue",
"- # 右にあるやつをたべる",
"- r = min(A[i], candy - K)",
"- candy -= r",
"- A[i] -= r",
"- ans += r",
"- if candy < K:",
"- continue",
"- # 左にあるやつを食べる",
"- l = min(A[i - 1], candy - K)",
"- candy -= l",
"- A[i - 1] -= l",
"- ans += l",
"- if candy < K:",
"- continue",
"+for i in range(N - 1):",
"+ L = A[i]",
"+ R = A[i + 1]",
"+ eat = max(0, L + R - x)",
"+ ans += eat",
"+ A[i + 1] = max(0, R - eat)"
] | false | 0.079618 | 0.099995 | 0.796219 | [
"s285476582",
"s556429037"
] |
u952708174 | p03363 | python | s889394912 | s200942537 | 219 | 156 | 41,504 | 40,468 | Accepted | Accepted | 28.77 | import collections
N = int(eval(input()))
A = [int(i) for i in input().split()]
S = [0] * (N+1)
for k in range(1,N+1):
S[k] = S[k-1] + A[k-1]
count = collections.Counter(S)
ans = 0
for k,v in list(count.items()):
ans += v * (v-1) // 2
print(ans) | def a_zero_sum_ranges(N, A):
import collections
import itertools
# s[l]==s[r] のとき、A[l+1]+...+A[r] == 0 となる
s = itertools.accumulate([0] + A)
count = collections.Counter(s)
ans = 0
for k, v in list(count.items()):
ans += v * (v - 1) // 2
return ans
N = int(eval(input()))
A = [int(i) for i in input().split()]
print((a_zero_sum_ranges(N, A))) | 13 | 14 | 251 | 381 | import collections
N = int(eval(input()))
A = [int(i) for i in input().split()]
S = [0] * (N + 1)
for k in range(1, N + 1):
S[k] = S[k - 1] + A[k - 1]
count = collections.Counter(S)
ans = 0
for k, v in list(count.items()):
ans += v * (v - 1) // 2
print(ans)
| def a_zero_sum_ranges(N, A):
import collections
import itertools
# s[l]==s[r] のとき、A[l+1]+...+A[r] == 0 となる
s = itertools.accumulate([0] + A)
count = collections.Counter(s)
ans = 0
for k, v in list(count.items()):
ans += v * (v - 1) // 2
return ans
N = int(eval(input()))
A = [int(i) for i in input().split()]
print((a_zero_sum_ranges(N, A)))
| false | 7.142857 | [
"-import collections",
"+def a_zero_sum_ranges(N, A):",
"+ import collections",
"+ import itertools",
"+",
"+ # s[l]==s[r] のとき、A[l+1]+...+A[r] == 0 となる",
"+ s = itertools.accumulate([0] + A)",
"+ count = collections.Counter(s)",
"+ ans = 0",
"+ for k, v in list(count.items()):",
"+ ans += v * (v - 1) // 2",
"+ return ans",
"+",
"-S = [0] * (N + 1)",
"-for k in range(1, N + 1):",
"- S[k] = S[k - 1] + A[k - 1]",
"-count = collections.Counter(S)",
"-ans = 0",
"-for k, v in list(count.items()):",
"- ans += v * (v - 1) // 2",
"-print(ans)",
"+print((a_zero_sum_ranges(N, A)))"
] | false | 0.047894 | 0.048664 | 0.984173 | [
"s889394912",
"s200942537"
] |
u633068244 | p01322 | python | s096392039 | s814494115 | 960 | 790 | 4,304 | 4,308 | Accepted | Accepted | 17.71 | import re
while 1:
n,m = list(map(int,input().split()))
if n ==0: break
prize = []
for i in range(n):
num,money = input().replace("*","[0-9]").split()
prize.append([re.compile(num),int(money)])
ans = 0
for i in range(m):
lot = input()
for num,money in prize:
if num.search(lot):
ans += money
print(ans) | import re
while 1:
n,m = list(map(int,input().split()))
if n ==0: break
prize = []
for i in range(n):
num,money = input().replace("*","[0-9]").split()
prize.append([re.compile(num),int(money)])
ans = 0
for i in range(m):
lot = input()
for num,money in prize:
if num.search(lot):
ans += money
break
print(ans) | 15 | 16 | 343 | 354 | import re
while 1:
n, m = list(map(int, input().split()))
if n == 0:
break
prize = []
for i in range(n):
num, money = input().replace("*", "[0-9]").split()
prize.append([re.compile(num), int(money)])
ans = 0
for i in range(m):
lot = input()
for num, money in prize:
if num.search(lot):
ans += money
print(ans)
| import re
while 1:
n, m = list(map(int, input().split()))
if n == 0:
break
prize = []
for i in range(n):
num, money = input().replace("*", "[0-9]").split()
prize.append([re.compile(num), int(money)])
ans = 0
for i in range(m):
lot = input()
for num, money in prize:
if num.search(lot):
ans += money
break
print(ans)
| false | 6.25 | [
"+ break"
] | false | 0.054155 | 0.05669 | 0.955285 | [
"s096392039",
"s814494115"
] |
u083960235 | p02732 | python | s641231496 | s665686164 | 534 | 339 | 27,152 | 35,024 | Accepted | Accepted | 36.52 | import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from heapq import heapify, heappop, heappush
def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def S_MAP(): return list(map(str, input().split()))
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
N = INT()
A = LIST()
C = Counter(A)
# print(C)
# combinations()
al = 0
for ball, num in list(C.items()):
al += num * (num - 1) // 2
# print(al)
for a in A:
ball = a
num = C[a]
ans = al - C[a] * (C[a] - 1) // 2 + (C[a] - 1) * (C[a] - 2) // 2
print(ans)
# for a in A:
# c[a] | import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect, bisect_left, bisect_right
def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def S_MAP(): return list(map(str, input().split()))
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
N = INT()
A = LIST()
C = Counter(A)
S = set(A)
# l = list(combinations())
# for s in S:
# C[s]
total = 0
for s in S:
total += C[s] * (C[s] - 1) // 2
# print(total)
for i, a in enumerate(A):
# before = C[a]
exc = total - C[a] * (C[a] - 1) // 2
a_num = C[a] - 1
now = exc + a_num * (a_num - 1) // 2
print(now)
| 37 | 43 | 1,052 | 1,141 | import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from heapq import heapify, heappop, heappush
def input():
return sys.stdin.readline().strip()
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def S_MAP():
return list(map(str, input().split()))
def LIST():
return list(map(int, input().split()))
def S_LIST():
return list(map(str, input().split()))
sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
N = INT()
A = LIST()
C = Counter(A)
# print(C)
# combinations()
al = 0
for ball, num in list(C.items()):
al += num * (num - 1) // 2
# print(al)
for a in A:
ball = a
num = C[a]
ans = al - C[a] * (C[a] - 1) // 2 + (C[a] - 1) * (C[a] - 2) // 2
print(ans)
# for a in A:
# c[a]
| import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect, bisect_left, bisect_right
def input():
return sys.stdin.readline().strip()
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def S_MAP():
return list(map(str, input().split()))
def LIST():
return list(map(int, input().split()))
def S_LIST():
return list(map(str, input().split()))
sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
N = INT()
A = LIST()
C = Counter(A)
S = set(A)
# l = list(combinations())
# for s in S:
# C[s]
total = 0
for s in S:
total += C[s] * (C[s] - 1) // 2
# print(total)
for i, a in enumerate(A):
# before = C[a]
exc = total - C[a] * (C[a] - 1) // 2
a_num = C[a] - 1
now = exc + a_num * (a_num - 1) // 2
print(now)
| false | 13.953488 | [
"-from heapq import heapify, heappop, heappush",
"+from fractions import gcd",
"+from bisect import bisect, bisect_left, bisect_right",
"-# print(C)",
"-# combinations()",
"-al = 0",
"-for ball, num in list(C.items()):",
"- al += num * (num - 1) // 2",
"-# print(al)",
"-for a in A:",
"- ball = a",
"- num = C[a]",
"- ans = al - C[a] * (C[a] - 1) // 2 + (C[a] - 1) * (C[a] - 2) // 2",
"- print(ans)",
"-# for a in A:",
"-# c[a]",
"+S = set(A)",
"+# l = list(combinations())",
"+# for s in S:",
"+# C[s]",
"+total = 0",
"+for s in S:",
"+ total += C[s] * (C[s] - 1) // 2",
"+# print(total)",
"+for i, a in enumerate(A):",
"+ # before = C[a]",
"+ exc = total - C[a] * (C[a] - 1) // 2",
"+ a_num = C[a] - 1",
"+ now = exc + a_num * (a_num - 1) // 2",
"+ print(now)"
] | false | 0.064099 | 0.034667 | 1.849023 | [
"s641231496",
"s665686164"
] |
u729133443 | p02665 | python | s681441161 | s530658381 | 529 | 433 | 87,440 | 20,292 | Accepted | Accepted | 18.15 | *a,=list(map(int,[*open(0)][1].split()))
c=sum(a)
s=b=1
for a in a:c-=a;b=min(c,b-a<<1);s+=b
print((max(-1,s))) | c=sum(a:=[*list(map(int,[*open(0)][1].split()))])
b=1
print((max(-1,sum((b:=min(c:=c-a,b-a<<1))for a in a)+1))) | 5 | 3 | 107 | 105 | (*a,) = list(map(int, [*open(0)][1].split()))
c = sum(a)
s = b = 1
for a in a:
c -= a
b = min(c, b - a << 1)
s += b
print((max(-1, s)))
| c = sum(a := [*list(map(int, [*open(0)][1].split()))])
b = 1
print((max(-1, sum((b := min(c := c - a, b - a << 1)) for a in a) + 1)))
| false | 40 | [
"-(*a,) = list(map(int, [*open(0)][1].split()))",
"-c = sum(a)",
"-s = b = 1",
"-for a in a:",
"- c -= a",
"- b = min(c, b - a << 1)",
"- s += b",
"-print((max(-1, s)))",
"+c = sum(a := [*list(map(int, [*open(0)][1].split()))])",
"+b = 1",
"+print((max(-1, sum((b := min(c := c - a, b - a << 1)) for a in a) + 1)))"
] | false | 0.040688 | 0.048982 | 0.830683 | [
"s681441161",
"s530658381"
] |
u119148115 | p02596 | python | s163963347 | s325432769 | 117 | 69 | 141,320 | 63,376 | Accepted | Accepted | 41.03 | import sys
def I(): return int(sys.stdin.readline().rstrip())
K = I()
if K % 2 == 0 or K % 5 == 0:
print((-1))
exit()
if K % 7 == 0:
K //= 7
A = [1] # A[i] = 10**i mod K
for i in range(K):
A.append((A[-1]*10) % K)
s = 1
for i in range(1,K+1):
if s % K == 0:
print(i)
exit()
else:
s += A[i]
s %= K
| import sys
def I(): return int(sys.stdin.readline().rstrip())
K = I()
if K % 2 == 0 or K % 5 == 0:
print((-1))
exit()
if K % 7 == 0:
K //= 7
s = 1
for i in range(1,K+1):
if s % K == 0:
print(i)
exit()
else:
s *= 10
s += 1
s %= K
| 22 | 19 | 376 | 307 | import sys
def I():
return int(sys.stdin.readline().rstrip())
K = I()
if K % 2 == 0 or K % 5 == 0:
print((-1))
exit()
if K % 7 == 0:
K //= 7
A = [1] # A[i] = 10**i mod K
for i in range(K):
A.append((A[-1] * 10) % K)
s = 1
for i in range(1, K + 1):
if s % K == 0:
print(i)
exit()
else:
s += A[i]
s %= K
| import sys
def I():
return int(sys.stdin.readline().rstrip())
K = I()
if K % 2 == 0 or K % 5 == 0:
print((-1))
exit()
if K % 7 == 0:
K //= 7
s = 1
for i in range(1, K + 1):
if s % K == 0:
print(i)
exit()
else:
s *= 10
s += 1
s %= K
| false | 13.636364 | [
"-A = [1] # A[i] = 10**i mod K",
"-for i in range(K):",
"- A.append((A[-1] * 10) % K)",
"- s += A[i]",
"+ s *= 10",
"+ s += 1"
] | false | 0.178417 | 0.149699 | 1.191842 | [
"s163963347",
"s325432769"
] |
u537782349 | p03632 | python | s591133579 | s250541670 | 19 | 17 | 2,940 | 2,940 | Accepted | Accepted | 10.53 | a, b, c, d = list(map(int, input().split()))
if max(a, c) > min(b, d):
print((0))
else:
print((-max(a, c)+min(b, d)))
| a, b, c, d = list(map(int, input().split()))
e = max(a, c)
f = min(b, d)
if e >= f:
print((0))
else:
print((abs(e-f)))
| 5 | 7 | 120 | 123 | a, b, c, d = list(map(int, input().split()))
if max(a, c) > min(b, d):
print((0))
else:
print((-max(a, c) + min(b, d)))
| a, b, c, d = list(map(int, input().split()))
e = max(a, c)
f = min(b, d)
if e >= f:
print((0))
else:
print((abs(e - f)))
| false | 28.571429 | [
"-if max(a, c) > min(b, d):",
"+e = max(a, c)",
"+f = min(b, d)",
"+if e >= f:",
"- print((-max(a, c) + min(b, d)))",
"+ print((abs(e - f)))"
] | false | 0.040841 | 0.044015 | 0.927891 | [
"s591133579",
"s250541670"
] |
u891635666 | p02888 | python | s899216032 | s106171919 | 1,805 | 1,326 | 62,652 | 3,188 | Accepted | Accepted | 26.54 | import bisect
import sys
input = sys.stdin.readline
def read_i():
return list(map(int, input().split()))
n = int(eval(input()))
ls = sorted(read_i())
ls2 = ls[::-1]
res = 0
for i, x in enumerate(ls2):
for j, y in enumerate(ls2[i + 1:], i + 1):
res += n - j - 1 - bisect.bisect(ls[:-(j + 1)], x - y)
print(res) | import bisect
import sys
input = sys.stdin.readline
def read_i():
return list(map(int, input().split()))
n = int(eval(input()))
ls = sorted(read_i())
res = 0
for i in range(n - 2):
x = ls[i]
for j in range(i + 1, n - 1):
y = ls[j]
res += bisect.bisect_left(ls, x + y) - j - 1
print(res) | 18 | 19 | 341 | 331 | import bisect
import sys
input = sys.stdin.readline
def read_i():
return list(map(int, input().split()))
n = int(eval(input()))
ls = sorted(read_i())
ls2 = ls[::-1]
res = 0
for i, x in enumerate(ls2):
for j, y in enumerate(ls2[i + 1 :], i + 1):
res += n - j - 1 - bisect.bisect(ls[: -(j + 1)], x - y)
print(res)
| import bisect
import sys
input = sys.stdin.readline
def read_i():
return list(map(int, input().split()))
n = int(eval(input()))
ls = sorted(read_i())
res = 0
for i in range(n - 2):
x = ls[i]
for j in range(i + 1, n - 1):
y = ls[j]
res += bisect.bisect_left(ls, x + y) - j - 1
print(res)
| false | 5.263158 | [
"-ls2 = ls[::-1]",
"-for i, x in enumerate(ls2):",
"- for j, y in enumerate(ls2[i + 1 :], i + 1):",
"- res += n - j - 1 - bisect.bisect(ls[: -(j + 1)], x - y)",
"+for i in range(n - 2):",
"+ x = ls[i]",
"+ for j in range(i + 1, n - 1):",
"+ y = ls[j]",
"+ res += bisect.bisect_left(ls, x + y) - j - 1"
] | false | 0.064411 | 0.056923 | 1.131538 | [
"s899216032",
"s106171919"
] |
u730769327 | p03470 | python | s621455489 | s038575725 | 171 | 61 | 38,512 | 61,968 | Accepted | Accepted | 64.33 | n=int(eval(input()))
a=[]
a.append(int(eval(input())))
for i in range(1,n):
dumy=int(eval(input()))
for j in a:
if j==dumy:
break
else:
a.append(dumy)
print((len(a)))
| n=int(eval(input()))
ans=set([])
for _ in range(n):
ans.add(int(eval(input())))
print((len(ans))) | 13 | 5 | 186 | 89 | n = int(eval(input()))
a = []
a.append(int(eval(input())))
for i in range(1, n):
dumy = int(eval(input()))
for j in a:
if j == dumy:
break
else:
a.append(dumy)
print((len(a)))
| n = int(eval(input()))
ans = set([])
for _ in range(n):
ans.add(int(eval(input())))
print((len(ans)))
| false | 61.538462 | [
"-a = []",
"-a.append(int(eval(input())))",
"-for i in range(1, n):",
"- dumy = int(eval(input()))",
"- for j in a:",
"- if j == dumy:",
"- break",
"- else:",
"- a.append(dumy)",
"-print((len(a)))",
"+ans = set([])",
"+for _ in range(n):",
"+ ans.add(int(eval(input())))",
"+print((len(ans)))"
] | false | 0.035342 | 0.094253 | 0.374972 | [
"s621455489",
"s038575725"
] |
u030879708 | p02836 | python | s855696640 | s677165357 | 31 | 26 | 8,936 | 8,936 | Accepted | Accepted | 16.13 | S=eval(input())
cnt = 0
for i in range(len(S)//2):
if S[i] != S[len(S) - i - 1]:
cnt += 1
print(cnt) | S=eval(input())
a=len(S)
print((sum(S[i]!=S[a-i-1]for i in range(a//2)))) | 6 | 3 | 111 | 67 | S = eval(input())
cnt = 0
for i in range(len(S) // 2):
if S[i] != S[len(S) - i - 1]:
cnt += 1
print(cnt)
| S = eval(input())
a = len(S)
print((sum(S[i] != S[a - i - 1] for i in range(a // 2))))
| false | 50 | [
"-cnt = 0",
"-for i in range(len(S) // 2):",
"- if S[i] != S[len(S) - i - 1]:",
"- cnt += 1",
"-print(cnt)",
"+a = len(S)",
"+print((sum(S[i] != S[a - i - 1] for i in range(a // 2))))"
] | false | 0.040258 | 0.070319 | 0.572507 | [
"s855696640",
"s677165357"
] |
u923279197 | p03061 | python | s262247331 | s445239084 | 363 | 205 | 92,256 | 16,144 | Accepted | Accepted | 43.53 | from fractions import gcd
n = int(eval(input()))
a = list(map(int,input().split()))
mae = [a[0]]
for i in range(n-1):
mae.append(gcd(mae[i],a[i+1]))
ushiro = [a[n-1]]
for i in range(n-1):
ushiro.append(gcd(ushiro[i],a[n-i-2]))
ans = ushiro[n-2]
for i in range(n-1):
if i != n-2:
ans = max(ans,gcd(mae[i],ushiro[n-i-3]))
else:
ans = max(ans,mae[n-2])
print(ans)
| from fractions import gcd
n = int(eval(input()))
a = list(map(int,input().split()))
s = [a[0]]
for i in range(1,n):
s.append(gcd(s[-1],a[i]))
u = [a[n-1]]
for i in range(n-2,-1,-1):
u.append(gcd(u[-1],a[i]))
#print(s,u)
ans = max(u[-2],s[-2])
for i in range(1,n-1):
#print(s[i-1],u[-2-i])
now = gcd(s[i-1],u[-2-i])
ans = max(ans,now)
print(ans) | 19 | 20 | 408 | 381 | from fractions import gcd
n = int(eval(input()))
a = list(map(int, input().split()))
mae = [a[0]]
for i in range(n - 1):
mae.append(gcd(mae[i], a[i + 1]))
ushiro = [a[n - 1]]
for i in range(n - 1):
ushiro.append(gcd(ushiro[i], a[n - i - 2]))
ans = ushiro[n - 2]
for i in range(n - 1):
if i != n - 2:
ans = max(ans, gcd(mae[i], ushiro[n - i - 3]))
else:
ans = max(ans, mae[n - 2])
print(ans)
| from fractions import gcd
n = int(eval(input()))
a = list(map(int, input().split()))
s = [a[0]]
for i in range(1, n):
s.append(gcd(s[-1], a[i]))
u = [a[n - 1]]
for i in range(n - 2, -1, -1):
u.append(gcd(u[-1], a[i]))
# print(s,u)
ans = max(u[-2], s[-2])
for i in range(1, n - 1):
# print(s[i-1],u[-2-i])
now = gcd(s[i - 1], u[-2 - i])
ans = max(ans, now)
print(ans)
| false | 5 | [
"-mae = [a[0]]",
"-for i in range(n - 1):",
"- mae.append(gcd(mae[i], a[i + 1]))",
"-ushiro = [a[n - 1]]",
"-for i in range(n - 1):",
"- ushiro.append(gcd(ushiro[i], a[n - i - 2]))",
"-ans = ushiro[n - 2]",
"-for i in range(n - 1):",
"- if i != n - 2:",
"- ans = max(ans, gcd(mae[i], ushiro[n - i - 3]))",
"- else:",
"- ans = max(ans, mae[n - 2])",
"+s = [a[0]]",
"+for i in range(1, n):",
"+ s.append(gcd(s[-1], a[i]))",
"+u = [a[n - 1]]",
"+for i in range(n - 2, -1, -1):",
"+ u.append(gcd(u[-1], a[i]))",
"+# print(s,u)",
"+ans = max(u[-2], s[-2])",
"+for i in range(1, n - 1):",
"+ # print(s[i-1],u[-2-i])",
"+ now = gcd(s[i - 1], u[-2 - i])",
"+ ans = max(ans, now)"
] | false | 0.11566 | 0.047914 | 2.413912 | [
"s262247331",
"s445239084"
] |