user_id
stringlengths
10
10
problem_id
stringlengths
6
6
language
stringclasses
1 value
submission_id_v0
stringlengths
10
10
submission_id_v1
stringlengths
10
10
cpu_time_v0
int64
10
38.3k
cpu_time_v1
int64
0
24.7k
memory_v0
int64
2.57k
1.02M
memory_v1
int64
2.57k
869k
status_v0
stringclasses
1 value
status_v1
stringclasses
1 value
improvement_frac
float64
7.51
100
input
stringlengths
20
4.55k
target
stringlengths
17
3.34k
code_v0_loc
int64
1
148
code_v1_loc
int64
1
184
code_v0_num_chars
int64
13
4.55k
code_v1_num_chars
int64
14
3.34k
code_v0_no_empty_lines
stringlengths
21
6.88k
code_v1_no_empty_lines
stringlengths
20
4.93k
code_same
bool
1 class
relative_loc_diff_percent
float64
0
79.8
diff
sequence
diff_only_import_comment
bool
1 class
measured_runtime_v0
float64
0.01
4.45
measured_runtime_v1
float64
0.01
4.31
runtime_lift
float64
0
359
key
sequence
u359358631
p03564
python
s968025171
s892181339
304
66
80,520
61,832
Accepted
Accepted
78.29
def main(): n, k = int(eval(input())), int(eval(input())) cnt = 0 x = 1 for _ in range(n): x *= 2 cnt += 1 if x > k: break print((x + k * (n - cnt))) if __name__ == "__main__": main()
def main(): n, k = int(eval(input())), int(eval(input())) x = 1 for _ in range(n): x = min(2 * x, x + k) print(x) if __name__ == "__main__": main()
16
11
249
177
def main(): n, k = int(eval(input())), int(eval(input())) cnt = 0 x = 1 for _ in range(n): x *= 2 cnt += 1 if x > k: break print((x + k * (n - cnt))) if __name__ == "__main__": main()
def main(): n, k = int(eval(input())), int(eval(input())) x = 1 for _ in range(n): x = min(2 * x, x + k) print(x) if __name__ == "__main__": main()
false
31.25
[ "- cnt = 0", "- x *= 2", "- cnt += 1", "- if x > k:", "- break", "- print((x + k * (n - cnt)))", "+ x = min(2 * x, x + k)", "+ print(x)" ]
false
0.043369
0.038581
1.124103
[ "s968025171", "s892181339" ]
u883048396
p04031
python
s656608462
s140187364
21
17
3,060
3,060
Accepted
Accepted
19.05
iN = int(eval(input())) aA = [int(x) for x in input().split()] i2M = (min(aA) + max(aA)) // 2 iMM = sum(aA) // len(aA) if i2M < iMM : iLM = i2M iUM = iMM + 1 else: iLM = iMM iUM = i2M + 1 aR = [] for iM in range(iLM,iUM+1): aR.append(0) for iA in aA: aR[-1] += (iA - iM) ** 2 print((min(aR)))
iN = int(eval(input())) aA = [int(x) for x in input().split()] #i2M = (min(aA) + max(aA)) // 2 iMM = sum(aA) // len(aA) #if i2M < iMM : # iLM = i2M # iUM = iMM + 1 #else: # iLM = iMM # iUM = i2M + 1 iLM = iMM iUM = iMM + 1 aR = [] for iM in range(iLM,iUM+1): aR.append(0) for iA in aA: aR[-1] += (iA - iM) ** 2 print((min(aR)))
19
23
338
371
iN = int(eval(input())) aA = [int(x) for x in input().split()] i2M = (min(aA) + max(aA)) // 2 iMM = sum(aA) // len(aA) if i2M < iMM: iLM = i2M iUM = iMM + 1 else: iLM = iMM iUM = i2M + 1 aR = [] for iM in range(iLM, iUM + 1): aR.append(0) for iA in aA: aR[-1] += (iA - iM) ** 2 print((min(aR)))
iN = int(eval(input())) aA = [int(x) for x in input().split()] # i2M = (min(aA) + max(aA)) // 2 iMM = sum(aA) // len(aA) # if i2M < iMM : # iLM = i2M # iUM = iMM + 1 # else: # iLM = iMM # iUM = i2M + 1 iLM = iMM iUM = iMM + 1 aR = [] for iM in range(iLM, iUM + 1): aR.append(0) for iA in aA: aR[-1] += (iA - iM) ** 2 print((min(aR)))
false
17.391304
[ "-i2M = (min(aA) + max(aA)) // 2", "+# i2M = (min(aA) + max(aA)) // 2", "-if i2M < iMM:", "- iLM = i2M", "- iUM = iMM + 1", "-else:", "- iLM = iMM", "- iUM = i2M + 1", "+# if i2M < iMM :", "+# iLM = i2M", "+# iUM = iMM + 1", "+# else:", "+# iLM = iMM", "+# iUM = i2M + 1", "+iLM = iMM", "+iUM = iMM + 1" ]
false
0.045312
0.046001
0.985034
[ "s656608462", "s140187364" ]
u156815136
p02606
python
s688471363
s478059346
43
38
10,388
10,368
Accepted
Accepted
11.63
#from statistics import median #import collections #aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0] from fractions import gcd from itertools import combinations,permutations,accumulate # (string,3) 3回 #from collections import deque from collections import deque,defaultdict,Counter import decimal import re #import bisect # # d = m - k[i] - k[j] # if kk[bisect.bisect_right(kk,d) - 1] == d: # # # # pythonで無理なときは、pypyでやると正解するかも!! # # import sys sys.setrecursionlimit(10000000) mod = 10**9 + 7 #mod = 9982443453 def readInts(): return list(map(int,input().split())) def I(): return int(eval(input())) l,r,d = readInts() print((r//d - (l-1)//d))
#from statistics import median #import collections #aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0] from fractions import gcd from itertools import combinations,permutations,accumulate, product # (string,3) 3回 #from collections import deque from collections import deque,defaultdict,Counter import decimal import re import math import bisect # # # # pythonで無理なときは、pypyでやると正解するかも!! # # # my_round_int = lambda x:np.round((x*2 + 1)//2) # 四捨五入g # # インデックス系 # int min_y = max(0, i - 2), max_y = min(h - 1, i + 2); # int min_x = max(0, j - 2), max_x = min(w - 1, j + 2); # # import sys sys.setrecursionlimit(10000000) mod = 10**9 + 7 #mod = 9982443453 #mod = 998244353 from sys import stdin readline = stdin.readline def readInts(): return list(map(int,readline().split())) def readTuples(): return tuple(map(int,readline().split())) def I(): return int(readline()) l,r,d = readInts() print((r//d - (l-1)//d))
30
40
710
984
# from statistics import median # import collections # aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0] from fractions import gcd from itertools import combinations, permutations, accumulate # (string,3) 3回 # from collections import deque from collections import deque, defaultdict, Counter import decimal import re # import bisect # # d = m - k[i] - k[j] # if kk[bisect.bisect_right(kk,d) - 1] == d: # # # # pythonで無理なときは、pypyでやると正解するかも!! # # import sys sys.setrecursionlimit(10000000) mod = 10**9 + 7 # mod = 9982443453 def readInts(): return list(map(int, input().split())) def I(): return int(eval(input())) l, r, d = readInts() print((r // d - (l - 1) // d))
# from statistics import median # import collections # aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0] from fractions import gcd from itertools import combinations, permutations, accumulate, product # (string,3) 3回 # from collections import deque from collections import deque, defaultdict, Counter import decimal import re import math import bisect # # # # pythonで無理なときは、pypyでやると正解するかも!! # # # my_round_int = lambda x:np.round((x*2 + 1)//2) # 四捨五入g # # インデックス系 # int min_y = max(0, i - 2), max_y = min(h - 1, i + 2); # int min_x = max(0, j - 2), max_x = min(w - 1, j + 2); # # import sys sys.setrecursionlimit(10000000) mod = 10**9 + 7 # mod = 9982443453 # mod = 998244353 from sys import stdin readline = stdin.readline def readInts(): return list(map(int, readline().split())) def readTuples(): return tuple(map(int, readline().split())) def I(): return int(readline()) l, r, d = readInts() print((r // d - (l - 1) // d))
false
25
[ "-from itertools import combinations, permutations, accumulate # (string,3) 3回", "+from itertools import combinations, permutations, accumulate, product # (string,3) 3回", "+import math", "+import bisect", "-# import bisect", "-#", "-# d = m - k[i] - k[j]", "-# if kk[bisect.bisect_right(kk,d) - 1] == d:", "+#", "+#", "+# my_round_int = lambda x:np.round((x*2 + 1)//2)", "+# 四捨五入g", "+#", "+# インデックス系", "+# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);", "+# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);", "+# mod = 998244353", "+from sys import stdin", "+", "+readline = stdin.readline", "+", "+", "- return list(map(int, input().split()))", "+ return list(map(int, readline().split()))", "+", "+", "+def readTuples():", "+ return tuple(map(int, readline().split()))", "- return int(eval(input()))", "+ return int(readline())" ]
false
0.03796
0.039699
0.956193
[ "s688471363", "s478059346" ]
u293198424
p03387
python
s884416733
s801527700
180
164
38,384
38,256
Accepted
Accepted
8.89
a = list(map(int,input().split())) evil = 0 odd = 0 ans = 0 for i in a: if i%2==0: evil += 1 else: odd += 1 if evil==3 or odd==3: a = [max(a)-i for i in a] ans += sum(a)//2 else: if evil==2: ans += 1 for i in range(3): if a[i]%2==0: a[i] += 1 else: ans += 1 for i in range(3): if a[i]%2==1: a[i] += 1 a = [max(a)-i for i in a] ans += sum(a)//2 print(ans)
a = [int(i) for i in input().split()] g = 0 k = 0 count = 0 for i in a: if i%2==0: g += 1 else: k += 1 if g==1: count += 1 for i in range(3): if a[i]%2==1: a[i] += 1 elif k==1: count += 1 for i in range(3): if a[i]%2==0: a[i] += 1 a = sorted(a)[::-1] count += (a[0]-a[1])//2 + (a[0]-a[2])//2 print(count)
26
24
516
433
a = list(map(int, input().split())) evil = 0 odd = 0 ans = 0 for i in a: if i % 2 == 0: evil += 1 else: odd += 1 if evil == 3 or odd == 3: a = [max(a) - i for i in a] ans += sum(a) // 2 else: if evil == 2: ans += 1 for i in range(3): if a[i] % 2 == 0: a[i] += 1 else: ans += 1 for i in range(3): if a[i] % 2 == 1: a[i] += 1 a = [max(a) - i for i in a] ans += sum(a) // 2 print(ans)
a = [int(i) for i in input().split()] g = 0 k = 0 count = 0 for i in a: if i % 2 == 0: g += 1 else: k += 1 if g == 1: count += 1 for i in range(3): if a[i] % 2 == 1: a[i] += 1 elif k == 1: count += 1 for i in range(3): if a[i] % 2 == 0: a[i] += 1 a = sorted(a)[::-1] count += (a[0] - a[1]) // 2 + (a[0] - a[2]) // 2 print(count)
false
7.692308
[ "-a = list(map(int, input().split()))", "-evil = 0", "-odd = 0", "-ans = 0", "+a = [int(i) for i in input().split()]", "+g = 0", "+k = 0", "+count = 0", "- evil += 1", "+ g += 1", "- odd += 1", "-if evil == 3 or odd == 3:", "- a = [max(a) - i for i in a]", "- ans += sum(a) // 2", "-else:", "- if evil == 2:", "- ans += 1", "- for i in range(3):", "- if a[i] % 2 == 0:", "- a[i] += 1", "- else:", "- ans += 1", "- for i in range(3):", "- if a[i] % 2 == 1:", "- a[i] += 1", "- a = [max(a) - i for i in a]", "- ans += sum(a) // 2", "-print(ans)", "+ k += 1", "+if g == 1:", "+ count += 1", "+ for i in range(3):", "+ if a[i] % 2 == 1:", "+ a[i] += 1", "+elif k == 1:", "+ count += 1", "+ for i in range(3):", "+ if a[i] % 2 == 0:", "+ a[i] += 1", "+a = sorted(a)[::-1]", "+count += (a[0] - a[1]) // 2 + (a[0] - a[2]) // 2", "+print(count)" ]
false
0.04228
0.045522
0.928768
[ "s884416733", "s801527700" ]
u617515020
p02936
python
s010168948
s254466923
1,742
1,380
56,080
223,540
Accepted
Accepted
20.78
from collections import deque n,q=list(map(int,input().split())) g=[[] for _ in range(n)] for _ in range(n-1): a,b=list(map(int,input().split())) g[a-1].append(b-1) g[b-1].append(a-1) s=[0]*n for _ in range(q): p,x=list(map(int,input().split())) s[p-1]+=x que=deque([0]) f=[0]*n f[0]=1 while que: v=que.popleft() c=s[v] for w in g[v]: if f[w]: continue f[w]=1 s[w]+=c que.append(w) print((*s))
import sys sys.setrecursionlimit(10**7) N, Q = list(map(int, input().split())) root = [[] for i in range(N)] ans = [0]*N for i in range(N-1): a, b = list(map(int, input().split())) a, b = a-1, b-1 root[a].append(b) root[b].append(a) for i in range(Q): p, x = list(map(int, input().split())) ans[p-1] += x visit = [False]*N def dfs(n): visit[n] = True for go in root[n]: if visit[go]: continue ans[go] += ans[n] dfs(go) dfs(0) print((*ans))
27
28
442
489
from collections import deque n, q = list(map(int, input().split())) g = [[] for _ in range(n)] for _ in range(n - 1): a, b = list(map(int, input().split())) g[a - 1].append(b - 1) g[b - 1].append(a - 1) s = [0] * n for _ in range(q): p, x = list(map(int, input().split())) s[p - 1] += x que = deque([0]) f = [0] * n f[0] = 1 while que: v = que.popleft() c = s[v] for w in g[v]: if f[w]: continue f[w] = 1 s[w] += c que.append(w) print((*s))
import sys sys.setrecursionlimit(10**7) N, Q = list(map(int, input().split())) root = [[] for i in range(N)] ans = [0] * N for i in range(N - 1): a, b = list(map(int, input().split())) a, b = a - 1, b - 1 root[a].append(b) root[b].append(a) for i in range(Q): p, x = list(map(int, input().split())) ans[p - 1] += x visit = [False] * N def dfs(n): visit[n] = True for go in root[n]: if visit[go]: continue ans[go] += ans[n] dfs(go) dfs(0) print((*ans))
false
3.571429
[ "-from collections import deque", "+import sys", "-n, q = list(map(int, input().split()))", "-g = [[] for _ in range(n)]", "-for _ in range(n - 1):", "+sys.setrecursionlimit(10**7)", "+N, Q = list(map(int, input().split()))", "+root = [[] for i in range(N)]", "+ans = [0] * N", "+for i in range(N - 1):", "- g[a - 1].append(b - 1)", "- g[b - 1].append(a - 1)", "-s = [0] * n", "-for _ in range(q):", "+ a, b = a - 1, b - 1", "+ root[a].append(b)", "+ root[b].append(a)", "+for i in range(Q):", "- s[p - 1] += x", "-que = deque([0])", "-f = [0] * n", "-f[0] = 1", "-while que:", "- v = que.popleft()", "- c = s[v]", "- for w in g[v]:", "- if f[w]:", "+ ans[p - 1] += x", "+visit = [False] * N", "+", "+", "+def dfs(n):", "+ visit[n] = True", "+ for go in root[n]:", "+ if visit[go]:", "- f[w] = 1", "- s[w] += c", "- que.append(w)", "-print((*s))", "+ ans[go] += ans[n]", "+ dfs(go)", "+", "+", "+dfs(0)", "+print((*ans))" ]
false
0.035622
0.03678
0.968514
[ "s010168948", "s254466923" ]
u970197315
p02755
python
s101780997
s417932966
115
23
3,064
2,940
Accepted
Accepted
80
# ABC158 C a,b=list(map(int,input().split())) # x=a*(100/8) # y=b*(100/10) # print(x,y) # print(int(x),int(y)) # sx=x*((108-8)/100) # sy=y*((110-10)/100) # print(int(sx),int(sy)) for i in range(200000): x,y=0.0,0.0 x=i*0.08 y=i*0.10 if a==int(x) and b==int(y): print(i) exit() print((-1))
a,b=list(map(int,input().split())) for i in range(1,10001): tax_a=int(i*0.08) tax_b=int(i*0.10) if tax_a==a and tax_b==b: print(i) exit(0) print((-1))
21
8
336
163
# ABC158 C a, b = list(map(int, input().split())) # x=a*(100/8) # y=b*(100/10) # print(x,y) # print(int(x),int(y)) # sx=x*((108-8)/100) # sy=y*((110-10)/100) # print(int(sx),int(sy)) for i in range(200000): x, y = 0.0, 0.0 x = i * 0.08 y = i * 0.10 if a == int(x) and b == int(y): print(i) exit() print((-1))
a, b = list(map(int, input().split())) for i in range(1, 10001): tax_a = int(i * 0.08) tax_b = int(i * 0.10) if tax_a == a and tax_b == b: print(i) exit(0) print((-1))
false
61.904762
[ "-# ABC158 C", "-# x=a*(100/8)", "-# y=b*(100/10)", "-# print(x,y)", "-# print(int(x),int(y))", "-# sx=x*((108-8)/100)", "-# sy=y*((110-10)/100)", "-# print(int(sx),int(sy))", "-for i in range(200000):", "- x, y = 0.0, 0.0", "- x = i * 0.08", "- y = i * 0.10", "- if a == int(x) and b == int(y):", "+for i in range(1, 10001):", "+ tax_a = int(i * 0.08)", "+ tax_b = int(i * 0.10)", "+ if tax_a == a and tax_b == b:", "- exit()", "+ exit(0)" ]
false
0.082068
0.037602
2.182571
[ "s101780997", "s417932966" ]
u287500079
p02953
python
s638243177
s385187198
96
81
14,396
14,252
Accepted
Accepted
15.62
#https://atcoder.jp/contests/abc136/tasks/abc136_c n = int(eval(input())) h = [int(i) for i in input().split()] a = [] flag = 'Yes' for i in reversed(list(range(n - 1))): if h[i+1] - h[i] < 0 and h[i+1] - h[i] > -2: h[i] -= 1 elif h[i+1] - h[i] < -1: flag = 'No' print(flag)
#https://atcoder.jp/contests/abc136/tasks/abc136_c n = int(eval(input())) h = [int(i) for i in input().split()] flag = 'Yes' for i in reversed(list(range(n - 1))): if h[i+1] - h[i] < 0 and h[i+1] - h[i] > -2: h[i] -= 1 elif h[i+1] - h[i] <= -2: flag = 'No' break print(flag)
13
13
300
308
# https://atcoder.jp/contests/abc136/tasks/abc136_c n = int(eval(input())) h = [int(i) for i in input().split()] a = [] flag = "Yes" for i in reversed(list(range(n - 1))): if h[i + 1] - h[i] < 0 and h[i + 1] - h[i] > -2: h[i] -= 1 elif h[i + 1] - h[i] < -1: flag = "No" print(flag)
# https://atcoder.jp/contests/abc136/tasks/abc136_c n = int(eval(input())) h = [int(i) for i in input().split()] flag = "Yes" for i in reversed(list(range(n - 1))): if h[i + 1] - h[i] < 0 and h[i + 1] - h[i] > -2: h[i] -= 1 elif h[i + 1] - h[i] <= -2: flag = "No" break print(flag)
false
0
[ "-a = []", "- elif h[i + 1] - h[i] < -1:", "+ elif h[i + 1] - h[i] <= -2:", "+ break" ]
false
0.043629
0.04442
0.982187
[ "s638243177", "s385187198" ]
u888092736
p02773
python
s452908148
s172773306
650
514
32,852
32,860
Accepted
Accepted
20.92
from collections import Counter N = int(input()) S = Counter(input() for _ in range(N)) max_app = max(S.values()) ans = sorted(k for k, v in S.items() if v == max_app) [print(string) for string in ans]
from collections import Counter N = int(eval(input())) S = Counter(eval(input()) for _ in range(N)) max_app = max(S.values()) print(('\n'.join(sorted(k for k, v in list(S.items()) if v == max_app))))
8
7
211
188
from collections import Counter N = int(input()) S = Counter(input() for _ in range(N)) max_app = max(S.values()) ans = sorted(k for k, v in S.items() if v == max_app) [print(string) for string in ans]
from collections import Counter N = int(eval(input())) S = Counter(eval(input()) for _ in range(N)) max_app = max(S.values()) print(("\n".join(sorted(k for k, v in list(S.items()) if v == max_app))))
false
12.5
[ "-N = int(input())", "-S = Counter(input() for _ in range(N))", "+N = int(eval(input()))", "+S = Counter(eval(input()) for _ in range(N))", "-ans = sorted(k for k, v in S.items() if v == max_app)", "-[print(string) for string in ans]", "+print((\"\\n\".join(sorted(k for k, v in list(S.items()) if v == max_app))))" ]
false
0.090759
0.047309
1.918449
[ "s452908148", "s172773306" ]
u761320129
p03283
python
s982538437
s720699904
1,195
732
44,328
49,948
Accepted
Accepted
38.74
N,M,Q = list(map(int,input().split())) src = [tuple(map(int,input().split())) for i in range(M)] qs = [tuple(map(int,input().split())) for i in range(Q)] imos = [[0]*(N+1) for i in range(N+1)] for l,r in src: imos[l][r] += 1 for i in range(N+1): for j in range(N): imos[i][j+1] += imos[i][j] for i in range(N): for j in range(N+1): imos[i+1][j] += imos[i][j] for p,q in qs: ans = imos[p-1][p-1] + imos[q][q] - imos[p-1][q] - imos[q][p-1] print(ans)
import sys input = sys.stdin.readline N,M,Q = map(int,input().split()) LR = [tuple(map(int,input().split())) for i in range(M)] PQ = [tuple(map(int,input().split())) for i in range(Q)] imos = [[0]*(N+1) for _ in range(N+1)] for l,r in LR: imos[l][r] += 1 for i in range(N+1): for j in range(N): imos[i][j+1] += imos[i][j] for j in range(N+1): for i in range(N): imos[i+1][j] += imos[i][j] ans = [] for p,q in PQ: p -= 1 a = imos[q][q] + imos[p][p] - imos[p][q] - imos[q][p] ans.append(a) print(*ans, sep='\n')
18
22
498
572
N, M, Q = list(map(int, input().split())) src = [tuple(map(int, input().split())) for i in range(M)] qs = [tuple(map(int, input().split())) for i in range(Q)] imos = [[0] * (N + 1) for i in range(N + 1)] for l, r in src: imos[l][r] += 1 for i in range(N + 1): for j in range(N): imos[i][j + 1] += imos[i][j] for i in range(N): for j in range(N + 1): imos[i + 1][j] += imos[i][j] for p, q in qs: ans = imos[p - 1][p - 1] + imos[q][q] - imos[p - 1][q] - imos[q][p - 1] print(ans)
import sys input = sys.stdin.readline N, M, Q = map(int, input().split()) LR = [tuple(map(int, input().split())) for i in range(M)] PQ = [tuple(map(int, input().split())) for i in range(Q)] imos = [[0] * (N + 1) for _ in range(N + 1)] for l, r in LR: imos[l][r] += 1 for i in range(N + 1): for j in range(N): imos[i][j + 1] += imos[i][j] for j in range(N + 1): for i in range(N): imos[i + 1][j] += imos[i][j] ans = [] for p, q in PQ: p -= 1 a = imos[q][q] + imos[p][p] - imos[p][q] - imos[q][p] ans.append(a) print(*ans, sep="\n")
false
18.181818
[ "-N, M, Q = list(map(int, input().split()))", "-src = [tuple(map(int, input().split())) for i in range(M)]", "-qs = [tuple(map(int, input().split())) for i in range(Q)]", "-imos = [[0] * (N + 1) for i in range(N + 1)]", "-for l, r in src:", "+import sys", "+", "+input = sys.stdin.readline", "+N, M, Q = map(int, input().split())", "+LR = [tuple(map(int, input().split())) for i in range(M)]", "+PQ = [tuple(map(int, input().split())) for i in range(Q)]", "+imos = [[0] * (N + 1) for _ in range(N + 1)]", "+for l, r in LR:", "-for i in range(N):", "- for j in range(N + 1):", "+for j in range(N + 1):", "+ for i in range(N):", "-for p, q in qs:", "- ans = imos[p - 1][p - 1] + imos[q][q] - imos[p - 1][q] - imos[q][p - 1]", "- print(ans)", "+ans = []", "+for p, q in PQ:", "+ p -= 1", "+ a = imos[q][q] + imos[p][p] - imos[p][q] - imos[q][p]", "+ ans.append(a)", "+print(*ans, sep=\"\\n\")" ]
false
0.041062
0.033643
1.220526
[ "s982538437", "s720699904" ]
u411203878
p03137
python
s250074355
s816183280
225
104
56,872
90,704
Accepted
Accepted
53.78
n,m = list(map(int,input().split())) t = list(map(int,input().split())) t.sort() memo = [] for i in range(m-1): memo.append(t[i+1]-t[i]) memo.sort() #print(memo) ans = 0 for i in range(m-n): #print(i) ans += memo[i] print(ans)
N,M = list(map(int,input().split())) X = list(map(int,input().split())) X.sort() memo = [] for i in range(1,M): memo.append(X[i]-X[i-1]) memo.sort() #print(memo) ans = 0 for i in range(M-N): ans += memo[i] print(ans)
15
17
248
239
n, m = list(map(int, input().split())) t = list(map(int, input().split())) t.sort() memo = [] for i in range(m - 1): memo.append(t[i + 1] - t[i]) memo.sort() # print(memo) ans = 0 for i in range(m - n): # print(i) ans += memo[i] print(ans)
N, M = list(map(int, input().split())) X = list(map(int, input().split())) X.sort() memo = [] for i in range(1, M): memo.append(X[i] - X[i - 1]) memo.sort() # print(memo) ans = 0 for i in range(M - N): ans += memo[i] print(ans)
false
11.764706
[ "-n, m = list(map(int, input().split()))", "-t = list(map(int, input().split()))", "-t.sort()", "+N, M = list(map(int, input().split()))", "+X = list(map(int, input().split()))", "+X.sort()", "-for i in range(m - 1):", "- memo.append(t[i + 1] - t[i])", "+for i in range(1, M):", "+ memo.append(X[i] - X[i - 1])", "-for i in range(m - n):", "- # print(i)", "+for i in range(M - N):" ]
false
0.042789
0.113493
0.377021
[ "s250074355", "s816183280" ]
u375616706
p03967
python
s071611269
s894268160
38
29
3,316
3,188
Accepted
Accepted
23.68
s = eval(input()) l = len(s) point = 0 cnt = 0 for i in s: if cnt > 0: cnt -= 1 if i == 'g': point += 1 else: cnt += 1 if i == 'p': point -= 1 print(point)
s = eval(input()) l = len(s) point = 0 for a, b in zip(s[0::2], s[1::2]): if a == 'p': point -= 1 if b == 'g': point += 1 print(point)
16
11
231
165
s = eval(input()) l = len(s) point = 0 cnt = 0 for i in s: if cnt > 0: cnt -= 1 if i == "g": point += 1 else: cnt += 1 if i == "p": point -= 1 print(point)
s = eval(input()) l = len(s) point = 0 for a, b in zip(s[0::2], s[1::2]): if a == "p": point -= 1 if b == "g": point += 1 print(point)
false
31.25
[ "-cnt = 0", "-for i in s:", "- if cnt > 0:", "- cnt -= 1", "- if i == \"g\":", "- point += 1", "- else:", "- cnt += 1", "- if i == \"p\":", "- point -= 1", "+for a, b in zip(s[0::2], s[1::2]):", "+ if a == \"p\":", "+ point -= 1", "+ if b == \"g\":", "+ point += 1" ]
false
0.044083
0.119925
0.367591
[ "s071611269", "s894268160" ]
u347640436
p03317
python
s559682667
s626728912
40
17
13,940
2,940
Accepted
Accepted
57.5
from sys import stdin n, k, *a = list(map(int, stdin.read().split())) print((((n - 1) + (k - 2)) // (k - 1)))
n, k = list(map(int, input().split())) print((((n - 1) + (k - 2)) // (k - 1)))
3
2
104
72
from sys import stdin n, k, *a = list(map(int, stdin.read().split())) print((((n - 1) + (k - 2)) // (k - 1)))
n, k = list(map(int, input().split())) print((((n - 1) + (k - 2)) // (k - 1)))
false
33.333333
[ "-from sys import stdin", "-", "-n, k, *a = list(map(int, stdin.read().split()))", "+n, k = list(map(int, input().split()))" ]
false
0.035612
0.100201
0.355407
[ "s559682667", "s626728912" ]
u192154323
p03062
python
s709334898
s995394054
105
80
15,020
20,064
Accepted
Accepted
23.81
n = int(eval(input())) a_ls = list(map(int, input().split())) num_minus = 0 Min = float('inf') Sum = 0 for i in range(n): if a_ls[i] < 0: num_minus += 1 Min = min(abs(a_ls[i]),Min) Sum += abs(a_ls[i]) if num_minus % 2 == 0: ans = Sum else: ans = Sum - 2 * Min print(ans)
N = int(eval(input())) a_ls = list(map(int, input().split())) abs_ls = [0] * N minus = 0 for i in range(N): if a_ls[i] < 0: minus += 1 abs_ls[i] = abs(a_ls[i]) if minus % 2 == 1: ans = sum(abs_ls) - 2 * min(abs_ls) else: ans = sum(abs_ls) print(ans)
16
14
309
281
n = int(eval(input())) a_ls = list(map(int, input().split())) num_minus = 0 Min = float("inf") Sum = 0 for i in range(n): if a_ls[i] < 0: num_minus += 1 Min = min(abs(a_ls[i]), Min) Sum += abs(a_ls[i]) if num_minus % 2 == 0: ans = Sum else: ans = Sum - 2 * Min print(ans)
N = int(eval(input())) a_ls = list(map(int, input().split())) abs_ls = [0] * N minus = 0 for i in range(N): if a_ls[i] < 0: minus += 1 abs_ls[i] = abs(a_ls[i]) if minus % 2 == 1: ans = sum(abs_ls) - 2 * min(abs_ls) else: ans = sum(abs_ls) print(ans)
false
12.5
[ "-n = int(eval(input()))", "+N = int(eval(input()))", "-num_minus = 0", "-Min = float(\"inf\")", "-Sum = 0", "-for i in range(n):", "+abs_ls = [0] * N", "+minus = 0", "+for i in range(N):", "- num_minus += 1", "- Min = min(abs(a_ls[i]), Min)", "- Sum += abs(a_ls[i])", "-if num_minus % 2 == 0:", "- ans = Sum", "+ minus += 1", "+ abs_ls[i] = abs(a_ls[i])", "+if minus % 2 == 1:", "+ ans = sum(abs_ls) - 2 * min(abs_ls)", "- ans = Sum - 2 * Min", "+ ans = sum(abs_ls)" ]
false
0.037343
0.075685
0.493403
[ "s709334898", "s995394054" ]
u562935282
p02743
python
s275321556
s735342599
42
19
5,460
2,940
Accepted
Accepted
54.76
def main(): from decimal import Decimal a, b, c = list(map(int, input().split())) x = Decimal(a).sqrt() y = Decimal(b).sqrt() z = Decimal(c).sqrt() print(('Yes' if x + y < z else 'No')) if __name__ == '__main__': main() # import sys # # sys.setrecursionlimit(10 ** 7) # # input = sys.stdin.readline # rstrip() # int(input()) # map(int, input().split())
def main(): a, b, c = list(map(int, input().split())) if c - a - b < 0: print('No') return res = 'Yes' if 4 * a * b < (c - a - b) * (c - a - b) else 'No' print(res) if __name__ == '__main__': main()
22
12
399
243
def main(): from decimal import Decimal a, b, c = list(map(int, input().split())) x = Decimal(a).sqrt() y = Decimal(b).sqrt() z = Decimal(c).sqrt() print(("Yes" if x + y < z else "No")) if __name__ == "__main__": main() # import sys # # sys.setrecursionlimit(10 ** 7) # # input = sys.stdin.readline # rstrip() # int(input()) # map(int, input().split())
def main(): a, b, c = list(map(int, input().split())) if c - a - b < 0: print("No") return res = "Yes" if 4 * a * b < (c - a - b) * (c - a - b) else "No" print(res) if __name__ == "__main__": main()
false
45.454545
[ "- from decimal import Decimal", "-", "- x = Decimal(a).sqrt()", "- y = Decimal(b).sqrt()", "- z = Decimal(c).sqrt()", "- print((\"Yes\" if x + y < z else \"No\"))", "+ if c - a - b < 0:", "+ print(\"No\")", "+ return", "+ res = \"Yes\" if 4 * a * b < (c - a - b) * (c - a - b) else \"No\"", "+ print(res)", "-# import sys", "-#", "-# sys.setrecursionlimit(10 ** 7)", "-#", "-# input = sys.stdin.readline", "-# rstrip()", "-# int(input())", "-# map(int, input().split())" ]
false
0.084155
0.079781
1.054836
[ "s275321556", "s735342599" ]
u987164499
p03473
python
s727225529
s554256162
150
29
12,400
9,056
Accepted
Accepted
80.67
from sys import stdin from itertools import combinations from math import factorial import numpy as np import math n = int(stdin.readline().rstrip()) print((24-n+24))
n = int(eval(input())) print((24+24-n))
9
3
174
34
from sys import stdin from itertools import combinations from math import factorial import numpy as np import math n = int(stdin.readline().rstrip()) print((24 - n + 24))
n = int(eval(input())) print((24 + 24 - n))
false
66.666667
[ "-from sys import stdin", "-from itertools import combinations", "-from math import factorial", "-import numpy as np", "-import math", "-", "-n = int(stdin.readline().rstrip())", "-print((24 - n + 24))", "+n = int(eval(input()))", "+print((24 + 24 - n))" ]
false
0.034237
0.03504
0.977102
[ "s727225529", "s554256162" ]
u790710233
p02912
python
s342621855
s002609526
216
169
14,380
14,252
Accepted
Accepted
21.76
import sys from math import floor from heapq import heappush, heappop, heappushpop input = sys.stdin.readline sys.setrecursionlimit(10**7) # 10**5 n, m = list(map(int, input().split())) # 10**9 a = sorted([-int(s) for s in input().split()]) for _ in range(m): x = heappop(a) heappush(a, x/2) print((sum([floor(-x) for x in a])))
import heapq n, m = list(map(int, input().split())) A = list([-int(x) for x in input().split()]) heapq.heapify(A) for _ in range(m): x = heapq.heappop(A)*(-1) x //= 2 heapq.heappush(A, -x) print((-sum(A)))
18
11
361
227
import sys from math import floor from heapq import heappush, heappop, heappushpop input = sys.stdin.readline sys.setrecursionlimit(10**7) # 10**5 n, m = list(map(int, input().split())) # 10**9 a = sorted([-int(s) for s in input().split()]) for _ in range(m): x = heappop(a) heappush(a, x / 2) print((sum([floor(-x) for x in a])))
import heapq n, m = list(map(int, input().split())) A = list([-int(x) for x in input().split()]) heapq.heapify(A) for _ in range(m): x = heapq.heappop(A) * (-1) x //= 2 heapq.heappush(A, -x) print((-sum(A)))
false
38.888889
[ "-import sys", "-from math import floor", "-from heapq import heappush, heappop, heappushpop", "+import heapq", "-input = sys.stdin.readline", "-sys.setrecursionlimit(10**7)", "-# 10**5", "-# 10**9", "-a = sorted([-int(s) for s in input().split()])", "+A = list([-int(x) for x in input().split()])", "+heapq.heapify(A)", "- x = heappop(a)", "- heappush(a, x / 2)", "-print((sum([floor(-x) for x in a])))", "+ x = heapq.heappop(A) * (-1)", "+ x //= 2", "+ heapq.heappush(A, -x)", "+print((-sum(A)))" ]
false
0.088908
0.145747
0.610016
[ "s342621855", "s002609526" ]
u225388820
p02582
python
s105839870
s497839180
78
26
61,648
8,964
Accepted
Accepted
66.67
s = eval(input()) if s[0] == s[1] == s[2] == "R": print((3)) elif s[0] == s[1] == "R" or s[1] == s[2] == "R": print((2)) elif "R" in s: print((1)) else: print((0))
s = eval(input()) if s == "RRR": print((3)) elif "RR" in s: print((2)) elif "R" in s: print((1)) else: print((0))
9
9
173
123
s = eval(input()) if s[0] == s[1] == s[2] == "R": print((3)) elif s[0] == s[1] == "R" or s[1] == s[2] == "R": print((2)) elif "R" in s: print((1)) else: print((0))
s = eval(input()) if s == "RRR": print((3)) elif "RR" in s: print((2)) elif "R" in s: print((1)) else: print((0))
false
0
[ "-if s[0] == s[1] == s[2] == \"R\":", "+if s == \"RRR\":", "-elif s[0] == s[1] == \"R\" or s[1] == s[2] == \"R\":", "+elif \"RR\" in s:" ]
false
0.04176
0.057377
0.727817
[ "s105839870", "s497839180" ]
u714300041
p02936
python
s846946984
s284948312
1,998
1,678
264,112
93,552
Accepted
Accepted
16.02
import sys input = sys.stdin.readline sys.setrecursionlimit(10 ** 7) N, Q = list(map(int, input().split())) class Node(): def __init__(self): self.connected = [] self.count = 0 def add_count(v, p): for c in G[v].connected: if c == p: continue G[c].count += G[v].count add_count(c, v) G = [Node() for _ in range(N)] for _ in range(N-1): a, b = list(map(int, input().split())) G[a-1].connected.append(b-1) G[b-1].connected.append(a-1) for _ in range(Q): p, x = list(map(int, input().split())) G[p-1].count += x add_count(0, -1) counts = [node.count for node in G] print((*counts))
import sys input = sys.stdin.readline sys.setrecursionlimit(10 ** 7) N, Q = list(map(int, input().split())) class Node(): def __init__(self): self.connected = [] self.count = 0 def add_count(v, p): for c in G[v].connected: if c == p: continue G[c].count += G[v].count add_count(c, v) def add_count2(): s = [(0, -1)] while s: v, p = s.pop() for c in G[v].connected: if c == p: continue G[c].count += G[v].count s.append((c, v)) G = [Node() for _ in range(N)] for _ in range(N-1): a, b = list(map(int, input().split())) G[a-1].connected.append(b-1) G[b-1].connected.append(a-1) for _ in range(Q): p, x = list(map(int, input().split())) G[p-1].count += x # add_count(0, -1) add_count2() counts = [node.count for node in G] print((*counts))
37
46
692
933
import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) N, Q = list(map(int, input().split())) class Node: def __init__(self): self.connected = [] self.count = 0 def add_count(v, p): for c in G[v].connected: if c == p: continue G[c].count += G[v].count add_count(c, v) G = [Node() for _ in range(N)] for _ in range(N - 1): a, b = list(map(int, input().split())) G[a - 1].connected.append(b - 1) G[b - 1].connected.append(a - 1) for _ in range(Q): p, x = list(map(int, input().split())) G[p - 1].count += x add_count(0, -1) counts = [node.count for node in G] print((*counts))
import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) N, Q = list(map(int, input().split())) class Node: def __init__(self): self.connected = [] self.count = 0 def add_count(v, p): for c in G[v].connected: if c == p: continue G[c].count += G[v].count add_count(c, v) def add_count2(): s = [(0, -1)] while s: v, p = s.pop() for c in G[v].connected: if c == p: continue G[c].count += G[v].count s.append((c, v)) G = [Node() for _ in range(N)] for _ in range(N - 1): a, b = list(map(int, input().split())) G[a - 1].connected.append(b - 1) G[b - 1].connected.append(a - 1) for _ in range(Q): p, x = list(map(int, input().split())) G[p - 1].count += x # add_count(0, -1) add_count2() counts = [node.count for node in G] print((*counts))
false
19.565217
[ "+def add_count2():", "+ s = [(0, -1)]", "+ while s:", "+ v, p = s.pop()", "+ for c in G[v].connected:", "+ if c == p:", "+ continue", "+ G[c].count += G[v].count", "+ s.append((c, v))", "+", "+", "-add_count(0, -1)", "+# add_count(0, -1)", "+add_count2()" ]
false
0.036496
0.033952
1.074923
[ "s846946984", "s284948312" ]
u133936772
p02624
python
s054889028
s010166640
1,880
1,411
562,508
9,156
Accepted
Accepted
24.95
n=int(eval(input())) from itertools import * s=[*accumulate(list(range(n+1)))] print((sum(i*s[n//i] for i in range(1,n+1))))
n=int(eval(input())) print((sum(n//i*(n//i+1)*i//2 for i in range(1,n+1))))
4
2
113
68
n = int(eval(input())) from itertools import * s = [*accumulate(list(range(n + 1)))] print((sum(i * s[n // i] for i in range(1, n + 1))))
n = int(eval(input())) print((sum(n // i * (n // i + 1) * i // 2 for i in range(1, n + 1))))
false
50
[ "-from itertools import *", "-", "-s = [*accumulate(list(range(n + 1)))]", "-print((sum(i * s[n // i] for i in range(1, n + 1))))", "+print((sum(n // i * (n // i + 1) * i // 2 for i in range(1, n + 1))))" ]
false
0.526373
1.021886
0.515099
[ "s054889028", "s010166640" ]
u847467233
p00015
python
s532685023
s983096256
30
20
5,584
5,592
Accepted
Accepted
33.33
# AOJ 0015 National Budget # Python3 2018.6.9 bal4u n = int(eval(input())) for i in range(n): a = str(eval(input())) b = str(eval(input())) if len(a) > 80 or len(b) > 80: print('overflow') else: s = str(int(a)+int(b)) if len(s) <= 80: print(s) else: print('overflow')
# AOJ 0015 National Budget # Python3 2018.6.9 bal4u n = int(eval(input())) for i in range(n): s = int(eval(input())) + int(eval(input())) if len(str(s)) <= 80: print(s) else: print('overflow')
15
10
337
213
# AOJ 0015 National Budget # Python3 2018.6.9 bal4u n = int(eval(input())) for i in range(n): a = str(eval(input())) b = str(eval(input())) if len(a) > 80 or len(b) > 80: print("overflow") else: s = str(int(a) + int(b)) if len(s) <= 80: print(s) else: print("overflow")
# AOJ 0015 National Budget # Python3 2018.6.9 bal4u n = int(eval(input())) for i in range(n): s = int(eval(input())) + int(eval(input())) if len(str(s)) <= 80: print(s) else: print("overflow")
false
33.333333
[ "- a = str(eval(input()))", "- b = str(eval(input()))", "- if len(a) > 80 or len(b) > 80:", "+ s = int(eval(input())) + int(eval(input()))", "+ if len(str(s)) <= 80:", "+ print(s)", "+ else:", "- else:", "- s = str(int(a) + int(b))", "- if len(s) <= 80:", "- print(s)", "- else:", "- print(\"overflow\")" ]
false
0.037627
0.07028
0.535381
[ "s532685023", "s983096256" ]
u774160580
p03107
python
s953024275
s645277198
185
77
44,892
3,956
Accepted
Accepted
58.38
S = eval(input()) a = sum([int(S[i]) for i in range(len(S))]) b = len(S) - a print((2*min(a, b)))
S = eval(input()) stack = [] stack.append(S[0]) for i in range(1, len(S)): if len(stack) == 0: stack.append(S[i]) continue cube = stack.pop() if cube != S[i]: continue stack.append(cube) stack.append(S[i]) print((len(S) - len(stack)))
4
13
92
283
S = eval(input()) a = sum([int(S[i]) for i in range(len(S))]) b = len(S) - a print((2 * min(a, b)))
S = eval(input()) stack = [] stack.append(S[0]) for i in range(1, len(S)): if len(stack) == 0: stack.append(S[i]) continue cube = stack.pop() if cube != S[i]: continue stack.append(cube) stack.append(S[i]) print((len(S) - len(stack)))
false
69.230769
[ "-a = sum([int(S[i]) for i in range(len(S))])", "-b = len(S) - a", "-print((2 * min(a, b)))", "+stack = []", "+stack.append(S[0])", "+for i in range(1, len(S)):", "+ if len(stack) == 0:", "+ stack.append(S[i])", "+ continue", "+ cube = stack.pop()", "+ if cube != S[i]:", "+ continue", "+ stack.append(cube)", "+ stack.append(S[i])", "+print((len(S) - len(stack)))" ]
false
0.036383
0.037859
0.961011
[ "s953024275", "s645277198" ]
u847541068
p03086
python
s026806822
s101331785
32
29
9,116
8,992
Accepted
Accepted
9.38
def main(): s = eval(input()) ans = 0 seq = 0 for c in s: if c == 'A' or c == 'C' or c == 'T' or c == 'G': seq+=1 else: ans = max(ans,seq) seq=0 else: ans = max(ans,seq) print(ans) if __name__ == '__main__': main()
if __name__ =='__main__': s = eval(input()) ans = 0 seq = 0 for c in s: if c=='A' or c=='T' or c=='G' or c=='C': seq+=1 else: ans = max(ans,seq) seq=0 ans = max(ans,seq) print(ans)
17
12
314
261
def main(): s = eval(input()) ans = 0 seq = 0 for c in s: if c == "A" or c == "C" or c == "T" or c == "G": seq += 1 else: ans = max(ans, seq) seq = 0 else: ans = max(ans, seq) print(ans) if __name__ == "__main__": main()
if __name__ == "__main__": s = eval(input()) ans = 0 seq = 0 for c in s: if c == "A" or c == "T" or c == "G" or c == "C": seq += 1 else: ans = max(ans, seq) seq = 0 ans = max(ans, seq) print(ans)
false
29.411765
[ "-def main():", "+if __name__ == \"__main__\":", "- if c == \"A\" or c == \"C\" or c == \"T\" or c == \"G\":", "+ if c == \"A\" or c == \"T\" or c == \"G\" or c == \"C\":", "- else:", "- ans = max(ans, seq)", "+ ans = max(ans, seq)", "-", "-", "-if __name__ == \"__main__\":", "- main()" ]
false
0.042995
0.089599
0.479858
[ "s026806822", "s101331785" ]
u077127204
p03574
python
s453433180
s221537443
362
291
21,400
20,156
Accepted
Accepted
19.61
import numpy as np from collections import defaultdict H, W = list(map(int, input().split())) S = np.array([list(eval(input())) for _ in range(H)]) for i in range(H): for j in range(W): if S[i, j] == '.': d = defaultdict(int) S[i, j] = np.sum(S[max(i-1, 0):i+2, max(j-1, 0):j+2] == '#') for s in S: print((''.join(s)))
import numpy as np H, W = list(map(int, input().split())) S = np.array([list(eval(input())) for _ in range(H)]) for i in range(H): for j in range(W): if S[i, j] == '.': S[i, j] = np.sum(S[max(i-1, 0):i+2, max(j-1, 0):j+2] == '#') for s in S: print((''.join(s)))
13
11
340
276
import numpy as np from collections import defaultdict H, W = list(map(int, input().split())) S = np.array([list(eval(input())) for _ in range(H)]) for i in range(H): for j in range(W): if S[i, j] == ".": d = defaultdict(int) S[i, j] = np.sum(S[max(i - 1, 0) : i + 2, max(j - 1, 0) : j + 2] == "#") for s in S: print(("".join(s)))
import numpy as np H, W = list(map(int, input().split())) S = np.array([list(eval(input())) for _ in range(H)]) for i in range(H): for j in range(W): if S[i, j] == ".": S[i, j] = np.sum(S[max(i - 1, 0) : i + 2, max(j - 1, 0) : j + 2] == "#") for s in S: print(("".join(s)))
false
15.384615
[ "-from collections import defaultdict", "- d = defaultdict(int)" ]
false
0.491516
0.423156
1.161548
[ "s453433180", "s221537443" ]
u504562455
p02719
python
s332632370
s131265419
169
19
38,256
9,100
Accepted
Accepted
88.76
N, K = [int(_) for _ in input().split()] N = N % K if N * 2 > K: print((K - N)) else: print(N)
# N = int(input()) N, K = [int(_) for _ in input().split()] N = N % K print((min(abs(N-K), N)))
6
4
106
97
N, K = [int(_) for _ in input().split()] N = N % K if N * 2 > K: print((K - N)) else: print(N)
# N = int(input()) N, K = [int(_) for _ in input().split()] N = N % K print((min(abs(N - K), N)))
false
33.333333
[ "+# N = int(input())", "-if N * 2 > K:", "- print((K - N))", "-else:", "- print(N)", "+print((min(abs(N - K), N)))" ]
false
0.070501
0.035781
1.970337
[ "s332632370", "s131265419" ]
u165133750
p03310
python
s928206897
s808734353
1,566
1,087
25,672
24,136
Accepted
Accepted
30.59
n = int(eval(input())) A = list(map(int, input().split())) F = [int()] * n F[0] = A[0] for b in range(1, n): F[b] = F[b - 1] + A[b] res = [0]*4 data = [10 ** 18] * 2 ex = [0]*4 ans = 10 ** 18 s = 0 t = 2 for i in range(1, n - 2): bl = [True, True] for j in range(s, i): res[0] = F[j] res[1] = F[i] - F[j] if not bl[0]: break if data[0] > abs(res[1] - res[0]) or j == s: s = j ex[0] = res[0] ex[1] = res[1] data[0] = abs(res[1] - res[0]) else: bl[0] = False for k in range(t, n): res[2] = F[k] - F[i] res[3] = F[n - 1] - F[k] if not bl[1]: break if data[1] > abs(res[3] - res[2]) or k == t: t = k ex[2] = res[2] ex[3] = res[3] data[1] = abs(res[3] - res[2]) else: bl[1] = False ans = min(ans, max(ex) - min(ex)) print(ans)
import sys input = sys.stdin.readline def main(): n = int(eval(input())) A = list(map(int, input().split())) F = [int()] * n F[0] = A[0] for b in range(1, n): F[b] = F[b - 1] + A[b] res = [0]*4 data = [10 ** 18] * 2 ex = [0]*4 ans = 10 ** 18 s = 0 t = 2 for i in range(1, n - 2): bl = [True, True] for j in range(s, i): res[0] = F[j] res[1] = F[i] - F[j] if not bl[0]: break if data[0] > abs(res[1] - res[0]) or j == s: s = j ex[0] = res[0] ex[1] = res[1] data[0] = abs(res[1] - res[0]) else: bl[0] = False for k in range(t, n): res[2] = F[k] - F[i] res[3] = F[n - 1] - F[k] if not bl[1]: break if data[1] > abs(res[3] - res[2]) or k == t: t = k ex[2] = res[2] ex[3] = res[3] data[1] = abs(res[3] - res[2]) else: bl[1] = False ans = min(ans, max(ex) - min(ex)) print(ans) if __name__ == '__main__': main()
43
50
1,004
1,262
n = int(eval(input())) A = list(map(int, input().split())) F = [int()] * n F[0] = A[0] for b in range(1, n): F[b] = F[b - 1] + A[b] res = [0] * 4 data = [10**18] * 2 ex = [0] * 4 ans = 10**18 s = 0 t = 2 for i in range(1, n - 2): bl = [True, True] for j in range(s, i): res[0] = F[j] res[1] = F[i] - F[j] if not bl[0]: break if data[0] > abs(res[1] - res[0]) or j == s: s = j ex[0] = res[0] ex[1] = res[1] data[0] = abs(res[1] - res[0]) else: bl[0] = False for k in range(t, n): res[2] = F[k] - F[i] res[3] = F[n - 1] - F[k] if not bl[1]: break if data[1] > abs(res[3] - res[2]) or k == t: t = k ex[2] = res[2] ex[3] = res[3] data[1] = abs(res[3] - res[2]) else: bl[1] = False ans = min(ans, max(ex) - min(ex)) print(ans)
import sys input = sys.stdin.readline def main(): n = int(eval(input())) A = list(map(int, input().split())) F = [int()] * n F[0] = A[0] for b in range(1, n): F[b] = F[b - 1] + A[b] res = [0] * 4 data = [10**18] * 2 ex = [0] * 4 ans = 10**18 s = 0 t = 2 for i in range(1, n - 2): bl = [True, True] for j in range(s, i): res[0] = F[j] res[1] = F[i] - F[j] if not bl[0]: break if data[0] > abs(res[1] - res[0]) or j == s: s = j ex[0] = res[0] ex[1] = res[1] data[0] = abs(res[1] - res[0]) else: bl[0] = False for k in range(t, n): res[2] = F[k] - F[i] res[3] = F[n - 1] - F[k] if not bl[1]: break if data[1] > abs(res[3] - res[2]) or k == t: t = k ex[2] = res[2] ex[3] = res[3] data[1] = abs(res[3] - res[2]) else: bl[1] = False ans = min(ans, max(ex) - min(ex)) print(ans) if __name__ == "__main__": main()
false
14
[ "-n = int(eval(input()))", "-A = list(map(int, input().split()))", "-F = [int()] * n", "-F[0] = A[0]", "-for b in range(1, n):", "- F[b] = F[b - 1] + A[b]", "-res = [0] * 4", "-data = [10**18] * 2", "-ex = [0] * 4", "-ans = 10**18", "-s = 0", "-t = 2", "-for i in range(1, n - 2):", "- bl = [True, True]", "- for j in range(s, i):", "- res[0] = F[j]", "- res[1] = F[i] - F[j]", "- if not bl[0]:", "- break", "- if data[0] > abs(res[1] - res[0]) or j == s:", "- s = j", "- ex[0] = res[0]", "- ex[1] = res[1]", "- data[0] = abs(res[1] - res[0])", "- else:", "- bl[0] = False", "- for k in range(t, n):", "- res[2] = F[k] - F[i]", "- res[3] = F[n - 1] - F[k]", "- if not bl[1]:", "- break", "- if data[1] > abs(res[3] - res[2]) or k == t:", "- t = k", "- ex[2] = res[2]", "- ex[3] = res[3]", "- data[1] = abs(res[3] - res[2])", "- else:", "- bl[1] = False", "- ans = min(ans, max(ex) - min(ex))", "-print(ans)", "+import sys", "+", "+input = sys.stdin.readline", "+", "+", "+def main():", "+ n = int(eval(input()))", "+ A = list(map(int, input().split()))", "+ F = [int()] * n", "+ F[0] = A[0]", "+ for b in range(1, n):", "+ F[b] = F[b - 1] + A[b]", "+ res = [0] * 4", "+ data = [10**18] * 2", "+ ex = [0] * 4", "+ ans = 10**18", "+ s = 0", "+ t = 2", "+ for i in range(1, n - 2):", "+ bl = [True, True]", "+ for j in range(s, i):", "+ res[0] = F[j]", "+ res[1] = F[i] - F[j]", "+ if not bl[0]:", "+ break", "+ if data[0] > abs(res[1] - res[0]) or j == s:", "+ s = j", "+ ex[0] = res[0]", "+ ex[1] = res[1]", "+ data[0] = abs(res[1] - res[0])", "+ else:", "+ bl[0] = False", "+ for k in range(t, n):", "+ res[2] = F[k] - F[i]", "+ res[3] = F[n - 1] - F[k]", "+ if not bl[1]:", "+ break", "+ if data[1] > abs(res[3] - res[2]) or k == t:", "+ t = k", "+ ex[2] = res[2]", "+ ex[3] = res[3]", "+ data[1] = abs(res[3] - res[2])", "+ else:", "+ bl[1] = False", "+ ans = min(ans, max(ex) - min(ex))", "+ print(ans)", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.045271
0.04613
0.981384
[ "s928206897", "s808734353" ]
u966000628
p03160
python
s984833862
s509988271
217
181
13,928
13,924
Accepted
Accepted
16.59
n = int(eval(input())) h = list(map(int, input().split())) cost = [float('inf') for _ in range(n)] cost[0] = 0 for x in range(n): if x + 1 < n: cost[x + 1] = min(cost[x + 1], cost[x] + abs(h[x + 1] - h[x])) if x + 2 < n: cost[x + 2] = min(cost[x + 2], cost[x] + abs(h[x + 2] - h[x])) print((cost[n - 1]))
n = int(eval(input())) h = list(map(int, input().split())) cost = [9999999999] * n cost[0] = 0 for x in range(n): if x + 1 < n: cost[x + 1] = min(cost[x + 1], cost[x] + abs(h[x + 1] - h[x])) if x + 2 < n: cost[x + 2] = min(cost[x + 2], cost[x] + abs(h[x + 2] - h[x])) print((cost[n - 1]))
14
14
342
326
n = int(eval(input())) h = list(map(int, input().split())) cost = [float("inf") for _ in range(n)] cost[0] = 0 for x in range(n): if x + 1 < n: cost[x + 1] = min(cost[x + 1], cost[x] + abs(h[x + 1] - h[x])) if x + 2 < n: cost[x + 2] = min(cost[x + 2], cost[x] + abs(h[x + 2] - h[x])) print((cost[n - 1]))
n = int(eval(input())) h = list(map(int, input().split())) cost = [9999999999] * n cost[0] = 0 for x in range(n): if x + 1 < n: cost[x + 1] = min(cost[x + 1], cost[x] + abs(h[x + 1] - h[x])) if x + 2 < n: cost[x + 2] = min(cost[x + 2], cost[x] + abs(h[x + 2] - h[x])) print((cost[n - 1]))
false
0
[ "-cost = [float(\"inf\") for _ in range(n)]", "+cost = [9999999999] * n" ]
false
0.08165
0.095275
0.856993
[ "s984833862", "s509988271" ]
u269778596
p02707
python
s856000679
s544606284
191
132
116,424
116,692
Accepted
Accepted
30.89
size = int(eval(input())) li = list(map(int,input().split())) from collections import Counter c1 = Counter(li) ans2 = [0] * size for i,j in list(c1.items()): ans2[i-1] = j for i in ans2: print(i)
from sys import stdin,stdout size = int(stdin.readline()) li = list(map(int,stdin.readline().split())) """ans = [0]*size for i in li: if i not in ans: ans[i-1] = 1 else: ans[i-1] += 1 for i in ans: print(i) """ from collections import Counter c1 = Counter(li) ans2 = [0] * size for i,j in list(c1.items()): ans2[i-1] = j for i in ans2: stdout.write(str(i)+"\n")
9
19
199
410
size = int(eval(input())) li = list(map(int, input().split())) from collections import Counter c1 = Counter(li) ans2 = [0] * size for i, j in list(c1.items()): ans2[i - 1] = j for i in ans2: print(i)
from sys import stdin, stdout size = int(stdin.readline()) li = list(map(int, stdin.readline().split())) """ans = [0]*size for i in li: if i not in ans: ans[i-1] = 1 else: ans[i-1] += 1 for i in ans: print(i) """ from collections import Counter c1 = Counter(li) ans2 = [0] * size for i, j in list(c1.items()): ans2[i - 1] = j for i in ans2: stdout.write(str(i) + "\n")
false
52.631579
[ "-size = int(eval(input()))", "-li = list(map(int, input().split()))", "+from sys import stdin, stdout", "+", "+size = int(stdin.readline())", "+li = list(map(int, stdin.readline().split()))", "+\"\"\"ans = [0]*size", "+for i in li:", "+ if i not in ans:", "+ ans[i-1] = 1", "+ else:", "+ ans[i-1] += 1", "+for i in ans:", "+ print(i)", "+\"\"\"", "- print(i)", "+ stdout.write(str(i) + \"\\n\")" ]
false
0.073984
0.00702
10.538778
[ "s856000679", "s544606284" ]
u638709900
p02988
python
s146056403
s945500883
21
17
3,316
3,064
Accepted
Accepted
19.05
n = int(eval(input())) p = list(map(int, input().split())) count = 0 for i in range(1,len(p)-1,1): if p[i+1] > p[i] > p[i-1]: count = count +1 elif p[i+1] < p[i] < p[i-1]: count = count +1 else: pass print(count)
n = int(eval(input())) p = list(map(int, input().split())) count = 0 for i in range(1,n-1,1): if p[i+1] > p[i] > p[i-1]: count = count +1 elif p[i+1] < p[i] < p[i-1]: count = count +1 else: pass print(count)
13
13
256
251
n = int(eval(input())) p = list(map(int, input().split())) count = 0 for i in range(1, len(p) - 1, 1): if p[i + 1] > p[i] > p[i - 1]: count = count + 1 elif p[i + 1] < p[i] < p[i - 1]: count = count + 1 else: pass print(count)
n = int(eval(input())) p = list(map(int, input().split())) count = 0 for i in range(1, n - 1, 1): if p[i + 1] > p[i] > p[i - 1]: count = count + 1 elif p[i + 1] < p[i] < p[i - 1]: count = count + 1 else: pass print(count)
false
0
[ "-for i in range(1, len(p) - 1, 1):", "+for i in range(1, n - 1, 1):" ]
false
0.045575
0.045989
0.991011
[ "s146056403", "s945500883" ]
u170201762
p03682
python
s199629627
s134605828
1,684
1,517
93,660
82,128
Accepted
Accepted
9.92
N = int(eval(input())) z = [tuple(map(int,input().split())) for i in range(N)] z.sort() y = [(z[i][1],i) for i in range(N)] y.sort() cost = [[] for i in range(N)] for i in range(N-1): j = y[i][1] cost[i].append((i-1,min(abs(z[i][0]-z[i-1][0]),abs(z[i][1]-z[i-1][1])))) j_ = y[i-1][1] cost[j].append((j_,min(abs(y[i][0]-y[i-1][0]),abs(z[j][0]-z[j_][0])))) cost[i].append((i+1,min(abs(z[i+1][0]-z[i][0]),abs(z[i+1][1]-z[i][1])))) j_ = y[i+1][1] cost[j].append((j_,min(abs(y[i+1][0]-y[i][0]),abs(z[j_][1]-z[j][1])))) i = N-1 j = y[i][1] cost[i].append((i-1,min(abs(z[i][0]-z[i-1][0]),abs(z[i][1]-z[i-1][1])))) j_ = y[i-1][1] cost[j].append((j_,min(abs(y[i][0]-y[i-1][0]),abs(z[j][0]-z[j_][0])))) import heapq def prim(cost): V = len(cost) res = 0 mincost = [float('inf')]*V used = [False]*V hq = [] mincost[0] = 0 heapq.heappush(hq,(0,0)) while hq: weight,u = heapq.heappop(hq) if not used[u]: used[u] = True res += weight mincost[u] = weight for v, v_cost in cost[u]: if not used[v]: heapq.heappush(hq,(v_cost,v)) return res print((prim(cost)))
import heapq def prim(cost): V = len(cost) res = 0 mincost = [float('inf')]*V used = [False]*V hq = [] mincost[0] = 0 heapq.heappush(hq,(0,0)) while hq: weight,u = heapq.heappop(hq) if used[u]: continue used[u] = True res += weight mincost[u] = weight for v, v_cost in cost[u]: if not used[v]: heapq.heappush(hq,(v_cost,v)) return res N = int(eval(input())) xyi = [] for i in range(N): x,y = list(map(int,input().split())) xyi.append([x,y,i]) xyi.sort() cost = [[] for _ in range(N)] for i in range(N-1): xj = xyi[i][0] j = xyi[i][2] xk = xyi[i+1][0] k = xyi[i+1][2] cost[j].append((k,xk-xj)) cost[k].append((j,xk-xj)) xyi.sort(key=lambda x:x[1]) for i in range(N-1): yj = xyi[i][1] j = xyi[i][2] yk = xyi[i+1][1] k = xyi[i+1][2] cost[j].append((k,yk-yj)) cost[k].append((j,yk-yj)) print((prim(cost)))
44
47
1,246
1,018
N = int(eval(input())) z = [tuple(map(int, input().split())) for i in range(N)] z.sort() y = [(z[i][1], i) for i in range(N)] y.sort() cost = [[] for i in range(N)] for i in range(N - 1): j = y[i][1] cost[i].append((i - 1, min(abs(z[i][0] - z[i - 1][0]), abs(z[i][1] - z[i - 1][1])))) j_ = y[i - 1][1] cost[j].append((j_, min(abs(y[i][0] - y[i - 1][0]), abs(z[j][0] - z[j_][0])))) cost[i].append((i + 1, min(abs(z[i + 1][0] - z[i][0]), abs(z[i + 1][1] - z[i][1])))) j_ = y[i + 1][1] cost[j].append((j_, min(abs(y[i + 1][0] - y[i][0]), abs(z[j_][1] - z[j][1])))) i = N - 1 j = y[i][1] cost[i].append((i - 1, min(abs(z[i][0] - z[i - 1][0]), abs(z[i][1] - z[i - 1][1])))) j_ = y[i - 1][1] cost[j].append((j_, min(abs(y[i][0] - y[i - 1][0]), abs(z[j][0] - z[j_][0])))) import heapq def prim(cost): V = len(cost) res = 0 mincost = [float("inf")] * V used = [False] * V hq = [] mincost[0] = 0 heapq.heappush(hq, (0, 0)) while hq: weight, u = heapq.heappop(hq) if not used[u]: used[u] = True res += weight mincost[u] = weight for v, v_cost in cost[u]: if not used[v]: heapq.heappush(hq, (v_cost, v)) return res print((prim(cost)))
import heapq def prim(cost): V = len(cost) res = 0 mincost = [float("inf")] * V used = [False] * V hq = [] mincost[0] = 0 heapq.heappush(hq, (0, 0)) while hq: weight, u = heapq.heappop(hq) if used[u]: continue used[u] = True res += weight mincost[u] = weight for v, v_cost in cost[u]: if not used[v]: heapq.heappush(hq, (v_cost, v)) return res N = int(eval(input())) xyi = [] for i in range(N): x, y = list(map(int, input().split())) xyi.append([x, y, i]) xyi.sort() cost = [[] for _ in range(N)] for i in range(N - 1): xj = xyi[i][0] j = xyi[i][2] xk = xyi[i + 1][0] k = xyi[i + 1][2] cost[j].append((k, xk - xj)) cost[k].append((j, xk - xj)) xyi.sort(key=lambda x: x[1]) for i in range(N - 1): yj = xyi[i][1] j = xyi[i][2] yk = xyi[i + 1][1] k = xyi[i + 1][2] cost[j].append((k, yk - yj)) cost[k].append((j, yk - yj)) print((prim(cost)))
false
6.382979
[ "-N = int(eval(input()))", "-z = [tuple(map(int, input().split())) for i in range(N)]", "-z.sort()", "-y = [(z[i][1], i) for i in range(N)]", "-y.sort()", "-cost = [[] for i in range(N)]", "-for i in range(N - 1):", "- j = y[i][1]", "- cost[i].append((i - 1, min(abs(z[i][0] - z[i - 1][0]), abs(z[i][1] - z[i - 1][1]))))", "- j_ = y[i - 1][1]", "- cost[j].append((j_, min(abs(y[i][0] - y[i - 1][0]), abs(z[j][0] - z[j_][0]))))", "- cost[i].append((i + 1, min(abs(z[i + 1][0] - z[i][0]), abs(z[i + 1][1] - z[i][1]))))", "- j_ = y[i + 1][1]", "- cost[j].append((j_, min(abs(y[i + 1][0] - y[i][0]), abs(z[j_][1] - z[j][1]))))", "-i = N - 1", "-j = y[i][1]", "-cost[i].append((i - 1, min(abs(z[i][0] - z[i - 1][0]), abs(z[i][1] - z[i - 1][1]))))", "-j_ = y[i - 1][1]", "-cost[j].append((j_, min(abs(y[i][0] - y[i - 1][0]), abs(z[j][0] - z[j_][0]))))", "- if not used[u]:", "- used[u] = True", "- res += weight", "- mincost[u] = weight", "- for v, v_cost in cost[u]:", "- if not used[v]:", "- heapq.heappush(hq, (v_cost, v))", "+ if used[u]:", "+ continue", "+ used[u] = True", "+ res += weight", "+ mincost[u] = weight", "+ for v, v_cost in cost[u]:", "+ if not used[v]:", "+ heapq.heappush(hq, (v_cost, v))", "+N = int(eval(input()))", "+xyi = []", "+for i in range(N):", "+ x, y = list(map(int, input().split()))", "+ xyi.append([x, y, i])", "+xyi.sort()", "+cost = [[] for _ in range(N)]", "+for i in range(N - 1):", "+ xj = xyi[i][0]", "+ j = xyi[i][2]", "+ xk = xyi[i + 1][0]", "+ k = xyi[i + 1][2]", "+ cost[j].append((k, xk - xj))", "+ cost[k].append((j, xk - xj))", "+xyi.sort(key=lambda x: x[1])", "+for i in range(N - 1):", "+ yj = xyi[i][1]", "+ j = xyi[i][2]", "+ yk = xyi[i + 1][1]", "+ k = xyi[i + 1][2]", "+ cost[j].append((k, yk - yj))", "+ cost[k].append((j, yk - yj))" ]
false
0.043147
0.040014
1.078274
[ "s199629627", "s134605828" ]
u474423089
p03013
python
s408449291
s441958376
447
49
460,020
11,884
Accepted
Accepted
89.04
import sys mod = 10**9+7 def main(): n,m=list(map(int,input().split(' '))) if m > 0: aaa = set(map(int,sys.stdin)) else: aaa = set() dp = [0] * (n+1) dp[0] = 1 dp[1] = 1 if 1 not in aaa else 0 for i in range(2,n+1): if i in aaa: continue dp[i] = dp[i-1]+dp[i-2] print((dp[n]%mod)) main()
import sys mod = 10**9+7 def main(): n,m=list(map(int,input().split(' '))) if m > 0: aaa = set(map(int,sys.stdin)) else: aaa = set() dp = [0] * (n+1) dp[0] = 1 dp[1] = 1 if 1 not in aaa else 0 for i in range(2,n+1): if i in aaa: continue dp[i] = (dp[i-1]+dp[i-2])%mod print((dp[n])) main()
20
20
377
379
import sys mod = 10**9 + 7 def main(): n, m = list(map(int, input().split(" "))) if m > 0: aaa = set(map(int, sys.stdin)) else: aaa = set() dp = [0] * (n + 1) dp[0] = 1 dp[1] = 1 if 1 not in aaa else 0 for i in range(2, n + 1): if i in aaa: continue dp[i] = dp[i - 1] + dp[i - 2] print((dp[n] % mod)) main()
import sys mod = 10**9 + 7 def main(): n, m = list(map(int, input().split(" "))) if m > 0: aaa = set(map(int, sys.stdin)) else: aaa = set() dp = [0] * (n + 1) dp[0] = 1 dp[1] = 1 if 1 not in aaa else 0 for i in range(2, n + 1): if i in aaa: continue dp[i] = (dp[i - 1] + dp[i - 2]) % mod print((dp[n])) main()
false
0
[ "- dp[i] = dp[i - 1] + dp[i - 2]", "- print((dp[n] % mod))", "+ dp[i] = (dp[i - 1] + dp[i - 2]) % mod", "+ print((dp[n]))" ]
false
0.058374
0.035044
1.665731
[ "s408449291", "s441958376" ]
u230621983
p03785
python
s762693957
s546787905
239
86
7,744
19,948
Accepted
Accepted
64.02
import collections n, c, k = list(map(int, input().split())) t = [int(eval(input())) for i in range(n)] t.sort() passenger = 0 departure_limit = t[0] + k bus_cnt = 0 for T in t: if passenger+1 > c or T > departure_limit: departure_limit = T+k passenger = 1 bus_cnt += 1 else: passenger+=1 print((bus_cnt+1))
n, c, k, *t = list(map(int, open(0).read().split())) t.sort() tmp = 0 cnt = 0 limit = t[0] + k for time in t: if tmp == c or time > limit: limit = time + k tmp = 1 cnt += 1 else: tmp += 1 print((cnt + 1))
20
13
357
248
import collections n, c, k = list(map(int, input().split())) t = [int(eval(input())) for i in range(n)] t.sort() passenger = 0 departure_limit = t[0] + k bus_cnt = 0 for T in t: if passenger + 1 > c or T > departure_limit: departure_limit = T + k passenger = 1 bus_cnt += 1 else: passenger += 1 print((bus_cnt + 1))
n, c, k, *t = list(map(int, open(0).read().split())) t.sort() tmp = 0 cnt = 0 limit = t[0] + k for time in t: if tmp == c or time > limit: limit = time + k tmp = 1 cnt += 1 else: tmp += 1 print((cnt + 1))
false
35
[ "-import collections", "-", "-n, c, k = list(map(int, input().split()))", "-t = [int(eval(input())) for i in range(n)]", "+n, c, k, *t = list(map(int, open(0).read().split()))", "-passenger = 0", "-departure_limit = t[0] + k", "-bus_cnt = 0", "-for T in t:", "- if passenger + 1 > c or T > departure_limit:", "- departure_limit = T + k", "- passenger = 1", "- bus_cnt += 1", "+tmp = 0", "+cnt = 0", "+limit = t[0] + k", "+for time in t:", "+ if tmp == c or time > limit:", "+ limit = time + k", "+ tmp = 1", "+ cnt += 1", "- passenger += 1", "-print((bus_cnt + 1))", "+ tmp += 1", "+print((cnt + 1))" ]
false
0.046278
0.127182
0.36387
[ "s762693957", "s546787905" ]
u252828980
p03681
python
s835315910
s266162842
704
55
5,192
3,064
Accepted
Accepted
92.19
import math n,m = list(map(int,input().split())) if abs(n-m)>=2: print((0)) if abs(n-m)==1: print((math.factorial(m)*math.factorial(n)%1000000007)) if n==m: print((math.factorial(m)*math.factorial(n)*2%1000000007))
n,m = list(map(int,(input().split()))) mod = 10**9+7 sn,sm = 1,1 for i in range(1,n+1): sn = sn*i%mod for i in range(1,m+1): sm = sm*i%mod if abs(n-m)>=2: print((0)) elif abs(n-m) == 1: print((sn*sm%mod)) elif abs(n-m) == 0: print((sn*sm*2%mod))
9
15
224
269
import math n, m = list(map(int, input().split())) if abs(n - m) >= 2: print((0)) if abs(n - m) == 1: print((math.factorial(m) * math.factorial(n) % 1000000007)) if n == m: print((math.factorial(m) * math.factorial(n) * 2 % 1000000007))
n, m = list(map(int, (input().split()))) mod = 10**9 + 7 sn, sm = 1, 1 for i in range(1, n + 1): sn = sn * i % mod for i in range(1, m + 1): sm = sm * i % mod if abs(n - m) >= 2: print((0)) elif abs(n - m) == 1: print((sn * sm % mod)) elif abs(n - m) == 0: print((sn * sm * 2 % mod))
false
40
[ "-import math", "-", "-n, m = list(map(int, input().split()))", "+n, m = list(map(int, (input().split())))", "+mod = 10**9 + 7", "+sn, sm = 1, 1", "+for i in range(1, n + 1):", "+ sn = sn * i % mod", "+for i in range(1, m + 1):", "+ sm = sm * i % mod", "-if abs(n - m) == 1:", "- print((math.factorial(m) * math.factorial(n) % 1000000007))", "-if n == m:", "- print((math.factorial(m) * math.factorial(n) * 2 % 1000000007))", "+elif abs(n - m) == 1:", "+ print((sn * sm % mod))", "+elif abs(n - m) == 0:", "+ print((sn * sm * 2 % mod))" ]
false
0.132973
0.037971
3.501962
[ "s835315910", "s266162842" ]
u627803856
p03828
python
s718436918
s517879686
206
80
40,048
68,024
Accepted
Accepted
61.17
n = int(eval(input())) mod = 10**9 + 7 d = {} for i in range(2,n+1): x = i for j in range(2,x+1): while x % j == 0: x = x // j d[j] = d.get(j, 0) + 1 ret = 1 for v in list(d.values()): ret *= v+1 print((ret % mod))
MOD = 10 ** 9 + 7 n = int(eval(input())) # 素数 primes = [True] * (n + 1) p = 2 while p * p <= n: if primes[p]: for i in range(p * p, n + 1, p): primes[i] = False p += 1 primes[0], primes[1] = False, False # counter cnt = [0] * (n + 1) for k in range(2, n + 1): now = k # 素因数分解 for i in range(2, k + 1): while k % i == 0: cnt[i] += 1 k //= i if k != 1: cnt[k] += 1 res = 1 for k in range(1, n + 1): if primes[k]: res *= cnt[k] + 1 res %= MOD print(res)
17
32
232
583
n = int(eval(input())) mod = 10**9 + 7 d = {} for i in range(2, n + 1): x = i for j in range(2, x + 1): while x % j == 0: x = x // j d[j] = d.get(j, 0) + 1 ret = 1 for v in list(d.values()): ret *= v + 1 print((ret % mod))
MOD = 10**9 + 7 n = int(eval(input())) # 素数 primes = [True] * (n + 1) p = 2 while p * p <= n: if primes[p]: for i in range(p * p, n + 1, p): primes[i] = False p += 1 primes[0], primes[1] = False, False # counter cnt = [0] * (n + 1) for k in range(2, n + 1): now = k # 素因数分解 for i in range(2, k + 1): while k % i == 0: cnt[i] += 1 k //= i if k != 1: cnt[k] += 1 res = 1 for k in range(1, n + 1): if primes[k]: res *= cnt[k] + 1 res %= MOD print(res)
false
46.875
[ "+MOD = 10**9 + 7", "-mod = 10**9 + 7", "-d = {}", "-for i in range(2, n + 1):", "- x = i", "- for j in range(2, x + 1):", "- while x % j == 0:", "- x = x // j", "- d[j] = d.get(j, 0) + 1", "-ret = 1", "-for v in list(d.values()):", "- ret *= v + 1", "-print((ret % mod))", "+# 素数", "+primes = [True] * (n + 1)", "+p = 2", "+while p * p <= n:", "+ if primes[p]:", "+ for i in range(p * p, n + 1, p):", "+ primes[i] = False", "+ p += 1", "+primes[0], primes[1] = False, False", "+# counter", "+cnt = [0] * (n + 1)", "+for k in range(2, n + 1):", "+ now = k", "+ # 素因数分解", "+ for i in range(2, k + 1):", "+ while k % i == 0:", "+ cnt[i] += 1", "+ k //= i", "+ if k != 1:", "+ cnt[k] += 1", "+res = 1", "+for k in range(1, n + 1):", "+ if primes[k]:", "+ res *= cnt[k] + 1", "+ res %= MOD", "+print(res)" ]
false
0.045516
0.109212
0.416771
[ "s718436918", "s517879686" ]
u089032001
p02695
python
s354864640
s322788344
630
534
22,944
94,212
Accepted
Accepted
15.24
import sys input = sys.stdin.readline sys.setrecursionlimit(2 * 10**6) def inpl(): return list(map(int, input().split())) back = [] def backtrack(n, ml, mh, tmp=[]): if n == 0: back.append(tmp) return for i in range(ml, mh + 1): backtrack(n - 1, i, mh, tmp + [i]) def main(): def count(carrer): ret = 0 for a, b, c, d in abcd: if carrer[b - 1] - carrer[a - 1] == c: ret += d return ret N, M, Q = inpl() ans = 0 abcd = [inpl() for _ in range(Q)] backtrack(N, 1, M) for carrer in back: # print(carrer) tmp = count(carrer) if tmp > ans: ans = tmp print(ans) if __name__ == '__main__': main()
import sys input = sys.stdin.readline sys.setrecursionlimit(2 * 10**6) def inpl(): return list(map(int, input().split())) def backtrack(n, ml, mh, tmp=[]): if n == 0: yield tmp return for i in range(ml, mh + 1): yield from backtrack(n - 1, i, mh, tmp + [i]) def main(): def count(ca): return sum(d for a, b, c, d in abcd if ca[b - 1] - ca[a - 1] == c) N, M, Q = inpl() abcd = [inpl() for _ in range(Q)] print((max(count(c) for c in backtrack(N, 1, M)))) if __name__ == '__main__': main()
42
28
797
586
import sys input = sys.stdin.readline sys.setrecursionlimit(2 * 10**6) def inpl(): return list(map(int, input().split())) back = [] def backtrack(n, ml, mh, tmp=[]): if n == 0: back.append(tmp) return for i in range(ml, mh + 1): backtrack(n - 1, i, mh, tmp + [i]) def main(): def count(carrer): ret = 0 for a, b, c, d in abcd: if carrer[b - 1] - carrer[a - 1] == c: ret += d return ret N, M, Q = inpl() ans = 0 abcd = [inpl() for _ in range(Q)] backtrack(N, 1, M) for carrer in back: # print(carrer) tmp = count(carrer) if tmp > ans: ans = tmp print(ans) if __name__ == "__main__": main()
import sys input = sys.stdin.readline sys.setrecursionlimit(2 * 10**6) def inpl(): return list(map(int, input().split())) def backtrack(n, ml, mh, tmp=[]): if n == 0: yield tmp return for i in range(ml, mh + 1): yield from backtrack(n - 1, i, mh, tmp + [i]) def main(): def count(ca): return sum(d for a, b, c, d in abcd if ca[b - 1] - ca[a - 1] == c) N, M, Q = inpl() abcd = [inpl() for _ in range(Q)] print((max(count(c) for c in backtrack(N, 1, M)))) if __name__ == "__main__": main()
false
33.333333
[ "-back = []", "-", "-", "- back.append(tmp)", "+ yield tmp", "- backtrack(n - 1, i, mh, tmp + [i])", "+ yield from backtrack(n - 1, i, mh, tmp + [i])", "- def count(carrer):", "- ret = 0", "- for a, b, c, d in abcd:", "- if carrer[b - 1] - carrer[a - 1] == c:", "- ret += d", "- return ret", "+ def count(ca):", "+ return sum(d for a, b, c, d in abcd if ca[b - 1] - ca[a - 1] == c)", "- ans = 0", "- backtrack(N, 1, M)", "- for carrer in back:", "- # print(carrer)", "- tmp = count(carrer)", "- if tmp > ans:", "- ans = tmp", "- print(ans)", "+ print((max(count(c) for c in backtrack(N, 1, M))))" ]
false
0.069618
0.139897
0.497636
[ "s354864640", "s322788344" ]
u141786930
p02898
python
s279855437
s925242551
67
50
10,636
11,892
Accepted
Accepted
25.37
from collections import deque n, k = list(map(int, input().split())) h = deque(list(input().split())) ans = 0 while len(h) > 0: if int(h.pop()) >= k: ans += 1 print(ans)
def main(): N, K = list(map(int, input().split())) h = list(int(x) for x in input().split()) ans = 0 for i in h: if i >= K: ans += 1 print(ans) if __name__ == '__main__': main()
11
13
196
234
from collections import deque n, k = list(map(int, input().split())) h = deque(list(input().split())) ans = 0 while len(h) > 0: if int(h.pop()) >= k: ans += 1 print(ans)
def main(): N, K = list(map(int, input().split())) h = list(int(x) for x in input().split()) ans = 0 for i in h: if i >= K: ans += 1 print(ans) if __name__ == "__main__": main()
false
15.384615
[ "-from collections import deque", "+def main():", "+ N, K = list(map(int, input().split()))", "+ h = list(int(x) for x in input().split())", "+ ans = 0", "+ for i in h:", "+ if i >= K:", "+ ans += 1", "+ print(ans)", "-n, k = list(map(int, input().split()))", "-h = deque(list(input().split()))", "-ans = 0", "-while len(h) > 0:", "- if int(h.pop()) >= k:", "- ans += 1", "-print(ans)", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.035663
0.035418
1.006912
[ "s279855437", "s925242551" ]
u312025627
p03945
python
s738894993
s923638397
172
39
39,280
3,188
Accepted
Accepted
77.33
def main(): S = eval(input()) ans = 0 for i in range(len(S)-1): if S[i] != S[i+1]: ans += 1 print(ans) if __name__ == '__main__': main()
def main(): S = eval(input()) N = len(S) ans = 0 for i in range(1, N): if S[i-1] != S[i]: ans += 1 print(ans) if __name__ == '__main__': main()
11
12
183
195
def main(): S = eval(input()) ans = 0 for i in range(len(S) - 1): if S[i] != S[i + 1]: ans += 1 print(ans) if __name__ == "__main__": main()
def main(): S = eval(input()) N = len(S) ans = 0 for i in range(1, N): if S[i - 1] != S[i]: ans += 1 print(ans) if __name__ == "__main__": main()
false
8.333333
[ "+ N = len(S)", "- for i in range(len(S) - 1):", "- if S[i] != S[i + 1]:", "+ for i in range(1, N):", "+ if S[i - 1] != S[i]:" ]
false
0.044623
0.035809
1.24613
[ "s738894993", "s923638397" ]
u227082700
p03855
python
s254365208
s496555384
1,275
1,130
47,332
44,388
Accepted
Accepted
11.37
from collections import* class u(): def __init__(self,n):self.n,self.r=[-1]*n,[0]*n def f(self,x): if self.n[x]<0:return x else:self.n[x]=self.f(self.n[x]);return self.n[x] def u(self,x,y): x,y=self.f(x),self.f(y) if x==y:return elif self.r[x]>self.r[y]:self.n[x]+=self.n[y];self.n[y]=x else:self.n[y]+=self.n[x];self.n[x]=y;self.r[y]+=self.r[x]==self.r[y] n,k,l=list(map(int,input().split()));d=u(n);t=u(n) for _ in range(k):a,b=list(map(int,input().split()));d.u(a-1,b-1) for _ in range(l):a,b=list(map(int,input().split()));t.u(a-1,b-1) p=[(d.f(i),t.f(i))for i in range(n)];c=Counter(p);print((*[c[p[i]]for i in range(n)]))
from collections import* n,k,l=list(map(int,input().split()));d=[-1]*n;t=[-1]*n def f(l,x): if l[x]<0:return x else:l[x]=f(l,l[x]);return l[x] def u(l,x,y): x,y=f(l,x),f(l,y) if x!=y:l[y]=x for _ in range(k):a,b=list(map(int,input().split()));u(d,a-1,b-1) for _ in range(l):a,b=list(map(int,input().split()));u(t,a-1,b-1) p=[(f(d,i),f(t,i))for i in range(n)];c=Counter(p);print((*[c[p[i]]for i in range(n)]))
15
11
650
406
from collections import * class u: def __init__(self, n): self.n, self.r = [-1] * n, [0] * n def f(self, x): if self.n[x] < 0: return x else: self.n[x] = self.f(self.n[x]) return self.n[x] def u(self, x, y): x, y = self.f(x), self.f(y) if x == y: return elif self.r[x] > self.r[y]: self.n[x] += self.n[y] self.n[y] = x else: self.n[y] += self.n[x] self.n[x] = y self.r[y] += self.r[x] == self.r[y] n, k, l = list(map(int, input().split())) d = u(n) t = u(n) for _ in range(k): a, b = list(map(int, input().split())) d.u(a - 1, b - 1) for _ in range(l): a, b = list(map(int, input().split())) t.u(a - 1, b - 1) p = [(d.f(i), t.f(i)) for i in range(n)] c = Counter(p) print((*[c[p[i]] for i in range(n)]))
from collections import * n, k, l = list(map(int, input().split())) d = [-1] * n t = [-1] * n def f(l, x): if l[x] < 0: return x else: l[x] = f(l, l[x]) return l[x] def u(l, x, y): x, y = f(l, x), f(l, y) if x != y: l[y] = x for _ in range(k): a, b = list(map(int, input().split())) u(d, a - 1, b - 1) for _ in range(l): a, b = list(map(int, input().split())) u(t, a - 1, b - 1) p = [(f(d, i), f(t, i)) for i in range(n)] c = Counter(p) print((*[c[p[i]] for i in range(n)]))
false
26.666667
[ "-", "-class u:", "- def __init__(self, n):", "- self.n, self.r = [-1] * n, [0] * n", "-", "- def f(self, x):", "- if self.n[x] < 0:", "- return x", "- else:", "- self.n[x] = self.f(self.n[x])", "- return self.n[x]", "-", "- def u(self, x, y):", "- x, y = self.f(x), self.f(y)", "- if x == y:", "- return", "- elif self.r[x] > self.r[y]:", "- self.n[x] += self.n[y]", "- self.n[y] = x", "- else:", "- self.n[y] += self.n[x]", "- self.n[x] = y", "- self.r[y] += self.r[x] == self.r[y]", "+n, k, l = list(map(int, input().split()))", "+d = [-1] * n", "+t = [-1] * n", "-n, k, l = list(map(int, input().split()))", "-d = u(n)", "-t = u(n)", "+def f(l, x):", "+ if l[x] < 0:", "+ return x", "+ else:", "+ l[x] = f(l, l[x])", "+ return l[x]", "+", "+", "+def u(l, x, y):", "+ x, y = f(l, x), f(l, y)", "+ if x != y:", "+ l[y] = x", "+", "+", "- d.u(a - 1, b - 1)", "+ u(d, a - 1, b - 1)", "- t.u(a - 1, b - 1)", "-p = [(d.f(i), t.f(i)) for i in range(n)]", "+ u(t, a - 1, b - 1)", "+p = [(f(d, i), f(t, i)) for i in range(n)]" ]
false
0.045551
0.125178
0.363894
[ "s254365208", "s496555384" ]
u761320129
p03599
python
s023150660
s545517105
128
76
3,188
9,256
Accepted
Accepted
40.62
A,B,C,D,E,F = list(map(int,input().split())) ws = set() for a in range(F+1): if a*100*A > F: break for b in range(F+1): if a*100*A + b*100*B > F: break ws.add(a*100*A + b*100*B) ss = set() for c in range(F+1): if c*C > F: break for d in range(F+1): if c*C + d*D > F: break ss.add(c*C + d*D) os = -1 ow = 999 for w in ws: if w==0: continue for s in ss: if s+w > F: continue if w*E < s*100: continue if os * (s+w) < s * (os+ow): os,ow = s,w print((os+ow, os))
A,B,C,D,E,F = list(map(int,input().split())) ws = set() for a in range(0,F+1,100*A): for b in range(0,F+1,100*B): if a+b > F: break ws.add(a+b) ws.remove(0) ss = set() for c in range(0,F+1,C): for d in range(0,F+1,D): if c+d > F: break ss.add(c+d) best_s = -1 best_w = 1 for w in ws: for s in ss: if w+s > F: continue if E*w < s*100: continue if best_s * (s+w) < s * (best_s + best_w): best_s = s best_w = w print((best_s+best_w, best_s))
26
25
569
549
A, B, C, D, E, F = list(map(int, input().split())) ws = set() for a in range(F + 1): if a * 100 * A > F: break for b in range(F + 1): if a * 100 * A + b * 100 * B > F: break ws.add(a * 100 * A + b * 100 * B) ss = set() for c in range(F + 1): if c * C > F: break for d in range(F + 1): if c * C + d * D > F: break ss.add(c * C + d * D) os = -1 ow = 999 for w in ws: if w == 0: continue for s in ss: if s + w > F: continue if w * E < s * 100: continue if os * (s + w) < s * (os + ow): os, ow = s, w print((os + ow, os))
A, B, C, D, E, F = list(map(int, input().split())) ws = set() for a in range(0, F + 1, 100 * A): for b in range(0, F + 1, 100 * B): if a + b > F: break ws.add(a + b) ws.remove(0) ss = set() for c in range(0, F + 1, C): for d in range(0, F + 1, D): if c + d > F: break ss.add(c + d) best_s = -1 best_w = 1 for w in ws: for s in ss: if w + s > F: continue if E * w < s * 100: continue if best_s * (s + w) < s * (best_s + best_w): best_s = s best_w = w print((best_s + best_w, best_s))
false
3.846154
[ "-for a in range(F + 1):", "- if a * 100 * A > F:", "- break", "- for b in range(F + 1):", "- if a * 100 * A + b * 100 * B > F:", "+for a in range(0, F + 1, 100 * A):", "+ for b in range(0, F + 1, 100 * B):", "+ if a + b > F:", "- ws.add(a * 100 * A + b * 100 * B)", "+ ws.add(a + b)", "+ws.remove(0)", "-for c in range(F + 1):", "- if c * C > F:", "- break", "- for d in range(F + 1):", "- if c * C + d * D > F:", "+for c in range(0, F + 1, C):", "+ for d in range(0, F + 1, D):", "+ if c + d > F:", "- ss.add(c * C + d * D)", "-os = -1", "-ow = 999", "+ ss.add(c + d)", "+best_s = -1", "+best_w = 1", "- if w == 0:", "- continue", "- if s + w > F:", "+ if w + s > F:", "- if w * E < s * 100:", "+ if E * w < s * 100:", "- if os * (s + w) < s * (os + ow):", "- os, ow = s, w", "-print((os + ow, os))", "+ if best_s * (s + w) < s * (best_s + best_w):", "+ best_s = s", "+ best_w = w", "+print((best_s + best_w, best_s))" ]
false
0.056351
0.048227
1.168434
[ "s023150660", "s545517105" ]
u989345508
p03103
python
s304808560
s714384961
526
477
29,796
27,756
Accepted
Accepted
9.32
n,m=list(map(int,input().split())) x,y=[],[] x=sorted([list(map(int,input().split()))for i in range(n)],key=lambda x:x[0]) #小さい方から買うけど、余ったら減らす #print(x) for i in range(n): #print(m) c=m-x[i][1] if c<=0: s=0 for j in range(i+1): #print(x[i]) s+=x[j][0]*x[j][1] #print(s) print((s+c*x[i][0])) break m=c
n,m=list(map(int,input().split())) ab=[list(map(int,input().split())) for i in range(n)] ab.sort() ans=0 for i in range(n): if m>ab[i][1]: ans+=ab[i][0]*ab[i][1] m-=ab[i][1] else: ans+=ab[i][0]*m print(ans) break
18
12
391
266
n, m = list(map(int, input().split())) x, y = [], [] x = sorted([list(map(int, input().split())) for i in range(n)], key=lambda x: x[0]) # 小さい方から買うけど、余ったら減らす # print(x) for i in range(n): # print(m) c = m - x[i][1] if c <= 0: s = 0 for j in range(i + 1): # print(x[i]) s += x[j][0] * x[j][1] # print(s) print((s + c * x[i][0])) break m = c
n, m = list(map(int, input().split())) ab = [list(map(int, input().split())) for i in range(n)] ab.sort() ans = 0 for i in range(n): if m > ab[i][1]: ans += ab[i][0] * ab[i][1] m -= ab[i][1] else: ans += ab[i][0] * m print(ans) break
false
33.333333
[ "-x, y = [], []", "-x = sorted([list(map(int, input().split())) for i in range(n)], key=lambda x: x[0])", "-# 小さい方から買うけど、余ったら減らす", "-# print(x)", "+ab = [list(map(int, input().split())) for i in range(n)]", "+ab.sort()", "+ans = 0", "- # print(m)", "- c = m - x[i][1]", "- if c <= 0:", "- s = 0", "- for j in range(i + 1):", "- # print(x[i])", "- s += x[j][0] * x[j][1]", "- # print(s)", "- print((s + c * x[i][0]))", "+ if m > ab[i][1]:", "+ ans += ab[i][0] * ab[i][1]", "+ m -= ab[i][1]", "+ else:", "+ ans += ab[i][0] * m", "+ print(ans)", "- m = c" ]
false
0.048699
0.050489
0.964533
[ "s304808560", "s714384961" ]
u561083515
p03734
python
s614137467
s028055314
575
379
3,444
3,188
Accepted
Accepted
34.09
import sys input = sys.stdin.readline from itertools import accumulate N,W = list(map(int,input().split())) WV = [[int(i) for i in input().split()] for _ in range(N)] MINW = WV[0][0] # それぞれの重さについての価値のリスト W0 = sorted([0] + [v for w,v in WV if w == MINW]) W1 = sorted([0] + [v for w,v in WV if w == MINW+1]) W2 = sorted([0] + [v for w,v in WV if w == MINW+2]) W3 = sorted([0] + [v for w,v in WV if w == MINW+3]) # 累積和 W0 = tuple(accumulate(W0)) W1 = tuple(accumulate(W1)) W2 = tuple(accumulate(W2)) W3 = tuple(accumulate(W3)) ans = 0 for w0 in range(len(W0)): for w1 in range(len(W1)): for w2 in range(len(W2)): for w3 in range(len(W3)): # tmp: 状態(w0,w1,w2,w3)での重さ tmp = (len(W0) - (w0 + 1)) * MINW tmp += (len(W1) - (w1 + 1)) * (MINW+1) tmp += (len(W2) - (w2 + 1)) * (MINW+2) tmp += (len(W3) - (w3 + 1)) * (MINW+3) # ナップサックに入る場合 if tmp <= W: # tmp: 価値の総和 tmp = W0[-1] - W0[w0] tmp += W1[-1] - W1[w1] tmp += W2[-1] - W2[w2] tmp += W3[-1] - W3[w3] ans = max(ans, tmp) print(ans)
N,W = list(map(int, input().split())) WV = [[int(i) for i in input().split()] for _ in range(N)] MINW = WV[0][0] W0,W1,W2,W3 = [],[],[],[] for w,v in WV: if w == MINW: W0.append(v) elif w == MINW + 1: W1.append(v) elif w == MINW + 2: W2.append(v) elif w == MINW + 3: W3.append(v) W0.sort(reverse=True) W1.sort(reverse=True) W2.sort(reverse=True) W3.sort(reverse=True) W0 = [0] + W0 W1 = [0] + W1 W2 = [0] + W2 W3 = [0] + W3 from itertools import accumulate W0 = list(accumulate(W0)) W1 = list(accumulate(W1)) W2 = list(accumulate(W2)) W3 = list(accumulate(W3)) ans = 0 for cnt0 in range(len(W0)): for cnt1 in range(len(W1)): for cnt2 in range(len(W2)): for cnt3 in range(len(W3)): SUMW = cnt0 * MINW SUMW += cnt1 * (MINW + 1) SUMW += cnt2 * (MINW + 2) SUMW += cnt3 * (MINW + 3) if SUMW <= W: SUMV = W0[cnt0] SUMV += W1[cnt1] SUMV += W2[cnt2] SUMV += W3[cnt3] ans = max(ans, SUMV) print(ans)
42
47
1,273
1,159
import sys input = sys.stdin.readline from itertools import accumulate N, W = list(map(int, input().split())) WV = [[int(i) for i in input().split()] for _ in range(N)] MINW = WV[0][0] # それぞれの重さについての価値のリスト W0 = sorted([0] + [v for w, v in WV if w == MINW]) W1 = sorted([0] + [v for w, v in WV if w == MINW + 1]) W2 = sorted([0] + [v for w, v in WV if w == MINW + 2]) W3 = sorted([0] + [v for w, v in WV if w == MINW + 3]) # 累積和 W0 = tuple(accumulate(W0)) W1 = tuple(accumulate(W1)) W2 = tuple(accumulate(W2)) W3 = tuple(accumulate(W3)) ans = 0 for w0 in range(len(W0)): for w1 in range(len(W1)): for w2 in range(len(W2)): for w3 in range(len(W3)): # tmp: 状態(w0,w1,w2,w3)での重さ tmp = (len(W0) - (w0 + 1)) * MINW tmp += (len(W1) - (w1 + 1)) * (MINW + 1) tmp += (len(W2) - (w2 + 1)) * (MINW + 2) tmp += (len(W3) - (w3 + 1)) * (MINW + 3) # ナップサックに入る場合 if tmp <= W: # tmp: 価値の総和 tmp = W0[-1] - W0[w0] tmp += W1[-1] - W1[w1] tmp += W2[-1] - W2[w2] tmp += W3[-1] - W3[w3] ans = max(ans, tmp) print(ans)
N, W = list(map(int, input().split())) WV = [[int(i) for i in input().split()] for _ in range(N)] MINW = WV[0][0] W0, W1, W2, W3 = [], [], [], [] for w, v in WV: if w == MINW: W0.append(v) elif w == MINW + 1: W1.append(v) elif w == MINW + 2: W2.append(v) elif w == MINW + 3: W3.append(v) W0.sort(reverse=True) W1.sort(reverse=True) W2.sort(reverse=True) W3.sort(reverse=True) W0 = [0] + W0 W1 = [0] + W1 W2 = [0] + W2 W3 = [0] + W3 from itertools import accumulate W0 = list(accumulate(W0)) W1 = list(accumulate(W1)) W2 = list(accumulate(W2)) W3 = list(accumulate(W3)) ans = 0 for cnt0 in range(len(W0)): for cnt1 in range(len(W1)): for cnt2 in range(len(W2)): for cnt3 in range(len(W3)): SUMW = cnt0 * MINW SUMW += cnt1 * (MINW + 1) SUMW += cnt2 * (MINW + 2) SUMW += cnt3 * (MINW + 3) if SUMW <= W: SUMV = W0[cnt0] SUMV += W1[cnt1] SUMV += W2[cnt2] SUMV += W3[cnt3] ans = max(ans, SUMV) print(ans)
false
10.638298
[ "-import sys", "-", "-input = sys.stdin.readline", "-from itertools import accumulate", "-", "-# それぞれの重さについての価値のリスト", "-W0 = sorted([0] + [v for w, v in WV if w == MINW])", "-W1 = sorted([0] + [v for w, v in WV if w == MINW + 1])", "-W2 = sorted([0] + [v for w, v in WV if w == MINW + 2])", "-W3 = sorted([0] + [v for w, v in WV if w == MINW + 3])", "-# 累積和", "-W0 = tuple(accumulate(W0))", "-W1 = tuple(accumulate(W1))", "-W2 = tuple(accumulate(W2))", "-W3 = tuple(accumulate(W3))", "+W0, W1, W2, W3 = [], [], [], []", "+for w, v in WV:", "+ if w == MINW:", "+ W0.append(v)", "+ elif w == MINW + 1:", "+ W1.append(v)", "+ elif w == MINW + 2:", "+ W2.append(v)", "+ elif w == MINW + 3:", "+ W3.append(v)", "+W0.sort(reverse=True)", "+W1.sort(reverse=True)", "+W2.sort(reverse=True)", "+W3.sort(reverse=True)", "+W0 = [0] + W0", "+W1 = [0] + W1", "+W2 = [0] + W2", "+W3 = [0] + W3", "+from itertools import accumulate", "+", "+W0 = list(accumulate(W0))", "+W1 = list(accumulate(W1))", "+W2 = list(accumulate(W2))", "+W3 = list(accumulate(W3))", "-for w0 in range(len(W0)):", "- for w1 in range(len(W1)):", "- for w2 in range(len(W2)):", "- for w3 in range(len(W3)):", "- # tmp: 状態(w0,w1,w2,w3)での重さ", "- tmp = (len(W0) - (w0 + 1)) * MINW", "- tmp += (len(W1) - (w1 + 1)) * (MINW + 1)", "- tmp += (len(W2) - (w2 + 1)) * (MINW + 2)", "- tmp += (len(W3) - (w3 + 1)) * (MINW + 3)", "- # ナップサックに入る場合", "- if tmp <= W:", "- # tmp: 価値の総和", "- tmp = W0[-1] - W0[w0]", "- tmp += W1[-1] - W1[w1]", "- tmp += W2[-1] - W2[w2]", "- tmp += W3[-1] - W3[w3]", "- ans = max(ans, tmp)", "+for cnt0 in range(len(W0)):", "+ for cnt1 in range(len(W1)):", "+ for cnt2 in range(len(W2)):", "+ for cnt3 in range(len(W3)):", "+ SUMW = cnt0 * MINW", "+ SUMW += cnt1 * (MINW + 1)", "+ SUMW += cnt2 * (MINW + 2)", "+ SUMW += cnt3 * (MINW + 3)", "+ if SUMW <= W:", "+ SUMV = W0[cnt0]", "+ SUMV += W1[cnt1]", "+ SUMV += W2[cnt2]", "+ SUMV += W3[cnt3]", "+ ans = max(ans, SUMV)" ]
false
0.086735
0.04476
1.937791
[ "s614137467", "s028055314" ]
u920103253
p02681
python
s079367788
s123670022
27
24
9,152
9,132
Accepted
Accepted
11.11
def s0():return eval(input()) def s1():return input().split() def s2(n):return [eval(input()) for x in range(n)] def s3(n):return [[input().split()] for _ in range(n)] def n0():return int(eval(input())) def n1():return [int(x) for x in input().split()] def n2(n):return [int(eval(input())) for _ in range(n)] def n3(n):return [[int(x) for x in input().split()] for _ in range(n)] s=s0() t=s0() if s==t[:-1]: print("Yes") else: print("No")
def s0():return input() def s1():return input().split() def s2(n):return [input() for x in range(n)] def s3(n):return [[input().split()] for _ in range(n)] def n0():return int(input()) def n1():return [int(x) for x in input().split()] def n2(n):return [int(input()) for _ in range(n)] def n3(n):return [[int(x) for x in input().split()] for _ in range(n)] def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)] def p0(b,yes,no): print(yes) if b else print(no) # from collections import Counter,deque,defaultdict # import itertools # import math # import networkx # from bisect import bisect_left,bisect_right s=s0() t=s0() p0(s==t[:-1],"Yes","No")
15
21
437
695
def s0(): return eval(input()) def s1(): return input().split() def s2(n): return [eval(input()) for x in range(n)] def s3(n): return [[input().split()] for _ in range(n)] def n0(): return int(eval(input())) def n1(): return [int(x) for x in input().split()] def n2(n): return [int(eval(input())) for _ in range(n)] def n3(n): return [[int(x) for x in input().split()] for _ in range(n)] s = s0() t = s0() if s == t[:-1]: print("Yes") else: print("No")
def s0(): return input() def s1(): return input().split() def s2(n): return [input() for x in range(n)] def s3(n): return [[input().split()] for _ in range(n)] def n0(): return int(input()) def n1(): return [int(x) for x in input().split()] def n2(n): return [int(input()) for _ in range(n)] def n3(n): return [[int(x) for x in input().split()] for _ in range(n)] def t3(n): return [tuple(int(x) for x in input().split()) for _ in range(n)] def p0(b, yes, no): print(yes) if b else print(no) # from collections import Counter,deque,defaultdict # import itertools # import math # import networkx # from bisect import bisect_left,bisect_right s = s0() t = s0() p0(s == t[:-1], "Yes", "No")
false
28.571429
[ "- return eval(input())", "+ return input()", "- return [eval(input()) for x in range(n)]", "+ return [input() for x in range(n)]", "- return int(eval(input()))", "+ return int(input())", "- return [int(eval(input())) for _ in range(n)]", "+ return [int(input()) for _ in range(n)]", "+def t3(n):", "+ return [tuple(int(x) for x in input().split()) for _ in range(n)]", "+", "+", "+def p0(b, yes, no):", "+ print(yes) if b else print(no)", "+", "+", "+# from collections import Counter,deque,defaultdict", "+# import itertools", "+# import math", "+# import networkx", "+# from bisect import bisect_left,bisect_right", "-if s == t[:-1]:", "- print(\"Yes\")", "-else:", "- print(\"No\")", "+p0(s == t[:-1], \"Yes\", \"No\")" ]
false
0.091805
0.04055
2.264026
[ "s079367788", "s123670022" ]
u667024514
p03864
python
s954132901
s734369852
123
92
14,052
14,052
Accepted
Accepted
25.2
n,x = list(map(int,input().split())) lis = list(map(int,input().split())) cou = 0 if lis[0] > x: cou += (lis[0] - x) lis[0] -= (lis[0] -x) for i in range(n-1): if lis[i+1] + lis[i] > x: cou += (lis[i+1] + lis[i] -x) lis[i+1] -= (lis[i+1] + lis[i] -x) print(cou)
n,k = list(map(int,input().split())) lis = list(map(int,input().split())) cou = lis[0] ans = 0 if cou > k: ans += cou-k cou = k for i in range(1,n): if cou + lis[i] > k: num = cou+lis[i]-k cou = lis[i]-num ans += num else: cou = lis[i] print(ans)
11
15
279
302
n, x = list(map(int, input().split())) lis = list(map(int, input().split())) cou = 0 if lis[0] > x: cou += lis[0] - x lis[0] -= lis[0] - x for i in range(n - 1): if lis[i + 1] + lis[i] > x: cou += lis[i + 1] + lis[i] - x lis[i + 1] -= lis[i + 1] + lis[i] - x print(cou)
n, k = list(map(int, input().split())) lis = list(map(int, input().split())) cou = lis[0] ans = 0 if cou > k: ans += cou - k cou = k for i in range(1, n): if cou + lis[i] > k: num = cou + lis[i] - k cou = lis[i] - num ans += num else: cou = lis[i] print(ans)
false
26.666667
[ "-n, x = list(map(int, input().split()))", "+n, k = list(map(int, input().split()))", "-cou = 0", "-if lis[0] > x:", "- cou += lis[0] - x", "- lis[0] -= lis[0] - x", "-for i in range(n - 1):", "- if lis[i + 1] + lis[i] > x:", "- cou += lis[i + 1] + lis[i] - x", "- lis[i + 1] -= lis[i + 1] + lis[i] - x", "-print(cou)", "+cou = lis[0]", "+ans = 0", "+if cou > k:", "+ ans += cou - k", "+ cou = k", "+for i in range(1, n):", "+ if cou + lis[i] > k:", "+ num = cou + lis[i] - k", "+ cou = lis[i] - num", "+ ans += num", "+ else:", "+ cou = lis[i]", "+print(ans)" ]
false
0.047368
0.04646
1.019542
[ "s954132901", "s734369852" ]
u926046014
p02959
python
s911167401
s595415235
135
123
18,624
18,624
Accepted
Accepted
8.89
n = int(eval(input())) a = [int(x) for x in input().split()] b = [int(x) for x in input().split()] assist = 0 kill = 0 for i in range(n): if assist+b[i] < a[i]: kill += assist+b[i] assist = 0 else: if assist <= a[i]: kill += a[i] assist += b[i] - a[i] else: kill += a[i] assist = b[i] if assist == 0: print(kill) elif assist < a[-1]: print((kill + assist)) else: print((kill + a[-1]))
n = int(eval(input())) a = list(map(int, input().split())) b = list(map(int, input().split())) assist = 0 kill = 0 for i in range(n): if assist+b[i] < a[i]: kill += assist+b[i] assist = 0 else: if assist <= a[i]: kill += a[i] assist += b[i] - a[i] else: kill += a[i] assist = b[i] if assist == 0: print(kill) elif assist < a[-1]: print((kill + assist)) else: print((kill + a[-1]))
25
25
501
497
n = int(eval(input())) a = [int(x) for x in input().split()] b = [int(x) for x in input().split()] assist = 0 kill = 0 for i in range(n): if assist + b[i] < a[i]: kill += assist + b[i] assist = 0 else: if assist <= a[i]: kill += a[i] assist += b[i] - a[i] else: kill += a[i] assist = b[i] if assist == 0: print(kill) elif assist < a[-1]: print((kill + assist)) else: print((kill + a[-1]))
n = int(eval(input())) a = list(map(int, input().split())) b = list(map(int, input().split())) assist = 0 kill = 0 for i in range(n): if assist + b[i] < a[i]: kill += assist + b[i] assist = 0 else: if assist <= a[i]: kill += a[i] assist += b[i] - a[i] else: kill += a[i] assist = b[i] if assist == 0: print(kill) elif assist < a[-1]: print((kill + assist)) else: print((kill + a[-1]))
false
0
[ "-a = [int(x) for x in input().split()]", "-b = [int(x) for x in input().split()]", "+a = list(map(int, input().split()))", "+b = list(map(int, input().split()))" ]
false
0.040749
0.044215
0.921622
[ "s911167401", "s595415235" ]
u165368960
p02830
python
s791136318
s054706601
19
17
3,316
2,940
Accepted
Accepted
10.53
n = int(eval(input())) s, t =list(map(str, input().split())) ans_list = [0] * n for i in range(n): ans_list[i] = s[i] + t[i] print(("".join(ans_list)))
n = int(eval(input())) s, t =list(map(str, input().split())) ans = "" for i in range(n): ans += s[i] ans += t[i] print(ans)
8
9
148
125
n = int(eval(input())) s, t = list(map(str, input().split())) ans_list = [0] * n for i in range(n): ans_list[i] = s[i] + t[i] print(("".join(ans_list)))
n = int(eval(input())) s, t = list(map(str, input().split())) ans = "" for i in range(n): ans += s[i] ans += t[i] print(ans)
false
11.111111
[ "-ans_list = [0] * n", "+ans = \"\"", "- ans_list[i] = s[i] + t[i]", "-print((\"\".join(ans_list)))", "+ ans += s[i]", "+ ans += t[i]", "+print(ans)" ]
false
0.045376
0.045255
1.002662
[ "s791136318", "s054706601" ]
u492605584
p03164
python
s667284909
s292196170
1,021
446
308,296
119,916
Accepted
Accepted
56.32
N, W = list(map(int, input().split())) L = [list(map(int, input().split())) for i in range(N)] V = 0 for i in range(N): V += L[i][1] dp = [[float('inf')] * (V + 1) for i in range(N+1)] dp[0][0] = 0 for i in range(N): for j in range(V+1): if j - L[i][1] >= 0: dp[i+1][j] = min(dp[i][j], dp[i][j-L[i][1]] + L[i][0]) else: dp[i+1][j] = dp[i][j] ans = 0 for j in range(V+1): if W >= dp[-1][j]: ans = max(ans, j) print(ans)
N, W = list(map(int, input().split())) L = [list(map(int, input().split())) for i in range(N)] V = 0 for i in range(N): V += L[i][1] dp = [[10**9+1] * (V + 1) for i in range(N+1)] dp[0][0] = 0 for i in range(N): for j in range(V+1): if j - L[i][1] >= 0: dp[i+1][j] = min(dp[i][j], dp[i][j-L[i][1]] + L[i][0]) else: dp[i+1][j] = dp[i][j] ans = 0 for j in range(V+1): if W >= dp[-1][j]: ans = max(ans, j) print(ans)
19
19
486
481
N, W = list(map(int, input().split())) L = [list(map(int, input().split())) for i in range(N)] V = 0 for i in range(N): V += L[i][1] dp = [[float("inf")] * (V + 1) for i in range(N + 1)] dp[0][0] = 0 for i in range(N): for j in range(V + 1): if j - L[i][1] >= 0: dp[i + 1][j] = min(dp[i][j], dp[i][j - L[i][1]] + L[i][0]) else: dp[i + 1][j] = dp[i][j] ans = 0 for j in range(V + 1): if W >= dp[-1][j]: ans = max(ans, j) print(ans)
N, W = list(map(int, input().split())) L = [list(map(int, input().split())) for i in range(N)] V = 0 for i in range(N): V += L[i][1] dp = [[10**9 + 1] * (V + 1) for i in range(N + 1)] dp[0][0] = 0 for i in range(N): for j in range(V + 1): if j - L[i][1] >= 0: dp[i + 1][j] = min(dp[i][j], dp[i][j - L[i][1]] + L[i][0]) else: dp[i + 1][j] = dp[i][j] ans = 0 for j in range(V + 1): if W >= dp[-1][j]: ans = max(ans, j) print(ans)
false
0
[ "-dp = [[float(\"inf\")] * (V + 1) for i in range(N + 1)]", "+dp = [[10**9 + 1] * (V + 1) for i in range(N + 1)]" ]
false
0.060143
0.101214
0.594219
[ "s667284909", "s292196170" ]
u886274153
p03166
python
s966126492
s014695267
808
732
42,208
42,320
Accepted
Accepted
9.41
import collections n, m = [int(i) for i in input().split()] todc = collections.defaultdict(lambda: []) lendc = collections.defaultdict(lambda: -1) for k in range(m): i, j = [int(n) for n in input().split()] todc[j] += [i] def maxlen(n): if len(todc[n]) == 0: lendc[n] = 0 return 0 else: m = 0 for i in todc[n]: if lendc[i] == -1: lendc[i] = maxlen(i) m = max(m, lendc[i]+1) return m def maxlen_stack(org_n): stack = [org_n] while stack: n = stack.pop() if len(todc[n]) == 0: lendc[n] = 0 else: m = 0 recursive = [] for i in todc[n]: if lendc[i] == -1: recursive.append(i) else: m = max(m, lendc[i]+1) if recursive: stack += [n] + recursive else: lendc[n] = m return lendc[org_n] k = 0 for i in range(1, n+1): if lendc[i] == -1: #lendc[i] = maxlen(i) lendc[i] = maxlen_stack(i) k = max(k, lendc[i]) print(k)
import collections n, m = [int(i) for i in input().split()] todc = collections.defaultdict(lambda: []) lendc = collections.defaultdict(lambda: -1) for k in range(m): i, j = [int(n) for n in input().split()] todc[j] += [i] def maxlen(n): if len(todc[n]) == 0: lendc[n] = 0 return 0 else: m = 0 for i in todc[n]: if lendc[i] == -1: lendc[i] = maxlen(i) m = max(m, lendc[i]+1) return m def maxlen_stack(org_n): stack = [org_n] while stack: n = stack.pop() if lendc[n] != -1: continue if len(todc[n]) == 0: lendc[n] = 0 else: m = 0 recursive = [] for i in todc[n]: if lendc[i] == -1: recursive.append(i) else: m = max(m, lendc[i]+1) if recursive: stack += [n] + recursive else: lendc[n] = m return lendc[org_n] k = 0 for i in range(1, n+1): if lendc[i] == -1: #lendc[i] = maxlen(i) lendc[i] = maxlen_stack(i) k = max(k, lendc[i]) print(k)
51
53
1,212
1,270
import collections n, m = [int(i) for i in input().split()] todc = collections.defaultdict(lambda: []) lendc = collections.defaultdict(lambda: -1) for k in range(m): i, j = [int(n) for n in input().split()] todc[j] += [i] def maxlen(n): if len(todc[n]) == 0: lendc[n] = 0 return 0 else: m = 0 for i in todc[n]: if lendc[i] == -1: lendc[i] = maxlen(i) m = max(m, lendc[i] + 1) return m def maxlen_stack(org_n): stack = [org_n] while stack: n = stack.pop() if len(todc[n]) == 0: lendc[n] = 0 else: m = 0 recursive = [] for i in todc[n]: if lendc[i] == -1: recursive.append(i) else: m = max(m, lendc[i] + 1) if recursive: stack += [n] + recursive else: lendc[n] = m return lendc[org_n] k = 0 for i in range(1, n + 1): if lendc[i] == -1: # lendc[i] = maxlen(i) lendc[i] = maxlen_stack(i) k = max(k, lendc[i]) print(k)
import collections n, m = [int(i) for i in input().split()] todc = collections.defaultdict(lambda: []) lendc = collections.defaultdict(lambda: -1) for k in range(m): i, j = [int(n) for n in input().split()] todc[j] += [i] def maxlen(n): if len(todc[n]) == 0: lendc[n] = 0 return 0 else: m = 0 for i in todc[n]: if lendc[i] == -1: lendc[i] = maxlen(i) m = max(m, lendc[i] + 1) return m def maxlen_stack(org_n): stack = [org_n] while stack: n = stack.pop() if lendc[n] != -1: continue if len(todc[n]) == 0: lendc[n] = 0 else: m = 0 recursive = [] for i in todc[n]: if lendc[i] == -1: recursive.append(i) else: m = max(m, lendc[i] + 1) if recursive: stack += [n] + recursive else: lendc[n] = m return lendc[org_n] k = 0 for i in range(1, n + 1): if lendc[i] == -1: # lendc[i] = maxlen(i) lendc[i] = maxlen_stack(i) k = max(k, lendc[i]) print(k)
false
3.773585
[ "+ if lendc[n] != -1:", "+ continue" ]
false
0.038986
0.08491
0.459142
[ "s966126492", "s014695267" ]
u546285759
p00353
python
s840382106
s306475046
60
20
7,700
7,708
Accepted
Accepted
66.67
m, f, b = list(map(int, input().split())) print(("NA" if m+f < b else max(0, b-m)))
m, f, b = list(map(int, input().split())) print(("NA"*(m+f < b) + (m+f >= b)*str(max(0, b-m))))
2
2
76
88
m, f, b = list(map(int, input().split())) print(("NA" if m + f < b else max(0, b - m)))
m, f, b = list(map(int, input().split())) print(("NA" * (m + f < b) + (m + f >= b) * str(max(0, b - m))))
false
0
[ "-print((\"NA\" if m + f < b else max(0, b - m)))", "+print((\"NA\" * (m + f < b) + (m + f >= b) * str(max(0, b - m))))" ]
false
0.044406
0.044042
1.008251
[ "s840382106", "s306475046" ]
u020390084
p03361
python
s866692416
s535611134
20
18
3,064
3,064
Accepted
Accepted
10
h,w = list(map(int,input().split())) cambus = [list(eval(input())) for _ in range(h)] import sys for i in range(h): for j in range(w): if cambus[i][j]=="#": b = [] if i != 0: b.append(cambus[i-1][j] == "#") if i != h-1: b.append(cambus[i+1][j] == "#") if j != 0: b.append(cambus[i][j-1] == "#") if j != w-1: b.append(cambus[i][j+1] == "#") if not any(b): print("No") sys.exit() print("Yes")
#!/usr/bin/env python3 import sys YES = "Yes" # type: str NO = "No" # type: str def solve(H: int, W: int, s: "List[str]"): s = ["."*(W+2)]+["."+ss+"." for ss in s]+["."*(W+2)] direction = ((0,1),(1,0),(0,-1),(-1,0)) # 全ての黒マスの上下左右に一つでも黒マスがあればおk for i in range(H+2): for j in range(W+2): if s[i][j] == ".": continue for x,y in direction: if s[i+x][j+y] == "#": break else: print(NO) return print(YES) return def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() H = int(next(tokens)) # type: int W = int(next(tokens)) # type: int s = [next(tokens) for _ in range(H)] # type: "List[str]" solve(H, W, s) if __name__ == '__main__': main()
22
41
503
991
h, w = list(map(int, input().split())) cambus = [list(eval(input())) for _ in range(h)] import sys for i in range(h): for j in range(w): if cambus[i][j] == "#": b = [] if i != 0: b.append(cambus[i - 1][j] == "#") if i != h - 1: b.append(cambus[i + 1][j] == "#") if j != 0: b.append(cambus[i][j - 1] == "#") if j != w - 1: b.append(cambus[i][j + 1] == "#") if not any(b): print("No") sys.exit() print("Yes")
#!/usr/bin/env python3 import sys YES = "Yes" # type: str NO = "No" # type: str def solve(H: int, W: int, s: "List[str]"): s = ["." * (W + 2)] + ["." + ss + "." for ss in s] + ["." * (W + 2)] direction = ((0, 1), (1, 0), (0, -1), (-1, 0)) # 全ての黒マスの上下左右に一つでも黒マスがあればおk for i in range(H + 2): for j in range(W + 2): if s[i][j] == ".": continue for x, y in direction: if s[i + x][j + y] == "#": break else: print(NO) return print(YES) return def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() H = int(next(tokens)) # type: int W = int(next(tokens)) # type: int s = [next(tokens) for _ in range(H)] # type: "List[str]" solve(H, W, s) if __name__ == "__main__": main()
false
46.341463
[ "-h, w = list(map(int, input().split()))", "-cambus = [list(eval(input())) for _ in range(h)]", "+#!/usr/bin/env python3", "-for i in range(h):", "- for j in range(w):", "- if cambus[i][j] == \"#\":", "- b = []", "- if i != 0:", "- b.append(cambus[i - 1][j] == \"#\")", "- if i != h - 1:", "- b.append(cambus[i + 1][j] == \"#\")", "- if j != 0:", "- b.append(cambus[i][j - 1] == \"#\")", "- if j != w - 1:", "- b.append(cambus[i][j + 1] == \"#\")", "- if not any(b):", "- print(\"No\")", "- sys.exit()", "-print(\"Yes\")", "+YES = \"Yes\" # type: str", "+NO = \"No\" # type: str", "+", "+", "+def solve(H: int, W: int, s: \"List[str]\"):", "+ s = [\".\" * (W + 2)] + [\".\" + ss + \".\" for ss in s] + [\".\" * (W + 2)]", "+ direction = ((0, 1), (1, 0), (0, -1), (-1, 0))", "+ # 全ての黒マスの上下左右に一つでも黒マスがあればおk", "+ for i in range(H + 2):", "+ for j in range(W + 2):", "+ if s[i][j] == \".\":", "+ continue", "+ for x, y in direction:", "+ if s[i + x][j + y] == \"#\":", "+ break", "+ else:", "+ print(NO)", "+ return", "+ print(YES)", "+ return", "+", "+", "+def main():", "+ def iterate_tokens():", "+ for line in sys.stdin:", "+ for word in line.split():", "+ yield word", "+", "+ tokens = iterate_tokens()", "+ H = int(next(tokens)) # type: int", "+ W = int(next(tokens)) # type: int", "+ s = [next(tokens) for _ in range(H)] # type: \"List[str]\"", "+ solve(H, W, s)", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.0415
0.038041
1.090912
[ "s866692416", "s535611134" ]
u285891772
p03835
python
s034691664
s788960714
1,787
1,626
15,236
15,300
Accepted
Accepted
9.01
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import accumulate, permutations, combinations, product, groupby from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left from fractions import gcd from heapq import heappush, heappop 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 import numpy as np K, S = MAP() count = 0 for X in range(0, K+1): for Y in range(0, K+1): Z = S - X - Y if 0 <= Z <= K: count += 1 print(count)
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2 from itertools import accumulate, permutations, combinations, product, groupby from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left from fractions import gcd from heapq import heappush, heappop from functools import reduce import numpy as np 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 K, S = MAP() ans = 0 for X in range(K+1): for Y in range(K+1): Z = S - X - Y if 0 <= Z <=K: ans += 1 print(ans)
31
32
946
942
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import accumulate, permutations, combinations, product, groupby from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left from fractions import gcd from heapq import heappush, heappop 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 import numpy as np K, S = MAP() count = 0 for X in range(0, K + 1): for Y in range(0, K + 1): Z = S - X - Y if 0 <= Z <= K: count += 1 print(count)
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2 from itertools import accumulate, permutations, combinations, product, groupby from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left from fractions import gcd from heapq import heappush, heappop from functools import reduce import numpy as np 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 K, S = MAP() ans = 0 for X in range(K + 1): for Y in range(K + 1): Z = S - X - Y if 0 <= Z <= K: ans += 1 print(ans)
false
3.125
[ "-from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians", "+from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2", "+import numpy as np", "-import numpy as np", "-", "-count = 0", "-for X in range(0, K + 1):", "- for Y in range(0, K + 1):", "+ans = 0", "+for X in range(K + 1):", "+ for Y in range(K + 1):", "- count += 1", "-print(count)", "+ ans += 1", "+print(ans)" ]
false
0.0404
0.039633
1.019355
[ "s034691664", "s788960714" ]
u997648604
p02693
python
s333872511
s596120383
106
92
27,208
61,644
Accepted
Accepted
13.21
import itertools import math import numpy as np import fractions from collections import deque from itertools import combinations from functools import reduce from functools import lru_cache import bisect import sys sys.setrecursionlimit(10**9) def main(): K = int(eval(input())) A,B = list(map(int,input().split())) ok = False for k in range(A,B+1): if k % K == 0: ok = True print(("OK" if ok else "NG")) if __name__ == "__main__": main()
import sys sys.setrecursionlimit(10**9) def mi(): return list(map(int,input().split())) def ii(): return int(eval(input())) def isp(): return input().split() def deb(text): print(("-------\n{}\n-------".format(text))) INF=10**20 def main(): K=ii() A,B=mi() for x in range(A,B+1): if x % K == 0: print("OK") exit() print("NG") if __name__ == "__main__": main()
30
26
506
431
import itertools import math import numpy as np import fractions from collections import deque from itertools import combinations from functools import reduce from functools import lru_cache import bisect import sys sys.setrecursionlimit(10**9) def main(): K = int(eval(input())) A, B = list(map(int, input().split())) ok = False for k in range(A, B + 1): if k % K == 0: ok = True print(("OK" if ok else "NG")) if __name__ == "__main__": main()
import sys sys.setrecursionlimit(10**9) def mi(): return list(map(int, input().split())) def ii(): return int(eval(input())) def isp(): return input().split() def deb(text): print(("-------\n{}\n-------".format(text))) INF = 10**20 def main(): K = ii() A, B = mi() for x in range(A, B + 1): if x % K == 0: print("OK") exit() print("NG") if __name__ == "__main__": main()
false
13.333333
[ "-import itertools", "-import math", "-import numpy as np", "-import fractions", "-from collections import deque", "-from itertools import combinations", "-from functools import reduce", "-from functools import lru_cache", "-import bisect", "+def mi():", "+ return list(map(int, input().split()))", "+", "+", "+def ii():", "+ return int(eval(input()))", "+", "+", "+def isp():", "+ return input().split()", "+", "+", "+def deb(text):", "+", "+", "+INF = 10**20", "+", "+", "- K = int(eval(input()))", "- A, B = list(map(int, input().split()))", "- ok = False", "- for k in range(A, B + 1):", "- if k % K == 0:", "- ok = True", "- print((\"OK\" if ok else \"NG\"))", "+ K = ii()", "+ A, B = mi()", "+ for x in range(A, B + 1):", "+ if x % K == 0:", "+ print(\"OK\")", "+ exit()", "+ print(\"NG\")" ]
false
0.036354
0.035044
1.0374
[ "s333872511", "s596120383" ]
u811967730
p02759
python
s282839227
s741182558
179
17
38,256
2,940
Accepted
Accepted
90.5
N = int(eval(input())) ans = N // 2 + N % 2 print(ans)
N = int(eval(input())) ans = (N + 1) // 2 print(ans)
5
5
55
53
N = int(eval(input())) ans = N // 2 + N % 2 print(ans)
N = int(eval(input())) ans = (N + 1) // 2 print(ans)
false
0
[ "-ans = N // 2 + N % 2", "+ans = (N + 1) // 2" ]
false
0.053672
0.052848
1.015603
[ "s282839227", "s741182558" ]
u644907318
p02755
python
s235071804
s411580513
196
178
39,024
38,384
Accepted
Accepted
9.18
A,B = list(map(int,input().split())) x = -1 for i in range(1,20000): if int(i*1.08)-i==A and int(i*1.1)-i==B: x = i break print(x)
A,B = list(map(int,input().split())) a1 = A/0.08 if a1!=int(A/0.08): a1 = int(A/0.08)+1 else: a1 = int(A/0.08) a2 = (A+1)/0.08 if a2!=int((A+1)/0.08): a2 = int((A+1)/0.08)+1 else: a2 = int((A+1)/0.08) b1 = B/0.1 if b1!=int(B/0.1): b1 = int(B/0.1)+1 else: b1 = int(B/0.1) b2 = (B+1)/0.1 if b2!=int((B+1)/0.1): b2 = int((B+1)/0.1)+1 else: b2 = int((B+1)/0.1) X = list(range(a1,a2)) Y = list(range(b1,b2)) x = -1 for i in X: if i in Y: x = i break print(x)
7
29
150
515
A, B = list(map(int, input().split())) x = -1 for i in range(1, 20000): if int(i * 1.08) - i == A and int(i * 1.1) - i == B: x = i break print(x)
A, B = list(map(int, input().split())) a1 = A / 0.08 if a1 != int(A / 0.08): a1 = int(A / 0.08) + 1 else: a1 = int(A / 0.08) a2 = (A + 1) / 0.08 if a2 != int((A + 1) / 0.08): a2 = int((A + 1) / 0.08) + 1 else: a2 = int((A + 1) / 0.08) b1 = B / 0.1 if b1 != int(B / 0.1): b1 = int(B / 0.1) + 1 else: b1 = int(B / 0.1) b2 = (B + 1) / 0.1 if b2 != int((B + 1) / 0.1): b2 = int((B + 1) / 0.1) + 1 else: b2 = int((B + 1) / 0.1) X = list(range(a1, a2)) Y = list(range(b1, b2)) x = -1 for i in X: if i in Y: x = i break print(x)
false
75.862069
[ "+a1 = A / 0.08", "+if a1 != int(A / 0.08):", "+ a1 = int(A / 0.08) + 1", "+else:", "+ a1 = int(A / 0.08)", "+a2 = (A + 1) / 0.08", "+if a2 != int((A + 1) / 0.08):", "+ a2 = int((A + 1) / 0.08) + 1", "+else:", "+ a2 = int((A + 1) / 0.08)", "+b1 = B / 0.1", "+if b1 != int(B / 0.1):", "+ b1 = int(B / 0.1) + 1", "+else:", "+ b1 = int(B / 0.1)", "+b2 = (B + 1) / 0.1", "+if b2 != int((B + 1) / 0.1):", "+ b2 = int((B + 1) / 0.1) + 1", "+else:", "+ b2 = int((B + 1) / 0.1)", "+X = list(range(a1, a2))", "+Y = list(range(b1, b2))", "-for i in range(1, 20000):", "- if int(i * 1.08) - i == A and int(i * 1.1) - i == B:", "+for i in X:", "+ if i in Y:" ]
false
0.053927
0.071661
0.752529
[ "s235071804", "s411580513" ]
u556589653
p03125
python
s849206872
s734612194
19
17
3,316
2,940
Accepted
Accepted
10.53
A, B = list(map(int,input().split())) if B % A == 0: print((A + B)) else: print((B - A))
a,b=list(map(int,input().split())) if b%a== 0: print((a+b)) else: print((b-a))
5
5
86
80
A, B = list(map(int, input().split())) if B % A == 0: print((A + B)) else: print((B - A))
a, b = list(map(int, input().split())) if b % a == 0: print((a + b)) else: print((b - a))
false
0
[ "-A, B = list(map(int, input().split()))", "-if B % A == 0:", "- print((A + B))", "+a, b = list(map(int, input().split()))", "+if b % a == 0:", "+ print((a + b))", "- print((B - A))", "+ print((b - a))" ]
false
0.047894
0.045874
1.044048
[ "s849206872", "s734612194" ]
u949115942
p02837
python
s216001739
s340353046
1,959
262
3,064
3,064
Accepted
Accepted
86.63
n = int(eval(input())) XY = [] for i in range(n): a = int(eval(input())) xy = [] for j in range(a): xy.append(list(map(int, input().split()))) XY.append(xy) def check(i, xiyj, HoU): # 矛盾したらFalse 正直者と仮定した証言より 正直&正直者と仮定されている / 不親切&不親切と仮定されている True if ((i >> xiyj) & 1) ^ HoU: return False return True max_honest = 0 for i in range(2 ** len(XY)): count = 0 honest = [0] * len(XY) is_contradiction = True for j in range(len(XY)): # 正直者と仮定したときだけ採用 if not ((i >> j) & 1): continue for k in range(len(XY[j])): xiyj = XY[j][k][0] - 1 HoU = XY[j][k][1] if not check(i, xiyj, HoU): is_contradiction = False if is_contradiction: for j in range(len(XY)): if ((i >> j) & 1): count+=1 if count > max_honest: max_honest =count print(max_honest)
n = int(eval(input())) XY = [] for i in range(n): a = int(eval(input())) xy = [] for j in range(a): xy.append(list(map(int, input().split()))) XY.append(xy) def check(i, xiyj, HoU): # 矛盾したらFalse 正直者と仮定した証言より 正直&正直者と仮定されている / 不親切&不親切と仮定されている True if ((i >> xiyj) & 1) ^ HoU: return False return True max_honest = 0 for i in range(2 ** len(XY)): count = 0 is_contradiction = True for j in range(len(XY)): # 正直者と仮定したときだけ採用 if not ((i >> j) & 1): continue for k in range(len(XY[j])): xiyj = XY[j][k][0] - 1 HoU = XY[j][k][1] if not check(i, xiyj, HoU): is_contradiction = False break if not is_contradiction: break if is_contradiction: for j in range(len(XY)): if ((i >> j) & 1): count+=1 if count > max_honest: max_honest =count print(max_honest)
41
44
1,002
1,065
n = int(eval(input())) XY = [] for i in range(n): a = int(eval(input())) xy = [] for j in range(a): xy.append(list(map(int, input().split()))) XY.append(xy) def check(i, xiyj, HoU): # 矛盾したらFalse 正直者と仮定した証言より 正直&正直者と仮定されている / 不親切&不親切と仮定されている True if ((i >> xiyj) & 1) ^ HoU: return False return True max_honest = 0 for i in range(2 ** len(XY)): count = 0 honest = [0] * len(XY) is_contradiction = True for j in range(len(XY)): # 正直者と仮定したときだけ採用 if not ((i >> j) & 1): continue for k in range(len(XY[j])): xiyj = XY[j][k][0] - 1 HoU = XY[j][k][1] if not check(i, xiyj, HoU): is_contradiction = False if is_contradiction: for j in range(len(XY)): if (i >> j) & 1: count += 1 if count > max_honest: max_honest = count print(max_honest)
n = int(eval(input())) XY = [] for i in range(n): a = int(eval(input())) xy = [] for j in range(a): xy.append(list(map(int, input().split()))) XY.append(xy) def check(i, xiyj, HoU): # 矛盾したらFalse 正直者と仮定した証言より 正直&正直者と仮定されている / 不親切&不親切と仮定されている True if ((i >> xiyj) & 1) ^ HoU: return False return True max_honest = 0 for i in range(2 ** len(XY)): count = 0 is_contradiction = True for j in range(len(XY)): # 正直者と仮定したときだけ採用 if not ((i >> j) & 1): continue for k in range(len(XY[j])): xiyj = XY[j][k][0] - 1 HoU = XY[j][k][1] if not check(i, xiyj, HoU): is_contradiction = False break if not is_contradiction: break if is_contradiction: for j in range(len(XY)): if (i >> j) & 1: count += 1 if count > max_honest: max_honest = count print(max_honest)
false
6.818182
[ "- honest = [0] * len(XY)", "+ break", "+ if not is_contradiction:", "+ break" ]
false
0.043931
0.037989
1.156394
[ "s216001739", "s340353046" ]
u150984829
p02396
python
s679213974
s434993232
130
70
5,612
6,296
Accepted
Accepted
46.15
i=1 while True: n=eval(input()) if int(n)==0:break print(f'Case {i}: {n}') i+=1
a=[] b=a.append while True: n=eval(input()) if int(n)==0:break b(n) for i in range(len(a)):print(f'Case {i+1}: {a[i]}')
6
7
82
122
i = 1 while True: n = eval(input()) if int(n) == 0: break print(f"Case {i}: {n}") i += 1
a = [] b = a.append while True: n = eval(input()) if int(n) == 0: break b(n) for i in range(len(a)): print(f"Case {i+1}: {a[i]}")
false
14.285714
[ "-i = 1", "+a = []", "+b = a.append", "- print(f\"Case {i}: {n}\")", "- i += 1", "+ b(n)", "+for i in range(len(a)):", "+ print(f\"Case {i+1}: {a[i]}\")" ]
false
0.035368
0.041551
0.8512
[ "s679213974", "s434993232" ]
u761320129
p03329
python
s397082614
s927475540
209
125
21,488
3,064
Accepted
Accepted
40.19
import sys sys.setrecursionlimit(10**7) N = int(eval(input())) wd = [1] n = 1 while 6**n <= N: wd.append(6**n) n += 1 n = 1 while 9**n <= N: wd.append(9**n) n += 1 if N in wd: print((1)) exit() wd.sort() INF = float('inf') mem = [INF] * (N+1) def dfs(n): if mem[n] != INF: return mem[n] if n < 6: return n mn = INF for d in wd[1:]: if n-d < 0: break mn = min(mn, 1 + dfs(n-d)) mem[n] = mn return mn print((dfs(N)))
import itertools N = int(eval(input())) sixs = [6, 36, 216, 1296, 7776, 46656] ans = N for ptn in itertools.product(list(range(6)), repeat=6): money = ope = 0 for s,p in zip(sixs,ptn): money += s*p ope += p if money > N: continue if ope > ans: continue rem = N - money while rem: ope += rem%9 rem //= 9 ans = min(ans, ope) print(ans)
31
19
501
401
import sys sys.setrecursionlimit(10**7) N = int(eval(input())) wd = [1] n = 1 while 6**n <= N: wd.append(6**n) n += 1 n = 1 while 9**n <= N: wd.append(9**n) n += 1 if N in wd: print((1)) exit() wd.sort() INF = float("inf") mem = [INF] * (N + 1) def dfs(n): if mem[n] != INF: return mem[n] if n < 6: return n mn = INF for d in wd[1:]: if n - d < 0: break mn = min(mn, 1 + dfs(n - d)) mem[n] = mn return mn print((dfs(N)))
import itertools N = int(eval(input())) sixs = [6, 36, 216, 1296, 7776, 46656] ans = N for ptn in itertools.product(list(range(6)), repeat=6): money = ope = 0 for s, p in zip(sixs, ptn): money += s * p ope += p if money > N: continue if ope > ans: continue rem = N - money while rem: ope += rem % 9 rem //= 9 ans = min(ans, ope) print(ans)
false
38.709677
[ "-import sys", "+import itertools", "-sys.setrecursionlimit(10**7)", "-wd = [1]", "-n = 1", "-while 6**n <= N:", "- wd.append(6**n)", "- n += 1", "-n = 1", "-while 9**n <= N:", "- wd.append(9**n)", "- n += 1", "-if N in wd:", "- print((1))", "- exit()", "-wd.sort()", "-INF = float(\"inf\")", "-mem = [INF] * (N + 1)", "-", "-", "-def dfs(n):", "- if mem[n] != INF:", "- return mem[n]", "- if n < 6:", "- return n", "- mn = INF", "- for d in wd[1:]:", "- if n - d < 0:", "- break", "- mn = min(mn, 1 + dfs(n - d))", "- mem[n] = mn", "- return mn", "-", "-", "-print((dfs(N)))", "+sixs = [6, 36, 216, 1296, 7776, 46656]", "+ans = N", "+for ptn in itertools.product(list(range(6)), repeat=6):", "+ money = ope = 0", "+ for s, p in zip(sixs, ptn):", "+ money += s * p", "+ ope += p", "+ if money > N:", "+ continue", "+ if ope > ans:", "+ continue", "+ rem = N - money", "+ while rem:", "+ ope += rem % 9", "+ rem //= 9", "+ ans = min(ans, ope)", "+print(ans)" ]
false
0.054178
0.158249
0.342358
[ "s397082614", "s927475540" ]
u941438707
p03637
python
s423389648
s202402697
83
64
14,252
14,252
Accepted
Accepted
22.89
n=int(eval(input())) a=list(map(int, input().split())) i=0 odd=0 even=0 eveneven=0 while i<n: if a[i]%4==0: eveneven+=1 elif a[i]%2==0: even+=1 else: odd+=1 i+=1 if even==0 and eveneven>=(odd-1): print("Yes") elif even!=0 and eveneven>=odd: print("Yes") else: print("No")
# whileだと実行時間83msだったけどforでは? n=int(eval(input())) a=list(map(int, input().split())) i=0 odd=0 even=0 eveneven=0 for i in a: if i%4==0: eveneven+=1 elif i%2==0: even+=1 else: odd+=1 if even==0 and eveneven>=(odd-1): print("Yes") elif even!=0 and eveneven>=odd: print("Yes") else: print("No")
20
20
340
353
n = int(eval(input())) a = list(map(int, input().split())) i = 0 odd = 0 even = 0 eveneven = 0 while i < n: if a[i] % 4 == 0: eveneven += 1 elif a[i] % 2 == 0: even += 1 else: odd += 1 i += 1 if even == 0 and eveneven >= (odd - 1): print("Yes") elif even != 0 and eveneven >= odd: print("Yes") else: print("No")
# whileだと実行時間83msだったけどforでは? n = int(eval(input())) a = list(map(int, input().split())) i = 0 odd = 0 even = 0 eveneven = 0 for i in a: if i % 4 == 0: eveneven += 1 elif i % 2 == 0: even += 1 else: odd += 1 if even == 0 and eveneven >= (odd - 1): print("Yes") elif even != 0 and eveneven >= odd: print("Yes") else: print("No")
false
0
[ "+# whileだと実行時間83msだったけどforでは?", "-while i < n:", "- if a[i] % 4 == 0:", "+for i in a:", "+ if i % 4 == 0:", "- elif a[i] % 2 == 0:", "+ elif i % 2 == 0:", "- i += 1" ]
false
0.036334
0.037806
0.961055
[ "s423389648", "s202402697" ]
u077291787
p03680
python
s927698865
s234281447
188
82
13,356
13,740
Accepted
Accepted
56.38
# ABC065B - Trained? n = int(eval(input())) lst = list(map(int, [input().rstrip() for _ in range(n)])) button = lst[0] count = 0 for _ in range(n): count += 1 if button == 2: break button = lst[button - 1] else: count = -1 print(count)
# ABC065B - Trained? import sys input = sys.stdin.readline n = int(eval(input())) lst = list(map(int, [input().rstrip() for _ in range(n)])) button = lst[0] count = 0 for _ in range(n): count += 1 if button == 2: break button = lst[button - 1] else: count = -1 print(count)
13
16
265
307
# ABC065B - Trained? n = int(eval(input())) lst = list(map(int, [input().rstrip() for _ in range(n)])) button = lst[0] count = 0 for _ in range(n): count += 1 if button == 2: break button = lst[button - 1] else: count = -1 print(count)
# ABC065B - Trained? import sys input = sys.stdin.readline n = int(eval(input())) lst = list(map(int, [input().rstrip() for _ in range(n)])) button = lst[0] count = 0 for _ in range(n): count += 1 if button == 2: break button = lst[button - 1] else: count = -1 print(count)
false
18.75
[ "+import sys", "+", "+input = sys.stdin.readline" ]
false
0.036455
0.035962
1.013715
[ "s927698865", "s234281447" ]
u006657459
p03944
python
s374621412
s630665016
70
17
3,064
3,064
Accepted
Accepted
75.71
fn = lambda: list(map(int, input().split())) W, H, N = fn() A = [[1 for _ in range(W)] for _ in range(H)] for _ in range(N): x, y, a = fn() if a == 1: for i in range(H): for j in range(x): A[i][j] = 0 elif a == 2: for i in range(H): for j in range(x, W): A[i][j] = 0 elif a == 3: for i in range(W): for j in range(y): A[j][i] = 0 elif a == 4: for i in range(W): for j in range(y, H): A[j][i] = 0 else: print('Something wrong') print((sum([sum(Ai) for Ai in A])))
fn = lambda: list(map(int, input().split())) W, H, N = fn() min_x, max_x = 0, W min_y, max_y = 0, H for i in range(N): xi, yi, ai = fn() if ai == 1: min_x = max(xi, min_x) elif ai == 2: max_x = min(xi, max_x) elif ai == 3: min_y = max(yi, min_y) elif ai == 4: max_y = min(yi, max_y) else: print('Something wrong') print((max(max_x - min_x, 0) * max(max_y - min_y, 0)))
25
18
656
442
fn = lambda: list(map(int, input().split())) W, H, N = fn() A = [[1 for _ in range(W)] for _ in range(H)] for _ in range(N): x, y, a = fn() if a == 1: for i in range(H): for j in range(x): A[i][j] = 0 elif a == 2: for i in range(H): for j in range(x, W): A[i][j] = 0 elif a == 3: for i in range(W): for j in range(y): A[j][i] = 0 elif a == 4: for i in range(W): for j in range(y, H): A[j][i] = 0 else: print("Something wrong") print((sum([sum(Ai) for Ai in A])))
fn = lambda: list(map(int, input().split())) W, H, N = fn() min_x, max_x = 0, W min_y, max_y = 0, H for i in range(N): xi, yi, ai = fn() if ai == 1: min_x = max(xi, min_x) elif ai == 2: max_x = min(xi, max_x) elif ai == 3: min_y = max(yi, min_y) elif ai == 4: max_y = min(yi, max_y) else: print("Something wrong") print((max(max_x - min_x, 0) * max(max_y - min_y, 0)))
false
28
[ "-A = [[1 for _ in range(W)] for _ in range(H)]", "-for _ in range(N):", "- x, y, a = fn()", "- if a == 1:", "- for i in range(H):", "- for j in range(x):", "- A[i][j] = 0", "- elif a == 2:", "- for i in range(H):", "- for j in range(x, W):", "- A[i][j] = 0", "- elif a == 3:", "- for i in range(W):", "- for j in range(y):", "- A[j][i] = 0", "- elif a == 4:", "- for i in range(W):", "- for j in range(y, H):", "- A[j][i] = 0", "+min_x, max_x = 0, W", "+min_y, max_y = 0, H", "+for i in range(N):", "+ xi, yi, ai = fn()", "+ if ai == 1:", "+ min_x = max(xi, min_x)", "+ elif ai == 2:", "+ max_x = min(xi, max_x)", "+ elif ai == 3:", "+ min_y = max(yi, min_y)", "+ elif ai == 4:", "+ max_y = min(yi, max_y)", "-print((sum([sum(Ai) for Ai in A])))", "+print((max(max_x - min_x, 0) * max(max_y - min_y, 0)))" ]
false
0.037173
0.042032
0.884411
[ "s374621412", "s630665016" ]
u863442865
p03488
python
s543497799
s659985209
757
18
80,604
3,188
Accepted
Accepted
97.62
def main(): import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) from collections import Counter, deque #from collections import defaultdict from itertools import combinations, permutations, accumulate, groupby #from itertools import product from bisect import bisect_left,bisect_right from heapq import heapify, heappop, heappush from math import floor, ceil #from operator import itemgetter #inf = 10**17 #mod = 10**9 + 7 s = input().rstrip() + 'T' x,y = list(map(int, input().split())) # 奇数はy方向, 偶数はx方向 l = [] susumu = 0 for i in range(len(s)): if s[i] == 'T': l.append(susumu) susumu = 0 else: susumu += 1 b = len(l) dp = [[0]*16001 for _ in range(3)] dp[0][8000] = 1 dp[1][8000] = 1 for i in range(b): if i==0: dp[2][8000+l[i]] = 1 elif i%2 == 0: for j in range(16000): if dp[0][j]: dp[2][j-l[i]] = 1 dp[2][j+l[i]] = 1 elif i%2 == 1: for j in range(16000): if dp[0][j]: dp[2][j-l[i]] = 1 dp[2][j+l[i]] = 1 dp = dp[1:] + [[0]*16000] if b%2 == 0: if dp[0][x+8000] == 1 and dp[1][y+8000] == 1: print('Yes') else: print('No') else: if dp[1][x+8000] == 1 and dp[0][y+8000] == 1: print('Yes') else: print('No') if __name__ == '__main__': main()
def main(): import sys input = sys.stdin.readline s = input().rstrip() x,y = list(map(int, input().split())) f = s.split('T') dx_list = list(map(len, f[::2])) dy_list = list(map(len, f[1::2])) nx = dx_list.pop(0) ny = 0 dx_list.sort(reverse=True) dy_list.sort(reverse=True) for dx in dx_list: if x >= nx: nx += dx else: nx -= dx for dy in dy_list: if y >= ny: ny += dy else: ny -= dy if nx == x and ny == y: print('Yes') else: print('No') if __name__ == '__main__': main()
58
34
1,631
669
def main(): import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) from collections import Counter, deque # from collections import defaultdict from itertools import combinations, permutations, accumulate, groupby # from itertools import product from bisect import bisect_left, bisect_right from heapq import heapify, heappop, heappush from math import floor, ceil # from operator import itemgetter # inf = 10**17 # mod = 10**9 + 7 s = input().rstrip() + "T" x, y = list(map(int, input().split())) # 奇数はy方向, 偶数はx方向 l = [] susumu = 0 for i in range(len(s)): if s[i] == "T": l.append(susumu) susumu = 0 else: susumu += 1 b = len(l) dp = [[0] * 16001 for _ in range(3)] dp[0][8000] = 1 dp[1][8000] = 1 for i in range(b): if i == 0: dp[2][8000 + l[i]] = 1 elif i % 2 == 0: for j in range(16000): if dp[0][j]: dp[2][j - l[i]] = 1 dp[2][j + l[i]] = 1 elif i % 2 == 1: for j in range(16000): if dp[0][j]: dp[2][j - l[i]] = 1 dp[2][j + l[i]] = 1 dp = dp[1:] + [[0] * 16000] if b % 2 == 0: if dp[0][x + 8000] == 1 and dp[1][y + 8000] == 1: print("Yes") else: print("No") else: if dp[1][x + 8000] == 1 and dp[0][y + 8000] == 1: print("Yes") else: print("No") if __name__ == "__main__": main()
def main(): import sys input = sys.stdin.readline s = input().rstrip() x, y = list(map(int, input().split())) f = s.split("T") dx_list = list(map(len, f[::2])) dy_list = list(map(len, f[1::2])) nx = dx_list.pop(0) ny = 0 dx_list.sort(reverse=True) dy_list.sort(reverse=True) for dx in dx_list: if x >= nx: nx += dx else: nx -= dx for dy in dy_list: if y >= ny: ny += dy else: ny -= dy if nx == x and ny == y: print("Yes") else: print("No") if __name__ == "__main__": main()
false
41.37931
[ "- sys.setrecursionlimit(10**7)", "- from collections import Counter, deque", "-", "- # from collections import defaultdict", "- from itertools import combinations, permutations, accumulate, groupby", "-", "- # from itertools import product", "- from bisect import bisect_left, bisect_right", "- from heapq import heapify, heappop, heappush", "- from math import floor, ceil", "-", "- # from operator import itemgetter", "- # inf = 10**17", "- # mod = 10**9 + 7", "- s = input().rstrip() + \"T\"", "+ s = input().rstrip()", "- # 奇数はy方向, 偶数はx方向", "- l = []", "- susumu = 0", "- for i in range(len(s)):", "- if s[i] == \"T\":", "- l.append(susumu)", "- susumu = 0", "+ f = s.split(\"T\")", "+ dx_list = list(map(len, f[::2]))", "+ dy_list = list(map(len, f[1::2]))", "+ nx = dx_list.pop(0)", "+ ny = 0", "+ dx_list.sort(reverse=True)", "+ dy_list.sort(reverse=True)", "+ for dx in dx_list:", "+ if x >= nx:", "+ nx += dx", "- susumu += 1", "- b = len(l)", "- dp = [[0] * 16001 for _ in range(3)]", "- dp[0][8000] = 1", "- dp[1][8000] = 1", "- for i in range(b):", "- if i == 0:", "- dp[2][8000 + l[i]] = 1", "- elif i % 2 == 0:", "- for j in range(16000):", "- if dp[0][j]:", "- dp[2][j - l[i]] = 1", "- dp[2][j + l[i]] = 1", "- elif i % 2 == 1:", "- for j in range(16000):", "- if dp[0][j]:", "- dp[2][j - l[i]] = 1", "- dp[2][j + l[i]] = 1", "- dp = dp[1:] + [[0] * 16000]", "- if b % 2 == 0:", "- if dp[0][x + 8000] == 1 and dp[1][y + 8000] == 1:", "- print(\"Yes\")", "+ nx -= dx", "+ for dy in dy_list:", "+ if y >= ny:", "+ ny += dy", "- print(\"No\")", "+ ny -= dy", "+ if nx == x and ny == y:", "+ print(\"Yes\")", "- if dp[1][x + 8000] == 1 and dp[0][y + 8000] == 1:", "- print(\"Yes\")", "- else:", "- print(\"No\")", "+ print(\"No\")" ]
false
0.140014
0.046935
2.983149
[ "s543497799", "s659985209" ]
u761320129
p03126
python
s716117572
s125504513
23
21
3,316
3,316
Accepted
Accepted
8.7
from collections import Counter N,M = list(map(int,input().split())) src = [tuple(map(int,input().split())) for i in range(N)] ctr = Counter() for row in src: ctr += Counter(row[1:]) ans = 0 for v in list(ctr.values()): if v==N: ans += 1 print(ans)
N,M = list(map(int,input().split())) A = [list(map(int,input().split())) for i in range(N)] from collections import Counter c = Counter() for a in A: c += Counter(a[1:]) ans = 0 for v in list(c.values()): if v==N: ans += 1 print(ans)
12
10
264
238
from collections import Counter N, M = list(map(int, input().split())) src = [tuple(map(int, input().split())) for i in range(N)] ctr = Counter() for row in src: ctr += Counter(row[1:]) ans = 0 for v in list(ctr.values()): if v == N: ans += 1 print(ans)
N, M = list(map(int, input().split())) A = [list(map(int, input().split())) for i in range(N)] from collections import Counter c = Counter() for a in A: c += Counter(a[1:]) ans = 0 for v in list(c.values()): if v == N: ans += 1 print(ans)
false
16.666667
[ "+N, M = list(map(int, input().split()))", "+A = [list(map(int, input().split())) for i in range(N)]", "-N, M = list(map(int, input().split()))", "-src = [tuple(map(int, input().split())) for i in range(N)]", "-ctr = Counter()", "-for row in src:", "- ctr += Counter(row[1:])", "+c = Counter()", "+for a in A:", "+ c += Counter(a[1:])", "-for v in list(ctr.values()):", "+for v in list(c.values()):" ]
false
0.042275
0.042102
1.004112
[ "s716117572", "s125504513" ]
u151785909
p03557
python
s543941122
s633067202
1,082
960
67,380
23,328
Accepted
Accepted
11.28
n = int(eval(input())) a = list(map(int,input().split())) b = list(map(int,input().split())) c = list(map(int,input().split())) t = 0 ans = 0 u =[0]*n d =[0]*n a2 =[] b2 =[] c2 =[] for i in range(n): a2.append([2,a[i]]) for i in range(n): b2.append([1,b[i]]) for i in range(n): c2.append([0,c[i]]) a2b2=a2+b2 b2c2=b2+c2 a2b2.sort(key = lambda x:(x[1],x[0])) b2c2.sort(key = lambda x:(x[1],x[0]),reverse=True) j=0 c=0 for i in range(2*n): if a2b2[i][0]==2: c+=1 if a2b2[i][0]==1: u[j]=c j+=1 j=0 c=0 for i in range(2*n): if b2c2[i][0]==0: c+=1 if b2c2[i][0]==1: d[j]=c j+=1 d.reverse() for i in range(n): ans+=u[i]*d[i] print(ans)
n = int(eval(input())) a = list(map(int,input().split())) b = list(map(int,input().split())) c = list(map(int,input().split())) a.sort() b.sort() c.sort() def n_smaller_a(num): if num>a[n-1]: return n if num<=a[0]: return 0 left=0 right=n-1 mid=(left+right)//2 while right-left>1: if a[mid]>=num: right=mid else: left=mid mid=(left+right)//2 if a[left]==num: return left else: return left+1 def n_bigger_c(num): if num >= c[n-1]: return 0 if num < c[0]: return n left=0 right=n-1 mid=(left+right)//2 while right-left>1: if c[mid]>num: right=mid else: left=mid mid=(left+right)//2 if c[right]==num: return n-right-1 else: return n-right ans = 0 for i in range(n): ans+=n_bigger_c(b[i])*n_smaller_a(b[i]) print(ans)
44
53
750
994
n = int(eval(input())) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) t = 0 ans = 0 u = [0] * n d = [0] * n a2 = [] b2 = [] c2 = [] for i in range(n): a2.append([2, a[i]]) for i in range(n): b2.append([1, b[i]]) for i in range(n): c2.append([0, c[i]]) a2b2 = a2 + b2 b2c2 = b2 + c2 a2b2.sort(key=lambda x: (x[1], x[0])) b2c2.sort(key=lambda x: (x[1], x[0]), reverse=True) j = 0 c = 0 for i in range(2 * n): if a2b2[i][0] == 2: c += 1 if a2b2[i][0] == 1: u[j] = c j += 1 j = 0 c = 0 for i in range(2 * n): if b2c2[i][0] == 0: c += 1 if b2c2[i][0] == 1: d[j] = c j += 1 d.reverse() for i in range(n): ans += u[i] * d[i] print(ans)
n = int(eval(input())) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) a.sort() b.sort() c.sort() def n_smaller_a(num): if num > a[n - 1]: return n if num <= a[0]: return 0 left = 0 right = n - 1 mid = (left + right) // 2 while right - left > 1: if a[mid] >= num: right = mid else: left = mid mid = (left + right) // 2 if a[left] == num: return left else: return left + 1 def n_bigger_c(num): if num >= c[n - 1]: return 0 if num < c[0]: return n left = 0 right = n - 1 mid = (left + right) // 2 while right - left > 1: if c[mid] > num: right = mid else: left = mid mid = (left + right) // 2 if c[right] == num: return n - right - 1 else: return n - right ans = 0 for i in range(n): ans += n_bigger_c(b[i]) * n_smaller_a(b[i]) print(ans)
false
16.981132
[ "-t = 0", "+a.sort()", "+b.sort()", "+c.sort()", "+", "+", "+def n_smaller_a(num):", "+ if num > a[n - 1]:", "+ return n", "+ if num <= a[0]:", "+ return 0", "+ left = 0", "+ right = n - 1", "+ mid = (left + right) // 2", "+ while right - left > 1:", "+ if a[mid] >= num:", "+ right = mid", "+ else:", "+ left = mid", "+ mid = (left + right) // 2", "+ if a[left] == num:", "+ return left", "+ else:", "+ return left + 1", "+", "+", "+def n_bigger_c(num):", "+ if num >= c[n - 1]:", "+ return 0", "+ if num < c[0]:", "+ return n", "+ left = 0", "+ right = n - 1", "+ mid = (left + right) // 2", "+ while right - left > 1:", "+ if c[mid] > num:", "+ right = mid", "+ else:", "+ left = mid", "+ mid = (left + right) // 2", "+ if c[right] == num:", "+ return n - right - 1", "+ else:", "+ return n - right", "+", "+", "-u = [0] * n", "-d = [0] * n", "-a2 = []", "-b2 = []", "-c2 = []", "- a2.append([2, a[i]])", "-for i in range(n):", "- b2.append([1, b[i]])", "-for i in range(n):", "- c2.append([0, c[i]])", "-a2b2 = a2 + b2", "-b2c2 = b2 + c2", "-a2b2.sort(key=lambda x: (x[1], x[0]))", "-b2c2.sort(key=lambda x: (x[1], x[0]), reverse=True)", "-j = 0", "-c = 0", "-for i in range(2 * n):", "- if a2b2[i][0] == 2:", "- c += 1", "- if a2b2[i][0] == 1:", "- u[j] = c", "- j += 1", "-j = 0", "-c = 0", "-for i in range(2 * n):", "- if b2c2[i][0] == 0:", "- c += 1", "- if b2c2[i][0] == 1:", "- d[j] = c", "- j += 1", "-d.reverse()", "-for i in range(n):", "- ans += u[i] * d[i]", "+ ans += n_bigger_c(b[i]) * n_smaller_a(b[i])" ]
false
0.155506
0.039601
3.926817
[ "s543941122", "s633067202" ]
u557168336
p02886
python
s488528930
s799795990
19
17
3,060
2,940
Accepted
Accepted
10.53
import sys input = sys.stdin.readline N = int(eval(input())) vD = list(map(int, input().split())) res = 0 for x in range(0, N-1): for y in range(x+1, N): res += vD[x] * vD[y] print(res)
N = int(eval(input())) vA = list(map(int, input().split())) res = 0 cs = 0 for a in vA: res += cs * a cs += a print(res)
12
9
197
128
import sys input = sys.stdin.readline N = int(eval(input())) vD = list(map(int, input().split())) res = 0 for x in range(0, N - 1): for y in range(x + 1, N): res += vD[x] * vD[y] print(res)
N = int(eval(input())) vA = list(map(int, input().split())) res = 0 cs = 0 for a in vA: res += cs * a cs += a print(res)
false
25
[ "-import sys", "-", "-input = sys.stdin.readline", "-vD = list(map(int, input().split()))", "+vA = list(map(int, input().split()))", "-for x in range(0, N - 1):", "- for y in range(x + 1, N):", "- res += vD[x] * vD[y]", "+cs = 0", "+for a in vA:", "+ res += cs * a", "+ cs += a" ]
false
0.046728
0.008037
5.813733
[ "s488528930", "s799795990" ]
u197300773
p02659
python
s408468873
s999353065
65
60
61,952
62,000
Accepted
Accepted
7.69
import math a,b=[x for x in input().split()] a=int(a) b=round(float(b)*100) print((int(a*b//100)))
import math a,b=[x for x in input().split()] a=int(a) b=round(float(b)*100) print((a*b//100))
5
5
103
98
import math a, b = [x for x in input().split()] a = int(a) b = round(float(b) * 100) print((int(a * b // 100)))
import math a, b = [x for x in input().split()] a = int(a) b = round(float(b) * 100) print((a * b // 100))
false
0
[ "-print((int(a * b // 100)))", "+print((a * b // 100))" ]
false
0.042391
0.035116
1.20716
[ "s408468873", "s999353065" ]
u312025627
p03087
python
s196820044
s727559703
1,000
412
52,668
25,200
Accepted
Accepted
58.8
def main(): N, Q = (int(i) for i in input().split()) S = eval(input()) C = [0] * (len(S) + 1) for i in range(1, len(S)): C[i+1] = C[i] + (1 if S[i] == "C" and S[i-1] == "A" else 0) for q in range(Q): le, ri = (int(i) for i in input().split()) print((C[ri] - C[le])) if __name__ == '__main__': main()
def main(): N, Q = (int(i) for i in input().split()) S = eval(input()) LR = [[int(i) for i in input().split()] for j in range(Q)] AC = [0]*N for i, s in enumerate(S): AC[i] = AC[i-1] if i > 0 and S[i-1] == "A" and s == "C": AC[i] += 1 S = list([0] + AC) for le, ri in LR: print((S[ri] - S[le])) if __name__ == '__main__': main()
14
16
356
406
def main(): N, Q = (int(i) for i in input().split()) S = eval(input()) C = [0] * (len(S) + 1) for i in range(1, len(S)): C[i + 1] = C[i] + (1 if S[i] == "C" and S[i - 1] == "A" else 0) for q in range(Q): le, ri = (int(i) for i in input().split()) print((C[ri] - C[le])) if __name__ == "__main__": main()
def main(): N, Q = (int(i) for i in input().split()) S = eval(input()) LR = [[int(i) for i in input().split()] for j in range(Q)] AC = [0] * N for i, s in enumerate(S): AC[i] = AC[i - 1] if i > 0 and S[i - 1] == "A" and s == "C": AC[i] += 1 S = list([0] + AC) for le, ri in LR: print((S[ri] - S[le])) if __name__ == "__main__": main()
false
12.5
[ "- C = [0] * (len(S) + 1)", "- for i in range(1, len(S)):", "- C[i + 1] = C[i] + (1 if S[i] == \"C\" and S[i - 1] == \"A\" else 0)", "- for q in range(Q):", "- le, ri = (int(i) for i in input().split())", "- print((C[ri] - C[le]))", "+ LR = [[int(i) for i in input().split()] for j in range(Q)]", "+ AC = [0] * N", "+ for i, s in enumerate(S):", "+ AC[i] = AC[i - 1]", "+ if i > 0 and S[i - 1] == \"A\" and s == \"C\":", "+ AC[i] += 1", "+ S = list([0] + AC)", "+ for le, ri in LR:", "+ print((S[ri] - S[le]))" ]
false
0.065458
0.035046
1.867794
[ "s196820044", "s727559703" ]
u261103969
p02614
python
s575584171
s683933089
76
57
68,224
9,188
Accepted
Accepted
25
import sys readline = sys.stdin.readline MOD = 10 ** 9 + 7 INF = float('INF') sys.setrecursionlimit(10 ** 5) def main(): from itertools import product h, w, k = list(map(int, readline().split())) c = [list(eval(input())) for _ in range(h)] ans = 0 for row_bit in product(list(range(2)), repeat=h): for col_bit in product(list(range(2)), repeat=w): cnt = 0 for row in range(h): for col in range(w): if c[row][col] == "#" and (row_bit[row] and col_bit[col]): cnt += 1 if cnt == k: ans += 1 print(ans) if __name__ == '__main__': main()
from itertools import product h, w, k = list(map(int, input().split())) c = [list(eval(input())) for _ in range(h)] ans = 0 for row_bit in product(list(range(2)), repeat=h): for col_bit in product(list(range(2)), repeat=w): cnt = 0 for row in range(h): for col in range(w): if c[row][col] == "#" and (row_bit[row] and col_bit[col]): cnt += 1 if cnt == k: ans += 1 print(ans)
31
18
696
459
import sys readline = sys.stdin.readline MOD = 10**9 + 7 INF = float("INF") sys.setrecursionlimit(10**5) def main(): from itertools import product h, w, k = list(map(int, readline().split())) c = [list(eval(input())) for _ in range(h)] ans = 0 for row_bit in product(list(range(2)), repeat=h): for col_bit in product(list(range(2)), repeat=w): cnt = 0 for row in range(h): for col in range(w): if c[row][col] == "#" and (row_bit[row] and col_bit[col]): cnt += 1 if cnt == k: ans += 1 print(ans) if __name__ == "__main__": main()
from itertools import product h, w, k = list(map(int, input().split())) c = [list(eval(input())) for _ in range(h)] ans = 0 for row_bit in product(list(range(2)), repeat=h): for col_bit in product(list(range(2)), repeat=w): cnt = 0 for row in range(h): for col in range(w): if c[row][col] == "#" and (row_bit[row] and col_bit[col]): cnt += 1 if cnt == k: ans += 1 print(ans)
false
41.935484
[ "-import sys", "+from itertools import product", "-readline = sys.stdin.readline", "-MOD = 10**9 + 7", "-INF = float(\"INF\")", "-sys.setrecursionlimit(10**5)", "-", "-", "-def main():", "- from itertools import product", "-", "- h, w, k = list(map(int, readline().split()))", "- c = [list(eval(input())) for _ in range(h)]", "- ans = 0", "- for row_bit in product(list(range(2)), repeat=h):", "- for col_bit in product(list(range(2)), repeat=w):", "- cnt = 0", "- for row in range(h):", "- for col in range(w):", "- if c[row][col] == \"#\" and (row_bit[row] and col_bit[col]):", "- cnt += 1", "- if cnt == k:", "- ans += 1", "- print(ans)", "-", "-", "-if __name__ == \"__main__\":", "- main()", "+h, w, k = list(map(int, input().split()))", "+c = [list(eval(input())) for _ in range(h)]", "+ans = 0", "+for row_bit in product(list(range(2)), repeat=h):", "+ for col_bit in product(list(range(2)), repeat=w):", "+ cnt = 0", "+ for row in range(h):", "+ for col in range(w):", "+ if c[row][col] == \"#\" and (row_bit[row] and col_bit[col]):", "+ cnt += 1", "+ if cnt == k:", "+ ans += 1", "+print(ans)" ]
false
0.047904
0.123684
0.387311
[ "s575584171", "s683933089" ]
u695474809
p02707
python
s825517029
s456930435
173
147
33,992
32,164
Accepted
Accepted
15.03
import collections N = int(eval(input())) number = list(map(int,input().split())) number = collections.Counter(number) for i in range(1,N+1): if i in number: print((number[i])) else: print("0")
N = int(eval(input())) number = list(map(int,input().split())) ans = [0]*N for i in number: ans[i-1] += 1 for i in ans: print(i)
9
8
218
139
import collections N = int(eval(input())) number = list(map(int, input().split())) number = collections.Counter(number) for i in range(1, N + 1): if i in number: print((number[i])) else: print("0")
N = int(eval(input())) number = list(map(int, input().split())) ans = [0] * N for i in number: ans[i - 1] += 1 for i in ans: print(i)
false
11.111111
[ "-import collections", "-", "-number = collections.Counter(number)", "-for i in range(1, N + 1):", "- if i in number:", "- print((number[i]))", "- else:", "- print(\"0\")", "+ans = [0] * N", "+for i in number:", "+ ans[i - 1] += 1", "+for i in ans:", "+ print(i)" ]
false
0.045493
0.04041
1.125787
[ "s825517029", "s456930435" ]
u677121387
p03127
python
s628396073
s768909354
96
60
14,252
14,252
Accepted
Accepted
37.5
n = int(eval(input())) a = list(map(int,input().split())) a.sort() for i in range(1,n): while a[i]%a[0] != 0: a[0],a[i] = a[i]%a[0],a[0] else: ans = a[0] print(ans)
n = int(eval(input())) a = list(map(int,input().split())) for i in range(1,n): while a[i]%a[0] != 0: a[0],a[i] = a[i]%a[0],a[0] else: ans = a[0] print(ans)
11
10
186
177
n = int(eval(input())) a = list(map(int, input().split())) a.sort() for i in range(1, n): while a[i] % a[0] != 0: a[0], a[i] = a[i] % a[0], a[0] else: ans = a[0] print(ans)
n = int(eval(input())) a = list(map(int, input().split())) for i in range(1, n): while a[i] % a[0] != 0: a[0], a[i] = a[i] % a[0], a[0] else: ans = a[0] print(ans)
false
9.090909
[ "-a.sort()" ]
false
0.041932
0.042667
0.982789
[ "s628396073", "s768909354" ]
u465699806
p03401
python
s841806058
s967842394
820
385
118,800
65,696
Accepted
Accepted
53.05
import itertools as it import collections as col import heapq as hq import sys import copy as cp sys.setrecursionlimit(10**9) input = sys.stdin.readline def dump(*objects): print(*objects, file=sys.stderr) N = int(input()) A = [0] + list(map(int, input().split())) + [0] dump(N, A) B = cp.deepcopy(A) C = cp.deepcopy(A) for i in range(1, len(A)): dump(i) B[i] = B[i-1] + abs(A[i]-A[i-1]) for i in range(len(A)-2, -1, step=-1): dump(i) C[i] = C[i+1] + abs(A[i]-A[i+1]) dump(A, B, C) for i in range(1, N+1): dump(i, B[i-1] + B[N+1] - B[i+1] + abs(A[i-1]-A[i+1])) print(B[i-1] + C[i+1] + abs(A[i-1]-A[i+1])) exit(0)
import itertools as it import collections as col import heapq as hq import sys import copy as cp sys.setrecursionlimit(10**9) input = sys.stdin.readline N = int(eval(input())) A = [0] + list(map(int, input().split())) + [0] B = cp.deepcopy(A) C = cp.deepcopy(A) for i in range(1, len(A)): B[i] = B[i-1] + abs(A[i]-A[i-1]) for i in range(len(A)-2, -1, step=-1): C[i] = C[i+1] + abs(A[i]-A[i+1]) for i in range(1, N+1): print((B[i-1] + C[i+1] + abs(A[i-1]-A[i+1])))
30
18
675
486
import itertools as it import collections as col import heapq as hq import sys import copy as cp sys.setrecursionlimit(10**9) input = sys.stdin.readline def dump(*objects): print(*objects, file=sys.stderr) N = int(input()) A = [0] + list(map(int, input().split())) + [0] dump(N, A) B = cp.deepcopy(A) C = cp.deepcopy(A) for i in range(1, len(A)): dump(i) B[i] = B[i - 1] + abs(A[i] - A[i - 1]) for i in range(len(A) - 2, -1, step=-1): dump(i) C[i] = C[i + 1] + abs(A[i] - A[i + 1]) dump(A, B, C) for i in range(1, N + 1): dump(i, B[i - 1] + B[N + 1] - B[i + 1] + abs(A[i - 1] - A[i + 1])) print(B[i - 1] + C[i + 1] + abs(A[i - 1] - A[i + 1])) exit(0)
import itertools as it import collections as col import heapq as hq import sys import copy as cp sys.setrecursionlimit(10**9) input = sys.stdin.readline N = int(eval(input())) A = [0] + list(map(int, input().split())) + [0] B = cp.deepcopy(A) C = cp.deepcopy(A) for i in range(1, len(A)): B[i] = B[i - 1] + abs(A[i] - A[i - 1]) for i in range(len(A) - 2, -1, step=-1): C[i] = C[i + 1] + abs(A[i] - A[i + 1]) for i in range(1, N + 1): print((B[i - 1] + C[i + 1] + abs(A[i - 1] - A[i + 1])))
false
40
[ "-", "-", "-def dump(*objects):", "- print(*objects, file=sys.stderr)", "-", "-", "-N = int(input())", "+N = int(eval(input()))", "-dump(N, A)", "- dump(i)", "- dump(i)", "-dump(A, B, C)", "- dump(i, B[i - 1] + B[N + 1] - B[i + 1] + abs(A[i - 1] - A[i + 1]))", "- print(B[i - 1] + C[i + 1] + abs(A[i - 1] - A[i + 1]))", "-exit(0)", "+ print((B[i - 1] + C[i + 1] + abs(A[i - 1] - A[i + 1])))" ]
false
0.039206
0.041205
0.951485
[ "s841806058", "s967842394" ]
u836737505
p03478
python
s139212700
s546854981
37
34
2,940
3,060
Accepted
Accepted
8.11
n,a,b = list(map(int, input().split())) c =0 for i in range(1,n+1): d = sum(int(j) for j in list(str(i))) if a<=d and d<=b: c += i print(c)
n,a,b = list(map(int, input().split())) ans = 0 for i in range(1,n+1): c = sum(list(map(int, str(i)))) if a <= c <= b: ans += i print(ans)
7
7
155
154
n, a, b = list(map(int, input().split())) c = 0 for i in range(1, n + 1): d = sum(int(j) for j in list(str(i))) if a <= d and d <= b: c += i print(c)
n, a, b = list(map(int, input().split())) ans = 0 for i in range(1, n + 1): c = sum(list(map(int, str(i)))) if a <= c <= b: ans += i print(ans)
false
0
[ "-c = 0", "+ans = 0", "- d = sum(int(j) for j in list(str(i)))", "- if a <= d and d <= b:", "- c += i", "-print(c)", "+ c = sum(list(map(int, str(i))))", "+ if a <= c <= b:", "+ ans += i", "+print(ans)" ]
false
0.045071
0.149358
0.301766
[ "s139212700", "s546854981" ]
u377989038
p02689
python
s246757306
s753274313
536
242
57,228
20,124
Accepted
Accepted
54.85
n, m = list(map(int, input().split())) h = [0] + list(map(int, input().split())) ab = [(list(map(int, input().split())))for _ in range(m)] l = [set({}) for _ in range(n + 1)] for a, b in ab: l[a].add(b) l[b].add(a) cnt = -1 for i, v in enumerate(l): if len(v) != 0: if h[i] > max([h[j] for j in v]): cnt += 1 else: cnt += 1 print(cnt)
n, m = list(map(int, input().split())) h = [0] + list(map(int, input().split())) bl = [True] * (n + 1) for i in range(m): a, b = list(map(int, input().split())) if h[a] > h[b]: bl[b] = False elif h[a] < h[b]: bl[a] = False else: bl[a], bl[b] = False, False print((sum(bl) - 1))
17
13
390
317
n, m = list(map(int, input().split())) h = [0] + list(map(int, input().split())) ab = [(list(map(int, input().split()))) for _ in range(m)] l = [set({}) for _ in range(n + 1)] for a, b in ab: l[a].add(b) l[b].add(a) cnt = -1 for i, v in enumerate(l): if len(v) != 0: if h[i] > max([h[j] for j in v]): cnt += 1 else: cnt += 1 print(cnt)
n, m = list(map(int, input().split())) h = [0] + list(map(int, input().split())) bl = [True] * (n + 1) for i in range(m): a, b = list(map(int, input().split())) if h[a] > h[b]: bl[b] = False elif h[a] < h[b]: bl[a] = False else: bl[a], bl[b] = False, False print((sum(bl) - 1))
false
23.529412
[ "-ab = [(list(map(int, input().split()))) for _ in range(m)]", "-l = [set({}) for _ in range(n + 1)]", "-for a, b in ab:", "- l[a].add(b)", "- l[b].add(a)", "-cnt = -1", "-for i, v in enumerate(l):", "- if len(v) != 0:", "- if h[i] > max([h[j] for j in v]):", "- cnt += 1", "+bl = [True] * (n + 1)", "+for i in range(m):", "+ a, b = list(map(int, input().split()))", "+ if h[a] > h[b]:", "+ bl[b] = False", "+ elif h[a] < h[b]:", "+ bl[a] = False", "- cnt += 1", "-print(cnt)", "+ bl[a], bl[b] = False, False", "+print((sum(bl) - 1))" ]
false
0.096879
0.03847
2.518262
[ "s246757306", "s753274313" ]
u480472958
p03607
python
s213081634
s546145387
208
167
16,268
17,888
Accepted
Accepted
19.71
n = int(eval(input())) a = [int(eval(input())) for i in range(n)] dic = {} for i in range(n): if a[i] in dic: del dic[a[i]] else: dic[a[i]] = None print((len(dic)))
n = int(eval(input())) dic = {} for i in range(n): a = eval(input()) if a in dic: del dic[a] else: dic[a] = None print((len(dic)))
9
9
182
152
n = int(eval(input())) a = [int(eval(input())) for i in range(n)] dic = {} for i in range(n): if a[i] in dic: del dic[a[i]] else: dic[a[i]] = None print((len(dic)))
n = int(eval(input())) dic = {} for i in range(n): a = eval(input()) if a in dic: del dic[a] else: dic[a] = None print((len(dic)))
false
0
[ "-a = [int(eval(input())) for i in range(n)]", "- if a[i] in dic:", "- del dic[a[i]]", "+ a = eval(input())", "+ if a in dic:", "+ del dic[a]", "- dic[a[i]] = None", "+ dic[a] = None" ]
false
0.041716
0.043731
0.953918
[ "s213081634", "s546145387" ]
u021019433
p02832
python
s537696153
s809000002
145
105
26,268
17,976
Accepted
Accepted
27.59
n = int(eval(input())) a = list(map(int, input().split())) i = k = 0 try: while True: i = a.index(k + 1, i) + 1 k += 1 except ValueError: print((n-(k or n+1)))
n = int(eval(input())) k = 0 for x in map(int, input().split()): if x == k + 1: k += 1 print((n - k if k else -1))
9
6
172
118
n = int(eval(input())) a = list(map(int, input().split())) i = k = 0 try: while True: i = a.index(k + 1, i) + 1 k += 1 except ValueError: print((n - (k or n + 1)))
n = int(eval(input())) k = 0 for x in map(int, input().split()): if x == k + 1: k += 1 print((n - k if k else -1))
false
33.333333
[ "-a = list(map(int, input().split()))", "-i = k = 0", "-try:", "- while True:", "- i = a.index(k + 1, i) + 1", "+k = 0", "+for x in map(int, input().split()):", "+ if x == k + 1:", "-except ValueError:", "- print((n - (k or n + 1)))", "+print((n - k if k else -1))" ]
false
0.037084
0.035177
1.054214
[ "s537696153", "s809000002" ]
u692746605
p03074
python
s830066985
s750014713
59
42
7,108
7,876
Accepted
Accepted
28.81
n, k = list(map(int, input().split())) s = eval(input()) l = [0,0] if (s[0] == '0') else [0] for i in range(1, n): if s[i-1] != s[i]: l += [i]; l += [n] if (s[-1] == '1') else [n,n] ll = len(l) pl = 2 * k + 1 if ll <= pl: print(n) else: print((max(l[pl+i]-l[i] for i in range(0, ll-pl+1, 2))))
n, k = list(map(int, input().split())) s = eval(input()) l = [0,0] if (s[0] == '0') else [0] l += [i for i in range(1,n) if s[i-1] != s[i]] l += [n] if (s[-1] == '1') else [n,n] ll = len(l) pl = 2 * k + 1 if (ll < pl): print(n) else: print((max(l[pl+i]-l[i] for i in range(0, ll-pl+1, 2))))
13
12
313
296
n, k = list(map(int, input().split())) s = eval(input()) l = [0, 0] if (s[0] == "0") else [0] for i in range(1, n): if s[i - 1] != s[i]: l += [i] l += [n] if (s[-1] == "1") else [n, n] ll = len(l) pl = 2 * k + 1 if ll <= pl: print(n) else: print((max(l[pl + i] - l[i] for i in range(0, ll - pl + 1, 2))))
n, k = list(map(int, input().split())) s = eval(input()) l = [0, 0] if (s[0] == "0") else [0] l += [i for i in range(1, n) if s[i - 1] != s[i]] l += [n] if (s[-1] == "1") else [n, n] ll = len(l) pl = 2 * k + 1 if ll < pl: print(n) else: print((max(l[pl + i] - l[i] for i in range(0, ll - pl + 1, 2))))
false
7.692308
[ "-for i in range(1, n):", "- if s[i - 1] != s[i]:", "- l += [i]", "+l += [i for i in range(1, n) if s[i - 1] != s[i]]", "-if ll <= pl:", "+if ll < pl:" ]
false
0.039636
0.070912
0.558953
[ "s830066985", "s750014713" ]
u539969758
p02726
python
s347518389
s771719766
1,980
1,792
3,444
3,444
Accepted
Accepted
9.49
N, X, Y = list(map(int,input().split())) k_list = [0]*N for p in range(1, N): for q in range(p, N+1): p2X = abs(p - X) p2Y = abs(p - Y) q2X = abs(q - X) q2Y = abs(q - Y) distance = min(q-p, p2X+1+q2Y, p2Y+1+q2X) k_list[distance] += 1 for k in range(1, N): print((k_list[k]))
N, X, Y = list(map(int,input().split())) k_list = [0]*N for p in range(1, N): for q in range(p, N+1): p2X = abs(p - X) p2Y = abs(p - Y) q2X = abs(q - X) q2Y = abs(q - Y) distance = min(q-p, p2X+1+q2Y) k_list[distance] += 1 for k in range(1, N): print((k_list[k]))
15
15
347
328
N, X, Y = list(map(int, input().split())) k_list = [0] * N for p in range(1, N): for q in range(p, N + 1): p2X = abs(p - X) p2Y = abs(p - Y) q2X = abs(q - X) q2Y = abs(q - Y) distance = min(q - p, p2X + 1 + q2Y, p2Y + 1 + q2X) k_list[distance] += 1 for k in range(1, N): print((k_list[k]))
N, X, Y = list(map(int, input().split())) k_list = [0] * N for p in range(1, N): for q in range(p, N + 1): p2X = abs(p - X) p2Y = abs(p - Y) q2X = abs(q - X) q2Y = abs(q - Y) distance = min(q - p, p2X + 1 + q2Y) k_list[distance] += 1 for k in range(1, N): print((k_list[k]))
false
0
[ "- distance = min(q - p, p2X + 1 + q2Y, p2Y + 1 + q2X)", "+ distance = min(q - p, p2X + 1 + q2Y)" ]
false
0.042442
0.046621
0.910365
[ "s347518389", "s771719766" ]
u670180528
p03818
python
s379791457
s079291282
51
36
19,480
16,160
Accepted
Accepted
29.41
from collections import*;n,l=open(0);a=sum(v-1for v in list(Counter(l.split()).values()));print((int(n)-a-(a%2)))
_,a=open(0);a=len(set(a.split()));print((a-(a%2<1)))
1
1
105
50
from collections import * n, l = open(0) a = sum(v - 1 for v in list(Counter(l.split()).values())) print((int(n) - a - (a % 2)))
_, a = open(0) a = len(set(a.split())) print((a - (a % 2 < 1)))
false
0
[ "-from collections import *", "-", "-n, l = open(0)", "-a = sum(v - 1 for v in list(Counter(l.split()).values()))", "-print((int(n) - a - (a % 2)))", "+_, a = open(0)", "+a = len(set(a.split()))", "+print((a - (a % 2 < 1)))" ]
false
0.037878
0.060495
0.626126
[ "s379791457", "s079291282" ]
u811841526
p02394
python
s593789781
s848701816
30
20
7,660
5,592
Accepted
Accepted
33.33
w,h,x,y,r = list(map(int, input().split())) if r <= x <= w-r and r <= y <= h-r: print('Yes') else: print('No')
W, H, x, y, r = list(map(int, input().split())) if r <= x <= W-r and r <= y <= H-r: print("Yes") else: print("No")
5
7
112
125
w, h, x, y, r = list(map(int, input().split())) if r <= x <= w - r and r <= y <= h - r: print("Yes") else: print("No")
W, H, x, y, r = list(map(int, input().split())) if r <= x <= W - r and r <= y <= H - r: print("Yes") else: print("No")
false
28.571429
[ "-w, h, x, y, r = list(map(int, input().split()))", "-if r <= x <= w - r and r <= y <= h - r:", "+W, H, x, y, r = list(map(int, input().split()))", "+if r <= x <= W - r and r <= y <= H - r:" ]
false
0.255661
0.044557
5.737816
[ "s593789781", "s848701816" ]
u296518383
p03329
python
s405559050
s181749108
1,016
644
3,828
3,828
Accepted
Accepted
36.61
N=int(eval(input())) M=[0]*(N+1) M[1]=1 for i in range(2,N+1): L=[M[i-1]+1] j=0 while i-6**j>=0: L.append(M[i-6**j]+1) j+=1 j=0 while i-9**j>=0: L.append(M[i-9**j]+1) j+=1 M[i]=min(L) #print(M) print((M[N]))
N = int(eval(input())) pattern = [1, 6, 36, 216, 1296, 7776, 46656, 9, 81, 729, 6561, 59049] INF = 10**6 dp = [INF] * (N+1) dp[0] = 0 for i in range(N+1): for p in pattern: if i + p <= N: dp[i+p] = min(dp[i+p], dp[i]+1) print((dp[N]))
19
14
248
255
N = int(eval(input())) M = [0] * (N + 1) M[1] = 1 for i in range(2, N + 1): L = [M[i - 1] + 1] j = 0 while i - 6**j >= 0: L.append(M[i - 6**j] + 1) j += 1 j = 0 while i - 9**j >= 0: L.append(M[i - 9**j] + 1) j += 1 M[i] = min(L) # print(M) print((M[N]))
N = int(eval(input())) pattern = [1, 6, 36, 216, 1296, 7776, 46656, 9, 81, 729, 6561, 59049] INF = 10**6 dp = [INF] * (N + 1) dp[0] = 0 for i in range(N + 1): for p in pattern: if i + p <= N: dp[i + p] = min(dp[i + p], dp[i] + 1) print((dp[N]))
false
26.315789
[ "-M = [0] * (N + 1)", "-M[1] = 1", "-for i in range(2, N + 1):", "- L = [M[i - 1] + 1]", "- j = 0", "- while i - 6**j >= 0:", "- L.append(M[i - 6**j] + 1)", "- j += 1", "- j = 0", "- while i - 9**j >= 0:", "- L.append(M[i - 9**j] + 1)", "- j += 1", "- M[i] = min(L)", "-# print(M)", "-print((M[N]))", "+pattern = [1, 6, 36, 216, 1296, 7776, 46656, 9, 81, 729, 6561, 59049]", "+INF = 10**6", "+dp = [INF] * (N + 1)", "+dp[0] = 0", "+for i in range(N + 1):", "+ for p in pattern:", "+ if i + p <= N:", "+ dp[i + p] = min(dp[i + p], dp[i] + 1)", "+print((dp[N]))" ]
false
0.235238
0.10865
2.165087
[ "s405559050", "s181749108" ]
u760802228
p02572
python
s689408227
s929368732
130
114
94,368
105,264
Accepted
Accepted
12.31
N = int(eval(input())) A = list(map(int, input().split())) t = 0 S = sum(A) c = 0 for i in range(len(A) - 1): S -= A[i] t = (t + (A[i] * S)) % 1000000007 print(t)
N = int(eval(input())) A = list(map(int, input().split())) t = 0 S = sum(A) c = 0 for i in range(len(A) - 1): S -= A[i] t = (t + (A[i] * S)) print((t % 1000000007))
9
9
183
183
N = int(eval(input())) A = list(map(int, input().split())) t = 0 S = sum(A) c = 0 for i in range(len(A) - 1): S -= A[i] t = (t + (A[i] * S)) % 1000000007 print(t)
N = int(eval(input())) A = list(map(int, input().split())) t = 0 S = sum(A) c = 0 for i in range(len(A) - 1): S -= A[i] t = t + (A[i] * S) print((t % 1000000007))
false
0
[ "- t = (t + (A[i] * S)) % 1000000007", "-print(t)", "+ t = t + (A[i] * S)", "+print((t % 1000000007))" ]
false
0.040365
0.054886
0.73544
[ "s689408227", "s929368732" ]
u909643606
p03212
python
s841498105
s056319354
157
18
16,020
3,064
Accepted
Accepted
88.54
s = ["3", "5", "7"] s2 = ["357", "375", "537", "573", "735", "753"] s3 = [] s4 = [] s5 = [] s6 = [] s7 = [] s8 = [] def PowerGorilla(s_t, s_i): s_new = [] for j in range(len(s_t)): for i in range(len(s_t[0])+1): for k in range(3): s_new.append(s_t[j][:i] + s_i[k] + s_t[j][i:]) sss = list(set(s_new)) return sss s3 = PowerGorilla(s2, s) s4 = PowerGorilla(s3, s) s5 = PowerGorilla(s4, s) s6 = PowerGorilla(s5, s) s7 = PowerGorilla(s6, s) s8 = PowerGorilla(s7, s) #print(PowerGorilla(s8, s)) num = [] num.extend(int(i) for i in s2) num.extend(int(i) for i in s3) num.extend(int(i) for i in s4) num.extend(int(i) for i in s5) num.extend(int(i) for i in s6) num.extend(int(i) for i in s7) num.extend(int(i) for i in s8) num.sort() count = 0 n = int(eval(input())) for i in range(len(num)): if num[i] <= n: count += 1 print(count)
import itertools n = eval(input()) dp = [[[[[0] * 2 for i in range(2)] for j in range(2)] for k in range(2)]for l in range(len(n))] #dp[i桁目][nより小さいかどうか][3がある][5がある][7がある] for i in range(len(n)): dp[i][0][0][0][0] = 1 for j in range(10): if int(n[0]) >= j: dp[0][int(n[0]) == j][j == 3][j == 5][j == 7] = 1 dp[0][1][0][0][0] = 0 for i, j, k, l, m in itertools.product(list(range(len(n)-1)), list(range(2)), list(range(2)), list(range(2)), list(range(10))): if m in [3, 5, 7]: dp[i + 1][0][j or m == 3][k or m == 5][l or m == 7] += dp[i][0][j][k][l] if m <= int(n[i+1]): dp[i + 1][m == int(n[i+1])][j or m == 3][k or m == 5][l or m == 7] += dp[i][1][j][k][l] print((dp[-1][0][1][1][1] + dp[-1][1][1][1][1]))
47
20
939
739
s = ["3", "5", "7"] s2 = ["357", "375", "537", "573", "735", "753"] s3 = [] s4 = [] s5 = [] s6 = [] s7 = [] s8 = [] def PowerGorilla(s_t, s_i): s_new = [] for j in range(len(s_t)): for i in range(len(s_t[0]) + 1): for k in range(3): s_new.append(s_t[j][:i] + s_i[k] + s_t[j][i:]) sss = list(set(s_new)) return sss s3 = PowerGorilla(s2, s) s4 = PowerGorilla(s3, s) s5 = PowerGorilla(s4, s) s6 = PowerGorilla(s5, s) s7 = PowerGorilla(s6, s) s8 = PowerGorilla(s7, s) # print(PowerGorilla(s8, s)) num = [] num.extend(int(i) for i in s2) num.extend(int(i) for i in s3) num.extend(int(i) for i in s4) num.extend(int(i) for i in s5) num.extend(int(i) for i in s6) num.extend(int(i) for i in s7) num.extend(int(i) for i in s8) num.sort() count = 0 n = int(eval(input())) for i in range(len(num)): if num[i] <= n: count += 1 print(count)
import itertools n = eval(input()) dp = [ [[[[0] * 2 for i in range(2)] for j in range(2)] for k in range(2)] for l in range(len(n)) ] # dp[i桁目][nより小さいかどうか][3がある][5がある][7がある] for i in range(len(n)): dp[i][0][0][0][0] = 1 for j in range(10): if int(n[0]) >= j: dp[0][int(n[0]) == j][j == 3][j == 5][j == 7] = 1 dp[0][1][0][0][0] = 0 for i, j, k, l, m in itertools.product( list(range(len(n) - 1)), list(range(2)), list(range(2)), list(range(2)), list(range(10)), ): if m in [3, 5, 7]: dp[i + 1][0][j or m == 3][k or m == 5][l or m == 7] += dp[i][0][j][k][l] if m <= int(n[i + 1]): dp[i + 1][m == int(n[i + 1])][j or m == 3][k or m == 5][l or m == 7] += dp[ i ][1][j][k][l] print((dp[-1][0][1][1][1] + dp[-1][1][1][1][1]))
false
57.446809
[ "-s = [\"3\", \"5\", \"7\"]", "-s2 = [\"357\", \"375\", \"537\", \"573\", \"735\", \"753\"]", "-s3 = []", "-s4 = []", "-s5 = []", "-s6 = []", "-s7 = []", "-s8 = []", "+import itertools", "-", "-def PowerGorilla(s_t, s_i):", "- s_new = []", "- for j in range(len(s_t)):", "- for i in range(len(s_t[0]) + 1):", "- for k in range(3):", "- s_new.append(s_t[j][:i] + s_i[k] + s_t[j][i:])", "- sss = list(set(s_new))", "- return sss", "-", "-", "-s3 = PowerGorilla(s2, s)", "-s4 = PowerGorilla(s3, s)", "-s5 = PowerGorilla(s4, s)", "-s6 = PowerGorilla(s5, s)", "-s7 = PowerGorilla(s6, s)", "-s8 = PowerGorilla(s7, s)", "-# print(PowerGorilla(s8, s))", "-num = []", "-num.extend(int(i) for i in s2)", "-num.extend(int(i) for i in s3)", "-num.extend(int(i) for i in s4)", "-num.extend(int(i) for i in s5)", "-num.extend(int(i) for i in s6)", "-num.extend(int(i) for i in s7)", "-num.extend(int(i) for i in s8)", "-num.sort()", "-count = 0", "-n = int(eval(input()))", "-for i in range(len(num)):", "- if num[i] <= n:", "- count += 1", "-print(count)", "+n = eval(input())", "+dp = [", "+ [[[[0] * 2 for i in range(2)] for j in range(2)] for k in range(2)]", "+ for l in range(len(n))", "+]", "+# dp[i桁目][nより小さいかどうか][3がある][5がある][7がある]", "+for i in range(len(n)):", "+ dp[i][0][0][0][0] = 1", "+for j in range(10):", "+ if int(n[0]) >= j:", "+ dp[0][int(n[0]) == j][j == 3][j == 5][j == 7] = 1", "+dp[0][1][0][0][0] = 0", "+for i, j, k, l, m in itertools.product(", "+ list(range(len(n) - 1)),", "+ list(range(2)),", "+ list(range(2)),", "+ list(range(2)),", "+ list(range(10)),", "+):", "+ if m in [3, 5, 7]:", "+ dp[i + 1][0][j or m == 3][k or m == 5][l or m == 7] += dp[i][0][j][k][l]", "+ if m <= int(n[i + 1]):", "+ dp[i + 1][m == int(n[i + 1])][j or m == 3][k or m == 5][l or m == 7] += dp[", "+ i", "+ ][1][j][k][l]", "+print((dp[-1][0][1][1][1] + dp[-1][1][1][1][1]))" ]
false
0.536866
0.041706
12.872628
[ "s841498105", "s056319354" ]
u645250356
p03578
python
s764948698
s098979046
438
248
118,728
58,060
Accepted
Accepted
43.38
from collections import Counter,defaultdict,deque import sys,heapq,bisect,math,itertools,string,queue sys.setrecursionlimit(10**8) mod = 10**9+7 def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) def inpl_str(): return list(sys.stdin.readline().split()) def inpln(n): return list(int(sys.stdin.readline()) for i in range(n)) n = inp() d = inpl() m = inp() t = inpl() cntd = Counter(d) cntt = Counter(t) for key in cntt: if cntt[key] > cntd[key]: print('NO') break else: print('YES')
from collections import Counter,defaultdict,deque from heapq import heappop,heappush from bisect import bisect_left,bisect_right import sys,math,itertools,fractions,pprint sys.setrecursionlimit(10**8) mod = 10**9+7 INF = float('inf') def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) n = inp() a = inpl() m = inp() b = inpl() ca = Counter(a) cb = Counter(b) for key in list(cb): if cb[key] > ca[key]: print('NO') break else: print('YES')
21
22
584
542
from collections import Counter, defaultdict, deque import sys, heapq, bisect, math, itertools, string, queue sys.setrecursionlimit(10**8) mod = 10**9 + 7 def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) def inpl_str(): return list(sys.stdin.readline().split()) def inpln(n): return list(int(sys.stdin.readline()) for i in range(n)) n = inp() d = inpl() m = inp() t = inpl() cntd = Counter(d) cntt = Counter(t) for key in cntt: if cntt[key] > cntd[key]: print("NO") break else: print("YES")
from collections import Counter, defaultdict, deque from heapq import heappop, heappush from bisect import bisect_left, bisect_right import sys, math, itertools, fractions, pprint sys.setrecursionlimit(10**8) mod = 10**9 + 7 INF = float("inf") def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) n = inp() a = inpl() m = inp() b = inpl() ca = Counter(a) cb = Counter(b) for key in list(cb): if cb[key] > ca[key]: print("NO") break else: print("YES")
false
4.545455
[ "-import sys, heapq, bisect, math, itertools, string, queue", "+from heapq import heappop, heappush", "+from bisect import bisect_left, bisect_right", "+import sys, math, itertools, fractions, pprint", "+INF = float(\"inf\")", "-def inpl_str():", "- return list(sys.stdin.readline().split())", "-", "-", "-def inpln(n):", "- return list(int(sys.stdin.readline()) for i in range(n))", "-", "-", "-d = inpl()", "+a = inpl()", "-t = inpl()", "-cntd = Counter(d)", "-cntt = Counter(t)", "-for key in cntt:", "- if cntt[key] > cntd[key]:", "+b = inpl()", "+ca = Counter(a)", "+cb = Counter(b)", "+for key in list(cb):", "+ if cb[key] > ca[key]:" ]
false
0.046216
0.086969
0.531406
[ "s764948698", "s098979046" ]
u536926054
p02580
python
s795460063
s883196245
1,341
1,209
134,732
139,540
Accepted
Accepted
9.84
import numpy as np def pd(s): # print(s) pass # input H, W, M = list(map(int, input().split())) ms = [ [int(i) for i in input().split()] for m in range(M) ] pd(f"{H=} {W=} {M=}") pd(f"{ms=}") rows = [0]*(H+1) cols = [0]*(W+1) bombs = {} for m in ms: h = m[0] w = m[1] rows[h] += 1 cols[w] += 1 bombs[f"{h},{w}"] = True rmax = max(rows) cmax = max(cols) rmax_hs = [i for i, v in enumerate(rows) if v == rmax] cmax_wh = [i for i, v in enumerate(cols) if v == cmax] for h in rmax_hs: for w in cmax_wh: if f"{h},{w}" not in bombs: print((rmax + cmax)) exit() print((rmax + cmax - 1))
import numpy as np import itertools def pd(s): #print(s) pass # input H, W, M = list(map(int, input().split())) ms = [ [int(i) for i in input().split()] for m in range(M) ] pd(f"{H=} {W=} {M=}") pd(f"{ms=}") rows = [0]*(H+1) cols = [0]*(W+1) bombs = {} for h,w in ms: rows[h] += 1 cols[w] += 1 bombs[f"{h},{w}"] = True rmax = max(rows) cmax = max(cols) rmax_hs = [i for i, v in enumerate(rows) if v == rmax] cmax_wh = [i for i, v in enumerate(cols) if v == cmax] for h,w in itertools.product(rmax_hs, cmax_wh): if f"{h},{w}" not in bombs: print((rmax + cmax)) exit() print((rmax + cmax - 1))
38
36
686
672
import numpy as np def pd(s): # print(s) pass # input H, W, M = list(map(int, input().split())) ms = [[int(i) for i in input().split()] for m in range(M)] pd(f"{H=} {W=} {M=}") pd(f"{ms=}") rows = [0] * (H + 1) cols = [0] * (W + 1) bombs = {} for m in ms: h = m[0] w = m[1] rows[h] += 1 cols[w] += 1 bombs[f"{h},{w}"] = True rmax = max(rows) cmax = max(cols) rmax_hs = [i for i, v in enumerate(rows) if v == rmax] cmax_wh = [i for i, v in enumerate(cols) if v == cmax] for h in rmax_hs: for w in cmax_wh: if f"{h},{w}" not in bombs: print((rmax + cmax)) exit() print((rmax + cmax - 1))
import numpy as np import itertools def pd(s): # print(s) pass # input H, W, M = list(map(int, input().split())) ms = [[int(i) for i in input().split()] for m in range(M)] pd(f"{H=} {W=} {M=}") pd(f"{ms=}") rows = [0] * (H + 1) cols = [0] * (W + 1) bombs = {} for h, w in ms: rows[h] += 1 cols[w] += 1 bombs[f"{h},{w}"] = True rmax = max(rows) cmax = max(cols) rmax_hs = [i for i, v in enumerate(rows) if v == rmax] cmax_wh = [i for i, v in enumerate(cols) if v == cmax] for h, w in itertools.product(rmax_hs, cmax_wh): if f"{h},{w}" not in bombs: print((rmax + cmax)) exit() print((rmax + cmax - 1))
false
5.263158
[ "+import itertools", "-for m in ms:", "- h = m[0]", "- w = m[1]", "+for h, w in ms:", "-for h in rmax_hs:", "- for w in cmax_wh:", "- if f\"{h},{w}\" not in bombs:", "- print((rmax + cmax))", "- exit()", "+for h, w in itertools.product(rmax_hs, cmax_wh):", "+ if f\"{h},{w}\" not in bombs:", "+ print((rmax + cmax))", "+ exit()" ]
false
0.058478
0.057119
1.023803
[ "s795460063", "s883196245" ]
u392319141
p02695
python
s363281140
s860808548
621
351
109,924
9,184
Accepted
Accepted
43.48
from functools import lru_cache N, M, Q = list(map(int, input().split())) BCD = [[] for _ in range(N)] for _ in range(Q): a, b, c, d = list(map(int, input().split())) BCD[a - 1].append((b - a, c, d)) @lru_cache(maxsize=None) def search(mi, A): if len(A) > N: return 0 ret = 0 for i in range(1, A[-1] + 1): ret = max(ret, search(i, A + (i,))) d = len(A) for b, c, d in BCD[N - d]: if A[-(b + 1)] - A[-1] == c: ret += d return ret ans = 0 for i in range(1, M + 1): ans = max(ans, search(i, (i,))) print(ans)
N, M, Q = list(map(int, input().split())) BCD = [[] for _ in range(N)] for _ in range(Q): a, b, c, d = list(map(int, input().split())) BCD[a - 1].append((b - a, c, d)) def search(mi, A): if len(A) > N: return 0 ret = 0 for i in range(1, A[-1] + 1): ret = max(ret, search(i, A + (i,))) d = len(A) for b, c, d in BCD[N - d]: if A[-(b + 1)] - A[-1] == c: ret += d return ret ans = 0 for i in range(1, M + 1): ans = max(ans, search(i, (i,))) print(ans)
28
25
599
538
from functools import lru_cache N, M, Q = list(map(int, input().split())) BCD = [[] for _ in range(N)] for _ in range(Q): a, b, c, d = list(map(int, input().split())) BCD[a - 1].append((b - a, c, d)) @lru_cache(maxsize=None) def search(mi, A): if len(A) > N: return 0 ret = 0 for i in range(1, A[-1] + 1): ret = max(ret, search(i, A + (i,))) d = len(A) for b, c, d in BCD[N - d]: if A[-(b + 1)] - A[-1] == c: ret += d return ret ans = 0 for i in range(1, M + 1): ans = max(ans, search(i, (i,))) print(ans)
N, M, Q = list(map(int, input().split())) BCD = [[] for _ in range(N)] for _ in range(Q): a, b, c, d = list(map(int, input().split())) BCD[a - 1].append((b - a, c, d)) def search(mi, A): if len(A) > N: return 0 ret = 0 for i in range(1, A[-1] + 1): ret = max(ret, search(i, A + (i,))) d = len(A) for b, c, d in BCD[N - d]: if A[-(b + 1)] - A[-1] == c: ret += d return ret ans = 0 for i in range(1, M + 1): ans = max(ans, search(i, (i,))) print(ans)
false
10.714286
[ "-from functools import lru_cache", "-", "-@lru_cache(maxsize=None)" ]
false
0.250247
0.099313
2.519783
[ "s363281140", "s860808548" ]
u102461423
p02642
python
s450828372
s482302336
573
155
125,100
46,496
Accepted
Accepted
72.95
import sys import numpy as np from numba import njit read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines U = 10**6 + 10 @njit('(i8[::1],i8[::1])', cache=True) def solve(A, primes): B = np.zeros(U + 1, np.int64) for x in A: B[x] += 1 for p in primes: for i in range(U // p + 1): B[p * i] += B[i] ret = 0 for x in A: ret += B[x] == 1 return ret def prime_table(N): is_prime = np.zeros(N, np.int64) is_prime[2:3] = 1 is_prime[3::2] = 1 for p in range(3, N, 2): if p * p >= N: break if is_prime[p]: is_prime[p * p::p + p] = 0 return is_prime, np.where(is_prime)[0] A = np.array(read().split(), np.int64)[1:] _, primes = prime_table(U) print((solve(A, primes)))
import sys import numpy as np read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines U = 10**6 + 10 def main(A, primes): B = np.zeros(U + 1, np.int64) for x in A: B[x] += 1 for p in primes: for i in range(U // p + 1): B[p * i] += B[i] ret = 0 for x in A: ret += B[x] == 1 return ret if sys.argv[-1] == 'ONLINE_JUDGE': from numba.pycc import CC cc = CC('my_module') cc.export('main', '(i8[::1],i8[::1])')(main) cc.compile() exit() from my_module import main def prime_table(N): is_prime = np.zeros(N, np.int64) is_prime[2:3] = 1 is_prime[3::2] = 1 for p in range(3, N, 2): if p * p >= N: break if is_prime[p]: is_prime[p * p::p + p] = 0 return is_prime, np.where(is_prime)[0] A = np.array(read().split(), np.int64)[1:] _, primes = prime_table(U) print((main(A, primes)))
38
44
870
1,008
import sys import numpy as np from numba import njit read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines U = 10**6 + 10 @njit("(i8[::1],i8[::1])", cache=True) def solve(A, primes): B = np.zeros(U + 1, np.int64) for x in A: B[x] += 1 for p in primes: for i in range(U // p + 1): B[p * i] += B[i] ret = 0 for x in A: ret += B[x] == 1 return ret def prime_table(N): is_prime = np.zeros(N, np.int64) is_prime[2:3] = 1 is_prime[3::2] = 1 for p in range(3, N, 2): if p * p >= N: break if is_prime[p]: is_prime[p * p :: p + p] = 0 return is_prime, np.where(is_prime)[0] A = np.array(read().split(), np.int64)[1:] _, primes = prime_table(U) print((solve(A, primes)))
import sys import numpy as np read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines U = 10**6 + 10 def main(A, primes): B = np.zeros(U + 1, np.int64) for x in A: B[x] += 1 for p in primes: for i in range(U // p + 1): B[p * i] += B[i] ret = 0 for x in A: ret += B[x] == 1 return ret if sys.argv[-1] == "ONLINE_JUDGE": from numba.pycc import CC cc = CC("my_module") cc.export("main", "(i8[::1],i8[::1])")(main) cc.compile() exit() from my_module import main def prime_table(N): is_prime = np.zeros(N, np.int64) is_prime[2:3] = 1 is_prime[3::2] = 1 for p in range(3, N, 2): if p * p >= N: break if is_prime[p]: is_prime[p * p :: p + p] = 0 return is_prime, np.where(is_prime)[0] A = np.array(read().split(), np.int64)[1:] _, primes = prime_table(U) print((main(A, primes)))
false
13.636364
[ "-from numba import njit", "-@njit(\"(i8[::1],i8[::1])\", cache=True)", "-def solve(A, primes):", "+def main(A, primes):", "+", "+", "+if sys.argv[-1] == \"ONLINE_JUDGE\":", "+ from numba.pycc import CC", "+", "+ cc = CC(\"my_module\")", "+ cc.export(\"main\", \"(i8[::1],i8[::1])\")(main)", "+ cc.compile()", "+ exit()", "+from my_module import main", "-print((solve(A, primes)))", "+print((main(A, primes)))" ]
false
0.188131
0.269839
0.697195
[ "s450828372", "s482302336" ]
u600402037
p02726
python
s779433045
s089264667
342
222
73,948
43,880
Accepted
Accepted
35.09
# coding: utf-8 import sys sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) N, X, Y = lr() dis = [[0] * (N+1) for _ in range(N+1)] for i in range(1, N): for j in range(i+1, N+1): dis[i][j] = j - i dis[j][i] = j - i dis[X][Y] = 1 dis[Y][X] = 1 for i in range(1, N): for j in range(i+1, N+1): dis[i][j] = min(dis[i][j], dis[i][X] + 1 + dis[Y][j]) answer = [0] * (N) for i in range(1, N): for j in range(i+1, N+1): d = dis[i][j] answer[d] += 1 print(('\n'.join(map(str, answer[1:]))))
# coding: utf-8 import sys import numpy as np sr = lambda: sys.stdin.buffer.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) N, X, Y = lr() dist = [] for i in range(1, N+1): z = np.arange(i+1, N+1) d1 = z - i d2 = np.abs(i - X) + np.abs(z - Y) + 1 d = np.minimum(d1, d2) dist.append(d) dist = np.concatenate(dist) cnt = np.bincount(dist, minlength=N) print(('\n'.join(cnt[1:].astype(str))))
27
20
622
467
# coding: utf-8 import sys sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) N, X, Y = lr() dis = [[0] * (N + 1) for _ in range(N + 1)] for i in range(1, N): for j in range(i + 1, N + 1): dis[i][j] = j - i dis[j][i] = j - i dis[X][Y] = 1 dis[Y][X] = 1 for i in range(1, N): for j in range(i + 1, N + 1): dis[i][j] = min(dis[i][j], dis[i][X] + 1 + dis[Y][j]) answer = [0] * (N) for i in range(1, N): for j in range(i + 1, N + 1): d = dis[i][j] answer[d] += 1 print(("\n".join(map(str, answer[1:]))))
# coding: utf-8 import sys import numpy as np sr = lambda: sys.stdin.buffer.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) N, X, Y = lr() dist = [] for i in range(1, N + 1): z = np.arange(i + 1, N + 1) d1 = z - i d2 = np.abs(i - X) + np.abs(z - Y) + 1 d = np.minimum(d1, d2) dist.append(d) dist = np.concatenate(dist) cnt = np.bincount(dist, minlength=N) print(("\n".join(cnt[1:].astype(str))))
false
25.925926
[ "+import numpy as np", "-sr = lambda: sys.stdin.readline().rstrip()", "+sr = lambda: sys.stdin.buffer.readline().rstrip()", "-dis = [[0] * (N + 1) for _ in range(N + 1)]", "-for i in range(1, N):", "- for j in range(i + 1, N + 1):", "- dis[i][j] = j - i", "- dis[j][i] = j - i", "-dis[X][Y] = 1", "-dis[Y][X] = 1", "-for i in range(1, N):", "- for j in range(i + 1, N + 1):", "- dis[i][j] = min(dis[i][j], dis[i][X] + 1 + dis[Y][j])", "-answer = [0] * (N)", "-for i in range(1, N):", "- for j in range(i + 1, N + 1):", "- d = dis[i][j]", "- answer[d] += 1", "-print((\"\\n\".join(map(str, answer[1:]))))", "+dist = []", "+for i in range(1, N + 1):", "+ z = np.arange(i + 1, N + 1)", "+ d1 = z - i", "+ d2 = np.abs(i - X) + np.abs(z - Y) + 1", "+ d = np.minimum(d1, d2)", "+ dist.append(d)", "+dist = np.concatenate(dist)", "+cnt = np.bincount(dist, minlength=N)", "+print((\"\\n\".join(cnt[1:].astype(str))))" ]
false
0.037554
0.181158
0.207299
[ "s779433045", "s089264667" ]
u803848678
p04002
python
s656102705
s510072747
2,488
1,971
166,892
166,488
Accepted
Accepted
20.78
from collections import Counter h, w, n = list(map(int, input().split())) d = Counter() for _ in range(n): a, b = list(map(int, input().split())) for i in range(3): for j in range(3): if w > b+j-1 > 1 < a+i-1 < h: d[(a+i,b+j)] += 1 ans = Counter() for i in list(d.values()): ans[i] += 1 print(((h-2)*(w-2) - sum(ans.values()))) for i in range(1,10): print((ans[i]))
i=lambda:map(int,input().split()) h,w,n=i() r=[0,1,2] d={} while n: a,b=i();n-=1 for j in r: for k in r: if w>=b+k>2<a+j<=h:d[(a+j,b+k)]=d.get((a+j,b+k),0)+1 c=[0]*10 for i in d:c[d[i]]+=1 c[0]=(h-2)*(w-2)-sum(c) print(*c,sep="\n")
15
13
409
272
from collections import Counter h, w, n = list(map(int, input().split())) d = Counter() for _ in range(n): a, b = list(map(int, input().split())) for i in range(3): for j in range(3): if w > b + j - 1 > 1 < a + i - 1 < h: d[(a + i, b + j)] += 1 ans = Counter() for i in list(d.values()): ans[i] += 1 print(((h - 2) * (w - 2) - sum(ans.values()))) for i in range(1, 10): print((ans[i]))
i = lambda: map(int, input().split()) h, w, n = i() r = [0, 1, 2] d = {} while n: a, b = i() n -= 1 for j in r: for k in r: if w >= b + k > 2 < a + j <= h: d[(a + j, b + k)] = d.get((a + j, b + k), 0) + 1 c = [0] * 10 for i in d: c[d[i]] += 1 c[0] = (h - 2) * (w - 2) - sum(c) print(*c, sep="\n")
false
13.333333
[ "-from collections import Counter", "-", "-h, w, n = list(map(int, input().split()))", "-d = Counter()", "-for _ in range(n):", "- a, b = list(map(int, input().split()))", "- for i in range(3):", "- for j in range(3):", "- if w > b + j - 1 > 1 < a + i - 1 < h:", "- d[(a + i, b + j)] += 1", "-ans = Counter()", "-for i in list(d.values()):", "- ans[i] += 1", "-print(((h - 2) * (w - 2) - sum(ans.values())))", "-for i in range(1, 10):", "- print((ans[i]))", "+i = lambda: map(int, input().split())", "+h, w, n = i()", "+r = [0, 1, 2]", "+d = {}", "+while n:", "+ a, b = i()", "+ n -= 1", "+ for j in r:", "+ for k in r:", "+ if w >= b + k > 2 < a + j <= h:", "+ d[(a + j, b + k)] = d.get((a + j, b + k), 0) + 1", "+c = [0] * 10", "+for i in d:", "+ c[d[i]] += 1", "+c[0] = (h - 2) * (w - 2) - sum(c)", "+print(*c, sep=\"\\n\")" ]
false
0.045648
0.048914
0.93323
[ "s656102705", "s510072747" ]
u625963200
p03160
python
s962666156
s402504682
199
182
13,928
13,980
Accepted
Accepted
8.54
n=int(eval(input())) K=list(map(int,input().split())) dp=[float('inf') for _ in range(n)] dp[0]=0 for i in range(len(K)-1): dp[i+1]=min(dp[i+1],dp[i]+abs(K[i]-K[i+1])) if i+2<len(K): dp[i+2]=min(dp[i+2],dp[i]+abs(K[i]-K[i+2])) print((dp[-1]))
n=int(eval(input())) H=list(map(int,input().split())) dp=[float('inf')]*n dp[0]=0 dp[1]=abs(H[1]-H[0]) for i in range(2,n): dp[i]=min(dp[i],dp[i-1]+abs(H[i]-H[i-1])) dp[i]=min(dp[i],dp[i-2]+abs(H[i]-H[i-2])) print((dp[-1]))
10
10
252
229
n = int(eval(input())) K = list(map(int, input().split())) dp = [float("inf") for _ in range(n)] dp[0] = 0 for i in range(len(K) - 1): dp[i + 1] = min(dp[i + 1], dp[i] + abs(K[i] - K[i + 1])) if i + 2 < len(K): dp[i + 2] = min(dp[i + 2], dp[i] + abs(K[i] - K[i + 2])) print((dp[-1]))
n = int(eval(input())) H = list(map(int, input().split())) dp = [float("inf")] * n dp[0] = 0 dp[1] = abs(H[1] - H[0]) for i in range(2, n): dp[i] = min(dp[i], dp[i - 1] + abs(H[i] - H[i - 1])) dp[i] = min(dp[i], dp[i - 2] + abs(H[i] - H[i - 2])) print((dp[-1]))
false
0
[ "-K = list(map(int, input().split()))", "-dp = [float(\"inf\") for _ in range(n)]", "+H = list(map(int, input().split()))", "+dp = [float(\"inf\")] * n", "-for i in range(len(K) - 1):", "- dp[i + 1] = min(dp[i + 1], dp[i] + abs(K[i] - K[i + 1]))", "- if i + 2 < len(K):", "- dp[i + 2] = min(dp[i + 2], dp[i] + abs(K[i] - K[i + 2]))", "+dp[1] = abs(H[1] - H[0])", "+for i in range(2, n):", "+ dp[i] = min(dp[i], dp[i - 1] + abs(H[i] - H[i - 1]))", "+ dp[i] = min(dp[i], dp[i - 2] + abs(H[i] - H[i - 2]))" ]
false
0.034713
0.033691
1.030332
[ "s962666156", "s402504682" ]
u761529120
p03806
python
s684772999
s233764344
1,766
1,500
60,012
59,500
Accepted
Accepted
15.06
N , Ma, Mb = list(map(int, input().split())) # 入力値の受け取り方を変える arr=[list(map(int,input().split())) for _ in range(N)] #a = [0] * N #b = [0] * N #c = [0] * N #for i in range(N): # a[i], b[i], c[i] = map(int, input().split()) # TLEになってしまうためinfを5000とかで設定する INF = 5000 # さらに計算量を落とすため10 * N + 1などを定数で設定する → 関係なかったため戻す # 最小値を求める問題なのでinfで初期化 # dp[i][sun_a][sum_b]で考えていく dp = [[[INF for _ in range(10 * N + 1)] for _ in range(10 * N + 1)] for _ in range(N+1)] # 初期選択状態を0とする dp[0][0][0] = 0 for i in range(N): a,b,c=arr[i] for j in range(10*N+1): for k in range(10*N+1): if dp[i][j][k] == INF: continue # 選ばなかった場合 dp[i+1][j][k] = min(dp[i+1][j][k], dp[i][j][k]) # 選んだ場合 dp[i+1][j+a][k+b] = min(dp[i+1][j+a][k+b], dp[i][j][k] + c) ans = INF # 0スタートは何を選んでいない状態となり最小値が0になってしまうため1から開始する # TLEになったため変更 #for i in range(1,10 * N + 1): # for j in range(1,10 * N + 1): # if i * Mb != j * Ma: # continue # ans = min(ans, dp[N][i][j]) # for i in range(1, 10*N+1): if i*Ma>10*N or i*Mb>10*N: break ans = min(ans, dp[N][i*Ma][i*Mb]) if ans == INF: print((-1)) else: print(ans)
N , Ma, Mb = list(map(int, input().split())) # 入力値の受け取り方を変える arr=[list(map(int,input().split())) for _ in range(N)] #a = [0] * N #b = [0] * N #c = [0] * N #for i in range(N): # a[i], b[i], c[i] = map(int, input().split()) # TLEになってしまうためinfを5000とかで設定する INF = 5000 # さらに計算量を落とすため10 * N + 1などを定数で設定する → 関係なかったため戻す # 最小値を求める問題なのでinfで初期化 # dp[i][sun_a][sum_b]で考えていく dp = [[[INF] * (10 * N + 1) for _ in range(10 * N + 1)] for _ in range(N+1)] # 初期選択状態を0とする dp[0][0][0] = 0 for i in range(N): a,b,c=arr[i] for j in range(10*N+1): for k in range(10*N+1): if dp[i][j][k] == INF: continue # 選ばなかった場合 dp[i+1][j][k] = min(dp[i+1][j][k], dp[i][j][k]) # 選んだ場合 dp[i+1][j+a][k+b] = min(dp[i+1][j+a][k+b], dp[i][j][k] + c) ans = INF # 0スタートは何を選んでいない状態となり最小値が0になってしまうため1から開始する # TLEになったため変更 #for i in range(1,10 * N + 1): # for j in range(1,10 * N + 1): # if i * Mb != j * Ma: # continue # ans = min(ans, dp[N][i][j]) # for i in range(1, 10*N+1): if i*Ma>10*N or i*Mb>10*N: break ans = min(ans, dp[N][i*Ma][i*Mb]) if ans == INF: print((-1)) else: print(ans)
59
59
1,289
1,277
N, Ma, Mb = list(map(int, input().split())) # 入力値の受け取り方を変える arr = [list(map(int, input().split())) for _ in range(N)] # a = [0] * N # b = [0] * N # c = [0] * N # for i in range(N): # a[i], b[i], c[i] = map(int, input().split()) # TLEになってしまうためinfを5000とかで設定する INF = 5000 # さらに計算量を落とすため10 * N + 1などを定数で設定する → 関係なかったため戻す # 最小値を求める問題なのでinfで初期化 # dp[i][sun_a][sum_b]で考えていく dp = [ [[INF for _ in range(10 * N + 1)] for _ in range(10 * N + 1)] for _ in range(N + 1) ] # 初期選択状態を0とする dp[0][0][0] = 0 for i in range(N): a, b, c = arr[i] for j in range(10 * N + 1): for k in range(10 * N + 1): if dp[i][j][k] == INF: continue # 選ばなかった場合 dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j][k]) # 選んだ場合 dp[i + 1][j + a][k + b] = min(dp[i + 1][j + a][k + b], dp[i][j][k] + c) ans = INF # 0スタートは何を選んでいない状態となり最小値が0になってしまうため1から開始する # TLEになったため変更 # for i in range(1,10 * N + 1): # for j in range(1,10 * N + 1): # if i * Mb != j * Ma: # continue # ans = min(ans, dp[N][i][j]) # for i in range(1, 10 * N + 1): if i * Ma > 10 * N or i * Mb > 10 * N: break ans = min(ans, dp[N][i * Ma][i * Mb]) if ans == INF: print((-1)) else: print(ans)
N, Ma, Mb = list(map(int, input().split())) # 入力値の受け取り方を変える arr = [list(map(int, input().split())) for _ in range(N)] # a = [0] * N # b = [0] * N # c = [0] * N # for i in range(N): # a[i], b[i], c[i] = map(int, input().split()) # TLEになってしまうためinfを5000とかで設定する INF = 5000 # さらに計算量を落とすため10 * N + 1などを定数で設定する → 関係なかったため戻す # 最小値を求める問題なのでinfで初期化 # dp[i][sun_a][sum_b]で考えていく dp = [[[INF] * (10 * N + 1) for _ in range(10 * N + 1)] for _ in range(N + 1)] # 初期選択状態を0とする dp[0][0][0] = 0 for i in range(N): a, b, c = arr[i] for j in range(10 * N + 1): for k in range(10 * N + 1): if dp[i][j][k] == INF: continue # 選ばなかった場合 dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j][k]) # 選んだ場合 dp[i + 1][j + a][k + b] = min(dp[i + 1][j + a][k + b], dp[i][j][k] + c) ans = INF # 0スタートは何を選んでいない状態となり最小値が0になってしまうため1から開始する # TLEになったため変更 # for i in range(1,10 * N + 1): # for j in range(1,10 * N + 1): # if i * Mb != j * Ma: # continue # ans = min(ans, dp[N][i][j]) # for i in range(1, 10 * N + 1): if i * Ma > 10 * N or i * Mb > 10 * N: break ans = min(ans, dp[N][i * Ma][i * Mb]) if ans == INF: print((-1)) else: print(ans)
false
0
[ "-dp = [", "- [[INF for _ in range(10 * N + 1)] for _ in range(10 * N + 1)] for _ in range(N + 1)", "-]", "+dp = [[[INF] * (10 * N + 1) for _ in range(10 * N + 1)] for _ in range(N + 1)]" ]
false
0.007128
0.07124
0.100059
[ "s684772999", "s233764344" ]
u312695001
p02695
python
s016781757
s202125432
1,082
691
21,608
21,480
Accepted
Accepted
36.14
import itertools N, M, Q = list(map(int, input().split())) a = [] b = [] c = [] d = [] for i in range(Q): ai, bi, ci, di = list(map(int, input().split())) a.append(ai) b.append(bi) c.append(ci) d.append(di) ans = 0 for A in list(itertools.combinations_with_replacement(list(range(1, M+1)), N)): # print(A) score = 0 for i in range(Q): if A[b[i]-1] - A[a[i]-1] == c[i]: score += d[i] if ans < score: ans = score # print(A, score) print(ans)
import itertools def main(): N, M, Q = list(map(int, input().split())) a = [] b = [] c = [] d = [] for i in range(Q): ai, bi, ci, di = list(map(int, input().split())) a.append(ai) b.append(bi) c.append(ci) d.append(di) ans = 0 for A in list(itertools.combinations_with_replacement(list(range(1, M+1)), N)): # print(A) score = 0 for i in range(Q): if A[b[i]-1] - A[a[i]-1] == c[i]: score += d[i] if ans < score: ans = score print(ans) if __name__ == "__main__": main()
27
30
703
733
import itertools N, M, Q = list(map(int, input().split())) a = [] b = [] c = [] d = [] for i in range(Q): ai, bi, ci, di = list(map(int, input().split())) a.append(ai) b.append(bi) c.append(ci) d.append(di) ans = 0 for A in list(itertools.combinations_with_replacement(list(range(1, M + 1)), N)): # print(A) score = 0 for i in range(Q): if A[b[i] - 1] - A[a[i] - 1] == c[i]: score += d[i] if ans < score: ans = score # print(A, score) print(ans)
import itertools def main(): N, M, Q = list(map(int, input().split())) a = [] b = [] c = [] d = [] for i in range(Q): ai, bi, ci, di = list(map(int, input().split())) a.append(ai) b.append(bi) c.append(ci) d.append(di) ans = 0 for A in list(itertools.combinations_with_replacement(list(range(1, M + 1)), N)): # print(A) score = 0 for i in range(Q): if A[b[i] - 1] - A[a[i] - 1] == c[i]: score += d[i] if ans < score: ans = score print(ans) if __name__ == "__main__": main()
false
10
[ "-N, M, Q = list(map(int, input().split()))", "-a = []", "-b = []", "-c = []", "-d = []", "-for i in range(Q):", "- ai, bi, ci, di = list(map(int, input().split()))", "- a.append(ai)", "- b.append(bi)", "- c.append(ci)", "- d.append(di)", "-ans = 0", "-for A in list(itertools.combinations_with_replacement(list(range(1, M + 1)), N)):", "- # print(A)", "- score = 0", "+", "+def main():", "+ N, M, Q = list(map(int, input().split()))", "+ a = []", "+ b = []", "+ c = []", "+ d = []", "- if A[b[i] - 1] - A[a[i] - 1] == c[i]:", "- score += d[i]", "- if ans < score:", "- ans = score", "-# print(A, score)", "-print(ans)", "+ ai, bi, ci, di = list(map(int, input().split()))", "+ a.append(ai)", "+ b.append(bi)", "+ c.append(ci)", "+ d.append(di)", "+ ans = 0", "+ for A in list(itertools.combinations_with_replacement(list(range(1, M + 1)), N)):", "+ # print(A)", "+ score = 0", "+ for i in range(Q):", "+ if A[b[i] - 1] - A[a[i] - 1] == c[i]:", "+ score += d[i]", "+ if ans < score:", "+ ans = score", "+ print(ans)", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.125815
0.128339
0.980335
[ "s016781757", "s202125432" ]
u457901067
p02632
python
s175784106
s279018299
1,915
748
11,060
76,288
Accepted
Accepted
60.94
K = int(eval(input())) S = eval(input()) N = len(S) mod = int(1e9+7) ### 123 ### a1bb2ccc3dddd 10文字インサート # pow(25,6) * pow(26,4) * 8C2 # (3はfixで、それより前の8mojiから1/2を入れる場所を決める) # これを3の位置でループする(1-indexで 3<=i<=N) # 123dddddddddd # pow(25,0) * pow(26,10) * 2C2(1) # 12x3ddddddddd # pow(25,1) * pow(26,9) * 3C2( = 2C2 * 3 / 1) # 12xx3dddddddd # pow(25,2) * pow(26,8) * 4C2( = 3C2 * 4 / 2) # ... # 12xxxxxxxxxx3 # pow(25,10) * pow(26,0) * 12C2( = 11C2 * 12 / 10) # 5C5, 6C5, 7C5 1, 6, 21, 56 wk = pow(26,K,mod) inv26 = pow(26,-1,mod) ans = wk for i in range(1,K+1): wk = (wk * 25 * inv26) % mod wk = (wk * (N-1+i) * pow(i,-1,mod) % mod) ans = (ans + wk)%mod print(ans)
K = int(eval(input())) S = eval(input()) N = len(S) mod = int(1e9+7) ### 123 ### a1bb2ccc3dddd 10文字インサート # pow(25,6) * pow(26,4) * 8C2 # (3はfixで、それより前の8mojiから1/2を入れる場所を決める) # これを3の位置でループする(1-indexで 3<=i<=N) # 123dddddddddd # pow(25,0) * pow(26,10) * 2C2(1) # 12x3ddddddddd # pow(25,1) * pow(26,9) * 3C2( = 2C2 * 3 / 1) # 12xx3dddddddd # pow(25,2) * pow(26,8) * 4C2( = 3C2 * 4 / 2) # ... # 12xxxxxxxxxx3 # pow(25,10) * pow(26,0) * 12C2( = 11C2 * 12 / 10) # 5C5, 6C5, 7C5 1, 6, 21, 56 def powinv(x,mod): return pow1(x,mod-2,mod) def pow1(x, n, mod): ans = 1 while n>0: if n % 2: ans *= x ans %= mod x *= x x %= mod n = n // 2 # n >>= 1 return ans wk = pow(26,K,mod) inv26 = powinv(26,mod) ans = wk for i in range(1,K+1): wk = (wk * 25 * inv26) % mod wk = (wk * (N-1+i) * powinv(i,mod) % mod) ans = (ans + wk)%mod print(ans)
33
46
696
910
K = int(eval(input())) S = eval(input()) N = len(S) mod = int(1e9 + 7) ### 123 ### a1bb2ccc3dddd 10文字インサート # pow(25,6) * pow(26,4) * 8C2 # (3はfixで、それより前の8mojiから1/2を入れる場所を決める) # これを3の位置でループする(1-indexで 3<=i<=N) # 123dddddddddd # pow(25,0) * pow(26,10) * 2C2(1) # 12x3ddddddddd # pow(25,1) * pow(26,9) * 3C2( = 2C2 * 3 / 1) # 12xx3dddddddd # pow(25,2) * pow(26,8) * 4C2( = 3C2 * 4 / 2) # ... # 12xxxxxxxxxx3 # pow(25,10) * pow(26,0) * 12C2( = 11C2 * 12 / 10) # 5C5, 6C5, 7C5 1, 6, 21, 56 wk = pow(26, K, mod) inv26 = pow(26, -1, mod) ans = wk for i in range(1, K + 1): wk = (wk * 25 * inv26) % mod wk = wk * (N - 1 + i) * pow(i, -1, mod) % mod ans = (ans + wk) % mod print(ans)
K = int(eval(input())) S = eval(input()) N = len(S) mod = int(1e9 + 7) ### 123 ### a1bb2ccc3dddd 10文字インサート # pow(25,6) * pow(26,4) * 8C2 # (3はfixで、それより前の8mojiから1/2を入れる場所を決める) # これを3の位置でループする(1-indexで 3<=i<=N) # 123dddddddddd # pow(25,0) * pow(26,10) * 2C2(1) # 12x3ddddddddd # pow(25,1) * pow(26,9) * 3C2( = 2C2 * 3 / 1) # 12xx3dddddddd # pow(25,2) * pow(26,8) * 4C2( = 3C2 * 4 / 2) # ... # 12xxxxxxxxxx3 # pow(25,10) * pow(26,0) * 12C2( = 11C2 * 12 / 10) # 5C5, 6C5, 7C5 1, 6, 21, 56 def powinv(x, mod): return pow1(x, mod - 2, mod) def pow1(x, n, mod): ans = 1 while n > 0: if n % 2: ans *= x ans %= mod x *= x x %= mod n = n // 2 # n >>= 1 return ans wk = pow(26, K, mod) inv26 = powinv(26, mod) ans = wk for i in range(1, K + 1): wk = (wk * 25 * inv26) % mod wk = wk * (N - 1 + i) * powinv(i, mod) % mod ans = (ans + wk) % mod print(ans)
false
28.26087
[ "+def powinv(x, mod):", "+ return pow1(x, mod - 2, mod)", "+", "+", "+def pow1(x, n, mod):", "+ ans = 1", "+ while n > 0:", "+ if n % 2:", "+ ans *= x", "+ ans %= mod", "+ x *= x", "+ x %= mod", "+ n = n // 2 # n >>= 1", "+ return ans", "+", "+", "-inv26 = pow(26, -1, mod)", "+inv26 = powinv(26, mod)", "- wk = wk * (N - 1 + i) * pow(i, -1, mod) % mod", "+ wk = wk * (N - 1 + i) * powinv(i, mod) % mod" ]
false
0.063502
0.060148
1.055764
[ "s175784106", "s279018299" ]
u670180528
p03734
python
s656035287
s771766873
288
254
3,064
3,064
Accepted
Accepted
11.81
from itertools import accumulate n,W,*L=list(map(int,open(0).read().split())) l=[[] for _ in range(4)] lim=[1]*4 m=min(L[::2]) for w,v in zip(*[iter(L)]*2): l[w-m].append(v) lim[w-m]+=1 ll=[] for x in l: ll.append([0]+list(accumulate(sorted(x)[::-1]))) ans=0 for i in range(lim[0]): for j in range(lim[1]): for k in range(lim[2]): for l in range(lim[3]): if m*i+(m+1)*j+(m+2)*k+(m+3)*l>W: continue ans=max(ans,ll[0][i]+ll[1][j]+ll[2][k]+ll[3][l]) print(ans)
from itertools import accumulate n,W,*L=list(map(int,open(0).read().split())) l=[[] for _ in range(4)] lim=[1]*4 m=min(L[::2]) for w,v in zip(*[iter(L)]*2): l[w-m].append(v) lim[w-m]+=1 ll=[] for x in l: ll.append([0]+list(accumulate(sorted(x)[::-1]))) ans=0 for i in range(lim[0]): if m*i>W: continue for j in range(lim[1]): if m*i+(m+1)*j>W: continue for k in range(lim[2]): if m*i+(m+1)*j+(m+2)*k>W: continue for l in range(lim[3]): if m*i+(m+1)*j+(m+2)*k+(m+3)*l>W: continue ans=max(ans,ll[0][i]+ll[1][j]+ll[2][k]+ll[3][l]) print(ans)
20
26
492
594
from itertools import accumulate n, W, *L = list(map(int, open(0).read().split())) l = [[] for _ in range(4)] lim = [1] * 4 m = min(L[::2]) for w, v in zip(*[iter(L)] * 2): l[w - m].append(v) lim[w - m] += 1 ll = [] for x in l: ll.append([0] + list(accumulate(sorted(x)[::-1]))) ans = 0 for i in range(lim[0]): for j in range(lim[1]): for k in range(lim[2]): for l in range(lim[3]): if m * i + (m + 1) * j + (m + 2) * k + (m + 3) * l > W: continue ans = max(ans, ll[0][i] + ll[1][j] + ll[2][k] + ll[3][l]) print(ans)
from itertools import accumulate n, W, *L = list(map(int, open(0).read().split())) l = [[] for _ in range(4)] lim = [1] * 4 m = min(L[::2]) for w, v in zip(*[iter(L)] * 2): l[w - m].append(v) lim[w - m] += 1 ll = [] for x in l: ll.append([0] + list(accumulate(sorted(x)[::-1]))) ans = 0 for i in range(lim[0]): if m * i > W: continue for j in range(lim[1]): if m * i + (m + 1) * j > W: continue for k in range(lim[2]): if m * i + (m + 1) * j + (m + 2) * k > W: continue for l in range(lim[3]): if m * i + (m + 1) * j + (m + 2) * k + (m + 3) * l > W: continue ans = max(ans, ll[0][i] + ll[1][j] + ll[2][k] + ll[3][l]) print(ans)
false
23.076923
[ "+ if m * i > W:", "+ continue", "+ if m * i + (m + 1) * j > W:", "+ continue", "+ if m * i + (m + 1) * j + (m + 2) * k > W:", "+ continue" ]
false
0.033449
0.055684
0.600698
[ "s656035287", "s771766873" ]
u651803486
p02994
python
s130884181
s962959738
29
17
3,444
2,940
Accepted
Accepted
41.38
import copy N, L = list(map(int, input().split())) apple_taste = [L+i for i in range(N)] pie_taste = sum(apple_taste) min_diff = 100000 for i in range(N): ap = copy.deepcopy(apple_taste) ap[i] = 0 pie_taste2 = sum(ap) diff = abs(pie_taste - pie_taste2) if diff < min_diff: min_diff = diff min_index = i apple_taste[min_index] = 0 print((sum(apple_taste)))
N, L = list(map(int, input().split())) pie = 0 min_abs = 10000 min_abs_apple = None for i in range(N): if min_abs > abs(i + L): min_abs = abs(i + L) min_abs_apple = i + L pie += i + L print((pie - min_abs_apple))
24
12
415
241
import copy N, L = list(map(int, input().split())) apple_taste = [L + i for i in range(N)] pie_taste = sum(apple_taste) min_diff = 100000 for i in range(N): ap = copy.deepcopy(apple_taste) ap[i] = 0 pie_taste2 = sum(ap) diff = abs(pie_taste - pie_taste2) if diff < min_diff: min_diff = diff min_index = i apple_taste[min_index] = 0 print((sum(apple_taste)))
N, L = list(map(int, input().split())) pie = 0 min_abs = 10000 min_abs_apple = None for i in range(N): if min_abs > abs(i + L): min_abs = abs(i + L) min_abs_apple = i + L pie += i + L print((pie - min_abs_apple))
false
50
[ "-import copy", "-", "-apple_taste = [L + i for i in range(N)]", "-pie_taste = sum(apple_taste)", "-min_diff = 100000", "+pie = 0", "+min_abs = 10000", "+min_abs_apple = None", "- ap = copy.deepcopy(apple_taste)", "- ap[i] = 0", "- pie_taste2 = sum(ap)", "- diff = abs(pie_taste - pie_taste2)", "- if diff < min_diff:", "- min_diff = diff", "- min_index = i", "-apple_taste[min_index] = 0", "-print((sum(apple_taste)))", "+ if min_abs > abs(i + L):", "+ min_abs = abs(i + L)", "+ min_abs_apple = i + L", "+ pie += i + L", "+print((pie - min_abs_apple))" ]
false
0.038862
0.036706
1.058743
[ "s130884181", "s962959738" ]
u150984829
p02279
python
s179543714
s055111824
1,080
860
55,844
55,920
Accepted
Accepted
20.37
def q(a,h): d[a]=str(h) for b in t[a]:q(b,h+1) t,p,d={},{},{} for _ in[0]*int(eval(input())): e=input().split() t[e[0]]=e[2:] for i in e[2:]:p[i]=e[0] r=(set(t)-set(p)).pop() p[r]='-1' q(r,0) for i in sorted(map(int,t)):i=str(i);print(('node',i+':','parent =',p[i]+',','depth =',d[i]+',','root,'if'-1'==p[i]else'internal node,'if t[i]else'leaf,',list(map(int,t[i]))))
def q(a,h): d[a]=str(h) for b in t[a]:q(b,h+1) t,p,d={},{},{} for _ in[0]*int(eval(input())): e=input().split() t[e[0]]=e[2:] for i in e[2:]:p[i]=e[0] r=(set(t)-set(p)).pop() p[r]='-1' q(r,0) for i in sorted(map(int,t)): i=str(i) f='root'if'-1'==p[i]else'internal node'if t[i]else'leaf' print(f'node {i}: parent = {p[i]}, depth = {d[i]}, {f}, {list(map(int,t[i]))}')
12
15
376
383
def q(a, h): d[a] = str(h) for b in t[a]: q(b, h + 1) t, p, d = {}, {}, {} for _ in [0] * int(eval(input())): e = input().split() t[e[0]] = e[2:] for i in e[2:]: p[i] = e[0] r = (set(t) - set(p)).pop() p[r] = "-1" q(r, 0) for i in sorted(map(int, t)): i = str(i) print( ( "node", i + ":", "parent =", p[i] + ",", "depth =", d[i] + ",", "root," if "-1" == p[i] else "internal node," if t[i] else "leaf,", list(map(int, t[i])), ) )
def q(a, h): d[a] = str(h) for b in t[a]: q(b, h + 1) t, p, d = {}, {}, {} for _ in [0] * int(eval(input())): e = input().split() t[e[0]] = e[2:] for i in e[2:]: p[i] = e[0] r = (set(t) - set(p)).pop() p[r] = "-1" q(r, 0) for i in sorted(map(int, t)): i = str(i) f = "root" if "-1" == p[i] else "internal node" if t[i] else "leaf" print(f"node {i}: parent = {p[i]}, depth = {d[i]}, {f}, {list(map(int,t[i]))}")
false
20
[ "- print(", "- (", "- \"node\",", "- i + \":\",", "- \"parent =\",", "- p[i] + \",\",", "- \"depth =\",", "- d[i] + \",\",", "- \"root,\" if \"-1\" == p[i] else \"internal node,\" if t[i] else \"leaf,\",", "- list(map(int, t[i])),", "- )", "- )", "+ f = \"root\" if \"-1\" == p[i] else \"internal node\" if t[i] else \"leaf\"", "+ print(f\"node {i}: parent = {p[i]}, depth = {d[i]}, {f}, {list(map(int,t[i]))}\")" ]
false
0.037081
0.047038
0.788332
[ "s179543714", "s055111824" ]
u670180528
p03608
python
s207184837
s159432829
593
504
72,408
22,224
Accepted
Accepted
15.01
from itertools import* n,m,o=list(map(int,input().split())) *R,=list(map(int,input().split())) INF=float("inf") d=[[INF]*n for _ in range(n)] r=range for i in r(n): d[i][i]=0 for _ in r(m): a,b,c=list(map(int,input().split())) d[a-1][b-1]=d[b-1][a-1]=c for k in r(n): for i in r(n): for j in r(n): d[i][j]=min(d[i][j],d[i][k]+d[k][j]) v=[[d[i-1][j-1]for j in R]for i in R] m=INF for t in permutations(r(o)): a=0;f=1 for i,j in zip(t,t[1:]): if v[i][j]==INF: f=0 break else: a+=v[i][j] if f: m=min(m,a) print(m)
from scipy.sparse import csr_matrix from scipy.sparse.csgraph import floyd_warshall from itertools import permutations n,m,r,*L=list(map(int,open(0).read().split())) f=floyd_warshall(csr_matrix((L[r+2::3],(L[r::3],L[r+1::3])),(n+1,n+1)),0) print((int(min(sum(f[s,t]for s,t in zip(o,o[1:]))for o in permutations(L[:r])))))
29
6
548
318
from itertools import * n, m, o = list(map(int, input().split())) (*R,) = list(map(int, input().split())) INF = float("inf") d = [[INF] * n for _ in range(n)] r = range for i in r(n): d[i][i] = 0 for _ in r(m): a, b, c = list(map(int, input().split())) d[a - 1][b - 1] = d[b - 1][a - 1] = c for k in r(n): for i in r(n): for j in r(n): d[i][j] = min(d[i][j], d[i][k] + d[k][j]) v = [[d[i - 1][j - 1] for j in R] for i in R] m = INF for t in permutations(r(o)): a = 0 f = 1 for i, j in zip(t, t[1:]): if v[i][j] == INF: f = 0 break else: a += v[i][j] if f: m = min(m, a) print(m)
from scipy.sparse import csr_matrix from scipy.sparse.csgraph import floyd_warshall from itertools import permutations n, m, r, *L = list(map(int, open(0).read().split())) f = floyd_warshall( csr_matrix((L[r + 2 :: 3], (L[r::3], L[r + 1 :: 3])), (n + 1, n + 1)), 0 ) print((int(min(sum(f[s, t] for s, t in zip(o, o[1:])) for o in permutations(L[:r])))))
false
79.310345
[ "-from itertools import *", "+from scipy.sparse import csr_matrix", "+from scipy.sparse.csgraph import floyd_warshall", "+from itertools import permutations", "-n, m, o = list(map(int, input().split()))", "-(*R,) = list(map(int, input().split()))", "-INF = float(\"inf\")", "-d = [[INF] * n for _ in range(n)]", "-r = range", "-for i in r(n):", "- d[i][i] = 0", "-for _ in r(m):", "- a, b, c = list(map(int, input().split()))", "- d[a - 1][b - 1] = d[b - 1][a - 1] = c", "-for k in r(n):", "- for i in r(n):", "- for j in r(n):", "- d[i][j] = min(d[i][j], d[i][k] + d[k][j])", "-v = [[d[i - 1][j - 1] for j in R] for i in R]", "-m = INF", "-for t in permutations(r(o)):", "- a = 0", "- f = 1", "- for i, j in zip(t, t[1:]):", "- if v[i][j] == INF:", "- f = 0", "- break", "- else:", "- a += v[i][j]", "- if f:", "- m = min(m, a)", "-print(m)", "+n, m, r, *L = list(map(int, open(0).read().split()))", "+f = floyd_warshall(", "+ csr_matrix((L[r + 2 :: 3], (L[r::3], L[r + 1 :: 3])), (n + 1, n + 1)), 0", "+)", "+print((int(min(sum(f[s, t] for s, t in zip(o, o[1:])) for o in permutations(L[:r])))))" ]
false
0.135332
0.326328
0.41471
[ "s207184837", "s159432829" ]
u761989513
p03831
python
s850253038
s865581352
94
83
14,252
14,252
Accepted
Accepted
11.7
n, a, b = list(map(int, input().split())) x = list(map(int, input().split())) ans = 0 for i in range(n - 1): ans += min((x[i + 1] - x[i]) * a, b) print(ans)
n, a, b = list(map(int, input().split())) x = list(map(int, input().split())) ans = 0 last = x[0] for i in x: ans += min((i - last) * a, b) last = i print(ans)
6
10
159
172
n, a, b = list(map(int, input().split())) x = list(map(int, input().split())) ans = 0 for i in range(n - 1): ans += min((x[i + 1] - x[i]) * a, b) print(ans)
n, a, b = list(map(int, input().split())) x = list(map(int, input().split())) ans = 0 last = x[0] for i in x: ans += min((i - last) * a, b) last = i print(ans)
false
40
[ "-for i in range(n - 1):", "- ans += min((x[i + 1] - x[i]) * a, b)", "+last = x[0]", "+for i in x:", "+ ans += min((i - last) * a, b)", "+ last = i" ]
false
0.071925
0.04169
1.72525
[ "s850253038", "s865581352" ]
u926412290
p02598
python
s375190410
s054602060
1,600
791
30,984
30,848
Accepted
Accepted
50.56
N, K = list(map(int, input().split())) A = list(map(int, input().split())) l = 0 r = max(A) for _ in range(30): mid = (r + l + 1) // 2 count = 0 for log in A: if log > mid: count += (log + mid - 1) // mid - 1 if count <= K: r = mid else: l = mid print(r)
N, K = list(map(int, input().split())) A = list(map(int, input().split())) l = 1 r = max(A) while l != r: mid = (r + l) // 2 count = 0 for log in A: count += (log - 1) // mid if count <= K: r = mid else: l = mid + 1 print(r)
17
16
323
280
N, K = list(map(int, input().split())) A = list(map(int, input().split())) l = 0 r = max(A) for _ in range(30): mid = (r + l + 1) // 2 count = 0 for log in A: if log > mid: count += (log + mid - 1) // mid - 1 if count <= K: r = mid else: l = mid print(r)
N, K = list(map(int, input().split())) A = list(map(int, input().split())) l = 1 r = max(A) while l != r: mid = (r + l) // 2 count = 0 for log in A: count += (log - 1) // mid if count <= K: r = mid else: l = mid + 1 print(r)
false
5.882353
[ "-l = 0", "+l = 1", "-for _ in range(30):", "- mid = (r + l + 1) // 2", "+while l != r:", "+ mid = (r + l) // 2", "- if log > mid:", "- count += (log + mid - 1) // mid - 1", "+ count += (log - 1) // mid", "- l = mid", "+ l = mid + 1" ]
false
0.040389
0.008103
4.98434
[ "s375190410", "s054602060" ]
u189479417
p02612
python
s241275681
s815772085
32
29
9,148
9,128
Accepted
Accepted
9.38
N = int(eval(input())) ans = (1000 - N % 1000) % 1000 print(ans)
N = int(eval(input())) k = 0 while k * 1000 < N: k += 1 ans = k * 1000 - N print(ans)
3
8
60
92
N = int(eval(input())) ans = (1000 - N % 1000) % 1000 print(ans)
N = int(eval(input())) k = 0 while k * 1000 < N: k += 1 ans = k * 1000 - N print(ans)
false
62.5
[ "-ans = (1000 - N % 1000) % 1000", "+k = 0", "+while k * 1000 < N:", "+ k += 1", "+ans = k * 1000 - N" ]
false
0.103784
0.037641
2.757186
[ "s241275681", "s815772085" ]
u790710233
p03715
python
s796259182
s173644707
30
27
9,196
9,220
Accepted
Accepted
10
h, w = list(map(int, input().split())) # =パターン x, y = divmod(h, 3) if y == 0: x1, x2, x3 = x, x, x elif y == 1: x1, x2, x3 = x+1, x, x else: x1, x2, x3 = x+1, x+1, x s1, s2, s3 = [x*w for x in (x1, x2, x3)] ans = s1-s3 # llパターン x, y = divmod(w, 3) if y == 0: x1, x2, x3 = x, x, x elif y == 1: x1, x2, x3 = x+1, x, x else: x1, x2, x3 = x+1, x+1, x s1, s2, s3 = [x*h for x in (x1, x2, x3)] ans = min(ans, s1-s3) # トパターン x = -(-w//3) s1 = x*h y = w-x x1, x2 = h//2, (h+1)//2 s2, s3 = x1*y, x2*y Ss = (s1, s2, s3) ans = min(ans, max(Ss)-min(Ss)) # トパターン x = w//3 s1 = x*h y = w-x x1, x2 = h//2, (h+1)//2 s2, s3 = x1*y, x2*y Ss = (s1, s2, s3) ans = min(ans, max(Ss)-min(Ss)) # Tパターン x = -(-h//3) s1 = x*w y = h-x x1, x2 = w//2, (w+1)//2 s2, s3 = x1*y, x2*y Ss = (s1, s2, s3) ans = min(ans, max(Ss)-min(Ss)) # Tパターン x = h//3 s1 = x*w y = h-x x1, x2 = w//2, (w+1)//2 s2, s3 = x1*y, x2*y Ss = (s1, s2, s3) ans = min(ans, max(Ss)-min(Ss)) print(ans)
h, w = list(map(int, input().split())) def solve_ll(a, b): x, y = divmod(a, 3) X = [x]*3 for i in range(y): X[i] += 1 s1, s2, s3 = [x*b for x in X] return s1-s3 def solve_T(a, b): INF = 10**18 res = INF for x in (b//3, -(-b//3)): s1 = x*a y = b-x x1, x2 = a//2, (a+1)//2 s2, s3 = x1*y, x2*y Ss = (s1, s2, s3) res = min(res, max(Ss)-min(Ss)) return res ans = min(solve_T(h, w), solve_T(w, h), solve_ll(h, w), solve_ll(w, h)) print(ans)
62
27
1,038
558
h, w = list(map(int, input().split())) # =パターン x, y = divmod(h, 3) if y == 0: x1, x2, x3 = x, x, x elif y == 1: x1, x2, x3 = x + 1, x, x else: x1, x2, x3 = x + 1, x + 1, x s1, s2, s3 = [x * w for x in (x1, x2, x3)] ans = s1 - s3 # llパターン x, y = divmod(w, 3) if y == 0: x1, x2, x3 = x, x, x elif y == 1: x1, x2, x3 = x + 1, x, x else: x1, x2, x3 = x + 1, x + 1, x s1, s2, s3 = [x * h for x in (x1, x2, x3)] ans = min(ans, s1 - s3) # トパターン x = -(-w // 3) s1 = x * h y = w - x x1, x2 = h // 2, (h + 1) // 2 s2, s3 = x1 * y, x2 * y Ss = (s1, s2, s3) ans = min(ans, max(Ss) - min(Ss)) # トパターン x = w // 3 s1 = x * h y = w - x x1, x2 = h // 2, (h + 1) // 2 s2, s3 = x1 * y, x2 * y Ss = (s1, s2, s3) ans = min(ans, max(Ss) - min(Ss)) # Tパターン x = -(-h // 3) s1 = x * w y = h - x x1, x2 = w // 2, (w + 1) // 2 s2, s3 = x1 * y, x2 * y Ss = (s1, s2, s3) ans = min(ans, max(Ss) - min(Ss)) # Tパターン x = h // 3 s1 = x * w y = h - x x1, x2 = w // 2, (w + 1) // 2 s2, s3 = x1 * y, x2 * y Ss = (s1, s2, s3) ans = min(ans, max(Ss) - min(Ss)) print(ans)
h, w = list(map(int, input().split())) def solve_ll(a, b): x, y = divmod(a, 3) X = [x] * 3 for i in range(y): X[i] += 1 s1, s2, s3 = [x * b for x in X] return s1 - s3 def solve_T(a, b): INF = 10**18 res = INF for x in (b // 3, -(-b // 3)): s1 = x * a y = b - x x1, x2 = a // 2, (a + 1) // 2 s2, s3 = x1 * y, x2 * y Ss = (s1, s2, s3) res = min(res, max(Ss) - min(Ss)) return res ans = min(solve_T(h, w), solve_T(w, h), solve_ll(h, w), solve_ll(w, h)) print(ans)
false
56.451613
[ "-# =パターン", "-x, y = divmod(h, 3)", "-if y == 0:", "- x1, x2, x3 = x, x, x", "-elif y == 1:", "- x1, x2, x3 = x + 1, x, x", "-else:", "- x1, x2, x3 = x + 1, x + 1, x", "-s1, s2, s3 = [x * w for x in (x1, x2, x3)]", "-ans = s1 - s3", "-# llパターン", "-x, y = divmod(w, 3)", "-if y == 0:", "- x1, x2, x3 = x, x, x", "-elif y == 1:", "- x1, x2, x3 = x + 1, x, x", "-else:", "- x1, x2, x3 = x + 1, x + 1, x", "-s1, s2, s3 = [x * h for x in (x1, x2, x3)]", "-ans = min(ans, s1 - s3)", "-# トパターン", "-x = -(-w // 3)", "-s1 = x * h", "-y = w - x", "-x1, x2 = h // 2, (h + 1) // 2", "-s2, s3 = x1 * y, x2 * y", "-Ss = (s1, s2, s3)", "-ans = min(ans, max(Ss) - min(Ss))", "-# トパターン", "-x = w // 3", "-s1 = x * h", "-y = w - x", "-x1, x2 = h // 2, (h + 1) // 2", "-s2, s3 = x1 * y, x2 * y", "-Ss = (s1, s2, s3)", "-ans = min(ans, max(Ss) - min(Ss))", "-# Tパターン", "-x = -(-h // 3)", "-s1 = x * w", "-y = h - x", "-x1, x2 = w // 2, (w + 1) // 2", "-s2, s3 = x1 * y, x2 * y", "-Ss = (s1, s2, s3)", "-ans = min(ans, max(Ss) - min(Ss))", "-# Tパターン", "-x = h // 3", "-s1 = x * w", "-y = h - x", "-x1, x2 = w // 2, (w + 1) // 2", "-s2, s3 = x1 * y, x2 * y", "-Ss = (s1, s2, s3)", "-ans = min(ans, max(Ss) - min(Ss))", "+", "+", "+def solve_ll(a, b):", "+ x, y = divmod(a, 3)", "+ X = [x] * 3", "+ for i in range(y):", "+ X[i] += 1", "+ s1, s2, s3 = [x * b for x in X]", "+ return s1 - s3", "+", "+", "+def solve_T(a, b):", "+ INF = 10**18", "+ res = INF", "+ for x in (b // 3, -(-b // 3)):", "+ s1 = x * a", "+ y = b - x", "+ x1, x2 = a // 2, (a + 1) // 2", "+ s2, s3 = x1 * y, x2 * y", "+ Ss = (s1, s2, s3)", "+ res = min(res, max(Ss) - min(Ss))", "+ return res", "+", "+", "+ans = min(solve_T(h, w), solve_T(w, h), solve_ll(h, w), solve_ll(w, h))" ]
false
0.045945
0.047569
0.965866
[ "s796259182", "s173644707" ]
u094999522
p02780
python
s905514413
s703981089
144
131
32,464
118,652
Accepted
Accepted
9.03
#!/usr/bin/env python3 n, k, *P = list(map(int, open(0).read().split())) p = [(i + 1) / 2 for i in P] c = sum(p[:k]) ans = c for i in range(n - k): c = c + p[i + k] - p[i] ans = max(c, ans) print(ans)
#!/usr/bin/env python3 n, k, *P = list(map(int, open(0).read().split())) p = [(i + 1) / 2 for i in P] s = [float()] for i in range(n): s.append(s[i] + p[i]) print((max(s[i + k] - s[i] for i in range(n - k + 1))))
9
7
211
215
#!/usr/bin/env python3 n, k, *P = list(map(int, open(0).read().split())) p = [(i + 1) / 2 for i in P] c = sum(p[:k]) ans = c for i in range(n - k): c = c + p[i + k] - p[i] ans = max(c, ans) print(ans)
#!/usr/bin/env python3 n, k, *P = list(map(int, open(0).read().split())) p = [(i + 1) / 2 for i in P] s = [float()] for i in range(n): s.append(s[i] + p[i]) print((max(s[i + k] - s[i] for i in range(n - k + 1))))
false
22.222222
[ "-c = sum(p[:k])", "-ans = c", "-for i in range(n - k):", "- c = c + p[i + k] - p[i]", "- ans = max(c, ans)", "-print(ans)", "+s = [float()]", "+for i in range(n):", "+ s.append(s[i] + p[i])", "+print((max(s[i + k] - s[i] for i in range(n - k + 1))))" ]
false
0.047792
0.07036
0.679254
[ "s905514413", "s703981089" ]
u661435580
p02389
python
s853649286
s723494233
20
0
5,580
4,616
Accepted
Accepted
100
a,b = list(map(int,input().split())) print((a*b,2*(a+b)))
a, b = list(map(int, input().split())) print(a*b , 2*(a+b))
2
2
51
58
a, b = list(map(int, input().split())) print((a * b, 2 * (a + b)))
a, b = list(map(int, input().split())) print(a * b, 2 * (a + b))
false
0
[ "-print((a * b, 2 * (a + b)))", "+print(a * b, 2 * (a + b))" ]
false
0.048521
0.049227
0.985651
[ "s853649286", "s723494233" ]