user_id
stringlengths 10
10
| problem_id
stringlengths 6
6
| language
stringclasses 1
value | submission_id_v0
stringlengths 10
10
| submission_id_v1
stringlengths 10
10
| cpu_time_v0
int64 10
38.3k
| cpu_time_v1
int64 0
24.7k
| memory_v0
int64 2.57k
1.02M
| memory_v1
int64 2.57k
869k
| status_v0
stringclasses 1
value | status_v1
stringclasses 1
value | improvement_frac
float64 7.51
100
| input
stringlengths 20
4.55k
| target
stringlengths 17
3.34k
| code_v0_loc
int64 1
148
| code_v1_loc
int64 1
184
| code_v0_num_chars
int64 13
4.55k
| code_v1_num_chars
int64 14
3.34k
| code_v0_no_empty_lines
stringlengths 21
6.88k
| code_v1_no_empty_lines
stringlengths 20
4.93k
| code_same
bool 1
class | relative_loc_diff_percent
float64 0
79.8
| diff
sequence | diff_only_import_comment
bool 1
class | measured_runtime_v0
float64 0.01
4.45
| measured_runtime_v1
float64 0.01
4.31
| runtime_lift
float64 0
359
| key
sequence |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
u925626880 | p03455 | python | s401206804 | s713493974 | 173 | 17 | 38,256 | 2,940 | Accepted | Accepted | 90.17 | a,b = [int(s) for s in input().split()]
print((('Even', 'Odd')[(a*b)%2]))
| a,b = list(map(int, input().split()))
if ((a*b) % 2):
print('Odd')
else:
print('Even')
| 2 | 6 | 73 | 95 | a, b = [int(s) for s in input().split()]
print((("Even", "Odd")[(a * b) % 2]))
| a, b = list(map(int, input().split()))
if (a * b) % 2:
print("Odd")
else:
print("Even")
| false | 66.666667 | [
"-a, b = [int(s) for s in input().split()]",
"-print(((\"Even\", \"Odd\")[(a * b) % 2]))",
"+a, b = list(map(int, input().split()))",
"+if (a * b) % 2:",
"+ print(\"Odd\")",
"+else:",
"+ print(\"Even\")"
] | false | 0.044956 | 0.037323 | 1.204505 | [
"s401206804",
"s713493974"
] |
u506705885 | p02408 | python | s810895964 | s554091811 | 30 | 20 | 7,748 | 5,612 | Accepted | Accepted | 33.33 | S_cards=[]
H_cards=[]
C_cards=[]
D_cards=[]
for i in range(1,14):
S_cards.append(i)
H_cards.append(i)
C_cards.append(i)
D_cards.append(i)
now_cards=int(eval(input()))
for i in range(0,now_cards):
kind_num=[]
kind_num=input().split()
if kind_num[0]=='S':
S_cards.remove(int(kind_num[1]))
elif kind_num[0]=='H':
H_cards.remove(int(kind_num[1]))
elif kind_num[0]=='C':
C_cards.remove(int(kind_num[1]))
elif kind_num[0]=='D':
D_cards.remove(int(kind_num[1]))
for i in range(0,len(S_cards)):
print(('S',S_cards[i]))
for i in range(0,len(H_cards)):
print(('H',H_cards[i]))
for i in range(0,len(C_cards)):
print(('C',C_cards[i]))
for i in range(0,len(D_cards)):
print(('D',D_cards[i])) | S=[i for i in range(1,14)]
H=[i for i in range(1,14)]
C=[i for i in range(1,14)]
D=[i for i in range(1,14)]
cards=int(eval(input()))
for i in range(0,cards):
mark,rank=input().split()
rank=int(rank)
if mark=="S":
S.remove(rank)
elif mark=="H":
H.remove(rank)
elif mark=="C":
C.remove(rank)
elif mark=="D":
D.remove(rank)
for i in S:
print(("S",i))
for i in H:
print(("H",i))
for i in C:
print(("C",i))
for i in D:
print(("D",i)) | 31 | 24 | 784 | 509 | S_cards = []
H_cards = []
C_cards = []
D_cards = []
for i in range(1, 14):
S_cards.append(i)
H_cards.append(i)
C_cards.append(i)
D_cards.append(i)
now_cards = int(eval(input()))
for i in range(0, now_cards):
kind_num = []
kind_num = input().split()
if kind_num[0] == "S":
S_cards.remove(int(kind_num[1]))
elif kind_num[0] == "H":
H_cards.remove(int(kind_num[1]))
elif kind_num[0] == "C":
C_cards.remove(int(kind_num[1]))
elif kind_num[0] == "D":
D_cards.remove(int(kind_num[1]))
for i in range(0, len(S_cards)):
print(("S", S_cards[i]))
for i in range(0, len(H_cards)):
print(("H", H_cards[i]))
for i in range(0, len(C_cards)):
print(("C", C_cards[i]))
for i in range(0, len(D_cards)):
print(("D", D_cards[i]))
| S = [i for i in range(1, 14)]
H = [i for i in range(1, 14)]
C = [i for i in range(1, 14)]
D = [i for i in range(1, 14)]
cards = int(eval(input()))
for i in range(0, cards):
mark, rank = input().split()
rank = int(rank)
if mark == "S":
S.remove(rank)
elif mark == "H":
H.remove(rank)
elif mark == "C":
C.remove(rank)
elif mark == "D":
D.remove(rank)
for i in S:
print(("S", i))
for i in H:
print(("H", i))
for i in C:
print(("C", i))
for i in D:
print(("D", i))
| false | 22.580645 | [
"-S_cards = []",
"-H_cards = []",
"-C_cards = []",
"-D_cards = []",
"-for i in range(1, 14):",
"- S_cards.append(i)",
"- H_cards.append(i)",
"- C_cards.append(i)",
"- D_cards.append(i)",
"-now_cards = int(eval(input()))",
"-for i in range(0, now_cards):",
"- kind_num = []",
"- kind_num = input().split()",
"- if kind_num[0] == \"S\":",
"- S_cards.remove(int(kind_num[1]))",
"- elif kind_num[0] == \"H\":",
"- H_cards.remove(int(kind_num[1]))",
"- elif kind_num[0] == \"C\":",
"- C_cards.remove(int(kind_num[1]))",
"- elif kind_num[0] == \"D\":",
"- D_cards.remove(int(kind_num[1]))",
"-for i in range(0, len(S_cards)):",
"- print((\"S\", S_cards[i]))",
"-for i in range(0, len(H_cards)):",
"- print((\"H\", H_cards[i]))",
"-for i in range(0, len(C_cards)):",
"- print((\"C\", C_cards[i]))",
"-for i in range(0, len(D_cards)):",
"- print((\"D\", D_cards[i]))",
"+S = [i for i in range(1, 14)]",
"+H = [i for i in range(1, 14)]",
"+C = [i for i in range(1, 14)]",
"+D = [i for i in range(1, 14)]",
"+cards = int(eval(input()))",
"+for i in range(0, cards):",
"+ mark, rank = input().split()",
"+ rank = int(rank)",
"+ if mark == \"S\":",
"+ S.remove(rank)",
"+ elif mark == \"H\":",
"+ H.remove(rank)",
"+ elif mark == \"C\":",
"+ C.remove(rank)",
"+ elif mark == \"D\":",
"+ D.remove(rank)",
"+for i in S:",
"+ print((\"S\", i))",
"+for i in H:",
"+ print((\"H\", i))",
"+for i in C:",
"+ print((\"C\", i))",
"+for i in D:",
"+ print((\"D\", i))"
] | false | 0.046981 | 0.045087 | 1.042012 | [
"s810895964",
"s554091811"
] |
u405660020 | p02912 | python | s077867498 | s593207885 | 184 | 163 | 14,168 | 14,180 | Accepted | Accepted | 11.41 | from heapq import heappop,heappush,heapify
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
n,m = list(map(int,input().split()))
a = [int(x) for x in input().split()]
a_minus = [-x for x in a]
heapify(a_minus)
pop = lambda: -heappop(a_minus)
push = lambda x: heappush(a_minus,-x)
for _ in range(m):
x = pop()
push(x//2)
print((-sum(a_minus))) | import heapq
n, m = list(map(int, input().split()))
a = list([int(x)*(-1) for x in input().split()])
heapq.heapify(a)
for i in range(m):
tmp_min=heapq.heappop(a)
heapq.heappush(a,(-1)*(-1*tmp_min//2)) # 計算誤差の関係で-1を2回かけてます
print((-sum(a)))
| 19 | 9 | 391 | 253 | from heapq import heappop, heappush, heapify
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
n, m = list(map(int, input().split()))
a = [int(x) for x in input().split()]
a_minus = [-x for x in a]
heapify(a_minus)
pop = lambda: -heappop(a_minus)
push = lambda x: heappush(a_minus, -x)
for _ in range(m):
x = pop()
push(x // 2)
print((-sum(a_minus)))
| import heapq
n, m = list(map(int, input().split()))
a = list([int(x) * (-1) for x in input().split()])
heapq.heapify(a)
for i in range(m):
tmp_min = heapq.heappop(a)
heapq.heappush(a, (-1) * (-1 * tmp_min // 2)) # 計算誤差の関係で-1を2回かけてます
print((-sum(a)))
| false | 52.631579 | [
"-from heapq import heappop, heappush, heapify",
"-import sys",
"+import heapq",
"-input = sys.stdin.readline",
"-sys.setrecursionlimit(10**7)",
"-a = [int(x) for x in input().split()]",
"-a_minus = [-x for x in a]",
"-heapify(a_minus)",
"-pop = lambda: -heappop(a_minus)",
"-push = lambda x: heappush(a_minus, -x)",
"-for _ in range(m):",
"- x = pop()",
"- push(x // 2)",
"-print((-sum(a_minus)))",
"+a = list([int(x) * (-1) for x in input().split()])",
"+heapq.heapify(a)",
"+for i in range(m):",
"+ tmp_min = heapq.heappop(a)",
"+ heapq.heappush(a, (-1) * (-1 * tmp_min // 2)) # 計算誤差の関係で-1を2回かけてます",
"+print((-sum(a)))"
] | false | 0.148584 | 0.054719 | 2.715391 | [
"s077867498",
"s593207885"
] |
u970197315 | p02631 | python | s625284846 | s254984085 | 169 | 155 | 31,648 | 31,604 | Accepted | Accepted | 8.28 | n=int(eval(input()))
a=list(map(int,input().split()))
s=0
for aa in a:
s^=aa
b=[]
for i in range(n):
b.append(s^a[i])
print((*b)) | n=int(eval(input()))
a=list(map(int,input().split()))
b=[]
s=0
for aa in a:
s^=aa
for aa in a:
b.append(s^aa)
print((*b)) | 9 | 9 | 133 | 125 | n = int(eval(input()))
a = list(map(int, input().split()))
s = 0
for aa in a:
s ^= aa
b = []
for i in range(n):
b.append(s ^ a[i])
print((*b))
| n = int(eval(input()))
a = list(map(int, input().split()))
b = []
s = 0
for aa in a:
s ^= aa
for aa in a:
b.append(s ^ aa)
print((*b))
| false | 0 | [
"+b = []",
"-b = []",
"-for i in range(n):",
"- b.append(s ^ a[i])",
"+for aa in a:",
"+ b.append(s ^ aa)"
] | false | 0.041646 | 0.041556 | 1.002164 | [
"s625284846",
"s254984085"
] |
u353919145 | p02836 | python | s948936298 | s855472548 | 183 | 17 | 38,384 | 3,060 | Accepted | Accepted | 90.71 | def main():
s = eval(input()); total = 0
for i in range(len(s) // 2):
if s[i] != s[-i - 1]:
total += 1
print(total)
main() | s = eval(input())
n = len(s)//2
count = 0
f = s[:n]
l = s[-n:]
l = l[::-1]
for i in range(n):
if f[i] != l[i]:
count+=1
print(count) | 7 | 10 | 154 | 150 | def main():
s = eval(input())
total = 0
for i in range(len(s) // 2):
if s[i] != s[-i - 1]:
total += 1
print(total)
main()
| s = eval(input())
n = len(s) // 2
count = 0
f = s[:n]
l = s[-n:]
l = l[::-1]
for i in range(n):
if f[i] != l[i]:
count += 1
print(count)
| false | 30 | [
"-def main():",
"- s = eval(input())",
"- total = 0",
"- for i in range(len(s) // 2):",
"- if s[i] != s[-i - 1]:",
"- total += 1",
"- print(total)",
"-",
"-",
"-main()",
"+s = eval(input())",
"+n = len(s) // 2",
"+count = 0",
"+f = s[:n]",
"+l = s[-n:]",
"+l = l[::-1]",
"+for i in range(n):",
"+ if f[i] != l[i]:",
"+ count += 1",
"+print(count)"
] | false | 0.036314 | 0.041486 | 0.87534 | [
"s948936298",
"s855472548"
] |
u279266699 | p02947 | python | s131146689 | s947659341 | 450 | 225 | 24,060 | 24,100 | Accepted | Accepted | 50 | from collections import Counter
from math import factorial
def combinations_count(n, r):
return factorial(n) // (factorial(n - r) * factorial(r))
n = int(eval(input()))
S = [''.join(sorted(eval(input()))) for _ in range(n)]
S_c = Counter(S)
ans = 0
for i in list(S_c.values()):
if i != 1:
ans += combinations_count(i, 2)
print(ans)
| from collections import Counter
n = int(eval(input()))
S = [''.join(sorted(eval(input()))) for _ in range(n)]
S_c = Counter(S)
ans = 0
for i in list(S_c.values()):
ans += i * (i - 1) // 2
print(ans) | 18 | 11 | 359 | 203 | from collections import Counter
from math import factorial
def combinations_count(n, r):
return factorial(n) // (factorial(n - r) * factorial(r))
n = int(eval(input()))
S = ["".join(sorted(eval(input()))) for _ in range(n)]
S_c = Counter(S)
ans = 0
for i in list(S_c.values()):
if i != 1:
ans += combinations_count(i, 2)
print(ans)
| from collections import Counter
n = int(eval(input()))
S = ["".join(sorted(eval(input()))) for _ in range(n)]
S_c = Counter(S)
ans = 0
for i in list(S_c.values()):
ans += i * (i - 1) // 2
print(ans)
| false | 38.888889 | [
"-from math import factorial",
"-",
"-",
"-def combinations_count(n, r):",
"- return factorial(n) // (factorial(n - r) * factorial(r))",
"-",
"- if i != 1:",
"- ans += combinations_count(i, 2)",
"+ ans += i * (i - 1) // 2"
] | false | 0.050401 | 0.04988 | 1.01045 | [
"s131146689",
"s947659341"
] |
u583507988 | p03162 | python | s915121148 | s840777150 | 667 | 250 | 50,216 | 106,196 | Accepted | Accepted | 62.52 | n = int(eval(input()))
a = [list(map(int, input().split())) for i in range(n)]
dp = [[0]*3 for i in range(n+1)]
for i in range(n):
for j in range(3):
for k in range(3):
if j==k:
continue
dp[i+1][k] = max(dp[i+1][k], dp[i][j]+a[i][k])
print((max(dp[-1]))) | n=int(eval(input()))
a=[list(map(int,input().split())) for i in range(n)]
dp=[[a[0][0],a[0][1],a[0][2]]]+[[0]*3 for i in range(n-1)]
for i in range(1,n):
for j in range(3):
if j==0:
dp[i][j]=max(dp[i-1][1],dp[i-1][2])+a[i][0]
elif j==1:
dp[i][j]=max(dp[i-1][0],dp[i-1][2])+a[i][1]
else:
dp[i][j]=max(dp[i-1][1],dp[i-1][0])+a[i][2]
print((max(dp[n-1]))) | 12 | 12 | 285 | 387 | n = int(eval(input()))
a = [list(map(int, input().split())) for i in range(n)]
dp = [[0] * 3 for i in range(n + 1)]
for i in range(n):
for j in range(3):
for k in range(3):
if j == k:
continue
dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + a[i][k])
print((max(dp[-1])))
| n = int(eval(input()))
a = [list(map(int, input().split())) for i in range(n)]
dp = [[a[0][0], a[0][1], a[0][2]]] + [[0] * 3 for i in range(n - 1)]
for i in range(1, n):
for j in range(3):
if j == 0:
dp[i][j] = max(dp[i - 1][1], dp[i - 1][2]) + a[i][0]
elif j == 1:
dp[i][j] = max(dp[i - 1][0], dp[i - 1][2]) + a[i][1]
else:
dp[i][j] = max(dp[i - 1][1], dp[i - 1][0]) + a[i][2]
print((max(dp[n - 1])))
| false | 0 | [
"-dp = [[0] * 3 for i in range(n + 1)]",
"-for i in range(n):",
"+dp = [[a[0][0], a[0][1], a[0][2]]] + [[0] * 3 for i in range(n - 1)]",
"+for i in range(1, n):",
"- for k in range(3):",
"- if j == k:",
"- continue",
"- dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + a[i][k])",
"-print((max(dp[-1])))",
"+ if j == 0:",
"+ dp[i][j] = max(dp[i - 1][1], dp[i - 1][2]) + a[i][0]",
"+ elif j == 1:",
"+ dp[i][j] = max(dp[i - 1][0], dp[i - 1][2]) + a[i][1]",
"+ else:",
"+ dp[i][j] = max(dp[i - 1][1], dp[i - 1][0]) + a[i][2]",
"+print((max(dp[n - 1])))"
] | false | 0.038275 | 0.037842 | 1.011435 | [
"s915121148",
"s840777150"
] |
u761529120 | p02742 | python | s018225025 | s709048421 | 189 | 166 | 38,484 | 38,384 | Accepted | Accepted | 12.17 | def main():
H, W = list(map(int, input().split()))
if H == 1 or W == 1:
print((1))
exit()
ans = 0
ans += (W - (W // 2)) * (H - (H // 2))
ans += (W // 2) * (H // 2)
print(ans)
if __name__ == "__main__":
main() | def main():
H, W = list(map(int, input().split()))
if H == 1 or W == 1:
print((1))
exit()
ans = (H // 2) * (W // 2)
yoko = W // 2 if W % 2 == 0 else W // 2 + 1
tate = H // 2 if H % 2 == 0 else H // 2 + 1
ans += tate * yoko
print(ans)
if __name__ == "__main__":
main() | 15 | 15 | 263 | 324 | def main():
H, W = list(map(int, input().split()))
if H == 1 or W == 1:
print((1))
exit()
ans = 0
ans += (W - (W // 2)) * (H - (H // 2))
ans += (W // 2) * (H // 2)
print(ans)
if __name__ == "__main__":
main()
| def main():
H, W = list(map(int, input().split()))
if H == 1 or W == 1:
print((1))
exit()
ans = (H // 2) * (W // 2)
yoko = W // 2 if W % 2 == 0 else W // 2 + 1
tate = H // 2 if H % 2 == 0 else H // 2 + 1
ans += tate * yoko
print(ans)
if __name__ == "__main__":
main()
| false | 0 | [
"- ans = 0",
"- ans += (W - (W // 2)) * (H - (H // 2))",
"- ans += (W // 2) * (H // 2)",
"+ ans = (H // 2) * (W // 2)",
"+ yoko = W // 2 if W % 2 == 0 else W // 2 + 1",
"+ tate = H // 2 if H % 2 == 0 else H // 2 + 1",
"+ ans += tate * yoko"
] | false | 0.041855 | 0.039976 | 1.046993 | [
"s018225025",
"s709048421"
] |
u644907318 | p02927 | python | s909353878 | s461674468 | 175 | 66 | 38,384 | 67,740 | Accepted | Accepted | 62.29 | M,D = list(map(int,input().split()))
cnt = 0
for i in range(22,D+1):
d = str(i)
if int(d[1])>=2 and int(d[1])*int(d[0])<=M:
cnt += 1
print(cnt) | M,D = list(map(int,input().split()))
cnt = 0
for m in range(4,M+1):
for d in range(1,D+1):
if d>=20:
d = str(d)
if int(d[1])>=2:
if m==int(d[0])*int(d[1]):
cnt += 1
print(cnt) | 7 | 10 | 159 | 250 | M, D = list(map(int, input().split()))
cnt = 0
for i in range(22, D + 1):
d = str(i)
if int(d[1]) >= 2 and int(d[1]) * int(d[0]) <= M:
cnt += 1
print(cnt)
| M, D = list(map(int, input().split()))
cnt = 0
for m in range(4, M + 1):
for d in range(1, D + 1):
if d >= 20:
d = str(d)
if int(d[1]) >= 2:
if m == int(d[0]) * int(d[1]):
cnt += 1
print(cnt)
| false | 30 | [
"-for i in range(22, D + 1):",
"- d = str(i)",
"- if int(d[1]) >= 2 and int(d[1]) * int(d[0]) <= M:",
"- cnt += 1",
"+for m in range(4, M + 1):",
"+ for d in range(1, D + 1):",
"+ if d >= 20:",
"+ d = str(d)",
"+ if int(d[1]) >= 2:",
"+ if m == int(d[0]) * int(d[1]):",
"+ cnt += 1"
] | false | 0.036118 | 0.035056 | 1.030275 | [
"s909353878",
"s461674468"
] |
u852210959 | p02708 | python | s235583618 | s924165603 | 113 | 93 | 19,640 | 19,580 | Accepted | Accepted | 17.7 | # -*- coding: utf-8 -*-
# 入力を整数に変換して受け取る
def input_int():
return int(eval(input()))
# マイナス1した値を返却
def int1(x):
return int(x) - 1
# 半角スペース区切り入力をIntに変換してMapで受け取る
def input_to_int_map():
return list(map(int, input().split()))
# 半角スペース区切り入力をIntに変換して受け取る
def input_to_int_tuple():
return tuple(map(int, input().split()))
# 半角スペース区切り入力をIntに変換してマイナス1した値を受け取る
def input_to_int_tuple_minus1():
return tuple(map(int1, input().split()))
MOD = 10 ** 9 + 7
from operator import mul
from functools import reduce
def cmb(n, r):
r = min(n-r,r)
if r == 0: return 1
over = reduce(mul, list(range(n, n - r, -1)))
under = reduce(mul, list(range(1, r + 1)))
return over // under
def main():
n, k = input_to_int_map()
all_n = n + 1
ret = 0
all_list_sum = [0]
pre = 0
for i in range(0, all_n):
all_list_sum.append(i + pre)
pre = i + pre
for choice_cnt in range(k, all_n + 1):
ret = (ret + (all_list_sum[n + 1] - all_list_sum[n + 1 - choice_cnt] - all_list_sum[choice_cnt] + 1)) % MOD
return ret
if __name__ == "__main__":
print((main()))
| # -*- coding: utf-8 -*-
# 入力を整数に変換して受け取る
def input_int():
return int(eval(input()))
# マイナス1した値を返却
def int1(x):
return int(x) - 1
# 半角スペース区切り入力をIntに変換してMapで受け取る
def input_to_int_map():
return list(map(int, input().split()))
# 半角スペース区切り入力をIntに変換して受け取る
def input_to_int_tuple():
return tuple(map(int, input().split()))
# 半角スペース区切り入力をIntに変換してマイナス1した値を受け取る
def input_to_int_tuple_minus1():
return tuple(map(int1, input().split()))
MOD = 10 ** 9 + 7
from operator import mul
from functools import reduce
def cmb(n, r):
r = min(n-r,r)
if r == 0: return 1
over = reduce(mul, list(range(n, n - r, -1)))
under = reduce(mul, list(range(1, r + 1)))
return over // under
def main():
n, k = input_to_int_map()
all_n = n + 1
ret = 0
all_list_sum = [0]
pre = 0
for i in range(0, all_n):
all_list_sum.append(i + pre)
pre = i + pre
for choice_cnt in range(k, all_n + 1):
ret = (ret + (all_list_sum[n + 1] - all_list_sum[n + 1 - choice_cnt] - all_list_sum[choice_cnt] + 1))
return ret % MOD
if __name__ == "__main__":
print((main()))
| 61 | 61 | 1,171 | 1,171 | # -*- coding: utf-8 -*-
# 入力を整数に変換して受け取る
def input_int():
return int(eval(input()))
# マイナス1した値を返却
def int1(x):
return int(x) - 1
# 半角スペース区切り入力をIntに変換してMapで受け取る
def input_to_int_map():
return list(map(int, input().split()))
# 半角スペース区切り入力をIntに変換して受け取る
def input_to_int_tuple():
return tuple(map(int, input().split()))
# 半角スペース区切り入力をIntに変換してマイナス1した値を受け取る
def input_to_int_tuple_minus1():
return tuple(map(int1, input().split()))
MOD = 10**9 + 7
from operator import mul
from functools import reduce
def cmb(n, r):
r = min(n - r, r)
if r == 0:
return 1
over = reduce(mul, list(range(n, n - r, -1)))
under = reduce(mul, list(range(1, r + 1)))
return over // under
def main():
n, k = input_to_int_map()
all_n = n + 1
ret = 0
all_list_sum = [0]
pre = 0
for i in range(0, all_n):
all_list_sum.append(i + pre)
pre = i + pre
for choice_cnt in range(k, all_n + 1):
ret = (
ret
+ (
all_list_sum[n + 1]
- all_list_sum[n + 1 - choice_cnt]
- all_list_sum[choice_cnt]
+ 1
)
) % MOD
return ret
if __name__ == "__main__":
print((main()))
| # -*- coding: utf-8 -*-
# 入力を整数に変換して受け取る
def input_int():
return int(eval(input()))
# マイナス1した値を返却
def int1(x):
return int(x) - 1
# 半角スペース区切り入力をIntに変換してMapで受け取る
def input_to_int_map():
return list(map(int, input().split()))
# 半角スペース区切り入力をIntに変換して受け取る
def input_to_int_tuple():
return tuple(map(int, input().split()))
# 半角スペース区切り入力をIntに変換してマイナス1した値を受け取る
def input_to_int_tuple_minus1():
return tuple(map(int1, input().split()))
MOD = 10**9 + 7
from operator import mul
from functools import reduce
def cmb(n, r):
r = min(n - r, r)
if r == 0:
return 1
over = reduce(mul, list(range(n, n - r, -1)))
under = reduce(mul, list(range(1, r + 1)))
return over // under
def main():
n, k = input_to_int_map()
all_n = n + 1
ret = 0
all_list_sum = [0]
pre = 0
for i in range(0, all_n):
all_list_sum.append(i + pre)
pre = i + pre
for choice_cnt in range(k, all_n + 1):
ret = ret + (
all_list_sum[n + 1]
- all_list_sum[n + 1 - choice_cnt]
- all_list_sum[choice_cnt]
+ 1
)
return ret % MOD
if __name__ == "__main__":
print((main()))
| false | 0 | [
"- ret = (",
"- ret",
"- + (",
"- all_list_sum[n + 1]",
"- - all_list_sum[n + 1 - choice_cnt]",
"- - all_list_sum[choice_cnt]",
"- + 1",
"- )",
"- ) % MOD",
"- return ret",
"+ ret = ret + (",
"+ all_list_sum[n + 1]",
"+ - all_list_sum[n + 1 - choice_cnt]",
"+ - all_list_sum[choice_cnt]",
"+ + 1",
"+ )",
"+ return ret % MOD"
] | false | 0.052534 | 0.051595 | 1.018199 | [
"s235583618",
"s924165603"
] |
u036104576 | p02714 | python | s455822249 | s395623171 | 1,770 | 165 | 360,132 | 68,704 | Accepted | Accepted | 90.68 | import sys
import itertools
# import numpy as np
import time
import math
sys.setrecursionlimit(10 ** 7)
from collections import defaultdict
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n = int(readline())
s = eval(input())
counter = [(0, 0, 0)]
for c in s:
rgb = counter[-1]
r, g, b = 0, 0, 0
if c == 'R':
r = 1
if c == 'G':
g = 1
if c == 'B':
b = 1
new_rgb = (rgb[0] + r, rgb[1] + g, rgb[2] + b)
counter.append(new_rgb)
ans = 0
MAX = 4002
x = []
for i in range(1, min(len(s) + 1, MAX)):
for j in range(i + 1, min(len(s) + 1, MAX)):
if s[i - 1] == s[j - 1]:
continue
x.append((i, j))
y = []
for p in x:
i = p[0]
j = p[1]
rgb = {'R', 'G', 'B'}
sub = {s[i - 1], s[j - 1]}
k_s = rgb.difference(sub).pop()
k_idx = 0
if k_s == 'R':
k_idx = 0
if k_s == 'G':
k_idx = 1
if k_s == 'B':
k_idx = 2
j_cnt = counter[j]
k_cnt = counter[len(s)]
omit = 0
if (2 * j - i) <= len(s):
omit = counter[2* j - i][k_idx] - counter[2 * j - i - 1][k_idx]
ans += (k_cnt[k_idx] - j_cnt[k_idx] - omit)
print(ans)
| import sys
import itertools
# import numpy as np
import time
import math
sys.setrecursionlimit(10 ** 7)
from collections import defaultdict
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n = int(readline())
s = eval(input())
r_c = 0
g_c = 0
b_c = 0
for c in s:
if c == 'R':
r_c += 1
if c == 'G':
g_c += 1
if c == 'B':
b_c += 1
rgb_count = r_c * g_c * b_c
MAX = min(len(s) + 1, 4005)
omit_count = 0
for i in range(1, len(s) + 1):
for j in range(i + 1, len(s) + 1):
k = 2 * j - i
if k >= len(s) + 1:
continue
if s[i - 1] != s[j - 1] and s[j - 1] != s[k - 1] and s[k - 1] != s[i - 1]:
omit_count += 1
print((rgb_count - omit_count)) | 63 | 39 | 1,282 | 811 | import sys
import itertools
# import numpy as np
import time
import math
sys.setrecursionlimit(10**7)
from collections import defaultdict
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n = int(readline())
s = eval(input())
counter = [(0, 0, 0)]
for c in s:
rgb = counter[-1]
r, g, b = 0, 0, 0
if c == "R":
r = 1
if c == "G":
g = 1
if c == "B":
b = 1
new_rgb = (rgb[0] + r, rgb[1] + g, rgb[2] + b)
counter.append(new_rgb)
ans = 0
MAX = 4002
x = []
for i in range(1, min(len(s) + 1, MAX)):
for j in range(i + 1, min(len(s) + 1, MAX)):
if s[i - 1] == s[j - 1]:
continue
x.append((i, j))
y = []
for p in x:
i = p[0]
j = p[1]
rgb = {"R", "G", "B"}
sub = {s[i - 1], s[j - 1]}
k_s = rgb.difference(sub).pop()
k_idx = 0
if k_s == "R":
k_idx = 0
if k_s == "G":
k_idx = 1
if k_s == "B":
k_idx = 2
j_cnt = counter[j]
k_cnt = counter[len(s)]
omit = 0
if (2 * j - i) <= len(s):
omit = counter[2 * j - i][k_idx] - counter[2 * j - i - 1][k_idx]
ans += k_cnt[k_idx] - j_cnt[k_idx] - omit
print(ans)
| import sys
import itertools
# import numpy as np
import time
import math
sys.setrecursionlimit(10**7)
from collections import defaultdict
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n = int(readline())
s = eval(input())
r_c = 0
g_c = 0
b_c = 0
for c in s:
if c == "R":
r_c += 1
if c == "G":
g_c += 1
if c == "B":
b_c += 1
rgb_count = r_c * g_c * b_c
MAX = min(len(s) + 1, 4005)
omit_count = 0
for i in range(1, len(s) + 1):
for j in range(i + 1, len(s) + 1):
k = 2 * j - i
if k >= len(s) + 1:
continue
if s[i - 1] != s[j - 1] and s[j - 1] != s[k - 1] and s[k - 1] != s[i - 1]:
omit_count += 1
print((rgb_count - omit_count))
| false | 38.095238 | [
"-counter = [(0, 0, 0)]",
"+r_c = 0",
"+g_c = 0",
"+b_c = 0",
"- rgb = counter[-1]",
"- r, g, b = 0, 0, 0",
"- r = 1",
"+ r_c += 1",
"- g = 1",
"+ g_c += 1",
"- b = 1",
"- new_rgb = (rgb[0] + r, rgb[1] + g, rgb[2] + b)",
"- counter.append(new_rgb)",
"-ans = 0",
"-MAX = 4002",
"-x = []",
"-for i in range(1, min(len(s) + 1, MAX)):",
"- for j in range(i + 1, min(len(s) + 1, MAX)):",
"- if s[i - 1] == s[j - 1]:",
"+ b_c += 1",
"+rgb_count = r_c * g_c * b_c",
"+MAX = min(len(s) + 1, 4005)",
"+omit_count = 0",
"+for i in range(1, len(s) + 1):",
"+ for j in range(i + 1, len(s) + 1):",
"+ k = 2 * j - i",
"+ if k >= len(s) + 1:",
"- x.append((i, j))",
"-y = []",
"-for p in x:",
"- i = p[0]",
"- j = p[1]",
"- rgb = {\"R\", \"G\", \"B\"}",
"- sub = {s[i - 1], s[j - 1]}",
"- k_s = rgb.difference(sub).pop()",
"- k_idx = 0",
"- if k_s == \"R\":",
"- k_idx = 0",
"- if k_s == \"G\":",
"- k_idx = 1",
"- if k_s == \"B\":",
"- k_idx = 2",
"- j_cnt = counter[j]",
"- k_cnt = counter[len(s)]",
"- omit = 0",
"- if (2 * j - i) <= len(s):",
"- omit = counter[2 * j - i][k_idx] - counter[2 * j - i - 1][k_idx]",
"- ans += k_cnt[k_idx] - j_cnt[k_idx] - omit",
"-print(ans)",
"+ if s[i - 1] != s[j - 1] and s[j - 1] != s[k - 1] and s[k - 1] != s[i - 1]:",
"+ omit_count += 1",
"+print((rgb_count - omit_count))"
] | false | 0.042829 | 0.048318 | 0.886411 | [
"s455822249",
"s395623171"
] |
u116233709 | p03127 | python | s107726156 | s482230197 | 1,665 | 84 | 14,252 | 14,224 | Accepted | Accepted | 94.95 | n=int(eval(input()))
a=list(map(int,input().split()))
a.sort()
while len(a)>=2:
for i in range(1,len(a)):
a[i]=a[i]%a[0]
if 0 in a:
for j in range(a.count(0)):
a.remove(0)
a.sort()
print((a[0]))
| n=int(eval(input()))
a=list(map(int,input().split()))
def gcd(x,y):
if x%y==0:
return y
else:
return gcd(y,x%y)
b=a[0]
for i in range(1,n):
b=gcd(b,a[i])
print(b)
| 15 | 15 | 229 | 198 | n = int(eval(input()))
a = list(map(int, input().split()))
a.sort()
while len(a) >= 2:
for i in range(1, len(a)):
a[i] = a[i] % a[0]
if 0 in a:
for j in range(a.count(0)):
a.remove(0)
a.sort()
print((a[0]))
| n = int(eval(input()))
a = list(map(int, input().split()))
def gcd(x, y):
if x % y == 0:
return y
else:
return gcd(y, x % y)
b = a[0]
for i in range(1, n):
b = gcd(b, a[i])
print(b)
| false | 0 | [
"-a.sort()",
"-while len(a) >= 2:",
"- for i in range(1, len(a)):",
"- a[i] = a[i] % a[0]",
"- if 0 in a:",
"- for j in range(a.count(0)):",
"- a.remove(0)",
"- a.sort()",
"-print((a[0]))",
"+",
"+",
"+def gcd(x, y):",
"+ if x % y == 0:",
"+ return y",
"+ else:",
"+ return gcd(y, x % y)",
"+",
"+",
"+b = a[0]",
"+for i in range(1, n):",
"+ b = gcd(b, a[i])",
"+print(b)"
] | false | 0.102922 | 0.036001 | 2.858864 | [
"s107726156",
"s482230197"
] |
u265213765 | p02659 | python | s938158634 | s889856974 | 28 | 25 | 10,016 | 10,048 | Accepted | Accepted | 10.71 | import math
from decimal import *
a,b = input().split()
a = Decimal(a)
b = Decimal(b)
b = b*100
print((math.floor(a*b//100))) | import math
from decimal import *
a,b = input().split()
a = Decimal(a)
b = Decimal(b)
# b = b*100
print((math.floor(a*b))) | 7 | 7 | 129 | 126 | import math
from decimal import *
a, b = input().split()
a = Decimal(a)
b = Decimal(b)
b = b * 100
print((math.floor(a * b // 100)))
| import math
from decimal import *
a, b = input().split()
a = Decimal(a)
b = Decimal(b)
# b = b*100
print((math.floor(a * b)))
| false | 0 | [
"-b = b * 100",
"-print((math.floor(a * b // 100)))",
"+# b = b*100",
"+print((math.floor(a * b)))"
] | false | 0.046932 | 0.04482 | 1.047115 | [
"s938158634",
"s889856974"
] |
u941047297 | p03796 | python | s191228806 | s487460740 | 183 | 39 | 38,512 | 2,940 | Accepted | Accepted | 78.69 | N = int(eval(input()))
p = 1
m = int(1e+9 + 7)
for i in range(1, N + 1):
p = p * i
if p > m:
p = p % m
print(p) | n = int(eval(input()))
p = 1
mod = 1000000007
for i in range(1, n + 1):
p *= i
p = p % mod
print(p) | 8 | 7 | 128 | 107 | N = int(eval(input()))
p = 1
m = int(1e9 + 7)
for i in range(1, N + 1):
p = p * i
if p > m:
p = p % m
print(p)
| n = int(eval(input()))
p = 1
mod = 1000000007
for i in range(1, n + 1):
p *= i
p = p % mod
print(p)
| false | 12.5 | [
"-N = int(eval(input()))",
"+n = int(eval(input()))",
"-m = int(1e9 + 7)",
"-for i in range(1, N + 1):",
"- p = p * i",
"- if p > m:",
"- p = p % m",
"+mod = 1000000007",
"+for i in range(1, n + 1):",
"+ p *= i",
"+ p = p % mod"
] | false | 0.044291 | 0.067472 | 0.65643 | [
"s191228806",
"s487460740"
] |
u306950978 | p02588 | python | s004840149 | s166375050 | 421 | 384 | 99,244 | 99,220 | Accepted | Accepted | 8.79 | from decimal import Decimal
n = int(eval(input()))
a = []
r = {}
for i in range(n):
d = int(float(eval(input()))*10**9 + 0.1)
d2 = 0
d5 = 0
while True:
if d % 2 != 0 and d % 5 != 0:
break
if d % 2 == 0:
d //= 2
d2 += 1
if d % 5 == 0:
d //= 5
d5 += 1
a.append((d2,d5))
r[(d2,d5)] = r.get((d2,d5),0) + 1
ans = 0
for x , y in list(r.keys()):
for i , j in list(r.keys()):
if min(x+i,y+j) >= 18:
ans += r[(x,y)]*r[(i,j)]
if x == i and y == j:
ans -= r[(x,y)]
print((ans//2)) | from decimal import Decimal
n = int(eval(input()))
a = []
r = {}
for i in range(n):
d = int(float(eval(input()))*10**9+0.01)
d2 = 0
d5 = 0
while True:
if d % 2 != 0 and d % 5 != 0:
break
if d % 2 == 0:
d //= 2
d2 += 1
if d % 5 == 0:
d //= 5
d5 += 1
a.append((d2,d5))
r[(d2,d5)] = r.get((d2,d5),0) + 1
ans = 0
for x , y in list(r.keys()):
for i , j in list(r.keys()):
if min(x+i,y+j) >= 18:
ans += r[(x,y)]*r[(i,j)]
if x == i and y == j:
ans -= r[(x,y)]
print((ans//2)) | 28 | 28 | 647 | 646 | from decimal import Decimal
n = int(eval(input()))
a = []
r = {}
for i in range(n):
d = int(float(eval(input())) * 10**9 + 0.1)
d2 = 0
d5 = 0
while True:
if d % 2 != 0 and d % 5 != 0:
break
if d % 2 == 0:
d //= 2
d2 += 1
if d % 5 == 0:
d //= 5
d5 += 1
a.append((d2, d5))
r[(d2, d5)] = r.get((d2, d5), 0) + 1
ans = 0
for x, y in list(r.keys()):
for i, j in list(r.keys()):
if min(x + i, y + j) >= 18:
ans += r[(x, y)] * r[(i, j)]
if x == i and y == j:
ans -= r[(x, y)]
print((ans // 2))
| from decimal import Decimal
n = int(eval(input()))
a = []
r = {}
for i in range(n):
d = int(float(eval(input())) * 10**9 + 0.01)
d2 = 0
d5 = 0
while True:
if d % 2 != 0 and d % 5 != 0:
break
if d % 2 == 0:
d //= 2
d2 += 1
if d % 5 == 0:
d //= 5
d5 += 1
a.append((d2, d5))
r[(d2, d5)] = r.get((d2, d5), 0) + 1
ans = 0
for x, y in list(r.keys()):
for i, j in list(r.keys()):
if min(x + i, y + j) >= 18:
ans += r[(x, y)] * r[(i, j)]
if x == i and y == j:
ans -= r[(x, y)]
print((ans // 2))
| false | 0 | [
"- d = int(float(eval(input())) * 10**9 + 0.1)",
"+ d = int(float(eval(input())) * 10**9 + 0.01)"
] | false | 0.089026 | 0.048246 | 1.845267 | [
"s004840149",
"s166375050"
] |
u838644735 | p03283 | python | s317688440 | s805161684 | 897 | 513 | 124,144 | 57,248 | Accepted | Accepted | 42.81 | def main():
N, M, Q, *X = list(map(int, open(0).read().split()))
L = [0]*M
R = [0]*M
p = [0]*Q
q = [0]*Q
for i in range(M):
L[i], R[i] = X[2*i], X[2*i + 1]
for i in range(Q):
p[i], q[i] = X[2*M + 2*i], X[2*M + 2*i + 1]
# print(N, M, Q, L, R, p, q)
S = [[0]*(N+1) for i in range(N+1)]
for i in range(M):
S[L[i]][R[i]] += 1
# for s in S:
# print(s)
S2 = [[0]*(N+1) for i in range(N+1)]
for i in range(N+1):
S2[i][0] = S[i][0]
for j in range(1, N+1):
S2[i][j] = S2[i][j-1] + S[i][j]
# for s in S2:
# print(s)
for i in range(Q):
pi, qi = p[i], q[i]
ans = 0
for j in range(pi, qi + 1):
ans += (S2[j][qi] - S2[j][pi-1])
print(ans)
if __name__ == '__main__':
main()
| def main():
N, M, Q, *X = list(map(int, open(0).read().split()))
L = [0]*M
R = [0]*M
p = [0]*Q
q = [0]*Q
for i in range(M):
L[i], R[i] = X[2*i], X[2*i + 1]
for i in range(Q):
p[i], q[i] = X[2*M + 2*i], X[2*M + 2*i + 1]
# print(N, M, Q, L, R, p, q)
S = [[0]*(N+1) for i in range(N+1)]
for i in range(M):
S[L[i]][R[i]] += 1
# for s in S:
# print(s)
S2 = [[0]*(N+1) for i in range(N+1)]
for i in range(N+1):
S2[i][0] = S[i][0]
for j in range(1, N+1):
S2[i][j] = S2[i][j-1] + S[i][j]
# for s in S2:
# print(s)
S3 = [[0]*(N+1) for i in range(N+1)]
for i in range(N+1):
S3[0][i] = S2[0][i]
for j in range(1, N+1):
S3[j][i] = S3[j-1][i] + S2[j][i]
for i in range(Q):
pi, qi = p[i], q[i]
ans = S3[qi][qi] - S3[qi][pi-1]
ans -= S3[pi-1][qi] - S3[pi-1][pi-1]
print(ans)
if __name__ == '__main__':
main()
| 32 | 37 | 861 | 1,026 | def main():
N, M, Q, *X = list(map(int, open(0).read().split()))
L = [0] * M
R = [0] * M
p = [0] * Q
q = [0] * Q
for i in range(M):
L[i], R[i] = X[2 * i], X[2 * i + 1]
for i in range(Q):
p[i], q[i] = X[2 * M + 2 * i], X[2 * M + 2 * i + 1]
# print(N, M, Q, L, R, p, q)
S = [[0] * (N + 1) for i in range(N + 1)]
for i in range(M):
S[L[i]][R[i]] += 1
# for s in S:
# print(s)
S2 = [[0] * (N + 1) for i in range(N + 1)]
for i in range(N + 1):
S2[i][0] = S[i][0]
for j in range(1, N + 1):
S2[i][j] = S2[i][j - 1] + S[i][j]
# for s in S2:
# print(s)
for i in range(Q):
pi, qi = p[i], q[i]
ans = 0
for j in range(pi, qi + 1):
ans += S2[j][qi] - S2[j][pi - 1]
print(ans)
if __name__ == "__main__":
main()
| def main():
N, M, Q, *X = list(map(int, open(0).read().split()))
L = [0] * M
R = [0] * M
p = [0] * Q
q = [0] * Q
for i in range(M):
L[i], R[i] = X[2 * i], X[2 * i + 1]
for i in range(Q):
p[i], q[i] = X[2 * M + 2 * i], X[2 * M + 2 * i + 1]
# print(N, M, Q, L, R, p, q)
S = [[0] * (N + 1) for i in range(N + 1)]
for i in range(M):
S[L[i]][R[i]] += 1
# for s in S:
# print(s)
S2 = [[0] * (N + 1) for i in range(N + 1)]
for i in range(N + 1):
S2[i][0] = S[i][0]
for j in range(1, N + 1):
S2[i][j] = S2[i][j - 1] + S[i][j]
# for s in S2:
# print(s)
S3 = [[0] * (N + 1) for i in range(N + 1)]
for i in range(N + 1):
S3[0][i] = S2[0][i]
for j in range(1, N + 1):
S3[j][i] = S3[j - 1][i] + S2[j][i]
for i in range(Q):
pi, qi = p[i], q[i]
ans = S3[qi][qi] - S3[qi][pi - 1]
ans -= S3[pi - 1][qi] - S3[pi - 1][pi - 1]
print(ans)
if __name__ == "__main__":
main()
| false | 13.513514 | [
"+ S3 = [[0] * (N + 1) for i in range(N + 1)]",
"+ for i in range(N + 1):",
"+ S3[0][i] = S2[0][i]",
"+ for j in range(1, N + 1):",
"+ S3[j][i] = S3[j - 1][i] + S2[j][i]",
"- ans = 0",
"- for j in range(pi, qi + 1):",
"- ans += S2[j][qi] - S2[j][pi - 1]",
"+ ans = S3[qi][qi] - S3[qi][pi - 1]",
"+ ans -= S3[pi - 1][qi] - S3[pi - 1][pi - 1]"
] | false | 0.082949 | 0.042634 | 1.945588 | [
"s317688440",
"s805161684"
] |
u218834617 | p03341 | python | s234947557 | s051099691 | 287 | 113 | 33,000 | 9,744 | Accepted | Accepted | 60.63 | N=int(eval(input()))
S=eval(input())
l,r=[0]*N,[0]*N
for i in range(N-1):
l[i+1]+=l[i]+(S[i]=='W')
for i in range(N-1,0,-1):
r[i-1]+=r[i]+(S[i]=='E')
ans=3*10**5
for i in range(N):
ans=min(ans,l[i]+r[i])
print(ans)
| N=int(eval(input()))
S=eval(input())
ans=cur=S.count('E')
for c in S:
cur+=-1 if c=='E' else 1
ans=min(ans,cur)
print(ans)
| 11 | 7 | 225 | 125 | N = int(eval(input()))
S = eval(input())
l, r = [0] * N, [0] * N
for i in range(N - 1):
l[i + 1] += l[i] + (S[i] == "W")
for i in range(N - 1, 0, -1):
r[i - 1] += r[i] + (S[i] == "E")
ans = 3 * 10**5
for i in range(N):
ans = min(ans, l[i] + r[i])
print(ans)
| N = int(eval(input()))
S = eval(input())
ans = cur = S.count("E")
for c in S:
cur += -1 if c == "E" else 1
ans = min(ans, cur)
print(ans)
| false | 36.363636 | [
"-l, r = [0] * N, [0] * N",
"-for i in range(N - 1):",
"- l[i + 1] += l[i] + (S[i] == \"W\")",
"-for i in range(N - 1, 0, -1):",
"- r[i - 1] += r[i] + (S[i] == \"E\")",
"-ans = 3 * 10**5",
"-for i in range(N):",
"- ans = min(ans, l[i] + r[i])",
"+ans = cur = S.count(\"E\")",
"+for c in S:",
"+ cur += -1 if c == \"E\" else 1",
"+ ans = min(ans, cur)"
] | false | 0.037358 | 0.102702 | 0.363748 | [
"s234947557",
"s051099691"
] |
u529787332 | p03448 | python | s867099042 | s756714766 | 61 | 49 | 8,404 | 3,060 | Accepted | Accepted | 19.67 | cnt500 = int(eval(input()))
cnt100 = int(eval(input()))
cnt50 = int(eval(input()))
X = int(eval(input()))
all = []
for a in range(cnt500+1):
for b in range(cnt100+1):
for c in range(cnt50+1):
all.append(a*500 + b*100 + c*50)
print((all.count(X))) | cnt500 = int(eval(input()))
cnt100 = int(eval(input()))
cnt50 = int(eval(input()))
X = int(eval(input()))
result = 0
for a in range(cnt500+1):
for b in range(cnt100+1):
for c in range(cnt50+1):
if (a*500 + b*100 + c*50) == X:
result += 1
print(result) | 11 | 12 | 255 | 277 | cnt500 = int(eval(input()))
cnt100 = int(eval(input()))
cnt50 = int(eval(input()))
X = int(eval(input()))
all = []
for a in range(cnt500 + 1):
for b in range(cnt100 + 1):
for c in range(cnt50 + 1):
all.append(a * 500 + b * 100 + c * 50)
print((all.count(X)))
| cnt500 = int(eval(input()))
cnt100 = int(eval(input()))
cnt50 = int(eval(input()))
X = int(eval(input()))
result = 0
for a in range(cnt500 + 1):
for b in range(cnt100 + 1):
for c in range(cnt50 + 1):
if (a * 500 + b * 100 + c * 50) == X:
result += 1
print(result)
| false | 8.333333 | [
"-all = []",
"+result = 0",
"- all.append(a * 500 + b * 100 + c * 50)",
"-print((all.count(X)))",
"+ if (a * 500 + b * 100 + c * 50) == X:",
"+ result += 1",
"+print(result)"
] | false | 0.19868 | 0.086539 | 2.295845 | [
"s867099042",
"s756714766"
] |
u121921603 | p02937 | python | s921208146 | s278212899 | 291 | 262 | 47,344 | 45,936 | Accepted | Accepted | 9.97 | from string import ascii_lowercase
from bisect import bisect_right
s = eval(input())
t = eval(input())
p = {c: [] for c in s}
for x, c in enumerate(s):
p[c].append(x)
z = 0
l = -1
for c in t:
if c not in p:
print((-1))
break
x = bisect_right(p[c], l)
if x == len(p[c]):
x = 0
z += 1
l = p[c][x]
else:
print((z * len(s) + l + 1))
| #from string import ascii_lowercase
from bisect import bisect_right
s = eval(input())
t = eval(input())
p = {c: [] for c in s}
for x, c in enumerate(s):
p[c].append(x)
z = 0
l = -1
for c in t:
if c not in p:
print((-1))
break
x = bisect_right(p[c], l)
if x == len(p[c]):
x = 0
z += 1
l = p[c][x]
else:
print((z * len(s) + l + 1))
| 20 | 20 | 388 | 389 | from string import ascii_lowercase
from bisect import bisect_right
s = eval(input())
t = eval(input())
p = {c: [] for c in s}
for x, c in enumerate(s):
p[c].append(x)
z = 0
l = -1
for c in t:
if c not in p:
print((-1))
break
x = bisect_right(p[c], l)
if x == len(p[c]):
x = 0
z += 1
l = p[c][x]
else:
print((z * len(s) + l + 1))
| # from string import ascii_lowercase
from bisect import bisect_right
s = eval(input())
t = eval(input())
p = {c: [] for c in s}
for x, c in enumerate(s):
p[c].append(x)
z = 0
l = -1
for c in t:
if c not in p:
print((-1))
break
x = bisect_right(p[c], l)
if x == len(p[c]):
x = 0
z += 1
l = p[c][x]
else:
print((z * len(s) + l + 1))
| false | 0 | [
"-from string import ascii_lowercase",
"+# from string import ascii_lowercase"
] | false | 0.071287 | 0.193438 | 0.368525 | [
"s921208146",
"s278212899"
] |
u698868214 | p02861 | python | s971998015 | s032455365 | 38 | 30 | 13,788 | 9,012 | Accepted | Accepted | 21.05 | import itertools
n = int(eval(input()))
town = [tuple(map(int,input().split())) for _ in range(n)]
c_town = list(itertools.combinations(town,2))
lp = len(list(itertools.permutations(town)))
sum_road = 0
for i in c_town:
sum_road += ((i[0][0]-i[1][0])**2 + (i[0][1]-i[1][1])**2)**0.5
print((2*sum_road/n)) | import math
from itertools import combinations
N = int(eval(input()))
xy = [tuple(map(int,input().split())) for _ in range(N)]
roots = list(combinations(list(range(0,N)),2))
sum_r = 0
for t, nt in roots:
sum_r += math.sqrt((xy[t][0] - xy[nt][0])**2 + (xy[t][1] - xy[nt][1])**2)
res = 2*sum_r/N
print(res) | 12 | 14 | 314 | 313 | import itertools
n = int(eval(input()))
town = [tuple(map(int, input().split())) for _ in range(n)]
c_town = list(itertools.combinations(town, 2))
lp = len(list(itertools.permutations(town)))
sum_road = 0
for i in c_town:
sum_road += ((i[0][0] - i[1][0]) ** 2 + (i[0][1] - i[1][1]) ** 2) ** 0.5
print((2 * sum_road / n))
| import math
from itertools import combinations
N = int(eval(input()))
xy = [tuple(map(int, input().split())) for _ in range(N)]
roots = list(combinations(list(range(0, N)), 2))
sum_r = 0
for t, nt in roots:
sum_r += math.sqrt((xy[t][0] - xy[nt][0]) ** 2 + (xy[t][1] - xy[nt][1]) ** 2)
res = 2 * sum_r / N
print(res)
| false | 14.285714 | [
"-import itertools",
"+import math",
"+from itertools import combinations",
"-n = int(eval(input()))",
"-town = [tuple(map(int, input().split())) for _ in range(n)]",
"-c_town = list(itertools.combinations(town, 2))",
"-lp = len(list(itertools.permutations(town)))",
"-sum_road = 0",
"-for i in c_town:",
"- sum_road += ((i[0][0] - i[1][0]) ** 2 + (i[0][1] - i[1][1]) ** 2) ** 0.5",
"-print((2 * sum_road / n))",
"+N = int(eval(input()))",
"+xy = [tuple(map(int, input().split())) for _ in range(N)]",
"+roots = list(combinations(list(range(0, N)), 2))",
"+sum_r = 0",
"+for t, nt in roots:",
"+ sum_r += math.sqrt((xy[t][0] - xy[nt][0]) ** 2 + (xy[t][1] - xy[nt][1]) ** 2)",
"+res = 2 * sum_r / N",
"+print(res)"
] | false | 0.040129 | 0.088676 | 0.45253 | [
"s971998015",
"s032455365"
] |
u037430802 | p02733 | python | s579872758 | s620064566 | 538 | 455 | 47,452 | 45,660 | Accepted | Accepted | 15.43 |
H,W,K = list(map(int, input().split()))
S = [[int(i) for i in list(eval(input()))] for _ in range(H)]
accum_col = [[0 for _ in range(W)] for _ in range(H)]
for i in range(H):
for j in range(W):
if i == 0:
accum_col[i][j] = S[i][j]
else:
accum_col[i][j] = accum_col[i-1][j] + S[i][j]
def cnt_white(x, a, b):
if a == 0:
return accum_col[b-1][x]
else:
return accum_col[b-1][x] - accum_col[a-1][x]
ans = H*W
for bit in range(1 << (H-1)):
# 横に直線で割るが、その線の真下のindex
horizs = [0]
cnt_split = bin(bit).count("1")
for i in range(H-1):
if bit & (1 << i):
"""
i=0でbitに1が立っていると、y=0と1の間を横一直線に割るので、次のブロックの始まりはy=1から。
みたいな意味でi+1
"""
horizs.append(i+1)
horizs.append(H)
# horizsの要素間がブロックなので-1
# これまでの各ブロックの累積のホワイトチョコの個数
prev = [0] * (len(horizs) - 1)
for x in range(W):
# 横位置でxの列の各ブロックのホワイトチョコの個数
curr_col = [cnt_white(x, a, b) for a,b in zip(horizs, horizs[1:])]
# 各ブロックの個数
prev_curr = [curr_col[i] + prev[i] for i in range(len(horizs)-1)]
if max(curr_col) > K:
# 一行だけみてもKを超えるブロックがあるので、十分大きい値を足してアウトにする
cnt_split += H*W
break
if max(prev_curr) > K:
# ホワイトチョコが最も多いブロックでKを超えていれば、手前の列までで割る
prev = curr_col
cnt_split += 1
else:
# いずれもK以下であればそのままブロックを広げる
prev = prev_curr
ans = min(ans, cnt_split)
print(ans)
|
H,W,K = list(map(int, input().split()))
S = [[int(i) for i in list(eval(input()))] for i in range(H)]
# 縦の累積ホワイトチョコ数
whites_col = [[0 for _ in range(W)] for _ in range(H)]
for w in range(W):
for h in range(H):
if h == 0:
whites_col[h][w] = S[h][w]
else:
whites_col[h][w] = whites_col[h-1][w] + S[h][w]
"""
マス目で考えると、縦Hマスある場合はH+1本の横線がある。
その横線の番号を渡して、その間にある数をとってくる
"""
def calc(w, a,b):
if a == 0:
return whites_col[b-1][w]
else:
return whites_col[b-1][w] - whites_col[a-1][w]
ans = (H-1)*(W-1)
for bit in range(1 << (H-1)):
cnt_split = bin(bit).count("1")
divs = [0]
for i in range(H-1):
if bit & (1 << i):
divs.append(i+1)
divs.append(H)
curr = [0] * (len(divs)-1)
prev = [0] * (len(divs)-1)
over_K_in_curr = False
for w in range(W):
for i,(a,b) in enumerate(zip(divs, divs[1:])):
curr[i] = calc(w, a, b)
over_K_in_curr = False
if max(curr) > K:
over_K_in_curr = True
break
for i in range(len(divs)-1):
prev[i] += curr[i]
if max(prev) > K:
cnt_split += 1
prev = curr[:]
if not over_K_in_curr:
ans = min(ans, cnt_split)
print(ans)
| 58 | 64 | 1,577 | 1,383 | H, W, K = list(map(int, input().split()))
S = [[int(i) for i in list(eval(input()))] for _ in range(H)]
accum_col = [[0 for _ in range(W)] for _ in range(H)]
for i in range(H):
for j in range(W):
if i == 0:
accum_col[i][j] = S[i][j]
else:
accum_col[i][j] = accum_col[i - 1][j] + S[i][j]
def cnt_white(x, a, b):
if a == 0:
return accum_col[b - 1][x]
else:
return accum_col[b - 1][x] - accum_col[a - 1][x]
ans = H * W
for bit in range(1 << (H - 1)):
# 横に直線で割るが、その線の真下のindex
horizs = [0]
cnt_split = bin(bit).count("1")
for i in range(H - 1):
if bit & (1 << i):
"""
i=0でbitに1が立っていると、y=0と1の間を横一直線に割るので、次のブロックの始まりはy=1から。
みたいな意味でi+1
"""
horizs.append(i + 1)
horizs.append(H)
# horizsの要素間がブロックなので-1
# これまでの各ブロックの累積のホワイトチョコの個数
prev = [0] * (len(horizs) - 1)
for x in range(W):
# 横位置でxの列の各ブロックのホワイトチョコの個数
curr_col = [cnt_white(x, a, b) for a, b in zip(horizs, horizs[1:])]
# 各ブロックの個数
prev_curr = [curr_col[i] + prev[i] for i in range(len(horizs) - 1)]
if max(curr_col) > K:
# 一行だけみてもKを超えるブロックがあるので、十分大きい値を足してアウトにする
cnt_split += H * W
break
if max(prev_curr) > K:
# ホワイトチョコが最も多いブロックでKを超えていれば、手前の列までで割る
prev = curr_col
cnt_split += 1
else:
# いずれもK以下であればそのままブロックを広げる
prev = prev_curr
ans = min(ans, cnt_split)
print(ans)
| H, W, K = list(map(int, input().split()))
S = [[int(i) for i in list(eval(input()))] for i in range(H)]
# 縦の累積ホワイトチョコ数
whites_col = [[0 for _ in range(W)] for _ in range(H)]
for w in range(W):
for h in range(H):
if h == 0:
whites_col[h][w] = S[h][w]
else:
whites_col[h][w] = whites_col[h - 1][w] + S[h][w]
"""
マス目で考えると、縦Hマスある場合はH+1本の横線がある。
その横線の番号を渡して、その間にある数をとってくる
"""
def calc(w, a, b):
if a == 0:
return whites_col[b - 1][w]
else:
return whites_col[b - 1][w] - whites_col[a - 1][w]
ans = (H - 1) * (W - 1)
for bit in range(1 << (H - 1)):
cnt_split = bin(bit).count("1")
divs = [0]
for i in range(H - 1):
if bit & (1 << i):
divs.append(i + 1)
divs.append(H)
curr = [0] * (len(divs) - 1)
prev = [0] * (len(divs) - 1)
over_K_in_curr = False
for w in range(W):
for i, (a, b) in enumerate(zip(divs, divs[1:])):
curr[i] = calc(w, a, b)
over_K_in_curr = False
if max(curr) > K:
over_K_in_curr = True
break
for i in range(len(divs) - 1):
prev[i] += curr[i]
if max(prev) > K:
cnt_split += 1
prev = curr[:]
if not over_K_in_curr:
ans = min(ans, cnt_split)
print(ans)
| false | 9.375 | [
"-S = [[int(i) for i in list(eval(input()))] for _ in range(H)]",
"-accum_col = [[0 for _ in range(W)] for _ in range(H)]",
"-for i in range(H):",
"- for j in range(W):",
"- if i == 0:",
"- accum_col[i][j] = S[i][j]",
"+S = [[int(i) for i in list(eval(input()))] for i in range(H)]",
"+# 縦の累積ホワイトチョコ数",
"+whites_col = [[0 for _ in range(W)] for _ in range(H)]",
"+for w in range(W):",
"+ for h in range(H):",
"+ if h == 0:",
"+ whites_col[h][w] = S[h][w]",
"- accum_col[i][j] = accum_col[i - 1][j] + S[i][j]",
"+ whites_col[h][w] = whites_col[h - 1][w] + S[h][w]",
"+\"\"\"",
"+マス目で考えると、縦Hマスある場合はH+1本の横線がある。",
"+その横線の番号を渡して、その間にある数をとってくる",
"+\"\"\"",
"-def cnt_white(x, a, b):",
"+def calc(w, a, b):",
"- return accum_col[b - 1][x]",
"+ return whites_col[b - 1][w]",
"- return accum_col[b - 1][x] - accum_col[a - 1][x]",
"+ return whites_col[b - 1][w] - whites_col[a - 1][w]",
"-ans = H * W",
"+ans = (H - 1) * (W - 1)",
"- # 横に直線で割るが、その線の真下のindex",
"- horizs = [0]",
"+ divs = [0]",
"- \"\"\"",
"- i=0でbitに1が立っていると、y=0と1の間を横一直線に割るので、次のブロックの始まりはy=1から。",
"- みたいな意味でi+1",
"- \"\"\"",
"- horizs.append(i + 1)",
"- horizs.append(H)",
"- # horizsの要素間がブロックなので-1",
"- # これまでの各ブロックの累積のホワイトチョコの個数",
"- prev = [0] * (len(horizs) - 1)",
"- for x in range(W):",
"- # 横位置でxの列の各ブロックのホワイトチョコの個数",
"- curr_col = [cnt_white(x, a, b) for a, b in zip(horizs, horizs[1:])]",
"- # 各ブロックの個数",
"- prev_curr = [curr_col[i] + prev[i] for i in range(len(horizs) - 1)]",
"- if max(curr_col) > K:",
"- # 一行だけみてもKを超えるブロックがあるので、十分大きい値を足してアウトにする",
"- cnt_split += H * W",
"+ divs.append(i + 1)",
"+ divs.append(H)",
"+ curr = [0] * (len(divs) - 1)",
"+ prev = [0] * (len(divs) - 1)",
"+ over_K_in_curr = False",
"+ for w in range(W):",
"+ for i, (a, b) in enumerate(zip(divs, divs[1:])):",
"+ curr[i] = calc(w, a, b)",
"+ over_K_in_curr = False",
"+ if max(curr) > K:",
"+ over_K_in_curr = True",
"- if max(prev_curr) > K:",
"- # ホワイトチョコが最も多いブロックでKを超えていれば、手前の列までで割る",
"- prev = curr_col",
"+ for i in range(len(divs) - 1):",
"+ prev[i] += curr[i]",
"+ if max(prev) > K:",
"- else:",
"- # いずれもK以下であればそのままブロックを広げる",
"- prev = prev_curr",
"- ans = min(ans, cnt_split)",
"+ prev = curr[:]",
"+ if not over_K_in_curr:",
"+ ans = min(ans, cnt_split)"
] | false | 0.044326 | 0.044167 | 1.003609 | [
"s579872758",
"s620064566"
] |
u965397031 | p02711 | python | s422982733 | s264584033 | 29 | 26 | 9,040 | 8,928 | Accepted | Accepted | 10.34 | n = eval(input())
if n[0] == '7' or n[1] == '7' or n[2] == '7':
ans = 'Yes'
else:
ans = 'No'
print(ans) | n = eval(input())
print(('Yes' if '7' in n else 'No')) | 7 | 2 | 112 | 47 | n = eval(input())
if n[0] == "7" or n[1] == "7" or n[2] == "7":
ans = "Yes"
else:
ans = "No"
print(ans)
| n = eval(input())
print(("Yes" if "7" in n else "No"))
| false | 71.428571 | [
"-if n[0] == \"7\" or n[1] == \"7\" or n[2] == \"7\":",
"- ans = \"Yes\"",
"-else:",
"- ans = \"No\"",
"-print(ans)",
"+print((\"Yes\" if \"7\" in n else \"No\"))"
] | false | 0.049039 | 0.047739 | 1.027233 | [
"s422982733",
"s264584033"
] |
u480138356 | p03546 | python | s113745105 | s801622381 | 414 | 289 | 25,992 | 17,732 | Accepted | Accepted | 30.19 | import sys
from scipy.sparse.csgraph import floyd_warshall as wf
input = sys.stdin.readline
def main():
H, W = list(map(int, input().split()))
link = [list(map(int, input().split())) for i in range(10)]
a = [list(map(int, input().split())) for i in range(H)]
link = wf(link)
ans = 0
for i in range(H):
for j in range(W):
if a[i][j] != -1:
ans += link[a[i][j]][1]
print((int(ans)))
if __name__ == "__main__":
main() | from scipy.sparse.csgraph import floyd_warshall as fw
def main():
h, w = list(map(int, input().split()))
link = [list(map(int, input().split())) for i in range(10)]
a = [list(map(int, input().split())) for i in range(h)]
link = fw(link)
ans = 0
for i in range(h):
for j in range(w):
if a[i][j] != -1:
ans += link[a[i][j]][1]
print((int(ans)))
if __name__ == "__main__":
main() | 20 | 19 | 467 | 459 | import sys
from scipy.sparse.csgraph import floyd_warshall as wf
input = sys.stdin.readline
def main():
H, W = list(map(int, input().split()))
link = [list(map(int, input().split())) for i in range(10)]
a = [list(map(int, input().split())) for i in range(H)]
link = wf(link)
ans = 0
for i in range(H):
for j in range(W):
if a[i][j] != -1:
ans += link[a[i][j]][1]
print((int(ans)))
if __name__ == "__main__":
main()
| from scipy.sparse.csgraph import floyd_warshall as fw
def main():
h, w = list(map(int, input().split()))
link = [list(map(int, input().split())) for i in range(10)]
a = [list(map(int, input().split())) for i in range(h)]
link = fw(link)
ans = 0
for i in range(h):
for j in range(w):
if a[i][j] != -1:
ans += link[a[i][j]][1]
print((int(ans)))
if __name__ == "__main__":
main()
| false | 5 | [
"-import sys",
"-from scipy.sparse.csgraph import floyd_warshall as wf",
"-",
"-input = sys.stdin.readline",
"+from scipy.sparse.csgraph import floyd_warshall as fw",
"- H, W = list(map(int, input().split()))",
"+ h, w = list(map(int, input().split()))",
"- a = [list(map(int, input().split())) for i in range(H)]",
"- link = wf(link)",
"+ a = [list(map(int, input().split())) for i in range(h)]",
"+ link = fw(link)",
"- for i in range(H):",
"- for j in range(W):",
"+ for i in range(h):",
"+ for j in range(w):"
] | false | 0.399887 | 0.316547 | 1.263279 | [
"s113745105",
"s801622381"
] |
u695811449 | p03173 | python | s041575729 | s454457999 | 1,407 | 537 | 50,652 | 46,300 | Accepted | Accepted | 61.83 | N=int(eval(input()))
A=list(map(int,input().split()))
DPLIST=[[None]*N for i in range(N)]
for i in range(N):
DPLIST[i][i]=[0,A[i]]
for i in range(1,N):
for j in range(i,N):
#print(i,j)
ANS=float("inf")
slime=float("inf")
for k in range(j-i,j):
sc1,sl1=DPLIST[j-i][k]
sc2,sl2=DPLIST[k+1][j]
if ANS>sc1+sc2+sl1+sl2:
ANS=sc1+sc2+sl1+sl2
slime=sl1+sl2
DPLIST[j-i][j]=[ANS,slime]
#print(DPLIST)
#print()
print((DPLIST[0][N-1][0])) | N=int(eval(input()))
A=list(map(int,input().split()))
DPLIST=[[None]*N for i in range(N)]
for i in range(N):
DPLIST[i][i]=0
SUM=[0]
for i in range(N):
SUM.append(SUM[-1]+A[i])
for i in range(1,N):
for j in range(i,N):
ANS=float("inf")
for k in range(j-i,j):
if ANS>DPLIST[j-i][k]+DPLIST[k+1][j]+SUM[j+1]-SUM[j-i]:
ANS=DPLIST[j-i][k]+DPLIST[k+1][j]+SUM[j+1]-SUM[j-i]
DPLIST[j-i][j]=ANS
print((DPLIST[0][N-1])) | 29 | 25 | 598 | 505 | N = int(eval(input()))
A = list(map(int, input().split()))
DPLIST = [[None] * N for i in range(N)]
for i in range(N):
DPLIST[i][i] = [0, A[i]]
for i in range(1, N):
for j in range(i, N):
# print(i,j)
ANS = float("inf")
slime = float("inf")
for k in range(j - i, j):
sc1, sl1 = DPLIST[j - i][k]
sc2, sl2 = DPLIST[k + 1][j]
if ANS > sc1 + sc2 + sl1 + sl2:
ANS = sc1 + sc2 + sl1 + sl2
slime = sl1 + sl2
DPLIST[j - i][j] = [ANS, slime]
# print(DPLIST)
# print()
print((DPLIST[0][N - 1][0]))
| N = int(eval(input()))
A = list(map(int, input().split()))
DPLIST = [[None] * N for i in range(N)]
for i in range(N):
DPLIST[i][i] = 0
SUM = [0]
for i in range(N):
SUM.append(SUM[-1] + A[i])
for i in range(1, N):
for j in range(i, N):
ANS = float("inf")
for k in range(j - i, j):
if ANS > DPLIST[j - i][k] + DPLIST[k + 1][j] + SUM[j + 1] - SUM[j - i]:
ANS = DPLIST[j - i][k] + DPLIST[k + 1][j] + SUM[j + 1] - SUM[j - i]
DPLIST[j - i][j] = ANS
print((DPLIST[0][N - 1]))
| false | 13.793103 | [
"- DPLIST[i][i] = [0, A[i]]",
"+ DPLIST[i][i] = 0",
"+SUM = [0]",
"+for i in range(N):",
"+ SUM.append(SUM[-1] + A[i])",
"- # print(i,j)",
"- slime = float(\"inf\")",
"- sc1, sl1 = DPLIST[j - i][k]",
"- sc2, sl2 = DPLIST[k + 1][j]",
"- if ANS > sc1 + sc2 + sl1 + sl2:",
"- ANS = sc1 + sc2 + sl1 + sl2",
"- slime = sl1 + sl2",
"- DPLIST[j - i][j] = [ANS, slime]",
"- # print(DPLIST)",
"- # print()",
"-print((DPLIST[0][N - 1][0]))",
"+ if ANS > DPLIST[j - i][k] + DPLIST[k + 1][j] + SUM[j + 1] - SUM[j - i]:",
"+ ANS = DPLIST[j - i][k] + DPLIST[k + 1][j] + SUM[j + 1] - SUM[j - i]",
"+ DPLIST[j - i][j] = ANS",
"+print((DPLIST[0][N - 1]))"
] | false | 0.14208 | 0.13112 | 1.083589 | [
"s041575729",
"s454457999"
] |
u270144704 | p02786 | python | s093539650 | s590724682 | 177 | 161 | 38,384 | 38,256 | Accepted | Accepted | 9.04 | from math import floor
def kill(life):
if life in list(dp.keys()):
return dp[life]
if life == 1:
dp[life] = 1
return 1
elif life > 1:
dp[life] = kill(floor(life/2)) * 2 + 1
return dp[life]
h = int(eval(input()))
dp = {}
print((kill(h))) | def kill(life):
if life == 1:
return 1
elif life > 1:
return kill(life//2) * 2 + 1
h = int(eval(input()))
print((kill(h))) | 13 | 7 | 286 | 144 | from math import floor
def kill(life):
if life in list(dp.keys()):
return dp[life]
if life == 1:
dp[life] = 1
return 1
elif life > 1:
dp[life] = kill(floor(life / 2)) * 2 + 1
return dp[life]
h = int(eval(input()))
dp = {}
print((kill(h)))
| def kill(life):
if life == 1:
return 1
elif life > 1:
return kill(life // 2) * 2 + 1
h = int(eval(input()))
print((kill(h)))
| false | 46.153846 | [
"-from math import floor",
"-",
"-",
"- if life in list(dp.keys()):",
"- return dp[life]",
"- dp[life] = 1",
"- dp[life] = kill(floor(life / 2)) * 2 + 1",
"- return dp[life]",
"+ return kill(life // 2) * 2 + 1",
"-dp = {}"
] | false | 0.04319 | 0.04216 | 1.024437 | [
"s093539650",
"s590724682"
] |
u529386725 | p01136 | python | s629434751 | s266187181 | 2,810 | 2,240 | 13,912 | 7,976 | Accepted | Accepted | 20.28 | MAX_N = 50
MAX_DAY = 30
def solve(n, f):
dp = [[set() for j in range(n)] for i in range(MAX_DAY + 1)]
for i in range(n):
dp[0][i].add(i)
for d in range(1, MAX_DAY + 1):
# for line in dp[:5]:
# print(line)
for i in range(n):
dp[d][i] |= dp[d - 1][i]
for j in range(n):
if f[d][i] and f[d][j]:
dp[d][i] |= dp[d - 1][j]
if len(dp[d][i]) == n:
return d
return -1
######################################
while True:
n = int(eval(input()))
if n == 0:
exit()
f = [[False] * n for i in range(MAX_DAY + 1)]
for i in range(n):
_, *li = list(map(int, input().split()))
for x in li:
f[x][i] = True
# for line in f:
# print(line)
print((solve(n, f))) | MAX_N = 50
MAX_DAY = 30
def solve(n, f):
dp = [{i} for i in range(n)]
for d in range(1, MAX_DAY + 1):
for i in range(n):
for j in range(n):
if f[d][i] and f[d][j]:
dp[i] |= dp[j]
if len(dp[i]) == n:
return d
return -1
######################################
while True:
n = int(eval(input()))
if n == 0:
exit()
f = [[False] * n for i in range(MAX_DAY + 1)]
for i in range(n):
_, *li = list(map(int, input().split()))
for x in li:
f[x][i] = True
print((solve(n, f))) | 41 | 31 | 881 | 640 | MAX_N = 50
MAX_DAY = 30
def solve(n, f):
dp = [[set() for j in range(n)] for i in range(MAX_DAY + 1)]
for i in range(n):
dp[0][i].add(i)
for d in range(1, MAX_DAY + 1):
# for line in dp[:5]:
# print(line)
for i in range(n):
dp[d][i] |= dp[d - 1][i]
for j in range(n):
if f[d][i] and f[d][j]:
dp[d][i] |= dp[d - 1][j]
if len(dp[d][i]) == n:
return d
return -1
######################################
while True:
n = int(eval(input()))
if n == 0:
exit()
f = [[False] * n for i in range(MAX_DAY + 1)]
for i in range(n):
_, *li = list(map(int, input().split()))
for x in li:
f[x][i] = True
# for line in f:
# print(line)
print((solve(n, f)))
| MAX_N = 50
MAX_DAY = 30
def solve(n, f):
dp = [{i} for i in range(n)]
for d in range(1, MAX_DAY + 1):
for i in range(n):
for j in range(n):
if f[d][i] and f[d][j]:
dp[i] |= dp[j]
if len(dp[i]) == n:
return d
return -1
######################################
while True:
n = int(eval(input()))
if n == 0:
exit()
f = [[False] * n for i in range(MAX_DAY + 1)]
for i in range(n):
_, *li = list(map(int, input().split()))
for x in li:
f[x][i] = True
print((solve(n, f)))
| false | 24.390244 | [
"- dp = [[set() for j in range(n)] for i in range(MAX_DAY + 1)]",
"- for i in range(n):",
"- dp[0][i].add(i)",
"+ dp = [{i} for i in range(n)]",
"- # for line in dp[:5]:",
"- # print(line)",
"- dp[d][i] |= dp[d - 1][i]",
"- dp[d][i] |= dp[d - 1][j]",
"- if len(dp[d][i]) == n:",
"+ dp[i] |= dp[j]",
"+ if len(dp[i]) == n:",
"- # for line in f:",
"- # print(line)"
] | false | 0.039538 | 0.038722 | 1.021075 | [
"s629434751",
"s266187181"
] |
u371132735 | p02813 | python | s661324351 | s622727007 | 135 | 29 | 10,868 | 3,064 | Accepted | Accepted | 78.52 |
import itertools
N = int(eval(input()))
a = list(itertools.permutations(list(range(1, N+1))))
s = []
for i in a:
ans = ""
for j in i:
ans+=str(j)
s.append(ans)
P = "".join(list(input().split()))
Q = "".join(list(input().split()))
ans = abs((s.index(P)+1)-(s.index(Q)+1))
print(ans)
| # abc150_c.py
'''
全パターン作ってソートで順番みる
'''
import itertools
N = int(eval(input()))
P = tuple(list(map(int,input().split())))
Q = tuple(list(map(int,input().split())))
l = [i+1 for i in range(N)]
target = itertools.permutations(l)
cnt=0
pcnt = 0
qcnt = 0
for i in target:
cnt += 1
if i == P:
pcnt=cnt
if i == Q:
qcnt=cnt
print((abs(pcnt-qcnt)))
| 16 | 22 | 298 | 384 | import itertools
N = int(eval(input()))
a = list(itertools.permutations(list(range(1, N + 1))))
s = []
for i in a:
ans = ""
for j in i:
ans += str(j)
s.append(ans)
P = "".join(list(input().split()))
Q = "".join(list(input().split()))
ans = abs((s.index(P) + 1) - (s.index(Q) + 1))
print(ans)
| # abc150_c.py
"""
全パターン作ってソートで順番みる
"""
import itertools
N = int(eval(input()))
P = tuple(list(map(int, input().split())))
Q = tuple(list(map(int, input().split())))
l = [i + 1 for i in range(N)]
target = itertools.permutations(l)
cnt = 0
pcnt = 0
qcnt = 0
for i in target:
cnt += 1
if i == P:
pcnt = cnt
if i == Q:
qcnt = cnt
print((abs(pcnt - qcnt)))
| false | 27.272727 | [
"+# abc150_c.py",
"+\"\"\"",
"+全パターン作ってソートで順番みる",
"+\"\"\"",
"-a = list(itertools.permutations(list(range(1, N + 1))))",
"-s = []",
"-for i in a:",
"- ans = \"\"",
"- for j in i:",
"- ans += str(j)",
"- s.append(ans)",
"-P = \"\".join(list(input().split()))",
"-Q = \"\".join(list(input().split()))",
"-ans = abs((s.index(P) + 1) - (s.index(Q) + 1))",
"-print(ans)",
"+P = tuple(list(map(int, input().split())))",
"+Q = tuple(list(map(int, input().split())))",
"+l = [i + 1 for i in range(N)]",
"+target = itertools.permutations(l)",
"+cnt = 0",
"+pcnt = 0",
"+qcnt = 0",
"+for i in target:",
"+ cnt += 1",
"+ if i == P:",
"+ pcnt = cnt",
"+ if i == Q:",
"+ qcnt = cnt",
"+print((abs(pcnt - qcnt)))"
] | false | 0.060016 | 0.041097 | 1.460348 | [
"s661324351",
"s622727007"
] |
u526603504 | p02913 | python | s841313699 | s595576357 | 831 | 75 | 247,176 | 6,516 | Accepted | Accepted | 90.97 | N = int(eval(input()))
S = eval(input())
dp = [[0 for _ in range(N)] for _ in range(N)]
ans = 0
for i in range(N):
for j in range(i + 1, N):
if S[i] == S[j]:
tmp = 1
if i > 0:
tmp += dp[i - 1][j - 1]
if j - i < tmp:
continue
dp[i][j] = tmp
ans = max(ans, dp[i][j])
print(ans) | N = int(eval(input()))
S = eval(input())
F = [1] * (N//2 + 2)
for i in range(1, len(F)):
F[i] = F[i] * 26
def check(l):
D = set()
for i in range(N - 2 * l + 1):
D.add(S[i:i+l])
if S[i+l:i+2*l] in D:
return True
OK = 0
NG = N // 2 + 1
while abs(OK - NG) > 1:
mid = (OK + NG) // 2
if check(mid):
OK = mid
else:
NG = mid
print(OK) | 17 | 25 | 381 | 412 | N = int(eval(input()))
S = eval(input())
dp = [[0 for _ in range(N)] for _ in range(N)]
ans = 0
for i in range(N):
for j in range(i + 1, N):
if S[i] == S[j]:
tmp = 1
if i > 0:
tmp += dp[i - 1][j - 1]
if j - i < tmp:
continue
dp[i][j] = tmp
ans = max(ans, dp[i][j])
print(ans)
| N = int(eval(input()))
S = eval(input())
F = [1] * (N // 2 + 2)
for i in range(1, len(F)):
F[i] = F[i] * 26
def check(l):
D = set()
for i in range(N - 2 * l + 1):
D.add(S[i : i + l])
if S[i + l : i + 2 * l] in D:
return True
OK = 0
NG = N // 2 + 1
while abs(OK - NG) > 1:
mid = (OK + NG) // 2
if check(mid):
OK = mid
else:
NG = mid
print(OK)
| false | 32 | [
"-dp = [[0 for _ in range(N)] for _ in range(N)]",
"-ans = 0",
"-for i in range(N):",
"- for j in range(i + 1, N):",
"- if S[i] == S[j]:",
"- tmp = 1",
"- if i > 0:",
"- tmp += dp[i - 1][j - 1]",
"- if j - i < tmp:",
"- continue",
"- dp[i][j] = tmp",
"- ans = max(ans, dp[i][j])",
"-print(ans)",
"+F = [1] * (N // 2 + 2)",
"+for i in range(1, len(F)):",
"+ F[i] = F[i] * 26",
"+",
"+",
"+def check(l):",
"+ D = set()",
"+ for i in range(N - 2 * l + 1):",
"+ D.add(S[i : i + l])",
"+ if S[i + l : i + 2 * l] in D:",
"+ return True",
"+",
"+",
"+OK = 0",
"+NG = N // 2 + 1",
"+while abs(OK - NG) > 1:",
"+ mid = (OK + NG) // 2",
"+ if check(mid):",
"+ OK = mid",
"+ else:",
"+ NG = mid",
"+print(OK)"
] | false | 0.065505 | 0.037526 | 1.745588 | [
"s841313699",
"s595576357"
] |
u729133443 | p03280 | python | s477821271 | s135872487 | 163 | 25 | 38,256 | 9,100 | Accepted | Accepted | 84.66 | print((eval('~-'+'*~-'.join(input().split())))) | a,b=list(map(int,input().split()))
print((~-a*~-b)) | 1 | 2 | 45 | 44 | print((eval("~-" + "*~-".join(input().split()))))
| a, b = list(map(int, input().split()))
print((~-a * ~-b))
| false | 50 | [
"-print((eval(\"~-\" + \"*~-\".join(input().split()))))",
"+a, b = list(map(int, input().split()))",
"+print((~-a * ~-b))"
] | false | 0.092527 | 0.037354 | 2.477026 | [
"s477821271",
"s135872487"
] |
u606045429 | p03063 | python | s611228932 | s967637923 | 254 | 108 | 12,776 | 3,500 | Accepted | Accepted | 57.48 | N = int(eval(input()))
S = eval(input())
white = [0] * (N + 1)
black = [0] * (N + 1)
for i, si in enumerate(S):
black[i + 1] = black[i]
white[i + 1] = white[i]
if si == "#":
black[i + 1] += 1
if si == ".":
white[i + 1] += 1
mi = 10 ** 10
for i in range(N + 1):
b = black[i]
w = white[N] - white[i]
mi = min(w + b, mi)
print(mi)
| N, S = int(eval(input())), eval(input())
b, w = 0, S.count('.')
ans = b + w
for si in S:
if si == "#":
b += 1
if si == ".":
w -= 1
ans = min(ans, b + w)
print(ans)
| 19 | 10 | 380 | 189 | N = int(eval(input()))
S = eval(input())
white = [0] * (N + 1)
black = [0] * (N + 1)
for i, si in enumerate(S):
black[i + 1] = black[i]
white[i + 1] = white[i]
if si == "#":
black[i + 1] += 1
if si == ".":
white[i + 1] += 1
mi = 10**10
for i in range(N + 1):
b = black[i]
w = white[N] - white[i]
mi = min(w + b, mi)
print(mi)
| N, S = int(eval(input())), eval(input())
b, w = 0, S.count(".")
ans = b + w
for si in S:
if si == "#":
b += 1
if si == ".":
w -= 1
ans = min(ans, b + w)
print(ans)
| false | 47.368421 | [
"-N = int(eval(input()))",
"-S = eval(input())",
"-white = [0] * (N + 1)",
"-black = [0] * (N + 1)",
"-for i, si in enumerate(S):",
"- black[i + 1] = black[i]",
"- white[i + 1] = white[i]",
"+N, S = int(eval(input())), eval(input())",
"+b, w = 0, S.count(\".\")",
"+ans = b + w",
"+for si in S:",
"- black[i + 1] += 1",
"+ b += 1",
"- white[i + 1] += 1",
"-mi = 10**10",
"-for i in range(N + 1):",
"- b = black[i]",
"- w = white[N] - white[i]",
"- mi = min(w + b, mi)",
"-print(mi)",
"+ w -= 1",
"+ ans = min(ans, b + w)",
"+print(ans)"
] | false | 0.039742 | 0.038751 | 1.025583 | [
"s611228932",
"s967637923"
] |
u617515020 | p03557 | python | s093805620 | s342890351 | 327 | 251 | 23,360 | 29,388 | Accepted | Accepted | 23.24 | import bisect
N = int(eval(input()))
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
A.sort()
B.sort()
C.sort()
cnt = 0
for j in range(N):
i = bisect.bisect_left(A, B[j])
k = bisect.bisect_right(C, B[j])
cnt += i * (N - k)
print(cnt) | from bisect import bisect,bisect_left
N=int(eval(input()))
A=sorted(list(map(int,input().split())))
B=sorted(list(map(int,input().split())))
C=sorted(list(map(int,input().split())))
ans=0
for b in B:
i=bisect_left(A,b)
j=bisect(C,b)
ans+=i*(N-j)
print(ans) | 16 | 11 | 310 | 266 | import bisect
N = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
B.sort()
C.sort()
cnt = 0
for j in range(N):
i = bisect.bisect_left(A, B[j])
k = bisect.bisect_right(C, B[j])
cnt += i * (N - k)
print(cnt)
| from bisect import bisect, bisect_left
N = int(eval(input()))
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))
ans = 0
for b in B:
i = bisect_left(A, b)
j = bisect(C, b)
ans += i * (N - j)
print(ans)
| false | 31.25 | [
"-import bisect",
"+from bisect import bisect, bisect_left",
"-A = list(map(int, input().split()))",
"-B = list(map(int, input().split()))",
"-C = list(map(int, input().split()))",
"-A.sort()",
"-B.sort()",
"-C.sort()",
"-cnt = 0",
"-for j in range(N):",
"- i = bisect.bisect_left(A, B[j])",
"- k = bisect.bisect_right(C, B[j])",
"- cnt += i * (N - k)",
"-print(cnt)",
"+A = sorted(list(map(int, input().split())))",
"+B = sorted(list(map(int, input().split())))",
"+C = sorted(list(map(int, input().split())))",
"+ans = 0",
"+for b in B:",
"+ i = bisect_left(A, b)",
"+ j = bisect(C, b)",
"+ ans += i * (N - j)",
"+print(ans)"
] | false | 0.043866 | 0.117362 | 0.373765 | [
"s093805620",
"s342890351"
] |
u828847847 | p03504 | python | s227968902 | s175992354 | 1,123 | 1,006 | 38,260 | 41,732 | Accepted | Accepted | 10.42 | n, c = list(map(int, input().split()))
r = [[0 for i in range(c)] for j in range(100000)]
for dummy in range(n):
s, t, c = list(map(int, input().split()))
for j in range(s - 1, t):
r[j][c - 1] = 1
ans = 0
for i in range(100000):
if sum(r[i]) > ans:
ans = sum(r[i])
print(ans) | n, c = list(map(int,input().split()))
arr = [[0 for i in range(c)] for j in range(10**5+1)]
for i in range(n):
s,t,ch = list(map(int,input().split()))
s -= 1
ch -= 1
for i in range(s,t):
arr[i][ch] = 1
ans = 0
for i in range(10**5+1):
ans = max(ans,sum(arr[i]))
print(ans) | 14 | 17 | 311 | 295 | n, c = list(map(int, input().split()))
r = [[0 for i in range(c)] for j in range(100000)]
for dummy in range(n):
s, t, c = list(map(int, input().split()))
for j in range(s - 1, t):
r[j][c - 1] = 1
ans = 0
for i in range(100000):
if sum(r[i]) > ans:
ans = sum(r[i])
print(ans)
| n, c = list(map(int, input().split()))
arr = [[0 for i in range(c)] for j in range(10**5 + 1)]
for i in range(n):
s, t, ch = list(map(int, input().split()))
s -= 1
ch -= 1
for i in range(s, t):
arr[i][ch] = 1
ans = 0
for i in range(10**5 + 1):
ans = max(ans, sum(arr[i]))
print(ans)
| false | 17.647059 | [
"-r = [[0 for i in range(c)] for j in range(100000)]",
"-for dummy in range(n):",
"- s, t, c = list(map(int, input().split()))",
"- for j in range(s - 1, t):",
"- r[j][c - 1] = 1",
"+arr = [[0 for i in range(c)] for j in range(10**5 + 1)]",
"+for i in range(n):",
"+ s, t, ch = list(map(int, input().split()))",
"+ s -= 1",
"+ ch -= 1",
"+ for i in range(s, t):",
"+ arr[i][ch] = 1",
"-for i in range(100000):",
"- if sum(r[i]) > ans:",
"- ans = sum(r[i])",
"+for i in range(10**5 + 1):",
"+ ans = max(ans, sum(arr[i]))"
] | false | 0.263796 | 0.191422 | 1.378083 | [
"s227968902",
"s175992354"
] |
u638456847 | p02624 | python | s544764223 | s843978332 | 1,623 | 587 | 9,172 | 109,172 | Accepted | Accepted | 63.83 | import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
def main(N):
ans = 0
for n in range(1,N+1):
ans += (N // n) * n * (1 + (N // n)) // 2
print(ans)
if __name__ == "__main__":
N = int(readline())
main(N)
| from numba import njit
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
@njit
def main(N):
ans = 0
for n in range(1,N+1):
ans += (N // n) * n * (1 + (N // n)) // 2
print(ans)
if __name__ == "__main__":
N = int(readline())
main(N)
| 17 | 19 | 296 | 327 | import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
def main(N):
ans = 0
for n in range(1, N + 1):
ans += (N // n) * n * (1 + (N // n)) // 2
print(ans)
if __name__ == "__main__":
N = int(readline())
main(N)
| from numba import njit
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
@njit
def main(N):
ans = 0
for n in range(1, N + 1):
ans += (N // n) * n * (1 + (N // n)) // 2
print(ans)
if __name__ == "__main__":
N = int(readline())
main(N)
| false | 10.526316 | [
"+from numba import njit",
"+@njit"
] | false | 0.549195 | 0.077759 | 7.062766 | [
"s544764223",
"s843978332"
] |
u573754721 | p02743 | python | s399104468 | s535996187 | 294 | 253 | 59,756 | 59,628 | Accepted | Accepted | 13.95 | from decimal import Decimal
a,b,c=list(map(int,input().split()))
if Decimal(a)**Decimal('0.5')+Decimal(b)**Decimal('0.5')<Decimal(c)**Decimal('0.5'):
print('Yes')
else:
print('No')
| import decimal
a,b,c=list(map(int,input().split()))
if decimal.Decimal(a)**decimal.Decimal('0.5')+decimal.Decimal(b)**decimal.Decimal('0.5')<decimal.Decimal(c)**decimal.Decimal('0.5'):
print('Yes')
else:
print('No')
| 6 | 7 | 188 | 229 | from decimal import Decimal
a, b, c = list(map(int, input().split()))
if Decimal(a) ** Decimal("0.5") + Decimal(b) ** Decimal("0.5") < Decimal(c) ** Decimal(
"0.5"
):
print("Yes")
else:
print("No")
| import decimal
a, b, c = list(map(int, input().split()))
if decimal.Decimal(a) ** decimal.Decimal("0.5") + decimal.Decimal(b) ** decimal.Decimal(
"0.5"
) < decimal.Decimal(c) ** decimal.Decimal("0.5"):
print("Yes")
else:
print("No")
| false | 14.285714 | [
"-from decimal import Decimal",
"+import decimal",
"-if Decimal(a) ** Decimal(\"0.5\") + Decimal(b) ** Decimal(\"0.5\") < Decimal(c) ** Decimal(",
"+if decimal.Decimal(a) ** decimal.Decimal(\"0.5\") + decimal.Decimal(b) ** decimal.Decimal(",
"-):",
"+) < decimal.Decimal(c) ** decimal.Decimal(\"0.5\"):"
] | false | 0.085267 | 0.043982 | 1.93868 | [
"s399104468",
"s535996187"
] |
u731368968 | p03061 | python | s057016039 | s860412554 | 249 | 225 | 14,400 | 14,080 | Accepted | Accepted | 9.64 | n = int(eval(input()))
a = list(map(int, input().split()))
from fractions import gcd
tl = [a[0]]
for i in range(1, n):
tl.append(gcd(tl[i - 1], a[i]))
tr = [a[n - 1]]
for i in range(1, n):
tr.append(gcd(tr[i - 1], a[n - 1 - i]))
tr.reverse()
ans = 1
for i in range(n):
tmp = 1
l = tl[i - 1] if 0 < i else tr[i + 1]
r = tr[i + 1] if i < n - 1 else tl[i - 1]
ans = max(ans, gcd(l, r))
print(ans)
| n = int(eval(input()))
a = list(map(int, input().split()))
from fractions import gcd
l = [a[0]]
for i in range(1, n):
l.append(gcd(l[i - 1], a[i]))
r = [a[n - 1]]
for i in range(1, n):
r.append(gcd(r[i - 1], a[n - 1 - i]))
r.reverse()
from functools import reduce
print((reduce(lambda x,y:max(x,y),[gcd(l[i-1]if 0<i else r[i+1],r[i+1] if i<n-1 else l[i-1])for i in range(n)]))) | 21 | 15 | 436 | 395 | n = int(eval(input()))
a = list(map(int, input().split()))
from fractions import gcd
tl = [a[0]]
for i in range(1, n):
tl.append(gcd(tl[i - 1], a[i]))
tr = [a[n - 1]]
for i in range(1, n):
tr.append(gcd(tr[i - 1], a[n - 1 - i]))
tr.reverse()
ans = 1
for i in range(n):
tmp = 1
l = tl[i - 1] if 0 < i else tr[i + 1]
r = tr[i + 1] if i < n - 1 else tl[i - 1]
ans = max(ans, gcd(l, r))
print(ans)
| n = int(eval(input()))
a = list(map(int, input().split()))
from fractions import gcd
l = [a[0]]
for i in range(1, n):
l.append(gcd(l[i - 1], a[i]))
r = [a[n - 1]]
for i in range(1, n):
r.append(gcd(r[i - 1], a[n - 1 - i]))
r.reverse()
from functools import reduce
print(
(
reduce(
lambda x, y: max(x, y),
[
gcd(
l[i - 1] if 0 < i else r[i + 1], r[i + 1] if i < n - 1 else l[i - 1]
)
for i in range(n)
],
)
)
)
| false | 28.571429 | [
"-tl = [a[0]]",
"+l = [a[0]]",
"- tl.append(gcd(tl[i - 1], a[i]))",
"-tr = [a[n - 1]]",
"+ l.append(gcd(l[i - 1], a[i]))",
"+r = [a[n - 1]]",
"- tr.append(gcd(tr[i - 1], a[n - 1 - i]))",
"-tr.reverse()",
"-ans = 1",
"-for i in range(n):",
"- tmp = 1",
"- l = tl[i - 1] if 0 < i else tr[i + 1]",
"- r = tr[i + 1] if i < n - 1 else tl[i - 1]",
"- ans = max(ans, gcd(l, r))",
"-print(ans)",
"+ r.append(gcd(r[i - 1], a[n - 1 - i]))",
"+r.reverse()",
"+from functools import reduce",
"+",
"+print(",
"+ (",
"+ reduce(",
"+ lambda x, y: max(x, y),",
"+ [",
"+ gcd(",
"+ l[i - 1] if 0 < i else r[i + 1], r[i + 1] if i < n - 1 else l[i - 1]",
"+ )",
"+ for i in range(n)",
"+ ],",
"+ )",
"+ )",
"+)"
] | false | 0.046837 | 0.04716 | 0.993151 | [
"s057016039",
"s860412554"
] |
u016881126 | p02603 | python | s277252162 | s992656096 | 32 | 28 | 9,304 | 9,172 | Accepted | Accepted | 12.5 | #!/usr/bin/env python3
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')
N = int(eval(input()))
A = list(map(int, input().split()))
# どこで反転するかを記録する
pre = [0] * N
pre_index = 0
old_a = A[0]
if A[0] > A[1]:
old_coef = -1
elif A[0] < A[1]:
old_coef = 1
else:
old_coef = 0
for i in range(1, N):
if A[i] > old_a:
coef = 1
elif A[i] < old_a:
coef = -1
else:
coef = 0
if coef != 0 and coef != old_coef:
for j in range(pre_index, i):
pre[j] = i - 1
pre_index = i
old_coef = coef
old_a = A[i]
for j in range(pre_index, N):
pre[j] = N - 1
# print("pre: {}".format(pre))
shojikin = 1000
stock = 0
if A[0] < A[pre[0]]:
q, mod = divmod(shojikin, A[0])
stock += q
shojikin = mod
elif pre[0] == N - 1:
# 何もしないほうが良い場合
print('1000')
quit()
# print("1st shojikin: {} stock: {}".format(shojikin, stock))
pre = list(set(pre))
pre.sort()
# print("sorted: {}".format(pre))
for deal_index in pre:
if stock:
shojikin += stock * A[deal_index]
stock = 0
# print("uri deal: {} shojikin: {} stock: {}".format(deal_index, shojikin, stock))
else:
q, mod = divmod(shojikin, A[deal_index])
stock += q
shojikin = mod
# print("kai deal: {} shojikin: {} stock: {}".format(deal_index, shojikin, stock))
# 下がり続けた場合は払い戻し
if stock:
shojikin += stock * A[deal_index]
stock = 0
print(shojikin) | #!/usr/bin/env python3
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')
N = int(eval(input()))
A = list(map(int, input().split()))
shojikin = 1000
stock = 0
for i in range(N):
if stock:
shojikin += stock * A[i]
stock = 0
if i+1 < N:
if A[i] < A[i+1]:
q, mod = divmod(shojikin, A[i])
stock = q
shojikin = mod
print(shojikin)
| 70 | 24 | 1,629 | 529 | #!/usr/bin/env python3
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10**7)
INF = float("inf")
N = int(eval(input()))
A = list(map(int, input().split()))
# どこで反転するかを記録する
pre = [0] * N
pre_index = 0
old_a = A[0]
if A[0] > A[1]:
old_coef = -1
elif A[0] < A[1]:
old_coef = 1
else:
old_coef = 0
for i in range(1, N):
if A[i] > old_a:
coef = 1
elif A[i] < old_a:
coef = -1
else:
coef = 0
if coef != 0 and coef != old_coef:
for j in range(pre_index, i):
pre[j] = i - 1
pre_index = i
old_coef = coef
old_a = A[i]
for j in range(pre_index, N):
pre[j] = N - 1
# print("pre: {}".format(pre))
shojikin = 1000
stock = 0
if A[0] < A[pre[0]]:
q, mod = divmod(shojikin, A[0])
stock += q
shojikin = mod
elif pre[0] == N - 1:
# 何もしないほうが良い場合
print("1000")
quit()
# print("1st shojikin: {} stock: {}".format(shojikin, stock))
pre = list(set(pre))
pre.sort()
# print("sorted: {}".format(pre))
for deal_index in pre:
if stock:
shojikin += stock * A[deal_index]
stock = 0
# print("uri deal: {} shojikin: {} stock: {}".format(deal_index, shojikin, stock))
else:
q, mod = divmod(shojikin, A[deal_index])
stock += q
shojikin = mod
# print("kai deal: {} shojikin: {} stock: {}".format(deal_index, shojikin, stock))
# 下がり続けた場合は払い戻し
if stock:
shojikin += stock * A[deal_index]
stock = 0
print(shojikin)
| #!/usr/bin/env python3
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10**7)
INF = float("inf")
N = int(eval(input()))
A = list(map(int, input().split()))
shojikin = 1000
stock = 0
for i in range(N):
if stock:
shojikin += stock * A[i]
stock = 0
if i + 1 < N:
if A[i] < A[i + 1]:
q, mod = divmod(shojikin, A[i])
stock = q
shojikin = mod
print(shojikin)
| false | 65.714286 | [
"-# どこで反転するかを記録する",
"-pre = [0] * N",
"-pre_index = 0",
"-old_a = A[0]",
"-if A[0] > A[1]:",
"- old_coef = -1",
"-elif A[0] < A[1]:",
"- old_coef = 1",
"-else:",
"- old_coef = 0",
"-for i in range(1, N):",
"- if A[i] > old_a:",
"- coef = 1",
"- elif A[i] < old_a:",
"- coef = -1",
"- else:",
"- coef = 0",
"- if coef != 0 and coef != old_coef:",
"- for j in range(pre_index, i):",
"- pre[j] = i - 1",
"- pre_index = i",
"- old_coef = coef",
"- old_a = A[i]",
"-for j in range(pre_index, N):",
"- pre[j] = N - 1",
"-# print(\"pre: {}\".format(pre))",
"-if A[0] < A[pre[0]]:",
"- q, mod = divmod(shojikin, A[0])",
"- stock += q",
"- shojikin = mod",
"-elif pre[0] == N - 1:",
"- # 何もしないほうが良い場合",
"- print(\"1000\")",
"- quit()",
"-# print(\"1st shojikin: {} stock: {}\".format(shojikin, stock))",
"-pre = list(set(pre))",
"-pre.sort()",
"-# print(\"sorted: {}\".format(pre))",
"-for deal_index in pre:",
"+for i in range(N):",
"- shojikin += stock * A[deal_index]",
"+ shojikin += stock * A[i]",
"- # print(\"uri deal: {} shojikin: {} stock: {}\".format(deal_index, shojikin, stock))",
"- else:",
"- q, mod = divmod(shojikin, A[deal_index])",
"- stock += q",
"- shojikin = mod",
"- # print(\"kai deal: {} shojikin: {} stock: {}\".format(deal_index, shojikin, stock))",
"-# 下がり続けた場合は払い戻し",
"-if stock:",
"- shojikin += stock * A[deal_index]",
"- stock = 0",
"+ if i + 1 < N:",
"+ if A[i] < A[i + 1]:",
"+ q, mod = divmod(shojikin, A[i])",
"+ stock = q",
"+ shojikin = mod"
] | false | 0.042075 | 0.041367 | 1.017115 | [
"s277252162",
"s992656096"
] |
u353919145 | p03261 | python | s096239677 | s404373332 | 19 | 17 | 3,064 | 2,940 | Accepted | Accepted | 10.53 | x=int(eval(input()))
words=[]
found=0
word_1=''
word_2=''
for i in range(x):
words.append(eval(input()))
for j in range(x-1):
for k in range(j+1,x):
if words[j]==words[k]:
found=-1
for c in range(x-1):
word_1=words[c]
word_2=words[c+1]
if word_1[-1]!=word_2[0]:
found=-1
if found==-1:
print("No")
else:
print("Yes") | def taka():
n = int(eval(input()))
listofwords =[]
for i in range(n):
strTEMP = eval(input())
if i == 0:
listofwords.append(strTEMP)
continue
else:
if strTEMP in listofwords:
return "No"
else:
cmp = listofwords[-1]
if strTEMP[0] != cmp[-1]:
return "No"
else:
listofwords.append(strTEMP)
return "Yes"
print((taka()))
| 21 | 21 | 380 | 516 | x = int(eval(input()))
words = []
found = 0
word_1 = ""
word_2 = ""
for i in range(x):
words.append(eval(input()))
for j in range(x - 1):
for k in range(j + 1, x):
if words[j] == words[k]:
found = -1
for c in range(x - 1):
word_1 = words[c]
word_2 = words[c + 1]
if word_1[-1] != word_2[0]:
found = -1
if found == -1:
print("No")
else:
print("Yes")
| def taka():
n = int(eval(input()))
listofwords = []
for i in range(n):
strTEMP = eval(input())
if i == 0:
listofwords.append(strTEMP)
continue
else:
if strTEMP in listofwords:
return "No"
else:
cmp = listofwords[-1]
if strTEMP[0] != cmp[-1]:
return "No"
else:
listofwords.append(strTEMP)
return "Yes"
print((taka()))
| false | 0 | [
"-x = int(eval(input()))",
"-words = []",
"-found = 0",
"-word_1 = \"\"",
"-word_2 = \"\"",
"-for i in range(x):",
"- words.append(eval(input()))",
"-for j in range(x - 1):",
"- for k in range(j + 1, x):",
"- if words[j] == words[k]:",
"- found = -1",
"-for c in range(x - 1):",
"- word_1 = words[c]",
"- word_2 = words[c + 1]",
"- if word_1[-1] != word_2[0]:",
"- found = -1",
"-if found == -1:",
"- print(\"No\")",
"-else:",
"- print(\"Yes\")",
"+def taka():",
"+ n = int(eval(input()))",
"+ listofwords = []",
"+ for i in range(n):",
"+ strTEMP = eval(input())",
"+ if i == 0:",
"+ listofwords.append(strTEMP)",
"+ continue",
"+ else:",
"+ if strTEMP in listofwords:",
"+ return \"No\"",
"+ else:",
"+ cmp = listofwords[-1]",
"+ if strTEMP[0] != cmp[-1]:",
"+ return \"No\"",
"+ else:",
"+ listofwords.append(strTEMP)",
"+ return \"Yes\"",
"+",
"+",
"+print((taka()))"
] | false | 0.045881 | 0.045225 | 1.014508 | [
"s096239677",
"s404373332"
] |
u756388720 | p02937 | python | s209128961 | s536419178 | 200 | 157 | 133,044 | 17,896 | Accepted | Accepted | 21.5 | def next(str):
N = len(str)
nxt = [[N] * 26 for i in range(N + 1)]
for i in range(N - 1, -1, -1):
for j in range(26):
nxt[i][j] = nxt[i + 1][j]
nxt[i][ord(str[i]) - ord('a')] = i
return nxt
def solve():
S = eval(input())
T = eval(input())
N = len(S)
M = 2 * N
S += S
nxt = next(S)
ans = -1
for c in T:
i = ans % N
pos = ord(c) - ord('a')
if nxt[i + 1][pos] == M:
return -1
ans += nxt[i + 1][pos] - i
return ans + 1
print((solve()))
| from bisect import bisect
def ctoi(c):
return ord(c) - ord('a')
def solve():
S = eval(input())
T = eval(input())
N = len(S)
idx = [[] for i in range(26)]
for i in range(2 * N):
idx[ctoi(S[i % N])].append(i)
ans = -1
for c in T:
if not idx[ctoi(c)]:
return -1
ans += idx[ctoi(c)][bisect(idx[ctoi(c)], ans % N)] - ans % N
return ans + 1
print((solve()))
| 26 | 19 | 569 | 430 | def next(str):
N = len(str)
nxt = [[N] * 26 for i in range(N + 1)]
for i in range(N - 1, -1, -1):
for j in range(26):
nxt[i][j] = nxt[i + 1][j]
nxt[i][ord(str[i]) - ord("a")] = i
return nxt
def solve():
S = eval(input())
T = eval(input())
N = len(S)
M = 2 * N
S += S
nxt = next(S)
ans = -1
for c in T:
i = ans % N
pos = ord(c) - ord("a")
if nxt[i + 1][pos] == M:
return -1
ans += nxt[i + 1][pos] - i
return ans + 1
print((solve()))
| from bisect import bisect
def ctoi(c):
return ord(c) - ord("a")
def solve():
S = eval(input())
T = eval(input())
N = len(S)
idx = [[] for i in range(26)]
for i in range(2 * N):
idx[ctoi(S[i % N])].append(i)
ans = -1
for c in T:
if not idx[ctoi(c)]:
return -1
ans += idx[ctoi(c)][bisect(idx[ctoi(c)], ans % N)] - ans % N
return ans + 1
print((solve()))
| false | 26.923077 | [
"-def next(str):",
"- N = len(str)",
"- nxt = [[N] * 26 for i in range(N + 1)]",
"- for i in range(N - 1, -1, -1):",
"- for j in range(26):",
"- nxt[i][j] = nxt[i + 1][j]",
"- nxt[i][ord(str[i]) - ord(\"a\")] = i",
"- return nxt",
"+from bisect import bisect",
"+",
"+",
"+def ctoi(c):",
"+ return ord(c) - ord(\"a\")",
"- M = 2 * N",
"- S += S",
"- nxt = next(S)",
"+ idx = [[] for i in range(26)]",
"+ for i in range(2 * N):",
"+ idx[ctoi(S[i % N])].append(i)",
"- i = ans % N",
"- pos = ord(c) - ord(\"a\")",
"- if nxt[i + 1][pos] == M:",
"+ if not idx[ctoi(c)]:",
"- ans += nxt[i + 1][pos] - i",
"+ ans += idx[ctoi(c)][bisect(idx[ctoi(c)], ans % N)] - ans % N"
] | false | 0.03734 | 0.126681 | 0.294755 | [
"s209128961",
"s536419178"
] |
u596276291 | p03625 | python | s826265601 | s621066393 | 146 | 81 | 22,436 | 18,700 | Accepted | Accepted | 44.52 | from collections import defaultdict, Counter
from itertools import product, groupby, count
from math import pi
from collections import deque
from bisect import bisect, bisect_left, bisect_right
INF = 10 ** 10
def main():
N = int(eval(input()))
A_list = list(map(int, input().split()))
c = Counter(A_list)
x = []
for length, n in sorted(list(c.items()), key=lambda x: x[0], reverse=True):
if n >= 4:
x += [length] * 4
elif n >= 2:
x += [length] * 2
x += [0] * 4
print((x[0] * x[2]))
if __name__ == '__main__':
main()
| from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]
def inside(y, x, H, W):
return 0 <= y < H and 0 <= x < W
def ceil(a, b):
return (a + b - 1) // b
def main():
N = int(eval(input()))
C = Counter(list(map(int, input().split())))
s1 = list(sorted([k for k, v in list(C.items()) if v >= 2], reverse=True))
s2 = list(sorted([k for k, v in list(C.items()) if v >= 4], reverse=True))
ans = 0
if len(s1) >= 2:
ans = max(ans, s1[0] * s1[1])
if len(s2) >= 1:
ans = max(ans, s2[0] ** 2)
print(ans)
if __name__ == '__main__':
main()
| 24 | 39 | 601 | 1,088 | from collections import defaultdict, Counter
from itertools import product, groupby, count
from math import pi
from collections import deque
from bisect import bisect, bisect_left, bisect_right
INF = 10**10
def main():
N = int(eval(input()))
A_list = list(map(int, input().split()))
c = Counter(A_list)
x = []
for length, n in sorted(list(c.items()), key=lambda x: x[0], reverse=True):
if n >= 4:
x += [length] * 4
elif n >= 2:
x += [length] * 2
x += [0] * 4
print((x[0] * x[2]))
if __name__ == "__main__":
main()
| from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]
def inside(y, x, H, W):
return 0 <= y < H and 0 <= x < W
def ceil(a, b):
return (a + b - 1) // b
def main():
N = int(eval(input()))
C = Counter(list(map(int, input().split())))
s1 = list(sorted([k for k, v in list(C.items()) if v >= 2], reverse=True))
s2 = list(sorted([k for k, v in list(C.items()) if v >= 4], reverse=True))
ans = 0
if len(s1) >= 2:
ans = max(ans, s1[0] * s1[1])
if len(s2) >= 1:
ans = max(ans, s2[0] ** 2)
print(ans)
if __name__ == "__main__":
main()
| false | 38.461538 | [
"-from itertools import product, groupby, count",
"-from math import pi",
"+from itertools import product, groupby, count, permutations, combinations",
"+from math import pi, sqrt",
"+from string import ascii_lowercase",
"+from functools import lru_cache",
"+import sys",
"-INF = 10**10",
"+sys.setrecursionlimit(10000)",
"+INF = float(\"inf\")",
"+YES, Yes, yes, NO, No, no = \"YES\", \"Yes\", \"yes\", \"NO\", \"No\", \"no\"",
"+dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]",
"+dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]",
"+",
"+",
"+def inside(y, x, H, W):",
"+ return 0 <= y < H and 0 <= x < W",
"+",
"+",
"+def ceil(a, b):",
"+ return (a + b - 1) // b",
"- A_list = list(map(int, input().split()))",
"- c = Counter(A_list)",
"- x = []",
"- for length, n in sorted(list(c.items()), key=lambda x: x[0], reverse=True):",
"- if n >= 4:",
"- x += [length] * 4",
"- elif n >= 2:",
"- x += [length] * 2",
"- x += [0] * 4",
"- print((x[0] * x[2]))",
"+ C = Counter(list(map(int, input().split())))",
"+ s1 = list(sorted([k for k, v in list(C.items()) if v >= 2], reverse=True))",
"+ s2 = list(sorted([k for k, v in list(C.items()) if v >= 4], reverse=True))",
"+ ans = 0",
"+ if len(s1) >= 2:",
"+ ans = max(ans, s1[0] * s1[1])",
"+ if len(s2) >= 1:",
"+ ans = max(ans, s2[0] ** 2)",
"+ print(ans)"
] | false | 0.046736 | 0.159157 | 0.293646 | [
"s826265601",
"s621066393"
] |
u864197622 | p03090 | python | s383318112 | s617397716 | 233 | 24 | 43,248 | 3,612 | Accepted | Accepted | 89.7 | N = int(eval(input()))
c = 0
ANS = []
for i in range(N):
for j in range(i+1, N):
if i+j+2 != (N if N % 2 else N+1):
c += 1
ANS.append((i+1, j+1))
print(c)
for ans in ANS:
print((*ans)) | N = int(eval(input()))
if N & 1:
print(((N-1)**2//2))
for i in range(N):
for j in range(i+1, N):
if i + j == N - 2 and j < N - 1: continue
print((i+1, j+1))
else:
print((N*N//2-N))
for i in range(N):
for j in range(i+1, N):
if i + j == N - 1: continue
print((i+1, j+1))
| 14 | 13 | 232 | 348 | N = int(eval(input()))
c = 0
ANS = []
for i in range(N):
for j in range(i + 1, N):
if i + j + 2 != (N if N % 2 else N + 1):
c += 1
ANS.append((i + 1, j + 1))
print(c)
for ans in ANS:
print((*ans))
| N = int(eval(input()))
if N & 1:
print(((N - 1) ** 2 // 2))
for i in range(N):
for j in range(i + 1, N):
if i + j == N - 2 and j < N - 1:
continue
print((i + 1, j + 1))
else:
print((N * N // 2 - N))
for i in range(N):
for j in range(i + 1, N):
if i + j == N - 1:
continue
print((i + 1, j + 1))
| false | 7.142857 | [
"-c = 0",
"-ANS = []",
"-for i in range(N):",
"- for j in range(i + 1, N):",
"- if i + j + 2 != (N if N % 2 else N + 1):",
"- c += 1",
"- ANS.append((i + 1, j + 1))",
"-print(c)",
"-for ans in ANS:",
"- print((*ans))",
"+if N & 1:",
"+ print(((N - 1) ** 2 // 2))",
"+ for i in range(N):",
"+ for j in range(i + 1, N):",
"+ if i + j == N - 2 and j < N - 1:",
"+ continue",
"+ print((i + 1, j + 1))",
"+else:",
"+ print((N * N // 2 - N))",
"+ for i in range(N):",
"+ for j in range(i + 1, N):",
"+ if i + j == N - 1:",
"+ continue",
"+ print((i + 1, j + 1))"
] | false | 0.124548 | 0.036546 | 3.40797 | [
"s383318112",
"s617397716"
] |
u312025627 | p02741 | python | s365758454 | s394041193 | 165 | 18 | 38,384 | 3,060 | Accepted | Accepted | 89.09 | def main():
A = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
N = int(eval(input()))
print((A[N-1]))
if __name__ == '__main__':
main()
| def main():
A = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K = int(eval(input()))
print((A[K-1]))
if __name__ == '__main__':
main()
| 9 | 9 | 216 | 216 | def main():
A = [
1,
1,
1,
2,
1,
2,
1,
5,
2,
2,
1,
5,
1,
2,
1,
14,
1,
5,
1,
5,
2,
2,
1,
15,
2,
2,
5,
4,
1,
4,
1,
51,
]
N = int(eval(input()))
print((A[N - 1]))
if __name__ == "__main__":
main()
| def main():
A = [
1,
1,
1,
2,
1,
2,
1,
5,
2,
2,
1,
5,
1,
2,
1,
14,
1,
5,
1,
5,
2,
2,
1,
15,
2,
2,
5,
4,
1,
4,
1,
51,
]
K = int(eval(input()))
print((A[K - 1]))
if __name__ == "__main__":
main()
| false | 0 | [
"- N = int(eval(input()))",
"- print((A[N - 1]))",
"+ K = int(eval(input()))",
"+ print((A[K - 1]))"
] | false | 0.05066 | 0.035193 | 1.439493 | [
"s365758454",
"s394041193"
] |
u627234757 | p02613 | python | s742474594 | s122784990 | 238 | 137 | 9,028 | 16,144 | Accepted | Accepted | 42.44 | n = int(eval(input()))
ac = 0
wa = 0
tle = 0
re = 0
for i in range(n):
s = eval(input())
if s == 'AC':
ac += 1
elif s == 'WA':
wa += 1
elif s== 'TLE':
tle += 1
elif s== 'RE':
re += 1
print(('AC x '+str(ac)))
print(('WA x '+str(wa)))
print(('TLE x '+str(tle)))
print(('RE x '+str(re))) | n=int(eval(input()))
s=[eval(input())for _ in range(n)]
print(("AC x",s.count("AC")))
print(("WA x",s.count("WA")))
print(("TLE x",s.count("TLE")))
print(("RE x",s.count("RE")))
| 19 | 6 | 312 | 163 | n = int(eval(input()))
ac = 0
wa = 0
tle = 0
re = 0
for i in range(n):
s = eval(input())
if s == "AC":
ac += 1
elif s == "WA":
wa += 1
elif s == "TLE":
tle += 1
elif s == "RE":
re += 1
print(("AC x " + str(ac)))
print(("WA x " + str(wa)))
print(("TLE x " + str(tle)))
print(("RE x " + str(re)))
| n = int(eval(input()))
s = [eval(input()) for _ in range(n)]
print(("AC x", s.count("AC")))
print(("WA x", s.count("WA")))
print(("TLE x", s.count("TLE")))
print(("RE x", s.count("RE")))
| false | 68.421053 | [
"-ac = 0",
"-wa = 0",
"-tle = 0",
"-re = 0",
"-for i in range(n):",
"- s = eval(input())",
"- if s == \"AC\":",
"- ac += 1",
"- elif s == \"WA\":",
"- wa += 1",
"- elif s == \"TLE\":",
"- tle += 1",
"- elif s == \"RE\":",
"- re += 1",
"-print((\"AC x \" + str(ac)))",
"-print((\"WA x \" + str(wa)))",
"-print((\"TLE x \" + str(tle)))",
"-print((\"RE x \" + str(re)))",
"+s = [eval(input()) for _ in range(n)]",
"+print((\"AC x\", s.count(\"AC\")))",
"+print((\"WA x\", s.count(\"WA\")))",
"+print((\"TLE x\", s.count(\"TLE\")))",
"+print((\"RE x\", s.count(\"RE\")))"
] | false | 0.082068 | 0.044029 | 1.863965 | [
"s742474594",
"s122784990"
] |
u623687794 | p03108 | python | s103665124 | s368712653 | 996 | 832 | 48,204 | 48,144 | Accepted | Accepted | 16.47 | import sys
sys.setrecursionlimit(100003)
n,m=list(map(int,input().split()))
bridges=[list(map(int,input().split())) for i in range(m)][::-1]
inconv=[n*(n-1)//2]*m
class UnionFind(object):
def __init__(self, N):
self.parent = [i for i in range(N)]
self.size = [1 for i in range(N)]
def merge(self, a, b):
if self.issame(a,b):
return
pa = self.root(a)
pb = self.root(b)
self.parent[pa] = pb
self.size[pb] += self.size[pa]
def root(self, x):
p = self.parent[x]
if p == x:
return x
else:
r = self.root(p)
self.parent[x] = r
return r
def issame(self, x, y):
return self.root(x) == self.root(y)
def getsize(self, x):
return self.size[self.root(x)]
uf = UnionFind(n)
for i in range(m-1):
if uf.issame(bridges[i][0]-1,bridges[i][1]-1):
inconv[i+1]=inconv[i]
continue
inconv[i+1]=inconv[i]-uf.getsize(bridges[i][0]-1)*uf.getsize(bridges[i][1]-1)
uf.merge(bridges[i][0]-1,bridges[i][1]-1)
for i in range(m):
print((inconv[m-i-1])) | import sys
sys.setrecursionlimit(1000003)
input=sys.stdin.readline
n,m=list(map(int,input().split()))
bridges=[list(map(int,input().split())) for i in range(m)][::-1]
inconv=[n*(n-1)//2]*m
class UnionFind(object):
def __init__(self, N):
self.parent = [i for i in range(N)]
self.size = [1 for i in range(N)]
def merge(self, a, b):
if self.issame(a,b):
return
pa = self.root(a)
pb = self.root(b)
self.parent[pa] = pb
self.size[pb] += self.size[pa]
def root(self, x):
p = self.parent[x]
if p == x:
return x
else:
r = self.root(p)
self.parent[x] = r
return r
def issame(self, x, y):
return self.root(x) == self.root(y)
def getsize(self, x):
return self.size[self.root(x)]
uf = UnionFind(n)
for i in range(m-1):
if uf.issame(bridges[i][0]-1,bridges[i][1]-1):
inconv[i+1]=inconv[i]
continue
inconv[i+1]=inconv[i]-uf.getsize(bridges[i][0]-1)*uf.getsize(bridges[i][1]-1)
uf.merge(bridges[i][0]-1,bridges[i][1]-1)
for i in range(m):
print((inconv[m-i-1]))
| 41 | 42 | 1,181 | 1,209 | import sys
sys.setrecursionlimit(100003)
n, m = list(map(int, input().split()))
bridges = [list(map(int, input().split())) for i in range(m)][::-1]
inconv = [n * (n - 1) // 2] * m
class UnionFind(object):
def __init__(self, N):
self.parent = [i for i in range(N)]
self.size = [1 for i in range(N)]
def merge(self, a, b):
if self.issame(a, b):
return
pa = self.root(a)
pb = self.root(b)
self.parent[pa] = pb
self.size[pb] += self.size[pa]
def root(self, x):
p = self.parent[x]
if p == x:
return x
else:
r = self.root(p)
self.parent[x] = r
return r
def issame(self, x, y):
return self.root(x) == self.root(y)
def getsize(self, x):
return self.size[self.root(x)]
uf = UnionFind(n)
for i in range(m - 1):
if uf.issame(bridges[i][0] - 1, bridges[i][1] - 1):
inconv[i + 1] = inconv[i]
continue
inconv[i + 1] = inconv[i] - uf.getsize(bridges[i][0] - 1) * uf.getsize(
bridges[i][1] - 1
)
uf.merge(bridges[i][0] - 1, bridges[i][1] - 1)
for i in range(m):
print((inconv[m - i - 1]))
| import sys
sys.setrecursionlimit(1000003)
input = sys.stdin.readline
n, m = list(map(int, input().split()))
bridges = [list(map(int, input().split())) for i in range(m)][::-1]
inconv = [n * (n - 1) // 2] * m
class UnionFind(object):
def __init__(self, N):
self.parent = [i for i in range(N)]
self.size = [1 for i in range(N)]
def merge(self, a, b):
if self.issame(a, b):
return
pa = self.root(a)
pb = self.root(b)
self.parent[pa] = pb
self.size[pb] += self.size[pa]
def root(self, x):
p = self.parent[x]
if p == x:
return x
else:
r = self.root(p)
self.parent[x] = r
return r
def issame(self, x, y):
return self.root(x) == self.root(y)
def getsize(self, x):
return self.size[self.root(x)]
uf = UnionFind(n)
for i in range(m - 1):
if uf.issame(bridges[i][0] - 1, bridges[i][1] - 1):
inconv[i + 1] = inconv[i]
continue
inconv[i + 1] = inconv[i] - uf.getsize(bridges[i][0] - 1) * uf.getsize(
bridges[i][1] - 1
)
uf.merge(bridges[i][0] - 1, bridges[i][1] - 1)
for i in range(m):
print((inconv[m - i - 1]))
| false | 2.380952 | [
"-sys.setrecursionlimit(100003)",
"+sys.setrecursionlimit(1000003)",
"+input = sys.stdin.readline"
] | false | 0.057513 | 0.064223 | 0.895526 | [
"s103665124",
"s368712653"
] |
u815878613 | p02984 | python | s433616740 | s639705084 | 1,658 | 114 | 20,408 | 20,416 | Accepted | Accepted | 93.12 | N = int(eval(input()))
A = list(map(int, input().split()))
ans = [0 for _ in range(N)]
sign = 1
for a in A:
ans[0] += sign * a
sign *= -1
for i in range(1, N):
ans[i] = 2 * A[0] - ans[i - 1]
t = A.pop(0)
A.append(t)
print((*ans))
| N = int(eval(input()))
A = list(map(int, input().split()))
ans = [0 for _ in range(N)]
sign = 1
for a in A:
ans[0] += sign * a
sign *= -1
for i in range(1, N):
ans[i] = 2 * A[i-1] - ans[i - 1]
print((*ans))
"""
ダム1: 2( a1 - a2 + a3 )
ダム2: 2( a2 - a3 + a1 )
ダム3: 2( a3 - a1 + a2 )
"""
| 18 | 21 | 265 | 314 | N = int(eval(input()))
A = list(map(int, input().split()))
ans = [0 for _ in range(N)]
sign = 1
for a in A:
ans[0] += sign * a
sign *= -1
for i in range(1, N):
ans[i] = 2 * A[0] - ans[i - 1]
t = A.pop(0)
A.append(t)
print((*ans))
| N = int(eval(input()))
A = list(map(int, input().split()))
ans = [0 for _ in range(N)]
sign = 1
for a in A:
ans[0] += sign * a
sign *= -1
for i in range(1, N):
ans[i] = 2 * A[i - 1] - ans[i - 1]
print((*ans))
"""
ダム1: 2( a1 - a2 + a3 )
ダム2: 2( a2 - a3 + a1 )
ダム3: 2( a3 - a1 + a2 )
"""
| false | 14.285714 | [
"- ans[i] = 2 * A[0] - ans[i - 1]",
"- t = A.pop(0)",
"- A.append(t)",
"+ ans[i] = 2 * A[i - 1] - ans[i - 1]",
"+\"\"\"",
"+ダム1: 2( a1 - a2 + a3 )",
"+ダム2: 2( a2 - a3 + a1 )",
"+ダム3: 2( a3 - a1 + a2 )",
"+\"\"\""
] | false | 0.145548 | 0.034813 | 4.18078 | [
"s433616740",
"s639705084"
] |
u858748695 | p03037 | python | s529773364 | s673611491 | 419 | 229 | 7,668 | 9,140 | Accepted | Accepted | 45.35 | #!/usr/bin/env python3
n, m = list(map(int, input().split()))
li = [0] * (n + 1)
for _ in range(m):
l, r = [int(x) - 1 for x in input().split()]
li[0] += 1
li[l] -= 1
li[r + 1] += 1
li[n] -= 1
for i in range(n):
li[i + 1] += li[i]
print((sum(x <= 0 for x in li[:-1])))
| n, m = list(map(int, input().split()))
ml, mr = 0, n
for i in range(m):
l, r = [int(x) - 1 for x in input().split()]
ml = max(ml, l)
mr = min(mr, r)
print((max(0, mr - ml + 1)))
| 12 | 7 | 301 | 193 | #!/usr/bin/env python3
n, m = list(map(int, input().split()))
li = [0] * (n + 1)
for _ in range(m):
l, r = [int(x) - 1 for x in input().split()]
li[0] += 1
li[l] -= 1
li[r + 1] += 1
li[n] -= 1
for i in range(n):
li[i + 1] += li[i]
print((sum(x <= 0 for x in li[:-1])))
| n, m = list(map(int, input().split()))
ml, mr = 0, n
for i in range(m):
l, r = [int(x) - 1 for x in input().split()]
ml = max(ml, l)
mr = min(mr, r)
print((max(0, mr - ml + 1)))
| false | 41.666667 | [
"-#!/usr/bin/env python3",
"-li = [0] * (n + 1)",
"-for _ in range(m):",
"+ml, mr = 0, n",
"+for i in range(m):",
"- li[0] += 1",
"- li[l] -= 1",
"- li[r + 1] += 1",
"- li[n] -= 1",
"-for i in range(n):",
"- li[i + 1] += li[i]",
"-print((sum(x <= 0 for x in li[:-1])))",
"+ ml = max(ml, l)",
"+ mr = min(mr, r)",
"+print((max(0, mr - ml + 1)))"
] | false | 0.079946 | 0.046216 | 1.729821 | [
"s529773364",
"s673611491"
] |
u737758066 | p03011 | python | s839176064 | s756712432 | 170 | 17 | 38,256 | 3,060 | Accepted | Accepted | 90 | p, q, r = list(map(int, input().split()))
print((min(p+q, q+r, p+r)))
| import itertools
p, q, r = list(map(int, input().split()))
ans = 10**18
for v in itertools.permutations([p, q, r], 2):
ans = min(ans, sum(v))
print(ans)
| 2 | 6 | 63 | 156 | p, q, r = list(map(int, input().split()))
print((min(p + q, q + r, p + r)))
| import itertools
p, q, r = list(map(int, input().split()))
ans = 10**18
for v in itertools.permutations([p, q, r], 2):
ans = min(ans, sum(v))
print(ans)
| false | 66.666667 | [
"+import itertools",
"+",
"-print((min(p + q, q + r, p + r)))",
"+ans = 10**18",
"+for v in itertools.permutations([p, q, r], 2):",
"+ ans = min(ans, sum(v))",
"+print(ans)"
] | false | 0.104479 | 0.043641 | 2.394079 | [
"s839176064",
"s756712432"
] |
u077291787 | p03044 | python | s741618537 | s274595657 | 484 | 386 | 81,564 | 42,792 | Accepted | Accepted | 20.25 | # ABC126D - Even Relation
import sys
sys.setrecursionlimit(10 ** 9)
def dfs(v: int, p: int) -> None:
for u, w in T[v]:
if u != p:
D[u] = (D[v] + w) % 2
dfs(u, v)
def main():
global T, D
N, *A = map(int, open(0).read().split())
T = [[] for _ in range(N + 1)]
for i in range(0, (N - 1) * 3, 3):
v, u, w = A[i : i + 3]
T[v] += [(u, w)]
T[u] += [(v, w)]
D = [0] * (N + 1) # D[i] := distance from vertex 1 (root)
dfs(1, -1)
print(*D[1:], sep="\n")
if __name__ == "__main__":
main()
| # ABC126D - Even Relation
def dfs(r: int) -> None:
stack = [r]
while stack:
v = stack.pop()
for u, w in T[v]:
if D[u] == -1:
D[u] = (D[v] + w) % 2
stack.append(u)
def main():
global T, D
N, *A = map(int, open(0).read().split())
T = [[] for _ in range(N + 1)]
for i in range(0, (N - 1) * 3, 3):
v, u, w = A[i : i + 3]
T[v] += [(u, w)]
T[u] += [(v, w)]
D = [-1] * (N + 1) # D[i] := parity of distance from vertex 1 (root)
D[1] = 0
dfs(1)
print(*D[1:], sep="\n")
if __name__ == "__main__":
main()
| 28 | 27 | 603 | 652 | # ABC126D - Even Relation
import sys
sys.setrecursionlimit(10**9)
def dfs(v: int, p: int) -> None:
for u, w in T[v]:
if u != p:
D[u] = (D[v] + w) % 2
dfs(u, v)
def main():
global T, D
N, *A = map(int, open(0).read().split())
T = [[] for _ in range(N + 1)]
for i in range(0, (N - 1) * 3, 3):
v, u, w = A[i : i + 3]
T[v] += [(u, w)]
T[u] += [(v, w)]
D = [0] * (N + 1) # D[i] := distance from vertex 1 (root)
dfs(1, -1)
print(*D[1:], sep="\n")
if __name__ == "__main__":
main()
| # ABC126D - Even Relation
def dfs(r: int) -> None:
stack = [r]
while stack:
v = stack.pop()
for u, w in T[v]:
if D[u] == -1:
D[u] = (D[v] + w) % 2
stack.append(u)
def main():
global T, D
N, *A = map(int, open(0).read().split())
T = [[] for _ in range(N + 1)]
for i in range(0, (N - 1) * 3, 3):
v, u, w = A[i : i + 3]
T[v] += [(u, w)]
T[u] += [(v, w)]
D = [-1] * (N + 1) # D[i] := parity of distance from vertex 1 (root)
D[1] = 0
dfs(1)
print(*D[1:], sep="\n")
if __name__ == "__main__":
main()
| false | 3.571429 | [
"-import sys",
"-",
"-sys.setrecursionlimit(10**9)",
"-",
"-",
"-def dfs(v: int, p: int) -> None:",
"- for u, w in T[v]:",
"- if u != p:",
"- D[u] = (D[v] + w) % 2",
"- dfs(u, v)",
"+def dfs(r: int) -> None:",
"+ stack = [r]",
"+ while stack:",
"+ v = stack.pop()",
"+ for u, w in T[v]:",
"+ if D[u] == -1:",
"+ D[u] = (D[v] + w) % 2",
"+ stack.append(u)",
"- D = [0] * (N + 1) # D[i] := distance from vertex 1 (root)",
"- dfs(1, -1)",
"+ D = [-1] * (N + 1) # D[i] := parity of distance from vertex 1 (root)",
"+ D[1] = 0",
"+ dfs(1)"
] | false | 0.063079 | 0.03921 | 1.608736 | [
"s741618537",
"s274595657"
] |
u317779196 | p02923 | python | s494059049 | s999060487 | 365 | 84 | 23,392 | 14,252 | Accepted | Accepted | 76.99 | import numpy as np
n = int(eval(input()))
h = np.array([int(i) for i in input().split()])
dh = np.diff(h)
ans = 0
ans_l = []
for i in range(len(dh)):
if dh[i] <= 0:
ans += 1
elif dh[i] > 0:
ans_l.append(ans)
ans = 0
ans_l.append(ans)
print((max(ans_l))) | n = int(eval(input()))
h = [int(i) for i in input().split()]
ans = 0
a = 0
for i in range(n-1):
if h[i] >= h[i+1]:
a += 1
else:
ans = max(ans, a)
a = 0
ans = max(ans, a)
print(ans) | 16 | 12 | 295 | 217 | import numpy as np
n = int(eval(input()))
h = np.array([int(i) for i in input().split()])
dh = np.diff(h)
ans = 0
ans_l = []
for i in range(len(dh)):
if dh[i] <= 0:
ans += 1
elif dh[i] > 0:
ans_l.append(ans)
ans = 0
ans_l.append(ans)
print((max(ans_l)))
| n = int(eval(input()))
h = [int(i) for i in input().split()]
ans = 0
a = 0
for i in range(n - 1):
if h[i] >= h[i + 1]:
a += 1
else:
ans = max(ans, a)
a = 0
ans = max(ans, a)
print(ans)
| false | 25 | [
"-import numpy as np",
"-",
"-h = np.array([int(i) for i in input().split()])",
"-dh = np.diff(h)",
"+h = [int(i) for i in input().split()]",
"-ans_l = []",
"-for i in range(len(dh)):",
"- if dh[i] <= 0:",
"- ans += 1",
"- elif dh[i] > 0:",
"- ans_l.append(ans)",
"- ans = 0",
"-ans_l.append(ans)",
"-print((max(ans_l)))",
"+a = 0",
"+for i in range(n - 1):",
"+ if h[i] >= h[i + 1]:",
"+ a += 1",
"+ else:",
"+ ans = max(ans, a)",
"+ a = 0",
"+ans = max(ans, a)",
"+print(ans)"
] | false | 0.481429 | 0.064159 | 7.503732 | [
"s494059049",
"s999060487"
] |
u080364835 | p02756 | python | s674101606 | s598077700 | 860 | 533 | 97,388 | 14,052 | Accepted | Accepted | 38.02 | s = list(input())
n = int(input())
head = []
tail = []
cnt = 0
for _ in range(n):
li = list(input().split())
if li[0] == '1':
head, tail = tail, head
cnt += 1
else:
if li[1] == '1':
head += li[2]
else:
tail += li[2]
if cnt % 2 != 0:
s = s[::-1]
ans = head[::-1] + s + tail
print(*ans , sep='')
| s = list(input())
n = int(input())
head = []
tail = []
cnt = 0
for _ in range(n):
li = list(input().split())
if li[0] == '1':
head, tail = tail, head
cnt += 1
else:
if li[1] == '1':
head.append(li[2])
else:
tail.append(li[2])
if cnt % 2 != 0:
s = s[::-1]
ans = head[::-1] + s + tail
print(*ans , sep='')
| 22 | 22 | 389 | 399 | s = list(input())
n = int(input())
head = []
tail = []
cnt = 0
for _ in range(n):
li = list(input().split())
if li[0] == "1":
head, tail = tail, head
cnt += 1
else:
if li[1] == "1":
head += li[2]
else:
tail += li[2]
if cnt % 2 != 0:
s = s[::-1]
ans = head[::-1] + s + tail
print(*ans, sep="")
| s = list(input())
n = int(input())
head = []
tail = []
cnt = 0
for _ in range(n):
li = list(input().split())
if li[0] == "1":
head, tail = tail, head
cnt += 1
else:
if li[1] == "1":
head.append(li[2])
else:
tail.append(li[2])
if cnt % 2 != 0:
s = s[::-1]
ans = head[::-1] + s + tail
print(*ans, sep="")
| false | 0 | [
"- head += li[2]",
"+ head.append(li[2])",
"- tail += li[2]",
"+ tail.append(li[2])"
] | false | 0.045781 | 0.046685 | 0.980643 | [
"s674101606",
"s598077700"
] |
u197300773 | p02728 | python | s824746203 | s945687245 | 2,373 | 2,060 | 176,476 | 139,612 | Accepted | Accepted | 13.19 | import sys
sys.setrecursionlimit(10**7)
def modinv(a,m=10**9+7):
if a==0: return 1
else:
b=m
(x, lastx) = (0, 1)
(y, lasty) = (1, 0)
while b != 0:
q = a // b
(a, b) = (b, a % b)
(x, lastx) = (lastx - q * x, x)
(y, lasty) = (lasty - q * y, y)
return lastx % m
def cur(p):
if neighbor[p]==[]: return
for x in neighbor[p]:
par[x]=p
neighbor[x].remove(p)
cur(x)
descend[par[p]]+=descend[p]
def cur2(p):
for x in neighbor[p]:
ans[x]=ans[p]*descend[x]*modinv(n-descend[x])
ans[x]%=mod
cur2(x)
mod=10**9+7
n=int(eval(input()))
neighbor=[set() for _ in range(n+2)]
descend=[1 for i in range(n+1)]
par=[0]+[0]*(n+1)
for _ in range(n-1):
a,b=list(map(int,input().split()))
neighbor[a].add(b)
neighbor[b].add(a)
cur(1)
ans=[1]*(n+1)
ans1=1
for i in range(1,n+1):
ans1=ans1*i*modinv(descend[i])
ans1%=mod
ans[1]=ans1
cur2(1)
for i in range(1,n+1):
print((ans[i])) | import sys
sys.setrecursionlimit(10**7)
def modinv(a,m=10**9+7):
if a==0: return 1
b=m
(x, lastx) = (0, 1)
(y, lasty) = (1, 0)
while b != 0:
q = a // b
(a, b) = (b, a % b)
(x, lastx) = (lastx - q * x, x)
(y, lasty) = (lasty - q * y, y)
return lastx % m
def cur(p):
for x in neighbor[p]:
if x==par[p]: continue
par[x]=p
descend[p]+=cur(x)
return descend[p]
def cur2(p):
for x in neighbor[p]:
if x==par[p]: continue
ans[x]=ans[p]*descend[x]*modinv(n-descend[x])%mod
cur2(x)
mod=10**9+7
n=int(eval(input()))
neighbor=[[] for _ in range(n+1)]
descend=[1]*(n+1)
par=[0]*(n+1)
for _ in range(n-1):
a,b=list(map(int,input().split()))
neighbor[a].append(b)
neighbor[b].append(a)
cur(1)
ans=[1]*(n+1)
ans1=1
for i in range(1,n+1):
ans1=ans1*i*modinv(descend[i])%mod
ans[1]=ans1
cur2(1)
for i in range(1,n+1):
print((ans[i]))
| 55 | 48 | 1,086 | 992 | import sys
sys.setrecursionlimit(10**7)
def modinv(a, m=10**9 + 7):
if a == 0:
return 1
else:
b = m
(x, lastx) = (0, 1)
(y, lasty) = (1, 0)
while b != 0:
q = a // b
(a, b) = (b, a % b)
(x, lastx) = (lastx - q * x, x)
(y, lasty) = (lasty - q * y, y)
return lastx % m
def cur(p):
if neighbor[p] == []:
return
for x in neighbor[p]:
par[x] = p
neighbor[x].remove(p)
cur(x)
descend[par[p]] += descend[p]
def cur2(p):
for x in neighbor[p]:
ans[x] = ans[p] * descend[x] * modinv(n - descend[x])
ans[x] %= mod
cur2(x)
mod = 10**9 + 7
n = int(eval(input()))
neighbor = [set() for _ in range(n + 2)]
descend = [1 for i in range(n + 1)]
par = [0] + [0] * (n + 1)
for _ in range(n - 1):
a, b = list(map(int, input().split()))
neighbor[a].add(b)
neighbor[b].add(a)
cur(1)
ans = [1] * (n + 1)
ans1 = 1
for i in range(1, n + 1):
ans1 = ans1 * i * modinv(descend[i])
ans1 %= mod
ans[1] = ans1
cur2(1)
for i in range(1, n + 1):
print((ans[i]))
| import sys
sys.setrecursionlimit(10**7)
def modinv(a, m=10**9 + 7):
if a == 0:
return 1
b = m
(x, lastx) = (0, 1)
(y, lasty) = (1, 0)
while b != 0:
q = a // b
(a, b) = (b, a % b)
(x, lastx) = (lastx - q * x, x)
(y, lasty) = (lasty - q * y, y)
return lastx % m
def cur(p):
for x in neighbor[p]:
if x == par[p]:
continue
par[x] = p
descend[p] += cur(x)
return descend[p]
def cur2(p):
for x in neighbor[p]:
if x == par[p]:
continue
ans[x] = ans[p] * descend[x] * modinv(n - descend[x]) % mod
cur2(x)
mod = 10**9 + 7
n = int(eval(input()))
neighbor = [[] for _ in range(n + 1)]
descend = [1] * (n + 1)
par = [0] * (n + 1)
for _ in range(n - 1):
a, b = list(map(int, input().split()))
neighbor[a].append(b)
neighbor[b].append(a)
cur(1)
ans = [1] * (n + 1)
ans1 = 1
for i in range(1, n + 1):
ans1 = ans1 * i * modinv(descend[i]) % mod
ans[1] = ans1
cur2(1)
for i in range(1, n + 1):
print((ans[i]))
| false | 12.727273 | [
"- else:",
"- b = m",
"- (x, lastx) = (0, 1)",
"- (y, lasty) = (1, 0)",
"- while b != 0:",
"- q = a // b",
"- (a, b) = (b, a % b)",
"- (x, lastx) = (lastx - q * x, x)",
"- (y, lasty) = (lasty - q * y, y)",
"- return lastx % m",
"+ b = m",
"+ (x, lastx) = (0, 1)",
"+ (y, lasty) = (1, 0)",
"+ while b != 0:",
"+ q = a // b",
"+ (a, b) = (b, a % b)",
"+ (x, lastx) = (lastx - q * x, x)",
"+ (y, lasty) = (lasty - q * y, y)",
"+ return lastx % m",
"- if neighbor[p] == []:",
"- return",
"+ if x == par[p]:",
"+ continue",
"- neighbor[x].remove(p)",
"- cur(x)",
"- descend[par[p]] += descend[p]",
"+ descend[p] += cur(x)",
"+ return descend[p]",
"- ans[x] = ans[p] * descend[x] * modinv(n - descend[x])",
"- ans[x] %= mod",
"+ if x == par[p]:",
"+ continue",
"+ ans[x] = ans[p] * descend[x] * modinv(n - descend[x]) % mod",
"-neighbor = [set() for _ in range(n + 2)]",
"-descend = [1 for i in range(n + 1)]",
"-par = [0] + [0] * (n + 1)",
"+neighbor = [[] for _ in range(n + 1)]",
"+descend = [1] * (n + 1)",
"+par = [0] * (n + 1)",
"- neighbor[a].add(b)",
"- neighbor[b].add(a)",
"+ neighbor[a].append(b)",
"+ neighbor[b].append(a)",
"- ans1 = ans1 * i * modinv(descend[i])",
"- ans1 %= mod",
"+ ans1 = ans1 * i * modinv(descend[i]) % mod"
] | false | 0.033208 | 0.069089 | 0.480657 | [
"s824746203",
"s945687245"
] |
u203383537 | p02995 | python | s886859171 | s971089599 | 35 | 28 | 5,076 | 9,152 | Accepted | Accepted | 20 | import fractions
def lcm(x,y):
return (x*y)//fractions.gcd(x,y)
a,b,c,d=list(map(int,input().split()))
d1=b//c
d2=b//d
d3=b//lcm(c,d)
d4=(a-1)//c
d5=(a-1)//d
d6=(a-1)//lcm(c,d)
ansb=b-(d1+d2-d3)
ansa=a-1-(d4+d5-d6)
print((ansb-ansa))
| def gcd(x,y):
if x < y:
x,y = y,x
if y == 0:
return x
else:
return gcd(y,x%y)
def lcm(x,y):
return (x*y)//gcd(x,y)
a,b,c,d = list(map(int,input().split()))
al = b-a+1
cnt_c = b//c - (a-1)//c
cnt_d = b//d - (a-1)//d
cnt_t = b//lcm(c,d) - (a-1)//lcm(c,d)
print((al - cnt_c - cnt_d + cnt_t)) | 17 | 23 | 250 | 361 | import fractions
def lcm(x, y):
return (x * y) // fractions.gcd(x, y)
a, b, c, d = list(map(int, input().split()))
d1 = b // c
d2 = b // d
d3 = b // lcm(c, d)
d4 = (a - 1) // c
d5 = (a - 1) // d
d6 = (a - 1) // lcm(c, d)
ansb = b - (d1 + d2 - d3)
ansa = a - 1 - (d4 + d5 - d6)
print((ansb - ansa))
| def gcd(x, y):
if x < y:
x, y = y, x
if y == 0:
return x
else:
return gcd(y, x % y)
def lcm(x, y):
return (x * y) // gcd(x, y)
a, b, c, d = list(map(int, input().split()))
al = b - a + 1
cnt_c = b // c - (a - 1) // c
cnt_d = b // d - (a - 1) // d
cnt_t = b // lcm(c, d) - (a - 1) // lcm(c, d)
print((al - cnt_c - cnt_d + cnt_t))
| false | 26.086957 | [
"-import fractions",
"+def gcd(x, y):",
"+ if x < y:",
"+ x, y = y, x",
"+ if y == 0:",
"+ return x",
"+ else:",
"+ return gcd(y, x % y)",
"- return (x * y) // fractions.gcd(x, y)",
"+ return (x * y) // gcd(x, y)",
"-d1 = b // c",
"-d2 = b // d",
"-d3 = b // lcm(c, d)",
"-d4 = (a - 1) // c",
"-d5 = (a - 1) // d",
"-d6 = (a - 1) // lcm(c, d)",
"-ansb = b - (d1 + d2 - d3)",
"-ansa = a - 1 - (d4 + d5 - d6)",
"-print((ansb - ansa))",
"+al = b - a + 1",
"+cnt_c = b // c - (a - 1) // c",
"+cnt_d = b // d - (a - 1) // d",
"+cnt_t = b // lcm(c, d) - (a - 1) // lcm(c, d)",
"+print((al - cnt_c - cnt_d + cnt_t))"
] | false | 0.083133 | 0.077651 | 1.070599 | [
"s886859171",
"s971089599"
] |
u596276291 | p03945 | python | s608197715 | s994381946 | 40 | 32 | 3,572 | 4,340 | Accepted | Accepted | 20 | from collections import defaultdict
def main():
s = eval(input())
ans = 0
for i in range(len(s) - 1):
if s[i] != s[i + 1]:
ans += 1
print(ans)
if __name__ == '__main__':
main()
| from collections import defaultdict
from itertools import groupby
def main():
S = eval(input())
print((len([k for k, g in groupby(S)]) - 1))
if __name__ == '__main__':
main()
| 13 | 11 | 226 | 193 | from collections import defaultdict
def main():
s = eval(input())
ans = 0
for i in range(len(s) - 1):
if s[i] != s[i + 1]:
ans += 1
print(ans)
if __name__ == "__main__":
main()
| from collections import defaultdict
from itertools import groupby
def main():
S = eval(input())
print((len([k for k, g in groupby(S)]) - 1))
if __name__ == "__main__":
main()
| false | 15.384615 | [
"+from itertools import groupby",
"- s = eval(input())",
"- ans = 0",
"- for i in range(len(s) - 1):",
"- if s[i] != s[i + 1]:",
"- ans += 1",
"- print(ans)",
"+ S = eval(input())",
"+ print((len([k for k, g in groupby(S)]) - 1))"
] | false | 0.049037 | 0.008335 | 5.88337 | [
"s608197715",
"s994381946"
] |
u926412290 | p02899 | python | s827819798 | s359260875 | 203 | 116 | 24,880 | 13,880 | Accepted | Accepted | 42.86 | N = int(input())
A = {num: i+1 for i,num in enumerate(map(int, input().split()))}
for i in range(1, N+1):
if i == N:
print(A[i])
else:
print(A[i], end=" ")
| N = int(eval(input()))
A = list(map(int, input().split()))
rev = [0] * N
for i in range(N):
rev[A[i] - 1] = i + 1
print((*rev)) | 8 | 7 | 187 | 130 | N = int(input())
A = {num: i + 1 for i, num in enumerate(map(int, input().split()))}
for i in range(1, N + 1):
if i == N:
print(A[i])
else:
print(A[i], end=" ")
| N = int(eval(input()))
A = list(map(int, input().split()))
rev = [0] * N
for i in range(N):
rev[A[i] - 1] = i + 1
print((*rev))
| false | 12.5 | [
"-N = int(input())",
"-A = {num: i + 1 for i, num in enumerate(map(int, input().split()))}",
"-for i in range(1, N + 1):",
"- if i == N:",
"- print(A[i])",
"- else:",
"- print(A[i], end=\" \")",
"+N = int(eval(input()))",
"+A = list(map(int, input().split()))",
"+rev = [0] * N",
"+for i in range(N):",
"+ rev[A[i] - 1] = i + 1",
"+print((*rev))"
] | false | 0.037966 | 0.043799 | 0.866833 | [
"s827819798",
"s359260875"
] |
u285891772 | p02744 | python | s581527899 | s215203330 | 123 | 91 | 10,640 | 10,480 | Accepted | Accepted | 26.02 | import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from 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(str, input().split()))
def ZIP(n): return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
#import numpy as np
from decimal import *
#非再帰バージョン
N = INT()
w = ["a"]
while w:
s = w.pop()
if len(s) == N:
print(s)
continue
else:
for j in range(len(set(s)), -1, -1):
t = s+ascii_lowercase[j]
w.append(t) | import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from 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(str, input().split()))
def ZIP(n): return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
#import numpy as np
from decimal import *
#再帰バージョン
N = INT()
def DFS(n):
if len(n) == N:
print(n)
else:
for i in range(len(set(n))+1):
m = n+ascii_lowercase[i]
DFS(m)
DFS("a")
| 35 | 34 | 1,143 | 1,100 | import sys, re
from collections import deque, defaultdict, Counter
from math import (
ceil,
sqrt,
hypot,
factorial,
pi,
sin,
cos,
tan,
asin,
acos,
atan,
radians,
degrees,
log2,
gcd,
)
from itertools import (
accumulate,
permutations,
combinations,
combinations_with_replacement,
product,
groupby,
)
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from 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(str, input().split()))
def ZIP(n):
return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
# import numpy as np
from decimal import *
# 非再帰バージョン
N = INT()
w = ["a"]
while w:
s = w.pop()
if len(s) == N:
print(s)
continue
else:
for j in range(len(set(s)), -1, -1):
t = s + ascii_lowercase[j]
w.append(t)
| import sys, re
from collections import deque, defaultdict, Counter
from math import (
ceil,
sqrt,
hypot,
factorial,
pi,
sin,
cos,
tan,
asin,
acos,
atan,
radians,
degrees,
log2,
gcd,
)
from itertools import (
accumulate,
permutations,
combinations,
combinations_with_replacement,
product,
groupby,
)
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from 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(str, input().split()))
def ZIP(n):
return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
# import numpy as np
from decimal import *
# 再帰バージョン
N = INT()
def DFS(n):
if len(n) == N:
print(n)
else:
for i in range(len(set(n)) + 1):
m = n + ascii_lowercase[i]
DFS(m)
DFS("a")
| false | 2.857143 | [
"-# 非再帰バージョン",
"+# 再帰バージョン",
"-w = [\"a\"]",
"-while w:",
"- s = w.pop()",
"- if len(s) == N:",
"- print(s)",
"- continue",
"+",
"+",
"+def DFS(n):",
"+ if len(n) == N:",
"+ print(n)",
"- for j in range(len(set(s)), -1, -1):",
"- t = s + ascii_lowercase[j]",
"- w.append(t)",
"+ for i in range(len(set(n)) + 1):",
"+ m = n + ascii_lowercase[i]",
"+ DFS(m)",
"+",
"+",
"+DFS(\"a\")"
] | false | 0.106449 | 0.102021 | 1.043404 | [
"s581527899",
"s215203330"
] |
u533039576 | p02686 | python | s740938628 | s058761341 | 1,998 | 1,290 | 92,056 | 91,936 | Accepted | Accepted | 35.44 | n = int(eval(input()))
s = [eval(input()) for _ in range(n)]
def bracket(x):
# f: final sum of brackets '(':+1, ')': -1
# m: min value of f
f = m = 0
for i in range(len(x)):
if x[i] == '(':
f += 1
else:
f -= 1
m = min(m, f)
# m <= 0
return f, m
def func(l):
# l = [(f, m)]
l.sort(key=lambda x: -x[1])
v = 0
for fi, mi in l:
if v + mi >= 0:
v += fi
else:
return -1
return v
l1 = []
l2 = []
for i in range(n):
fi, mi = bracket(s[i])
if fi >= 0:
l1.append((fi, mi))
else:
l2.append((-fi, mi - fi))
v1 = func(l1)
v2 = func(l2)
if v1 == -1 or v2 == -1:
ans = 'No'
else:
ans = 'Yes' if v1 == v2 else 'No'
print(ans)
| import sys
# input = sys.stdin.readline
input = lambda: sys.stdin.readline().rstrip()
n = int(eval(input()))
s = [eval(input()) for _ in range(n)]
def bracket(x):
# f: final sum of brackets '(':+1, ')': -1
# m: min value of f
f = m = 0
for i in range(len(x)):
if x[i] == '(':
f += 1
else:
f -= 1
m = min(m, f)
# m <= 0
return f, m
def func(l):
# l = [(f, m)]
l.sort(key=lambda x: -x[1])
v = 0
for fi, mi in l:
if v + mi >= 0:
v += fi
else:
return -1
return v
l1 = []
l2 = []
for i in range(n):
fi, mi = bracket(s[i])
if fi >= 0:
l1.append((fi, mi))
else:
l2.append((-fi, mi - fi))
v1 = func(l1)
v2 = func(l2)
if v1 == -1 or v2 == -1:
ans = 'No'
else:
ans = 'Yes' if v1 == v2 else 'No'
print(ans)
| 47 | 51 | 820 | 911 | n = int(eval(input()))
s = [eval(input()) for _ in range(n)]
def bracket(x):
# f: final sum of brackets '(':+1, ')': -1
# m: min value of f
f = m = 0
for i in range(len(x)):
if x[i] == "(":
f += 1
else:
f -= 1
m = min(m, f)
# m <= 0
return f, m
def func(l):
# l = [(f, m)]
l.sort(key=lambda x: -x[1])
v = 0
for fi, mi in l:
if v + mi >= 0:
v += fi
else:
return -1
return v
l1 = []
l2 = []
for i in range(n):
fi, mi = bracket(s[i])
if fi >= 0:
l1.append((fi, mi))
else:
l2.append((-fi, mi - fi))
v1 = func(l1)
v2 = func(l2)
if v1 == -1 or v2 == -1:
ans = "No"
else:
ans = "Yes" if v1 == v2 else "No"
print(ans)
| import sys
# input = sys.stdin.readline
input = lambda: sys.stdin.readline().rstrip()
n = int(eval(input()))
s = [eval(input()) for _ in range(n)]
def bracket(x):
# f: final sum of brackets '(':+1, ')': -1
# m: min value of f
f = m = 0
for i in range(len(x)):
if x[i] == "(":
f += 1
else:
f -= 1
m = min(m, f)
# m <= 0
return f, m
def func(l):
# l = [(f, m)]
l.sort(key=lambda x: -x[1])
v = 0
for fi, mi in l:
if v + mi >= 0:
v += fi
else:
return -1
return v
l1 = []
l2 = []
for i in range(n):
fi, mi = bracket(s[i])
if fi >= 0:
l1.append((fi, mi))
else:
l2.append((-fi, mi - fi))
v1 = func(l1)
v2 = func(l2)
if v1 == -1 or v2 == -1:
ans = "No"
else:
ans = "Yes" if v1 == v2 else "No"
print(ans)
| false | 7.843137 | [
"+import sys",
"+",
"+# input = sys.stdin.readline",
"+input = lambda: sys.stdin.readline().rstrip()"
] | false | 0.036633 | 0.041894 | 0.874407 | [
"s740938628",
"s058761341"
] |
u433532588 | p02981 | python | s910415898 | s842085601 | 176 | 17 | 38,384 | 2,940 | Accepted | Accepted | 90.34 | N, A, B = list(map(int, input().split()))
if N*A > B:
print(B)
else:
print((N*A)) | N, A, B = list(map(int, input().split()))
print((min(N*A, B))) | 5 | 2 | 85 | 55 | N, A, B = list(map(int, input().split()))
if N * A > B:
print(B)
else:
print((N * A))
| N, A, B = list(map(int, input().split()))
print((min(N * A, B)))
| false | 60 | [
"-if N * A > B:",
"- print(B)",
"-else:",
"- print((N * A))",
"+print((min(N * A, B)))"
] | false | 0.041163 | 0.035482 | 1.160102 | [
"s910415898",
"s842085601"
] |
u047393579 | p02862 | python | s493611819 | s281755438 | 881 | 310 | 102,028 | 118,764 | Accepted | Accepted | 64.81 | import sys
sys.setrecursionlimit(10**7)
import math
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
z = 10**9+7
X, Y = list(map(int, input().split()))
x = (-X+2*Y)/3
y = (2*X-Y)/3
if x.is_integer() and y.is_integer() and x>=0 and y>=0:
x = int(x)
y = int(y)
maximam = max(x,y)
minimam = min(x,y)
print((cmb(x+y,minimam)%z))
else:
print((0)) | import sys
sys.setrecursionlimit(10**7)
import math
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
X, Y = list(map(int, input().split()))
x = (-X+2*Y)/3
y = (2*X-Y)/3
if x.is_integer() and y.is_integer() and x>=0 and y>=0:
x = int(x)
y = int(y)
maximam = max(x,y)
minimam = min(x,y)
mod = 10**9+7 #出力の制限
N = x+y
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(x+y,minimam,mod)))
else:
print((0)) | 37 | 30 | 897 | 758 | import sys
sys.setrecursionlimit(10**7)
import math
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
z = 10**9 + 7
X, Y = list(map(int, input().split()))
x = (-X + 2 * Y) / 3
y = (2 * X - Y) / 3
if x.is_integer() and y.is_integer() and x >= 0 and y >= 0:
x = int(x)
y = int(y)
maximam = max(x, y)
minimam = min(x, y)
print((cmb(x + y, minimam) % z))
else:
print((0))
| import sys
sys.setrecursionlimit(10**7)
import math
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
X, Y = list(map(int, input().split()))
x = (-X + 2 * Y) / 3
y = (2 * X - Y) / 3
if x.is_integer() and y.is_integer() and x >= 0 and y >= 0:
x = int(x)
y = int(y)
maximam = max(x, y)
minimam = min(x, y)
mod = 10**9 + 7 # 出力の制限
N = x + y
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(x + y, minimam, mod)))
else:
print((0))
| false | 18.918919 | [
"-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",
"-z = 10**9 + 7",
"- print((cmb(x + y, minimam) % z))",
"+ mod = 10**9 + 7 # 出力の制限",
"+ N = x + y",
"+ 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(x + y, minimam, mod)))"
] | false | 0.604114 | 0.346299 | 1.744484 | [
"s493611819",
"s281755438"
] |
u121161758 | p03161 | python | s760577045 | s843408277 | 1,970 | 1,677 | 13,928 | 14,048 | Accepted | Accepted | 14.87 | N, K = list(map(int, input().split()))
h = list(map(int, input().split()))
inf = 10 ** 4 + 1
dp = [inf] * N
dp[0] = 0
for i in range(1,N):
H = h[i]
dp[i] = min( [dp[j] + abs(h[j] - H) for j in range(max(0, i-K),i)])
print((dp[-1]))
| import sys
def main():
input=sys.stdin.readline
N,K=list(map(int,input().split()))
H=list(map(int,input().split()))
if N-1<=K:
print((H[N-1]-H[0]))
return
inf=10**9+7
dp=[inf]*N
dp[0]=0
for i,h in enumerate(H):
if i==0:continue
m=inf
M=max(0,i-K)
dp[i]=min([dpt+abs(h-ht) for ht, dpt in zip(H[M:i],dp[M:i])])
print((dp[N-1]))
return
if __name__=="__main__":
main()
| 9 | 21 | 240 | 468 | N, K = list(map(int, input().split()))
h = list(map(int, input().split()))
inf = 10**4 + 1
dp = [inf] * N
dp[0] = 0
for i in range(1, N):
H = h[i]
dp[i] = min([dp[j] + abs(h[j] - H) for j in range(max(0, i - K), i)])
print((dp[-1]))
| import sys
def main():
input = sys.stdin.readline
N, K = list(map(int, input().split()))
H = list(map(int, input().split()))
if N - 1 <= K:
print((H[N - 1] - H[0]))
return
inf = 10**9 + 7
dp = [inf] * N
dp[0] = 0
for i, h in enumerate(H):
if i == 0:
continue
m = inf
M = max(0, i - K)
dp[i] = min([dpt + abs(h - ht) for ht, dpt in zip(H[M:i], dp[M:i])])
print((dp[N - 1]))
return
if __name__ == "__main__":
main()
| false | 57.142857 | [
"-N, K = list(map(int, input().split()))",
"-h = list(map(int, input().split()))",
"-inf = 10**4 + 1",
"-dp = [inf] * N",
"-dp[0] = 0",
"-for i in range(1, N):",
"- H = h[i]",
"- dp[i] = min([dp[j] + abs(h[j] - H) for j in range(max(0, i - K), i)])",
"-print((dp[-1]))",
"+import sys",
"+",
"+",
"+def main():",
"+ input = sys.stdin.readline",
"+ N, K = list(map(int, input().split()))",
"+ H = list(map(int, input().split()))",
"+ if N - 1 <= K:",
"+ print((H[N - 1] - H[0]))",
"+ return",
"+ inf = 10**9 + 7",
"+ dp = [inf] * N",
"+ dp[0] = 0",
"+ for i, h in enumerate(H):",
"+ if i == 0:",
"+ continue",
"+ m = inf",
"+ M = max(0, i - K)",
"+ dp[i] = min([dpt + abs(h - ht) for ht, dpt in zip(H[M:i], dp[M:i])])",
"+ print((dp[N - 1]))",
"+ return",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.050669 | 0.051498 | 0.983894 | [
"s760577045",
"s843408277"
] |
u858742833 | p03003 | python | s944259306 | s934263513 | 1,236 | 1,014 | 4,980 | 4,084 | Accepted | Accepted | 17.96 | def main():
mod = 10**9 + 7
N, M = list(map(int, input().split()))
S = list(map(int, input().split()))
T = list(map(int, input().split()))
u = [1] * (N + 1)
v = [1] * (N + 1)
for t in T:
for i, s in enumerate(S, 1):
if s == t:
v[i] = v[i - 1] + u[i]
else:
v[i] = v[i - 1] + u[i] - u[i - 1]
u, v = v, u
return u[-1] % mod
print((main()))
| def main():
mod = 10**9 + 7
N, M = list(map(int, input().split()))
S = list(map(int, input().split()))
T = list(map(int, input().split()))
V = [1] * N
for t in T:
p, q = 1, 1
for i, (s, v) in enumerate(zip(S, V)):
V[i] = q = v + q if s == t else v + q - p
p = v
return V[-1] % mod
print((main())) | 17 | 14 | 450 | 370 | def main():
mod = 10**9 + 7
N, M = list(map(int, input().split()))
S = list(map(int, input().split()))
T = list(map(int, input().split()))
u = [1] * (N + 1)
v = [1] * (N + 1)
for t in T:
for i, s in enumerate(S, 1):
if s == t:
v[i] = v[i - 1] + u[i]
else:
v[i] = v[i - 1] + u[i] - u[i - 1]
u, v = v, u
return u[-1] % mod
print((main()))
| def main():
mod = 10**9 + 7
N, M = list(map(int, input().split()))
S = list(map(int, input().split()))
T = list(map(int, input().split()))
V = [1] * N
for t in T:
p, q = 1, 1
for i, (s, v) in enumerate(zip(S, V)):
V[i] = q = v + q if s == t else v + q - p
p = v
return V[-1] % mod
print((main()))
| false | 17.647059 | [
"- u = [1] * (N + 1)",
"- v = [1] * (N + 1)",
"+ V = [1] * N",
"- for i, s in enumerate(S, 1):",
"- if s == t:",
"- v[i] = v[i - 1] + u[i]",
"- else:",
"- v[i] = v[i - 1] + u[i] - u[i - 1]",
"- u, v = v, u",
"- return u[-1] % mod",
"+ p, q = 1, 1",
"+ for i, (s, v) in enumerate(zip(S, V)):",
"+ V[i] = q = v + q if s == t else v + q - p",
"+ p = v",
"+ return V[-1] % mod"
] | false | 0.035213 | 0.036359 | 0.968492 | [
"s944259306",
"s934263513"
] |
u729133443 | p03227 | python | s206079069 | s015028640 | 190 | 17 | 38,384 | 2,940 | Accepted | Accepted | 91.05 | s=eval(input())
if(len(s)<3):print(s)
else:print((s[::-1])) | s=eval(input());print((s[::-1]*(len(s)-2)or s)) | 3 | 1 | 53 | 39 | s = eval(input())
if len(s) < 3:
print(s)
else:
print((s[::-1]))
| s = eval(input())
print((s[::-1] * (len(s) - 2) or s))
| false | 66.666667 | [
"-if len(s) < 3:",
"- print(s)",
"-else:",
"- print((s[::-1]))",
"+print((s[::-1] * (len(s) - 2) or s))"
] | false | 0.037494 | 0.063411 | 0.591288 | [
"s206079069",
"s015028640"
] |
u757117214 | p03607 | python | s139744622 | s105301019 | 123 | 84 | 108,956 | 22,604 | Accepted | Accepted | 31.71 | from collections import Counter
N,*A = list(map(int,open(0).read().split()))
ca = Counter(A)
copy_ca = ca.copy()
for i in list(ca.items()):
if i[1] % 2 == 0:
del copy_ca[i[0]]
print((len(copy_ca))) | from collections import defaultdict
N,*A = list(map(int,open(0).read().split()))
d = defaultdict(int) #初期値1
for a in A:
d[a] ^= 1 #0と1を反転
print((sum(d.values()))) | 8 | 6 | 210 | 164 | from collections import Counter
N, *A = list(map(int, open(0).read().split()))
ca = Counter(A)
copy_ca = ca.copy()
for i in list(ca.items()):
if i[1] % 2 == 0:
del copy_ca[i[0]]
print((len(copy_ca)))
| from collections import defaultdict
N, *A = list(map(int, open(0).read().split()))
d = defaultdict(int) # 初期値1
for a in A:
d[a] ^= 1 # 0と1を反転
print((sum(d.values())))
| false | 25 | [
"-from collections import Counter",
"+from collections import defaultdict",
"-ca = Counter(A)",
"-copy_ca = ca.copy()",
"-for i in list(ca.items()):",
"- if i[1] % 2 == 0:",
"- del copy_ca[i[0]]",
"-print((len(copy_ca)))",
"+d = defaultdict(int) # 初期値1",
"+for a in A:",
"+ d[a] ^= 1 # 0と1を反転",
"+print((sum(d.values())))"
] | false | 0.10506 | 0.072701 | 1.445096 | [
"s139744622",
"s105301019"
] |
u086503932 | p03108 | python | s707273619 | s713002489 | 684 | 392 | 18,952 | 102,724 | Accepted | Accepted | 42.69 | #!/usr/bin/env python3
import sys
class UnionFind():
def __init__(self, n):
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def main():
N, M = map(int, input().split())
A = [None] * M
B = [None] * M
for i in range(M):
A[i], B[i] = map(int, input().split())
ans = [0] * M
ans[-1] = N * (N-1) // 2
# 逆順に橋が出来ると不便さが変わるか調べる
uf = UnionFind(N)
for i in range(M-1):
# aとbが連結か調べる
a, b = A[M-1-i]-1, B[M-1-i]-1
if uf.find(a) == uf.find(b):
ans[M-i-2] = ans[M-i-1]
else:
ans[M-i-2] = ans[M-i-1] - abs(uf.parents[uf.find(a)]) * abs(uf.parents[uf.find(b)])
uf.union(a, b)
[print(a) for a in ans]
if __name__ == '__main__':
main()
| class UnionFind():
def __init__(self, n):
self.parents = list(range(n))
self.size = [1] * n
def find(self, x):
if self.parents[x] == x:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x != y:
if self.size[x] < self.size[y]:
x, y = y, x
self.parents[y] = x
self.size[x] += self.size[y]
N, M = map(int, input().split())
ab = [list(map(lambda x: int(x)-1, input().split())) for _ in range(M)]
uf = UnionFind(N)
now = N*(N-1)//2
ans = [now]
for i in range(M-1):
a = ab[M - i - 1][0]
b = ab[M - i - 1][1]
pa = uf.find(a)
pb = uf.find(b)
if pa != pb:
now -= uf.size[pa] * uf.size[pb]
uf.union(a, b)
ans.append(now)
[print(a) for a in ans[::-1]]
| 51 | 37 | 1,244 | 969 | #!/usr/bin/env python3
import sys
class UnionFind:
def __init__(self, n):
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def main():
N, M = map(int, input().split())
A = [None] * M
B = [None] * M
for i in range(M):
A[i], B[i] = map(int, input().split())
ans = [0] * M
ans[-1] = N * (N - 1) // 2
# 逆順に橋が出来ると不便さが変わるか調べる
uf = UnionFind(N)
for i in range(M - 1):
# aとbが連結か調べる
a, b = A[M - 1 - i] - 1, B[M - 1 - i] - 1
if uf.find(a) == uf.find(b):
ans[M - i - 2] = ans[M - i - 1]
else:
ans[M - i - 2] = ans[M - i - 1] - abs(uf.parents[uf.find(a)]) * abs(
uf.parents[uf.find(b)]
)
uf.union(a, b)
[print(a) for a in ans]
if __name__ == "__main__":
main()
| class UnionFind:
def __init__(self, n):
self.parents = list(range(n))
self.size = [1] * n
def find(self, x):
if self.parents[x] == x:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x != y:
if self.size[x] < self.size[y]:
x, y = y, x
self.parents[y] = x
self.size[x] += self.size[y]
N, M = map(int, input().split())
ab = [list(map(lambda x: int(x) - 1, input().split())) for _ in range(M)]
uf = UnionFind(N)
now = N * (N - 1) // 2
ans = [now]
for i in range(M - 1):
a = ab[M - i - 1][0]
b = ab[M - i - 1][1]
pa = uf.find(a)
pb = uf.find(b)
if pa != pb:
now -= uf.size[pa] * uf.size[pb]
uf.union(a, b)
ans.append(now)
[print(a) for a in ans[::-1]]
| false | 27.45098 | [
"-#!/usr/bin/env python3",
"-import sys",
"-",
"-",
"- self.parents = [-1] * n",
"+ self.parents = list(range(n))",
"+ self.size = [1] * n",
"- if self.parents[x] < 0:",
"+ if self.parents[x] == x:",
"- if x == y:",
"- return",
"- if self.parents[x] > self.parents[y]:",
"- x, y = y, x",
"- self.parents[x] += self.parents[y]",
"- self.parents[y] = x",
"+ if x != y:",
"+ if self.size[x] < self.size[y]:",
"+ x, y = y, x",
"+ self.parents[y] = x",
"+ self.size[x] += self.size[y]",
"-def main():",
"- N, M = map(int, input().split())",
"- A = [None] * M",
"- B = [None] * M",
"- for i in range(M):",
"- A[i], B[i] = map(int, input().split())",
"- ans = [0] * M",
"- ans[-1] = N * (N - 1) // 2",
"- # 逆順に橋が出来ると不便さが変わるか調べる",
"- uf = UnionFind(N)",
"- for i in range(M - 1):",
"- # aとbが連結か調べる",
"- a, b = A[M - 1 - i] - 1, B[M - 1 - i] - 1",
"- if uf.find(a) == uf.find(b):",
"- ans[M - i - 2] = ans[M - i - 1]",
"- else:",
"- ans[M - i - 2] = ans[M - i - 1] - abs(uf.parents[uf.find(a)]) * abs(",
"- uf.parents[uf.find(b)]",
"- )",
"- uf.union(a, b)",
"- [print(a) for a in ans]",
"-",
"-",
"-if __name__ == \"__main__\":",
"- main()",
"+N, M = map(int, input().split())",
"+ab = [list(map(lambda x: int(x) - 1, input().split())) for _ in range(M)]",
"+uf = UnionFind(N)",
"+now = N * (N - 1) // 2",
"+ans = [now]",
"+for i in range(M - 1):",
"+ a = ab[M - i - 1][0]",
"+ b = ab[M - i - 1][1]",
"+ pa = uf.find(a)",
"+ pb = uf.find(b)",
"+ if pa != pb:",
"+ now -= uf.size[pa] * uf.size[pb]",
"+ uf.union(a, b)",
"+ ans.append(now)",
"+[print(a) for a in ans[::-1]]"
] | false | 0.078879 | 0.037047 | 2.129158 | [
"s707273619",
"s713002489"
] |
u054729397 | p03644 | python | s752644150 | s145475279 | 19 | 17 | 2,940 | 3,060 | Accepted | Accepted | 10.53 | N=int(eval(input()))
n=1
while(2*n<=N):
n*=2
print(n) | N=int(eval(input()))
count=0
max=0
for a in range(1,N+1):
while(a%2==0):
a/=2
count+=1
if(max<count):
max=count
count=0
print((2**max)) | 7 | 14 | 59 | 179 | N = int(eval(input()))
n = 1
while 2 * n <= N:
n *= 2
print(n)
| N = int(eval(input()))
count = 0
max = 0
for a in range(1, N + 1):
while a % 2 == 0:
a /= 2
count += 1
if max < count:
max = count
count = 0
print((2**max))
| false | 50 | [
"-n = 1",
"-while 2 * n <= N:",
"- n *= 2",
"-print(n)",
"+count = 0",
"+max = 0",
"+for a in range(1, N + 1):",
"+ while a % 2 == 0:",
"+ a /= 2",
"+ count += 1",
"+ if max < count:",
"+ max = count",
"+ count = 0",
"+print((2**max))"
] | false | 0.057939 | 0.060755 | 0.953644 | [
"s752644150",
"s145475279"
] |
u073852194 | p02868 | python | s462353967 | s607451913 | 1,977 | 641 | 71,512 | 97,960 | Accepted | Accepted | 67.58 | class SegTreeMin:
"""
以下のクエリを処理する
1.update: i番目の値をxに更新する
2.get_min: 区間[l, r)の最小値を得る
"""
def __init__(self, n, INF):
"""
:param n: 要素数
:param INF: 初期値(入りうる要素より十分に大きな数)
"""
self.n = n
# nより大きい2の冪数
n2 = 1
while n2 < n:
n2 <<= 1
self.n2 = n2
self.tree = [INF] * (n2 << 1)
self.INF = INF
def update(self, i, x):
"""
i番目の値をxに更新
:param i: index(0-indexed)
:param x: update value
"""
i += self.n2
self.tree[i] = x
while i > 1:
self.tree[i >> 1] = x = min(x, self.tree[i ^ 1])
i >>= 1
def get_min(self, a, b):
"""
[a, b)の最小値を得る
:param a: index(0-indexed)
:param b: index(0-indexed)
"""
result = self.INF
# (k, l, r)
# k : 現在調べている区間のtree内index
# l, r: kが表す区間の左右端index [l, r)
q = [(1, 0, self.n2)]
while q:
k, l, r = q.pop()
if a <= l and r <= b:
result = min(result, self.tree[k])
continue
m = (l + r) // 2
k <<= 1
if a < m and l < b:
q.append((k, l, m))
if a < r and l < m:
q.append((k + 1, m, r))
return result
N,M = list(map(int,input().split()))
edges = [list(map(int,input().split())) for i in range(M)]
edges.sort()
ST = SegTreeMin(N+1,10**15)
ST.update(0,0)
for i in range(M):
min_ = ST.get_min(edges[i][0]-1,edges[i][1]-1)
if min_+edges[i][2] < ST.get_min(edges[i][1]-1,edges[i][1]):
ST.update(edges[i][1]-1,min_+edges[i][2])
if ST.get_min(N-1,N)!=10**15:
print((ST.get_min(N-1,N)))
else:print((-1)) | from heapq import heappop, heappush, heapify
class Graph(): #directed
def __init__(self, n, edge, indexed=1):
self.n = n
self.graph = [[] for _ in range(n)]
self.deg = [0 for _ in range(n)]
for e in edge:
self.graph[e[0] - indexed].append((e[1] - indexed, e[2]))
self.deg[e[1] - indexed] += 1
def dijkstra(self, s, INF=10**18, restore_to=None):
dist = [INF for _ in range(self.n)]
dist[s] = 0
heap = [(0, s)]
while heap:
cost, node = heappop(heap)
if dist[node] < cost:
continue
for adj, adjcost in self.graph[node]:
if dist[node] + adjcost < dist[adj]:
dist[adj] = dist[node] + adjcost
heappush(heap, (dist[adj], adj))
if restore_to is not None:
g = restore_to
if dist[g] == INF:
return dist, False
path = [g]
node = g
while node != s:
node = prev[node]
path.append(node)
return dist, path[::-1]
return dist
import sys
input = sys.stdin.readline
N, M = list(map(int, input().split()))
E = list()
for _ in range(M):
l, r, c = list(map(int, input().split()))
E.append((l - 1, r - 1, c))
for i in range(N - 1):
E.append((i + 1, i, 0))
g = Graph(N, E, 0)
res = g.dijkstra(0)[N - 1]
print((res if res != 10**18 else -1)) | 76 | 52 | 1,848 | 1,514 | class SegTreeMin:
"""
以下のクエリを処理する
1.update: i番目の値をxに更新する
2.get_min: 区間[l, r)の最小値を得る
"""
def __init__(self, n, INF):
"""
:param n: 要素数
:param INF: 初期値(入りうる要素より十分に大きな数)
"""
self.n = n
# nより大きい2の冪数
n2 = 1
while n2 < n:
n2 <<= 1
self.n2 = n2
self.tree = [INF] * (n2 << 1)
self.INF = INF
def update(self, i, x):
"""
i番目の値をxに更新
:param i: index(0-indexed)
:param x: update value
"""
i += self.n2
self.tree[i] = x
while i > 1:
self.tree[i >> 1] = x = min(x, self.tree[i ^ 1])
i >>= 1
def get_min(self, a, b):
"""
[a, b)の最小値を得る
:param a: index(0-indexed)
:param b: index(0-indexed)
"""
result = self.INF
# (k, l, r)
# k : 現在調べている区間のtree内index
# l, r: kが表す区間の左右端index [l, r)
q = [(1, 0, self.n2)]
while q:
k, l, r = q.pop()
if a <= l and r <= b:
result = min(result, self.tree[k])
continue
m = (l + r) // 2
k <<= 1
if a < m and l < b:
q.append((k, l, m))
if a < r and l < m:
q.append((k + 1, m, r))
return result
N, M = list(map(int, input().split()))
edges = [list(map(int, input().split())) for i in range(M)]
edges.sort()
ST = SegTreeMin(N + 1, 10**15)
ST.update(0, 0)
for i in range(M):
min_ = ST.get_min(edges[i][0] - 1, edges[i][1] - 1)
if min_ + edges[i][2] < ST.get_min(edges[i][1] - 1, edges[i][1]):
ST.update(edges[i][1] - 1, min_ + edges[i][2])
if ST.get_min(N - 1, N) != 10**15:
print((ST.get_min(N - 1, N)))
else:
print((-1))
| from heapq import heappop, heappush, heapify
class Graph: # directed
def __init__(self, n, edge, indexed=1):
self.n = n
self.graph = [[] for _ in range(n)]
self.deg = [0 for _ in range(n)]
for e in edge:
self.graph[e[0] - indexed].append((e[1] - indexed, e[2]))
self.deg[e[1] - indexed] += 1
def dijkstra(self, s, INF=10**18, restore_to=None):
dist = [INF for _ in range(self.n)]
dist[s] = 0
heap = [(0, s)]
while heap:
cost, node = heappop(heap)
if dist[node] < cost:
continue
for adj, adjcost in self.graph[node]:
if dist[node] + adjcost < dist[adj]:
dist[adj] = dist[node] + adjcost
heappush(heap, (dist[adj], adj))
if restore_to is not None:
g = restore_to
if dist[g] == INF:
return dist, False
path = [g]
node = g
while node != s:
node = prev[node]
path.append(node)
return dist, path[::-1]
return dist
import sys
input = sys.stdin.readline
N, M = list(map(int, input().split()))
E = list()
for _ in range(M):
l, r, c = list(map(int, input().split()))
E.append((l - 1, r - 1, c))
for i in range(N - 1):
E.append((i + 1, i, 0))
g = Graph(N, E, 0)
res = g.dijkstra(0)[N - 1]
print((res if res != 10**18 else -1))
| false | 31.578947 | [
"-class SegTreeMin:",
"- \"\"\"",
"- 以下のクエリを処理する",
"- 1.update: i番目の値をxに更新する",
"- 2.get_min: 区間[l, r)の最小値を得る",
"- \"\"\"",
"-",
"- def __init__(self, n, INF):",
"- \"\"\"",
"- :param n: 要素数",
"- :param INF: 初期値(入りうる要素より十分に大きな数)",
"- \"\"\"",
"- self.n = n",
"- # nより大きい2の冪数",
"- n2 = 1",
"- while n2 < n:",
"- n2 <<= 1",
"- self.n2 = n2",
"- self.tree = [INF] * (n2 << 1)",
"- self.INF = INF",
"-",
"- def update(self, i, x):",
"- \"\"\"",
"- i番目の値をxに更新",
"- :param i: index(0-indexed)",
"- :param x: update value",
"- \"\"\"",
"- i += self.n2",
"- self.tree[i] = x",
"- while i > 1:",
"- self.tree[i >> 1] = x = min(x, self.tree[i ^ 1])",
"- i >>= 1",
"-",
"- def get_min(self, a, b):",
"- \"\"\"",
"- [a, b)の最小値を得る",
"- :param a: index(0-indexed)",
"- :param b: index(0-indexed)",
"- \"\"\"",
"- result = self.INF",
"- # (k, l, r)",
"- # k : 現在調べている区間のtree内index",
"- # l, r: kが表す区間の左右端index [l, r)",
"- q = [(1, 0, self.n2)]",
"- while q:",
"- k, l, r = q.pop()",
"- if a <= l and r <= b:",
"- result = min(result, self.tree[k])",
"- continue",
"- m = (l + r) // 2",
"- k <<= 1",
"- if a < m and l < b:",
"- q.append((k, l, m))",
"- if a < r and l < m:",
"- q.append((k + 1, m, r))",
"- return result",
"+from heapq import heappop, heappush, heapify",
"+class Graph: # directed",
"+ def __init__(self, n, edge, indexed=1):",
"+ self.n = n",
"+ self.graph = [[] for _ in range(n)]",
"+ self.deg = [0 for _ in range(n)]",
"+ for e in edge:",
"+ self.graph[e[0] - indexed].append((e[1] - indexed, e[2]))",
"+ self.deg[e[1] - indexed] += 1",
"+",
"+ def dijkstra(self, s, INF=10**18, restore_to=None):",
"+ dist = [INF for _ in range(self.n)]",
"+ dist[s] = 0",
"+ heap = [(0, s)]",
"+ while heap:",
"+ cost, node = heappop(heap)",
"+ if dist[node] < cost:",
"+ continue",
"+ for adj, adjcost in self.graph[node]:",
"+ if dist[node] + adjcost < dist[adj]:",
"+ dist[adj] = dist[node] + adjcost",
"+ heappush(heap, (dist[adj], adj))",
"+ if restore_to is not None:",
"+ g = restore_to",
"+ if dist[g] == INF:",
"+ return dist, False",
"+ path = [g]",
"+ node = g",
"+ while node != s:",
"+ node = prev[node]",
"+ path.append(node)",
"+ return dist, path[::-1]",
"+ return dist",
"+",
"+",
"+import sys",
"+",
"+input = sys.stdin.readline",
"-edges = [list(map(int, input().split())) for i in range(M)]",
"-edges.sort()",
"-ST = SegTreeMin(N + 1, 10**15)",
"-ST.update(0, 0)",
"-for i in range(M):",
"- min_ = ST.get_min(edges[i][0] - 1, edges[i][1] - 1)",
"- if min_ + edges[i][2] < ST.get_min(edges[i][1] - 1, edges[i][1]):",
"- ST.update(edges[i][1] - 1, min_ + edges[i][2])",
"-if ST.get_min(N - 1, N) != 10**15:",
"- print((ST.get_min(N - 1, N)))",
"-else:",
"- print((-1))",
"+E = list()",
"+for _ in range(M):",
"+ l, r, c = list(map(int, input().split()))",
"+ E.append((l - 1, r - 1, c))",
"+for i in range(N - 1):",
"+ E.append((i + 1, i, 0))",
"+g = Graph(N, E, 0)",
"+res = g.dijkstra(0)[N - 1]",
"+print((res if res != 10**18 else -1))"
] | false | 0.036674 | 0.03922 | 0.93507 | [
"s462353967",
"s607451913"
] |
u764600134 | p04044 | python | s555301019 | s416983553 | 20 | 17 | 3,064 | 3,060 | Accepted | Accepted | 15 | # -*- coding: utf-8 -*-
"""
https://beta.atcoder.jp/contests/abc042/tasks/abc042_b
"""
import sys
from sys import stdin
input = stdin.readline
def solve(data):
data.sort()
return data
def main(args):
N, L = map(int, input().split())
data = [input().strip() for _ in range(N)]
ans = solve(data)
print(*ans, sep='')
if __name__ == '__main__':
main(sys.argv[1:])
| N, L = list(map(int, input().split()))
S = []
for i in range(N):
line = eval(input())
S.append(line)
S.sort()
print(("".join(S))) | 25 | 7 | 424 | 129 | # -*- coding: utf-8 -*-
"""
https://beta.atcoder.jp/contests/abc042/tasks/abc042_b
"""
import sys
from sys import stdin
input = stdin.readline
def solve(data):
data.sort()
return data
def main(args):
N, L = map(int, input().split())
data = [input().strip() for _ in range(N)]
ans = solve(data)
print(*ans, sep="")
if __name__ == "__main__":
main(sys.argv[1:])
| N, L = list(map(int, input().split()))
S = []
for i in range(N):
line = eval(input())
S.append(line)
S.sort()
print(("".join(S)))
| false | 72 | [
"-# -*- coding: utf-8 -*-",
"-\"\"\"",
"-https://beta.atcoder.jp/contests/abc042/tasks/abc042_b",
"-\"\"\"",
"-import sys",
"-from sys import stdin",
"-",
"-input = stdin.readline",
"-",
"-",
"-def solve(data):",
"- data.sort()",
"- return data",
"-",
"-",
"-def main(args):",
"- N, L = map(int, input().split())",
"- data = [input().strip() for _ in range(N)]",
"- ans = solve(data)",
"- print(*ans, sep=\"\")",
"-",
"-",
"-if __name__ == \"__main__\":",
"- main(sys.argv[1:])",
"+N, L = list(map(int, input().split()))",
"+S = []",
"+for i in range(N):",
"+ line = eval(input())",
"+ S.append(line)",
"+S.sort()",
"+print((\"\".join(S)))"
] | false | 0.074755 | 0.068754 | 1.087291 | [
"s555301019",
"s416983553"
] |
u764773675 | p03448 | python | s633729364 | s779358968 | 54 | 45 | 3,060 | 3,064 | Accepted | Accepted | 16.67 | # coding: utf-8
# Your code here!
a = int(eval(input()))
b = int(eval(input()))
c = int(eval(input()))
money = int(eval(input()))
count = 0
for i in range(a + 1):
for j in range(b + 1):
for k in range(c + 1):
total = i * 500 + j * 100 + k * 50
if total == money:
count += 1
print(count)
| # coding: utf-8
# Your code here!
l = int(eval(input()))
m = int(eval(input()))
n = int(eval(input()))
x = int(eval(input()))
count = 0
for i in range(l + 1):
p = 500 * i
for j in range(m + 1):
q = 100 * j
for k in range(n + 1):
r = 50 * k
if p + q + r == x:
count += 1
print(count) | 19 | 18 | 385 | 341 | # coding: utf-8
# Your code here!
a = int(eval(input()))
b = int(eval(input()))
c = int(eval(input()))
money = int(eval(input()))
count = 0
for i in range(a + 1):
for j in range(b + 1):
for k in range(c + 1):
total = i * 500 + j * 100 + k * 50
if total == money:
count += 1
print(count)
| # coding: utf-8
# Your code here!
l = int(eval(input()))
m = int(eval(input()))
n = int(eval(input()))
x = int(eval(input()))
count = 0
for i in range(l + 1):
p = 500 * i
for j in range(m + 1):
q = 100 * j
for k in range(n + 1):
r = 50 * k
if p + q + r == x:
count += 1
print(count)
| false | 5.263158 | [
"-a = int(eval(input()))",
"-b = int(eval(input()))",
"-c = int(eval(input()))",
"-money = int(eval(input()))",
"+l = int(eval(input()))",
"+m = int(eval(input()))",
"+n = int(eval(input()))",
"+x = int(eval(input()))",
"-for i in range(a + 1):",
"- for j in range(b + 1):",
"- for k in range(c + 1):",
"- total = i * 500 + j * 100 + k * 50",
"- if total == money:",
"+for i in range(l + 1):",
"+ p = 500 * i",
"+ for j in range(m + 1):",
"+ q = 100 * j",
"+ for k in range(n + 1):",
"+ r = 50 * k",
"+ if p + q + r == x:"
] | false | 0.100497 | 0.008307 | 12.098075 | [
"s633729364",
"s779358968"
] |
u077291787 | p02689 | python | s342168099 | s229314348 | 125 | 109 | 44,040 | 43,956 | Accepted | Accepted | 12.8 | # C - Peaks
def main():
N, M, *HAB = list(map(int, open(0).read().split()))
H, AB = [0] + HAB[:N], HAB[N:]
good_observatories = set(range(1, N + 1))
for a, b in zip(*[iter(AB)] * 2):
if H[a] >= H[b]:
good_observatories.discard(b)
if H[b] >= H[a]:
good_observatories.discard(a)
print((len(good_observatories)))
if __name__ == "__main__":
main()
| # C - Peaks
def main():
N, M, *HAB = list(map(int, open(0).read().split()))
H, AB = [0] + HAB[:N], HAB[N:]
is_good = [False] + [True] * N
for a, b in zip(*[iter(AB)] * 2):
if H[a] >= H[b]:
is_good[b] = False
if H[b] >= H[a]:
is_good[a] = False
print((sum(is_good)))
if __name__ == "__main__":
main()
| 15 | 15 | 416 | 372 | # C - Peaks
def main():
N, M, *HAB = list(map(int, open(0).read().split()))
H, AB = [0] + HAB[:N], HAB[N:]
good_observatories = set(range(1, N + 1))
for a, b in zip(*[iter(AB)] * 2):
if H[a] >= H[b]:
good_observatories.discard(b)
if H[b] >= H[a]:
good_observatories.discard(a)
print((len(good_observatories)))
if __name__ == "__main__":
main()
| # C - Peaks
def main():
N, M, *HAB = list(map(int, open(0).read().split()))
H, AB = [0] + HAB[:N], HAB[N:]
is_good = [False] + [True] * N
for a, b in zip(*[iter(AB)] * 2):
if H[a] >= H[b]:
is_good[b] = False
if H[b] >= H[a]:
is_good[a] = False
print((sum(is_good)))
if __name__ == "__main__":
main()
| false | 0 | [
"- good_observatories = set(range(1, N + 1))",
"+ is_good = [False] + [True] * N",
"- good_observatories.discard(b)",
"+ is_good[b] = False",
"- good_observatories.discard(a)",
"- print((len(good_observatories)))",
"+ is_good[a] = False",
"+ print((sum(is_good)))"
] | false | 0.038712 | 0.038221 | 1.012826 | [
"s342168099",
"s229314348"
] |
u803617136 | p03775 | python | s347776734 | s680225112 | 30 | 27 | 3,060 | 3,188 | Accepted | Accepted | 10 | import math
N = int(eval(input()))
ans = len(str(N))
for i in range(2, int(math.sqrt(N)) + 1):
if N % i == 0:
ans = min(ans, len(str(N // i)))
print(ans) | from math import ceil
def divisors(n):
res = []
for i in range(1, int(n ** 0.5) + 1):
if n % i == 0:
res.append(i)
if i != n // i:
res.append(n // i)
return res
n = int(eval(input()))
divs = divisors(n)
divs.sort()
lim = ceil(len(divs) / 2)
ans = 11
for i in range(lim):
a = divs[i]
b = divs[(-1) * (i + 1)]
f = max(len(str(a)), len(str(b)))
ans = min(ans, f)
print(ans)
| 7 | 24 | 165 | 468 | import math
N = int(eval(input()))
ans = len(str(N))
for i in range(2, int(math.sqrt(N)) + 1):
if N % i == 0:
ans = min(ans, len(str(N // i)))
print(ans)
| from math import ceil
def divisors(n):
res = []
for i in range(1, int(n**0.5) + 1):
if n % i == 0:
res.append(i)
if i != n // i:
res.append(n // i)
return res
n = int(eval(input()))
divs = divisors(n)
divs.sort()
lim = ceil(len(divs) / 2)
ans = 11
for i in range(lim):
a = divs[i]
b = divs[(-1) * (i + 1)]
f = max(len(str(a)), len(str(b)))
ans = min(ans, f)
print(ans)
| false | 70.833333 | [
"-import math",
"+from math import ceil",
"-N = int(eval(input()))",
"-ans = len(str(N))",
"-for i in range(2, int(math.sqrt(N)) + 1):",
"- if N % i == 0:",
"- ans = min(ans, len(str(N // i)))",
"+",
"+def divisors(n):",
"+ res = []",
"+ for i in range(1, int(n**0.5) + 1):",
"+ if n % i == 0:",
"+ res.append(i)",
"+ if i != n // i:",
"+ res.append(n // i)",
"+ return res",
"+",
"+",
"+n = int(eval(input()))",
"+divs = divisors(n)",
"+divs.sort()",
"+lim = ceil(len(divs) / 2)",
"+ans = 11",
"+for i in range(lim):",
"+ a = divs[i]",
"+ b = divs[(-1) * (i + 1)]",
"+ f = max(len(str(a)), len(str(b)))",
"+ ans = min(ans, f)"
] | false | 0.046961 | 0.049328 | 0.952027 | [
"s347776734",
"s680225112"
] |
u285681431 | p02691 | python | s449889004 | s393417107 | 243 | 214 | 59,468 | 61,560 | Accepted | Accepted | 11.93 | # 雰囲気で書いたら通ってしまったがなんで通ったかわからん
# i<jという前提を無視しているのではと感じる
N = int(eval(input()))
A = list(map(int, input().split()))
# i<jとして、条件は j-i = A_i + A_j
# i + A_i = j - A_j
dict1 = {}
for i in range(1, N + 1):
tmp = i + A[i - 1]
if tmp not in dict1:
dict1[tmp] = 1
else:
dict1[tmp] += 1
dict2 = {}
for i in range(1, N + 1):
tmp = i - A[i - 1]
if tmp not in dict2:
dict2[tmp] = 1
else:
dict2[tmp] += 1
# print(dict1, dict2)
ans = 0
for k, v in list(dict1.items()):
if k in dict2:
ans += v * dict2[k]
print(ans)
| import sys
from collections import defaultdict
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N, *A = list(map(int, read().split()))
memo = defaultdict(int) # 0で初期化する
answer = 0
for idx, x in enumerate(A, 1): # indexを1から始める
# i<jを満たしながらansを計算
# idx = 1の時はansが増えることはない
# idx = 2の時は、idx = 1の時の結果がmemoに記録されている
# idx = 3の時は、idx=1,2の結果が記録されている
# 以下同様
answer += memo[idx - x]
memo[idx + x] += 1
print(answer)
| 30 | 21 | 589 | 509 | # 雰囲気で書いたら通ってしまったがなんで通ったかわからん
# i<jという前提を無視しているのではと感じる
N = int(eval(input()))
A = list(map(int, input().split()))
# i<jとして、条件は j-i = A_i + A_j
# i + A_i = j - A_j
dict1 = {}
for i in range(1, N + 1):
tmp = i + A[i - 1]
if tmp not in dict1:
dict1[tmp] = 1
else:
dict1[tmp] += 1
dict2 = {}
for i in range(1, N + 1):
tmp = i - A[i - 1]
if tmp not in dict2:
dict2[tmp] = 1
else:
dict2[tmp] += 1
# print(dict1, dict2)
ans = 0
for k, v in list(dict1.items()):
if k in dict2:
ans += v * dict2[k]
print(ans)
| import sys
from collections import defaultdict
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N, *A = list(map(int, read().split()))
memo = defaultdict(int) # 0で初期化する
answer = 0
for idx, x in enumerate(A, 1): # indexを1から始める
# i<jを満たしながらansを計算
# idx = 1の時はansが増えることはない
# idx = 2の時は、idx = 1の時の結果がmemoに記録されている
# idx = 3の時は、idx=1,2の結果が記録されている
# 以下同様
answer += memo[idx - x]
memo[idx + x] += 1
print(answer)
| false | 30 | [
"-# 雰囲気で書いたら通ってしまったがなんで通ったかわからん",
"-# i<jという前提を無視しているのではと感じる",
"-N = int(eval(input()))",
"-A = list(map(int, input().split()))",
"-# i<jとして、条件は j-i = A_i + A_j",
"-# i + A_i = j - A_j",
"-dict1 = {}",
"-for i in range(1, N + 1):",
"- tmp = i + A[i - 1]",
"- if tmp not in dict1:",
"- dict1[tmp] = 1",
"- else:",
"- dict1[tmp] += 1",
"-dict2 = {}",
"-for i in range(1, N + 1):",
"- tmp = i - A[i - 1]",
"- if tmp not in dict2:",
"- dict2[tmp] = 1",
"- else:",
"- dict2[tmp] += 1",
"-# print(dict1, dict2)",
"-ans = 0",
"-for k, v in list(dict1.items()):",
"- if k in dict2:",
"- ans += v * dict2[k]",
"-print(ans)",
"+import sys",
"+from collections import defaultdict",
"+",
"+read = sys.stdin.buffer.read",
"+readline = sys.stdin.buffer.readline",
"+readlines = sys.stdin.buffer.readlines",
"+N, *A = list(map(int, read().split()))",
"+memo = defaultdict(int) # 0で初期化する",
"+answer = 0",
"+for idx, x in enumerate(A, 1): # indexを1から始める",
"+ # i<jを満たしながらansを計算",
"+ # idx = 1の時はansが増えることはない",
"+ # idx = 2の時は、idx = 1の時の結果がmemoに記録されている",
"+ # idx = 3の時は、idx=1,2の結果が記録されている",
"+ # 以下同様",
"+ answer += memo[idx - x]",
"+ memo[idx + x] += 1",
"+print(answer)"
] | false | 0.037977 | 0.037495 | 1.012868 | [
"s449889004",
"s393417107"
] |
u017415492 | p03805 | python | s462958971 | s787558237 | 71 | 36 | 74,264 | 9,384 | Accepted | Accepted | 49.3 | import itertools
n,m=list(map(int,input().split()))
edge =[[] for i in range(n+1)]
for i in range(m):
a,b=list(map(int,input().split()))
edge[a].append(b)
edge[b].append(a)
all_lis = list(itertools.permutations(list(range(2,n+1))))
def sati(x):
#xはリスト[4,5,7]
now=1
for i in range(n-1):
if not (x[i] in edge[now]):
return 0
now=x[i]
return 1
ans=0
for i in all_lis:
ans+=sati(i)
print(ans) | import itertools
n,m=list(map(int,input().split()))
edge=[[] for i in range(n+1)]
for i in range(m):
a,b=list(map(int,input().split()))
edge[a].append(b)
edge[b].append(a)
ans=0
for junretu in list(itertools.permutations(list(range(2,n+1)))):
now=1
flag=True
for i in list(junretu):
if not(i in edge[now]):
flag=False
break
now=i
if flag:
ans+=1
print(ans) | 22 | 19 | 429 | 402 | import itertools
n, m = list(map(int, input().split()))
edge = [[] for i in range(n + 1)]
for i in range(m):
a, b = list(map(int, input().split()))
edge[a].append(b)
edge[b].append(a)
all_lis = list(itertools.permutations(list(range(2, n + 1))))
def sati(x):
# xはリスト[4,5,7]
now = 1
for i in range(n - 1):
if not (x[i] in edge[now]):
return 0
now = x[i]
return 1
ans = 0
for i in all_lis:
ans += sati(i)
print(ans)
| import itertools
n, m = list(map(int, input().split()))
edge = [[] for i in range(n + 1)]
for i in range(m):
a, b = list(map(int, input().split()))
edge[a].append(b)
edge[b].append(a)
ans = 0
for junretu in list(itertools.permutations(list(range(2, n + 1)))):
now = 1
flag = True
for i in list(junretu):
if not (i in edge[now]):
flag = False
break
now = i
if flag:
ans += 1
print(ans)
| false | 13.636364 | [
"-all_lis = list(itertools.permutations(list(range(2, n + 1))))",
"-",
"-",
"-def sati(x):",
"- # xはリスト[4,5,7]",
"+ans = 0",
"+for junretu in list(itertools.permutations(list(range(2, n + 1)))):",
"- for i in range(n - 1):",
"- if not (x[i] in edge[now]):",
"- return 0",
"- now = x[i]",
"- return 1",
"-",
"-",
"-ans = 0",
"-for i in all_lis:",
"- ans += sati(i)",
"+ flag = True",
"+ for i in list(junretu):",
"+ if not (i in edge[now]):",
"+ flag = False",
"+ break",
"+ now = i",
"+ if flag:",
"+ ans += 1"
] | false | 0.107539 | 0.107163 | 1.00351 | [
"s462958971",
"s787558237"
] |
u347640436 | p02936 | python | s034554277 | s663441128 | 1,677 | 1,190 | 66,136 | 25,852 | Accepted | Accepted | 29.04 | def main():
_map, _range, _int = map, range, int
n, q = _map(_int, input().split())
values = [0] * (n + 1)
parents = [0] * (n + 1)
for i in _range(n - 1):
a, b = _map(_int, input().split())
parents[b] = a
for _ in _range(q):
p, x = _map(_int, input().split())
values[p] += x
for i in _range(1, n + 1):
values[i] += values[parents[i]]
print((*values[1:]))
main()
| def main():
_map, _range, _int = map, range, int
n, q = _map(_int, input().split())
values = [0] * (n + 1)
parents = [0] * (n + 1)
for _ in _range(n - 1):
a, b = _map(_int, input().split())
parents[b] = a
for _ in _range(q):
p, x = _map(_int, input().split())
values[p] += x
for i in _range(1, n + 1):
values[i] += values[parents[i]]
print((*values[1:]))
main()
| 15 | 15 | 410 | 410 | def main():
_map, _range, _int = map, range, int
n, q = _map(_int, input().split())
values = [0] * (n + 1)
parents = [0] * (n + 1)
for i in _range(n - 1):
a, b = _map(_int, input().split())
parents[b] = a
for _ in _range(q):
p, x = _map(_int, input().split())
values[p] += x
for i in _range(1, n + 1):
values[i] += values[parents[i]]
print((*values[1:]))
main()
| def main():
_map, _range, _int = map, range, int
n, q = _map(_int, input().split())
values = [0] * (n + 1)
parents = [0] * (n + 1)
for _ in _range(n - 1):
a, b = _map(_int, input().split())
parents[b] = a
for _ in _range(q):
p, x = _map(_int, input().split())
values[p] += x
for i in _range(1, n + 1):
values[i] += values[parents[i]]
print((*values[1:]))
main()
| false | 0 | [
"- for i in _range(n - 1):",
"+ for _ in _range(n - 1):"
] | false | 0.042225 | 0.036665 | 1.151654 | [
"s034554277",
"s663441128"
] |
u949353021 | p02570 | python | s834091585 | s276627357 | 30 | 27 | 9,156 | 9,128 | Accepted | Accepted | 10 | d, t, s = list(map(int, input().split()))
if t-d/s >= 0:
print("Yes")
else:
print("No") | d,t,s = list(map(int, input().split()))
if s*t >= d:
print("Yes")
else:
print("No") | 5 | 5 | 93 | 89 | d, t, s = list(map(int, input().split()))
if t - d / s >= 0:
print("Yes")
else:
print("No")
| d, t, s = list(map(int, input().split()))
if s * t >= d:
print("Yes")
else:
print("No")
| false | 0 | [
"-if t - d / s >= 0:",
"+if s * t >= d:"
] | false | 0.046779 | 0.184379 | 0.253709 | [
"s834091585",
"s276627357"
] |
u296518383 | p03564 | python | s123727746 | s723132837 | 21 | 17 | 3,060 | 3,060 | Accepted | Accepted | 19.05 | N,K=int(eval(input())),int(eval(input()))
ans=10**10
for i in range(2**N):
tmp=1
for j in range(N):
if (i>>(N-j-1)&1)==1:
tmp*=2
else:
tmp+=K
ans=min(ans,tmp)
print(ans) | N,K=int(eval(input())),int(eval(input()))
M=[0]*(N+1)
M[0]=1
for i in range(1,N+1):
M[i]=min(M[i-1]*2,M[i-1]+K)
print((M[N])) | 12 | 8 | 195 | 122 | N, K = int(eval(input())), int(eval(input()))
ans = 10**10
for i in range(2**N):
tmp = 1
for j in range(N):
if (i >> (N - j - 1) & 1) == 1:
tmp *= 2
else:
tmp += K
ans = min(ans, tmp)
print(ans)
| N, K = int(eval(input())), int(eval(input()))
M = [0] * (N + 1)
M[0] = 1
for i in range(1, N + 1):
M[i] = min(M[i - 1] * 2, M[i - 1] + K)
print((M[N]))
| false | 33.333333 | [
"-ans = 10**10",
"-for i in range(2**N):",
"- tmp = 1",
"- for j in range(N):",
"- if (i >> (N - j - 1) & 1) == 1:",
"- tmp *= 2",
"- else:",
"- tmp += K",
"- ans = min(ans, tmp)",
"-print(ans)",
"+M = [0] * (N + 1)",
"+M[0] = 1",
"+for i in range(1, N + 1):",
"+ M[i] = min(M[i - 1] * 2, M[i - 1] + K)",
"+print((M[N]))"
] | false | 0.047528 | 0.046575 | 1.020463 | [
"s123727746",
"s723132837"
] |
u045953894 | p03556 | python | s409330285 | s561598051 | 44 | 32 | 10,236 | 9,136 | Accepted | Accepted | 27.27 | def multiple(n):
a = []
for i in range(1,int(n**.5)+1):
a.append(i*i)
return a
n = int(eval(input()))
a = multiple(n)
ans = 10**18
for i in a:
if n-i < 0:
continue
ans = min(ans,abs(n-i))
print((n-ans)) | n = int(eval(input()))
for i in range(1,n+2):
if i*i > n:
print(((i-1)*(i-1)))
exit() | 13 | 5 | 242 | 101 | def multiple(n):
a = []
for i in range(1, int(n**0.5) + 1):
a.append(i * i)
return a
n = int(eval(input()))
a = multiple(n)
ans = 10**18
for i in a:
if n - i < 0:
continue
ans = min(ans, abs(n - i))
print((n - ans))
| n = int(eval(input()))
for i in range(1, n + 2):
if i * i > n:
print(((i - 1) * (i - 1)))
exit()
| false | 61.538462 | [
"-def multiple(n):",
"- a = []",
"- for i in range(1, int(n**0.5) + 1):",
"- a.append(i * i)",
"- return a",
"-",
"-",
"-a = multiple(n)",
"-ans = 10**18",
"-for i in a:",
"- if n - i < 0:",
"- continue",
"- ans = min(ans, abs(n - i))",
"-print((n - ans))",
"+for i in range(1, n + 2):",
"+ if i * i > n:",
"+ print(((i - 1) * (i - 1)))",
"+ exit()"
] | false | 0.100516 | 0.041587 | 2.417002 | [
"s409330285",
"s561598051"
] |
u708255304 | p03007 | python | s288318703 | s555024668 | 272 | 250 | 19,368 | 19,328 | Accepted | Accepted | 8.09 | N = int(eval(input()))
AAA = list(map(int, input().split()))
AAA.sort() # 昇順ソート
m = AAA[0]
M = AAA[N-1]
ANS = []
for i in range(1, N-1):
if AAA[i] > 0:
ANS.append((m, AAA[i]))
m -= AAA[i]
continue
ANS.append((M, AAA[i]))
M -= AAA[i]
ANS.append((M, m))
print((M-m))
for (x, y) in ANS:
print((x, y))
| N = int(eval(input()))
AAA = list(map(int, input().split()))
AAA.sort()
m = AAA[0]
M = AAA[N-1]
procedures = []
for i in range(1, N-1):
if AAA[i] > 0:
procedures.append((m, AAA[i]))
m -= AAA[i]
else:
procedures.append((M, AAA[i]))
M -= AAA[i]
procedures.append((M, m))
print((M-m))
for x, y in procedures:
print((x, y))
| 21 | 21 | 353 | 378 | N = int(eval(input()))
AAA = list(map(int, input().split()))
AAA.sort() # 昇順ソート
m = AAA[0]
M = AAA[N - 1]
ANS = []
for i in range(1, N - 1):
if AAA[i] > 0:
ANS.append((m, AAA[i]))
m -= AAA[i]
continue
ANS.append((M, AAA[i]))
M -= AAA[i]
ANS.append((M, m))
print((M - m))
for (x, y) in ANS:
print((x, y))
| N = int(eval(input()))
AAA = list(map(int, input().split()))
AAA.sort()
m = AAA[0]
M = AAA[N - 1]
procedures = []
for i in range(1, N - 1):
if AAA[i] > 0:
procedures.append((m, AAA[i]))
m -= AAA[i]
else:
procedures.append((M, AAA[i]))
M -= AAA[i]
procedures.append((M, m))
print((M - m))
for x, y in procedures:
print((x, y))
| false | 0 | [
"-AAA.sort() # 昇順ソート",
"+AAA.sort()",
"-ANS = []",
"+procedures = []",
"- ANS.append((m, AAA[i]))",
"+ procedures.append((m, AAA[i]))",
"- continue",
"- ANS.append((M, AAA[i]))",
"- M -= AAA[i]",
"-ANS.append((M, m))",
"+ else:",
"+ procedures.append((M, AAA[i]))",
"+ M -= AAA[i]",
"+procedures.append((M, m))",
"-for (x, y) in ANS:",
"+for x, y in procedures:"
] | false | 0.040497 | 0.119468 | 0.338978 | [
"s288318703",
"s555024668"
] |
u350248178 | p03163 | python | s249989183 | s689077446 | 652 | 216 | 181,512 | 16,344 | Accepted | Accepted | 66.87 | n,w=list(map(int,input().split()))
wv=[]
dp=[[0 for i in range(100010)]for j in range(110)]
for i in range(n):
a=[int(j) for j in input().split()]
wv.append(a)
from operator import itemgetter
wv.sort(key=itemgetter(0))
for i in range(n):
for j in range(w+1):
if j>=wv[i][0]:
dp[i+1][j]=max(dp[i][j],dp[i][j-wv[i][0]]+wv[i][1])
else:
dp[i+1][j]=dp[i][j]
print((dp[n][w])) | n,W=[int(j) for j in input().split()]
wv=[[int(j) for j in input().split()]for i in range(n)]
import numpy as np
dp=np.zeros(W+1,dtype=np.int64)
for w,v in wv:
dp[w:]=np.maximum(dp[w:],dp[:-w]+v)
print((dp.max())) | 19 | 7 | 436 | 221 | n, w = list(map(int, input().split()))
wv = []
dp = [[0 for i in range(100010)] for j in range(110)]
for i in range(n):
a = [int(j) for j in input().split()]
wv.append(a)
from operator import itemgetter
wv.sort(key=itemgetter(0))
for i in range(n):
for j in range(w + 1):
if j >= wv[i][0]:
dp[i + 1][j] = max(dp[i][j], dp[i][j - wv[i][0]] + wv[i][1])
else:
dp[i + 1][j] = dp[i][j]
print((dp[n][w]))
| n, W = [int(j) for j in input().split()]
wv = [[int(j) for j in input().split()] for i in range(n)]
import numpy as np
dp = np.zeros(W + 1, dtype=np.int64)
for w, v in wv:
dp[w:] = np.maximum(dp[w:], dp[:-w] + v)
print((dp.max()))
| false | 63.157895 | [
"-n, w = list(map(int, input().split()))",
"-wv = []",
"-dp = [[0 for i in range(100010)] for j in range(110)]",
"-for i in range(n):",
"- a = [int(j) for j in input().split()]",
"- wv.append(a)",
"-from operator import itemgetter",
"+n, W = [int(j) for j in input().split()]",
"+wv = [[int(j) for j in input().split()] for i in range(n)]",
"+import numpy as np",
"-wv.sort(key=itemgetter(0))",
"-for i in range(n):",
"- for j in range(w + 1):",
"- if j >= wv[i][0]:",
"- dp[i + 1][j] = max(dp[i][j], dp[i][j - wv[i][0]] + wv[i][1])",
"- else:",
"- dp[i + 1][j] = dp[i][j]",
"-print((dp[n][w]))",
"+dp = np.zeros(W + 1, dtype=np.int64)",
"+for w, v in wv:",
"+ dp[w:] = np.maximum(dp[w:], dp[:-w] + v)",
"+print((dp.max()))"
] | false | 1.575825 | 0.202126 | 7.796251 | [
"s249989183",
"s689077446"
] |
u077291787 | p02558 | python | s503476220 | s754292048 | 419 | 378 | 142,888 | 144,920 | Accepted | Accepted | 9.79 | from typing import Set
class UnionFind:
"""Union-Find: O(α(N))"""
__slots__ = ["_data_size", "_first_idx", "_parents"]
def __init__(self, data_size: int, is_zero_origin: bool = True) -> None:
self._data_size = data_size
self._first_idx = 0 if is_zero_origin else 1
self._parents = [-1] * (data_size + self._first_idx)
def __getitem__(self, x: int) -> int:
"""Find the group (root) of vertex x."""
if self._parents[x] < 0:
return x
self._parents[x] = self[self._parents[x]]
return self._parents[x]
def __len__(self) -> int:
"""Count the number of groups (roots)."""
return len(self.groups)
@property
def groups(self) -> Set[int]:
"""Return the set of groups (roots)."""
return {
self[x] for x in range(self._first_idx, self._data_size + self._first_idx)
}
def is_connected(self, x: int, y: int) -> bool:
"""Return whether two vertices x and y are connected or not."""
return self[x] == self[y]
def unite(self, x: int, y: int) -> None:
"""Unite two groups of vertices x and y."""
x, y = self[x], self[y]
if x == y:
return
if self._parents[x] > self._parents[y]:
x, y = y, x
self._parents[x] += self._parents[y]
self._parents[y] = x
def unite_all(self, *vertices: int) -> None:
"""Unite the groups of all of the given vertices."""
x = vertices[0]
for y in vertices[1:]:
self.unite(x, y)
def get_size(self, x: int) -> int:
"""Return the size of the group vertex x belongs."""
return -self._parents[self[x]]
def unionfind():
# https://judge.yosupo.jp/problem/unionfind
N, Q, *TUV = list(map(int, open(0).read().split()))
tree = UnionFind(N)
res = []
for t, u, v in zip(*[iter(TUV)] * 3):
if t:
res.append(int(tree.is_connected(u, v)))
else:
tree.unite(u, v)
print(("\n".join(map(str, res))))
if __name__ == "__main__":
unionfind()
| class UnionFind:
"""Union-Find: O(α(N))"""
__slots__ = ["_data_size", "_first_idx", "_parents"]
def __init__(self, data_size: int, is_zero_origin: bool = True) -> None:
self._data_size = data_size
self._first_idx = 0 if is_zero_origin else 1
self._parents = [-1] * (data_size + self._first_idx)
def _find(self, x: int) -> int:
if self._parents[x] < 0:
return x
self._parents[x] = self._find(self._parents[x])
return self._parents[x]
def is_connected(self, x: int, y: int) -> bool:
"""Return whether two vertices x and y are connected or not."""
return self._find(x) == self._find(y)
def unite(self, x: int, y: int) -> None:
"""Unite two groups of vertices x and y."""
x, y = self._find(x), self._find(y)
if x == y:
return
if self._parents[x] > self._parents[y]:
x, y = y, x
self._parents[x] += self._parents[y]
self._parents[y] = x
def unionfind():
# https://judge.yosupo.jp/problem/unionfind
# https://atcoder.jp/contests/practice2/tasks/practice2_a
N, Q, *TUV = list(map(int, open(0).read().split()))
tree = UnionFind(N)
res = []
for t, u, v in zip(*[iter(TUV)] * 3):
if t:
res.append(int(tree.is_connected(u, v)))
else:
tree.unite(u, v)
print(("\n".join(map(str, res))))
if __name__ == "__main__":
unionfind()
| 71 | 47 | 2,175 | 1,504 | from typing import Set
class UnionFind:
"""Union-Find: O(α(N))"""
__slots__ = ["_data_size", "_first_idx", "_parents"]
def __init__(self, data_size: int, is_zero_origin: bool = True) -> None:
self._data_size = data_size
self._first_idx = 0 if is_zero_origin else 1
self._parents = [-1] * (data_size + self._first_idx)
def __getitem__(self, x: int) -> int:
"""Find the group (root) of vertex x."""
if self._parents[x] < 0:
return x
self._parents[x] = self[self._parents[x]]
return self._parents[x]
def __len__(self) -> int:
"""Count the number of groups (roots)."""
return len(self.groups)
@property
def groups(self) -> Set[int]:
"""Return the set of groups (roots)."""
return {
self[x] for x in range(self._first_idx, self._data_size + self._first_idx)
}
def is_connected(self, x: int, y: int) -> bool:
"""Return whether two vertices x and y are connected or not."""
return self[x] == self[y]
def unite(self, x: int, y: int) -> None:
"""Unite two groups of vertices x and y."""
x, y = self[x], self[y]
if x == y:
return
if self._parents[x] > self._parents[y]:
x, y = y, x
self._parents[x] += self._parents[y]
self._parents[y] = x
def unite_all(self, *vertices: int) -> None:
"""Unite the groups of all of the given vertices."""
x = vertices[0]
for y in vertices[1:]:
self.unite(x, y)
def get_size(self, x: int) -> int:
"""Return the size of the group vertex x belongs."""
return -self._parents[self[x]]
def unionfind():
# https://judge.yosupo.jp/problem/unionfind
N, Q, *TUV = list(map(int, open(0).read().split()))
tree = UnionFind(N)
res = []
for t, u, v in zip(*[iter(TUV)] * 3):
if t:
res.append(int(tree.is_connected(u, v)))
else:
tree.unite(u, v)
print(("\n".join(map(str, res))))
if __name__ == "__main__":
unionfind()
| class UnionFind:
"""Union-Find: O(α(N))"""
__slots__ = ["_data_size", "_first_idx", "_parents"]
def __init__(self, data_size: int, is_zero_origin: bool = True) -> None:
self._data_size = data_size
self._first_idx = 0 if is_zero_origin else 1
self._parents = [-1] * (data_size + self._first_idx)
def _find(self, x: int) -> int:
if self._parents[x] < 0:
return x
self._parents[x] = self._find(self._parents[x])
return self._parents[x]
def is_connected(self, x: int, y: int) -> bool:
"""Return whether two vertices x and y are connected or not."""
return self._find(x) == self._find(y)
def unite(self, x: int, y: int) -> None:
"""Unite two groups of vertices x and y."""
x, y = self._find(x), self._find(y)
if x == y:
return
if self._parents[x] > self._parents[y]:
x, y = y, x
self._parents[x] += self._parents[y]
self._parents[y] = x
def unionfind():
# https://judge.yosupo.jp/problem/unionfind
# https://atcoder.jp/contests/practice2/tasks/practice2_a
N, Q, *TUV = list(map(int, open(0).read().split()))
tree = UnionFind(N)
res = []
for t, u, v in zip(*[iter(TUV)] * 3):
if t:
res.append(int(tree.is_connected(u, v)))
else:
tree.unite(u, v)
print(("\n".join(map(str, res))))
if __name__ == "__main__":
unionfind()
| false | 33.802817 | [
"-from typing import Set",
"-",
"-",
"- def __getitem__(self, x: int) -> int:",
"- \"\"\"Find the group (root) of vertex x.\"\"\"",
"+ def _find(self, x: int) -> int:",
"- self._parents[x] = self[self._parents[x]]",
"+ self._parents[x] = self._find(self._parents[x])",
"-",
"- def __len__(self) -> int:",
"- \"\"\"Count the number of groups (roots).\"\"\"",
"- return len(self.groups)",
"-",
"- @property",
"- def groups(self) -> Set[int]:",
"- \"\"\"Return the set of groups (roots).\"\"\"",
"- return {",
"- self[x] for x in range(self._first_idx, self._data_size + self._first_idx)",
"- }",
"- return self[x] == self[y]",
"+ return self._find(x) == self._find(y)",
"- x, y = self[x], self[y]",
"+ x, y = self._find(x), self._find(y)",
"- def unite_all(self, *vertices: int) -> None:",
"- \"\"\"Unite the groups of all of the given vertices.\"\"\"",
"- x = vertices[0]",
"- for y in vertices[1:]:",
"- self.unite(x, y)",
"-",
"- def get_size(self, x: int) -> int:",
"- \"\"\"Return the size of the group vertex x belongs.\"\"\"",
"- return -self._parents[self[x]]",
"-",
"+ # https://atcoder.jp/contests/practice2/tasks/practice2_a"
] | false | 0.088055 | 0.047376 | 1.858632 | [
"s503476220",
"s754292048"
] |
u394244719 | p02947 | python | s704817248 | s149624681 | 797 | 265 | 115,456 | 22,132 | Accepted | Accepted | 66.75 | import sys
import math
inint = lambda: int(sys.stdin.readline())
inintm = lambda: list(map(int, sys.stdin.readline().split()))
inintl = lambda: list(inintm())
instrm = lambda: list(map(str, sys.stdin.readline().split()))
instrl = lambda: list(instrm())
n = inint()
z = {():0}
ans = 0
def combinations(n, r):
if n < r:
return 0
else:
return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
for i in range(n):
c = [0]*123
s = eval(input())
for j in range(len(s)):
c[ord(s[j])] += 1
try:
z[tuple(c)] += 1
except:
z[tuple(c)] = 1
for i in z:
ans += combinations(z[i],2)
print(ans) | import sys
import math
inint = lambda: int(sys.stdin.readline())
inintm = lambda: list(map(int, sys.stdin.readline().split()))
inintl = lambda: list(inintm())
instrm = lambda: list(map(str, sys.stdin.readline().split()))
instrl = lambda: list(instrm())
n = inint()
z = {}
ans = 0
for i in range(n):
s = "".join(sorted(eval(input())))
try:
z[s] += 1
except:
z[s] = 1
for i in z:
ans += z[i]*(z[i]-1)//2
print(ans) | 35 | 26 | 688 | 458 | import sys
import math
inint = lambda: int(sys.stdin.readline())
inintm = lambda: list(map(int, sys.stdin.readline().split()))
inintl = lambda: list(inintm())
instrm = lambda: list(map(str, sys.stdin.readline().split()))
instrl = lambda: list(instrm())
n = inint()
z = {(): 0}
ans = 0
def combinations(n, r):
if n < r:
return 0
else:
return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
for i in range(n):
c = [0] * 123
s = eval(input())
for j in range(len(s)):
c[ord(s[j])] += 1
try:
z[tuple(c)] += 1
except:
z[tuple(c)] = 1
for i in z:
ans += combinations(z[i], 2)
print(ans)
| import sys
import math
inint = lambda: int(sys.stdin.readline())
inintm = lambda: list(map(int, sys.stdin.readline().split()))
inintl = lambda: list(inintm())
instrm = lambda: list(map(str, sys.stdin.readline().split()))
instrl = lambda: list(instrm())
n = inint()
z = {}
ans = 0
for i in range(n):
s = "".join(sorted(eval(input())))
try:
z[s] += 1
except:
z[s] = 1
for i in z:
ans += z[i] * (z[i] - 1) // 2
print(ans)
| false | 25.714286 | [
"-z = {(): 0}",
"+z = {}",
"-",
"-",
"-def combinations(n, r):",
"- if n < r:",
"- return 0",
"- else:",
"- return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))",
"-",
"-",
"- c = [0] * 123",
"- s = eval(input())",
"- for j in range(len(s)):",
"- c[ord(s[j])] += 1",
"+ s = \"\".join(sorted(eval(input())))",
"- z[tuple(c)] += 1",
"+ z[s] += 1",
"- z[tuple(c)] = 1",
"+ z[s] = 1",
"- ans += combinations(z[i], 2)",
"+ ans += z[i] * (z[i] - 1) // 2"
] | false | 0.081785 | 0.060247 | 1.357485 | [
"s704817248",
"s149624681"
] |
u991567869 | p02732 | python | s925505706 | s104019796 | 202 | 182 | 39,352 | 38,972 | Accepted | Accepted | 9.9 | def ban():
from collections import Counter
n = int(eval(input()))
a = list(map(int, input().split()))
b = Counter(a)
total = sum(i*(i - 1)//2 for i in list(b.values()))
ans = [(total - (b[i] - 1)) for i in a]
return "\n".join(map(str, ans))
print((ban())) | def ban():
n = int(eval(input()))
a = list(map(int, input().split()))
d = {}
total = 0
for i in a:
if i not in d:
d[i] = 1
else:
total += d[i]
d[i] += 1
ans = [total - (d[i] - 1) for i in a]
return "\n".join(map(str, ans))
print((ban())) | 11 | 17 | 281 | 328 | def ban():
from collections import Counter
n = int(eval(input()))
a = list(map(int, input().split()))
b = Counter(a)
total = sum(i * (i - 1) // 2 for i in list(b.values()))
ans = [(total - (b[i] - 1)) for i in a]
return "\n".join(map(str, ans))
print((ban()))
| def ban():
n = int(eval(input()))
a = list(map(int, input().split()))
d = {}
total = 0
for i in a:
if i not in d:
d[i] = 1
else:
total += d[i]
d[i] += 1
ans = [total - (d[i] - 1) for i in a]
return "\n".join(map(str, ans))
print((ban()))
| false | 35.294118 | [
"- from collections import Counter",
"-",
"- b = Counter(a)",
"- total = sum(i * (i - 1) // 2 for i in list(b.values()))",
"- ans = [(total - (b[i] - 1)) for i in a]",
"+ d = {}",
"+ total = 0",
"+ for i in a:",
"+ if i not in d:",
"+ d[i] = 1",
"+ else:",
"+ total += d[i]",
"+ d[i] += 1",
"+ ans = [total - (d[i] - 1) for i in a]"
] | false | 0.085102 | 0.033263 | 2.55843 | [
"s925505706",
"s104019796"
] |
u864197622 | p02798 | python | s417870934 | s001746507 | 769 | 544 | 50,520 | 50,520 | Accepted | Accepted | 29.26 | N = int(eval(input()))
A = [int(a) for a in input().split()]
B = [int(a) for a in input().split()]
AB = sorted(list(set(A + B)))
D = {ab: i+1 for i, ab in enumerate(AB)}
A = [D[a] for a in A]
B = [D[a] for a in B]
def chk(L):
NN = 5
BIT=[0] * (2**NN+1)
def addbit(i):
while i <= 2**NN:
BIT[i] += 1
i += i & (-i)
def getsum(i):
ret = 0
while i != 0:
ret += BIT[i]
i -= i&(-i)
return ret
s = 0
for l in L[::-1]:
s += getsum(l+1)
addbit(l+1)
return s
ans = 1 << 100
for m in range(1<<N):
b = bin(m)
if b[::2].count("1") != b[1::2].count("1"): continue
C = [[], []]
for i in range(N):
p = m >> i & 1
q = p + i & 1
C[q].append(((A[i] if p == 0 else B[i]) << 5) + i)
if len(C[1]) != N // 2: continue
C[0].sort()
C[1].sort()
CC = [C[i&1][i//2] for i in range(N)]
for i in range(1, N):
if CC[i-1] >> 5 > CC[i] >> 5: break
else:
CCC = [c % 32 for c in CC]
ans = min(ans, chk(CCC))
print((ans if ans < 1 << 100 else -1)) | N = int(eval(input()))
A = [int(a) for a in input().split()]
B = [int(a) for a in input().split()]
AB = sorted(list(set(A + B)))
D = {ab: i+1 for i, ab in enumerate(AB)}
A = [D[a] for a in A]
B = [D[a] for a in B]
ans = 1 << 100
for m in range(1<<N):
b = bin(m)
if b[::2].count("1") != b[1::2].count("1"): continue
C = [[], []]
for i in range(N):
p = m >> i & 1
q = p + i & 1
C[q].append(((A[i] if p == 0 else B[i]) << 5) + i)
if len(C[1]) != N // 2: continue
C[0].sort()
C[1].sort()
CC = [C[i&1][i//2] for i in range(N)]
for i in range(1, N):
if CC[i-1] >> 5 > CC[i] >> 5: break
else:
CCC = [c % 32 for c in CC]
t = 0
for i in range(N):
for j in range(i):
if CCC[i] < CCC[j]: t += 1
ans = min(ans, t)
print((ans if ans < 1 << 100 else -1)) | 46 | 31 | 1,162 | 895 | N = int(eval(input()))
A = [int(a) for a in input().split()]
B = [int(a) for a in input().split()]
AB = sorted(list(set(A + B)))
D = {ab: i + 1 for i, ab in enumerate(AB)}
A = [D[a] for a in A]
B = [D[a] for a in B]
def chk(L):
NN = 5
BIT = [0] * (2**NN + 1)
def addbit(i):
while i <= 2**NN:
BIT[i] += 1
i += i & (-i)
def getsum(i):
ret = 0
while i != 0:
ret += BIT[i]
i -= i & (-i)
return ret
s = 0
for l in L[::-1]:
s += getsum(l + 1)
addbit(l + 1)
return s
ans = 1 << 100
for m in range(1 << N):
b = bin(m)
if b[::2].count("1") != b[1::2].count("1"):
continue
C = [[], []]
for i in range(N):
p = m >> i & 1
q = p + i & 1
C[q].append(((A[i] if p == 0 else B[i]) << 5) + i)
if len(C[1]) != N // 2:
continue
C[0].sort()
C[1].sort()
CC = [C[i & 1][i // 2] for i in range(N)]
for i in range(1, N):
if CC[i - 1] >> 5 > CC[i] >> 5:
break
else:
CCC = [c % 32 for c in CC]
ans = min(ans, chk(CCC))
print((ans if ans < 1 << 100 else -1))
| N = int(eval(input()))
A = [int(a) for a in input().split()]
B = [int(a) for a in input().split()]
AB = sorted(list(set(A + B)))
D = {ab: i + 1 for i, ab in enumerate(AB)}
A = [D[a] for a in A]
B = [D[a] for a in B]
ans = 1 << 100
for m in range(1 << N):
b = bin(m)
if b[::2].count("1") != b[1::2].count("1"):
continue
C = [[], []]
for i in range(N):
p = m >> i & 1
q = p + i & 1
C[q].append(((A[i] if p == 0 else B[i]) << 5) + i)
if len(C[1]) != N // 2:
continue
C[0].sort()
C[1].sort()
CC = [C[i & 1][i // 2] for i in range(N)]
for i in range(1, N):
if CC[i - 1] >> 5 > CC[i] >> 5:
break
else:
CCC = [c % 32 for c in CC]
t = 0
for i in range(N):
for j in range(i):
if CCC[i] < CCC[j]:
t += 1
ans = min(ans, t)
print((ans if ans < 1 << 100 else -1))
| false | 32.608696 | [
"-",
"-",
"-def chk(L):",
"- NN = 5",
"- BIT = [0] * (2**NN + 1)",
"-",
"- def addbit(i):",
"- while i <= 2**NN:",
"- BIT[i] += 1",
"- i += i & (-i)",
"-",
"- def getsum(i):",
"- ret = 0",
"- while i != 0:",
"- ret += BIT[i]",
"- i -= i & (-i)",
"- return ret",
"-",
"- s = 0",
"- for l in L[::-1]:",
"- s += getsum(l + 1)",
"- addbit(l + 1)",
"- return s",
"-",
"-",
"- ans = min(ans, chk(CCC))",
"+ t = 0",
"+ for i in range(N):",
"+ for j in range(i):",
"+ if CCC[i] < CCC[j]:",
"+ t += 1",
"+ ans = min(ans, t)"
] | false | 0.036685 | 0.035715 | 1.027161 | [
"s417870934",
"s001746507"
] |
u072053884 | p02257 | python | s217739372 | s964747100 | 310 | 40 | 7,736 | 7,696 | Accepted | Accepted | 87.1 | def is_prime(x):
if x == 2:
return 1
elif x % 2 == 0:
return 0
l = x ** 0.5
for i in range(3, int(x ** 0.5) + 1, 2):
if x % i == 0:
return 0
return 1
import sys
def solve():
file_input = sys.stdin
N = file_input.readline()
cnt = 0
for l in file_input:
cnt += is_prime(int(l))
print(cnt)
solve() | # Fermat's little theorem
def is_prime(x):
if x == 2:
return 1
elif x % 2 == 0:
return 0
else:
return pow(2, x - 1, x) == 1
import sys
def solve():
file_input = sys.stdin
N = file_input.readline()
cnt = 0
for n in map(int, file_input):
cnt += is_prime(n)
print(cnt)
solve() | 22 | 20 | 402 | 359 | def is_prime(x):
if x == 2:
return 1
elif x % 2 == 0:
return 0
l = x**0.5
for i in range(3, int(x**0.5) + 1, 2):
if x % i == 0:
return 0
return 1
import sys
def solve():
file_input = sys.stdin
N = file_input.readline()
cnt = 0
for l in file_input:
cnt += is_prime(int(l))
print(cnt)
solve()
| # Fermat's little theorem
def is_prime(x):
if x == 2:
return 1
elif x % 2 == 0:
return 0
else:
return pow(2, x - 1, x) == 1
import sys
def solve():
file_input = sys.stdin
N = file_input.readline()
cnt = 0
for n in map(int, file_input):
cnt += is_prime(n)
print(cnt)
solve()
| false | 9.090909 | [
"+# Fermat's little theorem",
"- l = x**0.5",
"- for i in range(3, int(x**0.5) + 1, 2):",
"- if x % i == 0:",
"- return 0",
"- return 1",
"+ else:",
"+ return pow(2, x - 1, x) == 1",
"- for l in file_input:",
"- cnt += is_prime(int(l))",
"+ for n in map(int, file_input):",
"+ cnt += is_prime(n)"
] | false | 0.080822 | 0.035517 | 2.275597 | [
"s217739372",
"s964747100"
] |
u388927326 | p03575 | python | s006237497 | s850942344 | 119 | 28 | 3,572 | 3,572 | Accepted | Accepted | 76.47 | #!/usr/bin/env python3
from copy import deepcopy
def dfs(x, adj, visited):
for y, flag in enumerate(adj[x]):
if flag and y not in visited:
visited.add(y)
dfs(y, adj, visited)
def is_simply_connected(adj):
n = len(adj)
visited = {0}
dfs(0, adj, visited)
return len(visited) == n
def main():
n, m = list(map(int, input().split()))
adj = [[(i == j) for i in range(n)] for j in range(n)]
edges = set()
for i in range(m):
a1, b1 = list(map(int, input().split()))
a = a1 - 1
b = b1 - 1
edges.add((a, b))
adj[a][b] = True
adj[b][a] = True
res = 0
for a, b in edges:
adjc = deepcopy(adj)
adjc[a][b] = False
adjc[b][a] = False
if not is_simply_connected(adjc):
res += 1
print(res)
main()
| #!/usr/bin/env python3
from copy import deepcopy
def dfs(x, adj, visited):
for y, flag in enumerate(adj[x]):
if flag and y not in visited:
visited.add(y)
dfs(y, adj, visited)
def is_simply_connected(adj):
n = len(adj)
visited = {0} # O(log n). Use list instead.
dfs(0, adj, visited)
return len(visited) == n
def main():
n, m = list(map(int, input().split()))
adj = [[(i == j) for i in range(n)] for j in range(n)]
edges = set()
for i in range(m):
a1, b1 = list(map(int, input().split()))
a = a1 - 1
b = b1 - 1
edges.add((a, b))
adj[a][b] = True
adj[b][a] = True
res = 0
for a, b in edges:
adj[a][b] = adj[b][a] = False
if not is_simply_connected(adj):
res += 1
adj[a][b] = adj[b][a] = True
print(res)
main()
| 38 | 37 | 882 | 903 | #!/usr/bin/env python3
from copy import deepcopy
def dfs(x, adj, visited):
for y, flag in enumerate(adj[x]):
if flag and y not in visited:
visited.add(y)
dfs(y, adj, visited)
def is_simply_connected(adj):
n = len(adj)
visited = {0}
dfs(0, adj, visited)
return len(visited) == n
def main():
n, m = list(map(int, input().split()))
adj = [[(i == j) for i in range(n)] for j in range(n)]
edges = set()
for i in range(m):
a1, b1 = list(map(int, input().split()))
a = a1 - 1
b = b1 - 1
edges.add((a, b))
adj[a][b] = True
adj[b][a] = True
res = 0
for a, b in edges:
adjc = deepcopy(adj)
adjc[a][b] = False
adjc[b][a] = False
if not is_simply_connected(adjc):
res += 1
print(res)
main()
| #!/usr/bin/env python3
from copy import deepcopy
def dfs(x, adj, visited):
for y, flag in enumerate(adj[x]):
if flag and y not in visited:
visited.add(y)
dfs(y, adj, visited)
def is_simply_connected(adj):
n = len(adj)
visited = {0} # O(log n). Use list instead.
dfs(0, adj, visited)
return len(visited) == n
def main():
n, m = list(map(int, input().split()))
adj = [[(i == j) for i in range(n)] for j in range(n)]
edges = set()
for i in range(m):
a1, b1 = list(map(int, input().split()))
a = a1 - 1
b = b1 - 1
edges.add((a, b))
adj[a][b] = True
adj[b][a] = True
res = 0
for a, b in edges:
adj[a][b] = adj[b][a] = False
if not is_simply_connected(adj):
res += 1
adj[a][b] = adj[b][a] = True
print(res)
main()
| false | 2.631579 | [
"- visited = {0}",
"+ visited = {0} # O(log n). Use list instead.",
"- adjc = deepcopy(adj)",
"- adjc[a][b] = False",
"- adjc[b][a] = False",
"- if not is_simply_connected(adjc):",
"+ adj[a][b] = adj[b][a] = False",
"+ if not is_simply_connected(adj):",
"+ adj[a][b] = adj[b][a] = True"
] | false | 0.120053 | 0.038114 | 3.149839 | [
"s006237497",
"s850942344"
] |
u936985471 | p03503 | python | s417370238 | s097107440 | 320 | 96 | 3,064 | 3,064 | Accepted | Accepted | 70 | n=int(eval(input()))
f=[0]*n
for i in range(n):
x=list(map(int,input().split()))
for j in range(len(x)):
if x[j]==1:
f[i]+=1<<j
p=[[0 for j in range(10)] for i in range(n)]
for i in range(n):
p[i]=list(map(int,input().split()))
ans=10**9*(-1)-1
for i in range(1,2**10):
pro=0
for j in range(len(f)):
open=0
for k in range(10):
if (i>>k)&1==1 and (f[j]>>k)&1==1:
open+=1
pro+=p[j][open]
if ans<pro:
ans=pro
print(ans)
| # 曜日と時間帯の組み合わせを1111111111の10ビットで全探索
import sys
readline = sys.stdin.readline
N = int(readline())
F = [None] * N
for i in range(N):
F[i] = int(readline().rstrip().replace(" ",""),2)
P = [None] * N
for i in range(N):
P[i] = list(map(int,readline().split()))
ans = -(10 ** 10)
for i in range(1, 2 ** 10):
# joisinoが営業する時間帯の文字列11011101
# 各店について、店jとANDを取って、1ビットの数を数えるとCが分かる
point = 0
for j in range(N):
# 店j
debug = False
c = bin(i & F[j])[2:].count("1")
point += P[j][c]
if ans < point:
ans = point
print(ans)
| 25 | 28 | 492 | 580 | n = int(eval(input()))
f = [0] * n
for i in range(n):
x = list(map(int, input().split()))
for j in range(len(x)):
if x[j] == 1:
f[i] += 1 << j
p = [[0 for j in range(10)] for i in range(n)]
for i in range(n):
p[i] = list(map(int, input().split()))
ans = 10**9 * (-1) - 1
for i in range(1, 2**10):
pro = 0
for j in range(len(f)):
open = 0
for k in range(10):
if (i >> k) & 1 == 1 and (f[j] >> k) & 1 == 1:
open += 1
pro += p[j][open]
if ans < pro:
ans = pro
print(ans)
| # 曜日と時間帯の組み合わせを1111111111の10ビットで全探索
import sys
readline = sys.stdin.readline
N = int(readline())
F = [None] * N
for i in range(N):
F[i] = int(readline().rstrip().replace(" ", ""), 2)
P = [None] * N
for i in range(N):
P[i] = list(map(int, readline().split()))
ans = -(10**10)
for i in range(1, 2**10):
# joisinoが営業する時間帯の文字列11011101
# 各店について、店jとANDを取って、1ビットの数を数えるとCが分かる
point = 0
for j in range(N):
# 店j
debug = False
c = bin(i & F[j])[2:].count("1")
point += P[j][c]
if ans < point:
ans = point
print(ans)
| false | 10.714286 | [
"-n = int(eval(input()))",
"-f = [0] * n",
"-for i in range(n):",
"- x = list(map(int, input().split()))",
"- for j in range(len(x)):",
"- if x[j] == 1:",
"- f[i] += 1 << j",
"-p = [[0 for j in range(10)] for i in range(n)]",
"-for i in range(n):",
"- p[i] = list(map(int, input().split()))",
"-ans = 10**9 * (-1) - 1",
"+# 曜日と時間帯の組み合わせを1111111111の10ビットで全探索",
"+import sys",
"+",
"+readline = sys.stdin.readline",
"+N = int(readline())",
"+F = [None] * N",
"+for i in range(N):",
"+ F[i] = int(readline().rstrip().replace(\" \", \"\"), 2)",
"+P = [None] * N",
"+for i in range(N):",
"+ P[i] = list(map(int, readline().split()))",
"+ans = -(10**10)",
"- pro = 0",
"- for j in range(len(f)):",
"- open = 0",
"- for k in range(10):",
"- if (i >> k) & 1 == 1 and (f[j] >> k) & 1 == 1:",
"- open += 1",
"- pro += p[j][open]",
"- if ans < pro:",
"- ans = pro",
"+ # joisinoが営業する時間帯の文字列11011101",
"+ # 各店について、店jとANDを取って、1ビットの数を数えるとCが分かる",
"+ point = 0",
"+ for j in range(N):",
"+ # 店j",
"+ debug = False",
"+ c = bin(i & F[j])[2:].count(\"1\")",
"+ point += P[j][c]",
"+ if ans < point:",
"+ ans = point"
] | false | 0.044589 | 0.036494 | 1.22182 | [
"s417370238",
"s097107440"
] |
u922449550 | p03018 | python | s881956615 | s064237818 | 173 | 63 | 9,392 | 11,460 | Accepted | Accepted | 63.58 | S = eval(input())
N = len(S)
ans = num_a = 0
pre_is_a = True
i = 0
while i < N:
s = S[i]
if s == 'A':
pre_is_a = True
num_a += 1
elif s == 'B' and pre_is_a:
num_bc = 0
flag = True
for j in range(i, N-1, 2):
if S[j:j+2] == 'BC':
num_bc += 1
else:
flag = False
break
if num_bc:
ans += num_a * num_bc
if flag:
i = N
else:
i = j - 1
else:
pre_a = False
num_a = 0
else:
pre_a = False
num_a = 0
i += 1
print(ans) | S = eval(input())
S = S.replace('BC', 'D')
S = S.replace('B', 'C')
S = S.split('C')
ans = 0
def count_inv(s):
res = num = 0
for si in s:
if si == 'A':
num += 1
else:
res += num
return res
for s in S:
ans += count_inv(s)
print(ans) | 36 | 20 | 694 | 277 | S = eval(input())
N = len(S)
ans = num_a = 0
pre_is_a = True
i = 0
while i < N:
s = S[i]
if s == "A":
pre_is_a = True
num_a += 1
elif s == "B" and pre_is_a:
num_bc = 0
flag = True
for j in range(i, N - 1, 2):
if S[j : j + 2] == "BC":
num_bc += 1
else:
flag = False
break
if num_bc:
ans += num_a * num_bc
if flag:
i = N
else:
i = j - 1
else:
pre_a = False
num_a = 0
else:
pre_a = False
num_a = 0
i += 1
print(ans)
| S = eval(input())
S = S.replace("BC", "D")
S = S.replace("B", "C")
S = S.split("C")
ans = 0
def count_inv(s):
res = num = 0
for si in s:
if si == "A":
num += 1
else:
res += num
return res
for s in S:
ans += count_inv(s)
print(ans)
| false | 44.444444 | [
"-N = len(S)",
"-ans = num_a = 0",
"-pre_is_a = True",
"-i = 0",
"-while i < N:",
"- s = S[i]",
"- if s == \"A\":",
"- pre_is_a = True",
"- num_a += 1",
"- elif s == \"B\" and pre_is_a:",
"- num_bc = 0",
"- flag = True",
"- for j in range(i, N - 1, 2):",
"- if S[j : j + 2] == \"BC\":",
"- num_bc += 1",
"- else:",
"- flag = False",
"- break",
"- if num_bc:",
"- ans += num_a * num_bc",
"- if flag:",
"- i = N",
"- else:",
"- i = j - 1",
"+S = S.replace(\"BC\", \"D\")",
"+S = S.replace(\"B\", \"C\")",
"+S = S.split(\"C\")",
"+ans = 0",
"+",
"+",
"+def count_inv(s):",
"+ res = num = 0",
"+ for si in s:",
"+ if si == \"A\":",
"+ num += 1",
"- pre_a = False",
"- num_a = 0",
"- else:",
"- pre_a = False",
"- num_a = 0",
"- i += 1",
"+ res += num",
"+ return res",
"+",
"+",
"+for s in S:",
"+ ans += count_inv(s)"
] | false | 0.04189 | 0.056208 | 0.745273 | [
"s881956615",
"s064237818"
] |
u339550873 | p03110 | python | s318830444 | s034840388 | 19 | 17 | 3,060 | 2,940 | Accepted | Accepted | 10.53 | #! /usr/bin/env python3
# -*- coding: utf-8 -*-
N = int(eval(input()))
answer = 0
for _ in range(N):
x,u = input().split()
if u == "JPY":
money = float(x)
else:
money = float(x)*380000.0
answer += money
print(answer)
| #! /usr/bin/env python3
# -*- coding: utf-8 -*-
N = int(eval(input()))
answer = 0
for _ in range(N):
x,u = input().split()
if u == "JPY":
money = int(x)
else:
money = float(x)*380000.0
answer += money
print(answer)
| 15 | 14 | 261 | 257 | #! /usr/bin/env python3
# -*- coding: utf-8 -*-
N = int(eval(input()))
answer = 0
for _ in range(N):
x, u = input().split()
if u == "JPY":
money = float(x)
else:
money = float(x) * 380000.0
answer += money
print(answer)
| #! /usr/bin/env python3
# -*- coding: utf-8 -*-
N = int(eval(input()))
answer = 0
for _ in range(N):
x, u = input().split()
if u == "JPY":
money = int(x)
else:
money = float(x) * 380000.0
answer += money
print(answer)
| false | 6.666667 | [
"- money = float(x)",
"+ money = int(x)"
] | false | 0.042013 | 0.056693 | 0.741068 | [
"s318830444",
"s034840388"
] |
u467175809 | p01300 | python | s903846172 | s741838311 | 1,220 | 880 | 4,692 | 4,932 | Accepted | Accepted | 27.87 | while True:
S=input()
if S=='0':break
m=[1]+[0 for i in range(10)]
d=A=0
e=1
S=reversed(S)
for c in S:
d=(d+int(c)*e)%11
if int(c)!=0:A+=m[d]
m[d]+=1
e*=-1
print(A)
| while True:
S = input()[::-1]
if S == '0' : break
m = [1] + [0] * 10
diff = ans = 0
even = 1
for c in S:
num = int(c)
diff = (diff + num * even) % 11
if num : ans += m[diff]
m[diff] += 1
even *= -1
print(ans)
| 13 | 13 | 198 | 292 | while True:
S = input()
if S == "0":
break
m = [1] + [0 for i in range(10)]
d = A = 0
e = 1
S = reversed(S)
for c in S:
d = (d + int(c) * e) % 11
if int(c) != 0:
A += m[d]
m[d] += 1
e *= -1
print(A)
| while True:
S = input()[::-1]
if S == "0":
break
m = [1] + [0] * 10
diff = ans = 0
even = 1
for c in S:
num = int(c)
diff = (diff + num * even) % 11
if num:
ans += m[diff]
m[diff] += 1
even *= -1
print(ans)
| false | 0 | [
"- S = input()",
"+ S = input()[::-1]",
"- m = [1] + [0 for i in range(10)]",
"- d = A = 0",
"- e = 1",
"- S = reversed(S)",
"+ m = [1] + [0] * 10",
"+ diff = ans = 0",
"+ even = 1",
"- d = (d + int(c) * e) % 11",
"- if int(c) != 0:",
"- A += m[d]",
"- m[d] += 1",
"- e *= -1",
"- print(A)",
"+ num = int(c)",
"+ diff = (diff + num * even) % 11",
"+ if num:",
"+ ans += m[diff]",
"+ m[diff] += 1",
"+ even *= -1",
"+ print(ans)"
] | false | 0.076463 | 0.037527 | 2.037538 | [
"s903846172",
"s741838311"
] |
u366886346 | p02844 | python | s548080427 | s171632613 | 275 | 98 | 9,232 | 9,356 | Accepted | Accepted | 64.36 | n=int(eval(input()))
s=list(eval(input()))
fa=[n+1]*10
la=[-1]*10
for i in range(n):
s[i]=int(s[i])
if fa[s[i]]>n:
fa[s[i]]=i
la[s[i]]=i
ans=0
for i in range(10):
for j in range(10):
if fa[i]<la[j]:
num=[0]*10
for k in range(fa[i]+1,la[j]):
num[s[k]]=1
ans+=num.count(1)
print(ans)
| n=int(eval(input()))
s=list(eval(input()))
num=list(range(10))
for i in range(10):
num[i]=str(num[i])
ans=0
for i in range(n-2):
if len(num)==0:
break
if s[i] in num:
num2=[str(_) for _ in range(10)]
num.remove(s[i])
for j in range(i+1,n):
if len(num2)==0:
break
if s[j] in num2:
num2.remove(s[j])
ans+=len(set(s[j+1:]))
print(ans)
| 18 | 19 | 371 | 454 | n = int(eval(input()))
s = list(eval(input()))
fa = [n + 1] * 10
la = [-1] * 10
for i in range(n):
s[i] = int(s[i])
if fa[s[i]] > n:
fa[s[i]] = i
la[s[i]] = i
ans = 0
for i in range(10):
for j in range(10):
if fa[i] < la[j]:
num = [0] * 10
for k in range(fa[i] + 1, la[j]):
num[s[k]] = 1
ans += num.count(1)
print(ans)
| n = int(eval(input()))
s = list(eval(input()))
num = list(range(10))
for i in range(10):
num[i] = str(num[i])
ans = 0
for i in range(n - 2):
if len(num) == 0:
break
if s[i] in num:
num2 = [str(_) for _ in range(10)]
num.remove(s[i])
for j in range(i + 1, n):
if len(num2) == 0:
break
if s[j] in num2:
num2.remove(s[j])
ans += len(set(s[j + 1 :]))
print(ans)
| false | 5.263158 | [
"-fa = [n + 1] * 10",
"-la = [-1] * 10",
"-for i in range(n):",
"- s[i] = int(s[i])",
"- if fa[s[i]] > n:",
"- fa[s[i]] = i",
"- la[s[i]] = i",
"+num = list(range(10))",
"+for i in range(10):",
"+ num[i] = str(num[i])",
"-for i in range(10):",
"- for j in range(10):",
"- if fa[i] < la[j]:",
"- num = [0] * 10",
"- for k in range(fa[i] + 1, la[j]):",
"- num[s[k]] = 1",
"- ans += num.count(1)",
"+for i in range(n - 2):",
"+ if len(num) == 0:",
"+ break",
"+ if s[i] in num:",
"+ num2 = [str(_) for _ in range(10)]",
"+ num.remove(s[i])",
"+ for j in range(i + 1, n):",
"+ if len(num2) == 0:",
"+ break",
"+ if s[j] in num2:",
"+ num2.remove(s[j])",
"+ ans += len(set(s[j + 1 :]))"
] | false | 0.053279 | 0.036445 | 1.461886 | [
"s548080427",
"s171632613"
] |
u254871849 | p02844 | python | s987487248 | s513517764 | 29 | 26 | 3,956 | 3,772 | Accepted | Accepted | 10.34 | import sys
from itertools import product
from string import digits
def main():
n, s = sys.stdin.read().split()
n = int(n)
cand = list(''.join(p) for p in product(digits, repeat=3))
res = set()
for c in cand:
i = s.find(c[0])
if i == -1:
continue
j = s.find(c[1], i+1)
if j == -1:
continue
k = s.find(c[2], j+1)
if k == -1:
continue
res.add(c)
ans = len(res)
print(ans)
if __name__ == '__main__':
main() | import sys
from string import digits
def main():
n, s = sys.stdin.read().split()
res = []
for i in digits:
x = s.find(i)
if x == -1:
continue
for j in digits:
y = s.find(j, x+1)
if y == -1:
continue
for k in digits:
z = s.find(k, y+1)
if z == -1:
continue
res.append((i, j, k))
print((len(res)))
if __name__ == '__main__':
main() | 29 | 25 | 576 | 531 | import sys
from itertools import product
from string import digits
def main():
n, s = sys.stdin.read().split()
n = int(n)
cand = list("".join(p) for p in product(digits, repeat=3))
res = set()
for c in cand:
i = s.find(c[0])
if i == -1:
continue
j = s.find(c[1], i + 1)
if j == -1:
continue
k = s.find(c[2], j + 1)
if k == -1:
continue
res.add(c)
ans = len(res)
print(ans)
if __name__ == "__main__":
main()
| import sys
from string import digits
def main():
n, s = sys.stdin.read().split()
res = []
for i in digits:
x = s.find(i)
if x == -1:
continue
for j in digits:
y = s.find(j, x + 1)
if y == -1:
continue
for k in digits:
z = s.find(k, y + 1)
if z == -1:
continue
res.append((i, j, k))
print((len(res)))
if __name__ == "__main__":
main()
| false | 13.793103 | [
"-from itertools import product",
"- n = int(n)",
"- cand = list(\"\".join(p) for p in product(digits, repeat=3))",
"- res = set()",
"- for c in cand:",
"- i = s.find(c[0])",
"- if i == -1:",
"+ res = []",
"+ for i in digits:",
"+ x = s.find(i)",
"+ if x == -1:",
"- j = s.find(c[1], i + 1)",
"- if j == -1:",
"- continue",
"- k = s.find(c[2], j + 1)",
"- if k == -1:",
"- continue",
"- res.add(c)",
"- ans = len(res)",
"- print(ans)",
"+ for j in digits:",
"+ y = s.find(j, x + 1)",
"+ if y == -1:",
"+ continue",
"+ for k in digits:",
"+ z = s.find(k, y + 1)",
"+ if z == -1:",
"+ continue",
"+ res.append((i, j, k))",
"+ print((len(res)))"
] | false | 0.138676 | 0.054518 | 2.54367 | [
"s987487248",
"s513517764"
] |
u186082958 | p02386 | python | s492550061 | s457385090 | 4,290 | 120 | 11,812 | 11,816 | Accepted | Accepted | 97.2 | class Dice:
def __init__(self):
self.u=1
self.w=2
self.s=3
self.e=4
self.n=5
self.d=6
self.dic={"W":0,"S":1,"E":2,"N":3}
def __init__(self,u,w,s,e,n,d):
self.u=u
self.w=w
self.s=s
self.e=e
self.n=n
self.d=d
self.dic={"W":0,"S":1,"E":2,"N":3}
def rot(self,way):
if isinstance(way,str):
way=self.dic[way]
if(way==0):
c=self.u
self.u=self.e
self.e=self.d
self.d=self.w
self.w=c
elif way==1:
c=self.u
self.u=self.n
self.n=self.d
self.d=self.s
self.s=c
elif way==2:
c=self.u
self.u=self.w
self.w=self.d
self.d=self.e
self.e=c
def get_nums(self):
return {self.u,self.w,self.s,self.e,self.n,self.w,self.d}
def mk_dice():
u,s,e,w,n,d=list(map(int,input().split()))
return Dice(u,w,s,e,n,d)
import random
q=int(eval(input()))
dice_col=[]
ans=True
for j in range(q):
dice_b=mk_dice()
for dice in dice_col:
if(dice.get_nums()==dice_b.get_nums()):
for i in range (1000):
dice.rot(random.randint(0,2))
if(dice.u==dice_b.u and dice.d==dice_b.d and dice.w==dice_b.w and dice.s==dice_b.s and dice.e==dice_b.e and dice.n==dice_b.n):
ans=False
dice_col.append(dice_b)
if ans:
print('Yes')
else:
print('No') | class Dice:
def __init__(self):
self.u=1
self.w=2
self.s=3
self.e=4
self.n=5
self.d=6
self.dic={"W":0,"S":1,"E":2,"N":3}
def __init__(self,u,w,s,e,n,d):
self.u=u
self.w=w
self.s=s
self.e=e
self.n=n
self.d=d
self.dic={"W":0,"S":1,"E":2,"N":3}
def rot(self,way):
if isinstance(way,str):
way=self.dic[way]
if(way==0):
c=self.u
self.u=self.e
self.e=self.d
self.d=self.w
self.w=c
elif way==1:
c=self.u
self.u=self.n
self.n=self.d
self.d=self.s
self.s=c
elif way==2:
c=self.u
self.u=self.w
self.w=self.d
self.d=self.e
self.e=c
def get_nums(self):
return {self.u,self.w,self.s,self.e,self.n,self.w,self.d}
def mk_dice():
u,s,e,w,n,d=list(map(int,input().split()))
return Dice(u,w,s,e,n,d)
import random
q=int(eval(input()))
dice_col=[]
ans=True
for j in range(q):
dice_b=mk_dice()
for dice in dice_col:
if(dice.get_nums()==dice_b.get_nums()):
for i in range (1000):
dice.rot(random.randint(0,2))
if(dice.u==dice_b.u and dice.d==dice_b.d and dice.w==dice_b.w and dice.s==dice_b.s and dice.e==dice_b.e and dice.n==dice_b.n):
ans=False
if ~ans:
break
dice_col.append(dice_b)
if ans:
print('Yes')
else:
print('No') | 66 | 68 | 1,619 | 1,656 | class Dice:
def __init__(self):
self.u = 1
self.w = 2
self.s = 3
self.e = 4
self.n = 5
self.d = 6
self.dic = {"W": 0, "S": 1, "E": 2, "N": 3}
def __init__(self, u, w, s, e, n, d):
self.u = u
self.w = w
self.s = s
self.e = e
self.n = n
self.d = d
self.dic = {"W": 0, "S": 1, "E": 2, "N": 3}
def rot(self, way):
if isinstance(way, str):
way = self.dic[way]
if way == 0:
c = self.u
self.u = self.e
self.e = self.d
self.d = self.w
self.w = c
elif way == 1:
c = self.u
self.u = self.n
self.n = self.d
self.d = self.s
self.s = c
elif way == 2:
c = self.u
self.u = self.w
self.w = self.d
self.d = self.e
self.e = c
def get_nums(self):
return {self.u, self.w, self.s, self.e, self.n, self.w, self.d}
def mk_dice():
u, s, e, w, n, d = list(map(int, input().split()))
return Dice(u, w, s, e, n, d)
import random
q = int(eval(input()))
dice_col = []
ans = True
for j in range(q):
dice_b = mk_dice()
for dice in dice_col:
if dice.get_nums() == dice_b.get_nums():
for i in range(1000):
dice.rot(random.randint(0, 2))
if (
dice.u == dice_b.u
and dice.d == dice_b.d
and dice.w == dice_b.w
and dice.s == dice_b.s
and dice.e == dice_b.e
and dice.n == dice_b.n
):
ans = False
dice_col.append(dice_b)
if ans:
print("Yes")
else:
print("No")
| class Dice:
def __init__(self):
self.u = 1
self.w = 2
self.s = 3
self.e = 4
self.n = 5
self.d = 6
self.dic = {"W": 0, "S": 1, "E": 2, "N": 3}
def __init__(self, u, w, s, e, n, d):
self.u = u
self.w = w
self.s = s
self.e = e
self.n = n
self.d = d
self.dic = {"W": 0, "S": 1, "E": 2, "N": 3}
def rot(self, way):
if isinstance(way, str):
way = self.dic[way]
if way == 0:
c = self.u
self.u = self.e
self.e = self.d
self.d = self.w
self.w = c
elif way == 1:
c = self.u
self.u = self.n
self.n = self.d
self.d = self.s
self.s = c
elif way == 2:
c = self.u
self.u = self.w
self.w = self.d
self.d = self.e
self.e = c
def get_nums(self):
return {self.u, self.w, self.s, self.e, self.n, self.w, self.d}
def mk_dice():
u, s, e, w, n, d = list(map(int, input().split()))
return Dice(u, w, s, e, n, d)
import random
q = int(eval(input()))
dice_col = []
ans = True
for j in range(q):
dice_b = mk_dice()
for dice in dice_col:
if dice.get_nums() == dice_b.get_nums():
for i in range(1000):
dice.rot(random.randint(0, 2))
if (
dice.u == dice_b.u
and dice.d == dice_b.d
and dice.w == dice_b.w
and dice.s == dice_b.s
and dice.e == dice_b.e
and dice.n == dice_b.n
):
ans = False
if ~ans:
break
dice_col.append(dice_b)
if ans:
print("Yes")
else:
print("No")
| false | 2.941176 | [
"+ if ~ans:",
"+ break"
] | false | 0.048714 | 0.04122 | 1.181822 | [
"s492550061",
"s457385090"
] |
u891504219 | p02791 | python | s765403210 | s642023385 | 95 | 76 | 24,744 | 26,012 | Accepted | Accepted | 20 | N = int(eval(input()))
P_list = list(map(int,input().split()))
i_num = 0
min_P = P_list[0]
for p in P_list:
if p <= min_P:
min_P = p
i_num += 1
print(i_num) | def main():
N = int(eval(input()))
P_list = list(map(int,input().split()))
i_num = 0
min_P = P_list[0]
for p in P_list:
if p <= min_P:
min_P = p
i_num += 1
print(i_num)
if __name__ == "__main__":
main() | 9 | 13 | 178 | 269 | N = int(eval(input()))
P_list = list(map(int, input().split()))
i_num = 0
min_P = P_list[0]
for p in P_list:
if p <= min_P:
min_P = p
i_num += 1
print(i_num)
| def main():
N = int(eval(input()))
P_list = list(map(int, input().split()))
i_num = 0
min_P = P_list[0]
for p in P_list:
if p <= min_P:
min_P = p
i_num += 1
print(i_num)
if __name__ == "__main__":
main()
| false | 30.769231 | [
"-N = int(eval(input()))",
"-P_list = list(map(int, input().split()))",
"-i_num = 0",
"-min_P = P_list[0]",
"-for p in P_list:",
"- if p <= min_P:",
"- min_P = p",
"- i_num += 1",
"-print(i_num)",
"+def main():",
"+ N = int(eval(input()))",
"+ P_list = list(map(int, input().split()))",
"+ i_num = 0",
"+ min_P = P_list[0]",
"+ for p in P_list:",
"+ if p <= min_P:",
"+ min_P = p",
"+ i_num += 1",
"+ print(i_num)",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.04694 | 0.047536 | 0.987465 | [
"s765403210",
"s642023385"
] |
u970899068 | p02685 | python | s351063127 | s243961007 | 365 | 284 | 167,868 | 168,120 | Accepted | Accepted | 22.19 | # 二項係数のmod (大量のmod計算が必要なとき)
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=998244353
N = 10 ** 6 # 出力の制限
g1 = [1, 1] # 元テーブル
g2 = [1, 1] # 逆元テーブル
inverse = [0, 1] # 逆元テーブル計算用テーブル
for i in range(2, N + 1):
g1.append((g1[-1] * i) % mod)
inverse.append((-inverse[mod % i] * (mod // i)) % mod)
g2.append((g2[-1] * inverse[-1]) % mod)
n,m,k= list(map(int, input().split()))
ans=0
# 同じ色で塗る組数で場合分け
for i in range(k+1):
# 同色の組の色の割り当て
v1=m*pow(m-1,n-i-1,mod)
# グループの分け方
v2=cmb(n-1,i,mod)
ans+=v1*v2
ans%=mod
print(ans) | # 二項係数のmod (大量のmod計算が必要なとき)
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=998244353
N = 10 ** 6 # 出力の制限
g1 = [1, 1] # 元テーブル
g2 = [1, 1] # 逆元テーブル
inverse = [0, 1] # 逆元テーブル計算用テーブル
for i in range(2, N + 1):
g1.append((g1[-1] * i) % mod)
inverse.append((-inverse[mod % i] * (mod // i)) % mod)
g2.append((g2[-1] * inverse[-1]) % mod)
n,m,k= list(map(int, input().split()))
ans=0
# 同じ色で塗る組数で場合分け
for i in range(k,-1,-1):
# 同色の組の色の割り当て
if i==k:
v1 = m * pow(m - 1, n - i - 1, mod)
else:
v1*=m-1
v1%=mod
# グループの分け方
v2=cmb(n-1,i,mod)
ans+=v1*v2
ans%=mod
print(ans) | 33 | 38 | 660 | 741 | # 二項係数のmod (大量のmod計算が必要なとき)
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 = 998244353
N = 10**6 # 出力の制限
g1 = [1, 1] # 元テーブル
g2 = [1, 1] # 逆元テーブル
inverse = [0, 1] # 逆元テーブル計算用テーブル
for i in range(2, N + 1):
g1.append((g1[-1] * i) % mod)
inverse.append((-inverse[mod % i] * (mod // i)) % mod)
g2.append((g2[-1] * inverse[-1]) % mod)
n, m, k = list(map(int, input().split()))
ans = 0
# 同じ色で塗る組数で場合分け
for i in range(k + 1):
# 同色の組の色の割り当て
v1 = m * pow(m - 1, n - i - 1, mod)
# グループの分け方
v2 = cmb(n - 1, i, mod)
ans += v1 * v2
ans %= mod
print(ans)
| # 二項係数のmod (大量のmod計算が必要なとき)
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 = 998244353
N = 10**6 # 出力の制限
g1 = [1, 1] # 元テーブル
g2 = [1, 1] # 逆元テーブル
inverse = [0, 1] # 逆元テーブル計算用テーブル
for i in range(2, N + 1):
g1.append((g1[-1] * i) % mod)
inverse.append((-inverse[mod % i] * (mod // i)) % mod)
g2.append((g2[-1] * inverse[-1]) % mod)
n, m, k = list(map(int, input().split()))
ans = 0
# 同じ色で塗る組数で場合分け
for i in range(k, -1, -1):
# 同色の組の色の割り当て
if i == k:
v1 = m * pow(m - 1, n - i - 1, mod)
else:
v1 *= m - 1
v1 %= mod
# グループの分け方
v2 = cmb(n - 1, i, mod)
ans += v1 * v2
ans %= mod
print(ans)
| false | 13.157895 | [
"-for i in range(k + 1):",
"+for i in range(k, -1, -1):",
"- v1 = m * pow(m - 1, n - i - 1, mod)",
"+ if i == k:",
"+ v1 = m * pow(m - 1, n - i - 1, mod)",
"+ else:",
"+ v1 *= m - 1",
"+ v1 %= mod"
] | false | 0.00693 | 1.662284 | 0.004169 | [
"s351063127",
"s243961007"
] |
u879870653 | p03835 | python | s459543164 | s646660606 | 1,621 | 1,473 | 3,316 | 2,940 | Accepted | Accepted | 9.13 | ans = 0
k,s = list(map(int,input().split()))
for x in range(k+1) :
for y in range(k+1) :
z = s - (x+y)
if z >= 0 and z <= k :
ans += 1
print(ans)
| K,S = list(map(int,input().split()))
ans = 0
for x in range(K+1) :
for y in range(K+1) :
z = S-x-y
if 0 <= z <= K :
ans += 1
print(ans) | 10 | 8 | 195 | 168 | ans = 0
k, s = list(map(int, input().split()))
for x in range(k + 1):
for y in range(k + 1):
z = s - (x + y)
if z >= 0 and z <= k:
ans += 1
print(ans)
| K, S = list(map(int, input().split()))
ans = 0
for x in range(K + 1):
for y in range(K + 1):
z = S - x - y
if 0 <= z <= K:
ans += 1
print(ans)
| false | 20 | [
"+K, S = list(map(int, input().split()))",
"-k, s = list(map(int, input().split()))",
"-for x in range(k + 1):",
"- for y in range(k + 1):",
"- z = s - (x + y)",
"- if z >= 0 and z <= k:",
"+for x in range(K + 1):",
"+ for y in range(K + 1):",
"+ z = S - x - y",
"+ if 0 <= z <= K:"
] | false | 0.123056 | 0.039077 | 3.149071 | [
"s459543164",
"s646660606"
] |
u492447501 | p02923 | python | s500284898 | s895846600 | 81 | 67 | 14,252 | 14,252 | Accepted | Accepted | 17.28 | N = int(eval(input()))
*H, = list(map(int, input().split()))
max = 0
count = 0
node = 0
while node<N-1:
if H[node]<H[node+1]:
if max < count:
max = count
count = 0
node = node + 1
continue
count = count + 1
node = node + 1
if max < count:
max = count
print(max) | N = int(eval(input()))
*H, = list(map(int, input().split()))
max = 0
temp = 0
for h_index in range(0, len(H)-1, 1):
if H[h_index]>=H[h_index+1]:
temp = temp + 1
continue
if max < temp:
max = temp
temp = 0
if max < temp:
max = temp
print(max) | 20 | 17 | 331 | 288 | N = int(eval(input()))
(*H,) = list(map(int, input().split()))
max = 0
count = 0
node = 0
while node < N - 1:
if H[node] < H[node + 1]:
if max < count:
max = count
count = 0
node = node + 1
continue
count = count + 1
node = node + 1
if max < count:
max = count
print(max)
| N = int(eval(input()))
(*H,) = list(map(int, input().split()))
max = 0
temp = 0
for h_index in range(0, len(H) - 1, 1):
if H[h_index] >= H[h_index + 1]:
temp = temp + 1
continue
if max < temp:
max = temp
temp = 0
if max < temp:
max = temp
print(max)
| false | 15 | [
"-count = 0",
"-node = 0",
"-while node < N - 1:",
"- if H[node] < H[node + 1]:",
"- if max < count:",
"- max = count",
"- count = 0",
"- node = node + 1",
"+temp = 0",
"+for h_index in range(0, len(H) - 1, 1):",
"+ if H[h_index] >= H[h_index + 1]:",
"+ temp = temp + 1",
"- count = count + 1",
"- node = node + 1",
"-if max < count:",
"- max = count",
"+ if max < temp:",
"+ max = temp",
"+ temp = 0",
"+if max < temp:",
"+ max = temp"
] | false | 0.038973 | 0.039298 | 0.991754 | [
"s500284898",
"s895846600"
] |
u223663729 | p02838 | python | s670667694 | s461383522 | 1,885 | 239 | 49,232 | 65,676 | Accepted | Accepted | 87.32 | N, *A = list(map(int, open(0).read().split()))
mod = 10**9 + 7
ans = 0
for i in range(60):
mask = 1 << i
cnt = 0
for a in A:
if a & mask:
cnt += 1
x = cnt * (N-cnt)
x *= mask % mod
ans += x
ans %= mod
print(ans) | import numpy as np
N, *A = list(map(int, open(0).read().split()))
A = np.array(A, dtype=np.int64)
mod = 10**9 + 7
ans = 0
for i in range(60):
mask = 1 << i
cnt = np.count_nonzero(A&mask)
x = cnt * (N-cnt)
x *= mask % mod
ans += x
ans %= mod
print(ans) | 16 | 15 | 270 | 285 | N, *A = list(map(int, open(0).read().split()))
mod = 10**9 + 7
ans = 0
for i in range(60):
mask = 1 << i
cnt = 0
for a in A:
if a & mask:
cnt += 1
x = cnt * (N - cnt)
x *= mask % mod
ans += x
ans %= mod
print(ans)
| import numpy as np
N, *A = list(map(int, open(0).read().split()))
A = np.array(A, dtype=np.int64)
mod = 10**9 + 7
ans = 0
for i in range(60):
mask = 1 << i
cnt = np.count_nonzero(A & mask)
x = cnt * (N - cnt)
x *= mask % mod
ans += x
ans %= mod
print(ans)
| false | 6.25 | [
"+import numpy as np",
"+",
"+A = np.array(A, dtype=np.int64)",
"- cnt = 0",
"- for a in A:",
"- if a & mask:",
"- cnt += 1",
"+ cnt = np.count_nonzero(A & mask)"
] | false | 0.084793 | 0.266313 | 0.318396 | [
"s670667694",
"s461383522"
] |
u843482581 | p03478 | python | s801741759 | s327169510 | 32 | 29 | 9,132 | 9,112 | Accepted | Accepted | 9.38 | N, A, B = list(map(int, input().split()))
Sum = 0
for i in range(N):
o = (i+1)//10000
a = (i+1)%10000//1000
b = (i+1)%1000//100
c = (i+1)%100//10
d = (i+1)%10
e= o+a+b+c+d
if e >= A and e <= B:
Sum = Sum + (i+1)
print(Sum) | def FindSumOfDigits(n):
Sum = 0
while n>0:
Sum += n%10
n //= 10
return Sum
N, A, B = list(map(int, input().split()))
total = 0
for i in range(N):
Sum = FindSumOfDigits(i+1)
if A <= Sum and Sum <= B:
total += i+1
print(total)
| 14 | 15 | 249 | 257 | N, A, B = list(map(int, input().split()))
Sum = 0
for i in range(N):
o = (i + 1) // 10000
a = (i + 1) % 10000 // 1000
b = (i + 1) % 1000 // 100
c = (i + 1) % 100 // 10
d = (i + 1) % 10
e = o + a + b + c + d
if e >= A and e <= B:
Sum = Sum + (i + 1)
print(Sum)
| def FindSumOfDigits(n):
Sum = 0
while n > 0:
Sum += n % 10
n //= 10
return Sum
N, A, B = list(map(int, input().split()))
total = 0
for i in range(N):
Sum = FindSumOfDigits(i + 1)
if A <= Sum and Sum <= B:
total += i + 1
print(total)
| false | 6.666667 | [
"+def FindSumOfDigits(n):",
"+ Sum = 0",
"+ while n > 0:",
"+ Sum += n % 10",
"+ n //= 10",
"+ return Sum",
"+",
"+",
"-Sum = 0",
"+total = 0",
"- o = (i + 1) // 10000",
"- a = (i + 1) % 10000 // 1000",
"- b = (i + 1) % 1000 // 100",
"- c = (i + 1) % 100 // 10",
"- d = (i + 1) % 10",
"- e = o + a + b + c + d",
"- if e >= A and e <= B:",
"- Sum = Sum + (i + 1)",
"-print(Sum)",
"+ Sum = FindSumOfDigits(i + 1)",
"+ if A <= Sum and Sum <= B:",
"+ total += i + 1",
"+print(total)"
] | false | 0.0464 | 0.04916 | 0.943872 | [
"s801741759",
"s327169510"
] |
u298297089 | p03001 | python | s838395408 | s132539835 | 19 | 17 | 2,940 | 2,940 | Accepted | Accepted | 10.53 | W,H,x,y = list(map(int, input().split()))
print(('{:.9f}'.format(W*H/2), 1 if W / 2 == x and H / 2 == y else 0)) | w,h,x,y = list(map(int,input().split()))
print(('{:.12f}'.format(w * h / 2), 1 if w / 2 == x and h / 2 == y else 0))
| 3 | 2 | 107 | 110 | W, H, x, y = list(map(int, input().split()))
print(("{:.9f}".format(W * H / 2), 1 if W / 2 == x and H / 2 == y else 0))
| w, h, x, y = list(map(int, input().split()))
print(("{:.12f}".format(w * h / 2), 1 if w / 2 == x and h / 2 == y else 0))
| false | 33.333333 | [
"-W, H, x, y = list(map(int, input().split()))",
"-print((\"{:.9f}\".format(W * H / 2), 1 if W / 2 == x and H / 2 == y else 0))",
"+w, h, x, y = list(map(int, input().split()))",
"+print((\"{:.12f}\".format(w * h / 2), 1 if w / 2 == x and h / 2 == y else 0))"
] | false | 0.037554 | 0.038115 | 0.985269 | [
"s838395408",
"s132539835"
] |
u347640436 | p03108 | python | s397792795 | s511539480 | 657 | 420 | 39,988 | 43,440 | Accepted | Accepted | 36.07 | # Union Find 木
from sys import setrecursionlimit
def find(parent, i):
t = parent[i]
if t < 0:
return i
t = find(parent, t)
parent[i] = t
return t
def unite(parent, i, j):
i = find(parent, i)
j = find(parent, j)
if i == j:
return
parent[j] += parent[i]
parent[i] = j
setrecursionlimit(10 ** 5)
N, M = list(map(int, input().split()))
AB = [[int(c) - 1 for c in input().split()] for _ in range(M)]
parent = [-1] * N
inconvenience = N * (N - 1) // 2
result = []
for a, b in AB[::-1]:
result.append(inconvenience)
pa, pb = find(parent, a), find(parent, b)
if pa != pb:
inconvenience -= parent[pa] * parent[pb]
unite(parent, a, b)
print((*result[::-1]))
| # Union Find 木
from sys import setrecursionlimit
def find(parent, i):
t = parent[i]
if t < 0:
return i
t = find(parent, t)
parent[i] = t
return t
def unite(parent, i, j):
i = find(parent, i)
j = find(parent, j)
if i == j:
return
parent[j] += parent[i]
parent[i] = j
setrecursionlimit(10 ** 6)
N, M = list(map(int, input().split()))
AB = [[int(c) - 1 for c in input().split()] for _ in range(M)]
parent = [-1] * N
inconvenience = N * (N - 1) // 2
result = []
for a, b in AB[::-1]:
result.append(inconvenience)
pa, pb = find(parent, a), find(parent, b)
if pa != pb:
inconvenience -= parent[pa] * parent[pb]
unite(parent, a, b)
print((*result[::-1]))
| 37 | 37 | 764 | 764 | # Union Find 木
from sys import setrecursionlimit
def find(parent, i):
t = parent[i]
if t < 0:
return i
t = find(parent, t)
parent[i] = t
return t
def unite(parent, i, j):
i = find(parent, i)
j = find(parent, j)
if i == j:
return
parent[j] += parent[i]
parent[i] = j
setrecursionlimit(10**5)
N, M = list(map(int, input().split()))
AB = [[int(c) - 1 for c in input().split()] for _ in range(M)]
parent = [-1] * N
inconvenience = N * (N - 1) // 2
result = []
for a, b in AB[::-1]:
result.append(inconvenience)
pa, pb = find(parent, a), find(parent, b)
if pa != pb:
inconvenience -= parent[pa] * parent[pb]
unite(parent, a, b)
print((*result[::-1]))
| # Union Find 木
from sys import setrecursionlimit
def find(parent, i):
t = parent[i]
if t < 0:
return i
t = find(parent, t)
parent[i] = t
return t
def unite(parent, i, j):
i = find(parent, i)
j = find(parent, j)
if i == j:
return
parent[j] += parent[i]
parent[i] = j
setrecursionlimit(10**6)
N, M = list(map(int, input().split()))
AB = [[int(c) - 1 for c in input().split()] for _ in range(M)]
parent = [-1] * N
inconvenience = N * (N - 1) // 2
result = []
for a, b in AB[::-1]:
result.append(inconvenience)
pa, pb = find(parent, a), find(parent, b)
if pa != pb:
inconvenience -= parent[pa] * parent[pb]
unite(parent, a, b)
print((*result[::-1]))
| false | 0 | [
"-setrecursionlimit(10**5)",
"+setrecursionlimit(10**6)"
] | false | 0.036755 | 0.045019 | 0.816449 | [
"s397792795",
"s511539480"
] |
u690037900 | p03607 | python | s834448266 | s866881484 | 213 | 166 | 14,824 | 20,888 | Accepted | Accepted | 22.07 |
N=int(eval(input()))
S=set()
for i in range(N):
s=str(eval(input()))
S^={s}
print((len(S))) | from collections import Counter
n=int(eval(input()))
L=[int(eval(input())) for i in range(n)]
L1=Counter(L)
ans=0
for i in L1:
if L1[i]%2!=0:
ans+=1
print(ans) | 7 | 9 | 92 | 167 | N = int(eval(input()))
S = set()
for i in range(N):
s = str(eval(input()))
S ^= {s}
print((len(S)))
| from collections import Counter
n = int(eval(input()))
L = [int(eval(input())) for i in range(n)]
L1 = Counter(L)
ans = 0
for i in L1:
if L1[i] % 2 != 0:
ans += 1
print(ans)
| false | 22.222222 | [
"-N = int(eval(input()))",
"-S = set()",
"-for i in range(N):",
"- s = str(eval(input()))",
"- S ^= {s}",
"-print((len(S)))",
"+from collections import Counter",
"+",
"+n = int(eval(input()))",
"+L = [int(eval(input())) for i in range(n)]",
"+L1 = Counter(L)",
"+ans = 0",
"+for i in L1:",
"+ if L1[i] % 2 != 0:",
"+ ans += 1",
"+print(ans)"
] | false | 0.04203 | 0.037705 | 1.114721 | [
"s834448266",
"s866881484"
] |
u186838327 | p03835 | python | s516266980 | s580232365 | 1,246 | 269 | 2,940 | 41,052 | Accepted | Accepted | 78.41 | k, s = list(map(int, input().split()))
ans = 0
for x in range(k+1):
for y in range(k+1):
if 0 <= (s-x-y) <=k:
ans +=1
print(ans) | k,s = list(map(int, input().split()))
ans = 0
for x in range(k+1):
for y in range(k+1):
z = s-x-y
if 0 <= z and z <= k:
ans += 1
print(ans)
| 7 | 8 | 156 | 173 | k, s = list(map(int, input().split()))
ans = 0
for x in range(k + 1):
for y in range(k + 1):
if 0 <= (s - x - y) <= k:
ans += 1
print(ans)
| k, s = list(map(int, input().split()))
ans = 0
for x in range(k + 1):
for y in range(k + 1):
z = s - x - y
if 0 <= z and z <= k:
ans += 1
print(ans)
| false | 12.5 | [
"- if 0 <= (s - x - y) <= k:",
"+ z = s - x - y",
"+ if 0 <= z and z <= k:"
] | false | 0.064173 | 0.040251 | 1.594304 | [
"s516266980",
"s580232365"
] |
u369133448 | p02947 | python | s135954863 | s553708203 | 1,656 | 1,491 | 23,160 | 23,228 | Accepted | Accepted | 9.96 | n=int(eval(input()))
dic={}
for i in range(n):
wk={}
s=eval(input())
for i in range(len(s)):
if s[i] in wk:
wk[s[i]]+=1
else:
wk[s[i]]=1
list=sorted(list(wk.items()),key=lambda x:x[0])
key="".join(map(str,list(dict(list).items())))
if key in dic:
dic[key]+=1
else:
dic[key]=1
ans=0
for i in list(dic.values()):
if i==1:
continue
else:
ans+=i*(i-1)/2
print((int(ans))) | n=int(eval(input()))
dic={}
for i in range(n):
wk={}
s=eval(input())
for i in range(len(s)):
if s[i] in wk:
wk[s[i]]+=1
else:
wk[s[i]]=1
list=sorted(list(wk.items()),key=lambda x:x[0])
key="".join(map(str,list))
if key in dic:
dic[key]+=1
else:
dic[key]=1
ans=0
for i in list(dic.values()):
if i==1:
continue
else:
ans+=i*(i-1)/2
print((int(ans))) | 23 | 23 | 411 | 397 | n = int(eval(input()))
dic = {}
for i in range(n):
wk = {}
s = eval(input())
for i in range(len(s)):
if s[i] in wk:
wk[s[i]] += 1
else:
wk[s[i]] = 1
list = sorted(list(wk.items()), key=lambda x: x[0])
key = "".join(map(str, list(dict(list).items())))
if key in dic:
dic[key] += 1
else:
dic[key] = 1
ans = 0
for i in list(dic.values()):
if i == 1:
continue
else:
ans += i * (i - 1) / 2
print((int(ans)))
| n = int(eval(input()))
dic = {}
for i in range(n):
wk = {}
s = eval(input())
for i in range(len(s)):
if s[i] in wk:
wk[s[i]] += 1
else:
wk[s[i]] = 1
list = sorted(list(wk.items()), key=lambda x: x[0])
key = "".join(map(str, list))
if key in dic:
dic[key] += 1
else:
dic[key] = 1
ans = 0
for i in list(dic.values()):
if i == 1:
continue
else:
ans += i * (i - 1) / 2
print((int(ans)))
| false | 0 | [
"- key = \"\".join(map(str, list(dict(list).items())))",
"+ key = \"\".join(map(str, list))"
] | false | 0.036005 | 0.037603 | 0.957504 | [
"s135954863",
"s553708203"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.