user_id
stringlengths
10
10
problem_id
stringlengths
6
6
language
stringclasses
1 value
submission_id_v0
stringlengths
10
10
submission_id_v1
stringlengths
10
10
cpu_time_v0
int64
10
38.3k
cpu_time_v1
int64
0
24.7k
memory_v0
int64
2.57k
1.02M
memory_v1
int64
2.57k
869k
status_v0
stringclasses
1 value
status_v1
stringclasses
1 value
improvement_frac
float64
7.51
100
input
stringlengths
20
4.55k
target
stringlengths
17
3.34k
code_v0_loc
int64
1
148
code_v1_loc
int64
1
184
code_v0_num_chars
int64
13
4.55k
code_v1_num_chars
int64
14
3.34k
code_v0_no_empty_lines
stringlengths
21
6.88k
code_v1_no_empty_lines
stringlengths
20
4.93k
code_same
bool
1 class
relative_loc_diff_percent
float64
0
79.8
diff
list
diff_only_import_comment
bool
1 class
measured_runtime_v0
float64
0.01
4.45
measured_runtime_v1
float64
0.01
4.31
runtime_lift
float64
0
359
key
list
u966695411
p03835
python
s410946037
s531129125
1,549
1,043
3,060
2,940
Accepted
Accepted
32.67
K, S = list(map(int, input().split())) K += 1 cnt = 0 for i in range(K): if i+K*2<=S : continue if i>S : continue for j in range(min(K, S-i+1)): if i+j+K<=S : continue if i+j>S : break cnt += 1 print(cnt)
#! /usr/bin/env python3 K, S = list(map(int, input().split())) K += 1 cnt = 0 for i in range(min(K, S+1)): if i+K*2<=S : continue for j in range(min(K, S-i+1)): if i+j+K<=S : continue cnt += 1 print(cnt)
11
11
250
238
K, S = list(map(int, input().split())) K += 1 cnt = 0 for i in range(K): if i + K * 2 <= S: continue if i > S: continue for j in range(min(K, S - i + 1)): if i + j + K <= S: continue if i + j > S: break cnt += 1 print(cnt)
#! /usr/bin/env python3 K, S = list(map(int, input().split())) K += 1 cnt = 0 for i in range(min(K, S + 1)): if i + K * 2 <= S: continue for j in range(min(K, S - i + 1)): if i + j + K <= S: continue cnt += 1 print(cnt)
false
0
[ "+#! /usr/bin/env python3", "-for i in range(K):", "+for i in range(min(K, S + 1)):", "- continue", "- if i > S:", "- if i + j > S:", "- break" ]
false
0.042061
0.035966
1.169467
[ "s410946037", "s531129125" ]
u858885710
p00006
python
s075089214
s775628595
20
10
4,180
4,184
Accepted
Accepted
50
print(input().strip()[::-1])
print(input()[::-1])
1
1
31
23
print(input().strip()[::-1])
print(input()[::-1])
false
0
[ "-print(input().strip()[::-1])", "+print(input()[::-1])" ]
false
0.038577
0.039716
0.971323
[ "s075089214", "s775628595" ]
u279605379
p02297
python
s809754282
s793675868
30
20
7,728
7,728
Accepted
Accepted
33.33
x=list(range(int(eval(input())))) P=[] Q=[] for _ in x:P+=[[int(i) for i in input().split()]] P+=[P[0]] for j in x:Q+=[P[j][0]*P[j+1][1]-P[j][1]*P[j+1][0]] print((sum(Q)*0.5))
x=list(range(int(eval(input())))) P=[] for _ in x:P+=[[int(i) for i in input().split()]] _=0 P+=[P[0]] for j in x:_+=P[j][0]*P[j+1][1]-P[j+1][0]*P[j][1] print((_*0.5))
7
7
167
159
x = list(range(int(eval(input())))) P = [] Q = [] for _ in x: P += [[int(i) for i in input().split()]] P += [P[0]] for j in x: Q += [P[j][0] * P[j + 1][1] - P[j][1] * P[j + 1][0]] print((sum(Q) * 0.5))
x = list(range(int(eval(input())))) P = [] for _ in x: P += [[int(i) for i in input().split()]] _ = 0 P += [P[0]] for j in x: _ += P[j][0] * P[j + 1][1] - P[j + 1][0] * P[j][1] print((_ * 0.5))
false
0
[ "-Q = []", "+_ = 0", "- Q += [P[j][0] * P[j + 1][1] - P[j][1] * P[j + 1][0]]", "-print((sum(Q) * 0.5))", "+ _ += P[j][0] * P[j + 1][1] - P[j + 1][0] * P[j][1]", "+print((_ * 0.5))" ]
false
0.046287
0.042902
1.078898
[ "s809754282", "s793675868" ]
u711539583
p03127
python
s966629833
s149184603
117
79
15,020
14,224
Accepted
Accepted
32.48
n = int(eval(input())) hps = list(map(int, input().split())) m = min(hps) def gojo(a, b): if b == 0: return a else: return gojo(b, a % b) res = m for hp in hps: res = gojo(max(res, hp),min(res, hp)) print(res)
n = int(eval(input())) hps = list(map(int, input().split())) m = min(hps) def gojo(a, b): if b == 0: return a else: return gojo(b, a % b) res = m for hp in hps: res = gojo(hp, res) print(res)
12
12
228
210
n = int(eval(input())) hps = list(map(int, input().split())) m = min(hps) def gojo(a, b): if b == 0: return a else: return gojo(b, a % b) res = m for hp in hps: res = gojo(max(res, hp), min(res, hp)) print(res)
n = int(eval(input())) hps = list(map(int, input().split())) m = min(hps) def gojo(a, b): if b == 0: return a else: return gojo(b, a % b) res = m for hp in hps: res = gojo(hp, res) print(res)
false
0
[ "- res = gojo(max(res, hp), min(res, hp))", "+ res = gojo(hp, res)" ]
false
0.037555
0.007645
4.912472
[ "s966629833", "s149184603" ]
u421674761
p02659
python
s931513790
s792151581
37
25
9,988
9,032
Accepted
Accepted
32.43
from decimal import * a,b = input().split() print((int(Decimal(a)*Decimal(b))))
a,b = input().split() a = int(a) b = int(b.replace('.','')) print((a*b//100))
4
6
82
83
from decimal import * a, b = input().split() print((int(Decimal(a) * Decimal(b))))
a, b = input().split() a = int(a) b = int(b.replace(".", "")) print((a * b // 100))
false
33.333333
[ "-from decimal import *", "-", "-print((int(Decimal(a) * Decimal(b))))", "+a = int(a)", "+b = int(b.replace(\".\", \"\"))", "+print((a * b // 100))" ]
false
0.08169
0.037612
2.171895
[ "s931513790", "s792151581" ]
u811733736
p00508
python
s245200254
s626390360
16,990
14,750
84,488
84,100
Accepted
Accepted
13.18
# -*- coding: utf-8 -*- """ http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0585 """ import sys from sys import stdin from collections import namedtuple input = stdin.readline def closest_part(points, n): # ?????¬???p324??? if n <= 1: return float('inf') m = n // 2 x = points[m][0] d = min(closest_part(points[:m], m), closest_part(points[m:], n-m)) points.sort(key=lambda p:p[1]) b = [] for p in points: if (p[0] - x)**2 >= d: continue for q in b[::-1]: # dx = p[0] - b[-j-1][0] # dy = p[1] - b[-j-1][1] dx = p[0] - q[0] dy = p[1] - q[1] if dy**2 >= d: break d = min(d, (dx**2 + dy**2)) b.append(p) return d def main(args): n = int(eval(input())) points = [tuple(map(int, input().split())) for _ in range(n)] points.sort() # x????????§?????????????????? result = closest_part(points, n) print(result) if __name__ == '__main__': main(sys.argv[1:])
# -*- coding: utf-8 -*- """ http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0585 """ import sys from sys import stdin input = stdin.readline def closest_part(points, n): # ?????¬???p324??? if n <= 1: return float('inf') m = n // 2 x = points[m][0] d = min(closest_part(points[:m], m), closest_part(points[m:], n-m)) points.sort(key=lambda p:p[1]) b = [] for p in points: if (p[0] - x)**2 >= d: continue for q in b: dx = p[0] - q[0] dy = p[1] - q[1] if dy**2 >= d: break d = min(d, (dx**2 + dy**2)) b.insert(0, p) return d def main(args): n = int(eval(input())) points = [tuple(map(int, input().split())) for _ in range(n)] points.sort() # x????????§?????????????????? result = closest_part(points, n) print(result) if __name__ == '__main__': main(sys.argv[1:])
46
44
1,111
998
# -*- coding: utf-8 -*- """ http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0585 """ import sys from sys import stdin from collections import namedtuple input = stdin.readline def closest_part(points, n): # ?????¬???p324??? if n <= 1: return float("inf") m = n // 2 x = points[m][0] d = min(closest_part(points[:m], m), closest_part(points[m:], n - m)) points.sort(key=lambda p: p[1]) b = [] for p in points: if (p[0] - x) ** 2 >= d: continue for q in b[::-1]: # dx = p[0] - b[-j-1][0] # dy = p[1] - b[-j-1][1] dx = p[0] - q[0] dy = p[1] - q[1] if dy**2 >= d: break d = min(d, (dx**2 + dy**2)) b.append(p) return d def main(args): n = int(eval(input())) points = [tuple(map(int, input().split())) for _ in range(n)] points.sort() # x????????§?????????????????? result = closest_part(points, n) print(result) if __name__ == "__main__": main(sys.argv[1:])
# -*- coding: utf-8 -*- """ http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0585 """ import sys from sys import stdin input = stdin.readline def closest_part(points, n): # ?????¬???p324??? if n <= 1: return float("inf") m = n // 2 x = points[m][0] d = min(closest_part(points[:m], m), closest_part(points[m:], n - m)) points.sort(key=lambda p: p[1]) b = [] for p in points: if (p[0] - x) ** 2 >= d: continue for q in b: dx = p[0] - q[0] dy = p[1] - q[1] if dy**2 >= d: break d = min(d, (dx**2 + dy**2)) b.insert(0, p) return d def main(args): n = int(eval(input())) points = [tuple(map(int, input().split())) for _ in range(n)] points.sort() # x????????§?????????????????? result = closest_part(points, n) print(result) if __name__ == "__main__": main(sys.argv[1:])
false
4.347826
[ "-from collections import namedtuple", "- for q in b[::-1]:", "- # dx = p[0] - b[-j-1][0]", "- # dy = p[1] - b[-j-1][1]", "+ for q in b:", "- b.append(p)", "+ b.insert(0, p)" ]
false
0.044355
0.046532
0.953217
[ "s245200254", "s626390360" ]
u102461423
p02973
python
s437694518
s145035966
117
88
7,964
12,528
Accepted
Accepted
24.79
import sys input = sys.stdin.readline import bisect INF = 10 ** 18 N = int(eval(input())) A = [10 ** 10 - int(eval(input())) for _ in range(N)] # 逆順にしておく # 最長単調減少列:狭義 dp = [INF] * (N+1) # 長さ、その長さの末端としてありうる最大値 for a in A: idx = bisect.bisect_right(dp,a) dp[idx] = a answer = bisect.bisect_left(dp, INF) print(answer)
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines from bisect import bisect_right N,*A = list(map(int,read().split())) def LIS(seq): # 狭義 N = len(seq) INF = 10**18 dp = [INF] * (N+1) for x in seq: i = bisect_right(dp,x) dp[i] = x return bisect_right(dp,INF-1) answer = LIS([-x for x in A]) print(answer)
18
21
333
427
import sys input = sys.stdin.readline import bisect INF = 10**18 N = int(eval(input())) A = [10**10 - int(eval(input())) for _ in range(N)] # 逆順にしておく # 最長単調減少列:狭義 dp = [INF] * (N + 1) # 長さ、その長さの末端としてありうる最大値 for a in A: idx = bisect.bisect_right(dp, a) dp[idx] = a answer = bisect.bisect_left(dp, INF) print(answer)
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines from bisect import bisect_right N, *A = list(map(int, read().split())) def LIS(seq): # 狭義 N = len(seq) INF = 10**18 dp = [INF] * (N + 1) for x in seq: i = bisect_right(dp, x) dp[i] = x return bisect_right(dp, INF - 1) answer = LIS([-x for x in A]) print(answer)
false
14.285714
[ "-input = sys.stdin.readline", "-import bisect", "+read = sys.stdin.buffer.read", "+readline = sys.stdin.buffer.readline", "+readlines = sys.stdin.buffer.readlines", "+from bisect import bisect_right", "-INF = 10**18", "-N = int(eval(input()))", "-A = [10**10 - int(eval(input())) for _ in range(N)] ...
false
0.075458
0.111459
0.677003
[ "s437694518", "s145035966" ]
u133936772
p02763
python
s644773076
s791642925
1,705
1,302
120,308
28,928
Accepted
Accepted
23.64
f=input from bisect import bisect_left as g, insort as h n,s=int(f()),list(f()) d={chr(97+i):[] for i in range(26)} for i in range(n): d[s[i]]+=[i] for _ in range(int(f())): a,b,c=f().split(); b=int(b)-1 if a>'1': print((sum(1 for l in list(d.values()) if g(l,b)<len(l) and l[g(l,b)]<int(c)))) elif s[b]!=c: l=d[s[b]]; l.pop(g(l,b)); s[b]=c; h(d[c],b)
f=input; from bisect import bisect_left as g, insort as h f(); s,i=list(f()),0 from collections import * d=defaultdict(list) for c in s: d[c]+=[i]; i+=1 for _ in range(int(f())): a,b,c=f().split(); b=int(b)-1 if a>'1': print((sum(1 for l in list(d.values()) if g(l,b)<len(l) and l[g(l,b)]<int(c)))) elif s[b]!=c: l=d[s[b]]; l.pop(g(l,b)); s[b]=c; h(d[c],b)
9
9
357
362
f = input from bisect import bisect_left as g, insort as h n, s = int(f()), list(f()) d = {chr(97 + i): [] for i in range(26)} for i in range(n): d[s[i]] += [i] for _ in range(int(f())): a, b, c = f().split() b = int(b) - 1 if a > "1": print( ( sum( 1 for l in list(d.values()) if g(l, b) < len(l) and l[g(l, b)] < int(c) ) ) ) elif s[b] != c: l = d[s[b]] l.pop(g(l, b)) s[b] = c h(d[c], b)
f = input from bisect import bisect_left as g, insort as h f() s, i = list(f()), 0 from collections import * d = defaultdict(list) for c in s: d[c] += [i] i += 1 for _ in range(int(f())): a, b, c = f().split() b = int(b) - 1 if a > "1": print( ( sum( 1 for l in list(d.values()) if g(l, b) < len(l) and l[g(l, b)] < int(c) ) ) ) elif s[b] != c: l = d[s[b]] l.pop(g(l, b)) s[b] = c h(d[c], b)
false
0
[ "-n, s = int(f()), list(f())", "-d = {chr(97 + i): [] for i in range(26)}", "-for i in range(n):", "- d[s[i]] += [i]", "+f()", "+s, i = list(f()), 0", "+from collections import *", "+", "+d = defaultdict(list)", "+for c in s:", "+ d[c] += [i]", "+ i += 1" ]
false
0.039101
0.039772
0.983113
[ "s644773076", "s791642925" ]
u190167135
p02911
python
s106143120
s272747886
189
93
11,492
11,612
Accepted
Accepted
50.79
N,K,Q=list(map(int,input().split())) scores=[K-Q]*N for _ in range(Q): scores[int(eval(input()))-1]+=1 for score in scores: print(('Yes' if score>0 else 'No'))
import sys sys.setrecursionlimit(1000000000) input=sys.stdin.readline N,K,Q=list(map(int,input().split())) scores=[K-Q]*N for _ in range(Q): scores[int(eval(input()))-1]+=1 for score in scores: print(('Yes' if score>0 else 'No'))
6
9
158
231
N, K, Q = list(map(int, input().split())) scores = [K - Q] * N for _ in range(Q): scores[int(eval(input())) - 1] += 1 for score in scores: print(("Yes" if score > 0 else "No"))
import sys sys.setrecursionlimit(1000000000) input = sys.stdin.readline N, K, Q = list(map(int, input().split())) scores = [K - Q] * N for _ in range(Q): scores[int(eval(input())) - 1] += 1 for score in scores: print(("Yes" if score > 0 else "No"))
false
33.333333
[ "+import sys", "+", "+sys.setrecursionlimit(1000000000)", "+input = sys.stdin.readline" ]
false
0.041252
0.042229
0.976859
[ "s106143120", "s272747886" ]
u367701763
p03112
python
s032459620
s119110020
778
717
121,608
89,704
Accepted
Accepted
7.84
def near(x, Y): i = bisect_left(Y,x) if i == 0: return Y[i]-x elif i == len(Y): return x-Y[i-1] else: return min(Y[i]-x, x-Y[i-1]) def near2(x, Y): i = bisect_left(Y,x) if i == 0: return Y[i]-x + D[i][1] elif i == len(Y): return x-Y[i-1] + D[i-1][1] else: return min(Y[i]-x+D[i][1], x-Y[i-1]+D[i-1][1]) from bisect import * A, B, Q = list(map(int, input().split())) S = [] T = [] for _ in range(A): S.append(int(eval(input()))) for _ in range(B): T.append(int(eval(input()))) D = [] for a in S: D.append((a, near(a, T))) for b in T: D.append((b, near(b, S))) D.sort(key=lambda x:x[0]) D2 = [d for d, _ in D] for _ in range(Q): x = int(eval(input())) print((near2(x,D2)))
def near(x, X): i = bisect_left(X, x) if i == 0: return [X[i]-x] elif i == len(X): return [X[i-1]-x] else: return [X[i]-x, X[i-1]-x] from bisect import * A, B, Q = list(map(int, input().split())) S, T = [], [] for _ in range(A): S.append(int(eval(input()))) for _ in range(B): T.append(int(eval(input()))) for _ in range(Q): res = 1<<40 x = int(eval(input())) for a in near(x,S): for b in near(x,T): res = min(abs(a)+abs(a-b), abs(b)+abs(b-a), res) print(res)
37
19
788
513
def near(x, Y): i = bisect_left(Y, x) if i == 0: return Y[i] - x elif i == len(Y): return x - Y[i - 1] else: return min(Y[i] - x, x - Y[i - 1]) def near2(x, Y): i = bisect_left(Y, x) if i == 0: return Y[i] - x + D[i][1] elif i == len(Y): return x - Y[i - 1] + D[i - 1][1] else: return min(Y[i] - x + D[i][1], x - Y[i - 1] + D[i - 1][1]) from bisect import * A, B, Q = list(map(int, input().split())) S = [] T = [] for _ in range(A): S.append(int(eval(input()))) for _ in range(B): T.append(int(eval(input()))) D = [] for a in S: D.append((a, near(a, T))) for b in T: D.append((b, near(b, S))) D.sort(key=lambda x: x[0]) D2 = [d for d, _ in D] for _ in range(Q): x = int(eval(input())) print((near2(x, D2)))
def near(x, X): i = bisect_left(X, x) if i == 0: return [X[i] - x] elif i == len(X): return [X[i - 1] - x] else: return [X[i] - x, X[i - 1] - x] from bisect import * A, B, Q = list(map(int, input().split())) S, T = [], [] for _ in range(A): S.append(int(eval(input()))) for _ in range(B): T.append(int(eval(input()))) for _ in range(Q): res = 1 << 40 x = int(eval(input())) for a in near(x, S): for b in near(x, T): res = min(abs(a) + abs(a - b), abs(b) + abs(b - a), res) print(res)
false
48.648649
[ "-def near(x, Y):", "- i = bisect_left(Y, x)", "+def near(x, X):", "+ i = bisect_left(X, x)", "- return Y[i] - x", "- elif i == len(Y):", "- return x - Y[i - 1]", "+ return [X[i] - x]", "+ elif i == len(X):", "+ return [X[i - 1] - x]", "- return min...
false
0.045492
0.088523
0.513907
[ "s032459620", "s119110020" ]
u733608212
p03409
python
s906990167
s789070826
39
23
3,064
3,064
Accepted
Accepted
41.03
n = int(eval(input())) red_li = [list(map(int, input().split())) for _ in range(n)] blue_li = [list(map(int, input().split())) for _ in range(n)] ans = 0 red_li.sort(reverse = True, key = lambda x : (x[0], x[1])) blue_li.sort( key = lambda x : (x[0], x[1])) def count(red, blue): used_red = [] used_blue = [] for i in red: if i in used_red: continue for j in blue: if j in used_blue: continue if i[0] < j[0] and i[1] < j[1]: used_red.append(i) used_blue.append(j) break return len(used_red) ans = count(red_li, blue_li) red_li.sort(reverse = True,key = lambda x : (x[1], x[0])) blue_li.sort( key = lambda x : (x[1], x[0])) ans = max(ans, count(red_li, blue_li)) red_li.sort(reverse = True,key = lambda x : (x[1], x[0])) blue_li.sort( key = lambda x : (x[0], x[1])) ans = max(ans, count(red_li, blue_li)) red_li.sort(reverse = True,key = lambda x : (x[0], x[1])) blue_li.sort( key = lambda x : (x[1], x[0])) ans = max(ans, count(red_li, blue_li)) print(ans)
n = int(eval(input())) red_li = [list(map(int, input().split())) for _ in range(n)] blue_li = [list(map(int, input().split())) for _ in range(n)] ans = 0 red_li.sort(reverse = True, key = lambda x : (x[0], x[1])) blue_li.sort( key = lambda x : (x[0], x[1])) def count(red, blue): used_red = [] used_blue = [] for i in red: if i in used_red: continue for j in blue: if j in used_blue: continue if i[0] < j[0] and i[1] < j[1]: used_red.append(i) used_blue.append(j) break return len(used_red) red_li.sort(reverse = True,key = lambda x : (x[0], x[1])) blue_li.sort( key = lambda x : (x[1], x[0])) ans = max(ans, count(red_li, blue_li)) print(ans)
33
27
1,118
800
n = int(eval(input())) red_li = [list(map(int, input().split())) for _ in range(n)] blue_li = [list(map(int, input().split())) for _ in range(n)] ans = 0 red_li.sort(reverse=True, key=lambda x: (x[0], x[1])) blue_li.sort(key=lambda x: (x[0], x[1])) def count(red, blue): used_red = [] used_blue = [] for i in red: if i in used_red: continue for j in blue: if j in used_blue: continue if i[0] < j[0] and i[1] < j[1]: used_red.append(i) used_blue.append(j) break return len(used_red) ans = count(red_li, blue_li) red_li.sort(reverse=True, key=lambda x: (x[1], x[0])) blue_li.sort(key=lambda x: (x[1], x[0])) ans = max(ans, count(red_li, blue_li)) red_li.sort(reverse=True, key=lambda x: (x[1], x[0])) blue_li.sort(key=lambda x: (x[0], x[1])) ans = max(ans, count(red_li, blue_li)) red_li.sort(reverse=True, key=lambda x: (x[0], x[1])) blue_li.sort(key=lambda x: (x[1], x[0])) ans = max(ans, count(red_li, blue_li)) print(ans)
n = int(eval(input())) red_li = [list(map(int, input().split())) for _ in range(n)] blue_li = [list(map(int, input().split())) for _ in range(n)] ans = 0 red_li.sort(reverse=True, key=lambda x: (x[0], x[1])) blue_li.sort(key=lambda x: (x[0], x[1])) def count(red, blue): used_red = [] used_blue = [] for i in red: if i in used_red: continue for j in blue: if j in used_blue: continue if i[0] < j[0] and i[1] < j[1]: used_red.append(i) used_blue.append(j) break return len(used_red) red_li.sort(reverse=True, key=lambda x: (x[0], x[1])) blue_li.sort(key=lambda x: (x[1], x[0])) ans = max(ans, count(red_li, blue_li)) print(ans)
false
18.181818
[ "-ans = count(red_li, blue_li)", "-red_li.sort(reverse=True, key=lambda x: (x[1], x[0]))", "-blue_li.sort(key=lambda x: (x[1], x[0]))", "-ans = max(ans, count(red_li, blue_li))", "-red_li.sort(reverse=True, key=lambda x: (x[1], x[0]))", "-blue_li.sort(key=lambda x: (x[0], x[1]))", "-ans = max(ans, count...
false
0.038263
0.038863
0.984556
[ "s906990167", "s789070826" ]
u285891772
p02882
python
s604950446
s054328820
55
38
5,588
5,204
Accepted
Accepted
30.91
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2 from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left 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 a, b, x = MAP() S = x/a #水の断面積 if a*b/2 >= S: #水の断面:三角形 c = 2*S/b ans = degrees(atan(b/c)) else: #水の断面:台形 c = 2*S/a - b ans = degrees(atan((b-c)/a)) print(ans)
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2 from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left 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 a, b, x = MAP() y = 2*x/a/b h = x/a**2 left = b-h if x <= a*a*b/2: print((degrees(atan(b/y)))) else: print((degrees(atan(2*left/a))))
35
31
1,055
996
import sys, re from collections import deque, defaultdict, Counter from math import ( ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, ) from itertools import ( accumulate, permutations, combinations, combinations_with_replacement, product, groupby, ) from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left 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 a, b, x = MAP() S = x / a # 水の断面積 if a * b / 2 >= S: # 水の断面:三角形 c = 2 * S / b ans = degrees(atan(b / c)) else: # 水の断面:台形 c = 2 * S / a - b ans = degrees(atan((b - c) / a)) print(ans)
import sys, re from collections import deque, defaultdict, Counter from math import ( ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, ) from itertools import ( accumulate, permutations, combinations, combinations_with_replacement, product, groupby, ) from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left 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 a, b, x = MAP() y = 2 * x / a / b h = x / a**2 left = b - h if x <= a * a * b / 2: print((degrees(atan(b / y)))) else: print((degrees(atan(2 * left / a))))
false
11.428571
[ "-S = x / a # 水の断面積", "-if a * b / 2 >= S: # 水の断面:三角形", "- c = 2 * S / b", "- ans = degrees(atan(b / c))", "-else: # 水の断面:台形", "- c = 2 * S / a - b", "- ans = degrees(atan((b - c) / a))", "-print(ans)", "+y = 2 * x / a / b", "+h = x / a**2", "+left = b - h", "+if x <= a * a * b ...
false
0.038275
0.038675
0.989666
[ "s604950446", "s054328820" ]
u561083515
p02837
python
s378974375
s086916273
336
216
3,316
3,064
Accepted
Accepted
35.71
N = int(eval(input())) xy = [[] for _ in range(N)] for i in range(N): A = int(eval(input())) for _ in range(A): x,y = list(map(int,input().split())) xy[i].append([x-1,y]) answer = 0 # 状態n for n in range(2 ** N): # 正直者のリスト true_person = [] index = 0 copy_n = n while copy_n: if copy_n & 1: true_person.append(index) index += 1 copy_n >>= 1 # 矛盾が生じたときTrue flag = False # 人i for i in true_person: # iさんの証言 for x,y in xy[i]: # 証言と状態が違う場合 if (x in true_person and y == 0) or (not(x in true_person) and y == 1): flag = True if flag: break if flag: continue else: answer = max(answer, len(true_person)) print(answer)
N = int(eval(input())) edge = [[] for _ in range(N)] for i in range(N): A = int(eval(input())) for j in range(A): x,y = list(map(int,input().split())) edge[i].append((x-1,y)) ans = 0 for i in range(2**N): # 1: 正直者 state = [0] * N for j in range(N): state[j] = (i >> j) & 1 # 真偽を確かめる flag = True for j in range(N): if state[j] == 0: continue for x,y in edge[j]: if state[x] == y: continue flag = False break if not flag: break if not flag: continue ans = max(ans, state.count(1)) print(ans)
39
33
833
683
N = int(eval(input())) xy = [[] for _ in range(N)] for i in range(N): A = int(eval(input())) for _ in range(A): x, y = list(map(int, input().split())) xy[i].append([x - 1, y]) answer = 0 # 状態n for n in range(2**N): # 正直者のリスト true_person = [] index = 0 copy_n = n while copy_n: if copy_n & 1: true_person.append(index) index += 1 copy_n >>= 1 # 矛盾が生じたときTrue flag = False # 人i for i in true_person: # iさんの証言 for x, y in xy[i]: # 証言と状態が違う場合 if (x in true_person and y == 0) or (not (x in true_person) and y == 1): flag = True if flag: break if flag: continue else: answer = max(answer, len(true_person)) print(answer)
N = int(eval(input())) edge = [[] for _ in range(N)] for i in range(N): A = int(eval(input())) for j in range(A): x, y = list(map(int, input().split())) edge[i].append((x - 1, y)) ans = 0 for i in range(2**N): # 1: 正直者 state = [0] * N for j in range(N): state[j] = (i >> j) & 1 # 真偽を確かめる flag = True for j in range(N): if state[j] == 0: continue for x, y in edge[j]: if state[x] == y: continue flag = False break if not flag: break if not flag: continue ans = max(ans, state.count(1)) print(ans)
false
15.384615
[ "-xy = [[] for _ in range(N)]", "+edge = [[] for _ in range(N)]", "- for _ in range(A):", "+ for j in range(A):", "- xy[i].append([x - 1, y])", "-answer = 0", "-# 状態n", "-for n in range(2**N):", "- # 正直者のリスト", "- true_person = []", "- index = 0", "- copy_n = n", "- ...
false
0.060466
0.047355
1.276869
[ "s378974375", "s086916273" ]
u766477342
p00244
python
s253716786
s204333140
1,870
940
6,768
6,780
Accepted
Accepted
49.73
MAX_VAL = 99999999999 while 1: n,m = list(map(int,input().split())) if n == 0:break costs = {x:[] for x in range(1,n+1)} min_cost = [[MAX_VAL for x in range(2)] for y in range(n+1)] for i in range(m): a,b,c = list(map(int,input().split())) costs[a].append((b,c)) costs[b].append((a,c)) spam = [(0,1,2)] #(cost,num,free tickets count) while len(spam) > 0: mc = min(spam) spam.remove(mc) tic_i = 0 if mc[2] == 2 else 1 if mc[2] != 1 and min_cost[mc[1]][tic_i] != MAX_VAL: continue if mc[2] != 1: min_cost[mc[1]][tic_i] = mc[0] #移動できる場所の登録 for cv in costs[mc[1]]: #チケット不使用 if mc[2] != 1: spam.append((mc[0] + cv[1],cv[0],mc[2])) #チケット使用 if mc[2] > 0: spam.append((mc[0],cv[0],mc[2]-1)) #print(min_cost[n]) print((min(min_cost[n])))
MAX_V = 999999999999999999999 while 1: n,m = list(map(int,input().split())) if n == 0:break costs = {x:[] for x in range(1,n+1)} passed = [[0 for x in range(2)] for y in range(n+1)] result = [MAX_V,MAX_V] for i in range(m): a,b,c = list(map(int,input().split())) costs[a].append((b,c)) costs[b].append((a,c)) spam = [(0,1,2)] #(cost,num,free tickets count) while len(spam) > 0: mc = min(spam) spam.remove(mc) tic_i = 0 if mc[2] == 2 else 1 if mc[2] != 1 and passed[mc[1]][tic_i] != 0: continue if mc[2] != 1: passed[mc[1]][tic_i] = 1 if n == mc[1]: result[tic_i] = mc[0] if max(result) < MAX_V:break #移動できる場所の登録 for cv in costs[mc[1]]: #チケット不使用 if mc[2] != 1: spam.append((mc[0] + cv[1],cv[0],mc[2])) #チケット使用 if mc[2] > 0: spam.append((mc[0],cv[0],mc[2]-1)) print((min(result)))
35
39
986
1,077
MAX_VAL = 99999999999 while 1: n, m = list(map(int, input().split())) if n == 0: break costs = {x: [] for x in range(1, n + 1)} min_cost = [[MAX_VAL for x in range(2)] for y in range(n + 1)] for i in range(m): a, b, c = list(map(int, input().split())) costs[a].append((b, c)) costs[b].append((a, c)) spam = [(0, 1, 2)] # (cost,num,free tickets count) while len(spam) > 0: mc = min(spam) spam.remove(mc) tic_i = 0 if mc[2] == 2 else 1 if mc[2] != 1 and min_cost[mc[1]][tic_i] != MAX_VAL: continue if mc[2] != 1: min_cost[mc[1]][tic_i] = mc[0] # 移動できる場所の登録 for cv in costs[mc[1]]: # チケット不使用 if mc[2] != 1: spam.append((mc[0] + cv[1], cv[0], mc[2])) # チケット使用 if mc[2] > 0: spam.append((mc[0], cv[0], mc[2] - 1)) # print(min_cost[n]) print((min(min_cost[n])))
MAX_V = 999999999999999999999 while 1: n, m = list(map(int, input().split())) if n == 0: break costs = {x: [] for x in range(1, n + 1)} passed = [[0 for x in range(2)] for y in range(n + 1)] result = [MAX_V, MAX_V] for i in range(m): a, b, c = list(map(int, input().split())) costs[a].append((b, c)) costs[b].append((a, c)) spam = [(0, 1, 2)] # (cost,num,free tickets count) while len(spam) > 0: mc = min(spam) spam.remove(mc) tic_i = 0 if mc[2] == 2 else 1 if mc[2] != 1 and passed[mc[1]][tic_i] != 0: continue if mc[2] != 1: passed[mc[1]][tic_i] = 1 if n == mc[1]: result[tic_i] = mc[0] if max(result) < MAX_V: break # 移動できる場所の登録 for cv in costs[mc[1]]: # チケット不使用 if mc[2] != 1: spam.append((mc[0] + cv[1], cv[0], mc[2])) # チケット使用 if mc[2] > 0: spam.append((mc[0], cv[0], mc[2] - 1)) print((min(result)))
false
10.25641
[ "-MAX_VAL = 99999999999", "+MAX_V = 999999999999999999999", "- min_cost = [[MAX_VAL for x in range(2)] for y in range(n + 1)]", "+ passed = [[0 for x in range(2)] for y in range(n + 1)]", "+ result = [MAX_V, MAX_V]", "- if mc[2] != 1 and min_cost[mc[1]][tic_i] != MAX_VAL:", "+ if ...
false
0.089136
0.070438
1.265455
[ "s253716786", "s204333140" ]
u401686269
p02558
python
s767085920
s567845674
1,314
729
68,740
11,480
Accepted
Accepted
44.52
from networkx.utils import UnionFind N,Q=list(map(int,input().split())) uf = UnionFind() for i in range(Q): t,u,v = list(map(int,input().split())) if t:print((1 if uf[u]==uf[v] else 0)) else:uf.union(u,v)
class UnionFind(): def __init__(self, n=0): self.d = [-1]*n def find(self, x): if self.d[x] < 0: return x self.d[x] = self.find(self.d[x]) return self.d[x] def unite(self, x, y): x,y=self.find(x),self.find(y) if x==y:return False if self.d[x] > self.d[y]: x,y=y,x self.d[x] += self.d[y] self.d[y] = x return True def same(self, x,y): return self.find(x)==self.find(y) def size(self,x): return -self.d[self.find(x)] def main(): N,Q=list(map(int,input().split())) uf = UnionFind(N) for i in range(Q): t,u,v=list(map(int,input().split())) if t: print((+(uf.same(u,v)))) else: uf.unite(u,v) if __name__=="__main__": main()
7
32
202
786
from networkx.utils import UnionFind N, Q = list(map(int, input().split())) uf = UnionFind() for i in range(Q): t, u, v = list(map(int, input().split())) if t: print((1 if uf[u] == uf[v] else 0)) else: uf.union(u, v)
class UnionFind: def __init__(self, n=0): self.d = [-1] * n def find(self, x): if self.d[x] < 0: return x self.d[x] = self.find(self.d[x]) return self.d[x] def unite(self, x, y): x, y = self.find(x), self.find(y) if x == y: return False if self.d[x] > self.d[y]: x, y = y, x self.d[x] += self.d[y] self.d[y] = x return True def same(self, x, y): return self.find(x) == self.find(y) def size(self, x): return -self.d[self.find(x)] def main(): N, Q = list(map(int, input().split())) uf = UnionFind(N) for i in range(Q): t, u, v = list(map(int, input().split())) if t: print((+(uf.same(u, v)))) else: uf.unite(u, v) if __name__ == "__main__": main()
false
78.125
[ "-from networkx.utils import UnionFind", "+class UnionFind:", "+ def __init__(self, n=0):", "+ self.d = [-1] * n", "-N, Q = list(map(int, input().split()))", "-uf = UnionFind()", "-for i in range(Q):", "- t, u, v = list(map(int, input().split()))", "- if t:", "- print((1 if ...
false
0.038341
0.047764
0.80272
[ "s767085920", "s567845674" ]
u278955646
p02780
python
s575979469
s969220322
1,495
1,264
26,328
26,328
Accepted
Accepted
15.45
import queue N, K = list(map(int, input().split())) p = list(map(int, input().split())) for i in range(len(p)): p[i] = p[i] + 1 queue = queue.Queue() currentSum = 0 maxSum = 0 for i in range(len(p)): currentSum = currentSum + p[i] queue.put(p[i]) if queue.qsize() > K: currentSum = currentSum - queue.get() if queue.qsize() == K: maxSum = max(maxSum, currentSum) print(("{:.12f}".format(maxSum / 2)))
import queue N, K = list(map(int, input().split())) p = list(map(int, input().split())) for i in range(len(p)): p[i] = p[i] + 1 queue = queue.Queue() currentSum = 0 maxSum = 0 for i in range(len(p)): currentSum = currentSum + p[i] queue.put(p[i]) if i >= K: currentSum = currentSum - queue.get() if i >= K - 1: maxSum = max(maxSum, currentSum) print(("{:.12f}".format(maxSum / 2)))
21
21
458
435
import queue N, K = list(map(int, input().split())) p = list(map(int, input().split())) for i in range(len(p)): p[i] = p[i] + 1 queue = queue.Queue() currentSum = 0 maxSum = 0 for i in range(len(p)): currentSum = currentSum + p[i] queue.put(p[i]) if queue.qsize() > K: currentSum = currentSum - queue.get() if queue.qsize() == K: maxSum = max(maxSum, currentSum) print(("{:.12f}".format(maxSum / 2)))
import queue N, K = list(map(int, input().split())) p = list(map(int, input().split())) for i in range(len(p)): p[i] = p[i] + 1 queue = queue.Queue() currentSum = 0 maxSum = 0 for i in range(len(p)): currentSum = currentSum + p[i] queue.put(p[i]) if i >= K: currentSum = currentSum - queue.get() if i >= K - 1: maxSum = max(maxSum, currentSum) print(("{:.12f}".format(maxSum / 2)))
false
0
[ "- if queue.qsize() > K:", "+ if i >= K:", "- if queue.qsize() == K:", "+ if i >= K - 1:" ]
false
0.051597
0.008266
6.242197
[ "s575979469", "s969220322" ]
u311379832
p02844
python
s808676834
s799910428
23
21
3,064
3,064
Accepted
Accepted
8.7
N = int(eval(input())) S = eval(input()) ans = 0 anslst = [] for i in range(10): for j in range(10): for k in range(10): anslst.append(str(i) + str(j) + str(k)) tmp = ans for i in anslst: a, b, c = i index1 = S.find(a) index2 = S.find(b, index1 + 1) index3 = S.find(c, index2 + 1) if index1 != -1 and index2 != -1 and index3 != -1: ans += 1 print(ans)
N = int(eval(input())) S = eval(input()) cnt = 0 pin = [] for i in range(10): for j in range(10): for k in range(10): pin.append(str(i) + str(j) + str(k)) for i in range(1000): one = S.find(pin[i][0]) two = S.find(pin[i][1], one + 1) three = S.find(pin[i][2], two + 1) if one != -1 and two != -1 and three != -1: cnt += 1 print(cnt)
19
18
411
388
N = int(eval(input())) S = eval(input()) ans = 0 anslst = [] for i in range(10): for j in range(10): for k in range(10): anslst.append(str(i) + str(j) + str(k)) tmp = ans for i in anslst: a, b, c = i index1 = S.find(a) index2 = S.find(b, index1 + 1) index3 = S.find(c, index2 + 1) if index1 != -1 and index2 != -1 and index3 != -1: ans += 1 print(ans)
N = int(eval(input())) S = eval(input()) cnt = 0 pin = [] for i in range(10): for j in range(10): for k in range(10): pin.append(str(i) + str(j) + str(k)) for i in range(1000): one = S.find(pin[i][0]) two = S.find(pin[i][1], one + 1) three = S.find(pin[i][2], two + 1) if one != -1 and two != -1 and three != -1: cnt += 1 print(cnt)
false
5.263158
[ "-ans = 0", "-anslst = []", "+cnt = 0", "+pin = []", "- anslst.append(str(i) + str(j) + str(k))", "-tmp = ans", "-for i in anslst:", "- a, b, c = i", "- index1 = S.find(a)", "- index2 = S.find(b, index1 + 1)", "- index3 = S.find(c, index2 + 1)", "- if index1 != -1 and...
false
0.039947
0.040201
0.993683
[ "s808676834", "s799910428" ]
u958506960
p03495
python
s453163880
s418999576
219
79
49,020
35,996
Accepted
Accepted
63.93
n, k = list(map(int, input().split())) a = list(map(int, input().split())) if len(set(a)) == k: print((0)) exit() d = {} for i in a: if i in d: d[i] += 1 else: d[i] = 1 s = sorted(list(d.items()), key=lambda x:x[1]) ans = 0 for j in range(len(s) - k): ans += s[j][1] print(ans)
from collections import Counter n, k = list(map(int, input().split())) a = input().split() c = sorted(list(Counter(a).values()), reverse=True) print((max(0, sum(c[k:]))))
19
7
320
164
n, k = list(map(int, input().split())) a = list(map(int, input().split())) if len(set(a)) == k: print((0)) exit() d = {} for i in a: if i in d: d[i] += 1 else: d[i] = 1 s = sorted(list(d.items()), key=lambda x: x[1]) ans = 0 for j in range(len(s) - k): ans += s[j][1] print(ans)
from collections import Counter n, k = list(map(int, input().split())) a = input().split() c = sorted(list(Counter(a).values()), reverse=True) print((max(0, sum(c[k:]))))
false
63.157895
[ "+from collections import Counter", "+", "-a = list(map(int, input().split()))", "-if len(set(a)) == k:", "- print((0))", "- exit()", "-d = {}", "-for i in a:", "- if i in d:", "- d[i] += 1", "- else:", "- d[i] = 1", "-s = sorted(list(d.items()), key=lambda x: x[1])...
false
0.043559
0.034312
1.269502
[ "s453163880", "s418999576" ]
u519939795
p03073
python
s935762738
s838571985
91
69
4,852
3,188
Accepted
Accepted
24.18
s=eval(input()) a=[] b=[] for i in range(len(s)): if i%2==0: a.append('0') else: a.append('1') for j in range(len(s)): if j%2==1: b.append('0') else: b.append('1') ans1=0 ans2=0 for k in range(len(a)): if a[k]!=s[k]: ans1+=1 for z in range(len(b)): if b[z]!=s[z]: ans2+=1 print((min(ans1,ans2)))
S = eval(input()) C = ["0","1"] count1=count2=0 for i in range(len(S)): # case 1 if S[i] == C[i%2]: count1+=1 # case 2 if S[i] == C[(i+1)%2]: count2+=1 print((min([count1, count2])))
22
13
380
206
s = eval(input()) a = [] b = [] for i in range(len(s)): if i % 2 == 0: a.append("0") else: a.append("1") for j in range(len(s)): if j % 2 == 1: b.append("0") else: b.append("1") ans1 = 0 ans2 = 0 for k in range(len(a)): if a[k] != s[k]: ans1 += 1 for z in range(len(b)): if b[z] != s[z]: ans2 += 1 print((min(ans1, ans2)))
S = eval(input()) C = ["0", "1"] count1 = count2 = 0 for i in range(len(S)): # case 1 if S[i] == C[i % 2]: count1 += 1 # case 2 if S[i] == C[(i + 1) % 2]: count2 += 1 print((min([count1, count2])))
false
40.909091
[ "-s = eval(input())", "-a = []", "-b = []", "-for i in range(len(s)):", "- if i % 2 == 0:", "- a.append(\"0\")", "- else:", "- a.append(\"1\")", "-for j in range(len(s)):", "- if j % 2 == 1:", "- b.append(\"0\")", "- else:", "- b.append(\"1\")", "-an...
false
0.045477
0.044207
1.028708
[ "s935762738", "s838571985" ]
u845643816
p02241
python
s089812771
s396024342
40
20
6,292
6,116
Accepted
Accepted
50
n = int(eval(input())) edgeArray = [list(map(int, input().split())) for i in range(n)] edgeList = [] rootList = [-1 for i in range(n)] sumLength = 0 def getRoot(x): r = rootList[x] if r < 0: rootList[x] = x elif r != x: rootList[x] = getRoot(r) return rootList[x] for i in range(n): for j in range(i): if edgeArray[i][j] != -1: edgeList.append([edgeArray[i][j], i, j]) edgeList.sort(key=lambda x: x[0]) for e in edgeList: x = getRoot(e[1]) y = getRoot(e[2]) if x != y: sumLength += e[0] rootList[x] = rootList[y] = min(x, y) print(sumLength)
n = int(eval(input())) edgeList = [] for i in range(n): a = list(map(int, input().split())) for j in range(i): if a[j] != -1: edgeList.append([a[j], i, j]) rootList = [-1 for i in range(n)] sumLength = 0 def getRoot(x): r = rootList[x] if r < 0: rootList[x] = x elif r != x: rootList[x] = getRoot(r) return rootList[x] edgeList.sort(key=lambda x: x[0]) for e in edgeList: x = getRoot(e[1]) y = getRoot(e[2]) if x != y: sumLength += e[0] rootList[x] = rootList[y] = min(x, y) print(sumLength)
26
27
654
610
n = int(eval(input())) edgeArray = [list(map(int, input().split())) for i in range(n)] edgeList = [] rootList = [-1 for i in range(n)] sumLength = 0 def getRoot(x): r = rootList[x] if r < 0: rootList[x] = x elif r != x: rootList[x] = getRoot(r) return rootList[x] for i in range(n): for j in range(i): if edgeArray[i][j] != -1: edgeList.append([edgeArray[i][j], i, j]) edgeList.sort(key=lambda x: x[0]) for e in edgeList: x = getRoot(e[1]) y = getRoot(e[2]) if x != y: sumLength += e[0] rootList[x] = rootList[y] = min(x, y) print(sumLength)
n = int(eval(input())) edgeList = [] for i in range(n): a = list(map(int, input().split())) for j in range(i): if a[j] != -1: edgeList.append([a[j], i, j]) rootList = [-1 for i in range(n)] sumLength = 0 def getRoot(x): r = rootList[x] if r < 0: rootList[x] = x elif r != x: rootList[x] = getRoot(r) return rootList[x] edgeList.sort(key=lambda x: x[0]) for e in edgeList: x = getRoot(e[1]) y = getRoot(e[2]) if x != y: sumLength += e[0] rootList[x] = rootList[y] = min(x, y) print(sumLength)
false
3.703704
[ "-edgeArray = [list(map(int, input().split())) for i in range(n)]", "+for i in range(n):", "+ a = list(map(int, input().split()))", "+ for j in range(i):", "+ if a[j] != -1:", "+ edgeList.append([a[j], i, j])", "-for i in range(n):", "- for j in range(i):", "- if ed...
false
0.067836
0.072062
0.941354
[ "s089812771", "s396024342" ]
u190079347
p02837
python
s766618769
s443003057
1,062
276
3,064
3,064
Accepted
Accepted
74.01
n = int(eval(input())) A = [] xy = [] max = 0 for i in range(n): a = int(eval(input())) A.append(a) xy.append([list(map(int,input().split())) for i in range(a)]) for i in range(2**n): ls = [0]*n check = 0 for j in range(len(ls)): if (i >> j) & 1: ls[j] = 1 for p in range(len(xy)): for t in xy[p]: if t[1] == 1 and ls[p] == 1: if ls[t[0]-1] != 1: check = 1 break elif t[1] == 0 and ls[p] == 1: if ls[t[0]-1] != 0: check = 1 break if check == 0: if ls.count(1) > max: max = ls.count(1) print(max)
n = int(eval(input())) A = [] xy = [] max = 0 for i in range(n): a = int(eval(input())) A.append(a) xy.append([list(map(int,input().split())) for i in range(a)]) for i in range(2**n): ls = [0]*n check = 0 for j in range(len(ls)): if (i >> j) & 1: ls[j] = 1 for p in range(len(xy)): for t in xy[p]: if t[1] == 1 and ls[p] == 1: if ls[t[0]-1] != 1: check = 1 break elif t[1] == 0 and ls[p] == 1: if ls[t[0]-1] != 0: check = 1 break else: continue break if check == 0: if ls.count(1) > max: max = ls.count(1) print(max)
28
31
661
705
n = int(eval(input())) A = [] xy = [] max = 0 for i in range(n): a = int(eval(input())) A.append(a) xy.append([list(map(int, input().split())) for i in range(a)]) for i in range(2**n): ls = [0] * n check = 0 for j in range(len(ls)): if (i >> j) & 1: ls[j] = 1 for p in range(len(xy)): for t in xy[p]: if t[1] == 1 and ls[p] == 1: if ls[t[0] - 1] != 1: check = 1 break elif t[1] == 0 and ls[p] == 1: if ls[t[0] - 1] != 0: check = 1 break if check == 0: if ls.count(1) > max: max = ls.count(1) print(max)
n = int(eval(input())) A = [] xy = [] max = 0 for i in range(n): a = int(eval(input())) A.append(a) xy.append([list(map(int, input().split())) for i in range(a)]) for i in range(2**n): ls = [0] * n check = 0 for j in range(len(ls)): if (i >> j) & 1: ls[j] = 1 for p in range(len(xy)): for t in xy[p]: if t[1] == 1 and ls[p] == 1: if ls[t[0] - 1] != 1: check = 1 break elif t[1] == 0 and ls[p] == 1: if ls[t[0] - 1] != 0: check = 1 break else: continue break if check == 0: if ls.count(1) > max: max = ls.count(1) print(max)
false
9.677419
[ "+ else:", "+ continue", "+ break" ]
false
0.041318
0.044051
0.937952
[ "s766618769", "s443003057" ]
u860002137
p02647
python
s392596635
s786666230
1,072
874
123,956
124,384
Accepted
Accepted
18.47
import numpy as np from numba import njit, i8 n, k = list(map(int, input().split())) arr = np.array(list(map(int, input().split()))) @njit(i8[:](i8, i8, i8[:]), cache=True) def solve(n, k, arr): for i in range(min(k, 50)): tmp_arr = np.zeros(n + 2, np.int64) for i, power in enumerate(arr): tmp_arr[max(0, i - power + 1)] += 1 tmp_arr[min(n + 1, i + power + 2)] -= 1 arr = np.cumsum(tmp_arr)[1:-1] return arr print((*solve(n, k, arr)))
import numpy as np from numba import njit, i8 n, k = list(map(int, input().split())) arr = np.array(list(map(int, input().split()))) @njit(i8[:](i8, i8, i8[:]), cache=True) def solve(n, k, arr): for i in range(min(k, 50)): tmp_arr = np.zeros(n + 1, np.int64) for i, power in enumerate(arr): tmp_arr[max(0, i - power)] += 1 tmp_arr[min(n, i + power + 1)] -= 1 arr = np.cumsum(tmp_arr)[:-1] return arr print((*solve(n, k, arr)))
19
19
506
497
import numpy as np from numba import njit, i8 n, k = list(map(int, input().split())) arr = np.array(list(map(int, input().split()))) @njit(i8[:](i8, i8, i8[:]), cache=True) def solve(n, k, arr): for i in range(min(k, 50)): tmp_arr = np.zeros(n + 2, np.int64) for i, power in enumerate(arr): tmp_arr[max(0, i - power + 1)] += 1 tmp_arr[min(n + 1, i + power + 2)] -= 1 arr = np.cumsum(tmp_arr)[1:-1] return arr print((*solve(n, k, arr)))
import numpy as np from numba import njit, i8 n, k = list(map(int, input().split())) arr = np.array(list(map(int, input().split()))) @njit(i8[:](i8, i8, i8[:]), cache=True) def solve(n, k, arr): for i in range(min(k, 50)): tmp_arr = np.zeros(n + 1, np.int64) for i, power in enumerate(arr): tmp_arr[max(0, i - power)] += 1 tmp_arr[min(n, i + power + 1)] -= 1 arr = np.cumsum(tmp_arr)[:-1] return arr print((*solve(n, k, arr)))
false
0
[ "- tmp_arr = np.zeros(n + 2, np.int64)", "+ tmp_arr = np.zeros(n + 1, np.int64)", "- tmp_arr[max(0, i - power + 1)] += 1", "- tmp_arr[min(n + 1, i + power + 2)] -= 1", "- arr = np.cumsum(tmp_arr)[1:-1]", "+ tmp_arr[max(0, i - power)] += 1", "+ ...
false
0.210477
0.220467
0.95469
[ "s392596635", "s786666230" ]
u476604182
p03142
python
s685860172
s420455188
248
225
37,228
36,844
Accepted
Accepted
9.27
from collections import defaultdict, deque def main(): N, M, *L = list(map(int, open(0).read().split())) dic = defaultdict(list) par = [None]*N cnt = [0]*(N+1) cnt[0] = 1 for a,b in zip(*[iter(L)]*2): dic[a].append(b) cnt[b] += 1 for i, m in enumerate(cnt): if m==0: q = deque([i]) par[i-1] = '0' break while q: m = q.popleft() for c in dic[m]: cnt[c] -= 1 if cnt[c]==0: par[c-1] = str(m) q.append(c) ans = '\n'.join(par) print(ans) if __name__== '__main__': main()
from collections import defaultdict, deque def main(): N, M, *L = list(map(int, open(0).read().split())) dic = defaultdict(list) par = [None]*N cnt = [0]*(N+1) cnt[0] = 1 for a,b in zip(*[iter(L)]*2): dic[a].append(b) cnt[b] += 1 for i, m in enumerate(cnt): if m==0: q = deque([i]) par[i-1] = 0 break while q: m = q.popleft() for c in dic[m]: cnt[c] -= 1 if cnt[c]==0: par[c-1] = m q.append(c) ans = '\n'.join(map(str,par)) print(ans) if __name__== '__main__': main()
30
30
586
588
from collections import defaultdict, deque def main(): N, M, *L = list(map(int, open(0).read().split())) dic = defaultdict(list) par = [None] * N cnt = [0] * (N + 1) cnt[0] = 1 for a, b in zip(*[iter(L)] * 2): dic[a].append(b) cnt[b] += 1 for i, m in enumerate(cnt): if m == 0: q = deque([i]) par[i - 1] = "0" break while q: m = q.popleft() for c in dic[m]: cnt[c] -= 1 if cnt[c] == 0: par[c - 1] = str(m) q.append(c) ans = "\n".join(par) print(ans) if __name__ == "__main__": main()
from collections import defaultdict, deque def main(): N, M, *L = list(map(int, open(0).read().split())) dic = defaultdict(list) par = [None] * N cnt = [0] * (N + 1) cnt[0] = 1 for a, b in zip(*[iter(L)] * 2): dic[a].append(b) cnt[b] += 1 for i, m in enumerate(cnt): if m == 0: q = deque([i]) par[i - 1] = 0 break while q: m = q.popleft() for c in dic[m]: cnt[c] -= 1 if cnt[c] == 0: par[c - 1] = m q.append(c) ans = "\n".join(map(str, par)) print(ans) if __name__ == "__main__": main()
false
0
[ "- par[i - 1] = \"0\"", "+ par[i - 1] = 0", "- par[c - 1] = str(m)", "+ par[c - 1] = m", "- ans = \"\\n\".join(par)", "+ ans = \"\\n\".join(map(str, par))" ]
false
0.04662
0.043907
1.061811
[ "s685860172", "s420455188" ]
u987164499
p03469
python
s510264997
s829478567
149
17
12,248
2,940
Accepted
Accepted
88.59
from sys import stdin from itertools import combinations from math import factorial import numpy as np import math s = stdin.readline().rstrip() print((s.replace("2017","2018")))
s = eval(input()) print(("2018"+s[4:]))
9
3
186
34
from sys import stdin from itertools import combinations from math import factorial import numpy as np import math s = stdin.readline().rstrip() print((s.replace("2017", "2018")))
s = eval(input()) print(("2018" + s[4:]))
false
66.666667
[ "-from sys import stdin", "-from itertools import combinations", "-from math import factorial", "-import numpy as np", "-import math", "-", "-s = stdin.readline().rstrip()", "-print((s.replace(\"2017\", \"2018\")))", "+s = eval(input())", "+print((\"2018\" + s[4:]))" ]
false
0.043137
0.043755
0.985887
[ "s510264997", "s829478567" ]
u585482323
p03806
python
s768879508
s529217668
1,394
239
55,644
45,020
Accepted
Accepted
82.86
#!usr/bin/env python3 from collections import defaultdict, deque from heapq import heappush, heappop from itertools import permutations, accumulate import sys import math import bisect def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()] def I(): return int(sys.stdin.buffer.readline()) def LS():return [list(x) for x in sys.stdin.readline().split()] def S(): res = list(sys.stdin.readline()) if res[-1] == "\n": return res[:-1] return res def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] sys.setrecursionlimit(1000000) mod = 1000000007 def solve(): n,A,B = LI() G = LIR(n) n1 = n>>1 n2 = n-n1 s1 = defaultdict(lambda : float("inf")) s2 = defaultdict(lambda : float("inf")) for j in range(1<<n1): sa = 0 sb = 0 sc = 0 for i in range(n1): if j&(1<<i): a,b,c = G[i] sa += a sb += b sc += c if s1[(sa,sb)] > sc: s1[(sa,sb)] = sc m = 1 for j in range(1<<n2): sa = 0 sb = 0 sc = 0 for i in range(n2): if j&(1<<i): a,b,c = G[i+n1] sa += a sb += b sc += c if sa > m: m = sa if s2[(sa,sb)] > sc: s2[(sa,sb)] = sc ans = float("inf") for (a,b),c in list(s1.items()): for i in range(m+1): s = B*(i+a) if s%A: continue j = (s//A)-b nc = s2[(i,j)] cost = c+nc if a == b == i == j: continue if cost < ans: ans = cost if ans == float("inf"): print((-1)) return print(ans) return #Solve if __name__ == "__main__": solve()
#!usr/bin/env python3 from collections import defaultdict, deque from heapq import heappush, heappop from itertools import permutations, accumulate import sys import math import bisect def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()] def I(): return int(sys.stdin.buffer.readline()) def LS():return [list(x) for x in sys.stdin.readline().split()] def S(): res = list(sys.stdin.readline()) if res[-1] == "\n": return res[:-1] return res def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] sys.setrecursionlimit(1000000) mod = 1000000007 def solve(): n,A,B = LI() G = LIR(n) ma = sum([a for (a,_,_) in G]) mb = sum([b for (_,b,_) in G]) dp = [[float("inf")]*(mb+1) for i in range(ma+1)] dp[0][0] = 0 for a,b,c in G: for sa in range(ma)[::-1]: for sb in range(mb)[::-1]: na = sa+a if na > ma: continue nb = sb+b if nb > mb: continue nd = dp[sa][sb]+c if nd < dp[na][nb]: dp[na][nb] = nd ans = float("inf") for i in range(1,ma+1): s = B*i if s%A: continue j = B*i//A if j > mb: continue if dp[i][j] < ans: ans = dp[i][j] if ans == float("inf"): print((-1)) return print(ans) return #Solve if __name__ == "__main__": solve()
83
65
2,052
1,683
#!usr/bin/env python3 from collections import defaultdict, deque from heapq import heappush, heappop from itertools import permutations, accumulate import sys import math import bisect def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()] def I(): return int(sys.stdin.buffer.readline()) def LS(): return [list(x) for x in sys.stdin.readline().split()] def S(): res = list(sys.stdin.readline()) if res[-1] == "\n": return res[:-1] return res def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] sys.setrecursionlimit(1000000) mod = 1000000007 def solve(): n, A, B = LI() G = LIR(n) n1 = n >> 1 n2 = n - n1 s1 = defaultdict(lambda: float("inf")) s2 = defaultdict(lambda: float("inf")) for j in range(1 << n1): sa = 0 sb = 0 sc = 0 for i in range(n1): if j & (1 << i): a, b, c = G[i] sa += a sb += b sc += c if s1[(sa, sb)] > sc: s1[(sa, sb)] = sc m = 1 for j in range(1 << n2): sa = 0 sb = 0 sc = 0 for i in range(n2): if j & (1 << i): a, b, c = G[i + n1] sa += a sb += b sc += c if sa > m: m = sa if s2[(sa, sb)] > sc: s2[(sa, sb)] = sc ans = float("inf") for (a, b), c in list(s1.items()): for i in range(m + 1): s = B * (i + a) if s % A: continue j = (s // A) - b nc = s2[(i, j)] cost = c + nc if a == b == i == j: continue if cost < ans: ans = cost if ans == float("inf"): print((-1)) return print(ans) return # Solve if __name__ == "__main__": solve()
#!usr/bin/env python3 from collections import defaultdict, deque from heapq import heappush, heappop from itertools import permutations, accumulate import sys import math import bisect def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()] def I(): return int(sys.stdin.buffer.readline()) def LS(): return [list(x) for x in sys.stdin.readline().split()] def S(): res = list(sys.stdin.readline()) if res[-1] == "\n": return res[:-1] return res def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] sys.setrecursionlimit(1000000) mod = 1000000007 def solve(): n, A, B = LI() G = LIR(n) ma = sum([a for (a, _, _) in G]) mb = sum([b for (_, b, _) in G]) dp = [[float("inf")] * (mb + 1) for i in range(ma + 1)] dp[0][0] = 0 for a, b, c in G: for sa in range(ma)[::-1]: for sb in range(mb)[::-1]: na = sa + a if na > ma: continue nb = sb + b if nb > mb: continue nd = dp[sa][sb] + c if nd < dp[na][nb]: dp[na][nb] = nd ans = float("inf") for i in range(1, ma + 1): s = B * i if s % A: continue j = B * i // A if j > mb: continue if dp[i][j] < ans: ans = dp[i][j] if ans == float("inf"): print((-1)) return print(ans) return # Solve if __name__ == "__main__": solve()
false
21.686747
[ "- n1 = n >> 1", "- n2 = n - n1", "- s1 = defaultdict(lambda: float(\"inf\"))", "- s2 = defaultdict(lambda: float(\"inf\"))", "- for j in range(1 << n1):", "- sa = 0", "- sb = 0", "- sc = 0", "- for i in range(n1):", "- if j & (1 << i):", "- ...
false
0.085362
0.045156
1.890368
[ "s768879508", "s529217668" ]
u285443936
p02915
python
s795864070
s990916659
164
17
38,384
2,940
Accepted
Accepted
89.63
N = int(eval(input())) print((N**3))
num = int(eval(input())) print((num ** 3))
3
3
31
37
N = int(eval(input())) print((N**3))
num = int(eval(input())) print((num**3))
false
0
[ "-N = int(eval(input()))", "-print((N**3))", "+num = int(eval(input()))", "+print((num**3))" ]
false
0.091795
0.042412
2.164356
[ "s795864070", "s990916659" ]
u600402037
p02995
python
s517394845
s543065114
36
17
5,048
3,064
Accepted
Accepted
52.78
from fractions import gcd a,b,c,d=list(map(int,input().split())) count=0 x=b-a+1 def cal(x): return x//c+x//d-x//(c*d//gcd(c,d)) print((b-a+1-(cal(b)-cal(a-1))))
import sys sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) def gcd(a, b): #最大公約数 while b: a, b = b, a%b return a A, B, C, D = lr() cnt_divided_C = B // C - (A-1) // C cnt_divided_D = B // D - (A-1) // D x = C * D // gcd(C, D) cnt_divided_CD = B // x - (A-1) // x answer = B - (A-1) - (cnt_divided_C + cnt_divided_D - cnt_divided_CD) print(answer)
7
18
164
442
from fractions import gcd a, b, c, d = list(map(int, input().split())) count = 0 x = b - a + 1 def cal(x): return x // c + x // d - x // (c * d // gcd(c, d)) print((b - a + 1 - (cal(b) - cal(a - 1))))
import sys sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) def gcd(a, b): # 最大公約数 while b: a, b = b, a % b return a A, B, C, D = lr() cnt_divided_C = B // C - (A - 1) // C cnt_divided_D = B // D - (A - 1) // D x = C * D // gcd(C, D) cnt_divided_CD = B // x - (A - 1) // x answer = B - (A - 1) - (cnt_divided_C + cnt_divided_D - cnt_divided_CD) print(answer)
false
61.111111
[ "-from fractions import gcd", "+import sys", "-a, b, c, d = list(map(int, input().split()))", "-count = 0", "-x = b - a + 1", "+sr = lambda: sys.stdin.readline().rstrip()", "+ir = lambda: int(sr())", "+lr = lambda: list(map(int, sr().split()))", "-def cal(x):", "- return x // c + x // d - x // ...
false
0.062292
0.047375
1.314864
[ "s517394845", "s543065114" ]
u119982001
p02923
python
s482756431
s541264305
218
91
63,856
15,020
Accepted
Accepted
58.26
#Lower N = int(eval(input())) H = list(map(int, input().split())) max = 0 n=0 for i in range(N-1): if H[i] >= H[i+1]: n = n+1 else : n = 0 if n > max: max = n print(max)
N = int(eval(input())) H = list(map(int,input().split())) ans = 0 ctr = 0 for i in range(N-1): if H[i] >= H[i+1]: ctr += 1 else: ctr = 0 ans = max(ans, ctr) print(ans)
15
15
216
208
# Lower N = int(eval(input())) H = list(map(int, input().split())) max = 0 n = 0 for i in range(N - 1): if H[i] >= H[i + 1]: n = n + 1 else: n = 0 if n > max: max = n print(max)
N = int(eval(input())) H = list(map(int, input().split())) ans = 0 ctr = 0 for i in range(N - 1): if H[i] >= H[i + 1]: ctr += 1 else: ctr = 0 ans = max(ans, ctr) print(ans)
false
0
[ "-# Lower", "-max = 0", "-n = 0", "+ans = 0", "+ctr = 0", "- n = n + 1", "+ ctr += 1", "- n = 0", "- if n > max:", "- max = n", "-print(max)", "+ ctr = 0", "+ ans = max(ans, ctr)", "+print(ans)" ]
false
0.034745
0.034538
1.005996
[ "s482756431", "s541264305" ]
u796942881
p03721
python
s570216921
s259218261
269
223
29,076
29,868
Accepted
Accepted
17.1
from sys import stdin def main(): lines = stdin.readlines() N, K = list(map(int, lines[0].split())) abn = [[int(abi) for abi in line.split()] for line in lines[1:]] abn.sort() cnt = 0 for ai, bi in abn: cnt += bi if K <= cnt: print(ai) break return main()
from sys import stdin from operator import itemgetter def main(): lines = stdin.readlines() N, K = list(map(int, lines[0].split())) abn = [[int(abi) for abi in line.split()] for line in lines[1:]] abn.sort(key=itemgetter(0)) cnt = 0 for ai, bi in abn: cnt += bi if K <= cnt: print(ai) break return main()
18
19
339
389
from sys import stdin def main(): lines = stdin.readlines() N, K = list(map(int, lines[0].split())) abn = [[int(abi) for abi in line.split()] for line in lines[1:]] abn.sort() cnt = 0 for ai, bi in abn: cnt += bi if K <= cnt: print(ai) break return main()
from sys import stdin from operator import itemgetter def main(): lines = stdin.readlines() N, K = list(map(int, lines[0].split())) abn = [[int(abi) for abi in line.split()] for line in lines[1:]] abn.sort(key=itemgetter(0)) cnt = 0 for ai, bi in abn: cnt += bi if K <= cnt: print(ai) break return main()
false
5.263158
[ "+from operator import itemgetter", "- abn.sort()", "+ abn.sort(key=itemgetter(0))" ]
false
0.071284
0.044353
1.60722
[ "s570216921", "s259218261" ]
u181801282
p03816
python
s207876460
s328346025
78
44
20,336
14,396
Accepted
Accepted
43.59
N=int(eval(input())) A=list(map(int,input().split())) S={} for i in range(N): if A[i] in S: S[A[i]]+=1 else: S[A[i]]=1 d=0 for i in list(S.values()): d+=(i-1) print((len(set(A))-d%2))
N=int(eval(input())) K=len(set(list(map(int,input().split())))) if K%2==0: print((K-1)) else: print(K)
10
4
184
97
N = int(eval(input())) A = list(map(int, input().split())) S = {} for i in range(N): if A[i] in S: S[A[i]] += 1 else: S[A[i]] = 1 d = 0 for i in list(S.values()): d += i - 1 print((len(set(A)) - d % 2))
N = int(eval(input())) K = len(set(list(map(int, input().split())))) if K % 2 == 0: print((K - 1)) else: print(K)
false
60
[ "-A = list(map(int, input().split()))", "-S = {}", "-for i in range(N):", "- if A[i] in S:", "- S[A[i]] += 1", "- else:", "- S[A[i]] = 1", "-d = 0", "-for i in list(S.values()):", "- d += i - 1", "-print((len(set(A)) - d % 2))", "+K = len(set(list(map(int, input().split(...
false
0.088469
0.1057
0.836977
[ "s207876460", "s328346025" ]
u102461423
p02939
python
s149932297
s211356438
397
314
19,184
19,184
Accepted
Accepted
20.91
import sys input = sys.stdin.readline sys.setrecursionlimit(10 ** 7) S = input().rstrip() if len(S) == 1: print((1)) exit() # n文字目を最後に長さ1,2で見る INF = 10 ** 10 dp_1 = [-INF] * (len(S)) dp_2 = [-INF] * (len(S)) dp_1[0] = 1 dp_2[1] = 1 if S[0] != S[1]: dp_1[1] = 2 for i,s in enumerate(S[2:],2): # 2文字→1文字 x = dp_2[i-1] + 1 # 1文字→1文字 if S[i-1] != S[i]: x = max(x,dp_1[i-1] + 1) dp_1[i] = x # 1文字→2文字 x = dp_1[i-2] + 1 # 2文字→2文字 if S[i-3:i-1] != S[i-1:i+1]: x = max(x,dp_2[i-2] + 1) dp_2[i] = x answer = max(dp_1[-1], dp_2[-1]) print(answer)
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines # 長さ3以上は使わないとしてよい S = '$$' + read().rstrip().decode('utf-8') # 最後の長さ -> 文字列の個数 N = len(S) INF = 10 ** 9 one = [-INF] * N; one[1] = 0 two = [-INF] * N; two[1] = 0 for i in range(2,N): # 2 -> 1 x = two[i-1] + 1 # 1 -> 1 if S[i] != S[i-1]: y = one[i-1] + 1 if x < y: x = y one[i] = x # 1 -> 2 x = one[i-2] + 1 # 2 -> 2 if S[i-1:i+1] != S[i-3:i-1]: y = two[i-2] + 1 if x < y: x = y two[i] = x answer = max(one[-1],two[-1]) print(answer)
37
35
649
683
import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) S = input().rstrip() if len(S) == 1: print((1)) exit() # n文字目を最後に長さ1,2で見る INF = 10**10 dp_1 = [-INF] * (len(S)) dp_2 = [-INF] * (len(S)) dp_1[0] = 1 dp_2[1] = 1 if S[0] != S[1]: dp_1[1] = 2 for i, s in enumerate(S[2:], 2): # 2文字→1文字 x = dp_2[i - 1] + 1 # 1文字→1文字 if S[i - 1] != S[i]: x = max(x, dp_1[i - 1] + 1) dp_1[i] = x # 1文字→2文字 x = dp_1[i - 2] + 1 # 2文字→2文字 if S[i - 3 : i - 1] != S[i - 1 : i + 1]: x = max(x, dp_2[i - 2] + 1) dp_2[i] = x answer = max(dp_1[-1], dp_2[-1]) print(answer)
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines # 長さ3以上は使わないとしてよい S = "$$" + read().rstrip().decode("utf-8") # 最後の長さ -> 文字列の個数 N = len(S) INF = 10**9 one = [-INF] * N one[1] = 0 two = [-INF] * N two[1] = 0 for i in range(2, N): # 2 -> 1 x = two[i - 1] + 1 # 1 -> 1 if S[i] != S[i - 1]: y = one[i - 1] + 1 if x < y: x = y one[i] = x # 1 -> 2 x = one[i - 2] + 1 # 2 -> 2 if S[i - 1 : i + 1] != S[i - 3 : i - 1]: y = two[i - 2] + 1 if x < y: x = y two[i] = x answer = max(one[-1], two[-1]) print(answer)
false
5.405405
[ "-input = sys.stdin.readline", "-sys.setrecursionlimit(10**7)", "-S = input().rstrip()", "-if len(S) == 1:", "- print((1))", "- exit()", "-# n文字目を最後に長さ1,2で見る", "-INF = 10**10", "-dp_1 = [-INF] * (len(S))", "-dp_2 = [-INF] * (len(S))", "-dp_1[0] = 1", "-dp_2[1] = 1", "-if S[0] != S[1]:"...
false
0.196363
0.107859
1.820551
[ "s149932297", "s211356438" ]
u484229314
p02762
python
s867747570
s667460451
885
657
31,880
15,508
Accepted
Accepted
25.76
class UnionFind: """ size の要素数の UnionFind を管理する data 中の負数の要素が根となる """ def __init__(self, size): # 根は子を含む集合のデータ数を負数でもつ self.data = [-1] * size def merge(self, x, y): x = self.root(x) y = self.root(y) if x == y: return False # y の方がデータ数を多く if self.data[x] < self.data[y]: x, y = y, x # y に x をつなげる self.data[y] += self.data[x] self.data[x] = y return True def root(self, x): if self.data[x] < 0: return x self.data[x] = self.root(self.data[x]) return self.data[x] def size(self, x): """ 根は負数でデータ数を管理しているのでそれを返す """ return -self.data[self.root(x)] N, M, K = [int(_) for _ in input().split()] MG = [0] * (N + 1) uf = UnionFind(N + 1) for i in range(M): a, b = [int(_) for _ in input().split()] uf.merge(a, b) MG[a] += 1 MG[b] += 1 KG = [[] for _ in range(N + 1)] for i in range(K): a, b = [int(_) for _ in input().split()] KG[a].append(b) KG[b].append(a) res = [0]*(N) for i in range(1,N+1): cnt = uf.size(i) - MG[i]-1 for k in KG[i]: if uf.root(i)==uf.root(k): cnt-=1 res[i-1] =cnt print((*res))
class UnionFind: """ size の要素数の UnionFind を管理する data 中の負数の要素が根となる """ def __init__(self, size): # 根は子を含む集合のデータ数を負数でもつ self.data = [-1] * size def merge(self, x, y): x = self.root(x) y = self.root(y) if x == y: return False # y の方がデータ数を多く if self.data[x] < self.data[y]: x, y = y, x # y に x をつなげる self.data[y] += self.data[x] self.data[x] = y return True def root(self, x): if self.data[x] < 0: return x self.data[x] = self.root(self.data[x]) return self.data[x] def size(self, x): """ 根は負数でデータ数を管理しているのでそれを返す """ return -self.data[self.root(x)] N, M, K = [int(_) for _ in input().split()] NG = [0] * (N + 1) uf = UnionFind(N + 1) for i in range(M): a, b = [int(_) for _ in input().split()] uf.merge(a, b) NG[a] += 1 NG[b] += 1 # KG = [[] for _ in range(N + 1)] for i in range(K): a, b = [int(_) for _ in input().split()] if uf.root(a) == uf.root(b): NG[a] += 1 NG[b] += 1 res = [0] * (N) for i in range(1, N + 1): cnt = uf.size(i) - NG[i] - 1 res[i-1]=cnt print((*res))
60
58
1,320
1,283
class UnionFind: """ size の要素数の UnionFind を管理する data 中の負数の要素が根となる """ def __init__(self, size): # 根は子を含む集合のデータ数を負数でもつ self.data = [-1] * size def merge(self, x, y): x = self.root(x) y = self.root(y) if x == y: return False # y の方がデータ数を多く if self.data[x] < self.data[y]: x, y = y, x # y に x をつなげる self.data[y] += self.data[x] self.data[x] = y return True def root(self, x): if self.data[x] < 0: return x self.data[x] = self.root(self.data[x]) return self.data[x] def size(self, x): """ 根は負数でデータ数を管理しているのでそれを返す """ return -self.data[self.root(x)] N, M, K = [int(_) for _ in input().split()] MG = [0] * (N + 1) uf = UnionFind(N + 1) for i in range(M): a, b = [int(_) for _ in input().split()] uf.merge(a, b) MG[a] += 1 MG[b] += 1 KG = [[] for _ in range(N + 1)] for i in range(K): a, b = [int(_) for _ in input().split()] KG[a].append(b) KG[b].append(a) res = [0] * (N) for i in range(1, N + 1): cnt = uf.size(i) - MG[i] - 1 for k in KG[i]: if uf.root(i) == uf.root(k): cnt -= 1 res[i - 1] = cnt print((*res))
class UnionFind: """ size の要素数の UnionFind を管理する data 中の負数の要素が根となる """ def __init__(self, size): # 根は子を含む集合のデータ数を負数でもつ self.data = [-1] * size def merge(self, x, y): x = self.root(x) y = self.root(y) if x == y: return False # y の方がデータ数を多く if self.data[x] < self.data[y]: x, y = y, x # y に x をつなげる self.data[y] += self.data[x] self.data[x] = y return True def root(self, x): if self.data[x] < 0: return x self.data[x] = self.root(self.data[x]) return self.data[x] def size(self, x): """ 根は負数でデータ数を管理しているのでそれを返す """ return -self.data[self.root(x)] N, M, K = [int(_) for _ in input().split()] NG = [0] * (N + 1) uf = UnionFind(N + 1) for i in range(M): a, b = [int(_) for _ in input().split()] uf.merge(a, b) NG[a] += 1 NG[b] += 1 # KG = [[] for _ in range(N + 1)] for i in range(K): a, b = [int(_) for _ in input().split()] if uf.root(a) == uf.root(b): NG[a] += 1 NG[b] += 1 res = [0] * (N) for i in range(1, N + 1): cnt = uf.size(i) - NG[i] - 1 res[i - 1] = cnt print((*res))
false
3.333333
[ "-MG = [0] * (N + 1)", "+NG = [0] * (N + 1)", "- MG[a] += 1", "- MG[b] += 1", "-KG = [[] for _ in range(N + 1)]", "+ NG[a] += 1", "+ NG[b] += 1", "+# KG = [[] for _ in range(N + 1)]", "- KG[a].append(b)", "- KG[b].append(a)", "+ if uf.root(a) == uf.root(b):", "+ NG[...
false
0.039425
0.039219
1.005235
[ "s867747570", "s667460451" ]
u546338822
p03043
python
s368551659
s823527285
53
39
2,940
9,356
Accepted
Accepted
26.42
n,k = list(map(int,input().split())) ans = 0 for s in range(1,n+1): r = s i = 0 while r < k: r = r*2 i = i+1 ans += (0.5**i)/n print(ans)
def main(): n,k = list(map(int,input().split())) ans = 0 for i in range(1,n+1): c = 0 while i<k: i = i*2 c += 1 ans += 1/n * (1/2)**c print(ans) if __name__ == "__main__": main()
11
13
174
254
n, k = list(map(int, input().split())) ans = 0 for s in range(1, n + 1): r = s i = 0 while r < k: r = r * 2 i = i + 1 ans += (0.5**i) / n print(ans)
def main(): n, k = list(map(int, input().split())) ans = 0 for i in range(1, n + 1): c = 0 while i < k: i = i * 2 c += 1 ans += 1 / n * (1 / 2) ** c print(ans) if __name__ == "__main__": main()
false
15.384615
[ "-n, k = list(map(int, input().split()))", "-ans = 0", "-for s in range(1, n + 1):", "- r = s", "- i = 0", "- while r < k:", "- r = r * 2", "- i = i + 1", "- ans += (0.5**i) / n", "-print(ans)", "+def main():", "+ n, k = list(map(int, input().split()))", "+ an...
false
0.084446
0.046293
1.824147
[ "s368551659", "s823527285" ]
u285443936
p03037
python
s572042157
s295231726
354
166
3,060
3,064
Accepted
Accepted
53.11
N, M = list(map(int, input().split())) Lmax = 1 Rmin = N for i in range(M): L, R = list(map(int, input().split())) Lmax = max(Lmax, L) Rmin = min(Rmin, R) if Rmin < Lmax: print((0)) exit() print((Rmin-Lmax+1))
import sys input = sys.stdin.readline N, M = list(map(int, input().split())) L, R = 0, N for i in range(M): l, r = list(map(int,input().split())) L = max(L, l) R = min(R, r) if L > R: print((0)) exit() print((R-L+1))
12
13
221
229
N, M = list(map(int, input().split())) Lmax = 1 Rmin = N for i in range(M): L, R = list(map(int, input().split())) Lmax = max(Lmax, L) Rmin = min(Rmin, R) if Rmin < Lmax: print((0)) exit() print((Rmin - Lmax + 1))
import sys input = sys.stdin.readline N, M = list(map(int, input().split())) L, R = 0, N for i in range(M): l, r = list(map(int, input().split())) L = max(L, l) R = min(R, r) if L > R: print((0)) exit() print((R - L + 1))
false
7.692308
[ "+import sys", "+", "+input = sys.stdin.readline", "-Lmax = 1", "-Rmin = N", "+L, R = 0, N", "- L, R = list(map(int, input().split()))", "- Lmax = max(Lmax, L)", "- Rmin = min(Rmin, R)", "- if Rmin < Lmax:", "+ l, r = list(map(int, input().split()))", "+ L = max(L, l)", "+ ...
false
0.076158
0.039851
1.91107
[ "s572042157", "s295231726" ]
u832039789
p03478
python
s064937558
s051547908
37
31
3,060
2,940
Accepted
Accepted
16.22
def digitsum(n): res = 0 for i in range(5): res += (n//10**i)%10 return res n,a,b=list(map(int,input().split())) res=0 for i in range(1,n+1): if a<=digitsum(i)<=b: res += i print(res)
n,a,b = list(map(int,input().split())) def digitsum(num): s = str(num) r = 0 for c in s: r += int(c) return r res = 0 for i in range(1,n+1): if a<=digitsum(i)<=b: res += i print(res)
11
14
219
228
def digitsum(n): res = 0 for i in range(5): res += (n // 10**i) % 10 return res n, a, b = list(map(int, input().split())) res = 0 for i in range(1, n + 1): if a <= digitsum(i) <= b: res += i print(res)
n, a, b = list(map(int, input().split())) def digitsum(num): s = str(num) r = 0 for c in s: r += int(c) return r res = 0 for i in range(1, n + 1): if a <= digitsum(i) <= b: res += i print(res)
false
21.428571
[ "-def digitsum(n):", "- res = 0", "- for i in range(5):", "- res += (n // 10**i) % 10", "- return res", "+n, a, b = list(map(int, input().split()))", "-n, a, b = list(map(int, input().split()))", "+def digitsum(num):", "+ s = str(num)", "+ r = 0", "+ for c in s:", "+ ...
false
0.082378
0.081719
1.008067
[ "s064937558", "s051547908" ]
u150984829
p02397
python
s501331906
s756446128
40
30
5,976
5,876
Accepted
Accepted
25
a=[] while 1: n=eval(input()) if n=='0 0':break a.append(n) for s in a: print((*sorted(map(int, s.split()))))
a=[] import sys for s in sys.stdin: if s=='0 0\n':break a.append(s) for t in a: x,y=map(int,t.split()) print(f'{y} {x}') if x>y else print(t.strip())
7
8
111
160
a = [] while 1: n = eval(input()) if n == "0 0": break a.append(n) for s in a: print((*sorted(map(int, s.split()))))
a = [] import sys for s in sys.stdin: if s == "0 0\n": break a.append(s) for t in a: x, y = map(int, t.split()) print(f"{y} {x}") if x > y else print(t.strip())
false
12.5
[ "-while 1:", "- n = eval(input())", "- if n == \"0 0\":", "+import sys", "+", "+for s in sys.stdin:", "+ if s == \"0 0\\n\":", "- a.append(n)", "-for s in a:", "- print((*sorted(map(int, s.split()))))", "+ a.append(s)", "+for t in a:", "+ x, y = map(int, t.split())", "...
false
0.04418
0.042433
1.041155
[ "s501331906", "s756446128" ]
u296518383
p03448
python
s718064967
s725430439
37
33
3,060
3,060
Accepted
Accepted
10.81
A, B, C, X = int(eval(input())), int(eval(input())), int(eval(input())), int(eval(input())) X //= 50 answer = 0 for a in range(A + 1): if a * 10 > X: continue for b in range(B + 1): for c in range(C + 1): if a * 10 + b * 2 + c == X: answer += 1 print(answer)
A, B, C, X = int(eval(input())), int(eval(input())), int(eval(input())), int(eval(input())) X //= 50 answer = 0 for a in range(A + 1): if a * 10 > X: continue for b in range(B + 1): if a * 10 + b * 2 > X: continue for c in range(C + 1): if a * 10 + b * 2 + c == X: answer += 1 print(answer)
13
15
274
319
A, B, C, X = ( int(eval(input())), int(eval(input())), int(eval(input())), int(eval(input())), ) X //= 50 answer = 0 for a in range(A + 1): if a * 10 > X: continue for b in range(B + 1): for c in range(C + 1): if a * 10 + b * 2 + c == X: answer += 1 print(answer)
A, B, C, X = ( int(eval(input())), int(eval(input())), int(eval(input())), int(eval(input())), ) X //= 50 answer = 0 for a in range(A + 1): if a * 10 > X: continue for b in range(B + 1): if a * 10 + b * 2 > X: continue for c in range(C + 1): if a * 10 + b * 2 + c == X: answer += 1 print(answer)
false
13.333333
[ "+ if a * 10 + b * 2 > X:", "+ continue" ]
false
0.057126
0.050967
1.12083
[ "s718064967", "s725430439" ]
u416011173
p02630
python
s922129676
s412407083
380
342
30,028
30,072
Accepted
Accepted
10
# -*- coding: utf-8 -*- # モジュールのインポート import collections # 標準入力の取得 N = int(eval(input())) A = list(map(int, input().split())) Q = int(eval(input())) B, C = [], [] for q in range(Q): B_q, C_q = list(map(int, input().split())) B.append(B_q) C.append(C_q) # 求解処理 S = sum(A) counter_A = collections.Counter(A) for b, c in zip(B, C): S += (c - b) * counter_A[b] # 結果出力 print(S) # カウンターの更新 counter_A[c] += counter_A[b] counter_A[b] = 0
# -*- coding: utf-8 -*- # モジュールのインポート import collections def get_input() -> tuple: """ 標準入力を取得する. Returns:\n tuple: 標準入力 """ # 標準入力の取得 N = int(eval(input())) A = list(map(int, input().split())) Q = int(eval(input())) B, C = [], [] for q in range(Q): B_q, C_q = list(map(int, input().split())) B.append(B_q) C.append(C_q) return N, A, Q, B, C def main(A: list, B: list, C: list) -> None: """ 求解処理. Args:\n A (list): N個の正整数からなる数列 B (list): 操作における変換前の値 C (list): 操作における変換後の値 """ # 求解処理 sum_A = sum(A) counter_A = collections.Counter(A) for b, c in zip(B, C): sum_A += (c - b) * counter_A[b] # 結果出力 print(sum_A) # カウンターの更新 counter_A[c] += counter_A[b] counter_A[b] = 0 if __name__ == "__main__": # 標準入力を取得 N, A, Q, B, C = get_input() # 求解処理 main(A, B, C)
24
52
479
996
# -*- coding: utf-8 -*- # モジュールのインポート import collections # 標準入力の取得 N = int(eval(input())) A = list(map(int, input().split())) Q = int(eval(input())) B, C = [], [] for q in range(Q): B_q, C_q = list(map(int, input().split())) B.append(B_q) C.append(C_q) # 求解処理 S = sum(A) counter_A = collections.Counter(A) for b, c in zip(B, C): S += (c - b) * counter_A[b] # 結果出力 print(S) # カウンターの更新 counter_A[c] += counter_A[b] counter_A[b] = 0
# -*- coding: utf-8 -*- # モジュールのインポート import collections def get_input() -> tuple: """ 標準入力を取得する. Returns:\n tuple: 標準入力 """ # 標準入力の取得 N = int(eval(input())) A = list(map(int, input().split())) Q = int(eval(input())) B, C = [], [] for q in range(Q): B_q, C_q = list(map(int, input().split())) B.append(B_q) C.append(C_q) return N, A, Q, B, C def main(A: list, B: list, C: list) -> None: """ 求解処理. Args:\n A (list): N個の正整数からなる数列 B (list): 操作における変換前の値 C (list): 操作における変換後の値 """ # 求解処理 sum_A = sum(A) counter_A = collections.Counter(A) for b, c in zip(B, C): sum_A += (c - b) * counter_A[b] # 結果出力 print(sum_A) # カウンターの更新 counter_A[c] += counter_A[b] counter_A[b] = 0 if __name__ == "__main__": # 標準入力を取得 N, A, Q, B, C = get_input() # 求解処理 main(A, B, C)
false
53.846154
[ "-# 標準入力の取得", "-N = int(eval(input()))", "-A = list(map(int, input().split()))", "-Q = int(eval(input()))", "-B, C = [], []", "-for q in range(Q):", "- B_q, C_q = list(map(int, input().split()))", "- B.append(B_q)", "- C.append(C_q)", "-# 求解処理", "-S = sum(A)", "-counter_A = collection...
false
0.035522
0.042472
0.836373
[ "s922129676", "s412407083" ]
u761529120
p03252
python
s906487378
s365540864
185
92
41,840
74,352
Accepted
Accepted
50.27
def main(): S = eval(input()) T = eval(input()) start = [-1] * 26 goal = [-1] * 26 for i in range(len(S)): a = ord(S[i]) - ord('a') b = ord(T[i]) - ord('a') if start[a] != -1 or goal[b] != -1: if start[a] != b or goal[b] != a: print('No') exit() start[a] = b goal[b] = a print('Yes') main()
from collections import Counter def main(): S = eval(input()) T = eval(input()) cnt_S = [] cnt_T = [] for i, j in list(Counter(S).items()): cnt_S.append(j) for i, j in list(Counter(T).items()): cnt_T.append(j) cnt_S.sort() cnt_T.sort() if cnt_T == cnt_S: print('Yes') else: print('No') if __name__ == "__main__": main()
22
22
425
396
def main(): S = eval(input()) T = eval(input()) start = [-1] * 26 goal = [-1] * 26 for i in range(len(S)): a = ord(S[i]) - ord("a") b = ord(T[i]) - ord("a") if start[a] != -1 or goal[b] != -1: if start[a] != b or goal[b] != a: print("No") exit() start[a] = b goal[b] = a print("Yes") main()
from collections import Counter def main(): S = eval(input()) T = eval(input()) cnt_S = [] cnt_T = [] for i, j in list(Counter(S).items()): cnt_S.append(j) for i, j in list(Counter(T).items()): cnt_T.append(j) cnt_S.sort() cnt_T.sort() if cnt_T == cnt_S: print("Yes") else: print("No") if __name__ == "__main__": main()
false
0
[ "+from collections import Counter", "+", "+", "- start = [-1] * 26", "- goal = [-1] * 26", "- for i in range(len(S)):", "- a = ord(S[i]) - ord(\"a\")", "- b = ord(T[i]) - ord(\"a\")", "- if start[a] != -1 or goal[b] != -1:", "- if start[a] != b or goal[b] !...
false
0.035876
0.038421
0.933765
[ "s906487378", "s365540864" ]
u764600134
p03163
python
s538467930
s982431319
703
283
121,272
40,048
Accepted
Accepted
59.74
# -*- coding: utf-8 -*- """ D - Knapsack 1 https://atcoder.jp/contests/dp/tasks/dp_d """ import sys def solve(N, W, items): ans = {0: 0} for w, v in items: u = dict() for x, y in list(ans.items()): if x+w <= W and ans.get(x+w, 0) < y+v: u[x+w] = y+v ans.update(u) return max([v for v in list(ans.values())]) def main(args): N, W = list(map(int, input().split())) items = [[int(i) for i in input().split()] for _ in range(N)] ans = solve(N, W, items) print(ans) if __name__ == '__main__': main(sys.argv[1:])
# -*- coding: utf-8 -*- """ D - Knapsack 1 https://atcoder.jp/contests/dp/tasks/dp_d """ import sys def solve(N, W, items): dp = [0-1] * (W+1) dp[0] = 0 for w, v in items: for i in range(W, w-1, -1): if dp[i-w] != -1: dp[i] = max(dp[i], dp[i-w]+v) return max(dp) def main(args): N, W = list(map(int, input().split())) items = [[int(i) for i in input().split()] for _ in range(N)] ans = solve(N, W, items) print(ans) if __name__ == '__main__': main(sys.argv[1:])
29
29
607
563
# -*- coding: utf-8 -*- """ D - Knapsack 1 https://atcoder.jp/contests/dp/tasks/dp_d """ import sys def solve(N, W, items): ans = {0: 0} for w, v in items: u = dict() for x, y in list(ans.items()): if x + w <= W and ans.get(x + w, 0) < y + v: u[x + w] = y + v ans.update(u) return max([v for v in list(ans.values())]) def main(args): N, W = list(map(int, input().split())) items = [[int(i) for i in input().split()] for _ in range(N)] ans = solve(N, W, items) print(ans) if __name__ == "__main__": main(sys.argv[1:])
# -*- coding: utf-8 -*- """ D - Knapsack 1 https://atcoder.jp/contests/dp/tasks/dp_d """ import sys def solve(N, W, items): dp = [0 - 1] * (W + 1) dp[0] = 0 for w, v in items: for i in range(W, w - 1, -1): if dp[i - w] != -1: dp[i] = max(dp[i], dp[i - w] + v) return max(dp) def main(args): N, W = list(map(int, input().split())) items = [[int(i) for i in input().split()] for _ in range(N)] ans = solve(N, W, items) print(ans) if __name__ == "__main__": main(sys.argv[1:])
false
0
[ "- ans = {0: 0}", "+ dp = [0 - 1] * (W + 1)", "+ dp[0] = 0", "- u = dict()", "- for x, y in list(ans.items()):", "- if x + w <= W and ans.get(x + w, 0) < y + v:", "- u[x + w] = y + v", "- ans.update(u)", "- return max([v for v in list(ans.va...
false
0.078603
0.039392
1.995427
[ "s538467930", "s982431319" ]
u716043626
p03607
python
s811688474
s538617850
218
200
15,076
16,640
Accepted
Accepted
8.26
n = int(eval(input())) a = {} cnt = 0 for i in range(n): tmp = int(eval(input())) if tmp not in a: a[tmp] = 1 else: a[tmp] += 1 for v in list(a.values()): if v % 2 != 0: cnt += 1 print(cnt)
import collections n = int(eval(input())) a = [int(eval(input())) for _ in range(n)] ans = 0 c = collections.Counter(a) for i in list(c.values()): if i % 2 != 0: ans += 1 print(ans)
15
13
227
191
n = int(eval(input())) a = {} cnt = 0 for i in range(n): tmp = int(eval(input())) if tmp not in a: a[tmp] = 1 else: a[tmp] += 1 for v in list(a.values()): if v % 2 != 0: cnt += 1 print(cnt)
import collections n = int(eval(input())) a = [int(eval(input())) for _ in range(n)] ans = 0 c = collections.Counter(a) for i in list(c.values()): if i % 2 != 0: ans += 1 print(ans)
false
13.333333
[ "+import collections", "+", "-a = {}", "-cnt = 0", "-for i in range(n):", "- tmp = int(eval(input()))", "- if tmp not in a:", "- a[tmp] = 1", "- else:", "- a[tmp] += 1", "-for v in list(a.values()):", "- if v % 2 != 0:", "- cnt += 1", "-print(cnt)", "+a =...
false
0.034202
0.042621
0.802477
[ "s811688474", "s538617850" ]
u327466606
p03334
python
s723521343
s529330911
591
319
21,424
4,276
Accepted
Accepted
46.02
from math import sqrt from itertools import product import numpy as np def judge(D): n = 1 while D%4==0: n *= 2 D //= 4 def h1(x,y): return ~(x//n+y//n)%2 def h2(x,y): return ~(x//n)%2 return h1 if D%2==1 else h2 N,D1,D2 = list(map(int,input().split())) j1,j2 = judge(D1),judge(D2) cnt = 0 for x,y in product(list(range(N*2)),repeat=2): if j1(x,y) and j2(x,y): print((x,y)) cnt += 1 if cnt >= N*N: break
def judge(D): n = 0 while D%4==0: n += 1 D //= 4 def h1(x,y): return ~((x>>n)^(y>>n))&1 def h2(x,y): return ~(x>>n)&1 return h1 if D%2==1 else h2 N,D1,D2 = list(map(int,input().split())) j1,j2 = judge(D1),judge(D2) cnt = 0 for x in range(N*2): for y in range(N*2): if j1(x,y) and j2(x,y): print((x,y)) cnt += 1 if cnt >= N*N: exit()
27
24
467
409
from math import sqrt from itertools import product import numpy as np def judge(D): n = 1 while D % 4 == 0: n *= 2 D //= 4 def h1(x, y): return ~(x // n + y // n) % 2 def h2(x, y): return ~(x // n) % 2 return h1 if D % 2 == 1 else h2 N, D1, D2 = list(map(int, input().split())) j1, j2 = judge(D1), judge(D2) cnt = 0 for x, y in product(list(range(N * 2)), repeat=2): if j1(x, y) and j2(x, y): print((x, y)) cnt += 1 if cnt >= N * N: break
def judge(D): n = 0 while D % 4 == 0: n += 1 D //= 4 def h1(x, y): return ~((x >> n) ^ (y >> n)) & 1 def h2(x, y): return ~(x >> n) & 1 return h1 if D % 2 == 1 else h2 N, D1, D2 = list(map(int, input().split())) j1, j2 = judge(D1), judge(D2) cnt = 0 for x in range(N * 2): for y in range(N * 2): if j1(x, y) and j2(x, y): print((x, y)) cnt += 1 if cnt >= N * N: exit()
false
11.111111
[ "-from math import sqrt", "-from itertools import product", "-import numpy as np", "-", "-", "- n = 1", "+ n = 0", "- n *= 2", "+ n += 1", "- return ~(x // n + y // n) % 2", "+ return ~((x >> n) ^ (y >> n)) & 1", "- return ~(x // n) % 2", "+ re...
false
0.03839
0.071002
0.540692
[ "s723521343", "s529330911" ]
u505420467
p03160
python
s909015322
s559638164
139
127
13,980
13,980
Accepted
Accepted
8.63
n=int(eval(input())) h=list(map(int,input().split())) dp=[0]*n dp[1]=abs(h[0]-h[1]) for i in range(2,n): dp[i]=min(dp[i-2]+abs(h[i]-h[i-2]),dp[i-1]+abs(h[i]-h[i-1])) print((dp[n-1]))
n = int(eval(input())) h = list(map(int, input().split())) dp= [10 ** 9 + 7] * (n + 10) dp[0] = 0 dp[1] = abs(h[1] - h[0]) for i in range(2, n): dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2])) print((dp[n - 1]))
7
12
185
255
n = int(eval(input())) h = list(map(int, input().split())) dp = [0] * n dp[1] = abs(h[0] - h[1]) for i in range(2, n): dp[i] = min(dp[i - 2] + abs(h[i] - h[i - 2]), dp[i - 1] + abs(h[i] - h[i - 1])) print((dp[n - 1]))
n = int(eval(input())) h = list(map(int, input().split())) dp = [10**9 + 7] * (n + 10) dp[0] = 0 dp[1] = abs(h[1] - h[0]) for i in range(2, n): dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2])) print((dp[n - 1]))
false
41.666667
[ "-dp = [0] * n", "-dp[1] = abs(h[0] - h[1])", "+dp = [10**9 + 7] * (n + 10)", "+dp[0] = 0", "+dp[1] = abs(h[1] - h[0])", "- dp[i] = min(dp[i - 2] + abs(h[i] - h[i - 2]), dp[i - 1] + abs(h[i] - h[i - 1]))", "+ dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]))" ]
false
0.037571
0.042929
0.875189
[ "s909015322", "s559638164" ]
u072053884
p02235
python
s357999282
s973299669
4,430
2,480
7,772
7,752
Accepted
Accepted
44.02
def lcs_len(x, y): ly = len(y) tcsl = [0] * (ly + 1) for x_i in x: pre_tcsl = list(tcsl) for j in range(ly): if x_i == y[j]: tcsl[j] = pre_tcsl[j - 1] + 1 elif tcsl[j] < tcsl[j - 1]: tcsl[j] = tcsl[j - 1] print((tcsl[j])) q = int(eval(input())) for i in range(q): ax = eval(input()) ay = eval(input()) lcs_len(ax, ay)
def lcs_len(x, y): indices = [0] for y_i in y: t_index = 0 for i, index in enumerate(indices, 1): c_index = x.find(y_i, t_index) + 1 if c_index: if i < len(indices): t_index = indices[i] indices[i] = min(c_index, t_index) else: indices.append(c_index) break print((len(indices) - 1)) q = int(eval(input())) for i in range(q): ax = eval(input()) ay = eval(input()) lcs_len(ax, ay)
19
22
418
559
def lcs_len(x, y): ly = len(y) tcsl = [0] * (ly + 1) for x_i in x: pre_tcsl = list(tcsl) for j in range(ly): if x_i == y[j]: tcsl[j] = pre_tcsl[j - 1] + 1 elif tcsl[j] < tcsl[j - 1]: tcsl[j] = tcsl[j - 1] print((tcsl[j])) q = int(eval(input())) for i in range(q): ax = eval(input()) ay = eval(input()) lcs_len(ax, ay)
def lcs_len(x, y): indices = [0] for y_i in y: t_index = 0 for i, index in enumerate(indices, 1): c_index = x.find(y_i, t_index) + 1 if c_index: if i < len(indices): t_index = indices[i] indices[i] = min(c_index, t_index) else: indices.append(c_index) break print((len(indices) - 1)) q = int(eval(input())) for i in range(q): ax = eval(input()) ay = eval(input()) lcs_len(ax, ay)
false
13.636364
[ "- ly = len(y)", "- tcsl = [0] * (ly + 1)", "- for x_i in x:", "- pre_tcsl = list(tcsl)", "- for j in range(ly):", "- if x_i == y[j]:", "- tcsl[j] = pre_tcsl[j - 1] + 1", "- elif tcsl[j] < tcsl[j - 1]:", "- tcsl[j] = tcsl[j -...
false
0.092278
0.044138
2.090685
[ "s357999282", "s973299669" ]
u708255304
p03078
python
s827122509
s815168488
1,009
38
148,864
4,340
Accepted
Accepted
96.23
X, Y, Z, K = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) a_b = [] for i in range(X): for j in range(Y): a_b.append(A[i]+B[j]) a_b = sorted(a_b, reverse=True) ans = [] for k in range(min(K, len(a_b))): for l in range(min(K, len(C))): ans.append(a_b[k]+C[l]) ans = sorted(ans, reverse=True) for m in range(K): print((ans[m]))
# 優先度付き待ち行列で解く import heapq X, Y, Z, K = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A = sorted(A, reverse=True) B = sorted(B, reverse=True) C = sorted(C, reverse=True) A.append(-10**20) B.append(-10**20) C.append(-10**20) Q = [] heapq.heapify(Q) heapq.heappush(Q, (-(A[0]+B[0]+C[0]), 0, 0, 0)) # ケーキの美味しさ, Aのindex, Bのindex, Cのindex count = 0 fin = {} while count < K: delicious, a, b, c = heapq.heappop(Q) if (a, b, c) not in fin: fin[(a, b, c)] = True print((-delicious)) heapq.heappush(Q, (-(A[a+1]+B[b]+C[c]), a+1, b, c)) heapq.heappush(Q, (-(A[a]+B[b+1]+C[c]), a, b+1, c)) heapq.heappush(Q, (-(A[a]+B[b]+C[c+1]), a, b, c+1)) count += 1
17
27
457
813
X, Y, Z, K = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) a_b = [] for i in range(X): for j in range(Y): a_b.append(A[i] + B[j]) a_b = sorted(a_b, reverse=True) ans = [] for k in range(min(K, len(a_b))): for l in range(min(K, len(C))): ans.append(a_b[k] + C[l]) ans = sorted(ans, reverse=True) for m in range(K): print((ans[m]))
# 優先度付き待ち行列で解く import heapq X, Y, Z, K = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A = sorted(A, reverse=True) B = sorted(B, reverse=True) C = sorted(C, reverse=True) A.append(-(10**20)) B.append(-(10**20)) C.append(-(10**20)) Q = [] heapq.heapify(Q) heapq.heappush( Q, (-(A[0] + B[0] + C[0]), 0, 0, 0) ) # ケーキの美味しさ, Aのindex, Bのindex, Cのindex count = 0 fin = {} while count < K: delicious, a, b, c = heapq.heappop(Q) if (a, b, c) not in fin: fin[(a, b, c)] = True print((-delicious)) heapq.heappush(Q, (-(A[a + 1] + B[b] + C[c]), a + 1, b, c)) heapq.heappush(Q, (-(A[a] + B[b + 1] + C[c]), a, b + 1, c)) heapq.heappush(Q, (-(A[a] + B[b] + C[c + 1]), a, b, c + 1)) count += 1
false
37.037037
[ "+# 優先度付き待ち行列で解く", "+import heapq", "+", "-a_b = []", "-for i in range(X):", "- for j in range(Y):", "- a_b.append(A[i] + B[j])", "-a_b = sorted(a_b, reverse=True)", "-ans = []", "-for k in range(min(K, len(a_b))):", "- for l in range(min(K, len(C))):", "- ans.append(a_b[k]...
false
0.113469
0.037173
3.052471
[ "s827122509", "s815168488" ]
u761320129
p03593
python
s574105566
s422950993
232
24
3,444
3,380
Accepted
Accepted
89.66
from collections import Counter H,W = list(map(int,input().split())) src = [eval(input()) for i in range(H)] counter = Counter() for row in src: counter.update(row) def solve(): if H%2 == 0 and W%2 == 0: for n in list(counter.values()): if n%4 != 0: return False return True elif H%2 == 1 and W%2 == 1: odd = pairs = 0 for n in list(counter.values()): if n%4 == 0: continue if n%2 == 1: if odd > 0: return False odd = 1 if (n-1)%4 == 0: continue pairs += 2 if pairs > H+W-1: return False return True else: even = (H if H%2 == 0 else W) pairs = 0 for n in list(counter.values()): if n%4 == 0: continue if n%2 == 1: return False pairs += 2 if pairs > even: return False return True print(('Yes' if solve() else 'No'))
H,W = list(map(int,input().split())) A = [eval(input()) for i in range(H)] from collections import Counter ctr = Counter() for row in A: ctr.update(row) if H%2==0 and W%2==0: print(('Yes' if all(v%4==0 for v in list(ctr.values())) else 'No')) elif H%2 and W%2: odd = 0 for k,v in list(ctr.items()): if v%2: odd += 1 ctr[k] -= 1 if odd != 1: print('No') exit() four = 0 for v in list(ctr.values()): four += (v//4)*4 want = (H-H%2)*(W-W%2) print(('Yes' if four >= want else 'No')) else: if any(v%2 for v in list(ctr.values())): print('No') exit() four = 0 for v in list(ctr.values()): four += (v//4)*4 want = (H-H%2)*(W-W%2) print(('Yes' if four >= want else 'No'))
34
32
963
783
from collections import Counter H, W = list(map(int, input().split())) src = [eval(input()) for i in range(H)] counter = Counter() for row in src: counter.update(row) def solve(): if H % 2 == 0 and W % 2 == 0: for n in list(counter.values()): if n % 4 != 0: return False return True elif H % 2 == 1 and W % 2 == 1: odd = pairs = 0 for n in list(counter.values()): if n % 4 == 0: continue if n % 2 == 1: if odd > 0: return False odd = 1 if (n - 1) % 4 == 0: continue pairs += 2 if pairs > H + W - 1: return False return True else: even = H if H % 2 == 0 else W pairs = 0 for n in list(counter.values()): if n % 4 == 0: continue if n % 2 == 1: return False pairs += 2 if pairs > even: return False return True print(("Yes" if solve() else "No"))
H, W = list(map(int, input().split())) A = [eval(input()) for i in range(H)] from collections import Counter ctr = Counter() for row in A: ctr.update(row) if H % 2 == 0 and W % 2 == 0: print(("Yes" if all(v % 4 == 0 for v in list(ctr.values())) else "No")) elif H % 2 and W % 2: odd = 0 for k, v in list(ctr.items()): if v % 2: odd += 1 ctr[k] -= 1 if odd != 1: print("No") exit() four = 0 for v in list(ctr.values()): four += (v // 4) * 4 want = (H - H % 2) * (W - W % 2) print(("Yes" if four >= want else "No")) else: if any(v % 2 for v in list(ctr.values())): print("No") exit() four = 0 for v in list(ctr.values()): four += (v // 4) * 4 want = (H - H % 2) * (W - W % 2) print(("Yes" if four >= want else "No"))
false
5.882353
[ "+H, W = list(map(int, input().split()))", "+A = [eval(input()) for i in range(H)]", "-H, W = list(map(int, input().split()))", "-src = [eval(input()) for i in range(H)]", "-counter = Counter()", "-for row in src:", "- counter.update(row)", "-", "-", "-def solve():", "- if H % 2 == 0 and W...
false
0.122942
0.039856
3.084652
[ "s574105566", "s422950993" ]
u745087332
p03128
python
s158402316
s959906452
652
134
15,092
14,692
Accepted
Accepted
79.45
# coding:utf-8 import sys import math INF = float('inf') MOD = 10 ** 9 + 7 def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def II(): return int(sys.stdin.readline()) def SI(): return eval(input()) def main(): n, m = LI() A = LI() A.sort() A.reverse() match = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] # dp[i]: ちょうどマッチをi本使ったときに作れる整数の最大の桁数(-1: 作れない) dp = [-1] * (n + 1) dp[0] = 0 res = [0] * (n + 1) for i in range(1, n + 1): for j in A: # 最上位桁の数字を決める # k: 最上位桁をjにしたときの残りのマッチの数 k = i - match[j] if k < 0 or dp[k] == -1: continue if dp[i] < dp[k] + 1: dp[i] = dp[k] + 1 res[i] = j * 10 ** dp[k] + res[k] return res[n] print((main()))
# coding:utf-8 import sys INF = float('inf') MOD = 10 ** 9 + 7 def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def II(): return int(sys.stdin.readline()) def SI(): return eval(input()) def main(): n, m = LI() A = LI() match = [6, 2, 5, 5, 4, 5, 6, 3, 7, 6] # dp[i]: ちょうどマッチをi本使ったときに作れる整数の最大の値 dp = [-INF] * (n + 10) dp[0] = 0 for i in range(n): for a in A: j = i + match[a] dp[j] = max(dp[j], dp[i] * 10 + a) return dp[n] print((main()))
41
30
952
662
# coding:utf-8 import sys import math INF = float("inf") MOD = 10**9 + 7 def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def II(): return int(sys.stdin.readline()) def SI(): return eval(input()) def main(): n, m = LI() A = LI() A.sort() A.reverse() match = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] # dp[i]: ちょうどマッチをi本使ったときに作れる整数の最大の桁数(-1: 作れない) dp = [-1] * (n + 1) dp[0] = 0 res = [0] * (n + 1) for i in range(1, n + 1): for j in A: # 最上位桁の数字を決める # k: 最上位桁をjにしたときの残りのマッチの数 k = i - match[j] if k < 0 or dp[k] == -1: continue if dp[i] < dp[k] + 1: dp[i] = dp[k] + 1 res[i] = j * 10 ** dp[k] + res[k] return res[n] print((main()))
# coding:utf-8 import sys INF = float("inf") MOD = 10**9 + 7 def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def II(): return int(sys.stdin.readline()) def SI(): return eval(input()) def main(): n, m = LI() A = LI() match = [6, 2, 5, 5, 4, 5, 6, 3, 7, 6] # dp[i]: ちょうどマッチをi本使ったときに作れる整数の最大の値 dp = [-INF] * (n + 10) dp[0] = 0 for i in range(n): for a in A: j = i + match[a] dp[j] = max(dp[j], dp[i] * 10 + a) return dp[n] print((main()))
false
26.829268
[ "-import math", "- A.sort()", "- A.reverse()", "- match = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]", "- # dp[i]: ちょうどマッチをi本使ったときに作れる整数の最大の桁数(-1: 作れない)", "- dp = [-1] * (n + 1)", "+ match = [6, 2, 5, 5, 4, 5, 6, 3, 7, 6]", "+ # dp[i]: ちょうどマッチをi本使ったときに作れる整数の最大の値", "+ dp = [-INF] * (n + 1...
false
0.078508
0.036043
2.178161
[ "s158402316", "s959906452" ]
u987164499
p03371
python
s442207093
s856863761
152
18
12,508
3,064
Accepted
Accepted
88.16
from sys import stdin import numpy as np a,b,c,x,y= [int(x) for x in stdin.readline().rstrip().split()] if x >= y: print((min(a*x+b*y,c*2*y+a*(x-y),c*2*x))) else: print((min(a*x+b*y,c*2*x+b*(y-x),c*2*y)))
from sys import stdin from sys import setrecursionlimit setrecursionlimit(10 ** 7) a,b,c,x,y = list(map(int,stdin.readline().rstrip().split())) mi = 10**10 mi = min(mi,max(x,y)*2*c) mi = min(mi,a*x+b*y) if x >= y: mi = min(mi,y*2*c+(x-y)*a) else: mi = min(mi,x*2*c+(y-x)*b) print(mi)
8
16
216
304
from sys import stdin import numpy as np a, b, c, x, y = [int(x) for x in stdin.readline().rstrip().split()] if x >= y: print((min(a * x + b * y, c * 2 * y + a * (x - y), c * 2 * x))) else: print((min(a * x + b * y, c * 2 * x + b * (y - x), c * 2 * y)))
from sys import stdin from sys import setrecursionlimit setrecursionlimit(10**7) a, b, c, x, y = list(map(int, stdin.readline().rstrip().split())) mi = 10**10 mi = min(mi, max(x, y) * 2 * c) mi = min(mi, a * x + b * y) if x >= y: mi = min(mi, y * 2 * c + (x - y) * a) else: mi = min(mi, x * 2 * c + (y - x) * b) print(mi)
false
50
[ "-import numpy as np", "+from sys import setrecursionlimit", "-a, b, c, x, y = [int(x) for x in stdin.readline().rstrip().split()]", "+setrecursionlimit(10**7)", "+a, b, c, x, y = list(map(int, stdin.readline().rstrip().split()))", "+mi = 10**10", "+mi = min(mi, max(x, y) * 2 * c)", "+mi = min(mi, a *...
false
0.046203
0.08715
0.530154
[ "s442207093", "s856863761" ]
u044459372
p02881
python
s737144183
s689241217
195
139
2,940
3,060
Accepted
Accepted
28.72
n = int(eval(input())) i = int(n**(1/2)) while n%i: i-=1 j = n//i ans = (i - 1) + (j - 1) #print(i,j) print(ans)
n = int(eval(input())) for i in range(1,int(n**(1/2)+1))[::-1]: if not n%i: j = n//i print((i-1+j-1)) break
8
6
114
134
n = int(eval(input())) i = int(n ** (1 / 2)) while n % i: i -= 1 j = n // i ans = (i - 1) + (j - 1) # print(i,j) print(ans)
n = int(eval(input())) for i in range(1, int(n ** (1 / 2) + 1))[::-1]: if not n % i: j = n // i print((i - 1 + j - 1)) break
false
25
[ "-i = int(n ** (1 / 2))", "-while n % i:", "- i -= 1", "-j = n // i", "-ans = (i - 1) + (j - 1)", "-# print(i,j)", "-print(ans)", "+for i in range(1, int(n ** (1 / 2) + 1))[::-1]:", "+ if not n % i:", "+ j = n // i", "+ print((i - 1 + j - 1))", "+ break" ]
false
0.066076
0.124946
0.528839
[ "s737144183", "s689241217" ]
u359358631
p02899
python
s425758704
s507845911
273
127
99,140
86,112
Accepted
Accepted
53.48
def main(): n = int(input()) a_list = list(map(int, input().split())) lst = [[i, x] for i, x in enumerate(a_list)] lst.sort(key = lambda x: x[1]) for i in lst: print(i[0] + 1, end=" ") if __name__ == "__main__": main()
def main(): n = int(input()) a_list = list(map(int, input().split())) ans_list = [0] * n for i in range(n): ans_list[a_list[i] - 1] = i + 1 for ans in ans_list: print(ans, end=" ") if __name__ == "__main__": main()
11
14
263
272
def main(): n = int(input()) a_list = list(map(int, input().split())) lst = [[i, x] for i, x in enumerate(a_list)] lst.sort(key=lambda x: x[1]) for i in lst: print(i[0] + 1, end=" ") if __name__ == "__main__": main()
def main(): n = int(input()) a_list = list(map(int, input().split())) ans_list = [0] * n for i in range(n): ans_list[a_list[i] - 1] = i + 1 for ans in ans_list: print(ans, end=" ") if __name__ == "__main__": main()
false
21.428571
[ "- lst = [[i, x] for i, x in enumerate(a_list)]", "- lst.sort(key=lambda x: x[1])", "- for i in lst:", "- print(i[0] + 1, end=\" \")", "+ ans_list = [0] * n", "+ for i in range(n):", "+ ans_list[a_list[i] - 1] = i + 1", "+ for ans in ans_list:", "+ print(ans, e...
false
0.066599
0.067569
0.985644
[ "s425758704", "s507845911" ]
u132350318
p03413
python
s164334701
s842575857
331
151
20,992
14,472
Accepted
Accepted
54.38
import numpy as np def main(): n = int(input()) a = [int(x) for x in input().split()] best, solution = int(-1e10), [] for p in range(2): c = a.copy() indexes = list(range(p, n, 2)) if len(indexes) == 0: continue maks = max([c[i] for i in indexes]) pick = next(filter(lambda i: c[i] == maks, indexes)) chosen = set([pick] if maks <= 0 else filter(lambda i: c[i] > 0, indexes)) is_chosen = [(i in chosen) for i in range(n)] tot, res = sum([c[i] for i in chosen]), [] for i in reversed(range(n)): if not is_chosen[i]: if i == 0 or i + 1 == len(c): res += [i] del c[i], is_chosen[i] elif is_chosen[i - 1] == is_chosen[i + 1]: res += [i] c[i - 1] += c[i + 1] del c[i + 1], c[i], is_chosen[i + 1], is_chosen[i] if len(c) > 1 and not is_chosen[0]: res += [0] del c[0], is_chosen[0] if tot > best: best, solution = tot, np.array(res) + 1 print(best, len(solution), *solution, sep='\n') if __name__ == '__main__': main()
import numpy as np def main(): n = int(input()) a = [int(x) for x in input().split()] sol_tot, sol_tracker = int(-1e10), [] for p in range(2): c = a.copy() idx = list(range(p, n, 2)) if not idx: continue pick = max(idx, key=lambda i: c[i]) if c[pick] <= 0: chosen = set([pick]) else: chosen = set(filter(lambda i: c[i] > 0, idx)) is_chosen, tot, tracker = [False] * n, 0, [] for i in chosen: is_chosen[i] = True tot += c[i] for i in reversed(range(n)): if not is_chosen[i]: if i == 0 or i + 1 == len(c): tracker += [i] del c[i], is_chosen[i] elif is_chosen[i - 1] == is_chosen[i + 1]: tracker += [i] c[i - 1] += c[i + 1] del c[i + 1], c[i], is_chosen[i + 1], is_chosen[i] if len(c) > 1 and not is_chosen[0]: tracker += [0] del c[0], is_chosen[0] if tot > sol_tot: sol_tot, sol_tracker = tot, np.array(tracker) + 1 print(sol_tot, len(sol_tracker), *sol_tracker, sep='\n') if __name__ == '__main__': main()
43
48
1,269
1,316
import numpy as np def main(): n = int(input()) a = [int(x) for x in input().split()] best, solution = int(-1e10), [] for p in range(2): c = a.copy() indexes = list(range(p, n, 2)) if len(indexes) == 0: continue maks = max([c[i] for i in indexes]) pick = next(filter(lambda i: c[i] == maks, indexes)) chosen = set([pick] if maks <= 0 else filter(lambda i: c[i] > 0, indexes)) is_chosen = [(i in chosen) for i in range(n)] tot, res = sum([c[i] for i in chosen]), [] for i in reversed(range(n)): if not is_chosen[i]: if i == 0 or i + 1 == len(c): res += [i] del c[i], is_chosen[i] elif is_chosen[i - 1] == is_chosen[i + 1]: res += [i] c[i - 1] += c[i + 1] del c[i + 1], c[i], is_chosen[i + 1], is_chosen[i] if len(c) > 1 and not is_chosen[0]: res += [0] del c[0], is_chosen[0] if tot > best: best, solution = tot, np.array(res) + 1 print(best, len(solution), *solution, sep="\n") if __name__ == "__main__": main()
import numpy as np def main(): n = int(input()) a = [int(x) for x in input().split()] sol_tot, sol_tracker = int(-1e10), [] for p in range(2): c = a.copy() idx = list(range(p, n, 2)) if not idx: continue pick = max(idx, key=lambda i: c[i]) if c[pick] <= 0: chosen = set([pick]) else: chosen = set(filter(lambda i: c[i] > 0, idx)) is_chosen, tot, tracker = [False] * n, 0, [] for i in chosen: is_chosen[i] = True tot += c[i] for i in reversed(range(n)): if not is_chosen[i]: if i == 0 or i + 1 == len(c): tracker += [i] del c[i], is_chosen[i] elif is_chosen[i - 1] == is_chosen[i + 1]: tracker += [i] c[i - 1] += c[i + 1] del c[i + 1], c[i], is_chosen[i + 1], is_chosen[i] if len(c) > 1 and not is_chosen[0]: tracker += [0] del c[0], is_chosen[0] if tot > sol_tot: sol_tot, sol_tracker = tot, np.array(tracker) + 1 print(sol_tot, len(sol_tracker), *sol_tracker, sep="\n") if __name__ == "__main__": main()
false
10.416667
[ "- best, solution = int(-1e10), []", "+ sol_tot, sol_tracker = int(-1e10), []", "- indexes = list(range(p, n, 2))", "- if len(indexes) == 0:", "+ idx = list(range(p, n, 2))", "+ if not idx:", "- maks = max([c[i] for i in indexes])", "- pick = next(filter...
false
0.275502
0.217555
1.266358
[ "s164334701", "s842575857" ]
u759412327
p02786
python
s438234472
s336825866
31
28
9,096
9,144
Accepted
Accepted
9.68
from math import * H = int(eval(input())) print((2**(int(log2(H))+1)-1))
print((2**int(eval(input())).bit_length()-1))
3
1
66
37
from math import * H = int(eval(input())) print((2 ** (int(log2(H)) + 1) - 1))
print((2 ** int(eval(input())).bit_length() - 1))
false
66.666667
[ "-from math import *", "-", "-H = int(eval(input()))", "-print((2 ** (int(log2(H)) + 1) - 1))", "+print((2 ** int(eval(input())).bit_length() - 1))" ]
false
0.043771
0.04843
0.903792
[ "s438234472", "s336825866" ]
u334712262
p02559
python
s512853764
s044970842
1,500
892
225,708
184,928
Accepted
Accepted
40.53
# -*- coding: utf-8 -*- import bisect import heapq import math import random from collections import Counter, defaultdict, deque from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal from fractions import Fraction from functools import lru_cache, reduce from itertools import combinations, combinations_with_replacement, product, permutations, accumulate from operator import add, mul, sub, itemgetter, attrgetter import sys # sys.setrecursionlimit(10**6) # readline = sys.stdin.buffer.readline readline = sys.stdin.readline INF = 2**62-1 def read_int(): return int(readline()) def read_int_n(): return list(map(int, readline().split())) def read_float(): return float(readline()) def read_float_n(): return list(map(float, readline().split())) def read_str(): return readline().strip() def read_str_n(): return readline().strip().split() def ep(*args): print(*args, file=sys.stderr) def mt(f): import time def wrap(*args, **kwargs): s = time.perf_counter() ret = f(*args, **kwargs) e = time.perf_counter() ep(e - s, 'sec') return ret return wrap class SegmentTree: def __init__(self, array, operator, identity_element): _len = len(array) self.__op = operator self.__size = 1 << (_len - 1).bit_length() self.__tree = [identity_element] * self.__size + \ array + [identity_element] * (self.__size - _len) self.__ie = identity_element for i in range(self.__size - 1, 0, -1): self.__tree[i] = operator( self.__tree[i * 2], self.__tree[i * 2 + 1]) def update(self, i, v): i += self.__size self.__tree[i] = v while i: i //= 2 self.__tree[i] = self.__op( self.__tree[i * 2], self.__tree[i * 2 + 1]) def query(self, l, r): """[l, r) """ l += self.__size r += self.__size ret = self.__ie while l < r: if l & 1: ret = self.__op(ret, self.__tree[l]) l += 1 if r & 1: r -= 1 ret = self.__op(ret, self.__tree[r]) l //= 2 r //= 2 return ret def __getitem__(self, key): return self.__tree[key + self.__size] @mt def slv(N, A, Q): st = SegmentTree(A, add, 0) ans = [] for q in Q: if q[0] == 0: _, p, x = q st.update(p, st[p]+x) else: _, l, r = q ans.append(st.query(l, r)) return ans def main(): N, Q = read_int_n() A = read_int_n() Q = [read_int_n() for _ in range(Q)] print(*slv(N, A, Q), sep='\n') if __name__ == '__main__': main()
# -*- coding: utf-8 -*- import bisect import heapq import math import random from collections import Counter, defaultdict, deque from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal from fractions import Fraction from functools import lru_cache, reduce from itertools import combinations, combinations_with_replacement, product, permutations, accumulate from operator import add, mul, sub, itemgetter, attrgetter import sys # sys.setrecursionlimit(10**6) # readline = sys.stdin.buffer.readline readline = sys.stdin.readline INF = 2**62-1 def read_int(): return int(readline()) def read_int_n(): return list(map(int, readline().split())) def read_float(): return float(readline()) def read_float_n(): return list(map(float, readline().split())) def read_str(): return readline().strip() def read_str_n(): return readline().strip().split() def ep(*args): print(*args, file=sys.stderr) def mt(f): import time def wrap(*args, **kwargs): s = time.perf_counter() ret = f(*args, **kwargs) e = time.perf_counter() ep(e - s, 'sec') return ret return wrap class FenwicTree: def __init__(self, n): self.__data = [0] * n self.__n = n def add(self, i, x): i += 1 while i <= self.__n: self.__data[i-1] += x i += i & -i def sum(self, l, r): return self.__sum(r) - self.__sum(l) def __sum(self, r): s = 0 while r > 0: s += self.__data[r-1] r -= r & -r return s @mt def slv(N, A, Q): ft = FenwicTree(N) for i, a in enumerate(A): ft.add(i, a) ans = [] for q in Q: if q[0] == 0: _, p, x = q ft.add(p, x) else: _, l, r = q ans.append(ft.sum(l, r)) return ans def main(): N, Q = read_int_n() A = read_int_n() Q = [read_int_n() for _ in range(Q)] print(*slv(N, A, Q), sep='\n') if __name__ == '__main__': main()
127
114
2,907
2,165
# -*- coding: utf-8 -*- import bisect import heapq import math import random from collections import Counter, defaultdict, deque from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal from fractions import Fraction from functools import lru_cache, reduce from itertools import ( combinations, combinations_with_replacement, product, permutations, accumulate, ) from operator import add, mul, sub, itemgetter, attrgetter import sys # sys.setrecursionlimit(10**6) # readline = sys.stdin.buffer.readline readline = sys.stdin.readline INF = 2**62 - 1 def read_int(): return int(readline()) def read_int_n(): return list(map(int, readline().split())) def read_float(): return float(readline()) def read_float_n(): return list(map(float, readline().split())) def read_str(): return readline().strip() def read_str_n(): return readline().strip().split() def ep(*args): print(*args, file=sys.stderr) def mt(f): import time def wrap(*args, **kwargs): s = time.perf_counter() ret = f(*args, **kwargs) e = time.perf_counter() ep(e - s, "sec") return ret return wrap class SegmentTree: def __init__(self, array, operator, identity_element): _len = len(array) self.__op = operator self.__size = 1 << (_len - 1).bit_length() self.__tree = ( [identity_element] * self.__size + array + [identity_element] * (self.__size - _len) ) self.__ie = identity_element for i in range(self.__size - 1, 0, -1): self.__tree[i] = operator(self.__tree[i * 2], self.__tree[i * 2 + 1]) def update(self, i, v): i += self.__size self.__tree[i] = v while i: i //= 2 self.__tree[i] = self.__op(self.__tree[i * 2], self.__tree[i * 2 + 1]) def query(self, l, r): """[l, r)""" l += self.__size r += self.__size ret = self.__ie while l < r: if l & 1: ret = self.__op(ret, self.__tree[l]) l += 1 if r & 1: r -= 1 ret = self.__op(ret, self.__tree[r]) l //= 2 r //= 2 return ret def __getitem__(self, key): return self.__tree[key + self.__size] @mt def slv(N, A, Q): st = SegmentTree(A, add, 0) ans = [] for q in Q: if q[0] == 0: _, p, x = q st.update(p, st[p] + x) else: _, l, r = q ans.append(st.query(l, r)) return ans def main(): N, Q = read_int_n() A = read_int_n() Q = [read_int_n() for _ in range(Q)] print(*slv(N, A, Q), sep="\n") if __name__ == "__main__": main()
# -*- coding: utf-8 -*- import bisect import heapq import math import random from collections import Counter, defaultdict, deque from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal from fractions import Fraction from functools import lru_cache, reduce from itertools import ( combinations, combinations_with_replacement, product, permutations, accumulate, ) from operator import add, mul, sub, itemgetter, attrgetter import sys # sys.setrecursionlimit(10**6) # readline = sys.stdin.buffer.readline readline = sys.stdin.readline INF = 2**62 - 1 def read_int(): return int(readline()) def read_int_n(): return list(map(int, readline().split())) def read_float(): return float(readline()) def read_float_n(): return list(map(float, readline().split())) def read_str(): return readline().strip() def read_str_n(): return readline().strip().split() def ep(*args): print(*args, file=sys.stderr) def mt(f): import time def wrap(*args, **kwargs): s = time.perf_counter() ret = f(*args, **kwargs) e = time.perf_counter() ep(e - s, "sec") return ret return wrap class FenwicTree: def __init__(self, n): self.__data = [0] * n self.__n = n def add(self, i, x): i += 1 while i <= self.__n: self.__data[i - 1] += x i += i & -i def sum(self, l, r): return self.__sum(r) - self.__sum(l) def __sum(self, r): s = 0 while r > 0: s += self.__data[r - 1] r -= r & -r return s @mt def slv(N, A, Q): ft = FenwicTree(N) for i, a in enumerate(A): ft.add(i, a) ans = [] for q in Q: if q[0] == 0: _, p, x = q ft.add(p, x) else: _, l, r = q ans.append(ft.sum(l, r)) return ans def main(): N, Q = read_int_n() A = read_int_n() Q = [read_int_n() for _ in range(Q)] print(*slv(N, A, Q), sep="\n") if __name__ == "__main__": main()
false
10.23622
[ "-class SegmentTree:", "- def __init__(self, array, operator, identity_element):", "- _len = len(array)", "- self.__op = operator", "- self.__size = 1 << (_len - 1).bit_length()", "- self.__tree = (", "- [identity_element] * self.__size", "- + array...
false
0.038366
0.039195
0.97885
[ "s512853764", "s044970842" ]
u232852711
p03361
python
s858230098
s332754382
156
23
12,408
3,064
Accepted
Accepted
85.26
H, W = list(map(int, input().split(' '))) import numpy as np import sys grid = np.zeros((H, W)) for h in range(H): grid[h,:] = [0 if g == '.' else 1 for g in eval(input())] # print(grid) for h in range(H): for w in range(W): if grid[h, w] == 0: continue around = [] if h > 0: around.append(grid[h-1, w]) if w > 0: around.append(grid[h, w-1]) if h < H-1: around.append(grid[h+1, w]) if w < W-1: around.append(grid[h, w+1]) if 1 in around: pass else: # print(h, w, around) print('No') sys.exit() print('Yes')
h, w = list(map(int, input().split())) s = [eval(input()) for _ in range(h)] adj = [(1, 0), (0, 1), (-1, 0), (0, -1)] non_adj = 0 for y in range(h): for x in range(w): if s[y][x] == '.': continue n_adj = 0 for dx, dy in adj: i, j = y+dy, x+dx if i < 0 or i >= h or j < 0 or j >= w: continue if s[i][j] == '#': n_adj += 1 if n_adj == 0: non_adj += 1 # print(non_adj) if non_adj == 0: print('Yes') else: print('No')
29
23
627
566
H, W = list(map(int, input().split(" "))) import numpy as np import sys grid = np.zeros((H, W)) for h in range(H): grid[h, :] = [0 if g == "." else 1 for g in eval(input())] # print(grid) for h in range(H): for w in range(W): if grid[h, w] == 0: continue around = [] if h > 0: around.append(grid[h - 1, w]) if w > 0: around.append(grid[h, w - 1]) if h < H - 1: around.append(grid[h + 1, w]) if w < W - 1: around.append(grid[h, w + 1]) if 1 in around: pass else: # print(h, w, around) print("No") sys.exit() print("Yes")
h, w = list(map(int, input().split())) s = [eval(input()) for _ in range(h)] adj = [(1, 0), (0, 1), (-1, 0), (0, -1)] non_adj = 0 for y in range(h): for x in range(w): if s[y][x] == ".": continue n_adj = 0 for dx, dy in adj: i, j = y + dy, x + dx if i < 0 or i >= h or j < 0 or j >= w: continue if s[i][j] == "#": n_adj += 1 if n_adj == 0: non_adj += 1 # print(non_adj) if non_adj == 0: print("Yes") else: print("No")
false
20.689655
[ "-H, W = list(map(int, input().split(\" \")))", "-import numpy as np", "-import sys", "-", "-grid = np.zeros((H, W))", "-for h in range(H):", "- grid[h, :] = [0 if g == \".\" else 1 for g in eval(input())]", "-# print(grid)", "-for h in range(H):", "- for w in range(W):", "- if grid...
false
0.207994
0.037954
5.480185
[ "s858230098", "s332754382" ]
u606174760
p03700
python
s168391366
s971705751
1,813
1,245
10,960
10,952
Accepted
Accepted
31.33
# -*- coding:utf-8 -*- import math import sys line = input().split(' ') N = int(line[0]) A = int(line[1]) B = int(line[2]) hn = sorted([int(eval(input())) for i in range(N)]) maxT = int(hn[-1] / B) + 1 minT = 0 def enough(T): count = sum([math.ceil((h - B*T) / (A-B)) if math.ceil((h - B*T) / (A-B)) >= 0 else 0 for h in hn]) return True if count <= T else False while True: med = int((maxT + minT) / 2) if enough(med): maxT = med else: minT = med if maxT - minT <= 1: break print(maxT)
# -*- coding:utf-8 -*- import math N, A, B = list(map(int, input().split(' '))) hn = sorted([int(eval(input())) for i in range(N)]) maxT = int(hn[-1] / B) + 1 minT = 0 def enough(T): count = sum([math.ceil((h - B*T) / (A-B)) if (h - B*T) >= 0 else 0 for h in hn]) return True if count <= T else False while True: med = int((maxT + minT) / 2) if enough(med): maxT = med else: minT = med if maxT - minT <= 1: break print(maxT)
26
22
558
486
# -*- coding:utf-8 -*- import math import sys line = input().split(" ") N = int(line[0]) A = int(line[1]) B = int(line[2]) hn = sorted([int(eval(input())) for i in range(N)]) maxT = int(hn[-1] / B) + 1 minT = 0 def enough(T): count = sum( [ math.ceil((h - B * T) / (A - B)) if math.ceil((h - B * T) / (A - B)) >= 0 else 0 for h in hn ] ) return True if count <= T else False while True: med = int((maxT + minT) / 2) if enough(med): maxT = med else: minT = med if maxT - minT <= 1: break print(maxT)
# -*- coding:utf-8 -*- import math N, A, B = list(map(int, input().split(" "))) hn = sorted([int(eval(input())) for i in range(N)]) maxT = int(hn[-1] / B) + 1 minT = 0 def enough(T): count = sum( [math.ceil((h - B * T) / (A - B)) if (h - B * T) >= 0 else 0 for h in hn] ) return True if count <= T else False while True: med = int((maxT + minT) / 2) if enough(med): maxT = med else: minT = med if maxT - minT <= 1: break print(maxT)
false
15.384615
[ "-import sys", "-line = input().split(\" \")", "-N = int(line[0])", "-A = int(line[1])", "-B = int(line[2])", "+N, A, B = list(map(int, input().split(\" \")))", "- [", "- math.ceil((h - B * T) / (A - B))", "- if math.ceil((h - B * T) / (A - B)) >= 0", "- els...
false
0.101041
0.046912
2.153838
[ "s168391366", "s971705751" ]
u716530146
p02981
python
s832139951
s923823073
170
21
38,256
3,316
Accepted
Accepted
87.65
#!/usr/bin/env python3 import sys, math input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8') sys.setrecursionlimit(10**8) inf = float('inf') ans=count=0 n,a,b=list(map(int,input().split())) print((min(b,a*n)))
#!/usr/bin/env python3 import sys, math, itertools, heapq, collections, bisect input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8') sys.setrecursionlimit(10**8) inf = float('inf') ans = count = 0 n,a,b=list(map(int,input().split())) print((min(n*a,b)))
10
9
228
269
#!/usr/bin/env python3 import sys, math input = lambda: sys.stdin.buffer.readline().rstrip().decode("utf-8") sys.setrecursionlimit(10**8) inf = float("inf") ans = count = 0 n, a, b = list(map(int, input().split())) print((min(b, a * n)))
#!/usr/bin/env python3 import sys, math, itertools, heapq, collections, bisect input = lambda: sys.stdin.buffer.readline().rstrip().decode("utf-8") sys.setrecursionlimit(10**8) inf = float("inf") ans = count = 0 n, a, b = list(map(int, input().split())) print((min(n * a, b)))
false
10
[ "-import sys, math", "+import sys, math, itertools, heapq, collections, bisect", "-print((min(b, a * n)))", "+print((min(n * a, b)))" ]
false
0.044004
0.038032
1.157017
[ "s832139951", "s923823073" ]
u903005414
p02683
python
s716558180
s458393165
157
95
27,128
9,132
Accepted
Accepted
39.49
import numpy as np N, M, X = list(map(int, input().split())) C = [] A = [] for _ in range(N): tmp = list(map(int, input().split())) c = tmp[0] a = tmp[1:] C.append(c) A.append(a) A = np.array(A) ans = 10**18 for bit in range(1 << N): cost = 0 V = np.array([0] * M) for i in range(N): if bit & 1 << i: cost += C[i] V += A[i] if np.all(V >= X): ans = min(ans, cost) if ans == 10**18: print((-1)) else: print(ans)
import itertools as it N, M, X = list(map(int, input().split())) book = [[int(_) for _ in input().split()] for i in range(N)] # print(f'book={book}') combs = it.product([0, 1], repeat=N) prices = [] for comb in combs: # print(comb) bag = [0] * (M + 1) for i in range(N): if comb[i] == 0: continue else: for j in range(M + 1): bag[j] += book[i][j] # print(f'bag={bag}') if min(bag[1:]) < X: continue else: prices.append(bag[0]) if len(prices) == 0: print((-1)) else: print((min(prices)))
27
24
515
604
import numpy as np N, M, X = list(map(int, input().split())) C = [] A = [] for _ in range(N): tmp = list(map(int, input().split())) c = tmp[0] a = tmp[1:] C.append(c) A.append(a) A = np.array(A) ans = 10**18 for bit in range(1 << N): cost = 0 V = np.array([0] * M) for i in range(N): if bit & 1 << i: cost += C[i] V += A[i] if np.all(V >= X): ans = min(ans, cost) if ans == 10**18: print((-1)) else: print(ans)
import itertools as it N, M, X = list(map(int, input().split())) book = [[int(_) for _ in input().split()] for i in range(N)] # print(f'book={book}') combs = it.product([0, 1], repeat=N) prices = [] for comb in combs: # print(comb) bag = [0] * (M + 1) for i in range(N): if comb[i] == 0: continue else: for j in range(M + 1): bag[j] += book[i][j] # print(f'bag={bag}') if min(bag[1:]) < X: continue else: prices.append(bag[0]) if len(prices) == 0: print((-1)) else: print((min(prices)))
false
11.111111
[ "-import numpy as np", "+import itertools as it", "-C = []", "-A = []", "-for _ in range(N):", "- tmp = list(map(int, input().split()))", "- c = tmp[0]", "- a = tmp[1:]", "- C.append(c)", "- A.append(a)", "-A = np.array(A)", "-ans = 10**18", "-for bit in range(1 << N):", "- ...
false
0.286424
0.19814
1.445568
[ "s716558180", "s458393165" ]
u840310460
p03469
python
s282347734
s939591517
168
18
38,256
2,940
Accepted
Accepted
89.29
S = [i for i in input().split("/")] if S[0] == "2017": print(("2018/"+S[1]+"/"+S[2]))
S = eval(input()) print((S.replace("2017", "2018")))
3
2
89
45
S = [i for i in input().split("/")] if S[0] == "2017": print(("2018/" + S[1] + "/" + S[2]))
S = eval(input()) print((S.replace("2017", "2018")))
false
33.333333
[ "-S = [i for i in input().split(\"/\")]", "-if S[0] == \"2017\":", "- print((\"2018/\" + S[1] + \"/\" + S[2]))", "+S = eval(input())", "+print((S.replace(\"2017\", \"2018\")))" ]
false
0.046949
0.067899
0.69146
[ "s282347734", "s939591517" ]
u634461820
p03013
python
s005929402
s600359845
675
254
471,684
17,144
Accepted
Accepted
62.37
import bisect from operator import itemgetter import math import functools import itertools import numpy as np import sys MAX_INT = int(10e10) MIN_INT = -MAX_INT mod = 1000000007 sys.setrecursionlimit(1000000) def IL(): return list(map(int,input().split())) def SL(): return input().split() def I(): return int(sys.stdin.readline()) def S(): return eval(input()) N,M = IL() a = [I() for i in range(M)] dp = [0]*(N+1) dp[0] = 1 for i in a: dp[i] = -1 for i in range(N+1): if dp[i] == -1: continue if i+1 <= N: if dp[i+1] != -1: dp[i+1] += dp[i] if i+2 <= N: if dp[i+2] != -1: dp[i+2] += dp[i] print((dp[N]%mod))
import bisect from operator import itemgetter import math import functools import itertools import numpy as np import sys MAX_INT = int(10e10) MIN_INT = -MAX_INT mod = 1000000007 sys.setrecursionlimit(1000000) def IL(): return list(map(int,input().split())) def SL(): return input().split() def I(): return int(sys.stdin.readline()) def S(): return eval(input()) N,M = IL() a = [I() for i in range(M)] dp = [0]*(N+1) dp[0] = 1 for i in a: dp[i] = -1 for i in range(N+1): if dp[i] == -1: continue if i+1 <= N: if dp[i+1] != -1: dp[i+1] += dp[i]%mod if i+2 <= N: if dp[i+2] != -1: dp[i+2] += dp[i]%mod print((dp[N]%mod))
36
36
681
683
import bisect from operator import itemgetter import math import functools import itertools import numpy as np import sys MAX_INT = int(10e10) MIN_INT = -MAX_INT mod = 1000000007 sys.setrecursionlimit(1000000) def IL(): return list(map(int, input().split())) def SL(): return input().split() def I(): return int(sys.stdin.readline()) def S(): return eval(input()) N, M = IL() a = [I() for i in range(M)] dp = [0] * (N + 1) dp[0] = 1 for i in a: dp[i] = -1 for i in range(N + 1): if dp[i] == -1: continue if i + 1 <= N: if dp[i + 1] != -1: dp[i + 1] += dp[i] if i + 2 <= N: if dp[i + 2] != -1: dp[i + 2] += dp[i] print((dp[N] % mod))
import bisect from operator import itemgetter import math import functools import itertools import numpy as np import sys MAX_INT = int(10e10) MIN_INT = -MAX_INT mod = 1000000007 sys.setrecursionlimit(1000000) def IL(): return list(map(int, input().split())) def SL(): return input().split() def I(): return int(sys.stdin.readline()) def S(): return eval(input()) N, M = IL() a = [I() for i in range(M)] dp = [0] * (N + 1) dp[0] = 1 for i in a: dp[i] = -1 for i in range(N + 1): if dp[i] == -1: continue if i + 1 <= N: if dp[i + 1] != -1: dp[i + 1] += dp[i] % mod if i + 2 <= N: if dp[i + 2] != -1: dp[i + 2] += dp[i] % mod print((dp[N] % mod))
false
0
[ "- dp[i + 1] += dp[i]", "+ dp[i + 1] += dp[i] % mod", "- dp[i + 2] += dp[i]", "+ dp[i + 2] += dp[i] % mod" ]
false
0.046964
0.037617
1.248493
[ "s005929402", "s600359845" ]
u953237709
p03062
python
s100935795
s837216596
164
97
16,800
15,020
Accepted
Accepted
40.85
n = int(eval(input())) a = list(map(int, input().split())) def solveDp(): POS, NEG = 0, 1 dp = [[0 for _ in range(n + 1)] for _ in range(2)] dp[NEG][0] = -float('inf') for i in range(n): dp[POS][i + 1] = max(dp[POS][i] + a[i], dp[NEG][i] - a[i]) dp[NEG][i + 1] = max(dp[POS][i] - a[i], dp[NEG][i] + a[i]) print((dp[POS][n])) def solve(): nNegative = 0 total = 0 minVal = float('inf') for num in a: if num < 0: num *= -1 nNegative += 1 minVal = min(minVal, num) total += num print((total if nNegative & 1 == 0 else total - 2 * minVal)) solveDp()
n = int(eval(input())) a = list(map(int, input().split())) negCnt = 0 absSum = 0 minAbs = float('inf') for val in a: negCnt += val < 0 absVal = abs(val) absSum += absVal minAbs = min(minAbs, absVal) print((absSum - 2 * minAbs if negCnt & 1 else absSum))
25
12
665
273
n = int(eval(input())) a = list(map(int, input().split())) def solveDp(): POS, NEG = 0, 1 dp = [[0 for _ in range(n + 1)] for _ in range(2)] dp[NEG][0] = -float("inf") for i in range(n): dp[POS][i + 1] = max(dp[POS][i] + a[i], dp[NEG][i] - a[i]) dp[NEG][i + 1] = max(dp[POS][i] - a[i], dp[NEG][i] + a[i]) print((dp[POS][n])) def solve(): nNegative = 0 total = 0 minVal = float("inf") for num in a: if num < 0: num *= -1 nNegative += 1 minVal = min(minVal, num) total += num print((total if nNegative & 1 == 0 else total - 2 * minVal)) solveDp()
n = int(eval(input())) a = list(map(int, input().split())) negCnt = 0 absSum = 0 minAbs = float("inf") for val in a: negCnt += val < 0 absVal = abs(val) absSum += absVal minAbs = min(minAbs, absVal) print((absSum - 2 * minAbs if negCnt & 1 else absSum))
false
52
[ "-", "-", "-def solveDp():", "- POS, NEG = 0, 1", "- dp = [[0 for _ in range(n + 1)] for _ in range(2)]", "- dp[NEG][0] = -float(\"inf\")", "- for i in range(n):", "- dp[POS][i + 1] = max(dp[POS][i] + a[i], dp[NEG][i] - a[i])", "- dp[NEG][i + 1] = max(dp[POS][i] - a[i], dp[...
false
0.047457
0.046583
1.018753
[ "s100935795", "s837216596" ]
u282228874
p04045
python
s736814111
s937489161
103
84
2,940
2,940
Accepted
Accepted
18.45
n,k = list(map(int,input().split())) D = list(input().split()) while True: if any (d in str(n) for d in D): n += 1 else: print(n) exit()
n,k = list(map(int,input().split())) d = set(eval(input())) while len(set(str(n))&d): n += 1 print(n)
8
5
146
94
n, k = list(map(int, input().split())) D = list(input().split()) while True: if any(d in str(n) for d in D): n += 1 else: print(n) exit()
n, k = list(map(int, input().split())) d = set(eval(input())) while len(set(str(n)) & d): n += 1 print(n)
false
37.5
[ "-D = list(input().split())", "-while True:", "- if any(d in str(n) for d in D):", "- n += 1", "- else:", "- print(n)", "- exit()", "+d = set(eval(input()))", "+while len(set(str(n)) & d):", "+ n += 1", "+print(n)" ]
false
0.080722
0.049359
1.635416
[ "s736814111", "s937489161" ]
u141610915
p03949
python
s052196084
s831652621
829
326
98,652
146,616
Accepted
Accepted
60.68
import sys from collections import defaultdict as dd from collections import deque as dq import heapq hpush = heapq.heappush hpop = heapq.heappop input = sys.stdin.readline N = int(eval(input())) e = dd(list) for _ in range(N - 1): u, v = list(map(int, input().split())) e[u].append(v) e[v].append(u) K = int(eval(input())) ls = [-10 ** 10] * (N + 1) rs = [10 ** 10] * (N + 1) Q = dq([]) h = [] res = [-10 ** 10] * (N + 1) for _ in range(K): x, v = list(map(int, input().split())) ls[x] = v rs[x] = v hpush(h, (v, x)) res[x] = v Q.append(x) vis = [0] * (N + 1) while len(Q): x = Q.popleft() if vis[x]: continue vis[x] = 1 for y in e[x]: ls[y] = max(ls[y], ls[x] - 1) rs[y] = min(rs[y], rs[x] + 1) if ls[y] % 2 == ls[x] % 2: print("No") exit(0) if vis[y]: continue Q.append(y) for x in range(1, N + 1): if ls[x] > rs[x]: print("No") exit(0) while len(h): _, x = hpop(h) for y in e[x]: if res[y] != -10 ** 10: continue res[y] = res[x] + 1 hpush(h, (res[y], y)) #print(res, h) print("Yes") for r in res[1: ]: print(r)
import sys input = sys.stdin.readline N = int(eval(input())) e = [[] for _ in range(N + 1)] for _ in range(N - 1): u, v = list(map(int, input().split())) e[u].append(v) e[v].append(u) s = [1] color = [0] * (N + 1) color[1] = 1 while len(s): x = s.pop() for y in e[x]: if color[y]: if color[x] == color[y]: break continue s.append(y) color[y] = color[x] ^ 2 else: continue print("No") exit(0) res = [-1] * (N + 1) mx = 0 for _ in range(int(eval(input()))): v, p = list(map(int, input().split())) res[v] = p mx = max(mx, p) table = [[] for _ in range(mx + 1 + N + 1)] for i in range(N + 1): if res[i] != -1: table[res[i]].append(i) for i in range(mx + N + 1): while len(table[i]): x = table[i].pop() for y in e[x]: if res[y] == -1: res[y] = res[x] + 1 table[i + 1].append(y) elif abs(res[x] - res[y]) != 1: break else: continue break else: continue break else: print("Yes") for r in res[1: ]: print(r) exit(0) print("No")
59
51
1,141
1,059
import sys from collections import defaultdict as dd from collections import deque as dq import heapq hpush = heapq.heappush hpop = heapq.heappop input = sys.stdin.readline N = int(eval(input())) e = dd(list) for _ in range(N - 1): u, v = list(map(int, input().split())) e[u].append(v) e[v].append(u) K = int(eval(input())) ls = [-(10**10)] * (N + 1) rs = [10**10] * (N + 1) Q = dq([]) h = [] res = [-(10**10)] * (N + 1) for _ in range(K): x, v = list(map(int, input().split())) ls[x] = v rs[x] = v hpush(h, (v, x)) res[x] = v Q.append(x) vis = [0] * (N + 1) while len(Q): x = Q.popleft() if vis[x]: continue vis[x] = 1 for y in e[x]: ls[y] = max(ls[y], ls[x] - 1) rs[y] = min(rs[y], rs[x] + 1) if ls[y] % 2 == ls[x] % 2: print("No") exit(0) if vis[y]: continue Q.append(y) for x in range(1, N + 1): if ls[x] > rs[x]: print("No") exit(0) while len(h): _, x = hpop(h) for y in e[x]: if res[y] != -(10**10): continue res[y] = res[x] + 1 hpush(h, (res[y], y)) # print(res, h) print("Yes") for r in res[1:]: print(r)
import sys input = sys.stdin.readline N = int(eval(input())) e = [[] for _ in range(N + 1)] for _ in range(N - 1): u, v = list(map(int, input().split())) e[u].append(v) e[v].append(u) s = [1] color = [0] * (N + 1) color[1] = 1 while len(s): x = s.pop() for y in e[x]: if color[y]: if color[x] == color[y]: break continue s.append(y) color[y] = color[x] ^ 2 else: continue print("No") exit(0) res = [-1] * (N + 1) mx = 0 for _ in range(int(eval(input()))): v, p = list(map(int, input().split())) res[v] = p mx = max(mx, p) table = [[] for _ in range(mx + 1 + N + 1)] for i in range(N + 1): if res[i] != -1: table[res[i]].append(i) for i in range(mx + N + 1): while len(table[i]): x = table[i].pop() for y in e[x]: if res[y] == -1: res[y] = res[x] + 1 table[i + 1].append(y) elif abs(res[x] - res[y]) != 1: break else: continue break else: continue break else: print("Yes") for r in res[1:]: print(r) exit(0) print("No")
false
13.559322
[ "-from collections import defaultdict as dd", "-from collections import deque as dq", "-import heapq", "-hpush = heapq.heappush", "-hpop = heapq.heappop", "-e = dd(list)", "+e = [[] for _ in range(N + 1)]", "-K = int(eval(input()))", "-ls = [-(10**10)] * (N + 1)", "-rs = [10**10] * (N + 1)", "-Q...
false
0.03684
0.034904
1.055458
[ "s052196084", "s831652621" ]
u547085427
p03311
python
s804655068
s311523371
229
201
25,196
26,708
Accepted
Accepted
12.23
N = int(eval(input())) A = list(map(int,input().split())) for i in range(N): A[i] -= i A.sort() Ans = 0 mi = len(A)//2 # 中央値のindex for i in range(N): Ans += abs(A[i]-A[mi]) print(Ans)
n = int(eval(input())) a = list(map(int, input().split())) b = [(a[i] - i) for i in range(n)] b.sort() num = b[ n // 2] result = 0 for i in b: result += abs(num - i) print(result)
14
12
206
194
N = int(eval(input())) A = list(map(int, input().split())) for i in range(N): A[i] -= i A.sort() Ans = 0 mi = len(A) // 2 # 中央値のindex for i in range(N): Ans += abs(A[i] - A[mi]) print(Ans)
n = int(eval(input())) a = list(map(int, input().split())) b = [(a[i] - i) for i in range(n)] b.sort() num = b[n // 2] result = 0 for i in b: result += abs(num - i) print(result)
false
14.285714
[ "-N = int(eval(input()))", "-A = list(map(int, input().split()))", "-for i in range(N):", "- A[i] -= i", "-A.sort()", "-Ans = 0", "-mi = len(A) // 2 # 中央値のindex", "-for i in range(N):", "- Ans += abs(A[i] - A[mi])", "-print(Ans)", "+n = int(eval(input()))", "+a = list(map(int, input().s...
false
0.077752
0.044609
1.742981
[ "s804655068", "s311523371" ]
u803617136
p02981
python
s560363729
s903938617
174
19
38,256
2,940
Accepted
Accepted
89.08
N, A, B = list(map(int, input().split())) print((min(N * A, B)))
n, a, b = list(map(int, input().split())) ans = min(n * a, b) print(ans)
2
3
57
68
N, A, B = list(map(int, input().split())) print((min(N * A, B)))
n, a, b = list(map(int, input().split())) ans = min(n * a, b) print(ans)
false
33.333333
[ "-N, A, B = list(map(int, input().split()))", "-print((min(N * A, B)))", "+n, a, b = list(map(int, input().split()))", "+ans = min(n * a, b)", "+print(ans)" ]
false
0.0413
0.036438
1.133425
[ "s560363729", "s903938617" ]
u832039789
p02577
python
s228425459
s286761763
197
174
68,852
78,016
Accepted
Accepted
11.68
print(('YNeos'[int(eval(input()))%9>0::2]))
print("YNeos"[eval(input())%9>0::2])
1
1
35
28
print(("YNeos"[int(eval(input())) % 9 > 0 :: 2]))
print("YNeos"[eval(input()) % 9 > 0 :: 2])
false
0
[ "-print((\"YNeos\"[int(eval(input())) % 9 > 0 :: 2]))", "+print(\"YNeos\"[eval(input()) % 9 > 0 :: 2])" ]
false
0.036326
0.053802
0.675184
[ "s228425459", "s286761763" ]
u477977638
p02936
python
s644931429
s118971745
1,999
1,688
90,116
64,128
Accepted
Accepted
15.56
import collections n,q=list(map(int,input().split())) a=sorted(list(list(map(int,input().split())) for i in range(n-1))) p=collections.defaultdict(int) for i in range(q): k,v=list(map(int,input().split())) p[k]+=v li=[0]*n li[0]+=p[1] for i in range(n-1): li[a[i][1]-1]+=li[a[i][0]-1]+p[a[i][1]] print((*li))
from collections import deque n,q=list(map(int,input().split())) li=[[] for i in range(n+1)] ans=[0]*(n+1) for i in range(n-1): a,b=list(map(int,input().split())) li[a].append(b) li[b].append(a) for i in range(q): p,x=list(map(int,input().split())) ans[p]+=x Q=deque([1]) sumi=set([1]) while Q: # print(Q) now=Q.pop() for i in li[now]: if i in sumi: continue else: sumi.add(i) Q.append(i) ans[i]+=ans[now] print((*ans[1:]))
14
30
315
486
import collections n, q = list(map(int, input().split())) a = sorted(list(list(map(int, input().split())) for i in range(n - 1))) p = collections.defaultdict(int) for i in range(q): k, v = list(map(int, input().split())) p[k] += v li = [0] * n li[0] += p[1] for i in range(n - 1): li[a[i][1] - 1] += li[a[i][0] - 1] + p[a[i][1]] print((*li))
from collections import deque n, q = list(map(int, input().split())) li = [[] for i in range(n + 1)] ans = [0] * (n + 1) for i in range(n - 1): a, b = list(map(int, input().split())) li[a].append(b) li[b].append(a) for i in range(q): p, x = list(map(int, input().split())) ans[p] += x Q = deque([1]) sumi = set([1]) while Q: # print(Q) now = Q.pop() for i in li[now]: if i in sumi: continue else: sumi.add(i) Q.append(i) ans[i] += ans[now] print((*ans[1:]))
false
53.333333
[ "-import collections", "+from collections import deque", "-a = sorted(list(list(map(int, input().split())) for i in range(n - 1)))", "-p = collections.defaultdict(int)", "+li = [[] for i in range(n + 1)]", "+ans = [0] * (n + 1)", "+for i in range(n - 1):", "+ a, b = list(map(int, input().split()))"...
false
0.088794
0.047476
1.870309
[ "s644931429", "s118971745" ]
u254871849
p03611
python
s761108469
s935743300
150
106
18,352
19,056
Accepted
Accepted
29.33
import sys from collections import defaultdict cnt = defaultdict(int) def main(): n, *a = list(map(int, sys.stdin.read().split())) a.sort() l = a[0] r = a[-1] for val in a: cnt[val] += 1 ans = 0 for i in range(l, r+1): ans = max(ans, cnt[i-1] + cnt[i] + cnt[i+1]) print(ans) if __name__ == '__main__': main()
import sys from collections import defaultdict n, *a = list(map(int, sys.stdin.read().split())) def main(): res = defaultdict(int) for i in a: res[i-1] += 1 res[i] += 1 res[i+1] += 1 return max(res.values()) if __name__ == '__main__': ans = main() print(ans)
22
17
385
321
import sys from collections import defaultdict cnt = defaultdict(int) def main(): n, *a = list(map(int, sys.stdin.read().split())) a.sort() l = a[0] r = a[-1] for val in a: cnt[val] += 1 ans = 0 for i in range(l, r + 1): ans = max(ans, cnt[i - 1] + cnt[i] + cnt[i + 1]) print(ans) if __name__ == "__main__": main()
import sys from collections import defaultdict n, *a = list(map(int, sys.stdin.read().split())) def main(): res = defaultdict(int) for i in a: res[i - 1] += 1 res[i] += 1 res[i + 1] += 1 return max(res.values()) if __name__ == "__main__": ans = main() print(ans)
false
22.727273
[ "-cnt = defaultdict(int)", "+n, *a = list(map(int, sys.stdin.read().split()))", "- n, *a = list(map(int, sys.stdin.read().split()))", "- a.sort()", "- l = a[0]", "- r = a[-1]", "- for val in a:", "- cnt[val] += 1", "- ans = 0", "- for i in range(l, r + 1):", "- ...
false
0.037571
0.07989
0.470287
[ "s761108469", "s935743300" ]
u533232830
p02579
python
s197310302
s772878465
1,074
722
210,980
128,368
Accepted
Accepted
32.77
from collections import deque h, w = list(map(int, input().split())) C = list(map(int, input().split())) C = tuple([C[0]-1, C[1]-1]) D = tuple(map(int, input().split())) D = tuple([D[0]-1, D[1]-1]) maze = [list(eval(input())) for _ in range(h)] visit = [[False]*w for _ in range(h)] for i in range(h): for j in range(w): if maze[i][j] == "#": visit[i][j] = True DQ = deque([C]) DQ_warp = deque([]) dx = [1, 0, -1, 0] dy = [0, 1, 0, -1] ans = 0 while DQ or DQ_warp: while DQ: now = DQ.popleft() if now == D: print(ans) exit() x, y = now[0], now[1] if visit[x][y]: continue visit[x][y] = True for i in range(4): nx = x + dx[i] ny = y + dy[i] if 0<=nx<=h-1 and 0<=ny<=w-1 and visit[nx][ny]==False: DQ.append(tuple([nx, ny])) for i in range(-2, 3): for j in range(-2, 3): if i == j == 0: continue nx = x + i ny = y + j if 0<=nx<=h-1 and 0<=ny<=w-1 and visit[nx][ny]==False: DQ_warp.append(tuple([nx, ny])) if DQ_warp: DQ = DQ_warp.copy() DQ_warp = deque([]) ans += 1 print((-1))
from collections import deque H, W = list(map(int, input().split())) Ch, Cw = list(map(int, input().split())) Dh, Dw = list(map(int, input().split())) Ch, Cw, Dh, Dw = Ch-1, Cw-1, Dh-1, Dw-1 maze = [list(eval(input())) for _ in range(H)] visit = [[-1] * W for _ in range(H)] visit[Ch][Cw] = 0 DQ = deque([(Ch, Cw)]) dx = [1, 0, -1, 0] dy = [0, 1, 0, -1] while DQ: px, py = DQ.popleft() if (px, py) == (Dh, Dw): print((visit[px][py])) exit() for i in range(4): nx = px + dx[i] ny = py + dy[i] if 0<=nx<=H-1 and 0<=ny<=W-1 and maze[nx][ny]=="." and (visit[nx][ny]>visit[px][py] or visit[nx][ny]==-1): visit[nx][ny] = visit[px][py] DQ.appendleft((nx, ny)) for i in range(-2, 3): for j in range(-2, 3): if i == j == 0: continue nx = px + i ny = py + j if 0<=nx<=H-1 and 0<=ny<=W-1 and maze[nx][ny]=="." and visit[nx][ny]==-1: visit[nx][ny] = visit[px][py] + 1 DQ.append((nx, ny)) # for a in visit: # print(a) print((-1))
53
44
1,317
1,137
from collections import deque h, w = list(map(int, input().split())) C = list(map(int, input().split())) C = tuple([C[0] - 1, C[1] - 1]) D = tuple(map(int, input().split())) D = tuple([D[0] - 1, D[1] - 1]) maze = [list(eval(input())) for _ in range(h)] visit = [[False] * w for _ in range(h)] for i in range(h): for j in range(w): if maze[i][j] == "#": visit[i][j] = True DQ = deque([C]) DQ_warp = deque([]) dx = [1, 0, -1, 0] dy = [0, 1, 0, -1] ans = 0 while DQ or DQ_warp: while DQ: now = DQ.popleft() if now == D: print(ans) exit() x, y = now[0], now[1] if visit[x][y]: continue visit[x][y] = True for i in range(4): nx = x + dx[i] ny = y + dy[i] if 0 <= nx <= h - 1 and 0 <= ny <= w - 1 and visit[nx][ny] == False: DQ.append(tuple([nx, ny])) for i in range(-2, 3): for j in range(-2, 3): if i == j == 0: continue nx = x + i ny = y + j if 0 <= nx <= h - 1 and 0 <= ny <= w - 1 and visit[nx][ny] == False: DQ_warp.append(tuple([nx, ny])) if DQ_warp: DQ = DQ_warp.copy() DQ_warp = deque([]) ans += 1 print((-1))
from collections import deque H, W = list(map(int, input().split())) Ch, Cw = list(map(int, input().split())) Dh, Dw = list(map(int, input().split())) Ch, Cw, Dh, Dw = Ch - 1, Cw - 1, Dh - 1, Dw - 1 maze = [list(eval(input())) for _ in range(H)] visit = [[-1] * W for _ in range(H)] visit[Ch][Cw] = 0 DQ = deque([(Ch, Cw)]) dx = [1, 0, -1, 0] dy = [0, 1, 0, -1] while DQ: px, py = DQ.popleft() if (px, py) == (Dh, Dw): print((visit[px][py])) exit() for i in range(4): nx = px + dx[i] ny = py + dy[i] if ( 0 <= nx <= H - 1 and 0 <= ny <= W - 1 and maze[nx][ny] == "." and (visit[nx][ny] > visit[px][py] or visit[nx][ny] == -1) ): visit[nx][ny] = visit[px][py] DQ.appendleft((nx, ny)) for i in range(-2, 3): for j in range(-2, 3): if i == j == 0: continue nx = px + i ny = py + j if ( 0 <= nx <= H - 1 and 0 <= ny <= W - 1 and maze[nx][ny] == "." and visit[nx][ny] == -1 ): visit[nx][ny] = visit[px][py] + 1 DQ.append((nx, ny)) # for a in visit: # print(a) print((-1))
false
16.981132
[ "-h, w = list(map(int, input().split()))", "-C = list(map(int, input().split()))", "-C = tuple([C[0] - 1, C[1] - 1])", "-D = tuple(map(int, input().split()))", "-D = tuple([D[0] - 1, D[1] - 1])", "-maze = [list(eval(input())) for _ in range(h)]", "-visit = [[False] * w for _ in range(h)]", "-for i in ...
false
0.082049
0.038378
2.137938
[ "s197310302", "s772878465" ]
u672898046
p03610
python
s922155107
s685138242
85
17
4,596
3,188
Accepted
Accepted
80
s = input() for i, r in enumerate(s): if i%2==0: print(r, end="")
s = eval(input()) print((s[::2]))
4
2
74
26
s = input() for i, r in enumerate(s): if i % 2 == 0: print(r, end="")
s = eval(input()) print((s[::2]))
false
50
[ "-s = input()", "-for i, r in enumerate(s):", "- if i % 2 == 0:", "- print(r, end=\"\")", "+s = eval(input())", "+print((s[::2]))" ]
false
0.037878
0.03884
0.975251
[ "s922155107", "s685138242" ]
u671060652
p02922
python
s072430727
s701347976
173
63
39,824
61,840
Accepted
Accepted
63.58
a, b = list(map(int, input().split())) n = 0 while a*n-(n-1) < b: n += 1 print(n)
def main(): # n = int(input()) n, k = list(map(int, input().split())) # h = list(map(int, input().split())) # s = input() ans = 0 while True: if (n - 1) * ans + 1 >= k: print(ans) break ans += 1 if __name__ == '__main__': main()
7
16
88
309
a, b = list(map(int, input().split())) n = 0 while a * n - (n - 1) < b: n += 1 print(n)
def main(): # n = int(input()) n, k = list(map(int, input().split())) # h = list(map(int, input().split())) # s = input() ans = 0 while True: if (n - 1) * ans + 1 >= k: print(ans) break ans += 1 if __name__ == "__main__": main()
false
56.25
[ "-a, b = list(map(int, input().split()))", "-n = 0", "-while a * n - (n - 1) < b:", "- n += 1", "-print(n)", "+def main():", "+ # n = int(input())", "+ n, k = list(map(int, input().split()))", "+ # h = list(map(int, input().split()))", "+ # s = input()", "+ ans = 0", "+ wh...
false
0.037399
0.007548
4.954834
[ "s072430727", "s701347976" ]
u254871849
p03776
python
s126600602
s821186120
38
20
5,404
3,188
Accepted
Accepted
47.37
from statistics import mean nCr = {} def cmb(n, r): if n < r: return 0 if r == 0 or r == n: return 1 if r == 1: return n if (n,r) in nCr: return nCr[(n,r)] nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1) return nCr[(n,r)] n, a, b = [int(_) for _ in input().split()] values = [int(v) for v in input().split()] values.sort(reverse=True) maximum_mean = mean(values[:a]) print(maximum_mean) min_value = values[:a][-1] accepted = values[:a].count(min_value) full = values.count(min_value) if min_value == maximum_mean: ans = 0 for r in range(a, b+1): ans += cmb(full, r) else: ans = cmb(full, accepted) print(ans)
nCr = {} def cmb(n, r): if n < r: return 0 if r == 0 or r == n: return 1 if r == 1: return n if (n,r) in nCr: return nCr[(n,r)] nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1) return nCr[(n,r)] n, a, b = [int(_) for _ in input().split()] values = [int(v) for v in input().split()] values.sort(reverse=True) maximum_mean = sum(values[:a]) / a print(maximum_mean) min_value = values[:a][-1] accepted = values[:a].count(min_value) full = values.count(min_value) if min_value == maximum_mean: ans = 0 for r in range(a, b+1): ans += cmb(full, r) else: ans = cmb(full, accepted) print(ans)
30
28
688
660
from statistics import mean nCr = {} def cmb(n, r): if n < r: return 0 if r == 0 or r == n: return 1 if r == 1: return n if (n, r) in nCr: return nCr[(n, r)] nCr[(n, r)] = cmb(n - 1, r) + cmb(n - 1, r - 1) return nCr[(n, r)] n, a, b = [int(_) for _ in input().split()] values = [int(v) for v in input().split()] values.sort(reverse=True) maximum_mean = mean(values[:a]) print(maximum_mean) min_value = values[:a][-1] accepted = values[:a].count(min_value) full = values.count(min_value) if min_value == maximum_mean: ans = 0 for r in range(a, b + 1): ans += cmb(full, r) else: ans = cmb(full, accepted) print(ans)
nCr = {} def cmb(n, r): if n < r: return 0 if r == 0 or r == n: return 1 if r == 1: return n if (n, r) in nCr: return nCr[(n, r)] nCr[(n, r)] = cmb(n - 1, r) + cmb(n - 1, r - 1) return nCr[(n, r)] n, a, b = [int(_) for _ in input().split()] values = [int(v) for v in input().split()] values.sort(reverse=True) maximum_mean = sum(values[:a]) / a print(maximum_mean) min_value = values[:a][-1] accepted = values[:a].count(min_value) full = values.count(min_value) if min_value == maximum_mean: ans = 0 for r in range(a, b + 1): ans += cmb(full, r) else: ans = cmb(full, accepted) print(ans)
false
6.666667
[ "-from statistics import mean", "-", "-maximum_mean = mean(values[:a])", "+maximum_mean = sum(values[:a]) / a" ]
false
0.122961
0.143418
0.857361
[ "s126600602", "s821186120" ]
u427344224
p03127
python
s630667208
s105983449
100
87
14,252
14,252
Accepted
Accepted
13
N = int(eval(input())) a_list = list(map(int, input().split())) import fractions num = a_list[0] for i in range(N): a = a_list[i] num = fractions.gcd(num, a) print(num)
N = int(eval(input())) a_list = list(map(int, input().split())) def gcd(a, b): return a if b == 0 else gcd(b, a % b) ans = a_list[0] for i in range(N): ans = gcd(ans, a_list[i]) print(ans)
11
13
184
208
N = int(eval(input())) a_list = list(map(int, input().split())) import fractions num = a_list[0] for i in range(N): a = a_list[i] num = fractions.gcd(num, a) print(num)
N = int(eval(input())) a_list = list(map(int, input().split())) def gcd(a, b): return a if b == 0 else gcd(b, a % b) ans = a_list[0] for i in range(N): ans = gcd(ans, a_list[i]) print(ans)
false
15.384615
[ "-import fractions", "-num = a_list[0]", "+", "+def gcd(a, b):", "+ return a if b == 0 else gcd(b, a % b)", "+", "+", "+ans = a_list[0]", "- a = a_list[i]", "- num = fractions.gcd(num, a)", "-print(num)", "+ ans = gcd(ans, a_list[i])", "+print(ans)" ]
false
0.117957
0.102162
1.154606
[ "s630667208", "s105983449" ]
u467736898
p02868
python
s918046334
s853286688
1,758
1,190
112,152
77,272
Accepted
Accepted
32.31
# https://atcoder.jp/contests/abc014/submissions/3935971 class SegmentTree(object): __slots__ = ["elem_size", "tree", "default", "op"] def __init__(self, a: list, default: int, op): from math import ceil, log real_size = len(a) self.elem_size = elem_size = 1 << ceil(log(real_size, 2)) self.tree = tree = [default] * (elem_size * 2) tree[elem_size:elem_size + real_size] = a self.default = default self.op = op for i in range(elem_size - 1, 0, -1): tree[i] = op(tree[i << 1], tree[(i << 1) + 1]) def get_value(self, x: int, y: int) -> int: # 半開区間 l, r = x + self.elem_size, y + self.elem_size tree, result, op = self.tree, self.default, self.op while l < r: if l & 1: result = op(tree[l], result) l += 1 if r & 1: r -= 1 result = op(tree[r], result) l, r = l >> 1, r >> 1 return result def set_value(self, i: int, value: int) -> None: k = self.elem_size + i self.tree[k] = value self.update(k) def update(self, i: int) -> None: op, tree = self.op, self.tree while i > 1: i >>= 1 tree[i] = op(tree[i << 1], tree[(i << 1) + 1]) from operator import itemgetter N, M = list(map(int, input().split())) LRC = [list(map(int, input().split())) for _ in range(M)] LRC.sort(key=itemgetter(0)) idx_LRC = 0 q = [] seg = SegmentTree([float("inf")] * (N+1), float("inf"), min) seg.set_value(1, 0) for v in range(1, N+1): d = seg.get_value(v, N+1) while idx_LRC < M: l, r, c = LRC[idx_LRC] if l <= v: seg.set_value(r, min(seg.tree[r+seg.elem_size], d + c)) idx_LRC += 1 else: break ans = seg.tree[N+seg.elem_size] print((ans if ans!=float("inf") else -1))
# https://atcoder.jp/contests/nikkei2019-2-qual/submissions/8357999 を # 平方分割に書き換えた class Rmq: # 平方分割 # 値を変更すると元のリストの値も書き換わる def __init__(self, a, sqrt_n=500): from itertools import zip_longest self.n = len(a) self.sqrt_n = sqrt_n self.layer1 = a self.layer0 = [min(values) for values in zip_longest(*[iter(a)]*sqrt_n, fillvalue=float("inf"))] def get_min(self, l, r): sqrt_n = self.sqrt_n parent_l, parent_r = l//sqrt_n+1, (r+1)//sqrt_n if parent_l < parent_r: return min(min(self.layer0[parent_l:parent_r]), min(self.layer1[l:parent_l*sqrt_n]), min(self.layer1[parent_r*sqrt_n:r])) else: return min(self.layer1[l:r]) def set_value(self, idx, val): self.layer1[idx] = val idx //= self.sqrt_n self.layer0[idx] = min(self.layer0[idx], val) def chmin(self, idx, val): if self.layer1[idx] > val: self.set_value(idx, val) def debug(self): print(("layer0=", self.layer0)) print(("layer1=", self.layer1)) def __getitem__(self, item): return self.layer1[item] def __setitem__(self, key, value): self.set_value(key, value) from operator import itemgetter N, M = list(map(int, input().split())) LRC = [list(map(int, input().split())) for _ in range(M)] LRC.sort(key=itemgetter(0)) idx_LRC = 0 q = [] rmq = Rmq([float("inf")] * (N+1)) rmq.set_value(1, 0) for v in range(1, N+1): d = rmq.get_min(v, N+1) while idx_LRC < M: l, r, c = LRC[idx_LRC] if l <= v: rmq.chmin(r, d+c) idx_LRC += 1 else: break ans = rmq[N] print((ans if ans != float("inf") else -1))
60
66
1,960
1,833
# https://atcoder.jp/contests/abc014/submissions/3935971 class SegmentTree(object): __slots__ = ["elem_size", "tree", "default", "op"] def __init__(self, a: list, default: int, op): from math import ceil, log real_size = len(a) self.elem_size = elem_size = 1 << ceil(log(real_size, 2)) self.tree = tree = [default] * (elem_size * 2) tree[elem_size : elem_size + real_size] = a self.default = default self.op = op for i in range(elem_size - 1, 0, -1): tree[i] = op(tree[i << 1], tree[(i << 1) + 1]) def get_value(self, x: int, y: int) -> int: # 半開区間 l, r = x + self.elem_size, y + self.elem_size tree, result, op = self.tree, self.default, self.op while l < r: if l & 1: result = op(tree[l], result) l += 1 if r & 1: r -= 1 result = op(tree[r], result) l, r = l >> 1, r >> 1 return result def set_value(self, i: int, value: int) -> None: k = self.elem_size + i self.tree[k] = value self.update(k) def update(self, i: int) -> None: op, tree = self.op, self.tree while i > 1: i >>= 1 tree[i] = op(tree[i << 1], tree[(i << 1) + 1]) from operator import itemgetter N, M = list(map(int, input().split())) LRC = [list(map(int, input().split())) for _ in range(M)] LRC.sort(key=itemgetter(0)) idx_LRC = 0 q = [] seg = SegmentTree([float("inf")] * (N + 1), float("inf"), min) seg.set_value(1, 0) for v in range(1, N + 1): d = seg.get_value(v, N + 1) while idx_LRC < M: l, r, c = LRC[idx_LRC] if l <= v: seg.set_value(r, min(seg.tree[r + seg.elem_size], d + c)) idx_LRC += 1 else: break ans = seg.tree[N + seg.elem_size] print((ans if ans != float("inf") else -1))
# https://atcoder.jp/contests/nikkei2019-2-qual/submissions/8357999 を # 平方分割に書き換えた class Rmq: # 平方分割 # 値を変更すると元のリストの値も書き換わる def __init__(self, a, sqrt_n=500): from itertools import zip_longest self.n = len(a) self.sqrt_n = sqrt_n self.layer1 = a self.layer0 = [ min(values) for values in zip_longest(*[iter(a)] * sqrt_n, fillvalue=float("inf")) ] def get_min(self, l, r): sqrt_n = self.sqrt_n parent_l, parent_r = l // sqrt_n + 1, (r + 1) // sqrt_n if parent_l < parent_r: return min( min(self.layer0[parent_l:parent_r]), min(self.layer1[l : parent_l * sqrt_n]), min(self.layer1[parent_r * sqrt_n : r]), ) else: return min(self.layer1[l:r]) def set_value(self, idx, val): self.layer1[idx] = val idx //= self.sqrt_n self.layer0[idx] = min(self.layer0[idx], val) def chmin(self, idx, val): if self.layer1[idx] > val: self.set_value(idx, val) def debug(self): print(("layer0=", self.layer0)) print(("layer1=", self.layer1)) def __getitem__(self, item): return self.layer1[item] def __setitem__(self, key, value): self.set_value(key, value) from operator import itemgetter N, M = list(map(int, input().split())) LRC = [list(map(int, input().split())) for _ in range(M)] LRC.sort(key=itemgetter(0)) idx_LRC = 0 q = [] rmq = Rmq([float("inf")] * (N + 1)) rmq.set_value(1, 0) for v in range(1, N + 1): d = rmq.get_min(v, N + 1) while idx_LRC < M: l, r, c = LRC[idx_LRC] if l <= v: rmq.chmin(r, d + c) idx_LRC += 1 else: break ans = rmq[N] print((ans if ans != float("inf") else -1))
false
9.090909
[ "-# https://atcoder.jp/contests/abc014/submissions/3935971", "-class SegmentTree(object):", "- __slots__ = [\"elem_size\", \"tree\", \"default\", \"op\"]", "+# https://atcoder.jp/contests/nikkei2019-2-qual/submissions/8357999 を", "+# 平方分割に書き換えた", "+class Rmq:", "+ # 平方分割", "+ # 値を変更すると元のリストの値...
false
0.045755
0.045839
0.998175
[ "s918046334", "s853286688" ]
u562935282
p02852
python
s137680600
s176021379
249
85
15,084
11,388
Accepted
Accepted
65.86
# https://atcoder.jp/contests/abc146/submissions/8617148 def solve(N, M, S): from collections import namedtuple from heapq import heappop, heappush INF = N * 2 V = namedtuple('V', 'cnt index') cnt_from_N = [INF] * (N + 1) cnt_from_N[N] = 0 parent = [0] * (N + 1) h = [V(cnt=0, index=N)] for j in range(N - 1, -1, -1): # S[j]に到達する最小回数とその経路を求める if S[j]: continue while h: cnt, par = h[0] if par > j + M: # jまで移動できない(距離>M) heappop(h) continue break # jまで最小回数で到達できる頂点par # parまでの回数cnt if not h: return -1, # jまで到達できる頂点がない cnt_from_N[j] = cnt + 1 parent[j] = par heappush(h, V(cnt=cnt + 1, index=j)) ret = [] curr = 0 while curr < N: par = parent[curr] ret.append(par - curr) curr = par return ret def main(): N, M = list(map(int, input().split())) *S, = list(map(int, eval(input()))) print((*solve(N, M, S))) if __name__ == '__main__': main()
def main(): N, M = list(map(int, input().split())) *G, = list(map(int, eval(input()))) ans = [] cur = N ecur = cur - 1 while cur > 0: ncur = cur while (cur - ecur) <= M and ecur >= 0: if G[ecur] == 0: ncur = ecur ecur -= 1 if ncur == cur: print((-1)) return ans.append(cur - ncur) cur = ncur ans.reverse() print((*ans)) if __name__ == '__main__': main()
58
28
1,184
506
# https://atcoder.jp/contests/abc146/submissions/8617148 def solve(N, M, S): from collections import namedtuple from heapq import heappop, heappush INF = N * 2 V = namedtuple("V", "cnt index") cnt_from_N = [INF] * (N + 1) cnt_from_N[N] = 0 parent = [0] * (N + 1) h = [V(cnt=0, index=N)] for j in range(N - 1, -1, -1): # S[j]に到達する最小回数とその経路を求める if S[j]: continue while h: cnt, par = h[0] if par > j + M: # jまで移動できない(距離>M) heappop(h) continue break # jまで最小回数で到達できる頂点par # parまでの回数cnt if not h: return (-1,) # jまで到達できる頂点がない cnt_from_N[j] = cnt + 1 parent[j] = par heappush(h, V(cnt=cnt + 1, index=j)) ret = [] curr = 0 while curr < N: par = parent[curr] ret.append(par - curr) curr = par return ret def main(): N, M = list(map(int, input().split())) (*S,) = list(map(int, eval(input()))) print((*solve(N, M, S))) if __name__ == "__main__": main()
def main(): N, M = list(map(int, input().split())) (*G,) = list(map(int, eval(input()))) ans = [] cur = N ecur = cur - 1 while cur > 0: ncur = cur while (cur - ecur) <= M and ecur >= 0: if G[ecur] == 0: ncur = ecur ecur -= 1 if ncur == cur: print((-1)) return ans.append(cur - ncur) cur = ncur ans.reverse() print((*ans)) if __name__ == "__main__": main()
false
51.724138
[ "-# https://atcoder.jp/contests/abc146/submissions/8617148", "-def solve(N, M, S):", "- from collections import namedtuple", "- from heapq import heappop, heappush", "-", "- INF = N * 2", "- V = namedtuple(\"V\", \"cnt index\")", "- cnt_from_N = [INF] * (N + 1)", "- cnt_from_N[N] =...
false
0.171657
0.117939
1.455469
[ "s137680600", "s176021379" ]
u991542950
p02572
python
s278700468
s875960106
119
109
105,292
105,436
Accepted
Accepted
8.4
import sys input = sys.stdin.readline N = int(eval(input())) A = list(map(int, input().split())) mod = 10 ** 9 + 7 sum_A = sum(A) ans = 0 for a in A[:-1]: sum_A -= a ans += a * sum_A ans %= mod print(ans)
import sys input = sys.stdin.readline N = int(eval(input())) A = list(map(int, input().split())) mod = 10 ** 9 + 7 sum_A = sum(A) % mod ans = 0 for a in A[:-1]: sum_A -= a sum_A %= mod ans += a * sum_A ans %= mod ans %= mod print(ans)
15
17
219
257
import sys input = sys.stdin.readline N = int(eval(input())) A = list(map(int, input().split())) mod = 10**9 + 7 sum_A = sum(A) ans = 0 for a in A[:-1]: sum_A -= a ans += a * sum_A ans %= mod print(ans)
import sys input = sys.stdin.readline N = int(eval(input())) A = list(map(int, input().split())) mod = 10**9 + 7 sum_A = sum(A) % mod ans = 0 for a in A[:-1]: sum_A -= a sum_A %= mod ans += a * sum_A ans %= mod ans %= mod print(ans)
false
11.764706
[ "-sum_A = sum(A)", "+sum_A = sum(A) % mod", "+ sum_A %= mod", "+ ans %= mod" ]
false
0.049198
0.043017
1.143699
[ "s278700468", "s875960106" ]
u362771726
p02831
python
s679325533
s682461192
42
37
5,432
5,304
Accepted
Accepted
11.9
from fractions import gcd a, b = list(map(int, input().split())) lcm = a * b / gcd(a, b) print((int(lcm)))
# import math これだとエラーになる 3.4なので from fractions import gcd a, b = list(map(int, input().split())) hoge = (a*b) / gcd(a, b) print((int(hoge)))
5
6
103
138
from fractions import gcd a, b = list(map(int, input().split())) lcm = a * b / gcd(a, b) print((int(lcm)))
# import math これだとエラーになる 3.4なので from fractions import gcd a, b = list(map(int, input().split())) hoge = (a * b) / gcd(a, b) print((int(hoge)))
false
16.666667
[ "+# import math これだとエラーになる 3.4なので", "-lcm = a * b / gcd(a, b)", "-print((int(lcm)))", "+hoge = (a * b) / gcd(a, b)", "+print((int(hoge)))" ]
false
0.049893
0.060905
0.819195
[ "s679325533", "s682461192" ]
u463775490
p02755
python
s456486364
s919365308
19
17
3,060
2,940
Accepted
Accepted
10.53
import math a, b = list(map(int, input().split())) for i in range(b+1,1001): if math.floor(i * 0.08) == a and math.floor(i * 0.1) == b: ans = i break else: ans = -1 print(ans)
a, b = list(map(int,input().split())) if b * 10 <= (a * 25 + 24) // 2 and -(-a * 25 // 2) < (b + 1) * 10: print((max(-(-a*25//2), b * 10))) else: print((-1))
11
5
205
159
import math a, b = list(map(int, input().split())) for i in range(b + 1, 1001): if math.floor(i * 0.08) == a and math.floor(i * 0.1) == b: ans = i break else: ans = -1 print(ans)
a, b = list(map(int, input().split())) if b * 10 <= (a * 25 + 24) // 2 and -(-a * 25 // 2) < (b + 1) * 10: print((max(-(-a * 25 // 2), b * 10))) else: print((-1))
false
54.545455
[ "-import math", "-", "-for i in range(b + 1, 1001):", "- if math.floor(i * 0.08) == a and math.floor(i * 0.1) == b:", "- ans = i", "- break", "+if b * 10 <= (a * 25 + 24) // 2 and -(-a * 25 // 2) < (b + 1) * 10:", "+ print((max(-(-a * 25 // 2), b * 10)))", "- ans = -1", "-pr...
false
0.037778
0.036816
1.026141
[ "s456486364", "s919365308" ]
u500376440
p03633
python
s479651375
s936644114
30
25
9,180
9,176
Accepted
Accepted
16.67
from math import * N=int(eval(input())) T=list(int(eval(input())) for _ in range(N)) ans=T[0] for i in range(1,N): ans=ans*T[i]//gcd(ans,T[i]) print(ans)
from math import * def lcm(x,y): return (x*y)//gcd(x,y) N=int(eval(input())) T=[int(eval(input())) for _ in range(N)] ans=T[0] for i in range(1,N): ans=lcm(ans,T[i]) print(ans)
8
11
152
181
from math import * N = int(eval(input())) T = list(int(eval(input())) for _ in range(N)) ans = T[0] for i in range(1, N): ans = ans * T[i] // gcd(ans, T[i]) print(ans)
from math import * def lcm(x, y): return (x * y) // gcd(x, y) N = int(eval(input())) T = [int(eval(input())) for _ in range(N)] ans = T[0] for i in range(1, N): ans = lcm(ans, T[i]) print(ans)
false
27.272727
[ "+", "+def lcm(x, y):", "+ return (x * y) // gcd(x, y)", "+", "+", "-T = list(int(eval(input())) for _ in range(N))", "+T = [int(eval(input())) for _ in range(N)]", "- ans = ans * T[i] // gcd(ans, T[i])", "+ ans = lcm(ans, T[i])" ]
false
0.040621
0.048434
0.838698
[ "s479651375", "s936644114" ]
u211160392
p02862
python
s471268144
s459541457
306
231
3,064
55,660
Accepted
Accepted
24.51
MOD = 10**9+7 X,Y = list(map(int,input().split())) if (X+Y) % 3 != 0: print((0)) exit() N = (X+Y)//3 X -= N Y -= N if X < 0 or Y < 0: print((0)) exit() si = 1 bo = 1 for i in range(N): si = (si*(i+1)) % MOD for i in range(min(X,Y)): bo = (bo*(i+1)) % MOD for i in range(N-min(X,Y)): bo = (bo*(i+1)) % MOD print(((si*pow(bo,MOD-2,MOD))%MOD))
MOD = 10**9+7 # 問題に合わせて適宜書き換え list_size = 10**6+100 # 問題に合わせて適宜書き換え f_list = [1] * list_size f_r_list = [1] * list_size for i in range(list_size - 1): f_list[i + 1] = ((f_list[i] * (i+2)) % MOD) f_r_list[-1] = pow(f_list[-1], MOD - 2, MOD) for i in range(-2, -list_size-1, -1): f_r_list[i] = ((f_r_list[i+1] * (list_size + 2 + i)) % MOD) def comb(n,r): if r == 0 or n == r: return 1 return (((f_list[n - 1] * f_r_list[n - r - 1]) % MOD) * f_r_list[r - 1]) % MOD X,Y = list(map(int,input().split())) if (X+Y) % 3 != 0: print((0)) exit() N = (X+Y)//3 X -= N Y -= N if X < 0 or Y < 0: print((0)) exit() print((comb(N,X)))
21
30
377
685
MOD = 10**9 + 7 X, Y = list(map(int, input().split())) if (X + Y) % 3 != 0: print((0)) exit() N = (X + Y) // 3 X -= N Y -= N if X < 0 or Y < 0: print((0)) exit() si = 1 bo = 1 for i in range(N): si = (si * (i + 1)) % MOD for i in range(min(X, Y)): bo = (bo * (i + 1)) % MOD for i in range(N - min(X, Y)): bo = (bo * (i + 1)) % MOD print(((si * pow(bo, MOD - 2, MOD)) % MOD))
MOD = 10**9 + 7 # 問題に合わせて適宜書き換え list_size = 10**6 + 100 # 問題に合わせて適宜書き換え f_list = [1] * list_size f_r_list = [1] * list_size for i in range(list_size - 1): f_list[i + 1] = (f_list[i] * (i + 2)) % MOD f_r_list[-1] = pow(f_list[-1], MOD - 2, MOD) for i in range(-2, -list_size - 1, -1): f_r_list[i] = (f_r_list[i + 1] * (list_size + 2 + i)) % MOD def comb(n, r): if r == 0 or n == r: return 1 return (((f_list[n - 1] * f_r_list[n - r - 1]) % MOD) * f_r_list[r - 1]) % MOD X, Y = list(map(int, input().split())) if (X + Y) % 3 != 0: print((0)) exit() N = (X + Y) // 3 X -= N Y -= N if X < 0 or Y < 0: print((0)) exit() print((comb(N, X)))
false
30
[ "-MOD = 10**9 + 7", "+MOD = 10**9 + 7 # 問題に合わせて適宜書き換え", "+list_size = 10**6 + 100 # 問題に合わせて適宜書き換え", "+f_list = [1] * list_size", "+f_r_list = [1] * list_size", "+for i in range(list_size - 1):", "+ f_list[i + 1] = (f_list[i] * (i + 2)) % MOD", "+f_r_list[-1] = pow(f_list[-1], MOD - 2, MOD)", "+...
false
0.127599
0.868346
0.146944
[ "s471268144", "s459541457" ]
u254871849
p03240
python
s472239262
s344021281
36
31
3,064
3,064
Accepted
Accepted
13.89
# 2019-11-10 20:23:41(JST) import sys # import collections # import math # from string import ascii_lowercase, ascii_uppercase, digits # from bisect import bisect_left as bi_l, bisect_right as bi_r # import itertools # from functools import reduce # import operator as op # from scipy.misc import comb # float # import numpy as np def main(): n = int(sys.stdin.readline().rstrip()) info = [[int(x) for x in sys.stdin.readline().split()] for _ in range(n)] # 基準を決める for i in range(n): if info[i][2] >= 1: x0, y0, h0 = info[i][0], info[i][1], info[i][2] break # else: すべてのhは h = 0 for x in range(101): for y in range(101): H = h0 + abs(x - x0) + abs(y - y0) for i in range(n): # 中心(x, y, H)が条件を満たしているか確認する h = max(H - abs(x - info[i][0]) - abs(y - info[i][1]), 0) if h != info[i][2]: # 本当に中心なら同じ値になるはず break # そうでないならこれは正しくない else: # 全ての座標に対して条件を満たしていたなら res = [x, y, H] break # 中心は一意に決まるので見つかったらそれ以上調べる必要ない for i in range(3): res[i] = str(res[i]) print((' '.join(res))) if __name__ == "__main__": main()
# 2019-11-10 20:23:41(JST) import sys # import collections # import math # from string import ascii_lowercase, ascii_uppercase, digits # from bisect import bisect_left as bi_l, bisect_right as bi_r # import itertools # from functools import reduce # import operator as op # from scipy.misc import comb # float # import numpy as np def main(): n = int(sys.stdin.readline().rstrip()) info = [[int(x) for x in sys.stdin.readline().split()] for _ in range(n)] # 基準を決める for i in range(n): if info[i][2] >= 1: x0, y0, h0 = info[i][0], info[i][1], info[i][2] break # else: すべてのhは h = 0 for x in range(101): for y in range(101): H = h0 + abs(x - x0) + abs(y - y0) for i in range(n): # 中心(x, y, H)が条件を満たしているか確認する h = max(H - abs(x - info[i][0]) - abs(y - info[i][1]), 0) if h != info[i][2]: # 本当に中心なら同じ値になるはず break # そうでないならこれは正しくない else: # 全ての座標に対して条件を満たしていたなら res = [x, y, H] for i in range(3): res[i] = str(res[i]) print((' '.join(res))) sys.exit() # 中心は一意に決まるので見つかったらそれ以上調べる必要ない if __name__ == "__main__": main()
42
41
1,284
1,319
# 2019-11-10 20:23:41(JST) import sys # import collections # import math # from string import ascii_lowercase, ascii_uppercase, digits # from bisect import bisect_left as bi_l, bisect_right as bi_r # import itertools # from functools import reduce # import operator as op # from scipy.misc import comb # float # import numpy as np def main(): n = int(sys.stdin.readline().rstrip()) info = [[int(x) for x in sys.stdin.readline().split()] for _ in range(n)] # 基準を決める for i in range(n): if info[i][2] >= 1: x0, y0, h0 = info[i][0], info[i][1], info[i][2] break # else: すべてのhは h = 0 for x in range(101): for y in range(101): H = h0 + abs(x - x0) + abs(y - y0) for i in range(n): # 中心(x, y, H)が条件を満たしているか確認する h = max(H - abs(x - info[i][0]) - abs(y - info[i][1]), 0) if h != info[i][2]: #  本当に中心なら同じ値になるはず break # そうでないならこれは正しくない else: # 全ての座標に対して条件を満たしていたなら res = [x, y, H] break # 中心は一意に決まるので見つかったらそれ以上調べる必要ない for i in range(3): res[i] = str(res[i]) print((" ".join(res))) if __name__ == "__main__": main()
# 2019-11-10 20:23:41(JST) import sys # import collections # import math # from string import ascii_lowercase, ascii_uppercase, digits # from bisect import bisect_left as bi_l, bisect_right as bi_r # import itertools # from functools import reduce # import operator as op # from scipy.misc import comb # float # import numpy as np def main(): n = int(sys.stdin.readline().rstrip()) info = [[int(x) for x in sys.stdin.readline().split()] for _ in range(n)] # 基準を決める for i in range(n): if info[i][2] >= 1: x0, y0, h0 = info[i][0], info[i][1], info[i][2] break # else: すべてのhは h = 0 for x in range(101): for y in range(101): H = h0 + abs(x - x0) + abs(y - y0) for i in range(n): # 中心(x, y, H)が条件を満たしているか確認する h = max(H - abs(x - info[i][0]) - abs(y - info[i][1]), 0) if h != info[i][2]: #  本当に中心なら同じ値になるはず break # そうでないならこれは正しくない else: # 全ての座標に対して条件を満たしていたなら res = [x, y, H] for i in range(3): res[i] = str(res[i]) print((" ".join(res))) sys.exit() # 中心は一意に決まるので見つかったらそれ以上調べる必要ない if __name__ == "__main__": main()
false
2.380952
[ "- break # 中心は一意に決まるので見つかったらそれ以上調べる必要ない", "- for i in range(3):", "- res[i] = str(res[i])", "- print((\" \".join(res)))", "+ for i in range(3):", "+ res[i] = str(res[i])", "+ print((\" \".join(res)))", "+ sys....
false
0.060972
0.040486
1.506002
[ "s472239262", "s344021281" ]
u761320129
p03687
python
s882108304
s627111202
73
39
3,064
3,064
Accepted
Accepted
46.58
S = eval(input()) ans = len(S) for i in range(26): c = chr(ord('a') + i) t1 = S cnt = 0 while any(list([x!=c for x in t1])): t2 = '' for ca,cb in zip(t1,t1[1:]): if ca == c or cb == c: t2 += c else: t2 += ca t1 = t2 cnt += 1 ans = min(ans, cnt) print(ans)
S = eval(input()) ans = len(S) for i in range(26): c = chr(ord('a') + i) if not c in S: continue if all([c==a for a in S]): print((0)) exit() arr = list(S) tmp = 0 while 1: arr2 = [] diff = False tmp += 1 for a,b in zip(arr,arr[1:]): if a==c or b==c: arr2.append(c) else: arr2.append(a) diff = True if not diff: break arr = arr2 ans = min(ans, tmp) print(ans)
19
26
381
553
S = eval(input()) ans = len(S) for i in range(26): c = chr(ord("a") + i) t1 = S cnt = 0 while any(list([x != c for x in t1])): t2 = "" for ca, cb in zip(t1, t1[1:]): if ca == c or cb == c: t2 += c else: t2 += ca t1 = t2 cnt += 1 ans = min(ans, cnt) print(ans)
S = eval(input()) ans = len(S) for i in range(26): c = chr(ord("a") + i) if not c in S: continue if all([c == a for a in S]): print((0)) exit() arr = list(S) tmp = 0 while 1: arr2 = [] diff = False tmp += 1 for a, b in zip(arr, arr[1:]): if a == c or b == c: arr2.append(c) else: arr2.append(a) diff = True if not diff: break arr = arr2 ans = min(ans, tmp) print(ans)
false
26.923077
[ "- t1 = S", "- cnt = 0", "- while any(list([x != c for x in t1])):", "- t2 = \"\"", "- for ca, cb in zip(t1, t1[1:]):", "- if ca == c or cb == c:", "- t2 += c", "+ if not c in S:", "+ continue", "+ if all([c == a for a in S]):", "+ ...
false
0.041692
0.037469
1.112714
[ "s882108304", "s627111202" ]
u773265208
p04001
python
s182424565
s466255952
181
39
40,304
3,064
Accepted
Accepted
78.45
import itertools s = eval(input()) n = len(s) l = [] for i in range(1,n): l.append(i) ans = [] for i in range(1,n): index = list(itertools.combinations(l,i)) for j in range(len(index)): start = 0 for k in index[j]: ans.append(int(s[start:k])) start = k ans.append(int(s[k:n])) print((sum(ans) + int(s)))
s = eval(input()) n = len(s) ans = 0 for i in range(2**n): l = [] for j in range(n): if i & (1 << j): l.append(j) #print(l) string = s if len(l) == 0: continue for k in range(len(l)): if l[k] == 0: string = '+' + string else: string = string[:l[k]+k] + '+' + string[l[k]+k:] ans += eval(string) print(((ans + int(s))//2))
21
23
336
364
import itertools s = eval(input()) n = len(s) l = [] for i in range(1, n): l.append(i) ans = [] for i in range(1, n): index = list(itertools.combinations(l, i)) for j in range(len(index)): start = 0 for k in index[j]: ans.append(int(s[start:k])) start = k ans.append(int(s[k:n])) print((sum(ans) + int(s)))
s = eval(input()) n = len(s) ans = 0 for i in range(2**n): l = [] for j in range(n): if i & (1 << j): l.append(j) # print(l) string = s if len(l) == 0: continue for k in range(len(l)): if l[k] == 0: string = "+" + string else: string = string[: l[k] + k] + "+" + string[l[k] + k :] ans += eval(string) print(((ans + int(s)) // 2))
false
8.695652
[ "-import itertools", "-", "-l = []", "-for i in range(1, n):", "- l.append(i)", "-ans = []", "-for i in range(1, n):", "- index = list(itertools.combinations(l, i))", "- for j in range(len(index)):", "- start = 0", "- for k in index[j]:", "- ans.append(int(s[s...
false
0.044699
0.006325
7.066899
[ "s182424565", "s466255952" ]
u499381410
p02867
python
s322720553
s907472336
1,116
727
96,508
92,680
Accepted
Accepted
34.86
from collections import defaultdict, deque, Counter from heapq import heappush, heappop, heapify import math import bisect import random from itertools import permutations, accumulate, combinations, product import sys import string from bisect import bisect_left, bisect_right from math import factorial, ceil, floor from functools import reduce sys.setrecursionlimit(2147483647) INF = 10 ** 18 def LI(): return list(map(int, sys.stdin.buffer.readline().split())) def I(): return int(sys.stdin.buffer.readline()) def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split() def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8') def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] def SRL(n): return [list(S()) for i in range(n)] def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)] mod = 998244353 def main(): class UnionFind: def __init__(self, n): # 負 : 根であることを示す。絶対値はランクを示す # 非負: 根でないことを示す。値は親を示す self.table = [-1] * n self.size = [1] * n self.group_num = n def root(self, x): if self.table[x] < 0: return x else: self.table[x] = self.root(self.table[x]) return self.table[x] def is_same(self, x, y): return self.root(x) == self.root(y) def get_size(self, x): r = self.root(x) return self.size[r] def union(self, x, y): r1 = self.root(x) r2 = self.root(y) if r1 == r2: return # ランクの取得 d1 = self.table[r1] d2 = self.table[r2] if d1 <= d2: self.table[r2] = r1 self.size[r1] += self.size[r2] if d1 == d2: self.table[r1] -= 1 else: self.table[r1] = r2 self.size[r2] += self.size[r1] self.group_num -= 1 n = I() A = LI() B = LI() a_sort = sorted([(a, i) for i, a in enumerate(A)]) b_sort = sorted([(b, i) for i, b in enumerate(B)]) U = UnionFind(n) for i in range(n): if a_sort[i][0] > b_sort[i][0]: return 'No' for j in range(n): if j != 0 and a_sort[j][0] <= b_sort[j - 1][0]: return 'Yes' b_ind_to_a_ind = {} for i in range(n): b_ind_to_a_ind[b_sort[i][1]] = a_sort[i][1] for j in range(n): U.union(j, b_ind_to_a_ind[j]) if U.group_num == 1: return 'No' else: return 'Yes' print((main()))
from collections import defaultdict, deque, Counter from heapq import heappush, heappop, heapify import math import bisect import random from itertools import permutations, accumulate, combinations, product import sys import string from bisect import bisect_left, bisect_right from math import factorial, ceil, floor from functools import reduce sys.setrecursionlimit(2147483647) INF = 10 ** 18 def LI(): return list(map(int, sys.stdin.buffer.readline().split())) def I(): return int(sys.stdin.buffer.readline()) def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split() def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8') def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] def SRL(n): return [list(S()) for i in range(n)] def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)] mod = 998244353 class UnionFind: def __init__(self, n): # 負 : 根であることを示す。絶対値はランクを示す # 非負: 根でないことを示す。値は親を示す self.table = [-1] * n self.size = [1] * n self.group_num = n def root(self, x): if self.table[x] < 0: return x else: self.table[x] = self.root(self.table[x]) return self.table[x] def is_same(self, x, y): return self.root(x) == self.root(y) def get_size(self, x): r = self.root(x) return self.size[r] def union(self, x, y): r1 = self.root(x) r2 = self.root(y) if r1 == r2: return # ランクの取得 d1 = self.table[r1] d2 = self.table[r2] if d1 <= d2: self.table[r2] = r1 self.size[r1] += self.size[r2] if d1 == d2: self.table[r1] -= 1 else: self.table[r1] = r2 self.size[r2] += self.size[r1] self.group_num -= 1 def main(): n = I() A = LI() B = LI() a_sort_index = sorted(list(range(n)), key=lambda x:A[x]) b_sort_index = sorted(list(range(n)), key=lambda x: B[x]) flag = 0 U = UnionFind(n) for i in range(n): if A[a_sort_index[i]] > B[b_sort_index[i]]: return 'No' elif i != 0 and A[a_sort_index[i]] <= B[b_sort_index[i - 1]]: flag = 1 U.union(a_sort_index[i], b_sort_index[i]) if U.group_num == 1 and not flag: return 'No' else: return 'Yes' print((main()))
96
92
2,825
2,597
from collections import defaultdict, deque, Counter from heapq import heappush, heappop, heapify import math import bisect import random from itertools import permutations, accumulate, combinations, product import sys import string from bisect import bisect_left, bisect_right from math import factorial, ceil, floor from functools import reduce sys.setrecursionlimit(2147483647) INF = 10**18 def LI(): return list(map(int, sys.stdin.buffer.readline().split())) def I(): return int(sys.stdin.buffer.readline()) def LS(): return sys.stdin.buffer.readline().rstrip().decode("utf-8").split() def S(): return sys.stdin.buffer.readline().rstrip().decode("utf-8") def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] def SRL(n): return [list(S()) for i in range(n)] def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)] mod = 998244353 def main(): class UnionFind: def __init__(self, n): # 負 : 根であることを示す。絶対値はランクを示す # 非負: 根でないことを示す。値は親を示す self.table = [-1] * n self.size = [1] * n self.group_num = n def root(self, x): if self.table[x] < 0: return x else: self.table[x] = self.root(self.table[x]) return self.table[x] def is_same(self, x, y): return self.root(x) == self.root(y) def get_size(self, x): r = self.root(x) return self.size[r] def union(self, x, y): r1 = self.root(x) r2 = self.root(y) if r1 == r2: return # ランクの取得 d1 = self.table[r1] d2 = self.table[r2] if d1 <= d2: self.table[r2] = r1 self.size[r1] += self.size[r2] if d1 == d2: self.table[r1] -= 1 else: self.table[r1] = r2 self.size[r2] += self.size[r1] self.group_num -= 1 n = I() A = LI() B = LI() a_sort = sorted([(a, i) for i, a in enumerate(A)]) b_sort = sorted([(b, i) for i, b in enumerate(B)]) U = UnionFind(n) for i in range(n): if a_sort[i][0] > b_sort[i][0]: return "No" for j in range(n): if j != 0 and a_sort[j][0] <= b_sort[j - 1][0]: return "Yes" b_ind_to_a_ind = {} for i in range(n): b_ind_to_a_ind[b_sort[i][1]] = a_sort[i][1] for j in range(n): U.union(j, b_ind_to_a_ind[j]) if U.group_num == 1: return "No" else: return "Yes" print((main()))
from collections import defaultdict, deque, Counter from heapq import heappush, heappop, heapify import math import bisect import random from itertools import permutations, accumulate, combinations, product import sys import string from bisect import bisect_left, bisect_right from math import factorial, ceil, floor from functools import reduce sys.setrecursionlimit(2147483647) INF = 10**18 def LI(): return list(map(int, sys.stdin.buffer.readline().split())) def I(): return int(sys.stdin.buffer.readline()) def LS(): return sys.stdin.buffer.readline().rstrip().decode("utf-8").split() def S(): return sys.stdin.buffer.readline().rstrip().decode("utf-8") def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] def SRL(n): return [list(S()) for i in range(n)] def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)] mod = 998244353 class UnionFind: def __init__(self, n): # 負 : 根であることを示す。絶対値はランクを示す # 非負: 根でないことを示す。値は親を示す self.table = [-1] * n self.size = [1] * n self.group_num = n def root(self, x): if self.table[x] < 0: return x else: self.table[x] = self.root(self.table[x]) return self.table[x] def is_same(self, x, y): return self.root(x) == self.root(y) def get_size(self, x): r = self.root(x) return self.size[r] def union(self, x, y): r1 = self.root(x) r2 = self.root(y) if r1 == r2: return # ランクの取得 d1 = self.table[r1] d2 = self.table[r2] if d1 <= d2: self.table[r2] = r1 self.size[r1] += self.size[r2] if d1 == d2: self.table[r1] -= 1 else: self.table[r1] = r2 self.size[r2] += self.size[r1] self.group_num -= 1 def main(): n = I() A = LI() B = LI() a_sort_index = sorted(list(range(n)), key=lambda x: A[x]) b_sort_index = sorted(list(range(n)), key=lambda x: B[x]) flag = 0 U = UnionFind(n) for i in range(n): if A[a_sort_index[i]] > B[b_sort_index[i]]: return "No" elif i != 0 and A[a_sort_index[i]] <= B[b_sort_index[i - 1]]: flag = 1 U.union(a_sort_index[i], b_sort_index[i]) if U.group_num == 1 and not flag: return "No" else: return "Yes" print((main()))
false
4.166667
[ "+class UnionFind:", "+ def __init__(self, n):", "+ # 負 : 根であることを示す。絶対値はランクを示す", "+ # 非負: 根でないことを示す。値は親を示す", "+ self.table = [-1] * n", "+ self.size = [1] * n", "+ self.group_num = n", "+", "+ def root(self, x):", "+ if self.table[x] < 0:", "+ ...
false
0.036479
0.037217
0.980169
[ "s322720553", "s907472336" ]
u254871849
p03494
python
s561201098
s781915041
20
18
3,060
2,940
Accepted
Accepted
10
n = int(eval(input())) a = list(map(int, input().split())) count = 0 only_even = True while only_even: for i in range(n): if a[i] % 2 != 0: only_even = False if only_even == False: break for i in range(n): a[i] /= 2 count += 1 print(count)
import sys # import collections # import math # import string # import bisect # import re # import itertools # import statistics def main(): n, *numbers = (int(x) for x in sys.stdin.read().split()) still_can_be_divided = True count = 0 while still_can_be_divided: for i in range(n): if numbers[i] % 2 == 0: numbers[i] //= 2 else: still_can_be_divided = False if still_can_be_divided: count += 1 print(count) if __name__ == "__main__": # execute only if run as a script main()
17
27
285
627
n = int(eval(input())) a = list(map(int, input().split())) count = 0 only_even = True while only_even: for i in range(n): if a[i] % 2 != 0: only_even = False if only_even == False: break for i in range(n): a[i] /= 2 count += 1 print(count)
import sys # import collections # import math # import string # import bisect # import re # import itertools # import statistics def main(): n, *numbers = (int(x) for x in sys.stdin.read().split()) still_can_be_divided = True count = 0 while still_can_be_divided: for i in range(n): if numbers[i] % 2 == 0: numbers[i] //= 2 else: still_can_be_divided = False if still_can_be_divided: count += 1 print(count) if __name__ == "__main__": # execute only if run as a script main()
false
37.037037
[ "-n = int(eval(input()))", "-a = list(map(int, input().split()))", "-count = 0", "-only_even = True", "-while only_even:", "- for i in range(n):", "- if a[i] % 2 != 0:", "- only_even = False", "- if only_even == False:", "- break", "- for i in range(n):", "- ...
false
0.045136
0.04473
1.009084
[ "s561201098", "s781915041" ]
u353797797
p03183
python
s590130742
s950978800
1,595
1,446
82,036
82,036
Accepted
Accepted
9.34
def f(n): dp = [0] * (n * 10 ** 4 + 1) bs = [list(map(int, input().split())) for _ in range(n)] bs.sort(key=lambda x: x[0] + x[1]) for w, s, v in bs: for i in range(w + s, w - 1, -1): dpw = dp[i - w] + v if dpw > dp[i]: dp[i] = dpw print((max(dp))) n = int(eval(input())) f(n)
def f(n): mx = 0 dp = [0] * (n * 10 ** 4 + 1) bs = [list(map(int, input().split())) for _ in range(n)] bs.sort(key=lambda x: x[0] + x[1]) for w, s, v in bs: for i in range(w + s, w - 1, -1): dpw = dp[i - w] + v if dpw > dp[i]: dp[i] = dpw if dpw > mx: mx = dpw print(mx) n = int(eval(input())) f(n)
14
17
352
419
def f(n): dp = [0] * (n * 10**4 + 1) bs = [list(map(int, input().split())) for _ in range(n)] bs.sort(key=lambda x: x[0] + x[1]) for w, s, v in bs: for i in range(w + s, w - 1, -1): dpw = dp[i - w] + v if dpw > dp[i]: dp[i] = dpw print((max(dp))) n = int(eval(input())) f(n)
def f(n): mx = 0 dp = [0] * (n * 10**4 + 1) bs = [list(map(int, input().split())) for _ in range(n)] bs.sort(key=lambda x: x[0] + x[1]) for w, s, v in bs: for i in range(w + s, w - 1, -1): dpw = dp[i - w] + v if dpw > dp[i]: dp[i] = dpw if dpw > mx: mx = dpw print(mx) n = int(eval(input())) f(n)
false
17.647059
[ "+ mx = 0", "- print((max(dp)))", "+ if dpw > mx:", "+ mx = dpw", "+ print(mx)" ]
false
0.046297
0.044457
1.041379
[ "s590130742", "s950978800" ]
u997641430
p02922
python
s252283756
s873823238
19
17
2,940
2,940
Accepted
Accepted
10.53
A,B=list(map(int,input().split())) x=0 while (A-1)*x+1<B: x+=1 print(x)
a, b = list(map(int, input().split())) print((-(-(b-1)//(a-1))))
5
2
73
58
A, B = list(map(int, input().split())) x = 0 while (A - 1) * x + 1 < B: x += 1 print(x)
a, b = list(map(int, input().split())) print((-(-(b - 1) // (a - 1))))
false
60
[ "-A, B = list(map(int, input().split()))", "-x = 0", "-while (A - 1) * x + 1 < B:", "- x += 1", "-print(x)", "+a, b = list(map(int, input().split()))", "+print((-(-(b - 1) // (a - 1))))" ]
false
0.044876
0.068655
0.653646
[ "s252283756", "s873823238" ]
u631277801
p03456
python
s813468155
s539642768
151
17
12,504
3,064
Accepted
Accepted
88.74
import numpy as np # input a, b = input().split() ab = int(a+b) if np.sqrt(ab)-round(np.sqrt(ab)): print('No') else: print('Yes')
import sys stdin = sys.stdin sys.setrecursionlimit(10**5) def li(): return list(map(int, stdin.readline().split())) def li_(): return [int(x)-1 for x in stdin.readline().split()] def lf(): return list(map(float, stdin.readline().split())) def ls(): return stdin.readline().split() def ns(): return stdin.readline().rstrip() def lc(): return list(ns()) def ni(): return int(stdin.readline()) def nf(): return float(stdin.readline()) a,b = ls() num = int(a+b) ans = False for i in range(1000): if num == i*i: ans = True if ans: print("Yes") else: print("No")
11
27
150
612
import numpy as np # input a, b = input().split() ab = int(a + b) if np.sqrt(ab) - round(np.sqrt(ab)): print("No") else: print("Yes")
import sys stdin = sys.stdin sys.setrecursionlimit(10**5) def li(): return list(map(int, stdin.readline().split())) def li_(): return [int(x) - 1 for x in stdin.readline().split()] def lf(): return list(map(float, stdin.readline().split())) def ls(): return stdin.readline().split() def ns(): return stdin.readline().rstrip() def lc(): return list(ns()) def ni(): return int(stdin.readline()) def nf(): return float(stdin.readline()) a, b = ls() num = int(a + b) ans = False for i in range(1000): if num == i * i: ans = True if ans: print("Yes") else: print("No")
false
59.259259
[ "-import numpy as np", "+import sys", "-# input", "-a, b = input().split()", "-ab = int(a + b)", "-if np.sqrt(ab) - round(np.sqrt(ab)):", "+stdin = sys.stdin", "+sys.setrecursionlimit(10**5)", "+", "+", "+def li():", "+ return list(map(int, stdin.readline().split()))", "+", "+", "+def...
false
0.431549
0.03488
12.372538
[ "s813468155", "s539642768" ]
u037430802
p02900
python
s307682302
s143850631
469
333
5,268
3,060
Accepted
Accepted
29
#from collections import defaultdict import copy import math A,B = list(map(int, input().split())) num = min(A,B) tmps = {} p = 2 for p in range(2, math.ceil(num**0.5)+1): if A % p == 0 and B % p == 0: tmps[p] = True if A % (num//p) == 0 and B % (num//p) == 0: tmps[num//p] = True p += 1 if num != 1 and A % num == 0 and B % num == 0: tmps[num] = True d = copy.deepcopy(tmps) for k in list(tmps.keys()): if d.get(k, False): aaa = copy.deepcopy(d) for n in list(d.keys()): if k == n: continue if n > k and n % k == 0: aaa.pop(n) d = aaa print((len(list(d.keys()))+1))
A,B = list(map(int, input().split())) def getPrimeFactorsList(num): pn = 2 #素数は2から pflist = [] #素因数のリスト while pn * pn <= num: #√numまで調べる while num % pn == 0: #現在の素数で割り切れる範囲でループ num = num / pn pflist.append(pn) pn += 1 #割り切れなくなったら次の素数へ if num > 1: pflist.append(int(num)) return pflist pf_A = getPrimeFactorsList(A) pf_B = getPrimeFactorsList(B) ans = len(set(pf_A) & set(pf_B)) + 1 print(ans)
36
22
704
451
# from collections import defaultdict import copy import math A, B = list(map(int, input().split())) num = min(A, B) tmps = {} p = 2 for p in range(2, math.ceil(num**0.5) + 1): if A % p == 0 and B % p == 0: tmps[p] = True if A % (num // p) == 0 and B % (num // p) == 0: tmps[num // p] = True p += 1 if num != 1 and A % num == 0 and B % num == 0: tmps[num] = True d = copy.deepcopy(tmps) for k in list(tmps.keys()): if d.get(k, False): aaa = copy.deepcopy(d) for n in list(d.keys()): if k == n: continue if n > k and n % k == 0: aaa.pop(n) d = aaa print((len(list(d.keys())) + 1))
A, B = list(map(int, input().split())) def getPrimeFactorsList(num): pn = 2 # 素数は2から pflist = [] # 素因数のリスト while pn * pn <= num: # √numまで調べる while num % pn == 0: # 現在の素数で割り切れる範囲でループ num = num / pn pflist.append(pn) pn += 1 # 割り切れなくなったら次の素数へ if num > 1: pflist.append(int(num)) return pflist pf_A = getPrimeFactorsList(A) pf_B = getPrimeFactorsList(B) ans = len(set(pf_A) & set(pf_B)) + 1 print(ans)
false
38.888889
[ "-# from collections import defaultdict", "-import copy", "-import math", "+A, B = list(map(int, input().split()))", "-A, B = list(map(int, input().split()))", "-num = min(A, B)", "-tmps = {}", "-p = 2", "-for p in range(2, math.ceil(num**0.5) + 1):", "- if A % p == 0 and B % p == 0:", "- ...
false
0.038475
0.047133
0.816305
[ "s307682302", "s143850631" ]
u969850098
p02708
python
s862002772
s345762744
120
105
9,056
9,204
Accepted
Accepted
12.5
import sys readline = sys.stdin.readline MOD = 10 ** 9 + 7 def main(): N, K = list(map(int, readline().rstrip().split())) ans = 0 for k in range(K, N+2): mi = ((k-1) * k) // 2 ma = (N * (N + 1)) // 2 - ((N-k) * (N-k+1)) // 2 ans += (ma - mi + 1) % MOD print((ans % MOD)) if __name__ == '__main__': main()
import sys readline = sys.stdin.readline MOD = 10 ** 9 + 7 def main(): N, K = list(map(int, readline().rstrip().split())) ans = 0 m = (N * (N + 1)) // 2 for k in range(K, N+2): mi = ((k-1) * k) // 2 ma = m - ((N-k) * (N-k+1)) // 2 ans += (ma - mi + 1) % MOD print((ans % MOD)) if __name__ == '__main__': main()
17
18
360
371
import sys readline = sys.stdin.readline MOD = 10**9 + 7 def main(): N, K = list(map(int, readline().rstrip().split())) ans = 0 for k in range(K, N + 2): mi = ((k - 1) * k) // 2 ma = (N * (N + 1)) // 2 - ((N - k) * (N - k + 1)) // 2 ans += (ma - mi + 1) % MOD print((ans % MOD)) if __name__ == "__main__": main()
import sys readline = sys.stdin.readline MOD = 10**9 + 7 def main(): N, K = list(map(int, readline().rstrip().split())) ans = 0 m = (N * (N + 1)) // 2 for k in range(K, N + 2): mi = ((k - 1) * k) // 2 ma = m - ((N - k) * (N - k + 1)) // 2 ans += (ma - mi + 1) % MOD print((ans % MOD)) if __name__ == "__main__": main()
false
5.555556
[ "+ m = (N * (N + 1)) // 2", "- ma = (N * (N + 1)) // 2 - ((N - k) * (N - k + 1)) // 2", "+ ma = m - ((N - k) * (N - k + 1)) // 2" ]
false
0.079021
0.075194
1.050898
[ "s862002772", "s345762744" ]
u528124741
p03037
python
s426135742
s486383352
380
228
27,340
22,280
Accepted
Accepted
40
n,m = list(map(int,input().split(" "))) gates = [] for i in range(m): gates.append(list(map(int,input().split(" ")))) result = [1, n] for card in gates: if result[0] < card[0]: result[0] = card[0] if result[1] > card[1]: result[1] = card[1] tmp = result[1] - result[0] + 1 if tmp >= 0: print(tmp) else: print((0))
n,m = list(map(int,input().split(" "))) lr = [] ming = 0 maxg = 10 **6 for i in range(m): a,b = list(map(int,input().split(" "))) lr.append((a,b)) for i in lr: if i[0] > ming: ming = i[0] if i[1] < maxg: maxg = i[1] print((max([0, maxg - ming + 1])))
20
18
366
290
n, m = list(map(int, input().split(" "))) gates = [] for i in range(m): gates.append(list(map(int, input().split(" ")))) result = [1, n] for card in gates: if result[0] < card[0]: result[0] = card[0] if result[1] > card[1]: result[1] = card[1] tmp = result[1] - result[0] + 1 if tmp >= 0: print(tmp) else: print((0))
n, m = list(map(int, input().split(" "))) lr = [] ming = 0 maxg = 10**6 for i in range(m): a, b = list(map(int, input().split(" "))) lr.append((a, b)) for i in lr: if i[0] > ming: ming = i[0] if i[1] < maxg: maxg = i[1] print((max([0, maxg - ming + 1])))
false
10
[ "-gates = []", "+lr = []", "+ming = 0", "+maxg = 10**6", "- gates.append(list(map(int, input().split(\" \"))))", "-result = [1, n]", "-for card in gates:", "- if result[0] < card[0]:", "- result[0] = card[0]", "- if result[1] > card[1]:", "- result[1] = card[1]", "-tmp =...
false
0.040258
0.04092
0.983816
[ "s426135742", "s486383352" ]
u823513038
p02397
python
s406174400
s665112123
70
50
7,516
5,612
Accepted
Accepted
28.57
while True: a, b = sorted(map(int, input().split())) if (a == 0) & (b == 0): break print((a, b))
while True: a, b = list(map(int, input().split())) if a == 0 and b == 0: break if a < b: print((a, b)) else: print((b, a))
4
8
100
130
while True: a, b = sorted(map(int, input().split())) if (a == 0) & (b == 0): break print((a, b))
while True: a, b = list(map(int, input().split())) if a == 0 and b == 0: break if a < b: print((a, b)) else: print((b, a))
false
50
[ "- a, b = sorted(map(int, input().split()))", "- if (a == 0) & (b == 0):", "+ a, b = list(map(int, input().split()))", "+ if a == 0 and b == 0:", "- print((a, b))", "+ if a < b:", "+ print((a, b))", "+ else:", "+ print((b, a))" ]
false
0.05329
0.053343
0.999005
[ "s406174400", "s665112123" ]
u119148115
p03762
python
s231098380
s196818782
128
112
113,628
90,904
Accepted
Accepted
12.5
import sys def MI(): return list(map(int,sys.stdin.readline().rstrip().split())) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) #空白あり n,m = MI() x,y = LI(),LI() mod = 10**9+7 n,m = n-1,m-1 dx = [x[i+1]-x[i] for i in range(n)] dy = [y[i+1]-y[i] for i in range(m)] if n % 2 == 0: rx = [i*(n+1-i) for i in range(1,n//2+1)] + [i*(n+1-i) for i in range(n//2,0,-1)] else: rx = [i*(n+1-i) for i in range(1,n//2+2)] + [i*(n+1-i) for i in range(n//2,0,-1)] if m % 2 == 0: ry = [i*(m+1-i) for i in range(1,m//2+1)] + [i*(m+1-i) for i in range(m//2,0,-1)] else: ry = [i*(m+1-i) for i in range(1,m//2+2)] + [i*(m+1-i) for i in range(m//2,0,-1)] a = 0 for i,j in zip(dx,rx): a += i*j a %= mod b = 0 for i,j in zip(dy,ry): b += i*j b %= mod print(((a*b) % mod))
import sys sys.setrecursionlimit(10**7) def I(): return int(sys.stdin.readline().rstrip()) def MI(): return list(map(int,sys.stdin.readline().rstrip().split())) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) #空白あり def LI2(): return list(map(int,sys.stdin.readline().rstrip())) #空白なし def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) #空白あり def LS2(): return list(sys.stdin.readline().rstrip()) #空白なし N,M = MI() X = LI() Y = LI() mod = 10**9+7 r = sum((i*(N-i)*(X[i]-X[i-1])) % mod for i in range(1,N)) r %= mod ans = 0 for i in range(1,M): ans += r*i*(M-i)*(Y[i]-Y[i-1]) % mod ans %= mod print(ans)
31
26
831
715
import sys def MI(): return list(map(int, sys.stdin.readline().rstrip().split())) def LI(): return list(map(int, sys.stdin.readline().rstrip().split())) # 空白あり n, m = MI() x, y = LI(), LI() mod = 10**9 + 7 n, m = n - 1, m - 1 dx = [x[i + 1] - x[i] for i in range(n)] dy = [y[i + 1] - y[i] for i in range(m)] if n % 2 == 0: rx = [i * (n + 1 - i) for i in range(1, n // 2 + 1)] + [ i * (n + 1 - i) for i in range(n // 2, 0, -1) ] else: rx = [i * (n + 1 - i) for i in range(1, n // 2 + 2)] + [ i * (n + 1 - i) for i in range(n // 2, 0, -1) ] if m % 2 == 0: ry = [i * (m + 1 - i) for i in range(1, m // 2 + 1)] + [ i * (m + 1 - i) for i in range(m // 2, 0, -1) ] else: ry = [i * (m + 1 - i) for i in range(1, m // 2 + 2)] + [ i * (m + 1 - i) for i in range(m // 2, 0, -1) ] a = 0 for i, j in zip(dx, rx): a += i * j a %= mod b = 0 for i, j in zip(dy, ry): b += i * j b %= mod print(((a * b) % mod))
import sys sys.setrecursionlimit(10**7) def I(): return int(sys.stdin.readline().rstrip()) def MI(): return list(map(int, sys.stdin.readline().rstrip().split())) def LI(): return list(map(int, sys.stdin.readline().rstrip().split())) # 空白あり def LI2(): return list(map(int, sys.stdin.readline().rstrip())) # 空白なし def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) # 空白あり def LS2(): return list(sys.stdin.readline().rstrip()) # 空白なし N, M = MI() X = LI() Y = LI() mod = 10**9 + 7 r = sum((i * (N - i) * (X[i] - X[i - 1])) % mod for i in range(1, N)) r %= mod ans = 0 for i in range(1, M): ans += r * i * (M - i) * (Y[i] - Y[i - 1]) % mod ans %= mod print(ans)
false
16.129032
[ "+", "+sys.setrecursionlimit(10**7)", "+", "+", "+def I():", "+ return int(sys.stdin.readline().rstrip())", "-n, m = MI()", "-x, y = LI(), LI()", "+def LI2():", "+ return list(map(int, sys.stdin.readline().rstrip())) # 空白なし", "+", "+", "+def S():", "+ return sys.stdin.readline()....
false
0.032267
0.035035
0.921013
[ "s231098380", "s196818782" ]
u596276291
p03828
python
s584965455
s510943678
30
27
3,444
3,316
Accepted
Accepted
10
from collections import defaultdict MOD = 10 ** 9 + 7 # nを素因数分解する(O(n ^ (1 / 2))) # primeFactorDecomposition(12): {2: 2, 3: 1} def prime_factor_decomposition(n): m = defaultdict(int) while n > 1: find_factor = False for i in range(2, int(n ** 1/2) + 1): if n % i == 0: m[i] += 1 n //= i find_factor = True break if not find_factor: m[n] += 1 break return m def main(): N = int(eval(input())) all_m = defaultdict(int) for i in range(1, N + 1): m = prime_factor_decomposition(i) for k, v in list(m.items()): all_m[k] += v ans = 1 for v in list(all_m.values()): ans *= (v + 1) ans %= MOD print(ans) if __name__ == '__main__': main()
from collections import defaultdict MOD = 10 ** 9 + 7 # nを素因数分解する(O(n ^ (1 / 2))) # primeFactorDecomposition(12): {2: 2, 3: 1} def prime_factor_decomposition(n): import math m = defaultdict(int) while n > 1: find_factor = False for i in range(2, int(math.sqrt(n)) + 1): if n % i == 0: m[i] += 1 n //= i find_factor = True break if not find_factor: m[n] += 1 break return m def main(): N = int(eval(input())) m = defaultdict(int) for i in range(1, N + 1): d = prime_factor_decomposition(i) for k, v in list(d.items()): m[k] += v ans = 1 for k, v in list(m.items()): ans = (ans * (v + 1)) % MOD print(ans) if __name__ == '__main__': main()
44
41
875
873
from collections import defaultdict MOD = 10**9 + 7 # nを素因数分解する(O(n ^ (1 / 2))) # primeFactorDecomposition(12): {2: 2, 3: 1} def prime_factor_decomposition(n): m = defaultdict(int) while n > 1: find_factor = False for i in range(2, int(n**1 / 2) + 1): if n % i == 0: m[i] += 1 n //= i find_factor = True break if not find_factor: m[n] += 1 break return m def main(): N = int(eval(input())) all_m = defaultdict(int) for i in range(1, N + 1): m = prime_factor_decomposition(i) for k, v in list(m.items()): all_m[k] += v ans = 1 for v in list(all_m.values()): ans *= v + 1 ans %= MOD print(ans) if __name__ == "__main__": main()
from collections import defaultdict MOD = 10**9 + 7 # nを素因数分解する(O(n ^ (1 / 2))) # primeFactorDecomposition(12): {2: 2, 3: 1} def prime_factor_decomposition(n): import math m = defaultdict(int) while n > 1: find_factor = False for i in range(2, int(math.sqrt(n)) + 1): if n % i == 0: m[i] += 1 n //= i find_factor = True break if not find_factor: m[n] += 1 break return m def main(): N = int(eval(input())) m = defaultdict(int) for i in range(1, N + 1): d = prime_factor_decomposition(i) for k, v in list(d.items()): m[k] += v ans = 1 for k, v in list(m.items()): ans = (ans * (v + 1)) % MOD print(ans) if __name__ == "__main__": main()
false
6.818182
[ "+ import math", "+", "- for i in range(2, int(n**1 / 2) + 1):", "+ for i in range(2, int(math.sqrt(n)) + 1):", "- all_m = defaultdict(int)", "+ m = defaultdict(int)", "- m = prime_factor_decomposition(i)", "- for k, v in list(m.items()):", "- all_m[k]...
false
0.240643
0.063432
3.793717
[ "s584965455", "s510943678" ]
u311669106
p03494
python
s505917010
s516794059
20
18
2,940
2,940
Accepted
Accepted
10
n=int(eval(input())) ln=[int(a) for a in input().split()] i=0 while all(a % 2 ==0 for a in ln): ln=[a/2 for a in ln] i+=1 print(i)
n=int(eval(input())) ln=[int(a) for a in input().split()] i=0 while all(a%2==0 for a in ln): ln=[a//2 for a in ln] i+=1 print(i)
7
7
138
136
n = int(eval(input())) ln = [int(a) for a in input().split()] i = 0 while all(a % 2 == 0 for a in ln): ln = [a / 2 for a in ln] i += 1 print(i)
n = int(eval(input())) ln = [int(a) for a in input().split()] i = 0 while all(a % 2 == 0 for a in ln): ln = [a // 2 for a in ln] i += 1 print(i)
false
0
[ "- ln = [a / 2 for a in ln]", "+ ln = [a // 2 for a in ln]" ]
false
0.031376
0.033465
0.937558
[ "s505917010", "s516794059" ]
u368249389
p03150
python
s105854419
s519131461
186
18
38,640
2,940
Accepted
Accepted
90.32
# KEYENCE String 全通りのパターンを探索する # input process S = eval(input()) s_length = len(S) # initialization is_same = False for i in range(s_length): for j in range(i, s_length): # string slice tmp_str = S[:i+1] + S[j:] if tmp_str=="keyence": is_same = True break if is_same: print("YES") else: print("NO")
# Problem B - KEYENCE String # input s = eval(input()) s_l = len(s) # initialization is_ok = False # check for i in range(s_l): for j in range(i, s_l): tmp_s = s[:i] + s[j:] if tmp_s=='keyence': is_ok = True break # output if is_ok: print("YES") else: print("NO")
20
22
375
335
# KEYENCE String 全通りのパターンを探索する # input process S = eval(input()) s_length = len(S) # initialization is_same = False for i in range(s_length): for j in range(i, s_length): # string slice tmp_str = S[: i + 1] + S[j:] if tmp_str == "keyence": is_same = True break if is_same: print("YES") else: print("NO")
# Problem B - KEYENCE String # input s = eval(input()) s_l = len(s) # initialization is_ok = False # check for i in range(s_l): for j in range(i, s_l): tmp_s = s[:i] + s[j:] if tmp_s == "keyence": is_ok = True break # output if is_ok: print("YES") else: print("NO")
false
9.090909
[ "-# KEYENCE String 全通りのパターンを探索する", "-# input process", "-S = eval(input())", "-s_length = len(S)", "+# Problem B - KEYENCE String", "+# input", "+s = eval(input())", "+s_l = len(s)", "-is_same = False", "-for i in range(s_length):", "- for j in range(i, s_length):", "- # string slice...
false
0.075385
0.036587
2.060403
[ "s105854419", "s519131461" ]
u912237403
p00008
python
s865378961
s180174739
4,940
20
4,352
4,208
Accepted
Accepted
99.6
import sys,itertools for n in map(int,sys.stdin): x=0 for num in itertools.product("0123456789",repeat=4): eq="{}+{}+{}+{}".format(*(num)) if eval(eq)==n:x+=1 print(x)
import sys A=list(range(10)) for n in map(int,sys.stdin): x=0 for a in A: d=n-a if 0>d or d>27:continue for b in A: e=d-b if 0>e or e>18:continue for c in A: if (e-c)in A:x+=1 print(x)
7
13
186
233
import sys, itertools for n in map(int, sys.stdin): x = 0 for num in itertools.product("0123456789", repeat=4): eq = "{}+{}+{}+{}".format(*(num)) if eval(eq) == n: x += 1 print(x)
import sys A = list(range(10)) for n in map(int, sys.stdin): x = 0 for a in A: d = n - a if 0 > d or d > 27: continue for b in A: e = d - b if 0 > e or e > 18: continue for c in A: if (e - c) in A: x += 1 print(x)
false
46.153846
[ "-import sys, itertools", "+import sys", "+A = list(range(10))", "- for num in itertools.product(\"0123456789\", repeat=4):", "- eq = \"{}+{}+{}+{}\".format(*(num))", "- if eval(eq) == n:", "- x += 1", "+ for a in A:", "+ d = n - a", "+ if 0 > d or d > ...
false
0.463186
0.050065
9.251623
[ "s865378961", "s180174739" ]
u888092736
p02580
python
s660451352
s268885217
456
398
101,032
77,808
Accepted
Accepted
12.72
H, W, M, *hw = list(map(int, open(0).read().split())) H_cnt = [0] * (H + 1) W_cnt = [0] * (W + 1) bombs = [(h, w) for h, w in zip(*[iter(hw)] * 2)] for h, w in bombs: H_cnt[h] += 1 W_cnt[w] += 1 H_max_cnt = max(H_cnt) W_max_cnt = max(W_cnt) H_max = {i for i in range(1, H + 1) if H_cnt[i] == H_max_cnt} W_max = {i for i in range(1, W + 1) if W_cnt[i] == W_max_cnt} comb_cnt = len(H_max) * len(W_max) for h, w in bombs: if H_cnt[h] == H_max_cnt and W_cnt[w] == W_max_cnt: comb_cnt -= 1 ans = H_max_cnt + W_max_cnt print((ans if comb_cnt else ans - 1))
H, W, M, *hw = list(map(int, open(0).read().split())) H_cnt = [0] * (H + 1) W_cnt = [0] * (W + 1) bombs = [(h, w) for h, w in zip(*[iter(hw)] * 2)] for h, w in bombs: H_cnt[h] += 1 W_cnt[w] += 1 H_max_cnt = max(H_cnt) W_max_cnt = max(W_cnt) comb_cnt = H_cnt.count(H_max_cnt) * W_cnt.count(W_max_cnt) for h, w in bombs: if H_cnt[h] == H_max_cnt and W_cnt[w] == W_max_cnt: comb_cnt -= 1 ans = H_max_cnt + W_max_cnt print((ans if comb_cnt else ans - 1))
21
18
587
483
H, W, M, *hw = list(map(int, open(0).read().split())) H_cnt = [0] * (H + 1) W_cnt = [0] * (W + 1) bombs = [(h, w) for h, w in zip(*[iter(hw)] * 2)] for h, w in bombs: H_cnt[h] += 1 W_cnt[w] += 1 H_max_cnt = max(H_cnt) W_max_cnt = max(W_cnt) H_max = {i for i in range(1, H + 1) if H_cnt[i] == H_max_cnt} W_max = {i for i in range(1, W + 1) if W_cnt[i] == W_max_cnt} comb_cnt = len(H_max) * len(W_max) for h, w in bombs: if H_cnt[h] == H_max_cnt and W_cnt[w] == W_max_cnt: comb_cnt -= 1 ans = H_max_cnt + W_max_cnt print((ans if comb_cnt else ans - 1))
H, W, M, *hw = list(map(int, open(0).read().split())) H_cnt = [0] * (H + 1) W_cnt = [0] * (W + 1) bombs = [(h, w) for h, w in zip(*[iter(hw)] * 2)] for h, w in bombs: H_cnt[h] += 1 W_cnt[w] += 1 H_max_cnt = max(H_cnt) W_max_cnt = max(W_cnt) comb_cnt = H_cnt.count(H_max_cnt) * W_cnt.count(W_max_cnt) for h, w in bombs: if H_cnt[h] == H_max_cnt and W_cnt[w] == W_max_cnt: comb_cnt -= 1 ans = H_max_cnt + W_max_cnt print((ans if comb_cnt else ans - 1))
false
14.285714
[ "-H_max = {i for i in range(1, H + 1) if H_cnt[i] == H_max_cnt}", "-W_max = {i for i in range(1, W + 1) if W_cnt[i] == W_max_cnt}", "-comb_cnt = len(H_max) * len(W_max)", "+comb_cnt = H_cnt.count(H_max_cnt) * W_cnt.count(W_max_cnt)" ]
false
0.041053
0.039969
1.027137
[ "s660451352", "s268885217" ]
u498487134
p02935
python
s659370614
s372721493
162
67
38,256
61,508
Accepted
Accepted
58.64
N=int(eval(input())) v=list(map(int,input().split())) v.sort() ans=v[0] for i in range(1,N): ans=(ans+v[i])/2 print(ans)
import sys input = sys.stdin.readline def I(): return int(eval(input())) def MI(): return list(map(int, input().split())) def LI(): return list(map(int, input().split())) def main(): mod=10**9+7 N=I() v=LI() v.sort() ans=v[0] for i in range(1,N): ans=(ans+v[i])/2 print(ans) main()
8
18
126
326
N = int(eval(input())) v = list(map(int, input().split())) v.sort() ans = v[0] for i in range(1, N): ans = (ans + v[i]) / 2 print(ans)
import sys input = sys.stdin.readline def I(): return int(eval(input())) def MI(): return list(map(int, input().split())) def LI(): return list(map(int, input().split())) def main(): mod = 10**9 + 7 N = I() v = LI() v.sort() ans = v[0] for i in range(1, N): ans = (ans + v[i]) / 2 print(ans) main()
false
55.555556
[ "-N = int(eval(input()))", "-v = list(map(int, input().split()))", "-v.sort()", "-ans = v[0]", "-for i in range(1, N):", "- ans = (ans + v[i]) / 2", "-print(ans)", "+import sys", "+", "+input = sys.stdin.readline", "+", "+", "+def I():", "+ return int(eval(input()))", "+", "+", ...
false
0.035038
0.042028
0.833698
[ "s659370614", "s372721493" ]
u426764965
p03503
python
s934208629
s359054360
1,855
133
14,440
3,188
Accepted
Accepted
92.83
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import numpy as np def abc080_c(): N = int(readline()) # 他店の数 # 他店の営業パターン:店→日付→営業01 F = np.array([list(map(int, readline().split())) for _ in range(N)], dtype=np.int32) # 他店と何回重なると利益がどうなるか:店→重複回数→利益 P = np.array([list(map(int, readline().split())) for _ in range(N)], dtype=np.int32) ans = -10**12 # 最悪 100 * -10**7 # bit全探索 from itertools import product for mask in product(list(range(2)), repeat=10): if mask.count(1) == 0: continue profit = 0 for i in range(N): # 他店iの営業パターンと、自店の営業パターンmaskと、の要素積は、重複する営業日 overlap = np.multiply(F[i,:], mask).sum() profit += P[i, overlap] ans = max(profit, ans) print(ans) abc080_c()
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines def abc080_c(): N = int(readline()) # 他店の数 # 他店の営業パターン:店→日付→営業01 F = [list(map(int, readline().split())) for _ in range(N)] # 他店と何回重なると利益がどうなるか:店→重複回数→利益 P = [list(map(int, readline().split())) for _ in range(N)] ans = -10**12 # 最悪 100 * -10**7 # bit全探索 from itertools import product from operator import mul for mask in product(list(range(2)), repeat=10): if mask.count(1) == 0: continue profit = 0 for i in range(N): # 他店iの営業パターンと、自店の営業パターンmaskと、の要素積は、重複する営業日 #overlap = sum(x * y for x, y in zip(F[i], mask)) overlap = sum(map(mul, F[i], mask)) profit += P[i][overlap] ans = max(profit, ans) print(ans) abc080_c()
27
28
867
882
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import numpy as np def abc080_c(): N = int(readline()) # 他店の数 # 他店の営業パターン:店→日付→営業01 F = np.array([list(map(int, readline().split())) for _ in range(N)], dtype=np.int32) # 他店と何回重なると利益がどうなるか:店→重複回数→利益 P = np.array([list(map(int, readline().split())) for _ in range(N)], dtype=np.int32) ans = -(10**12) # 最悪 100 * -10**7 # bit全探索 from itertools import product for mask in product(list(range(2)), repeat=10): if mask.count(1) == 0: continue profit = 0 for i in range(N): # 他店iの営業パターンと、自店の営業パターンmaskと、の要素積は、重複する営業日 overlap = np.multiply(F[i, :], mask).sum() profit += P[i, overlap] ans = max(profit, ans) print(ans) abc080_c()
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines def abc080_c(): N = int(readline()) # 他店の数 # 他店の営業パターン:店→日付→営業01 F = [list(map(int, readline().split())) for _ in range(N)] # 他店と何回重なると利益がどうなるか:店→重複回数→利益 P = [list(map(int, readline().split())) for _ in range(N)] ans = -(10**12) # 最悪 100 * -10**7 # bit全探索 from itertools import product from operator import mul for mask in product(list(range(2)), repeat=10): if mask.count(1) == 0: continue profit = 0 for i in range(N): # 他店iの営業パターンと、自店の営業パターンmaskと、の要素積は、重複する営業日 # overlap = sum(x * y for x, y in zip(F[i], mask)) overlap = sum(map(mul, F[i], mask)) profit += P[i][overlap] ans = max(profit, ans) print(ans) abc080_c()
false
3.571429
[ "-import numpy as np", "- F = np.array([list(map(int, readline().split())) for _ in range(N)], dtype=np.int32)", "+ F = [list(map(int, readline().split())) for _ in range(N)]", "- P = np.array([list(map(int, readline().split())) for _ in range(N)], dtype=np.int32)", "+ P = [list(map(int, readlin...
false
0.556904
0.0387
14.390164
[ "s934208629", "s359054360" ]
u562935282
p02993
python
s859907773
s149234766
181
17
38,384
2,940
Accepted
Accepted
90.61
s = eval(input()) flg = True for s1, s2 in zip(s, s[1:]): if s1 == s2: flg = False break print(('Good' if flg else 'Bad'))
s = eval(input()) bl = 1 in (len(set(x)) for x in zip(s, s[1:])) print(('Bad' if bl else 'Good'))
9
3
145
92
s = eval(input()) flg = True for s1, s2 in zip(s, s[1:]): if s1 == s2: flg = False break print(("Good" if flg else "Bad"))
s = eval(input()) bl = 1 in (len(set(x)) for x in zip(s, s[1:])) print(("Bad" if bl else "Good"))
false
66.666667
[ "-flg = True", "-for s1, s2 in zip(s, s[1:]):", "- if s1 == s2:", "- flg = False", "- break", "-print((\"Good\" if flg else \"Bad\"))", "+bl = 1 in (len(set(x)) for x in zip(s, s[1:]))", "+print((\"Bad\" if bl else \"Good\"))" ]
false
0.066588
0.046671
1.42676
[ "s859907773", "s149234766" ]