user_id
stringlengths
10
10
problem_id
stringlengths
6
6
language
stringclasses
1 value
submission_id_v0
stringlengths
10
10
submission_id_v1
stringlengths
10
10
cpu_time_v0
int64
10
38.3k
cpu_time_v1
int64
0
24.7k
memory_v0
int64
2.57k
1.02M
memory_v1
int64
2.57k
869k
status_v0
stringclasses
1 value
status_v1
stringclasses
1 value
improvement_frac
float64
7.51
100
input
stringlengths
20
4.55k
target
stringlengths
17
3.34k
code_v0_loc
int64
1
148
code_v1_loc
int64
1
184
code_v0_num_chars
int64
13
4.55k
code_v1_num_chars
int64
14
3.34k
code_v0_no_empty_lines
stringlengths
21
6.88k
code_v1_no_empty_lines
stringlengths
20
4.93k
code_same
bool
1 class
relative_loc_diff_percent
float64
0
79.8
diff
list
diff_only_import_comment
bool
1 class
measured_runtime_v0
float64
0.01
4.45
measured_runtime_v1
float64
0.01
4.31
runtime_lift
float64
0
359
key
list
u426534722
p02249
python
s403110051
s756174700
1,780
1,490
92,000
92,016
Accepted
Accepted
16.29
base1 = 1009 base2 = 1013 mask = (1 << 32) - 1 def calc_hash(f, r, c): global ph, pw, h tmp = [[0] * c for _ in range(r)] dr, dc = r - ph, c - pw t1 = 1 for _ in range(pw): t1 = (t1 * base1) & mask for i in range(r): e = 0 for j in range(pw): e = e * base1 + f[i][j] for j in range(dc): tmp[i][j] = e e = (e * base1 - t1 * f[i][j] + f[i][j + pw]) & mask tmp[i][dc] = e t2 = 1 for _ in range(ph): t2 = (t2 * base2) & mask for j in range(dc + 1): e = 0 for i in range(ph): e = e * base2 + tmp[i][j] for i in range(dr): h[i][j] = e e = (e * base2 - t2 * tmp[i][j] + tmp[i + ph][j]) & mask h[dr][j] = e th, tw = list(map(int, input().split())) t = tuple(tuple(ord(c) for c in eval(input())) for _ in range(th)) ph, pw = list(map(int, input().split())) p = tuple(tuple(ord(c) for c in eval(input())) for _ in range(ph)) if th >= ph and tw >= pw: h = [[0] * tw for _ in range(th)] calc_hash(p, ph, pw) key = h[0][0] & mask calc_hash(t, th, tw) for i in range(th - ph + 1): for j in range(tw - pw + 1): if h[i][j] & mask == key: print((i, j))
base1 = 1009 base2 = 1013 mask = (1 << 32) - 1 def calc_hash(f, r, c): global ph, pw, h tmp = [[0] * c for _ in range(r)] dr, dc = r - ph, c - pw t1 = 1 for _ in range(pw): t1 = (t1 * base1) & mask for i in range(r): e = 0 for j in range(pw): e = e * base1 + f[i][j] for j in range(dc): tmp[i][j] = e e = (e * base1 - t1 * f[i][j] + f[i][j + pw]) & mask tmp[i][dc] = e t2 = 1 for _ in range(ph): t2 = (t2 * base2) & mask for j in range(dc + 1): e = 0 for i in range(ph): e = e * base2 + tmp[i][j] for i in range(dr): h[i][j] = e e = (e * base2 - t2 * tmp[i][j] + tmp[i + ph][j]) & mask h[dr][j] = e th, tw = list(map(int, input().split())) t = tuple(tuple(ord(c) for c in eval(input())) for _ in range(th)) ph, pw = list(map(int, input().split())) p = tuple(tuple(ord(c) for c in eval(input())) for _ in range(ph)) ans = [] if th >= ph and tw >= pw: h = [[0] * tw for _ in range(th)] calc_hash(p, ph, pw) key = h[0][0] & mask calc_hash(t, th, tw) for i in range(th - ph + 1): for j in range(tw - pw + 1): if h[i][j] & mask == key: ans.append(f"{i} {j}") if ans: print(("\n".join(a for a in ans)))
43
45
1,297
1,363
base1 = 1009 base2 = 1013 mask = (1 << 32) - 1 def calc_hash(f, r, c): global ph, pw, h tmp = [[0] * c for _ in range(r)] dr, dc = r - ph, c - pw t1 = 1 for _ in range(pw): t1 = (t1 * base1) & mask for i in range(r): e = 0 for j in range(pw): e = e * base1 + f[i][j] for j in range(dc): tmp[i][j] = e e = (e * base1 - t1 * f[i][j] + f[i][j + pw]) & mask tmp[i][dc] = e t2 = 1 for _ in range(ph): t2 = (t2 * base2) & mask for j in range(dc + 1): e = 0 for i in range(ph): e = e * base2 + tmp[i][j] for i in range(dr): h[i][j] = e e = (e * base2 - t2 * tmp[i][j] + tmp[i + ph][j]) & mask h[dr][j] = e th, tw = list(map(int, input().split())) t = tuple(tuple(ord(c) for c in eval(input())) for _ in range(th)) ph, pw = list(map(int, input().split())) p = tuple(tuple(ord(c) for c in eval(input())) for _ in range(ph)) if th >= ph and tw >= pw: h = [[0] * tw for _ in range(th)] calc_hash(p, ph, pw) key = h[0][0] & mask calc_hash(t, th, tw) for i in range(th - ph + 1): for j in range(tw - pw + 1): if h[i][j] & mask == key: print((i, j))
base1 = 1009 base2 = 1013 mask = (1 << 32) - 1 def calc_hash(f, r, c): global ph, pw, h tmp = [[0] * c for _ in range(r)] dr, dc = r - ph, c - pw t1 = 1 for _ in range(pw): t1 = (t1 * base1) & mask for i in range(r): e = 0 for j in range(pw): e = e * base1 + f[i][j] for j in range(dc): tmp[i][j] = e e = (e * base1 - t1 * f[i][j] + f[i][j + pw]) & mask tmp[i][dc] = e t2 = 1 for _ in range(ph): t2 = (t2 * base2) & mask for j in range(dc + 1): e = 0 for i in range(ph): e = e * base2 + tmp[i][j] for i in range(dr): h[i][j] = e e = (e * base2 - t2 * tmp[i][j] + tmp[i + ph][j]) & mask h[dr][j] = e th, tw = list(map(int, input().split())) t = tuple(tuple(ord(c) for c in eval(input())) for _ in range(th)) ph, pw = list(map(int, input().split())) p = tuple(tuple(ord(c) for c in eval(input())) for _ in range(ph)) ans = [] if th >= ph and tw >= pw: h = [[0] * tw for _ in range(th)] calc_hash(p, ph, pw) key = h[0][0] & mask calc_hash(t, th, tw) for i in range(th - ph + 1): for j in range(tw - pw + 1): if h[i][j] & mask == key: ans.append(f"{i} {j}") if ans: print(("\n".join(a for a in ans)))
false
4.444444
[ "+ans = []", "- print((i, j))", "+ ans.append(f\"{i} {j}\")", "+if ans:", "+ print((\"\\n\".join(a for a in ans)))" ]
false
0.051315
0.041935
1.223674
[ "s403110051", "s756174700" ]
u669696235
p02688
python
s165594743
s524206418
22
20
9,188
9,172
Accepted
Accepted
9.09
N,K=list(map(int,input().split())) hoge=[0 for j in range(N)] for j in range(K): eval(input()) for i in input().split(): hoge[int(i)-1]+=1 print((sum([j==0 for j in hoge])))
N,K=list(map(int,input().split())) hoge={} for j in range(K): eval(input()) [hoge.update({int(j)-1:1}) for j in input().split()] print((sum([not j in hoge for j in range(N)])))
8
6
184
176
N, K = list(map(int, input().split())) hoge = [0 for j in range(N)] for j in range(K): eval(input()) for i in input().split(): hoge[int(i) - 1] += 1 print((sum([j == 0 for j in hoge])))
N, K = list(map(int, input().split())) hoge = {} for j in range(K): eval(input()) [hoge.update({int(j) - 1: 1}) for j in input().split()] print((sum([not j in hoge for j in range(N)])))
false
25
[ "-hoge = [0 for j in range(N)]", "+hoge = {}", "- for i in input().split():", "- hoge[int(i) - 1] += 1", "-print((sum([j == 0 for j in hoge])))", "+ [hoge.update({int(j) - 1: 1}) for j in input().split()]", "+print((sum([not j in hoge for j in range(N)])))" ]
false
0.033296
0.035707
0.93247
[ "s165594743", "s524206418" ]
u633068244
p00086
python
s407539577
s770789272
20
10
4,216
4,216
Accepted
Accepted
50
while True: try: path = [0]*101 while True: a,b = list(map(int, input().split())) if a == 0: break path[a-1] += 1; path[b-1] += 1 for i in range(3,101): if path[i]%2 != 0: flag = 0 break else: flag = 1 if path[0]%2 == path[1]%2 == 1 and flag: print("OK") else: print("NG") except: break
while True: try: path = [0]*100 while True: a,b = list(map(int, input().split())) if a == 0: break path[a-1] += 1; path[b-1] += 1 if path[0]%2 == path[1]%2 == 1 and sum([x for x in path[2:] if x%2==1]) == 0: print("OK") else: print("NG") except: break
19
13
352
293
while True: try: path = [0] * 101 while True: a, b = list(map(int, input().split())) if a == 0: break path[a - 1] += 1 path[b - 1] += 1 for i in range(3, 101): if path[i] % 2 != 0: flag = 0 break else: flag = 1 if path[0] % 2 == path[1] % 2 == 1 and flag: print("OK") else: print("NG") except: break
while True: try: path = [0] * 100 while True: a, b = list(map(int, input().split())) if a == 0: break path[a - 1] += 1 path[b - 1] += 1 if ( path[0] % 2 == path[1] % 2 == 1 and sum([x for x in path[2:] if x % 2 == 1]) == 0 ): print("OK") else: print("NG") except: break
false
31.578947
[ "- path = [0] * 101", "+ path = [0] * 100", "- for i in range(3, 101):", "- if path[i] % 2 != 0:", "- flag = 0", "- break", "- else:", "- flag = 1", "- if path[0] % 2 == path[1] % 2 == 1 and flag:", "+ if (", "+ path[0] % 2 == path[1] % 2 == 1", "+ and sum([x for x in path[2:] if x % 2 == 1]) == 0", "+ ):" ]
false
0.045754
0.04644
0.985241
[ "s407539577", "s770789272" ]
u278886389
p03854
python
s332329927
s394578057
232
191
6,952
7,576
Accepted
Accepted
17.67
from collections import deque S = eval(input()) l = len(S) a = list(map(list,['dream','dreamer','erase','eraser'])) q = deque() q.append(["",0]) while len(q): b,i = q.pop() if i == l: print('YES') exit() x = 0 f = True for B in b: if i+x >= l or S[i+x] != B: f = False x += 1 if f: for A in a: q.append([A,i+x]) print('NO')
from collections import deque S = list(eval(input())) S.reverse() l = len(S) def rev(x): x = list(x) x.reverse() return x a = list(map(rev,['dream','dreamer','erase','eraser'])) q = deque() q.append(["",0]) while len(q): b,i = q.pop() if i == l: print('YES') exit() x = 0 f = True for B in b: if i+x >= l or S[i+x] != B: f = False x += 1 if f: for A in a: q.append([A,i+x]) print('NO')
25
31
434
515
from collections import deque S = eval(input()) l = len(S) a = list(map(list, ["dream", "dreamer", "erase", "eraser"])) q = deque() q.append(["", 0]) while len(q): b, i = q.pop() if i == l: print("YES") exit() x = 0 f = True for B in b: if i + x >= l or S[i + x] != B: f = False x += 1 if f: for A in a: q.append([A, i + x]) print("NO")
from collections import deque S = list(eval(input())) S.reverse() l = len(S) def rev(x): x = list(x) x.reverse() return x a = list(map(rev, ["dream", "dreamer", "erase", "eraser"])) q = deque() q.append(["", 0]) while len(q): b, i = q.pop() if i == l: print("YES") exit() x = 0 f = True for B in b: if i + x >= l or S[i + x] != B: f = False x += 1 if f: for A in a: q.append([A, i + x]) print("NO")
false
19.354839
[ "-S = eval(input())", "+S = list(eval(input()))", "+S.reverse()", "-a = list(map(list, [\"dream\", \"dreamer\", \"erase\", \"eraser\"]))", "+", "+", "+def rev(x):", "+ x = list(x)", "+ x.reverse()", "+ return x", "+", "+", "+a = list(map(rev, [\"dream\", \"dreamer\", \"erase\", \"eraser\"]))" ]
false
0.046474
0.045853
1.013526
[ "s332329927", "s394578057" ]
u928784113
p03059
python
s072126164
s427478077
19
17
2,940
2,940
Accepted
Accepted
10.53
A,B,T = list(map(int,input().split())) print((B*(T//A)))
A,B,T = list(map(int,input().split())) print(((T//A)*B))
2
2
49
49
A, B, T = list(map(int, input().split())) print((B * (T // A)))
A, B, T = list(map(int, input().split())) print(((T // A) * B))
false
0
[ "-print((B * (T // A)))", "+print(((T // A) * B))" ]
false
0.063405
0.062521
1.014151
[ "s072126164", "s427478077" ]
u790710233
p02683
python
s308258827
s095104592
81
35
9,228
9,240
Accepted
Accepted
56.79
n, m, x = list(map(int, input().split())) ca = [tuple(map(int, input().split()))for _ in range(n)] INF = 10**18 ans = INF for bit in range(1 << n): cost = 0 proficiency = [0]*m for i in range(n): if bit >> i & 1: c, *A = ca[i] cost += c for j in range(m): proficiency[j] += A[j] if cost < ans and all(x <= proficiency[j]for j in range(m)): ans = cost print((ans if ans != INF else -1))
import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) n, m, x = list(map(int, input().split())) ca = [tuple(map(int, input().split()))for _ in range(n)] INF = 10**18 ans = INF proficiency = [0]*m def dfs(i, cost): if i == n: global ans if cost < ans and all(x <= proficiency[j]for j in range(m)): ans = cost return 0 c, *A = ca[i] for j in range(m): proficiency[j] += A[j] dfs(i+1, cost+c) for j in range(m): proficiency[j] -= A[j] dfs(i+1, cost) dfs(0, 0) print((ans if ans != INF else -1))
16
28
476
604
n, m, x = list(map(int, input().split())) ca = [tuple(map(int, input().split())) for _ in range(n)] INF = 10**18 ans = INF for bit in range(1 << n): cost = 0 proficiency = [0] * m for i in range(n): if bit >> i & 1: c, *A = ca[i] cost += c for j in range(m): proficiency[j] += A[j] if cost < ans and all(x <= proficiency[j] for j in range(m)): ans = cost print((ans if ans != INF else -1))
import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) n, m, x = list(map(int, input().split())) ca = [tuple(map(int, input().split())) for _ in range(n)] INF = 10**18 ans = INF proficiency = [0] * m def dfs(i, cost): if i == n: global ans if cost < ans and all(x <= proficiency[j] for j in range(m)): ans = cost return 0 c, *A = ca[i] for j in range(m): proficiency[j] += A[j] dfs(i + 1, cost + c) for j in range(m): proficiency[j] -= A[j] dfs(i + 1, cost) dfs(0, 0) print((ans if ans != INF else -1))
false
42.857143
[ "+import sys", "+", "+input = sys.stdin.readline", "+sys.setrecursionlimit(10**7)", "-for bit in range(1 << n):", "- cost = 0", "- proficiency = [0] * m", "- for i in range(n):", "- if bit >> i & 1:", "- c, *A = ca[i]", "- cost += c", "- for j in range(m):", "- proficiency[j] += A[j]", "- if cost < ans and all(x <= proficiency[j] for j in range(m)):", "- ans = cost", "+proficiency = [0] * m", "+", "+", "+def dfs(i, cost):", "+ if i == n:", "+ global ans", "+ if cost < ans and all(x <= proficiency[j] for j in range(m)):", "+ ans = cost", "+ return 0", "+ c, *A = ca[i]", "+ for j in range(m):", "+ proficiency[j] += A[j]", "+ dfs(i + 1, cost + c)", "+ for j in range(m):", "+ proficiency[j] -= A[j]", "+ dfs(i + 1, cost)", "+", "+", "+dfs(0, 0)" ]
false
0.039435
0.03835
1.028298
[ "s308258827", "s095104592" ]
u821969418
p02629
python
s620108843
s573018809
32
28
9,112
9,136
Accepted
Accepted
12.5
def alpha2num(alpha): num=0 for index, item in enumerate(list(alpha)): num += pow(26,len(alpha)-index-1)*(ord(item)-ord('A')+1) return num def num2alpha(num): if num<=26: return chr(64+num) elif num%26==0: return num2alpha(num//26-1)+chr(90) else: return num2alpha(num//26)+chr(64+num%26) n=int(eval(input())) s = num2alpha(n) print((s.lower()))
n=int(eval(input())) chars = "Xabcdefghijklmnopqrstuvwxyz" n_rem = n ans = "" while True: x = n_rem%26 if x == 0: x = 26 ans += chars[x] n_rem -= x if n_rem == 0: break n_rem //=26 print((ans[::-1]))
18
20
413
257
def alpha2num(alpha): num = 0 for index, item in enumerate(list(alpha)): num += pow(26, len(alpha) - index - 1) * (ord(item) - ord("A") + 1) return num def num2alpha(num): if num <= 26: return chr(64 + num) elif num % 26 == 0: return num2alpha(num // 26 - 1) + chr(90) else: return num2alpha(num // 26) + chr(64 + num % 26) n = int(eval(input())) s = num2alpha(n) print((s.lower()))
n = int(eval(input())) chars = "Xabcdefghijklmnopqrstuvwxyz" n_rem = n ans = "" while True: x = n_rem % 26 if x == 0: x = 26 ans += chars[x] n_rem -= x if n_rem == 0: break n_rem //= 26 print((ans[::-1]))
false
10
[ "-def alpha2num(alpha):", "- num = 0", "- for index, item in enumerate(list(alpha)):", "- num += pow(26, len(alpha) - index - 1) * (ord(item) - ord(\"A\") + 1)", "- return num", "-", "-", "-def num2alpha(num):", "- if num <= 26:", "- return chr(64 + num)", "- elif num % 26 == 0:", "- return num2alpha(num // 26 - 1) + chr(90)", "- else:", "- return num2alpha(num // 26) + chr(64 + num % 26)", "-", "-", "-s = num2alpha(n)", "-print((s.lower()))", "+chars = \"Xabcdefghijklmnopqrstuvwxyz\"", "+n_rem = n", "+ans = \"\"", "+while True:", "+ x = n_rem % 26", "+ if x == 0:", "+ x = 26", "+ ans += chars[x]", "+ n_rem -= x", "+ if n_rem == 0:", "+ break", "+ n_rem //= 26", "+print((ans[::-1]))" ]
false
0.03562
0.036258
0.982406
[ "s620108843", "s573018809" ]
u923662841
p03722
python
s832138076
s489273917
875
478
9,276
9,976
Accepted
Accepted
45.37
N,M = list(map(int,input().split())) ABC = [tuple(map(int,input().split())) for i in range(M)] INF = float('inf') dist = [INF] * N dist[0] = 0 for i in range(N): for a,b,c in ABC: a,b,c = a-1,b-1,-c if dist[b] > dist[a] + c: dist[b] = dist[a] + c if i==N-1 and b == N-1: print('inf') exit() print((-dist[-1]))
from collections import deque N,M = list(map(int,input().split())) ABC = [] Adake = [[] for _ in range(N)] Bdake = [[] for _ in range(N)] for i in range(M): a,b,c = list(map(int, input().split())) ABC.append((a-1,b-1,-c)) Adake[a-1].append(b-1) Bdake[b-1].append(a-1) def dfs(X,s): used = {s} search = deque([s]) while search: ss = search.pop() for sss in X[ss]: if sss in used: continue used.add(sss) search.append(sss) return used U = dfs(Adake,0) & dfs(Bdake,N-1) ABC = [(a,b,c) for (a,b,c) in ABC if a in U and b in U] INF = float('inf') dist = [INF] * N dist[0] = 0 for i in range(N): for a,b,c in ABC: if dist[b] > dist[a] + c: dist[b] = dist[a] + c if i==N-1 and b == N-1: print('inf') exit() print((-dist[-1]))
15
38
392
913
N, M = list(map(int, input().split())) ABC = [tuple(map(int, input().split())) for i in range(M)] INF = float("inf") dist = [INF] * N dist[0] = 0 for i in range(N): for a, b, c in ABC: a, b, c = a - 1, b - 1, -c if dist[b] > dist[a] + c: dist[b] = dist[a] + c if i == N - 1 and b == N - 1: print("inf") exit() print((-dist[-1]))
from collections import deque N, M = list(map(int, input().split())) ABC = [] Adake = [[] for _ in range(N)] Bdake = [[] for _ in range(N)] for i in range(M): a, b, c = list(map(int, input().split())) ABC.append((a - 1, b - 1, -c)) Adake[a - 1].append(b - 1) Bdake[b - 1].append(a - 1) def dfs(X, s): used = {s} search = deque([s]) while search: ss = search.pop() for sss in X[ss]: if sss in used: continue used.add(sss) search.append(sss) return used U = dfs(Adake, 0) & dfs(Bdake, N - 1) ABC = [(a, b, c) for (a, b, c) in ABC if a in U and b in U] INF = float("inf") dist = [INF] * N dist[0] = 0 for i in range(N): for a, b, c in ABC: if dist[b] > dist[a] + c: dist[b] = dist[a] + c if i == N - 1 and b == N - 1: print("inf") exit() print((-dist[-1]))
false
60.526316
[ "+from collections import deque", "+", "-ABC = [tuple(map(int, input().split())) for i in range(M)]", "+ABC = []", "+Adake = [[] for _ in range(N)]", "+Bdake = [[] for _ in range(N)]", "+for i in range(M):", "+ a, b, c = list(map(int, input().split()))", "+ ABC.append((a - 1, b - 1, -c))", "+ Adake[a - 1].append(b - 1)", "+ Bdake[b - 1].append(a - 1)", "+", "+", "+def dfs(X, s):", "+ used = {s}", "+ search = deque([s])", "+ while search:", "+ ss = search.pop()", "+ for sss in X[ss]:", "+ if sss in used:", "+ continue", "+ used.add(sss)", "+ search.append(sss)", "+ return used", "+", "+", "+U = dfs(Adake, 0) & dfs(Bdake, N - 1)", "+ABC = [(a, b, c) for (a, b, c) in ABC if a in U and b in U]", "- a, b, c = a - 1, b - 1, -c" ]
false
0.050858
0.040533
1.254719
[ "s832138076", "s489273917" ]
u021019433
p02837
python
s927963697
s236407742
62
56
3,188
3,064
Accepted
Accepted
9.68
from itertools import combinations n = int(eval(input())) r = list(range(n)) a = [(set(), set()) for _ in r] for i in r: for _ in range(int(eval(input()))): x, y = list(map(int, input().split())) a[i][y].add(x - 1) fail = lambda x: not all(a[i][0].isdisjoint(x) and a[i][1].issubset(x) for i in x) while all(map(fail, combinations(r, n))): n -= 1 print(n)
from itertools import combinations n = int(eval(input())) r = list(range(n)) a = [(set(), set()) for _ in r] for i in r: for _ in range(int(eval(input()))): x, y = list(map(int, input().split())) a[i][y].add(x - 1) fail = lambda x: not all(a[i][0].isdisjoint(x) and a[i][1] < x for i in x) while all(map(fail, list(map(set, combinations(r, n))))): n -= 1 print(n)
15
15
361
363
from itertools import combinations n = int(eval(input())) r = list(range(n)) a = [(set(), set()) for _ in r] for i in r: for _ in range(int(eval(input()))): x, y = list(map(int, input().split())) a[i][y].add(x - 1) fail = lambda x: not all(a[i][0].isdisjoint(x) and a[i][1].issubset(x) for i in x) while all(map(fail, combinations(r, n))): n -= 1 print(n)
from itertools import combinations n = int(eval(input())) r = list(range(n)) a = [(set(), set()) for _ in r] for i in r: for _ in range(int(eval(input()))): x, y = list(map(int, input().split())) a[i][y].add(x - 1) fail = lambda x: not all(a[i][0].isdisjoint(x) and a[i][1] < x for i in x) while all(map(fail, list(map(set, combinations(r, n))))): n -= 1 print(n)
false
0
[ "-fail = lambda x: not all(a[i][0].isdisjoint(x) and a[i][1].issubset(x) for i in x)", "-while all(map(fail, combinations(r, n))):", "+fail = lambda x: not all(a[i][0].isdisjoint(x) and a[i][1] < x for i in x)", "+while all(map(fail, list(map(set, combinations(r, n))))):" ]
false
0.036541
0.036482
1.001616
[ "s927963697", "s236407742" ]
u729133443
p03545
python
s601578071
s009342497
165
17
38,384
2,940
Accepted
Accepted
89.7
a,b,c,d=eval(input()) o='+-' for i in o: for j in o: for k in o: s=a+i+b+j+c+k+d if eval(s)==7: print((s+'=7')) exit()
a,b,c,d=eval(input()) o='+-' for i in range(8): s=a+o[i&1]+b+o[i&2>0]+c+o[i&4>0]+d if eval(s)==7:print((s+'=7'));exit()
9
5
186
117
a, b, c, d = eval(input()) o = "+-" for i in o: for j in o: for k in o: s = a + i + b + j + c + k + d if eval(s) == 7: print((s + "=7")) exit()
a, b, c, d = eval(input()) o = "+-" for i in range(8): s = a + o[i & 1] + b + o[i & 2 > 0] + c + o[i & 4 > 0] + d if eval(s) == 7: print((s + "=7")) exit()
false
44.444444
[ "-for i in o:", "- for j in o:", "- for k in o:", "- s = a + i + b + j + c + k + d", "- if eval(s) == 7:", "- print((s + \"=7\"))", "- exit()", "+for i in range(8):", "+ s = a + o[i & 1] + b + o[i & 2 > 0] + c + o[i & 4 > 0] + d", "+ if eval(s) == 7:", "+ print((s + \"=7\"))", "+ exit()" ]
false
0.085246
0.034705
2.456314
[ "s601578071", "s009342497" ]
u145035045
p03361
python
s272884099
s557513759
21
18
4,724
3,064
Accepted
Accepted
14.29
import sys sys.setrecursionlimit(100000) h,w = list(map(int,input().split())) lst = [] for i in range(h): lst.append([s for s in eval(input())]) def dfs(x,y): if lst[x][y] == '#': lst[x][y] = '.' if x + 1 <= h - 1: dfs(x + 1,y) if x - 1 >= 0: dfs(x - 1,y) if y + 1 <= w - 1: dfs(x, y + 1) if y - 1 >= 0: dfs(x,y - 1) flag = True for i in range(h): for j in range(w): if lst[i][j] == '#': if (i - 1 >= 0 and lst[i - 1][j] == "#") or (i + 1 < h and lst[i + 1][j] == "#") or (j - 1 >= 0 and lst[i][j - 1] == "#") or (j + 1 < w and lst[i][j + 1] == "#"): dfs(i,j) else: flag = False break if flag: print("Yes") else: print("No")
h,w = list(map(int,input().split())) lst = ["." * (w + 2)] for _ in range(h): s = eval(input()) s = "." + s + "." lst.append(s) lst.append("." * (w + 2)) flag = True for x in range(1,h + 1): for y in range(1,w + 1): if lst[x][y] == "#": if lst[x - 1][y] == "." and lst[x + 1][y] == "." and lst[x][y + 1] == "." and lst[x][y - 1] == ".": flag = False break if flag: print("Yes") else: print("No")
30
22
736
447
import sys sys.setrecursionlimit(100000) h, w = list(map(int, input().split())) lst = [] for i in range(h): lst.append([s for s in eval(input())]) def dfs(x, y): if lst[x][y] == "#": lst[x][y] = "." if x + 1 <= h - 1: dfs(x + 1, y) if x - 1 >= 0: dfs(x - 1, y) if y + 1 <= w - 1: dfs(x, y + 1) if y - 1 >= 0: dfs(x, y - 1) flag = True for i in range(h): for j in range(w): if lst[i][j] == "#": if ( (i - 1 >= 0 and lst[i - 1][j] == "#") or (i + 1 < h and lst[i + 1][j] == "#") or (j - 1 >= 0 and lst[i][j - 1] == "#") or (j + 1 < w and lst[i][j + 1] == "#") ): dfs(i, j) else: flag = False break if flag: print("Yes") else: print("No")
h, w = list(map(int, input().split())) lst = ["." * (w + 2)] for _ in range(h): s = eval(input()) s = "." + s + "." lst.append(s) lst.append("." * (w + 2)) flag = True for x in range(1, h + 1): for y in range(1, w + 1): if lst[x][y] == "#": if ( lst[x - 1][y] == "." and lst[x + 1][y] == "." and lst[x][y + 1] == "." and lst[x][y - 1] == "." ): flag = False break if flag: print("Yes") else: print("No")
false
26.666667
[ "-import sys", "-", "-sys.setrecursionlimit(100000)", "-lst = []", "-for i in range(h):", "- lst.append([s for s in eval(input())])", "-", "-", "-def dfs(x, y):", "- if lst[x][y] == \"#\":", "- lst[x][y] = \".\"", "- if x + 1 <= h - 1:", "- dfs(x + 1, y)", "- if x - 1 >= 0:", "- dfs(x - 1, y)", "- if y + 1 <= w - 1:", "- dfs(x, y + 1)", "- if y - 1 >= 0:", "- dfs(x, y - 1)", "-", "-", "+lst = [\".\" * (w + 2)]", "+for _ in range(h):", "+ s = eval(input())", "+ s = \".\" + s + \".\"", "+ lst.append(s)", "+lst.append(\".\" * (w + 2))", "-for i in range(h):", "- for j in range(w):", "- if lst[i][j] == \"#\":", "+for x in range(1, h + 1):", "+ for y in range(1, w + 1):", "+ if lst[x][y] == \"#\":", "- (i - 1 >= 0 and lst[i - 1][j] == \"#\")", "- or (i + 1 < h and lst[i + 1][j] == \"#\")", "- or (j - 1 >= 0 and lst[i][j - 1] == \"#\")", "- or (j + 1 < w and lst[i][j + 1] == \"#\")", "+ lst[x - 1][y] == \".\"", "+ and lst[x + 1][y] == \".\"", "+ and lst[x][y + 1] == \".\"", "+ and lst[x][y - 1] == \".\"", "- dfs(i, j)", "- else:" ]
false
0.103075
0.100624
1.024363
[ "s272884099", "s557513759" ]
u814166125
p03610
python
s113914966
s570886879
38
17
3,956
3,188
Accepted
Accepted
55.26
# -*- coding: utf-8 -*- s = eval(input()) sList = list(s) output = "" for i in range(len(sList)): if i%2 == 0: output += sList[i] print(output)
s = eval(input()) print((s[::2]))
14
3
184
29
# -*- coding: utf-8 -*- s = eval(input()) sList = list(s) output = "" for i in range(len(sList)): if i % 2 == 0: output += sList[i] print(output)
s = eval(input()) print((s[::2]))
false
78.571429
[ "-# -*- coding: utf-8 -*-", "-sList = list(s)", "-output = \"\"", "-for i in range(len(sList)):", "- if i % 2 == 0:", "- output += sList[i]", "-print(output)", "+print((s[::2]))" ]
false
0.0466
0.117277
0.397355
[ "s113914966", "s570886879" ]
u054514819
p02708
python
s275080834
s951732731
157
71
9,200
83,176
Accepted
Accepted
54.78
N, K = list(map(int, input().split())) N += 1 mod = 10**9+7 ans = 0 for i in range(N+1-K): nowk = K+i min_k = nowk*(nowk-1)//2 max_k = (2*N-nowk-1)*nowk//2 ans += (max_k-min_k+1)%mod ans %= mod print(ans)
import sys def input(): return sys.stdin.readline().strip() def mapint(): return list(map(int, input().split())) sys.setrecursionlimit(10**9) N, K = mapint() mod = 10**9+7 from itertools import accumulate lis = list(accumulate([0]+[i for i in range(N+1)])) ans = 0 for k in range(K, N+2): MIN = lis[k] MAX = lis[-1]-lis[-1-k] ans += (MAX-MIN+1) ans %= mod print(ans)
12
16
230
392
N, K = list(map(int, input().split())) N += 1 mod = 10**9 + 7 ans = 0 for i in range(N + 1 - K): nowk = K + i min_k = nowk * (nowk - 1) // 2 max_k = (2 * N - nowk - 1) * nowk // 2 ans += (max_k - min_k + 1) % mod ans %= mod print(ans)
import sys def input(): return sys.stdin.readline().strip() def mapint(): return list(map(int, input().split())) sys.setrecursionlimit(10**9) N, K = mapint() mod = 10**9 + 7 from itertools import accumulate lis = list(accumulate([0] + [i for i in range(N + 1)])) ans = 0 for k in range(K, N + 2): MIN = lis[k] MAX = lis[-1] - lis[-1 - k] ans += MAX - MIN + 1 ans %= mod print(ans)
false
25
[ "-N, K = list(map(int, input().split()))", "-N += 1", "+import sys", "+", "+", "+def input():", "+ return sys.stdin.readline().strip()", "+", "+", "+def mapint():", "+ return list(map(int, input().split()))", "+", "+", "+sys.setrecursionlimit(10**9)", "+N, K = mapint()", "+from itertools import accumulate", "+", "+lis = list(accumulate([0] + [i for i in range(N + 1)]))", "-for i in range(N + 1 - K):", "- nowk = K + i", "- min_k = nowk * (nowk - 1) // 2", "- max_k = (2 * N - nowk - 1) * nowk // 2", "- ans += (max_k - min_k + 1) % mod", "+for k in range(K, N + 2):", "+ MIN = lis[k]", "+ MAX = lis[-1] - lis[-1 - k]", "+ ans += MAX - MIN + 1" ]
false
0.082644
0.085272
0.969184
[ "s275080834", "s951732731" ]
u561231954
p03014
python
s496234402
s317588053
1,893
935
306,952
251,044
Accepted
Accepted
50.61
h,w=list(map(int,input().split())) grid=[list(eval(input())) for i in range(h)] left=[[0]*w for _ in range(h)] for i in range(h): cnt=0 for j in range(w): if grid[i][j]=='.': cnt+=1 left[i][j]=cnt else: cnt=0 left[i][j]=cnt right=[[0]*w for _ in range(h)] for i in range(h): cnt=0 for j in range(w): if grid[i][w-j-1]=='.': cnt+=1 right[i][j]=cnt else: cnt=0 right[i][j]=cnt up=[[0]*w for i in range(h)] for i in range(w): cnt=0 for j in range(h): if grid[j][i]=='.': cnt+=1 up[j][i]=cnt else: cnt=0 up[j][i]=cnt down=[[0]*w for i in range(h)] for i in range(w): cnt=0 for j in range(h): if grid[h-j-1][i]=='.': cnt+=1 down[j][i]=cnt else: cnt=0 down[j][i]=cnt ans=0 for i in range(h): for j in range(w): if grid[i][j]=='.': tmp=left[i][j]+right[i][w-j-1]+up[i][j]+down[h-i-1][j]-3 if tmp>ans: ans=tmp else: continue print(ans)
def main(): import numpy as np h,w=list(map(int,input().split())) grid=np.array([list(eval(input())) for i in range(h)]) grid=np.where(grid=='.',1,0) left=np.zeros((h,w),dtype=np.int64) right=np.zeros((h,w),dtype=np.int64) up=np.zeros((h,w),dtype=np.int64) down=np.zeros((h,w),dtype=np.int64) for i in range(w): left[:,i]=(left[:,i-1]+1)*grid[:,i] right[:,-i-1]=(right[:,-i]+1)*grid[:,-i-1] for i in range(h): up[i]=(up[i-1]+1)*grid[i] down[-i-1]=(down[-i]+1)*grid[-i-1] print((np.max(left+right+up+down)-3)) if __name__=='__main__': main()
58
22
1,084
603
h, w = list(map(int, input().split())) grid = [list(eval(input())) for i in range(h)] left = [[0] * w for _ in range(h)] for i in range(h): cnt = 0 for j in range(w): if grid[i][j] == ".": cnt += 1 left[i][j] = cnt else: cnt = 0 left[i][j] = cnt right = [[0] * w for _ in range(h)] for i in range(h): cnt = 0 for j in range(w): if grid[i][w - j - 1] == ".": cnt += 1 right[i][j] = cnt else: cnt = 0 right[i][j] = cnt up = [[0] * w for i in range(h)] for i in range(w): cnt = 0 for j in range(h): if grid[j][i] == ".": cnt += 1 up[j][i] = cnt else: cnt = 0 up[j][i] = cnt down = [[0] * w for i in range(h)] for i in range(w): cnt = 0 for j in range(h): if grid[h - j - 1][i] == ".": cnt += 1 down[j][i] = cnt else: cnt = 0 down[j][i] = cnt ans = 0 for i in range(h): for j in range(w): if grid[i][j] == ".": tmp = left[i][j] + right[i][w - j - 1] + up[i][j] + down[h - i - 1][j] - 3 if tmp > ans: ans = tmp else: continue print(ans)
def main(): import numpy as np h, w = list(map(int, input().split())) grid = np.array([list(eval(input())) for i in range(h)]) grid = np.where(grid == ".", 1, 0) left = np.zeros((h, w), dtype=np.int64) right = np.zeros((h, w), dtype=np.int64) up = np.zeros((h, w), dtype=np.int64) down = np.zeros((h, w), dtype=np.int64) for i in range(w): left[:, i] = (left[:, i - 1] + 1) * grid[:, i] right[:, -i - 1] = (right[:, -i] + 1) * grid[:, -i - 1] for i in range(h): up[i] = (up[i - 1] + 1) * grid[i] down[-i - 1] = (down[-i] + 1) * grid[-i - 1] print((np.max(left + right + up + down) - 3)) if __name__ == "__main__": main()
false
62.068966
[ "-h, w = list(map(int, input().split()))", "-grid = [list(eval(input())) for i in range(h)]", "-left = [[0] * w for _ in range(h)]", "-for i in range(h):", "- cnt = 0", "- for j in range(w):", "- if grid[i][j] == \".\":", "- cnt += 1", "- left[i][j] = cnt", "- else:", "- cnt = 0", "- left[i][j] = cnt", "-right = [[0] * w for _ in range(h)]", "-for i in range(h):", "- cnt = 0", "- for j in range(w):", "- if grid[i][w - j - 1] == \".\":", "- cnt += 1", "- right[i][j] = cnt", "- else:", "- cnt = 0", "- right[i][j] = cnt", "-up = [[0] * w for i in range(h)]", "-for i in range(w):", "- cnt = 0", "- for j in range(h):", "- if grid[j][i] == \".\":", "- cnt += 1", "- up[j][i] = cnt", "- else:", "- cnt = 0", "- up[j][i] = cnt", "-down = [[0] * w for i in range(h)]", "-for i in range(w):", "- cnt = 0", "- for j in range(h):", "- if grid[h - j - 1][i] == \".\":", "- cnt += 1", "- down[j][i] = cnt", "- else:", "- cnt = 0", "- down[j][i] = cnt", "-ans = 0", "-for i in range(h):", "- for j in range(w):", "- if grid[i][j] == \".\":", "- tmp = left[i][j] + right[i][w - j - 1] + up[i][j] + down[h - i - 1][j] - 3", "- if tmp > ans:", "- ans = tmp", "- else:", "- continue", "-print(ans)", "+def main():", "+ import numpy as np", "+", "+ h, w = list(map(int, input().split()))", "+ grid = np.array([list(eval(input())) for i in range(h)])", "+ grid = np.where(grid == \".\", 1, 0)", "+ left = np.zeros((h, w), dtype=np.int64)", "+ right = np.zeros((h, w), dtype=np.int64)", "+ up = np.zeros((h, w), dtype=np.int64)", "+ down = np.zeros((h, w), dtype=np.int64)", "+ for i in range(w):", "+ left[:, i] = (left[:, i - 1] + 1) * grid[:, i]", "+ right[:, -i - 1] = (right[:, -i] + 1) * grid[:, -i - 1]", "+ for i in range(h):", "+ up[i] = (up[i - 1] + 1) * grid[i]", "+ down[-i - 1] = (down[-i] + 1) * grid[-i - 1]", "+ print((np.max(left + right + up + down) - 3))", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.04263
0.259317
0.164392
[ "s496234402", "s317588053" ]
u905203728
p03476
python
s643859784
s016946456
1,975
813
4,576
72,920
Accepted
Accepted
58.84
def prime(n): is_prime=[True]*(n+1) is_prime[0],is_prime[1]=False,False for i in range(2,int(n**0.5)+1): if not is_prime[i]:continue for j in range(i*2,n+1,i): is_prime[j]=False return [i for i in range(n+1) if is_prime[i]] prime_number=prime(10**5) number=[i for i in prime_number if (i+1)//2 in prime_number]+[0] ans=[0]*(10**5+1) count=0 for i in range(1,10**5): ans[i]=ans[i-1] if i==number[count]: ans[i] +=1 count +=1 for i in range(int(eval(input()))): a,b=list(map(int,input().split())) print((ans[b]-ans[a-1]))
def prime(n): is_prime=[True]*(n+1) is_prime[0],is_prime[1]=False,False for i in range(2,int(n**0.5)+1): if not is_prime[i]:continue for j in range(i*2,n+1,i): is_prime[j]=False return [i for i in range(n+1) if is_prime[i]] q=int(eval(input())) LR=[list(map(int,input().split())) for _ in range(q)] prime=prime(10**5) DP=[0]*(10**5+1) for i in prime: if i*2-1 in prime: DP[i*2-1]=1 for i in range(1,10**5+1): DP[i]=DP[i-1]+DP[i] for l,r in LR: print((DP[r]-DP[l-1]))
23
24
606
550
def prime(n): is_prime = [True] * (n + 1) is_prime[0], is_prime[1] = False, False for i in range(2, int(n**0.5) + 1): if not is_prime[i]: continue for j in range(i * 2, n + 1, i): is_prime[j] = False return [i for i in range(n + 1) if is_prime[i]] prime_number = prime(10**5) number = [i for i in prime_number if (i + 1) // 2 in prime_number] + [0] ans = [0] * (10**5 + 1) count = 0 for i in range(1, 10**5): ans[i] = ans[i - 1] if i == number[count]: ans[i] += 1 count += 1 for i in range(int(eval(input()))): a, b = list(map(int, input().split())) print((ans[b] - ans[a - 1]))
def prime(n): is_prime = [True] * (n + 1) is_prime[0], is_prime[1] = False, False for i in range(2, int(n**0.5) + 1): if not is_prime[i]: continue for j in range(i * 2, n + 1, i): is_prime[j] = False return [i for i in range(n + 1) if is_prime[i]] q = int(eval(input())) LR = [list(map(int, input().split())) for _ in range(q)] prime = prime(10**5) DP = [0] * (10**5 + 1) for i in prime: if i * 2 - 1 in prime: DP[i * 2 - 1] = 1 for i in range(1, 10**5 + 1): DP[i] = DP[i - 1] + DP[i] for l, r in LR: print((DP[r] - DP[l - 1]))
false
4.166667
[ "-prime_number = prime(10**5)", "-number = [i for i in prime_number if (i + 1) // 2 in prime_number] + [0]", "-ans = [0] * (10**5 + 1)", "-count = 0", "-for i in range(1, 10**5):", "- ans[i] = ans[i - 1]", "- if i == number[count]:", "- ans[i] += 1", "- count += 1", "-for i in range(int(eval(input()))):", "- a, b = list(map(int, input().split()))", "- print((ans[b] - ans[a - 1]))", "+q = int(eval(input()))", "+LR = [list(map(int, input().split())) for _ in range(q)]", "+prime = prime(10**5)", "+DP = [0] * (10**5 + 1)", "+for i in prime:", "+ if i * 2 - 1 in prime:", "+ DP[i * 2 - 1] = 1", "+for i in range(1, 10**5 + 1):", "+ DP[i] = DP[i - 1] + DP[i]", "+for l, r in LR:", "+ print((DP[r] - DP[l - 1]))" ]
false
1.121572
1.104046
1.015875
[ "s643859784", "s016946456" ]
u600195339
p02888
python
s140331051
s035365700
1,894
1,723
51,676
51,676
Accepted
Accepted
9.03
import bisect n = int(eval(input())) l = list(map(int, input().split())) l.sort() ans = 0 for i in range(n): for j in range(i+1, n): length = l[i] + l[j] index = bisect.bisect_left(l[j+1:], length) ans += index print(ans)
import bisect n = int(eval(input())) l = sorted(list(map(int, input().split()))) ans = 0 for i in range(n): for j in range(i+1, n): ans += bisect.bisect_left(l[j+1:], l[i] + l[j]) print(ans)
14
10
259
207
import bisect n = int(eval(input())) l = list(map(int, input().split())) l.sort() ans = 0 for i in range(n): for j in range(i + 1, n): length = l[i] + l[j] index = bisect.bisect_left(l[j + 1 :], length) ans += index print(ans)
import bisect n = int(eval(input())) l = sorted(list(map(int, input().split()))) ans = 0 for i in range(n): for j in range(i + 1, n): ans += bisect.bisect_left(l[j + 1 :], l[i] + l[j]) print(ans)
false
28.571429
[ "-l = list(map(int, input().split()))", "-l.sort()", "+l = sorted(list(map(int, input().split())))", "- length = l[i] + l[j]", "- index = bisect.bisect_left(l[j + 1 :], length)", "- ans += index", "+ ans += bisect.bisect_left(l[j + 1 :], l[i] + l[j])" ]
false
0.047157
0.046819
1.007222
[ "s140331051", "s035365700" ]
u970197315
p03311
python
s621941116
s712442324
261
207
26,180
30,828
Accepted
Accepted
20.69
n=int(eval(input())) b=[int(a-(i+1)) for i,a in enumerate(list(map(int,input().split())))] if n==1: print((0)) exit(0) bm=b[:] bm.sort() mid_1=bm[n//2] mid_2=bm[(n//2)+1] ans_1,ans_2=0,0 if n%2==1: for bb in b: ans_1+=abs(bb-mid_1) print(ans_1) else: for bb in b: ans_1+=abs(bb-mid_1) ans_2+=abs(bb-mid_2) print((min(ans_1,ans_2)))
n=int(eval(input())) a=list(map(int,input().split())) for i in range(n): a[i]-=i+1 b=a[:] b.sort() mid1=0 mid2=0 if n%2==1: ans=0 mid1=b[n//2] for bb in b: ans+=abs(bb-mid1) print(ans) else: mid1=b[n//2] mid2=b[n//2-1] ans1,ans2=0,0 for bb in b: ans1+=abs(bb-mid1) ans2+=abs(bb-mid2) print((min(ans1,ans2)))
20
22
367
353
n = int(eval(input())) b = [int(a - (i + 1)) for i, a in enumerate(list(map(int, input().split())))] if n == 1: print((0)) exit(0) bm = b[:] bm.sort() mid_1 = bm[n // 2] mid_2 = bm[(n // 2) + 1] ans_1, ans_2 = 0, 0 if n % 2 == 1: for bb in b: ans_1 += abs(bb - mid_1) print(ans_1) else: for bb in b: ans_1 += abs(bb - mid_1) ans_2 += abs(bb - mid_2) print((min(ans_1, ans_2)))
n = int(eval(input())) a = list(map(int, input().split())) for i in range(n): a[i] -= i + 1 b = a[:] b.sort() mid1 = 0 mid2 = 0 if n % 2 == 1: ans = 0 mid1 = b[n // 2] for bb in b: ans += abs(bb - mid1) print(ans) else: mid1 = b[n // 2] mid2 = b[n // 2 - 1] ans1, ans2 = 0, 0 for bb in b: ans1 += abs(bb - mid1) ans2 += abs(bb - mid2) print((min(ans1, ans2)))
false
9.090909
[ "-b = [int(a - (i + 1)) for i, a in enumerate(list(map(int, input().split())))]", "-if n == 1:", "- print((0))", "- exit(0)", "-bm = b[:]", "-bm.sort()", "-mid_1 = bm[n // 2]", "-mid_2 = bm[(n // 2) + 1]", "-ans_1, ans_2 = 0, 0", "+a = list(map(int, input().split()))", "+for i in range(n):", "+ a[i] -= i + 1", "+b = a[:]", "+b.sort()", "+mid1 = 0", "+mid2 = 0", "+ ans = 0", "+ mid1 = b[n // 2]", "- ans_1 += abs(bb - mid_1)", "- print(ans_1)", "+ ans += abs(bb - mid1)", "+ print(ans)", "+ mid1 = b[n // 2]", "+ mid2 = b[n // 2 - 1]", "+ ans1, ans2 = 0, 0", "- ans_1 += abs(bb - mid_1)", "- ans_2 += abs(bb - mid_2)", "- print((min(ans_1, ans_2)))", "+ ans1 += abs(bb - mid1)", "+ ans2 += abs(bb - mid2)", "+ print((min(ans1, ans2)))" ]
false
0.046852
0.112866
0.415109
[ "s621941116", "s712442324" ]
u222668979
p03959
python
s739083231
s381958169
157
112
97,744
97,460
Accepted
Accepted
28.66
n = int(eval(input())) t = list(map(int, input().split())) a = list(map(int, input().split())) mod = 10 ** 9 + 7 ans, l, r = 1, 0, n - 1 for i in range(1, n): if t[i] == t[i - 1]: ans = ans * t[i] % mod if t[i] == a[i]: l = i break for i in range(n - 1)[::-1]: if a[i] == a[i + 1]: ans = ans * a[i] % mod if t[i] == a[i]: r = i break if t[l] != max(t) or a[r] != max(a) or max(t) != max(a): print((0)) else: print((ans * pow(t[l], max(r - l - 1, 0), mod) % mod))
n = int(eval(input())) t = list(map(int, input().split())) a = list(map(int, input().split())) mod = 10 ** 9 + 7 ans = 1 if n == 1: print((int(t == a))) exit() for i in range(1, n - 1): ht, ha = 0, 0 if t[i - 1] < t[i] and a[i] > a[i + 1]: if t[i] != a[i]: print((0)) break elif t[i - 1] < t[i]: if t[i] > a[i]: print((0)) break elif a[i] > a[i + 1]: if t[i] < a[i]: print((0)) break else: ans = ans * min(t[i], a[i]) % mod else: print(ans)
23
27
549
590
n = int(eval(input())) t = list(map(int, input().split())) a = list(map(int, input().split())) mod = 10**9 + 7 ans, l, r = 1, 0, n - 1 for i in range(1, n): if t[i] == t[i - 1]: ans = ans * t[i] % mod if t[i] == a[i]: l = i break for i in range(n - 1)[::-1]: if a[i] == a[i + 1]: ans = ans * a[i] % mod if t[i] == a[i]: r = i break if t[l] != max(t) or a[r] != max(a) or max(t) != max(a): print((0)) else: print((ans * pow(t[l], max(r - l - 1, 0), mod) % mod))
n = int(eval(input())) t = list(map(int, input().split())) a = list(map(int, input().split())) mod = 10**9 + 7 ans = 1 if n == 1: print((int(t == a))) exit() for i in range(1, n - 1): ht, ha = 0, 0 if t[i - 1] < t[i] and a[i] > a[i + 1]: if t[i] != a[i]: print((0)) break elif t[i - 1] < t[i]: if t[i] > a[i]: print((0)) break elif a[i] > a[i + 1]: if t[i] < a[i]: print((0)) break else: ans = ans * min(t[i], a[i]) % mod else: print(ans)
false
14.814815
[ "-ans, l, r = 1, 0, n - 1", "-for i in range(1, n):", "- if t[i] == t[i - 1]:", "- ans = ans * t[i] % mod", "- if t[i] == a[i]:", "- l = i", "- break", "-for i in range(n - 1)[::-1]:", "- if a[i] == a[i + 1]:", "- ans = ans * a[i] % mod", "- if t[i] == a[i]:", "- r = i", "- break", "-if t[l] != max(t) or a[r] != max(a) or max(t) != max(a):", "- print((0))", "+ans = 1", "+if n == 1:", "+ print((int(t == a)))", "+ exit()", "+for i in range(1, n - 1):", "+ ht, ha = 0, 0", "+ if t[i - 1] < t[i] and a[i] > a[i + 1]:", "+ if t[i] != a[i]:", "+ print((0))", "+ break", "+ elif t[i - 1] < t[i]:", "+ if t[i] > a[i]:", "+ print((0))", "+ break", "+ elif a[i] > a[i + 1]:", "+ if t[i] < a[i]:", "+ print((0))", "+ break", "+ else:", "+ ans = ans * min(t[i], a[i]) % mod", "- print((ans * pow(t[l], max(r - l - 1, 0), mod) % mod))", "+ print(ans)" ]
false
0.088333
0.10819
0.816462
[ "s739083231", "s381958169" ]
u493520238
p03032
python
s078484134
s157324541
962
84
23,924
74,108
Accepted
Accepted
91.27
import bisect abcd = [] n, k = list(map(int, input().split())) v_list = list(map(int, input().split())) for a in range(0, k+1): for b in range(0, k+1-a): for c in range(0, k+1-a-b): d = k-a-b-c abcd.append([a,b,c,d]) ans = 0 for curr_abcd in abcd: a,b,c,d = curr_abcd cd = c+d if a + b >= n: have = sorted(v_list) else: have = sorted(v_list[0:a] + v_list[n-b:n]) minus_cnt = bisect.bisect_right(have,0) have = have[ min(minus_cnt, cd) : ] curr_sum = sum(have) ans = max(ans, curr_sum) print(ans)
from bisect import bisect_left, bisect_right n,k = list(map(int, input().split())) vl = list(map(int, input().split())) ans = 0 for get_num in range(0,k+1): rem = k-get_num for l in range(0,get_num+1): r = get_num-l if l+r > n: continue ls = vl[:l] rs = vl[n-r:] curr_l = ls + rs curr_l.sort() minus_cnt = bisect_left(curr_l, 0) if minus_cnt <= rem: curr_ans = sum(curr_l[minus_cnt:]) ans = max(curr_ans,ans) else: curr_ans = sum(curr_l[rem:]) ans = max(curr_ans,ans) print(ans)
28
24
610
626
import bisect abcd = [] n, k = list(map(int, input().split())) v_list = list(map(int, input().split())) for a in range(0, k + 1): for b in range(0, k + 1 - a): for c in range(0, k + 1 - a - b): d = k - a - b - c abcd.append([a, b, c, d]) ans = 0 for curr_abcd in abcd: a, b, c, d = curr_abcd cd = c + d if a + b >= n: have = sorted(v_list) else: have = sorted(v_list[0:a] + v_list[n - b : n]) minus_cnt = bisect.bisect_right(have, 0) have = have[min(minus_cnt, cd) :] curr_sum = sum(have) ans = max(ans, curr_sum) print(ans)
from bisect import bisect_left, bisect_right n, k = list(map(int, input().split())) vl = list(map(int, input().split())) ans = 0 for get_num in range(0, k + 1): rem = k - get_num for l in range(0, get_num + 1): r = get_num - l if l + r > n: continue ls = vl[:l] rs = vl[n - r :] curr_l = ls + rs curr_l.sort() minus_cnt = bisect_left(curr_l, 0) if minus_cnt <= rem: curr_ans = sum(curr_l[minus_cnt:]) ans = max(curr_ans, ans) else: curr_ans = sum(curr_l[rem:]) ans = max(curr_ans, ans) print(ans)
false
14.285714
[ "-import bisect", "+from bisect import bisect_left, bisect_right", "-abcd = []", "-v_list = list(map(int, input().split()))", "-for a in range(0, k + 1):", "- for b in range(0, k + 1 - a):", "- for c in range(0, k + 1 - a - b):", "- d = k - a - b - c", "- abcd.append([a, b, c, d])", "+vl = list(map(int, input().split()))", "-for curr_abcd in abcd:", "- a, b, c, d = curr_abcd", "- cd = c + d", "- if a + b >= n:", "- have = sorted(v_list)", "- else:", "- have = sorted(v_list[0:a] + v_list[n - b : n])", "- minus_cnt = bisect.bisect_right(have, 0)", "- have = have[min(minus_cnt, cd) :]", "- curr_sum = sum(have)", "- ans = max(ans, curr_sum)", "+for get_num in range(0, k + 1):", "+ rem = k - get_num", "+ for l in range(0, get_num + 1):", "+ r = get_num - l", "+ if l + r > n:", "+ continue", "+ ls = vl[:l]", "+ rs = vl[n - r :]", "+ curr_l = ls + rs", "+ curr_l.sort()", "+ minus_cnt = bisect_left(curr_l, 0)", "+ if minus_cnt <= rem:", "+ curr_ans = sum(curr_l[minus_cnt:])", "+ ans = max(curr_ans, ans)", "+ else:", "+ curr_ans = sum(curr_l[rem:])", "+ ans = max(curr_ans, ans)" ]
false
0.043231
0.036218
1.193617
[ "s078484134", "s157324541" ]
u096736378
p03354
python
s009353858
s056891402
618
566
14,008
13,812
Accepted
Accepted
8.41
n,m = list(map(int, input().split())) p = list(map(int, input().split())) par = [i for i in range(n)] rank = [0 for x in range(n)] def root(x): tmp = par[x] if tmp == x: return x else: a = root(tmp) par[x] = a return a def merge(x, y): x = root(x) y = root(y) if x == y: return else: if rank[x] > rank[y]: par[y] = x rank[y] += rank[x] else: par[x] = y rank[x] += rank[y] return for i in range(m): x, y = list(map(int, input().split())) merge(x-1, y-1) ans = 0 for i in range(n): if p[i]-1 == i: ans += 1 elif root(p[i]-1) == root(i): ans += 1 print(ans)
n,m = list(map(int, input().split())) p = list(map(int, input().split())) par = [i for i in range(n)] def root(x): tmp = par[x] if tmp == x: return x else: a = root(tmp) par[x] = a return a def merge(x, y): x = root(x) y = root(y) if x != y: par[x] = y return for i in range(m): x, y = list(map(int, input().split())) merge(x-1, y-1) ans = 0 for i in range(n): if p[i]-1 == i: ans += 1 elif root(p[i]-1) == root(i): ans += 1 print(ans)
41
33
631
487
n, m = list(map(int, input().split())) p = list(map(int, input().split())) par = [i for i in range(n)] rank = [0 for x in range(n)] def root(x): tmp = par[x] if tmp == x: return x else: a = root(tmp) par[x] = a return a def merge(x, y): x = root(x) y = root(y) if x == y: return else: if rank[x] > rank[y]: par[y] = x rank[y] += rank[x] else: par[x] = y rank[x] += rank[y] return for i in range(m): x, y = list(map(int, input().split())) merge(x - 1, y - 1) ans = 0 for i in range(n): if p[i] - 1 == i: ans += 1 elif root(p[i] - 1) == root(i): ans += 1 print(ans)
n, m = list(map(int, input().split())) p = list(map(int, input().split())) par = [i for i in range(n)] def root(x): tmp = par[x] if tmp == x: return x else: a = root(tmp) par[x] = a return a def merge(x, y): x = root(x) y = root(y) if x != y: par[x] = y return for i in range(m): x, y = list(map(int, input().split())) merge(x - 1, y - 1) ans = 0 for i in range(n): if p[i] - 1 == i: ans += 1 elif root(p[i] - 1) == root(i): ans += 1 print(ans)
false
19.512195
[ "-rank = [0 for x in range(n)]", "- if x == y:", "- return", "- else:", "- if rank[x] > rank[y]:", "- par[y] = x", "- rank[y] += rank[x]", "- else:", "- par[x] = y", "- rank[x] += rank[y]", "+ if x != y:", "+ par[x] = y" ]
false
0.035603
0.035325
1.00789
[ "s009353858", "s056891402" ]
u891635666
p03054
python
s509393763
s699389867
551
159
4,036
3,768
Accepted
Accepted
71.14
import collections h, w, n = list(map(int, input().split())) y, x = list(map(int, input().split())) s = input().rstrip() t = input().rstrip() counter = collections.Counter() for c in s: counter[c] += 1 def check(counts, direction, opposite_direction, pos, target): for i in range(n): counts[direction] -= 1 if s[i] == direction: pos += 1 if pos == target: return False if t[i] == opposite_direction and pos > 1 and counts[ opposite_direction] < pos: pos -= 1 return True for d, od, pos, target in [ ('R', 'L', x, w + 1), ('L', 'R', w + 1 - x, w + 1), ('D', 'U', y, h + 1), ('U', 'D', h + 1 - y, h + 1), ]: ok = check(collections.Counter(list(counter.items())), d, od, pos, target) if not ok: print('NO') break else: print('YES')
h, w, n = list(map(int, input().split())) y, x = list(map(int, input().split())) s = input().rstrip() t = input().rstrip() def check(direction, opposite_direction, pos, target): for i in range(n): if s[i] == direction: pos += 1 if pos == target: return False if t[i] == opposite_direction and pos > 1: pos -= 1 return True for d, od, pos, target in [ ('R', 'L', x, w + 1), ('L', 'R', w + 1 - x, w + 1), ('D', 'U', y, h + 1), ('U', 'D', h + 1 - y, h + 1), ]: ok = check(d, od, pos, target) if not ok: print('NO') break else: print('YES')
37
29
892
668
import collections h, w, n = list(map(int, input().split())) y, x = list(map(int, input().split())) s = input().rstrip() t = input().rstrip() counter = collections.Counter() for c in s: counter[c] += 1 def check(counts, direction, opposite_direction, pos, target): for i in range(n): counts[direction] -= 1 if s[i] == direction: pos += 1 if pos == target: return False if t[i] == opposite_direction and pos > 1 and counts[opposite_direction] < pos: pos -= 1 return True for d, od, pos, target in [ ("R", "L", x, w + 1), ("L", "R", w + 1 - x, w + 1), ("D", "U", y, h + 1), ("U", "D", h + 1 - y, h + 1), ]: ok = check(collections.Counter(list(counter.items())), d, od, pos, target) if not ok: print("NO") break else: print("YES")
h, w, n = list(map(int, input().split())) y, x = list(map(int, input().split())) s = input().rstrip() t = input().rstrip() def check(direction, opposite_direction, pos, target): for i in range(n): if s[i] == direction: pos += 1 if pos == target: return False if t[i] == opposite_direction and pos > 1: pos -= 1 return True for d, od, pos, target in [ ("R", "L", x, w + 1), ("L", "R", w + 1 - x, w + 1), ("D", "U", y, h + 1), ("U", "D", h + 1 - y, h + 1), ]: ok = check(d, od, pos, target) if not ok: print("NO") break else: print("YES")
false
21.621622
[ "-import collections", "-", "-counter = collections.Counter()", "-for c in s:", "- counter[c] += 1", "-def check(counts, direction, opposite_direction, pos, target):", "+def check(direction, opposite_direction, pos, target):", "- counts[direction] -= 1", "- if t[i] == opposite_direction and pos > 1 and counts[opposite_direction] < pos:", "+ if t[i] == opposite_direction and pos > 1:", "- ok = check(collections.Counter(list(counter.items())), d, od, pos, target)", "+ ok = check(d, od, pos, target)" ]
false
0.036327
0.037344
0.97277
[ "s509393763", "s699389867" ]
u378299699
p03207
python
s843393692
s629466574
19
17
2,940
2,940
Accepted
Accepted
10.53
n = int(eval(input())) nums =[] for i in range(n): nums.append(int(eval(input()))) m = max(nums) nums.remove(m) print((int(sum(nums) + (m / 2))))
N = int(eval(input())) nums = [] for i in range(N): nums.append(int(eval(input()))) m = max(nums) nums.remove(m) print((int(sum(nums) + (m / 2))))
8
7
144
143
n = int(eval(input())) nums = [] for i in range(n): nums.append(int(eval(input()))) m = max(nums) nums.remove(m) print((int(sum(nums) + (m / 2))))
N = int(eval(input())) nums = [] for i in range(N): nums.append(int(eval(input()))) m = max(nums) nums.remove(m) print((int(sum(nums) + (m / 2))))
false
12.5
[ "-n = int(eval(input()))", "+N = int(eval(input()))", "-for i in range(n):", "+for i in range(N):" ]
false
0.063582
0.048085
1.322273
[ "s843393692", "s629466574" ]
u017415492
p02756
python
s226911356
s301226248
788
454
42,372
35,864
Accepted
Accepted
42.39
s=eval(input()) q=int(eval(input())) que=[] count=0 left=[] right=[] for i in range(q): qu=list(map(str,input().split())) if qu[0]=="1": count+=1 que.append(qu) han=0 for i in range(q): if que[i][0]=="1": han+=1 else: if que[i][1]=="1": if (count-han)%2==0: left.append(que[i][2]) else: right.append(que[i][2]) elif que[i][1]=="2": if (count-han)%2==0: right.append(que[i][2]) else: left.append(que[i][2]) ls="".join(left[::-1]) rs="".join(right) if count%2==0: print((ls+s+rs)) else: print((ls+s[::-1]+rs))
s=eval(input()) q=int(eval(input())) que=[list(map(str,input().split())) for i in range(q)] count=0 for i in que: if i[0]=="1": count+=1 ans=[[],[]] ak=count for i in que: if i[0]=="1": count-=1 else: if i[1]=="1": ans[count%2].append(i[2]) else: ans[(count+1)%2].append(i[2]) if ak%2==0: print(("".join(reversed(ans[0]))+s+"".join(ans[1]))) else: print(("".join(reversed(ans[0]))+"".join(reversed(list(s)))+"".join(ans[1])))
32
21
612
467
s = eval(input()) q = int(eval(input())) que = [] count = 0 left = [] right = [] for i in range(q): qu = list(map(str, input().split())) if qu[0] == "1": count += 1 que.append(qu) han = 0 for i in range(q): if que[i][0] == "1": han += 1 else: if que[i][1] == "1": if (count - han) % 2 == 0: left.append(que[i][2]) else: right.append(que[i][2]) elif que[i][1] == "2": if (count - han) % 2 == 0: right.append(que[i][2]) else: left.append(que[i][2]) ls = "".join(left[::-1]) rs = "".join(right) if count % 2 == 0: print((ls + s + rs)) else: print((ls + s[::-1] + rs))
s = eval(input()) q = int(eval(input())) que = [list(map(str, input().split())) for i in range(q)] count = 0 for i in que: if i[0] == "1": count += 1 ans = [[], []] ak = count for i in que: if i[0] == "1": count -= 1 else: if i[1] == "1": ans[count % 2].append(i[2]) else: ans[(count + 1) % 2].append(i[2]) if ak % 2 == 0: print(("".join(reversed(ans[0])) + s + "".join(ans[1]))) else: print(("".join(reversed(ans[0])) + "".join(reversed(list(s))) + "".join(ans[1])))
false
34.375
[ "-que = []", "+que = [list(map(str, input().split())) for i in range(q)]", "-left = []", "-right = []", "-for i in range(q):", "- qu = list(map(str, input().split()))", "- if qu[0] == \"1\":", "+for i in que:", "+ if i[0] == \"1\":", "- que.append(qu)", "-han = 0", "-for i in range(q):", "- if que[i][0] == \"1\":", "- han += 1", "+ans = [[], []]", "+ak = count", "+for i in que:", "+ if i[0] == \"1\":", "+ count -= 1", "- if que[i][1] == \"1\":", "- if (count - han) % 2 == 0:", "- left.append(que[i][2])", "- else:", "- right.append(que[i][2])", "- elif que[i][1] == \"2\":", "- if (count - han) % 2 == 0:", "- right.append(que[i][2])", "- else:", "- left.append(que[i][2])", "-ls = \"\".join(left[::-1])", "-rs = \"\".join(right)", "-if count % 2 == 0:", "- print((ls + s + rs))", "+ if i[1] == \"1\":", "+ ans[count % 2].append(i[2])", "+ else:", "+ ans[(count + 1) % 2].append(i[2])", "+if ak % 2 == 0:", "+ print((\"\".join(reversed(ans[0])) + s + \"\".join(ans[1])))", "- print((ls + s[::-1] + rs))", "+ print((\"\".join(reversed(ans[0])) + \"\".join(reversed(list(s))) + \"\".join(ans[1])))" ]
false
0.037705
0.036221
1.040945
[ "s226911356", "s301226248" ]
u416011173
p02612
python
s234952487
s383287435
35
26
9,140
9,180
Accepted
Accepted
25.71
# -*- coding: utf-8 -*- # 標準入力を取得 N = int(eval(input())) # 求解処理 ans = (1000 - (N % 1000)) % 1000 # 結果出力 print(ans)
# -*- coding: utf-8 -*- def get_input() -> int: """ 標準入力を取得する. Returns:\n int: 標準入力 """ N = int(eval(input())) return N def main(N: int) -> None: """ メイン処理. Args:\n N (int): 整数(1 <= N <= 10000) """ # 求解処理 ans = (1000 - (N % 1000)) % 1000 # 結果出力 print(ans) if __name__ == "__main__": # 標準入力を取得 N = get_input() # メイン処理 main(N)
9
34
119
450
# -*- coding: utf-8 -*- # 標準入力を取得 N = int(eval(input())) # 求解処理 ans = (1000 - (N % 1000)) % 1000 # 結果出力 print(ans)
# -*- coding: utf-8 -*- def get_input() -> int: """ 標準入力を取得する. Returns:\n int: 標準入力 """ N = int(eval(input())) return N def main(N: int) -> None: """ メイン処理. Args:\n N (int): 整数(1 <= N <= 10000) """ # 求解処理 ans = (1000 - (N % 1000)) % 1000 # 結果出力 print(ans) if __name__ == "__main__": # 標準入力を取得 N = get_input() # メイン処理 main(N)
false
73.529412
[ "-# 標準入力を取得", "-N = int(eval(input()))", "-# 求解処理", "-ans = (1000 - (N % 1000)) % 1000", "-# 結果出力", "-print(ans)", "+def get_input() -> int:", "+ \"\"\"", "+ 標準入力を取得する.", "+ Returns:\\n", "+ int: 標準入力", "+ \"\"\"", "+ N = int(eval(input()))", "+ return N", "+", "+", "+def main(N: int) -> None:", "+ \"\"\"", "+ メイン処理.", "+ Args:\\n", "+ N (int): 整数(1 <= N <= 10000)", "+ \"\"\"", "+ # 求解処理", "+ ans = (1000 - (N % 1000)) % 1000", "+ # 結果出力", "+ print(ans)", "+", "+", "+if __name__ == \"__main__\":", "+ # 標準入力を取得", "+ N = get_input()", "+ # メイン処理", "+ main(N)" ]
false
0.038071
0.077896
0.488744
[ "s234952487", "s383287435" ]
u644907318
p04005
python
s725665877
s225872783
72
64
61,488
61,788
Accepted
Accepted
11.11
A,B,C = list(map(int,input().split())) if (A*B*C)%2==0: print((0)) else: print((min(A*B,B*C,C*A)))
A,B,C = list(map(int,input().split())) if A*B*C % 2 == 0: print((0)) else: print((min(A*B,B*C,C*A)))
5
5
100
102
A, B, C = list(map(int, input().split())) if (A * B * C) % 2 == 0: print((0)) else: print((min(A * B, B * C, C * A)))
A, B, C = list(map(int, input().split())) if A * B * C % 2 == 0: print((0)) else: print((min(A * B, B * C, C * A)))
false
0
[ "-if (A * B * C) % 2 == 0:", "+if A * B * C % 2 == 0:" ]
false
0.033695
0.074589
0.451736
[ "s725665877", "s225872783" ]
u853185302
p03160
python
s345105525
s146669969
831
549
103,100
22,744
Accepted
Accepted
33.94
import numpy as np import sys sys.setrecursionlimit(10**6) N = int(eval(input())) h = list(map(int,input().split())) memo = np.zeros(N) - 1 def search(i): if i == 0: return 0 elif i == 1: return abs(h[i] - h[i-1]) if memo[i] != -1: return memo[i] c1 = search(i-1) + abs(h[i]-h[i-1]) c2 = search(i-2) + abs(h[i]-h[i-2]) memo[i] = min(c1,c2) return min(c1,c2) print((int(search(N-1))))
import numpy as np N = int(eval(input())) h = list(map(int,input().split())) memo = np.zeros(N) memo[0] = 0 memo[1] = abs(h[0]-h[1]) for i in range(2,N): a = memo[i-1] + abs(h[i] - h[i-1]) b = memo[i-2] + abs(h[i] - h[i-2]) memo[i] = min(a,b) print((int(memo[N-1])))
23
15
430
282
import numpy as np import sys sys.setrecursionlimit(10**6) N = int(eval(input())) h = list(map(int, input().split())) memo = np.zeros(N) - 1 def search(i): if i == 0: return 0 elif i == 1: return abs(h[i] - h[i - 1]) if memo[i] != -1: return memo[i] c1 = search(i - 1) + abs(h[i] - h[i - 1]) c2 = search(i - 2) + abs(h[i] - h[i - 2]) memo[i] = min(c1, c2) return min(c1, c2) print((int(search(N - 1))))
import numpy as np N = int(eval(input())) h = list(map(int, input().split())) memo = np.zeros(N) memo[0] = 0 memo[1] = abs(h[0] - h[1]) for i in range(2, N): a = memo[i - 1] + abs(h[i] - h[i - 1]) b = memo[i - 2] + abs(h[i] - h[i - 2]) memo[i] = min(a, b) print((int(memo[N - 1])))
false
34.782609
[ "-import sys", "-sys.setrecursionlimit(10**6)", "-memo = np.zeros(N) - 1", "-", "-", "-def search(i):", "- if i == 0:", "- return 0", "- elif i == 1:", "- return abs(h[i] - h[i - 1])", "- if memo[i] != -1:", "- return memo[i]", "- c1 = search(i - 1) + abs(h[i] - h[i - 1])", "- c2 = search(i - 2) + abs(h[i] - h[i - 2])", "- memo[i] = min(c1, c2)", "- return min(c1, c2)", "-", "-", "-print((int(search(N - 1))))", "+memo = np.zeros(N)", "+memo[0] = 0", "+memo[1] = abs(h[0] - h[1])", "+for i in range(2, N):", "+ a = memo[i - 1] + abs(h[i] - h[i - 1])", "+ b = memo[i - 2] + abs(h[i] - h[i - 2])", "+ memo[i] = min(a, b)", "+print((int(memo[N - 1])))" ]
false
0.200277
0.195226
1.025875
[ "s345105525", "s146669969" ]
u272525952
p02818
python
s798601459
s476871323
165
28
38,384
9,116
Accepted
Accepted
83.03
a,b,k=list(map(int,input().split())) if a>=k: print((a-k,b)) elif a<k and a+b>=k: print((0,a+b-k)) else: print((0,0))
a,b,k=list(map(int,input().split())) if k<=a: print((a-k,b)) elif k>a and k<=a+b: print((0,a+b-k)) else: print((0,0))
8
7
129
123
a, b, k = list(map(int, input().split())) if a >= k: print((a - k, b)) elif a < k and a + b >= k: print((0, a + b - k)) else: print((0, 0))
a, b, k = list(map(int, input().split())) if k <= a: print((a - k, b)) elif k > a and k <= a + b: print((0, a + b - k)) else: print((0, 0))
false
12.5
[ "-if a >= k:", "+if k <= a:", "-elif a < k and a + b >= k:", "+elif k > a and k <= a + b:" ]
false
0.079397
0.035983
2.206526
[ "s798601459", "s476871323" ]
u263830634
p02990
python
s503064103
s702513045
202
21
3,316
3,316
Accepted
Accepted
89.6
import math N, K = list(map(int, input().split())) R = N - K if R == 0: #赤いボールが無い時 print((1)) for _ in range(1, K): print((0)) exit() if K == 1: #青いボールが1つのとき print((R+1)) exit() # K_1 = math.factorial(K-1) # R_1 = math.factorial(R+1) # print (K_1, R_1) for i in range(1, K+1): #K回答えを出力 if i > R+1: print((0)) continue if i == 1: print((R + 1)) continue # print (K_1, R_1, math.factorial(i)) if i >= 2: position = R_1 = math.factorial(R+1)//(math.factorial(i) * math.factorial(R + 1- i)) boal = math.factorial(K-1)//(math.factorial(i-1) * math.factorial(K - i)) print(((position * boal)%(7 + 10 ** 9)))
N, K = list(map(int, input().split())) R = N - K if R == 0: #赤いボールが無い時 print((1)) for _ in range(1, K): print((0)) exit() if K == 1: #青いボールが1つのとき print((R+1)) exit() for i in range(1, K+1): #K回答えを出力 if i > R+1: print((0)) continue if i == 1: position = R + 1 boal = 1 if i >= 2: position = ((position * (R + 1 - (i-1))) // i) #%(7 + 10 ** 9) boal = ((boal * (K - (i-1)))// (i-1)) #%(7 + 10 ** 9) print(((position * boal)%(7 + 10 ** 9)))
31
24
720
544
import math N, K = list(map(int, input().split())) R = N - K if R == 0: # 赤いボールが無い時 print((1)) for _ in range(1, K): print((0)) exit() if K == 1: # 青いボールが1つのとき print((R + 1)) exit() # K_1 = math.factorial(K-1) # R_1 = math.factorial(R+1) # print (K_1, R_1) for i in range(1, K + 1): # K回答えを出力 if i > R + 1: print((0)) continue if i == 1: print((R + 1)) continue # print (K_1, R_1, math.factorial(i)) if i >= 2: position = R_1 = math.factorial(R + 1) // ( math.factorial(i) * math.factorial(R + 1 - i) ) boal = math.factorial(K - 1) // (math.factorial(i - 1) * math.factorial(K - i)) print(((position * boal) % (7 + 10**9)))
N, K = list(map(int, input().split())) R = N - K if R == 0: # 赤いボールが無い時 print((1)) for _ in range(1, K): print((0)) exit() if K == 1: # 青いボールが1つのとき print((R + 1)) exit() for i in range(1, K + 1): # K回答えを出力 if i > R + 1: print((0)) continue if i == 1: position = R + 1 boal = 1 if i >= 2: position = (position * (R + 1 - (i - 1))) // i #%(7 + 10 ** 9) boal = (boal * (K - (i - 1))) // (i - 1) #%(7 + 10 ** 9) print(((position * boal) % (7 + 10**9)))
false
22.580645
[ "-import math", "-", "-# K_1 = math.factorial(K-1)", "-# R_1 = math.factorial(R+1)", "-# print (K_1, R_1)", "- print((R + 1))", "- continue", "- # print (K_1, R_1, math.factorial(i))", "+ position = R + 1", "+ boal = 1", "- position = R_1 = math.factorial(R + 1) // (", "- math.factorial(i) * math.factorial(R + 1 - i)", "- )", "- boal = math.factorial(K - 1) // (math.factorial(i - 1) * math.factorial(K - i))", "+ position = (position * (R + 1 - (i - 1))) // i #%(7 + 10 ** 9)", "+ boal = (boal * (K - (i - 1))) // (i - 1) #%(7 + 10 ** 9)" ]
false
0.042694
0.037009
1.153613
[ "s503064103", "s702513045" ]
u170183831
p03568
python
s272804435
s758926272
29
25
9,072
9,024
Accepted
Accepted
13.79
n = int(eval(input())) A = list(map(int, input().split())) count = 1 for a in A: count *= 2 if a % 2 == 0 else 1 print((3 ** n - count))
n = int(eval(input())) A = list(map(int, input().split())) print((3 ** n - 2 ** len([a for a in A if a % 2 == 0])))
7
4
137
111
n = int(eval(input())) A = list(map(int, input().split())) count = 1 for a in A: count *= 2 if a % 2 == 0 else 1 print((3**n - count))
n = int(eval(input())) A = list(map(int, input().split())) print((3**n - 2 ** len([a for a in A if a % 2 == 0])))
false
42.857143
[ "-count = 1", "-for a in A:", "- count *= 2 if a % 2 == 0 else 1", "-print((3**n - count))", "+print((3**n - 2 ** len([a for a in A if a % 2 == 0])))" ]
false
0.052115
0.077182
0.675215
[ "s272804435", "s758926272" ]
u489959379
p03304
python
s230418516
s861179972
32
23
9,132
9,164
Accepted
Accepted
28.12
import sys sys.setrecursionlimit(10 ** 7) f_inf = float('inf') mod = 10 ** 9 + 7 def resolve(): n, m, d = list(map(int, input().split())) if d == 0: print(((m - 1) / n)) else: print(((m - 1) * 2 * (n - d) / n ** 2)) if __name__ == '__main__': resolve()
import sys sys.setrecursionlimit(10 ** 7) input = sys.stdin.readline f_inf = float('inf') mod = 10 ** 9 + 7 def resolve(): n, m, d = list(map(int, input().split())) print(((m - 1) / n if d == 0 else (m - 1) * (n - d) * 2 / pow(n, 2))) if __name__ == '__main__': resolve()
17
15
296
295
import sys sys.setrecursionlimit(10**7) f_inf = float("inf") mod = 10**9 + 7 def resolve(): n, m, d = list(map(int, input().split())) if d == 0: print(((m - 1) / n)) else: print(((m - 1) * 2 * (n - d) / n**2)) if __name__ == "__main__": resolve()
import sys sys.setrecursionlimit(10**7) input = sys.stdin.readline f_inf = float("inf") mod = 10**9 + 7 def resolve(): n, m, d = list(map(int, input().split())) print(((m - 1) / n if d == 0 else (m - 1) * (n - d) * 2 / pow(n, 2))) if __name__ == "__main__": resolve()
false
11.764706
[ "+input = sys.stdin.readline", "- if d == 0:", "- print(((m - 1) / n))", "- else:", "- print(((m - 1) * 2 * (n - d) / n**2))", "+ print(((m - 1) / n if d == 0 else (m - 1) * (n - d) * 2 / pow(n, 2)))" ]
false
0.037697
0.037208
1.013152
[ "s230418516", "s861179972" ]
u671060652
p03041
python
s618621626
s829603141
164
68
38,256
61,820
Accepted
Accepted
58.54
n, k = list(map(int, input().split())) s = list(eval(input())) s[k-1] = chr(ord(s[k-1])+ord("a")-ord("A")) print(("".join(s)))
import math def main(): # n = int(input()) n, k = list(map(int, input().split())) # h = list(map(int, input().split())) s = list(eval(input())) # h = [int(input()) for _ in rane(n)] s[k-1] = s[k-1].lower() print(("".join(s))) if __name__ == '__main__': main()
6
16
119
298
n, k = list(map(int, input().split())) s = list(eval(input())) s[k - 1] = chr(ord(s[k - 1]) + ord("a") - ord("A")) print(("".join(s)))
import math def main(): # n = int(input()) n, k = list(map(int, input().split())) # h = list(map(int, input().split())) s = list(eval(input())) # h = [int(input()) for _ in rane(n)] s[k - 1] = s[k - 1].lower() print(("".join(s))) if __name__ == "__main__": main()
false
62.5
[ "-n, k = list(map(int, input().split()))", "-s = list(eval(input()))", "-s[k - 1] = chr(ord(s[k - 1]) + ord(\"a\") - ord(\"A\"))", "-print((\"\".join(s)))", "+import math", "+", "+", "+def main():", "+ # n = int(input())", "+ n, k = list(map(int, input().split()))", "+ # h = list(map(int, input().split()))", "+ s = list(eval(input()))", "+ # h = [int(input()) for _ in rane(n)]", "+ s[k - 1] = s[k - 1].lower()", "+ print((\"\".join(s)))", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.035708
0.034615
1.031559
[ "s618621626", "s829603141" ]
u811733736
p00184
python
s249712740
s336886744
810
660
7,980
7,992
Accepted
Accepted
18.52
# -*- coding: utf-8 -*- """ http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0184 """ import sys from sys import stdin from collections import defaultdict input = stdin.readline def main(args): while True: n = int(eval(input())) if n == 0: break visitors = defaultdict(int) for _ in range(n): age = int(eval(input())) if age < 10: visitors['under10'] += 1 elif age < 20: visitors['10s'] += 1 elif age < 30: visitors['20s'] += 1 elif age < 40: visitors['30s'] += 1 elif age < 50: visitors['40s'] += 1 elif age < 60: visitors['50s'] += 1 else: visitors['60s+'] += 1 print((visitors['under10'])) print((visitors['10s'])) print((visitors['20s'])) print((visitors['30s'])) print((visitors['40s'])) print((visitors['50s'])) print((visitors['60s+'])) if __name__ == '__main__': main(sys.argv[1:])
# -*- coding: utf-8 -*- """ http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0184 """ import sys from sys import stdin from collections import defaultdict input = stdin.readline def main(args): while True: n = int(eval(input())) if n == 0: break visitors = defaultdict(int) for _ in range(n): age = int(eval(input())) if age < 10: visitors['under10'] += 1 elif age < 20: visitors['10s'] += 1 elif age < 30: visitors['20s'] += 1 elif age < 40: visitors['30s'] += 1 elif age < 50: visitors['40s'] += 1 elif age < 60: visitors['50s'] += 1 else: visitors['60s+'] += 1 print((visitors['under10'])) print((visitors['10s'])) print((visitors['20s'])) print((visitors['30s'])) print((visitors['40s'])) print((visitors['50s'])) print((visitors['60s+'])) def main2(args): while True: n = int(eval(input())) if n == 0: break age = [0] * (120 + 1) for _ in range(n): n = int(eval(input())) age[n] += 1 print((sum(age[0:10]))) print((sum(age[10:20]))) print((sum(age[20:30]))) print((sum(age[30:40]))) print((sum(age[40:50]))) print((sum(age[50:60]))) print((sum(age[60:]))) if __name__ == '__main__': main2(sys.argv[1:])
47
67
1,145
1,585
# -*- coding: utf-8 -*- """ http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0184 """ import sys from sys import stdin from collections import defaultdict input = stdin.readline def main(args): while True: n = int(eval(input())) if n == 0: break visitors = defaultdict(int) for _ in range(n): age = int(eval(input())) if age < 10: visitors["under10"] += 1 elif age < 20: visitors["10s"] += 1 elif age < 30: visitors["20s"] += 1 elif age < 40: visitors["30s"] += 1 elif age < 50: visitors["40s"] += 1 elif age < 60: visitors["50s"] += 1 else: visitors["60s+"] += 1 print((visitors["under10"])) print((visitors["10s"])) print((visitors["20s"])) print((visitors["30s"])) print((visitors["40s"])) print((visitors["50s"])) print((visitors["60s+"])) if __name__ == "__main__": main(sys.argv[1:])
# -*- coding: utf-8 -*- """ http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0184 """ import sys from sys import stdin from collections import defaultdict input = stdin.readline def main(args): while True: n = int(eval(input())) if n == 0: break visitors = defaultdict(int) for _ in range(n): age = int(eval(input())) if age < 10: visitors["under10"] += 1 elif age < 20: visitors["10s"] += 1 elif age < 30: visitors["20s"] += 1 elif age < 40: visitors["30s"] += 1 elif age < 50: visitors["40s"] += 1 elif age < 60: visitors["50s"] += 1 else: visitors["60s+"] += 1 print((visitors["under10"])) print((visitors["10s"])) print((visitors["20s"])) print((visitors["30s"])) print((visitors["40s"])) print((visitors["50s"])) print((visitors["60s+"])) def main2(args): while True: n = int(eval(input())) if n == 0: break age = [0] * (120 + 1) for _ in range(n): n = int(eval(input())) age[n] += 1 print((sum(age[0:10]))) print((sum(age[10:20]))) print((sum(age[20:30]))) print((sum(age[30:40]))) print((sum(age[40:50]))) print((sum(age[50:60]))) print((sum(age[60:]))) if __name__ == "__main__": main2(sys.argv[1:])
false
29.850746
[ "+def main2(args):", "+ while True:", "+ n = int(eval(input()))", "+ if n == 0:", "+ break", "+ age = [0] * (120 + 1)", "+ for _ in range(n):", "+ n = int(eval(input()))", "+ age[n] += 1", "+ print((sum(age[0:10])))", "+ print((sum(age[10:20])))", "+ print((sum(age[20:30])))", "+ print((sum(age[30:40])))", "+ print((sum(age[40:50])))", "+ print((sum(age[50:60])))", "+ print((sum(age[60:])))", "+", "+", "- main(sys.argv[1:])", "+ main2(sys.argv[1:])" ]
false
0.131239
0.171046
0.767278
[ "s249712740", "s336886744" ]
u077291787
p03761
python
s777728675
s872190895
26
23
3,768
3,572
Accepted
Accepted
11.54
# ABC058C - 怪文書 / Dubious Document (ARC071C) import sys input = sys.stdin.readline from collections import Counter from string import ascii_lowercase def main(): N = int(eval(input())) D = tuple(Counter(eval(input())) for _ in range(N)) ans = "" for s in ascii_lowercase: if all(s in d for d in D): ans += s * min(d[s] for d in D) print(ans) if __name__ == "__main__": main()
# ABC058C - 怪文書 / Dubious Document (ARC071C) from functools import reduce def main(): N = int(input()) if N == 1: print(*sorted(input()), sep="") return S = tuple(input() for _ in range(N)) ch = sorted(reduce(lambda a, b: set(a) & set(b), S)) ans = "" for i in ch: ans += i * min(s.count(i) for s in S) print(ans) if __name__ == "__main__": main()
20
19
431
425
# ABC058C - 怪文書 / Dubious Document (ARC071C) import sys input = sys.stdin.readline from collections import Counter from string import ascii_lowercase def main(): N = int(eval(input())) D = tuple(Counter(eval(input())) for _ in range(N)) ans = "" for s in ascii_lowercase: if all(s in d for d in D): ans += s * min(d[s] for d in D) print(ans) if __name__ == "__main__": main()
# ABC058C - 怪文書 / Dubious Document (ARC071C) from functools import reduce def main(): N = int(input()) if N == 1: print(*sorted(input()), sep="") return S = tuple(input() for _ in range(N)) ch = sorted(reduce(lambda a, b: set(a) & set(b), S)) ans = "" for i in ch: ans += i * min(s.count(i) for s in S) print(ans) if __name__ == "__main__": main()
false
5
[ "-import sys", "-", "-input = sys.stdin.readline", "-from collections import Counter", "-from string import ascii_lowercase", "+from functools import reduce", "- N = int(eval(input()))", "- D = tuple(Counter(eval(input())) for _ in range(N))", "+ N = int(input())", "+ if N == 1:", "+ print(*sorted(input()), sep=\"\")", "+ return", "+ S = tuple(input() for _ in range(N))", "+ ch = sorted(reduce(lambda a, b: set(a) & set(b), S))", "- for s in ascii_lowercase:", "- if all(s in d for d in D):", "- ans += s * min(d[s] for d in D)", "+ for i in ch:", "+ ans += i * min(s.count(i) for s in S)" ]
false
0.154652
0.068422
2.260268
[ "s777728675", "s872190895" ]
u133936772
p02779
python
s825367655
s755267292
87
62
36,656
31,156
Accepted
Accepted
28.74
print((['YES','NO'][int(eval(input()))>len(set(map(int,input().split())))]))
print(('YNEOS'[int(eval(input()))>len(set(input().split()))::2]))
1
1
68
57
print((["YES", "NO"][int(eval(input())) > len(set(map(int, input().split())))]))
print(("YNEOS"[int(eval(input())) > len(set(input().split())) :: 2]))
false
0
[ "-print(([\"YES\", \"NO\"][int(eval(input())) > len(set(map(int, input().split())))]))", "+print((\"YNEOS\"[int(eval(input())) > len(set(input().split())) :: 2]))" ]
false
0.047393
0.03637
1.303062
[ "s825367655", "s755267292" ]
u690536347
p03216
python
s747678805
s701951573
1,515
1,337
86,108
83,312
Accepted
Accepted
11.75
N = int(eval(input())) S = eval(input()) Q = int(eval(input())) *k, = list(map(int, input().split())) acd = [0]*(N+1) acm = [0]*(N+1) acc = [0]*(N+1) acmc = [0]*(N+2) for i in range(1, N+1): acd[i] = acd[i-1] + (S[i-1]=="D") acm[i] = acm[i-1] + (S[i-1]=="M") acc[i] = acc[i-1] + (S[i-1]=="C") ans = 0 for i in range(1, N+1): if S[i-1]=="M": ans += acd[i-1]*(acc[N]-acc[i]) for i in range(1, N)[::-1]: acmc[i] += acmc[i+1] if S[i-1]=="M": acmc[i] += acc[N]-acc[i] for i in k: v = 0 for j in range(1, N+1): if S[j-1]=="D": v += (acm[min(N, i+j-1)]-acm[j]) * (acc[N]-acc[min(N, i+j-1)]) + acmc[min(i+j, N)] print((ans-v))
import sys input=sys.stdin.readline def solve(): N = int(eval(input())) S = eval(input()) Q = int(eval(input())) *k, = list(map(int, input().split())) acd = [0]*(N+1) acm = [0]*(N+1) acc = [0]*(N+1) acmc = [0]*(N+2) for i in range(1, N+1): acd[i] = acd[i-1] + (S[i-1]=="D") acm[i] = acm[i-1] + (S[i-1]=="M") acc[i] = acc[i-1] + (S[i-1]=="C") ans = 0 for i in range(1, N+1): if S[i-1]=="M": ans += acd[i-1]*(acc[N]-acc[i]) for i in range(1, N)[::-1]: acmc[i] += acmc[i+1] if S[i-1]=="M": acmc[i] += acc[N]-acc[i] for i in k: v = 0 for j in range(1, N+1): if S[j-1]=="D": v += (acm[min(N, i+j-1)]-acm[j]) * (acc[N]-acc[min(N, i+j-1)]) + acmc[min(i+j, N)] print((ans-v)) if __name__ == "__main__": solve()
31
40
699
905
N = int(eval(input())) S = eval(input()) Q = int(eval(input())) (*k,) = list(map(int, input().split())) acd = [0] * (N + 1) acm = [0] * (N + 1) acc = [0] * (N + 1) acmc = [0] * (N + 2) for i in range(1, N + 1): acd[i] = acd[i - 1] + (S[i - 1] == "D") acm[i] = acm[i - 1] + (S[i - 1] == "M") acc[i] = acc[i - 1] + (S[i - 1] == "C") ans = 0 for i in range(1, N + 1): if S[i - 1] == "M": ans += acd[i - 1] * (acc[N] - acc[i]) for i in range(1, N)[::-1]: acmc[i] += acmc[i + 1] if S[i - 1] == "M": acmc[i] += acc[N] - acc[i] for i in k: v = 0 for j in range(1, N + 1): if S[j - 1] == "D": v += (acm[min(N, i + j - 1)] - acm[j]) * ( acc[N] - acc[min(N, i + j - 1)] ) + acmc[min(i + j, N)] print((ans - v))
import sys input = sys.stdin.readline def solve(): N = int(eval(input())) S = eval(input()) Q = int(eval(input())) (*k,) = list(map(int, input().split())) acd = [0] * (N + 1) acm = [0] * (N + 1) acc = [0] * (N + 1) acmc = [0] * (N + 2) for i in range(1, N + 1): acd[i] = acd[i - 1] + (S[i - 1] == "D") acm[i] = acm[i - 1] + (S[i - 1] == "M") acc[i] = acc[i - 1] + (S[i - 1] == "C") ans = 0 for i in range(1, N + 1): if S[i - 1] == "M": ans += acd[i - 1] * (acc[N] - acc[i]) for i in range(1, N)[::-1]: acmc[i] += acmc[i + 1] if S[i - 1] == "M": acmc[i] += acc[N] - acc[i] for i in k: v = 0 for j in range(1, N + 1): if S[j - 1] == "D": v += (acm[min(N, i + j - 1)] - acm[j]) * ( acc[N] - acc[min(N, i + j - 1)] ) + acmc[min(i + j, N)] print((ans - v)) if __name__ == "__main__": solve()
false
22.5
[ "-N = int(eval(input()))", "-S = eval(input())", "-Q = int(eval(input()))", "-(*k,) = list(map(int, input().split()))", "-acd = [0] * (N + 1)", "-acm = [0] * (N + 1)", "-acc = [0] * (N + 1)", "-acmc = [0] * (N + 2)", "-for i in range(1, N + 1):", "- acd[i] = acd[i - 1] + (S[i - 1] == \"D\")", "- acm[i] = acm[i - 1] + (S[i - 1] == \"M\")", "- acc[i] = acc[i - 1] + (S[i - 1] == \"C\")", "-ans = 0", "-for i in range(1, N + 1):", "- if S[i - 1] == \"M\":", "- ans += acd[i - 1] * (acc[N] - acc[i])", "-for i in range(1, N)[::-1]:", "- acmc[i] += acmc[i + 1]", "- if S[i - 1] == \"M\":", "- acmc[i] += acc[N] - acc[i]", "-for i in k:", "- v = 0", "- for j in range(1, N + 1):", "- if S[j - 1] == \"D\":", "- v += (acm[min(N, i + j - 1)] - acm[j]) * (", "- acc[N] - acc[min(N, i + j - 1)]", "- ) + acmc[min(i + j, N)]", "- print((ans - v))", "+import sys", "+", "+input = sys.stdin.readline", "+", "+", "+def solve():", "+ N = int(eval(input()))", "+ S = eval(input())", "+ Q = int(eval(input()))", "+ (*k,) = list(map(int, input().split()))", "+ acd = [0] * (N + 1)", "+ acm = [0] * (N + 1)", "+ acc = [0] * (N + 1)", "+ acmc = [0] * (N + 2)", "+ for i in range(1, N + 1):", "+ acd[i] = acd[i - 1] + (S[i - 1] == \"D\")", "+ acm[i] = acm[i - 1] + (S[i - 1] == \"M\")", "+ acc[i] = acc[i - 1] + (S[i - 1] == \"C\")", "+ ans = 0", "+ for i in range(1, N + 1):", "+ if S[i - 1] == \"M\":", "+ ans += acd[i - 1] * (acc[N] - acc[i])", "+ for i in range(1, N)[::-1]:", "+ acmc[i] += acmc[i + 1]", "+ if S[i - 1] == \"M\":", "+ acmc[i] += acc[N] - acc[i]", "+ for i in k:", "+ v = 0", "+ for j in range(1, N + 1):", "+ if S[j - 1] == \"D\":", "+ v += (acm[min(N, i + j - 1)] - acm[j]) * (", "+ acc[N] - acc[min(N, i + j - 1)]", "+ ) + acmc[min(i + j, N)]", "+ print((ans - v))", "+", "+", "+if __name__ == \"__main__\":", "+ solve()" ]
false
0.099431
0.158474
0.627432
[ "s747678805", "s701951573" ]
u203843959
p03722
python
s329972201
s336600294
752
649
4,340
4,340
Accepted
Accepted
13.7
import sys sys.setrecursionlimit(10**9) N,M=list(map(int,input().split())) def find_negative_loop(n,w,es): dist=[float("inf")]*n #この始点はどこでもよい dist[1]=0 for i in range(n): for j in range(w): e=es[j] if dist[e[1]]>dist[e[0]]+e[2]: dist[e[1]]=dist[e[0]]+e[2] if i==n-1: return True return False def shortest_path(s,n,w,es): #s→iの最短距離 #s:始点, n:頂点数, w:辺の数, es[i]:[辺の始点,辺の終点,辺のコスト] dist=[float("inf")]*n #d[i]: s→iの最短距離 dist[s]=0 while True: update=False for p,q,r in es: # e: 辺iについて [from,to,cost] if dist[p]!=float("inf") and dist[q]>dist[p]+r: dist[q]=dist[p]+r update=True if not update: break return dist graph=[[] for _ in range(N+1)] elist=[] for _ in range(M): a,b,c=list(map(int,input().split())) graph[a].append(b) elist.append((a,b,-c)) #remove unnecessary vertex and edge visited=[None]*(N+1) def check_reachable(u): if u==N: reachable[u]=True return True visited[u]=True cnt=0 for v in graph[u]: if not visited[v]: ret=check_reachable(v) if ret: cnt+=1 if cnt>0: reachable[u]=True return True else: return False reachable=[False]*(N+1) for i in range(1,N+1): if not reachable[i]: visited=[False]*(N+1) check_reachable(i) #print(reachable) elist2=[] for a,b,nc in elist: if reachable[b]: elist2.append((a,b,nc)) M2=len(elist2) res1=find_negative_loop(N+1,M2,elist2) if res1: print("inf") else: res2=shortest_path(1,N+1,M2,elist2) print((-res2[N]))
import sys sys.setrecursionlimit(10**9) N,M=list(map(int,input().split())) def find_negative_loop(n,w,es): dist=[float("inf")]*n #この始点はどこでもよい dist[1]=0 for i in range(n): for j in range(w): e=es[j] if dist[e[1]]>dist[e[0]]+e[2]: dist[e[1]]=dist[e[0]]+e[2] if i==n-1: return True return False def shortest_path(s,n,w,es): #s→iの最短距離 #s:始点, n:頂点数, w:辺の数, es[i]:[辺の始点,辺の終点,辺のコスト] dist=[float("inf")]*n #d[i]: s→iの最短距離 dist[s]=0 while True: update=False for p,q,r in es: # e: 辺iについて [from,to,cost] if dist[p]!=float("inf") and dist[q]>dist[p]+r: dist[q]=dist[p]+r update=True if not update: break return dist graph=[[] for _ in range(N+1)] elist=[] for _ in range(M): a,b,c=list(map(int,input().split())) graph[a].append(b) elist.append((a,b,-c)) #remove unnecessary vertex and edge visited=[None]*(N+1) def check_reachable(u): visited[u]=True if u==N: reachable[u]=True return True elif reachable[u]!=None: return reachable[u] cnt=0 for v in graph[u]: if not visited[v]: ret=check_reachable(v) if ret: cnt+=1 if cnt>0: reachable[u]=True return True else: return False reachable=[None]*(N+1) for i in range(1,N+1): if reachable[i]==None: visited=[False]*(N+1) check_reachable(i) #print(reachable) elist2=[] for a,b,nc in elist: if reachable[b]: elist2.append((a,b,nc)) M2=len(elist2) res1=find_negative_loop(N+1,M2,elist2) if res1: print("inf") else: res2=shortest_path(1,N+1,M2,elist2) print((-res2[N]))
85
87
1,656
1,710
import sys sys.setrecursionlimit(10**9) N, M = list(map(int, input().split())) def find_negative_loop(n, w, es): dist = [float("inf")] * n # この始点はどこでもよい dist[1] = 0 for i in range(n): for j in range(w): e = es[j] if dist[e[1]] > dist[e[0]] + e[2]: dist[e[1]] = dist[e[0]] + e[2] if i == n - 1: return True return False def shortest_path(s, n, w, es): # s→iの最短距離 # s:始点, n:頂点数, w:辺の数, es[i]:[辺の始点,辺の終点,辺のコスト] dist = [float("inf")] * n # d[i]: s→iの最短距離 dist[s] = 0 while True: update = False for p, q, r in es: # e: 辺iについて [from,to,cost] if dist[p] != float("inf") and dist[q] > dist[p] + r: dist[q] = dist[p] + r update = True if not update: break return dist graph = [[] for _ in range(N + 1)] elist = [] for _ in range(M): a, b, c = list(map(int, input().split())) graph[a].append(b) elist.append((a, b, -c)) # remove unnecessary vertex and edge visited = [None] * (N + 1) def check_reachable(u): if u == N: reachable[u] = True return True visited[u] = True cnt = 0 for v in graph[u]: if not visited[v]: ret = check_reachable(v) if ret: cnt += 1 if cnt > 0: reachable[u] = True return True else: return False reachable = [False] * (N + 1) for i in range(1, N + 1): if not reachable[i]: visited = [False] * (N + 1) check_reachable(i) # print(reachable) elist2 = [] for a, b, nc in elist: if reachable[b]: elist2.append((a, b, nc)) M2 = len(elist2) res1 = find_negative_loop(N + 1, M2, elist2) if res1: print("inf") else: res2 = shortest_path(1, N + 1, M2, elist2) print((-res2[N]))
import sys sys.setrecursionlimit(10**9) N, M = list(map(int, input().split())) def find_negative_loop(n, w, es): dist = [float("inf")] * n # この始点はどこでもよい dist[1] = 0 for i in range(n): for j in range(w): e = es[j] if dist[e[1]] > dist[e[0]] + e[2]: dist[e[1]] = dist[e[0]] + e[2] if i == n - 1: return True return False def shortest_path(s, n, w, es): # s→iの最短距離 # s:始点, n:頂点数, w:辺の数, es[i]:[辺の始点,辺の終点,辺のコスト] dist = [float("inf")] * n # d[i]: s→iの最短距離 dist[s] = 0 while True: update = False for p, q, r in es: # e: 辺iについて [from,to,cost] if dist[p] != float("inf") and dist[q] > dist[p] + r: dist[q] = dist[p] + r update = True if not update: break return dist graph = [[] for _ in range(N + 1)] elist = [] for _ in range(M): a, b, c = list(map(int, input().split())) graph[a].append(b) elist.append((a, b, -c)) # remove unnecessary vertex and edge visited = [None] * (N + 1) def check_reachable(u): visited[u] = True if u == N: reachable[u] = True return True elif reachable[u] != None: return reachable[u] cnt = 0 for v in graph[u]: if not visited[v]: ret = check_reachable(v) if ret: cnt += 1 if cnt > 0: reachable[u] = True return True else: return False reachable = [None] * (N + 1) for i in range(1, N + 1): if reachable[i] == None: visited = [False] * (N + 1) check_reachable(i) # print(reachable) elist2 = [] for a, b, nc in elist: if reachable[b]: elist2.append((a, b, nc)) M2 = len(elist2) res1 = find_negative_loop(N + 1, M2, elist2) if res1: print("inf") else: res2 = shortest_path(1, N + 1, M2, elist2) print((-res2[N]))
false
2.298851
[ "+ visited[u] = True", "- visited[u] = True", "+ elif reachable[u] != None:", "+ return reachable[u]", "-reachable = [False] * (N + 1)", "+reachable = [None] * (N + 1)", "- if not reachable[i]:", "+ if reachable[i] == None:" ]
false
0.050926
0.048873
1.042014
[ "s329972201", "s336600294" ]
u744920373
p03031
python
s333776500
s837977397
31
27
3,064
3,064
Accepted
Accepted
12.9
import sys sys.setrecursionlimit(10**8) def ii(): return int(sys.stdin.readline()) def mi(): return list(map(int, sys.stdin.readline().split())) def li(): return list(map(int, sys.stdin.readline().split())) def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)] def dp2(ini, i, j): return [[ini]*i for _ in range(j)] def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)] #import bisect #bisect.bisect_left(B, a) #from collections import defaultdict #d = defaultdict(int) d[key] += value #from itertools import accumulate #list(accumulate(A)) N, M = mi() ks = [] for i in range(M): a = li() ks.append(a) P = li() cnt = 0 for i in range(2**N): x = bin(i)[2:].zfill(N) l = list(map(int, list(x))) flag = 1 for i in range(M): num , *switchs = ks[i] if sum([l[sw-1] for sw in switchs]) % 2 != P[i]: flag = 0 break if flag: cnt += 1 print(cnt)
import sys sys.setrecursionlimit(10**8) def ii(): return int(sys.stdin.readline()) def mi(): return list(map(int, sys.stdin.readline().split())) def li(): return list(map(int, sys.stdin.readline().split())) def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)] def dp2(ini, i, j): return [[ini]*i for _ in range(j)] def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)] #import bisect #bisect.bisect_left(B, a) #from collections import defaultdict #d = defaultdict(int) d[key] += value #from itertools import accumulate #list(accumulate(A)) from itertools import product N, M = mi() ks = [] for i in range(M): a = li() ks.append(a) P = li() cnt = 0 #for i in range(2**N): #x = bin(i)[2:].zfill(N) #l = list(map(int, list(x))) for l in product([0, 1], repeat=N): for i in range(M): num , *switchs = ks[i] if sum([l[sw-1] for sw in switchs]) % 2 != P[i]: break else: cnt += 1 print(cnt)
33
35
995
1,031
import sys sys.setrecursionlimit(10**8) def ii(): return int(sys.stdin.readline()) def mi(): return list(map(int, sys.stdin.readline().split())) def li(): return list(map(int, sys.stdin.readline().split())) def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)] def dp2(ini, i, j): return [[ini] * i for _ in range(j)] def dp3(ini, i, j, k): return [[[ini] * i for _ in range(j)] for _ in range(k)] # import bisect #bisect.bisect_left(B, a) # from collections import defaultdict #d = defaultdict(int) d[key] += value # from itertools import accumulate #list(accumulate(A)) N, M = mi() ks = [] for i in range(M): a = li() ks.append(a) P = li() cnt = 0 for i in range(2**N): x = bin(i)[2:].zfill(N) l = list(map(int, list(x))) flag = 1 for i in range(M): num, *switchs = ks[i] if sum([l[sw - 1] for sw in switchs]) % 2 != P[i]: flag = 0 break if flag: cnt += 1 print(cnt)
import sys sys.setrecursionlimit(10**8) def ii(): return int(sys.stdin.readline()) def mi(): return list(map(int, sys.stdin.readline().split())) def li(): return list(map(int, sys.stdin.readline().split())) def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)] def dp2(ini, i, j): return [[ini] * i for _ in range(j)] def dp3(ini, i, j, k): return [[[ini] * i for _ in range(j)] for _ in range(k)] # import bisect #bisect.bisect_left(B, a) # from collections import defaultdict #d = defaultdict(int) d[key] += value # from itertools import accumulate #list(accumulate(A)) from itertools import product N, M = mi() ks = [] for i in range(M): a = li() ks.append(a) P = li() cnt = 0 # for i in range(2**N): # x = bin(i)[2:].zfill(N) # l = list(map(int, list(x))) for l in product([0, 1], repeat=N): for i in range(M): num, *switchs = ks[i] if sum([l[sw - 1] for sw in switchs]) % 2 != P[i]: break else: cnt += 1 print(cnt)
false
5.714286
[ "+from itertools import product", "+", "-for i in range(2**N):", "- x = bin(i)[2:].zfill(N)", "- l = list(map(int, list(x)))", "- flag = 1", "+# for i in range(2**N):", "+# x = bin(i)[2:].zfill(N)", "+# l = list(map(int, list(x)))", "+for l in product([0, 1], repeat=N):", "- flag = 0", "- if flag:", "+ else:" ]
false
0.097365
0.13347
0.729492
[ "s333776500", "s837977397" ]
u156815136
p03240
python
s953557710
s539147230
386
57
5,148
5,148
Accepted
Accepted
85.23
from statistics import median #import collections #aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0] from fractions import gcd from itertools import combinations # (string,3) 3回 from collections import deque from collections import defaultdict import bisect # # d = m - k[i] - k[j] # if kk[bisect.bisect_right(kk,d) - 1] == d: # # # # pythonで無理なときは、pypyでやると正解するかも!! # # import sys sys.setrecursionlimit(10000000) mod = 10**9 + 7 def readInts(): return list(map(int,input().split())) def main(): n = int(eval(input())) vx = [] vy = [] vh = [] for i in range(n): x,y,h = readInts() vx.append(x) vy.append(y) vh.append(h) if h > 0: si = i # 基準となる座標はどこでもいい # けど、h = 0 のところはだめやねん # resx,resy,resh = -1,-1,-1 for x in range(101): for y in range(101): h = vh[si] + abs(x - vx[si]) + abs(y - vy[si]) ok = True for i in range(n): if vh[i] > 0 and h - vh[i] != abs(x - vx[i]) + abs(y - vy[i]): ok = False if vh[i] == 0 and h > abs(x - vx[i]) + abs(y - vy[i]): ok = False if ok: resx = x resy = y resh = h print((resx,resy,resh)) if __name__ == '__main__': main()
from statistics import median #import collections #aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0] from fractions import gcd from itertools import combinations # (string,3) 3回 from collections import deque from collections import defaultdict import bisect # # d = m - k[i] - k[j] # if kk[bisect.bisect_right(kk,d) - 1] == d: # # # # pythonで無理なときは、pypyでやると正解するかも!! # # import sys sys.setrecursionlimit(10000000) mod = 10**9 + 7 def readInts(): return list(map(int,input().split())) def I(): return int(eval(input())) n = I() x = [];y=[];h=[] sh = -1 for i in range(n): xa,ya,ha = readInts() x.append(xa);y.append(ya);h.append(ha); if ha > 0: sh = i # CxとCyを特定しておく すべてにおいて合致するかを考える resx = -1;resy =-1;resh=-1; for Cx in range(101): for Cy in range(101): ok = True H = h[sh] + abs(x[sh] - Cx) + abs(y[sh] - Cy) # 全操作して合致するようにする for i in range(n): if h[i] == 0: if H > abs(x[i] - Cx) + abs(y[i] - Cy): ok = False break elif h[i] > 0: if H -h[i] != abs(x[i] - Cx) + abs(y[i] - Cy): ok = False break if ok: resx = Cx;resy = Cy;resh = H; print((resx,resy,resh))
56
54
1,416
1,360
from statistics import median # import collections # aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0] from fractions import gcd from itertools import combinations # (string,3) 3回 from collections import deque from collections import defaultdict import bisect # # d = m - k[i] - k[j] # if kk[bisect.bisect_right(kk,d) - 1] == d: # # # # pythonで無理なときは、pypyでやると正解するかも!! # # import sys sys.setrecursionlimit(10000000) mod = 10**9 + 7 def readInts(): return list(map(int, input().split())) def main(): n = int(eval(input())) vx = [] vy = [] vh = [] for i in range(n): x, y, h = readInts() vx.append(x) vy.append(y) vh.append(h) if h > 0: si = i # 基準となる座標はどこでもいい # けど、h = 0 のところはだめやねん # resx, resy, resh = -1, -1, -1 for x in range(101): for y in range(101): h = vh[si] + abs(x - vx[si]) + abs(y - vy[si]) ok = True for i in range(n): if vh[i] > 0 and h - vh[i] != abs(x - vx[i]) + abs(y - vy[i]): ok = False if vh[i] == 0 and h > abs(x - vx[i]) + abs(y - vy[i]): ok = False if ok: resx = x resy = y resh = h print((resx, resy, resh)) if __name__ == "__main__": main()
from statistics import median # import collections # aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0] from fractions import gcd from itertools import combinations # (string,3) 3回 from collections import deque from collections import defaultdict import bisect # # d = m - k[i] - k[j] # if kk[bisect.bisect_right(kk,d) - 1] == d: # # # # pythonで無理なときは、pypyでやると正解するかも!! # # import sys sys.setrecursionlimit(10000000) mod = 10**9 + 7 def readInts(): return list(map(int, input().split())) def I(): return int(eval(input())) n = I() x = [] y = [] h = [] sh = -1 for i in range(n): xa, ya, ha = readInts() x.append(xa) y.append(ya) h.append(ha) if ha > 0: sh = i # CxとCyを特定しておく すべてにおいて合致するかを考える resx = -1 resy = -1 resh = -1 for Cx in range(101): for Cy in range(101): ok = True H = h[sh] + abs(x[sh] - Cx) + abs(y[sh] - Cy) # 全操作して合致するようにする for i in range(n): if h[i] == 0: if H > abs(x[i] - Cx) + abs(y[i] - Cy): ok = False break elif h[i] > 0: if H - h[i] != abs(x[i] - Cx) + abs(y[i] - Cy): ok = False break if ok: resx = Cx resy = Cy resh = H print((resx, resy, resh))
false
3.571429
[ "-def main():", "- n = int(eval(input()))", "- vx = []", "- vy = []", "- vh = []", "- for i in range(n):", "- x, y, h = readInts()", "- vx.append(x)", "- vy.append(y)", "- vh.append(h)", "- if h > 0:", "- si = i", "- # 基準となる座標はどこでもいい", "- # けど、h = 0 のところはだめやねん", "- #", "- resx, resy, resh = -1, -1, -1", "- for x in range(101):", "- for y in range(101):", "- h = vh[si] + abs(x - vx[si]) + abs(y - vy[si])", "- ok = True", "- for i in range(n):", "- if vh[i] > 0 and h - vh[i] != abs(x - vx[i]) + abs(y - vy[i]):", "- ok = False", "- if vh[i] == 0 and h > abs(x - vx[i]) + abs(y - vy[i]):", "- ok = False", "- if ok:", "- resx = x", "- resy = y", "- resh = h", "- print((resx, resy, resh))", "+def I():", "+ return int(eval(input()))", "-if __name__ == \"__main__\":", "- main()", "+n = I()", "+x = []", "+y = []", "+h = []", "+sh = -1", "+for i in range(n):", "+ xa, ya, ha = readInts()", "+ x.append(xa)", "+ y.append(ya)", "+ h.append(ha)", "+ if ha > 0:", "+ sh = i", "+# CxとCyを特定しておく すべてにおいて合致するかを考える", "+resx = -1", "+resy = -1", "+resh = -1", "+for Cx in range(101):", "+ for Cy in range(101):", "+ ok = True", "+ H = h[sh] + abs(x[sh] - Cx) + abs(y[sh] - Cy)", "+ # 全操作して合致するようにする", "+ for i in range(n):", "+ if h[i] == 0:", "+ if H > abs(x[i] - Cx) + abs(y[i] - Cy):", "+ ok = False", "+ break", "+ elif h[i] > 0:", "+ if H - h[i] != abs(x[i] - Cx) + abs(y[i] - Cy):", "+ ok = False", "+ break", "+ if ok:", "+ resx = Cx", "+ resy = Cy", "+ resh = H", "+print((resx, resy, resh))" ]
false
0.302139
0.075444
4.004832
[ "s953557710", "s539147230" ]
u197615397
p02346
python
s558546968
s271569113
3,380
3,110
19,168
18,592
Accepted
Accepted
7.99
import math import functools class SegmentTree: def __init__(self, a: list, default: int, op): real_size = len(a) self.elem_size = 1 << int(math.ceil(math.log2(real_size))) # honto ha int() iranai self.tree_size = 2 * self.elem_size + 1 self.tree = [default] * (self.elem_size - 1) + a + [default] * (self.elem_size - real_size) self.operation = op def get_range_index(self, x, y, k=0, l_end=0, r_end=None): if r_end is None: r_end = self.elem_size if l_end == x and y == r_end-1: return [k] elif not l_end <= x <= y < r_end: return [] mid = (l_end + r_end) // 2 left_y = y if y < mid-1 else mid-1 right_x = x if x > mid else mid left = self.get_range_index(x, left_y, 2*k+1, l_end, mid) right = self.get_range_index(right_x, y, 2*k+2, mid, r_end) return left + right def get_value(self, x, y): tree = self.tree index_list = self.get_range_index(x, y) op = self.operation return functools.reduce(op, (tree[n] for n in index_list)) def update_tree(self, k: int): op = self.operation tree = self.tree while k > 0: k = (k-1) // 2 left, right = tree[2*k+1], tree[2*k+2] tree[k] = op(left, right) def set_value(self, i: int, value: int, op: str): k = self.elem_size - 1 + i if op == "=": self.tree[k] = value elif op == "+": self.tree[k] += value self.update_tree(k) n, q = list(map(int, input().split())) rsq = SegmentTree([0]*n, 0, lambda x, y: x+y) ans = [] for _ in [0]*q: c, x, y = list(map(int, input().split())) if c == 0: rsq.set_value(x-1, y, "+") else: ans.append(rsq.get_value(x-1, y-1)) print(("\n".join([str(n) for n in ans])))
import math class SegmentTree: __slots__ = ["elem_size", "tree_size", "tree"] def __init__(self, a: list, default: int): real_size = len(a) self.elem_size = 1 << math.ceil(math.log2(real_size)) self.tree_size = 2 * self.elem_size + 1 self.tree = [default] * (self.elem_size - 1) + a + [default] * (self.elem_size - real_size) def get_range_index(self, x, y, k=0, l_end=0, r_end=None): '''[x, y], tree[k], [l_end, r_end)''' if r_end is None: r_end = self.elem_size if l_end == x and y == r_end-1: return [k] elif not l_end <= x <= y < r_end: return [] mid = (l_end + r_end) // 2 left_y = y if y < mid-1 else mid-1 right_x = x if x > mid else mid left = self.get_range_index(x, left_y, 2*k+1, l_end, mid) right = self.get_range_index(right_x, y, 2*k+2, mid, r_end) return left + right def get_value(self, x, y): tree = self.tree index_list = self.get_range_index(x, y) return sum(tree[n] for n in index_list) def update_tree(self, k: int): tree = self.tree while k > 0: k = (k-1) // 2 left, right = tree[2*k+1], tree[2*k+2] tree[k] = left + right def set_value(self, i: int, value: int, op: str): k = self.elem_size - 1 + i if op == "=": self.tree[k] = value elif op == "+": self.tree[k] += value self.update_tree(k) n, q = list(map(int, input().split())) rsq = SegmentTree([0]*n, 0) ans = [] for _ in [0]*q: c, x, y = list(map(int, input().split())) if c == 0: rsq.set_value(x-1, y, "+") else: ans.append(rsq.get_value(x-1, y-1)) print(("\n".join([str(n) for n in ans])))
63
63
1,940
1,864
import math import functools class SegmentTree: def __init__(self, a: list, default: int, op): real_size = len(a) self.elem_size = 1 << int( math.ceil(math.log2(real_size)) ) # honto ha int() iranai self.tree_size = 2 * self.elem_size + 1 self.tree = ( [default] * (self.elem_size - 1) + a + [default] * (self.elem_size - real_size) ) self.operation = op def get_range_index(self, x, y, k=0, l_end=0, r_end=None): if r_end is None: r_end = self.elem_size if l_end == x and y == r_end - 1: return [k] elif not l_end <= x <= y < r_end: return [] mid = (l_end + r_end) // 2 left_y = y if y < mid - 1 else mid - 1 right_x = x if x > mid else mid left = self.get_range_index(x, left_y, 2 * k + 1, l_end, mid) right = self.get_range_index(right_x, y, 2 * k + 2, mid, r_end) return left + right def get_value(self, x, y): tree = self.tree index_list = self.get_range_index(x, y) op = self.operation return functools.reduce(op, (tree[n] for n in index_list)) def update_tree(self, k: int): op = self.operation tree = self.tree while k > 0: k = (k - 1) // 2 left, right = tree[2 * k + 1], tree[2 * k + 2] tree[k] = op(left, right) def set_value(self, i: int, value: int, op: str): k = self.elem_size - 1 + i if op == "=": self.tree[k] = value elif op == "+": self.tree[k] += value self.update_tree(k) n, q = list(map(int, input().split())) rsq = SegmentTree([0] * n, 0, lambda x, y: x + y) ans = [] for _ in [0] * q: c, x, y = list(map(int, input().split())) if c == 0: rsq.set_value(x - 1, y, "+") else: ans.append(rsq.get_value(x - 1, y - 1)) print(("\n".join([str(n) for n in ans])))
import math class SegmentTree: __slots__ = ["elem_size", "tree_size", "tree"] def __init__(self, a: list, default: int): real_size = len(a) self.elem_size = 1 << math.ceil(math.log2(real_size)) self.tree_size = 2 * self.elem_size + 1 self.tree = ( [default] * (self.elem_size - 1) + a + [default] * (self.elem_size - real_size) ) def get_range_index(self, x, y, k=0, l_end=0, r_end=None): """[x, y], tree[k], [l_end, r_end)""" if r_end is None: r_end = self.elem_size if l_end == x and y == r_end - 1: return [k] elif not l_end <= x <= y < r_end: return [] mid = (l_end + r_end) // 2 left_y = y if y < mid - 1 else mid - 1 right_x = x if x > mid else mid left = self.get_range_index(x, left_y, 2 * k + 1, l_end, mid) right = self.get_range_index(right_x, y, 2 * k + 2, mid, r_end) return left + right def get_value(self, x, y): tree = self.tree index_list = self.get_range_index(x, y) return sum(tree[n] for n in index_list) def update_tree(self, k: int): tree = self.tree while k > 0: k = (k - 1) // 2 left, right = tree[2 * k + 1], tree[2 * k + 2] tree[k] = left + right def set_value(self, i: int, value: int, op: str): k = self.elem_size - 1 + i if op == "=": self.tree[k] = value elif op == "+": self.tree[k] += value self.update_tree(k) n, q = list(map(int, input().split())) rsq = SegmentTree([0] * n, 0) ans = [] for _ in [0] * q: c, x, y = list(map(int, input().split())) if c == 0: rsq.set_value(x - 1, y, "+") else: ans.append(rsq.get_value(x - 1, y - 1)) print(("\n".join([str(n) for n in ans])))
false
0
[ "-import functools", "- def __init__(self, a: list, default: int, op):", "+ __slots__ = [\"elem_size\", \"tree_size\", \"tree\"]", "+", "+ def __init__(self, a: list, default: int):", "- self.elem_size = 1 << int(", "- math.ceil(math.log2(real_size))", "- ) # honto ha int() iranai", "+ self.elem_size = 1 << math.ceil(math.log2(real_size))", "- self.operation = op", "+ \"\"\"[x, y], tree[k], [l_end, r_end)\"\"\"", "- op = self.operation", "- return functools.reduce(op, (tree[n] for n in index_list))", "+ return sum(tree[n] for n in index_list)", "- op = self.operation", "- tree[k] = op(left, right)", "+ tree[k] = left + right", "-rsq = SegmentTree([0] * n, 0, lambda x, y: x + y)", "+rsq = SegmentTree([0] * n, 0)" ]
false
0.040007
0.118077
0.338826
[ "s558546968", "s271569113" ]
u754022296
p03061
python
s761419984
s852597128
1,677
614
16,168
87,272
Accepted
Accepted
63.39
class Segtree: def __init__(self, original, func, element): self.n = len(original) self.element = element self.func = func self.N0 = 1 << (n-1).bit_length() self.seg = [element]*(self.N0 << 1) for i, j in enumerate(original, self.N0): self.seg[i] = j for i in range(self.N0-1, 0, -1): self.seg[i] = func(self.seg[2*i], self.seg[2*i+1]) def get(self, i): return self.seg[i+self.N0] def update(self, i, x): i += self.N0 self.seg[i] = x while i > 1: y = self.seg[i ^ 1] if y <= x: break i >>= 1 x = self.func(x, y) self.seg[i] = x def query(self, l, r): res = self.element l += self.N0 r += self.N0 while l < r: if r & 1: res = self.func(res, self.seg[r-1]) if l & 1: res = self.func(res, self.seg[l]) l += 1 l >>= 1 r >>= 1 return res import sys input = sys.stdin.readline from fractions import gcd n = int(eval(input())) A = list(map(int, input().split())) seg = Segtree(A, gcd, 0) ans = 0 for i in range(n): left = seg.query(0, i) right = seg.query(i+1, n) temp = gcd(left, right) ans = max(ans, temp) print(ans)
class Segtree: def __init__(self, original, func, element): self.n = len(original) self.element = element self.func = func self.N0 = 1 << (n-1).bit_length() self.seg = [element]*(self.N0 << 1) for i, j in enumerate(original, self.N0): self.seg[i] = j for i in range(self.N0-1, 0, -1): self.seg[i] = func(self.seg[2*i], self.seg[2*i+1]) def get(self, i): return self.seg[i+self.N0] def update(self, i, x): i += self.N0 self.seg[i] = x while i > 1: y = self.seg[i ^ 1] i >>= 1 x = self.func(x, y) self.seg[i] = x def query(self, l, r): res = self.element l += self.N0 r += self.N0 while l < r: if r & 1: res = self.func(res, self.seg[r-1]) if l & 1: res = self.func(res, self.seg[l]) l += 1 l >>= 1 r >>= 1 return res import sys input = sys.stdin.readline from fractions import gcd n = int(eval(input())) A = list(map(int, input().split())) seg = Segtree(A, gcd, 0) ans = 0 for i in range(n): left = seg.query(0, i) right = seg.query(i+1, n) temp = gcd(left, right) ans = max(ans, temp) print(ans)
55
53
1,445
1,400
class Segtree: def __init__(self, original, func, element): self.n = len(original) self.element = element self.func = func self.N0 = 1 << (n - 1).bit_length() self.seg = [element] * (self.N0 << 1) for i, j in enumerate(original, self.N0): self.seg[i] = j for i in range(self.N0 - 1, 0, -1): self.seg[i] = func(self.seg[2 * i], self.seg[2 * i + 1]) def get(self, i): return self.seg[i + self.N0] def update(self, i, x): i += self.N0 self.seg[i] = x while i > 1: y = self.seg[i ^ 1] if y <= x: break i >>= 1 x = self.func(x, y) self.seg[i] = x def query(self, l, r): res = self.element l += self.N0 r += self.N0 while l < r: if r & 1: res = self.func(res, self.seg[r - 1]) if l & 1: res = self.func(res, self.seg[l]) l += 1 l >>= 1 r >>= 1 return res import sys input = sys.stdin.readline from fractions import gcd n = int(eval(input())) A = list(map(int, input().split())) seg = Segtree(A, gcd, 0) ans = 0 for i in range(n): left = seg.query(0, i) right = seg.query(i + 1, n) temp = gcd(left, right) ans = max(ans, temp) print(ans)
class Segtree: def __init__(self, original, func, element): self.n = len(original) self.element = element self.func = func self.N0 = 1 << (n - 1).bit_length() self.seg = [element] * (self.N0 << 1) for i, j in enumerate(original, self.N0): self.seg[i] = j for i in range(self.N0 - 1, 0, -1): self.seg[i] = func(self.seg[2 * i], self.seg[2 * i + 1]) def get(self, i): return self.seg[i + self.N0] def update(self, i, x): i += self.N0 self.seg[i] = x while i > 1: y = self.seg[i ^ 1] i >>= 1 x = self.func(x, y) self.seg[i] = x def query(self, l, r): res = self.element l += self.N0 r += self.N0 while l < r: if r & 1: res = self.func(res, self.seg[r - 1]) if l & 1: res = self.func(res, self.seg[l]) l += 1 l >>= 1 r >>= 1 return res import sys input = sys.stdin.readline from fractions import gcd n = int(eval(input())) A = list(map(int, input().split())) seg = Segtree(A, gcd, 0) ans = 0 for i in range(n): left = seg.query(0, i) right = seg.query(i + 1, n) temp = gcd(left, right) ans = max(ans, temp) print(ans)
false
3.636364
[ "- if y <= x:", "- break" ]
false
0.125694
0.048723
2.579791
[ "s761419984", "s852597128" ]
u072053884
p00449
python
s397610814
s803661173
4,090
950
6,204
6,240
Accepted
Accepted
76.77
def solve(): max_fare = 99000001 def dijkstra(start, goal): unvisited = [i for i in range(n)] fare = [max_fare] * n fare[start] = 0 while True: min_fare = max_fare for i in unvisited: f = fare[i] if f < min_fare: min_fare = f u = i if u == goal: return min_fare elif min_fare == max_fare: return -1 unvisited.remove(u) for v, f in adj[u]: if v in unvisited: fare[v] = min(min_fare + f, fare[v]) import sys file_input = sys.stdin while True: n, k = list(map(int, file_input.readline().split())) if n == 0 and k == 0: break adj = [[] for i in range(n)] for i in range(k): line = file_input.readline() if line[0] == '0': a, b = list(map(int, line[2:].split())) print((dijkstra(a - 1, b - 1))) else: c, d, e = list(map(int, line[2:].split())) adj[c - 1].append((d - 1, e)) adj[d - 1].append((c - 1, e)) solve()
def solve(): from heapq import heappush, heappop def dijkstra(start, goal): fare = [99000001] * n fare[start] = 0 pq = [(0, start)] while pq: u_fare, u = heappop(pq) if u == goal: return u_fare for f, v in adj[u]: new_fare = u_fare + f if new_fare < fare[v]: fare[v] = new_fare heappush(pq, (new_fare, v)) return -1 import sys file_input = sys.stdin while True: n, k = list(map(int, file_input.readline().split())) if n == 0 and k == 0: break adj = [[] for i in range(n)] for i in range(k): line = file_input.readline() if line[0] == '0': a, b = list(map(int, line[2:].split())) print((dijkstra(a - 1, b - 1))) else: c, d, e = list(map(int, line[2:].split())) adj[c - 1].append((e, d - 1)) adj[d - 1].append((e, c - 1)) solve()
47
41
1,346
1,168
def solve(): max_fare = 99000001 def dijkstra(start, goal): unvisited = [i for i in range(n)] fare = [max_fare] * n fare[start] = 0 while True: min_fare = max_fare for i in unvisited: f = fare[i] if f < min_fare: min_fare = f u = i if u == goal: return min_fare elif min_fare == max_fare: return -1 unvisited.remove(u) for v, f in adj[u]: if v in unvisited: fare[v] = min(min_fare + f, fare[v]) import sys file_input = sys.stdin while True: n, k = list(map(int, file_input.readline().split())) if n == 0 and k == 0: break adj = [[] for i in range(n)] for i in range(k): line = file_input.readline() if line[0] == "0": a, b = list(map(int, line[2:].split())) print((dijkstra(a - 1, b - 1))) else: c, d, e = list(map(int, line[2:].split())) adj[c - 1].append((d - 1, e)) adj[d - 1].append((c - 1, e)) solve()
def solve(): from heapq import heappush, heappop def dijkstra(start, goal): fare = [99000001] * n fare[start] = 0 pq = [(0, start)] while pq: u_fare, u = heappop(pq) if u == goal: return u_fare for f, v in adj[u]: new_fare = u_fare + f if new_fare < fare[v]: fare[v] = new_fare heappush(pq, (new_fare, v)) return -1 import sys file_input = sys.stdin while True: n, k = list(map(int, file_input.readline().split())) if n == 0 and k == 0: break adj = [[] for i in range(n)] for i in range(k): line = file_input.readline() if line[0] == "0": a, b = list(map(int, line[2:].split())) print((dijkstra(a - 1, b - 1))) else: c, d, e = list(map(int, line[2:].split())) adj[c - 1].append((e, d - 1)) adj[d - 1].append((e, c - 1)) solve()
false
12.765957
[ "- max_fare = 99000001", "+ from heapq import heappush, heappop", "- unvisited = [i for i in range(n)]", "- fare = [max_fare] * n", "+ fare = [99000001] * n", "- while True:", "- min_fare = max_fare", "- for i in unvisited:", "- f = fare[i]", "- if f < min_fare:", "- min_fare = f", "- u = i", "+ pq = [(0, start)]", "+ while pq:", "+ u_fare, u = heappop(pq)", "- return min_fare", "- elif min_fare == max_fare:", "- return -1", "- unvisited.remove(u)", "- for v, f in adj[u]:", "- if v in unvisited:", "- fare[v] = min(min_fare + f, fare[v])", "+ return u_fare", "+ for f, v in adj[u]:", "+ new_fare = u_fare + f", "+ if new_fare < fare[v]:", "+ fare[v] = new_fare", "+ heappush(pq, (new_fare, v))", "+ return -1", "- adj[c - 1].append((d - 1, e))", "- adj[d - 1].append((c - 1, e))", "+ adj[c - 1].append((e, d - 1))", "+ adj[d - 1].append((e, c - 1))" ]
false
0.044912
0.041604
1.079501
[ "s397610814", "s803661173" ]
u537782349
p03262
python
s578800618
s046990819
132
109
14,224
14,224
Accepted
Accepted
17.42
def g_c_d(x, y): if x == 0: return y elif y == 0: return x else: return g_c_d(y, x%y) a, b = list(map(int, input().split())) c = list(map(int, input().split())) c.append(b) c.sort() d = 0 for i in range(1, a + 1): d = g_c_d(c[i] - c[i-1], d) print(d)
def g_c_d(x, y): if x == 0: return y elif y == 0: return x else: return g_c_d(y, x % y) a, b = list(map(int, input().split())) c = list(map(int, input().split())) c.append(b) d = 0 for i in range(len(c)): d = g_c_d(d, abs((c[i] - c[i-1]))) print(d)
17
16
303
300
def g_c_d(x, y): if x == 0: return y elif y == 0: return x else: return g_c_d(y, x % y) a, b = list(map(int, input().split())) c = list(map(int, input().split())) c.append(b) c.sort() d = 0 for i in range(1, a + 1): d = g_c_d(c[i] - c[i - 1], d) print(d)
def g_c_d(x, y): if x == 0: return y elif y == 0: return x else: return g_c_d(y, x % y) a, b = list(map(int, input().split())) c = list(map(int, input().split())) c.append(b) d = 0 for i in range(len(c)): d = g_c_d(d, abs((c[i] - c[i - 1]))) print(d)
false
5.882353
[ "-c.sort()", "-for i in range(1, a + 1):", "- d = g_c_d(c[i] - c[i - 1], d)", "+for i in range(len(c)):", "+ d = g_c_d(d, abs((c[i] - c[i - 1])))" ]
false
0.040461
0.040422
1.00096
[ "s578800618", "s046990819" ]
u133936772
p02887
python
s187051172
s591316323
54
39
15,988
3,316
Accepted
Accepted
27.78
f=input;f() import itertools as it print((len(list(it.groupby(f())))))
f=input;n=int(f());s=f() print((1+sum(s[i]!=s[i-1] for i in range(1,n))))
3
2
70
72
f = input f() import itertools as it print((len(list(it.groupby(f())))))
f = input n = int(f()) s = f() print((1 + sum(s[i] != s[i - 1] for i in range(1, n))))
false
33.333333
[ "-f()", "-import itertools as it", "-", "-print((len(list(it.groupby(f())))))", "+n = int(f())", "+s = f()", "+print((1 + sum(s[i] != s[i - 1] for i in range(1, n))))" ]
false
0.036417
0.03662
0.994465
[ "s187051172", "s591316323" ]
u121161758
p02934
python
s519075990
s306328791
20
17
3,064
3,060
Accepted
Accepted
15
n = int(eval(input())) list = list(map(int,input().split())) product_list = [1]*n for i in range(len(list)): for j in range(len(list)): if i != j : product_list[i] *= list[j] product_sum = 0 for i in range(len(list)): product_sum += product_list[i] total_product = product_list[0] * list[0] print(( total_product / product_sum))
n = int(eval(input())) list = list(map(int,input().split())) div_list = [0] * n for i in range(len(list)): div_list[i] = 1 / list[i] sum = 0 for i in range(len(list)): sum += div_list[i] print(( 1 / sum ))
17
13
359
221
n = int(eval(input())) list = list(map(int, input().split())) product_list = [1] * n for i in range(len(list)): for j in range(len(list)): if i != j: product_list[i] *= list[j] product_sum = 0 for i in range(len(list)): product_sum += product_list[i] total_product = product_list[0] * list[0] print((total_product / product_sum))
n = int(eval(input())) list = list(map(int, input().split())) div_list = [0] * n for i in range(len(list)): div_list[i] = 1 / list[i] sum = 0 for i in range(len(list)): sum += div_list[i] print((1 / sum))
false
23.529412
[ "-product_list = [1] * n", "+div_list = [0] * n", "- for j in range(len(list)):", "- if i != j:", "- product_list[i] *= list[j]", "-product_sum = 0", "+ div_list[i] = 1 / list[i]", "+sum = 0", "- product_sum += product_list[i]", "-total_product = product_list[0] * list[0]", "-print((total_product / product_sum))", "+ sum += div_list[i]", "+print((1 / sum))" ]
false
0.036311
0.036992
0.981594
[ "s519075990", "s306328791" ]
u690536347
p02991
python
s822590102
s169617197
1,115
1,016
125,144
120,288
Accepted
Accepted
8.88
from collections import defaultdict, deque from heapq import heappush, heappop def bfs(V, s, t): q = deque([(0, s)]) used = set() while q: dist, a = q.popleft() used.add(a) if a == t: break for b in V[a]: if b in used: continue q.append((dist+1, b)) if a != t: dist = -1 else: dist = -1 if dist%3 else dist//3 return dist def dijkstra1(V, n, source): # O(ElogV) inf = float("inf") dist = [inf] * (n+1) dist[source] = 0 q = [(0, source)] while q: cost, u = heappop(q) if dist[u] < cost: continue for c, v in V[u]: if dist[v] > dist[u] + c: dist[v] = dist[u] + c heappush(q, (dist[v], v)) return dist if __name__ == "__main__": V = defaultdict(list) N, M = list(map(int, input().split())) for _ in range(M): u, v = list(map(int, input().split())) V[u].append((1, v+(N))) V[u+(N)].append((1, v+(2*N))) V[u+(2*N)].append((1, v)) S, T = list(map(int, input().split())) dist = dijkstra1(V, 3*N, S)[T] print((-1 if dist==float("inf") else dist//3))
from heapq import heappush, heappop def dijkstra1(V, n, source): # O(ElogV) inf = float("inf") dist = [inf] * (n+1) dist[source] = 0 q = [(0, source)] while q: cost, u = heappop(q) if dist[u] < cost: continue for c, v in V[u]: if dist[v] > dist[u] + c: dist[v] = dist[u] + c heappush(q, (dist[v], v)) return dist if __name__ == "__main__": N, M = list(map(int, input().split())) V = {i:[] for i in range(1, 3*N+1)} for _ in range(M): u, v = list(map(int, input().split())) V[u].append((1, v+(N))) V[u+(N)].append((1, v+(2*N))) V[u+(2*N)].append((1, v)) S, T = list(map(int, input().split())) dist = dijkstra1(V, 3*N, S)[T] print((-1 if dist==float("inf") else dist//3))
55
34
1,266
853
from collections import defaultdict, deque from heapq import heappush, heappop def bfs(V, s, t): q = deque([(0, s)]) used = set() while q: dist, a = q.popleft() used.add(a) if a == t: break for b in V[a]: if b in used: continue q.append((dist + 1, b)) if a != t: dist = -1 else: dist = -1 if dist % 3 else dist // 3 return dist def dijkstra1(V, n, source): # O(ElogV) inf = float("inf") dist = [inf] * (n + 1) dist[source] = 0 q = [(0, source)] while q: cost, u = heappop(q) if dist[u] < cost: continue for c, v in V[u]: if dist[v] > dist[u] + c: dist[v] = dist[u] + c heappush(q, (dist[v], v)) return dist if __name__ == "__main__": V = defaultdict(list) N, M = list(map(int, input().split())) for _ in range(M): u, v = list(map(int, input().split())) V[u].append((1, v + (N))) V[u + (N)].append((1, v + (2 * N))) V[u + (2 * N)].append((1, v)) S, T = list(map(int, input().split())) dist = dijkstra1(V, 3 * N, S)[T] print((-1 if dist == float("inf") else dist // 3))
from heapq import heappush, heappop def dijkstra1(V, n, source): # O(ElogV) inf = float("inf") dist = [inf] * (n + 1) dist[source] = 0 q = [(0, source)] while q: cost, u = heappop(q) if dist[u] < cost: continue for c, v in V[u]: if dist[v] > dist[u] + c: dist[v] = dist[u] + c heappush(q, (dist[v], v)) return dist if __name__ == "__main__": N, M = list(map(int, input().split())) V = {i: [] for i in range(1, 3 * N + 1)} for _ in range(M): u, v = list(map(int, input().split())) V[u].append((1, v + (N))) V[u + (N)].append((1, v + (2 * N))) V[u + (2 * N)].append((1, v)) S, T = list(map(int, input().split())) dist = dijkstra1(V, 3 * N, S)[T] print((-1 if dist == float("inf") else dist // 3))
false
38.181818
[ "-from collections import defaultdict, deque", "-", "-", "-def bfs(V, s, t):", "- q = deque([(0, s)])", "- used = set()", "- while q:", "- dist, a = q.popleft()", "- used.add(a)", "- if a == t:", "- break", "- for b in V[a]:", "- if b in used:", "- continue", "- q.append((dist + 1, b))", "- if a != t:", "- dist = -1", "- else:", "- dist = -1 if dist % 3 else dist // 3", "- return dist", "- V = defaultdict(list)", "+ V = {i: [] for i in range(1, 3 * N + 1)}" ]
false
0.040278
0.044965
0.895745
[ "s822590102", "s169617197" ]
u332385682
p03716
python
s498446766
s688849259
674
402
119,840
37,212
Accepted
Accepted
40.36
import sys from heapq import heapify, heappush, heappop from itertools import accumulate inf = 1<<100 def solve(): N = int(eval(input())) a = [int(i) for i in input().split()] ps = [0] + list(accumulate(a)) psmin = [0] * (N + 1) minhp = a[:N] heapify(minhp) for i in range(1, N + 1): heappush(minhp, a[N - 1 + i]) x = heappop(minhp) psmin[i] = psmin[i - 1] + x psmax = [0] * (N + 1) maxhp = [-ai for ai in a[2*N:]] heapify(maxhp) for i in range(1, N + 1): heappush(maxhp, -a[2*N - i]) x = -heappop(maxhp) psmax[i] = psmax[i - 1] + x # print(psmin) # print(psmax) ans = -inf for i in range(0, N + 1): # print(ps[N + i], psmin[i], ps[3*N] - ps[N + i], psmax[N - i]) v = (ps[N + i] - psmin[i]) - (ps[3*N] - ps[N + i] - psmax[N - i]) ans = max(ans, v) print(ans) pass if __name__ == '__main__': solve()
import sys from heapq import heapify, heappush, heappop inf = 1<<60 def solve(): n = int(eval(input())) a = [int(i) for i in input().split()] ps = [sum(a[:n])] minhp = a[:n] heapify(minhp) for i in range(n): heappush(minhp, a[n + i]) x = heappop(minhp) ps.append(ps[-1] + a[n + i] - x) ss = [sum(a[2*n:])] maxhp = [-ai for ai in a[2*n:]] heapify(maxhp) for i in range(n): heappush(maxhp, -a[2*n - 1 - i]) x = -heappop(maxhp) ss.append(ss[-1] + a[2*n - 1 - i] - x) ans = -inf for i in range(n + 1): ans = max(ans, ps[i] - ss[n - i]) print(ans) if __name__ == '__main__': solve()
44
36
990
730
import sys from heapq import heapify, heappush, heappop from itertools import accumulate inf = 1 << 100 def solve(): N = int(eval(input())) a = [int(i) for i in input().split()] ps = [0] + list(accumulate(a)) psmin = [0] * (N + 1) minhp = a[:N] heapify(minhp) for i in range(1, N + 1): heappush(minhp, a[N - 1 + i]) x = heappop(minhp) psmin[i] = psmin[i - 1] + x psmax = [0] * (N + 1) maxhp = [-ai for ai in a[2 * N :]] heapify(maxhp) for i in range(1, N + 1): heappush(maxhp, -a[2 * N - i]) x = -heappop(maxhp) psmax[i] = psmax[i - 1] + x # print(psmin) # print(psmax) ans = -inf for i in range(0, N + 1): # print(ps[N + i], psmin[i], ps[3*N] - ps[N + i], psmax[N - i]) v = (ps[N + i] - psmin[i]) - (ps[3 * N] - ps[N + i] - psmax[N - i]) ans = max(ans, v) print(ans) pass if __name__ == "__main__": solve()
import sys from heapq import heapify, heappush, heappop inf = 1 << 60 def solve(): n = int(eval(input())) a = [int(i) for i in input().split()] ps = [sum(a[:n])] minhp = a[:n] heapify(minhp) for i in range(n): heappush(minhp, a[n + i]) x = heappop(minhp) ps.append(ps[-1] + a[n + i] - x) ss = [sum(a[2 * n :])] maxhp = [-ai for ai in a[2 * n :]] heapify(maxhp) for i in range(n): heappush(maxhp, -a[2 * n - 1 - i]) x = -heappop(maxhp) ss.append(ss[-1] + a[2 * n - 1 - i] - x) ans = -inf for i in range(n + 1): ans = max(ans, ps[i] - ss[n - i]) print(ans) if __name__ == "__main__": solve()
false
18.181818
[ "-from itertools import accumulate", "-inf = 1 << 100", "+inf = 1 << 60", "- N = int(eval(input()))", "+ n = int(eval(input()))", "- ps = [0] + list(accumulate(a))", "- psmin = [0] * (N + 1)", "- minhp = a[:N]", "+ ps = [sum(a[:n])]", "+ minhp = a[:n]", "- for i in range(1, N + 1):", "- heappush(minhp, a[N - 1 + i])", "+ for i in range(n):", "+ heappush(minhp, a[n + i])", "- psmin[i] = psmin[i - 1] + x", "- psmax = [0] * (N + 1)", "- maxhp = [-ai for ai in a[2 * N :]]", "+ ps.append(ps[-1] + a[n + i] - x)", "+ ss = [sum(a[2 * n :])]", "+ maxhp = [-ai for ai in a[2 * n :]]", "- for i in range(1, N + 1):", "- heappush(maxhp, -a[2 * N - i])", "+ for i in range(n):", "+ heappush(maxhp, -a[2 * n - 1 - i])", "- psmax[i] = psmax[i - 1] + x", "- # print(psmin)", "- # print(psmax)", "+ ss.append(ss[-1] + a[2 * n - 1 - i] - x)", "- for i in range(0, N + 1):", "- # print(ps[N + i], psmin[i], ps[3*N] - ps[N + i], psmax[N - i])", "- v = (ps[N + i] - psmin[i]) - (ps[3 * N] - ps[N + i] - psmax[N - i])", "- ans = max(ans, v)", "+ for i in range(n + 1):", "+ ans = max(ans, ps[i] - ss[n - i])", "- pass" ]
false
0.04488
0.046514
0.964885
[ "s498446766", "s688849259" ]
u931005464
p03167
python
s405998676
s610207536
750
656
52,548
52,572
Accepted
Accepted
12.53
h, w = list(map(int, input().split())) mat = [] dp = [] m = 10**9+7 for i in range(h): mat.append(list(eval(input()))) dp.append(list([0]*w)) dp[0][0] = 1 for x in range(h): for y in range(w): if x != 0 or y != 0: if mat[x][y] == "#": dp[x][y] = 0 else: dp[x][y] += (dp[x - 1][y] + dp[x][y - 1]) % m print((dp[h - 1][w - 1]))
h, w = list(map(int, input().split())) mat = [] dp = [] m = 10**9+7 for i in range(h): mat.append(list(eval(input()))) dp.append(list([0]*w)) dp[0][0] = 1 for x in range(h): for y in range(w): if x != 0 or y != 0: if mat[x][y] == "#": dp[x][y] = 0 else: dp[x][y] = (dp[x - 1][y] + dp[x][y - 1]) % m print((dp[h - 1][w - 1]))
25
25
421
420
h, w = list(map(int, input().split())) mat = [] dp = [] m = 10**9 + 7 for i in range(h): mat.append(list(eval(input()))) dp.append(list([0] * w)) dp[0][0] = 1 for x in range(h): for y in range(w): if x != 0 or y != 0: if mat[x][y] == "#": dp[x][y] = 0 else: dp[x][y] += (dp[x - 1][y] + dp[x][y - 1]) % m print((dp[h - 1][w - 1]))
h, w = list(map(int, input().split())) mat = [] dp = [] m = 10**9 + 7 for i in range(h): mat.append(list(eval(input()))) dp.append(list([0] * w)) dp[0][0] = 1 for x in range(h): for y in range(w): if x != 0 or y != 0: if mat[x][y] == "#": dp[x][y] = 0 else: dp[x][y] = (dp[x - 1][y] + dp[x][y - 1]) % m print((dp[h - 1][w - 1]))
false
0
[ "- dp[x][y] += (dp[x - 1][y] + dp[x][y - 1]) % m", "+ dp[x][y] = (dp[x - 1][y] + dp[x][y - 1]) % m" ]
false
0.040996
0.041615
0.985118
[ "s405998676", "s610207536" ]
u348805958
p02781
python
s645650237
s753797022
69
45
3,428
3,428
Accepted
Accepted
34.78
#!python3 iim = lambda: list(map(int, input().rstrip().split())) def resolve(): N = list(map(int, eval(input()))) K = int(eval(input())) size = len(N) if size < K: print((0)) return dp = [[[0]*(size+1) for j in range(2)] for i in range(size+1)] dp[0][0][0] = 1 for i in range(size): for less in range(2): for k in range(size): for x in range(10 if less else N[i] + 1): #print((i, less, k), x, (i+1, int(less or x < N[i]), k + (1 if x else 0))) dp[i+1][less or x < N[i]][k + (1 if x else 0)] += dp[i][less][k] #print(dp[i+1]) print((dp[-1][0][K] + dp[-1][1][K])) if __name__ == "__main__": resolve()
#!python3 iim = lambda: list(map(int, input().rstrip().split())) def resolve(): N = list(map(int, eval(input()))) K = int(eval(input())) size = len(N) if size < K: print((0)) return dp = [[[0]*(size+1) for j in range(2)] for i in range(size+1)] dp[0][0][0] = 1 for i in range(size): for less in range(2): for k in range(i+1): for x in range(10 if less else N[i] + 1): #print((i, less, k), x, (i+1, int(less or x < N[i]), k + (1 if x else 0))) dp[i+1][less or x < N[i]][k + (1 if x else 0)] += dp[i][less][k] #print(dp[i+1]) print((dp[-1][0][K] + dp[-1][1][K])) if __name__ == "__main__": resolve()
29
29
749
748
#!python3 iim = lambda: list(map(int, input().rstrip().split())) def resolve(): N = list(map(int, eval(input()))) K = int(eval(input())) size = len(N) if size < K: print((0)) return dp = [[[0] * (size + 1) for j in range(2)] for i in range(size + 1)] dp[0][0][0] = 1 for i in range(size): for less in range(2): for k in range(size): for x in range(10 if less else N[i] + 1): # print((i, less, k), x, (i+1, int(less or x < N[i]), k + (1 if x else 0))) dp[i + 1][less or x < N[i]][k + (1 if x else 0)] += dp[i][less][k] # print(dp[i+1]) print((dp[-1][0][K] + dp[-1][1][K])) if __name__ == "__main__": resolve()
#!python3 iim = lambda: list(map(int, input().rstrip().split())) def resolve(): N = list(map(int, eval(input()))) K = int(eval(input())) size = len(N) if size < K: print((0)) return dp = [[[0] * (size + 1) for j in range(2)] for i in range(size + 1)] dp[0][0][0] = 1 for i in range(size): for less in range(2): for k in range(i + 1): for x in range(10 if less else N[i] + 1): # print((i, less, k), x, (i+1, int(less or x < N[i]), k + (1 if x else 0))) dp[i + 1][less or x < N[i]][k + (1 if x else 0)] += dp[i][less][k] # print(dp[i+1]) print((dp[-1][0][K] + dp[-1][1][K])) if __name__ == "__main__": resolve()
false
0
[ "- for k in range(size):", "+ for k in range(i + 1):" ]
false
0.03468
0.035615
0.973749
[ "s645650237", "s753797022" ]
u333945892
p03291
python
s809484543
s233501158
1,432
261
11,428
11,440
Accepted
Accepted
81.77
from collections import defaultdict import sys,heapq,bisect,math,itertools,string,queue,datetime sys.setrecursionlimit(10**8) INF = float('inf') mod = 10**9+7 eps = 10**-7 AtoZ = [chr(i) for i in range(65,65+26)] atoz = [chr(i) for i in range(97,97+26)] def inpl(): return list(map(int, input().split())) def inpl_str(): return list(input().split()) def ex_square(n,k): #n^k if k == 0: ans = 1 elif k % 2 == 0: ans = ex_square(n, k//2) ** 2 else: ans = ex_square(n,k-1) * n ans %= mod return ans S = list(eval(input())) aa = [0] bb = [0] cc = [0] qq = [0] Sa = Sb =Sc = Sq = 0 for s in S: if s == 'A': Sa += 1 elif s == 'B': Sb += 1 elif s == 'C': Sc += 1 elif s == '?': Sq += 1 aa.append(Sa) bb.append(Sb) cc.append(Sc) qq.append(Sq) ans = 0 for i,s in enumerate(S): if s == 'B': SUMq = Sq elif s == '?': SUMq = Sq-1 elif s == 'A' or s == 'C': continue Lq = qq[i] Rq = SUMq-Lq La = aa[i] Rc = Sc - cc[i] if SUMq == 0: ex = 1 exx = exxx = 0 elif SUMq == 1: ex = 3 exx = 1 exxx = 0 else: exxx= ex_square(3,SUMq-2) exx = exxx*3%mod ex = exx*3%mod ans1 = (ex * (La*Rc)%mod)%mod ans2 = (exx * (Lq*Rc)%mod)%mod ans3 = (exx * (La*Rq)%mod)%mod ans4 = (exxx * (Lq*Rq)%mod)%mod ans += (ans1+ans2+ans3+ans4)%mod ans %= mod print(ans)
from collections import defaultdict import sys,heapq,bisect,math,itertools,string,queue,datetime sys.setrecursionlimit(10**8) INF = float('inf') mod = 10**9+7 eps = 10**-7 AtoZ = [chr(i) for i in range(65,65+26)] atoz = [chr(i) for i in range(97,97+26)] def inpl(): return list(map(int, input().split())) def inpl_str(): return list(input().split()) def ex_square(n,k): #n^k if k <= 0: return 1 elif k % 2 == 0: ans = ex_square(n, k//2) ** 2 else: ans = ex_square(n,k-1) * n return ans%mod S = list(eval(input())) aa = [0] bb = [0] cc = [0] qq = [0] Sa = Sb =Sc = Sq = 0 for s in S: if s == 'A': Sa += 1 elif s == 'B': Sb += 1 elif s == 'C': Sc += 1 elif s == '?': Sq += 1 aa.append(Sa) bb.append(Sb) cc.append(Sc) qq.append(Sq) ans = 0 ex = [ex_square(3,Sq),ex_square(3,Sq-1),ex_square(3,Sq-2),ex_square(3,Sq-3)] for i,s in enumerate(S): if s == 'B': k = 0 elif s == '?': k = 1 elif s == 'A' or s == 'C': continue Lq = qq[i] Rq = Sq-Lq-k La = aa[i] Rc = Sc - cc[i] ans1 = (ex[0 + k] * (La*Rc)%mod)%mod ans2 = (ex[1 + k] * (Lq*Rc)%mod)%mod ans3 = (ex[1 + k] * (La*Rq)%mod)%mod ans4 = (ex[2 + k] * (Lq*Rq)%mod)%mod ans += (ans1+ans2+ans3+ans4)%mod ans %= mod print(ans)
78
67
1,370
1,284
from collections import defaultdict import sys, heapq, bisect, math, itertools, string, queue, datetime sys.setrecursionlimit(10**8) INF = float("inf") mod = 10**9 + 7 eps = 10**-7 AtoZ = [chr(i) for i in range(65, 65 + 26)] atoz = [chr(i) for i in range(97, 97 + 26)] def inpl(): return list(map(int, input().split())) def inpl_str(): return list(input().split()) def ex_square(n, k): # n^k if k == 0: ans = 1 elif k % 2 == 0: ans = ex_square(n, k // 2) ** 2 else: ans = ex_square(n, k - 1) * n ans %= mod return ans S = list(eval(input())) aa = [0] bb = [0] cc = [0] qq = [0] Sa = Sb = Sc = Sq = 0 for s in S: if s == "A": Sa += 1 elif s == "B": Sb += 1 elif s == "C": Sc += 1 elif s == "?": Sq += 1 aa.append(Sa) bb.append(Sb) cc.append(Sc) qq.append(Sq) ans = 0 for i, s in enumerate(S): if s == "B": SUMq = Sq elif s == "?": SUMq = Sq - 1 elif s == "A" or s == "C": continue Lq = qq[i] Rq = SUMq - Lq La = aa[i] Rc = Sc - cc[i] if SUMq == 0: ex = 1 exx = exxx = 0 elif SUMq == 1: ex = 3 exx = 1 exxx = 0 else: exxx = ex_square(3, SUMq - 2) exx = exxx * 3 % mod ex = exx * 3 % mod ans1 = (ex * (La * Rc) % mod) % mod ans2 = (exx * (Lq * Rc) % mod) % mod ans3 = (exx * (La * Rq) % mod) % mod ans4 = (exxx * (Lq * Rq) % mod) % mod ans += (ans1 + ans2 + ans3 + ans4) % mod ans %= mod print(ans)
from collections import defaultdict import sys, heapq, bisect, math, itertools, string, queue, datetime sys.setrecursionlimit(10**8) INF = float("inf") mod = 10**9 + 7 eps = 10**-7 AtoZ = [chr(i) for i in range(65, 65 + 26)] atoz = [chr(i) for i in range(97, 97 + 26)] def inpl(): return list(map(int, input().split())) def inpl_str(): return list(input().split()) def ex_square(n, k): # n^k if k <= 0: return 1 elif k % 2 == 0: ans = ex_square(n, k // 2) ** 2 else: ans = ex_square(n, k - 1) * n return ans % mod S = list(eval(input())) aa = [0] bb = [0] cc = [0] qq = [0] Sa = Sb = Sc = Sq = 0 for s in S: if s == "A": Sa += 1 elif s == "B": Sb += 1 elif s == "C": Sc += 1 elif s == "?": Sq += 1 aa.append(Sa) bb.append(Sb) cc.append(Sc) qq.append(Sq) ans = 0 ex = [ ex_square(3, Sq), ex_square(3, Sq - 1), ex_square(3, Sq - 2), ex_square(3, Sq - 3), ] for i, s in enumerate(S): if s == "B": k = 0 elif s == "?": k = 1 elif s == "A" or s == "C": continue Lq = qq[i] Rq = Sq - Lq - k La = aa[i] Rc = Sc - cc[i] ans1 = (ex[0 + k] * (La * Rc) % mod) % mod ans2 = (ex[1 + k] * (Lq * Rc) % mod) % mod ans3 = (ex[1 + k] * (La * Rq) % mod) % mod ans4 = (ex[2 + k] * (Lq * Rq) % mod) % mod ans += (ans1 + ans2 + ans3 + ans4) % mod ans %= mod print(ans)
false
14.102564
[ "- if k == 0:", "- ans = 1", "+ if k <= 0:", "+ return 1", "- ans %= mod", "- return ans", "+ return ans % mod", "+ex = [", "+ ex_square(3, Sq),", "+ ex_square(3, Sq - 1),", "+ ex_square(3, Sq - 2),", "+ ex_square(3, Sq - 3),", "+]", "- SUMq = Sq", "+ k = 0", "- SUMq = Sq - 1", "+ k = 1", "- Rq = SUMq - Lq", "+ Rq = Sq - Lq - k", "- if SUMq == 0:", "- ex = 1", "- exx = exxx = 0", "- elif SUMq == 1:", "- ex = 3", "- exx = 1", "- exxx = 0", "- else:", "- exxx = ex_square(3, SUMq - 2)", "- exx = exxx * 3 % mod", "- ex = exx * 3 % mod", "- ans1 = (ex * (La * Rc) % mod) % mod", "- ans2 = (exx * (Lq * Rc) % mod) % mod", "- ans3 = (exx * (La * Rq) % mod) % mod", "- ans4 = (exxx * (Lq * Rq) % mod) % mod", "+ ans1 = (ex[0 + k] * (La * Rc) % mod) % mod", "+ ans2 = (ex[1 + k] * (Lq * Rc) % mod) % mod", "+ ans3 = (ex[1 + k] * (La * Rq) % mod) % mod", "+ ans4 = (ex[2 + k] * (Lq * Rq) % mod) % mod" ]
false
0.073042
0.034969
2.088768
[ "s809484543", "s233501158" ]
u896847891
p02784
python
s930071984
s900082062
41
37
13,964
9,944
Accepted
Accepted
9.76
h,n=list(map(int,input().split())) print(("Yes"if sum(list(map(int,input().split())))>=h else "No"))
h, n = list(map(int, input().split())) print(("Yes" if h <= sum(map(int, input().split())) else "No"))
2
2
93
95
h, n = list(map(int, input().split())) print(("Yes" if sum(list(map(int, input().split()))) >= h else "No"))
h, n = list(map(int, input().split())) print(("Yes" if h <= sum(map(int, input().split())) else "No"))
false
0
[ "-print((\"Yes\" if sum(list(map(int, input().split()))) >= h else \"No\"))", "+print((\"Yes\" if h <= sum(map(int, input().split())) else \"No\"))" ]
false
0.038878
0.039606
0.981623
[ "s930071984", "s900082062" ]
u724687935
p02644
python
s219563162
s111760460
1,734
1,546
401,304
400,560
Accepted
Accepted
10.84
from collections import deque H, W, K = list(map(int, input().split())) x1, y1, x2, y2 = [int(x) - 1 for x in input().split()] grid = [eval(input()) for _ in range(H)] INF = float('inf') path = [[[(INF, INF)] * 4 for _ in range(W)] for _ in range(H)] q = deque() for d in range(4): path[x1][y1][d] = (1, 0) q.append((x1, y1, d, 1, 0)) D = [(-1, 0), (0, 1), (1, 0), (0, -1)] while q: x, y, d, s, k = q.popleft() if k == K: for nd in range(4): if nd == d: dx, dy = D[nd] nk = 1 else: dx, dy = 0, 0 nk = 0 nx = x + dx; ny = y + dy ns = s + 1 if 0 <= nx < H and 0 <= ny < W and grid[nx][ny] == '.' and path[nx][ny][nd] > (ns, nk): path[nx][ny][nd] = (ns, nk) q.append((nx, ny, nd, ns, nk)) else: for nd in range(4): if nd == d: dx, dy = D[nd] nk = k + 1 else: dx, dy = 0, 0 nk = 0 nx = x + dx; ny = y + dy ns = s + (d != nd) if 0 <= nx < H and 0 <= ny < W and grid[nx][ny] == '.' and path[nx][ny][nd] > (ns, nk): path[nx][ny][nd] = (ns, nk) if ns == s: q.appendleft((nx, ny, nd, ns, nk)) else: q.append((nx, ny, nd, ns, nk)) ans = INF for d in range(4): ans = min(ans, path[x2][y2][d][0]) ans = -1 if ans == INF else ans print(ans)
from collections import deque H, W, K = list(map(int, input().split())) x1, y1, x2, y2 = [int(x) - 1 for x in input().split()] grid = [eval(input()) for _ in range(H)] INF = float('inf') path = [[[(INF, INF)] * 4 for _ in range(W)] for _ in range(H)] q = deque() for d in range(4): path[x1][y1][d] = (1, 0) q.append((x1, y1, d, 1, 0)) D = [(-1, 0), (0, 1), (1, 0), (0, -1)] while q: x, y, d, s, k = q.popleft() for nd in range(4): if nd == d: dx, dy = D[nd] nk = 1 if k == K else k + 1 ns = s + 1 if k == K else s else: dx, dy = 0, 0 nk = 0 ns = s + 1 nx = x + dx; ny = y + dy if 0 <= nx < H and 0 <= ny < W and grid[nx][ny] == '.' and path[nx][ny][nd] > (ns, nk): path[nx][ny][nd] = (ns, nk) if ns == s: q.appendleft((nx, ny, nd, ns, nk)) else: q.append((nx, ny, nd, ns, nk)) ans = INF for d in range(4): ans = min(ans, path[x2][y2][d][0]) ans = -1 if ans == INF else ans print(ans)
53
40
1,587
1,114
from collections import deque H, W, K = list(map(int, input().split())) x1, y1, x2, y2 = [int(x) - 1 for x in input().split()] grid = [eval(input()) for _ in range(H)] INF = float("inf") path = [[[(INF, INF)] * 4 for _ in range(W)] for _ in range(H)] q = deque() for d in range(4): path[x1][y1][d] = (1, 0) q.append((x1, y1, d, 1, 0)) D = [(-1, 0), (0, 1), (1, 0), (0, -1)] while q: x, y, d, s, k = q.popleft() if k == K: for nd in range(4): if nd == d: dx, dy = D[nd] nk = 1 else: dx, dy = 0, 0 nk = 0 nx = x + dx ny = y + dy ns = s + 1 if ( 0 <= nx < H and 0 <= ny < W and grid[nx][ny] == "." and path[nx][ny][nd] > (ns, nk) ): path[nx][ny][nd] = (ns, nk) q.append((nx, ny, nd, ns, nk)) else: for nd in range(4): if nd == d: dx, dy = D[nd] nk = k + 1 else: dx, dy = 0, 0 nk = 0 nx = x + dx ny = y + dy ns = s + (d != nd) if ( 0 <= nx < H and 0 <= ny < W and grid[nx][ny] == "." and path[nx][ny][nd] > (ns, nk) ): path[nx][ny][nd] = (ns, nk) if ns == s: q.appendleft((nx, ny, nd, ns, nk)) else: q.append((nx, ny, nd, ns, nk)) ans = INF for d in range(4): ans = min(ans, path[x2][y2][d][0]) ans = -1 if ans == INF else ans print(ans)
from collections import deque H, W, K = list(map(int, input().split())) x1, y1, x2, y2 = [int(x) - 1 for x in input().split()] grid = [eval(input()) for _ in range(H)] INF = float("inf") path = [[[(INF, INF)] * 4 for _ in range(W)] for _ in range(H)] q = deque() for d in range(4): path[x1][y1][d] = (1, 0) q.append((x1, y1, d, 1, 0)) D = [(-1, 0), (0, 1), (1, 0), (0, -1)] while q: x, y, d, s, k = q.popleft() for nd in range(4): if nd == d: dx, dy = D[nd] nk = 1 if k == K else k + 1 ns = s + 1 if k == K else s else: dx, dy = 0, 0 nk = 0 ns = s + 1 nx = x + dx ny = y + dy if ( 0 <= nx < H and 0 <= ny < W and grid[nx][ny] == "." and path[nx][ny][nd] > (ns, nk) ): path[nx][ny][nd] = (ns, nk) if ns == s: q.appendleft((nx, ny, nd, ns, nk)) else: q.append((nx, ny, nd, ns, nk)) ans = INF for d in range(4): ans = min(ans, path[x2][y2][d][0]) ans = -1 if ans == INF else ans print(ans)
false
24.528302
[ "- if k == K:", "- for nd in range(4):", "- if nd == d:", "- dx, dy = D[nd]", "- nk = 1", "+ for nd in range(4):", "+ if nd == d:", "+ dx, dy = D[nd]", "+ nk = 1 if k == K else k + 1", "+ ns = s + 1 if k == K else s", "+ else:", "+ dx, dy = 0, 0", "+ nk = 0", "+ ns = s + 1", "+ nx = x + dx", "+ ny = y + dy", "+ if (", "+ 0 <= nx < H", "+ and 0 <= ny < W", "+ and grid[nx][ny] == \".\"", "+ and path[nx][ny][nd] > (ns, nk)", "+ ):", "+ path[nx][ny][nd] = (ns, nk)", "+ if ns == s:", "+ q.appendleft((nx, ny, nd, ns, nk))", "- dx, dy = 0, 0", "- nk = 0", "- nx = x + dx", "- ny = y + dy", "- ns = s + 1", "- if (", "- 0 <= nx < H", "- and 0 <= ny < W", "- and grid[nx][ny] == \".\"", "- and path[nx][ny][nd] > (ns, nk)", "- ):", "- path[nx][ny][nd] = (ns, nk)", "- else:", "- for nd in range(4):", "- if nd == d:", "- dx, dy = D[nd]", "- nk = k + 1", "- else:", "- dx, dy = 0, 0", "- nk = 0", "- nx = x + dx", "- ny = y + dy", "- ns = s + (d != nd)", "- if (", "- 0 <= nx < H", "- and 0 <= ny < W", "- and grid[nx][ny] == \".\"", "- and path[nx][ny][nd] > (ns, nk)", "- ):", "- path[nx][ny][nd] = (ns, nk)", "- if ns == s:", "- q.appendleft((nx, ny, nd, ns, nk))", "- else:", "- q.append((nx, ny, nd, ns, nk))" ]
false
0.043132
0.0437
0.986997
[ "s219563162", "s111760460" ]
u392029857
p03463
python
s188264563
s275155220
20
18
3,060
3,064
Accepted
Accepted
10
N, A, B = list(map(int, input().split())) det = (B-A)%2 if det == 1: print('Borys') else: print('Alice')
N, A, B = list(map(int, input().split())) if (B-A)%2 == 0: print('Alice') else: print('Borys')
6
5
111
100
N, A, B = list(map(int, input().split())) det = (B - A) % 2 if det == 1: print("Borys") else: print("Alice")
N, A, B = list(map(int, input().split())) if (B - A) % 2 == 0: print("Alice") else: print("Borys")
false
16.666667
[ "-det = (B - A) % 2", "-if det == 1:", "+if (B - A) % 2 == 0:", "+ print(\"Alice\")", "+else:", "-else:", "- print(\"Alice\")" ]
false
0.041402
0.041733
0.992078
[ "s188264563", "s275155220" ]
u054514819
p02614
python
s957117603
s786322829
90
82
74,084
68,324
Accepted
Accepted
8.89
import sys def input(): return sys.stdin.readline().strip() def mapint(): return list(map(int, input().split())) sys.setrecursionlimit(10**9) H, W, K = mapint() rows = [0]*H query = [] allcnt = 0 for h in range(H): Cs = list(eval(input())) query.append(Cs) cnt = sum([1 if i=='#' else 0 for i in Cs]) rows[h] = cnt allcnt += cnt ans = 0 for i in range(1<<H): skip = set() num = 0 for h in range(H): if (i>>h)&1: skip.add(h) num += rows[h] for j in range(1<<W): num2 = num for w in range(W): if (j>>w)&1: for h2 in range(H): if h2 in skip: continue if query[h2][w]=='#': num2 += 1 if allcnt-num2==K: ans += 1 print(ans)
import sys def input(): return sys.stdin.readline().strip() def mapint(): return list(map(int, input().split())) sys.setrecursionlimit(10**9) H, W, K = mapint() query = [list(eval(input())) for _ in range(H)] ans = 0 for i in range(1<<H): for j in range(1<<W): cnt = 0 for h in range(H): for w in range(W): if not (i>>h)&1 and not (j>>w)&1: if query[h][w]=='#': cnt += 1 if cnt==K: ans += 1 print(ans)
36
21
863
524
import sys def input(): return sys.stdin.readline().strip() def mapint(): return list(map(int, input().split())) sys.setrecursionlimit(10**9) H, W, K = mapint() rows = [0] * H query = [] allcnt = 0 for h in range(H): Cs = list(eval(input())) query.append(Cs) cnt = sum([1 if i == "#" else 0 for i in Cs]) rows[h] = cnt allcnt += cnt ans = 0 for i in range(1 << H): skip = set() num = 0 for h in range(H): if (i >> h) & 1: skip.add(h) num += rows[h] for j in range(1 << W): num2 = num for w in range(W): if (j >> w) & 1: for h2 in range(H): if h2 in skip: continue if query[h2][w] == "#": num2 += 1 if allcnt - num2 == K: ans += 1 print(ans)
import sys def input(): return sys.stdin.readline().strip() def mapint(): return list(map(int, input().split())) sys.setrecursionlimit(10**9) H, W, K = mapint() query = [list(eval(input())) for _ in range(H)] ans = 0 for i in range(1 << H): for j in range(1 << W): cnt = 0 for h in range(H): for w in range(W): if not (i >> h) & 1 and not (j >> w) & 1: if query[h][w] == "#": cnt += 1 if cnt == K: ans += 1 print(ans)
false
41.666667
[ "-rows = [0] * H", "-query = []", "-allcnt = 0", "-for h in range(H):", "- Cs = list(eval(input()))", "- query.append(Cs)", "- cnt = sum([1 if i == \"#\" else 0 for i in Cs])", "- rows[h] = cnt", "- allcnt += cnt", "+query = [list(eval(input())) for _ in range(H)]", "- skip = set()", "- num = 0", "- for h in range(H):", "- if (i >> h) & 1:", "- skip.add(h)", "- num += rows[h]", "- num2 = num", "- for w in range(W):", "- if (j >> w) & 1:", "- for h2 in range(H):", "- if h2 in skip:", "- continue", "- if query[h2][w] == \"#\":", "- num2 += 1", "- if allcnt - num2 == K:", "+ cnt = 0", "+ for h in range(H):", "+ for w in range(W):", "+ if not (i >> h) & 1 and not (j >> w) & 1:", "+ if query[h][w] == \"#\":", "+ cnt += 1", "+ if cnt == K:" ]
false
0.044138
0.04417
0.999275
[ "s957117603", "s786322829" ]
u386819480
p03633
python
s451452244
s409798195
35
23
5,076
3,572
Accepted
Accepted
34.29
#!/usr/bin/env python3 import sys from fractions import gcd # from math import gcd from functools import reduce def lcm(x, y): return (x * y) // gcd(x, y) def solve(N: int, T: "List[int]"): print((reduce(lcm, T))) return # Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int T = [int(next(tokens)) for _ in range(N)] # type: "List[int]" solve(N, T) if __name__ == '__main__': main()
#!/usr/bin/env python3 import sys from functools import reduce sys.setrecursionlimit(10000000) INF = 1<<32 def solve(N: int, T: "List[int]"): from functools import reduce def lcm_base(a: int, b:int): return a*b // gcd(a,b) def lcm(*numbers): return reduce(lcm_base, numbers, 1) def gcd_base(a: int, b: int): while b: a, b = b, a%b return a def gcd(*numbers): return reduce(gcd_base, numbers) print((lcm(*T))) return def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int T = [int(next(tokens)) for _ in range(N)] # type: "List[int]" solve(N, T) if __name__ == '__main__': main()
28
41
754
841
#!/usr/bin/env python3 import sys from fractions import gcd # from math import gcd from functools import reduce def lcm(x, y): return (x * y) // gcd(x, y) def solve(N: int, T: "List[int]"): print((reduce(lcm, T))) return # Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int T = [int(next(tokens)) for _ in range(N)] # type: "List[int]" solve(N, T) if __name__ == "__main__": main()
#!/usr/bin/env python3 import sys from functools import reduce sys.setrecursionlimit(10000000) INF = 1 << 32 def solve(N: int, T: "List[int]"): from functools import reduce def lcm_base(a: int, b: int): return a * b // gcd(a, b) def lcm(*numbers): return reduce(lcm_base, numbers, 1) def gcd_base(a: int, b: int): while b: a, b = b, a % b return a def gcd(*numbers): return reduce(gcd_base, numbers) print((lcm(*T))) return def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int T = [int(next(tokens)) for _ in range(N)] # type: "List[int]" solve(N, T) if __name__ == "__main__": main()
false
31.707317
[ "-from fractions import gcd", "-", "-# from math import gcd", "-", "-def lcm(x, y):", "- return (x * y) // gcd(x, y)", "+sys.setrecursionlimit(10000000)", "+INF = 1 << 32", "- print((reduce(lcm, T)))", "+ from functools import reduce", "+", "+ def lcm_base(a: int, b: int):", "+ return a * b // gcd(a, b)", "+", "+ def lcm(*numbers):", "+ return reduce(lcm_base, numbers, 1)", "+", "+ def gcd_base(a: int, b: int):", "+ while b:", "+ a, b = b, a % b", "+ return a", "+", "+ def gcd(*numbers):", "+ return reduce(gcd_base, numbers)", "+", "+ print((lcm(*T)))", "-# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template)" ]
false
0.048649
0.059713
0.814717
[ "s451452244", "s409798195" ]
u895558682
p02768
python
s182193300
s423059519
165
149
3,064
3,064
Accepted
Accepted
9.7
M = 10**9 + 7 n,a,b = list(map(int, input().split())) def modinv(n): return pow(n, M-2, M) def comb(n, r): num = 1 for i in range(n,n-r,-1): cur = i while cur%M == 0: cur //= M num = (num*cur)%M denom = 1 for i in range(1,r+1): cur = i while cur%M == 0: cur //= M denom = (denom*cur)%M return num * modinv(denom) % M print(((pow(2, n, M) - comb(n, a) - comb(n, b) - 1) % M))
M = 10**9 + 7 n,a,b = list(map(int, input().split())) def modinv(n): return pow(n, M-2, M) def comb(n, r): num = denom = 1 for i in range(1,r+1): num = (num*(n+1-i))%M denom = (denom*i)%M return num * modinv(denom) % M print(((pow(2, n, M) - comb(n, a) - comb(n, b) - 1) % M))
25
14
492
316
M = 10**9 + 7 n, a, b = list(map(int, input().split())) def modinv(n): return pow(n, M - 2, M) def comb(n, r): num = 1 for i in range(n, n - r, -1): cur = i while cur % M == 0: cur //= M num = (num * cur) % M denom = 1 for i in range(1, r + 1): cur = i while cur % M == 0: cur //= M denom = (denom * cur) % M return num * modinv(denom) % M print(((pow(2, n, M) - comb(n, a) - comb(n, b) - 1) % M))
M = 10**9 + 7 n, a, b = list(map(int, input().split())) def modinv(n): return pow(n, M - 2, M) def comb(n, r): num = denom = 1 for i in range(1, r + 1): num = (num * (n + 1 - i)) % M denom = (denom * i) % M return num * modinv(denom) % M print(((pow(2, n, M) - comb(n, a) - comb(n, b) - 1) % M))
false
44
[ "- num = 1", "- for i in range(n, n - r, -1):", "- cur = i", "- while cur % M == 0:", "- cur //= M", "- num = (num * cur) % M", "- denom = 1", "+ num = denom = 1", "- cur = i", "- while cur % M == 0:", "- cur //= M", "- denom = (denom * cur) % M", "+ num = (num * (n + 1 - i)) % M", "+ denom = (denom * i) % M" ]
false
0.236346
0.15623
1.512805
[ "s182193300", "s423059519" ]
u433380437
p03386
python
s257652769
s813008554
75
26
62,432
9,196
Accepted
Accepted
65.33
a,b,k = list(map(int,input().split())) A=[] for i in range(a,min(a+k,b+1)): A.append(i) B=[] for i in range(b,max(b-k,a-1),-1): B.append(i) C=list(set(A+B)) C.sort(reverse=False) for j in range(len(C)): print((C[j]))
a,b,k = list(map(int,input().split())) A=[] B=[] for i in range(a,min(a+k,b+1)): A.append(i) for j in range(b,max(b-k,a-1),-1): A.append(j) B=list(set(A)) B.sort(reverse=False) for p in range(len(B)): print((B[p]))
11
11
230
228
a, b, k = list(map(int, input().split())) A = [] for i in range(a, min(a + k, b + 1)): A.append(i) B = [] for i in range(b, max(b - k, a - 1), -1): B.append(i) C = list(set(A + B)) C.sort(reverse=False) for j in range(len(C)): print((C[j]))
a, b, k = list(map(int, input().split())) A = [] B = [] for i in range(a, min(a + k, b + 1)): A.append(i) for j in range(b, max(b - k, a - 1), -1): A.append(j) B = list(set(A)) B.sort(reverse=False) for p in range(len(B)): print((B[p]))
false
0
[ "+B = []", "-B = []", "-for i in range(b, max(b - k, a - 1), -1):", "- B.append(i)", "-C = list(set(A + B))", "-C.sort(reverse=False)", "-for j in range(len(C)):", "- print((C[j]))", "+for j in range(b, max(b - k, a - 1), -1):", "+ A.append(j)", "+B = list(set(A))", "+B.sort(reverse=False)", "+for p in range(len(B)):", "+ print((B[p]))" ]
false
0.042372
0.101926
0.41571
[ "s257652769", "s813008554" ]
u887207211
p03252
python
s341320356
s416608098
256
29
7,708
3,632
Accepted
Accepted
88.67
S = sorted(eval(input())) T = sorted(eval(input())) S_list = [] T_list = [] for alp in "abcdefghijklmnopqrstuvwxyz": S_list.append(S.count(alp)) T_list.append(T.count(alp)) if(sorted(S_list) != sorted(T_list)): print('No') else: print('Yes')
S = eval(input()) T = eval(input()) s = [] t = [] for alp in "abcdefghijklmnopqrstuvwxyz": s.append(S.count(alp)) t.append(T.count(alp)) if(sorted(s) == sorted(t)): print("Yes") else: print("No")
11
11
247
202
S = sorted(eval(input())) T = sorted(eval(input())) S_list = [] T_list = [] for alp in "abcdefghijklmnopqrstuvwxyz": S_list.append(S.count(alp)) T_list.append(T.count(alp)) if sorted(S_list) != sorted(T_list): print("No") else: print("Yes")
S = eval(input()) T = eval(input()) s = [] t = [] for alp in "abcdefghijklmnopqrstuvwxyz": s.append(S.count(alp)) t.append(T.count(alp)) if sorted(s) == sorted(t): print("Yes") else: print("No")
false
0
[ "-S = sorted(eval(input()))", "-T = sorted(eval(input()))", "-S_list = []", "-T_list = []", "+S = eval(input())", "+T = eval(input())", "+s = []", "+t = []", "- S_list.append(S.count(alp))", "- T_list.append(T.count(alp))", "-if sorted(S_list) != sorted(T_list):", "+ s.append(S.count(alp))", "+ t.append(T.count(alp))", "+if sorted(s) == sorted(t):", "+ print(\"Yes\")", "+else:", "-else:", "- print(\"Yes\")" ]
false
0.120879
0.037331
3.238073
[ "s341320356", "s416608098" ]
u729133443
p02685
python
s556683846
s080264595
690
145
48,408
79,344
Accepted
Accepted
78.99
M=998244353 class Factorial: def __init__(self,n): self.f=f=[0]*(n+1) f[0]=b=1 for i in range(1,n+1):f[i]=b=b*i%M self.inv=inv=[0]*(n+1) inv[n]=b=pow(self.f[n],-1,M) for i in range(n,0,-1):inv[i-1]=b=b*i%M def factorial(self,i): return self.f[i] def ifactorial(self,i): return self.inv[i] def comb(self,n,k): if n>=k:return self.f[n]*self.inv[n-k]*self.inv[k]%M else:return 0 comb=Factorial(10**5*5).comb n,m,k=list(map(int,input().split())) print((sum(m*comb(n-1,i)*pow(m-1,~i+n,M)for i in range(k+1))%M))
M=998244353 class Factorial: def __init__(self,n): self.f=f=[0]*(n+1) f[0]=b=1 for i in range(1,n+1):f[i]=b=b*i%M self.inv=inv=[0]*(n+1) inv[n]=b=pow(self.f[n],M-2,M) for i in range(n,0,-1):inv[i-1]=b=b*i%M def factorial(self,i): return self.f[i] def ifactorial(self,i): return self.inv[i] def comb(self,n,k): if n>=k:return self.f[n]*self.inv[n-k]*self.inv[k]%M else:return 0 comb=Factorial(10**5*5).comb n,m,k=list(map(int,input().split())) print((sum(m*comb(n-1,i)*pow(m-1,~i+n,M)for i in range(k+1))%M))
19
19
612
613
M = 998244353 class Factorial: def __init__(self, n): self.f = f = [0] * (n + 1) f[0] = b = 1 for i in range(1, n + 1): f[i] = b = b * i % M self.inv = inv = [0] * (n + 1) inv[n] = b = pow(self.f[n], -1, M) for i in range(n, 0, -1): inv[i - 1] = b = b * i % M def factorial(self, i): return self.f[i] def ifactorial(self, i): return self.inv[i] def comb(self, n, k): if n >= k: return self.f[n] * self.inv[n - k] * self.inv[k] % M else: return 0 comb = Factorial(10**5 * 5).comb n, m, k = list(map(int, input().split())) print((sum(m * comb(n - 1, i) * pow(m - 1, ~i + n, M) for i in range(k + 1)) % M))
M = 998244353 class Factorial: def __init__(self, n): self.f = f = [0] * (n + 1) f[0] = b = 1 for i in range(1, n + 1): f[i] = b = b * i % M self.inv = inv = [0] * (n + 1) inv[n] = b = pow(self.f[n], M - 2, M) for i in range(n, 0, -1): inv[i - 1] = b = b * i % M def factorial(self, i): return self.f[i] def ifactorial(self, i): return self.inv[i] def comb(self, n, k): if n >= k: return self.f[n] * self.inv[n - k] * self.inv[k] % M else: return 0 comb = Factorial(10**5 * 5).comb n, m, k = list(map(int, input().split())) print((sum(m * comb(n - 1, i) * pow(m - 1, ~i + n, M) for i in range(k + 1)) % M))
false
0
[ "- inv[n] = b = pow(self.f[n], -1, M)", "+ inv[n] = b = pow(self.f[n], M - 2, M)" ]
false
0.776057
0.326549
2.376544
[ "s556683846", "s080264595" ]
u254022775
p03346
python
s709937887
s585220619
451
410
18,916
11,048
Accepted
Accepted
9.09
N = int(eval(input())) a = [0 for i in range(N)] chain = [0 for i in range(N+1)] for i in range(N): a[i] = int(eval(input())) chain[a[i]] = chain[a[i]-1]+1 print((N-max(chain)))
N = int(eval(input())) chain = [0 for i in range(N+1)] for i in range(N): a = int(eval(input())) chain[a] = chain[a-1]+1 print((N-max(chain)))
7
6
173
137
N = int(eval(input())) a = [0 for i in range(N)] chain = [0 for i in range(N + 1)] for i in range(N): a[i] = int(eval(input())) chain[a[i]] = chain[a[i] - 1] + 1 print((N - max(chain)))
N = int(eval(input())) chain = [0 for i in range(N + 1)] for i in range(N): a = int(eval(input())) chain[a] = chain[a - 1] + 1 print((N - max(chain)))
false
14.285714
[ "-a = [0 for i in range(N)]", "- a[i] = int(eval(input()))", "- chain[a[i]] = chain[a[i] - 1] + 1", "+ a = int(eval(input()))", "+ chain[a] = chain[a - 1] + 1" ]
false
0.048073
0.048703
0.987073
[ "s709937887", "s585220619" ]
u832039789
p03745
python
s471121341
s098684441
79
66
14,224
14,224
Accepted
Accepted
16.46
n = int(eval(input())) a = list(map(int,input().split())) cond = 0 # 1: 上昇, -1: 減少, 0: 一緒 res = 1 for i in range(1,len(a)): if a[i] > a[i-1]: # 上昇 if cond != 1: if cond == -1: res += 1 cond = 0 else: cond = 1 elif a[i] < a[i-1]: # 減少 if cond != -1: if cond == 1: res += 1 cond = 0 else: cond = -1 print(res)
n = int(eval(input())) a = list(map(int,input().split())) # 0 : 未定 # 1 : 増加 # -1 : 減少 res = 0 prv = a[0] cond = 0 for i in a: if cond == 0: if prv > i: cond = -1 elif prv < i: cond = 1 elif cond == 1: if prv > i: cond = 0 res += 1 else: if prv < i: cond = 0 res += 1 prv = i print((res + 1))
23
26
508
433
n = int(eval(input())) a = list(map(int, input().split())) cond = 0 # 1: 上昇, -1: 減少, 0: 一緒 res = 1 for i in range(1, len(a)): if a[i] > a[i - 1]: # 上昇 if cond != 1: if cond == -1: res += 1 cond = 0 else: cond = 1 elif a[i] < a[i - 1]: # 減少 if cond != -1: if cond == 1: res += 1 cond = 0 else: cond = -1 print(res)
n = int(eval(input())) a = list(map(int, input().split())) # 0 : 未定 # 1 : 増加 # -1 : 減少 res = 0 prv = a[0] cond = 0 for i in a: if cond == 0: if prv > i: cond = -1 elif prv < i: cond = 1 elif cond == 1: if prv > i: cond = 0 res += 1 else: if prv < i: cond = 0 res += 1 prv = i print((res + 1))
false
11.538462
[ "+# 0 : 未定", "+# 1 : 増加", "+# -1 : 減少", "+res = 0", "+prv = a[0]", "-# 1: 上昇, -1: 減少, 0: 一緒", "-res = 1", "-for i in range(1, len(a)):", "- if a[i] > a[i - 1]:", "- # 上昇", "- if cond != 1:", "- if cond == -1:", "- res += 1", "- cond = 0", "- else:", "- cond = 1", "- elif a[i] < a[i - 1]:", "- # 減少", "- if cond != -1:", "- if cond == 1:", "- res += 1", "- cond = 0", "- else:", "- cond = -1", "-print(res)", "+for i in a:", "+ if cond == 0:", "+ if prv > i:", "+ cond = -1", "+ elif prv < i:", "+ cond = 1", "+ elif cond == 1:", "+ if prv > i:", "+ cond = 0", "+ res += 1", "+ else:", "+ if prv < i:", "+ cond = 0", "+ res += 1", "+ prv = i", "+print((res + 1))" ]
false
0.17576
0.045181
3.890135
[ "s471121341", "s098684441" ]
u828766688
p03333
python
s141215168
s198972942
1,636
601
109,016
57,944
Accepted
Accepted
63.26
""" 貪欲か? 今いる地点から左のRと右のLの数を比較 多い方の最遠点に行く→そのような点が無くなったら終了 証明は… まず右のR,左のLは無意味→区間を無駄にするだけ 少ない方に行く→多い方の区間が無駄になる 近い点に行く→ ここがむずい 遠い区間が無駄になるのを防ぐため? 実装は? 多い方の処理→BITで左にあるRの数と右にあるLの数をlogNで 優先度付きキューで最小のRと最大のLを検出 10^5+1 を足して1 ~ 2*10^5 + 1の区間として扱う 初期・終了地点は 10^5+1 """ import heapq def bitadd(a,w,bit): #aにwを加える(1-origin) x = a while x <= (len(bit)-1): bit[x] += w x += x & (-1 * x) def bitsum(a,bit): #ind 1~aまでの和を求める ret = 0 x = a while x > 0: ret += bit[x] x -= x & (-1 * x) return ret N = int(eval(input())) used = [False] * N lq = [] rq = [] LR = [] LBIT = [0] * (2 * (10**5) + 10) RBIT = [0] * (2 * (10**5) + 10) for i in range(N): L,R = list(map(int,input().split())) L += 10**5+1 R += 10**5+1 LR.append([L,R]) heapq.heappush(lq,[-1 * L,i]) heapq.heappush(rq,[R,i]) bitadd(L,1,LBIT) bitadd(R,1,RBIT) ans = 0 now = 10**5+1 for i in range(N): R_in_left = bitsum(now-1,RBIT) L_in_right = N - i - bitsum(now,LBIT) if R_in_left >= L_in_right: #左にあるRに移動 while len(rq) > 0 and used[ rq[0][1] ]: heapq.heappop(rq) if len(rq) == 0: break nexp,nexind = heapq.heappop(rq) pair = LR[nexind][0] bitadd(nexp,-1,RBIT) bitadd(pair,-1,LBIT) used[nexind] = True if nexp >= now: break ans += now - nexp now = nexp else: while len(lq) > 0 and used[ lq[0][1] ]: heapq.heappop(lq) if len(lq) == 0: break nexp,nexind = heapq.heappop(lq) nexp *= -1 pair = LR[nexind][1] bitadd(nexp,-1,LBIT) bitadd(pair,-1,RBIT) used[nexind] = True if nexp <= now: break ans += nexp - now now = nexp ans += abs(10**5+1 - now) print (ans)
N = int(eval(input())) L = [] R = [] for i in range(N): l,r = list(map(int,input().split())) L.append(2 * l) R.append(-2 * r) L.sort() R.sort() L.reverse() R.reverse() ans = 0 now = 0 for i in range(N): now += L[i] ans = max(ans,now) now += R[i] ans = max(ans,now) now = 0 for i in range(N): now += R[i] ans = max(ans,now) now += L[i] ans = max(ans,now) print (ans)
122
33
2,004
438
""" 貪欲か? 今いる地点から左のRと右のLの数を比較 多い方の最遠点に行く→そのような点が無くなったら終了 証明は… まず右のR,左のLは無意味→区間を無駄にするだけ 少ない方に行く→多い方の区間が無駄になる 近い点に行く→ ここがむずい 遠い区間が無駄になるのを防ぐため? 実装は? 多い方の処理→BITで左にあるRの数と右にあるLの数をlogNで 優先度付きキューで最小のRと最大のLを検出 10^5+1 を足して1 ~ 2*10^5 + 1の区間として扱う 初期・終了地点は 10^5+1 """ import heapq def bitadd(a, w, bit): # aにwを加える(1-origin) x = a while x <= (len(bit) - 1): bit[x] += w x += x & (-1 * x) def bitsum(a, bit): # ind 1~aまでの和を求める ret = 0 x = a while x > 0: ret += bit[x] x -= x & (-1 * x) return ret N = int(eval(input())) used = [False] * N lq = [] rq = [] LR = [] LBIT = [0] * (2 * (10**5) + 10) RBIT = [0] * (2 * (10**5) + 10) for i in range(N): L, R = list(map(int, input().split())) L += 10**5 + 1 R += 10**5 + 1 LR.append([L, R]) heapq.heappush(lq, [-1 * L, i]) heapq.heappush(rq, [R, i]) bitadd(L, 1, LBIT) bitadd(R, 1, RBIT) ans = 0 now = 10**5 + 1 for i in range(N): R_in_left = bitsum(now - 1, RBIT) L_in_right = N - i - bitsum(now, LBIT) if R_in_left >= L_in_right: # 左にあるRに移動 while len(rq) > 0 and used[rq[0][1]]: heapq.heappop(rq) if len(rq) == 0: break nexp, nexind = heapq.heappop(rq) pair = LR[nexind][0] bitadd(nexp, -1, RBIT) bitadd(pair, -1, LBIT) used[nexind] = True if nexp >= now: break ans += now - nexp now = nexp else: while len(lq) > 0 and used[lq[0][1]]: heapq.heappop(lq) if len(lq) == 0: break nexp, nexind = heapq.heappop(lq) nexp *= -1 pair = LR[nexind][1] bitadd(nexp, -1, LBIT) bitadd(pair, -1, RBIT) used[nexind] = True if nexp <= now: break ans += nexp - now now = nexp ans += abs(10**5 + 1 - now) print(ans)
N = int(eval(input())) L = [] R = [] for i in range(N): l, r = list(map(int, input().split())) L.append(2 * l) R.append(-2 * r) L.sort() R.sort() L.reverse() R.reverse() ans = 0 now = 0 for i in range(N): now += L[i] ans = max(ans, now) now += R[i] ans = max(ans, now) now = 0 for i in range(N): now += R[i] ans = max(ans, now) now += L[i] ans = max(ans, now) print(ans)
false
72.95082
[ "-\"\"\"", "-貪欲か?", "-今いる地点から左のRと右のLの数を比較", "-多い方の最遠点に行く→そのような点が無くなったら終了", "-証明は…", "-まず右のR,左のLは無意味→区間を無駄にするだけ", "-少ない方に行く→多い方の区間が無駄になる", "-近い点に行く→ ここがむずい", "-遠い区間が無駄になるのを防ぐため?", "-実装は?", "-多い方の処理→BITで左にあるRの数と右にあるLの数をlogNで", "-優先度付きキューで最小のRと最大のLを検出", "-10^5+1 を足して1 ~ 2*10^5 + 1の区間として扱う", "-初期・終了地点は 10^5+1", "-\"\"\"", "-import heapq", "-", "-", "-def bitadd(a, w, bit): # aにwを加える(1-origin)", "- x = a", "- while x <= (len(bit) - 1):", "- bit[x] += w", "- x += x & (-1 * x)", "-", "-", "-def bitsum(a, bit): # ind 1~aまでの和を求める", "- ret = 0", "- x = a", "- while x > 0:", "- ret += bit[x]", "- x -= x & (-1 * x)", "- return ret", "-", "-", "-used = [False] * N", "-lq = []", "-rq = []", "-LR = []", "-LBIT = [0] * (2 * (10**5) + 10)", "-RBIT = [0] * (2 * (10**5) + 10)", "+L = []", "+R = []", "- L, R = list(map(int, input().split()))", "- L += 10**5 + 1", "- R += 10**5 + 1", "- LR.append([L, R])", "- heapq.heappush(lq, [-1 * L, i])", "- heapq.heappush(rq, [R, i])", "- bitadd(L, 1, LBIT)", "- bitadd(R, 1, RBIT)", "+ l, r = list(map(int, input().split()))", "+ L.append(2 * l)", "+ R.append(-2 * r)", "+L.sort()", "+R.sort()", "+L.reverse()", "+R.reverse()", "-now = 10**5 + 1", "+now = 0", "- R_in_left = bitsum(now - 1, RBIT)", "- L_in_right = N - i - bitsum(now, LBIT)", "- if R_in_left >= L_in_right: # 左にあるRに移動", "- while len(rq) > 0 and used[rq[0][1]]:", "- heapq.heappop(rq)", "- if len(rq) == 0:", "- break", "- nexp, nexind = heapq.heappop(rq)", "- pair = LR[nexind][0]", "- bitadd(nexp, -1, RBIT)", "- bitadd(pair, -1, LBIT)", "- used[nexind] = True", "- if nexp >= now:", "- break", "- ans += now - nexp", "- now = nexp", "- else:", "- while len(lq) > 0 and used[lq[0][1]]:", "- heapq.heappop(lq)", "- if len(lq) == 0:", "- break", "- nexp, nexind = heapq.heappop(lq)", "- nexp *= -1", "- pair = LR[nexind][1]", "- bitadd(nexp, -1, LBIT)", "- bitadd(pair, -1, RBIT)", "- used[nexind] = True", "- if nexp <= now:", "- break", "- ans += nexp - now", "- now = nexp", "-ans += abs(10**5 + 1 - now)", "+ now += L[i]", "+ ans = max(ans, now)", "+ now += R[i]", "+ ans = max(ans, now)", "+now = 0", "+for i in range(N):", "+ now += R[i]", "+ ans = max(ans, now)", "+ now += L[i]", "+ ans = max(ans, now)" ]
false
0.056504
0.043197
1.308061
[ "s141215168", "s198972942" ]
u272028993
p03845
python
s361179931
s296450611
29
19
2,692
2,568
Accepted
Accepted
34.48
import copy n=int(input()) t=list(map(int,input().split())) m=int(input()) pt=[list(map(int,input().split())) for _ in range(m)] ans=[0]*m for i in range(m): tmp=copy.deepcopy(t) tmp[pt[i][0]-1]=pt[i][1] for j in range(n): ans[i]+=tmp[j] for i in range(m): print((ans[i]))
n=int(input()) t=list(map(int,input().split())) m=int(input()) pt=[list(map(int,input().split())) for _ in range(m)] ans=[0]*m for i in range(m): tmp=list(t) tmp[pt[i][0]-1]=pt[i][1] for j in range(n): ans[i]+=tmp[j] for i in range(m): print((ans[i]))
13
12
314
292
import copy n = int(input()) t = list(map(int, input().split())) m = int(input()) pt = [list(map(int, input().split())) for _ in range(m)] ans = [0] * m for i in range(m): tmp = copy.deepcopy(t) tmp[pt[i][0] - 1] = pt[i][1] for j in range(n): ans[i] += tmp[j] for i in range(m): print((ans[i]))
n = int(input()) t = list(map(int, input().split())) m = int(input()) pt = [list(map(int, input().split())) for _ in range(m)] ans = [0] * m for i in range(m): tmp = list(t) tmp[pt[i][0] - 1] = pt[i][1] for j in range(n): ans[i] += tmp[j] for i in range(m): print((ans[i]))
false
7.692308
[ "-import copy", "-", "- tmp = copy.deepcopy(t)", "+ tmp = list(t)" ]
false
0.041625
0.043749
0.951445
[ "s361179931", "s296450611" ]
u773265208
p02790
python
s087981570
s761940484
19
17
3,060
2,940
Accepted
Accepted
10.53
a,b = list(map(str,input().split())) a_int = int(a) b_int = int(b) ans = [] sa = '' sb = '' for _ in range(b_int): sa += a for _ in range(a_int): sb += b ans.append(sa) ans.append(sb) ans.sort() print((ans[0]))
a,b = list(map(int,input().split())) if a > b: print((str(b)*a)) else: print((str(a)*b))
19
6
228
89
a, b = list(map(str, input().split())) a_int = int(a) b_int = int(b) ans = [] sa = "" sb = "" for _ in range(b_int): sa += a for _ in range(a_int): sb += b ans.append(sa) ans.append(sb) ans.sort() print((ans[0]))
a, b = list(map(int, input().split())) if a > b: print((str(b) * a)) else: print((str(a) * b))
false
68.421053
[ "-a, b = list(map(str, input().split()))", "-a_int = int(a)", "-b_int = int(b)", "-ans = []", "-sa = \"\"", "-sb = \"\"", "-for _ in range(b_int):", "- sa += a", "-for _ in range(a_int):", "- sb += b", "-ans.append(sa)", "-ans.append(sb)", "-ans.sort()", "-print((ans[0]))", "+a, b = list(map(int, input().split()))", "+if a > b:", "+ print((str(b) * a))", "+else:", "+ print((str(a) * b))" ]
false
0.068023
0.067272
1.011168
[ "s087981570", "s761940484" ]
u631277801
p03576
python
s208199436
s785283452
1,429
1,304
48,220
3,188
Accepted
Accepted
8.75
import sys stdin = sys.stdin def li(): return list(map(int, stdin.readline().split())) def li_(): return [int(x)-1 for x in stdin.readline().split()] def lf(): return list(map(float, stdin.readline().split())) def ls(): return stdin.readline().split() def ns(): return stdin.readline().rstrip() def lc(): return list(ns()) def ni(): return int(stdin.readline()) def nf(): return float(stdin.readline()) n,k = li() xs = [] ys = [] points = [] for _ in range(n): x,y = li() xs.append(x) ys.append(y) points.append((x,y)) xs.sort() ys.sort() ans = float("inf") for xst in range(n): for xed in range(xst+1,n): for yst in range(n): for yed in range(yst+1, n): cnt = 0 for px,py in points: if xs[xst] <= px <= xs[xed] and ys[yst] <= py <= ys[yed]: cnt += 1 if cnt >= k: ans = min(ans, (xs[xed]-xs[xst])*(ys[yed]-ys[yst])) print(ans)
import sys stdin = sys.stdin def li(): return map(int, stdin.readline().split()) def li_(): return map(lambda x: int(x)-1, stdin.readline().split()) def lf(): return map(float, stdin.readline().split()) def ls(): return stdin.readline().split() def ns(): return stdin.readline().rstrip() def lc(): return list(ns()) def ni(): return int(stdin.readline()) def nf(): return float(stdin.readline()) from itertools import accumulate n,k = li() xs = [] ys = [] points = [] for _ in range(n): x,y = li() xs.append(x) ys.append(y) points.append((x,y)) xs.sort() ys.sort() rank_x = {} rank_y = {} for i, x in enumerate(xs): rank_x.update({x:i+1}) for i, y in enumerate(ys): rank_y.update({y:i+1}) field = [[0 for _ in range(n+1)] for _ in range(n+1)] for px,py in points: field[rank_y[py]][rank_x[px]] = 1 for row in range(n+1): field[row] = list(accumulate(field[row])) for col in range(n+1): for row in range(n): field[row+1][col] += field[row][col] ans = float("inf") for xst in range(n): for xed in range(xst+1,n): for yst in range(n): for yed in range(yst+1,n): if field[yed+1][xed+1] + field[yst][xst] \ -field[yed+1][xst] - field[yst][xed+1]>= k: ans = min(ans, (xs[xed]-xs[xst])*(ys[yed]-ys[yst])) print(ans)
39
55
1,063
1,408
import sys stdin = sys.stdin def li(): return list(map(int, stdin.readline().split())) def li_(): return [int(x) - 1 for x in stdin.readline().split()] def lf(): return list(map(float, stdin.readline().split())) def ls(): return stdin.readline().split() def ns(): return stdin.readline().rstrip() def lc(): return list(ns()) def ni(): return int(stdin.readline()) def nf(): return float(stdin.readline()) n, k = li() xs = [] ys = [] points = [] for _ in range(n): x, y = li() xs.append(x) ys.append(y) points.append((x, y)) xs.sort() ys.sort() ans = float("inf") for xst in range(n): for xed in range(xst + 1, n): for yst in range(n): for yed in range(yst + 1, n): cnt = 0 for px, py in points: if xs[xst] <= px <= xs[xed] and ys[yst] <= py <= ys[yed]: cnt += 1 if cnt >= k: ans = min(ans, (xs[xed] - xs[xst]) * (ys[yed] - ys[yst])) print(ans)
import sys stdin = sys.stdin def li(): return map(int, stdin.readline().split()) def li_(): return map(lambda x: int(x) - 1, stdin.readline().split()) def lf(): return map(float, stdin.readline().split()) def ls(): return stdin.readline().split() def ns(): return stdin.readline().rstrip() def lc(): return list(ns()) def ni(): return int(stdin.readline()) def nf(): return float(stdin.readline()) from itertools import accumulate n, k = li() xs = [] ys = [] points = [] for _ in range(n): x, y = li() xs.append(x) ys.append(y) points.append((x, y)) xs.sort() ys.sort() rank_x = {} rank_y = {} for i, x in enumerate(xs): rank_x.update({x: i + 1}) for i, y in enumerate(ys): rank_y.update({y: i + 1}) field = [[0 for _ in range(n + 1)] for _ in range(n + 1)] for px, py in points: field[rank_y[py]][rank_x[px]] = 1 for row in range(n + 1): field[row] = list(accumulate(field[row])) for col in range(n + 1): for row in range(n): field[row + 1][col] += field[row][col] ans = float("inf") for xst in range(n): for xed in range(xst + 1, n): for yst in range(n): for yed in range(yst + 1, n): if ( field[yed + 1][xed + 1] + field[yst][xst] - field[yed + 1][xst] - field[yst][xed + 1] >= k ): ans = min(ans, (xs[xed] - xs[xst]) * (ys[yed] - ys[yst])) print(ans)
false
29.090909
[ "- return list(map(int, stdin.readline().split()))", "+ return map(int, stdin.readline().split())", "- return [int(x) - 1 for x in stdin.readline().split()]", "+ return map(lambda x: int(x) - 1, stdin.readline().split())", "- return list(map(float, stdin.readline().split()))", "+ return map(float, stdin.readline().split())", "+from itertools import accumulate", "+", "+rank_x = {}", "+rank_y = {}", "+for i, x in enumerate(xs):", "+ rank_x.update({x: i + 1})", "+for i, y in enumerate(ys):", "+ rank_y.update({y: i + 1})", "+field = [[0 for _ in range(n + 1)] for _ in range(n + 1)]", "+for px, py in points:", "+ field[rank_y[py]][rank_x[px]] = 1", "+for row in range(n + 1):", "+ field[row] = list(accumulate(field[row]))", "+for col in range(n + 1):", "+ for row in range(n):", "+ field[row + 1][col] += field[row][col]", "- cnt = 0", "- for px, py in points:", "- if xs[xst] <= px <= xs[xed] and ys[yst] <= py <= ys[yed]:", "- cnt += 1", "- if cnt >= k:", "+ if (", "+ field[yed + 1][xed + 1]", "+ + field[yst][xst]", "+ - field[yed + 1][xst]", "+ - field[yst][xed + 1]", "+ >= k", "+ ):" ]
false
0.039531
0.038542
1.025649
[ "s208199436", "s785283452" ]
u968166680
p02838
python
s284853051
s162750883
313
212
118,580
136,744
Accepted
Accepted
32.27
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())) ans = 0 p = 1 for _ in range(60): n = 0 for i in range(N): if A[i] % 2: n += 1 A[i] //= 2 ans = (ans + n * (N - n) * p) % MOD p = p * 2 % 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())) ans = 0 p = 1 for _ in range(60): n = 0 for i in range(N): A[i], d = A[i] // 2, A[i] % 2 n += d ans = (ans + n * (N - n) * p) % MOD p = p * 2 % MOD print(ans) return if __name__ == '__main__': main()
30
29
532
521
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())) ans = 0 p = 1 for _ in range(60): n = 0 for i in range(N): if A[i] % 2: n += 1 A[i] //= 2 ans = (ans + n * (N - n) * p) % MOD p = p * 2 % 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())) ans = 0 p = 1 for _ in range(60): n = 0 for i in range(N): A[i], d = A[i] // 2, A[i] % 2 n += d ans = (ans + n * (N - n) * p) % MOD p = p * 2 % MOD print(ans) return if __name__ == "__main__": main()
false
3.333333
[ "- if A[i] % 2:", "- n += 1", "- A[i] //= 2", "+ A[i], d = A[i] // 2, A[i] % 2", "+ n += d" ]
false
0.041673
0.068078
0.612129
[ "s284853051", "s162750883" ]
u949338836
p02390
python
s412207181
s970898842
40
30
6,724
6,724
Accepted
Accepted
25
#coding:utf-8 #1_1_D 2015.3.6 second = int(eval(input())) hour = second // 3600 minutes = (second // 60) % 60 second %= 60 print(("%s:%s:%s" %(hour,minutes,second)))
#coding:utf-8 #1_1_D 2015.3.6 second = int(eval(input())) hour = second // 3600 minutes = (second // 60) % 60 second %= 60 print(("{}:{}:{}".format(hour,minutes,second)))
7
7
163
168
# coding:utf-8 # 1_1_D 2015.3.6 second = int(eval(input())) hour = second // 3600 minutes = (second // 60) % 60 second %= 60 print(("%s:%s:%s" % (hour, minutes, second)))
# coding:utf-8 # 1_1_D 2015.3.6 second = int(eval(input())) hour = second // 3600 minutes = (second // 60) % 60 second %= 60 print(("{}:{}:{}".format(hour, minutes, second)))
false
0
[ "-print((\"%s:%s:%s\" % (hour, minutes, second)))", "+print((\"{}:{}:{}\".format(hour, minutes, second)))" ]
false
0.071436
0.041233
1.732485
[ "s412207181", "s970898842" ]
u060793972
p03379
python
s438967659
s196597039
301
201
26,180
28,608
Accepted
Accepted
33.22
n=int(eval(input())) x=list(map(int,input().split())) lr,rr=sorted(x)[n//2-1:n//2+1] for i in x: print((lr if lr<i else rr))
n=int(eval(input())) x=list(map(int,input().split())) lr,rr=sorted(x)[n//2-1:n//2+1] print(('\n'.join([str(lr) if lr<i else str(rr) for i in x])))
5
4
124
141
n = int(eval(input())) x = list(map(int, input().split())) lr, rr = sorted(x)[n // 2 - 1 : n // 2 + 1] for i in x: print((lr if lr < i else rr))
n = int(eval(input())) x = list(map(int, input().split())) lr, rr = sorted(x)[n // 2 - 1 : n // 2 + 1] print(("\n".join([str(lr) if lr < i else str(rr) for i in x])))
false
20
[ "-for i in x:", "- print((lr if lr < i else rr))", "+print((\"\\n\".join([str(lr) if lr < i else str(rr) for i in x])))" ]
false
0.041603
0.03856
1.078913
[ "s438967659", "s196597039" ]
u433380437
p02803
python
s525859923
s774141388
165
130
75,232
74,616
Accepted
Accepted
21.21
from collections import deque H, W = list(map(int, input().split())) maze = [eval(input()) for i in range(H)] def bfs(maze, sy, sx): visited = [[-1]*W for j in range(H)] queue = deque([[sy, sx]]) visited[sy][sx] = 0 while queue: ans=0 y, x = queue.popleft() for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]): new_y, new_x = y+j, x+k if 0 <= new_y < H and 0 <= new_x < W: if maze[new_y][new_x] == "." and visited[new_y][new_x] == -1 : visited[new_y][new_x] = visited[y][x] + 1 queue.append([new_y, new_x]) for l in range(H): for m in range(W): ans = max(ans,visited[l][m]) return ans ma=0 for sy in range(H): for sx in range(W): if maze[sy][sx] == ".": if bfs(maze,sy,sx) is not None: ma = max(bfs(maze, sy, sx),ma) print(ma)
h,w = list(map(int,input().split())) C = [list(eval(input())) for i in range(h)] queue = [] visited = [] visited = [[0 for i in range(w)] for i in range(h)] ans = 0 for i in range(h): for j in range(w): if C[i][j] == '.': queue.append([i,j]) visited[i][j] = 1 dy_dx = [[1,0],[0,1],[-1,0],[0,-1]] while len(queue) > 0: now = queue.pop(0) for k in range(4): y = now[0]+dy_dx[k][0] x = now[1]+dy_dx[k][1] if 0 <= y < h and 0 <= x < w: if C[y][x] != '#' and visited[y][x] == 0: visited[y][x] = visited[now[0]][now[1]]+1 #移動回数のカウント queue.append([y,x]) for l in range(h): for m in range(w): ans = max(ans,visited[l][m]) queue = [] visited = [[0 for i in range(w)] for i in range(h)] print((ans-1))
31
34
972
1,056
from collections import deque H, W = list(map(int, input().split())) maze = [eval(input()) for i in range(H)] def bfs(maze, sy, sx): visited = [[-1] * W for j in range(H)] queue = deque([[sy, sx]]) visited[sy][sx] = 0 while queue: ans = 0 y, x = queue.popleft() for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]): new_y, new_x = y + j, x + k if 0 <= new_y < H and 0 <= new_x < W: if maze[new_y][new_x] == "." and visited[new_y][new_x] == -1: visited[new_y][new_x] = visited[y][x] + 1 queue.append([new_y, new_x]) for l in range(H): for m in range(W): ans = max(ans, visited[l][m]) return ans ma = 0 for sy in range(H): for sx in range(W): if maze[sy][sx] == ".": if bfs(maze, sy, sx) is not None: ma = max(bfs(maze, sy, sx), ma) print(ma)
h, w = list(map(int, input().split())) C = [list(eval(input())) for i in range(h)] queue = [] visited = [] visited = [[0 for i in range(w)] for i in range(h)] ans = 0 for i in range(h): for j in range(w): if C[i][j] == ".": queue.append([i, j]) visited[i][j] = 1 dy_dx = [[1, 0], [0, 1], [-1, 0], [0, -1]] while len(queue) > 0: now = queue.pop(0) for k in range(4): y = now[0] + dy_dx[k][0] x = now[1] + dy_dx[k][1] if 0 <= y < h and 0 <= x < w: if C[y][x] != "#" and visited[y][x] == 0: visited[y][x] = visited[now[0]][now[1]] + 1 # 移動回数のカウント queue.append([y, x]) for l in range(h): for m in range(w): ans = max(ans, visited[l][m]) queue = [] visited = [[0 for i in range(w)] for i in range(h)] print((ans - 1))
false
8.823529
[ "-from collections import deque", "-", "-H, W = list(map(int, input().split()))", "-maze = [eval(input()) for i in range(H)]", "-", "-", "-def bfs(maze, sy, sx):", "- visited = [[-1] * W for j in range(H)]", "- queue = deque([[sy, sx]])", "- visited[sy][sx] = 0", "- while queue:", "- ans = 0", "- y, x = queue.popleft()", "- for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]):", "- new_y, new_x = y + j, x + k", "- if 0 <= new_y < H and 0 <= new_x < W:", "- if maze[new_y][new_x] == \".\" and visited[new_y][new_x] == -1:", "- visited[new_y][new_x] = visited[y][x] + 1", "- queue.append([new_y, new_x])", "- for l in range(H):", "- for m in range(W):", "- ans = max(ans, visited[l][m])", "- return ans", "-", "-", "-ma = 0", "-for sy in range(H):", "- for sx in range(W):", "- if maze[sy][sx] == \".\":", "- if bfs(maze, sy, sx) is not None:", "- ma = max(bfs(maze, sy, sx), ma)", "-print(ma)", "+h, w = list(map(int, input().split()))", "+C = [list(eval(input())) for i in range(h)]", "+queue = []", "+visited = []", "+visited = [[0 for i in range(w)] for i in range(h)]", "+ans = 0", "+for i in range(h):", "+ for j in range(w):", "+ if C[i][j] == \".\":", "+ queue.append([i, j])", "+ visited[i][j] = 1", "+ dy_dx = [[1, 0], [0, 1], [-1, 0], [0, -1]]", "+ while len(queue) > 0:", "+ now = queue.pop(0)", "+ for k in range(4):", "+ y = now[0] + dy_dx[k][0]", "+ x = now[1] + dy_dx[k][1]", "+ if 0 <= y < h and 0 <= x < w:", "+ if C[y][x] != \"#\" and visited[y][x] == 0:", "+ visited[y][x] = visited[now[0]][now[1]] + 1 # 移動回数のカウント", "+ queue.append([y, x])", "+ for l in range(h):", "+ for m in range(w):", "+ ans = max(ans, visited[l][m])", "+ queue = []", "+ visited = [[0 for i in range(w)] for i in range(h)]", "+print((ans - 1))" ]
false
0.040551
0.078874
0.514124
[ "s525859923", "s774141388" ]
u671060652
p03086
python
s417044607
s740258057
296
64
67,052
61,836
Accepted
Accepted
78.38
import itertools import math import fractions import functools import copy s = eval(input()) maximum = 0 count = 0 for i in range(len(s)): if s[i] == "A" or s[i] == "C" or s[i] == "G" or s[i] == "T": count += 1 maximum = max(maximum,count) else: count = 0 print(maximum)
def main(): # n = int(input()) # n, m = map(int, input().split()) # a = list(map(int, input().split())) s = eval(input()) # h = [int(input()) for _ in rane(n)] count = 0 maxi = 0 for string in s: if string == "A" or string == "C" or string == "G" or string == "T": count += 1 maxi= max(count, maxi) else: count = 0 print(maxi) if __name__ == '__main__': main()
18
20
317
469
import itertools import math import fractions import functools import copy s = eval(input()) maximum = 0 count = 0 for i in range(len(s)): if s[i] == "A" or s[i] == "C" or s[i] == "G" or s[i] == "T": count += 1 maximum = max(maximum, count) else: count = 0 print(maximum)
def main(): # n = int(input()) # n, m = map(int, input().split()) # a = list(map(int, input().split())) s = eval(input()) # h = [int(input()) for _ in rane(n)] count = 0 maxi = 0 for string in s: if string == "A" or string == "C" or string == "G" or string == "T": count += 1 maxi = max(count, maxi) else: count = 0 print(maxi) if __name__ == "__main__": main()
false
10
[ "-import itertools", "-import math", "-import fractions", "-import functools", "-import copy", "+def main():", "+ # n = int(input())", "+ # n, m = map(int, input().split())", "+ # a = list(map(int, input().split()))", "+ s = eval(input())", "+ # h = [int(input()) for _ in rane(n)]", "+ count = 0", "+ maxi = 0", "+ for string in s:", "+ if string == \"A\" or string == \"C\" or string == \"G\" or string == \"T\":", "+ count += 1", "+ maxi = max(count, maxi)", "+ else:", "+ count = 0", "+ print(maxi)", "-s = eval(input())", "-maximum = 0", "-count = 0", "-for i in range(len(s)):", "- if s[i] == \"A\" or s[i] == \"C\" or s[i] == \"G\" or s[i] == \"T\":", "- count += 1", "- maximum = max(maximum, count)", "- else:", "- count = 0", "-print(maximum)", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.035994
0.04554
0.790396
[ "s417044607", "s740258057" ]
u368249389
p02689
python
s454124211
s723665219
300
261
20,164
20,116
Accepted
Accepted
13
# Problem C - Peaks # input N, M = list(map(int, input().split())) h_list = list(map(int, input().split())) # initialization score_list = [0]*N for i in range(M): a, b = list(map(int, input().split())) if h_list[a-1]<h_list[b-1]: if h_list[b-1]>=0: score_list[b-1] += 1 else: score_list[b-1] = -1 * float("INF") score_list[a-1] = -1 * float("INF") elif h_list[a-1]>h_list[b-1]: if h_list[a-1]>=0: score_list[a-1] += 1 else: score_list[a-1] = -1 * float("INF") score_list[b-1] = -1 * float("INF") else: score_list[a-1] = -1 * float("INF") score_list[b-1] = -1 * float("INF") # output ans = 0 for s in score_list: if s>=0: ans += 1 print(ans)
# Problem C - Peaks # input N, M = list(map(int, input().split())) h_list = list(map(int, input().split())) # initialization ans_list = [1]*N ans = 0 # count for m in range(M): a, b = list(map(int, input().split())) if h_list[a-1]>h_list[b-1]: ans_list[b-1] = -1 elif h_list[a-1]<h_list[b-1]: ans_list[a-1] = -1 else: ans_list[a-1] = -1 ans_list[b-1] = -1 # check for a in ans_list: if a>0: ans += 1 # output print(ans)
32
28
804
500
# Problem C - Peaks # input N, M = list(map(int, input().split())) h_list = list(map(int, input().split())) # initialization score_list = [0] * N for i in range(M): a, b = list(map(int, input().split())) if h_list[a - 1] < h_list[b - 1]: if h_list[b - 1] >= 0: score_list[b - 1] += 1 else: score_list[b - 1] = -1 * float("INF") score_list[a - 1] = -1 * float("INF") elif h_list[a - 1] > h_list[b - 1]: if h_list[a - 1] >= 0: score_list[a - 1] += 1 else: score_list[a - 1] = -1 * float("INF") score_list[b - 1] = -1 * float("INF") else: score_list[a - 1] = -1 * float("INF") score_list[b - 1] = -1 * float("INF") # output ans = 0 for s in score_list: if s >= 0: ans += 1 print(ans)
# Problem C - Peaks # input N, M = list(map(int, input().split())) h_list = list(map(int, input().split())) # initialization ans_list = [1] * N ans = 0 # count for m in range(M): a, b = list(map(int, input().split())) if h_list[a - 1] > h_list[b - 1]: ans_list[b - 1] = -1 elif h_list[a - 1] < h_list[b - 1]: ans_list[a - 1] = -1 else: ans_list[a - 1] = -1 ans_list[b - 1] = -1 # check for a in ans_list: if a > 0: ans += 1 # output print(ans)
false
12.5
[ "-score_list = [0] * N", "-for i in range(M):", "+ans_list = [1] * N", "+ans = 0", "+# count", "+for m in range(M):", "- if h_list[a - 1] < h_list[b - 1]:", "- if h_list[b - 1] >= 0:", "- score_list[b - 1] += 1", "- else:", "- score_list[b - 1] = -1 * float(\"INF\")", "- score_list[a - 1] = -1 * float(\"INF\")", "- elif h_list[a - 1] > h_list[b - 1]:", "- if h_list[a - 1] >= 0:", "- score_list[a - 1] += 1", "- else:", "- score_list[a - 1] = -1 * float(\"INF\")", "- score_list[b - 1] = -1 * float(\"INF\")", "+ if h_list[a - 1] > h_list[b - 1]:", "+ ans_list[b - 1] = -1", "+ elif h_list[a - 1] < h_list[b - 1]:", "+ ans_list[a - 1] = -1", "- score_list[a - 1] = -1 * float(\"INF\")", "- score_list[b - 1] = -1 * float(\"INF\")", "+ ans_list[a - 1] = -1", "+ ans_list[b - 1] = -1", "+# check", "+for a in ans_list:", "+ if a > 0:", "+ ans += 1", "-ans = 0", "-for s in score_list:", "- if s >= 0:", "- ans += 1" ]
false
0.064511
0.063199
1.020755
[ "s454124211", "s723665219" ]
u332385682
p03701
python
s269883640
s737318021
132
18
3,188
3,060
Accepted
Accepted
86.36
import sys from itertools import accumulate def solve(): n = int(eval(input())) s = [int(eval(input())) for i in range(n)] lim = n * 100 dp = [False] * (lim + 1) dp[0] = True for i in range(n): for j in range(lim, s[i] - 1, -1): dp[j] |= dp[j - s[i]] for i in range(lim, 0, -1): if i % 10 == 0: continue if dp[i]: print(i) return print((0)) if __name__ == '__main__': solve()
import sys def solve(): n = int(eval(input())) s = [int(eval(input())) for i in range(n)] s.sort() ssum = sum(s) if ssum % 10: print(ssum) else: for si in s: if si % 10: print((ssum - si)) return print((0)) if __name__ == '__main__': solve()
26
21
500
346
import sys from itertools import accumulate def solve(): n = int(eval(input())) s = [int(eval(input())) for i in range(n)] lim = n * 100 dp = [False] * (lim + 1) dp[0] = True for i in range(n): for j in range(lim, s[i] - 1, -1): dp[j] |= dp[j - s[i]] for i in range(lim, 0, -1): if i % 10 == 0: continue if dp[i]: print(i) return print((0)) if __name__ == "__main__": solve()
import sys def solve(): n = int(eval(input())) s = [int(eval(input())) for i in range(n)] s.sort() ssum = sum(s) if ssum % 10: print(ssum) else: for si in s: if si % 10: print((ssum - si)) return print((0)) if __name__ == "__main__": solve()
false
19.230769
[ "-from itertools import accumulate", "- lim = n * 100", "- dp = [False] * (lim + 1)", "- dp[0] = True", "- for i in range(n):", "- for j in range(lim, s[i] - 1, -1):", "- dp[j] |= dp[j - s[i]]", "- for i in range(lim, 0, -1):", "- if i % 10 == 0:", "- continue", "- if dp[i]:", "- print(i)", "- return", "- print((0))", "+ s.sort()", "+ ssum = sum(s)", "+ if ssum % 10:", "+ print(ssum)", "+ else:", "+ for si in s:", "+ if si % 10:", "+ print((ssum - si))", "+ return", "+ print((0))" ]
false
0.04517
0.043019
1.049989
[ "s269883640", "s737318021" ]
u083960235
p03795
python
s715120052
s667361305
40
27
5,148
3,892
Accepted
Accepted
32.5
import sys, re, os from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import permutations, combinations, product, accumulate from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from fractions import gcd def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def S_MAP(): return list(map(str, input().split())) def LIST(): return list(map(int, input().split())) def S_LIST(): return list(map(str, input().split())) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10 ** 9 + 7 N = INT() c = N // 15 a = N * 800 - c * 200 print(a)
import sys, re, os from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import permutations, combinations, product, accumulate from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from heapq import heapify, heappop, heappush def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def S_MAP(): return list(map(str, input().split())) def LIST(): return list(map(int, input().split())) def S_LIST(): return list(map(str, input().split())) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10 ** 9 + 7 N = INT() x = N * 800 y = N // 15 * 200 print((x - y))
27
24
786
800
import sys, re, os from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import permutations, combinations, product, accumulate from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from fractions import gcd def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def S_MAP(): return list(map(str, input().split())) def LIST(): return list(map(int, input().split())) def S_LIST(): return list(map(str, input().split())) sys.setrecursionlimit(10**9) INF = float("inf") mod = 10**9 + 7 N = INT() c = N // 15 a = N * 800 - c * 200 print(a)
import sys, re, os from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import permutations, combinations, product, accumulate from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from heapq import heapify, heappop, heappush def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def S_MAP(): return list(map(str, input().split())) def LIST(): return list(map(int, input().split())) def S_LIST(): return list(map(str, input().split())) sys.setrecursionlimit(10**9) INF = float("inf") mod = 10**9 + 7 N = INT() x = N * 800 y = N // 15 * 200 print((x - y))
false
11.111111
[ "-from fractions import gcd", "+from heapq import heapify, heappop, heappush", "-c = N // 15", "-a = N * 800 - c * 200", "-print(a)", "+x = N * 800", "+y = N // 15 * 200", "+print((x - y))" ]
false
0.072945
0.040262
1.81178
[ "s715120052", "s667361305" ]
u305366205
p02796
python
s419755907
s595137059
455
407
16,996
18,260
Accepted
Accepted
10.55
n = int(eval(input())) robots = [] for _ in range(n): xi, li = list(map(int, input().split())) robots.append((xi + li, xi - li)) robots.sort() ans = n pre_right = robots[0][0] for i in range(1, n): now_left = robots[i][1] if pre_right > now_left: ans -= 1 else: pre_right = robots[i][0] print(ans)
n = int(eval(input())) robots = [] for _ in range(n): xi, li = list(map(int, input().split())) robots.append((xi - li, xi + li)) robots.sort(key=lambda x: x[1]) ans = 0 pre_r = -float('inf') for l, r in robots: if pre_r <= l: ans += 1 pre_r = r print(ans)
15
13
336
284
n = int(eval(input())) robots = [] for _ in range(n): xi, li = list(map(int, input().split())) robots.append((xi + li, xi - li)) robots.sort() ans = n pre_right = robots[0][0] for i in range(1, n): now_left = robots[i][1] if pre_right > now_left: ans -= 1 else: pre_right = robots[i][0] print(ans)
n = int(eval(input())) robots = [] for _ in range(n): xi, li = list(map(int, input().split())) robots.append((xi - li, xi + li)) robots.sort(key=lambda x: x[1]) ans = 0 pre_r = -float("inf") for l, r in robots: if pre_r <= l: ans += 1 pre_r = r print(ans)
false
13.333333
[ "- robots.append((xi + li, xi - li))", "-robots.sort()", "-ans = n", "-pre_right = robots[0][0]", "-for i in range(1, n):", "- now_left = robots[i][1]", "- if pre_right > now_left:", "- ans -= 1", "- else:", "- pre_right = robots[i][0]", "+ robots.append((xi - li, xi + li))", "+robots.sort(key=lambda x: x[1])", "+ans = 0", "+pre_r = -float(\"inf\")", "+for l, r in robots:", "+ if pre_r <= l:", "+ ans += 1", "+ pre_r = r" ]
false
0.040022
0.047616
0.840525
[ "s419755907", "s595137059" ]
u912237403
p00071
python
s588219945
s628385876
20
10
4,280
4,288
Accepted
Accepted
50
def bomb(x,y): s=M[y] if s[x]=="0":return M[y]=s[:x]+"0"+s[x+1:] for e in [-3,-2,-1,1,2,3]: bomb(x+e,y) bomb(x,y+e) return A=list(range(14)) B=list(range(3,11)) M=["00000000000000" for i in A] z="000" n=eval(input()) for i in range(n): s=input() for j in B: M[j]=z+input()+z x=eval(input())+2 y=eval(input())+2 bomb(x,y) print("Data %d:" %(i+1)) for j in B: print(M[j][3:-3])
def bomb(x,y): s=M[y] if s[x]=="0":return M[y]=s[:x]+"0"+s[x+1:] R=[-3,-2,-1,1,2,3] for e in R: bomb(x+e,y) bomb(x,y+e) return A=list(range(14)) B=list(range(3,11)) M=["00000000000000" for i in A] z="000" n=eval(input()) for i in range(n): s=input() for j in B: M[j]=z+input()+z x=eval(input())+2 y=eval(input())+2 bomb(x,y) print("Data %d:" %(i+1)) for j in B: print(M[j][3:-3])
24
25
455
464
def bomb(x, y): s = M[y] if s[x] == "0": return M[y] = s[:x] + "0" + s[x + 1 :] for e in [-3, -2, -1, 1, 2, 3]: bomb(x + e, y) bomb(x, y + e) return A = list(range(14)) B = list(range(3, 11)) M = ["00000000000000" for i in A] z = "000" n = eval(input()) for i in range(n): s = input() for j in B: M[j] = z + input() + z x = eval(input()) + 2 y = eval(input()) + 2 bomb(x, y) print("Data %d:" % (i + 1)) for j in B: print(M[j][3:-3])
def bomb(x, y): s = M[y] if s[x] == "0": return M[y] = s[:x] + "0" + s[x + 1 :] R = [-3, -2, -1, 1, 2, 3] for e in R: bomb(x + e, y) bomb(x, y + e) return A = list(range(14)) B = list(range(3, 11)) M = ["00000000000000" for i in A] z = "000" n = eval(input()) for i in range(n): s = input() for j in B: M[j] = z + input() + z x = eval(input()) + 2 y = eval(input()) + 2 bomb(x, y) print("Data %d:" % (i + 1)) for j in B: print(M[j][3:-3])
false
4
[ "- for e in [-3, -2, -1, 1, 2, 3]:", "+ R = [-3, -2, -1, 1, 2, 3]", "+ for e in R:" ]
false
0.04139
0.031545
1.312103
[ "s588219945", "s628385876" ]
u827448139
p00275
python
s445758880
s335153704
50
40
6,724
6,724
Accepted
Accepted
20
while 1: n=int(eval(input())) if n==0: break cs=eval(input()) a,b=[0]*n,0 for i in range(100): if cs[i]=="M": a[i%n]+=1 elif cs[i]=="S": a[i%n],b=0,b+1+a[i%n] elif cs[i]=="L": a[i%n],b=a[i%n]+1+b,0 a.sort() print((" ".join(map(str,a+[b]))))
while 1: n=int(eval(input())) if n==0: break a,b,i=[0]*n,0,0 for c in eval(input()): if c=="M": a[i]+=1 elif c=="S": a[i],b=0,b+1+a[i] elif c=="L": a[i],b=a[i]+1+b,0 i=(i+1)%n a.sort() print((" ".join(map(str,a+[b]))))
14
11
283
242
while 1: n = int(eval(input())) if n == 0: break cs = eval(input()) a, b = [0] * n, 0 for i in range(100): if cs[i] == "M": a[i % n] += 1 elif cs[i] == "S": a[i % n], b = 0, b + 1 + a[i % n] elif cs[i] == "L": a[i % n], b = a[i % n] + 1 + b, 0 a.sort() print((" ".join(map(str, a + [b]))))
while 1: n = int(eval(input())) if n == 0: break a, b, i = [0] * n, 0, 0 for c in eval(input()): if c == "M": a[i] += 1 elif c == "S": a[i], b = 0, b + 1 + a[i] elif c == "L": a[i], b = a[i] + 1 + b, 0 i = (i + 1) % n a.sort() print((" ".join(map(str, a + [b]))))
false
21.428571
[ "- cs = eval(input())", "- a, b = [0] * n, 0", "- for i in range(100):", "- if cs[i] == \"M\":", "- a[i % n] += 1", "- elif cs[i] == \"S\":", "- a[i % n], b = 0, b + 1 + a[i % n]", "- elif cs[i] == \"L\":", "- a[i % n], b = a[i % n] + 1 + b, 0", "+ a, b, i = [0] * n, 0, 0", "+ for c in eval(input()):", "+ if c == \"M\":", "+ a[i] += 1", "+ elif c == \"S\":", "+ a[i], b = 0, b + 1 + a[i]", "+ elif c == \"L\":", "+ a[i], b = a[i] + 1 + b, 0", "+ i = (i + 1) % n" ]
false
0.041665
0.043363
0.960857
[ "s445758880", "s335153704" ]
u353638740
p03854
python
s410166427
s709098654
157
90
3,444
3,188
Accepted
Accepted
42.68
str_list = ["dream","erase","er","ase","r",] class stringJudge(): def __init__(self,string,string_list): self.string = string self.string_list = string_list def isNextMatch(self): for (i,str_val) in enumerate(str_list): if self.string.startswith(str_val): self.string = self.string.split(str_val,1)[1] if len(self.string) == 0: return True if i ==0: if self.string.startswith(self.string_list[0]) or self.string.startswith(self.string_list[2]): return True elif i == 1: if self.string.startswith(self.string_list[0]) or self.string.startswith(self.string_list[1]) or self.string.startswith(self.string_list[4]): return True elif i == 2: if self.string.startswith(self.string_list[0]) or self.string.startswith(self.string_list[1]) or self.string.startswith(self.string_list[3]): return True elif i == 3: if self.string.startswith(self.string_list[0]) or self.string.startswith(self.string_list[1]) or self.string.startswith(self.string_list[4]): return True elif i == 4: if self.string.startswith(self.string_list[0]) or self.string.startswith(self.string_list[1]): return True return False instance = stringJudge(eval(input()),str_list) check = True while check and len(instance.string) > 0: check = instance.isNextMatch() print(('YES' if check else 'NO'))
str_list = ["dream","dreamer","erase","eraser"] class stringJudge(): def __init__(self,string,string_list): self.string = string self.string_list = string_list def isNextMatch(self): for str_val in self.string_list: if self.string.endswith(str_val): self.string = self.string.rsplit(str_val,1)[0] return True return False instance = stringJudge(eval(input()),str_list) check = True while check and len(instance.string) > 0: check = instance.isNextMatch() print(('YES' if check else 'NO'))
39
24
1,766
677
str_list = [ "dream", "erase", "er", "ase", "r", ] class stringJudge: def __init__(self, string, string_list): self.string = string self.string_list = string_list def isNextMatch(self): for (i, str_val) in enumerate(str_list): if self.string.startswith(str_val): self.string = self.string.split(str_val, 1)[1] if len(self.string) == 0: return True if i == 0: if self.string.startswith( self.string_list[0] ) or self.string.startswith(self.string_list[2]): return True elif i == 1: if ( self.string.startswith(self.string_list[0]) or self.string.startswith(self.string_list[1]) or self.string.startswith(self.string_list[4]) ): return True elif i == 2: if ( self.string.startswith(self.string_list[0]) or self.string.startswith(self.string_list[1]) or self.string.startswith(self.string_list[3]) ): return True elif i == 3: if ( self.string.startswith(self.string_list[0]) or self.string.startswith(self.string_list[1]) or self.string.startswith(self.string_list[4]) ): return True elif i == 4: if self.string.startswith( self.string_list[0] ) or self.string.startswith(self.string_list[1]): return True return False instance = stringJudge(eval(input()), str_list) check = True while check and len(instance.string) > 0: check = instance.isNextMatch() print(("YES" if check else "NO"))
str_list = ["dream", "dreamer", "erase", "eraser"] class stringJudge: def __init__(self, string, string_list): self.string = string self.string_list = string_list def isNextMatch(self): for str_val in self.string_list: if self.string.endswith(str_val): self.string = self.string.rsplit(str_val, 1)[0] return True return False instance = stringJudge(eval(input()), str_list) check = True while check and len(instance.string) > 0: check = instance.isNextMatch() print(("YES" if check else "NO"))
false
38.461538
[ "-str_list = [", "- \"dream\",", "- \"erase\",", "- \"er\",", "- \"ase\",", "- \"r\",", "-]", "+str_list = [\"dream\", \"dreamer\", \"erase\", \"eraser\"]", "- for (i, str_val) in enumerate(str_list):", "- if self.string.startswith(str_val):", "- self.string = self.string.split(str_val, 1)[1]", "- if len(self.string) == 0:", "- return True", "- if i == 0:", "- if self.string.startswith(", "- self.string_list[0]", "- ) or self.string.startswith(self.string_list[2]):", "- return True", "- elif i == 1:", "- if (", "- self.string.startswith(self.string_list[0])", "- or self.string.startswith(self.string_list[1])", "- or self.string.startswith(self.string_list[4])", "- ):", "- return True", "- elif i == 2:", "- if (", "- self.string.startswith(self.string_list[0])", "- or self.string.startswith(self.string_list[1])", "- or self.string.startswith(self.string_list[3])", "- ):", "- return True", "- elif i == 3:", "- if (", "- self.string.startswith(self.string_list[0])", "- or self.string.startswith(self.string_list[1])", "- or self.string.startswith(self.string_list[4])", "- ):", "- return True", "- elif i == 4:", "- if self.string.startswith(", "- self.string_list[0]", "- ) or self.string.startswith(self.string_list[1]):", "- return True", "+ for str_val in self.string_list:", "+ if self.string.endswith(str_val):", "+ self.string = self.string.rsplit(str_val, 1)[0]", "+ return True" ]
false
0.042808
0.043631
0.981143
[ "s410166427", "s709098654" ]
u219015402
p02755
python
s357643189
s589420878
19
17
3,060
3,060
Accepted
Accepted
10.53
import math A,B= list(map(int,input().split())) # min_x = math.ceil(max(A/8,B/10)*100) min_x = max(A//0.08,B//0.10) +1 max_x = (min((A+1)/8,(B+1)/10)*100) if max_x-min_x>0: ans = int(min_x) else: ans = -1 print(ans)
import math A,B= list(map(int,input().split())) min_x = math.ceil(max(A/0.08,B/0.10)) # min_x = max(A//0.08,B//0.10) +1 max_x = (min((A+1)/8,(B+1)/10)*100) if max_x-min_x>0: ans = int(min_x) else: ans = -1 print(ans)
11
11
228
229
import math A, B = list(map(int, input().split())) # min_x = math.ceil(max(A/8,B/10)*100) min_x = max(A // 0.08, B // 0.10) + 1 max_x = min((A + 1) / 8, (B + 1) / 10) * 100 if max_x - min_x > 0: ans = int(min_x) else: ans = -1 print(ans)
import math A, B = list(map(int, input().split())) min_x = math.ceil(max(A / 0.08, B / 0.10)) # min_x = max(A//0.08,B//0.10) +1 max_x = min((A + 1) / 8, (B + 1) / 10) * 100 if max_x - min_x > 0: ans = int(min_x) else: ans = -1 print(ans)
false
0
[ "-# min_x = math.ceil(max(A/8,B/10)*100)", "-min_x = max(A // 0.08, B // 0.10) + 1", "+min_x = math.ceil(max(A / 0.08, B / 0.10))", "+# min_x = max(A//0.08,B//0.10) +1" ]
false
0.04752
0.047015
1.010742
[ "s357643189", "s589420878" ]
u222841610
p03449
python
s880930742
s784808780
20
18
3,064
3,060
Accepted
Accepted
10
n = int(eval(input())) a1 = list(map(int, input().split())) a2 = list(map(int, input().split())) count = 0 max1 = 0 for i in range(n): for j in range(n): if j < i: count += a1[j] elif j==i: count += (a1[j] + a2[j]) else: count += a2[j] if max1 < count: max1 = count count = 0 print (max1)
n = int(eval(input())) a1 = list(map(int, input().split())) a2 = list(map(int, input().split())) m = 0 for i in range(n): m = max(m, sum(a1[:i+1])+sum(a2[i:])) print (m)
17
7
378
173
n = int(eval(input())) a1 = list(map(int, input().split())) a2 = list(map(int, input().split())) count = 0 max1 = 0 for i in range(n): for j in range(n): if j < i: count += a1[j] elif j == i: count += a1[j] + a2[j] else: count += a2[j] if max1 < count: max1 = count count = 0 print(max1)
n = int(eval(input())) a1 = list(map(int, input().split())) a2 = list(map(int, input().split())) m = 0 for i in range(n): m = max(m, sum(a1[: i + 1]) + sum(a2[i:])) print(m)
false
58.823529
[ "-count = 0", "-max1 = 0", "+m = 0", "- for j in range(n):", "- if j < i:", "- count += a1[j]", "- elif j == i:", "- count += a1[j] + a2[j]", "- else:", "- count += a2[j]", "- if max1 < count:", "- max1 = count", "- count = 0", "-print(max1)", "+ m = max(m, sum(a1[: i + 1]) + sum(a2[i:]))", "+print(m)" ]
false
0.128499
0.278872
0.460782
[ "s880930742", "s784808780" ]
u816631826
p02711
python
s452147033
s897933176
29
25
9,016
9,112
Accepted
Accepted
13.79
n=int(eval(input())) while(n!=0): digit=n%10 if(digit==7): flag=1 break else: flag=0 n=n//10 if(flag==1): print("Yes") else: print("No")
N=int(eval(input())) if '7' in str(N): print('Yes') else: print('No')
13
5
190
76
n = int(eval(input())) while n != 0: digit = n % 10 if digit == 7: flag = 1 break else: flag = 0 n = n // 10 if flag == 1: print("Yes") else: print("No")
N = int(eval(input())) if "7" in str(N): print("Yes") else: print("No")
false
61.538462
[ "-n = int(eval(input()))", "-while n != 0:", "- digit = n % 10", "- if digit == 7:", "- flag = 1", "- break", "- else:", "- flag = 0", "- n = n // 10", "-if flag == 1:", "+N = int(eval(input()))", "+if \"7\" in str(N):" ]
false
0.037087
0.077804
0.476677
[ "s452147033", "s897933176" ]
u285891772
p02873
python
s020635658
s545097867
565
420
35,876
35,184
Accepted
Accepted
25.66
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 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 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()) N = len(S) + 1 l = [0]*N r = [0]*N tmp_l = 0 for i in range(N-1): if S[i] == "<": tmp_l += 1 l[i+1] = tmp_l else: tmp_l = 0 tmp_r = 0 for i in range(N-2, -1, -1): if S[i] == ">": tmp_r += 1 r[i] =tmp_r else: tmp_r = 0 t = [max(r[i], l[i]) for i in range(N)] ans = 0 for i in range(N): ans += max(l[i], r[i]) #print(l) #print(r) #print(t) print(ans)
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 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 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()) N = len(S) + 1 l = [0]*N r = [0]*N tmp_l = 0 for i in range(N-1): if S[i] == "<": tmp_l += 1 l[i+1] = tmp_l else: tmp_l = 0 tmp_r = 0 for i in range(N-1): if S[N-i-2] == ">": tmp_r += 1 r[i+1] = tmp_r else: tmp_r = 0 r = r[::-1] t = [max(r[i], l[i]) for i in range(N)] print((sum(t)))
53
47
1,312
1,237
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 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 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()) N = len(S) + 1 l = [0] * N r = [0] * N tmp_l = 0 for i in range(N - 1): if S[i] == "<": tmp_l += 1 l[i + 1] = tmp_l else: tmp_l = 0 tmp_r = 0 for i in range(N - 2, -1, -1): if S[i] == ">": tmp_r += 1 r[i] = tmp_r else: tmp_r = 0 t = [max(r[i], l[i]) for i in range(N)] ans = 0 for i in range(N): ans += max(l[i], r[i]) # print(l) # print(r) # print(t) print(ans)
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 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 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()) N = len(S) + 1 l = [0] * N r = [0] * N tmp_l = 0 for i in range(N - 1): if S[i] == "<": tmp_l += 1 l[i + 1] = tmp_l else: tmp_l = 0 tmp_r = 0 for i in range(N - 1): if S[N - i - 2] == ">": tmp_r += 1 r[i + 1] = tmp_r else: tmp_r = 0 r = r[::-1] t = [max(r[i], l[i]) for i in range(N)] print((sum(t)))
false
11.320755
[ "-for i in range(N - 2, -1, -1):", "- if S[i] == \">\":", "+for i in range(N - 1):", "+ if S[N - i - 2] == \">\":", "- r[i] = tmp_r", "+ r[i + 1] = tmp_r", "+r = r[::-1]", "-ans = 0", "-for i in range(N):", "- ans += max(l[i], r[i])", "-# print(l)", "-# print(r)", "-# print(t)", "-print(ans)", "+print((sum(t)))" ]
false
0.047947
0.03917
1.224078
[ "s020635658", "s545097867" ]
u349724238
p02720
python
s988723619
s910559056
744
260
31,508
12,864
Accepted
Accepted
65.05
K = int(eval(input())) A = [1,2,3,4,5,6,7,8,9] for i in range(len(A)): if A[i] != 9: for j in range(-1,2): a = int(str(A[i]) + str(A[i]+j)) A.append(a) else: A.append(98) A.append(99) A.append(100) A.append(101) L1 = len(A.copy()) for i in range(10, L1): B = A[i] if B % 10 == 0: A.append(int(str(B) + '0')) A.append(int(str(B) + '1')) elif B % 10 == 9: A.append(int(str(B) + '8')) A.append(int(str(B) + '9')) else: for j in range(-1, 2): a = int(str(B) + str((B % 10) + j)) A.append(a) L2 = len(A.copy()) for i in range(8): for i in range(L1,L2): B = A[i] if B % 10 == 0: A.append(int(str(B) + '0')) A.append(int(str(B) + '1')) elif B % 10 == 9: A.append(int(str(B) + '8')) A.append(int(str(B) + '9')) else: for j in range(-1, 2): a = int(str(B) + str((B % 10) + j)) A.append(a) L1 = L2 L2 = len(A.copy()) print((A[K-1]))
K = int(eval(input())) A = [1,2,3,4,5,6,7,8,9] for i in range(len(A)): if A[i] != 9: for j in range(-1,2): a = int(str(A[i]) + str(A[i]+j)) A.append(a) else: A.append(98) A.append(99) A.append(100) A.append(101) L1 = 10 L2 = len(A.copy()) for i in range(8): for i in range(L1,L2): B = A[i] if B % 10 == 0: A.append(int(str(B) + '0')) A.append(int(str(B) + '1')) elif B % 10 == 9: A.append(int(str(B) + '8')) A.append(int(str(B) + '9')) else: for j in range(-1, 2): a = int(str(B) + str((B % 10) + j)) A.append(a) L1 = L2 L2 = len(A.copy()) print((A[K-1]))
42
30
1,127
768
K = int(eval(input())) A = [1, 2, 3, 4, 5, 6, 7, 8, 9] for i in range(len(A)): if A[i] != 9: for j in range(-1, 2): a = int(str(A[i]) + str(A[i] + j)) A.append(a) else: A.append(98) A.append(99) A.append(100) A.append(101) L1 = len(A.copy()) for i in range(10, L1): B = A[i] if B % 10 == 0: A.append(int(str(B) + "0")) A.append(int(str(B) + "1")) elif B % 10 == 9: A.append(int(str(B) + "8")) A.append(int(str(B) + "9")) else: for j in range(-1, 2): a = int(str(B) + str((B % 10) + j)) A.append(a) L2 = len(A.copy()) for i in range(8): for i in range(L1, L2): B = A[i] if B % 10 == 0: A.append(int(str(B) + "0")) A.append(int(str(B) + "1")) elif B % 10 == 9: A.append(int(str(B) + "8")) A.append(int(str(B) + "9")) else: for j in range(-1, 2): a = int(str(B) + str((B % 10) + j)) A.append(a) L1 = L2 L2 = len(A.copy()) print((A[K - 1]))
K = int(eval(input())) A = [1, 2, 3, 4, 5, 6, 7, 8, 9] for i in range(len(A)): if A[i] != 9: for j in range(-1, 2): a = int(str(A[i]) + str(A[i] + j)) A.append(a) else: A.append(98) A.append(99) A.append(100) A.append(101) L1 = 10 L2 = len(A.copy()) for i in range(8): for i in range(L1, L2): B = A[i] if B % 10 == 0: A.append(int(str(B) + "0")) A.append(int(str(B) + "1")) elif B % 10 == 9: A.append(int(str(B) + "8")) A.append(int(str(B) + "9")) else: for j in range(-1, 2): a = int(str(B) + str((B % 10) + j)) A.append(a) L1 = L2 L2 = len(A.copy()) print((A[K - 1]))
false
28.571429
[ "-L1 = len(A.copy())", "-for i in range(10, L1):", "- B = A[i]", "- if B % 10 == 0:", "- A.append(int(str(B) + \"0\"))", "- A.append(int(str(B) + \"1\"))", "- elif B % 10 == 9:", "- A.append(int(str(B) + \"8\"))", "- A.append(int(str(B) + \"9\"))", "- else:", "- for j in range(-1, 2):", "- a = int(str(B) + str((B % 10) + j))", "- A.append(a)", "+L1 = 10" ]
false
1.187684
0.273253
4.346461
[ "s988723619", "s910559056" ]
u777923818
p03702
python
s264149386
s587843470
1,047
390
14,876
17,060
Accepted
Accepted
62.75
# -*- coding: utf-8 -*- def inpl(): return tuple(map(int, input().split())) N, A, B = inpl() D = A-B H = [] res = 0 for _ in range(N): H.append(int(eval(input()))) H = sorted(H) l = sum(H) // (A+B*(N-1)) r = sum([h//A + (h%A>0) for h in H]) def judge(m): nH = [h - B*m for h in H] if sum([h//D + (h%D>0) for h in nH if h > 0]) <= m: return True else: return False while r-l > 1: mid = (l+r)//2 if judge(mid): r = mid else: l = mid if judge(l): print(l) else: print(r)
# -*- coding: utf-8 -*- import numpy as np N, A, B = list(map(int, input().split())) C = A - B E = np.array([int(eval(input())) for _ in range(N)], dtype=np.int64) Z = np.zeros(N, dtype=np.int64) OK = (np.max(E) // B) + 1 NG = 0 while (OK - NG) > 1: m = (OK + NG)//2 if -np.sum((-np.maximum(Z, E-m*B) // C)) <= m: OK = m else: NG = m print(OK)
31
21
563
385
# -*- coding: utf-8 -*- def inpl(): return tuple(map(int, input().split())) N, A, B = inpl() D = A - B H = [] res = 0 for _ in range(N): H.append(int(eval(input()))) H = sorted(H) l = sum(H) // (A + B * (N - 1)) r = sum([h // A + (h % A > 0) for h in H]) def judge(m): nH = [h - B * m for h in H] if sum([h // D + (h % D > 0) for h in nH if h > 0]) <= m: return True else: return False while r - l > 1: mid = (l + r) // 2 if judge(mid): r = mid else: l = mid if judge(l): print(l) else: print(r)
# -*- coding: utf-8 -*- import numpy as np N, A, B = list(map(int, input().split())) C = A - B E = np.array([int(eval(input())) for _ in range(N)], dtype=np.int64) Z = np.zeros(N, dtype=np.int64) OK = (np.max(E) // B) + 1 NG = 0 while (OK - NG) > 1: m = (OK + NG) // 2 if -np.sum((-np.maximum(Z, E - m * B) // C)) <= m: OK = m else: NG = m print(OK)
false
32.258065
[ "-def inpl():", "- return tuple(map(int, input().split()))", "+import numpy as np", "-", "-N, A, B = inpl()", "-D = A - B", "-H = []", "-res = 0", "-for _ in range(N):", "- H.append(int(eval(input())))", "-H = sorted(H)", "-l = sum(H) // (A + B * (N - 1))", "-r = sum([h // A + (h % A > 0) for h in H])", "-", "-", "-def judge(m):", "- nH = [h - B * m for h in H]", "- if sum([h // D + (h % D > 0) for h in nH if h > 0]) <= m:", "- return True", "+N, A, B = list(map(int, input().split()))", "+C = A - B", "+E = np.array([int(eval(input())) for _ in range(N)], dtype=np.int64)", "+Z = np.zeros(N, dtype=np.int64)", "+OK = (np.max(E) // B) + 1", "+NG = 0", "+while (OK - NG) > 1:", "+ m = (OK + NG) // 2", "+ if -np.sum((-np.maximum(Z, E - m * B) // C)) <= m:", "+ OK = m", "- return False", "-", "-", "-while r - l > 1:", "- mid = (l + r) // 2", "- if judge(mid):", "- r = mid", "- else:", "- l = mid", "-if judge(l):", "- print(l)", "-else:", "- print(r)", "+ NG = m", "+print(OK)" ]
false
0.04509
0.240621
0.187391
[ "s264149386", "s587843470" ]
u813098295
p04045
python
s684958329
s346796503
235
134
34,436
5,380
Accepted
Accepted
42.98
N, K = list(map(int, input().split())) D = list(map(int, input().split())) for i in range(N, 1000000): flag = 0 for j in D: if str(j) in str(i): flag = 1 break if flag == 0: print(i) exit()
def main(): N, K = list(map(int, input().split())) D = input().split() for i in range(N, N*10): if len(set(list(str(i))) & set(D)) == 0: print(i) break main()
16
10
234
214
N, K = list(map(int, input().split())) D = list(map(int, input().split())) for i in range(N, 1000000): flag = 0 for j in D: if str(j) in str(i): flag = 1 break if flag == 0: print(i) exit()
def main(): N, K = list(map(int, input().split())) D = input().split() for i in range(N, N * 10): if len(set(list(str(i))) & set(D)) == 0: print(i) break main()
false
37.5
[ "-N, K = list(map(int, input().split()))", "-D = list(map(int, input().split()))", "-for i in range(N, 1000000):", "- flag = 0", "- for j in D:", "- if str(j) in str(i):", "- flag = 1", "+def main():", "+ N, K = list(map(int, input().split()))", "+ D = input().split()", "+ for i in range(N, N * 10):", "+ if len(set(list(str(i))) & set(D)) == 0:", "+ print(i)", "- if flag == 0:", "- print(i)", "- exit()", "+", "+", "+main()" ]
false
0.04061
0.076295
0.532281
[ "s684958329", "s346796503" ]
u353919145
p02771
python
s080078859
s488144622
19
17
3,064
3,060
Accepted
Accepted
10.53
n = input().split() for i in range (3) : n[i] = int(n[i]) a = sorted (n) fl = False if (a[0] == a[1] and a[1] != a[2]) : fl = True if (a[0] != a[1] and a[1] == a[2]) : fl = True print(('Yes' if fl else 'No'))
A,B,C=input().split() a,b,c=int(A),int(B),int(C) if a==b and b!=c: print("Yes") elif a==c and a!=b: print("Yes") elif b==c and a!=b: print("Yes") else: print("No")
13
11
234
190
n = input().split() for i in range(3): n[i] = int(n[i]) a = sorted(n) fl = False if a[0] == a[1] and a[1] != a[2]: fl = True if a[0] != a[1] and a[1] == a[2]: fl = True print(("Yes" if fl else "No"))
A, B, C = input().split() a, b, c = int(A), int(B), int(C) if a == b and b != c: print("Yes") elif a == c and a != b: print("Yes") elif b == c and a != b: print("Yes") else: print("No")
false
15.384615
[ "-n = input().split()", "-for i in range(3):", "- n[i] = int(n[i])", "-a = sorted(n)", "-fl = False", "-if a[0] == a[1] and a[1] != a[2]:", "- fl = True", "-if a[0] != a[1] and a[1] == a[2]:", "- fl = True", "-print((\"Yes\" if fl else \"No\"))", "+A, B, C = input().split()", "+a, b, c = int(A), int(B), int(C)", "+if a == b and b != c:", "+ print(\"Yes\")", "+elif a == c and a != b:", "+ print(\"Yes\")", "+elif b == c and a != b:", "+ print(\"Yes\")", "+else:", "+ print(\"No\")" ]
false
0.040539
0.041422
0.978669
[ "s080078859", "s488144622" ]
u790710233
p02720
python
s449084553
s391670802
371
198
12,776
7,708
Accepted
Accepted
46.63
k = int(eval(input())) ans = [] def dfs(x): if x > 10**10: return 0 else: ans.append(x) y = x % 10 for i in range(10): if abs(y-i) <= 1: dfs(10*x+i) for i in range(1, 10): dfs(i) ans.sort() print((ans[k-1]))
k = int(eval(input())) ans = [] def dfs(x): if x > 3234566667: return 0 else: ans.append(x) y = x % 10 for i in range(10): if abs(y-i) <= 1: dfs(10*x+i) for i in range(1, 10): dfs(i) ans.sort() print((ans[k-1]))
18
20
307
307
k = int(eval(input())) ans = [] def dfs(x): if x > 10**10: return 0 else: ans.append(x) y = x % 10 for i in range(10): if abs(y - i) <= 1: dfs(10 * x + i) for i in range(1, 10): dfs(i) ans.sort() print((ans[k - 1]))
k = int(eval(input())) ans = [] def dfs(x): if x > 3234566667: return 0 else: ans.append(x) y = x % 10 for i in range(10): if abs(y - i) <= 1: dfs(10 * x + i) for i in range(1, 10): dfs(i) ans.sort() print((ans[k - 1]))
false
10
[ "- if x > 10**10:", "+ if x > 3234566667:" ]
false
1.119955
0.471633
2.374634
[ "s449084553", "s391670802" ]
u864197622
p02728
python
s085604682
s542446684
1,661
1,469
125,872
126,128
Accepted
Accepted
11.56
import sys input = sys.stdin.readline from collections import deque nn = 200200 mod = 10**9+7 fa = [1] * (nn+1) fainv = [1] * (nn+1) for i in range(nn): fa[i+1] = fa[i] * (i+1) % mod fainv[-1] = pow(fa[-1], mod-2, mod) for i in range(nn)[::-1]: fainv[i] = fainv[i+1] * (i+1) % mod C = lambda a, b: fa[a] * fainv[b] % mod * fainv[a-b] % mod if 0 <= b <= a else 0 N = int(eval(input())) X = [[] for i in range(N)] for i in range(N-1): x, y = list(map(int, input().split())) X[x-1].append(y-1) X[y-1].append(x-1) P = [-1] * N Q = deque([0]) R = [] while Q: i = deque.popleft(Q) R.append(i) for a in X[i]: if a != P[i]: P[a] = i X[a].remove(i) deque.append(Q, a) BU = [1] * N TD = [1] * N SI = [1] * N for i in R[::-1]: a = 1 s = 0 for j in X[i]: a = a * BU[j] * fainv[SI[j]] % mod s += SI[j] SI[i] = s + 1 BU[i] = fa[s] * a % mod for i in R: c = len(X[i]) AL = [1] * (c + 1) AR = [1] * (c + 1) for j in range(c): AL[j+1] = AL[j] * BU[X[i][j]] % mod * fainv[SI[X[i][j]]] % mod for j in range(c)[::-1]: AR[j] = AR[j+1] * BU[X[i][j]] % mod * fainv[SI[X[i][j]]] % mod for j in range(c): TD[X[i][j]] = TD[i] * fainv[N - SI[i]] % mod * AL[j] % mod * AR[j+1] % mod * fa[N - 1 - SI[X[i][j]]] % mod for i in range(N): print((BU[i] * TD[i] % mod * C(N-1, SI[i] - 1) % mod))
import sys input = sys.stdin.readline from collections import deque nn = 200200 mod = 10**9+7 fa = [1] * (nn+1) fainv = [1] * (nn+1) inv = [1] * (nn+1) for i in range(nn): fa[i+1] = fa[i] * (i+1) % mod fainv[-1] = pow(fa[-1], mod-2, mod) for i in range(nn)[::-1]: fainv[i] = fainv[i+1] * (i+1) % mod for i in range(1, nn)[::-1]: inv[i] = fainv[i] * fa[i-1] C = lambda a, b: fa[a] * fainv[b] % mod * fainv[a-b] % mod if 0 <= b <= a else 0 N = int(eval(input())) X = [[] for i in range(N)] for i in range(N-1): x, y = list(map(int, input().split())) X[x-1].append(y-1) X[y-1].append(x-1) P = [-1] * N Q = deque([0]) R = [] while Q: i = deque.popleft(Q) R.append(i) for a in X[i]: if a != P[i]: P[a] = i X[a].remove(i) deque.append(Q, a) BU = [1] * N TD = [1] * N SI = [1] * N for i in R[::-1]: a = 1 s = 1 for j in X[i]: a = a * BU[j] % mod s += SI[j] SI[i] = s BU[i] = inv[s] * a % mod for i in R: c = len(X[i]) AL = [1] * (c + 1) AR = [1] * (c + 1) for j in range(c): AL[j+1] = AL[j] * BU[X[i][j]] % mod for j in range(c)[::-1]: AR[j] = AR[j+1] * BU[X[i][j]] % mod for j in range(c): TD[X[i][j]] = TD[i] * AL[j] % mod * AR[j+1] % mod * inv[N - SI[X[i][j]]] % mod for i in range(N): print((BU[i] * fa[SI[i]] % mod * TD[i] % mod * fa[N - SI[i]] % mod * C(N-1, SI[i] - 1) % mod))
60
64
1,476
1,501
import sys input = sys.stdin.readline from collections import deque nn = 200200 mod = 10**9 + 7 fa = [1] * (nn + 1) fainv = [1] * (nn + 1) for i in range(nn): fa[i + 1] = fa[i] * (i + 1) % mod fainv[-1] = pow(fa[-1], mod - 2, mod) for i in range(nn)[::-1]: fainv[i] = fainv[i + 1] * (i + 1) % mod C = lambda a, b: fa[a] * fainv[b] % mod * fainv[a - b] % mod if 0 <= b <= a else 0 N = int(eval(input())) X = [[] for i in range(N)] for i in range(N - 1): x, y = list(map(int, input().split())) X[x - 1].append(y - 1) X[y - 1].append(x - 1) P = [-1] * N Q = deque([0]) R = [] while Q: i = deque.popleft(Q) R.append(i) for a in X[i]: if a != P[i]: P[a] = i X[a].remove(i) deque.append(Q, a) BU = [1] * N TD = [1] * N SI = [1] * N for i in R[::-1]: a = 1 s = 0 for j in X[i]: a = a * BU[j] * fainv[SI[j]] % mod s += SI[j] SI[i] = s + 1 BU[i] = fa[s] * a % mod for i in R: c = len(X[i]) AL = [1] * (c + 1) AR = [1] * (c + 1) for j in range(c): AL[j + 1] = AL[j] * BU[X[i][j]] % mod * fainv[SI[X[i][j]]] % mod for j in range(c)[::-1]: AR[j] = AR[j + 1] * BU[X[i][j]] % mod * fainv[SI[X[i][j]]] % mod for j in range(c): TD[X[i][j]] = ( TD[i] * fainv[N - SI[i]] % mod * AL[j] % mod * AR[j + 1] % mod * fa[N - 1 - SI[X[i][j]]] % mod ) for i in range(N): print((BU[i] * TD[i] % mod * C(N - 1, SI[i] - 1) % mod))
import sys input = sys.stdin.readline from collections import deque nn = 200200 mod = 10**9 + 7 fa = [1] * (nn + 1) fainv = [1] * (nn + 1) inv = [1] * (nn + 1) for i in range(nn): fa[i + 1] = fa[i] * (i + 1) % mod fainv[-1] = pow(fa[-1], mod - 2, mod) for i in range(nn)[::-1]: fainv[i] = fainv[i + 1] * (i + 1) % mod for i in range(1, nn)[::-1]: inv[i] = fainv[i] * fa[i - 1] C = lambda a, b: fa[a] * fainv[b] % mod * fainv[a - b] % mod if 0 <= b <= a else 0 N = int(eval(input())) X = [[] for i in range(N)] for i in range(N - 1): x, y = list(map(int, input().split())) X[x - 1].append(y - 1) X[y - 1].append(x - 1) P = [-1] * N Q = deque([0]) R = [] while Q: i = deque.popleft(Q) R.append(i) for a in X[i]: if a != P[i]: P[a] = i X[a].remove(i) deque.append(Q, a) BU = [1] * N TD = [1] * N SI = [1] * N for i in R[::-1]: a = 1 s = 1 for j in X[i]: a = a * BU[j] % mod s += SI[j] SI[i] = s BU[i] = inv[s] * a % mod for i in R: c = len(X[i]) AL = [1] * (c + 1) AR = [1] * (c + 1) for j in range(c): AL[j + 1] = AL[j] * BU[X[i][j]] % mod for j in range(c)[::-1]: AR[j] = AR[j + 1] * BU[X[i][j]] % mod for j in range(c): TD[X[i][j]] = TD[i] * AL[j] % mod * AR[j + 1] % mod * inv[N - SI[X[i][j]]] % mod for i in range(N): print( ( BU[i] * fa[SI[i]] % mod * TD[i] % mod * fa[N - SI[i]] % mod * C(N - 1, SI[i] - 1) % mod ) )
false
6.25
[ "+inv = [1] * (nn + 1)", "+for i in range(1, nn)[::-1]:", "+ inv[i] = fainv[i] * fa[i - 1]", "- s = 0", "+ s = 1", "- a = a * BU[j] * fainv[SI[j]] % mod", "+ a = a * BU[j] % mod", "- SI[i] = s + 1", "- BU[i] = fa[s] * a % mod", "+ SI[i] = s", "+ BU[i] = inv[s] * a % mod", "- AL[j + 1] = AL[j] * BU[X[i][j]] % mod * fainv[SI[X[i][j]]] % mod", "+ AL[j + 1] = AL[j] * BU[X[i][j]] % mod", "- AR[j] = AR[j + 1] * BU[X[i][j]] % mod * fainv[SI[X[i][j]]] % mod", "+ AR[j] = AR[j + 1] * BU[X[i][j]] % mod", "- TD[X[i][j]] = (", "- TD[i]", "- * fainv[N - SI[i]]", "+ TD[X[i][j]] = TD[i] * AL[j] % mod * AR[j + 1] % mod * inv[N - SI[X[i][j]]] % mod", "+for i in range(N):", "+ print(", "+ (", "+ BU[i]", "+ * fa[SI[i]]", "- * AL[j]", "+ * TD[i]", "- * AR[j + 1]", "+ * fa[N - SI[i]]", "- * fa[N - 1 - SI[X[i][j]]]", "+ * C(N - 1, SI[i] - 1)", "-for i in range(N):", "- print((BU[i] * TD[i] % mod * C(N - 1, SI[i] - 1) % mod))", "+ )" ]
false
0.305719
0.778613
0.392646
[ "s085604682", "s542446684" ]
u847923740
p03163
python
s522852613
s989052630
184
124
29,868
28,944
Accepted
Accepted
32.61
import numpy as np N, W = list(map(int, input().split())) dp = np.zeros(W + 1, dtype = np.int64) for i in range(N): w, v = list(map(int, input().split())) dp[w:] = np.maximum(dp[w:], dp[:-w] + v) print((dp.max()))
import numpy as np N, W = list(map(int, input().split())) dp = np.zeros(W + 1, dtype = np.int64) for i in range(N): w, v = list(map(int, input().split())) np.maximum(dp[w:], dp[:-w] + v, out = dp[w:]) print((dp.max()))
11
11
215
220
import numpy as np N, W = list(map(int, input().split())) dp = np.zeros(W + 1, dtype=np.int64) for i in range(N): w, v = list(map(int, input().split())) dp[w:] = np.maximum(dp[w:], dp[:-w] + v) print((dp.max()))
import numpy as np N, W = list(map(int, input().split())) dp = np.zeros(W + 1, dtype=np.int64) for i in range(N): w, v = list(map(int, input().split())) np.maximum(dp[w:], dp[:-w] + v, out=dp[w:]) print((dp.max()))
false
0
[ "- dp[w:] = np.maximum(dp[w:], dp[:-w] + v)", "+ np.maximum(dp[w:], dp[:-w] + v, out=dp[w:])" ]
false
0.210742
0.415911
0.506699
[ "s522852613", "s989052630" ]
u597374218
p03694
python
s496148621
s593771781
19
17
2,940
2,940
Accepted
Accepted
10.53
eval(input()) a=list(map(int,input().split())) print((max(a)-min(a)))
eval(input()) a = sorted(map(int, input().split())) print((a[-1]-a[0]))
3
3
63
65
eval(input()) a = list(map(int, input().split())) print((max(a) - min(a)))
eval(input()) a = sorted(map(int, input().split())) print((a[-1] - a[0]))
false
0
[ "-a = list(map(int, input().split()))", "-print((max(a) - min(a)))", "+a = sorted(map(int, input().split()))", "+print((a[-1] - a[0]))" ]
false
0.038964
0.038565
1.010343
[ "s496148621", "s593771781" ]
u864197622
p04014
python
s485942363
s810013994
28
22
3,316
3,308
Accepted
Accepted
21.43
def primeFactor(N): i, n, ret, d, sq = 2, N, {}, 2, 99 while i <= sq: k = 0 while n % i == 0: n, k, ret[i] = n//i, k+1, k+1 if k > 0 or i == 97: sq = int(n**(1/2)+0.5) if i < 4: i = i * 2 - 1 else: i, d = i+d, d^6 if n > 1: ret[n] = 1 return ret def divisors(N): pf = primeFactor(N) ret = [1] for p in pf: ret_prev = ret ret = [] for i in range(pf[p]+1): for r in ret_prev: ret.append(r * (p ** i)) return sorted(ret) def f(b, n): re = 0 while n: re += n % b n //= b return re N = int(eval(input())) S = int(eval(input())) if N < S: print((-1)) elif N == S: print((N+1)) else: for b in divisors(N-S): b += 1 if f(b, N) == S: print(b) break else: print((-1))
def primeFactor(N): i = 2 ret = {} n = N mrFlg = 0 while i**2 <= n: k = 0 while n % i == 0: n //= i k += 1 ret[i] = k i += 1 if i == 101 and n >= (2**20): def findFactorRho(N): # Primeでないことを確認したものを引数とする。 def gcd(a, b): while b: a, b = b, a % b return abs(a) def f(x, c): return ((x ** 2) + c) % N semi = [N] for c in range(1, 99): x, y, d = 2, 2, 1 while d == 1: x = f(x, c) y = f(f(y, c), c) d = gcd(abs(x-y), N) if d != N: if isPrimeMR(d): return d elif isPrimeMR(N//d): return N//d else: semi.append(d) while True: if isPrimeMR(n): ret[n], n = 1, 1 break else: mrFlg = 1 j = findFactorRho(n) k = 0 while n % j == 0: n //= j k += 1 ret[j] = k if n == 1: break if n > 1: ret[n] = 1 if mrFlg > 0: def dict_sort(X): Y={} for x in sorted(X.keys()): Y[x] = X[x] return Y ret = dict_sort(ret) return ret def isPrimeMR(n): if n == 2: return True if n == 1 or n & 1 == 0: return False d = (n - 1) >> 1 while d & 1 == 0: d >>= 1 for a in [2, 3, 5, 7, 11, 13, 17, 19, 23]: t = d y = pow(a, t, n) while t != n - 1 and y != 1 and y != n - 1: y = (y * y) % n t <<= 1 if y != n - 1 and t & 1 == 0: return False return True def divisors(N): pf = primeFactor(N) ret = [1] for p in pf: ret_prev = ret ret = [] for i in range(pf[p]+1): for r in ret_prev: ret.append(r * (p ** i)) return sorted(ret) def f(b, n): re = 0 while n: re += n % b n //= b return re N = int(eval(input())) S = int(eval(input())) if N < S: print((-1)) elif N == S: print((N+1)) else: for b in divisors(N-S): b += 1 if f(b, N) == S: print(b) break else: print((-1))
43
108
901
2,715
def primeFactor(N): i, n, ret, d, sq = 2, N, {}, 2, 99 while i <= sq: k = 0 while n % i == 0: n, k, ret[i] = n // i, k + 1, k + 1 if k > 0 or i == 97: sq = int(n ** (1 / 2) + 0.5) if i < 4: i = i * 2 - 1 else: i, d = i + d, d ^ 6 if n > 1: ret[n] = 1 return ret def divisors(N): pf = primeFactor(N) ret = [1] for p in pf: ret_prev = ret ret = [] for i in range(pf[p] + 1): for r in ret_prev: ret.append(r * (p**i)) return sorted(ret) def f(b, n): re = 0 while n: re += n % b n //= b return re N = int(eval(input())) S = int(eval(input())) if N < S: print((-1)) elif N == S: print((N + 1)) else: for b in divisors(N - S): b += 1 if f(b, N) == S: print(b) break else: print((-1))
def primeFactor(N): i = 2 ret = {} n = N mrFlg = 0 while i**2 <= n: k = 0 while n % i == 0: n //= i k += 1 ret[i] = k i += 1 if i == 101 and n >= (2**20): def findFactorRho(N): # Primeでないことを確認したものを引数とする。 def gcd(a, b): while b: a, b = b, a % b return abs(a) def f(x, c): return ((x**2) + c) % N semi = [N] for c in range(1, 99): x, y, d = 2, 2, 1 while d == 1: x = f(x, c) y = f(f(y, c), c) d = gcd(abs(x - y), N) if d != N: if isPrimeMR(d): return d elif isPrimeMR(N // d): return N // d else: semi.append(d) while True: if isPrimeMR(n): ret[n], n = 1, 1 break else: mrFlg = 1 j = findFactorRho(n) k = 0 while n % j == 0: n //= j k += 1 ret[j] = k if n == 1: break if n > 1: ret[n] = 1 if mrFlg > 0: def dict_sort(X): Y = {} for x in sorted(X.keys()): Y[x] = X[x] return Y ret = dict_sort(ret) return ret def isPrimeMR(n): if n == 2: return True if n == 1 or n & 1 == 0: return False d = (n - 1) >> 1 while d & 1 == 0: d >>= 1 for a in [2, 3, 5, 7, 11, 13, 17, 19, 23]: t = d y = pow(a, t, n) while t != n - 1 and y != 1 and y != n - 1: y = (y * y) % n t <<= 1 if y != n - 1 and t & 1 == 0: return False return True def divisors(N): pf = primeFactor(N) ret = [1] for p in pf: ret_prev = ret ret = [] for i in range(pf[p] + 1): for r in ret_prev: ret.append(r * (p**i)) return sorted(ret) def f(b, n): re = 0 while n: re += n % b n //= b return re N = int(eval(input())) S = int(eval(input())) if N < S: print((-1)) elif N == S: print((N + 1)) else: for b in divisors(N - S): b += 1 if f(b, N) == S: print(b) break else: print((-1))
false
60.185185
[ "- i, n, ret, d, sq = 2, N, {}, 2, 99", "- while i <= sq:", "+ i = 2", "+ ret = {}", "+ n = N", "+ mrFlg = 0", "+ while i**2 <= n:", "- n, k, ret[i] = n // i, k + 1, k + 1", "- if k > 0 or i == 97:", "- sq = int(n ** (1 / 2) + 0.5)", "- if i < 4:", "- i = i * 2 - 1", "- else:", "- i, d = i + d, d ^ 6", "+ n //= i", "+ k += 1", "+ ret[i] = k", "+ i += 1", "+ if i == 101 and n >= (2**20):", "+", "+ def findFactorRho(N): # Primeでないことを確認したものを引数とする。", "+ def gcd(a, b):", "+ while b:", "+ a, b = b, a % b", "+ return abs(a)", "+", "+ def f(x, c):", "+ return ((x**2) + c) % N", "+", "+ semi = [N]", "+ for c in range(1, 99):", "+ x, y, d = 2, 2, 1", "+ while d == 1:", "+ x = f(x, c)", "+ y = f(f(y, c), c)", "+ d = gcd(abs(x - y), N)", "+ if d != N:", "+ if isPrimeMR(d):", "+ return d", "+ elif isPrimeMR(N // d):", "+ return N // d", "+ else:", "+ semi.append(d)", "+", "+ while True:", "+ if isPrimeMR(n):", "+ ret[n], n = 1, 1", "+ break", "+ else:", "+ mrFlg = 1", "+ j = findFactorRho(n)", "+ k = 0", "+ while n % j == 0:", "+ n //= j", "+ k += 1", "+ ret[j] = k", "+ if n == 1:", "+ break", "+ if mrFlg > 0:", "+", "+ def dict_sort(X):", "+ Y = {}", "+ for x in sorted(X.keys()):", "+ Y[x] = X[x]", "+ return Y", "+", "+ ret = dict_sort(ret)", "+", "+", "+def isPrimeMR(n):", "+ if n == 2:", "+ return True", "+ if n == 1 or n & 1 == 0:", "+ return False", "+ d = (n - 1) >> 1", "+ while d & 1 == 0:", "+ d >>= 1", "+ for a in [2, 3, 5, 7, 11, 13, 17, 19, 23]:", "+ t = d", "+ y = pow(a, t, n)", "+ while t != n - 1 and y != 1 and y != n - 1:", "+ y = (y * y) % n", "+ t <<= 1", "+ if y != n - 1 and t & 1 == 0:", "+ return False", "+ return True" ]
false
0.040925
0.049075
0.833932
[ "s485942363", "s810013994" ]
u548252256
p02264
python
s124432070
s964483074
860
370
14,292
17,352
Accepted
Accepted
56.98
pnum,mtime = list(map(int,input().split(" "))) total = [list(input().split(" ")) for _ in range(pnum)] cnt=0 tcnt=0 while len(total) > 0: ztime = int(total[0][1]) - mtime if ztime <= 0: tcnt += int(total[0][1]) print((total[0][0],int(tcnt))) total.pop(0) else: total.append([total[0][0],ztime]) total.pop(0) tcnt += mtime cnt += 1
#queueを使った方法 from collections import deque pnum,mtime = list(map(int,input().split(" "))) q = deque([]) [q.append(input().split(" ")) for u in range(pnum)] tcnt=0 while len(q) > 0: qq = q.popleft() ztime = int(qq[1]) - mtime if ztime <= 0: tcnt += int(qq[1]) print((qq[0],int(tcnt))) else: q.append([qq[0],ztime]) tcnt += mtime
19
19
361
354
pnum, mtime = list(map(int, input().split(" "))) total = [list(input().split(" ")) for _ in range(pnum)] cnt = 0 tcnt = 0 while len(total) > 0: ztime = int(total[0][1]) - mtime if ztime <= 0: tcnt += int(total[0][1]) print((total[0][0], int(tcnt))) total.pop(0) else: total.append([total[0][0], ztime]) total.pop(0) tcnt += mtime cnt += 1
# queueを使った方法 from collections import deque pnum, mtime = list(map(int, input().split(" "))) q = deque([]) [q.append(input().split(" ")) for u in range(pnum)] tcnt = 0 while len(q) > 0: qq = q.popleft() ztime = int(qq[1]) - mtime if ztime <= 0: tcnt += int(qq[1]) print((qq[0], int(tcnt))) else: q.append([qq[0], ztime]) tcnt += mtime
false
0
[ "+# queueを使った方法", "+from collections import deque", "+", "-total = [list(input().split(\" \")) for _ in range(pnum)]", "-cnt = 0", "+q = deque([])", "+[q.append(input().split(\" \")) for u in range(pnum)]", "-while len(total) > 0:", "- ztime = int(total[0][1]) - mtime", "+while len(q) > 0:", "+ qq = q.popleft()", "+ ztime = int(qq[1]) - mtime", "- tcnt += int(total[0][1])", "- print((total[0][0], int(tcnt)))", "- total.pop(0)", "+ tcnt += int(qq[1])", "+ print((qq[0], int(tcnt)))", "- total.append([total[0][0], ztime])", "- total.pop(0)", "+ q.append([qq[0], ztime])", "- cnt += 1" ]
false
0.036825
0.036297
1.014539
[ "s124432070", "s964483074" ]
u285891772
p03805
python
s988859483
s082770242
61
45
5,160
5,316
Accepted
Accepted
26.23
import sys, re from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2 from collections import deque, defaultdict, Counter 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 from fractions import gcd from heapq import heappush, heappop, heapify from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) def ZIP(n): return list(zip(*(MAP() for _ in range(n)))) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10 ** 9 + 7 N, M = MAP() graph = defaultdict(list) for _ in range(M): a, b = MAP() graph[a-1].append(b-1) graph[b-1].append(a-1) #print(graph) ans = 0 A = list(range(1, N)) for x in permutations(A, N-1): #print(x) y = [0] tmp = graph[0] for i in range(N-1): if x[i] in tmp and not x[i] in y: y.append(x[i]) tmp = graph[x[i]] else: break else: ans += 1 #print("成功") print(ans)
import sys, re from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2 from collections import deque, defaultdict, Counter 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 from fractions import gcd from heapq import heappush, heappop, heapify from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) def ZIP(n): return list(zip(*(MAP() for _ in range(n)))) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10 ** 9 + 7 N, M = MAP() ab = [LIST() for _ in range(M)] #隣接行列 contact = [[0]*N for _ in range(N)] for a, b in ab: contact[a-1][b-1] = 1 contact[b-1][a-1] = 1 A = list(x for x in range(1, N)) ans = 0 for X in permutations(A, N-1): #print(X) tmp = 0 for y in X: if contact[tmp][y] == 1: tmp = y else: break else: #print("成功") ans += 1 print(ans)
49
46
1,284
1,244
import sys, re from math import ( ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, ) from collections import deque, defaultdict, Counter 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 from fractions import gcd from heapq import heappush, heappop, heapify from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) def ZIP(n): return list(zip(*(MAP() for _ in range(n)))) sys.setrecursionlimit(10**9) INF = float("inf") mod = 10**9 + 7 N, M = MAP() graph = defaultdict(list) for _ in range(M): a, b = MAP() graph[a - 1].append(b - 1) graph[b - 1].append(a - 1) # print(graph) ans = 0 A = list(range(1, N)) for x in permutations(A, N - 1): # print(x) y = [0] tmp = graph[0] for i in range(N - 1): if x[i] in tmp and not x[i] in y: y.append(x[i]) tmp = graph[x[i]] else: break else: ans += 1 # print("成功") print(ans)
import sys, re from math import ( ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, ) from collections import deque, defaultdict, Counter 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 from fractions import gcd from heapq import heappush, heappop, heapify from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) def ZIP(n): return list(zip(*(MAP() for _ in range(n)))) sys.setrecursionlimit(10**9) INF = float("inf") mod = 10**9 + 7 N, M = MAP() ab = [LIST() for _ in range(M)] # 隣接行列 contact = [[0] * N for _ in range(N)] for a, b in ab: contact[a - 1][b - 1] = 1 contact[b - 1][a - 1] = 1 A = list(x for x in range(1, N)) ans = 0 for X in permutations(A, N - 1): # print(X) tmp = 0 for y in X: if contact[tmp][y] == 1: tmp = y else: break else: # print("成功") ans += 1 print(ans)
false
6.122449
[ "-graph = defaultdict(list)", "-for _ in range(M):", "- a, b = MAP()", "- graph[a - 1].append(b - 1)", "- graph[b - 1].append(a - 1)", "-# print(graph)", "+ab = [LIST() for _ in range(M)]", "+# 隣接行列", "+contact = [[0] * N for _ in range(N)]", "+for a, b in ab:", "+ contact[a - 1][b - 1] = 1", "+ contact[b - 1][a - 1] = 1", "+A = list(x for x in range(1, N))", "-A = list(range(1, N))", "-for x in permutations(A, N - 1):", "- # print(x)", "- y = [0]", "- tmp = graph[0]", "- for i in range(N - 1):", "- if x[i] in tmp and not x[i] in y:", "- y.append(x[i])", "- tmp = graph[x[i]]", "+for X in permutations(A, N - 1):", "+ # print(X)", "+ tmp = 0", "+ for y in X:", "+ if contact[tmp][y] == 1:", "+ tmp = y", "+ # print(\"成功\")", "- # print(\"成功\")" ]
false
0.043283
0.038996
1.10993
[ "s988859483", "s082770242" ]
u223663729
p02722
python
s403995382
s696915021
265
211
3,064
3,188
Accepted
Accepted
20.38
N = int(eval(input())) cnt = 2 if N > 2 else 1 ret = [] for i in range(2, int(N**0.5)+1): if N % i == 0: k = N//i while k % i == 0: k //= i if k % i == 1: cnt += 1 if N // i != i: j = N // i k = i while k % j == 0: k //= j if k % j == 1: cnt += 1 M = N - 1 for i in range(2, int((M)**0.5)+1): if M % i == 0: cnt += 1 if M // i != i: cnt += 1 print(cnt)
N = int(eval(input())) def divisor(N): ret = [] for i in range(1, int(N**0.5)+1): if N % i == 0: ret.append(i) if N // i != i: ret.append(N//i) return ret div_N = divisor(N) div_N_1 = divisor(N-1) ans = 0 for k in div_N[1:]: n = N while n % k == 0: n //= k if n % k == 1: ans += 1 ans += len(div_N_1) - 1 print(ans)
28
27
550
431
N = int(eval(input())) cnt = 2 if N > 2 else 1 ret = [] for i in range(2, int(N**0.5) + 1): if N % i == 0: k = N // i while k % i == 0: k //= i if k % i == 1: cnt += 1 if N // i != i: j = N // i k = i while k % j == 0: k //= j if k % j == 1: cnt += 1 M = N - 1 for i in range(2, int((M) ** 0.5) + 1): if M % i == 0: cnt += 1 if M // i != i: cnt += 1 print(cnt)
N = int(eval(input())) def divisor(N): ret = [] for i in range(1, int(N**0.5) + 1): if N % i == 0: ret.append(i) if N // i != i: ret.append(N // i) return ret div_N = divisor(N) div_N_1 = divisor(N - 1) ans = 0 for k in div_N[1:]: n = N while n % k == 0: n //= k if n % k == 1: ans += 1 ans += len(div_N_1) - 1 print(ans)
false
3.571429
[ "-cnt = 2 if N > 2 else 1", "-ret = []", "-for i in range(2, int(N**0.5) + 1):", "- if N % i == 0:", "- k = N // i", "- while k % i == 0:", "- k //= i", "- if k % i == 1:", "- cnt += 1", "- if N // i != i:", "- j = N // i", "- k = i", "- while k % j == 0:", "- k //= j", "- if k % j == 1:", "- cnt += 1", "-M = N - 1", "-for i in range(2, int((M) ** 0.5) + 1):", "- if M % i == 0:", "- cnt += 1", "- if M // i != i:", "- cnt += 1", "-print(cnt)", "+", "+", "+def divisor(N):", "+ ret = []", "+ for i in range(1, int(N**0.5) + 1):", "+ if N % i == 0:", "+ ret.append(i)", "+ if N // i != i:", "+ ret.append(N // i)", "+ return ret", "+", "+", "+div_N = divisor(N)", "+div_N_1 = divisor(N - 1)", "+ans = 0", "+for k in div_N[1:]:", "+ n = N", "+ while n % k == 0:", "+ n //= k", "+ if n % k == 1:", "+ ans += 1", "+ans += len(div_N_1) - 1", "+print(ans)" ]
false
0.260514
0.066598
3.911759
[ "s403995382", "s696915021" ]
u969850098
p03339
python
s042942239
s016331586
146
124
3,780
3,672
Accepted
Accepted
15.07
import sys readline = sys.stdin.readline def main(): N = int(readline()) S = readline().rstrip() e_right = S.count('E') w_right = S.count('W') e_left, w_left = 0, 0 res = N for i in range(N): if S[i] == 'E': e_right -= 1 res = min(res, e_right + w_left) e_left += 1 else: w_right -= 1 res = min(res, e_right + w_left) w_left += 1 print(res) if __name__ == '__main__': main()
import sys readline = sys.stdin.readline def main(): N = int(readline()) S = readline().rstrip() e_right = S.count('E') w_left = 0 res = N for i in range(N): if S[i] == 'E': e_right -= 1 res = min(res, e_right + w_left) else: res = min(res, e_right + w_left) w_left += 1 print(res) if __name__ == '__main__': main()
24
22
528
444
import sys readline = sys.stdin.readline def main(): N = int(readline()) S = readline().rstrip() e_right = S.count("E") w_right = S.count("W") e_left, w_left = 0, 0 res = N for i in range(N): if S[i] == "E": e_right -= 1 res = min(res, e_right + w_left) e_left += 1 else: w_right -= 1 res = min(res, e_right + w_left) w_left += 1 print(res) if __name__ == "__main__": main()
import sys readline = sys.stdin.readline def main(): N = int(readline()) S = readline().rstrip() e_right = S.count("E") w_left = 0 res = N for i in range(N): if S[i] == "E": e_right -= 1 res = min(res, e_right + w_left) else: res = min(res, e_right + w_left) w_left += 1 print(res) if __name__ == "__main__": main()
false
8.333333
[ "- w_right = S.count(\"W\")", "- e_left, w_left = 0, 0", "+ w_left = 0", "- e_left += 1", "- w_right -= 1" ]
false
0.040339
0.108072
0.373257
[ "s042942239", "s016331586" ]
u768559443
p03207
python
s832482316
s863316684
171
17
38,384
2,940
Accepted
Accepted
90.06
n=int(eval(input())) l=[int(eval(input())) for i in range(n)] print((sum(l)-int(max(l)/2)))
n=int(eval(input())) p=[int(eval(input())) for i in range(n)] print((sum(p)-max(p)//2))
3
4
79
77
n = int(eval(input())) l = [int(eval(input())) for i in range(n)] print((sum(l) - int(max(l) / 2)))
n = int(eval(input())) p = [int(eval(input())) for i in range(n)] print((sum(p) - max(p) // 2))
false
25
[ "-l = [int(eval(input())) for i in range(n)]", "-print((sum(l) - int(max(l) / 2)))", "+p = [int(eval(input())) for i in range(n)]", "+print((sum(p) - max(p) // 2))" ]
false
0.042023
0.043211
0.972498
[ "s832482316", "s863316684" ]
u007263493
p03796
python
s071062079
s824519077
236
40
3,976
2,940
Accepted
Accepted
83.05
n = int(eval(input())) import math print((int(math.factorial(n))%(10**9+7)))
n = int(eval(input())) mod = 10 **9 +7 ans = 1 for i in range(1, n+1): ans *= i ans = ans % mod print(ans)
4
8
72
117
n = int(eval(input())) import math print((int(math.factorial(n)) % (10**9 + 7)))
n = int(eval(input())) mod = 10**9 + 7 ans = 1 for i in range(1, n + 1): ans *= i ans = ans % mod print(ans)
false
50
[ "-import math", "-", "-print((int(math.factorial(n)) % (10**9 + 7)))", "+mod = 10**9 + 7", "+ans = 1", "+for i in range(1, n + 1):", "+ ans *= i", "+ ans = ans % mod", "+print(ans)" ]
false
0.123842
0.041859
2.95855
[ "s071062079", "s824519077" ]
u816872429
p02993
python
s353263707
s324811740
194
17
38,384
2,940
Accepted
Accepted
91.24
s = eval(input()) print(('Bad' if any(a == b for a, b in zip(s, s[1:])) else 'Good'))
s = eval(input()) print(('Bad' if any(s[i] == s[i + 1] for i in range(3)) else 'Good'))
2
2
79
80
s = eval(input()) print(("Bad" if any(a == b for a, b in zip(s, s[1:])) else "Good"))
s = eval(input()) print(("Bad" if any(s[i] == s[i + 1] for i in range(3)) else "Good"))
false
0
[ "-print((\"Bad\" if any(a == b for a, b in zip(s, s[1:])) else \"Good\"))", "+print((\"Bad\" if any(s[i] == s[i + 1] for i in range(3)) else \"Good\"))" ]
false
0.093302
0.036202
2.577299
[ "s353263707", "s324811740" ]
u869790980
p03449
python
s510726314
s262992081
75
59
75,964
64,540
Accepted
Accepted
21.33
n,mat = input(),[ list(map(int,input().split())) for i in range(2)] def f(mat,i,j): if i<0 or j <0: return -float('inf') if i == 0 and j == 0: return mat[i][j] return mat[i][j] + max(f(mat,i-1,j),f(mat,i,j-1)) print(f(mat,1,len(mat[0])-1))
n,mat = input(),[ list(map(int,input().split())) for i in range(2)] mem = {} def f(mat,i,j): if i<0 or j <0: return -float('inf') if i == 0 and j == 0: return mat[i][j] if (i,j) not in mem: mem[(i,j)] = mat[i][j] + max(f(mat,i-1,j),f(mat,i,j-1)) return mem[(i,j)] print(f(mat,1,len(mat[0])-1))
8
9
255
310
n, mat = input(), [list(map(int, input().split())) for i in range(2)] def f(mat, i, j): if i < 0 or j < 0: return -float("inf") if i == 0 and j == 0: return mat[i][j] return mat[i][j] + max(f(mat, i - 1, j), f(mat, i, j - 1)) print(f(mat, 1, len(mat[0]) - 1))
n, mat = input(), [list(map(int, input().split())) for i in range(2)] mem = {} def f(mat, i, j): if i < 0 or j < 0: return -float("inf") if i == 0 and j == 0: return mat[i][j] if (i, j) not in mem: mem[(i, j)] = mat[i][j] + max(f(mat, i - 1, j), f(mat, i, j - 1)) return mem[(i, j)] print(f(mat, 1, len(mat[0]) - 1))
false
11.111111
[ "+mem = {}", "- return mat[i][j] + max(f(mat, i - 1, j), f(mat, i, j - 1))", "+ if (i, j) not in mem:", "+ mem[(i, j)] = mat[i][j] + max(f(mat, i - 1, j), f(mat, i, j - 1))", "+ return mem[(i, j)]" ]
false
0.036779
0.057021
0.645009
[ "s510726314", "s262992081" ]
u692336506
p03494
python
s148114168
s484668108
29
26
9,116
9,044
Accepted
Accepted
10.34
N = int(eval(input())) A = list(map(int, input().split())) # N が 2 で何回割れるか def how_many_times(N): exp = 0 while N % 2 == 0: N //= 2 exp += 1 return exp result = min([how_many_times(v) for v in A]) print(result)
N = int(eval(input())) A = list(map(int, input().split())) # N が 2 で何回割れるか def how_many_times(N): exp = 0 while N % 2 == 0: N //= 2 exp += 1 return exp result = min(list(map(how_many_times, A))) print(result)
13
13
246
232
N = int(eval(input())) A = list(map(int, input().split())) # N が 2 で何回割れるか def how_many_times(N): exp = 0 while N % 2 == 0: N //= 2 exp += 1 return exp result = min([how_many_times(v) for v in A]) print(result)
N = int(eval(input())) A = list(map(int, input().split())) # N が 2 で何回割れるか def how_many_times(N): exp = 0 while N % 2 == 0: N //= 2 exp += 1 return exp result = min(list(map(how_many_times, A))) print(result)
false
0
[ "-result = min([how_many_times(v) for v in A])", "+result = min(list(map(how_many_times, A)))" ]
false
0.04182
0.04898
0.853823
[ "s148114168", "s484668108" ]
u597374218
p03999
python
s524730826
s417658441
28
18
3,060
2,940
Accepted
Accepted
35.71
S=eval(input()) ans=0 for i in range(2**(len(S)-1)): tmp=S[0] for j in range(len(S)-1): if i&(1<<j):tmp+="+" tmp+=S[j+1] ans+=eval(tmp) print(ans)
S=eval(input()) ans=0 for i in range(len(S)): for j in range(i+1): ans+=int(S[-(i+1)])*(10**j)*(2**(len(S)-1))//(2**min(i,j+1)) print(ans)
9
6
176
149
S = eval(input()) ans = 0 for i in range(2 ** (len(S) - 1)): tmp = S[0] for j in range(len(S) - 1): if i & (1 << j): tmp += "+" tmp += S[j + 1] ans += eval(tmp) print(ans)
S = eval(input()) ans = 0 for i in range(len(S)): for j in range(i + 1): ans += ( int(S[-(i + 1)]) * (10**j) * (2 ** (len(S) - 1)) // (2 ** min(i, j + 1)) ) print(ans)
false
33.333333
[ "-for i in range(2 ** (len(S) - 1)):", "- tmp = S[0]", "- for j in range(len(S) - 1):", "- if i & (1 << j):", "- tmp += \"+\"", "- tmp += S[j + 1]", "- ans += eval(tmp)", "+for i in range(len(S)):", "+ for j in range(i + 1):", "+ ans += (", "+ int(S[-(i + 1)]) * (10**j) * (2 ** (len(S) - 1)) // (2 ** min(i, j + 1))", "+ )" ]
false
0.036797
0.036038
1.021059
[ "s524730826", "s417658441" ]
u323680411
p03447
python
s835814082
s833583402
19
17
3,060
2,940
Accepted
Accepted
10.53
X = int(eval(input())) A = int(eval(input())) B = int(eval(input())) bf = X - A while bf >= B: bf -= B print(bf)
X, A, B = [int(eval(input())) for i in range(3)] X -= A X %= B print(X)
9
5
108
70
X = int(eval(input())) A = int(eval(input())) B = int(eval(input())) bf = X - A while bf >= B: bf -= B print(bf)
X, A, B = [int(eval(input())) for i in range(3)] X -= A X %= B print(X)
false
44.444444
[ "-X = int(eval(input()))", "-A = int(eval(input()))", "-B = int(eval(input()))", "-bf = X - A", "-while bf >= B:", "- bf -= B", "-print(bf)", "+X, A, B = [int(eval(input())) for i in range(3)]", "+X -= A", "+X %= B", "+print(X)" ]
false
0.036166
0.036453
0.992143
[ "s835814082", "s833583402" ]