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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
u761320129 | p03221 | python | s974341092 | s891098688 | 738 | 682 | 47,844 | 47,772 | Accepted | Accepted | 7.59 | N,M = map(int,input().split())
src = [tuple(map(int,input().split())) for i in range(M)]
cs = [[] for i in range(N+1)]
for i,(p,y) in enumerate(src):
cs[p].append((y,i))
ans = [None]*M
for pi,cities in enumerate(cs):
for order,(y,i) in enumerate(sorted(cities)):
ans[i] = str(pi).zfill(6) + str(order+1).zfill(6)
print(*ans, sep='\n')
| N,M = map(int,input().split())
src = [tuple(map(int,input().split())) for i in range(M)]
cs = [[] for i in range(N+1)]
for i,(p,y) in enumerate(src):
cs[p].append((y,i))
for cc in cs:
cc.sort()
ans = [None] * M
for p in range(len(cs)):
for i,(_,j) in enumerate(cs[p]):
s = str(p).zfill(6) + str(i+1).zfill(6)
ans[j] = s
print(*ans, sep='\n')
| 12 | 15 | 363 | 385 | N, M = map(int, input().split())
src = [tuple(map(int, input().split())) for i in range(M)]
cs = [[] for i in range(N + 1)]
for i, (p, y) in enumerate(src):
cs[p].append((y, i))
ans = [None] * M
for pi, cities in enumerate(cs):
for order, (y, i) in enumerate(sorted(cities)):
ans[i] = str(pi).zfill(6) + str(order + 1).zfill(6)
print(*ans, sep="\n")
| N, M = map(int, input().split())
src = [tuple(map(int, input().split())) for i in range(M)]
cs = [[] for i in range(N + 1)]
for i, (p, y) in enumerate(src):
cs[p].append((y, i))
for cc in cs:
cc.sort()
ans = [None] * M
for p in range(len(cs)):
for i, (_, j) in enumerate(cs[p]):
s = str(p).zfill(6) + str(i + 1).zfill(6)
ans[j] = s
print(*ans, sep="\n")
| false | 20 | [
"+for cc in cs:",
"+ cc.sort()",
"-for pi, cities in enumerate(cs):",
"- for order, (y, i) in enumerate(sorted(cities)):",
"- ans[i] = str(pi).zfill(6) + str(order + 1).zfill(6)",
"+for p in range(len(cs)):",
"+ for i, (_, j) in enumerate(cs[p]):",
"+ s = str(p).zfill(6) + str(i + 1).zfill(6)",
"+ ans[j] = s"
] | false | 0.038329 | 0.074087 | 0.517358 | [
"s974341092",
"s891098688"
] |
u994988729 | p03363 | python | s381624446 | s828708095 | 209 | 166 | 41,664 | 41,620 | Accepted | Accepted | 20.57 | from collections import Counter
n = int(eval(input()))
a = list(map(int, input().split()))
cum = [0] * (n + 1)
for i in range(n):
cum[i + 1] = cum[i] + a[i]
c = Counter(cum)
ans = 0
for v in list(c.values()):
ans += v * (v - 1) // 2
print(ans) | from itertools import accumulate
from collections import Counter
N = int(eval(input()))
A = [0]+list(map(int, input().split()))
Acum = list(accumulate(A))
C = Counter(Acum)
ans = 0
for _, v in list(C.items()):
ans += (v - 1) * v // 2
print(ans)
| 13 | 12 | 253 | 250 | from collections import Counter
n = int(eval(input()))
a = list(map(int, input().split()))
cum = [0] * (n + 1)
for i in range(n):
cum[i + 1] = cum[i] + a[i]
c = Counter(cum)
ans = 0
for v in list(c.values()):
ans += v * (v - 1) // 2
print(ans)
| from itertools import accumulate
from collections import Counter
N = int(eval(input()))
A = [0] + list(map(int, input().split()))
Acum = list(accumulate(A))
C = Counter(Acum)
ans = 0
for _, v in list(C.items()):
ans += (v - 1) * v // 2
print(ans)
| false | 7.692308 | [
"+from itertools import accumulate",
"-n = int(eval(input()))",
"-a = list(map(int, input().split()))",
"-cum = [0] * (n + 1)",
"-for i in range(n):",
"- cum[i + 1] = cum[i] + a[i]",
"-c = Counter(cum)",
"+N = int(eval(input()))",
"+A = [0] + list(map(int, input().split()))",
"+Acum = list(accumulate(A))",
"+C = Counter(Acum)",
"-for v in list(c.values()):",
"- ans += v * (v - 1) // 2",
"+for _, v in list(C.items()):",
"+ ans += (v - 1) * v // 2"
] | false | 0.042538 | 0.099438 | 0.427785 | [
"s381624446",
"s828708095"
] |
u102278909 | p03032 | python | s577498183 | s393595776 | 624 | 219 | 49,372 | 43,356 | Accepted | Accepted | 64.9 | # coding: utf-8
import sys
input = sys.stdin.readline
# N = int(input())
N, K = list(map(int, input().split()))
D = [int(x) for x in input().split()]
# S = input()
ans = 0
for l in range(N + 1):
if l > K:
break
for r in range(N - l + 1):
if l + r > K:
break
l_list = sorted(D[0 : l])
r_list = sorted(D[N - r : N])
for discard_l in range(K - (l + r) + 1):
for discard_r in range(K - (l + r + discard_l) + 1):
value = sum(l_list[discard_l:])
value += sum(r_list[discard_r:])
ans = max(ans, value)
print(ans)
| # coding: utf-8
import sys
input = sys.stdin.readline
# N = int(input())
N, K = list(map(int, input().split()))
D = [int(x) for x in input().split()]
# S = input()
ans = 0
for l in range(N + 1):
if l > K:
break
for r in range(N - l + 1):
if l + r > K:
break
value_list = D[0 : l] + D[N - r : N]
value_list.sort()
for i in range(K - (l + r) + 1):
ans = max(ans, sum(value_list[i:]))
print(ans)
| 30 | 26 | 665 | 507 | # coding: utf-8
import sys
input = sys.stdin.readline
# N = int(input())
N, K = list(map(int, input().split()))
D = [int(x) for x in input().split()]
# S = input()
ans = 0
for l in range(N + 1):
if l > K:
break
for r in range(N - l + 1):
if l + r > K:
break
l_list = sorted(D[0:l])
r_list = sorted(D[N - r : N])
for discard_l in range(K - (l + r) + 1):
for discard_r in range(K - (l + r + discard_l) + 1):
value = sum(l_list[discard_l:])
value += sum(r_list[discard_r:])
ans = max(ans, value)
print(ans)
| # coding: utf-8
import sys
input = sys.stdin.readline
# N = int(input())
N, K = list(map(int, input().split()))
D = [int(x) for x in input().split()]
# S = input()
ans = 0
for l in range(N + 1):
if l > K:
break
for r in range(N - l + 1):
if l + r > K:
break
value_list = D[0:l] + D[N - r : N]
value_list.sort()
for i in range(K - (l + r) + 1):
ans = max(ans, sum(value_list[i:]))
print(ans)
| false | 13.333333 | [
"- l_list = sorted(D[0:l])",
"- r_list = sorted(D[N - r : N])",
"- for discard_l in range(K - (l + r) + 1):",
"- for discard_r in range(K - (l + r + discard_l) + 1):",
"- value = sum(l_list[discard_l:])",
"- value += sum(r_list[discard_r:])",
"- ans = max(ans, value)",
"+ value_list = D[0:l] + D[N - r : N]",
"+ value_list.sort()",
"+ for i in range(K - (l + r) + 1):",
"+ ans = max(ans, sum(value_list[i:]))"
] | false | 0.04482 | 0.091157 | 0.491682 | [
"s577498183",
"s393595776"
] |
u968166680 | p02845 | python | s503012770 | s351837088 | 226 | 66 | 60,068 | 14,068 | Accepted | Accepted | 70.8 | import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
def main():
MOD = 1000000007
N, *A = list(map(int, read().split()))
seq = [-1] * 3
ans = 1
try:
for a in A:
ans = ans * seq.count(a - 1) % MOD
seq[seq.index(a - 1)] = a
print(ans)
except:
print((0))
return
if __name__ == '__main__':
main()
| import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
def main():
MOD = 1000000007
N, *A = list(map(int, read().split()))
C = [0] * (N + 1)
C[0] = 3
ans = 1
for a in A:
ans = ans * C[a] % MOD
if ans == 0:
print((0))
return
C[a] -= 1
C[a + 1] += 1
print(ans)
return
if __name__ == '__main__':
main()
| 27 | 30 | 492 | 505 | import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60
def main():
MOD = 1000000007
N, *A = list(map(int, read().split()))
seq = [-1] * 3
ans = 1
try:
for a in A:
ans = ans * seq.count(a - 1) % MOD
seq[seq.index(a - 1)] = a
print(ans)
except:
print((0))
return
if __name__ == "__main__":
main()
| import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60
def main():
MOD = 1000000007
N, *A = list(map(int, read().split()))
C = [0] * (N + 1)
C[0] = 3
ans = 1
for a in A:
ans = ans * C[a] % MOD
if ans == 0:
print((0))
return
C[a] -= 1
C[a + 1] += 1
print(ans)
return
if __name__ == "__main__":
main()
| false | 10 | [
"- seq = [-1] * 3",
"+ C = [0] * (N + 1)",
"+ C[0] = 3",
"- try:",
"- for a in A:",
"- ans = ans * seq.count(a - 1) % MOD",
"- seq[seq.index(a - 1)] = a",
"- print(ans)",
"- except:",
"- print((0))",
"+ for a in A:",
"+ ans = ans * C[a] % MOD",
"+ if ans == 0:",
"+ print((0))",
"+ return",
"+ C[a] -= 1",
"+ C[a + 1] += 1",
"+ print(ans)"
] | false | 0.045441 | 0.082533 | 0.550583 | [
"s503012770",
"s351837088"
] |
u250583425 | p03476 | python | s394062063 | s196135418 | 397 | 266 | 6,896 | 6,360 | Accepted | Accepted | 33 | import sys
import math
def input(): return sys.stdin.readline().rstrip()
def isPrime(n):
m = (n + 1) // 2
n_sqrt = int(math.sqrt(n))
for i in range(2, n_sqrt + 1):
if n % i == 0 or m % i == 0:
return 0
else:
return 1
def main():
Q = int(eval(input()))
MAX = 10 ** 5
prime = [0] * MAX
for i in range(3, MAX):
prime[i] = prime[i-1] + isPrime(i)
for _ in range(Q):
l, r = list(map(int, input().split()))
print((prime[r] - prime[l-1]))
if __name__ == '__main__':
main() | import sys
def input(): return sys.stdin.readline().rstrip()
def main():
MAX = 10 ** 5
Q = int(eval(input()))
ans = [0] * (MAX + 1)
sum = 0
prime = set()
memo = [False] * 2 + [True] * (MAX - 1)
for i in range(2, MAX + 1):
if memo[i]:
prime.add(i)
for j in range(i * 2, MAX + 1, i):
memo[j] = False
if (i + 1) // 2 in prime:
sum += 1
ans[i] = sum
for _ in range(Q):
l, r = list(map(int, input().split()))
print((ans[r] - ans[l-1]))
if __name__ == '__main__':
main()
| 26 | 26 | 572 | 620 | import sys
import math
def input():
return sys.stdin.readline().rstrip()
def isPrime(n):
m = (n + 1) // 2
n_sqrt = int(math.sqrt(n))
for i in range(2, n_sqrt + 1):
if n % i == 0 or m % i == 0:
return 0
else:
return 1
def main():
Q = int(eval(input()))
MAX = 10**5
prime = [0] * MAX
for i in range(3, MAX):
prime[i] = prime[i - 1] + isPrime(i)
for _ in range(Q):
l, r = list(map(int, input().split()))
print((prime[r] - prime[l - 1]))
if __name__ == "__main__":
main()
| import sys
def input():
return sys.stdin.readline().rstrip()
def main():
MAX = 10**5
Q = int(eval(input()))
ans = [0] * (MAX + 1)
sum = 0
prime = set()
memo = [False] * 2 + [True] * (MAX - 1)
for i in range(2, MAX + 1):
if memo[i]:
prime.add(i)
for j in range(i * 2, MAX + 1, i):
memo[j] = False
if (i + 1) // 2 in prime:
sum += 1
ans[i] = sum
for _ in range(Q):
l, r = list(map(int, input().split()))
print((ans[r] - ans[l - 1]))
if __name__ == "__main__":
main()
| false | 0 | [
"-import math",
"-def isPrime(n):",
"- m = (n + 1) // 2",
"- n_sqrt = int(math.sqrt(n))",
"- for i in range(2, n_sqrt + 1):",
"- if n % i == 0 or m % i == 0:",
"- return 0",
"- else:",
"- return 1",
"-",
"-",
"+ MAX = 10**5",
"- MAX = 10**5",
"- prime = [0] * MAX",
"- for i in range(3, MAX):",
"- prime[i] = prime[i - 1] + isPrime(i)",
"+ ans = [0] * (MAX + 1)",
"+ sum = 0",
"+ prime = set()",
"+ memo = [False] * 2 + [True] * (MAX - 1)",
"+ for i in range(2, MAX + 1):",
"+ if memo[i]:",
"+ prime.add(i)",
"+ for j in range(i * 2, MAX + 1, i):",
"+ memo[j] = False",
"+ if (i + 1) // 2 in prime:",
"+ sum += 1",
"+ ans[i] = sum",
"- print((prime[r] - prime[l - 1]))",
"+ print((ans[r] - ans[l - 1]))"
] | false | 0.270606 | 0.178342 | 1.517343 | [
"s394062063",
"s196135418"
] |
u764215612 | p02702 | python | s213408394 | s581382216 | 296 | 84 | 9,368 | 9,300 | Accepted | Accepted | 71.62 | def main():
n, mods = 0, [1]+[0]*2019
for i, j in enumerate(reversed(eval(input()))):
n = (n+int(j)*pow(10, i, 2019))%2019
mods[n] += 1
print((sum([i*(i-1)//2 for i in mods])))
main() | def main():
n, mods = 0, [1]+[0]*2019
d = 1
for i, j in enumerate(reversed(eval(input()))):
# n = (n+int(j)*pow(10, i, 2019))%2019
n = (n+int(j)*d)%2019
d=d*10%2019
mods[n] += 1
print((sum([i*(i-1)//2 for i in mods])))
main() | 7 | 10 | 195 | 250 | def main():
n, mods = 0, [1] + [0] * 2019
for i, j in enumerate(reversed(eval(input()))):
n = (n + int(j) * pow(10, i, 2019)) % 2019
mods[n] += 1
print((sum([i * (i - 1) // 2 for i in mods])))
main()
| def main():
n, mods = 0, [1] + [0] * 2019
d = 1
for i, j in enumerate(reversed(eval(input()))):
# n = (n+int(j)*pow(10, i, 2019))%2019
n = (n + int(j) * d) % 2019
d = d * 10 % 2019
mods[n] += 1
print((sum([i * (i - 1) // 2 for i in mods])))
main()
| false | 30 | [
"+ d = 1",
"- n = (n + int(j) * pow(10, i, 2019)) % 2019",
"+ # n = (n+int(j)*pow(10, i, 2019))%2019",
"+ n = (n + int(j) * d) % 2019",
"+ d = d * 10 % 2019"
] | false | 0.046116 | 0.036211 | 1.273548 | [
"s213408394",
"s581382216"
] |
u945181840 | p03488 | python | s719530752 | s596894865 | 952 | 798 | 3,820 | 3,888 | Accepted | Accepted | 16.18 | s = input().split('T')
x, y = list(map(int, input().split()))
# x軸方向の移動について
# 1回目の移動はxの正方向のみ
here_x = [len(s[0])]
for i in s[2::2]:
move = len(i)
here_x = [i + move for i in here_x] + [i - move for i in here_x]
here_x = list(set(here_x))
# x軸方向の移動について
# 1回目の移動はxの正方向のみ
here_y = [0]
for i in s[1::2]:
move = len(i)
here_y = [i + move for i in here_y] + [i - move for i in here_y]
here_y = list(set(here_y))
if x in here_x and y in here_y:
print('Yes')
else:
print('No') | def main():
s = input().split('T')
x, y = list(map(int, input().split()))
# x軸方向の移動について
# 1回目の移動はxの正方向のみ
here_x = [len(s[0])]
for i in s[2::2]:
move = len(i)
here_x = [i + move for i in here_x] + [i - move for i in here_x]
here_x = set(here_x)
# y軸方向の移動について
here_y = [0]
for i in s[1::2]:
move = len(i)
here_y = [i + move for i in here_y] + [i - move for i in here_y]
here_y = set(here_y)
if x in here_x and y in here_y:
print('Yes')
else:
print('No')
if __name__ == '__main__':
main() | 25 | 29 | 523 | 626 | s = input().split("T")
x, y = list(map(int, input().split()))
# x軸方向の移動について
# 1回目の移動はxの正方向のみ
here_x = [len(s[0])]
for i in s[2::2]:
move = len(i)
here_x = [i + move for i in here_x] + [i - move for i in here_x]
here_x = list(set(here_x))
# x軸方向の移動について
# 1回目の移動はxの正方向のみ
here_y = [0]
for i in s[1::2]:
move = len(i)
here_y = [i + move for i in here_y] + [i - move for i in here_y]
here_y = list(set(here_y))
if x in here_x and y in here_y:
print("Yes")
else:
print("No")
| def main():
s = input().split("T")
x, y = list(map(int, input().split()))
# x軸方向の移動について
# 1回目の移動はxの正方向のみ
here_x = [len(s[0])]
for i in s[2::2]:
move = len(i)
here_x = [i + move for i in here_x] + [i - move for i in here_x]
here_x = set(here_x)
# y軸方向の移動について
here_y = [0]
for i in s[1::2]:
move = len(i)
here_y = [i + move for i in here_y] + [i - move for i in here_y]
here_y = set(here_y)
if x in here_x and y in here_y:
print("Yes")
else:
print("No")
if __name__ == "__main__":
main()
| false | 13.793103 | [
"-s = input().split(\"T\")",
"-x, y = list(map(int, input().split()))",
"-# x軸方向の移動について",
"-# 1回目の移動はxの正方向のみ",
"-here_x = [len(s[0])]",
"-for i in s[2::2]:",
"- move = len(i)",
"- here_x = [i + move for i in here_x] + [i - move for i in here_x]",
"- here_x = list(set(here_x))",
"-# x軸方向の移動について",
"-# 1回目の移動はxの正方向のみ",
"-here_y = [0]",
"-for i in s[1::2]:",
"- move = len(i)",
"- here_y = [i + move for i in here_y] + [i - move for i in here_y]",
"- here_y = list(set(here_y))",
"-if x in here_x and y in here_y:",
"- print(\"Yes\")",
"-else:",
"- print(\"No\")",
"+def main():",
"+ s = input().split(\"T\")",
"+ x, y = list(map(int, input().split()))",
"+ # x軸方向の移動について",
"+ # 1回目の移動はxの正方向のみ",
"+ here_x = [len(s[0])]",
"+ for i in s[2::2]:",
"+ move = len(i)",
"+ here_x = [i + move for i in here_x] + [i - move for i in here_x]",
"+ here_x = set(here_x)",
"+ # y軸方向の移動について",
"+ here_y = [0]",
"+ for i in s[1::2]:",
"+ move = len(i)",
"+ here_y = [i + move for i in here_y] + [i - move for i in here_y]",
"+ here_y = set(here_y)",
"+ if x in here_x and y in here_y:",
"+ print(\"Yes\")",
"+ else:",
"+ print(\"No\")",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.038201 | 0.041334 | 0.924199 | [
"s719530752",
"s596894865"
] |
u948524308 | p03162 | python | s148992399 | s457436351 | 977 | 475 | 3,064 | 3,064 | Accepted | Accepted | 51.38 | N=int(eval(input()))
p=list(map(int,input().split()))
for i in range(1,N):
add=list(map(int,input().split()))
temp=[[] for j in range(3)]
for j in range(3):
pnt=p[j]
for k in range(3):
if j==k:continue
else:
temp[k].append(pnt+add[k])
for j in range(3):
p[j]=max(temp[j])
print((max(p))) | N=int(eval(input()))
p=list(map(int,input().split()))
for i in range(1,N):
add=list(map(int,input().split()))
p0=p[0]
p1=p[1]
p2=p[2]
p[0]=max(add[0]+p1,add[0]+p2)
p[1]=max(add[1]+p2,add[1]+p0)
p[2]=max(add[2]+p0,add[2]+p1)
print((max(p)))
| 16 | 15 | 376 | 278 | N = int(eval(input()))
p = list(map(int, input().split()))
for i in range(1, N):
add = list(map(int, input().split()))
temp = [[] for j in range(3)]
for j in range(3):
pnt = p[j]
for k in range(3):
if j == k:
continue
else:
temp[k].append(pnt + add[k])
for j in range(3):
p[j] = max(temp[j])
print((max(p)))
| N = int(eval(input()))
p = list(map(int, input().split()))
for i in range(1, N):
add = list(map(int, input().split()))
p0 = p[0]
p1 = p[1]
p2 = p[2]
p[0] = max(add[0] + p1, add[0] + p2)
p[1] = max(add[1] + p2, add[1] + p0)
p[2] = max(add[2] + p0, add[2] + p1)
print((max(p)))
| false | 6.25 | [
"- temp = [[] for j in range(3)]",
"- for j in range(3):",
"- pnt = p[j]",
"- for k in range(3):",
"- if j == k:",
"- continue",
"- else:",
"- temp[k].append(pnt + add[k])",
"- for j in range(3):",
"- p[j] = max(temp[j])",
"+ p0 = p[0]",
"+ p1 = p[1]",
"+ p2 = p[2]",
"+ p[0] = max(add[0] + p1, add[0] + p2)",
"+ p[1] = max(add[1] + p2, add[1] + p0)",
"+ p[2] = max(add[2] + p0, add[2] + p1)"
] | false | 0.113353 | 0.044503 | 2.547093 | [
"s148992399",
"s457436351"
] |
u102461423 | p02901 | python | s184700371 | s865127569 | 1,485 | 788 | 3,444 | 12,512 | Accepted | Accepted | 46.94 | import sys
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)
import itertools
N,M = list(map(int,readline().split()))
AB = []
C = []
for _ in range(M):
AB.append(tuple(int(x) for x in readline().split()))
C.append(sum(1<<(int(x)-1) for x in readline().split()))
INF = 10**18
dp = [INF] * (1<<N)
dp[0] = 0
for n,((a,b),c) in itertools.product(list(range(1<<N)),list(zip(AB,C))):
m = n|c
x = dp[n]+a
if dp[m] > x:
dp[m] = x
answer = dp[-1]
if answer == INF:
answer = -1
print(answer)
| import sys
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)
import numpy as np
N,M = list(map(int,readline().split()))
AB = []
C = []
for _ in range(M):
AB.append(tuple(int(x) for x in readline().split()))
C.append(sum(1<<(int(x)-1) for x in readline().split()))
A,B = np.array(AB,np.int64).T
C = np.array(C,np.int64)
INF = 10**18
dp = np.full(1<<N,INF,np.int64)
dp[0] = 0
for n in range(1<<N):
target = n|C
value = A
I = np.lexsort((value,target))
target = target[I]
value = value[I]
is_first_elem = np.ones(M,np.bool)
is_first_elem[1:] = ~(target[:-1] == target[1:])
target = target[is_first_elem]
value = value[is_first_elem]
dp[target] = np.minimum(dp[target],dp[n]+value)
answer = dp[-1]
if answer == INF:
answer = -1
print(answer) | 27 | 37 | 574 | 869 | import sys
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**7)
import itertools
N, M = list(map(int, readline().split()))
AB = []
C = []
for _ in range(M):
AB.append(tuple(int(x) for x in readline().split()))
C.append(sum(1 << (int(x) - 1) for x in readline().split()))
INF = 10**18
dp = [INF] * (1 << N)
dp[0] = 0
for n, ((a, b), c) in itertools.product(list(range(1 << N)), list(zip(AB, C))):
m = n | c
x = dp[n] + a
if dp[m] > x:
dp[m] = x
answer = dp[-1]
if answer == INF:
answer = -1
print(answer)
| import sys
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**7)
import numpy as np
N, M = list(map(int, readline().split()))
AB = []
C = []
for _ in range(M):
AB.append(tuple(int(x) for x in readline().split()))
C.append(sum(1 << (int(x) - 1) for x in readline().split()))
A, B = np.array(AB, np.int64).T
C = np.array(C, np.int64)
INF = 10**18
dp = np.full(1 << N, INF, np.int64)
dp[0] = 0
for n in range(1 << N):
target = n | C
value = A
I = np.lexsort((value, target))
target = target[I]
value = value[I]
is_first_elem = np.ones(M, np.bool)
is_first_elem[1:] = ~(target[:-1] == target[1:])
target = target[is_first_elem]
value = value[is_first_elem]
dp[target] = np.minimum(dp[target], dp[n] + value)
answer = dp[-1]
if answer == INF:
answer = -1
print(answer)
| false | 27.027027 | [
"-import itertools",
"+import numpy as np",
"+A, B = np.array(AB, np.int64).T",
"+C = np.array(C, np.int64)",
"-dp = [INF] * (1 << N)",
"+dp = np.full(1 << N, INF, np.int64)",
"-for n, ((a, b), c) in itertools.product(list(range(1 << N)), list(zip(AB, C))):",
"- m = n | c",
"- x = dp[n] + a",
"- if dp[m] > x:",
"- dp[m] = x",
"+for n in range(1 << N):",
"+ target = n | C",
"+ value = A",
"+ I = np.lexsort((value, target))",
"+ target = target[I]",
"+ value = value[I]",
"+ is_first_elem = np.ones(M, np.bool)",
"+ is_first_elem[1:] = ~(target[:-1] == target[1:])",
"+ target = target[is_first_elem]",
"+ value = value[is_first_elem]",
"+ dp[target] = np.minimum(dp[target], dp[n] + value)"
] | false | 0.204381 | 0.23848 | 0.857016 | [
"s184700371",
"s865127569"
] |
u894258749 | p02998 | python | s823439687 | s691940431 | 637 | 561 | 25,072 | 16,104 | Accepted | Accepted | 11.93 | import sys
input = sys.stdin.readline
inpl = lambda: list(map(int,input().split()))
from collections import defaultdict
class UnionFind:
def __init__(self, N=None):
if N is None or N < 1:
self.parent = defaultdict(lambda: -1)
else:
self.parent = [-1]*int(N)
def root(self, n):
if self.parent[n] < 0:
return n
else:
m = self.root(self.parent[n])
self.parent[n] = m
return m
def merge(self, m, n):
rm = self.root(m)
rn = self.root(n)
if rm != rn:
if -self.parent[rm] < -self.parent[rn]:
rm, rn = rn, rm
self.parent[rm] += self.parent[rn]
self.parent[rn] = rm
def size(self, n):
return -self.parent[self.root(n)]
def connected(self, m, n):
return self.root(m) == self.root(n)
def groups(self):
if isinstance(self.parent,list):
return list([x<0 for x in self.parent]).count(True)
else: # self.parent: defaultdict
return list([x<0 for x in list(self.parent.values())]).count(True)
class CountUp:
def __init__(self, start=0):
self.index = start-1
def __call__(self):
self.index += 1
return self.index
Xi = defaultdict(CountUp())
Yi = defaultdict(CountUp())
N = int(eval(input()))
xy = []
for _ in range(N):
x, y = inpl()
xi = Xi[x]
yi = Yi[y]
xy.append((xi,yi))
Nx = len(Xi)
Ny = len(Yi)
Nxy = Nx + Ny
uf = UnionFind(Nx+Ny)
for xi, yi in xy:
uf.merge(xi,yi+Nx)
gi = defaultdict(CountUp())
Ng = uf.groups()
edges = [0]*Ng
nx = [0]*Ng
ny = [0]*Ng
for i in range(Nx):
nx[gi[uf.root(i)]] += 1
for i in range(Nx,Nxy):
ny[gi[uf.root(i)]] += 1
for xi, yi in xy:
edges[gi[uf.root(xi)]] += 1
ans = 0
for g in range(Ng):
ans += nx[g]*ny[g] - edges[g]
print(ans) | import sys
input = sys.stdin.readline
inpl = lambda: list(map(int,input().split()))
from collections import defaultdict
class UnionFind:
def __init__(self, N=None):
if N is None or N < 1:
self.parent = defaultdict(lambda: -1)
else:
self.parent = [-1]*int(N)
def root(self, n):
if self.parent[n] < 0:
return n
else:
m = self.root(self.parent[n])
self.parent[n] = m
return m
def merge(self, m, n):
rm = self.root(m)
rn = self.root(n)
if rm != rn:
if -self.parent[rm] < -self.parent[rn]:
rm, rn = rn, rm
self.parent[rm] += self.parent[rn]
self.parent[rn] = rm
def size(self, n):
return -self.parent[self.root(n)]
def connected(self, m, n):
return self.root(m) == self.root(n)
def groups(self):
if isinstance(self.parent,list):
return list([x<0 for x in self.parent]).count(True)
else: # self.parent: defaultdict
return list([x<0 for x in list(self.parent.values())]).count(True)
class CountUp:
def __init__(self, start=0):
self.index = start-1
def __call__(self):
self.index += 1
return self.index
N = int(eval(input()))
uf = UnionFind()
for _ in range(N):
x, y = inpl()
uf.merge(2*x+1,2*y)
Ng = uf.groups()
nx = [0]*Ng
ny = [0]*Ng
gi = defaultdict(CountUp())
for k in list(uf.parent.keys()):
if k % 2:
nx[gi[uf.root(k)]] += 1
else:
ny[gi[uf.root(k)]] += 1
ans = sum([ nx[g]*ny[g] for g in range(Ng) ]) - N
print(ans) | 81 | 67 | 1,971 | 1,716 | import sys
input = sys.stdin.readline
inpl = lambda: list(map(int, input().split()))
from collections import defaultdict
class UnionFind:
def __init__(self, N=None):
if N is None or N < 1:
self.parent = defaultdict(lambda: -1)
else:
self.parent = [-1] * int(N)
def root(self, n):
if self.parent[n] < 0:
return n
else:
m = self.root(self.parent[n])
self.parent[n] = m
return m
def merge(self, m, n):
rm = self.root(m)
rn = self.root(n)
if rm != rn:
if -self.parent[rm] < -self.parent[rn]:
rm, rn = rn, rm
self.parent[rm] += self.parent[rn]
self.parent[rn] = rm
def size(self, n):
return -self.parent[self.root(n)]
def connected(self, m, n):
return self.root(m) == self.root(n)
def groups(self):
if isinstance(self.parent, list):
return list([x < 0 for x in self.parent]).count(True)
else: # self.parent: defaultdict
return list([x < 0 for x in list(self.parent.values())]).count(True)
class CountUp:
def __init__(self, start=0):
self.index = start - 1
def __call__(self):
self.index += 1
return self.index
Xi = defaultdict(CountUp())
Yi = defaultdict(CountUp())
N = int(eval(input()))
xy = []
for _ in range(N):
x, y = inpl()
xi = Xi[x]
yi = Yi[y]
xy.append((xi, yi))
Nx = len(Xi)
Ny = len(Yi)
Nxy = Nx + Ny
uf = UnionFind(Nx + Ny)
for xi, yi in xy:
uf.merge(xi, yi + Nx)
gi = defaultdict(CountUp())
Ng = uf.groups()
edges = [0] * Ng
nx = [0] * Ng
ny = [0] * Ng
for i in range(Nx):
nx[gi[uf.root(i)]] += 1
for i in range(Nx, Nxy):
ny[gi[uf.root(i)]] += 1
for xi, yi in xy:
edges[gi[uf.root(xi)]] += 1
ans = 0
for g in range(Ng):
ans += nx[g] * ny[g] - edges[g]
print(ans)
| import sys
input = sys.stdin.readline
inpl = lambda: list(map(int, input().split()))
from collections import defaultdict
class UnionFind:
def __init__(self, N=None):
if N is None or N < 1:
self.parent = defaultdict(lambda: -1)
else:
self.parent = [-1] * int(N)
def root(self, n):
if self.parent[n] < 0:
return n
else:
m = self.root(self.parent[n])
self.parent[n] = m
return m
def merge(self, m, n):
rm = self.root(m)
rn = self.root(n)
if rm != rn:
if -self.parent[rm] < -self.parent[rn]:
rm, rn = rn, rm
self.parent[rm] += self.parent[rn]
self.parent[rn] = rm
def size(self, n):
return -self.parent[self.root(n)]
def connected(self, m, n):
return self.root(m) == self.root(n)
def groups(self):
if isinstance(self.parent, list):
return list([x < 0 for x in self.parent]).count(True)
else: # self.parent: defaultdict
return list([x < 0 for x in list(self.parent.values())]).count(True)
class CountUp:
def __init__(self, start=0):
self.index = start - 1
def __call__(self):
self.index += 1
return self.index
N = int(eval(input()))
uf = UnionFind()
for _ in range(N):
x, y = inpl()
uf.merge(2 * x + 1, 2 * y)
Ng = uf.groups()
nx = [0] * Ng
ny = [0] * Ng
gi = defaultdict(CountUp())
for k in list(uf.parent.keys()):
if k % 2:
nx[gi[uf.root(k)]] += 1
else:
ny[gi[uf.root(k)]] += 1
ans = sum([nx[g] * ny[g] for g in range(Ng)]) - N
print(ans)
| false | 17.283951 | [
"-Xi = defaultdict(CountUp())",
"-Yi = defaultdict(CountUp())",
"-xy = []",
"+uf = UnionFind()",
"- xi = Xi[x]",
"- yi = Yi[y]",
"- xy.append((xi, yi))",
"-Nx = len(Xi)",
"-Ny = len(Yi)",
"-Nxy = Nx + Ny",
"-uf = UnionFind(Nx + Ny)",
"-for xi, yi in xy:",
"- uf.merge(xi, yi + Nx)",
"-gi = defaultdict(CountUp())",
"+ uf.merge(2 * x + 1, 2 * y)",
"-edges = [0] * Ng",
"-for i in range(Nx):",
"- nx[gi[uf.root(i)]] += 1",
"-for i in range(Nx, Nxy):",
"- ny[gi[uf.root(i)]] += 1",
"-for xi, yi in xy:",
"- edges[gi[uf.root(xi)]] += 1",
"-ans = 0",
"-for g in range(Ng):",
"- ans += nx[g] * ny[g] - edges[g]",
"+gi = defaultdict(CountUp())",
"+for k in list(uf.parent.keys()):",
"+ if k % 2:",
"+ nx[gi[uf.root(k)]] += 1",
"+ else:",
"+ ny[gi[uf.root(k)]] += 1",
"+ans = sum([nx[g] * ny[g] for g in range(Ng)]) - N"
] | false | 0.041753 | 0.041406 | 1.008382 | [
"s823439687",
"s691940431"
] |
u721316601 | p03062 | python | s629264841 | s684181363 | 194 | 171 | 25,644 | 14,252 | Accepted | Accepted | 11.86 | N = int(eval(input()))
A = list(map(int, input().split()))
dp = [[0,0] for i in range(N+1)]
dp[0][1] = -10**20
for i in range(N):
dp[i+1][0] = max(dp[i][0] + A[i], dp[i][1] - A[i])
dp[i+1][1] = max(dp[i][0] - A[i], dp[i][1] + A[i])
print((dp[-1][0]))
| N = int(eval(input()))
A = list(map(int, input().split()))
dp = [0, -10**20]
tmp = [0, 0]
for i in range(N):
tmp[0] = max(dp[0] + A[i], dp[1] - A[i])
tmp[1] = max(dp[0] - A[i], dp[1] + A[i])
dp[0], dp[1] = tmp[0], tmp[1]
print((dp[0])) | 10 | 10 | 262 | 249 | N = int(eval(input()))
A = list(map(int, input().split()))
dp = [[0, 0] for i in range(N + 1)]
dp[0][1] = -(10**20)
for i in range(N):
dp[i + 1][0] = max(dp[i][0] + A[i], dp[i][1] - A[i])
dp[i + 1][1] = max(dp[i][0] - A[i], dp[i][1] + A[i])
print((dp[-1][0]))
| N = int(eval(input()))
A = list(map(int, input().split()))
dp = [0, -(10**20)]
tmp = [0, 0]
for i in range(N):
tmp[0] = max(dp[0] + A[i], dp[1] - A[i])
tmp[1] = max(dp[0] - A[i], dp[1] + A[i])
dp[0], dp[1] = tmp[0], tmp[1]
print((dp[0]))
| false | 0 | [
"-dp = [[0, 0] for i in range(N + 1)]",
"-dp[0][1] = -(10**20)",
"+dp = [0, -(10**20)]",
"+tmp = [0, 0]",
"- dp[i + 1][0] = max(dp[i][0] + A[i], dp[i][1] - A[i])",
"- dp[i + 1][1] = max(dp[i][0] - A[i], dp[i][1] + A[i])",
"-print((dp[-1][0]))",
"+ tmp[0] = max(dp[0] + A[i], dp[1] - A[i])",
"+ tmp[1] = max(dp[0] - A[i], dp[1] + A[i])",
"+ dp[0], dp[1] = tmp[0], tmp[1]",
"+print((dp[0]))"
] | false | 0.117052 | 0.035542 | 3.293344 | [
"s629264841",
"s684181363"
] |
u519003353 | p03493 | python | s960252788 | s005119091 | 19 | 17 | 2,940 | 2,940 | Accepted | Accepted | 10.53 | print((input().count("1"))) | number = eval(input())
a = number.count("1")
print(a)
| 1 | 3 | 25 | 50 | print((input().count("1")))
| number = eval(input())
a = number.count("1")
print(a)
| false | 66.666667 | [
"-print((input().count(\"1\")))",
"+number = eval(input())",
"+a = number.count(\"1\")",
"+print(a)"
] | false | 0.070173 | 0.040613 | 1.727849 | [
"s960252788",
"s005119091"
] |
u525065967 | p02888 | python | s318659144 | s842537341 | 1,715 | 1,400 | 3,188 | 3,188 | Accepted | Accepted | 18.37 | N = int(eval(input()))
L = list(map(int,input().split()))
L.sort()
cmax = L[-1] + L[-2]
csum = list(0 for _ in range(cmax+1))
for i in range(N): csum[L[i]] += 1
for i in range(1,cmax+1): csum[i] += csum[i-1]
ans = 0
for ib in range(N):
b = L[ib]
for ia in range(ib):
a = L[ia]
minL, maxL = abs(a-b), a+b
ans += csum[maxL-1] - csum[minL]
if minL < a < maxL: ans -= 1
if minL < b < maxL: ans -= 1
print((ans//3)) | import bisect
N = int(eval(input()))
L = list(map(int,input().split()))
L.sort()
ans = 0
for b in range(N):
for a in range(b):
ans += bisect.bisect_left(L, L[a] + L[b])-(b+1)
print(ans) | 17 | 9 | 466 | 199 | N = int(eval(input()))
L = list(map(int, input().split()))
L.sort()
cmax = L[-1] + L[-2]
csum = list(0 for _ in range(cmax + 1))
for i in range(N):
csum[L[i]] += 1
for i in range(1, cmax + 1):
csum[i] += csum[i - 1]
ans = 0
for ib in range(N):
b = L[ib]
for ia in range(ib):
a = L[ia]
minL, maxL = abs(a - b), a + b
ans += csum[maxL - 1] - csum[minL]
if minL < a < maxL:
ans -= 1
if minL < b < maxL:
ans -= 1
print((ans // 3))
| import bisect
N = int(eval(input()))
L = list(map(int, input().split()))
L.sort()
ans = 0
for b in range(N):
for a in range(b):
ans += bisect.bisect_left(L, L[a] + L[b]) - (b + 1)
print(ans)
| false | 47.058824 | [
"+import bisect",
"+",
"-cmax = L[-1] + L[-2]",
"-csum = list(0 for _ in range(cmax + 1))",
"-for i in range(N):",
"- csum[L[i]] += 1",
"-for i in range(1, cmax + 1):",
"- csum[i] += csum[i - 1]",
"-for ib in range(N):",
"- b = L[ib]",
"- for ia in range(ib):",
"- a = L[ia]",
"- minL, maxL = abs(a - b), a + b",
"- ans += csum[maxL - 1] - csum[minL]",
"- if minL < a < maxL:",
"- ans -= 1",
"- if minL < b < maxL:",
"- ans -= 1",
"-print((ans // 3))",
"+for b in range(N):",
"+ for a in range(b):",
"+ ans += bisect.bisect_left(L, L[a] + L[b]) - (b + 1)",
"+print(ans)"
] | false | 0.039275 | 0.036197 | 1.08504 | [
"s318659144",
"s842537341"
] |
u620084012 | p03112 | python | s698158029 | s269726892 | 1,103 | 684 | 16,752 | 12,780 | Accepted | Accepted | 37.99 | import bisect
A, B, Q = list(map(int,input().split()))
S = [-float("inf")] + sorted([int(eval(input())) for k in range(A)]) + [float("inf")]
T = [-float("inf")] + sorted([int(eval(input())) for k in range(B)]) + [float("inf")]
X = [int(eval(input())) for k in range(Q)]
for x in X:
p = bisect.bisect_left(S,x)
q = bisect.bisect_left(T,x)
t1 = max(abs(S[p]-x),abs(T[q]-x))
t2 = max(abs(S[p-1]-x),abs(T[q-1]-x))
t3 = abs(S[p-1]-x)+abs(S[p-1]-T[q])
t4 = abs(T[q-1]-x)+abs(S[p]-T[q-1])
t5 = abs(S[p]-x)+abs(S[p]-T[q-1])
t6 = abs(T[q]-x)+abs(S[p-1]-T[q])
print((min(t1,t2,t3,t4,t5,t6))) | import sys, math, bisect
sys.setrecursionlimit(200010)
def input():
return sys.stdin.readline()[:-1]
def main():
A, B, Q = list(map(int,input().split()))
s = [-10**12] + sorted([int(eval(input())) for k in range(A)]) + [10**12]
t = [-10**12] + sorted([int(eval(input())) for k in range(B)]) + [10**12]
for _ in range(Q):
q = int(eval(input()))
s1 = s[bisect.bisect_left(s,q)]
s2 = s[bisect.bisect_left(s,q)-1]
t1 = t[bisect.bisect_left(t,q)]
t2 = t[bisect.bisect_left(t,q)-1]
d1 = max(q-s2,q-t2)
d2 = max(s1-q,t1-q)
d3 = 2*(q-s2)+t1-q
d4 = 2*(q-t2)+s1-q
d5 = 2*(s1-q)+q-t2
d6 = 2*(t1-q)+q-s2
print((min(d1,d2,d3,d4,d5,d6)))
if __name__ == '__main__':
main()
| 16 | 26 | 615 | 780 | import bisect
A, B, Q = list(map(int, input().split()))
S = [-float("inf")] + sorted([int(eval(input())) for k in range(A)]) + [float("inf")]
T = [-float("inf")] + sorted([int(eval(input())) for k in range(B)]) + [float("inf")]
X = [int(eval(input())) for k in range(Q)]
for x in X:
p = bisect.bisect_left(S, x)
q = bisect.bisect_left(T, x)
t1 = max(abs(S[p] - x), abs(T[q] - x))
t2 = max(abs(S[p - 1] - x), abs(T[q - 1] - x))
t3 = abs(S[p - 1] - x) + abs(S[p - 1] - T[q])
t4 = abs(T[q - 1] - x) + abs(S[p] - T[q - 1])
t5 = abs(S[p] - x) + abs(S[p] - T[q - 1])
t6 = abs(T[q] - x) + abs(S[p - 1] - T[q])
print((min(t1, t2, t3, t4, t5, t6)))
| import sys, math, bisect
sys.setrecursionlimit(200010)
def input():
return sys.stdin.readline()[:-1]
def main():
A, B, Q = list(map(int, input().split()))
s = [-(10**12)] + sorted([int(eval(input())) for k in range(A)]) + [10**12]
t = [-(10**12)] + sorted([int(eval(input())) for k in range(B)]) + [10**12]
for _ in range(Q):
q = int(eval(input()))
s1 = s[bisect.bisect_left(s, q)]
s2 = s[bisect.bisect_left(s, q) - 1]
t1 = t[bisect.bisect_left(t, q)]
t2 = t[bisect.bisect_left(t, q) - 1]
d1 = max(q - s2, q - t2)
d2 = max(s1 - q, t1 - q)
d3 = 2 * (q - s2) + t1 - q
d4 = 2 * (q - t2) + s1 - q
d5 = 2 * (s1 - q) + q - t2
d6 = 2 * (t1 - q) + q - s2
print((min(d1, d2, d3, d4, d5, d6)))
if __name__ == "__main__":
main()
| false | 38.461538 | [
"-import bisect",
"+import sys, math, bisect",
"-A, B, Q = list(map(int, input().split()))",
"-S = [-float(\"inf\")] + sorted([int(eval(input())) for k in range(A)]) + [float(\"inf\")]",
"-T = [-float(\"inf\")] + sorted([int(eval(input())) for k in range(B)]) + [float(\"inf\")]",
"-X = [int(eval(input())) for k in range(Q)]",
"-for x in X:",
"- p = bisect.bisect_left(S, x)",
"- q = bisect.bisect_left(T, x)",
"- t1 = max(abs(S[p] - x), abs(T[q] - x))",
"- t2 = max(abs(S[p - 1] - x), abs(T[q - 1] - x))",
"- t3 = abs(S[p - 1] - x) + abs(S[p - 1] - T[q])",
"- t4 = abs(T[q - 1] - x) + abs(S[p] - T[q - 1])",
"- t5 = abs(S[p] - x) + abs(S[p] - T[q - 1])",
"- t6 = abs(T[q] - x) + abs(S[p - 1] - T[q])",
"- print((min(t1, t2, t3, t4, t5, t6)))",
"+sys.setrecursionlimit(200010)",
"+",
"+",
"+def input():",
"+ return sys.stdin.readline()[:-1]",
"+",
"+",
"+def main():",
"+ A, B, Q = list(map(int, input().split()))",
"+ s = [-(10**12)] + sorted([int(eval(input())) for k in range(A)]) + [10**12]",
"+ t = [-(10**12)] + sorted([int(eval(input())) for k in range(B)]) + [10**12]",
"+ for _ in range(Q):",
"+ q = int(eval(input()))",
"+ s1 = s[bisect.bisect_left(s, q)]",
"+ s2 = s[bisect.bisect_left(s, q) - 1]",
"+ t1 = t[bisect.bisect_left(t, q)]",
"+ t2 = t[bisect.bisect_left(t, q) - 1]",
"+ d1 = max(q - s2, q - t2)",
"+ d2 = max(s1 - q, t1 - q)",
"+ d3 = 2 * (q - s2) + t1 - q",
"+ d4 = 2 * (q - t2) + s1 - q",
"+ d5 = 2 * (s1 - q) + q - t2",
"+ d6 = 2 * (t1 - q) + q - s2",
"+ print((min(d1, d2, d3, d4, d5, d6)))",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.03736 | 0.061037 | 0.612083 | [
"s698158029",
"s269726892"
] |
u260980560 | p00713 | python | s539628324 | s856799877 | 28,240 | 24,730 | 6,640 | 6,580 | Accepted | Accepted | 12.43 | from math import sqrt
from bisect import bisect_left
def circle_center(x1, y1, x2, y2):
xd = x2 - x1; yd = y2 - y1
d = xd**2 + yd**2
k = sqrt((4.0 - d) / d) / 2.0
xc = (x1 + x2) / 2.0; yc = (y1 + y2) / 2.0
xd *= k; yd *= k
return [[xc - yd, yc + xd], [xc + yd, yc - xd]]
while 1:
n = int(input())
if n==0: break
p = sorted(list(map(float, input().split())) for i in range(n))
px = [e[0] for e in p]; py = [e[1] for e in p]
prev = 0
ans = 1
for i in range(n):
bx = px[i]; by = py[i]
while bx - px[prev] >= 2.0: prev += 1
for j in range(i+1, n):
cx = px[j]; cy = py[j]
if cx - bx >= 2.0: break
if (bx - cx)**2 + (by - cy)**2 <= 4.0:
for ex, ey in circle_center(bx, by, cx, cy):
count = 2
for k in range(prev, n):
if k==i or k==j: continue
dx = px[k]; dy = py[k]
if dx - ex >= 1.0: break
if (ex - dx)**2 + (ey - dy)**2 <= 1.0:
count += 1
ans = max(ans, count)
print(ans) | from math import sqrt
def circle_center(x1, y1, x2, y2):
xd = x2 - x1; yd = y2 - y1
d = xd**2 + yd**2
k = sqrt((4.0 - d) / d) / 2.0
xc = (x1 + x2) / 2.0; yc = (y1 + y2) / 2.0
xd *= k; yd *= k
return [[xc - yd, yc + xd], [xc + yd, yc - xd]]
while 1:
n = int(input())
if n==0: break
p = sorted(list(map(float, input().split())) for i in range(n))
prev = 0
ans = 1
for i in range(n):
bx, by = p[i]
while bx - p[prev][0] >= 2.0: prev += 1
for j in range(i+1, n):
cx, cy = p[j]
if cx - bx >= 2.0: break
if abs(by - cy) <= 2.0 and (bx - cx)**2 + (by - cy)**2 <= 4.0:
for ex, ey in circle_center(bx, by, cx, cy):
count = 2
for k in range(prev, n):
if k==i or k==j: continue
dx, dy = p[k]
if ex - dx >= 1.0: continue
if dx - ex >= 1.0: break
if abs(ey - dy) <= 1.0 and (ex - dx)**2 + (ey - dy)**2 <= 1.0:
count += 1
ans = max(ans, count)
print(ans) | 33 | 32 | 1,220 | 1,212 | from math import sqrt
from bisect import bisect_left
def circle_center(x1, y1, x2, y2):
xd = x2 - x1
yd = y2 - y1
d = xd**2 + yd**2
k = sqrt((4.0 - d) / d) / 2.0
xc = (x1 + x2) / 2.0
yc = (y1 + y2) / 2.0
xd *= k
yd *= k
return [[xc - yd, yc + xd], [xc + yd, yc - xd]]
while 1:
n = int(input())
if n == 0:
break
p = sorted(list(map(float, input().split())) for i in range(n))
px = [e[0] for e in p]
py = [e[1] for e in p]
prev = 0
ans = 1
for i in range(n):
bx = px[i]
by = py[i]
while bx - px[prev] >= 2.0:
prev += 1
for j in range(i + 1, n):
cx = px[j]
cy = py[j]
if cx - bx >= 2.0:
break
if (bx - cx) ** 2 + (by - cy) ** 2 <= 4.0:
for ex, ey in circle_center(bx, by, cx, cy):
count = 2
for k in range(prev, n):
if k == i or k == j:
continue
dx = px[k]
dy = py[k]
if dx - ex >= 1.0:
break
if (ex - dx) ** 2 + (ey - dy) ** 2 <= 1.0:
count += 1
ans = max(ans, count)
print(ans)
| from math import sqrt
def circle_center(x1, y1, x2, y2):
xd = x2 - x1
yd = y2 - y1
d = xd**2 + yd**2
k = sqrt((4.0 - d) / d) / 2.0
xc = (x1 + x2) / 2.0
yc = (y1 + y2) / 2.0
xd *= k
yd *= k
return [[xc - yd, yc + xd], [xc + yd, yc - xd]]
while 1:
n = int(input())
if n == 0:
break
p = sorted(list(map(float, input().split())) for i in range(n))
prev = 0
ans = 1
for i in range(n):
bx, by = p[i]
while bx - p[prev][0] >= 2.0:
prev += 1
for j in range(i + 1, n):
cx, cy = p[j]
if cx - bx >= 2.0:
break
if abs(by - cy) <= 2.0 and (bx - cx) ** 2 + (by - cy) ** 2 <= 4.0:
for ex, ey in circle_center(bx, by, cx, cy):
count = 2
for k in range(prev, n):
if k == i or k == j:
continue
dx, dy = p[k]
if ex - dx >= 1.0:
continue
if dx - ex >= 1.0:
break
if (
abs(ey - dy) <= 1.0
and (ex - dx) ** 2 + (ey - dy) ** 2 <= 1.0
):
count += 1
ans = max(ans, count)
print(ans)
| false | 3.030303 | [
"-from bisect import bisect_left",
"- px = [e[0] for e in p]",
"- py = [e[1] for e in p]",
"- bx = px[i]",
"- by = py[i]",
"- while bx - px[prev] >= 2.0:",
"+ bx, by = p[i]",
"+ while bx - p[prev][0] >= 2.0:",
"- cx = px[j]",
"- cy = py[j]",
"+ cx, cy = p[j]",
"- if (bx - cx) ** 2 + (by - cy) ** 2 <= 4.0:",
"+ if abs(by - cy) <= 2.0 and (bx - cx) ** 2 + (by - cy) ** 2 <= 4.0:",
"- dx = px[k]",
"- dy = py[k]",
"+ dx, dy = p[k]",
"+ if ex - dx >= 1.0:",
"+ continue",
"- if (ex - dx) ** 2 + (ey - dy) ** 2 <= 1.0:",
"+ if (",
"+ abs(ey - dy) <= 1.0",
"+ and (ex - dx) ** 2 + (ey - dy) ** 2 <= 1.0",
"+ ):"
] | false | 0.056661 | 0.050003 | 1.133158 | [
"s539628324",
"s856799877"
] |
u137038354 | p02614 | python | s326650803 | s809268858 | 66 | 53 | 9,112 | 9,176 | Accepted | Accepted | 19.7 | import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
H,W,K = list(map(int,readline().split()))
C = [readline().strip() for _ in range(H)]
ans = 0
for i in range(2**H):
for j in range(2**W):
cnt = 0
for s in range(H):
for t in range(W):
if (i >> s) & 1 and (j >> t) & 1 and C[s][t] == "#":
cnt += 1
if cnt == K:
ans += 1
print(ans) | import sys
def main():
H,W,K = list(map(int,input().split()))
a = []
for i in range(H):
a.append(sys.stdin.readline())
ans = 0
for i in range(2**H):
for j in range(2**W):
cnt = 0
for s in range(H):
for t in range(W):
if(i >> s) & 1 and (j >> t) & 1 and a[s][t] == "#":
cnt += 1
if cnt == K :
ans += 1
print(ans)
if __name__ == "__main__":
main() | 20 | 22 | 476 | 448 | import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
H, W, K = list(map(int, readline().split()))
C = [readline().strip() for _ in range(H)]
ans = 0
for i in range(2**H):
for j in range(2**W):
cnt = 0
for s in range(H):
for t in range(W):
if (i >> s) & 1 and (j >> t) & 1 and C[s][t] == "#":
cnt += 1
if cnt == K:
ans += 1
print(ans)
| import sys
def main():
H, W, K = list(map(int, input().split()))
a = []
for i in range(H):
a.append(sys.stdin.readline())
ans = 0
for i in range(2**H):
for j in range(2**W):
cnt = 0
for s in range(H):
for t in range(W):
if (i >> s) & 1 and (j >> t) & 1 and a[s][t] == "#":
cnt += 1
if cnt == K:
ans += 1
print(ans)
if __name__ == "__main__":
main()
| false | 9.090909 | [
"-read = sys.stdin.read",
"-readline = sys.stdin.readline",
"-readlines = sys.stdin.readlines",
"-H, W, K = list(map(int, readline().split()))",
"-C = [readline().strip() for _ in range(H)]",
"-ans = 0",
"-for i in range(2**H):",
"- for j in range(2**W):",
"- cnt = 0",
"- for s in range(H):",
"- for t in range(W):",
"- if (i >> s) & 1 and (j >> t) & 1 and C[s][t] == \"#\":",
"- cnt += 1",
"- if cnt == K:",
"- ans += 1",
"-print(ans)",
"+",
"+def main():",
"+ H, W, K = list(map(int, input().split()))",
"+ a = []",
"+ for i in range(H):",
"+ a.append(sys.stdin.readline())",
"+ ans = 0",
"+ for i in range(2**H):",
"+ for j in range(2**W):",
"+ cnt = 0",
"+ for s in range(H):",
"+ for t in range(W):",
"+ if (i >> s) & 1 and (j >> t) & 1 and a[s][t] == \"#\":",
"+ cnt += 1",
"+ if cnt == K:",
"+ ans += 1",
"+ print(ans)",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.047459 | 0.040589 | 1.169242 | [
"s326650803",
"s809268858"
] |
u278492238 | p03317 | python | s170063363 | s925958397 | 41 | 19 | 13,812 | 4,724 | Accepted | Accepted | 53.66 | from math import ceil
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
r = ceil((N-1) / (K-1))
print(r) | from math import ceil
N, K = list(map(int, input().split()))
#A = list(map(int, input().split()))
A = eval(input()) # dummy read
r = ceil((N-1) / (K-1))
print(r) | 6 | 7 | 135 | 163 | from math import ceil
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
r = ceil((N - 1) / (K - 1))
print(r)
| from math import ceil
N, K = list(map(int, input().split()))
# A = list(map(int, input().split()))
A = eval(input()) # dummy read
r = ceil((N - 1) / (K - 1))
print(r)
| false | 14.285714 | [
"-A = list(map(int, input().split()))",
"+# A = list(map(int, input().split()))",
"+A = eval(input()) # dummy read"
] | false | 0.007675 | 0.032409 | 0.236802 | [
"s170063363",
"s925958397"
] |
u564902833 | p03112 | python | s773827073 | s513029987 | 1,693 | 1,103 | 13,988 | 16,156 | Accepted | Accepted | 34.85 | import bisect
A, B, Q = list(map(int, input().split()))
INF = 10 ** 18
s = [-INF] + [int(eval(input())) for i in range(A)] + [INF]
t = [-INF] + [int(eval(input())) for i in range(B)] + [INF]
for q in range(Q):
x = int(eval(input()))
b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)
res = INF
for S in [s[b - 1], s[b]]:
for T in [t[d - 1], t[d]]:
d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)
res = min(res, d1, d2)
print(res)
| from bisect import bisect_right
A, B, Q = list(map(int, input().split()))
INF = 10**18
s = [-INF]
t = [-INF]
for _ in range(A):
s.append(int(eval(input())))
s.append(INF)
for _ in range(B):
t.append(int(eval(input())))
t.append(INF)
x = list(map(int, (eval(input()) for _ in range(Q))))
for y in x:
i = bisect_right(s, y)
j = bisect_right(t, y)
# ans = INF
# for S in [s[i - 1], s[i]]:
# for T in [t[j - 1], t[j]]:
# d1, d2 = abs(S - y) + abs(T - S), abs(T - y) + abs(S - T)
# ans = min(ans, d1, d2)
ans = min(
max(abs(s[i] - y), abs(t[j] - y)),
max(abs(s[i - 1] - y), abs(t[j - 1] - y)),
2 * min(abs(s[i] - y), abs(t[j - 1] - y)) + max(abs(s[i] - y), abs(t[j - 1] - y)),
2 * min(abs(s[i - 1] - y), abs(t[j] - y)) + max(abs(s[i - 1] - y), abs(t[j] - y))
)
print(ans) | 14 | 28 | 451 | 870 | import bisect
A, B, Q = list(map(int, input().split()))
INF = 10**18
s = [-INF] + [int(eval(input())) for i in range(A)] + [INF]
t = [-INF] + [int(eval(input())) for i in range(B)] + [INF]
for q in range(Q):
x = int(eval(input()))
b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)
res = INF
for S in [s[b - 1], s[b]]:
for T in [t[d - 1], t[d]]:
d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)
res = min(res, d1, d2)
print(res)
| from bisect import bisect_right
A, B, Q = list(map(int, input().split()))
INF = 10**18
s = [-INF]
t = [-INF]
for _ in range(A):
s.append(int(eval(input())))
s.append(INF)
for _ in range(B):
t.append(int(eval(input())))
t.append(INF)
x = list(map(int, (eval(input()) for _ in range(Q))))
for y in x:
i = bisect_right(s, y)
j = bisect_right(t, y)
# ans = INF
# for S in [s[i - 1], s[i]]:
# for T in [t[j - 1], t[j]]:
# d1, d2 = abs(S - y) + abs(T - S), abs(T - y) + abs(S - T)
# ans = min(ans, d1, d2)
ans = min(
max(abs(s[i] - y), abs(t[j] - y)),
max(abs(s[i - 1] - y), abs(t[j - 1] - y)),
2 * min(abs(s[i] - y), abs(t[j - 1] - y))
+ max(abs(s[i] - y), abs(t[j - 1] - y)),
2 * min(abs(s[i - 1] - y), abs(t[j] - y))
+ max(abs(s[i - 1] - y), abs(t[j] - y)),
)
print(ans)
| false | 50 | [
"-import bisect",
"+from bisect import bisect_right",
"-s = [-INF] + [int(eval(input())) for i in range(A)] + [INF]",
"-t = [-INF] + [int(eval(input())) for i in range(B)] + [INF]",
"-for q in range(Q):",
"- x = int(eval(input()))",
"- b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)",
"- res = INF",
"- for S in [s[b - 1], s[b]]:",
"- for T in [t[d - 1], t[d]]:",
"- d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)",
"- res = min(res, d1, d2)",
"- print(res)",
"+s = [-INF]",
"+t = [-INF]",
"+for _ in range(A):",
"+ s.append(int(eval(input())))",
"+s.append(INF)",
"+for _ in range(B):",
"+ t.append(int(eval(input())))",
"+t.append(INF)",
"+x = list(map(int, (eval(input()) for _ in range(Q))))",
"+for y in x:",
"+ i = bisect_right(s, y)",
"+ j = bisect_right(t, y)",
"+ # ans = INF",
"+ # for S in [s[i - 1], s[i]]:",
"+ # for T in [t[j - 1], t[j]]:",
"+ # d1, d2 = abs(S - y) + abs(T - S), abs(T - y) + abs(S - T)",
"+ # ans = min(ans, d1, d2)",
"+ ans = min(",
"+ max(abs(s[i] - y), abs(t[j] - y)),",
"+ max(abs(s[i - 1] - y), abs(t[j - 1] - y)),",
"+ 2 * min(abs(s[i] - y), abs(t[j - 1] - y))",
"+ + max(abs(s[i] - y), abs(t[j - 1] - y)),",
"+ 2 * min(abs(s[i - 1] - y), abs(t[j] - y))",
"+ + max(abs(s[i - 1] - y), abs(t[j] - y)),",
"+ )",
"+ print(ans)"
] | false | 0.037519 | 0.037298 | 1.005925 | [
"s773827073",
"s513029987"
] |
u144913062 | p02555 | python | s866859792 | s049954126 | 107 | 62 | 68,992 | 63,396 | Accepted | Accepted | 42.06 | from itertools import accumulate
S = int(eval(input()))
mod = 10**9 + 7
if S == 1 or S == 2:
print((0))
exit()
dp = [0] * (S + 1)
dp[0] = 1
ans = 0
for i in range(S):
cum = list(accumulate(dp))
for j in range(S, 2, -1):
dp[j] = cum[j-3] % mod
dp[0] = dp[1] = dp[2] = 0
ans = (ans + dp[S]) % mod
print(ans) | S = int(eval(input()))
mod = 10**9 + 7
dp = [0] * (S + 1)
dp[0] = 1
for i in range(3, S + 1):
dp[i] = (dp[i-1] + dp[i-3]) % mod
print((dp[S])) | 17 | 7 | 346 | 144 | from itertools import accumulate
S = int(eval(input()))
mod = 10**9 + 7
if S == 1 or S == 2:
print((0))
exit()
dp = [0] * (S + 1)
dp[0] = 1
ans = 0
for i in range(S):
cum = list(accumulate(dp))
for j in range(S, 2, -1):
dp[j] = cum[j - 3] % mod
dp[0] = dp[1] = dp[2] = 0
ans = (ans + dp[S]) % mod
print(ans)
| S = int(eval(input()))
mod = 10**9 + 7
dp = [0] * (S + 1)
dp[0] = 1
for i in range(3, S + 1):
dp[i] = (dp[i - 1] + dp[i - 3]) % mod
print((dp[S]))
| false | 58.823529 | [
"-from itertools import accumulate",
"-",
"-if S == 1 or S == 2:",
"- print((0))",
"- exit()",
"-ans = 0",
"-for i in range(S):",
"- cum = list(accumulate(dp))",
"- for j in range(S, 2, -1):",
"- dp[j] = cum[j - 3] % mod",
"- dp[0] = dp[1] = dp[2] = 0",
"- ans = (ans + dp[S]) % mod",
"-print(ans)",
"+for i in range(3, S + 1):",
"+ dp[i] = (dp[i - 1] + dp[i - 3]) % mod",
"+print((dp[S]))"
] | false | 0.1145 | 0.036749 | 3.115731 | [
"s866859792",
"s049954126"
] |
u285891772 | p03393 | python | s368497932 | s340566351 | 56 | 39 | 5,840 | 5,200 | Accepted | Accepted | 30.36 | import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
def ZIP(n): return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *
S = eval(input())
A = set(S)
for x in ascii_lowercase:
if not x in A:
print((S+x))
break
else:
if S == ascii_lowercase[::-1]:
print((-1))
else:
S = S[::-1]
for i in range(len(S)-1):
if S[i+1] < S[i]:
for char in sorted(S[:i+1]):
if char > S[i+1]:
print((S[::-1][:-i-2]+char))
exit()
| import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
def ZIP(n): return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *
S = eval(input())
A = set(S)
for x in ascii_lowercase:
if not x in A:
print((S+x))
break
else:
if S == ascii_lowercase[::-1]:
print((-1))
else:
for i in range(len(S)-2, -1, -1):
if S[i] < S[i+1]:
for char in sorted(S[i+1:]):
if S[i] < char:
print((S[:i]+char))
exit()
| 42 | 40 | 1,258 | 1,238 | import sys, re
from collections import deque, defaultdict, Counter
from math import (
ceil,
sqrt,
hypot,
factorial,
pi,
sin,
cos,
tan,
asin,
acos,
atan,
radians,
degrees,
log2,
log,
)
from itertools import (
accumulate,
permutations,
combinations,
combinations_with_replacement,
product,
groupby,
)
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input():
return sys.stdin.readline().strip()
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST():
return list(map(int, input().split()))
def ZIP(n):
return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
from decimal import *
S = eval(input())
A = set(S)
for x in ascii_lowercase:
if not x in A:
print((S + x))
break
else:
if S == ascii_lowercase[::-1]:
print((-1))
else:
S = S[::-1]
for i in range(len(S) - 1):
if S[i + 1] < S[i]:
for char in sorted(S[: i + 1]):
if char > S[i + 1]:
print((S[::-1][: -i - 2] + char))
exit()
| import sys, re
from collections import deque, defaultdict, Counter
from math import (
ceil,
sqrt,
hypot,
factorial,
pi,
sin,
cos,
tan,
asin,
acos,
atan,
radians,
degrees,
log2,
log,
)
from itertools import (
accumulate,
permutations,
combinations,
combinations_with_replacement,
product,
groupby,
)
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input():
return sys.stdin.readline().strip()
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST():
return list(map(int, input().split()))
def ZIP(n):
return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
from decimal import *
S = eval(input())
A = set(S)
for x in ascii_lowercase:
if not x in A:
print((S + x))
break
else:
if S == ascii_lowercase[::-1]:
print((-1))
else:
for i in range(len(S) - 2, -1, -1):
if S[i] < S[i + 1]:
for char in sorted(S[i + 1 :]):
if S[i] < char:
print((S[:i] + char))
exit()
| false | 4.761905 | [
"- S = S[::-1]",
"- for i in range(len(S) - 1):",
"- if S[i + 1] < S[i]:",
"- for char in sorted(S[: i + 1]):",
"- if char > S[i + 1]:",
"- print((S[::-1][: -i - 2] + char))",
"+ for i in range(len(S) - 2, -1, -1):",
"+ if S[i] < S[i + 1]:",
"+ for char in sorted(S[i + 1 :]):",
"+ if S[i] < char:",
"+ print((S[:i] + char))"
] | false | 0.104376 | 0.051726 | 2.017863 | [
"s368497932",
"s340566351"
] |
u340781749 | p03504 | python | s483752909 | s553585511 | 565 | 476 | 25,632 | 19,280 | Accepted | Accepted | 15.75 | from collections import defaultdict
from heapq import heapreplace, heappush
n, v = list(map(int, input().split()))
programs = defaultdict(list)
for _ in range(n):
s, t, c = list(map(int, input().split()))
programs[c].append((s, t))
combined = []
for c, p in list(programs.items()):
p.sort()
ps, pt = p[0]
for s, t in p[1:]:
if pt == s:
pt = t
else:
combined.append((ps, pt, c))
ps, pt = s, t
combined.append((ps, pt, c))
combined.sort()
recorders = [(-1, None)]
for s, t, c in combined:
end, channel = recorders[0]
if end < s or c == channel:
heapreplace(recorders, (t, c))
else:
heappush(recorders, (t, c))
print((len(recorders)))
| from collections import defaultdict
from itertools import accumulate
n, v = list(map(int, input().split()))
programs = defaultdict(list)
for _ in range(n):
s, t, c = list(map(int, input().split()))
programs[c].append((s, t))
imos = [0] * (2 * 10 ** 5 + 2)
for c, p in list(programs.items()):
p.sort()
ps, pt = p[0]
for s, t in p[1:]:
if pt == s:
pt = t
else:
imos[2 * ps - 1] += 1
imos[2 * pt + 1] -= 1
ps, pt = s, t
imos[2 * ps - 1] += 1
imos[2 * pt + 1] -= 1
print((max(accumulate(imos))))
| 30 | 24 | 748 | 590 | from collections import defaultdict
from heapq import heapreplace, heappush
n, v = list(map(int, input().split()))
programs = defaultdict(list)
for _ in range(n):
s, t, c = list(map(int, input().split()))
programs[c].append((s, t))
combined = []
for c, p in list(programs.items()):
p.sort()
ps, pt = p[0]
for s, t in p[1:]:
if pt == s:
pt = t
else:
combined.append((ps, pt, c))
ps, pt = s, t
combined.append((ps, pt, c))
combined.sort()
recorders = [(-1, None)]
for s, t, c in combined:
end, channel = recorders[0]
if end < s or c == channel:
heapreplace(recorders, (t, c))
else:
heappush(recorders, (t, c))
print((len(recorders)))
| from collections import defaultdict
from itertools import accumulate
n, v = list(map(int, input().split()))
programs = defaultdict(list)
for _ in range(n):
s, t, c = list(map(int, input().split()))
programs[c].append((s, t))
imos = [0] * (2 * 10**5 + 2)
for c, p in list(programs.items()):
p.sort()
ps, pt = p[0]
for s, t in p[1:]:
if pt == s:
pt = t
else:
imos[2 * ps - 1] += 1
imos[2 * pt + 1] -= 1
ps, pt = s, t
imos[2 * ps - 1] += 1
imos[2 * pt + 1] -= 1
print((max(accumulate(imos))))
| false | 20 | [
"-from heapq import heapreplace, heappush",
"+from itertools import accumulate",
"-combined = []",
"+imos = [0] * (2 * 10**5 + 2)",
"- combined.append((ps, pt, c))",
"+ imos[2 * ps - 1] += 1",
"+ imos[2 * pt + 1] -= 1",
"- combined.append((ps, pt, c))",
"-combined.sort()",
"-recorders = [(-1, None)]",
"-for s, t, c in combined:",
"- end, channel = recorders[0]",
"- if end < s or c == channel:",
"- heapreplace(recorders, (t, c))",
"- else:",
"- heappush(recorders, (t, c))",
"-print((len(recorders)))",
"+ imos[2 * ps - 1] += 1",
"+ imos[2 * pt + 1] -= 1",
"+print((max(accumulate(imos))))"
] | false | 0.043664 | 0.061666 | 0.708065 | [
"s483752909",
"s553585511"
] |
u968166680 | p02838 | python | s637199311 | s332411416 | 1,899 | 664 | 455,220 | 136,452 | Accepted | Accepted | 65.03 | import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
N, *A = list(map(int, read().split()))
M = 61
for i, a in enumerate(A):
A[i] = list(map(int, str(format(a, 'b')).zfill(M)[::-1]))
csum = [[0] * M for _ in range(N)]
csum[0] = A[0]
for i in range(1, N):
for j in range(M):
csum[i][j] = csum[i - 1][j] + A[i][j]
p2 = [0] * M
p2[0] = 1
for i in range(M - 1):
p2[i + 1] = p2[i] * 2 % MOD
B = [0] * M
for i, a in enumerate(A[1:], 1):
for j in range(M):
B[j] += csum[i - 1][j] if a[j] == 0 else i - csum[i - 1][j]
ans = 0
for j in range(M):
ans = (ans + B[j] * p2[j]) % MOD
print(ans)
return
if __name__ == '__main__':
main()
| import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
N, *A = list(map(int, read().split()))
M = 61
C = [0] * M
for a in A:
a = str(format(a, 'b'))
for i, d in enumerate(reversed(a)):
if d == '1':
C[i] += 1
ans = 0
p = 1
for c in C:
ans = (ans + c * (N - c) * p) % MOD
p = p * 2 % MOD
print(ans)
return
if __name__ == '__main__':
main()
| 42 | 32 | 911 | 584 | import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60
MOD = 1000000007
def main():
N, *A = list(map(int, read().split()))
M = 61
for i, a in enumerate(A):
A[i] = list(map(int, str(format(a, "b")).zfill(M)[::-1]))
csum = [[0] * M for _ in range(N)]
csum[0] = A[0]
for i in range(1, N):
for j in range(M):
csum[i][j] = csum[i - 1][j] + A[i][j]
p2 = [0] * M
p2[0] = 1
for i in range(M - 1):
p2[i + 1] = p2[i] * 2 % MOD
B = [0] * M
for i, a in enumerate(A[1:], 1):
for j in range(M):
B[j] += csum[i - 1][j] if a[j] == 0 else i - csum[i - 1][j]
ans = 0
for j in range(M):
ans = (ans + B[j] * p2[j]) % MOD
print(ans)
return
if __name__ == "__main__":
main()
| import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60
MOD = 1000000007
def main():
N, *A = list(map(int, read().split()))
M = 61
C = [0] * M
for a in A:
a = str(format(a, "b"))
for i, d in enumerate(reversed(a)):
if d == "1":
C[i] += 1
ans = 0
p = 1
for c in C:
ans = (ans + c * (N - c) * p) % MOD
p = p * 2 % MOD
print(ans)
return
if __name__ == "__main__":
main()
| false | 23.809524 | [
"- for i, a in enumerate(A):",
"- A[i] = list(map(int, str(format(a, \"b\")).zfill(M)[::-1]))",
"- csum = [[0] * M for _ in range(N)]",
"- csum[0] = A[0]",
"- for i in range(1, N):",
"- for j in range(M):",
"- csum[i][j] = csum[i - 1][j] + A[i][j]",
"- p2 = [0] * M",
"- p2[0] = 1",
"- for i in range(M - 1):",
"- p2[i + 1] = p2[i] * 2 % MOD",
"- B = [0] * M",
"- for i, a in enumerate(A[1:], 1):",
"- for j in range(M):",
"- B[j] += csum[i - 1][j] if a[j] == 0 else i - csum[i - 1][j]",
"+ C = [0] * M",
"+ for a in A:",
"+ a = str(format(a, \"b\"))",
"+ for i, d in enumerate(reversed(a)):",
"+ if d == \"1\":",
"+ C[i] += 1",
"- for j in range(M):",
"- ans = (ans + B[j] * p2[j]) % MOD",
"+ p = 1",
"+ for c in C:",
"+ ans = (ans + c * (N - c) * p) % MOD",
"+ p = p * 2 % MOD"
] | false | 0.037762 | 0.044173 | 0.854872 | [
"s637199311",
"s332411416"
] |
u952708174 | p02755 | python | s873667031 | s460090906 | 254 | 17 | 2,940 | 3,060 | Accepted | Accepted | 93.31 | def c_tax_increase():
A, B = [int(i) for i in input().split()]
for k in range(1, 10**6):
t1 = 8 * k // 100
t2 = k // 10
if t1 > 0 and t2 > 0 and t1 == A and t2 == B:
return k
return -1
print((c_tax_increase())) | def c_tax_increase():
from math import floor, ceil
A, B = [int(i) for i in input().split()]
lower = ceil(max(25 * A / 2, 10 * B))
upper = floor(min(25 * (A + 1) / 2, 10 * (B + 1)))
return lower if lower < upper else -1
print((c_tax_increase())) | 10 | 8 | 266 | 270 | def c_tax_increase():
A, B = [int(i) for i in input().split()]
for k in range(1, 10**6):
t1 = 8 * k // 100
t2 = k // 10
if t1 > 0 and t2 > 0 and t1 == A and t2 == B:
return k
return -1
print((c_tax_increase()))
| def c_tax_increase():
from math import floor, ceil
A, B = [int(i) for i in input().split()]
lower = ceil(max(25 * A / 2, 10 * B))
upper = floor(min(25 * (A + 1) / 2, 10 * (B + 1)))
return lower if lower < upper else -1
print((c_tax_increase()))
| false | 20 | [
"+ from math import floor, ceil",
"+",
"- for k in range(1, 10**6):",
"- t1 = 8 * k // 100",
"- t2 = k // 10",
"- if t1 > 0 and t2 > 0 and t1 == A and t2 == B:",
"- return k",
"- return -1",
"+ lower = ceil(max(25 * A / 2, 10 * B))",
"+ upper = floor(min(25 * (A + 1) / 2, 10 * (B + 1)))",
"+ return lower if lower < upper else -1"
] | false | 0.189248 | 0.037707 | 5.018924 | [
"s873667031",
"s460090906"
] |
u427344224 | p03714 | python | s023157116 | s016381671 | 481 | 441 | 37,212 | 40,340 | Accepted | Accepted | 8.32 | import heapq
N = int(eval(input()))
a_list = list(map(int, input().split()))
max_score = - float("inf")
red_list = a_list[:N]
blue_list = [-a for a in a_list[2 * N:]]
heapq.heapify(red_list)
heapq.heapify(blue_list)
red_sum = [sum(red_list)]
blue_sum = [sum(blue_list)]
for i in range(N, 2 * N):
heapq.heappush(red_list, a_list[i])
item = heapq.heappop(red_list)
red_sum.append(max(red_sum[-1], red_sum[-1] + a_list[i] - item))
for i in range(2 * N - 1, N - 1, -1):
heapq.heappush(blue_list, -a_list[i])
item = heapq.heappop(blue_list)
blue_sum.append(max(blue_sum[-1], blue_sum[-1] - a_list[i] - item))
for i in range(N+1):
score = red_sum[i] + blue_sum[-(i + 1)]
if max_score < score:
max_score = score
print(max_score)
| import heapq
N = int(eval(input()))
a_list = list(map(int, input().split()))
max_score = - float("inf")
red_list = a_list[:N]
blue_list = [-a for a in a_list[2 * N:]]
heapq.heapify(red_list)
heapq.heapify(blue_list)
red_sum = [sum(red_list)]
blue_sum = [sum(blue_list)]
for i in range(N, 2 * N):
heapq.heappush(red_list, a_list[i])
item = heapq.heappop(red_list)
red_sum.append(red_sum[-1] + a_list[i] - item)
for i in range(2 * N - 1, N - 1, -1):
heapq.heappush(blue_list, -a_list[i])
item = heapq.heappop(blue_list)
blue_sum.append(blue_sum[-1] - a_list[i] - item)
for i in range(N+1):
score = red_sum[i] + blue_sum[-(i + 1)]
if max_score < score:
max_score = score
print(max_score)
| 29 | 29 | 790 | 753 | import heapq
N = int(eval(input()))
a_list = list(map(int, input().split()))
max_score = -float("inf")
red_list = a_list[:N]
blue_list = [-a for a in a_list[2 * N :]]
heapq.heapify(red_list)
heapq.heapify(blue_list)
red_sum = [sum(red_list)]
blue_sum = [sum(blue_list)]
for i in range(N, 2 * N):
heapq.heappush(red_list, a_list[i])
item = heapq.heappop(red_list)
red_sum.append(max(red_sum[-1], red_sum[-1] + a_list[i] - item))
for i in range(2 * N - 1, N - 1, -1):
heapq.heappush(blue_list, -a_list[i])
item = heapq.heappop(blue_list)
blue_sum.append(max(blue_sum[-1], blue_sum[-1] - a_list[i] - item))
for i in range(N + 1):
score = red_sum[i] + blue_sum[-(i + 1)]
if max_score < score:
max_score = score
print(max_score)
| import heapq
N = int(eval(input()))
a_list = list(map(int, input().split()))
max_score = -float("inf")
red_list = a_list[:N]
blue_list = [-a for a in a_list[2 * N :]]
heapq.heapify(red_list)
heapq.heapify(blue_list)
red_sum = [sum(red_list)]
blue_sum = [sum(blue_list)]
for i in range(N, 2 * N):
heapq.heappush(red_list, a_list[i])
item = heapq.heappop(red_list)
red_sum.append(red_sum[-1] + a_list[i] - item)
for i in range(2 * N - 1, N - 1, -1):
heapq.heappush(blue_list, -a_list[i])
item = heapq.heappop(blue_list)
blue_sum.append(blue_sum[-1] - a_list[i] - item)
for i in range(N + 1):
score = red_sum[i] + blue_sum[-(i + 1)]
if max_score < score:
max_score = score
print(max_score)
| false | 0 | [
"- red_sum.append(max(red_sum[-1], red_sum[-1] + a_list[i] - item))",
"+ red_sum.append(red_sum[-1] + a_list[i] - item)",
"- blue_sum.append(max(blue_sum[-1], blue_sum[-1] - a_list[i] - item))",
"+ blue_sum.append(blue_sum[-1] - a_list[i] - item)"
] | false | 0.048275 | 0.047123 | 1.024454 | [
"s023157116",
"s016381671"
] |
u227082700 | p02973 | python | s420303772 | s874127275 | 246 | 188 | 7,068 | 16,848 | Accepted | Accepted | 23.58 | import bisect;n,a,l=int(eval(input())),[-int(eval(input()))],1
for i in range(n-1):
b=-int(eval(input()))
if a[-1]>b:a[bisect.bisect_right(a,b)]=b
else:a.append(b);l+=1
print(l) | n=int(eval(input()))
a=[int(eval(input()))for _ in range(n)]
dp=[2]*(n+1)
from bisect import bisect_left,bisect_right
for i in a:
dp[bisect_left(dp,-i+1)]=-i
print((dp.index(2))) | 6 | 7 | 170 | 172 | import bisect
n, a, l = int(eval(input())), [-int(eval(input()))], 1
for i in range(n - 1):
b = -int(eval(input()))
if a[-1] > b:
a[bisect.bisect_right(a, b)] = b
else:
a.append(b)
l += 1
print(l)
| n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
dp = [2] * (n + 1)
from bisect import bisect_left, bisect_right
for i in a:
dp[bisect_left(dp, -i + 1)] = -i
print((dp.index(2)))
| false | 14.285714 | [
"-import bisect",
"+n = int(eval(input()))",
"+a = [int(eval(input())) for _ in range(n)]",
"+dp = [2] * (n + 1)",
"+from bisect import bisect_left, bisect_right",
"-n, a, l = int(eval(input())), [-int(eval(input()))], 1",
"-for i in range(n - 1):",
"- b = -int(eval(input()))",
"- if a[-1] > b:",
"- a[bisect.bisect_right(a, b)] = b",
"- else:",
"- a.append(b)",
"- l += 1",
"-print(l)",
"+for i in a:",
"+ dp[bisect_left(dp, -i + 1)] = -i",
"+print((dp.index(2)))"
] | false | 0.039009 | 0.040545 | 0.962112 | [
"s420303772",
"s874127275"
] |
u426534722 | p02278 | python | s608344872 | s370895847 | 30 | 20 | 7,884 | 5,764 | Accepted | Accepted | 33.33 | MAX = 1000
VMAX = 10000
n = int(eval(input()))
A = [int(i) for i in input().split()]
V = [False] * MAX
def solve():
B = A[:]
T = [0] * (VMAX + 1)
B.sort()
ans = 0
s = min(VMAX, min(A))
for i in range(n):
T[B[i]] = i
for i in range(n):
if V[i] : continue
cur = i
S = 0
m = VMAX
an = 0
while True:
V[cur] = True
an += 1
v = A[cur]
m = min(m, v)
S += v
cur = T[v]
if V[cur] : break
ans += min(S + (an - 2) * m, m + S + (an + 1) * s)
print(ans)
solve() | VMAX = 10000
n = int(eval(input()))
A = list(map(int, input().split()))
s = min(A)
def solve():
ans = 0
V = [False] * n
B = sorted(A)
T = [0] * (VMAX + 1)
for i in range(n):
T[B[i]] = i
for i in range(n):
if V[i]:
continue
cur = i
S = 0
m = VMAX
an = 0
while True:
V[cur] = True
an += 1
v = A[cur]
m = min(m, v)
S += v
cur = T[v]
if V[cur]:
break
ans += min(S + (an - 2) * m, m + S + (an + 1) * s)
return ans
print((solve()))
| 30 | 30 | 651 | 651 | MAX = 1000
VMAX = 10000
n = int(eval(input()))
A = [int(i) for i in input().split()]
V = [False] * MAX
def solve():
B = A[:]
T = [0] * (VMAX + 1)
B.sort()
ans = 0
s = min(VMAX, min(A))
for i in range(n):
T[B[i]] = i
for i in range(n):
if V[i]:
continue
cur = i
S = 0
m = VMAX
an = 0
while True:
V[cur] = True
an += 1
v = A[cur]
m = min(m, v)
S += v
cur = T[v]
if V[cur]:
break
ans += min(S + (an - 2) * m, m + S + (an + 1) * s)
print(ans)
solve()
| VMAX = 10000
n = int(eval(input()))
A = list(map(int, input().split()))
s = min(A)
def solve():
ans = 0
V = [False] * n
B = sorted(A)
T = [0] * (VMAX + 1)
for i in range(n):
T[B[i]] = i
for i in range(n):
if V[i]:
continue
cur = i
S = 0
m = VMAX
an = 0
while True:
V[cur] = True
an += 1
v = A[cur]
m = min(m, v)
S += v
cur = T[v]
if V[cur]:
break
ans += min(S + (an - 2) * m, m + S + (an + 1) * s)
return ans
print((solve()))
| false | 0 | [
"-MAX = 1000",
"-A = [int(i) for i in input().split()]",
"-V = [False] * MAX",
"+A = list(map(int, input().split()))",
"+s = min(A)",
"- B = A[:]",
"+ ans = 0",
"+ V = [False] * n",
"+ B = sorted(A)",
"- B.sort()",
"- ans = 0",
"- s = min(VMAX, min(A))",
"- print(ans)",
"+ return ans",
"-solve()",
"+print((solve()))"
] | false | 0.041111 | 0.057368 | 0.716624 | [
"s608344872",
"s370895847"
] |
u046592970 | p02996 | python | s030520646 | s620480323 | 1,029 | 938 | 55,264 | 55,268 | Accepted | Accepted | 8.84 | n = int(eval(input()))
lis = sorted([list(map(int,input().split())) for _ in range(n)], key = lambda z:z[1])
t = 0
ans = "Yes"
for i in lis:
t += i[0]
if t > i[1]:
ans = "No"
print(ans) | from operator import itemgetter
n = int(eval(input()))
lis =sorted([list(map(int,input().split())) for _ in range(n)], key = itemgetter(1))
t = 0
ans = "Yes"
for i in lis:
t += i[0]
if t > i[1]:
ans = "No"
print(ans) | 9 | 10 | 203 | 235 | n = int(eval(input()))
lis = sorted([list(map(int, input().split())) for _ in range(n)], key=lambda z: z[1])
t = 0
ans = "Yes"
for i in lis:
t += i[0]
if t > i[1]:
ans = "No"
print(ans)
| from operator import itemgetter
n = int(eval(input()))
lis = sorted([list(map(int, input().split())) for _ in range(n)], key=itemgetter(1))
t = 0
ans = "Yes"
for i in lis:
t += i[0]
if t > i[1]:
ans = "No"
print(ans)
| false | 10 | [
"+from operator import itemgetter",
"+",
"-lis = sorted([list(map(int, input().split())) for _ in range(n)], key=lambda z: z[1])",
"+lis = sorted([list(map(int, input().split())) for _ in range(n)], key=itemgetter(1))"
] | false | 0.037646 | 0.062204 | 0.605213 | [
"s030520646",
"s620480323"
] |
u879309973 | p02852 | python | s687983353 | s016506926 | 121 | 93 | 11,244 | 11,228 | Accepted | Accepted | 23.14 | def solve(n, m, s):
cnt = 0
for i in range(1, n+1):
if (s[i-1] == "0") and (s[i] == "1"):
cnt = 1
elif (s[i-1] == "1") and (s[i] == "1"):
cnt += 1
if cnt >= m:
return -1
s = s[::-1]
i = 0
path = []
while i < n:
for j in range(min(m, n-i), 0, -1):
ni = i+j
if s[ni] == "0":
i = ni
path.append(j)
break
return " ".join(map(str, path[::-1]))
n, m = list(map(int, input().split()))
s = eval(input())
print((solve(n, m, s))) | def solve(n, m, s):
if s.find("1"*m) >= 0:
return -1
s = s[::-1]
i = 0
path = []
while i < n:
for j in range(min(m, n-i), 0, -1):
ni = i+j
if s[ni] == "0":
i = ni
path.append(j)
break
return " ".join(map(str, path[::-1]))
n, m = list(map(int, input().split()))
s = eval(input())
print((solve(n, m, s))) | 24 | 18 | 597 | 419 | def solve(n, m, s):
cnt = 0
for i in range(1, n + 1):
if (s[i - 1] == "0") and (s[i] == "1"):
cnt = 1
elif (s[i - 1] == "1") and (s[i] == "1"):
cnt += 1
if cnt >= m:
return -1
s = s[::-1]
i = 0
path = []
while i < n:
for j in range(min(m, n - i), 0, -1):
ni = i + j
if s[ni] == "0":
i = ni
path.append(j)
break
return " ".join(map(str, path[::-1]))
n, m = list(map(int, input().split()))
s = eval(input())
print((solve(n, m, s)))
| def solve(n, m, s):
if s.find("1" * m) >= 0:
return -1
s = s[::-1]
i = 0
path = []
while i < n:
for j in range(min(m, n - i), 0, -1):
ni = i + j
if s[ni] == "0":
i = ni
path.append(j)
break
return " ".join(map(str, path[::-1]))
n, m = list(map(int, input().split()))
s = eval(input())
print((solve(n, m, s)))
| false | 25 | [
"- cnt = 0",
"- for i in range(1, n + 1):",
"- if (s[i - 1] == \"0\") and (s[i] == \"1\"):",
"- cnt = 1",
"- elif (s[i - 1] == \"1\") and (s[i] == \"1\"):",
"- cnt += 1",
"- if cnt >= m:",
"- return -1",
"+ if s.find(\"1\" * m) >= 0:",
"+ return -1"
] | false | 0.046138 | 0.116475 | 0.396122 | [
"s687983353",
"s016506926"
] |
u289876798 | p03457 | python | s328507229 | s759587795 | 374 | 327 | 11,816 | 3,188 | Accepted | Accepted | 12.57 | #! env python
# -*- coding: utf-8 -*-
import os
import sys
# at_coder.ABC086C_Traveling
# Date: 2019/06/02
# Filename: ABC086C_Traveling
__author__ = 'acto_mini'
__date__ = "2019/06/02"
def main():
# 作業ディレクトリを自身のファイルのディレクトリに変更
os.chdir(os.path.dirname(os.path.abspath(sys.argv[0])))
t, x, y = [0], [0], [0]
# 整数の入力
num = int(eval(input()))
for i in range(num):
a, b, c = list(map(int, input().split()))
t.append(a)
x.append(b)
y.append(c)
can = True
for i in range(num):
dt = t[i + 1] - t[i]
dist = abs(x[i + 1] - x[i]) + abs(y[i + 1] - y[i])
if (dt < dist):
can = False
if (dt % 2 != dist % 2):
can = False
if can:
print("Yes")
else:
print("No")
return
if __name__ == '__main__':
main()
| #! env python
# -*- coding: utf-8 -*-
import os
import sys
# ac_py.main.py
# Date: 2020/06/08
# Filename: main.py
__author__ = 'acto_mini'
__date__ = "2020/06/08"
def main():
n = int(eval(input()))
t_prev = 0
x_prev = 0
y_prev = 0
for i in range(n):
t, x, y = list(map(int, input().split()))
dt = t - t_prev
dist = abs(x - x_prev) + abs(y - y_prev)
if dt < dist or ((dt % 2) != (dist % 2)):
print("No")
exit()
t_prev, x_prev, y_prev = t, x, y
print("Yes")
return
if __name__ == '__main__':
main()
| 48 | 34 | 889 | 623 | #! env python
# -*- coding: utf-8 -*-
import os
import sys
# at_coder.ABC086C_Traveling
# Date: 2019/06/02
# Filename: ABC086C_Traveling
__author__ = "acto_mini"
__date__ = "2019/06/02"
def main():
# 作業ディレクトリを自身のファイルのディレクトリに変更
os.chdir(os.path.dirname(os.path.abspath(sys.argv[0])))
t, x, y = [0], [0], [0]
# 整数の入力
num = int(eval(input()))
for i in range(num):
a, b, c = list(map(int, input().split()))
t.append(a)
x.append(b)
y.append(c)
can = True
for i in range(num):
dt = t[i + 1] - t[i]
dist = abs(x[i + 1] - x[i]) + abs(y[i + 1] - y[i])
if dt < dist:
can = False
if dt % 2 != dist % 2:
can = False
if can:
print("Yes")
else:
print("No")
return
if __name__ == "__main__":
main()
| #! env python
# -*- coding: utf-8 -*-
import os
import sys
# ac_py.main.py
# Date: 2020/06/08
# Filename: main.py
__author__ = "acto_mini"
__date__ = "2020/06/08"
def main():
n = int(eval(input()))
t_prev = 0
x_prev = 0
y_prev = 0
for i in range(n):
t, x, y = list(map(int, input().split()))
dt = t - t_prev
dist = abs(x - x_prev) + abs(y - y_prev)
if dt < dist or ((dt % 2) != (dist % 2)):
print("No")
exit()
t_prev, x_prev, y_prev = t, x, y
print("Yes")
return
if __name__ == "__main__":
main()
| false | 29.166667 | [
"-# at_coder.ABC086C_Traveling",
"-# Date: 2019/06/02",
"-# Filename: ABC086C_Traveling",
"+# ac_py.main.py",
"+# Date: 2020/06/08",
"+# Filename: main.py",
"-__date__ = \"2019/06/02\"",
"+__date__ = \"2020/06/08\"",
"- # 作業ディレクトリを自身のファイルのディレクトリに変更",
"- os.chdir(os.path.dirname(os.path.abspath(sys.argv[0])))",
"- t, x, y = [0], [0], [0]",
"- # 整数の入力",
"- num = int(eval(input()))",
"- for i in range(num):",
"- a, b, c = list(map(int, input().split()))",
"- t.append(a)",
"- x.append(b)",
"- y.append(c)",
"- can = True",
"- for i in range(num):",
"- dt = t[i + 1] - t[i]",
"- dist = abs(x[i + 1] - x[i]) + abs(y[i + 1] - y[i])",
"- if dt < dist:",
"- can = False",
"- if dt % 2 != dist % 2:",
"- can = False",
"- if can:",
"- print(\"Yes\")",
"- else:",
"- print(\"No\")",
"+ n = int(eval(input()))",
"+ t_prev = 0",
"+ x_prev = 0",
"+ y_prev = 0",
"+ for i in range(n):",
"+ t, x, y = list(map(int, input().split()))",
"+ dt = t - t_prev",
"+ dist = abs(x - x_prev) + abs(y - y_prev)",
"+ if dt < dist or ((dt % 2) != (dist % 2)):",
"+ print(\"No\")",
"+ exit()",
"+ t_prev, x_prev, y_prev = t, x, y",
"+ print(\"Yes\")"
] | false | 0.045517 | 0.045067 | 1.009981 | [
"s328507229",
"s759587795"
] |
u077025302 | p03363 | python | s204070134 | s765589368 | 234 | 207 | 26,136 | 41,196 | Accepted | Accepted | 11.54 | n = int(eval(input()))
a = list(map(int,input().split()))
list_S = [0]
ans = 0
for i in range(n):
list_S.append(list_S[i] + a[i])
list_S.sort() # 昇順に並び替え 計算量はO(NlogN)
pre = list_S[0] # 前の数字
acc = 1 # 今まで何個同じ数字が連続したか
for i in range(1,n+1): # i番目の数字を見る.ちなみに0番目の数字は上2行でもう見た
if list_S[i] == pre: # 今見ている数字が前の数字と同じなら,accに1加算
acc += 1
else: # 違うなら,ansに(acc個の中から2個選ぶ場合の数)を加算
ans += acc * (acc-1) // 2
pre = list_S[i]
acc = 1 # accを初期化
ans += acc * (acc-1) // 2 # 一番最後に連続している数字群を足せていないので,ここで補正
print(ans)
| n = int(eval(input()))
a = list(map(int,input().split()))
list_S = [0]
ans = 0
for i in range(n):
list_S.append(list_S[i] + a[i])
dict_S = {}
for i in list_S:
if i in dict_S:
dict_S[i] += 1
else:
dict_S[i] = 1
for v in list(dict_S.values()):
ans += v * (v-1) // 2
print(ans) | 22 | 18 | 564 | 314 | n = int(eval(input()))
a = list(map(int, input().split()))
list_S = [0]
ans = 0
for i in range(n):
list_S.append(list_S[i] + a[i])
list_S.sort() # 昇順に並び替え 計算量はO(NlogN)
pre = list_S[0] # 前の数字
acc = 1 # 今まで何個同じ数字が連続したか
for i in range(1, n + 1): # i番目の数字を見る.ちなみに0番目の数字は上2行でもう見た
if list_S[i] == pre: # 今見ている数字が前の数字と同じなら,accに1加算
acc += 1
else: # 違うなら,ansに(acc個の中から2個選ぶ場合の数)を加算
ans += acc * (acc - 1) // 2
pre = list_S[i]
acc = 1 # accを初期化
ans += acc * (acc - 1) // 2 # 一番最後に連続している数字群を足せていないので,ここで補正
print(ans)
| n = int(eval(input()))
a = list(map(int, input().split()))
list_S = [0]
ans = 0
for i in range(n):
list_S.append(list_S[i] + a[i])
dict_S = {}
for i in list_S:
if i in dict_S:
dict_S[i] += 1
else:
dict_S[i] = 1
for v in list(dict_S.values()):
ans += v * (v - 1) // 2
print(ans)
| false | 18.181818 | [
"-list_S.sort() # 昇順に並び替え 計算量はO(NlogN)",
"-pre = list_S[0] # 前の数字",
"-acc = 1 # 今まで何個同じ数字が連続したか",
"-for i in range(1, n + 1): # i番目の数字を見る.ちなみに0番目の数字は上2行でもう見た",
"- if list_S[i] == pre: # 今見ている数字が前の数字と同じなら,accに1加算",
"- acc += 1",
"- else: # 違うなら,ansに(acc個の中から2個選ぶ場合の数)を加算",
"- ans += acc * (acc - 1) // 2",
"- pre = list_S[i]",
"- acc = 1 # accを初期化",
"-ans += acc * (acc - 1) // 2 # 一番最後に連続している数字群を足せていないので,ここで補正",
"+dict_S = {}",
"+for i in list_S:",
"+ if i in dict_S:",
"+ dict_S[i] += 1",
"+ else:",
"+ dict_S[i] = 1",
"+for v in list(dict_S.values()):",
"+ ans += v * (v - 1) // 2"
] | false | 0.105142 | 0.046125 | 2.279503 | [
"s204070134",
"s765589368"
] |
u597374218 | p02959 | python | s126351596 | s858030929 | 180 | 163 | 18,476 | 19,116 | Accepted | Accepted | 9.44 | N=int(eval(input()))
A=list(map(int,input().split()))
B=list(map(int,input().split()))
count=0
for i in range(N):
count+=min(A[i],B[i])
if A[i]<B[i]:
if A[i+1]<B[i]-A[i]:
count+=A[i+1]
A[i+1]=0
else:
count+=B[i]-A[i]
A[i+1]-=B[i]-A[i]
print(count) | N=int(eval(input()))
A=list(map(int,input().split()))
B=list(map(int,input().split()))
count=0
for i,b in enumerate(B):
attack=min(b,A[i]+A[i+1])
count+=attack
A[i+1]-=max(0,attack-A[i])
print(count) | 14 | 9 | 326 | 213 | N = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
count = 0
for i in range(N):
count += min(A[i], B[i])
if A[i] < B[i]:
if A[i + 1] < B[i] - A[i]:
count += A[i + 1]
A[i + 1] = 0
else:
count += B[i] - A[i]
A[i + 1] -= B[i] - A[i]
print(count)
| N = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
count = 0
for i, b in enumerate(B):
attack = min(b, A[i] + A[i + 1])
count += attack
A[i + 1] -= max(0, attack - A[i])
print(count)
| false | 35.714286 | [
"-for i in range(N):",
"- count += min(A[i], B[i])",
"- if A[i] < B[i]:",
"- if A[i + 1] < B[i] - A[i]:",
"- count += A[i + 1]",
"- A[i + 1] = 0",
"- else:",
"- count += B[i] - A[i]",
"- A[i + 1] -= B[i] - A[i]",
"+for i, b in enumerate(B):",
"+ attack = min(b, A[i] + A[i + 1])",
"+ count += attack",
"+ A[i + 1] -= max(0, attack - A[i])"
] | false | 0.043755 | 0.076591 | 0.571283 | [
"s126351596",
"s858030929"
] |
u002459665 | p02756 | python | s680105934 | s526928341 | 645 | 481 | 26,288 | 44,644 | Accepted | Accepted | 25.43 | S = eval(input())
Q = int(eval(input()))
QUERY = []
for i in range(Q):
# q = list(map(int, input().split()))
q = input().split()
if q[0] == '1':
QUERY.append([int(q[0])])
else:
QUERY.append([int(q[0]), int(q[1]), q[2]])
st = []
en = []
rev = False
rev_c = 0
for q in QUERY:
if q[0] == 1:
if rev:
rev = False
else:
rev = True
rev_c += 1
else:
if q[1] == 1:
if not rev:
st.append(q[2])
else:
en.append(q[2])
else:
if not rev:
en.append(q[2])
else:
st.append(q[2])
# print(st)
# print(en)
st_s = "".join(st)
st_s = st_s[::-1]
en_s = "".join(en)
ans = st_s + S + en_s
if rev_c % 2 == 0:
pass
else:
ans = ans[::-1]
print(ans) | S = eval(input())
Q = int(eval(input()))
QUERY = []
for i in range(Q):
q = input().split()
QUERY.append(q)
from collections import deque
l = deque(list(S))
# print(l)
rev = 0
for qi in QUERY:
if qi[0] == '1':
rev += 1
else:
if rev % 2 == 0:
if qi[1] == '1':
l.appendleft(qi[2])
else:
l.append(qi[2])
else:
if qi[1] == '1':
l.append(qi[2])
else:
l.appendleft(qi[2])
# print(l)
ans = "".join(l)
# print(ans)
if rev % 2 != 0:
ans = ans[::-1]
print(ans) | 48 | 35 | 884 | 632 | S = eval(input())
Q = int(eval(input()))
QUERY = []
for i in range(Q):
# q = list(map(int, input().split()))
q = input().split()
if q[0] == "1":
QUERY.append([int(q[0])])
else:
QUERY.append([int(q[0]), int(q[1]), q[2]])
st = []
en = []
rev = False
rev_c = 0
for q in QUERY:
if q[0] == 1:
if rev:
rev = False
else:
rev = True
rev_c += 1
else:
if q[1] == 1:
if not rev:
st.append(q[2])
else:
en.append(q[2])
else:
if not rev:
en.append(q[2])
else:
st.append(q[2])
# print(st)
# print(en)
st_s = "".join(st)
st_s = st_s[::-1]
en_s = "".join(en)
ans = st_s + S + en_s
if rev_c % 2 == 0:
pass
else:
ans = ans[::-1]
print(ans)
| S = eval(input())
Q = int(eval(input()))
QUERY = []
for i in range(Q):
q = input().split()
QUERY.append(q)
from collections import deque
l = deque(list(S))
# print(l)
rev = 0
for qi in QUERY:
if qi[0] == "1":
rev += 1
else:
if rev % 2 == 0:
if qi[1] == "1":
l.appendleft(qi[2])
else:
l.append(qi[2])
else:
if qi[1] == "1":
l.append(qi[2])
else:
l.appendleft(qi[2])
# print(l)
ans = "".join(l)
# print(ans)
if rev % 2 != 0:
ans = ans[::-1]
print(ans)
| false | 27.083333 | [
"- # q = list(map(int, input().split()))",
"- if q[0] == \"1\":",
"- QUERY.append([int(q[0])])",
"+ QUERY.append(q)",
"+from collections import deque",
"+",
"+l = deque(list(S))",
"+# print(l)",
"+rev = 0",
"+for qi in QUERY:",
"+ if qi[0] == \"1\":",
"+ rev += 1",
"- QUERY.append([int(q[0]), int(q[1]), q[2]])",
"-st = []",
"-en = []",
"-rev = False",
"-rev_c = 0",
"-for q in QUERY:",
"- if q[0] == 1:",
"- if rev:",
"- rev = False",
"+ if rev % 2 == 0:",
"+ if qi[1] == \"1\":",
"+ l.appendleft(qi[2])",
"+ else:",
"+ l.append(qi[2])",
"- rev = True",
"- rev_c += 1",
"- else:",
"- if q[1] == 1:",
"- if not rev:",
"- st.append(q[2])",
"+ if qi[1] == \"1\":",
"+ l.append(qi[2])",
"- en.append(q[2])",
"- else:",
"- if not rev:",
"- en.append(q[2])",
"- else:",
"- st.append(q[2])",
"-# print(st)",
"-# print(en)",
"-st_s = \"\".join(st)",
"-st_s = st_s[::-1]",
"-en_s = \"\".join(en)",
"-ans = st_s + S + en_s",
"-if rev_c % 2 == 0:",
"- pass",
"-else:",
"+ l.appendleft(qi[2])",
"+# print(l)",
"+ans = \"\".join(l)",
"+# print(ans)",
"+if rev % 2 != 0:"
] | false | 0.044285 | 0.036759 | 1.204738 | [
"s680105934",
"s526928341"
] |
u914361753 | p03494 | python | s310452069 | s080981837 | 251 | 11 | 17,012 | 2,568 | Accepted | Accepted | 95.62 | import numpy as np
def IntLog2(N):
k = 0
while N%2 == 0:
k += 1
N /= 2
return k
N = input()
inputArray = list(map(int, input().split()))
Log2_inputArray = [IntLog2(n) for n in inputArray]
print(min(Log2_inputArray)) | def SolveABC081B(array):
print(max(j for j in range(32) if all(i % 2**j == 0 for i in array)))
eval(input())
inputArray = list(map(int, input().split()))
SolveABC081B(inputArray) | 12 | 6 | 256 | 183 | import numpy as np
def IntLog2(N):
k = 0
while N % 2 == 0:
k += 1
N /= 2
return k
N = input()
inputArray = list(map(int, input().split()))
Log2_inputArray = [IntLog2(n) for n in inputArray]
print(min(Log2_inputArray))
| def SolveABC081B(array):
print(max(j for j in range(32) if all(i % 2**j == 0 for i in array)))
eval(input())
inputArray = list(map(int, input().split()))
SolveABC081B(inputArray)
| false | 50 | [
"-import numpy as np",
"+def SolveABC081B(array):",
"+ print(max(j for j in range(32) if all(i % 2**j == 0 for i in array)))",
"-def IntLog2(N):",
"- k = 0",
"- while N % 2 == 0:",
"- k += 1",
"- N /= 2",
"- return k",
"-",
"-",
"-N = input()",
"+eval(input())",
"-Log2_inputArray = [IntLog2(n) for n in inputArray]",
"-print(min(Log2_inputArray))",
"+SolveABC081B(inputArray)"
] | false | 0.084427 | 0.036585 | 2.307694 | [
"s310452069",
"s080981837"
] |
u443512298 | p03944 | python | s865489152 | s649255609 | 24 | 22 | 3,064 | 3,064 | Accepted | Accepted | 8.33 | # coding: utf-8
"""Snuke's Coloring 2 (ABC Edit)
@author: hijiri.n
@modified: 11-19-2016
"""
def data(): return list(map(int, input().split()))
def solve(init, point):
w, h, N = init
rect = [0, w, 0, h]
for p in point:
x, y, a = p
if [1, -1][a % 2] * ([x, y][a > 2] - rect[a - 1]) < 0:
rect[a - 1] = [x, y][a > 2]
if (rect[1] <= rect[0]) if a <= 2 else (rect[3] <= rect[2]):
return 0
return (rect[1] - rect[0]) * (rect[3] - rect[2])
# Input init & points data
i_in = data()
p_in = [data() for _ in range(i_in[-1])]
print((solve(i_in, p_in))) | # coding: utf-8
"""Snuke's Coloring 2 (ABC Edit)
@author: hijiri.n
@modified: 11-19-2016
"""
def data(): return list(map(int, input().split()))
def solve(init, point):
w, h, N = init
rect = [0, w, 0, h]
for p in point:
x, y, a = p
rect[a - 1] = [min, max][a % 2](rect[a - 1], [x, y][a > 2])
if rect[1] <= rect[0] or rect[3] <= rect[2]:
return 0
return (rect[1] - rect[0]) * (rect[3] - rect[2])
# Input init & points data
i_in = data()
p_in = [data() for _ in range(i_in[-1])]
print((solve(i_in, p_in))) | 30 | 29 | 650 | 607 | # coding: utf-8
"""Snuke's Coloring 2 (ABC Edit)
@author: hijiri.n
@modified: 11-19-2016
"""
def data():
return list(map(int, input().split()))
def solve(init, point):
w, h, N = init
rect = [0, w, 0, h]
for p in point:
x, y, a = p
if [1, -1][a % 2] * ([x, y][a > 2] - rect[a - 1]) < 0:
rect[a - 1] = [x, y][a > 2]
if (rect[1] <= rect[0]) if a <= 2 else (rect[3] <= rect[2]):
return 0
return (rect[1] - rect[0]) * (rect[3] - rect[2])
# Input init & points data
i_in = data()
p_in = [data() for _ in range(i_in[-1])]
print((solve(i_in, p_in)))
| # coding: utf-8
"""Snuke's Coloring 2 (ABC Edit)
@author: hijiri.n
@modified: 11-19-2016
"""
def data():
return list(map(int, input().split()))
def solve(init, point):
w, h, N = init
rect = [0, w, 0, h]
for p in point:
x, y, a = p
rect[a - 1] = [min, max][a % 2](rect[a - 1], [x, y][a > 2])
if rect[1] <= rect[0] or rect[3] <= rect[2]:
return 0
return (rect[1] - rect[0]) * (rect[3] - rect[2])
# Input init & points data
i_in = data()
p_in = [data() for _ in range(i_in[-1])]
print((solve(i_in, p_in)))
| false | 3.333333 | [
"- if [1, -1][a % 2] * ([x, y][a > 2] - rect[a - 1]) < 0:",
"- rect[a - 1] = [x, y][a > 2]",
"- if (rect[1] <= rect[0]) if a <= 2 else (rect[3] <= rect[2]):",
"+ rect[a - 1] = [min, max][a % 2](rect[a - 1], [x, y][a > 2])",
"+ if rect[1] <= rect[0] or rect[3] <= rect[2]:"
] | false | 0.04889 | 0.113 | 0.432658 | [
"s865489152",
"s649255609"
] |
u729133443 | p03266 | python | s674238835 | s077694581 | 169 | 17 | 40,048 | 2,940 | Accepted | Accepted | 89.94 | n,k=list(map(int,input().split()))
m=[0]*k
for i in range(1,n+1):m[i%k]+=1
print((m[0]**3+[m[k//2]**3,0][k%2])) | n,k=list(map(int,input().split()));print(((n//k)**3+[((n-k//2)//k+1)**3,0][k%2])) | 4 | 1 | 106 | 73 | n, k = list(map(int, input().split()))
m = [0] * k
for i in range(1, n + 1):
m[i % k] += 1
print((m[0] ** 3 + [m[k // 2] ** 3, 0][k % 2]))
| n, k = list(map(int, input().split()))
print(((n // k) ** 3 + [((n - k // 2) // k + 1) ** 3, 0][k % 2]))
| false | 75 | [
"-m = [0] * k",
"-for i in range(1, n + 1):",
"- m[i % k] += 1",
"-print((m[0] ** 3 + [m[k // 2] ** 3, 0][k % 2]))",
"+print(((n // k) ** 3 + [((n - k // 2) // k + 1) ** 3, 0][k % 2]))"
] | false | 0.082571 | 0.045407 | 1.818489 | [
"s674238835",
"s077694581"
] |
u347203174 | p03829 | python | s846763478 | s880158870 | 95 | 84 | 85,040 | 85,464 | Accepted | Accepted | 11.58 | N, A, B = list(map(int, input().split()))
town = list(map(int, input().split()))
diff = [0]*(N+1)
for i in range(1, N):
diff[i] = town[i] - town[i-1]
sumz = 0
for i in range(1, N+1):
if diff[i]*A > B:
sumz += B
else:
sumz += diff[i]*A
print(sumz)
| N, A, B = list(map(int, input().split()))
num = list(map(int, input().split()))
ans = 0
for i in range(1, N):
d = num[i] - num[i-1]
if d*A < B:
ans += d*A
else:
ans += B
print(ans)
| 15 | 12 | 286 | 215 | N, A, B = list(map(int, input().split()))
town = list(map(int, input().split()))
diff = [0] * (N + 1)
for i in range(1, N):
diff[i] = town[i] - town[i - 1]
sumz = 0
for i in range(1, N + 1):
if diff[i] * A > B:
sumz += B
else:
sumz += diff[i] * A
print(sumz)
| N, A, B = list(map(int, input().split()))
num = list(map(int, input().split()))
ans = 0
for i in range(1, N):
d = num[i] - num[i - 1]
if d * A < B:
ans += d * A
else:
ans += B
print(ans)
| false | 20 | [
"-town = list(map(int, input().split()))",
"-diff = [0] * (N + 1)",
"+num = list(map(int, input().split()))",
"+ans = 0",
"- diff[i] = town[i] - town[i - 1]",
"-sumz = 0",
"-for i in range(1, N + 1):",
"- if diff[i] * A > B:",
"- sumz += B",
"+ d = num[i] - num[i - 1]",
"+ if d * A < B:",
"+ ans += d * A",
"- sumz += diff[i] * A",
"-print(sumz)",
"+ ans += B",
"+print(ans)"
] | false | 0.06808 | 0.113178 | 0.601531 | [
"s846763478",
"s880158870"
] |
u203843959 | p02983 | python | s319876975 | s878638227 | 842 | 684 | 3,064 | 3,064 | Accepted | Accepted | 18.76 | import sys
L,R=list(map(int,input().split()))
if R-L>2017:
print((0))
sys.exit()
L%=2019
while(R-L>2019):
R-=2019
#print(L,R)
answer=10**10
for i in range(L,R):
for j in range(i+1,R+1):
answer=min(answer,(i*j)%2019)
print(answer) | L,R=list(map(int,input().split()))
if L//2019 != R//2019:
print((0))
else:
L%=2019
R%=2019
answer=10**10
for i in range(L,R):
for j in range(i+1,R+1):
answer=min(answer,(i*j)%2019)
print(answer) | 18 | 14 | 260 | 232 | import sys
L, R = list(map(int, input().split()))
if R - L > 2017:
print((0))
sys.exit()
L %= 2019
while R - L > 2019:
R -= 2019
# print(L,R)
answer = 10**10
for i in range(L, R):
for j in range(i + 1, R + 1):
answer = min(answer, (i * j) % 2019)
print(answer)
| L, R = list(map(int, input().split()))
if L // 2019 != R // 2019:
print((0))
else:
L %= 2019
R %= 2019
answer = 10**10
for i in range(L, R):
for j in range(i + 1, R + 1):
answer = min(answer, (i * j) % 2019)
print(answer)
| false | 22.222222 | [
"-import sys",
"-",
"-if R - L > 2017:",
"+if L // 2019 != R // 2019:",
"- sys.exit()",
"-L %= 2019",
"-while R - L > 2019:",
"- R -= 2019",
"-# print(L,R)",
"-answer = 10**10",
"-for i in range(L, R):",
"- for j in range(i + 1, R + 1):",
"- answer = min(answer, (i * j) % 2019)",
"-print(answer)",
"+else:",
"+ L %= 2019",
"+ R %= 2019",
"+ answer = 10**10",
"+ for i in range(L, R):",
"+ for j in range(i + 1, R + 1):",
"+ answer = min(answer, (i * j) % 2019)",
"+ print(answer)"
] | false | 0.048074 | 0.043642 | 1.101555 | [
"s319876975",
"s878638227"
] |
u014333473 | p04043 | python | s644653229 | s636538587 | 27 | 24 | 9,068 | 8,908 | Accepted | Accepted | 11.11 | a,b,c=list(map(int,input().split()));print((['NO','YES'][max(a,b,c)==7 and (a+b+c)-max(a,b,c)==10])) | a=input().replace('5','');print(('NYOE S'[a.count('7')==1::2])) | 1 | 1 | 92 | 61 | a, b, c = list(map(int, input().split()))
print((["NO", "YES"][max(a, b, c) == 7 and (a + b + c) - max(a, b, c) == 10]))
| a = input().replace("5", "")
print(("NYOE S"[a.count("7") == 1 :: 2]))
| false | 0 | [
"-a, b, c = list(map(int, input().split()))",
"-print(([\"NO\", \"YES\"][max(a, b, c) == 7 and (a + b + c) - max(a, b, c) == 10]))",
"+a = input().replace(\"5\", \"\")",
"+print((\"NYOE S\"[a.count(\"7\") == 1 :: 2]))"
] | false | 0.041731 | 0.040699 | 1.025359 | [
"s644653229",
"s636538587"
] |
u476383383 | p02995 | python | s190848365 | s639235193 | 35 | 17 | 5,048 | 3,060 | Accepted | Accepted | 51.43 | from fractions import gcd
a, b, c, d = list(map(int, input().split()))
lcm = c*d // gcd(c,d)
def calc(x):
return x-(x//c)-(x//d)+(x//lcm)
print((calc(b)-calc(a-1))) | import sys
input = sys.stdin.readline
a, b, c, d = list(map(int, input().split()))
def gcd(a,b):
while b:
a, b = b, a%b
return a
def lcm(a,b):
return a*b//gcd(a,b)
def calc(x):
return x-(x//c)-(x//d)+(x//lcm(c,d))
print((calc(b)-calc(a-1))) | 9 | 16 | 171 | 275 | from fractions import gcd
a, b, c, d = list(map(int, input().split()))
lcm = c * d // gcd(c, d)
def calc(x):
return x - (x // c) - (x // d) + (x // lcm)
print((calc(b) - calc(a - 1)))
| import sys
input = sys.stdin.readline
a, b, c, d = list(map(int, input().split()))
def gcd(a, b):
while b:
a, b = b, a % b
return a
def lcm(a, b):
return a * b // gcd(a, b)
def calc(x):
return x - (x // c) - (x // d) + (x // lcm(c, d))
print((calc(b) - calc(a - 1)))
| false | 43.75 | [
"-from fractions import gcd",
"+import sys",
"+input = sys.stdin.readline",
"-lcm = c * d // gcd(c, d)",
"+",
"+",
"+def gcd(a, b):",
"+ while b:",
"+ a, b = b, a % b",
"+ return a",
"+",
"+",
"+def lcm(a, b):",
"+ return a * b // gcd(a, b)",
"- return x - (x // c) - (x // d) + (x // lcm)",
"+ return x - (x // c) - (x // d) + (x // lcm(c, d))"
] | false | 0.047655 | 0.044034 | 1.082237 | [
"s190848365",
"s639235193"
] |
u155236040 | p03804 | python | s996162472 | s988373982 | 21 | 19 | 3,064 | 3,064 | Accepted | Accepted | 9.52 | n,m = list(map(int,input().split()))
a_list = [eval(input()) for _ in range(n)]
b_list = [eval(input()) for _ in range(m)]
count = 0
res = []
for i in range(n-m+1):
for j in range(n-m+1):
f = True
for k in range(m):
for l in range(m):
if a_list[i+k][j+l] != b_list[k][l]:
f = False
break
if not f:
break
if f:
print('Yes')
exit()
print('No') | n,m = list(map(int,input().split()))
a_list = [eval(input()) for _ in range(n)]
b_list = [eval(input()) for _ in range(m)]
for i in range(n-m+1):
for j in range(n-m+1):
f = True
for k in range(m):
for l in range(m):
if a_list[i+k][j+l] != b_list[k][l]:
f = False
break
if not f:
break
if f:
print('Yes')
exit()
print('No') | 19 | 17 | 489 | 468 | n, m = list(map(int, input().split()))
a_list = [eval(input()) for _ in range(n)]
b_list = [eval(input()) for _ in range(m)]
count = 0
res = []
for i in range(n - m + 1):
for j in range(n - m + 1):
f = True
for k in range(m):
for l in range(m):
if a_list[i + k][j + l] != b_list[k][l]:
f = False
break
if not f:
break
if f:
print("Yes")
exit()
print("No")
| n, m = list(map(int, input().split()))
a_list = [eval(input()) for _ in range(n)]
b_list = [eval(input()) for _ in range(m)]
for i in range(n - m + 1):
for j in range(n - m + 1):
f = True
for k in range(m):
for l in range(m):
if a_list[i + k][j + l] != b_list[k][l]:
f = False
break
if not f:
break
if f:
print("Yes")
exit()
print("No")
| false | 10.526316 | [
"-count = 0",
"-res = []"
] | false | 0.032768 | 0.036122 | 0.907165 | [
"s996162472",
"s988373982"
] |
u263830634 | p03610 | python | s234819152 | s672502465 | 71 | 34 | 5,292 | 6,048 | Accepted | Accepted | 52.11 | s = list(input())
for i in range(0, len(s), 2):
print (s[i], end='')
print ()
| import sys
# input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7
S = list(input())
print (*S[::2], sep = '')
| 5 | 8 | 87 | 141 | s = list(input())
for i in range(0, len(s), 2):
print(s[i], end="")
print()
| import sys
# input = sys.stdin.readline
sys.setrecursionlimit(10**9)
MOD = 10**9 + 7
S = list(input())
print(*S[::2], sep="")
| false | 37.5 | [
"-s = list(input())",
"-for i in range(0, len(s), 2):",
"- print(s[i], end=\"\")",
"-print()",
"+import sys",
"+",
"+# input = sys.stdin.readline",
"+sys.setrecursionlimit(10**9)",
"+MOD = 10**9 + 7",
"+S = list(input())",
"+print(*S[::2], sep=\"\")"
] | false | 0.07821 | 0.042685 | 1.832267 | [
"s234819152",
"s672502465"
] |
u055875839 | p03434 | python | s116734728 | s561536293 | 19 | 17 | 2,940 | 2,940 | Accepted | Accepted | 10.53 | num = int(eval(input()))
cards = sorted(list(map(int, input().split())), reverse = True)
alice = 0
bob = 0
for i in range(num):
if i//2*2 == i:
alice += cards[i]
else:
bob += cards[i]
print((alice - bob)) | N = int(eval(input()))
A = list(map(int, input().split()))
A = sorted(A, reverse = True)
dif = sum(A[0::2]) - sum(A[1::2])
print(dif) | 12 | 5 | 221 | 131 | num = int(eval(input()))
cards = sorted(list(map(int, input().split())), reverse=True)
alice = 0
bob = 0
for i in range(num):
if i // 2 * 2 == i:
alice += cards[i]
else:
bob += cards[i]
print((alice - bob))
| N = int(eval(input()))
A = list(map(int, input().split()))
A = sorted(A, reverse=True)
dif = sum(A[0::2]) - sum(A[1::2])
print(dif)
| false | 58.333333 | [
"-num = int(eval(input()))",
"-cards = sorted(list(map(int, input().split())), reverse=True)",
"-alice = 0",
"-bob = 0",
"-for i in range(num):",
"- if i // 2 * 2 == i:",
"- alice += cards[i]",
"- else:",
"- bob += cards[i]",
"-print((alice - bob))",
"+N = int(eval(input()))",
"+A = list(map(int, input().split()))",
"+A = sorted(A, reverse=True)",
"+dif = sum(A[0::2]) - sum(A[1::2])",
"+print(dif)"
] | false | 0.067379 | 0.066108 | 1.019224 | [
"s116734728",
"s561536293"
] |
u249372595 | p03087 | python | s454372280 | s169705671 | 450 | 242 | 18,068 | 88,532 | Accepted | Accepted | 46.22 | N,Q = list(map(int,input().split()))
S = eval(input())
left=[]
right=[]
for _ in range(Q):
l,r = list(map(int,input().split()))
left.append(l)
right.append(r)
a = [0]*N
for i in range(1,N):
if S[i] == "C" and S[i-1] == "A":
a[i] = a[i-1] + 1
else:
a[i] = a[i-1]
#print(a)
ans = []
for j in range(Q):
ans.append(a[right[j]-1] - a[left[j]-1])
for k in ans:
print(k) | N,Q = list(map(int,input().split()))
S = eval(input())
L = []
R = []
for i in range(Q):
l,r=list(map(int,input().split()))
L.append(l)
R.append(r)
dp = [0]*N
for j in range(N-1):
if S[j]=='A' and S[j+1]=='C':
dp[j+1] = dp[j]+1
else:
dp[j+1] = dp[j]
for k in range(Q):
print((dp[R[k]-1]-dp[L[k]-1])) | 23 | 18 | 392 | 329 | N, Q = list(map(int, input().split()))
S = eval(input())
left = []
right = []
for _ in range(Q):
l, r = list(map(int, input().split()))
left.append(l)
right.append(r)
a = [0] * N
for i in range(1, N):
if S[i] == "C" and S[i - 1] == "A":
a[i] = a[i - 1] + 1
else:
a[i] = a[i - 1]
# print(a)
ans = []
for j in range(Q):
ans.append(a[right[j] - 1] - a[left[j] - 1])
for k in ans:
print(k)
| N, Q = list(map(int, input().split()))
S = eval(input())
L = []
R = []
for i in range(Q):
l, r = list(map(int, input().split()))
L.append(l)
R.append(r)
dp = [0] * N
for j in range(N - 1):
if S[j] == "A" and S[j + 1] == "C":
dp[j + 1] = dp[j] + 1
else:
dp[j + 1] = dp[j]
for k in range(Q):
print((dp[R[k] - 1] - dp[L[k] - 1]))
| false | 21.73913 | [
"-left = []",
"-right = []",
"-for _ in range(Q):",
"+L = []",
"+R = []",
"+for i in range(Q):",
"- left.append(l)",
"- right.append(r)",
"-a = [0] * N",
"-for i in range(1, N):",
"- if S[i] == \"C\" and S[i - 1] == \"A\":",
"- a[i] = a[i - 1] + 1",
"+ L.append(l)",
"+ R.append(r)",
"+dp = [0] * N",
"+for j in range(N - 1):",
"+ if S[j] == \"A\" and S[j + 1] == \"C\":",
"+ dp[j + 1] = dp[j] + 1",
"- a[i] = a[i - 1]",
"-# print(a)",
"-ans = []",
"-for j in range(Q):",
"- ans.append(a[right[j] - 1] - a[left[j] - 1])",
"-for k in ans:",
"- print(k)",
"+ dp[j + 1] = dp[j]",
"+for k in range(Q):",
"+ print((dp[R[k] - 1] - dp[L[k] - 1]))"
] | false | 0.043682 | 0.038734 | 1.127735 | [
"s454372280",
"s169705671"
] |
u332385682 | p03703 | python | s806346722 | s333516064 | 1,322 | 1,201 | 52,216 | 24,548 | Accepted | Accepted | 9.15 | import sys
from itertools import accumulate
def solve():
n, k = list(map(int, sys.stdin.readline().split()))
a = [int(sys.stdin.readline().rstrip()) - k for i in range(n)]
s = [0] + list(accumulate(a))
# 座標圧縮
s = [(si, i) for (i, si) in enumerate(s)]
s.sort()
z = [None] * (n + 1)
num = -1
p = -float('inf')
for i in range(n + 1):
if s[i][0] > p:
num += 1
z[s[i][1]] = num
p = s[i][0]
# FenwickTreeで転倒数を数える
ft = FenwickTree(num + 1)
ans = 0
for zi in z:
ans += ft.psum(zi + 1)
ft.add(zi, 1)
print(ans)
class FenwickTree:
def __init__(self, n):
self.n = n
self.b = [0] * (n + 1)
def add(self, i, x):
i += 1
while i <= self.n:
self.b[i] += x
i += i & (-i)
def psum(self, r):
res = 0
while r > 0:
res += self.b[r]
r -= r & (-r)
return res
if __name__ == '__main__':
solve() | import sys
from itertools import accumulate
inf = 1<<60
ans = 0
def solve():
n, k = list(map(int, sys.stdin.readline().split()))
a = [int(sys.stdin.readline().rstrip()) - k for i in range(n)]
s = [0] + list(accumulate(a))
MergeSort(s)
print(ans)
def MergeSort(a):
if len(a) == 1:
return a
apre = MergeSort(a[:len(a)//2])
asuf = MergeSort(a[len(a)//2:])
res = merge(apre, asuf)
return res
def merge(a, b):
global ans
na = len(a)
nb = len(b)
a.append(-inf)
b.append(-inf)
la = 0
lb = 0
res = []
for i in range(na + nb):
if a[la] <= b[lb]:
ans += na - la
res.append(b[lb])
lb += 1
else:
res.append(a[la])
la += 1
return res
if __name__ == '__main__':
solve() | 58 | 52 | 1,070 | 883 | import sys
from itertools import accumulate
def solve():
n, k = list(map(int, sys.stdin.readline().split()))
a = [int(sys.stdin.readline().rstrip()) - k for i in range(n)]
s = [0] + list(accumulate(a))
# 座標圧縮
s = [(si, i) for (i, si) in enumerate(s)]
s.sort()
z = [None] * (n + 1)
num = -1
p = -float("inf")
for i in range(n + 1):
if s[i][0] > p:
num += 1
z[s[i][1]] = num
p = s[i][0]
# FenwickTreeで転倒数を数える
ft = FenwickTree(num + 1)
ans = 0
for zi in z:
ans += ft.psum(zi + 1)
ft.add(zi, 1)
print(ans)
class FenwickTree:
def __init__(self, n):
self.n = n
self.b = [0] * (n + 1)
def add(self, i, x):
i += 1
while i <= self.n:
self.b[i] += x
i += i & (-i)
def psum(self, r):
res = 0
while r > 0:
res += self.b[r]
r -= r & (-r)
return res
if __name__ == "__main__":
solve()
| import sys
from itertools import accumulate
inf = 1 << 60
ans = 0
def solve():
n, k = list(map(int, sys.stdin.readline().split()))
a = [int(sys.stdin.readline().rstrip()) - k for i in range(n)]
s = [0] + list(accumulate(a))
MergeSort(s)
print(ans)
def MergeSort(a):
if len(a) == 1:
return a
apre = MergeSort(a[: len(a) // 2])
asuf = MergeSort(a[len(a) // 2 :])
res = merge(apre, asuf)
return res
def merge(a, b):
global ans
na = len(a)
nb = len(b)
a.append(-inf)
b.append(-inf)
la = 0
lb = 0
res = []
for i in range(na + nb):
if a[la] <= b[lb]:
ans += na - la
res.append(b[lb])
lb += 1
else:
res.append(a[la])
la += 1
return res
if __name__ == "__main__":
solve()
| false | 10.344828 | [
"+",
"+inf = 1 << 60",
"+ans = 0",
"- # 座標圧縮",
"- s = [(si, i) for (i, si) in enumerate(s)]",
"- s.sort()",
"- z = [None] * (n + 1)",
"- num = -1",
"- p = -float(\"inf\")",
"- for i in range(n + 1):",
"- if s[i][0] > p:",
"- num += 1",
"- z[s[i][1]] = num",
"- p = s[i][0]",
"- # FenwickTreeで転倒数を数える",
"- ft = FenwickTree(num + 1)",
"- ans = 0",
"- for zi in z:",
"- ans += ft.psum(zi + 1)",
"- ft.add(zi, 1)",
"+ MergeSort(s)",
"-class FenwickTree:",
"- def __init__(self, n):",
"- self.n = n",
"- self.b = [0] * (n + 1)",
"+def MergeSort(a):",
"+ if len(a) == 1:",
"+ return a",
"+ apre = MergeSort(a[: len(a) // 2])",
"+ asuf = MergeSort(a[len(a) // 2 :])",
"+ res = merge(apre, asuf)",
"+ return res",
"- def add(self, i, x):",
"- i += 1",
"- while i <= self.n:",
"- self.b[i] += x",
"- i += i & (-i)",
"- def psum(self, r):",
"- res = 0",
"- while r > 0:",
"- res += self.b[r]",
"- r -= r & (-r)",
"- return res",
"+def merge(a, b):",
"+ global ans",
"+ na = len(a)",
"+ nb = len(b)",
"+ a.append(-inf)",
"+ b.append(-inf)",
"+ la = 0",
"+ lb = 0",
"+ res = []",
"+ for i in range(na + nb):",
"+ if a[la] <= b[lb]:",
"+ ans += na - la",
"+ res.append(b[lb])",
"+ lb += 1",
"+ else:",
"+ res.append(a[la])",
"+ la += 1",
"+ return res"
] | false | 0.04182 | 0.040962 | 1.020953 | [
"s806346722",
"s333516064"
] |
u517724953 | p02761 | python | s534414801 | s776633474 | 190 | 162 | 38,256 | 38,384 | Accepted | Accepted | 14.74 | n, m = map(int, input().split())
ans = [-1]*n
for i in range(m):
s, c = map(int, input().split())
if s == 1 and c == 0 and n != 1:
print(-1)
exit()
if ans[s-1] == -1 or ans[s-1] == c:
ans[s-1] = c
else:
print(-1)
exit()
if ans[0] == -1 and n != 1:
ans[0] = 1
for i in range(n):
if ans[i] == -1:
ans[i] = 0
print(*ans, sep="")
| n, m = map(int, input().split())
ans = [-1]*n
if n == 1 and m == 0:
print(0)
exit()
for i in range(m):
s, c = map(int, input().split())
if s == 1 and c == 0 and n != 1:
print(-1)
exit()
if ans[s-1] == -1 or ans[s-1] == c:
ans[s-1] = c
else:
print(-1)
exit()
if ans[0] == -1:
ans[0] = 1
for i in range(n):
if ans[i] == -1:
ans[i] = 0
print(*ans, sep="")
| 22 | 28 | 423 | 467 | n, m = map(int, input().split())
ans = [-1] * n
for i in range(m):
s, c = map(int, input().split())
if s == 1 and c == 0 and n != 1:
print(-1)
exit()
if ans[s - 1] == -1 or ans[s - 1] == c:
ans[s - 1] = c
else:
print(-1)
exit()
if ans[0] == -1 and n != 1:
ans[0] = 1
for i in range(n):
if ans[i] == -1:
ans[i] = 0
print(*ans, sep="")
| n, m = map(int, input().split())
ans = [-1] * n
if n == 1 and m == 0:
print(0)
exit()
for i in range(m):
s, c = map(int, input().split())
if s == 1 and c == 0 and n != 1:
print(-1)
exit()
if ans[s - 1] == -1 or ans[s - 1] == c:
ans[s - 1] = c
else:
print(-1)
exit()
if ans[0] == -1:
ans[0] = 1
for i in range(n):
if ans[i] == -1:
ans[i] = 0
print(*ans, sep="")
| false | 21.428571 | [
"+if n == 1 and m == 0:",
"+ print(0)",
"+ exit()",
"-if ans[0] == -1 and n != 1:",
"+if ans[0] == -1:"
] | false | 0.043843 | 0.109124 | 0.401774 | [
"s534414801",
"s776633474"
] |
u941407962 | p02844 | python | s901783168 | s868569810 | 506 | 61 | 41,052 | 3,572 | Accepted | Accepted | 87.94 | n = int(eval(input()))
S = str(eval(input()))
r = 0
for i in range(1000):
t = "{0:03d}".format(i)
j = 0
for c in S:
if t[j] == c:
j += 1
if j == 3:
r += 1
break
print(r)
| n,S,r=int(eval(input())),eval(input()),0
dp1=[0]*n
dp2=[0]*n
d=set()
for i, c in enumerate(S):
dp1[i] = len(d)
d.add(c)
cs = [0 for i in range(10)]
d=set()
for i, c in enumerate(S[::-1]):
dp2[i] = len(d)
r += dp1[n-i-1]*(dp2[i]-dp2[cs[int(c)]])
d.add(c)
cs[int(c)] = i
print(r)
| 13 | 16 | 234 | 306 | n = int(eval(input()))
S = str(eval(input()))
r = 0
for i in range(1000):
t = "{0:03d}".format(i)
j = 0
for c in S:
if t[j] == c:
j += 1
if j == 3:
r += 1
break
print(r)
| n, S, r = int(eval(input())), eval(input()), 0
dp1 = [0] * n
dp2 = [0] * n
d = set()
for i, c in enumerate(S):
dp1[i] = len(d)
d.add(c)
cs = [0 for i in range(10)]
d = set()
for i, c in enumerate(S[::-1]):
dp2[i] = len(d)
r += dp1[n - i - 1] * (dp2[i] - dp2[cs[int(c)]])
d.add(c)
cs[int(c)] = i
print(r)
| false | 18.75 | [
"-n = int(eval(input()))",
"-S = str(eval(input()))",
"-r = 0",
"-for i in range(1000):",
"- t = \"{0:03d}\".format(i)",
"- j = 0",
"- for c in S:",
"- if t[j] == c:",
"- j += 1",
"- if j == 3:",
"- r += 1",
"- break",
"+n, S, r = int(eval(input())), eval(input()), 0",
"+dp1 = [0] * n",
"+dp2 = [0] * n",
"+d = set()",
"+for i, c in enumerate(S):",
"+ dp1[i] = len(d)",
"+ d.add(c)",
"+cs = [0 for i in range(10)]",
"+d = set()",
"+for i, c in enumerate(S[::-1]):",
"+ dp2[i] = len(d)",
"+ r += dp1[n - i - 1] * (dp2[i] - dp2[cs[int(c)]])",
"+ d.add(c)",
"+ cs[int(c)] = i"
] | false | 0.039289 | 0.079511 | 0.494136 | [
"s901783168",
"s868569810"
] |
u499259667 | p03844 | python | s391893464 | s838870777 | 17 | 12 | 2,940 | 2,572 | Accepted | Accepted | 29.41 | A,op,B=input().split()
A,B=list(map(int,[A,B]))
print((A+B if op=="+" else A-B)) | print((eval(input()))) | 3 | 1 | 74 | 14 | A, op, B = input().split()
A, B = list(map(int, [A, B]))
print((A + B if op == "+" else A - B))
| print((eval(input())))
| false | 66.666667 | [
"-A, op, B = input().split()",
"-A, B = list(map(int, [A, B]))",
"-print((A + B if op == \"+\" else A - B))",
"+print((eval(input())))"
] | false | 0.037664 | 0.062402 | 0.603566 | [
"s391893464",
"s838870777"
] |
u485319545 | p02572 | python | s314354163 | s067437801 | 1,645 | 152 | 42,456 | 31,476 | Accepted | Accepted | 90.76 | n=int(eval(input()))
a=list(map(int,input().split()))
mod=10**9+7
import numpy as np
cum=[]
prev=0
for i in range(n):
tmp = prev%mod +a[i]%mod
cum.append(tmp)
prev = cum[-1]
ans=0
for i in range(n-1):
p=a[i]
t = cum[-1] - cum[i]
ans+=(p*t)%mod
print((ans%mod)) | n=int(eval(input()))
a=list(map(int,input().split()))
mod=10**9+7
total = sum(a)
cum=[]
ans=0
for i in range(n):
total-=a[i]
ans += a[i]*(total)%mod
print((ans%mod)) | 23 | 14 | 305 | 186 | n = int(eval(input()))
a = list(map(int, input().split()))
mod = 10**9 + 7
import numpy as np
cum = []
prev = 0
for i in range(n):
tmp = prev % mod + a[i] % mod
cum.append(tmp)
prev = cum[-1]
ans = 0
for i in range(n - 1):
p = a[i]
t = cum[-1] - cum[i]
ans += (p * t) % mod
print((ans % mod))
| n = int(eval(input()))
a = list(map(int, input().split()))
mod = 10**9 + 7
total = sum(a)
cum = []
ans = 0
for i in range(n):
total -= a[i]
ans += a[i] * (total) % mod
print((ans % mod))
| false | 39.130435 | [
"-import numpy as np",
"-",
"+total = sum(a)",
"-prev = 0",
"+ans = 0",
"- tmp = prev % mod + a[i] % mod",
"- cum.append(tmp)",
"- prev = cum[-1]",
"-ans = 0",
"-for i in range(n - 1):",
"- p = a[i]",
"- t = cum[-1] - cum[i]",
"- ans += (p * t) % mod",
"+ total -= a[i]",
"+ ans += a[i] * (total) % mod"
] | false | 0.03638 | 0.035572 | 1.02272 | [
"s314354163",
"s067437801"
] |
u535803878 | p02762 | python | s617953945 | s723019839 | 1,453 | 472 | 108,548 | 115,400 | Accepted | Accepted | 67.52 |
from collections import defaultdict
n, m, k = list(map(int, input().split()))
ns = defaultdict(set)
bs = defaultdict(set)
for i in range(m):
a,b = list(map(int, input().split()))
ns[a-1].add(b-1)
ns[b-1].add(a-1)
for i in range(k):
c,d = list(map(int, input().split()))
bs[c-1].add(d-1)
bs[d-1].add(c-1)
s = [0]
start = 0
parent = [None] * n
starts = defaultdict(int)
starts[0] = 0
notdone = set(list(range(n)))
notdone.remove(start)
while notdone or s:
u = s.pop()
parent[u] = start
starts[start] += 1
for v in ns[u]:
if v in notdone:
s.append(v)
notdone.remove(v)
if not s and notdone:
start = notdone.pop()
parent[start] = start
s.append(start)
ans = [None] * n
for u in range(n):
val = starts[parent[u]] - 1 - len(ns[u])
for v in bs[u]:
if parent[v]==parent[u]:
val -= 1
ans[u] = val
print((" ".join(map(str, ans)))) | import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")
n,m,k = list(map(int, input().split()))
class UnionFindTree:
def __init__(self, n):
self.n = n
self.parent = list(range(n))
self.size = [1] * n
def root(self, i):
inter = set()
while self.parent[i]!=i:
inter.add(i)
i = self.parent[i]
r = i
for i in inter:
self.parent[i] = r
return r
def connect(self, i, j):
if i==j:
return
ri = self.root(i)
rj = self.root(j)
if ri==rj:
return
if self.size[ri]<self.size[rj]:
self.parent[ri] = rj
self.size[rj] += self.size[ri]
else:
self.parent[rj] = ri
self.size[ri] += self.size[rj]
uf = UnionFindTree(n)
ns = [[] for _ in range(n)]
for i in range(m):
a,b = [int(x)-1 for x in input().split()]
uf.connect(a,b)
ns[a].append(b)
ns[b].append(a)
for i in range(k):
c,d = [int(x)-1 for x in input().split()]
ns[c].append(d)
ns[d].append(c)
ans = [None]*n
for i in range(n):
r = uf.root(i)
s = uf.size[r]
v = 0
for j in ns[i]:
if r==uf.root(j):
v += 1
ans[i] = s - v - 1
write(" ".join(map(str, ans))) | 42 | 60 | 998 | 1,452 | from collections import defaultdict
n, m, k = list(map(int, input().split()))
ns = defaultdict(set)
bs = defaultdict(set)
for i in range(m):
a, b = list(map(int, input().split()))
ns[a - 1].add(b - 1)
ns[b - 1].add(a - 1)
for i in range(k):
c, d = list(map(int, input().split()))
bs[c - 1].add(d - 1)
bs[d - 1].add(c - 1)
s = [0]
start = 0
parent = [None] * n
starts = defaultdict(int)
starts[0] = 0
notdone = set(list(range(n)))
notdone.remove(start)
while notdone or s:
u = s.pop()
parent[u] = start
starts[start] += 1
for v in ns[u]:
if v in notdone:
s.append(v)
notdone.remove(v)
if not s and notdone:
start = notdone.pop()
parent[start] = start
s.append(start)
ans = [None] * n
for u in range(n):
val = starts[parent[u]] - 1 - len(ns[u])
for v in bs[u]:
if parent[v] == parent[u]:
val -= 1
ans[u] = val
print((" ".join(map(str, ans))))
| import sys
input = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x + "\n")
n, m, k = list(map(int, input().split()))
class UnionFindTree:
def __init__(self, n):
self.n = n
self.parent = list(range(n))
self.size = [1] * n
def root(self, i):
inter = set()
while self.parent[i] != i:
inter.add(i)
i = self.parent[i]
r = i
for i in inter:
self.parent[i] = r
return r
def connect(self, i, j):
if i == j:
return
ri = self.root(i)
rj = self.root(j)
if ri == rj:
return
if self.size[ri] < self.size[rj]:
self.parent[ri] = rj
self.size[rj] += self.size[ri]
else:
self.parent[rj] = ri
self.size[ri] += self.size[rj]
uf = UnionFindTree(n)
ns = [[] for _ in range(n)]
for i in range(m):
a, b = [int(x) - 1 for x in input().split()]
uf.connect(a, b)
ns[a].append(b)
ns[b].append(a)
for i in range(k):
c, d = [int(x) - 1 for x in input().split()]
ns[c].append(d)
ns[d].append(c)
ans = [None] * n
for i in range(n):
r = uf.root(i)
s = uf.size[r]
v = 0
for j in ns[i]:
if r == uf.root(j):
v += 1
ans[i] = s - v - 1
write(" ".join(map(str, ans)))
| false | 30 | [
"-from collections import defaultdict",
"+import sys",
"+input = lambda: sys.stdin.readline().rstrip()",
"+sys.setrecursionlimit(max(1000, 10**9))",
"+write = lambda x: sys.stdout.write(x + \"\\n\")",
"-ns = defaultdict(set)",
"-bs = defaultdict(set)",
"+",
"+",
"+class UnionFindTree:",
"+ def __init__(self, n):",
"+ self.n = n",
"+ self.parent = list(range(n))",
"+ self.size = [1] * n",
"+",
"+ def root(self, i):",
"+ inter = set()",
"+ while self.parent[i] != i:",
"+ inter.add(i)",
"+ i = self.parent[i]",
"+ r = i",
"+ for i in inter:",
"+ self.parent[i] = r",
"+ return r",
"+",
"+ def connect(self, i, j):",
"+ if i == j:",
"+ return",
"+ ri = self.root(i)",
"+ rj = self.root(j)",
"+ if ri == rj:",
"+ return",
"+ if self.size[ri] < self.size[rj]:",
"+ self.parent[ri] = rj",
"+ self.size[rj] += self.size[ri]",
"+ else:",
"+ self.parent[rj] = ri",
"+ self.size[ri] += self.size[rj]",
"+",
"+",
"+uf = UnionFindTree(n)",
"+ns = [[] for _ in range(n)]",
"- a, b = list(map(int, input().split()))",
"- ns[a - 1].add(b - 1)",
"- ns[b - 1].add(a - 1)",
"+ a, b = [int(x) - 1 for x in input().split()]",
"+ uf.connect(a, b)",
"+ ns[a].append(b)",
"+ ns[b].append(a)",
"- c, d = list(map(int, input().split()))",
"- bs[c - 1].add(d - 1)",
"- bs[d - 1].add(c - 1)",
"-s = [0]",
"-start = 0",
"-parent = [None] * n",
"-starts = defaultdict(int)",
"-starts[0] = 0",
"-notdone = set(list(range(n)))",
"-notdone.remove(start)",
"-while notdone or s:",
"- u = s.pop()",
"- parent[u] = start",
"- starts[start] += 1",
"- for v in ns[u]:",
"- if v in notdone:",
"- s.append(v)",
"- notdone.remove(v)",
"- if not s and notdone:",
"- start = notdone.pop()",
"- parent[start] = start",
"- s.append(start)",
"+ c, d = [int(x) - 1 for x in input().split()]",
"+ ns[c].append(d)",
"+ ns[d].append(c)",
"-for u in range(n):",
"- val = starts[parent[u]] - 1 - len(ns[u])",
"- for v in bs[u]:",
"- if parent[v] == parent[u]:",
"- val -= 1",
"- ans[u] = val",
"-print((\" \".join(map(str, ans))))",
"+for i in range(n):",
"+ r = uf.root(i)",
"+ s = uf.size[r]",
"+ v = 0",
"+ for j in ns[i]:",
"+ if r == uf.root(j):",
"+ v += 1",
"+ ans[i] = s - v - 1",
"+write(\" \".join(map(str, ans)))"
] | false | 0.063511 | 0.043249 | 1.468499 | [
"s617953945",
"s723019839"
] |
u673361376 | p03626 | python | s545227214 | s504504650 | 168 | 17 | 38,256 | 3,064 | Accepted | Accepted | 89.88 | N = int(eval(input()))
grids = [[s for s in eval(input())],[s for s in eval(input())]]
MOD = 1000000007
if grids[0][0] == grids[1][0]:
prv_row_type = 1
ans = 3
posx = 1
else:
prv_row_type = -1
ans = 6
posx = 2
while posx < N:
if grids[0][posx] == grids[1][posx]:
if prv_row_type == 1: ans *= 2
else: ans *= 1
prv_row_type = 1
posx += 1
else:
if prv_row_type == 1: ans *= 2
else: ans *= 3
prv_row_type = -1
posx += 2
print((ans%MOD)) | MOD = 10 ** 9 + 7
N = int(eval(input()))
S1 = eval(input())
S2 = eval(input())
ans = 1
prv_ptn = 0 # 1 or 2
i = 0
while i < N:
if S1[i] == S2[i]:
if prv_ptn == 0:
ans *= 3
elif prv_ptn == 1:
ans *= 2
else:
ans *= 1
ans %= MOD
prv_ptn = 1
i += 1
else:
if prv_ptn == 0:
ans *= 6
elif prv_ptn == 1:
ans *= 2
else:
ans *= 3
ans %= MOD
prv_ptn = 2
i += 2
print((ans % MOD))
| 26 | 30 | 490 | 555 | N = int(eval(input()))
grids = [[s for s in eval(input())], [s for s in eval(input())]]
MOD = 1000000007
if grids[0][0] == grids[1][0]:
prv_row_type = 1
ans = 3
posx = 1
else:
prv_row_type = -1
ans = 6
posx = 2
while posx < N:
if grids[0][posx] == grids[1][posx]:
if prv_row_type == 1:
ans *= 2
else:
ans *= 1
prv_row_type = 1
posx += 1
else:
if prv_row_type == 1:
ans *= 2
else:
ans *= 3
prv_row_type = -1
posx += 2
print((ans % MOD))
| MOD = 10**9 + 7
N = int(eval(input()))
S1 = eval(input())
S2 = eval(input())
ans = 1
prv_ptn = 0 # 1 or 2
i = 0
while i < N:
if S1[i] == S2[i]:
if prv_ptn == 0:
ans *= 3
elif prv_ptn == 1:
ans *= 2
else:
ans *= 1
ans %= MOD
prv_ptn = 1
i += 1
else:
if prv_ptn == 0:
ans *= 6
elif prv_ptn == 1:
ans *= 2
else:
ans *= 3
ans %= MOD
prv_ptn = 2
i += 2
print((ans % MOD))
| false | 13.333333 | [
"+MOD = 10**9 + 7",
"-grids = [[s for s in eval(input())], [s for s in eval(input())]]",
"-MOD = 1000000007",
"-if grids[0][0] == grids[1][0]:",
"- prv_row_type = 1",
"- ans = 3",
"- posx = 1",
"-else:",
"- prv_row_type = -1",
"- ans = 6",
"- posx = 2",
"-while posx < N:",
"- if grids[0][posx] == grids[1][posx]:",
"- if prv_row_type == 1:",
"+S1 = eval(input())",
"+S2 = eval(input())",
"+ans = 1",
"+prv_ptn = 0 # 1 or 2",
"+i = 0",
"+while i < N:",
"+ if S1[i] == S2[i]:",
"+ if prv_ptn == 0:",
"+ ans *= 3",
"+ elif prv_ptn == 1:",
"- prv_row_type = 1",
"- posx += 1",
"+ ans %= MOD",
"+ prv_ptn = 1",
"+ i += 1",
"- if prv_row_type == 1:",
"+ if prv_ptn == 0:",
"+ ans *= 6",
"+ elif prv_ptn == 1:",
"- prv_row_type = -1",
"- posx += 2",
"+ ans %= MOD",
"+ prv_ptn = 2",
"+ i += 2"
] | false | 0.040604 | 0.037987 | 1.068882 | [
"s545227214",
"s504504650"
] |
u358254559 | p02889 | python | s787580383 | s480216423 | 1,686 | 1,272 | 125,660 | 36,576 | Accepted | Accepted | 24.56 | n,m,l = list(map(int, input().split()))
wf=[[float("inf") for i in range(n)] for j in range(n)]
for i in range(m):
a,b,c = list(map(int,input().split()))
wf[a-1][b-1] = c
wf[b-1][a-1] = c
q = int(eval(input()))
st=[list(map(int,input().split())) for i in range(q)]
for i in range(n):
wf[i][i]=0
for k in range(n):
for i in range(n):
for j in range(i+1,n):
wf[i][j] = min(wf[i][j],wf[i][k]+wf[k][j])
wf[j][i] = wf[i][j]
for i in range(n):
for j in range(n):
if wf[i][j] <= l:
wf[i][j] = 1
else:
wf[i][j] = float("inf")
for k in range(n):
for i in range(n):
for j in range(i+1,n):
wf[i][j] = min(wf[i][j],wf[i][k]+wf[k][j])
wf[j][i] = wf[i][j]
for que in st:
s,t=que
if wf[s-1][t-1] == float("inf"):
print((-1))
else:
print((wf[s-1][t-1]-1)) | n,m,l = list(map(int, input().split()))
wf=[[float("inf") for i in range(n)] for j in range(n)]
for i in range(m):
a,b,c = list(map(int,input().split()))
wf[a-1][b-1] = c
wf[b-1][a-1] = c
q = int(eval(input()))
st=[list(map(int,input().split())) for i in range(q)]
from scipy.sparse.csgraph import floyd_warshall
for i in range(n):
wf[i][i]=0
wf=floyd_warshall(wf)
for i in range(n):
for j in range(n):
if wf[i][j] <= l:
wf[i][j] = 1
else:
wf[i][j] = float("inf")
wf=floyd_warshall(wf)
for que in st:
s,t=que
if wf[s-1][t-1] == float("inf"):
print((-1))
else:
print((int(wf[s-1][t-1]-1))) | 36 | 29 | 922 | 692 | n, m, l = list(map(int, input().split()))
wf = [[float("inf") for i in range(n)] for j in range(n)]
for i in range(m):
a, b, c = list(map(int, input().split()))
wf[a - 1][b - 1] = c
wf[b - 1][a - 1] = c
q = int(eval(input()))
st = [list(map(int, input().split())) for i in range(q)]
for i in range(n):
wf[i][i] = 0
for k in range(n):
for i in range(n):
for j in range(i + 1, n):
wf[i][j] = min(wf[i][j], wf[i][k] + wf[k][j])
wf[j][i] = wf[i][j]
for i in range(n):
for j in range(n):
if wf[i][j] <= l:
wf[i][j] = 1
else:
wf[i][j] = float("inf")
for k in range(n):
for i in range(n):
for j in range(i + 1, n):
wf[i][j] = min(wf[i][j], wf[i][k] + wf[k][j])
wf[j][i] = wf[i][j]
for que in st:
s, t = que
if wf[s - 1][t - 1] == float("inf"):
print((-1))
else:
print((wf[s - 1][t - 1] - 1))
| n, m, l = list(map(int, input().split()))
wf = [[float("inf") for i in range(n)] for j in range(n)]
for i in range(m):
a, b, c = list(map(int, input().split()))
wf[a - 1][b - 1] = c
wf[b - 1][a - 1] = c
q = int(eval(input()))
st = [list(map(int, input().split())) for i in range(q)]
from scipy.sparse.csgraph import floyd_warshall
for i in range(n):
wf[i][i] = 0
wf = floyd_warshall(wf)
for i in range(n):
for j in range(n):
if wf[i][j] <= l:
wf[i][j] = 1
else:
wf[i][j] = float("inf")
wf = floyd_warshall(wf)
for que in st:
s, t = que
if wf[s - 1][t - 1] == float("inf"):
print((-1))
else:
print((int(wf[s - 1][t - 1] - 1)))
| false | 19.444444 | [
"+from scipy.sparse.csgraph import floyd_warshall",
"+",
"-for k in range(n):",
"- for i in range(n):",
"- for j in range(i + 1, n):",
"- wf[i][j] = min(wf[i][j], wf[i][k] + wf[k][j])",
"- wf[j][i] = wf[i][j]",
"+wf = floyd_warshall(wf)",
"-for k in range(n):",
"- for i in range(n):",
"- for j in range(i + 1, n):",
"- wf[i][j] = min(wf[i][j], wf[i][k] + wf[k][j])",
"- wf[j][i] = wf[i][j]",
"+wf = floyd_warshall(wf)",
"- print((wf[s - 1][t - 1] - 1))",
"+ print((int(wf[s - 1][t - 1] - 1)))"
] | false | 0.042568 | 0.415619 | 0.10242 | [
"s787580383",
"s480216423"
] |
u840570107 | p02779 | python | s349822700 | s293382123 | 212 | 113 | 20,796 | 40,724 | Accepted | Accepted | 46.7 | n = int(eval(input()))
lis = [x for x in input().split()]
lis.sort()
for i in range(1, n):
if lis[i-1] == lis[i]:
print("NO")
exit()
print("YES") | n = int(eval(input()))
lis = input().split()
dic = {}
for i in range(n):
if lis[i] not in dic:
dic[lis[i]] = 1
else:
dic[lis[i]] += 1
for x in list(dic.values()):
if x != 1:
print("NO")
exit()
print("YES") | 10 | 16 | 162 | 237 | n = int(eval(input()))
lis = [x for x in input().split()]
lis.sort()
for i in range(1, n):
if lis[i - 1] == lis[i]:
print("NO")
exit()
print("YES")
| n = int(eval(input()))
lis = input().split()
dic = {}
for i in range(n):
if lis[i] not in dic:
dic[lis[i]] = 1
else:
dic[lis[i]] += 1
for x in list(dic.values()):
if x != 1:
print("NO")
exit()
print("YES")
| false | 37.5 | [
"-lis = [x for x in input().split()]",
"-lis.sort()",
"-for i in range(1, n):",
"- if lis[i - 1] == lis[i]:",
"+lis = input().split()",
"+dic = {}",
"+for i in range(n):",
"+ if lis[i] not in dic:",
"+ dic[lis[i]] = 1",
"+ else:",
"+ dic[lis[i]] += 1",
"+for x in list(dic.values()):",
"+ if x != 1:"
] | false | 0.041576 | 0.041013 | 1.013742 | [
"s349822700",
"s293382123"
] |
u136869985 | p03854 | python | s530503401 | s662096938 | 61 | 43 | 3,188 | 3,188 | Accepted | Accepted | 29.51 | A = ["dream", "dreamer", "erase", "eraser"]
for i in range(4):
A[i] = A[i][::-1]
S = input()[::-1]
idx = 0
while idx < len(S):
flag = False
for i in range(4):
if len(S) - idx < len(A[i]):
continue
else:
if S[idx:idx+len(A[i])] == A[i]:
flag = True
idx += len(A[i])
break
else:
continue
if idx >= len(S) or flag == False:
break
print((["NO","YES"][idx == len(S)])) | A = ['dream', 'dreamer', 'erase', 'eraser']
for i in range(len(A)):
A[i] = A[i][::-1]
s = input()[::-1]
i = 0
while True:
f = True
for a in A:
if len(a) > len(s) - i:
continue
if s[i:i+len(a)] == a:
i += len(a)
f = False
break
else:
if i == len(s):
print('YES')
exit()
if f == True:
print('NO')
exit()
print('YES') | 22 | 26 | 524 | 487 | A = ["dream", "dreamer", "erase", "eraser"]
for i in range(4):
A[i] = A[i][::-1]
S = input()[::-1]
idx = 0
while idx < len(S):
flag = False
for i in range(4):
if len(S) - idx < len(A[i]):
continue
else:
if S[idx : idx + len(A[i])] == A[i]:
flag = True
idx += len(A[i])
break
else:
continue
if idx >= len(S) or flag == False:
break
print((["NO", "YES"][idx == len(S)]))
| A = ["dream", "dreamer", "erase", "eraser"]
for i in range(len(A)):
A[i] = A[i][::-1]
s = input()[::-1]
i = 0
while True:
f = True
for a in A:
if len(a) > len(s) - i:
continue
if s[i : i + len(a)] == a:
i += len(a)
f = False
break
else:
if i == len(s):
print("YES")
exit()
if f == True:
print("NO")
exit()
print("YES")
| false | 15.384615 | [
"-for i in range(4):",
"+for i in range(len(A)):",
"-S = input()[::-1]",
"-idx = 0",
"-while idx < len(S):",
"- flag = False",
"- for i in range(4):",
"- if len(S) - idx < len(A[i]):",
"+s = input()[::-1]",
"+i = 0",
"+while True:",
"+ f = True",
"+ for a in A:",
"+ if len(a) > len(s) - i:",
"- else:",
"- if S[idx : idx + len(A[i])] == A[i]:",
"- flag = True",
"- idx += len(A[i])",
"- break",
"- else:",
"- continue",
"- if idx >= len(S) or flag == False:",
"- break",
"-print(([\"NO\", \"YES\"][idx == len(S)]))",
"+ if s[i : i + len(a)] == a:",
"+ i += len(a)",
"+ f = False",
"+ break",
"+ else:",
"+ if i == len(s):",
"+ print(\"YES\")",
"+ exit()",
"+ if f == True:",
"+ print(\"NO\")",
"+ exit()",
"+print(\"YES\")"
] | false | 0.041823 | 0.094286 | 0.443575 | [
"s530503401",
"s662096938"
] |
u811733736 | p02407 | python | s090426421 | s481151522 | 30 | 20 | 7,692 | 7,760 | Accepted | Accepted | 33.33 | if __name__ == '__main__':
data_num = int(eval(input()))
data = [x for x in input().split(' ')]
assert data_num == len(data), "invalid input"
data.reverse()
output = ' '.join(data)
print(output) | # -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_6_A&lang=jp
"""
import sys
from sys import stdin
input = stdin.readline
def main(args):
n = int(eval(input()))
numbers = [int(x) for x in input().split()]
numbers.reverse()
print((*numbers))
if __name__ == '__main__':
main(sys.argv[1:])
| 9 | 20 | 222 | 367 | if __name__ == "__main__":
data_num = int(eval(input()))
data = [x for x in input().split(" ")]
assert data_num == len(data), "invalid input"
data.reverse()
output = " ".join(data)
print(output)
| # -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_6_A&lang=jp
"""
import sys
from sys import stdin
input = stdin.readline
def main(args):
n = int(eval(input()))
numbers = [int(x) for x in input().split()]
numbers.reverse()
print((*numbers))
if __name__ == "__main__":
main(sys.argv[1:])
| false | 55 | [
"+# -*- coding: utf-8 -*-",
"+\"\"\"",
"+http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_6_A&lang=jp",
"+\"\"\"",
"+import sys",
"+from sys import stdin",
"+",
"+input = stdin.readline",
"+",
"+",
"+def main(args):",
"+ n = int(eval(input()))",
"+ numbers = [int(x) for x in input().split()]",
"+ numbers.reverse()",
"+ print((*numbers))",
"+",
"+",
"- data_num = int(eval(input()))",
"- data = [x for x in input().split(\" \")]",
"- assert data_num == len(data), \"invalid input\"",
"- data.reverse()",
"- output = \" \".join(data)",
"- print(output)",
"+ main(sys.argv[1:])"
] | false | 0.217173 | 0.038374 | 5.659387 | [
"s090426421",
"s481151522"
] |
u191874006 | p03061 | python | s434742794 | s745204644 | 251 | 109 | 59,632 | 89,740 | Accepted | Accepted | 56.57 | #!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def gcd(n,m):
if m == 0:
return n
else:
return gcd(m,n%m)
n = I()
a = LI()
l = [0]*n
r = [0]*n
l[0] = a[0]
for i in range(1,n):
l[i] = gcd(l[i-1],a[i])
r[-1] = a[-1]
for i in range(n-1)[::-1]:
r[i] = gcd(r[i+1],a[i])
ans = 0
for i in range(n):
if i == 0:
ans = max(ans,r[i+1])
elif i == n-1:
ans = max(ans,l[-2])
else:
ans = max(ans,gcd(l[i-1],r[i+1]))
print(ans)
| #!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
n = I()
a = LI()
L = [0] * (n+2)
L[0] = a[0]
R = [0] * (n+2)
R[-1] = a[-1]
for i in range(n):
L[i+1] = math.gcd(a[i], L[i])
R[-(i+2)] = math.gcd(a[-(i+1)], R[-(i+1)])
ans = 0
for i in range(1, n+1):
if i - 1 == 0:
ans = max(ans, R[i+1])
elif i == n:
ans = max(ans, L[i-1])
else:
ans = max(ans, math.gcd(L[i-1], R[i+1]))
print(ans) | 46 | 38 | 1,021 | 953 | #!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop, heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float("inf")
def I():
return int(sys.stdin.readline())
def LI():
return list(map(int, sys.stdin.readline().split()))
def gcd(n, m):
if m == 0:
return n
else:
return gcd(m, n % m)
n = I()
a = LI()
l = [0] * n
r = [0] * n
l[0] = a[0]
for i in range(1, n):
l[i] = gcd(l[i - 1], a[i])
r[-1] = a[-1]
for i in range(n - 1)[::-1]:
r[i] = gcd(r[i + 1], a[i])
ans = 0
for i in range(n):
if i == 0:
ans = max(ans, r[i + 1])
elif i == n - 1:
ans = max(ans, l[-2])
else:
ans = max(ans, gcd(l[i - 1], r[i + 1]))
print(ans)
| #!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop, heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float("inf")
def I():
return int(sys.stdin.readline())
def LI():
return list(map(int, sys.stdin.readline().split()))
n = I()
a = LI()
L = [0] * (n + 2)
L[0] = a[0]
R = [0] * (n + 2)
R[-1] = a[-1]
for i in range(n):
L[i + 1] = math.gcd(a[i], L[i])
R[-(i + 2)] = math.gcd(a[-(i + 1)], R[-(i + 1)])
ans = 0
for i in range(1, n + 1):
if i - 1 == 0:
ans = max(ans, R[i + 1])
elif i == n:
ans = max(ans, L[i - 1])
else:
ans = max(ans, math.gcd(L[i - 1], R[i + 1]))
print(ans)
| false | 17.391304 | [
"-def gcd(n, m):",
"- if m == 0:",
"- return n",
"- else:",
"- return gcd(m, n % m)",
"-",
"-",
"-l = [0] * n",
"-r = [0] * n",
"-l[0] = a[0]",
"-for i in range(1, n):",
"- l[i] = gcd(l[i - 1], a[i])",
"-r[-1] = a[-1]",
"-for i in range(n - 1)[::-1]:",
"- r[i] = gcd(r[i + 1], a[i])",
"+L = [0] * (n + 2)",
"+L[0] = a[0]",
"+R = [0] * (n + 2)",
"+R[-1] = a[-1]",
"+for i in range(n):",
"+ L[i + 1] = math.gcd(a[i], L[i])",
"+ R[-(i + 2)] = math.gcd(a[-(i + 1)], R[-(i + 1)])",
"-for i in range(n):",
"- if i == 0:",
"- ans = max(ans, r[i + 1])",
"- elif i == n - 1:",
"- ans = max(ans, l[-2])",
"+for i in range(1, n + 1):",
"+ if i - 1 == 0:",
"+ ans = max(ans, R[i + 1])",
"+ elif i == n:",
"+ ans = max(ans, L[i - 1])",
"- ans = max(ans, gcd(l[i - 1], r[i + 1]))",
"+ ans = max(ans, math.gcd(L[i - 1], R[i + 1]))"
] | false | 0.046387 | 0.039664 | 1.169499 | [
"s434742794",
"s745204644"
] |
u150984829 | p02414 | python | s412984810 | s236430198 | 130 | 110 | 6,984 | 6,588 | Accepted | Accepted | 15.38 | import sys
e=[list(map(int,x.split()))for x in sys.stdin];n=e[0][0]+1
[print(*x)for x in[[sum(s*t for s,t in zip(c,l))for l in zip(*e[n:])]for c in e[1:n]]]
| import sys
e=[list(map(int,x.split()))for x in sys.stdin];n=e[0][0]+1
for c in e[1:n]:print((*[sum([s*t for s,t in zip(c,l)])for l in zip(*e[n:])]))
| 3 | 3 | 159 | 149 | import sys
e = [list(map(int, x.split())) for x in sys.stdin]
n = e[0][0] + 1
[
print(*x)
for x in [[sum(s * t for s, t in zip(c, l)) for l in zip(*e[n:])] for c in e[1:n]]
]
| import sys
e = [list(map(int, x.split())) for x in sys.stdin]
n = e[0][0] + 1
for c in e[1:n]:
print((*[sum([s * t for s, t in zip(c, l)]) for l in zip(*e[n:])]))
| false | 0 | [
"-[",
"- print(*x)",
"- for x in [[sum(s * t for s, t in zip(c, l)) for l in zip(*e[n:])] for c in e[1:n]]",
"-]",
"+for c in e[1:n]:",
"+ print((*[sum([s * t for s, t in zip(c, l)]) for l in zip(*e[n:])]))"
] | false | 0.037684 | 0.037018 | 1.017994 | [
"s412984810",
"s236430198"
] |
u626337957 | p03701 | python | s698090247 | s712469139 | 192 | 177 | 3,188 | 3,064 | Accepted | Accepted | 7.81 | N = int(eval(input()))
nums=[int(eval(input())) for _ in range(N)]
MAX = 10**4
dp = [0] * (MAX+1)
dp[0] = 1
for num in nums:
for i in range(MAX+1)[::-1]:
if dp[i] == 1 and (i + num) <= MAX*MAX:
dp[i+num] = 1
ans = 0
for i in range(MAX+1):
if dp[i] == 1 and i%10 != 0:
ans = i
print(ans)
| N = int(eval(input()))
nums=[int(eval(input())) for _ in range(N)]
MAX = 10**4
dp = [0] * (MAX+1)
dp[0] = 1
for num in nums:
for i in range(MAX+1)[::-1]:
if dp[i] == 1 and (i + num) <= MAX+1:
dp[i+num] = 1
ans = 0
for i in range(MAX+1):
if dp[i] == 1 and i%10 != 0:
ans = i
print(ans)
| 14 | 14 | 306 | 304 | N = int(eval(input()))
nums = [int(eval(input())) for _ in range(N)]
MAX = 10**4
dp = [0] * (MAX + 1)
dp[0] = 1
for num in nums:
for i in range(MAX + 1)[::-1]:
if dp[i] == 1 and (i + num) <= MAX * MAX:
dp[i + num] = 1
ans = 0
for i in range(MAX + 1):
if dp[i] == 1 and i % 10 != 0:
ans = i
print(ans)
| N = int(eval(input()))
nums = [int(eval(input())) for _ in range(N)]
MAX = 10**4
dp = [0] * (MAX + 1)
dp[0] = 1
for num in nums:
for i in range(MAX + 1)[::-1]:
if dp[i] == 1 and (i + num) <= MAX + 1:
dp[i + num] = 1
ans = 0
for i in range(MAX + 1):
if dp[i] == 1 and i % 10 != 0:
ans = i
print(ans)
| false | 0 | [
"- if dp[i] == 1 and (i + num) <= MAX * MAX:",
"+ if dp[i] == 1 and (i + num) <= MAX + 1:"
] | false | 0.046089 | 0.047863 | 0.962938 | [
"s698090247",
"s712469139"
] |
u766684188 | p02899 | python | s553270586 | s529286608 | 575 | 109 | 65,196 | 13,940 | Accepted | Accepted | 81.04 | n=int(eval(input()))
A=list(map(int,input().split()))
B=[]
for i,a in enumerate(A):
B.append((a,i+1))
B.sort()
Ans=[]
for _,a in B:
Ans.append(a)
print((*Ans)) | n=int(eval(input()))
A=tuple(map(int,input().split()))
Ans=[0]*n
for i,a in enumerate(A):
Ans[a-1]=i+1
print((*Ans)) | 10 | 6 | 168 | 117 | n = int(eval(input()))
A = list(map(int, input().split()))
B = []
for i, a in enumerate(A):
B.append((a, i + 1))
B.sort()
Ans = []
for _, a in B:
Ans.append(a)
print((*Ans))
| n = int(eval(input()))
A = tuple(map(int, input().split()))
Ans = [0] * n
for i, a in enumerate(A):
Ans[a - 1] = i + 1
print((*Ans))
| false | 40 | [
"-A = list(map(int, input().split()))",
"-B = []",
"+A = tuple(map(int, input().split()))",
"+Ans = [0] * n",
"- B.append((a, i + 1))",
"-B.sort()",
"-Ans = []",
"-for _, a in B:",
"- Ans.append(a)",
"+ Ans[a - 1] = i + 1"
] | false | 0.007048 | 0.035328 | 0.19951 | [
"s553270586",
"s529286608"
] |
u860002137 | p02631 | python | s208344590 | s882649494 | 190 | 173 | 31,676 | 31,428 | Accepted | Accepted | 8.95 | n = int(eval(input()))
arr = list(map(int, input().split()))
a = arr[0]
for i in range(1, n):
a ^= arr[i]
ans = []
for i in range(n):
ans.append(a ^ arr[i])
print((*ans)) | n = int(eval(input()))
arr = list(map(int, input().split()))
a = 0
for i in range(n):
a ^= arr[i]
ans = []
for i in range(n):
ans.append(a ^ arr[i])
print((*ans)) | 13 | 13 | 190 | 178 | n = int(eval(input()))
arr = list(map(int, input().split()))
a = arr[0]
for i in range(1, n):
a ^= arr[i]
ans = []
for i in range(n):
ans.append(a ^ arr[i])
print((*ans))
| n = int(eval(input()))
arr = list(map(int, input().split()))
a = 0
for i in range(n):
a ^= arr[i]
ans = []
for i in range(n):
ans.append(a ^ arr[i])
print((*ans))
| false | 0 | [
"-a = arr[0]",
"-for i in range(1, n):",
"+a = 0",
"+for i in range(n):"
] | false | 0.046421 | 0.046462 | 0.999124 | [
"s208344590",
"s882649494"
] |
u010379708 | p02646 | python | s688664959 | s362980101 | 191 | 66 | 71,328 | 61,692 | Accepted | Accepted | 65.45 | from decimal import *
l=list(map(int, input().split(' ')))
a=l[0]
v=l[1]
l=list(map(int, input().split(' ')))
b=l[0]
w=l[1]
s=int(eval(input()))
ans=True
if a>b:
ans=Decimal(a)-Decimal(v*s)<=Decimal(b)-Decimal(w*s)
else:
ans=Decimal(a)+Decimal(v*s)>=Decimal(b)+Decimal(w*s)
if ans:
print("YES")
else:
print("NO")
|
l=list(map(int, input().split(' ')))
a=l[0]
v=l[1]
l=list(map(int, input().split(' ')))
b=l[0]
w=l[1]
s=int(eval(input()))
ans=True
if a>b:
ans=a-v*s<=b-w*s
else:
ans=a+v*s>=b+w*s
if ans:
print("YES")
else:
print("NO")
| 20 | 19 | 349 | 254 | from decimal import *
l = list(map(int, input().split(" ")))
a = l[0]
v = l[1]
l = list(map(int, input().split(" ")))
b = l[0]
w = l[1]
s = int(eval(input()))
ans = True
if a > b:
ans = Decimal(a) - Decimal(v * s) <= Decimal(b) - Decimal(w * s)
else:
ans = Decimal(a) + Decimal(v * s) >= Decimal(b) + Decimal(w * s)
if ans:
print("YES")
else:
print("NO")
| l = list(map(int, input().split(" ")))
a = l[0]
v = l[1]
l = list(map(int, input().split(" ")))
b = l[0]
w = l[1]
s = int(eval(input()))
ans = True
if a > b:
ans = a - v * s <= b - w * s
else:
ans = a + v * s >= b + w * s
if ans:
print("YES")
else:
print("NO")
| false | 5 | [
"-from decimal import *",
"-",
"- ans = Decimal(a) - Decimal(v * s) <= Decimal(b) - Decimal(w * s)",
"+ ans = a - v * s <= b - w * s",
"- ans = Decimal(a) + Decimal(v * s) >= Decimal(b) + Decimal(w * s)",
"+ ans = a + v * s >= b + w * s"
] | false | 0.041324 | 0.045514 | 0.907937 | [
"s688664959",
"s362980101"
] |
u629350026 | p02659 | python | s229075543 | s458011433 | 25 | 23 | 9,156 | 8,936 | Accepted | Accepted | 8 | A,B = list(map(str,input().split()))
A = int(A)
B = int(float(B)*1000)
print((int(A*B)//1000)) | a,b=list(map(str,input().split()))
tempb=int(float(b)*1000)
tempa=int(a)
print((int(tempa*tempb)//1000)) | 4 | 4 | 89 | 99 | A, B = list(map(str, input().split()))
A = int(A)
B = int(float(B) * 1000)
print((int(A * B) // 1000))
| a, b = list(map(str, input().split()))
tempb = int(float(b) * 1000)
tempa = int(a)
print((int(tempa * tempb) // 1000))
| false | 0 | [
"-A, B = list(map(str, input().split()))",
"-A = int(A)",
"-B = int(float(B) * 1000)",
"-print((int(A * B) // 1000))",
"+a, b = list(map(str, input().split()))",
"+tempb = int(float(b) * 1000)",
"+tempa = int(a)",
"+print((int(tempa * tempb) // 1000))"
] | false | 0.043143 | 0.120476 | 0.3581 | [
"s229075543",
"s458011433"
] |
u264349861 | p03166 | python | s734562256 | s293833527 | 484 | 423 | 163,508 | 152,644 | Accepted | Accepted | 12.6 | #dt = {} for i in x: dt[i] = dt.get(i,0)+1
import sys;input = sys.stdin.readline
inp,ip = lambda :int(eval(input())),lambda :[int(w) for w in input().split()]
import sys
sys.setrecursionlimit(10**6)
def dfs(u):
global grpah,vis,dp
vis.add(u)
for i in graph[u]:
if i not in vis:
dfs(i)
dp[u] = max(dp[u],dp[i] + 1)
n,m = ip()
graph = {i:[] for i in range(1,n+1)}
for i in range(m):
a,b = ip()
graph[a].append(b)
dp = [0]*(n+1)
vis = set()
for i in range(1,n+1):
if i not in vis:
dfs(i)
#print(dp)
print((max(dp))) | #dt = {} for i in x: dt[i] = dt.get(i,0)+1
import sys;input = sys.stdin.readline
inp,ip = lambda :int(eval(input())),lambda :[int(w) for w in input().split()]
import sys
sys.setrecursionlimit(10**6)
def dfs(u):
global grpah,vis,dp
vis[u] = 1
for i in graph[u]:
if not vis[i]:
dfs(i)
dp[u] = max(dp[u],dp[i] + 1)
n,m = ip()
graph = {i:[] for i in range(1,n+1)}
for i in range(m):
a,b = ip()
graph[a].append(b)
dp = [0]*(n+1)
vis = [0]*(n+1)
for i in range(1,n+1):
if not vis[i]:
dfs(i)
#print(dp)
print((max(dp))) | 28 | 28 | 595 | 595 | # dt = {} for i in x: dt[i] = dt.get(i,0)+1
import sys
input = sys.stdin.readline
inp, ip = lambda: int(eval(input())), lambda: [int(w) for w in input().split()]
import sys
sys.setrecursionlimit(10**6)
def dfs(u):
global grpah, vis, dp
vis.add(u)
for i in graph[u]:
if i not in vis:
dfs(i)
dp[u] = max(dp[u], dp[i] + 1)
n, m = ip()
graph = {i: [] for i in range(1, n + 1)}
for i in range(m):
a, b = ip()
graph[a].append(b)
dp = [0] * (n + 1)
vis = set()
for i in range(1, n + 1):
if i not in vis:
dfs(i)
# print(dp)
print((max(dp)))
| # dt = {} for i in x: dt[i] = dt.get(i,0)+1
import sys
input = sys.stdin.readline
inp, ip = lambda: int(eval(input())), lambda: [int(w) for w in input().split()]
import sys
sys.setrecursionlimit(10**6)
def dfs(u):
global grpah, vis, dp
vis[u] = 1
for i in graph[u]:
if not vis[i]:
dfs(i)
dp[u] = max(dp[u], dp[i] + 1)
n, m = ip()
graph = {i: [] for i in range(1, n + 1)}
for i in range(m):
a, b = ip()
graph[a].append(b)
dp = [0] * (n + 1)
vis = [0] * (n + 1)
for i in range(1, n + 1):
if not vis[i]:
dfs(i)
# print(dp)
print((max(dp)))
| false | 0 | [
"- vis.add(u)",
"+ vis[u] = 1",
"- if i not in vis:",
"+ if not vis[i]:",
"-vis = set()",
"+vis = [0] * (n + 1)",
"- if i not in vis:",
"+ if not vis[i]:"
] | false | 0.045901 | 0.038335 | 1.197341 | [
"s734562256",
"s293833527"
] |
u133936772 | p03013 | python | s500602349 | s886042289 | 182 | 71 | 3,060 | 3,064 | Accepted | Accepted | 60.99 | M=10**9+7
f=input
n,m=list(map(int,f().split()))
s,t=0,1
u=0 if m<1 else int(f())
for i in range(n):
if i==u-1:
s,t=t,0
try: u=int(f())
except: pass
else: s,t=t,(s+t)%M
print(t) | M=10**9+7
import sys
f=sys.stdin.readline
n,m=list(map(int,f().split()))
s,t=0,1
u=0 if m<1 else int(f())
for i in range(n):
if i==u-1:
s,t=t,0
try: u=int(f())
except: pass
else: s,t=t,(s+t)%M
print(t) | 12 | 13 | 198 | 223 | M = 10**9 + 7
f = input
n, m = list(map(int, f().split()))
s, t = 0, 1
u = 0 if m < 1 else int(f())
for i in range(n):
if i == u - 1:
s, t = t, 0
try:
u = int(f())
except:
pass
else:
s, t = t, (s + t) % M
print(t)
| M = 10**9 + 7
import sys
f = sys.stdin.readline
n, m = list(map(int, f().split()))
s, t = 0, 1
u = 0 if m < 1 else int(f())
for i in range(n):
if i == u - 1:
s, t = t, 0
try:
u = int(f())
except:
pass
else:
s, t = t, (s + t) % M
print(t)
| false | 7.692308 | [
"-f = input",
"+import sys",
"+",
"+f = sys.stdin.readline"
] | false | 0.041539 | 0.04293 | 0.967604 | [
"s500602349",
"s886042289"
] |
u579699847 | p02683 | python | s881998760 | s479958739 | 167 | 154 | 27,372 | 27,340 | Accepted | Accepted | 7.78 | import numpy as np,sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N,M,X = LI()
CA = np.array([LI() for _ in range(N)])
ans = float('INF')
for i in range(2**N):
bit = np.array([[i>>j&1 for j in range(N)]]).T
t = np.sum(CA*bit,axis=0)
if np.all(t[1:]>=X):
ans = min(ans,t[0])
print((ans if ans !=float('INF') else -1)) | import numpy as np,sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N,M,X = LI()
CA = np.array([LI() for _ in range(N)])
ans = float('INF')
for i in range(2**N):
bit = np.array([[i>>j&1 for j in range(N)]]).T
temp = (CA*bit).sum(axis=0)
if (temp[1:]>=X).all():
ans = min(ans,temp[0])
print((ans if ans!=float('INF') else -1))
| 11 | 11 | 371 | 379 | import numpy as np, sys
def LI():
return list(map(int, sys.stdin.readline().rstrip().split()))
N, M, X = LI()
CA = np.array([LI() for _ in range(N)])
ans = float("INF")
for i in range(2**N):
bit = np.array([[i >> j & 1 for j in range(N)]]).T
t = np.sum(CA * bit, axis=0)
if np.all(t[1:] >= X):
ans = min(ans, t[0])
print((ans if ans != float("INF") else -1))
| import numpy as np, sys
def LI():
return list(map(int, sys.stdin.readline().rstrip().split()))
N, M, X = LI()
CA = np.array([LI() for _ in range(N)])
ans = float("INF")
for i in range(2**N):
bit = np.array([[i >> j & 1 for j in range(N)]]).T
temp = (CA * bit).sum(axis=0)
if (temp[1:] >= X).all():
ans = min(ans, temp[0])
print((ans if ans != float("INF") else -1))
| false | 0 | [
"- t = np.sum(CA * bit, axis=0)",
"- if np.all(t[1:] >= X):",
"- ans = min(ans, t[0])",
"+ temp = (CA * bit).sum(axis=0)",
"+ if (temp[1:] >= X).all():",
"+ ans = min(ans, temp[0])"
] | false | 0.273366 | 0.330626 | 0.826814 | [
"s881998760",
"s479958739"
] |
u969850098 | p03713 | python | s218787061 | s704448190 | 52 | 34 | 5,576 | 5,064 | Accepted | Accepted | 34.62 | import sys
readline = sys.stdin.readline
from math import floor, ceil
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
def round(f, r=0):
return Decimal(str(f)).quantize(Decimal(str(r)), rounding=ROUND_HALF_UP)
def main():
H, W = list(map(int, readline().rstrip().split()))
ans = H * W
if H >= 3:
y1 = int(round(H/3))
y2 = (H-y1) // 2
y3 = H - y1 - y2
ans = min(ans, max(W*y1, W*y2, W*y3)-min(W*y1, W*y2, W*y3))
if W >= 3:
x1 = int(round(W/3))
x2 = (W-x1) // 2
x3 = W - x1 - x2
ans = min(ans, max(x1*H, x2*H, x3*H)-min(x1*H, x2*H, x3*H))
# 縦にスライス + 残りに横にスライス
x1_cand = [floor(W/3), ceil(W/3)]
# x1_cand = [i for i in range(1, W)]
y1 = H
for x1 in x1_cand:
x2 = W - x1
x3 = x2
y2 = H // 2
y3 = H - y2
ans = min(ans, max((x1*y1), (x2*y2), (x3*y3)) - min((x1*y1), (x2*y2), (x3*y3)))
# 横にスライス + 残りに縦にスライス
y1_cand = [floor(H/3), ceil(H/3)]
# y1_cand = [i for i in range(1, H)]
x1 = W
for y1 in y1_cand:
y2 = H - y1
y3 = y2
x2 = W // 2
x3 = W - x2
ans = min(ans, max((x1*y1), (x2*y2), (x3*y3)) - min((x1*y1), (x2*y2), (x3*y3)))
print(ans)
if __name__ == '__main__':
main() | import sys
readline = sys.stdin.readline
from math import floor, ceil
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
def round(f, r=0):
return Decimal(str(f)).quantize(Decimal(str(r)), rounding=ROUND_HALF_UP)
def main():
H, W = list(map(int, readline().rstrip().split()))
ans = H * W
if H >= 3:
y1 = int(round(H/3))
y2 = (H-y1) // 2
y3 = H - y1 - y2
ans = min(ans, max(W*y1, W*y2, W*y3)-min(W*y1, W*y2, W*y3))
if W >= 3:
x1 = int(round(W/3))
x2 = (W-x1) // 2
x3 = W - x1 - x2
ans = min(ans, max(x1*H, x2*H, x3*H)-min(x1*H, x2*H, x3*H))
# 縦にスライス + 残りに横にスライス
x1_cand = [int(round(W/3))]
y1 = H
for x1 in x1_cand:
x2 = W - x1
x3 = x2
y2 = H // 2
y3 = H - y2
ans = min(ans, max((x1*y1), (x2*y2), (x3*y3)) - min((x1*y1), (x2*y2), (x3*y3)))
# 横にスライス + 残りに縦にスライス
y1_cand = [int(round(H/3))]
x1 = W
for y1 in y1_cand:
y2 = H - y1
y3 = y2
x2 = W // 2
x3 = W - x2
ans = min(ans, max((x1*y1), (x2*y2), (x3*y3)) - min((x1*y1), (x2*y2), (x3*y3)))
print(ans)
if __name__ == '__main__':
main() | 47 | 46 | 1,338 | 1,244 | import sys
readline = sys.stdin.readline
from math import floor, ceil
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
def round(f, r=0):
return Decimal(str(f)).quantize(Decimal(str(r)), rounding=ROUND_HALF_UP)
def main():
H, W = list(map(int, readline().rstrip().split()))
ans = H * W
if H >= 3:
y1 = int(round(H / 3))
y2 = (H - y1) // 2
y3 = H - y1 - y2
ans = min(ans, max(W * y1, W * y2, W * y3) - min(W * y1, W * y2, W * y3))
if W >= 3:
x1 = int(round(W / 3))
x2 = (W - x1) // 2
x3 = W - x1 - x2
ans = min(ans, max(x1 * H, x2 * H, x3 * H) - min(x1 * H, x2 * H, x3 * H))
# 縦にスライス + 残りに横にスライス
x1_cand = [floor(W / 3), ceil(W / 3)]
# x1_cand = [i for i in range(1, W)]
y1 = H
for x1 in x1_cand:
x2 = W - x1
x3 = x2
y2 = H // 2
y3 = H - y2
ans = min(
ans,
max((x1 * y1), (x2 * y2), (x3 * y3)) - min((x1 * y1), (x2 * y2), (x3 * y3)),
)
# 横にスライス + 残りに縦にスライス
y1_cand = [floor(H / 3), ceil(H / 3)]
# y1_cand = [i for i in range(1, H)]
x1 = W
for y1 in y1_cand:
y2 = H - y1
y3 = y2
x2 = W // 2
x3 = W - x2
ans = min(
ans,
max((x1 * y1), (x2 * y2), (x3 * y3)) - min((x1 * y1), (x2 * y2), (x3 * y3)),
)
print(ans)
if __name__ == "__main__":
main()
| import sys
readline = sys.stdin.readline
from math import floor, ceil
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
def round(f, r=0):
return Decimal(str(f)).quantize(Decimal(str(r)), rounding=ROUND_HALF_UP)
def main():
H, W = list(map(int, readline().rstrip().split()))
ans = H * W
if H >= 3:
y1 = int(round(H / 3))
y2 = (H - y1) // 2
y3 = H - y1 - y2
ans = min(ans, max(W * y1, W * y2, W * y3) - min(W * y1, W * y2, W * y3))
if W >= 3:
x1 = int(round(W / 3))
x2 = (W - x1) // 2
x3 = W - x1 - x2
ans = min(ans, max(x1 * H, x2 * H, x3 * H) - min(x1 * H, x2 * H, x3 * H))
# 縦にスライス + 残りに横にスライス
x1_cand = [int(round(W / 3))]
y1 = H
for x1 in x1_cand:
x2 = W - x1
x3 = x2
y2 = H // 2
y3 = H - y2
ans = min(
ans,
max((x1 * y1), (x2 * y2), (x3 * y3)) - min((x1 * y1), (x2 * y2), (x3 * y3)),
)
# 横にスライス + 残りに縦にスライス
y1_cand = [int(round(H / 3))]
x1 = W
for y1 in y1_cand:
y2 = H - y1
y3 = y2
x2 = W // 2
x3 = W - x2
ans = min(
ans,
max((x1 * y1), (x2 * y2), (x3 * y3)) - min((x1 * y1), (x2 * y2), (x3 * y3)),
)
print(ans)
if __name__ == "__main__":
main()
| false | 2.12766 | [
"- x1_cand = [floor(W / 3), ceil(W / 3)]",
"- # x1_cand = [i for i in range(1, W)]",
"+ x1_cand = [int(round(W / 3))]",
"- y1_cand = [floor(H / 3), ceil(H / 3)]",
"- # y1_cand = [i for i in range(1, H)]",
"+ y1_cand = [int(round(H / 3))]"
] | false | 0.007435 | 0.040947 | 0.18158 | [
"s218787061",
"s704448190"
] |
u944325914 | p02614 | python | s068941655 | s165122974 | 130 | 54 | 9,340 | 9,148 | Accepted | Accepted | 58.46 | import copy
h,w,k=list(map(int,input().split()))
v=[]
for _ in range(h):
array=list(eval(input()))
v.append(array)
ans=0
for a in range(2**h):
c=copy.deepcopy(v)
for b in range(h):
if a>>b & 1:
for d in range(w):
c[b][d]=0
for e in range(2**w):
z=copy.deepcopy(c)
temp=0
for f in range(w):
if e>>f & 1:
for g in range(h):
z[g][f]=0
for p in range(h):
temp+=z[p].count("#")
if temp==k:
ans+=1
print(ans) | from itertools import product
h,w,k=list(map(int,input().split()))
c=[list(eval(input())) for _ in range(h)]
ans=0
for i in product([0,1],repeat=h):
for j in product([0,1],repeat=w):
temp=0
for m in range(h):
for n in range(w):
if i[m]==0 and j[n]==0 and c[m][n]=="#":
temp+=1
if temp==k:
ans+=1
print(ans)
| 25 | 16 | 546 | 371 | import copy
h, w, k = list(map(int, input().split()))
v = []
for _ in range(h):
array = list(eval(input()))
v.append(array)
ans = 0
for a in range(2**h):
c = copy.deepcopy(v)
for b in range(h):
if a >> b & 1:
for d in range(w):
c[b][d] = 0
for e in range(2**w):
z = copy.deepcopy(c)
temp = 0
for f in range(w):
if e >> f & 1:
for g in range(h):
z[g][f] = 0
for p in range(h):
temp += z[p].count("#")
if temp == k:
ans += 1
print(ans)
| from itertools import product
h, w, k = list(map(int, input().split()))
c = [list(eval(input())) for _ in range(h)]
ans = 0
for i in product([0, 1], repeat=h):
for j in product([0, 1], repeat=w):
temp = 0
for m in range(h):
for n in range(w):
if i[m] == 0 and j[n] == 0 and c[m][n] == "#":
temp += 1
if temp == k:
ans += 1
print(ans)
| false | 36 | [
"-import copy",
"+from itertools import product",
"-v = []",
"-for _ in range(h):",
"- array = list(eval(input()))",
"- v.append(array)",
"+c = [list(eval(input())) for _ in range(h)]",
"-for a in range(2**h):",
"- c = copy.deepcopy(v)",
"- for b in range(h):",
"- if a >> b & 1:",
"- for d in range(w):",
"- c[b][d] = 0",
"- for e in range(2**w):",
"- z = copy.deepcopy(c)",
"+for i in product([0, 1], repeat=h):",
"+ for j in product([0, 1], repeat=w):",
"- for f in range(w):",
"- if e >> f & 1:",
"- for g in range(h):",
"- z[g][f] = 0",
"- for p in range(h):",
"- temp += z[p].count(\"#\")",
"+ for m in range(h):",
"+ for n in range(w):",
"+ if i[m] == 0 and j[n] == 0 and c[m][n] == \"#\":",
"+ temp += 1"
] | false | 0.035077 | 0.029189 | 1.201703 | [
"s068941655",
"s165122974"
] |
u588341295 | p02883 | python | s129189946 | s935122693 | 1,952 | 1,079 | 115,200 | 113,408 | Accepted | Accepted | 44.72 | # -*- 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 ** 7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def bisearch_min(mn, mx, func):
""" 条件を満たす最小値を見つける二分探索 """
ok = mx
ng = mn
while ng+1 < ok:
mid = (ok+ng) // 2
if func(mid):
# 下を探しに行く
ok = mid
else:
# 上を探しに行く
ng = mid
return ok
N, K = MAP()
A = LIST()
B = LIST()
A.sort(reverse=True)
B.sort()
def check(m):
k = 0
for i, a in enumerate(A):
b = B[i]
k += max(ceil(a - m/b), 0)
if k > K:
return False
return True
print((bisearch_min(-1, INF, check)))
| # -*- 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 ** 7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def bisearch_min(mn, mx, func):
""" 条件を満たす最小値を見つける二分探索 """
ok = mx
ng = mn
while ng+1 < ok:
mid = (ok+ng) // 2
if func(mid):
# 下を探しに行く
ok = mid
else:
# 上を探しに行く
ng = mid
return ok
N, K = MAP()
A = LIST()
B = LIST()
A.sort(reverse=True)
B.sort()
def check(m):
k = 0
for i, a in enumerate(A):
b = B[i]
k += max(ceil(a - m/b), 0)
if k > K:
return False
return True
print((bisearch_min(-1, 10**12, check)))
| 52 | 52 | 1,270 | 1,273 | # -*- 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**7)
INF = 10**18
MOD = 10**9 + 7
def bisearch_min(mn, mx, func):
"""条件を満たす最小値を見つける二分探索"""
ok = mx
ng = mn
while ng + 1 < ok:
mid = (ok + ng) // 2
if func(mid):
# 下を探しに行く
ok = mid
else:
# 上を探しに行く
ng = mid
return ok
N, K = MAP()
A = LIST()
B = LIST()
A.sort(reverse=True)
B.sort()
def check(m):
k = 0
for i, a in enumerate(A):
b = B[i]
k += max(ceil(a - m / b), 0)
if k > K:
return False
return True
print((bisearch_min(-1, INF, check)))
| # -*- 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**7)
INF = 10**18
MOD = 10**9 + 7
def bisearch_min(mn, mx, func):
"""条件を満たす最小値を見つける二分探索"""
ok = mx
ng = mn
while ng + 1 < ok:
mid = (ok + ng) // 2
if func(mid):
# 下を探しに行く
ok = mid
else:
# 上を探しに行く
ng = mid
return ok
N, K = MAP()
A = LIST()
B = LIST()
A.sort(reverse=True)
B.sort()
def check(m):
k = 0
for i, a in enumerate(A):
b = B[i]
k += max(ceil(a - m / b), 0)
if k > K:
return False
return True
print((bisearch_min(-1, 10**12, check)))
| false | 0 | [
"-print((bisearch_min(-1, INF, check)))",
"+print((bisearch_min(-1, 10**12, check)))"
] | false | 0.065472 | 0.097824 | 0.669281 | [
"s129189946",
"s935122693"
] |
u455696302 | p03408 | python | s582553876 | s537162647 | 19 | 17 | 3,064 | 3,064 | Accepted | Accepted | 10.53 | N = int(eval(input()))
S = [eval(input()) for _ in range(N)]
M = int(eval(input()))
T = [eval(input()) for _ in range(M)]
Sw = list(set(S))
Tw = list(set(T))
mm = 0
for i in Sw:
tmp = S.count(i) - T.count(i)
if mm < tmp:
mm = tmp
for i in Tw:
tmp = S.count(i) - T.count(i)
if mm < tmp:
mm = tmp
print(mm) | N = int(eval(input()))
S = [eval(input()) for _ in range(N)]
M = int(eval(input()))
T = [eval(input()) for _ in range(M)]
red = {}
for i in T:
if i not in red:
red[i] = 1
else:
red[i] += 1
blue = {}
for i in S:
if i not in blue:
blue[i] = 1
else:
blue[i] += 1
res = 0
for i in set(S):
if i not in red:
tmp = blue[i]
else:
tmp = blue[i] - red[i]
if res < tmp:
res = tmp
print(res)
| 20 | 30 | 337 | 474 | N = int(eval(input()))
S = [eval(input()) for _ in range(N)]
M = int(eval(input()))
T = [eval(input()) for _ in range(M)]
Sw = list(set(S))
Tw = list(set(T))
mm = 0
for i in Sw:
tmp = S.count(i) - T.count(i)
if mm < tmp:
mm = tmp
for i in Tw:
tmp = S.count(i) - T.count(i)
if mm < tmp:
mm = tmp
print(mm)
| N = int(eval(input()))
S = [eval(input()) for _ in range(N)]
M = int(eval(input()))
T = [eval(input()) for _ in range(M)]
red = {}
for i in T:
if i not in red:
red[i] = 1
else:
red[i] += 1
blue = {}
for i in S:
if i not in blue:
blue[i] = 1
else:
blue[i] += 1
res = 0
for i in set(S):
if i not in red:
tmp = blue[i]
else:
tmp = blue[i] - red[i]
if res < tmp:
res = tmp
print(res)
| false | 33.333333 | [
"-Sw = list(set(S))",
"-Tw = list(set(T))",
"-mm = 0",
"-for i in Sw:",
"- tmp = S.count(i) - T.count(i)",
"- if mm < tmp:",
"- mm = tmp",
"-for i in Tw:",
"- tmp = S.count(i) - T.count(i)",
"- if mm < tmp:",
"- mm = tmp",
"-print(mm)",
"+red = {}",
"+for i in T:",
"+ if i not in red:",
"+ red[i] = 1",
"+ else:",
"+ red[i] += 1",
"+blue = {}",
"+for i in S:",
"+ if i not in blue:",
"+ blue[i] = 1",
"+ else:",
"+ blue[i] += 1",
"+res = 0",
"+for i in set(S):",
"+ if i not in red:",
"+ tmp = blue[i]",
"+ else:",
"+ tmp = blue[i] - red[i]",
"+ if res < tmp:",
"+ res = tmp",
"+print(res)"
] | false | 0.066994 | 0.054262 | 1.234633 | [
"s582553876",
"s537162647"
] |
u072717685 | p03416 | python | s366433774 | s295519632 | 71 | 50 | 2,940 | 9,164 | Accepted | Accepted | 29.58 | def main():
a, b = list(map(int,input().split()))
r = 0
for i in range(a, b + 1):
r += str(i) == str(i)[::-1]
print(r)
if __name__ == '__main__':
main() | import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
a, b = list(map(int, input().split()))
r = 0
for i1 in range(a, b + 1):
stri1 = str(i1)
r += stri1 == stri1[::-1]
print(r)
if __name__ == '__main__':
main()
| 10 | 14 | 185 | 279 | def main():
a, b = list(map(int, input().split()))
r = 0
for i in range(a, b + 1):
r += str(i) == str(i)[::-1]
print(r)
if __name__ == "__main__":
main()
| import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
a, b = list(map(int, input().split()))
r = 0
for i1 in range(a, b + 1):
stri1 = str(i1)
r += stri1 == stri1[::-1]
print(r)
if __name__ == "__main__":
main()
| false | 28.571429 | [
"+import sys",
"+",
"+read = sys.stdin.read",
"+readlines = sys.stdin.readlines",
"+",
"+",
"- for i in range(a, b + 1):",
"- r += str(i) == str(i)[::-1]",
"+ for i1 in range(a, b + 1):",
"+ stri1 = str(i1)",
"+ r += stri1 == stri1[::-1]"
] | false | 0.04736 | 0.040972 | 1.155892 | [
"s366433774",
"s295519632"
] |
u753803401 | p03547 | python | s612574008 | s815454772 | 28 | 17 | 2,940 | 2,940 | Accepted | Accepted | 39.29 | x, y = list(map(str, input().split()))
if x < y:
print("<")
elif x > y:
print(">")
else:
print("=")
| x, y = input().split()
if x < y:
print("<")
elif x > y:
print(">")
else:
print("=")
| 7 | 7 | 112 | 102 | x, y = list(map(str, input().split()))
if x < y:
print("<")
elif x > y:
print(">")
else:
print("=")
| x, y = input().split()
if x < y:
print("<")
elif x > y:
print(">")
else:
print("=")
| false | 0 | [
"-x, y = list(map(str, input().split()))",
"+x, y = input().split()"
] | false | 0.037147 | 0.039348 | 0.944068 | [
"s612574008",
"s815454772"
] |
u018679195 | p02785 | python | s440370586 | s404940276 | 162 | 145 | 26,180 | 105,392 | Accepted | Accepted | 10.49 | nk = list(map(int,input().split()))
n,k = nk
h = list(map(int,input().split()))
if k >= len(h):
print((0))
else:
h.sort()
for i in range (k):
h.pop()
print((sum(h))) | nMonsters, nSpecial = [int(x) for x in input().split()]
monst = [int(x) for x in input().split()]
monst.sort()
nMonsters -= nSpecial
if nMonsters < 0:
print((0))
else:
print((sum(monst[0:nMonsters])))
| 10 | 12 | 194 | 220 | nk = list(map(int, input().split()))
n, k = nk
h = list(map(int, input().split()))
if k >= len(h):
print((0))
else:
h.sort()
for i in range(k):
h.pop()
print((sum(h)))
| nMonsters, nSpecial = [int(x) for x in input().split()]
monst = [int(x) for x in input().split()]
monst.sort()
nMonsters -= nSpecial
if nMonsters < 0:
print((0))
else:
print((sum(monst[0:nMonsters])))
| false | 16.666667 | [
"-nk = list(map(int, input().split()))",
"-n, k = nk",
"-h = list(map(int, input().split()))",
"-if k >= len(h):",
"+nMonsters, nSpecial = [int(x) for x in input().split()]",
"+monst = [int(x) for x in input().split()]",
"+monst.sort()",
"+nMonsters -= nSpecial",
"+if nMonsters < 0:",
"- h.sort()",
"- for i in range(k):",
"- h.pop()",
"- print((sum(h)))",
"+ print((sum(monst[0:nMonsters])))"
] | false | 0.071164 | 0.070132 | 1.014705 | [
"s440370586",
"s404940276"
] |
u186838327 | p03103 | python | s995949399 | s791657649 | 859 | 383 | 53,208 | 78,900 | Accepted | Accepted | 55.41 | n, m = list(map(int, input().split()))
AB = []
for i in range(n):
a, b = list(map(int, input().split()))
AB.append((a, b))
AB.sort()
ans = 0
for i in range(n):
a, b = AB[i]
if b >= m:
ans += a*m
break
else:
ans += a*b
m -= b
print(ans)
| n, m = list(map(int, input().split()))
AB = []
for i in range(n):
a, b = list(map(int, input().split()))
AB.append((a, b))
AB.sort()
ans = 0
for a, b in AB:
if b <= m:
ans += a*b
m -= b
else:
ans += a*m
m = 0
if m == 0:
break
print(ans)
| 17 | 18 | 289 | 303 | n, m = list(map(int, input().split()))
AB = []
for i in range(n):
a, b = list(map(int, input().split()))
AB.append((a, b))
AB.sort()
ans = 0
for i in range(n):
a, b = AB[i]
if b >= m:
ans += a * m
break
else:
ans += a * b
m -= b
print(ans)
| n, m = list(map(int, input().split()))
AB = []
for i in range(n):
a, b = list(map(int, input().split()))
AB.append((a, b))
AB.sort()
ans = 0
for a, b in AB:
if b <= m:
ans += a * b
m -= b
else:
ans += a * m
m = 0
if m == 0:
break
print(ans)
| false | 5.555556 | [
"-for i in range(n):",
"- a, b = AB[i]",
"- if b >= m:",
"+for a, b in AB:",
"+ if b <= m:",
"+ ans += a * b",
"+ m -= b",
"+ else:",
"+ m = 0",
"+ if m == 0:",
"- else:",
"- ans += a * b",
"- m -= b"
] | false | 0.037077 | 0.037186 | 0.997073 | [
"s995949399",
"s791657649"
] |
u536113865 | p03627 | python | s148875753 | s469036728 | 104 | 81 | 14,224 | 18,216 | Accepted | Accepted | 22.12 | n = int(eval(input()))
a = list(map(int, input().split()))
a.sort()
f,s,i = 0,0,0
while i+1<n:
if a[i]==a[i+1]:
s = f
f = a[i]
i += 1
i += 1
print((f*s))
| ai = lambda: list(map(int, input().split()))
n = int(eval(input()))
a = ai()
from collections import Counter
c = Counter(a)
a = [i for i in c if c[i]>1]
a.sort()
if len(a)>0 and c[a[-1]]>=4:
print((a[-1]**2))
elif len(a)<2:
print((0))
else:
print((a[-1]*a[-2])) | 11 | 14 | 188 | 275 | n = int(eval(input()))
a = list(map(int, input().split()))
a.sort()
f, s, i = 0, 0, 0
while i + 1 < n:
if a[i] == a[i + 1]:
s = f
f = a[i]
i += 1
i += 1
print((f * s))
| ai = lambda: list(map(int, input().split()))
n = int(eval(input()))
a = ai()
from collections import Counter
c = Counter(a)
a = [i for i in c if c[i] > 1]
a.sort()
if len(a) > 0 and c[a[-1]] >= 4:
print((a[-1] ** 2))
elif len(a) < 2:
print((0))
else:
print((a[-1] * a[-2]))
| false | 21.428571 | [
"+ai = lambda: list(map(int, input().split()))",
"-a = list(map(int, input().split()))",
"+a = ai()",
"+from collections import Counter",
"+",
"+c = Counter(a)",
"+a = [i for i in c if c[i] > 1]",
"-f, s, i = 0, 0, 0",
"-while i + 1 < n:",
"- if a[i] == a[i + 1]:",
"- s = f",
"- f = a[i]",
"- i += 1",
"- i += 1",
"-print((f * s))",
"+if len(a) > 0 and c[a[-1]] >= 4:",
"+ print((a[-1] ** 2))",
"+elif len(a) < 2:",
"+ print((0))",
"+else:",
"+ print((a[-1] * a[-2]))"
] | false | 0.099792 | 0.05194 | 1.921284 | [
"s148875753",
"s469036728"
] |
u225388820 | p03660 | python | s057531669 | s961619886 | 377 | 285 | 117,900 | 32,224 | Accepted | Accepted | 24.4 | import sys
sys.setrecursionlimit(1000000000)
input = sys.stdin.readline
n = int(eval(input()))
es=[[] for i in range(n)]
for i in range(n - 1):
a, b = list(map(int, input().split()))
es[a - 1].append(b - 1)
es[b - 1].append(a - 1)
def dfs0(v, d, p):
if v == n - 1:
return d
for e in es[v]:
if e != p:
k = dfs0(e, d + 1, v)
if k:
if isinstance(k, int) and k // 2 == d:
return v, e
return k
return 0
def dfs1(v, p):
if v == E:
return 0
cnt = 1
for e in es[v]:
if e != p:
cnt += dfs1(e, v)
return cnt
V, E = dfs0(0, 0, -1)
if 2*dfs1(0, -1) > n:
print("Fennec")
else:
print("Snuke")
| import sys
sys.setrecursionlimit(1000000000)
input = sys.stdin.readline
from collections import deque
n = int(eval(input()))
es=[[] for i in range(n)]
for i in range(n - 1):
a, b = list(map(int, input().split()))
es[a - 1].append(b - 1)
es[b - 1].append(a - 1)
INF = 1 << 32
d = [INF] * n
d[0] = 0
q = deque([0])
while q:
v = q.popleft()
for e in es[v]:
if d[e] == INF:
d[e] = d[v] + 1
q.append(e)
d2 = [INF] * n
q.append(n - 1)
d2[n - 1] = 0
while q:
v = q.popleft()
for e in es[v]:
if d2[e] == INF and d2[v] + 1 < d[e]:
d2[e] = d2[v] + 1
q.append(e)
print(("Fennec" if 2 * sum(1 for i in d2 if i < INF) < n else "Snuke")) | 35 | 31 | 769 | 730 | import sys
sys.setrecursionlimit(1000000000)
input = sys.stdin.readline
n = int(eval(input()))
es = [[] for i in range(n)]
for i in range(n - 1):
a, b = list(map(int, input().split()))
es[a - 1].append(b - 1)
es[b - 1].append(a - 1)
def dfs0(v, d, p):
if v == n - 1:
return d
for e in es[v]:
if e != p:
k = dfs0(e, d + 1, v)
if k:
if isinstance(k, int) and k // 2 == d:
return v, e
return k
return 0
def dfs1(v, p):
if v == E:
return 0
cnt = 1
for e in es[v]:
if e != p:
cnt += dfs1(e, v)
return cnt
V, E = dfs0(0, 0, -1)
if 2 * dfs1(0, -1) > n:
print("Fennec")
else:
print("Snuke")
| import sys
sys.setrecursionlimit(1000000000)
input = sys.stdin.readline
from collections import deque
n = int(eval(input()))
es = [[] for i in range(n)]
for i in range(n - 1):
a, b = list(map(int, input().split()))
es[a - 1].append(b - 1)
es[b - 1].append(a - 1)
INF = 1 << 32
d = [INF] * n
d[0] = 0
q = deque([0])
while q:
v = q.popleft()
for e in es[v]:
if d[e] == INF:
d[e] = d[v] + 1
q.append(e)
d2 = [INF] * n
q.append(n - 1)
d2[n - 1] = 0
while q:
v = q.popleft()
for e in es[v]:
if d2[e] == INF and d2[v] + 1 < d[e]:
d2[e] = d2[v] + 1
q.append(e)
print(("Fennec" if 2 * sum(1 for i in d2 if i < INF) < n else "Snuke"))
| false | 11.428571 | [
"+from collections import deque",
"+",
"-",
"-",
"-def dfs0(v, d, p):",
"- if v == n - 1:",
"- return d",
"+INF = 1 << 32",
"+d = [INF] * n",
"+d[0] = 0",
"+q = deque([0])",
"+while q:",
"+ v = q.popleft()",
"- if e != p:",
"- k = dfs0(e, d + 1, v)",
"- if k:",
"- if isinstance(k, int) and k // 2 == d:",
"- return v, e",
"- return k",
"- return 0",
"-",
"-",
"-def dfs1(v, p):",
"- if v == E:",
"- return 0",
"- cnt = 1",
"+ if d[e] == INF:",
"+ d[e] = d[v] + 1",
"+ q.append(e)",
"+d2 = [INF] * n",
"+q.append(n - 1)",
"+d2[n - 1] = 0",
"+while q:",
"+ v = q.popleft()",
"- if e != p:",
"- cnt += dfs1(e, v)",
"- return cnt",
"-",
"-",
"-V, E = dfs0(0, 0, -1)",
"-if 2 * dfs1(0, -1) > n:",
"- print(\"Fennec\")",
"-else:",
"- print(\"Snuke\")",
"+ if d2[e] == INF and d2[v] + 1 < d[e]:",
"+ d2[e] = d2[v] + 1",
"+ q.append(e)",
"+print((\"Fennec\" if 2 * sum(1 for i in d2 if i < INF) < n else \"Snuke\"))"
] | false | 0.127086 | 0.048133 | 2.64031 | [
"s057531669",
"s961619886"
] |
u838644735 | p02928 | python | s223382026 | s255369883 | 226 | 189 | 41,692 | 41,708 | Accepted | Accepted | 16.37 | N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
class Bit:
def __init__(self, n):
self.size = n
self.tree = [0] * (n + 1)
def sum(self, i):
ret = 0
while i > 0:
ret += self.tree[i]
i -= i & -i
return ret
def add(self, i, x):
while i <= self.size:
self.tree[i] += x
i += i & -i
inter = 0
for i in range(N):
ai = A[i]
for j in range(i + 1):
aj = A[j]
if ai > aj:
inter += 1
bit = Bit(2000)
intra = 0
for i in range(len(A)):
a = A[i]
bit.add(a, 1)
intra += i + 1 - bit.sum(a)
# print(inter, intra)
mod = 10**9 + 7
ans = (intra * K * (K + 1) // 2) % mod
ans += (inter * (K - 1) * K // 2) % mod
print((ans % mod))
| N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
class Bit:
def __init__(self, n):
self.size = n
self.tree = [0] * (n + 1)
def sum(self, i):
ret = 0
while i > 0:
ret += self.tree[i]
i -= i & -i
return ret
def add(self, i, x):
while i <= self.size:
self.tree[i] += x
i += i & -i
# inter = 0
# for i in range(N):
# ai = A[i]
# for j in range(i + 1):
# aj = A[j]
# if ai > aj:
# inter += 1
bit = Bit(2000)
intra = 0
inter = 0
for i in range(len(A)):
a = A[i]
bit.add(a, 1)
intra += i + 1 - bit.sum(a)
if a != 1:
inter += bit.sum(a - 1)
# for i in range(len(A)):
# a = A[i]
# if a != 1:
# inter += bit.sum(a - 1)
# print(inter, intra)
mod = 10**9 + 7
ans = (intra * K * (K + 1) // 2) % mod
ans += (inter * (K - 1) * K // 2) % mod
print((ans % mod))
| 43 | 51 | 835 | 1,007 | N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
class Bit:
def __init__(self, n):
self.size = n
self.tree = [0] * (n + 1)
def sum(self, i):
ret = 0
while i > 0:
ret += self.tree[i]
i -= i & -i
return ret
def add(self, i, x):
while i <= self.size:
self.tree[i] += x
i += i & -i
inter = 0
for i in range(N):
ai = A[i]
for j in range(i + 1):
aj = A[j]
if ai > aj:
inter += 1
bit = Bit(2000)
intra = 0
for i in range(len(A)):
a = A[i]
bit.add(a, 1)
intra += i + 1 - bit.sum(a)
# print(inter, intra)
mod = 10**9 + 7
ans = (intra * K * (K + 1) // 2) % mod
ans += (inter * (K - 1) * K // 2) % mod
print((ans % mod))
| N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
class Bit:
def __init__(self, n):
self.size = n
self.tree = [0] * (n + 1)
def sum(self, i):
ret = 0
while i > 0:
ret += self.tree[i]
i -= i & -i
return ret
def add(self, i, x):
while i <= self.size:
self.tree[i] += x
i += i & -i
# inter = 0
# for i in range(N):
# ai = A[i]
# for j in range(i + 1):
# aj = A[j]
# if ai > aj:
# inter += 1
bit = Bit(2000)
intra = 0
inter = 0
for i in range(len(A)):
a = A[i]
bit.add(a, 1)
intra += i + 1 - bit.sum(a)
if a != 1:
inter += bit.sum(a - 1)
# for i in range(len(A)):
# a = A[i]
# if a != 1:
# inter += bit.sum(a - 1)
# print(inter, intra)
mod = 10**9 + 7
ans = (intra * K * (K + 1) // 2) % mod
ans += (inter * (K - 1) * K // 2) % mod
print((ans % mod))
| false | 15.686275 | [
"-inter = 0",
"-for i in range(N):",
"- ai = A[i]",
"- for j in range(i + 1):",
"- aj = A[j]",
"- if ai > aj:",
"- inter += 1",
"+# inter = 0",
"+# for i in range(N):",
"+# ai = A[i]",
"+# for j in range(i + 1):",
"+# aj = A[j]",
"+# if ai > aj:",
"+# inter += 1",
"+inter = 0",
"+ if a != 1:",
"+ inter += bit.sum(a - 1)",
"+# for i in range(len(A)):",
"+# a = A[i]",
"+# if a != 1:",
"+# inter += bit.sum(a - 1)"
] | false | 0.042676 | 0.054 | 0.790298 | [
"s223382026",
"s255369883"
] |
u320511454 | p03295 | python | s415201325 | s062876372 | 447 | 412 | 29,080 | 30,216 | Accepted | Accepted | 7.83 | n,m=list(map(int,input().split()))
M=[list(map(int,input().split())) for _ in range(m)]
M.sort(key=lambda X: X[1])
end,ans=0,0
for i in range(m):
if M[i][0] >= end:
ans += 1
end=M[i][1]
print(ans) | n,m=list(map(int,input().split()))
M=[list(map(int,input().split())) for _ in range(m)]
M.sort(key=lambda X: X[1])
end,ans=0,0
for a,b in M:
if a >= end:
ans += 1
end=b
print(ans) | 10 | 10 | 216 | 199 | n, m = list(map(int, input().split()))
M = [list(map(int, input().split())) for _ in range(m)]
M.sort(key=lambda X: X[1])
end, ans = 0, 0
for i in range(m):
if M[i][0] >= end:
ans += 1
end = M[i][1]
print(ans)
| n, m = list(map(int, input().split()))
M = [list(map(int, input().split())) for _ in range(m)]
M.sort(key=lambda X: X[1])
end, ans = 0, 0
for a, b in M:
if a >= end:
ans += 1
end = b
print(ans)
| false | 0 | [
"-for i in range(m):",
"- if M[i][0] >= end:",
"+for a, b in M:",
"+ if a >= end:",
"- end = M[i][1]",
"+ end = b"
] | false | 0.03705 | 0.073243 | 0.505859 | [
"s415201325",
"s062876372"
] |
u179169725 | p03037 | python | s106252952 | s674711363 | 357 | 282 | 3,060 | 8,892 | Accepted | Accepted | 21.01 | # https://atcoder.jp/contests/abc127/tasks/abc127_c
N, M = list(map(int, input().split()))
L = 0
R = N
for _ in range(M):
l, r = list(map(int, input().split()))
L = max(L, l)
R = min(R, r)
print((max(R - L + 1, 0)))
| # https://atcoder.jp/contests/abc127/tasks/abc127_c
# 脳死でimosで殴っても良い
class Imos1d:
def __init__(self, N: int):
'''
[0]*N の配列に対して、区間の加算を管理する。
'''
self.ls = [0] * (N + 1) # 配列外参照を防ぐため多くとっておく
self.N = N
def add(self, l, r, x):
'''
[l,r)の区間にxを足し込む O(1)
'''
self.ls[l] += x
self.ls[min(r, self.N)] -= x # 配列外参照は余分に作ったところにまとめておく(どうせ使わない)
def get_result(self):
'''
O(N) かけて、区間の加算結果を取得する
'''
from itertools import accumulate
return list(accumulate(self.ls[:-1]))
import sys
read = sys.stdin.readline
def read_ints():
return list(map(int, read().split()))
N, M = read_ints()
imos = Imos1d(N) # 各idカードはいくつのゲートを通ることができるのか
for _ in range(M):
l, r = read_ints()
imos.add(l - 1, r, 1)
print((sum([M == x for x in imos.get_result()])))
| 10 | 41 | 236 | 916 | # https://atcoder.jp/contests/abc127/tasks/abc127_c
N, M = list(map(int, input().split()))
L = 0
R = N
for _ in range(M):
l, r = list(map(int, input().split()))
L = max(L, l)
R = min(R, r)
print((max(R - L + 1, 0)))
| # https://atcoder.jp/contests/abc127/tasks/abc127_c
# 脳死でimosで殴っても良い
class Imos1d:
def __init__(self, N: int):
"""
[0]*N の配列に対して、区間の加算を管理する。
"""
self.ls = [0] * (N + 1) # 配列外参照を防ぐため多くとっておく
self.N = N
def add(self, l, r, x):
"""
[l,r)の区間にxを足し込む O(1)
"""
self.ls[l] += x
self.ls[min(r, self.N)] -= x # 配列外参照は余分に作ったところにまとめておく(どうせ使わない)
def get_result(self):
"""
O(N) かけて、区間の加算結果を取得する
"""
from itertools import accumulate
return list(accumulate(self.ls[:-1]))
import sys
read = sys.stdin.readline
def read_ints():
return list(map(int, read().split()))
N, M = read_ints()
imos = Imos1d(N) # 各idカードはいくつのゲートを通ることができるのか
for _ in range(M):
l, r = read_ints()
imos.add(l - 1, r, 1)
print((sum([M == x for x in imos.get_result()])))
| false | 75.609756 | [
"-N, M = list(map(int, input().split()))",
"-L = 0",
"-R = N",
"+# 脳死でimosで殴っても良い",
"+class Imos1d:",
"+ def __init__(self, N: int):",
"+ \"\"\"",
"+ [0]*N の配列に対して、区間の加算を管理する。",
"+ \"\"\"",
"+ self.ls = [0] * (N + 1) # 配列外参照を防ぐため多くとっておく",
"+ self.N = N",
"+",
"+ def add(self, l, r, x):",
"+ \"\"\"",
"+ [l,r)の区間にxを足し込む O(1)",
"+ \"\"\"",
"+ self.ls[l] += x",
"+ self.ls[min(r, self.N)] -= x # 配列外参照は余分に作ったところにまとめておく(どうせ使わない)",
"+",
"+ def get_result(self):",
"+ \"\"\"",
"+ O(N) かけて、区間の加算結果を取得する",
"+ \"\"\"",
"+ from itertools import accumulate",
"+",
"+ return list(accumulate(self.ls[:-1]))",
"+",
"+",
"+import sys",
"+",
"+read = sys.stdin.readline",
"+",
"+",
"+def read_ints():",
"+ return list(map(int, read().split()))",
"+",
"+",
"+N, M = read_ints()",
"+imos = Imos1d(N) # 各idカードはいくつのゲートを通ることができるのか",
"- l, r = list(map(int, input().split()))",
"- L = max(L, l)",
"- R = min(R, r)",
"-print((max(R - L + 1, 0)))",
"+ l, r = read_ints()",
"+ imos.add(l - 1, r, 1)",
"+print((sum([M == x for x in imos.get_result()])))"
] | false | 0.036772 | 0.035459 | 1.037028 | [
"s106252952",
"s674711363"
] |
u074220993 | p03762 | python | s658136218 | s281041910 | 117 | 104 | 25,396 | 24,456 | Accepted | Accepted | 11.11 | n, m = list(map(int, input().split()))
x = [x for x in map(int, input().split())]
y = [y for y in map(int, input().split())]
sum_x = 0
sum_y = 0
ans = 0
for i in range(n):
sum_x += (2*i - n + 1) * x[i]
for j in range(m):
sum_y += (2*j - m + 1) * y[j]
ans = sum_x * sum_y
print((ans%1000000007)) | n, m = list(map(int, input().split()))
X = sorted([int(x) for x in input().split()])
Y = sorted([int(x) for x in input().split()])
mod = 1000000007
def diffSum(X): #Σ(X[j]-X[i]) 1<=i<j<=N
l = len(X)
Res = [(2*i-l+1)*X[i] for i in range(l)]
return sum(Res)%mod
print((diffSum(X)*diffSum(Y)%mod)) | 12 | 11 | 306 | 310 | n, m = list(map(int, input().split()))
x = [x for x in map(int, input().split())]
y = [y for y in map(int, input().split())]
sum_x = 0
sum_y = 0
ans = 0
for i in range(n):
sum_x += (2 * i - n + 1) * x[i]
for j in range(m):
sum_y += (2 * j - m + 1) * y[j]
ans = sum_x * sum_y
print((ans % 1000000007))
| n, m = list(map(int, input().split()))
X = sorted([int(x) for x in input().split()])
Y = sorted([int(x) for x in input().split()])
mod = 1000000007
def diffSum(X): # Σ(X[j]-X[i]) 1<=i<j<=N
l = len(X)
Res = [(2 * i - l + 1) * X[i] for i in range(l)]
return sum(Res) % mod
print((diffSum(X) * diffSum(Y) % mod))
| false | 8.333333 | [
"-x = [x for x in map(int, input().split())]",
"-y = [y for y in map(int, input().split())]",
"-sum_x = 0",
"-sum_y = 0",
"-ans = 0",
"-for i in range(n):",
"- sum_x += (2 * i - n + 1) * x[i]",
"-for j in range(m):",
"- sum_y += (2 * j - m + 1) * y[j]",
"-ans = sum_x * sum_y",
"-print((ans % 1000000007))",
"+X = sorted([int(x) for x in input().split()])",
"+Y = sorted([int(x) for x in input().split()])",
"+mod = 1000000007",
"+",
"+",
"+def diffSum(X): # Σ(X[j]-X[i]) 1<=i<j<=N",
"+ l = len(X)",
"+ Res = [(2 * i - l + 1) * X[i] for i in range(l)]",
"+ return sum(Res) % mod",
"+",
"+",
"+print((diffSum(X) * diffSum(Y) % mod))"
] | false | 0.044894 | 0.045074 | 0.995998 | [
"s658136218",
"s281041910"
] |
u114920558 | p03283 | python | s644034941 | s194354361 | 2,831 | 1,713 | 53,208 | 57,304 | Accepted | Accepted | 39.49 | N, M, Q = list(map(int, input().split()))
train = [[0]*(N+1) for _ in range(N+1)]
for i in range(M):
a, b = list(map(int, input().split()))
train[a][b] += 1
for i in range(1, N+1):
for j in range(1, N+1):
train[i][j] += train[i][j-1]
for i in range(Q):
ans = 0
l, r = list(map(int, input().split()))
for j in range(l, r+1):
ans += train[j][r]-train[j][l-1]
print(ans)
| N, M, Q = list(map(int, input().split()))
train = [[0]*(N+1) for _ in range(N+1)]
for i in range(M):
a, b = list(map(int, input().split()))
train[a][b] += 1
for i in range(1, N+1):
for j in range(1, N+1):
train[i][j] += train[i][j-1]
for i in range(1, N+1):
for j in range(1, N+1):
train[j][i] += train[j-1][i]
for i in range(Q):
l, r = list(map(int, input().split()))
print((train[r][r]-train[l-1][r]-train[r][l-1]+train[l-1][l-1])) | 18 | 19 | 395 | 462 | N, M, Q = list(map(int, input().split()))
train = [[0] * (N + 1) for _ in range(N + 1)]
for i in range(M):
a, b = list(map(int, input().split()))
train[a][b] += 1
for i in range(1, N + 1):
for j in range(1, N + 1):
train[i][j] += train[i][j - 1]
for i in range(Q):
ans = 0
l, r = list(map(int, input().split()))
for j in range(l, r + 1):
ans += train[j][r] - train[j][l - 1]
print(ans)
| N, M, Q = list(map(int, input().split()))
train = [[0] * (N + 1) for _ in range(N + 1)]
for i in range(M):
a, b = list(map(int, input().split()))
train[a][b] += 1
for i in range(1, N + 1):
for j in range(1, N + 1):
train[i][j] += train[i][j - 1]
for i in range(1, N + 1):
for j in range(1, N + 1):
train[j][i] += train[j - 1][i]
for i in range(Q):
l, r = list(map(int, input().split()))
print((train[r][r] - train[l - 1][r] - train[r][l - 1] + train[l - 1][l - 1]))
| false | 5.263158 | [
"+for i in range(1, N + 1):",
"+ for j in range(1, N + 1):",
"+ train[j][i] += train[j - 1][i]",
"- ans = 0",
"- for j in range(l, r + 1):",
"- ans += train[j][r] - train[j][l - 1]",
"- print(ans)",
"+ print((train[r][r] - train[l - 1][r] - train[r][l - 1] + train[l - 1][l - 1]))"
] | false | 0.03546 | 0.038145 | 0.929603 | [
"s644034941",
"s194354361"
] |
u576432509 | p02936 | python | s255357914 | s074550858 | 1,812 | 1,157 | 93,452 | 93,448 | Accepted | Accepted | 36.15 |
from collections import deque
icase=0
if icase==0:
n,q=list(map(int,input().split()))
g = [set() for _ in range(n)]
for i in range(n-1):
ai,bi=list(map(int,input().split()))
g[ai-1].add(bi-1)
g[bi-1].add(ai-1)
g=tuple(g)
xx=[0]*n
for i in range(q):
pi,xi=list(map(int,input().split()))
xx[pi-1]=xx[pi-1]+xi
elif icase==2:
n,q=4,3
g = [deque([]) for _ in range(n)]
g[0]=deque([1])
g[1]=deque([0,2,3])
g[2]=deque([1])
g[3]=deque([1])
p=[0]*q
x=[0]*q
p[0]=1
x[0]=10
p[1]=0
x[1]=100
p[2]=2
x[2]=1
xx=[0]*n
for i in range(q):
xx[p[i]]=xx[p[i]]+x[i]
#ans:100 110 111 110
elif icase==3:
n,q=6,2
g = [deque([]) for _ in range(n)]
g[0]=deque([1,2])
g[1]=deque([0,3,4])
g[2]=deque([0,5])
g[3]=deque([1])
g[4]=deque([1])
g[5]=deque([2])
p=[0]*q
x=[0]*q
p[0]=0
x[0]=10
p[1]=0
x[1]=10
xx=[0]*n
for i in range(q):
# pi,xi=map(int,input().split())
xx[p[i]]=xx[p[i]]+x[i]
#q = deque([0])
stack=[0]
parent=[-1]*n
while stack:
# print(q)
state = stack.pop()
# print("------------- stack:",stack,"state:",state,"g:",g[state])
for v in g[state]:
# print("state:",state,"v:",v,"q:",q)
if parent[state] == v:
continue
else:
parent[v]=state
stack.append(v)
xx[v]+=xx[state]
# print("parent:",parent,"xx:",xx,"stack",stack)
print((" ".join(map(str,xx[0: ]))))
| import sys
input = sys.stdin.readline
from collections import deque
icase=0
if icase==0:
n,q=list(map(int,input().split()))
g = [set() for _ in range(n)]
for i in range(n-1):
ai,bi=list(map(int,input().split()))
g[ai-1].add(bi-1)
g[bi-1].add(ai-1)
g=tuple(g)
xx=[0]*n
for i in range(q):
pi,xi=list(map(int,input().split()))
xx[pi-1]=xx[pi-1]+xi
elif icase==2:
n,q=4,3
g = [deque([]) for _ in range(n)]
g[0]=deque([1])
g[1]=deque([0,2,3])
g[2]=deque([1])
g[3]=deque([1])
p=[0]*q
x=[0]*q
p[0]=1
x[0]=10
p[1]=0
x[1]=100
p[2]=2
x[2]=1
xx=[0]*n
for i in range(q):
xx[p[i]]=xx[p[i]]+x[i]
#ans:100 110 111 110
elif icase==3:
n,q=6,2
g = [deque([]) for _ in range(n)]
g[0]=deque([1,2])
g[1]=deque([0,3,4])
g[2]=deque([0,5])
g[3]=deque([1])
g[4]=deque([1])
g[5]=deque([2])
p=[0]*q
x=[0]*q
p[0]=0
x[0]=10
p[1]=0
x[1]=10
xx=[0]*n
for i in range(q):
# pi,xi=map(int,input().split())
xx[p[i]]=xx[p[i]]+x[i]
#q = deque([0])
stack=[0]
parent=[-1]*n
while stack:
# print(q)
state = stack.pop()
# print("------------- stack:",stack,"state:",state,"g:",g[state])
for v in g[state]:
# print("state:",state,"v:",v,"q:",q)
if parent[state] == v:
continue
else:
parent[v]=state
stack.append(v)
xx[v]+=xx[state]
# print("parent:",parent,"xx:",xx,"stack",stack)
print((" ".join(map(str,xx[0: ]))))
| 73 | 74 | 1,627 | 1,665 | from collections import deque
icase = 0
if icase == 0:
n, q = list(map(int, input().split()))
g = [set() for _ in range(n)]
for i in range(n - 1):
ai, bi = list(map(int, input().split()))
g[ai - 1].add(bi - 1)
g[bi - 1].add(ai - 1)
g = tuple(g)
xx = [0] * n
for i in range(q):
pi, xi = list(map(int, input().split()))
xx[pi - 1] = xx[pi - 1] + xi
elif icase == 2:
n, q = 4, 3
g = [deque([]) for _ in range(n)]
g[0] = deque([1])
g[1] = deque([0, 2, 3])
g[2] = deque([1])
g[3] = deque([1])
p = [0] * q
x = [0] * q
p[0] = 1
x[0] = 10
p[1] = 0
x[1] = 100
p[2] = 2
x[2] = 1
xx = [0] * n
for i in range(q):
xx[p[i]] = xx[p[i]] + x[i]
# ans:100 110 111 110
elif icase == 3:
n, q = 6, 2
g = [deque([]) for _ in range(n)]
g[0] = deque([1, 2])
g[1] = deque([0, 3, 4])
g[2] = deque([0, 5])
g[3] = deque([1])
g[4] = deque([1])
g[5] = deque([2])
p = [0] * q
x = [0] * q
p[0] = 0
x[0] = 10
p[1] = 0
x[1] = 10
xx = [0] * n
for i in range(q):
# pi,xi=map(int,input().split())
xx[p[i]] = xx[p[i]] + x[i]
# q = deque([0])
stack = [0]
parent = [-1] * n
while stack:
# print(q)
state = stack.pop()
# print("------------- stack:",stack,"state:",state,"g:",g[state])
for v in g[state]:
# print("state:",state,"v:",v,"q:",q)
if parent[state] == v:
continue
else:
parent[v] = state
stack.append(v)
xx[v] += xx[state]
# print("parent:",parent,"xx:",xx,"stack",stack)
print((" ".join(map(str, xx[0:]))))
| import sys
input = sys.stdin.readline
from collections import deque
icase = 0
if icase == 0:
n, q = list(map(int, input().split()))
g = [set() for _ in range(n)]
for i in range(n - 1):
ai, bi = list(map(int, input().split()))
g[ai - 1].add(bi - 1)
g[bi - 1].add(ai - 1)
g = tuple(g)
xx = [0] * n
for i in range(q):
pi, xi = list(map(int, input().split()))
xx[pi - 1] = xx[pi - 1] + xi
elif icase == 2:
n, q = 4, 3
g = [deque([]) for _ in range(n)]
g[0] = deque([1])
g[1] = deque([0, 2, 3])
g[2] = deque([1])
g[3] = deque([1])
p = [0] * q
x = [0] * q
p[0] = 1
x[0] = 10
p[1] = 0
x[1] = 100
p[2] = 2
x[2] = 1
xx = [0] * n
for i in range(q):
xx[p[i]] = xx[p[i]] + x[i]
# ans:100 110 111 110
elif icase == 3:
n, q = 6, 2
g = [deque([]) for _ in range(n)]
g[0] = deque([1, 2])
g[1] = deque([0, 3, 4])
g[2] = deque([0, 5])
g[3] = deque([1])
g[4] = deque([1])
g[5] = deque([2])
p = [0] * q
x = [0] * q
p[0] = 0
x[0] = 10
p[1] = 0
x[1] = 10
xx = [0] * n
for i in range(q):
# pi,xi=map(int,input().split())
xx[p[i]] = xx[p[i]] + x[i]
# q = deque([0])
stack = [0]
parent = [-1] * n
while stack:
# print(q)
state = stack.pop()
# print("------------- stack:",stack,"state:",state,"g:",g[state])
for v in g[state]:
# print("state:",state,"v:",v,"q:",q)
if parent[state] == v:
continue
else:
parent[v] = state
stack.append(v)
xx[v] += xx[state]
# print("parent:",parent,"xx:",xx,"stack",stack)
print((" ".join(map(str, xx[0:]))))
| false | 1.351351 | [
"+import sys",
"+",
"+input = sys.stdin.readline"
] | false | 0.056406 | 0.037895 | 1.488462 | [
"s255357914",
"s074550858"
] |
u644907318 | p03577 | python | s140345431 | s707366279 | 377 | 67 | 79,440 | 61,848 | Accepted | Accepted | 82.23 | print((input().strip()[:-8])) | S = input().strip()
print((S[:-8])) | 1 | 2 | 27 | 34 | print((input().strip()[:-8]))
| S = input().strip()
print((S[:-8]))
| false | 50 | [
"-print((input().strip()[:-8]))",
"+S = input().strip()",
"+print((S[:-8]))"
] | false | 0.073611 | 0.067786 | 1.085933 | [
"s140345431",
"s707366279"
] |
u340781749 | p02913 | python | s141859384 | s793627831 | 85 | 68 | 3,904 | 3,404 | Accepted | Accepted | 20 | def solve(n, s, d, MOD):
ttt = [ord(c) - 97 for c in s]
ttx = []
c = 1
for t in ttt[::-1]:
ttx.append(t * c % MOD)
c = c * d % MOD
ttx.reverse()
ttc = [0]
for t in ttx:
ttc.append((ttc[-1] + t) % MOD)
l, r = 0, n // 2 + 1
while l < r:
m = (l + r + 1) // 2
if search(m, d, ttc, MOD):
l = m
else:
r = m - 1
return l
def search(w, d, ttc, MOD):
appeared = []
comparing = set()
w2 = w * 2
p = 1
for i in range(w, n + 1):
t = (ttc[i] - ttc[i - w]) * p % MOD
if i >= w2:
comparing.add(appeared[i - w2])
if t in comparing:
return True
appeared.append(t)
p = p * d % MOD
return False
n = int(eval(input()))
s = eval(input())
MOD = 10 ** 9 + 7
print((min(solve(n, s, d, MOD) for d in (29, 31))))
| def solve(n, s):
l, r = 0, n // 2 + 1
while l < r:
m = (l + r + 1) // 2
if search(m, s):
l = m
else:
r = m - 1
return l
def search(w, s):
appeared = []
comparing = set()
w2 = w * 2
for i in range(w, n + 1):
t = hash(s[i - w:i])
if i >= w2:
comparing.add(appeared[i - w2])
if t in comparing:
return True
appeared.append(t)
return False
n = int(eval(input()))
s = eval(input())
print((solve(n, s)))
| 46 | 30 | 935 | 562 | def solve(n, s, d, MOD):
ttt = [ord(c) - 97 for c in s]
ttx = []
c = 1
for t in ttt[::-1]:
ttx.append(t * c % MOD)
c = c * d % MOD
ttx.reverse()
ttc = [0]
for t in ttx:
ttc.append((ttc[-1] + t) % MOD)
l, r = 0, n // 2 + 1
while l < r:
m = (l + r + 1) // 2
if search(m, d, ttc, MOD):
l = m
else:
r = m - 1
return l
def search(w, d, ttc, MOD):
appeared = []
comparing = set()
w2 = w * 2
p = 1
for i in range(w, n + 1):
t = (ttc[i] - ttc[i - w]) * p % MOD
if i >= w2:
comparing.add(appeared[i - w2])
if t in comparing:
return True
appeared.append(t)
p = p * d % MOD
return False
n = int(eval(input()))
s = eval(input())
MOD = 10**9 + 7
print((min(solve(n, s, d, MOD) for d in (29, 31))))
| def solve(n, s):
l, r = 0, n // 2 + 1
while l < r:
m = (l + r + 1) // 2
if search(m, s):
l = m
else:
r = m - 1
return l
def search(w, s):
appeared = []
comparing = set()
w2 = w * 2
for i in range(w, n + 1):
t = hash(s[i - w : i])
if i >= w2:
comparing.add(appeared[i - w2])
if t in comparing:
return True
appeared.append(t)
return False
n = int(eval(input()))
s = eval(input())
print((solve(n, s)))
| false | 34.782609 | [
"-def solve(n, s, d, MOD):",
"- ttt = [ord(c) - 97 for c in s]",
"- ttx = []",
"- c = 1",
"- for t in ttt[::-1]:",
"- ttx.append(t * c % MOD)",
"- c = c * d % MOD",
"- ttx.reverse()",
"- ttc = [0]",
"- for t in ttx:",
"- ttc.append((ttc[-1] + t) % MOD)",
"+def solve(n, s):",
"- if search(m, d, ttc, MOD):",
"+ if search(m, s):",
"-def search(w, d, ttc, MOD):",
"+def search(w, s):",
"- p = 1",
"- t = (ttc[i] - ttc[i - w]) * p % MOD",
"+ t = hash(s[i - w : i])",
"- p = p * d % MOD",
"-MOD = 10**9 + 7",
"-print((min(solve(n, s, d, MOD) for d in (29, 31))))",
"+print((solve(n, s)))"
] | false | 0.043312 | 0.040964 | 1.057339 | [
"s141859384",
"s793627831"
] |
u037430802 | p02937 | python | s722554995 | s769133893 | 158 | 125 | 7,668 | 8,052 | Accepted | Accepted | 20.89 | from bisect import bisect
S = eval(input())
T = eval(input())
N = len(S)
# Sにおいてある文字が出てくる位置を調べる
idxs_S = [[] for _ in range(26)] # a~zの分
for i, c in enumerate(S):
idx = ord(c) - ord("a")
idxs_S[idx].append(i)
# Tに出てくる文字がSになければ無理
for c in set(T):
if len(idxs_S[ord(c) - ord("a")]) == 0:
print((-1))
exit()
cnt_all_S = 0
idx_c = -1
for c in T:
tmp = ord(c) - ord("a")
idx = bisect(idxs_S[tmp], idx_c)
if idx == len(idxs_S[tmp]): # 現行のSにこれ以上使えるcがない場合、新たにSを連結してその中からcを取り出す
idx_c = idxs_S[tmp][0] # Sの中の初めのcの位置まで
cnt_all_S += 1
else:
idx_c = idxs_S[tmp][idx]
print((N*cnt_all_S + idx_c + 1)) | from collections import defaultdict
import bisect
s = eval(input())
t = eval(input())
N = len(s)
set_s = set(s)
set_t = set(t)
for c in set_t:
if c not in set_s:
print((-1))
exit()
# それぞれの文字のインデックスを記録
idxs = defaultdict(list)
for i in range(N):
idxs[s[i]].append(i)
current_idx = -1 # ここ0にしているとsの1文字目にtの1文字めと同じのがある時にずれるので注意
total = 0
for c in t:
next_idx = bisect.bisect(idxs[c], current_idx) # bisect(bisect_right)だと同じやつがある場合その右のidxになる
if next_idx == len(idxs[c]):
total += N
current_idx = idxs[c][0]
else:
current_idx = idxs[c][next_idx]
print((total + current_idx + 1))
#print(total , current_idx , 1) | 29 | 35 | 670 | 691 | from bisect import bisect
S = eval(input())
T = eval(input())
N = len(S)
# Sにおいてある文字が出てくる位置を調べる
idxs_S = [[] for _ in range(26)] # a~zの分
for i, c in enumerate(S):
idx = ord(c) - ord("a")
idxs_S[idx].append(i)
# Tに出てくる文字がSになければ無理
for c in set(T):
if len(idxs_S[ord(c) - ord("a")]) == 0:
print((-1))
exit()
cnt_all_S = 0
idx_c = -1
for c in T:
tmp = ord(c) - ord("a")
idx = bisect(idxs_S[tmp], idx_c)
if idx == len(idxs_S[tmp]): # 現行のSにこれ以上使えるcがない場合、新たにSを連結してその中からcを取り出す
idx_c = idxs_S[tmp][0] # Sの中の初めのcの位置まで
cnt_all_S += 1
else:
idx_c = idxs_S[tmp][idx]
print((N * cnt_all_S + idx_c + 1))
| from collections import defaultdict
import bisect
s = eval(input())
t = eval(input())
N = len(s)
set_s = set(s)
set_t = set(t)
for c in set_t:
if c not in set_s:
print((-1))
exit()
# それぞれの文字のインデックスを記録
idxs = defaultdict(list)
for i in range(N):
idxs[s[i]].append(i)
current_idx = -1 # ここ0にしているとsの1文字目にtの1文字めと同じのがある時にずれるので注意
total = 0
for c in t:
next_idx = bisect.bisect(
idxs[c], current_idx
) # bisect(bisect_right)だと同じやつがある場合その右のidxになる
if next_idx == len(idxs[c]):
total += N
current_idx = idxs[c][0]
else:
current_idx = idxs[c][next_idx]
print((total + current_idx + 1))
# print(total , current_idx , 1)
| false | 17.142857 | [
"-from bisect import bisect",
"+from collections import defaultdict",
"+import bisect",
"-S = eval(input())",
"-T = eval(input())",
"-N = len(S)",
"-# Sにおいてある文字が出てくる位置を調べる",
"-idxs_S = [[] for _ in range(26)] # a~zの分",
"-for i, c in enumerate(S):",
"- idx = ord(c) - ord(\"a\")",
"- idxs_S[idx].append(i)",
"-# Tに出てくる文字がSになければ無理",
"-for c in set(T):",
"- if len(idxs_S[ord(c) - ord(\"a\")]) == 0:",
"+s = eval(input())",
"+t = eval(input())",
"+N = len(s)",
"+set_s = set(s)",
"+set_t = set(t)",
"+for c in set_t:",
"+ if c not in set_s:",
"-cnt_all_S = 0",
"-idx_c = -1",
"-for c in T:",
"- tmp = ord(c) - ord(\"a\")",
"- idx = bisect(idxs_S[tmp], idx_c)",
"- if idx == len(idxs_S[tmp]): # 現行のSにこれ以上使えるcがない場合、新たにSを連結してその中からcを取り出す",
"- idx_c = idxs_S[tmp][0] # Sの中の初めのcの位置まで",
"- cnt_all_S += 1",
"+# それぞれの文字のインデックスを記録",
"+idxs = defaultdict(list)",
"+for i in range(N):",
"+ idxs[s[i]].append(i)",
"+current_idx = -1 # ここ0にしているとsの1文字目にtの1文字めと同じのがある時にずれるので注意",
"+total = 0",
"+for c in t:",
"+ next_idx = bisect.bisect(",
"+ idxs[c], current_idx",
"+ ) # bisect(bisect_right)だと同じやつがある場合その右のidxになる",
"+ if next_idx == len(idxs[c]):",
"+ total += N",
"+ current_idx = idxs[c][0]",
"- idx_c = idxs_S[tmp][idx]",
"-print((N * cnt_all_S + idx_c + 1))",
"+ current_idx = idxs[c][next_idx]",
"+print((total + current_idx + 1))",
"+# print(total , current_idx , 1)"
] | false | 0.101215 | 0.042008 | 2.409433 | [
"s722554995",
"s769133893"
] |
u233729690 | p02731 | python | s551846239 | s225690439 | 120 | 17 | 5,588 | 2,940 | Accepted | Accepted | 85.83 | from decimal import *
L = int(eval(input()))
print(((Decimal(L) / Decimal(3)) ** Decimal(3)))
| L = int(eval(input()))
print(((L / 3) ** 3)) | 5 | 3 | 92 | 40 | from decimal import *
L = int(eval(input()))
print(((Decimal(L) / Decimal(3)) ** Decimal(3)))
| L = int(eval(input()))
print(((L / 3) ** 3))
| false | 40 | [
"-from decimal import *",
"-",
"-print(((Decimal(L) / Decimal(3)) ** Decimal(3)))",
"+print(((L / 3) ** 3))"
] | false | 0.074993 | 0.039818 | 1.883399 | [
"s551846239",
"s225690439"
] |
u512212329 | p02629 | python | s053279489 | s669723617 | 34 | 31 | 9,468 | 9,464 | Accepted | Accepted | 8.82 | from collections import deque
import math
def main():
n = int(input())
if n == 1:
print('a')
return
digits = deque()
alpha = ord('a') - 1
maxex = int(math.log(n-1, 26))
ex = 1
for ex in range(1, maxex + 2):
bb = pow(26, ex - 1)
aa = bb * 26
rem = n % aa // bb
n -= bb * rem
if rem == 0:
if n == 0:
break
rem += 26
n -= aa
digits.appendleft(chr(alpha + rem))
[print(d, end='') for d in digits]
print()
if __name__ == '__main__':
main()
| from collections import deque
def main():
n = int(eval(input()))
base = 26
orig = ord('a')
ans = deque()
for exp in range(1, 12):
if (tmp := pow(base, exp)) >= n:
n -= 1 # zero_indexed for ASCII mod
for digit in range(exp):
ans.appendleft(chr(orig + n % base))
n //= base
break
else:
n -= tmp
print((''.join(ans)))
if __name__ == '__main__':
main()
| 31 | 22 | 626 | 491 | from collections import deque
import math
def main():
n = int(input())
if n == 1:
print("a")
return
digits = deque()
alpha = ord("a") - 1
maxex = int(math.log(n - 1, 26))
ex = 1
for ex in range(1, maxex + 2):
bb = pow(26, ex - 1)
aa = bb * 26
rem = n % aa // bb
n -= bb * rem
if rem == 0:
if n == 0:
break
rem += 26
n -= aa
digits.appendleft(chr(alpha + rem))
[print(d, end="") for d in digits]
print()
if __name__ == "__main__":
main()
| from collections import deque
def main():
n = int(eval(input()))
base = 26
orig = ord("a")
ans = deque()
for exp in range(1, 12):
if (tmp := pow(base, exp)) >= n:
n -= 1 # zero_indexed for ASCII mod
for digit in range(exp):
ans.appendleft(chr(orig + n % base))
n //= base
break
else:
n -= tmp
print(("".join(ans)))
if __name__ == "__main__":
main()
| false | 29.032258 | [
"-import math",
"- n = int(input())",
"- if n == 1:",
"- print(\"a\")",
"- return",
"- digits = deque()",
"- alpha = ord(\"a\") - 1",
"- maxex = int(math.log(n - 1, 26))",
"- ex = 1",
"- for ex in range(1, maxex + 2):",
"- bb = pow(26, ex - 1)",
"- aa = bb * 26",
"- rem = n % aa // bb",
"- n -= bb * rem",
"- if rem == 0:",
"- if n == 0:",
"- break",
"- rem += 26",
"- n -= aa",
"- digits.appendleft(chr(alpha + rem))",
"- [print(d, end=\"\") for d in digits]",
"- print()",
"+ n = int(eval(input()))",
"+ base = 26",
"+ orig = ord(\"a\")",
"+ ans = deque()",
"+ for exp in range(1, 12):",
"+ if (tmp := pow(base, exp)) >= n:",
"+ n -= 1 # zero_indexed for ASCII mod",
"+ for digit in range(exp):",
"+ ans.appendleft(chr(orig + n % base))",
"+ n //= base",
"+ break",
"+ else:",
"+ n -= tmp",
"+ print((\"\".join(ans)))"
] | false | 0.007681 | 0.042029 | 0.182752 | [
"s053279489",
"s669723617"
] |
u312025627 | p03449 | python | s670191048 | s022476368 | 169 | 24 | 38,512 | 3,064 | Accepted | Accepted | 85.8 | def main():
N = int(eval(input()))
A = [[int(i) for i in input().split()] for j in range(2)]
ans = 0
for i in range(N):
cur = sum(A[0][:i+1]) + sum(A[1][i:])
ans = max(ans, cur)
print(ans)
if __name__ == '__main__':
main()
| def main():
from itertools import accumulate
N = int(eval(input()))
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
accA = list(accumulate(A))
accB = list(accumulate([0] + B))
ans = 0
for i in range(N):
cur = accA[i] + (accB[N] - accB[i])
ans = max(ans, cur)
print(ans)
if __name__ == '__main__':
main()
| 12 | 16 | 270 | 399 | def main():
N = int(eval(input()))
A = [[int(i) for i in input().split()] for j in range(2)]
ans = 0
for i in range(N):
cur = sum(A[0][: i + 1]) + sum(A[1][i:])
ans = max(ans, cur)
print(ans)
if __name__ == "__main__":
main()
| def main():
from itertools import accumulate
N = int(eval(input()))
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
accA = list(accumulate(A))
accB = list(accumulate([0] + B))
ans = 0
for i in range(N):
cur = accA[i] + (accB[N] - accB[i])
ans = max(ans, cur)
print(ans)
if __name__ == "__main__":
main()
| false | 25 | [
"+ from itertools import accumulate",
"+",
"- A = [[int(i) for i in input().split()] for j in range(2)]",
"+ A = [int(i) for i in input().split()]",
"+ B = [int(i) for i in input().split()]",
"+ accA = list(accumulate(A))",
"+ accB = list(accumulate([0] + B))",
"- cur = sum(A[0][: i + 1]) + sum(A[1][i:])",
"+ cur = accA[i] + (accB[N] - accB[i])"
] | false | 0.037427 | 0.086665 | 0.431854 | [
"s670191048",
"s022476368"
] |
u525065967 | p02641 | python | s767694457 | s860113104 | 24 | 21 | 9,200 | 9,200 | Accepted | Accepted | 12.5 | x,n = list(map(int,input().split()))
if n == 0:
print(x)
exit()
P = [*list(map(int,input().split()))]
ans = 100+100 # inf = x + d + 1
for d in range(100): # [0,100)
now_diff = abs(ans - x)
min_x, max_x = x - d, x + d
if min_x not in P:
if now_diff > abs(min_x - x): ans = x-d
elif max_x not in P:
if now_diff > abs(max_x - x): ans = x+d
print(ans)
| x,n = list(map(int,input().split()))
if n == 0:
print(x)
exit()
P = [*list(map(int,input().split()))]
ans = 100 + 100 # inf = x + d + 1
for d in range(100): # [0,100)
now_diff = abs(ans - x)
min_x, max_x = x - d, x + d
if min_x not in P:
if now_diff > abs(min_x - x): ans = min_x
elif max_x not in P:
if now_diff > abs(max_x - x): ans = max_x
print(ans)
| 14 | 14 | 389 | 395 | x, n = list(map(int, input().split()))
if n == 0:
print(x)
exit()
P = [*list(map(int, input().split()))]
ans = 100 + 100 # inf = x + d + 1
for d in range(100): # [0,100)
now_diff = abs(ans - x)
min_x, max_x = x - d, x + d
if min_x not in P:
if now_diff > abs(min_x - x):
ans = x - d
elif max_x not in P:
if now_diff > abs(max_x - x):
ans = x + d
print(ans)
| x, n = list(map(int, input().split()))
if n == 0:
print(x)
exit()
P = [*list(map(int, input().split()))]
ans = 100 + 100 # inf = x + d + 1
for d in range(100): # [0,100)
now_diff = abs(ans - x)
min_x, max_x = x - d, x + d
if min_x not in P:
if now_diff > abs(min_x - x):
ans = min_x
elif max_x not in P:
if now_diff > abs(max_x - x):
ans = max_x
print(ans)
| false | 0 | [
"- ans = x - d",
"+ ans = min_x",
"- ans = x + d",
"+ ans = max_x"
] | false | 0.046177 | 0.046922 | 0.98411 | [
"s767694457",
"s860113104"
] |
u623814058 | p03612 | python | s353199632 | s280484939 | 96 | 64 | 19,968 | 20,456 | Accepted | Accepted | 33.33 | N=int(eval(input()))
S=[]
for x,y in zip(list(map(int,input().split())), list(range(1,N+1))):
if x==y: S.append(y)
S.append('$')
L=len(S)
l=[S[0]]
i=1
a=0
while i<L:
if S[i]=='$':a+=1
elif l[0]+1!=S[i]:
a+=1
l=[S[i]]
else:l.append(S[i])
i+=1
print(a) | N=int(eval(input()))
*P,=list(map(int,input().split()))
i=c=0
while i<N:
if P[i]==i+1:
c+=1
i+=1
i+=1
print(c) | 19 | 10 | 271 | 120 | N = int(eval(input()))
S = []
for x, y in zip(list(map(int, input().split())), list(range(1, N + 1))):
if x == y:
S.append(y)
S.append("$")
L = len(S)
l = [S[0]]
i = 1
a = 0
while i < L:
if S[i] == "$":
a += 1
elif l[0] + 1 != S[i]:
a += 1
l = [S[i]]
else:
l.append(S[i])
i += 1
print(a)
| N = int(eval(input()))
(*P,) = list(map(int, input().split()))
i = c = 0
while i < N:
if P[i] == i + 1:
c += 1
i += 1
i += 1
print(c)
| false | 47.368421 | [
"-S = []",
"-for x, y in zip(list(map(int, input().split())), list(range(1, N + 1))):",
"- if x == y:",
"- S.append(y)",
"-S.append(\"$\")",
"-L = len(S)",
"-l = [S[0]]",
"-i = 1",
"-a = 0",
"-while i < L:",
"- if S[i] == \"$\":",
"- a += 1",
"- elif l[0] + 1 != S[i]:",
"- a += 1",
"- l = [S[i]]",
"- else:",
"- l.append(S[i])",
"+(*P,) = list(map(int, input().split()))",
"+i = c = 0",
"+while i < N:",
"+ if P[i] == i + 1:",
"+ c += 1",
"+ i += 1",
"-print(a)",
"+print(c)"
] | false | 0.048037 | 0.045513 | 1.05545 | [
"s353199632",
"s280484939"
] |
u562935282 | p03476 | python | s050740599 | s270067798 | 240 | 207 | 6,372 | 14,368 | Accepted | Accepted | 13.75 | class Sieve:
"""区間[2,n]の値を素因数分解する"""
def __init__(self, n=1):
primes = []
f = [0] * (n + 1)
f[0] = f[1] = -1
for i in range(2, n + 1): # 素数を探す
if f[i]: continue
primes.append(i)
f[i] = i # 素数には自身を代入
for j in range(i * i, n + 1, i): # 合成数に素因数を書き込む
if not f[j]:
f[j] = i # 最小の素因数を代入
self.primes = primes
self.f = f
# def is_prime(self, x) -> bool: # 素数判定
# return self.f[x] == x
#
# def factor_list(self, x) -> list: # 素因数分解の昇順リスト, [2,2,3,5,...]
# res = []
# while x != 1:
# res.append(self.f[x])
# x //= self.f[x]
# return res
#
# def factor(self, x) -> list: # 素因数分解の頻度リスト, [[2,x],[3,y],[5,z],...]
# fl = self.factor_list(x)
# if not fl: return []
# res = [[fl[0], 0]]
# for p in fl:
# if res[-1][0] == p:
# res[-1][1] += 1
# else:
# res.append([p, 1])
# return res
def main():
import sys
input = sys.stdin.readline
sieve = Sieve(10 ** 5)
prime_set = set(sieve.primes)
acc = [0] * (10 ** 5 + 1)
cnt = 0
for x in range(1, 10 ** 5 + 1):
if (x % 2 == 1) and (x in prime_set) and ((x + 1) // 2 in prime_set):
cnt += 1
acc[x] = cnt
q = int(eval(input()))
for _ in range(q):
left, right = list(map(int, input().split())) # [left,right]<=10**5
res = acc[right] - acc[left - 1]
print(res)
if __name__ == '__main__':
main()
| class Sieve:
"""区間[2,n]の値を素因数分解する"""
def __init__(self, n=1):
primes = []
f = [0] * (n + 1)
f[0] = f[1] = -1
for i in range(2, n + 1): # 素数を探す
if f[i]: continue
primes.append(i)
f[i] = i # 素数には自身を代入
for j in range(i * i, n + 1, i): # 合成数に素因数を書き込む
if not f[j]:
f[j] = i # 最小の素因数を代入
self.primes = primes
self.f = f
def is_prime(self, x) -> bool: # 素数判定
return self.f[x] == x
def factor_list(self, x) -> list: # 素因数分解の昇順リスト, [2,2,3,5,...]
res = []
while x != 1:
res.append(self.f[x])
x //= self.f[x]
return res
def factor(self, x) -> list: # 素因数分解の頻度リスト, [[2,x],[3,y],[5,z],...]
fl = self.factor_list(x)
if not fl: return []
res = [[fl[0], 0]]
for p in fl:
if res[-1][0] == p:
res[-1][1] += 1
else:
res.append([p, 1])
return res
def main():
from itertools import accumulate
import sys
input = sys.stdin.readline
MX = 10 ** 5
s = Sieve(MX)
like2017 = [0] * (MX + 1)
for x in range(1, MX + 1, 2):
if s.is_prime(x) and s.is_prime((x + 1) // 2):
like2017[x] = 1
*acc, = accumulate(like2017)
Q = int(input())
ans = []
for _ in range(Q):
left, right = map(int, input().split())
res = acc[right] - acc[left - 1]
ans.append(res)
print(*ans, sep='\n')
if __name__ == '__main__':
main()
# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())
| 63 | 78 | 1,687 | 1,808 | class Sieve:
"""区間[2,n]の値を素因数分解する"""
def __init__(self, n=1):
primes = []
f = [0] * (n + 1)
f[0] = f[1] = -1
for i in range(2, n + 1): # 素数を探す
if f[i]:
continue
primes.append(i)
f[i] = i # 素数には自身を代入
for j in range(i * i, n + 1, i): # 合成数に素因数を書き込む
if not f[j]:
f[j] = i # 最小の素因数を代入
self.primes = primes
self.f = f
# def is_prime(self, x) -> bool: # 素数判定
# return self.f[x] == x
#
# def factor_list(self, x) -> list: # 素因数分解の昇順リスト, [2,2,3,5,...]
# res = []
# while x != 1:
# res.append(self.f[x])
# x //= self.f[x]
# return res
#
# def factor(self, x) -> list: # 素因数分解の頻度リスト, [[2,x],[3,y],[5,z],...]
# fl = self.factor_list(x)
# if not fl: return []
# res = [[fl[0], 0]]
# for p in fl:
# if res[-1][0] == p:
# res[-1][1] += 1
# else:
# res.append([p, 1])
# return res
def main():
import sys
input = sys.stdin.readline
sieve = Sieve(10**5)
prime_set = set(sieve.primes)
acc = [0] * (10**5 + 1)
cnt = 0
for x in range(1, 10**5 + 1):
if (x % 2 == 1) and (x in prime_set) and ((x + 1) // 2 in prime_set):
cnt += 1
acc[x] = cnt
q = int(eval(input()))
for _ in range(q):
left, right = list(map(int, input().split())) # [left,right]<=10**5
res = acc[right] - acc[left - 1]
print(res)
if __name__ == "__main__":
main()
| class Sieve:
"""区間[2,n]の値を素因数分解する"""
def __init__(self, n=1):
primes = []
f = [0] * (n + 1)
f[0] = f[1] = -1
for i in range(2, n + 1): # 素数を探す
if f[i]:
continue
primes.append(i)
f[i] = i # 素数には自身を代入
for j in range(i * i, n + 1, i): # 合成数に素因数を書き込む
if not f[j]:
f[j] = i # 最小の素因数を代入
self.primes = primes
self.f = f
def is_prime(self, x) -> bool: # 素数判定
return self.f[x] == x
def factor_list(self, x) -> list: # 素因数分解の昇順リスト, [2,2,3,5,...]
res = []
while x != 1:
res.append(self.f[x])
x //= self.f[x]
return res
def factor(self, x) -> list: # 素因数分解の頻度リスト, [[2,x],[3,y],[5,z],...]
fl = self.factor_list(x)
if not fl:
return []
res = [[fl[0], 0]]
for p in fl:
if res[-1][0] == p:
res[-1][1] += 1
else:
res.append([p, 1])
return res
def main():
from itertools import accumulate
import sys
input = sys.stdin.readline
MX = 10**5
s = Sieve(MX)
like2017 = [0] * (MX + 1)
for x in range(1, MX + 1, 2):
if s.is_prime(x) and s.is_prime((x + 1) // 2):
like2017[x] = 1
(*acc,) = accumulate(like2017)
Q = int(input())
ans = []
for _ in range(Q):
left, right = map(int, input().split())
res = acc[right] - acc[left - 1]
ans.append(res)
print(*ans, sep="\n")
if __name__ == "__main__":
main()
# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())
| false | 19.230769 | [
"- # def is_prime(self, x) -> bool: # 素数判定",
"- # return self.f[x] == x",
"- #",
"- # def factor_list(self, x) -> list: # 素因数分解の昇順リスト, [2,2,3,5,...]",
"- # res = []",
"- # while x != 1:",
"- # res.append(self.f[x])",
"- # x //= self.f[x]",
"- # return res",
"- #",
"- # def factor(self, x) -> list: # 素因数分解の頻度リスト, [[2,x],[3,y],[5,z],...]",
"- # fl = self.factor_list(x)",
"- # if not fl: return []",
"- # res = [[fl[0], 0]]",
"- # for p in fl:",
"- # if res[-1][0] == p:",
"- # res[-1][1] += 1",
"- # else:",
"- # res.append([p, 1])",
"- # return res",
"+ def is_prime(self, x) -> bool: # 素数判定",
"+ return self.f[x] == x",
"+",
"+ def factor_list(self, x) -> list: # 素因数分解の昇順リスト, [2,2,3,5,...]",
"+ res = []",
"+ while x != 1:",
"+ res.append(self.f[x])",
"+ x //= self.f[x]",
"+ return res",
"+",
"+ def factor(self, x) -> list: # 素因数分解の頻度リスト, [[2,x],[3,y],[5,z],...]",
"+ fl = self.factor_list(x)",
"+ if not fl:",
"+ return []",
"+ res = [[fl[0], 0]]",
"+ for p in fl:",
"+ if res[-1][0] == p:",
"+ res[-1][1] += 1",
"+ else:",
"+ res.append([p, 1])",
"+ return res",
"+ from itertools import accumulate",
"- sieve = Sieve(10**5)",
"- prime_set = set(sieve.primes)",
"- acc = [0] * (10**5 + 1)",
"- cnt = 0",
"- for x in range(1, 10**5 + 1):",
"- if (x % 2 == 1) and (x in prime_set) and ((x + 1) // 2 in prime_set):",
"- cnt += 1",
"- acc[x] = cnt",
"- q = int(eval(input()))",
"- for _ in range(q):",
"- left, right = list(map(int, input().split())) # [left,right]<=10**5",
"+ MX = 10**5",
"+ s = Sieve(MX)",
"+ like2017 = [0] * (MX + 1)",
"+ for x in range(1, MX + 1, 2):",
"+ if s.is_prime(x) and s.is_prime((x + 1) // 2):",
"+ like2017[x] = 1",
"+ (*acc,) = accumulate(like2017)",
"+ Q = int(input())",
"+ ans = []",
"+ for _ in range(Q):",
"+ left, right = map(int, input().split())",
"- print(res)",
"+ ans.append(res)",
"+ print(*ans, sep=\"\\n\")",
"+# import sys",
"+#",
"+# sys.setrecursionlimit(10 ** 7)",
"+#",
"+# input = sys.stdin.readline",
"+# rstrip()",
"+# int(input())",
"+# map(int, input().split())"
] | false | 0.146948 | 0.078916 | 1.862096 | [
"s050740599",
"s270067798"
] |
u811733736 | p02396 | python | s290871931 | s570789183 | 130 | 60 | 7,552 | 7,760 | Accepted | Accepted | 53.85 | if __name__ == '__main__':
current_no = 1
while True:
input_num = int(eval(input()))
if input_num != 0:
print(('Case {0}: {1}'.format(current_no, input_num)))
current_no += 1
else:
break | # -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_3_B&lang=jp
"""
import sys
from sys import stdin
input = stdin.readline
def main(args):
count = 1
while True:
x = int(eval(input()))
if x == 0:
break
print(('Case {}: {}'.format(count, x)))
count += 1
if __name__ == '__main__':
main(sys.argv[1:])
| 10 | 23 | 256 | 416 | if __name__ == "__main__":
current_no = 1
while True:
input_num = int(eval(input()))
if input_num != 0:
print(("Case {0}: {1}".format(current_no, input_num)))
current_no += 1
else:
break
| # -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_3_B&lang=jp
"""
import sys
from sys import stdin
input = stdin.readline
def main(args):
count = 1
while True:
x = int(eval(input()))
if x == 0:
break
print(("Case {}: {}".format(count, x)))
count += 1
if __name__ == "__main__":
main(sys.argv[1:])
| false | 56.521739 | [
"+# -*- coding: utf-8 -*-",
"+\"\"\"",
"+http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_3_B&lang=jp",
"+\"\"\"",
"+import sys",
"+from sys import stdin",
"+",
"+input = stdin.readline",
"+",
"+",
"+def main(args):",
"+ count = 1",
"+ while True:",
"+ x = int(eval(input()))",
"+ if x == 0:",
"+ break",
"+ print((\"Case {}: {}\".format(count, x)))",
"+ count += 1",
"+",
"+",
"- current_no = 1",
"- while True:",
"- input_num = int(eval(input()))",
"- if input_num != 0:",
"- print((\"Case {0}: {1}\".format(current_no, input_num)))",
"- current_no += 1",
"- else:",
"- break",
"+ main(sys.argv[1:])"
] | false | 0.102126 | 0.100629 | 1.014874 | [
"s290871931",
"s570789183"
] |
u067677727 | p02240 | python | s120374797 | s732135870 | 830 | 370 | 32,736 | 35,620 | Accepted | Accepted | 55.42 | # -*- coding: utf-8 -*-
def assignColor(G):
n = len(G)
C = [-1 for i in range(n)]
for i in range(n):
if C[i] == -1:
C = BFS(G, i, C)
return C
#@profile
def BFS(G, start, C):
n = len(G)
Q = []
Q.append(start)
C[start] = start
while len(Q) != 0:
u = Q.pop(0)
v = [i for i in G[u] if C[i] == -1] # v := ??£??\???????????????????????¢?´¢??????????????????
for i in v:
Q.append(i)
C[i] = C[start]
return C
def main():
n, m = list(map(int, input().split()))
G = [[] for i in range(n)]
for i in range(m):
s, t = list(map(int, input().split()))
G[s].append(t)
G[t].append(s)
C = assignColor(G)
q = int(eval(input()))
for i in range(q):
s, t = list(map(int, input().split()))
if C[s] == C[t]:
print("yes")
else:
print("no")
if __name__ == "__main__":
main() | #!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
def assign_color():
_color = 1
for m in range(vertices_num):
if vertices_status_list[m] == -1:
graph_dfs(m, _color)
_color += 1
return None
def graph_dfs(vertex, color):
vertices_stack = list()
vertices_stack.append(vertex)
vertices_status_list[vertex] = color
while vertices_stack:
current_vertex = vertices_stack[-1]
vertices_stack.pop()
for v in adj_list[current_vertex]:
if vertices_status_list[v] == -1:
vertices_status_list[v] = color
vertices_stack.append(v)
return None
def solve():
for relation in relation_info:
key, value = list(map(int, relation.split()))
adj_list[key].append(value)
adj_list[value].append(key)
assign_color()
# print(adj_list)
for question in question_list:
start, target = list(map(int, question.split()))
if vertices_status_list[start] == vertices_status_list[target]:
print("yes")
else:
print("no")
return vertices_status_list
if __name__ == '__main__':
_input = sys.stdin.readlines()
vertices_num, relation_num = list(map(int, _input[0].split()))
relation_info = _input[1:relation_num + 1]
question_num = int(_input[relation_num + 1])
question_list = _input[relation_num + 2:]
adj_list = tuple([[] for _ in range(vertices_num)])
vertices_status_list = [-1] * vertices_num
ans = solve() | 51 | 60 | 1,057 | 1,603 | # -*- coding: utf-8 -*-
def assignColor(G):
n = len(G)
C = [-1 for i in range(n)]
for i in range(n):
if C[i] == -1:
C = BFS(G, i, C)
return C
# @profile
def BFS(G, start, C):
n = len(G)
Q = []
Q.append(start)
C[start] = start
while len(Q) != 0:
u = Q.pop(0)
v = [
i for i in G[u] if C[i] == -1
] # v := ??£??\???????????????????????¢?´¢??????????????????
for i in v:
Q.append(i)
C[i] = C[start]
return C
def main():
n, m = list(map(int, input().split()))
G = [[] for i in range(n)]
for i in range(m):
s, t = list(map(int, input().split()))
G[s].append(t)
G[t].append(s)
C = assignColor(G)
q = int(eval(input()))
for i in range(q):
s, t = list(map(int, input().split()))
if C[s] == C[t]:
print("yes")
else:
print("no")
if __name__ == "__main__":
main()
| #!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
def assign_color():
_color = 1
for m in range(vertices_num):
if vertices_status_list[m] == -1:
graph_dfs(m, _color)
_color += 1
return None
def graph_dfs(vertex, color):
vertices_stack = list()
vertices_stack.append(vertex)
vertices_status_list[vertex] = color
while vertices_stack:
current_vertex = vertices_stack[-1]
vertices_stack.pop()
for v in adj_list[current_vertex]:
if vertices_status_list[v] == -1:
vertices_status_list[v] = color
vertices_stack.append(v)
return None
def solve():
for relation in relation_info:
key, value = list(map(int, relation.split()))
adj_list[key].append(value)
adj_list[value].append(key)
assign_color()
# print(adj_list)
for question in question_list:
start, target = list(map(int, question.split()))
if vertices_status_list[start] == vertices_status_list[target]:
print("yes")
else:
print("no")
return vertices_status_list
if __name__ == "__main__":
_input = sys.stdin.readlines()
vertices_num, relation_num = list(map(int, _input[0].split()))
relation_info = _input[1 : relation_num + 1]
question_num = int(_input[relation_num + 1])
question_list = _input[relation_num + 2 :]
adj_list = tuple([[] for _ in range(vertices_num)])
vertices_status_list = [-1] * vertices_num
ans = solve()
| false | 15 | [
"+#!/usr/bin/env python",
"-def assignColor(G):",
"- n = len(G)",
"- C = [-1 for i in range(n)]",
"- for i in range(n):",
"- if C[i] == -1:",
"- C = BFS(G, i, C)",
"- return C",
"+import sys",
"-# @profile",
"-def BFS(G, start, C):",
"- n = len(G)",
"- Q = []",
"- Q.append(start)",
"- C[start] = start",
"- while len(Q) != 0:",
"- u = Q.pop(0)",
"- v = [",
"- i for i in G[u] if C[i] == -1",
"- ] # v := ??£??\\???????????????????????¢?´¢??????????????????",
"- for i in v:",
"- Q.append(i)",
"- C[i] = C[start]",
"- return C",
"+def assign_color():",
"+ _color = 1",
"+ for m in range(vertices_num):",
"+ if vertices_status_list[m] == -1:",
"+ graph_dfs(m, _color)",
"+ _color += 1",
"+ return None",
"-def main():",
"- n, m = list(map(int, input().split()))",
"- G = [[] for i in range(n)]",
"- for i in range(m):",
"- s, t = list(map(int, input().split()))",
"- G[s].append(t)",
"- G[t].append(s)",
"- C = assignColor(G)",
"- q = int(eval(input()))",
"- for i in range(q):",
"- s, t = list(map(int, input().split()))",
"- if C[s] == C[t]:",
"+def graph_dfs(vertex, color):",
"+ vertices_stack = list()",
"+ vertices_stack.append(vertex)",
"+ vertices_status_list[vertex] = color",
"+ while vertices_stack:",
"+ current_vertex = vertices_stack[-1]",
"+ vertices_stack.pop()",
"+ for v in adj_list[current_vertex]:",
"+ if vertices_status_list[v] == -1:",
"+ vertices_status_list[v] = color",
"+ vertices_stack.append(v)",
"+ return None",
"+",
"+",
"+def solve():",
"+ for relation in relation_info:",
"+ key, value = list(map(int, relation.split()))",
"+ adj_list[key].append(value)",
"+ adj_list[value].append(key)",
"+ assign_color()",
"+ # print(adj_list)",
"+ for question in question_list:",
"+ start, target = list(map(int, question.split()))",
"+ if vertices_status_list[start] == vertices_status_list[target]:",
"+ return vertices_status_list",
"- main()",
"+ _input = sys.stdin.readlines()",
"+ vertices_num, relation_num = list(map(int, _input[0].split()))",
"+ relation_info = _input[1 : relation_num + 1]",
"+ question_num = int(_input[relation_num + 1])",
"+ question_list = _input[relation_num + 2 :]",
"+ adj_list = tuple([[] for _ in range(vertices_num)])",
"+ vertices_status_list = [-1] * vertices_num",
"+ ans = solve()"
] | false | 0.045748 | 0.104083 | 0.439536 | [
"s120374797",
"s732135870"
] |
u596276291 | p03475 | python | s980193826 | s278132313 | 100 | 74 | 4,584 | 4,080 | Accepted | Accepted | 26 | import sys
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache, reduce
from operator import xor
from heapq import heappush, heappop
INF = float("inf")
sys.setrecursionlimit(10**7)
# 4近傍(右, 下, 左, 上)
dy4, dx4 = [0, -1, 0, 1], [1, 0, -1, 0]
def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W
def main():
N = int(eval(input()))
C, S, F = [], [], []
for _ in range(N - 1):
c, s, f = list(map(int, input().split()))
C.append(c)
S.append(s)
F.append(f)
for i in range(N):
now = 0
for j in range(i, N - 1):
if S[j] > now:
now += S[j] - now
t = ceil(now / F[j])
now += (F[j] * t) - now
now += C[j]
print(now)
if __name__ == '__main__':
main()
| #!/usr/bin/python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
def inside(y, x, H, W):
return 0 <= y < H and 0 <= x < W
def ceil(a, b):
return (a + b - 1) // b
def main():
N = int(eval(input()))
L = []
for _ in range(N - 1):
c, s, f = list(map(int, input().split()))
L.append((c, s, f))
for i in range(len(L)):
x = 0
for c, s, f in L[i:]:
if x <= s:
x = s + c
else:
x = s + f * ceil(x - s, f) + c
print(x)
print((0))
if __name__ == '__main__':
main()
| 43 | 45 | 1,103 | 1,036 | import sys
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache, reduce
from operator import xor
from heapq import heappush, heappop
INF = float("inf")
sys.setrecursionlimit(10**7)
# 4近傍(右, 下, 左, 上)
dy4, dx4 = [0, -1, 0, 1], [1, 0, -1, 0]
def inside(y: int, x: int, H: int, W: int) -> bool:
return 0 <= y < H and 0 <= x < W
def main():
N = int(eval(input()))
C, S, F = [], [], []
for _ in range(N - 1):
c, s, f = list(map(int, input().split()))
C.append(c)
S.append(s)
F.append(f)
for i in range(N):
now = 0
for j in range(i, N - 1):
if S[j] > now:
now += S[j] - now
t = ceil(now / F[j])
now += (F[j] * t) - now
now += C[j]
print(now)
if __name__ == "__main__":
main()
| #!/usr/bin/python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
def inside(y, x, H, W):
return 0 <= y < H and 0 <= x < W
def ceil(a, b):
return (a + b - 1) // b
def main():
N = int(eval(input()))
L = []
for _ in range(N - 1):
c, s, f = list(map(int, input().split()))
L.append((c, s, f))
for i in range(len(L)):
x = 0
for c, s, f in L[i:]:
if x <= s:
x = s + c
else:
x = s + f * ceil(x - s, f) + c
print(x)
print((0))
if __name__ == "__main__":
main()
| false | 4.444444 | [
"-import sys",
"+#!/usr/bin/python3",
"-from math import pi, sqrt, ceil, floor",
"+from math import pi, sqrt",
"-from functools import lru_cache, reduce",
"-from operator import xor",
"-from heapq import heappush, heappop",
"+from functools import lru_cache",
"+import sys",
"+sys.setrecursionlimit(10000)",
"-sys.setrecursionlimit(10**7)",
"-# 4近傍(右, 下, 左, 上)",
"-dy4, dx4 = [0, -1, 0, 1], [1, 0, -1, 0]",
"+YES, Yes, yes, NO, No, no = \"YES\", \"Yes\", \"yes\", \"NO\", \"No\", \"no\"",
"+dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]",
"-def inside(y: int, x: int, H: int, W: int) -> bool:",
"+def inside(y, x, H, W):",
"+",
"+",
"+def ceil(a, b):",
"+ return (a + b - 1) // b",
"- C, S, F = [], [], []",
"+ L = []",
"- C.append(c)",
"- S.append(s)",
"- F.append(f)",
"- for i in range(N):",
"- now = 0",
"- for j in range(i, N - 1):",
"- if S[j] > now:",
"- now += S[j] - now",
"- t = ceil(now / F[j])",
"- now += (F[j] * t) - now",
"- now += C[j]",
"- print(now)",
"+ L.append((c, s, f))",
"+ for i in range(len(L)):",
"+ x = 0",
"+ for c, s, f in L[i:]:",
"+ if x <= s:",
"+ x = s + c",
"+ else:",
"+ x = s + f * ceil(x - s, f) + c",
"+ print(x)",
"+ print((0))"
] | false | 0.037273 | 0.034727 | 1.073308 | [
"s980193826",
"s278132313"
] |
u606045429 | p03354 | python | s523702064 | s259863050 | 666 | 315 | 13,812 | 44,028 | Accepted | Accepted | 52.7 | # http://www.geocities.jp/m_hiroi/light/pyalgo61.html
class UnionFind3:
def __init__(self, size):
# 負の値はルート (集合の代表) で集合の個数
# 正の値は次の要素を表す
self.table = [-1 for _ in range(size)]
# 集合の代表を求める
def find(self, x):
if self.table[x] < 0:
return x
else:
# 経路の圧縮
self.table[x] = self.find(self.table[x])
return self.table[x]
# 併合
def union(self, x, y):
s1 = self.find(x)
s2 = self.find(y)
if s1 != s2:
if self.table[s1] <= self.table[s2]:
# 小さいほうが個数が多い
self.table[s1] += self.table[s2]
self.table[s2] = s1
else:
self.table[s2] += self.table[s1]
self.table[s1] = s2
return True
return False
N, M = [int(i) for i in input().split()]
p = [int(i) - 1 for i in input().split()]
uf = UnionFind3(N + 1)
for i in range(M):
x, y = [int(i)-1 for i in input().split()]
uf.union(x, y)
count = 0
for i in range(N):
if p[i] != i:
if uf.find(p[i]) == uf.find(i):
count += 1
# pi = p[i]
# ppi = p[pi]
# p[i], p[pi] = ppi, pi
else:
count += 1
print(count) | class UnionFind:
def __init__(self, size):
self.data = [-1] * size
def find(self, x):
if self.data[x] < 0:
return x
else:
self.data[x] = self.find(self.data[x])
return self.data[x]
def union(self, x, y):
x, y = self.find(x), self.find(y)
if x != y:
if self.data[y] < self.data[x]:
x, y = y, x
self.data[x] += self.data[y]
self.data[y] = x
return (x != y)
def same(self, x, y):
return (self.find(x) == self.find(y))
N, M, *I = list(map(int, open(0).read().split()))
P, XY = I[:N], I[N:]
uf = UnionFind(N + 1)
for x, y in zip(*[iter(XY)] * 2):
uf.union(x, y)
ans = 0
for i, p in enumerate(P, 1):
if uf.same(i, p):
ans += 1
print(ans) | 52 | 33 | 1,321 | 837 | # http://www.geocities.jp/m_hiroi/light/pyalgo61.html
class UnionFind3:
def __init__(self, size):
# 負の値はルート (集合の代表) で集合の個数
# 正の値は次の要素を表す
self.table = [-1 for _ in range(size)]
# 集合の代表を求める
def find(self, x):
if self.table[x] < 0:
return x
else:
# 経路の圧縮
self.table[x] = self.find(self.table[x])
return self.table[x]
# 併合
def union(self, x, y):
s1 = self.find(x)
s2 = self.find(y)
if s1 != s2:
if self.table[s1] <= self.table[s2]:
# 小さいほうが個数が多い
self.table[s1] += self.table[s2]
self.table[s2] = s1
else:
self.table[s2] += self.table[s1]
self.table[s1] = s2
return True
return False
N, M = [int(i) for i in input().split()]
p = [int(i) - 1 for i in input().split()]
uf = UnionFind3(N + 1)
for i in range(M):
x, y = [int(i) - 1 for i in input().split()]
uf.union(x, y)
count = 0
for i in range(N):
if p[i] != i:
if uf.find(p[i]) == uf.find(i):
count += 1
# pi = p[i]
# ppi = p[pi]
# p[i], p[pi] = ppi, pi
else:
count += 1
print(count)
| class UnionFind:
def __init__(self, size):
self.data = [-1] * size
def find(self, x):
if self.data[x] < 0:
return x
else:
self.data[x] = self.find(self.data[x])
return self.data[x]
def union(self, x, y):
x, y = self.find(x), self.find(y)
if x != y:
if self.data[y] < self.data[x]:
x, y = y, x
self.data[x] += self.data[y]
self.data[y] = x
return x != y
def same(self, x, y):
return self.find(x) == self.find(y)
N, M, *I = list(map(int, open(0).read().split()))
P, XY = I[:N], I[N:]
uf = UnionFind(N + 1)
for x, y in zip(*[iter(XY)] * 2):
uf.union(x, y)
ans = 0
for i, p in enumerate(P, 1):
if uf.same(i, p):
ans += 1
print(ans)
| false | 36.538462 | [
"-# http://www.geocities.jp/m_hiroi/light/pyalgo61.html",
"-class UnionFind3:",
"+class UnionFind:",
"- # 負の値はルート (集合の代表) で集合の個数",
"- # 正の値は次の要素を表す",
"- self.table = [-1 for _ in range(size)]",
"+ self.data = [-1] * size",
"- # 集合の代表を求める",
"- if self.table[x] < 0:",
"+ if self.data[x] < 0:",
"- # 経路の圧縮",
"- self.table[x] = self.find(self.table[x])",
"- return self.table[x]",
"+ self.data[x] = self.find(self.data[x])",
"+ return self.data[x]",
"- # 併合",
"- s1 = self.find(x)",
"- s2 = self.find(y)",
"- if s1 != s2:",
"- if self.table[s1] <= self.table[s2]:",
"- # 小さいほうが個数が多い",
"- self.table[s1] += self.table[s2]",
"- self.table[s2] = s1",
"- else:",
"- self.table[s2] += self.table[s1]",
"- self.table[s1] = s2",
"- return True",
"- return False",
"+ x, y = self.find(x), self.find(y)",
"+ if x != y:",
"+ if self.data[y] < self.data[x]:",
"+ x, y = y, x",
"+ self.data[x] += self.data[y]",
"+ self.data[y] = x",
"+ return x != y",
"+",
"+ def same(self, x, y):",
"+ return self.find(x) == self.find(y)",
"-N, M = [int(i) for i in input().split()]",
"-p = [int(i) - 1 for i in input().split()]",
"-uf = UnionFind3(N + 1)",
"-for i in range(M):",
"- x, y = [int(i) - 1 for i in input().split()]",
"+N, M, *I = list(map(int, open(0).read().split()))",
"+P, XY = I[:N], I[N:]",
"+uf = UnionFind(N + 1)",
"+for x, y in zip(*[iter(XY)] * 2):",
"-count = 0",
"-for i in range(N):",
"- if p[i] != i:",
"- if uf.find(p[i]) == uf.find(i):",
"- count += 1",
"- # pi = p[i]",
"- # ppi = p[pi]",
"- # p[i], p[pi] = ppi, pi",
"- else:",
"- count += 1",
"-print(count)",
"+ans = 0",
"+for i, p in enumerate(P, 1):",
"+ if uf.same(i, p):",
"+ ans += 1",
"+print(ans)"
] | false | 0.04847 | 0.037199 | 1.302979 | [
"s523702064",
"s259863050"
] |
u644907318 | p03795 | python | s800877885 | s166860203 | 166 | 65 | 38,256 | 61,684 | Accepted | Accepted | 60.84 | N = int(eval(input()))
x = N*800
y = (N//15)*200
print((x-y)) | N = int(eval(input()))
x = 800*N
y = (N//15)*200
print((x-y)) | 4 | 4 | 56 | 56 | N = int(eval(input()))
x = N * 800
y = (N // 15) * 200
print((x - y))
| N = int(eval(input()))
x = 800 * N
y = (N // 15) * 200
print((x - y))
| false | 0 | [
"-x = N * 800",
"+x = 800 * N"
] | false | 0.039647 | 0.03987 | 0.994414 | [
"s800877885",
"s166860203"
] |
u340781749 | p02727 | python | s542416178 | s241299364 | 261 | 237 | 22,720 | 22,560 | Accepted | Accepted | 9.2 | x, y, a, b, c = list(map(int, input().split()))
ppp = list(map(int, input().split()))
qqq = list(map(int, input().split()))
rrr = list(map(int, input().split()))
ppp.sort(reverse=True)
qqq.sort(reverse=True)
rrr.sort(reverse=True)
ppqq = ppp[:x] + qqq[:y]
ppqq.sort(reverse=True)
ppqq.insert(0, 0)
rrr.insert(0, 0)
i = x + y
j = 1
while i > 0 and j <= c and ppqq[i] < rrr[j]:
i -= 1
j += 1
print((sum(ppqq[:i + 1]) + sum(rrr[:j])))
| x, y, a, b, c = list(map(int, input().split()))
ppp = list(map(int, input().split()))
qqq = list(map(int, input().split()))
rrr = list(map(int, input().split()))
ppp.sort(reverse=True)
qqq.sort(reverse=True)
ppqq = ppp[:x] + qqq[:y]
ppqq.extend(rrr)
ppqq.sort(reverse=True)
print((sum(ppqq[:x + y])))
| 18 | 10 | 456 | 308 | x, y, a, b, c = list(map(int, input().split()))
ppp = list(map(int, input().split()))
qqq = list(map(int, input().split()))
rrr = list(map(int, input().split()))
ppp.sort(reverse=True)
qqq.sort(reverse=True)
rrr.sort(reverse=True)
ppqq = ppp[:x] + qqq[:y]
ppqq.sort(reverse=True)
ppqq.insert(0, 0)
rrr.insert(0, 0)
i = x + y
j = 1
while i > 0 and j <= c and ppqq[i] < rrr[j]:
i -= 1
j += 1
print((sum(ppqq[: i + 1]) + sum(rrr[:j])))
| x, y, a, b, c = list(map(int, input().split()))
ppp = list(map(int, input().split()))
qqq = list(map(int, input().split()))
rrr = list(map(int, input().split()))
ppp.sort(reverse=True)
qqq.sort(reverse=True)
ppqq = ppp[:x] + qqq[:y]
ppqq.extend(rrr)
ppqq.sort(reverse=True)
print((sum(ppqq[: x + y])))
| false | 44.444444 | [
"-rrr.sort(reverse=True)",
"+ppqq.extend(rrr)",
"-ppqq.insert(0, 0)",
"-rrr.insert(0, 0)",
"-i = x + y",
"-j = 1",
"-while i > 0 and j <= c and ppqq[i] < rrr[j]:",
"- i -= 1",
"- j += 1",
"-print((sum(ppqq[: i + 1]) + sum(rrr[:j])))",
"+print((sum(ppqq[: x + y])))"
] | false | 0.091532 | 0.087241 | 1.049186 | [
"s542416178",
"s241299364"
] |
u562935282 | p02735 | python | s274337012 | s032479222 | 238 | 30 | 43,376 | 3,064 | Accepted | Accepted | 87.39 | def main():
from collections import deque
WHITE = 0
BLACK = 1
CHAR = '.', '#'
H, W = list(map(int, input().split()))
s = [eval(input()) for _ in range(H)]
h = deque()
x = CHAR.index(s[0][0])
h.append((x, 0, 0, x))
cost = [[H * W] * W for _ in range(H)]
cost[0][0] = x
while h:
cnt, r, c, mode = h.popleft()
if cnt > cost[r][c]:
continue
if r == H - 1 and c == W - 1:
print(cnt)
return
delta = int(mode == WHITE)
ncnt = cnt + delta
if r < H - 1:
if s[r + 1][c] == CHAR[mode]:
if cnt < cost[r + 1][c]:
cost[r + 1][c] = cnt
h.appendleft((cnt, r + 1, c, mode))
else:
if delta:
if ncnt < cost[r + 1][c]:
cost[r + 1][c] = ncnt
h.append((ncnt, r + 1, c, 1 - mode))
else:
if ncnt < cost[r + 1][c]:
cost[r + 1][c] = ncnt
h.appendleft((ncnt, r + 1, c, 1 - mode))
if c < W - 1:
if s[r][c + 1] == CHAR[mode]:
if cnt < cost[r][c + 1]:
cost[r][c + 1] = cnt
h.appendleft((cnt, r, c + 1, mode))
else:
if delta:
if ncnt < cost[r][c + 1]:
cost[r][c + 1] = ncnt
h.append((ncnt, r, c + 1, 1 - mode))
else:
if ncnt < cost[r][c + 1]:
cost[r][c + 1] = ncnt
h.appendleft((ncnt, r, c + 1, 1 - mode))
if __name__ == '__main__':
main()
# import sys
#
# input = sys.stdin.readline
# sys.setrecursionlimit(10 ** 7)
# rstrip()
# int(input())
# map(int, input().split())
| def main():
H, W = list(map(int, input().split()))
s = [eval(input()) for _ in range(H)]
dp = [[H * W] * W for _ in range(H)]
dp[0][0] = int(s[0][0] == '#')
for r in range(H):
for c in range(W):
if r > 0:
dp[r][c] = min(dp[r][c], dp[r - 1][c] + int(s[r][c] == '#' and s[r - 1][c] == '.'))
if c > 0:
dp[r][c] = min(dp[r][c], dp[r][c - 1] + int(s[r][c] == '#' and s[r][c - 1] == '.'))
res = dp[H - 1][W - 1]
print(res)
return
if __name__ == '__main__':
main()
| 70 | 22 | 1,949 | 573 | def main():
from collections import deque
WHITE = 0
BLACK = 1
CHAR = ".", "#"
H, W = list(map(int, input().split()))
s = [eval(input()) for _ in range(H)]
h = deque()
x = CHAR.index(s[0][0])
h.append((x, 0, 0, x))
cost = [[H * W] * W for _ in range(H)]
cost[0][0] = x
while h:
cnt, r, c, mode = h.popleft()
if cnt > cost[r][c]:
continue
if r == H - 1 and c == W - 1:
print(cnt)
return
delta = int(mode == WHITE)
ncnt = cnt + delta
if r < H - 1:
if s[r + 1][c] == CHAR[mode]:
if cnt < cost[r + 1][c]:
cost[r + 1][c] = cnt
h.appendleft((cnt, r + 1, c, mode))
else:
if delta:
if ncnt < cost[r + 1][c]:
cost[r + 1][c] = ncnt
h.append((ncnt, r + 1, c, 1 - mode))
else:
if ncnt < cost[r + 1][c]:
cost[r + 1][c] = ncnt
h.appendleft((ncnt, r + 1, c, 1 - mode))
if c < W - 1:
if s[r][c + 1] == CHAR[mode]:
if cnt < cost[r][c + 1]:
cost[r][c + 1] = cnt
h.appendleft((cnt, r, c + 1, mode))
else:
if delta:
if ncnt < cost[r][c + 1]:
cost[r][c + 1] = ncnt
h.append((ncnt, r, c + 1, 1 - mode))
else:
if ncnt < cost[r][c + 1]:
cost[r][c + 1] = ncnt
h.appendleft((ncnt, r, c + 1, 1 - mode))
if __name__ == "__main__":
main()
# import sys
#
# input = sys.stdin.readline
# sys.setrecursionlimit(10 ** 7)
# rstrip()
# int(input())
# map(int, input().split())
| def main():
H, W = list(map(int, input().split()))
s = [eval(input()) for _ in range(H)]
dp = [[H * W] * W for _ in range(H)]
dp[0][0] = int(s[0][0] == "#")
for r in range(H):
for c in range(W):
if r > 0:
dp[r][c] = min(
dp[r][c], dp[r - 1][c] + int(s[r][c] == "#" and s[r - 1][c] == ".")
)
if c > 0:
dp[r][c] = min(
dp[r][c], dp[r][c - 1] + int(s[r][c] == "#" and s[r][c - 1] == ".")
)
res = dp[H - 1][W - 1]
print(res)
return
if __name__ == "__main__":
main()
| false | 68.571429 | [
"- from collections import deque",
"-",
"- WHITE = 0",
"- BLACK = 1",
"- CHAR = \".\", \"#\"",
"- h = deque()",
"- x = CHAR.index(s[0][0])",
"- h.append((x, 0, 0, x))",
"- cost = [[H * W] * W for _ in range(H)]",
"- cost[0][0] = x",
"- while h:",
"- cnt, r, c, mode = h.popleft()",
"- if cnt > cost[r][c]:",
"- continue",
"- if r == H - 1 and c == W - 1:",
"- print(cnt)",
"- return",
"- delta = int(mode == WHITE)",
"- ncnt = cnt + delta",
"- if r < H - 1:",
"- if s[r + 1][c] == CHAR[mode]:",
"- if cnt < cost[r + 1][c]:",
"- cost[r + 1][c] = cnt",
"- h.appendleft((cnt, r + 1, c, mode))",
"- else:",
"- if delta:",
"- if ncnt < cost[r + 1][c]:",
"- cost[r + 1][c] = ncnt",
"- h.append((ncnt, r + 1, c, 1 - mode))",
"- else:",
"- if ncnt < cost[r + 1][c]:",
"- cost[r + 1][c] = ncnt",
"- h.appendleft((ncnt, r + 1, c, 1 - mode))",
"- if c < W - 1:",
"- if s[r][c + 1] == CHAR[mode]:",
"- if cnt < cost[r][c + 1]:",
"- cost[r][c + 1] = cnt",
"- h.appendleft((cnt, r, c + 1, mode))",
"- else:",
"- if delta:",
"- if ncnt < cost[r][c + 1]:",
"- cost[r][c + 1] = ncnt",
"- h.append((ncnt, r, c + 1, 1 - mode))",
"- else:",
"- if ncnt < cost[r][c + 1]:",
"- cost[r][c + 1] = ncnt",
"- h.appendleft((ncnt, r, c + 1, 1 - mode))",
"+ dp = [[H * W] * W for _ in range(H)]",
"+ dp[0][0] = int(s[0][0] == \"#\")",
"+ for r in range(H):",
"+ for c in range(W):",
"+ if r > 0:",
"+ dp[r][c] = min(",
"+ dp[r][c], dp[r - 1][c] + int(s[r][c] == \"#\" and s[r - 1][c] == \".\")",
"+ )",
"+ if c > 0:",
"+ dp[r][c] = min(",
"+ dp[r][c], dp[r][c - 1] + int(s[r][c] == \"#\" and s[r][c - 1] == \".\")",
"+ )",
"+ res = dp[H - 1][W - 1]",
"+ print(res)",
"+ return",
"-# import sys",
"-#",
"-# input = sys.stdin.readline",
"-# sys.setrecursionlimit(10 ** 7)",
"-# rstrip()",
"-# int(input())",
"-# map(int, input().split())"
] | false | 0.038529 | 0.038705 | 0.995449 | [
"s274337012",
"s032479222"
] |
u970267139 | p03752 | python | s666626824 | s824559418 | 327 | 170 | 3,064 | 3,064 | Accepted | Accepted | 48.01 | N, K = list(map(int, input().split()))
a = list(map(int, input().split()))
ans = pow(10, 18)
for i in range(2 ** N):
cost = 0
cnt = 0
highest = 0
for j in range(N):
if (i >> j) & 1:
cnt += 1
if highest >= a[j]:
cost += highest - a[j] + 1
highest += 1
highest = max(highest, a[j])
if cnt >= K:
ans = min(cost, ans)
print(ans) | n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
cost = 10 ** 18
for i in range(2 ** (n - 1)):
num = 0
c = 0
prev = a[0]
for j in range(n - 1):
if i >> j & 1:
num += 1
if a[j + 1] <= prev:
c += prev - a[j + 1] + 1
prev += 1
prev = max(prev, a[j + 1])
if num >= k - 1:
cost = min(c, cost)
print(cost) | 21 | 18 | 442 | 437 | N, K = list(map(int, input().split()))
a = list(map(int, input().split()))
ans = pow(10, 18)
for i in range(2**N):
cost = 0
cnt = 0
highest = 0
for j in range(N):
if (i >> j) & 1:
cnt += 1
if highest >= a[j]:
cost += highest - a[j] + 1
highest += 1
highest = max(highest, a[j])
if cnt >= K:
ans = min(cost, ans)
print(ans)
| n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
cost = 10**18
for i in range(2 ** (n - 1)):
num = 0
c = 0
prev = a[0]
for j in range(n - 1):
if i >> j & 1:
num += 1
if a[j + 1] <= prev:
c += prev - a[j + 1] + 1
prev += 1
prev = max(prev, a[j + 1])
if num >= k - 1:
cost = min(c, cost)
print(cost)
| false | 14.285714 | [
"-N, K = list(map(int, input().split()))",
"+n, k = list(map(int, input().split()))",
"-ans = pow(10, 18)",
"-for i in range(2**N):",
"- cost = 0",
"- cnt = 0",
"- highest = 0",
"- for j in range(N):",
"- if (i >> j) & 1:",
"- cnt += 1",
"- if highest >= a[j]:",
"- cost += highest - a[j] + 1",
"- highest += 1",
"- highest = max(highest, a[j])",
"- if cnt >= K:",
"- ans = min(cost, ans)",
"-print(ans)",
"+cost = 10**18",
"+for i in range(2 ** (n - 1)):",
"+ num = 0",
"+ c = 0",
"+ prev = a[0]",
"+ for j in range(n - 1):",
"+ if i >> j & 1:",
"+ num += 1",
"+ if a[j + 1] <= prev:",
"+ c += prev - a[j + 1] + 1",
"+ prev += 1",
"+ prev = max(prev, a[j + 1])",
"+ if num >= k - 1:",
"+ cost = min(c, cost)",
"+print(cost)"
] | false | 0.068628 | 0.088793 | 0.772903 | [
"s666626824",
"s824559418"
] |
u605853117 | p03170 | python | s894278687 | s961418817 | 1,077 | 333 | 60,508 | 52,828 | Accepted | Accepted | 69.08 | """
AtCoder Educational DP Contest
https://atcoder.jp/contests/dp/tasks/dp_k
K - Stones
"""
import collections
def solve(xs):
dp = collections.defaultdict(bool)
dp[0] = False
for j in range(1, K + 1):
iterable = ((j >= x) and (not dp[j - x]) for x in xs)
dp[j] = any(iterable)
return dp[K]
N, K = list(map(int, input().split()))
choices = collections.Counter([float(s) for s in input().split()])
assert len(choices) == N
res = solve(choices)
print(("First" if res else "Second"))
| """
AtCoder Educational DP Contest
https://atcoder.jp/contests/dp/tasks/dp_k
K - Stones
"""
import collections
def solve(xs):
dp = collections.defaultdict(bool)
dp[0] = False
for j in range(1, K + 1):
dp[j] = any((j >= x) and (not dp[j - x]) for x in xs)
return dp[K]
N, K = list(map(int, input().split()))
choices = [int(s) for s in input().split()]
assert len(choices) == N
res = solve(choices)
print(("First" if res else "Second"))
| 22 | 20 | 529 | 473 | """
AtCoder Educational DP Contest
https://atcoder.jp/contests/dp/tasks/dp_k
K - Stones
"""
import collections
def solve(xs):
dp = collections.defaultdict(bool)
dp[0] = False
for j in range(1, K + 1):
iterable = ((j >= x) and (not dp[j - x]) for x in xs)
dp[j] = any(iterable)
return dp[K]
N, K = list(map(int, input().split()))
choices = collections.Counter([float(s) for s in input().split()])
assert len(choices) == N
res = solve(choices)
print(("First" if res else "Second"))
| """
AtCoder Educational DP Contest
https://atcoder.jp/contests/dp/tasks/dp_k
K - Stones
"""
import collections
def solve(xs):
dp = collections.defaultdict(bool)
dp[0] = False
for j in range(1, K + 1):
dp[j] = any((j >= x) and (not dp[j - x]) for x in xs)
return dp[K]
N, K = list(map(int, input().split()))
choices = [int(s) for s in input().split()]
assert len(choices) == N
res = solve(choices)
print(("First" if res else "Second"))
| false | 9.090909 | [
"- iterable = ((j >= x) and (not dp[j - x]) for x in xs)",
"- dp[j] = any(iterable)",
"+ dp[j] = any((j >= x) and (not dp[j - x]) for x in xs)",
"-choices = collections.Counter([float(s) for s in input().split()])",
"+choices = [int(s) for s in input().split()]"
] | false | 0.101389 | 0.041766 | 2.427541 | [
"s894278687",
"s961418817"
] |
u406379114 | p02659 | python | s075683580 | s817427835 | 28 | 23 | 10,068 | 9,184 | Accepted | Accepted | 17.86 | from decimal import Decimal
a, b = input().split()
a = Decimal(a)
b = Decimal(b)
c = a*b
print((int(a*b))) | a, b = input().split()
a = int(a)
c = 0
c += a*int(b[0])*100
c += a*int(b[2])*10
c += a*int(b[3])
c = str(c)
if(len(c) < 3):
print((0))
else:
print((c[:-2]))
| 7 | 13 | 111 | 172 | from decimal import Decimal
a, b = input().split()
a = Decimal(a)
b = Decimal(b)
c = a * b
print((int(a * b)))
| a, b = input().split()
a = int(a)
c = 0
c += a * int(b[0]) * 100
c += a * int(b[2]) * 10
c += a * int(b[3])
c = str(c)
if len(c) < 3:
print((0))
else:
print((c[:-2]))
| false | 46.153846 | [
"-from decimal import Decimal",
"-",
"-a = Decimal(a)",
"-b = Decimal(b)",
"-c = a * b",
"-print((int(a * b)))",
"+a = int(a)",
"+c = 0",
"+c += a * int(b[0]) * 100",
"+c += a * int(b[2]) * 10",
"+c += a * int(b[3])",
"+c = str(c)",
"+if len(c) < 3:",
"+ print((0))",
"+else:",
"+ print((c[:-2]))"
] | false | 0.054179 | 0.050602 | 1.070678 | [
"s075683580",
"s817427835"
] |
u692746605 | p02714 | python | s287398682 | s290393202 | 1,405 | 958 | 9,252 | 9,192 | Accepted | Accepted | 31.81 | N=int(eval(input()))
S=[1 if x=='R' else (2 if x=='G' else 3) for x in [*eval(input())]]
t=S.count(1)*S.count(2)*S.count(3)
for i in range(N-2):
j=1
while i+2*j<N:
if S[i]*S[i+j]*S[i+2*j]==6:
t-=1
j+=1
print(t)
| def main():
N=int(eval(input()))
S=[1 if x=='R' else (2 if x=='G' else 3) for x in [*eval(input())]]
t=S.count(1)*S.count(2)*S.count(3)
for i in range(N-2):
j=1
while i+2*j<N:
if S[i]*S[i+j]*S[i+2*j]==6:
t-=1
j+=1
print(t)
main()
| 12 | 15 | 230 | 273 | N = int(eval(input()))
S = [1 if x == "R" else (2 if x == "G" else 3) for x in [*eval(input())]]
t = S.count(1) * S.count(2) * S.count(3)
for i in range(N - 2):
j = 1
while i + 2 * j < N:
if S[i] * S[i + j] * S[i + 2 * j] == 6:
t -= 1
j += 1
print(t)
| def main():
N = int(eval(input()))
S = [1 if x == "R" else (2 if x == "G" else 3) for x in [*eval(input())]]
t = S.count(1) * S.count(2) * S.count(3)
for i in range(N - 2):
j = 1
while i + 2 * j < N:
if S[i] * S[i + j] * S[i + 2 * j] == 6:
t -= 1
j += 1
print(t)
main()
| false | 20 | [
"-N = int(eval(input()))",
"-S = [1 if x == \"R\" else (2 if x == \"G\" else 3) for x in [*eval(input())]]",
"-t = S.count(1) * S.count(2) * S.count(3)",
"-for i in range(N - 2):",
"- j = 1",
"- while i + 2 * j < N:",
"- if S[i] * S[i + j] * S[i + 2 * j] == 6:",
"- t -= 1",
"- j += 1",
"-print(t)",
"+def main():",
"+ N = int(eval(input()))",
"+ S = [1 if x == \"R\" else (2 if x == \"G\" else 3) for x in [*eval(input())]]",
"+ t = S.count(1) * S.count(2) * S.count(3)",
"+ for i in range(N - 2):",
"+ j = 1",
"+ while i + 2 * j < N:",
"+ if S[i] * S[i + j] * S[i + 2 * j] == 6:",
"+ t -= 1",
"+ j += 1",
"+ print(t)",
"+",
"+",
"+main()"
] | false | 0.036118 | 0.038421 | 0.940076 | [
"s287398682",
"s290393202"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.