user_id
stringlengths
10
10
problem_id
stringlengths
6
6
language
stringclasses
1 value
submission_id_v0
stringlengths
10
10
submission_id_v1
stringlengths
10
10
cpu_time_v0
int64
10
38.3k
cpu_time_v1
int64
0
24.7k
memory_v0
int64
2.57k
1.02M
memory_v1
int64
2.57k
869k
status_v0
stringclasses
1 value
status_v1
stringclasses
1 value
improvement_frac
float64
7.51
100
input
stringlengths
20
4.55k
target
stringlengths
17
3.34k
code_v0_loc
int64
1
148
code_v1_loc
int64
1
184
code_v0_num_chars
int64
13
4.55k
code_v1_num_chars
int64
14
3.34k
code_v0_no_empty_lines
stringlengths
21
6.88k
code_v1_no_empty_lines
stringlengths
20
4.93k
code_same
bool
1 class
relative_loc_diff_percent
float64
0
79.8
diff
list
diff_only_import_comment
bool
1 class
measured_runtime_v0
float64
0.01
4.45
measured_runtime_v1
float64
0.01
4.31
runtime_lift
float64
0
359
key
list
u490553751
p03126
python
s060573365
s367867873
173
18
38,384
3,060
Accepted
Accepted
89.6
N,M = list(map(int,input().split())) nes = [] count = 0 for i in range(N) : li = list(map(int,input().split())) nes.append(li) favorite = [0] * M for i in range(N) : for j in range(1,nes[i][0]+1) : favorite[nes[i][j]-1] += 1 for i in range(M) : if favorite[i] == N : count+=1 print(count)
#template def inputlist(): return [int(k) for k in input().split()] #template N,M = inputlist() ans = [0]*(M+1) c =0 for i in range(N): A = inputlist() K = A[0] Aa = A[1:] for j in range(K): ans[Aa[j]] +=1 for i in range(1,M+1): if ans[i] == N: c+=1 print(c)
14
16
327
309
N, M = list(map(int, input().split())) nes = [] count = 0 for i in range(N): li = list(map(int, input().split())) nes.append(li) favorite = [0] * M for i in range(N): for j in range(1, nes[i][0] + 1): favorite[nes[i][j] - 1] += 1 for i in range(M): if favorite[i] == N: count += 1 print(count)
# template def inputlist(): return [int(k) for k in input().split()] # template N, M = inputlist() ans = [0] * (M + 1) c = 0 for i in range(N): A = inputlist() K = A[0] Aa = A[1:] for j in range(K): ans[Aa[j]] += 1 for i in range(1, M + 1): if ans[i] == N: c += 1 print(c)
false
12.5
[ "-N, M = list(map(int, input().split()))", "-nes = []", "-count = 0", "+# template", "+def inputlist():", "+ return [int(k) for k in input().split()]", "+", "+", "+# template", "+N, M = inputlist()", "+ans = [0] * (M + 1)", "+c = 0", "- li = list(map(int, input().split()))", "- nes.append(li)", "-favorite = [0] * M", "-for i in range(N):", "- for j in range(1, nes[i][0] + 1):", "- favorite[nes[i][j] - 1] += 1", "-for i in range(M):", "- if favorite[i] == N:", "- count += 1", "-print(count)", "+ A = inputlist()", "+ K = A[0]", "+ Aa = A[1:]", "+ for j in range(K):", "+ ans[Aa[j]] += 1", "+for i in range(1, M + 1):", "+ if ans[i] == N:", "+ c += 1", "+print(c)" ]
false
0.042869
0.036394
1.17791
[ "s060573365", "s367867873" ]
u060896757
p02613
python
s248560980
s145562010
271
156
85,012
84,200
Accepted
Accepted
42.44
import sys sys.setrecursionlimit(10 ** 6) input = sys.stdin.readline from math import floor, sqrt, factorial, hypot, log # log2ないyp from heapq import heappop, heappush, heappushpop from collections import Counter, defaultdict, deque from itertools import accumulate, permutations, combinations, product, combinations_with_replacement from bisect import bisect_left, bisect_right from copy import deepcopy from fractions import gcd from random import randint def ceil(a, b): return (a + b - 1) // b inf = float('inf') mod = 10 ** 9 + 7 def pprint(*A): for a in A: print(*a, sep='\n') def INT_(n): return int(n) - 1 def MI(): return map(int, input().split()) def MF(): return map(float, input().split()) def MI_(): return map(INT_, input().split()) def LI(): return list(MI()) def LI_(): return [int(x) - 1 for x in input().split()] def LF(): return list(MF()) def LIN(n: int): return [I() for _ in range(n)] def LLIN(n: int): return [LI() for _ in range(n)] def LLIN_(n: int): return [LI_() for _ in range(n)] def LLI(): return [list(map(int, l.split())) for l in input()] def I(): return int(input()) def F(): return float(input()) def ST(): return input().replace('\n', '') def main(): N = I() S = [] for _ in range(N): S.append(ST()) cnt = Counter(S) print("AC x", cnt['AC']) print("WA x", cnt['WA']) print("TLE x", cnt['TLE']) print("RE x", cnt['RE']) if __name__ == '__main__': main()
import sys sys.setrecursionlimit(10 ** 6) input = sys.stdin.readline from math import floor, sqrt, factorial, hypot, log # log2ないyp from heapq import heappop, heappush, heappushpop from collections import Counter, defaultdict, deque from itertools import accumulate, permutations, combinations, product, combinations_with_replacement from bisect import bisect_left, bisect_right from copy import deepcopy from fractions import gcd from random import randint def ceil(a, b): return (a + b - 1) // b inf = float('inf') mod = 10 ** 9 + 7 def pprint(*A): for a in A: print(*a, sep='\n') def INT_(n): return int(n) - 1 def MI(): return map(int, input().split()) def MF(): return map(float, input().split()) def MI_(): return map(INT_, input().split()) def LI(): return list(MI()) def LI_(): return [int(x) - 1 for x in input().split()] def LF(): return list(MF()) def LIN(n: int): return [I() for _ in range(n)] def LLIN(n: int): return [LI() for _ in range(n)] def LLIN_(n: int): return [LI_() for _ in range(n)] def LLI(): return [list(map(int, l.split())) for l in input()] def I(): return int(input()) def F(): return float(input()) def ST(): return input().replace('\n', '') def main(): N = I() AC = 0 WA = 0 TLE = 0 RE = 0 for _ in range(N): S = ST() if S == "AC": AC += 1 elif S == "WA": WA += 1 elif S == "TLE": TLE += 1 else: RE += 1 print("AC x", AC) print("WA x", WA) print("TLE x", TLE) print("RE x", RE) if __name__ == '__main__': main()
80
91
1,558
1,716
import sys sys.setrecursionlimit(10**6) input = sys.stdin.readline from math import floor, sqrt, factorial, hypot, log # log2ないyp from heapq import heappop, heappush, heappushpop from collections import Counter, defaultdict, deque from itertools import ( accumulate, permutations, combinations, product, combinations_with_replacement, ) from bisect import bisect_left, bisect_right from copy import deepcopy from fractions import gcd from random import randint def ceil(a, b): return (a + b - 1) // b inf = float("inf") mod = 10**9 + 7 def pprint(*A): for a in A: print(*a, sep="\n") def INT_(n): return int(n) - 1 def MI(): return map(int, input().split()) def MF(): return map(float, input().split()) def MI_(): return map(INT_, input().split()) def LI(): return list(MI()) def LI_(): return [int(x) - 1 for x in input().split()] def LF(): return list(MF()) def LIN(n: int): return [I() for _ in range(n)] def LLIN(n: int): return [LI() for _ in range(n)] def LLIN_(n: int): return [LI_() for _ in range(n)] def LLI(): return [list(map(int, l.split())) for l in input()] def I(): return int(input()) def F(): return float(input()) def ST(): return input().replace("\n", "") def main(): N = I() S = [] for _ in range(N): S.append(ST()) cnt = Counter(S) print("AC x", cnt["AC"]) print("WA x", cnt["WA"]) print("TLE x", cnt["TLE"]) print("RE x", cnt["RE"]) if __name__ == "__main__": main()
import sys sys.setrecursionlimit(10**6) input = sys.stdin.readline from math import floor, sqrt, factorial, hypot, log # log2ないyp from heapq import heappop, heappush, heappushpop from collections import Counter, defaultdict, deque from itertools import ( accumulate, permutations, combinations, product, combinations_with_replacement, ) from bisect import bisect_left, bisect_right from copy import deepcopy from fractions import gcd from random import randint def ceil(a, b): return (a + b - 1) // b inf = float("inf") mod = 10**9 + 7 def pprint(*A): for a in A: print(*a, sep="\n") def INT_(n): return int(n) - 1 def MI(): return map(int, input().split()) def MF(): return map(float, input().split()) def MI_(): return map(INT_, input().split()) def LI(): return list(MI()) def LI_(): return [int(x) - 1 for x in input().split()] def LF(): return list(MF()) def LIN(n: int): return [I() for _ in range(n)] def LLIN(n: int): return [LI() for _ in range(n)] def LLIN_(n: int): return [LI_() for _ in range(n)] def LLI(): return [list(map(int, l.split())) for l in input()] def I(): return int(input()) def F(): return float(input()) def ST(): return input().replace("\n", "") def main(): N = I() AC = 0 WA = 0 TLE = 0 RE = 0 for _ in range(N): S = ST() if S == "AC": AC += 1 elif S == "WA": WA += 1 elif S == "TLE": TLE += 1 else: RE += 1 print("AC x", AC) print("WA x", WA) print("TLE x", TLE) print("RE x", RE) if __name__ == "__main__": main()
false
12.087912
[ "- S = []", "+ AC = 0", "+ WA = 0", "+ TLE = 0", "+ RE = 0", "- S.append(ST())", "- cnt = Counter(S)", "- print(\"AC x\", cnt[\"AC\"])", "- print(\"WA x\", cnt[\"WA\"])", "- print(\"TLE x\", cnt[\"TLE\"])", "- print(\"RE x\", cnt[\"RE\"])", "+ S = ST()", "+ if S == \"AC\":", "+ AC += 1", "+ elif S == \"WA\":", "+ WA += 1", "+ elif S == \"TLE\":", "+ TLE += 1", "+ else:", "+ RE += 1", "+ print(\"AC x\", AC)", "+ print(\"WA x\", WA)", "+ print(\"TLE x\", TLE)", "+ print(\"RE x\", RE)" ]
false
0.086115
0.085427
1.008047
[ "s248560980", "s145562010" ]
u516613126
p03085
python
s499934879
s373109869
19
17
2,940
2,940
Accepted
Accepted
10.53
b = eval(input()) if b == "A": print("T") if b == "T": print("A") if b == "G": print("C") if b == "C": print("G")
d = {"A":"T","T":"A","C":"G","G":"C"} print((d[eval(input())]))
9
2
123
56
b = eval(input()) if b == "A": print("T") if b == "T": print("A") if b == "G": print("C") if b == "C": print("G")
d = {"A": "T", "T": "A", "C": "G", "G": "C"} print((d[eval(input())]))
false
77.777778
[ "-b = eval(input())", "-if b == \"A\":", "- print(\"T\")", "-if b == \"T\":", "- print(\"A\")", "-if b == \"G\":", "- print(\"C\")", "-if b == \"C\":", "- print(\"G\")", "+d = {\"A\": \"T\", \"T\": \"A\", \"C\": \"G\", \"G\": \"C\"}", "+print((d[eval(input())]))" ]
false
0.051452
0.051345
1.002078
[ "s499934879", "s373109869" ]
u654470292
p02775
python
s116869367
s693959462
947
557
187,456
143,144
Accepted
Accepted
41.18
import sys from collections import * import heapq import math import bisect from itertools import permutations,accumulate,combinations,product from fractions import gcd def input(): return sys.stdin.readline()[:-1] mod=pow(10,9)+7 n=eval(input()) # lst=[int(n[i]) for i in range(len(n))] # for i in range(len(n)): # lst.append(int(n[i])) # n=int(n) keta=len(n) ans=0 # lst.reverse() # dp=[[float('inf')]*2 for i in range(keta+1)] dp=[[0,1]] for i in range(keta): dp.append([float('inf')]*2) # dp[0]=[0,1] # print(dp) for i in range(keta): s=int(n[-1-i]) dp[i+1][0]=min(dp[i][0]+s,dp[i][1]+s+1) dp[i+1][1]=min(dp[i][0]+(10-s),dp[i][1]+(10-s-1)) # print(dp) print((min(dp[-1][0],dp[-1][1]+1)))
import sys from collections import * import heapq import math import bisect from itertools import permutations,accumulate,combinations,product from fractions import gcd def input(): return sys.stdin.readline()[:-1] mod=pow(10,9)+7 n=eval(input()) keta=len(n) ans=0 # dp=[[0,1]] # for i in range(keta): # dp.append([float('inf')]*2) dp0=[float('inf')]*(keta+1) dp1=[float('inf')]*(keta+1) dp0[0]=0 # dp[0]=[0,1] # print(dp) for i in range(keta): s=int(n[-1-i]) dp0[i+1]=min(dp0[i]+s,dp1[i]+s+1) dp1[i+1]=min(dp0[i]+(10-s),dp1[i]+(10-s-1)) # print(dp) print((min(dp0[-1],dp1[-1]+1)))
33
29
742
623
import sys from collections import * import heapq import math import bisect from itertools import permutations, accumulate, combinations, product from fractions import gcd def input(): return sys.stdin.readline()[:-1] mod = pow(10, 9) + 7 n = eval(input()) # lst=[int(n[i]) for i in range(len(n))] # for i in range(len(n)): # lst.append(int(n[i])) # n=int(n) keta = len(n) ans = 0 # lst.reverse() # dp=[[float('inf')]*2 for i in range(keta+1)] dp = [[0, 1]] for i in range(keta): dp.append([float("inf")] * 2) # dp[0]=[0,1] # print(dp) for i in range(keta): s = int(n[-1 - i]) dp[i + 1][0] = min(dp[i][0] + s, dp[i][1] + s + 1) dp[i + 1][1] = min(dp[i][0] + (10 - s), dp[i][1] + (10 - s - 1)) # print(dp) print((min(dp[-1][0], dp[-1][1] + 1)))
import sys from collections import * import heapq import math import bisect from itertools import permutations, accumulate, combinations, product from fractions import gcd def input(): return sys.stdin.readline()[:-1] mod = pow(10, 9) + 7 n = eval(input()) keta = len(n) ans = 0 # dp=[[0,1]] # for i in range(keta): # dp.append([float('inf')]*2) dp0 = [float("inf")] * (keta + 1) dp1 = [float("inf")] * (keta + 1) dp0[0] = 0 # dp[0]=[0,1] # print(dp) for i in range(keta): s = int(n[-1 - i]) dp0[i + 1] = min(dp0[i] + s, dp1[i] + s + 1) dp1[i + 1] = min(dp0[i] + (10 - s), dp1[i] + (10 - s - 1)) # print(dp) print((min(dp0[-1], dp1[-1] + 1)))
false
12.121212
[ "-# lst=[int(n[i]) for i in range(len(n))]", "-# for i in range(len(n)):", "-# lst.append(int(n[i]))", "-# n=int(n)", "-# lst.reverse()", "-# dp=[[float('inf')]*2 for i in range(keta+1)]", "-dp = [[0, 1]]", "-for i in range(keta):", "- dp.append([float(\"inf\")] * 2)", "+# dp=[[0,1]]", "+# for i in range(keta):", "+# dp.append([float('inf')]*2)", "+dp0 = [float(\"inf\")] * (keta + 1)", "+dp1 = [float(\"inf\")] * (keta + 1)", "+dp0[0] = 0", "- dp[i + 1][0] = min(dp[i][0] + s, dp[i][1] + s + 1)", "- dp[i + 1][1] = min(dp[i][0] + (10 - s), dp[i][1] + (10 - s - 1))", "+ dp0[i + 1] = min(dp0[i] + s, dp1[i] + s + 1)", "+ dp1[i + 1] = min(dp0[i] + (10 - s), dp1[i] + (10 - s - 1))", "-print((min(dp[-1][0], dp[-1][1] + 1)))", "+print((min(dp0[-1], dp1[-1] + 1)))" ]
false
0.03658
0.098423
0.371667
[ "s116869367", "s693959462" ]
u493520238
p02767
python
s582142259
s031667714
77
66
63,328
63,604
Accepted
Accepted
14.29
n = int(eval(input())) xl = list(map(int, input().split())) ans = 10**18 for i in range(0,101): curr_sum = 0 for x in xl: curr_sum += (i-x)*(i-x) ans = min(ans,curr_sum) print(ans)
n = int(eval(input())) xl = list(map(int, input().split())) ans = 10**9 for i in range(1,101): v = 0 for x in xl: v += (x-i)**2 ans = min(ans,v) print(ans)
11
11
206
189
n = int(eval(input())) xl = list(map(int, input().split())) ans = 10**18 for i in range(0, 101): curr_sum = 0 for x in xl: curr_sum += (i - x) * (i - x) ans = min(ans, curr_sum) print(ans)
n = int(eval(input())) xl = list(map(int, input().split())) ans = 10**9 for i in range(1, 101): v = 0 for x in xl: v += (x - i) ** 2 ans = min(ans, v) print(ans)
false
0
[ "-ans = 10**18", "-for i in range(0, 101):", "- curr_sum = 0", "+ans = 10**9", "+for i in range(1, 101):", "+ v = 0", "- curr_sum += (i - x) * (i - x)", "- ans = min(ans, curr_sum)", "+ v += (x - i) ** 2", "+ ans = min(ans, v)" ]
false
0.044589
0.044935
0.99229
[ "s582142259", "s031667714" ]
u546285759
p00012
python
s610403554
s803969326
30
20
7,620
5,592
Accepted
Accepted
33.33
import math def tri(x1, y1, x2, y2, x3, y3): return math.fabs((x2-x1)*(y3-y1) - (y2-y1)*(x3-x1)) / 2 while True: try: x1, y1, x2, y2, x3, y3, xp, yp = list(map(float, input().split())) except: break abc = tri(x1, y1, x2, y2, x3, y3) abp = tri(x1, y1, x2, y2, xp, yp) acp = tri(x1, y1, x3, y3, xp, yp) bcp = tri(x2, y2, x3, y3, xp, yp) x, y = int(abc*pow(10, 5)), int((abp+acp+bcp)*pow(10, 5)) print(("YES" if x >= y else "NO"))
while True: try: x1, y1, x2, y2, x3, y3, xp, yp = list(map(float, input().split())) except: break AB = [x2-x1, y2-y1] BC = [x3-x2, y3-y2] CA = [x1-x3, y1-y3] BP = [xp-x2, yp-y2] CP = [xp-x3, yp-y3] AP = [xp-x1, yp-y1] v1 = AB[0]*BP[1]-AB[1]*BP[0] v2 = BC[0]*CP[1]-BC[1]*CP[0] v3 = CA[0]*AP[1]-CA[1]*AP[0] print((["NO", "YES"][(v1<0 and v2<0 and v3<0) or (v1>0 and v2>0 and v3>0)]))
16
17
488
456
import math def tri(x1, y1, x2, y2, x3, y3): return math.fabs((x2 - x1) * (y3 - y1) - (y2 - y1) * (x3 - x1)) / 2 while True: try: x1, y1, x2, y2, x3, y3, xp, yp = list(map(float, input().split())) except: break abc = tri(x1, y1, x2, y2, x3, y3) abp = tri(x1, y1, x2, y2, xp, yp) acp = tri(x1, y1, x3, y3, xp, yp) bcp = tri(x2, y2, x3, y3, xp, yp) x, y = int(abc * pow(10, 5)), int((abp + acp + bcp) * pow(10, 5)) print(("YES" if x >= y else "NO"))
while True: try: x1, y1, x2, y2, x3, y3, xp, yp = list(map(float, input().split())) except: break AB = [x2 - x1, y2 - y1] BC = [x3 - x2, y3 - y2] CA = [x1 - x3, y1 - y3] BP = [xp - x2, yp - y2] CP = [xp - x3, yp - y3] AP = [xp - x1, yp - y1] v1 = AB[0] * BP[1] - AB[1] * BP[0] v2 = BC[0] * CP[1] - BC[1] * CP[0] v3 = CA[0] * AP[1] - CA[1] * AP[0] print( ( ["NO", "YES"][ (v1 < 0 and v2 < 0 and v3 < 0) or (v1 > 0 and v2 > 0 and v3 > 0) ] ) )
false
5.882353
[ "-import math", "-", "-", "-def tri(x1, y1, x2, y2, x3, y3):", "- return math.fabs((x2 - x1) * (y3 - y1) - (y2 - y1) * (x3 - x1)) / 2", "-", "-", "- abc = tri(x1, y1, x2, y2, x3, y3)", "- abp = tri(x1, y1, x2, y2, xp, yp)", "- acp = tri(x1, y1, x3, y3, xp, yp)", "- bcp = tri(x2, y2, x3, y3, xp, yp)", "- x, y = int(abc * pow(10, 5)), int((abp + acp + bcp) * pow(10, 5))", "- print((\"YES\" if x >= y else \"NO\"))", "+ AB = [x2 - x1, y2 - y1]", "+ BC = [x3 - x2, y3 - y2]", "+ CA = [x1 - x3, y1 - y3]", "+ BP = [xp - x2, yp - y2]", "+ CP = [xp - x3, yp - y3]", "+ AP = [xp - x1, yp - y1]", "+ v1 = AB[0] * BP[1] - AB[1] * BP[0]", "+ v2 = BC[0] * CP[1] - BC[1] * CP[0]", "+ v3 = CA[0] * AP[1] - CA[1] * AP[0]", "+ print(", "+ (", "+ [\"NO\", \"YES\"][", "+ (v1 < 0 and v2 < 0 and v3 < 0) or (v1 > 0 and v2 > 0 and v3 > 0)", "+ ]", "+ )", "+ )" ]
false
0.032553
0.036433
0.893492
[ "s610403554", "s803969326" ]
u223646582
p03163
python
s795024900
s262214310
951
745
258,312
171,912
Accepted
Accepted
21.66
# dp[i][w_sum]: i-1番目までの品物で重さがw_sumを超えないように選んだときの、価値の総和の最大値 N, W = list(map(int, input().split())) items = [tuple(map(int, input().split())) for i in range(N)] dp = [[0 for w_sum in range(W+100)] for i in range(N+100)] for i in range(N): for w_sum in range(W+1): # i-1番目の品物を選ぶ場合 # 重量的に入れられるなら入れてみる if w_sum-items[i][0] >= 0: dp[i+1][w_sum] = max(dp[i+1][w_sum], dp[i][w_sum-items[i][0]]+items[i][1]) # i-1番目の品物を選ばない場合 dp[i+1][w_sum] = max(dp[i+1][w_sum], dp[i][w_sum]) print((dp[N][W]))
# dp[i][w_sum]: i番目までの品物で重さがw_sumを超えないように選んだときの、価値の総和の最大値 N, W = list(map(int, input().split())) items = [tuple(map(int, input().split())) for i in range(N)] dp = [[0 for w_sum in range(W+1)] for i in range(N+1)] for i in range(N): for w_sum in range(W+1): # i-1番目の品物を選ぶ場合 # 重量的に入れられるなら入れてみる if w_sum+items[i][0] <= W: dp[i+1][w_sum+items[i][0]] = max(dp[i+1][w_sum+items[i][0]], dp[i][w_sum]+items[i][1]) # i-1番目の品物を選ばない場合 dp[i+1][w_sum] = max(dp[i+1][w_sum], dp[i][w_sum]) ans = 0 for w in range(W+1): ans = max(ans, dp[N][w]) print(ans)
20
22
593
665
# dp[i][w_sum]: i-1番目までの品物で重さがw_sumを超えないように選んだときの、価値の総和の最大値 N, W = list(map(int, input().split())) items = [tuple(map(int, input().split())) for i in range(N)] dp = [[0 for w_sum in range(W + 100)] for i in range(N + 100)] for i in range(N): for w_sum in range(W + 1): # i-1番目の品物を選ぶ場合 # 重量的に入れられるなら入れてみる if w_sum - items[i][0] >= 0: dp[i + 1][w_sum] = max( dp[i + 1][w_sum], dp[i][w_sum - items[i][0]] + items[i][1] ) # i-1番目の品物を選ばない場合 dp[i + 1][w_sum] = max(dp[i + 1][w_sum], dp[i][w_sum]) print((dp[N][W]))
# dp[i][w_sum]: i番目までの品物で重さがw_sumを超えないように選んだときの、価値の総和の最大値 N, W = list(map(int, input().split())) items = [tuple(map(int, input().split())) for i in range(N)] dp = [[0 for w_sum in range(W + 1)] for i in range(N + 1)] for i in range(N): for w_sum in range(W + 1): # i-1番目の品物を選ぶ場合 # 重量的に入れられるなら入れてみる if w_sum + items[i][0] <= W: dp[i + 1][w_sum + items[i][0]] = max( dp[i + 1][w_sum + items[i][0]], dp[i][w_sum] + items[i][1] ) # i-1番目の品物を選ばない場合 dp[i + 1][w_sum] = max(dp[i + 1][w_sum], dp[i][w_sum]) ans = 0 for w in range(W + 1): ans = max(ans, dp[N][w]) print(ans)
false
9.090909
[ "-# dp[i][w_sum]: i-1番目までの品物で重さがw_sumを超えないように選んだときの、価値の総和の最大値", "+# dp[i][w_sum]: i番目までの品物で重さがw_sumを超えないように選んだときの、価値の総和の最大値", "-dp = [[0 for w_sum in range(W + 100)] for i in range(N + 100)]", "+dp = [[0 for w_sum in range(W + 1)] for i in range(N + 1)]", "- if w_sum - items[i][0] >= 0:", "- dp[i + 1][w_sum] = max(", "- dp[i + 1][w_sum], dp[i][w_sum - items[i][0]] + items[i][1]", "+ if w_sum + items[i][0] <= W:", "+ dp[i + 1][w_sum + items[i][0]] = max(", "+ dp[i + 1][w_sum + items[i][0]], dp[i][w_sum] + items[i][1]", "-print((dp[N][W]))", "+ans = 0", "+for w in range(W + 1):", "+ ans = max(ans, dp[N][w])", "+print(ans)" ]
false
0.040105
0.038977
1.028932
[ "s795024900", "s262214310" ]
u133936772
p02788
python
s341636710
s005828270
1,608
1,028
82,008
76,508
Accepted
Accepted
36.07
f=lambda:list(map(int,input().split())) n,d,a=f() lt=sorted([tuple(f()) for _ in range(n)]) from collections import * q=deque() c=s=0 for x,h in lt: while q and q[0][0]<x: s+=q.popleft()[1] h-=s if h<1: continue t=-h//a; c-=t; s-=t*a; q.append((x+d*2,t*a)) print(c)
import sys f=lambda:list(map(int,sys.stdin.readline().split())) n,d,a=f() lt=sorted(tuple(f()) for _ in range(n)) from collections import * q=deque() c=s=0 for x,h in lt: while q and q[0][0]<x: s+=q.popleft()[1] h-=s if h<1: continue t=-h//a; c-=t; s-=t*a; q.append((x+d*2,t*a)) print(c)
12
13
279
302
f = lambda: list(map(int, input().split())) n, d, a = f() lt = sorted([tuple(f()) for _ in range(n)]) from collections import * q = deque() c = s = 0 for x, h in lt: while q and q[0][0] < x: s += q.popleft()[1] h -= s if h < 1: continue t = -h // a c -= t s -= t * a q.append((x + d * 2, t * a)) print(c)
import sys f = lambda: list(map(int, sys.stdin.readline().split())) n, d, a = f() lt = sorted(tuple(f()) for _ in range(n)) from collections import * q = deque() c = s = 0 for x, h in lt: while q and q[0][0] < x: s += q.popleft()[1] h -= s if h < 1: continue t = -h // a c -= t s -= t * a q.append((x + d * 2, t * a)) print(c)
false
7.692308
[ "-f = lambda: list(map(int, input().split()))", "+import sys", "+", "+f = lambda: list(map(int, sys.stdin.readline().split()))", "-lt = sorted([tuple(f()) for _ in range(n)])", "+lt = sorted(tuple(f()) for _ in range(n))" ]
false
0.042494
0.060358
0.704028
[ "s341636710", "s005828270" ]
u401487574
p02948
python
s247718831
s180615351
1,013
557
67,928
17,660
Accepted
Accepted
45.01
import heapq as hq n,m = list(map(int,input().split())) ab = [] for i in range(n): a,b = list(map(int,input().split())) ab.append((a,-b)) ab.sort() #日が短い順に ans = 0 idx = 0 q = [] for i in range(1,m+1): while idx<n and ab[idx][0] ==i: a,mb = ab[idx] hq.heappush(q,mb) idx+=1 if q!=[]: ans += -1*hq.heappop(q) print(ans)
import heapq as hq n,m = list(map(int,input().split())) ab = [] for i in range(n): a,b = list(map(int,input().split())) ab.append((a,-b)) ab.sort() ans = 0 idx = 0 q = [] for i in range(1,m+1): while idx<n and ab[idx][0] ==i: a,mb = ab[idx] hq.heappush(q,mb) idx+=1 if q!=[]: ans += -1*hq.heappop(q) print(ans)
19
19
374
366
import heapq as hq n, m = list(map(int, input().split())) ab = [] for i in range(n): a, b = list(map(int, input().split())) ab.append((a, -b)) ab.sort() # 日が短い順に ans = 0 idx = 0 q = [] for i in range(1, m + 1): while idx < n and ab[idx][0] == i: a, mb = ab[idx] hq.heappush(q, mb) idx += 1 if q != []: ans += -1 * hq.heappop(q) print(ans)
import heapq as hq n, m = list(map(int, input().split())) ab = [] for i in range(n): a, b = list(map(int, input().split())) ab.append((a, -b)) ab.sort() ans = 0 idx = 0 q = [] for i in range(1, m + 1): while idx < n and ab[idx][0] == i: a, mb = ab[idx] hq.heappush(q, mb) idx += 1 if q != []: ans += -1 * hq.heappop(q) print(ans)
false
0
[ "-ab.sort() # 日が短い順に", "+ab.sort()" ]
false
0.037484
0.035578
1.053569
[ "s247718831", "s180615351" ]
u918601425
p02847
python
s764018711
s591532566
164
18
38,256
2,940
Accepted
Accepted
89.02
ls=['SUN','MON','TUE','WED','THU','FRI','SAT'] x=eval(input()) for i in range(7): if x==ls[i]: print((7-i)) break
S=eval(input()) if S=='SUN': print((7)) elif S=='MON': print((6)) elif S=='TUE': print((5)) elif S=='WED': print((4)) elif S=='THU': print((3)) elif S=='FRI': print((2)) else: print((1))
6
15
121
194
ls = ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"] x = eval(input()) for i in range(7): if x == ls[i]: print((7 - i)) break
S = eval(input()) if S == "SUN": print((7)) elif S == "MON": print((6)) elif S == "TUE": print((5)) elif S == "WED": print((4)) elif S == "THU": print((3)) elif S == "FRI": print((2)) else: print((1))
false
60
[ "-ls = [\"SUN\", \"MON\", \"TUE\", \"WED\", \"THU\", \"FRI\", \"SAT\"]", "-x = eval(input())", "-for i in range(7):", "- if x == ls[i]:", "- print((7 - i))", "- break", "+S = eval(input())", "+if S == \"SUN\":", "+ print((7))", "+elif S == \"MON\":", "+ print((6))", "+elif S == \"TUE\":", "+ print((5))", "+elif S == \"WED\":", "+ print((4))", "+elif S == \"THU\":", "+ print((3))", "+elif S == \"FRI\":", "+ print((2))", "+else:", "+ print((1))" ]
false
0.121627
0.037913
3.208078
[ "s764018711", "s591532566" ]
u364555831
p02753
python
s709442319
s284289406
32
29
9,036
8,992
Accepted
Accepted
9.38
S = eval(input()) if S[0] == S[1] == S[2]: print("No") else: print("Yes")
S = list(eval(input())) #print(set(S)) setS = set(S) if len(setS) == 2: print("Yes") else: print("No")
5
9
80
115
S = eval(input()) if S[0] == S[1] == S[2]: print("No") else: print("Yes")
S = list(eval(input())) # print(set(S)) setS = set(S) if len(setS) == 2: print("Yes") else: print("No")
false
44.444444
[ "-S = eval(input())", "-if S[0] == S[1] == S[2]:", "+S = list(eval(input()))", "+# print(set(S))", "+setS = set(S)", "+if len(setS) == 2:", "+ print(\"Yes\")", "+else:", "-else:", "- print(\"Yes\")" ]
false
0.039501
0.041594
0.949678
[ "s709442319", "s284289406" ]
u015593272
p02755
python
s654141802
s151742069
19
17
3,060
3,064
Accepted
Accepted
10.53
import math A, B = list(map(int, input().split())) ans = -1 for i in range(1, 1251): a = int(math.floor(i * 0.08)) b = int(math.floor(i * 0.1)) if (a == A and b == B): ans = i break print(ans)
# O(1) solution import math A, B = list(map(int, input().split())) min_A = int(math.ceil(A * 12.5)) max_A = int(math.ceil((A + 1) * 12.5) - 1) grp_A = {i for i in range(min_A, max_A + 1)} min_B = int(math.ceil(B * 10)) max_B = int(math.ceil((B + 1) * 10) - 1) grp_B = {i for i in range(min_B, max_B + 1)} ans = grp_A & grp_B if (len(ans) == 0): ans = -1 else: ans = min(ans) print(ans)
17
23
241
417
import math A, B = list(map(int, input().split())) ans = -1 for i in range(1, 1251): a = int(math.floor(i * 0.08)) b = int(math.floor(i * 0.1)) if a == A and b == B: ans = i break print(ans)
# O(1) solution import math A, B = list(map(int, input().split())) min_A = int(math.ceil(A * 12.5)) max_A = int(math.ceil((A + 1) * 12.5) - 1) grp_A = {i for i in range(min_A, max_A + 1)} min_B = int(math.ceil(B * 10)) max_B = int(math.ceil((B + 1) * 10) - 1) grp_B = {i for i in range(min_B, max_B + 1)} ans = grp_A & grp_B if len(ans) == 0: ans = -1 else: ans = min(ans) print(ans)
false
26.086957
[ "+# O(1) solution", "-ans = -1", "-for i in range(1, 1251):", "- a = int(math.floor(i * 0.08))", "- b = int(math.floor(i * 0.1))", "- if a == A and b == B:", "- ans = i", "- break", "+min_A = int(math.ceil(A * 12.5))", "+max_A = int(math.ceil((A + 1) * 12.5) - 1)", "+grp_A = {i for i in range(min_A, max_A + 1)}", "+min_B = int(math.ceil(B * 10))", "+max_B = int(math.ceil((B + 1) * 10) - 1)", "+grp_B = {i for i in range(min_B, max_B + 1)}", "+ans = grp_A & grp_B", "+if len(ans) == 0:", "+ ans = -1", "+else:", "+ ans = min(ans)" ]
false
0.06515
0.061318
1.06249
[ "s654141802", "s151742069" ]
u089376182
p02861
python
s200105911
s390963330
482
287
9,460
13,928
Accepted
Accepted
40.46
import itertools n = int(eval(input())) city_pos = [list(map(int, input().split())) for _ in range(n)] dist_list = list() dist_way = list(itertools.permutations(list(range(n)))) for dist_i in dist_way: dist = 0 for i in range(len(dist_i)-1): dist += ((city_pos[dist_i[i]][0] - city_pos[dist_i[i+1]][0])**2 + (city_pos[dist_i[i]][1] - city_pos[dist_i[i+1]][1])**2)**(0.5) dist_list.append(dist) print((sum(dist_list)/len(dist_list)))
import itertools n = int(eval(input())) XY = [list(map(int, input().split())) for _ in range(n)] cand = list(itertools.permutations(list(range(n)), n)) ans = 0 for cand_i in cand: for i in range(n-1): ans += ((XY[cand_i[i]][0]-XY[cand_i[i+1]][0])**2+(XY[cand_i[i]][1]-XY[cand_i[i+1]][1])**2)**(1/2) print((ans/len(cand)))
17
13
454
335
import itertools n = int(eval(input())) city_pos = [list(map(int, input().split())) for _ in range(n)] dist_list = list() dist_way = list(itertools.permutations(list(range(n)))) for dist_i in dist_way: dist = 0 for i in range(len(dist_i) - 1): dist += ( (city_pos[dist_i[i]][0] - city_pos[dist_i[i + 1]][0]) ** 2 + (city_pos[dist_i[i]][1] - city_pos[dist_i[i + 1]][1]) ** 2 ) ** (0.5) dist_list.append(dist) print((sum(dist_list) / len(dist_list)))
import itertools n = int(eval(input())) XY = [list(map(int, input().split())) for _ in range(n)] cand = list(itertools.permutations(list(range(n)), n)) ans = 0 for cand_i in cand: for i in range(n - 1): ans += ( (XY[cand_i[i]][0] - XY[cand_i[i + 1]][0]) ** 2 + (XY[cand_i[i]][1] - XY[cand_i[i + 1]][1]) ** 2 ) ** (1 / 2) print((ans / len(cand)))
false
23.529412
[ "-city_pos = [list(map(int, input().split())) for _ in range(n)]", "-dist_list = list()", "-dist_way = list(itertools.permutations(list(range(n))))", "-for dist_i in dist_way:", "- dist = 0", "- for i in range(len(dist_i) - 1):", "- dist += (", "- (city_pos[dist_i[i]][0] - city_pos[dist_i[i + 1]][0]) ** 2", "- + (city_pos[dist_i[i]][1] - city_pos[dist_i[i + 1]][1]) ** 2", "- ) ** (0.5)", "- dist_list.append(dist)", "-print((sum(dist_list) / len(dist_list)))", "+XY = [list(map(int, input().split())) for _ in range(n)]", "+cand = list(itertools.permutations(list(range(n)), n))", "+ans = 0", "+for cand_i in cand:", "+ for i in range(n - 1):", "+ ans += (", "+ (XY[cand_i[i]][0] - XY[cand_i[i + 1]][0]) ** 2", "+ + (XY[cand_i[i]][1] - XY[cand_i[i + 1]][1]) ** 2", "+ ) ** (1 / 2)", "+print((ans / len(cand)))" ]
false
0.042958
0.08193
0.524325
[ "s200105911", "s390963330" ]
u352394527
p01631
python
s990839492
s639795659
4,620
2,440
6,124
6,156
Accepted
Accepted
47.19
def main(): n = int(eval(input())) words = [] scores = [] for _ in range(n): word, score = input().split() words.append(word) scores.append(int(score)) mp = ["#" * 6] + ["#" + eval(input()) + "#" for _ in range(4)] + ["#" * 6] t = int(eval(input())) def search(word): used = [[False] * 6 for _ in range(6)] vec = ((1, 0), (1, -1), (0, -1), (-1, -1), (-1, 0), (-1, 1), (0, 1), (1, 1)) def _search(word, pos, x, y): if pos == len(word) - 1:return 1 used[y][x] = True ret = 0 for dx, dy in vec: nx, ny = x + dx, y + dy if not used[ny][nx] and mp[ny][nx] == word[pos + 1]: ret += _search(word, pos + 1, nx, ny) used[y][x] = False return ret ret = 0 for y in range(1, 5): for x in range(1, 5): if mp[y][x] == word[0]:ret += _search(word, 0, x, y) return ret values = [] weights = [] for word, score in zip(words, scores): cnt = search(word) acc = 1 while cnt >= acc: cnt -= acc values.append(score * acc) weights.append(len(word) * acc) acc *= 2 if cnt: values.append(score * cnt) weights.append(len(word) * cnt) dp = [0] * (t + 1) for v, w in zip(values, weights): for x in range(max(-1, t - w), -1, -1): dp[x + w] = max(dp[x + w], dp[x] + v) print((max(dp))) main()
def main(): n = int(eval(input())) lst = [] for _ in range(n): word, score = input().split() lst.append((word, int(score))) mp = ["#" * 6] + ["#" + eval(input()) + "#" for _ in range(4)] + ["#" * 6] t = int(eval(input())) def search(word): used = [[False] * 6 for _ in range(6)] vec = ((1, 0), (1, -1), (0, -1), (-1, -1), (-1, 0), (-1, 1), (0, 1), (1, 1)) def _search(word, pos, x, y): if pos == len(word) - 1:return 1 used[y][x] = True ret = 0 for dx, dy in vec: nx, ny = x + dx, y + dy if not used[ny][nx] and mp[ny][nx] == word[pos + 1]: ret += _search(word, pos + 1, nx, ny) used[y][x] = False return ret ret = 0 for y in range(1, 5): for x in range(1, 5): if mp[y][x] == word[0]:ret += _search(word, 0, x, y) return ret items = [] for word, score in lst: cnt = search(word) acc = 1 weight = len(word) while cnt >= acc: cnt -= acc items.append((score * acc, weight * acc)) acc *= 2 if cnt: items.append((score * cnt, weight * cnt)) dp = [0] * (t + 1) for v, w in items: for x in range(t - w, -1, -1): if dp[x + w] < dp[x] + v:dp[x + w] = dp[x] + v print((max(dp))) main()
53
49
1,418
1,311
def main(): n = int(eval(input())) words = [] scores = [] for _ in range(n): word, score = input().split() words.append(word) scores.append(int(score)) mp = ["#" * 6] + ["#" + eval(input()) + "#" for _ in range(4)] + ["#" * 6] t = int(eval(input())) def search(word): used = [[False] * 6 for _ in range(6)] vec = ((1, 0), (1, -1), (0, -1), (-1, -1), (-1, 0), (-1, 1), (0, 1), (1, 1)) def _search(word, pos, x, y): if pos == len(word) - 1: return 1 used[y][x] = True ret = 0 for dx, dy in vec: nx, ny = x + dx, y + dy if not used[ny][nx] and mp[ny][nx] == word[pos + 1]: ret += _search(word, pos + 1, nx, ny) used[y][x] = False return ret ret = 0 for y in range(1, 5): for x in range(1, 5): if mp[y][x] == word[0]: ret += _search(word, 0, x, y) return ret values = [] weights = [] for word, score in zip(words, scores): cnt = search(word) acc = 1 while cnt >= acc: cnt -= acc values.append(score * acc) weights.append(len(word) * acc) acc *= 2 if cnt: values.append(score * cnt) weights.append(len(word) * cnt) dp = [0] * (t + 1) for v, w in zip(values, weights): for x in range(max(-1, t - w), -1, -1): dp[x + w] = max(dp[x + w], dp[x] + v) print((max(dp))) main()
def main(): n = int(eval(input())) lst = [] for _ in range(n): word, score = input().split() lst.append((word, int(score))) mp = ["#" * 6] + ["#" + eval(input()) + "#" for _ in range(4)] + ["#" * 6] t = int(eval(input())) def search(word): used = [[False] * 6 for _ in range(6)] vec = ((1, 0), (1, -1), (0, -1), (-1, -1), (-1, 0), (-1, 1), (0, 1), (1, 1)) def _search(word, pos, x, y): if pos == len(word) - 1: return 1 used[y][x] = True ret = 0 for dx, dy in vec: nx, ny = x + dx, y + dy if not used[ny][nx] and mp[ny][nx] == word[pos + 1]: ret += _search(word, pos + 1, nx, ny) used[y][x] = False return ret ret = 0 for y in range(1, 5): for x in range(1, 5): if mp[y][x] == word[0]: ret += _search(word, 0, x, y) return ret items = [] for word, score in lst: cnt = search(word) acc = 1 weight = len(word) while cnt >= acc: cnt -= acc items.append((score * acc, weight * acc)) acc *= 2 if cnt: items.append((score * cnt, weight * cnt)) dp = [0] * (t + 1) for v, w in items: for x in range(t - w, -1, -1): if dp[x + w] < dp[x] + v: dp[x + w] = dp[x] + v print((max(dp))) main()
false
7.54717
[ "- words = []", "- scores = []", "+ lst = []", "- words.append(word)", "- scores.append(int(score))", "+ lst.append((word, int(score)))", "- values = []", "- weights = []", "- for word, score in zip(words, scores):", "+ items = []", "+ for word, score in lst:", "+ weight = len(word)", "- values.append(score * acc)", "- weights.append(len(word) * acc)", "+ items.append((score * acc, weight * acc))", "- values.append(score * cnt)", "- weights.append(len(word) * cnt)", "+ items.append((score * cnt, weight * cnt))", "- for v, w in zip(values, weights):", "- for x in range(max(-1, t - w), -1, -1):", "- dp[x + w] = max(dp[x + w], dp[x] + v)", "+ for v, w in items:", "+ for x in range(t - w, -1, -1):", "+ if dp[x + w] < dp[x] + v:", "+ dp[x + w] = dp[x] + v" ]
false
0.04725
0.039618
1.192646
[ "s990839492", "s639795659" ]
u044220565
p02732
python
s029482999
s086835801
520
260
26,140
20,396
Accepted
Accepted
50
# coding: utf-8 N = int(eval(input())) A = list(map(int, input().split())) dict = {} for i in range(N): if A[i] in list(dict.keys()): dict[A[i]] += 1 else: dict[A[i]] = 1 def comb(n): if n<2: return 0 return int(n * (n - 1) / 2) # all ret = 0 for key in list(dict.keys()): val = dict[key] ret += comb(val) # i >= 0 for i in range(N): val_n = dict[A[i]] next_ret = ret - comb(val_n) + comb(val_n - 1) print(next_ret)
# coding: utf-8 import sys #from operator import itemgetter sysread = sys.stdin.buffer.readline read = sys.stdin.buffer.read #from heapq import heappop, heappush #from collections import defaultdict sys.setrecursionlimit(10**7) #import math #from itertools import product#accumulate, combinations, product #import bisect# lower_bound etc #import numpy as np #from copy import deepcopy #from collections import deque def run(): N = int(sysread()) A = list(map(int, sysread().split())) count = [0] * (N+1) for val in A: count[val] += 1 base_sum = 0 for val in count: if val <= 1:continue base_sum += val * (val-1) // 2 for i in range(N): if count[A[i]] == 1: print(base_sum) else: print((base_sum - count[A[i]] + 1)) if __name__ == "__main__": run()
27
31
457
872
# coding: utf-8 N = int(eval(input())) A = list(map(int, input().split())) dict = {} for i in range(N): if A[i] in list(dict.keys()): dict[A[i]] += 1 else: dict[A[i]] = 1 def comb(n): if n < 2: return 0 return int(n * (n - 1) / 2) # all ret = 0 for key in list(dict.keys()): val = dict[key] ret += comb(val) # i >= 0 for i in range(N): val_n = dict[A[i]] next_ret = ret - comb(val_n) + comb(val_n - 1) print(next_ret)
# coding: utf-8 import sys # from operator import itemgetter sysread = sys.stdin.buffer.readline read = sys.stdin.buffer.read # from heapq import heappop, heappush # from collections import defaultdict sys.setrecursionlimit(10**7) # import math # from itertools import product#accumulate, combinations, product # import bisect# lower_bound etc # import numpy as np # from copy import deepcopy # from collections import deque def run(): N = int(sysread()) A = list(map(int, sysread().split())) count = [0] * (N + 1) for val in A: count[val] += 1 base_sum = 0 for val in count: if val <= 1: continue base_sum += val * (val - 1) // 2 for i in range(N): if count[A[i]] == 1: print(base_sum) else: print((base_sum - count[A[i]] + 1)) if __name__ == "__main__": run()
false
12.903226
[ "-N = int(eval(input()))", "-A = list(map(int, input().split()))", "-dict = {}", "-for i in range(N):", "- if A[i] in list(dict.keys()):", "- dict[A[i]] += 1", "- else:", "- dict[A[i]] = 1", "+import sys", "+", "+# from operator import itemgetter", "+sysread = sys.stdin.buffer.readline", "+read = sys.stdin.buffer.read", "+# from heapq import heappop, heappush", "+# from collections import defaultdict", "+sys.setrecursionlimit(10**7)", "+# import math", "+# from itertools import product#accumulate, combinations, product", "+# import bisect# lower_bound etc", "+# import numpy as np", "+# from copy import deepcopy", "+# from collections import deque", "+def run():", "+ N = int(sysread())", "+ A = list(map(int, sysread().split()))", "+ count = [0] * (N + 1)", "+ for val in A:", "+ count[val] += 1", "+ base_sum = 0", "+ for val in count:", "+ if val <= 1:", "+ continue", "+ base_sum += val * (val - 1) // 2", "+ for i in range(N):", "+ if count[A[i]] == 1:", "+ print(base_sum)", "+ else:", "+ print((base_sum - count[A[i]] + 1))", "-def comb(n):", "- if n < 2:", "- return 0", "- return int(n * (n - 1) / 2)", "-", "-", "-# all", "-ret = 0", "-for key in list(dict.keys()):", "- val = dict[key]", "- ret += comb(val)", "-# i >= 0", "-for i in range(N):", "- val_n = dict[A[i]]", "- next_ret = ret - comb(val_n) + comb(val_n - 1)", "- print(next_ret)", "+if __name__ == \"__main__\":", "+ run()" ]
false
0.078198
0.07756
1.00822
[ "s029482999", "s086835801" ]
u761320129
p03503
python
s987014341
s067375803
391
292
3,064
3,064
Accepted
Accepted
25.32
N = int(eval(input())) isopen = [list(map(int,input().split())) for i in range(N)] gain = [list(map(int,input().split())) for i in range(N)] ans = -float('inf') for i in range(1,2**10): tmp = 0 for n in range(N): c = 0 for b in range(10): if ((i >> b)&1) & isopen[n][b]: c += 1 tmp += gain[n][c] ans = max(ans, tmp) print(ans)
N = int(eval(input())) F = [list(map(int,input().split())) for i in range(N)] P = [list(map(int,input().split())) for i in range(N)] ans = -float('inf') for b in range(1,2**10): tmp = 0 for i in range(N): c = 0 for k in range(10): if b&(1<<k) and F[i][k]: c += 1 tmp += P[i][c] ans = max(ans,tmp) print(ans)
15
15
400
381
N = int(eval(input())) isopen = [list(map(int, input().split())) for i in range(N)] gain = [list(map(int, input().split())) for i in range(N)] ans = -float("inf") for i in range(1, 2**10): tmp = 0 for n in range(N): c = 0 for b in range(10): if ((i >> b) & 1) & isopen[n][b]: c += 1 tmp += gain[n][c] ans = max(ans, tmp) print(ans)
N = int(eval(input())) F = [list(map(int, input().split())) for i in range(N)] P = [list(map(int, input().split())) for i in range(N)] ans = -float("inf") for b in range(1, 2**10): tmp = 0 for i in range(N): c = 0 for k in range(10): if b & (1 << k) and F[i][k]: c += 1 tmp += P[i][c] ans = max(ans, tmp) print(ans)
false
0
[ "-isopen = [list(map(int, input().split())) for i in range(N)]", "-gain = [list(map(int, input().split())) for i in range(N)]", "+F = [list(map(int, input().split())) for i in range(N)]", "+P = [list(map(int, input().split())) for i in range(N)]", "-for i in range(1, 2**10):", "+for b in range(1, 2**10):", "- for n in range(N):", "+ for i in range(N):", "- for b in range(10):", "- if ((i >> b) & 1) & isopen[n][b]:", "+ for k in range(10):", "+ if b & (1 << k) and F[i][k]:", "- tmp += gain[n][c]", "+ tmp += P[i][c]" ]
false
0.132354
0.120981
1.094004
[ "s987014341", "s067375803" ]
u888092736
p03031
python
s633756929
s811276865
37
30
3,064
3,064
Accepted
Accepted
18.92
N, M = list(map(int, input().split())) bulbs = [] for i in range(M): k, *s = list(map(int, input().split())) bulbs.append((k, s)) p = list(map(int, input().split())) ans = 0 for i in range(1 << N): on_cnt = [0] * M for j in range(N): if i >> j & 1: for k in range(M): if j + 1 in bulbs[k][1]: on_cnt[k] ^= 1 if on_cnt == p: ans += 1 print(ans)
N, M = list(map(int, input().split())) bulbs = [] for i in range(M): _, *conn_switches = list(map(int, input().split())) bulbs.append(conn_switches) P = list(map(int, input().split())) ans = 0 for i in range(1 << N): on_cnt = [0] * M for j, conn_switches in enumerate(bulbs): if P[j] ^ sum(i >> s - 1 & 1 for s in conn_switches) & 1: break else: ans += 1 print(ans)
18
16
434
418
N, M = list(map(int, input().split())) bulbs = [] for i in range(M): k, *s = list(map(int, input().split())) bulbs.append((k, s)) p = list(map(int, input().split())) ans = 0 for i in range(1 << N): on_cnt = [0] * M for j in range(N): if i >> j & 1: for k in range(M): if j + 1 in bulbs[k][1]: on_cnt[k] ^= 1 if on_cnt == p: ans += 1 print(ans)
N, M = list(map(int, input().split())) bulbs = [] for i in range(M): _, *conn_switches = list(map(int, input().split())) bulbs.append(conn_switches) P = list(map(int, input().split())) ans = 0 for i in range(1 << N): on_cnt = [0] * M for j, conn_switches in enumerate(bulbs): if P[j] ^ sum(i >> s - 1 & 1 for s in conn_switches) & 1: break else: ans += 1 print(ans)
false
11.111111
[ "- k, *s = list(map(int, input().split()))", "- bulbs.append((k, s))", "-p = list(map(int, input().split()))", "+ _, *conn_switches = list(map(int, input().split()))", "+ bulbs.append(conn_switches)", "+P = list(map(int, input().split()))", "- for j in range(N):", "- if i >> j & 1:", "- for k in range(M):", "- if j + 1 in bulbs[k][1]:", "- on_cnt[k] ^= 1", "- if on_cnt == p:", "+ for j, conn_switches in enumerate(bulbs):", "+ if P[j] ^ sum(i >> s - 1 & 1 for s in conn_switches) & 1:", "+ break", "+ else:" ]
false
0.038825
0.038812
1.000328
[ "s633756929", "s811276865" ]
u620480037
p03575
python
s067291390
s574592792
1,916
209
3,572
41,456
Accepted
Accepted
89.09
import copy N,M=list(map(int,input().split())) A=[] L=[[1000for i in range(N)]for j in range(N)] for i in range(M): a,b=list(map(int,input().split())) A.append([a,b]) L[a-1][b-1]=1 L[b-1][a-1]=1 for j in range(N): L[j][j]=0 #print(L) l=copy.deepcopy(L) cnt=0 for k in range(M): L=copy.deepcopy(l) L[A[k][0]-1][A[k][1]-1]=1000 L[A[k][1]-1][A[k][0]-1]=1000 for x in range(N): for y in range(N): for z in range(N): if L[y][z]>L[y][x]+L[x][z]: L[y][z]=L[y][x]+L[x][z] #print(L[A[k][0]-1][A[k][1]-1]) if L[A[k][0]-1][A[k][1]-1]>=1000: cnt+=1 L[A[k][0]-1][A[k][1]-1]=1 L[A[k][1]-1][A[k][0]-1]=1 #print(L) print(cnt)
import copy N,M=list(map(int,input().split())) A=[] for i in range(M): a,b=list(map(int,input().split())) A.append([a,b]) ANS=0 for i in range(M): L=[[]for _ in range(N+1)] for j in range(M): if i==j: continue else: L[A[j][0]].append((A[j][1],A[j][0])) L[A[j][1]].append((A[j][0],A[j][1])) X=1 C=[100 for i in range(N+1)] C[1]=1 C[0]=1 Q=L[1] #print(L) for j in range(1000): if len(Q)==j: break if C[Q[j][0]]==100: C[Q[j][0]]=C[Q[j][1]]+1 for k in L[Q[j][0]]: if C[k[0]]==100: Q.append((k[0],k[1])) #print(Q) #print(C) if 100 in C: ANS+=1 print(ANS)
33
36
755
782
import copy N, M = list(map(int, input().split())) A = [] L = [[1000 for i in range(N)] for j in range(N)] for i in range(M): a, b = list(map(int, input().split())) A.append([a, b]) L[a - 1][b - 1] = 1 L[b - 1][a - 1] = 1 for j in range(N): L[j][j] = 0 # print(L) l = copy.deepcopy(L) cnt = 0 for k in range(M): L = copy.deepcopy(l) L[A[k][0] - 1][A[k][1] - 1] = 1000 L[A[k][1] - 1][A[k][0] - 1] = 1000 for x in range(N): for y in range(N): for z in range(N): if L[y][z] > L[y][x] + L[x][z]: L[y][z] = L[y][x] + L[x][z] # print(L[A[k][0]-1][A[k][1]-1]) if L[A[k][0] - 1][A[k][1] - 1] >= 1000: cnt += 1 L[A[k][0] - 1][A[k][1] - 1] = 1 L[A[k][1] - 1][A[k][0] - 1] = 1 # print(L) print(cnt)
import copy N, M = list(map(int, input().split())) A = [] for i in range(M): a, b = list(map(int, input().split())) A.append([a, b]) ANS = 0 for i in range(M): L = [[] for _ in range(N + 1)] for j in range(M): if i == j: continue else: L[A[j][0]].append((A[j][1], A[j][0])) L[A[j][1]].append((A[j][0], A[j][1])) X = 1 C = [100 for i in range(N + 1)] C[1] = 1 C[0] = 1 Q = L[1] # print(L) for j in range(1000): if len(Q) == j: break if C[Q[j][0]] == 100: C[Q[j][0]] = C[Q[j][1]] + 1 for k in L[Q[j][0]]: if C[k[0]] == 100: Q.append((k[0], k[1])) # print(Q) # print(C) if 100 in C: ANS += 1 print(ANS)
false
8.333333
[ "-L = [[1000 for i in range(N)] for j in range(N)]", "- L[a - 1][b - 1] = 1", "- L[b - 1][a - 1] = 1", "-for j in range(N):", "- L[j][j] = 0", "-# print(L)", "-l = copy.deepcopy(L)", "-cnt = 0", "-for k in range(M):", "- L = copy.deepcopy(l)", "- L[A[k][0] - 1][A[k][1] - 1] = 1000", "- L[A[k][1] - 1][A[k][0] - 1] = 1000", "- for x in range(N):", "- for y in range(N):", "- for z in range(N):", "- if L[y][z] > L[y][x] + L[x][z]:", "- L[y][z] = L[y][x] + L[x][z]", "- # print(L[A[k][0]-1][A[k][1]-1])", "- if L[A[k][0] - 1][A[k][1] - 1] >= 1000:", "- cnt += 1", "- L[A[k][0] - 1][A[k][1] - 1] = 1", "- L[A[k][1] - 1][A[k][0] - 1] = 1", "-# print(L)", "-print(cnt)", "+ANS = 0", "+for i in range(M):", "+ L = [[] for _ in range(N + 1)]", "+ for j in range(M):", "+ if i == j:", "+ continue", "+ else:", "+ L[A[j][0]].append((A[j][1], A[j][0]))", "+ L[A[j][1]].append((A[j][0], A[j][1]))", "+ X = 1", "+ C = [100 for i in range(N + 1)]", "+ C[1] = 1", "+ C[0] = 1", "+ Q = L[1]", "+ # print(L)", "+ for j in range(1000):", "+ if len(Q) == j:", "+ break", "+ if C[Q[j][0]] == 100:", "+ C[Q[j][0]] = C[Q[j][1]] + 1", "+ for k in L[Q[j][0]]:", "+ if C[k[0]] == 100:", "+ Q.append((k[0], k[1]))", "+ # print(Q)", "+ # print(C)", "+ if 100 in C:", "+ ANS += 1", "+print(ANS)" ]
false
0.128596
0.043833
2.933761
[ "s067291390", "s574592792" ]
u170201762
p02863
python
s770705747
s799636686
1,228
582
181,764
117,336
Accepted
Accepted
52.61
N,T = list(map(int,input().split())) AB = [list(map(int,input().split())) for _ in range(N)] AB.sort(key=lambda x:x[1]) dp1 = [[0]*T for i in range(N+1)] for n in range(N): for w in range(T): if w-AB[n][0]>=0: dp1[n+1][w] = max(dp1[n][w],dp1[n][w-AB[n][0]]+AB[n][1]) else: dp1[n+1][w] = dp1[n][w] for n in range(N): for w in range(T-1): dp1[n][w+1] = max(dp1[n][w+1],dp1[n][w]) dp2 = [[0]*T for i in range(N+1)] for n in range(N): for w in range(T): if w-AB[-n-1][0]>=0: dp2[n+1][w] = max(dp2[n][w],dp2[n][w-AB[-n-1][0]]+AB[-n-1][1]) else: dp2[n+1][w] = dp2[n][w] for n in range(N): for w in range(T-1): dp2[n][w+1] = max(dp2[n][w+1],dp2[n][w]) ans = 0 for n in range(N): for w in range(T): ans = max(AB[n][1]+dp1[n][w]+dp2[N-n-1][T-1-w],ans) print(ans)
N,T = list(map(int,input().split())) AB = [list(map(int,input().split())) for _ in range(N)] AB.sort(key=lambda x:x[0]) dp = [[0]*T for i in range(N+1)] ans = 0 for n in range(N): for w in range(T): ans = max(ans,dp[n][w]+AB[n][1]) if w-AB[n][0]>=0: dp[n+1][w] = max(dp[n][w],dp[n][w-AB[n][0]]+AB[n][1]) else: dp[n+1][w] = dp[n][w] print(ans)
34
15
910
404
N, T = list(map(int, input().split())) AB = [list(map(int, input().split())) for _ in range(N)] AB.sort(key=lambda x: x[1]) dp1 = [[0] * T for i in range(N + 1)] for n in range(N): for w in range(T): if w - AB[n][0] >= 0: dp1[n + 1][w] = max(dp1[n][w], dp1[n][w - AB[n][0]] + AB[n][1]) else: dp1[n + 1][w] = dp1[n][w] for n in range(N): for w in range(T - 1): dp1[n][w + 1] = max(dp1[n][w + 1], dp1[n][w]) dp2 = [[0] * T for i in range(N + 1)] for n in range(N): for w in range(T): if w - AB[-n - 1][0] >= 0: dp2[n + 1][w] = max(dp2[n][w], dp2[n][w - AB[-n - 1][0]] + AB[-n - 1][1]) else: dp2[n + 1][w] = dp2[n][w] for n in range(N): for w in range(T - 1): dp2[n][w + 1] = max(dp2[n][w + 1], dp2[n][w]) ans = 0 for n in range(N): for w in range(T): ans = max(AB[n][1] + dp1[n][w] + dp2[N - n - 1][T - 1 - w], ans) print(ans)
N, T = list(map(int, input().split())) AB = [list(map(int, input().split())) for _ in range(N)] AB.sort(key=lambda x: x[0]) dp = [[0] * T for i in range(N + 1)] ans = 0 for n in range(N): for w in range(T): ans = max(ans, dp[n][w] + AB[n][1]) if w - AB[n][0] >= 0: dp[n + 1][w] = max(dp[n][w], dp[n][w - AB[n][0]] + AB[n][1]) else: dp[n + 1][w] = dp[n][w] print(ans)
false
55.882353
[ "-AB.sort(key=lambda x: x[1])", "-dp1 = [[0] * T for i in range(N + 1)]", "-for n in range(N):", "- for w in range(T):", "- if w - AB[n][0] >= 0:", "- dp1[n + 1][w] = max(dp1[n][w], dp1[n][w - AB[n][0]] + AB[n][1])", "- else:", "- dp1[n + 1][w] = dp1[n][w]", "-for n in range(N):", "- for w in range(T - 1):", "- dp1[n][w + 1] = max(dp1[n][w + 1], dp1[n][w])", "-dp2 = [[0] * T for i in range(N + 1)]", "-for n in range(N):", "- for w in range(T):", "- if w - AB[-n - 1][0] >= 0:", "- dp2[n + 1][w] = max(dp2[n][w], dp2[n][w - AB[-n - 1][0]] + AB[-n - 1][1])", "- else:", "- dp2[n + 1][w] = dp2[n][w]", "-for n in range(N):", "- for w in range(T - 1):", "- dp2[n][w + 1] = max(dp2[n][w + 1], dp2[n][w])", "+AB.sort(key=lambda x: x[0])", "+dp = [[0] * T for i in range(N + 1)]", "- ans = max(AB[n][1] + dp1[n][w] + dp2[N - n - 1][T - 1 - w], ans)", "+ ans = max(ans, dp[n][w] + AB[n][1])", "+ if w - AB[n][0] >= 0:", "+ dp[n + 1][w] = max(dp[n][w], dp[n][w - AB[n][0]] + AB[n][1])", "+ else:", "+ dp[n + 1][w] = dp[n][w]" ]
false
0.044159
0.081452
0.542154
[ "s770705747", "s799636686" ]
u254871849
p03339
python
s267999805
s812659703
300
138
4,084
3,700
Accepted
Accepted
54
# author: kagemeka # created: 2019-11-07 23:33:56(JST) ## internal modules import sys import collections # import math # import string # import bisect # import re # import itertools # import statistics # import functools # import operator ## external modules # import scipy.special # if use comb function on AtCoder, # import scipy.misc # select scipy.misc.comb (old version) def main(): n = int(sys.stdin.readline().rstrip()) s = sys.stdin.readline().rstrip() opposite = collections.Counter(s) opposite['W'] = 0 minimum = n for i in range(n): if s[i] == 'E': opposite['E'] -= 1 minimum = min(minimum, sum(opposite.values())) if s[i] == 'W': opposite['W'] += 1 print(minimum) if __name__ == "__main__": # execute only if run as a script main()
import sys n = int(sys.stdin.readline().rstrip()) s = sys.stdin.readline().rstrip() def main(): l = 0 r = s.count('E') res = r for i in range(n): cur = s[i] if cur == 'E': r -= 1 res = min(res, l + r) if cur == 'W': l += 1 return res if __name__ == '__main__': ans = main() print(ans)
38
21
930
391
# author: kagemeka # created: 2019-11-07 23:33:56(JST) ## internal modules import sys import collections # import math # import string # import bisect # import re # import itertools # import statistics # import functools # import operator ## external modules # import scipy.special # if use comb function on AtCoder, # import scipy.misc # select scipy.misc.comb (old version) def main(): n = int(sys.stdin.readline().rstrip()) s = sys.stdin.readline().rstrip() opposite = collections.Counter(s) opposite["W"] = 0 minimum = n for i in range(n): if s[i] == "E": opposite["E"] -= 1 minimum = min(minimum, sum(opposite.values())) if s[i] == "W": opposite["W"] += 1 print(minimum) if __name__ == "__main__": # execute only if run as a script main()
import sys n = int(sys.stdin.readline().rstrip()) s = sys.stdin.readline().rstrip() def main(): l = 0 r = s.count("E") res = r for i in range(n): cur = s[i] if cur == "E": r -= 1 res = min(res, l + r) if cur == "W": l += 1 return res if __name__ == "__main__": ans = main() print(ans)
false
44.736842
[ "-# author: kagemeka", "-# created: 2019-11-07 23:33:56(JST)", "-## internal modules", "-import collections", "-# import math", "-# import string", "-# import bisect", "-# import re", "-# import itertools", "-# import statistics", "-# import functools", "-# import operator", "-## external modules", "-# import scipy.special # if use comb function on AtCoder,", "-# import scipy.misc # select scipy.misc.comb (old version)", "+n = int(sys.stdin.readline().rstrip())", "+s = sys.stdin.readline().rstrip()", "+", "+", "- n = int(sys.stdin.readline().rstrip())", "- s = sys.stdin.readline().rstrip()", "- opposite = collections.Counter(s)", "- opposite[\"W\"] = 0", "- minimum = n", "+ l = 0", "+ r = s.count(\"E\")", "+ res = r", "- if s[i] == \"E\":", "- opposite[\"E\"] -= 1", "- minimum = min(minimum, sum(opposite.values()))", "- if s[i] == \"W\":", "- opposite[\"W\"] += 1", "- print(minimum)", "+ cur = s[i]", "+ if cur == \"E\":", "+ r -= 1", "+ res = min(res, l + r)", "+ if cur == \"W\":", "+ l += 1", "+ return res", "- # execute only if run as a script", "- main()", "+ ans = main()", "+ print(ans)" ]
false
0.039957
0.104719
0.381569
[ "s267999805", "s812659703" ]
u133936772
p02647
python
s561331407
s550632826
403
267
171,156
170,828
Accepted
Accepted
33.75
n,k,*l=list(map(int,open(0).read().split())) for _ in range(min(k,99)): s=[0]*(n+1) for i in range(n): s[max(i-l[i],0)]+=1 s[min(i+l[i]+1,n)]-=1 l[0]=min(s[0],n) for i in range(1,n): l[i]=min(l[i-1]+s[i],n) print((*l))
n,k,*l=list(map(int,open(0).read().split())) for _ in range(min(k,41)): s=[0]*(n+1) for i in range(n): s[max(i-l[i],0)]+=1 s[min(i+l[i]+1,n)]-=1 l[0]=min(s[0],n) for i in range(1,n): l[i]=min(l[i-1]+s[i],n) print((*l))
10
10
239
239
n, k, *l = list(map(int, open(0).read().split())) for _ in range(min(k, 99)): s = [0] * (n + 1) for i in range(n): s[max(i - l[i], 0)] += 1 s[min(i + l[i] + 1, n)] -= 1 l[0] = min(s[0], n) for i in range(1, n): l[i] = min(l[i - 1] + s[i], n) print((*l))
n, k, *l = list(map(int, open(0).read().split())) for _ in range(min(k, 41)): s = [0] * (n + 1) for i in range(n): s[max(i - l[i], 0)] += 1 s[min(i + l[i] + 1, n)] -= 1 l[0] = min(s[0], n) for i in range(1, n): l[i] = min(l[i - 1] + s[i], n) print((*l))
false
0
[ "-for _ in range(min(k, 99)):", "+for _ in range(min(k, 41)):" ]
false
0.035706
0.06704
0.5326
[ "s561331407", "s550632826" ]
u961595602
p03425
python
s666021022
s294795013
202
100
3,060
3,064
Accepted
Accepted
50.5
from itertools import combinations N = int(eval(input())) target = 'MARCH' first = [0 for _ in range(5)] for _ in range(N): s = eval(input()) if s[0] in target: first[target.find(s[0])] += 1 res = 0 for c in combinations(first, 3): res += c[0]*c[1]*c[2] print(res)
from itertools import combinations from sys import stdin ns = lambda: stdin.readline() ni = lambda: int(stdin.readline()) na = lambda: list(map(int, stdin.readline().split())) N = ni() target = 'MARCH' first = [0 for _ in range(5)] for _ in range(N): s = ns() if s[0] in target: first[target.find(s[0])] += 1 res = 0 for c in combinations(first, 3): res += c[0]*c[1]*c[2] print(res)
16
22
296
434
from itertools import combinations N = int(eval(input())) target = "MARCH" first = [0 for _ in range(5)] for _ in range(N): s = eval(input()) if s[0] in target: first[target.find(s[0])] += 1 res = 0 for c in combinations(first, 3): res += c[0] * c[1] * c[2] print(res)
from itertools import combinations from sys import stdin ns = lambda: stdin.readline() ni = lambda: int(stdin.readline()) na = lambda: list(map(int, stdin.readline().split())) N = ni() target = "MARCH" first = [0 for _ in range(5)] for _ in range(N): s = ns() if s[0] in target: first[target.find(s[0])] += 1 res = 0 for c in combinations(first, 3): res += c[0] * c[1] * c[2] print(res)
false
27.272727
[ "+from sys import stdin", "-N = int(eval(input()))", "+ns = lambda: stdin.readline()", "+ni = lambda: int(stdin.readline())", "+na = lambda: list(map(int, stdin.readline().split()))", "+N = ni()", "- s = eval(input())", "+ s = ns()" ]
false
0.114448
0.044244
2.586732
[ "s666021022", "s294795013" ]
u968404618
p03564
python
s155224430
s434718491
26
22
9,164
9,044
Accepted
Accepted
15.38
n = int(eval(input())) k = int(eval(input())) cnt = 1 for _ in range(n): cnt = min(cnt*2, cnt+k) print(cnt)
n = int(eval(input())) k = int(eval(input())) cnt = 1 for _ in range(n): if cnt <= k: cnt *= 2 else: cnt += k print(cnt)
7
10
106
142
n = int(eval(input())) k = int(eval(input())) cnt = 1 for _ in range(n): cnt = min(cnt * 2, cnt + k) print(cnt)
n = int(eval(input())) k = int(eval(input())) cnt = 1 for _ in range(n): if cnt <= k: cnt *= 2 else: cnt += k print(cnt)
false
30
[ "- cnt = min(cnt * 2, cnt + k)", "+ if cnt <= k:", "+ cnt *= 2", "+ else:", "+ cnt += k" ]
false
0.044924
0.044313
1.013794
[ "s155224430", "s434718491" ]
u847165882
p02989
python
s056169684
s995661945
105
79
14,428
14,396
Accepted
Accepted
24.76
N=int(eval(input())) D=[int(s) for s in input().split()] D=sorted(D) sum=[] count=0 for i in reversed(list(range(len(D)))): sum.append(D.pop(i)) if len(sum) == len(D): Ans=len(sum) break for i in range(D[Ans-1],sum[Ans-1],1): count+=1 print(count)
N=int(eval(input())) d=[int(s) for s in input().split(" ")] d.sort() K=d[(N//2)]-d[(N//2)-1] print(K)
14
6
277
101
N = int(eval(input())) D = [int(s) for s in input().split()] D = sorted(D) sum = [] count = 0 for i in reversed(list(range(len(D)))): sum.append(D.pop(i)) if len(sum) == len(D): Ans = len(sum) break for i in range(D[Ans - 1], sum[Ans - 1], 1): count += 1 print(count)
N = int(eval(input())) d = [int(s) for s in input().split(" ")] d.sort() K = d[(N // 2)] - d[(N // 2) - 1] print(K)
false
57.142857
[ "-D = [int(s) for s in input().split()]", "-D = sorted(D)", "-sum = []", "-count = 0", "-for i in reversed(list(range(len(D)))):", "- sum.append(D.pop(i))", "- if len(sum) == len(D):", "- Ans = len(sum)", "- break", "-for i in range(D[Ans - 1], sum[Ans - 1], 1):", "- count += 1", "-print(count)", "+d = [int(s) for s in input().split(\" \")]", "+d.sort()", "+K = d[(N // 2)] - d[(N // 2) - 1]", "+print(K)" ]
false
0.036811
0.035065
1.049785
[ "s056169684", "s995661945" ]
u247211039
p02719
python
s943047225
s620017424
30
26
8,988
9,132
Accepted
Accepted
13.33
N,K=list(map(int, input().split())) x=N%K if x ==0: print((0)) elif abs(x - K) > x: print(x) else: print((abs(x - K)))
N,K=list(map(int,input().split())) a=N//K ans=min(abs(N-a*K), abs(N-(a+1)*K)) print(ans)
10
6
131
89
N, K = list(map(int, input().split())) x = N % K if x == 0: print((0)) elif abs(x - K) > x: print(x) else: print((abs(x - K)))
N, K = list(map(int, input().split())) a = N // K ans = min(abs(N - a * K), abs(N - (a + 1) * K)) print(ans)
false
40
[ "-x = N % K", "-if x == 0:", "- print((0))", "-elif abs(x - K) > x:", "- print(x)", "-else:", "- print((abs(x - K)))", "+a = N // K", "+ans = min(abs(N - a * K), abs(N - (a + 1) * K))", "+print(ans)" ]
false
0.03953
0.034925
1.131873
[ "s943047225", "s620017424" ]
u287500079
p03361
python
s566701039
s108577136
334
297
62,444
63,208
Accepted
Accepted
11.08
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 STR(): return eval(input()) 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 = sys.maxsize mod = 10 ** 9 + 7 h,w = MAP() s = [STR() for _ in range(h)] for i in range(h): for j in range(w): if s[i][j] == '#': flag = [False for _ in range(4)] if i > 0 and s[i-1][j] == '#': flag[0] = True if i < h - 1 and s[i+1][j] == '#': flag[1] = True if j > 0 and s[i][j-1] == '#': flag[2] = True if j < w - 1 and s[i][j+1] == '#': flag[3] = True if sum(flag) == 0: print('No') exit() print('Yes')
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 STR(): return eval(input()) 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 = sys.maxsize mod = 10 ** 9 + 7 h,w = MAP() s = [STR() for _ in range(h)] ii = [-1, 1, 0, 0] jj = [0, 0, -1, 1] for i in range(h): for j in range(w): if s[i][j] == '#': flag = [False for _ in range(4)] for k in range(4): iii = i + ii[k] jjj = j + jj[k] if 0 <= iii < h and 0 <= jjj < w and s[iii][jjj] == '#': flag[k] = True if not sum(flag): print('No') exit() print('Yes')
37
36
1,317
1,253
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 STR(): return eval(input()) 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 = sys.maxsize mod = 10**9 + 7 h, w = MAP() s = [STR() for _ in range(h)] for i in range(h): for j in range(w): if s[i][j] == "#": flag = [False for _ in range(4)] if i > 0 and s[i - 1][j] == "#": flag[0] = True if i < h - 1 and s[i + 1][j] == "#": flag[1] = True if j > 0 and s[i][j - 1] == "#": flag[2] = True if j < w - 1 and s[i][j + 1] == "#": flag[3] = True if sum(flag) == 0: print("No") exit() print("Yes")
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 STR(): return eval(input()) 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 = sys.maxsize mod = 10**9 + 7 h, w = MAP() s = [STR() for _ in range(h)] ii = [-1, 1, 0, 0] jj = [0, 0, -1, 1] for i in range(h): for j in range(w): if s[i][j] == "#": flag = [False for _ in range(4)] for k in range(4): iii = i + ii[k] jjj = j + jj[k] if 0 <= iii < h and 0 <= jjj < w and s[iii][jjj] == "#": flag[k] = True if not sum(flag): print("No") exit() print("Yes")
false
2.702703
[ "+ii = [-1, 1, 0, 0]", "+jj = [0, 0, -1, 1]", "- if i > 0 and s[i - 1][j] == \"#\":", "- flag[0] = True", "- if i < h - 1 and s[i + 1][j] == \"#\":", "- flag[1] = True", "- if j > 0 and s[i][j - 1] == \"#\":", "- flag[2] = True", "- if j < w - 1 and s[i][j + 1] == \"#\":", "- flag[3] = True", "- if sum(flag) == 0:", "+ for k in range(4):", "+ iii = i + ii[k]", "+ jjj = j + jj[k]", "+ if 0 <= iii < h and 0 <= jjj < w and s[iii][jjj] == \"#\":", "+ flag[k] = True", "+ if not sum(flag):" ]
false
0.047619
0.049321
0.965477
[ "s566701039", "s108577136" ]
u512007680
p03295
python
s872093979
s232781619
381
325
20,388
5,984
Accepted
Accepted
14.7
N,M = list(map(int,input().split())) info = [] maxa = [0] * (N+1) for i in range(M): a,b = list(map(int,input().split())) info.append([a,b]) if maxa[b] < a: maxa[b] = a ok = 0 count = 0 for j in range(1,N+1): if ok < maxa[j]: count += 1 ok = j-1 print(count)
N,M = list(map(int,input().split())) maxa = [0] * (N+1) for i in range(M): a,b = list(map(int,input().split())) if maxa[b] < a: maxa[b] = a ok = 0 count = 0 for j in range(1,N+1): if ok < maxa[j]: count += 1 ok = j-1 print(count)
19
17
309
274
N, M = list(map(int, input().split())) info = [] maxa = [0] * (N + 1) for i in range(M): a, b = list(map(int, input().split())) info.append([a, b]) if maxa[b] < a: maxa[b] = a ok = 0 count = 0 for j in range(1, N + 1): if ok < maxa[j]: count += 1 ok = j - 1 print(count)
N, M = list(map(int, input().split())) maxa = [0] * (N + 1) for i in range(M): a, b = list(map(int, input().split())) if maxa[b] < a: maxa[b] = a ok = 0 count = 0 for j in range(1, N + 1): if ok < maxa[j]: count += 1 ok = j - 1 print(count)
false
10.526316
[ "-info = []", "- info.append([a, b])" ]
false
0.037113
0.045812
0.810104
[ "s872093979", "s232781619" ]
u284854859
p03821
python
s305968234
s627517920
384
290
15,020
51,292
Accepted
Accepted
24.48
n = int(eval(input())) a = [] b = [] for i in range(n): x,y = list(map(int,input().split())) a.append(x) b.append(y) res = 0 for i in range(n): a[n-1-i] += res c = a[n-1-i]%b[n-1-i] if c != 0: res += b[n-1-i]-c print(res)
import sys input = sys.stdin.readline n = int(eval(input())) a = [] b = [] for i in range(n): aa,bb = list(map(int,input().split())) a.append(aa) b.append(bb) s = 0 res = 0 for i in range(n-1,-1,-1): a[i] += res if a[i]%b[i] == 0: continue res += b[i]-(a[i]%b[i]) print(res)
17
24
261
328
n = int(eval(input())) a = [] b = [] for i in range(n): x, y = list(map(int, input().split())) a.append(x) b.append(y) res = 0 for i in range(n): a[n - 1 - i] += res c = a[n - 1 - i] % b[n - 1 - i] if c != 0: res += b[n - 1 - i] - c print(res)
import sys input = sys.stdin.readline n = int(eval(input())) a = [] b = [] for i in range(n): aa, bb = list(map(int, input().split())) a.append(aa) b.append(bb) s = 0 res = 0 for i in range(n - 1, -1, -1): a[i] += res if a[i] % b[i] == 0: continue res += b[i] - (a[i] % b[i]) print(res)
false
29.166667
[ "+import sys", "+", "+input = sys.stdin.readline", "- x, y = list(map(int, input().split()))", "- a.append(x)", "- b.append(y)", "+ aa, bb = list(map(int, input().split()))", "+ a.append(aa)", "+ b.append(bb)", "+s = 0", "-for i in range(n):", "- a[n - 1 - i] += res", "- c = a[n - 1 - i] % b[n - 1 - i]", "- if c != 0:", "- res += b[n - 1 - i] - c", "+for i in range(n - 1, -1, -1):", "+ a[i] += res", "+ if a[i] % b[i] == 0:", "+ continue", "+ res += b[i] - (a[i] % b[i])" ]
false
0.035921
0.032843
1.093704
[ "s305968234", "s627517920" ]
u088552457
p03944
python
s905726404
s513773559
173
98
3,188
3,188
Accepted
Accepted
43.35
w, h, n = list(map(int, input().split())) rw = w rh = h points = [] for x in range(w): rows = [] for y in range(h): rows.append(0) points.append(rows) for i in range(n): x, y, a = list(map(int, input().split())) if a == 1: for row_index, row in enumerate(points): for col_index, col in enumerate(row): if row_index < x: points[row_index][col_index] = 1 if a == 2: for row_index, row in enumerate(points): for col_index, col in enumerate(row): if row_index >= x: points[row_index][col_index] = 1 if a == 3: for row_index, row in enumerate(points): for col_index, col in enumerate(row): if col_index < y: points[row_index][col_index] = 1 if a == 4: for row_index, row in enumerate(points): for col_index, col in enumerate(row): if col_index >= y: points[row_index][col_index] = 1 count = 0 for row_index, row in enumerate(points): for col_index, col in enumerate(row): if points[row_index][col_index] == 0: count += 1 print(count)
def main(): w, h, n = input_list() points = [] for x in range(w): row = [True]*h points.append(row) for _ in range(n): x, y, a = input_list() if a == 1: for px, row in enumerate(points): for py, v in enumerate(row): if px+1 <= x: points[px][py] = False if a == 2: for px, row in enumerate(points): for py, v in enumerate(row): if px+1 > x: points[px][py] = False if a == 3: for px, row in enumerate(points): for py, v in enumerate(row): if py+1 <= y: points[px][py] = False if a == 4: for px, row in enumerate(points): for py, v in enumerate(row): if py+1 > y: points[px][py] = False ans = 0 for p in points: ans += p.count(True) print(ans) def input_list(): return list(map(int, input().split())) import math main()
40
40
1,114
953
w, h, n = list(map(int, input().split())) rw = w rh = h points = [] for x in range(w): rows = [] for y in range(h): rows.append(0) points.append(rows) for i in range(n): x, y, a = list(map(int, input().split())) if a == 1: for row_index, row in enumerate(points): for col_index, col in enumerate(row): if row_index < x: points[row_index][col_index] = 1 if a == 2: for row_index, row in enumerate(points): for col_index, col in enumerate(row): if row_index >= x: points[row_index][col_index] = 1 if a == 3: for row_index, row in enumerate(points): for col_index, col in enumerate(row): if col_index < y: points[row_index][col_index] = 1 if a == 4: for row_index, row in enumerate(points): for col_index, col in enumerate(row): if col_index >= y: points[row_index][col_index] = 1 count = 0 for row_index, row in enumerate(points): for col_index, col in enumerate(row): if points[row_index][col_index] == 0: count += 1 print(count)
def main(): w, h, n = input_list() points = [] for x in range(w): row = [True] * h points.append(row) for _ in range(n): x, y, a = input_list() if a == 1: for px, row in enumerate(points): for py, v in enumerate(row): if px + 1 <= x: points[px][py] = False if a == 2: for px, row in enumerate(points): for py, v in enumerate(row): if px + 1 > x: points[px][py] = False if a == 3: for px, row in enumerate(points): for py, v in enumerate(row): if py + 1 <= y: points[px][py] = False if a == 4: for px, row in enumerate(points): for py, v in enumerate(row): if py + 1 > y: points[px][py] = False ans = 0 for p in points: ans += p.count(True) print(ans) def input_list(): return list(map(int, input().split())) import math main()
false
0
[ "-w, h, n = list(map(int, input().split()))", "-rw = w", "-rh = h", "-points = []", "-for x in range(w):", "- rows = []", "- for y in range(h):", "- rows.append(0)", "- points.append(rows)", "-for i in range(n):", "- x, y, a = list(map(int, input().split()))", "- if a == 1:", "- for row_index, row in enumerate(points):", "- for col_index, col in enumerate(row):", "- if row_index < x:", "- points[row_index][col_index] = 1", "- if a == 2:", "- for row_index, row in enumerate(points):", "- for col_index, col in enumerate(row):", "- if row_index >= x:", "- points[row_index][col_index] = 1", "- if a == 3:", "- for row_index, row in enumerate(points):", "- for col_index, col in enumerate(row):", "- if col_index < y:", "- points[row_index][col_index] = 1", "- if a == 4:", "- for row_index, row in enumerate(points):", "- for col_index, col in enumerate(row):", "- if col_index >= y:", "- points[row_index][col_index] = 1", "-count = 0", "-for row_index, row in enumerate(points):", "- for col_index, col in enumerate(row):", "- if points[row_index][col_index] == 0:", "- count += 1", "-print(count)", "+def main():", "+ w, h, n = input_list()", "+ points = []", "+ for x in range(w):", "+ row = [True] * h", "+ points.append(row)", "+ for _ in range(n):", "+ x, y, a = input_list()", "+ if a == 1:", "+ for px, row in enumerate(points):", "+ for py, v in enumerate(row):", "+ if px + 1 <= x:", "+ points[px][py] = False", "+ if a == 2:", "+ for px, row in enumerate(points):", "+ for py, v in enumerate(row):", "+ if px + 1 > x:", "+ points[px][py] = False", "+ if a == 3:", "+ for px, row in enumerate(points):", "+ for py, v in enumerate(row):", "+ if py + 1 <= y:", "+ points[px][py] = False", "+ if a == 4:", "+ for px, row in enumerate(points):", "+ for py, v in enumerate(row):", "+ if py + 1 > y:", "+ points[px][py] = False", "+ ans = 0", "+ for p in points:", "+ ans += p.count(True)", "+ print(ans)", "+", "+", "+def input_list():", "+ return list(map(int, input().split()))", "+", "+", "+import math", "+", "+main()" ]
false
0.047037
0.069854
0.673366
[ "s905726404", "s513773559" ]
u535803878
p03277
python
s121222869
s605815309
1,029
368
121,856
128,588
Accepted
Accepted
64.24
import sys input = lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(max(1000, 10**9)) write = lambda x: sys.stdout.write(x+"\n") def init(bit, values): for i,v in enumerate(values): update(bit,i,v) #A1 ~ Aiまでの和 O(logN) def query(bit,i): res_sum = 0 while i > 0: res_sum += bit[i] i -= i&(-i) return res_sum #Ai += x O(logN) def update(bit,i,x): while i <= len(bit)-1: bit[i] += x i += i&(-i) return n = int(eval(input())) a = list(map(int, input().split())) from collections import Counter def sub(x): cumsum = [None] * n cumsum[0] = 1 if a[0]>=x else -1 for i in range(1,n): cumsum[i] = cumsum[i-1] + (1 if a[i]>=x else -1) ### BIT #A1 ... AnのBIT(1-indexed) bit = [0]*(2*n+2) update(bit, n+1, 1) ans = 0 for v in cumsum: ans += query(bit, v+n+1) update(bit, n+v+1, 1) return ans l = 0 r = 10**9+1 tmp = (n+1)*n//2 thre = tmp//2 + tmp%2 while l<r-1: m = (l+r)//2 if sub(m)>=thre: l = m else: r = m print(l)
import sys input = lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(max(1000, 10**9)) write = lambda x: sys.stdout.write(x+"\n") n = int(eval(input())) a = list(map(int, input().split())) from collections import Counter def sub(x): l = [1 if item>=x else -1 for item in a] count = [0] * (2*n+2) count[n] = 1 i = n cumsum = 1 ans = 0 for item in l: i += item if item==1: cumsum += count[i] else: cumsum -= count[i+1] ans += cumsum count[i] += 1 cumsum += 1 return ans l = 0 r = 10**9+1 tmp = (n+1)*n//2 thre = tmp//2 + tmp%2 while l<r-1: m = (l+r)//2 if sub(m)>=thre: l = m else: r = m print(l)
56
39
1,132
773
import sys input = lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(max(1000, 10**9)) write = lambda x: sys.stdout.write(x + "\n") def init(bit, values): for i, v in enumerate(values): update(bit, i, v) # A1 ~ Aiまでの和 O(logN) def query(bit, i): res_sum = 0 while i > 0: res_sum += bit[i] i -= i & (-i) return res_sum # Ai += x O(logN) def update(bit, i, x): while i <= len(bit) - 1: bit[i] += x i += i & (-i) return n = int(eval(input())) a = list(map(int, input().split())) from collections import Counter def sub(x): cumsum = [None] * n cumsum[0] = 1 if a[0] >= x else -1 for i in range(1, n): cumsum[i] = cumsum[i - 1] + (1 if a[i] >= x else -1) ### BIT # A1 ... AnのBIT(1-indexed) bit = [0] * (2 * n + 2) update(bit, n + 1, 1) ans = 0 for v in cumsum: ans += query(bit, v + n + 1) update(bit, n + v + 1, 1) return ans l = 0 r = 10**9 + 1 tmp = (n + 1) * n // 2 thre = tmp // 2 + tmp % 2 while l < r - 1: m = (l + r) // 2 if sub(m) >= thre: l = m else: r = m print(l)
import sys input = lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(max(1000, 10**9)) write = lambda x: sys.stdout.write(x + "\n") n = int(eval(input())) a = list(map(int, input().split())) from collections import Counter def sub(x): l = [1 if item >= x else -1 for item in a] count = [0] * (2 * n + 2) count[n] = 1 i = n cumsum = 1 ans = 0 for item in l: i += item if item == 1: cumsum += count[i] else: cumsum -= count[i + 1] ans += cumsum count[i] += 1 cumsum += 1 return ans l = 0 r = 10**9 + 1 tmp = (n + 1) * n // 2 thre = tmp // 2 + tmp % 2 while l < r - 1: m = (l + r) // 2 if sub(m) >= thre: l = m else: r = m print(l)
false
30.357143
[ "-", "-", "-def init(bit, values):", "- for i, v in enumerate(values):", "- update(bit, i, v)", "-", "-", "-# A1 ~ Aiまでの和 O(logN)", "-def query(bit, i):", "- res_sum = 0", "- while i > 0:", "- res_sum += bit[i]", "- i -= i & (-i)", "- return res_sum", "-", "-", "-# Ai += x O(logN)", "-def update(bit, i, x):", "- while i <= len(bit) - 1:", "- bit[i] += x", "- i += i & (-i)", "- return", "-", "-", "- cumsum = [None] * n", "- cumsum[0] = 1 if a[0] >= x else -1", "- for i in range(1, n):", "- cumsum[i] = cumsum[i - 1] + (1 if a[i] >= x else -1)", "- ### BIT", "- # A1 ... AnのBIT(1-indexed)", "- bit = [0] * (2 * n + 2)", "- update(bit, n + 1, 1)", "+ l = [1 if item >= x else -1 for item in a]", "+ count = [0] * (2 * n + 2)", "+ count[n] = 1", "+ i = n", "+ cumsum = 1", "- for v in cumsum:", "- ans += query(bit, v + n + 1)", "- update(bit, n + v + 1, 1)", "+ for item in l:", "+ i += item", "+ if item == 1:", "+ cumsum += count[i]", "+ else:", "+ cumsum -= count[i + 1]", "+ ans += cumsum", "+ count[i] += 1", "+ cumsum += 1" ]
false
0.034854
0.039551
0.881255
[ "s121222869", "s605815309" ]
u600402037
p02718
python
s833458746
s577666062
1,712
109
21,408
27,220
Accepted
Accepted
93.63
import sys import numpy as np sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) N, M = lr() A = np.array(lr(), np.int32) total = A.sum() A *= 4*M count = (A >= total).sum() bl = count >= M print(('Yes' if bl else 'No'))
# coding: utf-8 import sys import numpy as np sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) N, M = lr() A = np.array(lr()) total = A.sum() A *= 4 * M A = A[A>=total] bl = len(A) >= M print(('Yes' if bl else 'No'))
14
15
291
290
import sys import numpy as np sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) N, M = lr() A = np.array(lr(), np.int32) total = A.sum() A *= 4 * M count = (A >= total).sum() bl = count >= M print(("Yes" if bl else "No"))
# coding: utf-8 import sys import numpy as np sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) N, M = lr() A = np.array(lr()) total = A.sum() A *= 4 * M A = A[A >= total] bl = len(A) >= M print(("Yes" if bl else "No"))
false
6.666667
[ "+# coding: utf-8", "-A = np.array(lr(), np.int32)", "+A = np.array(lr())", "-count = (A >= total).sum()", "-bl = count >= M", "+A = A[A >= total]", "+bl = len(A) >= M" ]
false
0.362861
0.180559
2.009654
[ "s833458746", "s577666062" ]
u905203728
p02971
python
s957297699
s516983378
613
533
14,740
14,112
Accepted
Accepted
13.05
A=[int(eval(input())) for i in range(int(eval(input())))] one=sorted(A)[-1] two=sorted(A)[-2] for i in A: print((one if i!=one else two))
A=[int(eval(input())) for i in range(int(eval(input())))] B=sorted(A) one=B[-1] two=B[-2] for i in A:print((one if i!=one else two))
7
5
135
122
A = [int(eval(input())) for i in range(int(eval(input())))] one = sorted(A)[-1] two = sorted(A)[-2] for i in A: print((one if i != one else two))
A = [int(eval(input())) for i in range(int(eval(input())))] B = sorted(A) one = B[-1] two = B[-2] for i in A: print((one if i != one else two))
false
28.571429
[ "-one = sorted(A)[-1]", "-two = sorted(A)[-2]", "+B = sorted(A)", "+one = B[-1]", "+two = B[-2]" ]
false
0.109485
0.0854
1.282021
[ "s957297699", "s516983378" ]
u620868411
p03633
python
s371735107
s018740925
45
17
5,304
2,940
Accepted
Accepted
62.22
from fractions import gcd def lcm(a,b): return a*b//gcd(a,b) n = int(eval(input())) res = 1 for i in range(n): t = int(eval(input())) res = lcm(res, t) print(res)
# -*- coding: utf-8 -*- n = int(eval(input())) def gcd(a, b): if b==0: return a return gcd(b, a%b) def lcm(a,b): return a//gcd(a,b)*b ans = 1 for _ in range(n): t = int(eval(input())) ans = lcm(ans, t) print(ans)
9
18
168
251
from fractions import gcd def lcm(a, b): return a * b // gcd(a, b) n = int(eval(input())) res = 1 for i in range(n): t = int(eval(input())) res = lcm(res, t) print(res)
# -*- coding: utf-8 -*- n = int(eval(input())) def gcd(a, b): if b == 0: return a return gcd(b, a % b) def lcm(a, b): return a // gcd(a, b) * b ans = 1 for _ in range(n): t = int(eval(input())) ans = lcm(ans, t) print(ans)
false
50
[ "-from fractions import gcd", "+# -*- coding: utf-8 -*-", "+n = int(eval(input()))", "+", "+", "+def gcd(a, b):", "+ if b == 0:", "+ return a", "+ return gcd(b, a % b)", "- return a * b // gcd(a, b)", "+ return a // gcd(a, b) * b", "-n = int(eval(input()))", "-res = 1", "-for i in range(n):", "+ans = 1", "+for _ in range(n):", "- res = lcm(res, t)", "-print(res)", "+ ans = lcm(ans, t)", "+print(ans)" ]
false
0.179027
0.1296
1.381383
[ "s371735107", "s018740925" ]
u419330815
p03160
python
s420759283
s516095478
148
135
13,924
13,980
Accepted
Accepted
8.78
n = int(eval(input())) h = list(map(int, input().split())) dp = [10 ** 9] * n dp[0] = 0 dp[1] = abs(h[1] - h[0]) for i in range(2, n): h1 = dp[i - 1] + abs(h[i] - h[i - 1]) dp[i] = h1 if h1 < dp[i] else dp[i] h2 = dp[i - 2] + abs(h[i] - h[i - 2]) dp[i] = h2 if h2 < dp[i] else dp[i] print((dp[-1]))
n = int(eval(input())) h = list(map(int, input().split())) dp = [0] * n dp[0] = 0 dp[1] = abs(h[1] - h[0]) for i in range(2, n): h1 = dp[i - 1] + abs(h[i] - h[i - 1]) dp[i] = h1 h2 = dp[i - 2] + abs(h[i] - h[i - 2]) dp[i] = h2 if h2 < dp[i] else dp[i] print((dp[-1]))
16
16
326
295
n = int(eval(input())) h = list(map(int, input().split())) dp = [10**9] * n dp[0] = 0 dp[1] = abs(h[1] - h[0]) for i in range(2, n): h1 = dp[i - 1] + abs(h[i] - h[i - 1]) dp[i] = h1 if h1 < dp[i] else dp[i] h2 = dp[i - 2] + abs(h[i] - h[i - 2]) dp[i] = h2 if h2 < dp[i] else dp[i] print((dp[-1]))
n = int(eval(input())) h = list(map(int, input().split())) dp = [0] * n dp[0] = 0 dp[1] = abs(h[1] - h[0]) for i in range(2, n): h1 = dp[i - 1] + abs(h[i] - h[i - 1]) dp[i] = h1 h2 = dp[i - 2] + abs(h[i] - h[i - 2]) dp[i] = h2 if h2 < dp[i] else dp[i] print((dp[-1]))
false
0
[ "-dp = [10**9] * n", "+dp = [0] * n", "- dp[i] = h1 if h1 < dp[i] else dp[i]", "+ dp[i] = h1" ]
false
0.048978
0.04943
0.99084
[ "s420759283", "s516095478" ]
u909514237
p02574
python
s094863999
s336001977
394
353
194,212
194,512
Accepted
Accepted
10.41
import math N = int(eval(input())) A = list(map(int, input().split())) m = max(A) c = [0] * (m+1) for i in A: c[i] += 1 pairwise = True for i in range(2,m+1,1): cnt = 0 for j in range(i,m+1,i): cnt += c[j] if cnt > 1: pairwise = False if pairwise: print("pairwise coprime") exit() g = 0 for i in range(N): g = math.gcd(g,A[i]) if g == 1: print("setwise coprime") exit() print("not coprime")
import math N = int(eval(input())) a = list(map(int,input().split())) m = max(a) c = [0] * (m+1) for i in a: c[i] += 1 pairwise = True for i in range(2, m+1, 1): cnt = 0 for j in range(i, m+1, i): cnt += c[j] if cnt > 1: pairwise = False break if pairwise: print("pairwise coprime") exit() g = 0 for i in range(N): g = math.gcd(g, a[i]) if g == 1: print("setwise coprime") exit() print("not coprime")
27
30
439
464
import math N = int(eval(input())) A = list(map(int, input().split())) m = max(A) c = [0] * (m + 1) for i in A: c[i] += 1 pairwise = True for i in range(2, m + 1, 1): cnt = 0 for j in range(i, m + 1, i): cnt += c[j] if cnt > 1: pairwise = False if pairwise: print("pairwise coprime") exit() g = 0 for i in range(N): g = math.gcd(g, A[i]) if g == 1: print("setwise coprime") exit() print("not coprime")
import math N = int(eval(input())) a = list(map(int, input().split())) m = max(a) c = [0] * (m + 1) for i in a: c[i] += 1 pairwise = True for i in range(2, m + 1, 1): cnt = 0 for j in range(i, m + 1, i): cnt += c[j] if cnt > 1: pairwise = False break if pairwise: print("pairwise coprime") exit() g = 0 for i in range(N): g = math.gcd(g, a[i]) if g == 1: print("setwise coprime") exit() print("not coprime")
false
10
[ "-A = list(map(int, input().split()))", "-m = max(A)", "+a = list(map(int, input().split()))", "+m = max(a)", "-for i in A:", "+for i in a:", "- if cnt > 1:", "- pairwise = False", "+ if cnt > 1:", "+ pairwise = False", "+ break", "- g = math.gcd(g, A[i])", "+ g = math.gcd(g, a[i])" ]
false
0.046054
0.045884
1.003697
[ "s094863999", "s336001977" ]
u790710233
p03497
python
s057518268
s138726512
209
138
39,352
32,564
Accepted
Accepted
33.97
from collections import Counter n, k = list(map(int, input().split())) *a, = list(map(int, input().split())) c = Counter(a) kv = sorted(list(c.items()), key=lambda x: x[1], reverse=True) if n <= k: print((0)) else: ls = c.most_common(k) ans = n for k, v in ls: ans -= v print(ans)
from collections import Counter n, k = list(map(int, input().split())) *a, = list(map(int, input().split())) c = Counter(a) if n <= k: print((0)) else: ls = c.most_common(k) ans = n for k, v in ls: ans -= v print(ans)
16
14
306
246
from collections import Counter n, k = list(map(int, input().split())) (*a,) = list(map(int, input().split())) c = Counter(a) kv = sorted(list(c.items()), key=lambda x: x[1], reverse=True) if n <= k: print((0)) else: ls = c.most_common(k) ans = n for k, v in ls: ans -= v print(ans)
from collections import Counter n, k = list(map(int, input().split())) (*a,) = list(map(int, input().split())) c = Counter(a) if n <= k: print((0)) else: ls = c.most_common(k) ans = n for k, v in ls: ans -= v print(ans)
false
12.5
[ "-kv = sorted(list(c.items()), key=lambda x: x[1], reverse=True)" ]
false
0.032176
0.036513
0.881212
[ "s057518268", "s138726512" ]
u997521090
p03704
python
s386161403
s737390053
13
12
2,568
2,568
Accepted
Accepted
7.69
def f(d,x,y):n=int("9"*x+"0"*y);return d==0 if x<1 else sum(f(d-i*n,x-2,y+1)*(10-abs(i)-(y<1))for i in range(-9,10)if abs(d-i*n)<n) D=eval(input());print(sum(f(D,i,0)*(10-i%2*9)for i in range(1,21)))
def f(d,x,y):n=int("9"*x+"0"*y);return d==0 if x<1 else sum(f(d-i*n,x-2,y+1)*(10-abs(i)-(y<1))for i in [d/n,d/n+1]if -10<i<10) D=eval(input());print(sum(f(D,i,0)*(10-i%2*9)for i in range(1,21)))
2
2
194
188
def f(d, x, y): n = int("9" * x + "0" * y) return ( d == 0 if x < 1 else sum( f(d - i * n, x - 2, y + 1) * (10 - abs(i) - (y < 1)) for i in range(-9, 10) if abs(d - i * n) < n ) ) D = eval(input()) print(sum(f(D, i, 0) * (10 - i % 2 * 9) for i in range(1, 21)))
def f(d, x, y): n = int("9" * x + "0" * y) return ( d == 0 if x < 1 else sum( f(d - i * n, x - 2, y + 1) * (10 - abs(i) - (y < 1)) for i in [d / n, d / n + 1] if -10 < i < 10 ) ) D = eval(input()) print(sum(f(D, i, 0) * (10 - i % 2 * 9) for i in range(1, 21)))
false
0
[ "- for i in range(-9, 10)", "- if abs(d - i * n) < n", "+ for i in [d / n, d / n + 1]", "+ if -10 < i < 10" ]
false
0.088513
0.046266
1.913124
[ "s386161403", "s737390053" ]
u805403870
p03835
python
s864380071
s057172327
1,519
18
3,064
2,940
Accepted
Accepted
98.82
# 蟻本1-6-1例題相当 # 今回も、x、yを確定した際、zは一意に決まるか値が存在しないかのいずれかであることに着目する。 # よって2重のfor文で回してみる # 最大で2500^2≒600万となる # 最後に、x,yの取りうる範囲を考慮する k, s = list(map(int,input().split())) xmin = (s - 2 * k) if (s - 2 * k) > 0 else 0 xmax = k if k < s else s count = 0 for x in range(xmin, xmax+1): ymin = (s - k - x) if (s - k - x) > 0 else 0 ymax = k if k < s - x else s - x for y in range(ymin, ymax+1): if 0 <= s-x-y and s-x-y <= k: count += 1 print(count)
# 蟻本1-6-1例題相当 # 今回は、xのみ確定した際、y,zの取りうる値の組の数を求める。 # よって1重のfor文で回してみる # 最大で2500となる # 今回は、xの取りうる範囲を考慮しない k, s = list(map(int,input().split())) count = 0 for x in range(0, k+1): if 0 <= s-x and s-x <= k: #(y,z) = (0, s-x), ... ,(s-x, 0) count += s-x+1 elif k <= s-x and s-x <= 2*k: #(y,z) = (s-x-k, k), ... ,(k, s-x-k) count += 2*k-(s-x)+1 print(count)
17
14
463
367
# 蟻本1-6-1例題相当 # 今回も、x、yを確定した際、zは一意に決まるか値が存在しないかのいずれかであることに着目する。 # よって2重のfor文で回してみる # 最大で2500^2≒600万となる # 最後に、x,yの取りうる範囲を考慮する k, s = list(map(int, input().split())) xmin = (s - 2 * k) if (s - 2 * k) > 0 else 0 xmax = k if k < s else s count = 0 for x in range(xmin, xmax + 1): ymin = (s - k - x) if (s - k - x) > 0 else 0 ymax = k if k < s - x else s - x for y in range(ymin, ymax + 1): if 0 <= s - x - y and s - x - y <= k: count += 1 print(count)
# 蟻本1-6-1例題相当 # 今回は、xのみ確定した際、y,zの取りうる値の組の数を求める。 # よって1重のfor文で回してみる # 最大で2500となる # 今回は、xの取りうる範囲を考慮しない k, s = list(map(int, input().split())) count = 0 for x in range(0, k + 1): if 0 <= s - x and s - x <= k: # (y,z) = (0, s-x), ... ,(s-x, 0) count += s - x + 1 elif k <= s - x and s - x <= 2 * k: # (y,z) = (s-x-k, k), ... ,(k, s-x-k) count += 2 * k - (s - x) + 1 print(count)
false
17.647059
[ "-# 今回も、x、yを確定した際、zは一意に決まるか値が存在しないかのいずれかであることに着目する。", "-# よって2重のfor文で回してみる", "-# 最大で2500^2≒600万となる", "-# 最後に、x,yの取りうる範囲を考慮する", "+# 今回は、xのみ確定した際、y,zの取りうる値の組の数を求める。", "+# よって1重のfor文で回してみる", "+# 最大で2500となる", "+# 今回は、xの取りうる範囲を考慮しない", "-xmin = (s - 2 * k) if (s - 2 * k) > 0 else 0", "-xmax = k if k < s else s", "-for x in range(xmin, xmax + 1):", "- ymin = (s - k - x) if (s - k - x) > 0 else 0", "- ymax = k if k < s - x else s - x", "- for y in range(ymin, ymax + 1):", "- if 0 <= s - x - y and s - x - y <= k:", "- count += 1", "+for x in range(0, k + 1):", "+ if 0 <= s - x and s - x <= k: # (y,z) = (0, s-x), ... ,(s-x, 0)", "+ count += s - x + 1", "+ elif k <= s - x and s - x <= 2 * k: # (y,z) = (s-x-k, k), ... ,(k, s-x-k)", "+ count += 2 * k - (s - x) + 1" ]
false
0.047292
0.04514
1.047666
[ "s864380071", "s057172327" ]
u813098295
p03862
python
s163073518
s548042479
177
117
11,340
11,340
Accepted
Accepted
33.9
N, x = list(map(int, input().split())) a = list(map(int, input().split())) ans = 0 if a[0] > x: ans += (a[0]-x) a[0] = x for i in range(len(a)-1): if sum(a[i:i+2]) > x: ans += (sum(a[i:i+2]) - x) a[i+1] -= (sum(a[i:i+2]) - x) print(ans)
N, x = list(map(int, input().split())) a = list(map(int, input().split())) ans = 0 if a[0] > x: ans += (a[0]-x) a[0] = x for i in range(len(a)-1): if a[i]+a[i+1] > x: ans += (a[i]+a[i+1]-x) a[i+1] -= (a[i]+a[i+1]-x) print(ans)
14
14
276
269
N, x = list(map(int, input().split())) a = list(map(int, input().split())) ans = 0 if a[0] > x: ans += a[0] - x a[0] = x for i in range(len(a) - 1): if sum(a[i : i + 2]) > x: ans += sum(a[i : i + 2]) - x a[i + 1] -= sum(a[i : i + 2]) - x print(ans)
N, x = list(map(int, input().split())) a = list(map(int, input().split())) ans = 0 if a[0] > x: ans += a[0] - x a[0] = x for i in range(len(a) - 1): if a[i] + a[i + 1] > x: ans += a[i] + a[i + 1] - x a[i + 1] -= a[i] + a[i + 1] - x print(ans)
false
0
[ "- if sum(a[i : i + 2]) > x:", "- ans += sum(a[i : i + 2]) - x", "- a[i + 1] -= sum(a[i : i + 2]) - x", "+ if a[i] + a[i + 1] > x:", "+ ans += a[i] + a[i + 1] - x", "+ a[i + 1] -= a[i] + a[i + 1] - x" ]
false
0.055041
0.065088
0.845642
[ "s163073518", "s548042479" ]
u057109575
p02973
python
s406226877
s337547501
295
130
71,612
92,260
Accepted
Accepted
55.93
from bisect import bisect_right N, *A = list(map(int, open(0).read().split())) INF = 10 ** 10 dp = [INF] * N for i in range(N): dp[bisect_right(dp, -A[i])] = -A[i] print((max(i + 1 for i, v in enumerate(dp) if v < INF)))
from bisect import bisect_right N, *A = list(map(int, open(0).read().split())) x = [1] * (N + 1) for i in range(N): j = bisect_right(x, -A[i]) x[j] = -A[i] print((sum(v != 1 for v in x)))
10
10
229
200
from bisect import bisect_right N, *A = list(map(int, open(0).read().split())) INF = 10**10 dp = [INF] * N for i in range(N): dp[bisect_right(dp, -A[i])] = -A[i] print((max(i + 1 for i, v in enumerate(dp) if v < INF)))
from bisect import bisect_right N, *A = list(map(int, open(0).read().split())) x = [1] * (N + 1) for i in range(N): j = bisect_right(x, -A[i]) x[j] = -A[i] print((sum(v != 1 for v in x)))
false
0
[ "-INF = 10**10", "-dp = [INF] * N", "+x = [1] * (N + 1)", "- dp[bisect_right(dp, -A[i])] = -A[i]", "-print((max(i + 1 for i, v in enumerate(dp) if v < INF)))", "+ j = bisect_right(x, -A[i])", "+ x[j] = -A[i]", "+print((sum(v != 1 for v in x)))" ]
false
0.079957
0.08035
0.995113
[ "s406226877", "s337547501" ]
u261103969
p02754
python
s292798659
s835990830
181
17
38,384
2,940
Accepted
Accepted
90.61
# import bisect # from collections import Counter, deque # import copy # from heapq import heappush, heappop, heapify # from fractions import gcd # import itertools # from operator import attrgetter, itemgetter # import math import sys # import numpy as np ipti = sys.stdin.readline MOD = 10 ** 9 + 7 INF = float('INF') sys.setrecursionlimit(10 ** 5) def main(): n, a, b = list(map(int,ipti().split())) ab = a + b c = n // ab d = n % ab ans = c * a + min(a, d) print(ans) if __name__ == '__main__': main()
n, blue, red = list(map(int, input().split())) # n / (blue + red) = quot ... rem quot = n // (blue + red) # 商 quotient rem = n % (blue + red) # 余り remainder ans = blue * quot + min(blue, rem) print(ans)
30
9
569
215
# import bisect # from collections import Counter, deque # import copy # from heapq import heappush, heappop, heapify # from fractions import gcd # import itertools # from operator import attrgetter, itemgetter # import math import sys # import numpy as np ipti = sys.stdin.readline MOD = 10**9 + 7 INF = float("INF") sys.setrecursionlimit(10**5) def main(): n, a, b = list(map(int, ipti().split())) ab = a + b c = n // ab d = n % ab ans = c * a + min(a, d) print(ans) if __name__ == "__main__": main()
n, blue, red = list(map(int, input().split())) # n / (blue + red) = quot ... rem quot = n // (blue + red) # 商 quotient rem = n % (blue + red) # 余り remainder ans = blue * quot + min(blue, rem) print(ans)
false
70
[ "-# import bisect", "-# from collections import Counter, deque", "-# import copy", "-# from heapq import heappush, heappop, heapify", "-# from fractions import gcd", "-# import itertools", "-# from operator import attrgetter, itemgetter", "-# import math", "-import sys", "-", "-# import numpy as np", "-ipti = sys.stdin.readline", "-MOD = 10**9 + 7", "-INF = float(\"INF\")", "-sys.setrecursionlimit(10**5)", "-", "-", "-def main():", "- n, a, b = list(map(int, ipti().split()))", "- ab = a + b", "- c = n // ab", "- d = n % ab", "- ans = c * a + min(a, d)", "- print(ans)", "-", "-", "-if __name__ == \"__main__\":", "- main()", "+n, blue, red = list(map(int, input().split()))", "+# n / (blue + red) = quot ... rem", "+quot = n // (blue + red) # 商 quotient", "+rem = n % (blue + red) # 余り remainder", "+ans = blue * quot + min(blue, rem)", "+print(ans)" ]
false
0.041467
0.048569
0.853771
[ "s292798659", "s835990830" ]
u952022797
p03476
python
s326746134
s144569573
818
731
19,476
63,448
Accepted
Accepted
10.64
# -*- coding: utf-8 -*- import sys import random def main(): Q = int(eval(input())) maps = [] r_max = 0 for _ in range(Q): l, r = list(map(int, input().split(" "))) maps.append((l, r)) if r_max < r: r_max = r #marix = getPrimeNumList(r_max) base = [0] * (r_max+1) counts = 0 for i in range(r_max+1): if i == 0 or i == 1: continue if (i+1) % 2 == 0 and is_prime(i) == True: tmp = (i+1) / 2 if is_prime(tmp) == True: counts += 1 base[i] = counts for i in maps: l, r = i print((base[r] - base[l-1])) def getPrimeNumList(n): is_prime = [True] * (n + 1) is_prime[0] = False is_prime[1] = False for i in range(2, int(n**0.5) + 1): if not is_prime[i]: continue for j in range(i * 2, n + 1, i): is_prime[j] = False return [i for i in range(n + 1) if is_prime[i]] def is_prime(n): i = 2 while i * i <=n: if n % i == 0: return False i += 1 return True if __name__ == "__main__": main()
# -*- coding: utf-8 -*- import sys import copy import collections from bisect import bisect_left from bisect import bisect_right from collections import defaultdict from heapq import heappop, heappush import math # NO, PAY-PAY #import numpy as np #import statistics #from statistics import mean, median,variance,stdev def main(): Q = int(eval(input())) lr = [] for i in range(Q): l, r = list(map(int,input().split())) lr.append((l,r)) mapd = [] for i in range(0, 100001): if i == 0: mapd.append(0) continue if i == 1: mapd.append(0) continue if i % 2 == 0: mapd.append(mapd[i-1]) continue if is_prime(i) and is_prime((i+1)/2): mapd.append(mapd[i-1] + 1) else: mapd.append(mapd[i-1]) for i in lr: l, r = i print((mapd[r] - mapd[l-1])) def is_prime(n): i = 2 while i * i <=n: if n % i == 0: return False i += 1 return True if __name__ == "__main__": main()
54
53
1,020
1,168
# -*- coding: utf-8 -*- import sys import random def main(): Q = int(eval(input())) maps = [] r_max = 0 for _ in range(Q): l, r = list(map(int, input().split(" "))) maps.append((l, r)) if r_max < r: r_max = r # marix = getPrimeNumList(r_max) base = [0] * (r_max + 1) counts = 0 for i in range(r_max + 1): if i == 0 or i == 1: continue if (i + 1) % 2 == 0 and is_prime(i) == True: tmp = (i + 1) / 2 if is_prime(tmp) == True: counts += 1 base[i] = counts for i in maps: l, r = i print((base[r] - base[l - 1])) def getPrimeNumList(n): is_prime = [True] * (n + 1) is_prime[0] = False is_prime[1] = False for i in range(2, int(n**0.5) + 1): if not is_prime[i]: continue for j in range(i * 2, n + 1, i): is_prime[j] = False return [i for i in range(n + 1) if is_prime[i]] def is_prime(n): i = 2 while i * i <= n: if n % i == 0: return False i += 1 return True if __name__ == "__main__": main()
# -*- coding: utf-8 -*- import sys import copy import collections from bisect import bisect_left from bisect import bisect_right from collections import defaultdict from heapq import heappop, heappush import math # NO, PAY-PAY # import numpy as np # import statistics # from statistics import mean, median,variance,stdev def main(): Q = int(eval(input())) lr = [] for i in range(Q): l, r = list(map(int, input().split())) lr.append((l, r)) mapd = [] for i in range(0, 100001): if i == 0: mapd.append(0) continue if i == 1: mapd.append(0) continue if i % 2 == 0: mapd.append(mapd[i - 1]) continue if is_prime(i) and is_prime((i + 1) / 2): mapd.append(mapd[i - 1] + 1) else: mapd.append(mapd[i - 1]) for i in lr: l, r = i print((mapd[r] - mapd[l - 1])) def is_prime(n): i = 2 while i * i <= n: if n % i == 0: return False i += 1 return True if __name__ == "__main__": main()
false
1.851852
[ "-import random", "+import copy", "+import collections", "+from bisect import bisect_left", "+from bisect import bisect_right", "+from collections import defaultdict", "+from heapq import heappop, heappush", "+import math", "-", "+# NO, PAY-PAY", "+# import numpy as np", "+# import statistics", "+# from statistics import mean, median,variance,stdev", "- maps = []", "- r_max = 0", "- for _ in range(Q):", "- l, r = list(map(int, input().split(\" \")))", "- maps.append((l, r))", "- if r_max < r:", "- r_max = r", "- # marix = getPrimeNumList(r_max)", "- base = [0] * (r_max + 1)", "- counts = 0", "- for i in range(r_max + 1):", "- if i == 0 or i == 1:", "+ lr = []", "+ for i in range(Q):", "+ l, r = list(map(int, input().split()))", "+ lr.append((l, r))", "+ mapd = []", "+ for i in range(0, 100001):", "+ if i == 0:", "+ mapd.append(0)", "- if (i + 1) % 2 == 0 and is_prime(i) == True:", "- tmp = (i + 1) / 2", "- if is_prime(tmp) == True:", "- counts += 1", "- base[i] = counts", "- for i in maps:", "+ if i == 1:", "+ mapd.append(0)", "+ continue", "+ if i % 2 == 0:", "+ mapd.append(mapd[i - 1])", "+ continue", "+ if is_prime(i) and is_prime((i + 1) / 2):", "+ mapd.append(mapd[i - 1] + 1)", "+ else:", "+ mapd.append(mapd[i - 1])", "+ for i in lr:", "- print((base[r] - base[l - 1]))", "-", "-", "-def getPrimeNumList(n):", "- is_prime = [True] * (n + 1)", "- is_prime[0] = False", "- is_prime[1] = False", "- for i in range(2, int(n**0.5) + 1):", "- if not is_prime[i]:", "- continue", "- for j in range(i * 2, n + 1, i):", "- is_prime[j] = False", "- return [i for i in range(n + 1) if is_prime[i]]", "+ print((mapd[r] - mapd[l - 1]))" ]
false
0.040531
0.682302
0.059404
[ "s326746134", "s144569573" ]
u316386814
p03608
python
s513377200
s433890015
1,016
713
14,760
13,028
Accepted
Accepted
29.82
n, m, r = list(map(int, input().split())) rs = list(map(int, input().split())) # construct map import numpy as np dists = np.ones((n + 1, n + 1)) * float('inf') for _ in range(m): a, b, c = list(map(int, input().split())) dists[a, b] = dists[b, a] = c for i in range(1, n + 1): dists[i, i] = 0 from itertools import product, permutations for i, k in product(list(range(1, 1 + n)), repeat=2): dists[:, k] = np.minimum(dists[:, k], dists[:, i] + dists[i, k]) ans = float('inf') for path in permutations(rs): val = sum(dists[i, j] for i, j in zip(path, path[1:])) val = int(val) if val < ans: ans = val print(ans)
n, m, r = list(map(int, input().split())) rs = list(map(int, input().split())) # construct map import numpy as np dists = np.ones((n + 1, n + 1)) * float('inf') for _ in range(m): a, b, c = list(map(int, input().split())) dists[a, b] = dists[b, a] = c for i in range(1, n + 1): dists[i, i] = 0 from itertools import product, permutations for i, j in product(list(range(1, 1 + n)), repeat=2): dists[j] = np.minimum(dists[j], dists[i] + dists[j, i]) ans = float('inf') for path in permutations(rs): val = sum(dists[i, j] for i, j in zip(path, path[1:])) val = int(val) if val < ans: ans = val print(ans)
23
23
665
656
n, m, r = list(map(int, input().split())) rs = list(map(int, input().split())) # construct map import numpy as np dists = np.ones((n + 1, n + 1)) * float("inf") for _ in range(m): a, b, c = list(map(int, input().split())) dists[a, b] = dists[b, a] = c for i in range(1, n + 1): dists[i, i] = 0 from itertools import product, permutations for i, k in product(list(range(1, 1 + n)), repeat=2): dists[:, k] = np.minimum(dists[:, k], dists[:, i] + dists[i, k]) ans = float("inf") for path in permutations(rs): val = sum(dists[i, j] for i, j in zip(path, path[1:])) val = int(val) if val < ans: ans = val print(ans)
n, m, r = list(map(int, input().split())) rs = list(map(int, input().split())) # construct map import numpy as np dists = np.ones((n + 1, n + 1)) * float("inf") for _ in range(m): a, b, c = list(map(int, input().split())) dists[a, b] = dists[b, a] = c for i in range(1, n + 1): dists[i, i] = 0 from itertools import product, permutations for i, j in product(list(range(1, 1 + n)), repeat=2): dists[j] = np.minimum(dists[j], dists[i] + dists[j, i]) ans = float("inf") for path in permutations(rs): val = sum(dists[i, j] for i, j in zip(path, path[1:])) val = int(val) if val < ans: ans = val print(ans)
false
0
[ "-for i, k in product(list(range(1, 1 + n)), repeat=2):", "- dists[:, k] = np.minimum(dists[:, k], dists[:, i] + dists[i, k])", "+for i, j in product(list(range(1, 1 + n)), repeat=2):", "+ dists[j] = np.minimum(dists[j], dists[i] + dists[j, i])" ]
false
0.2057
0.571402
0.359992
[ "s513377200", "s433890015" ]
u747515887
p02837
python
s780187373
s765392804
109
72
3,064
3,064
Accepted
Accepted
33.94
def main(): n = int(eval(input())) xy = [] for i in range(n): a = int(eval(input())) xy.append([tuple(map(int, input().split())) for _ in range(a)]) c = 0 for i in range(1 << n): all_honest = True for j in range(n): if (1 << j) & i != 0: for x, y in xy[j]: x -= 1 # 人の番号をひとつずらす if ((1 << x) & i) >> x != y: all_honest = False break if not all_honest: break if all_honest: popcnt = bin(i).count('1') if popcnt > c: c = popcnt print(c) if __name__ == '__main__': main()
def main(): n = int(eval(input())) xy = [] for i in range(n): a = int(eval(input())) xy.append([tuple(map(int, input().split())) for _ in range(a)]) c = 0 for i in range(1 << n): popcnt = bin(i).count('1') if popcnt <= c: continue all_honest = True for j in range(n): if (1 << j) & i != 0: for x, y in xy[j]: x -= 1 # 人の番号をひとつずらす if ((1 << x) & i) >> x != y: all_honest = False break if not all_honest: break if all_honest: if popcnt > c: c = popcnt print(c) if __name__ == '__main__': main()
29
31
741
784
def main(): n = int(eval(input())) xy = [] for i in range(n): a = int(eval(input())) xy.append([tuple(map(int, input().split())) for _ in range(a)]) c = 0 for i in range(1 << n): all_honest = True for j in range(n): if (1 << j) & i != 0: for x, y in xy[j]: x -= 1 # 人の番号をひとつずらす if ((1 << x) & i) >> x != y: all_honest = False break if not all_honest: break if all_honest: popcnt = bin(i).count("1") if popcnt > c: c = popcnt print(c) if __name__ == "__main__": main()
def main(): n = int(eval(input())) xy = [] for i in range(n): a = int(eval(input())) xy.append([tuple(map(int, input().split())) for _ in range(a)]) c = 0 for i in range(1 << n): popcnt = bin(i).count("1") if popcnt <= c: continue all_honest = True for j in range(n): if (1 << j) & i != 0: for x, y in xy[j]: x -= 1 # 人の番号をひとつずらす if ((1 << x) & i) >> x != y: all_honest = False break if not all_honest: break if all_honest: if popcnt > c: c = popcnt print(c) if __name__ == "__main__": main()
false
6.451613
[ "+ popcnt = bin(i).count(\"1\")", "+ if popcnt <= c:", "+ continue", "- popcnt = bin(i).count(\"1\")" ]
false
0.053971
0.078393
0.688471
[ "s780187373", "s765392804" ]
u714642969
p03162
python
s783674108
s709735270
657
368
74,072
72,412
Accepted
Accepted
43.99
N=int(eval(input())) li=[list(map(int,input().split())) for i in range(N)] dp=[[0]*3 for i in range(N)] for i in range(N): if i==0: for j in range(3): dp[i][j] = li[i][j] else: for j in range(3): if j == 0: dp[i][j] = li[i][0] + dp[i-1][1] if dp[i-1][1] >= dp[i-1][2] else li[i][0] + dp[i-1][2] if j == 1: dp[i][j] = li[i][1] + dp[i-1][0] if dp[i-1][0] >= dp[i-1][2] else li[i][1] + dp[i-1][2] if j == 2: dp[i][j] = li[i][2] + dp[i-1][0] if dp[i-1][0] >= dp[i-1][1] else li[i][2] + dp[i-1][1] print((max(dp[N-1])))
import sys sys.setrecursionlimit(10**9) INF=10**18 MOD=10**9+7 def input(): return sys.stdin.readline().rstrip() def main(): N=int(eval(input())) l=[] for i in range(N): l.append(list(map(int,input().split()))) dp=[[0]*3 for _ in range(N+1)] for i in range(N): for k in range(3): dp[i+1][k]=max(dp[i][(k+1)%3]+l[i][k],dp[i][(k+2)%3]+l[i][k]) print((max(dp[N]))) if __name__ == '__main__': main()
16
19
642
464
N = int(eval(input())) li = [list(map(int, input().split())) for i in range(N)] dp = [[0] * 3 for i in range(N)] for i in range(N): if i == 0: for j in range(3): dp[i][j] = li[i][j] else: for j in range(3): if j == 0: dp[i][j] = ( li[i][0] + dp[i - 1][1] if dp[i - 1][1] >= dp[i - 1][2] else li[i][0] + dp[i - 1][2] ) if j == 1: dp[i][j] = ( li[i][1] + dp[i - 1][0] if dp[i - 1][0] >= dp[i - 1][2] else li[i][1] + dp[i - 1][2] ) if j == 2: dp[i][j] = ( li[i][2] + dp[i - 1][0] if dp[i - 1][0] >= dp[i - 1][1] else li[i][2] + dp[i - 1][1] ) print((max(dp[N - 1])))
import sys sys.setrecursionlimit(10**9) INF = 10**18 MOD = 10**9 + 7 def input(): return sys.stdin.readline().rstrip() def main(): N = int(eval(input())) l = [] for i in range(N): l.append(list(map(int, input().split()))) dp = [[0] * 3 for _ in range(N + 1)] for i in range(N): for k in range(3): dp[i + 1][k] = max( dp[i][(k + 1) % 3] + l[i][k], dp[i][(k + 2) % 3] + l[i][k] ) print((max(dp[N]))) if __name__ == "__main__": main()
false
15.789474
[ "-N = int(eval(input()))", "-li = [list(map(int, input().split())) for i in range(N)]", "-dp = [[0] * 3 for i in range(N)]", "-for i in range(N):", "- if i == 0:", "- for j in range(3):", "- dp[i][j] = li[i][j]", "- else:", "- for j in range(3):", "- if j == 0:", "- dp[i][j] = (", "- li[i][0] + dp[i - 1][1]", "- if dp[i - 1][1] >= dp[i - 1][2]", "- else li[i][0] + dp[i - 1][2]", "- )", "- if j == 1:", "- dp[i][j] = (", "- li[i][1] + dp[i - 1][0]", "- if dp[i - 1][0] >= dp[i - 1][2]", "- else li[i][1] + dp[i - 1][2]", "- )", "- if j == 2:", "- dp[i][j] = (", "- li[i][2] + dp[i - 1][0]", "- if dp[i - 1][0] >= dp[i - 1][1]", "- else li[i][2] + dp[i - 1][1]", "- )", "-print((max(dp[N - 1])))", "+import sys", "+", "+sys.setrecursionlimit(10**9)", "+INF = 10**18", "+MOD = 10**9 + 7", "+", "+", "+def input():", "+ return sys.stdin.readline().rstrip()", "+", "+", "+def main():", "+ N = int(eval(input()))", "+ l = []", "+ for i in range(N):", "+ l.append(list(map(int, input().split())))", "+ dp = [[0] * 3 for _ in range(N + 1)]", "+ for i in range(N):", "+ for k in range(3):", "+ dp[i + 1][k] = max(", "+ dp[i][(k + 1) % 3] + l[i][k], dp[i][(k + 2) % 3] + l[i][k]", "+ )", "+ print((max(dp[N])))", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.057272
0.087177
0.656966
[ "s783674108", "s709735270" ]
u847467233
p00155
python
s385889816
s034726647
60
40
5,808
5,772
Accepted
Accepted
33.33
# AOJ 0155 Spider Jin # Python3 2018.6.23 bal4u # 最短経路問題 MAXLEN = 50 MAX = 100 INF = 0x7ffffffffffffff x = [0]*(MAX+2) y = [0]*(MAX+2) dist = [INF]*(MAX+2) pre = [0]*(MAX+2) import heapq def dijkstra(V, to, start, goal): global dist dist = [INF]*V Q = [] dist[start] = 0 heapq.heappush(Q, (0, start)) while len(Q): t, s = heapq.heappop(Q) if s == goal: break if dist[s] < t: continue for i in to[s]: e, cost = i nt = t + cost if dist[e] > nt: dist[e] = nt heapq.heappush(Q, (nt, e)) pre[e] = s while 1: n = int(eval(input())) if n == 0: break for i in range(n): j, x_, y_ = list(map(int, input().split())) x[j], y[j] = x_, y_ n += 1 to = [[] for i in range(n)] for i in range(1, n): for j in range(1, n): dx, dy = x[i]-x[j], y[i]-y[j] dd = (dx**2 + dy**2)**0.5 if dd <= MAXLEN: to[i].append((j, dd)) to[j].append((i, dd)) m = int(eval(input())) for i in range(m): s, g = list(map(int, input().split())) if s == g: print(s) else: dijkstra(n, to, s, g) if dist[g] == INF: print("NA") else: ans = [] ans.append(g) while g != s: g = pre[g] ans.append(g) print((*ans[::-1]))
# AOJ 0155 Spider Jin # Python3 2018.6.23 bal4u # 最短経路問題 MAXLEN = 50 MAX = 100 INF = 0x7ffffffffffffff x = [0]*(MAX+2) y = [0]*(MAX+2) dist = [INF]*(MAX+2) pre = [0]*(MAX+2) import heapq def dijkstra(V, to, start, goal): global dist dist = [INF]*V Q = [] dist[start] = 0 heapq.heappush(Q, (0, start)) while Q: t, s = heapq.heappop(Q) if s == goal: break if dist[s] < t: continue for e, cost in to[s]: nt = t + cost if dist[e] > nt: dist[e] = nt heapq.heappush(Q, (nt, e)) pre[e] = s while 1: n = int(eval(input())) if n == 0: break for i in range(n): j, x_, y_ = list(map(int, input().split())) x[j], y[j] = x_, y_ n += 1 to = [[] for i in range(n)] for i in range(1, n): for j in range(i+1, n): dx, dy = x[i]-x[j], y[i]-y[j] cost = (dx**2 + dy**2)**0.5 if cost <= MAXLEN: to[i].append((j, cost)) to[j].append((i, cost)) m = int(eval(input())) for i in range(m): s, g = list(map(int, input().split())) if s == g: print(s) else: dijkstra(n, to, s, g) if dist[g] == INF: print("NA") else: ans = [] ans.append(g) while g != s: g = pre[g] ans.append(g) print((*ans[::-1]))
60
59
1,215
1,210
# AOJ 0155 Spider Jin # Python3 2018.6.23 bal4u # 最短経路問題 MAXLEN = 50 MAX = 100 INF = 0x7FFFFFFFFFFFFFF x = [0] * (MAX + 2) y = [0] * (MAX + 2) dist = [INF] * (MAX + 2) pre = [0] * (MAX + 2) import heapq def dijkstra(V, to, start, goal): global dist dist = [INF] * V Q = [] dist[start] = 0 heapq.heappush(Q, (0, start)) while len(Q): t, s = heapq.heappop(Q) if s == goal: break if dist[s] < t: continue for i in to[s]: e, cost = i nt = t + cost if dist[e] > nt: dist[e] = nt heapq.heappush(Q, (nt, e)) pre[e] = s while 1: n = int(eval(input())) if n == 0: break for i in range(n): j, x_, y_ = list(map(int, input().split())) x[j], y[j] = x_, y_ n += 1 to = [[] for i in range(n)] for i in range(1, n): for j in range(1, n): dx, dy = x[i] - x[j], y[i] - y[j] dd = (dx**2 + dy**2) ** 0.5 if dd <= MAXLEN: to[i].append((j, dd)) to[j].append((i, dd)) m = int(eval(input())) for i in range(m): s, g = list(map(int, input().split())) if s == g: print(s) else: dijkstra(n, to, s, g) if dist[g] == INF: print("NA") else: ans = [] ans.append(g) while g != s: g = pre[g] ans.append(g) print((*ans[::-1]))
# AOJ 0155 Spider Jin # Python3 2018.6.23 bal4u # 最短経路問題 MAXLEN = 50 MAX = 100 INF = 0x7FFFFFFFFFFFFFF x = [0] * (MAX + 2) y = [0] * (MAX + 2) dist = [INF] * (MAX + 2) pre = [0] * (MAX + 2) import heapq def dijkstra(V, to, start, goal): global dist dist = [INF] * V Q = [] dist[start] = 0 heapq.heappush(Q, (0, start)) while Q: t, s = heapq.heappop(Q) if s == goal: break if dist[s] < t: continue for e, cost in to[s]: nt = t + cost if dist[e] > nt: dist[e] = nt heapq.heappush(Q, (nt, e)) pre[e] = s while 1: n = int(eval(input())) if n == 0: break for i in range(n): j, x_, y_ = list(map(int, input().split())) x[j], y[j] = x_, y_ n += 1 to = [[] for i in range(n)] for i in range(1, n): for j in range(i + 1, n): dx, dy = x[i] - x[j], y[i] - y[j] cost = (dx**2 + dy**2) ** 0.5 if cost <= MAXLEN: to[i].append((j, cost)) to[j].append((i, cost)) m = int(eval(input())) for i in range(m): s, g = list(map(int, input().split())) if s == g: print(s) else: dijkstra(n, to, s, g) if dist[g] == INF: print("NA") else: ans = [] ans.append(g) while g != s: g = pre[g] ans.append(g) print((*ans[::-1]))
false
1.666667
[ "- while len(Q):", "+ while Q:", "- for i in to[s]:", "- e, cost = i", "+ for e, cost in to[s]:", "- for j in range(1, n):", "+ for j in range(i + 1, n):", "- dd = (dx**2 + dy**2) ** 0.5", "- if dd <= MAXLEN:", "- to[i].append((j, dd))", "- to[j].append((i, dd))", "+ cost = (dx**2 + dy**2) ** 0.5", "+ if cost <= MAXLEN:", "+ to[i].append((j, cost))", "+ to[j].append((i, cost))" ]
false
0.040165
0.007463
5.382111
[ "s385889816", "s034726647" ]
u844646164
p03545
python
s938840493
s719836608
168
65
38,256
61,692
Accepted
Accepted
61.31
abcd = str(eval(input())) a = abcd[0] b = abcd[1] c = abcd[2] d = abcd[3] sign = ['+', '-'] for i in range(2): for j in range(2): for k in range(2): tmp = a + sign[i] + b + sign[j] + c + sign[k] + d if eval(tmp) == 7: print((tmp+'=7')) exit()
abcd = list(eval(input())) a, b, c, d = abcd sign = ['+', '-'] for i in range(2**3): s = a for j in range(3): if (i>>j) & 1: s += sign[0] else: s += sign[1] s += abcd[j+1] if eval(s) == 7: print((s + "=7")) exit()
14
14
318
294
abcd = str(eval(input())) a = abcd[0] b = abcd[1] c = abcd[2] d = abcd[3] sign = ["+", "-"] for i in range(2): for j in range(2): for k in range(2): tmp = a + sign[i] + b + sign[j] + c + sign[k] + d if eval(tmp) == 7: print((tmp + "=7")) exit()
abcd = list(eval(input())) a, b, c, d = abcd sign = ["+", "-"] for i in range(2**3): s = a for j in range(3): if (i >> j) & 1: s += sign[0] else: s += sign[1] s += abcd[j + 1] if eval(s) == 7: print((s + "=7")) exit()
false
0
[ "-abcd = str(eval(input()))", "-a = abcd[0]", "-b = abcd[1]", "-c = abcd[2]", "-d = abcd[3]", "+abcd = list(eval(input()))", "+a, b, c, d = abcd", "-for i in range(2):", "- for j in range(2):", "- for k in range(2):", "- tmp = a + sign[i] + b + sign[j] + c + sign[k] + d", "- if eval(tmp) == 7:", "- print((tmp + \"=7\"))", "- exit()", "+for i in range(2**3):", "+ s = a", "+ for j in range(3):", "+ if (i >> j) & 1:", "+ s += sign[0]", "+ else:", "+ s += sign[1]", "+ s += abcd[j + 1]", "+ if eval(s) == 7:", "+ print((s + \"=7\"))", "+ exit()" ]
false
0.178762
0.071098
2.514317
[ "s938840493", "s719836608" ]
u916338311
p02580
python
s205671537
s909252526
1,054
899
113,492
96,180
Accepted
Accepted
14.71
h,w,m=list(map(int,input().split())) item=[list(map(int,input().split())) for i in range(m)] row=[0]*h col=[0]*w for i in range(m): x,y=item[i] row[x-1]+=1 col[y-1]+=1 mr,mc=max(row),max(col) xr=set([i for i in range(h) if row[i]==mr]) xc=set([i for i in range(w) if col[i]==mc]) check=len(xr)*len(xc) for i in range(m): r,c=item[i] if r-1 in xr and c-1 in xc: check-=1 print((mr+mc if check>0 else mr+mc-1))
H, W, M = list(map(int, input().split())) h = [0] * H w = [0] * W Mem = [tuple(map(int, input().split())) for _ in range(M) ] for i, j in Mem: h[i-1] += 1 w[j-1] += 1 maxh = max(h) maxw = max(w) listh = {i for i, v in enumerate(h, 1) if v == maxh} listw = {j for j, v in enumerate(w, 1) if v == maxw} cnt = len(listh) * len(listw) for i, j in Mem: if i in listh and j in listw: cnt -= 1 if cnt: ans = maxh + maxw else: ans = maxh + maxw - 1 print(ans)
17
27
444
495
h, w, m = list(map(int, input().split())) item = [list(map(int, input().split())) for i in range(m)] row = [0] * h col = [0] * w for i in range(m): x, y = item[i] row[x - 1] += 1 col[y - 1] += 1 mr, mc = max(row), max(col) xr = set([i for i in range(h) if row[i] == mr]) xc = set([i for i in range(w) if col[i] == mc]) check = len(xr) * len(xc) for i in range(m): r, c = item[i] if r - 1 in xr and c - 1 in xc: check -= 1 print((mr + mc if check > 0 else mr + mc - 1))
H, W, M = list(map(int, input().split())) h = [0] * H w = [0] * W Mem = [tuple(map(int, input().split())) for _ in range(M)] for i, j in Mem: h[i - 1] += 1 w[j - 1] += 1 maxh = max(h) maxw = max(w) listh = {i for i, v in enumerate(h, 1) if v == maxh} listw = {j for j, v in enumerate(w, 1) if v == maxw} cnt = len(listh) * len(listw) for i, j in Mem: if i in listh and j in listw: cnt -= 1 if cnt: ans = maxh + maxw else: ans = maxh + maxw - 1 print(ans)
false
37.037037
[ "-h, w, m = list(map(int, input().split()))", "-item = [list(map(int, input().split())) for i in range(m)]", "-row = [0] * h", "-col = [0] * w", "-for i in range(m):", "- x, y = item[i]", "- row[x - 1] += 1", "- col[y - 1] += 1", "-mr, mc = max(row), max(col)", "-xr = set([i for i in range(h) if row[i] == mr])", "-xc = set([i for i in range(w) if col[i] == mc])", "-check = len(xr) * len(xc)", "-for i in range(m):", "- r, c = item[i]", "- if r - 1 in xr and c - 1 in xc:", "- check -= 1", "-print((mr + mc if check > 0 else mr + mc - 1))", "+H, W, M = list(map(int, input().split()))", "+h = [0] * H", "+w = [0] * W", "+Mem = [tuple(map(int, input().split())) for _ in range(M)]", "+for i, j in Mem:", "+ h[i - 1] += 1", "+ w[j - 1] += 1", "+maxh = max(h)", "+maxw = max(w)", "+listh = {i for i, v in enumerate(h, 1) if v == maxh}", "+listw = {j for j, v in enumerate(w, 1) if v == maxw}", "+cnt = len(listh) * len(listw)", "+for i, j in Mem:", "+ if i in listh and j in listw:", "+ cnt -= 1", "+if cnt:", "+ ans = maxh + maxw", "+else:", "+ ans = maxh + maxw - 1", "+print(ans)" ]
false
0.078553
0.099175
0.792068
[ "s205671537", "s909252526" ]
u644907318
p02759
python
s455086419
s218715364
163
63
38,384
61,772
Accepted
Accepted
61.35
print(((int(eval(input()))+1)//2))
N = int(eval(input())) print(((N+1)//2))
1
2
26
33
print(((int(eval(input())) + 1) // 2))
N = int(eval(input())) print(((N + 1) // 2))
false
50
[ "-print(((int(eval(input())) + 1) // 2))", "+N = int(eval(input()))", "+print(((N + 1) // 2))" ]
false
0.035005
0.043949
0.796498
[ "s455086419", "s218715364" ]
u687574784
p03060
python
s904946592
s934256688
954
17
41,436
3,064
Accepted
Accepted
98.22
n = int(eval(input())) v = list(map(int, input().split())) c = list(map(int, input().split())) ans=-10*18 for i in range(1<<n): mask=[(i>>j)&1 for j in range(n)] X=0 Y=0 for k, m in enumerate(mask): if m==1: X+=v[k] Y+=c[k] ans=max(ans, X-Y) print(ans)
n = int(eval(input())) v = list(map(int, input().split())) c = list(map(int, input().split())) ans=0 for x,y in zip(v,c): ans+=max(x-y, 0) print(ans)
15
7
317
153
n = int(eval(input())) v = list(map(int, input().split())) c = list(map(int, input().split())) ans = -10 * 18 for i in range(1 << n): mask = [(i >> j) & 1 for j in range(n)] X = 0 Y = 0 for k, m in enumerate(mask): if m == 1: X += v[k] Y += c[k] ans = max(ans, X - Y) print(ans)
n = int(eval(input())) v = list(map(int, input().split())) c = list(map(int, input().split())) ans = 0 for x, y in zip(v, c): ans += max(x - y, 0) print(ans)
false
53.333333
[ "-ans = -10 * 18", "-for i in range(1 << n):", "- mask = [(i >> j) & 1 for j in range(n)]", "- X = 0", "- Y = 0", "- for k, m in enumerate(mask):", "- if m == 1:", "- X += v[k]", "- Y += c[k]", "- ans = max(ans, X - Y)", "+ans = 0", "+for x, y in zip(v, c):", "+ ans += max(x - y, 0)" ]
false
0.050722
0.04834
1.049269
[ "s904946592", "s934256688" ]
u347640436
p02627
python
s882370449
s974657908
31
24
9,076
9,024
Accepted
Accepted
22.58
A = eval(input()) if A == A.upper(): print('A') else: print('a')
A = eval(input()) if A.isupper(): print('A') else: print('a')
6
6
73
70
A = eval(input()) if A == A.upper(): print("A") else: print("a")
A = eval(input()) if A.isupper(): print("A") else: print("a")
false
0
[ "-if A == A.upper():", "+if A.isupper():" ]
false
0.047418
0.048009
0.987694
[ "s882370449", "s974657908" ]
u827202523
p04044
python
s402366994
s032960092
168
133
38,384
65,404
Accepted
Accepted
20.83
def getlist(): return list(map(int, input().split())) a,b = getlist() lis = [] for i in range(a): lis.append(input().strip()) lis.sort() print(("".join(lis)))
import sys from collections import defaultdict, deque, Counter import math # import copy from bisect import bisect_left, bisect_right # import heapq # sys.setrecursionlimit(1000000) # input aliases input = sys.stdin.readline getS = lambda: input().strip() getN = lambda: int(eval(input())) getList = lambda: list(map(int, input().split())) getZList = lambda: [int(x) - 1 for x in input().split()] INF = 10 ** 20 MOD = 10**9 + 7 divide = lambda x: pow(x, MOD-2, MOD) def main(): n, l = getList() lis = [] for i in range(n): lis.append(getS()) lis.sort() print(("".join(lis))) if __name__ == "__main__": main()
10
34
178
682
def getlist(): return list(map(int, input().split())) a, b = getlist() lis = [] for i in range(a): lis.append(input().strip()) lis.sort() print(("".join(lis)))
import sys from collections import defaultdict, deque, Counter import math # import copy from bisect import bisect_left, bisect_right # import heapq # sys.setrecursionlimit(1000000) # input aliases input = sys.stdin.readline getS = lambda: input().strip() getN = lambda: int(eval(input())) getList = lambda: list(map(int, input().split())) getZList = lambda: [int(x) - 1 for x in input().split()] INF = 10**20 MOD = 10**9 + 7 divide = lambda x: pow(x, MOD - 2, MOD) def main(): n, l = getList() lis = [] for i in range(n): lis.append(getS()) lis.sort() print(("".join(lis))) if __name__ == "__main__": main()
false
70.588235
[ "-def getlist():", "- return list(map(int, input().split()))", "+import sys", "+from collections import defaultdict, deque, Counter", "+import math", "+", "+# import copy", "+from bisect import bisect_left, bisect_right", "+", "+# import heapq", "+# sys.setrecursionlimit(1000000)", "+# input aliases", "+input = sys.stdin.readline", "+getS = lambda: input().strip()", "+getN = lambda: int(eval(input()))", "+getList = lambda: list(map(int, input().split()))", "+getZList = lambda: [int(x) - 1 for x in input().split()]", "+INF = 10**20", "+MOD = 10**9 + 7", "+divide = lambda x: pow(x, MOD - 2, MOD)", "-a, b = getlist()", "-lis = []", "-for i in range(a):", "- lis.append(input().strip())", "-lis.sort()", "-print((\"\".join(lis)))", "+def main():", "+ n, l = getList()", "+ lis = []", "+ for i in range(n):", "+ lis.append(getS())", "+ lis.sort()", "+ print((\"\".join(lis)))", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.041799
0.035965
1.162203
[ "s402366994", "s032960092" ]
u556589653
p03607
python
s042491727
s078068544
235
168
16,612
17,884
Accepted
Accepted
28.51
import collections N = int(eval(input())) ans = 0 now = 0 k = [] for i in range(N): A = int(eval(input())) k.append(A) p = collections.Counter(k) for i in p: if p[i]%2 == 1: ans += 1 print(ans)
N = int(eval(input())) dict1 = {} for i in range(N): A = eval(input()) if A in dict1: del dict1[A] else: dict1[A] = 1 print((len(dict1)))
13
9
203
145
import collections N = int(eval(input())) ans = 0 now = 0 k = [] for i in range(N): A = int(eval(input())) k.append(A) p = collections.Counter(k) for i in p: if p[i] % 2 == 1: ans += 1 print(ans)
N = int(eval(input())) dict1 = {} for i in range(N): A = eval(input()) if A in dict1: del dict1[A] else: dict1[A] = 1 print((len(dict1)))
false
30.769231
[ "-import collections", "-", "-ans = 0", "-now = 0", "-k = []", "+dict1 = {}", "- A = int(eval(input()))", "- k.append(A)", "-p = collections.Counter(k)", "-for i in p:", "- if p[i] % 2 == 1:", "- ans += 1", "-print(ans)", "+ A = eval(input())", "+ if A in dict1:", "+ del dict1[A]", "+ else:", "+ dict1[A] = 1", "+print((len(dict1)))" ]
false
0.102166
0.082267
1.241884
[ "s042491727", "s078068544" ]
u844646164
p02792
python
s622539062
s785787563
274
179
3,316
73,828
Accepted
Accepted
34.67
from collections import defaultdict N = int(eval(input())) ans = 0 c = defaultdict(int) for i in range(1, N+1): s = int(str(i)[0]) t = int(str(i)[-1]) if s != 0 and t != 0: c[(s, t)] += 1 for i in range(1, 10): for j in range(1, 10): ans += c[(i, j)] * c[(j, i)] print(ans)
from collections import defaultdict N = int(eval(input())) d = defaultdict(int) for i in range(1, N+1): s, t = str(i)[0], str(i)[-1] if s != 0 and t != 0: if s > t: s, t = s, t d[(s, t)] += 1 ans = 0 for i in range(1, 11): for j in range(1, 11): i = str(i) j = str(j) ans += d[(i, j)]*d[(j, i)] print(ans)
15
20
300
355
from collections import defaultdict N = int(eval(input())) ans = 0 c = defaultdict(int) for i in range(1, N + 1): s = int(str(i)[0]) t = int(str(i)[-1]) if s != 0 and t != 0: c[(s, t)] += 1 for i in range(1, 10): for j in range(1, 10): ans += c[(i, j)] * c[(j, i)] print(ans)
from collections import defaultdict N = int(eval(input())) d = defaultdict(int) for i in range(1, N + 1): s, t = str(i)[0], str(i)[-1] if s != 0 and t != 0: if s > t: s, t = s, t d[(s, t)] += 1 ans = 0 for i in range(1, 11): for j in range(1, 11): i = str(i) j = str(j) ans += d[(i, j)] * d[(j, i)] print(ans)
false
25
[ "+d = defaultdict(int)", "+for i in range(1, N + 1):", "+ s, t = str(i)[0], str(i)[-1]", "+ if s != 0 and t != 0:", "+ if s > t:", "+ s, t = s, t", "+ d[(s, t)] += 1", "-c = defaultdict(int)", "-for i in range(1, N + 1):", "- s = int(str(i)[0])", "- t = int(str(i)[-1])", "- if s != 0 and t != 0:", "- c[(s, t)] += 1", "-for i in range(1, 10):", "- for j in range(1, 10):", "- ans += c[(i, j)] * c[(j, i)]", "+for i in range(1, 11):", "+ for j in range(1, 11):", "+ i = str(i)", "+ j = str(j)", "+ ans += d[(i, j)] * d[(j, i)]" ]
false
0.054978
0.232461
0.236505
[ "s622539062", "s785787563" ]
u395210038
p02628
python
s699964544
s701155904
335
58
85,164
66,524
Accepted
Accepted
82.69
from sys import stdin, stdout read = stdin.readline write = stdout.write flush = stdout.flush xr = range def main(): n,k = list(map(int,read().split())) a = list(map(int,read().split())) a.sort() write('{}\n'.format(sum(a[:k]))) if __name__ == "__main__": main()
from sys import stdin, stdout read = stdin.readline write = stdout.write flush = stdout.flush xr = range def main(): n,k = list(map(int,read().split())) a = sorted(list(map(int,read().split()))) write('{}\n'.format(sum(a[:k]))) if __name__ == "__main__": main()
14
13
276
273
from sys import stdin, stdout read = stdin.readline write = stdout.write flush = stdout.flush xr = range def main(): n, k = list(map(int, read().split())) a = list(map(int, read().split())) a.sort() write("{}\n".format(sum(a[:k]))) if __name__ == "__main__": main()
from sys import stdin, stdout read = stdin.readline write = stdout.write flush = stdout.flush xr = range def main(): n, k = list(map(int, read().split())) a = sorted(list(map(int, read().split()))) write("{}\n".format(sum(a[:k]))) if __name__ == "__main__": main()
false
7.142857
[ "- a = list(map(int, read().split()))", "- a.sort()", "+ a = sorted(list(map(int, read().split())))" ]
false
0.034354
0.035855
0.958129
[ "s699964544", "s701155904" ]
u627600101
p02814
python
s566499077
s173569617
158
126
20,164
20,020
Accepted
Accepted
20.25
N, M = list(map(int, input().split())) a = list(map(int, input().split())) for k in range(N): a[k] //= 2 foo = 1 while a[0]%2 == 0: foo *= 2 a[0] //= 2 for k in range(1, N): if a[k] % foo == 0 and a[k]%(2*foo) !=0: a[k] //= foo continue else: print((0)) exit() ans = 0 for odd in [3, 5, 7]: flag = False for k in range(N): if a[k]%odd == 0: a[k] //= odd flag = True if flag: foo *= odd import math lcm = a.pop() for k in range(1, N): b = a.pop() lcm = lcm * b // math.gcd(lcm, b) if lcm* foo > M: print((0)) exit() lcm *= foo ans = int((M / lcm -1)//2 + 1) print(ans)
N, M = list(map(int, input().split())) a = list(map(int, input().split())) for k in range(N): a[k] //= 2 foo = 1 while a[0]%2 == 0: foo *= 2 a[0] //= 2 for k in range(1, N): if a[k] % foo == 0 and a[k]%(2*foo) !=0: a[k] //= foo continue else: print((0)) exit() ans = 0 for odd in [3]: flag = False for k in range(N): if a[k]%odd == 0: a[k] //= odd flag = True if flag: foo *= odd import math lcm = a.pop() for k in range(1, N): b = a.pop() lcm = lcm * b // math.gcd(lcm, b) if lcm* foo > M: print((0)) exit() lcm *= foo ans = int((M / lcm -1)//2 + 1) print(ans)
41
41
672
666
N, M = list(map(int, input().split())) a = list(map(int, input().split())) for k in range(N): a[k] //= 2 foo = 1 while a[0] % 2 == 0: foo *= 2 a[0] //= 2 for k in range(1, N): if a[k] % foo == 0 and a[k] % (2 * foo) != 0: a[k] //= foo continue else: print((0)) exit() ans = 0 for odd in [3, 5, 7]: flag = False for k in range(N): if a[k] % odd == 0: a[k] //= odd flag = True if flag: foo *= odd import math lcm = a.pop() for k in range(1, N): b = a.pop() lcm = lcm * b // math.gcd(lcm, b) if lcm * foo > M: print((0)) exit() lcm *= foo ans = int((M / lcm - 1) // 2 + 1) print(ans)
N, M = list(map(int, input().split())) a = list(map(int, input().split())) for k in range(N): a[k] //= 2 foo = 1 while a[0] % 2 == 0: foo *= 2 a[0] //= 2 for k in range(1, N): if a[k] % foo == 0 and a[k] % (2 * foo) != 0: a[k] //= foo continue else: print((0)) exit() ans = 0 for odd in [3]: flag = False for k in range(N): if a[k] % odd == 0: a[k] //= odd flag = True if flag: foo *= odd import math lcm = a.pop() for k in range(1, N): b = a.pop() lcm = lcm * b // math.gcd(lcm, b) if lcm * foo > M: print((0)) exit() lcm *= foo ans = int((M / lcm - 1) // 2 + 1) print(ans)
false
0
[ "-for odd in [3, 5, 7]:", "+for odd in [3]:" ]
false
0.037498
0.036995
1.013576
[ "s566499077", "s173569617" ]
u551313534
p04039
python
s925665372
s465102418
488
440
4,084
3,700
Accepted
Accepted
9.84
from functools import reduce import operator as op n = int(input().split(' ')[0]) ds_str = input().split(' ') ds = list(map(int, ds_str)) for m in range(n, 100000): mlist = list(map(int, list(str(m)))) if reduce(op.or_, [x in ds for x in mlist]): continue else: print(m) break
from functools import reduce import operator as op n = int(input().split(' ')[0]) ds_str = input().split(' ') ds = set(map(int, ds_str)) for m in range(n, 100000): mlist = list(map(int, list(str(m)))) if reduce(op.or_, [x in ds for x in mlist]): continue else: print(m) break
14
14
326
325
from functools import reduce import operator as op n = int(input().split(" ")[0]) ds_str = input().split(" ") ds = list(map(int, ds_str)) for m in range(n, 100000): mlist = list(map(int, list(str(m)))) if reduce(op.or_, [x in ds for x in mlist]): continue else: print(m) break
from functools import reduce import operator as op n = int(input().split(" ")[0]) ds_str = input().split(" ") ds = set(map(int, ds_str)) for m in range(n, 100000): mlist = list(map(int, list(str(m)))) if reduce(op.or_, [x in ds for x in mlist]): continue else: print(m) break
false
0
[ "-ds = list(map(int, ds_str))", "+ds = set(map(int, ds_str))" ]
false
0.042358
0.049068
0.86325
[ "s925665372", "s465102418" ]
u580697892
p03339
python
s881932398
s846365449
252
153
3,700
3,700
Accepted
Accepted
39.29
# coding: utf-8 N = int(eval(input())) S = eval(input()) w, e = 0, 0 for i in range(N): if S[i] == "E": e += 1 ans = e for i in range(N): if S[i] == "E": e -= 1 ans = min(ans, e+w) if S[i] == "W": w += 1 print(ans)
# coding: utf-8 N = int(eval(input())) S = eval(input()) e, w = 0, 0 e = S.count("E") ans = e for i in range(N): if S[i] == "E": e -= 1 ans = min(ans, e+w) else: w += 1 print(ans)
18
13
266
211
# coding: utf-8 N = int(eval(input())) S = eval(input()) w, e = 0, 0 for i in range(N): if S[i] == "E": e += 1 ans = e for i in range(N): if S[i] == "E": e -= 1 ans = min(ans, e + w) if S[i] == "W": w += 1 print(ans)
# coding: utf-8 N = int(eval(input())) S = eval(input()) e, w = 0, 0 e = S.count("E") ans = e for i in range(N): if S[i] == "E": e -= 1 ans = min(ans, e + w) else: w += 1 print(ans)
false
27.777778
[ "-w, e = 0, 0", "-for i in range(N):", "- if S[i] == \"E\":", "- e += 1", "+e, w = 0, 0", "+e = S.count(\"E\")", "- ans = min(ans, e + w)", "- if S[i] == \"W\":", "+ ans = min(ans, e + w)", "+ else:" ]
false
0.038902
0.038724
1.004619
[ "s881932398", "s846365449" ]
u355371431
p03324
python
s883760152
s140439393
170
17
38,512
2,940
Accepted
Accepted
90
D,N = list(map(int,input().split())) ans = (100**D) * N if(N == 100): ans += 100**D print(ans)
d,n = list(map(int,input().split())) ans = n * 100**d if n == 100: ans += 100**d print(ans)
5
5
97
93
D, N = list(map(int, input().split())) ans = (100**D) * N if N == 100: ans += 100**D print(ans)
d, n = list(map(int, input().split())) ans = n * 100**d if n == 100: ans += 100**d print(ans)
false
0
[ "-D, N = list(map(int, input().split()))", "-ans = (100**D) * N", "-if N == 100:", "- ans += 100**D", "+d, n = list(map(int, input().split()))", "+ans = n * 100**d", "+if n == 100:", "+ ans += 100**d" ]
false
0.042737
0.00754
5.667965
[ "s883760152", "s140439393" ]
u600402037
p03352
python
s185816330
s601109811
19
17
2,940
3,060
Accepted
Accepted
10.53
import math X = int(eval(input())) answer = 1 for i in range(X+1): for j in range(2, X+1): if i ** j <= X: answer = max(answer, i ** j) else: break print(answer)
X = int(eval(input())) answer = 1 for i in range(2, X+1): j = 2 while i**j <= X: answer = max(answer, i**j) j += 1 print(answer)
11
9
211
155
import math X = int(eval(input())) answer = 1 for i in range(X + 1): for j in range(2, X + 1): if i**j <= X: answer = max(answer, i**j) else: break print(answer)
X = int(eval(input())) answer = 1 for i in range(2, X + 1): j = 2 while i**j <= X: answer = max(answer, i**j) j += 1 print(answer)
false
18.181818
[ "-import math", "-", "-for i in range(X + 1):", "- for j in range(2, X + 1):", "- if i**j <= X:", "- answer = max(answer, i**j)", "- else:", "- break", "+for i in range(2, X + 1):", "+ j = 2", "+ while i**j <= X:", "+ answer = max(answer, i**j)", "+ j += 1" ]
false
0.05103
0.008635
5.909373
[ "s185816330", "s601109811" ]
u440180827
p00002
python
s772180528
s223633955
30
20
7,528
7,544
Accepted
Accepted
33.33
import sys strs = sys.stdin.readlines() for s in strs: a, b = list(map(int, s.split())) print((len(str(a + b))))
import sys for line in sys.stdin: a, b = list(map(int, line.split())) print((len(str(a + b))))
5
4
116
97
import sys strs = sys.stdin.readlines() for s in strs: a, b = list(map(int, s.split())) print((len(str(a + b))))
import sys for line in sys.stdin: a, b = list(map(int, line.split())) print((len(str(a + b))))
false
20
[ "-strs = sys.stdin.readlines()", "-for s in strs:", "- a, b = list(map(int, s.split()))", "+for line in sys.stdin:", "+ a, b = list(map(int, line.split()))" ]
false
0.083247
0.038503
2.162087
[ "s772180528", "s223633955" ]
u026075806
p03244
python
s890210111
s799356510
83
74
18,652
16,228
Accepted
Accepted
10.84
_ = eval(input()) seq = list(map(int,input().split())) seq1 = seq[::2] seq2 = seq[1::2] if len(set(seq)) == 1: print((len(seq2))) exit() def count_dictonary(seq): ret_dict={} for item in seq: if item not in ret_dict: ret_dict[item] = 1 else: ret_dict[item]+=1 return ret_dict def modes(counting_dict): #(11,2),(2,1),(3,3) ret={} for item in list(counting_dict.items()): no, count = item if counting_dict[no] in ret: ret[count].append(no) else: ret[count]=[no] return ret counting1 = count_dictonary(seq1) counting2 = count_dictonary(seq2) modes1 = sorted(list(modes(counting1).items()),reverse=True) modes2 = sorted(list(modes(counting2).items()),reverse=True) min_change=len(seq) if modes1[0][1] != modes2[0][1] or len(modes1[0][1]) >=2 or len(modes2[0][1]) >=2: min_change = (len(seq1) - modes1[0][0]) + (len(seq2) - modes2[0][0]) else: m01=len(seq) m10=len(seq) if len(modes2) !=1: m01 = (len(seq1) - modes1[0][0]) + (len(seq2) - modes2[1][0]) if len(modes1) !=1: m10 = (len(seq1) - modes1[1][0]) + (len(seq2) - modes2[0][0]) min_change = min(m01,m10) print(min_change)
def count_char_occurrence(seq): # count how many times characters occur and return results as a dictionary ret = {} for char in seq: if char in ret: ret[char] += 1 else: ret[char] = 1 return ret def accum_char_frequency(seq): """ accumulate frequency of each number in a inputted sequence Example: in: [a,a,a,a,b,b,b,b,c] out: { 4 times: [a,b] , 1 times: [c] } """ frequencies = count_char_occurrence(seq) ret = {} for char, count in list(frequencies.items()): if count in ret: ret[count].append(char) else: ret[count] = [char] return ret def main(): _ = eval(input()) seq = list(map(int, input().split())) odd = seq[::2] even = seq[1::2] if len(set(seq)) == 1: # when all chars are unique, return the length of even numbered chars print((len(even))) return no_freq_odd = accum_char_frequency(odd) freq_odd = sorted(list(no_freq_odd.items()), reverse=True) no_freq_even = accum_char_frequency(even) freq_even = sorted(list(no_freq_even.items()), reverse=True) if len(freq_odd[0][1]) == 1 and len(freq_even[0][1]) == 1 and freq_odd[0][1] == freq_even[0][1]: min_change_even = len(seq) if len(freq_even) != 1: min_change_even = (len(odd) - freq_odd[0][0]) + (len(even) - freq_even[1][0]) min_change_odd = len(seq) if len(freq_odd) != 1: min_change_odd = (len(odd) - freq_odd[1][0]) + (len(even) - freq_even[0][0]) print((min(min_change_even, min_change_odd))) return else: min_change = (len(odd) - freq_odd[0][0]) + (len(even) - freq_even[0][0]) print(min_change) return main()
51
63
1,299
1,827
_ = eval(input()) seq = list(map(int, input().split())) seq1 = seq[::2] seq2 = seq[1::2] if len(set(seq)) == 1: print((len(seq2))) exit() def count_dictonary(seq): ret_dict = {} for item in seq: if item not in ret_dict: ret_dict[item] = 1 else: ret_dict[item] += 1 return ret_dict def modes(counting_dict): # (11,2),(2,1),(3,3) ret = {} for item in list(counting_dict.items()): no, count = item if counting_dict[no] in ret: ret[count].append(no) else: ret[count] = [no] return ret counting1 = count_dictonary(seq1) counting2 = count_dictonary(seq2) modes1 = sorted(list(modes(counting1).items()), reverse=True) modes2 = sorted(list(modes(counting2).items()), reverse=True) min_change = len(seq) if modes1[0][1] != modes2[0][1] or len(modes1[0][1]) >= 2 or len(modes2[0][1]) >= 2: min_change = (len(seq1) - modes1[0][0]) + (len(seq2) - modes2[0][0]) else: m01 = len(seq) m10 = len(seq) if len(modes2) != 1: m01 = (len(seq1) - modes1[0][0]) + (len(seq2) - modes2[1][0]) if len(modes1) != 1: m10 = (len(seq1) - modes1[1][0]) + (len(seq2) - modes2[0][0]) min_change = min(m01, m10) print(min_change)
def count_char_occurrence(seq): # count how many times characters occur and return results as a dictionary ret = {} for char in seq: if char in ret: ret[char] += 1 else: ret[char] = 1 return ret def accum_char_frequency(seq): """ accumulate frequency of each number in a inputted sequence Example: in: [a,a,a,a,b,b,b,b,c] out: { 4 times: [a,b] , 1 times: [c] } """ frequencies = count_char_occurrence(seq) ret = {} for char, count in list(frequencies.items()): if count in ret: ret[count].append(char) else: ret[count] = [char] return ret def main(): _ = eval(input()) seq = list(map(int, input().split())) odd = seq[::2] even = seq[1::2] if ( len(set(seq)) == 1 ): # when all chars are unique, return the length of even numbered chars print((len(even))) return no_freq_odd = accum_char_frequency(odd) freq_odd = sorted(list(no_freq_odd.items()), reverse=True) no_freq_even = accum_char_frequency(even) freq_even = sorted(list(no_freq_even.items()), reverse=True) if ( len(freq_odd[0][1]) == 1 and len(freq_even[0][1]) == 1 and freq_odd[0][1] == freq_even[0][1] ): min_change_even = len(seq) if len(freq_even) != 1: min_change_even = (len(odd) - freq_odd[0][0]) + ( len(even) - freq_even[1][0] ) min_change_odd = len(seq) if len(freq_odd) != 1: min_change_odd = (len(odd) - freq_odd[1][0]) + (len(even) - freq_even[0][0]) print((min(min_change_even, min_change_odd))) return else: min_change = (len(odd) - freq_odd[0][0]) + (len(even) - freq_even[0][0]) print(min_change) return main()
false
19.047619
[ "-_ = eval(input())", "-seq = list(map(int, input().split()))", "-seq1 = seq[::2]", "-seq2 = seq[1::2]", "-if len(set(seq)) == 1:", "- print((len(seq2)))", "- exit()", "-", "-", "-def count_dictonary(seq):", "- ret_dict = {}", "- for item in seq:", "- if item not in ret_dict:", "- ret_dict[item] = 1", "+def count_char_occurrence(seq):", "+ # count how many times characters occur and return results as a dictionary", "+ ret = {}", "+ for char in seq:", "+ if char in ret:", "+ ret[char] += 1", "- ret_dict[item] += 1", "- return ret_dict", "-", "-", "-def modes(counting_dict):", "- # (11,2),(2,1),(3,3)", "- ret = {}", "- for item in list(counting_dict.items()):", "- no, count = item", "- if counting_dict[no] in ret:", "- ret[count].append(no)", "- else:", "- ret[count] = [no]", "+ ret[char] = 1", "-counting1 = count_dictonary(seq1)", "-counting2 = count_dictonary(seq2)", "-modes1 = sorted(list(modes(counting1).items()), reverse=True)", "-modes2 = sorted(list(modes(counting2).items()), reverse=True)", "-min_change = len(seq)", "-if modes1[0][1] != modes2[0][1] or len(modes1[0][1]) >= 2 or len(modes2[0][1]) >= 2:", "- min_change = (len(seq1) - modes1[0][0]) + (len(seq2) - modes2[0][0])", "-else:", "- m01 = len(seq)", "- m10 = len(seq)", "- if len(modes2) != 1:", "- m01 = (len(seq1) - modes1[0][0]) + (len(seq2) - modes2[1][0])", "- if len(modes1) != 1:", "- m10 = (len(seq1) - modes1[1][0]) + (len(seq2) - modes2[0][0])", "- min_change = min(m01, m10)", "-print(min_change)", "+def accum_char_frequency(seq):", "+ \"\"\"", "+ accumulate frequency of each number in a inputted sequence", "+ Example:", "+ in: [a,a,a,a,b,b,b,b,c]", "+ out: { 4 times: [a,b] , 1 times: [c] }", "+ \"\"\"", "+ frequencies = count_char_occurrence(seq)", "+ ret = {}", "+ for char, count in list(frequencies.items()):", "+ if count in ret:", "+ ret[count].append(char)", "+ else:", "+ ret[count] = [char]", "+ return ret", "+", "+", "+def main():", "+ _ = eval(input())", "+ seq = list(map(int, input().split()))", "+ odd = seq[::2]", "+ even = seq[1::2]", "+ if (", "+ len(set(seq)) == 1", "+ ): # when all chars are unique, return the length of even numbered chars", "+ print((len(even)))", "+ return", "+ no_freq_odd = accum_char_frequency(odd)", "+ freq_odd = sorted(list(no_freq_odd.items()), reverse=True)", "+ no_freq_even = accum_char_frequency(even)", "+ freq_even = sorted(list(no_freq_even.items()), reverse=True)", "+ if (", "+ len(freq_odd[0][1]) == 1", "+ and len(freq_even[0][1]) == 1", "+ and freq_odd[0][1] == freq_even[0][1]", "+ ):", "+ min_change_even = len(seq)", "+ if len(freq_even) != 1:", "+ min_change_even = (len(odd) - freq_odd[0][0]) + (", "+ len(even) - freq_even[1][0]", "+ )", "+ min_change_odd = len(seq)", "+ if len(freq_odd) != 1:", "+ min_change_odd = (len(odd) - freq_odd[1][0]) + (len(even) - freq_even[0][0])", "+ print((min(min_change_even, min_change_odd)))", "+ return", "+ else:", "+ min_change = (len(odd) - freq_odd[0][0]) + (len(even) - freq_even[0][0])", "+ print(min_change)", "+ return", "+", "+", "+main()" ]
false
0.043018
0.107153
0.401459
[ "s890210111", "s799356510" ]
u815878613
p03220
python
s330376736
s410385885
326
29
21,752
9,268
Accepted
Accepted
91.1
import sys import numpy as np N = int(eval(input())) T, A = list(map(int, input().split())) H = np.array(list(map(int, input().split()))) m = abs(A - (T - 0.006 * H[0])) num = 1 for n in range(1, N): d = abs(A - (T - 0.006 * H[n])) if d < m: m = d num = n+1 print(num)
N = int(eval(input())) T, A = list(map(int, input().split())) H = list(map(int, input().split())) pt = [abs(A - (T - h * 0.006)) for h in H] # np.argsortなしで,最大値,最小値のindexを取得 ans = min(enumerate(pt), key=lambda x: x[1])[0] print((ans + 1)) # 最大値が複数あるとき # [i for i, v in enumerate(li) if v == max(l)] # 計算重そう
17
14
307
310
import sys import numpy as np N = int(eval(input())) T, A = list(map(int, input().split())) H = np.array(list(map(int, input().split()))) m = abs(A - (T - 0.006 * H[0])) num = 1 for n in range(1, N): d = abs(A - (T - 0.006 * H[n])) if d < m: m = d num = n + 1 print(num)
N = int(eval(input())) T, A = list(map(int, input().split())) H = list(map(int, input().split())) pt = [abs(A - (T - h * 0.006)) for h in H] # np.argsortなしで,最大値,最小値のindexを取得 ans = min(enumerate(pt), key=lambda x: x[1])[0] print((ans + 1)) # 最大値が複数あるとき # [i for i, v in enumerate(li) if v == max(l)] # 計算重そう
false
17.647059
[ "-import sys", "-import numpy as np", "-", "-H = np.array(list(map(int, input().split())))", "-m = abs(A - (T - 0.006 * H[0]))", "-num = 1", "-for n in range(1, N):", "- d = abs(A - (T - 0.006 * H[n]))", "- if d < m:", "- m = d", "- num = n + 1", "-print(num)", "+H = list(map(int, input().split()))", "+pt = [abs(A - (T - h * 0.006)) for h in H]", "+# np.argsortなしで,最大値,最小値のindexを取得", "+ans = min(enumerate(pt), key=lambda x: x[1])[0]", "+print((ans + 1))", "+# 最大値が複数あるとき", "+# [i for i, v in enumerate(li) if v == max(l)]", "+# 計算重そう" ]
false
0.871432
0.041442
21.0276
[ "s330376736", "s410385885" ]
u794544096
p02760
python
s975685890
s824934805
562
60
79,668
62,088
Accepted
Accepted
89.32
a = [] for i in range(3): a1, a2, a3 = list(map(int, input().split())) a.append(a1) a.append(a2) a.append(a3) l = [0]*9 n = int(eval(input())) for i in range(n): b = int(eval(input())) if b in a: l[a.index(b)] += 1 if l[0] == 1 and l[1] == 1 and l[2] == 1: print('Yes') elif l[3] == 1 and l[4] == 1 and l[5] == 1: print('Yes') elif l[6] == 1 and l[7] == 1 and l[8] == 1: print('Yes') elif l[0] == 1 and l[3] == 1 and l[6] == 1: print('Yes') elif l[1] == 1 and l[4] == 1 and l[7] == 1: print('Yes') elif l[2] == 1 and l[5] == 1 and l[8] == 1: print('Yes') elif l[0] == 1 and l[4] == 1 and l[8] == 1: print('Yes') elif l[2] == 1 and l[4] == 1 and l[6] == 1: print('Yes') else: print('No')
a = [] for i in range(3): a1, a2, a3 = list(map(int, input().split())) a.append(a1) a.append(a2) a.append(a3) l = [0]*9 n = int(eval(input())) for i in range(n): b = int(eval(input())) for k in range(9): if a[k] == b: l[k] += 1 if l[0] == 1 and l[1] == 1 and l[2] == 1: print('Yes') elif l[3] == 1 and l[4] == 1 and l[5] == 1: print('Yes') elif l[6] == 1 and l[7] == 1 and l[8] == 1: print('Yes') elif l[0] == 1 and l[3] == 1 and l[6] == 1: print('Yes') elif l[1] == 1 and l[4] == 1 and l[7] == 1: print('Yes') elif l[2] == 1 and l[5] == 1 and l[8] == 1: print('Yes') elif l[0] == 1 and l[4] == 1 and l[8] == 1: print('Yes') elif l[2] == 1 and l[4] == 1 and l[6] == 1: print('Yes') else: print('No')
33
34
771
798
a = [] for i in range(3): a1, a2, a3 = list(map(int, input().split())) a.append(a1) a.append(a2) a.append(a3) l = [0] * 9 n = int(eval(input())) for i in range(n): b = int(eval(input())) if b in a: l[a.index(b)] += 1 if l[0] == 1 and l[1] == 1 and l[2] == 1: print("Yes") elif l[3] == 1 and l[4] == 1 and l[5] == 1: print("Yes") elif l[6] == 1 and l[7] == 1 and l[8] == 1: print("Yes") elif l[0] == 1 and l[3] == 1 and l[6] == 1: print("Yes") elif l[1] == 1 and l[4] == 1 and l[7] == 1: print("Yes") elif l[2] == 1 and l[5] == 1 and l[8] == 1: print("Yes") elif l[0] == 1 and l[4] == 1 and l[8] == 1: print("Yes") elif l[2] == 1 and l[4] == 1 and l[6] == 1: print("Yes") else: print("No")
a = [] for i in range(3): a1, a2, a3 = list(map(int, input().split())) a.append(a1) a.append(a2) a.append(a3) l = [0] * 9 n = int(eval(input())) for i in range(n): b = int(eval(input())) for k in range(9): if a[k] == b: l[k] += 1 if l[0] == 1 and l[1] == 1 and l[2] == 1: print("Yes") elif l[3] == 1 and l[4] == 1 and l[5] == 1: print("Yes") elif l[6] == 1 and l[7] == 1 and l[8] == 1: print("Yes") elif l[0] == 1 and l[3] == 1 and l[6] == 1: print("Yes") elif l[1] == 1 and l[4] == 1 and l[7] == 1: print("Yes") elif l[2] == 1 and l[5] == 1 and l[8] == 1: print("Yes") elif l[0] == 1 and l[4] == 1 and l[8] == 1: print("Yes") elif l[2] == 1 and l[4] == 1 and l[6] == 1: print("Yes") else: print("No")
false
2.941176
[ "- if b in a:", "- l[a.index(b)] += 1", "+ for k in range(9):", "+ if a[k] == b:", "+ l[k] += 1" ]
false
0.047519
0.042266
1.124285
[ "s975685890", "s824934805" ]
u659302753
p02726
python
s258150409
s747504319
637
491
80,220
53,212
Accepted
Accepted
22.92
from sys import stdin from collections import deque def get_adj_list(num_nodes, data, undirected=True): # adj_list ex) {1:[2,3,4], 2:[1,4,5], 3:[1,4], 4:[1,2,3,5], 5:[2,4]} graph = {} for i in range(num_nodes): graph[i+1] = [] for val in data: x, y = val graph[x] = graph[x] + [y] if undirected: graph[y] = graph[y] + [x] return graph def breadth_first_search(adj_list, start_node): dist = {} queue = deque([(start_node, 0)]) while len(queue) > 0: v, d = queue.popleft() if v in dist: continue dist[v] = d for u in adj_list[v]: if u not in dist: queue.append((u, d+1)) return dist # bfs def get_result(data): N, X, Y = data _data = [[i, i+1] for i in range(1, N)] _data += [[X, Y]] adj_list = get_adj_list(N, _data) dist_cnt = [0 for i in range(N)] for i in range(N): dist = breadth_first_search(adj_list, i+1) for j in range(i, N): dist_cnt[dist[j+1]] += 1 for i in range(1, N): print((dist_cnt[i])) # 解説のコード # def get_result(data): # N, X, Y = data # dist_cnt = [0 for i in range(N)] # for i in range(1, N+1): # for j in range(i+1, N+1): # min_dist = min([j-i, abs(X-i) + 1 + abs(Y-j), abs(Y-i) + 1 + abs(X-j)]) # dist_cnt[min_dist] += 1 # for i in range(1, N): # print(dist_cnt[i]) if __name__ == '__main__': data = list(map(int, stdin.readline().rstrip('\n').split(' '))) get_result(data)
# from sys import stdin # # 解説のコード # def get_result(data): # N, X, Y = data # dist_cnt = [0 for i in range(N)] # for i in range(1, N+1): # for j in range(i+1, N+1): # min_dist = min([j-i, abs(X-i) + 1 + abs(Y-j), abs(Y-i) + 1 + abs(X-j)]) # dist_cnt[min_dist] += 1 # for i in range(1, N): # print(dist_cnt[i]) # if __name__ == '__main__': # data = list(map(int, stdin.readline().rstrip('\n').split(' '))) # get_result(data) from sys import stdin from collections import deque # 重みなしグラフの隣接リスト # 0-indexed nodes def get_adj_list(num_nodes, data, undirected=True): graph = [[] for _ in range(num_nodes)] for val in data: x, y = val graph[x-1] = graph[x-1] + [y-1] if undirected: graph[y-1] = graph[y-1] + [x-1] return graph # BFS def breadth_first_search(adj_list, start_node): N = len(adj_list) order = [-1] * N # a bfs ordering of each vertex parent = [-1] * N # parent of each vertex in the bfs search tree depth = [-1] * N # the depth of each vertex q = deque([(start_node, -1, 0)]) # (vertex, parent, depth) num = 0 # current ordering while q: v, p, d = q.popleft() if order[v] < 0: # visited v for the first time order[v] = num parent[v] = p depth[v] = d num += 1 for u in adj_list[v]: if order[u] >= 0: continue q.append((u, v, d+1)) return order, parent, depth # BFS pypyでAC def get_result(data): N, X, Y = data _data = [[i, i+1] for i in range(1, N)] _data += [[X, Y]] adj_list = get_adj_list(N, _data) dist_cnt = [0 for i in range(N)] for i in range(N): _, _, depth = breadth_first_search(adj_list, i) for j in range(i, N): dist_cnt[depth[j]] += 1 for i in range(1, N): print((dist_cnt[i])) if __name__ == '__main__': data = list(map(int, stdin.readline().rstrip('\n').split(' '))) get_result(data)
58
72
1,623
2,110
from sys import stdin from collections import deque def get_adj_list(num_nodes, data, undirected=True): # adj_list ex) {1:[2,3,4], 2:[1,4,5], 3:[1,4], 4:[1,2,3,5], 5:[2,4]} graph = {} for i in range(num_nodes): graph[i + 1] = [] for val in data: x, y = val graph[x] = graph[x] + [y] if undirected: graph[y] = graph[y] + [x] return graph def breadth_first_search(adj_list, start_node): dist = {} queue = deque([(start_node, 0)]) while len(queue) > 0: v, d = queue.popleft() if v in dist: continue dist[v] = d for u in adj_list[v]: if u not in dist: queue.append((u, d + 1)) return dist # bfs def get_result(data): N, X, Y = data _data = [[i, i + 1] for i in range(1, N)] _data += [[X, Y]] adj_list = get_adj_list(N, _data) dist_cnt = [0 for i in range(N)] for i in range(N): dist = breadth_first_search(adj_list, i + 1) for j in range(i, N): dist_cnt[dist[j + 1]] += 1 for i in range(1, N): print((dist_cnt[i])) # 解説のコード # def get_result(data): # N, X, Y = data # dist_cnt = [0 for i in range(N)] # for i in range(1, N+1): # for j in range(i+1, N+1): # min_dist = min([j-i, abs(X-i) + 1 + abs(Y-j), abs(Y-i) + 1 + abs(X-j)]) # dist_cnt[min_dist] += 1 # for i in range(1, N): # print(dist_cnt[i]) if __name__ == "__main__": data = list(map(int, stdin.readline().rstrip("\n").split(" "))) get_result(data)
# from sys import stdin # # 解説のコード # def get_result(data): # N, X, Y = data # dist_cnt = [0 for i in range(N)] # for i in range(1, N+1): # for j in range(i+1, N+1): # min_dist = min([j-i, abs(X-i) + 1 + abs(Y-j), abs(Y-i) + 1 + abs(X-j)]) # dist_cnt[min_dist] += 1 # for i in range(1, N): # print(dist_cnt[i]) # if __name__ == '__main__': # data = list(map(int, stdin.readline().rstrip('\n').split(' '))) # get_result(data) from sys import stdin from collections import deque # 重みなしグラフの隣接リスト # 0-indexed nodes def get_adj_list(num_nodes, data, undirected=True): graph = [[] for _ in range(num_nodes)] for val in data: x, y = val graph[x - 1] = graph[x - 1] + [y - 1] if undirected: graph[y - 1] = graph[y - 1] + [x - 1] return graph # BFS def breadth_first_search(adj_list, start_node): N = len(adj_list) order = [-1] * N # a bfs ordering of each vertex parent = [-1] * N # parent of each vertex in the bfs search tree depth = [-1] * N # the depth of each vertex q = deque([(start_node, -1, 0)]) # (vertex, parent, depth) num = 0 # current ordering while q: v, p, d = q.popleft() if order[v] < 0: # visited v for the first time order[v] = num parent[v] = p depth[v] = d num += 1 for u in adj_list[v]: if order[u] >= 0: continue q.append((u, v, d + 1)) return order, parent, depth # BFS pypyでAC def get_result(data): N, X, Y = data _data = [[i, i + 1] for i in range(1, N)] _data += [[X, Y]] adj_list = get_adj_list(N, _data) dist_cnt = [0 for i in range(N)] for i in range(N): _, _, depth = breadth_first_search(adj_list, i) for j in range(i, N): dist_cnt[depth[j]] += 1 for i in range(1, N): print((dist_cnt[i])) if __name__ == "__main__": data = list(map(int, stdin.readline().rstrip("\n").split(" "))) get_result(data)
false
19.444444
[ "-from sys import stdin", "-from collections import deque", "-", "-", "-def get_adj_list(num_nodes, data, undirected=True):", "- # adj_list ex) {1:[2,3,4], 2:[1,4,5], 3:[1,4], 4:[1,2,3,5], 5:[2,4]}", "- graph = {}", "- for i in range(num_nodes):", "- graph[i + 1] = []", "- for val in data:", "- x, y = val", "- graph[x] = graph[x] + [y]", "- if undirected:", "- graph[y] = graph[y] + [x]", "- return graph", "-", "-", "-def breadth_first_search(adj_list, start_node):", "- dist = {}", "- queue = deque([(start_node, 0)])", "- while len(queue) > 0:", "- v, d = queue.popleft()", "- if v in dist:", "- continue", "- dist[v] = d", "- for u in adj_list[v]:", "- if u not in dist:", "- queue.append((u, d + 1))", "- return dist", "-", "-", "-# bfs", "-def get_result(data):", "- N, X, Y = data", "- _data = [[i, i + 1] for i in range(1, N)]", "- _data += [[X, Y]]", "- adj_list = get_adj_list(N, _data)", "- dist_cnt = [0 for i in range(N)]", "- for i in range(N):", "- dist = breadth_first_search(adj_list, i + 1)", "- for j in range(i, N):", "- dist_cnt[dist[j + 1]] += 1", "- for i in range(1, N):", "- print((dist_cnt[i]))", "-", "-", "-# 解説のコード", "+# from sys import stdin", "+# # 解説のコード", "+# if __name__ == '__main__':", "+# data = list(map(int, stdin.readline().rstrip('\\n').split(' ')))", "+# get_result(data)", "+from sys import stdin", "+from collections import deque", "+", "+# 重みなしグラフの隣接リスト", "+# 0-indexed nodes", "+def get_adj_list(num_nodes, data, undirected=True):", "+ graph = [[] for _ in range(num_nodes)]", "+ for val in data:", "+ x, y = val", "+ graph[x - 1] = graph[x - 1] + [y - 1]", "+ if undirected:", "+ graph[y - 1] = graph[y - 1] + [x - 1]", "+ return graph", "+", "+", "+# BFS", "+def breadth_first_search(adj_list, start_node):", "+ N = len(adj_list)", "+ order = [-1] * N # a bfs ordering of each vertex", "+ parent = [-1] * N # parent of each vertex in the bfs search tree", "+ depth = [-1] * N # the depth of each vertex", "+ q = deque([(start_node, -1, 0)]) # (vertex, parent, depth)", "+ num = 0 # current ordering", "+ while q:", "+ v, p, d = q.popleft()", "+ if order[v] < 0: # visited v for the first time", "+ order[v] = num", "+ parent[v] = p", "+ depth[v] = d", "+ num += 1", "+ for u in adj_list[v]:", "+ if order[u] >= 0:", "+ continue", "+ q.append((u, v, d + 1))", "+ return order, parent, depth", "+", "+", "+# BFS pypyでAC", "+def get_result(data):", "+ N, X, Y = data", "+ _data = [[i, i + 1] for i in range(1, N)]", "+ _data += [[X, Y]]", "+ adj_list = get_adj_list(N, _data)", "+ dist_cnt = [0 for i in range(N)]", "+ for i in range(N):", "+ _, _, depth = breadth_first_search(adj_list, i)", "+ for j in range(i, N):", "+ dist_cnt[depth[j]] += 1", "+ for i in range(1, N):", "+ print((dist_cnt[i]))", "+", "+" ]
false
0.066484
0.045273
1.468496
[ "s258150409", "s747504319" ]
u533039576
p02819
python
s260553332
s366113457
63
17
4,596
2,940
Accepted
Accepted
73.02
def eratosthenes(n: int) -> list: is_prime = [True] * (n + 1) is_prime[0] = is_prime[1] = False for i in range(2, n // 2 + 1): if is_prime[i]: for j in range(2, n // i + 1): is_prime[i * j] = False return is_prime x = int(eval(input())) is_prime = eratosthenes(x * 2 + 100) ans = x while not is_prime[ans]: ans += 1 print(ans)
def is_prime(n): if n <= 1: return False elif n == 2: return True elif n % 2 == 0: return False for i in range(3, n, 2): if i * i > n: break if n % i == 0: return False return True x = int(eval(input())) while not is_prime(x): x += 1 print(x)
16
19
394
345
def eratosthenes(n: int) -> list: is_prime = [True] * (n + 1) is_prime[0] = is_prime[1] = False for i in range(2, n // 2 + 1): if is_prime[i]: for j in range(2, n // i + 1): is_prime[i * j] = False return is_prime x = int(eval(input())) is_prime = eratosthenes(x * 2 + 100) ans = x while not is_prime[ans]: ans += 1 print(ans)
def is_prime(n): if n <= 1: return False elif n == 2: return True elif n % 2 == 0: return False for i in range(3, n, 2): if i * i > n: break if n % i == 0: return False return True x = int(eval(input())) while not is_prime(x): x += 1 print(x)
false
15.789474
[ "-def eratosthenes(n: int) -> list:", "- is_prime = [True] * (n + 1)", "- is_prime[0] = is_prime[1] = False", "- for i in range(2, n // 2 + 1):", "- if is_prime[i]:", "- for j in range(2, n // i + 1):", "- is_prime[i * j] = False", "- return is_prime", "+def is_prime(n):", "+ if n <= 1:", "+ return False", "+ elif n == 2:", "+ return True", "+ elif n % 2 == 0:", "+ return False", "+ for i in range(3, n, 2):", "+ if i * i > n:", "+ break", "+ if n % i == 0:", "+ return False", "+ return True", "-is_prime = eratosthenes(x * 2 + 100)", "-ans = x", "-while not is_prime[ans]:", "- ans += 1", "-print(ans)", "+while not is_prime(x):", "+ x += 1", "+print(x)" ]
false
0.043994
0.07866
0.559293
[ "s260553332", "s366113457" ]
u073852194
p03426
python
s767456531
s764640811
758
493
78,428
37,448
Accepted
Accepted
34.96
H,W,D = list(map(int,input().split())) A = [list(map(int,input().split())) for i in range(H)] Q = int(eval(input())) S = [list(map(int,input().split())) for i in range(Q)] P = [None]*(H*W+1) for i in range(H): for j in range(W): P[A[i][j]] = [i,j] Accum = [0]*(H*W+1) accum = 0 for i in range(D+1,H*W+1): Accum[i] = Accum[i-D]+abs(P[i][0]-P[i-D][0])+abs(P[i][1]-P[i-D][1]) for s in S: print((Accum[s[1]]-Accum[s[0]]))
H, W, D = list(map(int, input().split())) A = [tuple(map(int, input().split())) for _ in range(H)] P = {} for i in range(H): for j in range(W): P[A[i][j] - 1] = (i, j) cum = [0] * (H * W + 1) for a in range(H * W - D): i, j = P[a] x, y = P[a + D] cum[a + D] = cum[a] + abs(x - i) + abs(y - j) Q = int(eval(input())) ans = [] for _ in range(Q): l, r = list(map(int, input().split())) ans.append(cum[r - 1] - cum[l - 1]) print(('\n'.join(map(str, ans))))
17
24
442
494
H, W, D = list(map(int, input().split())) A = [list(map(int, input().split())) for i in range(H)] Q = int(eval(input())) S = [list(map(int, input().split())) for i in range(Q)] P = [None] * (H * W + 1) for i in range(H): for j in range(W): P[A[i][j]] = [i, j] Accum = [0] * (H * W + 1) accum = 0 for i in range(D + 1, H * W + 1): Accum[i] = Accum[i - D] + abs(P[i][0] - P[i - D][0]) + abs(P[i][1] - P[i - D][1]) for s in S: print((Accum[s[1]] - Accum[s[0]]))
H, W, D = list(map(int, input().split())) A = [tuple(map(int, input().split())) for _ in range(H)] P = {} for i in range(H): for j in range(W): P[A[i][j] - 1] = (i, j) cum = [0] * (H * W + 1) for a in range(H * W - D): i, j = P[a] x, y = P[a + D] cum[a + D] = cum[a] + abs(x - i) + abs(y - j) Q = int(eval(input())) ans = [] for _ in range(Q): l, r = list(map(int, input().split())) ans.append(cum[r - 1] - cum[l - 1]) print(("\n".join(map(str, ans))))
false
29.166667
[ "-A = [list(map(int, input().split())) for i in range(H)]", "-Q = int(eval(input()))", "-S = [list(map(int, input().split())) for i in range(Q)]", "-P = [None] * (H * W + 1)", "+A = [tuple(map(int, input().split())) for _ in range(H)]", "+P = {}", "- P[A[i][j]] = [i, j]", "-Accum = [0] * (H * W + 1)", "-accum = 0", "-for i in range(D + 1, H * W + 1):", "- Accum[i] = Accum[i - D] + abs(P[i][0] - P[i - D][0]) + abs(P[i][1] - P[i - D][1])", "-for s in S:", "- print((Accum[s[1]] - Accum[s[0]]))", "+ P[A[i][j] - 1] = (i, j)", "+cum = [0] * (H * W + 1)", "+for a in range(H * W - D):", "+ i, j = P[a]", "+ x, y = P[a + D]", "+ cum[a + D] = cum[a] + abs(x - i) + abs(y - j)", "+Q = int(eval(input()))", "+ans = []", "+for _ in range(Q):", "+ l, r = list(map(int, input().split()))", "+ ans.append(cum[r - 1] - cum[l - 1])", "+print((\"\\n\".join(map(str, ans))))" ]
false
0.042855
0.04391
0.97597
[ "s767456531", "s764640811" ]
u855694108
p02389
python
s084617491
s946804543
60
20
7,696
5,584
Accepted
Accepted
66.67
def main(): a, b = list(map(int, input().split())) print((a * b, 2 * (a + b))) if __name__ == "__main__": main()
a,b=list(map(int,input().split())) print((a*b, (a+b)*2))
6
2
122
50
def main(): a, b = list(map(int, input().split())) print((a * b, 2 * (a + b))) if __name__ == "__main__": main()
a, b = list(map(int, input().split())) print((a * b, (a + b) * 2))
false
66.666667
[ "-def main():", "- a, b = list(map(int, input().split()))", "- print((a * b, 2 * (a + b)))", "-", "-", "-if __name__ == \"__main__\":", "- main()", "+a, b = list(map(int, input().split()))", "+print((a * b, (a + b) * 2))" ]
false
0.035055
0.040374
0.868254
[ "s084617491", "s946804543" ]
u583455650
p02756
python
s025158656
s808805734
833
424
119,896
44,660
Accepted
Accepted
49.1
from collections import deque S = deque(eval(input())) Q = int(eval(input())) query = [input().split() for _ in range(Q)] reverse = False for q in query: if q[0] == '1': reverse = not reverse else: if q[1] == '1': if not reverse: S.appendleft(q[2]) else: S.append(q[2]) else: if not reverse: S.append(q[2]) else: S.appendleft(q[2]) if reverse: S.reverse() print((''.join(S)))
from collections import deque S = deque(eval(input())) Q = int(eval(input())) query = [input().split() for _ in range(Q)] reverse = False for q in query: if q[0] == '1': reverse = not reverse else: if q[1] == '1': S.append(q[2]) if reverse else S.appendleft(q[2]) else: S.appendleft(q[2]) if reverse else S.append(q[2]) if reverse: S.reverse() print((''.join(S)))
22
16
531
424
from collections import deque S = deque(eval(input())) Q = int(eval(input())) query = [input().split() for _ in range(Q)] reverse = False for q in query: if q[0] == "1": reverse = not reverse else: if q[1] == "1": if not reverse: S.appendleft(q[2]) else: S.append(q[2]) else: if not reverse: S.append(q[2]) else: S.appendleft(q[2]) if reverse: S.reverse() print(("".join(S)))
from collections import deque S = deque(eval(input())) Q = int(eval(input())) query = [input().split() for _ in range(Q)] reverse = False for q in query: if q[0] == "1": reverse = not reverse else: if q[1] == "1": S.append(q[2]) if reverse else S.appendleft(q[2]) else: S.appendleft(q[2]) if reverse else S.append(q[2]) if reverse: S.reverse() print(("".join(S)))
false
27.272727
[ "- if not reverse:", "- S.appendleft(q[2])", "- else:", "- S.append(q[2])", "+ S.append(q[2]) if reverse else S.appendleft(q[2])", "- if not reverse:", "- S.append(q[2])", "- else:", "- S.appendleft(q[2])", "+ S.appendleft(q[2]) if reverse else S.append(q[2])" ]
false
0.039686
0.03993
0.993884
[ "s025158656", "s808805734" ]
u394721319
p03163
python
s437218338
s077549573
672
323
171,656
20,656
Accepted
Accepted
51.93
n,k = [int(i) for i in input().split()] w = [] v = [] for _ in range(n): a,b = [int(i) for i in input().split()] w.append(a) v.append(b) dp = [[0 for _ in range(k+1)] for _ in range(n+1)] for i in range(n): for j in range(k+1): if j >= w[i]: dp[i+1][j] = max(dp[i][j-w[i]]+v[i], dp[i][j]) else: dp[i+1][j] = dp[i][j] print((dp[-1][-1]))
import numpy as np n,w = list(map(int, input().split())) items = list(list(map(int, input().split())) for _ in [0]*n) dp = np.zeros(w+1, dtype='int64') for weight, value in items: dp[weight:] = np.maximum(dp[weight:], dp[:w-weight+1] + value) print((dp.max()))
17
9
409
261
n, k = [int(i) for i in input().split()] w = [] v = [] for _ in range(n): a, b = [int(i) for i in input().split()] w.append(a) v.append(b) dp = [[0 for _ in range(k + 1)] for _ in range(n + 1)] for i in range(n): for j in range(k + 1): if j >= w[i]: dp[i + 1][j] = max(dp[i][j - w[i]] + v[i], dp[i][j]) else: dp[i + 1][j] = dp[i][j] print((dp[-1][-1]))
import numpy as np n, w = list(map(int, input().split())) items = list(list(map(int, input().split())) for _ in [0] * n) dp = np.zeros(w + 1, dtype="int64") for weight, value in items: dp[weight:] = np.maximum(dp[weight:], dp[: w - weight + 1] + value) print((dp.max()))
false
47.058824
[ "-n, k = [int(i) for i in input().split()]", "-w = []", "-v = []", "-for _ in range(n):", "- a, b = [int(i) for i in input().split()]", "- w.append(a)", "- v.append(b)", "-dp = [[0 for _ in range(k + 1)] for _ in range(n + 1)]", "-for i in range(n):", "- for j in range(k + 1):", "- if j >= w[i]:", "- dp[i + 1][j] = max(dp[i][j - w[i]] + v[i], dp[i][j])", "- else:", "- dp[i + 1][j] = dp[i][j]", "-print((dp[-1][-1]))", "+import numpy as np", "+", "+n, w = list(map(int, input().split()))", "+items = list(list(map(int, input().split())) for _ in [0] * n)", "+dp = np.zeros(w + 1, dtype=\"int64\")", "+for weight, value in items:", "+ dp[weight:] = np.maximum(dp[weight:], dp[: w - weight + 1] + value)", "+print((dp.max()))" ]
false
0.057023
0.328911
0.173369
[ "s437218338", "s077549573" ]
u991567869
p02784
python
s357580330
s793576363
57
43
13,964
13,964
Accepted
Accepted
24.56
h, n = list(map(int, input().split())) a = list(map(int, input().split())) at = 0 for i in range(n): at = at + a[i] if at >= h: print("Yes") else: print("No")
h, n = list(map(int, input().split())) a = list(map(int, input().split())) at = sum(a) if at >= h: print("Yes") else: print("No")
12
8
178
139
h, n = list(map(int, input().split())) a = list(map(int, input().split())) at = 0 for i in range(n): at = at + a[i] if at >= h: print("Yes") else: print("No")
h, n = list(map(int, input().split())) a = list(map(int, input().split())) at = sum(a) if at >= h: print("Yes") else: print("No")
false
33.333333
[ "-at = 0", "-for i in range(n):", "- at = at + a[i]", "+at = sum(a)" ]
false
0.036578
0.042531
0.860032
[ "s357580330", "s793576363" ]
u745087332
p03291
python
s145631915
s557421710
528
259
27,608
27,636
Accepted
Accepted
50.95
# coding:utf-8 import sys input = sys.stdin.readline INF = float('inf') MOD = 10 ** 9 + 7 def inpl(): return list(map(int, input().split())) S = input().rstrip() dp = [[0] * 4 for _ in range(len(S) + 1)] dp[0][0] = 1 # print(' ', dp[0][:]) for i in range(len(S)): # ABCカウントを更新しない for j in range(4): if S[i] != '?': dp[i + 1][j] += dp[i][j] else: dp[i + 1][j] += dp[i][j] * 3 dp[i + 1][j] %= MOD # ABCカウントを更新する if S[i] in ('A', '?'): dp[i + 1][1] += dp[i][0] if S[i] in ('B', '?'): dp[i + 1][2] += dp[i][1] if S[i] in ('C', '?'): dp[i + 1][3] += dp[i][2] for j in range(1, 4): dp[i + 1][j] %= MOD # print(S[i], dp[i + 1][:]) print((dp[-1][-1]))
# coding:utf-8 import sys input = sys.stdin.readline INF = float('inf') MOD = 10 ** 9 + 7 def inpl(): return list(map(int, input().split())) S = input().rstrip() dp = [[0] * 4 for _ in range(len(S) + 1)] dp[0][0] = 1 for i in range(len(S)): if S[i] == '?': dp[i + 1][0] = (dp[i][0] * 3) % MOD dp[i + 1][1] = (dp[i][1] * 3 + dp[i][0]) % MOD dp[i + 1][2] = (dp[i][2] * 3 + dp[i][1]) % MOD dp[i + 1][3] = (dp[i][3] * 3 + dp[i][2]) % MOD else: for j in range(4): dp[i + 1][j] = dp[i][j] if S[i] == 'A': dp[i + 1][1] = (dp[i + 1][1] + dp[i][0]) % MOD if S[i] == 'B': dp[i + 1][2] = (dp[i + 1][2] + dp[i][1]) % MOD if S[i] == 'C': dp[i + 1][3] = (dp[i + 1][3] + dp[i][2]) % MOD print((dp[-1][-1]))
39
35
781
854
# coding:utf-8 import sys input = sys.stdin.readline INF = float("inf") MOD = 10**9 + 7 def inpl(): return list(map(int, input().split())) S = input().rstrip() dp = [[0] * 4 for _ in range(len(S) + 1)] dp[0][0] = 1 # print(' ', dp[0][:]) for i in range(len(S)): # ABCカウントを更新しない for j in range(4): if S[i] != "?": dp[i + 1][j] += dp[i][j] else: dp[i + 1][j] += dp[i][j] * 3 dp[i + 1][j] %= MOD # ABCカウントを更新する if S[i] in ("A", "?"): dp[i + 1][1] += dp[i][0] if S[i] in ("B", "?"): dp[i + 1][2] += dp[i][1] if S[i] in ("C", "?"): dp[i + 1][3] += dp[i][2] for j in range(1, 4): dp[i + 1][j] %= MOD # print(S[i], dp[i + 1][:]) print((dp[-1][-1]))
# coding:utf-8 import sys input = sys.stdin.readline INF = float("inf") MOD = 10**9 + 7 def inpl(): return list(map(int, input().split())) S = input().rstrip() dp = [[0] * 4 for _ in range(len(S) + 1)] dp[0][0] = 1 for i in range(len(S)): if S[i] == "?": dp[i + 1][0] = (dp[i][0] * 3) % MOD dp[i + 1][1] = (dp[i][1] * 3 + dp[i][0]) % MOD dp[i + 1][2] = (dp[i][2] * 3 + dp[i][1]) % MOD dp[i + 1][3] = (dp[i][3] * 3 + dp[i][2]) % MOD else: for j in range(4): dp[i + 1][j] = dp[i][j] if S[i] == "A": dp[i + 1][1] = (dp[i + 1][1] + dp[i][0]) % MOD if S[i] == "B": dp[i + 1][2] = (dp[i + 1][2] + dp[i][1]) % MOD if S[i] == "C": dp[i + 1][3] = (dp[i + 1][3] + dp[i][2]) % MOD print((dp[-1][-1]))
false
10.25641
[ "-# print(' ', dp[0][:])", "- # ABCカウントを更新しない", "- for j in range(4):", "- if S[i] != \"?\":", "- dp[i + 1][j] += dp[i][j]", "- else:", "- dp[i + 1][j] += dp[i][j] * 3", "- dp[i + 1][j] %= MOD", "- # ABCカウントを更新する", "- if S[i] in (\"A\", \"?\"):", "- dp[i + 1][1] += dp[i][0]", "- if S[i] in (\"B\", \"?\"):", "- dp[i + 1][2] += dp[i][1]", "- if S[i] in (\"C\", \"?\"):", "- dp[i + 1][3] += dp[i][2]", "- for j in range(1, 4):", "- dp[i + 1][j] %= MOD", "- # print(S[i], dp[i + 1][:])", "+ if S[i] == \"?\":", "+ dp[i + 1][0] = (dp[i][0] * 3) % MOD", "+ dp[i + 1][1] = (dp[i][1] * 3 + dp[i][0]) % MOD", "+ dp[i + 1][2] = (dp[i][2] * 3 + dp[i][1]) % MOD", "+ dp[i + 1][3] = (dp[i][3] * 3 + dp[i][2]) % MOD", "+ else:", "+ for j in range(4):", "+ dp[i + 1][j] = dp[i][j]", "+ if S[i] == \"A\":", "+ dp[i + 1][1] = (dp[i + 1][1] + dp[i][0]) % MOD", "+ if S[i] == \"B\":", "+ dp[i + 1][2] = (dp[i + 1][2] + dp[i][1]) % MOD", "+ if S[i] == \"C\":", "+ dp[i + 1][3] = (dp[i + 1][3] + dp[i][2]) % MOD" ]
false
0.038752
0.088672
0.43703
[ "s145631915", "s557421710" ]
u114954806
p02923
python
s635491807
s478380139
108
99
14,528
14,528
Accepted
Accepted
8.33
from itertools import groupby N=int(eval(input())) H=list(map(int,input().split())) New=[] _max=0 for _ in range(N-1): if H[_]>=H[_+1]: New.append(1) else: New.append(0) for k,h in groupby(New): _sum=sum(list(h)) if k==1 and _sum>_max: _max=_sum print(_max)
from itertools import groupby N=int(eval(input())) H=list(map(int,input().split())) New=[1 if H[_]>=H[_+1] else 0 for _ in range(N-1)] _max=0 for k,h in groupby(New): _sum=sum(list(h)) if k==1 and _sum>_max: _max=_sum print(_max)
16
11
308
251
from itertools import groupby N = int(eval(input())) H = list(map(int, input().split())) New = [] _max = 0 for _ in range(N - 1): if H[_] >= H[_ + 1]: New.append(1) else: New.append(0) for k, h in groupby(New): _sum = sum(list(h)) if k == 1 and _sum > _max: _max = _sum print(_max)
from itertools import groupby N = int(eval(input())) H = list(map(int, input().split())) New = [1 if H[_] >= H[_ + 1] else 0 for _ in range(N - 1)] _max = 0 for k, h in groupby(New): _sum = sum(list(h)) if k == 1 and _sum > _max: _max = _sum print(_max)
false
31.25
[ "-New = []", "+New = [1 if H[_] >= H[_ + 1] else 0 for _ in range(N - 1)]", "-for _ in range(N - 1):", "- if H[_] >= H[_ + 1]:", "- New.append(1)", "- else:", "- New.append(0)" ]
false
0.041253
0.048317
0.853807
[ "s635491807", "s478380139" ]
u391731808
p03049
python
s030814285
s274218007
312
34
46,168
3,700
Accepted
Accepted
89.1
N = int(eval(input())) s = [eval(input()) for _ in [0]*N] ni = [0]*N for i,si in enumerate(s): for j,c in enumerate(si[:-1]): if c == "A" and si[j+1] == "B": ni[i] += 1 cntA,cntB,cntAB = 0,0,0 for si in s: if si[0]=="B" and si[-1]=="A": cntAB += 1 elif si[0]=="B": cntB += 1 elif si[-1]=="A": cntA += 1 ans = sum(ni) + max(0,cntAB - (cntA==0 and cntB==0)) + min(cntA,cntB) print(ans)
N = int(eval(input())) S = [eval(input()) for _ in [0]*N] ans = 0 BA = 0 BX = 0 XA = 0 for s in S: ans += s.count("AB") if s[0]=="B" and s[-1]=="A":BA+=1 elif s[0]=="B":BX+=1 elif s[-1]=="A":XA+=1 ans += min(BX,XA) + max(0,BA - (BX==XA==0)) print(ans)
17
14
447
269
N = int(eval(input())) s = [eval(input()) for _ in [0] * N] ni = [0] * N for i, si in enumerate(s): for j, c in enumerate(si[:-1]): if c == "A" and si[j + 1] == "B": ni[i] += 1 cntA, cntB, cntAB = 0, 0, 0 for si in s: if si[0] == "B" and si[-1] == "A": cntAB += 1 elif si[0] == "B": cntB += 1 elif si[-1] == "A": cntA += 1 ans = sum(ni) + max(0, cntAB - (cntA == 0 and cntB == 0)) + min(cntA, cntB) print(ans)
N = int(eval(input())) S = [eval(input()) for _ in [0] * N] ans = 0 BA = 0 BX = 0 XA = 0 for s in S: ans += s.count("AB") if s[0] == "B" and s[-1] == "A": BA += 1 elif s[0] == "B": BX += 1 elif s[-1] == "A": XA += 1 ans += min(BX, XA) + max(0, BA - (BX == XA == 0)) print(ans)
false
17.647059
[ "-s = [eval(input()) for _ in [0] * N]", "-ni = [0] * N", "-for i, si in enumerate(s):", "- for j, c in enumerate(si[:-1]):", "- if c == \"A\" and si[j + 1] == \"B\":", "- ni[i] += 1", "-cntA, cntB, cntAB = 0, 0, 0", "-for si in s:", "- if si[0] == \"B\" and si[-1] == \"A\":", "- cntAB += 1", "- elif si[0] == \"B\":", "- cntB += 1", "- elif si[-1] == \"A\":", "- cntA += 1", "-ans = sum(ni) + max(0, cntAB - (cntA == 0 and cntB == 0)) + min(cntA, cntB)", "+S = [eval(input()) for _ in [0] * N]", "+ans = 0", "+BA = 0", "+BX = 0", "+XA = 0", "+for s in S:", "+ ans += s.count(\"AB\")", "+ if s[0] == \"B\" and s[-1] == \"A\":", "+ BA += 1", "+ elif s[0] == \"B\":", "+ BX += 1", "+ elif s[-1] == \"A\":", "+ XA += 1", "+ans += min(BX, XA) + max(0, BA - (BX == XA == 0))" ]
false
0.124701
0.048521
2.570016
[ "s030814285", "s274218007" ]
u780962115
p03291
python
s824749890
s760534985
358
191
40,364
21,372
Accepted
Accepted
46.65
#we love abc s=eval(input()) mod=10**9+7 dpa=[[0,0] for i in range(len(s)+1)] dpc=[[0,0] for i in range(len(s)+1)] power3=[1 for i in range(10**5+100)] for i in range(10**5+3): power3[i+1]=(power3[i]*3)%mod for i in range(len(s)): if s[i]=="A": dpa[i+1][0]=(dpa[i][0]+power3[dpa[i][1]])%mod dpa[i+1][1]=dpa[i][1] elif s[i]=="?": dpa[i+1][0]=(3*dpa[i][0]+power3[dpa[i][1]])%mod dpa[i+1][1]=dpa[i][1]+1 else: dpa[i+1]=dpa[i] for i in range(len(s)): if s[len(s)-1-i]=="C": dpc[i+1][0]=(dpc[i][0]+power3[dpc[i][1]])%mod dpc[i+1][1]=dpc[i][1] elif s[len(s)-1-i]=="?": dpc[i+1][0]=(3*dpc[i][0]+power3[dpc[i][1]])%mod dpc[i+1][1]=dpc[i][1]+1 else: dpc[i+1]=dpc[i] ans=0 for i in range(1,len(s)-1): if s[i]=="B" or s[i]=="?": ans+=dpa[i][0]*dpc[len(s)-1-i][0] ans=ans%mod print(ans)
S = list(eval(input())) n = len(S) mod = 10**9 + 7 dpa = [0]*(10**5+10) dpc = [0]*(10**5+10) hatena_count = 0 pow3 = [1]*(10**5+10) for i in range(1, 10**5+10): pow3[i] = pow3[i-1]*3 % mod for i in range(n): if S[i] == "A": dpa[i+1] = (dpa[i] + pow3[hatena_count]) % mod elif S[i] == "?": dpa[i+1] = (3*dpa[i] + pow3[hatena_count]) % mod hatena_count += 1 else: dpa[i+1] = dpa[i] S.reverse() hatena_count = 0 for i in range(n): if S[i] == "C": dpc[i+1] = (dpc[i] + pow3[hatena_count]) % mod elif S[i] == "?": dpc[i+1] = (3*dpc[i] + pow3[hatena_count]) % mod hatena_count += 1 else: dpc[i+1] = dpc[i] ans = 0 for i in range(1, n - 1): if S[i] == "B" or S[i] == "?": ans += dpa[n-1-i]*dpc[i] ans %= mod print(ans)
32
42
941
868
# we love abc s = eval(input()) mod = 10**9 + 7 dpa = [[0, 0] for i in range(len(s) + 1)] dpc = [[0, 0] for i in range(len(s) + 1)] power3 = [1 for i in range(10**5 + 100)] for i in range(10**5 + 3): power3[i + 1] = (power3[i] * 3) % mod for i in range(len(s)): if s[i] == "A": dpa[i + 1][0] = (dpa[i][0] + power3[dpa[i][1]]) % mod dpa[i + 1][1] = dpa[i][1] elif s[i] == "?": dpa[i + 1][0] = (3 * dpa[i][0] + power3[dpa[i][1]]) % mod dpa[i + 1][1] = dpa[i][1] + 1 else: dpa[i + 1] = dpa[i] for i in range(len(s)): if s[len(s) - 1 - i] == "C": dpc[i + 1][0] = (dpc[i][0] + power3[dpc[i][1]]) % mod dpc[i + 1][1] = dpc[i][1] elif s[len(s) - 1 - i] == "?": dpc[i + 1][0] = (3 * dpc[i][0] + power3[dpc[i][1]]) % mod dpc[i + 1][1] = dpc[i][1] + 1 else: dpc[i + 1] = dpc[i] ans = 0 for i in range(1, len(s) - 1): if s[i] == "B" or s[i] == "?": ans += dpa[i][0] * dpc[len(s) - 1 - i][0] ans = ans % mod print(ans)
S = list(eval(input())) n = len(S) mod = 10**9 + 7 dpa = [0] * (10**5 + 10) dpc = [0] * (10**5 + 10) hatena_count = 0 pow3 = [1] * (10**5 + 10) for i in range(1, 10**5 + 10): pow3[i] = pow3[i - 1] * 3 % mod for i in range(n): if S[i] == "A": dpa[i + 1] = (dpa[i] + pow3[hatena_count]) % mod elif S[i] == "?": dpa[i + 1] = (3 * dpa[i] + pow3[hatena_count]) % mod hatena_count += 1 else: dpa[i + 1] = dpa[i] S.reverse() hatena_count = 0 for i in range(n): if S[i] == "C": dpc[i + 1] = (dpc[i] + pow3[hatena_count]) % mod elif S[i] == "?": dpc[i + 1] = (3 * dpc[i] + pow3[hatena_count]) % mod hatena_count += 1 else: dpc[i + 1] = dpc[i] ans = 0 for i in range(1, n - 1): if S[i] == "B" or S[i] == "?": ans += dpa[n - 1 - i] * dpc[i] ans %= mod print(ans)
false
23.809524
[ "-# we love abc", "-s = eval(input())", "+S = list(eval(input()))", "+n = len(S)", "-dpa = [[0, 0] for i in range(len(s) + 1)]", "-dpc = [[0, 0] for i in range(len(s) + 1)]", "-power3 = [1 for i in range(10**5 + 100)]", "-for i in range(10**5 + 3):", "- power3[i + 1] = (power3[i] * 3) % mod", "-for i in range(len(s)):", "- if s[i] == \"A\":", "- dpa[i + 1][0] = (dpa[i][0] + power3[dpa[i][1]]) % mod", "- dpa[i + 1][1] = dpa[i][1]", "- elif s[i] == \"?\":", "- dpa[i + 1][0] = (3 * dpa[i][0] + power3[dpa[i][1]]) % mod", "- dpa[i + 1][1] = dpa[i][1] + 1", "+dpa = [0] * (10**5 + 10)", "+dpc = [0] * (10**5 + 10)", "+hatena_count = 0", "+pow3 = [1] * (10**5 + 10)", "+for i in range(1, 10**5 + 10):", "+ pow3[i] = pow3[i - 1] * 3 % mod", "+for i in range(n):", "+ if S[i] == \"A\":", "+ dpa[i + 1] = (dpa[i] + pow3[hatena_count]) % mod", "+ elif S[i] == \"?\":", "+ dpa[i + 1] = (3 * dpa[i] + pow3[hatena_count]) % mod", "+ hatena_count += 1", "-for i in range(len(s)):", "- if s[len(s) - 1 - i] == \"C\":", "- dpc[i + 1][0] = (dpc[i][0] + power3[dpc[i][1]]) % mod", "- dpc[i + 1][1] = dpc[i][1]", "- elif s[len(s) - 1 - i] == \"?\":", "- dpc[i + 1][0] = (3 * dpc[i][0] + power3[dpc[i][1]]) % mod", "- dpc[i + 1][1] = dpc[i][1] + 1", "+S.reverse()", "+hatena_count = 0", "+for i in range(n):", "+ if S[i] == \"C\":", "+ dpc[i + 1] = (dpc[i] + pow3[hatena_count]) % mod", "+ elif S[i] == \"?\":", "+ dpc[i + 1] = (3 * dpc[i] + pow3[hatena_count]) % mod", "+ hatena_count += 1", "-for i in range(1, len(s) - 1):", "- if s[i] == \"B\" or s[i] == \"?\":", "- ans += dpa[i][0] * dpc[len(s) - 1 - i][0]", "- ans = ans % mod", "+for i in range(1, n - 1):", "+ if S[i] == \"B\" or S[i] == \"?\":", "+ ans += dpa[n - 1 - i] * dpc[i]", "+ ans %= mod" ]
false
0.042577
0.060939
0.698685
[ "s824749890", "s760534985" ]
u644907318
p03588
python
s268606914
s659254635
725
325
65,372
95,036
Accepted
Accepted
55.17
N = int(eval(input())) A = sorted([list(map(int,input().split())) for _ in range(N)],key=lambda x:x[0]) a = A[-1][0] b = A[-1][1] print((a+b))
N = int(eval(input())) A = sorted([list(map(int,input().split())) for _ in range(N)],key=lambda x:x[0]) a,b = A[-1] print((a+b))
5
4
138
123
N = int(eval(input())) A = sorted([list(map(int, input().split())) for _ in range(N)], key=lambda x: x[0]) a = A[-1][0] b = A[-1][1] print((a + b))
N = int(eval(input())) A = sorted([list(map(int, input().split())) for _ in range(N)], key=lambda x: x[0]) a, b = A[-1] print((a + b))
false
20
[ "-a = A[-1][0]", "-b = A[-1][1]", "+a, b = A[-1]" ]
false
0.034614
0.040837
0.847616
[ "s268606914", "s659254635" ]
u600402037
p02851
python
s786658234
s089239333
405
364
39,640
43,364
Accepted
Accepted
10.12
import sys import numpy as np from collections import defaultdict sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) N, K = lr() A = np.array([0] + lr()) A = (A-1) % K Acum = A.cumsum() % K counter = defaultdict(int) answer = 0 for i, x in enumerate(Acum): answer += counter[x] counter[x] += 1 if i >= K-1: counter[Acum[i-(K-1)]] -= 1 print(answer)
import sys import numpy as np from collections import defaultdict sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) N, K = lr() A = np.array([1] + lr()) A = (A-1) % K N += 1 # 累積和が同じになっている箇所に注目、要素がK-1離れている組み合わせは無理 Acum = (A.cumsum() % K).tolist() answer = 0 dic = defaultdict(int) for i, cur in enumerate(Acum): answer += dic[cur] dic[cur] += 1 if i >= K-1: vanish = Acum[i-(K-1)] dic[vanish] -= 1 print(answer) # 10
21
25
449
530
import sys import numpy as np from collections import defaultdict sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) N, K = lr() A = np.array([0] + lr()) A = (A - 1) % K Acum = A.cumsum() % K counter = defaultdict(int) answer = 0 for i, x in enumerate(Acum): answer += counter[x] counter[x] += 1 if i >= K - 1: counter[Acum[i - (K - 1)]] -= 1 print(answer)
import sys import numpy as np from collections import defaultdict sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) N, K = lr() A = np.array([1] + lr()) A = (A - 1) % K N += 1 # 累積和が同じになっている箇所に注目、要素がK-1離れている組み合わせは無理 Acum = (A.cumsum() % K).tolist() answer = 0 dic = defaultdict(int) for i, cur in enumerate(Acum): answer += dic[cur] dic[cur] += 1 if i >= K - 1: vanish = Acum[i - (K - 1)] dic[vanish] -= 1 print(answer) # 10
false
16
[ "-A = np.array([0] + lr())", "+A = np.array([1] + lr())", "-Acum = A.cumsum() % K", "-counter = defaultdict(int)", "+N += 1", "+# 累積和が同じになっている箇所に注目、要素がK-1離れている組み合わせは無理", "+Acum = (A.cumsum() % K).tolist()", "-for i, x in enumerate(Acum):", "- answer += counter[x]", "- counter[x] += 1", "+dic = defaultdict(int)", "+for i, cur in enumerate(Acum):", "+ answer += dic[cur]", "+ dic[cur] += 1", "- counter[Acum[i - (K - 1)]] -= 1", "+ vanish = Acum[i - (K - 1)]", "+ dic[vanish] -= 1", "+# 10" ]
false
0.221521
0.183425
1.20769
[ "s786658234", "s089239333" ]
u440551778
p03290
python
s545919269
s269014165
27
20
3,064
3,064
Accepted
Accepted
25.93
d, g = list(map(int, input().split())) pc = [tuple(map(int, input().split())) for i in range(d)] ans = float('inf') for i in range(2**d): sum = 0 cnt = 0 nokori = set(range(1, d+1)) for j in range(d): bitchk = 2**j if i & bitchk: sum += pc[j][0]*100*(j+1) + pc[j][1] cnt += pc[j][0] nokori.discard(j+1) if sum < g: use = max(nokori) # -(-(g-sum)//(use*100))は切り上げ除算 # pc[use-1][0]はその点数帯の問題数(解ける最大数) # -(-(g-sum)//(use*100))でgを超えるのに必要な問題数を出せる。 # ex) 300点問題が4問残ってるとする。不足している点数(g-sum)が500点のとき # -(-500//300)で2問解く必要があることがわかる。 n = min(pc[use-1][0], -(-(g-sum)//(use*100))) # n = (-(-(g-sum)//(use**100))) sum += n * use * 100 cnt += n if sum >= g: ans = min(ans, cnt) print(ans)
d, g = list(map(int, input().split())) pc = [tuple(map(int, input().split())) for i in range(d)] nokori = set(range(1, d+1)) def dfs(i, sum, nokori, cnt): global ans if i == d: if sum < g: use = max(nokori) n = min(pc[use-1][0], -(-(g-sum)//(use*100))) cnt += n sum += n * use*100 if sum >= g: ans = min(ans, cnt) else: dfs(i+1, sum, nokori, cnt) dfs(i+1, sum + pc[i][0] * (i+1) * 100 + pc[i][1], nokori-{i+1}, cnt+pc[i][0]) ans = float('inf') dfs(0, 0, nokori, 0) print(ans)
31
28
865
621
d, g = list(map(int, input().split())) pc = [tuple(map(int, input().split())) for i in range(d)] ans = float("inf") for i in range(2**d): sum = 0 cnt = 0 nokori = set(range(1, d + 1)) for j in range(d): bitchk = 2**j if i & bitchk: sum += pc[j][0] * 100 * (j + 1) + pc[j][1] cnt += pc[j][0] nokori.discard(j + 1) if sum < g: use = max(nokori) # -(-(g-sum)//(use*100))は切り上げ除算 # pc[use-1][0]はその点数帯の問題数(解ける最大数) # -(-(g-sum)//(use*100))でgを超えるのに必要な問題数を出せる。 # ex) 300点問題が4問残ってるとする。不足している点数(g-sum)が500点のとき # -(-500//300)で2問解く必要があることがわかる。 n = min(pc[use - 1][0], -(-(g - sum) // (use * 100))) # n = (-(-(g-sum)//(use**100))) sum += n * use * 100 cnt += n if sum >= g: ans = min(ans, cnt) print(ans)
d, g = list(map(int, input().split())) pc = [tuple(map(int, input().split())) for i in range(d)] nokori = set(range(1, d + 1)) def dfs(i, sum, nokori, cnt): global ans if i == d: if sum < g: use = max(nokori) n = min(pc[use - 1][0], -(-(g - sum) // (use * 100))) cnt += n sum += n * use * 100 if sum >= g: ans = min(ans, cnt) else: dfs(i + 1, sum, nokori, cnt) dfs( i + 1, sum + pc[i][0] * (i + 1) * 100 + pc[i][1], nokori - {i + 1}, cnt + pc[i][0], ) ans = float("inf") dfs(0, 0, nokori, 0) print(ans)
false
9.677419
[ "+nokori = set(range(1, d + 1))", "+", "+", "+def dfs(i, sum, nokori, cnt):", "+ global ans", "+ if i == d:", "+ if sum < g:", "+ use = max(nokori)", "+ n = min(pc[use - 1][0], -(-(g - sum) // (use * 100)))", "+ cnt += n", "+ sum += n * use * 100", "+ if sum >= g:", "+ ans = min(ans, cnt)", "+ else:", "+ dfs(i + 1, sum, nokori, cnt)", "+ dfs(", "+ i + 1,", "+ sum + pc[i][0] * (i + 1) * 100 + pc[i][1],", "+ nokori - {i + 1},", "+ cnt + pc[i][0],", "+ )", "+", "+", "-for i in range(2**d):", "- sum = 0", "- cnt = 0", "- nokori = set(range(1, d + 1))", "- for j in range(d):", "- bitchk = 2**j", "- if i & bitchk:", "- sum += pc[j][0] * 100 * (j + 1) + pc[j][1]", "- cnt += pc[j][0]", "- nokori.discard(j + 1)", "- if sum < g:", "- use = max(nokori)", "- # -(-(g-sum)//(use*100))は切り上げ除算", "- # pc[use-1][0]はその点数帯の問題数(解ける最大数)", "- # -(-(g-sum)//(use*100))でgを超えるのに必要な問題数を出せる。", "- # ex) 300点問題が4問残ってるとする。不足している点数(g-sum)が500点のとき", "- # -(-500//300)で2問解く必要があることがわかる。", "- n = min(pc[use - 1][0], -(-(g - sum) // (use * 100)))", "- # n = (-(-(g-sum)//(use**100)))", "- sum += n * use * 100", "- cnt += n", "- if sum >= g:", "- ans = min(ans, cnt)", "+dfs(0, 0, nokori, 0)" ]
false
0.04396
0.040591
1.082995
[ "s545919269", "s269014165" ]
u896451538
p02765
python
s853640030
s518386546
45
17
5,328
2,940
Accepted
Accepted
62.22
import math import itertools import fractions import heapq import collections import bisect import sys import copy sys.setrecursionlimit(10**9) mod = 10**7+9 inf = 10**20 def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return eval(input()) n,r = LI() if n<10: print((r+(100*(10-n)))) else: print(r)
n,r = list(map(int,input().split())) if n>=10: print(r) else: t = 100*(10-n) print((r+t))
27
7
692
106
import math import itertools import fractions import heapq import collections import bisect import sys import copy sys.setrecursionlimit(10**9) mod = 10**7 + 9 inf = 10**20 def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()] def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return eval(input()) n, r = LI() if n < 10: print((r + (100 * (10 - n)))) else: print(r)
n, r = list(map(int, input().split())) if n >= 10: print(r) else: t = 100 * (10 - n) print((r + t))
false
74.074074
[ "-import math", "-import itertools", "-import fractions", "-import heapq", "-import collections", "-import bisect", "-import sys", "-import copy", "-", "-sys.setrecursionlimit(10**9)", "-mod = 10**7 + 9", "-inf = 10**20", "-", "-", "-def LI():", "- return list(map(int, sys.stdin.readline().split()))", "-", "-", "-def LLI():", "- return [list(map(int, l.split())) for l in sys.stdin.readlines()]", "-", "-", "-def LI_():", "- return [int(x) - 1 for x in sys.stdin.readline().split()]", "-", "-", "-def LF():", "- return [float(x) for x in sys.stdin.readline().split()]", "-", "-", "-def LS():", "- return sys.stdin.readline().split()", "-", "-", "-def I():", "- return int(sys.stdin.readline())", "-", "-", "-def F():", "- return float(sys.stdin.readline())", "-", "-", "-def S():", "- return eval(input())", "-", "-", "-n, r = LI()", "-if n < 10:", "- print((r + (100 * (10 - n))))", "+n, r = list(map(int, input().split()))", "+if n >= 10:", "+ print(r)", "- print(r)", "+ t = 100 * (10 - n)", "+ print((r + t))" ]
false
0.094668
0.034849
2.716524
[ "s853640030", "s518386546" ]
u891635666
p02999
python
s481182366
s436345331
182
17
38,256
3,064
Accepted
Accepted
90.66
x, a = list(map(int, input().split())) if x < a: print((0)) else: print((10))
import sys input = sys.stdin.readline ri = lambda: int(eval(input())) rs = lambda: input().rstrip() ril = lambda: list(map(int, input().split())) rsl = lambda: input().rstrip().split() ris = lambda n: [ri() for _ in range(n)] rss = lambda n: [rs() for _ in range(n)] rils = lambda n: [ril() for _ in range(n)] rsls = lambda n: [rsl() for _ in range(n)] x, a = ril() print((0 if x < a else 10))
5
15
79
402
x, a = list(map(int, input().split())) if x < a: print((0)) else: print((10))
import sys input = sys.stdin.readline ri = lambda: int(eval(input())) rs = lambda: input().rstrip() ril = lambda: list(map(int, input().split())) rsl = lambda: input().rstrip().split() ris = lambda n: [ri() for _ in range(n)] rss = lambda n: [rs() for _ in range(n)] rils = lambda n: [ril() for _ in range(n)] rsls = lambda n: [rsl() for _ in range(n)] x, a = ril() print((0 if x < a else 10))
false
66.666667
[ "-x, a = list(map(int, input().split()))", "-if x < a:", "- print((0))", "-else:", "- print((10))", "+import sys", "+", "+input = sys.stdin.readline", "+ri = lambda: int(eval(input()))", "+rs = lambda: input().rstrip()", "+ril = lambda: list(map(int, input().split()))", "+rsl = lambda: input().rstrip().split()", "+ris = lambda n: [ri() for _ in range(n)]", "+rss = lambda n: [rs() for _ in range(n)]", "+rils = lambda n: [ril() for _ in range(n)]", "+rsls = lambda n: [rsl() for _ in range(n)]", "+x, a = ril()", "+print((0 if x < a else 10))" ]
false
0.036568
0.031314
1.167809
[ "s481182366", "s436345331" ]
u489959379
p02901
python
s336273757
s958087866
1,600
1,410
3,296
3,316
Accepted
Accepted
11.88
import sys sys.setrecursionlimit(10 ** 7) f_inf = float('inf') mod = 10 ** 9 + 7 def resolve(): n, m = list(map(int, input().split())) ABC = [] for _ in range(m): a, b = list(map(int, input().split())) C = list(map(int, input().split())) s = ["0"] * n for c in C: s[c - 1] = "1" c = "".join(s[::-1]) ABC.append([a, b, int(c, 2)]) dp = [f_inf for _ in range(1 << n)] dp[0] = 0 for a, b, c in ABC: for i in range(1 << n): idx = i | c dp[idx] = min(dp[idx], dp[i] + a) if dp[-1] == f_inf: print((-1)) else: print((dp[-1])) if __name__ == '__main__': resolve()
import sys sys.setrecursionlimit(10 ** 7) f_inf = float('inf') mod = 10 ** 9 + 7 def resolve(): n, m = list(map(int, input().split())) ABC = [] for _ in range(m): a, b = list(map(int, input().split())) C = list(map(int, input().split())) bit = ["0"] * n for c in C: bit[c - 1] = "1" bit = "".join(bit) ABC.append([a, b, int(bit, 2)]) dp = [f_inf for _ in range(1 << n)] dp[0] = 0 for i in range(1 << n): for a, b, c in ABC: idx = i | c dp[idx] = min(dp[idx], dp[i] + a) if dp[-1] != f_inf: print((dp[-1])) else: print((-1)) if __name__ == '__main__': resolve()
35
35
727
731
import sys sys.setrecursionlimit(10**7) f_inf = float("inf") mod = 10**9 + 7 def resolve(): n, m = list(map(int, input().split())) ABC = [] for _ in range(m): a, b = list(map(int, input().split())) C = list(map(int, input().split())) s = ["0"] * n for c in C: s[c - 1] = "1" c = "".join(s[::-1]) ABC.append([a, b, int(c, 2)]) dp = [f_inf for _ in range(1 << n)] dp[0] = 0 for a, b, c in ABC: for i in range(1 << n): idx = i | c dp[idx] = min(dp[idx], dp[i] + a) if dp[-1] == f_inf: print((-1)) else: print((dp[-1])) if __name__ == "__main__": resolve()
import sys sys.setrecursionlimit(10**7) f_inf = float("inf") mod = 10**9 + 7 def resolve(): n, m = list(map(int, input().split())) ABC = [] for _ in range(m): a, b = list(map(int, input().split())) C = list(map(int, input().split())) bit = ["0"] * n for c in C: bit[c - 1] = "1" bit = "".join(bit) ABC.append([a, b, int(bit, 2)]) dp = [f_inf for _ in range(1 << n)] dp[0] = 0 for i in range(1 << n): for a, b, c in ABC: idx = i | c dp[idx] = min(dp[idx], dp[i] + a) if dp[-1] != f_inf: print((dp[-1])) else: print((-1)) if __name__ == "__main__": resolve()
false
0
[ "- s = [\"0\"] * n", "+ bit = [\"0\"] * n", "- s[c - 1] = \"1\"", "- c = \"\".join(s[::-1])", "- ABC.append([a, b, int(c, 2)])", "+ bit[c - 1] = \"1\"", "+ bit = \"\".join(bit)", "+ ABC.append([a, b, int(bit, 2)])", "- for a, b, c in ABC:", "- for i in range(1 << n):", "+ for i in range(1 << n):", "+ for a, b, c in ABC:", "- if dp[-1] == f_inf:", "+ if dp[-1] != f_inf:", "+ print((dp[-1]))", "+ else:", "- else:", "- print((dp[-1]))" ]
false
0.037985
0.036485
1.041113
[ "s336273757", "s958087866" ]
u724687935
p02820
python
s946298215
s426537752
287
196
58,604
47,084
Accepted
Accepted
31.71
N, K = list(map(int, input().split())) R, S, P = list(map(int, input().split())) # R=0, S=1, P=2 T = eval(input()) _score = {'r': P, 's': R, 'p': S} s = [P, R, S] hand = {'r': 0, 's': 1, 'p': 2} H = [' '] * N dp = [[0] * 3 for _ in range(N + 1)] for sub in range(1, K + 1): i = sub while i <= N: h = hand[T[i - 1]] for j in range(3): score = s[j] if j == h else 0 dp[i][j] = max(dp[max(i - K, 0)][(j + 1) % 3], dp[max(i - K, 0)][(j + 2) % 3]) + score i += K ans = 0 for k in range(K): ans += max(dp[N - k]) print(ans)
N, K = list(map(int, input().split())) R, S, P = list(map(int, input().split())) score = {'r': R, 's': S, 'p': P} T = eval(input()) hand = {'r': 'p', 's': 'r', 'p': 's'} history = [] cnt = 0 for i, t in enumerate(T): if i < K: u = hand[t] flag = 1 elif K <= i < N - K: l = i - K r = i + K if hand[t] == history[l]: u = T[r] flag = 0 else: u = hand[t] flag = 1 else: l = i - K if hand[t] == history[l]: u = t flag = 0 else: u = hand[t] flag = 1 cnt += score[u] * flag history.append(u) print(cnt)
24
33
588
700
N, K = list(map(int, input().split())) R, S, P = list(map(int, input().split())) # R=0, S=1, P=2 T = eval(input()) _score = {"r": P, "s": R, "p": S} s = [P, R, S] hand = {"r": 0, "s": 1, "p": 2} H = [" "] * N dp = [[0] * 3 for _ in range(N + 1)] for sub in range(1, K + 1): i = sub while i <= N: h = hand[T[i - 1]] for j in range(3): score = s[j] if j == h else 0 dp[i][j] = ( max(dp[max(i - K, 0)][(j + 1) % 3], dp[max(i - K, 0)][(j + 2) % 3]) + score ) i += K ans = 0 for k in range(K): ans += max(dp[N - k]) print(ans)
N, K = list(map(int, input().split())) R, S, P = list(map(int, input().split())) score = {"r": R, "s": S, "p": P} T = eval(input()) hand = {"r": "p", "s": "r", "p": "s"} history = [] cnt = 0 for i, t in enumerate(T): if i < K: u = hand[t] flag = 1 elif K <= i < N - K: l = i - K r = i + K if hand[t] == history[l]: u = T[r] flag = 0 else: u = hand[t] flag = 1 else: l = i - K if hand[t] == history[l]: u = t flag = 0 else: u = hand[t] flag = 1 cnt += score[u] * flag history.append(u) print(cnt)
false
27.272727
[ "-R, S, P = list(map(int, input().split())) # R=0, S=1, P=2", "+R, S, P = list(map(int, input().split()))", "+score = {\"r\": R, \"s\": S, \"p\": P}", "-_score = {\"r\": P, \"s\": R, \"p\": S}", "-s = [P, R, S]", "-hand = {\"r\": 0, \"s\": 1, \"p\": 2}", "-H = [\" \"] * N", "-dp = [[0] * 3 for _ in range(N + 1)]", "-for sub in range(1, K + 1):", "- i = sub", "- while i <= N:", "- h = hand[T[i - 1]]", "- for j in range(3):", "- score = s[j] if j == h else 0", "- dp[i][j] = (", "- max(dp[max(i - K, 0)][(j + 1) % 3], dp[max(i - K, 0)][(j + 2) % 3])", "- + score", "- )", "- i += K", "-ans = 0", "-for k in range(K):", "- ans += max(dp[N - k])", "-print(ans)", "+hand = {\"r\": \"p\", \"s\": \"r\", \"p\": \"s\"}", "+history = []", "+cnt = 0", "+for i, t in enumerate(T):", "+ if i < K:", "+ u = hand[t]", "+ flag = 1", "+ elif K <= i < N - K:", "+ l = i - K", "+ r = i + K", "+ if hand[t] == history[l]:", "+ u = T[r]", "+ flag = 0", "+ else:", "+ u = hand[t]", "+ flag = 1", "+ else:", "+ l = i - K", "+ if hand[t] == history[l]:", "+ u = t", "+ flag = 0", "+ else:", "+ u = hand[t]", "+ flag = 1", "+ cnt += score[u] * flag", "+ history.append(u)", "+print(cnt)" ]
false
0.048533
0.074024
0.655638
[ "s946298215", "s426537752" ]
u506858457
p02850
python
s909539664
s925588443
714
416
48,004
65,696
Accepted
Accepted
41.74
from collections import deque n = int(eval(input())) adj = [[] for i in range(n)] for i in range(n-1): a,b = list(map(int,input().split())) adj[a-1].append([b-1,i]) adj[b-1].append([a-1,i]) mx_color = 0 for i in range(n): mx_color = max(mx_color,len(adj[i])) dist = [-1]*n res = [-1]*(n-1) q = deque([]) q.append([0,-1]) dist[0] = 0 while len(q) > 0: v,c = q.popleft() color = 1 if color == c: color += 1 for nv,nc in adj[v]: if dist[nv] == -1: dist[nv] = dist[v] + 1 q.append([nv,color]) res[nc] = color color += 1 if color == c: color += 1 print(mx_color) for i in res: print(i)
import sys n = int(eval(input())) links = [set() for _ in range(n)] for i, line in enumerate(sys.stdin): a, b = list(map(int, line.split())) a -= 1 b -= 1 links[a].add((i, b)) links[b].add((i, a)) ans = [-1] * (n - 1) k = max(list(map(len, links))) q = [(0, -1)] fixed = set() while q: v, c = q.pop() color = 1 if c == color: color += 1 for i, u in links[v]: if ans[i] != -1: continue ans[i] = color q.append((u, color)) color += 1 if c == color: color += 1 print(k) print(('\n'.join(map(str, ans))))
42
32
765
627
from collections import deque n = int(eval(input())) adj = [[] for i in range(n)] for i in range(n - 1): a, b = list(map(int, input().split())) adj[a - 1].append([b - 1, i]) adj[b - 1].append([a - 1, i]) mx_color = 0 for i in range(n): mx_color = max(mx_color, len(adj[i])) dist = [-1] * n res = [-1] * (n - 1) q = deque([]) q.append([0, -1]) dist[0] = 0 while len(q) > 0: v, c = q.popleft() color = 1 if color == c: color += 1 for nv, nc in adj[v]: if dist[nv] == -1: dist[nv] = dist[v] + 1 q.append([nv, color]) res[nc] = color color += 1 if color == c: color += 1 print(mx_color) for i in res: print(i)
import sys n = int(eval(input())) links = [set() for _ in range(n)] for i, line in enumerate(sys.stdin): a, b = list(map(int, line.split())) a -= 1 b -= 1 links[a].add((i, b)) links[b].add((i, a)) ans = [-1] * (n - 1) k = max(list(map(len, links))) q = [(0, -1)] fixed = set() while q: v, c = q.pop() color = 1 if c == color: color += 1 for i, u in links[v]: if ans[i] != -1: continue ans[i] = color q.append((u, color)) color += 1 if c == color: color += 1 print(k) print(("\n".join(map(str, ans))))
false
23.809524
[ "-from collections import deque", "+import sys", "-adj = [[] for i in range(n)]", "-for i in range(n - 1):", "- a, b = list(map(int, input().split()))", "- adj[a - 1].append([b - 1, i])", "- adj[b - 1].append([a - 1, i])", "-mx_color = 0", "-for i in range(n):", "- mx_color = max(mx_color, len(adj[i]))", "-dist = [-1] * n", "-res = [-1] * (n - 1)", "-q = deque([])", "-q.append([0, -1])", "-dist[0] = 0", "-while len(q) > 0:", "- v, c = q.popleft()", "+links = [set() for _ in range(n)]", "+for i, line in enumerate(sys.stdin):", "+ a, b = list(map(int, line.split()))", "+ a -= 1", "+ b -= 1", "+ links[a].add((i, b))", "+ links[b].add((i, a))", "+ans = [-1] * (n - 1)", "+k = max(list(map(len, links)))", "+q = [(0, -1)]", "+fixed = set()", "+while q:", "+ v, c = q.pop()", "- if color == c:", "+ if c == color:", "- for nv, nc in adj[v]:", "- if dist[nv] == -1:", "- dist[nv] = dist[v] + 1", "- q.append([nv, color])", "- res[nc] = color", "+ for i, u in links[v]:", "+ if ans[i] != -1:", "+ continue", "+ ans[i] = color", "+ q.append((u, color))", "+ color += 1", "+ if c == color:", "- if color == c:", "- color += 1", "-print(mx_color)", "-for i in res:", "- print(i)", "+print(k)", "+print((\"\\n\".join(map(str, ans))))" ]
false
0.082087
0.114561
0.716535
[ "s909539664", "s925588443" ]
u318127926
p02540
python
s056175891
s462766830
748
650
38,820
37,320
Accepted
Accepted
13.1
n = int(input()) xy = [] idx = [None]*n ys = [None]*n ans = [None]*n accumx = [None]*n accumn = [None]*n for i in range(n): x, y = map(int, input().split()) idx[x-1] = i ys[x-1] = y-1 accumx[-1] = ys[-1] for i in range(n-2, -1, -1): accumx[i] = max(accumx[i+1], ys[i]) accumn[0] = ys[0] for i in range(1, n): accumn[i] = min(accumn[i-1], ys[i]) def bisect(x): ok = 0 ng = n while abs(ok-ng)>1: mid = (ok+ng)//2 if accumx[mid]>x: ok = mid else: ng = mid return ok nowx = 0 while nowx<n: nxtx = nowx tmp = bisect(ys[nowx]) while tmp>nxtx: nxtx = tmp tmp = bisect(accumn[nxtx]) if nxtx<nowx: nxtx = nowx for i in range(nowx, nxtx+1): ans[idx[i]] = nxtx-nowx+1 nowx = nxtx + 1 print(*ans, sep='\n')
n = int(input()) xy = [] idx = [None]*n ys = [None]*n ans = [None]*n accumn = [None]*n for i in range(n): x, y = map(int, input().split()) idx[x-1] = i ys[x-1] = y-1 accumn[0] = ys[0] for i in range(1, n): accumn[i] = min(accumn[i-1], ys[i]) b = 0 for i in range(n): if accumn[i]==n-i-1: for j in range(b, i+1): ans[idx[j]] = i-b+1 b = i+1 print(*ans, sep='\n')
42
21
877
430
n = int(input()) xy = [] idx = [None] * n ys = [None] * n ans = [None] * n accumx = [None] * n accumn = [None] * n for i in range(n): x, y = map(int, input().split()) idx[x - 1] = i ys[x - 1] = y - 1 accumx[-1] = ys[-1] for i in range(n - 2, -1, -1): accumx[i] = max(accumx[i + 1], ys[i]) accumn[0] = ys[0] for i in range(1, n): accumn[i] = min(accumn[i - 1], ys[i]) def bisect(x): ok = 0 ng = n while abs(ok - ng) > 1: mid = (ok + ng) // 2 if accumx[mid] > x: ok = mid else: ng = mid return ok nowx = 0 while nowx < n: nxtx = nowx tmp = bisect(ys[nowx]) while tmp > nxtx: nxtx = tmp tmp = bisect(accumn[nxtx]) if nxtx < nowx: nxtx = nowx for i in range(nowx, nxtx + 1): ans[idx[i]] = nxtx - nowx + 1 nowx = nxtx + 1 print(*ans, sep="\n")
n = int(input()) xy = [] idx = [None] * n ys = [None] * n ans = [None] * n accumn = [None] * n for i in range(n): x, y = map(int, input().split()) idx[x - 1] = i ys[x - 1] = y - 1 accumn[0] = ys[0] for i in range(1, n): accumn[i] = min(accumn[i - 1], ys[i]) b = 0 for i in range(n): if accumn[i] == n - i - 1: for j in range(b, i + 1): ans[idx[j]] = i - b + 1 b = i + 1 print(*ans, sep="\n")
false
50
[ "-accumx = [None] * n", "-accumx[-1] = ys[-1]", "-for i in range(n - 2, -1, -1):", "- accumx[i] = max(accumx[i + 1], ys[i])", "-", "-", "-def bisect(x):", "- ok = 0", "- ng = n", "- while abs(ok - ng) > 1:", "- mid = (ok + ng) // 2", "- if accumx[mid] > x:", "- ok = mid", "- else:", "- ng = mid", "- return ok", "-", "-", "-nowx = 0", "-while nowx < n:", "- nxtx = nowx", "- tmp = bisect(ys[nowx])", "- while tmp > nxtx:", "- nxtx = tmp", "- tmp = bisect(accumn[nxtx])", "- if nxtx < nowx:", "- nxtx = nowx", "- for i in range(nowx, nxtx + 1):", "- ans[idx[i]] = nxtx - nowx + 1", "- nowx = nxtx + 1", "+b = 0", "+for i in range(n):", "+ if accumn[i] == n - i - 1:", "+ for j in range(b, i + 1):", "+ ans[idx[j]] = i - b + 1", "+ b = i + 1" ]
false
0.047818
0.047174
1.013648
[ "s056175891", "s462766830" ]
u588341295
p03074
python
s649080949
s679173682
147
118
4,724
4,724
Accepted
Accepted
19.73
# -*- coding: utf-8 -*- import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) 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 N,K=MAP() S=eval(input()) L=[] cnt0=0 # 0始まりの時は番兵的に1の区間0を追加しておく if S[0]=='0': L.append(0) cur=0 else: cur=1 cnt=0 # 1の区間の長さ、0の区間の長さ、1の区間の長さ...の配列Lを作る for i in range(N): if cur==int(S[i]): cnt+=1 else: L.append(cnt) if cur==0: cnt0+=1 cnt=1 # フラグの切り替え cur=1-cur else: if cnt!=0: L.append(cnt) if cur==0: cnt0+=1 # 0終わりの時は番兵的に1の区間0を追加しておく if S[-1]=='0': L.append(0) if cnt0<K: # 0区間の数がKより少なかったら、それに合わせて区間和取る長さを短くする K=cnt0 # 尺取法 l=0 r=K*2+1 ans=sm=sum(L[:K*2+1]) while l<len(L) and r<len(L): for i in range(2): sm+=L[r] r+=1 sm-=L[l] l+=1 ans=max(ans, sm) print(ans)
# -*- coding: utf-8 -*- import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print('Yes') def No(): print('No') def YES(): print('YES') def NO(): print('NO') sys.setrecursionlimit(10 ** 9) INF = 10 ** 18 MOD = 10 ** 9 + 7 N, K = MAP() S = eval(input()) # ランレングス圧縮 A = [] # 番兵 if S[0] == '0': A.append(0) cur = S[0] cnt = 1 for i, s in enumerate(S[1:], 1): if s != cur: A.append(cnt) cnt = 1 cur = s else: cnt += 1 A.append(cnt) # 例外処理 if len(A) == 1: print(N) exit() # 番兵 if S[-1] == '0': A.append(0) M = len(A) ans = sm = sum(A[:K*2+1]) for i in range(K*2+1, M): sm += A[i] # 今回増やすのが0の区間なら、後ろ2つ減る if i % 2 == 1: if i-K*2 >= 0: sm -= A[i-K*2] if i-K*2-1 >= 0: sm -= A[i-K*2-1] ans = max(ans, sm) print(ans)
67
60
1,340
1,331
# -*- coding: utf-8 -*- import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) 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 N, K = MAP() S = eval(input()) L = [] cnt0 = 0 # 0始まりの時は番兵的に1の区間0を追加しておく if S[0] == "0": L.append(0) cur = 0 else: cur = 1 cnt = 0 # 1の区間の長さ、0の区間の長さ、1の区間の長さ...の配列Lを作る for i in range(N): if cur == int(S[i]): cnt += 1 else: L.append(cnt) if cur == 0: cnt0 += 1 cnt = 1 # フラグの切り替え cur = 1 - cur else: if cnt != 0: L.append(cnt) if cur == 0: cnt0 += 1 # 0終わりの時は番兵的に1の区間0を追加しておく if S[-1] == "0": L.append(0) if cnt0 < K: # 0区間の数がKより少なかったら、それに合わせて区間和取る長さを短くする K = cnt0 # 尺取法 l = 0 r = K * 2 + 1 ans = sm = sum(L[: K * 2 + 1]) while l < len(L) and r < len(L): for i in range(2): sm += L[r] r += 1 sm -= L[l] l += 1 ans = max(ans, sm) print(ans)
# -*- coding: utf-8 -*- import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print("Yes") def No(): print("No") def YES(): print("YES") def NO(): print("NO") sys.setrecursionlimit(10**9) INF = 10**18 MOD = 10**9 + 7 N, K = MAP() S = eval(input()) # ランレングス圧縮 A = [] # 番兵 if S[0] == "0": A.append(0) cur = S[0] cnt = 1 for i, s in enumerate(S[1:], 1): if s != cur: A.append(cnt) cnt = 1 cur = s else: cnt += 1 A.append(cnt) # 例外処理 if len(A) == 1: print(N) exit() # 番兵 if S[-1] == "0": A.append(0) M = len(A) ans = sm = sum(A[: K * 2 + 1]) for i in range(K * 2 + 1, M): sm += A[i] # 今回増やすのが0の区間なら、後ろ2つ減る if i % 2 == 1: if i - K * 2 >= 0: sm -= A[i - K * 2] if i - K * 2 - 1 >= 0: sm -= A[i - K * 2 - 1] ans = max(ans, sm) print(ans)
false
10.447761
[ "+def list4d(a, b, c, d, e):", "+ return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]", "+", "+", "-def LIST():", "- return list(map(int, input().split()))", "+def LIST(N=None):", "+ return list(MAP()) if N is None else [INT() for i in range(N)]", "-INF = float(\"inf\")", "+INF = 10**18", "-L = []", "-cnt0 = 0", "-# 0始まりの時は番兵的に1の区間0を追加しておく", "+# ランレングス圧縮", "+A = []", "+# 番兵", "- L.append(0)", "- cur = 0", "-else:", "- cur = 1", "-cnt = 0", "-# 1の区間の長さ、0の区間の長さ、1の区間の長さ...の配列Lを作る", "-for i in range(N):", "- if cur == int(S[i]):", "+ A.append(0)", "+cur = S[0]", "+cnt = 1", "+for i, s in enumerate(S[1:], 1):", "+ if s != cur:", "+ A.append(cnt)", "+ cnt = 1", "+ cur = s", "+ else:", "- else:", "- L.append(cnt)", "- if cur == 0:", "- cnt0 += 1", "- cnt = 1", "- # フラグの切り替え", "- cur = 1 - cur", "-else:", "- if cnt != 0:", "- L.append(cnt)", "- if cur == 0:", "- cnt0 += 1", "-# 0終わりの時は番兵的に1の区間0を追加しておく", "+A.append(cnt)", "+# 例外処理", "+if len(A) == 1:", "+ print(N)", "+ exit()", "+# 番兵", "- L.append(0)", "-if cnt0 < K:", "- # 0区間の数がKより少なかったら、それに合わせて区間和取る長さを短くする", "- K = cnt0", "-# 尺取法", "-l = 0", "-r = K * 2 + 1", "-ans = sm = sum(L[: K * 2 + 1])", "-while l < len(L) and r < len(L):", "- for i in range(2):", "- sm += L[r]", "- r += 1", "- sm -= L[l]", "- l += 1", "+ A.append(0)", "+M = len(A)", "+ans = sm = sum(A[: K * 2 + 1])", "+for i in range(K * 2 + 1, M):", "+ sm += A[i]", "+ # 今回増やすのが0の区間なら、後ろ2つ減る", "+ if i % 2 == 1:", "+ if i - K * 2 >= 0:", "+ sm -= A[i - K * 2]", "+ if i - K * 2 - 1 >= 0:", "+ sm -= A[i - K * 2 - 1]" ]
false
0.090495
0.038237
2.366705
[ "s649080949", "s679173682" ]
u325282913
p03329
python
s054429657
s920607476
625
102
89,716
74,772
Accepted
Accepted
83.68
import sys sys.setrecursionlimit(10**7) N = int(eval(input())) memo = [-1]*(N+1) def rec(n): if n == 0: return 0 if memo[n] != -1: return memo[n] res = n m = 1 while m <= n: res = min(res,rec(n-m)+1) m *= 6 m = 1 while m <= n: res = min(res,rec(n-m)+1) m *= 9 memo[n] = res return memo[n] print((rec(N)))
N = int(eval(input())) dp = [float('inf')]*(N+1) dp[0] = 0 for i in range(N+1): if i+1 <= N: dp[i+1] = min(dp[i+1],dp[i]+1) for j in range(1,N+1): if i + 6**j > N: break dp[i+6**j] = min(dp[i+6**j],dp[i]+1) for k in range(1,N+1): if i + 9**k > N: break dp[i+9**k] = min(dp[i+9**k],dp[i]+1) print((dp[N]))
22
15
402
386
import sys sys.setrecursionlimit(10**7) N = int(eval(input())) memo = [-1] * (N + 1) def rec(n): if n == 0: return 0 if memo[n] != -1: return memo[n] res = n m = 1 while m <= n: res = min(res, rec(n - m) + 1) m *= 6 m = 1 while m <= n: res = min(res, rec(n - m) + 1) m *= 9 memo[n] = res return memo[n] print((rec(N)))
N = int(eval(input())) dp = [float("inf")] * (N + 1) dp[0] = 0 for i in range(N + 1): if i + 1 <= N: dp[i + 1] = min(dp[i + 1], dp[i] + 1) for j in range(1, N + 1): if i + 6**j > N: break dp[i + 6**j] = min(dp[i + 6**j], dp[i] + 1) for k in range(1, N + 1): if i + 9**k > N: break dp[i + 9**k] = min(dp[i + 9**k], dp[i] + 1) print((dp[N]))
false
31.818182
[ "-import sys", "-", "-sys.setrecursionlimit(10**7)", "-memo = [-1] * (N + 1)", "-", "-", "-def rec(n):", "- if n == 0:", "- return 0", "- if memo[n] != -1:", "- return memo[n]", "- res = n", "- m = 1", "- while m <= n:", "- res = min(res, rec(n - m) + 1)", "- m *= 6", "- m = 1", "- while m <= n:", "- res = min(res, rec(n - m) + 1)", "- m *= 9", "- memo[n] = res", "- return memo[n]", "-", "-", "-print((rec(N)))", "+dp = [float(\"inf\")] * (N + 1)", "+dp[0] = 0", "+for i in range(N + 1):", "+ if i + 1 <= N:", "+ dp[i + 1] = min(dp[i + 1], dp[i] + 1)", "+ for j in range(1, N + 1):", "+ if i + 6**j > N:", "+ break", "+ dp[i + 6**j] = min(dp[i + 6**j], dp[i] + 1)", "+ for k in range(1, N + 1):", "+ if i + 9**k > N:", "+ break", "+ dp[i + 9**k] = min(dp[i + 9**k], dp[i] + 1)", "+print((dp[N]))" ]
false
0.190281
0.746447
0.254915
[ "s054429657", "s920607476" ]
u712429027
p03497
python
s511496160
s815119113
209
190
49,752
49,640
Accepted
Accepted
9.09
import sys input = sys.stdin.readline ins = lambda: input().rstrip() ini = lambda: int(input().rstrip()) inm = lambda: map(int, input().split()) inl = lambda: list(map(int, input().split())) out = lambda x: print('\n'.join(map(str, x))) n, k = inm() a = inl() if len(set(a)) <= 2: print(0) else: b = {} for i in a: if i not in b: b[i] = 0 b[i] += 1 b = sorted(b.items(), key=lambda x: x[1]) ans = 0 for i in range(len(set(a))-k): ans += b[i][1] print(ans)
import sys input = sys.stdin.readline ins = lambda: input().rstrip() ini = lambda: int(input().rstrip()) inm = lambda: map(int, input().split()) inl = lambda: list(map(int, input().split())) out = lambda x: print('\n'.join(map(str, x))) n, k = inm() a = inl() if len(set(a)) <= 2: print(0) else: b = {} for i in a: if i not in b: b[i] = 0 b[i] += 1 b = list(map(lambda x: x[1], sorted(b.items(), key=lambda x: x[1]))) print(sum(b[:len(set(a))-k]))
23
20
542
515
import sys input = sys.stdin.readline ins = lambda: input().rstrip() ini = lambda: int(input().rstrip()) inm = lambda: map(int, input().split()) inl = lambda: list(map(int, input().split())) out = lambda x: print("\n".join(map(str, x))) n, k = inm() a = inl() if len(set(a)) <= 2: print(0) else: b = {} for i in a: if i not in b: b[i] = 0 b[i] += 1 b = sorted(b.items(), key=lambda x: x[1]) ans = 0 for i in range(len(set(a)) - k): ans += b[i][1] print(ans)
import sys input = sys.stdin.readline ins = lambda: input().rstrip() ini = lambda: int(input().rstrip()) inm = lambda: map(int, input().split()) inl = lambda: list(map(int, input().split())) out = lambda x: print("\n".join(map(str, x))) n, k = inm() a = inl() if len(set(a)) <= 2: print(0) else: b = {} for i in a: if i not in b: b[i] = 0 b[i] += 1 b = list(map(lambda x: x[1], sorted(b.items(), key=lambda x: x[1]))) print(sum(b[: len(set(a)) - k]))
false
13.043478
[ "- b = sorted(b.items(), key=lambda x: x[1])", "- ans = 0", "- for i in range(len(set(a)) - k):", "- ans += b[i][1]", "- print(ans)", "+ b = list(map(lambda x: x[1], sorted(b.items(), key=lambda x: x[1])))", "+ print(sum(b[: len(set(a)) - k]))" ]
false
0.034366
0.0391
0.878934
[ "s511496160", "s815119113" ]
u989345508
p02928
python
s118424902
s180893267
1,102
361
3,444
79,280
Accepted
Accepted
67.24
n,k=input().split() n,k=int(n),int(k) a1=[int(i) for i in input().split()] b1=[] for i in range(len(a1)): b1.append([sum(x>a1[i] for x in a1[:i]),0]) #print(b1) l=len(a1) a1.extend(a1) #print(a1) for i in range(l): #print(i) b1[i][1]=sum(x>a1[i+l] for x in a1[:i+l]) c=0 for i in range(len(b1)): c+=(2*b1[i][0]+(k-1)*(b1[i][1]-b1[i][0]))*k//2 if c>10**9+7: c=c%(10**9+7) print(c)
from bisect import bisect_right n,k=list(map(int,input().split())) a=list(map(int,input().split())) b=sorted(a) mod=10**9+7 ans=0 for i in range(n): for j in range(n): if i<j and a[i]>a[j]: ans+=1 ans*=k #print(ans) ans%=mod r=0 for i in range(n): r+=(n-bisect_right(b,b[i])) ans+=(r*(k-1)*k//2) ans%=mod print(ans)
22
19
432
355
n, k = input().split() n, k = int(n), int(k) a1 = [int(i) for i in input().split()] b1 = [] for i in range(len(a1)): b1.append([sum(x > a1[i] for x in a1[:i]), 0]) # print(b1) l = len(a1) a1.extend(a1) # print(a1) for i in range(l): # print(i) b1[i][1] = sum(x > a1[i + l] for x in a1[: i + l]) c = 0 for i in range(len(b1)): c += (2 * b1[i][0] + (k - 1) * (b1[i][1] - b1[i][0])) * k // 2 if c > 10**9 + 7: c = c % (10**9 + 7) print(c)
from bisect import bisect_right n, k = list(map(int, input().split())) a = list(map(int, input().split())) b = sorted(a) mod = 10**9 + 7 ans = 0 for i in range(n): for j in range(n): if i < j and a[i] > a[j]: ans += 1 ans *= k # print(ans) ans %= mod r = 0 for i in range(n): r += n - bisect_right(b, b[i]) ans += r * (k - 1) * k // 2 ans %= mod print(ans)
false
13.636364
[ "-n, k = input().split()", "-n, k = int(n), int(k)", "-a1 = [int(i) for i in input().split()]", "-b1 = []", "-for i in range(len(a1)):", "- b1.append([sum(x > a1[i] for x in a1[:i]), 0])", "-# print(b1)", "-l = len(a1)", "-a1.extend(a1)", "-# print(a1)", "-for i in range(l):", "- # print(i)", "- b1[i][1] = sum(x > a1[i + l] for x in a1[: i + l])", "-c = 0", "-for i in range(len(b1)):", "- c += (2 * b1[i][0] + (k - 1) * (b1[i][1] - b1[i][0])) * k // 2", "- if c > 10**9 + 7:", "- c = c % (10**9 + 7)", "-print(c)", "+from bisect import bisect_right", "+", "+n, k = list(map(int, input().split()))", "+a = list(map(int, input().split()))", "+b = sorted(a)", "+mod = 10**9 + 7", "+ans = 0", "+for i in range(n):", "+ for j in range(n):", "+ if i < j and a[i] > a[j]:", "+ ans += 1", "+ans *= k", "+# print(ans)", "+ans %= mod", "+r = 0", "+for i in range(n):", "+ r += n - bisect_right(b, b[i])", "+ans += r * (k - 1) * k // 2", "+ans %= mod", "+print(ans)" ]
false
0.053454
0.033508
1.595273
[ "s118424902", "s180893267" ]
u285891772
p03069
python
s139744584
s145871863
185
129
23,092
14,732
Accepted
Accepted
30.27
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2 from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left, insort, insort_left from fractions import gcd from heapq import heappush, heappop from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) def ZIP(n): return list(zip(*(MAP() for _ in range(n)))) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10**9 + 7 #from decimal import * N = INT() S = eval(input()) b = [0]*(N+1) w = [0]*(N+1) tmp_b = 0 for i in range(N): if S[i] == "#": tmp_b += 1 b[i+1] = tmp_b tmp_w = 0 for i in range(N-1, -1, -1): if S[i] == ".": tmp_w += 1 w[i] = tmp_w ans = min([b[i]+w[i] for i in range(N+1)]) #print(b) #print(w) print(ans)
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2 from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left, insort, insort_left from fractions import gcd from heapq import heappush, heappop from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) def ZIP(n): return list(zip(*(MAP() for _ in range(n)))) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10**9 + 7 #from decimal import * N = INT() S = list(eval(input())) tmp = S.count("#") tmp2 = len(S) - tmp num = [0]*N num_sharp = 0 num_peri = 0 for i in range(len(S)): if S[i] == "#": num_sharp += 1 else: num_peri += 1 num[i] = num_sharp + tmp2-num_peri print((min(tmp2, min(num))))
44
37
1,205
1,162
import sys, re from collections import deque, defaultdict, Counter from math import ( ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, ) # , log2 from itertools import ( accumulate, permutations, combinations, combinations_with_replacement, product, groupby, ) from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left, insort, insort_left from fractions import gcd from heapq import heappush, heappop from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) def ZIP(n): return list(zip(*(MAP() for _ in range(n)))) sys.setrecursionlimit(10**9) INF = float("inf") mod = 10**9 + 7 # from decimal import * N = INT() S = eval(input()) b = [0] * (N + 1) w = [0] * (N + 1) tmp_b = 0 for i in range(N): if S[i] == "#": tmp_b += 1 b[i + 1] = tmp_b tmp_w = 0 for i in range(N - 1, -1, -1): if S[i] == ".": tmp_w += 1 w[i] = tmp_w ans = min([b[i] + w[i] for i in range(N + 1)]) # print(b) # print(w) print(ans)
import sys, re from collections import deque, defaultdict, Counter from math import ( ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, ) # , log2 from itertools import ( accumulate, permutations, combinations, combinations_with_replacement, product, groupby, ) from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left, insort, insort_left from fractions import gcd from heapq import heappush, heappop from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) def ZIP(n): return list(zip(*(MAP() for _ in range(n)))) sys.setrecursionlimit(10**9) INF = float("inf") mod = 10**9 + 7 # from decimal import * N = INT() S = list(eval(input())) tmp = S.count("#") tmp2 = len(S) - tmp num = [0] * N num_sharp = 0 num_peri = 0 for i in range(len(S)): if S[i] == "#": num_sharp += 1 else: num_peri += 1 num[i] = num_sharp + tmp2 - num_peri print((min(tmp2, min(num))))
false
15.909091
[ "-S = eval(input())", "-b = [0] * (N + 1)", "-w = [0] * (N + 1)", "-tmp_b = 0", "-for i in range(N):", "+S = list(eval(input()))", "+tmp = S.count(\"#\")", "+tmp2 = len(S) - tmp", "+num = [0] * N", "+num_sharp = 0", "+num_peri = 0", "+for i in range(len(S)):", "- tmp_b += 1", "- b[i + 1] = tmp_b", "-tmp_w = 0", "-for i in range(N - 1, -1, -1):", "- if S[i] == \".\":", "- tmp_w += 1", "- w[i] = tmp_w", "-ans = min([b[i] + w[i] for i in range(N + 1)])", "-# print(b)", "-# print(w)", "-print(ans)", "+ num_sharp += 1", "+ else:", "+ num_peri += 1", "+ num[i] = num_sharp + tmp2 - num_peri", "+print((min(tmp2, min(num))))" ]
false
0.06345
0.037259
1.702945
[ "s139744584", "s145871863" ]
u270144704
p02726
python
s530679876
s394987617
503
425
48,476
47,196
Accepted
Accepted
15.51
from collections import deque # import sys # input = sys.stdin.readline n, x, y = list(map(int, input().split())) g = dict() for i in range(n): if i == 0: g[i] = [i+1] elif i == n-1: g[i] = [i-1] else: g[i] = [i-1, i+1] g[x-1].append(y-1) g[y-1].append(x-1) # print(g) distance = [0]*(n-1) # 1番ノードから各ノードへの最短距離を求めていく. for i in range(n): queue = deque() visited = [0]*n # まず処理される予定のノードが格納されているqueueに最初のノードを格納する queue.append(i) while queue: target = queue.popleft() for j in g[target]: if visited[j] == 0 or visited[j] > visited[target] + 1: visited[j] = visited[target] + 1 queue.append(j) for k, a in enumerate(visited): if k > i: if a >= 1: distance[a-1] += 1 # print(f"{i}番ノードからの各ノードへの最短距離は{visited}である") for l in distance: print(l)
from collections import deque def main(): n, x, y = list(map(int, input().split())) g = dict() for i in range(n): if i == 0: g[i] = [i+1] elif i == n-1: g[i] = [i-1] else: g[i] = [i-1, i+1] g[x-1].append(y-1) g[y-1].append(x-1) distance = [0]*(n-1) # 1番ノードから各ノードへの最短距離を求めていく. for i in range(n): queue = deque() visited = [0]*n # まず処理される予定のノードが格納されているqueueに最初のノードを格納する queue.append(i) while queue: target = queue.popleft() for j in g[target]: if visited[j] == 0 or visited[j] > visited[target] + 1: visited[j] = visited[target] + 1 queue.append(j) for k, a in enumerate(visited): if k > i: if a >= 1: distance[a-1] += 1 # print(f"{i}番ノードからの各ノードへの最短距離は{visited}である") for l in distance: print(l) if __name__ == "__main__": main()
35
36
937
1,036
from collections import deque # import sys # input = sys.stdin.readline n, x, y = list(map(int, input().split())) g = dict() for i in range(n): if i == 0: g[i] = [i + 1] elif i == n - 1: g[i] = [i - 1] else: g[i] = [i - 1, i + 1] g[x - 1].append(y - 1) g[y - 1].append(x - 1) # print(g) distance = [0] * (n - 1) # 1番ノードから各ノードへの最短距離を求めていく. for i in range(n): queue = deque() visited = [0] * n # まず処理される予定のノードが格納されているqueueに最初のノードを格納する queue.append(i) while queue: target = queue.popleft() for j in g[target]: if visited[j] == 0 or visited[j] > visited[target] + 1: visited[j] = visited[target] + 1 queue.append(j) for k, a in enumerate(visited): if k > i: if a >= 1: distance[a - 1] += 1 # print(f"{i}番ノードからの各ノードへの最短距離は{visited}である") for l in distance: print(l)
from collections import deque def main(): n, x, y = list(map(int, input().split())) g = dict() for i in range(n): if i == 0: g[i] = [i + 1] elif i == n - 1: g[i] = [i - 1] else: g[i] = [i - 1, i + 1] g[x - 1].append(y - 1) g[y - 1].append(x - 1) distance = [0] * (n - 1) # 1番ノードから各ノードへの最短距離を求めていく. for i in range(n): queue = deque() visited = [0] * n # まず処理される予定のノードが格納されているqueueに最初のノードを格納する queue.append(i) while queue: target = queue.popleft() for j in g[target]: if visited[j] == 0 or visited[j] > visited[target] + 1: visited[j] = visited[target] + 1 queue.append(j) for k, a in enumerate(visited): if k > i: if a >= 1: distance[a - 1] += 1 # print(f"{i}番ノードからの各ノードへの最短距離は{visited}である") for l in distance: print(l) if __name__ == "__main__": main()
false
2.777778
[ "-# import sys", "-# input = sys.stdin.readline", "-n, x, y = list(map(int, input().split()))", "-g = dict()", "-for i in range(n):", "- if i == 0:", "- g[i] = [i + 1]", "- elif i == n - 1:", "- g[i] = [i - 1]", "- else:", "- g[i] = [i - 1, i + 1]", "-g[x - 1].append(y - 1)", "-g[y - 1].append(x - 1)", "-# print(g)", "-distance = [0] * (n - 1)", "-# 1番ノードから各ノードへの最短距離を求めていく.", "-for i in range(n):", "- queue = deque()", "- visited = [0] * n", "- # まず処理される予定のノードが格納されているqueueに最初のノードを格納する", "- queue.append(i)", "- while queue:", "- target = queue.popleft()", "- for j in g[target]:", "- if visited[j] == 0 or visited[j] > visited[target] + 1:", "- visited[j] = visited[target] + 1", "- queue.append(j)", "- for k, a in enumerate(visited):", "- if k > i:", "- if a >= 1:", "- distance[a - 1] += 1", "+", "+def main():", "+ n, x, y = list(map(int, input().split()))", "+ g = dict()", "+ for i in range(n):", "+ if i == 0:", "+ g[i] = [i + 1]", "+ elif i == n - 1:", "+ g[i] = [i - 1]", "+ else:", "+ g[i] = [i - 1, i + 1]", "+ g[x - 1].append(y - 1)", "+ g[y - 1].append(x - 1)", "+ distance = [0] * (n - 1)", "+ # 1番ノードから各ノードへの最短距離を求めていく.", "+ for i in range(n):", "+ queue = deque()", "+ visited = [0] * n", "+ # まず処理される予定のノードが格納されているqueueに最初のノードを格納する", "+ queue.append(i)", "+ while queue:", "+ target = queue.popleft()", "+ for j in g[target]:", "+ if visited[j] == 0 or visited[j] > visited[target] + 1:", "+ visited[j] = visited[target] + 1", "+ queue.append(j)", "+ for k, a in enumerate(visited):", "+ if k > i:", "+ if a >= 1:", "+ distance[a - 1] += 1", "-for l in distance:", "- print(l)", "+ for l in distance:", "+ print(l)", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.007411
0.036132
0.205113
[ "s530679876", "s394987617" ]
u889564559
p03456
python
s708168853
s724388991
147
17
12,504
2,940
Accepted
Accepted
88.44
import numpy as np a, b = list(map(str,input().split())) target = int(a + b) target_full = np.sqrt(target) target_resid = target_full % 1 if target_resid == 0: print("Yes") else: print("No")
a, b = list(map(str,input().split())) target = int(a + b) if (target ** 0.5).is_integer(): print("Yes") else: print("No")
13
8
206
130
import numpy as np a, b = list(map(str, input().split())) target = int(a + b) target_full = np.sqrt(target) target_resid = target_full % 1 if target_resid == 0: print("Yes") else: print("No")
a, b = list(map(str, input().split())) target = int(a + b) if (target**0.5).is_integer(): print("Yes") else: print("No")
false
38.461538
[ "-import numpy as np", "-", "-target_full = np.sqrt(target)", "-target_resid = target_full % 1", "-if target_resid == 0:", "+if (target**0.5).is_integer():" ]
false
0.166673
0.036508
4.565393
[ "s708168853", "s724388991" ]
u403984573
p03137
python
s094586966
s305616159
146
119
13,832
13,840
Accepted
Accepted
18.49
N,M=list(map(int,input().split())) X=[int(i) for i in input().split()] X.sort() count=[] sum=0 if N<M: for i in range(M): if i != 0: count.append(X[i]-get) sum+=count[i-1] get=X[i] count.sort(reverse=True) for i in range(N-1): sum-=count[i] print(sum)
n,m = list(map(int,input().split())) x = [int(i) for i in input().split()] x.sort() xx = [] for i in range(len(x)-1): xx.append(abs(x[i]-x[i+1])) xx.sort() print((sum(xx[:-(n-1)])if n!=1 else sum(xx)))
16
8
294
203
N, M = list(map(int, input().split())) X = [int(i) for i in input().split()] X.sort() count = [] sum = 0 if N < M: for i in range(M): if i != 0: count.append(X[i] - get) sum += count[i - 1] get = X[i] count.sort(reverse=True) for i in range(N - 1): sum -= count[i] print(sum)
n, m = list(map(int, input().split())) x = [int(i) for i in input().split()] x.sort() xx = [] for i in range(len(x) - 1): xx.append(abs(x[i] - x[i + 1])) xx.sort() print((sum(xx[: -(n - 1)]) if n != 1 else sum(xx)))
false
50
[ "-N, M = list(map(int, input().split()))", "-X = [int(i) for i in input().split()]", "-X.sort()", "-count = []", "-sum = 0", "-if N < M:", "- for i in range(M):", "- if i != 0:", "- count.append(X[i] - get)", "- sum += count[i - 1]", "- get = X[i]", "- count.sort(reverse=True)", "- for i in range(N - 1):", "- sum -= count[i]", "-print(sum)", "+n, m = list(map(int, input().split()))", "+x = [int(i) for i in input().split()]", "+x.sort()", "+xx = []", "+for i in range(len(x) - 1):", "+ xx.append(abs(x[i] - x[i + 1]))", "+xx.sort()", "+print((sum(xx[: -(n - 1)]) if n != 1 else sum(xx)))" ]
false
0.065861
0.047003
1.401211
[ "s094586966", "s305616159" ]
u077291787
p03243
python
s946819632
s325868669
21
17
2,940
3,064
Accepted
Accepted
19.05
# ABC111B from math import ceil print((ceil(int(eval(input())) / 111) * 111))
# ABC111B from math import ceil num = int(eval(input())) print((ceil(num / 111) * 111))
4
5
73
84
# ABC111B from math import ceil print((ceil(int(eval(input())) / 111) * 111))
# ABC111B from math import ceil num = int(eval(input())) print((ceil(num / 111) * 111))
false
20
[ "-print((ceil(int(eval(input())) / 111) * 111))", "+num = int(eval(input()))", "+print((ceil(num / 111) * 111))" ]
false
0.154419
0.043792
3.526172
[ "s946819632", "s325868669" ]
u608088992
p03854
python
s358303298
s083302384
60
38
3,188
4,092
Accepted
Accepted
36.67
S = eval(input()) Sb = S[::-1] daydreamers = ["maerd", "remaerd", "esare", "resare"] judge = True i = 0 while i < len(S) and judge: temp = "" isThere = False for j in range(7): temp += Sb[i+j] if temp in daydreamers: isThere = True i = i+j+1 break if not isThere: judge = False print(("YES" if judge else "NO"))
def solve(): S = eval(input()) N = len(S) Srev = [] for i in reversed(list(range(N))): Srev.append(S[i]) Srev = "".join(Srev) ti = 0 while ti < N: if Srev[ti] == "m": if Srev[ti:min(N, ti + 5)] == "maerd": ti += 5 else: print("NO") break elif Srev[ti] == "e": if Srev[ti:min(N, ti + 5)] == "esare": ti += 5 else: print("NO") break elif Srev[ti] == "r": if Srev[ti:min(N, ti + 6)] == "resare": ti += 6 elif Srev[ti:min(N, ti + 7)] == "remaerd": ti += 7 else: print("NO") break else: print("NO") break else: print("YES") return 0 if __name__ == "__main__": solve()
19
34
399
862
S = eval(input()) Sb = S[::-1] daydreamers = ["maerd", "remaerd", "esare", "resare"] judge = True i = 0 while i < len(S) and judge: temp = "" isThere = False for j in range(7): temp += Sb[i + j] if temp in daydreamers: isThere = True i = i + j + 1 break if not isThere: judge = False print(("YES" if judge else "NO"))
def solve(): S = eval(input()) N = len(S) Srev = [] for i in reversed(list(range(N))): Srev.append(S[i]) Srev = "".join(Srev) ti = 0 while ti < N: if Srev[ti] == "m": if Srev[ti : min(N, ti + 5)] == "maerd": ti += 5 else: print("NO") break elif Srev[ti] == "e": if Srev[ti : min(N, ti + 5)] == "esare": ti += 5 else: print("NO") break elif Srev[ti] == "r": if Srev[ti : min(N, ti + 6)] == "resare": ti += 6 elif Srev[ti : min(N, ti + 7)] == "remaerd": ti += 7 else: print("NO") break else: print("NO") break else: print("YES") return 0 if __name__ == "__main__": solve()
false
44.117647
[ "-S = eval(input())", "-Sb = S[::-1]", "-daydreamers = [\"maerd\", \"remaerd\", \"esare\", \"resare\"]", "-judge = True", "-i = 0", "-while i < len(S) and judge:", "- temp = \"\"", "- isThere = False", "- for j in range(7):", "- temp += Sb[i + j]", "- if temp in daydreamers:", "- isThere = True", "- i = i + j + 1", "+def solve():", "+ S = eval(input())", "+ N = len(S)", "+ Srev = []", "+ for i in reversed(list(range(N))):", "+ Srev.append(S[i])", "+ Srev = \"\".join(Srev)", "+ ti = 0", "+ while ti < N:", "+ if Srev[ti] == \"m\":", "+ if Srev[ti : min(N, ti + 5)] == \"maerd\":", "+ ti += 5", "+ else:", "+ print(\"NO\")", "+ break", "+ elif Srev[ti] == \"e\":", "+ if Srev[ti : min(N, ti + 5)] == \"esare\":", "+ ti += 5", "+ else:", "+ print(\"NO\")", "+ break", "+ elif Srev[ti] == \"r\":", "+ if Srev[ti : min(N, ti + 6)] == \"resare\":", "+ ti += 6", "+ elif Srev[ti : min(N, ti + 7)] == \"remaerd\":", "+ ti += 7", "+ else:", "+ print(\"NO\")", "+ break", "+ else:", "+ print(\"NO\")", "- if not isThere:", "- judge = False", "-print((\"YES\" if judge else \"NO\"))", "+ else:", "+ print(\"YES\")", "+ return 0", "+", "+", "+if __name__ == \"__main__\":", "+ solve()" ]
false
0.041464
0.036558
1.134213
[ "s358303298", "s083302384" ]
u691018832
p02696
python
s901532650
s583186834
61
20
62,148
9,072
Accepted
Accepted
67.21
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) from math import floor a, b, n = list(map(int, readline().split())) if b > n: print((floor(a * n / b) - a * floor(n / b))) else: print((floor(a * (b - 1) / b) - a * floor((b - 1) / b)))
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) from math import floor a, b, n = list(map(int, readline().split())) print((floor(a * min(b - 1, n) / b) - a * floor(min(b - 1, n) / b)))
13
10
345
287
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10**7) from math import floor a, b, n = list(map(int, readline().split())) if b > n: print((floor(a * n / b) - a * floor(n / b))) else: print((floor(a * (b - 1) / b) - a * floor((b - 1) / b)))
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10**7) from math import floor a, b, n = list(map(int, readline().split())) print((floor(a * min(b - 1, n) / b) - a * floor(min(b - 1, n) / b)))
false
23.076923
[ "-if b > n:", "- print((floor(a * n / b) - a * floor(n / b)))", "-else:", "- print((floor(a * (b - 1) / b) - a * floor((b - 1) / b)))", "+print((floor(a * min(b - 1, n) / b) - a * floor(min(b - 1, n) / b)))" ]
false
0.124337
0.085006
1.462689
[ "s901532650", "s583186834" ]
u141786930
p03107
python
s242726267
s291156488
43
18
3,188
3,188
Accepted
Accepted
58.14
# C - Unification S = str(eval(input())) zeroCnt = 0 oneCnt = 0 ans = 0 for i in range(len(S)): if S[i]=='0': if oneCnt==0: zeroCnt += 1 else: ans += 2 oneCnt -= 1 else: if zeroCnt==0: oneCnt += 1 else: ans += 2 zeroCnt -= 1 print(ans)
# C - Unification S = str(eval(input())) zeroCnt = S.count('0') oneCnt = S.count('1') print((min(zeroCnt, oneCnt)*2))
23
8
368
119
# C - Unification S = str(eval(input())) zeroCnt = 0 oneCnt = 0 ans = 0 for i in range(len(S)): if S[i] == "0": if oneCnt == 0: zeroCnt += 1 else: ans += 2 oneCnt -= 1 else: if zeroCnt == 0: oneCnt += 1 else: ans += 2 zeroCnt -= 1 print(ans)
# C - Unification S = str(eval(input())) zeroCnt = S.count("0") oneCnt = S.count("1") print((min(zeroCnt, oneCnt) * 2))
false
65.217391
[ "-zeroCnt = 0", "-oneCnt = 0", "-ans = 0", "-for i in range(len(S)):", "- if S[i] == \"0\":", "- if oneCnt == 0:", "- zeroCnt += 1", "- else:", "- ans += 2", "- oneCnt -= 1", "- else:", "- if zeroCnt == 0:", "- oneCnt += 1", "- else:", "- ans += 2", "- zeroCnt -= 1", "-print(ans)", "+zeroCnt = S.count(\"0\")", "+oneCnt = S.count(\"1\")", "+print((min(zeroCnt, oneCnt) * 2))" ]
false
0.033912
0.040255
0.842421
[ "s242726267", "s291156488" ]
u548303713
p03037
python
s019469560
s250918613
408
338
27,344
3,064
Accepted
Accepted
17.16
n,m=list(map(int,input().split())) info=[] for i in range(m): info.append(list(map(int,input().split()))) start,goal=info[0][0],info[0][1] c=0 for i in range(1,m): start=max(start,info[i][0]) goal=min(goal,info[i][1]) if start>goal: c=1 break if c==0: print((goal-start+1)) else: print((0))
n,m=list(map(int,input().split())) L,R=list(map(int,input().split())) for i in range(m-1): l,r=list(map(int,input().split())) if r<L: L,R=0,-1 break if R<l: L,R=0,-1 break L=max(L,l) R=min(R,r) print((R-L+1))
18
14
343
254
n, m = list(map(int, input().split())) info = [] for i in range(m): info.append(list(map(int, input().split()))) start, goal = info[0][0], info[0][1] c = 0 for i in range(1, m): start = max(start, info[i][0]) goal = min(goal, info[i][1]) if start > goal: c = 1 break if c == 0: print((goal - start + 1)) else: print((0))
n, m = list(map(int, input().split())) L, R = list(map(int, input().split())) for i in range(m - 1): l, r = list(map(int, input().split())) if r < L: L, R = 0, -1 break if R < l: L, R = 0, -1 break L = max(L, l) R = min(R, r) print((R - L + 1))
false
22.222222
[ "-info = []", "-for i in range(m):", "- info.append(list(map(int, input().split())))", "-start, goal = info[0][0], info[0][1]", "-c = 0", "-for i in range(1, m):", "- start = max(start, info[i][0])", "- goal = min(goal, info[i][1])", "- if start > goal:", "- c = 1", "+L, R = list(map(int, input().split()))", "+for i in range(m - 1):", "+ l, r = list(map(int, input().split()))", "+ if r < L:", "+ L, R = 0, -1", "-if c == 0:", "- print((goal - start + 1))", "-else:", "- print((0))", "+ if R < l:", "+ L, R = 0, -1", "+ break", "+ L = max(L, l)", "+ R = min(R, r)", "+print((R - L + 1))" ]
false
0.037121
0.043399
0.85535
[ "s019469560", "s250918613" ]
u997641430
p02862
python
s484086052
s699497036
1,316
225
122,068
29,460
Accepted
Accepted
82.9
mod = 10**9+7 N = 10**6 g1 = [1, 1] g2 = [1, 1] inverse = [0, 1] for i in range(2, N + 1): g1.append((g1[-1] * i) % mod) inverse.append((-inverse[mod % i] * (mod//i)) % mod) g2.append((g2[-1] * inverse[-1]) % mod) def cmb(n, r, mod): if (r < 0 or r > n): return 0 return g1[n] * g2[r] * g2[n-r] % mod X, Y = list(map(int, input().split())) if (X + Y) % 3 != 0: ans = 0 else: n = (X + Y) // 3 r = min(X, Y) - n ans = cmb(n, r, mod) print(ans)
mod = 10**9+7 X, Y = list(map(int, input().split())) def comb(n, r, mod): if r < 0 or n < r: return 0 return fact[n]*pow(fact[r], mod-2, mod) * pow(fact[n-r], mod-2, mod) % mod if (X + Y) % 3 != 0: ans = 0 else: n = (X + Y) // 3 r = min(X, Y)-n # nCr fact = [1, 1] for i in range(2, n+1): fact.append(fact[-1] * i % mod) ans = comb(n, r, mod) print(ans)
27
23
512
428
mod = 10**9 + 7 N = 10**6 g1 = [1, 1] g2 = [1, 1] inverse = [0, 1] for i in range(2, N + 1): g1.append((g1[-1] * i) % mod) inverse.append((-inverse[mod % i] * (mod // i)) % mod) g2.append((g2[-1] * inverse[-1]) % mod) def cmb(n, r, mod): if r < 0 or r > n: return 0 return g1[n] * g2[r] * g2[n - r] % mod X, Y = list(map(int, input().split())) if (X + Y) % 3 != 0: ans = 0 else: n = (X + Y) // 3 r = min(X, Y) - n ans = cmb(n, r, mod) print(ans)
mod = 10**9 + 7 X, Y = list(map(int, input().split())) def comb(n, r, mod): if r < 0 or n < r: return 0 return fact[n] * pow(fact[r], mod - 2, mod) * pow(fact[n - r], mod - 2, mod) % mod if (X + Y) % 3 != 0: ans = 0 else: n = (X + Y) // 3 r = min(X, Y) - n # nCr fact = [1, 1] for i in range(2, n + 1): fact.append(fact[-1] * i % mod) ans = comb(n, r, mod) print(ans)
false
14.814815
[ "-N = 10**6", "-g1 = [1, 1]", "-g2 = [1, 1]", "-inverse = [0, 1]", "-for i in range(2, N + 1):", "- g1.append((g1[-1] * i) % mod)", "- inverse.append((-inverse[mod % i] * (mod // i)) % mod)", "- g2.append((g2[-1] * inverse[-1]) % mod)", "+X, Y = list(map(int, input().split()))", "-def cmb(n, r, mod):", "- if r < 0 or r > n:", "+def comb(n, r, mod):", "+ if r < 0 or n < r:", "- return g1[n] * g2[r] * g2[n - r] % mod", "+ return fact[n] * pow(fact[r], mod - 2, mod) * pow(fact[n - r], mod - 2, mod) % mod", "-X, Y = list(map(int, input().split()))", "- ans = cmb(n, r, mod)", "+ # nCr", "+ fact = [1, 1]", "+ for i in range(2, n + 1):", "+ fact.append(fact[-1] * i % mod)", "+ ans = comb(n, r, mod)" ]
false
3.027617
0.077409
39.111877
[ "s484086052", "s699497036" ]
u261103969
p02612
python
s696630240
s894519362
69
28
61,660
9,144
Accepted
Accepted
59.42
import sys readline = sys.stdin.readline MOD = 10 ** 9 + 7 INF = float('INF') sys.setrecursionlimit(10 ** 5) def main(): n = int(readline()) print(((1000 - n % 1000) % 1000)) if __name__ == '__main__': main()
n = int(eval(input())) x = 0 while x < n: x += 1000 print(( x - n ))
15
5
238
68
import sys readline = sys.stdin.readline MOD = 10**9 + 7 INF = float("INF") sys.setrecursionlimit(10**5) def main(): n = int(readline()) print(((1000 - n % 1000) % 1000)) if __name__ == "__main__": main()
n = int(eval(input())) x = 0 while x < n: x += 1000 print((x - n))
false
66.666667
[ "-import sys", "-", "-readline = sys.stdin.readline", "-MOD = 10**9 + 7", "-INF = float(\"INF\")", "-sys.setrecursionlimit(10**5)", "-", "-", "-def main():", "- n = int(readline())", "- print(((1000 - n % 1000) % 1000))", "-", "-", "-if __name__ == \"__main__\":", "- main()", "+n = int(eval(input()))", "+x = 0", "+while x < n:", "+ x += 1000", "+print((x - n))" ]
false
0.035683
0.053945
0.661472
[ "s696630240", "s894519362" ]
u070201429
p02632
python
s736165415
s700080973
1,086
475
222,064
245,636
Accepted
Accepted
56.26
class Combination: def __init__(self, n, mod): self.mod = mod # self.fac[i] ≡ i! (factorial:階乗) l = [1] num = 1 for i in range(1, n+1): num *= i num %= mod l.append(num) self.fac = l.copy() # self.rec[i] ≡ 1 / i! (reciprocal:逆数) num = pow(num, mod-2, mod) l = [1 for i in range(n+1)] l[n] = num for i in range(n-1, 0, -1): num *= i + 1 num %= mod l[i] = num self.rec = l.copy() # comb(n, r) ≡ nCr def comb(self, n, r): return self.fac[n] * self.rec[r] * self.rec[n - r] % self.mod mod = 10**9 + 7 k = int(eval(input())) s = eval(input()) n = len(s) c = Combination(k + n, mod) ans = 0 for i in range(k+1): ans += c.comb(n + i - 1, i) * pow(25, i, mod) * pow(26, k-i, mod) ans %= mod print(ans)
class Combination: def __init__(self, n, mod): self.mod = mod # self.fac[i] ≡ i! (factorial:階乗) l = [1] num = 1 for i in range(1, n+1): num *= i num %= mod l.append(num) self.fac = l.copy() # self.rec[i] ≡ 1 / i! (reciprocal:逆数) num = pow(num, mod-2, mod) l = [1 for i in range(n+1)] l[n] = num for i in range(n-1, 0, -1): num *= i + 1 num %= mod l[i] = num self.rec = l.copy() # comb(n, r) ≡ nCr def comb(self, n, r): return self.fac[n] * self.rec[r] * self.rec[n - r] % self.mod mod = 10**9 + 7 k = int(eval(input())) s = eval(input()) n = len(s) c = Combination(k + n, mod) pow25 = [1] pow26 = [1] for _ in range(k): pow25.append(25 * pow25[-1] % mod) pow26.append(26 * pow26[-1] % mod) ans = 0 for i in range(k+1): ans += c.comb(n+i-1, i) * pow25[i] * pow26[k-i] ans %= mod print(ans)
41
47
925
1,035
class Combination: def __init__(self, n, mod): self.mod = mod # self.fac[i] ≡ i! (factorial:階乗) l = [1] num = 1 for i in range(1, n + 1): num *= i num %= mod l.append(num) self.fac = l.copy() # self.rec[i] ≡ 1 / i! (reciprocal:逆数) num = pow(num, mod - 2, mod) l = [1 for i in range(n + 1)] l[n] = num for i in range(n - 1, 0, -1): num *= i + 1 num %= mod l[i] = num self.rec = l.copy() # comb(n, r) ≡ nCr def comb(self, n, r): return self.fac[n] * self.rec[r] * self.rec[n - r] % self.mod mod = 10**9 + 7 k = int(eval(input())) s = eval(input()) n = len(s) c = Combination(k + n, mod) ans = 0 for i in range(k + 1): ans += c.comb(n + i - 1, i) * pow(25, i, mod) * pow(26, k - i, mod) ans %= mod print(ans)
class Combination: def __init__(self, n, mod): self.mod = mod # self.fac[i] ≡ i! (factorial:階乗) l = [1] num = 1 for i in range(1, n + 1): num *= i num %= mod l.append(num) self.fac = l.copy() # self.rec[i] ≡ 1 / i! (reciprocal:逆数) num = pow(num, mod - 2, mod) l = [1 for i in range(n + 1)] l[n] = num for i in range(n - 1, 0, -1): num *= i + 1 num %= mod l[i] = num self.rec = l.copy() # comb(n, r) ≡ nCr def comb(self, n, r): return self.fac[n] * self.rec[r] * self.rec[n - r] % self.mod mod = 10**9 + 7 k = int(eval(input())) s = eval(input()) n = len(s) c = Combination(k + n, mod) pow25 = [1] pow26 = [1] for _ in range(k): pow25.append(25 * pow25[-1] % mod) pow26.append(26 * pow26[-1] % mod) ans = 0 for i in range(k + 1): ans += c.comb(n + i - 1, i) * pow25[i] * pow26[k - i] ans %= mod print(ans)
false
12.765957
[ "+pow25 = [1]", "+pow26 = [1]", "+for _ in range(k):", "+ pow25.append(25 * pow25[-1] % mod)", "+ pow26.append(26 * pow26[-1] % mod)", "- ans += c.comb(n + i - 1, i) * pow(25, i, mod) * pow(26, k - i, mod)", "+ ans += c.comb(n + i - 1, i) * pow25[i] * pow26[k - i]" ]
false
0.204109
0.04003
5.098876
[ "s736165415", "s700080973" ]