user_id
stringlengths
10
10
problem_id
stringlengths
6
6
language
stringclasses
1 value
submission_id_v0
stringlengths
10
10
submission_id_v1
stringlengths
10
10
cpu_time_v0
int64
10
38.3k
cpu_time_v1
int64
0
24.7k
memory_v0
int64
2.57k
1.02M
memory_v1
int64
2.57k
869k
status_v0
stringclasses
1 value
status_v1
stringclasses
1 value
improvement_frac
float64
7.51
100
input
stringlengths
20
4.55k
target
stringlengths
17
3.34k
code_v0_loc
int64
1
148
code_v1_loc
int64
1
184
code_v0_num_chars
int64
13
4.55k
code_v1_num_chars
int64
14
3.34k
code_v0_no_empty_lines
stringlengths
21
6.88k
code_v1_no_empty_lines
stringlengths
20
4.93k
code_same
bool
1 class
relative_loc_diff_percent
float64
0
79.8
diff
sequence
diff_only_import_comment
bool
1 class
measured_runtime_v0
float64
0.01
4.45
measured_runtime_v1
float64
0.01
4.31
runtime_lift
float64
0
359
key
sequence
u025235255
p03765
python
s887284816
s778909674
1,121
398
65,300
13,464
Accepted
Accepted
64.5
s, t, q = list(eval(input())), list(eval(input())), int(eval(input())) ssum, tsum = [0], [0] for i in range(len(s)): if s[i]=="A": ssum.append(ssum[-1]+1) else: ssum.append(ssum[-1]+2) for i in range(len(t)): if t[i]=="A": tsum.append(tsum[-1]+1) else: tsum.append(tsum[-1]+2) for i in range(q): a,b,c,d = list(map(int,input().split())) sa = (ssum[b]-ssum[a-1])-(tsum[d]-tsum[c-1]) if abs(sa)%3==0:print("YES") else: print("NO")
import sys input = sys.stdin.readline s, t, q = list(eval(input())), list(eval(input())), int(eval(input())) ssum, tsum = [0], [0] for i in range(len(s)): if s[i]=="A": ssum.append(ssum[-1]+1) else: ssum.append(ssum[-1]+2) for i in range(len(t)): if t[i]=="A": tsum.append(tsum[-1]+1) else: tsum.append(tsum[-1]+2) for i in range(q): a,b,c,d = list(map(int,input().split())) sa = (ssum[b]-ssum[a-1])-(tsum[d]-tsum[c-1]) if abs(sa)%3==0:print("YES") else: print("NO")
13
15
448
488
s, t, q = list(eval(input())), list(eval(input())), int(eval(input())) ssum, tsum = [0], [0] for i in range(len(s)): if s[i] == "A": ssum.append(ssum[-1] + 1) else: ssum.append(ssum[-1] + 2) for i in range(len(t)): if t[i] == "A": tsum.append(tsum[-1] + 1) else: tsum.append(tsum[-1] + 2) for i in range(q): a, b, c, d = list(map(int, input().split())) sa = (ssum[b] - ssum[a - 1]) - (tsum[d] - tsum[c - 1]) if abs(sa) % 3 == 0: print("YES") else: print("NO")
import sys input = sys.stdin.readline s, t, q = list(eval(input())), list(eval(input())), int(eval(input())) ssum, tsum = [0], [0] for i in range(len(s)): if s[i] == "A": ssum.append(ssum[-1] + 1) else: ssum.append(ssum[-1] + 2) for i in range(len(t)): if t[i] == "A": tsum.append(tsum[-1] + 1) else: tsum.append(tsum[-1] + 2) for i in range(q): a, b, c, d = list(map(int, input().split())) sa = (ssum[b] - ssum[a - 1]) - (tsum[d] - tsum[c - 1]) if abs(sa) % 3 == 0: print("YES") else: print("NO")
false
13.333333
[ "+import sys", "+", "+input = sys.stdin.readline" ]
false
0.042571
0.054959
0.774597
[ "s887284816", "s778909674" ]
u642874916
p02882
python
s265610367
s161978706
186
169
38,384
38,504
Accepted
Accepted
9.14
import math import os import sys # from fractions import gcd input = sys.stdin.readline sys.setrecursionlimit(2147483647) INF = float("inf") IINF = 10 ** 18 MOD = 10 ** 9 + 7 def main(): a, b, x = list(map(int, input().split())) h = x / float(a ** 2) remain = b - h ans = math.degrees(math.atan2(remain, a/2)) limit = math.degrees(math.atan2(h, a/2)) # limit = x / float(a ** 2) # # limit_degree = math.degrees(math.atan2(limit, a)) # print(limit + h < b) # print(limit) if ans <= limit: print(ans) else: # x = b * a * t / 2 t = 2 * x / (b * a) deg = math.degrees(math.atan2(b, t)) print(deg) if __name__ == '__main__': main()
import math import os import sys # from fractions import gcd input = sys.stdin.readline sys.setrecursionlimit(2147483647) INF = float("inf") IINF = 10 ** 18 MOD = 10 ** 9 + 7 def main(): a, b, x = list(map(int, input().split())) area = x / a h = area / a remain = b - h if h >= b / 2: print((math.degrees(math.atan2(remain, a / 2)))) else: a_dash = (2 * area) / b print((math.degrees(math.atan2(b, a_dash)))) if __name__ == '__main__': main()
35
26
756
521
import math import os import sys # from fractions import gcd input = sys.stdin.readline sys.setrecursionlimit(2147483647) INF = float("inf") IINF = 10**18 MOD = 10**9 + 7 def main(): a, b, x = list(map(int, input().split())) h = x / float(a**2) remain = b - h ans = math.degrees(math.atan2(remain, a / 2)) limit = math.degrees(math.atan2(h, a / 2)) # limit = x / float(a ** 2) # # limit_degree = math.degrees(math.atan2(limit, a)) # print(limit + h < b) # print(limit) if ans <= limit: print(ans) else: # x = b * a * t / 2 t = 2 * x / (b * a) deg = math.degrees(math.atan2(b, t)) print(deg) if __name__ == "__main__": main()
import math import os import sys # from fractions import gcd input = sys.stdin.readline sys.setrecursionlimit(2147483647) INF = float("inf") IINF = 10**18 MOD = 10**9 + 7 def main(): a, b, x = list(map(int, input().split())) area = x / a h = area / a remain = b - h if h >= b / 2: print((math.degrees(math.atan2(remain, a / 2)))) else: a_dash = (2 * area) / b print((math.degrees(math.atan2(b, a_dash)))) if __name__ == "__main__": main()
false
25.714286
[ "- h = x / float(a**2)", "+ area = x / a", "+ h = area / a", "- ans = math.degrees(math.atan2(remain, a / 2))", "- limit = math.degrees(math.atan2(h, a / 2))", "- # limit = x / float(a ** 2)", "- # # limit_degree = math.degrees(math.atan2(limit, a))", "- # print(limit + h < b)", "- # print(limit)", "- if ans <= limit:", "- print(ans)", "+ if h >= b / 2:", "+ print((math.degrees(math.atan2(remain, a / 2))))", "- # x = b * a * t / 2", "- t = 2 * x / (b * a)", "- deg = math.degrees(math.atan2(b, t))", "- print(deg)", "+ a_dash = (2 * area) / b", "+ print((math.degrees(math.atan2(b, a_dash))))" ]
false
0.044528
0.113109
0.393673
[ "s265610367", "s161978706" ]
u620084012
p03679
python
s967306476
s571301977
164
17
38,256
2,940
Accepted
Accepted
89.63
X, A, B = list(map(int,input().split())) if A >= B: print("delicious") elif X+A >= B: print("safe") else: print("dangerous")
X, A, B = list(map(int,input().split())) if B <= A: print("delicious") elif B <= A+X: print("safe") else: print("dangerous")
7
7
137
137
X, A, B = list(map(int, input().split())) if A >= B: print("delicious") elif X + A >= B: print("safe") else: print("dangerous")
X, A, B = list(map(int, input().split())) if B <= A: print("delicious") elif B <= A + X: print("safe") else: print("dangerous")
false
0
[ "-if A >= B:", "+if B <= A:", "-elif X + A >= B:", "+elif B <= A + X:" ]
false
0.103099
0.039443
2.61385
[ "s967306476", "s571301977" ]
u677121387
p02607
python
s151871237
s968960679
32
26
9,160
9,164
Accepted
Accepted
18.75
n = int(eval(input())) a = [int(i) for i in input().split()] ans = 0 for x,i in enumerate(a,1): if x%2 == 1 and i%2 == 1: ans += 1 print(ans)
n = int(eval(input())) a = [int(i) for i in input().split()] ans = 0 for i in range(n): if i%2 == 0 and a[i]%2 == 1: ans += 1 print(ans)
6
6
144
139
n = int(eval(input())) a = [int(i) for i in input().split()] ans = 0 for x, i in enumerate(a, 1): if x % 2 == 1 and i % 2 == 1: ans += 1 print(ans)
n = int(eval(input())) a = [int(i) for i in input().split()] ans = 0 for i in range(n): if i % 2 == 0 and a[i] % 2 == 1: ans += 1 print(ans)
false
0
[ "-for x, i in enumerate(a, 1):", "- if x % 2 == 1 and i % 2 == 1:", "+for i in range(n):", "+ if i % 2 == 0 and a[i] % 2 == 1:" ]
false
0.0428
0.03997
1.070788
[ "s151871237", "s968960679" ]
u648868410
p02588
python
s832234934
s132742291
1,161
415
9,248
74,828
Accepted
Accepted
64.25
N=int(eval(input())) A=[] PRECISION_DIGITS=9 cnt={} for n in range(N): tmpA = float(eval(input())) tmpA = round(tmpA*(10**PRECISION_DIGITS)) #print(tmpA) two = 0 five = 0 while (tmpA % 2) == 0: two += 1 tmpA /= 2 while (tmpA % 5) == 0: five += 1 tmpA /= 5 if (two,five) in cnt: cnt[(two,five)]+=1 else: cnt[(two,five)]=1 keys=sorted(cnt.keys()) # print(keys) ans = 0 for t1 in keys: for t2 in keys: # 2**a(a>=0) and 5**b(b>=0) => integer if 18 <= t1[0]+t2[0] and 18 <= t1[1]+t2[1]: cnt1 = cnt[(t1[0],t1[1])] cnt2 = cnt[(t2[0],t2[1])] if t1 < t2: ans += int(cnt1*cnt2) elif t1 == t2: # same entry # Total number of combinations choose 2 items # nC2 = n*(n-1)/2 ans += int(cnt1*(cnt1-1)/2) print(ans)
N=int(eval(input())) A=[] PRECISION_DIGITS=9 cnt={} for n in range(N): tmpA = float(eval(input())) tmpA = round(tmpA*10**PRECISION_DIGITS) #print(tmpA) five = 0 two = 0 while (tmpA % 2) == 0: two += 1 tmpA //= 2 while (tmpA % 5) == 0: five += 1 tmpA //= 5 # (10**9) -> (two,five)=(9,9) two -= PRECISION_DIGITS five -= PRECISION_DIGITS if (two,five) in cnt: cnt[(two,five)]+=1 else: cnt[(two,five)]=1 # print(cnt) ans = 0 for t1, cnt1 in list(cnt.items()): for t2, cnt2 in list(cnt.items()): # 2**a(a>=0) and 5**b(b>=0) => integer if 0 <= t1[0]+t2[0] and 0 <= t1[1]+t2[1]: if t1 < t2: ans += int(cnt1*cnt2) elif t1 == t2: # same entry # Total number of combinations choose 2 items # nC2 = n*(n-1)/2 ans += int((cnt1*(cnt2-1))/2) print(ans)
45
46
797
824
N = int(eval(input())) A = [] PRECISION_DIGITS = 9 cnt = {} for n in range(N): tmpA = float(eval(input())) tmpA = round(tmpA * (10**PRECISION_DIGITS)) # print(tmpA) two = 0 five = 0 while (tmpA % 2) == 0: two += 1 tmpA /= 2 while (tmpA % 5) == 0: five += 1 tmpA /= 5 if (two, five) in cnt: cnt[(two, five)] += 1 else: cnt[(two, five)] = 1 keys = sorted(cnt.keys()) # print(keys) ans = 0 for t1 in keys: for t2 in keys: # 2**a(a>=0) and 5**b(b>=0) => integer if 18 <= t1[0] + t2[0] and 18 <= t1[1] + t2[1]: cnt1 = cnt[(t1[0], t1[1])] cnt2 = cnt[(t2[0], t2[1])] if t1 < t2: ans += int(cnt1 * cnt2) elif t1 == t2: # same entry # Total number of combinations choose 2 items # nC2 = n*(n-1)/2 ans += int(cnt1 * (cnt1 - 1) / 2) print(ans)
N = int(eval(input())) A = [] PRECISION_DIGITS = 9 cnt = {} for n in range(N): tmpA = float(eval(input())) tmpA = round(tmpA * 10**PRECISION_DIGITS) # print(tmpA) five = 0 two = 0 while (tmpA % 2) == 0: two += 1 tmpA //= 2 while (tmpA % 5) == 0: five += 1 tmpA //= 5 # (10**9) -> (two,five)=(9,9) two -= PRECISION_DIGITS five -= PRECISION_DIGITS if (two, five) in cnt: cnt[(two, five)] += 1 else: cnt[(two, five)] = 1 # print(cnt) ans = 0 for t1, cnt1 in list(cnt.items()): for t2, cnt2 in list(cnt.items()): # 2**a(a>=0) and 5**b(b>=0) => integer if 0 <= t1[0] + t2[0] and 0 <= t1[1] + t2[1]: if t1 < t2: ans += int(cnt1 * cnt2) elif t1 == t2: # same entry # Total number of combinations choose 2 items # nC2 = n*(n-1)/2 ans += int((cnt1 * (cnt2 - 1)) / 2) print(ans)
false
2.173913
[ "- tmpA = round(tmpA * (10**PRECISION_DIGITS))", "+ tmpA = round(tmpA * 10**PRECISION_DIGITS)", "+ five = 0", "- five = 0", "- tmpA /= 2", "+ tmpA //= 2", "- tmpA /= 5", "+ tmpA //= 5", "+ # (10**9) -> (two,five)=(9,9)", "+ two -= PRECISION_DIGITS", "+ five -= PRECISION_DIGITS", "-keys = sorted(cnt.keys())", "-# print(keys)", "+# print(cnt)", "-for t1 in keys:", "- for t2 in keys:", "+for t1, cnt1 in list(cnt.items()):", "+ for t2, cnt2 in list(cnt.items()):", "- if 18 <= t1[0] + t2[0] and 18 <= t1[1] + t2[1]:", "- cnt1 = cnt[(t1[0], t1[1])]", "- cnt2 = cnt[(t2[0], t2[1])]", "+ if 0 <= t1[0] + t2[0] and 0 <= t1[1] + t2[1]:", "- ans += int(cnt1 * (cnt1 - 1) / 2)", "+ ans += int((cnt1 * (cnt2 - 1)) / 2)" ]
false
0.037962
0.038121
0.995816
[ "s832234934", "s132742291" ]
u150984829
p00064
python
s016319183
s350467886
40
20
6,544
5,600
Accepted
Accepted
50
import re,sys print((sum([sum(map(int,re.sub("\D", " ", e).split()))for e in sys.stdin])))
import sys print((sum(map(int,''.join([' ',c][c.isdigit()]for e in sys.stdin for c in e).split()))))
2
2
90
100
import re, sys print((sum([sum(map(int, re.sub("\D", " ", e).split())) for e in sys.stdin])))
import sys print( ( sum( map( int, "".join([" ", c][c.isdigit()] for e in sys.stdin for c in e).split(), ) ) ) )
false
0
[ "-import re, sys", "+import sys", "-print((sum([sum(map(int, re.sub(\"\\D\", \" \", e).split())) for e in sys.stdin])))", "+print(", "+ (", "+ sum(", "+ map(", "+ int,", "+ \"\".join([\" \", c][c.isdigit()] for e in sys.stdin for c in e).split(),", "+ )", "+ )", "+ )", "+)" ]
false
0.053856
0.051941
1.036874
[ "s016319183", "s350467886" ]
u756782069
p02621
python
s310268266
s821064221
32
29
9,048
9,076
Accepted
Accepted
9.38
a = int(eval(input())) b = [3, 14, 39, 84, 155, 258, 399, 584, 819, 1110] print((b[a-1]))
def main(): a = int(eval(input())) print((int(a+a*a+a**3))) if __name__ == "__main__": main()
3
6
83
103
a = int(eval(input())) b = [3, 14, 39, 84, 155, 258, 399, 584, 819, 1110] print((b[a - 1]))
def main(): a = int(eval(input())) print((int(a + a * a + a**3))) if __name__ == "__main__": main()
false
50
[ "-a = int(eval(input()))", "-b = [3, 14, 39, 84, 155, 258, 399, 584, 819, 1110]", "-print((b[a - 1]))", "+def main():", "+ a = int(eval(input()))", "+ print((int(a + a * a + a**3)))", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.044193
0.050402
0.876812
[ "s310268266", "s821064221" ]
u397384480
p02949
python
s493946326
s034983743
1,675
601
75,952
70,304
Accepted
Accepted
64.12
import bisect import collections import copy import functools import heapq import math import sys from collections import deque from collections import defaultdict input = sys.stdin.readline MOD = 10**9+7 N,M,P = list(map(int,(input().split()))) line = [] for i in range(M): a,b,c = list(map(int,(input().split()))) line.append([a-1,b-1,-c+P]) line.sort() min_distance = [float("inf")]*N # min_distance[i] は始点から街iまでの最短距離 min_distance[0] = 0 # 始点から始点への最短距離は0とする update = False for _ in range(N): for s,g,d in line: # [s,g,d] = [道路の始点,道路の終点,道路の長さ] について、すべての道路を見る if min_distance[s] != float("inf") and min_distance[s] + d < min_distance[g]: # 最短経路が確立されている街から伸びる道路を通ることで、距離を短くできるならば、 min_distance[g] = min_distance[s] + d # 最短距離を上書きする update = True if not update: break else: for _ in range(N): for s,g,d in line: # [s,g,d] = [道路の始点,道路の終点,道路の長さ] について、すべての道路を見る if min_distance[s] != float("inf") and min_distance[s] + d < min_distance[g]: # 最短経路が確立されている街から伸びる道路を通ることで、距離を短くできるならば、 min_distance[g] = -float("inf") if g == N-1: print((-1)) exit() print((max(-min_distance[N-1],0))) #print(min_distance)
import bisect import collections import copy import functools import heapq import math import sys from collections import deque from collections import defaultdict input = sys.stdin.readline MOD = 10**9+7 INF = float("inf") N,M,P = list(map(int,(input().split()))) line = [] for i in range(M): a,b,c = list(map(int,(input().split()))) line.append([a-1,b-1,-c+P]) min_distance = [INF]*N # min_distance[i] は始点から街iまでの最短距離 min_distance[0] = 0 # 始点から始点への最短距離は0とする def Bellman_Ford(S,V,E,distance): flag = 0 for _ in range(V): update = False for s,g,d in distance: # [s,g,d] = [道路の始点,道路の終点,道路の長さ] について、すべての道路を見る if min_distance[s] != INF and min_distance[s] + d < min_distance[g]: # 最短経路が確立されている街から伸びる道路を通ることで、距離を短くできるならば、 min_distance[g] = min_distance[s] + d # 最短距離を上書きする update = True if not update: flag = 1 break return min_distance,flag def Bellman_Ford2(S,V,E,distance): for _ in range(V): for s,g,d in distance: # [s,g,d] = [道路の始点,道路の終点,道路の長さ] について、すべての道路を見る if min_distance[s] != INF and min_distance[s] + d < min_distance[g]: # 最短経路が確立されている街から伸びる道路を通ることで、距離を短くできるならば、 min_distance[g] = -INF if g == N-1: break else: continue break return min_distance min_distance,flag = Bellman_Ford(1,N,M,line) if flag == 1: ans = min_distance[N-1] print((max(-ans,0))) else: min_distance = Bellman_Ford2(1,N,M,line) ans = min_distance[N-1] if ans == -INF: print((-1)) else: print((max(-ans,0))) #print(min_distance)
42
61
1,279
1,714
import bisect import collections import copy import functools import heapq import math import sys from collections import deque from collections import defaultdict input = sys.stdin.readline MOD = 10**9 + 7 N, M, P = list(map(int, (input().split()))) line = [] for i in range(M): a, b, c = list(map(int, (input().split()))) line.append([a - 1, b - 1, -c + P]) line.sort() min_distance = [float("inf")] * N # min_distance[i] は始点から街iまでの最短距離 min_distance[0] = 0 # 始点から始点への最短距離は0とする update = False for _ in range(N): for s, g, d in line: # [s,g,d] = [道路の始点,道路の終点,道路の長さ] について、すべての道路を見る if ( min_distance[s] != float("inf") and min_distance[s] + d < min_distance[g] ): # 最短経路が確立されている街から伸びる道路を通ることで、距離を短くできるならば、 min_distance[g] = min_distance[s] + d # 最短距離を上書きする update = True if not update: break else: for _ in range(N): for s, g, d in line: # [s,g,d] = [道路の始点,道路の終点,道路の長さ] について、すべての道路を見る if ( min_distance[s] != float("inf") and min_distance[s] + d < min_distance[g] ): # 最短経路が確立されている街から伸びる道路を通ることで、距離を短くできるならば、 min_distance[g] = -float("inf") if g == N - 1: print((-1)) exit() print((max(-min_distance[N - 1], 0))) # print(min_distance)
import bisect import collections import copy import functools import heapq import math import sys from collections import deque from collections import defaultdict input = sys.stdin.readline MOD = 10**9 + 7 INF = float("inf") N, M, P = list(map(int, (input().split()))) line = [] for i in range(M): a, b, c = list(map(int, (input().split()))) line.append([a - 1, b - 1, -c + P]) min_distance = [INF] * N # min_distance[i] は始点から街iまでの最短距離 min_distance[0] = 0 # 始点から始点への最短距離は0とする def Bellman_Ford(S, V, E, distance): flag = 0 for _ in range(V): update = False for s, g, d in distance: # [s,g,d] = [道路の始点,道路の終点,道路の長さ] について、すべての道路を見る if ( min_distance[s] != INF and min_distance[s] + d < min_distance[g] ): # 最短経路が確立されている街から伸びる道路を通ることで、距離を短くできるならば、 min_distance[g] = min_distance[s] + d # 最短距離を上書きする update = True if not update: flag = 1 break return min_distance, flag def Bellman_Ford2(S, V, E, distance): for _ in range(V): for s, g, d in distance: # [s,g,d] = [道路の始点,道路の終点,道路の長さ] について、すべての道路を見る if ( min_distance[s] != INF and min_distance[s] + d < min_distance[g] ): # 最短経路が確立されている街から伸びる道路を通ることで、距離を短くできるならば、 min_distance[g] = -INF if g == N - 1: break else: continue break return min_distance min_distance, flag = Bellman_Ford(1, N, M, line) if flag == 1: ans = min_distance[N - 1] print((max(-ans, 0))) else: min_distance = Bellman_Ford2(1, N, M, line) ans = min_distance[N - 1] if ans == -INF: print((-1)) else: print((max(-ans, 0))) # print(min_distance)
false
31.147541
[ "+INF = float(\"inf\")", "-line.sort()", "-min_distance = [float(\"inf\")] * N # min_distance[i] は始点から街iまでの最短距離", "+min_distance = [INF] * N # min_distance[i] は始点から街iまでの最短距離", "-update = False", "-for _ in range(N):", "- for s, g, d in line: # [s,g,d] = [道路の始点,道路の終点,道路の長さ] について、すべての道路を見る", "- if (", "- min_distance[s] != float(\"inf\") and min_distance[s] + d < min_distance[g]", "- ): # 最短経路が確立されている街から伸びる道路を通ることで、距離を短くできるならば、", "- min_distance[g] = min_distance[s] + d # 最短距離を上書きする", "- update = True", "- if not update:", "+", "+", "+def Bellman_Ford(S, V, E, distance):", "+ flag = 0", "+ for _ in range(V):", "+ update = False", "+ for s, g, d in distance: # [s,g,d] = [道路の始点,道路の終点,道路の長さ] について、すべての道路を見る", "+ if (", "+ min_distance[s] != INF and min_distance[s] + d < min_distance[g]", "+ ): # 最短経路が確立されている街から伸びる道路を通ることで、距離を短くできるならば、", "+ min_distance[g] = min_distance[s] + d # 最短距離を上書きする", "+ update = True", "+ if not update:", "+ flag = 1", "+ break", "+ return min_distance, flag", "+", "+", "+def Bellman_Ford2(S, V, E, distance):", "+ for _ in range(V):", "+ for s, g, d in distance: # [s,g,d] = [道路の始点,道路の終点,道路の長さ] について、すべての道路を見る", "+ if (", "+ min_distance[s] != INF and min_distance[s] + d < min_distance[g]", "+ ): # 最短経路が確立されている街から伸びる道路を通ることで、距離を短くできるならば、", "+ min_distance[g] = -INF", "+ if g == N - 1:", "+ break", "+ else:", "+ continue", "+ return min_distance", "+", "+", "+min_distance, flag = Bellman_Ford(1, N, M, line)", "+if flag == 1:", "+ ans = min_distance[N - 1]", "+ print((max(-ans, 0)))", "- for _ in range(N):", "- for s, g, d in line: # [s,g,d] = [道路の始点,道路の終点,道路の長さ] について、すべての道路を見る", "- if (", "- min_distance[s] != float(\"inf\")", "- and min_distance[s] + d < min_distance[g]", "- ): # 最短経路が確立されている街から伸びる道路を通ることで、距離を短くできるならば、", "- min_distance[g] = -float(\"inf\")", "- if g == N - 1:", "- print((-1))", "- exit()", "-print((max(-min_distance[N - 1], 0)))", "+ min_distance = Bellman_Ford2(1, N, M, line)", "+ ans = min_distance[N - 1]", "+ if ans == -INF:", "+ print((-1))", "+ else:", "+ print((max(-ans, 0)))" ]
false
0.035745
0.045487
0.785827
[ "s493946326", "s034983743" ]
u970197315
p03127
python
s664535009
s523622667
229
121
16,300
16,240
Accepted
Accepted
47.16
# ABC118 C - Monsters Battle Royale from fractions import gcd n = int(eval(input())) a = list(map(int,input().split())) ans = 10**10 for i in range(n-1): t = gcd(a[i],a[i+1]) ans = min(ans,t) print(ans)
from fractions import gcd n=int(eval(input())) a=list(map(int,input().split())) ans=10**18 t=0 for i in range(1,n): if i==1: t=gcd(a[0],a[1]) ans=min(ans,t) continue t=gcd(t,a[i]) ans=min(t,ans) print(ans)
11
14
217
232
# ABC118 C - Monsters Battle Royale from fractions import gcd n = int(eval(input())) a = list(map(int, input().split())) ans = 10**10 for i in range(n - 1): t = gcd(a[i], a[i + 1]) ans = min(ans, t) print(ans)
from fractions import gcd n = int(eval(input())) a = list(map(int, input().split())) ans = 10**18 t = 0 for i in range(1, n): if i == 1: t = gcd(a[0], a[1]) ans = min(ans, t) continue t = gcd(t, a[i]) ans = min(t, ans) print(ans)
false
21.428571
[ "-# ABC118 C - Monsters Battle Royale", "-ans = 10**10", "-for i in range(n - 1):", "- t = gcd(a[i], a[i + 1])", "- ans = min(ans, t)", "+ans = 10**18", "+t = 0", "+for i in range(1, n):", "+ if i == 1:", "+ t = gcd(a[0], a[1])", "+ ans = min(ans, t)", "+ continue", "+ t = gcd(t, a[i])", "+ ans = min(t, ans)" ]
false
0.050614
0.055486
0.912188
[ "s664535009", "s523622667" ]
u341087021
p03212
python
s206465452
s084693562
97
71
3,060
5,492
Accepted
Accepted
26.8
n = int(eval(input())) def nngg(m): if int(m) > n: return 0 ret = 1 if all(m.count(s)>0 for s in '375') else 0 for s in '357': ret += nngg(m+s) return ret print((nngg('0')))
n = int(eval(input())) tmpl = [['']] l = [] for i in range(1,10): #iは桁数 tmp = [] for x in tmpl[-1]: for s in '357': tmp.append(x+s) tmpl.append(tmp) l = l + tmp def check(s): if all(s.count(x) for x in '357'): return True else: return False ans = 0 for x in l: if int(x) <= n: if check(x): ans += 1 else: break print(ans)
11
28
209
446
n = int(eval(input())) def nngg(m): if int(m) > n: return 0 ret = 1 if all(m.count(s) > 0 for s in "375") else 0 for s in "357": ret += nngg(m + s) return ret print((nngg("0")))
n = int(eval(input())) tmpl = [[""]] l = [] for i in range(1, 10): # iは桁数 tmp = [] for x in tmpl[-1]: for s in "357": tmp.append(x + s) tmpl.append(tmp) l = l + tmp def check(s): if all(s.count(x) for x in "357"): return True else: return False ans = 0 for x in l: if int(x) <= n: if check(x): ans += 1 else: break print(ans)
false
60.714286
[ "+tmpl = [[\"\"]]", "+l = []", "+for i in range(1, 10):", "+ # iは桁数", "+ tmp = []", "+ for x in tmpl[-1]:", "+ for s in \"357\":", "+ tmp.append(x + s)", "+ tmpl.append(tmp)", "+ l = l + tmp", "-def nngg(m):", "- if int(m) > n:", "- return 0", "- ret = 1 if all(m.count(s) > 0 for s in \"375\") else 0", "- for s in \"357\":", "- ret += nngg(m + s)", "- return ret", "+def check(s):", "+ if all(s.count(x) for x in \"357\"):", "+ return True", "+ else:", "+ return False", "-print((nngg(\"0\")))", "+ans = 0", "+for x in l:", "+ if int(x) <= n:", "+ if check(x):", "+ ans += 1", "+ else:", "+ break", "+print(ans)" ]
false
0.050412
0.056815
0.887305
[ "s206465452", "s084693562" ]
u077291787
p03807
python
s935200099
s577515015
54
42
14,232
14,232
Accepted
Accepted
22.22
# AGC010A - Addition def main(): n = int(eval(input())) A = tuple(map(int, input().rstrip().split())) flg = sum(i % 2 == 1 for i in A) % 2 == 0 print(("YES" if flg else "NO")) if __name__ == "__main__": main()
# AGC010A - Addition def main(): n = int(eval(input())) A = tuple(map(int, input().rstrip().split())) print(("YES" if sum(A) % 2 == 0 else "NO")) if __name__ == "__main__": main()
10
9
232
197
# AGC010A - Addition def main(): n = int(eval(input())) A = tuple(map(int, input().rstrip().split())) flg = sum(i % 2 == 1 for i in A) % 2 == 0 print(("YES" if flg else "NO")) if __name__ == "__main__": main()
# AGC010A - Addition def main(): n = int(eval(input())) A = tuple(map(int, input().rstrip().split())) print(("YES" if sum(A) % 2 == 0 else "NO")) if __name__ == "__main__": main()
false
10
[ "- flg = sum(i % 2 == 1 for i in A) % 2 == 0", "- print((\"YES\" if flg else \"NO\"))", "+ print((\"YES\" if sum(A) % 2 == 0 else \"NO\"))" ]
false
0.041418
0.076913
0.538506
[ "s935200099", "s577515015" ]
u017810624
p02863
python
s449142993
s821593217
680
481
192,392
121,052
Accepted
Accepted
29.26
import sys input=sys.stdin.readline import copy def knapsack(N,W,weight,value): dp=[[999999999999 for i in range(W+1)] for j in range(N+1)] dp2=[[0 for i in range(W+1)] for j in range(N+1)] for i in range(W+1): dp[0][i]=0 for i in range(N): for w in range(W+1): if weight[i]<=w: if dp[i][w-weight[i]]+value[i]>dp[i][w]: dp[i+1][w]=dp[i][w-weight[i]]+value[i] dp2[i+1][w]=w-weight[i] else: dp[i+1][w]=dp[i][w] dp2[i+1][w]=w else: dp[i+1][w]=dp[i][w] dp2[i+1][w]=w l=[] x=W for i in range(n-1,-1,-1): if dp2[i+1][x]==x-weight[i]: l.append(i) x=dp2[i+1][x] return dp[N][W],l n,t=list(map(int,input().split())) l=[list(map(int,input().split())) for i in range(n)] a=[];b=[] for i in range(n): a.append(l[i][0]) b.append(l[i][1]) z=knapsack(n,t-1,a,b) L=[0]*n for i in range(len(z[1])): L[z[1][i]]=1 M=[] for i in range(n): if L[i]==0: M.append(l[i][1]) if len(M)==0: print((z[0])) else: print((z[0]+max(M)))
import sys input=sys.stdin.readline def knapsack(N,W,weight,value): dp=[[999999999999 for i in range(W+1)] for j in range(N+1)] for i in range(W+1): dp[0][i]=0 for i in range(N): for w in range(W+1): if weight[i]<=w: if dp[i][w-weight[i]]+value[i]>dp[i][w]: dp[i+1][w]=dp[i][w-weight[i]]+value[i] else: dp[i+1][w]=dp[i][w] else: dp[i+1][w]=dp[i][w] return dp n,t=list(map(int,input().split())) l=[list(map(int,input().split())) for i in range(n)] l.sort() a=[];b=[] for i in range(n): a.append(l[i][0]) b.append(l[i][1]) dp=knapsack(n,t-1,a,b) ans=[] for i in range(n): if i!=n: ans.append(dp[i][t-1]+b[i]) else: ans.append(dp[n][t]) print((max(ans)))
48
33
1,090
767
import sys input = sys.stdin.readline import copy def knapsack(N, W, weight, value): dp = [[999999999999 for i in range(W + 1)] for j in range(N + 1)] dp2 = [[0 for i in range(W + 1)] for j in range(N + 1)] for i in range(W + 1): dp[0][i] = 0 for i in range(N): for w in range(W + 1): if weight[i] <= w: if dp[i][w - weight[i]] + value[i] > dp[i][w]: dp[i + 1][w] = dp[i][w - weight[i]] + value[i] dp2[i + 1][w] = w - weight[i] else: dp[i + 1][w] = dp[i][w] dp2[i + 1][w] = w else: dp[i + 1][w] = dp[i][w] dp2[i + 1][w] = w l = [] x = W for i in range(n - 1, -1, -1): if dp2[i + 1][x] == x - weight[i]: l.append(i) x = dp2[i + 1][x] return dp[N][W], l n, t = list(map(int, input().split())) l = [list(map(int, input().split())) for i in range(n)] a = [] b = [] for i in range(n): a.append(l[i][0]) b.append(l[i][1]) z = knapsack(n, t - 1, a, b) L = [0] * n for i in range(len(z[1])): L[z[1][i]] = 1 M = [] for i in range(n): if L[i] == 0: M.append(l[i][1]) if len(M) == 0: print((z[0])) else: print((z[0] + max(M)))
import sys input = sys.stdin.readline def knapsack(N, W, weight, value): dp = [[999999999999 for i in range(W + 1)] for j in range(N + 1)] for i in range(W + 1): dp[0][i] = 0 for i in range(N): for w in range(W + 1): if weight[i] <= w: if dp[i][w - weight[i]] + value[i] > dp[i][w]: dp[i + 1][w] = dp[i][w - weight[i]] + value[i] else: dp[i + 1][w] = dp[i][w] else: dp[i + 1][w] = dp[i][w] return dp n, t = list(map(int, input().split())) l = [list(map(int, input().split())) for i in range(n)] l.sort() a = [] b = [] for i in range(n): a.append(l[i][0]) b.append(l[i][1]) dp = knapsack(n, t - 1, a, b) ans = [] for i in range(n): if i != n: ans.append(dp[i][t - 1] + b[i]) else: ans.append(dp[n][t]) print((max(ans)))
false
31.25
[ "-import copy", "- dp2 = [[0 for i in range(W + 1)] for j in range(N + 1)]", "- dp2[i + 1][w] = w - weight[i]", "- dp2[i + 1][w] = w", "- dp2[i + 1][w] = w", "- l = []", "- x = W", "- for i in range(n - 1, -1, -1):", "- if dp2[i + 1][x] == x - weight[i]:", "- l.append(i)", "- x = dp2[i + 1][x]", "- return dp[N][W], l", "+ return dp", "+l.sort()", "-z = knapsack(n, t - 1, a, b)", "-L = [0] * n", "-for i in range(len(z[1])):", "- L[z[1][i]] = 1", "-M = []", "+dp = knapsack(n, t - 1, a, b)", "+ans = []", "- if L[i] == 0:", "- M.append(l[i][1])", "-if len(M) == 0:", "- print((z[0]))", "-else:", "- print((z[0] + max(M)))", "+ if i != n:", "+ ans.append(dp[i][t - 1] + b[i])", "+ else:", "+ ans.append(dp[n][t])", "+print((max(ans)))" ]
false
0.100637
0.033277
3.024178
[ "s449142993", "s821593217" ]
u716530146
p03044
python
s558265686
s383065334
756
615
52,268
52,336
Accepted
Accepted
18.65
#!/usr/bin/env python3 n=int(eval(input())) uvw=[list(map(int,input().split())) for i in range(n-1)] graph=[[] for i in range(n+1)] color=[-1]*(n+1) for u,v,w in uvw: graph[u].append((v,w)) graph[v].append((u,w)) color[1]=1 ne=[1] while ne: t=ne.pop() for v,w in graph[t]: if color[v]==-1: ne.append(v) color[v]=color[t] if w%2==0 else (color[t]+1)%2 for i in range(1,n+1): print((color[i]))
#!/usr/bin/env python3 import sys input = lambda: sys.stdin.readline()[:-1] sys.setrecursionlimit(10**8) n = int(eval(input())) uvw = [list(map(int, input().split())) for i in range(n-1)] graph = [[] for i in range(n+1)] color = [-1]*(n+1) for u, v, w in uvw: graph[u].append((v, w)) graph[v].append((u, w)) color[1] = 1 ne = [1] while ne: t = ne.pop() for v, w in graph[t]: if color[v] == -1: ne.append(v) color[v] = color[t] if w % 2 == 0 else (color[t]+1) % 2 for i in range(1, n+1): print((color[i]))
20
25
456
577
#!/usr/bin/env python3 n = int(eval(input())) uvw = [list(map(int, input().split())) for i in range(n - 1)] graph = [[] for i in range(n + 1)] color = [-1] * (n + 1) for u, v, w in uvw: graph[u].append((v, w)) graph[v].append((u, w)) color[1] = 1 ne = [1] while ne: t = ne.pop() for v, w in graph[t]: if color[v] == -1: ne.append(v) color[v] = color[t] if w % 2 == 0 else (color[t] + 1) % 2 for i in range(1, n + 1): print((color[i]))
#!/usr/bin/env python3 import sys input = lambda: sys.stdin.readline()[:-1] sys.setrecursionlimit(10**8) n = int(eval(input())) uvw = [list(map(int, input().split())) for i in range(n - 1)] graph = [[] for i in range(n + 1)] color = [-1] * (n + 1) for u, v, w in uvw: graph[u].append((v, w)) graph[v].append((u, w)) color[1] = 1 ne = [1] while ne: t = ne.pop() for v, w in graph[t]: if color[v] == -1: ne.append(v) color[v] = color[t] if w % 2 == 0 else (color[t] + 1) % 2 for i in range(1, n + 1): print((color[i]))
false
20
[ "+import sys", "+", "+input = lambda: sys.stdin.readline()[:-1]", "+sys.setrecursionlimit(10**8)" ]
false
0.094351
0.123396
0.764614
[ "s558265686", "s383065334" ]
u244416763
p02731
python
s932363941
s466524764
58
16
5,588
2,940
Accepted
Accepted
72.41
import decimal l = int(eval(input())) print(((l/3)**3))
print(((int(eval(input()))/3)**3))
3
1
49
26
import decimal l = int(eval(input())) print(((l / 3) ** 3))
print(((int(eval(input())) / 3) ** 3))
false
66.666667
[ "-import decimal", "-", "-l = int(eval(input()))", "-print(((l / 3) ** 3))", "+print(((int(eval(input())) / 3) ** 3))" ]
false
0.058683
0.171779
0.341621
[ "s932363941", "s466524764" ]
u296150111
p02695
python
s233331030
s915975235
1,440
786
9,136
16,132
Accepted
Accepted
45.42
n,m,q=list(map(int,input().split())) abcd=[] for _ in range(q): a,b,c,d=list(map(int,input().split())) abcd.append((a,b,c,d)) ans=0 import itertools p=itertools.combinations_with_replacement(list(range(1,m+1)),n) for x in p: r=0 for i in range(q): if x[abcd[i][1]-1]-x[abcd[i][0]-1]==abcd[i][2]: r+=abcd[i][3] ans=max(ans,r) print(ans)
n,m,q=list(map(int,input().split())) abcd=[] for _ in range(q): a,b,c,d=list(map(int,input().split())) abcd.append((a,b,c,d)) ans=0 p=[] import sys sys.setrecursionlimit(10**6) def dfs(x): if len(x)==n: p.append(x) else: for i in range(m-x[-1]+1): dfs(x+[x[-1]+i]) dfs([1]) # import itertools # p=itertools.combinations_with_replacement(range(1,m+1),n) for x in p: r=0 for i in range(q): if x[abcd[i][1]-1]-x[abcd[i][0]-1]==abcd[i][2]: r+=abcd[i][3] ans=max(ans,r) print(ans)
15
25
341
506
n, m, q = list(map(int, input().split())) abcd = [] for _ in range(q): a, b, c, d = list(map(int, input().split())) abcd.append((a, b, c, d)) ans = 0 import itertools p = itertools.combinations_with_replacement(list(range(1, m + 1)), n) for x in p: r = 0 for i in range(q): if x[abcd[i][1] - 1] - x[abcd[i][0] - 1] == abcd[i][2]: r += abcd[i][3] ans = max(ans, r) print(ans)
n, m, q = list(map(int, input().split())) abcd = [] for _ in range(q): a, b, c, d = list(map(int, input().split())) abcd.append((a, b, c, d)) ans = 0 p = [] import sys sys.setrecursionlimit(10**6) def dfs(x): if len(x) == n: p.append(x) else: for i in range(m - x[-1] + 1): dfs(x + [x[-1] + i]) dfs([1]) # import itertools # p=itertools.combinations_with_replacement(range(1,m+1),n) for x in p: r = 0 for i in range(q): if x[abcd[i][1] - 1] - x[abcd[i][0] - 1] == abcd[i][2]: r += abcd[i][3] ans = max(ans, r) print(ans)
false
40
[ "-import itertools", "+p = []", "+import sys", "-p = itertools.combinations_with_replacement(list(range(1, m + 1)), n)", "+sys.setrecursionlimit(10**6)", "+", "+", "+def dfs(x):", "+ if len(x) == n:", "+ p.append(x)", "+ else:", "+ for i in range(m - x[-1] + 1):", "+ dfs(x + [x[-1] + i])", "+", "+", "+dfs([1])", "+# import itertools", "+# p=itertools.combinations_with_replacement(range(1,m+1),n)" ]
false
0.045718
0.080301
0.569334
[ "s233331030", "s915975235" ]
u000212387
p03317
python
s213937094
s654468146
39
17
13,880
3,060
Accepted
Accepted
56.41
n,k=list(map(int,input().split())) a=list(map(int, input().split())) print((-(-(n-1)//(k-1))))
n,k=list(map(int,input().split())) print((-(-(n-1)//(k-1))))
3
2
88
53
n, k = list(map(int, input().split())) a = list(map(int, input().split())) print((-(-(n - 1) // (k - 1))))
n, k = list(map(int, input().split())) print((-(-(n - 1) // (k - 1))))
false
33.333333
[ "-a = list(map(int, input().split()))" ]
false
0.041412
0.037802
1.095503
[ "s213937094", "s654468146" ]
u159994501
p03611
python
s348132006
s321556139
102
92
13,964
14,092
Accepted
Accepted
9.8
N = int(eval(input())) a = list(map(int, input().split())) L = [0] * 10 ** 5 for i in range(N): L[a[i]] += 1 s = L[0] + L[1] + L[2] A = s for i in range(10 ** 5-3): s += L[i+3] - L[i] A = max(A,s) print(A)
N = int(eval(input())) a = list(map(int, input().split())) num_list = [0 for _ in range(10 ** 5)] for i in a: if i > 0: num_list[i - 1] += 1 num_list[i] += 1 if i < 10 ** 5 - 1: num_list[i + 1] += 1 print((max(num_list)))
11
11
222
253
N = int(eval(input())) a = list(map(int, input().split())) L = [0] * 10**5 for i in range(N): L[a[i]] += 1 s = L[0] + L[1] + L[2] A = s for i in range(10**5 - 3): s += L[i + 3] - L[i] A = max(A, s) print(A)
N = int(eval(input())) a = list(map(int, input().split())) num_list = [0 for _ in range(10**5)] for i in a: if i > 0: num_list[i - 1] += 1 num_list[i] += 1 if i < 10**5 - 1: num_list[i + 1] += 1 print((max(num_list)))
false
0
[ "-L = [0] * 10**5", "-for i in range(N):", "- L[a[i]] += 1", "-s = L[0] + L[1] + L[2]", "-A = s", "-for i in range(10**5 - 3):", "- s += L[i + 3] - L[i]", "- A = max(A, s)", "-print(A)", "+num_list = [0 for _ in range(10**5)]", "+for i in a:", "+ if i > 0:", "+ num_list[i - 1] += 1", "+ num_list[i] += 1", "+ if i < 10**5 - 1:", "+ num_list[i + 1] += 1", "+print((max(num_list)))" ]
false
0.134842
0.184648
0.730263
[ "s348132006", "s321556139" ]
u497952650
p03645
python
s489667751
s989238835
559
380
6,132
10,424
Accepted
Accepted
32.02
N,M = list(map(int,input().split())) goto_N = [0]*N from_1 = [0]*N for _ in range(M): a,b = list(map(int,input().split())) if a == 1: from_1[b] = 1 elif b == N: goto_N[a] = 1 for i in range(N): if goto_N[i] and from_1[i]: print("POSSIBLE") exit() print("IMPOSSIBLE")
N,M = list(map(int,input().split())) ##1からきている&&Nに行ける road = [0]*N for _ in range(M): a,b = list(map(int,input().split())) if a == 1: road[b-1] += 1 elif b == N: road[a-1] += 1 if 2 in road: print("POSSIBLE") else: print("IMPOSSIBLE")
18
17
323
278
N, M = list(map(int, input().split())) goto_N = [0] * N from_1 = [0] * N for _ in range(M): a, b = list(map(int, input().split())) if a == 1: from_1[b] = 1 elif b == N: goto_N[a] = 1 for i in range(N): if goto_N[i] and from_1[i]: print("POSSIBLE") exit() print("IMPOSSIBLE")
N, M = list(map(int, input().split())) ##1からきている&&Nに行ける road = [0] * N for _ in range(M): a, b = list(map(int, input().split())) if a == 1: road[b - 1] += 1 elif b == N: road[a - 1] += 1 if 2 in road: print("POSSIBLE") else: print("IMPOSSIBLE")
false
5.555556
[ "-goto_N = [0] * N", "-from_1 = [0] * N", "+##1からきている&&Nに行ける", "+road = [0] * N", "- from_1[b] = 1", "+ road[b - 1] += 1", "- goto_N[a] = 1", "-for i in range(N):", "- if goto_N[i] and from_1[i]:", "- print(\"POSSIBLE\")", "- exit()", "-print(\"IMPOSSIBLE\")", "+ road[a - 1] += 1", "+if 2 in road:", "+ print(\"POSSIBLE\")", "+else:", "+ print(\"IMPOSSIBLE\")" ]
false
0.159919
0.146737
1.089835
[ "s489667751", "s989238835" ]
u761529120
p02888
python
s387070039
s742770300
795
668
42,460
41,836
Accepted
Accepted
15.97
import bisect def main(): N = int(eval(input())) L = list(map(int, input().split())) sort_L = sorted(L) cnt = 0 for i in range(N-2): for j in range(i+1,N-1): tmp = bisect.bisect_left(sort_L,sort_L[i] + sort_L[j]) if tmp - 1 > j: cnt += tmp - j - 1 print(cnt) if __name__ == "__main__": main()
from bisect import bisect_right def main(): N = int(eval(input())) L = list(map(int, input().split())) sort_L = sorted(L) ans = 0 for i in range(N-2): for j in range(i,N-1): if i == j: continue ok = j ng = N tmp = sort_L[i] + sort_L[j] while abs(ok - ng) > 1: mid = (ok + ng) // 2 if sort_L[mid] < tmp: ok = mid else: ng = mid ans += ok - j print(ans) if __name__ == "__main__": main()
18
29
387
625
import bisect def main(): N = int(eval(input())) L = list(map(int, input().split())) sort_L = sorted(L) cnt = 0 for i in range(N - 2): for j in range(i + 1, N - 1): tmp = bisect.bisect_left(sort_L, sort_L[i] + sort_L[j]) if tmp - 1 > j: cnt += tmp - j - 1 print(cnt) if __name__ == "__main__": main()
from bisect import bisect_right def main(): N = int(eval(input())) L = list(map(int, input().split())) sort_L = sorted(L) ans = 0 for i in range(N - 2): for j in range(i, N - 1): if i == j: continue ok = j ng = N tmp = sort_L[i] + sort_L[j] while abs(ok - ng) > 1: mid = (ok + ng) // 2 if sort_L[mid] < tmp: ok = mid else: ng = mid ans += ok - j print(ans) if __name__ == "__main__": main()
false
37.931034
[ "-import bisect", "+from bisect import bisect_right", "- cnt = 0", "+ ans = 0", "- for j in range(i + 1, N - 1):", "- tmp = bisect.bisect_left(sort_L, sort_L[i] + sort_L[j])", "- if tmp - 1 > j:", "- cnt += tmp - j - 1", "- print(cnt)", "+ for j in range(i, N - 1):", "+ if i == j:", "+ continue", "+ ok = j", "+ ng = N", "+ tmp = sort_L[i] + sort_L[j]", "+ while abs(ok - ng) > 1:", "+ mid = (ok + ng) // 2", "+ if sort_L[mid] < tmp:", "+ ok = mid", "+ else:", "+ ng = mid", "+ ans += ok - j", "+ print(ans)" ]
false
0.036097
0.0322
1.121028
[ "s387070039", "s742770300" ]
u075836834
p02410
python
s791242774
s391031107
40
20
8,016
8,056
Accepted
Accepted
50
n,m=[int(i) for i in input().split()] A=[] b=[] for i in range(n): A.append([int(j) for j in input().split()]) for i in range(m): b.append(int(eval(input()))) for i in range(n): s=0 for j in range(m): s+=A[i][j]*b[j] print(s)
a,b=list(map(int,input().split())) A=[] B=[] for i in range(a): A.append([int(j) for j in input().split()]) for i in range(b): B.append(int(eval(input()))) for i in range(a): s=0 for j in range(b): s+=A[i][j]*B[j] print(s)
14
15
241
234
n, m = [int(i) for i in input().split()] A = [] b = [] for i in range(n): A.append([int(j) for j in input().split()]) for i in range(m): b.append(int(eval(input()))) for i in range(n): s = 0 for j in range(m): s += A[i][j] * b[j] print(s)
a, b = list(map(int, input().split())) A = [] B = [] for i in range(a): A.append([int(j) for j in input().split()]) for i in range(b): B.append(int(eval(input()))) for i in range(a): s = 0 for j in range(b): s += A[i][j] * B[j] print(s)
false
6.666667
[ "-n, m = [int(i) for i in input().split()]", "+a, b = list(map(int, input().split()))", "-b = []", "-for i in range(n):", "+B = []", "+for i in range(a):", "-for i in range(m):", "- b.append(int(eval(input())))", "-for i in range(n):", "+for i in range(b):", "+ B.append(int(eval(input())))", "+for i in range(a):", "- for j in range(m):", "- s += A[i][j] * b[j]", "+ for j in range(b):", "+ s += A[i][j] * B[j]" ]
false
0.113513
0.081296
1.396292
[ "s791242774", "s391031107" ]
u852690916
p02936
python
s588921931
s537715032
1,781
753
125,468
92,876
Accepted
Accepted
57.72
N, Q = list(map(int, input().split())) EDGES = [list(map(int, input().split())) for i in range(N-1)] OPES = [list(map(int, input().split())) for i in range(Q)] VALUES = [0 for i in range(N)] #operation1 for o in OPES: VALUES[o[0]-1] += o[1] #operation2 EDGES.sort(key=lambda e:e[0]) for e in EDGES: VALUES[e[1]-1] += VALUES[e[0]-1] print((" ".join(map(str, VALUES))))
import sys def main(): input = sys.stdin.readline N,Q=list(map(int, input().split())) G=[[] for _ in range(N)] for _ in range(N-1): a,b=list(map(int, input().split())) a,b=a-1,b-1 G[a].append(b) G[b].append(a) C=[0]*N for _ in range(Q): p,x=list(map(int, input().split())) C[p-1]+=x stk=[0] used=[False]*N used[0]=True while stk: v = stk.pop() for to in G[v]: if used[to]: continue used[to] = True C[to]+=C[v] stk.append(to) print((*C)) if __name__ == '__main__': main()
12
29
379
640
N, Q = list(map(int, input().split())) EDGES = [list(map(int, input().split())) for i in range(N - 1)] OPES = [list(map(int, input().split())) for i in range(Q)] VALUES = [0 for i in range(N)] # operation1 for o in OPES: VALUES[o[0] - 1] += o[1] # operation2 EDGES.sort(key=lambda e: e[0]) for e in EDGES: VALUES[e[1] - 1] += VALUES[e[0] - 1] print((" ".join(map(str, VALUES))))
import sys def main(): input = sys.stdin.readline N, Q = list(map(int, input().split())) G = [[] for _ in range(N)] for _ in range(N - 1): a, b = list(map(int, input().split())) a, b = a - 1, b - 1 G[a].append(b) G[b].append(a) C = [0] * N for _ in range(Q): p, x = list(map(int, input().split())) C[p - 1] += x stk = [0] used = [False] * N used[0] = True while stk: v = stk.pop() for to in G[v]: if used[to]: continue used[to] = True C[to] += C[v] stk.append(to) print((*C)) if __name__ == "__main__": main()
false
58.62069
[ "-N, Q = list(map(int, input().split()))", "-EDGES = [list(map(int, input().split())) for i in range(N - 1)]", "-OPES = [list(map(int, input().split())) for i in range(Q)]", "-VALUES = [0 for i in range(N)]", "-# operation1", "-for o in OPES:", "- VALUES[o[0] - 1] += o[1]", "-# operation2", "-EDGES.sort(key=lambda e: e[0])", "-for e in EDGES:", "- VALUES[e[1] - 1] += VALUES[e[0] - 1]", "-print((\" \".join(map(str, VALUES))))", "+import sys", "+", "+", "+def main():", "+ input = sys.stdin.readline", "+ N, Q = list(map(int, input().split()))", "+ G = [[] for _ in range(N)]", "+ for _ in range(N - 1):", "+ a, b = list(map(int, input().split()))", "+ a, b = a - 1, b - 1", "+ G[a].append(b)", "+ G[b].append(a)", "+ C = [0] * N", "+ for _ in range(Q):", "+ p, x = list(map(int, input().split()))", "+ C[p - 1] += x", "+ stk = [0]", "+ used = [False] * N", "+ used[0] = True", "+ while stk:", "+ v = stk.pop()", "+ for to in G[v]:", "+ if used[to]:", "+ continue", "+ used[to] = True", "+ C[to] += C[v]", "+ stk.append(to)", "+ print((*C))", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.165808
0.043107
3.8464
[ "s588921931", "s537715032" ]
u897329068
p03745
python
s951230015
s019517194
1,014
78
23,140
14,252
Accepted
Accepted
92.31
import numpy N = int(eval(input())) AN = list(map(int,input().split())) ans = 1 #配列数。切らない場合1なので初期値1 beforeDiff = 0 #一つ前の差分値。初期値は任意 chgFlag = True #区切りフラグ。初期値は0番目に区切った扱いにするのでTrue for i in range(1,N): #i-1を参照するため1スタート diff = AN[i] - AN[i-1] if chgFlag or beforeDiff==0: #符号を維持(区切り直後、前回の差が0) beforeDiff = diff #区切り直後の差分値を入れる(重要なのは符号) chgFlag = False #区切らない continue if (numpy.sign(beforeDiff) == 1 and numpy.sign(diff) == -1) or (numpy.sign(beforeDiff) == -1 and numpy.sign(diff) == 1): #以前と符号が逆なら区切る chgFlag = True #区切る ans += 1 print(ans)
N = int(eval(input())) A = list(map(int,input().split())) ans = 1 sumDiff = 0 #この値の符号によって単純非減少、単純非増加を判定 #初期や区切った直後は0でそこからdiffを積み上げる。符号が異なる場合を前で除いているので #絶対値的に大きくだけで符号は変わらない。0のときも問題なく適用できる for i in range(1,len(A)): diff = A[i]-A[i-1] if sumDiff*diff < 0: #sumDiff,diff=(正,負),(負,正)のときだけ成立 どちらかが0の場合非成立 ans += 1 sumDiff = 0 #sumDiffをリセット(区切った直後にまた区切ることはないので、 #0だとこの分岐に引っかからないようにした) else: sumDiff += diff #代入だと0のとき符号が維持できない。加算することで符号が維持できる print(ans)
22
18
589
483
import numpy N = int(eval(input())) AN = list(map(int, input().split())) ans = 1 # 配列数。切らない場合1なので初期値1 beforeDiff = 0 # 一つ前の差分値。初期値は任意 chgFlag = True # 区切りフラグ。初期値は0番目に区切った扱いにするのでTrue for i in range(1, N): # i-1を参照するため1スタート diff = AN[i] - AN[i - 1] if chgFlag or beforeDiff == 0: # 符号を維持(区切り直後、前回の差が0) beforeDiff = diff # 区切り直後の差分値を入れる(重要なのは符号) chgFlag = False # 区切らない continue if (numpy.sign(beforeDiff) == 1 and numpy.sign(diff) == -1) or ( numpy.sign(beforeDiff) == -1 and numpy.sign(diff) == 1 ): # 以前と符号が逆なら区切る chgFlag = True # 区切る ans += 1 print(ans)
N = int(eval(input())) A = list(map(int, input().split())) ans = 1 sumDiff = 0 # この値の符号によって単純非減少、単純非増加を判定 # 初期や区切った直後は0でそこからdiffを積み上げる。符号が異なる場合を前で除いているので # 絶対値的に大きくだけで符号は変わらない。0のときも問題なく適用できる for i in range(1, len(A)): diff = A[i] - A[i - 1] if sumDiff * diff < 0: # sumDiff,diff=(正,負),(負,正)のときだけ成立 どちらかが0の場合非成立 ans += 1 sumDiff = 0 # sumDiffをリセット(区切った直後にまた区切ることはないので、 # 0だとこの分岐に引っかからないようにした) else: sumDiff += diff # 代入だと0のとき符号が維持できない。加算することで符号が維持できる print(ans)
false
18.181818
[ "-import numpy", "-", "-AN = list(map(int, input().split()))", "-ans = 1 # 配列数。切らない場合1なので初期値1", "-beforeDiff = 0 # 一つ前の差分値。初期値は任意", "-chgFlag = True # 区切りフラグ。初期値は0番目に区切った扱いにするのでTrue", "-for i in range(1, N): # i-1を参照するため1スタート", "- diff = AN[i] - AN[i - 1]", "- if chgFlag or beforeDiff == 0: # 符号を維持(区切り直後、前回の差が0)", "- beforeDiff = diff # 区切り直後の差分値を入れる(重要なのは符号)", "- chgFlag = False # 区切らない", "- continue", "- if (numpy.sign(beforeDiff) == 1 and numpy.sign(diff) == -1) or (", "- numpy.sign(beforeDiff) == -1 and numpy.sign(diff) == 1", "- ): # 以前と符号が逆なら区切る", "- chgFlag = True # 区切る", "+A = list(map(int, input().split()))", "+ans = 1", "+sumDiff = 0 # この値の符号によって単純非減少、単純非増加を判定", "+# 初期や区切った直後は0でそこからdiffを積み上げる。符号が異なる場合を前で除いているので", "+# 絶対値的に大きくだけで符号は変わらない。0のときも問題なく適用できる", "+for i in range(1, len(A)):", "+ diff = A[i] - A[i - 1]", "+ if sumDiff * diff < 0: # sumDiff,diff=(正,負),(負,正)のときだけ成立 どちらかが0の場合非成立", "+ sumDiff = 0 # sumDiffをリセット(区切った直後にまた区切ることはないので、", "+ # 0だとこの分岐に引っかからないようにした)", "+ else:", "+ sumDiff += diff # 代入だと0のとき符号が維持できない。加算することで符号が維持できる" ]
false
0.282911
0.03752
7.540348
[ "s951230015", "s019517194" ]
u566428756
p02743
python
s440084681
s621157781
34
17
5,076
2,940
Accepted
Accepted
50
from decimal import Decimal a,b,c=list(map(int,input().split())) ab_=Decimal(a).sqrt()+Decimal(b).sqrt() c_=Decimal(c).sqrt() if ab_<c_: print('Yes') else: print('No')
a,b,c=list(map(int,input().split())) if c-a-b>0 and 4*a*b<(c-a-b)**2: print('Yes') else: print('No')
8
5
177
106
from decimal import Decimal a, b, c = list(map(int, input().split())) ab_ = Decimal(a).sqrt() + Decimal(b).sqrt() c_ = Decimal(c).sqrt() if ab_ < c_: print("Yes") else: print("No")
a, b, c = list(map(int, input().split())) if c - a - b > 0 and 4 * a * b < (c - a - b) ** 2: print("Yes") else: print("No")
false
37.5
[ "-from decimal import Decimal", "-", "-ab_ = Decimal(a).sqrt() + Decimal(b).sqrt()", "-c_ = Decimal(c).sqrt()", "-if ab_ < c_:", "+if c - a - b > 0 and 4 * a * b < (c - a - b) ** 2:" ]
false
0.035795
0.031836
1.124375
[ "s440084681", "s621157781" ]
u935558307
p03546
python
s213243952
s721434391
93
78
74,192
73,936
Accepted
Accepted
16.13
H,W = list(map(int,input().split())) C = [list(map(int,input().split())) for _ in range(10)] A = [list(map(int,input().split())) for _ in range(H)] dp = [float("INF")]*(10) dp[1] = 0 cnt = 0 while cnt <= 10: cnt += 1 for i in range(10): for j in range(10): dp[j] = min(dp[j],dp[i]+C[j][i]) cost = 0 for i in range(H): for j in range(W): if A[i][j] != -1: cost += dp[A[i][j]] print(cost)
H,W = list(map(int,input().split())) C = [list(map(int,input().split())) for _ in range(10)] A = [list(map(int,input().split())) for _ in range(H)] cost = [float("INF")]*(10) cost[1] = 0 cnt = 0 while cnt < 10: cnt += 1 for i in range(10): for j in range(10): cost[j] = min(cost[j],cost[i]+C[j][i]) ans = 0 for i in range(H): for j in range(W): if A[i][j] != -1: ans += cost[A[i][j]] print(ans)
18
19
450
460
H, W = list(map(int, input().split())) C = [list(map(int, input().split())) for _ in range(10)] A = [list(map(int, input().split())) for _ in range(H)] dp = [float("INF")] * (10) dp[1] = 0 cnt = 0 while cnt <= 10: cnt += 1 for i in range(10): for j in range(10): dp[j] = min(dp[j], dp[i] + C[j][i]) cost = 0 for i in range(H): for j in range(W): if A[i][j] != -1: cost += dp[A[i][j]] print(cost)
H, W = list(map(int, input().split())) C = [list(map(int, input().split())) for _ in range(10)] A = [list(map(int, input().split())) for _ in range(H)] cost = [float("INF")] * (10) cost[1] = 0 cnt = 0 while cnt < 10: cnt += 1 for i in range(10): for j in range(10): cost[j] = min(cost[j], cost[i] + C[j][i]) ans = 0 for i in range(H): for j in range(W): if A[i][j] != -1: ans += cost[A[i][j]] print(ans)
false
5.263158
[ "-dp = [float(\"INF\")] * (10)", "-dp[1] = 0", "+cost = [float(\"INF\")] * (10)", "+cost[1] = 0", "-while cnt <= 10:", "+while cnt < 10:", "- dp[j] = min(dp[j], dp[i] + C[j][i])", "-cost = 0", "+ cost[j] = min(cost[j], cost[i] + C[j][i])", "+ans = 0", "- cost += dp[A[i][j]]", "-print(cost)", "+ ans += cost[A[i][j]]", "+print(ans)" ]
false
0.037929
0.037438
1.013113
[ "s213243952", "s721434391" ]
u729133443
p03354
python
s637602871
s270460090
571
520
14,008
14,516
Accepted
Accepted
8.93
I=lambda:list(map(int,input().split()));n,m=I();p=I();l=[i for i in range(n+1)] def u(x): if l[x]!=x:l[x]=u(l[x]) return l[x] for _ in[0]*m:x,y=I();l[u(x)]=u(y) print((sum(u(i)==u(j)for i,j in enumerate(p,1))))
class UnionFind(): def __init__(self,size): self.table=[-1]*size def root(self,x): while self.table[x]>=0: x=self.table[x] return x def unite(self,x,y): s1=self.root(x) s2=self.root(y) if s1!=s2: if self.table[s1]>self.table[s2]: s1,s2=s2,s1 self.table[s1]+=self.table[s2] self.table[s2]=s1 return def same(self,x,y): return self.root(x)==self.root(y) def size(self,x): return -self.table[self.root(x)] input=open(0).readline n,m=list(map(int,input().split())) *p,=list(map(int,input().split())) u=UnionFind(n+1) for _ in range(m): u.unite(*list(map(int,input().split()))) print((sum(u.same(p[i],i+1)for i in range(n))))
6
27
215
786
I = lambda: list(map(int, input().split())) n, m = I() p = I() l = [i for i in range(n + 1)] def u(x): if l[x] != x: l[x] = u(l[x]) return l[x] for _ in [0] * m: x, y = I() l[u(x)] = u(y) print((sum(u(i) == u(j) for i, j in enumerate(p, 1))))
class UnionFind: def __init__(self, size): self.table = [-1] * size def root(self, x): while self.table[x] >= 0: x = self.table[x] return x def unite(self, x, y): s1 = self.root(x) s2 = self.root(y) if s1 != s2: if self.table[s1] > self.table[s2]: s1, s2 = s2, s1 self.table[s1] += self.table[s2] self.table[s2] = s1 return def same(self, x, y): return self.root(x) == self.root(y) def size(self, x): return -self.table[self.root(x)] input = open(0).readline n, m = list(map(int, input().split())) (*p,) = list(map(int, input().split())) u = UnionFind(n + 1) for _ in range(m): u.unite(*list(map(int, input().split()))) print((sum(u.same(p[i], i + 1) for i in range(n))))
false
77.777778
[ "-I = lambda: list(map(int, input().split()))", "-n, m = I()", "-p = I()", "-l = [i for i in range(n + 1)]", "+class UnionFind:", "+ def __init__(self, size):", "+ self.table = [-1] * size", "+", "+ def root(self, x):", "+ while self.table[x] >= 0:", "+ x = self.table[x]", "+ return x", "+", "+ def unite(self, x, y):", "+ s1 = self.root(x)", "+ s2 = self.root(y)", "+ if s1 != s2:", "+ if self.table[s1] > self.table[s2]:", "+ s1, s2 = s2, s1", "+ self.table[s1] += self.table[s2]", "+ self.table[s2] = s1", "+ return", "+", "+ def same(self, x, y):", "+ return self.root(x) == self.root(y)", "+", "+ def size(self, x):", "+ return -self.table[self.root(x)]", "-def u(x):", "- if l[x] != x:", "- l[x] = u(l[x])", "- return l[x]", "-", "-", "-for _ in [0] * m:", "- x, y = I()", "- l[u(x)] = u(y)", "-print((sum(u(i) == u(j) for i, j in enumerate(p, 1))))", "+input = open(0).readline", "+n, m = list(map(int, input().split()))", "+(*p,) = list(map(int, input().split()))", "+u = UnionFind(n + 1)", "+for _ in range(m):", "+ u.unite(*list(map(int, input().split())))", "+print((sum(u.same(p[i], i + 1) for i in range(n))))" ]
false
0.036524
0.045939
0.795057
[ "s637602871", "s270460090" ]
u094999522
p03836
python
s748453232
s849024822
165
33
75,768
9,364
Accepted
Accepted
80
#!/usr/bin/env python3 sx, sy, tx, ty = map(int, input().split()) x = tx - sx y = ty - sy h = abs(sx - tx) v = abs(sy - ty) if h * v > 0: ans = [[1, 0]] * h + [[0, 1]] * v + [[-1, 0]] * h + [[0, -1]] * v ans += [[0, -1]] + [[1, 0]] * -~h + [[0, 1]] * -~v + [[-1, 0]] ans += [[0, 1]] + [[-1, 0]] * -~h + [[0, -1]] * -~v + [[1, 0]] elif h < 1: ans = [[0, 1]] * v ans += [[1, 0]] + [[0, -1]] * v + [[-1, 0]] ans += [[-1, 0]] + [[0, 1]] * v + [[1, 0]] ans += [[0, 1]] + [[1, 0]] * 2 + [[0, -1]] * \ (v + 2) + [[-1, 0]] * 2 + [[0, 1]] * 2 elif v < 1: ans = [[1, 0]] * h ans += [[0, 1]] + [[-1, 0]] * h + [[0, -1]] ans += [[0, -1]] + [[1, 0]] * h + [[0, 1]] ans += [[1, 0]] + [[0, 1]] * 2 + [[-1, 0]] * \ (h + 2) + [[0, -1]] * 2 + [[1, 0]] * 2 if x < 0 and y < 0: ans = [*map(lambda x: [-x[0], -x[1]], ans)] elif x < 0: ans = [*map(lambda x: [-x[1], x[0]], ans)] elif y < 0: ans = [*map(lambda x: [x[1], -x[0]], ans)] for i in ans: if i == [1, 0]: print("R", end="") elif i == [-1, 0]: print("L", end="") elif i == [0, 1]: print("U", end="") else: print("D", end="") print("")
#!/usr/bin/env python3 sx, sy, tx, ty = map(int, input().split()) x = tx - sx y = ty - sy h = abs(sx - tx) v = abs(sy - ty) ans = [[1, 0]] * h + [[0, 1]] * v + [[-1, 0]] * h + [[0, -1]] * v ans += [[0, -1]] + [[1, 0]] * -~h + [[0, 1]] * -~v + [[-1, 0]] ans += [[0, 1]] + [[-1, 0]] * -~h + [[0, -1]] * -~v + [[1, 0]] if x < 0 and y < 0: ans = [*map(lambda x: [-x[0], -x[1]], ans)] elif x < 0: ans = [*map(lambda x: [-x[1], x[0]], ans)] elif y < 0: ans = [*map(lambda x: [x[1], -x[0]], ans)] for i in ans: if i == [1, 0]: print("R", end="") elif i == [-1, 0]: print("L", end="") elif i == [0, 1]: print("U", end="") else: print("D", end="") print("")
40
26
1,232
735
#!/usr/bin/env python3 sx, sy, tx, ty = map(int, input().split()) x = tx - sx y = ty - sy h = abs(sx - tx) v = abs(sy - ty) if h * v > 0: ans = [[1, 0]] * h + [[0, 1]] * v + [[-1, 0]] * h + [[0, -1]] * v ans += [[0, -1]] + [[1, 0]] * -~h + [[0, 1]] * -~v + [[-1, 0]] ans += [[0, 1]] + [[-1, 0]] * -~h + [[0, -1]] * -~v + [[1, 0]] elif h < 1: ans = [[0, 1]] * v ans += [[1, 0]] + [[0, -1]] * v + [[-1, 0]] ans += [[-1, 0]] + [[0, 1]] * v + [[1, 0]] ans += [[0, 1]] + [[1, 0]] * 2 + [[0, -1]] * (v + 2) + [[-1, 0]] * 2 + [[0, 1]] * 2 elif v < 1: ans = [[1, 0]] * h ans += [[0, 1]] + [[-1, 0]] * h + [[0, -1]] ans += [[0, -1]] + [[1, 0]] * h + [[0, 1]] ans += [[1, 0]] + [[0, 1]] * 2 + [[-1, 0]] * (h + 2) + [[0, -1]] * 2 + [[1, 0]] * 2 if x < 0 and y < 0: ans = [*map(lambda x: [-x[0], -x[1]], ans)] elif x < 0: ans = [*map(lambda x: [-x[1], x[0]], ans)] elif y < 0: ans = [*map(lambda x: [x[1], -x[0]], ans)] for i in ans: if i == [1, 0]: print("R", end="") elif i == [-1, 0]: print("L", end="") elif i == [0, 1]: print("U", end="") else: print("D", end="") print("")
#!/usr/bin/env python3 sx, sy, tx, ty = map(int, input().split()) x = tx - sx y = ty - sy h = abs(sx - tx) v = abs(sy - ty) ans = [[1, 0]] * h + [[0, 1]] * v + [[-1, 0]] * h + [[0, -1]] * v ans += [[0, -1]] + [[1, 0]] * -~h + [[0, 1]] * -~v + [[-1, 0]] ans += [[0, 1]] + [[-1, 0]] * -~h + [[0, -1]] * -~v + [[1, 0]] if x < 0 and y < 0: ans = [*map(lambda x: [-x[0], -x[1]], ans)] elif x < 0: ans = [*map(lambda x: [-x[1], x[0]], ans)] elif y < 0: ans = [*map(lambda x: [x[1], -x[0]], ans)] for i in ans: if i == [1, 0]: print("R", end="") elif i == [-1, 0]: print("L", end="") elif i == [0, 1]: print("U", end="") else: print("D", end="") print("")
false
35
[ "-if h * v > 0:", "- ans = [[1, 0]] * h + [[0, 1]] * v + [[-1, 0]] * h + [[0, -1]] * v", "- ans += [[0, -1]] + [[1, 0]] * -~h + [[0, 1]] * -~v + [[-1, 0]]", "- ans += [[0, 1]] + [[-1, 0]] * -~h + [[0, -1]] * -~v + [[1, 0]]", "-elif h < 1:", "- ans = [[0, 1]] * v", "- ans += [[1, 0]] + [[0, -1]] * v + [[-1, 0]]", "- ans += [[-1, 0]] + [[0, 1]] * v + [[1, 0]]", "- ans += [[0, 1]] + [[1, 0]] * 2 + [[0, -1]] * (v + 2) + [[-1, 0]] * 2 + [[0, 1]] * 2", "-elif v < 1:", "- ans = [[1, 0]] * h", "- ans += [[0, 1]] + [[-1, 0]] * h + [[0, -1]]", "- ans += [[0, -1]] + [[1, 0]] * h + [[0, 1]]", "- ans += [[1, 0]] + [[0, 1]] * 2 + [[-1, 0]] * (h + 2) + [[0, -1]] * 2 + [[1, 0]] * 2", "+ans = [[1, 0]] * h + [[0, 1]] * v + [[-1, 0]] * h + [[0, -1]] * v", "+ans += [[0, -1]] + [[1, 0]] * -~h + [[0, 1]] * -~v + [[-1, 0]]", "+ans += [[0, 1]] + [[-1, 0]] * -~h + [[0, -1]] * -~v + [[1, 0]]" ]
false
0.037836
0.03859
0.980478
[ "s748453232", "s849024822" ]
u392319141
p02722
python
s693638179
s702057944
426
209
3,188
3,188
Accepted
Accepted
50.94
N = int(eval(input())) def isOk(k): n = N while n % k == 0: n //= k return n % k == 1 if N <= 10**6: ans = 0 for i in range(2, N + 1): if isOk(i): ans += 1 print(ans) exit() ans = 0 V = set() for i in range(2, int(N**0.5) + 10): if isOk(i): ans += 1 V.add(i) # 約数の全列挙 def divisors(n): divisors = [] for i in range(1, int(n**0.5)+1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n//i) # divisors.sort(reverse=True) # ソート return divisors divN = divisors(N - 1) ans += len([d for d in divN if not d in V]) print(ans)
N = int(eval(input())) def isOk(k): n = N while n % k == 0: n //= k return n % k == 1 # 約数の全列挙 def divisors(n): divisors = [] for i in range(1, int(n**0.5)+1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n//i) # divisors.sort(reverse=True) # ソート return divisors divN = divisors(N) divN1 = divisors(N - 1) ans = len([0 for d in divN if d > 1 and isOk(d)]) + len([0 for d in divN1 if d > 1 and isOk(d)]) print(ans)
38
25
713
543
N = int(eval(input())) def isOk(k): n = N while n % k == 0: n //= k return n % k == 1 if N <= 10**6: ans = 0 for i in range(2, N + 1): if isOk(i): ans += 1 print(ans) exit() ans = 0 V = set() for i in range(2, int(N**0.5) + 10): if isOk(i): ans += 1 V.add(i) # 約数の全列挙 def divisors(n): divisors = [] for i in range(1, int(n**0.5) + 1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n // i) # divisors.sort(reverse=True) # ソート return divisors divN = divisors(N - 1) ans += len([d for d in divN if not d in V]) print(ans)
N = int(eval(input())) def isOk(k): n = N while n % k == 0: n //= k return n % k == 1 # 約数の全列挙 def divisors(n): divisors = [] for i in range(1, int(n**0.5) + 1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n // i) # divisors.sort(reverse=True) # ソート return divisors divN = divisors(N) divN1 = divisors(N - 1) ans = len([0 for d in divN if d > 1 and isOk(d)]) + len( [0 for d in divN1 if d > 1 and isOk(d)] ) print(ans)
false
34.210526
[ "-if N <= 10**6:", "- ans = 0", "- for i in range(2, N + 1):", "- if isOk(i):", "- ans += 1", "- print(ans)", "- exit()", "-ans = 0", "-V = set()", "-for i in range(2, int(N**0.5) + 10):", "- if isOk(i):", "- ans += 1", "- V.add(i)", "-divN = divisors(N - 1)", "-ans += len([d for d in divN if not d in V])", "+divN = divisors(N)", "+divN1 = divisors(N - 1)", "+ans = len([0 for d in divN if d > 1 and isOk(d)]) + len(", "+ [0 for d in divN1 if d > 1 and isOk(d)]", "+)" ]
false
0.283536
0.086842
3.264949
[ "s693638179", "s702057944" ]
u057109575
p03078
python
s198017073
s821697895
986
231
141,048
46,064
Accepted
Accepted
76.57
X, Y, Z, K = map(int, input().split()) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) ans1 = [] for i in range(X): for j in range(Y): ans1.append(A[i] + B[j]) ans1 = sorted(ans1, reverse=True)[:K] ans = [] for i in range(len(ans1)): for j in range(Z): ans.append(ans1[i] + C[j]) print(*sorted(ans, reverse=True)[:K], sep='\n')
X, Y, Z, K = 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) ans = [] for i in range(X): for j in range(Y): if (i + 1) * (j + 1) > K: break for k in range(Z): if (i + 1) * (j + 1) * (k + 1) <= K: ans.append(A[i] + B[j] + C[k]) else: break print(*sorted(ans, reverse=True)[:K], sep='\n')
20
22
453
549
X, Y, Z, K = map(int, input().split()) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) ans1 = [] for i in range(X): for j in range(Y): ans1.append(A[i] + B[j]) ans1 = sorted(ans1, reverse=True)[:K] ans = [] for i in range(len(ans1)): for j in range(Z): ans.append(ans1[i] + C[j]) print(*sorted(ans, reverse=True)[:K], sep="\n")
X, Y, Z, K = 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) ans = [] for i in range(X): for j in range(Y): if (i + 1) * (j + 1) > K: break for k in range(Z): if (i + 1) * (j + 1) * (k + 1) <= K: ans.append(A[i] + B[j] + C[k]) else: break print(*sorted(ans, reverse=True)[:K], sep="\n")
false
9.090909
[ "-ans1 = []", "+A.sort(reverse=True)", "+B.sort(reverse=True)", "+C.sort(reverse=True)", "+ans = []", "- ans1.append(A[i] + B[j])", "-ans1 = sorted(ans1, reverse=True)[:K]", "-ans = []", "-for i in range(len(ans1)):", "- for j in range(Z):", "- ans.append(ans1[i] + C[j])", "+ if (i + 1) * (j + 1) > K:", "+ break", "+ for k in range(Z):", "+ if (i + 1) * (j + 1) * (k + 1) <= K:", "+ ans.append(A[i] + B[j] + C[k])", "+ else:", "+ break" ]
false
0.042117
0.036555
1.15216
[ "s198017073", "s821697895" ]
u896741788
p03724
python
s895749881
s129559211
315
244
3,828
31,388
Accepted
Accepted
22.54
n,m=list(map(int,input().split())) l=[0]*(n+1) for i in range(m): a,s=list(map(int,input().split())) l[a]+=1 l[s]+=1 for i in l: if i%2:print("NO");exit() print("YES")
n,m=list(map(int,input().split())) from collections import Counter as co from itertools import chain flatten=chain.from_iterable print(("YES" if all(i%2==0 for i in list(co(flatten([list(map(int,input().split())) for i in range(m)])).values())) else "NO"))
9
6
179
248
n, m = list(map(int, input().split())) l = [0] * (n + 1) for i in range(m): a, s = list(map(int, input().split())) l[a] += 1 l[s] += 1 for i in l: if i % 2: print("NO") exit() print("YES")
n, m = list(map(int, input().split())) from collections import Counter as co from itertools import chain flatten = chain.from_iterable print( ( "YES" if all( i % 2 == 0 for i in list( co( flatten([list(map(int, input().split())) for i in range(m)]) ).values() ) ) else "NO" ) )
false
33.333333
[ "-l = [0] * (n + 1)", "-for i in range(m):", "- a, s = list(map(int, input().split()))", "- l[a] += 1", "- l[s] += 1", "-for i in l:", "- if i % 2:", "- print(\"NO\")", "- exit()", "-print(\"YES\")", "+from collections import Counter as co", "+from itertools import chain", "+", "+flatten = chain.from_iterable", "+print(", "+ (", "+ \"YES\"", "+ if all(", "+ i % 2 == 0", "+ for i in list(", "+ co(", "+ flatten([list(map(int, input().split())) for i in range(m)])", "+ ).values()", "+ )", "+ )", "+ else \"NO\"", "+ )", "+)" ]
false
0.048657
0.048644
1.000279
[ "s895749881", "s129559211" ]
u533232830
p02579
python
s963107857
s150800223
729
611
128,732
100,204
Accepted
Accepted
16.19
from collections import deque H, W = list(map(int, input().split())) Ch, Cw = list(map(int, input().split())) Dh, Dw = list(map(int, input().split())) Ch, Cw, Dh, Dw = Ch-1, Cw-1, Dh-1, Dw-1 maze = [list(eval(input())) for _ in range(H)] visit = [[-1] * W for _ in range(H)] visit[Ch][Cw] = 0 DQ = deque([(Ch, Cw)]) dx = [1, 0, -1, 0] dy = [0, 1, 0, -1] while DQ: px, py = DQ.popleft() if (px, py) == (Dh, Dw): print((visit[px][py])) exit() for i in range(4): nx = px + dx[i] ny = py + dy[i] if 0<=nx<=H-1 and 0<=ny<=W-1 and maze[nx][ny]=="." and (visit[nx][ny]>visit[px][py] or visit[nx][ny]==-1): visit[nx][ny] = visit[px][py] DQ.appendleft((nx, ny)) for i in range(-2, 3): for j in range(-2, 3): if i == j == 0: continue nx = px + i ny = py + j if 0<=nx<=H-1 and 0<=ny<=W-1 and maze[nx][ny]=="." and visit[nx][ny]==-1: visit[nx][ny] = visit[px][py] + 1 DQ.append((nx, ny)) # for a in visit: # print(a) print((-1))
from collections import deque H, W = list(map(int, input().split())) Ch, Cw = list(map(int, input().split())) Dh, Dw = list(map(int, input().split())) Ch, Cw, Dh, Dw = Ch-1, Cw-1, Dh-1, Dw-1 maze = [eval(input()) for _ in range(H)] visit = [[-1] * W for _ in range(H)] visit[Ch][Cw] = 0 DQ = deque([[Ch, Cw]]) dx = [1, 0, -1, 0] dy = [0, 1, 0, -1] while DQ: px, py = DQ.popleft() if px==Dh and py==Dw: print((visit[px][py])) exit() for i in range(4): nx = px + dx[i] ny = py + dy[i] if 0<=nx<=H-1 and 0<=ny<=W-1 and maze[nx][ny]=="." and (visit[nx][ny]>visit[px][py] or visit[nx][ny]==-1): visit[nx][ny] = visit[px][py] DQ.appendleft([nx, ny]) for i in range(-2, 3): for j in range(-2, 3): if i==j==0: continue nx = px + i ny = py + j if 0<=nx<=H-1 and 0<=ny<=W-1 and maze[nx][ny]=="." and visit[nx][ny]==-1: visit[nx][ny] = visit[px][py] + 1 DQ.append([nx, ny]) print((-1))
44
39
1,137
990
from collections import deque H, W = list(map(int, input().split())) Ch, Cw = list(map(int, input().split())) Dh, Dw = list(map(int, input().split())) Ch, Cw, Dh, Dw = Ch - 1, Cw - 1, Dh - 1, Dw - 1 maze = [list(eval(input())) for _ in range(H)] visit = [[-1] * W for _ in range(H)] visit[Ch][Cw] = 0 DQ = deque([(Ch, Cw)]) dx = [1, 0, -1, 0] dy = [0, 1, 0, -1] while DQ: px, py = DQ.popleft() if (px, py) == (Dh, Dw): print((visit[px][py])) exit() for i in range(4): nx = px + dx[i] ny = py + dy[i] if ( 0 <= nx <= H - 1 and 0 <= ny <= W - 1 and maze[nx][ny] == "." and (visit[nx][ny] > visit[px][py] or visit[nx][ny] == -1) ): visit[nx][ny] = visit[px][py] DQ.appendleft((nx, ny)) for i in range(-2, 3): for j in range(-2, 3): if i == j == 0: continue nx = px + i ny = py + j if ( 0 <= nx <= H - 1 and 0 <= ny <= W - 1 and maze[nx][ny] == "." and visit[nx][ny] == -1 ): visit[nx][ny] = visit[px][py] + 1 DQ.append((nx, ny)) # for a in visit: # print(a) print((-1))
from collections import deque H, W = list(map(int, input().split())) Ch, Cw = list(map(int, input().split())) Dh, Dw = list(map(int, input().split())) Ch, Cw, Dh, Dw = Ch - 1, Cw - 1, Dh - 1, Dw - 1 maze = [eval(input()) for _ in range(H)] visit = [[-1] * W for _ in range(H)] visit[Ch][Cw] = 0 DQ = deque([[Ch, Cw]]) dx = [1, 0, -1, 0] dy = [0, 1, 0, -1] while DQ: px, py = DQ.popleft() if px == Dh and py == Dw: print((visit[px][py])) exit() for i in range(4): nx = px + dx[i] ny = py + dy[i] if ( 0 <= nx <= H - 1 and 0 <= ny <= W - 1 and maze[nx][ny] == "." and (visit[nx][ny] > visit[px][py] or visit[nx][ny] == -1) ): visit[nx][ny] = visit[px][py] DQ.appendleft([nx, ny]) for i in range(-2, 3): for j in range(-2, 3): if i == j == 0: continue nx = px + i ny = py + j if ( 0 <= nx <= H - 1 and 0 <= ny <= W - 1 and maze[nx][ny] == "." and visit[nx][ny] == -1 ): visit[nx][ny] = visit[px][py] + 1 DQ.append([nx, ny]) print((-1))
false
11.363636
[ "-maze = [list(eval(input())) for _ in range(H)]", "+maze = [eval(input()) for _ in range(H)]", "-DQ = deque([(Ch, Cw)])", "+DQ = deque([[Ch, Cw]])", "- if (px, py) == (Dh, Dw):", "+ if px == Dh and py == Dw:", "- DQ.appendleft((nx, ny))", "+ DQ.appendleft([nx, ny])", "- DQ.append((nx, ny))", "- # for a in visit:", "- # print(a)", "+ DQ.append([nx, ny])" ]
false
0.036451
0.036559
0.99704
[ "s963107857", "s150800223" ]
u136090046
p02972
python
s861925284
s628894897
513
378
9,148
17,600
Accepted
Accepted
26.32
n = int(eval(input())) a_array = [int(x) for x in input().split()] ans_array = [0 for x in range(n)] for index in reversed(list(range(1, n + 1))): if index > n // 2: ans_array[index - 1] = a_array[index - 1] elif index - 1 != 0: tmp = sum([ans_array[x] for x in range(index * 2 - 1, n, index) if ans_array[x] != 0]) % 2 if tmp == a_array[index - 1]: pass else: ans_array[index - 1] = 1 else: tmp = sum([x for x in ans_array[1:] if x != 0]) % 2 if tmp == a_array[index - 1]: pass else: # tmpが0だったら1、1だったら0になるように ans_array[index - 1] = 1 print((sum([x for x in ans_array if x != 0]))) for index, ans in enumerate(ans_array, 1): if ans != 0: print(index)
n = int(eval(input())) array = [int(x) for x in input().split()] ans = [0 for x in range(n)] res = [] count = 0 for i in reversed(list(range(n))): a = array[i] if a == 1 and sum([x for x in ans[i::i+1]]) % 2 == 0: ans[i] = 1 count += 1 res.append(str(i+1)) elif a == 0 and sum([x for x in ans[i::i+1]]) % 2 == 1: ans[i] = 1 count += 1 res.append(str(i+1)) print(count) print((" ".join(res)))
24
19
802
458
n = int(eval(input())) a_array = [int(x) for x in input().split()] ans_array = [0 for x in range(n)] for index in reversed(list(range(1, n + 1))): if index > n // 2: ans_array[index - 1] = a_array[index - 1] elif index - 1 != 0: tmp = ( sum( [ ans_array[x] for x in range(index * 2 - 1, n, index) if ans_array[x] != 0 ] ) % 2 ) if tmp == a_array[index - 1]: pass else: ans_array[index - 1] = 1 else: tmp = sum([x for x in ans_array[1:] if x != 0]) % 2 if tmp == a_array[index - 1]: pass else: # tmpが0だったら1、1だったら0になるように ans_array[index - 1] = 1 print((sum([x for x in ans_array if x != 0]))) for index, ans in enumerate(ans_array, 1): if ans != 0: print(index)
n = int(eval(input())) array = [int(x) for x in input().split()] ans = [0 for x in range(n)] res = [] count = 0 for i in reversed(list(range(n))): a = array[i] if a == 1 and sum([x for x in ans[i :: i + 1]]) % 2 == 0: ans[i] = 1 count += 1 res.append(str(i + 1)) elif a == 0 and sum([x for x in ans[i :: i + 1]]) % 2 == 1: ans[i] = 1 count += 1 res.append(str(i + 1)) print(count) print((" ".join(res)))
false
20.833333
[ "-a_array = [int(x) for x in input().split()]", "-ans_array = [0 for x in range(n)]", "-for index in reversed(list(range(1, n + 1))):", "- if index > n // 2:", "- ans_array[index - 1] = a_array[index - 1]", "- elif index - 1 != 0:", "- tmp = (", "- sum(", "- [", "- ans_array[x]", "- for x in range(index * 2 - 1, n, index)", "- if ans_array[x] != 0", "- ]", "- )", "- % 2", "- )", "- if tmp == a_array[index - 1]:", "- pass", "- else:", "- ans_array[index - 1] = 1", "- else:", "- tmp = sum([x for x in ans_array[1:] if x != 0]) % 2", "- if tmp == a_array[index - 1]:", "- pass", "- else:", "- # tmpが0だったら1、1だったら0になるように", "- ans_array[index - 1] = 1", "-print((sum([x for x in ans_array if x != 0])))", "-for index, ans in enumerate(ans_array, 1):", "- if ans != 0:", "- print(index)", "+array = [int(x) for x in input().split()]", "+ans = [0 for x in range(n)]", "+res = []", "+count = 0", "+for i in reversed(list(range(n))):", "+ a = array[i]", "+ if a == 1 and sum([x for x in ans[i :: i + 1]]) % 2 == 0:", "+ ans[i] = 1", "+ count += 1", "+ res.append(str(i + 1))", "+ elif a == 0 and sum([x for x in ans[i :: i + 1]]) % 2 == 1:", "+ ans[i] = 1", "+ count += 1", "+ res.append(str(i + 1))", "+print(count)", "+print((\" \".join(res)))" ]
false
0.126854
0.102895
1.232845
[ "s861925284", "s628894897" ]
u334712262
p03007
python
s920861971
s754247493
301
271
21,300
21,304
Accepted
Accepted
9.97
# -*- coding: utf-8 -*- import bisect import heapq import math import random import sys from collections import Counter, defaultdict, deque from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal from functools import lru_cache, reduce from itertools import combinations, combinations_with_replacement, product, permutations from operator import add, mul, sub sys.setrecursionlimit(100000) input = sys.stdin.readline def read_int(): return int(input()) def read_int_n(): return list(map(int, input().split())) def read_float(): return float(input()) def read_float_n(): return list(map(float, input().split())) def read_str(): return input().strip() def read_str_n(): return list(map(str, input().split())) def error_print(*args): print(*args, file=sys.stderr) def mt(f): import time def wrap(*args, **kwargs): s = time.time() ret = f(*args, **kwargs) e = time.time() error_print(e - s, 'sec') return ret return wrap @mt def slv(N, A): A.sort() M = A.pop() heapq.heapify(A) m = heapq.heappop(A) ans = [] while A: a = heapq.heappop(A) if a < 0: ans.append((M, a)) M -= a else: ans.append((m, a)) m -= a print(M-m) for x, y in ans: print(x, y) print(M, m) def main(): N = read_int() A = read_int_n() (slv(N, A)) if __name__ == '__main__': main()
# -*- coding: utf-8 -*- import bisect import heapq import math import random import sys from collections import Counter, defaultdict, deque from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal from functools import lru_cache, reduce from itertools import combinations, combinations_with_replacement, product, permutations from operator import add, mul, sub sys.setrecursionlimit(100000) input = sys.stdin.readline def read_int(): return int(input()) def read_int_n(): return list(map(int, input().split())) def read_float(): return float(input()) def read_float_n(): return list(map(float, input().split())) def read_str(): return input().strip() def read_str_n(): return list(map(str, input().split())) def error_print(*args): print(*args, file=sys.stderr) def mt(f): import time def wrap(*args, **kwargs): s = time.time() ret = f(*args, **kwargs) e = time.time() error_print(e - s, 'sec') return ret return wrap @mt def slv(N, A): A.sort() M = A.pop() m = A.pop(0) ans = [] while A: a = A.pop() if a < 0: ans.append((M, a)) M -= a else: ans.append((m, a)) m -= a print(M-m) for x, y in ans: print(x, y) print(M, m) def main(): N = read_int() A = read_int_n() (slv(N, A)) if __name__ == '__main__': main()
89
88
1,574
1,535
# -*- coding: utf-8 -*- import bisect import heapq import math import random import sys from collections import Counter, defaultdict, deque from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal from functools import lru_cache, reduce from itertools import combinations, combinations_with_replacement, product, permutations from operator import add, mul, sub sys.setrecursionlimit(100000) input = sys.stdin.readline def read_int(): return int(input()) def read_int_n(): return list(map(int, input().split())) def read_float(): return float(input()) def read_float_n(): return list(map(float, input().split())) def read_str(): return input().strip() def read_str_n(): return list(map(str, input().split())) def error_print(*args): print(*args, file=sys.stderr) def mt(f): import time def wrap(*args, **kwargs): s = time.time() ret = f(*args, **kwargs) e = time.time() error_print(e - s, "sec") return ret return wrap @mt def slv(N, A): A.sort() M = A.pop() heapq.heapify(A) m = heapq.heappop(A) ans = [] while A: a = heapq.heappop(A) if a < 0: ans.append((M, a)) M -= a else: ans.append((m, a)) m -= a print(M - m) for x, y in ans: print(x, y) print(M, m) def main(): N = read_int() A = read_int_n() (slv(N, A)) if __name__ == "__main__": main()
# -*- coding: utf-8 -*- import bisect import heapq import math import random import sys from collections import Counter, defaultdict, deque from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal from functools import lru_cache, reduce from itertools import combinations, combinations_with_replacement, product, permutations from operator import add, mul, sub sys.setrecursionlimit(100000) input = sys.stdin.readline def read_int(): return int(input()) def read_int_n(): return list(map(int, input().split())) def read_float(): return float(input()) def read_float_n(): return list(map(float, input().split())) def read_str(): return input().strip() def read_str_n(): return list(map(str, input().split())) def error_print(*args): print(*args, file=sys.stderr) def mt(f): import time def wrap(*args, **kwargs): s = time.time() ret = f(*args, **kwargs) e = time.time() error_print(e - s, "sec") return ret return wrap @mt def slv(N, A): A.sort() M = A.pop() m = A.pop(0) ans = [] while A: a = A.pop() if a < 0: ans.append((M, a)) M -= a else: ans.append((m, a)) m -= a print(M - m) for x, y in ans: print(x, y) print(M, m) def main(): N = read_int() A = read_int_n() (slv(N, A)) if __name__ == "__main__": main()
false
1.123596
[ "- heapq.heapify(A)", "- m = heapq.heappop(A)", "+ m = A.pop(0)", "- a = heapq.heappop(A)", "+ a = A.pop()" ]
false
0.007088
0.039289
0.180399
[ "s920861971", "s754247493" ]
u475503988
p03816
python
s797673025
s806559776
78
45
14,396
14,564
Accepted
Accepted
42.31
N = int(eval(input())) A = list(map(int, input().split())) MAX_A = 10**5 dp = [0] * (MAX_A + 1) for i in range(N): dp[A[i]] += 1 tmp = 0 for j in range(MAX_A + 1): if dp[j] > 0: tmp += dp[j] - 1 tmp += tmp % 2 print((N - tmp))
N = int(eval(input())) A = list(map(int, input().split())) s = set(A) k = len(s) if k % 2: ans = k else: ans = k - 1 print(ans)
13
9
247
137
N = int(eval(input())) A = list(map(int, input().split())) MAX_A = 10**5 dp = [0] * (MAX_A + 1) for i in range(N): dp[A[i]] += 1 tmp = 0 for j in range(MAX_A + 1): if dp[j] > 0: tmp += dp[j] - 1 tmp += tmp % 2 print((N - tmp))
N = int(eval(input())) A = list(map(int, input().split())) s = set(A) k = len(s) if k % 2: ans = k else: ans = k - 1 print(ans)
false
30.769231
[ "-MAX_A = 10**5", "-dp = [0] * (MAX_A + 1)", "-for i in range(N):", "- dp[A[i]] += 1", "-tmp = 0", "-for j in range(MAX_A + 1):", "- if dp[j] > 0:", "- tmp += dp[j] - 1", "-tmp += tmp % 2", "-print((N - tmp))", "+s = set(A)", "+k = len(s)", "+if k % 2:", "+ ans = k", "+else:", "+ ans = k - 1", "+print(ans)" ]
false
0.061927
0.042271
1.465
[ "s797673025", "s806559776" ]
u844005364
p02838
python
s668846448
s891578153
1,692
1,558
155,864
138,552
Accepted
Accepted
7.92
n = int(eval(input())) arr = list([format(int(n), '060b')[::-1] for n in input().split()]) mod = 10 ** 9 + 7 res = 0 power_of_two = 1 for d in range(60): one = sum(x[d] == "1" for x in arr) res += one * (n - one) * power_of_two res %= mod power_of_two *= 2 power_of_two %= mod print(res)
n = int(eval(input())) arr = list(map(int, input().split())) mod = 10 ** 9 + 7 res = 0 for d in range(60): one = sum(x % 2 == 1 for x in arr) res += one * (n - one) * 2 ** d res %= mod arr = [x // 2 for x in arr] print(res)
15
13
324
249
n = int(eval(input())) arr = list([format(int(n), "060b")[::-1] for n in input().split()]) mod = 10**9 + 7 res = 0 power_of_two = 1 for d in range(60): one = sum(x[d] == "1" for x in arr) res += one * (n - one) * power_of_two res %= mod power_of_two *= 2 power_of_two %= mod print(res)
n = int(eval(input())) arr = list(map(int, input().split())) mod = 10**9 + 7 res = 0 for d in range(60): one = sum(x % 2 == 1 for x in arr) res += one * (n - one) * 2**d res %= mod arr = [x // 2 for x in arr] print(res)
false
13.333333
[ "-arr = list([format(int(n), \"060b\")[::-1] for n in input().split()])", "+arr = list(map(int, input().split()))", "-power_of_two = 1", "- one = sum(x[d] == \"1\" for x in arr)", "- res += one * (n - one) * power_of_two", "+ one = sum(x % 2 == 1 for x in arr)", "+ res += one * (n - one) * 2**d", "- power_of_two *= 2", "- power_of_two %= mod", "+ arr = [x // 2 for x in arr]" ]
false
0.039617
0.04317
0.91771
[ "s668846448", "s891578153" ]
u134302690
p03502
python
s229454915
s828019688
166
17
38,384
2,940
Accepted
Accepted
89.76
def digit10(x): dten = 0 while(x>0): dten+=int(x%10) x/=10 return dten n = int(eval(input())) if n%digit10(n)==0: print("Yes") else: print("No")
S = eval(input()) N = int(S) fn = 0 for i in range(len(S)): fn += int(S[i]) print(("Yes" if N % fn == 0 else "No"))
12
6
186
116
def digit10(x): dten = 0 while x > 0: dten += int(x % 10) x /= 10 return dten n = int(eval(input())) if n % digit10(n) == 0: print("Yes") else: print("No")
S = eval(input()) N = int(S) fn = 0 for i in range(len(S)): fn += int(S[i]) print(("Yes" if N % fn == 0 else "No"))
false
50
[ "-def digit10(x):", "- dten = 0", "- while x > 0:", "- dten += int(x % 10)", "- x /= 10", "- return dten", "-", "-", "-n = int(eval(input()))", "-if n % digit10(n) == 0:", "- print(\"Yes\")", "-else:", "- print(\"No\")", "+S = eval(input())", "+N = int(S)", "+fn = 0", "+for i in range(len(S)):", "+ fn += int(S[i])", "+print((\"Yes\" if N % fn == 0 else \"No\"))" ]
false
0.100875
0.039016
2.585486
[ "s229454915", "s828019688" ]
u894258749
p02913
python
s737446251
s419143388
1,438
1,170
92,508
90,588
Accepted
Accepted
18.64
inpl = lambda: list(map(int,input().split())) N = int(eval(input())) S = eval(input()) character_pos = [ set() for _ in range(26) ] for i in range(N): character_pos[ord(S[i])-ord('a')].add(i) ans = 0 continue_list = dict() for i in range(N): s = S[i] new_continue_list = dict() for p in character_pos[ord(s)-ord('a')]: if p < i: new_continue_list[p] = 1 for k, v in list(continue_list.items()): if s == S[k+1] and v + 1 <= i - k - 1: new_continue_list[k+1] = v+1 elif v > ans: ans = v continue_list = new_continue_list if len(list(continue_list.values())) > 0: ans = max(ans, max(continue_list.values())) print(ans)
inpl = lambda: list(map(int,input().split())) N = int(eval(input())) S = eval(input()) character_pos = [ set() for _ in range(26) ] ans = 0 continue_list = dict() for i in range(N): s = S[i] new_continue_list = dict() cpos = character_pos[ord(s)-ord('a')] for p in cpos: new_continue_list[p] = 1 cpos.add(i) for k, v in list(continue_list.items()): if s == S[k+1] and v + 1 <= i - k - 1: new_continue_list[k+1] = v+1 elif v > ans: ans = v continue_list = new_continue_list if len(list(continue_list.values())) > 0: ans = max(ans, max(continue_list.values())) print(ans)
26
23
708
649
inpl = lambda: list(map(int, input().split())) N = int(eval(input())) S = eval(input()) character_pos = [set() for _ in range(26)] for i in range(N): character_pos[ord(S[i]) - ord("a")].add(i) ans = 0 continue_list = dict() for i in range(N): s = S[i] new_continue_list = dict() for p in character_pos[ord(s) - ord("a")]: if p < i: new_continue_list[p] = 1 for k, v in list(continue_list.items()): if s == S[k + 1] and v + 1 <= i - k - 1: new_continue_list[k + 1] = v + 1 elif v > ans: ans = v continue_list = new_continue_list if len(list(continue_list.values())) > 0: ans = max(ans, max(continue_list.values())) print(ans)
inpl = lambda: list(map(int, input().split())) N = int(eval(input())) S = eval(input()) character_pos = [set() for _ in range(26)] ans = 0 continue_list = dict() for i in range(N): s = S[i] new_continue_list = dict() cpos = character_pos[ord(s) - ord("a")] for p in cpos: new_continue_list[p] = 1 cpos.add(i) for k, v in list(continue_list.items()): if s == S[k + 1] and v + 1 <= i - k - 1: new_continue_list[k + 1] = v + 1 elif v > ans: ans = v continue_list = new_continue_list if len(list(continue_list.values())) > 0: ans = max(ans, max(continue_list.values())) print(ans)
false
11.538462
[ "-for i in range(N):", "- character_pos[ord(S[i]) - ord(\"a\")].add(i)", "- for p in character_pos[ord(s) - ord(\"a\")]:", "- if p < i:", "- new_continue_list[p] = 1", "+ cpos = character_pos[ord(s) - ord(\"a\")]", "+ for p in cpos:", "+ new_continue_list[p] = 1", "+ cpos.add(i)" ]
false
0.038091
0.091976
0.414141
[ "s737446251", "s419143388" ]
u782850731
p00092
python
s709052243
s801572038
2,440
1,950
4,348
4,324
Accepted
Accepted
20.08
#!/usr/bin/env python from sys import stdin, exit def main(readline=stdin.readline): while 1: n = int(readline()) if not n: exit() pre = [0] * (n+1) now = [0] * (n+1) maximum = 0 for _ in range(n): for x, c in enumerate(readline().rstrip(), 1): if c == '.': now[x] = min(pre[x-1], pre[x], now[x-1]) + 1 if maximum < now[x]: maximum = now[x] for x in range(1, n+1): pre[x] = now[x] now[x] = 0 print(maximum) main()
#!/usr/bin/env python from sys import stdin, exit def main(readline=stdin.readline): while 1: n = int(readline()) if not n: exit() pre = [0] * (n+1) now = [0] * (n+1) maximum = 0 for _ in range(n): for x, c in enumerate(readline().rstrip(), 1): if c == '.': now[x] = min(pre[x-1], pre[x], now[x-1]) + 1 if maximum < now[x]: maximum = now[x] pre = now now = [0] * (n+1) print(maximum) main()
30
28
706
660
#!/usr/bin/env python from sys import stdin, exit def main(readline=stdin.readline): while 1: n = int(readline()) if not n: exit() pre = [0] * (n + 1) now = [0] * (n + 1) maximum = 0 for _ in range(n): for x, c in enumerate(readline().rstrip(), 1): if c == ".": now[x] = min(pre[x - 1], pre[x], now[x - 1]) + 1 if maximum < now[x]: maximum = now[x] for x in range(1, n + 1): pre[x] = now[x] now[x] = 0 print(maximum) main()
#!/usr/bin/env python from sys import stdin, exit def main(readline=stdin.readline): while 1: n = int(readline()) if not n: exit() pre = [0] * (n + 1) now = [0] * (n + 1) maximum = 0 for _ in range(n): for x, c in enumerate(readline().rstrip(), 1): if c == ".": now[x] = min(pre[x - 1], pre[x], now[x - 1]) + 1 if maximum < now[x]: maximum = now[x] pre = now now = [0] * (n + 1) print(maximum) main()
false
6.666667
[ "- for x in range(1, n + 1):", "- pre[x] = now[x]", "- now[x] = 0", "+ pre = now", "+ now = [0] * (n + 1)" ]
false
0.061402
0.037269
1.647536
[ "s709052243", "s801572038" ]
u059210959
p03069
python
s240834247
s096293063
1,666
432
28,456
21,680
Accepted
Accepted
74.07
# encoding:utf-8 import copy import numpy as np import random import bisect #bisect_left これで二部探索の大小検索が行える import math N = int(eval(input())) S = str(eval(input())) ans = 10**6 blacks = [0 for i in range(N)] black = 0 white = 0 for i in range(N): if S[i] == "#": black += 1 else: white += 1 blacks[i] = black ans = min(black,white,ans) # print(blacks) for i in range(1,N): cnt = 0 cnt += (N-(i+1))-(blacks[N-1]-blacks[i])#white # print("white",cnt) cnt += blacks[i-1]#black # print(cnt) ans = min(ans,cnt) print(ans)
# encoding:utf-8 import copy import numpy as np import random import bisect #bisect_left これで二部探索の大小検索が行える import math N = int(eval(input())) S = str(eval(input())) # ans = 10**6 # blacks = [0 for i in range(N)] # black = 0 # white = 0 # for i in range(N): # if S[i] == "#": # black += 1 # # else: # white += 1 # blacks[i] = black # # ans = min(black,white,ans) # # # print(blacks) # for i in range(1,N): # cnt = 0 # cnt += (N-(i+1))-(blacks[N-1]-blacks[i])#white # # print("white",cnt) # cnt += blacks[i-1]#black # # print(cnt) # ans = min(ans,cnt) # # print(ans) #count white cnt = S.count(".") l = [cnt] #all black for i in range(N): if S[i]==".": cnt -= 1 l.append(cnt) else: cnt += 1 l.append(cnt) # print(l) print((min(l)))
34
49
595
860
# encoding:utf-8 import copy import numpy as np import random import bisect # bisect_left これで二部探索の大小検索が行える import math N = int(eval(input())) S = str(eval(input())) ans = 10**6 blacks = [0 for i in range(N)] black = 0 white = 0 for i in range(N): if S[i] == "#": black += 1 else: white += 1 blacks[i] = black ans = min(black, white, ans) # print(blacks) for i in range(1, N): cnt = 0 cnt += (N - (i + 1)) - (blacks[N - 1] - blacks[i]) # white # print("white",cnt) cnt += blacks[i - 1] # black # print(cnt) ans = min(ans, cnt) print(ans)
# encoding:utf-8 import copy import numpy as np import random import bisect # bisect_left これで二部探索の大小検索が行える import math N = int(eval(input())) S = str(eval(input())) # ans = 10**6 # blacks = [0 for i in range(N)] # black = 0 # white = 0 # for i in range(N): # if S[i] == "#": # black += 1 # # else: # white += 1 # blacks[i] = black # # ans = min(black,white,ans) # # # print(blacks) # for i in range(1,N): # cnt = 0 # cnt += (N-(i+1))-(blacks[N-1]-blacks[i])#white # # print("white",cnt) # cnt += blacks[i-1]#black # # print(cnt) # ans = min(ans,cnt) # # print(ans) # count white cnt = S.count(".") l = [cnt] # all black for i in range(N): if S[i] == ".": cnt -= 1 l.append(cnt) else: cnt += 1 l.append(cnt) # print(l) print((min(l)))
false
30.612245
[ "-ans = 10**6", "-blacks = [0 for i in range(N)]", "-black = 0", "-white = 0", "+# ans = 10**6", "+# blacks = [0 for i in range(N)]", "+# black = 0", "+# white = 0", "+# for i in range(N):", "+# if S[i] == \"#\":", "+# black += 1", "+#", "+# else:", "+# white += 1", "+# blacks[i] = black", "+#", "+# ans = min(black,white,ans)", "+#", "+# # print(blacks)", "+# for i in range(1,N):", "+# cnt = 0", "+# cnt += (N-(i+1))-(blacks[N-1]-blacks[i])#white", "+# # print(\"white\",cnt)", "+# cnt += blacks[i-1]#black", "+# # print(cnt)", "+# ans = min(ans,cnt)", "+#", "+# print(ans)", "+# count white", "+cnt = S.count(\".\")", "+l = [cnt] # all black", "- if S[i] == \"#\":", "- black += 1", "+ if S[i] == \".\":", "+ cnt -= 1", "+ l.append(cnt)", "- white += 1", "- blacks[i] = black", "-ans = min(black, white, ans)", "-# print(blacks)", "-for i in range(1, N):", "- cnt = 0", "- cnt += (N - (i + 1)) - (blacks[N - 1] - blacks[i]) # white", "- # print(\"white\",cnt)", "- cnt += blacks[i - 1] # black", "- # print(cnt)", "- ans = min(ans, cnt)", "-print(ans)", "+ cnt += 1", "+ l.append(cnt)", "+# print(l)", "+print((min(l)))" ]
false
0.122964
0.045015
2.731627
[ "s240834247", "s096293063" ]
u136869985
p02741
python
s956596578
s136696783
19
17
3,316
3,060
Accepted
Accepted
10.53
A = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51] k = int(eval(input())) print((A[k - 1]))
print(([1,1,1,2,1,2,1,5,2,2,1,5,1,2,1,14,1,5,1,5,2,2,1,15,2,2,5,4,1,4,1,51][int(eval(input()))-1]))
3
1
138
91
A = [ 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51, ] k = int(eval(input())) print((A[k - 1]))
print( ( [ 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51, ][int(eval(input())) - 1] ) )
false
66.666667
[ "-A = [", "- 1,", "- 1,", "- 1,", "- 2,", "- 1,", "- 2,", "- 1,", "- 5,", "- 2,", "- 2,", "- 1,", "- 5,", "- 1,", "- 2,", "- 1,", "- 14,", "- 1,", "- 5,", "- 1,", "- 5,", "- 2,", "- 2,", "- 1,", "- 15,", "- 2,", "- 2,", "- 5,", "- 4,", "- 1,", "- 4,", "- 1,", "- 51,", "-]", "-k = int(eval(input()))", "-print((A[k - 1]))", "+print(", "+ (", "+ [", "+ 1,", "+ 1,", "+ 1,", "+ 2,", "+ 1,", "+ 2,", "+ 1,", "+ 5,", "+ 2,", "+ 2,", "+ 1,", "+ 5,", "+ 1,", "+ 2,", "+ 1,", "+ 14,", "+ 1,", "+ 5,", "+ 1,", "+ 5,", "+ 2,", "+ 2,", "+ 1,", "+ 15,", "+ 2,", "+ 2,", "+ 5,", "+ 4,", "+ 1,", "+ 4,", "+ 1,", "+ 51,", "+ ][int(eval(input())) - 1]", "+ )", "+)" ]
false
0.05203
0.067177
0.774527
[ "s956596578", "s136696783" ]
u724687935
p02863
python
s023472306
s528709750
871
486
177,160
118,104
Accepted
Accepted
44.2
import sys N, T = list(map(int, input().split())) S = sys.stdin.readlines() A = [] B = [] for s in S: a, b = list(map(int, s.split())) A.append(a) B.append(b) dp1 = [[0] * T for _ in range(N + 1)] for i in range(N): for j in range(T): here = dp1[i][j] if j < A[i]: dp1[i + 1][j] = here else: dp1[i + 1][j] = max(here, dp1[i][j - A[i]] + B[i]) dp2 = [[0] * T for _ in range(N + 2)] for i in range(N, 0, -1): for j in range(T): here = dp2[i + 1][j] if j < A[i - 1]: dp2[i][j] = here else: dp2[i][j] = max(here, dp2[i + 1][j - A[i - 1]] + B[i - 1]) ans = 0 for i in range(1, N + 1): t = 0 for j in range(T): t2 = dp1[i - 1][j] + dp2[i + 1][T - 1 - j] t = max(t, t2) ans = max(ans, t + B[i - 1]) print(ans)
N, T = list(map(int, input().split())) D = [tuple(map(int, input().split())) for _ in range(N)] D.sort() dp = [[0] * T for _ in range(N + 1)] for i in range(N): A, B = D[i] for j in range(T): here = dp[i][j] if j < A: dp[i + 1][j] = here else: dp[i + 1][j] = max(here, dp[i][j - A] + B) maxB = [0] * (N + 1) t = 0 for i in range(N - 1, -1, -1): t = max(t, D[i][1]) maxB[i] = t ans = 0 for i in range(N): ans = max(ans, dp[i + 1][T - 1] + maxB[i + 1]) print(ans)
38
25
877
552
import sys N, T = list(map(int, input().split())) S = sys.stdin.readlines() A = [] B = [] for s in S: a, b = list(map(int, s.split())) A.append(a) B.append(b) dp1 = [[0] * T for _ in range(N + 1)] for i in range(N): for j in range(T): here = dp1[i][j] if j < A[i]: dp1[i + 1][j] = here else: dp1[i + 1][j] = max(here, dp1[i][j - A[i]] + B[i]) dp2 = [[0] * T for _ in range(N + 2)] for i in range(N, 0, -1): for j in range(T): here = dp2[i + 1][j] if j < A[i - 1]: dp2[i][j] = here else: dp2[i][j] = max(here, dp2[i + 1][j - A[i - 1]] + B[i - 1]) ans = 0 for i in range(1, N + 1): t = 0 for j in range(T): t2 = dp1[i - 1][j] + dp2[i + 1][T - 1 - j] t = max(t, t2) ans = max(ans, t + B[i - 1]) print(ans)
N, T = list(map(int, input().split())) D = [tuple(map(int, input().split())) for _ in range(N)] D.sort() dp = [[0] * T for _ in range(N + 1)] for i in range(N): A, B = D[i] for j in range(T): here = dp[i][j] if j < A: dp[i + 1][j] = here else: dp[i + 1][j] = max(here, dp[i][j - A] + B) maxB = [0] * (N + 1) t = 0 for i in range(N - 1, -1, -1): t = max(t, D[i][1]) maxB[i] = t ans = 0 for i in range(N): ans = max(ans, dp[i + 1][T - 1] + maxB[i + 1]) print(ans)
false
34.210526
[ "-import sys", "-", "-S = sys.stdin.readlines()", "-A = []", "-B = []", "-for s in S:", "- a, b = list(map(int, s.split()))", "- A.append(a)", "- B.append(b)", "-dp1 = [[0] * T for _ in range(N + 1)]", "+D = [tuple(map(int, input().split())) for _ in range(N)]", "+D.sort()", "+dp = [[0] * T for _ in range(N + 1)]", "+ A, B = D[i]", "- here = dp1[i][j]", "- if j < A[i]:", "- dp1[i + 1][j] = here", "+ here = dp[i][j]", "+ if j < A:", "+ dp[i + 1][j] = here", "- dp1[i + 1][j] = max(here, dp1[i][j - A[i]] + B[i])", "-dp2 = [[0] * T for _ in range(N + 2)]", "-for i in range(N, 0, -1):", "- for j in range(T):", "- here = dp2[i + 1][j]", "- if j < A[i - 1]:", "- dp2[i][j] = here", "- else:", "- dp2[i][j] = max(here, dp2[i + 1][j - A[i - 1]] + B[i - 1])", "+ dp[i + 1][j] = max(here, dp[i][j - A] + B)", "+maxB = [0] * (N + 1)", "+t = 0", "+for i in range(N - 1, -1, -1):", "+ t = max(t, D[i][1])", "+ maxB[i] = t", "-for i in range(1, N + 1):", "- t = 0", "- for j in range(T):", "- t2 = dp1[i - 1][j] + dp2[i + 1][T - 1 - j]", "- t = max(t, t2)", "- ans = max(ans, t + B[i - 1])", "+for i in range(N):", "+ ans = max(ans, dp[i + 1][T - 1] + maxB[i + 1])" ]
false
0.063781
0.035809
1.781142
[ "s023472306", "s528709750" ]
u254871849
p02923
python
s039292087
s569015898
67
59
14,092
14,092
Accepted
Accepted
11.94
# 2019-11-17 20:44:23(JST) import sys # import collections # import math # from string import ascii_lowercase, ascii_uppercase, digits # from bisect import bisect_left as bi_l, bisect_right as bi_r # import itertools # from functools import reduce # import operator as op # import re # import heapq # import array # from scipy.misc import comb # (default: exact=False) # import numpy as np def main(): n, *h = [int(x) for x in sys.stdin.read().split()] step = 0 prev_height = 0 max_step = 0 for i in range(n): if h[i] <= prev_height: step += 1 else: max_step = max(max_step, step) step = 0 prev_height = h[i] max_step = max(max_step, step) print(max_step) if __name__ == "__main__": main()
import sys n, *H = list(map(int, sys.stdin.read().split())) def main(): res = 0 cnt = 0 prev = 0 for h in H + [float('inf')]: if h <= prev: cnt += 1 else: res = max(res, cnt) cnt = 0 prev = h return res if __name__ == '__main__': ans = main() print(ans)
34
20
824
361
# 2019-11-17 20:44:23(JST) import sys # import collections # import math # from string import ascii_lowercase, ascii_uppercase, digits # from bisect import bisect_left as bi_l, bisect_right as bi_r # import itertools # from functools import reduce # import operator as op # import re # import heapq # import array # from scipy.misc import comb # (default: exact=False) # import numpy as np def main(): n, *h = [int(x) for x in sys.stdin.read().split()] step = 0 prev_height = 0 max_step = 0 for i in range(n): if h[i] <= prev_height: step += 1 else: max_step = max(max_step, step) step = 0 prev_height = h[i] max_step = max(max_step, step) print(max_step) if __name__ == "__main__": main()
import sys n, *H = list(map(int, sys.stdin.read().split())) def main(): res = 0 cnt = 0 prev = 0 for h in H + [float("inf")]: if h <= prev: cnt += 1 else: res = max(res, cnt) cnt = 0 prev = h return res if __name__ == "__main__": ans = main() print(ans)
false
41.176471
[ "-# 2019-11-17 20:44:23(JST)", "-# import collections", "-# import math", "-# from string import ascii_lowercase, ascii_uppercase, digits", "-# from bisect import bisect_left as bi_l, bisect_right as bi_r", "-# import itertools", "-# from functools import reduce", "-# import operator as op", "-# import re", "-# import heapq", "-# import array", "-# from scipy.misc import comb # (default: exact=False)", "-# import numpy as np", "+n, *H = list(map(int, sys.stdin.read().split()))", "+", "+", "- n, *h = [int(x) for x in sys.stdin.read().split()]", "- step = 0", "- prev_height = 0", "- max_step = 0", "- for i in range(n):", "- if h[i] <= prev_height:", "- step += 1", "+ res = 0", "+ cnt = 0", "+ prev = 0", "+ for h in H + [float(\"inf\")]:", "+ if h <= prev:", "+ cnt += 1", "- max_step = max(max_step, step)", "- step = 0", "- prev_height = h[i]", "- max_step = max(max_step, step)", "- print(max_step)", "+ res = max(res, cnt)", "+ cnt = 0", "+ prev = h", "+ return res", "- main()", "+ ans = main()", "+ print(ans)" ]
false
0.040472
0.089327
0.45308
[ "s039292087", "s569015898" ]
u423585790
p03682
python
s013166240
s066143553
1,398
1,280
127,652
124,480
Accepted
Accepted
8.44
#!/usr/bin/env python3 from collections import defaultdict from collections import deque from heapq import heappush, heappop import sys import math import bisect import random import itertools sys.setrecursionlimit(10**5) stdin = sys.stdin bisect_left = bisect.bisect_left bisect_right = bisect.bisect_right def LI(): return list(map(int, stdin.readline().split())) def LF(): return list(map(float, stdin.readline().split())) def LI_(): return list([int(x)-1 for x in stdin.readline().split()]) def II(): return int(stdin.readline()) def IF(): return float(stdin.readline()) def LS(): return list(map(list, stdin.readline().split())) def S(): return list(stdin.readline().rstrip()) def IR(n): return [II() for _ in range(n)] def LIR(n): return [LI() for _ in range(n)] def FR(n): return [IF() for _ in range(n)] def LFR(n): return [LI() for _ in range(n)] def LIR_(n): return [LI_() for _ in range(n)] def SR(n): return [S() for _ in range(n)] def LSR(n): return [LS() for _ in range(n)] mod = 1000000007 inf = float('INF') #A def A(): x, a, b = LI() if b <= a: print("delicious") elif b <= a + x: print("safe") else: print("dangerous") return #B def B(): n = II() a = IR(n) check = [False] * (n + 1) check[1] = True now = a[0] for i in range(1,n+1): if check[now]: break if now == 2: print(i) return check[now] = True now = a[now - 1] print((-1)) return #C def C(): return #D def D(): def find(x): if x == par[x]: return x par[x] = find(par[x]) return par[x] def same(x, y): return find(x) == find(y) def unite(x, y): x = find(x) y = find(y) if rank[x] < rank[y]: par[x] = y else: par[y] = x if rank[x] == rank[y]: rank[x] += 1 return True n = II() par = [i for i in range(n)] rank = [0] * n xy = LIR(n) for i in range(n): xy[i].append(i) xy.sort(key=lambda x: x[0]) edg = [None] * (2 * n - 2) a = 0 for i in range(n-1): edg[i] = [xy[i + 1][0] - xy[i][0], xy[i][2], xy[i + 1][2]] xy.sort(key=lambda x: x[1]) for i in range(n-1): edg[n + i - 1] = [xy[i + 1][1] - xy[i][1], xy[i][2], xy[i + 1][2]] ans = 0 a = 0 edg.sort(key=lambda x: x[0]) for i in range(2 * n - 2): value, p0, p1 = edg[i] if a == n - 1: break if not same(p0, p1): unite(p0, p1) a += 1 ans += value print(ans) return #Solve if __name__ == '__main__': D()
#!/usr/bin/env python3 from collections import defaultdict from collections import deque from heapq import heappush, heappop import sys import math import bisect import random import itertools sys.setrecursionlimit(10**5) stdin = sys.stdin bisect_left = bisect.bisect_left bisect_right = bisect.bisect_right def LI(): return list(map(int, stdin.readline().split())) def LF(): return list(map(float, stdin.readline().split())) def LI_(): return list([int(x)-1 for x in stdin.readline().split()]) def II(): return int(stdin.readline()) def IF(): return float(stdin.readline()) def LS(): return list(map(list, stdin.readline().split())) def S(): return list(stdin.readline().rstrip()) def IR(n): return [II() for _ in range(n)] def LIR(n): return [LI() for _ in range(n)] def FR(n): return [IF() for _ in range(n)] def LFR(n): return [LI() for _ in range(n)] def LIR_(n): return [LI_() for _ in range(n)] def SR(n): return [S() for _ in range(n)] def LSR(n): return [LS() for _ in range(n)] mod = 1000000007 inf = float('INF') #A def A(): x, a, b = LI() if b <= a: print("delicious") elif b <= a + x: print("safe") else: print("dangerous") return #B def B(): n = II() a = IR(n) check = [False] * (n + 1) check[1] = True now = a[0] for i in range(1,n+1): if check[now]: break if now == 2: print(i) return check[now] = True now = a[now - 1] print((-1)) return #C def C(): return #D def D(): def find(x): if x == par[x]: return x par[x] = find(par[x]) return par[x] def unite(x, y): x = find(x) y = find(y) if x == y: return False if rank[x] < rank[y]: par[x] = y else: par[y] = x if rank[x] == rank[y]: rank[x] += 1 return True n = II() par = [i for i in range(n)] rank = [0] * n xy = LIR(n) for i in range(n): xy[i].append(i) xy.sort(key=lambda x: x[0]) edg = [None] * (2 * n - 2) a = 0 for i in range(n-1): edg[i] = [xy[i + 1][0] - xy[i][0], xy[i][2], xy[i + 1][2]] xy.sort(key=lambda x: x[1]) for i in range(n-1): edg[n + i - 1] = [xy[i + 1][1] - xy[i][1], xy[i][2], xy[i + 1][2]] ans = 0 a = 0 edg.sort(key=lambda x: x[0]) for i in range(2 * n - 2): value, p0, p1 = edg[i] if a == n - 1: break if unite(p0, p1): a += 1 ans += value print(ans) return #Solve if __name__ == '__main__': D()
114
112
2,808
2,755
#!/usr/bin/env python3 from collections import defaultdict from collections import deque from heapq import heappush, heappop import sys import math import bisect import random import itertools sys.setrecursionlimit(10**5) stdin = sys.stdin bisect_left = bisect.bisect_left bisect_right = bisect.bisect_right def LI(): return list(map(int, stdin.readline().split())) def LF(): return list(map(float, stdin.readline().split())) def LI_(): return list([int(x) - 1 for x in stdin.readline().split()]) def II(): return int(stdin.readline()) def IF(): return float(stdin.readline()) def LS(): return list(map(list, stdin.readline().split())) def S(): return list(stdin.readline().rstrip()) def IR(n): return [II() for _ in range(n)] def LIR(n): return [LI() for _ in range(n)] def FR(n): return [IF() for _ in range(n)] def LFR(n): return [LI() for _ in range(n)] def LIR_(n): return [LI_() for _ in range(n)] def SR(n): return [S() for _ in range(n)] def LSR(n): return [LS() for _ in range(n)] mod = 1000000007 inf = float("INF") # A def A(): x, a, b = LI() if b <= a: print("delicious") elif b <= a + x: print("safe") else: print("dangerous") return # B def B(): n = II() a = IR(n) check = [False] * (n + 1) check[1] = True now = a[0] for i in range(1, n + 1): if check[now]: break if now == 2: print(i) return check[now] = True now = a[now - 1] print((-1)) return # C def C(): return # D def D(): def find(x): if x == par[x]: return x par[x] = find(par[x]) return par[x] def same(x, y): return find(x) == find(y) def unite(x, y): x = find(x) y = find(y) if rank[x] < rank[y]: par[x] = y else: par[y] = x if rank[x] == rank[y]: rank[x] += 1 return True n = II() par = [i for i in range(n)] rank = [0] * n xy = LIR(n) for i in range(n): xy[i].append(i) xy.sort(key=lambda x: x[0]) edg = [None] * (2 * n - 2) a = 0 for i in range(n - 1): edg[i] = [xy[i + 1][0] - xy[i][0], xy[i][2], xy[i + 1][2]] xy.sort(key=lambda x: x[1]) for i in range(n - 1): edg[n + i - 1] = [xy[i + 1][1] - xy[i][1], xy[i][2], xy[i + 1][2]] ans = 0 a = 0 edg.sort(key=lambda x: x[0]) for i in range(2 * n - 2): value, p0, p1 = edg[i] if a == n - 1: break if not same(p0, p1): unite(p0, p1) a += 1 ans += value print(ans) return # Solve if __name__ == "__main__": D()
#!/usr/bin/env python3 from collections import defaultdict from collections import deque from heapq import heappush, heappop import sys import math import bisect import random import itertools sys.setrecursionlimit(10**5) stdin = sys.stdin bisect_left = bisect.bisect_left bisect_right = bisect.bisect_right def LI(): return list(map(int, stdin.readline().split())) def LF(): return list(map(float, stdin.readline().split())) def LI_(): return list([int(x) - 1 for x in stdin.readline().split()]) def II(): return int(stdin.readline()) def IF(): return float(stdin.readline()) def LS(): return list(map(list, stdin.readline().split())) def S(): return list(stdin.readline().rstrip()) def IR(n): return [II() for _ in range(n)] def LIR(n): return [LI() for _ in range(n)] def FR(n): return [IF() for _ in range(n)] def LFR(n): return [LI() for _ in range(n)] def LIR_(n): return [LI_() for _ in range(n)] def SR(n): return [S() for _ in range(n)] def LSR(n): return [LS() for _ in range(n)] mod = 1000000007 inf = float("INF") # A def A(): x, a, b = LI() if b <= a: print("delicious") elif b <= a + x: print("safe") else: print("dangerous") return # B def B(): n = II() a = IR(n) check = [False] * (n + 1) check[1] = True now = a[0] for i in range(1, n + 1): if check[now]: break if now == 2: print(i) return check[now] = True now = a[now - 1] print((-1)) return # C def C(): return # D def D(): def find(x): if x == par[x]: return x par[x] = find(par[x]) return par[x] def unite(x, y): x = find(x) y = find(y) if x == y: return False if rank[x] < rank[y]: par[x] = y else: par[y] = x if rank[x] == rank[y]: rank[x] += 1 return True n = II() par = [i for i in range(n)] rank = [0] * n xy = LIR(n) for i in range(n): xy[i].append(i) xy.sort(key=lambda x: x[0]) edg = [None] * (2 * n - 2) a = 0 for i in range(n - 1): edg[i] = [xy[i + 1][0] - xy[i][0], xy[i][2], xy[i + 1][2]] xy.sort(key=lambda x: x[1]) for i in range(n - 1): edg[n + i - 1] = [xy[i + 1][1] - xy[i][1], xy[i][2], xy[i + 1][2]] ans = 0 a = 0 edg.sort(key=lambda x: x[0]) for i in range(2 * n - 2): value, p0, p1 = edg[i] if a == n - 1: break if unite(p0, p1): a += 1 ans += value print(ans) return # Solve if __name__ == "__main__": D()
false
1.754386
[ "- def same(x, y):", "- return find(x) == find(y)", "-", "+ if x == y:", "+ return False", "- if not same(p0, p1):", "- unite(p0, p1)", "+ if unite(p0, p1):" ]
false
0.072625
0.097701
0.743347
[ "s013166240", "s066143553" ]
u633068244
p00089
python
s567584716
s777002004
400
10
4,400
4,316
Accepted
Accepted
97.5
def path(w,h,sm): global mx if w < 0 or len(inp[h])-1 < w: return 0 sm += inp[h][w] if sm < mx[h][w]: return 0 else: mx[h][w] = sm if h == c-1: return sm if h < c/2: return max(path(w,h+1,sm),path(w+1,h+1,sm)) else: return max(path(w,h+1,sm),path(w-1,h+1,sm)) c = 0 inp = [] while True: try: inp.append(list(map(int, input().split(",")))) c += 1 except: mx = [[0 for i in range((c+1)/2)] for i in range(c)] print(path(0,0,0)) break
def mx(inp,w,h): if h <= c/2: if w == 0: inp[h][w] += inp[h-1][w] elif w == len(inp[h])-1: inp[h][w] += inp[h-1][w-1] else: inp[h][w] += max(inp[h-1][w],inp[h-1][w-1]) else: inp[h][w] += max(inp[h-1][w],inp[h-1][w+1]) return inp c = 0 inp = [] while True: try: inp.append(list(map(int, input().split(",")))) c += 1 except: break for h in range(1,c): for w in range(len(inp[h])): inp = mx(inp,w,h) print(inp[c-1][0])
20
22
470
458
def path(w, h, sm): global mx if w < 0 or len(inp[h]) - 1 < w: return 0 sm += inp[h][w] if sm < mx[h][w]: return 0 else: mx[h][w] = sm if h == c - 1: return sm if h < c / 2: return max(path(w, h + 1, sm), path(w + 1, h + 1, sm)) else: return max(path(w, h + 1, sm), path(w - 1, h + 1, sm)) c = 0 inp = [] while True: try: inp.append(list(map(int, input().split(",")))) c += 1 except: mx = [[0 for i in range((c + 1) / 2)] for i in range(c)] print(path(0, 0, 0)) break
def mx(inp, w, h): if h <= c / 2: if w == 0: inp[h][w] += inp[h - 1][w] elif w == len(inp[h]) - 1: inp[h][w] += inp[h - 1][w - 1] else: inp[h][w] += max(inp[h - 1][w], inp[h - 1][w - 1]) else: inp[h][w] += max(inp[h - 1][w], inp[h - 1][w + 1]) return inp c = 0 inp = [] while True: try: inp.append(list(map(int, input().split(",")))) c += 1 except: break for h in range(1, c): for w in range(len(inp[h])): inp = mx(inp, w, h) print(inp[c - 1][0])
false
9.090909
[ "-def path(w, h, sm):", "- global mx", "- if w < 0 or len(inp[h]) - 1 < w:", "- return 0", "- sm += inp[h][w]", "- if sm < mx[h][w]:", "- return 0", "+def mx(inp, w, h):", "+ if h <= c / 2:", "+ if w == 0:", "+ inp[h][w] += inp[h - 1][w]", "+ elif w == len(inp[h]) - 1:", "+ inp[h][w] += inp[h - 1][w - 1]", "+ else:", "+ inp[h][w] += max(inp[h - 1][w], inp[h - 1][w - 1])", "- mx[h][w] = sm", "- if h == c - 1:", "- return sm", "- if h < c / 2:", "- return max(path(w, h + 1, sm), path(w + 1, h + 1, sm))", "- else:", "- return max(path(w, h + 1, sm), path(w - 1, h + 1, sm))", "+ inp[h][w] += max(inp[h - 1][w], inp[h - 1][w + 1])", "+ return inp", "- mx = [[0 for i in range((c + 1) / 2)] for i in range(c)]", "- print(path(0, 0, 0))", "+for h in range(1, c):", "+ for w in range(len(inp[h])):", "+ inp = mx(inp, w, h)", "+print(inp[c - 1][0])" ]
false
0.081578
0.037259
2.189469
[ "s567584716", "s777002004" ]
u645250356
p03665
python
s716190778
s426151264
200
37
39,916
5,084
Accepted
Accepted
81.5
from collections import Counter,defaultdict,deque from heapq import heapify,heappop,heappush import sys,bisect,math,itertools,string,queue sys.setrecursionlimit(10**8) mod = 10**9+7 def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) def inpl_str(): return list(sys.stdin.readline().split()) def inpln(n): return list(int(sys.stdin.readline()) for i in range(n)) def conb(n,r): return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) n,p = inpl() a = inpl() res = 0 odd = 0 even = 0 for i in a: if i%2: odd += 1 else: even += 1 # print(odd,even) tmp = 0 if p == 0 else 1 for i in range(tmp,odd+1,2): for j in range(0,even+1): res += conb(odd,i) * conb(even,j) print(res)
from collections import Counter,defaultdict,deque from heapq import heappop,heappush,heapify import sys,bisect,math,itertools,fractions sys.setrecursionlimit(10**8) mod = 10**9+7 INF = float('inf') def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) def conb(n,r): return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) n,m = inpl() a = inpl() odd = even = 0 for x in a: if x%2: odd += 1 else: even += 1 res = pow(2,even) ores = eres = 0 for i in range(odd+1): if i%2 == 0: eres += conb(odd,i) else: ores += conb(odd,i) if m: print((ores*res)) else: print((eres*res))
28
29
811
711
from collections import Counter, defaultdict, deque from heapq import heapify, heappop, heappush import sys, bisect, math, itertools, string, queue sys.setrecursionlimit(10**8) mod = 10**9 + 7 def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) def inpl_str(): return list(sys.stdin.readline().split()) def inpln(n): return list(int(sys.stdin.readline()) for i in range(n)) def conb(n, r): return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) n, p = inpl() a = inpl() res = 0 odd = 0 even = 0 for i in a: if i % 2: odd += 1 else: even += 1 # print(odd,even) tmp = 0 if p == 0 else 1 for i in range(tmp, odd + 1, 2): for j in range(0, even + 1): res += conb(odd, i) * conb(even, j) print(res)
from collections import Counter, defaultdict, deque from heapq import heappop, heappush, heapify import sys, bisect, math, itertools, fractions sys.setrecursionlimit(10**8) mod = 10**9 + 7 INF = float("inf") def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) def conb(n, r): return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) n, m = inpl() a = inpl() odd = even = 0 for x in a: if x % 2: odd += 1 else: even += 1 res = pow(2, even) ores = eres = 0 for i in range(odd + 1): if i % 2 == 0: eres += conb(odd, i) else: ores += conb(odd, i) if m: print((ores * res)) else: print((eres * res))
false
3.448276
[ "-from heapq import heapify, heappop, heappush", "-import sys, bisect, math, itertools, string, queue", "+from heapq import heappop, heappush, heapify", "+import sys, bisect, math, itertools, fractions", "+INF = float(\"inf\")", "-def inpl_str():", "- return list(sys.stdin.readline().split())", "-", "-", "-def inpln(n):", "- return list(int(sys.stdin.readline()) for i in range(n))", "-", "-", "-n, p = inpl()", "+n, m = inpl()", "-res = 0", "-odd = 0", "-even = 0", "-for i in a:", "- if i % 2:", "+odd = even = 0", "+for x in a:", "+ if x % 2:", "-# print(odd,even)", "-tmp = 0 if p == 0 else 1", "-for i in range(tmp, odd + 1, 2):", "- for j in range(0, even + 1):", "- res += conb(odd, i) * conb(even, j)", "-print(res)", "+res = pow(2, even)", "+ores = eres = 0", "+for i in range(odd + 1):", "+ if i % 2 == 0:", "+ eres += conb(odd, i)", "+ else:", "+ ores += conb(odd, i)", "+if m:", "+ print((ores * res))", "+else:", "+ print((eres * res))" ]
false
0.042333
0.033518
1.262994
[ "s716190778", "s426151264" ]
u918601425
p02616
python
s734892471
s563209085
267
236
31,756
31,716
Accepted
Accepted
11.61
MOD=10**9+7 N,K=[int(s) for s in input().split()] ls=[int(s) for s in input().split()] ans=set() ls=sorted(ls, key=lambda x: -abs(x)) mul=1 sign=0 zeroflag=0 flag=[0 for _ in range(N)] for i in range(K): flag[i]=1 if ls[i]<0: sign=(sign+1)%2 if sign==1: if 0 in ls: zeroflag=1 a=[0,0,0,0] b=[0,0,0,0] for j in range(K,N): if ls[j]>0: for k in range(K): if ls[K-1-k]<0: a[0]=ls[j] b[0]=j a[1]=ls[K-1-k] b[1]=K-1-k break break for j in range(K,N): if ls[j]<0: for k in range(K): if ls[K-1-k]>0: a[2]=ls[j] b[2]=j a[3]=ls[K-1-k] b[3]=K-1-k break break if a==[0,0,0,0]: flag.reverse() elif b[0]==0 and b[1]==0: flag[b[2]]=1 flag[b[3]]=0 elif b[2]==0 and b[3]==0: flag[b[0]]=1 flag[b[1]]=0 elif abs(a[0]*a[3])>abs(a[1]*a[2]): flag[b[0]]=1 flag[b[1]]=0 else: flag[b[2]]=1 flag[b[3]]=0 if sign==1 and a==[0,0,0,0] and zeroflag==1: print((0)) else: mul=1 for i in range(N): if flag[i]==1: mul=mul*ls[i]%MOD print(mul)
MOD=10**9+7 N,K=[int(s) for s in input().split()] ls=[int(s) for s in input().split()] ls=sorted(ls, key=lambda x: -abs(x)) #かける数をフラグで管理 flag=[0 for _ in range(N)] sign=0 for i in range(K): flag[i]=1 if ls[i]<0: sign=(sign+1)%2 if sign==1: #絶対値が大きい順にかけた数は負か? #フラグのない負の数を、フラグのある正の数と取り換え可能か? swap_neg_to_pos=[] for i in range(K,N): if ls[i]<0: for j in range(K): if ls[K-1-j]>0: swap_neg_to_pos=[i,K-1-j,ls[K-1-j],-ls[i]] break break #フラグのない正の数を、フラグのある負の数と取り換え可能か? swap_pos_to_neg=[] for i in range(K,N): if ls[i]>0: for j in range(K): if ls[K-1-j]<0: swap_pos_to_neg=[i,K-1-j,-ls[K-1-j],ls[i]] break break #フラグを修正 if swap_neg_to_pos!=[] and swap_pos_to_neg!=[]: #どちらも取り換え可能なとき #負の数にフラグを与えたほうがロスが少ないとき if swap_neg_to_pos[2]*swap_pos_to_neg[3]<swap_pos_to_neg[2]*swap_neg_to_pos[3]: flag[swap_neg_to_pos[0]]=1 flag[swap_neg_to_pos[1]]=0 else: #正の数にフラグを与えたほうがロスが少ないとき flag[swap_pos_to_neg[0]]=1 flag[swap_pos_to_neg[1]]=0 elif swap_neg_to_pos==[] and swap_pos_to_neg==[]: #どちらも取り換え不可能なとき flag.reverse() elif swap_pos_to_neg!=[]: #正の数にフラグを与えることのみ可能なとき flag[swap_pos_to_neg[0]]=1 flag[swap_pos_to_neg[1]]=0 else: #負の数にフラグを与えることのみ可能なとき flag[swap_neg_to_pos[0]]=1 flag[swap_neg_to_pos[1]]=0 ans=1 for i in range(N): if flag[i]==1: ans=(ans*ls[i])%MOD print(ans)
60
57
1,201
1,525
MOD = 10**9 + 7 N, K = [int(s) for s in input().split()] ls = [int(s) for s in input().split()] ans = set() ls = sorted(ls, key=lambda x: -abs(x)) mul = 1 sign = 0 zeroflag = 0 flag = [0 for _ in range(N)] for i in range(K): flag[i] = 1 if ls[i] < 0: sign = (sign + 1) % 2 if sign == 1: if 0 in ls: zeroflag = 1 a = [0, 0, 0, 0] b = [0, 0, 0, 0] for j in range(K, N): if ls[j] > 0: for k in range(K): if ls[K - 1 - k] < 0: a[0] = ls[j] b[0] = j a[1] = ls[K - 1 - k] b[1] = K - 1 - k break break for j in range(K, N): if ls[j] < 0: for k in range(K): if ls[K - 1 - k] > 0: a[2] = ls[j] b[2] = j a[3] = ls[K - 1 - k] b[3] = K - 1 - k break break if a == [0, 0, 0, 0]: flag.reverse() elif b[0] == 0 and b[1] == 0: flag[b[2]] = 1 flag[b[3]] = 0 elif b[2] == 0 and b[3] == 0: flag[b[0]] = 1 flag[b[1]] = 0 elif abs(a[0] * a[3]) > abs(a[1] * a[2]): flag[b[0]] = 1 flag[b[1]] = 0 else: flag[b[2]] = 1 flag[b[3]] = 0 if sign == 1 and a == [0, 0, 0, 0] and zeroflag == 1: print((0)) else: mul = 1 for i in range(N): if flag[i] == 1: mul = mul * ls[i] % MOD print(mul)
MOD = 10**9 + 7 N, K = [int(s) for s in input().split()] ls = [int(s) for s in input().split()] ls = sorted(ls, key=lambda x: -abs(x)) # かける数をフラグで管理 flag = [0 for _ in range(N)] sign = 0 for i in range(K): flag[i] = 1 if ls[i] < 0: sign = (sign + 1) % 2 if sign == 1: # 絶対値が大きい順にかけた数は負か? # フラグのない負の数を、フラグのある正の数と取り換え可能か? swap_neg_to_pos = [] for i in range(K, N): if ls[i] < 0: for j in range(K): if ls[K - 1 - j] > 0: swap_neg_to_pos = [i, K - 1 - j, ls[K - 1 - j], -ls[i]] break break # フラグのない正の数を、フラグのある負の数と取り換え可能か? swap_pos_to_neg = [] for i in range(K, N): if ls[i] > 0: for j in range(K): if ls[K - 1 - j] < 0: swap_pos_to_neg = [i, K - 1 - j, -ls[K - 1 - j], ls[i]] break break # フラグを修正 if swap_neg_to_pos != [] and swap_pos_to_neg != []: # どちらも取り換え可能なとき # 負の数にフラグを与えたほうがロスが少ないとき if ( swap_neg_to_pos[2] * swap_pos_to_neg[3] < swap_pos_to_neg[2] * swap_neg_to_pos[3] ): flag[swap_neg_to_pos[0]] = 1 flag[swap_neg_to_pos[1]] = 0 else: # 正の数にフラグを与えたほうがロスが少ないとき flag[swap_pos_to_neg[0]] = 1 flag[swap_pos_to_neg[1]] = 0 elif swap_neg_to_pos == [] and swap_pos_to_neg == []: # どちらも取り換え不可能なとき flag.reverse() elif swap_pos_to_neg != []: # 正の数にフラグを与えることのみ可能なとき flag[swap_pos_to_neg[0]] = 1 flag[swap_pos_to_neg[1]] = 0 else: # 負の数にフラグを与えることのみ可能なとき flag[swap_neg_to_pos[0]] = 1 flag[swap_neg_to_pos[1]] = 0 ans = 1 for i in range(N): if flag[i] == 1: ans = (ans * ls[i]) % MOD print(ans)
false
5
[ "-ans = set()", "-mul = 1", "+# かける数をフラグで管理", "+flag = [0 for _ in range(N)]", "-zeroflag = 0", "-flag = [0 for _ in range(N)]", "-if sign == 1:", "- if 0 in ls:", "- zeroflag = 1", "- a = [0, 0, 0, 0]", "- b = [0, 0, 0, 0]", "- for j in range(K, N):", "- if ls[j] > 0:", "- for k in range(K):", "- if ls[K - 1 - k] < 0:", "- a[0] = ls[j]", "- b[0] = j", "- a[1] = ls[K - 1 - k]", "- b[1] = K - 1 - k", "+if sign == 1: # 絶対値が大きい順にかけた数は負か?", "+ # フラグのない負の数を、フラグのある正の数と取り換え可能か?", "+ swap_neg_to_pos = []", "+ for i in range(K, N):", "+ if ls[i] < 0:", "+ for j in range(K):", "+ if ls[K - 1 - j] > 0:", "+ swap_neg_to_pos = [i, K - 1 - j, ls[K - 1 - j], -ls[i]]", "- for j in range(K, N):", "- if ls[j] < 0:", "- for k in range(K):", "- if ls[K - 1 - k] > 0:", "- a[2] = ls[j]", "- b[2] = j", "- a[3] = ls[K - 1 - k]", "- b[3] = K - 1 - k", "+ # フラグのない正の数を、フラグのある負の数と取り換え可能か?", "+ swap_pos_to_neg = []", "+ for i in range(K, N):", "+ if ls[i] > 0:", "+ for j in range(K):", "+ if ls[K - 1 - j] < 0:", "+ swap_pos_to_neg = [i, K - 1 - j, -ls[K - 1 - j], ls[i]]", "- if a == [0, 0, 0, 0]:", "+ # フラグを修正", "+ if swap_neg_to_pos != [] and swap_pos_to_neg != []: # どちらも取り換え可能なとき", "+ # 負の数にフラグを与えたほうがロスが少ないとき", "+ if (", "+ swap_neg_to_pos[2] * swap_pos_to_neg[3]", "+ < swap_pos_to_neg[2] * swap_neg_to_pos[3]", "+ ):", "+ flag[swap_neg_to_pos[0]] = 1", "+ flag[swap_neg_to_pos[1]] = 0", "+ else: # 正の数にフラグを与えたほうがロスが少ないとき", "+ flag[swap_pos_to_neg[0]] = 1", "+ flag[swap_pos_to_neg[1]] = 0", "+ elif swap_neg_to_pos == [] and swap_pos_to_neg == []: # どちらも取り換え不可能なとき", "- elif b[0] == 0 and b[1] == 0:", "- flag[b[2]] = 1", "- flag[b[3]] = 0", "- elif b[2] == 0 and b[3] == 0:", "- flag[b[0]] = 1", "- flag[b[1]] = 0", "- elif abs(a[0] * a[3]) > abs(a[1] * a[2]):", "- flag[b[0]] = 1", "- flag[b[1]] = 0", "- else:", "- flag[b[2]] = 1", "- flag[b[3]] = 0", "-if sign == 1 and a == [0, 0, 0, 0] and zeroflag == 1:", "- print((0))", "-else:", "- mul = 1", "- for i in range(N):", "- if flag[i] == 1:", "- mul = mul * ls[i] % MOD", "- print(mul)", "+ elif swap_pos_to_neg != []: # 正の数にフラグを与えることのみ可能なとき", "+ flag[swap_pos_to_neg[0]] = 1", "+ flag[swap_pos_to_neg[1]] = 0", "+ else: # 負の数にフラグを与えることのみ可能なとき", "+ flag[swap_neg_to_pos[0]] = 1", "+ flag[swap_neg_to_pos[1]] = 0", "+ans = 1", "+for i in range(N):", "+ if flag[i] == 1:", "+ ans = (ans * ls[i]) % MOD", "+print(ans)" ]
false
0.042001
0.037376
1.123757
[ "s734892471", "s563209085" ]
u350093546
p02555
python
s920672262
s086796430
97
81
68,156
65,080
Accepted
Accepted
16.49
s=int(eval(input())) mod=10**9+7 from operator import mul from functools import reduce def cmb(n,r): r = min(n-r,r) if r == 0: return 1 over = reduce(mul, list(range(n, n - r, -1))) under = reduce(mul, list(range(1,r + 1))) return over // under ans=0 for i in range(1,667): x=s-3*i if x<0: break ans+=cmb(i+x-1,x) ans%=mod print(ans)
s=int(eval(input())) mod=10**9+7 dp=[0]*2001 for i in range(3,2001): dp[i]+=1 for j in range(i-3,-1,-1): dp[i]+=dp[j] dp[i]%=mod print((dp[s]))
25
15
394
173
s = int(eval(input())) mod = 10**9 + 7 from operator import mul from functools import reduce def cmb(n, r): r = min(n - r, r) if r == 0: return 1 over = reduce(mul, list(range(n, n - r, -1))) under = reduce(mul, list(range(1, r + 1))) return over // under ans = 0 for i in range(1, 667): x = s - 3 * i if x < 0: break ans += cmb(i + x - 1, x) ans %= mod print(ans)
s = int(eval(input())) mod = 10**9 + 7 dp = [0] * 2001 for i in range(3, 2001): dp[i] += 1 for j in range(i - 3, -1, -1): dp[i] += dp[j] dp[i] %= mod print((dp[s]))
false
40
[ "-from operator import mul", "-from functools import reduce", "-", "-", "-def cmb(n, r):", "- r = min(n - r, r)", "- if r == 0:", "- return 1", "- over = reduce(mul, list(range(n, n - r, -1)))", "- under = reduce(mul, list(range(1, r + 1)))", "- return over // under", "-", "-", "-ans = 0", "-for i in range(1, 667):", "- x = s - 3 * i", "- if x < 0:", "- break", "- ans += cmb(i + x - 1, x)", "- ans %= mod", "-print(ans)", "+dp = [0] * 2001", "+for i in range(3, 2001):", "+ dp[i] += 1", "+ for j in range(i - 3, -1, -1):", "+ dp[i] += dp[j]", "+ dp[i] %= mod", "+print((dp[s]))" ]
false
0.051932
1.301695
0.039896
[ "s920672262", "s086796430" ]
u077291787
p02996
python
s879605381
s585586474
462
298
48,700
48,708
Accepted
Accepted
35.5
# ABC131D - Megalomania from itertools import accumulate from operator import itemgetter as gt def main(): N, *AB = list(map(int, open(0).read().split())) T, D = list(zip(*sorted([(i, j) for i, j in zip(*[iter(AB)] * 2)], key=gt(1)))) T = list(accumulate(T)) flg = all(t <= d for t, d in zip(T, D)) # all tasks finish within each deadline? print(("Yes" if flg else "No")) if __name__ == "__main__": main()
# ABC131D - Megalomania from operator import itemgetter as gt def main(): N, *AB = list(map(int, open(0).read().split())) cur, TD = 0, sorted([(i, j) for i, j in zip(*[iter(AB)] * 2)], key=gt(1)) for task, deadline in TD: # check all tasks greedily cur += task if cur > deadline: # fail to finish a task within its deadline print("No") return print("Yes") if __name__ == "__main__": main()
15
17
434
465
# ABC131D - Megalomania from itertools import accumulate from operator import itemgetter as gt def main(): N, *AB = list(map(int, open(0).read().split())) T, D = list(zip(*sorted([(i, j) for i, j in zip(*[iter(AB)] * 2)], key=gt(1)))) T = list(accumulate(T)) flg = all(t <= d for t, d in zip(T, D)) # all tasks finish within each deadline? print(("Yes" if flg else "No")) if __name__ == "__main__": main()
# ABC131D - Megalomania from operator import itemgetter as gt def main(): N, *AB = list(map(int, open(0).read().split())) cur, TD = 0, sorted([(i, j) for i, j in zip(*[iter(AB)] * 2)], key=gt(1)) for task, deadline in TD: # check all tasks greedily cur += task if cur > deadline: # fail to finish a task within its deadline print("No") return print("Yes") if __name__ == "__main__": main()
false
11.764706
[ "-from itertools import accumulate", "- T, D = list(zip(*sorted([(i, j) for i, j in zip(*[iter(AB)] * 2)], key=gt(1))))", "- T = list(accumulate(T))", "- flg = all(t <= d for t, d in zip(T, D)) # all tasks finish within each deadline?", "- print((\"Yes\" if flg else \"No\"))", "+ cur, TD = 0, sorted([(i, j) for i, j in zip(*[iter(AB)] * 2)], key=gt(1))", "+ for task, deadline in TD: # check all tasks greedily", "+ cur += task", "+ if cur > deadline: # fail to finish a task within its deadline", "+ print(\"No\")", "+ return", "+ print(\"Yes\")" ]
false
0.137417
0.039228
3.503053
[ "s879605381", "s585586474" ]
u440566786
p03579
python
s518477078
s214065022
385
355
62,316
59,244
Accepted
Accepted
7.79
import sys sys.setrecursionlimit(2147483647) INF=float("inf") MOD=10**9+7 input=lambda:sys.stdin.readline().rstrip() def resolve(): n,m=list(map(int,input().split())) E=[[] for _ in range(n)] for i in range(m): u,v=list(map(int,input().split())) u-=1; v-=1 E[u].append(v) E[v].append(u) # bipartite check col=[-1]*n col[0]=0 Q=[0] while(Q): v=Q.pop() for nv in E[v]: if(col[v]==col[nv]): # 二部グラフではない print((n*(n-1)//2-m)) return elif(col[nv]!=-1 and col[nv]^col[v]): continue col[nv]=1-col[v] Q.append(nv) depth=[-1]*n depth[0]=0 Q=[0] while(Q): v=Q.pop() for nv in E[v]: if(depth[nv]!=-1): continue depth[nv]=depth[v]+1 Q.append(nv) odd=sum(1 for i in range(n) if(depth[i]&1)) even=n-odd ans=odd*even-m print(ans) resolve()
import sys sys.setrecursionlimit(2147483647) INF=float("inf") MOD=10**9+7 input=lambda:sys.stdin.readline().rstrip() def resolve(): n,m=list(map(int,input().split())) E=[[] for _ in range(n)] for i in range(m): u,v=list(map(int,input().split())) u-=1; v-=1 E[u].append(v) E[v].append(u) # bipartite check col=[-1]*n col[0]=0 Q=[0] while(Q): v=Q.pop() for nv in E[v]: if(col[v]==col[nv]): # 二部グラフではない -> 全部繋げられる print((n*(n-1)//2-m)) return elif(col[nv]!=-1 and col[nv]^col[v]): continue col[nv]=1-col[v] Q.append(nv) # 二部グラフ -> 偶数と奇数とが繋げられる even=col.count(0) odd=col.count(1) print((even*odd-m)) resolve()
43
33
999
799
import sys sys.setrecursionlimit(2147483647) INF = float("inf") MOD = 10**9 + 7 input = lambda: sys.stdin.readline().rstrip() def resolve(): n, m = list(map(int, input().split())) E = [[] for _ in range(n)] for i in range(m): u, v = list(map(int, input().split())) u -= 1 v -= 1 E[u].append(v) E[v].append(u) # bipartite check col = [-1] * n col[0] = 0 Q = [0] while Q: v = Q.pop() for nv in E[v]: if col[v] == col[nv]: # 二部グラフではない print((n * (n - 1) // 2 - m)) return elif col[nv] != -1 and col[nv] ^ col[v]: continue col[nv] = 1 - col[v] Q.append(nv) depth = [-1] * n depth[0] = 0 Q = [0] while Q: v = Q.pop() for nv in E[v]: if depth[nv] != -1: continue depth[nv] = depth[v] + 1 Q.append(nv) odd = sum(1 for i in range(n) if (depth[i] & 1)) even = n - odd ans = odd * even - m print(ans) resolve()
import sys sys.setrecursionlimit(2147483647) INF = float("inf") MOD = 10**9 + 7 input = lambda: sys.stdin.readline().rstrip() def resolve(): n, m = list(map(int, input().split())) E = [[] for _ in range(n)] for i in range(m): u, v = list(map(int, input().split())) u -= 1 v -= 1 E[u].append(v) E[v].append(u) # bipartite check col = [-1] * n col[0] = 0 Q = [0] while Q: v = Q.pop() for nv in E[v]: if col[v] == col[nv]: # 二部グラフではない -> 全部繋げられる print((n * (n - 1) // 2 - m)) return elif col[nv] != -1 and col[nv] ^ col[v]: continue col[nv] = 1 - col[v] Q.append(nv) # 二部グラフ -> 偶数と奇数とが繋げられる even = col.count(0) odd = col.count(1) print((even * odd - m)) resolve()
false
23.255814
[ "- if col[v] == col[nv]: # 二部グラフではない", "+ if col[v] == col[nv]: # 二部グラフではない -> 全部繋げられる", "- depth = [-1] * n", "- depth[0] = 0", "- Q = [0]", "- while Q:", "- v = Q.pop()", "- for nv in E[v]:", "- if depth[nv] != -1:", "- continue", "- depth[nv] = depth[v] + 1", "- Q.append(nv)", "- odd = sum(1 for i in range(n) if (depth[i] & 1))", "- even = n - odd", "- ans = odd * even - m", "- print(ans)", "+ # 二部グラフ -> 偶数と奇数とが繋げられる", "+ even = col.count(0)", "+ odd = col.count(1)", "+ print((even * odd - m))" ]
false
0.039411
0.040468
0.973894
[ "s518477078", "s214065022" ]
u021019433
p02866
python
s203564728
s008989314
182
158
22,636
22,636
Accepted
Accepted
13.19
from collections import Counter M = 998244353 n = int(eval(input())) a = list(map(int, input().split())) x, c = next(a), Counter(a) r = 0 if x == c[0] == 0: r = p = 1 for i in range(1, n + 1): x = c[i] if x == 0: break r = r * pow(p, x, M) % M p = x; n -= p print(((r, 0)[n > 1]))
from collections import Counter M = 998244353 n = int(eval(input())) a = list(map(int, input().split())) x, c = next(a), Counter(a) r = 0 if x == c[0] == 0: r = p = 1 try: for i in range(1, n + 1): x = c.get(i) r = r * pow(p, x, M) % M p = x; n -= p except: pass print(((r, 0)[n > 1]))
16
17
309
322
from collections import Counter M = 998244353 n = int(eval(input())) a = list(map(int, input().split())) x, c = next(a), Counter(a) r = 0 if x == c[0] == 0: r = p = 1 for i in range(1, n + 1): x = c[i] if x == 0: break r = r * pow(p, x, M) % M p = x n -= p print(((r, 0)[n > 1]))
from collections import Counter M = 998244353 n = int(eval(input())) a = list(map(int, input().split())) x, c = next(a), Counter(a) r = 0 if x == c[0] == 0: r = p = 1 try: for i in range(1, n + 1): x = c.get(i) r = r * pow(p, x, M) % M p = x n -= p except: pass print(((r, 0)[n > 1]))
false
5.882353
[ "- for i in range(1, n + 1):", "- x = c[i]", "- if x == 0:", "- break", "- r = r * pow(p, x, M) % M", "- p = x", "- n -= p", "+ try:", "+ for i in range(1, n + 1):", "+ x = c.get(i)", "+ r = r * pow(p, x, M) % M", "+ p = x", "+ n -= p", "+ except:", "+ pass" ]
false
0.046562
0.081843
0.568922
[ "s203564728", "s008989314" ]
u077291787
p02996
python
s600630839
s064611791
654
439
45,928
33,488
Accepted
Accepted
32.87
# ABC131D - Megalomania import sys input = sys.stdin.readline from itertools import accumulate def main(): N = int(eval(input())) A = sorted([tuple(map(int, input().split())) for _ in range(N)], key=lambda x: x[1]) T, D = list(zip(*A)) # tasks, deadlines T = list(accumulate(T)) flg = all(t <= d for t, d in zip(T, D)) # all tasks finish within each deadline? print(("Yes" if flg else "No")) if __name__ == "__main__": main()
# ABC131D - Megalomania import sys input = sys.stdin.readline from operator import itemgetter as get def main(): N = int(eval(input())) A = sorted( [tuple(map(int, input().split())) for _ in range(N)], key=get(1) ) cur = 0 for task, deadline in A: # check all tasks greedily cur += task if cur > deadline: # fail to finish a task within its deadline print("No") break else: print("Yes") if __name__ == "__main__": main()
18
23
463
526
# ABC131D - Megalomania import sys input = sys.stdin.readline from itertools import accumulate def main(): N = int(eval(input())) A = sorted([tuple(map(int, input().split())) for _ in range(N)], key=lambda x: x[1]) T, D = list(zip(*A)) # tasks, deadlines T = list(accumulate(T)) flg = all(t <= d for t, d in zip(T, D)) # all tasks finish within each deadline? print(("Yes" if flg else "No")) if __name__ == "__main__": main()
# ABC131D - Megalomania import sys input = sys.stdin.readline from operator import itemgetter as get def main(): N = int(eval(input())) A = sorted([tuple(map(int, input().split())) for _ in range(N)], key=get(1)) cur = 0 for task, deadline in A: # check all tasks greedily cur += task if cur > deadline: # fail to finish a task within its deadline print("No") break else: print("Yes") if __name__ == "__main__": main()
false
21.73913
[ "-from itertools import accumulate", "+from operator import itemgetter as get", "- A = sorted([tuple(map(int, input().split())) for _ in range(N)], key=lambda x: x[1])", "- T, D = list(zip(*A)) # tasks, deadlines", "- T = list(accumulate(T))", "- flg = all(t <= d for t, d in zip(T, D)) # all tasks finish within each deadline?", "- print((\"Yes\" if flg else \"No\"))", "+ A = sorted([tuple(map(int, input().split())) for _ in range(N)], key=get(1))", "+ cur = 0", "+ for task, deadline in A: # check all tasks greedily", "+ cur += task", "+ if cur > deadline: # fail to finish a task within its deadline", "+ print(\"No\")", "+ break", "+ else:", "+ print(\"Yes\")" ]
false
0.035987
0.036945
0.974059
[ "s600630839", "s064611791" ]
u936985471
p04000
python
s583691820
s938762921
1,024
923
145,312
145,440
Accepted
Accepted
9.86
import sys readline = sys.stdin.readline H,W,N = list(map(int,readline().split())) from collections import defaultdict # 9x9のマスの左上のマスの座標をキーにして、各正方形の黒マス数をdictionaryで管理 # 10 ** 5 * 9程度 dic = defaultdict(int) for i in range(N): a,b = list(map(int,readline().split())) a,b = a - 1,b - 1 for A in range(max(0,a - 2), min(a + 1,H - 2)): if A < 0: continue for B in range(max(0,b - 2), min(b + 1,W - 2)): if B < 0: continue dic[(A,B)] += 1 ans = [0] * 10 for v in list(dic.values()): ans[v] += 1 ans[0] = (H - 2) * (W - 2) - sum(ans[1:]) for a in ans: print(a)
import sys readline = sys.stdin.readline H,W,N = list(map(int,readline().split())) from collections import defaultdict # 9x9のマスの左上のマスの座標をキーにして、各正方形の黒マス数をdictionaryで管理 # 10 ** 5 * 9程度 dic = defaultdict(int) for i in range(N): a,b = list(map(int,readline().split())) a,b = a - 1,b - 1 for A in range(max(0,a - 2), min(a + 1,H - 2)): for B in range(max(0,b - 2), min(b + 1,W - 2)): dic[(A,B)] += 1 ans = [0] * 10 for v in list(dic.values()): ans[v] += 1 ans[0] = (H - 2) * (W - 2) - sum(ans[1:]) for a in ans: print(a)
30
26
615
550
import sys readline = sys.stdin.readline H, W, N = list(map(int, readline().split())) from collections import defaultdict # 9x9のマスの左上のマスの座標をキーにして、各正方形の黒マス数をdictionaryで管理 # 10 ** 5 * 9程度 dic = defaultdict(int) for i in range(N): a, b = list(map(int, readline().split())) a, b = a - 1, b - 1 for A in range(max(0, a - 2), min(a + 1, H - 2)): if A < 0: continue for B in range(max(0, b - 2), min(b + 1, W - 2)): if B < 0: continue dic[(A, B)] += 1 ans = [0] * 10 for v in list(dic.values()): ans[v] += 1 ans[0] = (H - 2) * (W - 2) - sum(ans[1:]) for a in ans: print(a)
import sys readline = sys.stdin.readline H, W, N = list(map(int, readline().split())) from collections import defaultdict # 9x9のマスの左上のマスの座標をキーにして、各正方形の黒マス数をdictionaryで管理 # 10 ** 5 * 9程度 dic = defaultdict(int) for i in range(N): a, b = list(map(int, readline().split())) a, b = a - 1, b - 1 for A in range(max(0, a - 2), min(a + 1, H - 2)): for B in range(max(0, b - 2), min(b + 1, W - 2)): dic[(A, B)] += 1 ans = [0] * 10 for v in list(dic.values()): ans[v] += 1 ans[0] = (H - 2) * (W - 2) - sum(ans[1:]) for a in ans: print(a)
false
13.333333
[ "- if A < 0:", "- continue", "- if B < 0:", "- continue" ]
false
0.155956
0.171798
0.907786
[ "s583691820", "s938762921" ]
u945181840
p03682
python
s967193530
s198802969
742
293
49,012
36,040
Accepted
Accepted
60.51
import sys import numpy as np read = sys.stdin.read class UnionFind(): # 作りたい要素数nで初期化 # 使用するインスタンス変数の初期化 def __init__(self, n): self.n = n # root[x]<0ならそのノードが根かつその値が木の要素数 # rootノードでその木の要素数を記録する self.root = [-1]*(n+1) # 木をくっつける時にアンバランスにならないように調整する self.rnk = [0]*(n+1) # ノードxのrootノードを見つける def Find_Root(self, x): if self.root[x] < 0: return x else: # ここで代入しておくことで、後の繰り返しを避ける self.root[x] = self.Find_Root(self.root[x]) return self.root[x] # 木の併合、入力は併合したい各ノード def Unite(self, x, y): # 入力ノードのrootノードを見つける x = self.Find_Root(x) y = self.Find_Root(y) # すでに同じ木に属していた場合 if x == y: return # 違う木に属していた場合rnkを見てくっつける方を決める elif self.rnk[x] > self.rnk[y]: self.root[x] += self.root[y] self.root[y] = x else: self.root[y] += self.root[x] self.root[x] = y # rnkが同じ(深さに差がない場合)は1増やす if self.rnk[x] == self.rnk[y]: self.rnk[y] += 1 # xとyが同じグループに属するか判断 def isSameGroup(self, x, y): return self.Find_Root(x) == self.Find_Root(y) # ノードxが属する木のサイズを返す def Count(self, x): return -self.root[self.Find_Root(x)] N, *xy = list(map(int, read().split())) xy = np.array(xy, np.int64).reshape(N, 2) x = xy[:, 0] y = xy[:, 1] arg_x = np.argsort(x) arg_y = np.argsort(y) edges_x = x[arg_x[1:]] - x[arg_x[:-1]] edges_y = y[arg_y[1:]] - y[arg_y[:-1]] edges = np.concatenate([edges_x, edges_y]) towns_1 = np.concatenate([arg_x[:-1], arg_y[:-1]]) towns_2 = np.concatenate([arg_x[1:], arg_y[1:]]) arg_edges = np.argsort(edges) graph = list(zip(edges[arg_edges].tolist(), towns_1[arg_edges].tolist(), towns_2[arg_edges].tolist())) tree = UnionFind(N) answer = 0 for d, t1, t2 in graph: if tree.isSameGroup(t1, t2): continue tree.Unite(t1, t2) answer += d print(answer)
import sys import numpy as np from scipy.sparse import coo_matrix from scipy.sparse.csgraph import minimum_spanning_tree read = sys.stdin.read N, *xy = list(map(int, read().split())) xy = np.array(xy, np.int64).reshape(N, 2) x = xy[:, 0] y = xy[:, 1] arg_x = np.argsort(x) arg_x1 = arg_x[1:] arg_x2 = arg_x[:-1] arg_y = np.argsort(y) arg_y1 = arg_y[1:] arg_y2 = arg_y[:-1] edges_x = x[arg_x1] - x[arg_x2] edges_y = y[arg_y1] - y[arg_y2] edges = np.concatenate([edges_x, edges_y]) towns_1 = np.concatenate([np.minimum(arg_x1, arg_x2), np.maximum(arg_y1, arg_y2)]) towns_2 = np.concatenate([np.maximum(arg_x1, arg_x2), np.minimum(arg_y1, arg_y2)]) graph = coo_matrix((edges, (towns_1, towns_2)), shape=(N, N)) tree = minimum_spanning_tree(graph, overwrite=True) answer = int(tree.sum()) print(answer)
83
31
2,071
829
import sys import numpy as np read = sys.stdin.read class UnionFind: # 作りたい要素数nで初期化 # 使用するインスタンス変数の初期化 def __init__(self, n): self.n = n # root[x]<0ならそのノードが根かつその値が木の要素数 # rootノードでその木の要素数を記録する self.root = [-1] * (n + 1) # 木をくっつける時にアンバランスにならないように調整する self.rnk = [0] * (n + 1) # ノードxのrootノードを見つける def Find_Root(self, x): if self.root[x] < 0: return x else: # ここで代入しておくことで、後の繰り返しを避ける self.root[x] = self.Find_Root(self.root[x]) return self.root[x] # 木の併合、入力は併合したい各ノード def Unite(self, x, y): # 入力ノードのrootノードを見つける x = self.Find_Root(x) y = self.Find_Root(y) # すでに同じ木に属していた場合 if x == y: return # 違う木に属していた場合rnkを見てくっつける方を決める elif self.rnk[x] > self.rnk[y]: self.root[x] += self.root[y] self.root[y] = x else: self.root[y] += self.root[x] self.root[x] = y # rnkが同じ(深さに差がない場合)は1増やす if self.rnk[x] == self.rnk[y]: self.rnk[y] += 1 # xとyが同じグループに属するか判断 def isSameGroup(self, x, y): return self.Find_Root(x) == self.Find_Root(y) # ノードxが属する木のサイズを返す def Count(self, x): return -self.root[self.Find_Root(x)] N, *xy = list(map(int, read().split())) xy = np.array(xy, np.int64).reshape(N, 2) x = xy[:, 0] y = xy[:, 1] arg_x = np.argsort(x) arg_y = np.argsort(y) edges_x = x[arg_x[1:]] - x[arg_x[:-1]] edges_y = y[arg_y[1:]] - y[arg_y[:-1]] edges = np.concatenate([edges_x, edges_y]) towns_1 = np.concatenate([arg_x[:-1], arg_y[:-1]]) towns_2 = np.concatenate([arg_x[1:], arg_y[1:]]) arg_edges = np.argsort(edges) graph = list( zip( edges[arg_edges].tolist(), towns_1[arg_edges].tolist(), towns_2[arg_edges].tolist(), ) ) tree = UnionFind(N) answer = 0 for d, t1, t2 in graph: if tree.isSameGroup(t1, t2): continue tree.Unite(t1, t2) answer += d print(answer)
import sys import numpy as np from scipy.sparse import coo_matrix from scipy.sparse.csgraph import minimum_spanning_tree read = sys.stdin.read N, *xy = list(map(int, read().split())) xy = np.array(xy, np.int64).reshape(N, 2) x = xy[:, 0] y = xy[:, 1] arg_x = np.argsort(x) arg_x1 = arg_x[1:] arg_x2 = arg_x[:-1] arg_y = np.argsort(y) arg_y1 = arg_y[1:] arg_y2 = arg_y[:-1] edges_x = x[arg_x1] - x[arg_x2] edges_y = y[arg_y1] - y[arg_y2] edges = np.concatenate([edges_x, edges_y]) towns_1 = np.concatenate([np.minimum(arg_x1, arg_x2), np.maximum(arg_y1, arg_y2)]) towns_2 = np.concatenate([np.maximum(arg_x1, arg_x2), np.minimum(arg_y1, arg_y2)]) graph = coo_matrix((edges, (towns_1, towns_2)), shape=(N, N)) tree = minimum_spanning_tree(graph, overwrite=True) answer = int(tree.sum()) print(answer)
false
62.650602
[ "+from scipy.sparse import coo_matrix", "+from scipy.sparse.csgraph import minimum_spanning_tree", "-", "-", "-class UnionFind:", "- # 作りたい要素数nで初期化", "- # 使用するインスタンス変数の初期化", "- def __init__(self, n):", "- self.n = n", "- # root[x]<0ならそのノードが根かつその値が木の要素数", "- # rootノードでその木の要素数を記録する", "- self.root = [-1] * (n + 1)", "- # 木をくっつける時にアンバランスにならないように調整する", "- self.rnk = [0] * (n + 1)", "-", "- # ノードxのrootノードを見つける", "- def Find_Root(self, x):", "- if self.root[x] < 0:", "- return x", "- else:", "- # ここで代入しておくことで、後の繰り返しを避ける", "- self.root[x] = self.Find_Root(self.root[x])", "- return self.root[x]", "-", "- # 木の併合、入力は併合したい各ノード", "- def Unite(self, x, y):", "- # 入力ノードのrootノードを見つける", "- x = self.Find_Root(x)", "- y = self.Find_Root(y)", "- # すでに同じ木に属していた場合", "- if x == y:", "- return", "- # 違う木に属していた場合rnkを見てくっつける方を決める", "- elif self.rnk[x] > self.rnk[y]:", "- self.root[x] += self.root[y]", "- self.root[y] = x", "- else:", "- self.root[y] += self.root[x]", "- self.root[x] = y", "- # rnkが同じ(深さに差がない場合)は1増やす", "- if self.rnk[x] == self.rnk[y]:", "- self.rnk[y] += 1", "-", "- # xとyが同じグループに属するか判断", "- def isSameGroup(self, x, y):", "- return self.Find_Root(x) == self.Find_Root(y)", "-", "- # ノードxが属する木のサイズを返す", "- def Count(self, x):", "- return -self.root[self.Find_Root(x)]", "-", "-", "+arg_x1 = arg_x[1:]", "+arg_x2 = arg_x[:-1]", "-edges_x = x[arg_x[1:]] - x[arg_x[:-1]]", "-edges_y = y[arg_y[1:]] - y[arg_y[:-1]]", "+arg_y1 = arg_y[1:]", "+arg_y2 = arg_y[:-1]", "+edges_x = x[arg_x1] - x[arg_x2]", "+edges_y = y[arg_y1] - y[arg_y2]", "-towns_1 = np.concatenate([arg_x[:-1], arg_y[:-1]])", "-towns_2 = np.concatenate([arg_x[1:], arg_y[1:]])", "-arg_edges = np.argsort(edges)", "-graph = list(", "- zip(", "- edges[arg_edges].tolist(),", "- towns_1[arg_edges].tolist(),", "- towns_2[arg_edges].tolist(),", "- )", "-)", "-tree = UnionFind(N)", "-answer = 0", "-for d, t1, t2 in graph:", "- if tree.isSameGroup(t1, t2):", "- continue", "- tree.Unite(t1, t2)", "- answer += d", "+towns_1 = np.concatenate([np.minimum(arg_x1, arg_x2), np.maximum(arg_y1, arg_y2)])", "+towns_2 = np.concatenate([np.maximum(arg_x1, arg_x2), np.minimum(arg_y1, arg_y2)])", "+graph = coo_matrix((edges, (towns_1, towns_2)), shape=(N, N))", "+tree = minimum_spanning_tree(graph, overwrite=True)", "+answer = int(tree.sum())" ]
false
0.226156
0.697627
0.324178
[ "s967193530", "s198802969" ]
u790710233
p02659
python
s075460629
s610262851
26
21
10,068
9,064
Accepted
Accepted
19.23
from decimal import Decimal a, b = list(map(Decimal, input().split())) print((int(a*b)))
a, b = input().split() a = int(a) b = int(b.replace('.', '')) print((a*b//100))
3
4
83
80
from decimal import Decimal a, b = list(map(Decimal, input().split())) print((int(a * b)))
a, b = input().split() a = int(a) b = int(b.replace(".", "")) print((a * b // 100))
false
25
[ "-from decimal import Decimal", "-", "-a, b = list(map(Decimal, input().split()))", "-print((int(a * b)))", "+a, b = input().split()", "+a = int(a)", "+b = int(b.replace(\".\", \"\"))", "+print((a * b // 100))" ]
false
0.039468
0.036415
1.083842
[ "s075460629", "s610262851" ]
u644907318
p04035
python
s203557716
s848044202
303
124
63,984
86,000
Accepted
Accepted
59.08
N,L = list(map(int,input().split())) A = list(map(int,input().split())) A.insert(0,0) flag = 0 for i in range(1,N): if A[i]+A[i+1]>=L: flag = i break if flag == 0: print("Impossible") else: print("Possible") if flag==1: for i in range(N-1,0,-1): print(i) else: for i in range(1,flag): print(i) for i in range(N-1,flag-1,-1): print(i)
N,L = list(map(int,input().split())) A = list(map(int,input().split())) A.insert(0,0) cmax = 0 ind = -1 for i in range(1,N): if A[i]+A[i+1]>cmax: cmax = A[i]+A[i+1] ind = i if cmax>=L: print("Possible") for i in range(1,ind): print(i) for i in range(N-1,ind-1,-1): print(i) else: print("Impossible")
20
17
442
361
N, L = list(map(int, input().split())) A = list(map(int, input().split())) A.insert(0, 0) flag = 0 for i in range(1, N): if A[i] + A[i + 1] >= L: flag = i break if flag == 0: print("Impossible") else: print("Possible") if flag == 1: for i in range(N - 1, 0, -1): print(i) else: for i in range(1, flag): print(i) for i in range(N - 1, flag - 1, -1): print(i)
N, L = list(map(int, input().split())) A = list(map(int, input().split())) A.insert(0, 0) cmax = 0 ind = -1 for i in range(1, N): if A[i] + A[i + 1] > cmax: cmax = A[i] + A[i + 1] ind = i if cmax >= L: print("Possible") for i in range(1, ind): print(i) for i in range(N - 1, ind - 1, -1): print(i) else: print("Impossible")
false
15
[ "-flag = 0", "+cmax = 0", "+ind = -1", "- if A[i] + A[i + 1] >= L:", "- flag = i", "- break", "-if flag == 0:", "+ if A[i] + A[i + 1] > cmax:", "+ cmax = A[i] + A[i + 1]", "+ ind = i", "+if cmax >= L:", "+ print(\"Possible\")", "+ for i in range(1, ind):", "+ print(i)", "+ for i in range(N - 1, ind - 1, -1):", "+ print(i)", "+else:", "-else:", "- print(\"Possible\")", "- if flag == 1:", "- for i in range(N - 1, 0, -1):", "- print(i)", "- else:", "- for i in range(1, flag):", "- print(i)", "- for i in range(N - 1, flag - 1, -1):", "- print(i)" ]
false
0.03827
0.037344
1.024791
[ "s203557716", "s848044202" ]
u532966492
p03313
python
s920687972
s968320229
1,812
1,098
57,620
130,124
Accepted
Accepted
39.4
def main(): n = int(eval(input())) a = list(map(int, input().split())) d = [None]*(2**n) d[0] = [a[0], 0, -1, -1] ans = 0 for i, t1 in enumerate(a[1:]): i += 1 t2, t3, t4 = i, -1, -1 for j in range(len(bin(i))-2): k = i & ~(1 << j) if k == i: continue t5, t6, t7, t8 = d[k] if t5 > t1: t1, t2, t3, t4 = t5, t6, t1, t2 elif t5 > t3: if t6 != t2: t3, t4 = t5, t6 if t7 > t3: t3, t4 = t7, t8 d[i] = [t1, t2, t3, t4] ans = max(ans, t1+t3) print(ans) main()
def main(): n = int(eval(input())) a = list(map(int, input().split())) d = [[j, i, -1, -1] for i, j in enumerate(a)] ans = 0 for i in range(1, 2**n): t1, t2, t3, t4 = d[i] for j in range(len(bin(i))-2): t5, t6, t7, t8 = d[i & ~(1 << j)] if t5 > t1: t1, t2, t3, t4 = t5, t6, t1, t2 elif t5 > t3: if t6 != t2: t3, t4 = t5, t6 continue if t7 > t3: t3, t4 = t7, t8 d[i] = [t1, t2, t3, t4] ans = max(ans, t1+t3) print(ans) main()
27
23
702
638
def main(): n = int(eval(input())) a = list(map(int, input().split())) d = [None] * (2**n) d[0] = [a[0], 0, -1, -1] ans = 0 for i, t1 in enumerate(a[1:]): i += 1 t2, t3, t4 = i, -1, -1 for j in range(len(bin(i)) - 2): k = i & ~(1 << j) if k == i: continue t5, t6, t7, t8 = d[k] if t5 > t1: t1, t2, t3, t4 = t5, t6, t1, t2 elif t5 > t3: if t6 != t2: t3, t4 = t5, t6 if t7 > t3: t3, t4 = t7, t8 d[i] = [t1, t2, t3, t4] ans = max(ans, t1 + t3) print(ans) main()
def main(): n = int(eval(input())) a = list(map(int, input().split())) d = [[j, i, -1, -1] for i, j in enumerate(a)] ans = 0 for i in range(1, 2**n): t1, t2, t3, t4 = d[i] for j in range(len(bin(i)) - 2): t5, t6, t7, t8 = d[i & ~(1 << j)] if t5 > t1: t1, t2, t3, t4 = t5, t6, t1, t2 elif t5 > t3: if t6 != t2: t3, t4 = t5, t6 continue if t7 > t3: t3, t4 = t7, t8 d[i] = [t1, t2, t3, t4] ans = max(ans, t1 + t3) print(ans) main()
false
14.814815
[ "- d = [None] * (2**n)", "- d[0] = [a[0], 0, -1, -1]", "+ d = [[j, i, -1, -1] for i, j in enumerate(a)]", "- for i, t1 in enumerate(a[1:]):", "- i += 1", "- t2, t3, t4 = i, -1, -1", "+ for i in range(1, 2**n):", "+ t1, t2, t3, t4 = d[i]", "- k = i & ~(1 << j)", "- if k == i:", "- continue", "- t5, t6, t7, t8 = d[k]", "+ t5, t6, t7, t8 = d[i & ~(1 << j)]", "+ continue" ]
false
0.043134
0.037376
1.154055
[ "s920687972", "s968320229" ]
u893063840
p03732
python
s924168815
s844859407
263
36
3,064
3,064
Accepted
Accepted
86.31
from itertools import accumulate n, W = list(map(int, input().split())) wv = [list(map(int, input().split())) for _ in range(n)] w1 = wv[0][0] weights = [[] for _ in range(4)] for w, v in wv: w_diff = w - w1 weights[w_diff].append(v) for i in range(4): weights[i].sort(reverse=True) acc = [[0] + list(accumulate(li)) for li in weights] ans = 0 for i, e1 in enumerate(acc[0]): for j, e2 in enumerate(acc[1]): for k, e3 in enumerate(acc[2]): for l, e4 in enumerate(acc[3]): if w1 * i + (w1 + 1) * j + (w1 + 2) * k + (w1 + 3) * l <= W: ans = max(ans, e1 + e2 + e3 + e4) print(ans)
from itertools import accumulate n, W = list(map(int, input().split())) wv = [list(map(int, input().split())) for _ in range(n)] w1 = wv[0][0] weights = [[] for _ in range(4)] for w, v in wv: w_diff = w - w1 weights[w_diff].append(v) for i in range(4): weights[i].sort(reverse=True) acc = [[0] + list(accumulate(li)) for li in weights] l3 = len(weights[3]) ans = 0 for i, e1 in enumerate(acc[0]): for j, e2 in enumerate(acc[1]): for k, e3 in enumerate(acc[2]): w_sm = w1 * i + (w1 + 1) * j + (w1 + 2) * k if w_sm > W: break l = min((W - w_sm) // (w1 + 3), l3) val = acc[0][i] + acc[1][j] + acc[2][k] + acc[3][l] ans = max(ans, val) print(ans)
26
31
676
775
from itertools import accumulate n, W = list(map(int, input().split())) wv = [list(map(int, input().split())) for _ in range(n)] w1 = wv[0][0] weights = [[] for _ in range(4)] for w, v in wv: w_diff = w - w1 weights[w_diff].append(v) for i in range(4): weights[i].sort(reverse=True) acc = [[0] + list(accumulate(li)) for li in weights] ans = 0 for i, e1 in enumerate(acc[0]): for j, e2 in enumerate(acc[1]): for k, e3 in enumerate(acc[2]): for l, e4 in enumerate(acc[3]): if w1 * i + (w1 + 1) * j + (w1 + 2) * k + (w1 + 3) * l <= W: ans = max(ans, e1 + e2 + e3 + e4) print(ans)
from itertools import accumulate n, W = list(map(int, input().split())) wv = [list(map(int, input().split())) for _ in range(n)] w1 = wv[0][0] weights = [[] for _ in range(4)] for w, v in wv: w_diff = w - w1 weights[w_diff].append(v) for i in range(4): weights[i].sort(reverse=True) acc = [[0] + list(accumulate(li)) for li in weights] l3 = len(weights[3]) ans = 0 for i, e1 in enumerate(acc[0]): for j, e2 in enumerate(acc[1]): for k, e3 in enumerate(acc[2]): w_sm = w1 * i + (w1 + 1) * j + (w1 + 2) * k if w_sm > W: break l = min((W - w_sm) // (w1 + 3), l3) val = acc[0][i] + acc[1][j] + acc[2][k] + acc[3][l] ans = max(ans, val) print(ans)
false
16.129032
[ "+l3 = len(weights[3])", "- for l, e4 in enumerate(acc[3]):", "- if w1 * i + (w1 + 1) * j + (w1 + 2) * k + (w1 + 3) * l <= W:", "- ans = max(ans, e1 + e2 + e3 + e4)", "+ w_sm = w1 * i + (w1 + 1) * j + (w1 + 2) * k", "+ if w_sm > W:", "+ break", "+ l = min((W - w_sm) // (w1 + 3), l3)", "+ val = acc[0][i] + acc[1][j] + acc[2][k] + acc[3][l]", "+ ans = max(ans, val)" ]
false
0.093148
0.039591
2.352752
[ "s924168815", "s844859407" ]
u863442865
p03503
python
s604898681
s015873982
175
74
3,316
3,064
Accepted
Accepted
57.71
def main(): import sys #input = sys.stdin.readline sys.setrecursionlimit(10000000) from collections import Counter from collections import deque #dxy = [[0,1],[0,-1],[1,0],[-1,0]] #dxy = [[0,1],[0,-1],[1,0],[-1,0],[1,1],[1,-1],[-1,1],[-1,-1]] #mod = 1000000007 n = int(eval(input())) F = [input().split() for _ in range(n)] P = [list(map(int, input().split())) for _ in range(n)] ans = -10**10 for i in range(1, 1033): a = list(str(format(i, '010b'))) total = 0 for j in range(n): cnt = 0 for k in range(10): if F[j][k]=='1' and a[k]=='1': cnt += 1 total += P[j][cnt] if total>ans: ans = total print(ans) if __name__ == '__main__': main()
N=int(eval(input())) SO=[int(input().replace(' ',''), 2) for i in range(N)] PT=[list(map(int,input().split())) for i in range(N)] ret=-10**7*N for sp in range(1,2**10): r=0 for i in range(N): r+=PT[i][bin(SO[i] & sp).count('1')] ret=max(ret,r) print(ret)
34
10
848
267
def main(): import sys # input = sys.stdin.readline sys.setrecursionlimit(10000000) from collections import Counter from collections import deque # dxy = [[0,1],[0,-1],[1,0],[-1,0]] # dxy = [[0,1],[0,-1],[1,0],[-1,0],[1,1],[1,-1],[-1,1],[-1,-1]] # mod = 1000000007 n = int(eval(input())) F = [input().split() for _ in range(n)] P = [list(map(int, input().split())) for _ in range(n)] ans = -(10**10) for i in range(1, 1033): a = list(str(format(i, "010b"))) total = 0 for j in range(n): cnt = 0 for k in range(10): if F[j][k] == "1" and a[k] == "1": cnt += 1 total += P[j][cnt] if total > ans: ans = total print(ans) if __name__ == "__main__": main()
N = int(eval(input())) SO = [int(input().replace(" ", ""), 2) for i in range(N)] PT = [list(map(int, input().split())) for i in range(N)] ret = -(10**7) * N for sp in range(1, 2**10): r = 0 for i in range(N): r += PT[i][bin(SO[i] & sp).count("1")] ret = max(ret, r) print(ret)
false
70.588235
[ "-def main():", "- import sys", "-", "- # input = sys.stdin.readline", "- sys.setrecursionlimit(10000000)", "- from collections import Counter", "- from collections import deque", "-", "- # dxy = [[0,1],[0,-1],[1,0],[-1,0]]", "- # dxy = [[0,1],[0,-1],[1,0],[-1,0],[1,1],[1,-1],[-1,1],[-1,-1]]", "- # mod = 1000000007", "- n = int(eval(input()))", "- F = [input().split() for _ in range(n)]", "- P = [list(map(int, input().split())) for _ in range(n)]", "- ans = -(10**10)", "- for i in range(1, 1033):", "- a = list(str(format(i, \"010b\")))", "- total = 0", "- for j in range(n):", "- cnt = 0", "- for k in range(10):", "- if F[j][k] == \"1\" and a[k] == \"1\":", "- cnt += 1", "- total += P[j][cnt]", "- if total > ans:", "- ans = total", "- print(ans)", "-", "-", "-if __name__ == \"__main__\":", "- main()", "+N = int(eval(input()))", "+SO = [int(input().replace(\" \", \"\"), 2) for i in range(N)]", "+PT = [list(map(int, input().split())) for i in range(N)]", "+ret = -(10**7) * N", "+for sp in range(1, 2**10):", "+ r = 0", "+ for i in range(N):", "+ r += PT[i][bin(SO[i] & sp).count(\"1\")]", "+ ret = max(ret, r)", "+print(ret)" ]
false
0.037769
0.036953
1.022074
[ "s604898681", "s015873982" ]
u729133443
p03807
python
s880209288
s407903654
52
40
11,104
11,104
Accepted
Accepted
23.08
eval(input());print(('YNEOS'[sum(int(i)%2for i in input().split())%2::2]))
eval(input());print(('YNEOS'[sum(map(int,input().split()))%2::2]))
1
1
66
58
eval(input()) print(("YNEOS"[sum(int(i) % 2 for i in input().split()) % 2 :: 2]))
eval(input()) print(("YNEOS"[sum(map(int, input().split())) % 2 :: 2]))
false
0
[ "-print((\"YNEOS\"[sum(int(i) % 2 for i in input().split()) % 2 :: 2]))", "+print((\"YNEOS\"[sum(map(int, input().split())) % 2 :: 2]))" ]
false
0.045679
0.042054
1.0862
[ "s880209288", "s407903654" ]
u488401358
p02983
python
s127184919
s833458057
535
43
3,060
3,060
Accepted
Accepted
91.96
L,R=list(map(int,input().split())) if R-L+1>=2019: print((0)) else: m=2019 for i in range(L,R): for j in range(i+1,R+1): x=(i*j)%2019 if x<m: m=x print(m)
L,R=list(map(int,input().split())) if R-L+1>=671: print((0)) else: m=2019 for i in range(L,R): for j in range(i+1,R+1): x=(i*j)%2019 if x<m: m=x print(m)
11
11
220
219
L, R = list(map(int, input().split())) if R - L + 1 >= 2019: print((0)) else: m = 2019 for i in range(L, R): for j in range(i + 1, R + 1): x = (i * j) % 2019 if x < m: m = x print(m)
L, R = list(map(int, input().split())) if R - L + 1 >= 671: print((0)) else: m = 2019 for i in range(L, R): for j in range(i + 1, R + 1): x = (i * j) % 2019 if x < m: m = x print(m)
false
0
[ "-if R - L + 1 >= 2019:", "+if R - L + 1 >= 671:" ]
false
0.040977
0.036393
1.125975
[ "s127184919", "s833458057" ]
u633068244
p00138
python
s447018738
s451613907
20
10
4,292
4,272
Accepted
Accepted
50
an1, at1, an2, at2 = 0, 1000, 0, 1000 for i in range(3): n1, t1, n2, t2 = 0, 1000, 0, 1000 for j in range(8): n, t = list(map(float, input().split())) if t < t1: if t2 < at1: an1 = n2; at1 = t2 elif t2 < at2: an2 = n2; at2 = t2 n2 = n1; t2 = t1 n1 = n ; t1 = t elif t < t2: if t2 < at1: an1 = n2; at1 = t2 elif t2 < at2: an2 = n2; at2 = t2 n2 = n ; t2 = t else: if t < at1: an1 = n; at1 = t elif t < at2: an2 = n; at2 = t print("%d %4.2f"%(int(n1), t1)) print("%d %4.2f"%(int(n2), t2)) print("%d %4.2f"%(int(an1), at1)) print("%d %4.2f"%(int(an2), at2))
def check(x,y): global an1,at1,an2,at2 if y < at1: an1,at1 = x,y elif y < at2: an2,at2 = x,y an1, at1, an2, at2 = 0, 1000, 0, 1000 for i in range(3): n1, t1, n2, t2 = 0, 1000, 0, 1000 for j in range(8): n, t = list(map(float, input().split())) if t < t1: check(n2,t2) n1,t1,n2,t2 = n,t,n1,t1 elif t < t2: check(n2,t2) n2, t2 = n, t else: check(n,t) print("%d %4.2f"%(int(n1), t1)) print("%d %4.2f"%(int(n2), t2)) print("%d %4.2f"%(int(an1), at1)) print("%d %4.2f"%(int(an2), at2))
27
24
825
634
an1, at1, an2, at2 = 0, 1000, 0, 1000 for i in range(3): n1, t1, n2, t2 = 0, 1000, 0, 1000 for j in range(8): n, t = list(map(float, input().split())) if t < t1: if t2 < at1: an1 = n2 at1 = t2 elif t2 < at2: an2 = n2 at2 = t2 n2 = n1 t2 = t1 n1 = n t1 = t elif t < t2: if t2 < at1: an1 = n2 at1 = t2 elif t2 < at2: an2 = n2 at2 = t2 n2 = n t2 = t else: if t < at1: an1 = n at1 = t elif t < at2: an2 = n at2 = t print("%d %4.2f" % (int(n1), t1)) print("%d %4.2f" % (int(n2), t2)) print("%d %4.2f" % (int(an1), at1)) print("%d %4.2f" % (int(an2), at2))
def check(x, y): global an1, at1, an2, at2 if y < at1: an1, at1 = x, y elif y < at2: an2, at2 = x, y an1, at1, an2, at2 = 0, 1000, 0, 1000 for i in range(3): n1, t1, n2, t2 = 0, 1000, 0, 1000 for j in range(8): n, t = list(map(float, input().split())) if t < t1: check(n2, t2) n1, t1, n2, t2 = n, t, n1, t1 elif t < t2: check(n2, t2) n2, t2 = n, t else: check(n, t) print("%d %4.2f" % (int(n1), t1)) print("%d %4.2f" % (int(n2), t2)) print("%d %4.2f" % (int(an1), at1)) print("%d %4.2f" % (int(an2), at2))
false
11.111111
[ "+def check(x, y):", "+ global an1, at1, an2, at2", "+ if y < at1:", "+ an1, at1 = x, y", "+ elif y < at2:", "+ an2, at2 = x, y", "+", "+", "- if t2 < at1:", "- an1 = n2", "- at1 = t2", "- elif t2 < at2:", "- an2 = n2", "- at2 = t2", "- n2 = n1", "- t2 = t1", "- n1 = n", "- t1 = t", "+ check(n2, t2)", "+ n1, t1, n2, t2 = n, t, n1, t1", "- if t2 < at1:", "- an1 = n2", "- at1 = t2", "- elif t2 < at2:", "- an2 = n2", "- at2 = t2", "- n2 = n", "- t2 = t", "+ check(n2, t2)", "+ n2, t2 = n, t", "- if t < at1:", "- an1 = n", "- at1 = t", "- elif t < at2:", "- an2 = n", "- at2 = t", "+ check(n, t)" ]
false
0.076291
0.037782
2.019241
[ "s447018738", "s451613907" ]
u977389981
p03162
python
s030817301
s341933325
532
421
22,772
3,064
Accepted
Accepted
20.86
n = int(eval(input())) dp = [[0] * 3 for _ in range(n)] dp[0] = list(map(int, input().split())) for i in range(1, n): a, b, c = list(map(int, input().split())) dp[i][0] = a + max(dp[i - 1][1], dp[i - 1][2]) dp[i][1] = b + max(dp[i - 1][0], dp[i - 1][2]) dp[i][2] = c + max(dp[i - 1][0], dp[i - 1][1]) print((max(dp[-1])))
n = int(eval(input())) dp = [0] * 3 for i in range(n): a, b, c = list(map(int, input().split())) dp = [a + max(dp[1], dp[2]), b + max(dp[0], dp[2]), c + max(dp[0], dp[1])] print((max(dp)))
11
8
339
201
n = int(eval(input())) dp = [[0] * 3 for _ in range(n)] dp[0] = list(map(int, input().split())) for i in range(1, n): a, b, c = list(map(int, input().split())) dp[i][0] = a + max(dp[i - 1][1], dp[i - 1][2]) dp[i][1] = b + max(dp[i - 1][0], dp[i - 1][2]) dp[i][2] = c + max(dp[i - 1][0], dp[i - 1][1]) print((max(dp[-1])))
n = int(eval(input())) dp = [0] * 3 for i in range(n): a, b, c = list(map(int, input().split())) dp = [a + max(dp[1], dp[2]), b + max(dp[0], dp[2]), c + max(dp[0], dp[1])] print((max(dp)))
false
27.272727
[ "-dp = [[0] * 3 for _ in range(n)]", "-dp[0] = list(map(int, input().split()))", "-for i in range(1, n):", "+dp = [0] * 3", "+for i in range(n):", "- dp[i][0] = a + max(dp[i - 1][1], dp[i - 1][2])", "- dp[i][1] = b + max(dp[i - 1][0], dp[i - 1][2])", "- dp[i][2] = c + max(dp[i - 1][0], dp[i - 1][1])", "-print((max(dp[-1])))", "+ dp = [a + max(dp[1], dp[2]), b + max(dp[0], dp[2]), c + max(dp[0], dp[1])]", "+print((max(dp)))" ]
false
0.036809
0.037635
0.978071
[ "s030817301", "s341933325" ]
u790710233
p03330
python
s952709806
s804361417
209
170
3,444
3,444
Accepted
Accepted
18.66
from collections import defaultdict import itertools n, c = list(map(int, input().split())) D = [list(map(int, input().split()))for _ in range(c)] # 集計 diago = [defaultdict(int)for _ in range(3)] for i in range(n): for j, color in enumerate(map(int, input().split())): color -= 1 if (i+j) % 3 == 0: diago[0][color] += 1 elif (i+j) % 3 == 1: diago[1][color] += 1 else: diago[2][color] += 1 # 0列目をcにするときのcにするときの最小コスト costs = [[0]*c for _ in range(3)] for i in range(3): for j in range(c): for k, v in list(diago[i].items()): costs[i][j] += D[k][j]*v INF = 10**18 ans = INF for trio in itertools.combinations(list(range(c)), 3): for color in itertools.permutations(trio, 3): cost = sum(costs[i][j] for i, j in enumerate(color)) if cost < ans: ans = cost print(ans)
# リファクタ from collections import defaultdict import itertools n, c = list(map(int, input().split())) D = [list(map(int, input().split()))for _ in range(c)] # 集計 diago = [defaultdict(int)for _ in range(3)] for i in range(n): for j, color in enumerate(map(int, input().split())): diago[(i+j) % 3][color-1] += 1 # 0列目をcにするときのcにするときの最小コスト costs = [[0]*c for _ in range(3)] for i in range(3): for j in range(c): for k, v in list(diago[i].items()): costs[i][j] += D[k][j]*v INF = 10**18 ans = INF for trio in itertools.combinations(list(range(c)), 3): for color in itertools.permutations(trio, 3): cost = sum(costs[i][j] for i, j in enumerate(color)) if cost < ans: ans = cost print(ans)
33
27
907
759
from collections import defaultdict import itertools n, c = list(map(int, input().split())) D = [list(map(int, input().split())) for _ in range(c)] # 集計 diago = [defaultdict(int) for _ in range(3)] for i in range(n): for j, color in enumerate(map(int, input().split())): color -= 1 if (i + j) % 3 == 0: diago[0][color] += 1 elif (i + j) % 3 == 1: diago[1][color] += 1 else: diago[2][color] += 1 # 0列目をcにするときのcにするときの最小コスト costs = [[0] * c for _ in range(3)] for i in range(3): for j in range(c): for k, v in list(diago[i].items()): costs[i][j] += D[k][j] * v INF = 10**18 ans = INF for trio in itertools.combinations(list(range(c)), 3): for color in itertools.permutations(trio, 3): cost = sum(costs[i][j] for i, j in enumerate(color)) if cost < ans: ans = cost print(ans)
# リファクタ from collections import defaultdict import itertools n, c = list(map(int, input().split())) D = [list(map(int, input().split())) for _ in range(c)] # 集計 diago = [defaultdict(int) for _ in range(3)] for i in range(n): for j, color in enumerate(map(int, input().split())): diago[(i + j) % 3][color - 1] += 1 # 0列目をcにするときのcにするときの最小コスト costs = [[0] * c for _ in range(3)] for i in range(3): for j in range(c): for k, v in list(diago[i].items()): costs[i][j] += D[k][j] * v INF = 10**18 ans = INF for trio in itertools.combinations(list(range(c)), 3): for color in itertools.permutations(trio, 3): cost = sum(costs[i][j] for i, j in enumerate(color)) if cost < ans: ans = cost print(ans)
false
18.181818
[ "+# リファクタ", "- color -= 1", "- if (i + j) % 3 == 0:", "- diago[0][color] += 1", "- elif (i + j) % 3 == 1:", "- diago[1][color] += 1", "- else:", "- diago[2][color] += 1", "+ diago[(i + j) % 3][color - 1] += 1" ]
false
0.090348
0.08766
1.030664
[ "s952709806", "s804361417" ]
u440566786
p03163
python
s227042371
s417200681
1,674
405
145,668
118,128
Accepted
Accepted
75.81
import sys sys.setrecursionlimit(2147483647) INF=float("inf") MOD=10**9+7 def make_v(*args,e=0): from copy import deepcopy A=e for i in args[::-1]: A=[deepcopy(A) for _ in range(i)] return A input=lambda :sys.stdin.buffer.readline().rstrip() def resolve(): n,w=list(map(int,input().split())) W=[0]*(n+1) V=[0]*(n+1) for i in range(n): W[i+1],V[i+1]=list(map(int,input().split())) dp=make_v(n+1,w+1) for i in range(1,n+1): for k in range(w+1): if(k-W[i]>=0): dp[i][k]=max(dp[i-1][k-W[i]]+V[i],dp[i-1][k]) else: dp[i][k]=dp[i-1][k] print((dp[n][w])) resolve()
import sys sys.setrecursionlimit(2147483647) INF=float("inf") MOD=10**9+7 input=lambda :sys.stdin.buffer.readline().rstrip() def resolve(): n,w=list(map(int,input().split())) W=[0]*(n+1) V=[0]*(n+1) for i in range(n): W[i+1],V[i+1]=list(map(int,input().split())) dp=[[0]*(w+1) for _ in range(n+1)] for i in range(1,n+1): for k in range(w+1): if(k-W[i]>=0): dp[i][k]=max(dp[i-1][k-W[i]]+V[i],dp[i-1][k]) else: dp[i][k]=dp[i-1][k] print((dp[n][w])) resolve()
25
20
683
561
import sys sys.setrecursionlimit(2147483647) INF = float("inf") MOD = 10**9 + 7 def make_v(*args, e=0): from copy import deepcopy A = e for i in args[::-1]: A = [deepcopy(A) for _ in range(i)] return A input = lambda: sys.stdin.buffer.readline().rstrip() def resolve(): n, w = list(map(int, input().split())) W = [0] * (n + 1) V = [0] * (n + 1) for i in range(n): W[i + 1], V[i + 1] = list(map(int, input().split())) dp = make_v(n + 1, w + 1) for i in range(1, n + 1): for k in range(w + 1): if k - W[i] >= 0: dp[i][k] = max(dp[i - 1][k - W[i]] + V[i], dp[i - 1][k]) else: dp[i][k] = dp[i - 1][k] print((dp[n][w])) resolve()
import sys sys.setrecursionlimit(2147483647) INF = float("inf") MOD = 10**9 + 7 input = lambda: sys.stdin.buffer.readline().rstrip() def resolve(): n, w = list(map(int, input().split())) W = [0] * (n + 1) V = [0] * (n + 1) for i in range(n): W[i + 1], V[i + 1] = list(map(int, input().split())) dp = [[0] * (w + 1) for _ in range(n + 1)] for i in range(1, n + 1): for k in range(w + 1): if k - W[i] >= 0: dp[i][k] = max(dp[i - 1][k - W[i]] + V[i], dp[i - 1][k]) else: dp[i][k] = dp[i - 1][k] print((dp[n][w])) resolve()
false
20
[ "-", "-", "-def make_v(*args, e=0):", "- from copy import deepcopy", "-", "- A = e", "- for i in args[::-1]:", "- A = [deepcopy(A) for _ in range(i)]", "- return A", "-", "-", "- dp = make_v(n + 1, w + 1)", "+ dp = [[0] * (w + 1) for _ in range(n + 1)]" ]
false
0.050125
0.007729
6.485147
[ "s227042371", "s417200681" ]
u869790980
p03612
python
s549957349
s147287929
336
308
88,068
88,148
Accepted
Accepted
8.33
n = int(input()) count = 0 res = 0 ais = list(map(int , input().split())) for i,a in enumerate(ais): if a == i +1: count += 1 else: #flush the count res += (count + 1)/2# + 1 count = 0 if count: res += (count+1)/2 print(res)
n = int(input()) count = 0 res = 0 ais = list(map(int , input().split())) for i in range(n + 1): if (ais[i] if i < n else -1) != i + 1: #flush the count res += (count + 1)/2# + 1 count = 0 else: count +=1 print(res)
16
13
256
239
n = int(input()) count = 0 res = 0 ais = list(map(int, input().split())) for i, a in enumerate(ais): if a == i + 1: count += 1 else: # flush the count res += (count + 1) / 2 # + 1 count = 0 if count: res += (count + 1) / 2 print(res)
n = int(input()) count = 0 res = 0 ais = list(map(int, input().split())) for i in range(n + 1): if (ais[i] if i < n else -1) != i + 1: # flush the count res += (count + 1) / 2 # + 1 count = 0 else: count += 1 print(res)
false
18.75
[ "-for i, a in enumerate(ais):", "- if a == i + 1:", "- count += 1", "- else:", "+for i in range(n + 1):", "+ if (ais[i] if i < n else -1) != i + 1:", "-if count:", "- res += (count + 1) / 2", "+ else:", "+ count += 1" ]
false
0.123977
0.086826
1.427878
[ "s549957349", "s147287929" ]
u729133443
p02993
python
s146501960
s560190083
165
23
38,384
9,000
Accepted
Accepted
86.06
import re;print((re.search(r'(.)\1',eval(input()))and'Bad'or'Good'))
print(('Good'*eval('!='.join(eval(input())))or'Bad'))
1
1
60
45
import re print((re.search(r"(.)\1", eval(input())) and "Bad" or "Good"))
print(("Good" * eval("!=".join(eval(input()))) or "Bad"))
false
0
[ "-import re", "-", "-print((re.search(r\"(.)\\1\", eval(input())) and \"Bad\" or \"Good\"))", "+print((\"Good\" * eval(\"!=\".join(eval(input()))) or \"Bad\"))" ]
false
0.094571
0.039933
2.368252
[ "s146501960", "s560190083" ]
u729133443
p02841
python
s781241177
s551782200
174
17
38,384
2,940
Accepted
Accepted
90.23
a,b=open(0);print((+(a[:2]!=b[:2])))
print((+(input()[:2]!=input()[:2])))
1
1
34
34
a, b = open(0) print((+(a[:2] != b[:2])))
print((+(input()[:2] != input()[:2])))
false
0
[ "-a, b = open(0)", "-print((+(a[:2] != b[:2])))", "+print((+(input()[:2] != input()[:2])))" ]
false
0.143464
0.04007
3.580363
[ "s781241177", "s551782200" ]
u729133443
p02580
python
s291204280
s257692940
840
526
141,404
74,344
Accepted
Accepted
37.38
from collections import* (h,w,m),*z=[tuple(map(int,o.split()))for o in open(0)] s=set(z) y,x=[Counter(t).most_common()for t in zip(*z)] a,b=y[0][1],x[0][1] p=[i for i,v in y if v==a] q=[i for i,v in x if v==b] for i in p: for j in q: if(i,j)not in s:exit(print(a+b)) print(a+b-1)
*r,=c=[0]*9**6 _,*z=[[*list(map(int,t.split()))]for t in open(0)] for y,x in z:r[y]+=1;c[x]+=1 h,w=max(r),max(c) print((h+w-(r.count(h)*c.count(w)==sum(h+w==r[y]+c[x]for y,x in z))))
11
5
295
178
from collections import * (h, w, m), *z = [tuple(map(int, o.split())) for o in open(0)] s = set(z) y, x = [Counter(t).most_common() for t in zip(*z)] a, b = y[0][1], x[0][1] p = [i for i, v in y if v == a] q = [i for i, v in x if v == b] for i in p: for j in q: if (i, j) not in s: exit(print(a + b)) print(a + b - 1)
(*r,) = c = [0] * 9**6 _, *z = [[*list(map(int, t.split()))] for t in open(0)] for y, x in z: r[y] += 1 c[x] += 1 h, w = max(r), max(c) print((h + w - (r.count(h) * c.count(w) == sum(h + w == r[y] + c[x] for y, x in z))))
false
54.545455
[ "-from collections import *", "-", "-(h, w, m), *z = [tuple(map(int, o.split())) for o in open(0)]", "-s = set(z)", "-y, x = [Counter(t).most_common() for t in zip(*z)]", "-a, b = y[0][1], x[0][1]", "-p = [i for i, v in y if v == a]", "-q = [i for i, v in x if v == b]", "-for i in p:", "- for j in q:", "- if (i, j) not in s:", "- exit(print(a + b))", "-print(a + b - 1)", "+(*r,) = c = [0] * 9**6", "+_, *z = [[*list(map(int, t.split()))] for t in open(0)]", "+for y, x in z:", "+ r[y] += 1", "+ c[x] += 1", "+h, w = max(r), max(c)", "+print((h + w - (r.count(h) * c.count(w) == sum(h + w == r[y] + c[x] for y, x in z))))" ]
false
0.084917
0.263336
0.322466
[ "s291204280", "s257692940" ]
u105210954
p03163
python
s817843841
s353034179
205
185
92,852
14,796
Accepted
Accepted
9.76
import numpy as np def resolve(): n, w = list(map(int, input().split())) goods = np.array([list(map(int, input().split())) for _ in range(n)]) dp = np.zeros([n + 1, w + 1], dtype=int) for i in range(1, n + 1): tmp = np.zeros(w + 1, dtype=int) tmp[goods[i - 1][0]:] = dp[i - 1][:-goods[i - 1][0]] + goods[i - 1][1] dp[i] = np.maximum(dp[i - 1], tmp) print((dp[n][w])) resolve()
import numpy as np def resolve(): n, w = list(map(int, input().split())) goods = np.array([list(map(int, input().split())) for _ in range(n)]) # dpテーブルを1次元にして破壊的に更新していくパターン dp = np.zeros([w + 1], dtype=int) for i in range(1, n + 1): tmp = np.zeros(w + 1, dtype=int) tmp[goods[i - 1][0]:] = dp[:-goods[i - 1][0]] + goods[i - 1][1] dp = np.maximum(dp, tmp) print((dp[w])) resolve()
14
16
432
446
import numpy as np def resolve(): n, w = list(map(int, input().split())) goods = np.array([list(map(int, input().split())) for _ in range(n)]) dp = np.zeros([n + 1, w + 1], dtype=int) for i in range(1, n + 1): tmp = np.zeros(w + 1, dtype=int) tmp[goods[i - 1][0] :] = dp[i - 1][: -goods[i - 1][0]] + goods[i - 1][1] dp[i] = np.maximum(dp[i - 1], tmp) print((dp[n][w])) resolve()
import numpy as np def resolve(): n, w = list(map(int, input().split())) goods = np.array([list(map(int, input().split())) for _ in range(n)]) # dpテーブルを1次元にして破壊的に更新していくパターン dp = np.zeros([w + 1], dtype=int) for i in range(1, n + 1): tmp = np.zeros(w + 1, dtype=int) tmp[goods[i - 1][0] :] = dp[: -goods[i - 1][0]] + goods[i - 1][1] dp = np.maximum(dp, tmp) print((dp[w])) resolve()
false
12.5
[ "- dp = np.zeros([n + 1, w + 1], dtype=int)", "+ # dpテーブルを1次元にして破壊的に更新していくパターン", "+ dp = np.zeros([w + 1], dtype=int)", "- tmp[goods[i - 1][0] :] = dp[i - 1][: -goods[i - 1][0]] + goods[i - 1][1]", "- dp[i] = np.maximum(dp[i - 1], tmp)", "- print((dp[n][w]))", "+ tmp[goods[i - 1][0] :] = dp[: -goods[i - 1][0]] + goods[i - 1][1]", "+ dp = np.maximum(dp, tmp)", "+ print((dp[w]))" ]
false
0.162891
0.211986
0.768406
[ "s817843841", "s353034179" ]
u325282913
p03062
python
s607651244
s275626693
106
90
14,284
85,316
Accepted
Accepted
15.09
N = int(eval(input())) arr = list(map(int, input().split())) count = 0 gokei = 0 mi = float('inf') flg = False for i in arr: gokei += abs(i) mi = min(mi,abs(i)) if i < 0: count += 1 if i == 0: flg = True if flg or count % 2 == 0: print(gokei) else: print((gokei-mi*2))
N = int(eval(input())) arr = list(map(int, input().split())) cnt = 0 flg = False for i in range(N): if arr[i] == 0: flg = True if arr[i] < 0: cnt += 1 arr[i] = abs(arr[i]) if cnt % 2 == 0 or flg: print((sum(arr))) else: print((sum(arr) - min(arr)*2))
17
14
316
289
N = int(eval(input())) arr = list(map(int, input().split())) count = 0 gokei = 0 mi = float("inf") flg = False for i in arr: gokei += abs(i) mi = min(mi, abs(i)) if i < 0: count += 1 if i == 0: flg = True if flg or count % 2 == 0: print(gokei) else: print((gokei - mi * 2))
N = int(eval(input())) arr = list(map(int, input().split())) cnt = 0 flg = False for i in range(N): if arr[i] == 0: flg = True if arr[i] < 0: cnt += 1 arr[i] = abs(arr[i]) if cnt % 2 == 0 or flg: print((sum(arr))) else: print((sum(arr) - min(arr) * 2))
false
17.647059
[ "-count = 0", "-gokei = 0", "-mi = float(\"inf\")", "+cnt = 0", "-for i in arr:", "- gokei += abs(i)", "- mi = min(mi, abs(i))", "- if i < 0:", "- count += 1", "- if i == 0:", "+for i in range(N):", "+ if arr[i] == 0:", "-if flg or count % 2 == 0:", "- print(gokei)", "+ if arr[i] < 0:", "+ cnt += 1", "+ arr[i] = abs(arr[i])", "+if cnt % 2 == 0 or flg:", "+ print((sum(arr)))", "- print((gokei - mi * 2))", "+ print((sum(arr) - min(arr) * 2))" ]
false
0.156146
0.042293
3.691995
[ "s607651244", "s275626693" ]
u137542041
p02837
python
s925939924
s521125834
338
278
3,064
3,064
Accepted
Accepted
17.75
N = int(eval(input())) XY = [] for _ in range(N): A = int(eval(input())) temp = [] for _ in range(A): temp.append(list(map(int, input().split()))) XY.append(temp) max_honest = 0 for c in range(1 << N): check = [0] * N contradict = False temp = c cnt2 = 0 while temp != 0: if 1 & temp: check[cnt2] = 1 temp >>= 1 cnt2 += 1 for i in range(N): if check[i] == 1: for x, y in XY[i]: if check[x - 1] != y: contradict = True break if contradict: break if not contradict: cnt1 = 0 for i in range(N): if check[i] is not None and check[i] == 1: cnt1 += 1 max_honest = max(max_honest, cnt1) print(max_honest)
N = int(eval(input())) XY = [] for _ in range(N): A = int(eval(input())) temp = [] for _ in range(A): temp.append(list(map(int, input().split()))) XY.append(temp) max_honest = 0 for c in range(1 << N): check = [0] * N contradict = False cnt1 = 0 while c != 0: if 1 & c: check[cnt1] = 1 c >>= 1 cnt1 += 1 for i in range(N): if check[i] == 1: for x, y in XY[i]: if check[x - 1] != y: contradict = True break if contradict: break if not contradict: max_honest = max(max_honest, sum(check)) print(max_honest)
47
41
889
741
N = int(eval(input())) XY = [] for _ in range(N): A = int(eval(input())) temp = [] for _ in range(A): temp.append(list(map(int, input().split()))) XY.append(temp) max_honest = 0 for c in range(1 << N): check = [0] * N contradict = False temp = c cnt2 = 0 while temp != 0: if 1 & temp: check[cnt2] = 1 temp >>= 1 cnt2 += 1 for i in range(N): if check[i] == 1: for x, y in XY[i]: if check[x - 1] != y: contradict = True break if contradict: break if not contradict: cnt1 = 0 for i in range(N): if check[i] is not None and check[i] == 1: cnt1 += 1 max_honest = max(max_honest, cnt1) print(max_honest)
N = int(eval(input())) XY = [] for _ in range(N): A = int(eval(input())) temp = [] for _ in range(A): temp.append(list(map(int, input().split()))) XY.append(temp) max_honest = 0 for c in range(1 << N): check = [0] * N contradict = False cnt1 = 0 while c != 0: if 1 & c: check[cnt1] = 1 c >>= 1 cnt1 += 1 for i in range(N): if check[i] == 1: for x, y in XY[i]: if check[x - 1] != y: contradict = True break if contradict: break if not contradict: max_honest = max(max_honest, sum(check)) print(max_honest)
false
12.765957
[ "- temp = c", "- cnt2 = 0", "- while temp != 0:", "- if 1 & temp:", "- check[cnt2] = 1", "- temp >>= 1", "- cnt2 += 1", "+ cnt1 = 0", "+ while c != 0:", "+ if 1 & c:", "+ check[cnt1] = 1", "+ c >>= 1", "+ cnt1 += 1", "- cnt1 = 0", "- for i in range(N):", "- if check[i] is not None and check[i] == 1:", "- cnt1 += 1", "- max_honest = max(max_honest, cnt1)", "+ max_honest = max(max_honest, sum(check))" ]
false
0.037176
0.038027
0.977624
[ "s925939924", "s521125834" ]
u724687935
p02762
python
s000244798
s729692707
1,754
971
122,144
127,012
Accepted
Accepted
44.64
class UnionFind(): def __init__(self, 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 N, M, K = list(map(int, input().split())) uf = UnionFind(N) direct = [set() for _ in range(N)] for _ in range(M): a, b = list(map(int, input().split())) a -= 1; b -= 1 uf.union(a, b) direct[a].add(b) direct[b].add(a) for _ in range(K): a, b = list(map(int, input().split())) a -= 1; b -= 1 if uf.find(a) == uf.find(b): direct[a].add(b) direct[b].add(a) ans = [] for i in range(N): cnt = -uf.parents[uf.find(i)] - 1 cnt -= len(direct[i]) ans.append(cnt) print((*ans))
import sys class UnionFind(): def __init__(self, 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 N, M, K = list(map(int, input().split())) uf = UnionFind(N) direct = [set() for _ in range(N)] IN = sys.stdin.readlines() for i in range(M): a, b = list(map(int, IN[i].split())) a -= 1; b -= 1 uf.union(a, b) direct[a].add(b) direct[b].add(a) for i in range(M, M + K): a, b = list(map(int, IN[i].split())) a -= 1; b -= 1 if uf.find(a) == uf.find(b): direct[a].add(b) direct[b].add(a) ans = [] for i in range(N): cnt = -uf.parents[uf.find(i)] - 1 cnt -= len(direct[i]) ans.append(cnt) print((*ans))
47
51
1,077
1,124
class UnionFind: def __init__(self, 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 N, M, K = list(map(int, input().split())) uf = UnionFind(N) direct = [set() for _ in range(N)] for _ in range(M): a, b = list(map(int, input().split())) a -= 1 b -= 1 uf.union(a, b) direct[a].add(b) direct[b].add(a) for _ in range(K): a, b = list(map(int, input().split())) a -= 1 b -= 1 if uf.find(a) == uf.find(b): direct[a].add(b) direct[b].add(a) ans = [] for i in range(N): cnt = -uf.parents[uf.find(i)] - 1 cnt -= len(direct[i]) ans.append(cnt) print((*ans))
import sys class UnionFind: def __init__(self, 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 N, M, K = list(map(int, input().split())) uf = UnionFind(N) direct = [set() for _ in range(N)] IN = sys.stdin.readlines() for i in range(M): a, b = list(map(int, IN[i].split())) a -= 1 b -= 1 uf.union(a, b) direct[a].add(b) direct[b].add(a) for i in range(M, M + K): a, b = list(map(int, IN[i].split())) a -= 1 b -= 1 if uf.find(a) == uf.find(b): direct[a].add(b) direct[b].add(a) ans = [] for i in range(N): cnt = -uf.parents[uf.find(i)] - 1 cnt -= len(direct[i]) ans.append(cnt) print((*ans))
false
7.843137
[ "+import sys", "+", "+", "-for _ in range(M):", "- a, b = list(map(int, input().split()))", "+IN = sys.stdin.readlines()", "+for i in range(M):", "+ a, b = list(map(int, IN[i].split()))", "-for _ in range(K):", "- a, b = list(map(int, input().split()))", "+for i in range(M, M + K):", "+ a, b = list(map(int, IN[i].split()))" ]
false
0.090067
0.047234
1.906799
[ "s000244798", "s729692707" ]
u391875425
p03090
python
s579512461
s703698178
628
20
3,976
3,316
Accepted
Accepted
96.82
N = int(eval(input())) ans = [] lis = [] for i in range(N): lis.append(i + 1) if N % 2 == 0: M = (N - 2) * N // 2 for i in range(1, N): for j in range(1, N): if j != i and i != lis[-j]: tmp = sorted([i, lis[-j]]) if tmp not in ans: ans.append(tmp) print(M) for i in range(M): print((' '.join(map(str, ans[i])))) else: M = (N - 1) ** 2 // 2 for i in range(1, N): for j in range(2, N): if j != i + 1 and i != lis[-j]: tmp = sorted([i, lis[-j]]) if tmp not in ans: ans.append(tmp) for i in range(1, N): ans.append([N, i]) print(M) for i in range(M): print((' '.join(map(str, ans[i]))))
N = int(eval(input())) ans = [] M = N + 1 * (N % 2 == 0) for i in range(1, N + 1): for j in range(i + 1, N + 1): if i + j == M: continue ans.append('{} {}'.format(i, j)) print((len(ans))) print(('\n'.join(ans)))
29
10
808
242
N = int(eval(input())) ans = [] lis = [] for i in range(N): lis.append(i + 1) if N % 2 == 0: M = (N - 2) * N // 2 for i in range(1, N): for j in range(1, N): if j != i and i != lis[-j]: tmp = sorted([i, lis[-j]]) if tmp not in ans: ans.append(tmp) print(M) for i in range(M): print((" ".join(map(str, ans[i])))) else: M = (N - 1) ** 2 // 2 for i in range(1, N): for j in range(2, N): if j != i + 1 and i != lis[-j]: tmp = sorted([i, lis[-j]]) if tmp not in ans: ans.append(tmp) for i in range(1, N): ans.append([N, i]) print(M) for i in range(M): print((" ".join(map(str, ans[i]))))
N = int(eval(input())) ans = [] M = N + 1 * (N % 2 == 0) for i in range(1, N + 1): for j in range(i + 1, N + 1): if i + j == M: continue ans.append("{} {}".format(i, j)) print((len(ans))) print(("\n".join(ans)))
false
65.517241
[ "-lis = []", "-for i in range(N):", "- lis.append(i + 1)", "-if N % 2 == 0:", "- M = (N - 2) * N // 2", "- for i in range(1, N):", "- for j in range(1, N):", "- if j != i and i != lis[-j]:", "- tmp = sorted([i, lis[-j]])", "- if tmp not in ans:", "- ans.append(tmp)", "- print(M)", "- for i in range(M):", "- print((\" \".join(map(str, ans[i]))))", "-else:", "- M = (N - 1) ** 2 // 2", "- for i in range(1, N):", "- for j in range(2, N):", "- if j != i + 1 and i != lis[-j]:", "- tmp = sorted([i, lis[-j]])", "- if tmp not in ans:", "- ans.append(tmp)", "- for i in range(1, N):", "- ans.append([N, i])", "- print(M)", "- for i in range(M):", "- print((\" \".join(map(str, ans[i]))))", "+M = N + 1 * (N % 2 == 0)", "+for i in range(1, N + 1):", "+ for j in range(i + 1, N + 1):", "+ if i + j == M:", "+ continue", "+ ans.append(\"{} {}\".format(i, j))", "+print((len(ans)))", "+print((\"\\n\".join(ans)))" ]
false
0.076893
0.037523
2.04924
[ "s579512461", "s703698178" ]
u340781749
p03428
python
s261075906
s888169194
496
447
175,136
179,092
Accepted
Accepted
9.88
from collections import Counter import numpy as np def part(s, t): a = np.linspace(s, t, 1e5, endpoint=False) for i, v in list(Counter(np.argmax(np.dot(pts, [np.sin(a), np.cos(a)]), axis=0)).items()): ans[i] += v n = int(eval(input())) pts = [list(map(int, input().split())) for _ in range(n)] ans = np.zeros(n) part(0, np.pi) part(np.pi, 2 * np.pi) ans /= 2e5 print(('\n'.join(map(str, ans))))
from collections import Counter import numpy as np def solve(n, pts): ans = [0] * n div = 200000 a = np.linspace(0, 2 * np.pi, div, endpoint=False) b = np.array([np.cos(a), np.sin(a)], dtype=np.float32) for i, v in list(Counter(np.argmax(np.dot(pts, b), axis=0)).items()): ans[i] = v / div return ans n = int(eval(input())) pts = np.array([list(map(int, input().split())) for _ in range(n)], dtype=np.float32) print(('\n'.join(map(str, solve(n, pts)))))
17
19
417
496
from collections import Counter import numpy as np def part(s, t): a = np.linspace(s, t, 1e5, endpoint=False) for i, v in list( Counter(np.argmax(np.dot(pts, [np.sin(a), np.cos(a)]), axis=0)).items() ): ans[i] += v n = int(eval(input())) pts = [list(map(int, input().split())) for _ in range(n)] ans = np.zeros(n) part(0, np.pi) part(np.pi, 2 * np.pi) ans /= 2e5 print(("\n".join(map(str, ans))))
from collections import Counter import numpy as np def solve(n, pts): ans = [0] * n div = 200000 a = np.linspace(0, 2 * np.pi, div, endpoint=False) b = np.array([np.cos(a), np.sin(a)], dtype=np.float32) for i, v in list(Counter(np.argmax(np.dot(pts, b), axis=0)).items()): ans[i] = v / div return ans n = int(eval(input())) pts = np.array([list(map(int, input().split())) for _ in range(n)], dtype=np.float32) print(("\n".join(map(str, solve(n, pts)))))
false
10.526316
[ "-def part(s, t):", "- a = np.linspace(s, t, 1e5, endpoint=False)", "- for i, v in list(", "- Counter(np.argmax(np.dot(pts, [np.sin(a), np.cos(a)]), axis=0)).items()", "- ):", "- ans[i] += v", "+def solve(n, pts):", "+ ans = [0] * n", "+ div = 200000", "+ a = np.linspace(0, 2 * np.pi, div, endpoint=False)", "+ b = np.array([np.cos(a), np.sin(a)], dtype=np.float32)", "+ for i, v in list(Counter(np.argmax(np.dot(pts, b), axis=0)).items()):", "+ ans[i] = v / div", "+ return ans", "-pts = [list(map(int, input().split())) for _ in range(n)]", "-ans = np.zeros(n)", "-part(0, np.pi)", "-part(np.pi, 2 * np.pi)", "-ans /= 2e5", "-print((\"\\n\".join(map(str, ans))))", "+pts = np.array([list(map(int, input().split())) for _ in range(n)], dtype=np.float32)", "+print((\"\\n\".join(map(str, solve(n, pts)))))" ]
false
0.224311
0.342649
0.654638
[ "s261075906", "s888169194" ]
u670180528
p03798
python
s200545502
s392423347
261
211
6,152
7,680
Accepted
Accepted
19.16
n=int(input()) s=[0+(m=="o") for m in input()] #o:1,x:0 #Sheep:1,wolf:0 def nxt(a,b,m): if a==b: return m else: return 1-m for a,b in ((1,1),(0,1),(1,0),(0,0)): c,d = a,b ans = [a,b] for i in range(n-2): a,b = b,nxt(a,b,s[i+1]) ans.append(b) if nxt(a,b,s[-1])==c and nxt(b,c,s[0])==d: for x in ans: if x: print("S",end="") else: print("W",end="") exit() print(-1)
n,s=open(0);n=int(n) for a,b in ([0,0],[0,1],[1,0],[1,1]): r=[a,b] for i in range(n):a,b=b,s[-~i%n]=="xo"[a==b];r+=[b] if r[:2]==r[-2:]:print(*("WS"[i]for i in r[:-2]),sep="");exit() print(-1)
25
6
421
200
n = int(input()) s = [0 + (m == "o") for m in input()] # o:1,x:0 # Sheep:1,wolf:0 def nxt(a, b, m): if a == b: return m else: return 1 - m for a, b in ((1, 1), (0, 1), (1, 0), (0, 0)): c, d = a, b ans = [a, b] for i in range(n - 2): a, b = b, nxt(a, b, s[i + 1]) ans.append(b) if nxt(a, b, s[-1]) == c and nxt(b, c, s[0]) == d: for x in ans: if x: print("S", end="") else: print("W", end="") exit() print(-1)
n, s = open(0) n = int(n) for a, b in ([0, 0], [0, 1], [1, 0], [1, 1]): r = [a, b] for i in range(n): a, b = b, s[-~i % n] == "xo"[a == b] r += [b] if r[:2] == r[-2:]: print(*("WS"[i] for i in r[:-2]), sep="") exit() print(-1)
false
76
[ "-n = int(input())", "-s = [0 + (m == \"o\") for m in input()]", "-# o:1,x:0", "-# Sheep:1,wolf:0", "-def nxt(a, b, m):", "- if a == b:", "- return m", "- else:", "- return 1 - m", "-", "-", "-for a, b in ((1, 1), (0, 1), (1, 0), (0, 0)):", "- c, d = a, b", "- ans = [a, b]", "- for i in range(n - 2):", "- a, b = b, nxt(a, b, s[i + 1])", "- ans.append(b)", "- if nxt(a, b, s[-1]) == c and nxt(b, c, s[0]) == d:", "- for x in ans:", "- if x:", "- print(\"S\", end=\"\")", "- else:", "- print(\"W\", end=\"\")", "+n, s = open(0)", "+n = int(n)", "+for a, b in ([0, 0], [0, 1], [1, 0], [1, 1]):", "+ r = [a, b]", "+ for i in range(n):", "+ a, b = b, s[-~i % n] == \"xo\"[a == b]", "+ r += [b]", "+ if r[:2] == r[-2:]:", "+ print(*(\"WS\"[i] for i in r[:-2]), sep=\"\")" ]
false
0.068111
0.006979
9.758977
[ "s200545502", "s392423347" ]
u777864981
p03999
python
s003764487
s147957134
24
20
3,060
3,060
Accepted
Accepted
16.67
S = eval(input()) def DP(x , i): #print("x:i:",x,i) ans = 0 # iがSの長さになっていれば、評価する if i == len(S): # +が入っていればevalで評価する必要がある #print("評価") if '+' in x: return eval(x) else: return int(x) else: # i番目の数字の前に+を挟まない場合 ans += DP(x + S[i] , i+1) if i > 0: # i番目の数字の前に+を挟む場合 ans += DP(x + '+' + S[i], i+1) return ans print((DP('',0)))
s = eval(input()) n = int(s) r = 0 # bitの2進数表記で+を入れる位置を総当たりする for bit in range(2**(len(s)-1)): # eは先頭文字 e = s[0] # +が入る位置が、右からi桁目(0<= i <= Sの長さ-1)のとき for i in range(len(s)-1): if ((bit>>i)&1) == 1: # bitの2進数表記で右からi桁目が1のとき # '+'を入れる e += '+' # 次の文字(左からi番目)を入れる e += s[i+1] # +を入れた文字列を+で分割して整数に変換し、加算する r += sum(map(int, e.split('+'))) print(r)
22
18
469
437
S = eval(input()) def DP(x, i): # print("x:i:",x,i) ans = 0 # iがSの長さになっていれば、評価する if i == len(S): # +が入っていればevalで評価する必要がある # print("評価") if "+" in x: return eval(x) else: return int(x) else: # i番目の数字の前に+を挟まない場合 ans += DP(x + S[i], i + 1) if i > 0: # i番目の数字の前に+を挟む場合 ans += DP(x + "+" + S[i], i + 1) return ans print((DP("", 0)))
s = eval(input()) n = int(s) r = 0 # bitの2進数表記で+を入れる位置を総当たりする for bit in range(2 ** (len(s) - 1)): # eは先頭文字 e = s[0] # +が入る位置が、右からi桁目(0<= i <= Sの長さ-1)のとき for i in range(len(s) - 1): if ((bit >> i) & 1) == 1: # bitの2進数表記で右からi桁目が1のとき # '+'を入れる e += "+" # 次の文字(左からi番目)を入れる e += s[i + 1] # +を入れた文字列を+で分割して整数に変換し、加算する r += sum(map(int, e.split("+"))) print(r)
false
18.181818
[ "-S = eval(input())", "-", "-", "-def DP(x, i):", "- # print(\"x:i:\",x,i)", "- ans = 0", "- # iがSの長さになっていれば、評価する", "- if i == len(S):", "- # +が入っていればevalで評価する必要がある", "- # print(\"評価\")", "- if \"+\" in x:", "- return eval(x)", "- else:", "- return int(x)", "- else:", "- # i番目の数字の前に+を挟まない場合", "- ans += DP(x + S[i], i + 1)", "- if i > 0:", "- # i番目の数字の前に+を挟む場合", "- ans += DP(x + \"+\" + S[i], i + 1)", "- return ans", "-", "-", "-print((DP(\"\", 0)))", "+s = eval(input())", "+n = int(s)", "+r = 0", "+# bitの2進数表記で+を入れる位置を総当たりする", "+for bit in range(2 ** (len(s) - 1)):", "+ # eは先頭文字", "+ e = s[0]", "+ # +が入る位置が、右からi桁目(0<= i <= Sの長さ-1)のとき", "+ for i in range(len(s) - 1):", "+ if ((bit >> i) & 1) == 1:", "+ # bitの2進数表記で右からi桁目が1のとき", "+ # '+'を入れる", "+ e += \"+\"", "+ # 次の文字(左からi番目)を入れる", "+ e += s[i + 1]", "+ # +を入れた文字列を+で分割して整数に変換し、加算する", "+ r += sum(map(int, e.split(\"+\")))", "+print(r)" ]
false
0.047817
0.048973
0.97639
[ "s003764487", "s147957134" ]
u392319141
p03575
python
s144274346
s147135958
52
22
3,444
3,064
Accepted
Accepted
57.69
from collections import deque N, M = list(map(int, input().split())) edges = [] for _ in range(M): a, b = list(map(int, input().split())) a -= 1 b -= 1 edges.append((a, b)) ans = 0 for removeEdge in range(M): confilm = [False for _ in range(N)] que = deque([]) que.append(0) while que: now = que.popleft() confilm[now] = True for i, (a, b) in enumerate(edges): if i == removeEdge: continue if a == now: if not confilm[b]: que.append(b) if b == now: if not confilm[a]: que.append(a) if False in confilm: ans += 1 print(ans)
class UnionFind : def __init__(self, size) : self.parent = list(range(size)) self.height = [0] * size self.size = [1] * size self.component = size def root(self, index) : if self.parent[index] == index : # 根の場合 return index rootIndex = self.root(self.parent[index]) # 葉の場合親の根を取得 self.parent[index] = rootIndex # 親の付け直し return rootIndex def union(self, index1, index2) : # 結合 root1 = self.root(index1) root2 = self.root(index2) if root1 == root2 : # 連結されている場合 return self.component -= 1 # 連結成分を減らす if self.height[root1] < self.height[root2] : self.parent[root1] = root2 # root2に結合 self.size[root2] += self.size[root1] else : self.parent[root2] = root1 # root1に結合 self.size[root1] += self.size[root2] if self.height[root1] == self.height[root2] : self.height[root1] += 1 return def isSameRoot(self, index1, index2) : return self.root(index1) == self.root(index2) def sizeOfSameRoot(self, index) : return self.size[self.root(index)] def getComponent(self) : return self.component N, M = list(map(int, input().split())) AB = [tuple([int(a) - 1 for a in input().split()]) for _ in range(M)] ans = 0 for i in range(M): tree = UnionFind(N) for a, b in (AB[:i] + AB[i + 1:]): tree.union(a, b) if tree.getComponent() > 1: ans += 1 print(ans)
33
54
739
1,600
from collections import deque N, M = list(map(int, input().split())) edges = [] for _ in range(M): a, b = list(map(int, input().split())) a -= 1 b -= 1 edges.append((a, b)) ans = 0 for removeEdge in range(M): confilm = [False for _ in range(N)] que = deque([]) que.append(0) while que: now = que.popleft() confilm[now] = True for i, (a, b) in enumerate(edges): if i == removeEdge: continue if a == now: if not confilm[b]: que.append(b) if b == now: if not confilm[a]: que.append(a) if False in confilm: ans += 1 print(ans)
class UnionFind: def __init__(self, size): self.parent = list(range(size)) self.height = [0] * size self.size = [1] * size self.component = size def root(self, index): if self.parent[index] == index: # 根の場合 return index rootIndex = self.root(self.parent[index]) # 葉の場合親の根を取得 self.parent[index] = rootIndex # 親の付け直し return rootIndex def union(self, index1, index2): # 結合 root1 = self.root(index1) root2 = self.root(index2) if root1 == root2: # 連結されている場合 return self.component -= 1 # 連結成分を減らす if self.height[root1] < self.height[root2]: self.parent[root1] = root2 # root2に結合 self.size[root2] += self.size[root1] else: self.parent[root2] = root1 # root1に結合 self.size[root1] += self.size[root2] if self.height[root1] == self.height[root2]: self.height[root1] += 1 return def isSameRoot(self, index1, index2): return self.root(index1) == self.root(index2) def sizeOfSameRoot(self, index): return self.size[self.root(index)] def getComponent(self): return self.component N, M = list(map(int, input().split())) AB = [tuple([int(a) - 1 for a in input().split()]) for _ in range(M)] ans = 0 for i in range(M): tree = UnionFind(N) for a, b in AB[:i] + AB[i + 1 :]: tree.union(a, b) if tree.getComponent() > 1: ans += 1 print(ans)
false
38.888889
[ "-from collections import deque", "+class UnionFind:", "+ def __init__(self, size):", "+ self.parent = list(range(size))", "+ self.height = [0] * size", "+ self.size = [1] * size", "+ self.component = size", "+", "+ def root(self, index):", "+ if self.parent[index] == index: # 根の場合", "+ return index", "+ rootIndex = self.root(self.parent[index]) # 葉の場合親の根を取得", "+ self.parent[index] = rootIndex # 親の付け直し", "+ return rootIndex", "+", "+ def union(self, index1, index2): # 結合", "+ root1 = self.root(index1)", "+ root2 = self.root(index2)", "+ if root1 == root2: # 連結されている場合", "+ return", "+ self.component -= 1 # 連結成分を減らす", "+ if self.height[root1] < self.height[root2]:", "+ self.parent[root1] = root2 # root2に結合", "+ self.size[root2] += self.size[root1]", "+ else:", "+ self.parent[root2] = root1 # root1に結合", "+ self.size[root1] += self.size[root2]", "+ if self.height[root1] == self.height[root2]:", "+ self.height[root1] += 1", "+ return", "+", "+ def isSameRoot(self, index1, index2):", "+ return self.root(index1) == self.root(index2)", "+", "+ def sizeOfSameRoot(self, index):", "+ return self.size[self.root(index)]", "+", "+ def getComponent(self):", "+ return self.component", "+", "-edges = []", "-for _ in range(M):", "- a, b = list(map(int, input().split()))", "- a -= 1", "- b -= 1", "- edges.append((a, b))", "+AB = [tuple([int(a) - 1 for a in input().split()]) for _ in range(M)]", "-for removeEdge in range(M):", "- confilm = [False for _ in range(N)]", "- que = deque([])", "- que.append(0)", "- while que:", "- now = que.popleft()", "- confilm[now] = True", "- for i, (a, b) in enumerate(edges):", "- if i == removeEdge:", "- continue", "- if a == now:", "- if not confilm[b]:", "- que.append(b)", "- if b == now:", "- if not confilm[a]:", "- que.append(a)", "- if False in confilm:", "+for i in range(M):", "+ tree = UnionFind(N)", "+ for a, b in AB[:i] + AB[i + 1 :]:", "+ tree.union(a, b)", "+ if tree.getComponent() > 1:" ]
false
0.07612
0.101377
0.750864
[ "s144274346", "s147135958" ]
u578441226
p02582
python
s556206770
s902070756
30
27
8,976
9,036
Accepted
Accepted
10
s = eval(input()) if s[0] == "R": if s[1] == "R": if s[2] == "R": print("3") else: print("2") else: print("1") elif s[1] == "R": if s[2] == "R": print("2") else: print("1") elif s[2] == "R": print("1") else: print("0")
s = eval(input()) r = ["RRS","RRR","RSR","SRR","SSR","RSS","SSS","SRS"] ra = [2,3,1,2,1,1,0,1] for i in range(8): if r[i] == s: print((ra[i]))
19
7
335
153
s = eval(input()) if s[0] == "R": if s[1] == "R": if s[2] == "R": print("3") else: print("2") else: print("1") elif s[1] == "R": if s[2] == "R": print("2") else: print("1") elif s[2] == "R": print("1") else: print("0")
s = eval(input()) r = ["RRS", "RRR", "RSR", "SRR", "SSR", "RSS", "SSS", "SRS"] ra = [2, 3, 1, 2, 1, 1, 0, 1] for i in range(8): if r[i] == s: print((ra[i]))
false
63.157895
[ "-if s[0] == \"R\":", "- if s[1] == \"R\":", "- if s[2] == \"R\":", "- print(\"3\")", "- else:", "- print(\"2\")", "- else:", "- print(\"1\")", "-elif s[1] == \"R\":", "- if s[2] == \"R\":", "- print(\"2\")", "- else:", "- print(\"1\")", "-elif s[2] == \"R\":", "- print(\"1\")", "-else:", "- print(\"0\")", "+r = [\"RRS\", \"RRR\", \"RSR\", \"SRR\", \"SSR\", \"RSS\", \"SSS\", \"SRS\"]", "+ra = [2, 3, 1, 2, 1, 1, 0, 1]", "+for i in range(8):", "+ if r[i] == s:", "+ print((ra[i]))" ]
false
0.045996
0.045671
1.007123
[ "s556206770", "s902070756" ]
u747602774
p03379
python
s149111784
s087772656
353
306
26,772
25,620
Accepted
Accepted
13.31
N=int(eval(input())) X=list(map(int,input().split())) X_sort=sorted(X) if X_sort[N//2-1]==X_sort[N//2]: for n in range(N): print((X_sort[N//2])) else: if X_sort.count(X_sort[N//2-1])==1: for n in range(N): if X[n]>X_sort[N//2-1]: print((X_sort[N//2-1])) else: print((X_sort[N//2])) else: for n in range(N): if X[n]>X_sort[N//2-1]: print((X_sort[N//2-1])) else: print((X_sort[N//2]))
N = int(eval(input())) X = list(map(int,input().split())) Xs = sorted(X) Bl = Xs[(N-1)//2] Br = Xs[N//2] for i in range(N): if Bl < X[i]: print(Bl) else: print(Br)
21
10
537
191
N = int(eval(input())) X = list(map(int, input().split())) X_sort = sorted(X) if X_sort[N // 2 - 1] == X_sort[N // 2]: for n in range(N): print((X_sort[N // 2])) else: if X_sort.count(X_sort[N // 2 - 1]) == 1: for n in range(N): if X[n] > X_sort[N // 2 - 1]: print((X_sort[N // 2 - 1])) else: print((X_sort[N // 2])) else: for n in range(N): if X[n] > X_sort[N // 2 - 1]: print((X_sort[N // 2 - 1])) else: print((X_sort[N // 2]))
N = int(eval(input())) X = list(map(int, input().split())) Xs = sorted(X) Bl = Xs[(N - 1) // 2] Br = Xs[N // 2] for i in range(N): if Bl < X[i]: print(Bl) else: print(Br)
false
52.380952
[ "-X_sort = sorted(X)", "-if X_sort[N // 2 - 1] == X_sort[N // 2]:", "- for n in range(N):", "- print((X_sort[N // 2]))", "-else:", "- if X_sort.count(X_sort[N // 2 - 1]) == 1:", "- for n in range(N):", "- if X[n] > X_sort[N // 2 - 1]:", "- print((X_sort[N // 2 - 1]))", "- else:", "- print((X_sort[N // 2]))", "+Xs = sorted(X)", "+Bl = Xs[(N - 1) // 2]", "+Br = Xs[N // 2]", "+for i in range(N):", "+ if Bl < X[i]:", "+ print(Bl)", "- for n in range(N):", "- if X[n] > X_sort[N // 2 - 1]:", "- print((X_sort[N // 2 - 1]))", "- else:", "- print((X_sort[N // 2]))", "+ print(Br)" ]
false
0.198005
0.196521
1.007553
[ "s149111784", "s087772656" ]
u588341295
p03682
python
s620116160
s497681371
1,306
1,102
60,720
52,788
Accepted
Accepted
15.62
# -*- coding: utf-8 -*- """ ・最小全域木、Union-Find """ import sys def input(): return sys.stdin.readline().strip() sys.setrecursionlimit(10 ** 9) from operator import itemgetter # Union-Find木 class UnionFind: def __init__(self, n): # 親要素のノード番号を格納。par[x] == xの時そのノードは根 # 1-indexedのままでOK、その場合は[0]は未使用 self.par = [i for i in range(n+1)] # 木の高さを格納する(初期状態では0) self.rank = [0] * (n+1) # 検索 def find(self, x): # 根ならその番号を返す if self.par[x] == x: return x else: # 走査していく過程で親を書き換える self.par[x] = self.find(self.par[x]) return self.par[x] # 併合 def union(self, x, y): # 根を探す x = self.find(x) y = self.find(y) # 木の高さを比較し、低いほうから高いほうに辺を張る if self.rank[x] < self.rank[y]: self.par[x] = y else: self.par[y] = x # 木の高さが同じなら片方を1増やす if self.rank[x] == self.rank[y]: self.rank[x] += 1 # 同じ集合に属するか判定 def same(self, x, y): return self.find(x) == self.find(y) N = int(eval(input())) X = [[0] * 2 for i in range(N)] Y = [[0] * 2 for i in range(N)] for i in range(N): x, y = list(map(int, input().split())) X[i][0] = x X[i][1] = i Y[i][0] = y Y[i][1] = i # 元indexを保持して座標位置順にソート X.sort(key=itemgetter(0)) Y.sort(key=itemgetter(0)) edges = [] for i in range(1, N): # 座標上で隣り合う頂点同士で辺集合を作る edges.append((X[i-1][1], X[i][1], X[i][0] - X[i-1][0])) edges.append((Y[i-1][1], Y[i][1], Y[i][0] - Y[i-1][0])) # コスト順にソート edges.sort(key=itemgetter(2)) uf = UnionFind(N) ans = 0 grp = N # Union-Findで閉路を作らない確認をして最小全域木を作る for x, y, w in edges: if not uf.same(x, y): uf.union(x, y) ans += w grp -= 1 # グループが1つになれば、それ以上やる必要ない if grp == 1: break print(ans)
# -*- coding: utf-8 -*- import sys from operator import itemgetter def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print('Yes') def No(): print('No') def YES(): print('YES') def NO(): print('NO') sys.setrecursionlimit(10 ** 9) INF = float('inf') MOD = 10 ** 9 + 7 class UnionFind: """ Union-Find木 """ def __init__(self, n): self.n = n # 親要素のノード番号を格納。par[x] == xの時そのノードは根 # 1-indexedのままでOK、その場合は[0]は未使用 self.par = [i for i in range(n+1)] # 木の高さを格納する(初期状態では0) self.rank = [0] * (n+1) # あるノードを根とする集合に属するノード数 self.size = [1] * (n+1) # あるノードを根とする集合が木かどうか self.tree = [True] * (n+1) def find(self, x): """ 根の検索(グループ番号と言えなくもない) """ # 根ならその番号を返す if self.par[x] == x: return x else: # 走査していく過程で親を書き換える self.par[x] = self.find(self.par[x]) return self.par[x] def union(self, x, y): """ 併合 """ # 根を探す x = self.find(x) y = self.find(y) # 木かどうかの判定用 if x == y: self.tree[x] = False return if not self.tree[x] or not self.tree[y]: self.tree[x] = self.tree[y] = False # 木の高さを比較し、低いほうから高いほうに辺を張る if self.rank[x] < self.rank[y]: self.par[x] = y self.size[y] += self.size[x] else: self.par[y] = x self.size[x] += self.size[y] # 木の高さが同じなら片方を1増やす if self.rank[x] == self.rank[y]: self.rank[x] += 1 def same(self, x, y): """ 同じ集合に属するか判定 """ return self.find(x) == self.find(y) def get_size(self, x): """ あるノードの属する集合のノード数 """ return self.size[self.find(x)] def is_tree(self, x): """ 木かどうかの判定 """ return self.tree[self.find(x)] def len(self): """ 集合の数 """ res = set() for i in range(self.n+1): res.add(self.find(i)) # グループ0の分を引いて返却 return len(res) - 1 N = INT() XY = [] for i in range(N): x, y = MAP() XY.append((i, x, y)) edges = [] XY.sort(key=itemgetter(1)) for i in range(N-1): i1, x1, _ = XY[i] i2, x2, _ = XY[i+1] cost = x2 - x1 edges.append((i1, i2, cost)) XY.sort(key=itemgetter(2)) for i in range(N-1): i1, _, y1 = XY[i] i2, _, y2 = XY[i+1] cost = y2 - y1 edges.append((i1, i2, cost)) uf = UnionFind(N) ans = 0 edges.sort(key=itemgetter(2)) for a, b, cost in edges: if not uf.same(a, b): uf.union(a, b) ans += cost print(ans)
83
118
1,922
3,149
# -*- coding: utf-8 -*- """ ・最小全域木、Union-Find """ import sys def input(): return sys.stdin.readline().strip() sys.setrecursionlimit(10**9) from operator import itemgetter # Union-Find木 class UnionFind: def __init__(self, n): # 親要素のノード番号を格納。par[x] == xの時そのノードは根 # 1-indexedのままでOK、その場合は[0]は未使用 self.par = [i for i in range(n + 1)] # 木の高さを格納する(初期状態では0) self.rank = [0] * (n + 1) # 検索 def find(self, x): # 根ならその番号を返す if self.par[x] == x: return x else: # 走査していく過程で親を書き換える self.par[x] = self.find(self.par[x]) return self.par[x] # 併合 def union(self, x, y): # 根を探す x = self.find(x) y = self.find(y) # 木の高さを比較し、低いほうから高いほうに辺を張る if self.rank[x] < self.rank[y]: self.par[x] = y else: self.par[y] = x # 木の高さが同じなら片方を1増やす if self.rank[x] == self.rank[y]: self.rank[x] += 1 # 同じ集合に属するか判定 def same(self, x, y): return self.find(x) == self.find(y) N = int(eval(input())) X = [[0] * 2 for i in range(N)] Y = [[0] * 2 for i in range(N)] for i in range(N): x, y = list(map(int, input().split())) X[i][0] = x X[i][1] = i Y[i][0] = y Y[i][1] = i # 元indexを保持して座標位置順にソート X.sort(key=itemgetter(0)) Y.sort(key=itemgetter(0)) edges = [] for i in range(1, N): # 座標上で隣り合う頂点同士で辺集合を作る edges.append((X[i - 1][1], X[i][1], X[i][0] - X[i - 1][0])) edges.append((Y[i - 1][1], Y[i][1], Y[i][0] - Y[i - 1][0])) # コスト順にソート edges.sort(key=itemgetter(2)) uf = UnionFind(N) ans = 0 grp = N # Union-Findで閉路を作らない確認をして最小全域木を作る for x, y, w in edges: if not uf.same(x, y): uf.union(x, y) ans += w grp -= 1 # グループが1つになれば、それ以上やる必要ない if grp == 1: break print(ans)
# -*- coding: utf-8 -*- import sys from operator import itemgetter def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print("Yes") def No(): print("No") def YES(): print("YES") def NO(): print("NO") sys.setrecursionlimit(10**9) INF = float("inf") MOD = 10**9 + 7 class UnionFind: """Union-Find木""" def __init__(self, n): self.n = n # 親要素のノード番号を格納。par[x] == xの時そのノードは根 # 1-indexedのままでOK、その場合は[0]は未使用 self.par = [i for i in range(n + 1)] # 木の高さを格納する(初期状態では0) self.rank = [0] * (n + 1) # あるノードを根とする集合に属するノード数 self.size = [1] * (n + 1) # あるノードを根とする集合が木かどうか self.tree = [True] * (n + 1) def find(self, x): """根の検索(グループ番号と言えなくもない)""" # 根ならその番号を返す if self.par[x] == x: return x else: # 走査していく過程で親を書き換える self.par[x] = self.find(self.par[x]) return self.par[x] def union(self, x, y): """併合""" # 根を探す x = self.find(x) y = self.find(y) # 木かどうかの判定用 if x == y: self.tree[x] = False return if not self.tree[x] or not self.tree[y]: self.tree[x] = self.tree[y] = False # 木の高さを比較し、低いほうから高いほうに辺を張る if self.rank[x] < self.rank[y]: self.par[x] = y self.size[y] += self.size[x] else: self.par[y] = x self.size[x] += self.size[y] # 木の高さが同じなら片方を1増やす if self.rank[x] == self.rank[y]: self.rank[x] += 1 def same(self, x, y): """同じ集合に属するか判定""" return self.find(x) == self.find(y) def get_size(self, x): """あるノードの属する集合のノード数""" return self.size[self.find(x)] def is_tree(self, x): """木かどうかの判定""" return self.tree[self.find(x)] def len(self): """集合の数""" res = set() for i in range(self.n + 1): res.add(self.find(i)) # グループ0の分を引いて返却 return len(res) - 1 N = INT() XY = [] for i in range(N): x, y = MAP() XY.append((i, x, y)) edges = [] XY.sort(key=itemgetter(1)) for i in range(N - 1): i1, x1, _ = XY[i] i2, x2, _ = XY[i + 1] cost = x2 - x1 edges.append((i1, i2, cost)) XY.sort(key=itemgetter(2)) for i in range(N - 1): i1, _, y1 = XY[i] i2, _, y2 = XY[i + 1] cost = y2 - y1 edges.append((i1, i2, cost)) uf = UnionFind(N) ans = 0 edges.sort(key=itemgetter(2)) for a, b, cost in edges: if not uf.same(a, b): uf.union(a, b) ans += cost print(ans)
false
29.661017
[ "-\"\"\"", "-・最小全域木、Union-Find", "-\"\"\"", "+from operator import itemgetter", "+def list2d(a, b, c):", "+ return [[c] * b for i in range(a)]", "+", "+", "+def list3d(a, b, c, d):", "+ return [[[d] * c for j in range(b)] for i in range(a)]", "+", "+", "+def list4d(a, b, c, d, e):", "+ return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]", "+", "+", "+def ceil(x, y=1):", "+ return int(-(-x // y))", "+", "+", "+def INT():", "+ return int(eval(input()))", "+", "+", "+def MAP():", "+ return list(map(int, input().split()))", "+", "+", "+def LIST(N=None):", "+ return list(MAP()) if N is None else [INT() for i in range(N)]", "+", "+", "+def Yes():", "+ print(\"Yes\")", "+", "+", "+def No():", "+ print(\"No\")", "+", "+", "+def YES():", "+ print(\"YES\")", "+", "+", "+def NO():", "+ print(\"NO\")", "+", "+", "-from operator import itemgetter", "+INF = float(\"inf\")", "+MOD = 10**9 + 7", "-# Union-Find木", "+", "+ \"\"\"Union-Find木\"\"\"", "+", "+ self.n = n", "+ # あるノードを根とする集合に属するノード数", "+ self.size = [1] * (n + 1)", "+ # あるノードを根とする集合が木かどうか", "+ self.tree = [True] * (n + 1)", "- # 検索", "+ \"\"\"根の検索(グループ番号と言えなくもない)\"\"\"", "- # 併合", "+ \"\"\"併合\"\"\"", "+ # 木かどうかの判定用", "+ if x == y:", "+ self.tree[x] = False", "+ return", "+ if not self.tree[x] or not self.tree[y]:", "+ self.tree[x] = self.tree[y] = False", "+ self.size[y] += self.size[x]", "+ self.size[x] += self.size[y]", "- # 同じ集合に属するか判定", "+ \"\"\"同じ集合に属するか判定\"\"\"", "+ def get_size(self, x):", "+ \"\"\"あるノードの属する集合のノード数\"\"\"", "+ return self.size[self.find(x)]", "-N = int(eval(input()))", "-X = [[0] * 2 for i in range(N)]", "-Y = [[0] * 2 for i in range(N)]", "+ def is_tree(self, x):", "+ \"\"\"木かどうかの判定\"\"\"", "+ return self.tree[self.find(x)]", "+", "+ def len(self):", "+ \"\"\"集合の数\"\"\"", "+ res = set()", "+ for i in range(self.n + 1):", "+ res.add(self.find(i))", "+ # グループ0の分を引いて返却", "+ return len(res) - 1", "+", "+", "+N = INT()", "+XY = []", "- x, y = list(map(int, input().split()))", "- X[i][0] = x", "- X[i][1] = i", "- Y[i][0] = y", "- Y[i][1] = i", "-# 元indexを保持して座標位置順にソート", "-X.sort(key=itemgetter(0))", "-Y.sort(key=itemgetter(0))", "+ x, y = MAP()", "+ XY.append((i, x, y))", "-for i in range(1, N):", "- # 座標上で隣り合う頂点同士で辺集合を作る", "- edges.append((X[i - 1][1], X[i][1], X[i][0] - X[i - 1][0]))", "- edges.append((Y[i - 1][1], Y[i][1], Y[i][0] - Y[i - 1][0]))", "-# コスト順にソート", "-edges.sort(key=itemgetter(2))", "+XY.sort(key=itemgetter(1))", "+for i in range(N - 1):", "+ i1, x1, _ = XY[i]", "+ i2, x2, _ = XY[i + 1]", "+ cost = x2 - x1", "+ edges.append((i1, i2, cost))", "+XY.sort(key=itemgetter(2))", "+for i in range(N - 1):", "+ i1, _, y1 = XY[i]", "+ i2, _, y2 = XY[i + 1]", "+ cost = y2 - y1", "+ edges.append((i1, i2, cost))", "-grp = N", "-# Union-Findで閉路を作らない確認をして最小全域木を作る", "-for x, y, w in edges:", "- if not uf.same(x, y):", "- uf.union(x, y)", "- ans += w", "- grp -= 1", "- # グループが1つになれば、それ以上やる必要ない", "- if grp == 1:", "- break", "+edges.sort(key=itemgetter(2))", "+for a, b, cost in edges:", "+ if not uf.same(a, b):", "+ uf.union(a, b)", "+ ans += cost" ]
false
0.112369
0.041715
2.693709
[ "s620116160", "s497681371" ]
u092301301
p02773
python
s936262601
s856915856
1,005
635
100,432
90,568
Accepted
Accepted
36.82
d={} ; a=[] from collections import Counter for _ in range(int(eval(input()))): s=eval(input()) a.append(s) d=Counter(a) maxx=max(d.values()) ans=[] for i in d: if d[i]==maxx: ans.append(i) ans.sort() for i in ans: print(i)
import sys input = lambda: sys.stdin.readline().rstrip() d={} ; a=[] from collections import Counter for _ in range(int(eval(input()))): s=eval(input()) a.append(s) d=Counter(a) maxx=max(d.values()) ans=[] for i in d: if d[i]==maxx: ans.append(i) ans.sort() for i in ans: print(i)
15
17
254
313
d = {} a = [] from collections import Counter for _ in range(int(eval(input()))): s = eval(input()) a.append(s) d = Counter(a) maxx = max(d.values()) ans = [] for i in d: if d[i] == maxx: ans.append(i) ans.sort() for i in ans: print(i)
import sys input = lambda: sys.stdin.readline().rstrip() d = {} a = [] from collections import Counter for _ in range(int(eval(input()))): s = eval(input()) a.append(s) d = Counter(a) maxx = max(d.values()) ans = [] for i in d: if d[i] == maxx: ans.append(i) ans.sort() for i in ans: print(i)
false
11.764706
[ "+import sys", "+", "+input = lambda: sys.stdin.readline().rstrip()" ]
false
0.102468
0.038157
2.685434
[ "s936262601", "s856915856" ]
u312025627
p02684
python
s726892345
s114244020
138
94
124,580
92,536
Accepted
Accepted
31.88
def main(): N, K = (int(i) for i in input().split()) A = [int(i) for i in input().split()] d = [] d_set = set() s = 1 for _ in range(N): if s in d_set: if K < len(d): return print(d[K]) idx = d.index(s) K -= idx d = d[idx:] break d.append(s) d_set.add(s) s = A[s-1] # print(idx, d) K %= len(d) print(d[K]) if __name__ == '__main__': main()
def main(): N, K = (int(i) for i in input().split()) A = [int(i) for i in input().split()] d = [-1]*(N+1) v = 1 i = 0 while d[v] == -1: d[v] = i v = A[v-1] i += 1 c_length = i - d[v] # 閉路長 pre_c_length = d[v] if K < i: return print(d.index(K)) else: K -= pre_c_length K %= c_length return print(d.index(pre_c_length+K)) if __name__ == '__main__': main()
25
22
515
478
def main(): N, K = (int(i) for i in input().split()) A = [int(i) for i in input().split()] d = [] d_set = set() s = 1 for _ in range(N): if s in d_set: if K < len(d): return print(d[K]) idx = d.index(s) K -= idx d = d[idx:] break d.append(s) d_set.add(s) s = A[s - 1] # print(idx, d) K %= len(d) print(d[K]) if __name__ == "__main__": main()
def main(): N, K = (int(i) for i in input().split()) A = [int(i) for i in input().split()] d = [-1] * (N + 1) v = 1 i = 0 while d[v] == -1: d[v] = i v = A[v - 1] i += 1 c_length = i - d[v] # 閉路長 pre_c_length = d[v] if K < i: return print(d.index(K)) else: K -= pre_c_length K %= c_length return print(d.index(pre_c_length + K)) if __name__ == "__main__": main()
false
12
[ "- d = []", "- d_set = set()", "- s = 1", "- for _ in range(N):", "- if s in d_set:", "- if K < len(d):", "- return print(d[K])", "- idx = d.index(s)", "- K -= idx", "- d = d[idx:]", "- break", "- d.append(s)", "- d_set.add(s)", "- s = A[s - 1]", "- # print(idx, d)", "- K %= len(d)", "- print(d[K])", "+ d = [-1] * (N + 1)", "+ v = 1", "+ i = 0", "+ while d[v] == -1:", "+ d[v] = i", "+ v = A[v - 1]", "+ i += 1", "+ c_length = i - d[v] # 閉路長", "+ pre_c_length = d[v]", "+ if K < i:", "+ return print(d.index(K))", "+ else:", "+ K -= pre_c_length", "+ K %= c_length", "+ return print(d.index(pre_c_length + K))" ]
false
0.031375
0.036569
0.857951
[ "s726892345", "s114244020" ]
u315485238
p03674
python
s503833779
s955206994
847
412
31,328
29,340
Accepted
Accepted
51.36
n = int(eval(input())) A= list(map(int, input().split())) mod = int(1e9+7) def invmod(a, mod): if a==1: return 1 return -invmod(mod%a, mod) * (mod//a) %mod memo={} for i, a in enumerate(A): if a in memo: L = memo[a] C = i - memo[a] -1 R = len(A) - i-1 break else: memo[a] = i #print(L,C,R) _LR = [0]*(n+3) _LCR = [0] * (n+3) # _LCR[k] = (L+C+R)C(k) _k = [0] * (n+3) _LR[0] = _LCR[0] = _k[0] = 1 LR = [0]*(n+2) #LR[k] = (L+R)C(k) LR[0] = 1 #LDR = [0]*(n+2) #LDDR = [0]*(n+2) LCR = [0] * (n+2) # LCR[k] = _LCR[k] - LR[k] #LDCR = [0] * (n+2) #最後に*2を忘れないこと #LDCDR = [0] * (n+2) for k in range(1,n+2): _LR[k] = (_LR[k-1] * (L+R+1-k)) %mod _LCR[k] = (_LCR[k-1] * (L+C+R+1-k))% mod _k[k] = (_k[k-1] * invmod(k,mod)) %mod LR[k] = (_LR[k] * _k[k])%mod # LDR[k] = LR[k-1] # LDDR[k] = LDR[k-1] LCR[k] = (_LCR[k] * _k[k])%mod - LR[k] # LDCR[k] = LCR[k-1] # LDCDR[k] = LDCR[k-1] #print(LR, LCR) print(((LR[k] + LR[k-1] + LR[k-2] + LCR[k] + 2*LCR[k-1] + LCR[k-2])%mod)) #print(LR) #print(LDR) #print(LDDR) #print(_LCR) #print(LCR) #print(LDCR) #print(LDCDR)
n = int(eval(input())) A= list(map(int, input().split())) mod = 10**9+7 class combinationmod(): def __init__(self,MAX, mod): self.mod =mod self.fac=[0]*(MAX+1) self.finv=[0]*(MAX+1) self.inv=[0]*(MAX+1) self.fac[0]=self.fac[1]=1 self.finv[0]=self.finv[1]=1 self.inv[1]=1 for i in range(2,MAX+1): self.fac[i] = self.fac[i-1]*i%self.mod self.inv[i] = (-self.inv[mod%i]*(mod//i))%self.mod self.finv[i] = self.finv[i-1]* self.inv[i] %self.mod def nCk(self,n,k): if n<k or n<0 or k<0: return 0 return self.fac[n]*(self.finv[k]*self.finv[n-k]%self.mod)%self.mod memo={} for i, a in enumerate(A): if a in memo: L = memo[a] R = len(A) - i-1 break else: memo[a] = i c = combinationmod(n+1,mod) for k in range(1,n+2): print(((c.nCk(n+1,k) - c.nCk(L+R,k-1))%mod))
57
36
1,169
881
n = int(eval(input())) A = list(map(int, input().split())) mod = int(1e9 + 7) def invmod(a, mod): if a == 1: return 1 return -invmod(mod % a, mod) * (mod // a) % mod memo = {} for i, a in enumerate(A): if a in memo: L = memo[a] C = i - memo[a] - 1 R = len(A) - i - 1 break else: memo[a] = i # print(L,C,R) _LR = [0] * (n + 3) _LCR = [0] * (n + 3) # _LCR[k] = (L+C+R)C(k) _k = [0] * (n + 3) _LR[0] = _LCR[0] = _k[0] = 1 LR = [0] * (n + 2) # LR[k] = (L+R)C(k) LR[0] = 1 # LDR = [0]*(n+2) # LDDR = [0]*(n+2) LCR = [0] * (n + 2) # LCR[k] = _LCR[k] - LR[k] # LDCR = [0] * (n+2) #最後に*2を忘れないこと # LDCDR = [0] * (n+2) for k in range(1, n + 2): _LR[k] = (_LR[k - 1] * (L + R + 1 - k)) % mod _LCR[k] = (_LCR[k - 1] * (L + C + R + 1 - k)) % mod _k[k] = (_k[k - 1] * invmod(k, mod)) % mod LR[k] = (_LR[k] * _k[k]) % mod # LDR[k] = LR[k-1] # LDDR[k] = LDR[k-1] LCR[k] = (_LCR[k] * _k[k]) % mod - LR[k] # LDCR[k] = LCR[k-1] # LDCDR[k] = LDCR[k-1] # print(LR, LCR) print( ((LR[k] + LR[k - 1] + LR[k - 2] + LCR[k] + 2 * LCR[k - 1] + LCR[k - 2]) % mod) ) # print(LR) # print(LDR) # print(LDDR) # print(_LCR) # print(LCR) # print(LDCR) # print(LDCDR)
n = int(eval(input())) A = list(map(int, input().split())) mod = 10**9 + 7 class combinationmod: def __init__(self, MAX, mod): self.mod = mod self.fac = [0] * (MAX + 1) self.finv = [0] * (MAX + 1) self.inv = [0] * (MAX + 1) self.fac[0] = self.fac[1] = 1 self.finv[0] = self.finv[1] = 1 self.inv[1] = 1 for i in range(2, MAX + 1): self.fac[i] = self.fac[i - 1] * i % self.mod self.inv[i] = (-self.inv[mod % i] * (mod // i)) % self.mod self.finv[i] = self.finv[i - 1] * self.inv[i] % self.mod def nCk(self, n, k): if n < k or n < 0 or k < 0: return 0 return self.fac[n] * (self.finv[k] * self.finv[n - k] % self.mod) % self.mod memo = {} for i, a in enumerate(A): if a in memo: L = memo[a] R = len(A) - i - 1 break else: memo[a] = i c = combinationmod(n + 1, mod) for k in range(1, n + 2): print(((c.nCk(n + 1, k) - c.nCk(L + R, k - 1)) % mod))
false
36.842105
[ "-mod = int(1e9 + 7)", "+mod = 10**9 + 7", "-def invmod(a, mod):", "- if a == 1:", "- return 1", "- return -invmod(mod % a, mod) * (mod // a) % mod", "+class combinationmod:", "+ def __init__(self, MAX, mod):", "+ self.mod = mod", "+ self.fac = [0] * (MAX + 1)", "+ self.finv = [0] * (MAX + 1)", "+ self.inv = [0] * (MAX + 1)", "+ self.fac[0] = self.fac[1] = 1", "+ self.finv[0] = self.finv[1] = 1", "+ self.inv[1] = 1", "+ for i in range(2, MAX + 1):", "+ self.fac[i] = self.fac[i - 1] * i % self.mod", "+ self.inv[i] = (-self.inv[mod % i] * (mod // i)) % self.mod", "+ self.finv[i] = self.finv[i - 1] * self.inv[i] % self.mod", "+", "+ def nCk(self, n, k):", "+ if n < k or n < 0 or k < 0:", "+ return 0", "+ return self.fac[n] * (self.finv[k] * self.finv[n - k] % self.mod) % self.mod", "- C = i - memo[a] - 1", "-# print(L,C,R)", "-_LR = [0] * (n + 3)", "-_LCR = [0] * (n + 3) # _LCR[k] = (L+C+R)C(k)", "-_k = [0] * (n + 3)", "-_LR[0] = _LCR[0] = _k[0] = 1", "-LR = [0] * (n + 2) # LR[k] = (L+R)C(k)", "-LR[0] = 1", "-# LDR = [0]*(n+2)", "-# LDDR = [0]*(n+2)", "-LCR = [0] * (n + 2) # LCR[k] = _LCR[k] - LR[k]", "-# LDCR = [0] * (n+2) #最後に*2を忘れないこと", "-# LDCDR = [0] * (n+2)", "+c = combinationmod(n + 1, mod)", "- _LR[k] = (_LR[k - 1] * (L + R + 1 - k)) % mod", "- _LCR[k] = (_LCR[k - 1] * (L + C + R + 1 - k)) % mod", "- _k[k] = (_k[k - 1] * invmod(k, mod)) % mod", "- LR[k] = (_LR[k] * _k[k]) % mod", "- # LDR[k] = LR[k-1]", "- # LDDR[k] = LDR[k-1]", "- LCR[k] = (_LCR[k] * _k[k]) % mod - LR[k]", "- # LDCR[k] = LCR[k-1]", "- # LDCDR[k] = LDCR[k-1]", "- # print(LR, LCR)", "- print(", "- ((LR[k] + LR[k - 1] + LR[k - 2] + LCR[k] + 2 * LCR[k - 1] + LCR[k - 2]) % mod)", "- )", "-# print(LR)", "-# print(LDR)", "-# print(LDDR)", "-# print(_LCR)", "-# print(LCR)", "-# print(LDCR)", "-# print(LDCDR)", "+ print(((c.nCk(n + 1, k) - c.nCk(L + R, k - 1)) % mod))" ]
false
0.03432
0.057277
0.599188
[ "s503833779", "s955206994" ]
u301624971
p03262
python
s488878257
s593187184
103
92
16,284
16,268
Accepted
Accepted
10.68
import fractions from functools import reduce def gcd_list(numbers): return reduce(fractions.gcd, numbers) N,X=list(map(int,input().split())) W=list(map(int,input().split())) ans=[] for i in W: ans.append(abs(i-X)) print((gcd_list(ans)))
import fractions from functools import reduce def gcd_list(numbers): return reduce(fractions.gcd, numbers) def myAnswer(N:int,X:int,x:list) -> int: ans = [] for a in x: ans.append(abs(a-X)) return gcd_list(ans) def modelAnswer(): return def main(): N,X = list(map(int,input().split())) x = list(map(int,input().split())) print((myAnswer(N,X,x[:]))) if __name__ == '__main__': main()
13
22
253
435
import fractions from functools import reduce def gcd_list(numbers): return reduce(fractions.gcd, numbers) N, X = list(map(int, input().split())) W = list(map(int, input().split())) ans = [] for i in W: ans.append(abs(i - X)) print((gcd_list(ans)))
import fractions from functools import reduce def gcd_list(numbers): return reduce(fractions.gcd, numbers) def myAnswer(N: int, X: int, x: list) -> int: ans = [] for a in x: ans.append(abs(a - X)) return gcd_list(ans) def modelAnswer(): return def main(): N, X = list(map(int, input().split())) x = list(map(int, input().split())) print((myAnswer(N, X, x[:]))) if __name__ == "__main__": main()
false
40.909091
[ "-N, X = list(map(int, input().split()))", "-W = list(map(int, input().split()))", "-ans = []", "-for i in W:", "- ans.append(abs(i - X))", "-print((gcd_list(ans)))", "+def myAnswer(N: int, X: int, x: list) -> int:", "+ ans = []", "+ for a in x:", "+ ans.append(abs(a - X))", "+ return gcd_list(ans)", "+", "+", "+def modelAnswer():", "+ return", "+", "+", "+def main():", "+ N, X = list(map(int, input().split()))", "+ x = list(map(int, input().split()))", "+ print((myAnswer(N, X, x[:])))", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.059044
0.055651
1.06096
[ "s488878257", "s593187184" ]
u670180528
p03163
python
s260398047
s646730574
465
48
119,916
3,188
Accepted
Accepted
89.68
N,W=list(map(int,input().split())) dp=[[0]*(W+1) for _ in range(N+1)] for i in range(1,N+1): w,v=list(map(int,input().split())) for j in range(1,W+1): if j-w>=0: dp[i][j]=max(dp[i-1][j],dp[i-1][j-w]+v) else: dp[i][j]=dp[i-1][j] print((dp[N][W]))
from heapq import heappop, heappush from operator import itemgetter def branchAndBound(N: int, M: int, V: list, W: list, R: list) -> int: def upperbound(w, v, i): rest = M - w _v = v for j in range(i + 1, N): if W[j] >= rest: rest -= W[j] v += V[j] _v = v else: _v += R[j] * rest break return v, _v prov, tmp = upperbound(0, 0, -1) h = [(tmp, W[0], V[0] * (W[0] >= M), 0), (upperbound(0, 0, 0)[1], 0, 0, 0)] while h: _v, w, v, cur = heappop(h) if _v > prov or cur == N - 1: continue nxtw, nxtv = w + W[cur + 1], v + V[cur + 1] if nxtw >= M: heappush(h, (_v, nxtw, nxtv, cur + 1)) _prov, ub = upperbound(w, v, cur) if _prov < prov: prov = _prov if ub < prov: heappush(h, (ub, w, v, cur + 1)) return -prov def main(): N, M, *L = list(map(int, open(0).read().split())) t = [(v, w, v / w) for w, v in zip(*[iter(L)] * 2)] t.sort(key=itemgetter(2), reverse=True) V, W, R = [], [], [] for v, w, r in t: V += [-v] W += [-w] R += [r] ans = branchAndBound(N, -M, V, W, R) print(ans) if __name__=="__main__":main()
10
48
252
1,367
N, W = list(map(int, input().split())) dp = [[0] * (W + 1) for _ in range(N + 1)] for i in range(1, N + 1): w, v = list(map(int, input().split())) for j in range(1, W + 1): if j - w >= 0: dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w] + v) else: dp[i][j] = dp[i - 1][j] print((dp[N][W]))
from heapq import heappop, heappush from operator import itemgetter def branchAndBound(N: int, M: int, V: list, W: list, R: list) -> int: def upperbound(w, v, i): rest = M - w _v = v for j in range(i + 1, N): if W[j] >= rest: rest -= W[j] v += V[j] _v = v else: _v += R[j] * rest break return v, _v prov, tmp = upperbound(0, 0, -1) h = [(tmp, W[0], V[0] * (W[0] >= M), 0), (upperbound(0, 0, 0)[1], 0, 0, 0)] while h: _v, w, v, cur = heappop(h) if _v > prov or cur == N - 1: continue nxtw, nxtv = w + W[cur + 1], v + V[cur + 1] if nxtw >= M: heappush(h, (_v, nxtw, nxtv, cur + 1)) _prov, ub = upperbound(w, v, cur) if _prov < prov: prov = _prov if ub < prov: heappush(h, (ub, w, v, cur + 1)) return -prov def main(): N, M, *L = list(map(int, open(0).read().split())) t = [(v, w, v / w) for w, v in zip(*[iter(L)] * 2)] t.sort(key=itemgetter(2), reverse=True) V, W, R = [], [], [] for v, w, r in t: V += [-v] W += [-w] R += [r] ans = branchAndBound(N, -M, V, W, R) print(ans) if __name__ == "__main__": main()
false
79.166667
[ "-N, W = list(map(int, input().split()))", "-dp = [[0] * (W + 1) for _ in range(N + 1)]", "-for i in range(1, N + 1):", "- w, v = list(map(int, input().split()))", "- for j in range(1, W + 1):", "- if j - w >= 0:", "- dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w] + v)", "- else:", "- dp[i][j] = dp[i - 1][j]", "-print((dp[N][W]))", "+from heapq import heappop, heappush", "+from operator import itemgetter", "+", "+", "+def branchAndBound(N: int, M: int, V: list, W: list, R: list) -> int:", "+ def upperbound(w, v, i):", "+ rest = M - w", "+ _v = v", "+ for j in range(i + 1, N):", "+ if W[j] >= rest:", "+ rest -= W[j]", "+ v += V[j]", "+ _v = v", "+ else:", "+ _v += R[j] * rest", "+ break", "+ return v, _v", "+", "+ prov, tmp = upperbound(0, 0, -1)", "+ h = [(tmp, W[0], V[0] * (W[0] >= M), 0), (upperbound(0, 0, 0)[1], 0, 0, 0)]", "+ while h:", "+ _v, w, v, cur = heappop(h)", "+ if _v > prov or cur == N - 1:", "+ continue", "+ nxtw, nxtv = w + W[cur + 1], v + V[cur + 1]", "+ if nxtw >= M:", "+ heappush(h, (_v, nxtw, nxtv, cur + 1))", "+ _prov, ub = upperbound(w, v, cur)", "+ if _prov < prov:", "+ prov = _prov", "+ if ub < prov:", "+ heappush(h, (ub, w, v, cur + 1))", "+ return -prov", "+", "+", "+def main():", "+ N, M, *L = list(map(int, open(0).read().split()))", "+ t = [(v, w, v / w) for w, v in zip(*[iter(L)] * 2)]", "+ t.sort(key=itemgetter(2), reverse=True)", "+ V, W, R = [], [], []", "+ for v, w, r in t:", "+ V += [-v]", "+ W += [-w]", "+ R += [r]", "+ ans = branchAndBound(N, -M, V, W, R)", "+ print(ans)", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.095185
0.042279
2.251353
[ "s260398047", "s646730574" ]
u982591663
p02791
python
s622771363
s101622851
146
90
24,872
24,744
Accepted
Accepted
38.36
#C N = int(eval(input())) P = list(map(int, input().split())) ans = 0 min_num = 10**6 for i in range(N): min_num = min(min_num, P[i]) if min_num >= P[i]: ans += 1 print(ans)
N = int(eval(input())) P = list(map(int, input().split())) min_tmp = N+1 ans = 0 for p in P: if min_tmp >= p: ans += 1 min_tmp = p else: continue print(ans)
12
14
204
199
# C N = int(eval(input())) P = list(map(int, input().split())) ans = 0 min_num = 10**6 for i in range(N): min_num = min(min_num, P[i]) if min_num >= P[i]: ans += 1 print(ans)
N = int(eval(input())) P = list(map(int, input().split())) min_tmp = N + 1 ans = 0 for p in P: if min_tmp >= p: ans += 1 min_tmp = p else: continue print(ans)
false
14.285714
[ "-# C", "+min_tmp = N + 1", "-min_num = 10**6", "-for i in range(N):", "- min_num = min(min_num, P[i])", "- if min_num >= P[i]:", "+for p in P:", "+ if min_tmp >= p:", "+ min_tmp = p", "+ else:", "+ continue" ]
false
0.092503
0.044682
2.070251
[ "s622771363", "s101622851" ]
u642528832
p03361
python
s977286350
s394428035
34
30
9,144
9,148
Accepted
Accepted
11.76
h, w = list(map(int, input().split())) table = [list(eval(input())) for _ in range(h)] mx = [0, 1, 0, -1] my = [1, 0, -1, 0] for i in range(h): for j in range(w): if table[i][j] == "#": for k in range(4): tx, ty = j + mx[k], i + my[k] if 0 <= tx < w and 0 <= ty < h and table[ty][tx] == "#": break else: print("No") exit(0) print("Yes")
h, w = list(map(int, input().split())) table = [list(eval(input())) for _ in range(h)] mx = [0, 1, 0, -1]#yとの兼ね合いで片方は0にして上下左右判定 my = [1, 0, -1, 0]#xとの兼ね合いで片方は0にして上下左右判定 for i in range(h): for j in range(w): if table[i][j] == "#": for k in range(4): tx = j + mx[k]#左右判定 ty = i + my[k]#上下判定 if 0 <= tx < w and 0 <= ty < h and table[ty][tx] == "#":#添え字に使えるか判定している break else:#breakされなかった時実行される、上下左右に#がなかった時になる print("No") exit(0) print("Yes")
17
18
463
583
h, w = list(map(int, input().split())) table = [list(eval(input())) for _ in range(h)] mx = [0, 1, 0, -1] my = [1, 0, -1, 0] for i in range(h): for j in range(w): if table[i][j] == "#": for k in range(4): tx, ty = j + mx[k], i + my[k] if 0 <= tx < w and 0 <= ty < h and table[ty][tx] == "#": break else: print("No") exit(0) print("Yes")
h, w = list(map(int, input().split())) table = [list(eval(input())) for _ in range(h)] mx = [0, 1, 0, -1] # yとの兼ね合いで片方は0にして上下左右判定 my = [1, 0, -1, 0] # xとの兼ね合いで片方は0にして上下左右判定 for i in range(h): for j in range(w): if table[i][j] == "#": for k in range(4): tx = j + mx[k] # 左右判定 ty = i + my[k] # 上下判定 if ( 0 <= tx < w and 0 <= ty < h and table[ty][tx] == "#" ): # 添え字に使えるか判定している break else: # breakされなかった時実行される、上下左右に#がなかった時になる print("No") exit(0) print("Yes")
false
5.555556
[ "-mx = [0, 1, 0, -1]", "-my = [1, 0, -1, 0]", "+mx = [0, 1, 0, -1] # yとの兼ね合いで片方は0にして上下左右判定", "+my = [1, 0, -1, 0] # xとの兼ね合いで片方は0にして上下左右判定", "- tx, ty = j + mx[k], i + my[k]", "- if 0 <= tx < w and 0 <= ty < h and table[ty][tx] == \"#\":", "+ tx = j + mx[k] # 左右判定", "+ ty = i + my[k] # 上下判定", "+ if (", "+ 0 <= tx < w and 0 <= ty < h and table[ty][tx] == \"#\"", "+ ): # 添え字に使えるか判定している", "- else:", "+ else: # breakされなかった時実行される、上下左右に#がなかった時になる" ]
false
0.034042
0.036302
0.937746
[ "s977286350", "s394428035" ]
u708255304
p03212
python
s323766253
s873524061
93
76
2,940
4,340
Accepted
Accepted
18.28
N = int(eval(input())) def dfs(s): # 文字列 s で始まる七五三数の個数 if int(s) > N: return 0 ret = 1 if all(s.count(c) > 0 for c in '753') else 0 # s 自体が七五三数なら+1 for c in '753': ret += dfs(s + c) return ret print((dfs('0'))) # 本当はdfs('')と書きたいがint(s)でエラーを吐かないように仕方なく
N = int(eval(input())) num_list = [] def dfs(num, add_num): num *= 10 num += add_num if num > N: return num_list.append(num) dfs(num, 7) dfs(num, 5) dfs(num, 3) return num_list dfs(3, 3) dfs(3, 5) dfs(3, 7) dfs(5, 3) dfs(5, 5) dfs(5, 7) dfs(7, 3) dfs(7, 5) dfs(7, 7) ans = 0 tmp = 0 target = set(['7', '5', '3']) # print(num_list) for n in num_list: tmp = 0 for t in target: if t in str(n): tmp += 1 if tmp == 3: ans += 1 print(ans)
13
43
295
559
N = int(eval(input())) def dfs(s): # 文字列 s で始まる七五三数の個数 if int(s) > N: return 0 ret = 1 if all(s.count(c) > 0 for c in "753") else 0 # s 自体が七五三数なら+1 for c in "753": ret += dfs(s + c) return ret print((dfs("0"))) # 本当はdfs('')と書きたいがint(s)でエラーを吐かないように仕方なく
N = int(eval(input())) num_list = [] def dfs(num, add_num): num *= 10 num += add_num if num > N: return num_list.append(num) dfs(num, 7) dfs(num, 5) dfs(num, 3) return num_list dfs(3, 3) dfs(3, 5) dfs(3, 7) dfs(5, 3) dfs(5, 5) dfs(5, 7) dfs(7, 3) dfs(7, 5) dfs(7, 7) ans = 0 tmp = 0 target = set(["7", "5", "3"]) # print(num_list) for n in num_list: tmp = 0 for t in target: if t in str(n): tmp += 1 if tmp == 3: ans += 1 print(ans)
false
69.767442
[ "+num_list = []", "-def dfs(s): # 文字列 s で始まる七五三数の個数", "- if int(s) > N:", "- return 0", "- ret = 1 if all(s.count(c) > 0 for c in \"753\") else 0 # s 自体が七五三数なら+1", "- for c in \"753\":", "- ret += dfs(s + c)", "- return ret", "+def dfs(num, add_num):", "+ num *= 10", "+ num += add_num", "+ if num > N:", "+ return", "+ num_list.append(num)", "+ dfs(num, 7)", "+ dfs(num, 5)", "+ dfs(num, 3)", "+ return num_list", "-print((dfs(\"0\"))) # 本当はdfs('')と書きたいがint(s)でエラーを吐かないように仕方なく", "+dfs(3, 3)", "+dfs(3, 5)", "+dfs(3, 7)", "+dfs(5, 3)", "+dfs(5, 5)", "+dfs(5, 7)", "+dfs(7, 3)", "+dfs(7, 5)", "+dfs(7, 7)", "+ans = 0", "+tmp = 0", "+target = set([\"7\", \"5\", \"3\"])", "+# print(num_list)", "+for n in num_list:", "+ tmp = 0", "+ for t in target:", "+ if t in str(n):", "+ tmp += 1", "+ if tmp == 3:", "+ ans += 1", "+print(ans)" ]
false
0.067755
0.067689
1.000971
[ "s323766253", "s873524061" ]
u759412327
p03721
python
s710545773
s764106631
494
323
28,640
5,736
Accepted
Accepted
34.62
N,K = list(map(int, input().split())) s = sorted([list(map(int, input().split())) for i in range(N)]) t = 0 while K>0: K-=s[t][1] t+=1 print((s[t-1][0]))
N,K = list(map(int,input().split())) num = (10**5+1)*[0] tot = 0 for n in range(N): a,b=list(map(int,input().split())) num[a]+=b for n in range(10**5+1): tot+=num[n] if K<=tot: print(n) break
9
13
163
210
N, K = list(map(int, input().split())) s = sorted([list(map(int, input().split())) for i in range(N)]) t = 0 while K > 0: K -= s[t][1] t += 1 print((s[t - 1][0]))
N, K = list(map(int, input().split())) num = (10**5 + 1) * [0] tot = 0 for n in range(N): a, b = list(map(int, input().split())) num[a] += b for n in range(10**5 + 1): tot += num[n] if K <= tot: print(n) break
false
30.769231
[ "-s = sorted([list(map(int, input().split())) for i in range(N)])", "-t = 0", "-while K > 0:", "- K -= s[t][1]", "- t += 1", "-print((s[t - 1][0]))", "+num = (10**5 + 1) * [0]", "+tot = 0", "+for n in range(N):", "+ a, b = list(map(int, input().split()))", "+ num[a] += b", "+for n in range(10**5 + 1):", "+ tot += num[n]", "+ if K <= tot:", "+ print(n)", "+ break" ]
false
0.039746
0.039036
1.018192
[ "s710545773", "s764106631" ]
u077291787
p03993
python
s807415999
s612212719
136
56
22,500
14,008
Accepted
Accepted
58.82
# code-festival-2016-qualaB - 仲良しうさぎ / Friendly Rabbits def main(): N = int(eval(input())) A = tuple(map(int, input().split())) ans, cand = 0, set() for i, j in enumerate(A, 1): i, j = min(i, j), max(i, j) if (i, j) in cand: ans += 1 else: cand |= {(i, j)} print(ans) if __name__ == "__main__": main()
# code-festival-2016-qualaB - 仲良しうさぎ / Friendly Rabbits # exhaustive search def main(): N = int(eval(input())) A = [0] + list(map(int, input().split())) ans = sum(i == A[j] for i, j in enumerate(A[1:], 1)) // 2 print(ans) if __name__ == "__main__": main()
16
11
384
281
# code-festival-2016-qualaB - 仲良しうさぎ / Friendly Rabbits def main(): N = int(eval(input())) A = tuple(map(int, input().split())) ans, cand = 0, set() for i, j in enumerate(A, 1): i, j = min(i, j), max(i, j) if (i, j) in cand: ans += 1 else: cand |= {(i, j)} print(ans) if __name__ == "__main__": main()
# code-festival-2016-qualaB - 仲良しうさぎ / Friendly Rabbits # exhaustive search def main(): N = int(eval(input())) A = [0] + list(map(int, input().split())) ans = sum(i == A[j] for i, j in enumerate(A[1:], 1)) // 2 print(ans) if __name__ == "__main__": main()
false
31.25
[ "+# exhaustive search", "- A = tuple(map(int, input().split()))", "- ans, cand = 0, set()", "- for i, j in enumerate(A, 1):", "- i, j = min(i, j), max(i, j)", "- if (i, j) in cand:", "- ans += 1", "- else:", "- cand |= {(i, j)}", "+ A = [0] + list(map(int, input().split()))", "+ ans = sum(i == A[j] for i, j in enumerate(A[1:], 1)) // 2" ]
false
0.150926
0.101971
1.480088
[ "s807415999", "s612212719" ]
u119148115
p02534
python
s296597965
s860848335
77
70
61,960
61,868
Accepted
Accepted
9.09
import sys sys.setrecursionlimit(10**7) def I(): return int(sys.stdin.readline().rstrip()) def MI(): return list(map(int,sys.stdin.readline().rstrip().split())) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) #空白あり def LI2(): return list(map(int,sys.stdin.readline().rstrip())) #空白なし def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) #空白あり def LS2(): return list(sys.stdin.readline().rstrip()) #空白なし K = I() ans = '' for i in range(K): ans += 'ACL' print(ans)
import sys def I(): return int(sys.stdin.readline().rstrip()) K = I() ans = '' for _ in range(K): ans += 'ACL' print(ans)
17
9
560
136
import sys sys.setrecursionlimit(10**7) def I(): return int(sys.stdin.readline().rstrip()) def MI(): return list(map(int, sys.stdin.readline().rstrip().split())) def LI(): return list(map(int, sys.stdin.readline().rstrip().split())) # 空白あり def LI2(): return list(map(int, sys.stdin.readline().rstrip())) # 空白なし def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) # 空白あり def LS2(): return list(sys.stdin.readline().rstrip()) # 空白なし K = I() ans = "" for i in range(K): ans += "ACL" print(ans)
import sys def I(): return int(sys.stdin.readline().rstrip()) K = I() ans = "" for _ in range(K): ans += "ACL" print(ans)
false
47.058824
[ "-", "-sys.setrecursionlimit(10**7)", "-def MI():", "- return list(map(int, sys.stdin.readline().rstrip().split()))", "-", "-", "-def LI():", "- return list(map(int, sys.stdin.readline().rstrip().split())) # 空白あり", "-", "-", "-def LI2():", "- return list(map(int, sys.stdin.readline().rstrip())) # 空白なし", "-", "-", "-def S():", "- return sys.stdin.readline().rstrip()", "-", "-", "-def LS():", "- return list(sys.stdin.readline().rstrip().split()) # 空白あり", "-", "-", "-def LS2():", "- return list(sys.stdin.readline().rstrip()) # 空白なし", "-", "-", "-for i in range(K):", "+for _ in range(K):" ]
false
0.042722
0.037855
1.128586
[ "s296597965", "s860848335" ]
u865298224
p02819
python
s941589233
s947681010
195
18
7,576
2,940
Accepted
Accepted
90.77
def get_sieve_of_eratosthenes(n): if not isinstance(n, int): raise TypeError('n is int type.') if n < 2: raise ValueError('n is more than 2') prime = [2] limit = int(n**0.5) data = [i + 1 for i in range(2, n, 2)] while True: p = data[0] if limit <= p: return prime + data prime.append(p) data = [e for e in data if e % p != 0] def main(): X = int(eval(input())) primes = get_sieve_of_eratosthenes(X*2) for p in primes: if X <= p: print(p) break if __name__ == "__main__": main()
def is_prime(n): i = 2 while(i**2 <= n): if n % i == 0: return False i += 1 return True def main(): X = int(eval(input())) for x in range(X, 2*X): if is_prime(x): print(x) break if __name__ == "__main__": main()
28
20
637
314
def get_sieve_of_eratosthenes(n): if not isinstance(n, int): raise TypeError("n is int type.") if n < 2: raise ValueError("n is more than 2") prime = [2] limit = int(n**0.5) data = [i + 1 for i in range(2, n, 2)] while True: p = data[0] if limit <= p: return prime + data prime.append(p) data = [e for e in data if e % p != 0] def main(): X = int(eval(input())) primes = get_sieve_of_eratosthenes(X * 2) for p in primes: if X <= p: print(p) break if __name__ == "__main__": main()
def is_prime(n): i = 2 while i**2 <= n: if n % i == 0: return False i += 1 return True def main(): X = int(eval(input())) for x in range(X, 2 * X): if is_prime(x): print(x) break if __name__ == "__main__": main()
false
28.571429
[ "-def get_sieve_of_eratosthenes(n):", "- if not isinstance(n, int):", "- raise TypeError(\"n is int type.\")", "- if n < 2:", "- raise ValueError(\"n is more than 2\")", "- prime = [2]", "- limit = int(n**0.5)", "- data = [i + 1 for i in range(2, n, 2)]", "- while True:", "- p = data[0]", "- if limit <= p:", "- return prime + data", "- prime.append(p)", "- data = [e for e in data if e % p != 0]", "+def is_prime(n):", "+ i = 2", "+ while i**2 <= n:", "+ if n % i == 0:", "+ return False", "+ i += 1", "+ return True", "- primes = get_sieve_of_eratosthenes(X * 2)", "- for p in primes:", "- if X <= p:", "- print(p)", "+ for x in range(X, 2 * X):", "+ if is_prime(x):", "+ print(x)" ]
false
0.052825
0.040658
1.299243
[ "s941589233", "s947681010" ]
u606878291
p03309
python
s890764699
s613134256
273
174
49,444
49,584
Accepted
Accepted
36.26
import numpy as np N = int(eval(input())) A = np.array(list(map(int, input().split(' ')))) i = np.arange(1, N + 1) b = int(np.median(sorted(A - i))) print((np.sum(np.abs(A - (i + b)))))
import numpy as np N = int(eval(input())) A = np.array(list(map(int, input().split(' ')))) diff = A - (np.arange(N) + 1) diff.sort() if N % 2 == 0: median = (diff[N // 2] + diff[N // 2 - 1]) // 2 else: median = diff[N // 2] print((np.sum(np.abs(diff - median))))
9
14
189
280
import numpy as np N = int(eval(input())) A = np.array(list(map(int, input().split(" ")))) i = np.arange(1, N + 1) b = int(np.median(sorted(A - i))) print((np.sum(np.abs(A - (i + b)))))
import numpy as np N = int(eval(input())) A = np.array(list(map(int, input().split(" ")))) diff = A - (np.arange(N) + 1) diff.sort() if N % 2 == 0: median = (diff[N // 2] + diff[N // 2 - 1]) // 2 else: median = diff[N // 2] print((np.sum(np.abs(diff - median))))
false
35.714286
[ "-i = np.arange(1, N + 1)", "-b = int(np.median(sorted(A - i)))", "-print((np.sum(np.abs(A - (i + b)))))", "+diff = A - (np.arange(N) + 1)", "+diff.sort()", "+if N % 2 == 0:", "+ median = (diff[N // 2] + diff[N // 2 - 1]) // 2", "+else:", "+ median = diff[N // 2]", "+print((np.sum(np.abs(diff - median))))" ]
false
0.486502
0.27415
1.774584
[ "s890764699", "s613134256" ]
u968166680
p03329
python
s614804012
s683470587
173
144
9,448
9,192
Accepted
Accepted
16.76
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 MOD = 1000000007 def main(): N = int(readline()) amt = [1] a = 6 while a <= N: amt.append(a) a *= 6 a = 9 while a <= N: amt.append(a) a *= 9 dp = [INF] * (N + 1) dp[0] = 0 for i in range(1, N + 1): for a in amt: if i >= a and dp[i] > dp[i - a]: dp[i] = dp[i - a] + 1 print((dp[N])) return if __name__ == '__main__': main()
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 MOD = 1000000007 def f(n, a): ans = 0 while n > 0: ans += n % a n //= a return ans def main(): N = int(readline()) ans = INF for i in range(N + 1): ans = min(ans, f(i, 6) + f(N - i, 9)) print(ans) return if __name__ == '__main__': main()
37
31
622
477
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10**9) INF = 1 << 60 MOD = 1000000007 def main(): N = int(readline()) amt = [1] a = 6 while a <= N: amt.append(a) a *= 6 a = 9 while a <= N: amt.append(a) a *= 9 dp = [INF] * (N + 1) dp[0] = 0 for i in range(1, N + 1): for a in amt: if i >= a and dp[i] > dp[i - a]: dp[i] = dp[i - a] + 1 print((dp[N])) return if __name__ == "__main__": main()
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10**9) INF = 1 << 60 MOD = 1000000007 def f(n, a): ans = 0 while n > 0: ans += n % a n //= a return ans def main(): N = int(readline()) ans = INF for i in range(N + 1): ans = min(ans, f(i, 6) + f(N - i, 9)) print(ans) return if __name__ == "__main__": main()
false
16.216216
[ "+def f(n, a):", "+ ans = 0", "+ while n > 0:", "+ ans += n % a", "+ n //= a", "+ return ans", "+", "+", "- amt = [1]", "- a = 6", "- while a <= N:", "- amt.append(a)", "- a *= 6", "- a = 9", "- while a <= N:", "- amt.append(a)", "- a *= 9", "- dp = [INF] * (N + 1)", "- dp[0] = 0", "- for i in range(1, N + 1):", "- for a in amt:", "- if i >= a and dp[i] > dp[i - a]:", "- dp[i] = dp[i - a] + 1", "- print((dp[N]))", "+ ans = INF", "+ for i in range(N + 1):", "+ ans = min(ans, f(i, 6) + f(N - i, 9))", "+ print(ans)" ]
false
0.115372
0.121073
0.952913
[ "s614804012", "s683470587" ]
u242518667
p03478
python
s291689588
s080112766
33
28
2,940
2,940
Accepted
Accepted
15.15
n,a,b=list(map(int,input().split())) ans=0 for i in range(1,n+1): if a<=sum(map(int,list(str(i))))<=b: ans+=i print(ans)
n,a,b=list(map(int,input().split())) print((sum(i for i in range(n+1) if a<=sum(map(int,str(i)))<=b)))
7
3
133
97
n, a, b = list(map(int, input().split())) ans = 0 for i in range(1, n + 1): if a <= sum(map(int, list(str(i)))) <= b: ans += i print(ans)
n, a, b = list(map(int, input().split())) print((sum(i for i in range(n + 1) if a <= sum(map(int, str(i))) <= b)))
false
57.142857
[ "-ans = 0", "-for i in range(1, n + 1):", "- if a <= sum(map(int, list(str(i)))) <= b:", "- ans += i", "-print(ans)", "+print((sum(i for i in range(n + 1) if a <= sum(map(int, str(i))) <= b)))" ]
false
0.041986
0.150813
0.278397
[ "s291689588", "s080112766" ]
u368796742
p03798
python
s527225572
s611890427
458
234
6,788
6,928
Accepted
Accepted
48.91
n = int(input()) l = list(input()) def che(k): if l[k] == "o": if ans[k] == 1: if ans[k-1]*ans[(k+1)%n] == 1: return True else: return False else: if ans[k-1]*ans[(k+1)%n] == -1: return True else: return False else: if ans[k] == 1: if ans[k-1]*ans[(k+1)%n] == -1: return True else: return False else: if ans[k-1]*ans[(k+1)%n] == 1: return True else: return False check = [[1,1],[1,-1],[-1,1],[-1,-1]] for j,k in check: ans = [0]*n ans[0] = j ans[1] = k for i in range(1,n): if ans[i] == 1: if l[i] == "o": ans[(i+1)%n] = ans[i-1] else: ans[(i+1)%n] = -ans[i-1] else: if l[i] == "o": ans[(i+1)%n] = -ans[i-1] else: ans[(i+1)%n] = ans[i-1] d = True for m in range(n): if che(m) == False: d = False if d: for i in ans: if i == 1: print("S",end="") else: print("W",end="") exit() print(-1)
n = int(input()) l = list(input()) l += l[0] check = [[1,1],[1,-1],[-1,1],[-1,-1]] for j,k in check: ans=[j,k] for i in range(1,n+1): if ans[i] == 1: if l[i] == "o": ans.append(ans[i-1]) else: ans.append(-ans[i-1]) else: if l[i] == "o": ans.append(-ans[i-1]) else: ans.append(ans[i-1]) if ans[1] == ans[-1] and ans[0] == ans[-2]: for i in ans[:-2]: if i == 1: print("S",end="") else: print("W",end="") exit() print(-1)
62
32
1,401
694
n = int(input()) l = list(input()) def che(k): if l[k] == "o": if ans[k] == 1: if ans[k - 1] * ans[(k + 1) % n] == 1: return True else: return False else: if ans[k - 1] * ans[(k + 1) % n] == -1: return True else: return False else: if ans[k] == 1: if ans[k - 1] * ans[(k + 1) % n] == -1: return True else: return False else: if ans[k - 1] * ans[(k + 1) % n] == 1: return True else: return False check = [[1, 1], [1, -1], [-1, 1], [-1, -1]] for j, k in check: ans = [0] * n ans[0] = j ans[1] = k for i in range(1, n): if ans[i] == 1: if l[i] == "o": ans[(i + 1) % n] = ans[i - 1] else: ans[(i + 1) % n] = -ans[i - 1] else: if l[i] == "o": ans[(i + 1) % n] = -ans[i - 1] else: ans[(i + 1) % n] = ans[i - 1] d = True for m in range(n): if che(m) == False: d = False if d: for i in ans: if i == 1: print("S", end="") else: print("W", end="") exit() print(-1)
n = int(input()) l = list(input()) l += l[0] check = [[1, 1], [1, -1], [-1, 1], [-1, -1]] for j, k in check: ans = [j, k] for i in range(1, n + 1): if ans[i] == 1: if l[i] == "o": ans.append(ans[i - 1]) else: ans.append(-ans[i - 1]) else: if l[i] == "o": ans.append(-ans[i - 1]) else: ans.append(ans[i - 1]) if ans[1] == ans[-1] and ans[0] == ans[-2]: for i in ans[:-2]: if i == 1: print("S", end="") else: print("W", end="") exit() print(-1)
false
48.387097
[ "-", "-", "-def che(k):", "- if l[k] == \"o\":", "- if ans[k] == 1:", "- if ans[k - 1] * ans[(k + 1) % n] == 1:", "- return True", "- else:", "- return False", "- else:", "- if ans[k - 1] * ans[(k + 1) % n] == -1:", "- return True", "- else:", "- return False", "- else:", "- if ans[k] == 1:", "- if ans[k - 1] * ans[(k + 1) % n] == -1:", "- return True", "- else:", "- return False", "- else:", "- if ans[k - 1] * ans[(k + 1) % n] == 1:", "- return True", "- else:", "- return False", "-", "-", "+l += l[0]", "- ans = [0] * n", "- ans[0] = j", "- ans[1] = k", "- for i in range(1, n):", "+ ans = [j, k]", "+ for i in range(1, n + 1):", "- ans[(i + 1) % n] = ans[i - 1]", "+ ans.append(ans[i - 1])", "- ans[(i + 1) % n] = -ans[i - 1]", "+ ans.append(-ans[i - 1])", "- ans[(i + 1) % n] = -ans[i - 1]", "+ ans.append(-ans[i - 1])", "- ans[(i + 1) % n] = ans[i - 1]", "- d = True", "- for m in range(n):", "- if che(m) == False:", "- d = False", "- if d:", "- for i in ans:", "+ ans.append(ans[i - 1])", "+ if ans[1] == ans[-1] and ans[0] == ans[-2]:", "+ for i in ans[:-2]:" ]
false
0.035032
0.035035
0.999912
[ "s527225572", "s611890427" ]
u296518383
p03607
python
s352760061
s867470028
231
96
19,816
16,620
Accepted
Accepted
58.44
import collections N=int(eval(input())) A=[int(eval(input())) for _ in range(N)] A=collections.Counter(A) A=list(A.items()) ans=0 for a in A: if a[1]%2==1: ans+=1 print(ans)
import sys input = sys.stdin.buffer.readline from collections import defaultdict N = int(eval(input())) A = [int(eval(input())) for _ in range(N)] cnt = defaultdict(int) for a in A: if cnt[a]: cnt[a] = 0 else: cnt[a] = 1 print((sum(cnt.values())))
12
16
180
276
import collections N = int(eval(input())) A = [int(eval(input())) for _ in range(N)] A = collections.Counter(A) A = list(A.items()) ans = 0 for a in A: if a[1] % 2 == 1: ans += 1 print(ans)
import sys input = sys.stdin.buffer.readline from collections import defaultdict N = int(eval(input())) A = [int(eval(input())) for _ in range(N)] cnt = defaultdict(int) for a in A: if cnt[a]: cnt[a] = 0 else: cnt[a] = 1 print((sum(cnt.values())))
false
25
[ "-import collections", "+import sys", "+", "+input = sys.stdin.buffer.readline", "+from collections import defaultdict", "-A = collections.Counter(A)", "-A = list(A.items())", "-ans = 0", "+cnt = defaultdict(int)", "- if a[1] % 2 == 1:", "- ans += 1", "-print(ans)", "+ if cnt[a]:", "+ cnt[a] = 0", "+ else:", "+ cnt[a] = 1", "+print((sum(cnt.values())))" ]
false
0.044739
0.037312
1.199061
[ "s352760061", "s867470028" ]
u225020286
p02947
python
s601228695
s104845520
405
320
41,116
26,960
Accepted
Accepted
20.99
import collections N=int(eval(input())) S=[list(eval(input())) for i in range(N)] x=[] ans=0 for i in S: a=sorted(i) a="".join(a) x.append(a) x=collections.Counter(x) for i in list(x.values()): ans+=i*(i-1)/2 print((int(ans)))
import collections N=int(eval(input())) s=[eval(input()) for i in range(N)] S=[] ans=0 for i in s: a=sorted(i) a="".join(a) S.append(a) c=collections.Counter(S) d=list(map(int,list(c.values()))) for i in d: ans+=i*(i-1)/2 print((int(ans)))
14
15
236
245
import collections N = int(eval(input())) S = [list(eval(input())) for i in range(N)] x = [] ans = 0 for i in S: a = sorted(i) a = "".join(a) x.append(a) x = collections.Counter(x) for i in list(x.values()): ans += i * (i - 1) / 2 print((int(ans)))
import collections N = int(eval(input())) s = [eval(input()) for i in range(N)] S = [] ans = 0 for i in s: a = sorted(i) a = "".join(a) S.append(a) c = collections.Counter(S) d = list(map(int, list(c.values()))) for i in d: ans += i * (i - 1) / 2 print((int(ans)))
false
6.666667
[ "-S = [list(eval(input())) for i in range(N)]", "-x = []", "+s = [eval(input()) for i in range(N)]", "+S = []", "-for i in S:", "+for i in s:", "- x.append(a)", "-x = collections.Counter(x)", "-for i in list(x.values()):", "+ S.append(a)", "+c = collections.Counter(S)", "+d = list(map(int, list(c.values())))", "+for i in d:" ]
false
0.170584
0.087751
1.943961
[ "s601228695", "s104845520" ]
u426534722
p02279
python
s279624091
s971870683
660
560
34,844
34,520
Accepted
Accepted
15.15
import sys readline = sys.stdin.readline class Tree: __slots__ = ['id', 'p', 'depth', 'type', 'c'] def __init__(self): self.id = 0 self.p = -1 self.depth = -1 self.type = "leaf" self.c = [] def __str__(self): return f"node {self.id}: parent = {self.p}, depth = {self.depth}, {self.type}, {self.c}" n = int(input()) li = tuple(Tree() for _ in range(n)) for _ in range(n): id, k, *c = map(int, readline().split()) if k == 0: c = [] else: li[id].type = "internal node" li[id].id = id li[id].c = c for j in c: li[j].p = id root = 0 while True: a = li[root].p if a == -1: li[root].type = "root" li[root].depth = 0 break root = a dp = [(root, 0)] while dp: id, d = dp.pop() d += 1 for i in li[id].c: li[i].depth = d dp.append((i, d)) print(*li, sep="\n")
import sys readline = sys.stdin.readline class Tree: __slots__ = ['id', 'p', 'depth', 'type', 'c'] def __init__(self, id): self.id = id self.p = -1 self.depth = -1 self.type = "leaf" self.c = [] def __str__(self): return f"node {self.id}: parent = {self.p}, depth = {self.depth}, {self.type}, {self.c}" n = int(input()) li = tuple(Tree(i) for i in range(n)) for _ in range(n): id, k, *c = map(int, readline().split()) if k != 0: li[id].type = "internal node" li[id].c = c for j in c: li[j].p = id root = 0 while li[root].p != -1: root = li[root].p li[root].type = "root" li[root].depth = 0 def depth_check(id, d): d += 1 for i in li[id].c: li[i].depth = d if li[i].type != "leaf": depth_check(i, d) depth_check(root, 0) print(*li, sep="\n")
41
35
962
920
import sys readline = sys.stdin.readline class Tree: __slots__ = ["id", "p", "depth", "type", "c"] def __init__(self): self.id = 0 self.p = -1 self.depth = -1 self.type = "leaf" self.c = [] def __str__(self): return f"node {self.id}: parent = {self.p}, depth = {self.depth}, {self.type}, {self.c}" n = int(input()) li = tuple(Tree() for _ in range(n)) for _ in range(n): id, k, *c = map(int, readline().split()) if k == 0: c = [] else: li[id].type = "internal node" li[id].id = id li[id].c = c for j in c: li[j].p = id root = 0 while True: a = li[root].p if a == -1: li[root].type = "root" li[root].depth = 0 break root = a dp = [(root, 0)] while dp: id, d = dp.pop() d += 1 for i in li[id].c: li[i].depth = d dp.append((i, d)) print(*li, sep="\n")
import sys readline = sys.stdin.readline class Tree: __slots__ = ["id", "p", "depth", "type", "c"] def __init__(self, id): self.id = id self.p = -1 self.depth = -1 self.type = "leaf" self.c = [] def __str__(self): return f"node {self.id}: parent = {self.p}, depth = {self.depth}, {self.type}, {self.c}" n = int(input()) li = tuple(Tree(i) for i in range(n)) for _ in range(n): id, k, *c = map(int, readline().split()) if k != 0: li[id].type = "internal node" li[id].c = c for j in c: li[j].p = id root = 0 while li[root].p != -1: root = li[root].p li[root].type = "root" li[root].depth = 0 def depth_check(id, d): d += 1 for i in li[id].c: li[i].depth = d if li[i].type != "leaf": depth_check(i, d) depth_check(root, 0) print(*li, sep="\n")
false
14.634146
[ "- def __init__(self):", "- self.id = 0", "+ def __init__(self, id):", "+ self.id = id", "-li = tuple(Tree() for _ in range(n))", "+li = tuple(Tree(i) for i in range(n))", "- if k == 0:", "- c = []", "- else:", "+ if k != 0:", "- li[id].id = id", "- li[id].c = c", "- for j in c:", "- li[j].p = id", "+ li[id].c = c", "+ for j in c:", "+ li[j].p = id", "-while True:", "- a = li[root].p", "- if a == -1:", "- li[root].type = \"root\"", "- li[root].depth = 0", "- break", "- root = a", "-dp = [(root, 0)]", "-while dp:", "- id, d = dp.pop()", "+while li[root].p != -1:", "+ root = li[root].p", "+li[root].type = \"root\"", "+li[root].depth = 0", "+", "+", "+def depth_check(id, d):", "- dp.append((i, d))", "+ if li[i].type != \"leaf\":", "+ depth_check(i, d)", "+", "+", "+depth_check(root, 0)" ]
false
0.049997
0.048304
1.035039
[ "s279624091", "s971870683" ]
u602500004
p02684
python
s063511731
s128338971
386
197
202,428
32,520
Accepted
Accepted
48.96
import bisect,collections,copy,heapq,itertools,math,string from collections import defaultdict as D from functools import reduce import numpy as np import sys import os from operator import mul sys.setrecursionlimit(10**7) def _S(): return sys.stdin.readline().rstrip() def I(): return int(_S()) def LS(): return list(_S().split()) def LI(): return list(map(int,LS())) if os.getenv("LOCAL"): inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt' sys.stdin = open(inputFile, "r") # k: number of transfer _,k = LI() a = LI() # 街の番号を0始まりに変更 a = list([x-1 for x in a]) # print(a) s = set([0]) # 再帰関数 def rec(visited,next): if next in s: # print(visited) return visited,visited.index(next) else: s.add(next) visited.append(next) return rec(visited,a[next]) visited = [0] # 訪れた街、初めて2度訪れた街のインデックスを取得 visited,loopStart = rec(visited,a[0]) # print(visited,loopStart) if k < len(visited): townIndex = visited[k] else: visitedLoop = visited[loopStart:] # print(visitedLoop) # 残り回数を循環配列の長さで割った余り index = (k-(loopStart))%len(visitedLoop) # print(index) townIndex = visitedLoop[index] print((townIndex+1))
import math import sys import os from operator import mul sys.setrecursionlimit(10**7) def _S(): return sys.stdin.readline().rstrip() def I(): return int(_S()) def LS(): return list(_S().split()) def LI(): return list(map(int,LS())) if os.getenv("LOCAL"): inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt' sys.stdin = open(inputFile, "r") INF = float("inf") _,k = LI() a = LI() a = list([x-1 for x in a]) # 訪れる順序、indexは移動回数 route = [0] # 訪れた番号、高速検索用にhash tableを使う visited = set([0]) next = a[0] while True: if next in visited: loopStart = route.index(next) break else: route.append(next) visited.add(next) next = a[next] # print(route) # print(loopStart) beforeLoop = route[:loopStart] # print(beforeLoop) loop = route[loopStart:] # print(loop) # loop前 if k < loopStart: ans = beforeLoop[k] # loop後 else: numOfLoops,mod = divmod((k-(loopStart)),len(loop)) # print(numOfLoops,mod) ans = loop[mod] ans += 1 print(ans)
55
57
1,276
1,098
import bisect, collections, copy, heapq, itertools, math, string from collections import defaultdict as D from functools import reduce import numpy as np import sys import os from operator import mul sys.setrecursionlimit(10**7) def _S(): return sys.stdin.readline().rstrip() def I(): return int(_S()) def LS(): return list(_S().split()) def LI(): return list(map(int, LS())) if os.getenv("LOCAL"): inputFile = basename_without_ext = ( os.path.splitext(os.path.basename(__file__))[0] + ".txt" ) sys.stdin = open(inputFile, "r") # k: number of transfer _, k = LI() a = LI() # 街の番号を0始まりに変更 a = list([x - 1 for x in a]) # print(a) s = set([0]) # 再帰関数 def rec(visited, next): if next in s: # print(visited) return visited, visited.index(next) else: s.add(next) visited.append(next) return rec(visited, a[next]) visited = [0] # 訪れた街、初めて2度訪れた街のインデックスを取得 visited, loopStart = rec(visited, a[0]) # print(visited,loopStart) if k < len(visited): townIndex = visited[k] else: visitedLoop = visited[loopStart:] # print(visitedLoop) # 残り回数を循環配列の長さで割った余り index = (k - (loopStart)) % len(visitedLoop) # print(index) townIndex = visitedLoop[index] print((townIndex + 1))
import math import sys import os from operator import mul sys.setrecursionlimit(10**7) def _S(): return sys.stdin.readline().rstrip() def I(): return int(_S()) def LS(): return list(_S().split()) def LI(): return list(map(int, LS())) if os.getenv("LOCAL"): inputFile = basename_without_ext = ( os.path.splitext(os.path.basename(__file__))[0] + ".txt" ) sys.stdin = open(inputFile, "r") INF = float("inf") _, k = LI() a = LI() a = list([x - 1 for x in a]) # 訪れる順序、indexは移動回数 route = [0] # 訪れた番号、高速検索用にhash tableを使う visited = set([0]) next = a[0] while True: if next in visited: loopStart = route.index(next) break else: route.append(next) visited.add(next) next = a[next] # print(route) # print(loopStart) beforeLoop = route[:loopStart] # print(beforeLoop) loop = route[loopStart:] # print(loop) # loop前 if k < loopStart: ans = beforeLoop[k] # loop後 else: numOfLoops, mod = divmod((k - (loopStart)), len(loop)) # print(numOfLoops,mod) ans = loop[mod] ans += 1 print(ans)
false
3.508772
[ "-import bisect, collections, copy, heapq, itertools, math, string", "-from collections import defaultdict as D", "-from functools import reduce", "-import numpy as np", "+import math", "-# k: number of transfer", "+INF = float(\"inf\")", "-# 街の番号を0始まりに変更", "-# print(a)", "-s = set([0])", "-# 再帰関数", "-def rec(visited, next):", "- if next in s:", "- # print(visited)", "- return visited, visited.index(next)", "+# 訪れる順序、indexは移動回数", "+route = [0]", "+# 訪れた番号、高速検索用にhash tableを使う", "+visited = set([0])", "+next = a[0]", "+while True:", "+ if next in visited:", "+ loopStart = route.index(next)", "+ break", "- s.add(next)", "- visited.append(next)", "- return rec(visited, a[next])", "-", "-", "-visited = [0]", "-# 訪れた街、初めて2度訪れた街のインデックスを取得", "-visited, loopStart = rec(visited, a[0])", "-# print(visited,loopStart)", "-if k < len(visited):", "- townIndex = visited[k]", "+ route.append(next)", "+ visited.add(next)", "+ next = a[next]", "+# print(route)", "+# print(loopStart)", "+beforeLoop = route[:loopStart]", "+# print(beforeLoop)", "+loop = route[loopStart:]", "+# print(loop)", "+# loop前", "+if k < loopStart:", "+ ans = beforeLoop[k]", "+# loop後", "- visitedLoop = visited[loopStart:]", "- # print(visitedLoop)", "- # 残り回数を循環配列の長さで割った余り", "- index = (k - (loopStart)) % len(visitedLoop)", "- # print(index)", "- townIndex = visitedLoop[index]", "-print((townIndex + 1))", "+ numOfLoops, mod = divmod((k - (loopStart)), len(loop))", "+ # print(numOfLoops,mod)", "+ ans = loop[mod]", "+ans += 1", "+print(ans)" ]
false
0.064543
0.046668
1.383027
[ "s063511731", "s128338971" ]
u011062360
p02803
python
s043947866
s377148722
396
233
3,316
9,248
Accepted
Accepted
41.16
from collections import deque def bfs(h, w, s, sx, sy): dx = [1, 0, -1, 0] dy = [0, 1, 0, -1] d = [[-1] * w for _ in range(h)] d[sx][sy] = 0 que = deque() que.append((sx, sy)) while que: x, y = que.popleft() for i in range(4): nx = x + dx[i] ny = y + dy[i] if 0 <= nx < h and 0 <= ny < w and s[nx][ny] != '#' and d[nx][ny] == -1: que.append((nx, ny)) d[nx][ny] = d[x][y] + 1 md = 0 for i in range(h): for j in range(w): md = max(md, d[i][j]) return md h, w = [int(_) for _ in input().split()] s = [0] * h for i in range(h): s[i] = list(eval(input())) ans = 0 for i in range(h): for j in range(w): if s[i][j] == '.': ans = max(ans, bfs(h, w, s, i, j)) print(ans)
h, w = list(map(int, input().split())) ma = [ list(eval(input())) for _ in range(h) ] d = [(1, 0), (-1, 0), (0, 1), (0, -1)] ans = 0 def bfs(sy, sx): if ma[sy][sx] == "#": return 0 q = [[sy, sx, 0]] flag = [[0] * w for _ in range(h)] flag[sy][sx] = 1 ans = 0 while True: if len(q) == 0: break y, x, dist = q.pop(0) for dy, dx in d: if 0 <= y + dy < h and 0 <= x + dx < w and flag[y + dy][x + dx] == 0 and ma[y + dy][x + dx] == ".": flag[y + dy][x + dx] = 1 q.append([y + dy, x + dx, dist + 1]) ans = max(ans, dist + 1) return ans for j in range(h): for i in range(w): ans = max(ans, bfs(j, i)) print(ans)
39
30
879
770
from collections import deque def bfs(h, w, s, sx, sy): dx = [1, 0, -1, 0] dy = [0, 1, 0, -1] d = [[-1] * w for _ in range(h)] d[sx][sy] = 0 que = deque() que.append((sx, sy)) while que: x, y = que.popleft() for i in range(4): nx = x + dx[i] ny = y + dy[i] if 0 <= nx < h and 0 <= ny < w and s[nx][ny] != "#" and d[nx][ny] == -1: que.append((nx, ny)) d[nx][ny] = d[x][y] + 1 md = 0 for i in range(h): for j in range(w): md = max(md, d[i][j]) return md h, w = [int(_) for _ in input().split()] s = [0] * h for i in range(h): s[i] = list(eval(input())) ans = 0 for i in range(h): for j in range(w): if s[i][j] == ".": ans = max(ans, bfs(h, w, s, i, j)) print(ans)
h, w = list(map(int, input().split())) ma = [list(eval(input())) for _ in range(h)] d = [(1, 0), (-1, 0), (0, 1), (0, -1)] ans = 0 def bfs(sy, sx): if ma[sy][sx] == "#": return 0 q = [[sy, sx, 0]] flag = [[0] * w for _ in range(h)] flag[sy][sx] = 1 ans = 0 while True: if len(q) == 0: break y, x, dist = q.pop(0) for dy, dx in d: if ( 0 <= y + dy < h and 0 <= x + dx < w and flag[y + dy][x + dx] == 0 and ma[y + dy][x + dx] == "." ): flag[y + dy][x + dx] = 1 q.append([y + dy, x + dx, dist + 1]) ans = max(ans, dist + 1) return ans for j in range(h): for i in range(w): ans = max(ans, bfs(j, i)) print(ans)
false
23.076923
[ "-from collections import deque", "+h, w = list(map(int, input().split()))", "+ma = [list(eval(input())) for _ in range(h)]", "+d = [(1, 0), (-1, 0), (0, 1), (0, -1)]", "+ans = 0", "-def bfs(h, w, s, sx, sy):", "- dx = [1, 0, -1, 0]", "- dy = [0, 1, 0, -1]", "- d = [[-1] * w for _ in range(h)]", "- d[sx][sy] = 0", "- que = deque()", "- que.append((sx, sy))", "- while que:", "- x, y = que.popleft()", "- for i in range(4):", "- nx = x + dx[i]", "- ny = y + dy[i]", "- if 0 <= nx < h and 0 <= ny < w and s[nx][ny] != \"#\" and d[nx][ny] == -1:", "- que.append((nx, ny))", "- d[nx][ny] = d[x][y] + 1", "- md = 0", "- for i in range(h):", "- for j in range(w):", "- md = max(md, d[i][j])", "- return md", "+def bfs(sy, sx):", "+ if ma[sy][sx] == \"#\":", "+ return 0", "+ q = [[sy, sx, 0]]", "+ flag = [[0] * w for _ in range(h)]", "+ flag[sy][sx] = 1", "+ ans = 0", "+ while True:", "+ if len(q) == 0:", "+ break", "+ y, x, dist = q.pop(0)", "+ for dy, dx in d:", "+ if (", "+ 0 <= y + dy < h", "+ and 0 <= x + dx < w", "+ and flag[y + dy][x + dx] == 0", "+ and ma[y + dy][x + dx] == \".\"", "+ ):", "+ flag[y + dy][x + dx] = 1", "+ q.append([y + dy, x + dx, dist + 1])", "+ ans = max(ans, dist + 1)", "+ return ans", "-h, w = [int(_) for _ in input().split()]", "-s = [0] * h", "-for i in range(h):", "- s[i] = list(eval(input()))", "-ans = 0", "-for i in range(h):", "- for j in range(w):", "- if s[i][j] == \".\":", "- ans = max(ans, bfs(h, w, s, i, j))", "+for j in range(h):", "+ for i in range(w):", "+ ans = max(ans, bfs(j, i))" ]
false
0.1494
0.129012
1.158027
[ "s043947866", "s377148722" ]