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
u013756322
p02761
python
s603541979
s283705918
183
165
38,384
38,384
Accepted
Accepted
9.84
n, m = list(map(int, input().split())) if (n == 1 and m == 0): print((0)) exit() if (m == 0): print(('1' + '0' * (n - 1))) exit() dic = {} for i in range(m): s, c = list(map(int, input().split())) try: _ = dic[s] except KeyError: if (s == 1 and c == 0 and n >= 2): print((-1)) exit() dic[s] = c else: if (dic[s] != c): print((-1)) exit() ok = False if (n == 1): start = 0 else: start = 10 ** (n - 1) for i in range(start, 10 ** n): for k, v in list(dic.items()): if (str(i)[k - 1] == str(v)): ok = True else: ok = False break else: if (ok): print(i) exit()
n, m = list(map(int, input().split())) if (n == 1 and m == 0): print((0)) exit() if (m == 0): print(('1' + '0' * (n - 1))) exit() dic = {} for i in range(m): s, c = list(map(int, input().split())) try: _ = dic[s] except KeyError: if (s == 1 and c == 0 and n >= 2): print((-1)) exit() dic[s] = c else: if (dic[s] != c): print((-1)) exit() ok = False if (n == 1): start = 0 else: start = 10 ** (n - 1) for i in range(start, 10 ** n): for k, v in list(dic.items()): if (str(i)[k - 1] != str(v)): break else: print(i) exit()
38
34
781
693
n, m = list(map(int, input().split())) if n == 1 and m == 0: print((0)) exit() if m == 0: print(("1" + "0" * (n - 1))) exit() dic = {} for i in range(m): s, c = list(map(int, input().split())) try: _ = dic[s] except KeyError: if s == 1 and c == 0 and n >= 2: print((-1)) exit() dic[s] = c else: if dic[s] != c: print((-1)) exit() ok = False if n == 1: start = 0 else: start = 10 ** (n - 1) for i in range(start, 10**n): for k, v in list(dic.items()): if str(i)[k - 1] == str(v): ok = True else: ok = False break else: if ok: print(i) exit()
n, m = list(map(int, input().split())) if n == 1 and m == 0: print((0)) exit() if m == 0: print(("1" + "0" * (n - 1))) exit() dic = {} for i in range(m): s, c = list(map(int, input().split())) try: _ = dic[s] except KeyError: if s == 1 and c == 0 and n >= 2: print((-1)) exit() dic[s] = c else: if dic[s] != c: print((-1)) exit() ok = False if n == 1: start = 0 else: start = 10 ** (n - 1) for i in range(start, 10**n): for k, v in list(dic.items()): if str(i)[k - 1] != str(v): break else: print(i) exit()
false
10.526316
[ "- if str(i)[k - 1] == str(v):", "- ok = True", "- else:", "- ok = False", "+ if str(i)[k - 1] != str(v):", "- if ok:", "- print(i)", "- exit()", "+ print(i)", "+ exit()" ]
false
0.048994
0.043264
1.132441
[ "s603541979", "s283705918" ]
u729133443
p03425
python
s112532154
s778854694
54
49
10,864
10,864
Accepted
Accepted
9.26
from itertools import*;d={};g=d.get for t in open(0).read().split():d[t[0]]=g(t[0],0)+1 print((sum(g(p,0)*g(q,0)*g(r,0)for p,q,r in combinations('MARCH',3))))
from itertools import*;d=[0]*128 for t in open(0).read().split():d[ord(t[0])]+=1 print((sum(p*q*r for p,q,r in combinations([d[ord(t)]for t in'MARCH'],3))))
3
3
158
156
from itertools import * d = {} g = d.get for t in open(0).read().split(): d[t[0]] = g(t[0], 0) + 1 print((sum(g(p, 0) * g(q, 0) * g(r, 0) for p, q, r in combinations("MARCH", 3))))
from itertools import * d = [0] * 128 for t in open(0).read().split(): d[ord(t[0])] += 1 print((sum(p * q * r for p, q, r in combinations([d[ord(t)] for t in "MARCH"], 3))))
false
0
[ "-d = {}", "-g = d.get", "+d = [0] * 128", "- d[t[0]] = g(t[0], 0) + 1", "-print((sum(g(p, 0) * g(q, 0) * g(r, 0) for p, q, r in combinations(\"MARCH\", 3))))", "+ d[ord(t[0])] += 1", "+print((sum(p * q * r for p, q, r in combinations([d[ord(t)] for t in \"MARCH\"], 3))))" ]
false
0.046967
0.04646
1.010906
[ "s112532154", "s778854694" ]
u887207211
p03598
python
s615292569
s996309585
20
18
3,060
2,940
Accepted
Accepted
10
N = int(eval(input())) K = int(eval(input())) X = list(map(int,input().split())) ans = 0 k = int(K/2) for x in X: if(x > k): ans += (K-x) * 2 else: ans += x * 2 print(ans)
N = int(eval(input())) K = int(eval(input())) X = list(map(int,input().split())) cnt = 0 for x in X: if(x > K//2): cnt += (K-x)*2 else: cnt += x*2 print(cnt)
12
10
183
166
N = int(eval(input())) K = int(eval(input())) X = list(map(int, input().split())) ans = 0 k = int(K / 2) for x in X: if x > k: ans += (K - x) * 2 else: ans += x * 2 print(ans)
N = int(eval(input())) K = int(eval(input())) X = list(map(int, input().split())) cnt = 0 for x in X: if x > K // 2: cnt += (K - x) * 2 else: cnt += x * 2 print(cnt)
false
16.666667
[ "-ans = 0", "-k = int(K / 2)", "+cnt = 0", "- if x > k:", "- ans += (K - x) * 2", "+ if x > K // 2:", "+ cnt += (K - x) * 2", "- ans += x * 2", "-print(ans)", "+ cnt += x * 2", "+print(cnt)" ]
false
0.037206
0.03817
0.974726
[ "s615292569", "s996309585" ]
u060793972
p03050
python
s176413653
s905850467
442
144
2,940
9,340
Accepted
Accepted
67.42
n=int(eval(input())) p=0 for i in range(1,int(n**0.5)+2): j,k=divmod(n-i,i) p+=0 if k or j<=i else j print(p)
n=int(eval(input())) p=0 for i in range(1,int(n**0.5)+10): if n%i==0 and n//i-1>i: p+=n//i-1 print(p)
6
6
116
112
n = int(eval(input())) p = 0 for i in range(1, int(n**0.5) + 2): j, k = divmod(n - i, i) p += 0 if k or j <= i else j print(p)
n = int(eval(input())) p = 0 for i in range(1, int(n**0.5) + 10): if n % i == 0 and n // i - 1 > i: p += n // i - 1 print(p)
false
0
[ "-for i in range(1, int(n**0.5) + 2):", "- j, k = divmod(n - i, i)", "- p += 0 if k or j <= i else j", "+for i in range(1, int(n**0.5) + 10):", "+ if n % i == 0 and n // i - 1 > i:", "+ p += n // i - 1" ]
false
0.554219
0.20946
2.645936
[ "s176413653", "s905850467" ]
u631277801
p03503
python
s658968331
s392543257
224
80
3,064
3,064
Accepted
Accepted
64.29
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()) def dfs(depth:int, inbis:str, f:list, p:list): if depth != 10: return max(dfs(depth+1, inbis+"1",f,p), dfs(depth+1, inbis+"0",f,p)) else: if inbis.count("1") == 0: return -10**10 else: biz = [int(i) for i in inbis] ans = 0 for i in range(len(f)): common = [biz[j]*f[i][j] for j in range(10)] ans += p[i][sum(common)] return ans n = ni() f = [] p = [] for _ in range(n): f.append(list(li())) for _ in range(n): p.append(list(li())) print((dfs(0,"",f,p)))
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()) n = ni() f = [int("".join(ls()), 2) for _ in range(n)] p = [list(li()) for _ in range(n)] # bit全探索 ans = -float("inf") for bit in range(1, 1<<10): profit = 0 for i,fi in enumerate(f): both = bin(bit&fi).count("1") profit += p[i][both] ans = max(ans, profit) print(ans)
40
30
1,103
778
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()) def dfs(depth: int, inbis: str, f: list, p: list): if depth != 10: return max(dfs(depth + 1, inbis + "1", f, p), dfs(depth + 1, inbis + "0", f, p)) else: if inbis.count("1") == 0: return -(10**10) else: biz = [int(i) for i in inbis] ans = 0 for i in range(len(f)): common = [biz[j] * f[i][j] for j in range(10)] ans += p[i][sum(common)] return ans n = ni() f = [] p = [] for _ in range(n): f.append(list(li())) for _ in range(n): p.append(list(li())) print((dfs(0, "", f, p)))
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()) n = ni() f = [int("".join(ls()), 2) for _ in range(n)] p = [list(li()) for _ in range(n)] # bit全探索 ans = -float("inf") for bit in range(1, 1 << 10): profit = 0 for i, fi in enumerate(f): both = bin(bit & fi).count("1") profit += p[i][both] ans = max(ans, profit) print(ans)
false
25
[ "-def dfs(depth: int, inbis: str, f: list, p: list):", "- if depth != 10:", "- return max(dfs(depth + 1, inbis + \"1\", f, p), dfs(depth + 1, inbis + \"0\", f, p))", "- else:", "- if inbis.count(\"1\") == 0:", "- return -(10**10)", "- else:", "- biz = [int(i) for i in inbis]", "- ans = 0", "- for i in range(len(f)):", "- common = [biz[j] * f[i][j] for j in range(10)]", "- ans += p[i][sum(common)]", "- return ans", "-", "-", "-f = []", "-p = []", "-for _ in range(n):", "- f.append(list(li()))", "-for _ in range(n):", "- p.append(list(li()))", "-print((dfs(0, \"\", f, p)))", "+f = [int(\"\".join(ls()), 2) for _ in range(n)]", "+p = [list(li()) for _ in range(n)]", "+# bit全探索", "+ans = -float(\"inf\")", "+for bit in range(1, 1 << 10):", "+ profit = 0", "+ for i, fi in enumerate(f):", "+ both = bin(bit & fi).count(\"1\")", "+ profit += p[i][both]", "+ ans = max(ans, profit)", "+print(ans)" ]
false
0.041836
0.044593
0.938194
[ "s658968331", "s392543257" ]
u644907318
p02786
python
s300237509
s893277407
174
113
38,384
61,672
Accepted
Accepted
35.06
def f(n): if n==1: return 1 return 1+2*f(n//2) print((f(int(eval(input())))))
memo = {} def f(n): if n==1: return 1 if n in memo: return memo[n] memo[n] = 1+2*f(n//2) return memo[n] print((f(int(eval(input())))))
5
9
89
166
def f(n): if n == 1: return 1 return 1 + 2 * f(n // 2) print((f(int(eval(input())))))
memo = {} def f(n): if n == 1: return 1 if n in memo: return memo[n] memo[n] = 1 + 2 * f(n // 2) return memo[n] print((f(int(eval(input())))))
false
44.444444
[ "+memo = {}", "+", "+", "- return 1 + 2 * f(n // 2)", "+ if n in memo:", "+ return memo[n]", "+ memo[n] = 1 + 2 * f(n // 2)", "+ return memo[n]" ]
false
0.04191
0.037298
1.123644
[ "s300237509", "s893277407" ]
u645250356
p04013
python
s076723387
s172464478
586
515
131,928
118,872
Accepted
Accepted
12.12
from collections import Counter,defaultdict,deque import sys,heapq,bisect,math,itertools,string,queue sys.setrecursionlimit(10**8) mod = 10**9+7 def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) def inpl_str(): return list(sys.stdin.readline().split()) def inpln(n): return list(int(sys.stdin.readline()) for i in range(n)) n,A = inpl() x = inpl() dp = [[[0 for _ in range(n+5)] for i in range(3005)] for j in range(n+5)] dp[0][0][0] = 1 for i in range(n): for j in range(sum(x)+1): for k in range(n): if j >= x[i]: dp[i+1][j][k+1] = dp[i][j-x[i]][k] + dp[i][j][k+1] else: dp[i+1][j][k] = dp[i][j][k] # for i in range(n+1): # print(dp[i][:50]) ans = 0 for j in range(1,sum(x)+1): for k in range(1,n+1): if j/k == A: ans += dp[n][j][k] print(ans)
from collections import Counter,defaultdict,deque import sys,heapq,bisect,math,itertools,string,queue sys.setrecursionlimit(10**8) mod = 10**9+7 def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) def inpl_str(): return list(sys.stdin.readline().split()) def inpln(n): return list(int(sys.stdin.readline()) for i in range(n)) n,A = inpl() x = inpl() nx = n * max(max(x),A) dp = [[[0 for _ in range(n+5)] for i in range(nx+1)] for j in range(n+5)] dp[0][0][0] = 1 for i in range(n): for j in range(nx+1): for k in range(n): if j >= x[i]: dp[i+1][j][k+1] = dp[i][j-x[i]][k] + dp[i][j][k+1] else: dp[i+1][j][k] = dp[i][j][k] ans = 0 for j in range(1,nx+1): for k in range(1,n+1): if j/k == A: ans += dp[n][j][k] print(ans)
28
28
927
896
from collections import Counter, defaultdict, deque import sys, heapq, bisect, math, itertools, string, queue sys.setrecursionlimit(10**8) mod = 10**9 + 7 def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) def inpl_str(): return list(sys.stdin.readline().split()) def inpln(n): return list(int(sys.stdin.readline()) for i in range(n)) n, A = inpl() x = inpl() dp = [[[0 for _ in range(n + 5)] for i in range(3005)] for j in range(n + 5)] dp[0][0][0] = 1 for i in range(n): for j in range(sum(x) + 1): for k in range(n): if j >= x[i]: dp[i + 1][j][k + 1] = dp[i][j - x[i]][k] + dp[i][j][k + 1] else: dp[i + 1][j][k] = dp[i][j][k] # for i in range(n+1): # print(dp[i][:50]) ans = 0 for j in range(1, sum(x) + 1): for k in range(1, n + 1): if j / k == A: ans += dp[n][j][k] print(ans)
from collections import Counter, defaultdict, deque import sys, heapq, bisect, math, itertools, string, queue sys.setrecursionlimit(10**8) mod = 10**9 + 7 def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) def inpl_str(): return list(sys.stdin.readline().split()) def inpln(n): return list(int(sys.stdin.readline()) for i in range(n)) n, A = inpl() x = inpl() nx = n * max(max(x), A) dp = [[[0 for _ in range(n + 5)] for i in range(nx + 1)] for j in range(n + 5)] dp[0][0][0] = 1 for i in range(n): for j in range(nx + 1): for k in range(n): if j >= x[i]: dp[i + 1][j][k + 1] = dp[i][j - x[i]][k] + dp[i][j][k + 1] else: dp[i + 1][j][k] = dp[i][j][k] ans = 0 for j in range(1, nx + 1): for k in range(1, n + 1): if j / k == A: ans += dp[n][j][k] print(ans)
false
0
[ "-dp = [[[0 for _ in range(n + 5)] for i in range(3005)] for j in range(n + 5)]", "+nx = n * max(max(x), A)", "+dp = [[[0 for _ in range(n + 5)] for i in range(nx + 1)] for j in range(n + 5)]", "- for j in range(sum(x) + 1):", "+ for j in range(nx + 1):", "-# for i in range(n+1):", "-# print(dp[i][:50])", "-for j in range(1, sum(x) + 1):", "+for j in range(1, nx + 1):" ]
false
0.100758
0.048542
2.075693
[ "s076723387", "s172464478" ]
u011062360
p02773
python
s838751094
s739195751
704
536
35,572
46,336
Accepted
Accepted
23.86
from collections import Counter n = int(eval(input())) list_S = [eval(input()) for _ in range(n)] dic_S = Counter(list_S) m = 0 for i in list(dic_S.values()): m = max(m, i) ans = [] for k, v in list(dic_S.items()): if v == m: ans.append(k) ans.sort() for s in ans: print(s)
from collections import Counter n = int(eval(input())) list_S = [] ans = [] for _ in range(n): list_S.append(str(eval(input()))) list_S = Counter(list_S) list_S = list(list_S.items()) list_S.sort(key=lambda x:x[1], reverse=True) for l in list_S: if list_S[0][1] == l[1]: ans.append(l[0]) ans.sort() for s in ans: print(s)
14
17
281
347
from collections import Counter n = int(eval(input())) list_S = [eval(input()) for _ in range(n)] dic_S = Counter(list_S) m = 0 for i in list(dic_S.values()): m = max(m, i) ans = [] for k, v in list(dic_S.items()): if v == m: ans.append(k) ans.sort() for s in ans: print(s)
from collections import Counter n = int(eval(input())) list_S = [] ans = [] for _ in range(n): list_S.append(str(eval(input()))) list_S = Counter(list_S) list_S = list(list_S.items()) list_S.sort(key=lambda x: x[1], reverse=True) for l in list_S: if list_S[0][1] == l[1]: ans.append(l[0]) ans.sort() for s in ans: print(s)
false
17.647059
[ "-list_S = [eval(input()) for _ in range(n)]", "-dic_S = Counter(list_S)", "-m = 0", "-for i in list(dic_S.values()):", "- m = max(m, i)", "+list_S = []", "-for k, v in list(dic_S.items()):", "- if v == m:", "- ans.append(k)", "+for _ in range(n):", "+ list_S.append(str(eval(input())))", "+list_S = Counter(list_S)", "+list_S = list(list_S.items())", "+list_S.sort(key=lambda x: x[1], reverse=True)", "+for l in list_S:", "+ if list_S[0][1] == l[1]:", "+ ans.append(l[0])" ]
false
0.046027
0.038232
1.203884
[ "s838751094", "s739195751" ]
u335278042
p03262
python
s816655007
s660938013
92
69
14,252
14,252
Accepted
Accepted
25
N,X = list(map(int, input().split())) def myabs(i): return abs(i-X) xlis = list(map(myabs, list(map(int, input().split())))) from fractions import gcd res = xlis[0] for i in xlis: if i%res == 0: continue res = gcd(i,res) print(res)
N,X = list(map(int, input().split())) def myabs(i): return abs(i-X) xlis = list(map(myabs, list(map(int, input().split())))) def gcd(a, b): while b != 0: a, b = b, a%b return a res = xlis[0] for i in xlis: if i%res == 0: continue res = gcd(i,res) print(res)
14
18
255
302
N, X = list(map(int, input().split())) def myabs(i): return abs(i - X) xlis = list(map(myabs, list(map(int, input().split())))) from fractions import gcd res = xlis[0] for i in xlis: if i % res == 0: continue res = gcd(i, res) print(res)
N, X = list(map(int, input().split())) def myabs(i): return abs(i - X) xlis = list(map(myabs, list(map(int, input().split())))) def gcd(a, b): while b != 0: a, b = b, a % b return a res = xlis[0] for i in xlis: if i % res == 0: continue res = gcd(i, res) print(res)
false
22.222222
[ "-from fractions import gcd", "+", "+", "+def gcd(a, b):", "+ while b != 0:", "+ a, b = b, a % b", "+ return a", "+" ]
false
0.049133
0.037926
1.295472
[ "s816655007", "s660938013" ]
u638795007
p03472
python
s570729645
s243710672
310
275
49,756
42,460
Accepted
Accepted
11.29
import sys def I(): return int(sys.stdin.readline()) def LI(): return list(map(int,sys.stdin.readline().split())) mod = 10**9 + 7 inf = float('inf') N, H = LI() a = [0]*N; b = [0]*N for i in range(N): a[i], b[i] = LI() maxa = max(a) usefulb = [] for i in b: if i>maxa: usefulb.append(i) #print(usefulb) usefulb.sort(reverse = True) cur = int(0) LastH = H for v in usefulb: LastH -= v cur +=1 if LastH<=0: break #print(LastH, maxa) if LastH>0: cur += ((LastH+maxa-1)//maxa) ans = cur print(ans)
def examA(): C = [SI()for _ in range(3)] ans = C[0][0]+C[1][1]+C[2][2] print(ans) return def examB(): N, M = LI() P = [0]*N S = [LSI()for _ in range(M)] pena = 0 ac = set() for p,s in S: p = int(p)-1 if s=="WA": P[p] += 1 else: if p in ac: continue ac.add(p) pena += P[p] print((len(ac),pena)) return def examC(): W, H, N = LI() lx, rx, ly, ry = 0, W, 0, H A = [LI()for _ in range(N)] for x,y,a in A: if a==1: lx = max(lx,x) elif a==2: rx = min(rx,x) elif a==3: ly = max(ly,y) elif a==4: ry = min(ry,y) ans = max(0,rx-lx)*max(0,ry-ly) print(ans) return def examD(): N, H = LI() B = [0]*N maxa = 0 ans = 0 for i in range(N): a, B[i] = LI() if a>maxa: maxa = a B.sort(reverse=True) for b in B: if b<maxa: break H -= b ans += 1 if H<=0: print(ans) return ans += -(-H//maxa) print(ans) return def examE(): ans = 0 print(ans) return def examF(): ans = 0 print(ans) return import sys,bisect,itertools,heapq,math,random from copy import deepcopy from heapq import heappop,heappush,heapify from collections import Counter,defaultdict,deque read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines def I(): return int(readline()) def LI(): return list(map(int,readline().split())) def LSI(): return list(map(str,sys.stdin.readline().split())) def LS(): return sys.stdin.readline().split() def SI(): return sys.stdin.readline().strip() global mod,mod2,inf,alphabet,_ep mod = 10**9 + 7 mod2 = 998244353 inf = 10**18 _ep = 10**(-12) alphabet = [chr(ord('a') + i) for i in range(26)] sys.setrecursionlimit(10**7) if __name__ == '__main__': examD() """ 142 12 9 1445 0 1 asd dfg hj o o aidn """
30
104
564
2,147
import sys def I(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) mod = 10**9 + 7 inf = float("inf") N, H = LI() a = [0] * N b = [0] * N for i in range(N): a[i], b[i] = LI() maxa = max(a) usefulb = [] for i in b: if i > maxa: usefulb.append(i) # print(usefulb) usefulb.sort(reverse=True) cur = int(0) LastH = H for v in usefulb: LastH -= v cur += 1 if LastH <= 0: break # print(LastH, maxa) if LastH > 0: cur += (LastH + maxa - 1) // maxa ans = cur print(ans)
def examA(): C = [SI() for _ in range(3)] ans = C[0][0] + C[1][1] + C[2][2] print(ans) return def examB(): N, M = LI() P = [0] * N S = [LSI() for _ in range(M)] pena = 0 ac = set() for p, s in S: p = int(p) - 1 if s == "WA": P[p] += 1 else: if p in ac: continue ac.add(p) pena += P[p] print((len(ac), pena)) return def examC(): W, H, N = LI() lx, rx, ly, ry = 0, W, 0, H A = [LI() for _ in range(N)] for x, y, a in A: if a == 1: lx = max(lx, x) elif a == 2: rx = min(rx, x) elif a == 3: ly = max(ly, y) elif a == 4: ry = min(ry, y) ans = max(0, rx - lx) * max(0, ry - ly) print(ans) return def examD(): N, H = LI() B = [0] * N maxa = 0 ans = 0 for i in range(N): a, B[i] = LI() if a > maxa: maxa = a B.sort(reverse=True) for b in B: if b < maxa: break H -= b ans += 1 if H <= 0: print(ans) return ans += -(-H // maxa) print(ans) return def examE(): ans = 0 print(ans) return def examF(): ans = 0 print(ans) return import sys, bisect, itertools, heapq, math, random from copy import deepcopy from heapq import heappop, heappush, heapify from collections import Counter, defaultdict, deque read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines def I(): return int(readline()) def LI(): return list(map(int, readline().split())) def LSI(): return list(map(str, sys.stdin.readline().split())) def LS(): return sys.stdin.readline().split() def SI(): return sys.stdin.readline().strip() global mod, mod2, inf, alphabet, _ep mod = 10**9 + 7 mod2 = 998244353 inf = 10**18 _ep = 10 ** (-12) alphabet = [chr(ord("a") + i) for i in range(26)] sys.setrecursionlimit(10**7) if __name__ == "__main__": examD() """ 142 12 9 1445 0 1 asd dfg hj o o aidn """
false
71.153846
[ "-import sys", "+def examA():", "+ C = [SI() for _ in range(3)]", "+ ans = C[0][0] + C[1][1] + C[2][2]", "+ print(ans)", "+ return", "+", "+", "+def examB():", "+ N, M = LI()", "+ P = [0] * N", "+ S = [LSI() for _ in range(M)]", "+ pena = 0", "+ ac = set()", "+ for p, s in S:", "+ p = int(p) - 1", "+ if s == \"WA\":", "+ P[p] += 1", "+ else:", "+ if p in ac:", "+ continue", "+ ac.add(p)", "+ pena += P[p]", "+ print((len(ac), pena))", "+ return", "+", "+", "+def examC():", "+ W, H, N = LI()", "+ lx, rx, ly, ry = 0, W, 0, H", "+ A = [LI() for _ in range(N)]", "+ for x, y, a in A:", "+ if a == 1:", "+ lx = max(lx, x)", "+ elif a == 2:", "+ rx = min(rx, x)", "+ elif a == 3:", "+ ly = max(ly, y)", "+ elif a == 4:", "+ ry = min(ry, y)", "+ ans = max(0, rx - lx) * max(0, ry - ly)", "+ print(ans)", "+ return", "+", "+", "+def examD():", "+ N, H = LI()", "+ B = [0] * N", "+ maxa = 0", "+ ans = 0", "+ for i in range(N):", "+ a, B[i] = LI()", "+ if a > maxa:", "+ maxa = a", "+ B.sort(reverse=True)", "+ for b in B:", "+ if b < maxa:", "+ break", "+ H -= b", "+ ans += 1", "+ if H <= 0:", "+ print(ans)", "+ return", "+ ans += -(-H // maxa)", "+ print(ans)", "+ return", "+", "+", "+def examE():", "+ ans = 0", "+ print(ans)", "+ return", "+", "+", "+def examF():", "+ ans = 0", "+ print(ans)", "+ return", "+", "+", "+import sys, bisect, itertools, heapq, math, random", "+from copy import deepcopy", "+from heapq import heappop, heappush, heapify", "+from collections import Counter, defaultdict, deque", "+", "+read = sys.stdin.buffer.read", "+readline = sys.stdin.buffer.readline", "+readlines = sys.stdin.buffer.readlines", "- return int(sys.stdin.readline())", "+ return int(readline())", "- return list(map(int, sys.stdin.readline().split()))", "+ return list(map(int, readline().split()))", "+def LSI():", "+ return list(map(str, sys.stdin.readline().split()))", "+", "+", "+def LS():", "+ return sys.stdin.readline().split()", "+", "+", "+def SI():", "+ return sys.stdin.readline().strip()", "+", "+", "+global mod, mod2, inf, alphabet, _ep", "-inf = float(\"inf\")", "-N, H = LI()", "-a = [0] * N", "-b = [0] * N", "-for i in range(N):", "- a[i], b[i] = LI()", "-maxa = max(a)", "-usefulb = []", "-for i in b:", "- if i > maxa:", "- usefulb.append(i)", "-# print(usefulb)", "-usefulb.sort(reverse=True)", "-cur = int(0)", "-LastH = H", "-for v in usefulb:", "- LastH -= v", "- cur += 1", "- if LastH <= 0:", "- break", "-# print(LastH, maxa)", "-if LastH > 0:", "- cur += (LastH + maxa - 1) // maxa", "-ans = cur", "-print(ans)", "+mod2 = 998244353", "+inf = 10**18", "+_ep = 10 ** (-12)", "+alphabet = [chr(ord(\"a\") + i) for i in range(26)]", "+sys.setrecursionlimit(10**7)", "+if __name__ == \"__main__\":", "+ examD()", "+\"\"\"", "+142", "+12 9 1445 0 1", "+asd dfg hj o o", "+aidn", "+\"\"\"" ]
false
0.037075
0.040057
0.925539
[ "s570729645", "s243710672" ]
u824237520
p03078
python
s288022043
s709089536
834
275
151,768
48,540
Accepted
Accepted
67.03
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())) ab = [] for s in a: for t in b: ab.append(s + t) ab.sort(reverse=True) c.sort(reverse=True) ans = [] for i in range(min(k, len(ab))): for u in c: ans.append(ab[i] + u) ans.sort(reverse=True) for i in range(k): print((ans[i]))
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())) ans = [] a.sort(reverse=True) b.sort(reverse=True) c.sort(reverse=True) for s in range(x): for t in range(y): for u in range(z): if (s+1) * (t+1) * (u+1) > k: break ans.append(a[s] + b[t] + c[u]) ans.sort(reverse=True) for i in range(k): print((ans[i]))
24
22
428
480
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())) ab = [] for s in a: for t in b: ab.append(s + t) ab.sort(reverse=True) c.sort(reverse=True) ans = [] for i in range(min(k, len(ab))): for u in c: ans.append(ab[i] + u) ans.sort(reverse=True) for i in range(k): print((ans[i]))
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())) ans = [] a.sort(reverse=True) b.sort(reverse=True) c.sort(reverse=True) for s in range(x): for t in range(y): for u in range(z): if (s + 1) * (t + 1) * (u + 1) > k: break ans.append(a[s] + b[t] + c[u]) ans.sort(reverse=True) for i in range(k): print((ans[i]))
false
8.333333
[ "-ab = []", "-for s in a:", "- for t in b:", "- ab.append(s + t)", "-ab.sort(reverse=True)", "+ans = []", "+a.sort(reverse=True)", "+b.sort(reverse=True)", "-ans = []", "-for i in range(min(k, len(ab))):", "- for u in c:", "- ans.append(ab[i] + u)", "+for s in range(x):", "+ for t in range(y):", "+ for u in range(z):", "+ if (s + 1) * (t + 1) * (u + 1) > k:", "+ break", "+ ans.append(a[s] + b[t] + c[u])" ]
false
0.037853
0.054521
0.694291
[ "s288022043", "s709089536" ]
u157020659
p02631
python
s311211749
s829110781
171
149
31,504
31,512
Accepted
Accepted
12.87
n = int(input()) a = list(map(int, input().split())) s = 0 for i in a: s = s ^ i ans = [] for i in a: ans.append(s ^ i) print(*ans, sep=' ')
n = int(input()) a = list(map(int, input().split())) s = 0 for i in a: s = s ^ i ans = [s ^ i for i in a] print(*ans, sep=' ')
9
7
156
136
n = int(input()) a = list(map(int, input().split())) s = 0 for i in a: s = s ^ i ans = [] for i in a: ans.append(s ^ i) print(*ans, sep=" ")
n = int(input()) a = list(map(int, input().split())) s = 0 for i in a: s = s ^ i ans = [s ^ i for i in a] print(*ans, sep=" ")
false
22.222222
[ "-ans = []", "-for i in a:", "- ans.append(s ^ i)", "+ans = [s ^ i for i in a]" ]
false
0.04496
0.044872
1.001957
[ "s311211749", "s829110781" ]
u498487134
p02831
python
s955053722
s242422004
300
64
66,156
62,212
Accepted
Accepted
78.67
import fractions A, B = list(map(int, input().split())) f=fractions.gcd(A,B) print((int(A*B/f)))
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 from math import gcd a,b=MI() print(((a*b)//gcd(a,b))) main()
6
15
96
281
import fractions A, B = list(map(int, input().split())) f = fractions.gcd(A, B) print((int(A * B / f)))
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 from math import gcd a, b = MI() print(((a * b) // gcd(a, b))) main()
false
60
[ "-import fractions", "+import sys", "-A, B = list(map(int, input().split()))", "-f = fractions.gcd(A, B)", "-print((int(A * B / f)))", "+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", "+ from math import gcd", "+", "+ a, b = MI()", "+ print(((a * b) // gcd(a, b)))", "+", "+", "+main()" ]
false
0.043482
0.03604
1.206497
[ "s955053722", "s242422004" ]
u001024152
p02861
python
s680455152
s662067026
340
17
3,064
2,940
Accepted
Accepted
95
from itertools import permutations from math import sqrt N = int(eval(input())) xy = [] for _ in range(N): x, y = list(map(int, input().split())) xy.append((x, y)) _sum = 0 for p in permutations(list(range(N))): s = p[0] x, y = xy[s] for i, pi in enumerate(p): if i == 0: continue nx, ny = xy[pi] d = (nx-x)**2 + (ny-y)**2 _sum += sqrt(d) a = 1 for i in range(1, N+1): a *= i print((_sum/a))
from math import hypot N = int(eval(input())) XY = [tuple(map(int, input().split())) for _ in range(N)] _sum = 0 for xi, yi in XY: for xj, yj in XY: _sum += hypot(xi-xj, yi-yj) print((_sum/N))
25
11
468
210
from itertools import permutations from math import sqrt N = int(eval(input())) xy = [] for _ in range(N): x, y = list(map(int, input().split())) xy.append((x, y)) _sum = 0 for p in permutations(list(range(N))): s = p[0] x, y = xy[s] for i, pi in enumerate(p): if i == 0: continue nx, ny = xy[pi] d = (nx - x) ** 2 + (ny - y) ** 2 _sum += sqrt(d) a = 1 for i in range(1, N + 1): a *= i print((_sum / a))
from math import hypot N = int(eval(input())) XY = [tuple(map(int, input().split())) for _ in range(N)] _sum = 0 for xi, yi in XY: for xj, yj in XY: _sum += hypot(xi - xj, yi - yj) print((_sum / N))
false
56
[ "-from itertools import permutations", "-from math import sqrt", "+from math import hypot", "-xy = []", "-for _ in range(N):", "- x, y = list(map(int, input().split()))", "- xy.append((x, y))", "+XY = [tuple(map(int, input().split())) for _ in range(N)]", "-for p in permutations(list(range(N))):", "- s = p[0]", "- x, y = xy[s]", "- for i, pi in enumerate(p):", "- if i == 0:", "- continue", "- nx, ny = xy[pi]", "- d = (nx - x) ** 2 + (ny - y) ** 2", "- _sum += sqrt(d)", "-a = 1", "-for i in range(1, N + 1):", "- a *= i", "-print((_sum / a))", "+for xi, yi in XY:", "+ for xj, yj in XY:", "+ _sum += hypot(xi - xj, yi - yj)", "+print((_sum / N))" ]
false
0.137664
0.038742
3.553353
[ "s680455152", "s662067026" ]
u285891772
p03013
python
s663705601
s014856646
481
122
496,200
9,860
Accepted
Accepted
74.64
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2 from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left, insort, insort_left from fractions import gcd from heapq import heappush, heappop from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) def ZIP(n): return list(zip(*(MAP() for _ in range(n)))) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10**9 + 7 N, M = MAP() a = [INT() for _ in range(M)] fib_list = [0]*(N+1) fib_list[0] = 1 fib_list[1] = 1 def fib(n): if n < 2: return fib_list[n] elif fib_list[n] != 0: return fib_list[n] else: fib_list[n] = fib(n-1) + fib(n-2) return fib_list[n] tmp = -1 ans = 1 for x in a: #print(tmp, x) if x == tmp+1: print((0)) exit() else: ans = ans*fib(x-tmp-2)%mod tmp = x ans = ans*fib(N-tmp-1)%mod print(ans)
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2 from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left, insort, insort_left from fractions import gcd from heapq import heappush, heappop from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) def ZIP(n): return list(zip(*(MAP() for _ in range(n)))) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10**9 + 7 N, M = MAP() a = deque([INT() for _ in range(M)]) a.append(0) dp = [0]*(N+1) dp[0] = 1 dp[1] = 1 if a[0] == 1: dp[1] = 0 a.popleft() q = a.popleft() for i in range(2, N+1): if i == q: dp[i] = 0 q = a.popleft() else: dp[i] = (dp[i-1] + dp[i-2])%mod print((dp[N]))
54
42
1,329
1,169
import sys, re from collections import deque, defaultdict, Counter from math import ( ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, ) # , log2 from itertools import ( accumulate, permutations, combinations, combinations_with_replacement, product, groupby, ) from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left, insort, insort_left from fractions import gcd from heapq import heappush, heappop from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) def ZIP(n): return list(zip(*(MAP() for _ in range(n)))) sys.setrecursionlimit(10**9) INF = float("inf") mod = 10**9 + 7 N, M = MAP() a = [INT() for _ in range(M)] fib_list = [0] * (N + 1) fib_list[0] = 1 fib_list[1] = 1 def fib(n): if n < 2: return fib_list[n] elif fib_list[n] != 0: return fib_list[n] else: fib_list[n] = fib(n - 1) + fib(n - 2) return fib_list[n] tmp = -1 ans = 1 for x in a: # print(tmp, x) if x == tmp + 1: print((0)) exit() else: ans = ans * fib(x - tmp - 2) % mod tmp = x ans = ans * fib(N - tmp - 1) % mod print(ans)
import sys, re from collections import deque, defaultdict, Counter from math import ( ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, ) # , log2 from itertools import ( accumulate, permutations, combinations, combinations_with_replacement, product, groupby, ) from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left, insort, insort_left from fractions import gcd from heapq import heappush, heappop from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) def ZIP(n): return list(zip(*(MAP() for _ in range(n)))) sys.setrecursionlimit(10**9) INF = float("inf") mod = 10**9 + 7 N, M = MAP() a = deque([INT() for _ in range(M)]) a.append(0) dp = [0] * (N + 1) dp[0] = 1 dp[1] = 1 if a[0] == 1: dp[1] = 0 a.popleft() q = a.popleft() for i in range(2, N + 1): if i == q: dp[i] = 0 q = a.popleft() else: dp[i] = (dp[i - 1] + dp[i - 2]) % mod print((dp[N]))
false
22.222222
[ "-a = [INT() for _ in range(M)]", "-fib_list = [0] * (N + 1)", "-fib_list[0] = 1", "-fib_list[1] = 1", "-", "-", "-def fib(n):", "- if n < 2:", "- return fib_list[n]", "- elif fib_list[n] != 0:", "- return fib_list[n]", "+a = deque([INT() for _ in range(M)])", "+a.append(0)", "+dp = [0] * (N + 1)", "+dp[0] = 1", "+dp[1] = 1", "+if a[0] == 1:", "+ dp[1] = 0", "+ a.popleft()", "+q = a.popleft()", "+for i in range(2, N + 1):", "+ if i == q:", "+ dp[i] = 0", "+ q = a.popleft()", "- fib_list[n] = fib(n - 1) + fib(n - 2)", "- return fib_list[n]", "-", "-", "-tmp = -1", "-ans = 1", "-for x in a:", "- # print(tmp, x)", "- if x == tmp + 1:", "- print((0))", "- exit()", "- else:", "- ans = ans * fib(x - tmp - 2) % mod", "- tmp = x", "-ans = ans * fib(N - tmp - 1) % mod", "-print(ans)", "+ dp[i] = (dp[i - 1] + dp[i - 2]) % mod", "+print((dp[N]))" ]
false
0.125093
0.092804
1.347931
[ "s663705601", "s014856646" ]
u057109575
p02912
python
s953775511
s660688966
333
155
71,228
95,396
Accepted
Accepted
53.45
from heapq import heappush, heappop N, M, *A = list(map(int, open(0).read().split())) q = [] for v in A: heappush(q, -v) for _ in range(M): v = heappop(q) heappush(q, -(-v // 2)) print((-sum(q)))
from heapq import heappush, heappop N, M, *A = list(map(int, open(0).read().split())) q = [] for v in A: heappush(q, -v) for _ in range(M): v = heappop(q) heappush(q, -((-v) // 2)) print((-sum(q)))
13
13
224
226
from heapq import heappush, heappop N, M, *A = list(map(int, open(0).read().split())) q = [] for v in A: heappush(q, -v) for _ in range(M): v = heappop(q) heappush(q, -(-v // 2)) print((-sum(q)))
from heapq import heappush, heappop N, M, *A = list(map(int, open(0).read().split())) q = [] for v in A: heappush(q, -v) for _ in range(M): v = heappop(q) heappush(q, -((-v) // 2)) print((-sum(q)))
false
0
[ "- heappush(q, -(-v // 2))", "+ heappush(q, -((-v) // 2))" ]
false
0.043095
0.049445
0.871561
[ "s953775511", "s660688966" ]
u847467233
p00534
python
s708041408
s311494818
830
580
19,124
19,132
Accepted
Accepted
30.12
# AOJ 0611: Silk Road # Python3 2018.7.4 bal4u import sys from sys import stdin input = stdin.readline INF = 0x7fffffff n, m = list(map(int, input().split())) d = [int(eval(input())) for i in range(n)] c = [int(eval(input())) for i in range(m)] dp = [[INF for j in range(n+1)] for i in range(m+1)] dp[0][0] = 0 for i in range(m): for j in range(n+1): dp[i+1][j] = dp[i][j] for j in range(n): if dp[i][j] != INF: dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j]+c[i]*d[j]) print((dp[m][n]))
# AOJ 0611: Silk Road # Python3 2018.7.4 bal4u import sys from sys import stdin input = stdin.readline INF = 0x7fffffff n, m = list(map(int, input().split())) d = [int(eval(input())) for i in range(n)] c = [int(eval(input())) for i in range(m)] dp = [[INF for j in range(n+1)] for i in range(m+1)] dp[0][0] = 0 for i in range(m): dp[i+1] = dp[i][0:n+1] for j in range(n): if dp[i][j] != INF: dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j]+c[i]*d[j]) print((dp[m][n]))
19
19
490
470
# AOJ 0611: Silk Road # Python3 2018.7.4 bal4u import sys from sys import stdin input = stdin.readline INF = 0x7FFFFFFF n, m = list(map(int, input().split())) d = [int(eval(input())) for i in range(n)] c = [int(eval(input())) for i in range(m)] dp = [[INF for j in range(n + 1)] for i in range(m + 1)] dp[0][0] = 0 for i in range(m): for j in range(n + 1): dp[i + 1][j] = dp[i][j] for j in range(n): if dp[i][j] != INF: dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j] + c[i] * d[j]) print((dp[m][n]))
# AOJ 0611: Silk Road # Python3 2018.7.4 bal4u import sys from sys import stdin input = stdin.readline INF = 0x7FFFFFFF n, m = list(map(int, input().split())) d = [int(eval(input())) for i in range(n)] c = [int(eval(input())) for i in range(m)] dp = [[INF for j in range(n + 1)] for i in range(m + 1)] dp[0][0] = 0 for i in range(m): dp[i + 1] = dp[i][0 : n + 1] for j in range(n): if dp[i][j] != INF: dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j] + c[i] * d[j]) print((dp[m][n]))
false
0
[ "- for j in range(n + 1):", "- dp[i + 1][j] = dp[i][j]", "+ dp[i + 1] = dp[i][0 : n + 1]" ]
false
0.038944
0.037507
1.038302
[ "s708041408", "s311494818" ]
u729133443
p03573
python
s667143394
s669617774
164
27
38,384
9,008
Accepted
Accepted
83.54
print((eval(input().replace(' ','^'))))
print((eval(input().replace(*' ^'))))
1
1
37
35
print((eval(input().replace(" ", "^"))))
print((eval(input().replace(*" ^"))))
false
0
[ "-print((eval(input().replace(\" \", \"^\"))))", "+print((eval(input().replace(*\" ^\"))))" ]
false
0.073223
0.033601
2.179206
[ "s667143394", "s669617774" ]
u940279019
p03211
python
s162010990
s356123708
20
17
3,060
2,940
Accepted
Accepted
15
s = eval(input()) imin = 753 for i in range(len(s)-2): if(abs(int(s[i] + s[i+1] + s[i+2]) - 753) )< imin: imin = abs(int(s[i] + s[i+1] + s[i+2])-753) print(imin)
s = eval(input()) imin = 753 for i in range(len(s) - 2): c = abs(int(s[i]+s[i+1]+s[i+2]) - 753) if c < imin: imin = c print(imin)
6
7
167
137
s = eval(input()) imin = 753 for i in range(len(s) - 2): if (abs(int(s[i] + s[i + 1] + s[i + 2]) - 753)) < imin: imin = abs(int(s[i] + s[i + 1] + s[i + 2]) - 753) print(imin)
s = eval(input()) imin = 753 for i in range(len(s) - 2): c = abs(int(s[i] + s[i + 1] + s[i + 2]) - 753) if c < imin: imin = c print(imin)
false
14.285714
[ "- if (abs(int(s[i] + s[i + 1] + s[i + 2]) - 753)) < imin:", "- imin = abs(int(s[i] + s[i + 1] + s[i + 2]) - 753)", "+ c = abs(int(s[i] + s[i + 1] + s[i + 2]) - 753)", "+ if c < imin:", "+ imin = c" ]
false
0.037935
0.039729
0.954845
[ "s162010990", "s356123708" ]
u214617707
p03371
python
s916889222
s218487725
138
123
3,060
3,060
Accepted
Accepted
10.87
a, b, c, x, y = list(map(int, input().split())) num = float("inf") for i in range(max(x, y) + 1): num = min(num, a * max(0, (x - i)) + b * max(0, (y - i)) + 2 * c * i) print(num)
A, B, C, X, Y = list(map(int, input().split())) num = float("inf") for i in range(0, (10 ** 5) * 2 + 1, 2): num = min(num, max(0, X - i // 2) * A + max(0, Y - i // 2) * B + C * i) print(num)
5
5
180
192
a, b, c, x, y = list(map(int, input().split())) num = float("inf") for i in range(max(x, y) + 1): num = min(num, a * max(0, (x - i)) + b * max(0, (y - i)) + 2 * c * i) print(num)
A, B, C, X, Y = list(map(int, input().split())) num = float("inf") for i in range(0, (10**5) * 2 + 1, 2): num = min(num, max(0, X - i // 2) * A + max(0, Y - i // 2) * B + C * i) print(num)
false
0
[ "-a, b, c, x, y = list(map(int, input().split()))", "+A, B, C, X, Y = list(map(int, input().split()))", "-for i in range(max(x, y) + 1):", "- num = min(num, a * max(0, (x - i)) + b * max(0, (y - i)) + 2 * c * i)", "+for i in range(0, (10**5) * 2 + 1, 2):", "+ num = min(num, max(0, X - i // 2) * A + max(0, Y - i // 2) * B + C * i)" ]
false
0.070645
0.22873
0.308858
[ "s916889222", "s218487725" ]
u489124637
p02659
python
s166075054
s584671410
33
21
10,524
9,036
Accepted
Accepted
36.36
#有理数演算 from math import floor from fractions import Fraction a, b = input().split() a = int(a) b = Fraction(b) print((floor(a * b)))
#正しい丸め処理 a, b = input().split() a = int(a) b = round(float(b) * 100) print((a * b // 100))
9
6
140
94
# 有理数演算 from math import floor from fractions import Fraction a, b = input().split() a = int(a) b = Fraction(b) print((floor(a * b)))
# 正しい丸め処理 a, b = input().split() a = int(a) b = round(float(b) * 100) print((a * b // 100))
false
33.333333
[ "-# 有理数演算", "-from math import floor", "-from fractions import Fraction", "-", "+# 正しい丸め処理", "-b = Fraction(b)", "-print((floor(a * b)))", "+b = round(float(b) * 100)", "+print((a * b // 100))" ]
false
0.044931
0.070413
0.638109
[ "s166075054", "s584671410" ]
u926181697
p03127
python
s675110317
s689231885
175
85
14,252
14,252
Accepted
Accepted
51.43
N = int(eval(input())) L = list(map(int,input().split())) L = sorted(L) while True: for i in range(1,len(L)): L[i] %= L[0] L= [x for x in L if x!=0] L= sorted(L) if len(L) == 1: break print((L[0]))
def gcd(x , y): if x < y: x , y = y , x if y == 0: return x r = x % y return gcd(y , r) N = int(eval(input())) L = list(map(int,input().split())) ans = L[0] for i in range(len(L)): ans = gcd( ans ,L[i] ) print(ans)
11
14
233
259
N = int(eval(input())) L = list(map(int, input().split())) L = sorted(L) while True: for i in range(1, len(L)): L[i] %= L[0] L = [x for x in L if x != 0] L = sorted(L) if len(L) == 1: break print((L[0]))
def gcd(x, y): if x < y: x, y = y, x if y == 0: return x r = x % y return gcd(y, r) N = int(eval(input())) L = list(map(int, input().split())) ans = L[0] for i in range(len(L)): ans = gcd(ans, L[i]) print(ans)
false
21.428571
[ "+def gcd(x, y):", "+ if x < y:", "+ x, y = y, x", "+ if y == 0:", "+ return x", "+ r = x % y", "+ return gcd(y, r)", "+", "+", "-L = sorted(L)", "-while True:", "- for i in range(1, len(L)):", "- L[i] %= L[0]", "- L = [x for x in L if x != 0]", "- L = sorted(L)", "- if len(L) == 1:", "- break", "-print((L[0]))", "+ans = L[0]", "+for i in range(len(L)):", "+ ans = gcd(ans, L[i])", "+print(ans)" ]
false
0.120332
0.038214
3.148848
[ "s675110317", "s689231885" ]
u729133443
p02560
python
s671974280
s175355467
120
104
9,052
8,988
Accepted
Accepted
13.33
code = r""" # distutils: language=c++ # distutils: include_dirs=[/home/contestant/.local/lib/python3.8/site-packages/numpy/core/include, /opt/atcoder-stl] # cython: boundscheck=False # cython: wraparound=False cdef extern from "/opt/atcoder-stl/atcoder/math.hpp" namespace "atcoder": cdef long long floor_sum(long long n, long long m, long long a, long long b) from libc.stdio cimport scanf, printf cdef int t, i cdef long long n, m, a, b scanf('%d', &t) for i in range(t): scanf('%lld%lld%lld%lld', &n, &m, &a, &b) printf('%lld\n', floor_sum(n, m, a, b)) """ import os, sys if sys.argv[-1] == 'ONLINE_JUDGE': open('solve.pyx', 'w').write(code) os.system('cythonize -i -3 -b solve.pyx') import solve
code = r""" # distutils: language=c++ # distutils: include_dirs=[/home/contestant/.local/lib/python3.8/site-packages/numpy/core/include, /opt/atcoder-stl] # cython: boundscheck=False # cython: wraparound=False from libc.stdio cimport getchar, printf cdef extern from "/opt/atcoder-stl/atcoder/math.hpp" namespace "atcoder": cdef long long floor_sum(long long n, long long m, long long a, long long b) cdef long long cin() nogil: cdef long long b, c = 0 while 1: b = getchar() - 48 if b < 0: break c = c * 10 + b return c cdef int i, t = cin() cdef long long n, m, a, b for i in range(t): n = cin() m = cin() a = cin() b = cin() printf('%lld\n', floor_sum(n, m, a, b)) """ import os, sys if sys.argv[-1] == 'ONLINE_JUDGE': open('solve.pyx', 'w').write(code) os.system('cythonize -i -3 -b solve.pyx') import solve
22
29
742
907
code = r""" # distutils: language=c++ # distutils: include_dirs=[/home/contestant/.local/lib/python3.8/site-packages/numpy/core/include, /opt/atcoder-stl] # cython: boundscheck=False # cython: wraparound=False cdef extern from "/opt/atcoder-stl/atcoder/math.hpp" namespace "atcoder": cdef long long floor_sum(long long n, long long m, long long a, long long b) from libc.stdio cimport scanf, printf cdef int t, i cdef long long n, m, a, b scanf('%d', &t) for i in range(t): scanf('%lld%lld%lld%lld', &n, &m, &a, &b) printf('%lld\n', floor_sum(n, m, a, b)) """ import os, sys if sys.argv[-1] == "ONLINE_JUDGE": open("solve.pyx", "w").write(code) os.system("cythonize -i -3 -b solve.pyx") import solve
code = r""" # distutils: language=c++ # distutils: include_dirs=[/home/contestant/.local/lib/python3.8/site-packages/numpy/core/include, /opt/atcoder-stl] # cython: boundscheck=False # cython: wraparound=False from libc.stdio cimport getchar, printf cdef extern from "/opt/atcoder-stl/atcoder/math.hpp" namespace "atcoder": cdef long long floor_sum(long long n, long long m, long long a, long long b) cdef long long cin() nogil: cdef long long b, c = 0 while 1: b = getchar() - 48 if b < 0: break c = c * 10 + b return c cdef int i, t = cin() cdef long long n, m, a, b for i in range(t): n = cin() m = cin() a = cin() b = cin() printf('%lld\n', floor_sum(n, m, a, b)) """ import os, sys if sys.argv[-1] == "ONLINE_JUDGE": open("solve.pyx", "w").write(code) os.system("cythonize -i -3 -b solve.pyx") import solve
false
24.137931
[ "+from libc.stdio cimport getchar, printf", "-from libc.stdio cimport scanf, printf", "-cdef int t, i", "+cdef long long cin() nogil:", "+ cdef long long b, c = 0", "+ while 1:", "+ b = getchar() - 48", "+ if b < 0: break", "+ c = c * 10 + b", "+ return c", "+cdef int i, t = cin()", "-scanf('%d', &t)", "- scanf('%lld%lld%lld%lld', &n, &m, &a, &b)", "+ n = cin()", "+ m = cin()", "+ a = cin()", "+ b = cin()" ]
false
0.035176
0.036031
0.976257
[ "s671974280", "s175355467" ]
u955248595
p02552
python
s470109807
s218493931
28
22
9,016
9,092
Accepted
Accepted
21.43
print(([1,0][eval(input())=='1']))
print((1-int(eval(input()))))
1
1
26
21
print(([1, 0][eval(input()) == "1"]))
print((1 - int(eval(input()))))
false
0
[ "-print(([1, 0][eval(input()) == \"1\"]))", "+print((1 - int(eval(input()))))" ]
false
0.031607
0.139324
0.226863
[ "s470109807", "s218493931" ]
u094191970
p02755
python
s136141386
s959978327
465
26
3,060
2,940
Accepted
Accepted
94.41
a,b=list(map(int,input().split())) n=1 while n<=10**6: if int(n*0.08)==a and int(n*0.1)==b: print(n) exit() else: n+=1 print((-1))
a,b=list(map(int,input().split())) n=1 while n<=2*10**4: if int(n*0.08)==a and int(n*0.1)==b: print(n) exit() else: n+=1 print((-1))
10
10
148
150
a, b = list(map(int, input().split())) n = 1 while n <= 10**6: if int(n * 0.08) == a and int(n * 0.1) == b: print(n) exit() else: n += 1 print((-1))
a, b = list(map(int, input().split())) n = 1 while n <= 2 * 10**4: if int(n * 0.08) == a and int(n * 0.1) == b: print(n) exit() else: n += 1 print((-1))
false
0
[ "-while n <= 10**6:", "+while n <= 2 * 10**4:" ]
false
0.64508
0.040021
16.118377
[ "s136141386", "s959978327" ]
u780342333
p02255
python
s917748249
s924744418
30
20
7,720
5,976
Accepted
Accepted
33.33
N = int(eval(input())) A = [int (x) for x in input().split(" ")] for i in range(1, N): print((" ".join([str(x) for x in A]))) v = A[i] j = i -1 while j>=0 and A[j] > v: A[j+1] = A[j] j -= 1 A[j+1] = v print((" ".join([str(x) for x in A])))
#for i = 1 to A.length-1 # key = A[i] # /* insert A[i] into the sorted sequence A[0,...,j-1] */ #j = i - 1 # while j >= 0 and A[j] > key # A[j+1] = A[j] # j-- # A[j+1] = key n = int(eval(input())) nums = list(map(int, input().split())) for i in range(0, n): key = nums[i] j = i - 1 while (j>=0) and (nums[j] > key): nums[j+1] = nums[j] j -= 1 nums[j+1] = key print((*nums))
13
19
279
446
N = int(eval(input())) A = [int(x) for x in input().split(" ")] for i in range(1, N): print((" ".join([str(x) for x in A]))) v = A[i] j = i - 1 while j >= 0 and A[j] > v: A[j + 1] = A[j] j -= 1 A[j + 1] = v print((" ".join([str(x) for x in A])))
# for i = 1 to A.length-1 # key = A[i] # /* insert A[i] into the sorted sequence A[0,...,j-1] */ # j = i - 1 # while j >= 0 and A[j] > key # A[j+1] = A[j] # j-- # A[j+1] = key n = int(eval(input())) nums = list(map(int, input().split())) for i in range(0, n): key = nums[i] j = i - 1 while (j >= 0) and (nums[j] > key): nums[j + 1] = nums[j] j -= 1 nums[j + 1] = key print((*nums))
false
31.578947
[ "-N = int(eval(input()))", "-A = [int(x) for x in input().split(\" \")]", "-for i in range(1, N):", "- print((\" \".join([str(x) for x in A])))", "- v = A[i]", "+# for i = 1 to A.length-1", "+# key = A[i]", "+# /* insert A[i] into the sorted sequence A[0,...,j-1] */", "+# j = i - 1", "+# while j >= 0 and A[j] > key", "+# A[j+1] = A[j]", "+# j--", "+# A[j+1] = key", "+n = int(eval(input()))", "+nums = list(map(int, input().split()))", "+for i in range(0, n):", "+ key = nums[i]", "- while j >= 0 and A[j] > v:", "- A[j + 1] = A[j]", "+ while (j >= 0) and (nums[j] > key):", "+ nums[j + 1] = nums[j]", "- A[j + 1] = v", "-print((\" \".join([str(x) for x in A])))", "+ nums[j + 1] = key", "+ print((*nums))" ]
false
0.123858
0.109358
1.132589
[ "s917748249", "s924744418" ]
u451017206
p03039
python
s557316850
s543593745
801
179
72,924
38,768
Accepted
Accepted
77.65
from math import factorial N, M, K = list(map(int, input().split())) mod = 10 ** 9 + 7 def Comb(N, K): a = factorial(N) % mod b = factorial(K) % mod c = factorial(N-K) % mod return (a * pow(b, mod-2, mod) * pow(c, mod-2, mod)) % mod c = Comb(N*M-2, K-2) ans = 0 for d in range(M): ans += d * (M - d) * (N ** 2) ans %= mod for d in range(N): ans += d * (N - d) * (M ** 2) ans %= mod ans *= c ans %= mod print(ans)
from math import factorial N, M, K = list(map(int, input().split())) mod = 10 ** 9 + 7 def f(N): a = 1 for i in range(1, N+1): a *= i a %= mod return a % mod def Comb(N, K): a = f(N) b = f(K) c = f(N-K) return (a * pow(b, mod-2, mod) * pow(c, mod-2, mod)) % mod c = Comb(N*M-2, K-2) ans = 0 for d in range(M): ans += d * (M - d) * (N ** 2) ans %= mod for d in range(N): ans += d * (N - d) * (M ** 2) ans %= mod ans *= c ans %= mod print(ans)
28
35
474
539
from math import factorial N, M, K = list(map(int, input().split())) mod = 10**9 + 7 def Comb(N, K): a = factorial(N) % mod b = factorial(K) % mod c = factorial(N - K) % mod return (a * pow(b, mod - 2, mod) * pow(c, mod - 2, mod)) % mod c = Comb(N * M - 2, K - 2) ans = 0 for d in range(M): ans += d * (M - d) * (N**2) ans %= mod for d in range(N): ans += d * (N - d) * (M**2) ans %= mod ans *= c ans %= mod print(ans)
from math import factorial N, M, K = list(map(int, input().split())) mod = 10**9 + 7 def f(N): a = 1 for i in range(1, N + 1): a *= i a %= mod return a % mod def Comb(N, K): a = f(N) b = f(K) c = f(N - K) return (a * pow(b, mod - 2, mod) * pow(c, mod - 2, mod)) % mod c = Comb(N * M - 2, K - 2) ans = 0 for d in range(M): ans += d * (M - d) * (N**2) ans %= mod for d in range(N): ans += d * (N - d) * (M**2) ans %= mod ans *= c ans %= mod print(ans)
false
20
[ "+def f(N):", "+ a = 1", "+ for i in range(1, N + 1):", "+ a *= i", "+ a %= mod", "+ return a % mod", "+", "+", "- a = factorial(N) % mod", "- b = factorial(K) % mod", "- c = factorial(N - K) % mod", "+ a = f(N)", "+ b = f(K)", "+ c = f(N - K)" ]
false
0.041063
0.038946
1.054358
[ "s557316850", "s543593745" ]
u295178043
p02713
python
s838077335
s179958930
638
149
9,388
68,520
Accepted
Accepted
76.65
K = int(eval(input())) g2 = [[0]*(K+1) for _ in range(K+1)] def gcd(a, b): if g2[a][b] > 0: return g2[a][b] tmpa = a tmpb = b while b > 0: a,b = b, a%b g2[tmpa][tmpb] = a g2[tmpb][tmpa] = a return a def gcd_3(a,b,c): g = gcd(a,b) g = gcd(g,c) return g sm = 0 for a in range(1, K+1): sm += a for b in range(a+1, K+1): for c in range(b+1, K+1): sm += gcd_3(a,b,c) * 6 for b in range(1, K+1): if a != b: sm += gcd(a,b) * 3 print(sm)
K = int(eval(input())) g2 = [[0]*(K+1) for _ in range(K+1)] def gcd(a, b): if g2[a][b] > 0: return g2[a][b] tmpa = a tmpb = b while b > 0: a,b = b, a%b g2[tmpa][tmpb] = a g2[tmpb][tmpa] = a return a def gcd_3(a,b,c): g = gcd(a,b) g = gcd(g,c) return g sm = 0 for a in range(1, K+1): for b in range(1, K+1): for c in range(1, K+1): sm += gcd_3(a,b,c) print(sm)
30
26
565
463
K = int(eval(input())) g2 = [[0] * (K + 1) for _ in range(K + 1)] def gcd(a, b): if g2[a][b] > 0: return g2[a][b] tmpa = a tmpb = b while b > 0: a, b = b, a % b g2[tmpa][tmpb] = a g2[tmpb][tmpa] = a return a def gcd_3(a, b, c): g = gcd(a, b) g = gcd(g, c) return g sm = 0 for a in range(1, K + 1): sm += a for b in range(a + 1, K + 1): for c in range(b + 1, K + 1): sm += gcd_3(a, b, c) * 6 for b in range(1, K + 1): if a != b: sm += gcd(a, b) * 3 print(sm)
K = int(eval(input())) g2 = [[0] * (K + 1) for _ in range(K + 1)] def gcd(a, b): if g2[a][b] > 0: return g2[a][b] tmpa = a tmpb = b while b > 0: a, b = b, a % b g2[tmpa][tmpb] = a g2[tmpb][tmpa] = a return a def gcd_3(a, b, c): g = gcd(a, b) g = gcd(g, c) return g sm = 0 for a in range(1, K + 1): for b in range(1, K + 1): for c in range(1, K + 1): sm += gcd_3(a, b, c) print(sm)
false
13.333333
[ "- sm += a", "- for b in range(a + 1, K + 1):", "- for c in range(b + 1, K + 1):", "- sm += gcd_3(a, b, c) * 6", "- if a != b:", "- sm += gcd(a, b) * 3", "+ for c in range(1, K + 1):", "+ sm += gcd_3(a, b, c)" ]
false
0.08804
0.046039
1.912301
[ "s838077335", "s179958930" ]
u222668979
p02615
python
s266535844
s455686855
161
138
32,312
123,960
Accepted
Accepted
14.29
from collections import deque n = int(eval(input())) a = sorted(map(int, input().split()), reverse=True) ans, cnt = 0, deque([a[0]]) for i in a[1:]: ans += cnt.popleft() cnt.extend([i,i]) print(ans)
n = int(eval(input())) a = sorted(map(int, input().split()), reverse=True) ans, que, cnt = 0, [a[0]], 0 for i in a[1:]: ans += que[cnt] que += [i, i] cnt += 1 print(ans)
10
9
212
185
from collections import deque n = int(eval(input())) a = sorted(map(int, input().split()), reverse=True) ans, cnt = 0, deque([a[0]]) for i in a[1:]: ans += cnt.popleft() cnt.extend([i, i]) print(ans)
n = int(eval(input())) a = sorted(map(int, input().split()), reverse=True) ans, que, cnt = 0, [a[0]], 0 for i in a[1:]: ans += que[cnt] que += [i, i] cnt += 1 print(ans)
false
10
[ "-from collections import deque", "-", "-ans, cnt = 0, deque([a[0]])", "+ans, que, cnt = 0, [a[0]], 0", "- ans += cnt.popleft()", "- cnt.extend([i, i])", "+ ans += que[cnt]", "+ que += [i, i]", "+ cnt += 1" ]
false
0.045967
0.046264
0.993586
[ "s266535844", "s455686855" ]
u934442292
p02773
python
s854071612
s992235807
435
328
35,928
35,932
Accepted
Accepted
24.6
import sys from collections import Counter input = sys.stdin.readline def main(): N = int(input()) S = [""] * N for i in range(N): S[i] = input().rstrip() c = Counter(S) max_v = max(c.values()) ans = [k for k, v in c.items() if v == max_v] ans.sort() print(*ans, sep="\n") if __name__ == "__main__": main()
import sys from collections import Counter input = sys.stdin.readline def main(): N = int(eval(input())) S = [""] * N for i in range(N): S[i] = input().rstrip() c = Counter(S) max_v = max(c.values()) ans = [k for k, v in list(c.items()) if v == max_v] ans.sort() print(("\n".join(ans))) if __name__ == "__main__": main()
22
22
379
379
import sys from collections import Counter input = sys.stdin.readline def main(): N = int(input()) S = [""] * N for i in range(N): S[i] = input().rstrip() c = Counter(S) max_v = max(c.values()) ans = [k for k, v in c.items() if v == max_v] ans.sort() print(*ans, sep="\n") if __name__ == "__main__": main()
import sys from collections import Counter input = sys.stdin.readline def main(): N = int(eval(input())) S = [""] * N for i in range(N): S[i] = input().rstrip() c = Counter(S) max_v = max(c.values()) ans = [k for k, v in list(c.items()) if v == max_v] ans.sort() print(("\n".join(ans))) if __name__ == "__main__": main()
false
0
[ "- N = int(input())", "+ N = int(eval(input()))", "- ans = [k for k, v in c.items() if v == max_v]", "+ ans = [k for k, v in list(c.items()) if v == max_v]", "- print(*ans, sep=\"\\n\")", "+ print((\"\\n\".join(ans)))" ]
false
0.034217
0.042025
0.814198
[ "s854071612", "s992235807" ]
u345966487
p03355
python
s388303284
s666225461
48
32
3,060
4,464
Accepted
Accepted
33.33
s=eval(input());k=int(eval(input()));q=[] for i in range(len(s)): for j in range(k):x=s[i:i+j+1];q=q if x in q else sorted(q+[x])[:k] print((q[-1]))
s=eval(input());k=int(eval(input()));print((sorted({s[i:i+j+1]for i in range(len(s))for j in range(k)})[k-1]))
4
1
138
96
s = eval(input()) k = int(eval(input())) q = [] for i in range(len(s)): for j in range(k): x = s[i : i + j + 1] q = q if x in q else sorted(q + [x])[:k] print((q[-1]))
s = eval(input()) k = int(eval(input())) print((sorted({s[i : i + j + 1] for i in range(len(s)) for j in range(k)})[k - 1]))
false
75
[ "-q = []", "-for i in range(len(s)):", "- for j in range(k):", "- x = s[i : i + j + 1]", "- q = q if x in q else sorted(q + [x])[:k]", "-print((q[-1]))", "+print((sorted({s[i : i + j + 1] for i in range(len(s)) for j in range(k)})[k - 1]))" ]
false
0.047065
0.048651
0.967398
[ "s388303284", "s666225461" ]
u832039789
p03073
python
s837619777
s950570502
53
33
3,188
4,256
Accepted
Accepted
37.74
s=eval(input()) n=len(s) a=sum(i%2^int(s[i])for i in range(n)) print((min(a,n-a)))
*s,=list(map(int,eval(input()))) n=len(s) a=sum(s[::2])+n//2-sum(s[1::2]) print((min(a,n-a)))
4
4
77
82
s = eval(input()) n = len(s) a = sum(i % 2 ^ int(s[i]) for i in range(n)) print((min(a, n - a)))
(*s,) = list(map(int, eval(input()))) n = len(s) a = sum(s[::2]) + n // 2 - sum(s[1::2]) print((min(a, n - a)))
false
0
[ "-s = eval(input())", "+(*s,) = list(map(int, eval(input())))", "-a = sum(i % 2 ^ int(s[i]) for i in range(n))", "+a = sum(s[::2]) + n // 2 - sum(s[1::2])" ]
false
0.106152
0.042854
2.477066
[ "s837619777", "s950570502" ]
u086503932
p03546
python
s157296885
s248493863
203
82
40,428
73,524
Accepted
Accepted
59.61
#!/usr/bin/env python3 def main(): H, W = list(map(int, input().split())) INF = 10**12 c = [None for _ in range(10)] for i in range(10): c[i] = list(map(int, input().split())) for k in range(10): for i in range(10): for j in range(10): c[i][j] = min(c[i][j], c[i][k]+c[k][j]) ans = 0 for i in range(H): A = list(map(int, input().split())) for j in range(W): if A[j] != -1: ans += c[A[j]][1] print(ans) if __name__ == "__main__": main()
from heapq import heappop, heappush H, W = list(map(int, input().split())) c = [list(map(int, input().split())) for _ in range(10)] # Dijkstra法で1からの距離を求める INF = 10**12 q = [(0,1)] # 始点のコストとindex d = [INF] * 10 d[1] = 0 while len(q) > 0: cost, u = heappop(q) #print(u,c[u]) for v in range(10): if v == u: continue #print(i,v) tmp = d[u] + c[v][u] #print(v,tmp) if tmp < d[v]: d[v] = tmp heappush(q, (d[v], v)) #print(d) A = [0]*10 for i in range(H): tmp = list(map(int, input().split())) for j in range(W): if tmp[j] >= 0: A[tmp[j]] += 1 ans = 0 for i in range(10): ans += A[i]*d[i] print(ans)
25
35
587
739
#!/usr/bin/env python3 def main(): H, W = list(map(int, input().split())) INF = 10**12 c = [None for _ in range(10)] for i in range(10): c[i] = list(map(int, input().split())) for k in range(10): for i in range(10): for j in range(10): c[i][j] = min(c[i][j], c[i][k] + c[k][j]) ans = 0 for i in range(H): A = list(map(int, input().split())) for j in range(W): if A[j] != -1: ans += c[A[j]][1] print(ans) if __name__ == "__main__": main()
from heapq import heappop, heappush H, W = list(map(int, input().split())) c = [list(map(int, input().split())) for _ in range(10)] # Dijkstra法で1からの距離を求める INF = 10**12 q = [(0, 1)] # 始点のコストとindex d = [INF] * 10 d[1] = 0 while len(q) > 0: cost, u = heappop(q) # print(u,c[u]) for v in range(10): if v == u: continue # print(i,v) tmp = d[u] + c[v][u] # print(v,tmp) if tmp < d[v]: d[v] = tmp heappush(q, (d[v], v)) # print(d) A = [0] * 10 for i in range(H): tmp = list(map(int, input().split())) for j in range(W): if tmp[j] >= 0: A[tmp[j]] += 1 ans = 0 for i in range(10): ans += A[i] * d[i] print(ans)
false
28.571429
[ "-#!/usr/bin/env python3", "-def main():", "- H, W = list(map(int, input().split()))", "- INF = 10**12", "- c = [None for _ in range(10)]", "- for i in range(10):", "- c[i] = list(map(int, input().split()))", "- for k in range(10):", "- for i in range(10):", "- for j in range(10):", "- c[i][j] = min(c[i][j], c[i][k] + c[k][j])", "- ans = 0", "- for i in range(H):", "- A = list(map(int, input().split()))", "- for j in range(W):", "- if A[j] != -1:", "- ans += c[A[j]][1]", "- print(ans)", "+from heapq import heappop, heappush", "-", "-if __name__ == \"__main__\":", "- main()", "+H, W = list(map(int, input().split()))", "+c = [list(map(int, input().split())) for _ in range(10)]", "+# Dijkstra法で1からの距離を求める", "+INF = 10**12", "+q = [(0, 1)] # 始点のコストとindex", "+d = [INF] * 10", "+d[1] = 0", "+while len(q) > 0:", "+ cost, u = heappop(q)", "+ # print(u,c[u])", "+ for v in range(10):", "+ if v == u:", "+ continue", "+ # print(i,v)", "+ tmp = d[u] + c[v][u]", "+ # print(v,tmp)", "+ if tmp < d[v]:", "+ d[v] = tmp", "+ heappush(q, (d[v], v))", "+ # print(d)", "+A = [0] * 10", "+for i in range(H):", "+ tmp = list(map(int, input().split()))", "+ for j in range(W):", "+ if tmp[j] >= 0:", "+ A[tmp[j]] += 1", "+ans = 0", "+for i in range(10):", "+ ans += A[i] * d[i]", "+print(ans)" ]
false
0.072523
0.073984
0.980245
[ "s157296885", "s248493863" ]
u254871849
p02954
python
s075015721
s694646389
155
102
6,896
9,084
Accepted
Accepted
34.19
# 2019-11-16 10:55:08(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 import re def main(): # 左がRで右がLとなっている箇所でそれぞれどちらかにあつまる。10^100 は実質無限なので距離が奇数か偶数かで場合わけ s = sys.stdin.readline().rstrip() + 'R' # 後々のループ処理のときのことを考えて最後にRを足しておく n = len(s) - 1 all_occurrences_of_rl = [m.start() for m in re.finditer('RL', s)] counts = [0 for _ in range(n)] left = 0 for i in range(len(all_occurrences_of_rl)): right = all_occurrences_of_rl[i] + 1 while s[right+1] == 'L': # 次がLだったら右端を拡張していく right += 1 r_count = 1 + (all_occurrences_of_rl[i] - left) // 2 + (right - all_occurrences_of_rl[i]) // 2 l_count = (right - left + 1) - r_count counts[all_occurrences_of_rl[i]] = r_count counts[all_occurrences_of_rl[i] + 1] = l_count left = right + 1 for i in range(n): print(counts[i], end=' ') if __name__ == "__main__": main()
import sys s = sys.stdin.readline().rstrip() n = len(s) s += 'R' def main(): l = [] for i in range(1, n): if s[i] == 'L': if s[i-1] == 'R': ls = i if s[i+1] == 'R': lg = i l.append((ls, lg)) res = [0] * n j = 0 ls, lg = l[j] for i in range(n): if i > lg: j += 1 ls, lg = l[j] d = abs(ls - i) if d & 1: res[ls-1] += 1 else: res[ls] += 1 return res if __name__ == '__main__': ans = main() print(*ans, sep=' ')
39
34
1,245
649
# 2019-11-16 10:55:08(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 import re def main(): # 左がRで右がLとなっている箇所でそれぞれどちらかにあつまる。10^100 は実質無限なので距離が奇数か偶数かで場合わけ s = sys.stdin.readline().rstrip() + "R" # 後々のループ処理のときのことを考えて最後にRを足しておく n = len(s) - 1 all_occurrences_of_rl = [m.start() for m in re.finditer("RL", s)] counts = [0 for _ in range(n)] left = 0 for i in range(len(all_occurrences_of_rl)): right = all_occurrences_of_rl[i] + 1 while s[right + 1] == "L": # 次がLだったら右端を拡張していく right += 1 r_count = ( 1 + (all_occurrences_of_rl[i] - left) // 2 + (right - all_occurrences_of_rl[i]) // 2 ) l_count = (right - left + 1) - r_count counts[all_occurrences_of_rl[i]] = r_count counts[all_occurrences_of_rl[i] + 1] = l_count left = right + 1 for i in range(n): print(counts[i], end=" ") if __name__ == "__main__": main()
import sys s = sys.stdin.readline().rstrip() n = len(s) s += "R" def main(): l = [] for i in range(1, n): if s[i] == "L": if s[i - 1] == "R": ls = i if s[i + 1] == "R": lg = i l.append((ls, lg)) res = [0] * n j = 0 ls, lg = l[j] for i in range(n): if i > lg: j += 1 ls, lg = l[j] d = abs(ls - i) if d & 1: res[ls - 1] += 1 else: res[ls] += 1 return res if __name__ == "__main__": ans = main() print(*ans, sep=" ")
false
12.820513
[ "-# 2019-11-16 10:55:08(JST)", "-# import collections", "-# import math", "-# from string import ascii_lowercase, ascii_uppercase, digits", "-# from bisect import bisect_left as bi_l, bisect_right as bi_r", "-# import itertools", "-# from functools import reduce", "-# import operator as op", "-# from scipy.misc import comb # float", "-# import numpy as np", "-import re", "+s = sys.stdin.readline().rstrip()", "+n = len(s)", "+s += \"R\"", "- # 左がRで右がLとなっている箇所でそれぞれどちらかにあつまる。10^100 は実質無限なので距離が奇数か偶数かで場合わけ", "- s = sys.stdin.readline().rstrip() + \"R\" # 後々のループ処理のときのことを考えて最後にRを足しておく", "- n = len(s) - 1", "- all_occurrences_of_rl = [m.start() for m in re.finditer(\"RL\", s)]", "- counts = [0 for _ in range(n)]", "- left = 0", "- for i in range(len(all_occurrences_of_rl)):", "- right = all_occurrences_of_rl[i] + 1", "- while s[right + 1] == \"L\": # 次がLだったら右端を拡張していく", "- right += 1", "- r_count = (", "- 1", "- + (all_occurrences_of_rl[i] - left) // 2", "- + (right - all_occurrences_of_rl[i]) // 2", "- )", "- l_count = (right - left + 1) - r_count", "- counts[all_occurrences_of_rl[i]] = r_count", "- counts[all_occurrences_of_rl[i] + 1] = l_count", "- left = right + 1", "+ l = []", "+ for i in range(1, n):", "+ if s[i] == \"L\":", "+ if s[i - 1] == \"R\":", "+ ls = i", "+ if s[i + 1] == \"R\":", "+ lg = i", "+ l.append((ls, lg))", "+ res = [0] * n", "+ j = 0", "+ ls, lg = l[j]", "- print(counts[i], end=\" \")", "+ if i > lg:", "+ j += 1", "+ ls, lg = l[j]", "+ d = abs(ls - i)", "+ if d & 1:", "+ res[ls - 1] += 1", "+ else:", "+ res[ls] += 1", "+ return res", "- main()", "+ ans = main()", "+ print(*ans, sep=\" \")" ]
false
0.067806
0.03642
1.861759
[ "s075015721", "s694646389" ]
u303039933
p02720
python
s380509689
s591868348
279
94
62,572
14,860
Accepted
Accepted
66.31
# -*- coding: utf-8 -*- import sys import math import os import itertools import string import heapq import _collections from collections import Counter from collections import defaultdict from functools import lru_cache import bisect import re import queue from decimal import * class Scanner(): @staticmethod def int(): return int(sys.stdin.readline().rstrip()) @staticmethod def string(): return sys.stdin.readline().rstrip() @staticmethod def map_int(): return [int(x) for x in Scanner.string().split()] @staticmethod def string_list(n): return [eval(input()) for i in range(n)] @staticmethod def int_list_list(n): return [Scanner.map_int() for i in range(n)] @staticmethod def int_cols_list(n): return [int(eval(input())) for i in range(n)] class Math(): @staticmethod def gcd(a, b): if b == 0: return a return Math.gcd(b, a % b) @staticmethod def lcm(a, b): return (a * b) // Math.gcd(a, b) @staticmethod def divisor(n): res = [] i = 1 for i in range(1, int(n ** 0.5) + 1): if n % i == 0: res.append(i) if i != n // i: res.append(n // i) return res @staticmethod def round_up(a, b): return -(-a // b) @staticmethod def is_prime(n): if n < 2: return False if n == 2: return True if n % 2 == 0: return False d = int(n ** 0.5) + 1 for i in range(3, d + 1, 2): if n % i == 0: return False return True def pop_count(x): x = x - ((x >> 1) & 0x5555555555555555) x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333) x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f x = x + (x >> 8) x = x + (x >> 16) x = x + (x >> 32) return x & 0x0000007f MOD = int(1e09) + 7 INF = int(1e15) def isOK(A): A.sort() for i in range(len(A) - 1): if A[i] + 1 != A[i + 1]: return False return True def func(x): return 1 def solve(): K = Scanner.int() q = queue.deque() for i in range(1, 9 + 1): q.append(i) for _ in range(K - 1): x = q.popleft() if x % 10 != 0: q.append(x * 10 + x % 10 - 1) q.append(x * 10 + x % 10) if x % 10 != 9: q.append(x * 10 + x % 10 + 1) print((q.popleft())) def main(): # sys.stdin = open("sample.txt") solve() if __name__ == "__main__": main()
# -*- coding: utf-8 -*- import sys import math import os import itertools import string import heapq import _collections from collections import Counter from collections import defaultdict from collections import deque from functools import lru_cache import bisect import re import queue import decimal class Scanner(): @staticmethod def int(): return int(sys.stdin.readline().rstrip()) @staticmethod def string(): return sys.stdin.readline().rstrip() @staticmethod def map_int(): return [int(x) for x in Scanner.string().split()] @staticmethod def string_list(n): return [Scanner.string() for i in range(n)] @staticmethod def int_list_list(n): return [Scanner.map_int() for i in range(n)] @staticmethod def int_cols_list(n): return [Scanner.int() for i in range(n)] class Math(): @staticmethod def gcd(a, b): if b == 0: return a return Math.gcd(b, a % b) @staticmethod def lcm(a, b): return (a * b) // Math.gcd(a, b) @staticmethod def divisor(n): res = [] i = 1 for i in range(1, int(n ** 0.5) + 1): if n % i == 0: res.append(i) if i != n // i: res.append(n // i) return res @staticmethod def round_up(a, b): return -(-a // b) @staticmethod def is_prime(n): if n < 2: return False if n == 2: return True if n % 2 == 0: return False d = int(n ** 0.5) + 1 for i in range(3, d + 1, 2): if n % i == 0: return False return True @staticmethod def fact(N): res = {} tmp = N for i in range(2, int(N ** 0.5 + 1) + 1): cnt = 0 while tmp % i == 0: cnt += 1 tmp //= i if cnt > 0: res[i] = cnt if tmp != 1: res[tmp] = 1 if res == {}: res[N] = 1 return res def pop_count(x): x = x - ((x >> 1) & 0x5555555555555555) x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333) x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f x = x + (x >> 8) x = x + (x >> 16) x = x + (x >> 32) return x & 0x0000007f MOD = int(1e09) + 7 INF = int(1e15) def solve(): K = Scanner.int() d = deque() for i in range(1, 10): d.append(i) MAX = 10 ** 5 + 100 for i in range(MAX): n = d[i] a = int(str(n)[-1]) if a != 0: d.append(n * 10 + (a - 1)) d.append(n * 10 + a) if a != 9: d.append(n * 10 + (a + 1)) if len(d) >= K: print((d[K - 1])) return def main(): # sys.stdin = open("sample.txt") # T = Scanner.int() # for _ in range(T): # solve() # print('YNeos'[not solve()::2]) solve() if __name__ == "__main__": main()
132
146
2,741
3,176
# -*- coding: utf-8 -*- import sys import math import os import itertools import string import heapq import _collections from collections import Counter from collections import defaultdict from functools import lru_cache import bisect import re import queue from decimal import * class Scanner: @staticmethod def int(): return int(sys.stdin.readline().rstrip()) @staticmethod def string(): return sys.stdin.readline().rstrip() @staticmethod def map_int(): return [int(x) for x in Scanner.string().split()] @staticmethod def string_list(n): return [eval(input()) for i in range(n)] @staticmethod def int_list_list(n): return [Scanner.map_int() for i in range(n)] @staticmethod def int_cols_list(n): return [int(eval(input())) for i in range(n)] class Math: @staticmethod def gcd(a, b): if b == 0: return a return Math.gcd(b, a % b) @staticmethod def lcm(a, b): return (a * b) // Math.gcd(a, b) @staticmethod def divisor(n): res = [] i = 1 for i in range(1, int(n**0.5) + 1): if n % i == 0: res.append(i) if i != n // i: res.append(n // i) return res @staticmethod def round_up(a, b): return -(-a // b) @staticmethod def is_prime(n): if n < 2: return False if n == 2: return True if n % 2 == 0: return False d = int(n**0.5) + 1 for i in range(3, d + 1, 2): if n % i == 0: return False return True def pop_count(x): x = x - ((x >> 1) & 0x5555555555555555) x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333) x = (x + (x >> 4)) & 0x0F0F0F0F0F0F0F0F x = x + (x >> 8) x = x + (x >> 16) x = x + (x >> 32) return x & 0x0000007F MOD = int(1e09) + 7 INF = int(1e15) def isOK(A): A.sort() for i in range(len(A) - 1): if A[i] + 1 != A[i + 1]: return False return True def func(x): return 1 def solve(): K = Scanner.int() q = queue.deque() for i in range(1, 9 + 1): q.append(i) for _ in range(K - 1): x = q.popleft() if x % 10 != 0: q.append(x * 10 + x % 10 - 1) q.append(x * 10 + x % 10) if x % 10 != 9: q.append(x * 10 + x % 10 + 1) print((q.popleft())) def main(): # sys.stdin = open("sample.txt") solve() if __name__ == "__main__": main()
# -*- coding: utf-8 -*- import sys import math import os import itertools import string import heapq import _collections from collections import Counter from collections import defaultdict from collections import deque from functools import lru_cache import bisect import re import queue import decimal class Scanner: @staticmethod def int(): return int(sys.stdin.readline().rstrip()) @staticmethod def string(): return sys.stdin.readline().rstrip() @staticmethod def map_int(): return [int(x) for x in Scanner.string().split()] @staticmethod def string_list(n): return [Scanner.string() for i in range(n)] @staticmethod def int_list_list(n): return [Scanner.map_int() for i in range(n)] @staticmethod def int_cols_list(n): return [Scanner.int() for i in range(n)] class Math: @staticmethod def gcd(a, b): if b == 0: return a return Math.gcd(b, a % b) @staticmethod def lcm(a, b): return (a * b) // Math.gcd(a, b) @staticmethod def divisor(n): res = [] i = 1 for i in range(1, int(n**0.5) + 1): if n % i == 0: res.append(i) if i != n // i: res.append(n // i) return res @staticmethod def round_up(a, b): return -(-a // b) @staticmethod def is_prime(n): if n < 2: return False if n == 2: return True if n % 2 == 0: return False d = int(n**0.5) + 1 for i in range(3, d + 1, 2): if n % i == 0: return False return True @staticmethod def fact(N): res = {} tmp = N for i in range(2, int(N**0.5 + 1) + 1): cnt = 0 while tmp % i == 0: cnt += 1 tmp //= i if cnt > 0: res[i] = cnt if tmp != 1: res[tmp] = 1 if res == {}: res[N] = 1 return res def pop_count(x): x = x - ((x >> 1) & 0x5555555555555555) x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333) x = (x + (x >> 4)) & 0x0F0F0F0F0F0F0F0F x = x + (x >> 8) x = x + (x >> 16) x = x + (x >> 32) return x & 0x0000007F MOD = int(1e09) + 7 INF = int(1e15) def solve(): K = Scanner.int() d = deque() for i in range(1, 10): d.append(i) MAX = 10**5 + 100 for i in range(MAX): n = d[i] a = int(str(n)[-1]) if a != 0: d.append(n * 10 + (a - 1)) d.append(n * 10 + a) if a != 9: d.append(n * 10 + (a + 1)) if len(d) >= K: print((d[K - 1])) return def main(): # sys.stdin = open("sample.txt") # T = Scanner.int() # for _ in range(T): # solve() # print('YNeos'[not solve()::2]) solve() if __name__ == "__main__": main()
false
9.589041
[ "+from collections import deque", "-from decimal import *", "+import decimal", "- return [eval(input()) for i in range(n)]", "+ return [Scanner.string() for i in range(n)]", "- return [int(eval(input())) for i in range(n)]", "+ return [Scanner.int() for i in range(n)]", "+ @staticmethod", "+ def fact(N):", "+ res = {}", "+ tmp = N", "+ for i in range(2, int(N**0.5 + 1) + 1):", "+ cnt = 0", "+ while tmp % i == 0:", "+ cnt += 1", "+ tmp //= i", "+ if cnt > 0:", "+ res[i] = cnt", "+ if tmp != 1:", "+ res[tmp] = 1", "+ if res == {}:", "+ res[N] = 1", "+ return res", "+", "-def isOK(A):", "- A.sort()", "- for i in range(len(A) - 1):", "- if A[i] + 1 != A[i + 1]:", "- return False", "- return True", "-", "-", "-def func(x):", "- return 1", "-", "-", "- q = queue.deque()", "- for i in range(1, 9 + 1):", "- q.append(i)", "- for _ in range(K - 1):", "- x = q.popleft()", "- if x % 10 != 0:", "- q.append(x * 10 + x % 10 - 1)", "- q.append(x * 10 + x % 10)", "- if x % 10 != 9:", "- q.append(x * 10 + x % 10 + 1)", "- print((q.popleft()))", "+ d = deque()", "+ for i in range(1, 10):", "+ d.append(i)", "+ MAX = 10**5 + 100", "+ for i in range(MAX):", "+ n = d[i]", "+ a = int(str(n)[-1])", "+ if a != 0:", "+ d.append(n * 10 + (a - 1))", "+ d.append(n * 10 + a)", "+ if a != 9:", "+ d.append(n * 10 + (a + 1))", "+ if len(d) >= K:", "+ print((d[K - 1]))", "+ return", "+ # T = Scanner.int()", "+ # for _ in range(T):", "+ # solve()", "+ # print('YNeos'[not solve()::2])" ]
false
0.047319
0.100681
0.469986
[ "s380509689", "s591868348" ]
u874723578
p03103
python
s435868647
s807643818
830
204
64,984
25,828
Accepted
Accepted
75.42
n, m = list(map(int, input().split())) A = [] B = [] for i in range(n): x, y = list(map(int, input().split())) A.append(x) B.append(y) ans = 0 for price, amount in sorted(zip(A, B)): ans += price * min(m, amount) m -= amount if m <= 0: break print(ans)
n, m, *l= list(map(int, open(0).read().split())) ans = 0 for price, amount in sorted(zip(l[::2], l[1::2])): ans += price * min(m, amount) m -= amount if m <= 0: break print(ans)
15
9
287
200
n, m = list(map(int, input().split())) A = [] B = [] for i in range(n): x, y = list(map(int, input().split())) A.append(x) B.append(y) ans = 0 for price, amount in sorted(zip(A, B)): ans += price * min(m, amount) m -= amount if m <= 0: break print(ans)
n, m, *l = list(map(int, open(0).read().split())) ans = 0 for price, amount in sorted(zip(l[::2], l[1::2])): ans += price * min(m, amount) m -= amount if m <= 0: break print(ans)
false
40
[ "-n, m = list(map(int, input().split()))", "-A = []", "-B = []", "-for i in range(n):", "- x, y = list(map(int, input().split()))", "- A.append(x)", "- B.append(y)", "+n, m, *l = list(map(int, open(0).read().split()))", "-for price, amount in sorted(zip(A, B)):", "+for price, amount in sorted(zip(l[::2], l[1::2])):" ]
false
0.035173
0.042748
0.822801
[ "s435868647", "s807643818" ]
u363610900
p03577
python
s974223048
s977041372
20
17
2,940
2,940
Accepted
Accepted
15
s = eval(input()) print((s[0:len(s)-8]))
S = eval(input()) print((S[:-8]))
2
2
33
26
s = eval(input()) print((s[0 : len(s) - 8]))
S = eval(input()) print((S[:-8]))
false
0
[ "-s = eval(input())", "-print((s[0 : len(s) - 8]))", "+S = eval(input())", "+print((S[:-8]))" ]
false
0.046303
0.0447
1.035859
[ "s974223048", "s977041372" ]
u795688372
p02762
python
s763137942
s044106966
1,260
699
94,512
83,784
Accepted
Accepted
44.52
N, M, K = map(int, input().split()) friend = [[] for _ in range(N)] block = [[] for _ in range(N)] for _ in range(M): a, b = map(int, input().split()) friend[a - 1].append(b - 1) friend[b - 1].append(a - 1) for _ in range(K): a, b = map(int, input().split()) block[a - 1].append(b - 1) block[b - 1].append(a - 1) vst = [0] * N SIZE = [] C = 0 for i in range(N): if not vst[i]: C += 1 vst[i] = C q = [i] cnt = 0 for u in q: cnt += 1 for v in friend[u]: if not vst[v]: vst[v] = C q.append(v) SIZE.append(cnt) for i in range(N): ret = SIZE[vst[i] - 1] - 1 ret -= len(friend[i]) for b in block[i]: if vst[i] == vst[b]: ret -= 1 print(ret, end=' ') print()
import sys input = sys.stdin.readline N, M, K = map(int, input().split()) friend = [[] for _ in range(N)] block = [[] for _ in range(N)] for _ in range(M): a, b = map(int, input().split()) friend[a - 1].append(b - 1) friend[b - 1].append(a - 1) for _ in range(K): a, b = map(int, input().split()) block[a - 1].append(b - 1) block[b - 1].append(a - 1) vst = [0] * N SIZE = [] C = 0 for i in range(N): if not vst[i]: C += 1 vst[i] = C q = [i] cnt = 0 for u in q: cnt += 1 for v in friend[u]: if not vst[v]: vst[v] = C q.append(v) SIZE.append(cnt) for i in range(N): ret = SIZE[vst[i] - 1] - 1 ret -= len(friend[i]) for b in block[i]: if vst[i] == vst[b]: ret -= 1 print(ret, end=' ') print()
38
41
884
926
N, M, K = map(int, input().split()) friend = [[] for _ in range(N)] block = [[] for _ in range(N)] for _ in range(M): a, b = map(int, input().split()) friend[a - 1].append(b - 1) friend[b - 1].append(a - 1) for _ in range(K): a, b = map(int, input().split()) block[a - 1].append(b - 1) block[b - 1].append(a - 1) vst = [0] * N SIZE = [] C = 0 for i in range(N): if not vst[i]: C += 1 vst[i] = C q = [i] cnt = 0 for u in q: cnt += 1 for v in friend[u]: if not vst[v]: vst[v] = C q.append(v) SIZE.append(cnt) for i in range(N): ret = SIZE[vst[i] - 1] - 1 ret -= len(friend[i]) for b in block[i]: if vst[i] == vst[b]: ret -= 1 print(ret, end=" ") print()
import sys input = sys.stdin.readline N, M, K = map(int, input().split()) friend = [[] for _ in range(N)] block = [[] for _ in range(N)] for _ in range(M): a, b = map(int, input().split()) friend[a - 1].append(b - 1) friend[b - 1].append(a - 1) for _ in range(K): a, b = map(int, input().split()) block[a - 1].append(b - 1) block[b - 1].append(a - 1) vst = [0] * N SIZE = [] C = 0 for i in range(N): if not vst[i]: C += 1 vst[i] = C q = [i] cnt = 0 for u in q: cnt += 1 for v in friend[u]: if not vst[v]: vst[v] = C q.append(v) SIZE.append(cnt) for i in range(N): ret = SIZE[vst[i] - 1] - 1 ret -= len(friend[i]) for b in block[i]: if vst[i] == vst[b]: ret -= 1 print(ret, end=" ") print()
false
7.317073
[ "+import sys", "+", "+input = sys.stdin.readline" ]
false
0.040997
0.038612
1.061752
[ "s763137942", "s044106966" ]
u225388820
p02558
python
s534122398
s756621677
257
209
87,912
83,448
Accepted
Accepted
18.68
import typing class DSU: ''' Implement (union by size) + (path compression) Reference: Zvi Galil and Giuseppe F. Italiano, Data structures and algorithms for disjoint set union problems ''' def __init__(self, n: int = 0): self._n = n self.parent_or_size = [-1] * n def merge(self, a: int, b: int) -> int: assert 0 <= a < self._n assert 0 <= b < self._n x = self.leader(a) y = self.leader(b) if x == y: return x if -self.parent_or_size[x] < -self.parent_or_size[y]: x, y = y, x self.parent_or_size[x] += self.parent_or_size[y] self.parent_or_size[y] = x return x def same(self, a: int, b: int) -> bool: assert 0 <= a < self._n assert 0 <= b < self._n return self.leader(a) == self.leader(b) def leader(self, a: int) -> int: assert 0 <= a < self._n r = a while self.parent_or_size[r] >= 0: r = self.parent_or_size[r] while self.parent_or_size[a] >= 0: self.parent_or_size[a], a = r, self.parent_or_size[a] return r def size(self, a: int) -> int: assert 0 <= a < self._n return -self.parent_or_size[self.leader(a)] def groups(self) -> typing.List[typing.List[int]]: leader_buf = [self.leader(i) for i in range(self._n)] result = [[] for _ in range(self._n)] for i in range(self._n): result[leader_buf[i]].append(i) return list([r for r in result if r]) import sys input = sys.stdin.readline n, q = list(map(int, input().split())) uf = DSU(n) res = [] for i in range(q): t, u, v = list(map(int, input().split())) if t: res.append(int(uf.same(u, v))) else: uf.merge(u, v) print(("\n".join(map(str, res))))
class UnionFind: __slots__ = ["N", "root"] def __init__(self, N): """ N:要素数 root:各要素の親要素の番号を格納するリスト. ただし, root[x] < 0 ならその頂点が根で-root[x]が木の要素数. """ self.N = N self.root = [-1] * N def __repr__(self): return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots()) def find(self, x): """頂点xの根を見つける""" r = x while self.root[r] >= 0: r = self.root[r] while self.root[x] >= 0: self.root[x], x = r, self.root[x] return r def union(self, x, y): """x, yが属する木をunion""" x = self.find(x) y = self.find(y) if x == y: return elif self.root[y] < self.root[x]: x, y = y, x self.root[x] += self.root[y] self.root[y] = x def same(self, x, y): """xとyが同じグループに属するかどうか""" return self.find(x) == self.find(y) def count(self, x): """頂点xが属する木のサイズを返す""" return - self.root[self.find(x)] def members(self, x): """xが属する木の要素を列挙""" _root = self.find(x) return [i for i in range(self.N) if self.find(i) == _root] def roots(self): """森の根を列挙""" return [i for i, x in enumerate(self.root) if x < 0] def group_count(self): """連結成分の数""" return len(self.roots()) def all_group_members(self): """{ルート要素: [そのグループに含まれる要素のリスト], ...}の辞書を返す""" return {r: self.members(r) for r in self.roots()} import sys input = sys.stdin.readline n, q = list(map(int, input().split())) uf = UnionFind(n) res = [] for i in range(q): t, u, v = list(map(int, input().split())) if t: res.append(int(uf.same(u, v))) else: uf.union(u, v) print(("\n".join(map(str, res))))
78
75
1,925
1,884
import typing class DSU: """ Implement (union by size) + (path compression) Reference: Zvi Galil and Giuseppe F. Italiano, Data structures and algorithms for disjoint set union problems """ def __init__(self, n: int = 0): self._n = n self.parent_or_size = [-1] * n def merge(self, a: int, b: int) -> int: assert 0 <= a < self._n assert 0 <= b < self._n x = self.leader(a) y = self.leader(b) if x == y: return x if -self.parent_or_size[x] < -self.parent_or_size[y]: x, y = y, x self.parent_or_size[x] += self.parent_or_size[y] self.parent_or_size[y] = x return x def same(self, a: int, b: int) -> bool: assert 0 <= a < self._n assert 0 <= b < self._n return self.leader(a) == self.leader(b) def leader(self, a: int) -> int: assert 0 <= a < self._n r = a while self.parent_or_size[r] >= 0: r = self.parent_or_size[r] while self.parent_or_size[a] >= 0: self.parent_or_size[a], a = r, self.parent_or_size[a] return r def size(self, a: int) -> int: assert 0 <= a < self._n return -self.parent_or_size[self.leader(a)] def groups(self) -> typing.List[typing.List[int]]: leader_buf = [self.leader(i) for i in range(self._n)] result = [[] for _ in range(self._n)] for i in range(self._n): result[leader_buf[i]].append(i) return list([r for r in result if r]) import sys input = sys.stdin.readline n, q = list(map(int, input().split())) uf = DSU(n) res = [] for i in range(q): t, u, v = list(map(int, input().split())) if t: res.append(int(uf.same(u, v))) else: uf.merge(u, v) print(("\n".join(map(str, res))))
class UnionFind: __slots__ = ["N", "root"] def __init__(self, N): """ N:要素数 root:各要素の親要素の番号を格納するリスト. ただし, root[x] < 0 ならその頂点が根で-root[x]が木の要素数. """ self.N = N self.root = [-1] * N def __repr__(self): return "\n".join("{}: {}".format(r, self.members(r)) for r in self.roots()) def find(self, x): """頂点xの根を見つける""" r = x while self.root[r] >= 0: r = self.root[r] while self.root[x] >= 0: self.root[x], x = r, self.root[x] return r def union(self, x, y): """x, yが属する木をunion""" x = self.find(x) y = self.find(y) if x == y: return elif self.root[y] < self.root[x]: x, y = y, x self.root[x] += self.root[y] self.root[y] = x def same(self, x, y): """xとyが同じグループに属するかどうか""" return self.find(x) == self.find(y) def count(self, x): """頂点xが属する木のサイズを返す""" return -self.root[self.find(x)] def members(self, x): """xが属する木の要素を列挙""" _root = self.find(x) return [i for i in range(self.N) if self.find(i) == _root] def roots(self): """森の根を列挙""" return [i for i, x in enumerate(self.root) if x < 0] def group_count(self): """連結成分の数""" return len(self.roots()) def all_group_members(self): """{ルート要素: [そのグループに含まれる要素のリスト], ...}の辞書を返す""" return {r: self.members(r) for r in self.roots()} import sys input = sys.stdin.readline n, q = list(map(int, input().split())) uf = UnionFind(n) res = [] for i in range(q): t, u, v = list(map(int, input().split())) if t: res.append(int(uf.same(u, v))) else: uf.union(u, v) print(("\n".join(map(str, res))))
false
3.846154
[ "-import typing", "+class UnionFind:", "+ __slots__ = [\"N\", \"root\"]", "+ def __init__(self, N):", "+ \"\"\"", "+ N:要素数", "+ root:各要素の親要素の番号を格納するリスト.", "+ ただし, root[x] < 0 ならその頂点が根で-root[x]が木の要素数.", "+ \"\"\"", "+ self.N = N", "+ self.root = [-1] * N", "-class DSU:", "- \"\"\"", "- Implement (union by size) + (path compression)", "- Reference:", "- Zvi Galil and Giuseppe F. Italiano,", "- Data structures and algorithms for disjoint set union problems", "- \"\"\"", "+ def __repr__(self):", "+ return \"\\n\".join(\"{}: {}\".format(r, self.members(r)) for r in self.roots())", "- def __init__(self, n: int = 0):", "- self._n = n", "- self.parent_or_size = [-1] * n", "-", "- def merge(self, a: int, b: int) -> int:", "- assert 0 <= a < self._n", "- assert 0 <= b < self._n", "- x = self.leader(a)", "- y = self.leader(b)", "- if x == y:", "- return x", "- if -self.parent_or_size[x] < -self.parent_or_size[y]:", "- x, y = y, x", "- self.parent_or_size[x] += self.parent_or_size[y]", "- self.parent_or_size[y] = x", "- return x", "-", "- def same(self, a: int, b: int) -> bool:", "- assert 0 <= a < self._n", "- assert 0 <= b < self._n", "- return self.leader(a) == self.leader(b)", "-", "- def leader(self, a: int) -> int:", "- assert 0 <= a < self._n", "- r = a", "- while self.parent_or_size[r] >= 0:", "- r = self.parent_or_size[r]", "- while self.parent_or_size[a] >= 0:", "- self.parent_or_size[a], a = r, self.parent_or_size[a]", "+ def find(self, x):", "+ \"\"\"頂点xの根を見つける\"\"\"", "+ r = x", "+ while self.root[r] >= 0:", "+ r = self.root[r]", "+ while self.root[x] >= 0:", "+ self.root[x], x = r, self.root[x]", "- def size(self, a: int) -> int:", "- assert 0 <= a < self._n", "- return -self.parent_or_size[self.leader(a)]", "+ def union(self, x, y):", "+ \"\"\"x, yが属する木をunion\"\"\"", "+ x = self.find(x)", "+ y = self.find(y)", "+ if x == y:", "+ return", "+ elif self.root[y] < self.root[x]:", "+ x, y = y, x", "+ self.root[x] += self.root[y]", "+ self.root[y] = x", "- def groups(self) -> typing.List[typing.List[int]]:", "- leader_buf = [self.leader(i) for i in range(self._n)]", "- result = [[] for _ in range(self._n)]", "- for i in range(self._n):", "- result[leader_buf[i]].append(i)", "- return list([r for r in result if r])", "+ def same(self, x, y):", "+ \"\"\"xとyが同じグループに属するかどうか\"\"\"", "+ return self.find(x) == self.find(y)", "+", "+ def count(self, x):", "+ \"\"\"頂点xが属する木のサイズを返す\"\"\"", "+ return -self.root[self.find(x)]", "+", "+ def members(self, x):", "+ \"\"\"xが属する木の要素を列挙\"\"\"", "+ _root = self.find(x)", "+ return [i for i in range(self.N) if self.find(i) == _root]", "+", "+ def roots(self):", "+ \"\"\"森の根を列挙\"\"\"", "+ return [i for i, x in enumerate(self.root) if x < 0]", "+", "+ def group_count(self):", "+ \"\"\"連結成分の数\"\"\"", "+ return len(self.roots())", "+", "+ def all_group_members(self):", "+ \"\"\"{ルート要素: [そのグループに含まれる要素のリスト], ...}の辞書を返す\"\"\"", "+ return {r: self.members(r) for r in self.roots()}", "-uf = DSU(n)", "+uf = UnionFind(n)", "- uf.merge(u, v)", "+ uf.union(u, v)" ]
false
0.04262
0.03666
1.162601
[ "s534122398", "s756621677" ]
u843318925
p03448
python
s567923415
s970602169
51
38
3,060
3,064
Accepted
Accepted
25.49
a, b, c, x = list(map(int, [eval(input()) for i in range(4)])) count = 0 for i in range(a + 1): for j in range(b + 1): for k in range(c + 1): if 500 * i + 100 * j + 50 * k == x: count += 1 print(count)
a, b, c, x = list(map(int, [eval(input()) for i in range(4)])) count = 0 for i in range(a + 1): if 500 * i == x: count += 1 break elif 500 * i > x: break else: for j in range(b + 1): if 500 * i + 100 * j == x: count += 1 break elif 500 * i + 100 * j > x: break else: for k in range(c + 1): if 500 * i + 100 * j + 50 * k == x: count += 1 break print(count)
8
21
236
575
a, b, c, x = list(map(int, [eval(input()) for i in range(4)])) count = 0 for i in range(a + 1): for j in range(b + 1): for k in range(c + 1): if 500 * i + 100 * j + 50 * k == x: count += 1 print(count)
a, b, c, x = list(map(int, [eval(input()) for i in range(4)])) count = 0 for i in range(a + 1): if 500 * i == x: count += 1 break elif 500 * i > x: break else: for j in range(b + 1): if 500 * i + 100 * j == x: count += 1 break elif 500 * i + 100 * j > x: break else: for k in range(c + 1): if 500 * i + 100 * j + 50 * k == x: count += 1 break print(count)
false
61.904762
[ "- for j in range(b + 1):", "- for k in range(c + 1):", "- if 500 * i + 100 * j + 50 * k == x:", "+ if 500 * i == x:", "+ count += 1", "+ break", "+ elif 500 * i > x:", "+ break", "+ else:", "+ for j in range(b + 1):", "+ if 500 * i + 100 * j == x:", "+ break", "+ elif 500 * i + 100 * j > x:", "+ break", "+ else:", "+ for k in range(c + 1):", "+ if 500 * i + 100 * j + 50 * k == x:", "+ count += 1", "+ break" ]
false
0.076661
0.050824
1.508375
[ "s567923415", "s970602169" ]
u533039576
p03355
python
s255566188
s708110851
36
33
3,064
5,084
Accepted
Accepted
8.33
s = str(eval(input())) n = int(eval(input())) cand = [str(s[0])] for i in range(len(s)): if len(cand) == n and s[i] > cand[-1]: continue for j in range(i, len(s)): tmp = s[i:j+1] #print(i,j, tmp, cand) if len(cand) == n and tmp > cand[-1]: break if tmp in cand: continue cand += [tmp] #cand = sorted(cand) cand.sort() if len(cand) > n: cand.pop() print((cand.pop()))
s = eval(input()) k = int(eval(input())) substr = [] for n in range(1, k+1): for i in range(len(s)-n+1): substr.append(s[i:i+n]) substr = list(set(substr)) substr.sort() print((substr[k-1]))
22
11
493
201
s = str(eval(input())) n = int(eval(input())) cand = [str(s[0])] for i in range(len(s)): if len(cand) == n and s[i] > cand[-1]: continue for j in range(i, len(s)): tmp = s[i : j + 1] # print(i,j, tmp, cand) if len(cand) == n and tmp > cand[-1]: break if tmp in cand: continue cand += [tmp] # cand = sorted(cand) cand.sort() if len(cand) > n: cand.pop() print((cand.pop()))
s = eval(input()) k = int(eval(input())) substr = [] for n in range(1, k + 1): for i in range(len(s) - n + 1): substr.append(s[i : i + n]) substr = list(set(substr)) substr.sort() print((substr[k - 1]))
false
50
[ "-s = str(eval(input()))", "-n = int(eval(input()))", "-cand = [str(s[0])]", "-for i in range(len(s)):", "- if len(cand) == n and s[i] > cand[-1]:", "- continue", "- for j in range(i, len(s)):", "- tmp = s[i : j + 1]", "- # print(i,j, tmp, cand)", "- if len(cand) == n and tmp > cand[-1]:", "- break", "- if tmp in cand:", "- continue", "- cand += [tmp]", "- # cand = sorted(cand)", "- cand.sort()", "- if len(cand) > n:", "- cand.pop()", "-print((cand.pop()))", "+s = eval(input())", "+k = int(eval(input()))", "+substr = []", "+for n in range(1, k + 1):", "+ for i in range(len(s) - n + 1):", "+ substr.append(s[i : i + n])", "+substr = list(set(substr))", "+substr.sort()", "+print((substr[k - 1]))" ]
false
0.080479
0.044713
1.799914
[ "s255566188", "s708110851" ]
u401452016
p02683
python
s354836822
s338884224
251
199
27,804
27,280
Accepted
Accepted
20.72
#167C def main(): import itertools as ite import sys, numpy as np N,M,X = list(map(int, sys.stdin.readline().split())) CA = [np.array(list(map(int, sys.stdin.readline().split()))) for _ in range(N)] bit = np.array(list(ite.product([0,1], repeat=N))) #式の展開 #print(CA) #print(bit) ans = -1 for row in bit: result = np.array([0 for _ in range(M+1)]) #print(ans) for idx, num in enumerate(row): #print(CA[idx]*num) result += CA[idx]*num if np.all(result[1:]>=X): #print(result[0]) if ans==-1 or ans >result[0]: ans = result[0] print(ans) if __name__=='__main__': main()
#167C bit探索 def main(): import sys, numpy as np N,M,X =list(map(int, sys.stdin.readline().split())) CAB = [tuple(map(int, sys.stdin.readline().split())) for _ in range(N)] #bit探索 ans = -1 for i in range(2**N): result = np.array([0 for _ in range(M+1)]) for j in range(N): #桁(右始まり) if ((i>>j) &1) ==1: result +=np.array(CAB[N-j-1]) if np.all(result[1:]>=X): if ans==-1 or ans > result[0]: ans = result[0] print(ans) if __name__=='__main__': main()
27
22
750
589
# 167C def main(): import itertools as ite import sys, numpy as np N, M, X = list(map(int, sys.stdin.readline().split())) CA = [np.array(list(map(int, sys.stdin.readline().split()))) for _ in range(N)] bit = np.array(list(ite.product([0, 1], repeat=N))) # 式の展開 # print(CA) # print(bit) ans = -1 for row in bit: result = np.array([0 for _ in range(M + 1)]) # print(ans) for idx, num in enumerate(row): # print(CA[idx]*num) result += CA[idx] * num if np.all(result[1:] >= X): # print(result[0]) if ans == -1 or ans > result[0]: ans = result[0] print(ans) if __name__ == "__main__": main()
# 167C bit探索 def main(): import sys, numpy as np N, M, X = list(map(int, sys.stdin.readline().split())) CAB = [tuple(map(int, sys.stdin.readline().split())) for _ in range(N)] # bit探索 ans = -1 for i in range(2**N): result = np.array([0 for _ in range(M + 1)]) for j in range(N): # 桁(右始まり) if ((i >> j) & 1) == 1: result += np.array(CAB[N - j - 1]) if np.all(result[1:] >= X): if ans == -1 or ans > result[0]: ans = result[0] print(ans) if __name__ == "__main__": main()
false
18.518519
[ "-# 167C", "+# 167C bit探索", "- import itertools as ite", "- CA = [np.array(list(map(int, sys.stdin.readline().split()))) for _ in range(N)]", "- bit = np.array(list(ite.product([0, 1], repeat=N))) # 式の展開", "- # print(CA)", "- # print(bit)", "+ CAB = [tuple(map(int, sys.stdin.readline().split())) for _ in range(N)]", "+ # bit探索", "- for row in bit:", "+ for i in range(2**N):", "- # print(ans)", "- for idx, num in enumerate(row):", "- # print(CA[idx]*num)", "- result += CA[idx] * num", "+ for j in range(N): # 桁(右始まり)", "+ if ((i >> j) & 1) == 1:", "+ result += np.array(CAB[N - j - 1])", "- # print(result[0])" ]
false
0.303121
0.305185
0.993236
[ "s354836822", "s338884224" ]
u543954314
p02617
python
s351172077
s661127280
189
167
9,096
9,212
Accepted
Accepted
11.64
import sys readline = sys.stdin.readline readall = sys.stdin.read ns = lambda: readline().rstrip() ni = lambda: int(readline().rstrip()) nm = lambda: map(int, readline().split()) nl = lambda: list(map(int, readline().split())) prn = lambda x: print(*x, sep='\n') def solve(): n = ni() ans = 0 for i in range(1, n+1): ans += i * (n - i + 1) for _ in range(n-1): u, v = nm() if u > v: u, v = v, u ans -= u * (n - v + 1) print(ans) return solve()
import sys readline = sys.stdin.readline readall = sys.stdin.read ns = lambda: readline().rstrip() ni = lambda: int(readline().rstrip()) nm = lambda: map(int, readline().split()) nl = lambda: list(map(int, readline().split())) prn = lambda x: print(*x, sep='\n') def solve(): n = ni() ans = n * (n + 1) ** 2 // 2 - n * (n + 1) * (2 * n + 1) // 6 for _ in range(n-1): u, v = nm() if u > v: u, v = v, u ans -= u * (n - v + 1) print(ans) return solve()
24
22
538
530
import sys readline = sys.stdin.readline readall = sys.stdin.read ns = lambda: readline().rstrip() ni = lambda: int(readline().rstrip()) nm = lambda: map(int, readline().split()) nl = lambda: list(map(int, readline().split())) prn = lambda x: print(*x, sep="\n") def solve(): n = ni() ans = 0 for i in range(1, n + 1): ans += i * (n - i + 1) for _ in range(n - 1): u, v = nm() if u > v: u, v = v, u ans -= u * (n - v + 1) print(ans) return solve()
import sys readline = sys.stdin.readline readall = sys.stdin.read ns = lambda: readline().rstrip() ni = lambda: int(readline().rstrip()) nm = lambda: map(int, readline().split()) nl = lambda: list(map(int, readline().split())) prn = lambda x: print(*x, sep="\n") def solve(): n = ni() ans = n * (n + 1) ** 2 // 2 - n * (n + 1) * (2 * n + 1) // 6 for _ in range(n - 1): u, v = nm() if u > v: u, v = v, u ans -= u * (n - v + 1) print(ans) return solve()
false
8.333333
[ "- ans = 0", "- for i in range(1, n + 1):", "- ans += i * (n - i + 1)", "+ ans = n * (n + 1) ** 2 // 2 - n * (n + 1) * (2 * n + 1) // 6" ]
false
0.080363
0.043569
1.844512
[ "s351172077", "s661127280" ]
u764600134
p03645
python
s357430812
s447448178
595
281
18,936
18,936
Accepted
Accepted
52.77
to_middle = set() # 島1から渡ることのできる島 from_middle = set() # 島Nへ渡ることのできる島 N, M = list(map(int, (input().split()))) for _ in range(M): f, t = list(map(int, (input().split()))) if f == 1: to_middle.add(t) elif t == N: from_middle.add(f) if to_middle & from_middle: print('POSSIBLE') else: print('IMPOSSIBLE')
from sys import stdin input = stdin.readline to_middle = set() # 島1から渡ることのできる島 from_middle = set() # 島Nへ渡ることのできる島 N, M = list(map(int, (input().split()))) for _ in range(M): f, t = list(map(int, (input().split()))) if f == 1: to_middle.add(t) elif t == N: from_middle.add(f) if to_middle & from_middle: print('POSSIBLE') else: print('IMPOSSIBLE')
14
17
360
409
to_middle = set() # 島1から渡ることのできる島 from_middle = set() # 島Nへ渡ることのできる島 N, M = list(map(int, (input().split()))) for _ in range(M): f, t = list(map(int, (input().split()))) if f == 1: to_middle.add(t) elif t == N: from_middle.add(f) if to_middle & from_middle: print("POSSIBLE") else: print("IMPOSSIBLE")
from sys import stdin input = stdin.readline to_middle = set() # 島1から渡ることのできる島 from_middle = set() # 島Nへ渡ることのできる島 N, M = list(map(int, (input().split()))) for _ in range(M): f, t = list(map(int, (input().split()))) if f == 1: to_middle.add(t) elif t == N: from_middle.add(f) if to_middle & from_middle: print("POSSIBLE") else: print("IMPOSSIBLE")
false
17.647059
[ "+from sys import stdin", "+", "+input = stdin.readline" ]
false
0.087703
0.24097
0.363957
[ "s357430812", "s447448178" ]
u248364740
p03036
python
s372668197
s251090914
31
26
9,032
9,152
Accepted
Accepted
16.13
#!/usr/bin/env python3 # -*- coding: utf-8 -*- r, D, x = list(map(int, input().split())) for _ in range(10): x = r * x - D print(x)
r, d, x = list(map(int, input().strip().split())) for i in range(10): x = r * x - d print(x)
8
6
143
102
#!/usr/bin/env python3 # -*- coding: utf-8 -*- r, D, x = list(map(int, input().split())) for _ in range(10): x = r * x - D print(x)
r, d, x = list(map(int, input().strip().split())) for i in range(10): x = r * x - d print(x)
false
25
[ "-#!/usr/bin/env python3", "-# -*- coding: utf-8 -*-", "-r, D, x = list(map(int, input().split()))", "-for _ in range(10):", "- x = r * x - D", "+r, d, x = list(map(int, input().strip().split()))", "+for i in range(10):", "+ x = r * x - d" ]
false
0.036565
0.147559
0.247802
[ "s372668197", "s251090914" ]
u606045429
p03252
python
s571033158
s640913693
129
119
3,632
3,632
Accepted
Accepted
7.75
S = eval(input()) T = eval(input()) tdic = dict() sdic = dict() for i in range(len(S)): if T[i] in tdic: if tdic[T[i]] != S[i]: print("No") break else: tdic[T[i]] = S[i] if S[i] in sdic: if sdic[S[i]] != T[i]: print("No") break else: sdic[S[i]] = T[i] else: print("Yes")
S, T = [eval(input()) for _ in range(2)] smemo, tmemo = {}, {} for si, ti in zip(S, T): if si in smemo and smemo[si] != ti or ti in tmemo and tmemo[ti] != si: print("No") quit() smemo[si], tmemo[ti] = ti, si print("Yes")
21
8
380
246
S = eval(input()) T = eval(input()) tdic = dict() sdic = dict() for i in range(len(S)): if T[i] in tdic: if tdic[T[i]] != S[i]: print("No") break else: tdic[T[i]] = S[i] if S[i] in sdic: if sdic[S[i]] != T[i]: print("No") break else: sdic[S[i]] = T[i] else: print("Yes")
S, T = [eval(input()) for _ in range(2)] smemo, tmemo = {}, {} for si, ti in zip(S, T): if si in smemo and smemo[si] != ti or ti in tmemo and tmemo[ti] != si: print("No") quit() smemo[si], tmemo[ti] = ti, si print("Yes")
false
61.904762
[ "-S = eval(input())", "-T = eval(input())", "-tdic = dict()", "-sdic = dict()", "-for i in range(len(S)):", "- if T[i] in tdic:", "- if tdic[T[i]] != S[i]:", "- print(\"No\")", "- break", "- else:", "- tdic[T[i]] = S[i]", "- if S[i] in sdic:", "- if sdic[S[i]] != T[i]:", "- print(\"No\")", "- break", "- else:", "- sdic[S[i]] = T[i]", "-else:", "- print(\"Yes\")", "+S, T = [eval(input()) for _ in range(2)]", "+smemo, tmemo = {}, {}", "+for si, ti in zip(S, T):", "+ if si in smemo and smemo[si] != ti or ti in tmemo and tmemo[ti] != si:", "+ print(\"No\")", "+ quit()", "+ smemo[si], tmemo[ti] = ti, si", "+print(\"Yes\")" ]
false
0.03461
0.03688
0.93843
[ "s571033158", "s640913693" ]
u054412614
p03241
python
s534258930
s088340648
566
36
9,256
9,120
Accepted
Accepted
93.64
import copy def cd_generator(num): ans=[] for i in range(1,10000000): if num%i==0: ans.append(i) temp=copy.deepcopy(ans) temp.reverse() for ele in temp: ans.append(num//ele) return ans def main(): n,m=list(map(int,input().split())) array=cd_generator(m) ans=0 for ele in array: if m//ele>=n: ans=max(ans,ele) print(ans) main()
def make_divisors(n): lower_divisors,upper_divisors=[],[] i=1 while i*i<=n: if n%i==0: lower_divisors.append(i) if i!=n//i: upper_divisors.append(n//i) i+=1 return lower_divisors+upper_divisors[::-1] n,m=list(map(int,input().split())) array=make_divisors(m) array.reverse() for ele in array: if m//ele>=n: print(ele) exit()
20
17
431
426
import copy def cd_generator(num): ans = [] for i in range(1, 10000000): if num % i == 0: ans.append(i) temp = copy.deepcopy(ans) temp.reverse() for ele in temp: ans.append(num // ele) return ans def main(): n, m = list(map(int, input().split())) array = cd_generator(m) ans = 0 for ele in array: if m // ele >= n: ans = max(ans, ele) print(ans) main()
def make_divisors(n): lower_divisors, upper_divisors = [], [] i = 1 while i * i <= n: if n % i == 0: lower_divisors.append(i) if i != n // i: upper_divisors.append(n // i) i += 1 return lower_divisors + upper_divisors[::-1] n, m = list(map(int, input().split())) array = make_divisors(m) array.reverse() for ele in array: if m // ele >= n: print(ele) exit()
false
15
[ "-import copy", "+def make_divisors(n):", "+ lower_divisors, upper_divisors = [], []", "+ i = 1", "+ while i * i <= n:", "+ if n % i == 0:", "+ lower_divisors.append(i)", "+ if i != n // i:", "+ upper_divisors.append(n // i)", "+ i += 1", "+ return lower_divisors + upper_divisors[::-1]", "-def cd_generator(num):", "- ans = []", "- for i in range(1, 10000000):", "- if num % i == 0:", "- ans.append(i)", "- temp = copy.deepcopy(ans)", "- temp.reverse()", "- for ele in temp:", "- ans.append(num // ele)", "- return ans", "-", "-", "-def main():", "- n, m = list(map(int, input().split()))", "- array = cd_generator(m)", "- ans = 0", "- for ele in array:", "- if m // ele >= n:", "- ans = max(ans, ele)", "- print(ans)", "-", "-", "-main()", "+n, m = list(map(int, input().split()))", "+array = make_divisors(m)", "+array.reverse()", "+for ele in array:", "+ if m // ele >= n:", "+ print(ele)", "+ exit()" ]
false
3.278351
0.03945
83.101414
[ "s534258930", "s088340648" ]
u827885761
p03209
python
s243595239
s356139077
20
17
3,064
3,064
Accepted
Accepted
15
n, x = list(map(int, input().split())) A = [1] * (n + 1) P = [1] * (n + 1) for i in range(1, n + 1): A[i] = A[i - 1] * 2 + 3 P[i] = P[i - 1] * 2 + 1 def pate(m, y): if m == 0: return 1 else: c = 0 if y >= 1: y -= 1 if y >= 1: if y >= A[m - 1]: y -= A[m - 1] c += P[m - 1] else: c += pate(m - 1, y) y = 0 if y >= 1: y -= 1 c += 1 if y >= 1: if y >= A[m - 1]: y -= A[m - 1] c += P[m - 1] else: c += pate(m - 1, y) y = 0 if y >= 1: y -= 1 return c print((pate(n, x)))
n, x = list(map(int, input().split())) A = [1] * (n + 1) P = [1] * (n + 1) for i in range(1, n + 1): A[i] = A[i - 1] * 2 + 3 P[i] = P[i - 1] * 2 + 1 c = 0 for i in list(range(n+1))[::-1]: if i == 0: c += 1 elif x == 1: break elif x <= A[i - 1] + 1: x -= 1 elif x == A[i - 1] + 2: c += P[i - 1] + 1 break elif x <= A[i] - 1: c += P[i - 1] + 1 x -= A[i - 1] + 2 elif x == A[i]: c += P[i] break print(c)
45
32
816
538
n, x = list(map(int, input().split())) A = [1] * (n + 1) P = [1] * (n + 1) for i in range(1, n + 1): A[i] = A[i - 1] * 2 + 3 P[i] = P[i - 1] * 2 + 1 def pate(m, y): if m == 0: return 1 else: c = 0 if y >= 1: y -= 1 if y >= 1: if y >= A[m - 1]: y -= A[m - 1] c += P[m - 1] else: c += pate(m - 1, y) y = 0 if y >= 1: y -= 1 c += 1 if y >= 1: if y >= A[m - 1]: y -= A[m - 1] c += P[m - 1] else: c += pate(m - 1, y) y = 0 if y >= 1: y -= 1 return c print((pate(n, x)))
n, x = list(map(int, input().split())) A = [1] * (n + 1) P = [1] * (n + 1) for i in range(1, n + 1): A[i] = A[i - 1] * 2 + 3 P[i] = P[i - 1] * 2 + 1 c = 0 for i in list(range(n + 1))[::-1]: if i == 0: c += 1 elif x == 1: break elif x <= A[i - 1] + 1: x -= 1 elif x == A[i - 1] + 2: c += P[i - 1] + 1 break elif x <= A[i] - 1: c += P[i - 1] + 1 x -= A[i - 1] + 2 elif x == A[i]: c += P[i] break print(c)
false
28.888889
[ "-", "-", "-def pate(m, y):", "- if m == 0:", "- return 1", "- else:", "- c = 0", "- if y >= 1:", "- y -= 1", "- if y >= 1:", "- if y >= A[m - 1]:", "- y -= A[m - 1]", "- c += P[m - 1]", "- else:", "- c += pate(m - 1, y)", "- y = 0", "- if y >= 1:", "- y -= 1", "- c += 1", "- if y >= 1:", "- if y >= A[m - 1]:", "- y -= A[m - 1]", "- c += P[m - 1]", "- else:", "- c += pate(m - 1, y)", "- y = 0", "- if y >= 1:", "- y -= 1", "- return c", "-", "-", "-print((pate(n, x)))", "+c = 0", "+for i in list(range(n + 1))[::-1]:", "+ if i == 0:", "+ c += 1", "+ elif x == 1:", "+ break", "+ elif x <= A[i - 1] + 1:", "+ x -= 1", "+ elif x == A[i - 1] + 2:", "+ c += P[i - 1] + 1", "+ break", "+ elif x <= A[i] - 1:", "+ c += P[i - 1] + 1", "+ x -= A[i - 1] + 2", "+ elif x == A[i]:", "+ c += P[i]", "+ break", "+print(c)" ]
false
0.06173
0.060877
1.014012
[ "s243595239", "s356139077" ]
u191874006
p02699
python
s215093903
s991069998
108
67
65,248
65,548
Accepted
Accepted
37.96
#!/usr/bin/env python3 import sys import math from bisect import bisect_right as br from bisect import bisect_left as bl sys.setrecursionlimit(2147483647) from heapq import heappush, heappop,heappushpop from collections import defaultdict from itertools import accumulate from collections import Counter from collections import deque from operator import itemgetter from itertools import permutations mod = 10**9 + 7 inf = float('inf') def I(): return int(sys.stdin.readline()) def LI(): return list(map(int,sys.stdin.readline().split())) s,w = LI() if s <= w: print('unsafe') else: print('safe')
#!/usr/bin/env python3 #A import sys import math from bisect import bisect_right as br from bisect import bisect_left as bl sys.setrecursionlimit(2147483647) from heapq import heappush, heappop,heappushpop from collections import defaultdict from itertools import accumulate from collections import Counter from collections import deque from operator import itemgetter from itertools import permutations mod = 10**9 + 7 inf = float('inf') def I(): return int(sys.stdin.readline()) def LI(): return list(map(int,sys.stdin.readline().split())) s,w = LI() if w >= s: print('unsafe') else: print('safe')
24
25
629
633
#!/usr/bin/env python3 import sys import math from bisect import bisect_right as br from bisect import bisect_left as bl sys.setrecursionlimit(2147483647) from heapq import heappush, heappop, heappushpop from collections import defaultdict from itertools import accumulate from collections import Counter from collections import deque from operator import itemgetter from itertools import permutations mod = 10**9 + 7 inf = float("inf") def I(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) s, w = LI() if s <= w: print("unsafe") else: print("safe")
#!/usr/bin/env python3 # A import sys import math from bisect import bisect_right as br from bisect import bisect_left as bl sys.setrecursionlimit(2147483647) from heapq import heappush, heappop, heappushpop from collections import defaultdict from itertools import accumulate from collections import Counter from collections import deque from operator import itemgetter from itertools import permutations mod = 10**9 + 7 inf = float("inf") def I(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) s, w = LI() if w >= s: print("unsafe") else: print("safe")
false
4
[ "+# A", "-if s <= w:", "+if w >= s:" ]
false
0.045871
0.046131
0.994371
[ "s215093903", "s991069998" ]
u627600101
p02616
python
s016980815
s749521679
257
236
31,868
31,744
Accepted
Accepted
8.17
N, K = list(map(int, input().split())) A = list(map(int, input().split())) mod = 10 ** 9 + 7 plus = [] zero = [] minus = [] ans = 1 for k in range(N): if A[k] > 0: plus.append(A[k]) elif A[k] < 0: minus.append(-1 * A[k]) else: zero.append(A[k]) plus.sort(reverse = True) minus.sort(reverse = True) lp = len(plus) lm = len(minus) lz = len(zero) if lz + K > N: print((0)) exit() elif lp == 0: if K % 2 == 1: if lz > 0: print((0)) exit() else: for k in range(K): ans = ans * (-1) * minus[- k - 1] % mod print(ans) exit() else: for k in range(K): ans = ans * (-1) * minus[k] % mod print(ans) exit() elif lm == 0: for k in range(K): ans = ans * plus[k] % mod print(ans) exit() p = 0 m = 0 for k in range(K): if plus[p] >= minus[m]: p += 1 if p == lp: m = K - p break else: m += 1 if m == lm: p = K - m break def main(mp, mm, plus, minus): mod = 10 ** 9 + 7 ans = 1 for k in range(mp): ans = ans * plus[k] % mod for k in range(mm): ans = ans * (-1) * minus[k] % mod print(ans) exit() if m % 2 == 0: main(p, m, plus, minus) else: if p == lp: if m != lm: main(p - 1, m + 1, plus, minus) else: if lz > 0: print((0)) exit() else: main(p, m, plus, minus) elif m == lm: main(p + 1, m - 1, plus, minus) elif p == 0: main(p + 1, m - 1, plus, minus) else: if plus[p] * plus[p - 1] > minus[m - 1] * minus[m]: main(p + 1, m - 1, plus, minus) else: main(p - 1, m + 1, plus, minus)
N, K = list(map(int, input().split())) A = list(map(int, input().split())) mod = 10 ** 9 + 7 plus = [] lz = 0 minus = [] ans = 1 for k in range(N): if A[k] > 0: plus.append(A[k]) elif A[k] < 0: minus.append(A[k]) else: lz += 1 plus.sort(reverse = True) minus.sort() lp = len(plus) lm = len(minus) def main(mp, mm, plus, minus): mod = 10 ** 9 + 7 ans = 1 for k in range(mp): ans = ans * plus[k] % mod for k in range(mm): ans = ans * minus[k] % mod print(ans) exit() if lz + K > N: print((0)) exit() elif lp == 0: if K % 2 == 1: if lz > 0: print((0)) exit() else: for k in range(K): ans = ans * minus[- k - 1] % mod print(ans) exit() else: main(0, K, plus, minus) elif lm == 0: main(K, 0, plus, minus) p = 0 m = 0 for _ in range(K): if plus[p] >= -1 * minus[m]: p += 1 if p == lp: m = K - p break else: m += 1 if m == lm: p = K - m break if m % 2 == 0: main(p, m, plus, minus) else: if p == lp: if m != lm: main(p - 1, m + 1, plus, minus) else: if lz > 0: print((0)) exit() else: main(p, m, plus, minus) elif m == lm: main(p + 1, m - 1, plus, minus) elif p == 0: main(p + 1, m - 1, plus, minus) else: if plus[p] * plus[p - 1] > minus[m - 1] * minus[m]: main(p + 1, m - 1, plus, minus) else: main(p - 1, m + 1, plus, minus)
91
84
1,703
1,528
N, K = list(map(int, input().split())) A = list(map(int, input().split())) mod = 10**9 + 7 plus = [] zero = [] minus = [] ans = 1 for k in range(N): if A[k] > 0: plus.append(A[k]) elif A[k] < 0: minus.append(-1 * A[k]) else: zero.append(A[k]) plus.sort(reverse=True) minus.sort(reverse=True) lp = len(plus) lm = len(minus) lz = len(zero) if lz + K > N: print((0)) exit() elif lp == 0: if K % 2 == 1: if lz > 0: print((0)) exit() else: for k in range(K): ans = ans * (-1) * minus[-k - 1] % mod print(ans) exit() else: for k in range(K): ans = ans * (-1) * minus[k] % mod print(ans) exit() elif lm == 0: for k in range(K): ans = ans * plus[k] % mod print(ans) exit() p = 0 m = 0 for k in range(K): if plus[p] >= minus[m]: p += 1 if p == lp: m = K - p break else: m += 1 if m == lm: p = K - m break def main(mp, mm, plus, minus): mod = 10**9 + 7 ans = 1 for k in range(mp): ans = ans * plus[k] % mod for k in range(mm): ans = ans * (-1) * minus[k] % mod print(ans) exit() if m % 2 == 0: main(p, m, plus, minus) else: if p == lp: if m != lm: main(p - 1, m + 1, plus, minus) else: if lz > 0: print((0)) exit() else: main(p, m, plus, minus) elif m == lm: main(p + 1, m - 1, plus, minus) elif p == 0: main(p + 1, m - 1, plus, minus) else: if plus[p] * plus[p - 1] > minus[m - 1] * minus[m]: main(p + 1, m - 1, plus, minus) else: main(p - 1, m + 1, plus, minus)
N, K = list(map(int, input().split())) A = list(map(int, input().split())) mod = 10**9 + 7 plus = [] lz = 0 minus = [] ans = 1 for k in range(N): if A[k] > 0: plus.append(A[k]) elif A[k] < 0: minus.append(A[k]) else: lz += 1 plus.sort(reverse=True) minus.sort() lp = len(plus) lm = len(minus) def main(mp, mm, plus, minus): mod = 10**9 + 7 ans = 1 for k in range(mp): ans = ans * plus[k] % mod for k in range(mm): ans = ans * minus[k] % mod print(ans) exit() if lz + K > N: print((0)) exit() elif lp == 0: if K % 2 == 1: if lz > 0: print((0)) exit() else: for k in range(K): ans = ans * minus[-k - 1] % mod print(ans) exit() else: main(0, K, plus, minus) elif lm == 0: main(K, 0, plus, minus) p = 0 m = 0 for _ in range(K): if plus[p] >= -1 * minus[m]: p += 1 if p == lp: m = K - p break else: m += 1 if m == lm: p = K - m break if m % 2 == 0: main(p, m, plus, minus) else: if p == lp: if m != lm: main(p - 1, m + 1, plus, minus) else: if lz > 0: print((0)) exit() else: main(p, m, plus, minus) elif m == lm: main(p + 1, m - 1, plus, minus) elif p == 0: main(p + 1, m - 1, plus, minus) else: if plus[p] * plus[p - 1] > minus[m - 1] * minus[m]: main(p + 1, m - 1, plus, minus) else: main(p - 1, m + 1, plus, minus)
false
7.692308
[ "-zero = []", "+lz = 0", "- minus.append(-1 * A[k])", "+ minus.append(A[k])", "- zero.append(A[k])", "+ lz += 1", "-minus.sort(reverse=True)", "+minus.sort()", "-lz = len(zero)", "+", "+", "+def main(mp, mm, plus, minus):", "+ mod = 10**9 + 7", "+ ans = 1", "+ for k in range(mp):", "+ ans = ans * plus[k] % mod", "+ for k in range(mm):", "+ ans = ans * minus[k] % mod", "+ print(ans)", "+ exit()", "+", "+", "- ans = ans * (-1) * minus[-k - 1] % mod", "+ ans = ans * minus[-k - 1] % mod", "- for k in range(K):", "- ans = ans * (-1) * minus[k] % mod", "- print(ans)", "- exit()", "+ main(0, K, plus, minus)", "- for k in range(K):", "- ans = ans * plus[k] % mod", "- print(ans)", "- exit()", "+ main(K, 0, plus, minus)", "-for k in range(K):", "- if plus[p] >= minus[m]:", "+for _ in range(K):", "+ if plus[p] >= -1 * minus[m]:", "-", "-", "-def main(mp, mm, plus, minus):", "- mod = 10**9 + 7", "- ans = 1", "- for k in range(mp):", "- ans = ans * plus[k] % mod", "- for k in range(mm):", "- ans = ans * (-1) * minus[k] % mod", "- print(ans)", "- exit()", "-", "-" ]
false
0.039647
0.037379
1.060683
[ "s016980815", "s749521679" ]
u357335656
p02658
python
s265570900
s666276544
81
48
21,420
21,624
Accepted
Accepted
40.74
n = int(eval(input())) a = list(map(int,input().split())) a.sort() if a[0] == 0: print((0)) exit() a.sort(reverse=True) ans = 1 for i in range(n): ans *= a[i] if ans > 10 ** 18: ans = -1 break print(ans)
N = int(eval(input())) A = list(map(int,input(). split ())) if 0 in A: print((0)) exit() prod = 1 for a in A: prod *= a if prod > 1000000000000000000: print((-1)) exit() print(prod)
18
12
232
190
n = int(eval(input())) a = list(map(int, input().split())) a.sort() if a[0] == 0: print((0)) exit() a.sort(reverse=True) ans = 1 for i in range(n): ans *= a[i] if ans > 10**18: ans = -1 break print(ans)
N = int(eval(input())) A = list(map(int, input().split())) if 0 in A: print((0)) exit() prod = 1 for a in A: prod *= a if prod > 1000000000000000000: print((-1)) exit() print(prod)
false
33.333333
[ "-n = int(eval(input()))", "-a = list(map(int, input().split()))", "-a.sort()", "-if a[0] == 0:", "+N = int(eval(input()))", "+A = list(map(int, input().split()))", "+if 0 in A:", "-a.sort(reverse=True)", "-ans = 1", "-for i in range(n):", "- ans *= a[i]", "- if ans > 10**18:", "- ans = -1", "- break", "-print(ans)", "+prod = 1", "+for a in A:", "+ prod *= a", "+ if prod > 1000000000000000000:", "+ print((-1))", "+ exit()", "+print(prod)" ]
false
0.047014
0.046685
1.007047
[ "s265570900", "s666276544" ]
u156163787
p03634
python
s007224328
s871474860
1,890
1,616
90,140
86,176
Accepted
Accepted
14.5
from queue import Queue INF=float('inf') n=int(eval(input())) g=[[] for _ in range(n)] for _ in range(n-1): u,v,w=list(map(int,input().split())) g[u-1].append((v-1,w)) g[v-1].append((u-1,w)) q,k=list(map(int,input().split())) ds=[INF]*n ds[k-1]=0 que=Queue() que.put((k-1,0)) while not que.empty(): u,d=que.get() for v,w in g[u]: if ds[v]==INF: ds[v]=d+w que.put((v,d+w)) for _ in range(q): u,v=list(map(int,input().split())) print((ds[u-1]+ds[v-1]))
from collections import deque INF=float('inf') n=int(eval(input())) g=[[] for _ in range(n)] for _ in range(n-1): u,v,w=list(map(int,input().split())) g[u-1].append((v-1,w)) g[v-1].append((u-1,w)) q,k=list(map(int,input().split())) ds=[INF]*n ds[k-1]=0 que=deque() que.append((k-1,0)) while len(que): u,d=que.popleft() for v,w in g[u]: if ds[v]==INF: ds[v]=d+w que.append((v,d+w)) for _ in range(q): u,v=list(map(int,input().split())) print((ds[u-1]+ds[v-1]))
26
26
514
523
from queue import Queue INF = float("inf") n = int(eval(input())) g = [[] for _ in range(n)] for _ in range(n - 1): u, v, w = list(map(int, input().split())) g[u - 1].append((v - 1, w)) g[v - 1].append((u - 1, w)) q, k = list(map(int, input().split())) ds = [INF] * n ds[k - 1] = 0 que = Queue() que.put((k - 1, 0)) while not que.empty(): u, d = que.get() for v, w in g[u]: if ds[v] == INF: ds[v] = d + w que.put((v, d + w)) for _ in range(q): u, v = list(map(int, input().split())) print((ds[u - 1] + ds[v - 1]))
from collections import deque INF = float("inf") n = int(eval(input())) g = [[] for _ in range(n)] for _ in range(n - 1): u, v, w = list(map(int, input().split())) g[u - 1].append((v - 1, w)) g[v - 1].append((u - 1, w)) q, k = list(map(int, input().split())) ds = [INF] * n ds[k - 1] = 0 que = deque() que.append((k - 1, 0)) while len(que): u, d = que.popleft() for v, w in g[u]: if ds[v] == INF: ds[v] = d + w que.append((v, d + w)) for _ in range(q): u, v = list(map(int, input().split())) print((ds[u - 1] + ds[v - 1]))
false
0
[ "-from queue import Queue", "+from collections import deque", "-que = Queue()", "-que.put((k - 1, 0))", "-while not que.empty():", "- u, d = que.get()", "+que = deque()", "+que.append((k - 1, 0))", "+while len(que):", "+ u, d = que.popleft()", "- que.put((v, d + w))", "+ que.append((v, d + w))" ]
false
0.105134
0.096212
1.092728
[ "s007224328", "s871474860" ]
u638795007
p04021
python
s493848474
s957523364
288
136
55,388
10,572
Accepted
Accepted
52.78
def examC(): N = I(); A = [I() for _ in range(N)] AS = sorted(A) A0 = A[::2] d = defaultdict(bool) for i in AS[::2]: d[i] = True ans = 0 for i in A0: if not d[i]: ans +=1 print(ans) import sys,copy,bisect,itertools,heapq,math from heapq import heappop,heappush,heapify from collections import Counter,defaultdict,deque def I(): return int(sys.stdin.readline()) def LI(): return list(map(int,sys.stdin.readline().split())) def LSI(): return list(map(str,sys.stdin.readline().split())) def LS(): return sys.stdin.readline().split() def SI(): return sys.stdin.readline().strip() mod = 10**9 + 7 inf = float('inf') if __name__ == '__main__': examC()
def examA(): S = SI() if "W" in S and not "E" in S: print("No") elif "E" in S and not "W" in S: print("No") elif "N" in S and not "S" in S: print("No") elif "S" in S and not "N" in S: print("No") else: print("Yes") return def examB(): N = I() A = [I()for _ in range(N)] ans = 0 for i in range(N-1): ans += A[i]//2 if A[i]%2 and A[i+1]>=1: ans += 1 A[i+1] -= 1 ans += A[N-1]//2 print(ans) return def examC(): N = I() A = [I()for _ in range(N)] if N==1: print((0)) return odd = set() for i in range(N): if i&1==0: odd.add(A[i]) A.sort() ans = 0 for i in range((N+1)//2): if A[i*2] in odd: continue ans += 1 print(ans) return def examD(): N = I() S = [I()for _ in range(N)] ans = 0 print(ans) return def examE(): ans = 0 print(ans) return def examF(): ans = 0 print(ans) return import sys,bisect,itertools,heapq,math,random from copy import deepcopy from heapq import heappop,heappush,heapify from collections import Counter,defaultdict,deque def I(): return int(sys.stdin.readline()) def LI(): return list(map(int,sys.stdin.readline().split())) def LSI(): return list(map(str,sys.stdin.readline().split())) def LS(): return sys.stdin.readline().split() def SI(): return sys.stdin.readline().strip() global mod,mod2,inf,alphabet,_ep mod = 10**9 + 7 mod2 = 998244353 inf = 10**18 _ep = 10**(-12) alphabet = [chr(ord('a') + i) for i in range(26)] sys.setrecursionlimit(10**6) if __name__ == '__main__': examC() """ """
26
88
736
1,797
def examC(): N = I() A = [I() for _ in range(N)] AS = sorted(A) A0 = A[::2] d = defaultdict(bool) for i in AS[::2]: d[i] = True ans = 0 for i in A0: if not d[i]: ans += 1 print(ans) import sys, copy, bisect, itertools, heapq, math from heapq import heappop, heappush, heapify from collections import Counter, defaultdict, deque def I(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LSI(): return list(map(str, sys.stdin.readline().split())) def LS(): return sys.stdin.readline().split() def SI(): return sys.stdin.readline().strip() mod = 10**9 + 7 inf = float("inf") if __name__ == "__main__": examC()
def examA(): S = SI() if "W" in S and not "E" in S: print("No") elif "E" in S and not "W" in S: print("No") elif "N" in S and not "S" in S: print("No") elif "S" in S and not "N" in S: print("No") else: print("Yes") return def examB(): N = I() A = [I() for _ in range(N)] ans = 0 for i in range(N - 1): ans += A[i] // 2 if A[i] % 2 and A[i + 1] >= 1: ans += 1 A[i + 1] -= 1 ans += A[N - 1] // 2 print(ans) return def examC(): N = I() A = [I() for _ in range(N)] if N == 1: print((0)) return odd = set() for i in range(N): if i & 1 == 0: odd.add(A[i]) A.sort() ans = 0 for i in range((N + 1) // 2): if A[i * 2] in odd: continue ans += 1 print(ans) return def examD(): N = I() S = [I() for _ in range(N)] ans = 0 print(ans) return def examE(): ans = 0 print(ans) return def examF(): ans = 0 print(ans) return import sys, bisect, itertools, heapq, math, random from copy import deepcopy from heapq import heappop, heappush, heapify from collections import Counter, defaultdict, deque def I(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LSI(): return list(map(str, sys.stdin.readline().split())) def LS(): return sys.stdin.readline().split() def SI(): return sys.stdin.readline().strip() global mod, mod2, inf, alphabet, _ep mod = 10**9 + 7 mod2 = 998244353 inf = 10**18 _ep = 10 ** (-12) alphabet = [chr(ord("a") + i) for i in range(26)] sys.setrecursionlimit(10**6) if __name__ == "__main__": examC() """ """
false
70.454545
[ "+def examA():", "+ S = SI()", "+ if \"W\" in S and not \"E\" in S:", "+ print(\"No\")", "+ elif \"E\" in S and not \"W\" in S:", "+ print(\"No\")", "+ elif \"N\" in S and not \"S\" in S:", "+ print(\"No\")", "+ elif \"S\" in S and not \"N\" in S:", "+ print(\"No\")", "+ else:", "+ print(\"Yes\")", "+ return", "+", "+", "+def examB():", "+ N = I()", "+ A = [I() for _ in range(N)]", "+ ans = 0", "+ for i in range(N - 1):", "+ ans += A[i] // 2", "+ if A[i] % 2 and A[i + 1] >= 1:", "+ ans += 1", "+ A[i + 1] -= 1", "+ ans += A[N - 1] // 2", "+ print(ans)", "+ return", "+", "+", "- AS = sorted(A)", "- A0 = A[::2]", "- d = defaultdict(bool)", "- for i in AS[::2]:", "- d[i] = True", "+ if N == 1:", "+ print((0))", "+ return", "+ odd = set()", "+ for i in range(N):", "+ if i & 1 == 0:", "+ odd.add(A[i])", "+ A.sort()", "- for i in A0:", "- if not d[i]:", "- ans += 1", "+ for i in range((N + 1) // 2):", "+ if A[i * 2] in odd:", "+ continue", "+ ans += 1", "+ return", "-import sys, copy, bisect, itertools, heapq, math", "+def examD():", "+ N = I()", "+ S = [I() for _ in range(N)]", "+ ans = 0", "+ print(ans)", "+ return", "+", "+", "+def examE():", "+ ans = 0", "+ print(ans)", "+ return", "+", "+", "+def examF():", "+ ans = 0", "+ print(ans)", "+ return", "+", "+", "+import sys, bisect, itertools, heapq, math, random", "+from copy import deepcopy", "+global mod, mod2, inf, alphabet, _ep", "-inf = float(\"inf\")", "+mod2 = 998244353", "+inf = 10**18", "+_ep = 10 ** (-12)", "+alphabet = [chr(ord(\"a\") + i) for i in range(26)]", "+sys.setrecursionlimit(10**6)", "+\"\"\"", "+\"\"\"" ]
false
0.055645
0.036298
1.532996
[ "s493848474", "s957523364" ]
u996749146
p03252
python
s478563714
s367146675
90
41
3,632
4,144
Accepted
Accepted
54.44
def main(): s = eval(input()) t = eval(input()) dt = dict() ds = dict() for i in range(len(s)): if t[i] not in dt: dt[t[i]] = s[i] else: if dt[t[i]] != s[i]: print("No") return if s[i] not in ds: ds[s[i]] = t[i] else: if ds[s[i]] != t[i]: print("No") return print("Yes") if __name__ == "__main__": main()
#提出3250967より from collections import Counter S = eval(input()) T = eval(input()) s = Counter(S) t = Counter(T) if sorted(s.values()) == sorted(t.values()): print("Yes") else: print("No")
25
14
492
196
def main(): s = eval(input()) t = eval(input()) dt = dict() ds = dict() for i in range(len(s)): if t[i] not in dt: dt[t[i]] = s[i] else: if dt[t[i]] != s[i]: print("No") return if s[i] not in ds: ds[s[i]] = t[i] else: if ds[s[i]] != t[i]: print("No") return print("Yes") if __name__ == "__main__": main()
# 提出3250967より from collections import Counter S = eval(input()) T = eval(input()) s = Counter(S) t = Counter(T) if sorted(s.values()) == sorted(t.values()): print("Yes") else: print("No")
false
44
[ "-def main():", "- s = eval(input())", "- t = eval(input())", "- dt = dict()", "- ds = dict()", "- for i in range(len(s)):", "- if t[i] not in dt:", "- dt[t[i]] = s[i]", "- else:", "- if dt[t[i]] != s[i]:", "- print(\"No\")", "- return", "- if s[i] not in ds:", "- ds[s[i]] = t[i]", "- else:", "- if ds[s[i]] != t[i]:", "- print(\"No\")", "- return", "+# 提出3250967より", "+from collections import Counter", "+", "+S = eval(input())", "+T = eval(input())", "+s = Counter(S)", "+t = Counter(T)", "+if sorted(s.values()) == sorted(t.values()):", "-", "-", "-if __name__ == \"__main__\":", "- main()", "+else:", "+ print(\"No\")" ]
false
0.048806
0.048406
1.008266
[ "s478563714", "s367146675" ]
u073852194
p03722
python
s921016425
s124948367
405
335
48,216
46,812
Accepted
Accepted
17.28
INF = 10**18 N,M = list(map(int,input().split())) edge = [list(map(int,input().split())) for i in range(M)] graph = [[] for _ in range(N)] for e in edge: graph[e[0]-1].append([e[1]-1,-e[2]]) dist = [INF for _ in range(N)] dist[0] = 0 for _ in range(N): flag = False for node,g in enumerate(graph): for adj,cost in g: if dist[node] != INF and dist[node]+cost < dist[adj]: dist[adj] = dist[node]+cost if _==N-1: update = adj flag = True if not flag: print((-dist[N-1])) break else: visited = [0 for _ in range(N)] visited[update] = 1 stack = [update] while stack: node = stack.pop() for adj,c in graph[node]: if not visited[adj]: visited[adj] = 1 stack.append(adj) if visited[N-1]: print('inf') else: print((-dist[N-1]))
class Graph(): #directed def __init__(self, n, edge, indexed=1): self.n = n self.graph = [[] for _ in range(n)] self.deg = [0 for _ in range(n)] for e in edge: self.graph[e[0] - indexed].append((e[1] - indexed, e[2])) self.deg[e[1] - indexed] += 1 def dijkstra(self, s, INF=10**18, restore_to=None): dist = [INF for _ in range(self.n)] dist[s] = 0 heap = [(0, s)] while heap: cost, node = heappop(heap) if dist[node] < cost: continue for adj, adjcost in self.graph[node]: if dist[node] + adjcost < dist[adj]: dist[adj] = dist[node] + adjcost heappush(heap, (dist[adj], adj)) if restore_to is not None: g = restore_to if dist[g] == INF: return dist, False path = [g] node = g while node != s: node = prev[node] path.append(node) return dist, path[::-1] return dist def bellman_ford(self, s, t=None, INF=10**18): dist = [INF for _ in range(self.n)] dist[s] = 0 update = True for i in range(self.n): update = False for node, g in enumerate(self.graph): for adj, adjcost in g: if dist[node] != INF and dist[node] + adjcost < dist[adj]: dist[adj] = dist[node] + adjcost update = True if not update: return dist[t] if t is not None else dist if t is None: return negative_cycle = [0 for _ in range(self.n)] for i in range(self.n): for node, g in enumerate(self.graph): for adj, adjcost in g: if dist[node] != INF and dist[node] + adjcost < dist[adj]: dist[adj] = dist[node] + adjcost negative_cycle[adj] = True if not negative_cycle[t]: return dist[t] import sys input = sys.stdin.readline N, M = list(map(int, input().split())) E = [] for _ in range(M): a, b, c = list(map(int, input().split())) E.append((a, b, -c)) g = Graph(N, E) bf = g.bellman_ford(0, N - 1) print((-bf if bf is not None else 'inf'))
40
72
985
2,436
INF = 10**18 N, M = list(map(int, input().split())) edge = [list(map(int, input().split())) for i in range(M)] graph = [[] for _ in range(N)] for e in edge: graph[e[0] - 1].append([e[1] - 1, -e[2]]) dist = [INF for _ in range(N)] dist[0] = 0 for _ in range(N): flag = False for node, g in enumerate(graph): for adj, cost in g: if dist[node] != INF and dist[node] + cost < dist[adj]: dist[adj] = dist[node] + cost if _ == N - 1: update = adj flag = True if not flag: print((-dist[N - 1])) break else: visited = [0 for _ in range(N)] visited[update] = 1 stack = [update] while stack: node = stack.pop() for adj, c in graph[node]: if not visited[adj]: visited[adj] = 1 stack.append(adj) if visited[N - 1]: print("inf") else: print((-dist[N - 1]))
class Graph: # directed def __init__(self, n, edge, indexed=1): self.n = n self.graph = [[] for _ in range(n)] self.deg = [0 for _ in range(n)] for e in edge: self.graph[e[0] - indexed].append((e[1] - indexed, e[2])) self.deg[e[1] - indexed] += 1 def dijkstra(self, s, INF=10**18, restore_to=None): dist = [INF for _ in range(self.n)] dist[s] = 0 heap = [(0, s)] while heap: cost, node = heappop(heap) if dist[node] < cost: continue for adj, adjcost in self.graph[node]: if dist[node] + adjcost < dist[adj]: dist[adj] = dist[node] + adjcost heappush(heap, (dist[adj], adj)) if restore_to is not None: g = restore_to if dist[g] == INF: return dist, False path = [g] node = g while node != s: node = prev[node] path.append(node) return dist, path[::-1] return dist def bellman_ford(self, s, t=None, INF=10**18): dist = [INF for _ in range(self.n)] dist[s] = 0 update = True for i in range(self.n): update = False for node, g in enumerate(self.graph): for adj, adjcost in g: if dist[node] != INF and dist[node] + adjcost < dist[adj]: dist[adj] = dist[node] + adjcost update = True if not update: return dist[t] if t is not None else dist if t is None: return negative_cycle = [0 for _ in range(self.n)] for i in range(self.n): for node, g in enumerate(self.graph): for adj, adjcost in g: if dist[node] != INF and dist[node] + adjcost < dist[adj]: dist[adj] = dist[node] + adjcost negative_cycle[adj] = True if not negative_cycle[t]: return dist[t] import sys input = sys.stdin.readline N, M = list(map(int, input().split())) E = [] for _ in range(M): a, b, c = list(map(int, input().split())) E.append((a, b, -c)) g = Graph(N, E) bf = g.bellman_ford(0, N - 1) print((-bf if bf is not None else "inf"))
false
44.444444
[ "-INF = 10**18", "+class Graph: # directed", "+ def __init__(self, n, edge, indexed=1):", "+ self.n = n", "+ self.graph = [[] for _ in range(n)]", "+ self.deg = [0 for _ in range(n)]", "+ for e in edge:", "+ self.graph[e[0] - indexed].append((e[1] - indexed, e[2]))", "+ self.deg[e[1] - indexed] += 1", "+", "+ def dijkstra(self, s, INF=10**18, restore_to=None):", "+ dist = [INF for _ in range(self.n)]", "+ dist[s] = 0", "+ heap = [(0, s)]", "+ while heap:", "+ cost, node = heappop(heap)", "+ if dist[node] < cost:", "+ continue", "+ for adj, adjcost in self.graph[node]:", "+ if dist[node] + adjcost < dist[adj]:", "+ dist[adj] = dist[node] + adjcost", "+ heappush(heap, (dist[adj], adj))", "+ if restore_to is not None:", "+ g = restore_to", "+ if dist[g] == INF:", "+ return dist, False", "+ path = [g]", "+ node = g", "+ while node != s:", "+ node = prev[node]", "+ path.append(node)", "+ return dist, path[::-1]", "+ return dist", "+", "+ def bellman_ford(self, s, t=None, INF=10**18):", "+ dist = [INF for _ in range(self.n)]", "+ dist[s] = 0", "+ update = True", "+ for i in range(self.n):", "+ update = False", "+ for node, g in enumerate(self.graph):", "+ for adj, adjcost in g:", "+ if dist[node] != INF and dist[node] + adjcost < dist[adj]:", "+ dist[adj] = dist[node] + adjcost", "+ update = True", "+ if not update:", "+ return dist[t] if t is not None else dist", "+ if t is None:", "+ return", "+ negative_cycle = [0 for _ in range(self.n)]", "+ for i in range(self.n):", "+ for node, g in enumerate(self.graph):", "+ for adj, adjcost in g:", "+ if dist[node] != INF and dist[node] + adjcost < dist[adj]:", "+ dist[adj] = dist[node] + adjcost", "+ negative_cycle[adj] = True", "+ if not negative_cycle[t]:", "+ return dist[t]", "+", "+", "+import sys", "+", "+input = sys.stdin.readline", "-edge = [list(map(int, input().split())) for i in range(M)]", "-graph = [[] for _ in range(N)]", "-for e in edge:", "- graph[e[0] - 1].append([e[1] - 1, -e[2]])", "-dist = [INF for _ in range(N)]", "-dist[0] = 0", "-for _ in range(N):", "- flag = False", "- for node, g in enumerate(graph):", "- for adj, cost in g:", "- if dist[node] != INF and dist[node] + cost < dist[adj]:", "- dist[adj] = dist[node] + cost", "- if _ == N - 1:", "- update = adj", "- flag = True", "- if not flag:", "- print((-dist[N - 1]))", "- break", "-else:", "- visited = [0 for _ in range(N)]", "- visited[update] = 1", "- stack = [update]", "- while stack:", "- node = stack.pop()", "- for adj, c in graph[node]:", "- if not visited[adj]:", "- visited[adj] = 1", "- stack.append(adj)", "- if visited[N - 1]:", "- print(\"inf\")", "- else:", "- print((-dist[N - 1]))", "+E = []", "+for _ in range(M):", "+ a, b, c = list(map(int, input().split()))", "+ E.append((a, b, -c))", "+g = Graph(N, E)", "+bf = g.bellman_ford(0, N - 1)", "+print((-bf if bf is not None else \"inf\"))" ]
false
0.042112
0.040655
1.035833
[ "s921016425", "s124948367" ]
u133936772
p03087
python
s658772582
s954765542
876
286
6,164
6,332
Accepted
Accepted
67.35
f = lambda : list(map(int,input().split())) n, q = f() s = eval(input()) cnt = 0 ln = [0]*n for i in range(1,n): if s[i-1:i+1] == 'AC': cnt += 1 ln[i] = cnt for _ in range(q): l, r = f() print((ln[r-1]-ln[l-1]))
import sys input = sys.stdin.readline f = lambda : list(map(int,input().split())) n, q = f() s = eval(input()) cnt = 0 ln = [0]*n for i in range(1,n): if s[i-1:i+1] == 'AC': cnt += 1 ln[i] = cnt for _ in range(q): l, r = f() print((ln[r-1]-ln[l-1]))
13
16
222
264
f = lambda: list(map(int, input().split())) n, q = f() s = eval(input()) cnt = 0 ln = [0] * n for i in range(1, n): if s[i - 1 : i + 1] == "AC": cnt += 1 ln[i] = cnt for _ in range(q): l, r = f() print((ln[r - 1] - ln[l - 1]))
import sys input = sys.stdin.readline f = lambda: list(map(int, input().split())) n, q = f() s = eval(input()) cnt = 0 ln = [0] * n for i in range(1, n): if s[i - 1 : i + 1] == "AC": cnt += 1 ln[i] = cnt for _ in range(q): l, r = f() print((ln[r - 1] - ln[l - 1]))
false
18.75
[ "+import sys", "+", "+input = sys.stdin.readline" ]
false
0.042169
0.126701
0.332824
[ "s658772582", "s954765542" ]
u753803401
p02946
python
s075454561
s499249402
19
17
3,060
3,060
Accepted
Accepted
10.53
k, x = list(map(int, input().split())) a = [] for i in range(x, x + k): if i not in a: a.append(i) for i in range(x, x - k, -1): if i not in a: a.append(i) a.sort() print((*a))
k, x = list(map(int, input().split())) a = [] for i in range(x, x + k): a.append(i) for i in range(x - 1, x - k, -1): a.append(i) a.sort() print((*a))
10
8
202
158
k, x = list(map(int, input().split())) a = [] for i in range(x, x + k): if i not in a: a.append(i) for i in range(x, x - k, -1): if i not in a: a.append(i) a.sort() print((*a))
k, x = list(map(int, input().split())) a = [] for i in range(x, x + k): a.append(i) for i in range(x - 1, x - k, -1): a.append(i) a.sort() print((*a))
false
20
[ "- if i not in a:", "- a.append(i)", "-for i in range(x, x - k, -1):", "- if i not in a:", "- a.append(i)", "+ a.append(i)", "+for i in range(x - 1, x - k, -1):", "+ a.append(i)" ]
false
0.084216
0.037313
2.256998
[ "s075454561", "s499249402" ]
u893063840
p02683
python
s554495385
s678657349
107
77
28,224
9,208
Accepted
Accepted
28.04
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline import numpy as np from itertools import product n, m, x = list(map(int, readline().split())) ca = np.array(read().split(), np.int64).reshape((n, m + 1)) INF = 10 ** 9 c = ca[:, 0] a = ca[:, 1:] p = np.array([e for e in product([1, 0], repeat=n)], np.int64) rikai = np.dot(p, a) cost = np.dot(p, c) idx = rikai.min(axis=1) >= x if idx.any(): ans = cost[idx].min() else: ans = -1 print(ans)
n, m, x = list(map(int, input().split())) ca = [list(map(int, input().split())) for _ in range(n)] INF = 10 ** 9 ans = INF for i in range(1 << n): sm = [0] * m cost = 0 for j in range(n): if i >> j & 1: cost += ca[j][0] for k, e in enumerate(ca[j][1:]): sm[k] += e if min(sm) >= x: ans = min(ans, cost) if ans == INF: ans = -1 print(ans)
24
21
497
432
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline import numpy as np from itertools import product n, m, x = list(map(int, readline().split())) ca = np.array(read().split(), np.int64).reshape((n, m + 1)) INF = 10**9 c = ca[:, 0] a = ca[:, 1:] p = np.array([e for e in product([1, 0], repeat=n)], np.int64) rikai = np.dot(p, a) cost = np.dot(p, c) idx = rikai.min(axis=1) >= x if idx.any(): ans = cost[idx].min() else: ans = -1 print(ans)
n, m, x = list(map(int, input().split())) ca = [list(map(int, input().split())) for _ in range(n)] INF = 10**9 ans = INF for i in range(1 << n): sm = [0] * m cost = 0 for j in range(n): if i >> j & 1: cost += ca[j][0] for k, e in enumerate(ca[j][1:]): sm[k] += e if min(sm) >= x: ans = min(ans, cost) if ans == INF: ans = -1 print(ans)
false
12.5
[ "-import sys", "-", "-read = sys.stdin.buffer.read", "-readline = sys.stdin.buffer.readline", "-import numpy as np", "-from itertools import product", "-", "-n, m, x = list(map(int, readline().split()))", "-ca = np.array(read().split(), np.int64).reshape((n, m + 1))", "+n, m, x = list(map(int, input().split()))", "+ca = [list(map(int, input().split())) for _ in range(n)]", "-c = ca[:, 0]", "-a = ca[:, 1:]", "-p = np.array([e for e in product([1, 0], repeat=n)], np.int64)", "-rikai = np.dot(p, a)", "-cost = np.dot(p, c)", "-idx = rikai.min(axis=1) >= x", "-if idx.any():", "- ans = cost[idx].min()", "-else:", "+ans = INF", "+for i in range(1 << n):", "+ sm = [0] * m", "+ cost = 0", "+ for j in range(n):", "+ if i >> j & 1:", "+ cost += ca[j][0]", "+ for k, e in enumerate(ca[j][1:]):", "+ sm[k] += e", "+ if min(sm) >= x:", "+ ans = min(ans, cost)", "+if ans == INF:" ]
false
0.256689
0.107224
2.393939
[ "s554495385", "s678657349" ]
u063056051
p01102
python
s127406693
s624732423
30
20
5,576
5,580
Accepted
Accepted
33.33
while 1: s1=input().split('"') if s1[0]==".": break s2=input().split('"') cnt1=0 cnt2=0 flag=0 if len(s1)!=len(s2): print("DIFFERENT") else: i=0 while i<len(s1): if s1[i]==s2[i]: cnt1+=1 elif i%2==0: print("DIFFERENT") flag=1 break else: cnt2+=1 if cnt2>1: print("DIFFERENT") break i+=1 if flag==0 and cnt2==1: print("CLOSE") if cnt1==len(s1): print("IDENTICAL")
while 1: list1=input().split('"') if list1[0]==".": break list2=input().split('"') cnt1=0 cnt2=0 flag=0 if len(list1)!=len(list2): print("DIFFERENT") else: i=0 while i<len(list1): if list1[i]==list2[i]: cnt1+=1 elif i%2==0: print("DIFFERENT") flag=1 break else: cnt2+=1 if cnt2>1: print("DIFFERENT") break i+=1 if flag==0 and cnt2==1: print("CLOSE") if cnt1==len(list1): print("IDENTICAL")
32
33
712
741
while 1: s1 = input().split('"') if s1[0] == ".": break s2 = input().split('"') cnt1 = 0 cnt2 = 0 flag = 0 if len(s1) != len(s2): print("DIFFERENT") else: i = 0 while i < len(s1): if s1[i] == s2[i]: cnt1 += 1 elif i % 2 == 0: print("DIFFERENT") flag = 1 break else: cnt2 += 1 if cnt2 > 1: print("DIFFERENT") break i += 1 if flag == 0 and cnt2 == 1: print("CLOSE") if cnt1 == len(s1): print("IDENTICAL")
while 1: list1 = input().split('"') if list1[0] == ".": break list2 = input().split('"') cnt1 = 0 cnt2 = 0 flag = 0 if len(list1) != len(list2): print("DIFFERENT") else: i = 0 while i < len(list1): if list1[i] == list2[i]: cnt1 += 1 elif i % 2 == 0: print("DIFFERENT") flag = 1 break else: cnt2 += 1 if cnt2 > 1: print("DIFFERENT") break i += 1 if flag == 0 and cnt2 == 1: print("CLOSE") if cnt1 == len(list1): print("IDENTICAL")
false
3.030303
[ "- s1 = input().split('\"')", "- if s1[0] == \".\":", "+ list1 = input().split('\"')", "+ if list1[0] == \".\":", "- s2 = input().split('\"')", "+ list2 = input().split('\"')", "- if len(s1) != len(s2):", "+ if len(list1) != len(list2):", "- while i < len(s1):", "- if s1[i] == s2[i]:", "+ while i < len(list1):", "+ if list1[i] == list2[i]:", "- if cnt1 == len(s1):", "+ if cnt1 == len(list1):" ]
false
0.040669
0.043307
0.939091
[ "s127406693", "s624732423" ]
u189023301
p02720
python
s205142053
s131341360
341
193
65,628
43,632
Accepted
Accepted
43.4
import sys input = sys.stdin.readline import itertools lunlun = [[] for i in range(11)] def main(): n = int(eval(input())) for i in range(100): flag = True l = len(str(i)) if l == 1: lunlun[l - 1].append(i) else: for a in range(1, len(str(i))): if abs(int(str(i)[a - 1]) - int(str(i)[a])) >= 2: flag = False break if flag: lunlun[l - 1].append(i) else: continue for j in range(1, 9): for a in lunlun[j]: for b in range(10): if abs(int(str(a)[-1]) - b) < 2: lunlun[j+1].append(int(str(a)+str(b))) lunlun2 = list(itertools.chain.from_iterable(lunlun)) print((lunlun2[n])) if __name__ == '__main__': main()
import sys input = sys.stdin.readline def main(): n = int(eval(input())) lunlun = [[] for i in range(11)] lunlun[0] = [1, 2, 3, 4, 5, 6, 7, 8, 9] cnt = 9 if n < 10: print(n) exit() for j in range(0, 10): for a in lunlun[j]: for b in range(10): if abs((a % 10) - b) < 2: lunlun[j + 1].append(10 * a + b) cnt += 1 if cnt == n: print((10 * a + b)) exit() if __name__ == '__main__': main()
32
24
878
592
import sys input = sys.stdin.readline import itertools lunlun = [[] for i in range(11)] def main(): n = int(eval(input())) for i in range(100): flag = True l = len(str(i)) if l == 1: lunlun[l - 1].append(i) else: for a in range(1, len(str(i))): if abs(int(str(i)[a - 1]) - int(str(i)[a])) >= 2: flag = False break if flag: lunlun[l - 1].append(i) else: continue for j in range(1, 9): for a in lunlun[j]: for b in range(10): if abs(int(str(a)[-1]) - b) < 2: lunlun[j + 1].append(int(str(a) + str(b))) lunlun2 = list(itertools.chain.from_iterable(lunlun)) print((lunlun2[n])) if __name__ == "__main__": main()
import sys input = sys.stdin.readline def main(): n = int(eval(input())) lunlun = [[] for i in range(11)] lunlun[0] = [1, 2, 3, 4, 5, 6, 7, 8, 9] cnt = 9 if n < 10: print(n) exit() for j in range(0, 10): for a in lunlun[j]: for b in range(10): if abs((a % 10) - b) < 2: lunlun[j + 1].append(10 * a + b) cnt += 1 if cnt == n: print((10 * a + b)) exit() if __name__ == "__main__": main()
false
25
[ "-import itertools", "-", "-lunlun = [[] for i in range(11)]", "- for i in range(100):", "- flag = True", "- l = len(str(i))", "- if l == 1:", "- lunlun[l - 1].append(i)", "- else:", "- for a in range(1, len(str(i))):", "- if abs(int(str(i)[a - 1]) - int(str(i)[a])) >= 2:", "- flag = False", "- break", "- if flag:", "- lunlun[l - 1].append(i)", "- else:", "- continue", "- for j in range(1, 9):", "+ lunlun = [[] for i in range(11)]", "+ lunlun[0] = [1, 2, 3, 4, 5, 6, 7, 8, 9]", "+ cnt = 9", "+ if n < 10:", "+ print(n)", "+ exit()", "+ for j in range(0, 10):", "- if abs(int(str(a)[-1]) - b) < 2:", "- lunlun[j + 1].append(int(str(a) + str(b)))", "- lunlun2 = list(itertools.chain.from_iterable(lunlun))", "- print((lunlun2[n]))", "+ if abs((a % 10) - b) < 2:", "+ lunlun[j + 1].append(10 * a + b)", "+ cnt += 1", "+ if cnt == n:", "+ print((10 * a + b))", "+ exit()" ]
false
0.932469
0.119145
7.826356
[ "s205142053", "s131341360" ]
u844646164
p02912
python
s535439179
s110941558
625
229
93,208
14,532
Accepted
Accepted
63.36
import heapq N, M = list(map(int, input().split())) A = list(map(int, input().split())) q = [] for a in A: q += [-a] heapq.heapify(q) for _ in range(M): a = heapq.heappop(q) heapq.heappush(q, a/2) ans = 0 for p in q: ans += int(-p) print(ans)
import heapq import math N, M = list(map(int, input().split())) A = list([-int(x) for x in input().split()]) heapq.heapify(A) while M > 0: a = heapq.heappop(A) heapq.heappush(A, a/2) M -= 1 ans = 0 for a in range(N): ans += math.floor(-A[a]) print(ans)
15
17
261
280
import heapq N, M = list(map(int, input().split())) A = list(map(int, input().split())) q = [] for a in A: q += [-a] heapq.heapify(q) for _ in range(M): a = heapq.heappop(q) heapq.heappush(q, a / 2) ans = 0 for p in q: ans += int(-p) print(ans)
import heapq import math N, M = list(map(int, input().split())) A = list([-int(x) for x in input().split()]) heapq.heapify(A) while M > 0: a = heapq.heappop(A) heapq.heappush(A, a / 2) M -= 1 ans = 0 for a in range(N): ans += math.floor(-A[a]) print(ans)
false
11.764706
[ "+import math", "-A = list(map(int, input().split()))", "-q = []", "-for a in A:", "- q += [-a]", "-heapq.heapify(q)", "-for _ in range(M):", "- a = heapq.heappop(q)", "- heapq.heappush(q, a / 2)", "+A = list([-int(x) for x in input().split()])", "+heapq.heapify(A)", "+while M > 0:", "+ a = heapq.heappop(A)", "+ heapq.heappush(A, a / 2)", "+ M -= 1", "-for p in q:", "- ans += int(-p)", "+for a in range(N):", "+ ans += math.floor(-A[a])" ]
false
0.094962
0.04768
1.991659
[ "s535439179", "s110941558" ]
u844646164
p02781
python
s576670109
s207566484
203
78
41,712
68,352
Accepted
Accepted
61.58
N = int(eval(input())) K = int(eval(input())) l = len(str(N)) dp = [[[0]*(K+1) for _ in range(2)] for _ in range(l+1)] # dp[i][smaller][j] # i: 調べている桁 # smaller: 未満フラグ(未満のとき1) # j: 0以外の数がj回出た dp[0][0][0] = 1 for i in range(l): n = int(str(N)[i]) for j in range(2): for k in range(K+1): for m in range(10): # 今までは一致 if j == 0 and m > n: continue if j == 0 and m == n: nj = 0 # 今回も一致 if m == 0: nk = k # 0なら回数は増えない else: if k < K: nk = k + 1 # 0以外の数がK-1回以下しかでていないなら増やす else: nk = k continue if j == 0 and m < n: nj = 1 if m == 0: nk = k else: if k < K: nk = k + 1 else: nk = k continue # すでに未満 if j == 1: nj = j if m == 0: nk = k else: if k < K: nk = k + 1 else: nk = k continue dp[i+1][nj][nk] += dp[i][j][k] print((dp[l][0][K]+dp[l][1][K]))
N = str(eval(input())) K = int(eval(input())) dp = [[[0]*2 for _ in range(K+1)] for _ in range(len(N)+1)] dp[0][0][0] = 1 for i in range(len(N)): n = int(N[i]) for j in range(K+1): for k in range(2): # smaller(未満なら1) for l in range(10): nj, nk = j, 0 if k == 0 and l == n: nk = 0 elif k == 0 and l < n: nk = 1 elif k == 0 and l > n: continue if k == 1: nk = 1 if l != 0: if j < K: nj += 1 else: continue dp[i+1][nj][nk] += dp[i][j][k] print((dp[-1][K][0] + dp[-1][K][1]))
55
34
1,190
687
N = int(eval(input())) K = int(eval(input())) l = len(str(N)) dp = [[[0] * (K + 1) for _ in range(2)] for _ in range(l + 1)] # dp[i][smaller][j] # i: 調べている桁 # smaller: 未満フラグ(未満のとき1) # j: 0以外の数がj回出た dp[0][0][0] = 1 for i in range(l): n = int(str(N)[i]) for j in range(2): for k in range(K + 1): for m in range(10): # 今までは一致 if j == 0 and m > n: continue if j == 0 and m == n: nj = 0 # 今回も一致 if m == 0: nk = k # 0なら回数は増えない else: if k < K: nk = k + 1 # 0以外の数がK-1回以下しかでていないなら増やす else: nk = k continue if j == 0 and m < n: nj = 1 if m == 0: nk = k else: if k < K: nk = k + 1 else: nk = k continue # すでに未満 if j == 1: nj = j if m == 0: nk = k else: if k < K: nk = k + 1 else: nk = k continue dp[i + 1][nj][nk] += dp[i][j][k] print((dp[l][0][K] + dp[l][1][K]))
N = str(eval(input())) K = int(eval(input())) dp = [[[0] * 2 for _ in range(K + 1)] for _ in range(len(N) + 1)] dp[0][0][0] = 1 for i in range(len(N)): n = int(N[i]) for j in range(K + 1): for k in range(2): # smaller(未満なら1) for l in range(10): nj, nk = j, 0 if k == 0 and l == n: nk = 0 elif k == 0 and l < n: nk = 1 elif k == 0 and l > n: continue if k == 1: nk = 1 if l != 0: if j < K: nj += 1 else: continue dp[i + 1][nj][nk] += dp[i][j][k] print((dp[-1][K][0] + dp[-1][K][1]))
false
38.181818
[ "-N = int(eval(input()))", "+N = str(eval(input()))", "-l = len(str(N))", "-dp = [[[0] * (K + 1) for _ in range(2)] for _ in range(l + 1)]", "-# dp[i][smaller][j]", "-# i: 調べている桁", "-# smaller: 未満フラグ(未満のとき1)", "-# j: 0以外の数がj回出た", "+dp = [[[0] * 2 for _ in range(K + 1)] for _ in range(len(N) + 1)]", "-for i in range(l):", "- n = int(str(N)[i])", "- for j in range(2):", "- for k in range(K + 1):", "- for m in range(10):", "- # 今までは一致", "- if j == 0 and m > n:", "+for i in range(len(N)):", "+ n = int(N[i])", "+ for j in range(K + 1):", "+ for k in range(2): # smaller(未満なら1)", "+ for l in range(10):", "+ nj, nk = j, 0", "+ if k == 0 and l == n:", "+ nk = 0", "+ elif k == 0 and l < n:", "+ nk = 1", "+ elif k == 0 and l > n:", "- if j == 0 and m == n:", "- nj = 0 # 今回も一致", "- if m == 0:", "- nk = k # 0なら回数は増えない", "+ if k == 1:", "+ nk = 1", "+ if l != 0:", "+ if j < K:", "+ nj += 1", "- if k < K:", "- nk = k + 1 # 0以外の数がK-1回以下しかでていないなら増やす", "- else:", "- nk = k", "- continue", "- if j == 0 and m < n:", "- nj = 1", "- if m == 0:", "- nk = k", "- else:", "- if k < K:", "- nk = k + 1", "- else:", "- nk = k", "- continue", "- # すでに未満", "- if j == 1:", "- nj = j", "- if m == 0:", "- nk = k", "- else:", "- if k < K:", "- nk = k + 1", "- else:", "- nk = k", "- continue", "+ continue", "-print((dp[l][0][K] + dp[l][1][K]))", "+print((dp[-1][K][0] + dp[-1][K][1]))" ]
false
0.049214
0.07567
0.65037
[ "s576670109", "s207566484" ]
u506858457
p03014
python
s081946431
s777354060
1,902
1,120
306,952
211,204
Accepted
Accepted
41.11
H,W=list(map(int,input().split())) S = [] for _ in range(H): S.append(list(eval(input()))) Left = [[0] * W for i in range(H)] for i in range(H): cur=0 for j in range(W): #cur=0 if S[i][j]=='#': cur=0 else: cur=cur+1 Left[i][j]=cur Right=[[0] * W for i in range(H)] for i in range(H): cur=0 for j in range(W-1,-1,-1): if S[i][j]=='#': cur=0 else: cur+=1 Right[i][j]=cur Up=[[0] * W for i in range(H)] for j in range(W): cur=0 for i in range(H): if S[i][j]=='#': cur=0 else: cur+=1 Up[i][j]=cur Down=[[0] * W for i in range(H)] for j in range(W): cur=0 for i in range(H-1,-1,-1): if S[i][j]=='#': cur=0 else: cur+=1 Down[i][j]=cur res=0 for i in range(H): for j in range(W): if S[i][j]=='#': continue res=max(res,Left[i][j]+Right[i][j]+Up[i][j]+Down[i][j]-3) print(res)
#Satoooh H, W = list(map(int, input().split())) S = [eval(input()) for _ in range(H)] # そのマスを含めてLeft, Right, Up, Downにそれぞれ何マス分明かりを照らせるかを配列に記録 L = [[0] * W for _ in range(H)] R = [[0] * W for _ in range(H)] D = [[0] * W for _ in range(H)] U = [[0] * W for _ in range(H)] for i in range(H): for j in range(W): if S[i][j] == ".": if j == 0: L[i][j] = 1 else: L[i][j] = L[i][j - 1] + 1 for i in range(H): for j in range(W - 1, -1, -1): if S[i][j] == ".": if j == W - 1: R[i][j] = 1 else: R[i][j] = R[i][j + 1] + 1 for j in range(W): for i in range(H - 1, -1, -1): if S[i][j] == ".": if i == H - 1: D[i][j] = 1 else: D[i][j] = D[i + 1][j] + 1 for j in range(W): for i in range(H): if S[i][j] == ".": if i == 0: U[i][j] = 1 else: U[i][j] = U[i - 1][j] + 1 ans = 0 X = [[0] * W for _ in range(H)] for i in range(H): for j in range(W): X[i][j] = L[i][j] + R[i][j] + D[i][j] + U[i][j] - 3 ans = max(ans, max(X[i])) print(ans)
53
51
976
1,035
H, W = list(map(int, input().split())) S = [] for _ in range(H): S.append(list(eval(input()))) Left = [[0] * W for i in range(H)] for i in range(H): cur = 0 for j in range(W): # cur=0 if S[i][j] == "#": cur = 0 else: cur = cur + 1 Left[i][j] = cur Right = [[0] * W for i in range(H)] for i in range(H): cur = 0 for j in range(W - 1, -1, -1): if S[i][j] == "#": cur = 0 else: cur += 1 Right[i][j] = cur Up = [[0] * W for i in range(H)] for j in range(W): cur = 0 for i in range(H): if S[i][j] == "#": cur = 0 else: cur += 1 Up[i][j] = cur Down = [[0] * W for i in range(H)] for j in range(W): cur = 0 for i in range(H - 1, -1, -1): if S[i][j] == "#": cur = 0 else: cur += 1 Down[i][j] = cur res = 0 for i in range(H): for j in range(W): if S[i][j] == "#": continue res = max(res, Left[i][j] + Right[i][j] + Up[i][j] + Down[i][j] - 3) print(res)
# Satoooh H, W = list(map(int, input().split())) S = [eval(input()) for _ in range(H)] # そのマスを含めてLeft, Right, Up, Downにそれぞれ何マス分明かりを照らせるかを配列に記録 L = [[0] * W for _ in range(H)] R = [[0] * W for _ in range(H)] D = [[0] * W for _ in range(H)] U = [[0] * W for _ in range(H)] for i in range(H): for j in range(W): if S[i][j] == ".": if j == 0: L[i][j] = 1 else: L[i][j] = L[i][j - 1] + 1 for i in range(H): for j in range(W - 1, -1, -1): if S[i][j] == ".": if j == W - 1: R[i][j] = 1 else: R[i][j] = R[i][j + 1] + 1 for j in range(W): for i in range(H - 1, -1, -1): if S[i][j] == ".": if i == H - 1: D[i][j] = 1 else: D[i][j] = D[i + 1][j] + 1 for j in range(W): for i in range(H): if S[i][j] == ".": if i == 0: U[i][j] = 1 else: U[i][j] = U[i - 1][j] + 1 ans = 0 X = [[0] * W for _ in range(H)] for i in range(H): for j in range(W): X[i][j] = L[i][j] + R[i][j] + D[i][j] + U[i][j] - 3 ans = max(ans, max(X[i])) print(ans)
false
3.773585
[ "+# Satoooh", "-S = []", "-for _ in range(H):", "- S.append(list(eval(input())))", "-Left = [[0] * W for i in range(H)]", "-for i in range(H):", "- cur = 0", "- for j in range(W):", "- # cur=0", "- if S[i][j] == \"#\":", "- cur = 0", "- else:", "- cur = cur + 1", "- Left[i][j] = cur", "-Right = [[0] * W for i in range(H)]", "-for i in range(H):", "- cur = 0", "- for j in range(W - 1, -1, -1):", "- if S[i][j] == \"#\":", "- cur = 0", "- else:", "- cur += 1", "- Right[i][j] = cur", "-Up = [[0] * W for i in range(H)]", "-for j in range(W):", "- cur = 0", "- for i in range(H):", "- if S[i][j] == \"#\":", "- cur = 0", "- else:", "- cur += 1", "- Up[i][j] = cur", "-Down = [[0] * W for i in range(H)]", "-for j in range(W):", "- cur = 0", "- for i in range(H - 1, -1, -1):", "- if S[i][j] == \"#\":", "- cur = 0", "- else:", "- cur += 1", "- Down[i][j] = cur", "-res = 0", "+S = [eval(input()) for _ in range(H)]", "+# そのマスを含めてLeft, Right, Up, Downにそれぞれ何マス分明かりを照らせるかを配列に記録", "+L = [[0] * W for _ in range(H)]", "+R = [[0] * W for _ in range(H)]", "+D = [[0] * W for _ in range(H)]", "+U = [[0] * W for _ in range(H)]", "- if S[i][j] == \"#\":", "- continue", "- res = max(res, Left[i][j] + Right[i][j] + Up[i][j] + Down[i][j] - 3)", "-print(res)", "+ if S[i][j] == \".\":", "+ if j == 0:", "+ L[i][j] = 1", "+ else:", "+ L[i][j] = L[i][j - 1] + 1", "+for i in range(H):", "+ for j in range(W - 1, -1, -1):", "+ if S[i][j] == \".\":", "+ if j == W - 1:", "+ R[i][j] = 1", "+ else:", "+ R[i][j] = R[i][j + 1] + 1", "+for j in range(W):", "+ for i in range(H - 1, -1, -1):", "+ if S[i][j] == \".\":", "+ if i == H - 1:", "+ D[i][j] = 1", "+ else:", "+ D[i][j] = D[i + 1][j] + 1", "+for j in range(W):", "+ for i in range(H):", "+ if S[i][j] == \".\":", "+ if i == 0:", "+ U[i][j] = 1", "+ else:", "+ U[i][j] = U[i - 1][j] + 1", "+ans = 0", "+X = [[0] * W for _ in range(H)]", "+for i in range(H):", "+ for j in range(W):", "+ X[i][j] = L[i][j] + R[i][j] + D[i][j] + U[i][j] - 3", "+ ans = max(ans, max(X[i]))", "+print(ans)" ]
false
0.092994
0.069079
1.346194
[ "s081946431", "s777354060" ]
u021019433
p03032
python
s511226498
s937139481
53
44
3,064
3,316
Accepted
Accepted
16.98
import heapq from itertools import chain R = lambda: list(map(int, input().split())) n, k = R() v = list(R()) r = 0 for i in range(1, min(n, k) + 1): for j in range(i): s = 0 h = [] for m in chain(list(range(i - j)), list(range(n - j, n))): x = v[m] s += x if x < 0: heapq.heappush(h, x) j = i while h and j < k: s -= heapq.heappop(h) j += 1 r = max(r, s) print(r)
from itertools import chain R = lambda: list(map(int, input().split())) n, k = R() v = list(R()) a = sorted((x, i) for i, x in enumerate(v) if x < 0) r = 0 for i in range(1, min(n, k) + 1): for j in range(i): r1, r2 = list(range(i - j)), list(range(n - j, n)) s = sum(v[m] for m in chain(r1, r2)) j = i for x, m in a: if j == k: break if m in r1 or m in r2: s -= x j += 1 r = max(r, s) print(r)
22
20
497
514
import heapq from itertools import chain R = lambda: list(map(int, input().split())) n, k = R() v = list(R()) r = 0 for i in range(1, min(n, k) + 1): for j in range(i): s = 0 h = [] for m in chain(list(range(i - j)), list(range(n - j, n))): x = v[m] s += x if x < 0: heapq.heappush(h, x) j = i while h and j < k: s -= heapq.heappop(h) j += 1 r = max(r, s) print(r)
from itertools import chain R = lambda: list(map(int, input().split())) n, k = R() v = list(R()) a = sorted((x, i) for i, x in enumerate(v) if x < 0) r = 0 for i in range(1, min(n, k) + 1): for j in range(i): r1, r2 = list(range(i - j)), list(range(n - j, n)) s = sum(v[m] for m in chain(r1, r2)) j = i for x, m in a: if j == k: break if m in r1 or m in r2: s -= x j += 1 r = max(r, s) print(r)
false
9.090909
[ "-import heapq", "+a = sorted((x, i) for i, x in enumerate(v) if x < 0)", "- s = 0", "- h = []", "- for m in chain(list(range(i - j)), list(range(n - j, n))):", "- x = v[m]", "- s += x", "- if x < 0:", "- heapq.heappush(h, x)", "+ r1, r2 = list(range(i - j)), list(range(n - j, n))", "+ s = sum(v[m] for m in chain(r1, r2))", "- while h and j < k:", "- s -= heapq.heappop(h)", "- j += 1", "+ for x, m in a:", "+ if j == k:", "+ break", "+ if m in r1 or m in r2:", "+ s -= x", "+ j += 1" ]
false
0.03656
0.038038
0.961155
[ "s511226498", "s937139481" ]
u208713671
p03565
python
s813542888
s784182064
77
64
62,996
62,672
Accepted
Accepted
16.88
S = list(eval(input())) T = list(eval(input())) NS,NT = len(S),len(T) outs = [] if NS>=NT: for i in range(NS-NT+1): flag = 0 for j in range(NT): if S[i+j]==T[j] or S[i+j]=="?": continue else: flag = 1 break if flag==0: out = ["a"]*NS for j in range(NT): out[i+j]=T[j] for j in range(NS): if S[j]!="?": out[j]=S[j] outs.append("".join(out)) if len(outs) == 0: print("UNRESTORABLE") else: outs.sort() print((outs[0]))
S = list(eval(input())) T = list(eval(input())) NS,NT = len(S),len(T) outs = [] if NS>=NT: for i in range(NS-NT+1): flag = 0 for j in range(NT): if S[i+j]==T[j] or S[i+j]=="?": continue else: flag = 1 break if flag==0: out = ["a"]*NS for j in range(NT): out[i+j]=T[j] for j in range(NS): if S[j]!="?": out[j]=S[j] outs.append("".join(out)) if len(outs) == 0: print("UNRESTORABLE") else: print((outs[-1]))
27
26
640
624
S = list(eval(input())) T = list(eval(input())) NS, NT = len(S), len(T) outs = [] if NS >= NT: for i in range(NS - NT + 1): flag = 0 for j in range(NT): if S[i + j] == T[j] or S[i + j] == "?": continue else: flag = 1 break if flag == 0: out = ["a"] * NS for j in range(NT): out[i + j] = T[j] for j in range(NS): if S[j] != "?": out[j] = S[j] outs.append("".join(out)) if len(outs) == 0: print("UNRESTORABLE") else: outs.sort() print((outs[0]))
S = list(eval(input())) T = list(eval(input())) NS, NT = len(S), len(T) outs = [] if NS >= NT: for i in range(NS - NT + 1): flag = 0 for j in range(NT): if S[i + j] == T[j] or S[i + j] == "?": continue else: flag = 1 break if flag == 0: out = ["a"] * NS for j in range(NT): out[i + j] = T[j] for j in range(NS): if S[j] != "?": out[j] = S[j] outs.append("".join(out)) if len(outs) == 0: print("UNRESTORABLE") else: print((outs[-1]))
false
3.703704
[ "- outs.sort()", "- print((outs[0]))", "+ print((outs[-1]))" ]
false
0.033407
0.044497
0.750779
[ "s813542888", "s784182064" ]
u723711163
p02708
python
s743424263
s758884920
170
62
9,204
64,792
Accepted
Accepted
63.53
N, K = list(map(int, input().split())) MAX = 10 ** 9 + 7 res = 0 def calc_sum(l, r): return ((l+r) * (r-l+1)) // 2 for i in range(K, N+2): low = calc_sum(0,i-1) high = calc_sum(N-i+1,N) res = (res + (high-low+1)) % MAX print(res)
N,K = list(map(int,input().split())) MOD = 10**9+7 res = 0 curmin,curmax = 0, N mini,maxi = 1, N-1 for i in range(1,N+2): if i == N+1: # print(1) res += 1 else: if i >= K: # print(curmin,curmax) res = (res + curmax - curmin + 1) % MOD curmin += mini curmax += maxi mini += 1 maxi -= 1 print((res % MOD))
14
19
252
359
N, K = list(map(int, input().split())) MAX = 10**9 + 7 res = 0 def calc_sum(l, r): return ((l + r) * (r - l + 1)) // 2 for i in range(K, N + 2): low = calc_sum(0, i - 1) high = calc_sum(N - i + 1, N) res = (res + (high - low + 1)) % MAX print(res)
N, K = list(map(int, input().split())) MOD = 10**9 + 7 res = 0 curmin, curmax = 0, N mini, maxi = 1, N - 1 for i in range(1, N + 2): if i == N + 1: # print(1) res += 1 else: if i >= K: # print(curmin,curmax) res = (res + curmax - curmin + 1) % MOD curmin += mini curmax += maxi mini += 1 maxi -= 1 print((res % MOD))
false
26.315789
[ "-MAX = 10**9 + 7", "+MOD = 10**9 + 7", "-", "-", "-def calc_sum(l, r):", "- return ((l + r) * (r - l + 1)) // 2", "-", "-", "-for i in range(K, N + 2):", "- low = calc_sum(0, i - 1)", "- high = calc_sum(N - i + 1, N)", "- res = (res + (high - low + 1)) % MAX", "-print(res)", "+curmin, curmax = 0, N", "+mini, maxi = 1, N - 1", "+for i in range(1, N + 2):", "+ if i == N + 1:", "+ # print(1)", "+ res += 1", "+ else:", "+ if i >= K:", "+ # print(curmin,curmax)", "+ res = (res + curmax - curmin + 1) % MOD", "+ curmin += mini", "+ curmax += maxi", "+ mini += 1", "+ maxi -= 1", "+print((res % MOD))" ]
false
0.08262
0.108847
0.759051
[ "s743424263", "s758884920" ]
u709304134
p02928
python
s380413157
s424766814
1,896
316
3,188
82,536
Accepted
Accepted
83.33
MOD = 1000000007 N,K = list(map(int,input().split())) A = list(map(int,input().split())) def bubble_sort(A): cnt = 0 for i in range(len(A)): for j in range(len(A)-1, i, -1): if A[j] < A[j-1]: A[j], A[j-1] = A[j-1], A[j] cnt += 1 return cnt def sigma(k): return int(k*(k+1)//2) C = [] for k in range(2): C.extend(A) cnt = bubble_sort(A) diff = bubble_sort(C) - 2 * cnt a = (K*cnt) b = (diff*sigma(K-1)) print(((a+b)%MOD))
import sys input = sys.stdin.readline sys.setrecursionlimit(10 ** 7) import numpy as np MOD = 10**9 + 7 N,K = list(map(int,input().split())) A = np.array(input().split(), dtype=np.int64) # 同じグループ内 def type_1(): bl1 = A[:,None] > A[None,:] bl2 = np.arange(N,dtype=np.int64)[:,None] < np.arange(N,dtype=np.int64)[None,:] x = ((bl1 & bl2)*1).astype(np.int64).sum() % MOD return x*K%MOD def type_2(): # グループ間 counter = np.bincount(A) cum = counter.cumsum() larger = N-cum x = (larger * counter % MOD).sum() % MOD y = K*(K-1)//2 % MOD return x*y%MOD answer = (type_1() + type_2()) % MOD print(answer)
21
29
506
668
MOD = 1000000007 N, K = list(map(int, input().split())) A = list(map(int, input().split())) def bubble_sort(A): cnt = 0 for i in range(len(A)): for j in range(len(A) - 1, i, -1): if A[j] < A[j - 1]: A[j], A[j - 1] = A[j - 1], A[j] cnt += 1 return cnt def sigma(k): return int(k * (k + 1) // 2) C = [] for k in range(2): C.extend(A) cnt = bubble_sort(A) diff = bubble_sort(C) - 2 * cnt a = K * cnt b = diff * sigma(K - 1) print(((a + b) % MOD))
import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) import numpy as np MOD = 10**9 + 7 N, K = list(map(int, input().split())) A = np.array(input().split(), dtype=np.int64) # 同じグループ内 def type_1(): bl1 = A[:, None] > A[None, :] bl2 = np.arange(N, dtype=np.int64)[:, None] < np.arange(N, dtype=np.int64)[None, :] x = ((bl1 & bl2) * 1).astype(np.int64).sum() % MOD return x * K % MOD def type_2(): # グループ間 counter = np.bincount(A) cum = counter.cumsum() larger = N - cum x = (larger * counter % MOD).sum() % MOD y = K * (K - 1) // 2 % MOD return x * y % MOD answer = (type_1() + type_2()) % MOD print(answer)
false
27.586207
[ "-MOD = 1000000007", "+import sys", "+", "+input = sys.stdin.readline", "+sys.setrecursionlimit(10**7)", "+import numpy as np", "+", "+MOD = 10**9 + 7", "-A = list(map(int, input().split()))", "+A = np.array(input().split(), dtype=np.int64)", "+# 同じグループ内", "+def type_1():", "+ bl1 = A[:, None] > A[None, :]", "+ bl2 = np.arange(N, dtype=np.int64)[:, None] < np.arange(N, dtype=np.int64)[None, :]", "+ x = ((bl1 & bl2) * 1).astype(np.int64).sum() % MOD", "+ return x * K % MOD", "-def bubble_sort(A):", "- cnt = 0", "- for i in range(len(A)):", "- for j in range(len(A) - 1, i, -1):", "- if A[j] < A[j - 1]:", "- A[j], A[j - 1] = A[j - 1], A[j]", "- cnt += 1", "- return cnt", "+def type_2():", "+ # グループ間", "+ counter = np.bincount(A)", "+ cum = counter.cumsum()", "+ larger = N - cum", "+ x = (larger * counter % MOD).sum() % MOD", "+ y = K * (K - 1) // 2 % MOD", "+ return x * y % MOD", "-def sigma(k):", "- return int(k * (k + 1) // 2)", "-", "-", "-C = []", "-for k in range(2):", "- C.extend(A)", "-cnt = bubble_sort(A)", "-diff = bubble_sort(C) - 2 * cnt", "-a = K * cnt", "-b = diff * sigma(K - 1)", "-print(((a + b) % MOD))", "+answer = (type_1() + type_2()) % MOD", "+print(answer)" ]
false
0.107864
0.212525
0.507534
[ "s380413157", "s424766814" ]
u243572357
p03470
python
s097589129
s151457655
20
17
2,940
3,064
Accepted
Accepted
15
n = int(eval(input())) a = [int(eval(input())) for _ in range(n)] print((len(set(a))))
n = int(eval(input())) print((len(set([eval(input()) for i in range(n)]))))
4
2
76
62
n = int(eval(input())) a = [int(eval(input())) for _ in range(n)] print((len(set(a))))
n = int(eval(input())) print((len(set([eval(input()) for i in range(n)]))))
false
50
[ "-a = [int(eval(input())) for _ in range(n)]", "-print((len(set(a))))", "+print((len(set([eval(input()) for i in range(n)]))))" ]
false
0.072268
0.060149
1.201487
[ "s097589129", "s151457655" ]
u958693198
p02850
python
s676672278
s153658511
412
371
28,200
21,784
Accepted
Accepted
9.95
import sys from collections import deque input = sys.stdin.readline N = int(eval(input())) X = [[] for _ in range(N)] for i in range(N-1): a, b = list(map(int, input().split())) X[a-1].append((i, b-1)) Q = deque([(0, -1)]) ANS = [-1] * (N-1) cmax = 0 while Q: x, c0 = Q.pop() c = 1 for i, y in X[x]: if c == c0: c += 1 ANS[i] = c Q.appendleft((y, c)) c += 1 cmax = max(cmax, c-1) print(cmax) for ans in ANS: print(ans)
import sys from collections import deque input = sys.stdin.readline N = int(eval(input())) bi=[0]* N children = [[] for _ in range(N)] for i in range(N-1): a, b = list(map(int, input().split())) bi[i]=b-1 children[a-1].append(b-1) queue = deque([0]) colors = [0] * N maxColor = 0 while queue: node = queue.popleft() nodeColor = colors[node] color = 1 for child in children[node]: if color == nodeColor: color += 1 colors[child] = color queue.append(child) color += 1 maxColor = max(maxColor, color-1) print(maxColor) for i in range(N-1): print((colors[bi[i]]))
25
28
492
643
import sys from collections import deque input = sys.stdin.readline N = int(eval(input())) X = [[] for _ in range(N)] for i in range(N - 1): a, b = list(map(int, input().split())) X[a - 1].append((i, b - 1)) Q = deque([(0, -1)]) ANS = [-1] * (N - 1) cmax = 0 while Q: x, c0 = Q.pop() c = 1 for i, y in X[x]: if c == c0: c += 1 ANS[i] = c Q.appendleft((y, c)) c += 1 cmax = max(cmax, c - 1) print(cmax) for ans in ANS: print(ans)
import sys from collections import deque input = sys.stdin.readline N = int(eval(input())) bi = [0] * N children = [[] for _ in range(N)] for i in range(N - 1): a, b = list(map(int, input().split())) bi[i] = b - 1 children[a - 1].append(b - 1) queue = deque([0]) colors = [0] * N maxColor = 0 while queue: node = queue.popleft() nodeColor = colors[node] color = 1 for child in children[node]: if color == nodeColor: color += 1 colors[child] = color queue.append(child) color += 1 maxColor = max(maxColor, color - 1) print(maxColor) for i in range(N - 1): print((colors[bi[i]]))
false
10.714286
[ "-X = [[] for _ in range(N)]", "+bi = [0] * N", "+children = [[] for _ in range(N)]", "- X[a - 1].append((i, b - 1))", "-Q = deque([(0, -1)])", "-ANS = [-1] * (N - 1)", "-cmax = 0", "-while Q:", "- x, c0 = Q.pop()", "- c = 1", "- for i, y in X[x]:", "- if c == c0:", "- c += 1", "- ANS[i] = c", "- Q.appendleft((y, c))", "- c += 1", "- cmax = max(cmax, c - 1)", "-print(cmax)", "-for ans in ANS:", "- print(ans)", "+ bi[i] = b - 1", "+ children[a - 1].append(b - 1)", "+queue = deque([0])", "+colors = [0] * N", "+maxColor = 0", "+while queue:", "+ node = queue.popleft()", "+ nodeColor = colors[node]", "+ color = 1", "+ for child in children[node]:", "+ if color == nodeColor:", "+ color += 1", "+ colors[child] = color", "+ queue.append(child)", "+ color += 1", "+ maxColor = max(maxColor, color - 1)", "+print(maxColor)", "+for i in range(N - 1):", "+ print((colors[bi[i]]))" ]
false
0.046739
0.047042
0.993561
[ "s676672278", "s153658511" ]
u003475507
p02781
python
s139889129
s245698873
23
18
3,064
3,064
Accepted
Accepted
21.74
s = eval(input()) K = int(eval(input())) n =len(s) dp = [[[0] * 2 for _ in range(4)] for _ in range(101)] dp[0][0][0]=1 for i in range(n): for j in range(4): for k in range(2): nd = int(s[i]) for d in range(10): ni = i+1; nj = j; nk = k if d != 0 :nj+=1 if nj > K:continue if k==0: if d > nd:continue if d < nd:nk =1 dp[ni][nj][nk] += dp[i][j][k] # print(d,k) # print(i,j,k,dp[i][j][k]) # print(ni,nj,nk,dp[ni][nj][nk]) # [print(i) for i in dp] ans=dp[n][K][0] + dp[n][K][1] print(ans) # [print(i) for i in dp]
s=eval(input()) n=len(s) K=int(eval(input())) dp=[[[0] * 5 for _ in range(2)] for _ in range(n+1)] dp[0][0][0]=1 for i in range(n): ni= int(s[i]) for k in range(4): # smaller 1 -> 全部OK dp[i + 1][1][k + 1] += dp[i][1][k] * 9; dp[i + 1][1][k] += dp[i][1][k]; # smaller 0,next smaller 1 -> nowより小さいのを全部 # 次の桁からsmallerであるためにはN<ni であることが必要で # Nは0より大きい必要がある。(0より小さいものがない=確定しない if (ni > 0): dp[i + 1][1][k + 1] += dp[i][0][k] * (ni - 1) dp[i + 1][1][k] += dp[i][0][k] # smaller 0,next smaller 0 -> nowだけ if (ni > 0) : dp[i + 1][0][k + 1] = dp[i][0][k] else: dp[i + 1][0][k] = dp[i][0][k] ans=dp[n][0][K] + dp[n][1][K] print(ans)
29
31
751
858
s = eval(input()) K = int(eval(input())) n = len(s) dp = [[[0] * 2 for _ in range(4)] for _ in range(101)] dp[0][0][0] = 1 for i in range(n): for j in range(4): for k in range(2): nd = int(s[i]) for d in range(10): ni = i + 1 nj = j nk = k if d != 0: nj += 1 if nj > K: continue if k == 0: if d > nd: continue if d < nd: nk = 1 dp[ni][nj][nk] += dp[i][j][k] # print(d,k) # print(i,j,k,dp[i][j][k]) # print(ni,nj,nk,dp[ni][nj][nk]) # [print(i) for i in dp] ans = dp[n][K][0] + dp[n][K][1] print(ans) # [print(i) for i in dp]
s = eval(input()) n = len(s) K = int(eval(input())) dp = [[[0] * 5 for _ in range(2)] for _ in range(n + 1)] dp[0][0][0] = 1 for i in range(n): ni = int(s[i]) for k in range(4): # smaller 1 -> 全部OK dp[i + 1][1][k + 1] += dp[i][1][k] * 9 dp[i + 1][1][k] += dp[i][1][k] # smaller 0,next smaller 1 -> nowより小さいのを全部 # 次の桁からsmallerであるためにはN<ni であることが必要で # Nは0より大きい必要がある。(0より小さいものがない=確定しない if ni > 0: dp[i + 1][1][k + 1] += dp[i][0][k] * (ni - 1) dp[i + 1][1][k] += dp[i][0][k] # smaller 0,next smaller 0 -> nowだけ if ni > 0: dp[i + 1][0][k + 1] = dp[i][0][k] else: dp[i + 1][0][k] = dp[i][0][k] ans = dp[n][0][K] + dp[n][1][K] print(ans)
false
6.451613
[ "+n = len(s)", "-n = len(s)", "-dp = [[[0] * 2 for _ in range(4)] for _ in range(101)]", "+dp = [[[0] * 5 for _ in range(2)] for _ in range(n + 1)]", "- for j in range(4):", "- for k in range(2):", "- nd = int(s[i])", "- for d in range(10):", "- ni = i + 1", "- nj = j", "- nk = k", "- if d != 0:", "- nj += 1", "- if nj > K:", "- continue", "- if k == 0:", "- if d > nd:", "- continue", "- if d < nd:", "- nk = 1", "- dp[ni][nj][nk] += dp[i][j][k]", "- # print(d,k)", "- # print(i,j,k,dp[i][j][k])", "- # print(ni,nj,nk,dp[ni][nj][nk])", "- # [print(i) for i in dp]", "-ans = dp[n][K][0] + dp[n][K][1]", "+ ni = int(s[i])", "+ for k in range(4):", "+ # smaller 1 -> 全部OK", "+ dp[i + 1][1][k + 1] += dp[i][1][k] * 9", "+ dp[i + 1][1][k] += dp[i][1][k]", "+ # smaller 0,next smaller 1 -> nowより小さいのを全部", "+ # 次の桁からsmallerであるためにはN<ni であることが必要で", "+ # Nは0より大きい必要がある。(0より小さいものがない=確定しない", "+ if ni > 0:", "+ dp[i + 1][1][k + 1] += dp[i][0][k] * (ni - 1)", "+ dp[i + 1][1][k] += dp[i][0][k]", "+ # smaller 0,next smaller 0 -> nowだけ", "+ if ni > 0:", "+ dp[i + 1][0][k + 1] = dp[i][0][k]", "+ else:", "+ dp[i + 1][0][k] = dp[i][0][k]", "+ans = dp[n][0][K] + dp[n][1][K]", "-# [print(i) for i in dp]" ]
false
0.118143
0.039159
3.016986
[ "s139889129", "s245698873" ]
u350243405
p02880
python
s647945172
s452613266
19
17
3,060
3,064
Accepted
Accepted
10.53
n=int(eval(input())) i=1 check=False while i<int(n**.5+1): if n/i<10 and n%i==0: print("Yes") check=True break i+=1 if not check: print("No")
n=int(eval(input())) check=False; i=1 while i<10: j=1 while j<10: if (i*j==n): print('Yes') check=True break; j+=1; if check: break i+=1 if not check: print("No")
12
18
183
257
n = int(eval(input())) i = 1 check = False while i < int(n**0.5 + 1): if n / i < 10 and n % i == 0: print("Yes") check = True break i += 1 if not check: print("No")
n = int(eval(input())) check = False i = 1 while i < 10: j = 1 while j < 10: if i * j == n: print("Yes") check = True break j += 1 if check: break i += 1 if not check: print("No")
false
33.333333
[ "+check = False", "-check = False", "-while i < int(n**0.5 + 1):", "- if n / i < 10 and n % i == 0:", "- print(\"Yes\")", "- check = True", "+while i < 10:", "+ j = 1", "+ while j < 10:", "+ if i * j == n:", "+ print(\"Yes\")", "+ check = True", "+ break", "+ j += 1", "+ if check:" ]
false
0.0429
0.041534
1.032888
[ "s647945172", "s452613266" ]
u393253137
p02744
python
s071276548
s561603629
93
52
14,788
15,368
Accepted
Accepted
44.09
n = int(input()) A = 'a' S ='abcdefghij' for _ in range(n-1): A = [a + s for a in A for s in S[:len(set(a))+1]] print(*A, sep='\n')
n = int(eval(input())) A = 'a' S = 'abcdefghij' for _ in range(n-1): A = [ a + s for a in A for s in S[:len(set(a)) + 1]] print(('\n'.join(A)))
6
6
140
144
n = int(input()) A = "a" S = "abcdefghij" for _ in range(n - 1): A = [a + s for a in A for s in S[: len(set(a)) + 1]] print(*A, sep="\n")
n = int(eval(input())) A = "a" S = "abcdefghij" for _ in range(n - 1): A = [a + s for a in A for s in S[: len(set(a)) + 1]] print(("\n".join(A)))
false
0
[ "-n = int(input())", "+n = int(eval(input()))", "-print(*A, sep=\"\\n\")", "+print((\"\\n\".join(A)))" ]
false
0.042452
0.036565
1.161011
[ "s071276548", "s561603629" ]
u782930273
p03137
python
s314416050
s200693707
133
109
18,388
13,840
Accepted
Accepted
18.05
N, M = list(map(int, input().split())) X = [int(x) for x in input().split()] if N >= M: print((0)) else: X.sort() dX = [(i, X[i + 1] - X[i]) for i in range(M - 1)] dX.sort(key=lambda x: x[1], reverse=True) print((sum(d[1] for d in dX[N - 1:])))
N, M = list(map(int, input().split())) X = [int(x) for x in input().split()] if N >= M: print((0)) else: X.sort() dX = [X[i + 1] - X[i] for i in range(M - 1)] dX.sort(reverse=True) print((sum(dX[N - 1:])))
10
10
264
225
N, M = list(map(int, input().split())) X = [int(x) for x in input().split()] if N >= M: print((0)) else: X.sort() dX = [(i, X[i + 1] - X[i]) for i in range(M - 1)] dX.sort(key=lambda x: x[1], reverse=True) print((sum(d[1] for d in dX[N - 1 :])))
N, M = list(map(int, input().split())) X = [int(x) for x in input().split()] if N >= M: print((0)) else: X.sort() dX = [X[i + 1] - X[i] for i in range(M - 1)] dX.sort(reverse=True) print((sum(dX[N - 1 :])))
false
0
[ "- dX = [(i, X[i + 1] - X[i]) for i in range(M - 1)]", "- dX.sort(key=lambda x: x[1], reverse=True)", "- print((sum(d[1] for d in dX[N - 1 :])))", "+ dX = [X[i + 1] - X[i] for i in range(M - 1)]", "+ dX.sort(reverse=True)", "+ print((sum(dX[N - 1 :])))" ]
false
0.048593
0.04912
0.989264
[ "s314416050", "s200693707" ]
u148981246
p02614
python
s085047860
s647222946
83
64
9,144
9,032
Accepted
Accepted
22.89
h, w, k = list(map(int, input().split(' '))) c = [eval(input()) for x in range(h)] cnt = 0 for m in range(2**(h+w)): cc = c.copy() for ij in range(h+w): if ((m >> ij) & 1): if ij in range(h): cc[ij] = '.'*w if ij in range(h,h+w): for t in range(h): cc[t] = cc[t][:ij-h]+'.'+cc[t][ij+1-h:] num = sum(cc[s].count('#') for s in range(h)) if num == k: cnt += 1 print(cnt)
h, w, k = list(map(int, input().split(' '))) c = [eval(input()) for x in range(h)] cnt = 0 for maskR in range(2**h): for maskC in range(2**w): black = 0 for i in range(h): for j in range(w): if (((maskR >> i) &1) == 0 and ((maskC >> j) &1) == 0 and c[i][j] == '#'): black += 1 if black == k: cnt += 1 print(cnt)
16
15
478
422
h, w, k = list(map(int, input().split(" "))) c = [eval(input()) for x in range(h)] cnt = 0 for m in range(2 ** (h + w)): cc = c.copy() for ij in range(h + w): if (m >> ij) & 1: if ij in range(h): cc[ij] = "." * w if ij in range(h, h + w): for t in range(h): cc[t] = cc[t][: ij - h] + "." + cc[t][ij + 1 - h :] num = sum(cc[s].count("#") for s in range(h)) if num == k: cnt += 1 print(cnt)
h, w, k = list(map(int, input().split(" "))) c = [eval(input()) for x in range(h)] cnt = 0 for maskR in range(2**h): for maskC in range(2**w): black = 0 for i in range(h): for j in range(w): if ( ((maskR >> i) & 1) == 0 and ((maskC >> j) & 1) == 0 and c[i][j] == "#" ): black += 1 if black == k: cnt += 1 print(cnt)
false
6.25
[ "-for m in range(2 ** (h + w)):", "- cc = c.copy()", "- for ij in range(h + w):", "- if (m >> ij) & 1:", "- if ij in range(h):", "- cc[ij] = \".\" * w", "- if ij in range(h, h + w):", "- for t in range(h):", "- cc[t] = cc[t][: ij - h] + \".\" + cc[t][ij + 1 - h :]", "- num = sum(cc[s].count(\"#\") for s in range(h))", "- if num == k:", "- cnt += 1", "+for maskR in range(2**h):", "+ for maskC in range(2**w):", "+ black = 0", "+ for i in range(h):", "+ for j in range(w):", "+ if (", "+ ((maskR >> i) & 1) == 0", "+ and ((maskC >> j) & 1) == 0", "+ and c[i][j] == \"#\"", "+ ):", "+ black += 1", "+ if black == k:", "+ cnt += 1" ]
false
0.040791
0.097828
0.416967
[ "s085047860", "s647222946" ]
u462329577
p02754
python
s431048101
s273735386
175
17
38,256
2,940
Accepted
Accepted
90.29
#!/usr/bin/env python3 n,a,b = list(map(int,input().split())) print(((n//(a+b))*a + min(a,n%(a+b))))
n, a, b = list(map(int, input().split())) print(((n // (a + b)) * a + min(n % (a + b), a)))
4
2
96
85
#!/usr/bin/env python3 n, a, b = list(map(int, input().split())) print(((n // (a + b)) * a + min(a, n % (a + b))))
n, a, b = list(map(int, input().split())) print(((n // (a + b)) * a + min(n % (a + b), a)))
false
50
[ "-#!/usr/bin/env python3", "-print(((n // (a + b)) * a + min(a, n % (a + b))))", "+print(((n // (a + b)) * a + min(n % (a + b), a)))" ]
false
0.042336
0.03544
1.194599
[ "s431048101", "s273735386" ]
u347600233
p02713
python
s172778467
s416037176
1,940
1,157
9,108
9,020
Accepted
Accepted
40.36
def gcd(a, b): if a < b: a, b = b, a while b: a, b = b, a % b return a k = int(eval(input())) sum = 0 for i in range(1, k + 1): for j in range(1, k + 1): gcd_ij = gcd(i, j) for k in range(1, k + 1): sum += gcd(gcd_ij, k) print(sum)
from math import gcd k = int(eval(input())) sum = 0 for i in range(1, k + 1): for j in range(1, k + 1): gcd_ij = gcd(i, j) for k in range(1, k + 1): sum += gcd(gcd_ij, k) print(sum)
16
9
302
215
def gcd(a, b): if a < b: a, b = b, a while b: a, b = b, a % b return a k = int(eval(input())) sum = 0 for i in range(1, k + 1): for j in range(1, k + 1): gcd_ij = gcd(i, j) for k in range(1, k + 1): sum += gcd(gcd_ij, k) print(sum)
from math import gcd k = int(eval(input())) sum = 0 for i in range(1, k + 1): for j in range(1, k + 1): gcd_ij = gcd(i, j) for k in range(1, k + 1): sum += gcd(gcd_ij, k) print(sum)
false
43.75
[ "-def gcd(a, b):", "- if a < b:", "- a, b = b, a", "- while b:", "- a, b = b, a % b", "- return a", "-", "+from math import gcd" ]
false
0.177702
0.146084
1.216444
[ "s172778467", "s416037176" ]
u922449550
p02714
python
s721511424
s632947125
1,381
657
9,692
9,848
Accepted
Accepted
52.43
import itertools import bisect N = int(eval(input())) S = eval(input()) R_set = set() G_set = set() B_set = set() R = [] G = [] B = [] R_ids = [0] * N G_ids = [0] * N B_ids = [0] * N for i, s in enumerate(S): if s == 'R': R_set.add(i) R.append(i) R_ids[i] = 1 elif s == 'G': G_set.add(i) G.append(i) G_ids[i] = 1 else: B_set.add(i) B.append(i) B_ids[i] = 1 R_ids = list(itertools.accumulate(reversed(R_ids)))[::-1] G_ids = list(itertools.accumulate(reversed(G_ids)))[::-1] B_ids = list(itertools.accumulate(reversed(B_ids)))[::-1] ans = 0 for r_idx in R: start = bisect.bisect_left(G, r_idx) for g_idx in G[start:]: diff = g_idx - r_idx num = B_ids[g_idx] if g_idx+diff in B_set: num -= 1 ans += num start = bisect.bisect_left(B, r_idx) for b_idx in B[start:]: diff = b_idx - r_idx num = G_ids[b_idx] if b_idx+diff in G_set: num -= 1 ans += num for g_idx in G: start = bisect.bisect_left(R, g_idx) for r_idx in R[start:]: diff = r_idx - g_idx num = B_ids[r_idx] if r_idx+diff in B_set: num -= 1 ans += num start = bisect.bisect_left(B, g_idx) for b_idx in B[start:]: diff = b_idx - g_idx num = R_ids[b_idx] if b_idx+diff in R_set: num -= 1 ans += num for b_idx in B: start = bisect.bisect_left(G, b_idx) for g_idx in G[start:]: diff = g_idx - b_idx num = R_ids[g_idx] if g_idx+diff in R_set: num -= 1 ans += num start = bisect.bisect_left(R, b_idx) for r_idx in R[start:]: diff = r_idx - b_idx num = G_ids[r_idx] if r_idx+diff in G_set: num -= 1 ans += num print(ans)
import itertools import bisect N = int(eval(input())) S = eval(input()) R_set = set() G_set = set() B_set = set() R = [] G = [] B = [] R_ids = [0] * N G_ids = [0] * N B_ids = [0] * N for i, s in enumerate(S): if s == 'R': R_set.add(i) R.append(i) R_ids[i] = 1 elif s == 'G': G_set.add(i) G.append(i) G_ids[i] = 1 else: B_set.add(i) B.append(i) B_ids[i] = 1 R_ids = list(itertools.accumulate(reversed(R_ids)))[::-1] G_ids = list(itertools.accumulate(reversed(G_ids)))[::-1] B_ids = list(itertools.accumulate(reversed(B_ids)))[::-1] r = (R_set, R, R_ids) g = (G_set, G, G_ids) b = (B_set, B, B_ids) def count_rgb(r, g, b): res = 0 r_set, _r, r_ids = r g_set, _g, g_ids = g b_set, _b, b_ids = b for r_idx in _r: start = bisect.bisect_left(_g, r_idx) for g_idx in _g[start:]: diff = g_idx - r_idx num = b_ids[g_idx] if g_idx+diff in b_set: num -= 1 res += num return res ans = 0 for rgb in itertools.permutations((r, g, b), 3): ans += count_rgb(rgb[0], rgb[1], rgb[2]) print(ans)
88
59
1,962
1,234
import itertools import bisect N = int(eval(input())) S = eval(input()) R_set = set() G_set = set() B_set = set() R = [] G = [] B = [] R_ids = [0] * N G_ids = [0] * N B_ids = [0] * N for i, s in enumerate(S): if s == "R": R_set.add(i) R.append(i) R_ids[i] = 1 elif s == "G": G_set.add(i) G.append(i) G_ids[i] = 1 else: B_set.add(i) B.append(i) B_ids[i] = 1 R_ids = list(itertools.accumulate(reversed(R_ids)))[::-1] G_ids = list(itertools.accumulate(reversed(G_ids)))[::-1] B_ids = list(itertools.accumulate(reversed(B_ids)))[::-1] ans = 0 for r_idx in R: start = bisect.bisect_left(G, r_idx) for g_idx in G[start:]: diff = g_idx - r_idx num = B_ids[g_idx] if g_idx + diff in B_set: num -= 1 ans += num start = bisect.bisect_left(B, r_idx) for b_idx in B[start:]: diff = b_idx - r_idx num = G_ids[b_idx] if b_idx + diff in G_set: num -= 1 ans += num for g_idx in G: start = bisect.bisect_left(R, g_idx) for r_idx in R[start:]: diff = r_idx - g_idx num = B_ids[r_idx] if r_idx + diff in B_set: num -= 1 ans += num start = bisect.bisect_left(B, g_idx) for b_idx in B[start:]: diff = b_idx - g_idx num = R_ids[b_idx] if b_idx + diff in R_set: num -= 1 ans += num for b_idx in B: start = bisect.bisect_left(G, b_idx) for g_idx in G[start:]: diff = g_idx - b_idx num = R_ids[g_idx] if g_idx + diff in R_set: num -= 1 ans += num start = bisect.bisect_left(R, b_idx) for r_idx in R[start:]: diff = r_idx - b_idx num = G_ids[r_idx] if r_idx + diff in G_set: num -= 1 ans += num print(ans)
import itertools import bisect N = int(eval(input())) S = eval(input()) R_set = set() G_set = set() B_set = set() R = [] G = [] B = [] R_ids = [0] * N G_ids = [0] * N B_ids = [0] * N for i, s in enumerate(S): if s == "R": R_set.add(i) R.append(i) R_ids[i] = 1 elif s == "G": G_set.add(i) G.append(i) G_ids[i] = 1 else: B_set.add(i) B.append(i) B_ids[i] = 1 R_ids = list(itertools.accumulate(reversed(R_ids)))[::-1] G_ids = list(itertools.accumulate(reversed(G_ids)))[::-1] B_ids = list(itertools.accumulate(reversed(B_ids)))[::-1] r = (R_set, R, R_ids) g = (G_set, G, G_ids) b = (B_set, B, B_ids) def count_rgb(r, g, b): res = 0 r_set, _r, r_ids = r g_set, _g, g_ids = g b_set, _b, b_ids = b for r_idx in _r: start = bisect.bisect_left(_g, r_idx) for g_idx in _g[start:]: diff = g_idx - r_idx num = b_ids[g_idx] if g_idx + diff in b_set: num -= 1 res += num return res ans = 0 for rgb in itertools.permutations((r, g, b), 3): ans += count_rgb(rgb[0], rgb[1], rgb[2]) print(ans)
false
32.954545
[ "+r = (R_set, R, R_ids)", "+g = (G_set, G, G_ids)", "+b = (B_set, B, B_ids)", "+", "+", "+def count_rgb(r, g, b):", "+ res = 0", "+ r_set, _r, r_ids = r", "+ g_set, _g, g_ids = g", "+ b_set, _b, b_ids = b", "+ for r_idx in _r:", "+ start = bisect.bisect_left(_g, r_idx)", "+ for g_idx in _g[start:]:", "+ diff = g_idx - r_idx", "+ num = b_ids[g_idx]", "+ if g_idx + diff in b_set:", "+ num -= 1", "+ res += num", "+ return res", "+", "+", "-for r_idx in R:", "- start = bisect.bisect_left(G, r_idx)", "- for g_idx in G[start:]:", "- diff = g_idx - r_idx", "- num = B_ids[g_idx]", "- if g_idx + diff in B_set:", "- num -= 1", "- ans += num", "- start = bisect.bisect_left(B, r_idx)", "- for b_idx in B[start:]:", "- diff = b_idx - r_idx", "- num = G_ids[b_idx]", "- if b_idx + diff in G_set:", "- num -= 1", "- ans += num", "-for g_idx in G:", "- start = bisect.bisect_left(R, g_idx)", "- for r_idx in R[start:]:", "- diff = r_idx - g_idx", "- num = B_ids[r_idx]", "- if r_idx + diff in B_set:", "- num -= 1", "- ans += num", "- start = bisect.bisect_left(B, g_idx)", "- for b_idx in B[start:]:", "- diff = b_idx - g_idx", "- num = R_ids[b_idx]", "- if b_idx + diff in R_set:", "- num -= 1", "- ans += num", "-for b_idx in B:", "- start = bisect.bisect_left(G, b_idx)", "- for g_idx in G[start:]:", "- diff = g_idx - b_idx", "- num = R_ids[g_idx]", "- if g_idx + diff in R_set:", "- num -= 1", "- ans += num", "- start = bisect.bisect_left(R, b_idx)", "- for r_idx in R[start:]:", "- diff = r_idx - b_idx", "- num = G_ids[r_idx]", "- if r_idx + diff in G_set:", "- num -= 1", "- ans += num", "+for rgb in itertools.permutations((r, g, b), 3):", "+ ans += count_rgb(rgb[0], rgb[1], rgb[2])" ]
false
0.043765
0.043364
1.009259
[ "s721511424", "s632947125" ]
u437215432
p02713
python
s331841393
s422049532
1,982
1,207
10,380
9,084
Accepted
Accepted
39.1
# ABC162C from fractions import gcd from math import gcd k = int(eval(input())) total = 0 for a in range(1, k+1): for b in range(1, k+1): for c in range(1, k+1): # print(a, b, c, gcd(a, gcd(b, c))) total += gcd(a, gcd(b, c)) print(total)
from math import gcd k = int(eval(input())) total = 0 for a in range(1, k+1): for b in range(1, k+1): t = gcd(a, b) for c in range(1, k+1): # print(a, b, c, gcd(a, gcd(b, c))) total += gcd(t, c) print(total) # sample_02 1982 ms
13
11
282
277
# ABC162C from fractions import gcd from math import gcd k = int(eval(input())) total = 0 for a in range(1, k + 1): for b in range(1, k + 1): for c in range(1, k + 1): # print(a, b, c, gcd(a, gcd(b, c))) total += gcd(a, gcd(b, c)) print(total)
from math import gcd k = int(eval(input())) total = 0 for a in range(1, k + 1): for b in range(1, k + 1): t = gcd(a, b) for c in range(1, k + 1): # print(a, b, c, gcd(a, gcd(b, c))) total += gcd(t, c) print(total) # sample_02 1982 ms
false
15.384615
[ "-# ABC162C", "-from fractions import gcd", "+ t = gcd(a, b)", "- total += gcd(a, gcd(b, c))", "-print(total)", "+ total += gcd(t, c)", "+print(total) # sample_02 1982 ms" ]
false
0.05725
0.332934
0.171956
[ "s331841393", "s422049532" ]
u949876708
p02923
python
s317229269
s365438704
89
66
14,252
14,252
Accepted
Accepted
25.84
n=int(eval(input())) h=[int(i) for i in input().split()] c=0 d=c for i in range(n-1): if h[i]>=h[i+1]: c+=1 else: d=max([c,d]) c=0 print((max([c,d])))
n = int(eval(input())) L = list(map(int, input().split())) tmp = 0 result = 0 for i in range(n-1): if L[i] >= L[i+1]: tmp += 1 else: if tmp > result: result = tmp tmp = 0 if tmp > result: result = tmp print(result)
12
15
186
271
n = int(eval(input())) h = [int(i) for i in input().split()] c = 0 d = c for i in range(n - 1): if h[i] >= h[i + 1]: c += 1 else: d = max([c, d]) c = 0 print((max([c, d])))
n = int(eval(input())) L = list(map(int, input().split())) tmp = 0 result = 0 for i in range(n - 1): if L[i] >= L[i + 1]: tmp += 1 else: if tmp > result: result = tmp tmp = 0 if tmp > result: result = tmp print(result)
false
20
[ "-h = [int(i) for i in input().split()]", "-c = 0", "-d = c", "+L = list(map(int, input().split()))", "+tmp = 0", "+result = 0", "- if h[i] >= h[i + 1]:", "- c += 1", "+ if L[i] >= L[i + 1]:", "+ tmp += 1", "- d = max([c, d])", "- c = 0", "-print((max([c, d])))", "+ if tmp > result:", "+ result = tmp", "+ tmp = 0", "+if tmp > result:", "+ result = tmp", "+print(result)" ]
false
0.07091
0.115715
0.612802
[ "s317229269", "s365438704" ]
u095021077
p02945
python
s128251957
s981643815
182
17
38,256
2,940
Accepted
Accepted
90.66
temp=list(map(int, input().split())) print((max([temp[0]+temp[1], temp[0]-temp[1], temp[0]*temp[1]])))
A, B= list(map(int, input().split())) c= A+B d= A-B e= A*B f=max(c, d, e) print(f)
3
6
103
81
temp = list(map(int, input().split())) print((max([temp[0] + temp[1], temp[0] - temp[1], temp[0] * temp[1]])))
A, B = list(map(int, input().split())) c = A + B d = A - B e = A * B f = max(c, d, e) print(f)
false
50
[ "-temp = list(map(int, input().split()))", "-print((max([temp[0] + temp[1], temp[0] - temp[1], temp[0] * temp[1]])))", "+A, B = list(map(int, input().split()))", "+c = A + B", "+d = A - B", "+e = A * B", "+f = max(c, d, e)", "+print(f)" ]
false
0.04802
0.084422
0.568812
[ "s128251957", "s981643815" ]
u912115033
p03575
python
s662365611
s488767549
347
32
3,572
3,572
Accepted
Accepted
90.78
from copy import deepcopy def dfs(v): visited[v] = 1 ret = 1 for w in range(n): if [v, w] not in r: continue elif visited[w] == 1: continue ret += dfs(w) visited[w] = 1 return ret n,m = list(map(int,input().split())) x = [] cnt = 0 for _ in range(m): a,b = list(map(int,input().split())) x.append([a-1,b-1]) x.append([b-1, a-1]) for i in range(m): r = deepcopy(x) r.pop(2*i) r.pop(2*i) visited = [0]*n if dfs(0) == n: cnt += 1 print((m-cnt))
from copy import deepcopy def dfs(v): visited[v] = 1 ret = 1 for w in r[v]: if visited[w] == 1: continue ret += dfs(w) visited[w] = 1 return ret n,m = list(map(int,input().split())) x = [[] for _ in range(n)] x_list = [] cnt = 0 for _ in range(m): a,b = list(map(int,input().split())) x_list.append([a-1,b-1]) x[a-1].append(b-1) x[b-1].append(a-1) for i in range(m): r = deepcopy(x) r[x_list[i][0]].remove(x_list[i][1]) r[x_list[i][1]].remove(x_list[i][0]) visited = [0]*n if dfs(0) == n: cnt += 1 print((m-cnt))
31
31
573
628
from copy import deepcopy def dfs(v): visited[v] = 1 ret = 1 for w in range(n): if [v, w] not in r: continue elif visited[w] == 1: continue ret += dfs(w) visited[w] = 1 return ret n, m = list(map(int, input().split())) x = [] cnt = 0 for _ in range(m): a, b = list(map(int, input().split())) x.append([a - 1, b - 1]) x.append([b - 1, a - 1]) for i in range(m): r = deepcopy(x) r.pop(2 * i) r.pop(2 * i) visited = [0] * n if dfs(0) == n: cnt += 1 print((m - cnt))
from copy import deepcopy def dfs(v): visited[v] = 1 ret = 1 for w in r[v]: if visited[w] == 1: continue ret += dfs(w) visited[w] = 1 return ret n, m = list(map(int, input().split())) x = [[] for _ in range(n)] x_list = [] cnt = 0 for _ in range(m): a, b = list(map(int, input().split())) x_list.append([a - 1, b - 1]) x[a - 1].append(b - 1) x[b - 1].append(a - 1) for i in range(m): r = deepcopy(x) r[x_list[i][0]].remove(x_list[i][1]) r[x_list[i][1]].remove(x_list[i][0]) visited = [0] * n if dfs(0) == n: cnt += 1 print((m - cnt))
false
0
[ "- for w in range(n):", "- if [v, w] not in r:", "- continue", "- elif visited[w] == 1:", "+ for w in r[v]:", "+ if visited[w] == 1:", "-x = []", "+x = [[] for _ in range(n)]", "+x_list = []", "- x.append([a - 1, b - 1])", "- x.append([b - 1, a - 1])", "+ x_list.append([a - 1, b - 1])", "+ x[a - 1].append(b - 1)", "+ x[b - 1].append(a - 1)", "- r.pop(2 * i)", "- r.pop(2 * i)", "+ r[x_list[i][0]].remove(x_list[i][1])", "+ r[x_list[i][1]].remove(x_list[i][0])" ]
false
0.059115
0.058574
1.009232
[ "s662365611", "s488767549" ]
u076363290
p02657
python
s590766731
s126355360
28
25
9,060
9,028
Accepted
Accepted
10.71
a, b = list(map(int, input().split())) answer = a * b print(answer)
a, b = list(map(int, input().split())) print((a*b))
3
2
63
44
a, b = list(map(int, input().split())) answer = a * b print(answer)
a, b = list(map(int, input().split())) print((a * b))
false
33.333333
[ "-answer = a * b", "-print(answer)", "+print((a * b))" ]
false
0.081226
0.03645
2.22842
[ "s590766731", "s126355360" ]
u392029857
p03107
python
s398495511
s825625893
24
19
3,956
3,188
Accepted
Accepted
20.83
s = list(eval(input())) print((len(s) - (abs(s.count('0')-s.count('1')))))
s = eval(input()) print((2*min(s.count('1'),s.count('0'))))
2
2
67
52
s = list(eval(input())) print((len(s) - (abs(s.count("0") - s.count("1")))))
s = eval(input()) print((2 * min(s.count("1"), s.count("0"))))
false
0
[ "-s = list(eval(input()))", "-print((len(s) - (abs(s.count(\"0\") - s.count(\"1\")))))", "+s = eval(input())", "+print((2 * min(s.count(\"1\"), s.count(\"0\"))))" ]
false
0.101486
0.03821
2.655971
[ "s398495511", "s825625893" ]
u025501820
p02954
python
s729029296
s174925134
211
144
14,036
11,340
Accepted
Accepted
31.75
import math from collections import deque S = eval(input()) L_kyoukai = [] R_kyoukai = [0] flag = False for i in range(1, len(S)): if flag is False and S[i] == "L": L_kyoukai.append(i) R_kyoukai.append(i - 1) flag = True if flag is True and S[i] == "R": L_kyoukai.append(i - 1) R_kyoukai.append(i) flag = False ans = [] L_kyoukai.append(len(S) - 1) r_diff = [R_kyoukai[i + 1] - R_kyoukai[i] + 1 for i in range(0, len(R_kyoukai), 2)] l_diff = [L_kyoukai[i + 1] - L_kyoukai[i] + 1 for i in range(0, len(L_kyoukai), 2)] for r, l in zip(r_diff, l_diff): tmp_1 = math.ceil(r / 2) tmp_2 = math.ceil(l / 2) ans.append(tmp_1 + l - tmp_2) ans.append(r - tmp_1 + tmp_2) q = deque(ans) answer = "" for i in range(len(S)): if 1 <= i <= len(S) - 2: if (S[i] == "L" and S[i - 1] == "R") or (S[i] == "R" and S[ i + 1] == "L"): answer += str(q.popleft()) answer += " " else: answer += "0 " elif i == 0: if S[i + 1] == "L": answer += str(q.popleft()) answer += " " else: answer += "0 " elif i == len(S) - 1: if S[i - 1] == "R": answer += str(q.popleft()) answer += " " else: answer += "0 " print(answer)
import math from collections import deque S = eval(input()) ans = [0 for _ in range(len(S))] cnt = 0 for i in range(len(S) - 1): if S[i] == "R": if S[i + 1] == "R": cnt += 1 else: cnt += 1 ans[i] += math.ceil(cnt / 2) ans[i + 1] += cnt - math.ceil(cnt / 2) cnt = 0 ans = ans[:: -1] S = S[:: -1] cnt = 0 for i in range(len(S) - 1): if S[i] == "L": if S[i + 1] == "L": cnt += 1 else: cnt += 1 ans[i] += math.ceil(cnt / 2) ans[i + 1] += cnt - math.ceil(cnt / 2) cnt = 0 ans = ans[:: -1] print((" ".join(map(str, ans))))
48
28
1,381
695
import math from collections import deque S = eval(input()) L_kyoukai = [] R_kyoukai = [0] flag = False for i in range(1, len(S)): if flag is False and S[i] == "L": L_kyoukai.append(i) R_kyoukai.append(i - 1) flag = True if flag is True and S[i] == "R": L_kyoukai.append(i - 1) R_kyoukai.append(i) flag = False ans = [] L_kyoukai.append(len(S) - 1) r_diff = [R_kyoukai[i + 1] - R_kyoukai[i] + 1 for i in range(0, len(R_kyoukai), 2)] l_diff = [L_kyoukai[i + 1] - L_kyoukai[i] + 1 for i in range(0, len(L_kyoukai), 2)] for r, l in zip(r_diff, l_diff): tmp_1 = math.ceil(r / 2) tmp_2 = math.ceil(l / 2) ans.append(tmp_1 + l - tmp_2) ans.append(r - tmp_1 + tmp_2) q = deque(ans) answer = "" for i in range(len(S)): if 1 <= i <= len(S) - 2: if (S[i] == "L" and S[i - 1] == "R") or (S[i] == "R" and S[i + 1] == "L"): answer += str(q.popleft()) answer += " " else: answer += "0 " elif i == 0: if S[i + 1] == "L": answer += str(q.popleft()) answer += " " else: answer += "0 " elif i == len(S) - 1: if S[i - 1] == "R": answer += str(q.popleft()) answer += " " else: answer += "0 " print(answer)
import math from collections import deque S = eval(input()) ans = [0 for _ in range(len(S))] cnt = 0 for i in range(len(S) - 1): if S[i] == "R": if S[i + 1] == "R": cnt += 1 else: cnt += 1 ans[i] += math.ceil(cnt / 2) ans[i + 1] += cnt - math.ceil(cnt / 2) cnt = 0 ans = ans[::-1] S = S[::-1] cnt = 0 for i in range(len(S) - 1): if S[i] == "L": if S[i + 1] == "L": cnt += 1 else: cnt += 1 ans[i] += math.ceil(cnt / 2) ans[i + 1] += cnt - math.ceil(cnt / 2) cnt = 0 ans = ans[::-1] print((" ".join(map(str, ans))))
false
41.666667
[ "-L_kyoukai = []", "-R_kyoukai = [0]", "-flag = False", "-for i in range(1, len(S)):", "- if flag is False and S[i] == \"L\":", "- L_kyoukai.append(i)", "- R_kyoukai.append(i - 1)", "- flag = True", "- if flag is True and S[i] == \"R\":", "- L_kyoukai.append(i - 1)", "- R_kyoukai.append(i)", "- flag = False", "-ans = []", "-L_kyoukai.append(len(S) - 1)", "-r_diff = [R_kyoukai[i + 1] - R_kyoukai[i] + 1 for i in range(0, len(R_kyoukai), 2)]", "-l_diff = [L_kyoukai[i + 1] - L_kyoukai[i] + 1 for i in range(0, len(L_kyoukai), 2)]", "-for r, l in zip(r_diff, l_diff):", "- tmp_1 = math.ceil(r / 2)", "- tmp_2 = math.ceil(l / 2)", "- ans.append(tmp_1 + l - tmp_2)", "- ans.append(r - tmp_1 + tmp_2)", "-q = deque(ans)", "-answer = \"\"", "-for i in range(len(S)):", "- if 1 <= i <= len(S) - 2:", "- if (S[i] == \"L\" and S[i - 1] == \"R\") or (S[i] == \"R\" and S[i + 1] == \"L\"):", "- answer += str(q.popleft())", "- answer += \" \"", "+ans = [0 for _ in range(len(S))]", "+cnt = 0", "+for i in range(len(S) - 1):", "+ if S[i] == \"R\":", "+ if S[i + 1] == \"R\":", "+ cnt += 1", "- answer += \"0 \"", "- elif i == 0:", "+ cnt += 1", "+ ans[i] += math.ceil(cnt / 2)", "+ ans[i + 1] += cnt - math.ceil(cnt / 2)", "+ cnt = 0", "+ans = ans[::-1]", "+S = S[::-1]", "+cnt = 0", "+for i in range(len(S) - 1):", "+ if S[i] == \"L\":", "- answer += str(q.popleft())", "- answer += \" \"", "+ cnt += 1", "- answer += \"0 \"", "- elif i == len(S) - 1:", "- if S[i - 1] == \"R\":", "- answer += str(q.popleft())", "- answer += \" \"", "- else:", "- answer += \"0 \"", "-print(answer)", "+ cnt += 1", "+ ans[i] += math.ceil(cnt / 2)", "+ ans[i + 1] += cnt - math.ceil(cnt / 2)", "+ cnt = 0", "+ans = ans[::-1]", "+print((\" \".join(map(str, ans))))" ]
false
0.047063
0.127937
0.367861
[ "s729029296", "s174925134" ]
u401487574
p02596
python
s561519587
s476987426
405
172
68,220
9,412
Accepted
Accepted
57.53
ma = lambda :map(int,input().split()) ni = lambda:int(input()) yn = lambda fl:print("Yes") if fl else print("No") import collections import math import itertools import heapq as hq k = ni() a = 0 for i in range(10**6): a=(a+7*pow(10,i,k))%k if a== 0: print(i+1) break else: print(-1)
ma = lambda :map(int,input().split()) ni = lambda:int(input()) yn = lambda fl:print("Yes") if fl else print("No") import collections import math import itertools import heapq as hq k = ni() if k%2==0 or k%5==0: print(-1) exit() if k%7==0: L=9*k//7 else: L=9*k tmp=1 for i in range(1,10**6): tmp = tmp*10 %L if tmp==1: print(i) break else: print(-1)
16
24
327
417
ma = lambda: map(int, input().split()) ni = lambda: int(input()) yn = lambda fl: print("Yes") if fl else print("No") import collections import math import itertools import heapq as hq k = ni() a = 0 for i in range(10**6): a = (a + 7 * pow(10, i, k)) % k if a == 0: print(i + 1) break else: print(-1)
ma = lambda: map(int, input().split()) ni = lambda: int(input()) yn = lambda fl: print("Yes") if fl else print("No") import collections import math import itertools import heapq as hq k = ni() if k % 2 == 0 or k % 5 == 0: print(-1) exit() if k % 7 == 0: L = 9 * k // 7 else: L = 9 * k tmp = 1 for i in range(1, 10**6): tmp = tmp * 10 % L if tmp == 1: print(i) break else: print(-1)
false
33.333333
[ "-a = 0", "-for i in range(10**6):", "- a = (a + 7 * pow(10, i, k)) % k", "- if a == 0:", "- print(i + 1)", "+if k % 2 == 0 or k % 5 == 0:", "+ print(-1)", "+ exit()", "+if k % 7 == 0:", "+ L = 9 * k // 7", "+else:", "+ L = 9 * k", "+tmp = 1", "+for i in range(1, 10**6):", "+ tmp = tmp * 10 % L", "+ if tmp == 1:", "+ print(i)" ]
false
0.560756
0.088152
6.361266
[ "s561519587", "s476987426" ]
u390901183
p02708
python
s079487408
s401745953
185
152
9,948
9,828
Accepted
Accepted
17.84
from collections import deque import sys import bisect import math import itertools from queue import deque from math import gcd INF = float('inf') mod = 10**9+7 eps = 10**-7 def inp(): return int(sys.stdin.readline()) def inp_list(): return list(map(int, sys.stdin.readline().split())) def lcm(x, y): return (x * y) // gcd(x, y) N, K = inp_list() ans = 0 for k in range(K, N + 2): # M => 和の最大値, m => 和の最小値, k について和としてありえるものの個数は M - m + 1 M = ( N * (N + 1) // 2 - (N - k) * (N + 1 - k) // 2 ) % mod m = k * (k - 1) // 2 % mod ans += (M - m + 1) % mod print((ans % mod))
from collections import deque import sys import bisect import math import itertools from queue import deque from math import gcd INF = float('inf') mod = 10**9+7 eps = 10**-7 def inp(): return int(sys.stdin.readline()) def inp_list(): return list(map(int, sys.stdin.readline().split())) def lcm(x, y): return (x * y) // gcd(x, y) N, K = inp_list() ans = 0 for k in range(K, N + 2): # M => 和の最大値, m => 和の最小値, k について和としてありえるものの個数は M - m + 1 M = ( N * (N + 1) // 2 - (N - k) * (N + 1 - k) // 2 ) m = k * (k - 1) // 2 ans += (M - m + 1) print((ans % mod))
27
27
618
600
from collections import deque import sys import bisect import math import itertools from queue import deque from math import gcd INF = float("inf") mod = 10**9 + 7 eps = 10**-7 def inp(): return int(sys.stdin.readline()) def inp_list(): return list(map(int, sys.stdin.readline().split())) def lcm(x, y): return (x * y) // gcd(x, y) N, K = inp_list() ans = 0 for k in range(K, N + 2): # M => 和の最大値, m => 和の最小値, k について和としてありえるものの個数は M - m + 1 M = (N * (N + 1) // 2 - (N - k) * (N + 1 - k) // 2) % mod m = k * (k - 1) // 2 % mod ans += (M - m + 1) % mod print((ans % mod))
from collections import deque import sys import bisect import math import itertools from queue import deque from math import gcd INF = float("inf") mod = 10**9 + 7 eps = 10**-7 def inp(): return int(sys.stdin.readline()) def inp_list(): return list(map(int, sys.stdin.readline().split())) def lcm(x, y): return (x * y) // gcd(x, y) N, K = inp_list() ans = 0 for k in range(K, N + 2): # M => 和の最大値, m => 和の最小値, k について和としてありえるものの個数は M - m + 1 M = N * (N + 1) // 2 - (N - k) * (N + 1 - k) // 2 m = k * (k - 1) // 2 ans += M - m + 1 print((ans % mod))
false
0
[ "- M = (N * (N + 1) // 2 - (N - k) * (N + 1 - k) // 2) % mod", "- m = k * (k - 1) // 2 % mod", "- ans += (M - m + 1) % mod", "+ M = N * (N + 1) // 2 - (N - k) * (N + 1 - k) // 2", "+ m = k * (k - 1) // 2", "+ ans += M - m + 1" ]
false
0.08703
0.105148
0.827697
[ "s079487408", "s401745953" ]
u227020436
p02702
python
s354040062
s298997351
169
104
9,676
77,744
Accepted
Accepted
38.46
# D - Multiple of 2019 from collections import Counter s = eval(input()) count = 0 counter = Counter([0]) suffix = 0 pow = 1 for i in range(len(s) - 1, -1, -1): suffix = (int(s[i]) * pow + suffix) % 2019 pow = pow * 10 % 2019 count += counter[suffix] counter[suffix] += 1 print(count)
# D - Multiple of 2019 from collections import Counter s = eval(input()) r = [0] for d in map(int, s): r.append((r[-1] * 10 + d) % 2019) e = 1 for i in range(len(r) - 1, -1, -1): r[i] = r[i] * e % 2019 e = e * 10 % 2019 def choose2(x): return x * (x - 1) // 2 counter = Counter(r) print((sum(choose2(counter[i]) for i in counter)))
18
20
317
364
# D - Multiple of 2019 from collections import Counter s = eval(input()) count = 0 counter = Counter([0]) suffix = 0 pow = 1 for i in range(len(s) - 1, -1, -1): suffix = (int(s[i]) * pow + suffix) % 2019 pow = pow * 10 % 2019 count += counter[suffix] counter[suffix] += 1 print(count)
# D - Multiple of 2019 from collections import Counter s = eval(input()) r = [0] for d in map(int, s): r.append((r[-1] * 10 + d) % 2019) e = 1 for i in range(len(r) - 1, -1, -1): r[i] = r[i] * e % 2019 e = e * 10 % 2019 def choose2(x): return x * (x - 1) // 2 counter = Counter(r) print((sum(choose2(counter[i]) for i in counter)))
false
10
[ "-count = 0", "-counter = Counter([0])", "-suffix = 0", "-pow = 1", "-for i in range(len(s) - 1, -1, -1):", "- suffix = (int(s[i]) * pow + suffix) % 2019", "- pow = pow * 10 % 2019", "- count += counter[suffix]", "- counter[suffix] += 1", "-print(count)", "+r = [0]", "+for d in map(int, s):", "+ r.append((r[-1] * 10 + d) % 2019)", "+e = 1", "+for i in range(len(r) - 1, -1, -1):", "+ r[i] = r[i] * e % 2019", "+ e = e * 10 % 2019", "+", "+", "+def choose2(x):", "+ return x * (x - 1) // 2", "+", "+", "+counter = Counter(r)", "+print((sum(choose2(counter[i]) for i in counter)))" ]
false
0.054341
0.035768
1.519268
[ "s354040062", "s298997351" ]
u644907318
p03472
python
s166133794
s319480384
632
232
63,064
96,840
Accepted
Accepted
63.29
from bisect import bisect_right N,H = list(map(int,input().split())) A = [] B = [] for _ in range(N): a,b = list(map(int,input().split())) A.append(a) B.append(b) A = sorted(A,reverse=True) B = sorted(B) a = A[0] ind = bisect_right(B,a) cnt = 0 flag = 0 for i in range(N-1,ind-1,-1): H -= B[i] cnt += 1 if H<=0: flag = 1 break if flag==0: k = H//a if H%a>0: k += 1 cnt += k print(cnt)
import math N,H = list(map(int,input().split())) A = [list(map(int,input().split())) for _ in range(N)] a = 0 for i in range(N): if A[i][0]>a: a = A[i][0] B = [] for i in range(N): if A[i][1]>a: B.append(A[i][1]) B = sorted(B,reverse=True) totB = sum(B) if totB>=H: flag = 0 tot = 0 for i in range(len(B)): tot += B[i] if tot>=H: flag = i+1 break print(flag) else: h = H-totB n = len(B)+math.ceil(h/a) print(n)
26
26
457
521
from bisect import bisect_right N, H = list(map(int, input().split())) A = [] B = [] for _ in range(N): a, b = list(map(int, input().split())) A.append(a) B.append(b) A = sorted(A, reverse=True) B = sorted(B) a = A[0] ind = bisect_right(B, a) cnt = 0 flag = 0 for i in range(N - 1, ind - 1, -1): H -= B[i] cnt += 1 if H <= 0: flag = 1 break if flag == 0: k = H // a if H % a > 0: k += 1 cnt += k print(cnt)
import math N, H = list(map(int, input().split())) A = [list(map(int, input().split())) for _ in range(N)] a = 0 for i in range(N): if A[i][0] > a: a = A[i][0] B = [] for i in range(N): if A[i][1] > a: B.append(A[i][1]) B = sorted(B, reverse=True) totB = sum(B) if totB >= H: flag = 0 tot = 0 for i in range(len(B)): tot += B[i] if tot >= H: flag = i + 1 break print(flag) else: h = H - totB n = len(B) + math.ceil(h / a) print(n)
false
0
[ "-from bisect import bisect_right", "+import math", "-A = []", "+A = [list(map(int, input().split())) for _ in range(N)]", "+a = 0", "+for i in range(N):", "+ if A[i][0] > a:", "+ a = A[i][0]", "-for _ in range(N):", "- a, b = list(map(int, input().split()))", "- A.append(a)", "- B.append(b)", "-A = sorted(A, reverse=True)", "-B = sorted(B)", "-a = A[0]", "-ind = bisect_right(B, a)", "-cnt = 0", "-flag = 0", "-for i in range(N - 1, ind - 1, -1):", "- H -= B[i]", "- cnt += 1", "- if H <= 0:", "- flag = 1", "- break", "-if flag == 0:", "- k = H // a", "- if H % a > 0:", "- k += 1", "- cnt += k", "-print(cnt)", "+for i in range(N):", "+ if A[i][1] > a:", "+ B.append(A[i][1])", "+B = sorted(B, reverse=True)", "+totB = sum(B)", "+if totB >= H:", "+ flag = 0", "+ tot = 0", "+ for i in range(len(B)):", "+ tot += B[i]", "+ if tot >= H:", "+ flag = i + 1", "+ break", "+ print(flag)", "+else:", "+ h = H - totB", "+ n = len(B) + math.ceil(h / a)", "+ print(n)" ]
false
0.079669
0.037316
2.135006
[ "s166133794", "s319480384" ]
u564902833
p02996
python
s225406902
s701700777
1,517
1,272
138,064
112,472
Accepted
Accepted
16.15
N = int(eval(input())) A, B = ( list(zip(*(list(map(int, input().split())) for _ in range(N)))) if N else ((), ()) ) a, b = list(zip(*sorted(zip(A, B), key=lambda t: t[1]))) t = 0 ans = 'Yes' for x, y in zip(a, b): t += x if t > y: ans = 'No' print(ans)
from functools import reduce # 出力 N = int(eval(input())) A, B = ( list(zip(*(list(map(int, input().split())) for _ in range(N)))) if N else ((), ()) ) # 〆切時刻が小さい順にgreedyに仕事を処理する ans, _ = reduce( lambda acc, t: ( 'Yes' if acc[0] == 'Yes' and acc[1] + t[0] <= t[1] else 'No', acc[1] + t[0] ), sorted(zip(A, B), key=lambda t: t[1]), ('Yes', 0) ) # 出力 print(ans)
16
23
272
438
N = int(eval(input())) A, B = ( list(zip(*(list(map(int, input().split())) for _ in range(N)))) if N else ((), ()) ) a, b = list(zip(*sorted(zip(A, B), key=lambda t: t[1]))) t = 0 ans = "Yes" for x, y in zip(a, b): t += x if t > y: ans = "No" print(ans)
from functools import reduce # 出力 N = int(eval(input())) A, B = ( list(zip(*(list(map(int, input().split())) for _ in range(N)))) if N else ((), ()) ) # 〆切時刻が小さい順にgreedyに仕事を処理する ans, _ = reduce( lambda acc, t: ( "Yes" if acc[0] == "Yes" and acc[1] + t[0] <= t[1] else "No", acc[1] + t[0], ), sorted(zip(A, B), key=lambda t: t[1]), ("Yes", 0), ) # 出力 print(ans)
false
30.434783
[ "+from functools import reduce", "+", "+# 出力", "-a, b = list(zip(*sorted(zip(A, B), key=lambda t: t[1])))", "-t = 0", "-ans = \"Yes\"", "-for x, y in zip(a, b):", "- t += x", "- if t > y:", "- ans = \"No\"", "+# 〆切時刻が小さい順にgreedyに仕事を処理する", "+ans, _ = reduce(", "+ lambda acc, t: (", "+ \"Yes\" if acc[0] == \"Yes\" and acc[1] + t[0] <= t[1] else \"No\",", "+ acc[1] + t[0],", "+ ),", "+ sorted(zip(A, B), key=lambda t: t[1]),", "+ (\"Yes\", 0),", "+)", "+# 出力" ]
false
0.046274
0.049433
0.936081
[ "s225406902", "s701700777" ]
u592547545
p03013
python
s979305746
s665756013
197
146
30,272
14,380
Accepted
Accepted
25.89
def readinput(): n,m=list(map(int,input().split())) a=[] for _ in range(m): a.append(int(eval(input()))) return n,a def main(n,a): MOD=10**9+7 nroute=[0]*(n+2) nroute[0]=0 nroute[1]=1 nroute[2]=1 for i in range(3,n+2): nroute[i]=(nroute[i-1]+nroute[i-2])%MOD #print(nroute) subn=[] i=0 for j in a: subn.append((i,j-1)) i=j+1 subn.append((i,n)) #print(subn) nways=1 for i,j in subn: l=j-i+1 nways=nways*nroute[l]%MOD return nways if __name__=='__main__': n,a=readinput() ans=main(n,a) print(ans)
import sys INFTY=sys.maxsize def readinput(): n,m=list(map(int,input().split())) a=[] for _ in range(m): a.append(int(eval(input()))) return n,m,a def main(n,m,a): MOD=10**9+7 dp=[0]*(n+3) dp[0]=1 ia=0 for i in range(n+1): if ia<m and i==a[ia]: ia+=1 #print(ia) continue dp[i+1]=(dp[i+1]+dp[i])%MOD dp[i+2]=(dp[i+2]+dp[i])%MOD #print(dp) return dp[n] if __name__=='__main__': n,m,a=readinput() ans=main(n,m,a) print(ans)
38
30
673
576
def readinput(): n, m = list(map(int, input().split())) a = [] for _ in range(m): a.append(int(eval(input()))) return n, a def main(n, a): MOD = 10**9 + 7 nroute = [0] * (n + 2) nroute[0] = 0 nroute[1] = 1 nroute[2] = 1 for i in range(3, n + 2): nroute[i] = (nroute[i - 1] + nroute[i - 2]) % MOD # print(nroute) subn = [] i = 0 for j in a: subn.append((i, j - 1)) i = j + 1 subn.append((i, n)) # print(subn) nways = 1 for i, j in subn: l = j - i + 1 nways = nways * nroute[l] % MOD return nways if __name__ == "__main__": n, a = readinput() ans = main(n, a) print(ans)
import sys INFTY = sys.maxsize def readinput(): n, m = list(map(int, input().split())) a = [] for _ in range(m): a.append(int(eval(input()))) return n, m, a def main(n, m, a): MOD = 10**9 + 7 dp = [0] * (n + 3) dp[0] = 1 ia = 0 for i in range(n + 1): if ia < m and i == a[ia]: ia += 1 # print(ia) continue dp[i + 1] = (dp[i + 1] + dp[i]) % MOD dp[i + 2] = (dp[i + 2] + dp[i]) % MOD # print(dp) return dp[n] if __name__ == "__main__": n, m, a = readinput() ans = main(n, m, a) print(ans)
false
21.052632
[ "+import sys", "+", "+INFTY = sys.maxsize", "+", "+", "- return n, a", "+ return n, m, a", "-def main(n, a):", "+def main(n, m, a):", "- nroute = [0] * (n + 2)", "- nroute[0] = 0", "- nroute[1] = 1", "- nroute[2] = 1", "- for i in range(3, n + 2):", "- nroute[i] = (nroute[i - 1] + nroute[i - 2]) % MOD", "- # print(nroute)", "- subn = []", "- i = 0", "- for j in a:", "- subn.append((i, j - 1))", "- i = j + 1", "- subn.append((i, n))", "- # print(subn)", "- nways = 1", "- for i, j in subn:", "- l = j - i + 1", "- nways = nways * nroute[l] % MOD", "- return nways", "+ dp = [0] * (n + 3)", "+ dp[0] = 1", "+ ia = 0", "+ for i in range(n + 1):", "+ if ia < m and i == a[ia]:", "+ ia += 1", "+ # print(ia)", "+ continue", "+ dp[i + 1] = (dp[i + 1] + dp[i]) % MOD", "+ dp[i + 2] = (dp[i + 2] + dp[i]) % MOD", "+ # print(dp)", "+ return dp[n]", "- n, a = readinput()", "- ans = main(n, a)", "+ n, m, a = readinput()", "+ ans = main(n, m, a)" ]
false
0.045574
0.040802
1.116965
[ "s979305746", "s665756013" ]
u036104576
p02815
python
s404626652
s415153054
535
322
50,812
31,612
Accepted
Accepted
39.81
import sys import itertools # import numpy as np import time import math import heapq from collections import defaultdict from collections import Counter sys.setrecursionlimit(10 ** 7) INF = 10 ** 18 MOD = 10 ** 9 + 7 read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines # map(int, input().split()) import sys import itertools # import numpy as np import time import math from heapq import heappop, heappush from collections import defaultdict from collections import Counter from collections import deque sys.setrecursionlimit(10 ** 7) INF = 10 ** 18 MOD = 10 ** 9 + 7 read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines # map(int, input().split()) N = int(eval(input())) C = list(sorted(map(int, input().split()), reverse=True)) MAX = 2 * 10 ** 5 + 5 MOD = 10 ** 9 + 7 fac = [0 for i in range(MAX)] finv = [0 for i in range(MAX)] inv = [0 for i in range(MAX)] def comInit(mod): fac[0], fac[1] = 1, 1 finv[0], finv[1] = 1, 1 inv[1] = 1 for i in range(2, MAX): fac[i] = fac[i - 1] * i % mod inv[i] = mod - inv[mod % i] * (mod // i) % mod finv[i] = finv[i - 1] * inv[i] % mod def com(n, r, mod): if n < r: return 0 if n < 0 or r < 0: return 0 return fac[n] * (finv[r] * finv[n - r] % mod) % mod def p(n, r, mod): return fac[n] * finv[n - r] % mod comInit(MOD) ans = 0 pow_list = [1] * (N + 1) for i in range(1, N + 1): pow_list[i] = (2 * pow_list[i - 1]) % MOD base = pow_list[N] for i, c in enumerate(C): now = pow_list[N - i - 1] tot = 0 if i >= 1: tot = pow_list[i] + i * pow_list[i - 1] else: tot = pow_list[i] ans += (tot * now * c) % MOD ans %= MOD print((ans * base % MOD))
MOD = 10 ** 9 + 7 N = int(eval(input())) C = list(sorted(map(int, input().split()), reverse=True)) ans = 0 pow_list = [1] * (N + 1) for i in range(1, N + 1): pow_list[i] = (2 * pow_list[i - 1]) % MOD base = pow_list[N] # 基本戦略:コストが一番高いものを一番最後に変更する for i, c in enumerate(C): now = pow_list[N - i - 1] tot = 0 # コストがi番目に大きい値は、最後からi番目に変更を行うので # 左からi-bitまでに何個1が立ったかで加算回数が決まる if i >= 1: tot = pow_list[i] + i * pow_list[i - 1] else: tot = pow_list[i] ans += (tot * now * c) % MOD ans %= MOD print((ans * base % MOD))
86
23
1,900
578
import sys import itertools # import numpy as np import time import math import heapq from collections import defaultdict from collections import Counter sys.setrecursionlimit(10**7) INF = 10**18 MOD = 10**9 + 7 read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines # map(int, input().split()) import sys import itertools # import numpy as np import time import math from heapq import heappop, heappush from collections import defaultdict from collections import Counter from collections import deque sys.setrecursionlimit(10**7) INF = 10**18 MOD = 10**9 + 7 read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines # map(int, input().split()) N = int(eval(input())) C = list(sorted(map(int, input().split()), reverse=True)) MAX = 2 * 10**5 + 5 MOD = 10**9 + 7 fac = [0 for i in range(MAX)] finv = [0 for i in range(MAX)] inv = [0 for i in range(MAX)] def comInit(mod): fac[0], fac[1] = 1, 1 finv[0], finv[1] = 1, 1 inv[1] = 1 for i in range(2, MAX): fac[i] = fac[i - 1] * i % mod inv[i] = mod - inv[mod % i] * (mod // i) % mod finv[i] = finv[i - 1] * inv[i] % mod def com(n, r, mod): if n < r: return 0 if n < 0 or r < 0: return 0 return fac[n] * (finv[r] * finv[n - r] % mod) % mod def p(n, r, mod): return fac[n] * finv[n - r] % mod comInit(MOD) ans = 0 pow_list = [1] * (N + 1) for i in range(1, N + 1): pow_list[i] = (2 * pow_list[i - 1]) % MOD base = pow_list[N] for i, c in enumerate(C): now = pow_list[N - i - 1] tot = 0 if i >= 1: tot = pow_list[i] + i * pow_list[i - 1] else: tot = pow_list[i] ans += (tot * now * c) % MOD ans %= MOD print((ans * base % MOD))
MOD = 10**9 + 7 N = int(eval(input())) C = list(sorted(map(int, input().split()), reverse=True)) ans = 0 pow_list = [1] * (N + 1) for i in range(1, N + 1): pow_list[i] = (2 * pow_list[i - 1]) % MOD base = pow_list[N] # 基本戦略:コストが一番高いものを一番最後に変更する for i, c in enumerate(C): now = pow_list[N - i - 1] tot = 0 # コストがi番目に大きい値は、最後からi番目に変更を行うので # 左からi-bitまでに何個1が立ったかで加算回数が決まる if i >= 1: tot = pow_list[i] + i * pow_list[i - 1] else: tot = pow_list[i] ans += (tot * now * c) % MOD ans %= MOD print((ans * base % MOD))
false
73.255814
[ "-import sys", "-import itertools", "-", "-# import numpy as np", "-import time", "-import math", "-import heapq", "-from collections import defaultdict", "-from collections import Counter", "-", "-sys.setrecursionlimit(10**7)", "-INF = 10**18", "-read = sys.stdin.buffer.read", "-readline = sys.stdin.buffer.readline", "-readlines = sys.stdin.buffer.readlines", "-# map(int, input().split())", "-import sys", "-import itertools", "-", "-# import numpy as np", "-import time", "-import math", "-from heapq import heappop, heappush", "-from collections import defaultdict", "-from collections import Counter", "-from collections import deque", "-", "-sys.setrecursionlimit(10**7)", "-INF = 10**18", "-MOD = 10**9 + 7", "-read = sys.stdin.buffer.read", "-readline = sys.stdin.buffer.readline", "-readlines = sys.stdin.buffer.readlines", "-# map(int, input().split())", "-MAX = 2 * 10**5 + 5", "-MOD = 10**9 + 7", "-fac = [0 for i in range(MAX)]", "-finv = [0 for i in range(MAX)]", "-inv = [0 for i in range(MAX)]", "-", "-", "-def comInit(mod):", "- fac[0], fac[1] = 1, 1", "- finv[0], finv[1] = 1, 1", "- inv[1] = 1", "- for i in range(2, MAX):", "- fac[i] = fac[i - 1] * i % mod", "- inv[i] = mod - inv[mod % i] * (mod // i) % mod", "- finv[i] = finv[i - 1] * inv[i] % mod", "-", "-", "-def com(n, r, mod):", "- if n < r:", "- return 0", "- if n < 0 or r < 0:", "- return 0", "- return fac[n] * (finv[r] * finv[n - r] % mod) % mod", "-", "-", "-def p(n, r, mod):", "- return fac[n] * finv[n - r] % mod", "-", "-", "-comInit(MOD)", "+# 基本戦略:コストが一番高いものを一番最後に変更する", "+ # コストがi番目に大きい値は、最後からi番目に変更を行うので", "+ # 左からi-bitまでに何個1が立ったかで加算回数が決まる" ]
false
0.510595
0.036761
13.889493
[ "s404626652", "s415153054" ]
u626337957
p03701
python
s700433615
s783669780
143
117
3,188
3,060
Accepted
Accepted
18.18
N = int(eval(input())) nums=[int(eval(input())) for _ in range(N)] sum_num = sum(nums) dp = [0] * (sum_num+1) dp[0] = 1 for num in nums: for i in range(sum_num+1)[::-1]: if dp[i] == 1 and i + num <= sum_num: dp[i+num] = 1 ans = 0 for i in range(sum_num+1): if dp[i] == 1 and i%10 != 0: ans = i print(ans)
N = int(eval(input())) nums=[int(eval(input())) for _ in range(N)] sum_num = sum(nums) dp = [0] * (sum_num+1) dp[0] = 1 for num in nums: for i in range(sum_num+1)[::-1]: if dp[i] == 1: dp[i+num] = 1 ans = 0 for i in range(sum_num+1): if dp[i] == 1 and i%10 != 0: ans = i print(ans)
14
14
324
301
N = int(eval(input())) nums = [int(eval(input())) for _ in range(N)] sum_num = sum(nums) dp = [0] * (sum_num + 1) dp[0] = 1 for num in nums: for i in range(sum_num + 1)[::-1]: if dp[i] == 1 and i + num <= sum_num: dp[i + num] = 1 ans = 0 for i in range(sum_num + 1): if dp[i] == 1 and i % 10 != 0: ans = i print(ans)
N = int(eval(input())) nums = [int(eval(input())) for _ in range(N)] sum_num = sum(nums) dp = [0] * (sum_num + 1) dp[0] = 1 for num in nums: for i in range(sum_num + 1)[::-1]: if dp[i] == 1: dp[i + num] = 1 ans = 0 for i in range(sum_num + 1): if dp[i] == 1 and i % 10 != 0: ans = i print(ans)
false
0
[ "- if dp[i] == 1 and i + num <= sum_num:", "+ if dp[i] == 1:" ]
false
0.038605
0.033114
1.165803
[ "s700433615", "s783669780" ]
u895515293
p02720
python
s717987979
s344037987
180
112
17,004
11,956
Accepted
Accepted
37.78
import sys from collections import deque sys.setrecursionlimit(10**7) INTMAX = 9223372036854775807 INTMIN = -9223372036854775808 DVSR = 1000000007 def POW(x, y): return pow(x, y, DVSR) def INV(x, d=DVSR): return pow(x, d - 2, d) def DIV(x, y, d=DVSR): return (x * INV(y, d)) % d def LI(): return [int(x) for x in input().split()] def LF(): return [float(x) for x in input().split()] def LS(): return input().split() def II(): return int(eval(input())) deq=deque(["1", "2", "3", "4", "5", "6", "7", "8", "9"]) K=II() for i in range(K-1): v = deq.popleft() last = int(v[-1]) if last == 0: deq.append(v + "0") deq.append(v + "1") elif last == 9: deq.append(v + "8") deq.append(v + "9") else: deq.append("{}{}".format(v, last-1)) deq.append("{}{}".format(v, last)) deq.append("{}{}".format(v, last+1)) print((deq.popleft()))
import sys from collections import deque sys.setrecursionlimit(10**7) INTMAX = 9223372036854775807 INTMIN = -9223372036854775808 DVSR = 1000000007 def POW(x, y): return pow(x, y, DVSR) def INV(x, d=DVSR): return pow(x, d - 2, d) def DIV(x, y, d=DVSR): return (x * INV(y, d)) % d def LI(): return [int(x) for x in input().split()] def LF(): return [float(x) for x in input().split()] def LS(): return input().split() def II(): return int(eval(input())) deq=deque([1, 2, 3, 4, 5, 6, 7, 8, 9]) K=II() for i in range(K-1): v = deq.popleft() last = v % 10 if last == 0: deq.append(10*v) deq.append(10*v + 1) elif last == 9: deq.append(10*v + 8) deq.append(10*v + 9) else: deq.append(10*v + last-1) deq.append(10*v + last) deq.append(10*v + last+1) print((deq.popleft()))
32
32
923
868
import sys from collections import deque sys.setrecursionlimit(10**7) INTMAX = 9223372036854775807 INTMIN = -9223372036854775808 DVSR = 1000000007 def POW(x, y): return pow(x, y, DVSR) def INV(x, d=DVSR): return pow(x, d - 2, d) def DIV(x, y, d=DVSR): return (x * INV(y, d)) % d def LI(): return [int(x) for x in input().split()] def LF(): return [float(x) for x in input().split()] def LS(): return input().split() def II(): return int(eval(input())) deq = deque(["1", "2", "3", "4", "5", "6", "7", "8", "9"]) K = II() for i in range(K - 1): v = deq.popleft() last = int(v[-1]) if last == 0: deq.append(v + "0") deq.append(v + "1") elif last == 9: deq.append(v + "8") deq.append(v + "9") else: deq.append("{}{}".format(v, last - 1)) deq.append("{}{}".format(v, last)) deq.append("{}{}".format(v, last + 1)) print((deq.popleft()))
import sys from collections import deque sys.setrecursionlimit(10**7) INTMAX = 9223372036854775807 INTMIN = -9223372036854775808 DVSR = 1000000007 def POW(x, y): return pow(x, y, DVSR) def INV(x, d=DVSR): return pow(x, d - 2, d) def DIV(x, y, d=DVSR): return (x * INV(y, d)) % d def LI(): return [int(x) for x in input().split()] def LF(): return [float(x) for x in input().split()] def LS(): return input().split() def II(): return int(eval(input())) deq = deque([1, 2, 3, 4, 5, 6, 7, 8, 9]) K = II() for i in range(K - 1): v = deq.popleft() last = v % 10 if last == 0: deq.append(10 * v) deq.append(10 * v + 1) elif last == 9: deq.append(10 * v + 8) deq.append(10 * v + 9) else: deq.append(10 * v + last - 1) deq.append(10 * v + last) deq.append(10 * v + last + 1) print((deq.popleft()))
false
0
[ "-deq = deque([\"1\", \"2\", \"3\", \"4\", \"5\", \"6\", \"7\", \"8\", \"9\"])", "+deq = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])", "- last = int(v[-1])", "+ last = v % 10", "- deq.append(v + \"0\")", "- deq.append(v + \"1\")", "+ deq.append(10 * v)", "+ deq.append(10 * v + 1)", "- deq.append(v + \"8\")", "- deq.append(v + \"9\")", "+ deq.append(10 * v + 8)", "+ deq.append(10 * v + 9)", "- deq.append(\"{}{}\".format(v, last - 1))", "- deq.append(\"{}{}\".format(v, last))", "- deq.append(\"{}{}\".format(v, last + 1))", "+ deq.append(10 * v + last - 1)", "+ deq.append(10 * v + last)", "+ deq.append(10 * v + last + 1)" ]
false
0.152333
0.286682
0.531364
[ "s717987979", "s344037987" ]
u537782349
p03212
python
s649638294
s618299935
55
48
3,064
3,060
Accepted
Accepted
12.73
def ac(s, t, int3, int5, int7): if s == "": return ac(s + "3", t, int3 + 1, int5, int7) \ + ac(s + "5", t, int3, int5+1, int7) \ + ac(s + "7", t, int3, int5, int7+1) elif int(s) <= t: if int3 != 0 and int5 != 0 and int7 != 0: return 1 \ + ac(s + "3", t, int3 + 1, int5, int7) \ + ac(s + "5", t, int3, int5+1, int7) \ + ac(s + "7", t, int3, int5, int7+1) else: return 0 \ + ac(s + "3", t, int3 + 1, int5, int7) \ + ac(s + "5", t, int3, int5 + 1, int7) \ + ac(s + "7", t, int3, int5, int7 + 1) else: return 0 a = int(input()) print(ac("", a, 0, 0, 0))
import itertools a = eval(input()) b = list("357") c = 0 for j in range(3, len(a) + 1): for i in itertools.product(b, repeat=j): if int("".join(i)) <= int(a) and "3" in i and "5" in i and "7" in i: c += 1 print(c)
22
9
785
240
def ac(s, t, int3, int5, int7): if s == "": return ( ac(s + "3", t, int3 + 1, int5, int7) + ac(s + "5", t, int3, int5 + 1, int7) + ac(s + "7", t, int3, int5, int7 + 1) ) elif int(s) <= t: if int3 != 0 and int5 != 0 and int7 != 0: return ( 1 + ac(s + "3", t, int3 + 1, int5, int7) + ac(s + "5", t, int3, int5 + 1, int7) + ac(s + "7", t, int3, int5, int7 + 1) ) else: return ( 0 + ac(s + "3", t, int3 + 1, int5, int7) + ac(s + "5", t, int3, int5 + 1, int7) + ac(s + "7", t, int3, int5, int7 + 1) ) else: return 0 a = int(input()) print(ac("", a, 0, 0, 0))
import itertools a = eval(input()) b = list("357") c = 0 for j in range(3, len(a) + 1): for i in itertools.product(b, repeat=j): if int("".join(i)) <= int(a) and "3" in i and "5" in i and "7" in i: c += 1 print(c)
false
59.090909
[ "-def ac(s, t, int3, int5, int7):", "- if s == \"\":", "- return (", "- ac(s + \"3\", t, int3 + 1, int5, int7)", "- + ac(s + \"5\", t, int3, int5 + 1, int7)", "- + ac(s + \"7\", t, int3, int5, int7 + 1)", "- )", "- elif int(s) <= t:", "- if int3 != 0 and int5 != 0 and int7 != 0:", "- return (", "- 1", "- + ac(s + \"3\", t, int3 + 1, int5, int7)", "- + ac(s + \"5\", t, int3, int5 + 1, int7)", "- + ac(s + \"7\", t, int3, int5, int7 + 1)", "- )", "- else:", "- return (", "- 0", "- + ac(s + \"3\", t, int3 + 1, int5, int7)", "- + ac(s + \"5\", t, int3, int5 + 1, int7)", "- + ac(s + \"7\", t, int3, int5, int7 + 1)", "- )", "- else:", "- return 0", "+import itertools", "-", "-a = int(input())", "-print(ac(\"\", a, 0, 0, 0))", "+a = eval(input())", "+b = list(\"357\")", "+c = 0", "+for j in range(3, len(a) + 1):", "+ for i in itertools.product(b, repeat=j):", "+ if int(\"\".join(i)) <= int(a) and \"3\" in i and \"5\" in i and \"7\" in i:", "+ c += 1", "+print(c)" ]
false
0.042755
0.158281
0.27012
[ "s649638294", "s618299935" ]
u225388820
p02558
python
s975908780
s995370225
314
270
76,352
75,140
Accepted
Accepted
14.01
def main(): class UnionFind: def __init__(self, N): """ N:要素数 root:各要素の親要素の番号を格納するリスト. ただし, root[x] < 0 ならその頂点が根で-root[x]が木の要素数. rank:ランク """ self.N = N self.root = [-1] * N self.rank = [0] * N def find(self, x): """頂点xの根を見つける""" if self.root[x] < 0: return x else: while self.root[x] >= 0: x = self.root[x] return x def union(self, x, y): """x,yが属する木をunion""" # 根を比較する # すでに同じ木に属していた場合は何もしない. # 違う木に属していた場合はrankを見てくっつける方を決める. # rankが同じ時はrankを1増やす x = self.find(x) y = self.find(y) if x == y: return elif self.rank[x] > self.rank[y]: self.root[x] += self.root[y] self.root[y] = x else: self.root[y] += self.root[x] self.root[x] = y if self.rank[x] == self.rank[y]: self.rank[y] += 1 def same(self, x, y): """xとyが同じグループに属するかどうか""" return self.find(x) == self.find(y) import sys n, q = list(map(int, sys.stdin.buffer.readline().split())) uf = UnionFind(n) for _ in range(q): t, u, v = list(map(int, sys.stdin.buffer.readline().split())) if t: print((int(uf.same(u, v)))) else: uf.union(u, v) main()
class UnionFind: def __init__(self, N: int): """ N:要素数 root:各要素の親要素の番号を格納するリスト. ただし, root[x] < 0 ならその頂点が根で-root[x]が木の要素数. rank:ランク """ self.N = N self.root = [-1] * N self.rank = [0] * N def __repr__(self): return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots()) def find(self, x: int) -> int: """頂点xの根を見つける""" if self.root[x] < 0: return x else: while self.root[x] >= 0: x = self.root[x] return x def union(self, x: int, y: int) -> int: """x,yが属する木をunion""" # 根を比較する # すでに同じ木に属していた場合は何もしない. # 違う木に属していた場合はrankを見てくっつける方を決める. # rankが同じ時はrankを1増やす x = self.find(x) y = self.find(y) if x == y: return elif self.rank[x] > self.rank[y]: self.root[x] += self.root[y] self.root[y] = x else: self.root[y] += self.root[x] self.root[x] = y if self.rank[x] == self.rank[y]: self.rank[y] += 1 def same(self, x: int, y: int) -> bool: """xとyが同じグループに属するかどうか""" return self.find(x) == self.find(y) def count(self, x): """頂点xが属する木のサイズを返す""" return - self.root[self.find(x)] def members(self, x): """xが属する木の要素を列挙""" _root = self.find(x) return [i for i in range(self.N) if self.find == _root] def roots(self): """森の根を列挙""" return [i for i, x in enumerate(self.root) if x < 0] def group_count(self): """連結成分の数""" return len(self.roots()) def all_group_members(self): """{ルート要素: [そのグループに含まれる要素のリスト], ...}の辞書を返す""" return {r: self.members(r) for r in self.roots()} import sys input = sys.stdin.readline 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((int(uf.same(u, v)))) else: uf.union(u, v)
57
79
1,621
2,151
def main(): class UnionFind: def __init__(self, N): """ N:要素数 root:各要素の親要素の番号を格納するリスト. ただし, root[x] < 0 ならその頂点が根で-root[x]が木の要素数. rank:ランク """ self.N = N self.root = [-1] * N self.rank = [0] * N def find(self, x): """頂点xの根を見つける""" if self.root[x] < 0: return x else: while self.root[x] >= 0: x = self.root[x] return x def union(self, x, y): """x,yが属する木をunion""" # 根を比較する # すでに同じ木に属していた場合は何もしない. # 違う木に属していた場合はrankを見てくっつける方を決める. # rankが同じ時はrankを1増やす x = self.find(x) y = self.find(y) if x == y: return elif self.rank[x] > self.rank[y]: self.root[x] += self.root[y] self.root[y] = x else: self.root[y] += self.root[x] self.root[x] = y if self.rank[x] == self.rank[y]: self.rank[y] += 1 def same(self, x, y): """xとyが同じグループに属するかどうか""" return self.find(x) == self.find(y) import sys n, q = list(map(int, sys.stdin.buffer.readline().split())) uf = UnionFind(n) for _ in range(q): t, u, v = list(map(int, sys.stdin.buffer.readline().split())) if t: print((int(uf.same(u, v)))) else: uf.union(u, v) main()
class UnionFind: def __init__(self, N: int): """ N:要素数 root:各要素の親要素の番号を格納するリスト. ただし, root[x] < 0 ならその頂点が根で-root[x]が木の要素数. rank:ランク """ self.N = N self.root = [-1] * N self.rank = [0] * N def __repr__(self): return "\n".join("{}: {}".format(r, self.members(r)) for r in self.roots()) def find(self, x: int) -> int: """頂点xの根を見つける""" if self.root[x] < 0: return x else: while self.root[x] >= 0: x = self.root[x] return x def union(self, x: int, y: int) -> int: """x,yが属する木をunion""" # 根を比較する # すでに同じ木に属していた場合は何もしない. # 違う木に属していた場合はrankを見てくっつける方を決める. # rankが同じ時はrankを1増やす x = self.find(x) y = self.find(y) if x == y: return elif self.rank[x] > self.rank[y]: self.root[x] += self.root[y] self.root[y] = x else: self.root[y] += self.root[x] self.root[x] = y if self.rank[x] == self.rank[y]: self.rank[y] += 1 def same(self, x: int, y: int) -> bool: """xとyが同じグループに属するかどうか""" return self.find(x) == self.find(y) def count(self, x): """頂点xが属する木のサイズを返す""" return -self.root[self.find(x)] def members(self, x): """xが属する木の要素を列挙""" _root = self.find(x) return [i for i in range(self.N) if self.find == _root] def roots(self): """森の根を列挙""" return [i for i, x in enumerate(self.root) if x < 0] def group_count(self): """連結成分の数""" return len(self.roots()) def all_group_members(self): """{ルート要素: [そのグループに含まれる要素のリスト], ...}の辞書を返す""" return {r: self.members(r) for r in self.roots()} import sys input = sys.stdin.readline 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((int(uf.same(u, v)))) else: uf.union(u, v)
false
27.848101
[ "-def main():", "- class UnionFind:", "- def __init__(self, N):", "- \"\"\"", "- N:要素数", "- root:各要素の親要素の番号を格納するリスト.", "- ただし, root[x] < 0 ならその頂点が根で-root[x]が木の要素数.", "- rank:ランク", "- \"\"\"", "- self.N = N", "- self.root = [-1] * N", "- self.rank = [0] * N", "+class UnionFind:", "+ def __init__(self, N: int):", "+ \"\"\"", "+ N:要素数", "+ root:各要素の親要素の番号を格納するリスト.", "+ ただし, root[x] < 0 ならその頂点が根で-root[x]が木の要素数.", "+ rank:ランク", "+ \"\"\"", "+ self.N = N", "+ self.root = [-1] * N", "+ self.rank = [0] * N", "- def find(self, x):", "- \"\"\"頂点xの根を見つける\"\"\"", "- if self.root[x] < 0:", "- return x", "- else:", "- while self.root[x] >= 0:", "- x = self.root[x]", "- return x", "+ def __repr__(self):", "+ return \"\\n\".join(\"{}: {}\".format(r, self.members(r)) for r in self.roots())", "- def union(self, x, y):", "- \"\"\"x,yが属する木をunion\"\"\"", "- # 根を比較する", "- # すでに同じ木に属していた場合は何もしない.", "- # 違う木に属していた場合はrankを見てくっつける方を決める.", "- # rankが同じ時はrankを1増やす", "- x = self.find(x)", "- y = self.find(y)", "- if x == y:", "- return", "- elif self.rank[x] > self.rank[y]:", "- self.root[x] += self.root[y]", "- self.root[y] = x", "- else:", "- self.root[y] += self.root[x]", "- self.root[x] = y", "- if self.rank[x] == self.rank[y]:", "- self.rank[y] += 1", "+ def find(self, x: int) -> int:", "+ \"\"\"頂点xの根を見つける\"\"\"", "+ if self.root[x] < 0:", "+ return x", "+ else:", "+ while self.root[x] >= 0:", "+ x = self.root[x]", "+ return x", "- def same(self, x, y):", "- \"\"\"xとyが同じグループに属するかどうか\"\"\"", "- return self.find(x) == self.find(y)", "+ def union(self, x: int, y: int) -> int:", "+ \"\"\"x,yが属する木をunion\"\"\"", "+ # 根を比較する", "+ # すでに同じ木に属していた場合は何もしない.", "+ # 違う木に属していた場合はrankを見てくっつける方を決める.", "+ # rankが同じ時はrankを1増やす", "+ x = self.find(x)", "+ y = self.find(y)", "+ if x == y:", "+ return", "+ elif self.rank[x] > self.rank[y]:", "+ self.root[x] += self.root[y]", "+ self.root[y] = x", "+ else:", "+ self.root[y] += self.root[x]", "+ self.root[x] = y", "+ if self.rank[x] == self.rank[y]:", "+ self.rank[y] += 1", "- import sys", "+ def same(self, x: int, y: int) -> bool:", "+ \"\"\"xとyが同じグループに属するかどうか\"\"\"", "+ return self.find(x) == self.find(y)", "- n, q = list(map(int, sys.stdin.buffer.readline().split()))", "- uf = UnionFind(n)", "- for _ in range(q):", "- t, u, v = list(map(int, sys.stdin.buffer.readline().split()))", "- if t:", "- print((int(uf.same(u, v))))", "- else:", "- uf.union(u, v)", "+ def count(self, x):", "+ \"\"\"頂点xが属する木のサイズを返す\"\"\"", "+ return -self.root[self.find(x)]", "+", "+ def members(self, x):", "+ \"\"\"xが属する木の要素を列挙\"\"\"", "+ _root = self.find(x)", "+ return [i for i in range(self.N) if self.find == _root]", "+", "+ def roots(self):", "+ \"\"\"森の根を列挙\"\"\"", "+ return [i for i, x in enumerate(self.root) if x < 0]", "+", "+ def group_count(self):", "+ \"\"\"連結成分の数\"\"\"", "+ return len(self.roots())", "+", "+ def all_group_members(self):", "+ \"\"\"{ルート要素: [そのグループに含まれる要素のリスト], ...}の辞書を返す\"\"\"", "+ return {r: self.members(r) for r in self.roots()}", "-main()", "+import sys", "+", "+input = sys.stdin.readline", "+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((int(uf.same(u, v))))", "+ else:", "+ uf.union(u, v)" ]
false
0.037288
0.083678
0.445614
[ "s975908780", "s995370225" ]
u530383736
p02813
python
s925068036
s617942257
80
29
6,040
7,924
Accepted
Accepted
63.75
# -*- coding: utf-8 -*- from itertools import permutations N = int(input().strip()) pat_P = [ "".join( input().rstrip().split() )][0] pat_Q = [ "".join( input().rstrip().split() )][0] #----- perm_list = [ "".join( map(str, pat) ) for pat in permutations(list(range(1,N+1)))] perm_list.sort() a = perm_list.index(pat_P) + 1 b = perm_list.index(pat_Q) + 1 print((abs(a-b)))
# -*- coding: utf-8 -*- from itertools import permutations N = int(input().strip()) pat_P = tuple(map(int, input().rstrip().split())) pat_Q = tuple(map(int, input().rstrip().split())) #----- perm_list = [ pat for pat in permutations(list(range(1,N+1)))] a = perm_list.index(pat_P) + 1 b = perm_list.index(pat_Q) + 1 print((abs(a-b)))
14
13
380
341
# -*- coding: utf-8 -*- from itertools import permutations N = int(input().strip()) pat_P = ["".join(input().rstrip().split())][0] pat_Q = ["".join(input().rstrip().split())][0] # ----- perm_list = ["".join(map(str, pat)) for pat in permutations(list(range(1, N + 1)))] perm_list.sort() a = perm_list.index(pat_P) + 1 b = perm_list.index(pat_Q) + 1 print((abs(a - b)))
# -*- coding: utf-8 -*- from itertools import permutations N = int(input().strip()) pat_P = tuple(map(int, input().rstrip().split())) pat_Q = tuple(map(int, input().rstrip().split())) # ----- perm_list = [pat for pat in permutations(list(range(1, N + 1)))] a = perm_list.index(pat_P) + 1 b = perm_list.index(pat_Q) + 1 print((abs(a - b)))
false
7.142857
[ "-pat_P = [\"\".join(input().rstrip().split())][0]", "-pat_Q = [\"\".join(input().rstrip().split())][0]", "+pat_P = tuple(map(int, input().rstrip().split()))", "+pat_Q = tuple(map(int, input().rstrip().split()))", "-perm_list = [\"\".join(map(str, pat)) for pat in permutations(list(range(1, N + 1)))]", "-perm_list.sort()", "+perm_list = [pat for pat in permutations(list(range(1, N + 1)))]" ]
false
0.042941
0.038234
1.123096
[ "s925068036", "s617942257" ]
u923606520
p03107
python
s726419542
s982131448
266
178
44,016
40,048
Accepted
Accepted
33.08
from collections import deque deq=deque() s=eval(input()) n=len(s) for i in s: if len(deq)==0: deq.append(i) continue x=deq.pop() if x==i: deq.append(x) deq.append(i) print((n-len(deq)))
from collections import Counter s=eval(input()) c=Counter(s) print((min(c["0"],c["1"])*2))
13
4
234
85
from collections import deque deq = deque() s = eval(input()) n = len(s) for i in s: if len(deq) == 0: deq.append(i) continue x = deq.pop() if x == i: deq.append(x) deq.append(i) print((n - len(deq)))
from collections import Counter s = eval(input()) c = Counter(s) print((min(c["0"], c["1"]) * 2))
false
69.230769
[ "-from collections import deque", "+from collections import Counter", "-deq = deque()", "-n = len(s)", "-for i in s:", "- if len(deq) == 0:", "- deq.append(i)", "- continue", "- x = deq.pop()", "- if x == i:", "- deq.append(x)", "- deq.append(i)", "-print((n - len(deq)))", "+c = Counter(s)", "+print((min(c[\"0\"], c[\"1\"]) * 2))" ]
false
0.045642
0.046466
0.982276
[ "s726419542", "s982131448" ]
u732870425
p02678
python
s438976801
s605950991
1,683
514
105,680
101,732
Accepted
Accepted
69.46
N, M = list(map(int, input().split())) L = [[] for _ in range(N+1)] for _ in range(M): a, b = list(map(int, input().split())) L[a].append(b) L[b].append(a) ans = [0 for _ in range(N+1)] now = [1] next = [] while len(now): for x in now: for y in L[x]: if (ans[y] == 0) and (y not in now): ans[y] = x next.append(y) now = next.copy() next = [] print("Yes") for x in range(2, N+1): print((ans[x]))
N, M = list(map(int, input().split())) L = [[] for _ in range(N+1)] for _ in range(M): a, b = list(map(int, input().split())) L[a].append(b) L[b].append(a) ans = [0 for _ in range(N+1)] now = [1] next = [] while len(now): for x in now: for y in L[x]: if (ans[y] == 0): ans[y] = x next.append(y) now = next.copy() next = [] print("Yes") for x in range(2, N+1): print((ans[x]))
23
23
485
467
N, M = list(map(int, input().split())) L = [[] for _ in range(N + 1)] for _ in range(M): a, b = list(map(int, input().split())) L[a].append(b) L[b].append(a) ans = [0 for _ in range(N + 1)] now = [1] next = [] while len(now): for x in now: for y in L[x]: if (ans[y] == 0) and (y not in now): ans[y] = x next.append(y) now = next.copy() next = [] print("Yes") for x in range(2, N + 1): print((ans[x]))
N, M = list(map(int, input().split())) L = [[] for _ in range(N + 1)] for _ in range(M): a, b = list(map(int, input().split())) L[a].append(b) L[b].append(a) ans = [0 for _ in range(N + 1)] now = [1] next = [] while len(now): for x in now: for y in L[x]: if ans[y] == 0: ans[y] = x next.append(y) now = next.copy() next = [] print("Yes") for x in range(2, N + 1): print((ans[x]))
false
0
[ "- if (ans[y] == 0) and (y not in now):", "+ if ans[y] == 0:" ]
false
0.041253
0.041777
0.98745
[ "s438976801", "s605950991" ]
u366886346
p03304
python
s545763766
s782799610
33
27
9,944
8,984
Accepted
Accepted
18.18
import decimal n,m,d=list(map(int,input().split())) print((decimal.Decimal(((2**min(1,d))*(n-d)*(m-1))/(n**2))))
n,m,d=list(map(int,input().split())) print((((2**min(1,d))*(n-d)*(m-1))/(n**2)))
3
2
107
74
import decimal n, m, d = list(map(int, input().split())) print((decimal.Decimal(((2 ** min(1, d)) * (n - d) * (m - 1)) / (n**2))))
n, m, d = list(map(int, input().split())) print((((2 ** min(1, d)) * (n - d) * (m - 1)) / (n**2)))
false
33.333333
[ "-import decimal", "-", "-print((decimal.Decimal(((2 ** min(1, d)) * (n - d) * (m - 1)) / (n**2))))", "+print((((2 ** min(1, d)) * (n - d) * (m - 1)) / (n**2)))" ]
false
0.04874
0.04659
1.046154
[ "s545763766", "s782799610" ]
u923662841
p03252
python
s616003821
s809638196
108
40
20,708
9,288
Accepted
Accepted
62.96
S = eval(input()) T = eval(input()) s = {d:[] for d in set(S)} t = {d:[] for d in set(T)} for i, (j,k) in enumerate(zip(S,T)): s[j] += [i] t[k] += [i] a = sorted(s.values()) b = sorted(t.values()) print(('Yes' if a==b else "No"))
s=eval(input()) t=eval(input()) S=sorted(map(s.count,set(s))) T=sorted(map(t.count,set(t))) print(("Yes" if S==T else "No"))
12
5
236
114
S = eval(input()) T = eval(input()) s = {d: [] for d in set(S)} t = {d: [] for d in set(T)} for i, (j, k) in enumerate(zip(S, T)): s[j] += [i] t[k] += [i] a = sorted(s.values()) b = sorted(t.values()) print(("Yes" if a == b else "No"))
s = eval(input()) t = eval(input()) S = sorted(map(s.count, set(s))) T = sorted(map(t.count, set(t))) print(("Yes" if S == T else "No"))
false
58.333333
[ "-S = eval(input())", "-T = eval(input())", "-s = {d: [] for d in set(S)}", "-t = {d: [] for d in set(T)}", "-for i, (j, k) in enumerate(zip(S, T)):", "- s[j] += [i]", "- t[k] += [i]", "-a = sorted(s.values())", "-b = sorted(t.values())", "-print((\"Yes\" if a == b else \"No\"))", "+s = eval(input())", "+t = eval(input())", "+S = sorted(map(s.count, set(s)))", "+T = sorted(map(t.count, set(t)))", "+print((\"Yes\" if S == T else \"No\"))" ]
false
0.047193
0.052451
0.899745
[ "s616003821", "s809638196" ]