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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
u077291787 | p03497 | python | s384534260 | s723190677 | 200 | 95 | 33,696 | 32,572 | Accepted | Accepted | 52.5 | # ARC086C - Not so Diverse (ABC081C)
n, k = list(map(int, input().rstrip().split()))
lst = sorted(list(map(int, input().rstrip().split())))
dic = {}
for i in lst:
if i not in dic:
dic[i] = 1
else:
dic[i] += 1
cnt = sorted([i for i in list(dic.values())], reverse=True)
print((sum(cnt[k:]))) | from collections import Counter
n, k = list(map(int, input().rstrip().split()))
lst = list(map(int, input().rstrip().split()))
cnt = sorted(list(Counter(lst).values()), reverse=True)
print((sum(cnt[k:]))) | 12 | 6 | 318 | 202 | # ARC086C - Not so Diverse (ABC081C)
n, k = list(map(int, input().rstrip().split()))
lst = sorted(list(map(int, input().rstrip().split())))
dic = {}
for i in lst:
if i not in dic:
dic[i] = 1
else:
dic[i] += 1
cnt = sorted([i for i in list(dic.values())], reverse=True)
print((sum(cnt[k:])))
| from collections import Counter
n, k = list(map(int, input().rstrip().split()))
lst = list(map(int, input().rstrip().split()))
cnt = sorted(list(Counter(lst).values()), reverse=True)
print((sum(cnt[k:])))
| false | 50 | [
"-# ARC086C - Not so Diverse (ABC081C)",
"+from collections import Counter",
"+",
"-lst = sorted(list(map(int, input().rstrip().split())))",
"-dic = {}",
"-for i in lst:",
"- if i not in dic:",
"- dic[i] = 1",
"- else:",
"- dic[i] += 1",
"-cnt = sorted([i for i in list(dic.values())], reverse=True)",
"+lst = list(map(int, input().rstrip().split()))",
"+cnt = sorted(list(Counter(lst).values()), reverse=True)"
] | false | 0.042404 | 0.102434 | 0.41396 | [
"s384534260",
"s723190677"
] |
u392319141 | p03912 | python | s473837892 | s521566700 | 342 | 306 | 35,160 | 35,932 | Accepted | Accepted | 10.53 | from collections import Counter
N, M = list(map(int, input().split()))
cntX = Counter(list(map(int, input().split())))
cntMod = Counter()
cntDup = Counter()
for x, c in list(cntX.items()):
cntMod[x % M] += c
cntDup[x % M] += c // 2
ans = 0
for n in range(M // 2 + 1):
m = (M - n) % M
if m == n:
ans += cntMod[n] // 2
continue
cnt = min(cntMod[n], cntMod[m])
cntMod[n] -= cnt
cntMod[m] -= cnt
ans += cnt
ans += min(cntMod[n] // 2, cntDup[n]) + min(cntMod[m] // 2, cntDup[m])
print(ans)
| from collections import Counter
N, M = list(map(int, input().split()))
X = list(map(int, input().split()))
dupCnt = Counter()
modCnt = Counter()
for x, c in list(Counter(X).items()):
x %= M
dupCnt[x] += c // 2
modCnt[x] += c
ans = 0
for i in range(M):
j = M - i
if i > j:
break
if i == j or i == 0:
ans += modCnt[i] // 2
continue
mi = min(modCnt[i], modCnt[j])
ans += mi
ans += min((modCnt[i] - mi) // 2, dupCnt[i])
ans += min((modCnt[j] - mi) // 2, dupCnt[j])
print(ans)
| 24 | 29 | 546 | 559 | from collections import Counter
N, M = list(map(int, input().split()))
cntX = Counter(list(map(int, input().split())))
cntMod = Counter()
cntDup = Counter()
for x, c in list(cntX.items()):
cntMod[x % M] += c
cntDup[x % M] += c // 2
ans = 0
for n in range(M // 2 + 1):
m = (M - n) % M
if m == n:
ans += cntMod[n] // 2
continue
cnt = min(cntMod[n], cntMod[m])
cntMod[n] -= cnt
cntMod[m] -= cnt
ans += cnt
ans += min(cntMod[n] // 2, cntDup[n]) + min(cntMod[m] // 2, cntDup[m])
print(ans)
| from collections import Counter
N, M = list(map(int, input().split()))
X = list(map(int, input().split()))
dupCnt = Counter()
modCnt = Counter()
for x, c in list(Counter(X).items()):
x %= M
dupCnt[x] += c // 2
modCnt[x] += c
ans = 0
for i in range(M):
j = M - i
if i > j:
break
if i == j or i == 0:
ans += modCnt[i] // 2
continue
mi = min(modCnt[i], modCnt[j])
ans += mi
ans += min((modCnt[i] - mi) // 2, dupCnt[i])
ans += min((modCnt[j] - mi) // 2, dupCnt[j])
print(ans)
| false | 17.241379 | [
"-cntX = Counter(list(map(int, input().split())))",
"-cntMod = Counter()",
"-cntDup = Counter()",
"-for x, c in list(cntX.items()):",
"- cntMod[x % M] += c",
"- cntDup[x % M] += c // 2",
"+X = list(map(int, input().split()))",
"+dupCnt = Counter()",
"+modCnt = Counter()",
"+for x, c in list(Counter(X).items()):",
"+ x %= M",
"+ dupCnt[x] += c // 2",
"+ modCnt[x] += c",
"-for n in range(M // 2 + 1):",
"- m = (M - n) % M",
"- if m == n:",
"- ans += cntMod[n] // 2",
"+for i in range(M):",
"+ j = M - i",
"+ if i > j:",
"+ break",
"+ if i == j or i == 0:",
"+ ans += modCnt[i] // 2",
"- cnt = min(cntMod[n], cntMod[m])",
"- cntMod[n] -= cnt",
"- cntMod[m] -= cnt",
"- ans += cnt",
"- ans += min(cntMod[n] // 2, cntDup[n]) + min(cntMod[m] // 2, cntDup[m])",
"+ mi = min(modCnt[i], modCnt[j])",
"+ ans += mi",
"+ ans += min((modCnt[i] - mi) // 2, dupCnt[i])",
"+ ans += min((modCnt[j] - mi) // 2, dupCnt[j])"
] | false | 0.048604 | 0.049099 | 0.98993 | [
"s473837892",
"s521566700"
] |
u120691615 | p02831 | python | s785993745 | s789895647 | 55 | 17 | 2,940 | 2,940 | Accepted | Accepted | 69.09 | A,B = list(map(int,input().split()))
a,b = A,B
while True:
if a > b:
b += B
elif a < b:
a += A
if a == b:
print(a)
break | A,B = list(map(int,input().split()))
def gcd(a, b):
if a % b == 0:
return b
else:
return gcd(b, a % b)
def lcm(a, b):
return a / gcd(a, b) * b
print((int(lcm(A,B)))) | 10 | 12 | 167 | 199 | A, B = list(map(int, input().split()))
a, b = A, B
while True:
if a > b:
b += B
elif a < b:
a += A
if a == b:
print(a)
break
| A, B = list(map(int, input().split()))
def gcd(a, b):
if a % b == 0:
return b
else:
return gcd(b, a % b)
def lcm(a, b):
return a / gcd(a, b) * b
print((int(lcm(A, B))))
| false | 16.666667 | [
"-a, b = A, B",
"-while True:",
"- if a > b:",
"- b += B",
"- elif a < b:",
"- a += A",
"- if a == b:",
"- print(a)",
"- break",
"+",
"+",
"+def gcd(a, b):",
"+ if a % b == 0:",
"+ return b",
"+ else:",
"+ return gcd(b, a % b)",
"+",
"+",
"+def lcm(a, b):",
"+ return a / gcd(a, b) * b",
"+",
"+",
"+print((int(lcm(A, B))))"
] | false | 0.102311 | 0.107063 | 0.955614 | [
"s785993745",
"s789895647"
] |
u863442865 | p03625 | python | s889793287 | s748910323 | 117 | 101 | 14,764 | 14,756 | Accepted | Accepted | 13.68 | def main():
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10000000)
from collections import Counter, deque
#from collections import defaultdict
from itertools import combinations, permutations
#from itertools import accumulate, product
from bisect import bisect_left,bisect_right
from math import floor, ceil
#from operator import itemgetter
#mod = 1000000007
N = int(eval(input()))
A = list(map(int, input().split()))
a = sorted(A, reverse=1)
res1 = 0
res2 = []
for i in range(N-3):
if a[i]==a[i+1]==a[i+2]==a[i+3]:
res1 = a[i]
break
for i in range(N-1):
if a[i]==a[i+1] and not a[i] in res2:
res2.append(a[i])
if len(res2)==2:
break
if len(res2)==0:
print((0))
elif len(res2)==1:
print((res1**2))
else:
print((max(res1**2, res2[0]*res2[1])))
if __name__ == '__main__':
main() | def main():
import sys
#input = sys.stdin.readline
sys.setrecursionlimit(10000000)
from collections import Counter, deque
#from collections import defaultdict
from itertools import combinations, permutations
#from itertools import accumulate, product
from bisect import bisect_left,bisect_right
from math import floor, ceil
#from operator import itemgetter
#mod = 1000000007
N = int(eval(input()))
A = list(map(int, input().split()))
a = sorted(A, reverse=1)
res1 = 0
res2 = []
for i in range(N-3):
if a[i]==a[i+1]==a[i+2]==a[i+3]:
res1 = a[i]
break
for i in range(N-1):
if a[i]==a[i+1] and not a[i] in res2:
res2.append(a[i])
if len(res2)==2:
break
if len(res2)<2:
print((res1**2))
else:
print((max(res1**2, res2[0]*res2[1])))
if __name__ == '__main__':
main() | 39 | 37 | 1,006 | 964 | def main():
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10000000)
from collections import Counter, deque
# from collections import defaultdict
from itertools import combinations, permutations
# from itertools import accumulate, product
from bisect import bisect_left, bisect_right
from math import floor, ceil
# from operator import itemgetter
# mod = 1000000007
N = int(eval(input()))
A = list(map(int, input().split()))
a = sorted(A, reverse=1)
res1 = 0
res2 = []
for i in range(N - 3):
if a[i] == a[i + 1] == a[i + 2] == a[i + 3]:
res1 = a[i]
break
for i in range(N - 1):
if a[i] == a[i + 1] and not a[i] in res2:
res2.append(a[i])
if len(res2) == 2:
break
if len(res2) == 0:
print((0))
elif len(res2) == 1:
print((res1**2))
else:
print((max(res1**2, res2[0] * res2[1])))
if __name__ == "__main__":
main()
| def main():
import sys
# input = sys.stdin.readline
sys.setrecursionlimit(10000000)
from collections import Counter, deque
# from collections import defaultdict
from itertools import combinations, permutations
# from itertools import accumulate, product
from bisect import bisect_left, bisect_right
from math import floor, ceil
# from operator import itemgetter
# mod = 1000000007
N = int(eval(input()))
A = list(map(int, input().split()))
a = sorted(A, reverse=1)
res1 = 0
res2 = []
for i in range(N - 3):
if a[i] == a[i + 1] == a[i + 2] == a[i + 3]:
res1 = a[i]
break
for i in range(N - 1):
if a[i] == a[i + 1] and not a[i] in res2:
res2.append(a[i])
if len(res2) == 2:
break
if len(res2) < 2:
print((res1**2))
else:
print((max(res1**2, res2[0] * res2[1])))
if __name__ == "__main__":
main()
| false | 5.128205 | [
"- input = sys.stdin.readline",
"+ # input = sys.stdin.readline",
"- if len(res2) == 0:",
"- print((0))",
"- elif len(res2) == 1:",
"+ if len(res2) < 2:"
] | false | 0.039281 | 0.007461 | 5.264583 | [
"s889793287",
"s748910323"
] |
u766684188 | p02901 | python | s865846228 | s976274194 | 548 | 476 | 145,756 | 141,020 | Accepted | Accepted | 13.14 | #E
import sys
input=sys.stdin.readline
def main():
n,m=list(map(int,input().split()))
Cost=[0]*m
Key=[0]*m
for i in range(m):
a,b=list(map(int,input().split()))
C=tuple(map(int,input().split()))
Cost[i]=a
for c in C:
Key[i]+=1<<(c-1)
#print(Cost,Key)
DP=[[float('inf')]*(1<<n) for _ in range(m+1)]
for i,(c,k) in enumerate(zip(Cost,Key)):
DP[i+1][k]=min(DP[i][k],c)
for j in range(1,1<<n):
DP[i+1][j]=min(DP[i][j],DP[i+1][j])
DP[i+1][j|k]=min(DP[i+1][j|k],DP[i][j|k],DP[i][j]+c)
#print(DP)
print((-1 if DP[-1][-1]==float('inf') else DP[-1][-1]))
if __name__=='__main__':
main() | import sys
input=sys.stdin.readline
def main():
n,m=list(map(int,input().split()))
Cost=[0]*m
Key=[0]*m
for i in range(m):
a,b=list(map(int,input().split()))
C=tuple(map(int,input().split()))
Cost[i]=a
for c in C:
Key[i]+=1<<(c-1)
DP=[[float('inf')]*(1<<n) for _ in range(m+1)]
DP[0][0]=0
for i,(c,k) in enumerate(zip(Cost,Key)):
for j in range(1<<n):
DP[i+1][j]=min(DP[i][j],DP[i+1][j])
DP[i+1][j|k]=min(DP[i+1][j|k],DP[i][j]+c)
print((-1 if DP[-1][-1]==float('inf') else DP[-1][-1]))
if __name__=='__main__':
main() | 26 | 23 | 718 | 639 | # E
import sys
input = sys.stdin.readline
def main():
n, m = list(map(int, input().split()))
Cost = [0] * m
Key = [0] * m
for i in range(m):
a, b = list(map(int, input().split()))
C = tuple(map(int, input().split()))
Cost[i] = a
for c in C:
Key[i] += 1 << (c - 1)
# print(Cost,Key)
DP = [[float("inf")] * (1 << n) for _ in range(m + 1)]
for i, (c, k) in enumerate(zip(Cost, Key)):
DP[i + 1][k] = min(DP[i][k], c)
for j in range(1, 1 << n):
DP[i + 1][j] = min(DP[i][j], DP[i + 1][j])
DP[i + 1][j | k] = min(DP[i + 1][j | k], DP[i][j | k], DP[i][j] + c)
# print(DP)
print((-1 if DP[-1][-1] == float("inf") else DP[-1][-1]))
if __name__ == "__main__":
main()
| import sys
input = sys.stdin.readline
def main():
n, m = list(map(int, input().split()))
Cost = [0] * m
Key = [0] * m
for i in range(m):
a, b = list(map(int, input().split()))
C = tuple(map(int, input().split()))
Cost[i] = a
for c in C:
Key[i] += 1 << (c - 1)
DP = [[float("inf")] * (1 << n) for _ in range(m + 1)]
DP[0][0] = 0
for i, (c, k) in enumerate(zip(Cost, Key)):
for j in range(1 << n):
DP[i + 1][j] = min(DP[i][j], DP[i + 1][j])
DP[i + 1][j | k] = min(DP[i + 1][j | k], DP[i][j] + c)
print((-1 if DP[-1][-1] == float("inf") else DP[-1][-1]))
if __name__ == "__main__":
main()
| false | 11.538462 | [
"-# E",
"- # print(Cost,Key)",
"+ DP[0][0] = 0",
"- DP[i + 1][k] = min(DP[i][k], c)",
"- for j in range(1, 1 << n):",
"+ for j in range(1 << n):",
"- DP[i + 1][j | k] = min(DP[i + 1][j | k], DP[i][j | k], DP[i][j] + c)",
"- # print(DP)",
"+ DP[i + 1][j | k] = min(DP[i + 1][j | k], DP[i][j] + c)"
] | false | 0.039662 | 0.087423 | 0.453676 | [
"s865846228",
"s976274194"
] |
u474561976 | p02683 | python | s403980861 | s406465201 | 53 | 30 | 11,544 | 9,220 | Accepted | Accepted | 43.4 | def main():
from sys import stdin
import itertools
n,m,x = list(map(int,stdin.readline().rstrip().split()))
mat = []
for _ in range(n):
temp = list(map(int,stdin.readline().rstrip().split()))
mat.append(temp)
sum = []
for i in range(n+1):
for l in itertools.combinations(mat,i):
temp = [0]*(m+1)
for k in range(m+1):
for j in l:
temp[k]+=j[k]
sum.append(temp)
sum.sort(key=lambda x: x[0])
for l in sum:
ans = -1
flag = True
for j in l[1:]:
if j < x:
flag = False
break
if flag:
ans=l[0]
break
print(ans)
main() | import math
def solve(C,A,x,k,s,U):
if k == 0:
if min(U) >= x:
return s
else:
return math.inf
else:
s_use = s+C[k-1]
U_use = [u+a for u,a in zip(U,A[k-1])]
return min(solve(C,A,x,k-1,s,U),solve(C,A,x,k-1,s_use,U_use))
def main():
from sys import stdin
n,m,x = list(map(int,stdin.readline().rstrip().split()))
C = []
A = []
for _ in range(n):
temp = list(map(int,stdin.readline().rstrip().split()))
C.append(temp[0])
A.append(temp[1:])
U = [0]*m
ans = solve(C,A,x,n,0,U)
print((ans if ans != math.inf else -1))
main() | 33 | 31 | 796 | 693 | def main():
from sys import stdin
import itertools
n, m, x = list(map(int, stdin.readline().rstrip().split()))
mat = []
for _ in range(n):
temp = list(map(int, stdin.readline().rstrip().split()))
mat.append(temp)
sum = []
for i in range(n + 1):
for l in itertools.combinations(mat, i):
temp = [0] * (m + 1)
for k in range(m + 1):
for j in l:
temp[k] += j[k]
sum.append(temp)
sum.sort(key=lambda x: x[0])
for l in sum:
ans = -1
flag = True
for j in l[1:]:
if j < x:
flag = False
break
if flag:
ans = l[0]
break
print(ans)
main()
| import math
def solve(C, A, x, k, s, U):
if k == 0:
if min(U) >= x:
return s
else:
return math.inf
else:
s_use = s + C[k - 1]
U_use = [u + a for u, a in zip(U, A[k - 1])]
return min(solve(C, A, x, k - 1, s, U), solve(C, A, x, k - 1, s_use, U_use))
def main():
from sys import stdin
n, m, x = list(map(int, stdin.readline().rstrip().split()))
C = []
A = []
for _ in range(n):
temp = list(map(int, stdin.readline().rstrip().split()))
C.append(temp[0])
A.append(temp[1:])
U = [0] * m
ans = solve(C, A, x, n, 0, U)
print((ans if ans != math.inf else -1))
main()
| false | 6.060606 | [
"+import math",
"+",
"+",
"+def solve(C, A, x, k, s, U):",
"+ if k == 0:",
"+ if min(U) >= x:",
"+ return s",
"+ else:",
"+ return math.inf",
"+ else:",
"+ s_use = s + C[k - 1]",
"+ U_use = [u + a for u, a in zip(U, A[k - 1])]",
"+ return min(solve(C, A, x, k - 1, s, U), solve(C, A, x, k - 1, s_use, U_use))",
"+",
"+",
"- import itertools",
"- mat = []",
"+ C = []",
"+ A = []",
"- mat.append(temp)",
"- sum = []",
"- for i in range(n + 1):",
"- for l in itertools.combinations(mat, i):",
"- temp = [0] * (m + 1)",
"- for k in range(m + 1):",
"- for j in l:",
"- temp[k] += j[k]",
"- sum.append(temp)",
"- sum.sort(key=lambda x: x[0])",
"- for l in sum:",
"- ans = -1",
"- flag = True",
"- for j in l[1:]:",
"- if j < x:",
"- flag = False",
"- break",
"- if flag:",
"- ans = l[0]",
"- break",
"- print(ans)",
"+ C.append(temp[0])",
"+ A.append(temp[1:])",
"+ U = [0] * m",
"+ ans = solve(C, A, x, n, 0, U)",
"+ print((ans if ans != math.inf else -1))"
] | false | 0.075795 | 0.093864 | 0.807497 | [
"s403980861",
"s406465201"
] |
u482789362 | p02710 | python | s982910726 | s320144791 | 1,791 | 1,560 | 461,932 | 446,452 | Accepted | Accepted | 12.9 | import sys
from collections import defaultdict
sys.setrecursionlimit(2 * 10 ** 5)
(N,) = [int(x) for x in input().split()]
colors = [int(x) for x in input().split()]
edges = [[int(x) for x in input().split()] for i in range(N - 1)]
graph = defaultdict(list)
for u, v in edges:
graph[u].append(v)
graph[v].append(u)
parent = {1: None}
children = defaultdict(list)
def rootTree(node):
for nbr in graph[node]:
if nbr not in parent:
parent[nbr] = node
children[node].append(nbr)
rootTree(nbr)
rootTree(1)
colorlessCount = [0 for c in range(N + 1)]
colorlessTime = [0 for c in range(N + 1)]
t = 0
def buildComps(node):
global t
t += 1
currColor = colors[node - 1]
colorlessTime[currColor] += 1
for child in children[node]:
oldCount = t - colorlessTime[currColor]
colorlessTime[currColor] = t
buildComps(child)
s = t - colorlessTime[currColor]
colorlessTime[currColor] = t - oldCount
colorlessCount[currColor] += s * (s + 1) // 2
buildComps(1)
for c in range(1, N + 1):
s = t - colorlessTime[c]
colorlessCount[c] += s * (s + 1) // 2
maxPairs = N * (N + 1) // 2
for c in range(1, N + 1):
print((maxPairs - colorlessCount[c]))
| import sys
sys.setrecursionlimit(2 * 10 ** 5)
N = int(eval(input()))
colors = [int(x) for x in input().split()]
edges = [[int(x) for x in input().split()] for i in range(N - 1)]
graph = [[] for i in range(N + 1)]
for u, v in edges:
graph[u].append(v)
graph[v].append(u)
parent = {1: None}
children = {}
def rootTree(node):
children[node] = []
for nbr in graph[node]:
if nbr not in parent:
parent[nbr] = node
children[node].append(nbr)
rootTree(nbr)
rootTree(1)
# Count the paths that don't contain a particular color
# If we can find a max c-less component (in the sense that the nodes are either leaves or bordered by color c) of size s, then there are (s * s + 1 / 2) c-less paths in that component
colorlessCount = [0 for c in range(N + 1)]
# In our DFS we want to increment the size of each component except for the one matching current color all at once but that will TLE
# Instead implicitly increment them by tracking current size as dfs time `t` minus some offset. Then we can increment all just by adding to t or subtract from one by fiddling with the offset
colorlessTime = [0 for c in range(N + 1)]
t = 0
def buildComps(node):
global t
currColor = colors[node - 1]
# Increment all by 1 except currColor
t += 1
colorlessTime[currColor] += 1
for child in children[node]:
# Each child forms a new currColor-less component so we need to save the old count
oldCount = t - colorlessTime[currColor]
# Start new comp
colorlessTime[currColor] = t
buildComps(child)
# Done with child comp, count the paths and discard comp
s = t - colorlessTime[currColor]
colorlessCount[currColor] += s * (s + 1) // 2
# Restore old count
colorlessTime[currColor] = t - oldCount
buildComps(1)
# Count the colorless components path from root too
for c in range(1, N + 1):
s = t - colorlessTime[c]
colorlessCount[c] += s * (s + 1) // 2
# We counted colorless but want colored paths so take complement
maxPairs = N * (N + 1) // 2
for c in range(1, N + 1):
print((maxPairs - colorlessCount[c]))
| 54 | 66 | 1,319 | 2,222 | import sys
from collections import defaultdict
sys.setrecursionlimit(2 * 10**5)
(N,) = [int(x) for x in input().split()]
colors = [int(x) for x in input().split()]
edges = [[int(x) for x in input().split()] for i in range(N - 1)]
graph = defaultdict(list)
for u, v in edges:
graph[u].append(v)
graph[v].append(u)
parent = {1: None}
children = defaultdict(list)
def rootTree(node):
for nbr in graph[node]:
if nbr not in parent:
parent[nbr] = node
children[node].append(nbr)
rootTree(nbr)
rootTree(1)
colorlessCount = [0 for c in range(N + 1)]
colorlessTime = [0 for c in range(N + 1)]
t = 0
def buildComps(node):
global t
t += 1
currColor = colors[node - 1]
colorlessTime[currColor] += 1
for child in children[node]:
oldCount = t - colorlessTime[currColor]
colorlessTime[currColor] = t
buildComps(child)
s = t - colorlessTime[currColor]
colorlessTime[currColor] = t - oldCount
colorlessCount[currColor] += s * (s + 1) // 2
buildComps(1)
for c in range(1, N + 1):
s = t - colorlessTime[c]
colorlessCount[c] += s * (s + 1) // 2
maxPairs = N * (N + 1) // 2
for c in range(1, N + 1):
print((maxPairs - colorlessCount[c]))
| import sys
sys.setrecursionlimit(2 * 10**5)
N = int(eval(input()))
colors = [int(x) for x in input().split()]
edges = [[int(x) for x in input().split()] for i in range(N - 1)]
graph = [[] for i in range(N + 1)]
for u, v in edges:
graph[u].append(v)
graph[v].append(u)
parent = {1: None}
children = {}
def rootTree(node):
children[node] = []
for nbr in graph[node]:
if nbr not in parent:
parent[nbr] = node
children[node].append(nbr)
rootTree(nbr)
rootTree(1)
# Count the paths that don't contain a particular color
# If we can find a max c-less component (in the sense that the nodes are either leaves or bordered by color c) of size s, then there are (s * s + 1 / 2) c-less paths in that component
colorlessCount = [0 for c in range(N + 1)]
# In our DFS we want to increment the size of each component except for the one matching current color all at once but that will TLE
# Instead implicitly increment them by tracking current size as dfs time `t` minus some offset. Then we can increment all just by adding to t or subtract from one by fiddling with the offset
colorlessTime = [0 for c in range(N + 1)]
t = 0
def buildComps(node):
global t
currColor = colors[node - 1]
# Increment all by 1 except currColor
t += 1
colorlessTime[currColor] += 1
for child in children[node]:
# Each child forms a new currColor-less component so we need to save the old count
oldCount = t - colorlessTime[currColor]
# Start new comp
colorlessTime[currColor] = t
buildComps(child)
# Done with child comp, count the paths and discard comp
s = t - colorlessTime[currColor]
colorlessCount[currColor] += s * (s + 1) // 2
# Restore old count
colorlessTime[currColor] = t - oldCount
buildComps(1)
# Count the colorless components path from root too
for c in range(1, N + 1):
s = t - colorlessTime[c]
colorlessCount[c] += s * (s + 1) // 2
# We counted colorless but want colored paths so take complement
maxPairs = N * (N + 1) // 2
for c in range(1, N + 1):
print((maxPairs - colorlessCount[c]))
| false | 18.181818 | [
"-from collections import defaultdict",
"-(N,) = [int(x) for x in input().split()]",
"+N = int(eval(input()))",
"-graph = defaultdict(list)",
"+graph = [[] for i in range(N + 1)]",
"-children = defaultdict(list)",
"+children = {}",
"+ children[node] = []",
"+# Count the paths that don't contain a particular color",
"+# If we can find a max c-less component (in the sense that the nodes are either leaves or bordered by color c) of size s, then there are (s * s + 1 / 2) c-less paths in that component",
"+# In our DFS we want to increment the size of each component except for the one matching current color all at once but that will TLE",
"+# Instead implicitly increment them by tracking current size as dfs time `t` minus some offset. Then we can increment all just by adding to t or subtract from one by fiddling with the offset",
"+ currColor = colors[node - 1]",
"+ # Increment all by 1 except currColor",
"- currColor = colors[node - 1]",
"+ # Each child forms a new currColor-less component so we need to save the old count",
"+ # Start new comp",
"+ # Done with child comp, count the paths and discard comp",
"+ colorlessCount[currColor] += s * (s + 1) // 2",
"+ # Restore old count",
"- colorlessCount[currColor] += s * (s + 1) // 2",
"+# Count the colorless components path from root too",
"+# We counted colorless but want colored paths so take complement"
] | false | 0.033272 | 0.035229 | 0.944458 | [
"s982910726",
"s320144791"
] |
u079411907 | p02803 | python | s100718478 | s276211968 | 850 | 650 | 90,712 | 46,360 | Accepted | Accepted | 23.53 | '''input
3 3
.#.
#..
.#.
'''
# A coding delight
from sys import stdin, stdout
import gc
gc.disable()
input = stdin.readline
from collections import deque
def mp(arr):
arr = list(map(str, arr))
return ' '.join(arr)
def bfs(source):
myq = deque()
myq.append(source)
visited = dict()
visited[mp(source)] = True
dist = -1
while len(myq) > 0:
temp = deque()
dist += 1
while len(myq) > 0:
x, y = myq.popleft()
if x - 1 >= 0:
if maze[x - 1][y] != '#' and mp([x - 1, y]) not in visited:
visited[mp([x -1, y])] = True
temp.append([x - 1, y])
if x + 1 < n:
if maze[x + 1][y] != '#' and mp([x + 1, y]) not in visited:
visited[mp([x + 1, y])] = True
temp.append([x + 1, y])
if y - 1 >= 0:
if maze[x][y - 1] != '#' and mp([x, y - 1]) not in visited:
visited[mp([x, y - 1])] = True
temp.append([x, y - 1])
if y + 1 < m:
if maze[x][y + 1] != '#' and mp([x, y + 1]) not in visited:
visited[mp([x, y + 1])] = True
temp.append([x, y + 1])
myq = temp
return dist
# main starts
n, m = list(map(int, input().split()))
maze = []
for _ in range(n):
state = list(input().strip())
maze.append(state)
# from random import randint
# for _ in range(1000):
# maze = []
# n = randint(1, 20)
# m = randint(1, 20)
# for i in range(n):
# temp = []
# for j in range(m):
# k = randint(1, 2)
# if k == 1:
# temp.append('.')
# else:
# temp.append('#')
# maze.append(temp)
ans = 0
for i in range(n):
for j in range(m):
if maze[i][j] != '#':
first = [i, j]
ans = max(ans, bfs(first))
print(ans) | '''input
3 3
.#.
#..
.#.
'''
# A coding delight
from sys import stdin, stdout
import gc
gc.disable()
input = stdin.readline
from collections import deque
def mp(arr):
arr = list(map(str, arr))
return ' '.join(arr)
def bfs(source):
myq = deque()
myq.append(source)
visited = dict()
visited[mp(source)] = True
dist = -1
while len(myq) > 0:
temp = deque()
dist += 1
while len(myq) > 0:
x, y = myq.popleft()
if x - 1 >= 0 and maze[x - 1][y] != '#' and mp([x - 1, y]) not in visited:
visited[mp([x -1, y])] = True
temp.append([x - 1, y])
if x + 1 < n and maze[x + 1][y] != '#' and mp([x + 1, y]) not in visited:
visited[mp([x + 1, y])] = True
temp.append([x + 1, y])
if y - 1 >= 0 and maze[x][y - 1] != '#' and mp([x, y - 1]) not in visited:
visited[mp([x, y - 1])] = True
temp.append([x, y - 1])
if y + 1 < m and maze[x][y + 1] != '#' and mp([x, y + 1]) not in visited:
visited[mp([x, y + 1])] = True
temp.append([x, y + 1])
myq = temp
return dist
# main starts
n, m = list(map(int, input().split()))
maze = []
for _ in range(n):
state = list(input().strip())
maze.append(state)
# from random import randint
# for _ in range(1000):
# maze = []
# n = randint(1, 20)
# m = randint(1, 20)
# for i in range(n):
# temp = []
# for j in range(m):
# k = randint(1, 2)
# if k == 1:
# temp.append('.')
# else:
# temp.append('#')
# maze.append(temp)
ans = 0
for i in range(n):
for j in range(m):
if maze[i][j] != '#':
first = [i, j]
ans = max(ans, bfs(first))
print(ans) | 79 | 75 | 1,652 | 1,632 | """input
3 3
.#.
#..
.#.
"""
# A coding delight
from sys import stdin, stdout
import gc
gc.disable()
input = stdin.readline
from collections import deque
def mp(arr):
arr = list(map(str, arr))
return " ".join(arr)
def bfs(source):
myq = deque()
myq.append(source)
visited = dict()
visited[mp(source)] = True
dist = -1
while len(myq) > 0:
temp = deque()
dist += 1
while len(myq) > 0:
x, y = myq.popleft()
if x - 1 >= 0:
if maze[x - 1][y] != "#" and mp([x - 1, y]) not in visited:
visited[mp([x - 1, y])] = True
temp.append([x - 1, y])
if x + 1 < n:
if maze[x + 1][y] != "#" and mp([x + 1, y]) not in visited:
visited[mp([x + 1, y])] = True
temp.append([x + 1, y])
if y - 1 >= 0:
if maze[x][y - 1] != "#" and mp([x, y - 1]) not in visited:
visited[mp([x, y - 1])] = True
temp.append([x, y - 1])
if y + 1 < m:
if maze[x][y + 1] != "#" and mp([x, y + 1]) not in visited:
visited[mp([x, y + 1])] = True
temp.append([x, y + 1])
myq = temp
return dist
# main starts
n, m = list(map(int, input().split()))
maze = []
for _ in range(n):
state = list(input().strip())
maze.append(state)
# from random import randint
# for _ in range(1000):
# maze = []
# n = randint(1, 20)
# m = randint(1, 20)
# for i in range(n):
# temp = []
# for j in range(m):
# k = randint(1, 2)
# if k == 1:
# temp.append('.')
# else:
# temp.append('#')
# maze.append(temp)
ans = 0
for i in range(n):
for j in range(m):
if maze[i][j] != "#":
first = [i, j]
ans = max(ans, bfs(first))
print(ans)
| """input
3 3
.#.
#..
.#.
"""
# A coding delight
from sys import stdin, stdout
import gc
gc.disable()
input = stdin.readline
from collections import deque
def mp(arr):
arr = list(map(str, arr))
return " ".join(arr)
def bfs(source):
myq = deque()
myq.append(source)
visited = dict()
visited[mp(source)] = True
dist = -1
while len(myq) > 0:
temp = deque()
dist += 1
while len(myq) > 0:
x, y = myq.popleft()
if x - 1 >= 0 and maze[x - 1][y] != "#" and mp([x - 1, y]) not in visited:
visited[mp([x - 1, y])] = True
temp.append([x - 1, y])
if x + 1 < n and maze[x + 1][y] != "#" and mp([x + 1, y]) not in visited:
visited[mp([x + 1, y])] = True
temp.append([x + 1, y])
if y - 1 >= 0 and maze[x][y - 1] != "#" and mp([x, y - 1]) not in visited:
visited[mp([x, y - 1])] = True
temp.append([x, y - 1])
if y + 1 < m and maze[x][y + 1] != "#" and mp([x, y + 1]) not in visited:
visited[mp([x, y + 1])] = True
temp.append([x, y + 1])
myq = temp
return dist
# main starts
n, m = list(map(int, input().split()))
maze = []
for _ in range(n):
state = list(input().strip())
maze.append(state)
# from random import randint
# for _ in range(1000):
# maze = []
# n = randint(1, 20)
# m = randint(1, 20)
# for i in range(n):
# temp = []
# for j in range(m):
# k = randint(1, 2)
# if k == 1:
# temp.append('.')
# else:
# temp.append('#')
# maze.append(temp)
ans = 0
for i in range(n):
for j in range(m):
if maze[i][j] != "#":
first = [i, j]
ans = max(ans, bfs(first))
print(ans)
| false | 5.063291 | [
"- if x - 1 >= 0:",
"- if maze[x - 1][y] != \"#\" and mp([x - 1, y]) not in visited:",
"- visited[mp([x - 1, y])] = True",
"- temp.append([x - 1, y])",
"- if x + 1 < n:",
"- if maze[x + 1][y] != \"#\" and mp([x + 1, y]) not in visited:",
"- visited[mp([x + 1, y])] = True",
"- temp.append([x + 1, y])",
"- if y - 1 >= 0:",
"- if maze[x][y - 1] != \"#\" and mp([x, y - 1]) not in visited:",
"- visited[mp([x, y - 1])] = True",
"- temp.append([x, y - 1])",
"- if y + 1 < m:",
"- if maze[x][y + 1] != \"#\" and mp([x, y + 1]) not in visited:",
"- visited[mp([x, y + 1])] = True",
"- temp.append([x, y + 1])",
"+ if x - 1 >= 0 and maze[x - 1][y] != \"#\" and mp([x - 1, y]) not in visited:",
"+ visited[mp([x - 1, y])] = True",
"+ temp.append([x - 1, y])",
"+ if x + 1 < n and maze[x + 1][y] != \"#\" and mp([x + 1, y]) not in visited:",
"+ visited[mp([x + 1, y])] = True",
"+ temp.append([x + 1, y])",
"+ if y - 1 >= 0 and maze[x][y - 1] != \"#\" and mp([x, y - 1]) not in visited:",
"+ visited[mp([x, y - 1])] = True",
"+ temp.append([x, y - 1])",
"+ if y + 1 < m and maze[x][y + 1] != \"#\" and mp([x, y + 1]) not in visited:",
"+ visited[mp([x, y + 1])] = True",
"+ temp.append([x, y + 1])"
] | false | 0.037072 | 0.037955 | 0.976747 | [
"s100718478",
"s276211968"
] |
u150984829 | p02397 | python | s037337671 | s074842659 | 50 | 40 | 5,612 | 5,980 | Accepted | Accepted | 20 | while 1:
n=input()
if n=='0 0':break
x,y=map(int,n.split())
print(y,x) if x>y else print(n)
| a=[]
while 1:
n=input()
if n=='0 0':break
a.append(n)
for s in a:
x,y=map(int,s.split())
print(y,x) if x>y else print(s)
| 5 | 8 | 99 | 132 | while 1:
n = input()
if n == "0 0":
break
x, y = map(int, n.split())
print(y, x) if x > y else print(n)
| a = []
while 1:
n = input()
if n == "0 0":
break
a.append(n)
for s in a:
x, y = map(int, s.split())
print(y, x) if x > y else print(s)
| false | 37.5 | [
"+a = []",
"- x, y = map(int, n.split())",
"- print(y, x) if x > y else print(n)",
"+ a.append(n)",
"+for s in a:",
"+ x, y = map(int, s.split())",
"+ print(y, x) if x > y else print(s)"
] | false | 0.034473 | 0.034793 | 0.990817 | [
"s037337671",
"s074842659"
] |
u936985471 | p03163 | python | s509474462 | s684540561 | 658 | 328 | 171,912 | 21,700 | Accepted | Accepted | 50.15 | N,W=list(map(int,input().split()))
weight=[0]*N
values=[0]*N
for i in range(N):
weight[i],values[i]=list(map(int,input().split()))
dp=[[0 for i in range(W+1)] for j in range(N+1)]
for i in range(N):
for w in range(W+1):
if w>=weight[i]:
dp[i+1][w]=max(dp[i][w],dp[i][w-weight[i]]+values[i])
else:
dp[i+1][w]=dp[i][w]
print((dp[N][W]))
| n,W=list(map(int,input().split()))
stones=[None]*n
for i in range(n):
w,v=list(map(int,input().split()))
stones[i]=[w,v]
import numpy as np
dp=np.zeros(W+1,dtype=int)
for i in range(len(stones)):
w=stones[i][0]
v=stones[i][1]
np.maximum(dp[:-w]+v,dp[w:],dp[w:])
print((dp.max())) | 16 | 15 | 369 | 292 | N, W = list(map(int, input().split()))
weight = [0] * N
values = [0] * N
for i in range(N):
weight[i], values[i] = list(map(int, input().split()))
dp = [[0 for i in range(W + 1)] for j in range(N + 1)]
for i in range(N):
for w in range(W + 1):
if w >= weight[i]:
dp[i + 1][w] = max(dp[i][w], dp[i][w - weight[i]] + values[i])
else:
dp[i + 1][w] = dp[i][w]
print((dp[N][W]))
| n, W = list(map(int, input().split()))
stones = [None] * n
for i in range(n):
w, v = list(map(int, input().split()))
stones[i] = [w, v]
import numpy as np
dp = np.zeros(W + 1, dtype=int)
for i in range(len(stones)):
w = stones[i][0]
v = stones[i][1]
np.maximum(dp[:-w] + v, dp[w:], dp[w:])
print((dp.max()))
| false | 6.25 | [
"-N, W = list(map(int, input().split()))",
"-weight = [0] * N",
"-values = [0] * N",
"-for i in range(N):",
"- weight[i], values[i] = list(map(int, input().split()))",
"-dp = [[0 for i in range(W + 1)] for j in range(N + 1)]",
"-for i in range(N):",
"- for w in range(W + 1):",
"- if w >= weight[i]:",
"- dp[i + 1][w] = max(dp[i][w], dp[i][w - weight[i]] + values[i])",
"- else:",
"- dp[i + 1][w] = dp[i][w]",
"-print((dp[N][W]))",
"+n, W = list(map(int, input().split()))",
"+stones = [None] * n",
"+for i in range(n):",
"+ w, v = list(map(int, input().split()))",
"+ stones[i] = [w, v]",
"+import numpy as np",
"+",
"+dp = np.zeros(W + 1, dtype=int)",
"+for i in range(len(stones)):",
"+ w = stones[i][0]",
"+ v = stones[i][1]",
"+ np.maximum(dp[:-w] + v, dp[w:], dp[w:])",
"+print((dp.max()))"
] | false | 0.044828 | 0.379138 | 0.118237 | [
"s509474462",
"s684540561"
] |
u729133443 | p03470 | python | s688664100 | s113273036 | 180 | 17 | 38,384 | 2,940 | Accepted | Accepted | 90.56 | print((len(set(open(0).readlines()[1:])))) | _,*s=open(0);print((len(set(s)))) | 1 | 1 | 40 | 31 | print((len(set(open(0).readlines()[1:]))))
| _, *s = open(0)
print((len(set(s))))
| false | 0 | [
"-print((len(set(open(0).readlines()[1:]))))",
"+_, *s = open(0)",
"+print((len(set(s))))"
] | false | 0.119626 | 0.043886 | 2.725808 | [
"s688664100",
"s113273036"
] |
u038408819 | p02726 | python | s485493356 | s428646008 | 1,552 | 649 | 205,832 | 136,200 | Accepted | Accepted | 58.18 | N, X, Y = list(map(int, input().split()))
g = [[] for i in range(N)]
for i in range(N):
u = i
v = i + 1
if v < N:
g[u].append(v)
g[v].append(u)
g[X - 1].append(Y - 1)
g[Y - 1].append(X - 1)
from collections import deque
dis = [[float('Inf')] * N for _ in range(N)]
count = [0] * (N - 1)
def bfs(i):
d = [False] * N
que = deque()
#for j in g[i]:
que.append(i)
d[i] = True
dis[i][i] = 0
pre = i
while que:
p = que.popleft()
for k in g[p]:
if d[k]:
continue
else:
d[k] = True
que.append(k)
dis[i][k] = dis[i][p] + 1
dis[k][i] = dis[i][p] + 1
count[dis[i][k] - 1] += 1
#count[dis[k][i] - 1] += 1
pre = p
for i in range(N):
bfs(i)
for i in range(N - 1):
print((count[i] // 2))
| N, X, Y = list(map(int, input().split()))
g = [[] for i in range(N)]
for i in range(N):
u = i
v = i + 1
if v < N:
g[u].append(v)
g[v].append(u)
g[X - 1].append(Y - 1)
g[Y - 1].append(X - 1)
from collections import deque
dis = [[float('Inf')] * N for _ in range(N)]
count = [0] * (N - 1)
def bfs(i):
d = [False] * N
que = deque()
#for j in g[i]:
que.append(i)
d[i] = True
dis[i][i] = 0
#pre = i
while que:
p = que.popleft()
for k in g[p]:
if d[k]:
continue
else:
d[k] = True
que.append(k)
dis[i][k] = dis[i][p] + 1
#dis[k][i] = dis[i][p] + 1
count[dis[i][k] - 1] += 1
#count[dis[k][i] - 1] += 1
#pre = p
for i in range(N):
bfs(i)
for i in range(N - 1):
print((count[i] // 2))
| 44 | 44 | 943 | 946 | N, X, Y = list(map(int, input().split()))
g = [[] for i in range(N)]
for i in range(N):
u = i
v = i + 1
if v < N:
g[u].append(v)
g[v].append(u)
g[X - 1].append(Y - 1)
g[Y - 1].append(X - 1)
from collections import deque
dis = [[float("Inf")] * N for _ in range(N)]
count = [0] * (N - 1)
def bfs(i):
d = [False] * N
que = deque()
# for j in g[i]:
que.append(i)
d[i] = True
dis[i][i] = 0
pre = i
while que:
p = que.popleft()
for k in g[p]:
if d[k]:
continue
else:
d[k] = True
que.append(k)
dis[i][k] = dis[i][p] + 1
dis[k][i] = dis[i][p] + 1
count[dis[i][k] - 1] += 1
# count[dis[k][i] - 1] += 1
pre = p
for i in range(N):
bfs(i)
for i in range(N - 1):
print((count[i] // 2))
| N, X, Y = list(map(int, input().split()))
g = [[] for i in range(N)]
for i in range(N):
u = i
v = i + 1
if v < N:
g[u].append(v)
g[v].append(u)
g[X - 1].append(Y - 1)
g[Y - 1].append(X - 1)
from collections import deque
dis = [[float("Inf")] * N for _ in range(N)]
count = [0] * (N - 1)
def bfs(i):
d = [False] * N
que = deque()
# for j in g[i]:
que.append(i)
d[i] = True
dis[i][i] = 0
# pre = i
while que:
p = que.popleft()
for k in g[p]:
if d[k]:
continue
else:
d[k] = True
que.append(k)
dis[i][k] = dis[i][p] + 1
# dis[k][i] = dis[i][p] + 1
count[dis[i][k] - 1] += 1
# count[dis[k][i] - 1] += 1
# pre = p
for i in range(N):
bfs(i)
for i in range(N - 1):
print((count[i] // 2))
| false | 0 | [
"- pre = i",
"+ # pre = i",
"- dis[k][i] = dis[i][p] + 1",
"+ # dis[k][i] = dis[i][p] + 1",
"- pre = p",
"+ # pre = p"
] | false | 0.037848 | 0.038218 | 0.990315 | [
"s485493356",
"s428646008"
] |
u629540524 | p02952 | python | s211952983 | s494931596 | 74 | 68 | 73,416 | 68,396 | Accepted | Accepted | 8.11 | n = int(eval(input()))
count= 0
for i in range(1,n+1):
if len(str(i)) == 1 or len(str(i)) == 3 or len(str(i)) == 5:
count+=1
print(count) | n = int(eval(input()))
count= 0
for i in range(1,n+1):
if len(str(i))%2 == 1:
count+=1
print(count) | 6 | 6 | 148 | 110 | n = int(eval(input()))
count = 0
for i in range(1, n + 1):
if len(str(i)) == 1 or len(str(i)) == 3 or len(str(i)) == 5:
count += 1
print(count)
| n = int(eval(input()))
count = 0
for i in range(1, n + 1):
if len(str(i)) % 2 == 1:
count += 1
print(count)
| false | 0 | [
"- if len(str(i)) == 1 or len(str(i)) == 3 or len(str(i)) == 5:",
"+ if len(str(i)) % 2 == 1:"
] | false | 0.052549 | 0.087671 | 0.599397 | [
"s211952983",
"s494931596"
] |
u252883287 | p03855 | python | s931802016 | s858947403 | 1,750 | 1,508 | 43,812 | 46,424 | Accepted | Accepted | 13.83 | class UnionFind(object):
def __init__(self, n):
# 親のnodeを表す
self.par = [i for i in range(n)]
def root(self, x):
if self.par[x] == x:
return x
else:
# 経路圧縮
self.par[x] = self.root(self.par[x])
return self.par[x]
def same(self, x, y):
return self.root(x) == self.root(y)
def union(self, x, y):
x = self.root(x)
y = self.root(y)
if x == y:
return
self.par[x] = y
class UnionFindRank(UnionFind):
def __init__(self, n):
UnionFind.__init__(self, n)
self.rank = [0 for _ in range(n)]
def union(self, x, y):
x = self.root(x)
y = self.root(y)
if x == y:
return
if self.rank[x] < self.rank[y]:
self.par[x] = y
else:
self.par[y] = x
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
def _abc049_d():
"""連結"""
N, K, L = list(map(int, input().split(' ')))
ur = UnionFindRank(N)
for _ in range(K):
p, q = list(map(int, input().split(' ')))
p -= 1
q -= 1
ur.union(p, q)
ut = UnionFindRank(N)
for _ in range(L):
r, s = list(map(int, input().split(' ')))
r -= 1
s -= 1
ut.union(r, s)
def _id(r, t):
return r * 1e8 + t
from collections import defaultdict
d = defaultdict(int)
for i in range(N):
d[_id(ur.root(i), ut.root(i))] += 1
for i in range(N):
print(d[_id(ur.root(i), ut.root(i))], end=' ')
_abc049_d()
| class UnionFind(object):
def __init__(self, n):
# 親のnodeを表す
self.par = [i for i in range(n)]
def root(self, x):
if self.par[x] == x:
return x
else:
# 経路圧縮
self.par[x] = self.root(self.par[x])
return self.par[x]
def same(self, x, y):
return self.root(x) == self.root(y)
def union(self, x, y):
x = self.root(x)
y = self.root(y)
if x == y:
return
self.par[x] = y
class UnionFindRank(UnionFind):
def __init__(self, n):
UnionFind.__init__(self, n)
self.rank = [0 for _ in range(n)]
def union(self, x, y):
x = self.root(x)
y = self.root(y)
if x == y:
return
if self.rank[x] < self.rank[y]:
self.par[x] = y
else:
self.par[y] = x
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
def _abc049_d():
"""連結"""
N, K, L = list(map(int, input().split(' ')))
ur = UnionFindRank(N)
for _ in range(K):
p, q = list(map(int, input().split(' ')))
p -= 1
q -= 1
ur.union(p, q)
ut = UnionFindRank(N)
for _ in range(L):
r, s = list(map(int, input().split(' ')))
r -= 1
s -= 1
ut.union(r, s)
def _id(r, t):
return r * 1e8 + t
from collections import defaultdict
d = defaultdict(int)
ids = []
for i in range(N):
__id = _id(ur.root(i), ut.root(i))
d[__id] += 1
ids.append(__id)
for i in range(N):
print(d[ids[i]], end=' ')
_abc049_d()
| 77 | 80 | 1,694 | 1,734 | class UnionFind(object):
def __init__(self, n):
# 親のnodeを表す
self.par = [i for i in range(n)]
def root(self, x):
if self.par[x] == x:
return x
else:
# 経路圧縮
self.par[x] = self.root(self.par[x])
return self.par[x]
def same(self, x, y):
return self.root(x) == self.root(y)
def union(self, x, y):
x = self.root(x)
y = self.root(y)
if x == y:
return
self.par[x] = y
class UnionFindRank(UnionFind):
def __init__(self, n):
UnionFind.__init__(self, n)
self.rank = [0 for _ in range(n)]
def union(self, x, y):
x = self.root(x)
y = self.root(y)
if x == y:
return
if self.rank[x] < self.rank[y]:
self.par[x] = y
else:
self.par[y] = x
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
def _abc049_d():
"""連結"""
N, K, L = list(map(int, input().split(" ")))
ur = UnionFindRank(N)
for _ in range(K):
p, q = list(map(int, input().split(" ")))
p -= 1
q -= 1
ur.union(p, q)
ut = UnionFindRank(N)
for _ in range(L):
r, s = list(map(int, input().split(" ")))
r -= 1
s -= 1
ut.union(r, s)
def _id(r, t):
return r * 1e8 + t
from collections import defaultdict
d = defaultdict(int)
for i in range(N):
d[_id(ur.root(i), ut.root(i))] += 1
for i in range(N):
print(d[_id(ur.root(i), ut.root(i))], end=" ")
_abc049_d()
| class UnionFind(object):
def __init__(self, n):
# 親のnodeを表す
self.par = [i for i in range(n)]
def root(self, x):
if self.par[x] == x:
return x
else:
# 経路圧縮
self.par[x] = self.root(self.par[x])
return self.par[x]
def same(self, x, y):
return self.root(x) == self.root(y)
def union(self, x, y):
x = self.root(x)
y = self.root(y)
if x == y:
return
self.par[x] = y
class UnionFindRank(UnionFind):
def __init__(self, n):
UnionFind.__init__(self, n)
self.rank = [0 for _ in range(n)]
def union(self, x, y):
x = self.root(x)
y = self.root(y)
if x == y:
return
if self.rank[x] < self.rank[y]:
self.par[x] = y
else:
self.par[y] = x
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
def _abc049_d():
"""連結"""
N, K, L = list(map(int, input().split(" ")))
ur = UnionFindRank(N)
for _ in range(K):
p, q = list(map(int, input().split(" ")))
p -= 1
q -= 1
ur.union(p, q)
ut = UnionFindRank(N)
for _ in range(L):
r, s = list(map(int, input().split(" ")))
r -= 1
s -= 1
ut.union(r, s)
def _id(r, t):
return r * 1e8 + t
from collections import defaultdict
d = defaultdict(int)
ids = []
for i in range(N):
__id = _id(ur.root(i), ut.root(i))
d[__id] += 1
ids.append(__id)
for i in range(N):
print(d[ids[i]], end=" ")
_abc049_d()
| false | 3.75 | [
"+ ids = []",
"- d[_id(ur.root(i), ut.root(i))] += 1",
"+ __id = _id(ur.root(i), ut.root(i))",
"+ d[__id] += 1",
"+ ids.append(__id)",
"- print(d[_id(ur.root(i), ut.root(i))], end=\" \")",
"+ print(d[ids[i]], end=\" \")"
] | false | 0.040695 | 0.040009 | 1.017135 | [
"s931802016",
"s858947403"
] |
u260980560 | p00437 | python | s442369537 | s051943785 | 30 | 20 | 4,296 | 4,284 | Accepted | Accepted | 33.33 | while 1:
a, b, c = list(map(int, input().split()))
if not a:
break
n = eval(input())
I = []; J = []; K = []
res = [2]*(a+b+c)
for p in range(n):
i, j, k, r = list(map(int, input().split()))
i -= 1; j -= 1; k -= 1
if r:
res[i] = res[j] = res[k] = 1
else:
I.append(i); J.append(j); K.append(k)
for p in range(len(I)):
i, j, k = I[p], J[p], K[p]
if res[i]==res[j]==res[k]==1:
continue
if res[i]==res[j]==1:
res[k] = 0
elif res[j]==res[k]==1:
res[i] = 0
elif res[k]==res[i]==1:
res[j] = 0
for i in range(a+b+c):
print(res[i]) | while 1:
a, b, c = list(map(int, input().split()))
if not a:
break
I = []
res = [2]*(a+b+c)
for p in range(int(input())):
i, j, k, r = list(map(int, input().split()))
i -= 1; j -= 1; k -= 1
if r:
res[i] = res[j] = res[k] = 1
else:
I.append((i, j, k))
for e in I:
i, j, k = e
if res[i]+res[j]+res[k]!=4:
continue
if res[i]==2:
res[i] = -1
elif res[j]==2:
res[j] = -1
else:
res[k] = -1
for i in range(a+b+c):
print(res[i] if res[i]>=0 else 0) | 27 | 25 | 732 | 653 | while 1:
a, b, c = list(map(int, input().split()))
if not a:
break
n = eval(input())
I = []
J = []
K = []
res = [2] * (a + b + c)
for p in range(n):
i, j, k, r = list(map(int, input().split()))
i -= 1
j -= 1
k -= 1
if r:
res[i] = res[j] = res[k] = 1
else:
I.append(i)
J.append(j)
K.append(k)
for p in range(len(I)):
i, j, k = I[p], J[p], K[p]
if res[i] == res[j] == res[k] == 1:
continue
if res[i] == res[j] == 1:
res[k] = 0
elif res[j] == res[k] == 1:
res[i] = 0
elif res[k] == res[i] == 1:
res[j] = 0
for i in range(a + b + c):
print(res[i])
| while 1:
a, b, c = list(map(int, input().split()))
if not a:
break
I = []
res = [2] * (a + b + c)
for p in range(int(input())):
i, j, k, r = list(map(int, input().split()))
i -= 1
j -= 1
k -= 1
if r:
res[i] = res[j] = res[k] = 1
else:
I.append((i, j, k))
for e in I:
i, j, k = e
if res[i] + res[j] + res[k] != 4:
continue
if res[i] == 2:
res[i] = -1
elif res[j] == 2:
res[j] = -1
else:
res[k] = -1
for i in range(a + b + c):
print(res[i] if res[i] >= 0 else 0)
| false | 7.407407 | [
"- n = eval(input())",
"- J = []",
"- K = []",
"- for p in range(n):",
"+ for p in range(int(input())):",
"- I.append(i)",
"- J.append(j)",
"- K.append(k)",
"- for p in range(len(I)):",
"- i, j, k = I[p], J[p], K[p]",
"- if res[i] == res[j] == res[k] == 1:",
"+ I.append((i, j, k))",
"+ for e in I:",
"+ i, j, k = e",
"+ if res[i] + res[j] + res[k] != 4:",
"- if res[i] == res[j] == 1:",
"- res[k] = 0",
"- elif res[j] == res[k] == 1:",
"- res[i] = 0",
"- elif res[k] == res[i] == 1:",
"- res[j] = 0",
"+ if res[i] == 2:",
"+ res[i] = -1",
"+ elif res[j] == 2:",
"+ res[j] = -1",
"+ else:",
"+ res[k] = -1",
"- print(res[i])",
"+ print(res[i] if res[i] >= 0 else 0)"
] | false | 0.069128 | 0.067546 | 1.02342 | [
"s442369537",
"s051943785"
] |
u600402037 | p03044 | python | s259897066 | s598148719 | 688 | 563 | 76,464 | 41,796 | Accepted | Accepted | 18.17 | import sys
sys.setrecursionlimit(10**6)
N = int(eval(input()))
edges = [[] for _ in range(N)]
for _ in range(N-1):
u, v, w = list(map(int, input().split()))
if w&1:
edges[u-1].append((v-1, -1))
edges[v-1].append((u-1, -1))
else:
edges[u-1].append((v-1, 1))
edges[v-1].append((u-1, 1))
colors = [None] * N
def set_color(x, c):
colors[x] = c
for y, sgn in edges[x]:
if colors[y] == None:
set_color(y, c*sgn)
set_color(0, 1)
for z in colors:
print(((z+1)//2))
| # coding: utf-8
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N = ir()
graph = [[] for _ in range(N+1)] # 1-indexed
for _ in range(N-1):
a, b, w = lr()
graph[a].append((b, w%2))
graph[b].append((a, w%2))
color = [None] * (N+1)
color[1] = 0
root = 1
parent = [0] * (N+1)
stack = [(root, 0)]
while stack:
cur, c = stack.pop()
for next, weight in graph[cur]:
if next == parent[cur]:
continue
parent[next] = cur
if weight == 0:
color[next] = c
else:
color[next] = 1 - c
stack.append((next, color[next]))
print(*color[1:], sep='\n')
| 26 | 32 | 549 | 732 | import sys
sys.setrecursionlimit(10**6)
N = int(eval(input()))
edges = [[] for _ in range(N)]
for _ in range(N - 1):
u, v, w = list(map(int, input().split()))
if w & 1:
edges[u - 1].append((v - 1, -1))
edges[v - 1].append((u - 1, -1))
else:
edges[u - 1].append((v - 1, 1))
edges[v - 1].append((u - 1, 1))
colors = [None] * N
def set_color(x, c):
colors[x] = c
for y, sgn in edges[x]:
if colors[y] == None:
set_color(y, c * sgn)
set_color(0, 1)
for z in colors:
print(((z + 1) // 2))
| # coding: utf-8
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N = ir()
graph = [[] for _ in range(N + 1)] # 1-indexed
for _ in range(N - 1):
a, b, w = lr()
graph[a].append((b, w % 2))
graph[b].append((a, w % 2))
color = [None] * (N + 1)
color[1] = 0
root = 1
parent = [0] * (N + 1)
stack = [(root, 0)]
while stack:
cur, c = stack.pop()
for next, weight in graph[cur]:
if next == parent[cur]:
continue
parent[next] = cur
if weight == 0:
color[next] = c
else:
color[next] = 1 - c
stack.append((next, color[next]))
print(*color[1:], sep="\n")
| false | 18.75 | [
"+# coding: utf-8",
"-sys.setrecursionlimit(10**6)",
"-N = int(eval(input()))",
"-edges = [[] for _ in range(N)]",
"+sr = lambda: sys.stdin.readline().rstrip()",
"+ir = lambda: int(sr())",
"+lr = lambda: list(map(int, sr().split()))",
"+N = ir()",
"+graph = [[] for _ in range(N + 1)] # 1-indexed",
"- u, v, w = list(map(int, input().split()))",
"- if w & 1:",
"- edges[u - 1].append((v - 1, -1))",
"- edges[v - 1].append((u - 1, -1))",
"- else:",
"- edges[u - 1].append((v - 1, 1))",
"- edges[v - 1].append((u - 1, 1))",
"-colors = [None] * N",
"-",
"-",
"-def set_color(x, c):",
"- colors[x] = c",
"- for y, sgn in edges[x]:",
"- if colors[y] == None:",
"- set_color(y, c * sgn)",
"-",
"-",
"-set_color(0, 1)",
"-for z in colors:",
"- print(((z + 1) // 2))",
"+ a, b, w = lr()",
"+ graph[a].append((b, w % 2))",
"+ graph[b].append((a, w % 2))",
"+color = [None] * (N + 1)",
"+color[1] = 0",
"+root = 1",
"+parent = [0] * (N + 1)",
"+stack = [(root, 0)]",
"+while stack:",
"+ cur, c = stack.pop()",
"+ for next, weight in graph[cur]:",
"+ if next == parent[cur]:",
"+ continue",
"+ parent[next] = cur",
"+ if weight == 0:",
"+ color[next] = c",
"+ else:",
"+ color[next] = 1 - c",
"+ stack.append((next, color[next]))",
"+print(*color[1:], sep=\"\\n\")"
] | false | 0.036081 | 0.036306 | 0.99378 | [
"s259897066",
"s598148719"
] |
u588341295 | p02787 | python | s229878786 | s398888350 | 918 | 624 | 191,512 | 41,452 | Accepted | Accepted | 32.03 | # -*- coding: utf-8 -*-
import sys
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7
H, N = MAP()
AB = [()]
for i in range(N):
a, b = MAP()
AB.append((a, b))
dp = list2d(N+1, 20007, INF)
dp[0][0] = 0
for i in range(1, N+1):
a, b = AB[i]
for j in range(20007):
dp[i][j] = min(dp[i][j], dp[i-1][j])
if j-a >= 0:
dp[i][j] = min(dp[i][j], dp[i][j-a] + b, dp[i-1][j-a] + b)
print((min(dp[N][H:])))
| # -*- coding: utf-8 -*-
import sys
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7
H, N = MAP()
AB = []
for i in range(N):
a, b = MAP()
AB.append((a, b))
dp = [INF] * 20007
dp[0] = 0
for i in range(20007):
for a, b in AB:
if i-a >= 0:
dp[i] = min(dp[i], dp[i-a] + b)
ans = min(dp[H:])
print(ans)
| 35 | 34 | 1,062 | 956 | # -*- coding: utf-8 -*-
import sys
def input():
return sys.stdin.readline().strip()
def list2d(a, b, c):
return [[c] * b for i in range(a)]
def list3d(a, b, c, d):
return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e):
return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1):
return int(-(-x // y))
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST(N=None):
return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes():
print("Yes")
def No():
print("No")
def YES():
print("YES")
def NO():
print("NO")
sys.setrecursionlimit(10**9)
INF = 10**18
MOD = 10**9 + 7
H, N = MAP()
AB = [()]
for i in range(N):
a, b = MAP()
AB.append((a, b))
dp = list2d(N + 1, 20007, INF)
dp[0][0] = 0
for i in range(1, N + 1):
a, b = AB[i]
for j in range(20007):
dp[i][j] = min(dp[i][j], dp[i - 1][j])
if j - a >= 0:
dp[i][j] = min(dp[i][j], dp[i][j - a] + b, dp[i - 1][j - a] + b)
print((min(dp[N][H:])))
| # -*- coding: utf-8 -*-
import sys
def input():
return sys.stdin.readline().strip()
def list2d(a, b, c):
return [[c] * b for i in range(a)]
def list3d(a, b, c, d):
return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e):
return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1):
return int(-(-x // y))
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST(N=None):
return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes():
print("Yes")
def No():
print("No")
def YES():
print("YES")
def NO():
print("NO")
sys.setrecursionlimit(10**9)
INF = 10**18
MOD = 10**9 + 7
H, N = MAP()
AB = []
for i in range(N):
a, b = MAP()
AB.append((a, b))
dp = [INF] * 20007
dp[0] = 0
for i in range(20007):
for a, b in AB:
if i - a >= 0:
dp[i] = min(dp[i], dp[i - a] + b)
ans = min(dp[H:])
print(ans)
| false | 2.857143 | [
"-AB = [()]",
"+AB = []",
"-dp = list2d(N + 1, 20007, INF)",
"-dp[0][0] = 0",
"-for i in range(1, N + 1):",
"- a, b = AB[i]",
"- for j in range(20007):",
"- dp[i][j] = min(dp[i][j], dp[i - 1][j])",
"- if j - a >= 0:",
"- dp[i][j] = min(dp[i][j], dp[i][j - a] + b, dp[i - 1][j - a] + b)",
"-print((min(dp[N][H:])))",
"+dp = [INF] * 20007",
"+dp[0] = 0",
"+for i in range(20007):",
"+ for a, b in AB:",
"+ if i - a >= 0:",
"+ dp[i] = min(dp[i], dp[i - a] + b)",
"+ans = min(dp[H:])",
"+print(ans)"
] | false | 0.37418 | 0.135577 | 2.759914 | [
"s229878786",
"s398888350"
] |
u977661421 | p02761 | python | s122839724 | s286750994 | 20 | 18 | 3,064 | 3,060 | Accepted | Accepted | 10 | # -*- coding: utf-8 -*-
n, m = list(map(int,input().split()))
sc = []
for i in range(m):
sc.append([int(i) for i in input().split()])
if n == 1:
if m == 1:
print((sc[0][1]))
if m == 0:
print((0))
if m >= 2:
print((-1))
if n == 2:
count = 0
for i in range(10, 100):
tmp1 = i // 10
tmp2 = i - (tmp1 * 10)
flag = True
for j in range(m):
if sc[j][0] == 1 and sc[j][1] != tmp1:
flag = False
if sc[j][0] == 2 and sc[j][1] != tmp2:
flag = False
if flag:
print(i)
break
else:
count += 1
if count == 90:
print((-1))
if n == 3:
count = 0
for i in range(100, 1000):
tmp1 = i // 100
tmp2 = (i - (tmp1 * 100)) // 10
tmp3 = i - tmp1 * 100 - tmp2 * 10
flag = True
for j in range(m):
if sc[j][0] == 1 and sc[j][1] != tmp1:
flag = False
if sc[j][0] == 2 and sc[j][1] != tmp2:
flag = False
if sc[j][0] == 3 and sc[j][1] != tmp3:
flag = False
if flag:
print(i)
break
else:
count += 1
if count == 900:
print((-1))
| # -*- coding: utf-8 -*-
n, m = list(map(int,input().split()))
sc = []
for i in range(m):
sc.append([int(i) for i in input().split()])
for i in range(0, 1000):
i = str(i)
if len(i) != n:
continue
flag = True
for j in range(m):
#print(i, i[sc[j][0] - 1], sc[j][1])
if i[sc[j][0] - 1] != str(sc[j][1]):
flag = False
if flag:
print(i)
exit()
print((-1))
| 52 | 19 | 1,328 | 437 | # -*- coding: utf-8 -*-
n, m = list(map(int, input().split()))
sc = []
for i in range(m):
sc.append([int(i) for i in input().split()])
if n == 1:
if m == 1:
print((sc[0][1]))
if m == 0:
print((0))
if m >= 2:
print((-1))
if n == 2:
count = 0
for i in range(10, 100):
tmp1 = i // 10
tmp2 = i - (tmp1 * 10)
flag = True
for j in range(m):
if sc[j][0] == 1 and sc[j][1] != tmp1:
flag = False
if sc[j][0] == 2 and sc[j][1] != tmp2:
flag = False
if flag:
print(i)
break
else:
count += 1
if count == 90:
print((-1))
if n == 3:
count = 0
for i in range(100, 1000):
tmp1 = i // 100
tmp2 = (i - (tmp1 * 100)) // 10
tmp3 = i - tmp1 * 100 - tmp2 * 10
flag = True
for j in range(m):
if sc[j][0] == 1 and sc[j][1] != tmp1:
flag = False
if sc[j][0] == 2 and sc[j][1] != tmp2:
flag = False
if sc[j][0] == 3 and sc[j][1] != tmp3:
flag = False
if flag:
print(i)
break
else:
count += 1
if count == 900:
print((-1))
| # -*- coding: utf-8 -*-
n, m = list(map(int, input().split()))
sc = []
for i in range(m):
sc.append([int(i) for i in input().split()])
for i in range(0, 1000):
i = str(i)
if len(i) != n:
continue
flag = True
for j in range(m):
# print(i, i[sc[j][0] - 1], sc[j][1])
if i[sc[j][0] - 1] != str(sc[j][1]):
flag = False
if flag:
print(i)
exit()
print((-1))
| false | 63.461538 | [
"-if n == 1:",
"- if m == 1:",
"- print((sc[0][1]))",
"- if m == 0:",
"- print((0))",
"- if m >= 2:",
"- print((-1))",
"-if n == 2:",
"- count = 0",
"- for i in range(10, 100):",
"- tmp1 = i // 10",
"- tmp2 = i - (tmp1 * 10)",
"- flag = True",
"- for j in range(m):",
"- if sc[j][0] == 1 and sc[j][1] != tmp1:",
"- flag = False",
"- if sc[j][0] == 2 and sc[j][1] != tmp2:",
"- flag = False",
"- if flag:",
"- print(i)",
"- break",
"- else:",
"- count += 1",
"- if count == 90:",
"- print((-1))",
"-if n == 3:",
"- count = 0",
"- for i in range(100, 1000):",
"- tmp1 = i // 100",
"- tmp2 = (i - (tmp1 * 100)) // 10",
"- tmp3 = i - tmp1 * 100 - tmp2 * 10",
"- flag = True",
"- for j in range(m):",
"- if sc[j][0] == 1 and sc[j][1] != tmp1:",
"- flag = False",
"- if sc[j][0] == 2 and sc[j][1] != tmp2:",
"- flag = False",
"- if sc[j][0] == 3 and sc[j][1] != tmp3:",
"- flag = False",
"- if flag:",
"- print(i)",
"- break",
"- else:",
"- count += 1",
"- if count == 900:",
"- print((-1))",
"+for i in range(0, 1000):",
"+ i = str(i)",
"+ if len(i) != n:",
"+ continue",
"+ flag = True",
"+ for j in range(m):",
"+ # print(i, i[sc[j][0] - 1], sc[j][1])",
"+ if i[sc[j][0] - 1] != str(sc[j][1]):",
"+ flag = False",
"+ if flag:",
"+ print(i)",
"+ exit()",
"+print((-1))"
] | false | 0.007467 | 0.039377 | 0.189621 | [
"s122839724",
"s286750994"
] |
u608088992 | p03805 | python | s817266348 | s998277399 | 69 | 27 | 3,064 | 9,200 | Accepted | Accepted | 60.87 | import sys
from itertools import permutations
def solve():
input = sys.stdin.readline
N, M = list(map(int, input().split()))
Edge = [[] for _ in range(N)]
for _ in range(M):
a, b = list(map(int, input().split()))
Edge[a-1].append(b-1)
Edge[b-1].append(a-1)
count = 0
for s in permutations(list(range(N)), N):
Visited = [False for _ in range(N)]
for i, n in enumerate(s):
if i == 0:
if n != 0: break
else: Visited[0] = True
else:
if n in Edge[s[i-1]]: Visited[n] = True
else: break
else: count += 1
print(count)
return 0
if __name__ == "__main__":
solve() | import sys
from itertools import permutations
def solve():
N, M = list(map(int, input().split()))
Edge = [[] for _ in range(N)]
for _ in range(M):
a, b = list(map(int, input().split()))
Edge[a-1].append(b-1)
Edge[b-1].append(a-1)
count = 0
for order in permutations(list(range(N))):
if order[0] != 0: continue
for i in range(N-1):
if order[i+1] not in Edge[order[i]]: break
else: count += 1
print(count)
return 0
if __name__ == "__main__":
solve() | 29 | 22 | 740 | 545 | import sys
from itertools import permutations
def solve():
input = sys.stdin.readline
N, M = list(map(int, input().split()))
Edge = [[] for _ in range(N)]
for _ in range(M):
a, b = list(map(int, input().split()))
Edge[a - 1].append(b - 1)
Edge[b - 1].append(a - 1)
count = 0
for s in permutations(list(range(N)), N):
Visited = [False for _ in range(N)]
for i, n in enumerate(s):
if i == 0:
if n != 0:
break
else:
Visited[0] = True
else:
if n in Edge[s[i - 1]]:
Visited[n] = True
else:
break
else:
count += 1
print(count)
return 0
if __name__ == "__main__":
solve()
| import sys
from itertools import permutations
def solve():
N, M = list(map(int, input().split()))
Edge = [[] for _ in range(N)]
for _ in range(M):
a, b = list(map(int, input().split()))
Edge[a - 1].append(b - 1)
Edge[b - 1].append(a - 1)
count = 0
for order in permutations(list(range(N))):
if order[0] != 0:
continue
for i in range(N - 1):
if order[i + 1] not in Edge[order[i]]:
break
else:
count += 1
print(count)
return 0
if __name__ == "__main__":
solve()
| false | 24.137931 | [
"- input = sys.stdin.readline",
"- for s in permutations(list(range(N)), N):",
"- Visited = [False for _ in range(N)]",
"- for i, n in enumerate(s):",
"- if i == 0:",
"- if n != 0:",
"- break",
"- else:",
"- Visited[0] = True",
"- else:",
"- if n in Edge[s[i - 1]]:",
"- Visited[n] = True",
"- else:",
"- break",
"+ for order in permutations(list(range(N))):",
"+ if order[0] != 0:",
"+ continue",
"+ for i in range(N - 1):",
"+ if order[i + 1] not in Edge[order[i]]:",
"+ break"
] | false | 0.042956 | 0.168213 | 0.255367 | [
"s817266348",
"s998277399"
] |
u644907318 | p02720 | python | s725776477 | s872057730 | 430 | 110 | 60,400 | 88,684 | Accepted | Accepted | 74.42 | def f(N): # N is string
k = len(N)
dp = [[[[0 for _ in range(10)] for _ in range(2)] for _ in range(2)] for _ in range(k+1)]
for j in range(10):
dp[1][0][0][j]=(j==int(N[0]))
dp[1][0][1][j]=0
dp[1][1][0][j]=(j<int(N[0]))
dp[1][1][1][j]=0
for i in range(2,k+1):
for j in range(10):
for m in range(10):
dp[i][0][1][j] += (dp[i-1][0][0][m]+dp[i-1][0][1][m])*(abs(m-j)<=1)*(j==int(N[i-1]))
dp[i][1][0][j]=1
for m in range(10):
dp[i][1][1][j] += (dp[i-1][0][0][m]+dp[i-1][0][1][m])*(abs(m-j)<=1)*(j<int(N[i-1]))\
+dp[i-1][1][1][m]*(abs(m-j)<=1)
for m in range(1,10):
dp[i][1][1][j] += dp[i-1][1][0][m]*(abs(m-j)<=1)
cnt = 0
for j in range(10):
cnt += dp[k][0][0][j]+dp[k][0][1][j]+dp[k][1][0][j]+dp[k][1][1][j]
return cnt-1
K = int(input())
low = 0
high = 4*10**9
while high-low>1:
mid = (high+low)//2
n = f(str(mid))
if n<K:
low = mid
elif n>=K:
high = mid
print(high)
| from collections import deque
K = int(eval(input()))
A = deque([str(i) for i in range(1,10)])
cnt = 0
while cnt<K:
a = A.popleft()
cnt += 1
if a[-1]=="0":
a0 = a+"0"
a1 = a+"1"
A.append(a0)
A.append(a1)
elif a[-1]=="9":
a0 = a+"8"
a1 = a+"9"
A.append(a0)
A.append(a1)
else:
b = a[-1]
a0 = a+str(int(b)-1)
a1 = a+b
a2 = a+str(int(b)+1)
A.append(a0)
A.append(a1)
A.append(a2)
print(a) | 33 | 26 | 1,136 | 541 | def f(N): # N is string
k = len(N)
dp = [
[[[0 for _ in range(10)] for _ in range(2)] for _ in range(2)]
for _ in range(k + 1)
]
for j in range(10):
dp[1][0][0][j] = j == int(N[0])
dp[1][0][1][j] = 0
dp[1][1][0][j] = j < int(N[0])
dp[1][1][1][j] = 0
for i in range(2, k + 1):
for j in range(10):
for m in range(10):
dp[i][0][1][j] += (
(dp[i - 1][0][0][m] + dp[i - 1][0][1][m])
* (abs(m - j) <= 1)
* (j == int(N[i - 1]))
)
dp[i][1][0][j] = 1
for m in range(10):
dp[i][1][1][j] += (dp[i - 1][0][0][m] + dp[i - 1][0][1][m]) * (
abs(m - j) <= 1
) * (j < int(N[i - 1])) + dp[i - 1][1][1][m] * (abs(m - j) <= 1)
for m in range(1, 10):
dp[i][1][1][j] += dp[i - 1][1][0][m] * (abs(m - j) <= 1)
cnt = 0
for j in range(10):
cnt += dp[k][0][0][j] + dp[k][0][1][j] + dp[k][1][0][j] + dp[k][1][1][j]
return cnt - 1
K = int(input())
low = 0
high = 4 * 10**9
while high - low > 1:
mid = (high + low) // 2
n = f(str(mid))
if n < K:
low = mid
elif n >= K:
high = mid
print(high)
| from collections import deque
K = int(eval(input()))
A = deque([str(i) for i in range(1, 10)])
cnt = 0
while cnt < K:
a = A.popleft()
cnt += 1
if a[-1] == "0":
a0 = a + "0"
a1 = a + "1"
A.append(a0)
A.append(a1)
elif a[-1] == "9":
a0 = a + "8"
a1 = a + "9"
A.append(a0)
A.append(a1)
else:
b = a[-1]
a0 = a + str(int(b) - 1)
a1 = a + b
a2 = a + str(int(b) + 1)
A.append(a0)
A.append(a1)
A.append(a2)
print(a)
| false | 21.212121 | [
"-def f(N): # N is string",
"- k = len(N)",
"- dp = [",
"- [[[0 for _ in range(10)] for _ in range(2)] for _ in range(2)]",
"- for _ in range(k + 1)",
"- ]",
"- for j in range(10):",
"- dp[1][0][0][j] = j == int(N[0])",
"- dp[1][0][1][j] = 0",
"- dp[1][1][0][j] = j < int(N[0])",
"- dp[1][1][1][j] = 0",
"- for i in range(2, k + 1):",
"- for j in range(10):",
"- for m in range(10):",
"- dp[i][0][1][j] += (",
"- (dp[i - 1][0][0][m] + dp[i - 1][0][1][m])",
"- * (abs(m - j) <= 1)",
"- * (j == int(N[i - 1]))",
"- )",
"- dp[i][1][0][j] = 1",
"- for m in range(10):",
"- dp[i][1][1][j] += (dp[i - 1][0][0][m] + dp[i - 1][0][1][m]) * (",
"- abs(m - j) <= 1",
"- ) * (j < int(N[i - 1])) + dp[i - 1][1][1][m] * (abs(m - j) <= 1)",
"- for m in range(1, 10):",
"- dp[i][1][1][j] += dp[i - 1][1][0][m] * (abs(m - j) <= 1)",
"- cnt = 0",
"- for j in range(10):",
"- cnt += dp[k][0][0][j] + dp[k][0][1][j] + dp[k][1][0][j] + dp[k][1][1][j]",
"- return cnt - 1",
"+from collections import deque",
"-",
"-K = int(input())",
"-low = 0",
"-high = 4 * 10**9",
"-while high - low > 1:",
"- mid = (high + low) // 2",
"- n = f(str(mid))",
"- if n < K:",
"- low = mid",
"- elif n >= K:",
"- high = mid",
"-print(high)",
"+K = int(eval(input()))",
"+A = deque([str(i) for i in range(1, 10)])",
"+cnt = 0",
"+while cnt < K:",
"+ a = A.popleft()",
"+ cnt += 1",
"+ if a[-1] == \"0\":",
"+ a0 = a + \"0\"",
"+ a1 = a + \"1\"",
"+ A.append(a0)",
"+ A.append(a1)",
"+ elif a[-1] == \"9\":",
"+ a0 = a + \"8\"",
"+ a1 = a + \"9\"",
"+ A.append(a0)",
"+ A.append(a1)",
"+ else:",
"+ b = a[-1]",
"+ a0 = a + str(int(b) - 1)",
"+ a1 = a + b",
"+ a2 = a + str(int(b) + 1)",
"+ A.append(a0)",
"+ A.append(a1)",
"+ A.append(a2)",
"+print(a)"
] | false | 0.06787 | 0.056915 | 1.192471 | [
"s725776477",
"s872057730"
] |
u103902792 | p03835 | python | s587707771 | s128434482 | 1,857 | 1,459 | 2,940 | 2,940 | Accepted | Accepted | 21.43 | k,s = list(map(int,input().split()))
x=y=z=0
count = 0
for i in range(min(k,s)+1):
for j in range(min(k,s)+1):
z = s-x-y
if 0 <= z <= k:
count += 1
y += 1
y = 0
x +=1
print(count)
| k,s = list(map(int,input().split()))
count = 0
for x in range(k+1):
for y in range(k+1):
z = s-x-y
if 0 <= z <= k:
count += 1
print(count) | 12 | 9 | 209 | 157 | k, s = list(map(int, input().split()))
x = y = z = 0
count = 0
for i in range(min(k, s) + 1):
for j in range(min(k, s) + 1):
z = s - x - y
if 0 <= z <= k:
count += 1
y += 1
y = 0
x += 1
print(count)
| k, s = list(map(int, input().split()))
count = 0
for x in range(k + 1):
for y in range(k + 1):
z = s - x - y
if 0 <= z <= k:
count += 1
print(count)
| false | 25 | [
"-x = y = z = 0",
"-for i in range(min(k, s) + 1):",
"- for j in range(min(k, s) + 1):",
"+for x in range(k + 1):",
"+ for y in range(k + 1):",
"- y += 1",
"- y = 0",
"- x += 1"
] | false | 0.040503 | 0.040452 | 1.00126 | [
"s587707771",
"s128434482"
] |
u159994501 | p03448 | python | s612742755 | s492249832 | 66 | 49 | 3,064 | 3,060 | Accepted | Accepted | 25.76 | A=int(eval(input()))
B=int(eval(input()))
C=int(eval(input()))
X=int(eval(input()))
a=0
b=0
c=0
count = 0
while a*500<=X and a<=A:
while a*500+b*100<=X and b<=B:
while a*500+b*100+c * 50 <=X and c<=C:
if a*500+b*100+c*50==X:
#print(a,b,c)
count+=1
break
else:
#print(a,a,b,c)
c+=1
c=0
b+=1
#print(b,c)
a+=1
b=0
c=0
#print(a,b,c)
print(count)
| A = int(eval(input()))
B = int(eval(input()))
C = int(eval(input()))
X = int(eval(input()))
ans = 0
for i in range(A + 1):
for j in range(B + 1):
for k in range(C + 1):
if 500 * i + 100 * j + 50 * k == X:
ans += 1
print(ans)
| 26 | 12 | 499 | 253 | A = int(eval(input()))
B = int(eval(input()))
C = int(eval(input()))
X = int(eval(input()))
a = 0
b = 0
c = 0
count = 0
while a * 500 <= X and a <= A:
while a * 500 + b * 100 <= X and b <= B:
while a * 500 + b * 100 + c * 50 <= X and c <= C:
if a * 500 + b * 100 + c * 50 == X:
# print(a,b,c)
count += 1
break
else:
# print(a,a,b,c)
c += 1
c = 0
b += 1
# print(b,c)
a += 1
b = 0
c = 0
# print(a,b,c)
print(count)
| A = int(eval(input()))
B = int(eval(input()))
C = int(eval(input()))
X = int(eval(input()))
ans = 0
for i in range(A + 1):
for j in range(B + 1):
for k in range(C + 1):
if 500 * i + 100 * j + 50 * k == X:
ans += 1
print(ans)
| false | 53.846154 | [
"-a = 0",
"-b = 0",
"-c = 0",
"-count = 0",
"-while a * 500 <= X and a <= A:",
"- while a * 500 + b * 100 <= X and b <= B:",
"- while a * 500 + b * 100 + c * 50 <= X and c <= C:",
"- if a * 500 + b * 100 + c * 50 == X:",
"- # print(a,b,c)",
"- count += 1",
"- break",
"- else:",
"- # print(a,a,b,c)",
"- c += 1",
"- c = 0",
"- b += 1",
"- # print(b,c)",
"- a += 1",
"- b = 0",
"- c = 0",
"- # print(a,b,c)",
"-print(count)",
"+ans = 0",
"+for i in range(A + 1):",
"+ for j in range(B + 1):",
"+ for k in range(C + 1):",
"+ if 500 * i + 100 * j + 50 * k == X:",
"+ ans += 1",
"+print(ans)"
] | false | 0.102413 | 0.382979 | 0.267412 | [
"s612742755",
"s492249832"
] |
u983918956 | p03569 | python | s160416561 | s406041928 | 106 | 65 | 4,212 | 3,316 | Accepted | Accepted | 38.68 | from collections import deque
s = deque(eval(input()))
ans = 0
while len(s) >= 2:
if s[0] == s[-1]:
s.popleft()
s.pop()
elif s[0] == "x":
s.append("x")
ans += 1
elif s[-1] == "x":
s.appendleft("x")
ans += 1
else:
ans = -1
break
print(ans) | s = eval(input())
l = 0
r = len(s)-1
ans = 0
while r-l >= 1:
if s[l] == s[r]:
l += 1
r -= 1
elif s[l] == "x":
l += 1
ans += 1
elif s[r] == "x":
r -= 1
ans += 1
else:
ans = -1
break
print(ans) | 21 | 21 | 336 | 288 | from collections import deque
s = deque(eval(input()))
ans = 0
while len(s) >= 2:
if s[0] == s[-1]:
s.popleft()
s.pop()
elif s[0] == "x":
s.append("x")
ans += 1
elif s[-1] == "x":
s.appendleft("x")
ans += 1
else:
ans = -1
break
print(ans)
| s = eval(input())
l = 0
r = len(s) - 1
ans = 0
while r - l >= 1:
if s[l] == s[r]:
l += 1
r -= 1
elif s[l] == "x":
l += 1
ans += 1
elif s[r] == "x":
r -= 1
ans += 1
else:
ans = -1
break
print(ans)
| false | 0 | [
"-from collections import deque",
"-",
"-s = deque(eval(input()))",
"+s = eval(input())",
"+l = 0",
"+r = len(s) - 1",
"-while len(s) >= 2:",
"- if s[0] == s[-1]:",
"- s.popleft()",
"- s.pop()",
"- elif s[0] == \"x\":",
"- s.append(\"x\")",
"+while r - l >= 1:",
"+ if s[l] == s[r]:",
"+ l += 1",
"+ r -= 1",
"+ elif s[l] == \"x\":",
"+ l += 1",
"- elif s[-1] == \"x\":",
"- s.appendleft(\"x\")",
"+ elif s[r] == \"x\":",
"+ r -= 1"
] | false | 0.089898 | 0.035144 | 2.558036 | [
"s160416561",
"s406041928"
] |
u073852194 | p02973 | python | s548704148 | s722432116 | 601 | 115 | 53,592 | 85,372 | Accepted | Accepted | 80.87 | import bisect
from collections import deque
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
LDS = deque()
LDS.append(A[0])
for i in range(1,N):
if LDS[0] >= A[i]:
LDS.appendleft(A[i])
else:
LDS[bisect.bisect_left(LDS,A[i])-1] = A[i]
print((len(LDS))) | from bisect import bisect_left, bisect_right
def LIS(arr): #bisect.bisect_left
n = len(arr)
lis = [arr[0]]
for a in arr:
if a > lis[-1]:
lis.append(a)
else:
lis[bisect_left(lis, a)] = a
return len(lis)
import sys
input = sys.stdin.readline
N = int(eval(input()))
A = []
for i in range(N):
A.append((-int(eval(input())), i))
print((LIS(A)))
| 16 | 22 | 297 | 413 | import bisect
from collections import deque
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
LDS = deque()
LDS.append(A[0])
for i in range(1, N):
if LDS[0] >= A[i]:
LDS.appendleft(A[i])
else:
LDS[bisect.bisect_left(LDS, A[i]) - 1] = A[i]
print((len(LDS)))
| from bisect import bisect_left, bisect_right
def LIS(arr): # bisect.bisect_left
n = len(arr)
lis = [arr[0]]
for a in arr:
if a > lis[-1]:
lis.append(a)
else:
lis[bisect_left(lis, a)] = a
return len(lis)
import sys
input = sys.stdin.readline
N = int(eval(input()))
A = []
for i in range(N):
A.append((-int(eval(input())), i))
print((LIS(A)))
| false | 27.272727 | [
"-import bisect",
"-from collections import deque",
"+from bisect import bisect_left, bisect_right",
"+",
"+def LIS(arr): # bisect.bisect_left",
"+ n = len(arr)",
"+ lis = [arr[0]]",
"+ for a in arr:",
"+ if a > lis[-1]:",
"+ lis.append(a)",
"+ else:",
"+ lis[bisect_left(lis, a)] = a",
"+ return len(lis)",
"+",
"+",
"+import sys",
"+",
"+input = sys.stdin.readline",
"-A = [int(eval(input())) for _ in range(N)]",
"-LDS = deque()",
"-LDS.append(A[0])",
"-for i in range(1, N):",
"- if LDS[0] >= A[i]:",
"- LDS.appendleft(A[i])",
"- else:",
"- LDS[bisect.bisect_left(LDS, A[i]) - 1] = A[i]",
"-print((len(LDS)))",
"+A = []",
"+for i in range(N):",
"+ A.append((-int(eval(input())), i))",
"+print((LIS(A)))"
] | false | 0.053927 | 0.036855 | 1.463209 | [
"s548704148",
"s722432116"
] |
u721407235 | p02683 | python | s605002163 | s261614178 | 157 | 85 | 30,836 | 9,216 | Accepted | Accepted | 45.86 | import numpy as np
import itertools
N,M,X=list(map(int,input().split()))
CA=[]
D=[]
for n in range(N):
arr=list(map(int,input().split()))
CA.append(arr)
CA=np.array(CA)
v=list(itertools.product([0,1], repeat=N))
for v_ in v:
SUM=np.zeros(M+1)
for n in range(N):
if v_[n]==1:
SUM = SUM+CA[n]
D.append(list(SUM))
key=[]
value=[]
for d in D:
key.append(d[0])
value.append(d[1:])
dict = dict(list(zip(key,value)))
dict_sorted = sorted(list(dict.items()), key=lambda x:x[0])
for d in dict_sorted:
if all([i>=X for i in d[1]]):
print((int(d[0])))
exit()
print((-1))
| N,M,X=list(map(int,input().split()))
arr=[list(map(int,input().split())) for _ in range(N)]
ans=9999999999
for i in range(2**N):
cost=0
C=[0]*M
for n in range(N):
#右にずらして一桁目が1かどうかを判定
if (i>>n) &1:
cost += arr[n][0]
for j in range(1,M+1):
C[j-1] += arr[n][j]
if min(C)>=X:
ans=min(ans, cost)
if ans == 9999999999:
print((-1))
else:
print(ans) | 38 | 21 | 624 | 407 | import numpy as np
import itertools
N, M, X = list(map(int, input().split()))
CA = []
D = []
for n in range(N):
arr = list(map(int, input().split()))
CA.append(arr)
CA = np.array(CA)
v = list(itertools.product([0, 1], repeat=N))
for v_ in v:
SUM = np.zeros(M + 1)
for n in range(N):
if v_[n] == 1:
SUM = SUM + CA[n]
D.append(list(SUM))
key = []
value = []
for d in D:
key.append(d[0])
value.append(d[1:])
dict = dict(list(zip(key, value)))
dict_sorted = sorted(list(dict.items()), key=lambda x: x[0])
for d in dict_sorted:
if all([i >= X for i in d[1]]):
print((int(d[0])))
exit()
print((-1))
| N, M, X = list(map(int, input().split()))
arr = [list(map(int, input().split())) for _ in range(N)]
ans = 9999999999
for i in range(2**N):
cost = 0
C = [0] * M
for n in range(N):
# 右にずらして一桁目が1かどうかを判定
if (i >> n) & 1:
cost += arr[n][0]
for j in range(1, M + 1):
C[j - 1] += arr[n][j]
if min(C) >= X:
ans = min(ans, cost)
if ans == 9999999999:
print((-1))
else:
print(ans)
| false | 44.736842 | [
"-import numpy as np",
"-import itertools",
"-",
"-CA = []",
"-D = []",
"-for n in range(N):",
"- arr = list(map(int, input().split()))",
"- CA.append(arr)",
"-CA = np.array(CA)",
"-v = list(itertools.product([0, 1], repeat=N))",
"-for v_ in v:",
"- SUM = np.zeros(M + 1)",
"+arr = [list(map(int, input().split())) for _ in range(N)]",
"+ans = 9999999999",
"+for i in range(2**N):",
"+ cost = 0",
"+ C = [0] * M",
"- if v_[n] == 1:",
"- SUM = SUM + CA[n]",
"- D.append(list(SUM))",
"-key = []",
"-value = []",
"-for d in D:",
"- key.append(d[0])",
"- value.append(d[1:])",
"-dict = dict(list(zip(key, value)))",
"-dict_sorted = sorted(list(dict.items()), key=lambda x: x[0])",
"-for d in dict_sorted:",
"- if all([i >= X for i in d[1]]):",
"- print((int(d[0])))",
"- exit()",
"-print((-1))",
"+ # 右にずらして一桁目が1かどうかを判定",
"+ if (i >> n) & 1:",
"+ cost += arr[n][0]",
"+ for j in range(1, M + 1):",
"+ C[j - 1] += arr[n][j]",
"+ if min(C) >= X:",
"+ ans = min(ans, cost)",
"+if ans == 9999999999:",
"+ print((-1))",
"+else:",
"+ print(ans)"
] | false | 0.185466 | 0.036079 | 5.14052 | [
"s605002163",
"s261614178"
] |
u971811058 | p03495 | python | s690290607 | s860087138 | 192 | 139 | 35,156 | 35,300 | Accepted | Accepted | 27.6 | from collections import Counter, deque, defaultdict
n, k = list(map(int, input().split()))
A = list(map(int, input().split()))
t = defaultdict(int)
for x in A:
t[x]+=1
B = []
for x in list(t.values()):
B.append(x)
B.sort()
if(len(B)<=k):
print((0))
exit()
ans = 0
for i in range(0, len(B)):
ans+=B[i]
if len(B)-(i+1) <= k:
break
print(ans)
| from collections import Counter, deque, defaultdict
n, k = list(map(int, input().split()))
A = list(map(int, input().split()))
t = defaultdict(int)
for x in A:
t[x]+=1
B = list(t.values())
B.sort()
if(len(B)<=k):
print((0))
exit()
ans = sum(B[:len(B)-k])
print(ans)
| 20 | 14 | 382 | 284 | from collections import Counter, deque, defaultdict
n, k = list(map(int, input().split()))
A = list(map(int, input().split()))
t = defaultdict(int)
for x in A:
t[x] += 1
B = []
for x in list(t.values()):
B.append(x)
B.sort()
if len(B) <= k:
print((0))
exit()
ans = 0
for i in range(0, len(B)):
ans += B[i]
if len(B) - (i + 1) <= k:
break
print(ans)
| from collections import Counter, deque, defaultdict
n, k = list(map(int, input().split()))
A = list(map(int, input().split()))
t = defaultdict(int)
for x in A:
t[x] += 1
B = list(t.values())
B.sort()
if len(B) <= k:
print((0))
exit()
ans = sum(B[: len(B) - k])
print(ans)
| false | 30 | [
"-B = []",
"-for x in list(t.values()):",
"- B.append(x)",
"+B = list(t.values())",
"-ans = 0",
"-for i in range(0, len(B)):",
"- ans += B[i]",
"- if len(B) - (i + 1) <= k:",
"- break",
"+ans = sum(B[: len(B) - k])"
] | false | 0.077356 | 0.042084 | 1.838129 | [
"s690290607",
"s860087138"
] |
u600402037 | p02839 | python | s025818905 | s742731879 | 518 | 436 | 173,488 | 173,488 | Accepted | Accepted | 15.83 | import sys
import numpy as np
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
H, W = lr()
A = np.array([lr() for _ in range(H)])
B = np.array([lr() for _ in range(H)])
diff = np.abs(A - B)
X = (H+W) * 80
L = X + X + 1 #真ん中を0とする、最後に-X
dp = [[None] * W for _ in range(H)]
dp[0][0] = np.zeros(L, np.bool)
dp[0][0][X+diff[0][0]] = 1; dp[0][0][X-diff[0][0]] = 1 #非負整数のみでも良い
for h in range(H):
for w in range(W):
if h == 0 and w == 0:
continue
di = diff[h][w]
x = np.zeros(L, np.bool)
if h > 0:
x[di:] |= dp[h-1][w][:L-di]
x[:L-di] |= dp[h-1][w][di:]
if w > 0:
x[di:] |= dp[h][w-1][:L-di]
x[:L-di] |= dp[h][w-1][di:]
dp[h][w] = x
dp = dp[-1][-1][X:]
possible = np.where(dp==1)[0]
answer = possible.min()
print(answer)
#
| import sys
import numpy as np
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
H, W = lr()
A = np.array([lr() for _ in range(H)])
B = np.array([lr() for _ in range(H)])
diff = np.abs(A - B).tolist()
X = (H+W) * 80
L = X + X + 1 #真ん中を0とする、最後に-X
dp = [[None] * W for _ in range(H)]
dp[0][0] = np.zeros(L, np.bool)
dp[0][0][X+diff[0][0]] = 1; dp[0][0][X-diff[0][0]] = 1 #非負整数のみでも良い
for h in range(H):
for w in range(W):
if h == 0 and w == 0:
continue
di = diff[h][w]
x = np.zeros(L, np.bool)
if h > 0:
x[di:] |= dp[h-1][w][:L-di]
x[:L-di] |= dp[h-1][w][di:]
if w > 0:
x[di:] |= dp[h][w-1][:L-di]
x[:L-di] |= dp[h][w-1][di:]
dp[h][w] = x
dp = dp[-1][-1][X:]
possible = np.where(dp==1)[0]
answer = possible.min()
print(answer)
#
| 36 | 36 | 925 | 934 | import sys
import numpy as np
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
H, W = lr()
A = np.array([lr() for _ in range(H)])
B = np.array([lr() for _ in range(H)])
diff = np.abs(A - B)
X = (H + W) * 80
L = X + X + 1 # 真ん中を0とする、最後に-X
dp = [[None] * W for _ in range(H)]
dp[0][0] = np.zeros(L, np.bool)
dp[0][0][X + diff[0][0]] = 1
dp[0][0][X - diff[0][0]] = 1 # 非負整数のみでも良い
for h in range(H):
for w in range(W):
if h == 0 and w == 0:
continue
di = diff[h][w]
x = np.zeros(L, np.bool)
if h > 0:
x[di:] |= dp[h - 1][w][: L - di]
x[: L - di] |= dp[h - 1][w][di:]
if w > 0:
x[di:] |= dp[h][w - 1][: L - di]
x[: L - di] |= dp[h][w - 1][di:]
dp[h][w] = x
dp = dp[-1][-1][X:]
possible = np.where(dp == 1)[0]
answer = possible.min()
print(answer)
#
| import sys
import numpy as np
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
H, W = lr()
A = np.array([lr() for _ in range(H)])
B = np.array([lr() for _ in range(H)])
diff = np.abs(A - B).tolist()
X = (H + W) * 80
L = X + X + 1 # 真ん中を0とする、最後に-X
dp = [[None] * W for _ in range(H)]
dp[0][0] = np.zeros(L, np.bool)
dp[0][0][X + diff[0][0]] = 1
dp[0][0][X - diff[0][0]] = 1 # 非負整数のみでも良い
for h in range(H):
for w in range(W):
if h == 0 and w == 0:
continue
di = diff[h][w]
x = np.zeros(L, np.bool)
if h > 0:
x[di:] |= dp[h - 1][w][: L - di]
x[: L - di] |= dp[h - 1][w][di:]
if w > 0:
x[di:] |= dp[h][w - 1][: L - di]
x[: L - di] |= dp[h][w - 1][di:]
dp[h][w] = x
dp = dp[-1][-1][X:]
possible = np.where(dp == 1)[0]
answer = possible.min()
print(answer)
#
| false | 0 | [
"-diff = np.abs(A - B)",
"+diff = np.abs(A - B).tolist()"
] | false | 0.69146 | 0.172282 | 4.013542 | [
"s025818905",
"s742731879"
] |
u227082700 | p02558 | python | s540297911 | s808372747 | 452 | 385 | 13,436 | 79,248 | Accepted | Accepted | 14.82 | import sys
input = lambda: sys.stdin.readline().rstrip()
# UnionFind
class UnionFind:
def __init__(self,n):
self.n=n
self.a=[-1]*n
self.r=[0]*n
self.siz=n
def root_find(self,x):
if self.a[x]<0:
return x
else:
self.a[x]=self.root_find(self.a[x])
return self.a[x]
def unite(self,x,y):
x=self.root_find(x)
y=self.root_find(y)
if x==y:
return
if self.r[x]==self.r[y]:
self.r[x]+=1
self.a[x]+=self.a[y]
self.a[y]=x
elif self.r[x]>self.r[y]:
self.a[x]+=self.a[y]
self.a[y]=x
else:
self.a[y]+=self.a[x]
self.a[x]=y
self.siz-=1
def root_same(self,x,y):
return self.root_find(x)==self.root_find(y)
n,q=list(map(int,input().split()))
u=UnionFind(n)
for _ in range(q):
t,a,b=list(map(int,input().split()))
if t==0:
u.unite(a,b)
else:
print((u.root_same(a,b)+0)) | import sys
input = lambda: sys.stdin.readline().rstrip()
# UnionFind
class UnionFind:
def __init__(self,n):
self.n=n
self.a=[-1]*n
self.siz=n
def root_find(self,x):
if self.a[x]<0:
return x
else:
self.a[x]=self.root_find(self.a[x])
return self.a[x]
def unite(self,x,y):
x=self.root_find(x)
y=self.root_find(y)
if x==y:
return
elif self.a[x]<self.a[y]:
self.a[x]+=self.a[y]
self.a[y]=x
else:
self.a[y]+=self.a[x]
self.a[x]=y
self.siz-=1
def root_same(self,x,y):
return self.root_find(x)==self.root_find(y)
n,q=list(map(int,input().split()))
u=UnionFind(n)
for _ in range(q):
t,a,b=list(map(int,input().split()))
if t==0:
u.unite(a,b)
else:
print((u.root_same(a,b)+0))
| 44 | 38 | 942 | 926 | import sys
input = lambda: sys.stdin.readline().rstrip()
# UnionFind
class UnionFind:
def __init__(self, n):
self.n = n
self.a = [-1] * n
self.r = [0] * n
self.siz = n
def root_find(self, x):
if self.a[x] < 0:
return x
else:
self.a[x] = self.root_find(self.a[x])
return self.a[x]
def unite(self, x, y):
x = self.root_find(x)
y = self.root_find(y)
if x == y:
return
if self.r[x] == self.r[y]:
self.r[x] += 1
self.a[x] += self.a[y]
self.a[y] = x
elif self.r[x] > self.r[y]:
self.a[x] += self.a[y]
self.a[y] = x
else:
self.a[y] += self.a[x]
self.a[x] = y
self.siz -= 1
def root_same(self, x, y):
return self.root_find(x) == self.root_find(y)
n, q = list(map(int, input().split()))
u = UnionFind(n)
for _ in range(q):
t, a, b = list(map(int, input().split()))
if t == 0:
u.unite(a, b)
else:
print((u.root_same(a, b) + 0))
| import sys
input = lambda: sys.stdin.readline().rstrip()
# UnionFind
class UnionFind:
def __init__(self, n):
self.n = n
self.a = [-1] * n
self.siz = n
def root_find(self, x):
if self.a[x] < 0:
return x
else:
self.a[x] = self.root_find(self.a[x])
return self.a[x]
def unite(self, x, y):
x = self.root_find(x)
y = self.root_find(y)
if x == y:
return
elif self.a[x] < self.a[y]:
self.a[x] += self.a[y]
self.a[y] = x
else:
self.a[y] += self.a[x]
self.a[x] = y
self.siz -= 1
def root_same(self, x, y):
return self.root_find(x) == self.root_find(y)
n, q = list(map(int, input().split()))
u = UnionFind(n)
for _ in range(q):
t, a, b = list(map(int, input().split()))
if t == 0:
u.unite(a, b)
else:
print((u.root_same(a, b) + 0))
| false | 13.636364 | [
"- self.r = [0] * n",
"- if self.r[x] == self.r[y]:",
"- self.r[x] += 1",
"- self.a[x] += self.a[y]",
"- self.a[y] = x",
"- elif self.r[x] > self.r[y]:",
"+ elif self.a[x] < self.a[y]:"
] | false | 0.044386 | 0.042605 | 1.041807 | [
"s540297911",
"s808372747"
] |
u562935282 | p03659 | python | s196185740 | s408201900 | 211 | 172 | 24,832 | 24,832 | Accepted | Accepted | 18.48 | def inpl(): return input().split()
n = int(eval(input()))
a = list(map(int, inpl()))
sa = sum(a)
b = [a[0]]
for i in range(1, n - 1):
b.append(a[i] + b[i - 1])
ans = float('inf')
for x in b:
ans = min(ans, abs(sa - 2 * x))
print(ans) | n = int(eval(input()))
*a, = list(map(int, input().split()))
ret = 10 ** 15
s = 0
t = sum(a)
a.pop() # 最後の要素は取れない
for x in a:
s += x
t -= x
ret = min(ret, abs(s - t))
print(ret)
| 13 | 14 | 249 | 195 | def inpl():
return input().split()
n = int(eval(input()))
a = list(map(int, inpl()))
sa = sum(a)
b = [a[0]]
for i in range(1, n - 1):
b.append(a[i] + b[i - 1])
ans = float("inf")
for x in b:
ans = min(ans, abs(sa - 2 * x))
print(ans)
| n = int(eval(input()))
(*a,) = list(map(int, input().split()))
ret = 10**15
s = 0
t = sum(a)
a.pop() # 最後の要素は取れない
for x in a:
s += x
t -= x
ret = min(ret, abs(s - t))
print(ret)
| false | 7.142857 | [
"-def inpl():",
"- return input().split()",
"-",
"-",
"-a = list(map(int, inpl()))",
"-sa = sum(a)",
"-b = [a[0]]",
"-for i in range(1, n - 1):",
"- b.append(a[i] + b[i - 1])",
"-ans = float(\"inf\")",
"-for x in b:",
"- ans = min(ans, abs(sa - 2 * x))",
"-print(ans)",
"+(*a,) = list(map(int, input().split()))",
"+ret = 10**15",
"+s = 0",
"+t = sum(a)",
"+a.pop() # 最後の要素は取れない",
"+for x in a:",
"+ s += x",
"+ t -= x",
"+ ret = min(ret, abs(s - t))",
"+print(ret)"
] | false | 0.036391 | 0.0395 | 0.921288 | [
"s196185740",
"s408201900"
] |
u391331433 | p03253 | python | s038156569 | s663489824 | 337 | 44 | 74,380 | 10,036 | Accepted | Accepted | 86.94 | import sys
from collections import deque
import copy
def power_func(a,b,p):
if b==0: return 1
if b%2==0:
d=power_func(a,b//2,p)
return d*d %p
if b%2==1:
return (a*power_func(a,b-1,p ))%p
class comb_calclator():
def __init__(self, N, p):
self.N = N
self.p = p
self.frac_N = [0 for i in range(N + 1)]
self.frac_N[0] = 1
self.comb_N = {}
for i in range(1, N + 1):
self.frac_N[i] = (self.frac_N[i - 1] * i ) % p
def comb(self, n, r):
if n<0 or r<0 or n<r: return 0
if n==0 or r==0: return 1
if (n, r) in self.comb_N:
return self.comb_N[(n, r)]
a = self.frac_N[n]
b = self.frac_N[r]
c = self.frac_N[n - r]
self.comb_N[(n, r)] = (a*power_func(b,self.p-2,self.p)*power_func(c,self.p-2, self.p))% self.p
self.comb_N[(n, n - r)] = self.comb_N[(n, r)]
return self.comb_N[(n, r)]
def prime_decomposition(n):
i = 2
table = []
while i * i <= n:
while n % i == 0:
n /= i
table.append(i)
i += 1
if n > 1:
table.append(n)
return table
def get_read_func(fileobject):
if fileobject == None :
return raw_input
else:
return fileobject.readline
def main():
if len(sys.argv) > 1:
f = open(sys.argv[1])
else:
f = None
read_func = get_read_func(f);
input_raw = read_func().strip().split()
[N, M] = [int(input_raw[0]), int(input_raw[1])]
prime_table = prime_decomposition(M)
primes = {}
for p in prime_table:
if p in primes:
primes[p] += 1
else:
primes[p] = 1
cmb = comb_calclator(10 * N, int(1e+9) + 7)
count = 1
for p in primes:
b = primes[p]
count = (count * cmb.comb(b + N - 1, b))%(int(1e+9) + 7)
print(count)
if __name__ == '__main__':
main()
| import sys
from collections import deque
import copy
def power_func(a,b,p):
if b==0: return 1
if b%2==0:
d=power_func(a,b//2,p)
return d*d %p
if b%2==1:
return (a*power_func(a,b-1,p ))%p
class comb_calclator():
def __init__(self, N, p):
self.N = N
self.p = p
self.frac_N = [0 for i in range(N + 1)]
self.frac_N[0] = 1
self.comb_N = {}
for i in range(1, N + 1):
self.frac_N[i] = (self.frac_N[i - 1] * i ) % p
def comb(self, n, r):
if n<0 or r<0 or n<r: return 0
if n==0 or r==0: return 1
if (n, r) in self.comb_N:
return self.comb_N[(n, r)]
a = self.frac_N[n]
b = self.frac_N[r]
c = self.frac_N[n - r]
self.comb_N[(n, r)] = (a*power_func(b,self.p-2,self.p)*power_func(c,self.p-2, self.p))% self.p
self.comb_N[(n, n - r)] = self.comb_N[(n, r)]
return self.comb_N[(n, r)]
def prime_decomposition(n):
i = 2
table = []
while i * i <= n:
while n % i == 0:
n /= i
table.append(i)
i += 1
if n > 1:
table.append(n)
return table
def get_read_func(fileobject):
if fileobject == None :
return raw_input
else:
return fileobject.readline
def main():
if len(sys.argv) > 1:
f = open(sys.argv[1])
else:
f = None
read_func = get_read_func(f);
input_raw = read_func().strip().split()
[N, M] = [int(input_raw[0]), int(input_raw[1])]
prime_table = prime_decomposition(M)
primes = {}
for p in prime_table:
if p in primes:
primes[p] += 1
else:
primes[p] = 1
max_num = 0
for p in primes:
max_num = max(max_num, primes[p])
cmb = comb_calclator(max_num + N, int(1e+9) + 7)
count = 1
for p in primes:
b = primes[p]
count = (count * cmb.comb(b + N - 1, b))%(int(1e+9) + 7)
print(count)
if __name__ == '__main__':
main()
| 85 | 89 | 1,976 | 2,065 | import sys
from collections import deque
import copy
def power_func(a, b, p):
if b == 0:
return 1
if b % 2 == 0:
d = power_func(a, b // 2, p)
return d * d % p
if b % 2 == 1:
return (a * power_func(a, b - 1, p)) % p
class comb_calclator:
def __init__(self, N, p):
self.N = N
self.p = p
self.frac_N = [0 for i in range(N + 1)]
self.frac_N[0] = 1
self.comb_N = {}
for i in range(1, N + 1):
self.frac_N[i] = (self.frac_N[i - 1] * i) % p
def comb(self, n, r):
if n < 0 or r < 0 or n < r:
return 0
if n == 0 or r == 0:
return 1
if (n, r) in self.comb_N:
return self.comb_N[(n, r)]
a = self.frac_N[n]
b = self.frac_N[r]
c = self.frac_N[n - r]
self.comb_N[(n, r)] = (
a * power_func(b, self.p - 2, self.p) * power_func(c, self.p - 2, self.p)
) % self.p
self.comb_N[(n, n - r)] = self.comb_N[(n, r)]
return self.comb_N[(n, r)]
def prime_decomposition(n):
i = 2
table = []
while i * i <= n:
while n % i == 0:
n /= i
table.append(i)
i += 1
if n > 1:
table.append(n)
return table
def get_read_func(fileobject):
if fileobject == None:
return raw_input
else:
return fileobject.readline
def main():
if len(sys.argv) > 1:
f = open(sys.argv[1])
else:
f = None
read_func = get_read_func(f)
input_raw = read_func().strip().split()
[N, M] = [int(input_raw[0]), int(input_raw[1])]
prime_table = prime_decomposition(M)
primes = {}
for p in prime_table:
if p in primes:
primes[p] += 1
else:
primes[p] = 1
cmb = comb_calclator(10 * N, int(1e9) + 7)
count = 1
for p in primes:
b = primes[p]
count = (count * cmb.comb(b + N - 1, b)) % (int(1e9) + 7)
print(count)
if __name__ == "__main__":
main()
| import sys
from collections import deque
import copy
def power_func(a, b, p):
if b == 0:
return 1
if b % 2 == 0:
d = power_func(a, b // 2, p)
return d * d % p
if b % 2 == 1:
return (a * power_func(a, b - 1, p)) % p
class comb_calclator:
def __init__(self, N, p):
self.N = N
self.p = p
self.frac_N = [0 for i in range(N + 1)]
self.frac_N[0] = 1
self.comb_N = {}
for i in range(1, N + 1):
self.frac_N[i] = (self.frac_N[i - 1] * i) % p
def comb(self, n, r):
if n < 0 or r < 0 or n < r:
return 0
if n == 0 or r == 0:
return 1
if (n, r) in self.comb_N:
return self.comb_N[(n, r)]
a = self.frac_N[n]
b = self.frac_N[r]
c = self.frac_N[n - r]
self.comb_N[(n, r)] = (
a * power_func(b, self.p - 2, self.p) * power_func(c, self.p - 2, self.p)
) % self.p
self.comb_N[(n, n - r)] = self.comb_N[(n, r)]
return self.comb_N[(n, r)]
def prime_decomposition(n):
i = 2
table = []
while i * i <= n:
while n % i == 0:
n /= i
table.append(i)
i += 1
if n > 1:
table.append(n)
return table
def get_read_func(fileobject):
if fileobject == None:
return raw_input
else:
return fileobject.readline
def main():
if len(sys.argv) > 1:
f = open(sys.argv[1])
else:
f = None
read_func = get_read_func(f)
input_raw = read_func().strip().split()
[N, M] = [int(input_raw[0]), int(input_raw[1])]
prime_table = prime_decomposition(M)
primes = {}
for p in prime_table:
if p in primes:
primes[p] += 1
else:
primes[p] = 1
max_num = 0
for p in primes:
max_num = max(max_num, primes[p])
cmb = comb_calclator(max_num + N, int(1e9) + 7)
count = 1
for p in primes:
b = primes[p]
count = (count * cmb.comb(b + N - 1, b)) % (int(1e9) + 7)
print(count)
if __name__ == "__main__":
main()
| false | 4.494382 | [
"- cmb = comb_calclator(10 * N, int(1e9) + 7)",
"+ max_num = 0",
"+ for p in primes:",
"+ max_num = max(max_num, primes[p])",
"+ cmb = comb_calclator(max_num + N, int(1e9) + 7)"
] | false | 0.043037 | 0.044043 | 0.977159 | [
"s038156569",
"s663489824"
] |
u770199020 | p03262 | python | s442810718 | s279373950 | 157 | 101 | 14,100 | 14,224 | Accepted | Accepted | 35.67 |
def gcd(p, q):
a, b = (p, q) if p >= q else (q, p)
c = a % b
while c != 0:
a, b = (b, c) if b >= c else (c, b)
c = a % b
return b
N, X = [int(x) for x in input().split()]
xn = sorted([int(x) for x in input().split()])
diffs = []
if X < xn[0]:
diffs.append(xn[0] -X)
for n in range(N-1):
if xn[n] < X < xn[n+1]:
diffs.append(X - xn[n])
diffs.append(xn[n+1] - X)
else:
diffs.append(xn[n+1] - xn[n])
if X > xn[N-1]:
diffs.append(X - xn[N-1])
if len(diffs) > 1:
D = gcd(diffs[0], diffs[1])
for i in range(N-2):
D = gcd(D, diffs[i+2])
else:
D = diffs[0]
print(D)
|
def gcd(x, y):
#assert x >= y
return gcd(y, x%y) if y else x
N, X = [int(i) for i in input().split()]
Xn = [int(i) for i in input().split()]
dx =[abs(x-X) for x in Xn]
gcd_num = dx[0]
for x in dx:
a, b = (gcd_num, x) if gcd_num > x else (x, gcd_num)
gcd_num = gcd(a, b)
print(gcd_num)
| 32 | 21 | 642 | 324 | def gcd(p, q):
a, b = (p, q) if p >= q else (q, p)
c = a % b
while c != 0:
a, b = (b, c) if b >= c else (c, b)
c = a % b
return b
N, X = [int(x) for x in input().split()]
xn = sorted([int(x) for x in input().split()])
diffs = []
if X < xn[0]:
diffs.append(xn[0] - X)
for n in range(N - 1):
if xn[n] < X < xn[n + 1]:
diffs.append(X - xn[n])
diffs.append(xn[n + 1] - X)
else:
diffs.append(xn[n + 1] - xn[n])
if X > xn[N - 1]:
diffs.append(X - xn[N - 1])
if len(diffs) > 1:
D = gcd(diffs[0], diffs[1])
for i in range(N - 2):
D = gcd(D, diffs[i + 2])
else:
D = diffs[0]
print(D)
| def gcd(x, y):
# assert x >= y
return gcd(y, x % y) if y else x
N, X = [int(i) for i in input().split()]
Xn = [int(i) for i in input().split()]
dx = [abs(x - X) for x in Xn]
gcd_num = dx[0]
for x in dx:
a, b = (gcd_num, x) if gcd_num > x else (x, gcd_num)
gcd_num = gcd(a, b)
print(gcd_num)
| false | 34.375 | [
"-def gcd(p, q):",
"- a, b = (p, q) if p >= q else (q, p)",
"- c = a % b",
"- while c != 0:",
"- a, b = (b, c) if b >= c else (c, b)",
"- c = a % b",
"- return b",
"+def gcd(x, y):",
"+ # assert x >= y",
"+ return gcd(y, x % y) if y else x",
"-N, X = [int(x) for x in input().split()]",
"-xn = sorted([int(x) for x in input().split()])",
"-diffs = []",
"-if X < xn[0]:",
"- diffs.append(xn[0] - X)",
"-for n in range(N - 1):",
"- if xn[n] < X < xn[n + 1]:",
"- diffs.append(X - xn[n])",
"- diffs.append(xn[n + 1] - X)",
"- else:",
"- diffs.append(xn[n + 1] - xn[n])",
"-if X > xn[N - 1]:",
"- diffs.append(X - xn[N - 1])",
"-if len(diffs) > 1:",
"- D = gcd(diffs[0], diffs[1])",
"- for i in range(N - 2):",
"- D = gcd(D, diffs[i + 2])",
"-else:",
"- D = diffs[0]",
"-print(D)",
"+N, X = [int(i) for i in input().split()]",
"+Xn = [int(i) for i in input().split()]",
"+dx = [abs(x - X) for x in Xn]",
"+gcd_num = dx[0]",
"+for x in dx:",
"+ a, b = (gcd_num, x) if gcd_num > x else (x, gcd_num)",
"+ gcd_num = gcd(a, b)",
"+print(gcd_num)"
] | false | 0.03672 | 0.142891 | 0.256977 | [
"s442810718",
"s279373950"
] |
u077291787 | p03354 | python | s049900920 | s166264147 | 529 | 480 | 90,168 | 25,184 | Accepted | Accepted | 9.26 | # ARC097D - Equals
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
def dfs(v: int, color: int) -> None:
group[v] = color # make vertex v searched
for u in G[v]: # search vertices available from v recursively
if not group[u]: # skip if already searched
dfs(u, color)
def main():
# check i and Pi are connected components or not
global G, group
N, M = tuple(map(int, input().split()))
P = tuple(map(int, input().split()))
E = tuple(tuple(map(int, input().split())) for _ in range(M))
G = [[] for _ in range(N + 1)] # construct a graph (1-idx)
for v, u in E:
G[v] += [u]
G[u] += [v]
group = [0] * (N + 1)
color = 1
for v in range(1, N + 1): # connected components are in the same group
if not group[v]:
dfs(v, color)
color += 1
ans = sum(group[i] == group[p] for i, p in enumerate(P, 1))
print(ans)
if __name__ == "__main__":
main() | # ABC097D - Equals (ARC097D)
import sys
input = sys.stdin.readline
class UnionFind:
def __init__(self, N): # construct a Union-Find tree (1-idx)
self.parent = [i for i in range(N + 1)]
self.rank = [0] * (N + 1)
def find(self, x): # find the group (root) of a vertex
if self.parent[x] == x:
return x
self.parent[x] = self.find(self.parent[x])
return self.parent[x]
def is_same(self, x, y): # check two vertices are in the same group
return self.find(x) == self.find(y)
def unite(self, x, y): # unite two groups
x, y = self.find(x), self.find(y)
if x == y: # the same group
return
# unite a small one to a bigger one to balance trees
if self.rank[x] < self.rank[y]:
self.parent[x] = y
else:
self.parent[y] = x
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
def main():
# check i and Pi are connected components or not
N, M = tuple(map(int, input().split()))
P = tuple(map(int, input().split()))
E = tuple(tuple(map(int, input().split())) for _ in range(M))
U = UnionFind(N) # construct a Union-Find tree (1-idx)
for v, u in E: # connected components are in the same group
U.unite(v, u)
ans = sum(U.is_same(i, p) for i, p in enumerate(P, 1))
print(ans)
if __name__ == "__main__":
main() | 36 | 46 | 1,025 | 1,472 | # ARC097D - Equals
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**9)
def dfs(v: int, color: int) -> None:
group[v] = color # make vertex v searched
for u in G[v]: # search vertices available from v recursively
if not group[u]: # skip if already searched
dfs(u, color)
def main():
# check i and Pi are connected components or not
global G, group
N, M = tuple(map(int, input().split()))
P = tuple(map(int, input().split()))
E = tuple(tuple(map(int, input().split())) for _ in range(M))
G = [[] for _ in range(N + 1)] # construct a graph (1-idx)
for v, u in E:
G[v] += [u]
G[u] += [v]
group = [0] * (N + 1)
color = 1
for v in range(1, N + 1): # connected components are in the same group
if not group[v]:
dfs(v, color)
color += 1
ans = sum(group[i] == group[p] for i, p in enumerate(P, 1))
print(ans)
if __name__ == "__main__":
main()
| # ABC097D - Equals (ARC097D)
import sys
input = sys.stdin.readline
class UnionFind:
def __init__(self, N): # construct a Union-Find tree (1-idx)
self.parent = [i for i in range(N + 1)]
self.rank = [0] * (N + 1)
def find(self, x): # find the group (root) of a vertex
if self.parent[x] == x:
return x
self.parent[x] = self.find(self.parent[x])
return self.parent[x]
def is_same(self, x, y): # check two vertices are in the same group
return self.find(x) == self.find(y)
def unite(self, x, y): # unite two groups
x, y = self.find(x), self.find(y)
if x == y: # the same group
return
# unite a small one to a bigger one to balance trees
if self.rank[x] < self.rank[y]:
self.parent[x] = y
else:
self.parent[y] = x
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
def main():
# check i and Pi are connected components or not
N, M = tuple(map(int, input().split()))
P = tuple(map(int, input().split()))
E = tuple(tuple(map(int, input().split())) for _ in range(M))
U = UnionFind(N) # construct a Union-Find tree (1-idx)
for v, u in E: # connected components are in the same group
U.unite(v, u)
ans = sum(U.is_same(i, p) for i, p in enumerate(P, 1))
print(ans)
if __name__ == "__main__":
main()
| false | 21.73913 | [
"-# ARC097D - Equals",
"+# ABC097D - Equals (ARC097D)",
"-sys.setrecursionlimit(10**9)",
"-def dfs(v: int, color: int) -> None:",
"- group[v] = color # make vertex v searched",
"- for u in G[v]: # search vertices available from v recursively",
"- if not group[u]: # skip if already searched",
"- dfs(u, color)",
"+class UnionFind:",
"+ def __init__(self, N): # construct a Union-Find tree (1-idx)",
"+ self.parent = [i for i in range(N + 1)]",
"+ self.rank = [0] * (N + 1)",
"+",
"+ def find(self, x): # find the group (root) of a vertex",
"+ if self.parent[x] == x:",
"+ return x",
"+ self.parent[x] = self.find(self.parent[x])",
"+ return self.parent[x]",
"+",
"+ def is_same(self, x, y): # check two vertices are in the same group",
"+ return self.find(x) == self.find(y)",
"+",
"+ def unite(self, x, y): # unite two groups",
"+ x, y = self.find(x), self.find(y)",
"+ if x == y: # the same group",
"+ return",
"+ # unite a small one to a bigger one to balance trees",
"+ if self.rank[x] < self.rank[y]:",
"+ self.parent[x] = y",
"+ else:",
"+ self.parent[y] = x",
"+ if self.rank[x] == self.rank[y]:",
"+ self.rank[x] += 1",
"- global G, group",
"- G = [[] for _ in range(N + 1)] # construct a graph (1-idx)",
"- for v, u in E:",
"- G[v] += [u]",
"- G[u] += [v]",
"- group = [0] * (N + 1)",
"- color = 1",
"- for v in range(1, N + 1): # connected components are in the same group",
"- if not group[v]:",
"- dfs(v, color)",
"- color += 1",
"- ans = sum(group[i] == group[p] for i, p in enumerate(P, 1))",
"+ U = UnionFind(N) # construct a Union-Find tree (1-idx)",
"+ for v, u in E: # connected components are in the same group",
"+ U.unite(v, u)",
"+ ans = sum(U.is_same(i, p) for i, p in enumerate(P, 1))"
] | false | 0.041191 | 0.037626 | 1.094736 | [
"s049900920",
"s166264147"
] |
u860657719 | p02623 | python | s099477498 | s733223009 | 306 | 184 | 110,968 | 132,948 | Accepted | Accepted | 39.87 | n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0
s = 0
b_count = 0
for i in range(m):
if s + b[i] <= k:
s += b[i]
ans += 1
b_count = i+1
else:
break
a_count = 0
while True:
if a_count < n and s+a[a_count] <= k:
s += a[a_count]
a_count += 1
ans += 1
else:
break
now = ans
for i in range(b_count-1, -1, -1):
s -= b[i]
now -= 1
while True:
if a_count < n and s +a[a_count] <= k:
s += a[a_count]
a_count += 1
now += 1
else:
break
ans = max(now, ans)
print(ans) | n, m, k = list(map(int,input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
sa = [0]
for i in range(n):
sa.append(sa[-1] + a[i])
inf = 1001001001
sb = [-inf, 0]
for i in range(m):
sb.append(sb[-1] + b[i])
sb.append(inf)
ans = 0
for i in range(n+1):
s = sa[i]
l = 0
r = len(sb) - 1
while l+1 < r:
m = (l+r) //2
if s + sb[m] <= k:
l = m
else:
r = m
if l == 0:
continue
else:
ans = max(ans, i+l-1)
print(ans) | 34 | 27 | 716 | 558 | n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0
s = 0
b_count = 0
for i in range(m):
if s + b[i] <= k:
s += b[i]
ans += 1
b_count = i + 1
else:
break
a_count = 0
while True:
if a_count < n and s + a[a_count] <= k:
s += a[a_count]
a_count += 1
ans += 1
else:
break
now = ans
for i in range(b_count - 1, -1, -1):
s -= b[i]
now -= 1
while True:
if a_count < n and s + a[a_count] <= k:
s += a[a_count]
a_count += 1
now += 1
else:
break
ans = max(now, ans)
print(ans)
| n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
sa = [0]
for i in range(n):
sa.append(sa[-1] + a[i])
inf = 1001001001
sb = [-inf, 0]
for i in range(m):
sb.append(sb[-1] + b[i])
sb.append(inf)
ans = 0
for i in range(n + 1):
s = sa[i]
l = 0
r = len(sb) - 1
while l + 1 < r:
m = (l + r) // 2
if s + sb[m] <= k:
l = m
else:
r = m
if l == 0:
continue
else:
ans = max(ans, i + l - 1)
print(ans)
| false | 20.588235 | [
"+sa = [0]",
"+for i in range(n):",
"+ sa.append(sa[-1] + a[i])",
"+inf = 1001001001",
"+sb = [-inf, 0]",
"+for i in range(m):",
"+ sb.append(sb[-1] + b[i])",
"+sb.append(inf)",
"-s = 0",
"-b_count = 0",
"-for i in range(m):",
"- if s + b[i] <= k:",
"- s += b[i]",
"- ans += 1",
"- b_count = i + 1",
"+for i in range(n + 1):",
"+ s = sa[i]",
"+ l = 0",
"+ r = len(sb) - 1",
"+ while l + 1 < r:",
"+ m = (l + r) // 2",
"+ if s + sb[m] <= k:",
"+ l = m",
"+ else:",
"+ r = m",
"+ if l == 0:",
"+ continue",
"- break",
"-a_count = 0",
"-while True:",
"- if a_count < n and s + a[a_count] <= k:",
"- s += a[a_count]",
"- a_count += 1",
"- ans += 1",
"- else:",
"- break",
"-now = ans",
"-for i in range(b_count - 1, -1, -1):",
"- s -= b[i]",
"- now -= 1",
"- while True:",
"- if a_count < n and s + a[a_count] <= k:",
"- s += a[a_count]",
"- a_count += 1",
"- now += 1",
"- else:",
"- break",
"- ans = max(now, ans)",
"+ ans = max(ans, i + l - 1)"
] | false | 0.039658 | 0.124578 | 0.318343 | [
"s099477498",
"s733223009"
] |
u879870653 | p03160 | python | s994213689 | s652244818 | 206 | 125 | 13,980 | 13,980 | Accepted | Accepted | 39.32 | N = int(eval(input()))
H = list(map(int,input().split()))
dp = [float("inf") for i in range(N)]
dp[0] = 0
for i in range(N-1) :
dp[i+1] = min(dp[i+1], dp[i] + abs(H[i] - H[i+1]))
if i <= N-3 :
dp[i+2] = min(dp[i+2], dp[i] + abs(H[i] - H[i+2]))
ans = dp[N-1]
print(ans) | n = int(eval(input()))
h = list(map(int,input().split()))
dp = [0]*(n)
dp[1] = abs(h[0]-h[1])
for i in range(2, len(dp)) :
a = dp[i-2] + abs(h[i-2]-h[i])
b = dp[i-1] + abs(h[i-1]-h[i])
dp[i] = min(a, b)
print((dp[n-1]))
| 14 | 10 | 295 | 234 | N = int(eval(input()))
H = list(map(int, input().split()))
dp = [float("inf") for i in range(N)]
dp[0] = 0
for i in range(N - 1):
dp[i + 1] = min(dp[i + 1], dp[i] + abs(H[i] - H[i + 1]))
if i <= N - 3:
dp[i + 2] = min(dp[i + 2], dp[i] + abs(H[i] - H[i + 2]))
ans = dp[N - 1]
print(ans)
| n = int(eval(input()))
h = list(map(int, input().split()))
dp = [0] * (n)
dp[1] = abs(h[0] - h[1])
for i in range(2, len(dp)):
a = dp[i - 2] + abs(h[i - 2] - h[i])
b = dp[i - 1] + abs(h[i - 1] - h[i])
dp[i] = min(a, b)
print((dp[n - 1]))
| false | 28.571429 | [
"-N = int(eval(input()))",
"-H = list(map(int, input().split()))",
"-dp = [float(\"inf\") for i in range(N)]",
"-dp[0] = 0",
"-for i in range(N - 1):",
"- dp[i + 1] = min(dp[i + 1], dp[i] + abs(H[i] - H[i + 1]))",
"- if i <= N - 3:",
"- dp[i + 2] = min(dp[i + 2], dp[i] + abs(H[i] - H[i + 2]))",
"-ans = dp[N - 1]",
"-print(ans)",
"+n = int(eval(input()))",
"+h = list(map(int, input().split()))",
"+dp = [0] * (n)",
"+dp[1] = abs(h[0] - h[1])",
"+for i in range(2, len(dp)):",
"+ a = dp[i - 2] + abs(h[i - 2] - h[i])",
"+ b = dp[i - 1] + abs(h[i - 1] - h[i])",
"+ dp[i] = min(a, b)",
"+print((dp[n - 1]))"
] | false | 0.041551 | 0.04182 | 0.993561 | [
"s994213689",
"s652244818"
] |
u844005364 | p03854 | python | s830778514 | s238769498 | 70 | 19 | 3,188 | 3,188 | Accepted | Accepted | 72.86 | s = eval(input())
while s:
if s[:6] == "eraser":
s = s[6:]
elif s[:5] == "erase":
s = s[5:]
elif s[:5] == "dream":
if s[5:8] == "era":
s = s[5:]
elif s[5:7] == "er":
s = s[7:]
else:
s = s[5:]
else:
print("NO")
exit()
print("YES")
| s = eval(input())
if s.replace("eraser","").replace("erase","").replace("dreamer","").replace("dream","") == "":
print("YES")
else:
print("NO") | 18 | 6 | 350 | 151 | s = eval(input())
while s:
if s[:6] == "eraser":
s = s[6:]
elif s[:5] == "erase":
s = s[5:]
elif s[:5] == "dream":
if s[5:8] == "era":
s = s[5:]
elif s[5:7] == "er":
s = s[7:]
else:
s = s[5:]
else:
print("NO")
exit()
print("YES")
| s = eval(input())
if (
s.replace("eraser", "")
.replace("erase", "")
.replace("dreamer", "")
.replace("dream", "")
== ""
):
print("YES")
else:
print("NO")
| false | 66.666667 | [
"-while s:",
"- if s[:6] == \"eraser\":",
"- s = s[6:]",
"- elif s[:5] == \"erase\":",
"- s = s[5:]",
"- elif s[:5] == \"dream\":",
"- if s[5:8] == \"era\":",
"- s = s[5:]",
"- elif s[5:7] == \"er\":",
"- s = s[7:]",
"- else:",
"- s = s[5:]",
"- else:",
"- print(\"NO\")",
"- exit()",
"-print(\"YES\")",
"+if (",
"+ s.replace(\"eraser\", \"\")",
"+ .replace(\"erase\", \"\")",
"+ .replace(\"dreamer\", \"\")",
"+ .replace(\"dream\", \"\")",
"+ == \"\"",
"+):",
"+ print(\"YES\")",
"+else:",
"+ print(\"NO\")"
] | false | 0.04073 | 0.150788 | 0.270112 | [
"s830778514",
"s238769498"
] |
u257162238 | p02609 | python | s615311107 | s745991108 | 436 | 347 | 25,300 | 25,376 | Accepted | Accepted | 20.41 | import sys
input = sys.stdin.readline
import math
def read():
N = int(input().strip())
X = input().strip()
return N, X
def bitdiv(N:int, X:str, d:int):
q = 0
for i in range(N):
q <<= 1
q |= int(X[i])
p, q = divmod(q, d)
return q
def solve(N, X):
BP = [0 for i in range(N)]
BM = [0 for i in range(N)]
c = X.count("1")
# 2^k mod (c+1) を高速に求める
qp = bitdiv(N, X, c+1)
BP[N-1] = 1 % (c+1)
for i in range(N-2, -1, -1):
BP[i] = (BP[i+1] * 2) % (c+1)
# 2^k mod (c-1) を高速に求める
if c > 1:
qm = bitdiv(N, X, c-1)
BM[N-1] = 1 % (c-1)
for i in range(N-2, -1, -1):
BM[i] = (BM[i+1] * 2) % (c-1)
for i in range(N):
q = 0
ans = 0
if X[i] == "0":
# X_i \equiv (X + 2^i)
q = (qp + BP[i]) % (c+1)
ans += 1
elif X[i] == "1" and c > 1:
# X_i \equiv (X - 2^i)
q = (qm - BM[i]) % (c-1)
ans += 1
else:
q = 0
ans = 0
while q > 0:
q %= (bin(q).count("1"))
ans += 1
print(ans)
if __name__ == '__main__':
inputs = read()
outputs = solve(*inputs)
if outputs is not None:
print(("%s" % str(outputs)))
| import sys
input = sys.stdin.readline
import math
def read():
N = int(input().strip())
X = input().strip()
return N, X
def bitdiv(N:int, X:str, d:int):
q = 0
for i in range(N):
q <<= 1
q |= int(X[i])
p, q = divmod(q, d)
return q
def solve(N, X):
BP = [0 for i in range(N)]
BM = [0 for i in range(N)]
c = X.count("1")
# 2^k mod (c+1) を高速に求める
qp = int(X, base=2) % (c+1)
BP[N-1] = 1 % (c+1)
for i in range(N-2, -1, -1):
BP[i] = (BP[i+1] * 2) % (c+1)
# 2^k mod (c-1) を高速に求める
if c > 1:
qm = int(X, base=2) % (c-1)
BM[N-1] = 1 % (c-1)
for i in range(N-2, -1, -1):
BM[i] = (BM[i+1] * 2) % (c-1)
for i in range(N):
q = 0
ans = 0
if X[i] == "0":
# X_i \equiv (X + 2^i)
q = (qp + BP[i]) % (c+1)
ans += 1
elif X[i] == "1" and c > 1:
# X_i \equiv (X - 2^i)
q = (qm - BM[i]) % (c-1)
ans += 1
else:
q = 0
ans = 0
while q > 0:
q %= (bin(q).count("1"))
ans += 1
print(ans)
if __name__ == '__main__':
inputs = read()
outputs = solve(*inputs)
if outputs is not None:
print(("%s" % str(outputs)))
| 65 | 65 | 1,380 | 1,390 | import sys
input = sys.stdin.readline
import math
def read():
N = int(input().strip())
X = input().strip()
return N, X
def bitdiv(N: int, X: str, d: int):
q = 0
for i in range(N):
q <<= 1
q |= int(X[i])
p, q = divmod(q, d)
return q
def solve(N, X):
BP = [0 for i in range(N)]
BM = [0 for i in range(N)]
c = X.count("1")
# 2^k mod (c+1) を高速に求める
qp = bitdiv(N, X, c + 1)
BP[N - 1] = 1 % (c + 1)
for i in range(N - 2, -1, -1):
BP[i] = (BP[i + 1] * 2) % (c + 1)
# 2^k mod (c-1) を高速に求める
if c > 1:
qm = bitdiv(N, X, c - 1)
BM[N - 1] = 1 % (c - 1)
for i in range(N - 2, -1, -1):
BM[i] = (BM[i + 1] * 2) % (c - 1)
for i in range(N):
q = 0
ans = 0
if X[i] == "0":
# X_i \equiv (X + 2^i)
q = (qp + BP[i]) % (c + 1)
ans += 1
elif X[i] == "1" and c > 1:
# X_i \equiv (X - 2^i)
q = (qm - BM[i]) % (c - 1)
ans += 1
else:
q = 0
ans = 0
while q > 0:
q %= bin(q).count("1")
ans += 1
print(ans)
if __name__ == "__main__":
inputs = read()
outputs = solve(*inputs)
if outputs is not None:
print(("%s" % str(outputs)))
| import sys
input = sys.stdin.readline
import math
def read():
N = int(input().strip())
X = input().strip()
return N, X
def bitdiv(N: int, X: str, d: int):
q = 0
for i in range(N):
q <<= 1
q |= int(X[i])
p, q = divmod(q, d)
return q
def solve(N, X):
BP = [0 for i in range(N)]
BM = [0 for i in range(N)]
c = X.count("1")
# 2^k mod (c+1) を高速に求める
qp = int(X, base=2) % (c + 1)
BP[N - 1] = 1 % (c + 1)
for i in range(N - 2, -1, -1):
BP[i] = (BP[i + 1] * 2) % (c + 1)
# 2^k mod (c-1) を高速に求める
if c > 1:
qm = int(X, base=2) % (c - 1)
BM[N - 1] = 1 % (c - 1)
for i in range(N - 2, -1, -1):
BM[i] = (BM[i + 1] * 2) % (c - 1)
for i in range(N):
q = 0
ans = 0
if X[i] == "0":
# X_i \equiv (X + 2^i)
q = (qp + BP[i]) % (c + 1)
ans += 1
elif X[i] == "1" and c > 1:
# X_i \equiv (X - 2^i)
q = (qm - BM[i]) % (c - 1)
ans += 1
else:
q = 0
ans = 0
while q > 0:
q %= bin(q).count("1")
ans += 1
print(ans)
if __name__ == "__main__":
inputs = read()
outputs = solve(*inputs)
if outputs is not None:
print(("%s" % str(outputs)))
| false | 0 | [
"- qp = bitdiv(N, X, c + 1)",
"+ qp = int(X, base=2) % (c + 1)",
"- qm = bitdiv(N, X, c - 1)",
"+ qm = int(X, base=2) % (c - 1)"
] | false | 0.046482 | 0.062144 | 0.747979 | [
"s615311107",
"s745991108"
] |
u796942881 | p03286 | python | s617823802 | s954981057 | 24 | 19 | 3,316 | 2,940 | Accepted | Accepted | 20.83 | from collections import deque
S = deque()
def main():
N = int(eval(input()))
while N:
if (abs(N % -2) == 1):
S.appendleft('1')
N -= 1
else:
S.appendleft('0')
N //= -2
if not S:
S.append('0')
print((''.join(list(S))))
return
main()
| def main():
N = int(eval(input()))
S = ""
if N == 0:
print((0))
else:
while N:
if N % 2 != 0:
S = '1' + S
N -= 1
else:
S = '0' + S
N //= -2
print(S)
return
main()
| 24 | 24 | 342 | 314 | from collections import deque
S = deque()
def main():
N = int(eval(input()))
while N:
if abs(N % -2) == 1:
S.appendleft("1")
N -= 1
else:
S.appendleft("0")
N //= -2
if not S:
S.append("0")
print(("".join(list(S))))
return
main()
| def main():
N = int(eval(input()))
S = ""
if N == 0:
print((0))
else:
while N:
if N % 2 != 0:
S = "1" + S
N -= 1
else:
S = "0" + S
N //= -2
print(S)
return
main()
| false | 0 | [
"-from collections import deque",
"-",
"-S = deque()",
"-",
"-",
"- while N:",
"- if abs(N % -2) == 1:",
"- S.appendleft(\"1\")",
"- N -= 1",
"- else:",
"- S.appendleft(\"0\")",
"- N //= -2",
"- if not S:",
"- S.append(\"0\")",
"- print((\"\".join(list(S))))",
"+ S = \"\"",
"+ if N == 0:",
"+ print((0))",
"+ else:",
"+ while N:",
"+ if N % 2 != 0:",
"+ S = \"1\" + S",
"+ N -= 1",
"+ else:",
"+ S = \"0\" + S",
"+ N //= -2",
"+ print(S)"
] | false | 0.040967 | 0.03823 | 1.071581 | [
"s617823802",
"s954981057"
] |
u533039576 | p02642 | python | s719635460 | s088281058 | 130 | 113 | 92,732 | 103,228 | Accepted | Accepted | 13.08 | n = int(eval(input()))
a = list(map(int, input().split()))
a.sort()
cnt = [0] * (a[-1] + 1)
for i in range(n):
cnt[a[i]] += 1
ans = 0
for i in range(1, a[-1] + 1):
if cnt[i] > 0:
if cnt[i] == 1:
ans += 1
for j in range(2, a[-1] + 1):
na = i * j
if na <= a[-1]:
cnt[na] = 0
else:
break
print(ans)
| n = int(eval(input()))
a = list(map(int, input().split()))
b = [0] * (max(a) + 1)
# b[i] = (aの要素がiであるような数)
for i in range(n):
b[a[i]] += 1
ans = 0
for i in range(1, len(b)):
if b[i] > 0:
if b[i] == 1:
ans += 1
# print(i, ans)
for j in range(len(b)):
if i * j >= len(b):
break
b[i * j] = 0
print(ans)
| 21 | 20 | 417 | 400 | n = int(eval(input()))
a = list(map(int, input().split()))
a.sort()
cnt = [0] * (a[-1] + 1)
for i in range(n):
cnt[a[i]] += 1
ans = 0
for i in range(1, a[-1] + 1):
if cnt[i] > 0:
if cnt[i] == 1:
ans += 1
for j in range(2, a[-1] + 1):
na = i * j
if na <= a[-1]:
cnt[na] = 0
else:
break
print(ans)
| n = int(eval(input()))
a = list(map(int, input().split()))
b = [0] * (max(a) + 1)
# b[i] = (aの要素がiであるような数)
for i in range(n):
b[a[i]] += 1
ans = 0
for i in range(1, len(b)):
if b[i] > 0:
if b[i] == 1:
ans += 1
# print(i, ans)
for j in range(len(b)):
if i * j >= len(b):
break
b[i * j] = 0
print(ans)
| false | 4.761905 | [
"-a.sort()",
"-cnt = [0] * (a[-1] + 1)",
"+b = [0] * (max(a) + 1)",
"+# b[i] = (aの要素がiであるような数)",
"- cnt[a[i]] += 1",
"+ b[a[i]] += 1",
"-for i in range(1, a[-1] + 1):",
"- if cnt[i] > 0:",
"- if cnt[i] == 1:",
"+for i in range(1, len(b)):",
"+ if b[i] > 0:",
"+ if b[i] == 1:",
"- for j in range(2, a[-1] + 1):",
"- na = i * j",
"- if na <= a[-1]:",
"- cnt[na] = 0",
"- else:",
"+ # print(i, ans)",
"+ for j in range(len(b)):",
"+ if i * j >= len(b):",
"+ b[i * j] = 0"
] | false | 0.047355 | 0.046476 | 1.018911 | [
"s719635460",
"s088281058"
] |
u832152513 | p02642 | python | s950342999 | s718053062 | 149 | 132 | 132,764 | 132,828 | Accepted | Accepted | 11.41 | n = int(eval(input()))
a = sorted(list(map(int, input().split())))
x = max(a)
dp = [0] * (x+1)
for ai in a:
i = 1
if dp[ai] <= 2:
while i * ai <= x:
dp[i * ai] += 1
i += 1
ans = 0
for ai in a:
if dp[ai] <= 1:
ans += 1
print(ans) | n = int(eval(input()))
a = list(map(int, input().split()))
x = max(a)
dp = [0] * (x+1)
for ai in a:
i = 1
if dp[ai] <= 2:
while i * ai <= x:
dp[i * ai] += 1
i += 1
ans = 0
for ai in a:
if dp[ai] <= 1:
ans += 1
print(ans) | 18 | 18 | 294 | 286 | n = int(eval(input()))
a = sorted(list(map(int, input().split())))
x = max(a)
dp = [0] * (x + 1)
for ai in a:
i = 1
if dp[ai] <= 2:
while i * ai <= x:
dp[i * ai] += 1
i += 1
ans = 0
for ai in a:
if dp[ai] <= 1:
ans += 1
print(ans)
| n = int(eval(input()))
a = list(map(int, input().split()))
x = max(a)
dp = [0] * (x + 1)
for ai in a:
i = 1
if dp[ai] <= 2:
while i * ai <= x:
dp[i * ai] += 1
i += 1
ans = 0
for ai in a:
if dp[ai] <= 1:
ans += 1
print(ans)
| false | 0 | [
"-a = sorted(list(map(int, input().split())))",
"+a = list(map(int, input().split()))"
] | false | 0.070764 | 0.043338 | 1.632834 | [
"s950342999",
"s718053062"
] |
u902040736 | p03448 | python | s472677632 | s819963217 | 62 | 43 | 3,064 | 3,060 | Accepted | Accepted | 30.65 | def check_money(a, b, c, total, results):
if a * 500 + b * 100 + c * 50 == total:
check = str(a) + ',' + str(b) + ',' + str(c)
for result in results:
if check in result:
break
else:
results.append(check)
return results
else:
return results
def main():
coin_a = int(eval(input()))
coin_b = int(eval(input()))
coin_c = int(eval(input()))
total_money = int(eval(input()))
result = list()
for coin_a_count in range(coin_a+1):
if coin_a_count <= coin_a:
for coin_b_count in range(coin_b+1):
if coin_b_count <= coin_b:
for coin_c_count in range(coin_c+1):
if coin_c_count <= coin_c:
result = check_money(coin_a_count, coin_b_count, coin_c_count, total_money, result)
print((result.__len__()))
if __name__ == '__main__':
main()
| def main():
coin_a = int(eval(input()))
coin_b = int(eval(input()))
coin_c = int(eval(input()))
total_money = int(eval(input()))
result_count = 0
for i in range(coin_a+1):
for j in range(coin_b+1):
for k in range(coin_c+1):
if i * 500 + j * 100 + k * 50 == total_money:
result_count += 1
print(result_count)
if __name__ == '__main__':
main()
| 33 | 18 | 961 | 427 | def check_money(a, b, c, total, results):
if a * 500 + b * 100 + c * 50 == total:
check = str(a) + "," + str(b) + "," + str(c)
for result in results:
if check in result:
break
else:
results.append(check)
return results
else:
return results
def main():
coin_a = int(eval(input()))
coin_b = int(eval(input()))
coin_c = int(eval(input()))
total_money = int(eval(input()))
result = list()
for coin_a_count in range(coin_a + 1):
if coin_a_count <= coin_a:
for coin_b_count in range(coin_b + 1):
if coin_b_count <= coin_b:
for coin_c_count in range(coin_c + 1):
if coin_c_count <= coin_c:
result = check_money(
coin_a_count,
coin_b_count,
coin_c_count,
total_money,
result,
)
print((result.__len__()))
if __name__ == "__main__":
main()
| def main():
coin_a = int(eval(input()))
coin_b = int(eval(input()))
coin_c = int(eval(input()))
total_money = int(eval(input()))
result_count = 0
for i in range(coin_a + 1):
for j in range(coin_b + 1):
for k in range(coin_c + 1):
if i * 500 + j * 100 + k * 50 == total_money:
result_count += 1
print(result_count)
if __name__ == "__main__":
main()
| false | 45.454545 | [
"-def check_money(a, b, c, total, results):",
"- if a * 500 + b * 100 + c * 50 == total:",
"- check = str(a) + \",\" + str(b) + \",\" + str(c)",
"- for result in results:",
"- if check in result:",
"- break",
"- else:",
"- results.append(check)",
"- return results",
"- else:",
"- return results",
"-",
"-",
"- result = list()",
"- for coin_a_count in range(coin_a + 1):",
"- if coin_a_count <= coin_a:",
"- for coin_b_count in range(coin_b + 1):",
"- if coin_b_count <= coin_b:",
"- for coin_c_count in range(coin_c + 1):",
"- if coin_c_count <= coin_c:",
"- result = check_money(",
"- coin_a_count,",
"- coin_b_count,",
"- coin_c_count,",
"- total_money,",
"- result,",
"- )",
"- print((result.__len__()))",
"+ result_count = 0",
"+ for i in range(coin_a + 1):",
"+ for j in range(coin_b + 1):",
"+ for k in range(coin_c + 1):",
"+ if i * 500 + j * 100 + k * 50 == total_money:",
"+ result_count += 1",
"+ print(result_count)"
] | false | 0.100806 | 0.07326 | 1.375999 | [
"s472677632",
"s819963217"
] |
u077291787 | p03487 | python | s046122903 | s461461389 | 73 | 67 | 17,780 | 18,728 | Accepted | Accepted | 8.22 | # ABC082C - Good Sequence (ARC087C)
import sys
input = sys.stdin.readline
def main():
n = int(eval(input()))
lst = list(map(int, input().rstrip().split()))
cnt = {}
for i in lst:
if i not in cnt:
cnt[i] = 0
cnt[i] += 1
ans = 0
for i, j in list(cnt.items()):
if i > j:
ans += j
elif i < j:
ans += j - i
print(ans)
if __name__ == "__main__":
main() | # ABC082C - Good Sequence (ARC087C)
from collections import Counter
def main():
N, *A = list(map(int, open(0).read().split()))
C = Counter(A)
ans = sum(j if i > j else j - i for i, j in list(C.items()))
print(ans)
if __name__ == "__main__":
main() | 23 | 13 | 459 | 271 | # ABC082C - Good Sequence (ARC087C)
import sys
input = sys.stdin.readline
def main():
n = int(eval(input()))
lst = list(map(int, input().rstrip().split()))
cnt = {}
for i in lst:
if i not in cnt:
cnt[i] = 0
cnt[i] += 1
ans = 0
for i, j in list(cnt.items()):
if i > j:
ans += j
elif i < j:
ans += j - i
print(ans)
if __name__ == "__main__":
main()
| # ABC082C - Good Sequence (ARC087C)
from collections import Counter
def main():
N, *A = list(map(int, open(0).read().split()))
C = Counter(A)
ans = sum(j if i > j else j - i for i, j in list(C.items()))
print(ans)
if __name__ == "__main__":
main()
| false | 43.478261 | [
"-import sys",
"-",
"-input = sys.stdin.readline",
"+from collections import Counter",
"- n = int(eval(input()))",
"- lst = list(map(int, input().rstrip().split()))",
"- cnt = {}",
"- for i in lst:",
"- if i not in cnt:",
"- cnt[i] = 0",
"- cnt[i] += 1",
"- ans = 0",
"- for i, j in list(cnt.items()):",
"- if i > j:",
"- ans += j",
"- elif i < j:",
"- ans += j - i",
"+ N, *A = list(map(int, open(0).read().split()))",
"+ C = Counter(A)",
"+ ans = sum(j if i > j else j - i for i, j in list(C.items()))"
] | false | 0.168588 | 0.126166 | 1.336235 | [
"s046122903",
"s461461389"
] |
u712429027 | p03319 | python | s660908952 | s876730979 | 107 | 51 | 20,712 | 20,600 | Accepted | Accepted | 52.34 | import sys
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().split())
inl = lambda: list(map(int, input().split()))
out = lambda x: print('\n'.join(map(str, x)))
ceil = lambda a, b: (a + b - 1) // b
n, k = inm()
a = inl()
start = a.index(1)
ans = 10**9
for i in range(max(0, start-k+1), min(n-1, start+k)):
ans = min(ans, ceil(i, k-1) + ceil(n-i-1, k-1))
print(ans)
| import sys
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().split())
inl = lambda: list(map(int, input().split()))
out = lambda x: print('\n'.join(map(str, x)))
ceil = lambda a, b: (a + b - 1) // b
n, k = inm()
a = inl()
print(ceil(n-1, k-1))
| 16 | 12 | 460 | 330 | import sys
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().split())
inl = lambda: list(map(int, input().split()))
out = lambda x: print("\n".join(map(str, x)))
ceil = lambda a, b: (a + b - 1) // b
n, k = inm()
a = inl()
start = a.index(1)
ans = 10**9
for i in range(max(0, start - k + 1), min(n - 1, start + k)):
ans = min(ans, ceil(i, k - 1) + ceil(n - i - 1, k - 1))
print(ans)
| import sys
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().split())
inl = lambda: list(map(int, input().split()))
out = lambda x: print("\n".join(map(str, x)))
ceil = lambda a, b: (a + b - 1) // b
n, k = inm()
a = inl()
print(ceil(n - 1, k - 1))
| false | 25 | [
"-start = a.index(1)",
"-ans = 10**9",
"-for i in range(max(0, start - k + 1), min(n - 1, start + k)):",
"- ans = min(ans, ceil(i, k - 1) + ceil(n - i - 1, k - 1))",
"-print(ans)",
"+print(ceil(n - 1, k - 1))"
] | false | 0.12135 | 0.114856 | 1.056548 | [
"s660908952",
"s876730979"
] |
u391819434 | p02796 | python | s216224312 | s490421269 | 783 | 387 | 89,468 | 42,716 | Accepted | Accepted | 50.57 | N=int(eval(input()))
xl=[list(map(int,input().split()))for _ in range(N)]
arms={}
for x,l in xl:
arms[x-l]=0
arms[x+l]=0
for x,l in xl:
arms[x-l]+=1
arms[x+l]-=1
point={}
for x,l in xl:
point[x-l]=[]
point[x+l]=[]
for x,l in xl:
point[x-l].append(x+l)
ans=N
K=sorted(arms.keys())
now=0
count=[]
for k in K:
now+=arms[k]
for kk in point[k]:
count.append(kk)
for i in range(count.count(k)):
count.remove(k)
if now>=2:
ans-=now-1
now=1
C=sorted(count)[::-1]
for c in C[:-1]:
arms[c]+=1
count.remove(c)
print(ans) | N=int(eval(input()))
xl=[list(map(int,input().split()))for _ in range(N)]
rl=[[x+l,x-l]for x,l in xl]
rl.sort()
now=-10**9
ans=0
for r,l in rl:
if l>=now:
ans+=1
now=r
print(ans) | 35 | 11 | 655 | 202 | N = int(eval(input()))
xl = [list(map(int, input().split())) for _ in range(N)]
arms = {}
for x, l in xl:
arms[x - l] = 0
arms[x + l] = 0
for x, l in xl:
arms[x - l] += 1
arms[x + l] -= 1
point = {}
for x, l in xl:
point[x - l] = []
point[x + l] = []
for x, l in xl:
point[x - l].append(x + l)
ans = N
K = sorted(arms.keys())
now = 0
count = []
for k in K:
now += arms[k]
for kk in point[k]:
count.append(kk)
for i in range(count.count(k)):
count.remove(k)
if now >= 2:
ans -= now - 1
now = 1
C = sorted(count)[::-1]
for c in C[:-1]:
arms[c] += 1
count.remove(c)
print(ans)
| N = int(eval(input()))
xl = [list(map(int, input().split())) for _ in range(N)]
rl = [[x + l, x - l] for x, l in xl]
rl.sort()
now = -(10**9)
ans = 0
for r, l in rl:
if l >= now:
ans += 1
now = r
print(ans)
| false | 68.571429 | [
"-arms = {}",
"-for x, l in xl:",
"- arms[x - l] = 0",
"- arms[x + l] = 0",
"-for x, l in xl:",
"- arms[x - l] += 1",
"- arms[x + l] -= 1",
"-point = {}",
"-for x, l in xl:",
"- point[x - l] = []",
"- point[x + l] = []",
"-for x, l in xl:",
"- point[x - l].append(x + l)",
"-ans = N",
"-K = sorted(arms.keys())",
"-now = 0",
"-count = []",
"-for k in K:",
"- now += arms[k]",
"- for kk in point[k]:",
"- count.append(kk)",
"- for i in range(count.count(k)):",
"- count.remove(k)",
"- if now >= 2:",
"- ans -= now - 1",
"- now = 1",
"- C = sorted(count)[::-1]",
"- for c in C[:-1]:",
"- arms[c] += 1",
"- count.remove(c)",
"+rl = [[x + l, x - l] for x, l in xl]",
"+rl.sort()",
"+now = -(10**9)",
"+ans = 0",
"+for r, l in rl:",
"+ if l >= now:",
"+ ans += 1",
"+ now = r"
] | false | 0.133142 | 0.085644 | 1.554599 | [
"s216224312",
"s490421269"
] |
u597374218 | p03807 | python | s902872149 | s375993126 | 56 | 40 | 14,108 | 11,104 | Accepted | Accepted | 28.57 | N=int(eval(input()))
A=list(map(int,input().split()))
odd=0
for a in A:
if a%2==1:
odd+=1
print(("YES" if odd%2==0 else "NO")) | N=int(eval(input()))
print(("YES" if sum(map(int,input().split()))%2==0 else "NO")) | 7 | 2 | 136 | 76 | N = int(eval(input()))
A = list(map(int, input().split()))
odd = 0
for a in A:
if a % 2 == 1:
odd += 1
print(("YES" if odd % 2 == 0 else "NO"))
| N = int(eval(input()))
print(("YES" if sum(map(int, input().split())) % 2 == 0 else "NO"))
| false | 71.428571 | [
"-A = list(map(int, input().split()))",
"-odd = 0",
"-for a in A:",
"- if a % 2 == 1:",
"- odd += 1",
"-print((\"YES\" if odd % 2 == 0 else \"NO\"))",
"+print((\"YES\" if sum(map(int, input().split())) % 2 == 0 else \"NO\"))"
] | false | 0.076829 | 0.081082 | 0.947555 | [
"s902872149",
"s375993126"
] |
u133936772 | p02603 | python | s454622815 | s107619094 | 35 | 29 | 9,196 | 9,036 | Accepted | Accepted | 17.14 | n,*l=list(map(int,open(0).read().split()))
a,c=1000,0
for i in range(n-1):
s,t=l[i:i+2]
if s>t: a+=c*s; c=0
if s<t: c+=a//s; a-=a//s*s
print((a+c*t)) | n,*l=list(map(int,open(0).read().split()))
a=1000
for i in range(n-1):
s,t=l[i:i+2]
a+=a//s*max(t-s,0)
print(a) | 7 | 6 | 153 | 114 | n, *l = list(map(int, open(0).read().split()))
a, c = 1000, 0
for i in range(n - 1):
s, t = l[i : i + 2]
if s > t:
a += c * s
c = 0
if s < t:
c += a // s
a -= a // s * s
print((a + c * t))
| n, *l = list(map(int, open(0).read().split()))
a = 1000
for i in range(n - 1):
s, t = l[i : i + 2]
a += a // s * max(t - s, 0)
print(a)
| false | 14.285714 | [
"-a, c = 1000, 0",
"+a = 1000",
"- if s > t:",
"- a += c * s",
"- c = 0",
"- if s < t:",
"- c += a // s",
"- a -= a // s * s",
"-print((a + c * t))",
"+ a += a // s * max(t - s, 0)",
"+print(a)"
] | false | 0.136648 | 0.106569 | 1.282247 | [
"s454622815",
"s107619094"
] |
u075012704 | p03504 | python | s482770429 | s938436448 | 866 | 741 | 93,528 | 120,664 | Accepted | Accepted | 14.43 | N, C = list(map(int, input().split()))
TV = [[0]*(2*10**5) for i in range(C)]
for i in range(N):
s, t, c = list(map(int, input().split()))
TV[c-1][2*s-2] += 1
TV[c-1][2*t-1] -= 1
for i in range(C):
for j in range(1, 2*10**5):
TV[i][j] = TV[i][j]+TV[i][j-1]
for i in range(C):
for j in range(1, 2*10**5):
TV[i][j] = min(1, TV[i][j])
ans = 0
for i in range(2*10**5):
tmp = 0
for j in range(C):
tmp += TV[j][i]
ans = max(ans, tmp)
print(ans)
| from itertools import accumulate
N, C = list(map(int, input().split()))
G = [[0] * (10 ** 5 + 1) for i in range(C)]
for i in range(N):
s, t, c = list(map(int, input().split()))
c = c - 1
G[c][s - 1] += 1
G[c][t] -= 1
for i in range(C):
G[i] = list(accumulate(G[i]))
ans = 0
for i in range(10 ** 5 + 1):
tmp = 0
for c in range(C):
tmp += min(1, G[c][i])
ans = max(ans, tmp)
print(ans)
| 23 | 20 | 509 | 434 | N, C = list(map(int, input().split()))
TV = [[0] * (2 * 10**5) for i in range(C)]
for i in range(N):
s, t, c = list(map(int, input().split()))
TV[c - 1][2 * s - 2] += 1
TV[c - 1][2 * t - 1] -= 1
for i in range(C):
for j in range(1, 2 * 10**5):
TV[i][j] = TV[i][j] + TV[i][j - 1]
for i in range(C):
for j in range(1, 2 * 10**5):
TV[i][j] = min(1, TV[i][j])
ans = 0
for i in range(2 * 10**5):
tmp = 0
for j in range(C):
tmp += TV[j][i]
ans = max(ans, tmp)
print(ans)
| from itertools import accumulate
N, C = list(map(int, input().split()))
G = [[0] * (10**5 + 1) for i in range(C)]
for i in range(N):
s, t, c = list(map(int, input().split()))
c = c - 1
G[c][s - 1] += 1
G[c][t] -= 1
for i in range(C):
G[i] = list(accumulate(G[i]))
ans = 0
for i in range(10**5 + 1):
tmp = 0
for c in range(C):
tmp += min(1, G[c][i])
ans = max(ans, tmp)
print(ans)
| false | 13.043478 | [
"+from itertools import accumulate",
"+",
"-TV = [[0] * (2 * 10**5) for i in range(C)]",
"+G = [[0] * (10**5 + 1) for i in range(C)]",
"- TV[c - 1][2 * s - 2] += 1",
"- TV[c - 1][2 * t - 1] -= 1",
"+ c = c - 1",
"+ G[c][s - 1] += 1",
"+ G[c][t] -= 1",
"- for j in range(1, 2 * 10**5):",
"- TV[i][j] = TV[i][j] + TV[i][j - 1]",
"-for i in range(C):",
"- for j in range(1, 2 * 10**5):",
"- TV[i][j] = min(1, TV[i][j])",
"+ G[i] = list(accumulate(G[i]))",
"-for i in range(2 * 10**5):",
"+for i in range(10**5 + 1):",
"- for j in range(C):",
"- tmp += TV[j][i]",
"+ for c in range(C):",
"+ tmp += min(1, G[c][i])"
] | false | 1.030905 | 1.450826 | 0.710565 | [
"s482770429",
"s938436448"
] |
u175034939 | p02900 | python | s044227422 | s727556205 | 400 | 178 | 3,064 | 3,064 | Accepted | Accepted | 55.5 | import math
a, b = list(map(int, input().split()))
def is_prime(num):
if num == 2:
return True
elif num < 3 or num % 2 == 0:
return False
for i in range(3, int(math.sqrt(num)) + 1, 2):
if num % i == 0:
return False
return True
if b > a:
a, b = b, a
c = []
for i in range(1, int(math.sqrt(b))+1):
if a%i == 0 and b%i == 0:
if is_prime(i):
c.append(i)
k = b//i
if a%k == 0:
if is_prime(k):
c.append(k)
print((len(set(c))+1)) | import math
a, b = list(map(int, input().split()))
def is_prime(num):
if num == 2:
return True
elif num < 3 or num % 2 == 0:
return False
for i in range(3, int(math.sqrt(num)) + 1, 2):
if num % i == 0:
return False
return True
if b > a:
a, b = b, a
c = []
for i in range(1, int(math.sqrt(b))+1):
if b%i == 0:
k = b//i
if a%k == 0:
if is_prime(k):
c.append(k)
if a%i == 0:
if is_prime(i):
c.append(i)
print((len(set(c))+1)) | 25 | 26 | 549 | 582 | import math
a, b = list(map(int, input().split()))
def is_prime(num):
if num == 2:
return True
elif num < 3 or num % 2 == 0:
return False
for i in range(3, int(math.sqrt(num)) + 1, 2):
if num % i == 0:
return False
return True
if b > a:
a, b = b, a
c = []
for i in range(1, int(math.sqrt(b)) + 1):
if a % i == 0 and b % i == 0:
if is_prime(i):
c.append(i)
k = b // i
if a % k == 0:
if is_prime(k):
c.append(k)
print((len(set(c)) + 1))
| import math
a, b = list(map(int, input().split()))
def is_prime(num):
if num == 2:
return True
elif num < 3 or num % 2 == 0:
return False
for i in range(3, int(math.sqrt(num)) + 1, 2):
if num % i == 0:
return False
return True
if b > a:
a, b = b, a
c = []
for i in range(1, int(math.sqrt(b)) + 1):
if b % i == 0:
k = b // i
if a % k == 0:
if is_prime(k):
c.append(k)
if a % i == 0:
if is_prime(i):
c.append(i)
print((len(set(c)) + 1))
| false | 3.846154 | [
"- if a % i == 0 and b % i == 0:",
"- if is_prime(i):",
"- c.append(i)",
"- k = b // i",
"- if a % k == 0:",
"- if is_prime(k):",
"- c.append(k)",
"+ if b % i == 0:",
"+ k = b // i",
"+ if a % k == 0:",
"+ if is_prime(k):",
"+ c.append(k)",
"+ if a % i == 0:",
"+ if is_prime(i):",
"+ c.append(i)"
] | false | 0.045993 | 0.204506 | 0.224897 | [
"s044227422",
"s727556205"
] |
u556589653 | p03160 | python | s146286124 | s888716912 | 142 | 131 | 14,692 | 13,976 | Accepted | Accepted | 7.75 | dp = [0]*(110000)
A = int(eval(input()))
h = list(map(int,input().split()))
for i in range(1,A):
if i == 1:
dp[i] = dp[i-1]+abs(h[i]-h[i-1])
else:
dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))
print((dp[A-1])) | N = int(eval(input()))
h = list(map(int,input().split()))
dp = [0] * 110000
for i in range(1,N):
if i == 1:
dp[i] = dp[i-1]+abs(h[i-1]-h[i])
else:
dp[i] = min(dp[i-1]+abs(h[i-1]-h[i]),dp[i-2]+abs(h[i-2]-h[i]))
print((dp[N-1])) | 9 | 9 | 250 | 238 | dp = [0] * (110000)
A = int(eval(input()))
h = list(map(int, input().split()))
for i in range(1, A):
if i == 1:
dp[i] = dp[i - 1] + abs(h[i] - h[i - 1])
else:
dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]))
print((dp[A - 1]))
| N = int(eval(input()))
h = list(map(int, input().split()))
dp = [0] * 110000
for i in range(1, N):
if i == 1:
dp[i] = dp[i - 1] + abs(h[i - 1] - h[i])
else:
dp[i] = min(dp[i - 1] + abs(h[i - 1] - h[i]), dp[i - 2] + abs(h[i - 2] - h[i]))
print((dp[N - 1]))
| false | 0 | [
"-dp = [0] * (110000)",
"-A = int(eval(input()))",
"+N = int(eval(input()))",
"-for i in range(1, A):",
"+dp = [0] * 110000",
"+for i in range(1, N):",
"- dp[i] = dp[i - 1] + abs(h[i] - h[i - 1])",
"+ dp[i] = dp[i - 1] + abs(h[i - 1] - h[i])",
"- dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]))",
"-print((dp[A - 1]))",
"+ dp[i] = min(dp[i - 1] + abs(h[i - 1] - h[i]), dp[i - 2] + abs(h[i - 2] - h[i]))",
"+print((dp[N - 1]))"
] | false | 0.097991 | 0.08312 | 1.178918 | [
"s146286124",
"s888716912"
] |
u657361950 | p02266 | python | s569778337 | s797441089 | 70 | 30 | 6,128 | 6,120 | Accepted | Accepted | 57.14 | s = eval(input())
st1=[]
st2=[]
st3=[]
n=len(s)
lv = 0
for i in range(n):
c=s[i]
if c=='\\':
lv-=1
st1.append(i)
elif c=='/':
lv+=1
if len(st1) > 0:
a = i - st1.pop()
if len(st2)==0 or st2[len(st2)-1]>=lv:
st3.append(a)
else:
t=0
while len(st2)>0 and st2[len(st2)-1]<lv:
st2.pop()
t+=st3.pop()
st3.append(a+t)
st2.append(lv)
else:
if len(st2) > 0:
st2.pop()
st2.append(lv)
st=''
total=0
n = len(st3)
st+=str(n)
for i in range(n):
st+=' '+str(st3[i])
total+=(st3[i])
print(total)
print(st)
| s = eval(input())
st1=[]
st2=[]
st3=[]
n=len(s)
lv = 0
for i in range(n):
c=s[i]
if c=='\\':
lv-=1
st1.append(i)
elif c=='/':
lv+=1
if len(st1) > 0:
a = i - st1.pop()
t=0
while len(st2)>0 and st2[-1]<lv:
st2.pop()
t+=st3.pop()
st3.append(a+t)
st2.append(lv)
else:
if len(st2) > 0:
st2.pop()
st2.append(lv)
st=''
total=0
n = len(st3)
st+=str(n)
for i in range(n):
st+=' '+str(st3[i])
total+=(st3[i])
print(total)
print(st)
| 39 | 36 | 594 | 509 | s = eval(input())
st1 = []
st2 = []
st3 = []
n = len(s)
lv = 0
for i in range(n):
c = s[i]
if c == "\\":
lv -= 1
st1.append(i)
elif c == "/":
lv += 1
if len(st1) > 0:
a = i - st1.pop()
if len(st2) == 0 or st2[len(st2) - 1] >= lv:
st3.append(a)
else:
t = 0
while len(st2) > 0 and st2[len(st2) - 1] < lv:
st2.pop()
t += st3.pop()
st3.append(a + t)
st2.append(lv)
else:
if len(st2) > 0:
st2.pop()
st2.append(lv)
st = ""
total = 0
n = len(st3)
st += str(n)
for i in range(n):
st += " " + str(st3[i])
total += st3[i]
print(total)
print(st)
| s = eval(input())
st1 = []
st2 = []
st3 = []
n = len(s)
lv = 0
for i in range(n):
c = s[i]
if c == "\\":
lv -= 1
st1.append(i)
elif c == "/":
lv += 1
if len(st1) > 0:
a = i - st1.pop()
t = 0
while len(st2) > 0 and st2[-1] < lv:
st2.pop()
t += st3.pop()
st3.append(a + t)
st2.append(lv)
else:
if len(st2) > 0:
st2.pop()
st2.append(lv)
st = ""
total = 0
n = len(st3)
st += str(n)
for i in range(n):
st += " " + str(st3[i])
total += st3[i]
print(total)
print(st)
| false | 7.692308 | [
"- if len(st2) == 0 or st2[len(st2) - 1] >= lv:",
"- st3.append(a)",
"- else:",
"- t = 0",
"- while len(st2) > 0 and st2[len(st2) - 1] < lv:",
"- st2.pop()",
"- t += st3.pop()",
"- st3.append(a + t)",
"+ t = 0",
"+ while len(st2) > 0 and st2[-1] < lv:",
"+ st2.pop()",
"+ t += st3.pop()",
"+ st3.append(a + t)"
] | false | 0.036803 | 0.080684 | 0.456133 | [
"s569778337",
"s797441089"
] |
u325282913 | p02866 | python | s359479255 | s055133669 | 170 | 89 | 16,252 | 84,688 | Accepted | Accepted | 47.65 | N = int(eval(input()))
array = list(map(int, input().split()))
if array[0] != 0:
print((0))
exit()
array.sort()
if 1 in array and len(set(array[1:])) == 1:
print((1))
exit()
if not (2 in array):
print((0))
exit()
if 0 in array[1:]:
print((0))
exit()
index = array.index(2)
count = 1
count_old = array.count(1)
ans = 1
first = array[index]
for i in range(index,N-1):
if first != array[i+1]:
if first != array[i+1] - 1:
print((0))
exit()
ans *= count_old ** count
count_old = count
count = 1
else:
count += 1
first = array[i+1]
ans %= 998244353
ans *= count_old ** count
ans %= 998244353
print(ans) | MOD = 998244353
N = int(eval(input()))
D = list(map(int, input().split()))
if D[0] != 0:
print((0))
exit()
D_2 = [0]*(max(D)+1)
for i in D:
D_2[i] += 1
if D_2[0] != 1:
print((0))
exit()
ans = 1
for i in range(1,max(D)+1):
ans *= D_2[i-1]**D_2[i]
ans %= MOD
print(ans)
| 35 | 17 | 726 | 302 | N = int(eval(input()))
array = list(map(int, input().split()))
if array[0] != 0:
print((0))
exit()
array.sort()
if 1 in array and len(set(array[1:])) == 1:
print((1))
exit()
if not (2 in array):
print((0))
exit()
if 0 in array[1:]:
print((0))
exit()
index = array.index(2)
count = 1
count_old = array.count(1)
ans = 1
first = array[index]
for i in range(index, N - 1):
if first != array[i + 1]:
if first != array[i + 1] - 1:
print((0))
exit()
ans *= count_old**count
count_old = count
count = 1
else:
count += 1
first = array[i + 1]
ans %= 998244353
ans *= count_old**count
ans %= 998244353
print(ans)
| MOD = 998244353
N = int(eval(input()))
D = list(map(int, input().split()))
if D[0] != 0:
print((0))
exit()
D_2 = [0] * (max(D) + 1)
for i in D:
D_2[i] += 1
if D_2[0] != 1:
print((0))
exit()
ans = 1
for i in range(1, max(D) + 1):
ans *= D_2[i - 1] ** D_2[i]
ans %= MOD
print(ans)
| false | 51.428571 | [
"+MOD = 998244353",
"-array = list(map(int, input().split()))",
"-if array[0] != 0:",
"+D = list(map(int, input().split()))",
"+if D[0] != 0:",
"-array.sort()",
"-if 1 in array and len(set(array[1:])) == 1:",
"- print((1))",
"- exit()",
"-if not (2 in array):",
"+D_2 = [0] * (max(D) + 1)",
"+for i in D:",
"+ D_2[i] += 1",
"+if D_2[0] != 1:",
"-if 0 in array[1:]:",
"- print((0))",
"- exit()",
"-index = array.index(2)",
"-count = 1",
"-count_old = array.count(1)",
"-first = array[index]",
"-for i in range(index, N - 1):",
"- if first != array[i + 1]:",
"- if first != array[i + 1] - 1:",
"- print((0))",
"- exit()",
"- ans *= count_old**count",
"- count_old = count",
"- count = 1",
"- else:",
"- count += 1",
"- first = array[i + 1]",
"- ans %= 998244353",
"-ans *= count_old**count",
"-ans %= 998244353",
"+for i in range(1, max(D) + 1):",
"+ ans *= D_2[i - 1] ** D_2[i]",
"+ ans %= MOD"
] | false | 0.046218 | 0.046279 | 0.998674 | [
"s359479255",
"s055133669"
] |
u359358631 | p03861 | python | s898599036 | s326515003 | 34 | 29 | 9,160 | 9,152 | Accepted | Accepted | 14.71 | def main():
a, b, x = list(map(int, input().split()))
ans = b // x - a // x
if a % x == 0:
ans += 1
print(ans)
if __name__ == "__main__":
main()
| def main():
a, b, x = list(map(int, input().split()))
ans = b // x - (a - 1) // x
print(ans)
if __name__ == "__main__":
main()
| 11 | 10 | 180 | 150 | def main():
a, b, x = list(map(int, input().split()))
ans = b // x - a // x
if a % x == 0:
ans += 1
print(ans)
if __name__ == "__main__":
main()
| def main():
a, b, x = list(map(int, input().split()))
ans = b // x - (a - 1) // x
print(ans)
if __name__ == "__main__":
main()
| false | 9.090909 | [
"- ans = b // x - a // x",
"- if a % x == 0:",
"- ans += 1",
"+ ans = b // x - (a - 1) // x"
] | false | 0.086065 | 0.049663 | 1.732977 | [
"s898599036",
"s326515003"
] |
u223646582 | p03608 | python | s160492589 | s715113627 | 643 | 397 | 19,340 | 39,468 | Accepted | Accepted | 38.26 | import itertools
from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
N, M, R = list(map(int, input().split()))
r = [int(i) for i in input().split()]
G = [[10**8]*(N+1) for _ in range(N+1)] # 1-indexed
for _ in range(M):
A, B, C = list(map(int, input().split()))
# 無向グラフ
G[A][B] = C
G[B][A] = C
# 有向グラフ
# G[A][B]=C
dg = csgraph_from_dense(G, null_value=10**8)
d = floyd_warshall(dg)
ans = 10**12
for Q in itertools.permutations(r):
c = 0
for i in range(R-1):
c += d[Q[i]][Q[i+1]]
ans = min(ans, c)
print((int(ans)))
| import itertools
from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
N, M, R = list(map(int, input().split()))
r = [int(i) for i in input().split()]
G = [[10**8]*(N+1) for _ in range(N+1)]
for _ in range(M):
A, B, C = list(map(int, input().split()))
G[A][B] = C
G[B][A] = C
DG = csgraph_from_dense(G, null_value=10**8)
d = floyd_warshall(DG)
ans = 10**8
for route in itertools.permutations(r):
c = 0
for i in range(len(route)-1):
c += d[route[i]][route[i+1]]
ans = min(ans, c)
print((int(ans)))
| 27 | 21 | 595 | 552 | import itertools
from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
N, M, R = list(map(int, input().split()))
r = [int(i) for i in input().split()]
G = [[10**8] * (N + 1) for _ in range(N + 1)] # 1-indexed
for _ in range(M):
A, B, C = list(map(int, input().split()))
# 無向グラフ
G[A][B] = C
G[B][A] = C
# 有向グラフ
# G[A][B]=C
dg = csgraph_from_dense(G, null_value=10**8)
d = floyd_warshall(dg)
ans = 10**12
for Q in itertools.permutations(r):
c = 0
for i in range(R - 1):
c += d[Q[i]][Q[i + 1]]
ans = min(ans, c)
print((int(ans)))
| import itertools
from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
N, M, R = list(map(int, input().split()))
r = [int(i) for i in input().split()]
G = [[10**8] * (N + 1) for _ in range(N + 1)]
for _ in range(M):
A, B, C = list(map(int, input().split()))
G[A][B] = C
G[B][A] = C
DG = csgraph_from_dense(G, null_value=10**8)
d = floyd_warshall(DG)
ans = 10**8
for route in itertools.permutations(r):
c = 0
for i in range(len(route) - 1):
c += d[route[i]][route[i + 1]]
ans = min(ans, c)
print((int(ans)))
| false | 22.222222 | [
"-G = [[10**8] * (N + 1) for _ in range(N + 1)] # 1-indexed",
"+G = [[10**8] * (N + 1) for _ in range(N + 1)]",
"- # 無向グラフ",
"- # 有向グラフ",
"- # G[A][B]=C",
"-dg = csgraph_from_dense(G, null_value=10**8)",
"-d = floyd_warshall(dg)",
"-ans = 10**12",
"-for Q in itertools.permutations(r):",
"+DG = csgraph_from_dense(G, null_value=10**8)",
"+d = floyd_warshall(DG)",
"+ans = 10**8",
"+for route in itertools.permutations(r):",
"- for i in range(R - 1):",
"- c += d[Q[i]][Q[i + 1]]",
"+ for i in range(len(route) - 1):",
"+ c += d[route[i]][route[i + 1]]"
] | false | 0.25324 | 0.242628 | 1.043739 | [
"s160492589",
"s715113627"
] |
u077291787 | p04040 | python | s717701890 | s479117460 | 215 | 179 | 18,804 | 18,804 | Accepted | Accepted | 16.74 | # ARC058D - いろはちゃんとマス目 / Iroha and a Grid (ABC042D)
def get_fact(lim):
# compute a toble of factorials (1-idx)
fact = [1] * (lim + 1)
x = 1
for i in range(1, lim + 1):
x = (x * i) % MOD
fact[i] = x
return fact
def get_inv(lim):
# compute a toble of inverse factorials (1-idx)
inv = [1] * (lim + 1)
inv[lim] = pow(fact[lim], MOD - 2, MOD)
x = inv[lim]
for i in range(lim - 1, 0, -1):
x = (x * (i + 1)) % MOD
inv[i] = x
return inv
def comb(n: int, r: int) -> int:
# compute nCr (n! / r!(n - r)!)
return fact[n] * inv[n - r] * inv[r]
def main():
global MOD, fact, inv
H, W, A, B = tuple(map(int, input().split()))
MOD = 10 ** 9 + 7
fact = get_fact(H + W)
inv = get_inv(H + W)
ans = 0
for i in range(B, W):
ans += comb(i + H - A - 1, i) * comb(W - i - 1 + A - 1, A - 1)
ans %= MOD
print(ans)
if __name__ == "__main__":
main() | # ARC058D - いろはちゃんとマス目 / Iroha and a Grid (ABC042D)
def get_fact(lim):
# compute a toble of factorials (1-idx)
fact = [1] * (lim + 1)
x = 1
for i in range(1, lim + 1):
x = (x * i) % MOD
fact[i] = x
return fact
def get_inv(lim):
# compute a toble of inverse factorials (1-idx)
inv = [1] * (lim + 1)
inv[lim] = pow(fact[lim], MOD - 2, MOD)
x = inv[lim]
for i in range(lim - 1, 0, -1):
x = (x * (i + 1)) % MOD
inv[i] = x
return inv
def comb(n: int, r: int) -> int:
# compute nCr (n! / r!(n - r)!)
return fact[n] * inv[n - r] * inv[r]
def main():
global MOD, fact, inv
H, W, A, B = tuple(map(int, input().split()))
MOD = 10 ** 9 + 7
fact = get_fact(H + W)
inv = get_inv(H + W)
ans = 0
x, y = H - A - 1, W + A - 2
for i in range(B, W):
ans += comb(x + i, i) * comb(y - i, A - 1)
ans %= MOD
print(ans)
if __name__ == "__main__":
main() | 40 | 41 | 1,002 | 1,011 | # ARC058D - いろはちゃんとマス目 / Iroha and a Grid (ABC042D)
def get_fact(lim):
# compute a toble of factorials (1-idx)
fact = [1] * (lim + 1)
x = 1
for i in range(1, lim + 1):
x = (x * i) % MOD
fact[i] = x
return fact
def get_inv(lim):
# compute a toble of inverse factorials (1-idx)
inv = [1] * (lim + 1)
inv[lim] = pow(fact[lim], MOD - 2, MOD)
x = inv[lim]
for i in range(lim - 1, 0, -1):
x = (x * (i + 1)) % MOD
inv[i] = x
return inv
def comb(n: int, r: int) -> int:
# compute nCr (n! / r!(n - r)!)
return fact[n] * inv[n - r] * inv[r]
def main():
global MOD, fact, inv
H, W, A, B = tuple(map(int, input().split()))
MOD = 10**9 + 7
fact = get_fact(H + W)
inv = get_inv(H + W)
ans = 0
for i in range(B, W):
ans += comb(i + H - A - 1, i) * comb(W - i - 1 + A - 1, A - 1)
ans %= MOD
print(ans)
if __name__ == "__main__":
main()
| # ARC058D - いろはちゃんとマス目 / Iroha and a Grid (ABC042D)
def get_fact(lim):
# compute a toble of factorials (1-idx)
fact = [1] * (lim + 1)
x = 1
for i in range(1, lim + 1):
x = (x * i) % MOD
fact[i] = x
return fact
def get_inv(lim):
# compute a toble of inverse factorials (1-idx)
inv = [1] * (lim + 1)
inv[lim] = pow(fact[lim], MOD - 2, MOD)
x = inv[lim]
for i in range(lim - 1, 0, -1):
x = (x * (i + 1)) % MOD
inv[i] = x
return inv
def comb(n: int, r: int) -> int:
# compute nCr (n! / r!(n - r)!)
return fact[n] * inv[n - r] * inv[r]
def main():
global MOD, fact, inv
H, W, A, B = tuple(map(int, input().split()))
MOD = 10**9 + 7
fact = get_fact(H + W)
inv = get_inv(H + W)
ans = 0
x, y = H - A - 1, W + A - 2
for i in range(B, W):
ans += comb(x + i, i) * comb(y - i, A - 1)
ans %= MOD
print(ans)
if __name__ == "__main__":
main()
| false | 2.439024 | [
"+ x, y = H - A - 1, W + A - 2",
"- ans += comb(i + H - A - 1, i) * comb(W - i - 1 + A - 1, A - 1)",
"- ans %= MOD",
"+ ans += comb(x + i, i) * comb(y - i, A - 1)",
"+ ans %= MOD"
] | false | 0.200572 | 0.126467 | 1.585961 | [
"s717701890",
"s479117460"
] |
u063052907 | p04045 | python | s554188017 | s584895563 | 50 | 45 | 3,316 | 3,316 | Accepted | Accepted | 10 | def judge(lst_D, number):
str_number = str(number)
for d in lst_D:
if d in str_number:
return False
return True
def main():
N, K = list(map(int, input().split()))
lst_D = list(input().split())
cost = N
while True:
if judge(lst_D, cost):
print(cost)
break
cost += 1
if __name__ == "__main__":
main() | def main():
N, K = list(map(int, input().split()))
lst_D = list(input().split())
cost = N
while True:
for c in str(cost):
if c in lst_D:
break
else: # break しなかったときのみ実行される
print(cost)
break
cost += 1
if __name__ == "__main__":
main() | 22 | 17 | 410 | 344 | def judge(lst_D, number):
str_number = str(number)
for d in lst_D:
if d in str_number:
return False
return True
def main():
N, K = list(map(int, input().split()))
lst_D = list(input().split())
cost = N
while True:
if judge(lst_D, cost):
print(cost)
break
cost += 1
if __name__ == "__main__":
main()
| def main():
N, K = list(map(int, input().split()))
lst_D = list(input().split())
cost = N
while True:
for c in str(cost):
if c in lst_D:
break
else: # break しなかったときのみ実行される
print(cost)
break
cost += 1
if __name__ == "__main__":
main()
| false | 22.727273 | [
"-def judge(lst_D, number):",
"- str_number = str(number)",
"- for d in lst_D:",
"- if d in str_number:",
"- return False",
"- return True",
"-",
"-",
"- if judge(lst_D, cost):",
"+ for c in str(cost):",
"+ if c in lst_D:",
"+ break",
"+ else: # break しなかったときのみ実行される"
] | false | 0.115257 | 0.043018 | 2.679245 | [
"s554188017",
"s584895563"
] |
u566529875 | p03222 | python | s995024611 | s512896579 | 92 | 19 | 3,192 | 3,064 | Accepted | Accepted | 79.35 | h,w,kk = list(map(int,input().split()))
dp = [[[] for j in range(w)] for i in range(h+1)]
# dp[i][j]
# 高さiにおいて点jに行き得る通り数
for i in range(h+1):
for j in range(w):
dp[i][j] = 0
dp[0][0]=1
mod = 1000000007
for i in range(1,h+1):
for j in range(1<<(w-1)):
yoko = [False for loo in range(w)]
for k in range((w-1)):
yoko[k] = True if ((j>>k)&1) else False
ok = True
for l in range(w-2):
if(yoko[l]==True and yoko[l+1]==True):
ok = False
if(not ok):
continue
for l in range(w):
if(l==0):
if(yoko[l]):
dp[i][l] += dp[i-1][l+1]
else:
dp[i][l] += dp[i-1][l]
dp[i][l]%=mod
continue
if(l==w-1):
if(yoko[l-1]):
dp[i][l] += dp[i-1][l-1]
else:
dp[i][l] += dp[i-1][l]
dp[i][l]%=mod
continue
if(yoko[l-1] or yoko[l]):
if(yoko[l-1]):
dp[i][l]+= dp[i-1][l-1]
else:
dp[i][l]+= dp[i-1][l+1]
else:
dp[i][l] += dp[i-1][l]
dp[i][l]%=mod
print((dp[h][kk-1])) | mod = 10**9+7
h,w,k = list(map(int,input().split()))
dp =[[0]*w for _ in range(h+1)]
dp[0][0]=1
fibo=[1]*10
for i in range(2,10):
fibo[i] = fibo[i-2]+fibo[i-1]
for i in range(1,h+1):
for j in range(w):
dp[i][j] = dp[i-1][j]*fibo[j]*fibo[w-j-1]%mod
if(j>0):
dp[i][j] += dp[i-1][j-1]*fibo[j-1]*fibo[w-j-1]%mod
dp[i][j] %= mod
if(j<w-1):
dp[i][j] += dp[i-1][j+1]*fibo[j]*fibo[w-j-2]%mod
dp[i][j]%=mod
print((dp[h][k-1])) | 49 | 17 | 1,909 | 585 | h, w, kk = list(map(int, input().split()))
dp = [[[] for j in range(w)] for i in range(h + 1)]
# dp[i][j]
# 高さiにおいて点jに行き得る通り数
for i in range(h + 1):
for j in range(w):
dp[i][j] = 0
dp[0][0] = 1
mod = 1000000007
for i in range(1, h + 1):
for j in range(1 << (w - 1)):
yoko = [False for loo in range(w)]
for k in range((w - 1)):
yoko[k] = True if ((j >> k) & 1) else False
ok = True
for l in range(w - 2):
if yoko[l] == True and yoko[l + 1] == True:
ok = False
if not ok:
continue
for l in range(w):
if l == 0:
if yoko[l]:
dp[i][l] += dp[i - 1][l + 1]
else:
dp[i][l] += dp[i - 1][l]
dp[i][l] %= mod
continue
if l == w - 1:
if yoko[l - 1]:
dp[i][l] += dp[i - 1][l - 1]
else:
dp[i][l] += dp[i - 1][l]
dp[i][l] %= mod
continue
if yoko[l - 1] or yoko[l]:
if yoko[l - 1]:
dp[i][l] += dp[i - 1][l - 1]
else:
dp[i][l] += dp[i - 1][l + 1]
else:
dp[i][l] += dp[i - 1][l]
dp[i][l] %= mod
print((dp[h][kk - 1]))
| mod = 10**9 + 7
h, w, k = list(map(int, input().split()))
dp = [[0] * w for _ in range(h + 1)]
dp[0][0] = 1
fibo = [1] * 10
for i in range(2, 10):
fibo[i] = fibo[i - 2] + fibo[i - 1]
for i in range(1, h + 1):
for j in range(w):
dp[i][j] = dp[i - 1][j] * fibo[j] * fibo[w - j - 1] % mod
if j > 0:
dp[i][j] += dp[i - 1][j - 1] * fibo[j - 1] * fibo[w - j - 1] % mod
dp[i][j] %= mod
if j < w - 1:
dp[i][j] += dp[i - 1][j + 1] * fibo[j] * fibo[w - j - 2] % mod
dp[i][j] %= mod
print((dp[h][k - 1]))
| false | 65.306122 | [
"-h, w, kk = list(map(int, input().split()))",
"-dp = [[[] for j in range(w)] for i in range(h + 1)]",
"-# dp[i][j]",
"-# 高さiにおいて点jに行き得る通り数",
"-for i in range(h + 1):",
"+mod = 10**9 + 7",
"+h, w, k = list(map(int, input().split()))",
"+dp = [[0] * w for _ in range(h + 1)]",
"+dp[0][0] = 1",
"+fibo = [1] * 10",
"+for i in range(2, 10):",
"+ fibo[i] = fibo[i - 2] + fibo[i - 1]",
"+for i in range(1, h + 1):",
"- dp[i][j] = 0",
"-dp[0][0] = 1",
"-mod = 1000000007",
"-for i in range(1, h + 1):",
"- for j in range(1 << (w - 1)):",
"- yoko = [False for loo in range(w)]",
"- for k in range((w - 1)):",
"- yoko[k] = True if ((j >> k) & 1) else False",
"- ok = True",
"- for l in range(w - 2):",
"- if yoko[l] == True and yoko[l + 1] == True:",
"- ok = False",
"- if not ok:",
"- continue",
"- for l in range(w):",
"- if l == 0:",
"- if yoko[l]:",
"- dp[i][l] += dp[i - 1][l + 1]",
"- else:",
"- dp[i][l] += dp[i - 1][l]",
"- dp[i][l] %= mod",
"- continue",
"- if l == w - 1:",
"- if yoko[l - 1]:",
"- dp[i][l] += dp[i - 1][l - 1]",
"- else:",
"- dp[i][l] += dp[i - 1][l]",
"- dp[i][l] %= mod",
"- continue",
"- if yoko[l - 1] or yoko[l]:",
"- if yoko[l - 1]:",
"- dp[i][l] += dp[i - 1][l - 1]",
"- else:",
"- dp[i][l] += dp[i - 1][l + 1]",
"- else:",
"- dp[i][l] += dp[i - 1][l]",
"- dp[i][l] %= mod",
"-print((dp[h][kk - 1]))",
"+ dp[i][j] = dp[i - 1][j] * fibo[j] * fibo[w - j - 1] % mod",
"+ if j > 0:",
"+ dp[i][j] += dp[i - 1][j - 1] * fibo[j - 1] * fibo[w - j - 1] % mod",
"+ dp[i][j] %= mod",
"+ if j < w - 1:",
"+ dp[i][j] += dp[i - 1][j + 1] * fibo[j] * fibo[w - j - 2] % mod",
"+ dp[i][j] %= mod",
"+print((dp[h][k - 1]))"
] | false | 0.006981 | 0.039802 | 0.175394 | [
"s995024611",
"s512896579"
] |
u325282913 | p03266 | python | s091114694 | s313422372 | 101 | 52 | 4,596 | 4,596 | Accepted | Accepted | 48.51 | N, K = list(map(int,input().split()))
arr = [0]*K
ans = 0
for i in range(1,N+1):
arr[i%K] += 1
for a in range(K):
b = (K-a) % K
c = (K-a) % K
if (b+c) % K == 0:
ans += arr[a] * arr[b] * arr[c]
print(ans) | N, K = list(map(int, input().split()))
arr = [0]*K
for i in range(1,N+1):
arr[i%K] += 1
print((arr[0]**3 if K%2!=0 else arr[0]**3+arr[K//2]**3)) | 11 | 5 | 231 | 144 | N, K = list(map(int, input().split()))
arr = [0] * K
ans = 0
for i in range(1, N + 1):
arr[i % K] += 1
for a in range(K):
b = (K - a) % K
c = (K - a) % K
if (b + c) % K == 0:
ans += arr[a] * arr[b] * arr[c]
print(ans)
| N, K = list(map(int, input().split()))
arr = [0] * K
for i in range(1, N + 1):
arr[i % K] += 1
print((arr[0] ** 3 if K % 2 != 0 else arr[0] ** 3 + arr[K // 2] ** 3))
| false | 54.545455 | [
"-ans = 0",
"-for a in range(K):",
"- b = (K - a) % K",
"- c = (K - a) % K",
"- if (b + c) % K == 0:",
"- ans += arr[a] * arr[b] * arr[c]",
"-print(ans)",
"+print((arr[0] ** 3 if K % 2 != 0 else arr[0] ** 3 + arr[K // 2] ** 3))"
] | false | 0.045413 | 0.204116 | 0.222489 | [
"s091114694",
"s313422372"
] |
u323045245 | p03835 | python | s987532949 | s189982865 | 1,710 | 1,275 | 2,940 | 2,940 | Accepted | Accepted | 25.44 | K, S = list(map(int, input().split(' ')))
count = 0
for i in range(K+1):
for j in range(K+1):
if S - i - j <= K and S - i - j >= 0:
count += 1
print(count)
| k, s = list(map(int, input().split()))
count = 0
for x in range(k+1):
for y in range(k+1):
if (k>=s-x-y>=0):
count += 1
print(count)
| 8 | 7 | 172 | 157 | K, S = list(map(int, input().split(" ")))
count = 0
for i in range(K + 1):
for j in range(K + 1):
if S - i - j <= K and S - i - j >= 0:
count += 1
print(count)
| k, s = list(map(int, input().split()))
count = 0
for x in range(k + 1):
for y in range(k + 1):
if k >= s - x - y >= 0:
count += 1
print(count)
| false | 12.5 | [
"-K, S = list(map(int, input().split(\" \")))",
"+k, s = list(map(int, input().split()))",
"-for i in range(K + 1):",
"- for j in range(K + 1):",
"- if S - i - j <= K and S - i - j >= 0:",
"+for x in range(k + 1):",
"+ for y in range(k + 1):",
"+ if k >= s - x - y >= 0:"
] | false | 0.045644 | 0.044475 | 1.026284 | [
"s987532949",
"s189982865"
] |
u593567568 | p02911 | python | s893229140 | s312298095 | 260 | 213 | 8,632 | 9,760 | Accepted | Accepted | 18.08 | N,K,Q = list(map(int,input().split()))
ANS = [0] * N
A = [int(eval(input())) for _ in range(Q)]
for a in A:
ANS[a-1] += 1
for i in range(N):
p = K - Q + ANS[i]
if p <= 0:
print('No')
else:
print('Yes')
exit()
| N,K,Q = list(map(int,input().split()))
ANS = [0] * N
A = [int(eval(input())) for _ in range(Q)]
for a in A:
ANS[a-1] += 1
R = []
for i in range(N):
p = K - Q + ANS[i]
if p <= 0:
R.append('No')
else:
R.append('Yes')
print(('\n'.join(R)))
| 14 | 15 | 234 | 261 | N, K, Q = list(map(int, input().split()))
ANS = [0] * N
A = [int(eval(input())) for _ in range(Q)]
for a in A:
ANS[a - 1] += 1
for i in range(N):
p = K - Q + ANS[i]
if p <= 0:
print("No")
else:
print("Yes")
exit()
| N, K, Q = list(map(int, input().split()))
ANS = [0] * N
A = [int(eval(input())) for _ in range(Q)]
for a in A:
ANS[a - 1] += 1
R = []
for i in range(N):
p = K - Q + ANS[i]
if p <= 0:
R.append("No")
else:
R.append("Yes")
print(("\n".join(R)))
| false | 6.666667 | [
"+R = []",
"- print(\"No\")",
"+ R.append(\"No\")",
"- print(\"Yes\")",
"-exit()",
"+ R.append(\"Yes\")",
"+print((\"\\n\".join(R)))"
] | false | 0.047116 | 0.08409 | 0.560305 | [
"s893229140",
"s312298095"
] |
u761320129 | p02713 | python | s102698609 | s316588316 | 1,173 | 198 | 9,176 | 68,412 | Accepted | Accepted | 83.12 | from math import gcd
K = int(eval(input()))
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) | from math import gcd
K = int(eval(input()))
ans = 0
for i in range(1,K+1):
for j in range(1,K+1):
g = gcd(i,j)
for k in range(1,K+1):
ans += gcd(g,k)
print(ans) | 10 | 9 | 196 | 194 | from math import gcd
K = int(eval(input()))
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)
| from math import gcd
K = int(eval(input()))
ans = 0
for i in range(1, K + 1):
for j in range(1, K + 1):
g = gcd(i, j)
for k in range(1, K + 1):
ans += gcd(g, k)
print(ans)
| false | 10 | [
"-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)",
"+for i in range(1, K + 1):",
"+ for j in range(1, K + 1):",
"+ g = gcd(i, j)",
"+ for k in range(1, K + 1):",
"+ ans += gcd(g, k)"
] | false | 0.150053 | 0.233321 | 0.643117 | [
"s102698609",
"s316588316"
] |
u790012205 | p03449 | python | s085328542 | s345528890 | 167 | 17 | 38,512 | 3,060 | Accepted | Accepted | 89.82 | N = int(eval(input()))
A1 = list((list(map(int, input().split()))))
A2 = list((list(map(int, input().split()))))
Cmax = 0
for i in range(N):
C = sum(A1[:i + 1]) + sum(A2[i:])
Cmax = max(Cmax, C)
print(Cmax) | N = int(eval(input()))
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))
C = 0
c = 0
for i in range(N):
c = sum(A1[:i + 1]) + sum(A2[i:])
C = max(C, c)
print(C) | 8 | 9 | 203 | 198 | N = int(eval(input()))
A1 = list((list(map(int, input().split()))))
A2 = list((list(map(int, input().split()))))
Cmax = 0
for i in range(N):
C = sum(A1[: i + 1]) + sum(A2[i:])
Cmax = max(Cmax, C)
print(Cmax)
| N = int(eval(input()))
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))
C = 0
c = 0
for i in range(N):
c = sum(A1[: i + 1]) + sum(A2[i:])
C = max(C, c)
print(C)
| false | 11.111111 | [
"-A1 = list((list(map(int, input().split()))))",
"-A2 = list((list(map(int, input().split()))))",
"-Cmax = 0",
"+A1 = list(map(int, input().split()))",
"+A2 = list(map(int, input().split()))",
"+C = 0",
"+c = 0",
"- C = sum(A1[: i + 1]) + sum(A2[i:])",
"- Cmax = max(Cmax, C)",
"-print(Cmax)",
"+ c = sum(A1[: i + 1]) + sum(A2[i:])",
"+ C = max(C, c)",
"+print(C)"
] | false | 0.133279 | 0.0359 | 3.712522 | [
"s085328542",
"s345528890"
] |
u273262677 | p02773 | python | s749683455 | s694922283 | 624 | 354 | 37,136 | 38,476 | Accepted | Accepted | 43.27 | l =[]
r=[]
n = int(input())
for i in range(n):
l.append(input())
d={}
for i in l:
if i in d:
d[i]+=1
else:
d[i]=1
print()
m = max(d.values())
for key,value in d.items():
if value==m:
r.append(key)
sorted_r = sorted(r)
print(*sorted_r,sep='\n')
| from collections import Counter
import sys
n = int(sys.stdin.readline())
sn = sys.stdin.read().split()
c = Counter(sn)
num = max(c.values())
ans = [i for i, j in list(c.items()) if j == num]
ans.sort()
print(('\n'.join(ans))) | 18 | 9 | 300 | 225 | l = []
r = []
n = int(input())
for i in range(n):
l.append(input())
d = {}
for i in l:
if i in d:
d[i] += 1
else:
d[i] = 1
print()
m = max(d.values())
for key, value in d.items():
if value == m:
r.append(key)
sorted_r = sorted(r)
print(*sorted_r, sep="\n")
| from collections import Counter
import sys
n = int(sys.stdin.readline())
sn = sys.stdin.read().split()
c = Counter(sn)
num = max(c.values())
ans = [i for i, j in list(c.items()) if j == num]
ans.sort()
print(("\n".join(ans)))
| false | 50 | [
"-l = []",
"-r = []",
"-n = int(input())",
"-for i in range(n):",
"- l.append(input())",
"-d = {}",
"-for i in l:",
"- if i in d:",
"- d[i] += 1",
"- else:",
"- d[i] = 1",
"-print()",
"-m = max(d.values())",
"-for key, value in d.items():",
"- if value == m:",
"- r.append(key)",
"-sorted_r = sorted(r)",
"-print(*sorted_r, sep=\"\\n\")",
"+from collections import Counter",
"+import sys",
"+",
"+n = int(sys.stdin.readline())",
"+sn = sys.stdin.read().split()",
"+c = Counter(sn)",
"+num = max(c.values())",
"+ans = [i for i, j in list(c.items()) if j == num]",
"+ans.sort()",
"+print((\"\\n\".join(ans)))"
] | false | 0.036701 | 0.035822 | 1.024524 | [
"s749683455",
"s694922283"
] |
u333945892 | p03878 | python | s707000576 | s780310893 | 847 | 605 | 31,940 | 32,928 | Accepted | Accepted | 28.57 | from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
N = int(eval(input()))
points = []
for i in range(N):
a = int(eval(input()))
points.append([a,True])
for i in range(N):
b = int(eval(input()))
points.append([b,False])
points.sort()
ans = 1
an = bn = 0
for x,c in points:
if c:
if bn > 0:
ans = (ans*bn)%mod
bn -= 1
else:
an += 1
else:
if an > 0:
ans = (ans*an)%mod
an -= 1
else:
bn += 1
print((ans%mod))
| from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
N = inp()
ab = []
for i in range(N):
a = inp()
ab.append([a,1])
for i in range(N):
b = inp()
ab.append([b,-1])
ab.sort()
cnt = 0
ans = 1
for x,k in ab:
cnt += k
if (cnt > 0) and (k > 0):
ans *= cnt
elif (cnt < 0) and (k < 0):
ans *= -cnt
ans %= mod
print((ans%mod))
| 36 | 33 | 771 | 698 | from collections import defaultdict, deque
import sys, heapq, bisect, math, itertools, string, queue, datetime
sys.setrecursionlimit(10**8)
INF = float("inf")
mod = 10**9 + 7
eps = 10**-7
def inpl():
return list(map(int, input().split()))
def inpls():
return list(input().split())
N = int(eval(input()))
points = []
for i in range(N):
a = int(eval(input()))
points.append([a, True])
for i in range(N):
b = int(eval(input()))
points.append([b, False])
points.sort()
ans = 1
an = bn = 0
for x, c in points:
if c:
if bn > 0:
ans = (ans * bn) % mod
bn -= 1
else:
an += 1
else:
if an > 0:
ans = (ans * an) % mod
an -= 1
else:
bn += 1
print((ans % mod))
| from collections import defaultdict, deque
import sys, heapq, bisect, math, itertools, string, queue, copy, time
sys.setrecursionlimit(10**8)
INF = float("inf")
mod = 10**9 + 7
eps = 10**-7
def inp():
return int(sys.stdin.readline())
def inpl():
return list(map(int, sys.stdin.readline().split()))
def inpl_str():
return list(sys.stdin.readline().split())
N = inp()
ab = []
for i in range(N):
a = inp()
ab.append([a, 1])
for i in range(N):
b = inp()
ab.append([b, -1])
ab.sort()
cnt = 0
ans = 1
for x, k in ab:
cnt += k
if (cnt > 0) and (k > 0):
ans *= cnt
elif (cnt < 0) and (k < 0):
ans *= -cnt
ans %= mod
print((ans % mod))
| false | 8.333333 | [
"-import sys, heapq, bisect, math, itertools, string, queue, datetime",
"+import sys, heapq, bisect, math, itertools, string, queue, copy, time",
"-def inpl():",
"- return list(map(int, input().split()))",
"+def inp():",
"+ return int(sys.stdin.readline())",
"-def inpls():",
"- return list(input().split())",
"+def inpl():",
"+ return list(map(int, sys.stdin.readline().split()))",
"-N = int(eval(input()))",
"-points = []",
"+def inpl_str():",
"+ return list(sys.stdin.readline().split())",
"+",
"+",
"+N = inp()",
"+ab = []",
"- a = int(eval(input()))",
"- points.append([a, True])",
"+ a = inp()",
"+ ab.append([a, 1])",
"- b = int(eval(input()))",
"- points.append([b, False])",
"-points.sort()",
"+ b = inp()",
"+ ab.append([b, -1])",
"+ab.sort()",
"+cnt = 0",
"-an = bn = 0",
"-for x, c in points:",
"- if c:",
"- if bn > 0:",
"- ans = (ans * bn) % mod",
"- bn -= 1",
"- else:",
"- an += 1",
"- else:",
"- if an > 0:",
"- ans = (ans * an) % mod",
"- an -= 1",
"- else:",
"- bn += 1",
"+for x, k in ab:",
"+ cnt += k",
"+ if (cnt > 0) and (k > 0):",
"+ ans *= cnt",
"+ elif (cnt < 0) and (k < 0):",
"+ ans *= -cnt",
"+ ans %= mod"
] | false | 0.089031 | 0.100562 | 0.885339 | [
"s707000576",
"s780310893"
] |
u977661421 | p03107 | python | s433612596 | s366996161 | 22 | 18 | 3,956 | 3,188 | Accepted | Accepted | 18.18 | # -*- coding: utf-8 -*-
s = list(eval(input()))
ans = min(s.count('0'), s.count('1'))
print((ans * 2))
| # -*- coding: utf-8 -*-
s = eval(input())
ans = 2 * (min(s.count('0'), s.count('1')))
print(ans)
| 5 | 5 | 100 | 96 | # -*- coding: utf-8 -*-
s = list(eval(input()))
ans = min(s.count("0"), s.count("1"))
print((ans * 2))
| # -*- coding: utf-8 -*-
s = eval(input())
ans = 2 * (min(s.count("0"), s.count("1")))
print(ans)
| false | 0 | [
"-s = list(eval(input()))",
"-ans = min(s.count(\"0\"), s.count(\"1\"))",
"-print((ans * 2))",
"+s = eval(input())",
"+ans = 2 * (min(s.count(\"0\"), s.count(\"1\")))",
"+print(ans)"
] | false | 0.042872 | 0.170394 | 0.251607 | [
"s433612596",
"s366996161"
] |
u948524308 | p03495 | python | s945522875 | s190838986 | 185 | 111 | 45,332 | 25,644 | Accepted | Accepted | 40 | N,K = list(map(int,input().split()))
A =list(map(int,input().split()))
num = [0]*2000001
for i in range(N):
num[A[i]] +=1
V = 2000001 - num.count(0)
if V <=K:
print((0))
else:
num.sort()
num.reverse()
print((sum(num[K:]))) | N,K = list(map(int,input().split()))
A =list(map(int,input().split()))
num = [0]*(N+1)
for i in range(N):
num[A[i]] +=1
V = N+1 - num.count(0)
if V <=K:
print((0))
else:
num.sort()
num.reverse()
print((sum(num[K:]))) | 16 | 16 | 251 | 245 | N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
num = [0] * 2000001
for i in range(N):
num[A[i]] += 1
V = 2000001 - num.count(0)
if V <= K:
print((0))
else:
num.sort()
num.reverse()
print((sum(num[K:])))
| N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
num = [0] * (N + 1)
for i in range(N):
num[A[i]] += 1
V = N + 1 - num.count(0)
if V <= K:
print((0))
else:
num.sort()
num.reverse()
print((sum(num[K:])))
| false | 0 | [
"-num = [0] * 2000001",
"+num = [0] * (N + 1)",
"-V = 2000001 - num.count(0)",
"+V = N + 1 - num.count(0)"
] | false | 0.116132 | 0.035723 | 3.250906 | [
"s945522875",
"s190838986"
] |
u408071652 | p02924 | python | s168983938 | s854833960 | 109 | 69 | 64,280 | 64,696 | Accepted | Accepted | 36.7 | import sys
from collections import deque
import itertools
from collections import deque
sys.setrecursionlimit(10 ** 9)
# map(int, sys.stdin.read().split())
def input():
return sys.stdin.readline().rstrip()
def main():
N = int(eval(input()))
print((int(N*(N-1)//2)))
if __name__ == "__main__":
main()
| import sys
from collections import deque
import itertools
from collections import deque
sys.setrecursionlimit(10 ** 9)
# map(int, sys.stdin.read().split())
def input():
return sys.stdin.readline().rstrip()
def main():
N = int(eval(input()))
print((N*(N-1)//2))
if __name__ == "__main__":
main()
| 22 | 22 | 338 | 333 | import sys
from collections import deque
import itertools
from collections import deque
sys.setrecursionlimit(10**9)
# map(int, sys.stdin.read().split())
def input():
return sys.stdin.readline().rstrip()
def main():
N = int(eval(input()))
print((int(N * (N - 1) // 2)))
if __name__ == "__main__":
main()
| import sys
from collections import deque
import itertools
from collections import deque
sys.setrecursionlimit(10**9)
# map(int, sys.stdin.read().split())
def input():
return sys.stdin.readline().rstrip()
def main():
N = int(eval(input()))
print((N * (N - 1) // 2))
if __name__ == "__main__":
main()
| false | 0 | [
"- print((int(N * (N - 1) // 2)))",
"+ print((N * (N - 1) // 2))"
] | false | 0.106198 | 0.08135 | 1.305446 | [
"s168983938",
"s854833960"
] |
u513081876 | p03557 | python | s358628911 | s693006190 | 331 | 259 | 23,244 | 29,416 | Accepted | Accepted | 21.75 | import bisect
N = int(eval(input()))
A = sorted([int(i) for i in input().split()])
B = sorted([int(i) for i in input().split()])
C = sorted([int(i) for i in input().split()])
ans = 0
for i in B:
ans += (bisect.bisect_left(A, i)) * (N-bisect.bisect_right(C, i))
print(ans) | import bisect
N = int(eval(input()))
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
A.sort()
B.sort()
C.sort()
ans = 0
for i in B:
num_A = bisect.bisect_left(A, i)
num_B = bisect.bisect_right(C, i)
ans += num_A * (N - num_B)
print(ans) | 12 | 17 | 283 | 327 | import bisect
N = int(eval(input()))
A = sorted([int(i) for i in input().split()])
B = sorted([int(i) for i in input().split()])
C = sorted([int(i) for i in input().split()])
ans = 0
for i in B:
ans += (bisect.bisect_left(A, i)) * (N - bisect.bisect_right(C, i))
print(ans)
| import bisect
N = int(eval(input()))
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
A.sort()
B.sort()
C.sort()
ans = 0
for i in B:
num_A = bisect.bisect_left(A, i)
num_B = bisect.bisect_right(C, i)
ans += num_A * (N - num_B)
print(ans)
| false | 29.411765 | [
"-A = sorted([int(i) for i in input().split()])",
"-B = sorted([int(i) for i in input().split()])",
"-C = sorted([int(i) for i in input().split()])",
"+A = [int(i) for i in input().split()]",
"+B = [int(i) for i in input().split()]",
"+C = [int(i) for i in input().split()]",
"+A.sort()",
"+B.sort()",
"+C.sort()",
"- ans += (bisect.bisect_left(A, i)) * (N - bisect.bisect_right(C, i))",
"+ num_A = bisect.bisect_left(A, i)",
"+ num_B = bisect.bisect_right(C, i)",
"+ ans += num_A * (N - num_B)"
] | false | 0.041581 | 0.042032 | 0.98927 | [
"s358628911",
"s693006190"
] |
u186838327 | p02580 | python | s467584811 | s015836802 | 295 | 213 | 89,748 | 104,100 | Accepted | Accepted | 27.8 | import sys
input = sys.stdin.buffer.readline
def main():
H, W, M = list(map(int, input().split()))
#HW = [0]*m
HC = [0]*H
WC = [0]*W
A = [0]*M
for i in range(M):
h, w = list(map(int, input().split()))
h, w = h-1, w-1
#HW[i] = (h, w)
HC[h] += 1
WC[w] += 1
A[i] = (h, w)
from collections import Counter
hct = Counter(HC)
wct = Counter(WC)
hct = list(hct.items())
wct = list(wct.items())
hct.sort(reverse=True)
wct.sort(reverse=True)
#print(hct)
#print(wct)
temph = hct[0][0]
tempw= wct[0][0]
tempa = temph+tempw
cnthw = hct[0][1]*wct[0][1]
cnt = 0
for h, w in A:
if HC[h]+WC[w] ==tempa:
cnt += 1
#print(cnt, cnthw)
if cnt < cnthw:
print(tempa)
else:
print((tempa-1))
if __name__ == '__main__':
main()
| import sys
import io, os
#input = sys.stdin.buffer.readline
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
h, w, m = list(map(int, input().split()))
R = [0]*h
C = [0]*w
YX = []
for i in range(m):
y, x = list(map(int, input().split()))
y, x = y-1, x-1
R[y] +=1
C[x] +=1
YX.append((y, x))
max_r = max(R)
max_c = max(C)
cr = 0
cc = 0
for i in range(h):
if R[i] == max_r:
cr += 1
for i in range(w):
if C[i] == max_c:
cc +=1
c = 0
for y, x in YX:
if R[y] == max_r and C[x] == max_c:
c += 1
if c < cr*cc:
print((max_r+max_c))
else:
print((max_r+max_c-1))
| 46 | 34 | 921 | 645 | import sys
input = sys.stdin.buffer.readline
def main():
H, W, M = list(map(int, input().split()))
# HW = [0]*m
HC = [0] * H
WC = [0] * W
A = [0] * M
for i in range(M):
h, w = list(map(int, input().split()))
h, w = h - 1, w - 1
# HW[i] = (h, w)
HC[h] += 1
WC[w] += 1
A[i] = (h, w)
from collections import Counter
hct = Counter(HC)
wct = Counter(WC)
hct = list(hct.items())
wct = list(wct.items())
hct.sort(reverse=True)
wct.sort(reverse=True)
# print(hct)
# print(wct)
temph = hct[0][0]
tempw = wct[0][0]
tempa = temph + tempw
cnthw = hct[0][1] * wct[0][1]
cnt = 0
for h, w in A:
if HC[h] + WC[w] == tempa:
cnt += 1
# print(cnt, cnthw)
if cnt < cnthw:
print(tempa)
else:
print((tempa - 1))
if __name__ == "__main__":
main()
| import sys
import io, os
# input = sys.stdin.buffer.readline
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
h, w, m = list(map(int, input().split()))
R = [0] * h
C = [0] * w
YX = []
for i in range(m):
y, x = list(map(int, input().split()))
y, x = y - 1, x - 1
R[y] += 1
C[x] += 1
YX.append((y, x))
max_r = max(R)
max_c = max(C)
cr = 0
cc = 0
for i in range(h):
if R[i] == max_r:
cr += 1
for i in range(w):
if C[i] == max_c:
cc += 1
c = 0
for y, x in YX:
if R[y] == max_r and C[x] == max_c:
c += 1
if c < cr * cc:
print((max_r + max_c))
else:
print((max_r + max_c - 1))
| false | 26.086957 | [
"+import io, os",
"-input = sys.stdin.buffer.readline",
"-",
"-",
"-def main():",
"- H, W, M = list(map(int, input().split()))",
"- # HW = [0]*m",
"- HC = [0] * H",
"- WC = [0] * W",
"- A = [0] * M",
"- for i in range(M):",
"- h, w = list(map(int, input().split()))",
"- h, w = h - 1, w - 1",
"- # HW[i] = (h, w)",
"- HC[h] += 1",
"- WC[w] += 1",
"- A[i] = (h, w)",
"- from collections import Counter",
"-",
"- hct = Counter(HC)",
"- wct = Counter(WC)",
"- hct = list(hct.items())",
"- wct = list(wct.items())",
"- hct.sort(reverse=True)",
"- wct.sort(reverse=True)",
"- # print(hct)",
"- # print(wct)",
"- temph = hct[0][0]",
"- tempw = wct[0][0]",
"- tempa = temph + tempw",
"- cnthw = hct[0][1] * wct[0][1]",
"- cnt = 0",
"- for h, w in A:",
"- if HC[h] + WC[w] == tempa:",
"- cnt += 1",
"- # print(cnt, cnthw)",
"- if cnt < cnthw:",
"- print(tempa)",
"- else:",
"- print((tempa - 1))",
"-",
"-",
"-if __name__ == \"__main__\":",
"- main()",
"+# input = sys.stdin.buffer.readline",
"+input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline",
"+h, w, m = list(map(int, input().split()))",
"+R = [0] * h",
"+C = [0] * w",
"+YX = []",
"+for i in range(m):",
"+ y, x = list(map(int, input().split()))",
"+ y, x = y - 1, x - 1",
"+ R[y] += 1",
"+ C[x] += 1",
"+ YX.append((y, x))",
"+max_r = max(R)",
"+max_c = max(C)",
"+cr = 0",
"+cc = 0",
"+for i in range(h):",
"+ if R[i] == max_r:",
"+ cr += 1",
"+for i in range(w):",
"+ if C[i] == max_c:",
"+ cc += 1",
"+c = 0",
"+for y, x in YX:",
"+ if R[y] == max_r and C[x] == max_c:",
"+ c += 1",
"+if c < cr * cc:",
"+ print((max_r + max_c))",
"+else:",
"+ print((max_r + max_c - 1))"
] | false | 0.035066 | 0.048983 | 0.715885 | [
"s467584811",
"s015836802"
] |
u517152997 | p02928 | python | s282764194 | s232904515 | 779 | 43 | 3,188 | 3,316 | Accepted | Accepted | 94.48 | # -*- coding: utf-8 -*-
#
import math
import sys
import itertools
DIV_NUM = 1000000000 + 7
N,K = list(map(int, input().split()))
A = [int(x) for x in input().split()]
if N==1:
print((0))
exit()
answer = 0
for i in range(len(A)):
for j in range(len(A)-1,i,-1):
if A[j]<A[j-1]:
A[j],A[j-1] = A[j-1],A[j]
answer += 1
q=0
p=A[0]
r=0
for i in range(1,N):
if A[i]>p:
p=A[i]
r=i
q += r
answer = answer % DIV_NUM
answer = (answer * K) % DIV_NUM
q = q % DIV_NUM
answer = answer + q * K * (K-1) // 2
answer = answer % DIV_NUM
print(answer)
| # -*- coding: utf-8 -*-
#
import math
import sys
import itertools
# import numpy as np
DIV_NUM = 1000000000 + 7
INPUT_NUMS = list(map(int, input().split()))
N=int(INPUT_NUMS[0])
K=int(INPUT_NUMS[1])
A = [int(x) for x in input().split()]
#AA = np.array(A , dtype='int64')
if N==1:
print((0))
exit()
nn=int(math.log2(2000))+1
tree = [0] * (2**nn)
def BIT_update(tree,x):
while x <= 2000:
tree[x] += 1
y = x
z = 1
while y > 0:
if y % 2 == 1:
x += z
break
y //= 2
z *= 2
def BIT_sum(tree,x):
s = 0
while x > 0:
s += tree[x]
y = x
z = 1
while y > 0:
if y % 2 == 1:
x -= z
break
y //= 2
z *= 2
return s
answer = N*(N-1)//2
for i in A:
answer -= BIT_sum(tree,i)
BIT_update(tree,i)
B = sorted(A)
q=0
p=B[0]
r=0
for i in range(1,N):
if B[i]>p:
p=B[i]
r=i
q += r
answer = answer * K + q * K * (K-1) // 2
answer = answer % DIV_NUM
print(answer)
| 37 | 70 | 633 | 1,177 | # -*- coding: utf-8 -*-
#
import math
import sys
import itertools
DIV_NUM = 1000000000 + 7
N, K = list(map(int, input().split()))
A = [int(x) for x in input().split()]
if N == 1:
print((0))
exit()
answer = 0
for i in range(len(A)):
for j in range(len(A) - 1, i, -1):
if A[j] < A[j - 1]:
A[j], A[j - 1] = A[j - 1], A[j]
answer += 1
q = 0
p = A[0]
r = 0
for i in range(1, N):
if A[i] > p:
p = A[i]
r = i
q += r
answer = answer % DIV_NUM
answer = (answer * K) % DIV_NUM
q = q % DIV_NUM
answer = answer + q * K * (K - 1) // 2
answer = answer % DIV_NUM
print(answer)
| # -*- coding: utf-8 -*-
#
import math
import sys
import itertools
# import numpy as np
DIV_NUM = 1000000000 + 7
INPUT_NUMS = list(map(int, input().split()))
N = int(INPUT_NUMS[0])
K = int(INPUT_NUMS[1])
A = [int(x) for x in input().split()]
# AA = np.array(A , dtype='int64')
if N == 1:
print((0))
exit()
nn = int(math.log2(2000)) + 1
tree = [0] * (2**nn)
def BIT_update(tree, x):
while x <= 2000:
tree[x] += 1
y = x
z = 1
while y > 0:
if y % 2 == 1:
x += z
break
y //= 2
z *= 2
def BIT_sum(tree, x):
s = 0
while x > 0:
s += tree[x]
y = x
z = 1
while y > 0:
if y % 2 == 1:
x -= z
break
y //= 2
z *= 2
return s
answer = N * (N - 1) // 2
for i in A:
answer -= BIT_sum(tree, i)
BIT_update(tree, i)
B = sorted(A)
q = 0
p = B[0]
r = 0
for i in range(1, N):
if B[i] > p:
p = B[i]
r = i
q += r
answer = answer * K + q * K * (K - 1) // 2
answer = answer % DIV_NUM
print(answer)
| false | 47.142857 | [
"+# import numpy as np",
"-N, K = list(map(int, input().split()))",
"+INPUT_NUMS = list(map(int, input().split()))",
"+N = int(INPUT_NUMS[0])",
"+K = int(INPUT_NUMS[1])",
"+# AA = np.array(A , dtype='int64')",
"-answer = 0",
"-for i in range(len(A)):",
"- for j in range(len(A) - 1, i, -1):",
"- if A[j] < A[j - 1]:",
"- A[j], A[j - 1] = A[j - 1], A[j]",
"- answer += 1",
"+nn = int(math.log2(2000)) + 1",
"+tree = [0] * (2**nn)",
"+",
"+",
"+def BIT_update(tree, x):",
"+ while x <= 2000:",
"+ tree[x] += 1",
"+ y = x",
"+ z = 1",
"+ while y > 0:",
"+ if y % 2 == 1:",
"+ x += z",
"+ break",
"+ y //= 2",
"+ z *= 2",
"+",
"+",
"+def BIT_sum(tree, x):",
"+ s = 0",
"+ while x > 0:",
"+ s += tree[x]",
"+ y = x",
"+ z = 1",
"+ while y > 0:",
"+ if y % 2 == 1:",
"+ x -= z",
"+ break",
"+ y //= 2",
"+ z *= 2",
"+ return s",
"+",
"+",
"+answer = N * (N - 1) // 2",
"+for i in A:",
"+ answer -= BIT_sum(tree, i)",
"+ BIT_update(tree, i)",
"+B = sorted(A)",
"-p = A[0]",
"+p = B[0]",
"- if A[i] > p:",
"- p = A[i]",
"+ if B[i] > p:",
"+ p = B[i]",
"-answer = answer % DIV_NUM",
"-answer = (answer * K) % DIV_NUM",
"-q = q % DIV_NUM",
"-answer = answer + q * K * (K - 1) // 2",
"+answer = answer * K + q * K * (K - 1) // 2"
] | false | 0.039558 | 0.038947 | 1.015678 | [
"s282764194",
"s232904515"
] |
u397384480 | p02949 | python | s775444571 | s471142258 | 1,910 | 1,710 | 75,868 | 75,880 | Accepted | Accepted | 10.47 | import bisect
import collections
import copy
import functools
import heapq
import math
import sys
from collections import deque
from collections import defaultdict
input = sys.stdin.readline
MOD = 10**9+7
N,M,P = list(map(int,(input().split())))
line = []
for i in range(M):
a,b,c = list(map(int,(input().split())))
line.append([a-1,b-1,-c+P])
min_distance = [float("inf")]*N # min_distance[i] は始点から街iまでの最短距離
min_distance[0] = 0 # 始点から始点への最短距離は0とする
#negative = [False]*N
"""
def Bellman_Ford(S,V,E,distance,negative):
negative = [False]*N
count = 1
while count < V:
count += 1
for s,g,d in distance: # [s,g,d] = [道路の始点,道路の終点,道路の長さ] について、すべての道路を見る
if min_distance[s] != float("inf") and min_distance[s] + d < min_distance[g]: # 最短経路が確立されている街から伸びる道路を通ることで、距離を短くできるならば、
min_distance[g] = min_distance[s] + d # 最短距離を上書きする
negative[s],negative[g] = True,True
return min_distance,negative
min_distance,negative = Bellman_Ford(1,N,M,line,negative)
ans = min_distance[N-1]
negative = [False]*N
min_distance,negative = Bellman_Ford(1,N,M,line,negative)
print(negative)
print(min_distance)
if negative[N-1]:
print(-1)
else:
print(max(-ans,0))
"""
def Bellman_Ford(S,V,E,distance):
update = False
flag = 0
for _ in range(V):
for s,g,d in distance: # [s,g,d] = [道路の始点,道路の終点,道路の長さ] について、すべての道路を見る
if min_distance[s] != float("inf") and min_distance[s] + d < min_distance[g]: # 最短経路が確立されている街から伸びる道路を通ることで、距離を短くできるならば、
min_distance[g] = min_distance[s] + d # 最短距離を上書きする
update = True
if not update:
flag = 1
break
return min_distance,flag
def Bellman_Ford2(S,V,E,distance):
for _ in range(V):
for s,g,d in distance: # [s,g,d] = [道路の始点,道路の終点,道路の長さ] について、すべての道路を見る
if min_distance[s] != float("inf") and min_distance[s] + d < min_distance[g]: # 最短経路が確立されている街から伸びる道路を通ることで、距離を短くできるならば、
min_distance[g] = -float("inf")
return min_distance
min_distance,flag = Bellman_Ford(1,N,M,line)
if flag == 1:
ans = min_distance[N-1]
print((max(-ans,0)))
else:
min_distance = Bellman_Ford2(1,N,M,line)
ans = min_distance[N-1]
if ans == -float("inf"):
print((-1))
else:
print((max(-ans,0)))
#print(min_distance) | import bisect
import collections
import copy
import functools
import heapq
import math
import sys
from collections import deque
from collections import defaultdict
input = sys.stdin.readline
MOD = 10**9+7
N,M,P = list(map(int,(input().split())))
line = []
for i in range(M):
a,b,c = list(map(int,(input().split())))
line.append([a-1,b-1,-c+P])
min_distance = [float("inf")]*N # min_distance[i] は始点から街iまでの最短距離
min_distance[0] = 0 # 始点から始点への最短距離は0とする
def Bellman_Ford(S,V,E,distance):
update = False
flag = 0
for _ in range(V):
for s,g,d in distance: # [s,g,d] = [道路の始点,道路の終点,道路の長さ] について、すべての道路を見る
if min_distance[s] != float("inf") and min_distance[s] + d < min_distance[g]: # 最短経路が確立されている街から伸びる道路を通ることで、距離を短くできるならば、
min_distance[g] = min_distance[s] + d # 最短距離を上書きする
update = True
if not update:
flag = 1
break
return min_distance,flag
def Bellman_Ford2(S,V,E,distance):
for _ in range(V):
for s,g,d in distance: # [s,g,d] = [道路の始点,道路の終点,道路の長さ] について、すべての道路を見る
if min_distance[s] != float("inf") and min_distance[s] + d < min_distance[g]: # 最短経路が確立されている街から伸びる道路を通ることで、距離を短くできるならば、
min_distance[g] = -float("inf")
if g == N-1:
break
else:
continue
break
return min_distance
min_distance,flag = Bellman_Ford(1,N,M,line)
if flag == 1:
ans = min_distance[N-1]
print((max(-ans,0)))
else:
min_distance = Bellman_Ford2(1,N,M,line)
ans = min_distance[N-1]
if ans == -float("inf"):
print((-1))
else:
print((max(-ans,0)))
#print(min_distance) | 81 | 60 | 2,427 | 1,735 | import bisect
import collections
import copy
import functools
import heapq
import math
import sys
from collections import deque
from collections import defaultdict
input = sys.stdin.readline
MOD = 10**9 + 7
N, M, P = list(map(int, (input().split())))
line = []
for i in range(M):
a, b, c = list(map(int, (input().split())))
line.append([a - 1, b - 1, -c + P])
min_distance = [float("inf")] * N # min_distance[i] は始点から街iまでの最短距離
min_distance[0] = 0 # 始点から始点への最短距離は0とする
# negative = [False]*N
"""
def Bellman_Ford(S,V,E,distance,negative):
negative = [False]*N
count = 1
while count < V:
count += 1
for s,g,d in distance: # [s,g,d] = [道路の始点,道路の終点,道路の長さ] について、すべての道路を見る
if min_distance[s] != float("inf") and min_distance[s] + d < min_distance[g]: # 最短経路が確立されている街から伸びる道路を通ることで、距離を短くできるならば、
min_distance[g] = min_distance[s] + d # 最短距離を上書きする
negative[s],negative[g] = True,True
return min_distance,negative
min_distance,negative = Bellman_Ford(1,N,M,line,negative)
ans = min_distance[N-1]
negative = [False]*N
min_distance,negative = Bellman_Ford(1,N,M,line,negative)
print(negative)
print(min_distance)
if negative[N-1]:
print(-1)
else:
print(max(-ans,0))
"""
def Bellman_Ford(S, V, E, distance):
update = False
flag = 0
for _ in range(V):
for s, g, d in distance: # [s,g,d] = [道路の始点,道路の終点,道路の長さ] について、すべての道路を見る
if (
min_distance[s] != float("inf")
and min_distance[s] + d < min_distance[g]
): # 最短経路が確立されている街から伸びる道路を通ることで、距離を短くできるならば、
min_distance[g] = min_distance[s] + d # 最短距離を上書きする
update = True
if not update:
flag = 1
break
return min_distance, flag
def Bellman_Ford2(S, V, E, distance):
for _ in range(V):
for s, g, d in distance: # [s,g,d] = [道路の始点,道路の終点,道路の長さ] について、すべての道路を見る
if (
min_distance[s] != float("inf")
and min_distance[s] + d < min_distance[g]
): # 最短経路が確立されている街から伸びる道路を通ることで、距離を短くできるならば、
min_distance[g] = -float("inf")
return min_distance
min_distance, flag = Bellman_Ford(1, N, M, line)
if flag == 1:
ans = min_distance[N - 1]
print((max(-ans, 0)))
else:
min_distance = Bellman_Ford2(1, N, M, line)
ans = min_distance[N - 1]
if ans == -float("inf"):
print((-1))
else:
print((max(-ans, 0)))
# print(min_distance)
| import bisect
import collections
import copy
import functools
import heapq
import math
import sys
from collections import deque
from collections import defaultdict
input = sys.stdin.readline
MOD = 10**9 + 7
N, M, P = list(map(int, (input().split())))
line = []
for i in range(M):
a, b, c = list(map(int, (input().split())))
line.append([a - 1, b - 1, -c + P])
min_distance = [float("inf")] * N # min_distance[i] は始点から街iまでの最短距離
min_distance[0] = 0 # 始点から始点への最短距離は0とする
def Bellman_Ford(S, V, E, distance):
update = False
flag = 0
for _ in range(V):
for s, g, d in distance: # [s,g,d] = [道路の始点,道路の終点,道路の長さ] について、すべての道路を見る
if (
min_distance[s] != float("inf")
and min_distance[s] + d < min_distance[g]
): # 最短経路が確立されている街から伸びる道路を通ることで、距離を短くできるならば、
min_distance[g] = min_distance[s] + d # 最短距離を上書きする
update = True
if not update:
flag = 1
break
return min_distance, flag
def Bellman_Ford2(S, V, E, distance):
for _ in range(V):
for s, g, d in distance: # [s,g,d] = [道路の始点,道路の終点,道路の長さ] について、すべての道路を見る
if (
min_distance[s] != float("inf")
and min_distance[s] + d < min_distance[g]
): # 最短経路が確立されている街から伸びる道路を通ることで、距離を短くできるならば、
min_distance[g] = -float("inf")
if g == N - 1:
break
else:
continue
break
return min_distance
min_distance, flag = Bellman_Ford(1, N, M, line)
if flag == 1:
ans = min_distance[N - 1]
print((max(-ans, 0)))
else:
min_distance = Bellman_Ford2(1, N, M, line)
ans = min_distance[N - 1]
if ans == -float("inf"):
print((-1))
else:
print((max(-ans, 0)))
# print(min_distance)
| false | 25.925926 | [
"-# negative = [False]*N",
"-\"\"\"",
"-def Bellman_Ford(S,V,E,distance,negative):",
"- negative = [False]*N",
"- count = 1",
"- while count < V:",
"- count += 1",
"- for s,g,d in distance: # [s,g,d] = [道路の始点,道路の終点,道路の長さ] について、すべての道路を見る",
"- if min_distance[s] != float(\"inf\") and min_distance[s] + d < min_distance[g]: # 最短経路が確立されている街から伸びる道路を通ることで、距離を短くできるならば、",
"- min_distance[g] = min_distance[s] + d # 最短距離を上書きする",
"- negative[s],negative[g] = True,True",
"- return min_distance,negative",
"-min_distance,negative = Bellman_Ford(1,N,M,line,negative)",
"-ans = min_distance[N-1]",
"-negative = [False]*N",
"-min_distance,negative = Bellman_Ford(1,N,M,line,negative)",
"-print(negative)",
"-print(min_distance)",
"-if negative[N-1]:",
"- print(-1)",
"-else:",
"- print(max(-ans,0))",
"-\"\"\"",
"+ if g == N - 1:",
"+ break",
"+ else:",
"+ continue",
"+ break"
] | false | 0.101065 | 0.100834 | 1.002291 | [
"s775444571",
"s471142258"
] |
u075012704 | p03295 | python | s683682521 | s879492823 | 582 | 432 | 20,072 | 21,336 | Accepted | Accepted | 25.77 | N, M = list(map(int, input().split()))
E = []
for i in range(M):
a, b = list(map(int, input().split()))
a, b = a-1, b-1
E.append([a, b])
E.sort()
l, r = 0, float('inf')
ans = 0
for a, b in E:
if b <= l or a >= r:
ans += 1
l, r = a, b
else:
l = max(a, l)
r = min(b, r)
print((ans + 1))
| N, M = list(map(int, input().split()))
E = []
for i in range(M):
a, b = list(map(int, input().split()))
a, b = a - 1, b - 1
E.append([a, b])
E.sort(key=lambda x: x[1])
r = 0
ans = 0
for a, b in E:
if a >= r:
ans += 1
r = b
print(ans)
| 19 | 17 | 343 | 273 | N, M = list(map(int, input().split()))
E = []
for i in range(M):
a, b = list(map(int, input().split()))
a, b = a - 1, b - 1
E.append([a, b])
E.sort()
l, r = 0, float("inf")
ans = 0
for a, b in E:
if b <= l or a >= r:
ans += 1
l, r = a, b
else:
l = max(a, l)
r = min(b, r)
print((ans + 1))
| N, M = list(map(int, input().split()))
E = []
for i in range(M):
a, b = list(map(int, input().split()))
a, b = a - 1, b - 1
E.append([a, b])
E.sort(key=lambda x: x[1])
r = 0
ans = 0
for a, b in E:
if a >= r:
ans += 1
r = b
print(ans)
| false | 10.526316 | [
"-E.sort()",
"-l, r = 0, float(\"inf\")",
"+E.sort(key=lambda x: x[1])",
"+r = 0",
"- if b <= l or a >= r:",
"+ if a >= r:",
"- l, r = a, b",
"- else:",
"- l = max(a, l)",
"- r = min(b, r)",
"-print((ans + 1))",
"+ r = b",
"+print(ans)"
] | false | 0.139094 | 0.040395 | 3.443355 | [
"s683682521",
"s879492823"
] |
u623819879 | p02947 | python | s504598157 | s472418790 | 680 | 378 | 62,552 | 68,440 | Accepted | Accepted | 44.41 | from heapq import heappush, heappop
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations
import sys
import bisect
import string
sys.setrecursionlimit(10**6)
def SI():
return input().split()
def MI():
return list(map(int,input().split()))
def I():
return int(eval(input()))
def LI():
return [int(i) for i in input().split()]
YN=['Yes','No']
YNeos='YNeos'
mo=10**9+7
imp='IMPOSSIBLE'
alp=string.ascii_lowercase
num=enumerate(alp)
d=dict()
for i,j in num:
d[j]=i
n=I()
w=[]
ans=0
di=defaultdict(int)
X=[]
for i in range(n):
s=''.join(sorted(list(eval(input()))))
di[s]+=1
for i,j in list(di.items()):
ans+=j*(j-1)//2
print(ans) | from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations
import sys
import bisect
import string
import math
import time
#import random
def I():
return int(input())
def MI():
return map(int,input().split())
def LI():
return [int(i) for i in input().split()]
def LI_():
return [int(i)-1 for i in input().split()]
def StoI():
return [ord(i)-97 +10 for i in input()]
def ItoS(nn):
return chr(nn+97)
def GI(V,E,Directed=False,index=0):
org_inp=[]
g=[[] for i in range(n)]
for i in range(E):
inp=LI()
org_inp.append(inp)
if index==0:
inp[0]-=1
inp[1]-=1
if len(inp)==2:
a,b=inp
g[a].append(b)
if not Directed:
g[b].append(a)
elif len(inp)==3:
a,b,c=inp
aa=(inp[0],inp[2])
bb=(inp[1],inp[2])
g[a].append(bb)
if not Directed:
g[b].append(aa)
return g,org_inp
def show(*inp,end='\n'):
if show_flg:
print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
u_alp=string.ascii_uppercase
#sys.setrecursionlimit(10**5)
input=lambda: sys.stdin.readline().rstrip()
show_flg=False
show_flg=True
n=I()
mp=defaultdict(int)
t=[]
for i in range(n):
s=StoI()
s.sort()
tmp=0
for i in s:
tmp=tmp*100+i
t.append(tmp)
#mp[s]+=1
c=Counter(t)
ans=0
for i,j in c.items():
ans+=j*(j-1)//2
print(ans)
| 38 | 77 | 724 | 1,671 | from heapq import heappush, heappop
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations
import sys
import bisect
import string
sys.setrecursionlimit(10**6)
def SI():
return input().split()
def MI():
return list(map(int, input().split()))
def I():
return int(eval(input()))
def LI():
return [int(i) for i in input().split()]
YN = ["Yes", "No"]
YNeos = "YNeos"
mo = 10**9 + 7
imp = "IMPOSSIBLE"
alp = string.ascii_lowercase
num = enumerate(alp)
d = dict()
for i, j in num:
d[j] = i
n = I()
w = []
ans = 0
di = defaultdict(int)
X = []
for i in range(n):
s = "".join(sorted(list(eval(input()))))
di[s] += 1
for i, j in list(di.items()):
ans += j * (j - 1) // 2
print(ans)
| from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations
import sys
import bisect
import string
import math
import time
# import random
def I():
return int(input())
def MI():
return map(int, input().split())
def LI():
return [int(i) for i in input().split()]
def LI_():
return [int(i) - 1 for i in input().split()]
def StoI():
return [ord(i) - 97 + 10 for i in input()]
def ItoS(nn):
return chr(nn + 97)
def GI(V, E, Directed=False, index=0):
org_inp = []
g = [[] for i in range(n)]
for i in range(E):
inp = LI()
org_inp.append(inp)
if index == 0:
inp[0] -= 1
inp[1] -= 1
if len(inp) == 2:
a, b = inp
g[a].append(b)
if not Directed:
g[b].append(a)
elif len(inp) == 3:
a, b, c = inp
aa = (inp[0], inp[2])
bb = (inp[1], inp[2])
g[a].append(bb)
if not Directed:
g[b].append(aa)
return g, org_inp
def show(*inp, end="\n"):
if show_flg:
print(*inp, end=end)
YN = ["Yes", "No"]
mo = 10**9 + 7
inf = float("inf")
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
# sys.setrecursionlimit(10**5)
input = lambda: sys.stdin.readline().rstrip()
show_flg = False
show_flg = True
n = I()
mp = defaultdict(int)
t = []
for i in range(n):
s = StoI()
s.sort()
tmp = 0
for i in s:
tmp = tmp * 100 + i
t.append(tmp)
# mp[s]+=1
c = Counter(t)
ans = 0
for i, j in c.items():
ans += j * (j - 1) // 2
print(ans)
| false | 50.649351 | [
"-from heapq import heappush, heappop",
"+from heapq import heappush, heappop, heapify",
"-from itertools import permutations",
"+from itertools import permutations, combinations",
"+import math",
"+import time",
"-sys.setrecursionlimit(10**6)",
"-",
"-",
"-def SI():",
"- return input().split()",
"+# import random",
"+def I():",
"+ return int(input())",
"- return list(map(int, input().split()))",
"-",
"-",
"-def I():",
"- return int(eval(input()))",
"+ return map(int, input().split())",
"+def LI_():",
"+ return [int(i) - 1 for i in input().split()]",
"+",
"+",
"+def StoI():",
"+ return [ord(i) - 97 + 10 for i in input()]",
"+",
"+",
"+def ItoS(nn):",
"+ return chr(nn + 97)",
"+",
"+",
"+def GI(V, E, Directed=False, index=0):",
"+ org_inp = []",
"+ g = [[] for i in range(n)]",
"+ for i in range(E):",
"+ inp = LI()",
"+ org_inp.append(inp)",
"+ if index == 0:",
"+ inp[0] -= 1",
"+ inp[1] -= 1",
"+ if len(inp) == 2:",
"+ a, b = inp",
"+ g[a].append(b)",
"+ if not Directed:",
"+ g[b].append(a)",
"+ elif len(inp) == 3:",
"+ a, b, c = inp",
"+ aa = (inp[0], inp[2])",
"+ bb = (inp[1], inp[2])",
"+ g[a].append(bb)",
"+ if not Directed:",
"+ g[b].append(aa)",
"+ return g, org_inp",
"+",
"+",
"+def show(*inp, end=\"\\n\"):",
"+ if show_flg:",
"+ print(*inp, end=end)",
"+",
"+",
"-YNeos = \"YNeos\"",
"-imp = \"IMPOSSIBLE\"",
"-alp = string.ascii_lowercase",
"-num = enumerate(alp)",
"-d = dict()",
"-for i, j in num:",
"- d[j] = i",
"+inf = float(\"inf\")",
"+l_alp = string.ascii_lowercase",
"+u_alp = string.ascii_uppercase",
"+# sys.setrecursionlimit(10**5)",
"+input = lambda: sys.stdin.readline().rstrip()",
"+show_flg = False",
"+show_flg = True",
"-w = []",
"+mp = defaultdict(int)",
"+t = []",
"+for i in range(n):",
"+ s = StoI()",
"+ s.sort()",
"+ tmp = 0",
"+ for i in s:",
"+ tmp = tmp * 100 + i",
"+ t.append(tmp)",
"+ # mp[s]+=1",
"+c = Counter(t)",
"-di = defaultdict(int)",
"-X = []",
"-for i in range(n):",
"- s = \"\".join(sorted(list(eval(input()))))",
"- di[s] += 1",
"-for i, j in list(di.items()):",
"+for i, j in c.items():"
] | false | 0.006407 | 0.101019 | 0.063425 | [
"s504598157",
"s472418790"
] |
u360515075 | p03474 | python | s905769914 | s817706924 | 19 | 17 | 3,060 | 2,940 | Accepted | Accepted | 10.53 | A, B = list(map(int, input().split()))
S = eval(input())
if any([S.count("-") != 1, S[0] == "-", S[-1] == "-"]):
print ("No")
else:
a, b = S.split("-")
if len(a) == A and len(b) == B:
print ("Yes")
else:
print ("No") | A, B = list(map(int, input().split()))
S = eval(input())
print(("Yes" if S[A] == "-" and S.count("-") == 1 else "No")) | 11 | 4 | 231 | 109 | A, B = list(map(int, input().split()))
S = eval(input())
if any([S.count("-") != 1, S[0] == "-", S[-1] == "-"]):
print("No")
else:
a, b = S.split("-")
if len(a) == A and len(b) == B:
print("Yes")
else:
print("No")
| A, B = list(map(int, input().split()))
S = eval(input())
print(("Yes" if S[A] == "-" and S.count("-") == 1 else "No"))
| false | 63.636364 | [
"-if any([S.count(\"-\") != 1, S[0] == \"-\", S[-1] == \"-\"]):",
"- print(\"No\")",
"-else:",
"- a, b = S.split(\"-\")",
"- if len(a) == A and len(b) == B:",
"- print(\"Yes\")",
"- else:",
"- print(\"No\")",
"+print((\"Yes\" if S[A] == \"-\" and S.count(\"-\") == 1 else \"No\"))"
] | false | 0.053727 | 0.056427 | 0.952153 | [
"s905769914",
"s817706924"
] |
u572012241 | p02696 | python | s142961368 | s785728096 | 23 | 19 | 9,192 | 9,092 | Accepted | Accepted | 17.39 | a, b, n = list(map(int, input().split()))
if b>n:
print((a*n//b - a*((n)//b)))
else:
print((a*((n//b)*b-1)//b - a*(((n//b)*b-1)//b)))
| a,b,n=list(map(int,input().split()))
print((a*min(b-1,n)//b)) | 7 | 2 | 141 | 54 | a, b, n = list(map(int, input().split()))
if b > n:
print((a * n // b - a * ((n) // b)))
else:
print((a * ((n // b) * b - 1) // b - a * (((n // b) * b - 1) // b)))
| a, b, n = list(map(int, input().split()))
print((a * min(b - 1, n) // b))
| false | 71.428571 | [
"-if b > n:",
"- print((a * n // b - a * ((n) // b)))",
"-else:",
"- print((a * ((n // b) * b - 1) // b - a * (((n // b) * b - 1) // b)))",
"+print((a * min(b - 1, n) // b))"
] | false | 0.110241 | 0.044862 | 2.457322 | [
"s142961368",
"s785728096"
] |
u038024401 | p02713 | python | s410796421 | s729188764 | 1,961 | 535 | 9,168 | 9,176 | Accepted | Accepted | 72.72 | from math import gcd
K = int(eval(input()))
ans = 0
for i in range(1, K + 1):
for j in range(1, K + 1):
for k in range(1, K + 1):
ans += gcd(gcd(i, j), k)
print(ans)
| from math import gcd
K = int(eval(input()))
ans = 0
for i in range(1, K + 1):
for j in range(1, K + 1):
tmp = gcd(i, j)
if tmp == 1:
ans += K
else:
for k in range(1, K + 1):
ans += gcd(tmp, k)
print(ans)
| 10 | 14 | 195 | 281 | from math import gcd
K = int(eval(input()))
ans = 0
for i in range(1, K + 1):
for j in range(1, K + 1):
for k in range(1, K + 1):
ans += gcd(gcd(i, j), k)
print(ans)
| from math import gcd
K = int(eval(input()))
ans = 0
for i in range(1, K + 1):
for j in range(1, K + 1):
tmp = gcd(i, j)
if tmp == 1:
ans += K
else:
for k in range(1, K + 1):
ans += gcd(tmp, k)
print(ans)
| false | 28.571429 | [
"- for k in range(1, K + 1):",
"- ans += gcd(gcd(i, j), k)",
"+ tmp = gcd(i, j)",
"+ if tmp == 1:",
"+ ans += K",
"+ else:",
"+ for k in range(1, K + 1):",
"+ ans += gcd(tmp, k)"
] | false | 0.238182 | 0.062027 | 3.839965 | [
"s410796421",
"s729188764"
] |
u941753895 | p03160 | python | s116540491 | s962393844 | 226 | 127 | 28,180 | 16,708 | Accepted | Accepted | 43.81 | class struct:
def __init__(self,a,b):
self.a=a
self.b=b
n=int(eval(input()))
l=list(map(int,input().split()))
l2=[struct(0,0) for _ in range(n)]
l2[0].a=l[0]
l2[1].a=l[1]
l2[1].b=abs(l[0]-l[1])
i=2
for x in l[2:]:
l2[i].a=x
l2[i].b=min(abs(l2[i-2].a-x)+l2[i-2].b,
abs(l2[i-1].a-x)+l2[i-1].b)
i+=1
print((l2[-1].b)) | import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time
sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
def LI(): return list(map(int,input().split()))
def I(): return int(eval(input()))
def LS(): return input().split()
def S(): return eval(input())
def main():
n=I()
l=LI()
dp=[0]*100010
dp[1]=0
dp[2]=abs(l[0]-l[1])
for i in range(2,n):
dp[i+1]=min(dp[i]+abs(l[i]-l[i-1]),dp[i-1]+abs(l[i]-l[i-2]))
return dp[n]
print((main()))
| 21 | 25 | 350 | 501 | class struct:
def __init__(self, a, b):
self.a = a
self.b = b
n = int(eval(input()))
l = list(map(int, input().split()))
l2 = [struct(0, 0) for _ in range(n)]
l2[0].a = l[0]
l2[1].a = l[1]
l2[1].b = abs(l[0] - l[1])
i = 2
for x in l[2:]:
l2[i].a = x
l2[i].b = min(
abs(l2[i - 2].a - x) + l2[i - 2].b, abs(l2[i - 1].a - x) + l2[i - 1].b
)
i += 1
print((l2[-1].b))
| import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time
sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7
def LI():
return list(map(int, input().split()))
def I():
return int(eval(input()))
def LS():
return input().split()
def S():
return eval(input())
def main():
n = I()
l = LI()
dp = [0] * 100010
dp[1] = 0
dp[2] = abs(l[0] - l[1])
for i in range(2, n):
dp[i + 1] = min(dp[i] + abs(l[i] - l[i - 1]), dp[i - 1] + abs(l[i] - l[i - 2]))
return dp[n]
print((main()))
| false | 16 | [
"-class struct:",
"- def __init__(self, a, b):",
"- self.a = a",
"- self.b = b",
"+import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time",
"+",
"+sys.setrecursionlimit(10**7)",
"+inf = 10**20",
"+mod = 10**9 + 7",
"-n = int(eval(input()))",
"-l = list(map(int, input().split()))",
"-l2 = [struct(0, 0) for _ in range(n)]",
"-l2[0].a = l[0]",
"-l2[1].a = l[1]",
"-l2[1].b = abs(l[0] - l[1])",
"-i = 2",
"-for x in l[2:]:",
"- l2[i].a = x",
"- l2[i].b = min(",
"- abs(l2[i - 2].a - x) + l2[i - 2].b, abs(l2[i - 1].a - x) + l2[i - 1].b",
"- )",
"- i += 1",
"-print((l2[-1].b))",
"+def LI():",
"+ return list(map(int, input().split()))",
"+",
"+",
"+def I():",
"+ return int(eval(input()))",
"+",
"+",
"+def LS():",
"+ return input().split()",
"+",
"+",
"+def S():",
"+ return eval(input())",
"+",
"+",
"+def main():",
"+ n = I()",
"+ l = LI()",
"+ dp = [0] * 100010",
"+ dp[1] = 0",
"+ dp[2] = abs(l[0] - l[1])",
"+ for i in range(2, n):",
"+ dp[i + 1] = min(dp[i] + abs(l[i] - l[i - 1]), dp[i - 1] + abs(l[i] - l[i - 2]))",
"+ return dp[n]",
"+",
"+",
"+print((main()))"
] | false | 0.036191 | 0.041404 | 0.874099 | [
"s116540491",
"s962393844"
] |
u644907318 | p02743 | python | s597831945 | s578500414 | 173 | 61 | 38,256 | 61,840 | Accepted | Accepted | 64.74 | a,b,c = list(map(int,input().split()))
if c>a+b and c**2-2*c*(a+b)+(a-b)**2>0:
print("Yes")
else:
print("No") | a,b,c = list(map(int,input().split()))
if c>a+b and (c-a-b)**2>4*a*b:
print("Yes")
else:
print("No") | 5 | 5 | 115 | 106 | a, b, c = list(map(int, input().split()))
if c > a + b and c**2 - 2 * c * (a + b) + (a - b) ** 2 > 0:
print("Yes")
else:
print("No")
| a, b, c = list(map(int, input().split()))
if c > a + b and (c - a - b) ** 2 > 4 * a * b:
print("Yes")
else:
print("No")
| false | 0 | [
"-if c > a + b and c**2 - 2 * c * (a + b) + (a - b) ** 2 > 0:",
"+if c > a + b and (c - a - b) ** 2 > 4 * a * b:"
] | false | 0.08482 | 0.042468 | 1.997285 | [
"s597831945",
"s578500414"
] |
u948524308 | p02954 | python | s014402752 | s855981209 | 176 | 109 | 4,864 | 6,400 | Accepted | Accepted | 38.07 | S=input()
N=len(S)
ans=[0]*N
cnt_o=1
cnt_e=0
idx=0
f=True #True=R
for i in range(1,N):
if f==True:
if S[i]=="R":
temp=cnt_e
cnt_e=cnt_o
cnt_o =temp+1
else:
ans[i-1]+=cnt_o
ans[i]=cnt_e
cnt_o=1
cnt_e=0
f=False
idx=i
else:
if S[i]=="L":
temp=cnt_e
cnt_e=cnt_o
cnt_o=temp+1
else:
ans[idx]+=cnt_o
ans[idx-1]+=cnt_e
cnt_o=1
cnt_e=0
f=True
ans[idx]+=cnt_o
ans[idx-1]+=cnt_e
for i in range(N):
print(str(ans[i]),end=" ")
| S=eval(input())
N=len(S)
ans=[0]*N
cnt=1
idx=0
f=True #True=R
for i in range(1,N):
if f==True:
if S[i]=="R":
cnt+=1
else:
ans[i-1]+=(cnt+1)//2
ans[i]=cnt//2
cnt=1
f=False
idx=i
else:
if S[i]=="L":
cnt+=1
else:
ans[idx]+=(cnt+1)//2
ans[idx-1]+=cnt//2
cnt=1
f=True
ans[idx]+=(cnt+1)//2
ans[idx-1]+=cnt//2
print((*ans))
| 40 | 31 | 708 | 517 | S = input()
N = len(S)
ans = [0] * N
cnt_o = 1
cnt_e = 0
idx = 0
f = True # True=R
for i in range(1, N):
if f == True:
if S[i] == "R":
temp = cnt_e
cnt_e = cnt_o
cnt_o = temp + 1
else:
ans[i - 1] += cnt_o
ans[i] = cnt_e
cnt_o = 1
cnt_e = 0
f = False
idx = i
else:
if S[i] == "L":
temp = cnt_e
cnt_e = cnt_o
cnt_o = temp + 1
else:
ans[idx] += cnt_o
ans[idx - 1] += cnt_e
cnt_o = 1
cnt_e = 0
f = True
ans[idx] += cnt_o
ans[idx - 1] += cnt_e
for i in range(N):
print(str(ans[i]), end=" ")
| S = eval(input())
N = len(S)
ans = [0] * N
cnt = 1
idx = 0
f = True # True=R
for i in range(1, N):
if f == True:
if S[i] == "R":
cnt += 1
else:
ans[i - 1] += (cnt + 1) // 2
ans[i] = cnt // 2
cnt = 1
f = False
idx = i
else:
if S[i] == "L":
cnt += 1
else:
ans[idx] += (cnt + 1) // 2
ans[idx - 1] += cnt // 2
cnt = 1
f = True
ans[idx] += (cnt + 1) // 2
ans[idx - 1] += cnt // 2
print((*ans))
| false | 22.5 | [
"-S = input()",
"+S = eval(input())",
"-cnt_o = 1",
"-cnt_e = 0",
"+cnt = 1",
"- temp = cnt_e",
"- cnt_e = cnt_o",
"- cnt_o = temp + 1",
"+ cnt += 1",
"- ans[i - 1] += cnt_o",
"- ans[i] = cnt_e",
"- cnt_o = 1",
"- cnt_e = 0",
"+ ans[i - 1] += (cnt + 1) // 2",
"+ ans[i] = cnt // 2",
"+ cnt = 1",
"- temp = cnt_e",
"- cnt_e = cnt_o",
"- cnt_o = temp + 1",
"+ cnt += 1",
"- ans[idx] += cnt_o",
"- ans[idx - 1] += cnt_e",
"- cnt_o = 1",
"- cnt_e = 0",
"+ ans[idx] += (cnt + 1) // 2",
"+ ans[idx - 1] += cnt // 2",
"+ cnt = 1",
"-ans[idx] += cnt_o",
"-ans[idx - 1] += cnt_e",
"-for i in range(N):",
"- print(str(ans[i]), end=\" \")",
"+ans[idx] += (cnt + 1) // 2",
"+ans[idx - 1] += cnt // 2",
"+print((*ans))"
] | false | 0.038297 | 0.097312 | 0.393549 | [
"s014402752",
"s855981209"
] |
u763881112 | p03610 | python | s554875810 | s616643075 | 218 | 151 | 13,788 | 12,756 | Accepted | Accepted | 30.73 |
import numpy as np
s=input()
for i in range(len(s)):
if(i%2==0):
print(s[i],end="")
print()
|
import numpy as np
print((input()[::2]))
| 10 | 6 | 117 | 48 | import numpy as np
s = input()
for i in range(len(s)):
if i % 2 == 0:
print(s[i], end="")
print()
| import numpy as np
print((input()[::2]))
| false | 40 | [
"-s = input()",
"-for i in range(len(s)):",
"- if i % 2 == 0:",
"- print(s[i], end=\"\")",
"-print()",
"+print((input()[::2]))"
] | false | 0.111303 | 0.119643 | 0.930291 | [
"s554875810",
"s616643075"
] |
u912237403 | p00043 | python | s294805589 | s393343090 | 30 | 10 | 4,276 | 4,284 | Accepted | Accepted | 66.67 | def check(x,j=1):
if sum(x)==0: return True
for i in range(j,10):
y = x[:]
if y[i]>=3:
y[i] -= 3
if check(y,i): return True
y = x[:]
if i<8 and y[i]>0 and y[i+1]>0 and y[i+2]>0:
y[i] -= 1
y[i+1] -= 1
y[i+2] -= 1
if check(y,i): return True
return False
while True:
c = [0]*10
try:
for e in map(int,input()):
c[e] += 1
except:
break
f = False
for i in range(1,10):
c1=c[:]
if c1[i]>=4: continue
else: c1[i]+=1
atama = [j for j,e in enumerate(c1) if e>=2]
for e in atama:
c1[e]-=2
if check(c1):
f = True
print(i, end=' ')
break
c1[e]+=2
if f: print()
else: print(0) | def check(x,j=1):
if sum(x)==0: return True
for i in range(j,10):
if x[i]>0:break
y = x[:]
if y[i]>=3:
y[i] -= 3
if check(y,i): return True
y = x[:]
if i<8 and y[i]>0 and y[i+1]>0 and y[i+2]>0:
y[i] -= 1
y[i+1] -= 1
y[i+2] -= 1
if check(y,i): return True
return False
while True:
c = [0]*10
try:
for e in map(int,input()):
c[e] += 1
except:
break
f = False
for i in range(1,10):
c1=c[:]
if c1[i]>=4: continue
else: c1[i]+=1
atama = [j for j,e in enumerate(c1) if e>=2]
for e in atama:
c1[e]-=2
if check(c1):
f = True
print(i, end=' ')
break
c1[e]+=2
if f: print()
else: print(0) | 38 | 39 | 889 | 874 | def check(x, j=1):
if sum(x) == 0:
return True
for i in range(j, 10):
y = x[:]
if y[i] >= 3:
y[i] -= 3
if check(y, i):
return True
y = x[:]
if i < 8 and y[i] > 0 and y[i + 1] > 0 and y[i + 2] > 0:
y[i] -= 1
y[i + 1] -= 1
y[i + 2] -= 1
if check(y, i):
return True
return False
while True:
c = [0] * 10
try:
for e in map(int, input()):
c[e] += 1
except:
break
f = False
for i in range(1, 10):
c1 = c[:]
if c1[i] >= 4:
continue
else:
c1[i] += 1
atama = [j for j, e in enumerate(c1) if e >= 2]
for e in atama:
c1[e] -= 2
if check(c1):
f = True
print(i, end=" ")
break
c1[e] += 2
if f:
print()
else:
print(0)
| def check(x, j=1):
if sum(x) == 0:
return True
for i in range(j, 10):
if x[i] > 0:
break
y = x[:]
if y[i] >= 3:
y[i] -= 3
if check(y, i):
return True
y = x[:]
if i < 8 and y[i] > 0 and y[i + 1] > 0 and y[i + 2] > 0:
y[i] -= 1
y[i + 1] -= 1
y[i + 2] -= 1
if check(y, i):
return True
return False
while True:
c = [0] * 10
try:
for e in map(int, input()):
c[e] += 1
except:
break
f = False
for i in range(1, 10):
c1 = c[:]
if c1[i] >= 4:
continue
else:
c1[i] += 1
atama = [j for j, e in enumerate(c1) if e >= 2]
for e in atama:
c1[e] -= 2
if check(c1):
f = True
print(i, end=" ")
break
c1[e] += 2
if f:
print()
else:
print(0)
| false | 2.564103 | [
"- y = x[:]",
"- if y[i] >= 3:",
"- y[i] -= 3",
"- if check(y, i):",
"- return True",
"- y = x[:]",
"- if i < 8 and y[i] > 0 and y[i + 1] > 0 and y[i + 2] > 0:",
"- y[i] -= 1",
"- y[i + 1] -= 1",
"- y[i + 2] -= 1",
"- if check(y, i):",
"- return True",
"+ if x[i] > 0:",
"+ break",
"+ y = x[:]",
"+ if y[i] >= 3:",
"+ y[i] -= 3",
"+ if check(y, i):",
"+ return True",
"+ y = x[:]",
"+ if i < 8 and y[i] > 0 and y[i + 1] > 0 and y[i + 2] > 0:",
"+ y[i] -= 1",
"+ y[i + 1] -= 1",
"+ y[i + 2] -= 1",
"+ if check(y, i):",
"+ return True"
] | false | 0.189396 | 0.076887 | 2.463291 | [
"s294805589",
"s393343090"
] |
u352394527 | p02371 | python | s447098491 | s669194531 | 990 | 860 | 43,244 | 46,316 | Accepted | Accepted | 13.13 | from heapq import heappop, heappush
INF = 10 ** 20
n = int(eval(input()))
edges = [[] for _ in range(n)]
for _ in range(n - 1):
s, t, w = list(map(int, input().split()))
edges[s].append((w, t))
edges[t].append((w, s))
cost = [INF] * n
que = [(0, 0)]
cost[0] = 0
while que:
acc, num = heappop(que)
for weight, to in edges[num]:
if weight + acc < cost[to]:
cost[to] = weight + acc
heappush(que, (weight + acc, to))
max_ind = cost.index(max(cost))
cost = [INF] * n
que = [(0, max_ind)]
cost[max_ind] = 0
while que:
acc, num = heappop(que)
for weight, to in edges[num]:
if weight + acc < cost[to]:
cost[to] = weight + acc
heappush(que, (weight + acc, to))
print((max(cost)))
| from heapq import heappop, heappush
INF = 10 ** 20
def main():
n = int(eval(input()))
edges = [[] for _ in range(n)]
for _ in range(n - 1):
s, t, w = list(map(int, input().split()))
edges[s].append((w, t))
edges[t].append((w, s))
def func(start):
cost = [INF] * n
que = [(0, start)]
cost[start] = 0
while que:
acc, num = heappop(que)
for weight, to in edges[num]:
if weight + acc < cost[to]:
cost[to] = weight + acc
heappush(que, (weight + acc, to))
return cost
cost1 = func(0)
max_ind = cost1.index(max(cost1))
cost2 = func(max_ind)
print((max(cost2)))
main()
| 34 | 31 | 742 | 681 | from heapq import heappop, heappush
INF = 10**20
n = int(eval(input()))
edges = [[] for _ in range(n)]
for _ in range(n - 1):
s, t, w = list(map(int, input().split()))
edges[s].append((w, t))
edges[t].append((w, s))
cost = [INF] * n
que = [(0, 0)]
cost[0] = 0
while que:
acc, num = heappop(que)
for weight, to in edges[num]:
if weight + acc < cost[to]:
cost[to] = weight + acc
heappush(que, (weight + acc, to))
max_ind = cost.index(max(cost))
cost = [INF] * n
que = [(0, max_ind)]
cost[max_ind] = 0
while que:
acc, num = heappop(que)
for weight, to in edges[num]:
if weight + acc < cost[to]:
cost[to] = weight + acc
heappush(que, (weight + acc, to))
print((max(cost)))
| from heapq import heappop, heappush
INF = 10**20
def main():
n = int(eval(input()))
edges = [[] for _ in range(n)]
for _ in range(n - 1):
s, t, w = list(map(int, input().split()))
edges[s].append((w, t))
edges[t].append((w, s))
def func(start):
cost = [INF] * n
que = [(0, start)]
cost[start] = 0
while que:
acc, num = heappop(que)
for weight, to in edges[num]:
if weight + acc < cost[to]:
cost[to] = weight + acc
heappush(que, (weight + acc, to))
return cost
cost1 = func(0)
max_ind = cost1.index(max(cost1))
cost2 = func(max_ind)
print((max(cost2)))
main()
| false | 8.823529 | [
"-n = int(eval(input()))",
"-edges = [[] for _ in range(n)]",
"-for _ in range(n - 1):",
"- s, t, w = list(map(int, input().split()))",
"- edges[s].append((w, t))",
"- edges[t].append((w, s))",
"-cost = [INF] * n",
"-que = [(0, 0)]",
"-cost[0] = 0",
"-while que:",
"- acc, num = heappop(que)",
"- for weight, to in edges[num]:",
"- if weight + acc < cost[to]:",
"- cost[to] = weight + acc",
"- heappush(que, (weight + acc, to))",
"-max_ind = cost.index(max(cost))",
"-cost = [INF] * n",
"-que = [(0, max_ind)]",
"-cost[max_ind] = 0",
"-while que:",
"- acc, num = heappop(que)",
"- for weight, to in edges[num]:",
"- if weight + acc < cost[to]:",
"- cost[to] = weight + acc",
"- heappush(que, (weight + acc, to))",
"-print((max(cost)))",
"+",
"+",
"+def main():",
"+ n = int(eval(input()))",
"+ edges = [[] for _ in range(n)]",
"+ for _ in range(n - 1):",
"+ s, t, w = list(map(int, input().split()))",
"+ edges[s].append((w, t))",
"+ edges[t].append((w, s))",
"+",
"+ def func(start):",
"+ cost = [INF] * n",
"+ que = [(0, start)]",
"+ cost[start] = 0",
"+ while que:",
"+ acc, num = heappop(que)",
"+ for weight, to in edges[num]:",
"+ if weight + acc < cost[to]:",
"+ cost[to] = weight + acc",
"+ heappush(que, (weight + acc, to))",
"+ return cost",
"+",
"+ cost1 = func(0)",
"+ max_ind = cost1.index(max(cost1))",
"+ cost2 = func(max_ind)",
"+ print((max(cost2)))",
"+",
"+",
"+main()"
] | false | 0.038123 | 0.036789 | 1.036251 | [
"s447098491",
"s669194531"
] |
u186838327 | p02763 | python | s952468416 | s881277797 | 1,755 | 1,552 | 477,816 | 476,372 | Accepted | Accepted | 11.57 | n = int(eval(input()))
s = list(str(eval(input())))
s = [{ord(c)-ord('a')} for c in s]
def segfunc(x, y):
return x | y
def init(init_val):
# set_val
for i in range(n):
seg[i+num-1] = init_val[i]
# built
for i in range(num-2, -1, -1):
seg[i] = segfunc(seg[2*i+1], seg[2*i+2])
def update(k, x):
k += num - 1
seg[k] = x
while k:
k = (k-1)//2
seg[k] = segfunc(seg[2*k+1], seg[2*k+2])
def query(p, q):
if q <= p:
return ide_ele
p += num - 1
q += num - 2
res = ide_ele
while q-p>1:
if p&1 == 0:
res = segfunc(res, seg[p])
if q&1 == 1:
res = segfunc(res, seg[q])
q -= 1
p = p//2
q = (q-1)//2
if p == q:
res = segfunc(res, seg[p])
else:
res = segfunc(segfunc(res, seg[p]), seg[q])
return res
# identity element
ide_ele = set()
# num: n以上の最小の2のべき乗
num = 2**(n-1).bit_length()
seg = [ide_ele]*2*num
init(s)
q = int(eval(input()))
for _ in range(q):
t, x, y = list(map(str, input().split()))
if t == '1':
i = int(x)-1
c = {ord(y)-ord('a')}
update(i, c)
else:
l = int(x)-1
r = int(y)-1
print((len(query(l, r+1)))) | import sys
input = sys.stdin.readline
n = int(eval(input()))
s = list(str(eval(input())))
s = [{ord(c)-ord('a')} for c in s]
def segfunc(x, y):
return x | y
def init(init_val):
# set_val
for i in range(n):
seg[i+num-1] = init_val[i]
# built
for i in range(num-2, -1, -1):
seg[i] = segfunc(seg[2*i+1], seg[2*i+2])
def update(k, x):
k += num - 1
seg[k] = x
while k:
k = (k-1)//2
seg[k] = segfunc(seg[2*k+1], seg[2*k+2])
def query(p, q):
if q <= p:
return ide_ele
p += num - 1
q += num - 2
res = ide_ele
while q-p>1:
if p&1 == 0:
res = segfunc(res, seg[p])
if q&1 == 1:
res = segfunc(res, seg[q])
q -= 1
p = p//2
q = (q-1)//2
if p == q:
res = segfunc(res, seg[p])
else:
res = segfunc(segfunc(res, seg[p]), seg[q])
return res
# identity element
ide_ele = set()
# num: n以上の最小の2のべき乗
num = 2**(n-1).bit_length()
seg = [ide_ele]*2*num
init(s)
q = int(eval(input()))
for _ in range(q):
t, x, y = list(map(str, input().split()))
if t == '1':
i = int(x)-1
c = {ord(y)-ord('a')}
update(i, c)
else:
l = int(x)-1
r = int(y)-1
print((len(query(l, r+1))))
| 62 | 65 | 1,292 | 1,335 | n = int(eval(input()))
s = list(str(eval(input())))
s = [{ord(c) - ord("a")} for c in s]
def segfunc(x, y):
return x | y
def init(init_val):
# set_val
for i in range(n):
seg[i + num - 1] = init_val[i]
# built
for i in range(num - 2, -1, -1):
seg[i] = segfunc(seg[2 * i + 1], seg[2 * i + 2])
def update(k, x):
k += num - 1
seg[k] = x
while k:
k = (k - 1) // 2
seg[k] = segfunc(seg[2 * k + 1], seg[2 * k + 2])
def query(p, q):
if q <= p:
return ide_ele
p += num - 1
q += num - 2
res = ide_ele
while q - p > 1:
if p & 1 == 0:
res = segfunc(res, seg[p])
if q & 1 == 1:
res = segfunc(res, seg[q])
q -= 1
p = p // 2
q = (q - 1) // 2
if p == q:
res = segfunc(res, seg[p])
else:
res = segfunc(segfunc(res, seg[p]), seg[q])
return res
# identity element
ide_ele = set()
# num: n以上の最小の2のべき乗
num = 2 ** (n - 1).bit_length()
seg = [ide_ele] * 2 * num
init(s)
q = int(eval(input()))
for _ in range(q):
t, x, y = list(map(str, input().split()))
if t == "1":
i = int(x) - 1
c = {ord(y) - ord("a")}
update(i, c)
else:
l = int(x) - 1
r = int(y) - 1
print((len(query(l, r + 1))))
| import sys
input = sys.stdin.readline
n = int(eval(input()))
s = list(str(eval(input())))
s = [{ord(c) - ord("a")} for c in s]
def segfunc(x, y):
return x | y
def init(init_val):
# set_val
for i in range(n):
seg[i + num - 1] = init_val[i]
# built
for i in range(num - 2, -1, -1):
seg[i] = segfunc(seg[2 * i + 1], seg[2 * i + 2])
def update(k, x):
k += num - 1
seg[k] = x
while k:
k = (k - 1) // 2
seg[k] = segfunc(seg[2 * k + 1], seg[2 * k + 2])
def query(p, q):
if q <= p:
return ide_ele
p += num - 1
q += num - 2
res = ide_ele
while q - p > 1:
if p & 1 == 0:
res = segfunc(res, seg[p])
if q & 1 == 1:
res = segfunc(res, seg[q])
q -= 1
p = p // 2
q = (q - 1) // 2
if p == q:
res = segfunc(res, seg[p])
else:
res = segfunc(segfunc(res, seg[p]), seg[q])
return res
# identity element
ide_ele = set()
# num: n以上の最小の2のべき乗
num = 2 ** (n - 1).bit_length()
seg = [ide_ele] * 2 * num
init(s)
q = int(eval(input()))
for _ in range(q):
t, x, y = list(map(str, input().split()))
if t == "1":
i = int(x) - 1
c = {ord(y) - ord("a")}
update(i, c)
else:
l = int(x) - 1
r = int(y) - 1
print((len(query(l, r + 1))))
| false | 4.615385 | [
"+import sys",
"+",
"+input = sys.stdin.readline"
] | false | 0.042016 | 0.060342 | 0.696287 | [
"s952468416",
"s881277797"
] |
u497046426 | p02735 | python | s100749103 | s491633230 | 80 | 72 | 7,028 | 7,284 | Accepted | Accepted | 10 | from itertools import product
from heapq import heappush, heappop
class Dijkstra:
def __init__(self, N):
self.N = N # #vertices
self.E = [[] for _ in range(N)]
def add_edge(self, init, end, weight, undirected=False):
self.E[init].append((end, weight))
if undirected: self.E[end].append((init, weight))
def distance(self, s):
INF = float('inf')
self.dist = [INF] * self.N # the distance of each vertex from s
self.prev = [-1] * self.N # the previous vertex of each vertex on a shortest path from s
n_visited = 0 # #(visited vertices)
heap = []
heappush(heap, (0, -1, s))
while heap:
d, p, v = heappop(heap)
if self.dist[v] != INF: continue # (s,v)-shortest path is already calculated
self.dist[v] = d; self.prev[v] = p
n_visited += 1
if n_visited == self.N: break
for u, c in self.E[v]:
if self.dist[u] != INF: continue
temp = d + c
if self.dist[u] > temp: heappush(heap, (temp, v, u))
return self.dist
def shortest_path(self, t):
P = []
prev = self.prev
while True:
P.append(t)
t = prev[t]
if t == -1: break
return P[::-1]
H, W = list(map(int, input().split()))
dijkstra = Dijkstra(H * W)
def vtx(i, j): return i*W + j
def coord(n): return divmod(n, W)
grid = [eval(input()) for _ in range(H)] # |string| = W
E = [[] for _ in range(H * W)]
ans = 0 if grid[0][0] == '.' else 1
for i, j in product(list(range(H)), list(range(W))):
v = vtx(i, j)
check = [vtx(i+dx, j+dy) for dx, dy in [(1, 0), (0, 1)] if i+dx <= H-1 and j+dy <= W-1]
for u in check:
x, y = coord(u)
if grid[i][j] == '.' and grid[x][y] == '#':
dijkstra.add_edge(v, u, 1)
else:
dijkstra.add_edge(v, u, 0)
dist = dijkstra.distance(0)
ans += dist[vtx(H-1, W-1)]
print(ans) | from itertools import product
from collections import deque
class ZeroOneBFS:
def __init__(self, N):
self.N = N # #vertices
self.E = [[] for _ in range(N)]
def add_edge(self, init, end, weight, undirected=False):
assert weight in [0, 1]
self.E[init].append((end, weight))
if undirected: self.E[end].append((init, weight))
def distance(self, s):
INF = float('inf')
E, N = self.E, self.N
dist = [INF] * N # the distance of each vertex from s
prev = [-1] * N # the previous vertex of each vertex on a shortest path from s
dist[s] = 0
dq = deque([(0, s)]) # (dist, vertex)
n_visited = 0 # #(visited vertices)
while dq:
d, v = dq.popleft()
if dist[v] < d: continue # (s,v)-shortest path is already calculated
for u, c in E[v]:
temp = d + c
if dist[u] > temp:
dist[u] = temp; prev[u] = v
if c == 0: dq.appendleft((temp, u))
else: dq.append((temp, u))
n_visited += 1
if n_visited == N: break
self.dist, self.prev = dist, prev
return dist
def shortest_path(self, t):
P = []
prev = self.prev
while True:
P.append(t)
t = prev[t]
if t == -1: break
return P[::-1]
H, W = list(map(int, input().split()))
zobfs = ZeroOneBFS(H * W)
def vtx(i, j): return i*W + j
def coord(n): return divmod(n, W)
grid = [eval(input()) for _ in range(H)] # |string| = W
E = [[] for _ in range(H * W)]
ans = 0 if grid[0][0] == '.' else 1
for i, j in product(list(range(H)), list(range(W))):
v = vtx(i, j)
check = [vtx(i+dx, j+dy) for dx, dy in [(1, 0), (0, 1)] if i+dx <= H-1 and j+dy <= W-1]
for u in check:
x, y = coord(u)
if grid[i][j] == '.' and grid[x][y] == '#':
zobfs.add_edge(v, u, 1)
else:
zobfs.add_edge(v, u, 0)
dist = zobfs.distance(0)
ans += dist[vtx(H-1, W-1)]
print(ans) | 61 | 65 | 2,043 | 2,137 | from itertools import product
from heapq import heappush, heappop
class Dijkstra:
def __init__(self, N):
self.N = N # #vertices
self.E = [[] for _ in range(N)]
def add_edge(self, init, end, weight, undirected=False):
self.E[init].append((end, weight))
if undirected:
self.E[end].append((init, weight))
def distance(self, s):
INF = float("inf")
self.dist = [INF] * self.N # the distance of each vertex from s
self.prev = [
-1
] * self.N # the previous vertex of each vertex on a shortest path from s
n_visited = 0 # #(visited vertices)
heap = []
heappush(heap, (0, -1, s))
while heap:
d, p, v = heappop(heap)
if self.dist[v] != INF:
continue # (s,v)-shortest path is already calculated
self.dist[v] = d
self.prev[v] = p
n_visited += 1
if n_visited == self.N:
break
for u, c in self.E[v]:
if self.dist[u] != INF:
continue
temp = d + c
if self.dist[u] > temp:
heappush(heap, (temp, v, u))
return self.dist
def shortest_path(self, t):
P = []
prev = self.prev
while True:
P.append(t)
t = prev[t]
if t == -1:
break
return P[::-1]
H, W = list(map(int, input().split()))
dijkstra = Dijkstra(H * W)
def vtx(i, j):
return i * W + j
def coord(n):
return divmod(n, W)
grid = [eval(input()) for _ in range(H)] # |string| = W
E = [[] for _ in range(H * W)]
ans = 0 if grid[0][0] == "." else 1
for i, j in product(list(range(H)), list(range(W))):
v = vtx(i, j)
check = [
vtx(i + dx, j + dy)
for dx, dy in [(1, 0), (0, 1)]
if i + dx <= H - 1 and j + dy <= W - 1
]
for u in check:
x, y = coord(u)
if grid[i][j] == "." and grid[x][y] == "#":
dijkstra.add_edge(v, u, 1)
else:
dijkstra.add_edge(v, u, 0)
dist = dijkstra.distance(0)
ans += dist[vtx(H - 1, W - 1)]
print(ans)
| from itertools import product
from collections import deque
class ZeroOneBFS:
def __init__(self, N):
self.N = N # #vertices
self.E = [[] for _ in range(N)]
def add_edge(self, init, end, weight, undirected=False):
assert weight in [0, 1]
self.E[init].append((end, weight))
if undirected:
self.E[end].append((init, weight))
def distance(self, s):
INF = float("inf")
E, N = self.E, self.N
dist = [INF] * N # the distance of each vertex from s
prev = [-1] * N # the previous vertex of each vertex on a shortest path from s
dist[s] = 0
dq = deque([(0, s)]) # (dist, vertex)
n_visited = 0 # #(visited vertices)
while dq:
d, v = dq.popleft()
if dist[v] < d:
continue # (s,v)-shortest path is already calculated
for u, c in E[v]:
temp = d + c
if dist[u] > temp:
dist[u] = temp
prev[u] = v
if c == 0:
dq.appendleft((temp, u))
else:
dq.append((temp, u))
n_visited += 1
if n_visited == N:
break
self.dist, self.prev = dist, prev
return dist
def shortest_path(self, t):
P = []
prev = self.prev
while True:
P.append(t)
t = prev[t]
if t == -1:
break
return P[::-1]
H, W = list(map(int, input().split()))
zobfs = ZeroOneBFS(H * W)
def vtx(i, j):
return i * W + j
def coord(n):
return divmod(n, W)
grid = [eval(input()) for _ in range(H)] # |string| = W
E = [[] for _ in range(H * W)]
ans = 0 if grid[0][0] == "." else 1
for i, j in product(list(range(H)), list(range(W))):
v = vtx(i, j)
check = [
vtx(i + dx, j + dy)
for dx, dy in [(1, 0), (0, 1)]
if i + dx <= H - 1 and j + dy <= W - 1
]
for u in check:
x, y = coord(u)
if grid[i][j] == "." and grid[x][y] == "#":
zobfs.add_edge(v, u, 1)
else:
zobfs.add_edge(v, u, 0)
dist = zobfs.distance(0)
ans += dist[vtx(H - 1, W - 1)]
print(ans)
| false | 6.153846 | [
"-from heapq import heappush, heappop",
"+from collections import deque",
"-class Dijkstra:",
"+class ZeroOneBFS:",
"+ assert weight in [0, 1]",
"- self.dist = [INF] * self.N # the distance of each vertex from s",
"- self.prev = [",
"- -1",
"- ] * self.N # the previous vertex of each vertex on a shortest path from s",
"+ E, N = self.E, self.N",
"+ dist = [INF] * N # the distance of each vertex from s",
"+ prev = [-1] * N # the previous vertex of each vertex on a shortest path from s",
"+ dist[s] = 0",
"+ dq = deque([(0, s)]) # (dist, vertex)",
"- heap = []",
"- heappush(heap, (0, -1, s))",
"- while heap:",
"- d, p, v = heappop(heap)",
"- if self.dist[v] != INF:",
"+ while dq:",
"+ d, v = dq.popleft()",
"+ if dist[v] < d:",
"- self.dist[v] = d",
"- self.prev[v] = p",
"+ for u, c in E[v]:",
"+ temp = d + c",
"+ if dist[u] > temp:",
"+ dist[u] = temp",
"+ prev[u] = v",
"+ if c == 0:",
"+ dq.appendleft((temp, u))",
"+ else:",
"+ dq.append((temp, u))",
"- if n_visited == self.N:",
"+ if n_visited == N:",
"- for u, c in self.E[v]:",
"- if self.dist[u] != INF:",
"- continue",
"- temp = d + c",
"- if self.dist[u] > temp:",
"- heappush(heap, (temp, v, u))",
"- return self.dist",
"+ self.dist, self.prev = dist, prev",
"+ return dist",
"-dijkstra = Dijkstra(H * W)",
"+zobfs = ZeroOneBFS(H * W)",
"- dijkstra.add_edge(v, u, 1)",
"+ zobfs.add_edge(v, u, 1)",
"- dijkstra.add_edge(v, u, 0)",
"-dist = dijkstra.distance(0)",
"+ zobfs.add_edge(v, u, 0)",
"+dist = zobfs.distance(0)"
] | false | 0.041133 | 0.040065 | 1.02667 | [
"s100749103",
"s491633230"
] |
u644907318 | p03994 | python | s658732070 | s359046490 | 111 | 78 | 3,572 | 77,176 | Accepted | Accepted | 29.73 | s = input().strip()
K = int(eval(input()))
if K>len(s)*26:
d = (K-len(s)*26)//26
K = K-26*d
x = ""
for i in range(len(s)):
if i<len(s)-1 and (26-(ord(s[i])-ord("a")))%26 <= K:
x += "a"
K -= (26-(ord(s[i])-ord("a")))%26
elif i<len(s)-1:
x += s[i]
elif i==len(s)-1:
k = ord(s[i])+K%26
if k<=122:
x += chr(k)
else:
x += chr(k-26)
print(x) | A = {i-97:chr(i) for i in range(97,123)}
B = {v:k for k,v in list(A.items())}
s = list(input().strip())
K = int(eval(input()))
for i in range(len(s)-1):
if s[i]!="a" and K>=26-B[s[i]]:
K -= (26-B[s[i]])
s[i]="a"
k = K%26
ind = (B[s[-1]]+k)%26
s[-1] = A[ind]
print(("".join(s))) | 19 | 12 | 439 | 294 | s = input().strip()
K = int(eval(input()))
if K > len(s) * 26:
d = (K - len(s) * 26) // 26
K = K - 26 * d
x = ""
for i in range(len(s)):
if i < len(s) - 1 and (26 - (ord(s[i]) - ord("a"))) % 26 <= K:
x += "a"
K -= (26 - (ord(s[i]) - ord("a"))) % 26
elif i < len(s) - 1:
x += s[i]
elif i == len(s) - 1:
k = ord(s[i]) + K % 26
if k <= 122:
x += chr(k)
else:
x += chr(k - 26)
print(x)
| A = {i - 97: chr(i) for i in range(97, 123)}
B = {v: k for k, v in list(A.items())}
s = list(input().strip())
K = int(eval(input()))
for i in range(len(s) - 1):
if s[i] != "a" and K >= 26 - B[s[i]]:
K -= 26 - B[s[i]]
s[i] = "a"
k = K % 26
ind = (B[s[-1]] + k) % 26
s[-1] = A[ind]
print(("".join(s)))
| false | 36.842105 | [
"-s = input().strip()",
"+A = {i - 97: chr(i) for i in range(97, 123)}",
"+B = {v: k for k, v in list(A.items())}",
"+s = list(input().strip())",
"-if K > len(s) * 26:",
"- d = (K - len(s) * 26) // 26",
"- K = K - 26 * d",
"-x = \"\"",
"-for i in range(len(s)):",
"- if i < len(s) - 1 and (26 - (ord(s[i]) - ord(\"a\"))) % 26 <= K:",
"- x += \"a\"",
"- K -= (26 - (ord(s[i]) - ord(\"a\"))) % 26",
"- elif i < len(s) - 1:",
"- x += s[i]",
"- elif i == len(s) - 1:",
"- k = ord(s[i]) + K % 26",
"- if k <= 122:",
"- x += chr(k)",
"- else:",
"- x += chr(k - 26)",
"-print(x)",
"+for i in range(len(s) - 1):",
"+ if s[i] != \"a\" and K >= 26 - B[s[i]]:",
"+ K -= 26 - B[s[i]]",
"+ s[i] = \"a\"",
"+k = K % 26",
"+ind = (B[s[-1]] + k) % 26",
"+s[-1] = A[ind]",
"+print((\"\".join(s)))"
] | false | 0.06994 | 0.069683 | 1.003691 | [
"s658732070",
"s359046490"
] |
u316386814 | p03967 | python | s722370381 | s950940484 | 49 | 18 | 3,188 | 3,188 | Accepted | Accepted | 63.27 | s = eval(input())
ans = 0
for i, x in enumerate(s):
if i % 2 == 0 and x == 'p':
ans -= 1
elif i % 2 == 1 and x == 'g':
ans += 1
print(ans) | s = eval(input())
ans = len(s) // 2 - s.count('p')
print(ans) | 10 | 5 | 167 | 61 | s = eval(input())
ans = 0
for i, x in enumerate(s):
if i % 2 == 0 and x == "p":
ans -= 1
elif i % 2 == 1 and x == "g":
ans += 1
print(ans)
| s = eval(input())
ans = len(s) // 2 - s.count("p")
print(ans)
| false | 50 | [
"-ans = 0",
"-for i, x in enumerate(s):",
"- if i % 2 == 0 and x == \"p\":",
"- ans -= 1",
"- elif i % 2 == 1 and x == \"g\":",
"- ans += 1",
"+ans = len(s) // 2 - s.count(\"p\")"
] | false | 0.036839 | 0.037985 | 0.969839 | [
"s722370381",
"s950940484"
] |
u912237403 | p00084 | python | s963638891 | s378902102 | 20 | 10 | 4,192 | 4,192 | Accepted | Accepted | 50 | s=input()
s=s.replace(","," ")
s=s.replace("."," ")
for w in s.split():
if 3<=len(w)<=6:print(w, end=' ')
print() | s=input().replace(","," ").replace("."," ").split()
s=" ".join([w for w in s if 2<len(w)<7])
print(s) | 6 | 3 | 113 | 106 | s = input()
s = s.replace(",", " ")
s = s.replace(".", " ")
for w in s.split():
if 3 <= len(w) <= 6:
print(w, end=" ")
print()
| s = input().replace(",", " ").replace(".", " ").split()
s = " ".join([w for w in s if 2 < len(w) < 7])
print(s)
| false | 50 | [
"-s = input()",
"-s = s.replace(\",\", \" \")",
"-s = s.replace(\".\", \" \")",
"-for w in s.split():",
"- if 3 <= len(w) <= 6:",
"- print(w, end=\" \")",
"-print()",
"+s = input().replace(\",\", \" \").replace(\".\", \" \").split()",
"+s = \" \".join([w for w in s if 2 < len(w) < 7])",
"+print(s)"
] | false | 0.034896 | 0.034219 | 1.019772 | [
"s963638891",
"s378902102"
] |
u543152022 | p02911 | python | s669987930 | s637181206 | 298 | 170 | 9,052 | 9,056 | Accepted | Accepted | 42.95 | n, k, q = list(map(int, input().split()))
def judge():
val = {}
for _ in range(q):
a = int(eval(input()))
val[a-1] = val.get(a-1,0) + 1
#print(val)
for i in range(n):
if val.get(i,k-q) + (k - q) > 0:
print('Yes')
else:
print('No')
if k > q:
print((*['Yes' for _ in range(n)]))
else:
ans = judge()
| import sys
input = sys.stdin.readline
n, k, q = list(map(int, input().split()))
def judge():
val = {}
for _ in range(q):
a = int(eval(input()))
val[a-1] = val.get(a-1,0) + 1
#print(val)
for i in range(n):
if val.get(i,k-q) + (k - q) > 0:
print('Yes')
else:
print('No')
if k > q:
print((*['Yes' for _ in range(n)]))
else:
ans = judge()
| 16 | 18 | 378 | 418 | n, k, q = list(map(int, input().split()))
def judge():
val = {}
for _ in range(q):
a = int(eval(input()))
val[a - 1] = val.get(a - 1, 0) + 1
# print(val)
for i in range(n):
if val.get(i, k - q) + (k - q) > 0:
print("Yes")
else:
print("No")
if k > q:
print((*["Yes" for _ in range(n)]))
else:
ans = judge()
| import sys
input = sys.stdin.readline
n, k, q = list(map(int, input().split()))
def judge():
val = {}
for _ in range(q):
a = int(eval(input()))
val[a - 1] = val.get(a - 1, 0) + 1
# print(val)
for i in range(n):
if val.get(i, k - q) + (k - q) > 0:
print("Yes")
else:
print("No")
if k > q:
print((*["Yes" for _ in range(n)]))
else:
ans = judge()
| false | 11.111111 | [
"+import sys",
"+",
"+input = sys.stdin.readline"
] | false | 0.083337 | 0.04458 | 1.869381 | [
"s669987930",
"s637181206"
] |
u645250356 | p03186 | python | s930885446 | s782410593 | 188 | 39 | 38,640 | 10,484 | Accepted | Accepted | 79.26 | from collections import Counter,defaultdict,deque
from heapq import heapify,heappop,heappush
import sys,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))
a,b,c = inpl()
if a + b + 1 >= c:
print((b+c))
else:
print((a+b+1+b))
| from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right
import sys,math,itertools,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
a,b,c = inpl()
if b >= c:
print((b+c))
exit()
if a < c-b:
print((a+2*b+1))
else:
print((b+c))
| 16 | 18 | 511 | 458 | from collections import Counter, defaultdict, deque
from heapq import heapify, heappop, heappush
import sys, bisect, math, itertools, string, queue
sys.setrecursionlimit(10**8)
mod = 10**9 + 7
def inp():
return int(sys.stdin.readline())
def inpl():
return list(map(int, sys.stdin.readline().split()))
def inpl_str():
return list(sys.stdin.readline().split())
def inpln(n):
return list(int(sys.stdin.readline()) for i in range(n))
a, b, c = inpl()
if a + b + 1 >= c:
print((b + c))
else:
print((a + b + 1 + b))
| from collections import Counter, defaultdict, deque
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right
import sys, math, itertools, fractions
sys.setrecursionlimit(10**8)
mod = 10**9 + 7
INF = float("inf")
def inp():
return int(sys.stdin.readline())
def inpl():
return list(map(int, sys.stdin.readline().split()))
a, b, c = inpl()
if b >= c:
print((b + c))
exit()
if a < c - b:
print((a + 2 * b + 1))
else:
print((b + c))
| false | 11.111111 | [
"-from heapq import heapify, heappop, heappush",
"-import sys, bisect, math, itertools, string, queue",
"+from heapq import heappop, heappush",
"+from bisect import bisect_left, bisect_right",
"+import sys, math, itertools, fractions",
"+INF = float(\"inf\")",
"-def inpl_str():",
"- return list(sys.stdin.readline().split())",
"-",
"-",
"-def inpln(n):",
"- return list(int(sys.stdin.readline()) for i in range(n))",
"-",
"-",
"-if a + b + 1 >= c:",
"+if b >= c:",
"+ exit()",
"+if a < c - b:",
"+ print((a + 2 * b + 1))",
"- print((a + b + 1 + b))",
"+ print((b + c))"
] | false | 0.034321 | 0.054686 | 0.627601 | [
"s930885446",
"s782410593"
] |
u077898957 | p02885 | python | s637620710 | s979362115 | 1,816 | 17 | 22,028 | 2,940 | Accepted | Accepted | 99.06 | import numpy as np
import sys
a,b = list(map(int,input().split()))
c = b*2
print((a-c if a-c>=0 else 0))
| a,b=list(map(int,input().split()))
print((max(0,a-2*b)))
| 5 | 2 | 101 | 50 | import numpy as np
import sys
a, b = list(map(int, input().split()))
c = b * 2
print((a - c if a - c >= 0 else 0))
| a, b = list(map(int, input().split()))
print((max(0, a - 2 * b)))
| false | 60 | [
"-import numpy as np",
"-import sys",
"-",
"-c = b * 2",
"-print((a - c if a - c >= 0 else 0))",
"+print((max(0, a - 2 * b)))"
] | false | 0.047067 | 0.045846 | 1.026644 | [
"s637620710",
"s979362115"
] |
u535803878 | p02781 | python | s717347009 | s802176410 | 184 | 86 | 38,384 | 62,612 | Accepted | Accepted | 53.26 | ## ABC154E
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")
M = 10**9+7 # 出力の制限
N = 100 # 必要なテーブルサイズ
def cmb(n, r, M):
if ( r<0 or r>n ):
return 0
r = min(r, n-r)
return (g1[n] * g2[r] * g2[n-r]) % M
g1 = [None] * (N+1) # 元テーブル
g2 = [None] * (N+1) #逆元テーブル
inverse = [None] * (N+1) #逆元テーブル計算用テーブル
g1[0] = g1[1] = g2[0] = g2[1] = 1
inverse[0], inverse[1] = [0, 1]
for i in range( 2, N + 1 ):
g1[i] = ( g1[i-1] * i ) % M
inverse[i] = ( -inverse[M % i] * (M//i) ) % M # ai+b==0 mod M <=> i==-b*a^(-1) <=> i^(-1)==-b^(-1)*aより
g2[i] = (g2[i-1] * inverse[i]) % M
n = eval(input())
k = int(eval(input()))
l = len(n)
dp0 = [[0]*(k+1) for _ in range(l+1)] # i桁目まででNより小さく、非零がjの個数
dp1 = [[0]*(k+1) for _ in range(l+1)] # i桁目でNと同じで、非零がjの個数
dp1[0][0] = 1
if k>l:
ans = 0
else:
for i in range(1,l+1):
for j in range(k+1):
c = int(n[i-1])
if j>=1:
dp0[i][j] += 9 * dp0[i-1][j-1]
dp0[i][j] += dp0[i-1][j]
if c>=1:
dp0[i][j] += dp1[i-1][j]
if j>=1:
dp0[i][j] += (c-1) * dp1[i-1][j-1]
if c==0:
dp1[i][j] += dp1[i-1][j]
elif j>=1:
dp1[i][j] += dp1[i-1][j-1]
ans = dp0[l][k] + dp1[l][k]
print(ans) | import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")
n = eval(input())
k = int(eval(input()))
l = len(n)
dp1 = [[0]*(k+1) for _ in range(l+1)]
dp0 = [[0]*(k+1) for _ in range(l+1)]
dp1[0][0] = 1
dp0[0][0] = 0
for i in range(1, l+1):
for j in range(0, k+1):
if n[i-1]=="0":
dp1[i][j] = dp1[i-1][j]
else:
if j>=1:
dp1[i][j] = dp1[i-1][j-1]
dp0[i][j] += dp1[i-1][j]
if int(n[i-1])>=2 and j>=1:
dp0[i][j] += dp1[i-1][j-1] * (int(n[i-1])-1)
if j>=1:
dp0[i][j] += dp0[i-1][j-1]*9
dp0[i][j] += dp0[i-1][j]
print((dp0[l][k]+dp1[l][k])) | 59 | 27 | 1,494 | 749 | ## ABC154E
import sys
input = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x + "\n")
M = 10**9 + 7 # 出力の制限
N = 100 # 必要なテーブルサイズ
def cmb(n, r, M):
if r < 0 or r > n:
return 0
r = min(r, n - r)
return (g1[n] * g2[r] * g2[n - r]) % M
g1 = [None] * (N + 1) # 元テーブル
g2 = [None] * (N + 1) # 逆元テーブル
inverse = [None] * (N + 1) # 逆元テーブル計算用テーブル
g1[0] = g1[1] = g2[0] = g2[1] = 1
inverse[0], inverse[1] = [0, 1]
for i in range(2, N + 1):
g1[i] = (g1[i - 1] * i) % M
inverse[i] = (
-inverse[M % i] * (M // i)
) % M # ai+b==0 mod M <=> i==-b*a^(-1) <=> i^(-1)==-b^(-1)*aより
g2[i] = (g2[i - 1] * inverse[i]) % M
n = eval(input())
k = int(eval(input()))
l = len(n)
dp0 = [[0] * (k + 1) for _ in range(l + 1)] # i桁目まででNより小さく、非零がjの個数
dp1 = [[0] * (k + 1) for _ in range(l + 1)] # i桁目でNと同じで、非零がjの個数
dp1[0][0] = 1
if k > l:
ans = 0
else:
for i in range(1, l + 1):
for j in range(k + 1):
c = int(n[i - 1])
if j >= 1:
dp0[i][j] += 9 * dp0[i - 1][j - 1]
dp0[i][j] += dp0[i - 1][j]
if c >= 1:
dp0[i][j] += dp1[i - 1][j]
if j >= 1:
dp0[i][j] += (c - 1) * dp1[i - 1][j - 1]
if c == 0:
dp1[i][j] += dp1[i - 1][j]
elif j >= 1:
dp1[i][j] += dp1[i - 1][j - 1]
ans = dp0[l][k] + dp1[l][k]
print(ans)
| import sys
input = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x + "\n")
n = eval(input())
k = int(eval(input()))
l = len(n)
dp1 = [[0] * (k + 1) for _ in range(l + 1)]
dp0 = [[0] * (k + 1) for _ in range(l + 1)]
dp1[0][0] = 1
dp0[0][0] = 0
for i in range(1, l + 1):
for j in range(0, k + 1):
if n[i - 1] == "0":
dp1[i][j] = dp1[i - 1][j]
else:
if j >= 1:
dp1[i][j] = dp1[i - 1][j - 1]
dp0[i][j] += dp1[i - 1][j]
if int(n[i - 1]) >= 2 and j >= 1:
dp0[i][j] += dp1[i - 1][j - 1] * (int(n[i - 1]) - 1)
if j >= 1:
dp0[i][j] += dp0[i - 1][j - 1] * 9
dp0[i][j] += dp0[i - 1][j]
print((dp0[l][k] + dp1[l][k]))
| false | 54.237288 | [
"-## ABC154E",
"-M = 10**9 + 7 # 出力の制限",
"-N = 100 # 必要なテーブルサイズ",
"-",
"-",
"-def cmb(n, r, M):",
"- if r < 0 or r > n:",
"- return 0",
"- r = min(r, n - r)",
"- return (g1[n] * g2[r] * g2[n - r]) % M",
"-",
"-",
"-g1 = [None] * (N + 1) # 元テーブル",
"-g2 = [None] * (N + 1) # 逆元テーブル",
"-inverse = [None] * (N + 1) # 逆元テーブル計算用テーブル",
"-g1[0] = g1[1] = g2[0] = g2[1] = 1",
"-inverse[0], inverse[1] = [0, 1]",
"-for i in range(2, N + 1):",
"- g1[i] = (g1[i - 1] * i) % M",
"- inverse[i] = (",
"- -inverse[M % i] * (M // i)",
"- ) % M # ai+b==0 mod M <=> i==-b*a^(-1) <=> i^(-1)==-b^(-1)*aより",
"- g2[i] = (g2[i - 1] * inverse[i]) % M",
"-dp0 = [[0] * (k + 1) for _ in range(l + 1)] # i桁目まででNより小さく、非零がjの個数",
"-dp1 = [[0] * (k + 1) for _ in range(l + 1)] # i桁目でNと同じで、非零がjの個数",
"+dp1 = [[0] * (k + 1) for _ in range(l + 1)]",
"+dp0 = [[0] * (k + 1) for _ in range(l + 1)]",
"-if k > l:",
"- ans = 0",
"-else:",
"- for i in range(1, l + 1):",
"- for j in range(k + 1):",
"- c = int(n[i - 1])",
"+dp0[0][0] = 0",
"+for i in range(1, l + 1):",
"+ for j in range(0, k + 1):",
"+ if n[i - 1] == \"0\":",
"+ dp1[i][j] = dp1[i - 1][j]",
"+ else:",
"- dp0[i][j] += 9 * dp0[i - 1][j - 1]",
"- dp0[i][j] += dp0[i - 1][j]",
"- if c >= 1:",
"- dp0[i][j] += dp1[i - 1][j]",
"- if j >= 1:",
"- dp0[i][j] += (c - 1) * dp1[i - 1][j - 1]",
"- if c == 0:",
"- dp1[i][j] += dp1[i - 1][j]",
"- elif j >= 1:",
"- dp1[i][j] += dp1[i - 1][j - 1]",
"-ans = dp0[l][k] + dp1[l][k]",
"-print(ans)",
"+ dp1[i][j] = dp1[i - 1][j - 1]",
"+ dp0[i][j] += dp1[i - 1][j]",
"+ if int(n[i - 1]) >= 2 and j >= 1:",
"+ dp0[i][j] += dp1[i - 1][j - 1] * (int(n[i - 1]) - 1)",
"+ if j >= 1:",
"+ dp0[i][j] += dp0[i - 1][j - 1] * 9",
"+ dp0[i][j] += dp0[i - 1][j]",
"+print((dp0[l][k] + dp1[l][k]))"
] | false | 0.034331 | 0.04043 | 0.849125 | [
"s717347009",
"s802176410"
] |
u029169777 | p03250 | python | s398967129 | s063723750 | 20 | 17 | 3,316 | 2,940 | Accepted | Accepted | 15 | A,B,C=list(map(int,input().split()))
print((max(A,B,C)*9+A+B+C)) | A,B,C=list(map(int,input().split()))
maxa=max(A,B,C)
print((maxa*9+A+B+C)) | 3 | 5 | 59 | 72 | A, B, C = list(map(int, input().split()))
print((max(A, B, C) * 9 + A + B + C))
| A, B, C = list(map(int, input().split()))
maxa = max(A, B, C)
print((maxa * 9 + A + B + C))
| false | 40 | [
"-print((max(A, B, C) * 9 + A + B + C))",
"+maxa = max(A, B, C)",
"+print((maxa * 9 + A + B + C))"
] | false | 0.089445 | 0.073463 | 1.217561 | [
"s398967129",
"s063723750"
] |
u647766105 | p00111 | python | s535080739 | s997610401 | 30 | 20 | 4,348 | 4,348 | Accepted | Accepted | 33.33 | tableA,tableB = {},{}
def main():
make_table()
while True:
try:
s = "".join([tableA[c] for c in input()])
except:
break
tmp,ans = "",""
for c in s:
tmp += c
if tmp in tableB:
ans += tableB[tmp]
tmp = ""
print(ans)
def make_table():
global tableA,tableB
tableA={
"A":"00000",
"B":"00001",
"C":"00010",
"D":"00011",
"E":"00100",
"F":"00101",
"G":"00110",
"H":"00111",
"I":"01000",
"J":"01001",
"K":"01010",
"L":"01011",
"M":"01100",
"N":"01101",
"O":"01110",
"P":"01111",
"Q":"10000",
"R":"10001",
"S":"10010",
"T":"10011",
"U":"10100",
"V":"10101",
"W":"10110",
"X":"10111",
"Y":"11000",
"Z":"11001",
" ":"11010",
".":"11011",
",":"11100",
"-":"11101",
"'":"11110",
"?":"11111"}
tableB ={
"101":" ",
"000000":"'",
"000011":",",
"10010001":"-",
"010001":".",
"000001":"?",
"100101":"A",
"10011010":"B",
"0101":"C",
"0001":"D",
"110":"E",
"01001":"F",
"10011011":"G",
"010000":"H",
"0111":"I",
"10011000":"J",
"0110":"K",
"00100":"L",
"10011001":"M",
"10011110":"N",
"00101":"O",
"111":"P",
"10011111":"Q",
"1000":"R",
"00110":"S",
"00111":"T",
"10011100":"U",
"10011101":"V",
"000010":"W",
"10010010":"X",
"10010011":"Y",
"10010000":"Z"}
if __name__ == "__main__":
main() | def main():
tableA,tableB = make_table()
while True:
try:
s = "".join([tableA[c] for c in input()])
except:
break
tmp,ans = "",""
for c in s:
tmp += c
if tmp in tableB:
ans += tableB[tmp]
tmp = ""
print(ans)
def make_table():
tableA={
"A":"00000",
"B":"00001",
"C":"00010",
"D":"00011",
"E":"00100",
"F":"00101",
"G":"00110",
"H":"00111",
"I":"01000",
"J":"01001",
"K":"01010",
"L":"01011",
"M":"01100",
"N":"01101",
"O":"01110",
"P":"01111",
"Q":"10000",
"R":"10001",
"S":"10010",
"T":"10011",
"U":"10100",
"V":"10101",
"W":"10110",
"X":"10111",
"Y":"11000",
"Z":"11001",
" ":"11010",
".":"11011",
",":"11100",
"-":"11101",
"'":"11110",
"?":"11111"}
tableB ={
"101":" ",
"000000":"'",
"000011":",",
"10010001":"-",
"010001":".",
"000001":"?",
"100101":"A",
"10011010":"B",
"0101":"C",
"0001":"D",
"110":"E",
"01001":"F",
"10011011":"G",
"010000":"H",
"0111":"I",
"10011000":"J",
"0110":"K",
"00100":"L",
"10011001":"M",
"10011110":"N",
"00101":"O",
"111":"P",
"10011111":"Q",
"1000":"R",
"00110":"S",
"00111":"T",
"10011100":"U",
"10011101":"V",
"000010":"W",
"10010010":"X",
"10010011":"Y",
"10010000":"Z"}
return tableA,tableB
if __name__ == "__main__":
main() | 87 | 86 | 1,925 | 1,918 | tableA, tableB = {}, {}
def main():
make_table()
while True:
try:
s = "".join([tableA[c] for c in input()])
except:
break
tmp, ans = "", ""
for c in s:
tmp += c
if tmp in tableB:
ans += tableB[tmp]
tmp = ""
print(ans)
def make_table():
global tableA, tableB
tableA = {
"A": "00000",
"B": "00001",
"C": "00010",
"D": "00011",
"E": "00100",
"F": "00101",
"G": "00110",
"H": "00111",
"I": "01000",
"J": "01001",
"K": "01010",
"L": "01011",
"M": "01100",
"N": "01101",
"O": "01110",
"P": "01111",
"Q": "10000",
"R": "10001",
"S": "10010",
"T": "10011",
"U": "10100",
"V": "10101",
"W": "10110",
"X": "10111",
"Y": "11000",
"Z": "11001",
" ": "11010",
".": "11011",
",": "11100",
"-": "11101",
"'": "11110",
"?": "11111",
}
tableB = {
"101": " ",
"000000": "'",
"000011": ",",
"10010001": "-",
"010001": ".",
"000001": "?",
"100101": "A",
"10011010": "B",
"0101": "C",
"0001": "D",
"110": "E",
"01001": "F",
"10011011": "G",
"010000": "H",
"0111": "I",
"10011000": "J",
"0110": "K",
"00100": "L",
"10011001": "M",
"10011110": "N",
"00101": "O",
"111": "P",
"10011111": "Q",
"1000": "R",
"00110": "S",
"00111": "T",
"10011100": "U",
"10011101": "V",
"000010": "W",
"10010010": "X",
"10010011": "Y",
"10010000": "Z",
}
if __name__ == "__main__":
main()
| def main():
tableA, tableB = make_table()
while True:
try:
s = "".join([tableA[c] for c in input()])
except:
break
tmp, ans = "", ""
for c in s:
tmp += c
if tmp in tableB:
ans += tableB[tmp]
tmp = ""
print(ans)
def make_table():
tableA = {
"A": "00000",
"B": "00001",
"C": "00010",
"D": "00011",
"E": "00100",
"F": "00101",
"G": "00110",
"H": "00111",
"I": "01000",
"J": "01001",
"K": "01010",
"L": "01011",
"M": "01100",
"N": "01101",
"O": "01110",
"P": "01111",
"Q": "10000",
"R": "10001",
"S": "10010",
"T": "10011",
"U": "10100",
"V": "10101",
"W": "10110",
"X": "10111",
"Y": "11000",
"Z": "11001",
" ": "11010",
".": "11011",
",": "11100",
"-": "11101",
"'": "11110",
"?": "11111",
}
tableB = {
"101": " ",
"000000": "'",
"000011": ",",
"10010001": "-",
"010001": ".",
"000001": "?",
"100101": "A",
"10011010": "B",
"0101": "C",
"0001": "D",
"110": "E",
"01001": "F",
"10011011": "G",
"010000": "H",
"0111": "I",
"10011000": "J",
"0110": "K",
"00100": "L",
"10011001": "M",
"10011110": "N",
"00101": "O",
"111": "P",
"10011111": "Q",
"1000": "R",
"00110": "S",
"00111": "T",
"10011100": "U",
"10011101": "V",
"000010": "W",
"10010010": "X",
"10010011": "Y",
"10010000": "Z",
}
return tableA, tableB
if __name__ == "__main__":
main()
| false | 1.149425 | [
"-tableA, tableB = {}, {}",
"-",
"-",
"- make_table()",
"+ tableA, tableB = make_table()",
"- global tableA, tableB",
"+ return tableA, tableB"
] | false | 0.03957 | 0.039613 | 0.998904 | [
"s535080739",
"s997610401"
] |
u024612773 | p03848 | python | s123343052 | s340249041 | 1,875 | 217 | 54,540 | 52,588 | Accepted | Accepted | 88.43 | n=int(eval(input()))
a=list(map(int,input().split()))
def valid():
b = list(range((n+1)&1, n+1, 2))
for i in range(len(b)-1, -1, -1):
b.insert(i, b[i])
if b[0] == 0:
b = b[1:]
return list(sorted(a)) == b
ans,mod = 1,10**9+7
for i in range(n//2):
ans = (ans * 2) % mod
print((ans if valid() else 0)) | n=int(eval(input()))
a=list(sorted(map(int,input().split())))
def valid():
cur=(n+1)&1
for i in range(n):
if n&1==0 and i&1==0 and i>0:
cur+=2
if n&1==1 and i&1==1:
cur+=2
if a[i] != cur: return False
return True
print((2**(n//2)%(10**9+7) if valid() else 0)) | 13 | 12 | 332 | 322 | n = int(eval(input()))
a = list(map(int, input().split()))
def valid():
b = list(range((n + 1) & 1, n + 1, 2))
for i in range(len(b) - 1, -1, -1):
b.insert(i, b[i])
if b[0] == 0:
b = b[1:]
return list(sorted(a)) == b
ans, mod = 1, 10**9 + 7
for i in range(n // 2):
ans = (ans * 2) % mod
print((ans if valid() else 0))
| n = int(eval(input()))
a = list(sorted(map(int, input().split())))
def valid():
cur = (n + 1) & 1
for i in range(n):
if n & 1 == 0 and i & 1 == 0 and i > 0:
cur += 2
if n & 1 == 1 and i & 1 == 1:
cur += 2
if a[i] != cur:
return False
return True
print((2 ** (n // 2) % (10**9 + 7) if valid() else 0))
| false | 7.692308 | [
"-a = list(map(int, input().split()))",
"+a = list(sorted(map(int, input().split())))",
"- b = list(range((n + 1) & 1, n + 1, 2))",
"- for i in range(len(b) - 1, -1, -1):",
"- b.insert(i, b[i])",
"- if b[0] == 0:",
"- b = b[1:]",
"- return list(sorted(a)) == b",
"+ cur = (n + 1) & 1",
"+ for i in range(n):",
"+ if n & 1 == 0 and i & 1 == 0 and i > 0:",
"+ cur += 2",
"+ if n & 1 == 1 and i & 1 == 1:",
"+ cur += 2",
"+ if a[i] != cur:",
"+ return False",
"+ return True",
"-ans, mod = 1, 10**9 + 7",
"-for i in range(n // 2):",
"- ans = (ans * 2) % mod",
"-print((ans if valid() else 0))",
"+print((2 ** (n // 2) % (10**9 + 7) if valid() else 0))"
] | false | 0.039759 | 0.086353 | 0.460428 | [
"s123343052",
"s340249041"
] |
u537722973 | p02681 | python | s145417407 | s236567639 | 68 | 62 | 61,688 | 61,832 | Accepted | Accepted | 8.82 | s = eval(input())
t = eval(input())
print(((t == s+t[-1])*'Yes' + (t != s+t[-1])*'No')) | s = input()
t = input()
print('Yes') if t == s+t[-1] else print('No')
| 3 | 3 | 75 | 71 | s = eval(input())
t = eval(input())
print(((t == s + t[-1]) * "Yes" + (t != s + t[-1]) * "No"))
| s = input()
t = input()
print("Yes") if t == s + t[-1] else print("No")
| false | 0 | [
"-s = eval(input())",
"-t = eval(input())",
"-print(((t == s + t[-1]) * \"Yes\" + (t != s + t[-1]) * \"No\"))",
"+s = input()",
"+t = input()",
"+print(\"Yes\") if t == s + t[-1] else print(\"No\")"
] | false | 0.04234 | 0.04085 | 1.036467 | [
"s145417407",
"s236567639"
] |
u729133443 | p02955 | python | s274230418 | s912231883 | 264 | 162 | 42,716 | 3,064 | Accepted | Accepted | 38.64 | n,k,*a=list(map(int,open(0).read().split()))
s,m=sum(a),1
for i in sum([[s//i,i]for i in range(1,int(s**.5)+1)if s%i<1],[]):
p=[0]+sorted(j%i for j in a)
for j in range(n):p[j+1]+=p[j]
f=t=0
for j in range(n):
f|=t==p[~j]<=k
t+=i-p[~j]+p[-j-2]
m=max(m,i*f)
print(m) | n,k,*a=list(map(int,open(0).read().split()))
s=sum(a)
b=[]
for i in range(1,int(s**.5)+1):b+=[s//i,i]*(s%i<1)
m=1
for i in b:c=sorted(j%i for j in a);m=max(m,i*(sum(c[:-sum(c)//i])<=k))
print(m) | 11 | 7 | 287 | 194 | n, k, *a = list(map(int, open(0).read().split()))
s, m = sum(a), 1
for i in sum([[s // i, i] for i in range(1, int(s**0.5) + 1) if s % i < 1], []):
p = [0] + sorted(j % i for j in a)
for j in range(n):
p[j + 1] += p[j]
f = t = 0
for j in range(n):
f |= t == p[~j] <= k
t += i - p[~j] + p[-j - 2]
m = max(m, i * f)
print(m)
| n, k, *a = list(map(int, open(0).read().split()))
s = sum(a)
b = []
for i in range(1, int(s**0.5) + 1):
b += [s // i, i] * (s % i < 1)
m = 1
for i in b:
c = sorted(j % i for j in a)
m = max(m, i * (sum(c[: -sum(c) // i]) <= k))
print(m)
| false | 36.363636 | [
"-s, m = sum(a), 1",
"-for i in sum([[s // i, i] for i in range(1, int(s**0.5) + 1) if s % i < 1], []):",
"- p = [0] + sorted(j % i for j in a)",
"- for j in range(n):",
"- p[j + 1] += p[j]",
"- f = t = 0",
"- for j in range(n):",
"- f |= t == p[~j] <= k",
"- t += i - p[~j] + p[-j - 2]",
"- m = max(m, i * f)",
"+s = sum(a)",
"+b = []",
"+for i in range(1, int(s**0.5) + 1):",
"+ b += [s // i, i] * (s % i < 1)",
"+m = 1",
"+for i in b:",
"+ c = sorted(j % i for j in a)",
"+ m = max(m, i * (sum(c[: -sum(c) // i]) <= k))"
] | false | 0.095394 | 0.046111 | 2.06878 | [
"s274230418",
"s912231883"
] |
u909643606 | p03837 | python | s497343196 | s350140900 | 355 | 297 | 25,508 | 15,896 | Accepted | Accepted | 16.34 | #import sys
#import numpy as np
from scipy.sparse import csr_matrix, coo_matrix
from scipy.sparse.csgraph import dijkstra
#sys.setrecursionlimit(10000)
N, M = [int(i) for i in input().split()]
rows = []
cols = []
weights = []
for _ in range(M):
# u v 間のコスト
u, v, a = [int(i) for i in input().split()]
rows.append(u-1)
cols.append(v-1)
weights.append(a)
graph = coo_matrix((weights, (rows, cols)), shape=(N, N)).tocsr()
d1, pre = dijkstra(graph, directed=False, unweighted=False, return_predecessors =True)
#print(d1)
#print(pre)
path = []
for i in range(N):
for j in range(N):
if pre[i][j] != -9999:
if j < pre[i][j]:
path.append([j,pre[i][j]])
else:
path.append([pre[i][j], j])
path = list(map(list, set(map(tuple, path))))
print((M-len(path))) | #import sys
#import numpy as np
from scipy.sparse import csr_matrix, coo_matrix
from scipy.sparse.csgraph import dijkstra
#sys.setrecursionlimit(10000)
N, M = [int(i) for i in input().split()]
rows = []
cols = []
weights = []
for _ in range(M):
# u v 間のコスト
u, v, a = [int(i) for i in input().split()]
rows.append(u-1)
cols.append(v-1)
weights.append(a)
graph = coo_matrix((weights, (rows, cols)), shape=(N, N)).tocsr()
d1, pre = dijkstra(graph, directed=False, unweighted=False, return_predecessors =True)
#print(d1)
#print(pre)
path = [[0] * N for j in range(N)]
for i in range(N):
for j in range(N):
if pre[i][j] != -9999:
if j < pre[i][j]:
path[j][pre[i][j]] = 1
else:
path[pre[i][j]][j] = 1
print((M-sum(map(sum, path))))
| 35 | 36 | 871 | 855 | # import sys
# import numpy as np
from scipy.sparse import csr_matrix, coo_matrix
from scipy.sparse.csgraph import dijkstra
# sys.setrecursionlimit(10000)
N, M = [int(i) for i in input().split()]
rows = []
cols = []
weights = []
for _ in range(M):
# u v 間のコスト
u, v, a = [int(i) for i in input().split()]
rows.append(u - 1)
cols.append(v - 1)
weights.append(a)
graph = coo_matrix((weights, (rows, cols)), shape=(N, N)).tocsr()
d1, pre = dijkstra(graph, directed=False, unweighted=False, return_predecessors=True)
# print(d1)
# print(pre)
path = []
for i in range(N):
for j in range(N):
if pre[i][j] != -9999:
if j < pre[i][j]:
path.append([j, pre[i][j]])
else:
path.append([pre[i][j], j])
path = list(map(list, set(map(tuple, path))))
print((M - len(path)))
| # import sys
# import numpy as np
from scipy.sparse import csr_matrix, coo_matrix
from scipy.sparse.csgraph import dijkstra
# sys.setrecursionlimit(10000)
N, M = [int(i) for i in input().split()]
rows = []
cols = []
weights = []
for _ in range(M):
# u v 間のコスト
u, v, a = [int(i) for i in input().split()]
rows.append(u - 1)
cols.append(v - 1)
weights.append(a)
graph = coo_matrix((weights, (rows, cols)), shape=(N, N)).tocsr()
d1, pre = dijkstra(graph, directed=False, unweighted=False, return_predecessors=True)
# print(d1)
# print(pre)
path = [[0] * N for j in range(N)]
for i in range(N):
for j in range(N):
if pre[i][j] != -9999:
if j < pre[i][j]:
path[j][pre[i][j]] = 1
else:
path[pre[i][j]][j] = 1
print((M - sum(map(sum, path))))
| false | 2.777778 | [
"-path = []",
"+path = [[0] * N for j in range(N)]",
"- path.append([j, pre[i][j]])",
"+ path[j][pre[i][j]] = 1",
"- path.append([pre[i][j], j])",
"-path = list(map(list, set(map(tuple, path))))",
"-print((M - len(path)))",
"+ path[pre[i][j]][j] = 1",
"+print((M - sum(map(sum, path))))"
] | false | 0.249497 | 0.256234 | 0.973708 | [
"s497343196",
"s350140900"
] |
u440566786 | p02890 | python | s156802001 | s405415353 | 551 | 477 | 120,732 | 105,512 | Accepted | Accepted | 13.43 | import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
from collections import Counter
n=int(eval(input()))
A=list(Counter(list(map(int,input().split()))).values())
A.sort()
m=len(A)
S=[0]*(m+1) # cumulative distribution
for i in range(m): S[i+1]=S[i]+A[i]
# output
p=n
i=m
from bisect import bisect_left
for k in range(1,n+1):
while(1):
# pに対して先にi_pを求めておく
while(1):
if(i<=0 or A[i-1]<p): break
i-=1
if(S[i]+p*(m-i)>=k*p): break # p<0 or を書く必要はない
p-=1 # pの条件が真になるまで減らし続ける
print(p)
resolve() | import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def bin_sort(A,n_min=None,n_max=None):
if(n_min is None): n_min=min(A)
if(n_max is None): n_max=max(A)
bin=[0]*(n_max-n_min+1)
for a in A: bin[a-n_min]+=1
B=[]
for i in range(n_min,n_max+1): B+=[i]*bin[i-n_min]
return B
def resolve():
n=int(eval(input()))
A=[0]*n
for a in map(int,input().split()): A[a-1]+=1
A=bin_sort(A,0,n)
S=[0]*(n+1)
for i in range(n): S[i+1]=S[i]+A[i]
# output
p=n; i=n
for k in range(1,n+1):
while(1):
while(1):
if(i<=0 or A[i-1]<p): break
i-=1
if(S[i]+p*(n-i)>=k*p): break
p-=1
print(p)
resolve() | 27 | 32 | 726 | 813 | import sys
sys.setrecursionlimit(2147483647)
INF = float("inf")
MOD = 10**9 + 7
input = lambda: sys.stdin.readline().rstrip()
def resolve():
from collections import Counter
n = int(eval(input()))
A = list(Counter(list(map(int, input().split()))).values())
A.sort()
m = len(A)
S = [0] * (m + 1) # cumulative distribution
for i in range(m):
S[i + 1] = S[i] + A[i]
# output
p = n
i = m
from bisect import bisect_left
for k in range(1, n + 1):
while 1:
# pに対して先にi_pを求めておく
while 1:
if i <= 0 or A[i - 1] < p:
break
i -= 1
if S[i] + p * (m - i) >= k * p:
break # p<0 or を書く必要はない
p -= 1 # pの条件が真になるまで減らし続ける
print(p)
resolve()
| import sys
sys.setrecursionlimit(2147483647)
INF = float("inf")
MOD = 10**9 + 7
input = lambda: sys.stdin.readline().rstrip()
def bin_sort(A, n_min=None, n_max=None):
if n_min is None:
n_min = min(A)
if n_max is None:
n_max = max(A)
bin = [0] * (n_max - n_min + 1)
for a in A:
bin[a - n_min] += 1
B = []
for i in range(n_min, n_max + 1):
B += [i] * bin[i - n_min]
return B
def resolve():
n = int(eval(input()))
A = [0] * n
for a in map(int, input().split()):
A[a - 1] += 1
A = bin_sort(A, 0, n)
S = [0] * (n + 1)
for i in range(n):
S[i + 1] = S[i] + A[i]
# output
p = n
i = n
for k in range(1, n + 1):
while 1:
while 1:
if i <= 0 or A[i - 1] < p:
break
i -= 1
if S[i] + p * (n - i) >= k * p:
break
p -= 1
print(p)
resolve()
| false | 15.625 | [
"+def bin_sort(A, n_min=None, n_max=None):",
"+ if n_min is None:",
"+ n_min = min(A)",
"+ if n_max is None:",
"+ n_max = max(A)",
"+ bin = [0] * (n_max - n_min + 1)",
"+ for a in A:",
"+ bin[a - n_min] += 1",
"+ B = []",
"+ for i in range(n_min, n_max + 1):",
"+ B += [i] * bin[i - n_min]",
"+ return B",
"+",
"+",
"- from collections import Counter",
"-",
"- A = list(Counter(list(map(int, input().split()))).values())",
"- A.sort()",
"- m = len(A)",
"- S = [0] * (m + 1) # cumulative distribution",
"- for i in range(m):",
"+ A = [0] * n",
"+ for a in map(int, input().split()):",
"+ A[a - 1] += 1",
"+ A = bin_sort(A, 0, n)",
"+ S = [0] * (n + 1)",
"+ for i in range(n):",
"- i = m",
"- from bisect import bisect_left",
"-",
"+ i = n",
"- # pに対して先にi_pを求めておく",
"- if S[i] + p * (m - i) >= k * p:",
"- break # p<0 or を書く必要はない",
"- p -= 1 # pの条件が真になるまで減らし続ける",
"+ if S[i] + p * (n - i) >= k * p:",
"+ break",
"+ p -= 1"
] | false | 0.040284 | 0.06576 | 0.612585 | [
"s156802001",
"s405415353"
] |
u474423089 | p03846 | python | s093721012 | s702148472 | 64 | 59 | 14,812 | 14,820 | Accepted | Accepted | 7.81 | from collections import Counter
def main():
mod = 10**9+7
n = int(eval(input()))
a = list(map(int,input().split(' ')))
c = Counter(a)
ans = 1
if n%2 != 0:
for key,i in list(c.items()):
if key%2 != 0 or (key==0 and i != 1) or (key != 0 and i != 2):
ans = 0
break
elif i ==2:
ans *=2
ans %= mod
else:
for key,i in list(c.items()):
if key%2 ==0 or i !=2:
ans = 0
break
elif i ==2:
ans *=2
ans %= mod
print(ans)
if __name__ == '__main__':
main() | from collections import Counter
def main():
mod = 10**9+7
n = int(eval(input()))
a = list(map(int,input().split(' ')))
c = Counter(a)
ans = (2**(n//2))%mod
if n%2 != 0:
for key,i in list(c.items()):
if key%2 != 0 or (key==0 and i != 1) or (key != 0 and i != 2):
ans = 0
break
else:
for key,i in list(c.items()):
if key%2 ==0 or i !=2:
ans = 0
break
print(ans)
if __name__ == '__main__':
main() | 26 | 21 | 676 | 536 | from collections import Counter
def main():
mod = 10**9 + 7
n = int(eval(input()))
a = list(map(int, input().split(" ")))
c = Counter(a)
ans = 1
if n % 2 != 0:
for key, i in list(c.items()):
if key % 2 != 0 or (key == 0 and i != 1) or (key != 0 and i != 2):
ans = 0
break
elif i == 2:
ans *= 2
ans %= mod
else:
for key, i in list(c.items()):
if key % 2 == 0 or i != 2:
ans = 0
break
elif i == 2:
ans *= 2
ans %= mod
print(ans)
if __name__ == "__main__":
main()
| from collections import Counter
def main():
mod = 10**9 + 7
n = int(eval(input()))
a = list(map(int, input().split(" ")))
c = Counter(a)
ans = (2 ** (n // 2)) % mod
if n % 2 != 0:
for key, i in list(c.items()):
if key % 2 != 0 or (key == 0 and i != 1) or (key != 0 and i != 2):
ans = 0
break
else:
for key, i in list(c.items()):
if key % 2 == 0 or i != 2:
ans = 0
break
print(ans)
if __name__ == "__main__":
main()
| false | 19.230769 | [
"- ans = 1",
"+ ans = (2 ** (n // 2)) % mod",
"- elif i == 2:",
"- ans *= 2",
"- ans %= mod",
"- elif i == 2:",
"- ans *= 2",
"- ans %= mod"
] | false | 0.03866 | 0.039832 | 0.97057 | [
"s093721012",
"s702148472"
] |
u030726788 | p02934 | python | s320144859 | s727430503 | 147 | 27 | 12,420 | 9,152 | Accepted | Accepted | 81.63 | import numpy as np
n = int(eval(input()))
a = np.array(list(map(int,input().split())))
print((1.0/sum(1.0/a))) | n = int(eval(input()))
a = list(map(int,input().split()))
v = 0.0
for i in a:
v += 1.0 / i
print((1.0 / v)) | 4 | 6 | 105 | 108 | import numpy as np
n = int(eval(input()))
a = np.array(list(map(int, input().split())))
print((1.0 / sum(1.0 / a)))
| n = int(eval(input()))
a = list(map(int, input().split()))
v = 0.0
for i in a:
v += 1.0 / i
print((1.0 / v))
| false | 33.333333 | [
"-import numpy as np",
"-",
"-a = np.array(list(map(int, input().split())))",
"-print((1.0 / sum(1.0 / a)))",
"+a = list(map(int, input().split()))",
"+v = 0.0",
"+for i in a:",
"+ v += 1.0 / i",
"+print((1.0 / v))"
] | false | 1.3733 | 0.102547 | 13.391939 | [
"s320144859",
"s727430503"
] |
u319245933 | p02663 | python | s004328963 | s229898898 | 60 | 33 | 61,668 | 9,076 | Accepted | Accepted | 45 | import sys
H1,M1,H2,M2,K = list(map(int, sys.stdin.readline().split()))
print(((H2 - H1) * 60 + M2 - M1 - K))
| H1, M1, H2, M2, K = list(map(int, input().split()))
print(((H2*60 + M2 - K) - (H1*60 + M1))) | 5 | 2 | 108 | 85 | import sys
H1, M1, H2, M2, K = list(map(int, sys.stdin.readline().split()))
print(((H2 - H1) * 60 + M2 - M1 - K))
| H1, M1, H2, M2, K = list(map(int, input().split()))
print(((H2 * 60 + M2 - K) - (H1 * 60 + M1)))
| false | 60 | [
"-import sys",
"-",
"-H1, M1, H2, M2, K = list(map(int, sys.stdin.readline().split()))",
"-print(((H2 - H1) * 60 + M2 - M1 - K))",
"+H1, M1, H2, M2, K = list(map(int, input().split()))",
"+print(((H2 * 60 + M2 - K) - (H1 * 60 + M1)))"
] | false | 0.036143 | 0.102732 | 0.351818 | [
"s004328963",
"s229898898"
] |
u628335443 | p02773 | python | s694643398 | s675901830 | 611 | 536 | 35,572 | 35,984 | Accepted | Accepted | 12.27 | from collections import Counter
n = int(eval(input()))
s = []
for i in range(n):
s.append(eval(input()))
cnt = Counter(s)
max_count = max(cnt.values())
ans = [k for k, count in list(cnt.items()) if count == max_count]
for a in sorted(ans):
print(a)
| from collections import Counter
n = int(eval(input()))
s = []
for i in range(n):
s.append(eval(input()))
cnt = Counter(s)
max_count = max(cnt.values())
ans = [k for k, count in list(cnt.items()) if count == max_count]
print(("\n".join(sorted(ans))))
| 13 | 12 | 254 | 248 | from collections import Counter
n = int(eval(input()))
s = []
for i in range(n):
s.append(eval(input()))
cnt = Counter(s)
max_count = max(cnt.values())
ans = [k for k, count in list(cnt.items()) if count == max_count]
for a in sorted(ans):
print(a)
| from collections import Counter
n = int(eval(input()))
s = []
for i in range(n):
s.append(eval(input()))
cnt = Counter(s)
max_count = max(cnt.values())
ans = [k for k, count in list(cnt.items()) if count == max_count]
print(("\n".join(sorted(ans))))
| false | 7.692308 | [
"-for a in sorted(ans):",
"- print(a)",
"+print((\"\\n\".join(sorted(ans))))"
] | false | 0.078317 | 0.040411 | 1.937992 | [
"s694643398",
"s675901830"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.