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
u200887663
p02780
python
s820654849
s703907988
224
172
25,060
24,812
Accepted
Accepted
23.21
n,k=list(map(int,input().split())) pl=list(map(int,input().split())) cuml=[] cum=0 for i in range(n): cum+=(pl[i]+1)/2 cuml.append(cum) mx=0 for i in range(n-(k-1)): if i==0: mx=max(cuml[i+k-1],mx) else: mx=max(cuml[i+k-1]-cuml[i-1],mx) print(('{:.9f}'.format(mx)))
#n=int(input()) n,k=list(map(int,input().split())) pl=list(map(int,input().split())) #l=[list(map(int,input().split())) for i in range(n)] expl=[0.0] ansl=[] cum=0 for i in range(n): cum+=(1+pl[i])/2 expl.append(cum) for i in range(n-k+1): ansl.append(expl[i+k]-expl[i]) print(('{:.9f}'.format(max(ansl))))
15
16
305
328
n, k = list(map(int, input().split())) pl = list(map(int, input().split())) cuml = [] cum = 0 for i in range(n): cum += (pl[i] + 1) / 2 cuml.append(cum) mx = 0 for i in range(n - (k - 1)): if i == 0: mx = max(cuml[i + k - 1], mx) else: mx = max(cuml[i + k - 1] - cuml[i - 1], mx) print(("{:.9f}".format(mx)))
# n=int(input()) n, k = list(map(int, input().split())) pl = list(map(int, input().split())) # l=[list(map(int,input().split())) for i in range(n)] expl = [0.0] ansl = [] cum = 0 for i in range(n): cum += (1 + pl[i]) / 2 expl.append(cum) for i in range(n - k + 1): ansl.append(expl[i + k] - expl[i]) print(("{:.9f}".format(max(ansl))))
false
6.25
[ "+# n=int(input())", "-cuml = []", "+# l=[list(map(int,input().split())) for i in range(n)]", "+expl = [0.0]", "+ansl = []", "- cum += (pl[i] + 1) / 2", "- cuml.append(cum)", "-mx = 0", "-for i in range(n - (k - 1)):", "- if i == 0:", "- mx = max(cuml[i + k - 1], mx)", "- el...
false
0.04224
0.036434
1.15936
[ "s820654849", "s703907988" ]
u188827677
p02779
python
s975771588
s316240555
263
80
26,808
32,692
Accepted
Accepted
69.58
n = int(eval(input())) a = list(map(int, input().split())) b = list(set(a)) if sorted(a) == sorted(b): print('YES') else: print('NO')
n = int(eval(input())) a = list(input().split()) b = list(set(a)) if len(a) == len(b): print('YES') else: print('NO')
9
8
141
123
n = int(eval(input())) a = list(map(int, input().split())) b = list(set(a)) if sorted(a) == sorted(b): print("YES") else: print("NO")
n = int(eval(input())) a = list(input().split()) b = list(set(a)) if len(a) == len(b): print("YES") else: print("NO")
false
11.111111
[ "-a = list(map(int, input().split()))", "+a = list(input().split())", "-if sorted(a) == sorted(b):", "+if len(a) == len(b):" ]
false
0.043331
0.077147
0.561663
[ "s975771588", "s316240555" ]
u062484507
p03013
python
s717029191
s523821020
96
85
18,932
18,352
Accepted
Accepted
11.46
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines MOD = 10**9+7 n, m = list(map(int, readline().split())) a = list(map(int, read().split())) dp = [0] * (n + 1) ok = [1] * (n + 1) for i in a: ok[i] = 0 dp[0] = 1 dp[1] = 1 * ok[1] for i in range(2, n + 1): if ok[i - 1] == 0 and ok[i - 2] == 0: print((0)) exit() else: dp[i] = dp[i - 1]*ok[i - 1] + dp[i - 2]*ok[i - 2] if dp[i] > MOD: dp[i] %= MOD print((dp[-1]))
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines MOD = 10**9+7 n, m = list(map(int, readline().split())) a = list(map(int, read().split())) dp = [0] * (n + 1) ng = [0] * (n + 1) for i in a: ng[i] = 1 dp[0] = 1 if ng[1] != 1: dp[1] = 1 for i in range(2, n + 1): if ng[i - 1] == 1 and ng[i - 2] == 1: print((0)) exit() elif ng[i - 1] == 1: dp[i] = dp[i - 2] elif ng[i - 2] == 1: dp[i] = dp[i - 1] else: dp[i] = dp[i - 1] + dp[i - 2] if dp[i] > MOD: dp[i] %= MOD print((dp[-1]))
28
33
548
646
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines MOD = 10**9 + 7 n, m = list(map(int, readline().split())) a = list(map(int, read().split())) dp = [0] * (n + 1) ok = [1] * (n + 1) for i in a: ok[i] = 0 dp[0] = 1 dp[1] = 1 * ok[1] for i in range(2, n + 1): if ok[i - 1] == 0 and ok[i - 2] == 0: print((0)) exit() else: dp[i] = dp[i - 1] * ok[i - 1] + dp[i - 2] * ok[i - 2] if dp[i] > MOD: dp[i] %= MOD print((dp[-1]))
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines MOD = 10**9 + 7 n, m = list(map(int, readline().split())) a = list(map(int, read().split())) dp = [0] * (n + 1) ng = [0] * (n + 1) for i in a: ng[i] = 1 dp[0] = 1 if ng[1] != 1: dp[1] = 1 for i in range(2, n + 1): if ng[i - 1] == 1 and ng[i - 2] == 1: print((0)) exit() elif ng[i - 1] == 1: dp[i] = dp[i - 2] elif ng[i - 2] == 1: dp[i] = dp[i - 1] else: dp[i] = dp[i - 1] + dp[i - 2] if dp[i] > MOD: dp[i] %= MOD print((dp[-1]))
false
15.151515
[ "-ok = [1] * (n + 1)", "+ng = [0] * (n + 1)", "- ok[i] = 0", "+ ng[i] = 1", "-dp[1] = 1 * ok[1]", "+if ng[1] != 1:", "+ dp[1] = 1", "- if ok[i - 1] == 0 and ok[i - 2] == 0:", "+ if ng[i - 1] == 1 and ng[i - 2] == 1:", "+ elif ng[i - 1] == 1:", "+ dp[i] = dp[i - 2]", "+...
false
0.168819
0.042133
4.006841
[ "s717029191", "s523821020" ]
u375616706
p03733
python
s846619780
s582336360
151
135
25,200
26,836
Accepted
Accepted
10.6
N, T = list(map(int, input().split())) t = list(map(int, input().split())) ans = 0 for i in range(1, N): if t[i]-t[i-1] <= T: ans += t[i]-t[i-1] else: ans += T print((ans+T))
N, T = list(map(int, input().split())) t = list(map(int, input().split())) print((T+sum(min(T, t[i]-t[i-1]) for i in range(1, N))))
11
3
203
126
N, T = list(map(int, input().split())) t = list(map(int, input().split())) ans = 0 for i in range(1, N): if t[i] - t[i - 1] <= T: ans += t[i] - t[i - 1] else: ans += T print((ans + T))
N, T = list(map(int, input().split())) t = list(map(int, input().split())) print((T + sum(min(T, t[i] - t[i - 1]) for i in range(1, N))))
false
72.727273
[ "-ans = 0", "-for i in range(1, N):", "- if t[i] - t[i - 1] <= T:", "- ans += t[i] - t[i - 1]", "- else:", "- ans += T", "-print((ans + T))", "+print((T + sum(min(T, t[i] - t[i - 1]) for i in range(1, N))))" ]
false
0.045596
0.041532
1.097839
[ "s846619780", "s582336360" ]
u774160580
p03805
python
s606389491
s971034571
33
30
3,064
3,064
Accepted
Accepted
9.09
import itertools as it N, M = list(map(int, input().split())) graph = [[] for i in range(N)] for i in range(M): a, b = list(map(int, input().split())) a, b = a - 1, b - 1 graph[a].append(b) graph[b].append(a) ans = 0 for path in it.permutations(list(range(N))): if path[0] != 0: continue is_connected = True for ith_edge in range(len(path) - 1): if path[ith_edge + 1] not in graph[path[ith_edge]]: is_connected = False break if is_connected: ans += 1 print(ans)
import itertools as it N, M = list(map(int, input().split())) graph = [[] for i in range(N)] for i in range(M): a, b = list(map(int, input().split())) a, b = a - 1, b - 1 graph[a].append(b) graph[b].append(a) ans = 0 for path in it.permutations(list(range(N))): if path[0] != 0: break is_connected = True for ith_edge in range(len(path) - 1): if path[ith_edge + 1] not in graph[path[ith_edge]]: is_connected = False break if is_connected: ans += 1 print(ans)
21
21
545
542
import itertools as it N, M = list(map(int, input().split())) graph = [[] for i in range(N)] for i in range(M): a, b = list(map(int, input().split())) a, b = a - 1, b - 1 graph[a].append(b) graph[b].append(a) ans = 0 for path in it.permutations(list(range(N))): if path[0] != 0: continue is_connected = True for ith_edge in range(len(path) - 1): if path[ith_edge + 1] not in graph[path[ith_edge]]: is_connected = False break if is_connected: ans += 1 print(ans)
import itertools as it N, M = list(map(int, input().split())) graph = [[] for i in range(N)] for i in range(M): a, b = list(map(int, input().split())) a, b = a - 1, b - 1 graph[a].append(b) graph[b].append(a) ans = 0 for path in it.permutations(list(range(N))): if path[0] != 0: break is_connected = True for ith_edge in range(len(path) - 1): if path[ith_edge + 1] not in graph[path[ith_edge]]: is_connected = False break if is_connected: ans += 1 print(ans)
false
0
[ "- continue", "+ break" ]
false
0.154226
0.007329
21.043367
[ "s606389491", "s971034571" ]
u011634450
p03069
python
s526916020
s737724629
94
51
3,624
11,136
Accepted
Accepted
45.74
def C(N, S): cand = "#" * N n_diff_chars = sum(a!=b for a, b in zip(cand, S)) min_n_diff_chars = n_diff_chars for c in S: if c == ".": n_diff_chars -= 1 else: n_diff_chars += 1 min_n_diff_chars = min(min_n_diff_chars, n_diff_chars) print(min_n_diff_chars) if __name__ == "__main__": N = int(eval(input())) S = eval(input()) C(N, S)
def C(N, S): n_diff_chars = S.count(".") cand_list = [n_diff_chars] for c in S: if c == ".": n_diff_chars -= 1 else: n_diff_chars += 1 cand_list.append(n_diff_chars) print((min(cand_list))) if __name__ == "__main__": N = int(eval(input())) S = eval(input()) C(N, S)
17
16
417
344
def C(N, S): cand = "#" * N n_diff_chars = sum(a != b for a, b in zip(cand, S)) min_n_diff_chars = n_diff_chars for c in S: if c == ".": n_diff_chars -= 1 else: n_diff_chars += 1 min_n_diff_chars = min(min_n_diff_chars, n_diff_chars) print(min_n_diff_chars) if __name__ == "__main__": N = int(eval(input())) S = eval(input()) C(N, S)
def C(N, S): n_diff_chars = S.count(".") cand_list = [n_diff_chars] for c in S: if c == ".": n_diff_chars -= 1 else: n_diff_chars += 1 cand_list.append(n_diff_chars) print((min(cand_list))) if __name__ == "__main__": N = int(eval(input())) S = eval(input()) C(N, S)
false
5.882353
[ "- cand = \"#\" * N", "- n_diff_chars = sum(a != b for a, b in zip(cand, S))", "- min_n_diff_chars = n_diff_chars", "+ n_diff_chars = S.count(\".\")", "+ cand_list = [n_diff_chars]", "- min_n_diff_chars = min(min_n_diff_chars, n_diff_chars)", "- print(min_n_diff_chars)", "+ ...
false
0.033199
0.031459
1.055308
[ "s526916020", "s737724629" ]
u102461423
p03053
python
s817866212
s998340422
980
239
105,976
20,256
Accepted
Accepted
75.61
import sys sys.setrecursionlimit(10**6) input = sys.stdin.readline H,W = list(map(int,input().split())) INF = 10**18 q = [] visited = [[True]*(W+2)] visited += [[True] + [x == '#' for x in input().rstrip()] + [True] for _ in range(H)] visited.append([True]*(W+2)) for i in range(1,H+1): for j in range(1,W+1): if visited[i][j]: q.append((i,j)) moves = [(0,1),(0,-1),(1,0),(-1,0)] ans = -1 while q: qq = [] ans += 1 for x,y in q: if not visited[x-1][y]: visited[x-1][y] = True qq.append((x-1,y)) if not visited[x+1][y]: visited[x+1][y] = True qq.append((x+1,y)) if not visited[x][y-1]: visited[x][y-1] = True qq.append((x,y-1)) if not visited[x][y+1]: visited[x][y+1] = True qq.append((x,y+1)) q = qq print(ans)
import numpy as np import sys # 距離K以内にxが居ない # xからの距離を測る buf = sys.stdin.buffer R,C = list(map(int,buf.readline().split())) black = np.zeros((R+2,C+2),dtype=np.bool) black[1:-1,1:] = (np.frombuffer(buf.read(R*(C+1)),dtype='S1') == b'#').reshape(R,C+1) INF = 10 ** 9 dist = np.zeros((R,C),dtype=np.int32) dist[~black[1:-1,1:-1]] = INF for n in range(1,R): np.minimum(dist[n-1]+1,dist[n],out=dist[n]) for n in range(R-2,-1,-1): np.minimum(dist[n+1]+1,dist[n],out=dist[n]) for n in range(1,C): np.minimum(dist[:,n-1]+1,dist[:,n],out=dist[:,n]) for n in range(C-2,-1,-1): np.minimum(dist[:,n+1]+1,dist[:,n],out=dist[:,n]) answer = dist.max() print(answer)
39
26
836
683
import sys sys.setrecursionlimit(10**6) input = sys.stdin.readline H, W = list(map(int, input().split())) INF = 10**18 q = [] visited = [[True] * (W + 2)] visited += [[True] + [x == "#" for x in input().rstrip()] + [True] for _ in range(H)] visited.append([True] * (W + 2)) for i in range(1, H + 1): for j in range(1, W + 1): if visited[i][j]: q.append((i, j)) moves = [(0, 1), (0, -1), (1, 0), (-1, 0)] ans = -1 while q: qq = [] ans += 1 for x, y in q: if not visited[x - 1][y]: visited[x - 1][y] = True qq.append((x - 1, y)) if not visited[x + 1][y]: visited[x + 1][y] = True qq.append((x + 1, y)) if not visited[x][y - 1]: visited[x][y - 1] = True qq.append((x, y - 1)) if not visited[x][y + 1]: visited[x][y + 1] = True qq.append((x, y + 1)) q = qq print(ans)
import numpy as np import sys # 距離K以内にxが居ない # xからの距離を測る buf = sys.stdin.buffer R, C = list(map(int, buf.readline().split())) black = np.zeros((R + 2, C + 2), dtype=np.bool) black[1:-1, 1:] = (np.frombuffer(buf.read(R * (C + 1)), dtype="S1") == b"#").reshape( R, C + 1 ) INF = 10**9 dist = np.zeros((R, C), dtype=np.int32) dist[~black[1:-1, 1:-1]] = INF for n in range(1, R): np.minimum(dist[n - 1] + 1, dist[n], out=dist[n]) for n in range(R - 2, -1, -1): np.minimum(dist[n + 1] + 1, dist[n], out=dist[n]) for n in range(1, C): np.minimum(dist[:, n - 1] + 1, dist[:, n], out=dist[:, n]) for n in range(C - 2, -1, -1): np.minimum(dist[:, n + 1] + 1, dist[:, n], out=dist[:, n]) answer = dist.max() print(answer)
false
33.333333
[ "+import numpy as np", "-sys.setrecursionlimit(10**6)", "-input = sys.stdin.readline", "-H, W = list(map(int, input().split()))", "-INF = 10**18", "-q = []", "-visited = [[True] * (W + 2)]", "-visited += [[True] + [x == \"#\" for x in input().rstrip()] + [True] for _ in range(H)]", "-visited.append(...
false
0.038041
0.43517
0.087417
[ "s817866212", "s998340422" ]
u038021590
p03165
python
s682286850
s820584475
992
328
405,896
144,656
Accepted
Accepted
66.94
from collections import deque s = eval(input()) t = eval(input()) ls = len(s) lt = len(t) DP_len = [[0] * (lt + 1) for i in range(ls + 1)] Prev =[[0] * (lt + 1) for i in range(ls + 1)] for i in range(1, ls + 1): for j in range(1, lt + 1): if s[i - 1] == t[j - 1]: if max(DP_len[i - 1][j - 1] + 1, DP_len[i][j - 1], DP_len[i - 1][j]) == DP_len[i-1][j-1] + 1: DP_len[i][j] = DP_len[i-1][j-1] + 1 Prev[i][j] = (i-1, j-1) else: if DP_len[i][j - 1] >= DP_len[i - 1][j]: DP_len[i][j] = DP_len[i][j - 1] Prev[i][j] = (i, j - 1) else: DP_len[i][j] = DP_len[i - 1][j] Prev[i][j] = (i - 1, j) else: if DP_len[i][j - 1] >= DP_len[i - 1][j]: DP_len[i][j] = DP_len[i][j - 1] Prev[i][j] = (i, j-1) else: DP_len[i][j] = DP_len[i - 1][j] Prev[i][j] = (i - 1, j) x = ls y = lt ans = '' while True: if x == 0 or y == 0: break nx, ny = Prev[x][y] if (nx != x) and (ny != y): ans = s[x-1] + ans x = nx y = ny print(ans)
S = eval(input()) T = eval(input()) ls = len(S) lt = len(T) DP = [[0] * (lt + 1) for _ in range(ls + 1)] Ans = [] for i, s in enumerate(S, 1): for j, t in enumerate(T, 1): if s == t: DP[i][j] = DP[i - 1][j - 1] + 1 else: DP[i][j] = max(DP[i - 1][j], DP[i][j - 1]) cnts = ls cntt = lt while DP[cnts][cntt]: while DP[cnts][cntt] == DP[cnts][cntt - 1]: cntt -= 1 while DP[cnts][cntt] == DP[cnts - 1][cntt]: cnts -= 1 cnts -= 1 cntt -= 1 Ans.append(S[cnts]) print((''.join(Ans[::-1])))
42
25
1,244
574
from collections import deque s = eval(input()) t = eval(input()) ls = len(s) lt = len(t) DP_len = [[0] * (lt + 1) for i in range(ls + 1)] Prev = [[0] * (lt + 1) for i in range(ls + 1)] for i in range(1, ls + 1): for j in range(1, lt + 1): if s[i - 1] == t[j - 1]: if ( max(DP_len[i - 1][j - 1] + 1, DP_len[i][j - 1], DP_len[i - 1][j]) == DP_len[i - 1][j - 1] + 1 ): DP_len[i][j] = DP_len[i - 1][j - 1] + 1 Prev[i][j] = (i - 1, j - 1) else: if DP_len[i][j - 1] >= DP_len[i - 1][j]: DP_len[i][j] = DP_len[i][j - 1] Prev[i][j] = (i, j - 1) else: DP_len[i][j] = DP_len[i - 1][j] Prev[i][j] = (i - 1, j) else: if DP_len[i][j - 1] >= DP_len[i - 1][j]: DP_len[i][j] = DP_len[i][j - 1] Prev[i][j] = (i, j - 1) else: DP_len[i][j] = DP_len[i - 1][j] Prev[i][j] = (i - 1, j) x = ls y = lt ans = "" while True: if x == 0 or y == 0: break nx, ny = Prev[x][y] if (nx != x) and (ny != y): ans = s[x - 1] + ans x = nx y = ny print(ans)
S = eval(input()) T = eval(input()) ls = len(S) lt = len(T) DP = [[0] * (lt + 1) for _ in range(ls + 1)] Ans = [] for i, s in enumerate(S, 1): for j, t in enumerate(T, 1): if s == t: DP[i][j] = DP[i - 1][j - 1] + 1 else: DP[i][j] = max(DP[i - 1][j], DP[i][j - 1]) cnts = ls cntt = lt while DP[cnts][cntt]: while DP[cnts][cntt] == DP[cnts][cntt - 1]: cntt -= 1 while DP[cnts][cntt] == DP[cnts - 1][cntt]: cnts -= 1 cnts -= 1 cntt -= 1 Ans.append(S[cnts]) print(("".join(Ans[::-1])))
false
40.47619
[ "-from collections import deque", "-", "-s = eval(input())", "-t = eval(input())", "-ls = len(s)", "-lt = len(t)", "-DP_len = [[0] * (lt + 1) for i in range(ls + 1)]", "-Prev = [[0] * (lt + 1) for i in range(ls + 1)]", "-for i in range(1, ls + 1):", "- for j in range(1, lt + 1):", "- i...
false
0.060887
0.087081
0.699203
[ "s682286850", "s820584475" ]
u131984977
p02392
python
s163637605
s421725295
40
30
6,724
6,724
Accepted
Accepted
25
x = input().split(' ') a = int(x[0]) b = int(x[1]) c = int(x[2]) if a < b < c: print('Yes') else: print('No')
(a, b, c) = input().rstrip().split() a = int(a) b = int(b) c = int(c) if a < b < c: print('Yes') else: print('No')
9
9
126
131
x = input().split(" ") a = int(x[0]) b = int(x[1]) c = int(x[2]) if a < b < c: print("Yes") else: print("No")
(a, b, c) = input().rstrip().split() a = int(a) b = int(b) c = int(c) if a < b < c: print("Yes") else: print("No")
false
0
[ "-x = input().split(\" \")", "-a = int(x[0])", "-b = int(x[1])", "-c = int(x[2])", "+(a, b, c) = input().rstrip().split()", "+a = int(a)", "+b = int(b)", "+c = int(c)" ]
false
0.046463
0.042875
1.083683
[ "s163637605", "s421725295" ]
u361381049
p02848
python
s995767506
s689053233
24
21
3,188
3,188
Accepted
Accepted
12.5
n = int(eval(input())) s = list(eval(input())) a = [] for i in range(len(s)): b = ord(s[i]) b -= 65 b += n b = b % 26 b += 65 b = chr(b) a.append(b) a= ''.join(a) print(a)
n = int(eval(input())) s = list(eval(input())) a = [] for i in range(len(s)): b = chr((ord(s[i]) -65 + n) % 26 + 65) a.append(b) a= ''.join(a) print(a)
18
9
200
154
n = int(eval(input())) s = list(eval(input())) a = [] for i in range(len(s)): b = ord(s[i]) b -= 65 b += n b = b % 26 b += 65 b = chr(b) a.append(b) a = "".join(a) print(a)
n = int(eval(input())) s = list(eval(input())) a = [] for i in range(len(s)): b = chr((ord(s[i]) - 65 + n) % 26 + 65) a.append(b) a = "".join(a) print(a)
false
50
[ "- b = ord(s[i])", "- b -= 65", "- b += n", "- b = b % 26", "- b += 65", "- b = chr(b)", "+ b = chr((ord(s[i]) - 65 + n) % 26 + 65)" ]
false
0.044846
0.044193
1.014777
[ "s995767506", "s689053233" ]
u073852194
p03078
python
s642659489
s474110949
396
302
58,588
52,188
Accepted
Accepted
23.74
import heapq import collections x,y,z,k = list(map(int,input().split())) A = list(map(int,input().split())) B = list(map(int,input().split())) C = list(map(int,input().split())) A.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) heap = [] heapq.heapify(heap) heapq.heappush(heap,(-(A[0]+B[0]+C[0]),0,0,0)) dictionary = collections.defaultdict(bool) dictionary[(0,0,0)] = True i = 0 while i<k: M = heapq.heappop(heap) print((-M[0])) i += 1 if not dictionary[(M[1]+1,M[2],M[3])] and M[1]+1<x: heapq.heappush(heap,(-(A[M[1]+1]+B[M[2]]+C[M[3]]),M[1]+1,M[2],M[3])) dictionary[(M[1]+1,M[2],M[3])] = True if not dictionary[(M[1],M[2]+1,M[3])] and M[2]+1<y: heapq.heappush(heap,(-(A[M[1]]+B[M[2]+1]+C[M[3]]),M[1],M[2]+1,M[3])) dictionary[(M[1],M[2]+1,M[3])] = True if not dictionary[(M[1],M[2],M[3]+1)] and M[3]+1<z: heapq.heappush(heap,(-(A[M[1]]+B[M[2]]+C[M[3]+1]),M[1],M[2],M[3]+1)) dictionary[(M[1],M[2],M[3]+1)] = True
from heapq import heappop, heappush, heapify X, Y, Z, K = list(map(int,input().split())) A = list(map(int,input().split())) B = list(map(int,input().split())) C = list(map(int,input().split())) A.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) heap = list() used = set() res = list() heappush(heap, (-(A[0] + B[0] + C[0]), 0, 0, 0)) used.add((0, 0, 0)) for _ in range(K): v, i, j, k = heappop(heap) res.append(-v) if i + 1 < X and (i + 1, j, k) not in used: used.add((i + 1, j, k)) heappush(heap, (-(A[i + 1] + B[j] + C[k]), i + 1, j, k)) if j + 1 < Y and (i, j + 1, k) not in used: used.add((i, j + 1, k)) heappush(heap, (-(A[i] + B[j + 1] + C[k]), i, j + 1, k)) if k + 1 < Z and (i, j, k + 1) not in used: used.add((i, j, k + 1)) heappush(heap, (-(A[i] + B[j] + C[k + 1]), i, j, k + 1)) print(('\n'.join(map(str, res))))
34
32
1,030
940
import heapq import collections x, y, z, k = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) heap = [] heapq.heapify(heap) heapq.heappush(heap, (-(A[0] + B[0] + C[0]), 0, 0, 0)) dictionary = collections.defaultdict(bool) dictionary[(0, 0, 0)] = True i = 0 while i < k: M = heapq.heappop(heap) print((-M[0])) i += 1 if not dictionary[(M[1] + 1, M[2], M[3])] and M[1] + 1 < x: heapq.heappush(heap, (-(A[M[1] + 1] + B[M[2]] + C[M[3]]), M[1] + 1, M[2], M[3])) dictionary[(M[1] + 1, M[2], M[3])] = True if not dictionary[(M[1], M[2] + 1, M[3])] and M[2] + 1 < y: heapq.heappush(heap, (-(A[M[1]] + B[M[2] + 1] + C[M[3]]), M[1], M[2] + 1, M[3])) dictionary[(M[1], M[2] + 1, M[3])] = True if not dictionary[(M[1], M[2], M[3] + 1)] and M[3] + 1 < z: heapq.heappush(heap, (-(A[M[1]] + B[M[2]] + C[M[3] + 1]), M[1], M[2], M[3] + 1)) dictionary[(M[1], M[2], M[3] + 1)] = True
from heapq import heappop, heappush, heapify X, Y, Z, K = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) heap = list() used = set() res = list() heappush(heap, (-(A[0] + B[0] + C[0]), 0, 0, 0)) used.add((0, 0, 0)) for _ in range(K): v, i, j, k = heappop(heap) res.append(-v) if i + 1 < X and (i + 1, j, k) not in used: used.add((i + 1, j, k)) heappush(heap, (-(A[i + 1] + B[j] + C[k]), i + 1, j, k)) if j + 1 < Y and (i, j + 1, k) not in used: used.add((i, j + 1, k)) heappush(heap, (-(A[i] + B[j + 1] + C[k]), i, j + 1, k)) if k + 1 < Z and (i, j, k + 1) not in used: used.add((i, j, k + 1)) heappush(heap, (-(A[i] + B[j] + C[k + 1]), i, j, k + 1)) print(("\n".join(map(str, res))))
false
5.882353
[ "-import heapq", "-import collections", "+from heapq import heappop, heappush, heapify", "-x, y, z, k = list(map(int, input().split()))", "+X, Y, Z, K = list(map(int, input().split()))", "-heap = []", "-heapq.heapify(heap)", "-heapq.heappush(heap, (-(A[0] + B[0] + C[0]), 0, 0, 0))", "-dictionary = c...
false
0.036606
0.04611
0.793871
[ "s642659489", "s474110949" ]
u921615009
p03262
python
s215628278
s915334603
462
131
23,132
14,748
Accepted
Accepted
71.65
from functools import reduce import numpy as np def gcd(a, b): if b > 0: return gcd(b, a%b) else: return a def gcd_list(arg_list): return reduce(gcd, arg_list) N, X = tuple(map(int, input().split(" "))) Xs = [X] + list(map(int, input().split(" "))) Xs = list(map(abs, np.diff(Xs))) r = gcd_list(Xs) print(r)
from functools import * N, X = list(map(int, input().split(" "))) xs = list(map(int, input().split(" "))) xs = list([X-x if X>x else x-X for x in xs]) def gcd(a, b): if b == 0: return a return gcd(b, a%b) r = reduce(gcd, xs) print(r)
17
10
349
265
from functools import reduce import numpy as np def gcd(a, b): if b > 0: return gcd(b, a % b) else: return a def gcd_list(arg_list): return reduce(gcd, arg_list) N, X = tuple(map(int, input().split(" "))) Xs = [X] + list(map(int, input().split(" "))) Xs = list(map(abs, np.diff(Xs))) r = gcd_list(Xs) print(r)
from functools import * N, X = list(map(int, input().split(" "))) xs = list(map(int, input().split(" "))) xs = list([X - x if X > x else x - X for x in xs]) def gcd(a, b): if b == 0: return a return gcd(b, a % b) r = reduce(gcd, xs) print(r)
false
41.176471
[ "-from functools import reduce", "-import numpy as np", "+from functools import *", "+", "+N, X = list(map(int, input().split(\" \")))", "+xs = list(map(int, input().split(\" \")))", "+xs = list([X - x if X > x else x - X for x in xs])", "- if b > 0:", "- return gcd(b, a % b)", "- els...
false
0.199841
0.066273
3.015416
[ "s215628278", "s915334603" ]
u072053884
p02417
python
s464910903
s560349443
70
30
7,916
7,980
Accepted
Accepted
57.14
import string import sys input_str = "" for i in sys.stdin: input_str += i for i in range(26): char = string.ascii_lowercase[i] CHAR = string.ascii_uppercase[i] cnt = input_str.count(char) + input_str.count(CHAR) print(("{0} : {1}".format(char, cnt)))
import string import sys input_str = sys.stdin.read() for i in range(26): char = string.ascii_lowercase[i] CHAR = string.ascii_uppercase[i] cnt = input_str.count(char) + input_str.count(CHAR) print(("{0} : {1}".format(char, cnt)))
13
10
284
255
import string import sys input_str = "" for i in sys.stdin: input_str += i for i in range(26): char = string.ascii_lowercase[i] CHAR = string.ascii_uppercase[i] cnt = input_str.count(char) + input_str.count(CHAR) print(("{0} : {1}".format(char, cnt)))
import string import sys input_str = sys.stdin.read() for i in range(26): char = string.ascii_lowercase[i] CHAR = string.ascii_uppercase[i] cnt = input_str.count(char) + input_str.count(CHAR) print(("{0} : {1}".format(char, cnt)))
false
23.076923
[ "-input_str = \"\"", "-for i in sys.stdin:", "- input_str += i", "+input_str = sys.stdin.read()" ]
false
0.042555
0.043664
0.974599
[ "s464910903", "s560349443" ]
u754022296
p03627
python
s088066984
s356582107
100
72
18,600
22,132
Accepted
Accepted
28
from collections import defaultdict n = int(eval(input())) A = list(map(int, input().split())) d = defaultdict(int) l = [] for key in A: d[key] += 1 if d[key] == 2: l.append(key) d[key] = 0 if len(l) < 2: print((0)) else: l.sort(reverse=True) print((l[0]*l[1]))
from collections import Counter n = int(eval(input())) A = list(map(int, input().split())) C = Counter(A) L = [] for k, v in list(C.items()): if v >= 2: L.append(k) if v >= 4: L.append(k) if len(L) < 2: print((0)) else: L.sort() ans = L[-1] * L[-2] print(ans)
16
17
285
282
from collections import defaultdict n = int(eval(input())) A = list(map(int, input().split())) d = defaultdict(int) l = [] for key in A: d[key] += 1 if d[key] == 2: l.append(key) d[key] = 0 if len(l) < 2: print((0)) else: l.sort(reverse=True) print((l[0] * l[1]))
from collections import Counter n = int(eval(input())) A = list(map(int, input().split())) C = Counter(A) L = [] for k, v in list(C.items()): if v >= 2: L.append(k) if v >= 4: L.append(k) if len(L) < 2: print((0)) else: L.sort() ans = L[-1] * L[-2] print(ans)
false
5.882353
[ "-from collections import defaultdict", "+from collections import Counter", "-d = defaultdict(int)", "-l = []", "-for key in A:", "- d[key] += 1", "- if d[key] == 2:", "- l.append(key)", "- d[key] = 0", "-if len(l) < 2:", "+C = Counter(A)", "+L = []", "+for k, v in list(C...
false
0.046692
0.045454
1.027239
[ "s088066984", "s356582107" ]
u238667145
p02388
python
s329469583
s776315486
30
20
6,724
7,792
Accepted
Accepted
33.33
x = int(eval(input())) print((x*x*x))
import math print((int(math.pow(int(eval(input())), 3))))
2
3
30
52
x = int(eval(input())) print((x * x * x))
import math print((int(math.pow(int(eval(input())), 3))))
false
33.333333
[ "-x = int(eval(input()))", "-print((x * x * x))", "+import math", "+", "+print((int(math.pow(int(eval(input())), 3))))" ]
false
0.037797
0.042111
0.897571
[ "s329469583", "s776315486" ]
u571128069
p03062
python
s407379969
s987496393
101
79
11,668
11,212
Accepted
Accepted
21.78
from itertools import * N = int(eval(input())) An = list(map(int, input().split())) total = 0 minim = 1000000000 num_negs = 0 for a in An: if a < 0: num_negs += 1 a *= -1 pass total += a minim = min(minim, a) pass if num_negs % 2: print((total - 2*minim)) else: print(total) pass
N = int(eval(input())) An = list(map(int, input().split())) total = 0 minim = 1000000000 num_negs = 0 for a in An: if a < 0: num_negs += 1 a *= -1 pass total += a minim = minim if minim < a else a pass if num_negs % 2: print((total - 2*minim)) else: print(total) pass
23
22
344
331
from itertools import * N = int(eval(input())) An = list(map(int, input().split())) total = 0 minim = 1000000000 num_negs = 0 for a in An: if a < 0: num_negs += 1 a *= -1 pass total += a minim = min(minim, a) pass if num_negs % 2: print((total - 2 * minim)) else: print(total) pass
N = int(eval(input())) An = list(map(int, input().split())) total = 0 minim = 1000000000 num_negs = 0 for a in An: if a < 0: num_negs += 1 a *= -1 pass total += a minim = minim if minim < a else a pass if num_negs % 2: print((total - 2 * minim)) else: print(total) pass
false
4.347826
[ "-from itertools import *", "-", "- minim = min(minim, a)", "+ minim = minim if minim < a else a" ]
false
0.045133
0.04454
1.013323
[ "s407379969", "s987496393" ]
u584658281
p02707
python
s531841195
s238813596
220
146
36,148
32,260
Accepted
Accepted
33.64
N = int(eval(input())) A = list(map(int,input().split())) from collections import defaultdict d = defaultdict(int) for ai in A: d[ai] += 1 for n in range(1,N+1): print((d[n]))
N=int(eval(input())) A=list(map(int,input().split())) c = [0]*(N+1) for ai in A: c[ai] +=1 for i in c[1:]: print(i)
11
8
184
123
N = int(eval(input())) A = list(map(int, input().split())) from collections import defaultdict d = defaultdict(int) for ai in A: d[ai] += 1 for n in range(1, N + 1): print((d[n]))
N = int(eval(input())) A = list(map(int, input().split())) c = [0] * (N + 1) for ai in A: c[ai] += 1 for i in c[1:]: print(i)
false
27.272727
[ "-from collections import defaultdict", "-", "-d = defaultdict(int)", "+c = [0] * (N + 1)", "- d[ai] += 1", "-for n in range(1, N + 1):", "- print((d[n]))", "+ c[ai] += 1", "+for i in c[1:]:", "+ print(i)" ]
false
0.034286
0.035202
0.973982
[ "s531841195", "s238813596" ]
u414980766
p02887
python
s596840388
s125839960
69
42
3,316
3,316
Accepted
Accepted
39.13
N = int(eval(input())) S = eval(input()) res = 0 i = 0 while i < N: j = 1 while i + j < N and S[i] == S[i + j]: j += 1 i += j res += 1 print(res)
N = int(eval(input())) S = eval(input()) res = 1 a = S[0] for i in range(N): if a != S[i]: res += 1 a = S[i] print(res)
12
10
169
137
N = int(eval(input())) S = eval(input()) res = 0 i = 0 while i < N: j = 1 while i + j < N and S[i] == S[i + j]: j += 1 i += j res += 1 print(res)
N = int(eval(input())) S = eval(input()) res = 1 a = S[0] for i in range(N): if a != S[i]: res += 1 a = S[i] print(res)
false
16.666667
[ "-res = 0", "-i = 0", "-while i < N:", "- j = 1", "- while i + j < N and S[i] == S[i + j]:", "- j += 1", "- i += j", "- res += 1", "+res = 1", "+a = S[0]", "+for i in range(N):", "+ if a != S[i]:", "+ res += 1", "+ a = S[i]" ]
false
0.032347
0.040966
0.789598
[ "s596840388", "s125839960" ]
u596276291
p03550
python
s375852860
s615853056
736
27
48,728
4,080
Accepted
Accepted
96.33
from collections import defaultdict, Counter from itertools import product, groupby, count, permutations, combinations from math import pi, sqrt from collections import deque from bisect import bisect, bisect_left, bisect_right from string import ascii_lowercase from functools import lru_cache INF = float("inf") import sys sys.setrecursionlimit(10000) a = [] memo = [] # 相手がi番目を引いたときにだせる最大/最小のスコア def dfs(turn, i): global memo, a if memo[turn][i] != -1: return memo[turn][i] ans = 0 if turn == 0 else INF for j in range(i + 1, len(a)): if j == len(a) - 1: s = abs(a[j] - a[i]) else: s = abs(dfs(1 - turn, j)) # X if turn == 0: ans = max(ans, s) # Y else: ans = min(ans, s) memo[turn][i] = ans return ans def solve2(N, Z, W): global a, memo a = [W] + a memo = [[-1] * len(a) for _ in range(2)] return dfs(0, 0) def solve(N, Z, W): global a ans = abs(a[-1] - W) if len(a) > 1: ans = max(ans, abs(a[-2] - a[-1])) return ans def main(): global a N, Z, W = list(map(int, input().split())) a = list(map(int, input().split())) print((solve2(N, Z, W))) if __name__ == '__main__': main()
from collections import defaultdict, Counter from itertools import product, groupby, count, permutations, combinations from math import pi, sqrt from collections import deque from bisect import bisect, bisect_left, bisect_right from string import ascii_lowercase from functools import lru_cache import sys sys.setrecursionlimit(10000) INF = float("inf") YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no" dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0] def inside(y, x, H, W): return 0 <= y < H and 0 <= x < W def ceil(a, b): return (a + b - 1) // b def main(): N, Z, W = list(map(int, input().split())) A = list(map(int, input().split())) if N == 1: print((abs(A[0] - W))) else: print((max(abs(A[-1] - W), abs(A[-1] - A[-2])))) if __name__ == '__main__': main()
63
33
1,337
844
from collections import defaultdict, Counter from itertools import product, groupby, count, permutations, combinations from math import pi, sqrt from collections import deque from bisect import bisect, bisect_left, bisect_right from string import ascii_lowercase from functools import lru_cache INF = float("inf") import sys sys.setrecursionlimit(10000) a = [] memo = [] # 相手がi番目を引いたときにだせる最大/最小のスコア def dfs(turn, i): global memo, a if memo[turn][i] != -1: return memo[turn][i] ans = 0 if turn == 0 else INF for j in range(i + 1, len(a)): if j == len(a) - 1: s = abs(a[j] - a[i]) else: s = abs(dfs(1 - turn, j)) # X if turn == 0: ans = max(ans, s) # Y else: ans = min(ans, s) memo[turn][i] = ans return ans def solve2(N, Z, W): global a, memo a = [W] + a memo = [[-1] * len(a) for _ in range(2)] return dfs(0, 0) def solve(N, Z, W): global a ans = abs(a[-1] - W) if len(a) > 1: ans = max(ans, abs(a[-2] - a[-1])) return ans def main(): global a N, Z, W = list(map(int, input().split())) a = list(map(int, input().split())) print((solve2(N, Z, W))) if __name__ == "__main__": main()
from collections import defaultdict, Counter from itertools import product, groupby, count, permutations, combinations from math import pi, sqrt from collections import deque from bisect import bisect, bisect_left, bisect_right from string import ascii_lowercase from functools import lru_cache import sys sys.setrecursionlimit(10000) INF = float("inf") YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no" dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0] def inside(y, x, H, W): return 0 <= y < H and 0 <= x < W def ceil(a, b): return (a + b - 1) // b def main(): N, Z, W = list(map(int, input().split())) A = list(map(int, input().split())) if N == 1: print((abs(A[0] - W))) else: print((max(abs(A[-1] - W), abs(A[-1] - A[-2])))) if __name__ == "__main__": main()
false
47.619048
[ "-", "-INF = float(\"inf\")", "-a = []", "-memo = []", "-# 相手がi番目を引いたときにだせる最大/最小のスコア", "-def dfs(turn, i):", "- global memo, a", "- if memo[turn][i] != -1:", "- return memo[turn][i]", "- ans = 0 if turn == 0 else INF", "- for j in range(i + 1, len(a)):", "- if j == le...
false
0.077276
0.036099
2.14069
[ "s375852860", "s615853056" ]
u389910364
p03483
python
s964231920
s490175381
893
292
10,016
62,136
Accepted
Accepted
67.3
import os import sys from collections import Counter class BinaryIndexedTree: # http://hos.ac/slides/20140319_bit.pdf def __init__(self, size): """ :param int size: """ self._bit = [0] * size self._size = size def add(self, i, w): """ i 番目に w を加える :param int i: :param int w: """ x = i + 1 while x <= self._size: self._bit[x - 1] += w x += x & -x def sum(self, i): """ [0, i) の合計 :param int i: """ ret = 0 while i > 0: ret += self._bit[i - 1] i -= i & -i return ret def __len__(self): return self._size if os.getenv("LOCAL"): sys.stdin = open("_in.txt", "r") sys.setrecursionlimit(10 ** 9) INF = float("inf") IINF = 10 ** 18 MOD = 10 ** 9 + 7 # MOD = 998244353 S = sys.stdin.buffer.readline().decode().rstrip() counter = Counter(S) # 回文にできるかどうかはかんたんに判定できる if len(S) % 2 == 0: ok = True for c, cnt in list(counter.items()): ok &= cnt % 2 == 0 else: odds = 0 for c, cnt in list(counter.items()): odds += cnt % 2 == 1 ok = odds == 1 if not ok: print((-1)) exit() # 左右に寄せる。 # 左側か右側かだけで転倒数を数える counts = [0] * 26 ls = '' mid = '' rs = '' invs = 0 for c in S: n = ord(c) - ord('a') counts[n] += 1 if counter[c] & 1: if counts[n] <= counter[c] // 2: ls += c invs += len(rs) + len(mid) elif counts[n] == counter[c] // 2 + 1: mid += c invs += len(rs) else: rs += c else: if counts[n] <= counter[c] // 2: ls += c invs += len(rs) + len(mid) else: rs += c rs = rs[::-1] # 目的の回文への置換回数と同じ回数で ls -> rs に置換できる l_idx = [[] for _ in range(26)] for i, c in enumerate(ls): n = ord(c) - ord('a') l_idx[n].append(i) counts = [0] * 26 idx = [] for i, c in enumerate(rs): n = ord(c) - ord('a') idx.append(l_idx[n][counts[n]]) counts[n] += 1 # idx を昇順にする == ls と同じ並びにするまでの回数 invs2 = 0 bit = BinaryIndexedTree(size=len(ls)) for i in reversed(idx): invs2 += bit.sum(i) bit.add(i, 1) ans = invs + invs2 # print(invs, invs2) # print(ls, rs) # print(idx) print(ans)
import os import sys from collections import Counter class BinaryIndexedTree: # http://hos.ac/slides/20140319_bit.pdf def __init__(self, size): """ :param int size: """ self._bit = [0] * size self._size = size def add(self, i, w): """ i 番目に w を加える :param int i: :param int w: """ x = i + 1 while x <= self._size: self._bit[x - 1] += w x += x & -x def sum(self, i): """ [0, i) の合計 :param int i: """ ret = 0 while i > 0: ret += self._bit[i - 1] i -= i & -i return ret def __len__(self): return self._size if os.getenv("LOCAL"): sys.stdin = open("_in.txt", "r") sys.setrecursionlimit(10 ** 9) INF = float("inf") IINF = 10 ** 18 MOD = 10 ** 9 + 7 # MOD = 998244353 # PyPy だと文字列結合がめちゃくちゃ遅いっぽい S = sys.stdin.buffer.readline().decode().rstrip() counter = Counter(S) # 回文にできるかどうかはかんたんに判定できる if len(S) % 2 == 0: ok = True for c, cnt in list(counter.items()): ok &= cnt % 2 == 0 else: odds = 0 for c, cnt in list(counter.items()): odds += cnt % 2 == 1 ok = odds == 1 if not ok: print((-1)) exit() # 左右に寄せる。 # 左側か右側かだけで転倒数を数える counts = [0] * 26 ls = [] mid = [] rs = [] invs = 0 for c in S: n = ord(c) - ord('a') counts[n] += 1 if counter[c] & 1: if counts[n] <= counter[c] // 2: ls.append(c) invs += len(rs) + len(mid) elif counts[n] == counter[c] // 2 + 1: mid.append(c) invs += len(rs) else: rs.append(c) else: if counts[n] <= counter[c] // 2: ls.append(c) invs += len(rs) + len(mid) else: rs.append(c) rs = rs[::-1] # 目的の回文への置換回数と同じ回数で ls -> rs に置換できる l_idx = [[] for _ in range(26)] for i, c in enumerate(ls): n = ord(c) - ord('a') l_idx[n].append(i) counts = [0] * 26 idx = [] for i, c in enumerate(rs): n = ord(c) - ord('a') idx.append(l_idx[n][counts[n]]) counts[n] += 1 # idx を昇順にする == ls と同じ並びにするまでの回数 invs2 = 0 bit = BinaryIndexedTree(size=len(ls)) for i in reversed(idx): invs2 += bit.sum(i) bit.add(i, 1) ans = invs + invs2 # print(invs, invs2) # print(ls, rs) # print(idx) print(ans)
116
117
2,405
2,458
import os import sys from collections import Counter class BinaryIndexedTree: # http://hos.ac/slides/20140319_bit.pdf def __init__(self, size): """ :param int size: """ self._bit = [0] * size self._size = size def add(self, i, w): """ i 番目に w を加える :param int i: :param int w: """ x = i + 1 while x <= self._size: self._bit[x - 1] += w x += x & -x def sum(self, i): """ [0, i) の合計 :param int i: """ ret = 0 while i > 0: ret += self._bit[i - 1] i -= i & -i return ret def __len__(self): return self._size if os.getenv("LOCAL"): sys.stdin = open("_in.txt", "r") sys.setrecursionlimit(10**9) INF = float("inf") IINF = 10**18 MOD = 10**9 + 7 # MOD = 998244353 S = sys.stdin.buffer.readline().decode().rstrip() counter = Counter(S) # 回文にできるかどうかはかんたんに判定できる if len(S) % 2 == 0: ok = True for c, cnt in list(counter.items()): ok &= cnt % 2 == 0 else: odds = 0 for c, cnt in list(counter.items()): odds += cnt % 2 == 1 ok = odds == 1 if not ok: print((-1)) exit() # 左右に寄せる。 # 左側か右側かだけで転倒数を数える counts = [0] * 26 ls = "" mid = "" rs = "" invs = 0 for c in S: n = ord(c) - ord("a") counts[n] += 1 if counter[c] & 1: if counts[n] <= counter[c] // 2: ls += c invs += len(rs) + len(mid) elif counts[n] == counter[c] // 2 + 1: mid += c invs += len(rs) else: rs += c else: if counts[n] <= counter[c] // 2: ls += c invs += len(rs) + len(mid) else: rs += c rs = rs[::-1] # 目的の回文への置換回数と同じ回数で ls -> rs に置換できる l_idx = [[] for _ in range(26)] for i, c in enumerate(ls): n = ord(c) - ord("a") l_idx[n].append(i) counts = [0] * 26 idx = [] for i, c in enumerate(rs): n = ord(c) - ord("a") idx.append(l_idx[n][counts[n]]) counts[n] += 1 # idx を昇順にする == ls と同じ並びにするまでの回数 invs2 = 0 bit = BinaryIndexedTree(size=len(ls)) for i in reversed(idx): invs2 += bit.sum(i) bit.add(i, 1) ans = invs + invs2 # print(invs, invs2) # print(ls, rs) # print(idx) print(ans)
import os import sys from collections import Counter class BinaryIndexedTree: # http://hos.ac/slides/20140319_bit.pdf def __init__(self, size): """ :param int size: """ self._bit = [0] * size self._size = size def add(self, i, w): """ i 番目に w を加える :param int i: :param int w: """ x = i + 1 while x <= self._size: self._bit[x - 1] += w x += x & -x def sum(self, i): """ [0, i) の合計 :param int i: """ ret = 0 while i > 0: ret += self._bit[i - 1] i -= i & -i return ret def __len__(self): return self._size if os.getenv("LOCAL"): sys.stdin = open("_in.txt", "r") sys.setrecursionlimit(10**9) INF = float("inf") IINF = 10**18 MOD = 10**9 + 7 # MOD = 998244353 # PyPy だと文字列結合がめちゃくちゃ遅いっぽい S = sys.stdin.buffer.readline().decode().rstrip() counter = Counter(S) # 回文にできるかどうかはかんたんに判定できる if len(S) % 2 == 0: ok = True for c, cnt in list(counter.items()): ok &= cnt % 2 == 0 else: odds = 0 for c, cnt in list(counter.items()): odds += cnt % 2 == 1 ok = odds == 1 if not ok: print((-1)) exit() # 左右に寄せる。 # 左側か右側かだけで転倒数を数える counts = [0] * 26 ls = [] mid = [] rs = [] invs = 0 for c in S: n = ord(c) - ord("a") counts[n] += 1 if counter[c] & 1: if counts[n] <= counter[c] // 2: ls.append(c) invs += len(rs) + len(mid) elif counts[n] == counter[c] // 2 + 1: mid.append(c) invs += len(rs) else: rs.append(c) else: if counts[n] <= counter[c] // 2: ls.append(c) invs += len(rs) + len(mid) else: rs.append(c) rs = rs[::-1] # 目的の回文への置換回数と同じ回数で ls -> rs に置換できる l_idx = [[] for _ in range(26)] for i, c in enumerate(ls): n = ord(c) - ord("a") l_idx[n].append(i) counts = [0] * 26 idx = [] for i, c in enumerate(rs): n = ord(c) - ord("a") idx.append(l_idx[n][counts[n]]) counts[n] += 1 # idx を昇順にする == ls と同じ並びにするまでの回数 invs2 = 0 bit = BinaryIndexedTree(size=len(ls)) for i in reversed(idx): invs2 += bit.sum(i) bit.add(i, 1) ans = invs + invs2 # print(invs, invs2) # print(ls, rs) # print(idx) print(ans)
false
0.854701
[ "+# PyPy だと文字列結合がめちゃくちゃ遅いっぽい", "-ls = \"\"", "-mid = \"\"", "-rs = \"\"", "+ls = []", "+mid = []", "+rs = []", "- ls += c", "+ ls.append(c)", "- mid += c", "+ mid.append(c)", "- rs += c", "+ rs.append(c)", "- ls +...
false
0.037327
0.046596
0.801063
[ "s964231920", "s490175381" ]
u562935282
p02861
python
s356096165
s051624200
377
294
3,188
3,572
Accepted
Accepted
22.02
from itertools import permutations n = int(eval(input())) *ps, = (tuple(map(int, input().split())) for _ in range(n)) ret = 0 for perm in permutations(ps): it = iter(perm) p = next(it) for q in it: ret += ((p[0] - q[0]) ** 2 + (p[1] - q[1]) ** 2) ** 0.5 p = q def fact(n): if n == 0: return 1 return n * fact(n - 1) ret /= fact(n) print(ret)
def main(): from collections import namedtuple from itertools import permutations from math import factorial City = namedtuple('City', 'x y') def dist(a: City, b: City) -> float: dx = a.x - b.x dy = a.y - b.y return (dx * dx + dy * dy) ** 0.5 N = int(eval(input())) cities = [] for _ in range(N): x, y = list(map(int, input().split())) c = City(x=x, y=y) cities.append(c) total = 0 for perm in permutations(cities): it = iter(perm) p = next(it) for city in it: total += dist(p, city) p = city ans = total / factorial(N) print(ans) if __name__ == '__main__': main() # import sys # # sys.setrecursionlimit(10 ** 7) # # input = sys.stdin.readline # rstrip() # int(input()) # map(int, input().split())
22
44
400
887
from itertools import permutations n = int(eval(input())) (*ps,) = (tuple(map(int, input().split())) for _ in range(n)) ret = 0 for perm in permutations(ps): it = iter(perm) p = next(it) for q in it: ret += ((p[0] - q[0]) ** 2 + (p[1] - q[1]) ** 2) ** 0.5 p = q def fact(n): if n == 0: return 1 return n * fact(n - 1) ret /= fact(n) print(ret)
def main(): from collections import namedtuple from itertools import permutations from math import factorial City = namedtuple("City", "x y") def dist(a: City, b: City) -> float: dx = a.x - b.x dy = a.y - b.y return (dx * dx + dy * dy) ** 0.5 N = int(eval(input())) cities = [] for _ in range(N): x, y = list(map(int, input().split())) c = City(x=x, y=y) cities.append(c) total = 0 for perm in permutations(cities): it = iter(perm) p = next(it) for city in it: total += dist(p, city) p = city ans = total / factorial(N) print(ans) if __name__ == "__main__": main() # import sys # # sys.setrecursionlimit(10 ** 7) # # input = sys.stdin.readline # rstrip() # int(input()) # map(int, input().split())
false
50
[ "-from itertools import permutations", "+def main():", "+ from collections import namedtuple", "+ from itertools import permutations", "+ from math import factorial", "-n = int(eval(input()))", "-(*ps,) = (tuple(map(int, input().split())) for _ in range(n))", "-ret = 0", "-for perm in permu...
false
0.088203
0.07196
1.225715
[ "s356096165", "s051624200" ]
u163783894
p02659
python
s780795528
s084777755
24
20
10,072
9,172
Accepted
Accepted
16.67
import sys import decimal input = lambda: sys.stdin.readline().rstrip() def solve(): A, B = input().split() A = int(A) B = decimal.Decimal(B) print((int(A * B))) if __name__ == '__main__': solve()
import sys input = lambda: sys.stdin.readline().rstrip() def solve(): A, B = input().split() A = int(A) B = B.replace('.', '') B = int(B) ans = (A * B) // 100 print(ans) if __name__ == '__main__': solve()
14
17
232
255
import sys import decimal input = lambda: sys.stdin.readline().rstrip() def solve(): A, B = input().split() A = int(A) B = decimal.Decimal(B) print((int(A * B))) if __name__ == "__main__": solve()
import sys input = lambda: sys.stdin.readline().rstrip() def solve(): A, B = input().split() A = int(A) B = B.replace(".", "") B = int(B) ans = (A * B) // 100 print(ans) if __name__ == "__main__": solve()
false
17.647059
[ "-import decimal", "- B = decimal.Decimal(B)", "- print((int(A * B)))", "+ B = B.replace(\".\", \"\")", "+ B = int(B)", "+ ans = (A * B) // 100", "+ print(ans)" ]
false
0.047969
0.047191
1.016496
[ "s780795528", "s084777755" ]
u852690916
p03411
python
s719660241
s939431208
172
68
39,024
67,792
Accepted
Accepted
60.47
N=int(eval(input())) RED=[tuple(map(int, input().split())) for _ in range(N)] BLUE=[tuple(map(int, input().split())) for _ in range(N)] RED.sort(key=lambda x:x[1], reverse=True) BLUE.sort(key=lambda x:x[0]) ans=0 r_used=[False]*N for b in BLUE: for j,r in enumerate(RED): if r_used[j]: continue if r[0]<b[0] and r[1]<b[1]: ans+=1 r_used[j]=True break print(ans)
# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..) import sys def main(N, AB, CD): ans = 0 AB.sort(key=lambda x: x[0], reverse=True) for a, b in AB: CD.sort(key=lambda x: x[1]) idx = 0 while idx < len(CD): c, d = CD[idx] if a < c and b < d: break idx += 1 else: continue ans += 1 del CD[idx] print(ans) if __name__ == '__main__': input = sys.stdin.readline N = int(eval(input())) AB = [tuple(map(int, input().split())) for _ in range(N)] CD = [tuple(map(int, input().split())) for _ in range(N)] main(N, AB, CD)
17
26
429
677
N = int(eval(input())) RED = [tuple(map(int, input().split())) for _ in range(N)] BLUE = [tuple(map(int, input().split())) for _ in range(N)] RED.sort(key=lambda x: x[1], reverse=True) BLUE.sort(key=lambda x: x[0]) ans = 0 r_used = [False] * N for b in BLUE: for j, r in enumerate(RED): if r_used[j]: continue if r[0] < b[0] and r[1] < b[1]: ans += 1 r_used[j] = True break print(ans)
# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..) import sys def main(N, AB, CD): ans = 0 AB.sort(key=lambda x: x[0], reverse=True) for a, b in AB: CD.sort(key=lambda x: x[1]) idx = 0 while idx < len(CD): c, d = CD[idx] if a < c and b < d: break idx += 1 else: continue ans += 1 del CD[idx] print(ans) if __name__ == "__main__": input = sys.stdin.readline N = int(eval(input())) AB = [tuple(map(int, input().split())) for _ in range(N)] CD = [tuple(map(int, input().split())) for _ in range(N)] main(N, AB, CD)
false
34.615385
[ "-N = int(eval(input()))", "-RED = [tuple(map(int, input().split())) for _ in range(N)]", "-BLUE = [tuple(map(int, input().split())) for _ in range(N)]", "-RED.sort(key=lambda x: x[1], reverse=True)", "-BLUE.sort(key=lambda x: x[0])", "-ans = 0", "-r_used = [False] * N", "-for b in BLUE:", "- for...
false
0.118544
0.083809
1.414456
[ "s719660241", "s939431208" ]
u726615467
p02861
python
s843264967
s845241893
109
17
8,052
3,060
Accepted
Accepted
84.4
N = int(eval(input())) xy = [list(map(int, input().split())) for _ in range(N)] import math dist = [[0] * N for _ in range(N)] for i in range(N - 1): xi, yi = xy[i] for j in range(i + 1, N): xj, yj = xy[j] dist[i][j] = math.sqrt((xi - xj) ** 2 + (yi - yj) ** 2) dist[j][i] = dist[i][j] import itertools ans = 0 cases = list(itertools.permutations(list(range(N)))) for case in cases: for idx in range(N - 1): ans += dist[case[idx]][case[idx + 1]] ans /= len(cases) print(ans)
N = int(eval(input())) xy = [list(map(int, input().split())) for _ in range(N)] import math dist_sum = 0 for i in range(N): xi, yi = xy[i] for j in range(N): xj, yj = xy[j] dist_sum += math.sqrt((xi - xj) ** 2 + (yi - yj) ** 2) print((dist_sum / N))
23
13
533
280
N = int(eval(input())) xy = [list(map(int, input().split())) for _ in range(N)] import math dist = [[0] * N for _ in range(N)] for i in range(N - 1): xi, yi = xy[i] for j in range(i + 1, N): xj, yj = xy[j] dist[i][j] = math.sqrt((xi - xj) ** 2 + (yi - yj) ** 2) dist[j][i] = dist[i][j] import itertools ans = 0 cases = list(itertools.permutations(list(range(N)))) for case in cases: for idx in range(N - 1): ans += dist[case[idx]][case[idx + 1]] ans /= len(cases) print(ans)
N = int(eval(input())) xy = [list(map(int, input().split())) for _ in range(N)] import math dist_sum = 0 for i in range(N): xi, yi = xy[i] for j in range(N): xj, yj = xy[j] dist_sum += math.sqrt((xi - xj) ** 2 + (yi - yj) ** 2) print((dist_sum / N))
false
43.478261
[ "-dist = [[0] * N for _ in range(N)]", "-for i in range(N - 1):", "+dist_sum = 0", "+for i in range(N):", "- for j in range(i + 1, N):", "+ for j in range(N):", "- dist[i][j] = math.sqrt((xi - xj) ** 2 + (yi - yj) ** 2)", "- dist[j][i] = dist[i][j]", "-import itertools", "-", ...
false
0.039407
0.155815
0.25291
[ "s843264967", "s845241893" ]
u606045429
p02971
python
s272330540
s492881630
1,161
528
86,360
14,112
Accepted
Accepted
54.52
N = int(eval(input())) A = [int(eval(input())) for _ in range(N)] # http://tjkendev.github.io/procon-library/python/range_query/rmq_segment_tree.html # N: 処理する区間の長さ N0 = 2**(N-1).bit_length() INF = 2**31-1 data = [0]*(2*N0) # a_k の値を x に更新 def update(k, x): k += N0-1 data[k] = x while k >= 0: k = (k - 1) // 2 data[k] = max(data[2*k+1], data[2*k+2]) # 区間[l, r)の最小値 def query(l, r): L = l + N0 R = r + N0 s = 0 while L < R: if R & 1: R -= 1 s = max(s, data[R-1]) if L & 1: s = max(s, data[L-1]) L += 1 L >>= 1 R >>= 1 return s for i, a in enumerate(A): update(i, a) l, r = 0, 1 for _ in range(N): a, b = query(0, l), query(r, N) print((max(a, b))) l += 1 r += 1
N = int(eval(input())) A = [int(eval(input())) for _ in range(N)] B = sorted(A) f, s = B[-1], B[-2] for a in A: if a == f: print(s) else: print(f)
44
11
846
170
N = int(eval(input())) A = [int(eval(input())) for _ in range(N)] # http://tjkendev.github.io/procon-library/python/range_query/rmq_segment_tree.html # N: 処理する区間の長さ N0 = 2 ** (N - 1).bit_length() INF = 2**31 - 1 data = [0] * (2 * N0) # a_k の値を x に更新 def update(k, x): k += N0 - 1 data[k] = x while k >= 0: k = (k - 1) // 2 data[k] = max(data[2 * k + 1], data[2 * k + 2]) # 区間[l, r)の最小値 def query(l, r): L = l + N0 R = r + N0 s = 0 while L < R: if R & 1: R -= 1 s = max(s, data[R - 1]) if L & 1: s = max(s, data[L - 1]) L += 1 L >>= 1 R >>= 1 return s for i, a in enumerate(A): update(i, a) l, r = 0, 1 for _ in range(N): a, b = query(0, l), query(r, N) print((max(a, b))) l += 1 r += 1
N = int(eval(input())) A = [int(eval(input())) for _ in range(N)] B = sorted(A) f, s = B[-1], B[-2] for a in A: if a == f: print(s) else: print(f)
false
75
[ "-# http://tjkendev.github.io/procon-library/python/range_query/rmq_segment_tree.html", "-# N: 処理する区間の長さ", "-N0 = 2 ** (N - 1).bit_length()", "-INF = 2**31 - 1", "-data = [0] * (2 * N0)", "-# a_k の値を x に更新", "-def update(k, x):", "- k += N0 - 1", "- data[k] = x", "- while k >= 0:", "- ...
false
0.078918
0.037085
2.128029
[ "s272330540", "s492881630" ]
u264265458
p03035
python
s446862327
s061989976
19
17
2,940
2,940
Accepted
Accepted
10.53
i=list(map(int,input().split())) if i[0]>=13: print((i[1])) elif 6<=i[0]<=12: print((int(i[1]/2))) else : print((0))
a,b=list(map(int,input().split())) print((b if a>12 else int(b/2) if 5<a and a<13 else 0))
8
2
125
83
i = list(map(int, input().split())) if i[0] >= 13: print((i[1])) elif 6 <= i[0] <= 12: print((int(i[1] / 2))) else: print((0))
a, b = list(map(int, input().split())) print((b if a > 12 else int(b / 2) if 5 < a and a < 13 else 0))
false
75
[ "-i = list(map(int, input().split()))", "-if i[0] >= 13:", "- print((i[1]))", "-elif 6 <= i[0] <= 12:", "- print((int(i[1] / 2)))", "-else:", "- print((0))", "+a, b = list(map(int, input().split()))", "+print((b if a > 12 else int(b / 2) if 5 < a and a < 13 else 0))" ]
false
0.068208
0.072253
0.94401
[ "s446862327", "s061989976" ]
u480138356
p02925
python
s720704118
s988835928
1,812
1,359
35,064
36,992
Accepted
Accepted
25
import time def main(): N = int(eval(input())) a = [list(map(int, input().split())) for i in range(N)] start = time.time() now = [0] * N day = 0 gamed_day = [-1] * N finished = 0 while True: if time.time() - start > 1.6: print(((N*(N-1))//2)) break had_game = False all_finish = True for i in range(N-1, -1, -1): if now[i] < N-1 and gamed_day[i] != day: all_finish = False want = a[i][now[i]] - 1 if gamed_day[want] != day:# 今日試合していない if a[want][now[want]] - 1 == i:# 相手の試合相手が自分 now[want] += 1 now[i] += 1 if now[want] >= N-1: finished += 1 if now[i] >= N-1: finished += 1 gamed_day[i] = day gamed_day[want] = day had_game = True # print(day+1, i+1, want+1) if all_finish or finished == N: if had_game: print((day+1)) else: print(day) break if not had_game: print((-1)) break day += 1 # print(now) if __name__ == "__main__": main()
def main(): N = int(eval(input())) a = [list(map(int, input().split())) for i in range(N)] now = [0] * N day = 0 gamed_day = [-1] * N ind = [i for i in range(N)] while len(ind) > 0: next_ = [] while len(ind) > 0: i = ind.pop(-1) if now[i] < N-1 and gamed_day[i] != day: all_finish = False want = a[i][now[i]] - 1 if gamed_day[want] != day:# 今日試合していない if a[want][now[want]] - 1 == i:# 相手の試合相手が自分 now[want] += 1 now[i] += 1 if now[want] < N-1: next_.append(want) if now[i] < N-1: next_.append(i) gamed_day[i] = day gamed_day[want] = day had_game = True # print(day+1, i+1, want+1) ind = next_ day += 1 ok = True for i in range(N): if now[i] < N-1: ok = False break if ok: print(day) else: print((-1)) if __name__ == "__main__": main()
45
44
1,405
1,249
import time def main(): N = int(eval(input())) a = [list(map(int, input().split())) for i in range(N)] start = time.time() now = [0] * N day = 0 gamed_day = [-1] * N finished = 0 while True: if time.time() - start > 1.6: print(((N * (N - 1)) // 2)) break had_game = False all_finish = True for i in range(N - 1, -1, -1): if now[i] < N - 1 and gamed_day[i] != day: all_finish = False want = a[i][now[i]] - 1 if gamed_day[want] != day: # 今日試合していない if a[want][now[want]] - 1 == i: # 相手の試合相手が自分 now[want] += 1 now[i] += 1 if now[want] >= N - 1: finished += 1 if now[i] >= N - 1: finished += 1 gamed_day[i] = day gamed_day[want] = day had_game = True # print(day+1, i+1, want+1) if all_finish or finished == N: if had_game: print((day + 1)) else: print(day) break if not had_game: print((-1)) break day += 1 # print(now) if __name__ == "__main__": main()
def main(): N = int(eval(input())) a = [list(map(int, input().split())) for i in range(N)] now = [0] * N day = 0 gamed_day = [-1] * N ind = [i for i in range(N)] while len(ind) > 0: next_ = [] while len(ind) > 0: i = ind.pop(-1) if now[i] < N - 1 and gamed_day[i] != day: all_finish = False want = a[i][now[i]] - 1 if gamed_day[want] != day: # 今日試合していない if a[want][now[want]] - 1 == i: # 相手の試合相手が自分 now[want] += 1 now[i] += 1 if now[want] < N - 1: next_.append(want) if now[i] < N - 1: next_.append(i) gamed_day[i] = day gamed_day[want] = day had_game = True # print(day+1, i+1, want+1) ind = next_ day += 1 ok = True for i in range(N): if now[i] < N - 1: ok = False break if ok: print(day) else: print((-1)) if __name__ == "__main__": main()
false
2.222222
[ "-import time", "-", "-", "- start = time.time()", "- finished = 0", "- while True:", "- if time.time() - start > 1.6:", "- print(((N * (N - 1)) // 2))", "- break", "- had_game = False", "- all_finish = True", "- for i in range(N - 1, ...
false
0.077454
0.041519
1.865537
[ "s720704118", "s988835928" ]
u312078744
p03739
python
s061469772
s651864437
126
94
14,504
14,468
Accepted
Accepted
25.4
n = int(eval(input())) a = list(map(int, input().split())) # プラススタート ------------------ ans01 = 0 temp = a[0] if (temp > 0): pass else: add = abs(temp) + 1 ans01 += add temp = 1 for i in range(1, n): tar = temp + a[i] if (tar * temp < 0): temp = tar else: add = abs(tar) + 1 ans01 += add if (temp > 0): temp = -1 else: temp = 1 #print(tar, ans) # マイナススタート ------------------ ans02 = 0 temp = a[0] if (temp < 0): pass else: add = abs(temp) + 1 ans02 += add temp = -1 for i in range(1, n): tar = temp + a[i] if (tar * temp < 0): temp = tar else: add = abs(tar) + 1 ans02 += add if (temp > 0): temp = -1 else: temp = 1 #print(tar, ans) ans = min(ans01, ans02) print(ans)
n = int(eval(input())) a = list(map(int, input().split())) def calc(val): # valには、1か−1を入れる。 if (val * a[0] > 0): # 狙った符号のパターン temp = a[0] ans01 = 0 else: # 違うパターン add = abs(a[0]) + 1 ans01 = add temp = val for i in range(1, n): tar = temp + a[i] if (tar * temp < 0): temp = tar else: add = abs(tar) + 1 ans01 += add if (temp > 0): temp = -1 else: temp = 1 return ans01 ans = min(calc(1), calc(-1)) print(ans)
52
36
911
639
n = int(eval(input())) a = list(map(int, input().split())) # プラススタート ------------------ ans01 = 0 temp = a[0] if temp > 0: pass else: add = abs(temp) + 1 ans01 += add temp = 1 for i in range(1, n): tar = temp + a[i] if tar * temp < 0: temp = tar else: add = abs(tar) + 1 ans01 += add if temp > 0: temp = -1 else: temp = 1 # print(tar, ans) # マイナススタート ------------------ ans02 = 0 temp = a[0] if temp < 0: pass else: add = abs(temp) + 1 ans02 += add temp = -1 for i in range(1, n): tar = temp + a[i] if tar * temp < 0: temp = tar else: add = abs(tar) + 1 ans02 += add if temp > 0: temp = -1 else: temp = 1 # print(tar, ans) ans = min(ans01, ans02) print(ans)
n = int(eval(input())) a = list(map(int, input().split())) def calc(val): # valには、1か−1を入れる。 if val * a[0] > 0: # 狙った符号のパターン temp = a[0] ans01 = 0 else: # 違うパターン add = abs(a[0]) + 1 ans01 = add temp = val for i in range(1, n): tar = temp + a[i] if tar * temp < 0: temp = tar else: add = abs(tar) + 1 ans01 += add if temp > 0: temp = -1 else: temp = 1 return ans01 ans = min(calc(1), calc(-1)) print(ans)
false
30.769231
[ "-ans01 = 0", "-temp = a[0]", "-if temp > 0:", "- pass", "-else:", "- add = abs(temp) + 1", "- ans01 += add", "- temp = 1", "-for i in range(1, n):", "- tar = temp + a[i]", "- if tar * temp < 0:", "- temp = tar", "+", "+", "+def calc(val):", "+ # valには、1か−1を...
false
0.062208
0.100219
0.620723
[ "s061469772", "s651864437" ]
u282228874
p03325
python
s015203098
s751312462
88
81
4,148
4,212
Accepted
Accepted
7.95
N = int(eval(input())) A = list(map(int,input().split())) res = 0 for a in A: while a%2 == 0: res += 1 a //= 2 print(res)
n = int(eval(input())) A = list(map(int,input().split())) res = 0 for a in A: while a%2 == 0: res += 1 a //= 2 print(res)
8
8
142
142
N = int(eval(input())) A = list(map(int, input().split())) res = 0 for a in A: while a % 2 == 0: res += 1 a //= 2 print(res)
n = int(eval(input())) A = list(map(int, input().split())) res = 0 for a in A: while a % 2 == 0: res += 1 a //= 2 print(res)
false
0
[ "-N = int(eval(input()))", "+n = int(eval(input()))" ]
false
0.038636
0.040613
0.95132
[ "s015203098", "s751312462" ]
u991567869
p02958
python
s762998711
s945011577
23
17
3,444
2,940
Accepted
Accepted
26.09
import copy n = int(eval(input())) p = list(map(int, input().split())) q = copy.copy(p) q.sort() c = 0 for i in range(n): if p[i] != q[i]: c = c + 1 if c == 2 or c == 0: print("YES") else: print("NO")
n = int(eval(input())) p = list(map(int, input().split())) c = 0 for i in range(n): if p[i] != i + 1: c = c + 1 if c == 2 or c == 0: print("YES") else: print("NO")
16
12
232
190
import copy n = int(eval(input())) p = list(map(int, input().split())) q = copy.copy(p) q.sort() c = 0 for i in range(n): if p[i] != q[i]: c = c + 1 if c == 2 or c == 0: print("YES") else: print("NO")
n = int(eval(input())) p = list(map(int, input().split())) c = 0 for i in range(n): if p[i] != i + 1: c = c + 1 if c == 2 or c == 0: print("YES") else: print("NO")
false
25
[ "-import copy", "-", "-q = copy.copy(p)", "-q.sort()", "- if p[i] != q[i]:", "+ if p[i] != i + 1:" ]
false
0.04063
0.070676
0.574884
[ "s762998711", "s945011577" ]
u628285938
p02888
python
s964496688
s556818635
1,978
1,241
9,232
9,344
Accepted
Accepted
37.26
# -*- coding: utf-8 -*- """ Created on Wed Sep 9 20:56:06 2020 @author: liang """ N = int(eval(input())) L = [int(x) for x in input().split()] L.sort() ans = 0 #print(L) for i in range(N-2): #print("1:",i) p = i+2 #以下O(2?N) 定数倍が遅い for j in range(i+1,N-1): #print("2",i,j) while p < N and L[p] < L[i] + L[j] : p += 1 #print("up") #print(p) #ans += len(L[j+1:p]) ans += max(0, p - j - 1) print(ans)
# -*- coding: utf-8 -*- """ Created on Wed Sep 9 21:39:55 2020 @author: liang """ # -*- coding: utf-8 -*- """ Created on Wed Sep 9 20:56:06 2020 @author: liang """ N = int(eval(input())) L = [int(x) for x in input().split()] from bisect import bisect_left L.sort() ans = 0 #print(L) for i in range(N-2): #print("1:",i) #p = i+2 #以下O(2N) 定数倍が遅い for j in range(i+1,N-1): #print("2",i,j) t = L[i] + L[j] #while p < N and L[p] < L[i] + L[j] : # p += 1 p = bisect_left(L,t) #print("up") #print(p) #ans += len(L[j+1:p]) ans += max(0, p - j -1) print(ans)
26
37
499
681
# -*- coding: utf-8 -*- """ Created on Wed Sep 9 20:56:06 2020 @author: liang """ N = int(eval(input())) L = [int(x) for x in input().split()] L.sort() ans = 0 # print(L) for i in range(N - 2): # print("1:",i) p = i + 2 # 以下O(2?N) 定数倍が遅い for j in range(i + 1, N - 1): # print("2",i,j) while p < N and L[p] < L[i] + L[j]: p += 1 # print("up") # print(p) # ans += len(L[j+1:p]) ans += max(0, p - j - 1) print(ans)
# -*- coding: utf-8 -*- """ Created on Wed Sep 9 21:39:55 2020 @author: liang """ # -*- coding: utf-8 -*- """ Created on Wed Sep 9 20:56:06 2020 @author: liang """ N = int(eval(input())) L = [int(x) for x in input().split()] from bisect import bisect_left L.sort() ans = 0 # print(L) for i in range(N - 2): # print("1:",i) # p = i+2 # 以下O(2N) 定数倍が遅い for j in range(i + 1, N - 1): # print("2",i,j) t = L[i] + L[j] # while p < N and L[p] < L[i] + L[j] : # p += 1 p = bisect_left(L, t) # print("up") # print(p) # ans += len(L[j+1:p]) ans += max(0, p - j - 1) print(ans)
false
29.72973
[ "+# -*- coding: utf-8 -*-", "+\"\"\"", "+Created on Wed Sep 9 21:39:55 2020", "+@author: liang", "+\"\"\"", "+from bisect import bisect_left", "+", "- p = i + 2", "- # 以下O(2?N) 定数倍が遅い", "+ # p = i+2", "+ # 以下O(2N) 定数倍が遅い", "- while p < N and L[p] < L[i] + L[j]:", "- ...
false
0.038204
0.067277
0.567864
[ "s964496688", "s556818635" ]
u813098295
p02688
python
s593746250
s970252759
25
21
9,184
9,068
Accepted
Accepted
16
N, K = list(map(int, input().split())) snuke = [False] * N for i in range(K): d = int(eval(input())) a = list(map(int, input().split())) for j in range(d): snuke[a[j] - 1] = True ans = 0 for i in range(N): if not snuke[i]: ans += 1 print(ans)
N, K = list(map(int, input().split())) snukes = [0 for _ in range(N)] for _ in range(K): d = int(eval(input())) A = list(map(int, input().split())) for a in A: snukes[a - 1] += 1 print((snukes.count(0)))
15
10
280
214
N, K = list(map(int, input().split())) snuke = [False] * N for i in range(K): d = int(eval(input())) a = list(map(int, input().split())) for j in range(d): snuke[a[j] - 1] = True ans = 0 for i in range(N): if not snuke[i]: ans += 1 print(ans)
N, K = list(map(int, input().split())) snukes = [0 for _ in range(N)] for _ in range(K): d = int(eval(input())) A = list(map(int, input().split())) for a in A: snukes[a - 1] += 1 print((snukes.count(0)))
false
33.333333
[ "-snuke = [False] * N", "-for i in range(K):", "+snukes = [0 for _ in range(N)]", "+for _ in range(K):", "- a = list(map(int, input().split()))", "- for j in range(d):", "- snuke[a[j] - 1] = True", "-ans = 0", "-for i in range(N):", "- if not snuke[i]:", "- ans += 1", "-...
false
0.044996
0.039771
1.131365
[ "s593746250", "s970252759" ]
u631277801
p03287
python
s362846534
s972951376
99
84
16,300
17,796
Accepted
Accepted
15.15
from itertools import accumulate from collections import defaultdict N,M = list(map(int, input().split())) A = list(map(int, input().split())) #1 累積和をとる B = [0] + list(accumulate(A)) #2 そのmodをとる B = [b%M for b in B] #3 1~Nまで、辞書内の当該キーをansにプラスしながら進む cnt = defaultdict(int) ans = 0 for b in B: ans += cnt[b] cnt[b] += 1 print(ans)
import sys stdin = sys.stdin sys.setrecursionlimit(10**5) 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()) from collections import Counter from itertools import accumulate n,m = li() a = list(li()) acum = list(accumulate(a)) acum = [acumi%m for acumi in acum] cnt = Counter(acum) ans = cnt[0] for k,v in list(cnt.items()): ans += v*(v-1)//2 print(ans)
21
30
360
708
from itertools import accumulate from collections import defaultdict N, M = list(map(int, input().split())) A = list(map(int, input().split())) # 1 累積和をとる B = [0] + list(accumulate(A)) # 2 そのmodをとる B = [b % M for b in B] # 3 1~Nまで、辞書内の当該キーをansにプラスしながら進む cnt = defaultdict(int) ans = 0 for b in B: ans += cnt[b] cnt[b] += 1 print(ans)
import sys stdin = sys.stdin sys.setrecursionlimit(10**5) 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()) from collections import Counter from itertools import accumulate n, m = li() a = list(li()) acum = list(accumulate(a)) acum = [acumi % m for acumi in acum] cnt = Counter(acum) ans = cnt[0] for k, v in list(cnt.items()): ans += v * (v - 1) // 2 print(ans)
false
30
[ "+import sys", "+", "+stdin = sys.stdin", "+sys.setrecursionlimit(10**5)", "+", "+", "+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(ma...
false
0.047207
0.044016
1.0725
[ "s362846534", "s972951376" ]
u777923818
p03734
python
s946474204
s690039208
784
626
3,188
3,188
Accepted
Accepted
20.15
# -*- coding: utf-8 -*- from itertools import accumulate, product from operator import itemgetter def inpl(): return tuple(map(int, input().split())) N, W = inpl() I = [inpl() for _ in range(N)] w1 = I[0][0] A = {w1 + x: [] for x in range(4)} for w, v in I: A[w].append(v) for k, v in list(A.items()): A[k] = [0] + list(accumulate(sorted(v, reverse=True))) res = 0 g0 = itemgetter(0) g1 = itemgetter(1) for L in product(enumerate(A[w1]), enumerate(A[w1+1]), enumerate(A[w1+2]), enumerate(A[w1+3])): if sum([(w1+i)*l for i, l in enumerate(map(g0, L))]) <= W: res = max(res, sum(map(g1, L))) print(res)
# -*- coding: utf-8 -*- def inpl(): return list(map(int, input().split())) from itertools import accumulate, product N, W = inpl() A = [] for _ in range(N): A.append(inpl()) B = [[] for _ in range(4)] w1 = A[0][0] for w, v in A: B[w-w1].append(v) B = [sorted(b, reverse=True) for b in B] C = [[0] + list(accumulate(b)) for b in B] res = 0 for L in product(enumerate(C[0]), enumerate(C[1]), enumerate(C[2]), enumerate(C[3])): if sum([(w1+i)*l[0] for i, l in enumerate(L)]) <= W: res = max(res, sum([l[1] for l in L])) print(res)
28
27
698
635
# -*- coding: utf-8 -*- from itertools import accumulate, product from operator import itemgetter def inpl(): return tuple(map(int, input().split())) N, W = inpl() I = [inpl() for _ in range(N)] w1 = I[0][0] A = {w1 + x: [] for x in range(4)} for w, v in I: A[w].append(v) for k, v in list(A.items()): A[k] = [0] + list(accumulate(sorted(v, reverse=True))) res = 0 g0 = itemgetter(0) g1 = itemgetter(1) for L in product( enumerate(A[w1]), enumerate(A[w1 + 1]), enumerate(A[w1 + 2]), enumerate(A[w1 + 3]) ): if sum([(w1 + i) * l for i, l in enumerate(map(g0, L))]) <= W: res = max(res, sum(map(g1, L))) print(res)
# -*- coding: utf-8 -*- def inpl(): return list(map(int, input().split())) from itertools import accumulate, product N, W = inpl() A = [] for _ in range(N): A.append(inpl()) B = [[] for _ in range(4)] w1 = A[0][0] for w, v in A: B[w - w1].append(v) B = [sorted(b, reverse=True) for b in B] C = [[0] + list(accumulate(b)) for b in B] res = 0 for L in product(enumerate(C[0]), enumerate(C[1]), enumerate(C[2]), enumerate(C[3])): if sum([(w1 + i) * l[0] for i, l in enumerate(L)]) <= W: res = max(res, sum([l[1] for l in L])) print(res)
false
3.571429
[ "-from itertools import accumulate, product", "-from operator import itemgetter", "+def inpl():", "+ return list(map(int, input().split()))", "-def inpl():", "- return tuple(map(int, input().split()))", "-", "+from itertools import accumulate, product", "-I = [inpl() for _ in range(N)]", "-w...
false
0.040194
0.041363
0.971726
[ "s946474204", "s690039208" ]
u970197315
p03574
python
s993208960
s538471416
26
24
3,192
3,448
Accepted
Accepted
7.69
# ABC075 B - Minesweeper H,W = list(map(int,input().split())) G = [['' for _ in range(W+2)] for _ in range(H+2)] Ans = [[0 for _ in range(W+2)] for _ in range(H+2)] for i in range(1,H+1): S = eval(input()) for j,s in enumerate(S): G[i][j+1]= s for i in range(1,H+1): for j in range(W): # 1行目 if i == 1: if G[i][j+2] == '#': Ans[i][j+1] += 1 # if G[i][j+1] == '#': # Ans[i][j+1] = '#' if G[i][j] == '#': Ans[i][j+1] += 1 if G[i+1][j+2] == '#': Ans[i][j+1] += 1 if G[i+1][j+1] == '#': Ans[i][j+1] += 1 if G[i+1][j] == '#': Ans[i][j+1] += 1 continue # 最終行 if i == H: if G[i][j+2] == '#': Ans[i][j+1] += 1 # if G[i][j+1] == '#': # Ans[i][j+1] = '#' if G[i][j] == '#': Ans[i][j+1] += 1 if G[i-1][j+2] == '#': Ans[i][j+1] += 1 if G[i-1][j+1] == '#': Ans[i][j+1] += 1 if G[i-1][j] == '#': Ans[i][j+1] += 1 continue if G[i][j+2] == '#': Ans[i][j+1] += 1 # if G[i][j+1] == '#': # Ans[i][j+1] = '#' if G[i][j] == '#': Ans[i][j+1] += 1 if G[i+1][j+2] == '#': Ans[i][j+1] += 1 if G[i+1][j+1] == '#': Ans[i][j+1] += 1 if G[i+1][j] == '#': Ans[i][j+1] += 1 if G[i-1][j+2] == '#': Ans[i][j+1] += 1 if G[i-1][j+1] == '#': Ans[i][j+1] += 1 if G[i-1][j] == '#': Ans[i][j+1] += 1 for i in range(1,H+1): for j in range(1,W+1): Ans[i][j] = str(Ans[i][j]) if G[i][j] == '#': Ans[i][j] = '#' for i in range(1,H+1): s = '' for j in range(1,W+1): s += Ans[i][j] print(s)
h,w=list(map(int,input().split())) s=[eval(input()) for i in range(h)] a=[[0]*w for i in range(h)] if h==1 and w==1: if s[0]=="#": print("#") else: print((0)) elif h==1 and w>1: for i in range(w): t=0 if i==0: if s[0][i+1]=="#":t+=1 elif 0<i<w-1: if s[0][i+1]=="#":t+=1 if s[0][i-1]=="#":t+=1 elif i==w-1: if s[0][i-1]=="#":t+=1 if s[0][i]=="#": a[0][i]="#" else: a[0][i]=t tt="" for aa in a: for aaa in aa: tt+=str(aaa) print((str(tt))) elif w==1 and h>1: for i in range(h): t=0 if i==0: if s[i+1]=="#":t+=1 elif 0<i<h-1: if s[i+1]=="#":t+=1 if s[i-1]=="#":t+=1 elif i==h-1: if s[i-1]=="#":t+=1 if s[i]=="#": a[i][0]="#" else: a[i][0]=t for aa in a: print((*aa)) elif w>1 and h>1: for i in range(h): for j in range(w): t=0 if i==0: if j==0: if s[i][j+1]=="#":t+=1 if s[i+1][j+1]=="#":t+=1 if s[i+1][j]=="#":t+=1 elif 0<j<w-1: if s[i][j+1]=="#":t+=1 if s[i+1][j+1]=="#":t+=1 if s[i+1][j]=="#":t+=1 if s[i+1][j-1]=="#":t+=1 if s[i][j-1]=="#":t+=1 elif j==w-1: if s[i+1][j]=="#":t+=1 if s[i+1][j-1]=="#":t+=1 if s[i][j-1]=="#":t+=1 elif 0<i<h-1: if j==0: if s[i-1][j]=="#":t+=1 if s[i-1][j+1]=="#":t+=1 if s[i][j+1]=="#":t+=1 if s[i+1][j+1]=="#":t+=1 if s[i+1][j]=="#":t+=1 elif 0<j<w-1: if s[i][j+1]=="#":t+=1 if s[i+1][j+1]=="#":t+=1 if s[i+1][j]=="#":t+=1 if s[i+1][j-1]=="#":t+=1 if s[i][j-1]=="#":t+=1 if s[i-1][j-1]=="#":t+=1 if s[i-1][j]=="#":t+=1 if s[i-1][j+1]=="#":t+=1 elif j==w-1: if s[i+1][j]=="#":t+=1 if s[i+1][j-1]=="#":t+=1 if s[i][j-1]=="#":t+=1 if s[i-1][j-1]=="#":t+=1 if s[i-1][j]=="#":t+=1 elif i==h-1: if j==0: if s[i][j+1]=="#":t+=1 if s[i-1][j+1]=="#":t+=1 if s[i-1][j]=="#":t+=1 elif 0<j<w-1: if s[i][j+1]=="#":t+=1 if s[i-1][j+1]=="#":t+=1 if s[i-1][j]=="#":t+=1 if s[i-1][j-1]=="#":t+=1 if s[i][j-1]=="#":t+=1 elif j==w-1: if s[i-1][j]=="#":t+=1 if s[i-1][j-1]=="#":t+=1 if s[i][j-1]=="#":t+=1 if s[i][j]=="#": a[i][j]="#" else: a[i][j]=t for aa in a: tt="" for aaa in aa: tt+=str(aaa) print(tt)
74
110
2,060
2,745
# ABC075 B - Minesweeper H, W = list(map(int, input().split())) G = [["" for _ in range(W + 2)] for _ in range(H + 2)] Ans = [[0 for _ in range(W + 2)] for _ in range(H + 2)] for i in range(1, H + 1): S = eval(input()) for j, s in enumerate(S): G[i][j + 1] = s for i in range(1, H + 1): for j in range(W): # 1行目 if i == 1: if G[i][j + 2] == "#": Ans[i][j + 1] += 1 # if G[i][j+1] == '#': # Ans[i][j+1] = '#' if G[i][j] == "#": Ans[i][j + 1] += 1 if G[i + 1][j + 2] == "#": Ans[i][j + 1] += 1 if G[i + 1][j + 1] == "#": Ans[i][j + 1] += 1 if G[i + 1][j] == "#": Ans[i][j + 1] += 1 continue # 最終行 if i == H: if G[i][j + 2] == "#": Ans[i][j + 1] += 1 # if G[i][j+1] == '#': # Ans[i][j+1] = '#' if G[i][j] == "#": Ans[i][j + 1] += 1 if G[i - 1][j + 2] == "#": Ans[i][j + 1] += 1 if G[i - 1][j + 1] == "#": Ans[i][j + 1] += 1 if G[i - 1][j] == "#": Ans[i][j + 1] += 1 continue if G[i][j + 2] == "#": Ans[i][j + 1] += 1 # if G[i][j+1] == '#': # Ans[i][j+1] = '#' if G[i][j] == "#": Ans[i][j + 1] += 1 if G[i + 1][j + 2] == "#": Ans[i][j + 1] += 1 if G[i + 1][j + 1] == "#": Ans[i][j + 1] += 1 if G[i + 1][j] == "#": Ans[i][j + 1] += 1 if G[i - 1][j + 2] == "#": Ans[i][j + 1] += 1 if G[i - 1][j + 1] == "#": Ans[i][j + 1] += 1 if G[i - 1][j] == "#": Ans[i][j + 1] += 1 for i in range(1, H + 1): for j in range(1, W + 1): Ans[i][j] = str(Ans[i][j]) if G[i][j] == "#": Ans[i][j] = "#" for i in range(1, H + 1): s = "" for j in range(1, W + 1): s += Ans[i][j] print(s)
h, w = list(map(int, input().split())) s = [eval(input()) for i in range(h)] a = [[0] * w for i in range(h)] if h == 1 and w == 1: if s[0] == "#": print("#") else: print((0)) elif h == 1 and w > 1: for i in range(w): t = 0 if i == 0: if s[0][i + 1] == "#": t += 1 elif 0 < i < w - 1: if s[0][i + 1] == "#": t += 1 if s[0][i - 1] == "#": t += 1 elif i == w - 1: if s[0][i - 1] == "#": t += 1 if s[0][i] == "#": a[0][i] = "#" else: a[0][i] = t tt = "" for aa in a: for aaa in aa: tt += str(aaa) print((str(tt))) elif w == 1 and h > 1: for i in range(h): t = 0 if i == 0: if s[i + 1] == "#": t += 1 elif 0 < i < h - 1: if s[i + 1] == "#": t += 1 if s[i - 1] == "#": t += 1 elif i == h - 1: if s[i - 1] == "#": t += 1 if s[i] == "#": a[i][0] = "#" else: a[i][0] = t for aa in a: print((*aa)) elif w > 1 and h > 1: for i in range(h): for j in range(w): t = 0 if i == 0: if j == 0: if s[i][j + 1] == "#": t += 1 if s[i + 1][j + 1] == "#": t += 1 if s[i + 1][j] == "#": t += 1 elif 0 < j < w - 1: if s[i][j + 1] == "#": t += 1 if s[i + 1][j + 1] == "#": t += 1 if s[i + 1][j] == "#": t += 1 if s[i + 1][j - 1] == "#": t += 1 if s[i][j - 1] == "#": t += 1 elif j == w - 1: if s[i + 1][j] == "#": t += 1 if s[i + 1][j - 1] == "#": t += 1 if s[i][j - 1] == "#": t += 1 elif 0 < i < h - 1: if j == 0: if s[i - 1][j] == "#": t += 1 if s[i - 1][j + 1] == "#": t += 1 if s[i][j + 1] == "#": t += 1 if s[i + 1][j + 1] == "#": t += 1 if s[i + 1][j] == "#": t += 1 elif 0 < j < w - 1: if s[i][j + 1] == "#": t += 1 if s[i + 1][j + 1] == "#": t += 1 if s[i + 1][j] == "#": t += 1 if s[i + 1][j - 1] == "#": t += 1 if s[i][j - 1] == "#": t += 1 if s[i - 1][j - 1] == "#": t += 1 if s[i - 1][j] == "#": t += 1 if s[i - 1][j + 1] == "#": t += 1 elif j == w - 1: if s[i + 1][j] == "#": t += 1 if s[i + 1][j - 1] == "#": t += 1 if s[i][j - 1] == "#": t += 1 if s[i - 1][j - 1] == "#": t += 1 if s[i - 1][j] == "#": t += 1 elif i == h - 1: if j == 0: if s[i][j + 1] == "#": t += 1 if s[i - 1][j + 1] == "#": t += 1 if s[i - 1][j] == "#": t += 1 elif 0 < j < w - 1: if s[i][j + 1] == "#": t += 1 if s[i - 1][j + 1] == "#": t += 1 if s[i - 1][j] == "#": t += 1 if s[i - 1][j - 1] == "#": t += 1 if s[i][j - 1] == "#": t += 1 elif j == w - 1: if s[i - 1][j] == "#": t += 1 if s[i - 1][j - 1] == "#": t += 1 if s[i][j - 1] == "#": t += 1 if s[i][j] == "#": a[i][j] = "#" else: a[i][j] = t for aa in a: tt = "" for aaa in aa: tt += str(aaa) print(tt)
false
32.727273
[ "-# ABC075 B - Minesweeper", "-H, W = list(map(int, input().split()))", "-G = [[\"\" for _ in range(W + 2)] for _ in range(H + 2)]", "-Ans = [[0 for _ in range(W + 2)] for _ in range(H + 2)]", "-for i in range(1, H + 1):", "- S = eval(input())", "- for j, s in enumerate(S):", "- G[i][j + ...
false
0.037957
0.039056
0.971857
[ "s993208960", "s538471416" ]
u399721252
p02936
python
s875683328
s220537229
1,951
816
107,084
95,308
Accepted
Accepted
58.18
n, q = [ int(v) for v in input().split() ] value_list = [ 0 for i in range(n) ] connect_list = [ [] for i in range(n) ] for i in range(n-1): a, b = [ int(v)-1 for v in input().split() ] connect_list[a].append(b) connect_list[b].append(a) for i in range(q): c, p = [ int(v)-1 for v in input().split() ] value_list[c] += p + 1 serached_list = [ 0 for i in range(n) ] search_list= connect_list[0] serached_list[0] = 1 for i in connect_list[0]: value_list[i] += value_list[0] while search_list != []: new_search_list = [] for i in search_list: serached_list[i] = 1 for j in connect_list[i]: if serached_list[j] == 0: value_list[j] += value_list[i] new_search_list.append(j) search_list = new_search_list print((*value_list))
import sys input = sys.stdin.readline n, q = [ int(v) for v in input().split() ] value_list = [ 0 for i in range(n) ] connect_list = [ [] for i in range(n) ] for i in range(n-1): a, b = [ int(v)-1 for v in input().split() ] connect_list[a].append(b) connect_list[b].append(a) for i in range(q): c, p = [ int(v)-1 for v in input().split() ] value_list[c] += p + 1 serached_list = [ 0 for i in range(n) ] search_list= connect_list[0] serached_list[0] = 1 for i in connect_list[0]: value_list[i] += value_list[0] while search_list != []: new_search_list = [] for i in search_list: serached_list[i] = 1 for j in connect_list[i]: if serached_list[j] == 0: value_list[j] += value_list[i] new_search_list.append(j) search_list = new_search_list print((*value_list))
30
33
850
893
n, q = [int(v) for v in input().split()] value_list = [0 for i in range(n)] connect_list = [[] for i in range(n)] for i in range(n - 1): a, b = [int(v) - 1 for v in input().split()] connect_list[a].append(b) connect_list[b].append(a) for i in range(q): c, p = [int(v) - 1 for v in input().split()] value_list[c] += p + 1 serached_list = [0 for i in range(n)] search_list = connect_list[0] serached_list[0] = 1 for i in connect_list[0]: value_list[i] += value_list[0] while search_list != []: new_search_list = [] for i in search_list: serached_list[i] = 1 for j in connect_list[i]: if serached_list[j] == 0: value_list[j] += value_list[i] new_search_list.append(j) search_list = new_search_list print((*value_list))
import sys input = sys.stdin.readline n, q = [int(v) for v in input().split()] value_list = [0 for i in range(n)] connect_list = [[] for i in range(n)] for i in range(n - 1): a, b = [int(v) - 1 for v in input().split()] connect_list[a].append(b) connect_list[b].append(a) for i in range(q): c, p = [int(v) - 1 for v in input().split()] value_list[c] += p + 1 serached_list = [0 for i in range(n)] search_list = connect_list[0] serached_list[0] = 1 for i in connect_list[0]: value_list[i] += value_list[0] while search_list != []: new_search_list = [] for i in search_list: serached_list[i] = 1 for j in connect_list[i]: if serached_list[j] == 0: value_list[j] += value_list[i] new_search_list.append(j) search_list = new_search_list print((*value_list))
false
9.090909
[ "+import sys", "+", "+input = sys.stdin.readline" ]
false
0.037618
0.035919
1.047287
[ "s875683328", "s220537229" ]
u553987207
p02732
python
s507738609
s545859749
273
230
26,140
32,796
Accepted
Accepted
15.75
N = int(eval(input())) A = list(map(int, input().split())) c = [0] * (N + 1) for a in A: c[a] += 1 total = sum([n * (n - 1) // 2 for n in c]) for a in A: print((total - (c[a] - 1)))
N = int(eval(input())) A = tuple(map(int, input().split())) dupcount = [0] * (N + 1) for a in A: dupcount[a] += 1 allc = 0 for a in range(1, N + 1): c = dupcount[a] if c > 1: allc += (c * (c - 1) // 2) for a in A: ans = allc c = dupcount[a] if c > 0: ans -= (c - 1) print(ans)
8
19
188
335
N = int(eval(input())) A = list(map(int, input().split())) c = [0] * (N + 1) for a in A: c[a] += 1 total = sum([n * (n - 1) // 2 for n in c]) for a in A: print((total - (c[a] - 1)))
N = int(eval(input())) A = tuple(map(int, input().split())) dupcount = [0] * (N + 1) for a in A: dupcount[a] += 1 allc = 0 for a in range(1, N + 1): c = dupcount[a] if c > 1: allc += c * (c - 1) // 2 for a in A: ans = allc c = dupcount[a] if c > 0: ans -= c - 1 print(ans)
false
57.894737
[ "-A = list(map(int, input().split()))", "-c = [0] * (N + 1)", "+A = tuple(map(int, input().split()))", "+dupcount = [0] * (N + 1)", "- c[a] += 1", "-total = sum([n * (n - 1) // 2 for n in c])", "+ dupcount[a] += 1", "+allc = 0", "+for a in range(1, N + 1):", "+ c = dupcount[a]", "+ i...
false
0.106438
0.035494
2.998747
[ "s507738609", "s545859749" ]
u366959492
p03044
python
s556939054
s298090833
911
764
70,432
70,688
Accepted
Accepted
16.14
n=int(eval(input())) l=[[] for _ in range(n+1)] q=[(1,0)] ans=[-1]*n while n>1: u,v,w=list(map(int,input().split())) l[u]+=[(v,w)] l[v]+=[(u,w)] n-=1 while q: u,w=q.pop() ans[u-1]=w%2 for v,d in l[u]: q+=[(v,w+d)]*(ans[v-1]<0) print((*ans))
n=int(input()) l=[[] for _ in range(n)] for _ in range(n-1): u,v,w=map(int,input().split()) u-=1 v-=1 l[u].append((v,w)) l[v].append((u,w)) iro=[-1]*n iro[0]=1 from collections import deque q=deque() q.append(0) while q: v=q.popleft() for i,w in l[v]: if iro[i]!=-1: continue if w%2==0: iro[i]=iro[v] else: iro[i]=iro[v]^1 q.append(i) print(*iro,sep="\n")
15
26
277
479
n = int(eval(input())) l = [[] for _ in range(n + 1)] q = [(1, 0)] ans = [-1] * n while n > 1: u, v, w = list(map(int, input().split())) l[u] += [(v, w)] l[v] += [(u, w)] n -= 1 while q: u, w = q.pop() ans[u - 1] = w % 2 for v, d in l[u]: q += [(v, w + d)] * (ans[v - 1] < 0) print((*ans))
n = int(input()) l = [[] for _ in range(n)] for _ in range(n - 1): u, v, w = map(int, input().split()) u -= 1 v -= 1 l[u].append((v, w)) l[v].append((u, w)) iro = [-1] * n iro[0] = 1 from collections import deque q = deque() q.append(0) while q: v = q.popleft() for i, w in l[v]: if iro[i] != -1: continue if w % 2 == 0: iro[i] = iro[v] else: iro[i] = iro[v] ^ 1 q.append(i) print(*iro, sep="\n")
false
42.307692
[ "-n = int(eval(input()))", "-l = [[] for _ in range(n + 1)]", "-q = [(1, 0)]", "-ans = [-1] * n", "-while n > 1:", "- u, v, w = list(map(int, input().split()))", "- l[u] += [(v, w)]", "- l[v] += [(u, w)]", "- n -= 1", "+n = int(input())", "+l = [[] for _ in range(n)]", "+for _ in r...
false
0.045187
0.09254
0.488296
[ "s556939054", "s298090833" ]
u392319141
p03106
python
s267024063
s662961493
35
17
5,048
2,940
Accepted
Accepted
51.43
import fractions as fr A , B , K = list(map(int,input().split())) # A,B <= 100 k = 0 R = int(max(fr.gcd(A,B),1)) for i in range(R,0,-1) : if A % i == 0 and B % i == 0 : k += 1 if k >= K : print(i) break
A, B, K = list(map(int, input().split())) ans = [] for i in range(1, 1000): if A % i == 0 and B % i == 0: ans.append(i) ans.sort(reverse=True) print((ans[K - 1]))
15
9
260
177
import fractions as fr A, B, K = list(map(int, input().split())) # A,B <= 100 k = 0 R = int(max(fr.gcd(A, B), 1)) for i in range(R, 0, -1): if A % i == 0 and B % i == 0: k += 1 if k >= K: print(i) break
A, B, K = list(map(int, input().split())) ans = [] for i in range(1, 1000): if A % i == 0 and B % i == 0: ans.append(i) ans.sort(reverse=True) print((ans[K - 1]))
false
40
[ "-import fractions as fr", "-", "-A, B, K = list(map(int, input().split())) # A,B <= 100", "-k = 0", "-R = int(max(fr.gcd(A, B), 1))", "-for i in range(R, 0, -1):", "+A, B, K = list(map(int, input().split()))", "+ans = []", "+for i in range(1, 1000):", "- k += 1", "- if k >= K:", ...
false
0.046257
0.038634
1.1973
[ "s267024063", "s662961493" ]
u682672120
p02574
python
s801306850
s393997230
518
433
196,824
187,512
Accepted
Accepted
16.41
from collections import defaultdict def gcd(a, b): if a < b: return gcd(b, a) while b > 0: a, b = b, a % b return a def sieve_of_eratosthenes_max(n): sieve = [0] * (n+1) sieve[0] = 0 #素数でない sieve[1] = 1 #素数でない for i in range(2, n+1): if sieve[i] == 0: for j in range(1, n // i + 1): sieve[i * j] = i return sieve def factorize_by_sieve_of_eratosthenes(x, sieve): factor = defaultdict(int) while sieve[x] != x: factor[sieve[x]] += 1 x //= sieve[x] factor[x] += 1 return factor n = int(eval(input())) a_list = list(map(int, input().split())) a_list.sort() sieve = sieve_of_eratosthenes_max(a_list[-1]) pairwise = True setwise = True primes = set() x = a_list[0] for a in a_list: x = gcd(x, a) if pairwise and a != 1: factor = set(factorize_by_sieve_of_eratosthenes(a, sieve).keys()) if not primes.isdisjoint(factor): pairwise = False else: primes |= factor if pairwise: print("pairwise coprime") elif x == 1: print("setwise coprime") else: print("not coprime")
from collections import defaultdict import math def gcd(a, b): if a < b: return gcd(b, a) while b > 0: a, b = b, a % b return a def sieve_of_eratosthenes(n): sieve = list(range(n+1)) sieve[0] = 1 #素数でない sieve[1] = 1 #素数でない m = int(math.sqrt(n)) for i in range(2, m + 1): if sieve[i] < i: continue for j in range(i * i, n + 1, i): if sieve[j] == j: sieve[j] = i return sieve def factorize_by_sieve(x, sieve): factor = defaultdict(int) while sieve[x] != x: factor[sieve[x]] += 1 x //= sieve[x] factor[x] += 1 return factor n = int(eval(input())) a_list = list(map(int, input().split())) a_list.sort() sieve = sieve_of_eratosthenes(a_list[-1]) pairwise = True setwise = True primes = set() x = a_list[0] for a in a_list: x = gcd(x, a) if pairwise and a != 1: factor = set(factorize_by_sieve(a, sieve).keys()) if not primes.isdisjoint(factor): pairwise = False else: primes |= factor if pairwise: print("pairwise coprime") elif x == 1: print("setwise coprime") else: print("not coprime")
53
55
1,197
1,245
from collections import defaultdict def gcd(a, b): if a < b: return gcd(b, a) while b > 0: a, b = b, a % b return a def sieve_of_eratosthenes_max(n): sieve = [0] * (n + 1) sieve[0] = 0 # 素数でない sieve[1] = 1 # 素数でない for i in range(2, n + 1): if sieve[i] == 0: for j in range(1, n // i + 1): sieve[i * j] = i return sieve def factorize_by_sieve_of_eratosthenes(x, sieve): factor = defaultdict(int) while sieve[x] != x: factor[sieve[x]] += 1 x //= sieve[x] factor[x] += 1 return factor n = int(eval(input())) a_list = list(map(int, input().split())) a_list.sort() sieve = sieve_of_eratosthenes_max(a_list[-1]) pairwise = True setwise = True primes = set() x = a_list[0] for a in a_list: x = gcd(x, a) if pairwise and a != 1: factor = set(factorize_by_sieve_of_eratosthenes(a, sieve).keys()) if not primes.isdisjoint(factor): pairwise = False else: primes |= factor if pairwise: print("pairwise coprime") elif x == 1: print("setwise coprime") else: print("not coprime")
from collections import defaultdict import math def gcd(a, b): if a < b: return gcd(b, a) while b > 0: a, b = b, a % b return a def sieve_of_eratosthenes(n): sieve = list(range(n + 1)) sieve[0] = 1 # 素数でない sieve[1] = 1 # 素数でない m = int(math.sqrt(n)) for i in range(2, m + 1): if sieve[i] < i: continue for j in range(i * i, n + 1, i): if sieve[j] == j: sieve[j] = i return sieve def factorize_by_sieve(x, sieve): factor = defaultdict(int) while sieve[x] != x: factor[sieve[x]] += 1 x //= sieve[x] factor[x] += 1 return factor n = int(eval(input())) a_list = list(map(int, input().split())) a_list.sort() sieve = sieve_of_eratosthenes(a_list[-1]) pairwise = True setwise = True primes = set() x = a_list[0] for a in a_list: x = gcd(x, a) if pairwise and a != 1: factor = set(factorize_by_sieve(a, sieve).keys()) if not primes.isdisjoint(factor): pairwise = False else: primes |= factor if pairwise: print("pairwise coprime") elif x == 1: print("setwise coprime") else: print("not coprime")
false
3.636364
[ "+import math", "-def sieve_of_eratosthenes_max(n):", "- sieve = [0] * (n + 1)", "- sieve[0] = 0 # 素数でない", "+def sieve_of_eratosthenes(n):", "+ sieve = list(range(n + 1))", "+ sieve[0] = 1 # 素数でない", "- for i in range(2, n + 1):", "- if sieve[i] == 0:", "- for j i...
false
0.042116
0.038272
1.100428
[ "s801306850", "s393997230" ]
u259755734
p02765
python
s800339912
s389353809
78
23
61,608
9,096
Accepted
Accepted
70.51
n, r = list(map(int, input().split())) if n >= 10: print(r) else: print((r + 100*(10-n)))
import sys stdin = sys.stdin ni = lambda: int(ns()) ns = lambda: stdin.readline().rstrip() na = lambda: list(map(int, stdin.readline().split())) # code here N, R = na() if N >= 10: print(R) else: print((R + 100*(10-N)))
6
16
96
246
n, r = list(map(int, input().split())) if n >= 10: print(r) else: print((r + 100 * (10 - n)))
import sys stdin = sys.stdin ni = lambda: int(ns()) ns = lambda: stdin.readline().rstrip() na = lambda: list(map(int, stdin.readline().split())) # code here N, R = na() if N >= 10: print(R) else: print((R + 100 * (10 - N)))
false
62.5
[ "-n, r = list(map(int, input().split()))", "-if n >= 10:", "- print(r)", "+import sys", "+", "+stdin = sys.stdin", "+ni = lambda: int(ns())", "+ns = lambda: stdin.readline().rstrip()", "+na = lambda: list(map(int, stdin.readline().split()))", "+# code here", "+N, R = na()", "+if N >= 10:", ...
false
0.058666
0.054834
1.069886
[ "s800339912", "s389353809" ]
u761320129
p03488
python
s778645867
s661758647
1,265
1,050
3,816
3,820
Accepted
Accepted
17
S = eval(input()) x,y = list(map(int,input().split())) if 'T' not in S: print(('Yes' if x==len(S) and y==0 else 'No')) exit() sp = S.split('T') x -= len(sp[0]) v_moves = [] h_moves = [] for i,s in enumerate(sp[1:]): if not s: continue if i%2==0: v_moves.append(len(s)) else: h_moves.append(len(s)) if not h_moves: if x != 0: print('No') exit() else: hs = set([0]) for h in h_moves: tmp = set() for h2 in hs: tmp.add(h2 + h) tmp.add(h2 - h) hs = tmp if x not in hs: print('No') exit() if not v_moves: if y != 0: print('No') exit() else: vs = set([0]) for v in v_moves: tmp = set() for v2 in vs: tmp.add(v2 + v) tmp.add(v2 - v) vs = tmp if y not in vs: print('No') exit() print('Yes')
S = eval(input()) X,Y = list(map(int,input().split())) st = S.split('T') X -= len(st[0]) xds = [] yds = [] for i,s in enumerate(st[1:]): if i%2: xds.append(len(s)) else: yds.append(len(s)) def ok(to, ds): dp = set([0]) for d in ds: tmp = [] for v in dp: tmp.append(v+d) tmp.append(v-d) dp = set(tmp) return to in dp print(('Yes' if ok(X,xds) and ok(Y,yds) else 'No'))
52
25
954
465
S = eval(input()) x, y = list(map(int, input().split())) if "T" not in S: print(("Yes" if x == len(S) and y == 0 else "No")) exit() sp = S.split("T") x -= len(sp[0]) v_moves = [] h_moves = [] for i, s in enumerate(sp[1:]): if not s: continue if i % 2 == 0: v_moves.append(len(s)) else: h_moves.append(len(s)) if not h_moves: if x != 0: print("No") exit() else: hs = set([0]) for h in h_moves: tmp = set() for h2 in hs: tmp.add(h2 + h) tmp.add(h2 - h) hs = tmp if x not in hs: print("No") exit() if not v_moves: if y != 0: print("No") exit() else: vs = set([0]) for v in v_moves: tmp = set() for v2 in vs: tmp.add(v2 + v) tmp.add(v2 - v) vs = tmp if y not in vs: print("No") exit() print("Yes")
S = eval(input()) X, Y = list(map(int, input().split())) st = S.split("T") X -= len(st[0]) xds = [] yds = [] for i, s in enumerate(st[1:]): if i % 2: xds.append(len(s)) else: yds.append(len(s)) def ok(to, ds): dp = set([0]) for d in ds: tmp = [] for v in dp: tmp.append(v + d) tmp.append(v - d) dp = set(tmp) return to in dp print(("Yes" if ok(X, xds) and ok(Y, yds) else "No"))
false
51.923077
[ "-x, y = list(map(int, input().split()))", "-if \"T\" not in S:", "- print((\"Yes\" if x == len(S) and y == 0 else \"No\"))", "- exit()", "-sp = S.split(\"T\")", "-x -= len(sp[0])", "-v_moves = []", "-h_moves = []", "-for i, s in enumerate(sp[1:]):", "- if not s:", "- continue", ...
false
0.043352
0.042895
1.010645
[ "s778645867", "s661758647" ]
u312025627
p03494
python
s585779020
s924848474
177
18
39,024
3,060
Accepted
Accepted
89.83
n = int(eval(input())) a = {int(i) for i in input().split()} ans = 0 while not any(i&1 for i in a): ans += 1 a = {i//2 for i in a} print(ans)
n = int(eval(input())) a = [int(i) for i in input().split()] ans = 0 while not any(i&1 for i in a): ans += 1 a = [i//2 for i in a] print(ans)
8
8
151
151
n = int(eval(input())) a = {int(i) for i in input().split()} ans = 0 while not any(i & 1 for i in a): ans += 1 a = {i // 2 for i in a} print(ans)
n = int(eval(input())) a = [int(i) for i in input().split()] ans = 0 while not any(i & 1 for i in a): ans += 1 a = [i // 2 for i in a] print(ans)
false
0
[ "-a = {int(i) for i in input().split()}", "+a = [int(i) for i in input().split()]", "- a = {i // 2 for i in a}", "+ a = [i // 2 for i in a]" ]
false
0.043501
0.03601
1.208012
[ "s585779020", "s924848474" ]
u414980766
p02861
python
s459910353
s770175100
1,310
567
12,388
12,388
Accepted
Accepted
56.72
from itertools import permutations as perm import sys import math import numpy as np read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N = int(readline()) XY = np.array(read().split(), np.int64) X = XY[0::2] Y = XY[1::2] res = 0 cnt = 0 for p in perm(list(range(N))): for i in range(N - 1): res += math.sqrt((X[p[i + 1]] - X[p[i]])**2 + (Y[p[i + 1]] - Y[p[i]])**2) cnt += 1 print((res/cnt))
from itertools import permutations as perm import sys import numpy as np read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N = int(readline()) XY = list(map(int, read().split())) X = XY[0::2] Y = XY[1::2] res = 0 cnt = 0 for p in perm(list(range(N))): for i in range(N - 1): res += ((X[p[i + 1]] - X[p[i]])**2 + (Y[p[i + 1]] - Y[p[i]])**2)**0.5 cnt += 1 print((res/cnt))
19
18
476
455
from itertools import permutations as perm import sys import math import numpy as np read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N = int(readline()) XY = np.array(read().split(), np.int64) X = XY[0::2] Y = XY[1::2] res = 0 cnt = 0 for p in perm(list(range(N))): for i in range(N - 1): res += math.sqrt((X[p[i + 1]] - X[p[i]]) ** 2 + (Y[p[i + 1]] - Y[p[i]]) ** 2) cnt += 1 print((res / cnt))
from itertools import permutations as perm import sys import numpy as np read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N = int(readline()) XY = list(map(int, read().split())) X = XY[0::2] Y = XY[1::2] res = 0 cnt = 0 for p in perm(list(range(N))): for i in range(N - 1): res += ((X[p[i + 1]] - X[p[i]]) ** 2 + (Y[p[i + 1]] - Y[p[i]]) ** 2) ** 0.5 cnt += 1 print((res / cnt))
false
5.263158
[ "-import math", "-XY = np.array(read().split(), np.int64)", "+XY = list(map(int, read().split()))", "- res += math.sqrt((X[p[i + 1]] - X[p[i]]) ** 2 + (Y[p[i + 1]] - Y[p[i]]) ** 2)", "+ res += ((X[p[i + 1]] - X[p[i]]) ** 2 + (Y[p[i + 1]] - Y[p[i]]) ** 2) ** 0.5" ]
false
0.362667
0.11371
3.189412
[ "s459910353", "s770175100" ]
u077291787
p03994
python
s788943821
s288410782
49
43
5,532
4,980
Accepted
Accepted
12.24
# code-festival-2016-qualaC - 次のアルファベット / Next Letter from string import ascii_lowercase as abc def main(): S = input().rstrip() K = int(eval(input())) # dist[c] := distance to "a" through "z" dist = {c: 26 - i for i, c in enumerate(abc)} dist["a"] = 0 A = [dist[i] for i in S] ans = "" for i, s in zip(A[:-1], S[:-1]): if 0 < i <= K: # change s to "a" if possible ans += "a" K -= i else: ans += s # use the remaining K on A[-1] and combine with ans ans += chr((ord(S[-1]) + K - ord("a")) % 26 + ord("a")) print(ans) if __name__ == "__main__": main()
# code-festival-2016-qualaC - 次のアルファベット / Next Letter def main(): S = input().rstrip() K = int(eval(input())) abc = "abcdefghijklmnopqrstuvwxyz" # dist[c] := distance to "a" through "z" dist = {c: 26 - i for i, c in enumerate(abc)} dist["a"] = 0 A = [dist[i] for i in S] ans = "" for i, s in zip(A[:-1], S[:-1]): if 0 < i <= K: # change s to "a" if possible ans += "a" K -= i else: ans += s # use the remaining K on A[-1] and combine with ans ans += chr((ord(S[-1]) + K - ord("a")) % 26 + ord("a")) print(ans) if __name__ == "__main__": main()
25
23
673
666
# code-festival-2016-qualaC - 次のアルファベット / Next Letter from string import ascii_lowercase as abc def main(): S = input().rstrip() K = int(eval(input())) # dist[c] := distance to "a" through "z" dist = {c: 26 - i for i, c in enumerate(abc)} dist["a"] = 0 A = [dist[i] for i in S] ans = "" for i, s in zip(A[:-1], S[:-1]): if 0 < i <= K: # change s to "a" if possible ans += "a" K -= i else: ans += s # use the remaining K on A[-1] and combine with ans ans += chr((ord(S[-1]) + K - ord("a")) % 26 + ord("a")) print(ans) if __name__ == "__main__": main()
# code-festival-2016-qualaC - 次のアルファベット / Next Letter def main(): S = input().rstrip() K = int(eval(input())) abc = "abcdefghijklmnopqrstuvwxyz" # dist[c] := distance to "a" through "z" dist = {c: 26 - i for i, c in enumerate(abc)} dist["a"] = 0 A = [dist[i] for i in S] ans = "" for i, s in zip(A[:-1], S[:-1]): if 0 < i <= K: # change s to "a" if possible ans += "a" K -= i else: ans += s # use the remaining K on A[-1] and combine with ans ans += chr((ord(S[-1]) + K - ord("a")) % 26 + ord("a")) print(ans) if __name__ == "__main__": main()
false
8
[ "-from string import ascii_lowercase as abc", "-", "-", "+ abc = \"abcdefghijklmnopqrstuvwxyz\"" ]
false
0.007625
0.094316
0.08085
[ "s788943821", "s288410782" ]
u813102292
p03031
python
s466158928
s601763540
41
27
3,064
3,064
Accepted
Accepted
34.15
n, m = list(map(int, input().split())) s = [] for i in range(m): inputs = list(map(int, input().split())) k = inputs[0] s.append(inputs[1:]) p = list(map(int, input().split())) res = 0 for i in range(2 ** n): flag = True bit_i = bin(i)[2:].zfill(n) for j in range(m): sum_s = 0 for idx in s[j]: sum_s += int(bit_i[idx-1]) if sum_s % 2 != p[j]: flag = False break if flag: res += 1 print(res)
N, M = list(map(int, input().split())) S = [] for _ in range(M): ks = list(map(int, input().split())) S.append(ks[1:]) P = list(map(int, input().split())) ans = 0 for i in range(2**N): bi = str(bin(i))[2:] bi = bi.zfill(N) isAddable = True for j in range(M): s_sum = 0 for s in S[j]: if bi[s-1] == '1': s_sum += 1 if s_sum % 2 != P[j]: isAddable = False break if isAddable: ans += 1 print(ans)
24
23
507
522
n, m = list(map(int, input().split())) s = [] for i in range(m): inputs = list(map(int, input().split())) k = inputs[0] s.append(inputs[1:]) p = list(map(int, input().split())) res = 0 for i in range(2**n): flag = True bit_i = bin(i)[2:].zfill(n) for j in range(m): sum_s = 0 for idx in s[j]: sum_s += int(bit_i[idx - 1]) if sum_s % 2 != p[j]: flag = False break if flag: res += 1 print(res)
N, M = list(map(int, input().split())) S = [] for _ in range(M): ks = list(map(int, input().split())) S.append(ks[1:]) P = list(map(int, input().split())) ans = 0 for i in range(2**N): bi = str(bin(i))[2:] bi = bi.zfill(N) isAddable = True for j in range(M): s_sum = 0 for s in S[j]: if bi[s - 1] == "1": s_sum += 1 if s_sum % 2 != P[j]: isAddable = False break if isAddable: ans += 1 print(ans)
false
4.166667
[ "-n, m = list(map(int, input().split()))", "-s = []", "-for i in range(m):", "- inputs = list(map(int, input().split()))", "- k = inputs[0]", "- s.append(inputs[1:])", "-p = list(map(int, input().split()))", "-res = 0", "-for i in range(2**n):", "- flag = True", "- bit_i = bin(i)[...
false
0.056822
0.03503
1.622086
[ "s466158928", "s601763540" ]
u057109575
p02900
python
s602945522
s595628072
185
76
38,512
62,848
Accepted
Accepted
58.92
A, B = list(map(int, input().split())) def prime_factor(n): d = set() for i in range(2, n + 1): if i * i > n: break while n % i == 0: d.add(i) n //= i if n != 1: d.add(n) return d a = prime_factor(A) b = prime_factor(B) print((len(set(a) & set(b)) + 1))
A, B = list(map(int, input().split())) def prime_factor(n): res = set([1]) for i in range(2, n + 1): if i * i > n: break while n % i == 0: res.add(i) n //= i if n != 1: res.add(n) return res print((len(prime_factor(A) & prime_factor(B))))
19
18
356
361
A, B = list(map(int, input().split())) def prime_factor(n): d = set() for i in range(2, n + 1): if i * i > n: break while n % i == 0: d.add(i) n //= i if n != 1: d.add(n) return d a = prime_factor(A) b = prime_factor(B) print((len(set(a) & set(b)) + 1))
A, B = list(map(int, input().split())) def prime_factor(n): res = set([1]) for i in range(2, n + 1): if i * i > n: break while n % i == 0: res.add(i) n //= i if n != 1: res.add(n) return res print((len(prime_factor(A) & prime_factor(B))))
false
5.263158
[ "- d = set()", "+ res = set([1])", "- d.add(i)", "+ res.add(i)", "- d.add(n)", "- return d", "+ res.add(n)", "+ return res", "-a = prime_factor(A)", "-b = prime_factor(B)", "-print((len(set(a) & set(b)) + 1))", "+print((len(prime_factor(A) & prim...
false
0.041918
0.077515
0.540773
[ "s602945522", "s595628072" ]
u459639226
p03137
python
s499298863
s160349993
131
114
13,960
13,968
Accepted
Accepted
12.98
N, M = list(map(int, input().split())) X = sorted(list(map(int, input().split()))) if M <= N: print((0)) else: Y = [] for i in range(1, len(X)): Y.append(X[i] - X[i-1]) Y = sorted(Y) if N == 1: print((sum(Y))) else: print((sum(Y[:-(N-1)])))
N, M = list(map(int, input().split())) X = list(map(int, input().split())) X.sort() t = [0] * (M - 1) for i in range(1, M): t[i - 1] = X[i] - X[i - 1] t.sort(reverse=True) print((sum(t[N - 1:])))
13
8
289
199
N, M = list(map(int, input().split())) X = sorted(list(map(int, input().split()))) if M <= N: print((0)) else: Y = [] for i in range(1, len(X)): Y.append(X[i] - X[i - 1]) Y = sorted(Y) if N == 1: print((sum(Y))) else: print((sum(Y[: -(N - 1)])))
N, M = list(map(int, input().split())) X = list(map(int, input().split())) X.sort() t = [0] * (M - 1) for i in range(1, M): t[i - 1] = X[i] - X[i - 1] t.sort(reverse=True) print((sum(t[N - 1 :])))
false
38.461538
[ "-X = sorted(list(map(int, input().split())))", "-if M <= N:", "- print((0))", "-else:", "- Y = []", "- for i in range(1, len(X)):", "- Y.append(X[i] - X[i - 1])", "- Y = sorted(Y)", "- if N == 1:", "- print((sum(Y)))", "- else:", "- print((sum(Y[: -(N - ...
false
0.068976
0.042653
1.617154
[ "s499298863", "s160349993" ]
u727051308
p02576
python
s352219319
s361913894
32
25
9,084
8,932
Accepted
Accepted
21.88
N, X, T = list(map(int,input().split())) if N % X == 0: print(( T*N // X )) else: print(( T*(N // X + 1)))
N, X, T = list(map(int,input().split())) if N % X == 0: print(((N//X)*T)) else: print(((N//X+1)*T))
6
5
107
97
N, X, T = list(map(int, input().split())) if N % X == 0: print((T * N // X)) else: print((T * (N // X + 1)))
N, X, T = list(map(int, input().split())) if N % X == 0: print(((N // X) * T)) else: print(((N // X + 1) * T))
false
16.666667
[ "- print((T * N // X))", "+ print(((N // X) * T))", "- print((T * (N // X + 1)))", "+ print(((N // X + 1) * T))" ]
false
0.040537
0.044877
0.903292
[ "s352219319", "s361913894" ]
u608088992
p03449
python
s110294272
s653140383
22
18
3,316
3,064
Accepted
Accepted
18.18
import sys from collections import deque def solve(): input = sys.stdin.readline N = int(eval(input())) A = [[int(a) for a in input().split()] for _ in range(2)] M = ((1, 0), (0, 1)) q = deque() q.append((0, 0, 0)) C = [[0] * N for _ in range(2)] while q: i, j, n = q.popleft() if n + A[i][j] > C[i][j]: C[i][j] = n + A[i][j] for di, dj in M: if 0 <= i + di < 2 and 0 <= j + dj < N: q.append((i + di, j + dj, C[i][j])) print((C[1][N-1])) return 0 if __name__ == "__main__": solve()
import sys def solve(): input = sys.stdin.readline N = int(eval(input())) A = [[int(a) for a in input().split()] for _ in range(2)] first = [0] * N second = [0] * N first[0] = A[0][0] second[N-1] = A[1][N-1] for i in range(1, N): first[i] = first[i-1] + A[0][i] second[N - 1- i] = second[N - i] + A[1][N - 1- i] maxPoint = 0 for i in range(N): maxPoint = max(maxPoint, first[i] + second[i]) print(maxPoint) return 0 if __name__ == "__main__": solve()
25
23
621
550
import sys from collections import deque def solve(): input = sys.stdin.readline N = int(eval(input())) A = [[int(a) for a in input().split()] for _ in range(2)] M = ((1, 0), (0, 1)) q = deque() q.append((0, 0, 0)) C = [[0] * N for _ in range(2)] while q: i, j, n = q.popleft() if n + A[i][j] > C[i][j]: C[i][j] = n + A[i][j] for di, dj in M: if 0 <= i + di < 2 and 0 <= j + dj < N: q.append((i + di, j + dj, C[i][j])) print((C[1][N - 1])) return 0 if __name__ == "__main__": solve()
import sys def solve(): input = sys.stdin.readline N = int(eval(input())) A = [[int(a) for a in input().split()] for _ in range(2)] first = [0] * N second = [0] * N first[0] = A[0][0] second[N - 1] = A[1][N - 1] for i in range(1, N): first[i] = first[i - 1] + A[0][i] second[N - 1 - i] = second[N - i] + A[1][N - 1 - i] maxPoint = 0 for i in range(N): maxPoint = max(maxPoint, first[i] + second[i]) print(maxPoint) return 0 if __name__ == "__main__": solve()
false
8
[ "-from collections import deque", "- M = ((1, 0), (0, 1))", "- q = deque()", "- q.append((0, 0, 0))", "- C = [[0] * N for _ in range(2)]", "- while q:", "- i, j, n = q.popleft()", "- if n + A[i][j] > C[i][j]:", "- C[i][j] = n + A[i][j]", "- for di...
false
0.036991
0.034968
1.057849
[ "s110294272", "s653140383" ]
u279266699
p02837
python
s512940509
s181985179
388
261
3,064
8,900
Accepted
Accepted
32.73
n = int(eval(input())) l = [] A = [] for i in range(n): a = int(eval(input())) A += [a] l_1 = [] for j in range(a): l_1 += [list(map(int, input().split()))] l += [l_1] ans = 0 for i in range(1 << n): honest = [] liar = [] for j in range(n): if ((i >> j) & 1): if j + 1 in liar: break elif j + 1 not in honest: honest += [j + 1] sugg = l[j] for k in sugg: if k[1] == 1: if k[0] in liar: break elif k[0] not in honest: honest += [k[0]] else: if k[0] in honest: break elif k[0] not in liar: liar += [k[0]] else: continue break else: if j + 1 in honest: break elif j + 1 not in liar: liar += [j + 1] else: if ans < len(honest): ans = len(honest) print(ans)
n = int(eval(input())) num_of_sug = [] sug = [] for i in range(n): m = int(eval(input())) num_of_sug += [m] sug += [[tuple(map(int, input().split())) for _ in range(m)]] ans = 0 for i in range(2 ** n): liar = [] honest = [] for j in range(n): if ((i >> j) & 1): if j + 1 in liar: break elif j + 1 not in honest: honest += [j + 1] sug_tmp = sug[j] for sug_ in sug_tmp: if sug_[1] == 1: if sug_[0] in liar: break elif sug_[0] not in honest: honest += [sug_[0]] else: if sug_[0] in honest: break elif sug_[0] not in liar: liar += [sug_[0]] else: continue break else: if j + 1 in honest: break elif j + 1 not in liar: liar += [j + 1] else: if ans < len(honest): ans = len(honest) print(ans)
49
44
1,158
1,169
n = int(eval(input())) l = [] A = [] for i in range(n): a = int(eval(input())) A += [a] l_1 = [] for j in range(a): l_1 += [list(map(int, input().split()))] l += [l_1] ans = 0 for i in range(1 << n): honest = [] liar = [] for j in range(n): if (i >> j) & 1: if j + 1 in liar: break elif j + 1 not in honest: honest += [j + 1] sugg = l[j] for k in sugg: if k[1] == 1: if k[0] in liar: break elif k[0] not in honest: honest += [k[0]] else: if k[0] in honest: break elif k[0] not in liar: liar += [k[0]] else: continue break else: if j + 1 in honest: break elif j + 1 not in liar: liar += [j + 1] else: if ans < len(honest): ans = len(honest) print(ans)
n = int(eval(input())) num_of_sug = [] sug = [] for i in range(n): m = int(eval(input())) num_of_sug += [m] sug += [[tuple(map(int, input().split())) for _ in range(m)]] ans = 0 for i in range(2**n): liar = [] honest = [] for j in range(n): if (i >> j) & 1: if j + 1 in liar: break elif j + 1 not in honest: honest += [j + 1] sug_tmp = sug[j] for sug_ in sug_tmp: if sug_[1] == 1: if sug_[0] in liar: break elif sug_[0] not in honest: honest += [sug_[0]] else: if sug_[0] in honest: break elif sug_[0] not in liar: liar += [sug_[0]] else: continue break else: if j + 1 in honest: break elif j + 1 not in liar: liar += [j + 1] else: if ans < len(honest): ans = len(honest) print(ans)
false
10.204082
[ "-l = []", "-A = []", "+num_of_sug = []", "+sug = []", "- a = int(eval(input()))", "- A += [a]", "- l_1 = []", "- for j in range(a):", "- l_1 += [list(map(int, input().split()))]", "- l += [l_1]", "+ m = int(eval(input()))", "+ num_of_sug += [m]", "+ sug += [[t...
false
0.095863
0.036618
2.617935
[ "s512940509", "s181985179" ]
u655834330
p03127
python
s566001117
s073425573
380
316
23,132
27,532
Accepted
Accepted
16.84
import numpy as np def submit(): n = int(eval(input())) alist = list(map(int, input().split())) while True: curr_idx = np.argmin(alist) curr_min = alist[curr_idx] surplus_sum = 0 for i in range(len(alist)): if i == curr_idx: continue alist[i] %= curr_min surplus_sum += alist[i] if surplus_sum == 0: print(curr_min) break alist = [a for a in alist if a] if __name__ == "__main__": submit()
import numpy as np def gcd(a, b): if b == 0: return a return gcd(b, a % b) def submit(): n = int(eval(input())) alist = list(map(int, input().split())) g = alist[0] for a in alist[1:]: g = gcd(g, a) print(g) if __name__ == "__main__": submit()
28
23
563
320
import numpy as np def submit(): n = int(eval(input())) alist = list(map(int, input().split())) while True: curr_idx = np.argmin(alist) curr_min = alist[curr_idx] surplus_sum = 0 for i in range(len(alist)): if i == curr_idx: continue alist[i] %= curr_min surplus_sum += alist[i] if surplus_sum == 0: print(curr_min) break alist = [a for a in alist if a] if __name__ == "__main__": submit()
import numpy as np def gcd(a, b): if b == 0: return a return gcd(b, a % b) def submit(): n = int(eval(input())) alist = list(map(int, input().split())) g = alist[0] for a in alist[1:]: g = gcd(g, a) print(g) if __name__ == "__main__": submit()
false
17.857143
[ "+", "+", "+def gcd(a, b):", "+ if b == 0:", "+ return a", "+ return gcd(b, a % b)", "- while True:", "- curr_idx = np.argmin(alist)", "- curr_min = alist[curr_idx]", "- surplus_sum = 0", "- for i in range(len(alist)):", "- if i == curr_id...
false
0.164167
0.062008
2.647496
[ "s566001117", "s073425573" ]
u185896732
p03361
python
s278969073
s835178163
23
18
3,064
3,064
Accepted
Accepted
21.74
#import pysnooper #import os,re,sys,operator,math,heapq,string #from collections import Counter,deque #from operator import itemgetter #from itertools import accumulate,combinations,groupby,combinations_with_replacement,permutations from sys import stdin,setrecursionlimit #from copy import deepcopy setrecursionlimit(10**6) input=stdin.readline h,w=list(map(int,input().split())) s=[list(input().rstrip()) for _ in range(h)] mas=[["."]*w for _ in range(h)] for i in range(h): for j in range(w): if j+1<w and (s[i][j],s[i][j+1])==("#","#"): mas[i][j],mas[i][j+1]="#","#" if j-1>=0 and (s[i][j],s[i][j-1])==("#","#"): mas[i][j],mas[i][j-1]="#","#" if i+1<h and (s[i][j],s[i+1][j])==("#","#"): mas[i][j],mas[i+1][j]="#","#" if i-1>=0 and (s[i][j],s[i-1][j])==("#","#"): mas[i-1][j],mas[i][j]="#","#" print(("Yes" if mas==s else "No"))
h,w=list(map(int,input().split())) s=[list(eval(input())) for _ in range(h)] #print(s) for i in range(h): for j in range(w): #print(i,j) if s[i][j]=="#": if i!=0: if s[i-1][j]=="#": continue if i!=h-1: if s[i+1][j]=="#": continue if j!=0: if s[i][j-1]=="#": continue if j!=w-1: if s[i][j+1]=="#": continue print("No") exit() print("Yes")
25
22
934
582
# import pysnooper # import os,re,sys,operator,math,heapq,string # from collections import Counter,deque # from operator import itemgetter # from itertools import accumulate,combinations,groupby,combinations_with_replacement,permutations from sys import stdin, setrecursionlimit # from copy import deepcopy setrecursionlimit(10**6) input = stdin.readline h, w = list(map(int, input().split())) s = [list(input().rstrip()) for _ in range(h)] mas = [["."] * w for _ in range(h)] for i in range(h): for j in range(w): if j + 1 < w and (s[i][j], s[i][j + 1]) == ("#", "#"): mas[i][j], mas[i][j + 1] = "#", "#" if j - 1 >= 0 and (s[i][j], s[i][j - 1]) == ("#", "#"): mas[i][j], mas[i][j - 1] = "#", "#" if i + 1 < h and (s[i][j], s[i + 1][j]) == ("#", "#"): mas[i][j], mas[i + 1][j] = "#", "#" if i - 1 >= 0 and (s[i][j], s[i - 1][j]) == ("#", "#"): mas[i - 1][j], mas[i][j] = "#", "#" print(("Yes" if mas == s else "No"))
h, w = list(map(int, input().split())) s = [list(eval(input())) for _ in range(h)] # print(s) for i in range(h): for j in range(w): # print(i,j) if s[i][j] == "#": if i != 0: if s[i - 1][j] == "#": continue if i != h - 1: if s[i + 1][j] == "#": continue if j != 0: if s[i][j - 1] == "#": continue if j != w - 1: if s[i][j + 1] == "#": continue print("No") exit() print("Yes")
false
12
[ "-# import pysnooper", "-# import os,re,sys,operator,math,heapq,string", "-# from collections import Counter,deque", "-# from operator import itemgetter", "-# from itertools import accumulate,combinations,groupby,combinations_with_replacement,permutations", "-from sys import stdin, setrecursionlimit", "...
false
0.036216
0.036049
1.004618
[ "s278969073", "s835178163" ]
u078349616
p03524
python
s631112300
s914330673
38
18
3,444
3,188
Accepted
Accepted
52.63
from collections import defaultdict S = eval(input()) d = defaultdict(int) for i in range(len(S)): d[S[i]] += 1 ma = max(d["a"], d["b"], d["c"]) mi = min(d["a"], d["b"], d["c"]) if ma-mi > 1: print("NO") else: print("YES")
S = eval(input()) l = [] l.append(S.count("a")) l.append(S.count("b")) l.append(S.count("c")) if max(l) - min(l) > 1: print("NO") else: print("YES")
15
9
240
154
from collections import defaultdict S = eval(input()) d = defaultdict(int) for i in range(len(S)): d[S[i]] += 1 ma = max(d["a"], d["b"], d["c"]) mi = min(d["a"], d["b"], d["c"]) if ma - mi > 1: print("NO") else: print("YES")
S = eval(input()) l = [] l.append(S.count("a")) l.append(S.count("b")) l.append(S.count("c")) if max(l) - min(l) > 1: print("NO") else: print("YES")
false
40
[ "-from collections import defaultdict", "-", "-d = defaultdict(int)", "-for i in range(len(S)):", "- d[S[i]] += 1", "-ma = max(d[\"a\"], d[\"b\"], d[\"c\"])", "-mi = min(d[\"a\"], d[\"b\"], d[\"c\"])", "-if ma - mi > 1:", "+l = []", "+l.append(S.count(\"a\"))", "+l.append(S.count(\"b\"))", ...
false
0.156033
0.007809
19.979954
[ "s631112300", "s914330673" ]
u231848612
p03061
python
s344365714
s066264191
215
198
14,052
14,440
Accepted
Accepted
7.91
def GCD(a, b): """ Euclidean algorithm""" if a < b: (a, b) = (b, a) if b == 0: return a m = a % b while m != 0: a = b b = m m = a % b return b N = int(input()) A = [ int(v) for v in input().split() ] if N < 2 and 1e5 < N: raise() for v in A: if v < 1 and v < 1e9: raise() l_list = [] l = 0 for i in range(0, N): l = GCD(l, A[i]) l_list.append( l ) r_list = [] r = 0 for i in range(-1, -(N+1), -1): r = GCD(r, A[i]) r_list.append( r ) n = [] for i in range(0, N): if i-1 < 0: l = 0 else: l = l_list[i-1] if N-i-2 < 0: r = 0 else: r = r_list[N-i-2] n.append(GCD(l, r)) print(max(n))
def GCD(a, b): """ Euclidean algorithm""" if a < b: (a, b) = (b, a) if b == 0: return a m = a % b while m != 0: a = b b = m m = a % b return b N = int(input()) A = [ int(v) for v in input().split() ] AR = list(reversed(A)) if N < 2 and 1e5 < N: raise() for v in A: if v < 1 and v < 1e9: raise() l_list = [0] for i in range(0, N): l = GCD(l_list[i], A[i]) l_list.append( l ) r_list = [0] for i in range(0, N): r = GCD(r_list[i], AR[i]) r_list.append( r ) n = [] j = -2 for i in range(0, N): l = l_list[i] r = r_list[j] n.append(GCD(l, r)) j -= 1 print(max(n))
43
37
752
686
def GCD(a, b): """Euclidean algorithm""" if a < b: (a, b) = (b, a) if b == 0: return a m = a % b while m != 0: a = b b = m m = a % b return b N = int(input()) A = [int(v) for v in input().split()] if N < 2 and 1e5 < N: raise () for v in A: if v < 1 and v < 1e9: raise () l_list = [] l = 0 for i in range(0, N): l = GCD(l, A[i]) l_list.append(l) r_list = [] r = 0 for i in range(-1, -(N + 1), -1): r = GCD(r, A[i]) r_list.append(r) n = [] for i in range(0, N): if i - 1 < 0: l = 0 else: l = l_list[i - 1] if N - i - 2 < 0: r = 0 else: r = r_list[N - i - 2] n.append(GCD(l, r)) print(max(n))
def GCD(a, b): """Euclidean algorithm""" if a < b: (a, b) = (b, a) if b == 0: return a m = a % b while m != 0: a = b b = m m = a % b return b N = int(input()) A = [int(v) for v in input().split()] AR = list(reversed(A)) if N < 2 and 1e5 < N: raise () for v in A: if v < 1 and v < 1e9: raise () l_list = [0] for i in range(0, N): l = GCD(l_list[i], A[i]) l_list.append(l) r_list = [0] for i in range(0, N): r = GCD(r_list[i], AR[i]) r_list.append(r) n = [] j = -2 for i in range(0, N): l = l_list[i] r = r_list[j] n.append(GCD(l, r)) j -= 1 print(max(n))
false
13.953488
[ "+AR = list(reversed(A))", "-l_list = []", "-l = 0", "+l_list = [0]", "- l = GCD(l, A[i])", "+ l = GCD(l_list[i], A[i])", "-r_list = []", "-r = 0", "-for i in range(-1, -(N + 1), -1):", "- r = GCD(r, A[i])", "+r_list = [0]", "+for i in range(0, N):", "+ r = GCD(r_list[i], AR[i])"...
false
0.060012
0.037876
1.584429
[ "s344365714", "s066264191" ]
u133936772
p02642
python
s601869809
s457327089
725
415
33,292
33,016
Accepted
Accepted
42.76
M=10**6+1 _,*l=list(map(int,open(0).read().split())) a=[0]*M for i in l: if a[i]<2: for j in range(i,M,i): a[j]+=2 a[i]-=1 print((a.count(1)))
M=10**6+1 _,*l=list(map(int,open(0).read().split())) a=[0]*M for i in l: if a[i]<1: for j in range(i*2,M,i): a[j]=2 a[i]+=1 print((a.count(1)))
8
8
151
150
M = 10**6 + 1 _, *l = list(map(int, open(0).read().split())) a = [0] * M for i in l: if a[i] < 2: for j in range(i, M, i): a[j] += 2 a[i] -= 1 print((a.count(1)))
M = 10**6 + 1 _, *l = list(map(int, open(0).read().split())) a = [0] * M for i in l: if a[i] < 1: for j in range(i * 2, M, i): a[j] = 2 a[i] += 1 print((a.count(1)))
false
0
[ "- if a[i] < 2:", "- for j in range(i, M, i):", "- a[j] += 2", "- a[i] -= 1", "+ if a[i] < 1:", "+ for j in range(i * 2, M, i):", "+ a[j] = 2", "+ a[i] += 1" ]
false
0.007295
0.241575
0.030198
[ "s601869809", "s457327089" ]
u471797506
p03142
python
s590869202
s659325031
1,266
799
182,360
116,748
Accepted
Accepted
36.89
import sys from collections import defaultdict sys.setrecursionlimit(100000) N, M = list(map(int, input().split())) AB = defaultdict(list) gain = [0]*N for i in range(N + M - 1): a, b = list(map(int, input().split())) AB[a - 1].append(b - 1) gain[b - 1] += 1 ans = [None]*N def rec(u, p): ans[u] = p for v in AB[u]: gain[v] -= 1 for v in AB[u]: if gain[v] == 0 and ans[v] is None: rec(v, u) root = gain.index(0) rec(root, -1) for i in range(N): print((ans[i] + 1))
import sys from collections import defaultdict sys.setrecursionlimit(1000000) N, M = list(map(int, input().split())) AB = defaultdict(list) gain = [0]*N for i in range(N + M - 1): a, b = list(map(int, input().split())) AB[a - 1].append(b - 1) gain[b - 1] += 1 ans = [None]*N def rec(u, p): ans[u] = p for v in AB[u]: gain[v] -= 1 for v in AB[u]: if gain[v] == 0 and ans[v] is None: rec(v, u) root = gain.index(0) rec(root, -1) for i in range(N): print((ans[i] + 1))
26
26
536
537
import sys from collections import defaultdict sys.setrecursionlimit(100000) N, M = list(map(int, input().split())) AB = defaultdict(list) gain = [0] * N for i in range(N + M - 1): a, b = list(map(int, input().split())) AB[a - 1].append(b - 1) gain[b - 1] += 1 ans = [None] * N def rec(u, p): ans[u] = p for v in AB[u]: gain[v] -= 1 for v in AB[u]: if gain[v] == 0 and ans[v] is None: rec(v, u) root = gain.index(0) rec(root, -1) for i in range(N): print((ans[i] + 1))
import sys from collections import defaultdict sys.setrecursionlimit(1000000) N, M = list(map(int, input().split())) AB = defaultdict(list) gain = [0] * N for i in range(N + M - 1): a, b = list(map(int, input().split())) AB[a - 1].append(b - 1) gain[b - 1] += 1 ans = [None] * N def rec(u, p): ans[u] = p for v in AB[u]: gain[v] -= 1 for v in AB[u]: if gain[v] == 0 and ans[v] is None: rec(v, u) root = gain.index(0) rec(root, -1) for i in range(N): print((ans[i] + 1))
false
0
[ "-sys.setrecursionlimit(100000)", "+sys.setrecursionlimit(1000000)" ]
false
0.063937
0.035589
1.79654
[ "s590869202", "s659325031" ]
u513081876
p03625
python
s910471910
s498101313
229
73
21,540
22,104
Accepted
Accepted
68.12
import collections N = int(eval(input())) A = [int(i) for i in input().split()] dic = collections.Counter(A).most_common() tmp = [] check = 0 dic.sort(reverse=True) for a, b in dic: if b >= 2: check += 1 tmp.append(a) if b>= 4: break if check == 2: break if len(tmp) == 0: print((0)) elif len(tmp) == 1: print((tmp[0]*tmp[0])) else: print((tmp[0] * tmp[1]))
import collections N = int(eval(input())) a = [int(i) for i in input().split()] check = [] dict = collections.Counter(a) for a, b in list(dict.items()): if b >= 2: check.append(a) if len(check) >=2: check.sort() if dict[check[-1]] >= 4: print((check[-1] ** 2)) else: print((check[-1] * check[-2])) elif len(check) == 1: if dict[check[-1]] >= 4: print((check[-1] ** 2)) else: print((0)) else: print((0))
27
23
449
472
import collections N = int(eval(input())) A = [int(i) for i in input().split()] dic = collections.Counter(A).most_common() tmp = [] check = 0 dic.sort(reverse=True) for a, b in dic: if b >= 2: check += 1 tmp.append(a) if b >= 4: break if check == 2: break if len(tmp) == 0: print((0)) elif len(tmp) == 1: print((tmp[0] * tmp[0])) else: print((tmp[0] * tmp[1]))
import collections N = int(eval(input())) a = [int(i) for i in input().split()] check = [] dict = collections.Counter(a) for a, b in list(dict.items()): if b >= 2: check.append(a) if len(check) >= 2: check.sort() if dict[check[-1]] >= 4: print((check[-1] ** 2)) else: print((check[-1] * check[-2])) elif len(check) == 1: if dict[check[-1]] >= 4: print((check[-1] ** 2)) else: print((0)) else: print((0))
false
14.814815
[ "-A = [int(i) for i in input().split()]", "-dic = collections.Counter(A).most_common()", "-tmp = []", "-check = 0", "-dic.sort(reverse=True)", "-for a, b in dic:", "+a = [int(i) for i in input().split()]", "+check = []", "+dict = collections.Counter(a)", "+for a, b in list(dict.items()):", "- ...
false
0.043512
0.040897
1.063944
[ "s910471910", "s498101313" ]
u097317219
p04013
python
s144152086
s265726840
421
387
92,636
92,636
Accepted
Accepted
8.08
n,a = list(map(int,input().split())) x = list(map(int,input().split())) max_x = max(x) dp = [[[0]*(n*max_x+1) for i in range(n+1)] for j in range(n+1)] dp[0][0][0] = 1 for i in range(n+1): for j in range(n+1): for k in range(n*max_x+1): if i>=1 and k < x[i-1]: dp[i][j][k] = dp[i-1][j][k] elif i>=1 and j>= 1 and k>= x[i-1]: dp[i][j][k] = dp[i-1][j][k]+dp[i-1][j-1][k-x[i-1]] else: continue ans = 0 for j in range(1,n+1): if j*a <= n*max_x+1: ans += dp[n][j][j*a] print(ans)
n,a = list(map(int,input().split())) x = list(map(int,input().split())) max_x = max(max(x),a) dp = [[[0]*(n*max_x+1) for i in range(n+1)] for j in range(n+1)] dp[0][0][0] = 1 for i in range(n+1): for j in range(n+1): for k in range(n*max_x+1): if i>=1 and k < x[i-1]: dp[i][j][k] = dp[i-1][j][k] elif i>=1 and j>= 1 and k>= x[i-1]: dp[i][j][k] = dp[i-1][j][k]+dp[i-1][j-1][k-x[i-1]] else: continue ans = 0 for j in range(1,n+1): ans += dp[n][j][j*a] print(ans)
19
18
540
523
n, a = list(map(int, input().split())) x = list(map(int, input().split())) max_x = max(x) dp = [[[0] * (n * max_x + 1) for i in range(n + 1)] for j in range(n + 1)] dp[0][0][0] = 1 for i in range(n + 1): for j in range(n + 1): for k in range(n * max_x + 1): if i >= 1 and k < x[i - 1]: dp[i][j][k] = dp[i - 1][j][k] elif i >= 1 and j >= 1 and k >= x[i - 1]: dp[i][j][k] = dp[i - 1][j][k] + dp[i - 1][j - 1][k - x[i - 1]] else: continue ans = 0 for j in range(1, n + 1): if j * a <= n * max_x + 1: ans += dp[n][j][j * a] print(ans)
n, a = list(map(int, input().split())) x = list(map(int, input().split())) max_x = max(max(x), a) dp = [[[0] * (n * max_x + 1) for i in range(n + 1)] for j in range(n + 1)] dp[0][0][0] = 1 for i in range(n + 1): for j in range(n + 1): for k in range(n * max_x + 1): if i >= 1 and k < x[i - 1]: dp[i][j][k] = dp[i - 1][j][k] elif i >= 1 and j >= 1 and k >= x[i - 1]: dp[i][j][k] = dp[i - 1][j][k] + dp[i - 1][j - 1][k - x[i - 1]] else: continue ans = 0 for j in range(1, n + 1): ans += dp[n][j][j * a] print(ans)
false
5.263158
[ "-max_x = max(x)", "+max_x = max(max(x), a)", "- if j * a <= n * max_x + 1:", "- ans += dp[n][j][j * a]", "+ ans += dp[n][j][j * a]" ]
false
0.035532
0.037165
0.956054
[ "s144152086", "s265726840" ]
u325956328
p02787
python
s866157183
s392977217
374
319
43,740
42,864
Accepted
Accepted
14.71
H, N = list(map(int, input().split())) dp = [10 ** 18] * (H + 1) dp[0] = 0 for i in range(N): a, b = list(map(int, input().split())) for j in range(H): nj = min(j + a, H) # nj: 次のjのindex, 配列外参照しないようにminをとる dp[nj] = min(dp[nj], dp[j] + b) print((dp[H]))
def main(): H, N = list(map(int, input().split())) dp = [10 ** 18] * (H + 1) dp[0] = 0 for i in range(N): a, b = list(map(int, input().split())) for j in range(H): nj = min(j + a, H) # nj: 次のjのindex, 配列外参照しないようにminをとる dp[nj] = min(dp[nj], dp[j] + b) print((dp[H])) main()
13
16
280
339
H, N = list(map(int, input().split())) dp = [10**18] * (H + 1) dp[0] = 0 for i in range(N): a, b = list(map(int, input().split())) for j in range(H): nj = min(j + a, H) # nj: 次のjのindex, 配列外参照しないようにminをとる dp[nj] = min(dp[nj], dp[j] + b) print((dp[H]))
def main(): H, N = list(map(int, input().split())) dp = [10**18] * (H + 1) dp[0] = 0 for i in range(N): a, b = list(map(int, input().split())) for j in range(H): nj = min(j + a, H) # nj: 次のjのindex, 配列外参照しないようにminをとる dp[nj] = min(dp[nj], dp[j] + b) print((dp[H])) main()
false
18.75
[ "-H, N = list(map(int, input().split()))", "-dp = [10**18] * (H + 1)", "-dp[0] = 0", "-for i in range(N):", "- a, b = list(map(int, input().split()))", "- for j in range(H):", "- nj = min(j + a, H) # nj: 次のjのindex, 配列外参照しないようにminをとる", "- dp[nj] = min(dp[nj], dp[j] + b)", "-print...
false
0.07441
0.065823
1.130459
[ "s866157183", "s392977217" ]
u123756661
p04000
python
s045441429
s638121950
1,654
841
163,288
139,512
Accepted
Accepted
49.15
def sol(): import sys input=sys.stdin.readline h,w,n=list(map(int,input().split())) d={} for i in range(n): y,x=list(map(int,input().split())) if (y,x) in d: d[(y,x)]+=1 else: d[(y,x)]=1 if y+1<=h and (y+1,x) in d: d[(y+1,x)]+=1 elif y+1<=h: d[(y+1,x)]=1 if y+2<=h and (y+2,x) in d: d[(y+2,x)]+=1 elif y+2<=h: d[(y+2,x)]=1 if x+1<=w and (y,x+1) in d: d[(y,x+1)]+=1 elif x+1<=w: d[(y,x+1)]=1 if x+2<=w and (y,x+2) in d: d[(y,x+2)]+=1 elif x+2<=w: d[(y,x+2)]=1 if x+1<=w and y+1<=h and (y+1,x+1) in d: d[(y+1,x+1)]+=1 elif x+1<=w and y+1<=h: d[(y+1,x+1)]=1 if x+2<=w and y+1<=h and (y+1,x+2) in d: d[(y+1,x+2)]+=1 elif x+2<=w and y+1<=h: d[(y+1,x+2)]=1 if x+1<=w and y+2<=h and (y+2,x+1) in d: d[(y+2,x+1)]+=1 elif x+1<=w and y+2<=h: d[(y+2,x+1)]=1 if x+2<=w and y+2<=h and (y+2,x+2) in d: d[(y+2,x+2)]+=1 elif x+2<=w and y+2<=h: d[(y+2,x+2)]=1 ans=[0]*10 for i in d: if i[0]>2 and i[1]>2: ans[d[i]]+=1 ans[0]=h*w-sum(ans)-w*2-h*2+4 for i in ans: print(i) if __name__=="__main__": sol()
def sol(): import sys input=sys.stdin.readline h,w,n=list(map(int,input().split())) d={} t=[(0,0),(0,1),(0,2),(1,0),(1,1),(1,2),(2,0),(2,1),(2,2)] for i in range(n): y,x=list(map(int,input().split())) for a,b in t: a+=y b+=x if 0<a<=h and 0<b<=w and (a,b) in d: d[(a,b)]+=1 elif 0<a<=h and 0<b<=w: d[(a,b)]=1 ans=[0]*10 for i in d: if i[0]>2 and i[1]>2: ans[d[i]]+=1 ans[0]=h*w-sum(ans)-w*2-h*2+4 for i in ans: print(i) if __name__=="__main__": sol()
55
25
1,475
601
def sol(): import sys input = sys.stdin.readline h, w, n = list(map(int, input().split())) d = {} for i in range(n): y, x = list(map(int, input().split())) if (y, x) in d: d[(y, x)] += 1 else: d[(y, x)] = 1 if y + 1 <= h and (y + 1, x) in d: d[(y + 1, x)] += 1 elif y + 1 <= h: d[(y + 1, x)] = 1 if y + 2 <= h and (y + 2, x) in d: d[(y + 2, x)] += 1 elif y + 2 <= h: d[(y + 2, x)] = 1 if x + 1 <= w and (y, x + 1) in d: d[(y, x + 1)] += 1 elif x + 1 <= w: d[(y, x + 1)] = 1 if x + 2 <= w and (y, x + 2) in d: d[(y, x + 2)] += 1 elif x + 2 <= w: d[(y, x + 2)] = 1 if x + 1 <= w and y + 1 <= h and (y + 1, x + 1) in d: d[(y + 1, x + 1)] += 1 elif x + 1 <= w and y + 1 <= h: d[(y + 1, x + 1)] = 1 if x + 2 <= w and y + 1 <= h and (y + 1, x + 2) in d: d[(y + 1, x + 2)] += 1 elif x + 2 <= w and y + 1 <= h: d[(y + 1, x + 2)] = 1 if x + 1 <= w and y + 2 <= h and (y + 2, x + 1) in d: d[(y + 2, x + 1)] += 1 elif x + 1 <= w and y + 2 <= h: d[(y + 2, x + 1)] = 1 if x + 2 <= w and y + 2 <= h and (y + 2, x + 2) in d: d[(y + 2, x + 2)] += 1 elif x + 2 <= w and y + 2 <= h: d[(y + 2, x + 2)] = 1 ans = [0] * 10 for i in d: if i[0] > 2 and i[1] > 2: ans[d[i]] += 1 ans[0] = h * w - sum(ans) - w * 2 - h * 2 + 4 for i in ans: print(i) if __name__ == "__main__": sol()
def sol(): import sys input = sys.stdin.readline h, w, n = list(map(int, input().split())) d = {} t = [(0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2), (2, 0), (2, 1), (2, 2)] for i in range(n): y, x = list(map(int, input().split())) for a, b in t: a += y b += x if 0 < a <= h and 0 < b <= w and (a, b) in d: d[(a, b)] += 1 elif 0 < a <= h and 0 < b <= w: d[(a, b)] = 1 ans = [0] * 10 for i in d: if i[0] > 2 and i[1] > 2: ans[d[i]] += 1 ans[0] = h * w - sum(ans) - w * 2 - h * 2 + 4 for i in ans: print(i) if __name__ == "__main__": sol()
false
54.545455
[ "+ t = [(0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2), (2, 0), (2, 1), (2, 2)]", "- if (y, x) in d:", "- d[(y, x)] += 1", "- else:", "- d[(y, x)] = 1", "- if y + 1 <= h and (y + 1, x) in d:", "- d[(y + 1, x)] += 1", "- elif y + 1 <= h:",...
false
0.067012
0.038163
1.755947
[ "s045441429", "s638121950" ]
u335830383
p02993
python
s384958935
s377951929
163
18
38,384
2,940
Accepted
Accepted
88.96
n = list(eval(input())) flag = 1 for i in range(1,len(n)): if n[i-1] == n[i]: print("Bad") flag = 0 break if flag: print("Good")
s = eval(input()) last = s[0] flag = 0 for i in s[1:]: if i == last: flag = 1 last = i if flag: print("Bad") else: print("Good")
9
12
163
158
n = list(eval(input())) flag = 1 for i in range(1, len(n)): if n[i - 1] == n[i]: print("Bad") flag = 0 break if flag: print("Good")
s = eval(input()) last = s[0] flag = 0 for i in s[1:]: if i == last: flag = 1 last = i if flag: print("Bad") else: print("Good")
false
25
[ "-n = list(eval(input()))", "-flag = 1", "-for i in range(1, len(n)):", "- if n[i - 1] == n[i]:", "- print(\"Bad\")", "- flag = 0", "- break", "+s = eval(input())", "+last = s[0]", "+flag = 0", "+for i in s[1:]:", "+ if i == last:", "+ flag = 1", "+ las...
false
0.11645
0.036043
3.230872
[ "s384958935", "s377951929" ]
u968166680
p03600
python
s696041557
s959828399
494
426
42,588
42,332
Accepted
Accepted
13.77
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 def main(): N = int(readline()) G = [list(map(int, readline().split())) for _ in range(N)] ans = 0 for i in range(N): for j in range(i + 1, N): needed = True for k in range(N): if G[i][j] > G[i][k] + G[k][j]: print((-1)) return if k not in (i, j) and G[i][j] == G[i][k] + G[k][j]: needed = False if needed: ans += G[i][j] 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 def main(): N = int(readline()) G = [list(map(int, readline().split())) for _ in range(N)] ans = 0 for i in range(N): for j in range(i + 1, N): needed = True for k in range(N): if k == i or k == j: continue if G[i][j] > G[i][k] + G[k][j]: print((-1)) return if G[i][j] == G[i][k] + G[k][j]: needed = False if needed: ans += G[i][j] print(ans) return if __name__ == '__main__': main()
32
34
730
778
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10**9) INF = 1 << 60 def main(): N = int(readline()) G = [list(map(int, readline().split())) for _ in range(N)] ans = 0 for i in range(N): for j in range(i + 1, N): needed = True for k in range(N): if G[i][j] > G[i][k] + G[k][j]: print((-1)) return if k not in (i, j) and G[i][j] == G[i][k] + G[k][j]: needed = False if needed: ans += G[i][j] 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 def main(): N = int(readline()) G = [list(map(int, readline().split())) for _ in range(N)] ans = 0 for i in range(N): for j in range(i + 1, N): needed = True for k in range(N): if k == i or k == j: continue if G[i][j] > G[i][k] + G[k][j]: print((-1)) return if G[i][j] == G[i][k] + G[k][j]: needed = False if needed: ans += G[i][j] print(ans) return if __name__ == "__main__": main()
false
5.882353
[ "+ if k == i or k == j:", "+ continue", "- if k not in (i, j) and G[i][j] == G[i][k] + G[k][j]:", "+ if G[i][j] == G[i][k] + G[k][j]:" ]
false
0.040482
0.041933
0.965392
[ "s696041557", "s959828399" ]
u354638986
p03252
python
s477787420
s145656225
73
42
3,632
3,632
Accepted
Accepted
42.47
def main(): s, t = eval(input()), eval(input()) s_dic, t_dic = {}, {} for i, j in zip(s, t): if i in s_dic and s_dic[i] != j: print("No") exit() if j in t_dic and t_dic[j] != i: print("No") exit() s_dic[i], t_dic[j] = j, i print("Yes") if __name__ == '__main__': main()
def main(): s, t = eval(input()), eval(input()) used, dic = [0] * 512, {} for i in range(26): dic[chr(ord('a')+i)] = chr(ord('a')+i) for i, j in zip(s, t): if dic[i] == j: used[ord(i)] = 1 continue for k, v in list(dic.items()): if v == j: if used[ord(k)]: print("No") exit() dic[k] = i if used[ord(i)] and dic[i] != j: print("No") exit() dic[i], used[ord(i)] = j, 1 print("Yes") if __name__ == '__main__': main()
20
30
375
629
def main(): s, t = eval(input()), eval(input()) s_dic, t_dic = {}, {} for i, j in zip(s, t): if i in s_dic and s_dic[i] != j: print("No") exit() if j in t_dic and t_dic[j] != i: print("No") exit() s_dic[i], t_dic[j] = j, i print("Yes") if __name__ == "__main__": main()
def main(): s, t = eval(input()), eval(input()) used, dic = [0] * 512, {} for i in range(26): dic[chr(ord("a") + i)] = chr(ord("a") + i) for i, j in zip(s, t): if dic[i] == j: used[ord(i)] = 1 continue for k, v in list(dic.items()): if v == j: if used[ord(k)]: print("No") exit() dic[k] = i if used[ord(i)] and dic[i] != j: print("No") exit() dic[i], used[ord(i)] = j, 1 print("Yes") if __name__ == "__main__": main()
false
33.333333
[ "- s_dic, t_dic = {}, {}", "+ used, dic = [0] * 512, {}", "+ for i in range(26):", "+ dic[chr(ord(\"a\") + i)] = chr(ord(\"a\") + i)", "- if i in s_dic and s_dic[i] != j:", "+ if dic[i] == j:", "+ used[ord(i)] = 1", "+ continue", "+ for k, v...
false
0.065451
0.045061
1.452491
[ "s477787420", "s145656225" ]
u098012509
p03854
python
s665112913
s625734973
38
24
3,956
3,188
Accepted
Accepted
36.84
import sys input = sys.stdin.readline def main(): S = input().strip() s = list(S) n = len(s) while n > 0: if "".join(s[n - 5:n]) == "dream": n -= 5 elif "".join(s[n - 5:n]) == "erase": n -= 5 elif "".join(s[n - 7:n]) == "dreamer": n -= 7 elif "".join(s[n - 6:n]) == "eraser": n -= 6 else: print("NO") return else: print("YES") if __name__ == '__main__': main()
import sys input = sys.stdin.readline def main(): S = input().strip() n = len(S) while n > 0: if S[n - 5:n] == "dream": n -= 5 elif S[n - 5:n] == "erase": n -= 5 elif S[n - 7:n] == "dreamer": n -= 7 elif S[n - 6:n] == "eraser": n -= 6 else: print("NO") return else: print("YES") if __name__ == '__main__': main()
29
28
540
487
import sys input = sys.stdin.readline def main(): S = input().strip() s = list(S) n = len(s) while n > 0: if "".join(s[n - 5 : n]) == "dream": n -= 5 elif "".join(s[n - 5 : n]) == "erase": n -= 5 elif "".join(s[n - 7 : n]) == "dreamer": n -= 7 elif "".join(s[n - 6 : n]) == "eraser": n -= 6 else: print("NO") return else: print("YES") if __name__ == "__main__": main()
import sys input = sys.stdin.readline def main(): S = input().strip() n = len(S) while n > 0: if S[n - 5 : n] == "dream": n -= 5 elif S[n - 5 : n] == "erase": n -= 5 elif S[n - 7 : n] == "dreamer": n -= 7 elif S[n - 6 : n] == "eraser": n -= 6 else: print("NO") return else: print("YES") if __name__ == "__main__": main()
false
3.448276
[ "- s = list(S)", "- n = len(s)", "+ n = len(S)", "- if \"\".join(s[n - 5 : n]) == \"dream\":", "+ if S[n - 5 : n] == \"dream\":", "- elif \"\".join(s[n - 5 : n]) == \"erase\":", "+ elif S[n - 5 : n] == \"erase\":", "- elif \"\".join(s[n - 7 : n]) == \"dreame...
false
0.042972
0.036514
1.17686
[ "s665112913", "s625734973" ]
u573754721
p02910
python
s235217336
s806646293
181
17
38,384
2,940
Accepted
Accepted
90.61
import sys S = list(eval(input())) odd = S[::2] even = S[1::2] flag = True for i in odd: if i == 'L': flag = False break for j in even: if j =='R': flag = False break if flag: print('Yes') else: print('No')
s=eval(input()) for i in range(len(s)): if i%2==0 and s[i]=='L': print("No") exit() if i%2==1 and s[i]=='R': print("No") exit() print('Yes')
23
10
312
206
import sys S = list(eval(input())) odd = S[::2] even = S[1::2] flag = True for i in odd: if i == "L": flag = False break for j in even: if j == "R": flag = False break if flag: print("Yes") else: print("No")
s = eval(input()) for i in range(len(s)): if i % 2 == 0 and s[i] == "L": print("No") exit() if i % 2 == 1 and s[i] == "R": print("No") exit() print("Yes")
false
56.521739
[ "-import sys", "-", "-S = list(eval(input()))", "-odd = S[::2]", "-even = S[1::2]", "-flag = True", "-for i in odd:", "- if i == \"L\":", "- flag = False", "- break", "-for j in even:", "- if j == \"R\":", "- flag = False", "- break", "-if flag:", "- ...
false
0.036909
0.041508
0.889188
[ "s235217336", "s806646293" ]
u489959379
p03026
python
s653421160
s601276216
66
61
18,236
22,304
Accepted
Accepted
7.58
import sys sys.setrecursionlimit(10 ** 7) input = sys.stdin.readline f_inf = float('inf') mod = 10 ** 9 + 7 res = 0 def resolve(): def dfs(v, p): global res c = C.pop(0) T[v] = c for u in edge[v]: if u == p: continue else: res += min(T[v], C[0]) dfs(u, v) n = int(eval(input())) edge = [[] for _ in range(n)] cnt_edge = [0] * n for _ in range(n - 1): a, b = list(map(int, input().split())) edge[a - 1].append(b - 1) edge[b - 1].append(a - 1) cnt_edge[a - 1] += 1 cnt_edge[b - 1] += 1 C = list(map(int, input().split())) C.sort(reverse=True) start = cnt_edge.index(max(cnt_edge)) T = [0] * n dfs(start, -1) print(res) print((*T)) if __name__ == '__main__': resolve()
import sys sys.setrecursionlimit(10 ** 7) input = sys.stdin.readline f_inf = float('inf') mod = 10 ** 9 + 7 res = 0 def resolve(): def dfs(v, p): global res c = C.pop(0) T[v] = c for u in edge[v]: if u == p: continue else: res += min(T[v], C[0]) dfs(u, v) n = int(eval(input())) edge = [[] for _ in range(n)] for _ in range(n - 1): a, b = list(map(int, input().split())) edge[a - 1].append(b - 1) edge[b - 1].append(a - 1) C = list(map(int, input().split())) C.sort(reverse=True) T = [0] * n dfs(0, -1) print(res) print((*T)) if __name__ == '__main__': resolve()
42
37
896
763
import sys sys.setrecursionlimit(10**7) input = sys.stdin.readline f_inf = float("inf") mod = 10**9 + 7 res = 0 def resolve(): def dfs(v, p): global res c = C.pop(0) T[v] = c for u in edge[v]: if u == p: continue else: res += min(T[v], C[0]) dfs(u, v) n = int(eval(input())) edge = [[] for _ in range(n)] cnt_edge = [0] * n for _ in range(n - 1): a, b = list(map(int, input().split())) edge[a - 1].append(b - 1) edge[b - 1].append(a - 1) cnt_edge[a - 1] += 1 cnt_edge[b - 1] += 1 C = list(map(int, input().split())) C.sort(reverse=True) start = cnt_edge.index(max(cnt_edge)) T = [0] * n dfs(start, -1) print(res) print((*T)) if __name__ == "__main__": resolve()
import sys sys.setrecursionlimit(10**7) input = sys.stdin.readline f_inf = float("inf") mod = 10**9 + 7 res = 0 def resolve(): def dfs(v, p): global res c = C.pop(0) T[v] = c for u in edge[v]: if u == p: continue else: res += min(T[v], C[0]) dfs(u, v) n = int(eval(input())) edge = [[] for _ in range(n)] for _ in range(n - 1): a, b = list(map(int, input().split())) edge[a - 1].append(b - 1) edge[b - 1].append(a - 1) C = list(map(int, input().split())) C.sort(reverse=True) T = [0] * n dfs(0, -1) print(res) print((*T)) if __name__ == "__main__": resolve()
false
11.904762
[ "- cnt_edge = [0] * n", "- cnt_edge[a - 1] += 1", "- cnt_edge[b - 1] += 1", "- start = cnt_edge.index(max(cnt_edge))", "- dfs(start, -1)", "+ dfs(0, -1)" ]
false
0.065788
0.038841
1.693776
[ "s653421160", "s601276216" ]
u498487134
p02768
python
s548630180
s500065852
187
148
38,512
107,444
Accepted
Accepted
20.86
n,a,b=list(map(int,input().split())) mod=10**9+7 def cmb(n, r,mod): if n - r < r: r = n - r if r == 0: return 1 if r == 1: return n #X//Y X=1 Y=1 for i in range(r): X*=(n-i) X%=mod Y*=(i+1) Y%=mod inv=pow(Y,mod-2,mod) return (X*inv)%mod allp=pow(2,n,mod)-1 ans=(allp-cmb(n,a,mod)-cmb(n,b,mod))%mod if n==2: ans=0 print(ans)
import sys input = sys.stdin.readline def I(): return int(eval(input())) def MI(): return list(map(int, input().split())) def LI(): return list(map(int, input().split())) def main(): mod=10**9+7 N,a,b=MI() M=2*(10**5) + 5 def cmb(n, r): if n - r < r: r = n - r if r == 0: return 1 if r == 1: return n numerator = [n - r + k + 1 for k in range(r)] denominator = [k + 1 for k in range(r)] for p in range(2,r+1): pivot = denominator[p - 1] if pivot > 1: offset = (n - r) % p for k in range(p-1,r,p): numerator[k - offset] /= pivot denominator[k] /= pivot result = 1 for k in range(r): if numerator[k] > 1: result *= int(numerator[k]) result%=mod return result ans=pow(2,N,mod)-1 ans-=cmb(N,a) ans-=cmb(N,b) print((ans%mod)) main()
29
42
449
1,020
n, a, b = list(map(int, input().split())) mod = 10**9 + 7 def cmb(n, r, mod): if n - r < r: r = n - r if r == 0: return 1 if r == 1: return n # X//Y X = 1 Y = 1 for i in range(r): X *= n - i X %= mod Y *= i + 1 Y %= mod inv = pow(Y, mod - 2, mod) return (X * inv) % mod allp = pow(2, n, mod) - 1 ans = (allp - cmb(n, a, mod) - cmb(n, b, mod)) % mod if n == 2: ans = 0 print(ans)
import sys input = sys.stdin.readline def I(): return int(eval(input())) def MI(): return list(map(int, input().split())) def LI(): return list(map(int, input().split())) def main(): mod = 10**9 + 7 N, a, b = MI() M = 2 * (10**5) + 5 def cmb(n, r): if n - r < r: r = n - r if r == 0: return 1 if r == 1: return n numerator = [n - r + k + 1 for k in range(r)] denominator = [k + 1 for k in range(r)] for p in range(2, r + 1): pivot = denominator[p - 1] if pivot > 1: offset = (n - r) % p for k in range(p - 1, r, p): numerator[k - offset] /= pivot denominator[k] /= pivot result = 1 for k in range(r): if numerator[k] > 1: result *= int(numerator[k]) result %= mod return result ans = pow(2, N, mod) - 1 ans -= cmb(N, a) ans -= cmb(N, b) print((ans % mod)) main()
false
30.952381
[ "-n, a, b = list(map(int, input().split()))", "-mod = 10**9 + 7", "+import sys", "+", "+input = sys.stdin.readline", "-def cmb(n, r, mod):", "- if n - r < r:", "- r = n - r", "- if r == 0:", "- return 1", "- if r == 1:", "- return n", "- # X//Y", "- X = ...
false
0.207615
0.498484
0.416493
[ "s548630180", "s500065852" ]
u367701763
p02793
python
s324628200
s077985756
232
174
78,756
148,436
Accepted
Accepted
25
from collections import Counter, defaultdict # 拡張ユークリッド互除法 # ax + by = gcd(a,b)の最小整数解を返す def egcd(a, b): if a == 0: return (b, 0, 1) else: g, y, x = egcd(b % a, a) return (g, x - (b // a) * y, y) # mを法とするaの乗法的逆元 def modinv(a, m): g, x, y = egcd(a, m) if g != 1: raise Exception('modular inverse does not exist') else: return x % m # 素因数分解 def prime_factors(n): i = 2 while i * i <= n: if n % i: i += 1 else: n //= i yield i if n > 1: yield n # mを法とするときのa^n def modpow(a,n,m): res = 1 t = a while n: if n%2: res = (res*t)%m t = (t*t)%m n //= 2 return res def lcm_mod(nums, mod): p = defaultdict(int) for n in nums: c = Counter(prime_factors(n)) for v,cnt in list(c.items()): p[v] = max(p[v],cnt) res = 1 for v,cnt in list(p.items()): res *= modpow(v,cnt,mod) res %= mod return res MOD = 10**9+7 N = int(eval(input())) A = list(map(int,input().split())) s = sum(modinv(a,MOD) for a in A)%MOD s *= lcm_mod(A, MOD) print((s%MOD))
import sys input = sys.stdin.readline from collections import defaultdict class PrimeFactor(): def __init__(self, n): # エラトステネス O(N loglog N) self.n = n self.table = [i if i % 2 else 2 for i in range(n + 1)] self.table[0] = 0 for p in range(3, n + 1): if self.table[p] == p: for q in range(p * p, n + 1, 2 * p): self.table[q] = p def is_prime(self, x): # 素数判定 O(1) if x < 2: return False return self.table[x] == x def prime_factors(self, x): # 素因数分解 O(logN) res = [] if x < 2: return res while self.table[x] != 1: res.append(self.table[x]) x //= self.table[x] return res def prime_counter(self, x): # 素因数分解(個数のリスト) res = defaultdict(int) if x < 2: return res while self.table[x] != 1: res[self.table[x]] += 1 x //= self.table[x] return res def prime_gcd(self, X): # n個の最大公約数 X:n個のリスト exponents = self.prime_counter(X[0]) for x in X[1:]: Y = self.prime_counter(x) for prime, exp in list(exponents.items()): if Y[prime] < exp: exponents[prime] = Y[prime] res = 1 for prime, exp in list(exponents.items()): res *= pow(prime, exp) return res def prime_lcm(self, X, mod=None): # n個の最小公倍数 X:n個のリスト exponents = defaultdict(int) for x in X: for prime, exp in list(self.prime_counter(x).items()): if exp > exponents[prime]: exponents[prime] = exp res = 1 for prime, exp in list(exponents.items()): res *= pow(prime, exp, mod) if mod == None: return res else: return res % mod mod = 10 ** 9 + 7 N = int(eval(input())) A = list(map(int, input().split())) table = PrimeFactor(10**6) num = table.prime_lcm(A,mod) res = 0 for a in A: res += num * pow(a, mod - 2, mod) print((res % mod))
66
77
1,231
2,208
from collections import Counter, defaultdict # 拡張ユークリッド互除法 # ax + by = gcd(a,b)の最小整数解を返す def egcd(a, b): if a == 0: return (b, 0, 1) else: g, y, x = egcd(b % a, a) return (g, x - (b // a) * y, y) # mを法とするaの乗法的逆元 def modinv(a, m): g, x, y = egcd(a, m) if g != 1: raise Exception("modular inverse does not exist") else: return x % m # 素因数分解 def prime_factors(n): i = 2 while i * i <= n: if n % i: i += 1 else: n //= i yield i if n > 1: yield n # mを法とするときのa^n def modpow(a, n, m): res = 1 t = a while n: if n % 2: res = (res * t) % m t = (t * t) % m n //= 2 return res def lcm_mod(nums, mod): p = defaultdict(int) for n in nums: c = Counter(prime_factors(n)) for v, cnt in list(c.items()): p[v] = max(p[v], cnt) res = 1 for v, cnt in list(p.items()): res *= modpow(v, cnt, mod) res %= mod return res MOD = 10**9 + 7 N = int(eval(input())) A = list(map(int, input().split())) s = sum(modinv(a, MOD) for a in A) % MOD s *= lcm_mod(A, MOD) print((s % MOD))
import sys input = sys.stdin.readline from collections import defaultdict class PrimeFactor: def __init__(self, n): # エラトステネス O(N loglog N) self.n = n self.table = [i if i % 2 else 2 for i in range(n + 1)] self.table[0] = 0 for p in range(3, n + 1): if self.table[p] == p: for q in range(p * p, n + 1, 2 * p): self.table[q] = p def is_prime(self, x): # 素数判定 O(1) if x < 2: return False return self.table[x] == x def prime_factors(self, x): # 素因数分解 O(logN) res = [] if x < 2: return res while self.table[x] != 1: res.append(self.table[x]) x //= self.table[x] return res def prime_counter(self, x): # 素因数分解(個数のリスト) res = defaultdict(int) if x < 2: return res while self.table[x] != 1: res[self.table[x]] += 1 x //= self.table[x] return res def prime_gcd(self, X): # n個の最大公約数 X:n個のリスト exponents = self.prime_counter(X[0]) for x in X[1:]: Y = self.prime_counter(x) for prime, exp in list(exponents.items()): if Y[prime] < exp: exponents[prime] = Y[prime] res = 1 for prime, exp in list(exponents.items()): res *= pow(prime, exp) return res def prime_lcm(self, X, mod=None): # n個の最小公倍数 X:n個のリスト exponents = defaultdict(int) for x in X: for prime, exp in list(self.prime_counter(x).items()): if exp > exponents[prime]: exponents[prime] = exp res = 1 for prime, exp in list(exponents.items()): res *= pow(prime, exp, mod) if mod == None: return res else: return res % mod mod = 10**9 + 7 N = int(eval(input())) A = list(map(int, input().split())) table = PrimeFactor(10**6) num = table.prime_lcm(A, mod) res = 0 for a in A: res += num * pow(a, mod - 2, mod) print((res % mod))
false
14.285714
[ "-from collections import Counter, defaultdict", "+import sys", "-# 拡張ユークリッド互除法", "-# ax + by = gcd(a,b)の最小整数解を返す", "-def egcd(a, b):", "- if a == 0:", "- return (b, 0, 1)", "- else:", "- g, y, x = egcd(b % a, a)", "- return (g, x - (b // a) * y, y)", "+input = sys.std...
false
0.046654
1.291252
0.036131
[ "s324628200", "s077985756" ]
u540761833
p02948
python
s573769164
s654353342
498
355
23,752
23,752
Accepted
Accepted
28.71
import heapq N,M = list(map(int,input().split())) AB = [[] for i in range(M+1)] for i in range(N): a,b = list(map(int,input().split())) if a <= M: AB[a].append(-b) work = 0 AB2 = [] heapq.heapify(AB2) for i in range(1,M+1): for j in AB[i]: heapq.heappush(AB2,j) if len(AB2) > 0: b = heapq.heappop(AB2) work += -b print(work)
import sys import heapq input = sys.stdin.readline N,M = list(map(int,input().split())) AB = [[] for i in range(M+1)] for i in range(N): a,b = list(map(int,input().split())) if a <= M: AB[a].append(-b) work = 0 AB2 = [] heapq.heapify(AB2) for i in range(1,M+1): for j in AB[i]: heapq.heappush(AB2,j) if len(AB2) > 0: b = heapq.heappop(AB2) work += -b print(work)
17
19
382
422
import heapq N, M = list(map(int, input().split())) AB = [[] for i in range(M + 1)] for i in range(N): a, b = list(map(int, input().split())) if a <= M: AB[a].append(-b) work = 0 AB2 = [] heapq.heapify(AB2) for i in range(1, M + 1): for j in AB[i]: heapq.heappush(AB2, j) if len(AB2) > 0: b = heapq.heappop(AB2) work += -b print(work)
import sys import heapq input = sys.stdin.readline N, M = list(map(int, input().split())) AB = [[] for i in range(M + 1)] for i in range(N): a, b = list(map(int, input().split())) if a <= M: AB[a].append(-b) work = 0 AB2 = [] heapq.heapify(AB2) for i in range(1, M + 1): for j in AB[i]: heapq.heappush(AB2, j) if len(AB2) > 0: b = heapq.heappop(AB2) work += -b print(work)
false
10.526316
[ "+import sys", "+input = sys.stdin.readline" ]
false
0.129693
0.087813
1.476916
[ "s573769164", "s654353342" ]
u891635666
p03283
python
s660778449
s225746665
1,203
506
60,380
54,748
Accepted
Accepted
57.94
import itertools import sys input = sys.stdin.readline n, m, q = list(map(int, input().split())) ls = [[0] * n for _ in range(n)] for _ in range(m): l, r = list(map(int, input().split())) ls[l - 1][r - l] += 1 for i in range(n): ls[i] = list(itertools.accumulate(ls[i])) for _ in range(q): l, r = list(map(int, input().split())) l -= 1 r -= 1 res = 0 for i in range(r - l + 1): res += ls[l + i][r - l - i] print(res)
import sys input = sys.stdin.readline n, m, q = list(map(int, input().split())) ls = [[0] * (n + 1) for _ in range(n + 1)] for _ in range(m): l, r = list(map(int, input().split())) ls[l][r] += 1 for i in range(1, n + 1): for j in range(1, n + 1): ls[i][j] += ls[i - 1][j] + ls[i][j - 1] - ls[i - 1][j - 1] for _ in range(q): l, r = list(map(int, input().split())) print((ls[r][r] - ls[l - 1][r] - ls[r][l - 1] + ls[l - 1][l - 1]))
20
15
463
454
import itertools import sys input = sys.stdin.readline n, m, q = list(map(int, input().split())) ls = [[0] * n for _ in range(n)] for _ in range(m): l, r = list(map(int, input().split())) ls[l - 1][r - l] += 1 for i in range(n): ls[i] = list(itertools.accumulate(ls[i])) for _ in range(q): l, r = list(map(int, input().split())) l -= 1 r -= 1 res = 0 for i in range(r - l + 1): res += ls[l + i][r - l - i] print(res)
import sys input = sys.stdin.readline n, m, q = list(map(int, input().split())) ls = [[0] * (n + 1) for _ in range(n + 1)] for _ in range(m): l, r = list(map(int, input().split())) ls[l][r] += 1 for i in range(1, n + 1): for j in range(1, n + 1): ls[i][j] += ls[i - 1][j] + ls[i][j - 1] - ls[i - 1][j - 1] for _ in range(q): l, r = list(map(int, input().split())) print((ls[r][r] - ls[l - 1][r] - ls[r][l - 1] + ls[l - 1][l - 1]))
false
25
[ "-import itertools", "-ls = [[0] * n for _ in range(n)]", "+ls = [[0] * (n + 1) for _ in range(n + 1)]", "- ls[l - 1][r - l] += 1", "-for i in range(n):", "- ls[i] = list(itertools.accumulate(ls[i]))", "+ ls[l][r] += 1", "+for i in range(1, n + 1):", "+ for j in range(1, n + 1):", "+ ...
false
0.041945
0.041023
1.022482
[ "s660778449", "s225746665" ]
u133936772
p02936
python
s430626963
s260991310
1,488
1,198
283,156
56,284
Accepted
Accepted
19.49
import sys sys.setrecursionlimit(10**6) f=lambda:list(map(int,input().split())) n,k=f() g=[[] for _ in range(n)] for i in range(n-1): a,b=f() g[a-1]+=[b-1] g[b-1]+=[a-1] l=[0]*n for _ in range(k): p,x=f() l[p-1]+=x def dfs(v,p=-1): for c in g[v]: if c==p: continue l[c]+=l[v] dfs(c,v) dfs(0) print((*l))
f=lambda:list(map(int,input().split())) n,k=f() g=[[] for _ in range(n)] for _ in range(n-1): a,b=f() g[a-1]+=[b-1] g[b-1]+=[a-1] l=[0]*n for _ in range(k): p,x=f() l[p-1]+=x u=[0]*n q=[0] while q: v=q.pop() u[v]=1 for c in g[v]: if u[c]: continue l[c]+=l[v] q+=[c] print((*l))
20
21
338
317
import sys sys.setrecursionlimit(10**6) f = lambda: list(map(int, input().split())) n, k = f() g = [[] for _ in range(n)] for i in range(n - 1): a, b = f() g[a - 1] += [b - 1] g[b - 1] += [a - 1] l = [0] * n for _ in range(k): p, x = f() l[p - 1] += x def dfs(v, p=-1): for c in g[v]: if c == p: continue l[c] += l[v] dfs(c, v) dfs(0) print((*l))
f = lambda: list(map(int, input().split())) n, k = f() g = [[] for _ in range(n)] for _ in range(n - 1): a, b = f() g[a - 1] += [b - 1] g[b - 1] += [a - 1] l = [0] * n for _ in range(k): p, x = f() l[p - 1] += x u = [0] * n q = [0] while q: v = q.pop() u[v] = 1 for c in g[v]: if u[c]: continue l[c] += l[v] q += [c] print((*l))
false
4.761905
[ "-import sys", "-", "-sys.setrecursionlimit(10**6)", "-for i in range(n - 1):", "+for _ in range(n - 1):", "-", "-", "-def dfs(v, p=-1):", "+u = [0] * n", "+q = [0]", "+while q:", "+ v = q.pop()", "+ u[v] = 1", "- if c == p:", "+ if u[c]:", "- dfs(c, v)", "...
false
0.043887
0.037453
1.171779
[ "s430626963", "s260991310" ]
u371763408
p03240
python
s838218136
s359624022
445
409
3,064
3,064
Accepted
Accepted
8.09
N = int(eval(input())) x, y, h = [0]*N, [0]*N, [0]*N for i in range(N): x[i], y[i], h[i] = list(map(int, input().split())) for cx in range(0, 101): for cy in range(0, 101): for i in range(N): if h[i] > 0: H = h[i] + abs(x[i]-cx)+abs(y[i]-cy) for i in range(N): if h[i] != max(0, H-abs(x[i]-cx)-abs(y[i]-cy)): break else: print((cx, cy, H)) exit()
n = int(eval(input())) xs = [] ys = [] hs = [] for i in range(n): x,y,h = list(map(int,input().split())) xs.append(x) ys.append(y) hs.append(h) for x in range(101): for y in range(101): for i in range(n): if hs[i] >0: H = hs[i] + abs(xs[i]-x)+abs(ys[i]-y) for i in range(n): if hs[i] != max(0, H-abs(xs[i]-x)-abs(ys[i]-y)): break else: print((x,y,H)) exit()
17
22
470
428
N = int(eval(input())) x, y, h = [0] * N, [0] * N, [0] * N for i in range(N): x[i], y[i], h[i] = list(map(int, input().split())) for cx in range(0, 101): for cy in range(0, 101): for i in range(N): if h[i] > 0: H = h[i] + abs(x[i] - cx) + abs(y[i] - cy) for i in range(N): if h[i] != max(0, H - abs(x[i] - cx) - abs(y[i] - cy)): break else: print((cx, cy, H)) exit()
n = int(eval(input())) xs = [] ys = [] hs = [] for i in range(n): x, y, h = list(map(int, input().split())) xs.append(x) ys.append(y) hs.append(h) for x in range(101): for y in range(101): for i in range(n): if hs[i] > 0: H = hs[i] + abs(xs[i] - x) + abs(ys[i] - y) for i in range(n): if hs[i] != max(0, H - abs(xs[i] - x) - abs(ys[i] - y)): break else: print((x, y, H)) exit()
false
22.727273
[ "-N = int(eval(input()))", "-x, y, h = [0] * N, [0] * N, [0] * N", "-for i in range(N):", "- x[i], y[i], h[i] = list(map(int, input().split()))", "-for cx in range(0, 101):", "- for cy in range(0, 101):", "- for i in range(N):", "- if h[i] > 0:", "- H = h[i] + ...
false
0.042506
0.041039
1.035761
[ "s838218136", "s359624022" ]
u077291787
p02558
python
s195943610
s796522838
255
219
84,944
83,928
Accepted
Accepted
14.12
from typing import List class UnionFind: """Union Find (Disjoint Set): O(α(N)) References: https://github.com/atcoder/ac-library/blob/master/atcoder/dsu.hpp https://tumoiyorozu.github.io/single-file-ac-library/document_en/dsu.html """ __slots__ = ["_data_size", "_roots"] def __init__(self, data_size: int) -> None: self._data_size = data_size self._roots = [-1] * data_size def __getitem__(self, x: int) -> int: """Find the group (root) of vertex x in O(α(n)) amortized.""" while self._roots[x] >= 0: x = self._roots[x] return x def __len__(self) -> int: """Count the number of groups (roots).""" return len(self.groups) @property def groups(self) -> List[int]: """Return the set of groups (roots) in O(n).""" return [i for i, r in enumerate(self._roots) if r < 0] def is_connected(self, x: int, y: int) -> bool: """Return whether two vertices x and y are connected in O(α(n)) amortized.""" return self[x] == self[y] def unite(self, x: int, y: int) -> None: """Unite two groups of vertices x and y in O(α(n)) amortized.""" x, y = self[x], self[y] if x == y: return if self._roots[x] > self._roots[y]: x, y = y, x self._roots[x] += self._roots[y] self._roots[y] = x def get_size(self, x: int) -> int: """Return the size of the group where vertex x belongs in O(α(n)) amortized.""" return -self._roots[self[x]] import sys readline = sys.stdin.buffer.readline N, Q = list(map(int, readline().split())) tree = UnionFind(N) res = [] for _ in range(Q): t, u, v = list(map(int, readline().split())) if t: res.append(int(tree.is_connected(u, v))) else: tree.unite(u, v) print(("\n".join(map(str, res))))
class UnionFind: """Union Find (Disjoint Set): O(α(N)) References: https://github.com/atcoder/ac-library/blob/master/atcoder/dsu.hpp https://tumoiyorozu.github.io/single-file-ac-library/document_en/dsu.html """ __slots__ = ["_data_size", "_roots"] def __init__(self, data_size: int) -> None: self._data_size = data_size self._roots = [-1] * data_size def __getitem__(self, x: int) -> int: """Find the group (root) of vertex x in O(α(n)) amortized.""" while self._roots[x] >= 0: x = self._roots[x] return x def is_connected(self, x: int, y: int) -> bool: """Return whether two vertices x and y are connected in O(α(n)) amortized.""" return self[x] == self[y] def unite(self, x: int, y: int) -> None: """Unite two groups of vertices x and y in O(α(n)) amortized.""" x, y = self[x], self[y] if x == y: return if self._roots[x] > self._roots[y]: x, y = y, x self._roots[x] += self._roots[y] self._roots[y] = x import sys readline = sys.stdin.buffer.readline N, Q = list(map(int, readline().split())) tree = UnionFind(N) res = [] for _ in range(Q): t, u, v = list(map(int, readline().split())) if t: res.append(int(tree.is_connected(u, v))) else: tree.unite(u, v) print(("\n".join(map(str, res))))
64
48
1,940
1,451
from typing import List class UnionFind: """Union Find (Disjoint Set): O(α(N)) References: https://github.com/atcoder/ac-library/blob/master/atcoder/dsu.hpp https://tumoiyorozu.github.io/single-file-ac-library/document_en/dsu.html """ __slots__ = ["_data_size", "_roots"] def __init__(self, data_size: int) -> None: self._data_size = data_size self._roots = [-1] * data_size def __getitem__(self, x: int) -> int: """Find the group (root) of vertex x in O(α(n)) amortized.""" while self._roots[x] >= 0: x = self._roots[x] return x def __len__(self) -> int: """Count the number of groups (roots).""" return len(self.groups) @property def groups(self) -> List[int]: """Return the set of groups (roots) in O(n).""" return [i for i, r in enumerate(self._roots) if r < 0] def is_connected(self, x: int, y: int) -> bool: """Return whether two vertices x and y are connected in O(α(n)) amortized.""" return self[x] == self[y] def unite(self, x: int, y: int) -> None: """Unite two groups of vertices x and y in O(α(n)) amortized.""" x, y = self[x], self[y] if x == y: return if self._roots[x] > self._roots[y]: x, y = y, x self._roots[x] += self._roots[y] self._roots[y] = x def get_size(self, x: int) -> int: """Return the size of the group where vertex x belongs in O(α(n)) amortized.""" return -self._roots[self[x]] import sys readline = sys.stdin.buffer.readline N, Q = list(map(int, readline().split())) tree = UnionFind(N) res = [] for _ in range(Q): t, u, v = list(map(int, readline().split())) if t: res.append(int(tree.is_connected(u, v))) else: tree.unite(u, v) print(("\n".join(map(str, res))))
class UnionFind: """Union Find (Disjoint Set): O(α(N)) References: https://github.com/atcoder/ac-library/blob/master/atcoder/dsu.hpp https://tumoiyorozu.github.io/single-file-ac-library/document_en/dsu.html """ __slots__ = ["_data_size", "_roots"] def __init__(self, data_size: int) -> None: self._data_size = data_size self._roots = [-1] * data_size def __getitem__(self, x: int) -> int: """Find the group (root) of vertex x in O(α(n)) amortized.""" while self._roots[x] >= 0: x = self._roots[x] return x def is_connected(self, x: int, y: int) -> bool: """Return whether two vertices x and y are connected in O(α(n)) amortized.""" return self[x] == self[y] def unite(self, x: int, y: int) -> None: """Unite two groups of vertices x and y in O(α(n)) amortized.""" x, y = self[x], self[y] if x == y: return if self._roots[x] > self._roots[y]: x, y = y, x self._roots[x] += self._roots[y] self._roots[y] = x import sys readline = sys.stdin.buffer.readline N, Q = list(map(int, readline().split())) tree = UnionFind(N) res = [] for _ in range(Q): t, u, v = list(map(int, readline().split())) if t: res.append(int(tree.is_connected(u, v))) else: tree.unite(u, v) print(("\n".join(map(str, res))))
false
25
[ "-from typing import List", "-", "-", "- def __len__(self) -> int:", "- \"\"\"Count the number of groups (roots).\"\"\"", "- return len(self.groups)", "-", "- @property", "- def groups(self) -> List[int]:", "- \"\"\"Return the set of groups (roots) in O(n).\"\"\"", ...
false
0.069852
0.057357
1.217849
[ "s195943610", "s796522838" ]
u509661905
p03837
python
s580895703
s008429047
346
270
44,396
41,584
Accepted
Accepted
21.97
#!/usr/bin/env pypy3 import collections import itertools INF = 10 ** 8 UNDEF = -1 def floyd_warshall_undirected(num_vs, edges): n = num_vs dist = [[INF for _ in range(n)] for _ in range(n)] pred = [[UNDEF for _ in range(n)] for _ in range(n)] for u in range(n): dist[u][u] = 0 for (u, v), c in list(edges.items()): dist[u][v] = c dist[v][u] = c pred[u][v] = u pred[v][u] = v for t, u, v in itertools.product(list(range(n)), repeat=3): nl = dist[u][t] + dist[t][v] if nl < dist[u][v]: dist[u][v] = nl pred[u][v] = pred[t][v] return dist, pred def construct_shortest_path(s, t, pred): path = collections.deque() path.appendleft(t) while t != s: t = pred[s][t] path.appendleft(t) return list(path) def main(): n, m = (int(x) for x in input().split()) edges = dict() used = dict() for _ in range(m): a, b, c = (int(x) for x in input().split()) a -= 1 b -= 1 a, b = min(a, b), max(a, b) edges[(a, b)] = c used[(a, b)] = False _, pred = floyd_warshall_undirected(n, edges) for s in range(n): for t in range(s + 1, n): path = construct_shortest_path(s, t, pred) for u, v in zip(path[:-1], path[1:]): u, v = min(u, v), max(u, v) used[(u, v)] = True ans = m - sum(used.values()) print(ans) if __name__ == '__main__': main()
#!/usr/bin/env pypy3 import collections import itertools INF = 10 ** 8 UNDEF = -1 def floyd_warshall(num_vs, edges): n = num_vs dist = [[INF for _ in range(n)] for _ in range(n)] for u in range(n): dist[u][u] = 0 for (u, v), c in list(edges.items()): dist[u][v] = c for t, u, v in itertools.product(list(range(n)), repeat=3): nl = dist[u][t] + dist[t][v] if nl < dist[u][v]: dist[u][v] = nl return dist def main(): n, m = (int(x) for x in input().split()) edges = dict() used = dict() for _ in range(m): a, b, c = (int(x) for x in input().split()) a -= 1 b -= 1 edges[(a, b)] = c edges[(b, a)] = c used[(a, b)] = False dist = floyd_warshall(n, edges) ans = 0 for (u, v), c in list(edges.items()): if u < v: if dist[u][v] != c: ans += 1 print(ans) if __name__ == '__main__': main()
62
46
1,563
1,005
#!/usr/bin/env pypy3 import collections import itertools INF = 10**8 UNDEF = -1 def floyd_warshall_undirected(num_vs, edges): n = num_vs dist = [[INF for _ in range(n)] for _ in range(n)] pred = [[UNDEF for _ in range(n)] for _ in range(n)] for u in range(n): dist[u][u] = 0 for (u, v), c in list(edges.items()): dist[u][v] = c dist[v][u] = c pred[u][v] = u pred[v][u] = v for t, u, v in itertools.product(list(range(n)), repeat=3): nl = dist[u][t] + dist[t][v] if nl < dist[u][v]: dist[u][v] = nl pred[u][v] = pred[t][v] return dist, pred def construct_shortest_path(s, t, pred): path = collections.deque() path.appendleft(t) while t != s: t = pred[s][t] path.appendleft(t) return list(path) def main(): n, m = (int(x) for x in input().split()) edges = dict() used = dict() for _ in range(m): a, b, c = (int(x) for x in input().split()) a -= 1 b -= 1 a, b = min(a, b), max(a, b) edges[(a, b)] = c used[(a, b)] = False _, pred = floyd_warshall_undirected(n, edges) for s in range(n): for t in range(s + 1, n): path = construct_shortest_path(s, t, pred) for u, v in zip(path[:-1], path[1:]): u, v = min(u, v), max(u, v) used[(u, v)] = True ans = m - sum(used.values()) print(ans) if __name__ == "__main__": main()
#!/usr/bin/env pypy3 import collections import itertools INF = 10**8 UNDEF = -1 def floyd_warshall(num_vs, edges): n = num_vs dist = [[INF for _ in range(n)] for _ in range(n)] for u in range(n): dist[u][u] = 0 for (u, v), c in list(edges.items()): dist[u][v] = c for t, u, v in itertools.product(list(range(n)), repeat=3): nl = dist[u][t] + dist[t][v] if nl < dist[u][v]: dist[u][v] = nl return dist def main(): n, m = (int(x) for x in input().split()) edges = dict() used = dict() for _ in range(m): a, b, c = (int(x) for x in input().split()) a -= 1 b -= 1 edges[(a, b)] = c edges[(b, a)] = c used[(a, b)] = False dist = floyd_warshall(n, edges) ans = 0 for (u, v), c in list(edges.items()): if u < v: if dist[u][v] != c: ans += 1 print(ans) if __name__ == "__main__": main()
false
25.806452
[ "-def floyd_warshall_undirected(num_vs, edges):", "+def floyd_warshall(num_vs, edges):", "- pred = [[UNDEF for _ in range(n)] for _ in range(n)]", "- dist[v][u] = c", "- pred[u][v] = u", "- pred[v][u] = v", "- pred[u][v] = pred[t][v]", "- return dist, pred", "-"...
false
0.039949
0.064394
0.620382
[ "s580895703", "s008429047" ]
u731291894
p03645
python
s561779373
s795735422
1,450
920
42,676
38,544
Accepted
Accepted
36.55
# coding: utf-8 from queue import Queue N, M = tuple(map(int, input().split())) graph = [ [] for i in range(N+1)] for i in range(M): a, b = tuple(map(int, input().split())) graph[a].append(b) graph[b].append(a) def is_reach(n): dist = [0 for i in range(N+1)] is_visit = [False for i in range(N+1)] is_visit[1] = True q = Queue() q.put(1) while not q.empty(): v = q.get() for u in graph[v]: if not is_visit[u]: is_visit[u] = True q.put(u) dist[u] = dist[v] + 1 if u == n and dist[u] == 2: return True if dist[u] > 2: return False return False print(("POSSIBLE" if is_reach(N) else "IMPOSSIBLE"))
# coding: utf-8 N, M = tuple(map(int, input().split())) graph = [ [] for i in range(N+1)] for i in range(M): a, b = tuple(map(int, input().split())) graph[a].append(b) graph[b].append(a) res = "IMPOSSIBLE" for i in range(2, N): if 1 in graph[i] and N in graph[i]: res = "POSSIBLE" print(res)
31
16
815
335
# coding: utf-8 from queue import Queue N, M = tuple(map(int, input().split())) graph = [[] for i in range(N + 1)] for i in range(M): a, b = tuple(map(int, input().split())) graph[a].append(b) graph[b].append(a) def is_reach(n): dist = [0 for i in range(N + 1)] is_visit = [False for i in range(N + 1)] is_visit[1] = True q = Queue() q.put(1) while not q.empty(): v = q.get() for u in graph[v]: if not is_visit[u]: is_visit[u] = True q.put(u) dist[u] = dist[v] + 1 if u == n and dist[u] == 2: return True if dist[u] > 2: return False return False print(("POSSIBLE" if is_reach(N) else "IMPOSSIBLE"))
# coding: utf-8 N, M = tuple(map(int, input().split())) graph = [[] for i in range(N + 1)] for i in range(M): a, b = tuple(map(int, input().split())) graph[a].append(b) graph[b].append(a) res = "IMPOSSIBLE" for i in range(2, N): if 1 in graph[i] and N in graph[i]: res = "POSSIBLE" print(res)
false
48.387097
[ "-from queue import Queue", "-", "-", "-", "-def is_reach(n):", "- dist = [0 for i in range(N + 1)]", "- is_visit = [False for i in range(N + 1)]", "- is_visit[1] = True", "- q = Queue()", "- q.put(1)", "- while not q.empty():", "- v = q.get()", "- for u in gr...
false
0.048967
0.046072
1.062852
[ "s561779373", "s795735422" ]
u729972685
p03166
python
s882541278
s760937979
1,114
733
155,140
116,444
Accepted
Accepted
34.2
from sys import stdin, setrecursionlimit from collections import defaultdict input = stdin.readline setrecursionlimit(200000) N, M = list(map(int, input().split())) # d = [0] * (N + 1) adj = defaultdict(set) for _ in range(M): x, y = list(map(int, input().split())) adj[x].add(y) # d[y] += 1 dp = [-1] * (N + 1) def lp(x: 'int') -> 'int': if dp[x] >= 0: return dp[x] else: dp[x] = 0 for y in adj[x]: dp[x] = max(dp[x], lp(y) + 1) return dp[x] print((max(lp(i) for i in range(1, N + 1))))
from sys import stdin, setrecursionlimit from collections import defaultdict input = stdin.readline setrecursionlimit(200000) N, M = list(map(int, input().split())) # d = [0] * (N + 1) adj = defaultdict(list) for _ in range(M): x, y = list(map(int, input().split())) adj[x].append(y) # d[y] += 1 dp = [-1] * (N + 1) def lp(x: 'int') -> 'int': if dp[x] >= 0: return dp[x] else: dp[x] = 0 for y in adj[x]: dp[x] = max(dp[x], lp(y) + 1) return dp[x] print((max(lp(i) for i in range(1, N + 1))))
26
26
568
572
from sys import stdin, setrecursionlimit from collections import defaultdict input = stdin.readline setrecursionlimit(200000) N, M = list(map(int, input().split())) # d = [0] * (N + 1) adj = defaultdict(set) for _ in range(M): x, y = list(map(int, input().split())) adj[x].add(y) # d[y] += 1 dp = [-1] * (N + 1) def lp(x: "int") -> "int": if dp[x] >= 0: return dp[x] else: dp[x] = 0 for y in adj[x]: dp[x] = max(dp[x], lp(y) + 1) return dp[x] print((max(lp(i) for i in range(1, N + 1))))
from sys import stdin, setrecursionlimit from collections import defaultdict input = stdin.readline setrecursionlimit(200000) N, M = list(map(int, input().split())) # d = [0] * (N + 1) adj = defaultdict(list) for _ in range(M): x, y = list(map(int, input().split())) adj[x].append(y) # d[y] += 1 dp = [-1] * (N + 1) def lp(x: "int") -> "int": if dp[x] >= 0: return dp[x] else: dp[x] = 0 for y in adj[x]: dp[x] = max(dp[x], lp(y) + 1) return dp[x] print((max(lp(i) for i in range(1, N + 1))))
false
0
[ "-adj = defaultdict(set)", "+adj = defaultdict(list)", "- adj[x].add(y)", "+ adj[x].append(y)" ]
false
0.041174
0.062631
0.657403
[ "s882541278", "s760937979" ]
u164727245
p02598
python
s157939991
s965392114
240
190
50,932
51,204
Accepted
Accepted
20.83
# coding: utf-8 import numpy as np def solve(*args: str) -> str: n, k = list(map(int, args[0].split())) A = np.array(tuple(map(int, args[1].split()))) l, r = 0, np.max(A) while l+1 < r: m = (l+r)//2 if k < np.sum(-(-A//m)-1): l = m else: r = m return str(r) if __name__ == "__main__": print((solve(*(open(0).read().splitlines()))))
# coding: utf-8 import numpy as np def solve(*args: str) -> str: n, k = list(map(int, args[0].split())) A = np.array(tuple(map(int, args[1].split()))) l, r = 0, np.max(A) while l+1 < r: m = (l+r)//2 if k < np.sum(np.ceil(A/m)-1): l = m else: r = m return str(r) if __name__ == "__main__": print((solve(*(open(0).read().splitlines()))))
21
21
422
426
# coding: utf-8 import numpy as np def solve(*args: str) -> str: n, k = list(map(int, args[0].split())) A = np.array(tuple(map(int, args[1].split()))) l, r = 0, np.max(A) while l + 1 < r: m = (l + r) // 2 if k < np.sum(-(-A // m) - 1): l = m else: r = m return str(r) if __name__ == "__main__": print((solve(*(open(0).read().splitlines()))))
# coding: utf-8 import numpy as np def solve(*args: str) -> str: n, k = list(map(int, args[0].split())) A = np.array(tuple(map(int, args[1].split()))) l, r = 0, np.max(A) while l + 1 < r: m = (l + r) // 2 if k < np.sum(np.ceil(A / m) - 1): l = m else: r = m return str(r) if __name__ == "__main__": print((solve(*(open(0).read().splitlines()))))
false
0
[ "- if k < np.sum(-(-A // m) - 1):", "+ if k < np.sum(np.ceil(A / m) - 1):" ]
false
0.191433
0.767014
0.249582
[ "s157939991", "s965392114" ]
u983918956
p03111
python
s980375689
s096150854
236
67
3,188
3,064
Accepted
Accepted
71.61
import itertools N,A,B,C = list(map(int,input().split())) l = [int(eval(input())) for i in range(N)] inf = float('inf') ans = inf for pair in itertools.product(list(range(4)),repeat=N): mA = 0 ; mB = 0; mC = 0; cnt = 0 for i in range(N): if pair[i] == 1: mA += l[i] cnt += 1 elif pair[i] == 2: mB += l[i] cnt += 1 elif pair[i] == 3: mC += l[i] cnt += 1 if mA*mB*mC == 0:continue cost = abs(mA-A) + abs(mB-B) + abs(mC-C) + (cnt-3)*10 if cost < ans: ans = cost print(ans)
N,A,B,C = list(map(int,input().split())) l = [int(eval(input())) for i in range(N)] inf = float('inf') def dfs(depth=0, a=0, b=0, c=0): if depth == N: if a*b*c != 0: return abs(a-A) + abs(b-B) + abs(c-C) - 30 return inf res0 = dfs(depth+1,a,b,c) res1 = dfs(depth+1,a+l[depth],b,c) + 10 res2 = dfs(depth+1,a,b+l[depth],c) + 10 res3 = dfs(depth+1,a,b,c+l[depth]) + 10 return min([res0,res1,res2,res3]) print((dfs()))
22
16
596
469
import itertools N, A, B, C = list(map(int, input().split())) l = [int(eval(input())) for i in range(N)] inf = float("inf") ans = inf for pair in itertools.product(list(range(4)), repeat=N): mA = 0 mB = 0 mC = 0 cnt = 0 for i in range(N): if pair[i] == 1: mA += l[i] cnt += 1 elif pair[i] == 2: mB += l[i] cnt += 1 elif pair[i] == 3: mC += l[i] cnt += 1 if mA * mB * mC == 0: continue cost = abs(mA - A) + abs(mB - B) + abs(mC - C) + (cnt - 3) * 10 if cost < ans: ans = cost print(ans)
N, A, B, C = list(map(int, input().split())) l = [int(eval(input())) for i in range(N)] inf = float("inf") def dfs(depth=0, a=0, b=0, c=0): if depth == N: if a * b * c != 0: return abs(a - A) + abs(b - B) + abs(c - C) - 30 return inf res0 = dfs(depth + 1, a, b, c) res1 = dfs(depth + 1, a + l[depth], b, c) + 10 res2 = dfs(depth + 1, a, b + l[depth], c) + 10 res3 = dfs(depth + 1, a, b, c + l[depth]) + 10 return min([res0, res1, res2, res3]) print((dfs()))
false
27.272727
[ "-import itertools", "-", "-ans = inf", "-for pair in itertools.product(list(range(4)), repeat=N):", "- mA = 0", "- mB = 0", "- mC = 0", "- cnt = 0", "- for i in range(N):", "- if pair[i] == 1:", "- mA += l[i]", "- cnt += 1", "- elif pair[i]...
false
0.262571
0.056803
4.622488
[ "s980375689", "s096150854" ]
u561083515
p02775
python
s449840390
s168363148
585
479
20,452
20,452
Accepted
Accepted
18.12
import sys input = sys.stdin.readline # たこ焼き器の価値 N = [0] + list(map(int, tuple(input().rstrip("\n")))) # 支払額 Ncopy = N.copy() def main(): # 紙幣の枚数 ans = 0 # 繰り上げ発生時に変更 flag = False for i in range(len(N)-1, 0, -1): # 繰り上げしない場合 if (Ncopy[i] <= 4) or (Ncopy[i] == 5 and N[i-1] <= 4): ans += Ncopy[i] flag = False # 繰り上げする場合 else: Ncopy[i-1] += 1 if not flag: ans += 10 - N[i] else: ans += 9 - N[i] Ncopy[i] = 0 flag = True if Ncopy[0] == 1: ans += 1 print(ans) if __name__ == "__main__": main()
#!/usr/bin/env python3 import sys input = sys.stdin.readline def main(): N = [0] + list(map(int, tuple(input().rstrip("\n")))) Ncopy = N.copy() ans = 0 flag = False for i in range(len(N)-1, 0, -1): if (Ncopy[i] <= 4) or (Ncopy[i] == 5 and N[i-1] <= 4): ans += Ncopy[i] flag = False else: Ncopy[i-1] += 1 if not flag: ans += 10 - N[i] else: ans += 9 - N[i] Ncopy[i] = 0 flag = True if Ncopy[0] == 1: ans += 1 print(ans) if __name__ == "__main__": main()
36
30
719
659
import sys input = sys.stdin.readline # たこ焼き器の価値 N = [0] + list(map(int, tuple(input().rstrip("\n")))) # 支払額 Ncopy = N.copy() def main(): # 紙幣の枚数 ans = 0 # 繰り上げ発生時に変更 flag = False for i in range(len(N) - 1, 0, -1): # 繰り上げしない場合 if (Ncopy[i] <= 4) or (Ncopy[i] == 5 and N[i - 1] <= 4): ans += Ncopy[i] flag = False # 繰り上げする場合 else: Ncopy[i - 1] += 1 if not flag: ans += 10 - N[i] else: ans += 9 - N[i] Ncopy[i] = 0 flag = True if Ncopy[0] == 1: ans += 1 print(ans) if __name__ == "__main__": main()
#!/usr/bin/env python3 import sys input = sys.stdin.readline def main(): N = [0] + list(map(int, tuple(input().rstrip("\n")))) Ncopy = N.copy() ans = 0 flag = False for i in range(len(N) - 1, 0, -1): if (Ncopy[i] <= 4) or (Ncopy[i] == 5 and N[i - 1] <= 4): ans += Ncopy[i] flag = False else: Ncopy[i - 1] += 1 if not flag: ans += 10 - N[i] else: ans += 9 - N[i] Ncopy[i] = 0 flag = True if Ncopy[0] == 1: ans += 1 print(ans) if __name__ == "__main__": main()
false
16.666667
[ "+#!/usr/bin/env python3", "-# たこ焼き器の価値", "-N = [0] + list(map(int, tuple(input().rstrip(\"\\n\"))))", "-# 支払額", "-Ncopy = N.copy()", "- # 紙幣の枚数", "+ N = [0] + list(map(int, tuple(input().rstrip(\"\\n\"))))", "+ Ncopy = N.copy()", "- # 繰り上げ発生時に変更", "- # 繰り上げしない場合", "- #...
false
0.037396
0.068809
0.543472
[ "s449840390", "s168363148" ]
u645855527
p02959
python
s510122268
s472224428
277
105
81,892
97,720
Accepted
Accepted
62.09
n = int(eval(input())) a = list(map(int, input().split())) b = list(map(int, input().split())) total = 0 for i in range(n): if b[i] > a[i]: total += a[i] if b[i]-a[i] > a[i+1]: total += a[i+1] a[i+1] = 0 else: total += b[i] - a[i] a[i+1] -= b[i] - a[i] else: total += b[i] print(total)
N = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) ans = 0 carry = 0 for a, b in zip(A, B): a2 = max(0, a - carry) if a2 < b: ans += a carry = b - a2 else: ans += carry + b carry = 0 ans += min(carry, A[-1]) print(ans)
17
18
384
320
n = int(eval(input())) a = list(map(int, input().split())) b = list(map(int, input().split())) total = 0 for i in range(n): if b[i] > a[i]: total += a[i] if b[i] - a[i] > a[i + 1]: total += a[i + 1] a[i + 1] = 0 else: total += b[i] - a[i] a[i + 1] -= b[i] - a[i] else: total += b[i] print(total)
N = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) ans = 0 carry = 0 for a, b in zip(A, B): a2 = max(0, a - carry) if a2 < b: ans += a carry = b - a2 else: ans += carry + b carry = 0 ans += min(carry, A[-1]) print(ans)
false
5.555556
[ "-n = int(eval(input()))", "-a = list(map(int, input().split()))", "-b = list(map(int, input().split()))", "-total = 0", "-for i in range(n):", "- if b[i] > a[i]:", "- total += a[i]", "- if b[i] - a[i] > a[i + 1]:", "- total += a[i + 1]", "- a[i + 1] = 0", ...
false
0.043285
0.035973
1.203262
[ "s510122268", "s472224428" ]
u987164499
p02767
python
s073400871
s234292587
23
21
2,940
3,064
Accepted
Accepted
8.7
from sys import stdin n = int(stdin.readline().rstrip()) li = list(map(int,stdin.readline().rstrip().split())) mi = 10**10 for i in range(100): point = 0 for j in li: point += (j-i)**2 mi = min(mi,point) print(mi)
N = int(eval(input())) X = list(map(int,input().split())) min_power = 10**10 #どこの座標で集会をするか for i in range(1,101): power = 0 for j in X: power += (j-i)**2 min_power = min(min_power,power) print(min_power)
10
13
242
232
from sys import stdin n = int(stdin.readline().rstrip()) li = list(map(int, stdin.readline().rstrip().split())) mi = 10**10 for i in range(100): point = 0 for j in li: point += (j - i) ** 2 mi = min(mi, point) print(mi)
N = int(eval(input())) X = list(map(int, input().split())) min_power = 10**10 # どこの座標で集会をするか for i in range(1, 101): power = 0 for j in X: power += (j - i) ** 2 min_power = min(min_power, power) print(min_power)
false
23.076923
[ "-from sys import stdin", "-", "-n = int(stdin.readline().rstrip())", "-li = list(map(int, stdin.readline().rstrip().split()))", "-mi = 10**10", "-for i in range(100):", "- point = 0", "- for j in li:", "- point += (j - i) ** 2", "- mi = min(mi, point)", "-print(mi)", "+N = int...
false
0.04244
0.043724
0.97063
[ "s073400871", "s234292587" ]
u038404105
p02684
python
s004058094
s131220017
149
133
32,400
32,328
Accepted
Accepted
10.74
import sys readline = sys.stdin.buffer.readline def main(): n, k = list(map(int, input().split())) a = list(map(int, input().split())) now=1 flg = 0 path = [1] pathcheck ={1} while True: now = a[now-1] flg = flg + 1 if now in pathcheck: flg = -1 path.append(now) break path.append(now) pathcheck.add(now) if flg == k: break if flg == k: print(now) exit() x1 = path.index(now) x2 = len(path)-1 x3 = (k-x1)%(x2-x1) print((path[x1+x3])) if __name__ == '__main__': main()
import sys readline = sys.stdin.buffer.readline def main(): n, k = list(map(int, input().split())) a = list(map(int, input().split())) now=1 flg = 0 path = [1] pathcheck ={1} for i in range(min(k,n)): now = a[now-1] if now in pathcheck: flg = -1 path.append(now) break path.append(now) pathcheck.add(now) if flg == 0: print(now) exit() x1 = path.index(now) x2 = len(path)-1 x3 = (k-x1)%(x2-x1) print((path[x1+x3])) if __name__ == '__main__': main()
35
32
663
613
import sys readline = sys.stdin.buffer.readline def main(): n, k = list(map(int, input().split())) a = list(map(int, input().split())) now = 1 flg = 0 path = [1] pathcheck = {1} while True: now = a[now - 1] flg = flg + 1 if now in pathcheck: flg = -1 path.append(now) break path.append(now) pathcheck.add(now) if flg == k: break if flg == k: print(now) exit() x1 = path.index(now) x2 = len(path) - 1 x3 = (k - x1) % (x2 - x1) print((path[x1 + x3])) if __name__ == "__main__": main()
import sys readline = sys.stdin.buffer.readline def main(): n, k = list(map(int, input().split())) a = list(map(int, input().split())) now = 1 flg = 0 path = [1] pathcheck = {1} for i in range(min(k, n)): now = a[now - 1] if now in pathcheck: flg = -1 path.append(now) break path.append(now) pathcheck.add(now) if flg == 0: print(now) exit() x1 = path.index(now) x2 = len(path) - 1 x3 = (k - x1) % (x2 - x1) print((path[x1 + x3])) if __name__ == "__main__": main()
false
8.571429
[ "- while True:", "+ for i in range(min(k, n)):", "- flg = flg + 1", "- if flg == k:", "- break", "- if flg == k:", "+ if flg == 0:" ]
false
0.083525
0.088102
0.948057
[ "s004058094", "s131220017" ]
u227082700
p03354
python
s383193515
s854271486
694
569
14,008
14,008
Accepted
Accepted
18.01
n,m=list(map(int,input().split())) p=list(map(int,input().split())) ans=0 import sys;sys.setrecursionlimit(10**9) class u():#UnionFind f-根探し u-連結 s-連結? c-要素数 def __init__(self,n):self.n,self.r=[-1]*n,[0]*n def f(self,x): if self.n[x]<0:return x else:self.n[x]=self.f(self.n[x]);return self.n[x] def u(self,x,y): x,y=self.f(x),self.f(y) if x==y:return elif self.r[x]>self.r[y]:self.n[x]+=self.n[y];self.n[y]=x else:self.n[y]+=self.n[x];self.n[x]=y;self.r[y]+=self.r[x]==self.r[y] u=u(n) for i in range(m): a,b=list(map(int,input().split())) u.u(a-1,b-1) for i in range(n): if p[i]==i+1:ans+=1 elif u.f(i)==u.f(p[i]-1):ans+=1 print(ans)
n,m=list(map(int,input().split()));p=list(map(int,input().split()));z=0;import sys;sys.setrecursionlimit(10**9);f=[i for i in range(n)] def r(f,x): if f[x]!=x:f[x]=r(f,f[x]) return f[x] def u(f,a,b): x,y=r(f,a),r(f,b) if x!=y:f[x]=y for i in range(m):a,b=list(map(int,input().split()));u(f,a-1,b-1) for i in range(n):z+=r(f,i)==r(f,p[i]-1) print(z)
22
10
681
353
n, m = list(map(int, input().split())) p = list(map(int, input().split())) ans = 0 import sys sys.setrecursionlimit(10**9) class u: # UnionFind f-根探し u-連結 s-連結? c-要素数 def __init__(self, n): self.n, self.r = [-1] * n, [0] * n def f(self, x): if self.n[x] < 0: return x else: self.n[x] = self.f(self.n[x]) return self.n[x] def u(self, x, y): x, y = self.f(x), self.f(y) if x == y: return elif self.r[x] > self.r[y]: self.n[x] += self.n[y] self.n[y] = x else: self.n[y] += self.n[x] self.n[x] = y self.r[y] += self.r[x] == self.r[y] u = u(n) for i in range(m): a, b = list(map(int, input().split())) u.u(a - 1, b - 1) for i in range(n): if p[i] == i + 1: ans += 1 elif u.f(i) == u.f(p[i] - 1): ans += 1 print(ans)
n, m = list(map(int, input().split())) p = list(map(int, input().split())) z = 0 import sys sys.setrecursionlimit(10**9) f = [i for i in range(n)] def r(f, x): if f[x] != x: f[x] = r(f, f[x]) return f[x] def u(f, a, b): x, y = r(f, a), r(f, b) if x != y: f[x] = y for i in range(m): a, b = list(map(int, input().split())) u(f, a - 1, b - 1) for i in range(n): z += r(f, i) == r(f, p[i] - 1) print(z)
false
54.545455
[ "-ans = 0", "+z = 0", "+f = [i for i in range(n)]", "-class u: # UnionFind f-根探し u-連結 s-連結? c-要素数", "- def __init__(self, n):", "- self.n, self.r = [-1] * n, [0] * n", "-", "- def f(self, x):", "- if self.n[x] < 0:", "- return x", "- else:", "- ...
false
0.047956
0.047976
0.999585
[ "s383193515", "s854271486" ]
u252828980
p02836
python
s053336288
s876455104
19
17
2,940
2,940
Accepted
Accepted
10.53
s = eval(input()) cnt = 0 for i in range(1,len(s)//2+1): if s[i-1] != s[-i]: #print(s[i-1],s[-i]) cnt += 1 print(cnt)
s = eval(input()) cnt = 0 for i in range(len(s)//2): if s[i] != s[-(i+1)]: cnt +=1 print(cnt)
7
6
137
98
s = eval(input()) cnt = 0 for i in range(1, len(s) // 2 + 1): if s[i - 1] != s[-i]: # print(s[i-1],s[-i]) cnt += 1 print(cnt)
s = eval(input()) cnt = 0 for i in range(len(s) // 2): if s[i] != s[-(i + 1)]: cnt += 1 print(cnt)
false
14.285714
[ "-for i in range(1, len(s) // 2 + 1):", "- if s[i - 1] != s[-i]:", "- # print(s[i-1],s[-i])", "+for i in range(len(s) // 2):", "+ if s[i] != s[-(i + 1)]:" ]
false
0.048108
0.047631
1.010014
[ "s053336288", "s876455104" ]
u347640436
p02603
python
s427772168
s054299588
34
31
9,016
9,176
Accepted
Accepted
8.82
N = int(eval(input())) A = list(map(int, input().split())) t = [-1] * (N + 1) t[0] = 1000 for i in range(N): t[i + 1] = max(t[i + 1], t[i]) k = t[i] // A[i] y = t[i] % A[i] for j in range(i + 1, N): t[j + 1] = max(t[j + 1], k * A[j] + y) print((t[N]))
N = int(eval(input())) A = list(map(int, input().split())) t = [-1] * (N + 1) t[0] = 1000 for i in range(N): k = t[i] // A[i] y = t[i] % A[i] for j in range(i, N): t[j + 1] = max(t[j + 1], k * A[j] + y) print((t[N]))
12
11
280
240
N = int(eval(input())) A = list(map(int, input().split())) t = [-1] * (N + 1) t[0] = 1000 for i in range(N): t[i + 1] = max(t[i + 1], t[i]) k = t[i] // A[i] y = t[i] % A[i] for j in range(i + 1, N): t[j + 1] = max(t[j + 1], k * A[j] + y) print((t[N]))
N = int(eval(input())) A = list(map(int, input().split())) t = [-1] * (N + 1) t[0] = 1000 for i in range(N): k = t[i] // A[i] y = t[i] % A[i] for j in range(i, N): t[j + 1] = max(t[j + 1], k * A[j] + y) print((t[N]))
false
8.333333
[ "- t[i + 1] = max(t[i + 1], t[i])", "- for j in range(i + 1, N):", "+ for j in range(i, N):" ]
false
0.038946
0.047206
0.825021
[ "s427772168", "s054299588" ]
u614181788
p02573
python
s284025149
s087465061
777
567
14,736
107,228
Accepted
Accepted
27.03
#UnionFind class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} def __str__(self): return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots()) n,m = list(map(int,input().split())) uf = UnionFind(n+1) for i in range(m): a,b = list(map(int,input().split())) uf.union(a,b) ans = 0 for i in range(1,n+1): ans = max(ans, uf.size(i)) print(ans)
from collections import deque n,m = list(map(int,input().split())) V = [[] for i in range(n+1)] for i in range(m): a,b = list(map(int,input().split())) V[a].append(b) V[b].append(a) reach = [0]*(n+1) ans = 0 for i in range(1,n+1): if reach[i] != 0: pass else: q = deque([]) q.append(i) reach[i] = 1 j = 1 while q: x = q.popleft() for y in V[x]: if reach[y] == 0: reach[y] = 1 q.append(y) j += 1 ans = max(ans, j) print(ans)
60
30
1,419
672
# UnionFind class UnionFind: def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} def __str__(self): return "\n".join("{}: {}".format(r, self.members(r)) for r in self.roots()) n, m = list(map(int, input().split())) uf = UnionFind(n + 1) for i in range(m): a, b = list(map(int, input().split())) uf.union(a, b) ans = 0 for i in range(1, n + 1): ans = max(ans, uf.size(i)) print(ans)
from collections import deque n, m = list(map(int, input().split())) V = [[] for i in range(n + 1)] for i in range(m): a, b = list(map(int, input().split())) V[a].append(b) V[b].append(a) reach = [0] * (n + 1) ans = 0 for i in range(1, n + 1): if reach[i] != 0: pass else: q = deque([]) q.append(i) reach[i] = 1 j = 1 while q: x = q.popleft() for y in V[x]: if reach[y] == 0: reach[y] = 1 q.append(y) j += 1 ans = max(ans, j) print(ans)
false
50
[ "-# UnionFind", "-class UnionFind:", "- def __init__(self, n):", "- self.n = n", "- self.parents = [-1] * n", "-", "- def find(self, x):", "- if self.parents[x] < 0:", "- return x", "- else:", "- self.parents[x] = self.find(self.parents[x])...
false
0.034965
0.035582
0.982649
[ "s284025149", "s087465061" ]
u094191970
p02795
python
s635895371
s972490946
27
17
3,316
2,940
Accepted
Accepted
37.04
h=int(eval(input())) w=int(eval(input())) n=int(eval(input())) if w>=h: if n%w==0: print((n//w)) else: print((n//w+1)) else: if n%h==0: print((n//h)) else: print((n//h+1))
h=int(eval(input())) w=int(eval(input())) n=int(eval(input())) mx=max(h,w) if n%mx==0: print((n//mx)) else: print((n//mx+1))
14
8
171
111
h = int(eval(input())) w = int(eval(input())) n = int(eval(input())) if w >= h: if n % w == 0: print((n // w)) else: print((n // w + 1)) else: if n % h == 0: print((n // h)) else: print((n // h + 1))
h = int(eval(input())) w = int(eval(input())) n = int(eval(input())) mx = max(h, w) if n % mx == 0: print((n // mx)) else: print((n // mx + 1))
false
42.857143
[ "-if w >= h:", "- if n % w == 0:", "- print((n // w))", "- else:", "- print((n // w + 1))", "+mx = max(h, w)", "+if n % mx == 0:", "+ print((n // mx))", "- if n % h == 0:", "- print((n // h))", "- else:", "- print((n // h + 1))", "+ print((n // m...
false
0.036184
0.037145
0.974119
[ "s635895371", "s972490946" ]
u506858457
p02873
python
s661329394
s851944285
402
346
23,336
23,336
Accepted
Accepted
13.93
S=eval(input()) L=[0]*(len(S)+1) #print(L) for i in range(len(S)): if S[i]=='<': L[i+1]=max(L[i+1],L[i]+1) for i in range(len(S)-1,-1,-1): if S[i]=='>': L[i]=max(L[i],L[i+1]+1) print((sum(L)))
S=eval(input()) L=[0]*(len(S)+1) #print(L) for i in range(len(S)): if S[i]=='<': L[i+1]=L[i]+1 for i in range(len(S)-1,-1,-1): if S[i]=='>': L[i]=max(L[i],L[i+1]+1) print((sum(L)))
10
10
205
194
S = eval(input()) L = [0] * (len(S) + 1) # print(L) for i in range(len(S)): if S[i] == "<": L[i + 1] = max(L[i + 1], L[i] + 1) for i in range(len(S) - 1, -1, -1): if S[i] == ">": L[i] = max(L[i], L[i + 1] + 1) print((sum(L)))
S = eval(input()) L = [0] * (len(S) + 1) # print(L) for i in range(len(S)): if S[i] == "<": L[i + 1] = L[i] + 1 for i in range(len(S) - 1, -1, -1): if S[i] == ">": L[i] = max(L[i], L[i + 1] + 1) print((sum(L)))
false
0
[ "- L[i + 1] = max(L[i + 1], L[i] + 1)", "+ L[i + 1] = L[i] + 1" ]
false
0.046254
0.046649
0.991539
[ "s661329394", "s851944285" ]
u494037809
p02659
python
s497502209
s340457995
112
21
27,180
9,100
Accepted
Accepted
81.25
import math import numpy as np # math.floor X = list(input().split()) A = int(X[0]) B = float(X[1]) # s = str(A*B) ans = (A*int(B*100+0.5))//100 print(ans)
a,b = list(map(float,input().split())) a = int(a) b = round(float(b) * 100) print((a*b//100))
12
6
169
94
import math import numpy as np # math.floor X = list(input().split()) A = int(X[0]) B = float(X[1]) # s = str(A*B) ans = (A * int(B * 100 + 0.5)) // 100 print(ans)
a, b = list(map(float, input().split())) a = int(a) b = round(float(b) * 100) print((a * b // 100))
false
50
[ "-import math", "-import numpy as np", "-", "-# math.floor", "-X = list(input().split())", "-A = int(X[0])", "-B = float(X[1])", "-# s = str(A*B)", "-ans = (A * int(B * 100 + 0.5)) // 100", "-print(ans)", "+a, b = list(map(float, input().split()))", "+a = int(a)", "+b = round(float(b) * 100)...
false
0.056436
0.054621
1.033223
[ "s497502209", "s340457995" ]
u695079172
p02762
python
s791959419
s830727751
1,172
1,044
54,312
20,288
Accepted
Accepted
10.92
import sys sys.setrecursionlimit(500000) class UF: #経路圧縮のみのunion find木 def __init__(self,n): self.n = n self.parents = [-1] * (n+1) #1-indexedにするために1個足している self.rnks = [0] * (n+1) def find(self,n): if self.parents[n] < 0: return n else: self.parents[n] = self.find(self.parents[n]) return self.parents[n] def union(self,a,b): a_par = self.find(a) b_par = self.find(b) if a_par == b_par: return if self.rnks[a_par] > self.rnks[b_par]: a_par,b_par = b_par,a_par if self.rnks[a_par] == self.rnks[b_par]: self.rnks[a_par] += 1 self.parents[a_par] += self.parents[b_par] self.parents[b_par] = a_par def length(self,n): par = self.find(n) return abs(self.parents[par]) def is_same(self,a,b): return self.find(a) == self.find(b) def main(): n,m,k = list(map(int,input().split())) uf = UF(n) block_lst = [0 for _ in range(n+1)] friend_lst = [0 for _ in range(n+1)] #友達リスト部分 for i in range(m): a,b = list(map(int,input().split())) friend_lst[a] += 1 friend_lst[b] += 1 uf.union(a,b) #print(friend_lst) #ブロックリスト部分 for i in range(k): c,d = list(map(int,input().split())) if uf.is_same(c,d):#c,dが同じ友達候補グループにない限り、解答には影響しない! block_lst[c] += 1 block_lst[d] += 1 #print(block_lst) #メイン処理 answer = [] for i in range(1,n+1): f_o_f = uf.length(i) answer.append(f_o_f - friend_lst[i] - block_lst[i] - 1) print((" ".join(map(str,answer)))) if __name__ == '__main__': main()
#import sys #sys.setrecursionlimit(500000) マージテクをちゃんとしていればこんなものはいらないはず…… class UF: #経路圧縮+マージテクのunion find木 def __init__(self,n): self.n = n self.parents = [-1] * (n+1) #1-indexedにするために1個足している self.rnks = [0] * (n+1) def find(self,n): if self.parents[n] < 0: return n else: self.parents[n] = self.find(self.parents[n]) return self.parents[n] def union(self,a,b): a_par = self.find(a) b_par = self.find(b) if a_par == b_par: return if self.rnks[a_par] < self.rnks[b_par]: #ランクの高い方の根に低い方の根をつける 逆にしないように……! a_par,b_par = b_par,a_par if self.rnks[a_par] == self.rnks[b_par]: self.rnks[a_par] += 1 self.parents[a_par] += self.parents[b_par] self.parents[b_par] = a_par def length(self,n): par = self.find(n) return abs(self.parents[par]) def is_same(self,a,b): return self.find(a) == self.find(b) def main(): n,m,k = list(map(int,input().split())) uf = UF(n) block_lst = [0 for _ in range(n+1)] friend_lst = [0 for _ in range(n+1)] #友達リスト部分 for i in range(m): a,b = list(map(int,input().split())) friend_lst[a] += 1 friend_lst[b] += 1 uf.union(a,b) #print(friend_lst) #ブロックリスト部分 for i in range(k): c,d = list(map(int,input().split())) if uf.is_same(c,d):#c,dが同じ友達候補グループにない限り、解答には影響しない! block_lst[c] += 1 block_lst[d] += 1 #print(block_lst) #メイン処理 answer = [] for i in range(1,n+1): f_o_f = uf.length(i) answer.append(f_o_f - friend_lst[i] - block_lst[i] - 1) print((" ".join(map(str,answer)))) if __name__ == '__main__': main()
77
76
1,793
1,860
import sys sys.setrecursionlimit(500000) class UF: # 経路圧縮のみのunion find木 def __init__(self, n): self.n = n self.parents = [-1] * (n + 1) # 1-indexedにするために1個足している self.rnks = [0] * (n + 1) def find(self, n): if self.parents[n] < 0: return n else: self.parents[n] = self.find(self.parents[n]) return self.parents[n] def union(self, a, b): a_par = self.find(a) b_par = self.find(b) if a_par == b_par: return if self.rnks[a_par] > self.rnks[b_par]: a_par, b_par = b_par, a_par if self.rnks[a_par] == self.rnks[b_par]: self.rnks[a_par] += 1 self.parents[a_par] += self.parents[b_par] self.parents[b_par] = a_par def length(self, n): par = self.find(n) return abs(self.parents[par]) def is_same(self, a, b): return self.find(a) == self.find(b) def main(): n, m, k = list(map(int, input().split())) uf = UF(n) block_lst = [0 for _ in range(n + 1)] friend_lst = [0 for _ in range(n + 1)] # 友達リスト部分 for i in range(m): a, b = list(map(int, input().split())) friend_lst[a] += 1 friend_lst[b] += 1 uf.union(a, b) # print(friend_lst) # ブロックリスト部分 for i in range(k): c, d = list(map(int, input().split())) if uf.is_same(c, d): # c,dが同じ友達候補グループにない限り、解答には影響しない! block_lst[c] += 1 block_lst[d] += 1 # print(block_lst) # メイン処理 answer = [] for i in range(1, n + 1): f_o_f = uf.length(i) answer.append(f_o_f - friend_lst[i] - block_lst[i] - 1) print((" ".join(map(str, answer)))) if __name__ == "__main__": main()
# import sys # sys.setrecursionlimit(500000) マージテクをちゃんとしていればこんなものはいらないはず…… class UF: # 経路圧縮+マージテクのunion find木 def __init__(self, n): self.n = n self.parents = [-1] * (n + 1) # 1-indexedにするために1個足している self.rnks = [0] * (n + 1) def find(self, n): if self.parents[n] < 0: return n else: self.parents[n] = self.find(self.parents[n]) return self.parents[n] def union(self, a, b): a_par = self.find(a) b_par = self.find(b) if a_par == b_par: return if self.rnks[a_par] < self.rnks[b_par]: # ランクの高い方の根に低い方の根をつける 逆にしないように……! a_par, b_par = b_par, a_par if self.rnks[a_par] == self.rnks[b_par]: self.rnks[a_par] += 1 self.parents[a_par] += self.parents[b_par] self.parents[b_par] = a_par def length(self, n): par = self.find(n) return abs(self.parents[par]) def is_same(self, a, b): return self.find(a) == self.find(b) def main(): n, m, k = list(map(int, input().split())) uf = UF(n) block_lst = [0 for _ in range(n + 1)] friend_lst = [0 for _ in range(n + 1)] # 友達リスト部分 for i in range(m): a, b = list(map(int, input().split())) friend_lst[a] += 1 friend_lst[b] += 1 uf.union(a, b) # print(friend_lst) # ブロックリスト部分 for i in range(k): c, d = list(map(int, input().split())) if uf.is_same(c, d): # c,dが同じ友達候補グループにない限り、解答には影響しない! block_lst[c] += 1 block_lst[d] += 1 # print(block_lst) # メイン処理 answer = [] for i in range(1, n + 1): f_o_f = uf.length(i) answer.append(f_o_f - friend_lst[i] - block_lst[i] - 1) print((" ".join(map(str, answer)))) if __name__ == "__main__": main()
false
1.298701
[ "-import sys", "-", "-sys.setrecursionlimit(500000)", "-", "-", "+# import sys", "+# sys.setrecursionlimit(500000) マージテクをちゃんとしていればこんなものはいらないはず……", "- # 経路圧縮のみのunion find木", "+ # 経路圧縮+マージテクのunion find木", "- if self.rnks[a_par] > self.rnks[b_par]:", "+ if self.rnks[a_par] < sel...
false
0.045948
0.045638
1.006795
[ "s791959419", "s830727751" ]
u773981351
p03944
python
s107466899
s349605242
46
18
3,192
3,064
Accepted
Accepted
60.87
def init_rectangle(w, h): rectangle = [] for x in range(w): x_list = [] for y in range(h): x_list.append(True) rectangle.append(x_list) return rectangle def area(rectangle): count = 0 for i in rectangle: for j in i: if j: count += 1 return count def paint_point(rectangle, w, h, x1, x2, y1, y2): for x in range(x1, x2): for y in range(h): rectangle[x][y] = False for x in range(w): for y in range(y1, y2): rectangle[x][y] = False def paint(rectangle, w, h, points): for x, y, a in points: x1 = x2 = y1 = y2 = 0 if a == 1: x2 = x elif a == 2: x1 = x x2 = w elif a == 3: y2 = y else: y1 = y y2 = h paint_point(rectangle, w, h, x1, x2, y1, y2) if __name__ == '__main__': w, h, n = list(map(int, input().split())) points = [list(map(int, input().split())) for _ in range(n)] rectangle = init_rectangle(w, h) paint(rectangle, w, h, points) print((area(rectangle)))
def area(x2, y2, points): x1 = y1 = 0 for x, y, a in points: if a == 1: x1 = min(max(x1, x), x2) elif a == 2: x2 = max(min(x2, x), x1) elif a == 3: y1 = min(max(y1, y), y2) else: y2 = max(min(y2, y), y1) return (x2 - x1) * (y2 - y1) if __name__ == '__main__': w, h, n = list(map(int, input().split())) points = [list(map(int, input().split())) for _ in range(n)] print((area(w, h, points)))
47
18
1,204
511
def init_rectangle(w, h): rectangle = [] for x in range(w): x_list = [] for y in range(h): x_list.append(True) rectangle.append(x_list) return rectangle def area(rectangle): count = 0 for i in rectangle: for j in i: if j: count += 1 return count def paint_point(rectangle, w, h, x1, x2, y1, y2): for x in range(x1, x2): for y in range(h): rectangle[x][y] = False for x in range(w): for y in range(y1, y2): rectangle[x][y] = False def paint(rectangle, w, h, points): for x, y, a in points: x1 = x2 = y1 = y2 = 0 if a == 1: x2 = x elif a == 2: x1 = x x2 = w elif a == 3: y2 = y else: y1 = y y2 = h paint_point(rectangle, w, h, x1, x2, y1, y2) if __name__ == "__main__": w, h, n = list(map(int, input().split())) points = [list(map(int, input().split())) for _ in range(n)] rectangle = init_rectangle(w, h) paint(rectangle, w, h, points) print((area(rectangle)))
def area(x2, y2, points): x1 = y1 = 0 for x, y, a in points: if a == 1: x1 = min(max(x1, x), x2) elif a == 2: x2 = max(min(x2, x), x1) elif a == 3: y1 = min(max(y1, y), y2) else: y2 = max(min(y2, y), y1) return (x2 - x1) * (y2 - y1) if __name__ == "__main__": w, h, n = list(map(int, input().split())) points = [list(map(int, input().split())) for _ in range(n)] print((area(w, h, points)))
false
61.702128
[ "-def init_rectangle(w, h):", "- rectangle = []", "- for x in range(w):", "- x_list = []", "- for y in range(h):", "- x_list.append(True)", "- rectangle.append(x_list)", "- return rectangle", "-", "-", "-def area(rectangle):", "- count = 0", "- ...
false
0.043665
0.087687
0.497965
[ "s107466899", "s349605242" ]
u374841433
p02755
python
s803396400
s078921968
1,779
313
21,428
20,252
Accepted
Accepted
82.41
import math import numpy as np a,b=[int(v) for v in input().split()] min_8=math.ceil(a/0.08) max_8=(a+1)//0.08 min_10=math.ceil(b/0.1) max_10=(b+1)//0.1 range_8 = np.arange(min_8,max_8+1).astype(int) range_10 = np.arange(min_10,max_10+1).astype(int) try: print((min(np.intersect1d(range_8,range_10)))) except: print((-1))
import math import numpy as np a, b = [int(v) for v in input().split()] try: print((min(np.intersect1d(np.arange(math.ceil(a/0.08), (a+1) //0.08+ 1).astype(int), np.arange(math.ceil(b/0.1), (b+1)//0.1 + 1).astype(int))))) except: print((-1))
18
12
350
262
import math import numpy as np a, b = [int(v) for v in input().split()] min_8 = math.ceil(a / 0.08) max_8 = (a + 1) // 0.08 min_10 = math.ceil(b / 0.1) max_10 = (b + 1) // 0.1 range_8 = np.arange(min_8, max_8 + 1).astype(int) range_10 = np.arange(min_10, max_10 + 1).astype(int) try: print((min(np.intersect1d(range_8, range_10)))) except: print((-1))
import math import numpy as np a, b = [int(v) for v in input().split()] try: print( ( min( np.intersect1d( np.arange(math.ceil(a / 0.08), (a + 1) // 0.08 + 1).astype(int), np.arange(math.ceil(b / 0.1), (b + 1) // 0.1 + 1).astype(int), ) ) ) ) except: print((-1))
false
33.333333
[ "-min_8 = math.ceil(a / 0.08)", "-max_8 = (a + 1) // 0.08", "-min_10 = math.ceil(b / 0.1)", "-max_10 = (b + 1) // 0.1", "-range_8 = np.arange(min_8, max_8 + 1).astype(int)", "-range_10 = np.arange(min_10, max_10 + 1).astype(int)", "- print((min(np.intersect1d(range_8, range_10))))", "+ print(", ...
false
0.250564
0.462915
0.541275
[ "s803396400", "s078921968" ]
u094191970
p03786
python
s327289546
s065968600
848
117
14,512
14,320
Accepted
Accepted
86.2
n=int(eval(input())) a=sorted(list(map(int,input().split()))) ok=n-1 ng=-1 while abs(ok-ng)>1: mid=(ok+ng)//2 inx=mid bool=True sum_mid=sum(a[:mid+1]) while bool and inx!=n-2: if sum_mid*2>=a[inx+1]: sum_mid+=a[inx+1] inx+=1 else: bool=False if bool: ok=mid else: ng=mid print((n-ok))
n=int(eval(input())) a=sorted(list(map(int,input().split()))) ans=1 sum=a[0] for i in range(1,n): if sum*2>=a[i]: ans+=1 else: ans=1 sum+=a[i] print(ans)
26
12
331
166
n = int(eval(input())) a = sorted(list(map(int, input().split()))) ok = n - 1 ng = -1 while abs(ok - ng) > 1: mid = (ok + ng) // 2 inx = mid bool = True sum_mid = sum(a[: mid + 1]) while bool and inx != n - 2: if sum_mid * 2 >= a[inx + 1]: sum_mid += a[inx + 1] inx += 1 else: bool = False if bool: ok = mid else: ng = mid print((n - ok))
n = int(eval(input())) a = sorted(list(map(int, input().split()))) ans = 1 sum = a[0] for i in range(1, n): if sum * 2 >= a[i]: ans += 1 else: ans = 1 sum += a[i] print(ans)
false
53.846154
[ "-ok = n - 1", "-ng = -1", "-while abs(ok - ng) > 1:", "- mid = (ok + ng) // 2", "- inx = mid", "- bool = True", "- sum_mid = sum(a[: mid + 1])", "- while bool and inx != n - 2:", "- if sum_mid * 2 >= a[inx + 1]:", "- sum_mid += a[inx + 1]", "- inx += ...
false
0.041156
0.035028
1.17492
[ "s327289546", "s065968600" ]
u373047809
p03161
python
s325214072
s045021161
366
284
89,940
88,216
Accepted
Accepted
22.4
n, k, *h = list(map(int, open(0).read().split())) h += [0] * 200 dp = [0] + [float("inf")] * 100200 for i in range(1, n): dp[i] = min(dp[i-a] + abs(h[i] - h[i-a]) for a in range(1, k + 1)) print((dp[n - 1]))
n, k, *h = list(map(int, open(0).read().split())) dp = [0] * n for i in range(1, n): dp[i] = min(dp[i-a] + abs(h[i] - h[i-a]) for a in range(1, min(i, k) + 1)) print((dp[n - 1]))
6
5
206
176
n, k, *h = list(map(int, open(0).read().split())) h += [0] * 200 dp = [0] + [float("inf")] * 100200 for i in range(1, n): dp[i] = min(dp[i - a] + abs(h[i] - h[i - a]) for a in range(1, k + 1)) print((dp[n - 1]))
n, k, *h = list(map(int, open(0).read().split())) dp = [0] * n for i in range(1, n): dp[i] = min(dp[i - a] + abs(h[i] - h[i - a]) for a in range(1, min(i, k) + 1)) print((dp[n - 1]))
false
16.666667
[ "-h += [0] * 200", "-dp = [0] + [float(\"inf\")] * 100200", "+dp = [0] * n", "- dp[i] = min(dp[i - a] + abs(h[i] - h[i - a]) for a in range(1, k + 1))", "+ dp[i] = min(dp[i - a] + abs(h[i] - h[i - a]) for a in range(1, min(i, k) + 1))" ]
false
0.047779
0.043748
1.092142
[ "s325214072", "s045021161" ]
u841568901
p02791
python
s527209748
s136396355
158
126
25,768
32,192
Accepted
Accepted
20.25
N = int(eval(input())) P = [int(x) for x in input().split()] R = 1000000 c = 0 for i in range(N): if min(R, P[i])==P[i]: c += 1 R = P[i] else: pass print(c)
N = int(eval(input())) P = list(map(int, input().split())) m = P[0] S = 0 for p in P: if m>=p: S += 1 m = min(m, p) print(S)
11
9
176
134
N = int(eval(input())) P = [int(x) for x in input().split()] R = 1000000 c = 0 for i in range(N): if min(R, P[i]) == P[i]: c += 1 R = P[i] else: pass print(c)
N = int(eval(input())) P = list(map(int, input().split())) m = P[0] S = 0 for p in P: if m >= p: S += 1 m = min(m, p) print(S)
false
18.181818
[ "-P = [int(x) for x in input().split()]", "-R = 1000000", "-c = 0", "-for i in range(N):", "- if min(R, P[i]) == P[i]:", "- c += 1", "- R = P[i]", "- else:", "- pass", "-print(c)", "+P = list(map(int, input().split()))", "+m = P[0]", "+S = 0", "+for p in P:", "...
false
0.039282
0.038892
1.010032
[ "s527209748", "s136396355" ]
u261103969
p02646
python
s134958083
s954749643
61
20
61,700
9,092
Accepted
Accepted
67.21
import sys readline = sys.stdin.buffer.readline MOD = 10 ** 9 + 7 INF = float('INF') sys.setrecursionlimit(10 ** 5) def main(): a, v = list(map(int, readline().split())) b, w = list(map(int, readline().split())) t = int(eval(input())) dist = abs(b - a) vel = v - w if vel * t >= dist: print("YES") else: print("NO") if __name__ == '__main__': main()
a, v = list(map(int, input().split())) b, w = list(map(int, input().split())) t = int(eval(input())) dist = abs(b - a) r_vel = v - w if r_vel * t >= dist: print("YES") else: print("NO")
24
11
410
188
import sys readline = sys.stdin.buffer.readline MOD = 10**9 + 7 INF = float("INF") sys.setrecursionlimit(10**5) def main(): a, v = list(map(int, readline().split())) b, w = list(map(int, readline().split())) t = int(eval(input())) dist = abs(b - a) vel = v - w if vel * t >= dist: print("YES") else: print("NO") if __name__ == "__main__": main()
a, v = list(map(int, input().split())) b, w = list(map(int, input().split())) t = int(eval(input())) dist = abs(b - a) r_vel = v - w if r_vel * t >= dist: print("YES") else: print("NO")
false
54.166667
[ "-import sys", "-", "-readline = sys.stdin.buffer.readline", "-MOD = 10**9 + 7", "-INF = float(\"INF\")", "-sys.setrecursionlimit(10**5)", "-", "-", "-def main():", "- a, v = list(map(int, readline().split()))", "- b, w = list(map(int, readline().split()))", "- t = int(eval(input()))"...
false
0.060428
0.056266
1.073962
[ "s134958083", "s954749643" ]
u353919145
p03127
python
s163029744
s458815692
104
96
14,224
84,100
Accepted
Accepted
7.69
n=int(eval(input())) a=list(map(int,input().split())) def gcd(a,b): while(a%b!=0): a,b=b,a%b return b a=list(sorted(a)) c=gcd(a[0],a[1]) for i in range(2,n): c=gcd(a[i],c) print(c)
import sys input=sys.stdin.buffer.readline from math import* n=int(eval(input())) arr=list(map(int,input().split())) ans=1 if n>2: ans=gcd(arr[0],arr[1]) for i in range(2,n): ans=gcd(ans,arr[i]) else: ans=gcd(arr[0],arr[1]) print(ans)
12
14
207
247
n = int(eval(input())) a = list(map(int, input().split())) def gcd(a, b): while a % b != 0: a, b = b, a % b return b a = list(sorted(a)) c = gcd(a[0], a[1]) for i in range(2, n): c = gcd(a[i], c) print(c)
import sys input = sys.stdin.buffer.readline from math import * n = int(eval(input())) arr = list(map(int, input().split())) ans = 1 if n > 2: ans = gcd(arr[0], arr[1]) for i in range(2, n): ans = gcd(ans, arr[i]) else: ans = gcd(arr[0], arr[1]) print(ans)
false
14.285714
[ "+import sys", "+", "+input = sys.stdin.buffer.readline", "+from math import *", "+", "-a = list(map(int, input().split()))", "-", "-", "-def gcd(a, b):", "- while a % b != 0:", "- a, b = b, a % b", "- return b", "-", "-", "-a = list(sorted(a))", "-c = gcd(a[0], a[1])", ...
false
0.114432
0.007912
14.4638
[ "s163029744", "s458815692" ]
u320567105
p03127
python
s171552382
s124670880
90
57
14,252
14,252
Accepted
Accepted
36.67
N = int(eval(input())) #A = [int(i) for i in input().split()] A = list(map(int,input().split())) def gcp(a,b): if b == 0: return a else: return gcp(b,a%b) a = A[0] for i in range(1,N): a = gcp(a,A[i]) print(a)
eval(input()) A = list(map(int,input().split())) b = min(A) for a in A: while True: if a%b == 0: break a,b = b, a%b print(b)
14
10
246
160
N = int(eval(input())) # A = [int(i) for i in input().split()] A = list(map(int, input().split())) def gcp(a, b): if b == 0: return a else: return gcp(b, a % b) a = A[0] for i in range(1, N): a = gcp(a, A[i]) print(a)
eval(input()) A = list(map(int, input().split())) b = min(A) for a in A: while True: if a % b == 0: break a, b = b, a % b print(b)
false
28.571429
[ "-N = int(eval(input()))", "-# A = [int(i) for i in input().split()]", "+eval(input())", "-", "-", "-def gcp(a, b):", "- if b == 0:", "- return a", "- else:", "- return gcp(b, a % b)", "-", "-", "-a = A[0]", "-for i in range(1, N):", "- a = gcp(a, A[i])", "-print...
false
0.102689
0.112311
0.914325
[ "s171552382", "s124670880" ]
u325282913
p02813
python
s505162204
s152223541
232
85
43,504
74,052
Accepted
Accepted
63.36
import itertools N = int(eval(input())) P = list(map(int, input().split())) Q = list(map(int, input().split())) A = [i for i in range(1,N+1)] count = 1 for i in itertools.permutations(A): flg = True for k in range(N): if i[k] != P[k]: flg = False break if flg: a = count flg = True for k in range(N): if i[k] != Q[k]: flg = False break if flg: b = count count += 1 print((abs(a-b)))
import itertools N = int(eval(input())) P = list(map(int, input().split())) Q = list(map(int, input().split())) a = [i for i in range(1,N+1)] cnt = 0 ans_a, ans_b = 0, 0 for target in itertools.permutations(a): cnt += 1 if list(target) == P: ans_a = cnt if list(target) == Q: ans_b = cnt print((abs(ans_a-ans_b)))
23
14
504
346
import itertools N = int(eval(input())) P = list(map(int, input().split())) Q = list(map(int, input().split())) A = [i for i in range(1, N + 1)] count = 1 for i in itertools.permutations(A): flg = True for k in range(N): if i[k] != P[k]: flg = False break if flg: a = count flg = True for k in range(N): if i[k] != Q[k]: flg = False break if flg: b = count count += 1 print((abs(a - b)))
import itertools N = int(eval(input())) P = list(map(int, input().split())) Q = list(map(int, input().split())) a = [i for i in range(1, N + 1)] cnt = 0 ans_a, ans_b = 0, 0 for target in itertools.permutations(a): cnt += 1 if list(target) == P: ans_a = cnt if list(target) == Q: ans_b = cnt print((abs(ans_a - ans_b)))
false
39.130435
[ "-A = [i for i in range(1, N + 1)]", "-count = 1", "-for i in itertools.permutations(A):", "- flg = True", "- for k in range(N):", "- if i[k] != P[k]:", "- flg = False", "- break", "- if flg:", "- a = count", "- flg = True", "- for k in range(...
false
0.053563
0.127117
0.421369
[ "s505162204", "s152223541" ]