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
u896451538
p02766
python
s182568361
s423648363
39
17
5,328
2,940
Accepted
Accepted
56.41
import math import itertools import fractions import heapq import collections import bisect import sys import copy sys.setrecursionlimit(10**9) mod = 10**7+9 inf = 10**20 def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return eval(input()) n,k = LI() ans = 0 while n: n//=k ans+=1 print(ans)
n,k = list(map(int,input().split())) ans=0 while n>0: n=n//k ans+=1 print(ans)
28
8
688
95
import math import itertools import fractions import heapq import collections import bisect import sys import copy sys.setrecursionlimit(10**9) mod = 10**7 + 9 inf = 10**20 def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()] def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return eval(input()) n, k = LI() ans = 0 while n: n //= k ans += 1 print(ans)
n, k = list(map(int, input().split())) ans = 0 while n > 0: n = n // k ans += 1 print(ans)
false
71.428571
[ "-import math", "-import itertools", "-import fractions", "-import heapq", "-import collections", "-import bisect", "-import sys", "-import copy", "-", "-sys.setrecursionlimit(10**9)", "-mod = 10**7 + 9", "-inf = 10**20", "-", "-", "-def LI():", "- return list(map(int, sys.stdin.readline().split()))", "-", "-", "-def LLI():", "- return [list(map(int, l.split())) for l in sys.stdin.readlines()]", "-", "-", "-def LI_():", "- return [int(x) - 1 for x in sys.stdin.readline().split()]", "-", "-", "-def LF():", "- return [float(x) for x in sys.stdin.readline().split()]", "-", "-", "-def LS():", "- return sys.stdin.readline().split()", "-", "-", "-def I():", "- return int(sys.stdin.readline())", "-", "-", "-def F():", "- return float(sys.stdin.readline())", "-", "-", "-def S():", "- return eval(input())", "-", "-", "-n, k = LI()", "+n, k = list(map(int, input().split()))", "-while n:", "- n //= k", "+while n > 0:", "+ n = n // k" ]
false
0.03707
0.035428
1.046348
[ "s182568361", "s423648363" ]
u691896522
p03805
python
s474592196
s595399644
784
209
56,408
41,948
Accepted
Accepted
73.34
import copy n, m = list(map(int, input().split())) adjacent_list = [[] for i in range(n+1)] for i in range(m): a, b = list(map(int, input().split())) adjacent_list[a].append(b) adjacent_list[b].append(a) ans = 0 def dfs(node,f): f.add(node) global ans if len(f) == n: ans += 1 else: for i in adjacent_list[node]: if i not in f: k = copy.deepcopy(f) dfs(i,k) dfs(1,set()) print(ans)
n, m = list(map(int, input().split())) adjacent_list = [[] for i in range(n+1)] for i in range(m): a, b = list(map(int, input().split())) adjacent_list[a].append(b) adjacent_list[b].append(a) ans = 0 def dfs(node,f): global ans if len(f) == n: ans += 1 else: for i in adjacent_list[node]: if i not in f: k = f | set([i]) dfs(i,k) dfs(1,set([1])) print(ans)
20
18
476
445
import copy n, m = list(map(int, input().split())) adjacent_list = [[] for i in range(n + 1)] for i in range(m): a, b = list(map(int, input().split())) adjacent_list[a].append(b) adjacent_list[b].append(a) ans = 0 def dfs(node, f): f.add(node) global ans if len(f) == n: ans += 1 else: for i in adjacent_list[node]: if i not in f: k = copy.deepcopy(f) dfs(i, k) dfs(1, set()) print(ans)
n, m = list(map(int, input().split())) adjacent_list = [[] for i in range(n + 1)] for i in range(m): a, b = list(map(int, input().split())) adjacent_list[a].append(b) adjacent_list[b].append(a) ans = 0 def dfs(node, f): global ans if len(f) == n: ans += 1 else: for i in adjacent_list[node]: if i not in f: k = f | set([i]) dfs(i, k) dfs(1, set([1])) print(ans)
false
10
[ "-import copy", "-", "- f.add(node)", "- k = copy.deepcopy(f)", "+ k = f | set([i])", "-dfs(1, set())", "+dfs(1, set([1]))" ]
false
0.035602
0.04386
0.811719
[ "s474592196", "s595399644" ]
u608007704
p02597
python
s920292474
s686319073
70
30
9,460
9,300
Accepted
Accepted
57.14
N=int(eval(input())) c=eval(input()) rCount=0 for i in range(N): if c[i]=='R': rCount+=1 wCount=0 for i in range(rCount): if c[i]=='W': wCount+=1 print(wCount)
N=int(eval(input())) c=eval(input()) rCount=c.count('R') wCount=c[0:rCount].count('W') print(wCount)
14
6
179
94
N = int(eval(input())) c = eval(input()) rCount = 0 for i in range(N): if c[i] == "R": rCount += 1 wCount = 0 for i in range(rCount): if c[i] == "W": wCount += 1 print(wCount)
N = int(eval(input())) c = eval(input()) rCount = c.count("R") wCount = c[0:rCount].count("W") print(wCount)
false
57.142857
[ "-rCount = 0", "-for i in range(N):", "- if c[i] == \"R\":", "- rCount += 1", "-wCount = 0", "-for i in range(rCount):", "- if c[i] == \"W\":", "- wCount += 1", "+rCount = c.count(\"R\")", "+wCount = c[0:rCount].count(\"W\")" ]
false
0.035981
0.036504
0.985676
[ "s920292474", "s686319073" ]
u524534026
p03805
python
s543310324
s104963808
288
133
8,052
81,824
Accepted
Accepted
53.82
import sys import itertools n,m=list(map(int,input().split())) ab=[] for _ in range(m): ab.append(list(map(int,input().split()))) lis=list(range(1,n+1)) per_lis =[i for i in list(itertools.permutations(lis)) if i[0]==1] ans=0 for one_case in per_lis: tmp=0 for j in range(n-1): for num in ab: if one_case[j]==num[0] and one_case[j+1]==num[1]: tmp+=1 elif one_case[j]==num[1] and one_case[j+1]==num[0]: tmp+=1 if tmp==n-1: ans+=1 print(ans)
import sys import math import itertools import statistics n,m=list(map(int,input().split())) side=[] for _ in range(m): side.append(tuple(map(int,input().split()))) per_lis =[i for i in list(itertools.permutations(list(range(1,n+1)))) if i[0]==1] ans=0 for one_case in per_lis: tmp=0 for i in range(n-1): if ((one_case[i],one_case[i+1]) in side) or ((one_case[i+1],one_case[i]) in side): tmp+=1 if tmp==n-1: ans+=1 print(ans)
30
19
597
483
import sys import itertools n, m = list(map(int, input().split())) ab = [] for _ in range(m): ab.append(list(map(int, input().split()))) lis = list(range(1, n + 1)) per_lis = [i for i in list(itertools.permutations(lis)) if i[0] == 1] ans = 0 for one_case in per_lis: tmp = 0 for j in range(n - 1): for num in ab: if one_case[j] == num[0] and one_case[j + 1] == num[1]: tmp += 1 elif one_case[j] == num[1] and one_case[j + 1] == num[0]: tmp += 1 if tmp == n - 1: ans += 1 print(ans)
import sys import math import itertools import statistics n, m = list(map(int, input().split())) side = [] for _ in range(m): side.append(tuple(map(int, input().split()))) per_lis = [i for i in list(itertools.permutations(list(range(1, n + 1)))) if i[0] == 1] ans = 0 for one_case in per_lis: tmp = 0 for i in range(n - 1): if ((one_case[i], one_case[i + 1]) in side) or ( (one_case[i + 1], one_case[i]) in side ): tmp += 1 if tmp == n - 1: ans += 1 print(ans)
false
36.666667
[ "+import math", "+import statistics", "-ab = []", "+side = []", "- ab.append(list(map(int, input().split())))", "-lis = list(range(1, n + 1))", "-per_lis = [i for i in list(itertools.permutations(lis)) if i[0] == 1]", "+ side.append(tuple(map(int, input().split())))", "+per_lis = [i for i in list(itertools.permutations(list(range(1, n + 1)))) if i[0] == 1]", "- for j in range(n - 1):", "- for num in ab:", "- if one_case[j] == num[0] and one_case[j + 1] == num[1]:", "- tmp += 1", "- elif one_case[j] == num[1] and one_case[j + 1] == num[0]:", "- tmp += 1", "- if tmp == n - 1:", "- ans += 1", "+ for i in range(n - 1):", "+ if ((one_case[i], one_case[i + 1]) in side) or (", "+ (one_case[i + 1], one_case[i]) in side", "+ ):", "+ tmp += 1", "+ if tmp == n - 1:", "+ ans += 1" ]
false
0.126873
0.062447
2.031705
[ "s543310324", "s104963808" ]
u021019433
p02630
python
s043104802
s559758478
579
485
22,132
17,824
Accepted
Accepted
16.23
from collections import Counter R = lambda: list(map(int, input().split())) R() d = Counter(R()) s = sum(d.elements()) q, = R() for _ in range(q): b, c = R() s += (c - b) * d[b] print(s) d[c]+=d[b] d[b] = 0
R = lambda: list(map(int, input().split())) R() a = [0] * 100001 s = 0 for x in R(): s += x a[x] += 1 q, = R() for _ in range(q): b, c = R() s += (c - b) * a[b] print(s) a[c]+=a[b] a[b] = 0
13
14
224
211
from collections import Counter R = lambda: list(map(int, input().split())) R() d = Counter(R()) s = sum(d.elements()) (q,) = R() for _ in range(q): b, c = R() s += (c - b) * d[b] print(s) d[c] += d[b] d[b] = 0
R = lambda: list(map(int, input().split())) R() a = [0] * 100001 s = 0 for x in R(): s += x a[x] += 1 (q,) = R() for _ in range(q): b, c = R() s += (c - b) * a[b] print(s) a[c] += a[b] a[b] = 0
false
7.142857
[ "-from collections import Counter", "-", "-d = Counter(R())", "-s = sum(d.elements())", "+a = [0] * 100001", "+s = 0", "+for x in R():", "+ s += x", "+ a[x] += 1", "- s += (c - b) * d[b]", "+ s += (c - b) * a[b]", "- d[c] += d[b]", "- d[b] = 0", "+ a[c] += a[b]", "+ a[b] = 0" ]
false
0.036875
0.10944
0.336941
[ "s043104802", "s559758478" ]
u379136995
p02612
python
s091128386
s014239897
35
27
9,108
9,044
Accepted
Accepted
22.86
a=int(eval(input())) if a%1000==0: print((0)) else: print((1000-a%1000))
n=int(eval(input())) n=n%1000 if n==0: print((0)) else: print((1000-n))
5
6
72
70
a = int(eval(input())) if a % 1000 == 0: print((0)) else: print((1000 - a % 1000))
n = int(eval(input())) n = n % 1000 if n == 0: print((0)) else: print((1000 - n))
false
16.666667
[ "-a = int(eval(input()))", "-if a % 1000 == 0:", "+n = int(eval(input()))", "+n = n % 1000", "+if n == 0:", "- print((1000 - a % 1000))", "+ print((1000 - n))" ]
false
0.046557
0.045961
1.012972
[ "s091128386", "s014239897" ]
u729133443
p02900
python
s437781583
s482673343
44
33
5,820
4,692
Accepted
Accepted
25
import fractions as f,subprocess as s;print((len(set(s.Popen(('factor',str(f.gcd(*list(map(int,input().split()))))),stdout=s.PIPE).stdout.read().split()))))
from subprocess import*;a,b=[set(Popen(('factor',x),stdout=PIPE).stdout.read().split()[1:])for x in input().split()];print((len(a&b)+1))
1
1
148
134
import fractions as f, subprocess as s print( ( len( set( s.Popen( ("factor", str(f.gcd(*list(map(int, input().split()))))), stdout=s.PIPE, ) .stdout.read() .split() ) ) ) )
from subprocess import * a, b = [ set(Popen(("factor", x), stdout=PIPE).stdout.read().split()[1:]) for x in input().split() ] print((len(a & b) + 1))
false
0
[ "-import fractions as f, subprocess as s", "+from subprocess import *", "-print(", "- (", "- len(", "- set(", "- s.Popen(", "- (\"factor\", str(f.gcd(*list(map(int, input().split()))))),", "- stdout=s.PIPE,", "- )", "- .stdout.read()", "- .split()", "- )", "- )", "- )", "-)", "+a, b = [", "+ set(Popen((\"factor\", x), stdout=PIPE).stdout.read().split()[1:])", "+ for x in input().split()", "+]", "+print((len(a & b) + 1))" ]
false
0.066977
0.056696
1.181336
[ "s437781583", "s482673343" ]
u273010357
p02844
python
s430489309
s013420538
1,048
829
3,572
3,828
Accepted
Accepted
20.9
from collections import defaultdict n = int(eval(input())) S = eval(input()) d1 = defaultdict(int) d2 = defaultdict(int) d3 = defaultdict(int) for s in S: for x in d2: d3[x+s]+=1 for y in d1: d2[y+s]+=1 d1[s]+=1 print((len(d3)))
N = int(eval(input())) S = list(eval(input())) def ind(l, x, default=-1): if x in l: return l.index(x) else: return default cnt = 0 for i in range(1000): tmp = S t = str(i).zfill(3) pos_1 = ind(tmp,t[0]) if pos_1>=0: tmp = tmp[pos_1+1:] elif pos_1 == -1: continue pos_2 = ind(tmp,t[1]) if pos_2>=0: tmp = tmp[pos_2+1:] elif pos_2 == -1: continue pos_3 = ind(tmp,t[2]) if pos_3>=0: tmp = tmp[pos_3+1:] elif pos_3 == -1: continue cnt += 1 print(cnt)
16
33
260
592
from collections import defaultdict n = int(eval(input())) S = eval(input()) d1 = defaultdict(int) d2 = defaultdict(int) d3 = defaultdict(int) for s in S: for x in d2: d3[x + s] += 1 for y in d1: d2[y + s] += 1 d1[s] += 1 print((len(d3)))
N = int(eval(input())) S = list(eval(input())) def ind(l, x, default=-1): if x in l: return l.index(x) else: return default cnt = 0 for i in range(1000): tmp = S t = str(i).zfill(3) pos_1 = ind(tmp, t[0]) if pos_1 >= 0: tmp = tmp[pos_1 + 1 :] elif pos_1 == -1: continue pos_2 = ind(tmp, t[1]) if pos_2 >= 0: tmp = tmp[pos_2 + 1 :] elif pos_2 == -1: continue pos_3 = ind(tmp, t[2]) if pos_3 >= 0: tmp = tmp[pos_3 + 1 :] elif pos_3 == -1: continue cnt += 1 print(cnt)
false
51.515152
[ "-from collections import defaultdict", "+N = int(eval(input()))", "+S = list(eval(input()))", "-n = int(eval(input()))", "-S = eval(input())", "-d1 = defaultdict(int)", "-d2 = defaultdict(int)", "-d3 = defaultdict(int)", "-for s in S:", "- for x in d2:", "- d3[x + s] += 1", "- for y in d1:", "- d2[y + s] += 1", "- d1[s] += 1", "-print((len(d3)))", "+", "+def ind(l, x, default=-1):", "+ if x in l:", "+ return l.index(x)", "+ else:", "+ return default", "+", "+", "+cnt = 0", "+for i in range(1000):", "+ tmp = S", "+ t = str(i).zfill(3)", "+ pos_1 = ind(tmp, t[0])", "+ if pos_1 >= 0:", "+ tmp = tmp[pos_1 + 1 :]", "+ elif pos_1 == -1:", "+ continue", "+ pos_2 = ind(tmp, t[1])", "+ if pos_2 >= 0:", "+ tmp = tmp[pos_2 + 1 :]", "+ elif pos_2 == -1:", "+ continue", "+ pos_3 = ind(tmp, t[2])", "+ if pos_3 >= 0:", "+ tmp = tmp[pos_3 + 1 :]", "+ elif pos_3 == -1:", "+ continue", "+ cnt += 1", "+print(cnt)" ]
false
0.034104
0.04186
0.814728
[ "s430489309", "s013420538" ]
u263830634
p03944
python
s993233811
s519161899
154
68
12,508
3,064
Accepted
Accepted
55.84
import numpy as np W, H, N = list(map(int, input().split())) g = np.array([[1] * W for _ in range(H)]) for _ in range(N): x, y, a = list(map(int, input().split())) if a == 1: g[:,:x] = 0 elif a == 2: g[:,x:] = 0 elif a == 3: g[H - y:,:] = 0 elif a == 4: g[:H - y,:] = 0 print((g.sum())) # print (g)
W, H, N = list(map(int, input().split())) G = [[1] * H for _ in range(W)] for _ in range(N): x, y, a = list(map(int, input().split())) if a == 1: for x_ in range(x): for y_ in range(H): G[x_][y_] = 0 if a == 2: for x_ in range(x, W): for y_ in range(H): G[x_][y_] = 0 if a == 3: for x_ in range(W): for y_ in range(y): G[x_][y_] = 0 if a == 4: for x_ in range(W): for y_ in range(y, H): G[x_][y_] = 0 ans = 0 for g in G: # print (g) ans += sum(g) print (ans)
19
33
359
666
import numpy as np W, H, N = list(map(int, input().split())) g = np.array([[1] * W for _ in range(H)]) for _ in range(N): x, y, a = list(map(int, input().split())) if a == 1: g[:, :x] = 0 elif a == 2: g[:, x:] = 0 elif a == 3: g[H - y :, :] = 0 elif a == 4: g[: H - y, :] = 0 print((g.sum())) # print (g)
W, H, N = list(map(int, input().split())) G = [[1] * H for _ in range(W)] for _ in range(N): x, y, a = list(map(int, input().split())) if a == 1: for x_ in range(x): for y_ in range(H): G[x_][y_] = 0 if a == 2: for x_ in range(x, W): for y_ in range(H): G[x_][y_] = 0 if a == 3: for x_ in range(W): for y_ in range(y): G[x_][y_] = 0 if a == 4: for x_ in range(W): for y_ in range(y, H): G[x_][y_] = 0 ans = 0 for g in G: # print (g) ans += sum(g) print(ans)
false
42.424242
[ "-import numpy as np", "-", "-g = np.array([[1] * W for _ in range(H)])", "+G = [[1] * H for _ in range(W)]", "- g[:, :x] = 0", "- elif a == 2:", "- g[:, x:] = 0", "- elif a == 3:", "- g[H - y :, :] = 0", "- elif a == 4:", "- g[: H - y, :] = 0", "-print((g.sum()))", "-# print (g)", "+ for x_ in range(x):", "+ for y_ in range(H):", "+ G[x_][y_] = 0", "+ if a == 2:", "+ for x_ in range(x, W):", "+ for y_ in range(H):", "+ G[x_][y_] = 0", "+ if a == 3:", "+ for x_ in range(W):", "+ for y_ in range(y):", "+ G[x_][y_] = 0", "+ if a == 4:", "+ for x_ in range(W):", "+ for y_ in range(y, H):", "+ G[x_][y_] = 0", "+ans = 0", "+for g in G:", "+ # print (g)", "+ ans += sum(g)", "+print(ans)" ]
false
0.383502
0.038428
9.979788
[ "s993233811", "s519161899" ]
u759412327
p03485
python
s312136018
s859018544
21
17
3,316
2,940
Accepted
Accepted
19.05
import math a,b = list(map(int,input().split())) print((math.ceil((a+b)/2)))
from math import ceil print((ceil((sum(list(map(int,input().split()))))/2)))
3
2
76
75
import math a, b = list(map(int, input().split())) print((math.ceil((a + b) / 2)))
from math import ceil print((ceil((sum(list(map(int, input().split())))) / 2)))
false
33.333333
[ "-import math", "+from math import ceil", "-a, b = list(map(int, input().split()))", "-print((math.ceil((a + b) / 2)))", "+print((ceil((sum(list(map(int, input().split())))) / 2)))" ]
false
0.043046
0.046781
0.920166
[ "s312136018", "s859018544" ]
u745087332
p04021
python
s024193249
s767775331
225
113
14,872
14,612
Accepted
Accepted
49.78
# coding:utf-8 INF = float('inf') def inpl(): return list(map(int, input().split())) N = int(eval(input())) A = [int(eval(input())) for _ in range(N)] B = sorted(A) C = A[::2] + B[1::2] D = set(C) print((N - len(D)))
# coding:utf-8 import sys INF = float('inf') MOD = 10 ** 9 + 7 def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def II(): return int(sys.stdin.readline()) def SI(): return eval(input()) def main(): n = II() A = [II() for _ in range(n)] B = A[:] A.sort() return (n + 1) // 2 - len(set(A[::2]) & set(B[::2])) print((main()))
15
26
222
565
# coding:utf-8 INF = float("inf") def inpl(): return list(map(int, input().split())) N = int(eval(input())) A = [int(eval(input())) for _ in range(N)] B = sorted(A) C = A[::2] + B[1::2] D = set(C) print((N - len(D)))
# coding:utf-8 import sys INF = float("inf") MOD = 10**9 + 7 def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def II(): return int(sys.stdin.readline()) def SI(): return eval(input()) def main(): n = II() A = [II() for _ in range(n)] B = A[:] A.sort() return (n + 1) // 2 - len(set(A[::2]) & set(B[::2])) print((main()))
false
42.307692
[ "+import sys", "+", "+MOD = 10**9 + 7", "-def inpl():", "- return list(map(int, input().split()))", "+def LI():", "+ return [int(x) for x in sys.stdin.readline().split()]", "-N = int(eval(input()))", "-A = [int(eval(input())) for _ in range(N)]", "-B = sorted(A)", "-C = A[::2] + B[1::2]", "-D = set(C)", "-print((N - len(D)))", "+def LI_():", "+ return [int(x) - 1 for x in sys.stdin.readline().split()]", "+", "+", "+def LF():", "+ return [float(x) for x in sys.stdin.readline().split()]", "+", "+", "+def LS():", "+ return sys.stdin.readline().split()", "+", "+", "+def II():", "+ return int(sys.stdin.readline())", "+", "+", "+def SI():", "+ return eval(input())", "+", "+", "+def main():", "+ n = II()", "+ A = [II() for _ in range(n)]", "+ B = A[:]", "+ A.sort()", "+ return (n + 1) // 2 - len(set(A[::2]) & set(B[::2]))", "+", "+", "+print((main()))" ]
false
0.057832
0.037101
1.558788
[ "s024193249", "s767775331" ]
u218834617
p02573
python
s465125690
s634193000
538
324
111,248
107,416
Accepted
Accepted
39.78
n,m=list(map(int,input().split())) adj=[[] for _ in range(n)] for _ in range(m): a,b=list(map(int,input().split())) a,b=a-1,b-1 adj[a].append(b) adj[b].append(a) ans=0 vis=[0]*n for i in range(n): if vis[i]: continue vis[i]=1 k=0 stk=[i] while stk: u=stk.pop() k+=1 for v in adj[u]: if vis[v]: continue vis[v]=1 stk.append(v) ans=max(ans,k) print(ans)
import sys n,m=list(map(int,next(sys.stdin).split())) adj=[[] for _ in range(n)] for _ in range(m): a,b=list(map(int,next(sys.stdin).split())) a,b=a-1,b-1 adj[a].append(b) adj[b].append(a) ans=0 vis=[0]*n for i in range(n): if vis[i]: continue vis[i]=1 k=0 stk=[i] while stk: u=stk.pop() k+=1 for v in adj[u]: if vis[v]: continue vis[v]=1 stk.append(v) ans=max(ans,k) print(ans)
27
29
492
522
n, m = list(map(int, input().split())) adj = [[] for _ in range(n)] for _ in range(m): a, b = list(map(int, input().split())) a, b = a - 1, b - 1 adj[a].append(b) adj[b].append(a) ans = 0 vis = [0] * n for i in range(n): if vis[i]: continue vis[i] = 1 k = 0 stk = [i] while stk: u = stk.pop() k += 1 for v in adj[u]: if vis[v]: continue vis[v] = 1 stk.append(v) ans = max(ans, k) print(ans)
import sys n, m = list(map(int, next(sys.stdin).split())) adj = [[] for _ in range(n)] for _ in range(m): a, b = list(map(int, next(sys.stdin).split())) a, b = a - 1, b - 1 adj[a].append(b) adj[b].append(a) ans = 0 vis = [0] * n for i in range(n): if vis[i]: continue vis[i] = 1 k = 0 stk = [i] while stk: u = stk.pop() k += 1 for v in adj[u]: if vis[v]: continue vis[v] = 1 stk.append(v) ans = max(ans, k) print(ans)
false
6.896552
[ "-n, m = list(map(int, input().split()))", "+import sys", "+", "+n, m = list(map(int, next(sys.stdin).split()))", "- a, b = list(map(int, input().split()))", "+ a, b = list(map(int, next(sys.stdin).split()))" ]
false
0.085095
0.040156
2.119118
[ "s465125690", "s634193000" ]
u147544115
p02948
python
s005395106
s372030178
489
443
26,020
26,072
Accepted
Accepted
9.41
# -*- coding: utf-8 -*- from heapq import heappush, heappop n, m = list(map(int, input().split())) # A日後、報酬B workList = {} for i in range(n): a, b = list(map(int, input().split())) if a not in workList: workList[a] = [-b] else: workList[a].append(-b) # print(workList) hq = [] sum = 0 for i in range(1, m + 1): if i in workList: for w in workList[i]: heappush(hq, w) val = None if len(hq) > 0: val = heappop(hq) if val is not None: sum += -val print(sum)
# -*- coding: utf-8 -*- from heapq import heappush, heappop n, m = list(map(int, input().split())) # A日後、報酬B # 日付ごとに報酬をリスト化 workList = {} for i in range(n): a, b = list(map(int, input().split())) if a not in workList: workList[a] = [b] else: workList[a].append(b) hq = [] sum = 0 for i in range(1, m + 1): # 日付が短い順にheapに追加 # 最大値を取り出すため正負は逆に if i in workList: for w in workList[i]: heappush(hq, -w) # 最大値を取り出し、正負を戻して加算 if len(hq) > 0: val = heappop(hq) sum += -val print(sum)
30
31
558
583
# -*- coding: utf-8 -*- from heapq import heappush, heappop n, m = list(map(int, input().split())) # A日後、報酬B workList = {} for i in range(n): a, b = list(map(int, input().split())) if a not in workList: workList[a] = [-b] else: workList[a].append(-b) # print(workList) hq = [] sum = 0 for i in range(1, m + 1): if i in workList: for w in workList[i]: heappush(hq, w) val = None if len(hq) > 0: val = heappop(hq) if val is not None: sum += -val print(sum)
# -*- coding: utf-8 -*- from heapq import heappush, heappop n, m = list(map(int, input().split())) # A日後、報酬B # 日付ごとに報酬をリスト化 workList = {} for i in range(n): a, b = list(map(int, input().split())) if a not in workList: workList[a] = [b] else: workList[a].append(b) hq = [] sum = 0 for i in range(1, m + 1): # 日付が短い順にheapに追加 # 最大値を取り出すため正負は逆に if i in workList: for w in workList[i]: heappush(hq, -w) # 最大値を取り出し、正負を戻して加算 if len(hq) > 0: val = heappop(hq) sum += -val print(sum)
false
3.225806
[ "+# 日付ごとに報酬をリスト化", "- workList[a] = [-b]", "+ workList[a] = [b]", "- workList[a].append(-b)", "-# print(workList)", "+ workList[a].append(b)", "+ # 日付が短い順にheapに追加", "+ # 最大値を取り出すため正負は逆に", "- heappush(hq, w)", "- val = None", "+ heappush(hq, -w)", "+ # 最大値を取り出し、正負を戻して加算", "- if val is not None:" ]
false
0.048237
0.043889
1.099065
[ "s005395106", "s372030178" ]
u161164709
p02585
python
s108357099
s871367251
2,616
1,422
884,604
296,124
Accepted
Accepted
45.64
n, k = list(map(int, input().split())) p = list(map(int, input().split())) c = list(map(int, input().split())) mv_array = [set() for _ in range(n)] score_mv_array = [[] for _ in range(n)] score_array = [0]*n def get_sum(array): score_array = [0] for i, a in enumerate(array): score_array.append(score_array[i]+a) return max(score_array) def get_max(array, q, mod): if q == 0: m_score = get_sum(array[:mod]) else: m_score = get_sum(array+array[:mod]) m_score = sum(array)*(q-1) + m_score return m_score for i in range(n): score = 0 max_score = c[i] pos = i for j in range(k): pos = p[pos]-1 if pos in mv_array[i]: len_mv = len(score_mv_array[i]) q, mod = divmod(k-j, len_mv) score += get_max(score_mv_array[i], q, mod) max_score = max(score, max_score) break score += c[pos] mv_array[i].add(pos) score_mv_array[i].append(c[pos]) max_score = max(score, max_score) score_array[i] = max_score print((max(score_array)))
n, k = list(map(int, input().split())) p = list(map(int, input().split())) c = list(map(int, input().split())) # mv_array = [set() for _ in range(n)] score_mv_array = [[] for _ in range(n)] score_array = [0]*n def get_sum(array): score_array = [0] for i, a in enumerate(array): score_array.append(score_array[i]+a) return max(score_array) def get_max(array, q, mod): if q == 0: m_score = get_sum(array[:mod]) else: m_score = get_sum(array+array[:mod]) m_score = sum(array)*(q-1) + m_score return m_score for i in range(n): score = 0 max_score = c[i] pos = i start_pos = p[pos]-1 for j in range(k): pos = p[pos]-1 # if pos in mv_array[i]: if j!=0 and pos == start_pos: len_mv = len(score_mv_array[i]) q, mod = divmod(k-j, len_mv) score += get_max(score_mv_array[i], q, mod) max_score = max(score, max_score) break score += c[pos] # mv_array[i].add(pos) score_mv_array[i].append(c[pos]) max_score = max(score, max_score) score_array[i] = max_score print((max(score_array)))
41
43
1,135
1,206
n, k = list(map(int, input().split())) p = list(map(int, input().split())) c = list(map(int, input().split())) mv_array = [set() for _ in range(n)] score_mv_array = [[] for _ in range(n)] score_array = [0] * n def get_sum(array): score_array = [0] for i, a in enumerate(array): score_array.append(score_array[i] + a) return max(score_array) def get_max(array, q, mod): if q == 0: m_score = get_sum(array[:mod]) else: m_score = get_sum(array + array[:mod]) m_score = sum(array) * (q - 1) + m_score return m_score for i in range(n): score = 0 max_score = c[i] pos = i for j in range(k): pos = p[pos] - 1 if pos in mv_array[i]: len_mv = len(score_mv_array[i]) q, mod = divmod(k - j, len_mv) score += get_max(score_mv_array[i], q, mod) max_score = max(score, max_score) break score += c[pos] mv_array[i].add(pos) score_mv_array[i].append(c[pos]) max_score = max(score, max_score) score_array[i] = max_score print((max(score_array)))
n, k = list(map(int, input().split())) p = list(map(int, input().split())) c = list(map(int, input().split())) # mv_array = [set() for _ in range(n)] score_mv_array = [[] for _ in range(n)] score_array = [0] * n def get_sum(array): score_array = [0] for i, a in enumerate(array): score_array.append(score_array[i] + a) return max(score_array) def get_max(array, q, mod): if q == 0: m_score = get_sum(array[:mod]) else: m_score = get_sum(array + array[:mod]) m_score = sum(array) * (q - 1) + m_score return m_score for i in range(n): score = 0 max_score = c[i] pos = i start_pos = p[pos] - 1 for j in range(k): pos = p[pos] - 1 # if pos in mv_array[i]: if j != 0 and pos == start_pos: len_mv = len(score_mv_array[i]) q, mod = divmod(k - j, len_mv) score += get_max(score_mv_array[i], q, mod) max_score = max(score, max_score) break score += c[pos] # mv_array[i].add(pos) score_mv_array[i].append(c[pos]) max_score = max(score, max_score) score_array[i] = max_score print((max(score_array)))
false
4.651163
[ "-mv_array = [set() for _ in range(n)]", "+# mv_array = [set() for _ in range(n)]", "+ start_pos = p[pos] - 1", "- if pos in mv_array[i]:", "+ # if pos in mv_array[i]:", "+ if j != 0 and pos == start_pos:", "- mv_array[i].add(pos)", "+ # mv_array[i].add(pos)" ]
false
0.037925
0.086282
0.439549
[ "s108357099", "s871367251" ]
u493520238
p03044
python
s096230736
s342771673
377
241
95,588
95,172
Accepted
Accepted
36.07
from collections import deque def bfs(start, g, visited): q = deque([start]) visited[start] = 0 while q: curr_node = q.popleft() for next_node, w in g[curr_node]: if visited[next_node] >= 0: continue visited[next_node] = (visited[curr_node] + w)%2 q.append(next_node) n = int(eval(input())) gl = [ [] for _ in range(n+1)] for _ in range(n-1): u,v,w = list(map(int, input().split())) gl[u].append((v,w)) gl[v].append((u,w)) visited = [-1] * (n+1) bfs(1, gl, visited) for v in visited[1:]: if v%2 == 0: print((0)) else: print((1))
import sys from collections import deque input = sys.stdin.readline sys.setrecursionlimit(10**6) def dfs(start,n,g): visited = [-1]*(n+1) visited[start] = 0 stack = deque([start]) while stack: c_node = stack.pop() for neib, dist in g[c_node]: if visited[neib] != -1: continue visited[neib] = visited[c_node] + dist stack.append(neib) return visited N = int(eval(input())) g = [ [] for _ in range(N+1)] visited = [-1] * (N+1) for _ in range(N-1): u, v, w = list(map(int, input().split())) w%=2 g[u].append((v,w)) g[v].append((u,w)) visited = dfs(1,N,g) for p in visited[1:]: print((p%2))
25
33
624
713
from collections import deque def bfs(start, g, visited): q = deque([start]) visited[start] = 0 while q: curr_node = q.popleft() for next_node, w in g[curr_node]: if visited[next_node] >= 0: continue visited[next_node] = (visited[curr_node] + w) % 2 q.append(next_node) n = int(eval(input())) gl = [[] for _ in range(n + 1)] for _ in range(n - 1): u, v, w = list(map(int, input().split())) gl[u].append((v, w)) gl[v].append((u, w)) visited = [-1] * (n + 1) bfs(1, gl, visited) for v in visited[1:]: if v % 2 == 0: print((0)) else: print((1))
import sys from collections import deque input = sys.stdin.readline sys.setrecursionlimit(10**6) def dfs(start, n, g): visited = [-1] * (n + 1) visited[start] = 0 stack = deque([start]) while stack: c_node = stack.pop() for neib, dist in g[c_node]: if visited[neib] != -1: continue visited[neib] = visited[c_node] + dist stack.append(neib) return visited N = int(eval(input())) g = [[] for _ in range(N + 1)] visited = [-1] * (N + 1) for _ in range(N - 1): u, v, w = list(map(int, input().split())) w %= 2 g[u].append((v, w)) g[v].append((u, w)) visited = dfs(1, N, g) for p in visited[1:]: print((p % 2))
false
24.242424
[ "+import sys", "-", "-def bfs(start, g, visited):", "- q = deque([start])", "- visited[start] = 0", "- while q:", "- curr_node = q.popleft()", "- for next_node, w in g[curr_node]:", "- if visited[next_node] >= 0:", "- continue", "- visited[next_node] = (visited[curr_node] + w) % 2", "- q.append(next_node)", "+input = sys.stdin.readline", "+sys.setrecursionlimit(10**6)", "-n = int(eval(input()))", "-gl = [[] for _ in range(n + 1)]", "-for _ in range(n - 1):", "+def dfs(start, n, g):", "+ visited = [-1] * (n + 1)", "+ visited[start] = 0", "+ stack = deque([start])", "+ while stack:", "+ c_node = stack.pop()", "+ for neib, dist in g[c_node]:", "+ if visited[neib] != -1:", "+ continue", "+ visited[neib] = visited[c_node] + dist", "+ stack.append(neib)", "+ return visited", "+", "+", "+N = int(eval(input()))", "+g = [[] for _ in range(N + 1)]", "+visited = [-1] * (N + 1)", "+for _ in range(N - 1):", "- gl[u].append((v, w))", "- gl[v].append((u, w))", "-visited = [-1] * (n + 1)", "-bfs(1, gl, visited)", "-for v in visited[1:]:", "- if v % 2 == 0:", "- print((0))", "- else:", "- print((1))", "+ w %= 2", "+ g[u].append((v, w))", "+ g[v].append((u, w))", "+visited = dfs(1, N, g)", "+for p in visited[1:]:", "+ print((p % 2))" ]
false
0.079186
0.045225
1.750941
[ "s096230736", "s342771673" ]
u606045429
p03716
python
s973821392
s811842344
339
283
40,164
36,308
Accepted
Accepted
16.52
from heapq import heapify, heappop, heappush N, *A = list(map(int, open(0).read().split())) Q = A[:N] heapify(Q) R = [sum(Q)] for a in A[N:2 * N]: heappush(Q, a) R.append(R[-1] + a - heappop(Q)) Q = [-a for a in A[2 * N:]] heapify(Q) B = [sum(Q)] for a in reversed(A[N:2 * N]): heappush(Q, -a) B.append(B[-1] - a - heappop(Q)) print((max(r + b for r, b in zip(R, reversed(B)))))
from heapq import heapify, heappushpop N, *A = list(map(int, open(0).read().split())) Q = A[:N] heapify(Q) R = [sum(Q)] for a in A[N:2 * N]: R.append(R[-1] + a - heappushpop(Q, a)) Q = [-a for a in A[2 * N:]] heapify(Q) B = [sum(Q)] for a in reversed(A[N:2 * N]): B.append(B[-1] - a - heappushpop(Q, -a)) print((max(r + b for r, b in zip(R, reversed(B)))))
21
19
413
381
from heapq import heapify, heappop, heappush N, *A = list(map(int, open(0).read().split())) Q = A[:N] heapify(Q) R = [sum(Q)] for a in A[N : 2 * N]: heappush(Q, a) R.append(R[-1] + a - heappop(Q)) Q = [-a for a in A[2 * N :]] heapify(Q) B = [sum(Q)] for a in reversed(A[N : 2 * N]): heappush(Q, -a) B.append(B[-1] - a - heappop(Q)) print((max(r + b for r, b in zip(R, reversed(B)))))
from heapq import heapify, heappushpop N, *A = list(map(int, open(0).read().split())) Q = A[:N] heapify(Q) R = [sum(Q)] for a in A[N : 2 * N]: R.append(R[-1] + a - heappushpop(Q, a)) Q = [-a for a in A[2 * N :]] heapify(Q) B = [sum(Q)] for a in reversed(A[N : 2 * N]): B.append(B[-1] - a - heappushpop(Q, -a)) print((max(r + b for r, b in zip(R, reversed(B)))))
false
9.52381
[ "-from heapq import heapify, heappop, heappush", "+from heapq import heapify, heappushpop", "- heappush(Q, a)", "- R.append(R[-1] + a - heappop(Q))", "+ R.append(R[-1] + a - heappushpop(Q, a))", "- heappush(Q, -a)", "- B.append(B[-1] - a - heappop(Q))", "+ B.append(B[-1] - a - heappushpop(Q, -a))" ]
false
0.094344
0.048072
1.962534
[ "s973821392", "s811842344" ]
u743420240
p02844
python
s044573833
s805948139
698
575
3,188
3,188
Accepted
Accepted
17.62
def main(): # 入力 n = int(eval(input())) s = eval(input()) set1 = set() set2 = set() set3 = set() for x in s: for x2 in set2: _x2 = x2+x if x2+x not in set3: set3.add(_x2) for x1 in set1: _x1 = x1+x if x1+x not in set2: set2.add(_x1) if x not in set1: set1.add(x) print((len(set3))) main()
def main(): # 入力 n = int(eval(input())) s = eval(input()) set1 = set() set2 = set() set3 = set() for x in s: for x2 in set2: _x2 = x2+x set3.add(_x2) for x1 in set1: _x1 = x1+x set2.add(_x1) set1.add(x) print((len(set3))) main()
24
21
450
343
def main(): # 入力 n = int(eval(input())) s = eval(input()) set1 = set() set2 = set() set3 = set() for x in s: for x2 in set2: _x2 = x2 + x if x2 + x not in set3: set3.add(_x2) for x1 in set1: _x1 = x1 + x if x1 + x not in set2: set2.add(_x1) if x not in set1: set1.add(x) print((len(set3))) main()
def main(): # 入力 n = int(eval(input())) s = eval(input()) set1 = set() set2 = set() set3 = set() for x in s: for x2 in set2: _x2 = x2 + x set3.add(_x2) for x1 in set1: _x1 = x1 + x set2.add(_x1) set1.add(x) print((len(set3))) main()
false
12.5
[ "- if x2 + x not in set3:", "- set3.add(_x2)", "+ set3.add(_x2)", "- if x1 + x not in set2:", "- set2.add(_x1)", "- if x not in set1:", "- set1.add(x)", "+ set2.add(_x1)", "+ set1.add(x)" ]
false
0.037427
0.041945
0.892289
[ "s044573833", "s805948139" ]
u934442292
p03721
python
s676848445
s058151330
223
146
18,216
5,736
Accepted
Accepted
34.53
import sys from operator import itemgetter input = sys.stdin.readline # NOQA def main(): N, K = list(map(int, input().split())) ab = [None] * N for i in range(N): ab[i] = tuple(map(int, input().split())) ab.sort(key=itemgetter(0)) cnt = 0 for a, b in ab: cnt += b if cnt >= K: ans = a break print(ans) if __name__ == "__main__": main()
import sys input = sys.stdin.readline # NOQA def main(): N, K = list(map(int, input().split())) cnt = [0] * (1 + 10**5) for i in range(N): a, b = list(map(int, input().split())) cnt[a] += b total = 0 for i in range(1, 10**5 + 1): total += cnt[i] if total >= K: ans = i break print(ans) if __name__ == "__main__": main()
24
23
444
421
import sys from operator import itemgetter input = sys.stdin.readline # NOQA def main(): N, K = list(map(int, input().split())) ab = [None] * N for i in range(N): ab[i] = tuple(map(int, input().split())) ab.sort(key=itemgetter(0)) cnt = 0 for a, b in ab: cnt += b if cnt >= K: ans = a break print(ans) if __name__ == "__main__": main()
import sys input = sys.stdin.readline # NOQA def main(): N, K = list(map(int, input().split())) cnt = [0] * (1 + 10**5) for i in range(N): a, b = list(map(int, input().split())) cnt[a] += b total = 0 for i in range(1, 10**5 + 1): total += cnt[i] if total >= K: ans = i break print(ans) if __name__ == "__main__": main()
false
4.166667
[ "-from operator import itemgetter", "- ab = [None] * N", "+ cnt = [0] * (1 + 10**5)", "- ab[i] = tuple(map(int, input().split()))", "- ab.sort(key=itemgetter(0))", "- cnt = 0", "- for a, b in ab:", "- cnt += b", "- if cnt >= K:", "- ans = a", "+ a, b = list(map(int, input().split()))", "+ cnt[a] += b", "+ total = 0", "+ for i in range(1, 10**5 + 1):", "+ total += cnt[i]", "+ if total >= K:", "+ ans = i" ]
false
0.057351
0.073348
0.78191
[ "s676848445", "s058151330" ]
u621935300
p03069
python
s760637344
s206004984
76
69
46,364
46,364
Accepted
Accepted
9.21
N=eval(input()) S=input() L=[0] for i,x in enumerate(S): if x=="#": L.append( L[-1]+1 ) else: L.append( L[-1] ) ans=float("inf") for i in range(N+1): b=L[i] # black on left w=N-i-(L[-1]-L[i]) ans=min(ans , b+w) print(ans)
N=eval(input()) S=input() L=[0] for i,x in enumerate(S): if x=="#": L.append( L[-1]+1 ) else: L.append( L[-1] ) ans=float("inf") for i in range(N+1): b=L[i] # black on left w=N-i-(L[-1]-L[i]) # white on right ans=min(ans , b+w) print(ans)
18
18
251
270
N = eval(input()) S = input() L = [0] for i, x in enumerate(S): if x == "#": L.append(L[-1] + 1) else: L.append(L[-1]) ans = float("inf") for i in range(N + 1): b = L[i] # black on left w = N - i - (L[-1] - L[i]) ans = min(ans, b + w) print(ans)
N = eval(input()) S = input() L = [0] for i, x in enumerate(S): if x == "#": L.append(L[-1] + 1) else: L.append(L[-1]) ans = float("inf") for i in range(N + 1): b = L[i] # black on left w = N - i - (L[-1] - L[i]) # white on right ans = min(ans, b + w) print(ans)
false
0
[ "- w = N - i - (L[-1] - L[i])", "+ w = N - i - (L[-1] - L[i]) # white on right" ]
false
0.036577
0.035835
1.02073
[ "s760637344", "s206004984" ]
u416011173
p02691
python
s080865290
s464987152
193
151
40,448
40,460
Accepted
Accepted
21.76
# -*- coding: utf-8 -*- # モジュールのインポート import collections # 標準入力の取得 N = int(eval(input())) A = list(map(int, input().split())) # 求解処理 left = {} result = 0 for j in range(N): r = -A[j] + j result += left.get(r, 0) l = A[j] + j left[l] = left.get(l, 0) + 1 # 結果出力 print(result)
# -*- coding: utf-8 -*- # 標準入力の取得 N = int(eval(input())) A = list(map(int, input().split())) def main() -> None: """Entry point """ # 求解処理 """ 1 <= i < j <= Nとすると、 j - i = A_i + A_j ⇒ -A_j + j = A_i +i となる。 したがって、各jについて、左辺の値を計算し、等式が成立するようなi(< j)の個数を求めればよい。 """ right = {} result = 0 for j in range(N): l = -A[j] + j result += right.get(l, 0) r = A[j] + j right[r] = right.get(r, 0) + 1 # 結果出力 print(result) if __name__ == "__main__": main()
19
30
306
561
# -*- coding: utf-8 -*- # モジュールのインポート import collections # 標準入力の取得 N = int(eval(input())) A = list(map(int, input().split())) # 求解処理 left = {} result = 0 for j in range(N): r = -A[j] + j result += left.get(r, 0) l = A[j] + j left[l] = left.get(l, 0) + 1 # 結果出力 print(result)
# -*- coding: utf-8 -*- # 標準入力の取得 N = int(eval(input())) A = list(map(int, input().split())) def main() -> None: """Entry point""" # 求解処理 """ 1 <= i < j <= Nとすると、 j - i = A_i + A_j ⇒ -A_j + j = A_i +i となる。 したがって、各jについて、左辺の値を計算し、等式が成立するようなi(< j)の個数を求めればよい。 """ right = {} result = 0 for j in range(N): l = -A[j] + j result += right.get(l, 0) r = A[j] + j right[r] = right.get(r, 0) + 1 # 結果出力 print(result) if __name__ == "__main__": main()
false
36.666667
[ "-# モジュールのインポート", "-import collections", "-", "-# 求解処理", "-left = {}", "-result = 0", "-for j in range(N):", "- r = -A[j] + j", "- result += left.get(r, 0)", "- l = A[j] + j", "- left[l] = left.get(l, 0) + 1", "-# 結果出力", "-print(result)", "+", "+", "+def main() -> None:", "+ \"\"\"Entry point\"\"\"", "+ # 求解処理", "+ \"\"\"", "+ 1 <= i < j <= Nとすると、", "+ j - i = A_i + A_j ⇒ -A_j + j = A_i +i", "+ となる。", "+ したがって、各jについて、左辺の値を計算し、等式が成立するようなi(< j)の個数を求めればよい。", "+ \"\"\"", "+ right = {}", "+ result = 0", "+ for j in range(N):", "+ l = -A[j] + j", "+ result += right.get(l, 0)", "+ r = A[j] + j", "+ right[r] = right.get(r, 0) + 1", "+ # 結果出力", "+ print(result)", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.134372
0.072939
1.842242
[ "s080865290", "s464987152" ]
u354916249
p02918
python
s494274511
s547176533
49
44
3,316
3,316
Accepted
Accepted
10.2
N, K = list(map(int, input().split())) S = eval(input()) counter = 0 RL = 0 RL_L = 0 RL_R = 0 if S[0] == 'L': RL_L += 1 if S[N-1] == 'R': RL_R += 1 for i in range(N-1): if S[i:i+2] == 'RL': counter += 1 if (counter - K) >= 0: counter -= K K = 0 else: K -= counter counter = 0 RL = 0 if RL_L == 1 and K > 0: RL_L -= 1 K -= 1 if RL_R == 1 and K > 0: RL_R -= 1 K -= 1 ans = N - (counter*2 + RL_L + RL_R) print((min(ans, N-1)))
N, K = list(map(int, input().split())) S = eval(input()) counter = 0 ans = N-1 for i in range(N-1): if S[i] != S[i+1]: ans -= 1 print((min(N-1, ans+2*K)))
36
11
509
165
N, K = list(map(int, input().split())) S = eval(input()) counter = 0 RL = 0 RL_L = 0 RL_R = 0 if S[0] == "L": RL_L += 1 if S[N - 1] == "R": RL_R += 1 for i in range(N - 1): if S[i : i + 2] == "RL": counter += 1 if (counter - K) >= 0: counter -= K K = 0 else: K -= counter counter = 0 RL = 0 if RL_L == 1 and K > 0: RL_L -= 1 K -= 1 if RL_R == 1 and K > 0: RL_R -= 1 K -= 1 ans = N - (counter * 2 + RL_L + RL_R) print((min(ans, N - 1)))
N, K = list(map(int, input().split())) S = eval(input()) counter = 0 ans = N - 1 for i in range(N - 1): if S[i] != S[i + 1]: ans -= 1 print((min(N - 1, ans + 2 * K)))
false
69.444444
[ "-RL = 0", "-RL_L = 0", "-RL_R = 0", "-if S[0] == \"L\":", "- RL_L += 1", "-if S[N - 1] == \"R\":", "- RL_R += 1", "+ans = N - 1", "- if S[i : i + 2] == \"RL\":", "- counter += 1", "-if (counter - K) >= 0:", "- counter -= K", "- K = 0", "-else:", "- K -= counter", "- counter = 0", "- RL = 0", "-if RL_L == 1 and K > 0:", "- RL_L -= 1", "- K -= 1", "-if RL_R == 1 and K > 0:", "- RL_R -= 1", "- K -= 1", "-ans = N - (counter * 2 + RL_L + RL_R)", "-print((min(ans, N - 1)))", "+ if S[i] != S[i + 1]:", "+ ans -= 1", "+print((min(N - 1, ans + 2 * K)))" ]
false
0.046601
0.046463
1.002981
[ "s494274511", "s547176533" ]
u823458368
p03804
python
s278916145
s490109640
318
150
21,676
3,064
Accepted
Accepted
52.83
import numpy as np n, m = list(map(int, input().split())) a = [[j for j in eval(input())] for i in range(n)] b = [[j for j in eval(input())] for i in range(m)] ans = 'No' na = np.array(a) nb = np.array(b) for i in range(n-m+1): for j in range(n-m+1): s = na[i:m+i, list(range(j, m+j))] if (s == nb).all(): ans = 'Yes' break print(ans)
a, b = list(map(int,input().split())) A = [eval(input()) for _ in range(a)] B = [eval(input()) for _ in range(b)] ans = "No" for i in range(a-b+1): for j in range(a-b+1): cnt = 0 if A[i][j] == B[0][0]: for k in range(b): for l in range(b): if A[i+k][j+l] == B[k][l]: cnt += 1 if cnt == b**2: ans = "Yes" print(ans)
14
16
367
448
import numpy as np n, m = list(map(int, input().split())) a = [[j for j in eval(input())] for i in range(n)] b = [[j for j in eval(input())] for i in range(m)] ans = "No" na = np.array(a) nb = np.array(b) for i in range(n - m + 1): for j in range(n - m + 1): s = na[i : m + i, list(range(j, m + j))] if (s == nb).all(): ans = "Yes" break print(ans)
a, b = list(map(int, input().split())) A = [eval(input()) for _ in range(a)] B = [eval(input()) for _ in range(b)] ans = "No" for i in range(a - b + 1): for j in range(a - b + 1): cnt = 0 if A[i][j] == B[0][0]: for k in range(b): for l in range(b): if A[i + k][j + l] == B[k][l]: cnt += 1 if cnt == b**2: ans = "Yes" print(ans)
false
12.5
[ "-import numpy as np", "-", "-n, m = list(map(int, input().split()))", "-a = [[j for j in eval(input())] for i in range(n)]", "-b = [[j for j in eval(input())] for i in range(m)]", "+a, b = list(map(int, input().split()))", "+A = [eval(input()) for _ in range(a)]", "+B = [eval(input()) for _ in range(b)]", "-na = np.array(a)", "-nb = np.array(b)", "-for i in range(n - m + 1):", "- for j in range(n - m + 1):", "- s = na[i : m + i, list(range(j, m + j))]", "- if (s == nb).all():", "- ans = \"Yes\"", "- break", "+for i in range(a - b + 1):", "+ for j in range(a - b + 1):", "+ cnt = 0", "+ if A[i][j] == B[0][0]:", "+ for k in range(b):", "+ for l in range(b):", "+ if A[i + k][j + l] == B[k][l]:", "+ cnt += 1", "+ if cnt == b**2:", "+ ans = \"Yes\"" ]
false
0.465787
0.007798
59.73428
[ "s278916145", "s490109640" ]
u790710233
p03164
python
s749630531
s694113397
417
300
120,044
41,964
Accepted
Accepted
28.06
n, w = list(map(int, input().split())) weights, values = list(zip(*[tuple(map(int, input().split())) for _ in range(n)])) UV = 10**5 INF = 10**10 dp = [[INF]*(UV+1) for _ in range(n+1)] for i in range(n+1): dp[i][0] = 0 for i in range(1, n+1): for j in range(1, UV+1): dp[i][j] = dp[i-1][j] if 0 <= j-values[i-1]: dp[i][j] = min(dp[i][j], dp[i-1][j-values[i-1]]+weights[i-1]) ans = 0 for i in reversed(list(range(UV+1))): if dp[-1][i] <= w: ans = i break print(ans)
n, w = list(map(int, input().split())) weights, values = list(zip(*[tuple(map(int, input().split())) for _ in range(n)])) UV = 10**5 INF = 10**10 dp = [INF]*(UV+1) dp[0] = 0 for i in range(1, n+1): for j in reversed(list(range(1, UV+1))): if j-values[i-1] < 0: continue dp[j] = min(dp[j], dp[j-values[i-1]]+weights[i-1]) ans = 0 for j in reversed(list(range(UV+1))): if dp[j] <= w: ans = j break print(ans)
20
20
528
457
n, w = list(map(int, input().split())) weights, values = list(zip(*[tuple(map(int, input().split())) for _ in range(n)])) UV = 10**5 INF = 10**10 dp = [[INF] * (UV + 1) for _ in range(n + 1)] for i in range(n + 1): dp[i][0] = 0 for i in range(1, n + 1): for j in range(1, UV + 1): dp[i][j] = dp[i - 1][j] if 0 <= j - values[i - 1]: dp[i][j] = min(dp[i][j], dp[i - 1][j - values[i - 1]] + weights[i - 1]) ans = 0 for i in reversed(list(range(UV + 1))): if dp[-1][i] <= w: ans = i break print(ans)
n, w = list(map(int, input().split())) weights, values = list(zip(*[tuple(map(int, input().split())) for _ in range(n)])) UV = 10**5 INF = 10**10 dp = [INF] * (UV + 1) dp[0] = 0 for i in range(1, n + 1): for j in reversed(list(range(1, UV + 1))): if j - values[i - 1] < 0: continue dp[j] = min(dp[j], dp[j - values[i - 1]] + weights[i - 1]) ans = 0 for j in reversed(list(range(UV + 1))): if dp[j] <= w: ans = j break print(ans)
false
0
[ "-dp = [[INF] * (UV + 1) for _ in range(n + 1)]", "-for i in range(n + 1):", "- dp[i][0] = 0", "+dp = [INF] * (UV + 1)", "+dp[0] = 0", "- for j in range(1, UV + 1):", "- dp[i][j] = dp[i - 1][j]", "- if 0 <= j - values[i - 1]:", "- dp[i][j] = min(dp[i][j], dp[i - 1][j - values[i - 1]] + weights[i - 1])", "+ for j in reversed(list(range(1, UV + 1))):", "+ if j - values[i - 1] < 0:", "+ continue", "+ dp[j] = min(dp[j], dp[j - values[i - 1]] + weights[i - 1])", "-for i in reversed(list(range(UV + 1))):", "- if dp[-1][i] <= w:", "- ans = i", "+for j in reversed(list(range(UV + 1))):", "+ if dp[j] <= w:", "+ ans = j" ]
false
0.738183
1.050969
0.702383
[ "s749630531", "s694113397" ]
u970899068
p02990
python
s606146306
s851013895
549
31
3,444
4,596
Accepted
Accepted
94.35
def cmb(n, r): if n - r < r: r = n - r if r == 0: return 1 if r == 1: return n numerator = [n - r + k + 1 for k in range(r)] denominator = [k + 1 for k in range(r)] for p in range(2,r+1): pivot = denominator[p - 1] if pivot > 1: offset = (n - r) % p for k in range(p-1,r,p): numerator[k - offset] /= pivot denominator[k] /= pivot result = 1 for k in range(r): if numerator[k] > 1: result *= int(numerator[k]) return result n,k=list(map(int, input().split())) for i in range(1,k+1): if i > n-k+1: print((0)) else: print((cmb(n-k+1,i)%(10**9+7)*cmb(k-1,i-1)%(10**9+7)))
def cmb(n, r, mod): if ( r<0 or r>n ): return 0 r = min(r, n-r) return g1[n] * g2[r] * g2[n-r] % mod mod = 10**9+7 #出力の制限 N = 10**4 g1 = [1, 1] # 元テーブル g2 = [1, 1] #逆元テーブル inverse = [0, 1] #逆元テーブル計算用テーブル for i in range( 2, N + 1 ): g1.append( ( g1[-1] * i ) % mod ) inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod ) g2.append( (g2[-1] * inverse[-1]) % mod ) n,k=list(map(int, input().split())) for i in range(1,k+1): if i > n-k+1: print((0)) else: print((cmb(n-k+1,i,mod)*cmb(k-1,i-1,mod)%mod))
29
25
744
582
def cmb(n, r): if n - r < r: r = n - r if r == 0: return 1 if r == 1: return n numerator = [n - r + k + 1 for k in range(r)] denominator = [k + 1 for k in range(r)] for p in range(2, r + 1): pivot = denominator[p - 1] if pivot > 1: offset = (n - r) % p for k in range(p - 1, r, p): numerator[k - offset] /= pivot denominator[k] /= pivot result = 1 for k in range(r): if numerator[k] > 1: result *= int(numerator[k]) return result n, k = list(map(int, input().split())) for i in range(1, k + 1): if i > n - k + 1: print((0)) else: print((cmb(n - k + 1, i) % (10**9 + 7) * cmb(k - 1, i - 1) % (10**9 + 7)))
def cmb(n, r, mod): if r < 0 or r > n: return 0 r = min(r, n - r) return g1[n] * g2[r] * g2[n - r] % mod mod = 10**9 + 7 # 出力の制限 N = 10**4 g1 = [1, 1] # 元テーブル g2 = [1, 1] # 逆元テーブル inverse = [0, 1] # 逆元テーブル計算用テーブル for i in range(2, N + 1): g1.append((g1[-1] * i) % mod) inverse.append((-inverse[mod % i] * (mod // i)) % mod) g2.append((g2[-1] * inverse[-1]) % mod) n, k = list(map(int, input().split())) for i in range(1, k + 1): if i > n - k + 1: print((0)) else: print((cmb(n - k + 1, i, mod) * cmb(k - 1, i - 1, mod) % mod))
false
13.793103
[ "-def cmb(n, r):", "- if n - r < r:", "- r = n - r", "- if r == 0:", "- return 1", "- if r == 1:", "- return n", "- numerator = [n - r + k + 1 for k in range(r)]", "- denominator = [k + 1 for k in range(r)]", "- for p in range(2, r + 1):", "- pivot = denominator[p - 1]", "- if pivot > 1:", "- offset = (n - r) % p", "- for k in range(p - 1, r, p):", "- numerator[k - offset] /= pivot", "- denominator[k] /= pivot", "- result = 1", "- for k in range(r):", "- if numerator[k] > 1:", "- result *= int(numerator[k])", "- return result", "+def cmb(n, r, mod):", "+ if r < 0 or r > n:", "+ return 0", "+ r = min(r, n - r)", "+ return g1[n] * g2[r] * g2[n - r] % mod", "+mod = 10**9 + 7 # 出力の制限", "+N = 10**4", "+g1 = [1, 1] # 元テーブル", "+g2 = [1, 1] # 逆元テーブル", "+inverse = [0, 1] # 逆元テーブル計算用テーブル", "+for i in range(2, N + 1):", "+ g1.append((g1[-1] * i) % mod)", "+ inverse.append((-inverse[mod % i] * (mod // i)) % mod)", "+ g2.append((g2[-1] * inverse[-1]) % mod)", "- print((cmb(n - k + 1, i) % (10**9 + 7) * cmb(k - 1, i - 1) % (10**9 + 7)))", "+ print((cmb(n - k + 1, i, mod) * cmb(k - 1, i - 1, mod) % mod))" ]
false
0.154207
0.04685
3.291475
[ "s606146306", "s851013895" ]
u298297089
p03240
python
s667730420
s036499580
301
276
51,440
49,520
Accepted
Accepted
8.31
N = int(eval(input())) A = [] for i in range(N): x,y,h = list(map(int, input().split())) A.append([x,y,h]) H = max([h for x,y,h in A]) while True: for i in range(100+1): for j in range(100+1): for x,y,h in A: tx, ty = abs(x-i), abs(y-j) if max(H - tx - ty, 0) != h: break else: print((i,j,H)) exit() H += 1
n = int(eval(input())) py = [] start = 0 for i in range(n): x,y,h = list(map(int, input().split())) if start < h: start = h py.append((x,y,h)) height = lambda x,y,cx,cy,hh:max(hh -abs(x-cx) -abs(y-cy), 0) while True: for i in range(101): for j in range(101): for a,b,h in py: if height(a,b,i,j,start) != h: # no break else: # ok print((i,j,start)) exit() start += 1
18
22
443
538
N = int(eval(input())) A = [] for i in range(N): x, y, h = list(map(int, input().split())) A.append([x, y, h]) H = max([h for x, y, h in A]) while True: for i in range(100 + 1): for j in range(100 + 1): for x, y, h in A: tx, ty = abs(x - i), abs(y - j) if max(H - tx - ty, 0) != h: break else: print((i, j, H)) exit() H += 1
n = int(eval(input())) py = [] start = 0 for i in range(n): x, y, h = list(map(int, input().split())) if start < h: start = h py.append((x, y, h)) height = lambda x, y, cx, cy, hh: max(hh - abs(x - cx) - abs(y - cy), 0) while True: for i in range(101): for j in range(101): for a, b, h in py: if height(a, b, i, j, start) != h: # no break else: # ok print((i, j, start)) exit() start += 1
false
18.181818
[ "-N = int(eval(input()))", "-A = []", "-for i in range(N):", "+n = int(eval(input()))", "+py = []", "+start = 0", "+for i in range(n):", "- A.append([x, y, h])", "-H = max([h for x, y, h in A])", "+ if start < h:", "+ start = h", "+ py.append((x, y, h))", "+height = lambda x, y, cx, cy, hh: max(hh - abs(x - cx) - abs(y - cy), 0)", "- for i in range(100 + 1):", "- for j in range(100 + 1):", "- for x, y, h in A:", "- tx, ty = abs(x - i), abs(y - j)", "- if max(H - tx - ty, 0) != h:", "+ for i in range(101):", "+ for j in range(101):", "+ for a, b, h in py:", "+ if height(a, b, i, j, start) != h:", "+ # no", "- print((i, j, H))", "+ # ok", "+ print((i, j, start))", "- H += 1", "+ start += 1" ]
false
0.086158
0.089305
0.964752
[ "s667730420", "s036499580" ]
u289547799
p02695
python
s621765700
s513994721
1,680
995
23,060
9,256
Accepted
Accepted
40.77
n, m, q = list(map(int, input().split())) req = [list(map(int, input().split())) for i in range(q)] lst = [] if n == 2: for a in range(1,m+1): for b in range(a, m+1): lst.append([a, b]) if n == 3: for a in range(1,m+1): for b in range(a, m+1): for c in range(b, m+1): lst.append([a, b, c]) if n == 4: for a in range(1,m+1): for b in range(a, m+1): for c in range(b, m+1): for d in range(c, m+1): lst.append([a, b, c, d]) if n == 5: for a in range(1,m+1): for b in range(a, m+1): for c in range(b, m+1): for d in range(c, m+1): for e in range(d, m+1): lst.append([a, b, c, d, e]) if n == 6: for a in range(1,m+1): for b in range(a, m+1): for c in range(b, m+1): for d in range(c, m+1): for e in range(d, m+1): for f in range(e, m+1): lst.append([a, b, c, d, e, f]) if n == 7: for a in range(1,m+1): for b in range(a, m+1): for c in range(b, m+1): for d in range(c, m+1): for e in range(d, m+1): for f in range(e, m+1): for g in range(f, m+1): lst.append([a, b, c, d, e, f, g]) if n == 8: for a in range(1,m+1): for b in range(a, m+1): for c in range(b, m+1): for d in range(c, m+1): for e in range(d, m+1): for f in range(e, m+1): for g in range(f, m+1): for h in range(g, m+1): lst.append([a, b, c, d, e, f, g, h]) if n == 9: for a in range(1,m+1): for b in range(a, m+1): for c in range(b, m+1): for d in range(c, m+1): for e in range(d, m+1): for f in range(e, m+1): for g in range(f, m+1): for h in range(g, m+1): for i in range(h, m+1): lst.append([a, b, c, d, e, f, g, h, i]) if n == 10: for a in range(1,m+1): for b in range(a, m+1): for c in range(b, m+1): for d in range(c, m+1): for e in range(d, m+1): for f in range(e, m+1): for g in range(f, m+1): for h in range(g, m+1): for i in range(h, m+1): for j in range(i, m+1): lst.append([a, b, c, d, e, f, g, h, i, j]) ans = 0 for i in range(len(lst)): res = 0 for j in range(q): if lst[i][req[j][1]-1] - lst[i][req[j][0]-1] == req[j][2]: res += req[j][3] ans = max(ans, res) print(ans)
N, M, Q = list(map(int, input().split())) req = [list(map(int, input().split())) for i in range(Q)] maxi = 0 def dfs(A): global maxi if len(A) == N: # 終端条件 --- 10 重ループまで回したら処理して打ち切り ans = 0 for i in range(Q): if A[req[i][1]-1] - A[req[i][0]-1] == req[i][2]: ans += req[i][3] maxi = max(maxi, ans) return if len(A) == 0: for v in range(1, M+1): A.append(v) dfs(A) A.pop() else: for v in range(A[-1], M+1): A.append(v) dfs(A) A.pop() # これが結構ポイント dfs([]) print(maxi)
96
29
2,776
599
n, m, q = list(map(int, input().split())) req = [list(map(int, input().split())) for i in range(q)] lst = [] if n == 2: for a in range(1, m + 1): for b in range(a, m + 1): lst.append([a, b]) if n == 3: for a in range(1, m + 1): for b in range(a, m + 1): for c in range(b, m + 1): lst.append([a, b, c]) if n == 4: for a in range(1, m + 1): for b in range(a, m + 1): for c in range(b, m + 1): for d in range(c, m + 1): lst.append([a, b, c, d]) if n == 5: for a in range(1, m + 1): for b in range(a, m + 1): for c in range(b, m + 1): for d in range(c, m + 1): for e in range(d, m + 1): lst.append([a, b, c, d, e]) if n == 6: for a in range(1, m + 1): for b in range(a, m + 1): for c in range(b, m + 1): for d in range(c, m + 1): for e in range(d, m + 1): for f in range(e, m + 1): lst.append([a, b, c, d, e, f]) if n == 7: for a in range(1, m + 1): for b in range(a, m + 1): for c in range(b, m + 1): for d in range(c, m + 1): for e in range(d, m + 1): for f in range(e, m + 1): for g in range(f, m + 1): lst.append([a, b, c, d, e, f, g]) if n == 8: for a in range(1, m + 1): for b in range(a, m + 1): for c in range(b, m + 1): for d in range(c, m + 1): for e in range(d, m + 1): for f in range(e, m + 1): for g in range(f, m + 1): for h in range(g, m + 1): lst.append([a, b, c, d, e, f, g, h]) if n == 9: for a in range(1, m + 1): for b in range(a, m + 1): for c in range(b, m + 1): for d in range(c, m + 1): for e in range(d, m + 1): for f in range(e, m + 1): for g in range(f, m + 1): for h in range(g, m + 1): for i in range(h, m + 1): lst.append([a, b, c, d, e, f, g, h, i]) if n == 10: for a in range(1, m + 1): for b in range(a, m + 1): for c in range(b, m + 1): for d in range(c, m + 1): for e in range(d, m + 1): for f in range(e, m + 1): for g in range(f, m + 1): for h in range(g, m + 1): for i in range(h, m + 1): for j in range(i, m + 1): lst.append([a, b, c, d, e, f, g, h, i, j]) ans = 0 for i in range(len(lst)): res = 0 for j in range(q): if lst[i][req[j][1] - 1] - lst[i][req[j][0] - 1] == req[j][2]: res += req[j][3] ans = max(ans, res) print(ans)
N, M, Q = list(map(int, input().split())) req = [list(map(int, input().split())) for i in range(Q)] maxi = 0 def dfs(A): global maxi if len(A) == N: # 終端条件 --- 10 重ループまで回したら処理して打ち切り ans = 0 for i in range(Q): if A[req[i][1] - 1] - A[req[i][0] - 1] == req[i][2]: ans += req[i][3] maxi = max(maxi, ans) return if len(A) == 0: for v in range(1, M + 1): A.append(v) dfs(A) A.pop() else: for v in range(A[-1], M + 1): A.append(v) dfs(A) A.pop() # これが結構ポイント dfs([]) print(maxi)
false
69.791667
[ "-n, m, q = list(map(int, input().split()))", "-req = [list(map(int, input().split())) for i in range(q)]", "-lst = []", "-if n == 2:", "- for a in range(1, m + 1):", "- for b in range(a, m + 1):", "- lst.append([a, b])", "-if n == 3:", "- for a in range(1, m + 1):", "- for b in range(a, m + 1):", "- for c in range(b, m + 1):", "- lst.append([a, b, c])", "-if n == 4:", "- for a in range(1, m + 1):", "- for b in range(a, m + 1):", "- for c in range(b, m + 1):", "- for d in range(c, m + 1):", "- lst.append([a, b, c, d])", "-if n == 5:", "- for a in range(1, m + 1):", "- for b in range(a, m + 1):", "- for c in range(b, m + 1):", "- for d in range(c, m + 1):", "- for e in range(d, m + 1):", "- lst.append([a, b, c, d, e])", "-if n == 6:", "- for a in range(1, m + 1):", "- for b in range(a, m + 1):", "- for c in range(b, m + 1):", "- for d in range(c, m + 1):", "- for e in range(d, m + 1):", "- for f in range(e, m + 1):", "- lst.append([a, b, c, d, e, f])", "-if n == 7:", "- for a in range(1, m + 1):", "- for b in range(a, m + 1):", "- for c in range(b, m + 1):", "- for d in range(c, m + 1):", "- for e in range(d, m + 1):", "- for f in range(e, m + 1):", "- for g in range(f, m + 1):", "- lst.append([a, b, c, d, e, f, g])", "-if n == 8:", "- for a in range(1, m + 1):", "- for b in range(a, m + 1):", "- for c in range(b, m + 1):", "- for d in range(c, m + 1):", "- for e in range(d, m + 1):", "- for f in range(e, m + 1):", "- for g in range(f, m + 1):", "- for h in range(g, m + 1):", "- lst.append([a, b, c, d, e, f, g, h])", "-if n == 9:", "- for a in range(1, m + 1):", "- for b in range(a, m + 1):", "- for c in range(b, m + 1):", "- for d in range(c, m + 1):", "- for e in range(d, m + 1):", "- for f in range(e, m + 1):", "- for g in range(f, m + 1):", "- for h in range(g, m + 1):", "- for i in range(h, m + 1):", "- lst.append([a, b, c, d, e, f, g, h, i])", "-if n == 10:", "- for a in range(1, m + 1):", "- for b in range(a, m + 1):", "- for c in range(b, m + 1):", "- for d in range(c, m + 1):", "- for e in range(d, m + 1):", "- for f in range(e, m + 1):", "- for g in range(f, m + 1):", "- for h in range(g, m + 1):", "- for i in range(h, m + 1):", "- for j in range(i, m + 1):", "- lst.append([a, b, c, d, e, f, g, h, i, j])", "-ans = 0", "-for i in range(len(lst)):", "- res = 0", "- for j in range(q):", "- if lst[i][req[j][1] - 1] - lst[i][req[j][0] - 1] == req[j][2]:", "- res += req[j][3]", "- ans = max(ans, res)", "-print(ans)", "+N, M, Q = list(map(int, input().split()))", "+req = [list(map(int, input().split())) for i in range(Q)]", "+maxi = 0", "+", "+", "+def dfs(A):", "+ global maxi", "+ ans = 0", "+ for i in range(Q):", "+ if A[req[i][1] - 1] - A[req[i][0] - 1] == req[i][2]:", "+ ans += req[i][3]", "+ maxi = max(maxi, ans)", "+ return", "+ if len(A) == 0:", "+ for v in range(1, M + 1):", "+ A.append(v)", "+ dfs(A)", "+ A.pop()", "+ else:", "+ for v in range(A[-1], M + 1):", "+ A.append(v)", "+ dfs(A)", "+ A.pop() # これが結構ポイント", "+", "+", "+dfs([])", "+print(maxi)" ]
false
0.19255
0.061924
3.10945
[ "s621765700", "s513994721" ]
u222668979
p03330
python
s617889119
s201587783
158
144
76,620
76,524
Accepted
Accepted
8.86
from itertools import permutations n, c = list(map(int, input().split())) d = [list(map(int, input().split())) for _ in range(c)] cmat = [list(map(int, input().split())) for _ in range(n)] dcnt = [[0] * c for _ in range(3)] for i in range(n): for j in range(n): mod = (i + j) % 3 dcnt[mod][cmat[i][j] - 1] += 1 ans = 10 ** 9 for color in permutations(list(range(c)), 3): tmp = 0 for tgt, cnt in zip(color, dcnt): tmp += sum(d[i][tgt] * cnt[i] for i in range(c)) ans = min(ans, tmp) print(ans)
from itertools import permutations n, c = list(map(int, input().split())) d = [list(map(int, input().split())) for _ in range(c)] cmat = [list(map(int, input().split())) for _ in range(n)] dcnt = [[0] * c for _ in range(3)] for i, ci in enumerate(cmat): for j, cij in enumerate(ci): mod = (i + j) % 3 dcnt[mod][cij - 1] += 1 ans = 10 ** 9 for color in permutations(list(range(c)), 3): tmp = 0 for tgt, cnt in zip(color, dcnt): tmp += sum(d[i][tgt] * cnt[i] for i in range(c)) ans = min(ans, tmp) print(ans)
19
19
542
556
from itertools import permutations n, c = list(map(int, input().split())) d = [list(map(int, input().split())) for _ in range(c)] cmat = [list(map(int, input().split())) for _ in range(n)] dcnt = [[0] * c for _ in range(3)] for i in range(n): for j in range(n): mod = (i + j) % 3 dcnt[mod][cmat[i][j] - 1] += 1 ans = 10**9 for color in permutations(list(range(c)), 3): tmp = 0 for tgt, cnt in zip(color, dcnt): tmp += sum(d[i][tgt] * cnt[i] for i in range(c)) ans = min(ans, tmp) print(ans)
from itertools import permutations n, c = list(map(int, input().split())) d = [list(map(int, input().split())) for _ in range(c)] cmat = [list(map(int, input().split())) for _ in range(n)] dcnt = [[0] * c for _ in range(3)] for i, ci in enumerate(cmat): for j, cij in enumerate(ci): mod = (i + j) % 3 dcnt[mod][cij - 1] += 1 ans = 10**9 for color in permutations(list(range(c)), 3): tmp = 0 for tgt, cnt in zip(color, dcnt): tmp += sum(d[i][tgt] * cnt[i] for i in range(c)) ans = min(ans, tmp) print(ans)
false
0
[ "-for i in range(n):", "- for j in range(n):", "+for i, ci in enumerate(cmat):", "+ for j, cij in enumerate(ci):", "- dcnt[mod][cmat[i][j] - 1] += 1", "+ dcnt[mod][cij - 1] += 1" ]
false
0.04479
0.043622
1.026771
[ "s617889119", "s201587783" ]
u585482323
p03767
python
s416388741
s868840850
644
316
120,508
77,936
Accepted
Accepted
50.93
#!usr/bin/env python3 from collections import defaultdict,deque from heapq import heappush, heappop import sys import math import bisect import random def LI(): return [int(x) for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS():return [list(x) for x in sys.stdin.readline().split()] def S(): return list(sys.stdin.readline())[:-1] def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] sys.setrecursionlimit(1000000) mod = 1000000007 #A def A(): n = I() a = LI() a.sort(key = lambda x:-x) ans = 0 for i in range(n): ans += a[2*i+1] print(ans) return #B def B(): def dfs(d,x,c): if d <= dp[x]: return dp[x] = d if not f[x]: f[x] = c for y in v[x]: dfs(d-1,y,c) n,m = LI() f = [0]*n v = [[] for i in range(n)] for i in range(m): a,b = LI() a -= 1 b -= 1 v[a].append(b) v[b].append(a) dp = defaultdict(lambda : -1) q = I() l = LIR(q) l = l[::-1] for x,d,c in l: x -= 1 dfs(d,x,c) for i in f: print(i) return #C def C(): n = I() return #D def D(): n = I() return #E def E(): n = I() return #F def F(): n = I() return #Solve if __name__ == "__main__": A()
#!usr/bin/env python3 from collections import defaultdict, deque from heapq import heappush, heappop from itertools import permutations, accumulate import sys import math import bisect def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()] def I(): return int(sys.stdin.buffer.readline()) def LS():return [list(x) for x in sys.stdin.readline().split()] def S(): res = list(sys.stdin.readline()) if res[-1] == "\n": return res[:-1] return res def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] sys.setrecursionlimit(1000000) mod = 1000000007 def solve(): n = I() a = LI() a.sort(reverse=True) print((sum(a[1:2*n:2]))) return #Solve if __name__ == "__main__": solve()
91
37
1,576
900
#!usr/bin/env python3 from collections import defaultdict, deque from heapq import heappush, heappop import sys import math import bisect import random def LI(): return [int(x) for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS(): return [list(x) for x in sys.stdin.readline().split()] def S(): return list(sys.stdin.readline())[:-1] def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] sys.setrecursionlimit(1000000) mod = 1000000007 # A def A(): n = I() a = LI() a.sort(key=lambda x: -x) ans = 0 for i in range(n): ans += a[2 * i + 1] print(ans) return # B def B(): def dfs(d, x, c): if d <= dp[x]: return dp[x] = d if not f[x]: f[x] = c for y in v[x]: dfs(d - 1, y, c) n, m = LI() f = [0] * n v = [[] for i in range(n)] for i in range(m): a, b = LI() a -= 1 b -= 1 v[a].append(b) v[b].append(a) dp = defaultdict(lambda: -1) q = I() l = LIR(q) l = l[::-1] for x, d, c in l: x -= 1 dfs(d, x, c) for i in f: print(i) return # C def C(): n = I() return # D def D(): n = I() return # E def E(): n = I() return # F def F(): n = I() return # Solve if __name__ == "__main__": A()
#!usr/bin/env python3 from collections import defaultdict, deque from heapq import heappush, heappop from itertools import permutations, accumulate import sys import math import bisect def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()] def I(): return int(sys.stdin.buffer.readline()) def LS(): return [list(x) for x in sys.stdin.readline().split()] def S(): res = list(sys.stdin.readline()) if res[-1] == "\n": return res[:-1] return res def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] sys.setrecursionlimit(1000000) mod = 1000000007 def solve(): n = I() a = LI() a.sort(reverse=True) print((sum(a[1 : 2 * n : 2]))) return # Solve if __name__ == "__main__": solve()
false
59.340659
[ "+from itertools import permutations, accumulate", "-import random", "- return [int(x) for x in sys.stdin.readline().split()]", "+ return [int(x) for x in sys.stdin.buffer.readline().split()]", "- return int(sys.stdin.readline())", "+ return int(sys.stdin.buffer.readline())", "- return list(sys.stdin.readline())[:-1]", "+ res = list(sys.stdin.readline())", "+ if res[-1] == \"\\n\":", "+ return res[:-1]", "+ return res", "-# A", "-def A():", "+", "+", "+def solve():", "- a.sort(key=lambda x: -x)", "- ans = 0", "- for i in range(n):", "- ans += a[2 * i + 1]", "- print(ans)", "- return", "-", "-", "-# B", "-def B():", "- def dfs(d, x, c):", "- if d <= dp[x]:", "- return", "- dp[x] = d", "- if not f[x]:", "- f[x] = c", "- for y in v[x]:", "- dfs(d - 1, y, c)", "-", "- n, m = LI()", "- f = [0] * n", "- v = [[] for i in range(n)]", "- for i in range(m):", "- a, b = LI()", "- a -= 1", "- b -= 1", "- v[a].append(b)", "- v[b].append(a)", "- dp = defaultdict(lambda: -1)", "- q = I()", "- l = LIR(q)", "- l = l[::-1]", "- for x, d, c in l:", "- x -= 1", "- dfs(d, x, c)", "- for i in f:", "- print(i)", "- return", "-", "-", "-# C", "-def C():", "- n = I()", "- return", "-", "-", "-# D", "-def D():", "- n = I()", "- return", "-", "-", "-# E", "-def E():", "- n = I()", "- return", "-", "-", "-# F", "-def F():", "- n = I()", "+ a.sort(reverse=True)", "+ print((sum(a[1 : 2 * n : 2])))", "- A()", "+ solve()" ]
false
0.046577
0.047013
0.990727
[ "s416388741", "s868840850" ]
u399973890
p02848
python
s559397900
s649424427
25
23
3,188
3,316
Accepted
Accepted
8
N = int(eval(input())) S = list(eval(input())) alphabet = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'] answer = [] for s in S: number = alphabet.index(s) while number + N >= 26: number = number - 26 answer.append(alphabet[number+N]) print((''.join(answer)))
def minus26(idx): while idx >= 26: idx = idx - 26 return idx N = int(eval(input())) S = list(eval(input())) alphabet = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'] S_idx = [alphabet.index(s)+N for s in S] S_idx = [minus26(idx) for idx in S_idx] print((''.join([alphabet[idx] for idx in S_idx])))
14
16
401
443
N = int(eval(input())) S = list(eval(input())) alphabet = [ "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", ] answer = [] for s in S: number = alphabet.index(s) while number + N >= 26: number = number - 26 answer.append(alphabet[number + N]) print(("".join(answer)))
def minus26(idx): while idx >= 26: idx = idx - 26 return idx N = int(eval(input())) S = list(eval(input())) alphabet = [ "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", ] S_idx = [alphabet.index(s) + N for s in S] S_idx = [minus26(idx) for idx in S_idx] print(("".join([alphabet[idx] for idx in S_idx])))
false
12.5
[ "+def minus26(idx):", "+ while idx >= 26:", "+ idx = idx - 26", "+ return idx", "+", "+", "-answer = []", "-for s in S:", "- number = alphabet.index(s)", "- while number + N >= 26:", "- number = number - 26", "- answer.append(alphabet[number + N])", "-print((\"\".join(answer)))", "+S_idx = [alphabet.index(s) + N for s in S]", "+S_idx = [minus26(idx) for idx in S_idx]", "+print((\"\".join([alphabet[idx] for idx in S_idx])))" ]
false
0.045079
0.038248
1.178592
[ "s559397900", "s649424427" ]
u968166680
p02788
python
s920497436
s178607436
644
580
148,056
152,628
Accepted
Accepted
9.94
import sys from bisect import bisect_left read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 MOD = 1000000007 def main(): N, D, A, *XH = list(map(int, read().split())) monster = [0] * N for i, (x, h) in enumerate(zip(*[iter(XH)] * 2)): monster[i] = (x, (h + A - 1) // A) monster.sort() pos = [] damage = [] left = right = 0 cum_damage = 0 ans = 0 for x, h in monster: left = right right = bisect_left(pos, x) cum_damage -= sum(damage[left:right]) if h > cum_damage: pos.append(x + 2 * D) damage.append(h - cum_damage) ans += h - cum_damage cum_damage += h - cum_damage print(ans) return if __name__ == '__main__': main()
import sys from bisect import bisect_left read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 MOD = 1000000007 def main(): N, D, A, *XH = list(map(int, read().split())) monster = [0] * N for i, (x, h) in enumerate(zip(*[iter(XH)] * 2)): monster[i] = (x, (h + A - 1) // A) monster.sort() pos = [] damage = [] idx = 0 cur_damage = 0 ans = 0 for x, h in monster: while idx < len(pos) and pos[idx] < x: cur_damage -= damage[idx] idx += 1 if h > cur_damage: pos.append(x + 2 * D) damage.append(h - cur_damage) ans += h - cur_damage cur_damage += h - cur_damage print(ans) return if __name__ == '__main__': main()
43
43
886
880
import sys from bisect import bisect_left read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10**9) INF = 1 << 60 MOD = 1000000007 def main(): N, D, A, *XH = list(map(int, read().split())) monster = [0] * N for i, (x, h) in enumerate(zip(*[iter(XH)] * 2)): monster[i] = (x, (h + A - 1) // A) monster.sort() pos = [] damage = [] left = right = 0 cum_damage = 0 ans = 0 for x, h in monster: left = right right = bisect_left(pos, x) cum_damage -= sum(damage[left:right]) if h > cum_damage: pos.append(x + 2 * D) damage.append(h - cum_damage) ans += h - cum_damage cum_damage += h - cum_damage print(ans) return if __name__ == "__main__": main()
import sys from bisect import bisect_left read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10**9) INF = 1 << 60 MOD = 1000000007 def main(): N, D, A, *XH = list(map(int, read().split())) monster = [0] * N for i, (x, h) in enumerate(zip(*[iter(XH)] * 2)): monster[i] = (x, (h + A - 1) // A) monster.sort() pos = [] damage = [] idx = 0 cur_damage = 0 ans = 0 for x, h in monster: while idx < len(pos) and pos[idx] < x: cur_damage -= damage[idx] idx += 1 if h > cur_damage: pos.append(x + 2 * D) damage.append(h - cur_damage) ans += h - cur_damage cur_damage += h - cur_damage print(ans) return if __name__ == "__main__": main()
false
0
[ "- left = right = 0", "- cum_damage = 0", "+ idx = 0", "+ cur_damage = 0", "- left = right", "- right = bisect_left(pos, x)", "- cum_damage -= sum(damage[left:right])", "- if h > cum_damage:", "+ while idx < len(pos) and pos[idx] < x:", "+ cur_damage -= damage[idx]", "+ idx += 1", "+ if h > cur_damage:", "- damage.append(h - cum_damage)", "- ans += h - cum_damage", "- cum_damage += h - cum_damage", "+ damage.append(h - cur_damage)", "+ ans += h - cur_damage", "+ cur_damage += h - cur_damage" ]
false
0.038764
0.03697
1.048516
[ "s920497436", "s178607436" ]
u562935282
p03290
python
s077360451
s866862433
360
21
3,064
3,064
Accepted
Accepted
94.17
inf = float('inf') def rec(cur, partially_solved, solve_num, score): if cur == d: return solve_num if score >= g else inf res = rec(cur + 1, partially_solved, solve_num, score) res = min(res, rec(cur + 1, partially_solved, solve_num + p[cur], score + p[cur] * (cur + 1) * 100 + c[cur])) if not partially_solved: for i in range(1, p[cur]): res = min(res, rec(cur + 1, True, solve_num + i, score + i * (cur + 1) * 100)) return res d, g = list(map(int, input().split())) p, c = [], [] for _ in range(d): tp, tc = list(map(int, input().split())) p.append(tp) c.append(tc) print((rec(0, False, 0, 0)))
def main(): from itertools import product D, G = list(map(int, input().split())) prob = [] for j in range(1, D + 1): p, c = list(map(int, input().split())) prob.append((j * 100, p, c)) # score,amount,bonus ans = -1 for prd in product([0, 1], repeat=D): cnt = 0 g = 0 for j, (score, amount, bonus) in zip(prd, prob): if j: cnt += amount g += score * amount + bonus if g < G: for j, (score, amount, bonus) in reversed(tuple(zip(prd, prob))): if (not j) and (score * amount >= G - g): use = (G - g + score - 1) // score cnt += use g += score * use break if (g < G) or (~ans and ans <= cnt): continue ans = cnt print(ans) if __name__ == '__main__': main()
25
35
709
931
inf = float("inf") def rec(cur, partially_solved, solve_num, score): if cur == d: return solve_num if score >= g else inf res = rec(cur + 1, partially_solved, solve_num, score) res = min( res, rec( cur + 1, partially_solved, solve_num + p[cur], score + p[cur] * (cur + 1) * 100 + c[cur], ), ) if not partially_solved: for i in range(1, p[cur]): res = min( res, rec(cur + 1, True, solve_num + i, score + i * (cur + 1) * 100) ) return res d, g = list(map(int, input().split())) p, c = [], [] for _ in range(d): tp, tc = list(map(int, input().split())) p.append(tp) c.append(tc) print((rec(0, False, 0, 0)))
def main(): from itertools import product D, G = list(map(int, input().split())) prob = [] for j in range(1, D + 1): p, c = list(map(int, input().split())) prob.append((j * 100, p, c)) # score,amount,bonus ans = -1 for prd in product([0, 1], repeat=D): cnt = 0 g = 0 for j, (score, amount, bonus) in zip(prd, prob): if j: cnt += amount g += score * amount + bonus if g < G: for j, (score, amount, bonus) in reversed(tuple(zip(prd, prob))): if (not j) and (score * amount >= G - g): use = (G - g + score - 1) // score cnt += use g += score * use break if (g < G) or (~ans and ans <= cnt): continue ans = cnt print(ans) if __name__ == "__main__": main()
false
28.571429
[ "-inf = float(\"inf\")", "+def main():", "+ from itertools import product", "+", "+ D, G = list(map(int, input().split()))", "+ prob = []", "+ for j in range(1, D + 1):", "+ p, c = list(map(int, input().split()))", "+ prob.append((j * 100, p, c)) # score,amount,bonus", "+ ans = -1", "+ for prd in product([0, 1], repeat=D):", "+ cnt = 0", "+ g = 0", "+ for j, (score, amount, bonus) in zip(prd, prob):", "+ if j:", "+ cnt += amount", "+ g += score * amount + bonus", "+ if g < G:", "+ for j, (score, amount, bonus) in reversed(tuple(zip(prd, prob))):", "+ if (not j) and (score * amount >= G - g):", "+ use = (G - g + score - 1) // score", "+ cnt += use", "+ g += score * use", "+ break", "+ if (g < G) or (~ans and ans <= cnt):", "+ continue", "+ ans = cnt", "+ print(ans)", "-def rec(cur, partially_solved, solve_num, score):", "- if cur == d:", "- return solve_num if score >= g else inf", "- res = rec(cur + 1, partially_solved, solve_num, score)", "- res = min(", "- res,", "- rec(", "- cur + 1,", "- partially_solved,", "- solve_num + p[cur],", "- score + p[cur] * (cur + 1) * 100 + c[cur],", "- ),", "- )", "- if not partially_solved:", "- for i in range(1, p[cur]):", "- res = min(", "- res, rec(cur + 1, True, solve_num + i, score + i * (cur + 1) * 100)", "- )", "- return res", "-", "-", "-d, g = list(map(int, input().split()))", "-p, c = [], []", "-for _ in range(d):", "- tp, tc = list(map(int, input().split()))", "- p.append(tp)", "- c.append(tc)", "-print((rec(0, False, 0, 0)))", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.041299
0.037146
1.111797
[ "s077360451", "s866862433" ]
u461833298
p02861
python
s166750835
s045922177
351
203
3,188
3,064
Accepted
Accepted
42.17
import itertools import math N = int(eval(input())) P = [[int(x) for x in input().split()] for _ in range(N)] ans=0 for p in itertools.permutations(P): for (x1, y1), (x2, y2) in zip(p, p[1:]): ans += ((x1-x2)**2 + (y1-y2)**2)**.5 print((ans/math.factorial(N)))
import itertools import math N = int(eval(input())) P = [[int(x) for x in input().split()] for _ in range(N)] ans=0 for p in itertools.permutations(P): for (x1, y1), (x2, y2) in zip(p, p[1:]): ans += math.hypot(x1-x2, y1-y2) print((ans/math.factorial(N)))
10
10
274
269
import itertools import math N = int(eval(input())) P = [[int(x) for x in input().split()] for _ in range(N)] ans = 0 for p in itertools.permutations(P): for (x1, y1), (x2, y2) in zip(p, p[1:]): ans += ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5 print((ans / math.factorial(N)))
import itertools import math N = int(eval(input())) P = [[int(x) for x in input().split()] for _ in range(N)] ans = 0 for p in itertools.permutations(P): for (x1, y1), (x2, y2) in zip(p, p[1:]): ans += math.hypot(x1 - x2, y1 - y2) print((ans / math.factorial(N)))
false
0
[ "- ans += ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5", "+ ans += math.hypot(x1 - x2, y1 - y2)" ]
false
0.04126
0.045001
0.916879
[ "s166750835", "s045922177" ]
u952467214
p03475
python
s883370878
s937301144
128
84
3,444
3,444
Accepted
Accepted
34.38
import sys sys.setrecursionlimit(10 ** 7) input = sys.stdin.readline n = int(eval(input())) c = [0]*(n-1) s = [0]*(n-1) f = [0]*(n-1) for i in range(n-1): c[i], s[i], f[i] = list(map(int, input().split())) def dfs(eki,t): if eki == n-1: return t cc = c[eki] ss = s[eki] ff = f[eki] m = max(0,-(-t+ss)//ff) if t < ss: return dfs(eki+1, ss+cc) else: return dfs(eki+1, -(-t//ff)*ff+cc) for i in range(n): print((dfs(i,0)))
import sys sys.setrecursionlimit(10 ** 7) input = sys.stdin.readline n = int(eval(input())) c = [0]*(n-1) s = [0]*(n-1) f = [0]*(n-1) for i in range(n-1): c[i], s[i], f[i] = list(map(int, input().split())) def dfs(eki,t): if eki == n-1: return t cc = c[eki] ss = s[eki] ff = f[eki] if t < ss: return dfs(eki+1, ss+cc) else: return dfs(eki+1, -(-t//ff)*ff+cc) for i in range(n): print((dfs(i,0)))
28
28
499
472
import sys sys.setrecursionlimit(10**7) input = sys.stdin.readline n = int(eval(input())) c = [0] * (n - 1) s = [0] * (n - 1) f = [0] * (n - 1) for i in range(n - 1): c[i], s[i], f[i] = list(map(int, input().split())) def dfs(eki, t): if eki == n - 1: return t cc = c[eki] ss = s[eki] ff = f[eki] m = max(0, -(-t + ss) // ff) if t < ss: return dfs(eki + 1, ss + cc) else: return dfs(eki + 1, -(-t // ff) * ff + cc) for i in range(n): print((dfs(i, 0)))
import sys sys.setrecursionlimit(10**7) input = sys.stdin.readline n = int(eval(input())) c = [0] * (n - 1) s = [0] * (n - 1) f = [0] * (n - 1) for i in range(n - 1): c[i], s[i], f[i] = list(map(int, input().split())) def dfs(eki, t): if eki == n - 1: return t cc = c[eki] ss = s[eki] ff = f[eki] if t < ss: return dfs(eki + 1, ss + cc) else: return dfs(eki + 1, -(-t // ff) * ff + cc) for i in range(n): print((dfs(i, 0)))
false
0
[ "- m = max(0, -(-t + ss) // ff)" ]
false
0.099985
0.112021
0.892562
[ "s883370878", "s937301144" ]
u905203728
p03354
python
s992408886
s821734521
1,632
684
127,596
35,276
Accepted
Accepted
58.09
#Union Findで連結を判定 N,M = list(map(int,input().split())) *P, = list(map(int,input().split())) XY = [list(map(int,input().split())) for _ in range(M)] class UnionFind: def __init__(self,N): self.Parent = [-1]*N def get_Parent(self,n): if self.Parent[n] == -1:return n p = self.get_Parent(self.Parent[n]) self.Parent[n] = p return p def merge(self,x,y): x = self.get_Parent(x) y = self.get_Parent(y) if x!=y: self.Parent[y] = x return def is_united(self,x,y): return self.get_Parent(x)==self.get_Parent(y) U = UnionFind(N) for x,y in XY: x-=1 y-=1 U.merge(x,y) print((sum(U.is_united(i,p-1) for i,p in enumerate(P))))
class UnionFind(): def __init__(self,n): self.n=n self.root=[-1]*n self.rank=[-1]*n def Find_Root(self,x): if self.root[x]<0:return x else: self.root[x]=self.Find_Root(self.root[x]) return self.root[x] def Unite(self,x,y): x=self.Find_Root(x) y=self.Find_Root(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 isSameGroup(self,x,y): return self.Find_Root(x)==self.Find_Root(y) def Count(self,x): return -self.root[self.Find_Root(x)] def members(self,x): root=self.Find_Root(x) return [i for i in range(self.n) if self.Find_Root(i)==root] def address(self): return[i for i,j in enumerate(self.root) if j<0] def group_members(self): return {i: self.members(i) for i in self.address()} def size(self,x): return -self.root[self.Find_Root(x)] n,m=list(map(int,input().split())) P=list(map(int,input().split())) XY=[list(map(int,input().split())) for i in range(m)] UnionFind=UnionFind(n) for x,y in XY: UnionFind.Unite(x-1,y-1) print((sum([UnionFind.isSameGroup(i,j-1) for i,j in enumerate(P)])))
27
55
735
1,470
# Union Findで連結を判定 N, M = list(map(int, input().split())) (*P,) = list(map(int, input().split())) XY = [list(map(int, input().split())) for _ in range(M)] class UnionFind: def __init__(self, N): self.Parent = [-1] * N def get_Parent(self, n): if self.Parent[n] == -1: return n p = self.get_Parent(self.Parent[n]) self.Parent[n] = p return p def merge(self, x, y): x = self.get_Parent(x) y = self.get_Parent(y) if x != y: self.Parent[y] = x return def is_united(self, x, y): return self.get_Parent(x) == self.get_Parent(y) U = UnionFind(N) for x, y in XY: x -= 1 y -= 1 U.merge(x, y) print((sum(U.is_united(i, p - 1) for i, p in enumerate(P))))
class UnionFind: def __init__(self, n): self.n = n self.root = [-1] * n self.rank = [-1] * n def Find_Root(self, x): if self.root[x] < 0: return x else: self.root[x] = self.Find_Root(self.root[x]) return self.root[x] def Unite(self, x, y): x = self.Find_Root(x) y = self.Find_Root(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 isSameGroup(self, x, y): return self.Find_Root(x) == self.Find_Root(y) def Count(self, x): return -self.root[self.Find_Root(x)] def members(self, x): root = self.Find_Root(x) return [i for i in range(self.n) if self.Find_Root(i) == root] def address(self): return [i for i, j in enumerate(self.root) if j < 0] def group_members(self): return {i: self.members(i) for i in self.address()} def size(self, x): return -self.root[self.Find_Root(x)] n, m = list(map(int, input().split())) P = list(map(int, input().split())) XY = [list(map(int, input().split())) for i in range(m)] UnionFind = UnionFind(n) for x, y in XY: UnionFind.Unite(x - 1, y - 1) print((sum([UnionFind.isSameGroup(i, j - 1) for i, j in enumerate(P)])))
false
50.909091
[ "-# Union Findで連結を判定", "-N, M = list(map(int, input().split()))", "-(*P,) = list(map(int, input().split()))", "-XY = [list(map(int, input().split())) for _ in range(M)]", "+class UnionFind:", "+ def __init__(self, n):", "+ self.n = n", "+ self.root = [-1] * n", "+ self.rank = [-1] * n", "+", "+ def Find_Root(self, x):", "+ if self.root[x] < 0:", "+ return x", "+ else:", "+ self.root[x] = self.Find_Root(self.root[x])", "+ return self.root[x]", "+", "+ def Unite(self, x, y):", "+ x = self.Find_Root(x)", "+ y = self.Find_Root(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 isSameGroup(self, x, y):", "+ return self.Find_Root(x) == self.Find_Root(y)", "+", "+ def Count(self, x):", "+ return -self.root[self.Find_Root(x)]", "+", "+ def members(self, x):", "+ root = self.Find_Root(x)", "+ return [i for i in range(self.n) if self.Find_Root(i) == root]", "+", "+ def address(self):", "+ return [i for i, j in enumerate(self.root) if j < 0]", "+", "+ def group_members(self):", "+ return {i: self.members(i) for i in self.address()}", "+", "+ def size(self, x):", "+ return -self.root[self.Find_Root(x)]", "-class UnionFind:", "- def __init__(self, N):", "- self.Parent = [-1] * N", "-", "- def get_Parent(self, n):", "- if self.Parent[n] == -1:", "- return n", "- p = self.get_Parent(self.Parent[n])", "- self.Parent[n] = p", "- return p", "-", "- def merge(self, x, y):", "- x = self.get_Parent(x)", "- y = self.get_Parent(y)", "- if x != y:", "- self.Parent[y] = x", "- return", "-", "- def is_united(self, x, y):", "- return self.get_Parent(x) == self.get_Parent(y)", "-", "-", "-U = UnionFind(N)", "+n, m = list(map(int, input().split()))", "+P = list(map(int, input().split()))", "+XY = [list(map(int, input().split())) for i in range(m)]", "+UnionFind = UnionFind(n)", "- x -= 1", "- y -= 1", "- U.merge(x, y)", "-print((sum(U.is_united(i, p - 1) for i, p in enumerate(P))))", "+ UnionFind.Unite(x - 1, y - 1)", "+print((sum([UnionFind.isSameGroup(i, j - 1) for i, j in enumerate(P)])))" ]
false
0.041779
0.047141
0.886252
[ "s992408886", "s821734521" ]
u573754721
p02952
python
s983728385
s384054720
57
47
2,940
2,940
Accepted
Accepted
17.54
n=int(eval(input())) c=0 for i in range(1,n+1): if len(str(i))%2!=0: c+=1 print(c)
n=int(eval(input())) print((sum(len(str(i))%2 for i in range(1,n+1))))
6
2
100
63
n = int(eval(input())) c = 0 for i in range(1, n + 1): if len(str(i)) % 2 != 0: c += 1 print(c)
n = int(eval(input())) print((sum(len(str(i)) % 2 for i in range(1, n + 1))))
false
66.666667
[ "-c = 0", "-for i in range(1, n + 1):", "- if len(str(i)) % 2 != 0:", "- c += 1", "-print(c)", "+print((sum(len(str(i)) % 2 for i in range(1, n + 1))))" ]
false
0.112358
0.055875
2.010884
[ "s983728385", "s384054720" ]
u585348179
p02713
python
s727100148
s779362347
1,061
961
69,464
69,780
Accepted
Accepted
9.43
K=int(eval(input())) import itertools,math from functools import reduce data = [i for i in range(1,K+1)] def gcd(*numbers): return reduce(math.gcd, numbers) ans = 0 for a,b,c in itertools.product(data, repeat=3): ans += gcd(a,b,c) print(ans)
K=int(eval(input())) import math from functools import reduce def gcd(*numbers): return reduce(math.gcd, numbers) ans = 0 for a in range(1,K+1): for b in range(1,K+1): for c in range(1,K+1): ans += gcd(a,b,c) print(ans)
15
15
263
260
K = int(eval(input())) import itertools, math from functools import reduce data = [i for i in range(1, K + 1)] def gcd(*numbers): return reduce(math.gcd, numbers) ans = 0 for a, b, c in itertools.product(data, repeat=3): ans += gcd(a, b, c) print(ans)
K = int(eval(input())) import math from functools import reduce def gcd(*numbers): return reduce(math.gcd, numbers) ans = 0 for a in range(1, K + 1): for b in range(1, K + 1): for c in range(1, K + 1): ans += gcd(a, b, c) print(ans)
false
0
[ "-import itertools, math", "+import math", "-", "-data = [i for i in range(1, K + 1)]", "-for a, b, c in itertools.product(data, repeat=3):", "- ans += gcd(a, b, c)", "+for a in range(1, K + 1):", "+ for b in range(1, K + 1):", "+ for c in range(1, K + 1):", "+ ans += gcd(a, b, c)" ]
false
0.047997
0.041945
1.14428
[ "s727100148", "s779362347" ]
u488127128
p03448
python
s918865315
s173728555
49
44
3,060
3,060
Accepted
Accepted
10.2
A = int(eval(input())) B = int(eval(input())) C = int(eval(input())) x = int(eval(input())) count = 0 if x % 50 != 0: print((0)) else: for c in range(C+1): for b in range(B+1): for a in range(A+1): if c*50 + b*100 + a*500 == x: count += 1 print(count)
A = int(eval(input())) B = int(eval(input())) C = int(eval(input())) x = int(eval(input())) print((sum([1 for a in range(A+1) for b in range(B+1) for c in range(C+1) if 500*a + 100*b + 50*c == x])))
15
5
308
176
A = int(eval(input())) B = int(eval(input())) C = int(eval(input())) x = int(eval(input())) count = 0 if x % 50 != 0: print((0)) else: for c in range(C + 1): for b in range(B + 1): for a in range(A + 1): if c * 50 + b * 100 + a * 500 == x: count += 1 print(count)
A = int(eval(input())) B = int(eval(input())) C = int(eval(input())) x = int(eval(input())) print( ( sum( [ 1 for a in range(A + 1) for b in range(B + 1) for c in range(C + 1) if 500 * a + 100 * b + 50 * c == x ] ) ) )
false
66.666667
[ "-count = 0", "-if x % 50 != 0:", "- print((0))", "-else:", "- for c in range(C + 1):", "- for b in range(B + 1):", "- for a in range(A + 1):", "- if c * 50 + b * 100 + a * 500 == x:", "- count += 1", "- print(count)", "+print(", "+ (", "+ sum(", "+ [", "+ 1", "+ for a in range(A + 1)", "+ for b in range(B + 1)", "+ for c in range(C + 1)", "+ if 500 * a + 100 * b + 50 * c == x", "+ ]", "+ )", "+ )", "+)" ]
false
0.048855
0.106802
0.457434
[ "s918865315", "s173728555" ]
u562935282
p03944
python
s721271424
s092527317
73
18
3,064
3,064
Accepted
Accepted
75.34
w, h ,n = list(map(int, input().split())) sq = list(list(True for _ in range(h)) for _ in range(w))##sq[w][h] for i in range(n): x, y, a = list(map(int, input().split())) if a == 1: for ix in range(x): for iy in range(h): sq[ix][iy] = False if a == 2: for ix in range(x, w): for iy in range(h): sq[ix][iy] = False if a == 3: for ix in range(w): for iy in range(y): sq[ix][iy] = False if a == 4: for ix in range(w): for iy in range(y, h): sq[ix][iy] = False s = 0 for h in range(w): s += sq[h].count(True) print(s)
def main(): W, H, N = list(map(int, input().split())) xl, xh = 0, W yl, yh = 0, H for _ in range(N): x, y, a = list(map(int, input().split())) if a == 1: xl = max(xl, x) elif a == 2: xh = min(xh, x) elif a == 3: yl = max(yl, y) else: yh = min(yh, y) s = max(0, xh - xl) * max(0, yh - yl) print(s) if __name__ == '__main__': main()
25
23
713
462
w, h, n = list(map(int, input().split())) sq = list(list(True for _ in range(h)) for _ in range(w)) ##sq[w][h] for i in range(n): x, y, a = list(map(int, input().split())) if a == 1: for ix in range(x): for iy in range(h): sq[ix][iy] = False if a == 2: for ix in range(x, w): for iy in range(h): sq[ix][iy] = False if a == 3: for ix in range(w): for iy in range(y): sq[ix][iy] = False if a == 4: for ix in range(w): for iy in range(y, h): sq[ix][iy] = False s = 0 for h in range(w): s += sq[h].count(True) print(s)
def main(): W, H, N = list(map(int, input().split())) xl, xh = 0, W yl, yh = 0, H for _ in range(N): x, y, a = list(map(int, input().split())) if a == 1: xl = max(xl, x) elif a == 2: xh = min(xh, x) elif a == 3: yl = max(yl, y) else: yh = min(yh, y) s = max(0, xh - xl) * max(0, yh - yl) print(s) if __name__ == "__main__": main()
false
8
[ "-w, h, n = list(map(int, input().split()))", "-sq = list(list(True for _ in range(h)) for _ in range(w)) ##sq[w][h]", "-for i in range(n):", "- x, y, a = list(map(int, input().split()))", "- if a == 1:", "- for ix in range(x):", "- for iy in range(h):", "- sq[ix][iy] = False", "- if a == 2:", "- for ix in range(x, w):", "- for iy in range(h):", "- sq[ix][iy] = False", "- if a == 3:", "- for ix in range(w):", "- for iy in range(y):", "- sq[ix][iy] = False", "- if a == 4:", "- for ix in range(w):", "- for iy in range(y, h):", "- sq[ix][iy] = False", "-s = 0", "-for h in range(w):", "- s += sq[h].count(True)", "-print(s)", "+def main():", "+ W, H, N = list(map(int, input().split()))", "+ xl, xh = 0, W", "+ yl, yh = 0, H", "+ for _ in range(N):", "+ x, y, a = list(map(int, input().split()))", "+ if a == 1:", "+ xl = max(xl, x)", "+ elif a == 2:", "+ xh = min(xh, x)", "+ elif a == 3:", "+ yl = max(yl, y)", "+ else:", "+ yh = min(yh, y)", "+ s = max(0, xh - xl) * max(0, yh - yl)", "+ print(s)", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.056256
0.076219
0.738086
[ "s721271424", "s092527317" ]
u023229441
p03127
python
s853955014
s748247621
1,592
92
15,020
14,252
Accepted
Accepted
94.22
n=int(eval(input())) A=list(map(int,input().split())) B=A while len(B)>1: C=[i for i in range(len(B))] C.remove(B.index(min(B))) d=min(B) for i in C: B[i]=B[i]%d while 0 in B: B.remove(0) print((B[0]))
n=int(eval(input())) A=list(map(int,input().split())) ans=A[0] def gcd(a,b): if b==0: return a else: return gcd(b,a%b) def lcm(a,b): return a*b//gcd(a,b) for i in range(n-1): ans=gcd(ans,A[i+1]) if ans==1: print((1));exit() print(ans)
14
16
226
279
n = int(eval(input())) A = list(map(int, input().split())) B = A while len(B) > 1: C = [i for i in range(len(B))] C.remove(B.index(min(B))) d = min(B) for i in C: B[i] = B[i] % d while 0 in B: B.remove(0) print((B[0]))
n = int(eval(input())) A = list(map(int, input().split())) ans = A[0] def gcd(a, b): if b == 0: return a else: return gcd(b, a % b) def lcm(a, b): return a * b // gcd(a, b) for i in range(n - 1): ans = gcd(ans, A[i + 1]) if ans == 1: print((1)) exit() print(ans)
false
12.5
[ "-B = A", "-while len(B) > 1:", "- C = [i for i in range(len(B))]", "- C.remove(B.index(min(B)))", "- d = min(B)", "- for i in C:", "- B[i] = B[i] % d", "- while 0 in B:", "- B.remove(0)", "-print((B[0]))", "+ans = A[0]", "+", "+", "+def gcd(a, b):", "+ if b == 0:", "+ return a", "+ else:", "+ return gcd(b, a % b)", "+", "+", "+def lcm(a, b):", "+ return a * b // gcd(a, b)", "+", "+", "+for i in range(n - 1):", "+ ans = gcd(ans, A[i + 1])", "+ if ans == 1:", "+ print((1))", "+ exit()", "+print(ans)" ]
false
0.112633
0.035426
3.179395
[ "s853955014", "s748247621" ]
u553987207
p02785
python
s003250936
s575408310
155
105
26,764
31,568
Accepted
Accepted
32.26
N, K = list(map(int, input().split())) H = list(map(int, input().split())) if N <= K: print((0)) else: H.sort(reverse=True) print((sum(H[K:])))
N, K = list(map(int, input().split())) H = sorted(map(int, input().split()), reverse=True) ans = sum(H[K:]) print(ans)
7
4
151
115
N, K = list(map(int, input().split())) H = list(map(int, input().split())) if N <= K: print((0)) else: H.sort(reverse=True) print((sum(H[K:])))
N, K = list(map(int, input().split())) H = sorted(map(int, input().split()), reverse=True) ans = sum(H[K:]) print(ans)
false
42.857143
[ "-H = list(map(int, input().split()))", "-if N <= K:", "- print((0))", "-else:", "- H.sort(reverse=True)", "- print((sum(H[K:])))", "+H = sorted(map(int, input().split()), reverse=True)", "+ans = sum(H[K:])", "+print(ans)" ]
false
0.034793
0.034168
1.01828
[ "s003250936", "s575408310" ]
u977661421
p03624
python
s187727631
s696768991
1,245
322
3,956
3,956
Accepted
Accepted
74.14
# -*- coding: utf-8 -*- s = list(str(eval(input()))) alph = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] if len(set(s)) >= 26: print("None") exit() for i in alph: for j in s: if not(i in s): print(i) exit()
# -*- coding: utf-8 -*- s = list(str(eval(input()))) alph = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] """ if len(set(s)) >= 26: print("None") exit() for i in alph: for j in s: if not(i in s): print(i) exit() """ check = [False] * 26 for i in s: for j in range(26): if i == alph[j]: check[j] = True tmp = 0 for i in range(26): if check[i] == False: print((alph[i])) exit() if check[i]: tmp += 1 if tmp == 26: print("None")
12
29
343
637
# -*- coding: utf-8 -*- s = list(str(eval(input()))) alph = [ "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", ] if len(set(s)) >= 26: print("None") exit() for i in alph: for j in s: if not (i in s): print(i) exit()
# -*- coding: utf-8 -*- s = list(str(eval(input()))) alph = [ "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", ] """ if len(set(s)) >= 26: print("None") exit() for i in alph: for j in s: if not(i in s): print(i) exit() """ check = [False] * 26 for i in s: for j in range(26): if i == alph[j]: check[j] = True tmp = 0 for i in range(26): if check[i] == False: print((alph[i])) exit() if check[i]: tmp += 1 if tmp == 26: print("None")
false
58.62069
[ "+\"\"\"", "- if not (i in s):", "+ if not(i in s):", "+\"\"\"", "+check = [False] * 26", "+for i in s:", "+ for j in range(26):", "+ if i == alph[j]:", "+ check[j] = True", "+tmp = 0", "+for i in range(26):", "+ if check[i] == False:", "+ print((alph[i]))", "+ exit()", "+ if check[i]:", "+ tmp += 1", "+if tmp == 26:", "+ print(\"None\")" ]
false
0.040073
0.046047
0.870255
[ "s187727631", "s696768991" ]
u086503932
p03069
python
s175127511
s397944709
123
83
11,756
9,776
Accepted
Accepted
32.52
#!/usr/bin/env python3 from collections import deque, Counter from heapq import heappop, heappush from bisect import bisect_right def main(): N = int(eval(input())) S = eval(input()) B = [] W = [] i = 0 fin = None while i < N: if S[i] == '#': if i == N-1: B.append(1) fin = True else: tmp = 1 while S[i+1] == '#': tmp += 1 i += 1 if i == N-1: fin = True break B.append(tmp) else: if i == N-1: W.append(1) fin = False else: tmp = 1 while S[i+1] == '.': tmp += 1 i += 1 if i == N-1: fin = False break W.append(tmp) i += 1 ans = sum(B) L = len(B)+len(W) B = B[::-1] W = W[::-1] now = ans if fin: for i in range(L): if i % 2 == 0: now -= B[i//2] else: now += W[i//2] ans = min(ans,now) else: for i in range(L): if i % 2 == 1: now -= B[i//2] else: now += W[i//2] ans = min(ans,now) print(ans) if __name__ == "__main__": main()
#!/usr/bin/env python3 from collections import deque, Counter from heapq import heappop, heappush from bisect import bisect_right def main(): N = int(eval(input())) S = eval(input()) B = 0 W = S.count('.') ans = B+W for i in range(N): if S[i] == '#': B += 1 else: W -= 1 ans = min(ans, B+W) print(ans) if __name__ == "__main__": main()
68
22
1,552
428
#!/usr/bin/env python3 from collections import deque, Counter from heapq import heappop, heappush from bisect import bisect_right def main(): N = int(eval(input())) S = eval(input()) B = [] W = [] i = 0 fin = None while i < N: if S[i] == "#": if i == N - 1: B.append(1) fin = True else: tmp = 1 while S[i + 1] == "#": tmp += 1 i += 1 if i == N - 1: fin = True break B.append(tmp) else: if i == N - 1: W.append(1) fin = False else: tmp = 1 while S[i + 1] == ".": tmp += 1 i += 1 if i == N - 1: fin = False break W.append(tmp) i += 1 ans = sum(B) L = len(B) + len(W) B = B[::-1] W = W[::-1] now = ans if fin: for i in range(L): if i % 2 == 0: now -= B[i // 2] else: now += W[i // 2] ans = min(ans, now) else: for i in range(L): if i % 2 == 1: now -= B[i // 2] else: now += W[i // 2] ans = min(ans, now) print(ans) if __name__ == "__main__": main()
#!/usr/bin/env python3 from collections import deque, Counter from heapq import heappop, heappush from bisect import bisect_right def main(): N = int(eval(input())) S = eval(input()) B = 0 W = S.count(".") ans = B + W for i in range(N): if S[i] == "#": B += 1 else: W -= 1 ans = min(ans, B + W) print(ans) if __name__ == "__main__": main()
false
67.647059
[ "- B = []", "- W = []", "- i = 0", "- fin = None", "- while i < N:", "+ B = 0", "+ W = S.count(\".\")", "+ ans = B + W", "+ for i in range(N):", "- if i == N - 1:", "- B.append(1)", "- fin = True", "- else:", "- tmp = 1", "- while S[i + 1] == \"#\":", "- tmp += 1", "- i += 1", "- if i == N - 1:", "- fin = True", "- break", "- B.append(tmp)", "+ B += 1", "- if i == N - 1:", "- W.append(1)", "- fin = False", "- else:", "- tmp = 1", "- while S[i + 1] == \".\":", "- tmp += 1", "- i += 1", "- if i == N - 1:", "- fin = False", "- break", "- W.append(tmp)", "- i += 1", "- ans = sum(B)", "- L = len(B) + len(W)", "- B = B[::-1]", "- W = W[::-1]", "- now = ans", "- if fin:", "- for i in range(L):", "- if i % 2 == 0:", "- now -= B[i // 2]", "- else:", "- now += W[i // 2]", "- ans = min(ans, now)", "- else:", "- for i in range(L):", "- if i % 2 == 1:", "- now -= B[i // 2]", "- else:", "- now += W[i // 2]", "- ans = min(ans, now)", "+ W -= 1", "+ ans = min(ans, B + W)" ]
false
0.06691
0.120396
0.555751
[ "s175127511", "s397944709" ]
u934225857
p02659
python
s015017187
s860422316
30
22
10,464
9,060
Accepted
Accepted
26.67
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_int, b_frac = b.split(".") bb = int(b_int) * 100 + int(b_frac) print((a * bb // 100))
6
5
128
123
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_int, b_frac = b.split(".") bb = int(b_int) * 100 + int(b_frac) print((a * bb // 100))
false
16.666667
[ "-from math import floor", "-from fractions import Fraction", "-", "-b = Fraction(b)", "-print((floor(a * b)))", "+b_int, b_frac = b.split(\".\")", "+bb = int(b_int) * 100 + int(b_frac)", "+print((a * bb // 100))" ]
false
0.045411
0.039744
1.142585
[ "s015017187", "s860422316" ]
u747602774
p02844
python
s810622997
s182365175
764
177
45,148
38,384
Accepted
Accepted
76.83
N = int(eval(input())) S = list(eval(input())) ans = 0 for i in range(10): for j in range(10): for k in range(10): n = 0 while str(i) != S[n] and n < N-3: n += 1 if S[n] != str(i): break n += 1 while str(j) != S[n] and n < N-2: n += 1 if S[n] != str(j): break n += 1 while str(k) != S[n] and n < N-1: n += 1 if S[n] == str(k): ans += 1 print(ans)
N = int(eval(input())) S = eval(input()) ans = 0 snumber = [str(i) for i in range(10)] for i in snumber: for j in snumber: for k in snumber: a = S.find(i) if a == -1: break b = S.find(j,a+1) if b == -1: break c = S.find(k,b+1) if c != -1: ans += 1 print(ans)
22
17
571
395
N = int(eval(input())) S = list(eval(input())) ans = 0 for i in range(10): for j in range(10): for k in range(10): n = 0 while str(i) != S[n] and n < N - 3: n += 1 if S[n] != str(i): break n += 1 while str(j) != S[n] and n < N - 2: n += 1 if S[n] != str(j): break n += 1 while str(k) != S[n] and n < N - 1: n += 1 if S[n] == str(k): ans += 1 print(ans)
N = int(eval(input())) S = eval(input()) ans = 0 snumber = [str(i) for i in range(10)] for i in snumber: for j in snumber: for k in snumber: a = S.find(i) if a == -1: break b = S.find(j, a + 1) if b == -1: break c = S.find(k, b + 1) if c != -1: ans += 1 print(ans)
false
22.727273
[ "-S = list(eval(input()))", "+S = eval(input())", "-for i in range(10):", "- for j in range(10):", "- for k in range(10):", "- n = 0", "- while str(i) != S[n] and n < N - 3:", "- n += 1", "- if S[n] != str(i):", "+snumber = [str(i) for i in range(10)]", "+for i in snumber:", "+ for j in snumber:", "+ for k in snumber:", "+ a = S.find(i)", "+ if a == -1:", "- n += 1", "- while str(j) != S[n] and n < N - 2:", "- n += 1", "- if S[n] != str(j):", "+ b = S.find(j, a + 1)", "+ if b == -1:", "- n += 1", "- while str(k) != S[n] and n < N - 1:", "- n += 1", "- if S[n] == str(k):", "+ c = S.find(k, b + 1)", "+ if c != -1:" ]
false
0.03873
0.039345
0.984387
[ "s810622997", "s182365175" ]
u600402037
p03128
python
s188279652
s058367137
1,184
255
255,112
51,164
Accepted
Accepted
78.46
# coding: utf-8 import sys sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) # まずは桁数を増やす→数字の大きい順に並べる N, M = lr() A = lr() matches = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] A = [(matches[a], a) for a in A] A.sort(key = lambda x: x[1], reverse=True) A.sort(key = lambda x: x[0]) top_match = A[0][0] dp = [None] * (N+1) dp[0] = [] used = set() for match, num in A: if match in used: continue used.add(match) for x in range(N+1): if x - match < 0: continue if dp[x] == None and dp[x-match] != None: dp[x] = dp[x-match] + [num] elif dp[x] != None and dp[x-match] != None: if len(dp[x-match]) >= len(dp[x]): dp[x] = dp[x-match] + [num] elif len(dp[x-match]) >= 1 and len(dp[x-match]) == len(dp[x]) - 1: y = list(map(str, dp[x][::-1])); y.sort(reverse=True) z = [str(num)] + list(map(str, dp[x-match][::-1])); z.sort(reverse=True) y = int(''.join(y)) z = int(''.join(z)) if z > y: dp[x] = dp[x-match] + [num] X = dp[N] X.sort(reverse=True) answer = ''.join(list(map(str, X))) print(answer) # 37
# coding: utf-8 import sys sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) N, M = lr() A = lr() dp = [-1] * (N+1) dp[0] = 0 for x in range(N): for a in A: y = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6][a] if x + y > N: continue dp[x+y] = max(dp[x+y], dp[x] * 10 + a) answer = dp[N] print(answer) # 32
43
21
1,290
411
# coding: utf-8 import sys sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) # まずは桁数を増やす→数字の大きい順に並べる N, M = lr() A = lr() matches = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] A = [(matches[a], a) for a in A] A.sort(key=lambda x: x[1], reverse=True) A.sort(key=lambda x: x[0]) top_match = A[0][0] dp = [None] * (N + 1) dp[0] = [] used = set() for match, num in A: if match in used: continue used.add(match) for x in range(N + 1): if x - match < 0: continue if dp[x] == None and dp[x - match] != None: dp[x] = dp[x - match] + [num] elif dp[x] != None and dp[x - match] != None: if len(dp[x - match]) >= len(dp[x]): dp[x] = dp[x - match] + [num] elif len(dp[x - match]) >= 1 and len(dp[x - match]) == len(dp[x]) - 1: y = list(map(str, dp[x][::-1])) y.sort(reverse=True) z = [str(num)] + list(map(str, dp[x - match][::-1])) z.sort(reverse=True) y = int("".join(y)) z = int("".join(z)) if z > y: dp[x] = dp[x - match] + [num] X = dp[N] X.sort(reverse=True) answer = "".join(list(map(str, X))) print(answer) # 37
# coding: utf-8 import sys sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) N, M = lr() A = lr() dp = [-1] * (N + 1) dp[0] = 0 for x in range(N): for a in A: y = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6][a] if x + y > N: continue dp[x + y] = max(dp[x + y], dp[x] * 10 + a) answer = dp[N] print(answer) # 32
false
51.162791
[ "-# まずは桁数を増やす→数字の大きい順に並べる", "-matches = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]", "-A = [(matches[a], a) for a in A]", "-A.sort(key=lambda x: x[1], reverse=True)", "-A.sort(key=lambda x: x[0])", "-top_match = A[0][0]", "-dp = [None] * (N + 1)", "-dp[0] = []", "-used = set()", "-for match, num in A:", "- if match in used:", "- continue", "- used.add(match)", "- for x in range(N + 1):", "- if x - match < 0:", "+dp = [-1] * (N + 1)", "+dp[0] = 0", "+for x in range(N):", "+ for a in A:", "+ y = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6][a]", "+ if x + y > N:", "- if dp[x] == None and dp[x - match] != None:", "- dp[x] = dp[x - match] + [num]", "- elif dp[x] != None and dp[x - match] != None:", "- if len(dp[x - match]) >= len(dp[x]):", "- dp[x] = dp[x - match] + [num]", "- elif len(dp[x - match]) >= 1 and len(dp[x - match]) == len(dp[x]) - 1:", "- y = list(map(str, dp[x][::-1]))", "- y.sort(reverse=True)", "- z = [str(num)] + list(map(str, dp[x - match][::-1]))", "- z.sort(reverse=True)", "- y = int(\"\".join(y))", "- z = int(\"\".join(z))", "- if z > y:", "- dp[x] = dp[x - match] + [num]", "-X = dp[N]", "-X.sort(reverse=True)", "-answer = \"\".join(list(map(str, X)))", "+ dp[x + y] = max(dp[x + y], dp[x] * 10 + a)", "+answer = dp[N]", "-# 37", "+# 32" ]
false
0.035611
0.070668
0.503925
[ "s188279652", "s058367137" ]
u392319141
p03329
python
s987397380
s009899572
760
650
6,296
3,828
Accepted
Accepted
14.47
N = int(eval(input())) dp = [float('inf') for _ in range(N + 1)] dp[N] = 0 for i in range(N, -1, -1) : if i - 1 >= 0 : dp[i - 1] = min(dp[i - 1], dp[i] + 1) dis = 6 while i - dis >= 0 : dp[i - dis] = min(dp[i - dis], dp[i] + 1) dis *= 6 dis = 9 while i - dis >= 0 : dp[i - dis] = min(dp[i - dis], dp[i] + 1) dis *= 9 print((dp[0]))
N = int(eval(input())) dp = [10**18] * (N + 1) dp[0] = 0 for i in range(N): prd = 6 while i + prd <= N: dp[i + prd] = min(dp[i + prd], dp[i] + 1) prd *= 6 prd = 9 while i + prd <= N: dp[i + prd] = min(dp[i + prd], dp[i] + 1) prd *= 9 ans = 10**18 for i, c in enumerate(dp): ans = min(ans, N - i + c) print(ans)
18
19
403
378
N = int(eval(input())) dp = [float("inf") for _ in range(N + 1)] dp[N] = 0 for i in range(N, -1, -1): if i - 1 >= 0: dp[i - 1] = min(dp[i - 1], dp[i] + 1) dis = 6 while i - dis >= 0: dp[i - dis] = min(dp[i - dis], dp[i] + 1) dis *= 6 dis = 9 while i - dis >= 0: dp[i - dis] = min(dp[i - dis], dp[i] + 1) dis *= 9 print((dp[0]))
N = int(eval(input())) dp = [10**18] * (N + 1) dp[0] = 0 for i in range(N): prd = 6 while i + prd <= N: dp[i + prd] = min(dp[i + prd], dp[i] + 1) prd *= 6 prd = 9 while i + prd <= N: dp[i + prd] = min(dp[i + prd], dp[i] + 1) prd *= 9 ans = 10**18 for i, c in enumerate(dp): ans = min(ans, N - i + c) print(ans)
false
5.263158
[ "-dp = [float(\"inf\") for _ in range(N + 1)]", "-dp[N] = 0", "-for i in range(N, -1, -1):", "- if i - 1 >= 0:", "- dp[i - 1] = min(dp[i - 1], dp[i] + 1)", "- dis = 6", "- while i - dis >= 0:", "- dp[i - dis] = min(dp[i - dis], dp[i] + 1)", "- dis *= 6", "- dis = 9", "- while i - dis >= 0:", "- dp[i - dis] = min(dp[i - dis], dp[i] + 1)", "- dis *= 9", "-print((dp[0]))", "+dp = [10**18] * (N + 1)", "+dp[0] = 0", "+for i in range(N):", "+ prd = 6", "+ while i + prd <= N:", "+ dp[i + prd] = min(dp[i + prd], dp[i] + 1)", "+ prd *= 6", "+ prd = 9", "+ while i + prd <= N:", "+ dp[i + prd] = min(dp[i + prd], dp[i] + 1)", "+ prd *= 9", "+ans = 10**18", "+for i, c in enumerate(dp):", "+ ans = min(ans, N - i + c)", "+print(ans)" ]
false
0.169715
0.21869
0.776053
[ "s987397380", "s009899572" ]
u620868411
p03252
python
s987916975
s451158542
385
142
6,224
3,632
Accepted
Accepted
63.12
# -*- coding: utf-8 -*- import unittest def func(s,t): n = len(s) for c in set(s): d = None for i in range(n): if s[i]==c: if d is None: d = t[i] elif d!=t[i]: return "No" for c in set(t): d = None for i in range(n): if t[i]==c: if d is None: d = s[i] elif d!=s[i]: return "No" return "Yes" class Test(unittest.TestCase): def test(self): self.assertEqual(func("azzel", "apple"), "Yes") self.assertEqual(func("chokudai", "redcoder"), "No") self.assertEqual(func("abcdefghijklmnopqrstuvwxyz", "ibyhqfrekavclxjstdwgpzmonu"), "Yes") self.assertEqual(func("abc", "abc"), "Yes") if __name__ == '__main__': s = eval(input()) t = eval(input()) # unittest.main() print((func(s,t)))
# -*- coding: utf-8 -*- s = eval(input()) t = eval(input()) n = len(s) ds = {} dt = {} for i in range(n): if s[i] not in ds: ds[s[i]] = t[i] elif ds[s[i]]!=t[i]: print("No") exit() if t[i] not in dt: dt[t[i]] = s[i] elif dt[t[i]]!=s[i]: print("No") exit() print("Yes")
36
19
966
340
# -*- coding: utf-8 -*- import unittest def func(s, t): n = len(s) for c in set(s): d = None for i in range(n): if s[i] == c: if d is None: d = t[i] elif d != t[i]: return "No" for c in set(t): d = None for i in range(n): if t[i] == c: if d is None: d = s[i] elif d != s[i]: return "No" return "Yes" class Test(unittest.TestCase): def test(self): self.assertEqual(func("azzel", "apple"), "Yes") self.assertEqual(func("chokudai", "redcoder"), "No") self.assertEqual( func("abcdefghijklmnopqrstuvwxyz", "ibyhqfrekavclxjstdwgpzmonu"), "Yes" ) self.assertEqual(func("abc", "abc"), "Yes") if __name__ == "__main__": s = eval(input()) t = eval(input()) # unittest.main() print((func(s, t)))
# -*- coding: utf-8 -*- s = eval(input()) t = eval(input()) n = len(s) ds = {} dt = {} for i in range(n): if s[i] not in ds: ds[s[i]] = t[i] elif ds[s[i]] != t[i]: print("No") exit() if t[i] not in dt: dt[t[i]] = s[i] elif dt[t[i]] != s[i]: print("No") exit() print("Yes")
false
47.222222
[ "-import unittest", "-", "-", "-def func(s, t):", "- n = len(s)", "- for c in set(s):", "- d = None", "- for i in range(n):", "- if s[i] == c:", "- if d is None:", "- d = t[i]", "- elif d != t[i]:", "- return \"No\"", "- for c in set(t):", "- d = None", "- for i in range(n):", "- if t[i] == c:", "- if d is None:", "- d = s[i]", "- elif d != s[i]:", "- return \"No\"", "- return \"Yes\"", "-", "-", "-class Test(unittest.TestCase):", "- def test(self):", "- self.assertEqual(func(\"azzel\", \"apple\"), \"Yes\")", "- self.assertEqual(func(\"chokudai\", \"redcoder\"), \"No\")", "- self.assertEqual(", "- func(\"abcdefghijklmnopqrstuvwxyz\", \"ibyhqfrekavclxjstdwgpzmonu\"), \"Yes\"", "- )", "- self.assertEqual(func(\"abc\", \"abc\"), \"Yes\")", "-", "-", "-if __name__ == \"__main__\":", "- s = eval(input())", "- t = eval(input())", "- # unittest.main()", "- print((func(s, t)))", "+s = eval(input())", "+t = eval(input())", "+n = len(s)", "+ds = {}", "+dt = {}", "+for i in range(n):", "+ if s[i] not in ds:", "+ ds[s[i]] = t[i]", "+ elif ds[s[i]] != t[i]:", "+ print(\"No\")", "+ exit()", "+ if t[i] not in dt:", "+ dt[t[i]] = s[i]", "+ elif dt[t[i]] != s[i]:", "+ print(\"No\")", "+ exit()", "+print(\"Yes\")" ]
false
0.105777
0.0767
1.379108
[ "s987916975", "s451158542" ]
u933096856
p02417
python
s786045426
s253234920
30
10
7,536
6,508
Accepted
Accepted
66.67
a=[0]*26 w='abcdefghijklmnopqrstuvwxyz' try: while True: s=list(input().upper()) for i in s: if i=='A': a[0]+=1 elif i=='B': a[1]+=1 elif i=='C': a[2]+=1 elif i=='D': a[3]+=1 elif i=='E': a[4]+=1 elif i=='F': a[5]+=1 elif i=='G': a[6]+=1 elif i=='H': a[7]+=1 elif i=='I': a[8]+=1 elif i=='J': a[9]+=1 elif i=='K': a[10]+=1 elif i=='L': a[11]+=1 elif i=='M': a[12]+=1 elif i=='N': a[13]+=1 elif i=='O': a[14]+=1 elif i=='P': a[15]+=1 elif i=='Q': a[16]+=1 elif i=='R': a[17]+=1 elif i=='S': a[18]+=1 elif i=='T': a[19]+=1 elif i=='U': a[20]+=1 elif i=='V': a[21]+=1 elif i=='W': a[22]+=1 elif i=='X': a[23]+=1 elif i=='Y': a[24]+=1 elif i=='Z': a[25]+=1 except EOFError: pass for i in range(26): print((w[i:i+1], ':', str(a[i])))
a=[0]*26 w='abcdefghijklmnopqrstuvwxyz' try: while True: s=list(input().upper()) for i in s: if i=='A': a[0]+=1 elif i=='B': a[1]+=1 elif i=='C': a[2]+=1 elif i=='D': a[3]+=1 elif i=='E': a[4]+=1 elif i=='F': a[5]+=1 elif i=='G': a[6]+=1 elif i=='H': a[7]+=1 elif i=='I': a[8]+=1 elif i=='J': a[9]+=1 elif i=='K': a[10]+=1 elif i=='L': a[11]+=1 elif i=='M': a[12]+=1 elif i=='N': a[13]+=1 elif i=='O': a[14]+=1 elif i=='P': a[15]+=1 elif i=='Q': a[16]+=1 elif i=='R': a[17]+=1 elif i=='S': a[18]+=1 elif i=='T': a[19]+=1 elif i=='U': a[20]+=1 elif i=='V': a[21]+=1 elif i=='W': a[22]+=1 elif i=='X': a[23]+=1 elif i=='Y': a[24]+=1 elif i=='Z': a[25]+=1 except EOFError: pass for i in range(26): print(w[i:i+1], ':', str(a[i]))
64
64
1,548
1,551
a = [0] * 26 w = "abcdefghijklmnopqrstuvwxyz" try: while True: s = list(input().upper()) for i in s: if i == "A": a[0] += 1 elif i == "B": a[1] += 1 elif i == "C": a[2] += 1 elif i == "D": a[3] += 1 elif i == "E": a[4] += 1 elif i == "F": a[5] += 1 elif i == "G": a[6] += 1 elif i == "H": a[7] += 1 elif i == "I": a[8] += 1 elif i == "J": a[9] += 1 elif i == "K": a[10] += 1 elif i == "L": a[11] += 1 elif i == "M": a[12] += 1 elif i == "N": a[13] += 1 elif i == "O": a[14] += 1 elif i == "P": a[15] += 1 elif i == "Q": a[16] += 1 elif i == "R": a[17] += 1 elif i == "S": a[18] += 1 elif i == "T": a[19] += 1 elif i == "U": a[20] += 1 elif i == "V": a[21] += 1 elif i == "W": a[22] += 1 elif i == "X": a[23] += 1 elif i == "Y": a[24] += 1 elif i == "Z": a[25] += 1 except EOFError: pass for i in range(26): print((w[i : i + 1], ":", str(a[i])))
a = [0] * 26 w = "abcdefghijklmnopqrstuvwxyz" try: while True: s = list(input().upper()) for i in s: if i == "A": a[0] += 1 elif i == "B": a[1] += 1 elif i == "C": a[2] += 1 elif i == "D": a[3] += 1 elif i == "E": a[4] += 1 elif i == "F": a[5] += 1 elif i == "G": a[6] += 1 elif i == "H": a[7] += 1 elif i == "I": a[8] += 1 elif i == "J": a[9] += 1 elif i == "K": a[10] += 1 elif i == "L": a[11] += 1 elif i == "M": a[12] += 1 elif i == "N": a[13] += 1 elif i == "O": a[14] += 1 elif i == "P": a[15] += 1 elif i == "Q": a[16] += 1 elif i == "R": a[17] += 1 elif i == "S": a[18] += 1 elif i == "T": a[19] += 1 elif i == "U": a[20] += 1 elif i == "V": a[21] += 1 elif i == "W": a[22] += 1 elif i == "X": a[23] += 1 elif i == "Y": a[24] += 1 elif i == "Z": a[25] += 1 except EOFError: pass for i in range(26): print(w[i : i + 1], ":", str(a[i]))
false
0
[ "- print((w[i : i + 1], \":\", str(a[i])))", "+ print(w[i : i + 1], \":\", str(a[i]))" ]
false
0.039826
0.03824
1.041495
[ "s786045426", "s253234920" ]
u759412327
p03696
python
s855562446
s964556766
31
26
9,068
9,152
Accepted
Accepted
16.13
N = int(eval(input())) S = eval(input()) T = S for n in range(N): T = T.replace("()","") L = T.count("(") R = T.count(")") S = R*"("+S+L*")" print(S)
N = int(eval(input())) S = T = eval(input()) while "()" in S: S = S.replace("()","") print(("("*S.count(")")+T+S.count("(")*")"))
11
7
151
125
N = int(eval(input())) S = eval(input()) T = S for n in range(N): T = T.replace("()", "") L = T.count("(") R = T.count(")") S = R * "(" + S + L * ")" print(S)
N = int(eval(input())) S = T = eval(input()) while "()" in S: S = S.replace("()", "") print(("(" * S.count(")") + T + S.count("(") * ")"))
false
36.363636
[ "-S = eval(input())", "-T = S", "-for n in range(N):", "- T = T.replace(\"()\", \"\")", "-L = T.count(\"(\")", "-R = T.count(\")\")", "-S = R * \"(\" + S + L * \")\"", "-print(S)", "+S = T = eval(input())", "+while \"()\" in S:", "+ S = S.replace(\"()\", \"\")", "+print((\"(\" * S.count(\")\") + T + S.count(\"(\") * \")\"))" ]
false
0.0367
0.036513
1.005131
[ "s855562446", "s964556766" ]
u312025627
p03291
python
s487572413
s005370818
400
127
9,156
73,672
Accepted
Accepted
68.25
MOD = 10**9 + 7 def main(): S = eval(input()) N = len(S) pre_hatena = S[:1].count("?") a = S[:1].count("A") post_hatena = S[2:].count("?") c = S[2:].count("C") ans = 0 for i in range(1, N-1): if S[i] == "?" or S[i] == "B": pre_pow = pow(3, pre_hatena-1, MOD) pre = ((pre_pow * 3) % MOD) * a + pre_pow * pre_hatena post_pow = pow(3, post_hatena-1, MOD) post = ((post_pow * 3) % MOD) * c + post_pow * post_hatena ans += pre * post ans %= MOD if S[i] == "?": pre_hatena += 1 if S[i] == "A": a += 1 if S[i+1] == "?": post_hatena -= 1 if S[i+1] == "C": c -= 1 print(ans) if __name__ == '__main__': main()
MOD = 10**9 + 7 def main(): S = eval(input()) N = len(S) pre_hatena = S[:1].count("?") a = S[:1].count("A") post_hatena = S[2:].count("?") c = S[2:].count("C") rev_3 = pow(3, MOD-2, MOD) ans = 0 for i in range(1, N-1): if S[i] == "?" or S[i] == "B": pre_pow = pow(3, pre_hatena, MOD) pre = pre_pow * a + ((pre_pow * rev_3) % MOD) * pre_hatena post_pow = pow(3, post_hatena, MOD) post = post_pow * c + ((post_pow * rev_3) % MOD) * post_hatena ans += pre * post ans %= MOD if S[i] == "?": pre_hatena += 1 if S[i] == "A": a += 1 if S[i+1] == "?": post_hatena -= 1 if S[i+1] == "C": c -= 1 print(ans) if __name__ == '__main__': main()
33
34
831
867
MOD = 10**9 + 7 def main(): S = eval(input()) N = len(S) pre_hatena = S[:1].count("?") a = S[:1].count("A") post_hatena = S[2:].count("?") c = S[2:].count("C") ans = 0 for i in range(1, N - 1): if S[i] == "?" or S[i] == "B": pre_pow = pow(3, pre_hatena - 1, MOD) pre = ((pre_pow * 3) % MOD) * a + pre_pow * pre_hatena post_pow = pow(3, post_hatena - 1, MOD) post = ((post_pow * 3) % MOD) * c + post_pow * post_hatena ans += pre * post ans %= MOD if S[i] == "?": pre_hatena += 1 if S[i] == "A": a += 1 if S[i + 1] == "?": post_hatena -= 1 if S[i + 1] == "C": c -= 1 print(ans) if __name__ == "__main__": main()
MOD = 10**9 + 7 def main(): S = eval(input()) N = len(S) pre_hatena = S[:1].count("?") a = S[:1].count("A") post_hatena = S[2:].count("?") c = S[2:].count("C") rev_3 = pow(3, MOD - 2, MOD) ans = 0 for i in range(1, N - 1): if S[i] == "?" or S[i] == "B": pre_pow = pow(3, pre_hatena, MOD) pre = pre_pow * a + ((pre_pow * rev_3) % MOD) * pre_hatena post_pow = pow(3, post_hatena, MOD) post = post_pow * c + ((post_pow * rev_3) % MOD) * post_hatena ans += pre * post ans %= MOD if S[i] == "?": pre_hatena += 1 if S[i] == "A": a += 1 if S[i + 1] == "?": post_hatena -= 1 if S[i + 1] == "C": c -= 1 print(ans) if __name__ == "__main__": main()
false
2.941176
[ "+ rev_3 = pow(3, MOD - 2, MOD)", "- pre_pow = pow(3, pre_hatena - 1, MOD)", "- pre = ((pre_pow * 3) % MOD) * a + pre_pow * pre_hatena", "- post_pow = pow(3, post_hatena - 1, MOD)", "- post = ((post_pow * 3) % MOD) * c + post_pow * post_hatena", "+ pre_pow = pow(3, pre_hatena, MOD)", "+ pre = pre_pow * a + ((pre_pow * rev_3) % MOD) * pre_hatena", "+ post_pow = pow(3, post_hatena, MOD)", "+ post = post_pow * c + ((post_pow * rev_3) % MOD) * post_hatena" ]
false
0.034865
0.035827
0.973156
[ "s487572413", "s005370818" ]
u422104747
p03330
python
s589614307
s681953692
1,404
216
5,244
3,188
Accepted
Accepted
84.62
s=input().split() N=int(s[0]) C=int(s[1]) d=[] for i in range(C): s=input().split() temp=[] for item in s: temp.append(int(item)) d.append(temp) if N==1: print("0") else: c=[[],[],[]] cost=[[],[],[]] for j in range(N): s=input().split() for i in range(len(s)): c[(i+j)%3].append(int(s[i])-1) for i in range(C): s=0 for col in c[0]: s+=d[col][i] cost[0].append((s,i)) s=0 for col in c[1]: s+=d[col][i] cost[1].append((s,i)) s=0 for col in c[2]: s+=d[col][i] cost[2].append((s,i)) res=100000000000 for i in range(C): for j in range(C): for k in range(C): if cost[0][i][1]!=cost[1][j][1] and cost[1][j][1]!=cost[2][k][1] and cost[2][k][1]!=cost[0][i][1]: res=min(res,cost[0][i][0]+cost[1][j][0]+cost[2][k][0]) print(res)
s=input().split() n=int(s[0]) c=int(s[1]) d=[[0 for i in range(c+1)] for j in range(c+1)] for i in range(c): s=input().split() for j in range(c): d[i+1][j+1]=int(s[j]) cnt=[[0 for i in range(c+1)],[0 for i in range(c+1)],[0 for i in range(c+1)]] for i in range(n): s=input().split() for j in range(n): cnt[(i+j)%3][int(s[j])]+=1 cnt[(i+j)%3][0]+=1 iwa=[[0 for i in range(c+1)],[0 for i in range(c+1)],[0 for i in range(c+1)]] for i in range(1,c+1): for j in range(1,c+1): for k in range(3): iwa[k][i]+=d[j][i]*cnt[k][j] m=10**9 for i in range(1,1+c): for j in range(1,1+c): for k in range(1,1+c): if i==j or j==k or k==i: continue m=min(m,iwa[0][i]+iwa[1][j]+iwa[2][k]) print(m)
39
27
1,004
790
s = input().split() N = int(s[0]) C = int(s[1]) d = [] for i in range(C): s = input().split() temp = [] for item in s: temp.append(int(item)) d.append(temp) if N == 1: print("0") else: c = [[], [], []] cost = [[], [], []] for j in range(N): s = input().split() for i in range(len(s)): c[(i + j) % 3].append(int(s[i]) - 1) for i in range(C): s = 0 for col in c[0]: s += d[col][i] cost[0].append((s, i)) s = 0 for col in c[1]: s += d[col][i] cost[1].append((s, i)) s = 0 for col in c[2]: s += d[col][i] cost[2].append((s, i)) res = 100000000000 for i in range(C): for j in range(C): for k in range(C): if ( cost[0][i][1] != cost[1][j][1] and cost[1][j][1] != cost[2][k][1] and cost[2][k][1] != cost[0][i][1] ): res = min(res, cost[0][i][0] + cost[1][j][0] + cost[2][k][0]) print(res)
s = input().split() n = int(s[0]) c = int(s[1]) d = [[0 for i in range(c + 1)] for j in range(c + 1)] for i in range(c): s = input().split() for j in range(c): d[i + 1][j + 1] = int(s[j]) cnt = [[0 for i in range(c + 1)], [0 for i in range(c + 1)], [0 for i in range(c + 1)]] for i in range(n): s = input().split() for j in range(n): cnt[(i + j) % 3][int(s[j])] += 1 cnt[(i + j) % 3][0] += 1 iwa = [[0 for i in range(c + 1)], [0 for i in range(c + 1)], [0 for i in range(c + 1)]] for i in range(1, c + 1): for j in range(1, c + 1): for k in range(3): iwa[k][i] += d[j][i] * cnt[k][j] m = 10**9 for i in range(1, 1 + c): for j in range(1, 1 + c): for k in range(1, 1 + c): if i == j or j == k or k == i: continue m = min(m, iwa[0][i] + iwa[1][j] + iwa[2][k]) print(m)
false
30.769231
[ "-N = int(s[0])", "-C = int(s[1])", "-d = []", "-for i in range(C):", "+n = int(s[0])", "+c = int(s[1])", "+d = [[0 for i in range(c + 1)] for j in range(c + 1)]", "+for i in range(c):", "- temp = []", "- for item in s:", "- temp.append(int(item))", "- d.append(temp)", "-if N == 1:", "- print(\"0\")", "-else:", "- c = [[], [], []]", "- cost = [[], [], []]", "- for j in range(N):", "- s = input().split()", "- for i in range(len(s)):", "- c[(i + j) % 3].append(int(s[i]) - 1)", "- for i in range(C):", "- s = 0", "- for col in c[0]:", "- s += d[col][i]", "- cost[0].append((s, i))", "- s = 0", "- for col in c[1]:", "- s += d[col][i]", "- cost[1].append((s, i))", "- s = 0", "- for col in c[2]:", "- s += d[col][i]", "- cost[2].append((s, i))", "- res = 100000000000", "- for i in range(C):", "- for j in range(C):", "- for k in range(C):", "- if (", "- cost[0][i][1] != cost[1][j][1]", "- and cost[1][j][1] != cost[2][k][1]", "- and cost[2][k][1] != cost[0][i][1]", "- ):", "- res = min(res, cost[0][i][0] + cost[1][j][0] + cost[2][k][0])", "- print(res)", "+ for j in range(c):", "+ d[i + 1][j + 1] = int(s[j])", "+cnt = [[0 for i in range(c + 1)], [0 for i in range(c + 1)], [0 for i in range(c + 1)]]", "+for i in range(n):", "+ s = input().split()", "+ for j in range(n):", "+ cnt[(i + j) % 3][int(s[j])] += 1", "+ cnt[(i + j) % 3][0] += 1", "+iwa = [[0 for i in range(c + 1)], [0 for i in range(c + 1)], [0 for i in range(c + 1)]]", "+for i in range(1, c + 1):", "+ for j in range(1, c + 1):", "+ for k in range(3):", "+ iwa[k][i] += d[j][i] * cnt[k][j]", "+m = 10**9", "+for i in range(1, 1 + c):", "+ for j in range(1, 1 + c):", "+ for k in range(1, 1 + c):", "+ if i == j or j == k or k == i:", "+ continue", "+ m = min(m, iwa[0][i] + iwa[1][j] + iwa[2][k])", "+print(m)" ]
false
0.054649
0.036825
1.48402
[ "s589614307", "s681953692" ]
u022979415
p03325
python
s827297633
s521033858
84
68
4,148
4,148
Accepted
Accepted
19.05
def main(): N = int(eval(input())) numbers = list(map(int, input().split(" "))) answer = 0 odds = 0 while odds < N: odds = 0 for i in range(N): if not numbers[i] % 2: numbers[i] //= 2 answer += 1 else: odds += 1 print(answer) if __name__ == '__main__': main()
def main(): n = int(eval(input())) a = [int(x) for x in input().split()] answer = 0 for aa in a: while aa > 0 and aa % 2 == 0: aa //= 2 answer += 1 print(answer) if __name__ == '__main__': main()
18
14
388
262
def main(): N = int(eval(input())) numbers = list(map(int, input().split(" "))) answer = 0 odds = 0 while odds < N: odds = 0 for i in range(N): if not numbers[i] % 2: numbers[i] //= 2 answer += 1 else: odds += 1 print(answer) if __name__ == "__main__": main()
def main(): n = int(eval(input())) a = [int(x) for x in input().split()] answer = 0 for aa in a: while aa > 0 and aa % 2 == 0: aa //= 2 answer += 1 print(answer) if __name__ == "__main__": main()
false
22.222222
[ "- N = int(eval(input()))", "- numbers = list(map(int, input().split(\" \")))", "+ n = int(eval(input()))", "+ a = [int(x) for x in input().split()]", "- odds = 0", "- while odds < N:", "- odds = 0", "- for i in range(N):", "- if not numbers[i] % 2:", "- numbers[i] //= 2", "- answer += 1", "- else:", "- odds += 1", "+ for aa in a:", "+ while aa > 0 and aa % 2 == 0:", "+ aa //= 2", "+ answer += 1" ]
false
0.041646
0.040557
1.026835
[ "s827297633", "s521033858" ]
u186838327
p03165
python
s950183430
s823134490
516
349
119,132
149,792
Accepted
Accepted
32.36
s = str(eval(input())) t = str(eval(input())) dp = [[-1]*3100 for _ in range(3100)] # dp[i+1][j+1]: s[i], t[j]まで見たときのLCSの長さ dp[0][0] = 0 for i in range(len(s)): for j in range(len(t)): if s[i] == t[j]: dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j]+1) dp[i+1][j+1] = max(dp[i+1][j+1], dp[i+1][j]) dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j+1]) i = len(s) j = len(t) ans = '' while i>0 and j>0: if dp[i][j] == dp[i-1][j]: i -= 1 elif dp[i][j] == dp[i][j-1]: j -= 1 else: ans = s[i-1] + ans i -= 1 j -= 1 print(ans)
s = str(eval(input())) t = str(eval(input())) dp = [[0]*3100 for _ in range(3100)] for i in range(len(s)): for j in range(len(t)): if s[i] == t[j]: dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j]+1) dp[i+1][j+1] = max(dp[i+1][j+1], dp[i+1][j]) dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j+1]) i = len(s) j = len(t) ans = [] while i > 0 and j > 0: if dp[i][j] == dp[i-1][j]: i -= 1 elif dp[i][j] == dp[i][j-1]: j -= 1 else: ans.append(s[i-1]) i -= 1 j -= 1 ans.reverse() print((''.join(ans)))
27
26
573
588
s = str(eval(input())) t = str(eval(input())) dp = [[-1] * 3100 for _ in range(3100)] # dp[i+1][j+1]: s[i], t[j]まで見たときのLCSの長さ dp[0][0] = 0 for i in range(len(s)): for j in range(len(t)): if s[i] == t[j]: dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + 1) dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i + 1][j]) dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j + 1]) i = len(s) j = len(t) ans = "" while i > 0 and j > 0: if dp[i][j] == dp[i - 1][j]: i -= 1 elif dp[i][j] == dp[i][j - 1]: j -= 1 else: ans = s[i - 1] + ans i -= 1 j -= 1 print(ans)
s = str(eval(input())) t = str(eval(input())) dp = [[0] * 3100 for _ in range(3100)] for i in range(len(s)): for j in range(len(t)): if s[i] == t[j]: dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + 1) dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i + 1][j]) dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j + 1]) i = len(s) j = len(t) ans = [] while i > 0 and j > 0: if dp[i][j] == dp[i - 1][j]: i -= 1 elif dp[i][j] == dp[i][j - 1]: j -= 1 else: ans.append(s[i - 1]) i -= 1 j -= 1 ans.reverse() print(("".join(ans)))
false
3.703704
[ "-dp = [[-1] * 3100 for _ in range(3100)]", "-# dp[i+1][j+1]: s[i], t[j]まで見たときのLCSの長さ", "-dp[0][0] = 0", "+dp = [[0] * 3100 for _ in range(3100)]", "-ans = \"\"", "+ans = []", "- ans = s[i - 1] + ans", "+ ans.append(s[i - 1])", "-print(ans)", "+ans.reverse()", "+print((\"\".join(ans)))" ]
false
0.035339
0.0356
0.99268
[ "s950183430", "s823134490" ]
u809819902
p02835
python
s550236385
s732640668
32
29
9,072
9,156
Accepted
Accepted
9.38
a = list(map(int, input().split())) print(("bust" if sum(a)>=22 else "win"))
a=list(map(int, input().split())) b=sum(a) print(("bust" if b>=22 else "win"))
2
3
69
78
a = list(map(int, input().split())) print(("bust" if sum(a) >= 22 else "win"))
a = list(map(int, input().split())) b = sum(a) print(("bust" if b >= 22 else "win"))
false
33.333333
[ "-print((\"bust\" if sum(a) >= 22 else \"win\"))", "+b = sum(a)", "+print((\"bust\" if b >= 22 else \"win\"))" ]
false
0.046503
0.047123
0.986858
[ "s550236385", "s732640668" ]
u579699847
p03163
python
s663987185
s334751257
738
358
121,200
22,440
Accepted
Accepted
51.49
import itertools,sys def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) N,W = LI() wv = [LI() for _ in range(N)] dp = [[0]*(W+1) for _ in range(N+1)] #1_indexed for i,j in itertools.product(list(range(N)),list(range(W+1))): w,v = wv[i] if j-w>=0: dp[i+1][j] = max(dp[i+1][j],dp[i][j-w]+v) dp[i+1][j] = max(dp[i+1][j],dp[i][j]) print((dp[-1][-1]))
import numpy as np,sys def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) N,W = LI() wv = [LI() for _ in range(N)] dp = np.zeros(W+1,dtype=int) #1_indexed for i in range(N): w,v = wv[i] dp[w:] = np.fmax(dp[:-w]+v,dp[w:]) print((dp[-1]))
11
9
382
270
import itertools, sys def LI(): return list(map(int, sys.stdin.readline().rstrip().split())) N, W = LI() wv = [LI() for _ in range(N)] dp = [[0] * (W + 1) for _ in range(N + 1)] # 1_indexed for i, j in itertools.product(list(range(N)), list(range(W + 1))): w, v = wv[i] if j - w >= 0: dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - w] + v) dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]) print((dp[-1][-1]))
import numpy as np, sys def LI(): return list(map(int, sys.stdin.readline().rstrip().split())) N, W = LI() wv = [LI() for _ in range(N)] dp = np.zeros(W + 1, dtype=int) # 1_indexed for i in range(N): w, v = wv[i] dp[w:] = np.fmax(dp[:-w] + v, dp[w:]) print((dp[-1]))
false
18.181818
[ "-import itertools, sys", "+import numpy as np, sys", "-dp = [[0] * (W + 1) for _ in range(N + 1)] # 1_indexed", "-for i, j in itertools.product(list(range(N)), list(range(W + 1))):", "+dp = np.zeros(W + 1, dtype=int) # 1_indexed", "+for i in range(N):", "- if j - w >= 0:", "- dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - w] + v)", "- dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])", "-print((dp[-1][-1]))", "+ dp[w:] = np.fmax(dp[:-w] + v, dp[w:])", "+print((dp[-1]))" ]
false
0.038694
0.182154
0.212426
[ "s663987185", "s334751257" ]
u687574784
p02712
python
s340899127
s719668769
113
21
30,120
9,008
Accepted
Accepted
81.42
print((sum([i for i in range(1, int(eval(input()))+1) if i%3!=0 and i%5!=0])))
n = int(eval(input())) def s(n): return n*(n+1)//2 print((s(n) - s(n//3)*3 - s(n//5)*5 + s(n//15)*15))
1
4
70
101
print((sum([i for i in range(1, int(eval(input())) + 1) if i % 3 != 0 and i % 5 != 0])))
n = int(eval(input())) def s(n): return n * (n + 1) // 2 print((s(n) - s(n // 3) * 3 - s(n // 5) * 5 + s(n // 15) * 15))
false
75
[ "-print((sum([i for i in range(1, int(eval(input())) + 1) if i % 3 != 0 and i % 5 != 0])))", "+n = int(eval(input()))", "+", "+", "+def s(n):", "+ return n * (n + 1) // 2", "+", "+", "+print((s(n) - s(n // 3) * 3 - s(n // 5) * 5 + s(n // 15) * 15))" ]
false
0.006632
0.031103
0.213237
[ "s340899127", "s719668769" ]
u562935282
p02883
python
s482383063
s733692002
648
569
122,900
122,132
Accepted
Accepted
12.19
def binary_search(*, ok, ng, func): while abs(ok - ng) > 1: mid = (ok + ng) // 2 if func(mid): ok = mid else: ng = mid return ok def main(): N, K = list(map(int, input().split())) *A, = sorted(map(int, input().split())) *F, = sorted(map(int, input().split()), reverse=True) def is_ok(score): rest = K for a, f in zip(A, F): exceed = max(0, a * f - score) if exceed: need = (exceed + f - 1) // f if need > a or need > rest: return False rest -= need return True ans = binary_search(ok=10 ** 12, ng=-1, func=is_ok) print(ans) if __name__ == '__main__': main()
# https://atcoder.jp/contests/abc144/submissions/8168248 # is_okでscoreを割るアイディア def binary_search(*, ok, ng, func): while abs(ok - ng) > 1: mid = (ok + ng) // 2 if func(mid): ok = mid else: ng = mid return ok def main(): N, K = list(map(int, input().split())) *A, = sorted(map(int, input().split())) *F, = sorted(map(int, input().split()), reverse=True) def is_ok(score): rest = K for a, f in zip(A, F): max_a = score // f rest -= max(0, a - max_a) if rest < 0: return False return True ans = binary_search(ok=10 ** 12, ng=-1, func=is_ok) print(ans) if __name__ == '__main__': main()
32
32
789
759
def binary_search(*, ok, ng, func): while abs(ok - ng) > 1: mid = (ok + ng) // 2 if func(mid): ok = mid else: ng = mid return ok def main(): N, K = list(map(int, input().split())) (*A,) = sorted(map(int, input().split())) (*F,) = sorted(map(int, input().split()), reverse=True) def is_ok(score): rest = K for a, f in zip(A, F): exceed = max(0, a * f - score) if exceed: need = (exceed + f - 1) // f if need > a or need > rest: return False rest -= need return True ans = binary_search(ok=10**12, ng=-1, func=is_ok) print(ans) if __name__ == "__main__": main()
# https://atcoder.jp/contests/abc144/submissions/8168248 # is_okでscoreを割るアイディア def binary_search(*, ok, ng, func): while abs(ok - ng) > 1: mid = (ok + ng) // 2 if func(mid): ok = mid else: ng = mid return ok def main(): N, K = list(map(int, input().split())) (*A,) = sorted(map(int, input().split())) (*F,) = sorted(map(int, input().split()), reverse=True) def is_ok(score): rest = K for a, f in zip(A, F): max_a = score // f rest -= max(0, a - max_a) if rest < 0: return False return True ans = binary_search(ok=10**12, ng=-1, func=is_ok) print(ans) if __name__ == "__main__": main()
false
0
[ "+# https://atcoder.jp/contests/abc144/submissions/8168248", "+# is_okでscoreを割るアイディア", "- exceed = max(0, a * f - score)", "- if exceed:", "- need = (exceed + f - 1) // f", "- if need > a or need > rest:", "- return False", "- rest -= need", "+ max_a = score // f", "+ rest -= max(0, a - max_a)", "+ if rest < 0:", "+ return False" ]
false
0.114133
0.042107
2.710558
[ "s482383063", "s733692002" ]
u129749062
p02641
python
s181168922
s592950420
37
27
9,188
9,184
Accepted
Accepted
27.03
import sys X ,N = list(map(int,input().split())) p = list(map(int,input().split())) min_dif = 10000 output = 10000 for i in range(10000): if (5000 - i in p) == False: if abs(X-(5000-i)) <= min_dif: min_dif = abs(X-(5000 - i)) output = 5000 - i print(output)
X,N = list(map(int,input().split())) p = list(map(int,input().split())) p.sort() diff = 100000 ans = 0 for i in range(-200, 200): if i not in p: if abs(X-i) < diff: diff = abs(X-i) ans = i print(ans)
13
11
292
221
import sys X, N = list(map(int, input().split())) p = list(map(int, input().split())) min_dif = 10000 output = 10000 for i in range(10000): if (5000 - i in p) == False: if abs(X - (5000 - i)) <= min_dif: min_dif = abs(X - (5000 - i)) output = 5000 - i print(output)
X, N = list(map(int, input().split())) p = list(map(int, input().split())) p.sort() diff = 100000 ans = 0 for i in range(-200, 200): if i not in p: if abs(X - i) < diff: diff = abs(X - i) ans = i print(ans)
false
15.384615
[ "-import sys", "-", "-min_dif = 10000", "-output = 10000", "-for i in range(10000):", "- if (5000 - i in p) == False:", "- if abs(X - (5000 - i)) <= min_dif:", "- min_dif = abs(X - (5000 - i))", "- output = 5000 - i", "-print(output)", "+p.sort()", "+diff = 100000", "+ans = 0", "+for i in range(-200, 200):", "+ if i not in p:", "+ if abs(X - i) < diff:", "+ diff = abs(X - i)", "+ ans = i", "+print(ans)" ]
false
0.101506
0.122056
0.831632
[ "s181168922", "s592950420" ]
u102461423
p02702
python
s238879261
s127185462
1,398
344
29,156
29,012
Accepted
Accepted
75.39
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import numpy as np def solve(S): dp = np.zeros(2019, np.int64) pow10 = 1 answer = 0 for x in S[::-1]: dp[0] += 1 x = x * pow10 % 2019 dp = np.roll(dp, x) answer += dp[0] pow10 *= 10 pow10 %= 2019 return answer def cc_export(): from numba.pycc import CC cc = CC('my_module') cc.export('solve', '(i4[:],)')(solve) cc.compile() try: from my_module import solve except: cc_export() exit() S = np.array(list(read().rstrip()), dtype=np.int32) - ord('0') print((solve(S)))
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import numpy as np def solve(S): dp = np.zeros(2019, np.int64) pow10 = 1 answer = 0 for x in S[::-1]: dp[0] += 1 x = x * pow10 % 2019 newdp = np.empty_like(dp) newdp[x:] = dp[:-x] newdp[:x] = dp[-x:] dp = newdp answer += dp[0] pow10 *= 10 pow10 %= 2019 return answer def cc_export(): from numba.pycc import CC cc = CC('my_module') cc.export('solve', '(i4[:],)')(solve) cc.compile() try: from my_module import solve except: cc_export() exit() S = np.array(list(read().rstrip()), dtype=np.int32) - ord('0') print((solve(S)))
36
39
718
802
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import numpy as np def solve(S): dp = np.zeros(2019, np.int64) pow10 = 1 answer = 0 for x in S[::-1]: dp[0] += 1 x = x * pow10 % 2019 dp = np.roll(dp, x) answer += dp[0] pow10 *= 10 pow10 %= 2019 return answer def cc_export(): from numba.pycc import CC cc = CC("my_module") cc.export("solve", "(i4[:],)")(solve) cc.compile() try: from my_module import solve except: cc_export() exit() S = np.array(list(read().rstrip()), dtype=np.int32) - ord("0") print((solve(S)))
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import numpy as np def solve(S): dp = np.zeros(2019, np.int64) pow10 = 1 answer = 0 for x in S[::-1]: dp[0] += 1 x = x * pow10 % 2019 newdp = np.empty_like(dp) newdp[x:] = dp[:-x] newdp[:x] = dp[-x:] dp = newdp answer += dp[0] pow10 *= 10 pow10 %= 2019 return answer def cc_export(): from numba.pycc import CC cc = CC("my_module") cc.export("solve", "(i4[:],)")(solve) cc.compile() try: from my_module import solve except: cc_export() exit() S = np.array(list(read().rstrip()), dtype=np.int32) - ord("0") print((solve(S)))
false
7.692308
[ "- dp = np.roll(dp, x)", "+ newdp = np.empty_like(dp)", "+ newdp[x:] = dp[:-x]", "+ newdp[:x] = dp[-x:]", "+ dp = newdp" ]
false
0.266237
0.257632
1.033402
[ "s238879261", "s127185462" ]
u095021077
p03037
python
s871989987
s308478670
574
457
44,136
12,504
Accepted
Accepted
20.38
temp=input().split() N=int(temp[0]) M=int(temp[1]) Lmax=int(0) Rmin=int(N-1) for i in range(M): temp=list(map(int, input().split())) if Lmax<temp[0]-1: Lmax=temp[0]-1 if Rmin>temp[1]-1: Rmin=temp[1]-1 if Rmin>=Lmax: print((Rmin-Lmax+1)) else: print((0))
import numpy as np N, M=list(map(int, input().split())) L=1 R=N for i in range(M): temp=list(map(int, input().split())) if L<temp[0]: L=temp[0] if R>temp[1]: R=temp[1] temp=int(R-L+1) if temp>0: print(temp) else: print((0))
18
21
295
269
temp = input().split() N = int(temp[0]) M = int(temp[1]) Lmax = int(0) Rmin = int(N - 1) for i in range(M): temp = list(map(int, input().split())) if Lmax < temp[0] - 1: Lmax = temp[0] - 1 if Rmin > temp[1] - 1: Rmin = temp[1] - 1 if Rmin >= Lmax: print((Rmin - Lmax + 1)) else: print((0))
import numpy as np N, M = list(map(int, input().split())) L = 1 R = N for i in range(M): temp = list(map(int, input().split())) if L < temp[0]: L = temp[0] if R > temp[1]: R = temp[1] temp = int(R - L + 1) if temp > 0: print(temp) else: print((0))
false
14.285714
[ "-temp = input().split()", "-N = int(temp[0])", "-M = int(temp[1])", "-Lmax = int(0)", "-Rmin = int(N - 1)", "+import numpy as np", "+", "+N, M = list(map(int, input().split()))", "+L = 1", "+R = N", "- if Lmax < temp[0] - 1:", "- Lmax = temp[0] - 1", "- if Rmin > temp[1] - 1:", "- Rmin = temp[1] - 1", "-if Rmin >= Lmax:", "- print((Rmin - Lmax + 1))", "+ if L < temp[0]:", "+ L = temp[0]", "+ if R > temp[1]:", "+ R = temp[1]", "+temp = int(R - L + 1)", "+if temp > 0:", "+ print(temp)" ]
false
0.040255
0.036775
1.094638
[ "s871989987", "s308478670" ]
u729133443
p03240
python
s319870854
s005737408
281
48
50,140
3,928
Accepted
Accepted
82.92
n=int(eval(input())) p=[list(map(int,input().split()))for _ in range(n)] ax,ay,ah=list([x for x in p if x[2]])[0] for x in range(101): for y in range(101): H=ah+abs(ax-x)+abs(ay-y) if all(max(H-abs(t[0]-x)-abs(t[1]-y),0)==t[2]for t in p): print((x,y,H))
n=int(eval(input()));p=eval('list(map(int,input().split())),'*n);x,y,h=[x for x in p if x[2]][0] for I in range(10201):j,i=I//101,I%101;H=h+abs(x-j)+abs(y-i);print((*(j,i,H)*all(max(H-abs(t[0]-j)-abs(t[1]-i),0)==t[2]for t in p)))
8
3
269
224
n = int(eval(input())) p = [list(map(int, input().split())) for _ in range(n)] ax, ay, ah = list([x for x in p if x[2]])[0] for x in range(101): for y in range(101): H = ah + abs(ax - x) + abs(ay - y) if all(max(H - abs(t[0] - x) - abs(t[1] - y), 0) == t[2] for t in p): print((x, y, H))
n = int(eval(input())) p = eval("list(map(int,input().split()))," * n) x, y, h = [x for x in p if x[2]][0] for I in range(10201): j, i = I // 101, I % 101 H = h + abs(x - j) + abs(y - i) print( (*(j, i, H) * all(max(H - abs(t[0] - j) - abs(t[1] - i), 0) == t[2] for t in p)) )
false
62.5
[ "-p = [list(map(int, input().split())) for _ in range(n)]", "-ax, ay, ah = list([x for x in p if x[2]])[0]", "-for x in range(101):", "- for y in range(101):", "- H = ah + abs(ax - x) + abs(ay - y)", "- if all(max(H - abs(t[0] - x) - abs(t[1] - y), 0) == t[2] for t in p):", "- print((x, y, H))", "+p = eval(\"list(map(int,input().split())),\" * n)", "+x, y, h = [x for x in p if x[2]][0]", "+for I in range(10201):", "+ j, i = I // 101, I % 101", "+ H = h + abs(x - j) + abs(y - i)", "+ print(", "+ (*(j, i, H) * all(max(H - abs(t[0] - j) - abs(t[1] - i), 0) == t[2] for t in p))", "+ )" ]
false
0.159912
0.063153
2.53216
[ "s319870854", "s005737408" ]
u094191970
p03085
python
s861035105
s413905361
20
17
3,060
2,940
Accepted
Accepted
15
b=eval(input()) print(('A' if b=='T' else 'T' if b=='A' else 'C' if b=='G' else 'G'))
s=eval(input()) print(('T' if s=='A' else 'G' if s=='C' else 'A' if s=='T' else 'C'))
2
2
78
78
b = eval(input()) print(("A" if b == "T" else "T" if b == "A" else "C" if b == "G" else "G"))
s = eval(input()) print(("T" if s == "A" else "G" if s == "C" else "A" if s == "T" else "C"))
false
0
[ "-b = eval(input())", "-print((\"A\" if b == \"T\" else \"T\" if b == \"A\" else \"C\" if b == \"G\" else \"G\"))", "+s = eval(input())", "+print((\"T\" if s == \"A\" else \"G\" if s == \"C\" else \"A\" if s == \"T\" else \"C\"))" ]
false
0.049068
0.050953
0.962996
[ "s861035105", "s413905361" ]
u476124554
p03111
python
s033355915
s851744287
245
73
3,192
4,984
Accepted
Accepted
70.2
from itertools import combinations def f(in_A,in_B,in_C,A,B,C,ex_l,counter): if (counter == len(ex_l)): return abs(in_A-A)+abs(in_B-B)+abs(in_C-C) else: tmp = ex_l[counter] counter +=1 a1 = f(in_A+tmp,in_B,in_C,A,B,C,ex_l,counter)+10 a2 = f(in_A,in_B+tmp,in_C,A,B,C,ex_l,counter)+10 a3 = f(in_A,in_B,in_C+tmp,A,B,C,ex_l,counter)+10 a4 = f(in_A,in_B,in_C,A,B,C,ex_l,counter) return min(a1,a2,a3,a4) N,A,B,C=list(map(int,input().split())) l = [] for i in range(N): l.append(int(eval(input()))) in_l = list(map(list,combinations(l,3))) ex_l = [l[:] for _ in range(len(in_l))] for i in range(len(in_l)): ex_l[i].remove(in_l[i][0]) ex_l[i].remove(in_l[i][1]) ex_l[i].remove(in_l[i][2]) mp = [] for i in range(len(in_l)): mp.append(f(in_l[i][0],in_l[i][1],in_l[i][2],A,B,C,ex_l[i],0)) mp.append(f(in_l[i][0],in_l[i][1],in_l[i][2],A,C,B,ex_l[i],0)) mp.append(f(in_l[i][0],in_l[i][1],in_l[i][2],B,A,C,ex_l[i],0)) mp.append(f(in_l[i][0],in_l[i][1],in_l[i][2],B,C,A,ex_l[i],0)) mp.append(f(in_l[i][0],in_l[i][1],in_l[i][2],C,A,B,ex_l[i],0)) mp.append(f(in_l[i][0],in_l[i][1],in_l[i][2],C,B,A,ex_l[i],0)) mp = min(mp) print(mp)
n,a,b,c = list(map(int,input().split())) l = [] ans = [] for i in range(n): l.append(int(eval(input()))) def f(x,y,z,arr,ca,cb,cc): global a global b global c global ans if arr: f(x + arr[0], y, z, arr[1:],ca+1,cb,cc) f(x, y + arr[0], z, arr[1:],ca,cb+1,cc) f(x, y, z + arr[0], arr[1:],ca,cb,cc+1) f(x, y, z, arr[1:],ca,cb,cc) else: if x > 0 and y > 0 and z > 0: ans.append(abs(a-x) + abs(b-y) + abs(c-z) + 10 * (ca + cb + cc - 3)) f(0,0,0,l,0,0,0) print((min(ans)))
35
21
1,249
559
from itertools import combinations def f(in_A, in_B, in_C, A, B, C, ex_l, counter): if counter == len(ex_l): return abs(in_A - A) + abs(in_B - B) + abs(in_C - C) else: tmp = ex_l[counter] counter += 1 a1 = f(in_A + tmp, in_B, in_C, A, B, C, ex_l, counter) + 10 a2 = f(in_A, in_B + tmp, in_C, A, B, C, ex_l, counter) + 10 a3 = f(in_A, in_B, in_C + tmp, A, B, C, ex_l, counter) + 10 a4 = f(in_A, in_B, in_C, A, B, C, ex_l, counter) return min(a1, a2, a3, a4) N, A, B, C = list(map(int, input().split())) l = [] for i in range(N): l.append(int(eval(input()))) in_l = list(map(list, combinations(l, 3))) ex_l = [l[:] for _ in range(len(in_l))] for i in range(len(in_l)): ex_l[i].remove(in_l[i][0]) ex_l[i].remove(in_l[i][1]) ex_l[i].remove(in_l[i][2]) mp = [] for i in range(len(in_l)): mp.append(f(in_l[i][0], in_l[i][1], in_l[i][2], A, B, C, ex_l[i], 0)) mp.append(f(in_l[i][0], in_l[i][1], in_l[i][2], A, C, B, ex_l[i], 0)) mp.append(f(in_l[i][0], in_l[i][1], in_l[i][2], B, A, C, ex_l[i], 0)) mp.append(f(in_l[i][0], in_l[i][1], in_l[i][2], B, C, A, ex_l[i], 0)) mp.append(f(in_l[i][0], in_l[i][1], in_l[i][2], C, A, B, ex_l[i], 0)) mp.append(f(in_l[i][0], in_l[i][1], in_l[i][2], C, B, A, ex_l[i], 0)) mp = min(mp) print(mp)
n, a, b, c = list(map(int, input().split())) l = [] ans = [] for i in range(n): l.append(int(eval(input()))) def f(x, y, z, arr, ca, cb, cc): global a global b global c global ans if arr: f(x + arr[0], y, z, arr[1:], ca + 1, cb, cc) f(x, y + arr[0], z, arr[1:], ca, cb + 1, cc) f(x, y, z + arr[0], arr[1:], ca, cb, cc + 1) f(x, y, z, arr[1:], ca, cb, cc) else: if x > 0 and y > 0 and z > 0: ans.append(abs(a - x) + abs(b - y) + abs(c - z) + 10 * (ca + cb + cc - 3)) f(0, 0, 0, l, 0, 0, 0) print((min(ans)))
false
40
[ "-from itertools import combinations", "+n, a, b, c = list(map(int, input().split()))", "+l = []", "+ans = []", "+for i in range(n):", "+ l.append(int(eval(input())))", "-def f(in_A, in_B, in_C, A, B, C, ex_l, counter):", "- if counter == len(ex_l):", "- return abs(in_A - A) + abs(in_B - B) + abs(in_C - C)", "+def f(x, y, z, arr, ca, cb, cc):", "+ global a", "+ global b", "+ global c", "+ global ans", "+ if arr:", "+ f(x + arr[0], y, z, arr[1:], ca + 1, cb, cc)", "+ f(x, y + arr[0], z, arr[1:], ca, cb + 1, cc)", "+ f(x, y, z + arr[0], arr[1:], ca, cb, cc + 1)", "+ f(x, y, z, arr[1:], ca, cb, cc)", "- tmp = ex_l[counter]", "- counter += 1", "- a1 = f(in_A + tmp, in_B, in_C, A, B, C, ex_l, counter) + 10", "- a2 = f(in_A, in_B + tmp, in_C, A, B, C, ex_l, counter) + 10", "- a3 = f(in_A, in_B, in_C + tmp, A, B, C, ex_l, counter) + 10", "- a4 = f(in_A, in_B, in_C, A, B, C, ex_l, counter)", "- return min(a1, a2, a3, a4)", "+ if x > 0 and y > 0 and z > 0:", "+ ans.append(abs(a - x) + abs(b - y) + abs(c - z) + 10 * (ca + cb + cc - 3))", "-N, A, B, C = list(map(int, input().split()))", "-l = []", "-for i in range(N):", "- l.append(int(eval(input())))", "-in_l = list(map(list, combinations(l, 3)))", "-ex_l = [l[:] for _ in range(len(in_l))]", "-for i in range(len(in_l)):", "- ex_l[i].remove(in_l[i][0])", "- ex_l[i].remove(in_l[i][1])", "- ex_l[i].remove(in_l[i][2])", "-mp = []", "-for i in range(len(in_l)):", "- mp.append(f(in_l[i][0], in_l[i][1], in_l[i][2], A, B, C, ex_l[i], 0))", "- mp.append(f(in_l[i][0], in_l[i][1], in_l[i][2], A, C, B, ex_l[i], 0))", "- mp.append(f(in_l[i][0], in_l[i][1], in_l[i][2], B, A, C, ex_l[i], 0))", "- mp.append(f(in_l[i][0], in_l[i][1], in_l[i][2], B, C, A, ex_l[i], 0))", "- mp.append(f(in_l[i][0], in_l[i][1], in_l[i][2], C, A, B, ex_l[i], 0))", "- mp.append(f(in_l[i][0], in_l[i][1], in_l[i][2], C, B, A, ex_l[i], 0))", "-mp = min(mp)", "-print(mp)", "+f(0, 0, 0, l, 0, 0, 0)", "+print((min(ans)))" ]
false
0.631062
0.137399
4.592923
[ "s033355915", "s851744287" ]
u023958502
p03078
python
s406476908
s200166740
827
36
4,592
4,852
Accepted
Accepted
95.65
import heapq X,Y,Z,K = list(map(int,input().split())) A = list(map(int,input().split())) B = list(map(int,input().split())) C = list(map(int,input().split())) asort,bsort,csort = sorted(A,reverse=True),sorted(B,reverse=True),sorted(C,reverse=True) already = [[0,0,0]] print((asort[0] + bsort[0] + csort[0])) x,y,z = 0,0,0 check = [] for k in range(K - 1): if [x + 1,y,z] not in already and x + 1 < X: already.append([x + 1,y,z]) heapq.heappush(check,(-(asort[x + 1] + bsort[y] + csort[z]),x + 1,y,z)) if [x,y + 1,z] not in already and y + 1 < Y: already.append([x,y + 1,z]) heapq.heappush(check,(-(asort[x] + bsort[y + 1] + csort[z]),x,y + 1,z)) if [x,y,z + 1] not in already and z + 1 < Z: already.append([x,y,z + 1]) heapq.heappush(check,(-(asort[x] + bsort[y] + csort[z + 1]),x,y,z + 1)) maxsum = heapq.heappop(check) print((-maxsum[0])) x,y,z = maxsum[1],maxsum[2],maxsum[3]
import heapq _x, _y, _z, k = list(map(int, input().split())) aa = list(reversed(sorted(map(int, input().split())))) bb = list(reversed(sorted(map(int, input().split())))) cc = list(reversed(sorted(map(int, input().split())))) ar = [] history = set() def push(x, y, z): if (x, y, z) in history: pass else: v = aa[x] + bb[y] + cc[z] heapq.heappush(ar, (-v, x, y, z)) history.add((x, y, z)) def pop(): (v, x, y, z) = heapq.heappop(ar) return (-v, x, y, z) push(0, 0, 0) for _ in range(k): (total, x, y, z) = pop() print(total) if x + 1 < len(aa): push(x + 1, y, z) if y + 1 < len(bb): push(x, y + 1, z) if z + 1 < len(cc): push(x, y, z + 1)
23
35
962
773
import heapq X, Y, Z, K = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) asort, bsort, csort = ( sorted(A, reverse=True), sorted(B, reverse=True), sorted(C, reverse=True), ) already = [[0, 0, 0]] print((asort[0] + bsort[0] + csort[0])) x, y, z = 0, 0, 0 check = [] for k in range(K - 1): if [x + 1, y, z] not in already and x + 1 < X: already.append([x + 1, y, z]) heapq.heappush(check, (-(asort[x + 1] + bsort[y] + csort[z]), x + 1, y, z)) if [x, y + 1, z] not in already and y + 1 < Y: already.append([x, y + 1, z]) heapq.heappush(check, (-(asort[x] + bsort[y + 1] + csort[z]), x, y + 1, z)) if [x, y, z + 1] not in already and z + 1 < Z: already.append([x, y, z + 1]) heapq.heappush(check, (-(asort[x] + bsort[y] + csort[z + 1]), x, y, z + 1)) maxsum = heapq.heappop(check) print((-maxsum[0])) x, y, z = maxsum[1], maxsum[2], maxsum[3]
import heapq _x, _y, _z, k = list(map(int, input().split())) aa = list(reversed(sorted(map(int, input().split())))) bb = list(reversed(sorted(map(int, input().split())))) cc = list(reversed(sorted(map(int, input().split())))) ar = [] history = set() def push(x, y, z): if (x, y, z) in history: pass else: v = aa[x] + bb[y] + cc[z] heapq.heappush(ar, (-v, x, y, z)) history.add((x, y, z)) def pop(): (v, x, y, z) = heapq.heappop(ar) return (-v, x, y, z) push(0, 0, 0) for _ in range(k): (total, x, y, z) = pop() print(total) if x + 1 < len(aa): push(x + 1, y, z) if y + 1 < len(bb): push(x, y + 1, z) if z + 1 < len(cc): push(x, y, z + 1)
false
34.285714
[ "-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()))", "-asort, bsort, csort = (", "- sorted(A, reverse=True),", "- sorted(B, reverse=True),", "- sorted(C, reverse=True),", "-)", "-already = [[0, 0, 0]]", "-print((asort[0] + bsort[0] + csort[0]))", "-x, y, z = 0, 0, 0", "-check = []", "-for k in range(K - 1):", "- if [x + 1, y, z] not in already and x + 1 < X:", "- already.append([x + 1, y, z])", "- heapq.heappush(check, (-(asort[x + 1] + bsort[y] + csort[z]), x + 1, y, z))", "- if [x, y + 1, z] not in already and y + 1 < Y:", "- already.append([x, y + 1, z])", "- heapq.heappush(check, (-(asort[x] + bsort[y + 1] + csort[z]), x, y + 1, z))", "- if [x, y, z + 1] not in already and z + 1 < Z:", "- already.append([x, y, z + 1])", "- heapq.heappush(check, (-(asort[x] + bsort[y] + csort[z + 1]), x, y, z + 1))", "- maxsum = heapq.heappop(check)", "- print((-maxsum[0]))", "- x, y, z = maxsum[1], maxsum[2], maxsum[3]", "+_x, _y, _z, k = list(map(int, input().split()))", "+aa = list(reversed(sorted(map(int, input().split()))))", "+bb = list(reversed(sorted(map(int, input().split()))))", "+cc = list(reversed(sorted(map(int, input().split()))))", "+ar = []", "+history = set()", "+", "+", "+def push(x, y, z):", "+ if (x, y, z) in history:", "+ pass", "+ else:", "+ v = aa[x] + bb[y] + cc[z]", "+ heapq.heappush(ar, (-v, x, y, z))", "+ history.add((x, y, z))", "+", "+", "+def pop():", "+ (v, x, y, z) = heapq.heappop(ar)", "+ return (-v, x, y, z)", "+", "+", "+push(0, 0, 0)", "+for _ in range(k):", "+ (total, x, y, z) = pop()", "+ print(total)", "+ if x + 1 < len(aa):", "+ push(x + 1, y, z)", "+ if y + 1 < len(bb):", "+ push(x, y + 1, z)", "+ if z + 1 < len(cc):", "+ push(x, y, z + 1)" ]
false
0.101503
0.037837
2.68262
[ "s406476908", "s200166740" ]
u301624971
p02861
python
s017392208
s621460463
383
18
3,064
3,064
Accepted
Accepted
95.3
import itertools import math N=int(eval(input())) x=[] y=[] for _ in range(N): x1,y1=list(map(int,input().split())) x.append(x1) y.append(y1) conut=[i for i in range(N)] conb=itertools.permutations(conut, N) total=0 for n,c in enumerate(conb): for i in range(N-1): n1=c[i] n2=c[i+1] h=math.sqrt((x[n1]-x[n2])**2 + (y[n1]-y[n2])**2) total+=h print((total/(n+1)))
import itertools N=int(eval(input())) XY=[] for _ in range(N): tmp=list(map(int,input().split())) XY.append(tmp) l=[i for i in range(N)] permutation = itertools.permutations(l, 2) total=0 for p in permutation: i=p[0] j=p[1] total+=((XY[i][0] - XY[j][0])**2 + (XY[i][1] - XY[j][1])**2)**0.5 print((total/N))
26
15
432
333
import itertools import math N = int(eval(input())) x = [] y = [] for _ in range(N): x1, y1 = list(map(int, input().split())) x.append(x1) y.append(y1) conut = [i for i in range(N)] conb = itertools.permutations(conut, N) total = 0 for n, c in enumerate(conb): for i in range(N - 1): n1 = c[i] n2 = c[i + 1] h = math.sqrt((x[n1] - x[n2]) ** 2 + (y[n1] - y[n2]) ** 2) total += h print((total / (n + 1)))
import itertools N = int(eval(input())) XY = [] for _ in range(N): tmp = list(map(int, input().split())) XY.append(tmp) l = [i for i in range(N)] permutation = itertools.permutations(l, 2) total = 0 for p in permutation: i = p[0] j = p[1] total += ((XY[i][0] - XY[j][0]) ** 2 + (XY[i][1] - XY[j][1]) ** 2) ** 0.5 print((total / N))
false
42.307692
[ "-import math", "-x = []", "-y = []", "+XY = []", "- x1, y1 = list(map(int, input().split()))", "- x.append(x1)", "- y.append(y1)", "-conut = [i for i in range(N)]", "-conb = itertools.permutations(conut, N)", "+ tmp = list(map(int, input().split()))", "+ XY.append(tmp)", "+l = [i for i in range(N)]", "+permutation = itertools.permutations(l, 2)", "-for n, c in enumerate(conb):", "- for i in range(N - 1):", "- n1 = c[i]", "- n2 = c[i + 1]", "- h = math.sqrt((x[n1] - x[n2]) ** 2 + (y[n1] - y[n2]) ** 2)", "- total += h", "-print((total / (n + 1)))", "+for p in permutation:", "+ i = p[0]", "+ j = p[1]", "+ total += ((XY[i][0] - XY[j][0]) ** 2 + (XY[i][1] - XY[j][1]) ** 2) ** 0.5", "+print((total / N))" ]
false
0.081931
0.03847
2.129755
[ "s017392208", "s621460463" ]
u006880673
p02936
python
s159996988
s363202559
1,507
1,129
193,492
239,840
Accepted
Accepted
25.08
import sys input = sys.stdin.readline N, Q = list(map(int, input().split())) a = [0]*(N) #1 index b = [0]*(N) #1 index p = [0]*(Q+1) #1 index x = [0]*(Q+1) #1 index counter = [0]*(N+1) #1 index for i in range(1, N): a[i], b[i] = list(map(int, input().split())) for i in range(1, Q+1): p[i], x[i] = list(map(int, input().split())) counter[p[i]] += x[i] from collections import deque graph = {i: deque() for i in range(1, N+1)} for i in range(1, N): graph[a[i]].append(b[i]) graph[b[i]].append(a[i]) def dfs(v): seen = [0]*(N+1) stack = [] seen[v] = 1 stack.append(v) while stack: s = stack[-1] if not graph[s]: stack.pop() continue g = graph[s].popleft() if seen[g]: continue seen[g] = 1 stack.append(g) counter[g] += counter[s] dfs(v=1) print((*counter[1:]))
from collections import deque, defaultdict N, Q = list(map(int, input().split())) G = defaultdict(lambda: deque()) for _ in range(N-1): a,b = list(map(int, input().split())) G[a].append(b) G[b].append(a) cnt = [0]*(N+1) for _ in range(Q): p, x = list(map(int, input().split())) cnt[p] += x def dfs(v, cnt): seen = [0] * (N+1) seen[v] = 1 stack = [v] while stack: v = stack[-1] if G[v]: w = G[v].popleft() if not seen[w]: # if 訪れていなければ cnt[w] += cnt[v] seen[w] = 1 stack.append(w) else: stack.pop() return cnt cnt = dfs(1, cnt) print((*cnt[1:]))
41
31
916
708
import sys input = sys.stdin.readline N, Q = list(map(int, input().split())) a = [0] * (N) # 1 index b = [0] * (N) # 1 index p = [0] * (Q + 1) # 1 index x = [0] * (Q + 1) # 1 index counter = [0] * (N + 1) # 1 index for i in range(1, N): a[i], b[i] = list(map(int, input().split())) for i in range(1, Q + 1): p[i], x[i] = list(map(int, input().split())) counter[p[i]] += x[i] from collections import deque graph = {i: deque() for i in range(1, N + 1)} for i in range(1, N): graph[a[i]].append(b[i]) graph[b[i]].append(a[i]) def dfs(v): seen = [0] * (N + 1) stack = [] seen[v] = 1 stack.append(v) while stack: s = stack[-1] if not graph[s]: stack.pop() continue g = graph[s].popleft() if seen[g]: continue seen[g] = 1 stack.append(g) counter[g] += counter[s] dfs(v=1) print((*counter[1:]))
from collections import deque, defaultdict N, Q = list(map(int, input().split())) G = defaultdict(lambda: deque()) for _ in range(N - 1): a, b = list(map(int, input().split())) G[a].append(b) G[b].append(a) cnt = [0] * (N + 1) for _ in range(Q): p, x = list(map(int, input().split())) cnt[p] += x def dfs(v, cnt): seen = [0] * (N + 1) seen[v] = 1 stack = [v] while stack: v = stack[-1] if G[v]: w = G[v].popleft() if not seen[w]: # if 訪れていなければ cnt[w] += cnt[v] seen[w] = 1 stack.append(w) else: stack.pop() return cnt cnt = dfs(1, cnt) print((*cnt[1:]))
false
24.390244
[ "-import sys", "+from collections import deque, defaultdict", "-input = sys.stdin.readline", "-a = [0] * (N) # 1 index", "-b = [0] * (N) # 1 index", "-p = [0] * (Q + 1) # 1 index", "-x = [0] * (Q + 1) # 1 index", "-counter = [0] * (N + 1) # 1 index", "-for i in range(1, N):", "- a[i], b[i] = list(map(int, input().split()))", "-for i in range(1, Q + 1):", "- p[i], x[i] = list(map(int, input().split()))", "- counter[p[i]] += x[i]", "-from collections import deque", "-", "-graph = {i: deque() for i in range(1, N + 1)}", "-for i in range(1, N):", "- graph[a[i]].append(b[i])", "- graph[b[i]].append(a[i])", "+G = defaultdict(lambda: deque())", "+for _ in range(N - 1):", "+ a, b = list(map(int, input().split()))", "+ G[a].append(b)", "+ G[b].append(a)", "+cnt = [0] * (N + 1)", "+for _ in range(Q):", "+ p, x = list(map(int, input().split()))", "+ cnt[p] += x", "-def dfs(v):", "+def dfs(v, cnt):", "- stack = []", "- stack.append(v)", "+ stack = [v]", "- s = stack[-1]", "- if not graph[s]:", "+ v = stack[-1]", "+ if G[v]:", "+ w = G[v].popleft()", "+ if not seen[w]: # if 訪れていなければ", "+ cnt[w] += cnt[v]", "+ seen[w] = 1", "+ stack.append(w)", "+ else:", "- continue", "- g = graph[s].popleft()", "- if seen[g]:", "- continue", "- seen[g] = 1", "- stack.append(g)", "- counter[g] += counter[s]", "+ return cnt", "-dfs(v=1)", "-print((*counter[1:]))", "+cnt = dfs(1, cnt)", "+print((*cnt[1:]))" ]
false
0.047546
0.043613
1.090168
[ "s159996988", "s363202559" ]
u279493135
p03103
python
s781534679
s741268569
1,951
302
22,384
29,024
Accepted
Accepted
84.52
N, M = list(map(int, input().split())) A_B = [] for i in range(N): A_B.append([int(x) for x in input().split()]) money = 0 count = 0 A_B = sorted(A_B) while count < M: if count+A_B[0][1] <= M: count += A_B[0][1] money += A_B[0][0] * A_B[0][1] else: money += A_B[0][0] * (M-count) count = M A_B.pop(0) print(money)
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left 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() AB = [LIST() for _ in range(N)] ans = 0 cnt = 0 AB = sorted(AB, reverse=True) while cnt < M: A, B = AB[-1] if cnt+B <= M: cnt += B ans += A*B else: ans += A * (M-cnt) cnt = M AB.pop() print(ans)
17
35
373
1,064
N, M = list(map(int, input().split())) A_B = [] for i in range(N): A_B.append([int(x) for x in input().split()]) money = 0 count = 0 A_B = sorted(A_B) while count < M: if count + A_B[0][1] <= M: count += A_B[0][1] money += A_B[0][0] * A_B[0][1] else: money += A_B[0][0] * (M - count) count = M A_B.pop(0) print(money)
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd from itertools import ( accumulate, permutations, combinations, product, groupby, combinations_with_replacement, ) from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left 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() AB = [LIST() for _ in range(N)] ans = 0 cnt = 0 AB = sorted(AB, reverse=True) while cnt < M: A, B = AB[-1] if cnt + B <= M: cnt += B ans += A * B else: ans += A * (M - cnt) cnt = M AB.pop() print(ans)
false
51.428571
[ "-N, M = list(map(int, input().split()))", "-A_B = []", "-for i in range(N):", "- A_B.append([int(x) for x in input().split()])", "-money = 0", "-count = 0", "-A_B = sorted(A_B)", "-while count < M:", "- if count + A_B[0][1] <= M:", "- count += A_B[0][1]", "- money += A_B[0][0] * A_B[0][1]", "+import sys, re", "+from collections import deque, defaultdict, Counter", "+from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd", "+from itertools import (", "+ accumulate,", "+ permutations,", "+ combinations,", "+ product,", "+ groupby,", "+ combinations_with_replacement,", "+)", "+from operator import itemgetter, mul", "+from copy import deepcopy", "+from string import ascii_lowercase, ascii_uppercase, digits", "+from bisect import bisect, bisect_left", "+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()", "+AB = [LIST() for _ in range(N)]", "+ans = 0", "+cnt = 0", "+AB = sorted(AB, reverse=True)", "+while cnt < M:", "+ A, B = AB[-1]", "+ if cnt + B <= M:", "+ cnt += B", "+ ans += A * B", "- money += A_B[0][0] * (M - count)", "- count = M", "- A_B.pop(0)", "-print(money)", "+ ans += A * (M - cnt)", "+ cnt = M", "+ AB.pop()", "+print(ans)" ]
false
0.040967
0.035867
1.142181
[ "s781534679", "s741268569" ]
u886747123
p03176
python
s949437682
s761034479
1,819
1,495
124,880
124,880
Accepted
Accepted
17.81
N = int(eval(input())) h = list(map(int, input().split())) a = list(map(int, input().split())) num = 2 while num <= N+1: num *= 2 seg = [0]*(2*num-1) #update(i,x):Aiをxに更新する def update(i,x): k = i + num - 1 while k >= 0: seg[k] = max(x,seg[k]) k = (k-1)//2 #query(a,b,0,0,num):[a,b)の最大値 def query(a,b,k,l,r): if r <= a or b <= l: return -1 elif a <= l and r <= b: return seg[k] else: return max(query(a,b,2*k+1,l,(l+r)//2),query(a,b,2*k+2,(l+r)//2,r)) for i in range(N): update(h[i], query(0,h[i],0,0,num) + a[i]) print((max(seg)))
N = int(eval(input())) h = list(map(int, input().split())) a = list(map(int, input().split())) num = 2**((N+1).bit_length()) seg = [0]*(2*num-1) #update(i,x):Aiをxに更新する def update(i,x): k = i + num - 1 while k >= 0: seg[k] = max(x,seg[k]) k = (k-1)//2 #query(a,b,0,0,num):[a,b)の最大値 def query(a,b,k,l,r): if r <= a or b <= l: return -1 elif a <= l and r <= b: return seg[k] else: return max(query(a,b,2*k+1,l,(l+r)//2),query(a,b,2*k+2,(l+r)//2,r)) for i in range(N): update(h[i], query(0,h[i],0,0,num) + a[i]) print((max(seg)))
31
29
627
616
N = int(eval(input())) h = list(map(int, input().split())) a = list(map(int, input().split())) num = 2 while num <= N + 1: num *= 2 seg = [0] * (2 * num - 1) # update(i,x):Aiをxに更新する def update(i, x): k = i + num - 1 while k >= 0: seg[k] = max(x, seg[k]) k = (k - 1) // 2 # query(a,b,0,0,num):[a,b)の最大値 def query(a, b, k, l, r): if r <= a or b <= l: return -1 elif a <= l and r <= b: return seg[k] else: return max( query(a, b, 2 * k + 1, l, (l + r) // 2), query(a, b, 2 * k + 2, (l + r) // 2, r), ) for i in range(N): update(h[i], query(0, h[i], 0, 0, num) + a[i]) print((max(seg)))
N = int(eval(input())) h = list(map(int, input().split())) a = list(map(int, input().split())) num = 2 ** ((N + 1).bit_length()) seg = [0] * (2 * num - 1) # update(i,x):Aiをxに更新する def update(i, x): k = i + num - 1 while k >= 0: seg[k] = max(x, seg[k]) k = (k - 1) // 2 # query(a,b,0,0,num):[a,b)の最大値 def query(a, b, k, l, r): if r <= a or b <= l: return -1 elif a <= l and r <= b: return seg[k] else: return max( query(a, b, 2 * k + 1, l, (l + r) // 2), query(a, b, 2 * k + 2, (l + r) // 2, r), ) for i in range(N): update(h[i], query(0, h[i], 0, 0, num) + a[i]) print((max(seg)))
false
6.451613
[ "-num = 2", "-while num <= N + 1:", "- num *= 2", "+num = 2 ** ((N + 1).bit_length())" ]
false
0.049156
0.044177
1.112708
[ "s949437682", "s761034479" ]
u989345508
p03287
python
s580250235
s829195788
390
86
14,484
14,628
Accepted
Accepted
77.95
from itertools import accumulate from collections import Counter import math def combinations_count(n, r): return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) n,m=list(map(int,input().split())) s=list([x%m for x in list(accumulate(list(map(int,input().split()))))]) s.append(0) #print(s) d=Counter(s) #print(d) ans=0 for i in d: if d[i]>=2: ans+=combinations_count(d[i],2) print(ans)
from itertools import accumulate from collections import Counter n,m=list(map(int,input().split())) s=[0]+list([x%m for x in list(accumulate(list(map(int,input().split()))))]) ans=0 for i in list(Counter(s).values()): ans+=(i*(i-1)//2) print(ans)
18
8
435
248
from itertools import accumulate from collections import Counter import math def combinations_count(n, r): return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) n, m = list(map(int, input().split())) s = list([x % m for x in list(accumulate(list(map(int, input().split()))))]) s.append(0) # print(s) d = Counter(s) # print(d) ans = 0 for i in d: if d[i] >= 2: ans += combinations_count(d[i], 2) print(ans)
from itertools import accumulate from collections import Counter n, m = list(map(int, input().split())) s = [0] + list([x % m for x in list(accumulate(list(map(int, input().split()))))]) ans = 0 for i in list(Counter(s).values()): ans += i * (i - 1) // 2 print(ans)
false
55.555556
[ "-import math", "-", "-", "-def combinations_count(n, r):", "- return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))", "-", "-s = list([x % m for x in list(accumulate(list(map(int, input().split()))))])", "-s.append(0)", "-# print(s)", "-d = Counter(s)", "-# print(d)", "+s = [0] + list([x % m for x in list(accumulate(list(map(int, input().split()))))])", "-for i in d:", "- if d[i] >= 2:", "- ans += combinations_count(d[i], 2)", "+for i in list(Counter(s).values()):", "+ ans += i * (i - 1) // 2" ]
false
0.072356
0.043143
1.677128
[ "s580250235", "s829195788" ]
u426764965
p02596
python
s609194585
s654585481
1,750
125
9,164
9,156
Accepted
Accepted
92.86
k = int(eval(input())) x = 0 ans = -1 if k % 2 == 1: for i in range(10**6): x = (x + 7 * pow(10, i, k)) % k if x == 0: ans = i + 1 break print(ans)
def abc174_c(): k = int(eval(input())) ans = -1 if k % 2 == 0 or k % 5 == 0: return ans f = 0 for i in range(k+1): f = (f * 10 + 7) % k if f == 0: ans = i + 1 break return ans if __name__ == '__main__': print((abc174_c()))
10
15
194
305
k = int(eval(input())) x = 0 ans = -1 if k % 2 == 1: for i in range(10**6): x = (x + 7 * pow(10, i, k)) % k if x == 0: ans = i + 1 break print(ans)
def abc174_c(): k = int(eval(input())) ans = -1 if k % 2 == 0 or k % 5 == 0: return ans f = 0 for i in range(k + 1): f = (f * 10 + 7) % k if f == 0: ans = i + 1 break return ans if __name__ == "__main__": print((abc174_c()))
false
33.333333
[ "-k = int(eval(input()))", "-x = 0", "-ans = -1", "-if k % 2 == 1:", "- for i in range(10**6):", "- x = (x + 7 * pow(10, i, k)) % k", "- if x == 0:", "+def abc174_c():", "+ k = int(eval(input()))", "+ ans = -1", "+ if k % 2 == 0 or k % 5 == 0:", "+ return ans", "+ f = 0", "+ for i in range(k + 1):", "+ f = (f * 10 + 7) % k", "+ if f == 0:", "-print(ans)", "+ return ans", "+", "+", "+if __name__ == \"__main__\":", "+ print((abc174_c()))" ]
false
0.610075
0.052714
11.573206
[ "s609194585", "s654585481" ]
u218843509
p02962
python
s259346084
s467381162
912
376
56,848
133,304
Accepted
Accepted
58.77
import sys def input(): return sys.stdin.readline()[:-1] class KMP(): def __init__(self, sentence): self.sentence = sent = sentence self.l = l = len(sent) self.table = table = [0 for _ in range(l+1)] table[0] = -1 j = -1 for i in range(l): while j >= 0 and sent[i] != sent[j]: j = table[j] j += 1 if i < l-1 and sent[i+1] == sent[j]: table[i+1] = table[j] else: table[i+1] = j def search(self, key): table = self.table sent = self.sentence l = self.l i = 0 res = [] for j in range(len(key)): while i > -1 and sent[i] != key[j]: i = table[i] i += 1 if i >= l: res.append(j-i+1) i = table[i] return res s = eval(input()) s_concat = s t = eval(input()) ns, nt = len(s), len(t) if ns == 1: if {s} == set(list(t)): print((-1)) else: print((0)) sys.exit() while len(s_concat) < ns + nt - 1: s_concat += s adj = [-1 for _ in range(ns)] kmp = KMP(t) matches = kmp.search(s_concat) for i in matches: if i >= ns: break if i == (i+nt)%ns: print((-1)) sys.exit() adj[i] = (i+nt)%ns visited = [False for _ in range(ns)] path_len = [0 for _ in range(ns)] def dfs(x): cur = x res = 0 while adj[cur] >= 0: visited[cur] = True if adj[cur] == x: print((-1)) sys.exit() res += 1 if path_len[adj[cur]] > 0: path_len[x] = path_len[adj[cur]] + res return path_len[adj[cur]] + res cur = adj[cur] path_len[x] = res return res ans = 0 for i in range(ns): if not visited[i]: d = dfs(i) ans = max(ans, d) if ans == ns: print((-1)) else: print(ans)
import sys def input(): return sys.stdin.readline()[:-1] def Z_algorithm(s): l = len(s) res = [-1 for _ in range(l)] res[0] = l i, j = 1, 0 while i < l: while i+j < l and s[j] == s[i+j]: j += 1 res[i] = j if j == 0: i += 1 continue else: k = 1 while i+k < l and k + res[k] < j: res[i+k] = res[k] k += 1 i += k j -= k return res s = eval(input()) s_concat = s t = eval(input()) ns, nt = len(s), len(t) if ns == 1: if {s} == set(list(t)): print((-1)) else: print((0)) sys.exit() while len(s_concat) < ns + nt - 1: s_concat += s ts_concat = t + " " + s_concat z = Z_algorithm(ts_concat) adj = [-1 for _ in range(ns)] for i in range(1, len(z)): if i-nt-1 >= ns: break if z[i] == nt: j = i-nt-1 if j == (j+nt)%ns: print((-1)) sys.exit() adj[j] = (j+nt)%ns visited = [False for _ in range(ns)] path_len = [0 for _ in range(ns)] def dfs(x): cur = x res = 0 while adj[cur] >= 0: visited[cur] = True if adj[cur] == x: print((-1)) sys.exit() res += 1 if path_len[adj[cur]] > 0: path_len[x] = path_len[adj[cur]] + res return path_len[adj[cur]] + res cur = adj[cur] path_len[x] = res return res ans = 0 for i in range(ns): if not visited[i]: d = dfs(i) ans = max(ans, d) if ans == ns: print((-1)) else: print(ans)
94
86
1,630
1,379
import sys def input(): return sys.stdin.readline()[:-1] class KMP: def __init__(self, sentence): self.sentence = sent = sentence self.l = l = len(sent) self.table = table = [0 for _ in range(l + 1)] table[0] = -1 j = -1 for i in range(l): while j >= 0 and sent[i] != sent[j]: j = table[j] j += 1 if i < l - 1 and sent[i + 1] == sent[j]: table[i + 1] = table[j] else: table[i + 1] = j def search(self, key): table = self.table sent = self.sentence l = self.l i = 0 res = [] for j in range(len(key)): while i > -1 and sent[i] != key[j]: i = table[i] i += 1 if i >= l: res.append(j - i + 1) i = table[i] return res s = eval(input()) s_concat = s t = eval(input()) ns, nt = len(s), len(t) if ns == 1: if {s} == set(list(t)): print((-1)) else: print((0)) sys.exit() while len(s_concat) < ns + nt - 1: s_concat += s adj = [-1 for _ in range(ns)] kmp = KMP(t) matches = kmp.search(s_concat) for i in matches: if i >= ns: break if i == (i + nt) % ns: print((-1)) sys.exit() adj[i] = (i + nt) % ns visited = [False for _ in range(ns)] path_len = [0 for _ in range(ns)] def dfs(x): cur = x res = 0 while adj[cur] >= 0: visited[cur] = True if adj[cur] == x: print((-1)) sys.exit() res += 1 if path_len[adj[cur]] > 0: path_len[x] = path_len[adj[cur]] + res return path_len[adj[cur]] + res cur = adj[cur] path_len[x] = res return res ans = 0 for i in range(ns): if not visited[i]: d = dfs(i) ans = max(ans, d) if ans == ns: print((-1)) else: print(ans)
import sys def input(): return sys.stdin.readline()[:-1] def Z_algorithm(s): l = len(s) res = [-1 for _ in range(l)] res[0] = l i, j = 1, 0 while i < l: while i + j < l and s[j] == s[i + j]: j += 1 res[i] = j if j == 0: i += 1 continue else: k = 1 while i + k < l and k + res[k] < j: res[i + k] = res[k] k += 1 i += k j -= k return res s = eval(input()) s_concat = s t = eval(input()) ns, nt = len(s), len(t) if ns == 1: if {s} == set(list(t)): print((-1)) else: print((0)) sys.exit() while len(s_concat) < ns + nt - 1: s_concat += s ts_concat = t + " " + s_concat z = Z_algorithm(ts_concat) adj = [-1 for _ in range(ns)] for i in range(1, len(z)): if i - nt - 1 >= ns: break if z[i] == nt: j = i - nt - 1 if j == (j + nt) % ns: print((-1)) sys.exit() adj[j] = (j + nt) % ns visited = [False for _ in range(ns)] path_len = [0 for _ in range(ns)] def dfs(x): cur = x res = 0 while adj[cur] >= 0: visited[cur] = True if adj[cur] == x: print((-1)) sys.exit() res += 1 if path_len[adj[cur]] > 0: path_len[x] = path_len[adj[cur]] + res return path_len[adj[cur]] + res cur = adj[cur] path_len[x] = res return res ans = 0 for i in range(ns): if not visited[i]: d = dfs(i) ans = max(ans, d) if ans == ns: print((-1)) else: print(ans)
false
8.510638
[ "-class KMP:", "- def __init__(self, sentence):", "- self.sentence = sent = sentence", "- self.l = l = len(sent)", "- self.table = table = [0 for _ in range(l + 1)]", "- table[0] = -1", "- j = -1", "- for i in range(l):", "- while j >= 0 and sent[i] != sent[j]:", "- j = table[j]", "+def Z_algorithm(s):", "+ l = len(s)", "+ res = [-1 for _ in range(l)]", "+ res[0] = l", "+ i, j = 1, 0", "+ while i < l:", "+ while i + j < l and s[j] == s[i + j]:", "- if i < l - 1 and sent[i + 1] == sent[j]:", "- table[i + 1] = table[j]", "- else:", "- table[i + 1] = j", "-", "- def search(self, key):", "- table = self.table", "- sent = self.sentence", "- l = self.l", "- i = 0", "- res = []", "- for j in range(len(key)):", "- while i > -1 and sent[i] != key[j]:", "- i = table[i]", "+ res[i] = j", "+ if j == 0:", "- if i >= l:", "- res.append(j - i + 1)", "- i = table[i]", "- return res", "+ continue", "+ else:", "+ k = 1", "+ while i + k < l and k + res[k] < j:", "+ res[i + k] = res[k]", "+ k += 1", "+ i += k", "+ j -= k", "+ return res", "+ts_concat = t + \" \" + s_concat", "+z = Z_algorithm(ts_concat)", "-kmp = KMP(t)", "-matches = kmp.search(s_concat)", "-for i in matches:", "- if i >= ns:", "+for i in range(1, len(z)):", "+ if i - nt - 1 >= ns:", "- if i == (i + nt) % ns:", "- print((-1))", "- sys.exit()", "- adj[i] = (i + nt) % ns", "+ if z[i] == nt:", "+ j = i - nt - 1", "+ if j == (j + nt) % ns:", "+ print((-1))", "+ sys.exit()", "+ adj[j] = (j + nt) % ns" ]
false
0.032185
0.13867
0.2321
[ "s259346084", "s467381162" ]
u818050295
p03721
python
s409866943
s946575110
384
300
5,924
5,928
Accepted
Accepted
21.88
tmp1 = list(map(int, input().split(" "))) num = [0 for i in range(10**5)] for i in range(tmp1[0]): tmp = list(map(int, input().split(" "))) num[tmp[0]-1] += tmp[1] tmp = 0 i = 0 while tmp < tmp1[1]: tmp = tmp + num[i] if tmp >= tmp1[1]: print((i+1)) i = i + 1
tmp = input().split(" ") K = int(tmp[1]) num = [0 for i in range(10**5)] for i in range(int(tmp[0])): tmp = input().split(" ") num[int(tmp[0])-1] += int(tmp[1]) tmp = 0 i = 0 while tmp < K: tmp = tmp + num[i] if tmp >= K: print((i+1)) i = i + 1
12
15
296
291
tmp1 = list(map(int, input().split(" "))) num = [0 for i in range(10**5)] for i in range(tmp1[0]): tmp = list(map(int, input().split(" "))) num[tmp[0] - 1] += tmp[1] tmp = 0 i = 0 while tmp < tmp1[1]: tmp = tmp + num[i] if tmp >= tmp1[1]: print((i + 1)) i = i + 1
tmp = input().split(" ") K = int(tmp[1]) num = [0 for i in range(10**5)] for i in range(int(tmp[0])): tmp = input().split(" ") num[int(tmp[0]) - 1] += int(tmp[1]) tmp = 0 i = 0 while tmp < K: tmp = tmp + num[i] if tmp >= K: print((i + 1)) i = i + 1
false
20
[ "-tmp1 = list(map(int, input().split(\" \")))", "+tmp = input().split(\" \")", "+K = int(tmp[1])", "-for i in range(tmp1[0]):", "- tmp = list(map(int, input().split(\" \")))", "- num[tmp[0] - 1] += tmp[1]", "+for i in range(int(tmp[0])):", "+ tmp = input().split(\" \")", "+ num[int(tmp[0]) - 1] += int(tmp[1])", "-while tmp < tmp1[1]:", "+while tmp < K:", "- if tmp >= tmp1[1]:", "+ if tmp >= K:" ]
false
0.159084
0.130407
1.219905
[ "s409866943", "s946575110" ]
u477320129
p02887
python
s168671440
s938864998
324
63
4,108
15,988
Accepted
Accepted
80.56
from functools import reduce _ = eval(input()) S = eval(input()) print((len(reduce(lambda a, b: a if a[-1] == b else a + b , S[1:], S[0]))))
from itertools import groupby _ = eval(input()) print((len(tuple(groupby(eval(input()))))))
4
3
129
80
from functools import reduce _ = eval(input()) S = eval(input()) print((len(reduce(lambda a, b: a if a[-1] == b else a + b, S[1:], S[0]))))
from itertools import groupby _ = eval(input()) print((len(tuple(groupby(eval(input()))))))
false
25
[ "-from functools import reduce", "+from itertools import groupby", "-S = eval(input())", "-print((len(reduce(lambda a, b: a if a[-1] == b else a + b, S[1:], S[0]))))", "+print((len(tuple(groupby(eval(input()))))))" ]
false
0.054146
0.0417
1.298454
[ "s168671440", "s938864998" ]
u079022693
p02629
python
s140840269
s098451820
30
25
9,152
9,172
Accepted
Accepted
16.67
def to_n(x,n): ans=[] if x==0: return [0] while x>0: x-=1 ans.append(x%n) x//=n return ans[::-1] from sys import stdin def main(): #入力 readline=stdin.readline n=int(readline()) alp=[chr(i) for i in range(97,97+26)] m=to_n(n,26) ans=[alp[m[i]] for i in range(len(m))] print(("".join(ans))) if __name__=="__main__": main()
def to_n(x,n,cnt): ans=[] for _ in range(cnt): ans.append(x%n) x//=n return ans[::-1] from sys import stdin def main(): #入力 readline=stdin.readline n=int(readline()) alp=[chr(i) for i in range(97,97+26)] tmp=26 cnt=1 while n>tmp: n-=tmp tmp*=26 cnt+=1 n-=1 m=to_n(n,26,cnt) ans="".join([alp[m[i]] for i in range(len(m))]) print(ans) if __name__=="__main__": main()
23
29
423
501
def to_n(x, n): ans = [] if x == 0: return [0] while x > 0: x -= 1 ans.append(x % n) x //= n return ans[::-1] from sys import stdin def main(): # 入力 readline = stdin.readline n = int(readline()) alp = [chr(i) for i in range(97, 97 + 26)] m = to_n(n, 26) ans = [alp[m[i]] for i in range(len(m))] print(("".join(ans))) if __name__ == "__main__": main()
def to_n(x, n, cnt): ans = [] for _ in range(cnt): ans.append(x % n) x //= n return ans[::-1] from sys import stdin def main(): # 入力 readline = stdin.readline n = int(readline()) alp = [chr(i) for i in range(97, 97 + 26)] tmp = 26 cnt = 1 while n > tmp: n -= tmp tmp *= 26 cnt += 1 n -= 1 m = to_n(n, 26, cnt) ans = "".join([alp[m[i]] for i in range(len(m))]) print(ans) if __name__ == "__main__": main()
false
20.689655
[ "-def to_n(x, n):", "+def to_n(x, n, cnt):", "- if x == 0:", "- return [0]", "- while x > 0:", "- x -= 1", "+ for _ in range(cnt):", "- m = to_n(n, 26)", "- ans = [alp[m[i]] for i in range(len(m))]", "- print((\"\".join(ans)))", "+ tmp = 26", "+ cnt = 1", "+ while n > tmp:", "+ n -= tmp", "+ tmp *= 26", "+ cnt += 1", "+ n -= 1", "+ m = to_n(n, 26, cnt)", "+ ans = \"\".join([alp[m[i]] for i in range(len(m))])", "+ print(ans)" ]
false
0.034797
0.076568
0.454454
[ "s140840269", "s098451820" ]
u864090097
p02584
python
s998159752
s273711296
37
29
9,172
9,116
Accepted
Accepted
21.62
X, K, D = list(map(int ,input().split())) if K * D < abs(X): ans = abs(X) - K * D else: if abs(X) // D % 2 == 0: if K % 2 == 0: ans = abs(X) % D else: ans = abs(abs(X) % D - D) else: if K % 2 == 0: ans = abs(abs(X) % D - D) else: ans = abs(X) % D print(ans)
X, K, D = list(map(int ,input().split())) X = abs(X) if K * D < X: ans = X - K * D else: if X // D % 2 == 0: if K % 2 == 0: ans = X % D else: ans = abs(X % D - D) else: if K % 2 == 0: ans = abs(X % D - D) else: ans = X % D print(ans)
17
18
361
339
X, K, D = list(map(int, input().split())) if K * D < abs(X): ans = abs(X) - K * D else: if abs(X) // D % 2 == 0: if K % 2 == 0: ans = abs(X) % D else: ans = abs(abs(X) % D - D) else: if K % 2 == 0: ans = abs(abs(X) % D - D) else: ans = abs(X) % D print(ans)
X, K, D = list(map(int, input().split())) X = abs(X) if K * D < X: ans = X - K * D else: if X // D % 2 == 0: if K % 2 == 0: ans = X % D else: ans = abs(X % D - D) else: if K % 2 == 0: ans = abs(X % D - D) else: ans = X % D print(ans)
false
5.555556
[ "-if K * D < abs(X):", "- ans = abs(X) - K * D", "+X = abs(X)", "+if K * D < X:", "+ ans = X - K * D", "- if abs(X) // D % 2 == 0:", "+ if X // D % 2 == 0:", "- ans = abs(X) % D", "+ ans = X % D", "- ans = abs(abs(X) % D - D)", "+ ans = abs(X % D - D)", "- ans = abs(abs(X) % D - D)", "+ ans = abs(X % D - D)", "- ans = abs(X) % D", "+ ans = X % D" ]
false
0.044004
0.049148
0.895336
[ "s998159752", "s273711296" ]
u562935282
p03105
python
s100120702
s200206595
21
17
3,316
2,940
Accepted
Accepted
19.05
a, b, c = list(map(int, input().split())) max = (b // a) print((max if max < c else c))
A, B, C = list(map(int, input().split())) print((min(B // A, C)))
5
2
85
59
a, b, c = list(map(int, input().split())) max = b // a print((max if max < c else c))
A, B, C = list(map(int, input().split())) print((min(B // A, C)))
false
60
[ "-a, b, c = list(map(int, input().split()))", "-max = b // a", "-print((max if max < c else c))", "+A, B, C = list(map(int, input().split()))", "+print((min(B // A, C)))" ]
false
0.091317
0.120444
0.758163
[ "s100120702", "s200206595" ]
u476604182
p03837
python
s048932680
s958633309
549
239
64,092
17,244
Accepted
Accepted
56.47
from collections import defaultdict from heapq import heappush, heappop N, M = list(map(int, input().split())) dic = defaultdict(list) Els = [] for i in range(M): a, b, c = list(map(int, input().split())) dic[a-1] += [(b-1,c)] dic[b-1] += [(a-1, c)] Els += [(a-1,b-1,c)] def dijkstra(s,e): dist = [float('inf')]*N dist[s] = 0 q = [(0,s)] z = -1 while q: c, v = heappop(q) if dist[v]<c: continue dist[v] = c for u, m in dic[v]: if dist[u]>dist[v]+m: dist[u] = dist[v]+m heappush(q,(dist[u],u)) if u==e: z = v return z ans = 0 for a, b, c in Els: if dijkstra(a,b)!=a: ans += 1 print(ans)
from scipy.sparse.csgraph import shortest_path N, M = list(map(int, input().split())) dic = [[0]*N for i in range(N)] Els = [] for i in range(M): a, b, c = list(map(int, input().split())) dic[a-1][b-1] = c dic[b-1][a-1] = c Els += [(a-1,b-1,c)] d, p = shortest_path(dic, return_predecessors=True, method='D') ans = 0 for a, b, c in Els: if p[a][b]!=a: ans += 1 print(ans)
34
16
696
389
from collections import defaultdict from heapq import heappush, heappop N, M = list(map(int, input().split())) dic = defaultdict(list) Els = [] for i in range(M): a, b, c = list(map(int, input().split())) dic[a - 1] += [(b - 1, c)] dic[b - 1] += [(a - 1, c)] Els += [(a - 1, b - 1, c)] def dijkstra(s, e): dist = [float("inf")] * N dist[s] = 0 q = [(0, s)] z = -1 while q: c, v = heappop(q) if dist[v] < c: continue dist[v] = c for u, m in dic[v]: if dist[u] > dist[v] + m: dist[u] = dist[v] + m heappush(q, (dist[u], u)) if u == e: z = v return z ans = 0 for a, b, c in Els: if dijkstra(a, b) != a: ans += 1 print(ans)
from scipy.sparse.csgraph import shortest_path N, M = list(map(int, input().split())) dic = [[0] * N for i in range(N)] Els = [] for i in range(M): a, b, c = list(map(int, input().split())) dic[a - 1][b - 1] = c dic[b - 1][a - 1] = c Els += [(a - 1, b - 1, c)] d, p = shortest_path(dic, return_predecessors=True, method="D") ans = 0 for a, b, c in Els: if p[a][b] != a: ans += 1 print(ans)
false
52.941176
[ "-from collections import defaultdict", "-from heapq import heappush, heappop", "+from scipy.sparse.csgraph import shortest_path", "-dic = defaultdict(list)", "+dic = [[0] * N for i in range(N)]", "- dic[a - 1] += [(b - 1, c)]", "- dic[b - 1] += [(a - 1, c)]", "+ dic[a - 1][b - 1] = c", "+ dic[b - 1][a - 1] = c", "-", "-", "-def dijkstra(s, e):", "- dist = [float(\"inf\")] * N", "- dist[s] = 0", "- q = [(0, s)]", "- z = -1", "- while q:", "- c, v = heappop(q)", "- if dist[v] < c:", "- continue", "- dist[v] = c", "- for u, m in dic[v]:", "- if dist[u] > dist[v] + m:", "- dist[u] = dist[v] + m", "- heappush(q, (dist[u], u))", "- if u == e:", "- z = v", "- return z", "-", "-", "+d, p = shortest_path(dic, return_predecessors=True, method=\"D\")", "- if dijkstra(a, b) != a:", "+ if p[a][b] != a:" ]
false
0.038827
0.304387
0.127559
[ "s048932680", "s958633309" ]
u912237403
p00070
python
s401181428
s713773506
3,580
2,850
4,252
4,252
Accepted
Accepted
20.39
import sys def f0070(A,n,s): if n==1: if s in A:f=1 else:f=0 return f c=0 A=sorted(A) A1=A[:n][::-1] A2=A[-n:] N=list(range(n)) def f(A): return sum([(i+1)*A[i] for i in N]) if f(A1)<=s<=f(A2): for i in range(len(A)): b=s-A[i]*n c+=f0070(A[:i]+A[i+1:],n-1,b) return c for a in sys.stdin: n,s=list(map(int,a.split())) print(f0070(list(range(10)),n,s))
import sys def f0070(A,n,s): if n==1:return s in A A=sorted(A) A1=A[:n][::-1] A2=A[-n:] N=list(range(n)) b1=0 b2=0 c=0 for i in N: b1+=(i+1)*A1[i] b2+=(i+1)*A2[i] if b1<=s<=b2: for i in range(len(A)): b=s-A[i]*n c+=f0070(A[:i]+A[i+1:],n-1,b) return c for a in sys.stdin: n,s=list(map(int,a.split())) print(f0070(list(range(10)),n,s))
22
21
407
384
import sys def f0070(A, n, s): if n == 1: if s in A: f = 1 else: f = 0 return f c = 0 A = sorted(A) A1 = A[:n][::-1] A2 = A[-n:] N = list(range(n)) def f(A): return sum([(i + 1) * A[i] for i in N]) if f(A1) <= s <= f(A2): for i in range(len(A)): b = s - A[i] * n c += f0070(A[:i] + A[i + 1 :], n - 1, b) return c for a in sys.stdin: n, s = list(map(int, a.split())) print(f0070(list(range(10)), n, s))
import sys def f0070(A, n, s): if n == 1: return s in A A = sorted(A) A1 = A[:n][::-1] A2 = A[-n:] N = list(range(n)) b1 = 0 b2 = 0 c = 0 for i in N: b1 += (i + 1) * A1[i] b2 += (i + 1) * A2[i] if b1 <= s <= b2: for i in range(len(A)): b = s - A[i] * n c += f0070(A[:i] + A[i + 1 :], n - 1, b) return c for a in sys.stdin: n, s = list(map(int, a.split())) print(f0070(list(range(10)), n, s))
false
4.545455
[ "- if s in A:", "- f = 1", "- else:", "- f = 0", "- return f", "- c = 0", "+ return s in A", "-", "- def f(A):", "- return sum([(i + 1) * A[i] for i in N])", "-", "- if f(A1) <= s <= f(A2):", "+ b1 = 0", "+ b2 = 0", "+ c = 0", "+ for i in N:", "+ b1 += (i + 1) * A1[i]", "+ b2 += (i + 1) * A2[i]", "+ if b1 <= s <= b2:" ]
false
0.036617
0.036246
1.010216
[ "s401181428", "s713773506" ]
u023229441
p03309
python
s486033661
s702065673
271
145
26,892
123,112
Accepted
Accepted
46.49
import sys import math mod=10**9+7 inf=float("inf") from math import sqrt from collections import deque from collections import Counter input=lambda: sys.stdin.readline().strip() sys.setrecursionlimit(11451419) from functools import lru_cache #メモ化再帰defの冒頭に毎回 @lru_cache(maxsize=10**10) #引数にlistはだめ #######ここまでテンプレ####### #######ここから天ぷら######## n=int(eval(input())) A=list(map(int,input().split())) SA=[0 for i in range(n)] for i in range(n): SA[i]=A[i]-i-1 SA.sort() if n%2==0: geta=(SA[n//2]+SA[n//2-1])//2 else: geta=SA[n//2] ans=0 for i in range(n): ans+= abs(A[i]-(geta+i+1)) print(ans)
n=int(eval(input())) A=list(map(int,input().split())) if n==1:print((0));exit() A=[A[i]-i-1 for i in range(n)] B=sorted(A) #print(B) if n%2==1: d=B[n//2] print((sum([abs(A[i]-d) for i in range(n)]))) exit() ans=0 d=(B[n//2-1]+B[n//2])//2 print((sum([abs(A[i]-d) for i in range(n)])))
29
16
630
302
import sys import math mod = 10**9 + 7 inf = float("inf") from math import sqrt from collections import deque from collections import Counter input = lambda: sys.stdin.readline().strip() sys.setrecursionlimit(11451419) from functools import lru_cache # メモ化再帰defの冒頭に毎回 @lru_cache(maxsize=10**10) # 引数にlistはだめ #######ここまでテンプレ####### #######ここから天ぷら######## n = int(eval(input())) A = list(map(int, input().split())) SA = [0 for i in range(n)] for i in range(n): SA[i] = A[i] - i - 1 SA.sort() if n % 2 == 0: geta = (SA[n // 2] + SA[n // 2 - 1]) // 2 else: geta = SA[n // 2] ans = 0 for i in range(n): ans += abs(A[i] - (geta + i + 1)) print(ans)
n = int(eval(input())) A = list(map(int, input().split())) if n == 1: print((0)) exit() A = [A[i] - i - 1 for i in range(n)] B = sorted(A) # print(B) if n % 2 == 1: d = B[n // 2] print((sum([abs(A[i] - d) for i in range(n)]))) exit() ans = 0 d = (B[n // 2 - 1] + B[n // 2]) // 2 print((sum([abs(A[i] - d) for i in range(n)])))
false
44.827586
[ "-import sys", "-import math", "-", "-mod = 10**9 + 7", "-inf = float(\"inf\")", "-from math import sqrt", "-from collections import deque", "-from collections import Counter", "-", "-input = lambda: sys.stdin.readline().strip()", "-sys.setrecursionlimit(11451419)", "-from functools import lru_cache", "-", "-# メモ化再帰defの冒頭に毎回 @lru_cache(maxsize=10**10)", "-# 引数にlistはだめ", "-#######ここまでテンプレ#######", "-#######ここから天ぷら########", "-SA = [0 for i in range(n)]", "-for i in range(n):", "- SA[i] = A[i] - i - 1", "-SA.sort()", "-if n % 2 == 0:", "- geta = (SA[n // 2] + SA[n // 2 - 1]) // 2", "-else:", "- geta = SA[n // 2]", "+if n == 1:", "+ print((0))", "+ exit()", "+A = [A[i] - i - 1 for i in range(n)]", "+B = sorted(A)", "+# print(B)", "+if n % 2 == 1:", "+ d = B[n // 2]", "+ print((sum([abs(A[i] - d) for i in range(n)])))", "+ exit()", "-for i in range(n):", "- ans += abs(A[i] - (geta + i + 1))", "-print(ans)", "+d = (B[n // 2 - 1] + B[n // 2]) // 2", "+print((sum([abs(A[i] - d) for i in range(n)])))" ]
false
0.083311
0.220692
0.3775
[ "s486033661", "s702065673" ]
u576432509
p03836
python
s463328355
s474281046
20
17
3,064
3,060
Accepted
Accepted
15
sx,sy,tx,ty=list(map(int,input().split())) dx=tx-sx dy=ty-sy root="" for i in range(dy): root=root+"U" for i in range(dx): root=root+"R" for i in range(dy): root=root+"D" for i in range(dx): root=root+"L" root=root+"L" for i in range(dy+1): root=root+"U" for i in range(dx+1): root=root+"R" root=root+"D" root=root+"R" for i in range(dy+1): root=root+"D" for i in range(dx+1): root=root+"L" root=root+"U" print(root)
sx,sy,tx,ty=list(map(int,input().split())) dx=tx-sx dy=ty-sy r="U"*dy+"R"*dx r=r+"D"*dy+"L"*dx r=r+"L"+"U"*(dy+1)+"R"*(dx+1)+"D" r=r+"R"+"D"*(dy+1)+"L"*(dx+1)+"U" print(r)
31
10
486
176
sx, sy, tx, ty = list(map(int, input().split())) dx = tx - sx dy = ty - sy root = "" for i in range(dy): root = root + "U" for i in range(dx): root = root + "R" for i in range(dy): root = root + "D" for i in range(dx): root = root + "L" root = root + "L" for i in range(dy + 1): root = root + "U" for i in range(dx + 1): root = root + "R" root = root + "D" root = root + "R" for i in range(dy + 1): root = root + "D" for i in range(dx + 1): root = root + "L" root = root + "U" print(root)
sx, sy, tx, ty = list(map(int, input().split())) dx = tx - sx dy = ty - sy r = "U" * dy + "R" * dx r = r + "D" * dy + "L" * dx r = r + "L" + "U" * (dy + 1) + "R" * (dx + 1) + "D" r = r + "R" + "D" * (dy + 1) + "L" * (dx + 1) + "U" print(r)
false
67.741935
[ "-root = \"\"", "-for i in range(dy):", "- root = root + \"U\"", "-for i in range(dx):", "- root = root + \"R\"", "-for i in range(dy):", "- root = root + \"D\"", "-for i in range(dx):", "- root = root + \"L\"", "-root = root + \"L\"", "-for i in range(dy + 1):", "- root = root + \"U\"", "-for i in range(dx + 1):", "- root = root + \"R\"", "-root = root + \"D\"", "-root = root + \"R\"", "-for i in range(dy + 1):", "- root = root + \"D\"", "-for i in range(dx + 1):", "- root = root + \"L\"", "-root = root + \"U\"", "-print(root)", "+r = \"U\" * dy + \"R\" * dx", "+r = r + \"D\" * dy + \"L\" * dx", "+r = r + \"L\" + \"U\" * (dy + 1) + \"R\" * (dx + 1) + \"D\"", "+r = r + \"R\" + \"D\" * (dy + 1) + \"L\" * (dx + 1) + \"U\"", "+print(r)" ]
false
0.067875
0.071222
0.953003
[ "s463328355", "s474281046" ]
u083960235
p02899
python
s752592024
s341530400
307
139
25,624
15,940
Accepted
Accepted
54.72
import sys, re, os from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import permutations, combinations, product, accumulate from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from fractions import gcd def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def S_MAP(): return list(map(str, input().split())) def LIST(): return list(map(int, input().split())) def S_LIST(): return list(map(str, input().split())) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10 ** 9 + 7 N = INT() A = LIST() L = [] for i, a in enumerate(A): L.append([i+1, a]) L = sorted(L,key=lambda x: x[1]) ans = [] for i in range(N): ans.append(L[i][0]) print((*ans))
import sys, re, os from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import permutations, combinations, product, accumulate from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from fractions import gcd def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def S_MAP(): return list(map(str, input().split())) def LIST(): return list(map(int, input().split())) def S_LIST(): return list(map(str, input().split())) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10 ** 9 + 7 N = INT() A = LIST() ans = [0] * N for i in range(len(A)): ans[A[i]-1] = i + 1 print((*ans)) # L = [] # for i, a in enumerate(A): # L.append([i+1, a]) # L = sorted(L,key=lambda x: x[1]) # ans = [] # for i in range(N): # ans.append(L[i][0]) # print(*ans)
33
41
919
1,021
import sys, re, os from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import permutations, combinations, product, accumulate from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from fractions import gcd def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def S_MAP(): return list(map(str, input().split())) def LIST(): return list(map(int, input().split())) def S_LIST(): return list(map(str, input().split())) sys.setrecursionlimit(10**9) INF = float("inf") mod = 10**9 + 7 N = INT() A = LIST() L = [] for i, a in enumerate(A): L.append([i + 1, a]) L = sorted(L, key=lambda x: x[1]) ans = [] for i in range(N): ans.append(L[i][0]) print((*ans))
import sys, re, os from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import permutations, combinations, product, accumulate from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from fractions import gcd def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def S_MAP(): return list(map(str, input().split())) def LIST(): return list(map(int, input().split())) def S_LIST(): return list(map(str, input().split())) sys.setrecursionlimit(10**9) INF = float("inf") mod = 10**9 + 7 N = INT() A = LIST() ans = [0] * N for i in range(len(A)): ans[A[i] - 1] = i + 1 print((*ans)) # L = [] # for i, a in enumerate(A): # L.append([i+1, a]) # L = sorted(L,key=lambda x: x[1]) # ans = [] # for i in range(N): # ans.append(L[i][0]) # print(*ans)
false
19.512195
[ "-L = []", "-for i, a in enumerate(A):", "- L.append([i + 1, a])", "-L = sorted(L, key=lambda x: x[1])", "-ans = []", "-for i in range(N):", "- ans.append(L[i][0])", "+ans = [0] * N", "+for i in range(len(A)):", "+ ans[A[i] - 1] = i + 1", "+# L = []", "+# for i, a in enumerate(A):", "+# L.append([i+1, a])", "+# L = sorted(L,key=lambda x: x[1])", "+# ans = []", "+# for i in range(N):", "+# ans.append(L[i][0])", "+# print(*ans)" ]
false
0.036835
0.036799
1.000986
[ "s752592024", "s341530400" ]
u373047809
p02744
python
s217309901
s756898408
195
156
17,884
24,176
Accepted
Accepted
20
k = "a", for _ in range(int(input()) - 1): k = {a + b for a in k for b in a + chr(ord(max(a)) + 1)} print(*sorted(k), sep='\n')
k = "a", for _ in range(int(eval(input())) - 1): k = {a + b for a in k for b in a + chr(ord(max(a)) + 1)} for i in sorted(k):print(i)
4
4
132
132
k = ("a",) for _ in range(int(input()) - 1): k = {a + b for a in k for b in a + chr(ord(max(a)) + 1)} print(*sorted(k), sep="\n")
k = ("a",) for _ in range(int(eval(input())) - 1): k = {a + b for a in k for b in a + chr(ord(max(a)) + 1)} for i in sorted(k): print(i)
false
0
[ "-for _ in range(int(input()) - 1):", "+for _ in range(int(eval(input())) - 1):", "-print(*sorted(k), sep=\"\\n\")", "+for i in sorted(k):", "+ print(i)" ]
false
0.039359
0.037045
1.06247
[ "s217309901", "s756898408" ]
u022979415
p03295
python
s767956331
s613752435
455
412
29,088
22,820
Accepted
Accepted
9.45
def main(): islands, request_num = list(map(int, input().split())) demolition = [] requests = [] for _ in range(request_num): requests.append(list(map(int, input().split()))) requests.sort(key=lambda x: x[1], reverse=False) for begin, end in requests: if 0 < len(demolition) and begin <= demolition[-1] < end: continue else: demolition.append(end - 1) print((len(demolition))) if __name__ == '__main__': main()
def main(): n, m = list(map(int, input().split())) query = [[int(x) for x in input().split()] for _ in range(m)] break_bridges = [-1] query.sort(key=lambda x: x[1]) for begin, end in query: if not (begin <= break_bridges[-1] < end): break_bridges.append(end - 1) print((len(break_bridges) - 1)) if __name__ == '__main__': main()
18
14
503
385
def main(): islands, request_num = list(map(int, input().split())) demolition = [] requests = [] for _ in range(request_num): requests.append(list(map(int, input().split()))) requests.sort(key=lambda x: x[1], reverse=False) for begin, end in requests: if 0 < len(demolition) and begin <= demolition[-1] < end: continue else: demolition.append(end - 1) print((len(demolition))) if __name__ == "__main__": main()
def main(): n, m = list(map(int, input().split())) query = [[int(x) for x in input().split()] for _ in range(m)] break_bridges = [-1] query.sort(key=lambda x: x[1]) for begin, end in query: if not (begin <= break_bridges[-1] < end): break_bridges.append(end - 1) print((len(break_bridges) - 1)) if __name__ == "__main__": main()
false
22.222222
[ "- islands, request_num = list(map(int, input().split()))", "- demolition = []", "- requests = []", "- for _ in range(request_num):", "- requests.append(list(map(int, input().split())))", "- requests.sort(key=lambda x: x[1], reverse=False)", "- for begin, end in requests:", "- if 0 < len(demolition) and begin <= demolition[-1] < end:", "- continue", "- else:", "- demolition.append(end - 1)", "- print((len(demolition)))", "+ n, m = list(map(int, input().split()))", "+ query = [[int(x) for x in input().split()] for _ in range(m)]", "+ break_bridges = [-1]", "+ query.sort(key=lambda x: x[1])", "+ for begin, end in query:", "+ if not (begin <= break_bridges[-1] < end):", "+ break_bridges.append(end - 1)", "+ print((len(break_bridges) - 1))" ]
false
0.037171
0.03696
1.005707
[ "s767956331", "s613752435" ]
u867826040
p02596
python
s149021198
s483366821
480
141
105,752
27,488
Accepted
Accepted
70.62
from numba import njit,prange @njit('i8(i8)',cache=True) def f(k): a = 7%k for i in prange(k): if a == 0: return i+1 a = (a*10+7)%k else: return -1 k = int(eval(input())) print((f(k)))
import sys if sys.argv[-1] == "ONLINE_JUDGE": from numba.pycc import CC cc = CC("solve") @cc.export('solve', 'i8(i8)') def f(k): a = 7 % k for i in range(k): if a == 0: return i + 1 a = (a * 10 + 7) % k else: return -1 cc.compile() exit(0) from solve import solve print((solve(int(eval(input())))))
12
20
235
412
from numba import njit, prange @njit("i8(i8)", cache=True) def f(k): a = 7 % k for i in prange(k): if a == 0: return i + 1 a = (a * 10 + 7) % k else: return -1 k = int(eval(input())) print((f(k)))
import sys if sys.argv[-1] == "ONLINE_JUDGE": from numba.pycc import CC cc = CC("solve") @cc.export("solve", "i8(i8)") def f(k): a = 7 % k for i in range(k): if a == 0: return i + 1 a = (a * 10 + 7) % k else: return -1 cc.compile() exit(0) from solve import solve print((solve(int(eval(input())))))
false
40
[ "-from numba import njit, prange", "+import sys", "+if sys.argv[-1] == \"ONLINE_JUDGE\":", "+ from numba.pycc import CC", "-@njit(\"i8(i8)\", cache=True)", "-def f(k):", "- a = 7 % k", "- for i in prange(k):", "- if a == 0:", "- return i + 1", "- a = (a * 10 + 7) % k", "- else:", "- return -1", "+ cc = CC(\"solve\")", "+ @cc.export(\"solve\", \"i8(i8)\")", "+ def f(k):", "+ a = 7 % k", "+ for i in range(k):", "+ if a == 0:", "+ return i + 1", "+ a = (a * 10 + 7) % k", "+ else:", "+ return -1", "-k = int(eval(input()))", "-print((f(k)))", "+ cc.compile()", "+ exit(0)", "+from solve import solve", "+", "+print((solve(int(eval(input())))))" ]
false
0.045887
0.04644
0.988087
[ "s149021198", "s483366821" ]
u426534722
p02234
python
s688093923
s053998859
230
170
5,672
5,720
Accepted
Accepted
26.09
INF = float("inf") n = int(eval(input())) z = [] m = [[0] * (n + 1) for _ in range(n + 1)] for i in range(1, n + 1): a, b = list(map(int, input().split())) z.append(a) z.append(b) for l in range(1, n): for i in range(1, n - l + 1): j = i + l m[i][j] = INF for k in range(i, j): m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + z[i - 1] * z[k] * z[j]) print((m[1][n]))
import sys INF = float("inf") n = int(eval(input())) m = [[0] * (n + 1) for _ in range(n + 1)] li = [list(map(int, a.split())) for a in sys.stdin] z = (li[0][0], ) + list(zip(*li))[1] for l in range(1, n): for i in range(1, n - l + 1): j = i + l m[i][j] = INF for k in range(i, j): m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + z[i - 1] * z[k] * z[j]) print((m[1][n]))
16
14
416
416
INF = float("inf") n = int(eval(input())) z = [] m = [[0] * (n + 1) for _ in range(n + 1)] for i in range(1, n + 1): a, b = list(map(int, input().split())) z.append(a) z.append(b) for l in range(1, n): for i in range(1, n - l + 1): j = i + l m[i][j] = INF for k in range(i, j): m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + z[i - 1] * z[k] * z[j]) print((m[1][n]))
import sys INF = float("inf") n = int(eval(input())) m = [[0] * (n + 1) for _ in range(n + 1)] li = [list(map(int, a.split())) for a in sys.stdin] z = (li[0][0],) + list(zip(*li))[1] for l in range(1, n): for i in range(1, n - l + 1): j = i + l m[i][j] = INF for k in range(i, j): m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + z[i - 1] * z[k] * z[j]) print((m[1][n]))
false
12.5
[ "+import sys", "+", "-z = []", "-for i in range(1, n + 1):", "- a, b = list(map(int, input().split()))", "- z.append(a)", "-z.append(b)", "+li = [list(map(int, a.split())) for a in sys.stdin]", "+z = (li[0][0],) + list(zip(*li))[1]" ]
false
0.076913
0.064415
1.194022
[ "s688093923", "s053998859" ]
u827241372
p03338
python
s693858698
s203414283
22
19
3,060
2,940
Accepted
Accepted
13.64
def main() -> None: N = int(eval(input())) S = eval(input()) m = 0 for i in range(N): l1 = S[0:i] l2 = S[i:] if m < len(set(sorted(l1)) & set(sorted(l2))): m = len(set(sorted(l1)) & set(sorted(l2))) print(m) if __name__ == '__main__': main()
def main() -> None: N = int(eval(input())) S = eval(input()) m = 0 for i in range(N): same_num = len(set(sorted(S[0:i])) & set(sorted(S[i:]))) m = same_num if m < same_num else m print(m) if __name__ == '__main__': main()
15
13
311
269
def main() -> None: N = int(eval(input())) S = eval(input()) m = 0 for i in range(N): l1 = S[0:i] l2 = S[i:] if m < len(set(sorted(l1)) & set(sorted(l2))): m = len(set(sorted(l1)) & set(sorted(l2))) print(m) if __name__ == "__main__": main()
def main() -> None: N = int(eval(input())) S = eval(input()) m = 0 for i in range(N): same_num = len(set(sorted(S[0:i])) & set(sorted(S[i:]))) m = same_num if m < same_num else m print(m) if __name__ == "__main__": main()
false
13.333333
[ "- l1 = S[0:i]", "- l2 = S[i:]", "- if m < len(set(sorted(l1)) & set(sorted(l2))):", "- m = len(set(sorted(l1)) & set(sorted(l2)))", "+ same_num = len(set(sorted(S[0:i])) & set(sorted(S[i:])))", "+ m = same_num if m < same_num else m" ]
false
0.039288
0.038905
1.009828
[ "s693858698", "s203414283" ]
u334712262
p02550
python
s590275309
s447384823
864
567
88,824
94,052
Accepted
Accepted
34.38
# -*- coding: utf-8 -*- import bisect import heapq import math import random from collections import Counter, defaultdict, deque from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal from fractions import Fraction from functools import lru_cache, reduce from itertools import combinations, combinations_with_replacement, product, permutations, accumulate from operator import add, mul, sub, itemgetter, attrgetter import sys # sys.setrecursionlimit(10**6) # readline = sys.stdin.buffer.readline readline = sys.stdin.readline INF = 1 << 60 def read_int(): return int(readline()) def read_int_n(): return list(map(int, readline().split())) def read_float(): return float(readline()) def read_float_n(): return list(map(float, readline().split())) def read_str(): return readline().strip() def read_str_n(): return readline().strip().split() def ep(*args): print(*args, file=sys.stderr) def mt(f): import time def wrap(*args, **kwargs): s = time.perf_counter() ret = f(*args, **kwargs) e = time.perf_counter() ep(e - s, 'sec') return ret return wrap @mt def slv(N, X, M): ans = 0 x = X x %= M # if math.gcd(X, M) != 1: if False: for _ in range(N): ans += x x *= x x %= M if x == 0: break return ans else: x = X s = [X] u = set() while True: x *= x x %= M s.append(x) if x in u: break u.add(x) i = s.index(s[-1]) if i + 1 >= N: return sum(s[:N]) % M N -= i ans += sum(s[:i]) s = s[i:] s.pop() ss = sum(s) ans += (N // len(s)) * ss ans += sum(s[:N%len(s)]) return ans def main(): N, X, M = read_int_n() print(slv(N, X, M)) # N = 10**10 # X = random.randint(1, 10**5) # M = random.randint(1, 10**5) # N, X, M = 10000000000, 82162, 79872 # print(N, X, M) # print(slv(N, X, M)) if __name__ == '__main__': main()
# -*- coding: utf-8 -*- import bisect import heapq import math import random from collections import Counter, defaultdict, deque from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal from fractions import Fraction from functools import lru_cache, reduce from itertools import combinations, combinations_with_replacement, product, permutations, accumulate from operator import add, mul, sub, itemgetter, attrgetter import sys # sys.setrecursionlimit(10**6) # readline = sys.stdin.buffer.readline readline = sys.stdin.readline INF = 1 << 60 def read_int(): return int(readline()) def read_int_n(): return list(map(int, readline().split())) def read_float(): return float(readline()) def read_float_n(): return list(map(float, readline().split())) def read_str(): return readline().strip() def read_str_n(): return readline().strip().split() def ep(*args): print(*args, file=sys.stderr) def mt(f): import time def wrap(*args, **kwargs): s = time.perf_counter() ret = f(*args, **kwargs) e = time.perf_counter() ep(e - s, 'sec') return ret return wrap @mt def slv(N, X, M): ans = 0 x = X x %= M x = X s = [X] u = set() while True: x *= x x %= M s.append(x) if x in u: break u.add(x) i = s.index(s[-1]) if i + 1 >= N: return sum(s[:N]) % M N -= i ans += sum(s[:i]) s = s[i:] s.pop() ss = sum(s) ans += (N // len(s)) * ss ans += sum(s[:N%len(s)]) return ans def main(): N, X, M = read_int_n() print(slv(N, X, M)) if __name__ == '__main__': main()
117
101
2,275
1,795
# -*- coding: utf-8 -*- import bisect import heapq import math import random from collections import Counter, defaultdict, deque from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal from fractions import Fraction from functools import lru_cache, reduce from itertools import ( combinations, combinations_with_replacement, product, permutations, accumulate, ) from operator import add, mul, sub, itemgetter, attrgetter import sys # sys.setrecursionlimit(10**6) # readline = sys.stdin.buffer.readline readline = sys.stdin.readline INF = 1 << 60 def read_int(): return int(readline()) def read_int_n(): return list(map(int, readline().split())) def read_float(): return float(readline()) def read_float_n(): return list(map(float, readline().split())) def read_str(): return readline().strip() def read_str_n(): return readline().strip().split() def ep(*args): print(*args, file=sys.stderr) def mt(f): import time def wrap(*args, **kwargs): s = time.perf_counter() ret = f(*args, **kwargs) e = time.perf_counter() ep(e - s, "sec") return ret return wrap @mt def slv(N, X, M): ans = 0 x = X x %= M # if math.gcd(X, M) != 1: if False: for _ in range(N): ans += x x *= x x %= M if x == 0: break return ans else: x = X s = [X] u = set() while True: x *= x x %= M s.append(x) if x in u: break u.add(x) i = s.index(s[-1]) if i + 1 >= N: return sum(s[:N]) % M N -= i ans += sum(s[:i]) s = s[i:] s.pop() ss = sum(s) ans += (N // len(s)) * ss ans += sum(s[: N % len(s)]) return ans def main(): N, X, M = read_int_n() print(slv(N, X, M)) # N = 10**10 # X = random.randint(1, 10**5) # M = random.randint(1, 10**5) # N, X, M = 10000000000, 82162, 79872 # print(N, X, M) # print(slv(N, X, M)) if __name__ == "__main__": main()
# -*- coding: utf-8 -*- import bisect import heapq import math import random from collections import Counter, defaultdict, deque from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal from fractions import Fraction from functools import lru_cache, reduce from itertools import ( combinations, combinations_with_replacement, product, permutations, accumulate, ) from operator import add, mul, sub, itemgetter, attrgetter import sys # sys.setrecursionlimit(10**6) # readline = sys.stdin.buffer.readline readline = sys.stdin.readline INF = 1 << 60 def read_int(): return int(readline()) def read_int_n(): return list(map(int, readline().split())) def read_float(): return float(readline()) def read_float_n(): return list(map(float, readline().split())) def read_str(): return readline().strip() def read_str_n(): return readline().strip().split() def ep(*args): print(*args, file=sys.stderr) def mt(f): import time def wrap(*args, **kwargs): s = time.perf_counter() ret = f(*args, **kwargs) e = time.perf_counter() ep(e - s, "sec") return ret return wrap @mt def slv(N, X, M): ans = 0 x = X x %= M x = X s = [X] u = set() while True: x *= x x %= M s.append(x) if x in u: break u.add(x) i = s.index(s[-1]) if i + 1 >= N: return sum(s[:N]) % M N -= i ans += sum(s[:i]) s = s[i:] s.pop() ss = sum(s) ans += (N // len(s)) * ss ans += sum(s[: N % len(s)]) return ans def main(): N, X, M = read_int_n() print(slv(N, X, M)) if __name__ == "__main__": main()
false
13.675214
[ "- # if math.gcd(X, M) != 1:", "- if False:", "- for _ in range(N):", "- ans += x", "- x *= x", "- x %= M", "- if x == 0:", "- break", "- return ans", "- else:", "- x = X", "- s = [X]", "- u = set()", "- while True:", "- x *= x", "- x %= M", "- s.append(x)", "- if x in u:", "- break", "- u.add(x)", "- i = s.index(s[-1])", "- if i + 1 >= N:", "- return sum(s[:N]) % M", "- N -= i", "- ans += sum(s[:i])", "- s = s[i:]", "- s.pop()", "- ss = sum(s)", "- ans += (N // len(s)) * ss", "- ans += sum(s[: N % len(s)])", "- return ans", "+ x = X", "+ s = [X]", "+ u = set()", "+ while True:", "+ x *= x", "+ x %= M", "+ s.append(x)", "+ if x in u:", "+ break", "+ u.add(x)", "+ i = s.index(s[-1])", "+ if i + 1 >= N:", "+ return sum(s[:N]) % M", "+ N -= i", "+ ans += sum(s[:i])", "+ s = s[i:]", "+ s.pop()", "+ ss = sum(s)", "+ ans += (N // len(s)) * ss", "+ ans += sum(s[: N % len(s)])", "+ return ans", "- # N = 10**10", "- # X = random.randint(1, 10**5)", "- # M = random.randint(1, 10**5)", "- # N, X, M = 10000000000, 82162, 79872", "- # print(N, X, M)", "- # print(slv(N, X, M))" ]
false
0.082385
0.036536
2.254916
[ "s590275309", "s447384823" ]
u941645670
p02726
python
s812585194
s701401892
1,995
1,562
3,444
3,444
Accepted
Accepted
21.7
n,x,y=list(map(int,input().split())) ans=[0]*n #個数を数えるのにバケットを用意する for i in range(1,n+1): #i<jなるすべての頂点の組について最短距離を求める for j in range(i+1,n+1): dist1=j-i dist2=abs(x-i)+abs(y-j)+1 dist3=abs(y-i)+abs(x-j)+1 d=min(dist1,dist2,dist3) #最短距離は上式により求められる ans[d]+=1 #最短距離がdとなる組の個数を1増やす for i in range(1,n): print((ans[i]))
n,x,y=list(map(int,input().split())) ans=[0]*n #個数を数えるのにバケットを用意する for i in range(1,n+1): #i<jなるすべての頂点の組について最短距離を求める for j in range(i+1,n+1): dist1=j-i dist2=abs(x-i)+abs(y-j)+1 d=min(dist1,dist2) #最短距離は上式により求められる ans[d]+=1 #最短距離がdとなる組の個数を1増やす for i in range(1,n): print((ans[i]))
11
10
361
320
n, x, y = list(map(int, input().split())) ans = [0] * n # 個数を数えるのにバケットを用意する for i in range(1, n + 1): # i<jなるすべての頂点の組について最短距離を求める for j in range(i + 1, n + 1): dist1 = j - i dist2 = abs(x - i) + abs(y - j) + 1 dist3 = abs(y - i) + abs(x - j) + 1 d = min(dist1, dist2, dist3) # 最短距離は上式により求められる ans[d] += 1 # 最短距離がdとなる組の個数を1増やす for i in range(1, n): print((ans[i]))
n, x, y = list(map(int, input().split())) ans = [0] * n # 個数を数えるのにバケットを用意する for i in range(1, n + 1): # i<jなるすべての頂点の組について最短距離を求める for j in range(i + 1, n + 1): dist1 = j - i dist2 = abs(x - i) + abs(y - j) + 1 d = min(dist1, dist2) # 最短距離は上式により求められる ans[d] += 1 # 最短距離がdとなる組の個数を1増やす for i in range(1, n): print((ans[i]))
false
9.090909
[ "- dist3 = abs(y - i) + abs(x - j) + 1", "- d = min(dist1, dist2, dist3) # 最短距離は上式により求められる", "+ d = min(dist1, dist2) # 最短距離は上式により求められる" ]
false
0.047407
0.04734
1.001406
[ "s812585194", "s701401892" ]
u303059352
p03109
python
s865838356
s835167525
20
17
2,940
2,940
Accepted
Accepted
15
print(("Heisei" if eval(input())<="2019/04/30" else "TBD"))
print(("Heisei" if eval(input()) < "2019/05/01" else "TBD"))
1
1
52
52
print(("Heisei" if eval(input()) <= "2019/04/30" else "TBD"))
print(("Heisei" if eval(input()) < "2019/05/01" else "TBD"))
false
0
[ "-print((\"Heisei\" if eval(input()) <= \"2019/04/30\" else \"TBD\"))", "+print((\"Heisei\" if eval(input()) < \"2019/05/01\" else \"TBD\"))" ]
false
0.069685
0.069123
1.008129
[ "s865838356", "s835167525" ]
u725757838
p03478
python
s100574200
s903497837
56
31
5,108
2,940
Accepted
Accepted
44.64
n,a,b=list(map(int,input().split())) listint=[i for i in range(1,n+1)] liststr=[str(listint[i]) for i in range(n)] anssum=[[] for i in range(n)] def calculate_sum(listint,liststr,k): sumnumber=liststr[k-1] sumlist=list(sumnumber) sumlistint=[int(sumlist[i]) for i in range(len(sumlist))] sum=0 for i in range(len(sumlistint)): sum=sum+sumlistint[i] return(sum) for k in range(0,n): anssum[k]=[listint[k],calculate_sum(listint,liststr,k+1)] answer=0 for i in range(0,n): if a<=anssum[i][1]<=b: answer=answer+anssum[i][0] print(answer)
n,a,b=list(map(int,input().split())) answer=0 for i in range(1,n+1): if a<=sum(map(int,str(i)))<=b: answer=answer+i print(answer)
21
7
579
145
n, a, b = list(map(int, input().split())) listint = [i for i in range(1, n + 1)] liststr = [str(listint[i]) for i in range(n)] anssum = [[] for i in range(n)] def calculate_sum(listint, liststr, k): sumnumber = liststr[k - 1] sumlist = list(sumnumber) sumlistint = [int(sumlist[i]) for i in range(len(sumlist))] sum = 0 for i in range(len(sumlistint)): sum = sum + sumlistint[i] return sum for k in range(0, n): anssum[k] = [listint[k], calculate_sum(listint, liststr, k + 1)] answer = 0 for i in range(0, n): if a <= anssum[i][1] <= b: answer = answer + anssum[i][0] print(answer)
n, a, b = list(map(int, input().split())) answer = 0 for i in range(1, n + 1): if a <= sum(map(int, str(i))) <= b: answer = answer + i print(answer)
false
66.666667
[ "-listint = [i for i in range(1, n + 1)]", "-liststr = [str(listint[i]) for i in range(n)]", "-anssum = [[] for i in range(n)]", "-", "-", "-def calculate_sum(listint, liststr, k):", "- sumnumber = liststr[k - 1]", "- sumlist = list(sumnumber)", "- sumlistint = [int(sumlist[i]) for i in range(len(sumlist))]", "- sum = 0", "- for i in range(len(sumlistint)):", "- sum = sum + sumlistint[i]", "- return sum", "-", "-", "-for k in range(0, n):", "- anssum[k] = [listint[k], calculate_sum(listint, liststr, k + 1)]", "-for i in range(0, n):", "- if a <= anssum[i][1] <= b:", "- answer = answer + anssum[i][0]", "+for i in range(1, n + 1):", "+ if a <= sum(map(int, str(i))) <= b:", "+ answer = answer + i" ]
false
0.042841
0.039082
1.096181
[ "s100574200", "s903497837" ]
u910632349
p02594
python
s964080467
s144248212
31
28
9,136
8,924
Accepted
Accepted
9.68
a=int(eval(input())) if a>=30: print("Yes") else: print("No")
x=int(eval(input())) print(("Yes" if x>=30 else "No"))
5
2
67
47
a = int(eval(input())) if a >= 30: print("Yes") else: print("No")
x = int(eval(input())) print(("Yes" if x >= 30 else "No"))
false
60
[ "-a = int(eval(input()))", "-if a >= 30:", "- print(\"Yes\")", "-else:", "- print(\"No\")", "+x = int(eval(input()))", "+print((\"Yes\" if x >= 30 else \"No\"))" ]
false
0.091617
0.111832
0.819239
[ "s964080467", "s144248212" ]
u177388368
p03031
python
s084129491
s369935998
56
45
3,064
9,136
Accepted
Accepted
19.64
n,m=list(map(int,input().split())) s=[] k=[] for i in range(m): ss=list(map(int,input().split())) k.append(ss[0]) s.append(ss[1:]) p=list(map(int,input().split())) def cntbin(num): bin_num = bin(num)[2:] count = 0 for i in bin_num: count += int(i) return count ans=0 for bit in range(2**n): ok=True for mm in range(m): on=0 for i in s[mm]: if bit & 2**(i-1)!=0: on+=1 if on%2==p[mm]: pass else: ok=False if ok:ans+=1 print(ans)
n,m=list(map(int,input().split())) k=[] s=[] def cntbin(num): bin_num = bin(num)[2:] count = 0 for i in bin_num: count += int(i) return count for i in range(m): kk,*ss=list(map(int,input().split())) k.append(kk) s.append(ss) p=list(map(int,input().split())) ans=0 for i in range(2**n): ok=True for mm in range(m): if not ok:break mask=0 for ss in s[mm]: mask+=1 << ss-1 on=cntbin(i&mask) if p[mm]!=on%2: ok=False if ok:ans+=1 print(ans)
33
33
600
590
n, m = list(map(int, input().split())) s = [] k = [] for i in range(m): ss = list(map(int, input().split())) k.append(ss[0]) s.append(ss[1:]) p = list(map(int, input().split())) def cntbin(num): bin_num = bin(num)[2:] count = 0 for i in bin_num: count += int(i) return count ans = 0 for bit in range(2**n): ok = True for mm in range(m): on = 0 for i in s[mm]: if bit & 2 ** (i - 1) != 0: on += 1 if on % 2 == p[mm]: pass else: ok = False if ok: ans += 1 print(ans)
n, m = list(map(int, input().split())) k = [] s = [] def cntbin(num): bin_num = bin(num)[2:] count = 0 for i in bin_num: count += int(i) return count for i in range(m): kk, *ss = list(map(int, input().split())) k.append(kk) s.append(ss) p = list(map(int, input().split())) ans = 0 for i in range(2**n): ok = True for mm in range(m): if not ok: break mask = 0 for ss in s[mm]: mask += 1 << ss - 1 on = cntbin(i & mask) if p[mm] != on % 2: ok = False if ok: ans += 1 print(ans)
false
0
[ "+k = []", "-k = []", "-for i in range(m):", "- ss = list(map(int, input().split()))", "- k.append(ss[0])", "- s.append(ss[1:])", "-p = list(map(int, input().split()))", "+for i in range(m):", "+ kk, *ss = list(map(int, input().split()))", "+ k.append(kk)", "+ s.append(ss)", "+p = list(map(int, input().split()))", "-for bit in range(2**n):", "+for i in range(2**n):", "- on = 0", "- for i in s[mm]:", "- if bit & 2 ** (i - 1) != 0:", "- on += 1", "- if on % 2 == p[mm]:", "- pass", "- else:", "+ if not ok:", "+ break", "+ mask = 0", "+ for ss in s[mm]:", "+ mask += 1 << ss - 1", "+ on = cntbin(i & mask)", "+ if p[mm] != on % 2:" ]
false
0.045742
0.038347
1.19283
[ "s084129491", "s369935998" ]
u604839890
p03162
python
s128871599
s112883971
438
332
41,884
42,240
Accepted
Accepted
24.2
n = int(eval(input())) abc = [list(map(int, input().split())) for _ in range(n)] aabbcc = [[0], [0], [0]] tmp = [0]*3 for i in abc: for j in range(3): tmp[j] = i[j] + max(aabbcc[(j+1)%3][-1], aabbcc[(j+2)%3][-1]) for j in range(3): aabbcc[j].append(tmp[j]) print((max([i[-1] for i in aabbcc])))
n = int(eval(input())) abc = [list(map(int, input().split())) for _ in range(n)] a, b, c = [0], [0], [0] for i in abc: aa = i[0] + max(b[-1], c[-1]) bb = i[1] + max(c[-1], a[-1]) cc = i[2] + max(a[-1], b[-1]) a.append(aa) b.append(bb) c.append(cc) print((max(a[-1], b[-1], c[-1])))
11
12
309
297
n = int(eval(input())) abc = [list(map(int, input().split())) for _ in range(n)] aabbcc = [[0], [0], [0]] tmp = [0] * 3 for i in abc: for j in range(3): tmp[j] = i[j] + max(aabbcc[(j + 1) % 3][-1], aabbcc[(j + 2) % 3][-1]) for j in range(3): aabbcc[j].append(tmp[j]) print((max([i[-1] for i in aabbcc])))
n = int(eval(input())) abc = [list(map(int, input().split())) for _ in range(n)] a, b, c = [0], [0], [0] for i in abc: aa = i[0] + max(b[-1], c[-1]) bb = i[1] + max(c[-1], a[-1]) cc = i[2] + max(a[-1], b[-1]) a.append(aa) b.append(bb) c.append(cc) print((max(a[-1], b[-1], c[-1])))
false
8.333333
[ "-aabbcc = [[0], [0], [0]]", "-tmp = [0] * 3", "+a, b, c = [0], [0], [0]", "- for j in range(3):", "- tmp[j] = i[j] + max(aabbcc[(j + 1) % 3][-1], aabbcc[(j + 2) % 3][-1])", "- for j in range(3):", "- aabbcc[j].append(tmp[j])", "-print((max([i[-1] for i in aabbcc])))", "+ aa = i[0] + max(b[-1], c[-1])", "+ bb = i[1] + max(c[-1], a[-1])", "+ cc = i[2] + max(a[-1], b[-1])", "+ a.append(aa)", "+ b.append(bb)", "+ c.append(cc)", "+print((max(a[-1], b[-1], c[-1])))" ]
false
0.007965
0.036596
0.217659
[ "s128871599", "s112883971" ]
u186838327
p03050
python
s110163365
s292217820
117
73
3,268
65,828
Accepted
Accepted
37.61
n = int(eval(input())) def make_divisors(n): divisors = [] for i in range(1, int(n**0.5)+1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n//i) #divisors.sort(reverse=True) return divisors d = make_divisors(n) ans = 0 for a in d: if a == 1: continue else: q = n//a m = a-1 if 0 <= q <= m-1: ans += m print(ans)
n = int(eval(input())) def make_divisors(n): divisors = [] for i in range(1, int(n**0.5)+1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n//i) #divisors.sort(reverse=True) return divisors D = make_divisors(n) ans = 0 for d in D: m = d-1 q = n//d if m > 0 and 0 <= q < m: ans += m print(ans)
24
20
468
412
n = int(eval(input())) def make_divisors(n): divisors = [] for i in range(1, int(n**0.5) + 1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n // i) # divisors.sort(reverse=True) return divisors d = make_divisors(n) ans = 0 for a in d: if a == 1: continue else: q = n // a m = a - 1 if 0 <= q <= m - 1: ans += m print(ans)
n = int(eval(input())) def make_divisors(n): divisors = [] for i in range(1, int(n**0.5) + 1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n // i) # divisors.sort(reverse=True) return divisors D = make_divisors(n) ans = 0 for d in D: m = d - 1 q = n // d if m > 0 and 0 <= q < m: ans += m print(ans)
false
16.666667
[ "-d = make_divisors(n)", "+D = make_divisors(n)", "-for a in d:", "- if a == 1:", "- continue", "- else:", "- q = n // a", "- m = a - 1", "- if 0 <= q <= m - 1:", "- ans += m", "+for d in D:", "+ m = d - 1", "+ q = n // d", "+ if m > 0 and 0 <= q < m:", "+ ans += m" ]
false
0.286893
0.19393
1.479365
[ "s110163365", "s292217820" ]
u307159845
p03854
python
s044780668
s357409248
184
88
3,188
3,956
Accepted
Accepted
52.17
S = eval(input()) S_r = S[::-1] dire = ['dream','dreamer','erase','eraser'] dire_r = [0]*4 for i in range(4): tmp = dire[i] dire_r[i] = tmp[::-1] ind = 0 excep = 0 while ind <len(S_r): if excep == 1: break flag2= 0 for j in range(4): if flag2 ==0: case = 0 for k in range(len(dire_r[j])): tmp = dire_r[j] if ind + k < len(S_r) and case == 0: # print(j) # print('S:'+S_r[ind+k]) # print('dire:'+tmp[k]) if S_r[ind+k] != tmp[k]: flag = 0 case = 1 if j == 3: excep = 1 elif k== len(dire_r[j]) -1: ind = ind + len(dire_r[j]) flag = 1 case = 1 flag2 = 1 if flag == 1: print('YES') else: print('NO')
S = eval(input()) dire = ['dream','dreamer','erase','eraser'] DP = [0] * 100000 DP[0] = 1 for s in range(len(S)): if DP[s] != 1: continue for i in range(4): tmp = S[s: s+len(dire[i])] if tmp == dire[i]: DP[s + len(dire[i])] = 1 if DP[len(S)] == 1: print('YES') else: print('NO')
42
21
1,030
351
S = eval(input()) S_r = S[::-1] dire = ["dream", "dreamer", "erase", "eraser"] dire_r = [0] * 4 for i in range(4): tmp = dire[i] dire_r[i] = tmp[::-1] ind = 0 excep = 0 while ind < len(S_r): if excep == 1: break flag2 = 0 for j in range(4): if flag2 == 0: case = 0 for k in range(len(dire_r[j])): tmp = dire_r[j] if ind + k < len(S_r) and case == 0: # print(j) # print('S:'+S_r[ind+k]) # print('dire:'+tmp[k]) if S_r[ind + k] != tmp[k]: flag = 0 case = 1 if j == 3: excep = 1 elif k == len(dire_r[j]) - 1: ind = ind + len(dire_r[j]) flag = 1 case = 1 flag2 = 1 if flag == 1: print("YES") else: print("NO")
S = eval(input()) dire = ["dream", "dreamer", "erase", "eraser"] DP = [0] * 100000 DP[0] = 1 for s in range(len(S)): if DP[s] != 1: continue for i in range(4): tmp = S[s : s + len(dire[i])] if tmp == dire[i]: DP[s + len(dire[i])] = 1 if DP[len(S)] == 1: print("YES") else: print("NO")
false
50
[ "-S_r = S[::-1]", "-dire_r = [0] * 4", "-for i in range(4):", "- tmp = dire[i]", "- dire_r[i] = tmp[::-1]", "-ind = 0", "-excep = 0", "-while ind < len(S_r):", "- if excep == 1:", "- break", "- flag2 = 0", "- for j in range(4):", "- if flag2 == 0:", "- case = 0", "- for k in range(len(dire_r[j])):", "- tmp = dire_r[j]", "- if ind + k < len(S_r) and case == 0:", "- # print(j)", "- # print('S:'+S_r[ind+k])", "- # print('dire:'+tmp[k])", "- if S_r[ind + k] != tmp[k]:", "- flag = 0", "- case = 1", "- if j == 3:", "- excep = 1", "- elif k == len(dire_r[j]) - 1:", "- ind = ind + len(dire_r[j])", "- flag = 1", "- case = 1", "- flag2 = 1", "-if flag == 1:", "+DP = [0] * 100000", "+DP[0] = 1", "+for s in range(len(S)):", "+ if DP[s] != 1:", "+ continue", "+ for i in range(4):", "+ tmp = S[s : s + len(dire[i])]", "+ if tmp == dire[i]:", "+ DP[s + len(dire[i])] = 1", "+if DP[len(S)] == 1:" ]
false
0.037568
0.037492
1.00203
[ "s044780668", "s357409248" ]
u075012704
p02708
python
s290686575
s531792427
130
112
9,192
9,176
Accepted
Accepted
13.85
N, K = list(map(int, input().split())) MOD = 10 ** 9 + 7 LOW, HIGH = 0, N ans = 0 if 1 >= K: ans += (HIGH - LOW + 1) for i in range(2, N + 2): LOW += i - 1 HIGH += N - i + 1 LOW %= MOD HIGH %= MOD if i >= K: ans += (HIGH - LOW + 1) ans %= MOD print(ans)
N, K = list(map(int, input().split())) MOD = 10 ** 9 + 7 low, high = 0, 0 ans = 0 for i in range(1, N + 2): low += i - 1 high += N - i + 1 if i >= K: ans += (high - low + 1) ans %= MOD print(ans)
19
14
310
234
N, K = list(map(int, input().split())) MOD = 10**9 + 7 LOW, HIGH = 0, N ans = 0 if 1 >= K: ans += HIGH - LOW + 1 for i in range(2, N + 2): LOW += i - 1 HIGH += N - i + 1 LOW %= MOD HIGH %= MOD if i >= K: ans += HIGH - LOW + 1 ans %= MOD print(ans)
N, K = list(map(int, input().split())) MOD = 10**9 + 7 low, high = 0, 0 ans = 0 for i in range(1, N + 2): low += i - 1 high += N - i + 1 if i >= K: ans += high - low + 1 ans %= MOD print(ans)
false
26.315789
[ "-LOW, HIGH = 0, N", "+low, high = 0, 0", "-if 1 >= K:", "- ans += HIGH - LOW + 1", "-for i in range(2, N + 2):", "- LOW += i - 1", "- HIGH += N - i + 1", "- LOW %= MOD", "- HIGH %= MOD", "+for i in range(1, N + 2):", "+ low += i - 1", "+ high += N - i + 1", "- ans += HIGH - LOW + 1", "+ ans += high - low + 1" ]
false
0.06708
0.061884
1.083958
[ "s290686575", "s531792427" ]
u654558363
p03846
python
s907202509
s140256936
153
141
14,436
14,308
Accepted
Accepted
7.84
from functools import reduce if __name__ == "__main__": n = int(eval(input())) a = [int(x) for x in input().split()] x = [0]*n if n % 2 == 0: for i in a: if i % 2 != 1: print((0)) exit() else: for i in a: if i % 2 != 0: print((0)) exit() for i in a: if i == 0 and x[i] == 1: print((0)) exit() elif x[i] == 2: print((0)) exit() else: x[i] += 1 print((reduce(lambda x, y: x * y if y != 0 else x, x, 1) % (10 ** 9 + 7)))
from functools import reduce if __name__ == "__main__": n = int(eval(input())) a = [int(x) for x in input().split()] x = [0]*n """if n % 2 == 0: for i in a: if i % 2 != 1: print(0) exit() else: for i in a: if i % 2 != 0: print(0) exit()""" for i in a: if i == 0 and x[i] == 1: print((0)) exit() elif x[i] == 2: print((0)) exit() else: x[i] += 1 print((reduce(lambda x, y: x * y if y != 0 else x, x, 1) % (10 ** 9 + 7)))
26
26
643
649
from functools import reduce if __name__ == "__main__": n = int(eval(input())) a = [int(x) for x in input().split()] x = [0] * n if n % 2 == 0: for i in a: if i % 2 != 1: print((0)) exit() else: for i in a: if i % 2 != 0: print((0)) exit() for i in a: if i == 0 and x[i] == 1: print((0)) exit() elif x[i] == 2: print((0)) exit() else: x[i] += 1 print((reduce(lambda x, y: x * y if y != 0 else x, x, 1) % (10**9 + 7)))
from functools import reduce if __name__ == "__main__": n = int(eval(input())) a = [int(x) for x in input().split()] x = [0] * n """if n % 2 == 0: for i in a: if i % 2 != 1: print(0) exit() else: for i in a: if i % 2 != 0: print(0) exit()""" for i in a: if i == 0 and x[i] == 1: print((0)) exit() elif x[i] == 2: print((0)) exit() else: x[i] += 1 print((reduce(lambda x, y: x * y if y != 0 else x, x, 1) % (10**9 + 7)))
false
0
[ "- if n % 2 == 0:", "+ \"\"\"if n % 2 == 0:", "- print((0))", "+ print(0)", "- print((0))", "- exit()", "+ print(0)", "+ exit()\"\"\"" ]
false
0.037078
0.036476
1.016478
[ "s907202509", "s140256936" ]
u610473220
p03107
python
s118176858
s287376590
29
18
3,188
3,188
Accepted
Accepted
37.93
S = eval(input()) c0 = 0 c1 = 0 for i in S: if i == "0": c0 += 1 else: c1 += 1 print((min(c0, c1) * 2))
S = eval(input()) c0 = S.count("0") c1 = S.count("1") print((min(c0, c1) * 2))
9
4
127
73
S = eval(input()) c0 = 0 c1 = 0 for i in S: if i == "0": c0 += 1 else: c1 += 1 print((min(c0, c1) * 2))
S = eval(input()) c0 = S.count("0") c1 = S.count("1") print((min(c0, c1) * 2))
false
55.555556
[ "-c0 = 0", "-c1 = 0", "-for i in S:", "- if i == \"0\":", "- c0 += 1", "- else:", "- c1 += 1", "+c0 = S.count(\"0\")", "+c1 = S.count(\"1\")" ]
false
0.062302
0.05024
1.240087
[ "s118176858", "s287376590" ]
u075012704
p02695
python
s197647265
s376317354
1,063
595
9,060
9,212
Accepted
Accepted
44.03
from itertools import combinations_with_replacement N, M, Q = list(map(int, input().split())) X = [list(map(int, input().split())) for _ in range(Q)] ans = 0 for pattern in combinations_with_replacement(list(range(1, M + 1)), N): tmp_ans = 0 pattern = list(pattern) for a, b, c, d in X: if pattern[b - 1] - pattern[a - 1] == c: tmp_ans += d ans = max(ans, tmp_ans) print(ans)
from itertools import combinations_with_replacement N, M, Q = list(map(int, input().split())) X = [list(map(int, input().split())) for _ in range(Q)] ans = 0 def calc(arr): score = 0 for a, b, c, d in X: if arr[b - 1] - arr[a - 1] == c: score += d return score def dfs(arr): global ans if len(arr) == N: ans = max(ans, calc(arr)) elif len(arr) == 0: for nx in range(1, M + 1): dfs(arr + [nx]) else: for nx in range(arr[-1], M + 1): dfs(arr + [nx]) dfs([]) print(ans)
14
29
415
592
from itertools import combinations_with_replacement N, M, Q = list(map(int, input().split())) X = [list(map(int, input().split())) for _ in range(Q)] ans = 0 for pattern in combinations_with_replacement(list(range(1, M + 1)), N): tmp_ans = 0 pattern = list(pattern) for a, b, c, d in X: if pattern[b - 1] - pattern[a - 1] == c: tmp_ans += d ans = max(ans, tmp_ans) print(ans)
from itertools import combinations_with_replacement N, M, Q = list(map(int, input().split())) X = [list(map(int, input().split())) for _ in range(Q)] ans = 0 def calc(arr): score = 0 for a, b, c, d in X: if arr[b - 1] - arr[a - 1] == c: score += d return score def dfs(arr): global ans if len(arr) == N: ans = max(ans, calc(arr)) elif len(arr) == 0: for nx in range(1, M + 1): dfs(arr + [nx]) else: for nx in range(arr[-1], M + 1): dfs(arr + [nx]) dfs([]) print(ans)
false
51.724138
[ "-for pattern in combinations_with_replacement(list(range(1, M + 1)), N):", "- tmp_ans = 0", "- pattern = list(pattern)", "+", "+", "+def calc(arr):", "+ score = 0", "- if pattern[b - 1] - pattern[a - 1] == c:", "- tmp_ans += d", "- ans = max(ans, tmp_ans)", "+ if arr[b - 1] - arr[a - 1] == c:", "+ score += d", "+ return score", "+", "+", "+def dfs(arr):", "+ global ans", "+ if len(arr) == N:", "+ ans = max(ans, calc(arr))", "+ elif len(arr) == 0:", "+ for nx in range(1, M + 1):", "+ dfs(arr + [nx])", "+ else:", "+ for nx in range(arr[-1], M + 1):", "+ dfs(arr + [nx])", "+", "+", "+dfs([])" ]
false
0.130506
0.066038
1.976213
[ "s197647265", "s376317354" ]
u504836877
p03112
python
s810819952
s890625579
2,000
1,512
78,312
12,128
Accepted
Accepted
24.4
import bisect A, B, Q = list(map(int, input().split())) INF = 10 ** 18 s = [-INF] + [int(eval(input())) for i in range(A)] + [INF] t = [-INF] + [int(eval(input())) for i in range(B)] + [INF] for q in range(Q): x = int(eval(input())) b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x) res = INF for S in [s[b - 1], s[b]]: for T in [t[d - 1], t[d]]: d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T) res = min(res, d1, d2) print(res)
A,B,Q = list(map(int, input().split())) S = [int(eval(input())) for _ in range(A)] T = [int(eval(input())) for _ in range(B)] import bisect for _ in range(Q): x = int(eval(input())) s_idx = bisect.bisect_left(S, x) t_idx = bisect.bisect_left(T, x) if s_idx == A and t_idx == B: ans = x-min(S[-1], T[-1]) elif s_idx == A and t_idx == 0: ans = min(x-S[-1]*2+T[0], T[0]*2-x-S[-1]) elif t_idx == B and s_idx == 0: ans = min(x-T[-1]*2+S[0], S[0]*2-x-T[-1]) elif s_idx == A: ans = min(x-min(S[-1], T[t_idx-1]), x-S[-1]*2+T[t_idx], T[t_idx]*2-x-S[-1]) elif t_idx == B: ans = min(x-min(T[-1], S[s_idx-1]), x-T[-1]*2+S[s_idx], S[s_idx]*2-x-T[-1]) elif s_idx == 0 and t_idx == 0: ans = max(S[0], T[0])-x elif s_idx == 0: ans = min(max(S[0], T[t_idx])-x, S[0]*2-x-T[t_idx-1], x-T[t_idx-1]*2+S[0]) elif t_idx == 0: ans = min(max(T[0], S[s_idx])-x, T[0]*2-x-S[s_idx-1], x-S[s_idx-1]*2+T[0]) else: ans = min(max(S[s_idx], T[t_idx])-x, x-min(S[s_idx-1], T[t_idx-1]), S[s_idx]*2-x-T[t_idx-1], T[t_idx]*2-x-S[s_idx-1]) ans = min(ans, x-T[t_idx-1]*2+S[s_idx], x-S[s_idx-1]*2+T[t_idx]) print(ans)
15
28
491
1,212
import bisect A, B, Q = list(map(int, input().split())) INF = 10**18 s = [-INF] + [int(eval(input())) for i in range(A)] + [INF] t = [-INF] + [int(eval(input())) for i in range(B)] + [INF] for q in range(Q): x = int(eval(input())) b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x) res = INF for S in [s[b - 1], s[b]]: for T in [t[d - 1], t[d]]: d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T) res = min(res, d1, d2) print(res)
A, B, Q = list(map(int, input().split())) S = [int(eval(input())) for _ in range(A)] T = [int(eval(input())) for _ in range(B)] import bisect for _ in range(Q): x = int(eval(input())) s_idx = bisect.bisect_left(S, x) t_idx = bisect.bisect_left(T, x) if s_idx == A and t_idx == B: ans = x - min(S[-1], T[-1]) elif s_idx == A and t_idx == 0: ans = min(x - S[-1] * 2 + T[0], T[0] * 2 - x - S[-1]) elif t_idx == B and s_idx == 0: ans = min(x - T[-1] * 2 + S[0], S[0] * 2 - x - T[-1]) elif s_idx == A: ans = min( x - min(S[-1], T[t_idx - 1]), x - S[-1] * 2 + T[t_idx], T[t_idx] * 2 - x - S[-1], ) elif t_idx == B: ans = min( x - min(T[-1], S[s_idx - 1]), x - T[-1] * 2 + S[s_idx], S[s_idx] * 2 - x - T[-1], ) elif s_idx == 0 and t_idx == 0: ans = max(S[0], T[0]) - x elif s_idx == 0: ans = min( max(S[0], T[t_idx]) - x, S[0] * 2 - x - T[t_idx - 1], x - T[t_idx - 1] * 2 + S[0], ) elif t_idx == 0: ans = min( max(T[0], S[s_idx]) - x, T[0] * 2 - x - S[s_idx - 1], x - S[s_idx - 1] * 2 + T[0], ) else: ans = min( max(S[s_idx], T[t_idx]) - x, x - min(S[s_idx - 1], T[t_idx - 1]), S[s_idx] * 2 - x - T[t_idx - 1], T[t_idx] * 2 - x - S[s_idx - 1], ) ans = min(ans, x - T[t_idx - 1] * 2 + S[s_idx], x - S[s_idx - 1] * 2 + T[t_idx]) print(ans)
false
46.428571
[ "+A, B, Q = list(map(int, input().split()))", "+S = [int(eval(input())) for _ in range(A)]", "+T = [int(eval(input())) for _ in range(B)]", "-A, B, Q = list(map(int, input().split()))", "-INF = 10**18", "-s = [-INF] + [int(eval(input())) for i in range(A)] + [INF]", "-t = [-INF] + [int(eval(input())) for i in range(B)] + [INF]", "-for q in range(Q):", "+for _ in range(Q):", "- b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)", "- res = INF", "- for S in [s[b - 1], s[b]]:", "- for T in [t[d - 1], t[d]]:", "- d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)", "- res = min(res, d1, d2)", "- print(res)", "+ s_idx = bisect.bisect_left(S, x)", "+ t_idx = bisect.bisect_left(T, x)", "+ if s_idx == A and t_idx == B:", "+ ans = x - min(S[-1], T[-1])", "+ elif s_idx == A and t_idx == 0:", "+ ans = min(x - S[-1] * 2 + T[0], T[0] * 2 - x - S[-1])", "+ elif t_idx == B and s_idx == 0:", "+ ans = min(x - T[-1] * 2 + S[0], S[0] * 2 - x - T[-1])", "+ elif s_idx == A:", "+ ans = min(", "+ x - min(S[-1], T[t_idx - 1]),", "+ x - S[-1] * 2 + T[t_idx],", "+ T[t_idx] * 2 - x - S[-1],", "+ )", "+ elif t_idx == B:", "+ ans = min(", "+ x - min(T[-1], S[s_idx - 1]),", "+ x - T[-1] * 2 + S[s_idx],", "+ S[s_idx] * 2 - x - T[-1],", "+ )", "+ elif s_idx == 0 and t_idx == 0:", "+ ans = max(S[0], T[0]) - x", "+ elif s_idx == 0:", "+ ans = min(", "+ max(S[0], T[t_idx]) - x,", "+ S[0] * 2 - x - T[t_idx - 1],", "+ x - T[t_idx - 1] * 2 + S[0],", "+ )", "+ elif t_idx == 0:", "+ ans = min(", "+ max(T[0], S[s_idx]) - x,", "+ T[0] * 2 - x - S[s_idx - 1],", "+ x - S[s_idx - 1] * 2 + T[0],", "+ )", "+ else:", "+ ans = min(", "+ max(S[s_idx], T[t_idx]) - x,", "+ x - min(S[s_idx - 1], T[t_idx - 1]),", "+ S[s_idx] * 2 - x - T[t_idx - 1],", "+ T[t_idx] * 2 - x - S[s_idx - 1],", "+ )", "+ ans = min(ans, x - T[t_idx - 1] * 2 + S[s_idx], x - S[s_idx - 1] * 2 + T[t_idx])", "+ print(ans)" ]
false
0.049102
0.04815
1.019767
[ "s810819952", "s890625579" ]