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
u217627525
p03737
python
s676319048
s078602161
19
17
2,940
2,940
Accepted
Accepted
10.53
s1,s2,s3=input().split() s1=s1.upper() s2=s2.upper() s3=s3.upper() print((s1[0]+s2[0]+s3[0]))
s1,s2,s3=input().split() print((s1[0].upper()+s2[0].upper()+s3[0].upper()))
5
2
95
74
s1, s2, s3 = input().split() s1 = s1.upper() s2 = s2.upper() s3 = s3.upper() print((s1[0] + s2[0] + s3[0]))
s1, s2, s3 = input().split() print((s1[0].upper() + s2[0].upper() + s3[0].upper()))
false
60
[ "-s1 = s1.upper()", "-s2 = s2.upper()", "-s3 = s3.upper()", "-print((s1[0] + s2[0] + s3[0]))", "+print((s1[0].upper() + s2[0].upper() + s3[0].upper()))" ]
false
0.059952
0.044351
1.351774
[ "s676319048", "s078602161" ]
u127499732
p02899
python
s242807443
s800386589
81
72
15,588
15,528
Accepted
Accepted
11.11
def main(): n=int(eval(input())) a=list(map(int,input().split())) b=[0]*n for index,number in enumerate(a): b[number-1]=str(index+1) print((" ".join(b))) if __name__=="__main__": main()
def main(): import sys n=int(eval(input())) a=tuple(map(int,sys.stdin.readline().split())) b=[0]*n for index,number in enumerate(a): b[number-1]=str(index+1) print((" ".join(b))) if __name__=="__main__": main()
9
10
201
229
def main(): n = int(eval(input())) a = list(map(int, input().split())) b = [0] * n for index, number in enumerate(a): b[number - 1] = str(index + 1) print((" ".join(b))) if __name__ == "__main__": main()
def main(): import sys n = int(eval(input())) a = tuple(map(int, sys.stdin.readline().split())) b = [0] * n for index, number in enumerate(a): b[number - 1] = str(index + 1) print((" ".join(b))) if __name__ == "__main__": main()
false
10
[ "+ import sys", "+", "- a = list(map(int, input().split()))", "+ a = tuple(map(int, sys.stdin.readline().split()))" ]
false
0.162359
0.053131
3.055798
[ "s242807443", "s800386589" ]
u475402977
p02583
python
s906455176
s253840093
165
116
9,220
9,116
Accepted
Accepted
29.7
import itertools N=int(eval(input())) A=list(map(int, input().split())) ans=0 for any_pair in itertools.combinations(A, 3): pair=sorted(any_pair) #print(type(pair)) if pair[0]+pair[1]>pair[2] and pair[1]+pair[2]>pair[0] and pair[0]+pair[2]>pair[1] and pair[0]!=pair[1] and pair[1]!=pair[2]: ans+=1 #print(pair) print(ans)
import itertools N=int(eval(input())) A=list(map(int, input().split())) ans=0 for any_pair in itertools.combinations(A, 3): pair=sorted(any_pair)#新しいリストを作成 #print(type(pair)) if pair[0]+pair[1]>pair[2] and pair[0]!=pair[1] and pair[1]!=pair[2]: ans+=1 #print(pair) print(ans)
11
11
353
307
import itertools N = int(eval(input())) A = list(map(int, input().split())) ans = 0 for any_pair in itertools.combinations(A, 3): pair = sorted(any_pair) # print(type(pair)) if ( pair[0] + pair[1] > pair[2] and pair[1] + pair[2] > pair[0] and pair[0] + pair[2] > pair[1] and pair[0] != pair[1] and pair[1] != pair[2] ): ans += 1 # print(pair) print(ans)
import itertools N = int(eval(input())) A = list(map(int, input().split())) ans = 0 for any_pair in itertools.combinations(A, 3): pair = sorted(any_pair) # 新しいリストを作成 # print(type(pair)) if pair[0] + pair[1] > pair[2] and pair[0] != pair[1] and pair[1] != pair[2]: ans += 1 # print(pair) print(ans)
false
0
[ "- pair = sorted(any_pair)", "+ pair = sorted(any_pair) # 新しいリストを作成", "- if (", "- pair[0] + pair[1] > pair[2]", "- and pair[1] + pair[2] > pair[0]", "- and pair[0] + pair[2] > pair[1]", "- and pair[0] != pair[1]", "- and pair[1] != pair[2]", "- ):", "+ if pair[0] + pair[1] > pair[2] and pair[0] != pair[1] and pair[1] != pair[2]:" ]
false
0.036929
0.037358
0.988497
[ "s906455176", "s253840093" ]
u210827208
p02684
python
s373984561
s463638950
175
108
32,400
95,628
Accepted
Accepted
38.29
n,k=list(map(int,input().split())) A=list(map(int,input().split())) cnt=0 s=1 M=[0] B=[0]*(n+1) while cnt<n: s=A[s-1] if B[s-1]==0: B[s-1]+=1 else: imp=s-1 break M.append(s-1) cnt+=1 x=M.index(imp) y=len(M)-x if k<=x: print((M[k]+1)) else: N=M[x:] print((N[(k-x)%y]+1))
n,k=list(map(int,input().split())) A=list(map(int,input().split())) cnt=0 s=1 M=[0] B=[False]*(n+1) while cnt<n: s=A[s-1] if not B[s-1]: B[s-1]=True else: break M.append(s-1) cnt+=1 x=M.index(s-1) y=len(M)-x if k<=x: print((M[k]+1)) else: N=M[x:] print((N[(k-x)%y]+1))
23
22
338
328
n, k = list(map(int, input().split())) A = list(map(int, input().split())) cnt = 0 s = 1 M = [0] B = [0] * (n + 1) while cnt < n: s = A[s - 1] if B[s - 1] == 0: B[s - 1] += 1 else: imp = s - 1 break M.append(s - 1) cnt += 1 x = M.index(imp) y = len(M) - x if k <= x: print((M[k] + 1)) else: N = M[x:] print((N[(k - x) % y] + 1))
n, k = list(map(int, input().split())) A = list(map(int, input().split())) cnt = 0 s = 1 M = [0] B = [False] * (n + 1) while cnt < n: s = A[s - 1] if not B[s - 1]: B[s - 1] = True else: break M.append(s - 1) cnt += 1 x = M.index(s - 1) y = len(M) - x if k <= x: print((M[k] + 1)) else: N = M[x:] print((N[(k - x) % y] + 1))
false
4.347826
[ "-B = [0] * (n + 1)", "+B = [False] * (n + 1)", "- if B[s - 1] == 0:", "- B[s - 1] += 1", "+ if not B[s - 1]:", "+ B[s - 1] = True", "- imp = s - 1", "-x = M.index(imp)", "+x = M.index(s - 1)" ]
false
0.139517
0.060777
2.295574
[ "s373984561", "s463638950" ]
u254871849
p03221
python
s140193478
s473941668
1,037
481
77,172
60,912
Accepted
Accepted
53.62
# 2019-11-11 14:35:02(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 # from scipy.misc import comb # float # import numpy as np from copy import deepcopy def main(): n, m = (int(x) for x in sys.stdin.readline().split()) PY = [[int(x) for x in sys.stdin.readline().split()] for _ in range(m)] py = sorted(deepcopy(PY)) ids = dict() for i in range(m): p, y = py[i][0], py[i][1] if not p in ids: ids[p] = dict() x = 0 x += 1 id_i = '0' * (6 - (math.floor(math.log10(p)) + 1)) + str(p) + '0' * (6 - (math.floor(math.log10(x)) + 1)) + str(x) ids[p][y] = id_i for i in range(m): p, y = PY[i][0], PY[i][1] print((ids[p][y])) if __name__ == "__main__": main()
import sys from collections import defaultdict n, m, *py = map(int, sys.stdin.read().split()) py = list(zip(*[iter(py)] * 2)) def main(): ids = defaultdict(list) for p, y in py: ids[p].append(y) for p, ys in ids.items(): ids[p] = dict([(y, i) for i, y in enumerate(sorted(ys), 1)]) for p, y in py: x = ids[p][y] first = str(p) last = str(x) first = '0' * (6 - len(first)) + first last = '0' * (6 - len(last)) + last yield first + last if __name__ == '__main__': ans = main() print(*ans, sep='\n')
35
25
1,003
625
# 2019-11-11 14:35:02(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 # from scipy.misc import comb # float # import numpy as np from copy import deepcopy def main(): n, m = (int(x) for x in sys.stdin.readline().split()) PY = [[int(x) for x in sys.stdin.readline().split()] for _ in range(m)] py = sorted(deepcopy(PY)) ids = dict() for i in range(m): p, y = py[i][0], py[i][1] if not p in ids: ids[p] = dict() x = 0 x += 1 id_i = ( "0" * (6 - (math.floor(math.log10(p)) + 1)) + str(p) + "0" * (6 - (math.floor(math.log10(x)) + 1)) + str(x) ) ids[p][y] = id_i for i in range(m): p, y = PY[i][0], PY[i][1] print((ids[p][y])) if __name__ == "__main__": main()
import sys from collections import defaultdict n, m, *py = map(int, sys.stdin.read().split()) py = list(zip(*[iter(py)] * 2)) def main(): ids = defaultdict(list) for p, y in py: ids[p].append(y) for p, ys in ids.items(): ids[p] = dict([(y, i) for i, y in enumerate(sorted(ys), 1)]) for p, y in py: x = ids[p][y] first = str(p) last = str(x) first = "0" * (6 - len(first)) + first last = "0" * (6 - len(last)) + last yield first + last if __name__ == "__main__": ans = main() print(*ans, sep="\n")
false
28.571429
[ "-# 2019-11-11 14:35:02(JST)", "+from collections import defaultdict", "-# 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", "-# from scipy.misc import comb # float", "-# import numpy as np", "-from copy import deepcopy", "+n, m, *py = map(int, sys.stdin.read().split())", "+py = list(zip(*[iter(py)] * 2))", "- n, m = (int(x) for x in sys.stdin.readline().split())", "- PY = [[int(x) for x in sys.stdin.readline().split()] for _ in range(m)]", "- py = sorted(deepcopy(PY))", "- ids = dict()", "- for i in range(m):", "- p, y = py[i][0], py[i][1]", "- if not p in ids:", "- ids[p] = dict()", "- x = 0", "- x += 1", "- id_i = (", "- \"0\" * (6 - (math.floor(math.log10(p)) + 1))", "- + str(p)", "- + \"0\" * (6 - (math.floor(math.log10(x)) + 1))", "- + str(x)", "- )", "- ids[p][y] = id_i", "- for i in range(m):", "- p, y = PY[i][0], PY[i][1]", "- print((ids[p][y]))", "+ ids = defaultdict(list)", "+ for p, y in py:", "+ ids[p].append(y)", "+ for p, ys in ids.items():", "+ ids[p] = dict([(y, i) for i, y in enumerate(sorted(ys), 1)])", "+ for p, y in py:", "+ x = ids[p][y]", "+ first = str(p)", "+ last = str(x)", "+ first = \"0\" * (6 - len(first)) + first", "+ last = \"0\" * (6 - len(last)) + last", "+ yield first + last", "- main()", "+ ans = main()", "+ print(*ans, sep=\"\\n\")" ]
false
0.084687
0.036766
2.303438
[ "s140193478", "s473941668" ]
u644907318
p03804
python
s896795551
s117421387
168
65
38,384
63,580
Accepted
Accepted
61.31
N,M = list(map(int,input().split())) A = [input().strip() for _ in range(N)] B = [input().strip() for _ in range(M)] for i in range(N-M+1): for j in range(N-M+1): flag = 0 for k in range(M): for l in range(M): if B[k][l] != A[i+k][j+l]: flag=1 break if flag==1:break if flag==0:break if flag==0:break if flag==0: print("Yes") else: print("No")
N,M = list(map(int,input().split())) A = [] for _ in range(N): A.append(input().strip()) B = [] for _ in range(M): B.append(input().strip()) flag = 0 for i in range(N-M+1): for j in range(N-M+1): ind = 0 for k in range(M): for l in range(M): if A[i+k][j+l]!=B[k][l]: ind = 1 break if ind==1:break if ind==0: flag = 1 if flag==1:break if flag==1: print("Yes") else: print("No")
18
24
474
533
N, M = list(map(int, input().split())) A = [input().strip() for _ in range(N)] B = [input().strip() for _ in range(M)] for i in range(N - M + 1): for j in range(N - M + 1): flag = 0 for k in range(M): for l in range(M): if B[k][l] != A[i + k][j + l]: flag = 1 break if flag == 1: break if flag == 0: break if flag == 0: break if flag == 0: print("Yes") else: print("No")
N, M = list(map(int, input().split())) A = [] for _ in range(N): A.append(input().strip()) B = [] for _ in range(M): B.append(input().strip()) flag = 0 for i in range(N - M + 1): for j in range(N - M + 1): ind = 0 for k in range(M): for l in range(M): if A[i + k][j + l] != B[k][l]: ind = 1 break if ind == 1: break if ind == 0: flag = 1 if flag == 1: break if flag == 1: print("Yes") else: print("No")
false
25
[ "-A = [input().strip() for _ in range(N)]", "-B = [input().strip() for _ in range(M)]", "+A = []", "+for _ in range(N):", "+ A.append(input().strip())", "+B = []", "+for _ in range(M):", "+ B.append(input().strip())", "+flag = 0", "- flag = 0", "+ ind = 0", "- if B[k][l] != A[i + k][j + l]:", "- flag = 1", "+ if A[i + k][j + l] != B[k][l]:", "+ ind = 1", "- if flag == 1:", "+ if ind == 1:", "- if flag == 0:", "- break", "- if flag == 0:", "+ if ind == 0:", "+ flag = 1", "+ if flag == 1:", "-if flag == 0:", "+if flag == 1:" ]
false
0.061867
0.036017
1.717724
[ "s896795551", "s117421387" ]
u627803856
p03456
python
s348541779
s466509667
188
169
38,384
38,256
Accepted
Accepted
10.11
a,b=list(map(str,input().split())) c=int(a+b) sq = [i*i for i in range(1,10001)] if c in sq: print('Yes') else: print('No')
a, b = map(int, input().split()) c = int(str(a) + str(b)) square = [i ** 2 for i in range(1, 500)] print('Yes') if c in square else print('No')
5
7
121
152
a, b = list(map(str, input().split())) c = int(a + b) sq = [i * i for i in range(1, 10001)] if c in sq: print("Yes") else: print("No")
a, b = map(int, input().split()) c = int(str(a) + str(b)) square = [i**2 for i in range(1, 500)] print("Yes") if c in square else print("No")
false
28.571429
[ "-a, b = list(map(str, input().split()))", "-c = int(a + b)", "-sq = [i * i for i in range(1, 10001)]", "-if c in sq:", "- print(\"Yes\")", "-else:", "- print(\"No\")", "+a, b = map(int, input().split())", "+c = int(str(a) + str(b))", "+square = [i**2 for i in range(1, 500)]", "+print(\"Yes\") if c in square else print(\"No\")" ]
false
0.036877
0.035673
1.033759
[ "s348541779", "s466509667" ]
u285891772
p03298
python
s873330395
s152468473
1,427
711
103,440
230,612
Accepted
Accepted
50.18
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left, insort, insort_left from heapq import heappush, heappop from functools import reduce, lru_cache def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) def TUPLE(): return tuple(map(int, input().split())) def ZIP(n): return list(zip(*(MAP() for _ in range(n)))) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10 ** 9 + 7 #mod = 998244353 from decimal import * #import numpy as np #decimal.getcontext().prec = 10 def main(): N = INT() S = eval(input()) former = S[:N] latter = S[N:][::-1] dic_f = defaultdict(int) dic_l = defaultdict(int) for x in product([0, 1], repeat=N): tmp_red = "" tmp_blue = "" for i in range(N): if x[i]: tmp_red += former[i] else: tmp_blue += former[i] dic_f["{},{}".format(tmp_red, tmp_blue)] += 1 for x in product([0, 1], repeat=N): tmp_red = "" tmp_blue = "" for i in range(N): if x[i]: tmp_red += latter[i] else: tmp_blue += latter[i] dic_l["{},{}".format(tmp_red, tmp_blue)] += 1 ans = 0 for key in dic_f: ans += dic_f[key] * dic_l[key] print(ans) if __name__ == '__main__': main()
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left, insort, insort_left from heapq import heappush, heappop from functools import reduce, lru_cache def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) def TUPLE(): return tuple(map(int, input().split())) def ZIP(n): return list(zip(*(MAP() for _ in range(n)))) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10 ** 9 + 7 #mod = 998244353 from decimal import * #import numpy as np #decimal.getcontext().prec = 10 N = INT() S = eval(input()) former = S[:N] latter = S[N:][::-1] dic_f = defaultdict(int) dic_l = defaultdict(int) for x in product([0, 1], repeat=N): tmp_red = "" tmp_blue = "" for i in range(N): if x[i]: tmp_red += former[i] else: tmp_blue += former[i] dic_f["{},{}".format(tmp_red, tmp_blue)] += 1 for x in product([0, 1], repeat=N): tmp_red = "" tmp_blue = "" for i in range(N): if x[i]: tmp_red += latter[i] else: tmp_blue += latter[i] dic_l["{},{}".format(tmp_red, tmp_blue)] += 1 ans = 0 for key in dic_f: ans += dic_f[key] * dic_l[key] print(ans)
65
62
1,713
1,636
import sys, re from collections import deque, defaultdict, Counter from math import ( ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd, ) from itertools import ( accumulate, permutations, combinations, combinations_with_replacement, product, groupby, ) from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left, insort, insort_left from heapq import heappush, heappop from functools import reduce, lru_cache def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) def TUPLE(): return tuple(map(int, input().split())) def ZIP(n): return list(zip(*(MAP() for _ in range(n)))) sys.setrecursionlimit(10**9) INF = float("inf") mod = 10**9 + 7 # mod = 998244353 from decimal import * # import numpy as np # decimal.getcontext().prec = 10 def main(): N = INT() S = eval(input()) former = S[:N] latter = S[N:][::-1] dic_f = defaultdict(int) dic_l = defaultdict(int) for x in product([0, 1], repeat=N): tmp_red = "" tmp_blue = "" for i in range(N): if x[i]: tmp_red += former[i] else: tmp_blue += former[i] dic_f["{},{}".format(tmp_red, tmp_blue)] += 1 for x in product([0, 1], repeat=N): tmp_red = "" tmp_blue = "" for i in range(N): if x[i]: tmp_red += latter[i] else: tmp_blue += latter[i] dic_l["{},{}".format(tmp_red, tmp_blue)] += 1 ans = 0 for key in dic_f: ans += dic_f[key] * dic_l[key] print(ans) if __name__ == "__main__": main()
import sys, re from collections import deque, defaultdict, Counter from math import ( ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd, ) from itertools import ( accumulate, permutations, combinations, combinations_with_replacement, product, groupby, ) from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left, insort, insort_left from heapq import heappush, heappop from functools import reduce, lru_cache def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) def TUPLE(): return tuple(map(int, input().split())) def ZIP(n): return list(zip(*(MAP() for _ in range(n)))) sys.setrecursionlimit(10**9) INF = float("inf") mod = 10**9 + 7 # mod = 998244353 from decimal import * # import numpy as np # decimal.getcontext().prec = 10 N = INT() S = eval(input()) former = S[:N] latter = S[N:][::-1] dic_f = defaultdict(int) dic_l = defaultdict(int) for x in product([0, 1], repeat=N): tmp_red = "" tmp_blue = "" for i in range(N): if x[i]: tmp_red += former[i] else: tmp_blue += former[i] dic_f["{},{}".format(tmp_red, tmp_blue)] += 1 for x in product([0, 1], repeat=N): tmp_red = "" tmp_blue = "" for i in range(N): if x[i]: tmp_red += latter[i] else: tmp_blue += latter[i] dic_l["{},{}".format(tmp_red, tmp_blue)] += 1 ans = 0 for key in dic_f: ans += dic_f[key] * dic_l[key] print(ans)
false
4.615385
[ "-def main():", "- N = INT()", "- S = eval(input())", "- former = S[:N]", "- latter = S[N:][::-1]", "- dic_f = defaultdict(int)", "- dic_l = defaultdict(int)", "- for x in product([0, 1], repeat=N):", "- tmp_red = \"\"", "- tmp_blue = \"\"", "- for i in range(N):", "- if x[i]:", "- tmp_red += former[i]", "- else:", "- tmp_blue += former[i]", "- dic_f[\"{},{}\".format(tmp_red, tmp_blue)] += 1", "- for x in product([0, 1], repeat=N):", "- tmp_red = \"\"", "- tmp_blue = \"\"", "- for i in range(N):", "- if x[i]:", "- tmp_red += latter[i]", "- else:", "- tmp_blue += latter[i]", "- dic_l[\"{},{}\".format(tmp_red, tmp_blue)] += 1", "- ans = 0", "- for key in dic_f:", "- ans += dic_f[key] * dic_l[key]", "- print(ans)", "-", "-", "-if __name__ == \"__main__\":", "- main()", "+N = INT()", "+S = eval(input())", "+former = S[:N]", "+latter = S[N:][::-1]", "+dic_f = defaultdict(int)", "+dic_l = defaultdict(int)", "+for x in product([0, 1], repeat=N):", "+ tmp_red = \"\"", "+ tmp_blue = \"\"", "+ for i in range(N):", "+ if x[i]:", "+ tmp_red += former[i]", "+ else:", "+ tmp_blue += former[i]", "+ dic_f[\"{},{}\".format(tmp_red, tmp_blue)] += 1", "+for x in product([0, 1], repeat=N):", "+ tmp_red = \"\"", "+ tmp_blue = \"\"", "+ for i in range(N):", "+ if x[i]:", "+ tmp_red += latter[i]", "+ else:", "+ tmp_blue += latter[i]", "+ dic_l[\"{},{}\".format(tmp_red, tmp_blue)] += 1", "+ans = 0", "+for key in dic_f:", "+ ans += dic_f[key] * dic_l[key]", "+print(ans)" ]
false
0.034064
0.036678
0.928731
[ "s873330395", "s152468473" ]
u821989875
p02576
python
s471271258
s907824221
32
29
9,152
9,072
Accepted
Accepted
9.38
n, x, t = list(map(int, input().split())) if n % x == 0: print(((n//x)*t)) else: print((((n//x)+1)*t))
import math N, X, T = list(map(int, input().split())) print((math.ceil(N/ X)* T))
5
3
100
75
n, x, t = list(map(int, input().split())) if n % x == 0: print(((n // x) * t)) else: print((((n // x) + 1) * t))
import math N, X, T = list(map(int, input().split())) print((math.ceil(N / X) * T))
false
40
[ "-n, x, t = list(map(int, input().split()))", "-if n % x == 0:", "- print(((n // x) * t))", "-else:", "- print((((n // x) + 1) * t))", "+import math", "+", "+N, X, T = list(map(int, input().split()))", "+print((math.ceil(N / X) * T))" ]
false
0.139144
0.096899
1.435966
[ "s471271258", "s907824221" ]
u021019433
p02900
python
s852242565
s845003250
364
310
5,048
5,048
Accepted
Accepted
14.84
from fractions import gcd d = gcd(*list(map(int, input().split()))) r = 1 i = 2 while i * i <= d: c = 0 while d % i == 0: c += 1 d //= i r += c > 0 i += 1 print((r + (d > 1)))
from fractions import gcd d = gcd(*list(map(int, input().split()))) r = 1 i = 2 while i * i <= d: c = 0 while d % i == 0: c += 1 d //= i if c: r += 1 i += 1 print((r + (d > 1)))
13
13
213
215
from fractions import gcd d = gcd(*list(map(int, input().split()))) r = 1 i = 2 while i * i <= d: c = 0 while d % i == 0: c += 1 d //= i r += c > 0 i += 1 print((r + (d > 1)))
from fractions import gcd d = gcd(*list(map(int, input().split()))) r = 1 i = 2 while i * i <= d: c = 0 while d % i == 0: c += 1 d //= i if c: r += 1 i += 1 print((r + (d > 1)))
false
0
[ "- r += c > 0", "+ if c:", "+ r += 1" ]
false
0.071105
0.053242
1.335493
[ "s852242565", "s845003250" ]
u088552457
p02614
python
s289285671
s252575526
352
109
69,752
78,292
Accepted
Accepted
69.03
# import sys # input = sys.stdin.readline # import re import math import itertools def main(): h, w, k = input_list() maze = [] for H in range(h): maze.append(list(eval(input()))) ans = [] a = 0 all = 0 for l in maze: a += l.count('#') all += l.count('#') ans.append(a) hash_list_H = [] kumi = 0 for H in range(h): if maze[H].count('#') == k: kumi += 1 # hash_list_H.append(maze[H].count('#')) hash_list_W = [] for W in range(w): a = 0 for H in range(h): if maze[H][W] == '#': a += 1 if a == k: kumi += 1 hash_list_W.append(a) # kumi = hash_list_W.count(k) + hash_list_H.count(k) # if all == k: # kumi += 1 # for H in range(1, h+1): # for c in itertools.combinations(hash_list_H, H): # if all - sum(list(c)) == k: # kumi += 1 # for W in range(1, w+1): # for c in itertools.combinations(hash_list_W, W): # if all - sum(list(c)) == k: # kumi += 1 # print(kumi) ss = 0 # for H in range(1, h+1): # for W in range(1, w+1): # for hc in itertools.combinations(hash_list_H, H): # for wc in itertools.combinations(hash_list_W, W): # if all - (sum(hc) + sum(wc)) == k: # ss += 1 # print(kumi+ss) r = 0 done = [] for H in range(h+1): for W in range(w+1): for hc in itertools.combinations(list(range(h)), H): for wc in itertools.combinations(list(range(w)), W): if (hc, wc) in done: continue done.append((hc, wc)) if count(maze, hc, wc) == k: r += 1 print(r) def combinations_count(n, r): return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) def count(mazes, hc, wc): hc = list(hc) wc = list(wc) r = 0 for hi, row in enumerate(mazes): if hi in hc: continue for wi, m in enumerate(row): if wi in wc: continue if m == '#': r += 1 return r def input_list(): return list(map(int, input().split())) def input_list_str(): return list(map(str, input().split())) if __name__ == '__main__': main()
# import sys # input = sys.stdin.readline import itertools import collections from decimal import Decimal from functools import reduce # 持っているビスケットを叩き、1枚増やす # ビスケット A枚を 1円に交換する # 1円をビスケット B枚に交換する def main(): H, W, k = input_list() maze = [list(eval(input())) for _ in range(H)] ans = 0 for row_bit in itertools.product(list(range(2)), repeat=H): for col_bit in itertools.product(list(range(2)), repeat=W): cnt = 0 for row in range(H): for col in range(W): if maze[row][col] == "#" and (row_bit[row] and col_bit[col]): cnt += 1 if cnt == k: ans += 1 print(ans) def prime_factorize(n): a = [] while n % 2 == 0: a.append(2) n //= 2 f = 3 while f * f <= n: if n % f == 0: a.append(f) n //= f else: f += 2 if n != 1: a.append(n) return a def bfs(H, W, black_cells, dist): d = 0 while black_cells: h, w = black_cells.popleft() d = dist[h][w] for dy, dx in ((1, 0), (0, 1), (-1, 0), (0, -1)): new_h = h + dy new_w = w + dx if new_h < 0 or H <= new_h or new_w < 0 or W <= new_w: continue if dist[new_h][new_w] == -1: dist[new_h][new_w] = d + 1 black_cells.append((new_h, new_w)) return d def input_list(): return list(map(int, input().split())) def input_list_str(): return list(map(str, input().split())) if __name__ == "__main__": main()
94
70
2,528
1,679
# import sys # input = sys.stdin.readline # import re import math import itertools def main(): h, w, k = input_list() maze = [] for H in range(h): maze.append(list(eval(input()))) ans = [] a = 0 all = 0 for l in maze: a += l.count("#") all += l.count("#") ans.append(a) hash_list_H = [] kumi = 0 for H in range(h): if maze[H].count("#") == k: kumi += 1 # hash_list_H.append(maze[H].count('#')) hash_list_W = [] for W in range(w): a = 0 for H in range(h): if maze[H][W] == "#": a += 1 if a == k: kumi += 1 hash_list_W.append(a) # kumi = hash_list_W.count(k) + hash_list_H.count(k) # if all == k: # kumi += 1 # for H in range(1, h+1): # for c in itertools.combinations(hash_list_H, H): # if all - sum(list(c)) == k: # kumi += 1 # for W in range(1, w+1): # for c in itertools.combinations(hash_list_W, W): # if all - sum(list(c)) == k: # kumi += 1 # print(kumi) ss = 0 # for H in range(1, h+1): # for W in range(1, w+1): # for hc in itertools.combinations(hash_list_H, H): # for wc in itertools.combinations(hash_list_W, W): # if all - (sum(hc) + sum(wc)) == k: # ss += 1 # print(kumi+ss) r = 0 done = [] for H in range(h + 1): for W in range(w + 1): for hc in itertools.combinations(list(range(h)), H): for wc in itertools.combinations(list(range(w)), W): if (hc, wc) in done: continue done.append((hc, wc)) if count(maze, hc, wc) == k: r += 1 print(r) def combinations_count(n, r): return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) def count(mazes, hc, wc): hc = list(hc) wc = list(wc) r = 0 for hi, row in enumerate(mazes): if hi in hc: continue for wi, m in enumerate(row): if wi in wc: continue if m == "#": r += 1 return r def input_list(): return list(map(int, input().split())) def input_list_str(): return list(map(str, input().split())) if __name__ == "__main__": main()
# import sys # input = sys.stdin.readline import itertools import collections from decimal import Decimal from functools import reduce # 持っているビスケットを叩き、1枚増やす # ビスケット A枚を 1円に交換する # 1円をビスケット B枚に交換する def main(): H, W, k = input_list() maze = [list(eval(input())) for _ in range(H)] ans = 0 for row_bit in itertools.product(list(range(2)), repeat=H): for col_bit in itertools.product(list(range(2)), repeat=W): cnt = 0 for row in range(H): for col in range(W): if maze[row][col] == "#" and (row_bit[row] and col_bit[col]): cnt += 1 if cnt == k: ans += 1 print(ans) def prime_factorize(n): a = [] while n % 2 == 0: a.append(2) n //= 2 f = 3 while f * f <= n: if n % f == 0: a.append(f) n //= f else: f += 2 if n != 1: a.append(n) return a def bfs(H, W, black_cells, dist): d = 0 while black_cells: h, w = black_cells.popleft() d = dist[h][w] for dy, dx in ((1, 0), (0, 1), (-1, 0), (0, -1)): new_h = h + dy new_w = w + dx if new_h < 0 or H <= new_h or new_w < 0 or W <= new_w: continue if dist[new_h][new_w] == -1: dist[new_h][new_w] = d + 1 black_cells.append((new_h, new_w)) return d def input_list(): return list(map(int, input().split())) def input_list_str(): return list(map(str, input().split())) if __name__ == "__main__": main()
false
25.531915
[ "-# import re", "-import math", "+import collections", "+from decimal import Decimal", "+from functools import reduce", "+", "+# 持っているビスケットを叩き、1枚増やす", "+# ビスケット A枚を 1円に交換する", "+# 1円をビスケット B枚に交換する", "+def main():", "+ H, W, k = input_list()", "+ maze = [list(eval(input())) for _ in range(H)]", "+ ans = 0", "+ for row_bit in itertools.product(list(range(2)), repeat=H):", "+ for col_bit in itertools.product(list(range(2)), repeat=W):", "+ cnt = 0", "+ for row in range(H):", "+ for col in range(W):", "+ if maze[row][col] == \"#\" and (row_bit[row] and col_bit[col]):", "+ cnt += 1", "+ if cnt == k:", "+ ans += 1", "+ print(ans)", "-def main():", "- h, w, k = input_list()", "- maze = []", "- for H in range(h):", "- maze.append(list(eval(input())))", "- ans = []", "- a = 0", "- all = 0", "- for l in maze:", "- a += l.count(\"#\")", "- all += l.count(\"#\")", "- ans.append(a)", "- hash_list_H = []", "- kumi = 0", "- for H in range(h):", "- if maze[H].count(\"#\") == k:", "- kumi += 1", "- # hash_list_H.append(maze[H].count('#'))", "- hash_list_W = []", "- for W in range(w):", "- a = 0", "- for H in range(h):", "- if maze[H][W] == \"#\":", "- a += 1", "- if a == k:", "- kumi += 1", "- hash_list_W.append(a)", "- # kumi = hash_list_W.count(k) + hash_list_H.count(k)", "- # if all == k:", "- # kumi += 1", "- # for H in range(1, h+1):", "- # for c in itertools.combinations(hash_list_H, H):", "- # if all - sum(list(c)) == k:", "- # kumi += 1", "- # for W in range(1, w+1):", "- # for c in itertools.combinations(hash_list_W, W):", "- # if all - sum(list(c)) == k:", "- # kumi += 1", "- # print(kumi)", "- ss = 0", "- # for H in range(1, h+1):", "- # for W in range(1, w+1):", "- # for hc in itertools.combinations(hash_list_H, H):", "- # for wc in itertools.combinations(hash_list_W, W):", "- # if all - (sum(hc) + sum(wc)) == k:", "- # ss += 1", "- # print(kumi+ss)", "- r = 0", "- done = []", "- for H in range(h + 1):", "- for W in range(w + 1):", "- for hc in itertools.combinations(list(range(h)), H):", "- for wc in itertools.combinations(list(range(w)), W):", "- if (hc, wc) in done:", "- continue", "- done.append((hc, wc))", "- if count(maze, hc, wc) == k:", "- r += 1", "- print(r)", "+def prime_factorize(n):", "+ a = []", "+ while n % 2 == 0:", "+ a.append(2)", "+ n //= 2", "+ f = 3", "+ while f * f <= n:", "+ if n % f == 0:", "+ a.append(f)", "+ n //= f", "+ else:", "+ f += 2", "+ if n != 1:", "+ a.append(n)", "+ return a", "-def combinations_count(n, r):", "- return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))", "-", "-", "-def count(mazes, hc, wc):", "- hc = list(hc)", "- wc = list(wc)", "- r = 0", "- for hi, row in enumerate(mazes):", "- if hi in hc:", "- continue", "- for wi, m in enumerate(row):", "- if wi in wc:", "+def bfs(H, W, black_cells, dist):", "+ d = 0", "+ while black_cells:", "+ h, w = black_cells.popleft()", "+ d = dist[h][w]", "+ for dy, dx in ((1, 0), (0, 1), (-1, 0), (0, -1)):", "+ new_h = h + dy", "+ new_w = w + dx", "+ if new_h < 0 or H <= new_h or new_w < 0 or W <= new_w:", "- if m == \"#\":", "- r += 1", "- return r", "+ if dist[new_h][new_w] == -1:", "+ dist[new_h][new_w] = d + 1", "+ black_cells.append((new_h, new_w))", "+ return d" ]
false
0.04723
0.046101
1.024488
[ "s289285671", "s252575526" ]
u588341295
p03112
python
s814277990
s995639538
1,265
1,029
30,120
14,504
Accepted
Accepted
18.66
# -*- coding: utf-8 -*- import sys, re from collections import deque, defaultdict, Counter from math import sqrt, hypot, factorial, pi, sin, cos, radians, log10 if sys.version_info.minor >= 5: from math import gcd else: from fractions import gcd from heapq import heappop, heappush, heapify, heappushpop from bisect import bisect_left, bisect_right from itertools import permutations, combinations, product, accumulate from operator import itemgetter, mul, xor from copy import copy, deepcopy from functools import reduce, partial from fractions import Fraction from string import ascii_lowercase, ascii_uppercase, digits from datetime import date 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 ceil(x, y=1): return int(-(-x // y)) def round(x): return int((x*2+1) // 2) def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD def lcm(x, y): return (x * y) // gcd(x, y) def lcm_list(nums): return reduce(lcm, nums, 1) def gcd_list(nums): return reduce(gcd, nums, nums[0]) def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) 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 A,B,Q=MAP() S=[-INF]*(A+2) for i in range(A): S[i+1]=INT() T=[-INF]*(B+2) for i in range(B): T[i+1]=INT() S[-1]=T[-1]=INF # Si番目の神社から左に一番近い寺 L1=[INF]*(A+2) # Si番目の神社から右に一番近い寺 R1=[INF]*(A+2) for i in range(1, A+1): idx=bisect_right(T, S[i])-1 if T[idx]!=0: L1[i]=S[i]-T[idx] idx=bisect_left(T, S[i]) if T[idx]!=INF: R1[i]=T[idx]-S[i] # Ti番目の寺から左に一番近い神社 L2=[INF]*(B+2) # Ti番目の寺から右に一番近い神社 R2=[INF]*(B+2) for i in range(1, B+1): idx=bisect_right(S, T[i])-1 if S[idx]!=0: L2[i]=T[i]-S[idx] idx=bisect_left(S, T[i]) if S[idx]!=INF: R2[i]=S[idx]-T[i] for i in range(Q): dist1=dist2=dist3=dist4=INF x=INT() # 地点xから左に一番近い神社 idx=bisect_right(S, x)-1 # idx番目の神社に行く dist1=x-S[idx] # idx番目の神社から一番近い寺に行く dist1+=min(L1[idx], R1[idx]) idx=bisect_left(S, x) dist2=S[idx]-x dist2+=min(L1[idx], R1[idx]) idx=bisect_right(T, x)-1 dist3=x-T[idx] dist3+=min(L2[idx], R2[idx]) idx=bisect_left(T, x) dist4=T[idx]-x dist4+=min(L2[idx], R2[idx]) print((min(dist1, dist2, dist3, dist4)))
# -*- coding: utf-8 -*- """ 参考:https://img.atcoder.jp/abc119/editorial.pdf """ import sys, re from collections import deque, defaultdict, Counter from math import sqrt, hypot, factorial, pi, sin, cos, radians, log10 if sys.version_info.minor >= 5: from math import gcd else: from fractions import gcd from heapq import heappop, heappush, heapify, heappushpop from bisect import bisect_left, bisect_right from itertools import permutations, combinations, product, accumulate from operator import itemgetter, mul, xor from copy import copy, deepcopy from functools import reduce, partial from fractions import Fraction from string import ascii_lowercase, ascii_uppercase, digits from datetime import date 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 ceil(x, y=1): return int(-(-x // y)) def round(x): return int((x*2+1) // 2) def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD def lcm(x, y): return (x * y) // gcd(x, y) def lcm_list(nums): return reduce(lcm, nums, 1) def gcd_list(nums): return reduce(gcd, nums, nums[0]) def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) def Yes(): print('Yes') def No(): print('No') def YES(): print('YES') def NO(): print('NO') sys.setrecursionlimit(10 ** 9) INF = 10 ** 18 MOD = 10 ** 9 + 7 A,B,Q=MAP() S=[-INF]*(A+2) for i in range(A): S[i+1]=INT() T=[-INF]*(B+2) for i in range(B): T[i+1]=INT() S[-1]=T[-1]=INF for i in range(Q): dist1=dist2=dist3=dist4=INF x=INT() # 地点xから左に一番近い神社 idx1=bisect_right(S, x)-1 # 右に一番近い神社 idx2=bisect_left(S, x) idx3=bisect_right(T, x)-1 idx4=bisect_left(T, x) # idx番目の神社に行く dist1=x-S[idx1] # idx番目の神社から一番近い寺に行く dist1+=min(abs(S[idx1]-T[idx3]), abs(S[idx1]-T[idx4])) dist2=S[idx2]-x dist2+=min(abs(S[idx2]-T[idx3]), abs(S[idx2]-T[idx4])) dist3=x-T[idx3] dist3+=min(abs(T[idx3]-S[idx1]), abs(T[idx3]-S[idx2])) dist4=T[idx4]-x dist4+=min(abs(T[idx4]-S[idx1]), abs(T[idx4]-S[idx2])) print((min(dist1, dist2, dist3, dist4)))
90
71
2,602
2,274
# -*- coding: utf-8 -*- import sys, re from collections import deque, defaultdict, Counter from math import sqrt, hypot, factorial, pi, sin, cos, radians, log10 if sys.version_info.minor >= 5: from math import gcd else: from fractions import gcd from heapq import heappop, heappush, heapify, heappushpop from bisect import bisect_left, bisect_right from itertools import permutations, combinations, product, accumulate from operator import itemgetter, mul, xor from copy import copy, deepcopy from functools import reduce, partial from fractions import Fraction from string import ascii_lowercase, ascii_uppercase, digits from datetime import date 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 ceil(x, y=1): return int(-(-x // y)) def round(x): return int((x * 2 + 1) // 2) def fermat(x, y, MOD): return x * pow(y, MOD - 2, MOD) % MOD def lcm(x, y): return (x * y) // gcd(x, y) def lcm_list(nums): return reduce(lcm, nums, 1) def gcd_list(nums): return reduce(gcd, nums, nums[0]) def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) 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 A, B, Q = MAP() S = [-INF] * (A + 2) for i in range(A): S[i + 1] = INT() T = [-INF] * (B + 2) for i in range(B): T[i + 1] = INT() S[-1] = T[-1] = INF # Si番目の神社から左に一番近い寺 L1 = [INF] * (A + 2) # Si番目の神社から右に一番近い寺 R1 = [INF] * (A + 2) for i in range(1, A + 1): idx = bisect_right(T, S[i]) - 1 if T[idx] != 0: L1[i] = S[i] - T[idx] idx = bisect_left(T, S[i]) if T[idx] != INF: R1[i] = T[idx] - S[i] # Ti番目の寺から左に一番近い神社 L2 = [INF] * (B + 2) # Ti番目の寺から右に一番近い神社 R2 = [INF] * (B + 2) for i in range(1, B + 1): idx = bisect_right(S, T[i]) - 1 if S[idx] != 0: L2[i] = T[i] - S[idx] idx = bisect_left(S, T[i]) if S[idx] != INF: R2[i] = S[idx] - T[i] for i in range(Q): dist1 = dist2 = dist3 = dist4 = INF x = INT() # 地点xから左に一番近い神社 idx = bisect_right(S, x) - 1 # idx番目の神社に行く dist1 = x - S[idx] # idx番目の神社から一番近い寺に行く dist1 += min(L1[idx], R1[idx]) idx = bisect_left(S, x) dist2 = S[idx] - x dist2 += min(L1[idx], R1[idx]) idx = bisect_right(T, x) - 1 dist3 = x - T[idx] dist3 += min(L2[idx], R2[idx]) idx = bisect_left(T, x) dist4 = T[idx] - x dist4 += min(L2[idx], R2[idx]) print((min(dist1, dist2, dist3, dist4)))
# -*- coding: utf-8 -*- """ 参考:https://img.atcoder.jp/abc119/editorial.pdf """ import sys, re from collections import deque, defaultdict, Counter from math import sqrt, hypot, factorial, pi, sin, cos, radians, log10 if sys.version_info.minor >= 5: from math import gcd else: from fractions import gcd from heapq import heappop, heappush, heapify, heappushpop from bisect import bisect_left, bisect_right from itertools import permutations, combinations, product, accumulate from operator import itemgetter, mul, xor from copy import copy, deepcopy from functools import reduce, partial from fractions import Fraction from string import ascii_lowercase, ascii_uppercase, digits from datetime import date 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 ceil(x, y=1): return int(-(-x // y)) def round(x): return int((x * 2 + 1) // 2) def fermat(x, y, MOD): return x * pow(y, MOD - 2, MOD) % MOD def lcm(x, y): return (x * y) // gcd(x, y) def lcm_list(nums): return reduce(lcm, nums, 1) def gcd_list(nums): return reduce(gcd, nums, nums[0]) def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) def Yes(): print("Yes") def No(): print("No") def YES(): print("YES") def NO(): print("NO") sys.setrecursionlimit(10**9) INF = 10**18 MOD = 10**9 + 7 A, B, Q = MAP() S = [-INF] * (A + 2) for i in range(A): S[i + 1] = INT() T = [-INF] * (B + 2) for i in range(B): T[i + 1] = INT() S[-1] = T[-1] = INF for i in range(Q): dist1 = dist2 = dist3 = dist4 = INF x = INT() # 地点xから左に一番近い神社 idx1 = bisect_right(S, x) - 1 # 右に一番近い神社 idx2 = bisect_left(S, x) idx3 = bisect_right(T, x) - 1 idx4 = bisect_left(T, x) # idx番目の神社に行く dist1 = x - S[idx1] # idx番目の神社から一番近い寺に行く dist1 += min(abs(S[idx1] - T[idx3]), abs(S[idx1] - T[idx4])) dist2 = S[idx2] - x dist2 += min(abs(S[idx2] - T[idx3]), abs(S[idx2] - T[idx4])) dist3 = x - T[idx3] dist3 += min(abs(T[idx3] - S[idx1]), abs(T[idx3] - S[idx2])) dist4 = T[idx4] - x dist4 += min(abs(T[idx4] - S[idx1]), abs(T[idx4] - S[idx2])) print((min(dist1, dist2, dist3, dist4)))
false
21.111111
[ "+\"\"\"", "+参考:https://img.atcoder.jp/abc119/editorial.pdf", "+\"\"\"", "-INF = float(\"inf\")", "+INF = 10**18", "-# Si番目の神社から左に一番近い寺", "-L1 = [INF] * (A + 2)", "-# Si番目の神社から右に一番近い寺", "-R1 = [INF] * (A + 2)", "-for i in range(1, A + 1):", "- idx = bisect_right(T, S[i]) - 1", "- if T[idx] != 0:", "- L1[i] = S[i] - T[idx]", "- idx = bisect_left(T, S[i])", "- if T[idx] != INF:", "- R1[i] = T[idx] - S[i]", "-# Ti番目の寺から左に一番近い神社", "-L2 = [INF] * (B + 2)", "-# Ti番目の寺から右に一番近い神社", "-R2 = [INF] * (B + 2)", "-for i in range(1, B + 1):", "- idx = bisect_right(S, T[i]) - 1", "- if S[idx] != 0:", "- L2[i] = T[i] - S[idx]", "- idx = bisect_left(S, T[i])", "- if S[idx] != INF:", "- R2[i] = S[idx] - T[i]", "- idx = bisect_right(S, x) - 1", "+ idx1 = bisect_right(S, x) - 1", "+ # 右に一番近い神社", "+ idx2 = bisect_left(S, x)", "+ idx3 = bisect_right(T, x) - 1", "+ idx4 = bisect_left(T, x)", "- dist1 = x - S[idx]", "+ dist1 = x - S[idx1]", "- dist1 += min(L1[idx], R1[idx])", "- idx = bisect_left(S, x)", "- dist2 = S[idx] - x", "- dist2 += min(L1[idx], R1[idx])", "- idx = bisect_right(T, x) - 1", "- dist3 = x - T[idx]", "- dist3 += min(L2[idx], R2[idx])", "- idx = bisect_left(T, x)", "- dist4 = T[idx] - x", "- dist4 += min(L2[idx], R2[idx])", "+ dist1 += min(abs(S[idx1] - T[idx3]), abs(S[idx1] - T[idx4]))", "+ dist2 = S[idx2] - x", "+ dist2 += min(abs(S[idx2] - T[idx3]), abs(S[idx2] - T[idx4]))", "+ dist3 = x - T[idx3]", "+ dist3 += min(abs(T[idx3] - S[idx1]), abs(T[idx3] - S[idx2]))", "+ dist4 = T[idx4] - x", "+ dist4 += min(abs(T[idx4] - S[idx1]), abs(T[idx4] - S[idx2]))" ]
false
0.037125
0.037142
0.999548
[ "s814277990", "s995639538" ]
u150984829
p02419
python
s945595291
s524502012
30
20
5,564
5,540
Accepted
Accepted
33.33
W=eval(input()) T=[] while 1: a=eval(input()) if'END_OF_TEXT'==a:break T+=[s.lower() for s in a.split()] print((T.count(W)))
import sys W=eval(input()) print((sys.stdin.read().lower().split().count(W)))
7
3
119
71
W = eval(input()) T = [] while 1: a = eval(input()) if "END_OF_TEXT" == a: break T += [s.lower() for s in a.split()] print((T.count(W)))
import sys W = eval(input()) print((sys.stdin.read().lower().split().count(W)))
false
57.142857
[ "+import sys", "+", "-T = []", "-while 1:", "- a = eval(input())", "- if \"END_OF_TEXT\" == a:", "- break", "- T += [s.lower() for s in a.split()]", "-print((T.count(W)))", "+print((sys.stdin.read().lower().split().count(W)))" ]
false
0.043013
0.042703
1.007257
[ "s945595291", "s524502012" ]
u597374218
p03126
python
s946789304
s353613147
30
25
9,108
9,152
Accepted
Accepted
16.67
N,M=list(map(int,input().split())) food=set(range(1,M+1)) for i in range(N): K,*A=list(map(int,input().split())) food&=set(A) print((len(food)))
N,M=list(map(int,input().split())) food=set(range(1,M+1)) for i in range(N): A=list(map(int,input().split()[1:])) food&=set(A) print((len(food)))
6
6
143
144
N, M = list(map(int, input().split())) food = set(range(1, M + 1)) for i in range(N): K, *A = list(map(int, input().split())) food &= set(A) print((len(food)))
N, M = list(map(int, input().split())) food = set(range(1, M + 1)) for i in range(N): A = list(map(int, input().split()[1:])) food &= set(A) print((len(food)))
false
0
[ "- K, *A = list(map(int, input().split()))", "+ A = list(map(int, input().split()[1:]))" ]
false
0.049808
0.049129
1.013823
[ "s946789304", "s353613147" ]
u670180528
p04046
python
s488284755
s916785866
203
138
14,836
14,836
Accepted
Accepted
32.02
h,w,a,b = list(map(int, input().split())) mx = max(h,w) mod = 10**9+7 fac = [1]*(h+w+1) for i in range(1,h+w+1): fac[i]=fac[i-1]*i%mod rev = [1]*(mx+1) rev[-1] = pow(fac[mx], mod-2, mod) for i in range(mx-1, -1, -1): rev[i] = rev[i+1]*(i+1)%mod const = rev[h-a-1]*rev[a-1]%mod ans = 0 for i in range(b,w): ans += fac[h-a+i-1]*rev[i]*fac[a+w-2-i]*rev[w-i-1]%mod print((ans*const%mod))
def solve(): h,w,a,b = list(map(int, input().split())) mx = max(h,w) mod = 10**9+7 fac = [1]*(h+w+1) for i in range(1,h+w+1): fac[i]=fac[i-1]*i%mod rev = [1]*(mx+1) rev[-1] = pow(fac[mx], mod-2, mod) for i in range(mx-1, -1, -1): rev[i] = rev[i+1]*(i+1)%mod const = rev[h-a-1]*rev[a-1]%mod ans = sum(fac[h-a+i-1]*rev[i]*fac[a+w-2-i]*rev[w-i-1]%mod for i in range(b,w)) print((ans*const%mod)) if __name__=="__main__":solve()
15
16
392
446
h, w, a, b = list(map(int, input().split())) mx = max(h, w) mod = 10**9 + 7 fac = [1] * (h + w + 1) for i in range(1, h + w + 1): fac[i] = fac[i - 1] * i % mod rev = [1] * (mx + 1) rev[-1] = pow(fac[mx], mod - 2, mod) for i in range(mx - 1, -1, -1): rev[i] = rev[i + 1] * (i + 1) % mod const = rev[h - a - 1] * rev[a - 1] % mod ans = 0 for i in range(b, w): ans += fac[h - a + i - 1] * rev[i] * fac[a + w - 2 - i] * rev[w - i - 1] % mod print((ans * const % mod))
def solve(): h, w, a, b = list(map(int, input().split())) mx = max(h, w) mod = 10**9 + 7 fac = [1] * (h + w + 1) for i in range(1, h + w + 1): fac[i] = fac[i - 1] * i % mod rev = [1] * (mx + 1) rev[-1] = pow(fac[mx], mod - 2, mod) for i in range(mx - 1, -1, -1): rev[i] = rev[i + 1] * (i + 1) % mod const = rev[h - a - 1] * rev[a - 1] % mod ans = sum( fac[h - a + i - 1] * rev[i] * fac[a + w - 2 - i] * rev[w - i - 1] % mod for i in range(b, w) ) print((ans * const % mod)) if __name__ == "__main__": solve()
false
6.25
[ "-h, w, a, b = list(map(int, input().split()))", "-mx = max(h, w)", "-mod = 10**9 + 7", "-fac = [1] * (h + w + 1)", "-for i in range(1, h + w + 1):", "- fac[i] = fac[i - 1] * i % mod", "-rev = [1] * (mx + 1)", "-rev[-1] = pow(fac[mx], mod - 2, mod)", "-for i in range(mx - 1, -1, -1):", "- rev[i] = rev[i + 1] * (i + 1) % mod", "-const = rev[h - a - 1] * rev[a - 1] % mod", "-ans = 0", "-for i in range(b, w):", "- ans += fac[h - a + i - 1] * rev[i] * fac[a + w - 2 - i] * rev[w - i - 1] % mod", "-print((ans * const % mod))", "+def solve():", "+ h, w, a, b = list(map(int, input().split()))", "+ mx = max(h, w)", "+ mod = 10**9 + 7", "+ fac = [1] * (h + w + 1)", "+ for i in range(1, h + w + 1):", "+ fac[i] = fac[i - 1] * i % mod", "+ rev = [1] * (mx + 1)", "+ rev[-1] = pow(fac[mx], mod - 2, mod)", "+ for i in range(mx - 1, -1, -1):", "+ rev[i] = rev[i + 1] * (i + 1) % mod", "+ const = rev[h - a - 1] * rev[a - 1] % mod", "+ ans = sum(", "+ fac[h - a + i - 1] * rev[i] * fac[a + w - 2 - i] * rev[w - i - 1] % mod", "+ for i in range(b, w)", "+ )", "+ print((ans * const % mod))", "+", "+", "+if __name__ == \"__main__\":", "+ solve()" ]
false
0.090932
0.045645
1.992165
[ "s488284755", "s916785866" ]
u821432765
p02791
python
s647283844
s701062159
1,128
104
25,716
24,744
Accepted
Accepted
90.78
# Binary Indexed Tree (Fenwick Tree) class BIT: def __init__(self, n): self.n = n self.data = [0]*(n+1) self.el = [0]*(n+1) def sum(self, i): s = 0 while i > 0: s += self.data[i] i -= i & -i return s def add(self, i, x): # assert i > 0 self.el[i] += x while i <= self.n: self.data[i] += x i += i & -i def get(self, i, j=None): if j is None: return self.el[i] return self.sum(j) - self.sum(i) N = int(eval(input())) P = [int(i) for i in input().split()] res = 0 bit = BIT(200010) for i, p in enumerate(P): bit.add(p, 1) res += 1 if bit.sum(p) <= 1 else 0 # print(bit.sum(p)) print(res)
# # Binary Indexed Tree (Fenwick Tree) # class BIT: # def __init__(self, n): # self.n = n # self.data = [0]*(n+1) # self.el = [0]*(n+1) # def sum(self, i): # s = 0 # while i > 0: # s += self.data[i] # i -= i & -i # return s # def add(self, i, x): # # assert i > 0 # self.el[i] += x # while i <= self.n: # self.data[i] += x # i += i & -i # def get(self, i, j=None): # if j is None: # return self.el[i] # return self.sum(j) - self.sum(i) # N = int(input()) # P = [int(i) for i in input().split()] # res = 0 # bit = BIT(200010) # for i, p in enumerate(P): # bit.add(p, 1) # res += 1 if bit.sum(p) <= 1 else 0 # # print(bit.sum(p)) # print(res) INF = 10**18 N = int(eval(input())) P = [int(i) for i in input().split()] minp = INF res = 0 for p in P: if p < minp: minp = p res += 1 print(res)
34
46
791
1,027
# Binary Indexed Tree (Fenwick Tree) class BIT: def __init__(self, n): self.n = n self.data = [0] * (n + 1) self.el = [0] * (n + 1) def sum(self, i): s = 0 while i > 0: s += self.data[i] i -= i & -i return s def add(self, i, x): # assert i > 0 self.el[i] += x while i <= self.n: self.data[i] += x i += i & -i def get(self, i, j=None): if j is None: return self.el[i] return self.sum(j) - self.sum(i) N = int(eval(input())) P = [int(i) for i in input().split()] res = 0 bit = BIT(200010) for i, p in enumerate(P): bit.add(p, 1) res += 1 if bit.sum(p) <= 1 else 0 # print(bit.sum(p)) print(res)
# # Binary Indexed Tree (Fenwick Tree) # class BIT: # def __init__(self, n): # self.n = n # self.data = [0]*(n+1) # self.el = [0]*(n+1) # def sum(self, i): # s = 0 # while i > 0: # s += self.data[i] # i -= i & -i # return s # def add(self, i, x): # # assert i > 0 # self.el[i] += x # while i <= self.n: # self.data[i] += x # i += i & -i # def get(self, i, j=None): # if j is None: # return self.el[i] # return self.sum(j) - self.sum(i) # N = int(input()) # P = [int(i) for i in input().split()] # res = 0 # bit = BIT(200010) # for i, p in enumerate(P): # bit.add(p, 1) # res += 1 if bit.sum(p) <= 1 else 0 # # print(bit.sum(p)) # print(res) INF = 10**18 N = int(eval(input())) P = [int(i) for i in input().split()] minp = INF res = 0 for p in P: if p < minp: minp = p res += 1 print(res)
false
26.086957
[ "-# Binary Indexed Tree (Fenwick Tree)", "-class BIT:", "- def __init__(self, n):", "- self.n = n", "- self.data = [0] * (n + 1)", "- self.el = [0] * (n + 1)", "-", "- def sum(self, i):", "- s = 0", "- while i > 0:", "- s += self.data[i]", "- i -= i & -i", "- return s", "-", "- def add(self, i, x):", "- # assert i > 0", "- self.el[i] += x", "- while i <= self.n:", "- self.data[i] += x", "- i += i & -i", "-", "- def get(self, i, j=None):", "- if j is None:", "- return self.el[i]", "- return self.sum(j) - self.sum(i)", "-", "-", "+# # Binary Indexed Tree (Fenwick Tree)", "+# class BIT:", "+# def __init__(self, n):", "+# self.n = n", "+# self.data = [0]*(n+1)", "+# self.el = [0]*(n+1)", "+# def sum(self, i):", "+# s = 0", "+# while i > 0:", "+# s += self.data[i]", "+# i -= i & -i", "+# return s", "+# def add(self, i, x):", "+# # assert i > 0", "+# self.el[i] += x", "+# while i <= self.n:", "+# self.data[i] += x", "+# i += i & -i", "+# def get(self, i, j=None):", "+# if j is None:", "+# return self.el[i]", "+# return self.sum(j) - self.sum(i)", "+# N = int(input())", "+# P = [int(i) for i in input().split()]", "+# res = 0", "+# bit = BIT(200010)", "+# for i, p in enumerate(P):", "+# bit.add(p, 1)", "+# res += 1 if bit.sum(p) <= 1 else 0", "+# # print(bit.sum(p))", "+# print(res)", "+INF = 10**18", "+minp = INF", "-bit = BIT(200010)", "-for i, p in enumerate(P):", "- bit.add(p, 1)", "- res += 1 if bit.sum(p) <= 1 else 0", "- # print(bit.sum(p))", "+for p in P:", "+ if p < minp:", "+ minp = p", "+ res += 1" ]
false
0.06795
0.034859
1.949299
[ "s647283844", "s701062159" ]
u102461423
p02888
python
s217232802
s028825832
281
165
153,024
12,940
Accepted
Accepted
41.28
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines # 長さじゃなくて、棒自体で区別してるやんけー! import numpy as np N = int(readline()) L = np.array(read().split(),np.int32) L.sort() U=1000 counter = np.bincount(L,minlength=U+U+10) cum = counter.cumsum() add = L[:,None] + L[None,:] max_c = cum[add-1] cnt_c = max_c - np.arange(len(L)) - 1 answer = np.triu(cnt_c,1).sum() print(answer)
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import numpy as np from numpy.fft import rfft,irfft N = int(readline()) L = np.array(read().split(),np.int32) fft_len = 2048 counter = np.bincount(L,minlength=1001) add = (irfft(rfft(counter,fft_len)**2)+.5).astype(int) # 同じものを2回使うパターンを除外 add[:2002:2] -= counter add //= 2 # a+b <= c となる(a,b,c)を除外する cum = counter.cumsum() remove = ((N-cum+counter) * add[:1001]).sum() answer = N*(N-1)*(N-2)//6 - remove print(answer)
24
27
460
567
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines # 長さじゃなくて、棒自体で区別してるやんけー! import numpy as np N = int(readline()) L = np.array(read().split(), np.int32) L.sort() U = 1000 counter = np.bincount(L, minlength=U + U + 10) cum = counter.cumsum() add = L[:, None] + L[None, :] max_c = cum[add - 1] cnt_c = max_c - np.arange(len(L)) - 1 answer = np.triu(cnt_c, 1).sum() print(answer)
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import numpy as np from numpy.fft import rfft, irfft N = int(readline()) L = np.array(read().split(), np.int32) fft_len = 2048 counter = np.bincount(L, minlength=1001) add = (irfft(rfft(counter, fft_len) ** 2) + 0.5).astype(int) # 同じものを2回使うパターンを除外 add[:2002:2] -= counter add //= 2 # a+b <= c となる(a,b,c)を除外する cum = counter.cumsum() remove = ((N - cum + counter) * add[:1001]).sum() answer = N * (N - 1) * (N - 2) // 6 - remove print(answer)
false
11.111111
[ "-# 長さじゃなくて、棒自体で区別してるやんけー!", "+from numpy.fft import rfft, irfft", "-L.sort()", "-U = 1000", "-counter = np.bincount(L, minlength=U + U + 10)", "+fft_len = 2048", "+counter = np.bincount(L, minlength=1001)", "+add = (irfft(rfft(counter, fft_len) ** 2) + 0.5).astype(int)", "+# 同じものを2回使うパターンを除外", "+add[:2002:2] -= counter", "+add //= 2", "+# a+b <= c となる(a,b,c)を除外する", "-add = L[:, None] + L[None, :]", "-max_c = cum[add - 1]", "-cnt_c = max_c - np.arange(len(L)) - 1", "-answer = np.triu(cnt_c, 1).sum()", "+remove = ((N - cum + counter) * add[:1001]).sum()", "+answer = N * (N - 1) * (N - 2) // 6 - remove" ]
false
0.247387
0.317918
0.778148
[ "s217232802", "s028825832" ]
u239091426
p02712
python
s885718316
s957869804
160
121
9,140
30,024
Accepted
Accepted
24.38
n = int(eval(input())) c = 0 for i in range(1,n+1): if i%3 != 0 and i%5 != 0: c += i print(c)
n = int(eval(input())) l = [i for i in range(1,n+1) if i%3 != 0 and i%5 != 0] print((sum(l)))
6
3
98
87
n = int(eval(input())) c = 0 for i in range(1, n + 1): if i % 3 != 0 and i % 5 != 0: c += i print(c)
n = int(eval(input())) l = [i for i in range(1, n + 1) if i % 3 != 0 and i % 5 != 0] print((sum(l)))
false
50
[ "-c = 0", "-for i in range(1, n + 1):", "- if i % 3 != 0 and i % 5 != 0:", "- c += i", "-print(c)", "+l = [i for i in range(1, n + 1) if i % 3 != 0 and i % 5 != 0]", "+print((sum(l)))" ]
false
0.109938
0.124186
0.885264
[ "s885718316", "s957869804" ]
u647766105
p00133
python
s859738370
s397760862
20
10
4,300
4,300
Accepted
Accepted
50
from functools import reduce T = lambda d:["".join(d) for d in zip(*d[::-1])] D = [input() for _ in range(8)] for i in range(1,4): print(str(90*i)) print("\n".join(reduce(lambda a,b:b(a),[T]*i,D)))
from functools import reduce T = lambda d:["".join(d) for d in zip(*d[::-1])] D = [input() for _ in range(8)] for i in range(1,4): print(90*i) print("\n".join(reduce(lambda a,b:b(a),[T]*i,D)))
5
5
184
179
from functools import reduce T = lambda d: ["".join(d) for d in zip(*d[::-1])] D = [input() for _ in range(8)] for i in range(1, 4): print(str(90 * i)) print("\n".join(reduce(lambda a, b: b(a), [T] * i, D)))
from functools import reduce T = lambda d: ["".join(d) for d in zip(*d[::-1])] D = [input() for _ in range(8)] for i in range(1, 4): print(90 * i) print("\n".join(reduce(lambda a, b: b(a), [T] * i, D)))
false
0
[ "- print(str(90 * i))", "+ print(90 * i)" ]
false
0.046164
0.04596
1.004448
[ "s859738370", "s397760862" ]
u150984829
p02262
python
s106177575
s932722285
19,030
11,310
53,288
53,324
Accepted
Accepted
40.57
import sys n = int(input()) A = [int(e)for e in sys.stdin] cnt = 0 G = [int((3**i-1)/2)for i in range(14,0,-1)] G = [v for v in G if v <= n] def insertionSort(A, n, g): global cnt for i in range(g, n): v = A[i] j = i - g while j >= 0 and A[j] > v: A[j+g] = A[j] j = j - g cnt += 1 A[j+g] = v for g in G: insertionSort(A, n, g) print(len(G)) print(*G) print(cnt) print(*A,sep='\n')
import sys n = int(input()) A = [int(e)for e in sys.stdin] cnt = 0 G = [int((2.0555**i-1)/1.0555)for i in range(19,0,-1)]+[1] G = [v for v in G if v <= n] def insertionSort(A, n, g): global cnt for i in range(g, n): v = A[i] j = i - g while j >= 0 and A[j] > v: A[j+g] = A[j] j = j - g cnt += 1 A[j+g] = v for g in G: insertionSort(A, n, g) print(len(G)) print(*G) print(cnt) print(*A,sep='\n')
22
22
482
496
import sys n = int(input()) A = [int(e) for e in sys.stdin] cnt = 0 G = [int((3**i - 1) / 2) for i in range(14, 0, -1)] G = [v for v in G if v <= n] def insertionSort(A, n, g): global cnt for i in range(g, n): v = A[i] j = i - g while j >= 0 and A[j] > v: A[j + g] = A[j] j = j - g cnt += 1 A[j + g] = v for g in G: insertionSort(A, n, g) print(len(G)) print(*G) print(cnt) print(*A, sep="\n")
import sys n = int(input()) A = [int(e) for e in sys.stdin] cnt = 0 G = [int((2.0555**i - 1) / 1.0555) for i in range(19, 0, -1)] + [1] G = [v for v in G if v <= n] def insertionSort(A, n, g): global cnt for i in range(g, n): v = A[i] j = i - g while j >= 0 and A[j] > v: A[j + g] = A[j] j = j - g cnt += 1 A[j + g] = v for g in G: insertionSort(A, n, g) print(len(G)) print(*G) print(cnt) print(*A, sep="\n")
false
0
[ "-G = [int((3**i - 1) / 2) for i in range(14, 0, -1)]", "+G = [int((2.0555**i - 1) / 1.0555) for i in range(19, 0, -1)] + [1]" ]
false
0.038035
0.066333
0.573398
[ "s106177575", "s932722285" ]
u546285759
p00424
python
s079438919
s456190171
310
260
7,744
7,868
Accepted
Accepted
16.13
while True: x = int(eval(input())) if x == 0: break dcl = {} for i in range(x): inp = list(map(str, input().split())) dcl[inp[0]] = inp[1] ans = "" x = int(eval(input())) for i in range(x): y = str(input()[0]) if y in dcl: ans += dcl[y] else: ans += y print(ans)
while True: n = int(eval(input())) if n == 0: break d = {} for _ in range(n): a, b = input().split() d[a] = b m = int(eval(input())) ans = "" for _ in range(m): a = input().strip() ans += d.get(a, a) print(ans)
17
14
370
283
while True: x = int(eval(input())) if x == 0: break dcl = {} for i in range(x): inp = list(map(str, input().split())) dcl[inp[0]] = inp[1] ans = "" x = int(eval(input())) for i in range(x): y = str(input()[0]) if y in dcl: ans += dcl[y] else: ans += y print(ans)
while True: n = int(eval(input())) if n == 0: break d = {} for _ in range(n): a, b = input().split() d[a] = b m = int(eval(input())) ans = "" for _ in range(m): a = input().strip() ans += d.get(a, a) print(ans)
false
17.647059
[ "- x = int(eval(input()))", "- if x == 0:", "+ n = int(eval(input()))", "+ if n == 0:", "- dcl = {}", "- for i in range(x):", "- inp = list(map(str, input().split()))", "- dcl[inp[0]] = inp[1]", "+ d = {}", "+ for _ in range(n):", "+ a, b = input().split()", "+ d[a] = b", "+ m = int(eval(input()))", "- x = int(eval(input()))", "- for i in range(x):", "- y = str(input()[0])", "- if y in dcl:", "- ans += dcl[y]", "- else:", "- ans += y", "+ for _ in range(m):", "+ a = input().strip()", "+ ans += d.get(a, a)" ]
false
0.036776
0.035702
1.030093
[ "s079438919", "s456190171" ]
u222668979
p03209
python
s643344758
s508044155
64
31
61,872
9,156
Accepted
Accepted
51.56
n, x = list(map(int, input().split())) pate, slice = [1], [1] for _ in range(n+1): pate.append(2 * pate[-1] + 1) slice.append(2 * slice[-1] + 3) ans = 0 while n >= 0 and x > 0: if n == 0 and x > 0: ans += 1 x -= 1 elif x >= slice[n - 1] + 2: ans += pate[n - 1] + 1 x -= slice[n - 1] + 2 elif x < slice[n - 1] + 2: x -= 1 n -= 1 print(ans)
n, x = list(map(int, input().split())) pate, slice = [1], [1] for _ in range(n + 1): pate.append(2 * pate[-1] + 1) slice.append(2 * slice[-1] + 3) ans = 0 while n > 0 and x > 0: if x >= slice[n - 1] + 2: ans += pate[n - 1] + 1 x -= slice[n - 1] + 2 elif x < slice[n - 1] + 2: x -= 1 n -= 1 print((ans + (x > 0)))
19
16
417
366
n, x = list(map(int, input().split())) pate, slice = [1], [1] for _ in range(n + 1): pate.append(2 * pate[-1] + 1) slice.append(2 * slice[-1] + 3) ans = 0 while n >= 0 and x > 0: if n == 0 and x > 0: ans += 1 x -= 1 elif x >= slice[n - 1] + 2: ans += pate[n - 1] + 1 x -= slice[n - 1] + 2 elif x < slice[n - 1] + 2: x -= 1 n -= 1 print(ans)
n, x = list(map(int, input().split())) pate, slice = [1], [1] for _ in range(n + 1): pate.append(2 * pate[-1] + 1) slice.append(2 * slice[-1] + 3) ans = 0 while n > 0 and x > 0: if x >= slice[n - 1] + 2: ans += pate[n - 1] + 1 x -= slice[n - 1] + 2 elif x < slice[n - 1] + 2: x -= 1 n -= 1 print((ans + (x > 0)))
false
15.789474
[ "-while n >= 0 and x > 0:", "- if n == 0 and x > 0:", "- ans += 1", "- x -= 1", "- elif x >= slice[n - 1] + 2:", "+while n > 0 and x > 0:", "+ if x >= slice[n - 1] + 2:", "-print(ans)", "+print((ans + (x > 0)))" ]
false
0.042394
0.07862
0.53923
[ "s643344758", "s508044155" ]
u990608646
p02888
python
s920516409
s026009923
1,859
1,608
3,188
3,188
Accepted
Accepted
13.5
import itertools N = int(eval(input())) L = list(map(int,input().split())) # N = 2000 # L = list(range(N)) # # 重複を消す # L = list(set(L)) # N = len(L) # Lを小さい順にソート L = sorted(L) # j=0〜max(L)について,L[i]<jを満たす最大のi: X[j] = i X = [] for j in range(L[-1]+1): flag = False for i in range(N-1,-1,-1): if L[i] < j: X.append(i) flag = True break # 見つからなければ if not flag: X.append(None) # j=0〜max(L)について,L[i]>jを満たす最小のi: Y[j] = i Y = [] for j in range(L[-1]+1): flag = False for i in range(N): if L[i] > j: Y.append(i) flag = True break # 見つからなければ if not flag: Y.append(None) #print(L) ind1 = 0 ind2 = N-1 ans = 0 for i in range(N-2): a = L[i] for j in range(i+1,N-1): b = L[j] # print(b-a,a+b,Y[b-a],X[a+b]) # cのindexの範囲 = Y[b-a]〜X[a+b] cmin = Y[b-a] if a+b <= L[-1]: cmax = X[a+b] else: cmax = N - 1 # cminはjより大きい if cmin is not None and cmin <= j: cmin = j + 1 #print(b-a,a+b,cmin,cmax) # if a == 2 and b == 3: # print(b-a,a+b,cmin,cmax) # exit() # どちらかがNoneなら0 if cmin is not None and cmax is not None and cmin <= cmax: ans += cmax - cmin + 1 print(ans)
import itertools import bisect N = int(eval(input())) L = list(map(int,input().split())) # Lを小さい順にソート L = sorted(L) # a <= b <= cを仮定してもおk # a,bを全探索し,条件を満たすcの数をO(N)未満の方法で求めればよい ans = 0 for i in range(N-2): a = L[i] for j in range(i+1,N-1): b = L[j] # Lの中で条件b-a<cを満たす最小のc ind_cmin = j+1 # Lの中で条件L[k]<a+bを満たす最大のk = Lの中で昇順ソートを崩さずa+bを挿入できる最小のインデックス-1 # 2分法で探す ind_cmax = bisect.bisect_left(L,a+b) - 1 ans += ind_cmax - ind_cmin + 1 print(ans)
74
28
1,440
542
import itertools N = int(eval(input())) L = list(map(int, input().split())) # N = 2000 # L = list(range(N)) # # 重複を消す # L = list(set(L)) # N = len(L) # Lを小さい順にソート L = sorted(L) # j=0〜max(L)について,L[i]<jを満たす最大のi: X[j] = i X = [] for j in range(L[-1] + 1): flag = False for i in range(N - 1, -1, -1): if L[i] < j: X.append(i) flag = True break # 見つからなければ if not flag: X.append(None) # j=0〜max(L)について,L[i]>jを満たす最小のi: Y[j] = i Y = [] for j in range(L[-1] + 1): flag = False for i in range(N): if L[i] > j: Y.append(i) flag = True break # 見つからなければ if not flag: Y.append(None) # print(L) ind1 = 0 ind2 = N - 1 ans = 0 for i in range(N - 2): a = L[i] for j in range(i + 1, N - 1): b = L[j] # print(b-a,a+b,Y[b-a],X[a+b]) # cのindexの範囲 = Y[b-a]〜X[a+b] cmin = Y[b - a] if a + b <= L[-1]: cmax = X[a + b] else: cmax = N - 1 # cminはjより大きい if cmin is not None and cmin <= j: cmin = j + 1 # print(b-a,a+b,cmin,cmax) # if a == 2 and b == 3: # print(b-a,a+b,cmin,cmax) # exit() # どちらかがNoneなら0 if cmin is not None and cmax is not None and cmin <= cmax: ans += cmax - cmin + 1 print(ans)
import itertools import bisect N = int(eval(input())) L = list(map(int, input().split())) # Lを小さい順にソート L = sorted(L) # a <= b <= cを仮定してもおk # a,bを全探索し,条件を満たすcの数をO(N)未満の方法で求めればよい ans = 0 for i in range(N - 2): a = L[i] for j in range(i + 1, N - 1): b = L[j] # Lの中で条件b-a<cを満たす最小のc ind_cmin = j + 1 # Lの中で条件L[k]<a+bを満たす最大のk = Lの中で昇順ソートを崩さずa+bを挿入できる最小のインデックス-1 # 2分法で探す ind_cmax = bisect.bisect_left(L, a + b) - 1 ans += ind_cmax - ind_cmin + 1 print(ans)
false
62.162162
[ "+import bisect", "-# N = 2000", "-# L = list(range(N))", "-# # 重複を消す", "-# L = list(set(L))", "-# N = len(L)", "-# j=0〜max(L)について,L[i]<jを満たす最大のi: X[j] = i", "-X = []", "-for j in range(L[-1] + 1):", "- flag = False", "- for i in range(N - 1, -1, -1):", "- if L[i] < j:", "- X.append(i)", "- flag = True", "- break", "- # 見つからなければ", "- if not flag:", "- X.append(None)", "-# j=0〜max(L)について,L[i]>jを満たす最小のi: Y[j] = i", "-Y = []", "-for j in range(L[-1] + 1):", "- flag = False", "- for i in range(N):", "- if L[i] > j:", "- Y.append(i)", "- flag = True", "- break", "- # 見つからなければ", "- if not flag:", "- Y.append(None)", "-# print(L)", "-ind1 = 0", "-ind2 = N - 1", "+# a <= b <= cを仮定してもおk", "+# a,bを全探索し,条件を満たすcの数をO(N)未満の方法で求めればよい", "- # print(b-a,a+b,Y[b-a],X[a+b])", "- # cのindexの範囲 = Y[b-a]〜X[a+b]", "- cmin = Y[b - a]", "- if a + b <= L[-1]:", "- cmax = X[a + b]", "- else:", "- cmax = N - 1", "- # cminはjより大きい", "- if cmin is not None and cmin <= j:", "- cmin = j + 1", "- # print(b-a,a+b,cmin,cmax)", "- # if a == 2 and b == 3:", "- # print(b-a,a+b,cmin,cmax)", "- # exit()", "- # どちらかがNoneなら0", "- if cmin is not None and cmax is not None and cmin <= cmax:", "- ans += cmax - cmin + 1", "+ # Lの中で条件b-a<cを満たす最小のc", "+ ind_cmin = j + 1", "+ # Lの中で条件L[k]<a+bを満たす最大のk = Lの中で昇順ソートを崩さずa+bを挿入できる最小のインデックス-1", "+ # 2分法で探す", "+ ind_cmax = bisect.bisect_left(L, a + b) - 1", "+ ans += ind_cmax - ind_cmin + 1" ]
false
0.107272
0.070456
1.52254
[ "s920516409", "s026009923" ]
u359358631
p02578
python
s734684387
s252861152
101
82
32,232
32,376
Accepted
Accepted
18.81
def main(): N = int(eval(input())) A = list(map(int, input().split())) h = A[0] ans = 0 for i in range(N): if A[i] < h: ans += h - A[i] if A[i] > h: h = A[i] print(ans) if __name__ == "__main__": main()
def main(): N = int(eval(input())) A = list(map(int, input().split())) tallest = A[0] ans = 0 for height in A: if height < tallest: ans += tallest - height elif height > tallest: tallest = height print(ans) if __name__ == "__main__": main()
17
18
285
325
def main(): N = int(eval(input())) A = list(map(int, input().split())) h = A[0] ans = 0 for i in range(N): if A[i] < h: ans += h - A[i] if A[i] > h: h = A[i] print(ans) if __name__ == "__main__": main()
def main(): N = int(eval(input())) A = list(map(int, input().split())) tallest = A[0] ans = 0 for height in A: if height < tallest: ans += tallest - height elif height > tallest: tallest = height print(ans) if __name__ == "__main__": main()
false
5.555556
[ "- h = A[0]", "+ tallest = A[0]", "- for i in range(N):", "- if A[i] < h:", "- ans += h - A[i]", "- if A[i] > h:", "- h = A[i]", "+ for height in A:", "+ if height < tallest:", "+ ans += tallest - height", "+ elif height > tallest:", "+ tallest = height" ]
false
0.038742
0.039287
0.986131
[ "s734684387", "s252861152" ]
u965436898
p03161
python
s950183306
s743401971
1,805
414
21,968
55,264
Accepted
Accepted
77.06
import numpy as np n,k = list(map(int,input().split())) field = np.array(input().split(),np.int64) dp = np.zeros(n,np.int64) # numpyのブロードキャストとスライスを組み合わせることで1重のfor文で済ますという変態的なことをしてる # ただ計算量がO(N)になっているかは謎 for i in range(1,n): left = max(0,i - k) dp[i] = (dp[left:i] + abs(field[left:i] - field[i])).min() print((dp[-1]))
n,k = list(map(int,input().split())) field = list(map(int,input().split())) dp = [float("inf")]*len(field) dp[0] = 0 for i in range(0,n - 1): for j in range(1,k + 1): if i + j < n: dp[i + j] = min(dp[i + j],dp[i] + abs(field[i + j] - field[i])) print((dp[-1]))
10
9
323
273
import numpy as np n, k = list(map(int, input().split())) field = np.array(input().split(), np.int64) dp = np.zeros(n, np.int64) # numpyのブロードキャストとスライスを組み合わせることで1重のfor文で済ますという変態的なことをしてる # ただ計算量がO(N)になっているかは謎 for i in range(1, n): left = max(0, i - k) dp[i] = (dp[left:i] + abs(field[left:i] - field[i])).min() print((dp[-1]))
n, k = list(map(int, input().split())) field = list(map(int, input().split())) dp = [float("inf")] * len(field) dp[0] = 0 for i in range(0, n - 1): for j in range(1, k + 1): if i + j < n: dp[i + j] = min(dp[i + j], dp[i] + abs(field[i + j] - field[i])) print((dp[-1]))
false
10
[ "-import numpy as np", "-", "-field = np.array(input().split(), np.int64)", "-dp = np.zeros(n, np.int64)", "-# numpyのブロードキャストとスライスを組み合わせることで1重のfor文で済ますという変態的なことをしてる", "-# ただ計算量がO(N)になっているかは謎", "-for i in range(1, n):", "- left = max(0, i - k)", "- dp[i] = (dp[left:i] + abs(field[left:i] - field[i])).min()", "+field = list(map(int, input().split()))", "+dp = [float(\"inf\")] * len(field)", "+dp[0] = 0", "+for i in range(0, n - 1):", "+ for j in range(1, k + 1):", "+ if i + j < n:", "+ dp[i + j] = min(dp[i + j], dp[i] + abs(field[i + j] - field[i]))" ]
false
0.341289
0.045343
7.526778
[ "s950183306", "s743401971" ]
u492026192
p02949
python
s513614275
s151807272
843
754
50,412
49,772
Accepted
Accepted
10.56
"""解説を見てから解いたコード""" N, M, P = list(map(int, input().split())) edges = [] for _ in range(M): a, b, c = list(map(int, input().split())) edges.append((a, b, c-P)) INF = float('inf') coin_map = [-INF] * (N+1) coin_map[1] = 0 for i in range(2*N): for a, b, c in edges: if coin_map[b] < coin_map[a] + c: coin_map[b] = coin_map[a] + c if i >= N: coin_map[b] = INF if i == N - 1: ans = coin_map[N] if ans != coin_map[N]: print((-1)) else: print((max(0, coin_map[N])))
n,m,p=list(map(int,input().split())) A=[] for i in range(m): a,b,c=list(map(int,input().split())) A.append((a,b,c-p)) def BellmanFord(edges,num_v,source): #グラフの初期化 inf=float("inf") dist=[-inf for i in range(num_v)] dist[source-1]=0 #辺の緩和 buf=0 for i in range(num_v*2): for edge in edges: if dist[edge[1]-1] < dist[edge[0]-1] + edge[2]: dist[edge[1]-1] = dist[edge[0]-1] + edge[2] if i>=num_v: dist[edge[1]-1] =inf if i==num_v-1: buf=dist[-1] if dist[-1]!=buf or dist[-1]==-inf: return -1 return max(dist[-1],0) x=BellmanFord(A,n,1) print(x)
28
28
558
704
"""解説を見てから解いたコード""" N, M, P = list(map(int, input().split())) edges = [] for _ in range(M): a, b, c = list(map(int, input().split())) edges.append((a, b, c - P)) INF = float("inf") coin_map = [-INF] * (N + 1) coin_map[1] = 0 for i in range(2 * N): for a, b, c in edges: if coin_map[b] < coin_map[a] + c: coin_map[b] = coin_map[a] + c if i >= N: coin_map[b] = INF if i == N - 1: ans = coin_map[N] if ans != coin_map[N]: print((-1)) else: print((max(0, coin_map[N])))
n, m, p = list(map(int, input().split())) A = [] for i in range(m): a, b, c = list(map(int, input().split())) A.append((a, b, c - p)) def BellmanFord(edges, num_v, source): # グラフの初期化 inf = float("inf") dist = [-inf for i in range(num_v)] dist[source - 1] = 0 # 辺の緩和 buf = 0 for i in range(num_v * 2): for edge in edges: if dist[edge[1] - 1] < dist[edge[0] - 1] + edge[2]: dist[edge[1] - 1] = dist[edge[0] - 1] + edge[2] if i >= num_v: dist[edge[1] - 1] = inf if i == num_v - 1: buf = dist[-1] if dist[-1] != buf or dist[-1] == -inf: return -1 return max(dist[-1], 0) x = BellmanFord(A, n, 1) print(x)
false
0
[ "-\"\"\"解説を見てから解いたコード\"\"\"", "-N, M, P = list(map(int, input().split()))", "-edges = []", "-for _ in range(M):", "+n, m, p = list(map(int, input().split()))", "+A = []", "+for i in range(m):", "- edges.append((a, b, c - P))", "-INF = float(\"inf\")", "-coin_map = [-INF] * (N + 1)", "-coin_map[1] = 0", "-for i in range(2 * N):", "- for a, b, c in edges:", "- if coin_map[b] < coin_map[a] + c:", "- coin_map[b] = coin_map[a] + c", "- if i >= N:", "- coin_map[b] = INF", "- if i == N - 1:", "- ans = coin_map[N]", "-if ans != coin_map[N]:", "- print((-1))", "-else:", "- print((max(0, coin_map[N])))", "+ A.append((a, b, c - p))", "+", "+", "+def BellmanFord(edges, num_v, source):", "+ # グラフの初期化", "+ inf = float(\"inf\")", "+ dist = [-inf for i in range(num_v)]", "+ dist[source - 1] = 0", "+ # 辺の緩和", "+ buf = 0", "+ for i in range(num_v * 2):", "+ for edge in edges:", "+ if dist[edge[1] - 1] < dist[edge[0] - 1] + edge[2]:", "+ dist[edge[1] - 1] = dist[edge[0] - 1] + edge[2]", "+ if i >= num_v:", "+ dist[edge[1] - 1] = inf", "+ if i == num_v - 1:", "+ buf = dist[-1]", "+ if dist[-1] != buf or dist[-1] == -inf:", "+ return -1", "+ return max(dist[-1], 0)", "+", "+", "+x = BellmanFord(A, n, 1)", "+print(x)" ]
false
0.03768
0.041389
0.910391
[ "s513614275", "s151807272" ]
u083960235
p02726
python
s658172218
s669358841
1,711
668
121,368
75,736
Accepted
Accepted
60.96
import sys, re, os from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import permutations, combinations, product, accumulate from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from fractions import gcd from heapq import heappop, heappush, heapify def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def S_MAP(): return list(map(str, input().split())) def LIST(): return list(map(int, input().split())) def S_LIST(): return list(map(str, input().split())) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10 ** 9 + 7 def dijkstra(E, start): N_d = len(E) dist = [INF] * N_d dist[start] = 0 q = [(0, start)] while q: dist_v, v = heappop(q) if dist[v] != dist_v: continue for u, dist_vu in E[v]: dist_u = dist_v + dist_vu if dist_u < dist[u]: dist[u] = dist_u heappush(q, (dist_u, u)) return dist N, X, Y = MAP() graph = defaultdict(list) for i in range(N-1): graph[i].append((i+1, 1)) graph[i+1].append((i, 1)) graph[X-1].append((Y-1, 1)) graph[Y-1].append((X-1, 1)) a = dijkstra(graph, 0) count = defaultdict(int) for i in range(N): a = dijkstra(graph, i) # print(a[i+1:]) for c in a[i+1:]: count[c] += 1 # print(count) for i in range(1, N): print((count[i]))
import sys, re, os from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import permutations, combinations, product, accumulate from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from fractions import gcd def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def S_MAP(): return list(map(str, input().split())) def LIST(): return list(map(int, input().split())) def S_LIST(): return list(map(str, input().split())) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10 ** 9 + 7 N, X, Y = MAP() graph = [[] for i in range(N)] for i in range(N-1): graph[i].append(i+1) graph[i+1].append(i) graph[X-1].append(Y-1) graph[Y-1].append(X-1) dic = defaultdict(int) for i in range(N): q = deque() q.append(i) dist = [INF] * N dist[i] = 0 while q: n = q.popleft() for node in graph[n]: if dist[node] == INF: dist[node] = dist[n] + 1 q.append(node) for d in dist: dic[d] += 1 for k in range(1, N): print((dic[k] // 2))
60
49
1,615
1,300
import sys, re, os from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import permutations, combinations, product, accumulate from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from fractions import gcd from heapq import heappop, heappush, heapify def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def S_MAP(): return list(map(str, input().split())) def LIST(): return list(map(int, input().split())) def S_LIST(): return list(map(str, input().split())) sys.setrecursionlimit(10**9) INF = float("inf") mod = 10**9 + 7 def dijkstra(E, start): N_d = len(E) dist = [INF] * N_d dist[start] = 0 q = [(0, start)] while q: dist_v, v = heappop(q) if dist[v] != dist_v: continue for u, dist_vu in E[v]: dist_u = dist_v + dist_vu if dist_u < dist[u]: dist[u] = dist_u heappush(q, (dist_u, u)) return dist N, X, Y = MAP() graph = defaultdict(list) for i in range(N - 1): graph[i].append((i + 1, 1)) graph[i + 1].append((i, 1)) graph[X - 1].append((Y - 1, 1)) graph[Y - 1].append((X - 1, 1)) a = dijkstra(graph, 0) count = defaultdict(int) for i in range(N): a = dijkstra(graph, i) # print(a[i+1:]) for c in a[i + 1 :]: count[c] += 1 # print(count) for i in range(1, N): print((count[i]))
import sys, re, os from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import permutations, combinations, product, accumulate from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from fractions import gcd def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def S_MAP(): return list(map(str, input().split())) def LIST(): return list(map(int, input().split())) def S_LIST(): return list(map(str, input().split())) sys.setrecursionlimit(10**9) INF = float("inf") mod = 10**9 + 7 N, X, Y = MAP() graph = [[] for i in range(N)] for i in range(N - 1): graph[i].append(i + 1) graph[i + 1].append(i) graph[X - 1].append(Y - 1) graph[Y - 1].append(X - 1) dic = defaultdict(int) for i in range(N): q = deque() q.append(i) dist = [INF] * N dist[i] = 0 while q: n = q.popleft() for node in graph[n]: if dist[node] == INF: dist[node] = dist[n] + 1 q.append(node) for d in dist: dic[d] += 1 for k in range(1, N): print((dic[k] // 2))
false
18.333333
[ "-from heapq import heappop, heappush, heapify", "-", "-", "-def dijkstra(E, start):", "- N_d = len(E)", "- dist = [INF] * N_d", "- dist[start] = 0", "- q = [(0, start)]", "+N, X, Y = MAP()", "+graph = [[] for i in range(N)]", "+for i in range(N - 1):", "+ graph[i].append(i + 1)", "+ graph[i + 1].append(i)", "+graph[X - 1].append(Y - 1)", "+graph[Y - 1].append(X - 1)", "+dic = defaultdict(int)", "+for i in range(N):", "+ q = deque()", "+ q.append(i)", "+ dist = [INF] * N", "+ dist[i] = 0", "- dist_v, v = heappop(q)", "- if dist[v] != dist_v:", "- continue", "- for u, dist_vu in E[v]:", "- dist_u = dist_v + dist_vu", "- if dist_u < dist[u]:", "- dist[u] = dist_u", "- heappush(q, (dist_u, u))", "- return dist", "-", "-", "-N, X, Y = MAP()", "-graph = defaultdict(list)", "-for i in range(N - 1):", "- graph[i].append((i + 1, 1))", "- graph[i + 1].append((i, 1))", "-graph[X - 1].append((Y - 1, 1))", "-graph[Y - 1].append((X - 1, 1))", "-a = dijkstra(graph, 0)", "-count = defaultdict(int)", "-for i in range(N):", "- a = dijkstra(graph, i)", "- # print(a[i+1:])", "- for c in a[i + 1 :]:", "- count[c] += 1", "-# print(count)", "-for i in range(1, N):", "- print((count[i]))", "+ n = q.popleft()", "+ for node in graph[n]:", "+ if dist[node] == INF:", "+ dist[node] = dist[n] + 1", "+ q.append(node)", "+ for d in dist:", "+ dic[d] += 1", "+for k in range(1, N):", "+ print((dic[k] // 2))" ]
false
0.131548
0.044119
2.981685
[ "s658172218", "s669358841" ]
u562935282
p02646
python
s647296608
s017400253
23
21
9,184
9,172
Accepted
Accepted
8.7
def main(): A, V = list(map(int, input().split())) B, W = list(map(int, input().split())) T = int(eval(input())) if A == B: print('YES') return d = abs(A - B) dv = V - W if d <= dv * T: print('YES') else: print('NO') return if __name__ == '__main__': main() # import sys # input = sys.stdin.readline # # sys.setrecursionlimit(10 ** 7) # # (int(x)-1 for x in input().split()) # rstrip() # # def binary_search(*, ok, ng, func): # while abs(ok - ng) > 1: # mid = (ok + ng) // 2 # if func(mid): # ok = mid # else: # ng = mid # return ok
def main(): A, V = list(map(int, input().split())) B, W = list(map(int, input().split())) T = int(eval(input())) d = abs(A - B) s = V - W print(('YES' if T * s >= d else 'NO')) if __name__ == '__main__': main()
38
12
686
233
def main(): A, V = list(map(int, input().split())) B, W = list(map(int, input().split())) T = int(eval(input())) if A == B: print("YES") return d = abs(A - B) dv = V - W if d <= dv * T: print("YES") else: print("NO") return if __name__ == "__main__": main() # import sys # input = sys.stdin.readline # # sys.setrecursionlimit(10 ** 7) # # (int(x)-1 for x in input().split()) # rstrip() # # def binary_search(*, ok, ng, func): # while abs(ok - ng) > 1: # mid = (ok + ng) // 2 # if func(mid): # ok = mid # else: # ng = mid # return ok
def main(): A, V = list(map(int, input().split())) B, W = list(map(int, input().split())) T = int(eval(input())) d = abs(A - B) s = V - W print(("YES" if T * s >= d else "NO")) if __name__ == "__main__": main()
false
68.421053
[ "- if A == B:", "- print(\"YES\")", "- return", "- dv = V - W", "- if d <= dv * T:", "- print(\"YES\")", "- else:", "- print(\"NO\")", "- return", "+ s = V - W", "+ print((\"YES\" if T * s >= d else \"NO\"))", "-# import sys", "-# input = sys.stdin.readline", "-#", "-# sys.setrecursionlimit(10 ** 7)", "-#", "-# (int(x)-1 for x in input().split())", "-# rstrip()", "-#", "-# def binary_search(*, ok, ng, func):", "-# while abs(ok - ng) > 1:", "-# mid = (ok + ng) // 2", "-# if func(mid):", "-# ok = mid", "-# else:", "-# ng = mid", "-# return ok" ]
false
0.06702
0.035554
1.885041
[ "s647296608", "s017400253" ]
u893063840
p02955
python
s732892869
s825118170
280
225
3,192
3,064
Accepted
Accepted
19.64
from math import sqrt from itertools import accumulate def common_divisors(x): ret = [] for i in range(1, int(sqrt(x)) + 1): if x % i == 0: ret.append(i) ret.append(x // i) return ret n, k = list(map(int, input().split())) a = list(map(int, input().split())) sm = sum(a) cd = common_divisors(sm) ans = 0 for ecd in cd: r = [e % ecd for e in a] r.sort() sub = [0] + list(accumulate(r)) add = [0] + list(accumulate(ecd - e for e in r[::-1])) add = add[::-1] for sb, ad in zip(sub, add): if sb == ad and sb <= k: ans = max(ans, ecd) print(ans)
def get_divisors(x): i = 1 ret = set() while i * i <= x: if x % i == 0: ret.add(i) ret.add(x // i) i += 1 return ret n, k = list(map(int, input().split())) a = list(map(int, input().split())) sm = sum(a) divs = get_divisors(sm) ans = 0 for div in divs: mods = [e % div for e in a] mods.sort() p = 0 m = n * div - sum(mods) for mod in mods: p += mod m -= div - mod if p == m: if p <= k: ans = max(ans, div) break print(ans)
32
34
662
597
from math import sqrt from itertools import accumulate def common_divisors(x): ret = [] for i in range(1, int(sqrt(x)) + 1): if x % i == 0: ret.append(i) ret.append(x // i) return ret n, k = list(map(int, input().split())) a = list(map(int, input().split())) sm = sum(a) cd = common_divisors(sm) ans = 0 for ecd in cd: r = [e % ecd for e in a] r.sort() sub = [0] + list(accumulate(r)) add = [0] + list(accumulate(ecd - e for e in r[::-1])) add = add[::-1] for sb, ad in zip(sub, add): if sb == ad and sb <= k: ans = max(ans, ecd) print(ans)
def get_divisors(x): i = 1 ret = set() while i * i <= x: if x % i == 0: ret.add(i) ret.add(x // i) i += 1 return ret n, k = list(map(int, input().split())) a = list(map(int, input().split())) sm = sum(a) divs = get_divisors(sm) ans = 0 for div in divs: mods = [e % div for e in a] mods.sort() p = 0 m = n * div - sum(mods) for mod in mods: p += mod m -= div - mod if p == m: if p <= k: ans = max(ans, div) break print(ans)
false
5.882353
[ "-from math import sqrt", "-from itertools import accumulate", "-", "-", "-def common_divisors(x):", "- ret = []", "- for i in range(1, int(sqrt(x)) + 1):", "+def get_divisors(x):", "+ i = 1", "+ ret = set()", "+ while i * i <= x:", "- ret.append(i)", "- ret.append(x // i)", "+ ret.add(i)", "+ ret.add(x // i)", "+ i += 1", "-cd = common_divisors(sm)", "+divs = get_divisors(sm)", "-for ecd in cd:", "- r = [e % ecd for e in a]", "- r.sort()", "- sub = [0] + list(accumulate(r))", "- add = [0] + list(accumulate(ecd - e for e in r[::-1]))", "- add = add[::-1]", "- for sb, ad in zip(sub, add):", "- if sb == ad and sb <= k:", "- ans = max(ans, ecd)", "+for div in divs:", "+ mods = [e % div for e in a]", "+ mods.sort()", "+ p = 0", "+ m = n * div - sum(mods)", "+ for mod in mods:", "+ p += mod", "+ m -= div - mod", "+ if p == m:", "+ if p <= k:", "+ ans = max(ans, div)", "+ break" ]
false
0.037295
0.037271
1.000643
[ "s732892869", "s825118170" ]
u223133214
p03846
python
s219404797
s265766881
107
96
13,876
13,876
Accepted
Accepted
10.28
from math import ceil import sys input = sys.stdin.readline N = int(eval(input())) A = list(map(int, input().split())) A.sort() if N % 2 == 1: num = (N - 1) // 2 if A[0] != 0: print((0)) exit() for i in range(1, N): if A[i] == ceil(i / 2) * 2: continue else: print((0)) exit() else: num = N // 2 for i in range(N - 1): if A[i] == (i // 2) * 2 + 1: continue else: print((0)) exit() ans = 1 for i in range(num): ans *= 2 ans %= (10**9 + 7) print(ans)
from math import ceil import sys input = sys.stdin.readline N = int(eval(input())) A = list(map(int, input().split())) A.sort() if N % 2 == 1: num = (N - 1) // 2 if A[0] != 0: print((0)) exit() for i in range(1, N): if A[i] == ceil(i / 2) * 2: continue else: print((0)) exit() else: num = N // 2 for i in range(N - 1): if A[i] == (i // 2) * 2 + 1: continue else: print((0)) exit() print(((2**num) % (10**9 + 7)))
33
29
620
570
from math import ceil import sys input = sys.stdin.readline N = int(eval(input())) A = list(map(int, input().split())) A.sort() if N % 2 == 1: num = (N - 1) // 2 if A[0] != 0: print((0)) exit() for i in range(1, N): if A[i] == ceil(i / 2) * 2: continue else: print((0)) exit() else: num = N // 2 for i in range(N - 1): if A[i] == (i // 2) * 2 + 1: continue else: print((0)) exit() ans = 1 for i in range(num): ans *= 2 ans %= 10**9 + 7 print(ans)
from math import ceil import sys input = sys.stdin.readline N = int(eval(input())) A = list(map(int, input().split())) A.sort() if N % 2 == 1: num = (N - 1) // 2 if A[0] != 0: print((0)) exit() for i in range(1, N): if A[i] == ceil(i / 2) * 2: continue else: print((0)) exit() else: num = N // 2 for i in range(N - 1): if A[i] == (i // 2) * 2 + 1: continue else: print((0)) exit() print(((2**num) % (10**9 + 7)))
false
12.121212
[ "-ans = 1", "-for i in range(num):", "- ans *= 2", "- ans %= 10**9 + 7", "-print(ans)", "+print(((2**num) % (10**9 + 7)))" ]
false
0.048737
0.048394
1.007095
[ "s219404797", "s265766881" ]
u141419468
p02689
python
s370152803
s844366387
309
252
27,756
20,060
Accepted
Accepted
18.45
import collections N, M = list(map(int,input().split())) H = list(map(int,input().split())) a = [] b = [] loser = [] for i in range(M): A, B = list(map(int, input().split())) a.append(A) b.append(B) if H[a[i]-1] > H[b[i]-1]: loser.append(b[i]) elif H[a[i]-1] == H[b[i]-1]: loser.append(b[i]) loser.append(a[i]) elif H[a[i]-1] < H[b[i]-1]: loser.append(a[i]) X = len(collections.Counter(loser)) print((N-X))
N, M = list(map(int, input().split())) H = list(map(int, input().split())) win = [1]*N for _ in range(M): A, B = list(map(int, input().split())) if H[A-1] > H[B-1]: win[B-1] = 0 elif H[A-1] < H[B-1]: win[A-1] = 0 else: win[A-1] = 0 win[B-1] = 0 print((sum(win)))
25
15
478
313
import collections N, M = list(map(int, input().split())) H = list(map(int, input().split())) a = [] b = [] loser = [] for i in range(M): A, B = list(map(int, input().split())) a.append(A) b.append(B) if H[a[i] - 1] > H[b[i] - 1]: loser.append(b[i]) elif H[a[i] - 1] == H[b[i] - 1]: loser.append(b[i]) loser.append(a[i]) elif H[a[i] - 1] < H[b[i] - 1]: loser.append(a[i]) X = len(collections.Counter(loser)) print((N - X))
N, M = list(map(int, input().split())) H = list(map(int, input().split())) win = [1] * N for _ in range(M): A, B = list(map(int, input().split())) if H[A - 1] > H[B - 1]: win[B - 1] = 0 elif H[A - 1] < H[B - 1]: win[A - 1] = 0 else: win[A - 1] = 0 win[B - 1] = 0 print((sum(win)))
false
40
[ "-import collections", "-", "-a = []", "-b = []", "-loser = []", "-for i in range(M):", "+win = [1] * N", "+for _ in range(M):", "- a.append(A)", "- b.append(B)", "- if H[a[i] - 1] > H[b[i] - 1]:", "- loser.append(b[i])", "- elif H[a[i] - 1] == H[b[i] - 1]:", "- loser.append(b[i])", "- loser.append(a[i])", "- elif H[a[i] - 1] < H[b[i] - 1]:", "- loser.append(a[i])", "-X = len(collections.Counter(loser))", "-print((N - X))", "+ if H[A - 1] > H[B - 1]:", "+ win[B - 1] = 0", "+ elif H[A - 1] < H[B - 1]:", "+ win[A - 1] = 0", "+ else:", "+ win[A - 1] = 0", "+ win[B - 1] = 0", "+print((sum(win)))" ]
false
0.042488
0.04356
0.975381
[ "s370152803", "s844366387" ]
u189487046
p03624
python
s089849342
s386846750
60
20
4,208
3,956
Accepted
Accepted
66.67
ALPHABET = "abcdefghijklmnopqrstuvwxyz" s = list(eval(input())) s.sort() for i in ALPHABET: if i not in s: print(i) break else: print("None")
ALPHABET = "abcdefghijklmnopqrstuvwxyz" s = list(eval(input())) for i in ALPHABET: if i not in s: print(i) break else: print("None")
10
9
170
160
ALPHABET = "abcdefghijklmnopqrstuvwxyz" s = list(eval(input())) s.sort() for i in ALPHABET: if i not in s: print(i) break else: print("None")
ALPHABET = "abcdefghijklmnopqrstuvwxyz" s = list(eval(input())) for i in ALPHABET: if i not in s: print(i) break else: print("None")
false
10
[ "-s.sort()" ]
false
0.039914
0.044332
0.900343
[ "s089849342", "s386846750" ]
u580258754
p03013
python
s252648436
s500533831
478
187
460,056
13,216
Accepted
Accepted
60.88
N, M = list(map(int,input().split())) a = set([int(eval(input())) for i in range(M)]) dp = [0 for i in range(N+1)] dp[0] = 1 dp[1] = 1 for i in range(2,N+1): if (i-2 in a) and (i-1 in a): dp[-1] = 0 break elif i-2 in a: dp[i] = dp[i-1] elif i-1 in a: dp[i] = dp[i-2] else: dp[i] = dp[i-1] + dp[i-2] print((dp[-1]%(7+10**9)))
N,M = list(map(int,input().split())) a = [int(eval(input())) for i in range(M)] a = set(a) dp = [0]*(N+100) for i in range(N+1): if i == 0: dp[i] = 1 continue if i in a: continue elif i-1 in a: dp[i] = dp[i-2] elif i-2 in a: dp[i] = dp[i-1] elif i-1 in a and i-2 in a: break else: dp[i] = dp[i-1] + dp[i-2] dp[i] = dp[i]%(7+10**9) print((dp[N]%(7+10**9)))
17
22
355
410
N, M = list(map(int, input().split())) a = set([int(eval(input())) for i in range(M)]) dp = [0 for i in range(N + 1)] dp[0] = 1 dp[1] = 1 for i in range(2, N + 1): if (i - 2 in a) and (i - 1 in a): dp[-1] = 0 break elif i - 2 in a: dp[i] = dp[i - 1] elif i - 1 in a: dp[i] = dp[i - 2] else: dp[i] = dp[i - 1] + dp[i - 2] print((dp[-1] % (7 + 10**9)))
N, M = list(map(int, input().split())) a = [int(eval(input())) for i in range(M)] a = set(a) dp = [0] * (N + 100) for i in range(N + 1): if i == 0: dp[i] = 1 continue if i in a: continue elif i - 1 in a: dp[i] = dp[i - 2] elif i - 2 in a: dp[i] = dp[i - 1] elif i - 1 in a and i - 2 in a: break else: dp[i] = dp[i - 1] + dp[i - 2] dp[i] = dp[i] % (7 + 10**9) print((dp[N] % (7 + 10**9)))
false
22.727273
[ "-a = set([int(eval(input())) for i in range(M)])", "-dp = [0 for i in range(N + 1)]", "-dp[0] = 1", "-dp[1] = 1", "-for i in range(2, N + 1):", "- if (i - 2 in a) and (i - 1 in a):", "- dp[-1] = 0", "- break", "+a = [int(eval(input())) for i in range(M)]", "+a = set(a)", "+dp = [0] * (N + 100)", "+for i in range(N + 1):", "+ if i == 0:", "+ dp[i] = 1", "+ continue", "+ if i in a:", "+ continue", "+ elif i - 1 in a:", "+ dp[i] = dp[i - 2]", "- elif i - 1 in a:", "- dp[i] = dp[i - 2]", "+ elif i - 1 in a and i - 2 in a:", "+ break", "-print((dp[-1] % (7 + 10**9)))", "+ dp[i] = dp[i] % (7 + 10**9)", "+print((dp[N] % (7 + 10**9)))" ]
false
0.036774
0.036548
1.006178
[ "s252648436", "s500533831" ]
u029000441
p04031
python
s214312169
s092367134
29
22
3,316
3,316
Accepted
Accepted
24.14
import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) from collections import Counter, deque from collections import defaultdict from itertools import combinations, permutations, accumulate, groupby, product from bisect import bisect_left,bisect_right from heapq import heapify, heappop, heappush from math import floor, ceil,pi,factorial from operator import itemgetter def I(): return int(eval(input())) def MI(): return list(map(int, input().split())) def LI(): return list(map(int, input().split())) def LI2(): return [int(eval(input())) for i in range(n)] def MXI(): return [[LI()]for i in range(n)] def SI(): return input().rstrip() def printns(x): print(('\n'.join(x))) def printni(x): print(('\n'.join(list(map(str,x))))) inf = 10**17 mod = 10**9 + 7 n=I() lis=LI() mn=inf for i in range(-100,100+1): sm=0 for s in lis: sm+=(s-i)**2 if sm<mn: mn=sm print(mn)
import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) from collections import Counter, deque from collections import defaultdict from itertools import combinations, permutations, accumulate, groupby, product from bisect import bisect_left,bisect_right from heapq import heapify, heappop, heappush from math import floor, ceil,pi,factorial from operator import itemgetter def I(): return int(eval(input())) def MI(): return list(map(int, input().split())) def LI(): return list(map(int, input().split())) def LI2(): return [int(eval(input())) for i in range(n)] def MXI(): return [[LI()]for i in range(n)] def SI(): return input().rstrip() def printns(x): print(('\n'.join(x))) def printni(x): print(('\n'.join(list(map(str,x))))) inf = 10**17 mod = 10**9 + 7 n=I() lis=LI() U,V=0,0 u=ceil(sum(lis)/n) v=int(sum(lis)/n) for i in range(n): U+=(lis[i]-u)**2 V+=(lis[i]-v)**2 print((min(U,V)))
31
30
916
916
import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) from collections import Counter, deque from collections import defaultdict from itertools import combinations, permutations, accumulate, groupby, product from bisect import bisect_left, bisect_right from heapq import heapify, heappop, heappush from math import floor, ceil, pi, factorial from operator import itemgetter def I(): return int(eval(input())) def MI(): return list(map(int, input().split())) def LI(): return list(map(int, input().split())) def LI2(): return [int(eval(input())) for i in range(n)] def MXI(): return [[LI()] for i in range(n)] def SI(): return input().rstrip() def printns(x): print(("\n".join(x))) def printni(x): print(("\n".join(list(map(str, x))))) inf = 10**17 mod = 10**9 + 7 n = I() lis = LI() mn = inf for i in range(-100, 100 + 1): sm = 0 for s in lis: sm += (s - i) ** 2 if sm < mn: mn = sm print(mn)
import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) from collections import Counter, deque from collections import defaultdict from itertools import combinations, permutations, accumulate, groupby, product from bisect import bisect_left, bisect_right from heapq import heapify, heappop, heappush from math import floor, ceil, pi, factorial from operator import itemgetter def I(): return int(eval(input())) def MI(): return list(map(int, input().split())) def LI(): return list(map(int, input().split())) def LI2(): return [int(eval(input())) for i in range(n)] def MXI(): return [[LI()] for i in range(n)] def SI(): return input().rstrip() def printns(x): print(("\n".join(x))) def printni(x): print(("\n".join(list(map(str, x))))) inf = 10**17 mod = 10**9 + 7 n = I() lis = LI() U, V = 0, 0 u = ceil(sum(lis) / n) v = int(sum(lis) / n) for i in range(n): U += (lis[i] - u) ** 2 V += (lis[i] - v) ** 2 print((min(U, V)))
false
3.225806
[ "-mn = inf", "-for i in range(-100, 100 + 1):", "- sm = 0", "- for s in lis:", "- sm += (s - i) ** 2", "- if sm < mn:", "- mn = sm", "-print(mn)", "+U, V = 0, 0", "+u = ceil(sum(lis) / n)", "+v = int(sum(lis) / n)", "+for i in range(n):", "+ U += (lis[i] - u) ** 2", "+ V += (lis[i] - v) ** 2", "+print((min(U, V)))" ]
false
0.04052
0.037985
1.066735
[ "s214312169", "s092367134" ]
u912237403
p00038
python
s752541984
s911093993
20
10
4,304
4,240
Accepted
Accepted
50
def readdata(): x = [] try: while True: x.append(list(map(int,input().split(",")))) except: return x def checkhand2(hand): tmp = [(e+11)%13 for e in hand] x1=sorted(list(set(tmp))) x2=[] for e in x1: x2.append(tmp.count(e)) return x1,x2 def isstraight(x1): if x1==[0,1,2,3,12]: return True e = x1[0] if x1==list(range(e,e+5)): return True else: return False def checkhand(hand): x1,x2 = checkhand2(hand) x2 = sorted(x2) prize = 0 if x2==[1,1,1,1,1]: if isstraight(x1): prize = 4 else: prize = 0 elif x2==[1,1,1,2]: prize = 1 elif x2==[1,2,2]: prize = 2 elif x2==[1,1,3]: prize = 3 elif x2==[2,3]: prize = 5 elif x2==[1,4]: prize = 6 return prize values=[2,3,4,5,6,7,8,9,10,11,12,13,1] prize=["null","one pair","two pair","three card", "straight","full house","four card"] hands = readdata() for e in hands: print(prize[checkhand(e)])
prize=["null","one pair","two pair","three card", "straight","full house","four card"] try: while True: hand = list(map(int,input().split(","))) x = sorted(list(set(hand))) a = len(x) b = max([hand.count(e) for e in x]) if b==4: p=6 elif b==3: if a==2: p=5 else: p=3 elif b==2: if a==3: p=2 else: p=1 elif b==1: e = x[0] if x==[1,10,11,12,13] or x==list(range(e,e+5)): p=4 else: p=0 print(prize[p]) except: pass
42
23
1,014
597
def readdata(): x = [] try: while True: x.append(list(map(int, input().split(",")))) except: return x def checkhand2(hand): tmp = [(e + 11) % 13 for e in hand] x1 = sorted(list(set(tmp))) x2 = [] for e in x1: x2.append(tmp.count(e)) return x1, x2 def isstraight(x1): if x1 == [0, 1, 2, 3, 12]: return True e = x1[0] if x1 == list(range(e, e + 5)): return True else: return False def checkhand(hand): x1, x2 = checkhand2(hand) x2 = sorted(x2) prize = 0 if x2 == [1, 1, 1, 1, 1]: if isstraight(x1): prize = 4 else: prize = 0 elif x2 == [1, 1, 1, 2]: prize = 1 elif x2 == [1, 2, 2]: prize = 2 elif x2 == [1, 1, 3]: prize = 3 elif x2 == [2, 3]: prize = 5 elif x2 == [1, 4]: prize = 6 return prize values = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 1] prize = [ "null", "one pair", "two pair", "three card", "straight", "full house", "four card", ] hands = readdata() for e in hands: print(prize[checkhand(e)])
prize = [ "null", "one pair", "two pair", "three card", "straight", "full house", "four card", ] try: while True: hand = list(map(int, input().split(","))) x = sorted(list(set(hand))) a = len(x) b = max([hand.count(e) for e in x]) if b == 4: p = 6 elif b == 3: if a == 2: p = 5 else: p = 3 elif b == 2: if a == 3: p = 2 else: p = 1 elif b == 1: e = x[0] if x == [1, 10, 11, 12, 13] or x == list(range(e, e + 5)): p = 4 else: p = 0 print(prize[p]) except: pass
false
45.238095
[ "-def readdata():", "- x = []", "- try:", "- while True:", "- x.append(list(map(int, input().split(\",\"))))", "- except:", "- return x", "-", "-", "-def checkhand2(hand):", "- tmp = [(e + 11) % 13 for e in hand]", "- x1 = sorted(list(set(tmp)))", "- x2 = []", "- for e in x1:", "- x2.append(tmp.count(e))", "- return x1, x2", "-", "-", "-def isstraight(x1):", "- if x1 == [0, 1, 2, 3, 12]:", "- return True", "- e = x1[0]", "- if x1 == list(range(e, e + 5)):", "- return True", "- else:", "- return False", "-", "-", "-def checkhand(hand):", "- x1, x2 = checkhand2(hand)", "- x2 = sorted(x2)", "- prize = 0", "- if x2 == [1, 1, 1, 1, 1]:", "- if isstraight(x1):", "- prize = 4", "- else:", "- prize = 0", "- elif x2 == [1, 1, 1, 2]:", "- prize = 1", "- elif x2 == [1, 2, 2]:", "- prize = 2", "- elif x2 == [1, 1, 3]:", "- prize = 3", "- elif x2 == [2, 3]:", "- prize = 5", "- elif x2 == [1, 4]:", "- prize = 6", "- return prize", "-", "-", "-values = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 1]", "-hands = readdata()", "-for e in hands:", "- print(prize[checkhand(e)])", "+try:", "+ while True:", "+ hand = list(map(int, input().split(\",\")))", "+ x = sorted(list(set(hand)))", "+ a = len(x)", "+ b = max([hand.count(e) for e in x])", "+ if b == 4:", "+ p = 6", "+ elif b == 3:", "+ if a == 2:", "+ p = 5", "+ else:", "+ p = 3", "+ elif b == 2:", "+ if a == 3:", "+ p = 2", "+ else:", "+ p = 1", "+ elif b == 1:", "+ e = x[0]", "+ if x == [1, 10, 11, 12, 13] or x == list(range(e, e + 5)):", "+ p = 4", "+ else:", "+ p = 0", "+ print(prize[p])", "+except:", "+ pass" ]
false
0.041628
0.048608
0.856414
[ "s752541984", "s911093993" ]
u647766105
p00117
python
s630584849
s497905380
20
10
4,504
4,508
Accepted
Accepted
50
import heapq def dijkstra(start,goal,graph): INF = 2 << 20 node_num = len(graph) visited = [False] * node_num costs = [INF] * node_num pq = [] costs[start] = 0 heapq.heappush(pq, [0,start]) while not len(pq) == 0: cur_cost,cur_node = heapq.heappop(pq) if visited[cur_node]: continue if all(visited[1:]): break visited[cur_node] = True costs[cur_node] = cur_cost for i in range(node_num): if not visited[i]: heapq.heappush(pq,[graph[cur_node][i] + costs[cur_node],i]) return costs[goal] n = eval(input()) m = eval(input()) INF = 2 << 20 graph = [[INF] * (n+1) for _ in range(n+1)] for _ in range(m): a,b,c,d = list(map(int,input().split(","))) graph[a][b] = c graph[b][a] = d home,shop,reward,price = list(map(int,input().split(","))) cost = dijkstra(home,shop,graph) + dijkstra(shop,home,graph) print(reward - price - cost)
import heapq def dijkstra(start,goal,graph): INF = 2 << 20 node_num = len(graph) visited = [False] * node_num costs = [INF] * node_num pq = [] costs[start] = 0 heapq.heappush(pq, [0,start]) while not len(pq) == 0: cur_cost,cur_node = heapq.heappop(pq) if visited[cur_node]: continue visited[cur_node] = True costs[cur_node] = cur_cost for i in range(node_num): if not visited[i]: heapq.heappush(pq,[graph[cur_node][i] + costs[cur_node],i]) return costs[goal] n = eval(input()) m = eval(input()) INF = 2 << 20 graph = [[INF] * (n+1) for _ in range(n+1)] for _ in range(m): a,b,c,d = list(map(int,input().split(","))) graph[a][b] = c graph[b][a] = d home,shop,reward,price = list(map(int,input().split(","))) cost = dijkstra(home,shop,graph) + dijkstra(shop,home,graph) print(reward - price - cost)
35
33
995
946
import heapq def dijkstra(start, goal, graph): INF = 2 << 20 node_num = len(graph) visited = [False] * node_num costs = [INF] * node_num pq = [] costs[start] = 0 heapq.heappush(pq, [0, start]) while not len(pq) == 0: cur_cost, cur_node = heapq.heappop(pq) if visited[cur_node]: continue if all(visited[1:]): break visited[cur_node] = True costs[cur_node] = cur_cost for i in range(node_num): if not visited[i]: heapq.heappush(pq, [graph[cur_node][i] + costs[cur_node], i]) return costs[goal] n = eval(input()) m = eval(input()) INF = 2 << 20 graph = [[INF] * (n + 1) for _ in range(n + 1)] for _ in range(m): a, b, c, d = list(map(int, input().split(","))) graph[a][b] = c graph[b][a] = d home, shop, reward, price = list(map(int, input().split(","))) cost = dijkstra(home, shop, graph) + dijkstra(shop, home, graph) print(reward - price - cost)
import heapq def dijkstra(start, goal, graph): INF = 2 << 20 node_num = len(graph) visited = [False] * node_num costs = [INF] * node_num pq = [] costs[start] = 0 heapq.heappush(pq, [0, start]) while not len(pq) == 0: cur_cost, cur_node = heapq.heappop(pq) if visited[cur_node]: continue visited[cur_node] = True costs[cur_node] = cur_cost for i in range(node_num): if not visited[i]: heapq.heappush(pq, [graph[cur_node][i] + costs[cur_node], i]) return costs[goal] n = eval(input()) m = eval(input()) INF = 2 << 20 graph = [[INF] * (n + 1) for _ in range(n + 1)] for _ in range(m): a, b, c, d = list(map(int, input().split(","))) graph[a][b] = c graph[b][a] = d home, shop, reward, price = list(map(int, input().split(","))) cost = dijkstra(home, shop, graph) + dijkstra(shop, home, graph) print(reward - price - cost)
false
5.714286
[ "- if all(visited[1:]):", "- break" ]
false
0.047596
0.085667
0.555596
[ "s630584849", "s497905380" ]
u033606236
p03409
python
s419241965
s099942388
174
19
39,152
3,064
Accepted
Accepted
89.08
n = int(eval(input())) red = [list(map(int,input().split())) for _ in range(n)] blue = [list(map(int,input().split())) for _ in range(n)] blue.sort(key=lambda x:(x[0],x[1])) check = [False]*n for i in range(n): a = -1 c = -1 for j in range(n): if check[j]:continue if blue[i][0] > red[j][0] and blue[i][1] > red[j][1]: if a < red[j][1]: a = red[j][1] c = j if c != -1: check[c] = True print((check.count(True)))
n = int(eval(input())) red = [list(map(int,input().split())) for _ in range(n)] red.sort(key=lambda x:(x[1])) blue = sorted(list(map(int,input().split())) for _ in range(n)) blue.sort(key=lambda x:(x[0],x[1])) seen = [False]*n for i in range(n): check = -1 for j in range(n): if seen[j]:continue if blue[i][0] > red[j][0] and blue[i][1] > red[j][1]: check = j if check != -1:seen[check] = True print((seen.count(True)))
17
14
503
464
n = int(eval(input())) red = [list(map(int, input().split())) for _ in range(n)] blue = [list(map(int, input().split())) for _ in range(n)] blue.sort(key=lambda x: (x[0], x[1])) check = [False] * n for i in range(n): a = -1 c = -1 for j in range(n): if check[j]: continue if blue[i][0] > red[j][0] and blue[i][1] > red[j][1]: if a < red[j][1]: a = red[j][1] c = j if c != -1: check[c] = True print((check.count(True)))
n = int(eval(input())) red = [list(map(int, input().split())) for _ in range(n)] red.sort(key=lambda x: (x[1])) blue = sorted(list(map(int, input().split())) for _ in range(n)) blue.sort(key=lambda x: (x[0], x[1])) seen = [False] * n for i in range(n): check = -1 for j in range(n): if seen[j]: continue if blue[i][0] > red[j][0] and blue[i][1] > red[j][1]: check = j if check != -1: seen[check] = True print((seen.count(True)))
false
17.647059
[ "-blue = [list(map(int, input().split())) for _ in range(n)]", "+red.sort(key=lambda x: (x[1]))", "+blue = sorted(list(map(int, input().split())) for _ in range(n))", "-check = [False] * n", "+seen = [False] * n", "- a = -1", "- c = -1", "+ check = -1", "- if check[j]:", "+ if seen[j]:", "- if a < red[j][1]:", "- a = red[j][1]", "- c = j", "- if c != -1:", "- check[c] = True", "-print((check.count(True)))", "+ check = j", "+ if check != -1:", "+ seen[check] = True", "+print((seen.count(True)))" ]
false
0.047254
0.038387
1.230974
[ "s419241965", "s099942388" ]
u761529120
p02960
python
s060754657
s393384008
651
414
61,916
101,420
Accepted
Accepted
36.41
def main(): S = eval(input()) N = len(S) MOD = 10 ** 9 + 7 dp = [[0] * 13 for _ in range(N + 5)] dp[0][0] = 1 for i in range(N): if S[i] != '?': for j in range(13): dp[i+1][(j * 10 + int(S[i]))%13] += dp[i][j] dp[i+1][(j * 10 + int(S[i]))%13] %= MOD else: for k in range(10): for j in range(13): dp[i+1][(j * 10 + k)%13] += dp[i][j] dp[i+1][(j * 10 + k)%13] %= MOD print((dp[N][5])) if __name__ == "__main__": main()
def main(): S = list(eval(input())) N = len(S) MOD = 10 ** 9 + 7 dp = [[0] * 13 for _ in range(N + 5)] dp[0][0] = 1 for i in range(N): for j in range(13): if S[i] != '?': dp[i+1][(10 * j + int(S[i])) % 13] += dp[i][j] dp[i+1][(10 * j + int(S[i])) % 13] %= MOD else: for k in range(10): dp[i+1][(10 * j + k) % 13] += dp[i][j] dp[i+1][(10 * j + k) % 13] %= MOD print((dp[N][5])) if __name__ == "__main__": main()
24
20
600
575
def main(): S = eval(input()) N = len(S) MOD = 10**9 + 7 dp = [[0] * 13 for _ in range(N + 5)] dp[0][0] = 1 for i in range(N): if S[i] != "?": for j in range(13): dp[i + 1][(j * 10 + int(S[i])) % 13] += dp[i][j] dp[i + 1][(j * 10 + int(S[i])) % 13] %= MOD else: for k in range(10): for j in range(13): dp[i + 1][(j * 10 + k) % 13] += dp[i][j] dp[i + 1][(j * 10 + k) % 13] %= MOD print((dp[N][5])) if __name__ == "__main__": main()
def main(): S = list(eval(input())) N = len(S) MOD = 10**9 + 7 dp = [[0] * 13 for _ in range(N + 5)] dp[0][0] = 1 for i in range(N): for j in range(13): if S[i] != "?": dp[i + 1][(10 * j + int(S[i])) % 13] += dp[i][j] dp[i + 1][(10 * j + int(S[i])) % 13] %= MOD else: for k in range(10): dp[i + 1][(10 * j + k) % 13] += dp[i][j] dp[i + 1][(10 * j + k) % 13] %= MOD print((dp[N][5])) if __name__ == "__main__": main()
false
16.666667
[ "- S = eval(input())", "+ S = list(eval(input()))", "- if S[i] != \"?\":", "- for j in range(13):", "- dp[i + 1][(j * 10 + int(S[i])) % 13] += dp[i][j]", "- dp[i + 1][(j * 10 + int(S[i])) % 13] %= MOD", "- else:", "- for k in range(10):", "- for j in range(13):", "- dp[i + 1][(j * 10 + k) % 13] += dp[i][j]", "- dp[i + 1][(j * 10 + k) % 13] %= MOD", "+ for j in range(13):", "+ if S[i] != \"?\":", "+ dp[i + 1][(10 * j + int(S[i])) % 13] += dp[i][j]", "+ dp[i + 1][(10 * j + int(S[i])) % 13] %= MOD", "+ else:", "+ for k in range(10):", "+ dp[i + 1][(10 * j + k) % 13] += dp[i][j]", "+ dp[i + 1][(10 * j + k) % 13] %= MOD" ]
false
0.038777
0.045486
0.852499
[ "s060754657", "s393384008" ]
u899975427
p03475
python
s717838002
s550450246
116
86
3,188
3,064
Accepted
Accepted
25.86
import sys input = sys.stdin.readline n = int(eval(input())) csfn = [() for i in range(n-1)] tl = [0]*n for i in range(n-1): c,s,f = list(map(int,input().split())) csfn[i] += (c,s,f) for j in range(i+1): if tl[j] < csfn[i][1]: tl[j] = csfn[i][1] + csfn[i][0] elif tl[j] % csfn[i][2] == 0: tl[j] += csfn[i][0] else: tl[j] += csfn[i][0] + csfn[i][2] - tl[j] % csfn[i][2] for k in tl: print(k)
import sys input = sys.stdin.readline n = int(eval(input())) tl = [0]*n for i in range(n-1): c,s,f = list(map(int,input().split())) for j in range(i+1): if tl[j] < s: tl[j] = s + c elif tl[j] % f == 0: tl[j] += c else: tl[j] += c + f - tl[j] % f for k in tl: print(k)
19
16
440
309
import sys input = sys.stdin.readline n = int(eval(input())) csfn = [() for i in range(n - 1)] tl = [0] * n for i in range(n - 1): c, s, f = list(map(int, input().split())) csfn[i] += (c, s, f) for j in range(i + 1): if tl[j] < csfn[i][1]: tl[j] = csfn[i][1] + csfn[i][0] elif tl[j] % csfn[i][2] == 0: tl[j] += csfn[i][0] else: tl[j] += csfn[i][0] + csfn[i][2] - tl[j] % csfn[i][2] for k in tl: print(k)
import sys input = sys.stdin.readline n = int(eval(input())) tl = [0] * n for i in range(n - 1): c, s, f = list(map(int, input().split())) for j in range(i + 1): if tl[j] < s: tl[j] = s + c elif tl[j] % f == 0: tl[j] += c else: tl[j] += c + f - tl[j] % f for k in tl: print(k)
false
15.789474
[ "-csfn = [() for i in range(n - 1)]", "- csfn[i] += (c, s, f)", "- if tl[j] < csfn[i][1]:", "- tl[j] = csfn[i][1] + csfn[i][0]", "- elif tl[j] % csfn[i][2] == 0:", "- tl[j] += csfn[i][0]", "+ if tl[j] < s:", "+ tl[j] = s + c", "+ elif tl[j] % f == 0:", "+ tl[j] += c", "- tl[j] += csfn[i][0] + csfn[i][2] - tl[j] % csfn[i][2]", "+ tl[j] += c + f - tl[j] % f" ]
false
0.156925
0.040839
3.842545
[ "s717838002", "s550450246" ]
u029000441
p03575
python
s763740636
s830377672
578
322
78,680
55,512
Accepted
Accepted
44.29
#dpでできないかな? import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) from collections import Counter, deque from collections import defaultdict from itertools import combinations, permutations, accumulate, groupby, product from bisect import bisect_left,bisect_right from heapq import heapify, heappop, heappush from math import floor, ceil,pi from operator import itemgetter def I(): return int(eval(input())) def MI(): return list(map(int, input().split())) def LI(): return list(map(int, input().split())) def LI2(): return [int(eval(input())) for i in range(n)] def MXI(): return [[LI()]for i in range(n)] def SI(): return input().rstrip() def printns(x): print(('\n'.join(x))) def printni(x): print(('\n'.join(list(map(str,x))))) inf = 10**17 mod = 10**9 + 7 def dfs(x): for i in tree[x]: if al[i]<0: al[i]=0 dfs(i) n,m=MI() lis=[LI() for i in range(m)] #print(lis) cou=0 for i in range(m): tree=[[] for i in range(n)] for j in range(m): if i!=j: tree[lis[j][0]-1].append(lis[j][1]-1) tree[lis[j][1]-1].append(lis[j][0]-1) count=0 for k in range(n): al=[-1]*n al[k]=0 dfs(k) #print(al) if sum(al)==0: count+=1 if count!=n: cou+=1 print(cou)
#dpでできないかな? import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) from collections import Counter, deque from collections import defaultdict from itertools import combinations, permutations, accumulate, groupby, product from bisect import bisect_left,bisect_right from heapq import heapify, heappop, heappush from math import floor, ceil,pi from operator import itemgetter def I(): return int(eval(input())) def MI(): return list(map(int, input().split())) def LI(): return list(map(int, input().split())) def LI2(): return [int(eval(input())) for i in range(n)] def MXI(): return [[LI()]for i in range(n)] def SI(): return input().rstrip() def printns(x): print(('\n'.join(x))) def printni(x): print(('\n'.join(list(map(str,x))))) inf = 10**17 mod = 10**9 + 7 def dfs(x): for i in tree[x]: if al[i]<0: al[i]=0 dfs(i) n,m=MI() lis=[LI() for i in range(m)] #print(lis) cou=0 for i in range(m): tree=[[] for i in range(n)] for j in range(m): if i!=j: tree[lis[j][0]-1].append(lis[j][1]-1) tree[lis[j][1]-1].append(lis[j][0]-1) count=0 for k in range(n): al=[-1]*n al[k]=0 dfs(k) #print(al) if not -1 in al: count+=1 if count!=n: cou+=1 print(cou)
51
51
1,359
1,357
# dpでできないかな? import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) from collections import Counter, deque from collections import defaultdict from itertools import combinations, permutations, accumulate, groupby, product from bisect import bisect_left, bisect_right from heapq import heapify, heappop, heappush from math import floor, ceil, pi from operator import itemgetter def I(): return int(eval(input())) def MI(): return list(map(int, input().split())) def LI(): return list(map(int, input().split())) def LI2(): return [int(eval(input())) for i in range(n)] def MXI(): return [[LI()] for i in range(n)] def SI(): return input().rstrip() def printns(x): print(("\n".join(x))) def printni(x): print(("\n".join(list(map(str, x))))) inf = 10**17 mod = 10**9 + 7 def dfs(x): for i in tree[x]: if al[i] < 0: al[i] = 0 dfs(i) n, m = MI() lis = [LI() for i in range(m)] # print(lis) cou = 0 for i in range(m): tree = [[] for i in range(n)] for j in range(m): if i != j: tree[lis[j][0] - 1].append(lis[j][1] - 1) tree[lis[j][1] - 1].append(lis[j][0] - 1) count = 0 for k in range(n): al = [-1] * n al[k] = 0 dfs(k) # print(al) if sum(al) == 0: count += 1 if count != n: cou += 1 print(cou)
# dpでできないかな? import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) from collections import Counter, deque from collections import defaultdict from itertools import combinations, permutations, accumulate, groupby, product from bisect import bisect_left, bisect_right from heapq import heapify, heappop, heappush from math import floor, ceil, pi from operator import itemgetter def I(): return int(eval(input())) def MI(): return list(map(int, input().split())) def LI(): return list(map(int, input().split())) def LI2(): return [int(eval(input())) for i in range(n)] def MXI(): return [[LI()] for i in range(n)] def SI(): return input().rstrip() def printns(x): print(("\n".join(x))) def printni(x): print(("\n".join(list(map(str, x))))) inf = 10**17 mod = 10**9 + 7 def dfs(x): for i in tree[x]: if al[i] < 0: al[i] = 0 dfs(i) n, m = MI() lis = [LI() for i in range(m)] # print(lis) cou = 0 for i in range(m): tree = [[] for i in range(n)] for j in range(m): if i != j: tree[lis[j][0] - 1].append(lis[j][1] - 1) tree[lis[j][1] - 1].append(lis[j][0] - 1) count = 0 for k in range(n): al = [-1] * n al[k] = 0 dfs(k) # print(al) if not -1 in al: count += 1 if count != n: cou += 1 print(cou)
false
0
[ "- if sum(al) == 0:", "+ if not -1 in al:" ]
false
0.048951
0.050135
0.976382
[ "s763740636", "s830377672" ]
u193453446
p02258
python
s139635397
s233601230
500
450
15,616
7,768
Accepted
Accepted
10
#!/usr/bin/env python # -*- coding: utf-8 -*- """ ?????§????????? FX????????§????????°?????????????????¨????????????????????¨??§????????????????????????????????¨?????§???????????? ????????°????????????100???????????? 1000???????????????????????????????????? 1?????? 108???????????£??????????£??????¨??? (108??? ?????? 100???) ???? 1000?????? == 8000??????????????????????????¨?????§???????????? ???????????¨????????????????????? t ?????????????????? Rt (t=0,1,2,,,n???1)??? ??\?????¨??????????????????????????§??????????????? Rj???Ri (????????????j>i ??¨??????) ????????§?????? ?±?????????????????????? """ import math # ????????? n = int(input().strip()) a = [] for i in range(n): a.append(int(input().strip())) min = a[0] cnt = -1000000000 for j in range(1,n): x = a[j] - min if cnt < x: cnt = x # print("cnt={0} min={1} Rj={2}".format(cnt,min,a[j])) if min > a[j]: min = a[j] print(cnt)
#!/usr/bin/env python # -*- coding: utf-8 -*- """ ?????§????????? FX????????§????????°?????????????????¨????????????????????¨??§????????????????????????????????¨?????§???????????? ????????°????????????100???????????? 1000???????????????????????????????????? 1?????? 108???????????£??????????£??????¨??? (108??? ?????? 100???) ???? 1000?????? == 8000??????????????????????????¨?????§???????????? ???????????¨????????????????????? t ?????????????????? Rt (t=0,1,2,,,n???1)??? ??\?????¨??????????????????????????§??????????????? Rj???Ri (????????????j>i ??¨??????) ????????§?????? ?±?????????????????????? """ import math # ????????? cnt = -1000000000 n = int(input().strip()) min = int(input().strip()) for i in range(1,n): a =int(input().strip()) x = a - min if cnt < x: cnt = x if min > a: min = a print(cnt)
30
28
956
871
#!/usr/bin/env python # -*- coding: utf-8 -*- """ ?????§????????? FX????????§????????°?????????????????¨????????????????????¨??§????????????????????????????????¨?????§???????????? ????????°????????????100???????????? 1000???????????????????????????????????? 1?????? 108???????????£??????????£??????¨??? (108??? ?????? 100???) ???? 1000?????? == 8000??????????????????????????¨?????§???????????? ???????????¨????????????????????? t ?????????????????? Rt (t=0,1,2,,,n???1)??? ??\?????¨??????????????????????????§??????????????? Rj???Ri (????????????j>i ??¨??????) ????????§?????? ?±?????????????????????? """ import math # ????????? n = int(input().strip()) a = [] for i in range(n): a.append(int(input().strip())) min = a[0] cnt = -1000000000 for j in range(1, n): x = a[j] - min if cnt < x: cnt = x # print("cnt={0} min={1} Rj={2}".format(cnt,min,a[j])) if min > a[j]: min = a[j] print(cnt)
#!/usr/bin/env python # -*- coding: utf-8 -*- """ ?????§????????? FX????????§????????°?????????????????¨????????????????????¨??§????????????????????????????????¨?????§???????????? ????????°????????????100???????????? 1000???????????????????????????????????? 1?????? 108???????????£??????????£??????¨??? (108??? ?????? 100???) ???? 1000?????? == 8000??????????????????????????¨?????§???????????? ???????????¨????????????????????? t ?????????????????? Rt (t=0,1,2,,,n???1)??? ??\?????¨??????????????????????????§??????????????? Rj???Ri (????????????j>i ??¨??????) ????????§?????? ?±?????????????????????? """ import math # ????????? cnt = -1000000000 n = int(input().strip()) min = int(input().strip()) for i in range(1, n): a = int(input().strip()) x = a - min if cnt < x: cnt = x if min > a: min = a print(cnt)
false
6.666667
[ "+cnt = -1000000000", "-a = []", "-for i in range(n):", "- a.append(int(input().strip()))", "-min = a[0]", "-cnt = -1000000000", "-for j in range(1, n):", "- x = a[j] - min", "+min = int(input().strip())", "+for i in range(1, n):", "+ a = int(input().strip())", "+ x = a - min", "- # print(\"cnt={0} min={1} Rj={2}\".format(cnt,min,a[j]))", "- if min > a[j]:", "- min = a[j]", "+ if min > a:", "+ min = a" ]
false
0.04476
0.043596
1.026713
[ "s139635397", "s233601230" ]
u729133443
p02904
python
s806557271
s750802025
808
636
106,920
121,148
Accepted
Accepted
21.29
from subprocess import* call(('pypy3','-c',""" def main(): def update(k,x): k+=N0-1 data_min[k]=data_max[k]=x while k>=0: k=(k-1)//2 a,b=data_min[2*k+1],data_min[2*k+2] data_min[k]=a if a<b else b a,b=data_max[2*k+1],data_max[2*k+2] data_max[k]=a if a>b else b def query_min(l,r): L,R=l+N0,r+N0 s=INF while L<R: if R&1: R-=1 t=data_min[R-1] if t<s:s=t if L&1: t=data_min[L-1] if t<s:s=t L+=1 L//=2 R//=2 return s def query_max(l,r): L,R=l+N0,r+N0 s=0 while L<R: if R&1: R-=1 t=data_max[R-1] if t>s:s=t if L&1: t=data_max[L-1] if t>s:s=t L+=1 L//=2 R//=2 return s n,k,*p=map(int,open(0).read().split()) N0=2**(n-1).bit_length() INF=10**18 data_min=[INF]*2*N0 data_max=[0]*2*N0 c=[0] for a,b in zip(p,p[1:]):c+=c[-1]+(a<b), *c,f=[b-a==k-1for a,b in zip(c,c[k-1:])] x=not f for i,q in enumerate(p):update(i,q) for i,(a,b,c)in enumerate(zip(p,p[k:],c)): f|=c if not c and(a!=query_min(i,i+k)or b!=query_max(i+1,i+k+1)):x+=1 print(x+f) main() """))
class SWAG(): def __init__(self,unit,f): self.fold_r=[unit] self.fold_l=[unit] self.data_r=[] self.data_l=[] self.f=f def __refill_right(self): temp=[] n=len(self.data_l) for _ in range(n//2): temp.append(self.popleft()) for _ in range(n//2,n): self.append(self.popleft()) for t in temp[::-1]: self.appendleft(t) def __refill_left(self): temp=[] n=len(self.data_r) for _ in range(n//2): temp.append(self.pop()) for _ in range(n//2,n): self.appendleft(self.pop()) for t in temp[::-1]: self.append(t) def append(self,x): self.fold_r.append(self.f(self.fold_r[-1],x)) self.data_r.append(x) def appendleft(self,x): self.fold_l.append(self.f(self.fold_l[-1],x)) self.data_l.append(x) def pop(self): if not self.data_r: self.__refill_right() self.fold_r.pop() return self.data_r.pop() def popleft(self): if not self.data_l: self.__refill_left() self.fold_l.pop() return self.data_l.pop() def fold_all(self): return self.f(self.fold_r[-1],self.fold_l[-1]) n,k,*p=list(map(int,open(0).read().split())) c=[0] for a,b in zip(p,p[1:]):c+=c[-1]+(a<b), *c,f=[b-a==k-1for a,b in zip(c,c[k-1:])] x=not f s_min=SWAG(10**18,min) s_max=SWAG(0,max) *_,=list(map(s_min.append,p[:k-1])) *_,=list(map(s_max.append,p[1:k])) for i,(a,b,c)in enumerate(zip(p,p[k:],c)): f|=c s_min.append(p[i+k-1]) s_max.append(b) if not c and(a!=s_min.fold_all()or b!=s_max.fold_all()):x+=1 s_min.popleft() s_max.popleft() print((x+f))
58
60
1,256
1,792
from subprocess import * call( ( "pypy3", "-c", """ def main(): def update(k,x): k+=N0-1 data_min[k]=data_max[k]=x while k>=0: k=(k-1)//2 a,b=data_min[2*k+1],data_min[2*k+2] data_min[k]=a if a<b else b a,b=data_max[2*k+1],data_max[2*k+2] data_max[k]=a if a>b else b def query_min(l,r): L,R=l+N0,r+N0 s=INF while L<R: if R&1: R-=1 t=data_min[R-1] if t<s:s=t if L&1: t=data_min[L-1] if t<s:s=t L+=1 L//=2 R//=2 return s def query_max(l,r): L,R=l+N0,r+N0 s=0 while L<R: if R&1: R-=1 t=data_max[R-1] if t>s:s=t if L&1: t=data_max[L-1] if t>s:s=t L+=1 L//=2 R//=2 return s n,k,*p=map(int,open(0).read().split()) N0=2**(n-1).bit_length() INF=10**18 data_min=[INF]*2*N0 data_max=[0]*2*N0 c=[0] for a,b in zip(p,p[1:]):c+=c[-1]+(a<b), *c,f=[b-a==k-1for a,b in zip(c,c[k-1:])] x=not f for i,q in enumerate(p):update(i,q) for i,(a,b,c)in enumerate(zip(p,p[k:],c)): f|=c if not c and(a!=query_min(i,i+k)or b!=query_max(i+1,i+k+1)):x+=1 print(x+f) main() """, ) )
class SWAG: def __init__(self, unit, f): self.fold_r = [unit] self.fold_l = [unit] self.data_r = [] self.data_l = [] self.f = f def __refill_right(self): temp = [] n = len(self.data_l) for _ in range(n // 2): temp.append(self.popleft()) for _ in range(n // 2, n): self.append(self.popleft()) for t in temp[::-1]: self.appendleft(t) def __refill_left(self): temp = [] n = len(self.data_r) for _ in range(n // 2): temp.append(self.pop()) for _ in range(n // 2, n): self.appendleft(self.pop()) for t in temp[::-1]: self.append(t) def append(self, x): self.fold_r.append(self.f(self.fold_r[-1], x)) self.data_r.append(x) def appendleft(self, x): self.fold_l.append(self.f(self.fold_l[-1], x)) self.data_l.append(x) def pop(self): if not self.data_r: self.__refill_right() self.fold_r.pop() return self.data_r.pop() def popleft(self): if not self.data_l: self.__refill_left() self.fold_l.pop() return self.data_l.pop() def fold_all(self): return self.f(self.fold_r[-1], self.fold_l[-1]) n, k, *p = list(map(int, open(0).read().split())) c = [0] for a, b in zip(p, p[1:]): c += (c[-1] + (a < b),) *c, f = [b - a == k - 1 for a, b in zip(c, c[k - 1 :])] x = not f s_min = SWAG(10**18, min) s_max = SWAG(0, max) (*_,) = list(map(s_min.append, p[: k - 1])) (*_,) = list(map(s_max.append, p[1:k])) for i, (a, b, c) in enumerate(zip(p, p[k:], c)): f |= c s_min.append(p[i + k - 1]) s_max.append(b) if not c and (a != s_min.fold_all() or b != s_max.fold_all()): x += 1 s_min.popleft() s_max.popleft() print((x + f))
false
3.333333
[ "-from subprocess import *", "+class SWAG:", "+ def __init__(self, unit, f):", "+ self.fold_r = [unit]", "+ self.fold_l = [unit]", "+ self.data_r = []", "+ self.data_l = []", "+ self.f = f", "-call(", "- (", "- \"pypy3\",", "- \"-c\",", "- \"\"\"", "-def main():", "- def update(k,x):", "- k+=N0-1", "- data_min[k]=data_max[k]=x", "- while k>=0:", "- k=(k-1)//2", "- a,b=data_min[2*k+1],data_min[2*k+2]", "- data_min[k]=a if a<b else b", "- a,b=data_max[2*k+1],data_max[2*k+2]", "- data_max[k]=a if a>b else b", "- def query_min(l,r):", "- L,R=l+N0,r+N0", "- s=INF", "- while L<R:", "- if R&1:", "- R-=1", "- t=data_min[R-1]", "- if t<s:s=t", "- if L&1:", "- t=data_min[L-1]", "- if t<s:s=t", "- L+=1", "- L//=2", "- R//=2", "- return s", "- def query_max(l,r):", "- L,R=l+N0,r+N0", "- s=0", "- while L<R:", "- if R&1:", "- R-=1", "- t=data_max[R-1]", "- if t>s:s=t", "- if L&1:", "- t=data_max[L-1]", "- if t>s:s=t", "- L+=1", "- L//=2", "- R//=2", "- return s", "- n,k,*p=map(int,open(0).read().split())", "- N0=2**(n-1).bit_length()", "- INF=10**18", "- data_min=[INF]*2*N0", "- data_max=[0]*2*N0", "- c=[0]", "- for a,b in zip(p,p[1:]):c+=c[-1]+(a<b),", "- *c,f=[b-a==k-1for a,b in zip(c,c[k-1:])]", "- x=not f", "- for i,q in enumerate(p):update(i,q)", "- for i,(a,b,c)in enumerate(zip(p,p[k:],c)):", "- f|=c", "- if not c and(a!=query_min(i,i+k)or b!=query_max(i+1,i+k+1)):x+=1", "- print(x+f)", "-main()", "-\"\"\",", "- )", "-)", "+ def __refill_right(self):", "+ temp = []", "+ n = len(self.data_l)", "+ for _ in range(n // 2):", "+ temp.append(self.popleft())", "+ for _ in range(n // 2, n):", "+ self.append(self.popleft())", "+ for t in temp[::-1]:", "+ self.appendleft(t)", "+", "+ def __refill_left(self):", "+ temp = []", "+ n = len(self.data_r)", "+ for _ in range(n // 2):", "+ temp.append(self.pop())", "+ for _ in range(n // 2, n):", "+ self.appendleft(self.pop())", "+ for t in temp[::-1]:", "+ self.append(t)", "+", "+ def append(self, x):", "+ self.fold_r.append(self.f(self.fold_r[-1], x))", "+ self.data_r.append(x)", "+", "+ def appendleft(self, x):", "+ self.fold_l.append(self.f(self.fold_l[-1], x))", "+ self.data_l.append(x)", "+", "+ def pop(self):", "+ if not self.data_r:", "+ self.__refill_right()", "+ self.fold_r.pop()", "+ return self.data_r.pop()", "+", "+ def popleft(self):", "+ if not self.data_l:", "+ self.__refill_left()", "+ self.fold_l.pop()", "+ return self.data_l.pop()", "+", "+ def fold_all(self):", "+ return self.f(self.fold_r[-1], self.fold_l[-1])", "+", "+", "+n, k, *p = list(map(int, open(0).read().split()))", "+c = [0]", "+for a, b in zip(p, p[1:]):", "+ c += (c[-1] + (a < b),)", "+*c, f = [b - a == k - 1 for a, b in zip(c, c[k - 1 :])]", "+x = not f", "+s_min = SWAG(10**18, min)", "+s_max = SWAG(0, max)", "+(*_,) = list(map(s_min.append, p[: k - 1]))", "+(*_,) = list(map(s_max.append, p[1:k]))", "+for i, (a, b, c) in enumerate(zip(p, p[k:], c)):", "+ f |= c", "+ s_min.append(p[i + k - 1])", "+ s_max.append(b)", "+ if not c and (a != s_min.fold_all() or b != s_max.fold_all()):", "+ x += 1", "+ s_min.popleft()", "+ s_max.popleft()", "+print((x + f))" ]
false
0.062182
0.048088
1.293081
[ "s806557271", "s750802025" ]
u219417113
p03162
python
s650932856
s717767029
658
392
74,584
70,492
Accepted
Accepted
40.43
n = int(eval(input())) abc = [tuple(map(int, input().split())) for _ in range(n)] dp = [[0] * 3 for _ in range(n)] dp[0][0] = abc[0][0] dp[0][1] = abc[0][1] dp[0][2] = abc[0][2] for i in range(1, n): for j in range(3): for k in range(3): if j != k: dp[i][j] = max(dp[i][j], dp[i-1][k] + abc[i][j]) print((max(dp[n-1])))
import sys input = sys.stdin.readline def main(): N = int(eval(input())) abc = [tuple(map(int, input().split())) for _ in range(N)] dp = [[0] * 3 for _ in range(N+1)] for i in range(3): dp[0][i] = 0 for i in range(1, N+1): for today in range(3): for yesterday in range(3): if today == yesterday: continue dp[i][today] = max(dp[i][today], dp[i-1][yesterday] + abc[i-1][today]) ans = 0 for i in range(3): ans = max(ans, dp[N][i]) print(ans) if __name__ == '__main__': main()
15
21
369
611
n = int(eval(input())) abc = [tuple(map(int, input().split())) for _ in range(n)] dp = [[0] * 3 for _ in range(n)] dp[0][0] = abc[0][0] dp[0][1] = abc[0][1] dp[0][2] = abc[0][2] for i in range(1, n): for j in range(3): for k in range(3): if j != k: dp[i][j] = max(dp[i][j], dp[i - 1][k] + abc[i][j]) print((max(dp[n - 1])))
import sys input = sys.stdin.readline def main(): N = int(eval(input())) abc = [tuple(map(int, input().split())) for _ in range(N)] dp = [[0] * 3 for _ in range(N + 1)] for i in range(3): dp[0][i] = 0 for i in range(1, N + 1): for today in range(3): for yesterday in range(3): if today == yesterday: continue dp[i][today] = max( dp[i][today], dp[i - 1][yesterday] + abc[i - 1][today] ) ans = 0 for i in range(3): ans = max(ans, dp[N][i]) print(ans) if __name__ == "__main__": main()
false
28.571429
[ "-n = int(eval(input()))", "-abc = [tuple(map(int, input().split())) for _ in range(n)]", "-dp = [[0] * 3 for _ in range(n)]", "-dp[0][0] = abc[0][0]", "-dp[0][1] = abc[0][1]", "-dp[0][2] = abc[0][2]", "-for i in range(1, n):", "- for j in range(3):", "- for k in range(3):", "- if j != k:", "- dp[i][j] = max(dp[i][j], dp[i - 1][k] + abc[i][j])", "-print((max(dp[n - 1])))", "+import sys", "+", "+input = sys.stdin.readline", "+", "+", "+def main():", "+ N = int(eval(input()))", "+ abc = [tuple(map(int, input().split())) for _ in range(N)]", "+ dp = [[0] * 3 for _ in range(N + 1)]", "+ for i in range(3):", "+ dp[0][i] = 0", "+ for i in range(1, N + 1):", "+ for today in range(3):", "+ for yesterday in range(3):", "+ if today == yesterday:", "+ continue", "+ dp[i][today] = max(", "+ dp[i][today], dp[i - 1][yesterday] + abc[i - 1][today]", "+ )", "+ ans = 0", "+ for i in range(3):", "+ ans = max(ans, dp[N][i])", "+ print(ans)", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.077162
0.077225
0.999191
[ "s650932856", "s717767029" ]
u197300773
p02937
python
s846467922
s217805027
306
277
74,256
75,868
Accepted
Accepted
9.48
import sys s=eval(input()) t=eval(input()) l=len(s) d={} for i in range(26): d[chr(ord("a")+i)]=i ref=[[] for _ in range(26)] for i in range(l): ref[d[s[i]]].append(i) for i in range(26): if ref[i]==[]: ref[i].append(-1) tmp=[0 for i in range(26)] next=[[-1]*26 for i in range(l)] for i in range(l): x=d[s[i]] tmp[x]=(tmp[x]+1)%len(ref[x]) for j in range(26): next[i][j]=ref[j][tmp[j]] p=s.find(t[0]) ans=p if p==-1: print((-1));sys.exit() for i in range(1,len(t)): x=d[t[i]] q=next[p][x] if q==-1: print((-1));sys.exit() ans+=-p+q if p>=q: ans+=l p=q print((ans+1))
import sys s=eval(input()) ss=s+s t=eval(input()) l=len(s) d={} for i in range(26): d[chr(ord("a")+i)]=i ref=[[] for _ in range(26)] for i in range(2*l): ref[d[ss[i]]].append(i) for i in range(26): if ref[i]==[]: ref[i].append(-1) tmp=[0 for i in range(26)] next=[[-1]*26 for i in range(l)] for i in range(l): tmp[d[s[i]]]+=1 for j in range(26): next[i][j]=ref[j][tmp[j]] p=s.find(t[0]) if p==-1: print((-1));sys.exit() ans=p for i in range(1,len(t)): x=d[t[i]] q=next[p][x] if q==-1: print((-1));sys.exit() ans+=-p+q p=q%l print((ans+1))
34
33
641
604
import sys s = eval(input()) t = eval(input()) l = len(s) d = {} for i in range(26): d[chr(ord("a") + i)] = i ref = [[] for _ in range(26)] for i in range(l): ref[d[s[i]]].append(i) for i in range(26): if ref[i] == []: ref[i].append(-1) tmp = [0 for i in range(26)] next = [[-1] * 26 for i in range(l)] for i in range(l): x = d[s[i]] tmp[x] = (tmp[x] + 1) % len(ref[x]) for j in range(26): next[i][j] = ref[j][tmp[j]] p = s.find(t[0]) ans = p if p == -1: print((-1)) sys.exit() for i in range(1, len(t)): x = d[t[i]] q = next[p][x] if q == -1: print((-1)) sys.exit() ans += -p + q if p >= q: ans += l p = q print((ans + 1))
import sys s = eval(input()) ss = s + s t = eval(input()) l = len(s) d = {} for i in range(26): d[chr(ord("a") + i)] = i ref = [[] for _ in range(26)] for i in range(2 * l): ref[d[ss[i]]].append(i) for i in range(26): if ref[i] == []: ref[i].append(-1) tmp = [0 for i in range(26)] next = [[-1] * 26 for i in range(l)] for i in range(l): tmp[d[s[i]]] += 1 for j in range(26): next[i][j] = ref[j][tmp[j]] p = s.find(t[0]) if p == -1: print((-1)) sys.exit() ans = p for i in range(1, len(t)): x = d[t[i]] q = next[p][x] if q == -1: print((-1)) sys.exit() ans += -p + q p = q % l print((ans + 1))
false
2.941176
[ "+ss = s + s", "-for i in range(l):", "- ref[d[s[i]]].append(i)", "+for i in range(2 * l):", "+ ref[d[ss[i]]].append(i)", "- x = d[s[i]]", "- tmp[x] = (tmp[x] + 1) % len(ref[x])", "+ tmp[d[s[i]]] += 1", "-ans = p", "+ans = p", "- if p >= q:", "- ans += l", "- p = q", "+ p = q % l" ]
false
0.047062
0.047826
0.98402
[ "s846467922", "s217805027" ]
u498487134
p02813
python
s154697956
s188031490
216
88
42,096
73,760
Accepted
Accepted
59.26
import itertools N=int(eval(input())) P = list(map(int, input().split())) Q = list(map(int, input().split())) a=0 b=0 index=0 for i in itertools.permutations(list(range(1,N+1)), N): if P==list(i): a=index if Q==list(i): b=index index+=1 print((abs(b-a)))
import sys input = sys.stdin.readline def I(): return int(eval(input())) def MI(): return list(map(int, input().split())) def LI(): return list(map(int, input().split())) def main(): mod=10**9+7 N=I() P=LI() Q=LI() import itertools cnt=0 p=0 q=0 for ite in itertools.permutations(list(range(1,N+1))): if P==list(ite): p=cnt if Q==list(ite): q=cnt cnt+=1 print((abs(p-q))) main()
16
30
288
524
import itertools N = int(eval(input())) P = list(map(int, input().split())) Q = list(map(int, input().split())) a = 0 b = 0 index = 0 for i in itertools.permutations(list(range(1, N + 1)), N): if P == list(i): a = index if Q == list(i): b = index index += 1 print((abs(b - a)))
import sys input = sys.stdin.readline def I(): return int(eval(input())) def MI(): return list(map(int, input().split())) def LI(): return list(map(int, input().split())) def main(): mod = 10**9 + 7 N = I() P = LI() Q = LI() import itertools cnt = 0 p = 0 q = 0 for ite in itertools.permutations(list(range(1, N + 1))): if P == list(ite): p = cnt if Q == list(ite): q = cnt cnt += 1 print((abs(p - q))) main()
false
46.666667
[ "-import itertools", "+import sys", "-N = int(eval(input()))", "-P = list(map(int, input().split()))", "-Q = list(map(int, input().split()))", "-a = 0", "-b = 0", "-index = 0", "-for i in itertools.permutations(list(range(1, N + 1)), N):", "- if P == list(i):", "- a = index", "- if Q == list(i):", "- b = index", "- index += 1", "-print((abs(b - a)))", "+input = sys.stdin.readline", "+", "+", "+def I():", "+ return int(eval(input()))", "+", "+", "+def MI():", "+ return list(map(int, input().split()))", "+", "+", "+def LI():", "+ return list(map(int, input().split()))", "+", "+", "+def main():", "+ mod = 10**9 + 7", "+ N = I()", "+ P = LI()", "+ Q = LI()", "+ import itertools", "+", "+ cnt = 0", "+ p = 0", "+ q = 0", "+ for ite in itertools.permutations(list(range(1, N + 1))):", "+ if P == list(ite):", "+ p = cnt", "+ if Q == list(ite):", "+ q = cnt", "+ cnt += 1", "+ print((abs(p - q)))", "+", "+", "+main()" ]
false
0.006934
0.037174
0.186535
[ "s154697956", "s188031490" ]
u167681750
p03457
python
s953188687
s386757761
404
327
28,068
3,060
Accepted
Accepted
19.06
n = int(eval(input())) txy = [[int(0)] * 3] txy += ([list(map(int, input().split())) for i in range(n)]) for i in range(n): t_diff = txy[i+1][0] - txy[i][0] xy_diff = (txy[i+1][1] + txy[i+1][2]) - (txy[i][1] + txy[i][2]) if t_diff % 2 != xy_diff % 2 or xy_diff > t_diff: print("No") exit() print("Yes")
n = int(eval(input())) for i in range(n): t, x, y = list(map(int, input().split())) if (t + x + y) % 2 == 1 or (x + y) > t: print("No") exit() print("Yes")
13
9
339
177
n = int(eval(input())) txy = [[int(0)] * 3] txy += [list(map(int, input().split())) for i in range(n)] for i in range(n): t_diff = txy[i + 1][0] - txy[i][0] xy_diff = (txy[i + 1][1] + txy[i + 1][2]) - (txy[i][1] + txy[i][2]) if t_diff % 2 != xy_diff % 2 or xy_diff > t_diff: print("No") exit() print("Yes")
n = int(eval(input())) for i in range(n): t, x, y = list(map(int, input().split())) if (t + x + y) % 2 == 1 or (x + y) > t: print("No") exit() print("Yes")
false
30.769231
[ "-txy = [[int(0)] * 3]", "-txy += [list(map(int, input().split())) for i in range(n)]", "- t_diff = txy[i + 1][0] - txy[i][0]", "- xy_diff = (txy[i + 1][1] + txy[i + 1][2]) - (txy[i][1] + txy[i][2])", "- if t_diff % 2 != xy_diff % 2 or xy_diff > t_diff:", "+ t, x, y = list(map(int, input().split()))", "+ if (t + x + y) % 2 == 1 or (x + y) > t:" ]
false
0.037126
0.039069
0.95027
[ "s953188687", "s386757761" ]
u896741788
p03160
python
s233159937
s567629006
205
127
13,928
14,696
Accepted
Accepted
38.05
n=int(eval(input())) l=list(map(int,input().split())) dp=[float("INF")]*n dp[0]=0;dp[1]=abs(l[0]-l[1]) for i in range(2,n): for j in range(1,3): dp[i]=min(dp[i-j]+abs(l[i]-l[i-j]),dp[i]) print((dp[-1]))
n=int(eval(input())) dp=[10**4*n]*n l=list(map(int,input().split())) dp[0]=0 dp[1]=abs(l[0]-l[1]) for i in range(2,n): dp[i]=min(dp[i-1]+abs(l[i]-l[i-1]),dp[i-2]+abs(l[i]-l[i-2])) print((dp[-1]))
8
8
208
196
n = int(eval(input())) l = list(map(int, input().split())) dp = [float("INF")] * n dp[0] = 0 dp[1] = abs(l[0] - l[1]) for i in range(2, n): for j in range(1, 3): dp[i] = min(dp[i - j] + abs(l[i] - l[i - j]), dp[i]) print((dp[-1]))
n = int(eval(input())) dp = [10**4 * n] * n l = list(map(int, input().split())) dp[0] = 0 dp[1] = abs(l[0] - l[1]) for i in range(2, n): dp[i] = min(dp[i - 1] + abs(l[i] - l[i - 1]), dp[i - 2] + abs(l[i] - l[i - 2])) print((dp[-1]))
false
0
[ "+dp = [10**4 * n] * n", "-dp = [float(\"INF\")] * n", "- for j in range(1, 3):", "- dp[i] = min(dp[i - j] + abs(l[i] - l[i - j]), dp[i])", "+ dp[i] = min(dp[i - 1] + abs(l[i] - l[i - 1]), dp[i - 2] + abs(l[i] - l[i - 2]))" ]
false
0.036413
0.039851
0.913751
[ "s233159937", "s567629006" ]
u347640436
p03806
python
s495004056
s183857440
1,048
894
4,844
4,844
Accepted
Accepted
14.69
INF = float('inf') MAXAB = 10 n, ma, mb = list(map(int, input().split())) t = [[INF] * (n * MAXAB + 1) for _ in range(n * MAXAB + 1)] t[0][0] = 0 for _ in range(n): a, b, c = list(map(int, input().split())) for aa in range(n * MAXAB, -1, -1): for bb in range(n * MAXAB, -1, -1): if t[aa][bb] == INF: continue if t[a + aa][b + bb] > t[aa][bb] + c: t[a + aa][b + bb] = t[aa][bb] + c result = INF for a in range(1, n * MAXAB + 1): for b in range(1, n * MAXAB + 1): if a * mb == b * ma and result > t[a][b]: result = t[a][b] if result == INF: result = -1 print(result)
INF = float('inf') n, ma, mb = list(map(int, input().split())) ccmax = n * 10 t = [[INF] * (ccmax + 1) for _ in range(ccmax + 1)] for _ in range(n): a, b, c = list(map(int, input().split())) for aa in range(ccmax, 0, -1): taa = t[aa] for bb in range(ccmax, 0, -1): if taa[bb] == INF: continue if t[a + aa][b + bb] > c + taa[bb]: t[a + aa][b + bb] = c + taa[bb] if t[a][b] > c: t[a][b] = c result = INF for a in range(1, ccmax): ta = t[a] for b in range(1, ccmax): if a * mb == b * ma and ta[b] < result: result = ta[b] if result == INF: result = -1 print(result)
21
24
623
636
INF = float("inf") MAXAB = 10 n, ma, mb = list(map(int, input().split())) t = [[INF] * (n * MAXAB + 1) for _ in range(n * MAXAB + 1)] t[0][0] = 0 for _ in range(n): a, b, c = list(map(int, input().split())) for aa in range(n * MAXAB, -1, -1): for bb in range(n * MAXAB, -1, -1): if t[aa][bb] == INF: continue if t[a + aa][b + bb] > t[aa][bb] + c: t[a + aa][b + bb] = t[aa][bb] + c result = INF for a in range(1, n * MAXAB + 1): for b in range(1, n * MAXAB + 1): if a * mb == b * ma and result > t[a][b]: result = t[a][b] if result == INF: result = -1 print(result)
INF = float("inf") n, ma, mb = list(map(int, input().split())) ccmax = n * 10 t = [[INF] * (ccmax + 1) for _ in range(ccmax + 1)] for _ in range(n): a, b, c = list(map(int, input().split())) for aa in range(ccmax, 0, -1): taa = t[aa] for bb in range(ccmax, 0, -1): if taa[bb] == INF: continue if t[a + aa][b + bb] > c + taa[bb]: t[a + aa][b + bb] = c + taa[bb] if t[a][b] > c: t[a][b] = c result = INF for a in range(1, ccmax): ta = t[a] for b in range(1, ccmax): if a * mb == b * ma and ta[b] < result: result = ta[b] if result == INF: result = -1 print(result)
false
12.5
[ "-MAXAB = 10", "-t = [[INF] * (n * MAXAB + 1) for _ in range(n * MAXAB + 1)]", "-t[0][0] = 0", "+ccmax = n * 10", "+t = [[INF] * (ccmax + 1) for _ in range(ccmax + 1)]", "- for aa in range(n * MAXAB, -1, -1):", "- for bb in range(n * MAXAB, -1, -1):", "- if t[aa][bb] == INF:", "+ for aa in range(ccmax, 0, -1):", "+ taa = t[aa]", "+ for bb in range(ccmax, 0, -1):", "+ if taa[bb] == INF:", "- if t[a + aa][b + bb] > t[aa][bb] + c:", "- t[a + aa][b + bb] = t[aa][bb] + c", "+ if t[a + aa][b + bb] > c + taa[bb]:", "+ t[a + aa][b + bb] = c + taa[bb]", "+ if t[a][b] > c:", "+ t[a][b] = c", "-for a in range(1, n * MAXAB + 1):", "- for b in range(1, n * MAXAB + 1):", "- if a * mb == b * ma and result > t[a][b]:", "- result = t[a][b]", "+for a in range(1, ccmax):", "+ ta = t[a]", "+ for b in range(1, ccmax):", "+ if a * mb == b * ma and ta[b] < result:", "+ result = ta[b]" ]
false
0.008026
0.039397
0.203718
[ "s495004056", "s183857440" ]
u320567105
p03147
python
s449297436
s445455698
22
18
3,064
3,060
Accepted
Accepted
18.18
ri = lambda: int(eval(input())) rl = lambda: list(map(int,input().split())) N = ri() h = rl() hl = len(h) ans = 0 flag = 0 for _ in range(sum(h)): if sum(h) == 0: break flag = 1 for i in range(hl): if flag == 1 and h[i] != 0: flag = 0 h[i] = h[i] - 1 ans += 1 elif flag == 0 and h[i] == 0: flag = 1 elif flag == 0 and h[i] != 0: h[i] = h[i] - 1 print(ans)
ri = lambda: int(eval(input())) rl = lambda: list(map(int,input().split())) N = ri() h = rl() ans = 0 pre = 0 for i in h: if pre < i: ans += i - pre pre = i print(ans)
24
14
480
193
ri = lambda: int(eval(input())) rl = lambda: list(map(int, input().split())) N = ri() h = rl() hl = len(h) ans = 0 flag = 0 for _ in range(sum(h)): if sum(h) == 0: break flag = 1 for i in range(hl): if flag == 1 and h[i] != 0: flag = 0 h[i] = h[i] - 1 ans += 1 elif flag == 0 and h[i] == 0: flag = 1 elif flag == 0 and h[i] != 0: h[i] = h[i] - 1 print(ans)
ri = lambda: int(eval(input())) rl = lambda: list(map(int, input().split())) N = ri() h = rl() ans = 0 pre = 0 for i in h: if pre < i: ans += i - pre pre = i print(ans)
false
41.666667
[ "-hl = len(h)", "-flag = 0", "-for _ in range(sum(h)):", "- if sum(h) == 0:", "- break", "- flag = 1", "- for i in range(hl):", "- if flag == 1 and h[i] != 0:", "- flag = 0", "- h[i] = h[i] - 1", "- ans += 1", "- elif flag == 0 and h[i] == 0:", "- flag = 1", "- elif flag == 0 and h[i] != 0:", "- h[i] = h[i] - 1", "+pre = 0", "+for i in h:", "+ if pre < i:", "+ ans += i - pre", "+ pre = i" ]
false
0.041641
0.040232
1.035031
[ "s449297436", "s445455698" ]
u505830998
p03324
python
s673342733
s600578579
12
10
2,820
2,568
Accepted
Accepted
16.67
# -*- coding: utf-8 -*- # スペース区切りの整数の入力 D, N = list(map(int, input().split())) l=[(100**D)*x for x in range(2*N) if (100**D)*x % (100**(D+1)) != 0] print(l[N-1])
# -*- coding: utf-8 -*- # スペース区切りの整数の入力 D,N = list(map(int, input().split())) print((100**D)*(N + (1 if N==100 else 0)))
6
4
165
121
# -*- coding: utf-8 -*- # スペース区切りの整数の入力 D, N = list(map(int, input().split())) l = [(100**D) * x for x in range(2 * N) if (100**D) * x % (100 ** (D + 1)) != 0] print(l[N - 1])
# -*- coding: utf-8 -*- # スペース区切りの整数の入力 D, N = list(map(int, input().split())) print((100**D) * (N + (1 if N == 100 else 0)))
false
33.333333
[ "-l = [(100**D) * x for x in range(2 * N) if (100**D) * x % (100 ** (D + 1)) != 0]", "-print(l[N - 1])", "+print((100**D) * (N + (1 if N == 100 else 0)))" ]
false
0.046027
0.243239
0.189227
[ "s673342733", "s600578579" ]
u624475441
p03163
python
s228337655
s893711826
317
176
19,352
14,456
Accepted
Accepted
44.48
import sys import numpy as np N, W = list(map(int, input().split())) it = iter(map(int, sys.stdin.read().split())) dp = np.zeros(W + 1, dtype=int) for w, v in zip(it, it): np.maximum(dp[:-w] + v, dp[w:], out=dp[w:]) print((dp[-1]))
import sys import numpy as np N, W = list(map(int, input().split())) it = iter(map(int, sys.stdin.read().split())) dp = np.zeros(W + 1, dtype=np.int64) for w, v in zip(it, it): np.maximum(dp[:-w] + v, dp[w:], out=dp[w:]) print((dp[-1]))
8
8
234
239
import sys import numpy as np N, W = list(map(int, input().split())) it = iter(map(int, sys.stdin.read().split())) dp = np.zeros(W + 1, dtype=int) for w, v in zip(it, it): np.maximum(dp[:-w] + v, dp[w:], out=dp[w:]) print((dp[-1]))
import sys import numpy as np N, W = list(map(int, input().split())) it = iter(map(int, sys.stdin.read().split())) dp = np.zeros(W + 1, dtype=np.int64) for w, v in zip(it, it): np.maximum(dp[:-w] + v, dp[w:], out=dp[w:]) print((dp[-1]))
false
0
[ "-dp = np.zeros(W + 1, dtype=int)", "+dp = np.zeros(W + 1, dtype=np.int64)" ]
false
0.468104
0.454001
1.031063
[ "s228337655", "s893711826" ]
u729972685
p03165
python
s478275331
s786891851
1,564
441
883,336
112,220
Accepted
Accepted
71.8
""" https://atcoder.jp/contests/dp/tasks/dp_f """ from collections import defaultdict s = eval(input()) t = eval(input()) ls = len(s) lt = len(t) dp = [[0] * (lt + 1) for _ in range(ls + 1)] pre = defaultdict(lambda: defaultdict(tuple)) for i in range(ls): for j in range(lt): if s[i] == t[j]: dp[i + 1][j + 1] = 1 + dp[i][j] pre[i + 1][j + 1] = (i, j) else: if dp[i + 1][j] >= dp[i][j + 1]: dp[i + 1][j + 1] = dp[i + 1][j] pre[i + 1][j + 1] = pre[i + 1][j] else: dp[i + 1][j + 1] = dp[i][j + 1] pre[i + 1][j + 1] = pre[i][j + 1] # print(dp[ls][lt]) ans = '' y = ls x = lt while pre[y][x]: ny, nx = pre[y][x] ans = s[ny] + ans y = ny x = nx print(ans)
""" https://atcoder.jp/contests/dp/tasks/dp_f """ from collections import defaultdict s = eval(input()) t = eval(input()) ls = len(s) lt = len(t) dp = [[0] * (lt + 1) for _ in range(ls + 1)] for i in range(ls): for j in range(lt): if s[i] == t[j]: dp[i + 1][j + 1] = 1 + dp[i][j] else: dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]) # print(dp[ls][lt]) N = dp[ls][lt] y = ls x = lt ans = '' while N: if dp[y][x] == dp[y - 1][x]: y -= 1 continue if dp[y][x] == dp[y][x - 1]: x -= 1 continue else: ans = s[y - 1] + ans N -= 1 x -= 1 y -= 1 print(ans)
39
35
833
697
""" https://atcoder.jp/contests/dp/tasks/dp_f """ from collections import defaultdict s = eval(input()) t = eval(input()) ls = len(s) lt = len(t) dp = [[0] * (lt + 1) for _ in range(ls + 1)] pre = defaultdict(lambda: defaultdict(tuple)) for i in range(ls): for j in range(lt): if s[i] == t[j]: dp[i + 1][j + 1] = 1 + dp[i][j] pre[i + 1][j + 1] = (i, j) else: if dp[i + 1][j] >= dp[i][j + 1]: dp[i + 1][j + 1] = dp[i + 1][j] pre[i + 1][j + 1] = pre[i + 1][j] else: dp[i + 1][j + 1] = dp[i][j + 1] pre[i + 1][j + 1] = pre[i][j + 1] # print(dp[ls][lt]) ans = "" y = ls x = lt while pre[y][x]: ny, nx = pre[y][x] ans = s[ny] + ans y = ny x = nx print(ans)
""" https://atcoder.jp/contests/dp/tasks/dp_f """ from collections import defaultdict s = eval(input()) t = eval(input()) ls = len(s) lt = len(t) dp = [[0] * (lt + 1) for _ in range(ls + 1)] for i in range(ls): for j in range(lt): if s[i] == t[j]: dp[i + 1][j + 1] = 1 + dp[i][j] else: dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]) # print(dp[ls][lt]) N = dp[ls][lt] y = ls x = lt ans = "" while N: if dp[y][x] == dp[y - 1][x]: y -= 1 continue if dp[y][x] == dp[y][x - 1]: x -= 1 continue else: ans = s[y - 1] + ans N -= 1 x -= 1 y -= 1 print(ans)
false
10.25641
[ "-pre = defaultdict(lambda: defaultdict(tuple))", "- pre[i + 1][j + 1] = (i, j)", "- if dp[i + 1][j] >= dp[i][j + 1]:", "- dp[i + 1][j + 1] = dp[i + 1][j]", "- pre[i + 1][j + 1] = pre[i + 1][j]", "- else:", "- dp[i + 1][j + 1] = dp[i][j + 1]", "- pre[i + 1][j + 1] = pre[i][j + 1]", "+ dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1])", "-ans = \"\"", "+N = dp[ls][lt]", "-while pre[y][x]:", "- ny, nx = pre[y][x]", "- ans = s[ny] + ans", "- y = ny", "- x = nx", "+ans = \"\"", "+while N:", "+ if dp[y][x] == dp[y - 1][x]:", "+ y -= 1", "+ continue", "+ if dp[y][x] == dp[y][x - 1]:", "+ x -= 1", "+ continue", "+ else:", "+ ans = s[y - 1] + ans", "+ N -= 1", "+ x -= 1", "+ y -= 1" ]
false
0.055035
0.035376
1.555714
[ "s478275331", "s786891851" ]
u659159398
p03162
python
s935385579
s739346117
707
591
48,052
32,296
Accepted
Accepted
16.41
n = int(eval(input())) happymat = [] dp = [] for _ in range(n): happymat.append(list(map(int, input().split()))) dp.append([0]*3) # dp[i][j] stores the max happiness after day i ... doing activity j on that day dp[0][0] = happymat[0][0] dp[0][1] = happymat[0][1] dp[0][2] = happymat[0][2] for i in range(1, n): for j in range(3): dp[i][j] = happymat[i][j] + max(dp[i-1][(j+1)%3], dp[i-1][(j+2)%3]) print((max(dp[n-1])))
n = int(eval(input())) happymat = [] for _ in range(n): happymat.append(list(map(int, input().split()))) # dp[j] stores the max happiness doing activity j on the current dp = [0]*3 for i in range(n): prev = dp.copy() for j in range(3): dp[j] = happymat[i][j] + max(prev[(j+1)%3], prev[(j+2)%3]) print((max(dp)))
17
14
450
339
n = int(eval(input())) happymat = [] dp = [] for _ in range(n): happymat.append(list(map(int, input().split()))) dp.append([0] * 3) # dp[i][j] stores the max happiness after day i ... doing activity j on that day dp[0][0] = happymat[0][0] dp[0][1] = happymat[0][1] dp[0][2] = happymat[0][2] for i in range(1, n): for j in range(3): dp[i][j] = happymat[i][j] + max(dp[i - 1][(j + 1) % 3], dp[i - 1][(j + 2) % 3]) print((max(dp[n - 1])))
n = int(eval(input())) happymat = [] for _ in range(n): happymat.append(list(map(int, input().split()))) # dp[j] stores the max happiness doing activity j on the current dp = [0] * 3 for i in range(n): prev = dp.copy() for j in range(3): dp[j] = happymat[i][j] + max(prev[(j + 1) % 3], prev[(j + 2) % 3]) print((max(dp)))
false
17.647059
[ "-dp = []", "- dp.append([0] * 3)", "-# dp[i][j] stores the max happiness after day i ... doing activity j on that day", "-dp[0][0] = happymat[0][0]", "-dp[0][1] = happymat[0][1]", "-dp[0][2] = happymat[0][2]", "-for i in range(1, n):", "+# dp[j] stores the max happiness doing activity j on the current", "+dp = [0] * 3", "+for i in range(n):", "+ prev = dp.copy()", "- dp[i][j] = happymat[i][j] + max(dp[i - 1][(j + 1) % 3], dp[i - 1][(j + 2) % 3])", "-print((max(dp[n - 1])))", "+ dp[j] = happymat[i][j] + max(prev[(j + 1) % 3], prev[(j + 2) % 3])", "+print((max(dp)))" ]
false
0.185939
0.044256
4.201465
[ "s935385579", "s739346117" ]
u451017206
p03128
python
s334439448
s555594210
138
91
28,120
3,388
Accepted
Accepted
34.06
N, M = list(map(int, input().split())) A = [i for i in input().split()] # dp[i] = i本使ってできる最大の数 def mx(a, b): if a is not None and b is None: return a elif a is None and b is not None: return b if len(a) != len(b): if len(a) > len(b): return a else: return b return max(a, b) # xを作るために使うマッチの本数 h = {'1':2, '2':5, '3':5, '4':4, '5':5, '6':6, '7':3, '8':7, '9':6} dp = [None] * (N + 1) dp[0] = '' for i in range(N + 1): for a in A: if i - h[a] < 0: continue if dp[i-h[a]] is None and dp[i] is None: continue try: dp[i] = mx(dp[i-h[a]] + a, dp[i]) except: continue print((dp[N]))
N, M = list(map(int, input().split())) A = sorted([int(i) for i in input().split()], reverse=True) # xを作るために使うマッチの本数 h = {1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6} # dp[i] = i 本のマッチ棒を使って、条件を満たす整数を作るときの最大桁数 dp = [-1] * (N + 1) dp[0] = 0 for i in range(N + 1): for a in A: if i - h[a] < 0: continue dp[i] = max(dp[i-h[a]] + 1, dp[i]) digit = dp[N] ans = '' n = N for d in range(digit): for a in A: if n - h[a] < 0:continue if dp[n - h[a]] == digit - 1: ans += str(a) n -= h[a] digit -= 1 break print(ans)
34
28
750
619
N, M = list(map(int, input().split())) A = [i for i in input().split()] # dp[i] = i本使ってできる最大の数 def mx(a, b): if a is not None and b is None: return a elif a is None and b is not None: return b if len(a) != len(b): if len(a) > len(b): return a else: return b return max(a, b) # xを作るために使うマッチの本数 h = {"1": 2, "2": 5, "3": 5, "4": 4, "5": 5, "6": 6, "7": 3, "8": 7, "9": 6} dp = [None] * (N + 1) dp[0] = "" for i in range(N + 1): for a in A: if i - h[a] < 0: continue if dp[i - h[a]] is None and dp[i] is None: continue try: dp[i] = mx(dp[i - h[a]] + a, dp[i]) except: continue print((dp[N]))
N, M = list(map(int, input().split())) A = sorted([int(i) for i in input().split()], reverse=True) # xを作るために使うマッチの本数 h = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6} # dp[i] = i 本のマッチ棒を使って、条件を満たす整数を作るときの最大桁数 dp = [-1] * (N + 1) dp[0] = 0 for i in range(N + 1): for a in A: if i - h[a] < 0: continue dp[i] = max(dp[i - h[a]] + 1, dp[i]) digit = dp[N] ans = "" n = N for d in range(digit): for a in A: if n - h[a] < 0: continue if dp[n - h[a]] == digit - 1: ans += str(a) n -= h[a] digit -= 1 break print(ans)
false
17.647059
[ "-A = [i for i in input().split()]", "-# dp[i] = i本使ってできる最大の数", "-def mx(a, b):", "- if a is not None and b is None:", "- return a", "- elif a is None and b is not None:", "- return b", "- if len(a) != len(b):", "- if len(a) > len(b):", "- return a", "- else:", "- return b", "- return max(a, b)", "-", "-", "+A = sorted([int(i) for i in input().split()], reverse=True)", "-h = {\"1\": 2, \"2\": 5, \"3\": 5, \"4\": 4, \"5\": 5, \"6\": 6, \"7\": 3, \"8\": 7, \"9\": 6}", "-dp = [None] * (N + 1)", "-dp[0] = \"\"", "+h = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6}", "+# dp[i] = i 本のマッチ棒を使って、条件を満たす整数を作るときの最大桁数", "+dp = [-1] * (N + 1)", "+dp[0] = 0", "- if dp[i - h[a]] is None and dp[i] is None:", "+ dp[i] = max(dp[i - h[a]] + 1, dp[i])", "+digit = dp[N]", "+ans = \"\"", "+n = N", "+for d in range(digit):", "+ for a in A:", "+ if n - h[a] < 0:", "- try:", "- dp[i] = mx(dp[i - h[a]] + a, dp[i])", "- except:", "- continue", "-print((dp[N]))", "+ if dp[n - h[a]] == digit - 1:", "+ ans += str(a)", "+ n -= h[a]", "+ digit -= 1", "+ break", "+print(ans)" ]
false
0.042898
0.039032
1.099027
[ "s334439448", "s555594210" ]
u349444371
p03821
python
s865078158
s267471224
428
379
27,380
28,148
Accepted
Accepted
11.45
n=int(eval(input())) ab = [list(map(int, input().split())) for _ in range(n)] ans=0 for i in range(n): #print(ab[-i-1][0]+ans,ab[-i-1][1]) if (ab[-i-1][0]+ans)%ab[-i-1][1]!=0: ans+=ab[-i-1][1]-(ab[-i-1][0]+ans)%ab[-i-1][1] #print(ans) print(ans)
n=int(eval(input())) ab = [list(map(int, input().split())) for _ in range(n)] ab=ab[::-1] #print(ab) ans=0 for a,b in ab: if (a+ans)%b!=0: ans+=b-(a+ans)%b print(ans)
9
9
267
180
n = int(eval(input())) ab = [list(map(int, input().split())) for _ in range(n)] ans = 0 for i in range(n): # print(ab[-i-1][0]+ans,ab[-i-1][1]) if (ab[-i - 1][0] + ans) % ab[-i - 1][1] != 0: ans += ab[-i - 1][1] - (ab[-i - 1][0] + ans) % ab[-i - 1][1] # print(ans) print(ans)
n = int(eval(input())) ab = [list(map(int, input().split())) for _ in range(n)] ab = ab[::-1] # print(ab) ans = 0 for a, b in ab: if (a + ans) % b != 0: ans += b - (a + ans) % b print(ans)
false
0
[ "+ab = ab[::-1]", "+# print(ab)", "-for i in range(n):", "- # print(ab[-i-1][0]+ans,ab[-i-1][1])", "- if (ab[-i - 1][0] + ans) % ab[-i - 1][1] != 0:", "- ans += ab[-i - 1][1] - (ab[-i - 1][0] + ans) % ab[-i - 1][1]", "- # print(ans)", "+for a, b in ab:", "+ if (a + ans) % b != 0:", "+ ans += b - (a + ans) % b" ]
false
0.04564
0.046391
0.983805
[ "s865078158", "s267471224" ]
u514687406
p02657
python
s917903144
s108106994
73
25
65,308
9,432
Accepted
Accepted
65.75
""" ~~ Author : Bhaskar ~~ Dated : 31~05~2020 """ import sys from bisect import * from math import floor,sqrt,ceil,factorial as F,gcd,pi from itertools import chain,combinations,permutations,accumulate from collections import Counter,defaultdict,OrderedDict,deque from array import array INT_MAX = sys.maxsize INT_MIN = -(sys.maxsize)-1 mod = 1000000007 lcm = lambda a,b : (a*b)//gcd(a,b) setbit = lambda x : bin(x)[2:].count("1") def solve(): a,b = list(map(int,sys.stdin.readline().split())) print((a*b)) if __name__ == "__main__": solve()
""" ~~ Author : Bhaskar ~~ Dated : 13~06~2020 """ import sys from bisect import * from math import floor, sqrt, ceil, factorial as F, gcd, pi from itertools import chain, combinations, permutations, accumulate from collections import Counter, defaultdict, OrderedDict, deque INT_MAX = sys.maxsize INT_MIN = -(sys.maxsize) - 1 mod = 1000000007 ch = "abcdefghijklmnopqrstuvwxyz" lcm = lambda a, b: (a * b) // gcd(a, b) setbit = lambda x: bin(x)[2:].count("1") INT = lambda type: type(sys.stdin.readline()) if type in [int, float] else type(sys.stdin.readline()).replace("\n", "") ARRAY = lambda type: list(map(type, sys.stdin.readline().split())) NUMS = lambda type: list(map(type, sys.stdin.readline().split())) def solve(): a,b = NUMS(int) print((a*b)) if __name__ == "__main__": try: sys.stdin = open("input.txt", "r") except: pass solve()
23
35
571
915
""" ~~ Author : Bhaskar ~~ Dated : 31~05~2020 """ import sys from bisect import * from math import floor, sqrt, ceil, factorial as F, gcd, pi from itertools import chain, combinations, permutations, accumulate from collections import Counter, defaultdict, OrderedDict, deque from array import array INT_MAX = sys.maxsize INT_MIN = -(sys.maxsize) - 1 mod = 1000000007 lcm = lambda a, b: (a * b) // gcd(a, b) setbit = lambda x: bin(x)[2:].count("1") def solve(): a, b = list(map(int, sys.stdin.readline().split())) print((a * b)) if __name__ == "__main__": solve()
""" ~~ Author : Bhaskar ~~ Dated : 13~06~2020 """ import sys from bisect import * from math import floor, sqrt, ceil, factorial as F, gcd, pi from itertools import chain, combinations, permutations, accumulate from collections import Counter, defaultdict, OrderedDict, deque INT_MAX = sys.maxsize INT_MIN = -(sys.maxsize) - 1 mod = 1000000007 ch = "abcdefghijklmnopqrstuvwxyz" lcm = lambda a, b: (a * b) // gcd(a, b) setbit = lambda x: bin(x)[2:].count("1") INT = ( lambda type: type(sys.stdin.readline()) if type in [int, float] else type(sys.stdin.readline()).replace("\n", "") ) ARRAY = lambda type: list(map(type, sys.stdin.readline().split())) NUMS = lambda type: list(map(type, sys.stdin.readline().split())) def solve(): a, b = NUMS(int) print((a * b)) if __name__ == "__main__": try: sys.stdin = open("input.txt", "r") except: pass solve()
false
34.285714
[ "-~~ Dated : 31~05~2020", "+~~ Dated : 13~06~2020", "-from array import array", "+ch = \"abcdefghijklmnopqrstuvwxyz\"", "+INT = (", "+ lambda type: type(sys.stdin.readline())", "+ if type in [int, float]", "+ else type(sys.stdin.readline()).replace(\"\\n\", \"\")", "+)", "+ARRAY = lambda type: list(map(type, sys.stdin.readline().split()))", "+NUMS = lambda type: list(map(type, sys.stdin.readline().split()))", "- a, b = list(map(int, sys.stdin.readline().split()))", "+ a, b = NUMS(int)", "+ try:", "+ sys.stdin = open(\"input.txt\", \"r\")", "+ except:", "+ pass" ]
false
0.045041
0.047424
0.94976
[ "s917903144", "s108106994" ]
u906501980
p02744
python
s927860611
s868482947
495
450
49,084
49,088
Accepted
Accepted
9.09
n = int(eval(input())) s = "abcdefghij" class Node: def __init__(self, string, index): self.children = [] self.string = string self.index = index def get_children(self): parent = self.string for i, c in enumerate(s[:self.index+1]): self.children.append(Node(parent+c, max(self.index, i+1))) return self.children root = Node("a", 1) children = [root] for _ in range(n-1): parents, children = children, [] for parent in parents: children.extend(parent.get_children()) for child in children: print((child.string))
n = int(eval(input())) s = "abcdefghij" class Node: def __init__(self, string, index): self.children = [] self.string = string self.index = index def get_children(self): parent = self.string for i, c in enumerate(s[:self.index+1], 1): self.children.append(Node(parent+c, max(i, self.index))) return self.children root = Node("a", 1) children = [root] for _ in range(n-1): parents, children = children, [] for parent in parents: children.extend(parent.get_children()) for child in children: print((child.string))
23
23
615
616
n = int(eval(input())) s = "abcdefghij" class Node: def __init__(self, string, index): self.children = [] self.string = string self.index = index def get_children(self): parent = self.string for i, c in enumerate(s[: self.index + 1]): self.children.append(Node(parent + c, max(self.index, i + 1))) return self.children root = Node("a", 1) children = [root] for _ in range(n - 1): parents, children = children, [] for parent in parents: children.extend(parent.get_children()) for child in children: print((child.string))
n = int(eval(input())) s = "abcdefghij" class Node: def __init__(self, string, index): self.children = [] self.string = string self.index = index def get_children(self): parent = self.string for i, c in enumerate(s[: self.index + 1], 1): self.children.append(Node(parent + c, max(i, self.index))) return self.children root = Node("a", 1) children = [root] for _ in range(n - 1): parents, children = children, [] for parent in parents: children.extend(parent.get_children()) for child in children: print((child.string))
false
0
[ "- for i, c in enumerate(s[: self.index + 1]):", "- self.children.append(Node(parent + c, max(self.index, i + 1)))", "+ for i, c in enumerate(s[: self.index + 1], 1):", "+ self.children.append(Node(parent + c, max(i, self.index)))" ]
false
0.044831
0.037387
1.199118
[ "s927860611", "s868482947" ]
u778814286
p03485
python
s369422647
s992446166
37
18
5,220
2,940
Accepted
Accepted
51.35
import math import statistics as st a,b = list(map(int,input().split())) print((math.ceil(st.mean((a,b)))))
import math a, b = list(map(int,input().split())) print((math.ceil((a+b)/2)))
6
3
106
71
import math import statistics as st a, b = list(map(int, input().split())) print((math.ceil(st.mean((a, b)))))
import math a, b = list(map(int, input().split())) print((math.ceil((a + b) / 2)))
false
50
[ "-import statistics as st", "-print((math.ceil(st.mean((a, b)))))", "+print((math.ceil((a + b) / 2)))" ]
false
0.180024
0.03774
4.770082
[ "s369422647", "s992446166" ]
u721403425
p02717
python
s563117721
s290327277
21
17
3,060
2,940
Accepted
Accepted
19.05
x,y,z = list(map(int,input().split())) print((z,x,y))
x,y,z = input().split() print((z,x,y))
2
2
46
37
x, y, z = list(map(int, input().split())) print((z, x, y))
x, y, z = input().split() print((z, x, y))
false
0
[ "-x, y, z = list(map(int, input().split()))", "+x, y, z = input().split()" ]
false
0.045548
0.115844
0.393184
[ "s563117721", "s290327277" ]
u407160848
p02735
python
s784587660
s513764254
569
410
69,208
58,712
Accepted
Accepted
27.94
import math from functools import reduce from collections import deque import heapq import sys sys.setrecursionlimit(10**7) # スペース区切りの入力を読み込んで数値リストにして返します。 def get_nums_l(): return [ int(s) for s in input().split(" ")] # 改行区切りの入力をn行読み込んで数値リストにして返します。 def get_nums_n(n): return [ int(input()) for _ in range(n)] # 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。 def get_all_int(): return map(int, open(0).read().split()) def log(*args): print("DEBUG:", *args, file=sys.stderr) h,w = get_nums_l() grid = [ input() for _ in range(h) ] dp = [ [99999999999999999999] * w for _ in range(h)] def bfs(cost, x, y): log(cost, y, x) if dp[y][x] <= cost: return dp[y][x] = cost if x < w-1: if grid[y][x] == "." and grid[y][x+1] == "#": heapq.heappush(heap, (cost+1, x+1, y)) else: heapq.heappush(heap, (cost, x+1, y)) if y < h-1: if grid[y][x] =="." and grid[y+1][x] == "#": heapq.heappush(heap, (cost+1, x, y+1)) else: heapq.heappush(heap, (cost, x, y+1)) heap = [] if grid[0][0] == ".": heapq.heappush(heap, (0,0,0)) else: heapq.heappush(heap, (1,0,0)) while heap: cost, x, y = heapq.heappop(heap) bfs(cost, x, y) print(dp[h-1][w-1])
import heapq import sys # スペース区切りの入力を読み込んで数値リストにして返します。 def get_nums_l(): return [ int(s) for s in input().split(" ")] def log(*args): print("DEBUG:", *args, file=sys.stderr) h,w = get_nums_l() grid = [ input() for _ in range(h) ] dp = [ [99999999999999999999] * w for _ in range(h)] def bfs(cost, x, y): # log(cost, y, x) if dp[y][x] <= cost: return dp[y][x] = cost if x < w-1: if grid[y][x] == "." and grid[y][x+1] == "#": heapq.heappush(heap, (cost+1, x+1, y)) else: heapq.heappush(heap, (cost, x+1, y)) if y < h-1: if grid[y][x] =="." and grid[y+1][x] == "#": heapq.heappush(heap, (cost+1, x, y+1)) else: heapq.heappush(heap, (cost, x, y+1)) heap = [] if grid[0][0] == ".": heapq.heappush(heap, (0,0,0)) else: heapq.heappush(heap, (1,0,0)) while heap: cost, x, y = heapq.heappop(heap) bfs(cost, x, y) print(dp[h-1][w-1])
57
45
1,320
1,012
import math from functools import reduce from collections import deque import heapq import sys sys.setrecursionlimit(10**7) # スペース区切りの入力を読み込んで数値リストにして返します。 def get_nums_l(): return [int(s) for s in input().split(" ")] # 改行区切りの入力をn行読み込んで数値リストにして返します。 def get_nums_n(n): return [int(input()) for _ in range(n)] # 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。 def get_all_int(): return map(int, open(0).read().split()) def log(*args): print("DEBUG:", *args, file=sys.stderr) h, w = get_nums_l() grid = [input() for _ in range(h)] dp = [[99999999999999999999] * w for _ in range(h)] def bfs(cost, x, y): log(cost, y, x) if dp[y][x] <= cost: return dp[y][x] = cost if x < w - 1: if grid[y][x] == "." and grid[y][x + 1] == "#": heapq.heappush(heap, (cost + 1, x + 1, y)) else: heapq.heappush(heap, (cost, x + 1, y)) if y < h - 1: if grid[y][x] == "." and grid[y + 1][x] == "#": heapq.heappush(heap, (cost + 1, x, y + 1)) else: heapq.heappush(heap, (cost, x, y + 1)) heap = [] if grid[0][0] == ".": heapq.heappush(heap, (0, 0, 0)) else: heapq.heappush(heap, (1, 0, 0)) while heap: cost, x, y = heapq.heappop(heap) bfs(cost, x, y) print(dp[h - 1][w - 1])
import heapq import sys # スペース区切りの入力を読み込んで数値リストにして返します。 def get_nums_l(): return [int(s) for s in input().split(" ")] def log(*args): print("DEBUG:", *args, file=sys.stderr) h, w = get_nums_l() grid = [input() for _ in range(h)] dp = [[99999999999999999999] * w for _ in range(h)] def bfs(cost, x, y): # log(cost, y, x) if dp[y][x] <= cost: return dp[y][x] = cost if x < w - 1: if grid[y][x] == "." and grid[y][x + 1] == "#": heapq.heappush(heap, (cost + 1, x + 1, y)) else: heapq.heappush(heap, (cost, x + 1, y)) if y < h - 1: if grid[y][x] == "." and grid[y + 1][x] == "#": heapq.heappush(heap, (cost + 1, x, y + 1)) else: heapq.heappush(heap, (cost, x, y + 1)) heap = [] if grid[0][0] == ".": heapq.heappush(heap, (0, 0, 0)) else: heapq.heappush(heap, (1, 0, 0)) while heap: cost, x, y = heapq.heappop(heap) bfs(cost, x, y) print(dp[h - 1][w - 1])
false
21.052632
[ "-import math", "-from functools import reduce", "-from collections import deque", "-sys.setrecursionlimit(10**7)", "-", "-", "-# 改行区切りの入力をn行読み込んで数値リストにして返します。", "-def get_nums_n(n):", "- return [int(input()) for _ in range(n)]", "-", "-", "-# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。", "-def get_all_int():", "- return map(int, open(0).read().split())", "- log(cost, y, x)", "+ # log(cost, y, x)" ]
false
0.045758
0.105672
0.433021
[ "s784587660", "s513764254" ]
u163320134
p03044
python
s367073918
s343333496
889
660
46,128
39,956
Accepted
Accepted
25.76
import collections n=int(eval(input())) ans=[0]*(n+1) tree=[[] for _ in range(n+1)] for i in range(n-1): u,v,w=list(map(int,input().split())) tree[u].append([v,w]) tree[v].append([u,w]) q=collections.deque([1]) check=[False]*(n+1) check[1]=True tmp=tree[1][0] if tmp[1]%2==0: ans[1]=1 ans[tmp[0]]=1 else: ans[1]=1 ans[tmp[0]]=0 while 1: if len(q)==0: break tmp=q.popleft() for i in range(len(tree[tmp])): v,w=tree[tmp][i][0],tree[tmp][i][1] if check[v]: continue else: check[v]=True if w%2==0: ans[v]=ans[tmp] else: ans[v]=abs(1-ans[tmp]) q.append(v) for i in range(1,n+1): print((ans[i]))
import collections n=int(eval(input())) g=[[] for _ in range(n+1)] for _ in range(n-1): a,b,w=list(map(int,input().split())) g[a].append((b,w)) g[b].append((a,w)) q=collections.deque() q.append(1) checked=[0]*(n+1) ans=[0]*(n+1) ans[1]=0 while len(q)!=0: v=q.popleft() checked[v]=1 for u,w in g[v]: if checked[u]==0: if w%2==0: ans[u]=ans[v] else: ans[u]=ans[v]^1 q.append(u) for i in range(1,n+1): print((ans[i]))
36
25
695
478
import collections n = int(eval(input())) ans = [0] * (n + 1) tree = [[] for _ in range(n + 1)] for i in range(n - 1): u, v, w = list(map(int, input().split())) tree[u].append([v, w]) tree[v].append([u, w]) q = collections.deque([1]) check = [False] * (n + 1) check[1] = True tmp = tree[1][0] if tmp[1] % 2 == 0: ans[1] = 1 ans[tmp[0]] = 1 else: ans[1] = 1 ans[tmp[0]] = 0 while 1: if len(q) == 0: break tmp = q.popleft() for i in range(len(tree[tmp])): v, w = tree[tmp][i][0], tree[tmp][i][1] if check[v]: continue else: check[v] = True if w % 2 == 0: ans[v] = ans[tmp] else: ans[v] = abs(1 - ans[tmp]) q.append(v) for i in range(1, n + 1): print((ans[i]))
import collections n = int(eval(input())) g = [[] for _ in range(n + 1)] for _ in range(n - 1): a, b, w = list(map(int, input().split())) g[a].append((b, w)) g[b].append((a, w)) q = collections.deque() q.append(1) checked = [0] * (n + 1) ans = [0] * (n + 1) ans[1] = 0 while len(q) != 0: v = q.popleft() checked[v] = 1 for u, w in g[v]: if checked[u] == 0: if w % 2 == 0: ans[u] = ans[v] else: ans[u] = ans[v] ^ 1 q.append(u) for i in range(1, n + 1): print((ans[i]))
false
30.555556
[ "+g = [[] for _ in range(n + 1)]", "+for _ in range(n - 1):", "+ a, b, w = list(map(int, input().split()))", "+ g[a].append((b, w))", "+ g[b].append((a, w))", "+q = collections.deque()", "+q.append(1)", "+checked = [0] * (n + 1)", "-tree = [[] for _ in range(n + 1)]", "-for i in range(n - 1):", "- u, v, w = list(map(int, input().split()))", "- tree[u].append([v, w])", "- tree[v].append([u, w])", "-q = collections.deque([1])", "-check = [False] * (n + 1)", "-check[1] = True", "-tmp = tree[1][0]", "-if tmp[1] % 2 == 0:", "- ans[1] = 1", "- ans[tmp[0]] = 1", "-else:", "- ans[1] = 1", "- ans[tmp[0]] = 0", "-while 1:", "- if len(q) == 0:", "- break", "- tmp = q.popleft()", "- for i in range(len(tree[tmp])):", "- v, w = tree[tmp][i][0], tree[tmp][i][1]", "- if check[v]:", "- continue", "- else:", "- check[v] = True", "+ans[1] = 0", "+while len(q) != 0:", "+ v = q.popleft()", "+ checked[v] = 1", "+ for u, w in g[v]:", "+ if checked[u] == 0:", "- ans[v] = ans[tmp]", "+ ans[u] = ans[v]", "- ans[v] = abs(1 - ans[tmp])", "- q.append(v)", "+ ans[u] = ans[v] ^ 1", "+ q.append(u)" ]
false
0.105659
0.046032
2.295329
[ "s367073918", "s343333496" ]
u077291787
p02744
python
s795070656
s424330224
69
61
15,732
15,380
Accepted
Accepted
11.59
# D - String Equivalence from string import ascii_lowercase def dfs(n: int) -> list: if n == 1: return ["a"] cur = dfs(n - 1) result = [] for s in cur: for c in ascii_lowercase[: len(set(s)) + 1]: result.append(s + c) return result def main(): N = int(eval(input())) result = dfs(N) result.sort() print(("\n".join(result))) if __name__ == "__main__": main()
# D - String Equivalence abc = "abcdefghij" def dfs(n: int) -> list: if n == 1: return ["a"] cur = dfs(n - 1) result = [] for s in cur: for c in abc[: len(set(s)) + 1]: result.append(s + c) return result def main(): N = int(eval(input())) result = dfs(N) result.sort() print(("\n".join(result))) if __name__ == "__main__": main()
24
24
447
419
# D - String Equivalence from string import ascii_lowercase def dfs(n: int) -> list: if n == 1: return ["a"] cur = dfs(n - 1) result = [] for s in cur: for c in ascii_lowercase[: len(set(s)) + 1]: result.append(s + c) return result def main(): N = int(eval(input())) result = dfs(N) result.sort() print(("\n".join(result))) if __name__ == "__main__": main()
# D - String Equivalence abc = "abcdefghij" def dfs(n: int) -> list: if n == 1: return ["a"] cur = dfs(n - 1) result = [] for s in cur: for c in abc[: len(set(s)) + 1]: result.append(s + c) return result def main(): N = int(eval(input())) result = dfs(N) result.sort() print(("\n".join(result))) if __name__ == "__main__": main()
false
0
[ "-from string import ascii_lowercase", "+abc = \"abcdefghij\"", "- for c in ascii_lowercase[: len(set(s)) + 1]:", "+ for c in abc[: len(set(s)) + 1]:" ]
false
0.049632
0.037699
1.316554
[ "s795070656", "s424330224" ]
u677121387
p02791
python
s168910518
s693337207
156
111
24,744
24,744
Accepted
Accepted
28.85
n = int(eval(input())) p = [int(i) for i in input().split()] t = p[0] ans = 0 for i in range(n): if t >= p[i]: ans += 1 t = min(p[i],t) print(ans)
n = int(eval(input())) p = [int(i) for i in input().split()] t = p[0] ans = 0 for i in range(n): if t >= p[i]: ans += 1 t = p[i] print(ans)
11
11
168
165
n = int(eval(input())) p = [int(i) for i in input().split()] t = p[0] ans = 0 for i in range(n): if t >= p[i]: ans += 1 t = min(p[i], t) print(ans)
n = int(eval(input())) p = [int(i) for i in input().split()] t = p[0] ans = 0 for i in range(n): if t >= p[i]: ans += 1 t = p[i] print(ans)
false
0
[ "- t = min(p[i], t)", "+ t = p[i]" ]
false
0.04721
0.046517
1.01488
[ "s168910518", "s693337207" ]
u450956662
p02912
python
s124972041
s872081265
167
147
14,252
20,248
Accepted
Accepted
11.98
import heapq N, M = list(map(int, input().split())) A = list([-int(x) for x in input().split()]) heapq.heapify(A) for _ in range(M): tmp = heapq.heappop(A) heapq.heappush(A, -(-tmp // 2)) print((-sum(A)))
import heapq N, M = list(map(int, input().split())) A = list([-int(x) for x in input().split()]) res = -sum(A) heapq.heapify(A) for _ in range(M): a = heapq.heappop(A) a *= -1 res -= (a - a // 2) a //= 2 heapq.heappush(A, - a) print(res)
11
12
223
267
import heapq N, M = list(map(int, input().split())) A = list([-int(x) for x in input().split()]) heapq.heapify(A) for _ in range(M): tmp = heapq.heappop(A) heapq.heappush(A, -(-tmp // 2)) print((-sum(A)))
import heapq N, M = list(map(int, input().split())) A = list([-int(x) for x in input().split()]) res = -sum(A) heapq.heapify(A) for _ in range(M): a = heapq.heappop(A) a *= -1 res -= a - a // 2 a //= 2 heapq.heappush(A, -a) print(res)
false
8.333333
[ "+res = -sum(A)", "- tmp = heapq.heappop(A)", "- heapq.heappush(A, -(-tmp // 2))", "-print((-sum(A)))", "+ a = heapq.heappop(A)", "+ a *= -1", "+ res -= a - a // 2", "+ a //= 2", "+ heapq.heappush(A, -a)", "+print(res)" ]
false
0.127166
0.055315
2.298957
[ "s124972041", "s872081265" ]
u888092736
p03044
python
s929374377
s653667934
539
487
109,260
78,652
Accepted
Accepted
9.65
import sys from collections import defaultdict sys.setrecursionlimit(1_000_000) def dfs(v): for nv, nw in g[v]: if visited[nv]: continue if nw % 2: ans[nv] = ans[v] ^ 1 else: ans[nv] = ans[v] visited[nv] = True dfs(nv) N, *UVW = list(map(int, open(0).read().split())) g = defaultdict(set) ans = [0] * N for u, v, w in zip(*[iter(UVW)] * 3): u -= 1 v -= 1 g[u].add((v, w)) g[v].add((u, w)) visited = [False] * N visited[0] = True dfs(0) print(("\n".join(map(str, ans))))
from collections import defaultdict, deque def bfs(start): q = deque([start]) dist = [-1] * N dist[start] = 0 while q: v = q.popleft() for nv, nw in g[v]: if dist[nv] >= 0: continue dist[nv] = (dist[v] + nw) % 2 q.append(nv) return dist N, *UVW = list(map(int, open(0).read().split())) g = defaultdict(set) ans = [0] * N for u, v, w in zip(*[iter(UVW)] * 3): u -= 1 v -= 1 g[u].add((v, w)) g[v].add((u, w)) print(("\n".join(map(str, bfs(0)))))
33
27
598
571
import sys from collections import defaultdict sys.setrecursionlimit(1_000_000) def dfs(v): for nv, nw in g[v]: if visited[nv]: continue if nw % 2: ans[nv] = ans[v] ^ 1 else: ans[nv] = ans[v] visited[nv] = True dfs(nv) N, *UVW = list(map(int, open(0).read().split())) g = defaultdict(set) ans = [0] * N for u, v, w in zip(*[iter(UVW)] * 3): u -= 1 v -= 1 g[u].add((v, w)) g[v].add((u, w)) visited = [False] * N visited[0] = True dfs(0) print(("\n".join(map(str, ans))))
from collections import defaultdict, deque def bfs(start): q = deque([start]) dist = [-1] * N dist[start] = 0 while q: v = q.popleft() for nv, nw in g[v]: if dist[nv] >= 0: continue dist[nv] = (dist[v] + nw) % 2 q.append(nv) return dist N, *UVW = list(map(int, open(0).read().split())) g = defaultdict(set) ans = [0] * N for u, v, w in zip(*[iter(UVW)] * 3): u -= 1 v -= 1 g[u].add((v, w)) g[v].add((u, w)) print(("\n".join(map(str, bfs(0)))))
false
18.181818
[ "-import sys", "-from collections import defaultdict", "-", "-sys.setrecursionlimit(1_000_000)", "+from collections import defaultdict, deque", "-def dfs(v):", "- for nv, nw in g[v]:", "- if visited[nv]:", "- continue", "- if nw % 2:", "- ans[nv] = ans[v] ^ 1", "- else:", "- ans[nv] = ans[v]", "- visited[nv] = True", "- dfs(nv)", "+def bfs(start):", "+ q = deque([start])", "+ dist = [-1] * N", "+ dist[start] = 0", "+ while q:", "+ v = q.popleft()", "+ for nv, nw in g[v]:", "+ if dist[nv] >= 0:", "+ continue", "+ dist[nv] = (dist[v] + nw) % 2", "+ q.append(nv)", "+ return dist", "-visited = [False] * N", "-visited[0] = True", "-dfs(0)", "-print((\"\\n\".join(map(str, ans))))", "+print((\"\\n\".join(map(str, bfs(0)))))" ]
false
0.036559
0.03624
1.008806
[ "s929374377", "s653667934" ]
u998733244
p02714
python
s376688887
s664734655
1,760
122
9,284
73,856
Accepted
Accepted
93.07
#!/usr/bin/env python3 MOD = 10**9 def make_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) return divisors N = int(eval(input())) S = eval(input()) ans = S.count('R') * S.count('G') * S.count('B') SN = [] for s in S: if s == 'R': SN.append(-1) elif s == 'G': SN.append(0) else: SN.append(1) rem2 = ['RRR', 'GGG', 'BBB'] count = 0 for i in range(1, N-1): index = i left = i - 1 right = i + 1 f = True while f: if left == -1 or right == N: break if SN[left] == SN[index] and SN[index] == SN[right] == 0 : pass elif SN[left] + SN[index] + SN[right] == 0 : count+= 1 left -= 1 right += 1 print((ans-count))
N = int(eval(input())) S = eval(input()) ans = S.count('R') * S.count('G') * S.count('B') SN = [] for s in S: if s == 'R': SN.append(-1) elif s == 'G': SN.append(0) else: SN.append(1) rem2 = ['RRR', 'GGG', 'BBB'] count = 0 for i in range(1, N-1): index = i left = i - 1 right = i + 1 f = True while f: if left == -1 or right == N: break if SN[left] == SN[index] and SN[index] == SN[right] == 0 : pass elif SN[left] + SN[index] + SN[right] == 0 : count+= 1 left -= 1 right += 1 print((ans-count))
44
32
892
631
#!/usr/bin/env python3 MOD = 10**9 def make_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) return divisors N = int(eval(input())) S = eval(input()) ans = S.count("R") * S.count("G") * S.count("B") SN = [] for s in S: if s == "R": SN.append(-1) elif s == "G": SN.append(0) else: SN.append(1) rem2 = ["RRR", "GGG", "BBB"] count = 0 for i in range(1, N - 1): index = i left = i - 1 right = i + 1 f = True while f: if left == -1 or right == N: break if SN[left] == SN[index] and SN[index] == SN[right] == 0: pass elif SN[left] + SN[index] + SN[right] == 0: count += 1 left -= 1 right += 1 print((ans - count))
N = int(eval(input())) S = eval(input()) ans = S.count("R") * S.count("G") * S.count("B") SN = [] for s in S: if s == "R": SN.append(-1) elif s == "G": SN.append(0) else: SN.append(1) rem2 = ["RRR", "GGG", "BBB"] count = 0 for i in range(1, N - 1): index = i left = i - 1 right = i + 1 f = True while f: if left == -1 or right == N: break if SN[left] == SN[index] and SN[index] == SN[right] == 0: pass elif SN[left] + SN[index] + SN[right] == 0: count += 1 left -= 1 right += 1 print((ans - count))
false
27.272727
[ "-#!/usr/bin/env python3", "-MOD = 10**9", "-", "-", "-def make_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)", "- return divisors", "-", "-" ]
false
0.100269
0.036938
2.714487
[ "s376688887", "s664734655" ]
u116002573
p02790
python
s460230107
s698868981
64
58
61,820
61,804
Accepted
Accepted
9.38
def main(): a, b = input().split() s = a * int(b) t = b * int(a) if s < t: return s return t if __name__ == '__main__': print((main()))
def main(): a, b = list(map(int, input().split())) s = str(a) * b t = str(b) * a if s < t: return s return t if __name__ == '__main__': print((main()))
12
12
180
190
def main(): a, b = input().split() s = a * int(b) t = b * int(a) if s < t: return s return t if __name__ == "__main__": print((main()))
def main(): a, b = list(map(int, input().split())) s = str(a) * b t = str(b) * a if s < t: return s return t if __name__ == "__main__": print((main()))
false
0
[ "- a, b = input().split()", "- s = a * int(b)", "- t = b * int(a)", "+ a, b = list(map(int, input().split()))", "+ s = str(a) * b", "+ t = str(b) * a" ]
false
0.0327
0.11046
0.296035
[ "s460230107", "s698868981" ]
u618251217
p02615
python
s707168009
s459190665
155
136
31,636
31,440
Accepted
Accepted
12.26
N = int(eval(input())) A = list(map(int, input().split())) A.sort(reverse=True) cnt = 1 idx = 0 ans = 0 while cnt <= N-1: ans += A[idx] if cnt % 2 == 1: #ans += A[idx] idx += 1 #else: #ans += A[idx] cnt += 1 print(ans)
N = int(eval(input())) A = list(map(int, input().split())) A.sort(reverse=True) ans = A[0] #最大値だけ1回 for i in range(N-2): ans += A[i//2 + 1] print(ans)
16
7
268
154
N = int(eval(input())) A = list(map(int, input().split())) A.sort(reverse=True) cnt = 1 idx = 0 ans = 0 while cnt <= N - 1: ans += A[idx] if cnt % 2 == 1: # ans += A[idx] idx += 1 # else: # ans += A[idx] cnt += 1 print(ans)
N = int(eval(input())) A = list(map(int, input().split())) A.sort(reverse=True) ans = A[0] # 最大値だけ1回 for i in range(N - 2): ans += A[i // 2 + 1] print(ans)
false
56.25
[ "-cnt = 1", "-idx = 0", "-ans = 0", "-while cnt <= N - 1:", "- ans += A[idx]", "- if cnt % 2 == 1:", "- # ans += A[idx]", "- idx += 1", "- # else:", "- # ans += A[idx]", "- cnt += 1", "+ans = A[0] # 最大値だけ1回", "+for i in range(N - 2):", "+ ans += A[i // 2 + 1]" ]
false
0.046531
0.046537
0.999886
[ "s707168009", "s459190665" ]
u926412290
p03805
python
s824245006
s713017617
85
29
74,536
9,140
Accepted
Accepted
65.88
N, M = list(map(int, input().split())) to = [[] for _ in range(N)] for _ in range(M): a, b = list(map(int, input().split())) a, b = a - 1, b - 1 to[a].append(b) to[b].append(a) res = 0 def dfs(v, seen): global res if seen == [1] * N: res += 1 return for nv in to[v]: if not seen[nv]: seen[nv] = 1 dfs(nv, seen) seen[nv] = 0 def main(): seen = [0] * N seen[0] = 1 dfs(0, seen) print(res) if __name__ == "__main__": main()
N, M = list(map(int, input().split())) to = [[] for _ in range(N)] for _ in range(M): a, b = list(map(int, input().split())) a, b = a - 1, b - 1 to[a].append(b) to[b].append(a) def dfs(v, seen): if seen == [1] * N: return 1 res = 0 for nv in to[v]: if not seen[nv]: seen[nv] = 1 res += dfs(nv, seen) seen[nv] = 0 return res def main(): seen = [0] * N seen[0] = 1 print((dfs(0, seen))) if __name__ == "__main__": main()
32
31
555
551
N, M = list(map(int, input().split())) to = [[] for _ in range(N)] for _ in range(M): a, b = list(map(int, input().split())) a, b = a - 1, b - 1 to[a].append(b) to[b].append(a) res = 0 def dfs(v, seen): global res if seen == [1] * N: res += 1 return for nv in to[v]: if not seen[nv]: seen[nv] = 1 dfs(nv, seen) seen[nv] = 0 def main(): seen = [0] * N seen[0] = 1 dfs(0, seen) print(res) if __name__ == "__main__": main()
N, M = list(map(int, input().split())) to = [[] for _ in range(N)] for _ in range(M): a, b = list(map(int, input().split())) a, b = a - 1, b - 1 to[a].append(b) to[b].append(a) def dfs(v, seen): if seen == [1] * N: return 1 res = 0 for nv in to[v]: if not seen[nv]: seen[nv] = 1 res += dfs(nv, seen) seen[nv] = 0 return res def main(): seen = [0] * N seen[0] = 1 print((dfs(0, seen))) if __name__ == "__main__": main()
false
3.125
[ "-res = 0", "- global res", "- res += 1", "- return", "+ return 1", "+ res = 0", "- dfs(nv, seen)", "+ res += dfs(nv, seen)", "+ return res", "- dfs(0, seen)", "- print(res)", "+ print((dfs(0, seen)))" ]
false
0.038028
0.071136
0.53459
[ "s824245006", "s713017617" ]
u506858457
p02683
python
s532075726
s337406452
103
90
9,124
9,180
Accepted
Accepted
12.62
def MI(): return list(map(int, input().split())) def LI(): return list(map(int, input().split())) N,M,X=MI() List=[] for i in range(N): CA=LI() List.append(CA) ans=-1 for i in range(1<<N): tmp=[0]*M cost=0 for j in range(N): if 1&(i>>j): cost+=List[j][0] for k in range(M): tmp[k]+=List[j][k+1] if min(tmp)>=X: if ans==-1: ans=cost else: ans=min(ans,cost) print(ans)
def MI(): return list(map(int, input().split())) def LI(): return list(map(int, input().split())) N,M,X=MI() C=[] A=[] for i in range(N): L=LI() C.append(L[0]) A.append(L[1:]) ans=-1 for i in range(1<<N): tmp=[0]*M cost=0 for j in range(N): if 1&(i>>j): cost+=C[j] for m in range(M): tmp[m]+=A[j][m] if min(tmp)>=X: if ans==-1: ans=cost else: ans=min(ans,cost) print(ans)
22
24
463
446
def MI(): return list(map(int, input().split())) def LI(): return list(map(int, input().split())) N, M, X = MI() List = [] for i in range(N): CA = LI() List.append(CA) ans = -1 for i in range(1 << N): tmp = [0] * M cost = 0 for j in range(N): if 1 & (i >> j): cost += List[j][0] for k in range(M): tmp[k] += List[j][k + 1] if min(tmp) >= X: if ans == -1: ans = cost else: ans = min(ans, cost) print(ans)
def MI(): return list(map(int, input().split())) def LI(): return list(map(int, input().split())) N, M, X = MI() C = [] A = [] for i in range(N): L = LI() C.append(L[0]) A.append(L[1:]) ans = -1 for i in range(1 << N): tmp = [0] * M cost = 0 for j in range(N): if 1 & (i >> j): cost += C[j] for m in range(M): tmp[m] += A[j][m] if min(tmp) >= X: if ans == -1: ans = cost else: ans = min(ans, cost) print(ans)
false
8.333333
[ "-List = []", "+C = []", "+A = []", "- CA = LI()", "- List.append(CA)", "+ L = LI()", "+ C.append(L[0])", "+ A.append(L[1:])", "- cost += List[j][0]", "- for k in range(M):", "- tmp[k] += List[j][k + 1]", "- if min(tmp) >= X:", "- if ans == -1:", "- ans = cost", "- else:", "- ans = min(ans, cost)", "+ cost += C[j]", "+ for m in range(M):", "+ tmp[m] += A[j][m]", "+ if min(tmp) >= X:", "+ if ans == -1:", "+ ans = cost", "+ else:", "+ ans = min(ans, cost)" ]
false
0.037978
0.048175
0.788332
[ "s532075726", "s337406452" ]
u633068244
p00884
python
s281780788
s857327380
790
90
4,464
4,416
Accepted
Accepted
88.61
while 1: n = eval(input()) if n == 0: break ans = {} for i in range(n): group,name = input().split(":") if i == 0: first = group ans[group] = set(name[:-1].split(",")) while 1: for key in ans: flag = 0 if key == first: continue for key1 in ans: if key in ans[key1]: ans[key1] |= ans[key] ans[key1].discard(key) flag = 1 if flag == 0: break print(len(ans[first]))
while 1: n = eval(input()) if n == 0: break ans = {} for i in range(n): group,name = input().split(":") if i == 0: first = group ans[group] = set(name[:-1].split(",")) while 1: for key in ans: flag = 0 if key == first: continue for key1 in ans: if key in ans[key1]: ans[key1] |= ans[key] ans[key1].discard(key) flag = 1 if flag: del ans[key] break if flag == 0: break print(len(ans[first]))
19
22
431
463
while 1: n = eval(input()) if n == 0: break ans = {} for i in range(n): group, name = input().split(":") if i == 0: first = group ans[group] = set(name[:-1].split(",")) while 1: for key in ans: flag = 0 if key == first: continue for key1 in ans: if key in ans[key1]: ans[key1] |= ans[key] ans[key1].discard(key) flag = 1 if flag == 0: break print(len(ans[first]))
while 1: n = eval(input()) if n == 0: break ans = {} for i in range(n): group, name = input().split(":") if i == 0: first = group ans[group] = set(name[:-1].split(",")) while 1: for key in ans: flag = 0 if key == first: continue for key1 in ans: if key in ans[key1]: ans[key1] |= ans[key] ans[key1].discard(key) flag = 1 if flag: del ans[key] break if flag == 0: break print(len(ans[first]))
false
13.636364
[ "- while 1:", "- for key in ans:", "- flag = 0", "- if key == first:", "- continue", "- for key1 in ans:", "- if key in ans[key1]:", "- ans[key1] |= ans[key]", "- ans[key1].discard(key)", "- flag = 1", "- if flag == 0:", "+ while 1:", "+ for key in ans:", "+ flag = 0", "+ if key == first:", "+ continue", "+ for key1 in ans:", "+ if key in ans[key1]:", "+ ans[key1] |= ans[key]", "+ ans[key1].discard(key)", "+ flag = 1", "+ if flag:", "+ del ans[key]", "+ if flag == 0:", "+ break" ]
false
0.036693
0.04465
0.821797
[ "s281780788", "s857327380" ]
u411923565
p03695
python
s842503780
s097317489
28
23
9,172
9,128
Accepted
Accepted
17.86
#C - Colorful Leaderboard N = int(eval(input())) a = list(map(int,input().split())) mini = 0 color_list = [] for i in a: if (i//400)<8 and ((i//400 in color_list) == False): mini += 1 color_list.append(i//400) maxi = mini for j in a: if j >= 3200: maxi += 1 if mini == 0:#忘れてた mini = 1 print((mini,maxi))
#8 C - Colorful Leaderboard N = int(eval(input())) a = list(map(int,input().split())) seen = [False]*8 cnt = 0 cnt_3200 = 0 for i in a: i = i//400 if i >= 8: cnt_3200 += 1 elif (seen[i] == False): cnt += 1 seen[i] = True if cnt == 0: print((1,cnt_3200)) else: print((cnt,cnt+cnt_3200))
18
19
352
343
# C - Colorful Leaderboard N = int(eval(input())) a = list(map(int, input().split())) mini = 0 color_list = [] for i in a: if (i // 400) < 8 and ((i // 400 in color_list) == False): mini += 1 color_list.append(i // 400) maxi = mini for j in a: if j >= 3200: maxi += 1 if mini == 0: # 忘れてた mini = 1 print((mini, maxi))
# 8 C - Colorful Leaderboard N = int(eval(input())) a = list(map(int, input().split())) seen = [False] * 8 cnt = 0 cnt_3200 = 0 for i in a: i = i // 400 if i >= 8: cnt_3200 += 1 elif seen[i] == False: cnt += 1 seen[i] = True if cnt == 0: print((1, cnt_3200)) else: print((cnt, cnt + cnt_3200))
false
5.263158
[ "-# C - Colorful Leaderboard", "+# 8 C - Colorful Leaderboard", "-mini = 0", "-color_list = []", "+seen = [False] * 8", "+cnt = 0", "+cnt_3200 = 0", "- if (i // 400) < 8 and ((i // 400 in color_list) == False):", "- mini += 1", "- color_list.append(i // 400)", "-maxi = mini", "-for j in a:", "- if j >= 3200:", "- maxi += 1", "-if mini == 0: # 忘れてた", "- mini = 1", "-print((mini, maxi))", "+ i = i // 400", "+ if i >= 8:", "+ cnt_3200 += 1", "+ elif seen[i] == False:", "+ cnt += 1", "+ seen[i] = True", "+if cnt == 0:", "+ print((1, cnt_3200))", "+else:", "+ print((cnt, cnt + cnt_3200))" ]
false
0.008716
0.036083
0.241549
[ "s842503780", "s097317489" ]
u103902792
p03356
python
s732221877
s557984283
992
832
80,232
71,144
Accepted
Accepted
16.13
n,m = list(map(int,input().split())) P = list(map(int,input().split())) uf = {i:-1 for i in range(1,n+1)} def get_p(i): while uf[i] != i: if uf[i] == -1: return i i = uf[i] return i for _ in range(m): x,y = list(map(int,input().split())) if x > y: x,y = y,x if uf[x]== uf[y] == -1: uf[x] = x uf[y] = x elif uf[x] != -1 and uf[y] != -1: p = get_p(x) uf[x] = p index = y while index != uf[index]: index = uf[y] uf[y] = p y = index else: uf[index] = p else: if uf[x] == -1: p = get_p(y) else: p = get_p(x) uf[x] = p uf[y] = p ans = 0 for i, p in enumerate(P): if get_p(i+1) == get_p(p): ans += 1 print(ans)
n,m = list(map(int,input().split())) P = list(map(int,input().split())) uf = {i:i for i in range(1,n+1)} def get_parent(i): lst = [] while uf[i] != i: lst.append(i) i = uf[i] for l in lst[:-1]: uf[l] = i return i def unite(i,j): p = get_parent(i) uf[get_parent(j)] = p def same(i,j): return get_parent(i) == get_parent(j) for _ in range(m): x,y = list(map(int,input().split())) unite(x,y) ans = 0 for i in range(1,n+1): ans += int(same(P[i-1],uf[i])) print(ans)
41
30
754
518
n, m = list(map(int, input().split())) P = list(map(int, input().split())) uf = {i: -1 for i in range(1, n + 1)} def get_p(i): while uf[i] != i: if uf[i] == -1: return i i = uf[i] return i for _ in range(m): x, y = list(map(int, input().split())) if x > y: x, y = y, x if uf[x] == uf[y] == -1: uf[x] = x uf[y] = x elif uf[x] != -1 and uf[y] != -1: p = get_p(x) uf[x] = p index = y while index != uf[index]: index = uf[y] uf[y] = p y = index else: uf[index] = p else: if uf[x] == -1: p = get_p(y) else: p = get_p(x) uf[x] = p uf[y] = p ans = 0 for i, p in enumerate(P): if get_p(i + 1) == get_p(p): ans += 1 print(ans)
n, m = list(map(int, input().split())) P = list(map(int, input().split())) uf = {i: i for i in range(1, n + 1)} def get_parent(i): lst = [] while uf[i] != i: lst.append(i) i = uf[i] for l in lst[:-1]: uf[l] = i return i def unite(i, j): p = get_parent(i) uf[get_parent(j)] = p def same(i, j): return get_parent(i) == get_parent(j) for _ in range(m): x, y = list(map(int, input().split())) unite(x, y) ans = 0 for i in range(1, n + 1): ans += int(same(P[i - 1], uf[i])) print(ans)
false
26.829268
[ "-uf = {i: -1 for i in range(1, n + 1)}", "+uf = {i: i for i in range(1, n + 1)}", "-def get_p(i):", "+def get_parent(i):", "+ lst = []", "- if uf[i] == -1:", "- return i", "+ lst.append(i)", "+ for l in lst[:-1]:", "+ uf[l] = i", "+", "+", "+def unite(i, j):", "+ p = get_parent(i)", "+ uf[get_parent(j)] = p", "+", "+", "+def same(i, j):", "+ return get_parent(i) == get_parent(j)", "- if x > y:", "- x, y = y, x", "- if uf[x] == uf[y] == -1:", "- uf[x] = x", "- uf[y] = x", "- elif uf[x] != -1 and uf[y] != -1:", "- p = get_p(x)", "- uf[x] = p", "- index = y", "- while index != uf[index]:", "- index = uf[y]", "- uf[y] = p", "- y = index", "- else:", "- uf[index] = p", "- else:", "- if uf[x] == -1:", "- p = get_p(y)", "- else:", "- p = get_p(x)", "- uf[x] = p", "- uf[y] = p", "+ unite(x, y)", "-for i, p in enumerate(P):", "- if get_p(i + 1) == get_p(p):", "- ans += 1", "+for i in range(1, n + 1):", "+ ans += int(same(P[i - 1], uf[i]))" ]
false
0.107302
0.0402
2.669216
[ "s732221877", "s557984283" ]
u067299340
p00010
python
s386023601
s122823497
20
10
4,336
4,332
Accepted
Accepted
50
def calc(a,b,c,d,e,f): A=2*(c-a) B=2*(d-b) C=a*a-c*c+b*b-d*d D=2*(e-a) E=2*(f-b) F=a*a-e*e+b*b-f*f N=(A*E-D*B) X=(B*F-E*C)/N Y=(C*D-F*A)/N R=((X-a)**2+(Y-b)**2)**0.5 return tuple(map(round,[X,Y,R],[3]*3)) l=[list(map(float,input().split()))for i in range(eval(input()))] for k in l:print("%.3f %.3f %.3f"%(calc(*k)))
def calc(a,b,c,d,e,f): A=2*(c-a) B=2*(d-b) C=a*a-c*c+b*b-d*d D=2*(e-a) E=2*(f-b) F=a*a-e*e+b*b-f*f N=(A*E-D*B) X=(B*F-E*C)/N Y=(C*D-F*A)/N return tuple(map(round,[X,Y,((X-a)**2+(Y-b)**2)**0.5],[3]*3)) l=[list(map(float,input().split()))for i in range(eval(input()))] for k in l:print("%.3f %.3f %.3f"%(calc(*k)))
14
13
330
324
def calc(a, b, c, d, e, f): A = 2 * (c - a) B = 2 * (d - b) C = a * a - c * c + b * b - d * d D = 2 * (e - a) E = 2 * (f - b) F = a * a - e * e + b * b - f * f N = A * E - D * B X = (B * F - E * C) / N Y = (C * D - F * A) / N R = ((X - a) ** 2 + (Y - b) ** 2) ** 0.5 return tuple(map(round, [X, Y, R], [3] * 3)) l = [list(map(float, input().split())) for i in range(eval(input()))] for k in l: print("%.3f %.3f %.3f" % (calc(*k)))
def calc(a, b, c, d, e, f): A = 2 * (c - a) B = 2 * (d - b) C = a * a - c * c + b * b - d * d D = 2 * (e - a) E = 2 * (f - b) F = a * a - e * e + b * b - f * f N = A * E - D * B X = (B * F - E * C) / N Y = (C * D - F * A) / N return tuple(map(round, [X, Y, ((X - a) ** 2 + (Y - b) ** 2) ** 0.5], [3] * 3)) l = [list(map(float, input().split())) for i in range(eval(input()))] for k in l: print("%.3f %.3f %.3f" % (calc(*k)))
false
7.142857
[ "- R = ((X - a) ** 2 + (Y - b) ** 2) ** 0.5", "- return tuple(map(round, [X, Y, R], [3] * 3))", "+ return tuple(map(round, [X, Y, ((X - a) ** 2 + (Y - b) ** 2) ** 0.5], [3] * 3))" ]
false
0.039181
0.031697
1.236128
[ "s386023601", "s122823497" ]
u075012704
p03464
python
s217039175
s662824047
1,986
500
14,252
63,984
Accepted
Accepted
74.82
K = int(eval(input())) A = list(map(int, input().split())) lo = 2 hi = 10**18 def check1(people): for a in A: people = (people // a) * a if people > 2: return False else: return True def check2(people): for a in A: people = (people // a) * a if people < 2: return False else: return True for i in range(100): center = (lo + hi) // 2 if check1(center): lo = center else: hi = center Mz = center lo = 2 hi = 10**18 for i in range(100): center = (lo + hi) // 2 if center > Mz: hi = center continue if check2(center): hi = center else: lo = center mz = hi if Mz >= mz: print((mz, Mz)) else: print((-1))
K = int(eval(input())) A = list(map(int, input().split())) # 最後に2人以上残るような最小のNを探す ok, ng = 10 ** 18, 0 while abs(ok - ng) > 1: n = (ok + ng) // 2 x = n for a in A: x = (x // a) * a if x >= 2: ok = n else: ng = n m = ok # 最後に2人以下になるような最大のNを探す ok, ng = 0, 10 ** 18 while abs(ok - ng) > 1: x = (ok + ng) // 2 n = x for a in A: x = x // a * a if x <= 2: ok = n else: ng = n M = ok # 条件を満たすかチェック mx, Mx = m, M for a in A: mx = (mx // a) * a Mx = (Mx // a) * a if mx == 2 and Mx == 2: print((m, M)) else: print((-1))
52
41
806
650
K = int(eval(input())) A = list(map(int, input().split())) lo = 2 hi = 10**18 def check1(people): for a in A: people = (people // a) * a if people > 2: return False else: return True def check2(people): for a in A: people = (people // a) * a if people < 2: return False else: return True for i in range(100): center = (lo + hi) // 2 if check1(center): lo = center else: hi = center Mz = center lo = 2 hi = 10**18 for i in range(100): center = (lo + hi) // 2 if center > Mz: hi = center continue if check2(center): hi = center else: lo = center mz = hi if Mz >= mz: print((mz, Mz)) else: print((-1))
K = int(eval(input())) A = list(map(int, input().split())) # 最後に2人以上残るような最小のNを探す ok, ng = 10**18, 0 while abs(ok - ng) > 1: n = (ok + ng) // 2 x = n for a in A: x = (x // a) * a if x >= 2: ok = n else: ng = n m = ok # 最後に2人以下になるような最大のNを探す ok, ng = 0, 10**18 while abs(ok - ng) > 1: x = (ok + ng) // 2 n = x for a in A: x = x // a * a if x <= 2: ok = n else: ng = n M = ok # 条件を満たすかチェック mx, Mx = m, M for a in A: mx = (mx // a) * a Mx = (Mx // a) * a if mx == 2 and Mx == 2: print((m, M)) else: print((-1))
false
21.153846
[ "-lo = 2", "-hi = 10**18", "-", "-", "-def check1(people):", "+# 最後に2人以上残るような最小のNを探す", "+ok, ng = 10**18, 0", "+while abs(ok - ng) > 1:", "+ n = (ok + ng) // 2", "+ x = n", "- people = (people // a) * a", "- if people > 2:", "- return False", "+ x = (x // a) * a", "+ if x >= 2:", "+ ok = n", "- return True", "-", "-", "-def check2(people):", "+ ng = n", "+m = ok", "+# 最後に2人以下になるような最大のNを探す", "+ok, ng = 0, 10**18", "+while abs(ok - ng) > 1:", "+ x = (ok + ng) // 2", "+ n = x", "- people = (people // a) * a", "- if people < 2:", "- return False", "+ x = x // a * a", "+ if x <= 2:", "+ ok = n", "- return True", "-", "-", "-for i in range(100):", "- center = (lo + hi) // 2", "- if check1(center):", "- lo = center", "- else:", "- hi = center", "-Mz = center", "-lo = 2", "-hi = 10**18", "-for i in range(100):", "- center = (lo + hi) // 2", "- if center > Mz:", "- hi = center", "- continue", "- if check2(center):", "- hi = center", "- else:", "- lo = center", "-mz = hi", "-if Mz >= mz:", "- print((mz, Mz))", "+ ng = n", "+M = ok", "+# 条件を満たすかチェック", "+mx, Mx = m, M", "+for a in A:", "+ mx = (mx // a) * a", "+ Mx = (Mx // a) * a", "+if mx == 2 and Mx == 2:", "+ print((m, M))" ]
false
0.04825
0.041162
1.172192
[ "s217039175", "s662824047" ]
u729133443
p03109
python
s231158317
s752347054
160
19
38,384
2,940
Accepted
Accepted
88.12
print(('TBD'*(input()[5:]>'04/30')or'Heisei'))
print(('TBD'*(input()[5:7]>'04')or'Heisei'))
1
1
44
42
print(("TBD" * (input()[5:] > "04/30") or "Heisei"))
print(("TBD" * (input()[5:7] > "04") or "Heisei"))
false
0
[ "-print((\"TBD\" * (input()[5:] > \"04/30\") or \"Heisei\"))", "+print((\"TBD\" * (input()[5:7] > \"04\") or \"Heisei\"))" ]
false
0.033539
0.068229
0.491564
[ "s231158317", "s752347054" ]
u499381410
p03634
python
s711306986
s198880091
696
594
96,432
79,316
Accepted
Accepted
14.66
from collections import defaultdict, deque from heapq import heappush, heappop, heapify import math import bisect import random import sys def LI(): return list(map(int, sys.stdin.readline().split())) def I(): return int(sys.stdin.readline()) def LIM(): return list([int(x) - 1 for x in sys.stdin.readline().split()]) def LS(): return sys.stdin.readline().split() def S(): return sys.stdin.readline() def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def LIRM(n): return [LIM() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] mod = 1000000007 n = I() graph = [[] for _ in range(n)] for _ in range(n-1): a, b, c = list(map(int, sys.stdin.readline().split())) graph[a-1] += [[b-1, c]] graph[b-1] += [[a-1, c]] q, k = LI() q_ab = LIRM(q) dist = n * [-1] dist[k-1] = 0 que = deque([k-1]) while que: cur = que.pop() for nxt, c in graph[cur]: if dist[nxt] == -1: dist[nxt] = dist[cur] + c que += [nxt] for a, b in q_ab: print((dist[a] + dist[b]))
from collections import defaultdict, deque, Counter from heapq import heappush, heappop, heapify import math import bisect import random from itertools import permutations, accumulate, combinations, product import sys import string from bisect import bisect_left, bisect_right from math import factorial, ceil, floor from operator import mul from functools import reduce sys.setrecursionlimit(2147483647) INF = 10 ** 13 def LI(): return list(map(int, sys.stdin.buffer.readline().split())) def I(): return int(sys.stdin.buffer.readline()) def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split() def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8') def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] def SRL(n): return [list(S()) for i in range(n)] def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)] mod = 1000000007 n = I() G = [[] for _ in range(n)] for a, b, c in LIR(n - 1): G[a - 1] += [(b - 1, c)] G[b - 1] += [(a - 1, c)] q, k = LI() dq = deque([k - 1]) dist = [-1] * n dist[k - 1] = 0 while dq: u = dq.pop() for v, c in G[u]: if dist[v] == -1: dist[v] = dist[u] + c dq += [v] for _ in range(q): x, y = LI() print((dist[x - 1] + dist[y - 1]))
49
51
1,146
1,436
from collections import defaultdict, deque from heapq import heappush, heappop, heapify import math import bisect import random import sys def LI(): return list(map(int, sys.stdin.readline().split())) def I(): return int(sys.stdin.readline()) def LIM(): return list([int(x) - 1 for x in sys.stdin.readline().split()]) def LS(): return sys.stdin.readline().split() def S(): return sys.stdin.readline() def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def LIRM(n): return [LIM() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] mod = 1000000007 n = I() graph = [[] for _ in range(n)] for _ in range(n - 1): a, b, c = list(map(int, sys.stdin.readline().split())) graph[a - 1] += [[b - 1, c]] graph[b - 1] += [[a - 1, c]] q, k = LI() q_ab = LIRM(q) dist = n * [-1] dist[k - 1] = 0 que = deque([k - 1]) while que: cur = que.pop() for nxt, c in graph[cur]: if dist[nxt] == -1: dist[nxt] = dist[cur] + c que += [nxt] for a, b in q_ab: print((dist[a] + dist[b]))
from collections import defaultdict, deque, Counter from heapq import heappush, heappop, heapify import math import bisect import random from itertools import permutations, accumulate, combinations, product import sys import string from bisect import bisect_left, bisect_right from math import factorial, ceil, floor from operator import mul from functools import reduce sys.setrecursionlimit(2147483647) INF = 10**13 def LI(): return list(map(int, sys.stdin.buffer.readline().split())) def I(): return int(sys.stdin.buffer.readline()) def LS(): return sys.stdin.buffer.readline().rstrip().decode("utf-8").split() def S(): return sys.stdin.buffer.readline().rstrip().decode("utf-8") def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] def SRL(n): return [list(S()) for i in range(n)] def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)] mod = 1000000007 n = I() G = [[] for _ in range(n)] for a, b, c in LIR(n - 1): G[a - 1] += [(b - 1, c)] G[b - 1] += [(a - 1, c)] q, k = LI() dq = deque([k - 1]) dist = [-1] * n dist[k - 1] = 0 while dq: u = dq.pop() for v, c in G[u]: if dist[v] == -1: dist[v] = dist[u] + c dq += [v] for _ in range(q): x, y = LI() print((dist[x - 1] + dist[y - 1]))
false
3.921569
[ "-from collections import defaultdict, deque", "+from collections import defaultdict, deque, Counter", "+from itertools import permutations, accumulate, combinations, product", "+import string", "+from bisect import bisect_left, bisect_right", "+from math import factorial, ceil, floor", "+from operator import mul", "+from functools import reduce", "+", "+sys.setrecursionlimit(2147483647)", "+INF = 10**13", "- return list(map(int, sys.stdin.readline().split()))", "+ return list(map(int, sys.stdin.buffer.readline().split()))", "- return int(sys.stdin.readline())", "-", "-", "-def LIM():", "- return list([int(x) - 1 for x in sys.stdin.readline().split()])", "+ return int(sys.stdin.buffer.readline())", "- return sys.stdin.readline().split()", "+ return sys.stdin.buffer.readline().rstrip().decode(\"utf-8\").split()", "- return sys.stdin.readline()", "+ return sys.stdin.buffer.readline().rstrip().decode(\"utf-8\")", "-def LIRM(n):", "- return [LIM() for i in range(n)]", "-", "-", "+def SRL(n):", "+ return [list(S()) for i in range(n)]", "+", "+", "+def MSRL(n):", "+ return [[int(j) for j in list(S())] for i in range(n)]", "+", "+", "-graph = [[] for _ in range(n)]", "-for _ in range(n - 1):", "- a, b, c = list(map(int, sys.stdin.readline().split()))", "- graph[a - 1] += [[b - 1, c]]", "- graph[b - 1] += [[a - 1, c]]", "+G = [[] for _ in range(n)]", "+for a, b, c in LIR(n - 1):", "+ G[a - 1] += [(b - 1, c)]", "+ G[b - 1] += [(a - 1, c)]", "-q_ab = LIRM(q)", "-dist = n * [-1]", "+dq = deque([k - 1])", "+dist = [-1] * n", "-que = deque([k - 1])", "-while que:", "- cur = que.pop()", "- for nxt, c in graph[cur]:", "- if dist[nxt] == -1:", "- dist[nxt] = dist[cur] + c", "- que += [nxt]", "-for a, b in q_ab:", "- print((dist[a] + dist[b]))", "+while dq:", "+ u = dq.pop()", "+ for v, c in G[u]:", "+ if dist[v] == -1:", "+ dist[v] = dist[u] + c", "+ dq += [v]", "+for _ in range(q):", "+ x, y = LI()", "+ print((dist[x - 1] + dist[y - 1]))" ]
false
0.06661
0.126335
0.527251
[ "s711306986", "s198880091" ]
u758815106
p03169
python
s273134022
s466882275
1,974
534
397,984
295,736
Accepted
Accepted
72.95
import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) N = int(eval(input())) a = list(map(int, input().split())) one = a.count(1) two = a.count(2) three = a.count(3) dp = [[[-1] * 301 for _ in range(301)] for _ in range(301)] def rec(i, j, k): if dp[i][j][k] >= 0: return dp[i][j][k] if i == 0 and j == 0 and k == 0: return 0.0 res = 0.0 if i > 0: res += rec(i - 1, j, k) * i if j > 0: res += rec(i + 1, j - 1, k) * j if k > 0: res += rec(i, j + 1, k - 1) * k res += N res /= i + j + k dp[i][j][k] = res return res res = rec(one, two, three) print(res)
import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) N = int(eval(input())) a = list(map(int, input().split())) one = a.count(1) two = a.count(2) three = a.count(3) dp = [[[0.0] * (N + 1) for _ in range((N + 1))] for _ in range((N + 1))] max_one = one + two + three max_two = two + three max_three = three for k in range(max_three + 1): for j in range(max_two + 1 - k): for i in range(max_one + 1 - j - k): if i + j + k == 0: continue else: r = N if i > 0: r += dp[i - 1][j][k] * i if j > 0: r += dp[i + 1][j - 1][k] * j if k > 0: r += dp[i][j + 1][k - 1] * k dp[i][j][k] = r / (i + j + k) print((dp[one][two][three]))
39
35
698
831
import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) N = int(eval(input())) a = list(map(int, input().split())) one = a.count(1) two = a.count(2) three = a.count(3) dp = [[[-1] * 301 for _ in range(301)] for _ in range(301)] def rec(i, j, k): if dp[i][j][k] >= 0: return dp[i][j][k] if i == 0 and j == 0 and k == 0: return 0.0 res = 0.0 if i > 0: res += rec(i - 1, j, k) * i if j > 0: res += rec(i + 1, j - 1, k) * j if k > 0: res += rec(i, j + 1, k - 1) * k res += N res /= i + j + k dp[i][j][k] = res return res res = rec(one, two, three) print(res)
import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) N = int(eval(input())) a = list(map(int, input().split())) one = a.count(1) two = a.count(2) three = a.count(3) dp = [[[0.0] * (N + 1) for _ in range((N + 1))] for _ in range((N + 1))] max_one = one + two + three max_two = two + three max_three = three for k in range(max_three + 1): for j in range(max_two + 1 - k): for i in range(max_one + 1 - j - k): if i + j + k == 0: continue else: r = N if i > 0: r += dp[i - 1][j][k] * i if j > 0: r += dp[i + 1][j - 1][k] * j if k > 0: r += dp[i][j + 1][k - 1] * k dp[i][j][k] = r / (i + j + k) print((dp[one][two][three]))
false
10.25641
[ "-dp = [[[-1] * 301 for _ in range(301)] for _ in range(301)]", "-", "-", "-def rec(i, j, k):", "- if dp[i][j][k] >= 0:", "- return dp[i][j][k]", "- if i == 0 and j == 0 and k == 0:", "- return 0.0", "- res = 0.0", "- if i > 0:", "- res += rec(i - 1, j, k) * i", "- if j > 0:", "- res += rec(i + 1, j - 1, k) * j", "- if k > 0:", "- res += rec(i, j + 1, k - 1) * k", "- res += N", "- res /= i + j + k", "- dp[i][j][k] = res", "- return res", "-", "-", "-res = rec(one, two, three)", "-print(res)", "+dp = [[[0.0] * (N + 1) for _ in range((N + 1))] for _ in range((N + 1))]", "+max_one = one + two + three", "+max_two = two + three", "+max_three = three", "+for k in range(max_three + 1):", "+ for j in range(max_two + 1 - k):", "+ for i in range(max_one + 1 - j - k):", "+ if i + j + k == 0:", "+ continue", "+ else:", "+ r = N", "+ if i > 0:", "+ r += dp[i - 1][j][k] * i", "+ if j > 0:", "+ r += dp[i + 1][j - 1][k] * j", "+ if k > 0:", "+ r += dp[i][j + 1][k - 1] * k", "+ dp[i][j][k] = r / (i + j + k)", "+print((dp[one][two][three]))" ]
false
1.19746
0.042632
28.088126
[ "s273134022", "s466882275" ]
u256678932
p02381
python
s787273670
s219395447
30
20
7,764
5,716
Accepted
Accepted
33.33
import math while True: n = int(eval(input())) if 0 == n: break points = list(map(int, input().split(' '))) m = sum(points)/n s = math.sqrt(sum([ (s - m)**2 for s in points ])/n) print(('{:.5f}'.format(s)))
from math import sqrt def sd(nums): n = len(nums) ave = sum(nums)/n return abs(sqrt(sum([(s - ave)**2 for s in nums])/n)) def main(): while True: n = eval(input()) if n == '0': break nums = [int(x) for x in input().split()] print(("{:f}".format(sd(nums)))) if __name__ == '__main__': main()
13
20
246
374
import math while True: n = int(eval(input())) if 0 == n: break points = list(map(int, input().split(" "))) m = sum(points) / n s = math.sqrt(sum([(s - m) ** 2 for s in points]) / n) print(("{:.5f}".format(s)))
from math import sqrt def sd(nums): n = len(nums) ave = sum(nums) / n return abs(sqrt(sum([(s - ave) ** 2 for s in nums]) / n)) def main(): while True: n = eval(input()) if n == "0": break nums = [int(x) for x in input().split()] print(("{:f}".format(sd(nums)))) if __name__ == "__main__": main()
false
35
[ "-import math", "+from math import sqrt", "-while True:", "- n = int(eval(input()))", "- if 0 == n:", "- break", "- points = list(map(int, input().split(\" \")))", "- m = sum(points) / n", "- s = math.sqrt(sum([(s - m) ** 2 for s in points]) / n)", "- print((\"{:.5f}\".format(s)))", "+", "+def sd(nums):", "+ n = len(nums)", "+ ave = sum(nums) / n", "+ return abs(sqrt(sum([(s - ave) ** 2 for s in nums]) / n))", "+", "+", "+def main():", "+ while True:", "+ n = eval(input())", "+ if n == \"0\":", "+ break", "+ nums = [int(x) for x in input().split()]", "+ print((\"{:f}\".format(sd(nums))))", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.121985
0.041654
2.928553
[ "s787273670", "s219395447" ]
u597455618
p02848
python
s359748534
s397537865
32
19
4,468
3,060
Accepted
Accepted
40.62
n = int(input()) s = input() for i in range(len(s)): print(chr(((ord(s[i])+n)%91)%65+65), end = "")
n = int(eval(input())) s = eval(input()) alph = "" for i in range(26): alph += chr(65+i) print((s.translate(str.maketrans(alph, alph[n:] + alph[:n]))))
4
6
104
144
n = int(input()) s = input() for i in range(len(s)): print(chr(((ord(s[i]) + n) % 91) % 65 + 65), end="")
n = int(eval(input())) s = eval(input()) alph = "" for i in range(26): alph += chr(65 + i) print((s.translate(str.maketrans(alph, alph[n:] + alph[:n]))))
false
33.333333
[ "-n = int(input())", "-s = input()", "-for i in range(len(s)):", "- print(chr(((ord(s[i]) + n) % 91) % 65 + 65), end=\"\")", "+n = int(eval(input()))", "+s = eval(input())", "+alph = \"\"", "+for i in range(26):", "+ alph += chr(65 + i)", "+print((s.translate(str.maketrans(alph, alph[n:] + alph[:n]))))" ]
false
0.034536
0.036515
0.94582
[ "s359748534", "s397537865" ]
u203669169
p02759
python
s711813508
s301861214
37
18
5,048
2,940
Accepted
Accepted
51.35
from fractions import gcd from collections import Counter, deque, defaultdict from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort from itertools import accumulate, product, permutations, combinations N = int(eval(input())) a = int(N / 2) if N % 2 == 1: a +=1 print(a)
N = int(eval(input())) print((int(N / 2 + N % 2)))
12
3
393
45
from fractions import gcd from collections import Counter, deque, defaultdict from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort from itertools import accumulate, product, permutations, combinations N = int(eval(input())) a = int(N / 2) if N % 2 == 1: a += 1 print(a)
N = int(eval(input())) print((int(N / 2 + N % 2)))
false
75
[ "-from fractions import gcd", "-from collections import Counter, deque, defaultdict", "-from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge", "-from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort", "-from itertools import accumulate, product, permutations, combinations", "-", "-a = int(N / 2)", "-if N % 2 == 1:", "- a += 1", "-print(a)", "+print((int(N / 2 + N % 2)))" ]
false
0.034244
0.034475
0.993288
[ "s711813508", "s301861214" ]
u332906195
p02948
python
s694631375
s389178323
571
441
18,232
26,984
Accepted
Accepted
22.77
import heapq maxB = 10 ** 1 N, M = list(map(int, input().split())) AB = [] for _ in range(N): A, B = list(map(int, input().split())) AB.append((maxB - B, A)) AB.sort(key=lambda x: x[1]) ans, heap, idx, lAB = 0, [], 0, len(AB) for i in range(M): while idx < lAB and AB[idx][1] <= i + 1: heapq.heappush(heap, AB[idx]) idx += 1 if len(heap) > 0: ans += maxB - heapq.heappop(heap)[0] print(ans)
import heapq N, M = list(map(int, input().split())) AB = {i + 1: [] for i in range(10 ** 5)} for _ in range(N): A, B = list(map(int, input().split())) AB[A].append(B) ans, h = 0, [] for i in range(1, M + 1): for b in AB[i]: heapq.heappush(h, -b) if len(h) > 0: ans -= heapq.heappop(h) print(ans)
20
16
442
334
import heapq maxB = 10**1 N, M = list(map(int, input().split())) AB = [] for _ in range(N): A, B = list(map(int, input().split())) AB.append((maxB - B, A)) AB.sort(key=lambda x: x[1]) ans, heap, idx, lAB = 0, [], 0, len(AB) for i in range(M): while idx < lAB and AB[idx][1] <= i + 1: heapq.heappush(heap, AB[idx]) idx += 1 if len(heap) > 0: ans += maxB - heapq.heappop(heap)[0] print(ans)
import heapq N, M = list(map(int, input().split())) AB = {i + 1: [] for i in range(10**5)} for _ in range(N): A, B = list(map(int, input().split())) AB[A].append(B) ans, h = 0, [] for i in range(1, M + 1): for b in AB[i]: heapq.heappush(h, -b) if len(h) > 0: ans -= heapq.heappop(h) print(ans)
false
20
[ "-maxB = 10**1", "-AB = []", "+AB = {i + 1: [] for i in range(10**5)}", "- AB.append((maxB - B, A))", "-AB.sort(key=lambda x: x[1])", "-ans, heap, idx, lAB = 0, [], 0, len(AB)", "-for i in range(M):", "- while idx < lAB and AB[idx][1] <= i + 1:", "- heapq.heappush(heap, AB[idx])", "- idx += 1", "- if len(heap) > 0:", "- ans += maxB - heapq.heappop(heap)[0]", "+ AB[A].append(B)", "+ans, h = 0, []", "+for i in range(1, M + 1):", "+ for b in AB[i]:", "+ heapq.heappush(h, -b)", "+ if len(h) > 0:", "+ ans -= heapq.heappop(h)" ]
false
0.037877
0.09678
0.391371
[ "s694631375", "s389178323" ]
u366886346
p03994
python
s847741943
s079913026
79
65
10,100
10,228
Accepted
Accepted
17.72
s=eval(input()) k=int(eval(input())) n=len(s) num=[0]*n for i in range(n): if s[i]!="a": num[i]=123-ord(s[i]) if sum(num)>=k: ans="" for i in range(n-1): if k>=num[i]: k-=num[i] ans+="a" else: ans+=s[i] if k>=num[-1]: ans+="a" else: ans+=chr(97+((ord(s[-1])-97+k)%26)) else: k-=sum(num) ans="a"*(n-1) ans+=chr(97+(k%26)) print(ans)
s=eval(input()) k=int(eval(input())) num=[(123-ord(s[i]))%26 for i in range(len(s))] ans="" for i in range(len(s)-1): if num[i]<=k: ans+="a" k-=num[i] else: ans+=s[i] k%=26 if num[-1]<=k: ans+=chr(97+k-num[-1]) else: ans+=chr(ord(s[-1])+k) print(ans)
24
16
451
294
s = eval(input()) k = int(eval(input())) n = len(s) num = [0] * n for i in range(n): if s[i] != "a": num[i] = 123 - ord(s[i]) if sum(num) >= k: ans = "" for i in range(n - 1): if k >= num[i]: k -= num[i] ans += "a" else: ans += s[i] if k >= num[-1]: ans += "a" else: ans += chr(97 + ((ord(s[-1]) - 97 + k) % 26)) else: k -= sum(num) ans = "a" * (n - 1) ans += chr(97 + (k % 26)) print(ans)
s = eval(input()) k = int(eval(input())) num = [(123 - ord(s[i])) % 26 for i in range(len(s))] ans = "" for i in range(len(s) - 1): if num[i] <= k: ans += "a" k -= num[i] else: ans += s[i] k %= 26 if num[-1] <= k: ans += chr(97 + k - num[-1]) else: ans += chr(ord(s[-1]) + k) print(ans)
false
33.333333
[ "-n = len(s)", "-num = [0] * n", "-for i in range(n):", "- if s[i] != \"a\":", "- num[i] = 123 - ord(s[i])", "-if sum(num) >= k:", "- ans = \"\"", "- for i in range(n - 1):", "- if k >= num[i]:", "- k -= num[i]", "- ans += \"a\"", "- else:", "- ans += s[i]", "- if k >= num[-1]:", "+num = [(123 - ord(s[i])) % 26 for i in range(len(s))]", "+ans = \"\"", "+for i in range(len(s) - 1):", "+ if num[i] <= k:", "+ k -= num[i]", "- ans += chr(97 + ((ord(s[-1]) - 97 + k) % 26))", "+ ans += s[i]", "+k %= 26", "+if num[-1] <= k:", "+ ans += chr(97 + k - num[-1])", "- k -= sum(num)", "- ans = \"a\" * (n - 1)", "- ans += chr(97 + (k % 26))", "+ ans += chr(ord(s[-1]) + k)" ]
false
0.038374
0.037625
1.019913
[ "s847741943", "s079913026" ]
u994988729
p03800
python
s505233824
s824688076
162
111
5,716
4,852
Accepted
Accepted
31.48
N = int(eval(input())) S = eval(input()) S = S[-1] + S + S[0] # sheep:1, wolf:0 isOK = False for x, y in [(1, 1), (1, 0), (0, 1), (0, 0)]: A = [-1] * len(S) A[0] = x A[1] = y for i in range(1, len(S)-1): if A[i]: # 羊の場合 A[i + 1] = A[i - 1] if S[i] == "o" else 1 - A[i - 1] else: # 狼の場合 A[i + 1] = A[i - 1] if S[i] == "x" else 1 - A[i - 1] if A[0] == A[-2] and A[1] == A[-1]: isOK = True break if isOK: ans = ["S" if i else "W" for i in A[1:-1]] ans = "".join(ans) else: ans = -1 print(ans)
from itertools import product N = int(eval(input())) S = eval(input()) S += S[0] def isOK(x, y): WS = [-1] * (N + 2) WS[0] = x WS[1] = y for i in range(1, N + 1): if S[i] == "o": WS[i + 1] = WS[i - 1] if WS[i] else 1 - WS[i - 1] else: WS[i + 1] = 1 - WS[i - 1] if WS[i] else WS[i - 1] if WS[0] == WS[-2] and WS[1] == WS[-1]: return WS[:-2] else: return [] for x, y in product(list(range(2)), repeat=2): ws = isOK(x, y) if len(ws) > 0: break if len(ws) == 0: ans = -1 else: ans = "" for x in ws: if x: ans += "S" else: ans += "W" print(ans)
27
37
598
712
N = int(eval(input())) S = eval(input()) S = S[-1] + S + S[0] # sheep:1, wolf:0 isOK = False for x, y in [(1, 1), (1, 0), (0, 1), (0, 0)]: A = [-1] * len(S) A[0] = x A[1] = y for i in range(1, len(S) - 1): if A[i]: # 羊の場合 A[i + 1] = A[i - 1] if S[i] == "o" else 1 - A[i - 1] else: # 狼の場合 A[i + 1] = A[i - 1] if S[i] == "x" else 1 - A[i - 1] if A[0] == A[-2] and A[1] == A[-1]: isOK = True break if isOK: ans = ["S" if i else "W" for i in A[1:-1]] ans = "".join(ans) else: ans = -1 print(ans)
from itertools import product N = int(eval(input())) S = eval(input()) S += S[0] def isOK(x, y): WS = [-1] * (N + 2) WS[0] = x WS[1] = y for i in range(1, N + 1): if S[i] == "o": WS[i + 1] = WS[i - 1] if WS[i] else 1 - WS[i - 1] else: WS[i + 1] = 1 - WS[i - 1] if WS[i] else WS[i - 1] if WS[0] == WS[-2] and WS[1] == WS[-1]: return WS[:-2] else: return [] for x, y in product(list(range(2)), repeat=2): ws = isOK(x, y) if len(ws) > 0: break if len(ws) == 0: ans = -1 else: ans = "" for x in ws: if x: ans += "S" else: ans += "W" print(ans)
false
27.027027
[ "+from itertools import product", "+", "-S = S[-1] + S + S[0]", "-# sheep:1, wolf:0", "-isOK = False", "-for x, y in [(1, 1), (1, 0), (0, 1), (0, 0)]:", "- A = [-1] * len(S)", "- A[0] = x", "- A[1] = y", "- for i in range(1, len(S) - 1):", "- if A[i]: # 羊の場合", "- A[i + 1] = A[i - 1] if S[i] == \"o\" else 1 - A[i - 1]", "- else: # 狼の場合", "- A[i + 1] = A[i - 1] if S[i] == \"x\" else 1 - A[i - 1]", "- if A[0] == A[-2] and A[1] == A[-1]:", "- isOK = True", "+S += S[0]", "+", "+", "+def isOK(x, y):", "+ WS = [-1] * (N + 2)", "+ WS[0] = x", "+ WS[1] = y", "+ for i in range(1, N + 1):", "+ if S[i] == \"o\":", "+ WS[i + 1] = WS[i - 1] if WS[i] else 1 - WS[i - 1]", "+ else:", "+ WS[i + 1] = 1 - WS[i - 1] if WS[i] else WS[i - 1]", "+ if WS[0] == WS[-2] and WS[1] == WS[-1]:", "+ return WS[:-2]", "+ else:", "+ return []", "+", "+", "+for x, y in product(list(range(2)), repeat=2):", "+ ws = isOK(x, y)", "+ if len(ws) > 0:", "-if isOK:", "- ans = [\"S\" if i else \"W\" for i in A[1:-1]]", "- ans = \"\".join(ans)", "+if len(ws) == 0:", "+ ans = -1", "- ans = -1", "+ ans = \"\"", "+ for x in ws:", "+ if x:", "+ ans += \"S\"", "+ else:", "+ ans += \"W\"" ]
false
0.123929
0.046774
2.649541
[ "s505233824", "s824688076" ]
u432551953
p02792
python
s633001333
s884717280
300
276
42,972
40,428
Accepted
Accepted
8
import sys input = sys.stdin.readline from operator import itemgetter sys.setrecursionlimit(10000000) INF = 10**30 def keta(n): return len(str(n)) def make(n, l, r): ans = 0 sn = str(n) for i in range(5): if keta(n) > 2+i: ans += 10 ** i elif keta(n) == 2 + i: if sn[0] > str(l): ans += 10 ** i elif sn[0] == str(l): if sn[-1] < r: ans += int(sn[1:-1]) else: if sn[1:-1] == '': ans += 1 else: ans += int(sn[1:-1]) + 1 else: pass else: pass if l == r: ans += 1 return ans def main(): n = int(input().strip()) ans = 0 for i in range(1, n+1): p = make(n, str(i)[-1], str(i)[0]) if i % 10 == 0: continue # if i < 10: # p += 1 # print("i ,p: ", i, p) ans += p print(ans) if __name__ == '__main__': main()
import sys input = sys.stdin.readline from operator import itemgetter sys.setrecursionlimit(10000000) INF = 10**30 from collections import defaultdict def main(): n = int(input().strip()) d = defaultdict(int) for i in range(1, n+1): ds = str(i) d[(ds[0], ds[-1])] += 1 ans = 0 for i in range(1, 10): for j in range(1, 10): si = str(i) sj = str(j) ans += d[(si, sj)] * d[(sj, si)] print(ans) if __name__ == '__main__': main()
48
24
1,122
539
import sys input = sys.stdin.readline from operator import itemgetter sys.setrecursionlimit(10000000) INF = 10**30 def keta(n): return len(str(n)) def make(n, l, r): ans = 0 sn = str(n) for i in range(5): if keta(n) > 2 + i: ans += 10**i elif keta(n) == 2 + i: if sn[0] > str(l): ans += 10**i elif sn[0] == str(l): if sn[-1] < r: ans += int(sn[1:-1]) else: if sn[1:-1] == "": ans += 1 else: ans += int(sn[1:-1]) + 1 else: pass else: pass if l == r: ans += 1 return ans def main(): n = int(input().strip()) ans = 0 for i in range(1, n + 1): p = make(n, str(i)[-1], str(i)[0]) if i % 10 == 0: continue # if i < 10: # p += 1 # print("i ,p: ", i, p) ans += p print(ans) if __name__ == "__main__": main()
import sys input = sys.stdin.readline from operator import itemgetter sys.setrecursionlimit(10000000) INF = 10**30 from collections import defaultdict def main(): n = int(input().strip()) d = defaultdict(int) for i in range(1, n + 1): ds = str(i) d[(ds[0], ds[-1])] += 1 ans = 0 for i in range(1, 10): for j in range(1, 10): si = str(i) sj = str(j) ans += d[(si, sj)] * d[(sj, si)] print(ans) if __name__ == "__main__": main()
false
50
[ "-", "-", "-def keta(n):", "- return len(str(n))", "-", "-", "-def make(n, l, r):", "- ans = 0", "- sn = str(n)", "- for i in range(5):", "- if keta(n) > 2 + i:", "- ans += 10**i", "- elif keta(n) == 2 + i:", "- if sn[0] > str(l):", "- ans += 10**i", "- elif sn[0] == str(l):", "- if sn[-1] < r:", "- ans += int(sn[1:-1])", "- else:", "- if sn[1:-1] == \"\":", "- ans += 1", "- else:", "- ans += int(sn[1:-1]) + 1", "- else:", "- pass", "- else:", "- pass", "- if l == r:", "- ans += 1", "- return ans", "+from collections import defaultdict", "+ d = defaultdict(int)", "+ for i in range(1, n + 1):", "+ ds = str(i)", "+ d[(ds[0], ds[-1])] += 1", "- for i in range(1, n + 1):", "- p = make(n, str(i)[-1], str(i)[0])", "- if i % 10 == 0:", "- continue", "- # if i < 10:", "- # p += 1", "- # print(\"i ,p: \", i, p)", "- ans += p", "+ for i in range(1, 10):", "+ for j in range(1, 10):", "+ si = str(i)", "+ sj = str(j)", "+ ans += d[(si, sj)] * d[(sj, si)]" ]
false
0.109779
0.068174
1.610281
[ "s633001333", "s884717280" ]
u363610900
p03448
python
s699045350
s007271848
54
46
3,060
3,064
Accepted
Accepted
14.81
A = int(eval(input())) B = int(eval(input())) C = int(eval(input())) X = int(eval(input())) ans = 0 for i in range(A+1): for j in range(B+1): for k in range(C+1): temp = i * 500 + j * 100 + k * 50 if temp == X: ans += 1 print(ans)
# -*- coding: utf-8 -*- A = int(eval(input())) B = int(eval(input())) C = int(eval(input())) X = int(eval(input())) def solve(a, b, c): ans = 0 for i in range(a+1): for j in range(b+1): for k in range(c+1): temp = i * 500 + j * 100 + k * 50 if temp == X: ans += 1 return ans def main(): ans = solve(A, B, C) print(ans) if __name__ == '__main__': main()
15
26
276
457
A = int(eval(input())) B = int(eval(input())) C = int(eval(input())) X = int(eval(input())) ans = 0 for i in range(A + 1): for j in range(B + 1): for k in range(C + 1): temp = i * 500 + j * 100 + k * 50 if temp == X: ans += 1 print(ans)
# -*- coding: utf-8 -*- A = int(eval(input())) B = int(eval(input())) C = int(eval(input())) X = int(eval(input())) def solve(a, b, c): ans = 0 for i in range(a + 1): for j in range(b + 1): for k in range(c + 1): temp = i * 500 + j * 100 + k * 50 if temp == X: ans += 1 return ans def main(): ans = solve(A, B, C) print(ans) if __name__ == "__main__": main()
false
42.307692
[ "+# -*- coding: utf-8 -*-", "-ans = 0", "-for i in range(A + 1):", "- for j in range(B + 1):", "- for k in range(C + 1):", "- temp = i * 500 + j * 100 + k * 50", "- if temp == X:", "- ans += 1", "-print(ans)", "+", "+", "+def solve(a, b, c):", "+ ans = 0", "+ for i in range(a + 1):", "+ for j in range(b + 1):", "+ for k in range(c + 1):", "+ temp = i * 500 + j * 100 + k * 50", "+ if temp == X:", "+ ans += 1", "+ return ans", "+", "+", "+def main():", "+ ans = solve(A, B, C)", "+ print(ans)", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.161806
0.00789
20.507681
[ "s699045350", "s007271848" ]
u599114793
p02732
python
s806125124
s250915527
509
440
44,368
111,436
Accepted
Accepted
13.56
n = int(eval(input())) a = list(map(int,input().split())) b = dict() c = dict() d = dict() for i in range(n): if a[i] not in b: b[a[i]] = 0 b[a[i]] += 1 b = list(b.items()) for i in range(len(b)): c[b[i][0]] = b[i][1] * (b[i][1]-1) // 2 d[b[i][0]] = (b[i][1]-1) * (b[i][1]-2) // 2 c_sum = sum(list(c.values())) for i in range(n): num = a[i] print((c_sum - c[num] + d[num]))
import collections n = int(eval(input())) a = list(map(int,input().split())) c = collections.Counter(a) c = list(c.items()) num = 0 nc2 = dict() n_1c2 = dict() for i in range(len(c)): nc2[c[i][0]] = c[i][1] * (c[i][1]-1) // 2 num += c[i][1] * (c[i][1]-1) // 2 n_1c2[c[i][0]] = (c[i][1]-1)*(c[i][1]-2) // 2 for i in range(n): tar = a[i] print((num-nc2[tar]+n_1c2[tar]))
18
16
416
397
n = int(eval(input())) a = list(map(int, input().split())) b = dict() c = dict() d = dict() for i in range(n): if a[i] not in b: b[a[i]] = 0 b[a[i]] += 1 b = list(b.items()) for i in range(len(b)): c[b[i][0]] = b[i][1] * (b[i][1] - 1) // 2 d[b[i][0]] = (b[i][1] - 1) * (b[i][1] - 2) // 2 c_sum = sum(list(c.values())) for i in range(n): num = a[i] print((c_sum - c[num] + d[num]))
import collections n = int(eval(input())) a = list(map(int, input().split())) c = collections.Counter(a) c = list(c.items()) num = 0 nc2 = dict() n_1c2 = dict() for i in range(len(c)): nc2[c[i][0]] = c[i][1] * (c[i][1] - 1) // 2 num += c[i][1] * (c[i][1] - 1) // 2 n_1c2[c[i][0]] = (c[i][1] - 1) * (c[i][1] - 2) // 2 for i in range(n): tar = a[i] print((num - nc2[tar] + n_1c2[tar]))
false
11.111111
[ "+import collections", "+", "-b = dict()", "-c = dict()", "-d = dict()", "+c = collections.Counter(a)", "+c = list(c.items())", "+num = 0", "+nc2 = dict()", "+n_1c2 = dict()", "+for i in range(len(c)):", "+ nc2[c[i][0]] = c[i][1] * (c[i][1] - 1) // 2", "+ num += c[i][1] * (c[i][1] - 1) // 2", "+ n_1c2[c[i][0]] = (c[i][1] - 1) * (c[i][1] - 2) // 2", "- if a[i] not in b:", "- b[a[i]] = 0", "- b[a[i]] += 1", "-b = list(b.items())", "-for i in range(len(b)):", "- c[b[i][0]] = b[i][1] * (b[i][1] - 1) // 2", "- d[b[i][0]] = (b[i][1] - 1) * (b[i][1] - 2) // 2", "-c_sum = sum(list(c.values()))", "-for i in range(n):", "- num = a[i]", "- print((c_sum - c[num] + d[num]))", "+ tar = a[i]", "+ print((num - nc2[tar] + n_1c2[tar]))" ]
false
0.038698
0.038752
0.998601
[ "s806125124", "s250915527" ]
u562935282
p03338
python
s391846653
s182952932
26
24
3,444
3,772
Accepted
Accepted
7.69
from collections import Counter N = int(eval(input())) s = eval(input()) res = 0 for i in range(1, N): c1 = Counter(s[:i]) c2 = Counter(s[i:]) res = max(res, len(set(c1.keys()) & set(c2.keys()))) print(res)
from string import ascii_lowercase n = int(eval(input())) s = eval(input()) ans = -1 for mid in range(1, n): # [0, mid), [mid, n) left = set(s[:mid]) right = set(s[mid:]) cnt = 0 for c in ascii_lowercase: if c in left and c in right: cnt += 1 ans = max(ans, cnt) print(ans)
12
17
221
325
from collections import Counter N = int(eval(input())) s = eval(input()) res = 0 for i in range(1, N): c1 = Counter(s[:i]) c2 = Counter(s[i:]) res = max(res, len(set(c1.keys()) & set(c2.keys()))) print(res)
from string import ascii_lowercase n = int(eval(input())) s = eval(input()) ans = -1 for mid in range(1, n): # [0, mid), [mid, n) left = set(s[:mid]) right = set(s[mid:]) cnt = 0 for c in ascii_lowercase: if c in left and c in right: cnt += 1 ans = max(ans, cnt) print(ans)
false
29.411765
[ "-from collections import Counter", "+from string import ascii_lowercase", "-N = int(eval(input()))", "+n = int(eval(input()))", "-res = 0", "-for i in range(1, N):", "- c1 = Counter(s[:i])", "- c2 = Counter(s[i:])", "- res = max(res, len(set(c1.keys()) & set(c2.keys())))", "-print(res)", "+ans = -1", "+for mid in range(1, n):", "+ # [0, mid), [mid, n)", "+ left = set(s[:mid])", "+ right = set(s[mid:])", "+ cnt = 0", "+ for c in ascii_lowercase:", "+ if c in left and c in right:", "+ cnt += 1", "+ ans = max(ans, cnt)", "+print(ans)" ]
false
0.04542
0.125416
0.362155
[ "s391846653", "s182952932" ]
u011062360
p02773
python
s811514417
s728152936
963
853
46,092
55,512
Accepted
Accepted
11.42
n = int(eval(input())) data_list = [] for _ in range(n): data_list.append(eval(input(""))) data_list_a = set(data_list) data_list_a = list(data_list_a) m = len(data_list_a) data_a = [0 for _ in range(m)] data_dic = dict(list(zip(data_list_a, data_a))) for i in range(n): data_dic[data_list[i]] += 1 data_score = list(data_dic.values()) max_value = max(data_score) ans = [] for i in range(m): if data_dic[data_list_a[i]] == max_value: ans.append(data_list_a[i]) ans.sort() for i in range(len(ans)): print((ans[i]))
n = int(eval(input())) list_S = [] for _ in range(n): list_S.append(eval(input())) dic_S = dict() set_S = set() for s in list_S: if s in set_S: dic_S[s] += 1 else: dic_S[s] = 1 set_S.add(s) list_ans = sorted(list(dic_S.items()), key=lambda x:x[1], reverse=True) a = 0 ans = [] for i in range(len(list_ans)): l = list_ans[i] a = max(a, l[1]) if a <= l[1]: ans.append(l[0]) ans.sort() for s in ans: print(s)
30
25
550
473
n = int(eval(input())) data_list = [] for _ in range(n): data_list.append(eval(input(""))) data_list_a = set(data_list) data_list_a = list(data_list_a) m = len(data_list_a) data_a = [0 for _ in range(m)] data_dic = dict(list(zip(data_list_a, data_a))) for i in range(n): data_dic[data_list[i]] += 1 data_score = list(data_dic.values()) max_value = max(data_score) ans = [] for i in range(m): if data_dic[data_list_a[i]] == max_value: ans.append(data_list_a[i]) ans.sort() for i in range(len(ans)): print((ans[i]))
n = int(eval(input())) list_S = [] for _ in range(n): list_S.append(eval(input())) dic_S = dict() set_S = set() for s in list_S: if s in set_S: dic_S[s] += 1 else: dic_S[s] = 1 set_S.add(s) list_ans = sorted(list(dic_S.items()), key=lambda x: x[1], reverse=True) a = 0 ans = [] for i in range(len(list_ans)): l = list_ans[i] a = max(a, l[1]) if a <= l[1]: ans.append(l[0]) ans.sort() for s in ans: print(s)
false
16.666667
[ "-data_list = []", "+list_S = []", "- data_list.append(eval(input(\"\")))", "-data_list_a = set(data_list)", "-data_list_a = list(data_list_a)", "-m = len(data_list_a)", "-data_a = [0 for _ in range(m)]", "-data_dic = dict(list(zip(data_list_a, data_a)))", "-for i in range(n):", "- data_dic[data_list[i]] += 1", "-data_score = list(data_dic.values())", "-max_value = max(data_score)", "+ list_S.append(eval(input()))", "+dic_S = dict()", "+set_S = set()", "+for s in list_S:", "+ if s in set_S:", "+ dic_S[s] += 1", "+ else:", "+ dic_S[s] = 1", "+ set_S.add(s)", "+list_ans = sorted(list(dic_S.items()), key=lambda x: x[1], reverse=True)", "+a = 0", "-for i in range(m):", "- if data_dic[data_list_a[i]] == max_value:", "- ans.append(data_list_a[i])", "+for i in range(len(list_ans)):", "+ l = list_ans[i]", "+ a = max(a, l[1])", "+ if a <= l[1]:", "+ ans.append(l[0])", "-for i in range(len(ans)):", "- print((ans[i]))", "+for s in ans:", "+ print(s)" ]
false
0.047425
0.048344
0.980983
[ "s811514417", "s728152936" ]
u038243492
p02397
python
s299582082
s881791487
30
20
6,452
6,380
Accepted
Accepted
33.33
list = [] while True: line = input().split(" ") if line[0] == "0" and line[1] == "0": break line = list(map(int, line)) #print line if line[0] > line[1]: temp = line[0] line[0] = line[1] line[1] = temp print(" ".join(map(str, line)))
while True: x, y = list(map(int, input().split())) if x == 0 and y == 0: break else: if x > y: print(str(y) + " " + str(x)) else: print(str(x) + " " + str(y))
12
9
269
222
list = [] while True: line = input().split(" ") if line[0] == "0" and line[1] == "0": break line = list(map(int, line)) # print line if line[0] > line[1]: temp = line[0] line[0] = line[1] line[1] = temp print(" ".join(map(str, line)))
while True: x, y = list(map(int, input().split())) if x == 0 and y == 0: break else: if x > y: print(str(y) + " " + str(x)) else: print(str(x) + " " + str(y))
false
25
[ "-list = []", "- line = input().split(\" \")", "- if line[0] == \"0\" and line[1] == \"0\":", "+ x, y = list(map(int, input().split()))", "+ if x == 0 and y == 0:", "- line = list(map(int, line))", "- # print line", "- if line[0] > line[1]:", "- temp = line[0]", "- line[0] = line[1]", "- line[1] = temp", "- print(\" \".join(map(str, line)))", "+ else:", "+ if x > y:", "+ print(str(y) + \" \" + str(x))", "+ else:", "+ print(str(x) + \" \" + str(y))" ]
false
0.108167
0.036634
2.952615
[ "s299582082", "s881791487" ]
u120233192
p02947
python
s894450730
s237839537
688
280
44,280
26,100
Accepted
Accepted
59.3
# 3.4.3 import re from collections import deque from functools import reduce from itertools import permutations from math import pi from operator import itemgetter from operator import mul from operator import xor from os import linesep from queue import PriorityQueue from sys import stdin def rline() -> str: return stdin.readline().strip() def rlines(hint: int = 1): ret = ['' for i in range(hint)] for i in range(hint): ret[i] = rline() return ret def htokens(hint: int = 1): lns = rlines(hint) ret = list([ln.split() for ln in lns]) # if return value has one and only one element(list), if hint == 1: # then add an empty list. ret.append([]) return ret def vtokens(hint: int = 1): m, _ = htokens() wint = len(m) ret = [[None] * hint for i in range(wint)] for y in range(hint): if y != 0: m, _ = htokens() # convert horizontal to vertical x = 0 for v in m: ret[x][y] = v x += 1 # if return value has one and only one element(list), if wint == 1: # then add an empty list. ret.append([]) return ret def rint(radix: int = 10) -> int: return int(rline(), radix) def hints(hint: int = 1, radix: int = 10): ret = htokens(hint) for i in range(len(ret)): ret[i] = list([int(v, radix) for v in ret[i]]) return ret def vints(hint: int = 1, radix: int = 10): ret = vtokens(hint) for i in range(len(ret)): ret[i] = list([int(v, radix) for v in ret[i]]) return ret def mat(hint: int, wint: int): return [[None]*wint for i in range(hint)] def filllist(lst, value: int) -> None: # destructive. for i in range(len(lst)): lst[i] = value def isprime(n: int) -> bool: if n <= 1: return False if n in (2, 3, 5): return True if n % 2 == 0: return False if n % 3 == 0: return False lst = int(n**0.5) f = 5 while f <= lst: if n % f == 0: return False if n % (f + 2) == 0: return False f += 6 return True def strmat(matrix, lnsep: str = linesep, fieldsep: str = ' ') -> str: return lnsep.join([fieldsep.join(map(str, row)) for row in matrix]) def strbool(boolval: int) -> str: return ['No', 'Yes'][boolval] def solve() -> None: # read here n = rint() ss = rlines(n) # solve here dict = {} for s in ss: cnt = [0] * 26 for c in s: cnt[ord(c) - ord('a')] += 1 tup = tuple(i for i in cnt) if not tup in list(dict.keys()): dict[tup] = 0 dict[tup] += 1 # 2-combination of x. ans = sum([0 if x == 1 else x*(x-1)//2 for x in list(dict.values())]) # print here print(ans) if __name__ == '__main__': solve()
# 3.4.3 import re from collections import deque from functools import reduce from itertools import permutations from math import pi from operator import itemgetter from operator import mul from operator import xor from os import linesep from queue import PriorityQueue from sys import stdin def rline() -> str: return stdin.readline().strip() def rlines(hint: int = 1): ret = ['' for i in range(hint)] for i in range(hint): ret[i] = rline() return ret def htokens(hint: int = 1): lns = rlines(hint) ret = list([ln.split() for ln in lns]) # if return value has one and only one element(list), if hint == 1: # then add an empty list. ret.append([]) return ret def vtokens(hint: int = 1): m, _ = htokens() wint = len(m) ret = [[None] * hint for i in range(wint)] for y in range(hint): if y != 0: m, _ = htokens() # convert horizontal to vertical x = 0 for v in m: ret[x][y] = v x += 1 # if return value has one and only one element(list), if wint == 1: # then add an empty list. ret.append([]) return ret def rint(radix: int = 10) -> int: return int(rline(), radix) def hints(hint: int = 1, radix: int = 10): ret = htokens(hint) for i in range(len(ret)): ret[i] = list([int(v, radix) for v in ret[i]]) return ret def vints(hint: int = 1, radix: int = 10): ret = vtokens(hint) for i in range(len(ret)): ret[i] = list([int(v, radix) for v in ret[i]]) return ret def mat(hint: int, wint: int): return [[None]*wint for i in range(hint)] def filllist(lst, value: int) -> None: # destructive. for i in range(len(lst)): lst[i] = value def isprime(n: int) -> bool: if n <= 1: return False if n in (2, 3, 5): return True if n % 2 == 0: return False if n % 3 == 0: return False lst = int(n**0.5) f = 5 while f <= lst: if n % f == 0: return False if n % (f + 2) == 0: return False f += 6 return True def strmat(matrix, lnsep: str = linesep, fieldsep: str = ' ') -> str: return lnsep.join([fieldsep.join(map(str, row)) for row in matrix]) def strbool(boolval: int) -> str: return ['No', 'Yes'][boolval] def solve() -> None: # read here n = rint() ss = rlines(n) # solve here dict = {} for s in ss: k = ''.join(sorted(list(s))) if not k in list(dict.keys()): dict[k] = 0 dict[k] += 1 # 2-combination of x. ans = sum([0 if x == 1 else x*(x-1)//2 for x in list(dict.values())]) # print here print(ans) if __name__ == '__main__': solve()
136
133
3,023
2,932
# 3.4.3 import re from collections import deque from functools import reduce from itertools import permutations from math import pi from operator import itemgetter from operator import mul from operator import xor from os import linesep from queue import PriorityQueue from sys import stdin def rline() -> str: return stdin.readline().strip() def rlines(hint: int = 1): ret = ["" for i in range(hint)] for i in range(hint): ret[i] = rline() return ret def htokens(hint: int = 1): lns = rlines(hint) ret = list([ln.split() for ln in lns]) # if return value has one and only one element(list), if hint == 1: # then add an empty list. ret.append([]) return ret def vtokens(hint: int = 1): m, _ = htokens() wint = len(m) ret = [[None] * hint for i in range(wint)] for y in range(hint): if y != 0: m, _ = htokens() # convert horizontal to vertical x = 0 for v in m: ret[x][y] = v x += 1 # if return value has one and only one element(list), if wint == 1: # then add an empty list. ret.append([]) return ret def rint(radix: int = 10) -> int: return int(rline(), radix) def hints(hint: int = 1, radix: int = 10): ret = htokens(hint) for i in range(len(ret)): ret[i] = list([int(v, radix) for v in ret[i]]) return ret def vints(hint: int = 1, radix: int = 10): ret = vtokens(hint) for i in range(len(ret)): ret[i] = list([int(v, radix) for v in ret[i]]) return ret def mat(hint: int, wint: int): return [[None] * wint for i in range(hint)] def filllist(lst, value: int) -> None: # destructive. for i in range(len(lst)): lst[i] = value def isprime(n: int) -> bool: if n <= 1: return False if n in (2, 3, 5): return True if n % 2 == 0: return False if n % 3 == 0: return False lst = int(n**0.5) f = 5 while f <= lst: if n % f == 0: return False if n % (f + 2) == 0: return False f += 6 return True def strmat(matrix, lnsep: str = linesep, fieldsep: str = " ") -> str: return lnsep.join([fieldsep.join(map(str, row)) for row in matrix]) def strbool(boolval: int) -> str: return ["No", "Yes"][boolval] def solve() -> None: # read here n = rint() ss = rlines(n) # solve here dict = {} for s in ss: cnt = [0] * 26 for c in s: cnt[ord(c) - ord("a")] += 1 tup = tuple(i for i in cnt) if not tup in list(dict.keys()): dict[tup] = 0 dict[tup] += 1 # 2-combination of x. ans = sum([0 if x == 1 else x * (x - 1) // 2 for x in list(dict.values())]) # print here print(ans) if __name__ == "__main__": solve()
# 3.4.3 import re from collections import deque from functools import reduce from itertools import permutations from math import pi from operator import itemgetter from operator import mul from operator import xor from os import linesep from queue import PriorityQueue from sys import stdin def rline() -> str: return stdin.readline().strip() def rlines(hint: int = 1): ret = ["" for i in range(hint)] for i in range(hint): ret[i] = rline() return ret def htokens(hint: int = 1): lns = rlines(hint) ret = list([ln.split() for ln in lns]) # if return value has one and only one element(list), if hint == 1: # then add an empty list. ret.append([]) return ret def vtokens(hint: int = 1): m, _ = htokens() wint = len(m) ret = [[None] * hint for i in range(wint)] for y in range(hint): if y != 0: m, _ = htokens() # convert horizontal to vertical x = 0 for v in m: ret[x][y] = v x += 1 # if return value has one and only one element(list), if wint == 1: # then add an empty list. ret.append([]) return ret def rint(radix: int = 10) -> int: return int(rline(), radix) def hints(hint: int = 1, radix: int = 10): ret = htokens(hint) for i in range(len(ret)): ret[i] = list([int(v, radix) for v in ret[i]]) return ret def vints(hint: int = 1, radix: int = 10): ret = vtokens(hint) for i in range(len(ret)): ret[i] = list([int(v, radix) for v in ret[i]]) return ret def mat(hint: int, wint: int): return [[None] * wint for i in range(hint)] def filllist(lst, value: int) -> None: # destructive. for i in range(len(lst)): lst[i] = value def isprime(n: int) -> bool: if n <= 1: return False if n in (2, 3, 5): return True if n % 2 == 0: return False if n % 3 == 0: return False lst = int(n**0.5) f = 5 while f <= lst: if n % f == 0: return False if n % (f + 2) == 0: return False f += 6 return True def strmat(matrix, lnsep: str = linesep, fieldsep: str = " ") -> str: return lnsep.join([fieldsep.join(map(str, row)) for row in matrix]) def strbool(boolval: int) -> str: return ["No", "Yes"][boolval] def solve() -> None: # read here n = rint() ss = rlines(n) # solve here dict = {} for s in ss: k = "".join(sorted(list(s))) if not k in list(dict.keys()): dict[k] = 0 dict[k] += 1 # 2-combination of x. ans = sum([0 if x == 1 else x * (x - 1) // 2 for x in list(dict.values())]) # print here print(ans) if __name__ == "__main__": solve()
false
2.205882
[ "- cnt = [0] * 26", "- for c in s:", "- cnt[ord(c) - ord(\"a\")] += 1", "- tup = tuple(i for i in cnt)", "- if not tup in list(dict.keys()):", "- dict[tup] = 0", "- dict[tup] += 1", "+ k = \"\".join(sorted(list(s)))", "+ if not k in list(dict.keys()):", "+ dict[k] = 0", "+ dict[k] += 1" ]
false
0.036173
0.036767
0.983843
[ "s894450730", "s237839537" ]
u553987207
p02732
python
s896045259
s507738609
1,938
273
121,172
26,140
Accepted
Accepted
85.91
from math import factorial from functools import lru_cache @lru_cache(maxsize=None) def cmbcount(n): if n > 1: return factorial(n) // (factorial(n - 2) * factorial(2)) return 0 N = int(eval(input())) A = list(map(int, input().split())) samecnt = [0] * (N + 1) for a in A: samecnt[a] += 1 cnts = [cmbcount(n) for n in samecnt] allcnt = sum(cnts) for i in range(N): a = A[i] o = cnts[a] n = cmbcount(samecnt[a] - 1) ans = allcnt - (o - n) print(ans)
N = int(eval(input())) A = list(map(int, input().split())) c = [0] * (N + 1) for a in A: c[a] += 1 total = sum([n * (n - 1) // 2 for n in c]) for a in A: print((total - (c[a] - 1)))
22
8
504
188
from math import factorial from functools import lru_cache @lru_cache(maxsize=None) def cmbcount(n): if n > 1: return factorial(n) // (factorial(n - 2) * factorial(2)) return 0 N = int(eval(input())) A = list(map(int, input().split())) samecnt = [0] * (N + 1) for a in A: samecnt[a] += 1 cnts = [cmbcount(n) for n in samecnt] allcnt = sum(cnts) for i in range(N): a = A[i] o = cnts[a] n = cmbcount(samecnt[a] - 1) ans = allcnt - (o - n) print(ans)
N = int(eval(input())) A = list(map(int, input().split())) c = [0] * (N + 1) for a in A: c[a] += 1 total = sum([n * (n - 1) // 2 for n in c]) for a in A: print((total - (c[a] - 1)))
false
63.636364
[ "-from math import factorial", "-from functools import lru_cache", "-", "-", "-@lru_cache(maxsize=None)", "-def cmbcount(n):", "- if n > 1:", "- return factorial(n) // (factorial(n - 2) * factorial(2))", "- return 0", "-", "-", "-samecnt = [0] * (N + 1)", "+c = [0] * (N + 1)", "- samecnt[a] += 1", "-cnts = [cmbcount(n) for n in samecnt]", "-allcnt = sum(cnts)", "-for i in range(N):", "- a = A[i]", "- o = cnts[a]", "- n = cmbcount(samecnt[a] - 1)", "- ans = allcnt - (o - n)", "- print(ans)", "+ c[a] += 1", "+total = sum([n * (n - 1) // 2 for n in c])", "+for a in A:", "+ print((total - (c[a] - 1)))" ]
false
0.039503
0.106438
0.371134
[ "s896045259", "s507738609" ]
u133936772
p02715
python
s878280367
s756101124
270
197
11,304
11,920
Accepted
Accepted
27.04
M=10**9+7 n,k=list(map(int,input().split())) l=[0]*(k+1) a=0 for i in range(k,0,-1): l[i]=pow(k//i,n,M)-sum(l[j] for j in range(i*2,k+1,i)) a+=i*l[i] print((a%M))
M=10**9+7 n,k=list(map(int,input().split())) l=[0]*(k+1) a=0 for i in range(k,0,-1): l[i]=pow(k//i,n,M)-sum(l[::i]) a+=i*l[i] print((a%M))
8
8
165
141
M = 10**9 + 7 n, k = list(map(int, input().split())) l = [0] * (k + 1) a = 0 for i in range(k, 0, -1): l[i] = pow(k // i, n, M) - sum(l[j] for j in range(i * 2, k + 1, i)) a += i * l[i] print((a % M))
M = 10**9 + 7 n, k = list(map(int, input().split())) l = [0] * (k + 1) a = 0 for i in range(k, 0, -1): l[i] = pow(k // i, n, M) - sum(l[::i]) a += i * l[i] print((a % M))
false
0
[ "- l[i] = pow(k // i, n, M) - sum(l[j] for j in range(i * 2, k + 1, i))", "+ l[i] = pow(k // i, n, M) - sum(l[::i])" ]
false
0.401331
0.354279
1.13281
[ "s878280367", "s756101124" ]
u832526214
p02661
python
s402538504
s916165026
461
208
25,352
55,376
Accepted
Accepted
54.88
n = int(eval(input())) a = [] b = [] for i in range(n): a_1, b_1 = input().split() a.append(int(a_1)) b.append(int(b_1)) a.sort() b.sort() is_odds = n % 2 == 0 if n % 2 == 0: print((b[n // 2 - 1] + b[n // 2] - a[n // 2 - 1] - a[n // 2] + 1)) else: print((b[(n + 1) // 2 - 1] - a[(n + 1) // 2 - 1] + 1))
n, *AB = list(map(int, open(0).read().split())) a = sorted(AB[::2]) b = sorted(AB[1::2]) is_odds = n % 2 == 0 if n % 2 == 0: print((b[n // 2 - 1] + b[n // 2] - a[n // 2 - 1] - a[n // 2] + 1)) else: print((b[(n + 1) // 2 - 1] - a[(n + 1) // 2 - 1] + 1))
14
8
310
251
n = int(eval(input())) a = [] b = [] for i in range(n): a_1, b_1 = input().split() a.append(int(a_1)) b.append(int(b_1)) a.sort() b.sort() is_odds = n % 2 == 0 if n % 2 == 0: print((b[n // 2 - 1] + b[n // 2] - a[n // 2 - 1] - a[n // 2] + 1)) else: print((b[(n + 1) // 2 - 1] - a[(n + 1) // 2 - 1] + 1))
n, *AB = list(map(int, open(0).read().split())) a = sorted(AB[::2]) b = sorted(AB[1::2]) is_odds = n % 2 == 0 if n % 2 == 0: print((b[n // 2 - 1] + b[n // 2] - a[n // 2 - 1] - a[n // 2] + 1)) else: print((b[(n + 1) // 2 - 1] - a[(n + 1) // 2 - 1] + 1))
false
42.857143
[ "-n = int(eval(input()))", "-a = []", "-b = []", "-for i in range(n):", "- a_1, b_1 = input().split()", "- a.append(int(a_1))", "- b.append(int(b_1))", "-a.sort()", "-b.sort()", "+n, *AB = list(map(int, open(0).read().split()))", "+a = sorted(AB[::2])", "+b = sorted(AB[1::2])" ]
false
0.039724
0.041638
0.954051
[ "s402538504", "s916165026" ]
u785220618
p03329
python
s218837901
s168293205
1,199
1,077
3,864
3,864
Accepted
Accepted
10.18
# -*- coding: utf-8 -*- N = int(eval(input())) A = [1] i = 1 while 6 ** i <= 100000: A.append(6 ** i) i += 1 j = 1 while 9 ** j <= 100000: A.append(9 ** j) j += 1 A.sort() table = [1000000 for _ in range(N + 1)] table[0] = 0 for i in range(1, N+1): a = 0 while 6 ** a <= i: table[i] = min(table[i], table[i - 6 ** a] + 1) a += 1 b = 0 while 9 ** b <= i: table[i] = min(table[i], table[i - 9 ** b] + 1) b += 1 print((table[N]))
# -*- coding: utf-8 -*- N = int(eval(input())) A = [1] i = 1 while 6 ** i <= 100000: A.append(6 ** i) i += 1 j = 1 while 9 ** j <= 100000: A.append(9 ** j) j += 1 A.sort() # 引き出せる金額のリスト table = [1000000 for _ in range(N + 1)] # i円を引き出す最小の操作回数をメモ、参照するのは常に前の値なのでループを回せる table[0] = 0 for i in range(1, N+1): a = 0 while 6 ** a <= i: table[i] = min(table[i], table[i - 6 ** a] + 1) # 1円,6円,36円,...を使って操作回数を減らす a += 1 b = 0 while 9 ** b <= i: table[i] = min(table[i], table[i - 9 ** b] + 1) # 1円,9円,81円,...を使って操作回数を減らす b += 1 print((table[N]))
29
29
516
632
# -*- coding: utf-8 -*- N = int(eval(input())) A = [1] i = 1 while 6**i <= 100000: A.append(6**i) i += 1 j = 1 while 9**j <= 100000: A.append(9**j) j += 1 A.sort() table = [1000000 for _ in range(N + 1)] table[0] = 0 for i in range(1, N + 1): a = 0 while 6**a <= i: table[i] = min(table[i], table[i - 6**a] + 1) a += 1 b = 0 while 9**b <= i: table[i] = min(table[i], table[i - 9**b] + 1) b += 1 print((table[N]))
# -*- coding: utf-8 -*- N = int(eval(input())) A = [1] i = 1 while 6**i <= 100000: A.append(6**i) i += 1 j = 1 while 9**j <= 100000: A.append(9**j) j += 1 A.sort() # 引き出せる金額のリスト table = [1000000 for _ in range(N + 1)] # i円を引き出す最小の操作回数をメモ、参照するのは常に前の値なのでループを回せる table[0] = 0 for i in range(1, N + 1): a = 0 while 6**a <= i: table[i] = min(table[i], table[i - 6**a] + 1) # 1円,6円,36円,...を使って操作回数を減らす a += 1 b = 0 while 9**b <= i: table[i] = min(table[i], table[i - 9**b] + 1) # 1円,9円,81円,...を使って操作回数を減らす b += 1 print((table[N]))
false
0
[ "-A.sort()", "-table = [1000000 for _ in range(N + 1)]", "+A.sort() # 引き出せる金額のリスト", "+table = [1000000 for _ in range(N + 1)] # i円を引き出す最小の操作回数をメモ、参照するのは常に前の値なのでループを回せる", "- table[i] = min(table[i], table[i - 6**a] + 1)", "+ table[i] = min(table[i], table[i - 6**a] + 1) # 1円,6円,36円,...を使って操作回数を減らす", "- table[i] = min(table[i], table[i - 9**b] + 1)", "+ table[i] = min(table[i], table[i - 9**b] + 1) # 1円,9円,81円,...を使って操作回数を減らす" ]
false
0.356373
0.159539
2.233768
[ "s218837901", "s168293205" ]
u952708174
p03599
python
s256868249
s893072109
1,266
68
3,188
3,188
Accepted
Accepted
94.63
def c_sugar_water(A, B, C, D, E, F): x = set() # 水の量が取りうるパターン y = set() # 砂糖の量が取りうるパターン for i in range(F // 100 + 1): for j in range(F // 100 + 1): tmp = 100 * A * i + 100 * B * j if tmp <= F: x.add(tmp) for i in range(F): for j in range(F): tmp = C * i + D * j if tmp <= F: y.add(tmp) concentration = 0 # 砂糖水の濃度 tmp = [0, 0] for water in x: for sugar in y: if water == 0 and sugar == 0: # 水も砂糖も入れないパターン continue elif E * (water // 100) < sugar: # 砂糖を溶かしきれない continue elif water + sugar > F: # ビーカーに入れられる質量を超えた continue else: if (100 * sugar) / (water + sugar) >= concentration: concentration = (100 * sugar) / (water + sugar) tmp = [water + sugar, sugar] ans = '{} {}'.format(tmp[0], tmp[1]) return ans A,B,C,D,E,F = [int(i) for i in input().split()] print((c_sugar_water(A, B, C, D, E, F)))
def c_sugar_water(A, B, C, D, E, F): x = set() # 水の量が取りうるパターン y = set() # 砂糖の量が取りうるパターン for i in range(F // 100 + 1): for j in range(F // 100 + 1): tmp = 100 * A * i + 100 * B * j if tmp <= F: x.add(tmp) else: break # A, Bは正整数なので、Fを超えるようなjの値にする意味がない for i in range(F): for j in range(F): tmp = C * i + D * j if tmp <= F: y.add(tmp) else: break concentration = 0 # 砂糖水の濃度 tmp = [0, 0] for water in x: for sugar in y: if water == 0 and sugar == 0: continue # 水も砂糖も入れていない elif E * (water // 100) < sugar: continue # 砂糖を溶かしきれない elif water + sugar > F: continue # ビーカーに入れられる質量を超えた else: if (100 * sugar) / (water + sugar) >= concentration: concentration = (100 * sugar) / (water + sugar) tmp = [water + sugar, sugar] ans = '{} {}'.format(tmp[0], tmp[1]) return ans A, B, C, D, E, F = [int(i) for i in input().split()] print((c_sugar_water(A, B, C, D, E, F)))
36
37
1,170
1,244
def c_sugar_water(A, B, C, D, E, F): x = set() # 水の量が取りうるパターン y = set() # 砂糖の量が取りうるパターン for i in range(F // 100 + 1): for j in range(F // 100 + 1): tmp = 100 * A * i + 100 * B * j if tmp <= F: x.add(tmp) for i in range(F): for j in range(F): tmp = C * i + D * j if tmp <= F: y.add(tmp) concentration = 0 # 砂糖水の濃度 tmp = [0, 0] for water in x: for sugar in y: if water == 0 and sugar == 0: # 水も砂糖も入れないパターン continue elif E * (water // 100) < sugar: # 砂糖を溶かしきれない continue elif water + sugar > F: # ビーカーに入れられる質量を超えた continue else: if (100 * sugar) / (water + sugar) >= concentration: concentration = (100 * sugar) / (water + sugar) tmp = [water + sugar, sugar] ans = "{} {}".format(tmp[0], tmp[1]) return ans A, B, C, D, E, F = [int(i) for i in input().split()] print((c_sugar_water(A, B, C, D, E, F)))
def c_sugar_water(A, B, C, D, E, F): x = set() # 水の量が取りうるパターン y = set() # 砂糖の量が取りうるパターン for i in range(F // 100 + 1): for j in range(F // 100 + 1): tmp = 100 * A * i + 100 * B * j if tmp <= F: x.add(tmp) else: break # A, Bは正整数なので、Fを超えるようなjの値にする意味がない for i in range(F): for j in range(F): tmp = C * i + D * j if tmp <= F: y.add(tmp) else: break concentration = 0 # 砂糖水の濃度 tmp = [0, 0] for water in x: for sugar in y: if water == 0 and sugar == 0: continue # 水も砂糖も入れていない elif E * (water // 100) < sugar: continue # 砂糖を溶かしきれない elif water + sugar > F: continue # ビーカーに入れられる質量を超えた else: if (100 * sugar) / (water + sugar) >= concentration: concentration = (100 * sugar) / (water + sugar) tmp = [water + sugar, sugar] ans = "{} {}".format(tmp[0], tmp[1]) return ans A, B, C, D, E, F = [int(i) for i in input().split()] print((c_sugar_water(A, B, C, D, E, F)))
false
2.702703
[ "+ else:", "+ break # A, Bは正整数なので、Fを超えるようなjの値にする意味がない", "+ else:", "+ break", "- # 水も砂糖も入れないパターン", "- continue", "+ continue # 水も砂糖も入れていない", "- # 砂糖を溶かしきれない", "- continue", "+ continue # 砂糖を溶かしきれない", "- # ビーカーに入れられる質量を超えた", "- continue", "+ continue # ビーカーに入れられる質量を超えた" ]
false
0.657666
0.045687
14.395182
[ "s256868249", "s893072109" ]
u357218223
p03207
python
s025901808
s850668975
19
17
3,060
2,940
Accepted
Accepted
10.53
# coding: utf-8 N = int(eval(input())) p = [ int(eval(input())) for _ in range(N)] m = max(p)//2 p[p.index(max(p))] = 0 print((sum(p)+m))
# coding: utf-8 p = [ int(eval(input())) for _ in range(int(eval(input())))] print((sum(p)-max(p)//2))
6
3
128
90
# coding: utf-8 N = int(eval(input())) p = [int(eval(input())) for _ in range(N)] m = max(p) // 2 p[p.index(max(p))] = 0 print((sum(p) + m))
# coding: utf-8 p = [int(eval(input())) for _ in range(int(eval(input())))] print((sum(p) - max(p) // 2))
false
50
[ "-N = int(eval(input()))", "-p = [int(eval(input())) for _ in range(N)]", "-m = max(p) // 2", "-p[p.index(max(p))] = 0", "-print((sum(p) + m))", "+p = [int(eval(input())) for _ in range(int(eval(input())))]", "+print((sum(p) - max(p) // 2))" ]
false
0.080723
0.035818
2.253712
[ "s025901808", "s850668975" ]
u111365362
p03061
python
s380837485
s828060045
393
270
14,436
14,080
Accepted
Accepted
31.3
n = int(eval(input())) a = list(map(int,input().split())) ans1 = a[1] for i in range(1,n): big,sml = a[i],ans1 while sml != 0: big,sml = sml,big%sml ans1 = big ans2 = a[-2] for i in range(n-1): big,sml = a[i],ans2 while sml != 0: big,sml = sml,big%sml ans2 = big l1 = [-1] now = a[0] for i in range(1,n): big,sml = now,a[i] while sml != 0: big,sml = sml,big%sml l1.append(now // big) now = big l2 = [-1] now = a[-1] for i in range(n-2,-1,-1): big,sml = now,a[i] while sml != 0: big,sml = sml,big%sml l2.append(now // big) now = big l2.reverse() l3 = [-1] for i in range(1,n-1): big,sml = l1[i],l2[i] while sml != 0: big,sml = sml,big%sml l3.append(big) l3.append(-1) now = a[0] for i in range(n): big,sml = now,a[i] while sml != 0: big,sml = sml,big%sml now = big ans3 = now * max(l3) #print(now) #print(l1) #print(l2) #print(l3) #print(ans1,ans2,ans3) print((max(ans1,ans2,ans3)))
#14:10 n = int(eval(input())) a = list(map(int,input().split())) b = [] for i in range(n): if i == 0: b.append(a[i]) else: big = b[-1] sml = a[i] while sml != 0: big,sml = sml,big%sml b.append(big) c = [] for j in range(n)[::-1]: if j == n-1: c.append(a[j]) else: big = c[-1] sml = a[j] while sml != 0: big,sml = sml,big%sml c.append(big) c.reverse() d = [] for i in range(n): if i == 0: d.append(c[1]) elif i == n-1: d.append(b[n-2]) else: big = b[i-1] sml = c[i+1] while sml != 0: big,sml = sml,big%sml d.append(big) #print(b) #print(c) #print(d) print((max(d)))
51
40
987
691
n = int(eval(input())) a = list(map(int, input().split())) ans1 = a[1] for i in range(1, n): big, sml = a[i], ans1 while sml != 0: big, sml = sml, big % sml ans1 = big ans2 = a[-2] for i in range(n - 1): big, sml = a[i], ans2 while sml != 0: big, sml = sml, big % sml ans2 = big l1 = [-1] now = a[0] for i in range(1, n): big, sml = now, a[i] while sml != 0: big, sml = sml, big % sml l1.append(now // big) now = big l2 = [-1] now = a[-1] for i in range(n - 2, -1, -1): big, sml = now, a[i] while sml != 0: big, sml = sml, big % sml l2.append(now // big) now = big l2.reverse() l3 = [-1] for i in range(1, n - 1): big, sml = l1[i], l2[i] while sml != 0: big, sml = sml, big % sml l3.append(big) l3.append(-1) now = a[0] for i in range(n): big, sml = now, a[i] while sml != 0: big, sml = sml, big % sml now = big ans3 = now * max(l3) # print(now) # print(l1) # print(l2) # print(l3) # print(ans1,ans2,ans3) print((max(ans1, ans2, ans3)))
# 14:10 n = int(eval(input())) a = list(map(int, input().split())) b = [] for i in range(n): if i == 0: b.append(a[i]) else: big = b[-1] sml = a[i] while sml != 0: big, sml = sml, big % sml b.append(big) c = [] for j in range(n)[::-1]: if j == n - 1: c.append(a[j]) else: big = c[-1] sml = a[j] while sml != 0: big, sml = sml, big % sml c.append(big) c.reverse() d = [] for i in range(n): if i == 0: d.append(c[1]) elif i == n - 1: d.append(b[n - 2]) else: big = b[i - 1] sml = c[i + 1] while sml != 0: big, sml = sml, big % sml d.append(big) # print(b) # print(c) # print(d) print((max(d)))
false
21.568627
[ "+# 14:10", "-ans1 = a[1]", "-for i in range(1, n):", "- big, sml = a[i], ans1", "- while sml != 0:", "- big, sml = sml, big % sml", "- ans1 = big", "-ans2 = a[-2]", "-for i in range(n - 1):", "- big, sml = a[i], ans2", "- while sml != 0:", "- big, sml = sml, big % sml", "- ans2 = big", "-l1 = [-1]", "-now = a[0]", "-for i in range(1, n):", "- big, sml = now, a[i]", "- while sml != 0:", "- big, sml = sml, big % sml", "- l1.append(now // big)", "- now = big", "-l2 = [-1]", "-now = a[-1]", "-for i in range(n - 2, -1, -1):", "- big, sml = now, a[i]", "- while sml != 0:", "- big, sml = sml, big % sml", "- l2.append(now // big)", "- now = big", "-l2.reverse()", "-l3 = [-1]", "-for i in range(1, n - 1):", "- big, sml = l1[i], l2[i]", "- while sml != 0:", "- big, sml = sml, big % sml", "- l3.append(big)", "-l3.append(-1)", "-now = a[0]", "+b = []", "- big, sml = now, a[i]", "- while sml != 0:", "- big, sml = sml, big % sml", "- now = big", "-ans3 = now * max(l3)", "-# print(now)", "-# print(l1)", "-# print(l2)", "-# print(l3)", "-# print(ans1,ans2,ans3)", "-print((max(ans1, ans2, ans3)))", "+ if i == 0:", "+ b.append(a[i])", "+ else:", "+ big = b[-1]", "+ sml = a[i]", "+ while sml != 0:", "+ big, sml = sml, big % sml", "+ b.append(big)", "+c = []", "+for j in range(n)[::-1]:", "+ if j == n - 1:", "+ c.append(a[j])", "+ else:", "+ big = c[-1]", "+ sml = a[j]", "+ while sml != 0:", "+ big, sml = sml, big % sml", "+ c.append(big)", "+c.reverse()", "+d = []", "+for i in range(n):", "+ if i == 0:", "+ d.append(c[1])", "+ elif i == n - 1:", "+ d.append(b[n - 2])", "+ else:", "+ big = b[i - 1]", "+ sml = c[i + 1]", "+ while sml != 0:", "+ big, sml = sml, big % sml", "+ d.append(big)", "+# print(b)", "+# print(c)", "+# print(d)", "+print((max(d)))" ]
false
0.043512
0.035709
1.218514
[ "s380837485", "s828060045" ]
u531631168
p02725
python
s886512017
s544224157
279
164
26,444
26,444
Accepted
Accepted
41.22
k, n = list(map(int, input().split())) a = list(map(int, input().split())) a2 = a + [aa + k for aa in a] max_inter = 0 for i in range(n*2 - 1): max_inter = max(max_inter, a2[i+1] - a2[i]) print((k - max_inter))
k, n = list(map(int, input().split())) arr = list(map(int, input().split())) max_inter = 0 max_inter = max(max_inter, arr[0]+k - arr[-1]) for i in range(n-1): max_inter = max(max_inter, arr[i+1] - arr[i]) print((k - max_inter))
7
7
212
229
k, n = list(map(int, input().split())) a = list(map(int, input().split())) a2 = a + [aa + k for aa in a] max_inter = 0 for i in range(n * 2 - 1): max_inter = max(max_inter, a2[i + 1] - a2[i]) print((k - max_inter))
k, n = list(map(int, input().split())) arr = list(map(int, input().split())) max_inter = 0 max_inter = max(max_inter, arr[0] + k - arr[-1]) for i in range(n - 1): max_inter = max(max_inter, arr[i + 1] - arr[i]) print((k - max_inter))
false
0
[ "-a = list(map(int, input().split()))", "-a2 = a + [aa + k for aa in a]", "+arr = list(map(int, input().split()))", "-for i in range(n * 2 - 1):", "- max_inter = max(max_inter, a2[i + 1] - a2[i])", "+max_inter = max(max_inter, arr[0] + k - arr[-1])", "+for i in range(n - 1):", "+ max_inter = max(max_inter, arr[i + 1] - arr[i])" ]
false
0.048901
0.036007
1.358088
[ "s886512017", "s544224157" ]
u058781705
p03292
python
s730752993
s804465419
187
62
38,384
61,688
Accepted
Accepted
66.84
def solve(): As = list(map(int, input().split())) print((max(As)-min(As))) # Solve if __name__ == "__main__": solve()
alist = list(map(int, input().split())) print((max(alist)-min(alist)))
10
3
141
72
def solve(): As = list(map(int, input().split())) print((max(As) - min(As))) # Solve if __name__ == "__main__": solve()
alist = list(map(int, input().split())) print((max(alist) - min(alist)))
false
70
[ "-def solve():", "- As = list(map(int, input().split()))", "- print((max(As) - min(As)))", "-", "-", "-# Solve", "-if __name__ == \"__main__\":", "- solve()", "+alist = list(map(int, input().split()))", "+print((max(alist) - min(alist)))" ]
false
0.036994
0.03779
0.978931
[ "s730752993", "s804465419" ]