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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
u699296734 | p03317 | python | s682182508 | s378748518 | 60 | 55 | 20,480 | 20,572 | Accepted | Accepted | 8.33 | n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
now = k
res = 1
while now < n:
now += k-1
res += 1
print(res) | n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
if (n + k - 1) // k == 1:
print((1))
else:
res = ((n - k) + (k - 2)) // (k - 1) + 1
print(res)
| 10 | 8 | 149 | 182 | n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
now = k
res = 1
while now < n:
now += k - 1
res += 1
print(res)
| n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
if (n + k - 1) // k == 1:
print((1))
else:
res = ((n - k) + (k - 2)) // (k - 1) + 1
print(res)
| false | 20 | [
"-now = k",
"-res = 1",
"-while now < n:",
"- now += k - 1",
"- res += 1",
"-print(res)",
"+if (n + k - 1) // k == 1:",
"+ print((1))",
"+else:",
"+ res = ((n - k) + (k - 2)) // (k - 1) + 1",
"+ print(res)"
] | false | 0.036335 | 0.035785 | 1.015373 | [
"s682182508",
"s378748518"
] |
u585482323 | p02953 | python | s294616356 | s011044792 | 235 | 200 | 60,144 | 58,224 | Accepted | Accepted | 14.89 | #!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007
#A
def A():
a,b,c = LI()
c -= a-b
print((max(0,c)))
return
#B
def B():
n = I()
ans = 0
for i in range(1,n+1):
s = str(i)
if len(s)%2:
ans += 1
print(ans)
return
#C
def C():
n = I()
h = LI()
h[0] -= 1
for i in range(n-1):
if h[i+1] < h[i]:
print("No")
return
if h[i+1] > h[i]:
h[i+1] -= 1
print("Yes")
return
#D
def D():
return
#E
def E():
return
#F
def F():
return
#Solve
if __name__ == "__main__":
C()
| #!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007
def solve():
n = I()
h = LI()
m = h[0]-1
for i in h[1:]:
if m > i:
print("No")
return
m = max(m,i-1)
print("Yes")
return
#Solve
if __name__ == "__main__":
solve()
| 78 | 42 | 1,312 | 989 | #!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI():
return [int(x) for x in sys.stdin.readline().split()]
def I():
return int(sys.stdin.readline())
def LS():
return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007
# A
def A():
a, b, c = LI()
c -= a - b
print((max(0, c)))
return
# B
def B():
n = I()
ans = 0
for i in range(1, n + 1):
s = str(i)
if len(s) % 2:
ans += 1
print(ans)
return
# C
def C():
n = I()
h = LI()
h[0] -= 1
for i in range(n - 1):
if h[i + 1] < h[i]:
print("No")
return
if h[i + 1] > h[i]:
h[i + 1] -= 1
print("Yes")
return
# D
def D():
return
# E
def E():
return
# F
def F():
return
# Solve
if __name__ == "__main__":
C()
| #!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI():
return [int(x) for x in sys.stdin.buffer.readline().split()]
def I():
return int(sys.stdin.buffer.readline())
def LS():
return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007
def solve():
n = I()
h = LI()
m = h[0] - 1
for i in h[1:]:
if m > i:
print("No")
return
m = max(m, i - 1)
print("Yes")
return
# Solve
if __name__ == "__main__":
solve()
| false | 46.153846 | [
"+from itertools import permutations, accumulate",
"-import random",
"- return [int(x) for x in sys.stdin.readline().split()]",
"+ return [int(x) for x in sys.stdin.buffer.readline().split()]",
"- return int(sys.stdin.readline())",
"+ return int(sys.stdin.buffer.readline())",
"-# A",
"-def A():",
"- a, b, c = LI()",
"- c -= a - b",
"- print((max(0, c)))",
"- return",
"-# B",
"-def B():",
"- n = I()",
"- ans = 0",
"- for i in range(1, n + 1):",
"- s = str(i)",
"- if len(s) % 2:",
"- ans += 1",
"- print(ans)",
"- return",
"-",
"-",
"-# C",
"-def C():",
"+def solve():",
"- h[0] -= 1",
"- for i in range(n - 1):",
"- if h[i + 1] < h[i]:",
"+ m = h[0] - 1",
"+ for i in h[1:]:",
"+ if m > i:",
"- if h[i + 1] > h[i]:",
"- h[i + 1] -= 1",
"+ m = max(m, i - 1)",
"- return",
"-",
"-",
"-# D",
"-def D():",
"- return",
"-",
"-",
"-# E",
"-def E():",
"- return",
"-",
"-",
"-# F",
"-def F():",
"- C()",
"+ solve()"
] | false | 0.045222 | 0.043239 | 1.045853 | [
"s294616356",
"s011044792"
] |
u023229441 | p03044 | python | s489874273 | s196692915 | 882 | 461 | 85,700 | 172,128 | Accepted | Accepted | 47.73 | import copy ; import sys ; sys.setrecursionlimit(11451419)
n=int(eval(input()))
color=[-1 for i in range(n)]
color[0]=1
G=[[] for i in range(n)]
for i in range(n-1):
a,b,d=list(map(int,input().split()))
G[a-1].append([b-1,d])
G[b-1].append([a-1,d])
def dfs(x):
for i,dis in G[x]:
if color[i] != -1: continue
if dis %2==1:
color[i]=1-color[x]
else:
color[i]=color[x]
dfs(i)
dfs(0)
for i in range(n):
print((color[i]))
| import sys
mod=10**9+7 ; inf=float("inf")
from math import sqrt, ceil
from collections import deque, Counter, defaultdict #すべてのkeyが用意されてる defaultdict(int)で初期化
input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from decimal import ROUND_HALF_UP,Decimal #変換後の末尾桁を0や0.01で指定
#Decimal((str(0.5)).quantize(Decimal('0'), rounding=ROUND_HALF_UP))
from functools import lru_cache
from bisect import bisect_left as bileft, bisect_right as biright
#メモ化再帰defの冒頭に毎回 @lru_cache(maxsize=10**10)
#引数にlistはだめ
#######ここまでテンプレ#######
#ソート、"a"+"b"、再帰ならPython3の方がいい
#######ここから天ぷら########
n=int(eval(input()))
G=[[] for i in range(n)]
for i in range(n-1):
a,b,w=list(map(int,input().split()))
a-=1;b-=1
G[a].append((b,w))
G[b].append((a,w))
C=[-1]*n
C[0]=0
def dfs(x):
for v,w in G[x]:
if C[v]==-1:
C[v]=1-C[x] if w%2==1 else C[x]
dfs(v)
dfs(0)
# print(G)
for i in range(n):
print((C[i]))
| 24 | 35 | 482 | 974 | import copy
import sys
sys.setrecursionlimit(11451419)
n = int(eval(input()))
color = [-1 for i in range(n)]
color[0] = 1
G = [[] for i in range(n)]
for i in range(n - 1):
a, b, d = list(map(int, input().split()))
G[a - 1].append([b - 1, d])
G[b - 1].append([a - 1, d])
def dfs(x):
for i, dis in G[x]:
if color[i] != -1:
continue
if dis % 2 == 1:
color[i] = 1 - color[x]
else:
color[i] = color[x]
dfs(i)
dfs(0)
for i in range(n):
print((color[i]))
| import sys
mod = 10**9 + 7
inf = float("inf")
from math import sqrt, ceil
from collections import (
deque,
Counter,
defaultdict,
) # すべてのkeyが用意されてる defaultdict(int)で初期化
input = lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from decimal import ROUND_HALF_UP, Decimal # 変換後の末尾桁を0や0.01で指定
# Decimal((str(0.5)).quantize(Decimal('0'), rounding=ROUND_HALF_UP))
from functools import lru_cache
from bisect import bisect_left as bileft, bisect_right as biright
# メモ化再帰defの冒頭に毎回 @lru_cache(maxsize=10**10)
# 引数にlistはだめ
#######ここまでテンプレ#######
# ソート、"a"+"b"、再帰ならPython3の方がいい
#######ここから天ぷら########
n = int(eval(input()))
G = [[] for i in range(n)]
for i in range(n - 1):
a, b, w = list(map(int, input().split()))
a -= 1
b -= 1
G[a].append((b, w))
G[b].append((a, w))
C = [-1] * n
C[0] = 0
def dfs(x):
for v, w in G[x]:
if C[v] == -1:
C[v] = 1 - C[x] if w % 2 == 1 else C[x]
dfs(v)
dfs(0)
# print(G)
for i in range(n):
print((C[i]))
| false | 31.428571 | [
"-import copy",
"+mod = 10**9 + 7",
"+inf = float(\"inf\")",
"+from math import sqrt, ceil",
"+from collections import (",
"+ deque,",
"+ Counter,",
"+ defaultdict,",
"+) # すべてのkeyが用意されてる defaultdict(int)で初期化",
"+",
"+input = lambda: sys.stdin.readline().strip()",
"+from decimal import ROUND_HALF_UP, Decimal # 変換後の末尾桁を0や0.01で指定",
"+",
"+# Decimal((str(0.5)).quantize(Decimal('0'), rounding=ROUND_HALF_UP))",
"+from functools import lru_cache",
"+from bisect import bisect_left as bileft, bisect_right as biright",
"+",
"+# メモ化再帰defの冒頭に毎回 @lru_cache(maxsize=10**10)",
"+# 引数にlistはだめ",
"+#######ここまでテンプレ#######",
"+# ソート、\"a\"+\"b\"、再帰ならPython3の方がいい",
"+#######ここから天ぷら########",
"-color = [-1 for i in range(n)]",
"-color[0] = 1",
"- a, b, d = list(map(int, input().split()))",
"- G[a - 1].append([b - 1, d])",
"- G[b - 1].append([a - 1, d])",
"+ a, b, w = list(map(int, input().split()))",
"+ a -= 1",
"+ b -= 1",
"+ G[a].append((b, w))",
"+ G[b].append((a, w))",
"+C = [-1] * n",
"+C[0] = 0",
"- for i, dis in G[x]:",
"- if color[i] != -1:",
"- continue",
"- if dis % 2 == 1:",
"- color[i] = 1 - color[x]",
"- else:",
"- color[i] = color[x]",
"- dfs(i)",
"+ for v, w in G[x]:",
"+ if C[v] == -1:",
"+ C[v] = 1 - C[x] if w % 2 == 1 else C[x]",
"+ dfs(v)",
"+# print(G)",
"- print((color[i]))",
"+ print((C[i]))"
] | false | 0.040918 | 0.04209 | 0.972154 | [
"s489874273",
"s196692915"
] |
u411203878 | p03476 | python | s975707913 | s164868747 | 1,110 | 738 | 53,340 | 93,836 | Accepted | Accepted | 33.51 | import math
def is_prime(n):
if n==1 :
return False
for k in range(2,int(math.sqrt(n))+1):
if n%k==0:
return False
return True
count = [0]
buf = 0
for i in range(1, 10**5 + 2):
if i % 2 == 0:
count.append(buf)
continue
hantei1 = is_prime(i)
hantei2 = is_prime((i+1)//2)
if hantei1 and hantei2:
buf += 1
count.append(buf)
q = int(eval(input()))
for i in range(q):
l,r = list(map(int,input().split()))
print((count[r]-count[l-1])) | def prime(p):
primeFlag = True
if p == 1:
primeFlag = False
for i in range(2,(int(p**0.5)+1)):
if p%i==0:
primeFlag = False
break
if primeFlag:
return True
else:
return False
Q = int(eval(input()))
memo = [0]*100001
for i in range(2,100001):
first = prime(i)
second = prime((i+1)//2)
if first and second:
memo[i] = 1
for i in range(1,100001):
memo[i] = memo[i-1]+memo[i]
for i in range(Q):
l,r = list(map(int,input().split()))
print((memo[r]-memo[l-1])) | 32 | 29 | 546 | 584 | import math
def is_prime(n):
if n == 1:
return False
for k in range(2, int(math.sqrt(n)) + 1):
if n % k == 0:
return False
return True
count = [0]
buf = 0
for i in range(1, 10**5 + 2):
if i % 2 == 0:
count.append(buf)
continue
hantei1 = is_prime(i)
hantei2 = is_prime((i + 1) // 2)
if hantei1 and hantei2:
buf += 1
count.append(buf)
q = int(eval(input()))
for i in range(q):
l, r = list(map(int, input().split()))
print((count[r] - count[l - 1]))
| def prime(p):
primeFlag = True
if p == 1:
primeFlag = False
for i in range(2, (int(p**0.5) + 1)):
if p % i == 0:
primeFlag = False
break
if primeFlag:
return True
else:
return False
Q = int(eval(input()))
memo = [0] * 100001
for i in range(2, 100001):
first = prime(i)
second = prime((i + 1) // 2)
if first and second:
memo[i] = 1
for i in range(1, 100001):
memo[i] = memo[i - 1] + memo[i]
for i in range(Q):
l, r = list(map(int, input().split()))
print((memo[r] - memo[l - 1]))
| false | 9.375 | [
"-import math",
"+def prime(p):",
"+ primeFlag = True",
"+ if p == 1:",
"+ primeFlag = False",
"+ for i in range(2, (int(p**0.5) + 1)):",
"+ if p % i == 0:",
"+ primeFlag = False",
"+ break",
"+ if primeFlag:",
"+ return True",
"+ else:",
"+ return False",
"-def is_prime(n):",
"- if n == 1:",
"- return False",
"- for k in range(2, int(math.sqrt(n)) + 1):",
"- if n % k == 0:",
"- return False",
"- return True",
"-",
"-",
"-count = [0]",
"-buf = 0",
"-for i in range(1, 10**5 + 2):",
"- if i % 2 == 0:",
"- count.append(buf)",
"- continue",
"- hantei1 = is_prime(i)",
"- hantei2 = is_prime((i + 1) // 2)",
"- if hantei1 and hantei2:",
"- buf += 1",
"- count.append(buf)",
"-q = int(eval(input()))",
"-for i in range(q):",
"+Q = int(eval(input()))",
"+memo = [0] * 100001",
"+for i in range(2, 100001):",
"+ first = prime(i)",
"+ second = prime((i + 1) // 2)",
"+ if first and second:",
"+ memo[i] = 1",
"+for i in range(1, 100001):",
"+ memo[i] = memo[i - 1] + memo[i]",
"+for i in range(Q):",
"- print((count[r] - count[l - 1]))",
"+ print((memo[r] - memo[l - 1]))"
] | false | 0.892757 | 0.73462 | 1.215264 | [
"s975707913",
"s164868747"
] |
u997641430 | p03162 | python | s107150840 | s717571173 | 615 | 384 | 65,624 | 3,316 | Accepted | Accepted | 37.56 | N = int(eval(input()))
A, B, C = [], [], []
for n in range(N):
a, b, c = list(map(int, input().split()))
A.append(a)
B.append(b)
C.append(c)
a, b, c = 0, 0, 0
for n in range(N):
a, b, c = A[n] + max(b, c), B[n] + max(c, a), C[n] + max(a, b)
print((max(a, b, c)))
| N = int(eval(input()))
a, b, c = 0, 0, 0
for n in range(N):
an, bn, cn = list(map(int, input().split()))
a, b, c = an + max(b, c), bn + max(c, a), cn + max(a, b)
print((max(a, b, c)))
| 11 | 6 | 279 | 183 | N = int(eval(input()))
A, B, C = [], [], []
for n in range(N):
a, b, c = list(map(int, input().split()))
A.append(a)
B.append(b)
C.append(c)
a, b, c = 0, 0, 0
for n in range(N):
a, b, c = A[n] + max(b, c), B[n] + max(c, a), C[n] + max(a, b)
print((max(a, b, c)))
| N = int(eval(input()))
a, b, c = 0, 0, 0
for n in range(N):
an, bn, cn = list(map(int, input().split()))
a, b, c = an + max(b, c), bn + max(c, a), cn + max(a, b)
print((max(a, b, c)))
| false | 45.454545 | [
"-A, B, C = [], [], []",
"-for n in range(N):",
"- a, b, c = list(map(int, input().split()))",
"- A.append(a)",
"- B.append(b)",
"- C.append(c)",
"- a, b, c = A[n] + max(b, c), B[n] + max(c, a), C[n] + max(a, b)",
"+ an, bn, cn = list(map(int, input().split()))",
"+ a, b, c = an + max(b, c), bn + max(c, a), cn + max(a, b)"
] | false | 0.037642 | 0.035693 | 1.054604 | [
"s107150840",
"s717571173"
] |
u499381410 | p02793 | python | s409181683 | s744109516 | 582 | 287 | 5,708 | 84,700 | Accepted | Accepted | 50.69 | from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from copy import deepcopy
from math import factorial, ceil, floor, gamma, log
from operator import mul
from functools import reduce
sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7
def primes(n):
ass = []
is_prime = [True] * (n + 1)
is_prime[0] = False
is_prime[1] = False
for i in range(2, int(n**0.5) + 1):
if not is_prime[i]:
continue
for j in range(i * 2, n + 1, i):
is_prime[j] = False
for i in range(len(is_prime)):
if is_prime[i]:
ass.append(i)
return ass
def prime_decomposition(n):
table = []
for i in range(2, int(n ** 0.5) + 1):
while n % i == 0:
table += [i]
n //= i
if n == 1:
break
if n != 1:
table += [a]
return table
pr = primes(10 ** 3 + 1)
n = I()
A = LI()
D = defaultdict(int)
for a in A:
for p in pr:
if a < p:
break
cnt = 0
while a % p == 0:
cnt += 1
a //= p
if cnt > D[p]:
D[p] = cnt
if a > 1 and D[a] == 0:
D[a] = 1
lcm = 1
for v in D:
lcm = lcm * pow(v, D[v], mod) % mod
ans = 0
for a in A:
ans = (ans + pow(a, mod-2, mod) * lcm % mod) % mod
print(ans) | from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from operator import mul
sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007
n = I()
A = LI()
D = defaultdict(int)
for i in range(n):
a = A[i]
Di = defaultdict(int)
for j in range(2, int(a ** 0.5) + 1):
while a % j == 0:
a //= j
Di[j] += 1
if a == 0:
break
if a:
Di[a] += 1
for k in Di:
D[k] = max(D[k], Di[k])
ret = 1
for ki in D:
ret = ret * pow(ki, D[ki], mod)
ret %= mod
ans = 0
for a in A:
ans += ret * pow(a, mod - 2, mod)
ans %= mod
print(ans)
| 84 | 65 | 2,206 | 1,558 | from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from copy import deepcopy
from math import factorial, ceil, floor, gamma, log
from operator import mul
from functools import reduce
sys.setrecursionlimit(2147483647)
INF = 10**20
def LI():
return list(map(int, sys.stdin.buffer.readline().split()))
def I():
return int(sys.stdin.buffer.readline())
def LS():
return sys.stdin.buffer.readline().rstrip().decode("utf-8").split()
def S():
return sys.stdin.buffer.readline().rstrip().decode("utf-8")
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
def SRL(n):
return [list(S()) for i in range(n)]
def MSRL(n):
return [[int(j) for j in list(S())] for i in range(n)]
mod = 10**9 + 7
def primes(n):
ass = []
is_prime = [True] * (n + 1)
is_prime[0] = False
is_prime[1] = False
for i in range(2, int(n**0.5) + 1):
if not is_prime[i]:
continue
for j in range(i * 2, n + 1, i):
is_prime[j] = False
for i in range(len(is_prime)):
if is_prime[i]:
ass.append(i)
return ass
def prime_decomposition(n):
table = []
for i in range(2, int(n**0.5) + 1):
while n % i == 0:
table += [i]
n //= i
if n == 1:
break
if n != 1:
table += [a]
return table
pr = primes(10**3 + 1)
n = I()
A = LI()
D = defaultdict(int)
for a in A:
for p in pr:
if a < p:
break
cnt = 0
while a % p == 0:
cnt += 1
a //= p
if cnt > D[p]:
D[p] = cnt
if a > 1 and D[a] == 0:
D[a] = 1
lcm = 1
for v in D:
lcm = lcm * pow(v, D[v], mod) % mod
ans = 0
for a in A:
ans = (ans + pow(a, mod - 2, mod) * lcm % mod) % mod
print(ans)
| from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from operator import mul
sys.setrecursionlimit(2147483647)
INF = 10**20
def LI():
return list(map(int, sys.stdin.readline().split()))
def I():
return int(sys.stdin.readline())
def LS():
return sys.stdin.buffer.readline().rstrip().decode("utf-8").split()
def S():
return sys.stdin.buffer.readline().rstrip().decode("utf-8")
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
def SRL(n):
return [list(S()) for i in range(n)]
def MSRL(n):
return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007
n = I()
A = LI()
D = defaultdict(int)
for i in range(n):
a = A[i]
Di = defaultdict(int)
for j in range(2, int(a**0.5) + 1):
while a % j == 0:
a //= j
Di[j] += 1
if a == 0:
break
if a:
Di[a] += 1
for k in Di:
D[k] = max(D[k], Di[k])
ret = 1
for ki in D:
ret = ret * pow(ki, D[ki], mod)
ret %= mod
ans = 0
for a in A:
ans += ret * pow(a, mod - 2, mod)
ans %= mod
print(ans)
| false | 22.619048 | [
"-from bisect import bisect_right, bisect_left",
"+import math",
"+import bisect",
"-from copy import deepcopy",
"-from math import factorial, ceil, floor, gamma, log",
"+from math import factorial, ceil, floor",
"+from operator import mul",
"- return list(map(int, sys.stdin.buffer.readline().split()))",
"+ return list(map(int, sys.stdin.readline().split()))",
"- return int(sys.stdin.buffer.readline())",
"+ return int(sys.stdin.readline())",
"-mod = 10**9 + 7",
"-",
"-",
"-def primes(n):",
"- ass = []",
"- is_prime = [True] * (n + 1)",
"- is_prime[0] = False",
"- is_prime[1] = False",
"- for i in range(2, int(n**0.5) + 1):",
"- if not is_prime[i]:",
"- continue",
"- for j in range(i * 2, n + 1, i):",
"- is_prime[j] = False",
"- for i in range(len(is_prime)):",
"- if is_prime[i]:",
"- ass.append(i)",
"- return ass",
"-",
"-",
"-def prime_decomposition(n):",
"- table = []",
"- for i in range(2, int(n**0.5) + 1):",
"- while n % i == 0:",
"- table += [i]",
"- n //= i",
"- if n == 1:",
"- break",
"- if n != 1:",
"- table += [a]",
"- return table",
"-",
"-",
"-pr = primes(10**3 + 1)",
"+mod = 1000000007",
"-for a in A:",
"- for p in pr:",
"- if a < p:",
"+for i in range(n):",
"+ a = A[i]",
"+ Di = defaultdict(int)",
"+ for j in range(2, int(a**0.5) + 1):",
"+ while a % j == 0:",
"+ a //= j",
"+ Di[j] += 1",
"+ if a == 0:",
"- cnt = 0",
"- while a % p == 0:",
"- cnt += 1",
"- a //= p",
"- if cnt > D[p]:",
"- D[p] = cnt",
"- if a > 1 and D[a] == 0:",
"- D[a] = 1",
"-lcm = 1",
"-for v in D:",
"- lcm = lcm * pow(v, D[v], mod) % mod",
"+ if a:",
"+ Di[a] += 1",
"+ for k in Di:",
"+ D[k] = max(D[k], Di[k])",
"+ret = 1",
"+for ki in D:",
"+ ret = ret * pow(ki, D[ki], mod)",
"+ ret %= mod",
"- ans = (ans + pow(a, mod - 2, mod) * lcm % mod) % mod",
"+ ans += ret * pow(a, mod - 2, mod)",
"+ ans %= mod"
] | false | 0.04628 | 0.047139 | 0.981764 | [
"s409181683",
"s744109516"
] |
u270467412 | p02837 | python | s631585298 | s648070485 | 1,588 | 185 | 3,064 | 3,064 | Accepted | Accepted | 88.35 | N = int(eval(input()))
A = []
xy = []
for i in range(N):
a = int(eval(input()))
A.append(a)
xykari = []
for j in range(a):
xykari2 = list(map(int, input().split()))
xykari.append(xykari2)
xy.append(xykari)
ans = 0
for i in range(2**N): # iはケース名
honest = 0
ng = 0
for j in range(N): # jはケースiでチェックする人j
if ((i>>j)&1)==0:
continue # jが不親切なら次の人(j+1)のチェックに移る
else:
for k in range(A[j]):
taisho = xy[j][k][0] - 1
if xy[j][k][1] != ((i>>taisho)&1):
ng = 1
honest += 1
if ans < honest and ng == 0:
ans = honest # ansを更新
print(ans) | N = int(eval(input()))
A = []
xy = []
for i in range(N):
a = int(eval(input()))
A.append(a)
xykari = []
for j in range(a):
xykari2 = list(map(int, input().split()))
xykari.append(xykari2)
xy.append(xykari)
ans = 0
for i in range(2**N): # iはケース名
honest = 0
ng = 0
for j in range(N): # jはケースiでチェックする人j
if ((i>>j)&1)==0:
continue # jが不親切なら次の人(j+1)のチェックに移る
else:
for k in range(A[j]):
taisho = xy[j][k][0] - 1
if xy[j][k][1] != ((i>>taisho)&1):
ng = 1
break
if ng == 1:
break
honest += 1
if ans < honest and ng == 0:
ans = honest # ansを更新
print(ans)
| 30 | 33 | 635 | 682 | N = int(eval(input()))
A = []
xy = []
for i in range(N):
a = int(eval(input()))
A.append(a)
xykari = []
for j in range(a):
xykari2 = list(map(int, input().split()))
xykari.append(xykari2)
xy.append(xykari)
ans = 0
for i in range(2**N): # iはケース名
honest = 0
ng = 0
for j in range(N): # jはケースiでチェックする人j
if ((i >> j) & 1) == 0:
continue # jが不親切なら次の人(j+1)のチェックに移る
else:
for k in range(A[j]):
taisho = xy[j][k][0] - 1
if xy[j][k][1] != ((i >> taisho) & 1):
ng = 1
honest += 1
if ans < honest and ng == 0:
ans = honest # ansを更新
print(ans)
| N = int(eval(input()))
A = []
xy = []
for i in range(N):
a = int(eval(input()))
A.append(a)
xykari = []
for j in range(a):
xykari2 = list(map(int, input().split()))
xykari.append(xykari2)
xy.append(xykari)
ans = 0
for i in range(2**N): # iはケース名
honest = 0
ng = 0
for j in range(N): # jはケースiでチェックする人j
if ((i >> j) & 1) == 0:
continue # jが不親切なら次の人(j+1)のチェックに移る
else:
for k in range(A[j]):
taisho = xy[j][k][0] - 1
if xy[j][k][1] != ((i >> taisho) & 1):
ng = 1
break
if ng == 1:
break
honest += 1
if ans < honest and ng == 0:
ans = honest # ansを更新
print(ans)
| false | 9.090909 | [
"+ break",
"+ if ng == 1:",
"+ break"
] | false | 0.18649 | 0.07732 | 2.411924 | [
"s631585298",
"s648070485"
] |
u089230684 | p03264 | python | s377228356 | s791797819 | 167 | 18 | 38,512 | 2,940 | Accepted | Accepted | 89.22 | k=int(eval(input()))
if (k%2)==1 and k<=100:
a=k//2
b=k//2+1
elif (k%2)==0 and k<=100:
a=k//2
b=k//2
print((a*b)) | K=int(eval(input()))
l=0
for i in range(1,K+1):
for z in range(i,K+1):
if (i%2==0 and z%2==1) or (i%2==1 and z%2==0):
l+=1
print(l)
| 8 | 7 | 128 | 156 | k = int(eval(input()))
if (k % 2) == 1 and k <= 100:
a = k // 2
b = k // 2 + 1
elif (k % 2) == 0 and k <= 100:
a = k // 2
b = k // 2
print((a * b))
| K = int(eval(input()))
l = 0
for i in range(1, K + 1):
for z in range(i, K + 1):
if (i % 2 == 0 and z % 2 == 1) or (i % 2 == 1 and z % 2 == 0):
l += 1
print(l)
| false | 12.5 | [
"-k = int(eval(input()))",
"-if (k % 2) == 1 and k <= 100:",
"- a = k // 2",
"- b = k // 2 + 1",
"-elif (k % 2) == 0 and k <= 100:",
"- a = k // 2",
"- b = k // 2",
"-print((a * b))",
"+K = int(eval(input()))",
"+l = 0",
"+for i in range(1, K + 1):",
"+ for z in range(i, K + 1):",
"+ if (i % 2 == 0 and z % 2 == 1) or (i % 2 == 1 and z % 2 == 0):",
"+ l += 1",
"+print(l)"
] | false | 0.085416 | 0.041108 | 2.077832 | [
"s377228356",
"s791797819"
] |
u227082700 | p03634 | python | s323957839 | s817694760 | 1,605 | 1,328 | 55,388 | 81,788 | Accepted | Accepted | 17.26 | n=int(eval(input()))
l=[[]for _ in range(n)]
for i in range(n-1):
a,b,c=list(map(int,input().split()))
l[a-1]+=[[b-1,c]]
l[b-1]+=[[a-1,c]]
q,k=list(map(int,input().split()))
k-=1
Q=[[k,0]]
c=[0]*n;c[k]=-1
while Q:
p=[]
for i,j in Q:
for x,y in l[i]:
if c[x]==0:
c[x]=j+y
p+=[[x,c[x]]]
Q=p
c[k]=0
for i in range(q):
x,y=list(map(int,input().split()))
print((c[x-1]+c[y-1])) | from heapq import heappop,heappush
def dijkstra(s,n,edge):
inf=10**20
ans=[inf]*n
ans[s]=0
h=[[0,s]]
while h:
c,v=heappop(h)
if ans[v]<c:continue
for u,t in edge[v]:
if c+t<ans[u]:
ans[u]=c+t
heappush(h,[c+t,u])
return ans
n=int(eval(input()))
edge=[[]for _ in range(n)]
for i in range(n-1):
a,b,c=list(map(int,input().split()))
a-=1;b-=1
edge[a].append([b,c])
edge[b].append([a,c])
q,k=list(map(int,input().split()))
k-=1
xy=[list(map(int,input().split()))for _ in range(q)]
for i in range(q):xy[i][0]-=1;xy[i][1]-=1
edge=dijkstra(k,n,edge)
for x,y in xy:print((edge[x]+edge[y])) | 22 | 27 | 409 | 640 | n = int(eval(input()))
l = [[] for _ in range(n)]
for i in range(n - 1):
a, b, c = list(map(int, input().split()))
l[a - 1] += [[b - 1, c]]
l[b - 1] += [[a - 1, c]]
q, k = list(map(int, input().split()))
k -= 1
Q = [[k, 0]]
c = [0] * n
c[k] = -1
while Q:
p = []
for i, j in Q:
for x, y in l[i]:
if c[x] == 0:
c[x] = j + y
p += [[x, c[x]]]
Q = p
c[k] = 0
for i in range(q):
x, y = list(map(int, input().split()))
print((c[x - 1] + c[y - 1]))
| from heapq import heappop, heappush
def dijkstra(s, n, edge):
inf = 10**20
ans = [inf] * n
ans[s] = 0
h = [[0, s]]
while h:
c, v = heappop(h)
if ans[v] < c:
continue
for u, t in edge[v]:
if c + t < ans[u]:
ans[u] = c + t
heappush(h, [c + t, u])
return ans
n = int(eval(input()))
edge = [[] for _ in range(n)]
for i in range(n - 1):
a, b, c = list(map(int, input().split()))
a -= 1
b -= 1
edge[a].append([b, c])
edge[b].append([a, c])
q, k = list(map(int, input().split()))
k -= 1
xy = [list(map(int, input().split())) for _ in range(q)]
for i in range(q):
xy[i][0] -= 1
xy[i][1] -= 1
edge = dijkstra(k, n, edge)
for x, y in xy:
print((edge[x] + edge[y]))
| false | 18.518519 | [
"+from heapq import heappop, heappush",
"+",
"+",
"+def dijkstra(s, n, edge):",
"+ inf = 10**20",
"+ ans = [inf] * n",
"+ ans[s] = 0",
"+ h = [[0, s]]",
"+ while h:",
"+ c, v = heappop(h)",
"+ if ans[v] < c:",
"+ continue",
"+ for u, t in edge[v]:",
"+ if c + t < ans[u]:",
"+ ans[u] = c + t",
"+ heappush(h, [c + t, u])",
"+ return ans",
"+",
"+",
"-l = [[] for _ in range(n)]",
"+edge = [[] for _ in range(n)]",
"- l[a - 1] += [[b - 1, c]]",
"- l[b - 1] += [[a - 1, c]]",
"+ a -= 1",
"+ b -= 1",
"+ edge[a].append([b, c])",
"+ edge[b].append([a, c])",
"-Q = [[k, 0]]",
"-c = [0] * n",
"-c[k] = -1",
"-while Q:",
"- p = []",
"- for i, j in Q:",
"- for x, y in l[i]:",
"- if c[x] == 0:",
"- c[x] = j + y",
"- p += [[x, c[x]]]",
"- Q = p",
"-c[k] = 0",
"+xy = [list(map(int, input().split())) for _ in range(q)]",
"- x, y = list(map(int, input().split()))",
"- print((c[x - 1] + c[y - 1]))",
"+ xy[i][0] -= 1",
"+ xy[i][1] -= 1",
"+edge = dijkstra(k, n, edge)",
"+for x, y in xy:",
"+ print((edge[x] + edge[y]))"
] | false | 0.106874 | 0.105069 | 1.017181 | [
"s323957839",
"s817694760"
] |
u747602774 | p03944 | python | s138627411 | s857815224 | 78 | 17 | 3,064 | 3,064 | Accepted | Accepted | 78.21 | W,H,N=list(map(int,input().split()))
li=[[1 for w in range(W)] for h in range(H)]
for n in range(N):
X,Y,a=list(map(int,input().split()))
if a==1:
for y in range(H):
for x in range(X):
li[y][x]=0
elif a==3:
for y in range(Y):
for x in range(W):
li[y][x]=0
elif a==2:
for y in range(H):
for x in range(X,W):
li[y][x]=0
else:
for y in range(Y,H):
for x in range(W):
li[y][x]=0
ans=sum(x.count(1) for x in li)
print(ans)
| w,h,n = list(map(int,input().split()))
p = [0,w,0,h]
for i in range(n):
x,y,a = list(map(int,input().split()))
if a == 1:
p[0] = max(x,p[0])
if a == 2:
p[1] = min(x,p[1])
if a == 3:
p[2] = max(y,p[2])
if a == 4:
p[3] = min(y,p[3])
print((max(0,p[1]-p[0])*max(0,p[3]-p[2])))
| 26 | 13 | 517 | 324 | W, H, N = list(map(int, input().split()))
li = [[1 for w in range(W)] for h in range(H)]
for n in range(N):
X, Y, a = list(map(int, input().split()))
if a == 1:
for y in range(H):
for x in range(X):
li[y][x] = 0
elif a == 3:
for y in range(Y):
for x in range(W):
li[y][x] = 0
elif a == 2:
for y in range(H):
for x in range(X, W):
li[y][x] = 0
else:
for y in range(Y, H):
for x in range(W):
li[y][x] = 0
ans = sum(x.count(1) for x in li)
print(ans)
| w, h, n = list(map(int, input().split()))
p = [0, w, 0, h]
for i in range(n):
x, y, a = list(map(int, input().split()))
if a == 1:
p[0] = max(x, p[0])
if a == 2:
p[1] = min(x, p[1])
if a == 3:
p[2] = max(y, p[2])
if a == 4:
p[3] = min(y, p[3])
print((max(0, p[1] - p[0]) * max(0, p[3] - p[2])))
| false | 50 | [
"-W, H, N = list(map(int, input().split()))",
"-li = [[1 for w in range(W)] for h in range(H)]",
"-for n in range(N):",
"- X, Y, a = list(map(int, input().split()))",
"+w, h, n = list(map(int, input().split()))",
"+p = [0, w, 0, h]",
"+for i in range(n):",
"+ x, y, a = list(map(int, input().split()))",
"- for y in range(H):",
"- for x in range(X):",
"- li[y][x] = 0",
"- elif a == 3:",
"- for y in range(Y):",
"- for x in range(W):",
"- li[y][x] = 0",
"- elif a == 2:",
"- for y in range(H):",
"- for x in range(X, W):",
"- li[y][x] = 0",
"- else:",
"- for y in range(Y, H):",
"- for x in range(W):",
"- li[y][x] = 0",
"-ans = sum(x.count(1) for x in li)",
"-print(ans)",
"+ p[0] = max(x, p[0])",
"+ if a == 2:",
"+ p[1] = min(x, p[1])",
"+ if a == 3:",
"+ p[2] = max(y, p[2])",
"+ if a == 4:",
"+ p[3] = min(y, p[3])",
"+print((max(0, p[1] - p[0]) * max(0, p[3] - p[2])))"
] | false | 0.053626 | 0.037597 | 1.426351 | [
"s138627411",
"s857815224"
] |
u314050667 | p03017 | python | s125171189 | s583795409 | 105 | 85 | 3,572 | 3,572 | Accepted | Accepted | 19.05 | N, A, B, C, D = list(map(int, input().split()))
A, B, C, D = A-1, B-1, C-1, D-1
S = eval(input()) + "###"
def chk(l, r):
for i in range(l, r-1):
if S[i:i+2] == "##":
return 0
return 1
def chk3(l, r):
for i in range(l, r):
if S[i:i+3].count("#") == 0:
return 1
return 0
if chk(A, C) and chk(B, D) and (C < D or chk3(B-1, D)):
print("Yes")
else:
print("No")
| import sys
n,a,b,c,d = list(map(int, input().split()))
s = eval(input())
tmp = ""
for i in range(a,c):
if s[i] == tmp == "#":
print("No")
sys.exit()
tmp = s[i]
for i in range(b,d):
if s[i] == tmp == "#":
print("No")
sys.exit()
tmp = s[i]
if c < d:
print("Yes")
sys.exit()
else:
cnt = 0
for i in range(b-2,d+1):
if s[i] == ".":
cnt += 1
if cnt == 3:
print("Yes")
sys.exit()
else:
cnt = 0
print("No") | 19 | 34 | 428 | 462 | N, A, B, C, D = list(map(int, input().split()))
A, B, C, D = A - 1, B - 1, C - 1, D - 1
S = eval(input()) + "###"
def chk(l, r):
for i in range(l, r - 1):
if S[i : i + 2] == "##":
return 0
return 1
def chk3(l, r):
for i in range(l, r):
if S[i : i + 3].count("#") == 0:
return 1
return 0
if chk(A, C) and chk(B, D) and (C < D or chk3(B - 1, D)):
print("Yes")
else:
print("No")
| import sys
n, a, b, c, d = list(map(int, input().split()))
s = eval(input())
tmp = ""
for i in range(a, c):
if s[i] == tmp == "#":
print("No")
sys.exit()
tmp = s[i]
for i in range(b, d):
if s[i] == tmp == "#":
print("No")
sys.exit()
tmp = s[i]
if c < d:
print("Yes")
sys.exit()
else:
cnt = 0
for i in range(b - 2, d + 1):
if s[i] == ".":
cnt += 1
if cnt == 3:
print("Yes")
sys.exit()
else:
cnt = 0
print("No")
| false | 44.117647 | [
"-N, A, B, C, D = list(map(int, input().split()))",
"-A, B, C, D = A - 1, B - 1, C - 1, D - 1",
"-S = eval(input()) + \"###\"",
"+import sys",
"-",
"-def chk(l, r):",
"- for i in range(l, r - 1):",
"- if S[i : i + 2] == \"##\":",
"- return 0",
"- return 1",
"-",
"-",
"-def chk3(l, r):",
"- for i in range(l, r):",
"- if S[i : i + 3].count(\"#\") == 0:",
"- return 1",
"- return 0",
"-",
"-",
"-if chk(A, C) and chk(B, D) and (C < D or chk3(B - 1, D)):",
"+n, a, b, c, d = list(map(int, input().split()))",
"+s = eval(input())",
"+tmp = \"\"",
"+for i in range(a, c):",
"+ if s[i] == tmp == \"#\":",
"+ print(\"No\")",
"+ sys.exit()",
"+ tmp = s[i]",
"+for i in range(b, d):",
"+ if s[i] == tmp == \"#\":",
"+ print(\"No\")",
"+ sys.exit()",
"+ tmp = s[i]",
"+if c < d:",
"+ sys.exit()",
"- print(\"No\")",
"+ cnt = 0",
"+ for i in range(b - 2, d + 1):",
"+ if s[i] == \".\":",
"+ cnt += 1",
"+ if cnt == 3:",
"+ print(\"Yes\")",
"+ sys.exit()",
"+ else:",
"+ cnt = 0",
"+print(\"No\")"
] | false | 0.042799 | 0.043306 | 0.988278 | [
"s125171189",
"s583795409"
] |
u747703115 | p03425 | python | s038995423 | s838000699 | 174 | 40 | 3,064 | 10,864 | Accepted | Accepted | 77.01 | n = int(eval(input()))
m, a, r, c, h = 0, 0, 0, 0, 0
for i in range(n):
s = eval(input())
if s[0]=='M':
m += 1
elif s[0]=='A':
a += 1
elif s[0]=='R':
r += 1
elif s[0]=='C':
c += 1
elif s[0]=='H':
h += 1
print((m*a*r+m*a*c+m*a*h+m*r*c+m*r*h+m*c*h+ a*r*c+a*r*h+a*c*h+r*c*h))
| from itertools import combinations
n, *S = open(0).read().split()
# 頭文字だけ抜き出す.
cap = [s[0] for s in S]
# M,A,R,C,H,それぞれ頭文字の中にある数をカウント.
cnt = [cap.count(i) for i in "MARCH"]
# 組み合わせの合計を取る.
ans = sum(x*y*z for x, y, z in combinations(cnt, 3))
print(ans) | 15 | 9 | 337 | 259 | n = int(eval(input()))
m, a, r, c, h = 0, 0, 0, 0, 0
for i in range(n):
s = eval(input())
if s[0] == "M":
m += 1
elif s[0] == "A":
a += 1
elif s[0] == "R":
r += 1
elif s[0] == "C":
c += 1
elif s[0] == "H":
h += 1
print(
(
m * a * r
+ m * a * c
+ m * a * h
+ m * r * c
+ m * r * h
+ m * c * h
+ a * r * c
+ a * r * h
+ a * c * h
+ r * c * h
)
)
| from itertools import combinations
n, *S = open(0).read().split()
# 頭文字だけ抜き出す.
cap = [s[0] for s in S]
# M,A,R,C,H,それぞれ頭文字の中にある数をカウント.
cnt = [cap.count(i) for i in "MARCH"]
# 組み合わせの合計を取る.
ans = sum(x * y * z for x, y, z in combinations(cnt, 3))
print(ans)
| false | 40 | [
"-n = int(eval(input()))",
"-m, a, r, c, h = 0, 0, 0, 0, 0",
"-for i in range(n):",
"- s = eval(input())",
"- if s[0] == \"M\":",
"- m += 1",
"- elif s[0] == \"A\":",
"- a += 1",
"- elif s[0] == \"R\":",
"- r += 1",
"- elif s[0] == \"C\":",
"- c += 1",
"- elif s[0] == \"H\":",
"- h += 1",
"-print(",
"- (",
"- m * a * r",
"- + m * a * c",
"- + m * a * h",
"- + m * r * c",
"- + m * r * h",
"- + m * c * h",
"- + a * r * c",
"- + a * r * h",
"- + a * c * h",
"- + r * c * h",
"- )",
"-)",
"+from itertools import combinations",
"+",
"+n, *S = open(0).read().split()",
"+# 頭文字だけ抜き出す.",
"+cap = [s[0] for s in S]",
"+# M,A,R,C,H,それぞれ頭文字の中にある数をカウント.",
"+cnt = [cap.count(i) for i in \"MARCH\"]",
"+# 組み合わせの合計を取る.",
"+ans = sum(x * y * z for x, y, z in combinations(cnt, 3))",
"+print(ans)"
] | false | 0.044105 | 0.042746 | 1.031808 | [
"s038995423",
"s838000699"
] |
u497952650 | p02791 | python | s788183966 | s483740595 | 169 | 145 | 24,744 | 24,744 | Accepted | Accepted | 14.2 | N = int(eval(input()))
P = list(map(int,input().split()))
minp = P[0]
ans = 0
for i in range(N):
if i != 0:
minp = min(minp,P[i])
if minp == P[i]:
ans += 1
print(ans)
| N = int(eval(input()))
P = list(map(int,input().split()))
minp = P[0]
ans = 0
for i in range(N):
minp = min(minp,P[i])
if minp == P[i]:
ans += 1
print(ans) | 13 | 12 | 200 | 179 | N = int(eval(input()))
P = list(map(int, input().split()))
minp = P[0]
ans = 0
for i in range(N):
if i != 0:
minp = min(minp, P[i])
if minp == P[i]:
ans += 1
print(ans)
| N = int(eval(input()))
P = list(map(int, input().split()))
minp = P[0]
ans = 0
for i in range(N):
minp = min(minp, P[i])
if minp == P[i]:
ans += 1
print(ans)
| false | 7.692308 | [
"- if i != 0:",
"- minp = min(minp, P[i])",
"+ minp = min(minp, P[i])"
] | false | 0.095204 | 0.046926 | 2.028795 | [
"s788183966",
"s483740595"
] |
u197300773 | p02901 | python | s096488733 | s665573638 | 1,316 | 775 | 3,188 | 3,188 | Accepted | Accepted | 41.11 | n,m=list(map(int,input().split()))
L=2**n
cost=[0]+[10**8 for i in range(L-1)]
for i in range(m):
a,b=list(map(int,input().split()))
c=sum([2**(int(i)-1) for i in input().split()])
for j in range(L):
q=j|c
x=cost[j]+a
if cost[q]>x:
cost[q]=x
print((cost[L-1] if cost[L-1]<10**8 else -1)) | def main():
n,m=list(map(int,input().split()))
L=2**n
cost=[0]+[10**8 for i in range(L-1)]
for _ in range(m):
a,_=list(map(int,input().split()))
c=sum([2**(int(i)-1) for i in input().split()])
for j in range(L):
q=j|c
x=cost[j]+a
if cost[q]>x:
cost[q]=x
print((cost[L-1] if cost[L-1]<10**8 else -1))
if __name__ == '__main__':
main() | 13 | 17 | 334 | 437 | n, m = list(map(int, input().split()))
L = 2**n
cost = [0] + [10**8 for i in range(L - 1)]
for i in range(m):
a, b = list(map(int, input().split()))
c = sum([2 ** (int(i) - 1) for i in input().split()])
for j in range(L):
q = j | c
x = cost[j] + a
if cost[q] > x:
cost[q] = x
print((cost[L - 1] if cost[L - 1] < 10**8 else -1))
| def main():
n, m = list(map(int, input().split()))
L = 2**n
cost = [0] + [10**8 for i in range(L - 1)]
for _ in range(m):
a, _ = list(map(int, input().split()))
c = sum([2 ** (int(i) - 1) for i in input().split()])
for j in range(L):
q = j | c
x = cost[j] + a
if cost[q] > x:
cost[q] = x
print((cost[L - 1] if cost[L - 1] < 10**8 else -1))
if __name__ == "__main__":
main()
| false | 23.529412 | [
"-n, m = list(map(int, input().split()))",
"-L = 2**n",
"-cost = [0] + [10**8 for i in range(L - 1)]",
"-for i in range(m):",
"- a, b = list(map(int, input().split()))",
"- c = sum([2 ** (int(i) - 1) for i in input().split()])",
"- for j in range(L):",
"- q = j | c",
"- x = cost[j] + a",
"- if cost[q] > x:",
"- cost[q] = x",
"-print((cost[L - 1] if cost[L - 1] < 10**8 else -1))",
"+def main():",
"+ n, m = list(map(int, input().split()))",
"+ L = 2**n",
"+ cost = [0] + [10**8 for i in range(L - 1)]",
"+ for _ in range(m):",
"+ a, _ = list(map(int, input().split()))",
"+ c = sum([2 ** (int(i) - 1) for i in input().split()])",
"+ for j in range(L):",
"+ q = j | c",
"+ x = cost[j] + a",
"+ if cost[q] > x:",
"+ cost[q] = x",
"+ print((cost[L - 1] if cost[L - 1] < 10**8 else -1))",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.123479 | 0.073671 | 1.676071 | [
"s096488733",
"s665573638"
] |
u163320134 | p03593 | python | s355071775 | s345431960 | 23 | 21 | 3,316 | 3,064 | Accepted | Accepted | 8.7 | h,w=list(map(int,input().split()))
ans=[['']*w for _ in range(h)]
char={}
for _ in range(h):
s=eval(input())
for c in s:
if c not in char:
char[c]=1
else:
char[c]+=1
ch=h//2
cw=w//2
fh=False
fw=False
if h%2==1:
ch+=1
fh=True
if w%2==1:
cw+=1
fw=True
for i in range(ch):
for j in range(cw):
if (i==ch-1 and fh==True) and (j==cw-1 and fw==True):
for c in list(char.keys()):
if char[c]%2==1:
ans[i][j]=c
char[c]-=1
if char[c]==0:
del char[c]
break
elif i==ch-1 and fh==True:
for c in list(char.keys()):
if char[c]%4==2:
ans[i][j]=c
ans[i][w-j-1]=c
char[c]-=2
if char[c]==0:
del char[c]
break
else:
for c in list(char.keys()):
if char[c]>=2:
ans[i][j]=c
ans[i][w-j-1]=c
char[c]-=2
if char[c]==0:
del char[c]
break
elif j==cw-1 and fw==True:
for c in list(char.keys()):
if char[c]%4==2:
ans[i][j]=c
ans[h-i-1][j]=c
char[c]-=2
if char[c]==0:
del char[c]
break
else:
for c in list(char.keys()):
if char[c]>=2:
ans[i][j]=c
ans[h-i-1][j]=c
char[c]-=2
if char[c]==0:
del char[c]
break
else:
for c in list(char.keys()):
if char[c]>=4:
ans[i][j]=c
ans[i][w-j-1]=c
ans[h-i-1][j]=c
ans[h-i-1][w-j-1]=c
char[c]-=4
if char[c]==0:
del char[c]
break
fy=True
for i in range(ch):
for j in range(cw):
if ans[i][j]=='':
fy=False
if fy==True:
print('Yes')
else:
print('No') | h,w=list(map(int,input().split()))
char={}
for _ in range(h):
s=eval(input())
for c in s:
if c not in char:
char[c]=1
else:
char[c]+=1
cnt4=(h//2)*(w//2)
cnt2=0
cnt1=0
if h%2==1 and w%2==1:
cnt1=1
cnt2=h//2+w//2
elif h%2==1:
cnt2=w//2
elif w%2==1:
cnt2=h//2
flag=True
for _ in range(cnt4):
for c in list(char.keys()):
if char[c]>=4:
char[c]-=4
if char[c]==0:
del char[c]
break
else:
flag=False
for _ in range(cnt2):
for c in list(char.keys()):
if char[c]>=2:
char[c]-=2
if char[c]==0:
del char[c]
break
else:
flag=False
for _ in range(cnt1):
for c in list(char.keys()):
if char[c]>=1:
char[c]-=1
if char[c]==0:
del char[c]
break
else:
flag=False
if flag==True:
print('Yes')
else:
print('No') | 86 | 51 | 1,863 | 861 | h, w = list(map(int, input().split()))
ans = [[""] * w for _ in range(h)]
char = {}
for _ in range(h):
s = eval(input())
for c in s:
if c not in char:
char[c] = 1
else:
char[c] += 1
ch = h // 2
cw = w // 2
fh = False
fw = False
if h % 2 == 1:
ch += 1
fh = True
if w % 2 == 1:
cw += 1
fw = True
for i in range(ch):
for j in range(cw):
if (i == ch - 1 and fh == True) and (j == cw - 1 and fw == True):
for c in list(char.keys()):
if char[c] % 2 == 1:
ans[i][j] = c
char[c] -= 1
if char[c] == 0:
del char[c]
break
elif i == ch - 1 and fh == True:
for c in list(char.keys()):
if char[c] % 4 == 2:
ans[i][j] = c
ans[i][w - j - 1] = c
char[c] -= 2
if char[c] == 0:
del char[c]
break
else:
for c in list(char.keys()):
if char[c] >= 2:
ans[i][j] = c
ans[i][w - j - 1] = c
char[c] -= 2
if char[c] == 0:
del char[c]
break
elif j == cw - 1 and fw == True:
for c in list(char.keys()):
if char[c] % 4 == 2:
ans[i][j] = c
ans[h - i - 1][j] = c
char[c] -= 2
if char[c] == 0:
del char[c]
break
else:
for c in list(char.keys()):
if char[c] >= 2:
ans[i][j] = c
ans[h - i - 1][j] = c
char[c] -= 2
if char[c] == 0:
del char[c]
break
else:
for c in list(char.keys()):
if char[c] >= 4:
ans[i][j] = c
ans[i][w - j - 1] = c
ans[h - i - 1][j] = c
ans[h - i - 1][w - j - 1] = c
char[c] -= 4
if char[c] == 0:
del char[c]
break
fy = True
for i in range(ch):
for j in range(cw):
if ans[i][j] == "":
fy = False
if fy == True:
print("Yes")
else:
print("No")
| h, w = list(map(int, input().split()))
char = {}
for _ in range(h):
s = eval(input())
for c in s:
if c not in char:
char[c] = 1
else:
char[c] += 1
cnt4 = (h // 2) * (w // 2)
cnt2 = 0
cnt1 = 0
if h % 2 == 1 and w % 2 == 1:
cnt1 = 1
cnt2 = h // 2 + w // 2
elif h % 2 == 1:
cnt2 = w // 2
elif w % 2 == 1:
cnt2 = h // 2
flag = True
for _ in range(cnt4):
for c in list(char.keys()):
if char[c] >= 4:
char[c] -= 4
if char[c] == 0:
del char[c]
break
else:
flag = False
for _ in range(cnt2):
for c in list(char.keys()):
if char[c] >= 2:
char[c] -= 2
if char[c] == 0:
del char[c]
break
else:
flag = False
for _ in range(cnt1):
for c in list(char.keys()):
if char[c] >= 1:
char[c] -= 1
if char[c] == 0:
del char[c]
break
else:
flag = False
if flag == True:
print("Yes")
else:
print("No")
| false | 40.697674 | [
"-ans = [[\"\"] * w for _ in range(h)]",
"-ch = h // 2",
"-cw = w // 2",
"-fh = False",
"-fw = False",
"-if h % 2 == 1:",
"- ch += 1",
"- fh = True",
"-if w % 2 == 1:",
"- cw += 1",
"- fw = True",
"-for i in range(ch):",
"- for j in range(cw):",
"- if (i == ch - 1 and fh == True) and (j == cw - 1 and fw == True):",
"- for c in list(char.keys()):",
"- if char[c] % 2 == 1:",
"- ans[i][j] = c",
"- char[c] -= 1",
"- if char[c] == 0:",
"- del char[c]",
"- break",
"- elif i == ch - 1 and fh == True:",
"- for c in list(char.keys()):",
"- if char[c] % 4 == 2:",
"- ans[i][j] = c",
"- ans[i][w - j - 1] = c",
"- char[c] -= 2",
"- if char[c] == 0:",
"- del char[c]",
"- break",
"- else:",
"- for c in list(char.keys()):",
"- if char[c] >= 2:",
"- ans[i][j] = c",
"- ans[i][w - j - 1] = c",
"- char[c] -= 2",
"- if char[c] == 0:",
"- del char[c]",
"- break",
"- elif j == cw - 1 and fw == True:",
"- for c in list(char.keys()):",
"- if char[c] % 4 == 2:",
"- ans[i][j] = c",
"- ans[h - i - 1][j] = c",
"- char[c] -= 2",
"- if char[c] == 0:",
"- del char[c]",
"- break",
"- else:",
"- for c in list(char.keys()):",
"- if char[c] >= 2:",
"- ans[i][j] = c",
"- ans[h - i - 1][j] = c",
"- char[c] -= 2",
"- if char[c] == 0:",
"- del char[c]",
"- break",
"- else:",
"- for c in list(char.keys()):",
"- if char[c] >= 4:",
"- ans[i][j] = c",
"- ans[i][w - j - 1] = c",
"- ans[h - i - 1][j] = c",
"- ans[h - i - 1][w - j - 1] = c",
"- char[c] -= 4",
"- if char[c] == 0:",
"- del char[c]",
"- break",
"-fy = True",
"-for i in range(ch):",
"- for j in range(cw):",
"- if ans[i][j] == \"\":",
"- fy = False",
"-if fy == True:",
"+cnt4 = (h // 2) * (w // 2)",
"+cnt2 = 0",
"+cnt1 = 0",
"+if h % 2 == 1 and w % 2 == 1:",
"+ cnt1 = 1",
"+ cnt2 = h // 2 + w // 2",
"+elif h % 2 == 1:",
"+ cnt2 = w // 2",
"+elif w % 2 == 1:",
"+ cnt2 = h // 2",
"+flag = True",
"+for _ in range(cnt4):",
"+ for c in list(char.keys()):",
"+ if char[c] >= 4:",
"+ char[c] -= 4",
"+ if char[c] == 0:",
"+ del char[c]",
"+ break",
"+ else:",
"+ flag = False",
"+for _ in range(cnt2):",
"+ for c in list(char.keys()):",
"+ if char[c] >= 2:",
"+ char[c] -= 2",
"+ if char[c] == 0:",
"+ del char[c]",
"+ break",
"+ else:",
"+ flag = False",
"+for _ in range(cnt1):",
"+ for c in list(char.keys()):",
"+ if char[c] >= 1:",
"+ char[c] -= 1",
"+ if char[c] == 0:",
"+ del char[c]",
"+ break",
"+ else:",
"+ flag = False",
"+if flag == True:"
] | false | 0.038964 | 0.034573 | 1.127017 | [
"s355071775",
"s345431960"
] |
u905203728 | p02862 | python | s406243767 | s881071015 | 306 | 130 | 118,764 | 156,708 | Accepted | Accepted | 57.52 | def cmb(n,r,mod):
if r<0 or r>n:return 0
r=min(r,n-r)
return g1[n]*g2[r]*g2[n-r]%mod
mod=10**9+7
x,y=list(map(int,input().split()))
g1=[1,1]
g2=[1,1]
inverse=[0,1]
n,m=(2*y-x)//3,(2*x-y)//3
if (x+y)%3!=0 or n<0 or m<0:print((0));exit()
for i in range(2,n+m+1):
g1.append((g1[-1]*i)%mod)
inverse.append((-inverse[mod%i]*(mod//i))%mod)
g2.append((g2[-1]*inverse[-1]%mod))
print((cmb(n+m,n,mod))) | mod=10**9+7
x,y=list(map(int,input().split()))
X,Y=(2*y-x)//3,(2*x-y)//3
if X<0 or Y<0 or (x+y)%3!=0:print((0));exit()
def cmb(n,r,mod):
if r<0 or r>n:return 0
return g1[r]*g2[r]%mod
n=X+Y
k=max(X,Y)
g1=[1,n]
g2=[1,1]
inverse=[0,1]
for i,j in enumerate(range(n-1,((n-k+1)-1),-1)):
i=i+2
g1.append((g1[-1]*j)%mod)
inverse.append((-inverse[mod%i]*(mod//i))%mod)
g2.append((g2[-1]*inverse[-1]%mod))
print((cmb(n,k,mod))) | 21 | 25 | 432 | 462 | def cmb(n, r, mod):
if r < 0 or r > n:
return 0
r = min(r, n - r)
return g1[n] * g2[r] * g2[n - r] % mod
mod = 10**9 + 7
x, y = list(map(int, input().split()))
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
n, m = (2 * y - x) // 3, (2 * x - y) // 3
if (x + y) % 3 != 0 or n < 0 or m < 0:
print((0))
exit()
for i in range(2, n + m + 1):
g1.append((g1[-1] * i) % mod)
inverse.append((-inverse[mod % i] * (mod // i)) % mod)
g2.append((g2[-1] * inverse[-1] % mod))
print((cmb(n + m, n, mod)))
| mod = 10**9 + 7
x, y = list(map(int, input().split()))
X, Y = (2 * y - x) // 3, (2 * x - y) // 3
if X < 0 or Y < 0 or (x + y) % 3 != 0:
print((0))
exit()
def cmb(n, r, mod):
if r < 0 or r > n:
return 0
return g1[r] * g2[r] % mod
n = X + Y
k = max(X, Y)
g1 = [1, n]
g2 = [1, 1]
inverse = [0, 1]
for i, j in enumerate(range(n - 1, ((n - k + 1) - 1), -1)):
i = i + 2
g1.append((g1[-1] * j) % mod)
inverse.append((-inverse[mod % i] * (mod // i)) % mod)
g2.append((g2[-1] * inverse[-1] % mod))
print((cmb(n, k, mod)))
| false | 16 | [
"+mod = 10**9 + 7",
"+x, y = list(map(int, input().split()))",
"+X, Y = (2 * y - x) // 3, (2 * x - y) // 3",
"+if X < 0 or Y < 0 or (x + y) % 3 != 0:",
"+ print((0))",
"+ exit()",
"+",
"+",
"- r = min(r, n - r)",
"- return g1[n] * g2[r] * g2[n - r] % mod",
"+ return g1[r] * g2[r] % mod",
"-mod = 10**9 + 7",
"-x, y = list(map(int, input().split()))",
"-g1 = [1, 1]",
"+n = X + Y",
"+k = max(X, Y)",
"+g1 = [1, n]",
"-n, m = (2 * y - x) // 3, (2 * x - y) // 3",
"-if (x + y) % 3 != 0 or n < 0 or m < 0:",
"- print((0))",
"- exit()",
"-for i in range(2, n + m + 1):",
"- g1.append((g1[-1] * i) % mod)",
"+for i, j in enumerate(range(n - 1, ((n - k + 1) - 1), -1)):",
"+ i = i + 2",
"+ g1.append((g1[-1] * j) % mod)",
"-print((cmb(n + m, n, mod)))",
"+print((cmb(n, k, mod)))"
] | false | 0.82883 | 0.168717 | 4.912556 | [
"s406243767",
"s881071015"
] |
u586121204 | p02887 | python | s136675957 | s496919712 | 44 | 35 | 3,316 | 12,788 | Accepted | Accepted | 20.45 | n = int(eval(input()))
s = eval(input())
before = ''
new = ''
for c in s:
if before != c:
new += c
before = c
print((len(new))) | import re
N = int(eval(input()))
S = eval(input())
rex = r'(.)\1{0,}'
pattern = re.compile(rex)
ans = pattern.findall(S)
print((len(ans))) | 9 | 10 | 141 | 136 | n = int(eval(input()))
s = eval(input())
before = ""
new = ""
for c in s:
if before != c:
new += c
before = c
print((len(new)))
| import re
N = int(eval(input()))
S = eval(input())
rex = r"(.)\1{0,}"
pattern = re.compile(rex)
ans = pattern.findall(S)
print((len(ans)))
| false | 10 | [
"-n = int(eval(input()))",
"-s = eval(input())",
"-before = \"\"",
"-new = \"\"",
"-for c in s:",
"- if before != c:",
"- new += c",
"- before = c",
"-print((len(new)))",
"+import re",
"+",
"+N = int(eval(input()))",
"+S = eval(input())",
"+rex = r\"(.)\\1{0,}\"",
"+pattern = re.compile(rex)",
"+ans = pattern.findall(S)",
"+print((len(ans)))"
] | false | 0.04202 | 0.040205 | 1.04514 | [
"s136675957",
"s496919712"
] |
u576432509 | p03721 | python | s967498648 | s147031588 | 465 | 321 | 20,104 | 5,744 | Accepted | Accepted | 30.97 | n,k=list(map(int,input().split()))
a=[]
for i in range(n):
ai,bi=list(map(int,input().split()))
a.append([ai,bi])
a.sort()
sumb=0
for i in range(n):
sumb=sumb+a[i][1]
if sumb>=k:
print((a[i][0]))
break
|
n,k=list(map(int,input().split()))
cnt=[0]*100001
for i in range(n):
ai,bi=list(map(int,input().split()))
cnt[ai]+=bi
for ans in range(1,len(cnt)):
if cnt[ans]>=k:
print(ans)
break
k-=cnt[ans] | 16 | 13 | 247 | 231 | n, k = list(map(int, input().split()))
a = []
for i in range(n):
ai, bi = list(map(int, input().split()))
a.append([ai, bi])
a.sort()
sumb = 0
for i in range(n):
sumb = sumb + a[i][1]
if sumb >= k:
print((a[i][0]))
break
| n, k = list(map(int, input().split()))
cnt = [0] * 100001
for i in range(n):
ai, bi = list(map(int, input().split()))
cnt[ai] += bi
for ans in range(1, len(cnt)):
if cnt[ans] >= k:
print(ans)
break
k -= cnt[ans]
| false | 18.75 | [
"-a = []",
"+cnt = [0] * 100001",
"- a.append([ai, bi])",
"-a.sort()",
"-sumb = 0",
"-for i in range(n):",
"- sumb = sumb + a[i][1]",
"- if sumb >= k:",
"- print((a[i][0]))",
"+ cnt[ai] += bi",
"+for ans in range(1, len(cnt)):",
"+ if cnt[ans] >= k:",
"+ print(ans)",
"+ k -= cnt[ans]"
] | false | 0.035727 | 0.032159 | 1.110944 | [
"s967498648",
"s147031588"
] |
u022407960 | p02234 | python | s258358722 | s342857749 | 170 | 140 | 7,816 | 7,948 | Accepted | Accepted | 17.65 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
def mat_mul_opt(_mat_info):
r, c = list(map(int, _mat_info[0]))
rc_info.extend([r, c])
for each in _mat_info[1:]:
rc_info.append(int(each[1]))
for l in range(2, mat_num + 1):
for i in range(1, mat_num - l + 2):
j = i + l - 1
ans[i][j] = 1e7
for k in range(i, j):
ans[i][j] = min(ans[i][j], ans[i][k] + ans[k + 1][j] +
rc_info[i - 1] * rc_info[k] * rc_info[j])
return ans[1][mat_num]
if __name__ == '__main__':
_input = sys.stdin.readlines()
mat_num = int(_input[0])
mat_info = tuple([x.split() for x in _input[1:]])
rc_info = []
ans = [[0] * (mat_num + 1) for _ in range(mat_num + 1)]
print((mat_mul_opt(mat_info))) | #!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
def mat_mul_opt(_mat_info):
rc_info.extend(list(map(int, _mat_info[0])))
rc_info.extend(list([int(x[1]) for x in _mat_info[1:]]))
for l in range(2, mat_num + 1):
for i in range(1, mat_num - l + 2):
j = i + l - 1
ans[i][j] = 1e7
for k in range(i, j):
ans[i][j] = min(ans[i][j], ans[i][k] + ans[k + 1][j] +
rc_info[i - 1] * rc_info[k] * rc_info[j])
return ans[1][mat_num]
if __name__ == '__main__':
_input = sys.stdin.readlines()
mat_num = int(_input[0])
mat_info = tuple([x.split() for x in _input[1:]])
rc_info = []
ans = [[0] * (mat_num + 1) for _ in range(mat_num + 1)]
print((mat_mul_opt(mat_info))) | 31 | 29 | 851 | 835 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
def mat_mul_opt(_mat_info):
r, c = list(map(int, _mat_info[0]))
rc_info.extend([r, c])
for each in _mat_info[1:]:
rc_info.append(int(each[1]))
for l in range(2, mat_num + 1):
for i in range(1, mat_num - l + 2):
j = i + l - 1
ans[i][j] = 1e7
for k in range(i, j):
ans[i][j] = min(
ans[i][j],
ans[i][k]
+ ans[k + 1][j]
+ rc_info[i - 1] * rc_info[k] * rc_info[j],
)
return ans[1][mat_num]
if __name__ == "__main__":
_input = sys.stdin.readlines()
mat_num = int(_input[0])
mat_info = tuple([x.split() for x in _input[1:]])
rc_info = []
ans = [[0] * (mat_num + 1) for _ in range(mat_num + 1)]
print((mat_mul_opt(mat_info)))
| #!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
def mat_mul_opt(_mat_info):
rc_info.extend(list(map(int, _mat_info[0])))
rc_info.extend(list([int(x[1]) for x in _mat_info[1:]]))
for l in range(2, mat_num + 1):
for i in range(1, mat_num - l + 2):
j = i + l - 1
ans[i][j] = 1e7
for k in range(i, j):
ans[i][j] = min(
ans[i][j],
ans[i][k]
+ ans[k + 1][j]
+ rc_info[i - 1] * rc_info[k] * rc_info[j],
)
return ans[1][mat_num]
if __name__ == "__main__":
_input = sys.stdin.readlines()
mat_num = int(_input[0])
mat_info = tuple([x.split() for x in _input[1:]])
rc_info = []
ans = [[0] * (mat_num + 1) for _ in range(mat_num + 1)]
print((mat_mul_opt(mat_info)))
| false | 6.451613 | [
"- r, c = list(map(int, _mat_info[0]))",
"- rc_info.extend([r, c])",
"- for each in _mat_info[1:]:",
"- rc_info.append(int(each[1]))",
"+ rc_info.extend(list(map(int, _mat_info[0])))",
"+ rc_info.extend(list([int(x[1]) for x in _mat_info[1:]]))"
] | false | 0.037671 | 0.065849 | 0.572085 | [
"s258358722",
"s342857749"
] |
u353895424 | p03254 | python | s984198825 | s239091562 | 171 | 30 | 38,448 | 9,060 | Accepted | Accepted | 82.46 | n, x = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
ans = 0
if x > sum(a):
print((n-1))
else:
for _a in a:
x -= _a
if x < 0:
print(ans)
exit()
else:
ans += 1
print(ans) | n, x = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort()
ans = 0
for a in A:
x -= a
if x < 0:
break
else:
ans += 1
if 0 < x:
ans -= 1
print((max(ans, 0)))
| 15 | 15 | 350 | 222 | n, x = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
ans = 0
if x > sum(a):
print((n - 1))
else:
for _a in a:
x -= _a
if x < 0:
print(ans)
exit()
else:
ans += 1
print(ans)
| n, x = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort()
ans = 0
for a in A:
x -= a
if x < 0:
break
else:
ans += 1
if 0 < x:
ans -= 1
print((max(ans, 0)))
| false | 0 | [
"-a = list(map(int, input().split()))",
"-a.sort()",
"+A = list(map(int, input().split()))",
"+A.sort()",
"-if x > sum(a):",
"- print((n - 1))",
"-else:",
"- for _a in a:",
"- x -= _a",
"- if x < 0:",
"- print(ans)",
"- exit()",
"- else:",
"- ans += 1",
"- print(ans)",
"+for a in A:",
"+ x -= a",
"+ if x < 0:",
"+ break",
"+ else:",
"+ ans += 1",
"+if 0 < x:",
"+ ans -= 1",
"+print((max(ans, 0)))"
] | false | 0.090354 | 0.0418 | 2.161592 | [
"s984198825",
"s239091562"
] |
u823885866 | p03162 | python | s322624012 | s310015186 | 1,554 | 608 | 41,828 | 56,520 | Accepted | Accepted | 60.88 | import sys
import math
import itertools
import collections
import numpy as np
rl = sys.stdin.readline
n = int(rl())
li = [list(map(int, rl().split())) for _ in range(n)]
dp = np.zeros((n, 3), dtype=int)
dp[0] = li[0]
for i in range(1, n):
a = dp[i-1][1] + li[i][0]
b = dp[i-1][2] + li[i][0]
dp[i][0] = max(a, b)
a = dp[i-1][0] + li[i][1]
b = dp[i-1][2] + li[i][1]
dp[i][1] = max(a, b)
a = dp[i-1][0] + li[i][2]
b = dp[i-1][1] + li[i][2]
dp[i][2] = max(a, b)
print((max(dp[-1])))
| import sys
import math
import itertools
import collections
import numpy as np
rl = sys.stdin.readline
n = int(rl())
li = [list(map(int, rl().split())) for _ in range(n)]
dp = [[0]*3 for _ in range(n)]
dp[0] = li[0]
for i in range(1, n):
a = dp[i-1][1] + li[i][0]
b = dp[i-1][2] + li[i][0]
dp[i][0] = max(a, b)
a = dp[i-1][0] + li[i][1]
b = dp[i-1][2] + li[i][1]
dp[i][1] = max(a, b)
a = dp[i-1][0] + li[i][2]
b = dp[i-1][1] + li[i][2]
dp[i][2] = max(a, b)
print((max(dp[-1])))
| 27 | 27 | 549 | 547 | import sys
import math
import itertools
import collections
import numpy as np
rl = sys.stdin.readline
n = int(rl())
li = [list(map(int, rl().split())) for _ in range(n)]
dp = np.zeros((n, 3), dtype=int)
dp[0] = li[0]
for i in range(1, n):
a = dp[i - 1][1] + li[i][0]
b = dp[i - 1][2] + li[i][0]
dp[i][0] = max(a, b)
a = dp[i - 1][0] + li[i][1]
b = dp[i - 1][2] + li[i][1]
dp[i][1] = max(a, b)
a = dp[i - 1][0] + li[i][2]
b = dp[i - 1][1] + li[i][2]
dp[i][2] = max(a, b)
print((max(dp[-1])))
| import sys
import math
import itertools
import collections
import numpy as np
rl = sys.stdin.readline
n = int(rl())
li = [list(map(int, rl().split())) for _ in range(n)]
dp = [[0] * 3 for _ in range(n)]
dp[0] = li[0]
for i in range(1, n):
a = dp[i - 1][1] + li[i][0]
b = dp[i - 1][2] + li[i][0]
dp[i][0] = max(a, b)
a = dp[i - 1][0] + li[i][1]
b = dp[i - 1][2] + li[i][1]
dp[i][1] = max(a, b)
a = dp[i - 1][0] + li[i][2]
b = dp[i - 1][1] + li[i][2]
dp[i][2] = max(a, b)
print((max(dp[-1])))
| false | 0 | [
"-dp = np.zeros((n, 3), dtype=int)",
"+dp = [[0] * 3 for _ in range(n)]"
] | false | 0.456797 | 0.064729 | 7.057087 | [
"s322624012",
"s310015186"
] |
u396495667 | p04044 | python | s172453455 | s885990746 | 20 | 17 | 3,316 | 3,060 | Accepted | Accepted | 15 | n,l =list(map(int, input().split()))
s = [eval(input()) for i in range(n)]
s.sort()
print((''.join(s))) | n,l = list(map(int, input().split()))
s = [eval(input()) for _ in range(n)]
s.sort()
print((''.join(s))) | 4 | 4 | 92 | 93 | n, l = list(map(int, input().split()))
s = [eval(input()) for i in range(n)]
s.sort()
print(("".join(s)))
| n, l = list(map(int, input().split()))
s = [eval(input()) for _ in range(n)]
s.sort()
print(("".join(s)))
| false | 0 | [
"-s = [eval(input()) for i in range(n)]",
"+s = [eval(input()) for _ in range(n)]"
] | false | 0.112262 | 0.036336 | 3.089593 | [
"s172453455",
"s885990746"
] |
u562935282 | p03039 | python | s736246388 | s518768180 | 241 | 205 | 18,960 | 11,384 | Accepted | Accepted | 14.94 | def cmb(n, r):
return fact[n] * inv_fact[r] * inv_fact[n - r] % MOD
MOD = 10 ** 9 + 7
N, M, K = list(map(int, input().split()))
fact = [1]
for i in range(1, N * M - 2 + 1):
fact.append(fact[-1] * i % MOD)
inv_fact = [-1] * (N * M - 1)
inv_fact[-1] = pow(fact[-1], MOD - 2, MOD)
for i in range(N * M - 3, -1, -1):
inv_fact[i] = inv_fact[i + 1] * (i + 1) % MOD
pat = cmb(N * M - 2, K - 2)
ans = 0
for i in range(M):
ans += i * (M - i) * N ** 2
for i in range(N):
ans += i * (N - i) * M ** 2
ans = (ans * pat) % MOD
print(ans)
| from collections import defaultdict
mod = 10 ** 9 + 7
memo = defaultdict(int)
def cmb(n, r):
if (n, r) in memo:
return memo[(n, r)]
if n < r or r < 0:
return 0
if r > n - r:
return cmb(n, n - r)
res = f[n] * pow(f[n - r], mod - 2, mod) * pow(f[r], mod - 2, mod) % mod
memo[(n, r)] = res
return res
n, m, k = list(map(int, input().split()))
f = [1]
for i in range(1, 2 * 10 ** 5 + 1):
f.append(f[-1] * i % mod)
ans = 0
for d in range(1, m):
ans += d * (m - d) * n ** 2
ans %= mod
for d in range(1, n):
ans += d * (n - d) * m ** 2
ans %= mod
ans *= cmb(n * m - 2, k - 2)
ans %= mod
print(ans)
| 30 | 41 | 578 | 707 | def cmb(n, r):
return fact[n] * inv_fact[r] * inv_fact[n - r] % MOD
MOD = 10**9 + 7
N, M, K = list(map(int, input().split()))
fact = [1]
for i in range(1, N * M - 2 + 1):
fact.append(fact[-1] * i % MOD)
inv_fact = [-1] * (N * M - 1)
inv_fact[-1] = pow(fact[-1], MOD - 2, MOD)
for i in range(N * M - 3, -1, -1):
inv_fact[i] = inv_fact[i + 1] * (i + 1) % MOD
pat = cmb(N * M - 2, K - 2)
ans = 0
for i in range(M):
ans += i * (M - i) * N**2
for i in range(N):
ans += i * (N - i) * M**2
ans = (ans * pat) % MOD
print(ans)
| from collections import defaultdict
mod = 10**9 + 7
memo = defaultdict(int)
def cmb(n, r):
if (n, r) in memo:
return memo[(n, r)]
if n < r or r < 0:
return 0
if r > n - r:
return cmb(n, n - r)
res = f[n] * pow(f[n - r], mod - 2, mod) * pow(f[r], mod - 2, mod) % mod
memo[(n, r)] = res
return res
n, m, k = list(map(int, input().split()))
f = [1]
for i in range(1, 2 * 10**5 + 1):
f.append(f[-1] * i % mod)
ans = 0
for d in range(1, m):
ans += d * (m - d) * n**2
ans %= mod
for d in range(1, n):
ans += d * (n - d) * m**2
ans %= mod
ans *= cmb(n * m - 2, k - 2)
ans %= mod
print(ans)
| false | 26.829268 | [
"-def cmb(n, r):",
"- return fact[n] * inv_fact[r] * inv_fact[n - r] % MOD",
"+from collections import defaultdict",
"+",
"+mod = 10**9 + 7",
"+memo = defaultdict(int)",
"-MOD = 10**9 + 7",
"-N, M, K = list(map(int, input().split()))",
"-fact = [1]",
"-for i in range(1, N * M - 2 + 1):",
"- fact.append(fact[-1] * i % MOD)",
"-inv_fact = [-1] * (N * M - 1)",
"-inv_fact[-1] = pow(fact[-1], MOD - 2, MOD)",
"-for i in range(N * M - 3, -1, -1):",
"- inv_fact[i] = inv_fact[i + 1] * (i + 1) % MOD",
"-pat = cmb(N * M - 2, K - 2)",
"+def cmb(n, r):",
"+ if (n, r) in memo:",
"+ return memo[(n, r)]",
"+ if n < r or r < 0:",
"+ return 0",
"+ if r > n - r:",
"+ return cmb(n, n - r)",
"+ res = f[n] * pow(f[n - r], mod - 2, mod) * pow(f[r], mod - 2, mod) % mod",
"+ memo[(n, r)] = res",
"+ return res",
"+",
"+",
"+n, m, k = list(map(int, input().split()))",
"+f = [1]",
"+for i in range(1, 2 * 10**5 + 1):",
"+ f.append(f[-1] * i % mod)",
"-for i in range(M):",
"- ans += i * (M - i) * N**2",
"-for i in range(N):",
"- ans += i * (N - i) * M**2",
"-ans = (ans * pat) % MOD",
"+for d in range(1, m):",
"+ ans += d * (m - d) * n**2",
"+ ans %= mod",
"+for d in range(1, n):",
"+ ans += d * (n - d) * m**2",
"+ ans %= mod",
"+ans *= cmb(n * m - 2, k - 2)",
"+ans %= mod"
] | false | 0.043418 | 0.146628 | 0.296106 | [
"s736246388",
"s518768180"
] |
u423585790 | p03026 | python | s796170997 | s785554572 | 302 | 249 | 48,860 | 49,116 | Accepted | Accepted | 17.55 | #!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list([int(x)-1 for x in stdin.readline().split()])
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')
#A
def A():
n = II()
print(((n-2)*180))
return
#B
def B():
b = S()
kati = b.count("o")
kati += 15 - len(b)
if kati >= 8:
print("YES")
else:
print("NO")
return
#C
def C():
return
#D
def D():
n = II()
ab = LIR_(n-1)
C = LI()
C.sort(reverse=True)
c = deque()
for ci in C:
c.appendleft(ci)
edg = [[] for i in range(n)]
for a, b in ab:
edg[a].append(b)
edg[b].append(a)
for num,e in enumerate(edg):
if len(e) == 1:
start = num
break
q = deque()
ans = [0 for i in range(n)]
q.append(start)
ans[start] = c.pop()
# print(start)
while q:
p = q.pop()
for e in edg[p]:
if not ans[e]:
ans[e] = c.pop()
q.append(e)
anssum = 0
for a, b in ab:
anssum += min(ans[a], ans[b])
print(anssum)
ans = list(map(str, ans))
print((" ".join(ans)))
return
#E
def E():
return
#F
def F():
return
#G
def G():
return
#H
def H():
return
#Solve
if __name__ == '__main__':
D()
| #!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list([int(x)-1 for x in stdin.readline().split()])
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')
#A
def A():
n = II()
print(((n-2)*180))
return
#B
def B():
b = S()
kati = b.count("o")
kati += 15 - len(b)
if kati >= 8:
print("YES")
else:
print("NO")
return
#C
def C():
return
#D
def D():
n = II()
ab = LIR_(n-1)
C = LI()
C.sort()
c = deque(C)
edg = [[] for i in range(n)]
for a, b in ab:
edg[a].append(b)
edg[b].append(a)
for num,e in enumerate(edg):
if len(e) == 1:
start = num
break
q = deque()
ans = [0 for i in range(n)]
q.append(start)
ans[start] = c.pop()
# print(start)
while q:
p = q.pop()
for e in edg[p]:
if not ans[e]:
ans[e] = c.pop()
q.append(e)
anssum = 0
for a, b in ab:
anssum += min(ans[a], ans[b])
print(anssum)
ans = list(map(str, ans))
print((" ".join(ans)))
return
#E
def E():
return
#F
def F():
return
#G
def G():
return
#H
def H():
return
#Solve
if __name__ == '__main__':
D() | 108 | 106 | 2,268 | 2,223 | #!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI():
return list(map(int, stdin.readline().split()))
def LF():
return list(map(float, stdin.readline().split()))
def LI_():
return list([int(x) - 1 for x in stdin.readline().split()])
def II():
return int(stdin.readline())
def IF():
return float(stdin.readline())
def LS():
return list(map(list, stdin.readline().split()))
def S():
return list(stdin.readline().rstrip())
def IR(n):
return [II() for _ in range(n)]
def LIR(n):
return [LI() for _ in range(n)]
def FR(n):
return [IF() for _ in range(n)]
def LFR(n):
return [LI() for _ in range(n)]
def LIR_(n):
return [LI_() for _ in range(n)]
def SR(n):
return [S() for _ in range(n)]
def LSR(n):
return [LS() for _ in range(n)]
mod = 1000000007
inf = float("INF")
# A
def A():
n = II()
print(((n - 2) * 180))
return
# B
def B():
b = S()
kati = b.count("o")
kati += 15 - len(b)
if kati >= 8:
print("YES")
else:
print("NO")
return
# C
def C():
return
# D
def D():
n = II()
ab = LIR_(n - 1)
C = LI()
C.sort(reverse=True)
c = deque()
for ci in C:
c.appendleft(ci)
edg = [[] for i in range(n)]
for a, b in ab:
edg[a].append(b)
edg[b].append(a)
for num, e in enumerate(edg):
if len(e) == 1:
start = num
break
q = deque()
ans = [0 for i in range(n)]
q.append(start)
ans[start] = c.pop()
# print(start)
while q:
p = q.pop()
for e in edg[p]:
if not ans[e]:
ans[e] = c.pop()
q.append(e)
anssum = 0
for a, b in ab:
anssum += min(ans[a], ans[b])
print(anssum)
ans = list(map(str, ans))
print((" ".join(ans)))
return
# E
def E():
return
# F
def F():
return
# G
def G():
return
# H
def H():
return
# Solve
if __name__ == "__main__":
D()
| #!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI():
return list(map(int, stdin.readline().split()))
def LF():
return list(map(float, stdin.readline().split()))
def LI_():
return list([int(x) - 1 for x in stdin.readline().split()])
def II():
return int(stdin.readline())
def IF():
return float(stdin.readline())
def LS():
return list(map(list, stdin.readline().split()))
def S():
return list(stdin.readline().rstrip())
def IR(n):
return [II() for _ in range(n)]
def LIR(n):
return [LI() for _ in range(n)]
def FR(n):
return [IF() for _ in range(n)]
def LFR(n):
return [LI() for _ in range(n)]
def LIR_(n):
return [LI_() for _ in range(n)]
def SR(n):
return [S() for _ in range(n)]
def LSR(n):
return [LS() for _ in range(n)]
mod = 1000000007
inf = float("INF")
# A
def A():
n = II()
print(((n - 2) * 180))
return
# B
def B():
b = S()
kati = b.count("o")
kati += 15 - len(b)
if kati >= 8:
print("YES")
else:
print("NO")
return
# C
def C():
return
# D
def D():
n = II()
ab = LIR_(n - 1)
C = LI()
C.sort()
c = deque(C)
edg = [[] for i in range(n)]
for a, b in ab:
edg[a].append(b)
edg[b].append(a)
for num, e in enumerate(edg):
if len(e) == 1:
start = num
break
q = deque()
ans = [0 for i in range(n)]
q.append(start)
ans[start] = c.pop()
# print(start)
while q:
p = q.pop()
for e in edg[p]:
if not ans[e]:
ans[e] = c.pop()
q.append(e)
anssum = 0
for a, b in ab:
anssum += min(ans[a], ans[b])
print(anssum)
ans = list(map(str, ans))
print((" ".join(ans)))
return
# E
def E():
return
# F
def F():
return
# G
def G():
return
# H
def H():
return
# Solve
if __name__ == "__main__":
D()
| false | 1.851852 | [
"- C.sort(reverse=True)",
"- c = deque()",
"- for ci in C:",
"- c.appendleft(ci)",
"+ C.sort()",
"+ c = deque(C)"
] | false | 0.041624 | 0.041315 | 1.007488 | [
"s796170997",
"s785554572"
] |
u072717685 | p02660 | python | s016070651 | s827846952 | 292 | 123 | 9,448 | 9,348 | Accepted | Accepted | 57.88 | import sys
from collections import Counter
def main():
n = int(eval(input()))
def is_prime(n):
for i in range(2, n + 1):
if i * i > n:
break
if n % i == 0:
return False
return n != 1
def prime_dec(n):
i = 2
table = []
while i * i <= n:
while n % i == 0:
n /= i
table.append(int(i))
i += 1
if n > 1:
table.append(n)
return table
if is_prime(n):
print((1))
sys.exit()
pd = prime_dec(n)
pdc = Counter(pd)
pdcl = [pdc[i] for i in pdc]
r = 0
for pse in pdcl:
num = pse
cnt = 1
while num > 0:
if cnt > num:
break
else:
r += 1
num -= cnt
cnt += 1
print(r)
if __name__ == '__main__':
main() | import sys
read = sys.stdin.read
def main():
def factorization(n):
arr = []
temp = n
for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
if temp % i == 0:
cnt = 0
while temp % i == 0:
cnt += 1
temp //= i
arr.append([i, cnt])
if temp != 1:
arr.append([temp, 1])
if arr == []:
arr.append([n, 1])
return arr
n = int(eval(input()))
if n == 1:
print((0))
sys.exit()
nfac = factorization(n)
r = 0
for nfe in nfac:
c = 1
while True:
if c <= nfe[1]:
nfe[1] -= c
r += 1
c += 1
else:
break
print(r)
if __name__ == '__main__':
main()
| 49 | 38 | 981 | 873 | import sys
from collections import Counter
def main():
n = int(eval(input()))
def is_prime(n):
for i in range(2, n + 1):
if i * i > n:
break
if n % i == 0:
return False
return n != 1
def prime_dec(n):
i = 2
table = []
while i * i <= n:
while n % i == 0:
n /= i
table.append(int(i))
i += 1
if n > 1:
table.append(n)
return table
if is_prime(n):
print((1))
sys.exit()
pd = prime_dec(n)
pdc = Counter(pd)
pdcl = [pdc[i] for i in pdc]
r = 0
for pse in pdcl:
num = pse
cnt = 1
while num > 0:
if cnt > num:
break
else:
r += 1
num -= cnt
cnt += 1
print(r)
if __name__ == "__main__":
main()
| import sys
read = sys.stdin.read
def main():
def factorization(n):
arr = []
temp = n
for i in range(2, int(-(-(n**0.5) // 1)) + 1):
if temp % i == 0:
cnt = 0
while temp % i == 0:
cnt += 1
temp //= i
arr.append([i, cnt])
if temp != 1:
arr.append([temp, 1])
if arr == []:
arr.append([n, 1])
return arr
n = int(eval(input()))
if n == 1:
print((0))
sys.exit()
nfac = factorization(n)
r = 0
for nfe in nfac:
c = 1
while True:
if c <= nfe[1]:
nfe[1] -= c
r += 1
c += 1
else:
break
print(r)
if __name__ == "__main__":
main()
| false | 22.44898 | [
"-from collections import Counter",
"+",
"+read = sys.stdin.read",
"+ def factorization(n):",
"+ arr = []",
"+ temp = n",
"+ for i in range(2, int(-(-(n**0.5) // 1)) + 1):",
"+ if temp % i == 0:",
"+ cnt = 0",
"+ while temp % i == 0:",
"+ cnt += 1",
"+ temp //= i",
"+ arr.append([i, cnt])",
"+ if temp != 1:",
"+ arr.append([temp, 1])",
"+ if arr == []:",
"+ arr.append([n, 1])",
"+ return arr",
"+",
"-",
"- def is_prime(n):",
"- for i in range(2, n + 1):",
"- if i * i > n:",
"+ if n == 1:",
"+ print((0))",
"+ sys.exit()",
"+ nfac = factorization(n)",
"+ r = 0",
"+ for nfe in nfac:",
"+ c = 1",
"+ while True:",
"+ if c <= nfe[1]:",
"+ nfe[1] -= c",
"+ r += 1",
"+ c += 1",
"+ else:",
"- if n % i == 0:",
"- return False",
"- return n != 1",
"-",
"- def prime_dec(n):",
"- i = 2",
"- table = []",
"- while i * i <= n:",
"- while n % i == 0:",
"- n /= i",
"- table.append(int(i))",
"- i += 1",
"- if n > 1:",
"- table.append(n)",
"- return table",
"-",
"- if is_prime(n):",
"- print((1))",
"- sys.exit()",
"- pd = prime_dec(n)",
"- pdc = Counter(pd)",
"- pdcl = [pdc[i] for i in pdc]",
"- r = 0",
"- for pse in pdcl:",
"- num = pse",
"- cnt = 1",
"- while num > 0:",
"- if cnt > num:",
"- break",
"- else:",
"- r += 1",
"- num -= cnt",
"- cnt += 1"
] | false | 0.086412 | 0.060739 | 1.422684 | [
"s016070651",
"s827846952"
] |
u077291787 | p03281 | python | s693132973 | s221723740 | 19 | 17 | 3,060 | 3,064 | Accepted | Accepted | 10.53 | # ABC106B - 105
n = int(eval(input()))
odd = []
odd_divs = []
for i in range(1, n + 1):
if i % 2 == 1:
odd.append(i)
for i in range(len(odd)):
count = 0
for j in range(1, odd[i] + 1):
if odd[i] % j == 0:
count += 1
odd_divs.append(count)
print((odd_divs.count(8))) | # ABC106B - 105
def divisors(x: int) -> set:
"""
Compute divisors of a number.
Args: x (int): an integer to be evaluated.
Returns: divs (set): set of divisors
"""
divs = set()
for i in range(1, int(x ** 0.5) + 1):
if x % i == 0:
divs.add(i), divs.add(x // i)
return divs
def main():
N = int(eval(input()))
ans = sum(len(divisors(i)) == 8 for i in range(1, N + 1, 2))
print(ans)
if __name__ == "__main__":
main() | 17 | 23 | 343 | 504 | # ABC106B - 105
n = int(eval(input()))
odd = []
odd_divs = []
for i in range(1, n + 1):
if i % 2 == 1:
odd.append(i)
for i in range(len(odd)):
count = 0
for j in range(1, odd[i] + 1):
if odd[i] % j == 0:
count += 1
odd_divs.append(count)
print((odd_divs.count(8)))
| # ABC106B - 105
def divisors(x: int) -> set:
"""
Compute divisors of a number.
Args: x (int): an integer to be evaluated.
Returns: divs (set): set of divisors
"""
divs = set()
for i in range(1, int(x**0.5) + 1):
if x % i == 0:
divs.add(i), divs.add(x // i)
return divs
def main():
N = int(eval(input()))
ans = sum(len(divisors(i)) == 8 for i in range(1, N + 1, 2))
print(ans)
if __name__ == "__main__":
main()
| false | 26.086957 | [
"-n = int(eval(input()))",
"-odd = []",
"-odd_divs = []",
"-for i in range(1, n + 1):",
"- if i % 2 == 1:",
"- odd.append(i)",
"-for i in range(len(odd)):",
"- count = 0",
"- for j in range(1, odd[i] + 1):",
"- if odd[i] % j == 0:",
"- count += 1",
"- odd_divs.append(count)",
"-print((odd_divs.count(8)))",
"+def divisors(x: int) -> set:",
"+ \"\"\"",
"+ Compute divisors of a number.",
"+ Args: x (int): an integer to be evaluated.",
"+ Returns: divs (set): set of divisors",
"+ \"\"\"",
"+ divs = set()",
"+ for i in range(1, int(x**0.5) + 1):",
"+ if x % i == 0:",
"+ divs.add(i), divs.add(x // i)",
"+ return divs",
"+",
"+",
"+def main():",
"+ N = int(eval(input()))",
"+ ans = sum(len(divisors(i)) == 8 for i in range(1, N + 1, 2))",
"+ print(ans)",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.050189 | 0.050268 | 0.998412 | [
"s693132973",
"s221723740"
] |
u345966487 | p03363 | python | s070235625 | s955986283 | 165 | 130 | 41,492 | 35,712 | Accepted | Accepted | 21.21 | import itertools
import collections
N = int(eval(input()))
A = list(map(int, input().split()))
acum = [0] + list(itertools.accumulate(A))
acount = collections.Counter(acum)
print((sum(n * (n-1) // 2 for n in list(acount.values())))) | from itertools import *
from collections import *
eval(input())
A=list(accumulate(list(map(int,input().split()))))
print((sum(n*(n-1)//2 for n in list(Counter(A+[0]).values())))) | 7 | 5 | 224 | 162 | import itertools
import collections
N = int(eval(input()))
A = list(map(int, input().split()))
acum = [0] + list(itertools.accumulate(A))
acount = collections.Counter(acum)
print((sum(n * (n - 1) // 2 for n in list(acount.values()))))
| from itertools import *
from collections import *
eval(input())
A = list(accumulate(list(map(int, input().split()))))
print((sum(n * (n - 1) // 2 for n in list(Counter(A + [0]).values()))))
| false | 28.571429 | [
"-import itertools",
"-import collections",
"+from itertools import *",
"+from collections import *",
"-N = int(eval(input()))",
"-A = list(map(int, input().split()))",
"-acum = [0] + list(itertools.accumulate(A))",
"-acount = collections.Counter(acum)",
"-print((sum(n * (n - 1) // 2 for n in list(acount.values()))))",
"+eval(input())",
"+A = list(accumulate(list(map(int, input().split()))))",
"+print((sum(n * (n - 1) // 2 for n in list(Counter(A + [0]).values()))))"
] | false | 0.042008 | 0.046535 | 0.902724 | [
"s070235625",
"s955986283"
] |
u077291787 | p04035 | python | s368312694 | s610373607 | 103 | 74 | 18,156 | 21,836 | Accepted | Accepted | 28.16 | # AGC002C - Knot Puzzle
def main():
N, L = tuple(map(int, input().split()))
A = tuple(map(int, input().split()))
B = [i + j for i, j in zip(A, A[1:])]
for i, (a, b) in enumerate(zip(A, A[1:]), 1):
if a + b >= L:
ans = [i for i in range(1, i)]
ans += [i for i in range(N - 1, i, -1)] + [i]
print("Possible")
print(*ans, sep="\n")
break
else:
print("Impossible")
if __name__ == "__main__":
main()
| # AGC002C - Knot Puzzle
def main():
N, L, *A = list(map(int, open(0).read().split()))
B = [i + j for i, j in zip(A, A[1:])]
x = max(B)
if x >= L: # at least one pair must be equal or greater than L
idx = B.index(x) + 1
# keep the biggest one until the end
ans = [i for i in range(1, idx)] + [i for i in range(N - 1, idx, -1)] + [idx]
print("Possible")
print(("\n".join(map(str, ans))))
else:
print("Impossible")
if __name__ == "__main__":
main() | 18 | 17 | 513 | 528 | # AGC002C - Knot Puzzle
def main():
N, L = tuple(map(int, input().split()))
A = tuple(map(int, input().split()))
B = [i + j for i, j in zip(A, A[1:])]
for i, (a, b) in enumerate(zip(A, A[1:]), 1):
if a + b >= L:
ans = [i for i in range(1, i)]
ans += [i for i in range(N - 1, i, -1)] + [i]
print("Possible")
print(*ans, sep="\n")
break
else:
print("Impossible")
if __name__ == "__main__":
main()
| # AGC002C - Knot Puzzle
def main():
N, L, *A = list(map(int, open(0).read().split()))
B = [i + j for i, j in zip(A, A[1:])]
x = max(B)
if x >= L: # at least one pair must be equal or greater than L
idx = B.index(x) + 1
# keep the biggest one until the end
ans = [i for i in range(1, idx)] + [i for i in range(N - 1, idx, -1)] + [idx]
print("Possible")
print(("\n".join(map(str, ans))))
else:
print("Impossible")
if __name__ == "__main__":
main()
| false | 5.555556 | [
"- N, L = tuple(map(int, input().split()))",
"- A = tuple(map(int, input().split()))",
"+ N, L, *A = list(map(int, open(0).read().split()))",
"- for i, (a, b) in enumerate(zip(A, A[1:]), 1):",
"- if a + b >= L:",
"- ans = [i for i in range(1, i)]",
"- ans += [i for i in range(N - 1, i, -1)] + [i]",
"- print(\"Possible\")",
"- print(*ans, sep=\"\\n\")",
"- break",
"+ x = max(B)",
"+ if x >= L: # at least one pair must be equal or greater than L",
"+ idx = B.index(x) + 1",
"+ # keep the biggest one until the end",
"+ ans = [i for i in range(1, idx)] + [i for i in range(N - 1, idx, -1)] + [idx]",
"+ print(\"Possible\")",
"+ print((\"\\n\".join(map(str, ans))))"
] | false | 0.037576 | 0.040472 | 0.928461 | [
"s368312694",
"s610373607"
] |
u759412327 | p02959 | python | s171510071 | s676762955 | 142 | 121 | 18,476 | 24,152 | Accepted | Accepted | 14.79 | N = int(eval(input()))
A = list(map(int,input().split()))
B = list(map(int,input().split()))
z = 0
for i in range(N):
if B[i]<=A[i]:
z+=B[i]
elif A[i]<B[i]<=A[i]+A[i+1]:
z+=B[i]
A[i+1]-=B[i]-A[i]
else:
z+=A[i]+A[i+1]
A[i+1]=0
print(z) | N = int(eval(input()))
A = list(map(int,input().split()))
B = list(map(int,input().split()))
ans = 0
for n in range(N):
if B[n]<=A[n]:
ans+=B[n]
elif B[n]<=A[n]+A[n+1]:
ans+=B[n]
A[n+1]-=B[n]-A[n]
else:
ans+=A[n]+A[n+1]
A[n+1] = 0
print(ans) | 16 | 16 | 271 | 278 | N = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
z = 0
for i in range(N):
if B[i] <= A[i]:
z += B[i]
elif A[i] < B[i] <= A[i] + A[i + 1]:
z += B[i]
A[i + 1] -= B[i] - A[i]
else:
z += A[i] + A[i + 1]
A[i + 1] = 0
print(z)
| N = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = 0
for n in range(N):
if B[n] <= A[n]:
ans += B[n]
elif B[n] <= A[n] + A[n + 1]:
ans += B[n]
A[n + 1] -= B[n] - A[n]
else:
ans += A[n] + A[n + 1]
A[n + 1] = 0
print(ans)
| false | 0 | [
"-z = 0",
"-for i in range(N):",
"- if B[i] <= A[i]:",
"- z += B[i]",
"- elif A[i] < B[i] <= A[i] + A[i + 1]:",
"- z += B[i]",
"- A[i + 1] -= B[i] - A[i]",
"+ans = 0",
"+for n in range(N):",
"+ if B[n] <= A[n]:",
"+ ans += B[n]",
"+ elif B[n] <= A[n] + A[n + 1]:",
"+ ans += B[n]",
"+ A[n + 1] -= B[n] - A[n]",
"- z += A[i] + A[i + 1]",
"- A[i + 1] = 0",
"-print(z)",
"+ ans += A[n] + A[n + 1]",
"+ A[n + 1] = 0",
"+print(ans)"
] | false | 0.066375 | 0.048962 | 1.355649 | [
"s171510071",
"s676762955"
] |
u497805118 | p03212 | python | s195527648 | s728714533 | 155 | 72 | 3,700 | 3,060 | Accepted | Accepted | 53.55 | n = int(eval(input()))
q = [ 3, 5, 7 ]
ans = 0
while len(q) != 0:
x = q.pop(0)
for i in [ 3, 5 , 7]:
y = 10 * x + i
if ( y <= n):
q.append(y)
if '3' in str(y) and '5' in str(y) and '7' in str(y):
ans += 1
print(ans) | n = int(eval(input()))
def dfs(l):
return sum([
# next
dfs(10 * l + i) if (10 * l + i) <= n else 0
for i in [3, 5, 7]] +
# current
[1 if '3' in str(l) and '5' in str(l) and '7' in str(l) else 0]
)
print((dfs(0))) | 13 | 12 | 286 | 269 | n = int(eval(input()))
q = [3, 5, 7]
ans = 0
while len(q) != 0:
x = q.pop(0)
for i in [3, 5, 7]:
y = 10 * x + i
if y <= n:
q.append(y)
if "3" in str(y) and "5" in str(y) and "7" in str(y):
ans += 1
print(ans)
| n = int(eval(input()))
def dfs(l):
return sum(
[
# next
dfs(10 * l + i) if (10 * l + i) <= n else 0
for i in [3, 5, 7]
]
+
# current
[1 if "3" in str(l) and "5" in str(l) and "7" in str(l) else 0]
)
print((dfs(0)))
| false | 7.692308 | [
"-q = [3, 5, 7]",
"-ans = 0",
"-while len(q) != 0:",
"- x = q.pop(0)",
"- for i in [3, 5, 7]:",
"- y = 10 * x + i",
"- if y <= n:",
"- q.append(y)",
"- if \"3\" in str(y) and \"5\" in str(y) and \"7\" in str(y):",
"- ans += 1",
"-print(ans)",
"+",
"+",
"+def dfs(l):",
"+ return sum(",
"+ [",
"+ # next",
"+ dfs(10 * l + i) if (10 * l + i) <= n else 0",
"+ for i in [3, 5, 7]",
"+ ]",
"+ +",
"+ # current",
"+ [1 if \"3\" in str(l) and \"5\" in str(l) and \"7\" in str(l) else 0]",
"+ )",
"+",
"+",
"+print((dfs(0)))"
] | false | 0.057477 | 0.058839 | 0.976852 | [
"s195527648",
"s728714533"
] |
u606045429 | p02867 | python | s802781629 | s275943922 | 644 | 534 | 30,864 | 30,860 | Accepted | Accepted | 17.08 | # https://atcoder.jp/contests/nikkei2019-2-qual/tasks/nikkei2019_2_qual_c
class UnionFind:
def __init__(self, size):
self.data = [-1] * size
def find(self, x):
if self.data[x] < 0:
return x
else:
self.data[x] = self.find(self.data[x])
return self.data[x]
def union(self, x, y):
x, y = self.find(x), self.find(y)
if x != y:
if self.data[y] < self.data[x]:
x, y = y, x
self.data[x] += self.data[y]
self.data[y] = x
return (x != y)
def same(self, x, y):
return (self.find(x) == self.find(y))
def size(self, x):
return -self.data[self.find(x)]
N, *AB = list(map(int, open(0).read().split()))
A, B = AB[:N], AB[N:]
AI = sorted((a, i) for i, (b, a) in enumerate(sorted(zip(B, A))))
A.sort()
B.sort()
if any(a > b for a, b in zip(A, B)):
print("No")
quit()
uf = UnionFind(N)
for j, (a, i) in enumerate(AI):
uf.union(i, j)
parents = {uf.find(i) for i in range(N)}
if len(parents) > 1:
print("Yes")
quit()
if any(a <= b for a, b in zip(A[1:], B)):
print("Yes")
else:
print("No") | # https://atcoder.jp/contests/nikkei2019-2-qual/tasks/nikkei2019_2_qual_c
class UnionFind:
def __init__(self, size):
self.data = [-1] * size
def find(self, x):
if self.data[x] < 0:
return x
else:
self.data[x] = self.find(self.data[x])
return self.data[x]
def union(self, x, y):
x, y = self.find(x), self.find(y)
if x != y:
if self.data[y] < self.data[x]:
x, y = y, x
self.data[x] += self.data[y]
self.data[y] = x
return (x != y)
def same(self, x, y):
return (self.find(x) == self.find(y))
def size(self, x):
return -self.data[self.find(x)]
N, *AB = list(map(int, open(0).read().split()))
A, B = AB[:N], AB[N:]
AI = sorted((a, i) for i, (b, a) in enumerate(sorted(zip(B, A))))
A.sort()
B.sort()
if any(a > b for a, b in zip(A, B)):
print("No")
quit()
uf = UnionFind(N)
for j, (a, i) in enumerate(AI):
uf.union(i, j)
if uf.size(0) != N or any(a <= b for a, b in zip(A[1:], B)):
print("Yes")
else:
print("No") | 50 | 44 | 1,221 | 1,142 | # https://atcoder.jp/contests/nikkei2019-2-qual/tasks/nikkei2019_2_qual_c
class UnionFind:
def __init__(self, size):
self.data = [-1] * size
def find(self, x):
if self.data[x] < 0:
return x
else:
self.data[x] = self.find(self.data[x])
return self.data[x]
def union(self, x, y):
x, y = self.find(x), self.find(y)
if x != y:
if self.data[y] < self.data[x]:
x, y = y, x
self.data[x] += self.data[y]
self.data[y] = x
return x != y
def same(self, x, y):
return self.find(x) == self.find(y)
def size(self, x):
return -self.data[self.find(x)]
N, *AB = list(map(int, open(0).read().split()))
A, B = AB[:N], AB[N:]
AI = sorted((a, i) for i, (b, a) in enumerate(sorted(zip(B, A))))
A.sort()
B.sort()
if any(a > b for a, b in zip(A, B)):
print("No")
quit()
uf = UnionFind(N)
for j, (a, i) in enumerate(AI):
uf.union(i, j)
parents = {uf.find(i) for i in range(N)}
if len(parents) > 1:
print("Yes")
quit()
if any(a <= b for a, b in zip(A[1:], B)):
print("Yes")
else:
print("No")
| # https://atcoder.jp/contests/nikkei2019-2-qual/tasks/nikkei2019_2_qual_c
class UnionFind:
def __init__(self, size):
self.data = [-1] * size
def find(self, x):
if self.data[x] < 0:
return x
else:
self.data[x] = self.find(self.data[x])
return self.data[x]
def union(self, x, y):
x, y = self.find(x), self.find(y)
if x != y:
if self.data[y] < self.data[x]:
x, y = y, x
self.data[x] += self.data[y]
self.data[y] = x
return x != y
def same(self, x, y):
return self.find(x) == self.find(y)
def size(self, x):
return -self.data[self.find(x)]
N, *AB = list(map(int, open(0).read().split()))
A, B = AB[:N], AB[N:]
AI = sorted((a, i) for i, (b, a) in enumerate(sorted(zip(B, A))))
A.sort()
B.sort()
if any(a > b for a, b in zip(A, B)):
print("No")
quit()
uf = UnionFind(N)
for j, (a, i) in enumerate(AI):
uf.union(i, j)
if uf.size(0) != N or any(a <= b for a, b in zip(A[1:], B)):
print("Yes")
else:
print("No")
| false | 12 | [
"-parents = {uf.find(i) for i in range(N)}",
"-if len(parents) > 1:",
"- print(\"Yes\")",
"- quit()",
"-if any(a <= b for a, b in zip(A[1:], B)):",
"+if uf.size(0) != N or any(a <= b for a, b in zip(A[1:], B)):"
] | false | 0.040745 | 0.038257 | 1.065036 | [
"s802781629",
"s275943922"
] |
u583507988 | p03457 | python | s250247249 | s815682163 | 272 | 234 | 17,720 | 9,176 | Accepted | Accepted | 13.97 | n = int(eval(input()))
t = [0]
x = [0]
y = [0]
for i in range(n):
t_, x_, y_ = list(map(int, input().split()))
t.append(t_)
x.append(x_)
y.append(y_)
for j in range(n):
dt = t[j+1] - t[j]
dx = abs(x[j+1] - x[j])
dy = abs(y[j+1] - y[j])
if dx+dy>dt or dt%2!=(dx+dy)%2:
print('No')
exit()
print('Yes') | n=int(eval(input()))
t=0
x=0
y=0
for i in range(n):
t_,x_,y_=list(map(int,input().split()))
t=abs(t_-t)
x=abs(x_-x)
y=abs(y_-y)
if x+y>t:
print('No')
exit()
if t_%2!=(x_+y_)%2:
print('No')
exit()
print('Yes') | 19 | 17 | 335 | 243 | n = int(eval(input()))
t = [0]
x = [0]
y = [0]
for i in range(n):
t_, x_, y_ = list(map(int, input().split()))
t.append(t_)
x.append(x_)
y.append(y_)
for j in range(n):
dt = t[j + 1] - t[j]
dx = abs(x[j + 1] - x[j])
dy = abs(y[j + 1] - y[j])
if dx + dy > dt or dt % 2 != (dx + dy) % 2:
print("No")
exit()
print("Yes")
| n = int(eval(input()))
t = 0
x = 0
y = 0
for i in range(n):
t_, x_, y_ = list(map(int, input().split()))
t = abs(t_ - t)
x = abs(x_ - x)
y = abs(y_ - y)
if x + y > t:
print("No")
exit()
if t_ % 2 != (x_ + y_) % 2:
print("No")
exit()
print("Yes")
| false | 10.526316 | [
"-t = [0]",
"-x = [0]",
"-y = [0]",
"+t = 0",
"+x = 0",
"+y = 0",
"- t.append(t_)",
"- x.append(x_)",
"- y.append(y_)",
"-for j in range(n):",
"- dt = t[j + 1] - t[j]",
"- dx = abs(x[j + 1] - x[j])",
"- dy = abs(y[j + 1] - y[j])",
"- if dx + dy > dt or dt % 2 != (dx + dy) % 2:",
"+ t = abs(t_ - t)",
"+ x = abs(x_ - x)",
"+ y = abs(y_ - y)",
"+ if x + y > t:",
"+ print(\"No\")",
"+ exit()",
"+ if t_ % 2 != (x_ + y_) % 2:"
] | false | 0.037858 | 0.043813 | 0.864073 | [
"s250247249",
"s815682163"
] |
u509392332 | p02735 | python | s752558873 | s196189864 | 54 | 42 | 5,876 | 3,956 | Accepted | Accepted | 22.22 | H, W = list(map(int, input().split()))
def change(x):
if x == '#':
return 1
else:
return 0
field = list()
for i in range(H):
field.append(list(map(change,[i for i in eval(input())])))
vector = [[1, 0], [0, 1]]
check_list = [[0 for _ in range(W)] for i in range(H)]
check_list[0][0] = 1
count_list = [[[0, [0, 0]] for _ in range(W)] for i in range(H)]
count_list[0][0][0] = field[0][0]
zahyo_check = [[(0, 0)]]
for i in range(H+W-2):
zahyo = zahyo_check[i]
zahyo_kari = list()
for (y, x) in zahyo:
for (dy, dx) in vector:
v = count_list[y][x][0]
y_k = y + dy
x_k = x + dx
try:
if field[y_k][x_k] == 1 and field[y][x] == 0:
v += 1
if check_list[y_k][x_k] == 0:
count_list[y_k][x_k][0] = v
count_list[y_k][x_k][1] = [y, x]
check_list[y_k][x_k] = 1
zahyo_kari.append((y_k, x_k))
else:
if v < count_list[y_k][x_k][0]:
count_list[y_k][x_k][0] = v
count_list[y_k][x_k][1] = [y, x]
except:
pass
zahyo_check.append(zahyo_kari)
print((count_list[H-1][W-1][0])) | H, W = list(map(int, input().split()))
def change(x): # 黒なら1, 白なら0 ※しなくてもよい
if x == '#':
return 1
else:
return 0
field = list()
for i in range(H):
field.append(list(map(change,[i for i in eval(input())])))
# 右と横に移動するベクトル
vector = [[1, 0], [0, 1]]
# 座標(i, j)に到達したか確認するリスト 未到達: 0 到達: 1
check_list = [[0 for _ in range(W)] for _ in range(H)]
check_list[0][0] = 1
# 座標(i, j)に到達するために操作が何回か必要か記録するリスト
count_list = [[0 for _ in range(W)] for _ in range(H)]
count_list[0][0] = field[0][0]
# 座標(i, j)に到達する際、どのマスから来るのが最善か記録するリスト
zahyo_front = [[0] * W] * H
zahyo_front[0][0] = [0, 0]
# 探索候補の座標を記録するリスト ※Queueモジュールなど使うと簡易になるらしい
# 1つ目のfor文 i番目のk個目の候補の座標はzahyo_search[k][i]
zahyo_search = [[(0, 0)]]
for i in range(H+W-2):
zahyo = zahyo_search[i] # i番目の探索候補の座標を取り出す
zahyo_kari = list() # (i+1)回目の探索候補の座標を記録する仮リスト
for (y, x) in zahyo:
for (dy, dx) in vector:
count = count_list[y][x]
y_k = y + dy
x_k = x + dx
try: # if y_k < H and x_k < W: でもよい
if field[y_k][x_k] == 1 and field[y][x] == 0:
count += 1
# (y_k, x_k)が黒かつ(y, x)が白ならば連続でないので、countを+1する
if check_list[y_k][x_k] == 0: # (y_k, x_k)に未到達なら、そのまま記録する
count_list[y_k][x_k] = count
zahyo_front[y_k][x_k] = [y, x]
check_list[y_k][x_k] = 1
zahyo_kari.append((y_k, x_k)) # (i+1)回目の探索候補の仮リストに入れる
else: # (y_k, x_k)に到達済
if count < count_list[y_k][x_k]: # countが記録されていたものより小さければ採用
count_list[y_k][x_k] = count
zahyo_front[y_k][x_k] = [y, x]
except:
pass
zahyo_search.append(zahyo_kari) # 仮リストを探索リストに入れる
print((count_list[H-1][W-1])) | 44 | 62 | 1,396 | 2,075 | H, W = list(map(int, input().split()))
def change(x):
if x == "#":
return 1
else:
return 0
field = list()
for i in range(H):
field.append(list(map(change, [i for i in eval(input())])))
vector = [[1, 0], [0, 1]]
check_list = [[0 for _ in range(W)] for i in range(H)]
check_list[0][0] = 1
count_list = [[[0, [0, 0]] for _ in range(W)] for i in range(H)]
count_list[0][0][0] = field[0][0]
zahyo_check = [[(0, 0)]]
for i in range(H + W - 2):
zahyo = zahyo_check[i]
zahyo_kari = list()
for (y, x) in zahyo:
for (dy, dx) in vector:
v = count_list[y][x][0]
y_k = y + dy
x_k = x + dx
try:
if field[y_k][x_k] == 1 and field[y][x] == 0:
v += 1
if check_list[y_k][x_k] == 0:
count_list[y_k][x_k][0] = v
count_list[y_k][x_k][1] = [y, x]
check_list[y_k][x_k] = 1
zahyo_kari.append((y_k, x_k))
else:
if v < count_list[y_k][x_k][0]:
count_list[y_k][x_k][0] = v
count_list[y_k][x_k][1] = [y, x]
except:
pass
zahyo_check.append(zahyo_kari)
print((count_list[H - 1][W - 1][0]))
| H, W = list(map(int, input().split()))
def change(x): # 黒なら1, 白なら0 ※しなくてもよい
if x == "#":
return 1
else:
return 0
field = list()
for i in range(H):
field.append(list(map(change, [i for i in eval(input())])))
# 右と横に移動するベクトル
vector = [[1, 0], [0, 1]]
# 座標(i, j)に到達したか確認するリスト 未到達: 0 到達: 1
check_list = [[0 for _ in range(W)] for _ in range(H)]
check_list[0][0] = 1
# 座標(i, j)に到達するために操作が何回か必要か記録するリスト
count_list = [[0 for _ in range(W)] for _ in range(H)]
count_list[0][0] = field[0][0]
# 座標(i, j)に到達する際、どのマスから来るのが最善か記録するリスト
zahyo_front = [[0] * W] * H
zahyo_front[0][0] = [0, 0]
# 探索候補の座標を記録するリスト ※Queueモジュールなど使うと簡易になるらしい
# 1つ目のfor文 i番目のk個目の候補の座標はzahyo_search[k][i]
zahyo_search = [[(0, 0)]]
for i in range(H + W - 2):
zahyo = zahyo_search[i] # i番目の探索候補の座標を取り出す
zahyo_kari = list() # (i+1)回目の探索候補の座標を記録する仮リスト
for (y, x) in zahyo:
for (dy, dx) in vector:
count = count_list[y][x]
y_k = y + dy
x_k = x + dx
try: # if y_k < H and x_k < W: でもよい
if field[y_k][x_k] == 1 and field[y][x] == 0:
count += 1
# (y_k, x_k)が黒かつ(y, x)が白ならば連続でないので、countを+1する
if check_list[y_k][x_k] == 0: # (y_k, x_k)に未到達なら、そのまま記録する
count_list[y_k][x_k] = count
zahyo_front[y_k][x_k] = [y, x]
check_list[y_k][x_k] = 1
zahyo_kari.append((y_k, x_k)) # (i+1)回目の探索候補の仮リストに入れる
else: # (y_k, x_k)に到達済
if count < count_list[y_k][x_k]: # countが記録されていたものより小さければ採用
count_list[y_k][x_k] = count
zahyo_front[y_k][x_k] = [y, x]
except:
pass
zahyo_search.append(zahyo_kari) # 仮リストを探索リストに入れる
print((count_list[H - 1][W - 1]))
| false | 29.032258 | [
"-def change(x):",
"+def change(x): # 黒なら1, 白なら0 ※しなくてもよい",
"+# 右と横に移動するベクトル",
"-check_list = [[0 for _ in range(W)] for i in range(H)]",
"+# 座標(i, j)に到達したか確認するリスト 未到達: 0 到達: 1",
"+check_list = [[0 for _ in range(W)] for _ in range(H)]",
"-count_list = [[[0, [0, 0]] for _ in range(W)] for i in range(H)]",
"-count_list[0][0][0] = field[0][0]",
"-zahyo_check = [[(0, 0)]]",
"+# 座標(i, j)に到達するために操作が何回か必要か記録するリスト",
"+count_list = [[0 for _ in range(W)] for _ in range(H)]",
"+count_list[0][0] = field[0][0]",
"+# 座標(i, j)に到達する際、どのマスから来るのが最善か記録するリスト",
"+zahyo_front = [[0] * W] * H",
"+zahyo_front[0][0] = [0, 0]",
"+# 探索候補の座標を記録するリスト ※Queueモジュールなど使うと簡易になるらしい",
"+# 1つ目のfor文 i番目のk個目の候補の座標はzahyo_search[k][i]",
"+zahyo_search = [[(0, 0)]]",
"- zahyo = zahyo_check[i]",
"- zahyo_kari = list()",
"+ zahyo = zahyo_search[i] # i番目の探索候補の座標を取り出す",
"+ zahyo_kari = list() # (i+1)回目の探索候補の座標を記録する仮リスト",
"- v = count_list[y][x][0]",
"+ count = count_list[y][x]",
"- try:",
"+ try: # if y_k < H and x_k < W: でもよい",
"- v += 1",
"- if check_list[y_k][x_k] == 0:",
"- count_list[y_k][x_k][0] = v",
"- count_list[y_k][x_k][1] = [y, x]",
"+ count += 1",
"+ # (y_k, x_k)が黒かつ(y, x)が白ならば連続でないので、countを+1する",
"+ if check_list[y_k][x_k] == 0: # (y_k, x_k)に未到達なら、そのまま記録する",
"+ count_list[y_k][x_k] = count",
"+ zahyo_front[y_k][x_k] = [y, x]",
"- zahyo_kari.append((y_k, x_k))",
"- else:",
"- if v < count_list[y_k][x_k][0]:",
"- count_list[y_k][x_k][0] = v",
"- count_list[y_k][x_k][1] = [y, x]",
"+ zahyo_kari.append((y_k, x_k)) # (i+1)回目の探索候補の仮リストに入れる",
"+ else: # (y_k, x_k)に到達済",
"+ if count < count_list[y_k][x_k]: # countが記録されていたものより小さければ採用",
"+ count_list[y_k][x_k] = count",
"+ zahyo_front[y_k][x_k] = [y, x]",
"- zahyo_check.append(zahyo_kari)",
"-print((count_list[H - 1][W - 1][0]))",
"+ zahyo_search.append(zahyo_kari) # 仮リストを探索リストに入れる",
"+print((count_list[H - 1][W - 1]))"
] | false | 0.214095 | 0.075592 | 2.832228 | [
"s752558873",
"s196189864"
] |
u562935282 | p02899 | python | s629545284 | s554104189 | 295 | 163 | 59,180 | 19,172 | Accepted | Accepted | 44.75 | n = int(eval(input()))
a = tuple(map(int, input().split()))
ans = [-1] * n
for ind, aa in enumerate(a, 1):
ans[aa - 1] = ind
print((*ans))
| n = int(eval(input()))
a = tuple(map(int, input().split()))
b = [x[0] for x in sorted(enumerate(a, 1), key=lambda x: x[1])]
print((*b))
| 7 | 4 | 142 | 136 | n = int(eval(input()))
a = tuple(map(int, input().split()))
ans = [-1] * n
for ind, aa in enumerate(a, 1):
ans[aa - 1] = ind
print((*ans))
| n = int(eval(input()))
a = tuple(map(int, input().split()))
b = [x[0] for x in sorted(enumerate(a, 1), key=lambda x: x[1])]
print((*b))
| false | 42.857143 | [
"-ans = [-1] * n",
"-for ind, aa in enumerate(a, 1):",
"- ans[aa - 1] = ind",
"-print((*ans))",
"+b = [x[0] for x in sorted(enumerate(a, 1), key=lambda x: x[1])]",
"+print((*b))"
] | false | 0.083411 | 0.1445 | 0.577237 | [
"s629545284",
"s554104189"
] |
u392319141 | p03283 | python | s595653230 | s796806970 | 1,232 | 1,122 | 26,080 | 19,148 | Accepted | Accepted | 8.93 | N, M, Q = list(map(int, input().split()))
train = [[0 for _ in range(N+1)] for _ in range(N+1)]
for _ in range(M) :
L, R = list(map(int, input().split()))
train[L][R] += 1
que = []
for _ in range(Q) :
p, q = list(map(int, input().split()))
que.append((p, q))
# 累積和
S = [[0 for _ in range(N+1)] for _ in range(N+1)] # ゼロパディング
for l in range(1, N+1) :
for r in range(1, N+1) :
S[l][r] = S[l-1][r] + S[l][r-1] - S[l-1][r-1] + train[l][r]
for p, q in que :
ans = S[q][q] - S[p-1][q] - S[q][p-1] + S[p-1][p-1]
print(ans) | N, M, Q = map(int, input().split())
LR = [[0] * (N + 1) for _ in range(N + 1)]
for _ in range(M):
L, R = map(int, input().split())
LR[L][R] += 1
for l in range(1, N + 1):
for r in range(1, N + 1):
LR[l][r] = LR[l - 1][r] + LR[l][r - 1] - LR[l - 1][r - 1] + LR[l][r]
ans = []
for _ in range(Q):
p, q = map(int, input().split())
cnt = LR[q][q] - LR[q][p - 1] - LR[p - 1][q] + LR[p - 1][p - 1]
ans.append(cnt)
print(*ans, sep='\n')
| 23 | 19 | 562 | 483 | N, M, Q = list(map(int, input().split()))
train = [[0 for _ in range(N + 1)] for _ in range(N + 1)]
for _ in range(M):
L, R = list(map(int, input().split()))
train[L][R] += 1
que = []
for _ in range(Q):
p, q = list(map(int, input().split()))
que.append((p, q))
# 累積和
S = [[0 for _ in range(N + 1)] for _ in range(N + 1)] # ゼロパディング
for l in range(1, N + 1):
for r in range(1, N + 1):
S[l][r] = S[l - 1][r] + S[l][r - 1] - S[l - 1][r - 1] + train[l][r]
for p, q in que:
ans = S[q][q] - S[p - 1][q] - S[q][p - 1] + S[p - 1][p - 1]
print(ans)
| N, M, Q = map(int, input().split())
LR = [[0] * (N + 1) for _ in range(N + 1)]
for _ in range(M):
L, R = map(int, input().split())
LR[L][R] += 1
for l in range(1, N + 1):
for r in range(1, N + 1):
LR[l][r] = LR[l - 1][r] + LR[l][r - 1] - LR[l - 1][r - 1] + LR[l][r]
ans = []
for _ in range(Q):
p, q = map(int, input().split())
cnt = LR[q][q] - LR[q][p - 1] - LR[p - 1][q] + LR[p - 1][p - 1]
ans.append(cnt)
print(*ans, sep="\n")
| false | 17.391304 | [
"-N, M, Q = list(map(int, input().split()))",
"-train = [[0 for _ in range(N + 1)] for _ in range(N + 1)]",
"+N, M, Q = map(int, input().split())",
"+LR = [[0] * (N + 1) for _ in range(N + 1)]",
"- L, R = list(map(int, input().split()))",
"- train[L][R] += 1",
"-que = []",
"-for _ in range(Q):",
"- p, q = list(map(int, input().split()))",
"- que.append((p, q))",
"-# 累積和",
"-S = [[0 for _ in range(N + 1)] for _ in range(N + 1)] # ゼロパディング",
"+ L, R = map(int, input().split())",
"+ LR[L][R] += 1",
"- S[l][r] = S[l - 1][r] + S[l][r - 1] - S[l - 1][r - 1] + train[l][r]",
"-for p, q in que:",
"- ans = S[q][q] - S[p - 1][q] - S[q][p - 1] + S[p - 1][p - 1]",
"- print(ans)",
"+ LR[l][r] = LR[l - 1][r] + LR[l][r - 1] - LR[l - 1][r - 1] + LR[l][r]",
"+ans = []",
"+for _ in range(Q):",
"+ p, q = map(int, input().split())",
"+ cnt = LR[q][q] - LR[q][p - 1] - LR[p - 1][q] + LR[p - 1][p - 1]",
"+ ans.append(cnt)",
"+print(*ans, sep=\"\\n\")"
] | false | 0.043092 | 0.04452 | 0.967942 | [
"s595653230",
"s796806970"
] |
u808427016 | p03558 | python | s021951164 | s494172101 | 91 | 68 | 9,192 | 7,832 | Accepted | Accepted | 25.27 | from collections import deque
def solve(K):
checked = [99999999999] * (K + 1)
queue = deque()
queue.append((1, 1))
checked[1] = 1
while queue:
x, n = queue.popleft()
if x == 0:
return n
_ = (x * 10) % K
if n < checked[_]:
queue.appendleft((_, n))
checked[_] = n
_ = (x + 1) % K
if n + 1 < checked[_]:
queue.append((_, n + 1))
checked[_] = n + 1
return None
K = int(eval(input()))
print((solve(K)))
| def solve(K):
checked = [False] * K
def calc(x):
while not checked[x]:
checked[x] = True
yield x
x = (x * 10) % K
i = 0
xs = [0]
while 1:
i += 1
ys = []
for x in xs:
for z in calc((x + 1) % K):
if z == 0:
return i
ys.append(z)
xs = ys
K = int(eval(input()))
print((solve(K))) | 24 | 21 | 550 | 448 | from collections import deque
def solve(K):
checked = [99999999999] * (K + 1)
queue = deque()
queue.append((1, 1))
checked[1] = 1
while queue:
x, n = queue.popleft()
if x == 0:
return n
_ = (x * 10) % K
if n < checked[_]:
queue.appendleft((_, n))
checked[_] = n
_ = (x + 1) % K
if n + 1 < checked[_]:
queue.append((_, n + 1))
checked[_] = n + 1
return None
K = int(eval(input()))
print((solve(K)))
| def solve(K):
checked = [False] * K
def calc(x):
while not checked[x]:
checked[x] = True
yield x
x = (x * 10) % K
i = 0
xs = [0]
while 1:
i += 1
ys = []
for x in xs:
for z in calc((x + 1) % K):
if z == 0:
return i
ys.append(z)
xs = ys
K = int(eval(input()))
print((solve(K)))
| false | 12.5 | [
"-from collections import deque",
"+def solve(K):",
"+ checked = [False] * K",
"+ def calc(x):",
"+ while not checked[x]:",
"+ checked[x] = True",
"+ yield x",
"+ x = (x * 10) % K",
"-def solve(K):",
"- checked = [99999999999] * (K + 1)",
"- queue = deque()",
"- queue.append((1, 1))",
"- checked[1] = 1",
"- while queue:",
"- x, n = queue.popleft()",
"- if x == 0:",
"- return n",
"- _ = (x * 10) % K",
"- if n < checked[_]:",
"- queue.appendleft((_, n))",
"- checked[_] = n",
"- _ = (x + 1) % K",
"- if n + 1 < checked[_]:",
"- queue.append((_, n + 1))",
"- checked[_] = n + 1",
"- return None",
"+ i = 0",
"+ xs = [0]",
"+ while 1:",
"+ i += 1",
"+ ys = []",
"+ for x in xs:",
"+ for z in calc((x + 1) % K):",
"+ if z == 0:",
"+ return i",
"+ ys.append(z)",
"+ xs = ys"
] | false | 0.150816 | 0.043001 | 3.507253 | [
"s021951164",
"s494172101"
] |
u836939578 | p02548 | python | s542245874 | s567907830 | 145 | 70 | 75,656 | 62,892 | Accepted | Accepted | 51.72 | N = int(eval(input()))
table = [0] * (N+5)
for i in range(1, N+3):
for j in range(i, N+2, i):
table[j] += 1
ans = 0
for i in range(N):
ans += table[i]
print(ans) | N = int(eval(input()))
ans = 0
for i in range(1, N):
ans += (N-1) // i
print(ans) | 12 | 8 | 185 | 89 | N = int(eval(input()))
table = [0] * (N + 5)
for i in range(1, N + 3):
for j in range(i, N + 2, i):
table[j] += 1
ans = 0
for i in range(N):
ans += table[i]
print(ans)
| N = int(eval(input()))
ans = 0
for i in range(1, N):
ans += (N - 1) // i
print(ans)
| false | 33.333333 | [
"-table = [0] * (N + 5)",
"-for i in range(1, N + 3):",
"- for j in range(i, N + 2, i):",
"- table[j] += 1",
"-for i in range(N):",
"- ans += table[i]",
"+for i in range(1, N):",
"+ ans += (N - 1) // i"
] | false | 0.439848 | 0.062344 | 7.055223 | [
"s542245874",
"s567907830"
] |
u200887663 | p03416 | python | s843966320 | s441828649 | 91 | 54 | 2,940 | 9,036 | Accepted | Accepted | 40.66 | a,b=list(map(int,input().split()))
count=0
for i in range(a,b+1):
l1=list(str(i))
l2=l1[::-1]
if l1==l2 :
count+=1
print(count) | #n=int(input())
a,b=list(map(int,input().split()))
#l=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]
count=0
for i in range(a,b+1):
istr=str(i)
if istr[0]==istr[4] and istr[1]==istr[3]:
count+=1
print(count)
| 8 | 10 | 138 | 265 | a, b = list(map(int, input().split()))
count = 0
for i in range(a, b + 1):
l1 = list(str(i))
l2 = l1[::-1]
if l1 == l2:
count += 1
print(count)
| # n=int(input())
a, b = list(map(int, input().split()))
# l=list(map(int,input().split()))
# l=[list(map(int,input().split())) for i in range(n)]
count = 0
for i in range(a, b + 1):
istr = str(i)
if istr[0] == istr[4] and istr[1] == istr[3]:
count += 1
print(count)
| false | 20 | [
"+# n=int(input())",
"+# l=list(map(int,input().split()))",
"+# l=[list(map(int,input().split())) for i in range(n)]",
"- l1 = list(str(i))",
"- l2 = l1[::-1]",
"- if l1 == l2:",
"+ istr = str(i)",
"+ if istr[0] == istr[4] and istr[1] == istr[3]:"
] | false | 0.05569 | 0.040246 | 1.383728 | [
"s843966320",
"s441828649"
] |
u352558780 | p03231 | python | s305261669 | s289199847 | 25 | 22 | 3,944 | 3,828 | Accepted | Accepted | 12 | import math
N,M = list(map(int,input().split()))
S = eval(input())
T = eval(input())
def lcd(n,m):
return int(n * m / gcd(n,m))
def gcd(n,m):
if n % m == 0:
return m
else:
return gcd(m,n % m)
# return int(m*n/math.gcd(n,m))
def prove(n,m):
n_i = int(n/gcd(n,m))
m_i = int(m/gcd(n,m))
n_list,m_list=[],[]
for i in range(gcd(n,m)):
n_list += S[i*n_i]
m_list += T[i*m_i]
# print(c)
# print(pair[m])
if n_list==m_list:
return lcd(n,m)
else:
return -1
print((prove(N,M)))
| import math
N,M = list(map(int,input().split()))
S = eval(input())
T = eval(input())
def lcd(n,m):
return int(n * m / gcd(n,m))
def gcd(n,m):
if n % m == 0:
return m
else:
return gcd(m,n % m)
# return int(m*n/math.gcd(n,m))
def prove(n,m):
n_i = int(lcd(n,m)/n)
m_i = int(lcd(n,m)/m)
n_list=[S[m_i*i] for i in range(gcd(n,m))]
m_list=[T[n_i*i] for i in range(gcd(n,m))]
# print(c)
# print(pair[m])
if n_list==m_list:
return lcd(n,m)
else:
return -1
print((prove(N,M)))
| 36 | 34 | 591 | 575 | import math
N, M = list(map(int, input().split()))
S = eval(input())
T = eval(input())
def lcd(n, m):
return int(n * m / gcd(n, m))
def gcd(n, m):
if n % m == 0:
return m
else:
return gcd(m, n % m)
# return int(m*n/math.gcd(n,m))
def prove(n, m):
n_i = int(n / gcd(n, m))
m_i = int(m / gcd(n, m))
n_list, m_list = [], []
for i in range(gcd(n, m)):
n_list += S[i * n_i]
m_list += T[i * m_i]
# print(c)
# print(pair[m])
if n_list == m_list:
return lcd(n, m)
else:
return -1
print((prove(N, M)))
| import math
N, M = list(map(int, input().split()))
S = eval(input())
T = eval(input())
def lcd(n, m):
return int(n * m / gcd(n, m))
def gcd(n, m):
if n % m == 0:
return m
else:
return gcd(m, n % m)
# return int(m*n/math.gcd(n,m))
def prove(n, m):
n_i = int(lcd(n, m) / n)
m_i = int(lcd(n, m) / m)
n_list = [S[m_i * i] for i in range(gcd(n, m))]
m_list = [T[n_i * i] for i in range(gcd(n, m))]
# print(c)
# print(pair[m])
if n_list == m_list:
return lcd(n, m)
else:
return -1
print((prove(N, M)))
| false | 5.555556 | [
"- n_i = int(n / gcd(n, m))",
"- m_i = int(m / gcd(n, m))",
"- n_list, m_list = [], []",
"- for i in range(gcd(n, m)):",
"- n_list += S[i * n_i]",
"- m_list += T[i * m_i]",
"+ n_i = int(lcd(n, m) / n)",
"+ m_i = int(lcd(n, m) / m)",
"+ n_list = [S[m_i * i] for i in range(gcd(n, m))]",
"+ m_list = [T[n_i * i] for i in range(gcd(n, m))]"
] | false | 0.089761 | 0.089257 | 1.005649 | [
"s305261669",
"s289199847"
] |
u922449550 | p03078 | python | s414495018 | s585462714 | 149 | 37 | 17,936 | 4,976 | Accepted | Accepted | 75.17 | # 想定解法2
X, Y, Z, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
ids = []
for x in range(1, X+1):
for y in range(1, Y+1):
if x*y > K:
break
for z in range(1, Z+1):
if x*y*z <= K:
ids.append((x-1, y-1, z-1))
else:
break
Ans = []
for x, y, z in ids:
Ans.append(A[x]+B[y]+C[z])
Ans.sort(reverse=True)
Ans = Ans[:K]
for ans in Ans:
print(ans) | # 想定解法3
import heapq
X, Y, Z, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
Q =[]
heapq.heappush(Q, [-(A[0]+B[0]+C[0]), 0, 0, 0])
added_idx = set((0, 0, 0))
for i in range(K):
nega_ans, x, y, z = heapq.heappop(Q)
print((-nega_ans))
if x+1 < X and (x+1, y, z) not in added_idx:
heapq.heappush(Q, [-(A[x+1]+B[y]+C[z]), x+1, y, z])
added_idx.add((x+1, y, z))
if y+1 < Y and (x, y+1, z) not in added_idx:
heapq.heappush(Q, [-(A[x]+B[y+1]+C[z]), x, y+1, z])
added_idx.add((x, y+1, z))
if z+1 < Z and (x, y, z+1) not in added_idx:
heapq.heappush(Q, [-(A[x]+B[y]+C[z+1]), x, y, z+1])
added_idx.add((x, y, z+1))
| 30 | 30 | 581 | 826 | # 想定解法2
X, Y, Z, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
ids = []
for x in range(1, X + 1):
for y in range(1, Y + 1):
if x * y > K:
break
for z in range(1, Z + 1):
if x * y * z <= K:
ids.append((x - 1, y - 1, z - 1))
else:
break
Ans = []
for x, y, z in ids:
Ans.append(A[x] + B[y] + C[z])
Ans.sort(reverse=True)
Ans = Ans[:K]
for ans in Ans:
print(ans)
| # 想定解法3
import heapq
X, Y, Z, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
Q = []
heapq.heappush(Q, [-(A[0] + B[0] + C[0]), 0, 0, 0])
added_idx = set((0, 0, 0))
for i in range(K):
nega_ans, x, y, z = heapq.heappop(Q)
print((-nega_ans))
if x + 1 < X and (x + 1, y, z) not in added_idx:
heapq.heappush(Q, [-(A[x + 1] + B[y] + C[z]), x + 1, y, z])
added_idx.add((x + 1, y, z))
if y + 1 < Y and (x, y + 1, z) not in added_idx:
heapq.heappush(Q, [-(A[x] + B[y + 1] + C[z]), x, y + 1, z])
added_idx.add((x, y + 1, z))
if z + 1 < Z and (x, y, z + 1) not in added_idx:
heapq.heappush(Q, [-(A[x] + B[y] + C[z + 1]), x, y, z + 1])
added_idx.add((x, y, z + 1))
| false | 0 | [
"-# 想定解法2",
"+# 想定解法3",
"+import heapq",
"+",
"-ids = []",
"-for x in range(1, X + 1):",
"- for y in range(1, Y + 1):",
"- if x * y > K:",
"- break",
"- for z in range(1, Z + 1):",
"- if x * y * z <= K:",
"- ids.append((x - 1, y - 1, z - 1))",
"- else:",
"- break",
"-Ans = []",
"-for x, y, z in ids:",
"- Ans.append(A[x] + B[y] + C[z])",
"-Ans.sort(reverse=True)",
"-Ans = Ans[:K]",
"-for ans in Ans:",
"- print(ans)",
"+Q = []",
"+heapq.heappush(Q, [-(A[0] + B[0] + C[0]), 0, 0, 0])",
"+added_idx = set((0, 0, 0))",
"+for i in range(K):",
"+ nega_ans, x, y, z = heapq.heappop(Q)",
"+ print((-nega_ans))",
"+ if x + 1 < X and (x + 1, y, z) not in added_idx:",
"+ heapq.heappush(Q, [-(A[x + 1] + B[y] + C[z]), x + 1, y, z])",
"+ added_idx.add((x + 1, y, z))",
"+ if y + 1 < Y and (x, y + 1, z) not in added_idx:",
"+ heapq.heappush(Q, [-(A[x] + B[y + 1] + C[z]), x, y + 1, z])",
"+ added_idx.add((x, y + 1, z))",
"+ if z + 1 < Z and (x, y, z + 1) not in added_idx:",
"+ heapq.heappush(Q, [-(A[x] + B[y] + C[z + 1]), x, y, z + 1])",
"+ added_idx.add((x, y, z + 1))"
] | false | 0.037817 | 0.047114 | 0.802669 | [
"s414495018",
"s585462714"
] |
u867848444 | p02802 | python | s828564079 | s143532952 | 373 | 336 | 41,756 | 29,088 | Accepted | Accepted | 9.92 | n,m=list(map(int,input().split()))
l=[list(input().split()) for i in range(m)]
from collections import defaultdict
cnt_ac=defaultdict(lambda:0)
cnt_wa=defaultdict(lambda:0)
count_wa=0
count_ac=0
for i in range(m):
if cnt_ac[l[i][0]]==0:
if l[i][1]=='WA':
cnt_wa[l[i][0]]+=1
elif l[i][1]=='AC':
cnt_ac[l[i][0]]=1
count_ac+=1
count_wa+=cnt_wa[l[i][0]]
print((count_ac,count_wa))
| from collections import defaultdict
n,m=list(map(int,input().split()))
p,s=[],[]
for i in range(m):
P,S=input().split()
p.append(int(P))
s.append(S)
pena=0
cnt_ac=defaultdict(lambda :0)
cnt_wa=defaultdict(lambda :0)
for x,y in zip(p,s):
if cnt_ac[x]==0:
if y=='AC':
cnt_ac[x]=1
pena+=cnt_wa[x]
elif y=='WA':
cnt_wa[x]+=1
print((sum(cnt_ac.values()),pena))
| 19 | 21 | 474 | 439 | n, m = list(map(int, input().split()))
l = [list(input().split()) for i in range(m)]
from collections import defaultdict
cnt_ac = defaultdict(lambda: 0)
cnt_wa = defaultdict(lambda: 0)
count_wa = 0
count_ac = 0
for i in range(m):
if cnt_ac[l[i][0]] == 0:
if l[i][1] == "WA":
cnt_wa[l[i][0]] += 1
elif l[i][1] == "AC":
cnt_ac[l[i][0]] = 1
count_ac += 1
count_wa += cnt_wa[l[i][0]]
print((count_ac, count_wa))
| from collections import defaultdict
n, m = list(map(int, input().split()))
p, s = [], []
for i in range(m):
P, S = input().split()
p.append(int(P))
s.append(S)
pena = 0
cnt_ac = defaultdict(lambda: 0)
cnt_wa = defaultdict(lambda: 0)
for x, y in zip(p, s):
if cnt_ac[x] == 0:
if y == "AC":
cnt_ac[x] = 1
pena += cnt_wa[x]
elif y == "WA":
cnt_wa[x] += 1
print((sum(cnt_ac.values()), pena))
| false | 9.52381 | [
"-n, m = list(map(int, input().split()))",
"-l = [list(input().split()) for i in range(m)]",
"+n, m = list(map(int, input().split()))",
"+p, s = [], []",
"+for i in range(m):",
"+ P, S = input().split()",
"+ p.append(int(P))",
"+ s.append(S)",
"+pena = 0",
"-count_wa = 0",
"-count_ac = 0",
"-for i in range(m):",
"- if cnt_ac[l[i][0]] == 0:",
"- if l[i][1] == \"WA\":",
"- cnt_wa[l[i][0]] += 1",
"- elif l[i][1] == \"AC\":",
"- cnt_ac[l[i][0]] = 1",
"- count_ac += 1",
"- count_wa += cnt_wa[l[i][0]]",
"-print((count_ac, count_wa))",
"+for x, y in zip(p, s):",
"+ if cnt_ac[x] == 0:",
"+ if y == \"AC\":",
"+ cnt_ac[x] = 1",
"+ pena += cnt_wa[x]",
"+ elif y == \"WA\":",
"+ cnt_wa[x] += 1",
"+print((sum(cnt_ac.values()), pena))"
] | false | 0.045195 | 0.044138 | 1.023936 | [
"s828564079",
"s143532952"
] |
u600402037 | p03073 | python | s811323112 | s256112625 | 895 | 64 | 15,696 | 4,652 | Accepted | Accepted | 92.85 | import numpy as np
S = list(int(x) for x in eval(input()))
L1 = np.array([0 if x % 2 == 0 else 1 for x in range(len(S))] )
L2 = np.array([1 if x % 2 == 0 else 0 for x in range(len(S))])
print((min(sum(np.logical_xor(S, L2)), sum(np.logical_xor(S, L1))))) | # coding: utf-8
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
S = list(map(int, list(sr())))
count = 0
for i in range(len(S)-1):
if S[i] == S[i+1]:
S[i+1] = 1 - S[i+1]
count += 1
answer = min(count, len(S) - count)
print(answer)
| 8 | 16 | 256 | 340 | import numpy as np
S = list(int(x) for x in eval(input()))
L1 = np.array([0 if x % 2 == 0 else 1 for x in range(len(S))])
L2 = np.array([1 if x % 2 == 0 else 0 for x in range(len(S))])
print((min(sum(np.logical_xor(S, L2)), sum(np.logical_xor(S, L1)))))
| # coding: utf-8
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
S = list(map(int, list(sr())))
count = 0
for i in range(len(S) - 1):
if S[i] == S[i + 1]:
S[i + 1] = 1 - S[i + 1]
count += 1
answer = min(count, len(S) - count)
print(answer)
| false | 50 | [
"-import numpy as np",
"+# coding: utf-8",
"+import sys",
"-S = list(int(x) for x in eval(input()))",
"-L1 = np.array([0 if x % 2 == 0 else 1 for x in range(len(S))])",
"-L2 = np.array([1 if x % 2 == 0 else 0 for x in range(len(S))])",
"-print((min(sum(np.logical_xor(S, L2)), sum(np.logical_xor(S, L1)))))",
"+sr = lambda: sys.stdin.readline().rstrip()",
"+ir = lambda: int(sr())",
"+lr = lambda: list(map(int, sr().split()))",
"+S = list(map(int, list(sr())))",
"+count = 0",
"+for i in range(len(S) - 1):",
"+ if S[i] == S[i + 1]:",
"+ S[i + 1] = 1 - S[i + 1]",
"+ count += 1",
"+answer = min(count, len(S) - count)",
"+print(answer)"
] | false | 0.945261 | 0.036057 | 26.215458 | [
"s811323112",
"s256112625"
] |
u644907318 | p03150 | python | s500911920 | s703006056 | 166 | 63 | 38,256 | 64,872 | Accepted | Accepted | 62.05 | S = input().strip()
N = len(S)
x = "keyence"
n = len(x)
if N<n:
flag = 0
else:
flag = 0
for i in range(7):
for j in range(1,8):
if S[:i]+S[-j:]==x:
flag = 1
break
if flag==1:break
if flag==1:
print("YES")
else:
print("NO") | S = input().strip()
N = len(S)
flag = 0
if S=="keyence":
flag = 1
else:
for i in range(N):
for j in range(i,N):
x = S[:i]
y = S[j+1:]
if x+y=="keyence":
flag = 1
break
if flag==1:break
if flag==1:
print("YES")
else:
print("NO") | 18 | 18 | 319 | 344 | S = input().strip()
N = len(S)
x = "keyence"
n = len(x)
if N < n:
flag = 0
else:
flag = 0
for i in range(7):
for j in range(1, 8):
if S[:i] + S[-j:] == x:
flag = 1
break
if flag == 1:
break
if flag == 1:
print("YES")
else:
print("NO")
| S = input().strip()
N = len(S)
flag = 0
if S == "keyence":
flag = 1
else:
for i in range(N):
for j in range(i, N):
x = S[:i]
y = S[j + 1 :]
if x + y == "keyence":
flag = 1
break
if flag == 1:
break
if flag == 1:
print("YES")
else:
print("NO")
| false | 0 | [
"-x = \"keyence\"",
"-n = len(x)",
"-if N < n:",
"- flag = 0",
"+flag = 0",
"+if S == \"keyence\":",
"+ flag = 1",
"- flag = 0",
"- for i in range(7):",
"- for j in range(1, 8):",
"- if S[:i] + S[-j:] == x:",
"+ for i in range(N):",
"+ for j in range(i, N):",
"+ x = S[:i]",
"+ y = S[j + 1 :]",
"+ if x + y == \"keyence\":"
] | false | 0.117351 | 0.037163 | 3.157723 | [
"s500911920",
"s703006056"
] |
u352394527 | p01334 | python | s251580576 | s732707688 | 120 | 110 | 6,672 | 6,672 | Accepted | Accepted | 8.33 | while True:
n = int(eval(input()))
if n == 0:break
to = []
for i in range(n):
line = list(map(int, input().split()))
for j in range(n):
x, y = line[2 * j:2 * j + 2]
to.append(y * n + x)
order = []
used = [False] * (n * n)
def dfs(x):
if used[x]:return
used[x] = True
dfs(to[x])
order.append(x)
for i in range(n * n):
dfs(i)
order.reverse()
def dfs2(x, used, group):
if used[x]:return False
if x in group:return True
group.add(x)
return dfs2(to[x], used, group)
used = [False] * (n * n)
ans = 0
for i in order:
group = set()
if not used[i]:
if dfs2(i, used, group):ans += 1
for g in group:used[g] = True
print(ans)
| while True:
n = int(eval(input()))
if n == 0:break
to = []
for i in range(n):
line = list(map(int, input().split()))
for j in range(n):
x, y = line[2 * j:2 * j + 2]
to.append(y * n + x)
order = []
used = [False] * (n * n)
def dfs(x):
if used[x]:return
used[x] = True
dfs(to[x])
order.append(x)
for i in range(n * n):
dfs(i)
order.reverse()
def dfs2(x, used, group):
if x in group:return True
if used[x]:return False
group.add(x)
used[x] = True
return dfs2(to[x], used, group)
used = [False] * (n * n)
ans = 0
for i in order:
group = set()
if not used[i]:
if dfs2(i, used, group):ans += 1
print(ans)
| 37 | 37 | 761 | 746 | while True:
n = int(eval(input()))
if n == 0:
break
to = []
for i in range(n):
line = list(map(int, input().split()))
for j in range(n):
x, y = line[2 * j : 2 * j + 2]
to.append(y * n + x)
order = []
used = [False] * (n * n)
def dfs(x):
if used[x]:
return
used[x] = True
dfs(to[x])
order.append(x)
for i in range(n * n):
dfs(i)
order.reverse()
def dfs2(x, used, group):
if used[x]:
return False
if x in group:
return True
group.add(x)
return dfs2(to[x], used, group)
used = [False] * (n * n)
ans = 0
for i in order:
group = set()
if not used[i]:
if dfs2(i, used, group):
ans += 1
for g in group:
used[g] = True
print(ans)
| while True:
n = int(eval(input()))
if n == 0:
break
to = []
for i in range(n):
line = list(map(int, input().split()))
for j in range(n):
x, y = line[2 * j : 2 * j + 2]
to.append(y * n + x)
order = []
used = [False] * (n * n)
def dfs(x):
if used[x]:
return
used[x] = True
dfs(to[x])
order.append(x)
for i in range(n * n):
dfs(i)
order.reverse()
def dfs2(x, used, group):
if x in group:
return True
if used[x]:
return False
group.add(x)
used[x] = True
return dfs2(to[x], used, group)
used = [False] * (n * n)
ans = 0
for i in order:
group = set()
if not used[i]:
if dfs2(i, used, group):
ans += 1
print(ans)
| false | 0 | [
"+ if x in group:",
"+ return True",
"- if x in group:",
"- return True",
"+ used[x] = True",
"- for g in group:",
"- used[g] = True"
] | false | 0.128509 | 0.090216 | 1.424459 | [
"s251580576",
"s732707688"
] |
u279439669 | p02571 | python | s741424092 | s625638301 | 51 | 47 | 9,132 | 9,092 | Accepted | Accepted | 7.84 | def core(s, t):
result = len(t)
for start in range(len(s) - len(t) + 1):
diff = 0
for i in range(len(t)):
if t[i] != s[start + i]:
diff += 1
result = min([diff, result])
return result
if __name__ == "__main__":
strings = [eval(input()) for i in range(2)]
print((core(strings[0], strings[1])))
| def subst(S, T)-> int:
lenT = len(T)
result = lenT
for i in range(len(S) - lenT + 1):
# tempS = S[i-lenT:i]
tempResult = 0
for j in range(lenT):
if T[j] != S[j + i]:
tempResult += 1
if tempResult < result:
result = tempResult
return result
if __name__ == "__main__":
S = eval(input())
T = eval(input())
print((subst(S, T))) | 13 | 18 | 336 | 382 | def core(s, t):
result = len(t)
for start in range(len(s) - len(t) + 1):
diff = 0
for i in range(len(t)):
if t[i] != s[start + i]:
diff += 1
result = min([diff, result])
return result
if __name__ == "__main__":
strings = [eval(input()) for i in range(2)]
print((core(strings[0], strings[1])))
| def subst(S, T) -> int:
lenT = len(T)
result = lenT
for i in range(len(S) - lenT + 1):
# tempS = S[i-lenT:i]
tempResult = 0
for j in range(lenT):
if T[j] != S[j + i]:
tempResult += 1
if tempResult < result:
result = tempResult
return result
if __name__ == "__main__":
S = eval(input())
T = eval(input())
print((subst(S, T)))
| false | 27.777778 | [
"-def core(s, t):",
"- result = len(t)",
"- for start in range(len(s) - len(t) + 1):",
"- diff = 0",
"- for i in range(len(t)):",
"- if t[i] != s[start + i]:",
"- diff += 1",
"- result = min([diff, result])",
"+def subst(S, T) -> int:",
"+ lenT = len(T)",
"+ result = lenT",
"+ for i in range(len(S) - lenT + 1):",
"+ # tempS = S[i-lenT:i]",
"+ tempResult = 0",
"+ for j in range(lenT):",
"+ if T[j] != S[j + i]:",
"+ tempResult += 1",
"+ if tempResult < result:",
"+ result = tempResult",
"- strings = [eval(input()) for i in range(2)]",
"- print((core(strings[0], strings[1])))",
"+ S = eval(input())",
"+ T = eval(input())",
"+ print((subst(S, T)))"
] | false | 0.038933 | 0.04522 | 0.860974 | [
"s741424092",
"s625638301"
] |
u904612569 | p03160 | python | s516567159 | s685963529 | 132 | 115 | 13,592 | 20,588 | Accepted | Accepted | 12.88 | from sys import stdin as I
from sys import stdout as O
N = int(I.readline())
H = [None] + list(map(int,I.readline().split()))
DP = [None for i in range(N+1)]
DP[1] = 0
DP[2] = abs(H[2]-H[1])
for i in range(3,N+1):DP[i] = min(DP[i-2]+abs(H[i]-H[i-2]),DP[i-1]+abs(H[i]-H[i-1]))
print((DP[N])) | N = int(eval(input()))
h = [*list(map(int, input().split()))]
dp = [0, abs(h[1] - h[0])] + [0] * (N - 2)
for i in range(2, N):
dp[i] = min(abs(h[i] - h[i-1]) + dp[i-1],abs(h[i] - h[i-2]) + dp[i-2])
print((dp[N-1])) | 9 | 6 | 296 | 206 | from sys import stdin as I
from sys import stdout as O
N = int(I.readline())
H = [None] + list(map(int, I.readline().split()))
DP = [None for i in range(N + 1)]
DP[1] = 0
DP[2] = abs(H[2] - H[1])
for i in range(3, N + 1):
DP[i] = min(DP[i - 2] + abs(H[i] - H[i - 2]), DP[i - 1] + abs(H[i] - H[i - 1]))
print((DP[N]))
| N = int(eval(input()))
h = [*list(map(int, input().split()))]
dp = [0, abs(h[1] - h[0])] + [0] * (N - 2)
for i in range(2, N):
dp[i] = min(abs(h[i] - h[i - 1]) + dp[i - 1], abs(h[i] - h[i - 2]) + dp[i - 2])
print((dp[N - 1]))
| false | 33.333333 | [
"-from sys import stdin as I",
"-from sys import stdout as O",
"-",
"-N = int(I.readline())",
"-H = [None] + list(map(int, I.readline().split()))",
"-DP = [None for i in range(N + 1)]",
"-DP[1] = 0",
"-DP[2] = abs(H[2] - H[1])",
"-for i in range(3, N + 1):",
"- DP[i] = min(DP[i - 2] + abs(H[i] - H[i - 2]), DP[i - 1] + abs(H[i] - H[i - 1]))",
"-print((DP[N]))",
"+N = int(eval(input()))",
"+h = [*list(map(int, input().split()))]",
"+dp = [0, abs(h[1] - h[0])] + [0] * (N - 2)",
"+for i in range(2, N):",
"+ dp[i] = min(abs(h[i] - h[i - 1]) + dp[i - 1], abs(h[i] - h[i - 2]) + dp[i - 2])",
"+print((dp[N - 1]))"
] | false | 0.130638 | 0.044387 | 2.94317 | [
"s516567159",
"s685963529"
] |
u813098295 | p02693 | python | s587852691 | s056148220 | 22 | 20 | 9,100 | 9,104 | Accepted | Accepted | 9.09 | K = int(eval(input()))
A, B = list(map(int, input().split()))
print(("OK" if A <= (B // K) * K else "NG")) | K = int(eval(input()))
A, B = list(map(int, input().split()))
print(("OK" if A // K != B // K or A % K == 0 else "NG")) | 4 | 4 | 96 | 109 | K = int(eval(input()))
A, B = list(map(int, input().split()))
print(("OK" if A <= (B // K) * K else "NG"))
| K = int(eval(input()))
A, B = list(map(int, input().split()))
print(("OK" if A // K != B // K or A % K == 0 else "NG"))
| false | 0 | [
"-print((\"OK\" if A <= (B // K) * K else \"NG\"))",
"+print((\"OK\" if A // K != B // K or A % K == 0 else \"NG\"))"
] | false | 0.035749 | 0.035141 | 1.017302 | [
"s587852691",
"s056148220"
] |
u777923818 | p03294 | python | s110691587 | s025796090 | 127 | 18 | 3,316 | 3,316 | Accepted | Accepted | 85.83 | eval(input())
A = list(map(int, input().split()))
ans = 0
x = 1
for a in A:
x *= a
for a in A:
ans += (x-1)%a
print(ans)
| def inpl(): return list(map(int, input().split()))
N = int(eval(input()))
A = inpl()
print((sum(A)-N)) | 13 | 4 | 139 | 97 | eval(input())
A = list(map(int, input().split()))
ans = 0
x = 1
for a in A:
x *= a
for a in A:
ans += (x - 1) % a
print(ans)
| def inpl():
return list(map(int, input().split()))
N = int(eval(input()))
A = inpl()
print((sum(A) - N))
| false | 69.230769 | [
"-eval(input())",
"-A = list(map(int, input().split()))",
"-ans = 0",
"-x = 1",
"-for a in A:",
"- x *= a",
"-for a in A:",
"- ans += (x - 1) % a",
"-print(ans)",
"+def inpl():",
"+ return list(map(int, input().split()))",
"+",
"+",
"+N = int(eval(input()))",
"+A = inpl()",
"+print((sum(A) - N))"
] | false | 0.036511 | 0.062294 | 0.586103 | [
"s110691587",
"s025796090"
] |
u925782032 | p02586 | python | s142890017 | s420770501 | 673 | 504 | 149,884 | 149,816 | Accepted | Accepted | 25.11 | import sys
from collections import defaultdict
range = xrange
input = raw_input
inp = [int(x) for x in sys.stdin.read().split()]; ii = 0
n = inp[ii]; ii += 1
m = inp[ii]; ii += 1
k = inp[ii]; ii += 1
R = inp[ii + 0: ii + 3 * k: 3]
C = inp[ii + 1: ii + 3 * k: 3]
V = inp[ii + 2: ii + 3 * k: 3]
items = [defaultdict(list) for _ in range(n)]
for i in range(k):
r = R[i] - 1
c = C[i] - 1
v = V[i]
items[r][c].append(v)
DP0 = [0] * m
DP1 = [0] * m
DP2 = [0] * m
DP3 = [0] * m
for r in range(n):
for c in range(m):
if c:
DP0[c] = max(DP0[c], DP0[c - 1])
DP1[c] = max(DP1[c], DP1[c - 1])
DP2[c] = max(DP2[c], DP2[c - 1])
DP3[c] = max(DP3[c], DP3[c - 1])
if c in items[r]:
for v in items[r][c]:
DP3[c] = max(DP3[c], DP2[c] + v)
DP2[c] = max(DP2[c], DP1[c] + v)
DP1[c] = max(DP1[c], DP0[c] + v)
for c in range(m):
DP0[c] = max(DP0[c], DP1[c], DP2[c], DP3[c])
print(DP0[-1])
| import sys
from collections import defaultdict
range = xrange
input = raw_input
inp = [int(x) for x in sys.stdin.read().split()]; ii = 0
n = inp[ii]; ii += 1
m = inp[ii]; ii += 1
k = inp[ii]; ii += 1
R = inp[ii + 0: ii + 3 * k: 3]
C = inp[ii + 1: ii + 3 * k: 3]
V = inp[ii + 2: ii + 3 * k: 3]
items = [defaultdict(list) for _ in range(n)]
for i in range(k):
r = R[i] - 1
c = C[i] - 1
v = V[i]
items[r][c].append(v)
DP0 = [0] * m
DP1 = [0] * m
DP2 = [0] * m
DP3 = [0] * m
for r in range(n):
itemsr = items[r]
for c in range(m):
if c:
DP0[c] = max(DP0[c], DP0[c - 1])
DP1[c] = max(DP1[c], DP1[c - 1])
DP2[c] = max(DP2[c], DP2[c - 1])
DP3[c] = max(DP3[c], DP3[c - 1])
if c in itemsr:
for v in itemsr[c]:
DP3[c] = max(DP3[c], DP2[c] + v)
DP2[c] = max(DP2[c], DP1[c] + v)
DP1[c] = max(DP1[c], DP0[c] + v)
for c in range(m):
DP0[c] = DP1[c] = DP2[c] = DP3[c]
print(DP0[-1])
| 42 | 43 | 1,068 | 1,076 | import sys
from collections import defaultdict
range = xrange
input = raw_input
inp = [int(x) for x in sys.stdin.read().split()]
ii = 0
n = inp[ii]
ii += 1
m = inp[ii]
ii += 1
k = inp[ii]
ii += 1
R = inp[ii + 0 : ii + 3 * k : 3]
C = inp[ii + 1 : ii + 3 * k : 3]
V = inp[ii + 2 : ii + 3 * k : 3]
items = [defaultdict(list) for _ in range(n)]
for i in range(k):
r = R[i] - 1
c = C[i] - 1
v = V[i]
items[r][c].append(v)
DP0 = [0] * m
DP1 = [0] * m
DP2 = [0] * m
DP3 = [0] * m
for r in range(n):
for c in range(m):
if c:
DP0[c] = max(DP0[c], DP0[c - 1])
DP1[c] = max(DP1[c], DP1[c - 1])
DP2[c] = max(DP2[c], DP2[c - 1])
DP3[c] = max(DP3[c], DP3[c - 1])
if c in items[r]:
for v in items[r][c]:
DP3[c] = max(DP3[c], DP2[c] + v)
DP2[c] = max(DP2[c], DP1[c] + v)
DP1[c] = max(DP1[c], DP0[c] + v)
for c in range(m):
DP0[c] = max(DP0[c], DP1[c], DP2[c], DP3[c])
print(DP0[-1])
| import sys
from collections import defaultdict
range = xrange
input = raw_input
inp = [int(x) for x in sys.stdin.read().split()]
ii = 0
n = inp[ii]
ii += 1
m = inp[ii]
ii += 1
k = inp[ii]
ii += 1
R = inp[ii + 0 : ii + 3 * k : 3]
C = inp[ii + 1 : ii + 3 * k : 3]
V = inp[ii + 2 : ii + 3 * k : 3]
items = [defaultdict(list) for _ in range(n)]
for i in range(k):
r = R[i] - 1
c = C[i] - 1
v = V[i]
items[r][c].append(v)
DP0 = [0] * m
DP1 = [0] * m
DP2 = [0] * m
DP3 = [0] * m
for r in range(n):
itemsr = items[r]
for c in range(m):
if c:
DP0[c] = max(DP0[c], DP0[c - 1])
DP1[c] = max(DP1[c], DP1[c - 1])
DP2[c] = max(DP2[c], DP2[c - 1])
DP3[c] = max(DP3[c], DP3[c - 1])
if c in itemsr:
for v in itemsr[c]:
DP3[c] = max(DP3[c], DP2[c] + v)
DP2[c] = max(DP2[c], DP1[c] + v)
DP1[c] = max(DP1[c], DP0[c] + v)
for c in range(m):
DP0[c] = DP1[c] = DP2[c] = DP3[c]
print(DP0[-1])
| false | 2.325581 | [
"+ itemsr = items[r]",
"- if c in items[r]:",
"- for v in items[r][c]:",
"+ if c in itemsr:",
"+ for v in itemsr[c]:",
"- DP0[c] = max(DP0[c], DP1[c], DP2[c], DP3[c])",
"+ DP0[c] = DP1[c] = DP2[c] = DP3[c]"
] | false | 0.047018 | 0.118631 | 0.396341 | [
"s142890017",
"s420770501"
] |
u795245552 | p02918 | python | s149127994 | s755955530 | 50 | 44 | 3,316 | 3,316 | Accepted | Accepted | 12 | N, K = [int(x) for x in input().split()]
S = str(eval(input()))
Unhappy = {}
Unhappy[1] = 0
Unhappy[2] = 0
for i in range(N):
if i == 0:
if S[i] == 'L':
Unhappy[1] += 1
if i == N - 1:
if S[i] == 'R':
Unhappy[1] += 1
else:
if S[i] == 'R' and S[i + 1] == 'L':
Unhappy[2] += 1
if Unhappy[1] == 0:
act = min(K, Unhappy[2] - 1)
K -= act
Unhappy[2] -= act
if K != 0:
K -= 1
Unhappy[2] -= 1
Unhappy[1] += 1
else:
act = min(K, Unhappy[2])
K -= act
Unhappy[2] -= act
if Unhappy[1] == 2 and K != 0:
K -= 1
Unhappy[1] -= 1
print((N - Unhappy[1] - Unhappy[2] * 2)) | N, K = [int(x) for x in input().split()]
S = str(eval(input()))
a=0
for i in range(N - 1):
if S[i]==S[i + 1]:
a += 1
b = min(N - 1, a + 2 * K)
print(b) | 35 | 9 | 726 | 157 | N, K = [int(x) for x in input().split()]
S = str(eval(input()))
Unhappy = {}
Unhappy[1] = 0
Unhappy[2] = 0
for i in range(N):
if i == 0:
if S[i] == "L":
Unhappy[1] += 1
if i == N - 1:
if S[i] == "R":
Unhappy[1] += 1
else:
if S[i] == "R" and S[i + 1] == "L":
Unhappy[2] += 1
if Unhappy[1] == 0:
act = min(K, Unhappy[2] - 1)
K -= act
Unhappy[2] -= act
if K != 0:
K -= 1
Unhappy[2] -= 1
Unhappy[1] += 1
else:
act = min(K, Unhappy[2])
K -= act
Unhappy[2] -= act
if Unhappy[1] == 2 and K != 0:
K -= 1
Unhappy[1] -= 1
print((N - Unhappy[1] - Unhappy[2] * 2))
| N, K = [int(x) for x in input().split()]
S = str(eval(input()))
a = 0
for i in range(N - 1):
if S[i] == S[i + 1]:
a += 1
b = min(N - 1, a + 2 * K)
print(b)
| false | 74.285714 | [
"-Unhappy = {}",
"-Unhappy[1] = 0",
"-Unhappy[2] = 0",
"-for i in range(N):",
"- if i == 0:",
"- if S[i] == \"L\":",
"- Unhappy[1] += 1",
"- if i == N - 1:",
"- if S[i] == \"R\":",
"- Unhappy[1] += 1",
"- else:",
"- if S[i] == \"R\" and S[i + 1] == \"L\":",
"- Unhappy[2] += 1",
"-if Unhappy[1] == 0:",
"- act = min(K, Unhappy[2] - 1)",
"- K -= act",
"- Unhappy[2] -= act",
"- if K != 0:",
"- K -= 1",
"- Unhappy[2] -= 1",
"- Unhappy[1] += 1",
"-else:",
"- act = min(K, Unhappy[2])",
"- K -= act",
"- Unhappy[2] -= act",
"- if Unhappy[1] == 2 and K != 0:",
"- K -= 1",
"- Unhappy[1] -= 1",
"-print((N - Unhappy[1] - Unhappy[2] * 2))",
"+a = 0",
"+for i in range(N - 1):",
"+ if S[i] == S[i + 1]:",
"+ a += 1",
"+b = min(N - 1, a + 2 * K)",
"+print(b)"
] | false | 0.043434 | 0.074935 | 0.579631 | [
"s149127994",
"s755955530"
] |
u654470292 | p03229 | python | s400063183 | s413012724 | 266 | 149 | 46,300 | 79,612 | Accepted | Accepted | 43.98 | import sys
def input():
return sys.stdin.readline()[:-1]
n=int(eval(input()))
a=[int(eval(input())) for i in range(n)]
a.sort()
if n==2:
print((a[1]-a[0]))
quit()
ans=0
for i in range((n-1)//2):
ans-=a[i]
for i in range((n-2)//2):
ans+=a[n-1-i]
ans*=2
if n%2!=0:
ans+=a[n//2]+a[n//2+1]
else:
ans+=a[n//2]-a[n//2-1]
ans2=0
for i in range((n-1)//2):
ans2+=a[n-1-i]
for i in range((n-2)//2):
ans2-=a[i]
ans2*=2
if n%2!=0:
ans2-=a[n//2]+a[n//2-1]
else:
ans2+=a[n//2]-a[n//2+1]
# print(ans)
# print(ans2)
print((max(ans,ans2))) | import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
return sys.stdin.readline()[:-1]
def ruiseki(lst):
return [0]+list(accumulate(lst))
sys.setrecursionlimit(500000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]
n=int(eval(input()))
a=[int(eval(input())) for i in range(n)]
a.sort()
ans1=0
if n%2==0:
for i in range(n):
if i<n//2:
ans1-=a[i]*2
else:
ans1+=a[i]*2
ans1-=a[n//2]
ans1+=a[n//2-1]
print(ans1)
else:
for i in range(n):
if i<n//2:
ans1-=a[i]*2
elif i>n//2:
ans1+=a[i]*2
print((max(ans1+a[n//2]-a[n//2+1],ans1-a[n//2]+a[n//2-1]))) | 36 | 39 | 589 | 879 | import sys
def input():
return sys.stdin.readline()[:-1]
n = int(eval(input()))
a = [int(eval(input())) for i in range(n)]
a.sort()
if n == 2:
print((a[1] - a[0]))
quit()
ans = 0
for i in range((n - 1) // 2):
ans -= a[i]
for i in range((n - 2) // 2):
ans += a[n - 1 - i]
ans *= 2
if n % 2 != 0:
ans += a[n // 2] + a[n // 2 + 1]
else:
ans += a[n // 2] - a[n // 2 - 1]
ans2 = 0
for i in range((n - 1) // 2):
ans2 += a[n - 1 - i]
for i in range((n - 2) // 2):
ans2 -= a[i]
ans2 *= 2
if n % 2 != 0:
ans2 -= a[n // 2] + a[n // 2 - 1]
else:
ans2 += a[n // 2] - a[n // 2 + 1]
# print(ans)
# print(ans2)
print((max(ans, ans2)))
| import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
return sys.stdin.readline()[:-1]
def ruiseki(lst):
return [0] + list(accumulate(lst))
sys.setrecursionlimit(500000)
mod = pow(10, 9) + 7
al = [chr(ord("a") + i) for i in range(26)]
direction = [[1, 0], [0, 1], [-1, 0], [0, -1]]
n = int(eval(input()))
a = [int(eval(input())) for i in range(n)]
a.sort()
ans1 = 0
if n % 2 == 0:
for i in range(n):
if i < n // 2:
ans1 -= a[i] * 2
else:
ans1 += a[i] * 2
ans1 -= a[n // 2]
ans1 += a[n // 2 - 1]
print(ans1)
else:
for i in range(n):
if i < n // 2:
ans1 -= a[i] * 2
elif i > n // 2:
ans1 += a[i] * 2
print((max(ans1 + a[n // 2] - a[n // 2 + 1], ans1 - a[n // 2] + a[n // 2 - 1])))
| false | 7.692308 | [
"+import bisect",
"+import copy",
"+import heapq",
"+import math",
"+from collections import *",
"+from functools import lru_cache",
"+from itertools import accumulate, combinations, permutations, product",
"+def ruiseki(lst):",
"+ return [0] + list(accumulate(lst))",
"+",
"+",
"+sys.setrecursionlimit(500000)",
"+mod = pow(10, 9) + 7",
"+al = [chr(ord(\"a\") + i) for i in range(26)]",
"+direction = [[1, 0], [0, 1], [-1, 0], [0, -1]]",
"-if n == 2:",
"- print((a[1] - a[0]))",
"- quit()",
"-ans = 0",
"-for i in range((n - 1) // 2):",
"- ans -= a[i]",
"-for i in range((n - 2) // 2):",
"- ans += a[n - 1 - i]",
"-ans *= 2",
"-if n % 2 != 0:",
"- ans += a[n // 2] + a[n // 2 + 1]",
"+ans1 = 0",
"+if n % 2 == 0:",
"+ for i in range(n):",
"+ if i < n // 2:",
"+ ans1 -= a[i] * 2",
"+ else:",
"+ ans1 += a[i] * 2",
"+ ans1 -= a[n // 2]",
"+ ans1 += a[n // 2 - 1]",
"+ print(ans1)",
"- ans += a[n // 2] - a[n // 2 - 1]",
"-ans2 = 0",
"-for i in range((n - 1) // 2):",
"- ans2 += a[n - 1 - i]",
"-for i in range((n - 2) // 2):",
"- ans2 -= a[i]",
"-ans2 *= 2",
"-if n % 2 != 0:",
"- ans2 -= a[n // 2] + a[n // 2 - 1]",
"-else:",
"- ans2 += a[n // 2] - a[n // 2 + 1]",
"-# print(ans)",
"-# print(ans2)",
"-print((max(ans, ans2)))",
"+ for i in range(n):",
"+ if i < n // 2:",
"+ ans1 -= a[i] * 2",
"+ elif i > n // 2:",
"+ ans1 += a[i] * 2",
"+ print((max(ans1 + a[n // 2] - a[n // 2 + 1], ans1 - a[n // 2] + a[n // 2 - 1])))"
] | false | 0.036096 | 0.035617 | 1.013431 | [
"s400063183",
"s413012724"
] |
u020390084 | p03487 | python | s908044962 | s980599469 | 110 | 80 | 27,820 | 24,244 | Accepted | Accepted | 27.27 | #!/usr/bin/env python3
import sys
import collections
def solve(N: int, a: "List[int]"):
counter = collections.Counter(a)
aset = set(a)
answer = 0
for aa in aset:
answer += (counter[aa]-aa) if counter[aa]>=aa else counter[aa]
print(answer)
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
a = [int(next(tokens)) for _ in range(N)] # type: "List[int]"
solve(N, a)
if __name__ == '__main__':
main()
| #!/usr/bin/env python3
import sys
from collections import Counter
def solve(N: int, a: "List[int]"):
counter = Counter(a)
answer = 0
for key,value in list(counter.items()):
if key >value:
answer += value
else:
answer += value-key
print(answer)
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
a = [int(next(tokens)) for _ in range(N)] # type: "List[int]"
solve(N, a)
if __name__ == '__main__':
main()
| 25 | 27 | 629 | 658 | #!/usr/bin/env python3
import sys
import collections
def solve(N: int, a: "List[int]"):
counter = collections.Counter(a)
aset = set(a)
answer = 0
for aa in aset:
answer += (counter[aa] - aa) if counter[aa] >= aa else counter[aa]
print(answer)
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
a = [int(next(tokens)) for _ in range(N)] # type: "List[int]"
solve(N, a)
if __name__ == "__main__":
main()
| #!/usr/bin/env python3
import sys
from collections import Counter
def solve(N: int, a: "List[int]"):
counter = Counter(a)
answer = 0
for key, value in list(counter.items()):
if key > value:
answer += value
else:
answer += value - key
print(answer)
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
a = [int(next(tokens)) for _ in range(N)] # type: "List[int]"
solve(N, a)
if __name__ == "__main__":
main()
| false | 7.407407 | [
"-import collections",
"+from collections import Counter",
"- counter = collections.Counter(a)",
"- aset = set(a)",
"+ counter = Counter(a)",
"- for aa in aset:",
"- answer += (counter[aa] - aa) if counter[aa] >= aa else counter[aa]",
"+ for key, value in list(counter.items()):",
"+ if key > value:",
"+ answer += value",
"+ else:",
"+ answer += value - key"
] | false | 0.040045 | 0.039361 | 1.017382 | [
"s908044962",
"s980599469"
] |
u935329231 | p02393 | python | s766778012 | s104284959 | 20 | 10 | 4,188 | 6,344 | Accepted | Accepted | 50 | #! /usr/bin/env python
# coding: utf-8
list = sorted(map(int, input().split()))
for i in list:
print(i, end=' ') | #! /usr/bin/env python
# -*- coding: utf-8 -*-
raw_list = sorted(map(int, input().split()))
print(("%d %d %d") % (raw_list[0], raw_list[1], raw_list[2])) | 6 | 5 | 117 | 160 | #! /usr/bin/env python
# coding: utf-8
list = sorted(map(int, input().split()))
for i in list:
print(i, end=" ")
| #! /usr/bin/env python
# -*- coding: utf-8 -*-
raw_list = sorted(map(int, input().split()))
print(("%d %d %d") % (raw_list[0], raw_list[1], raw_list[2]))
| false | 16.666667 | [
"-# coding: utf-8",
"-list = sorted(map(int, input().split()))",
"-for i in list:",
"- print(i, end=\" \")",
"+# -*- coding: utf-8 -*-",
"+raw_list = sorted(map(int, input().split()))",
"+print((\"%d %d %d\") % (raw_list[0], raw_list[1], raw_list[2]))"
] | false | 0.038445 | 0.036634 | 1.049437 | [
"s766778012",
"s104284959"
] |
u588341295 | p02727 | python | s038994498 | s732641368 | 510 | 442 | 98,336 | 96,424 | Accepted | Accepted | 13.33 | # -*- coding: utf-8 -*-
import sys
from heapq import heapify, heappop, heappush
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7
X, Y, N, M, L = MAP()
A = LIST()
B = LIST()
C = LIST()
A.sort(reverse=1)
B.sort(reverse=1)
C.sort(reverse=1)
que = []
que += A[:X]
que += B[:Y]
heapify(que)
for c in C:
mn = heappop(que)
if c > mn:
heappush(que, c)
else:
heappush(que, mn)
ans = sum(que)
print(ans)
| # -*- coding: utf-8 -*-
import sys
from heapq import heapify, heappop, heappush
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7
X, Y, N, M, L = MAP()
A = LIST()
B = LIST()
C = LIST()
A.sort(reverse=1)
B.sort(reverse=1)
que = []
que += A[:X]
que += B[:Y]
heapify(que)
for c in C:
if c > que[0]:
heappop(que)
heappush(que, c)
ans = sum(que)
print(ans)
| 43 | 40 | 1,060 | 1,006 | # -*- coding: utf-8 -*-
import sys
from heapq import heapify, heappop, heappush
def input():
return sys.stdin.readline().strip()
def list2d(a, b, c):
return [[c] * b for i in range(a)]
def list3d(a, b, c, d):
return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e):
return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1):
return int(-(-x // y))
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST(N=None):
return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes():
print("Yes")
def No():
print("No")
def YES():
print("YES")
def NO():
print("NO")
sys.setrecursionlimit(10**9)
INF = 10**18
MOD = 10**9 + 7
X, Y, N, M, L = MAP()
A = LIST()
B = LIST()
C = LIST()
A.sort(reverse=1)
B.sort(reverse=1)
C.sort(reverse=1)
que = []
que += A[:X]
que += B[:Y]
heapify(que)
for c in C:
mn = heappop(que)
if c > mn:
heappush(que, c)
else:
heappush(que, mn)
ans = sum(que)
print(ans)
| # -*- coding: utf-8 -*-
import sys
from heapq import heapify, heappop, heappush
def input():
return sys.stdin.readline().strip()
def list2d(a, b, c):
return [[c] * b for i in range(a)]
def list3d(a, b, c, d):
return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e):
return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1):
return int(-(-x // y))
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST(N=None):
return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes():
print("Yes")
def No():
print("No")
def YES():
print("YES")
def NO():
print("NO")
sys.setrecursionlimit(10**9)
INF = 10**18
MOD = 10**9 + 7
X, Y, N, M, L = MAP()
A = LIST()
B = LIST()
C = LIST()
A.sort(reverse=1)
B.sort(reverse=1)
que = []
que += A[:X]
que += B[:Y]
heapify(que)
for c in C:
if c > que[0]:
heappop(que)
heappush(que, c)
ans = sum(que)
print(ans)
| false | 6.976744 | [
"-C.sort(reverse=1)",
"- mn = heappop(que)",
"- if c > mn:",
"+ if c > que[0]:",
"+ heappop(que)",
"- else:",
"- heappush(que, mn)"
] | false | 0.047506 | 0.148135 | 0.320694 | [
"s038994498",
"s732641368"
] |
u888337853 | p03241 | python | s885655320 | s569974822 | 44 | 40 | 5,564 | 5,092 | Accepted | Accepted | 9.09 | import sys
# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue
sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7
ni = lambda: int(sys.stdin.readline())
ns = lambda: list(map(int, sys.stdin.readline().split()))
na = lambda: list(map(int, sys.stdin.readline().split()))
# ===CODE===
def main():
def make_divisors(n):
divisors = []
for i in range(1, int(n ** 0.5) + 1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n // i)
divisors.sort(reverse=True)
return divisors
n, m = ns()
gcd = make_divisors(m)
max_gcd = 1
for d in gcd:
if m // d >= n:
max_gcd = d
break
print(d)
if __name__ == '__main__':
main()
| import sys
# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue
sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7
ni = lambda: int(sys.stdin.readline())
ns = lambda: list(map(int, sys.stdin.readline().split()))
na = lambda: list(map(int, sys.stdin.readline().split()))
# ===CODE===
def main():
def make_divisors(n):
divisors = []
for i in range(1, int(n ** 0.5) + 1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n // i)
# divisors.sort(reverse=True)
return divisors
n, m = ns()
gcd = make_divisors(m)
max_gcd = 1
for d in gcd:
if m // d >= n:
max_gcd = max(max_gcd, d)
print(max_gcd)
if __name__ == '__main__':
main()
| 54 | 53 | 1,002 | 1,005 | import sys
# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue
sys.setrecursionlimit(10000001)
INF = 10**16
MOD = 10**9 + 7
ni = lambda: int(sys.stdin.readline())
ns = lambda: list(map(int, sys.stdin.readline().split()))
na = lambda: list(map(int, sys.stdin.readline().split()))
# ===CODE===
def main():
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5) + 1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n // i)
divisors.sort(reverse=True)
return divisors
n, m = ns()
gcd = make_divisors(m)
max_gcd = 1
for d in gcd:
if m // d >= n:
max_gcd = d
break
print(d)
if __name__ == "__main__":
main()
| import sys
# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue
sys.setrecursionlimit(10000001)
INF = 10**16
MOD = 10**9 + 7
ni = lambda: int(sys.stdin.readline())
ns = lambda: list(map(int, sys.stdin.readline().split()))
na = lambda: list(map(int, sys.stdin.readline().split()))
# ===CODE===
def main():
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5) + 1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n // i)
# divisors.sort(reverse=True)
return divisors
n, m = ns()
gcd = make_divisors(m)
max_gcd = 1
for d in gcd:
if m // d >= n:
max_gcd = max(max_gcd, d)
print(max_gcd)
if __name__ == "__main__":
main()
| false | 1.851852 | [
"- divisors.sort(reverse=True)",
"+ # divisors.sort(reverse=True)",
"- max_gcd = d",
"- break",
"- print(d)",
"+ max_gcd = max(max_gcd, d)",
"+ print(max_gcd)"
] | false | 0.113077 | 0.00751 | 15.057915 | [
"s885655320",
"s569974822"
] |
u721425712 | p03478 | python | s720164435 | s162086136 | 49 | 31 | 3,404 | 3,060 | Accepted | Accepted | 36.73 | N, A, B = list(map(int, input().split()))
ans = []
def degitsum(x):
string = str(x)
array = list(map(int, string))
return sum(array)
for i in range(N+1):
if A <= degitsum(i) and degitsum(i) <= B:
ans.append(i)
else:
continue
print((sum(ans))) | def degitsum(n):
ans = 0
while n/10 != 0:
ans += n%10
n = int(n/10)
return ans
n, a, b = list(map(int, input().split()))
ans = 0
for i in range(1, n+1):
if a <= degitsum(i) <= b:
ans += i
else:
continue
print(ans) | 15 | 17 | 262 | 286 | N, A, B = list(map(int, input().split()))
ans = []
def degitsum(x):
string = str(x)
array = list(map(int, string))
return sum(array)
for i in range(N + 1):
if A <= degitsum(i) and degitsum(i) <= B:
ans.append(i)
else:
continue
print((sum(ans)))
| def degitsum(n):
ans = 0
while n / 10 != 0:
ans += n % 10
n = int(n / 10)
return ans
n, a, b = list(map(int, input().split()))
ans = 0
for i in range(1, n + 1):
if a <= degitsum(i) <= b:
ans += i
else:
continue
print(ans)
| false | 11.764706 | [
"-N, A, B = list(map(int, input().split()))",
"-ans = []",
"+def degitsum(n):",
"+ ans = 0",
"+ while n / 10 != 0:",
"+ ans += n % 10",
"+ n = int(n / 10)",
"+ return ans",
"-def degitsum(x):",
"- string = str(x)",
"- array = list(map(int, string))",
"- return sum(array)",
"-",
"-",
"-for i in range(N + 1):",
"- if A <= degitsum(i) and degitsum(i) <= B:",
"- ans.append(i)",
"+n, a, b = list(map(int, input().split()))",
"+ans = 0",
"+for i in range(1, n + 1):",
"+ if a <= degitsum(i) <= b:",
"+ ans += i",
"-print((sum(ans)))",
"+print(ans)"
] | false | 0.037684 | 0.046324 | 0.813495 | [
"s720164435",
"s162086136"
] |
u678167152 | p03208 | python | s199346235 | s725224552 | 254 | 189 | 7,472 | 13,084 | Accepted | Accepted | 25.59 | N, K = list(map(int, input().split()))
H = [0]*N
for i in range(N):
H[i] = int(eval(input()))
H.sort()
m = H[-1]-H[0]
for i in range(N-K+1):
m = min(m,H[i+K-1]-H[i])
print(m) | def solve():
N, K = list(map(int, input().split()))
H = [int(eval(input())) for _ in range(N)]
H.sort()
ans = float('inf')
for i in range(N):
if i+K>N:
break
ans = min(H[i+K-1]-H[i],ans)
return ans
print((solve())) | 10 | 11 | 176 | 236 | N, K = list(map(int, input().split()))
H = [0] * N
for i in range(N):
H[i] = int(eval(input()))
H.sort()
m = H[-1] - H[0]
for i in range(N - K + 1):
m = min(m, H[i + K - 1] - H[i])
print(m)
| def solve():
N, K = list(map(int, input().split()))
H = [int(eval(input())) for _ in range(N)]
H.sort()
ans = float("inf")
for i in range(N):
if i + K > N:
break
ans = min(H[i + K - 1] - H[i], ans)
return ans
print((solve()))
| false | 9.090909 | [
"-N, K = list(map(int, input().split()))",
"-H = [0] * N",
"-for i in range(N):",
"- H[i] = int(eval(input()))",
"-H.sort()",
"-m = H[-1] - H[0]",
"-for i in range(N - K + 1):",
"- m = min(m, H[i + K - 1] - H[i])",
"-print(m)",
"+def solve():",
"+ N, K = list(map(int, input().split()))",
"+ H = [int(eval(input())) for _ in range(N)]",
"+ H.sort()",
"+ ans = float(\"inf\")",
"+ for i in range(N):",
"+ if i + K > N:",
"+ break",
"+ ans = min(H[i + K - 1] - H[i], ans)",
"+ return ans",
"+",
"+",
"+print((solve()))"
] | false | 0.072985 | 0.042076 | 1.734608 | [
"s199346235",
"s725224552"
] |
u941047297 | p03380 | python | s310759234 | s239661668 | 145 | 101 | 21,604 | 23,816 | Accepted | Accepted | 30.34 | def main():
n = int(eval(input()))
A = list(map(int, input().split()))
A.sort()
m = A.pop()
B = [[a, abs(a - (m / 2))] for a in A]
B.sort(key = lambda x: x[1])
print(('{} {}'. format(m, B[0][0])))
if __name__ == '__main__':
main()
| def main():
n = int(eval(input()))
A = list(map(int, input().split()))
A.sort()
ans = [str((m := A.pop())), ]
m /= 2
A = [(a, abs(a - m)) for a in A]
A.sort(key = lambda x: x[1])
ans.append(str(A[0][0]))
print((' '.join(ans)))
if __name__ == '__main__':
main()
| 11 | 13 | 266 | 306 | def main():
n = int(eval(input()))
A = list(map(int, input().split()))
A.sort()
m = A.pop()
B = [[a, abs(a - (m / 2))] for a in A]
B.sort(key=lambda x: x[1])
print(("{} {}".format(m, B[0][0])))
if __name__ == "__main__":
main()
| def main():
n = int(eval(input()))
A = list(map(int, input().split()))
A.sort()
ans = [
str((m := A.pop())),
]
m /= 2
A = [(a, abs(a - m)) for a in A]
A.sort(key=lambda x: x[1])
ans.append(str(A[0][0]))
print((" ".join(ans)))
if __name__ == "__main__":
main()
| false | 15.384615 | [
"- m = A.pop()",
"- B = [[a, abs(a - (m / 2))] for a in A]",
"- B.sort(key=lambda x: x[1])",
"- print((\"{} {}\".format(m, B[0][0])))",
"+ ans = [",
"+ str((m := A.pop())),",
"+ ]",
"+ m /= 2",
"+ A = [(a, abs(a - m)) for a in A]",
"+ A.sort(key=lambda x: x[1])",
"+ ans.append(str(A[0][0]))",
"+ print((\" \".join(ans)))"
] | false | 0.041649 | 0.043411 | 0.959423 | [
"s310759234",
"s239661668"
] |
u230621983 | p03048 | python | s103545192 | s526030601 | 1,550 | 1,337 | 2,940 | 2,940 | Accepted | Accepted | 13.74 | R, G, B, N = list(map(int, input().split()))
cnt = 0
for r in range(N//R+1):
Rr = R*r
for g in range((N-Rr)//G+1):
if (N-(R*r + G*g)) % B == 0:
cnt += 1
print(cnt) | R, G, B, N = list(map(int, input().split()))
cnt = 0
for r in range(N//R+1):
Rr = R*r
for g in range((N-Rr)//G+1):
if (N-(Rr + G*g)) % B == 0:
cnt += 1
print(cnt) | 9 | 9 | 194 | 193 | R, G, B, N = list(map(int, input().split()))
cnt = 0
for r in range(N // R + 1):
Rr = R * r
for g in range((N - Rr) // G + 1):
if (N - (R * r + G * g)) % B == 0:
cnt += 1
print(cnt)
| R, G, B, N = list(map(int, input().split()))
cnt = 0
for r in range(N // R + 1):
Rr = R * r
for g in range((N - Rr) // G + 1):
if (N - (Rr + G * g)) % B == 0:
cnt += 1
print(cnt)
| false | 0 | [
"- if (N - (R * r + G * g)) % B == 0:",
"+ if (N - (Rr + G * g)) % B == 0:"
] | false | 0.07768 | 0.181852 | 0.427158 | [
"s103545192",
"s526030601"
] |
u828706986 | p03450 | python | s596462403 | s171739739 | 586 | 536 | 55,268 | 70,064 | Accepted | Accepted | 8.53 | import sys
def main():
n, m = list(map(int, sys.stdin.readline().split()))
g = [[] for i in range(n)]
deg = [0] * n
lines = sys.stdin.read().splitlines()
for line in lines:
l, r, d = list(map(int, line.split()))
g[l - 1].append((r - 1, d))
deg[r - 1] += 1
dis = [-1] * n
for i in range(n):
if deg[i]:
continue
stack = list([i])
dis[i] = 0
while len(stack):
v = stack[-1]
stack.pop()
for u, d in g[v]:
if dis[u] == -1:
dis[u] = dis[v] + d
stack.append(u)
for v in range(n):
for u, d in g[v]:
if dis[v] + d != dis[u]:
print('No')
return
print('Yes')
if __name__ == '__main__':
main()
| import sys
def main():
n, m = list(map(int, sys.stdin.readline().split()))
g = [[] for i in range(n)]
deg = [0] * n
for i in range(m):
l, r, d = list(map(int, sys.stdin.readline().split()))
g[l - 1].append((r - 1, d))
deg[r - 1] += 1
dis = [-1] * n
for i in range(n):
if deg[i]:
continue
stack = list([i])
dis[i] = 0
while len(stack):
v = stack[-1]
stack.pop()
for u, d in g[v]:
if dis[u] == -1:
dis[u] = dis[v] + d
stack.append(u)
for v in range(n):
for u, d in g[v]:
if dis[v] + d != dis[u]:
print('No')
return
print('Yes')
if __name__ == '__main__':
main()
| 35 | 34 | 860 | 833 | import sys
def main():
n, m = list(map(int, sys.stdin.readline().split()))
g = [[] for i in range(n)]
deg = [0] * n
lines = sys.stdin.read().splitlines()
for line in lines:
l, r, d = list(map(int, line.split()))
g[l - 1].append((r - 1, d))
deg[r - 1] += 1
dis = [-1] * n
for i in range(n):
if deg[i]:
continue
stack = list([i])
dis[i] = 0
while len(stack):
v = stack[-1]
stack.pop()
for u, d in g[v]:
if dis[u] == -1:
dis[u] = dis[v] + d
stack.append(u)
for v in range(n):
for u, d in g[v]:
if dis[v] + d != dis[u]:
print("No")
return
print("Yes")
if __name__ == "__main__":
main()
| import sys
def main():
n, m = list(map(int, sys.stdin.readline().split()))
g = [[] for i in range(n)]
deg = [0] * n
for i in range(m):
l, r, d = list(map(int, sys.stdin.readline().split()))
g[l - 1].append((r - 1, d))
deg[r - 1] += 1
dis = [-1] * n
for i in range(n):
if deg[i]:
continue
stack = list([i])
dis[i] = 0
while len(stack):
v = stack[-1]
stack.pop()
for u, d in g[v]:
if dis[u] == -1:
dis[u] = dis[v] + d
stack.append(u)
for v in range(n):
for u, d in g[v]:
if dis[v] + d != dis[u]:
print("No")
return
print("Yes")
if __name__ == "__main__":
main()
| false | 2.857143 | [
"- lines = sys.stdin.read().splitlines()",
"- for line in lines:",
"- l, r, d = list(map(int, line.split()))",
"+ for i in range(m):",
"+ l, r, d = list(map(int, sys.stdin.readline().split()))"
] | false | 0.09393 | 0.068567 | 1.369888 | [
"s596462403",
"s171739739"
] |
u645250356 | p02719 | python | s550680502 | s448306329 | 315 | 38 | 66,156 | 10,212 | Accepted | Accepted | 87.94 | from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
from bisect import bisect_left
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
n,k = inpl()
print((min(n%k, k-(n%k)))) | from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right
import sys,math,itertools,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
n,k = inpl()
print((min(n%k, k-n%k))) | 12 | 12 | 387 | 383 | from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heapify
from bisect import bisect_left
import sys, math, itertools, fractions, pprint
sys.setrecursionlimit(10**8)
mod = 10**9 + 7
INF = float("inf")
def inp():
return int(sys.stdin.readline())
def inpl():
return list(map(int, sys.stdin.readline().split()))
n, k = inpl()
print((min(n % k, k - (n % k))))
| from collections import Counter, defaultdict, deque
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right
import sys, math, itertools, fractions
sys.setrecursionlimit(10**8)
mod = 10**9 + 7
INF = float("inf")
def inp():
return int(sys.stdin.readline())
def inpl():
return list(map(int, sys.stdin.readline().split()))
n, k = inpl()
print((min(n % k, k - n % k)))
| false | 0 | [
"-from heapq import heappop, heappush, heapify",
"-from bisect import bisect_left",
"-import sys, math, itertools, fractions, pprint",
"+from heapq import heappop, heappush",
"+from bisect import bisect_left, bisect_right",
"+import sys, math, itertools, fractions",
"-print((min(n % k, k - (n % k))))",
"+print((min(n % k, k - n % k)))"
] | false | 0.037359 | 0.043263 | 0.863522 | [
"s550680502",
"s448306329"
] |
u902973687 | p03164 | python | s000627023 | s332641934 | 1,563 | 716 | 171,720 | 171,372 | Accepted | Accepted | 54.19 | MAX_V = 100100
MAX_N = 101
INF = pow(2, 64)
N, W = list(map(int, input().split()))
w = [0 for _ in range(N)]
v = [0 for _ in range(N)]
for i in range(N):
w[i], v[i] = list(map(int, input().split()))
dp = [[INF for _ in range(MAX_V)] for _ in range(N + 1)]
dp[0][0] = 0
for i in range(N):
for sum_v in range(MAX_V):
# print(i, sum_v, sum_v - v[i] >= 0)
if sum_v - v[i] >= 0:
dp[i+1][sum_v] = min(dp[i+1][sum_v], dp[i][sum_v - v[i]] + w[i])
dp[i+1][sum_v] = min(dp[i+1][sum_v], dp[i][sum_v])
# print(dp[i + 1][sum_v])
ans = max([i for i in range(len(dp[N])) if dp[N][i] <= W])
# for l in dp:
# print([n for n in l if not n == INF])
print(ans)
| MAX_V = 100100
MAX_N = 101
INF = pow(2, 60)
N, W = list(map(int, input().split()))
w = [0 for _ in range(N)]
v = [0 for _ in range(N)]
for i in range(N):
w[i], v[i] = list(map(int, input().split()))
dp = [[INF for _ in range(MAX_V)] for _ in range(N + 1)]
dp[0][0] = 0
for i in range(N):
for sum_v in range(MAX_V):
# print(i, sum_v, sum_v - v[i] >= 0)
if sum_v - v[i] >= 0:
dp[i+1][sum_v] = min(dp[i+1][sum_v], dp[i][sum_v - v[i]] + w[i])
dp[i+1][sum_v] = min(dp[i+1][sum_v], dp[i][sum_v])
# print(dp[i + 1][sum_v])
ans = max([i for i in range(len(dp[N])) if dp[N][i] <= W])
# for l in dp:
# print([n for n in l if not n == INF])
print(ans)
| 25 | 25 | 713 | 713 | MAX_V = 100100
MAX_N = 101
INF = pow(2, 64)
N, W = list(map(int, input().split()))
w = [0 for _ in range(N)]
v = [0 for _ in range(N)]
for i in range(N):
w[i], v[i] = list(map(int, input().split()))
dp = [[INF for _ in range(MAX_V)] for _ in range(N + 1)]
dp[0][0] = 0
for i in range(N):
for sum_v in range(MAX_V):
# print(i, sum_v, sum_v - v[i] >= 0)
if sum_v - v[i] >= 0:
dp[i + 1][sum_v] = min(dp[i + 1][sum_v], dp[i][sum_v - v[i]] + w[i])
dp[i + 1][sum_v] = min(dp[i + 1][sum_v], dp[i][sum_v])
# print(dp[i + 1][sum_v])
ans = max([i for i in range(len(dp[N])) if dp[N][i] <= W])
# for l in dp:
# print([n for n in l if not n == INF])
print(ans)
| MAX_V = 100100
MAX_N = 101
INF = pow(2, 60)
N, W = list(map(int, input().split()))
w = [0 for _ in range(N)]
v = [0 for _ in range(N)]
for i in range(N):
w[i], v[i] = list(map(int, input().split()))
dp = [[INF for _ in range(MAX_V)] for _ in range(N + 1)]
dp[0][0] = 0
for i in range(N):
for sum_v in range(MAX_V):
# print(i, sum_v, sum_v - v[i] >= 0)
if sum_v - v[i] >= 0:
dp[i + 1][sum_v] = min(dp[i + 1][sum_v], dp[i][sum_v - v[i]] + w[i])
dp[i + 1][sum_v] = min(dp[i + 1][sum_v], dp[i][sum_v])
# print(dp[i + 1][sum_v])
ans = max([i for i in range(len(dp[N])) if dp[N][i] <= W])
# for l in dp:
# print([n for n in l if not n == INF])
print(ans)
| false | 0 | [
"-INF = pow(2, 64)",
"+INF = pow(2, 60)"
] | false | 1.164428 | 1.017117 | 1.144832 | [
"s000627023",
"s332641934"
] |
u079022693 | p03208 | python | s177816847 | s850627184 | 229 | 120 | 7,384 | 7,468 | Accepted | Accepted | 47.6 | def main():
N,K=list(map(int,input().split()))
h=[]
for i in range(N):
a=int(eval(input()))
h.append(a)
h.sort()
result=10**10
count=0
for i in range(N-K+1):
count=h[i+K-1]-h[i]
result=min(result,count)
print(result)
if __name__=="__main__":
main() | from sys import stdin
def main():
#入力
readline=stdin.readline
n,k=list(map(int,readline().split()))
h=[0]*n
for i in range(n):
h[i]=int(readline())
h.sort()
ans=float("inf")
for i in range(k-1,n):
s=h[i]-h[i-k+1]
ans=min(s,ans)
print(ans)
if __name__=="__main__":
main() | 16 | 19 | 324 | 353 | def main():
N, K = list(map(int, input().split()))
h = []
for i in range(N):
a = int(eval(input()))
h.append(a)
h.sort()
result = 10**10
count = 0
for i in range(N - K + 1):
count = h[i + K - 1] - h[i]
result = min(result, count)
print(result)
if __name__ == "__main__":
main()
| from sys import stdin
def main():
# 入力
readline = stdin.readline
n, k = list(map(int, readline().split()))
h = [0] * n
for i in range(n):
h[i] = int(readline())
h.sort()
ans = float("inf")
for i in range(k - 1, n):
s = h[i] - h[i - k + 1]
ans = min(s, ans)
print(ans)
if __name__ == "__main__":
main()
| false | 15.789474 | [
"+from sys import stdin",
"+",
"+",
"- N, K = list(map(int, input().split()))",
"- h = []",
"- for i in range(N):",
"- a = int(eval(input()))",
"- h.append(a)",
"+ # 入力",
"+ readline = stdin.readline",
"+ n, k = list(map(int, readline().split()))",
"+ h = [0] * n",
"+ for i in range(n):",
"+ h[i] = int(readline())",
"- result = 10**10",
"- count = 0",
"- for i in range(N - K + 1):",
"- count = h[i + K - 1] - h[i]",
"- result = min(result, count)",
"- print(result)",
"+ ans = float(\"inf\")",
"+ for i in range(k - 1, n):",
"+ s = h[i] - h[i - k + 1]",
"+ ans = min(s, ans)",
"+ print(ans)"
] | false | 0.040675 | 0.037066 | 1.097358 | [
"s177816847",
"s850627184"
] |
u585482323 | p02763 | python | s689695838 | s281407456 | 1,122 | 766 | 285,084 | 101,876 | Accepted | Accepted | 31.73 | #!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007
import operator
class SegmentTree:
def __init__(self, size, default, op = operator.add):
self.size = 2**size.bit_length()
self.dat = [default]*(self.size*2)
self.op = op
def update(self, i, x):
i += self.size
self.dat[i] = x
while i > 0:
i >>= 1
self.dat[i] = self.op(self.dat[i*2], self.dat[i*2+1])
def add(self, i, x):
i += self.size
self.dat[i] = self.op(self.dat[i], x)
while i > 0:
i >>= 1
self.dat[i] = self.op(self.dat[i], x)
def get(self, a, b = None):
if b is None:
b = a + 1
l, r = a + self.size, b + self.size
res = None
while l < r:
if l & 1:
if res is None:
res = self.dat[l]
else:
res = self.op(res, self.dat[l])
l += 1
if r & 1:
r -= 1
if res is None:
res = self.dat[r]
else:
res = self.op(res, self.dat[r])
l >>= 1
r >>= 1
return res
def solve():
n = I()
S = list(eval(input()))
m = ord("z")-ord("a")+1
s = [SegmentTree(n,0) for i in range(m)]
for i in range(n):
k = ord(S[i])-ord("a")
s[k].update(i,1)
Q = I()
for _ in range(Q):
q = input().split()
if q[0] == "1":
i = int(q[1])-1
if S[i] == q[2]:
continue
k = ord(S[i])-ord("a")
s[k].update(i,0)
k = ord(q[2])-ord("a")
s[k].update(i,1)
S[i] = q[2]
else:
l,r = q[1:]
l = int(l)
r = int(r)
ans = 0
for k in range(m):
if s[k].get(l-1,r):
ans += 1
print(ans)
return
#Solve
if __name__ == "__main__":
solve()
| #!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007
import operator
class SegmentTree:
def __init__(self, size, default, op = operator.or_):
self.size = 2**size.bit_length()
self.dat = [default]*(self.size*2)
self.op = op
def update(self, i, x):
i += self.size
self.dat[i] = x
while i > 0:
i >>= 1
self.dat[i] = self.op(self.dat[i*2], self.dat[i*2+1])
def add(self, i, x):
i += self.size
self.dat[i] = self.op(self.dat[i], x)
while i > 0:
i >>= 1
self.dat[i] = self.op(self.dat[i], x)
def get(self, a, b = None):
if b is None:
b = a + 1
l, r = a + self.size, b + self.size
res = None
while l < r:
if l & 1:
if res is None:
res = self.dat[l]
else:
res = self.op(res, self.dat[l])
l += 1
if r & 1:
r -= 1
if res is None:
res = self.dat[r]
else:
res = self.op(res, self.dat[r])
l >>= 1
r >>= 1
return res
def solve():
n = I()
S = list(eval(input()))
m = ord("z")-ord("a")+1
s = SegmentTree(n,0)
for i in range(n):
k = ord(S[i])-ord("a")
k = 1 << k
s.update(i,k)
Q = I()
for _ in range(Q):
q = input().split()
if q[0] == "1":
i = int(q[1])-1
if S[i] == q[2]:
continue
s.update(i,0)
k = ord(q[2])-ord("a")
k = 1 << k
s.update(i,k)
S[i] = q[2]
else:
l,r = q[1:]
l = int(l)
r = int(r)
print((bin(s.get(l-1,r)).count("1")))
return
#Solve
if __name__ == "__main__":
solve()
| 103 | 100 | 2,757 | 2,641 | #!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI():
return [int(x) for x in sys.stdin.readline().split()]
def I():
return int(sys.stdin.readline())
def LS():
return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007
import operator
class SegmentTree:
def __init__(self, size, default, op=operator.add):
self.size = 2 ** size.bit_length()
self.dat = [default] * (self.size * 2)
self.op = op
def update(self, i, x):
i += self.size
self.dat[i] = x
while i > 0:
i >>= 1
self.dat[i] = self.op(self.dat[i * 2], self.dat[i * 2 + 1])
def add(self, i, x):
i += self.size
self.dat[i] = self.op(self.dat[i], x)
while i > 0:
i >>= 1
self.dat[i] = self.op(self.dat[i], x)
def get(self, a, b=None):
if b is None:
b = a + 1
l, r = a + self.size, b + self.size
res = None
while l < r:
if l & 1:
if res is None:
res = self.dat[l]
else:
res = self.op(res, self.dat[l])
l += 1
if r & 1:
r -= 1
if res is None:
res = self.dat[r]
else:
res = self.op(res, self.dat[r])
l >>= 1
r >>= 1
return res
def solve():
n = I()
S = list(eval(input()))
m = ord("z") - ord("a") + 1
s = [SegmentTree(n, 0) for i in range(m)]
for i in range(n):
k = ord(S[i]) - ord("a")
s[k].update(i, 1)
Q = I()
for _ in range(Q):
q = input().split()
if q[0] == "1":
i = int(q[1]) - 1
if S[i] == q[2]:
continue
k = ord(S[i]) - ord("a")
s[k].update(i, 0)
k = ord(q[2]) - ord("a")
s[k].update(i, 1)
S[i] = q[2]
else:
l, r = q[1:]
l = int(l)
r = int(r)
ans = 0
for k in range(m):
if s[k].get(l - 1, r):
ans += 1
print(ans)
return
# Solve
if __name__ == "__main__":
solve()
| #!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI():
return [int(x) for x in sys.stdin.readline().split()]
def I():
return int(sys.stdin.readline())
def LS():
return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007
import operator
class SegmentTree:
def __init__(self, size, default, op=operator.or_):
self.size = 2 ** size.bit_length()
self.dat = [default] * (self.size * 2)
self.op = op
def update(self, i, x):
i += self.size
self.dat[i] = x
while i > 0:
i >>= 1
self.dat[i] = self.op(self.dat[i * 2], self.dat[i * 2 + 1])
def add(self, i, x):
i += self.size
self.dat[i] = self.op(self.dat[i], x)
while i > 0:
i >>= 1
self.dat[i] = self.op(self.dat[i], x)
def get(self, a, b=None):
if b is None:
b = a + 1
l, r = a + self.size, b + self.size
res = None
while l < r:
if l & 1:
if res is None:
res = self.dat[l]
else:
res = self.op(res, self.dat[l])
l += 1
if r & 1:
r -= 1
if res is None:
res = self.dat[r]
else:
res = self.op(res, self.dat[r])
l >>= 1
r >>= 1
return res
def solve():
n = I()
S = list(eval(input()))
m = ord("z") - ord("a") + 1
s = SegmentTree(n, 0)
for i in range(n):
k = ord(S[i]) - ord("a")
k = 1 << k
s.update(i, k)
Q = I()
for _ in range(Q):
q = input().split()
if q[0] == "1":
i = int(q[1]) - 1
if S[i] == q[2]:
continue
s.update(i, 0)
k = ord(q[2]) - ord("a")
k = 1 << k
s.update(i, k)
S[i] = q[2]
else:
l, r = q[1:]
l = int(l)
r = int(r)
print((bin(s.get(l - 1, r)).count("1")))
return
# Solve
if __name__ == "__main__":
solve()
| false | 2.912621 | [
"- def __init__(self, size, default, op=operator.add):",
"+ def __init__(self, size, default, op=operator.or_):",
"- s = [SegmentTree(n, 0) for i in range(m)]",
"+ s = SegmentTree(n, 0)",
"- s[k].update(i, 1)",
"+ k = 1 << k",
"+ s.update(i, k)",
"- k = ord(S[i]) - ord(\"a\")",
"- s[k].update(i, 0)",
"+ s.update(i, 0)",
"- s[k].update(i, 1)",
"+ k = 1 << k",
"+ s.update(i, k)",
"- ans = 0",
"- for k in range(m):",
"- if s[k].get(l - 1, r):",
"- ans += 1",
"- print(ans)",
"+ print((bin(s.get(l - 1, r)).count(\"1\")))"
] | false | 0.036862 | 0.100024 | 0.368531 | [
"s689695838",
"s281407456"
] |
u241190159 | p02803 | python | s718670879 | s533584577 | 1,516 | 767 | 4,080 | 62,292 | Accepted | Accepted | 49.41 | import bisect
import math
from queue import Queue
import sys
from copy import copy, deepcopy
from collections import defaultdict, Counter, deque
from itertools import combinations, permutations
from heapq import heapify, heappop, heappush
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
inf = float("inf")
def main():
H, W = map(int, readline().split())
S = [[s for s in input()] for h in range(H)]
ret = 0
delta = [(-1, 0), (1, 0), (0, -1), (0, 1)]
for h in range(H):
for w in range(W):
if S[h][w] == '.':
tmp_ret = 0
maze = deepcopy(S)
maze[h][w] = tmp_ret
q1 = Queue()
q1.put((h, w))
q2 = Queue()
while not (q1.empty() and q2.empty()):
while not q1.empty():
h, w = q1.get()
for dh, dw in delta:
if h + dh < H and h + dh >= 0 \
and w + dw < W and w + dw >= 0 \
and maze[h + dh][w + dw] == '.':
maze[h + dh][w + dw] = tmp_ret
q2.put((h + dh, w + dw))
if not q2.empty():
q1 = q2
q2 = Queue()
tmp_ret += 1
ret = max(ret, tmp_ret)
print(ret)
if __name__ == "__main__":
main()
| import bisect
import math
from queue import Queue
import sys
from copy import copy, deepcopy
from collections import defaultdict, Counter, deque
from itertools import combinations, permutations
from heapq import heapify, heappop, heappush
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
inf = float("inf")
def main():
H, W = map(int, readline().split())
S = [[s for s in input()] for h in range(H)]
ret = 0
delta = [(-1, 0), (1, 0), (0, -1), (0, 1)]
for h in range(H):
for w in range(W):
if S[h][w] == '.':
tmp_ret = 0
maze = deepcopy(S)
maze[h][w] = tmp_ret
q1 = Queue()
q1.put((h, w))
q2 = Queue()
while not (q1.empty() and q2.empty()):
while not q1.empty():
h, w = q1.get()
for dh, dw in delta:
if h + dh < H and h + dh >= 0 \
and w + dw < W and w + dw >= 0 \
and maze[h + dh][w + dw] == '.':
maze[h + dh][w + dw] = '#'
q2.put((h + dh, w + dw))
if not q2.empty():
q1 = q2
q2 = Queue()
tmp_ret += 1
ret = max(ret, tmp_ret)
print(ret)
if __name__ == "__main__":
main()
| 61 | 58 | 1,669 | 1,647 | import bisect
import math
from queue import Queue
import sys
from copy import copy, deepcopy
from collections import defaultdict, Counter, deque
from itertools import combinations, permutations
from heapq import heapify, heappop, heappush
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
inf = float("inf")
def main():
H, W = map(int, readline().split())
S = [[s for s in input()] for h in range(H)]
ret = 0
delta = [(-1, 0), (1, 0), (0, -1), (0, 1)]
for h in range(H):
for w in range(W):
if S[h][w] == ".":
tmp_ret = 0
maze = deepcopy(S)
maze[h][w] = tmp_ret
q1 = Queue()
q1.put((h, w))
q2 = Queue()
while not (q1.empty() and q2.empty()):
while not q1.empty():
h, w = q1.get()
for dh, dw in delta:
if (
h + dh < H
and h + dh >= 0
and w + dw < W
and w + dw >= 0
and maze[h + dh][w + dw] == "."
):
maze[h + dh][w + dw] = tmp_ret
q2.put((h + dh, w + dw))
if not q2.empty():
q1 = q2
q2 = Queue()
tmp_ret += 1
ret = max(ret, tmp_ret)
print(ret)
if __name__ == "__main__":
main()
| import bisect
import math
from queue import Queue
import sys
from copy import copy, deepcopy
from collections import defaultdict, Counter, deque
from itertools import combinations, permutations
from heapq import heapify, heappop, heappush
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
inf = float("inf")
def main():
H, W = map(int, readline().split())
S = [[s for s in input()] for h in range(H)]
ret = 0
delta = [(-1, 0), (1, 0), (0, -1), (0, 1)]
for h in range(H):
for w in range(W):
if S[h][w] == ".":
tmp_ret = 0
maze = deepcopy(S)
maze[h][w] = tmp_ret
q1 = Queue()
q1.put((h, w))
q2 = Queue()
while not (q1.empty() and q2.empty()):
while not q1.empty():
h, w = q1.get()
for dh, dw in delta:
if (
h + dh < H
and h + dh >= 0
and w + dw < W
and w + dw >= 0
and maze[h + dh][w + dw] == "."
):
maze[h + dh][w + dw] = "#"
q2.put((h + dh, w + dw))
if not q2.empty():
q1 = q2
q2 = Queue()
tmp_ret += 1
ret = max(ret, tmp_ret)
print(ret)
if __name__ == "__main__":
main()
| false | 4.918033 | [
"- maze[h + dh][w + dw] = tmp_ret",
"+ maze[h + dh][w + dw] = \"#\""
] | false | 0.05568 | 0.036327 | 1.532756 | [
"s718670879",
"s533584577"
] |
u562541930 | p02984 | python | s564080733 | s113393151 | 234 | 215 | 12,336 | 11,324 | Accepted | Accepted | 8.12 | def main():
N = int(input())
A = input().split()
S = 0
ans = []
for n in range(N):
ans.append(0)
A[n] = int(A[n])
S += A[n]
ans[0] = S
for n in range(N)[1::2]:
ans[0] -= 2 * A[n]
for n in range(N)[1:]:
ans[n] = 2 * A[n - 1] - ans[n - 1]
for n in range(N):
if n == N - 1:
print(ans[n])
else:
print(str(ans[n]) + " ", end="")
if __name__ == '__main__':
main()
| def main():
N = int(input())
A = input().split()
S = 0
for n in range(N):
A[n] = int(A[n])
S += A[n]
ans = S
for n in range(N)[1::2]:
ans -= 2 * A[n]
prev = ans
print(str(ans) + " ", end="")
for n in range(N)[1:]:
ans = 2 * A[n - 1] - prev
prev = ans
if n == N - 1:
print(ans)
else:
print(str(ans) + " ", end="")
if __name__ == '__main__':
main()
| 22 | 22 | 500 | 489 | def main():
N = int(input())
A = input().split()
S = 0
ans = []
for n in range(N):
ans.append(0)
A[n] = int(A[n])
S += A[n]
ans[0] = S
for n in range(N)[1::2]:
ans[0] -= 2 * A[n]
for n in range(N)[1:]:
ans[n] = 2 * A[n - 1] - ans[n - 1]
for n in range(N):
if n == N - 1:
print(ans[n])
else:
print(str(ans[n]) + " ", end="")
if __name__ == "__main__":
main()
| def main():
N = int(input())
A = input().split()
S = 0
for n in range(N):
A[n] = int(A[n])
S += A[n]
ans = S
for n in range(N)[1::2]:
ans -= 2 * A[n]
prev = ans
print(str(ans) + " ", end="")
for n in range(N)[1:]:
ans = 2 * A[n - 1] - prev
prev = ans
if n == N - 1:
print(ans)
else:
print(str(ans) + " ", end="")
if __name__ == "__main__":
main()
| false | 0 | [
"- ans = []",
"- ans.append(0)",
"- ans[0] = S",
"+ ans = S",
"- ans[0] -= 2 * A[n]",
"+ ans -= 2 * A[n]",
"+ prev = ans",
"+ print(str(ans) + \" \", end=\"\")",
"- ans[n] = 2 * A[n - 1] - ans[n - 1]",
"- for n in range(N):",
"+ ans = 2 * A[n - 1] - prev",
"+ prev = ans",
"- print(ans[n])",
"+ print(ans)",
"- print(str(ans[n]) + \" \", end=\"\")",
"+ print(str(ans) + \" \", end=\"\")"
] | false | 0.080668 | 0.042649 | 1.89143 | [
"s564080733",
"s113393151"
] |
u869919400 | p02803 | python | s239889388 | s966431176 | 295 | 260 | 47,708 | 45,788 | Accepted | Accepted | 11.86 | H, W = list(map(int, input().split()))
l = [eval(input()) for i in range(H)]
from collections import deque
d = [(1, 0), (-1, 0), (0, 1), (0, -1)]
ans = 0
for i in range(H):
for j in range(W):
if l[i][j] == '#':
continue
ll = [[0] * W for _ in range(H)]
q = deque([(i, j)])
while q:
y, x = q.popleft()
for dy, dx in d:
if 0 <= y+dy < H and 0 <= x+dx < W and l[y+dy][x+dx] == '.' and (y+dy, x+dx) != (i, j):
n = ll[y][x] + 1
if ll[y+dy][x+dx] == 0 or ll[y+dy][x+dx] > n:
ll[y+dy][x+dx] = n
q.append((y+dy, x+dx))
if ans < n:
ans = n
print(ans) | H, W = list(map(int, input().split()))
l = [eval(input()) for i in range(H)]
from collections import deque
d = [(1, 0), (-1, 0), (0, 1), (0, -1)]
ans = 0
for i in range(H):
for j in range(W):
if l[i][j] == '#':
continue
cells = [[None] * W for _ in range(H)]
cells[i][j] = 0
q = deque([(i, j)])
while q:
y, x = q.popleft()
for dy, dx in d:
if 0 <= y+dy < H and 0 <= x+dx < W and l[y+dy][x+dx] == '.' and (cells[y+dy][x+dx] is None or cells[y+dy][x+dx] > cells[y][x]+1):
n = cells[y][x] + 1
cells[y+dy][x+dx] = n
q.append((y+dy, x+dx))
if ans < n:
ans = n
print(ans) | 25 | 25 | 784 | 781 | H, W = list(map(int, input().split()))
l = [eval(input()) for i in range(H)]
from collections import deque
d = [(1, 0), (-1, 0), (0, 1), (0, -1)]
ans = 0
for i in range(H):
for j in range(W):
if l[i][j] == "#":
continue
ll = [[0] * W for _ in range(H)]
q = deque([(i, j)])
while q:
y, x = q.popleft()
for dy, dx in d:
if (
0 <= y + dy < H
and 0 <= x + dx < W
and l[y + dy][x + dx] == "."
and (y + dy, x + dx) != (i, j)
):
n = ll[y][x] + 1
if ll[y + dy][x + dx] == 0 or ll[y + dy][x + dx] > n:
ll[y + dy][x + dx] = n
q.append((y + dy, x + dx))
if ans < n:
ans = n
print(ans)
| H, W = list(map(int, input().split()))
l = [eval(input()) for i in range(H)]
from collections import deque
d = [(1, 0), (-1, 0), (0, 1), (0, -1)]
ans = 0
for i in range(H):
for j in range(W):
if l[i][j] == "#":
continue
cells = [[None] * W for _ in range(H)]
cells[i][j] = 0
q = deque([(i, j)])
while q:
y, x = q.popleft()
for dy, dx in d:
if (
0 <= y + dy < H
and 0 <= x + dx < W
and l[y + dy][x + dx] == "."
and (
cells[y + dy][x + dx] is None
or cells[y + dy][x + dx] > cells[y][x] + 1
)
):
n = cells[y][x] + 1
cells[y + dy][x + dx] = n
q.append((y + dy, x + dx))
if ans < n:
ans = n
print(ans)
| false | 0 | [
"- ll = [[0] * W for _ in range(H)]",
"+ cells = [[None] * W for _ in range(H)]",
"+ cells[i][j] = 0",
"- and (y + dy, x + dx) != (i, j)",
"+ and (",
"+ cells[y + dy][x + dx] is None",
"+ or cells[y + dy][x + dx] > cells[y][x] + 1",
"+ )",
"- n = ll[y][x] + 1",
"- if ll[y + dy][x + dx] == 0 or ll[y + dy][x + dx] > n:",
"- ll[y + dy][x + dx] = n",
"- q.append((y + dy, x + dx))",
"- if ans < n:",
"- ans = n",
"+ n = cells[y][x] + 1",
"+ cells[y + dy][x + dx] = n",
"+ q.append((y + dy, x + dx))",
"+ if ans < n:",
"+ ans = n"
] | false | 0.036881 | 0.054018 | 0.682753 | [
"s239889388",
"s966431176"
] |
u057109575 | p02899 | python | s563623759 | s900047164 | 411 | 205 | 68,140 | 96,172 | Accepted | Accepted | 50.12 | N = int(eval(input()))
A = list(map(int, input().split()))
ans = [i + 1for i, v
in sorted(enumerate(A), key=lambda x: x[1])]
print((*ans))
|
N = int(eval(input()))
X = list(map(int, input().split()))
ans = []
for i, _ in sorted(enumerate(X), key=lambda x: x[1]):
ans.append(i + 1)
print((*ans))
| 6 | 9 | 144 | 161 | N = int(eval(input()))
A = list(map(int, input().split()))
ans = [i + 1 for i, v in sorted(enumerate(A), key=lambda x: x[1])]
print((*ans))
| N = int(eval(input()))
X = list(map(int, input().split()))
ans = []
for i, _ in sorted(enumerate(X), key=lambda x: x[1]):
ans.append(i + 1)
print((*ans))
| false | 33.333333 | [
"-A = list(map(int, input().split()))",
"-ans = [i + 1 for i, v in sorted(enumerate(A), key=lambda x: x[1])]",
"+X = list(map(int, input().split()))",
"+ans = []",
"+for i, _ in sorted(enumerate(X), key=lambda x: x[1]):",
"+ ans.append(i + 1)"
] | false | 0.076252 | 0.08936 | 0.853314 | [
"s563623759",
"s900047164"
] |
u150984829 | p00448 | python | s078631675 | s697203890 | 13,620 | 12,490 | 6,916 | 6,912 | Accepted | Accepted | 8.3 | for e in iter(input,'0 0'):
r,_=list(map(int,e.split()))
d=[int(''.join(x),2)for x in zip(*[input().split()for _ in[0]*r])]
a=0
for i in range(1<<r):
b=0
for j in d:
c=bin(i^j).count('1')
b+=max(c,r-c)
a=max(a,b)
print(a)
| for e in iter(input,'0 0'):
r,_=list(map(int,e.split()))
d=[int(''.join(x),2)for x in zip(*[input().split()for _ in[0]*r])]
a=0
for i in range(1<<r):
b=0
for j in d:
c=bin(i^j).count('1')
b+=[r-c,c][c>r//2]
if b>a:a=b
print(a)
| 11 | 11 | 243 | 248 | for e in iter(input, "0 0"):
r, _ = list(map(int, e.split()))
d = [int("".join(x), 2) for x in zip(*[input().split() for _ in [0] * r])]
a = 0
for i in range(1 << r):
b = 0
for j in d:
c = bin(i ^ j).count("1")
b += max(c, r - c)
a = max(a, b)
print(a)
| for e in iter(input, "0 0"):
r, _ = list(map(int, e.split()))
d = [int("".join(x), 2) for x in zip(*[input().split() for _ in [0] * r])]
a = 0
for i in range(1 << r):
b = 0
for j in d:
c = bin(i ^ j).count("1")
b += [r - c, c][c > r // 2]
if b > a:
a = b
print(a)
| false | 0 | [
"- b += max(c, r - c)",
"- a = max(a, b)",
"+ b += [r - c, c][c > r // 2]",
"+ if b > a:",
"+ a = b"
] | false | 0.050413 | 0.049893 | 1.010429 | [
"s078631675",
"s697203890"
] |
u124498235 | p03105 | python | s985696984 | s853352950 | 20 | 17 | 3,060 | 2,940 | Accepted | Accepted | 15 | a, b, c = list(map(int, input().split()))
if a*c <= b:
print (c)
else:
print((b//a)) | a, b, c = list(map(int, input().split()))
if a*c < b:
print (c)
else:
print((b//a)) | 5 | 5 | 82 | 82 | a, b, c = list(map(int, input().split()))
if a * c <= b:
print(c)
else:
print((b // a))
| a, b, c = list(map(int, input().split()))
if a * c < b:
print(c)
else:
print((b // a))
| false | 0 | [
"-if a * c <= b:",
"+if a * c < b:"
] | false | 0.096522 | 0.036881 | 2.617091 | [
"s985696984",
"s853352950"
] |
u562935282 | p03040 | python | s780841618 | s635632089 | 780 | 609 | 74,308 | 11,148 | Accepted | Accepted | 21.92 | def main():
from heapq import heappush, heappop, heappushpop
import sys
input = sys.stdin.readline
class Median:
def __init__(self):
self.b = 0
self.l = []
self.sum_l = 0
self.r = []
self.sum_r = 0
def update(self, a: int, b: int) -> None:
self.b += b
size = len(self.l) + len(self.r)
if size % 2 == 0:
x = heappushpop(self.r, a)
self.sum_r += a - x
heappush(self.l, -x)
self.sum_l += x
else:
x = heappushpop(self.l, -a)
self.sum_l += a + x # a - (-x)
heappush(self.r, -x)
self.sum_r -= x # += (-x)
def query(self):
median = -self.l[0]
ret = (abs(len(self.l) * median - self.sum_l)
+ abs(self.sum_r - len(self.r) * median)
+ self.b)
return median, ret
med = Median()
n = int(eval(input()))
for _ in range(n):
q = iter(input().rstrip().split())
if next(q) == '1':
med.update(*list(map(int, q)))
else:
print((*med.query()))
if __name__ == '__main__':
main()
| def main():
from heapq import heappop, heappush
import sys
input = sys.stdin.readline
Q = int(eval(input()))
left = []
right = []
sum_l = 0
sum_r = 0
cnt = 0
b = 0
for _ in range(Q):
query = list(map(int, input().split()))
t = next(query)
if t == 1:
x, b_ = query
b += b_
cnt += 1
if cnt % 2 == 0:
heappush(left, -x)
sum_l += x
x = -heappop(left)
sum_l -= x
heappush(right, x)
sum_r += x
else:
heappush(right, x)
sum_r += x
x = heappop(right)
sum_r -= x
heappush(left, -x)
sum_l += x
else:
x = -left[0]
ans = b + sum_r - sum_l + x * (cnt % 2)
print((x, ans))
if __name__ == '__main__':
main()
# import sys
# input = sys.stdin.readline
#
# sys.setrecursionlimit(10 ** 7)
#
# (int(x)-1 for x in input().split())
# rstrip()
| 48 | 50 | 1,313 | 1,129 | def main():
from heapq import heappush, heappop, heappushpop
import sys
input = sys.stdin.readline
class Median:
def __init__(self):
self.b = 0
self.l = []
self.sum_l = 0
self.r = []
self.sum_r = 0
def update(self, a: int, b: int) -> None:
self.b += b
size = len(self.l) + len(self.r)
if size % 2 == 0:
x = heappushpop(self.r, a)
self.sum_r += a - x
heappush(self.l, -x)
self.sum_l += x
else:
x = heappushpop(self.l, -a)
self.sum_l += a + x # a - (-x)
heappush(self.r, -x)
self.sum_r -= x # += (-x)
def query(self):
median = -self.l[0]
ret = (
abs(len(self.l) * median - self.sum_l)
+ abs(self.sum_r - len(self.r) * median)
+ self.b
)
return median, ret
med = Median()
n = int(eval(input()))
for _ in range(n):
q = iter(input().rstrip().split())
if next(q) == "1":
med.update(*list(map(int, q)))
else:
print((*med.query()))
if __name__ == "__main__":
main()
| def main():
from heapq import heappop, heappush
import sys
input = sys.stdin.readline
Q = int(eval(input()))
left = []
right = []
sum_l = 0
sum_r = 0
cnt = 0
b = 0
for _ in range(Q):
query = list(map(int, input().split()))
t = next(query)
if t == 1:
x, b_ = query
b += b_
cnt += 1
if cnt % 2 == 0:
heappush(left, -x)
sum_l += x
x = -heappop(left)
sum_l -= x
heappush(right, x)
sum_r += x
else:
heappush(right, x)
sum_r += x
x = heappop(right)
sum_r -= x
heappush(left, -x)
sum_l += x
else:
x = -left[0]
ans = b + sum_r - sum_l + x * (cnt % 2)
print((x, ans))
if __name__ == "__main__":
main()
# import sys
# input = sys.stdin.readline
#
# sys.setrecursionlimit(10 ** 7)
#
# (int(x)-1 for x in input().split())
# rstrip()
| false | 4 | [
"- from heapq import heappush, heappop, heappushpop",
"+ from heapq import heappop, heappush",
"-",
"- class Median:",
"- def __init__(self):",
"- self.b = 0",
"- self.l = []",
"- self.sum_l = 0",
"- self.r = []",
"- self.sum_r = 0",
"-",
"- def update(self, a: int, b: int) -> None:",
"- self.b += b",
"- size = len(self.l) + len(self.r)",
"- if size % 2 == 0:",
"- x = heappushpop(self.r, a)",
"- self.sum_r += a - x",
"- heappush(self.l, -x)",
"- self.sum_l += x",
"+ Q = int(eval(input()))",
"+ left = []",
"+ right = []",
"+ sum_l = 0",
"+ sum_r = 0",
"+ cnt = 0",
"+ b = 0",
"+ for _ in range(Q):",
"+ query = list(map(int, input().split()))",
"+ t = next(query)",
"+ if t == 1:",
"+ x, b_ = query",
"+ b += b_",
"+ cnt += 1",
"+ if cnt % 2 == 0:",
"+ heappush(left, -x)",
"+ sum_l += x",
"+ x = -heappop(left)",
"+ sum_l -= x",
"+ heappush(right, x)",
"+ sum_r += x",
"- x = heappushpop(self.l, -a)",
"- self.sum_l += a + x # a - (-x)",
"- heappush(self.r, -x)",
"- self.sum_r -= x # += (-x)",
"-",
"- def query(self):",
"- median = -self.l[0]",
"- ret = (",
"- abs(len(self.l) * median - self.sum_l)",
"- + abs(self.sum_r - len(self.r) * median)",
"- + self.b",
"- )",
"- return median, ret",
"-",
"- med = Median()",
"- n = int(eval(input()))",
"- for _ in range(n):",
"- q = iter(input().rstrip().split())",
"- if next(q) == \"1\":",
"- med.update(*list(map(int, q)))",
"+ heappush(right, x)",
"+ sum_r += x",
"+ x = heappop(right)",
"+ sum_r -= x",
"+ heappush(left, -x)",
"+ sum_l += x",
"- print((*med.query()))",
"+ x = -left[0]",
"+ ans = b + sum_r - sum_l + x * (cnt % 2)",
"+ print((x, ans))",
"+# import sys",
"+# input = sys.stdin.readline",
"+#",
"+# sys.setrecursionlimit(10 ** 7)",
"+#",
"+# (int(x)-1 for x in input().split())",
"+# rstrip()"
] | false | 0.035895 | 0.046731 | 0.768126 | [
"s780841618",
"s635632089"
] |
u562935282 | p03147 | python | s536660690 | s126781929 | 21 | 17 | 3,060 | 2,940 | Accepted | Accepted | 19.05 | N = int(eval(input()))
h = list(map(int, input().split()))
ans = 0
i = 0
while i < N:
while h[i] == 0:
i += 1
if i == N: break
j = i
if i == N: break
while h[j] > 0:
h[j] -= 1
j += 1
if j == N: break
ans += 1
print(ans)
| n = int(eval(input()))
h = tuple(map(int, input().split()))
ans = 0
cur = 0
for hh in h:
if cur < hh:
ans += hh - cur
cur = hh
else:
cur = hh
print(ans)
| 18 | 12 | 293 | 191 | N = int(eval(input()))
h = list(map(int, input().split()))
ans = 0
i = 0
while i < N:
while h[i] == 0:
i += 1
if i == N:
break
j = i
if i == N:
break
while h[j] > 0:
h[j] -= 1
j += 1
if j == N:
break
ans += 1
print(ans)
| n = int(eval(input()))
h = tuple(map(int, input().split()))
ans = 0
cur = 0
for hh in h:
if cur < hh:
ans += hh - cur
cur = hh
else:
cur = hh
print(ans)
| false | 33.333333 | [
"-N = int(eval(input()))",
"-h = list(map(int, input().split()))",
"+n = int(eval(input()))",
"+h = tuple(map(int, input().split()))",
"-i = 0",
"-while i < N:",
"- while h[i] == 0:",
"- i += 1",
"- if i == N:",
"- break",
"- j = i",
"- if i == N:",
"- break",
"- while h[j] > 0:",
"- h[j] -= 1",
"- j += 1",
"- if j == N:",
"- break",
"- ans += 1",
"+cur = 0",
"+for hh in h:",
"+ if cur < hh:",
"+ ans += hh - cur",
"+ cur = hh",
"+ else:",
"+ cur = hh"
] | false | 0.043467 | 0.036246 | 1.199203 | [
"s536660690",
"s126781929"
] |
u638795007 | p03325 | python | s901461628 | s049784395 | 186 | 74 | 40,432 | 5,488 | Accepted | Accepted | 60.22 | def examC():
N= I()
A = LI()
cur = 0
for i in A:
while(True):
if i % 2 == 0:
i //= 2
cur += 1
else:
break
print(cur)
import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')
examC()
| def ABC67_B():
N, K = LI()
L = LI()
L.sort(reverse=True)
ans = sum(L[:K])
print(ans)
return
def ABC100_C():
def factorization_2(n):
arr = defaultdict(int)
temp = n
i = 2
if temp % i == 0:
cnt = 0
while temp % i == 0:
cnt += 1
temp //= i
arr[i] = cnt
if temp != 1:
arr[temp] = 1
if arr == []:
arr[n] = 1
return arr[2]
N = I()
A = LI()
ans = 0
for a in A:
ans += factorization_2(a)
print(ans)
return
def examC():
ans = 0
print(ans)
return
def examD():
ans = 0
print(ans)
return
def examE():
ans = 0
print(ans)
return
def examF():
ans = 0
print(ans)
return
import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]
sys.setrecursionlimit(10**6)
if __name__ == '__main__':
ABC100_C()
"""
""" | 27 | 76 | 684 | 1,540 | def examC():
N = I()
A = LI()
cur = 0
for i in A:
while True:
if i % 2 == 0:
i //= 2
cur += 1
else:
break
print(cur)
import sys, copy, bisect, itertools, heapq, math
from heapq import heappop, heappush, heapify
from collections import Counter, defaultdict, deque
def I():
return int(sys.stdin.readline())
def LI():
return list(map(int, sys.stdin.readline().split()))
def LSI():
return list(map(str, sys.stdin.readline().split()))
def LS():
return sys.stdin.readline().split()
def SI():
return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float("inf")
examC()
| def ABC67_B():
N, K = LI()
L = LI()
L.sort(reverse=True)
ans = sum(L[:K])
print(ans)
return
def ABC100_C():
def factorization_2(n):
arr = defaultdict(int)
temp = n
i = 2
if temp % i == 0:
cnt = 0
while temp % i == 0:
cnt += 1
temp //= i
arr[i] = cnt
if temp != 1:
arr[temp] = 1
if arr == []:
arr[n] = 1
return arr[2]
N = I()
A = LI()
ans = 0
for a in A:
ans += factorization_2(a)
print(ans)
return
def examC():
ans = 0
print(ans)
return
def examD():
ans = 0
print(ans)
return
def examE():
ans = 0
print(ans)
return
def examF():
ans = 0
print(ans)
return
import sys, bisect, itertools, heapq, math, random
from copy import deepcopy
from heapq import heappop, heappush, heapify
from collections import Counter, defaultdict, deque
def I():
return int(sys.stdin.readline())
def LI():
return list(map(int, sys.stdin.readline().split()))
def LSI():
return list(map(str, sys.stdin.readline().split()))
def LS():
return sys.stdin.readline().split()
def SI():
return sys.stdin.readline().strip()
global mod, mod2, inf, alphabet, _ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10 ** (-12)
alphabet = [chr(ord("a") + i) for i in range(26)]
sys.setrecursionlimit(10**6)
if __name__ == "__main__":
ABC100_C()
"""
"""
| false | 64.473684 | [
"-def examC():",
"+def ABC67_B():",
"+ N, K = LI()",
"+ L = LI()",
"+ L.sort(reverse=True)",
"+ ans = sum(L[:K])",
"+ print(ans)",
"+ return",
"+",
"+",
"+def ABC100_C():",
"+ def factorization_2(n):",
"+ arr = defaultdict(int)",
"+ temp = n",
"+ i = 2",
"+ if temp % i == 0:",
"+ cnt = 0",
"+ while temp % i == 0:",
"+ cnt += 1",
"+ temp //= i",
"+ arr[i] = cnt",
"+ if temp != 1:",
"+ arr[temp] = 1",
"+ if arr == []:",
"+ arr[n] = 1",
"+ return arr[2]",
"+",
"- cur = 0",
"- for i in A:",
"- while True:",
"- if i % 2 == 0:",
"- i //= 2",
"- cur += 1",
"- else:",
"- break",
"- print(cur)",
"+ ans = 0",
"+ for a in A:",
"+ ans += factorization_2(a)",
"+ print(ans)",
"+ return",
"-import sys, copy, bisect, itertools, heapq, math",
"+def examC():",
"+ ans = 0",
"+ print(ans)",
"+ return",
"+",
"+",
"+def examD():",
"+ ans = 0",
"+ print(ans)",
"+ return",
"+",
"+",
"+def examE():",
"+ ans = 0",
"+ print(ans)",
"+ return",
"+",
"+",
"+def examF():",
"+ ans = 0",
"+ print(ans)",
"+ return",
"+",
"+",
"+import sys, bisect, itertools, heapq, math, random",
"+from copy import deepcopy",
"+global mod, mod2, inf, alphabet, _ep",
"-inf = float(\"inf\")",
"-examC()",
"+mod2 = 998244353",
"+inf = 10**18",
"+_ep = 10 ** (-12)",
"+alphabet = [chr(ord(\"a\") + i) for i in range(26)]",
"+sys.setrecursionlimit(10**6)",
"+if __name__ == \"__main__\":",
"+ ABC100_C()",
"+\"\"\"",
"+\"\"\""
] | false | 0.047317 | 0.048112 | 0.983477 | [
"s901461628",
"s049784395"
] |
u197300773 | p03061 | python | s199633190 | s745996843 | 104 | 47 | 14,588 | 14,588 | Accepted | Accepted | 54.81 | def gcd(a,b):
if b>a:
a,b=b,a
while b:
a,b=b, a%b
return a
def cul(n,x):
l=len(x)
b=[x[i] for i in range(l)]
b.pop(n)
tmp=b[0]
for i in range(1,l-1):
tmp=gcd(tmp,b[i])
return tmp
import sys
import math
p=100
N=int(eval(input()))
a=list(map(int,input().split()))
if N<=p:
ans=0
for i in range(N):
tmp=cul(i,a)
if tmp>ans: ans=tmp
print(ans)
sys.exit()
M=a[0]
for i in range(1,p):
M=gcd(M,a[i])
ans=0
R=a[p]
for i in range(p,N):
r=gcd(R,a[i])
if r>ans:
for i in range(p):
s=gcd(cul(i,a[:p]),R)
if s>ans: ans=s
print(ans)
| def gcd(a,b):
if b>a:
a,b=b,a
while b:
a,b=b, a%b
return a
def cul(n,x):
l=len(x)
b=[x[i] for i in range(l)]
b.pop(n)
tmp=b[0]
for i in range(1,l-1):
tmp=gcd(tmp,b[i])
return tmp
import sys
import math
p=100
N=int(eval(input()))
a=list(map(int,input().split()))
if N<=p:
ans=0
for i in range(N):
tmp=cul(i,a)
if tmp>ans: ans=tmp
print(ans)
sys.exit()
M=a[0]
for i in range(1,p):
M=gcd(M,a[i])
ans=0
for i in range(p):
s=gcd(cul(i,a[:p]),a[p])
if s>ans: ans=s
print(ans) | 48 | 41 | 710 | 634 | def gcd(a, b):
if b > a:
a, b = b, a
while b:
a, b = b, a % b
return a
def cul(n, x):
l = len(x)
b = [x[i] for i in range(l)]
b.pop(n)
tmp = b[0]
for i in range(1, l - 1):
tmp = gcd(tmp, b[i])
return tmp
import sys
import math
p = 100
N = int(eval(input()))
a = list(map(int, input().split()))
if N <= p:
ans = 0
for i in range(N):
tmp = cul(i, a)
if tmp > ans:
ans = tmp
print(ans)
sys.exit()
M = a[0]
for i in range(1, p):
M = gcd(M, a[i])
ans = 0
R = a[p]
for i in range(p, N):
r = gcd(R, a[i])
if r > ans:
for i in range(p):
s = gcd(cul(i, a[:p]), R)
if s > ans:
ans = s
print(ans)
| def gcd(a, b):
if b > a:
a, b = b, a
while b:
a, b = b, a % b
return a
def cul(n, x):
l = len(x)
b = [x[i] for i in range(l)]
b.pop(n)
tmp = b[0]
for i in range(1, l - 1):
tmp = gcd(tmp, b[i])
return tmp
import sys
import math
p = 100
N = int(eval(input()))
a = list(map(int, input().split()))
if N <= p:
ans = 0
for i in range(N):
tmp = cul(i, a)
if tmp > ans:
ans = tmp
print(ans)
sys.exit()
M = a[0]
for i in range(1, p):
M = gcd(M, a[i])
ans = 0
for i in range(p):
s = gcd(cul(i, a[:p]), a[p])
if s > ans:
ans = s
print(ans)
| false | 14.583333 | [
"-R = a[p]",
"-for i in range(p, N):",
"- r = gcd(R, a[i])",
"-if r > ans:",
"- for i in range(p):",
"- s = gcd(cul(i, a[:p]), R)",
"- if s > ans:",
"- ans = s",
"+for i in range(p):",
"+ s = gcd(cul(i, a[:p]), a[p])",
"+ if s > ans:",
"+ ans = s"
] | false | 0.055655 | 0.036562 | 1.522235 | [
"s199633190",
"s745996843"
] |
u890870565 | p03160 | python | s978367332 | s108903307 | 527 | 261 | 23,092 | 23,072 | Accepted | Accepted | 50.47 | import numpy as np
Nmax = 10**5
N = int(eval(input()))
h = [int(x) for x in input().split()]
dp = np.zeros(Nmax + 1)
dp[0] = 0
dp[1] = abs(h[0] - h[1])
for i in range(2, N):
dp[i] = min(dp[i-1] + abs(h[i-1] - h[i]), dp[i-2] + abs(h[i-2] - h[i]))
print((int(dp[N-1]))) | import numpy as np
Nmax = 10**5
N = int(eval(input()))
h = [int(x) for x in input().split()]
dp = [0] * (Nmax + 1)
dp[0] = 0
dp[1] = abs(h[0] - h[1])
for i in range(2, N):
dp[i] = min(dp[i-1] + abs(h[i-1] - h[i]), dp[i-2] + abs(h[i-2] - h[i]))
print((int(dp[N-1])))
| 15 | 15 | 282 | 281 | import numpy as np
Nmax = 10**5
N = int(eval(input()))
h = [int(x) for x in input().split()]
dp = np.zeros(Nmax + 1)
dp[0] = 0
dp[1] = abs(h[0] - h[1])
for i in range(2, N):
dp[i] = min(dp[i - 1] + abs(h[i - 1] - h[i]), dp[i - 2] + abs(h[i - 2] - h[i]))
print((int(dp[N - 1])))
| import numpy as np
Nmax = 10**5
N = int(eval(input()))
h = [int(x) for x in input().split()]
dp = [0] * (Nmax + 1)
dp[0] = 0
dp[1] = abs(h[0] - h[1])
for i in range(2, N):
dp[i] = min(dp[i - 1] + abs(h[i - 1] - h[i]), dp[i - 2] + abs(h[i - 2] - h[i]))
print((int(dp[N - 1])))
| false | 0 | [
"-dp = np.zeros(Nmax + 1)",
"+dp = [0] * (Nmax + 1)"
] | false | 0.178511 | 0.036242 | 4.925563 | [
"s978367332",
"s108903307"
] |
u226155577 | p03355 | python | s072965601 | s656492327 | 217 | 39 | 42,332 | 4,464 | Accepted | Accepted | 82.03 | s = eval(input())
K = int(eval(input()))
from heapq import heappush, heappop
Q = set()
u = set()
N = len(s)
for i in range(N):
for j in range(i+1, i+K+1):
ss = s[i:j]
if ss in u:
continue
u.add(ss)
Q.add(ss)
if len(Q) > K:
Q.remove(max(Q))
l = sorted(Q)
print((l[K-1]))
| s = eval(input())
K = int(eval(input()))
Q = set()
L = len(s)
for i in range(L):
for j in range(K):
if i+j+1 <= L:
Q.add(s[i:i+j+1])
print((sorted(Q)[K-1])) | 19 | 9 | 344 | 174 | s = eval(input())
K = int(eval(input()))
from heapq import heappush, heappop
Q = set()
u = set()
N = len(s)
for i in range(N):
for j in range(i + 1, i + K + 1):
ss = s[i:j]
if ss in u:
continue
u.add(ss)
Q.add(ss)
if len(Q) > K:
Q.remove(max(Q))
l = sorted(Q)
print((l[K - 1]))
| s = eval(input())
K = int(eval(input()))
Q = set()
L = len(s)
for i in range(L):
for j in range(K):
if i + j + 1 <= L:
Q.add(s[i : i + j + 1])
print((sorted(Q)[K - 1]))
| false | 52.631579 | [
"-from heapq import heappush, heappop",
"-",
"-u = set()",
"-N = len(s)",
"-for i in range(N):",
"- for j in range(i + 1, i + K + 1):",
"- ss = s[i:j]",
"- if ss in u:",
"- continue",
"- u.add(ss)",
"- Q.add(ss)",
"- if len(Q) > K:",
"- Q.remove(max(Q))",
"-l = sorted(Q)",
"-print((l[K - 1]))",
"+L = len(s)",
"+for i in range(L):",
"+ for j in range(K):",
"+ if i + j + 1 <= L:",
"+ Q.add(s[i : i + j + 1])",
"+print((sorted(Q)[K - 1]))"
] | false | 0.085043 | 0.039006 | 2.180228 | [
"s072965601",
"s656492327"
] |
u102960641 | p03160 | python | s525262744 | s625774160 | 193 | 159 | 13,928 | 13,976 | Accepted | Accepted | 17.62 | n = int(eval(input()))
h = list(map(int, input().split()))
dp = [10 ** 9 + 7 for i in range(100010)]
dp[0] = 0
for i in range(1,n):
dp[i] = min(dp[i], dp[i-1] + abs(h[i] - h[i-1]))
if i > 1:
dp[i] = min(dp[i], dp[i-2] + abs(h[i] - h[i-2]))
print((dp[n-1]))
| n = int(eval(input()))
h = list(map(int, input().split()))
INF = 10 ** 12
dp = [INF] * (n+1) # 初期化
dp[0] = 0 # 初期条件
for i in range(1,n):
dp[i] = min(dp[i], dp[i-1] + abs(h[i] - h[i-1]))
if i > 1:
dp[i] = min(dp[i], dp[i-2] + abs(h[i] - h[i-2]))
print((dp[n-1])) | 9 | 11 | 265 | 272 | n = int(eval(input()))
h = list(map(int, input().split()))
dp = [10**9 + 7 for i in range(100010)]
dp[0] = 0
for i in range(1, n):
dp[i] = min(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]))
if i > 1:
dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]))
print((dp[n - 1]))
| n = int(eval(input()))
h = list(map(int, input().split()))
INF = 10**12
dp = [INF] * (n + 1) # 初期化
dp[0] = 0 # 初期条件
for i in range(1, n):
dp[i] = min(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]))
if i > 1:
dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]))
print((dp[n - 1]))
| false | 18.181818 | [
"-dp = [10**9 + 7 for i in range(100010)]",
"-dp[0] = 0",
"+INF = 10**12",
"+dp = [INF] * (n + 1) # 初期化",
"+dp[0] = 0 # 初期条件"
] | false | 0.071832 | 0.041965 | 1.711711 | [
"s525262744",
"s625774160"
] |
u671060652 | p02947 | python | s904459920 | s292892596 | 699 | 516 | 60,760 | 27,964 | Accepted | Accepted | 26.18 | import math
n = int(eval(input()))
dic = {}
def twoKimuawaseSum(num):
result = 0
for i in range(1, num):
result += i
return result
for i in range(n):
string = eval(input())
sortStr = "".join(sorted(string))
if sortStr in dic:
dic[sortStr] += 1
else:
dic[sortStr] = 1
sum = 0
for num in list(dic.values()):
if num == 1:
sum += 0
else:
sum += twoKimuawaseSum(num)
print((math.floor(sum)))
| import itertools
import math
from scipy.misc import comb
n = int(eval(input()))
dic = {}
for i in range(n):
string = eval(input())
sortStr = "".join(sorted(string))
if sortStr in dic:
dic[sortStr] += 1
else:
dic[sortStr] = 1
sum = 0
for num in list(dic.values()):
if num == 1:
sum += 0
else:
sum += comb(num, 2,exact=True)
print((math.floor(sum)))
| 27 | 20 | 474 | 404 | import math
n = int(eval(input()))
dic = {}
def twoKimuawaseSum(num):
result = 0
for i in range(1, num):
result += i
return result
for i in range(n):
string = eval(input())
sortStr = "".join(sorted(string))
if sortStr in dic:
dic[sortStr] += 1
else:
dic[sortStr] = 1
sum = 0
for num in list(dic.values()):
if num == 1:
sum += 0
else:
sum += twoKimuawaseSum(num)
print((math.floor(sum)))
| import itertools
import math
from scipy.misc import comb
n = int(eval(input()))
dic = {}
for i in range(n):
string = eval(input())
sortStr = "".join(sorted(string))
if sortStr in dic:
dic[sortStr] += 1
else:
dic[sortStr] = 1
sum = 0
for num in list(dic.values()):
if num == 1:
sum += 0
else:
sum += comb(num, 2, exact=True)
print((math.floor(sum)))
| false | 25.925926 | [
"+import itertools",
"+from scipy.misc import comb",
"-",
"-",
"-def twoKimuawaseSum(num):",
"- result = 0",
"- for i in range(1, num):",
"- result += i",
"- return result",
"-",
"-",
"- sum += twoKimuawaseSum(num)",
"+ sum += comb(num, 2, exact=True)"
] | false | 0.036832 | 0.747349 | 0.049284 | [
"s904459920",
"s292892596"
] |
u133936772 | p02714 | python | s066817222 | s954027099 | 1,564 | 756 | 9,144 | 9,184 | Accepted | Accepted | 51.66 | n,s=open(0);n=int(n);c=s.count;print((c('R')*c('G')*c('B')-sum(len(set(s[i:j+1:j-i>>1]))>2for i in range(n)for j in range(i+2,n,2)))) | n,s=open(0);n=int(n);c=s.count;print((c('R')*c('G')*c('B')-sum(s[i]!=s[j]!=s[i+j>>1]!=s[i]for i in range(n)for j in range(i+2,n,2)))) | 1 | 1 | 131 | 131 | n, s = open(0)
n = int(n)
c = s.count
print(
(
c("R") * c("G") * c("B")
- sum(
len(set(s[i : j + 1 : j - i >> 1])) > 2
for i in range(n)
for j in range(i + 2, n, 2)
)
)
)
| n, s = open(0)
n = int(n)
c = s.count
print(
(
c("R") * c("G") * c("B")
- sum(
s[i] != s[j] != s[i + j >> 1] != s[i]
for i in range(n)
for j in range(i + 2, n, 2)
)
)
)
| false | 0 | [
"- len(set(s[i : j + 1 : j - i >> 1])) > 2",
"+ s[i] != s[j] != s[i + j >> 1] != s[i]"
] | false | 0.037494 | 0.037439 | 1.001476 | [
"s066817222",
"s954027099"
] |
u729133443 | p03657 | python | s704659544 | s248407145 | 160 | 27 | 38,384 | 9,008 | Accepted | Accepted | 83.12 | a,b=list(map(int,input().split()));print((('Imp'*((a%3 and b%3 and(a+b)%3)>0)or'P')+'ossible')) | print(((eval(input().replace(*' *'))%3%2*'Imp'or'P')+'ossible')) | 1 | 1 | 87 | 62 | a, b = list(map(int, input().split()))
print((("Imp" * ((a % 3 and b % 3 and (a + b) % 3) > 0) or "P") + "ossible"))
| print(((eval(input().replace(*" *")) % 3 % 2 * "Imp" or "P") + "ossible"))
| false | 0 | [
"-a, b = list(map(int, input().split()))",
"-print(((\"Imp\" * ((a % 3 and b % 3 and (a + b) % 3) > 0) or \"P\") + \"ossible\"))",
"+print(((eval(input().replace(*\" *\")) % 3 % 2 * \"Imp\" or \"P\") + \"ossible\"))"
] | false | 0.118767 | 0.037822 | 3.140128 | [
"s704659544",
"s248407145"
] |
u222668979 | p03111 | python | s870640710 | s192595705 | 208 | 185 | 78,016 | 77,652 | Accepted | Accepted | 11.06 | from itertools import product
def solve(NUM, LIST):
lst = [l[i] for i, t in enumerate(LIST) if t == NUM]
if len(lst) == 0:
return 10 ** 5
ANS = (len(lst) - 1) * 10
ANS += abs(sum(lst) - tgt[NUM])
return ANS
tgt = list(map(int, input().split()))
l = [int(eval(input())) for _ in range(tgt[0])]
ans = 10 ** 5
for pttn in product([0, 1, 2, 3], repeat=tgt[0]):
tmp = sum(solve(i + 1, pttn) for i in range(3))
ans = min(ans, tmp)
print(ans)
| from itertools import product
def solve(T, PTTN):
lst = [l[i] for i, t in enumerate(PTTN) if t == T]
if lst:
ANS = (len(lst) - 1) * 10
ANS += abs(sum(lst) - tgt[T])
return ANS
return 10 ** 5
tgt = list(map(int, input().split()))
l = [int(eval(input())) for _ in range(tgt[0])]
ans = 10 ** 5
for pttn in product([0, 1, 2, 3], repeat=tgt[0]):
tmp = sum(solve(i + 1, pttn) for i in range(3))
ans = min(ans, tmp)
print(ans)
| 18 | 20 | 486 | 482 | from itertools import product
def solve(NUM, LIST):
lst = [l[i] for i, t in enumerate(LIST) if t == NUM]
if len(lst) == 0:
return 10**5
ANS = (len(lst) - 1) * 10
ANS += abs(sum(lst) - tgt[NUM])
return ANS
tgt = list(map(int, input().split()))
l = [int(eval(input())) for _ in range(tgt[0])]
ans = 10**5
for pttn in product([0, 1, 2, 3], repeat=tgt[0]):
tmp = sum(solve(i + 1, pttn) for i in range(3))
ans = min(ans, tmp)
print(ans)
| from itertools import product
def solve(T, PTTN):
lst = [l[i] for i, t in enumerate(PTTN) if t == T]
if lst:
ANS = (len(lst) - 1) * 10
ANS += abs(sum(lst) - tgt[T])
return ANS
return 10**5
tgt = list(map(int, input().split()))
l = [int(eval(input())) for _ in range(tgt[0])]
ans = 10**5
for pttn in product([0, 1, 2, 3], repeat=tgt[0]):
tmp = sum(solve(i + 1, pttn) for i in range(3))
ans = min(ans, tmp)
print(ans)
| false | 10 | [
"-def solve(NUM, LIST):",
"- lst = [l[i] for i, t in enumerate(LIST) if t == NUM]",
"- if len(lst) == 0:",
"- return 10**5",
"- ANS = (len(lst) - 1) * 10",
"- ANS += abs(sum(lst) - tgt[NUM])",
"- return ANS",
"+def solve(T, PTTN):",
"+ lst = [l[i] for i, t in enumerate(PTTN) if t == T]",
"+ if lst:",
"+ ANS = (len(lst) - 1) * 10",
"+ ANS += abs(sum(lst) - tgt[T])",
"+ return ANS",
"+ return 10**5"
] | false | 0.287914 | 0.496692 | 0.579662 | [
"s870640710",
"s192595705"
] |
u104171359 | p02384 | python | s018134608 | s720248100 | 30 | 20 | 7,764 | 7,836 | Accepted | Accepted | 33.33 | #!usr/bin/env python3
import sys
class Die:
def __init__(self, pips):
self.pips = pips
def move_die(self, direction):
if direction == 'N':
tmp = self.pips[0]
self.pips[0] = self.pips[1]
self.pips[1] = self.pips[5]
self.pips[5] = self.pips[4]
self.pips[4] = tmp
del tmp
elif direction == 'S':
tmp = self.pips[0]
self.pips[0] = self.pips[4]
self.pips[4] = self.pips[5]
self.pips[5] = self.pips[1]
self.pips[1] = tmp
del tmp
elif direction == 'E':
tmp = self.pips[0]
self.pips[0] = self.pips[3]
self.pips[3] = self.pips[5]
self.pips[5] = self.pips[2]
self.pips[2] = tmp
del tmp
elif direction == 'W':
tmp = self.pips[0]
self.pips[0] = self.pips[2]
self.pips[2] = self.pips[5]
self.pips[5] = self.pips[3]
self.pips[3] = tmp
del tmp
def spin_die_clockwise(self):
tmp = self.pips[1]
self.pips[1] = self.pips[2]
self.pips[2] = self.pips[4]
self.pips[4] = self.pips[3]
self.pips[3] = tmp
del tmp
def get_upside(self):
return self.pips[0]
def get_frontside(self):
return self.pips[1]
def get_rightside(self):
return self.pips[2]
def init_die():
pips = [int(pip) for pip in sys.stdin.readline().strip('\n').split()]
die = Die(pips)
return die
def roll_die(die):
directions = list(sys.stdin.readline().strip('\n'))
for direction in directions:
die.move_die(direction)
return die
def question_rightside(die):
q = int(sys.stdin.readline().strip('\n'))
for question in range(q):
q_pips = [int(pip) for pip in sys.stdin.readline().strip('\n').split()]
if q_pips[0] == die.pips[1]:
die.move_die('N')
elif q_pips[0] == die.pips[2]:
die.move_die('W')
elif q_pips[0] == die.pips[3]:
die.move_die('E')
elif q_pips[0] == die.pips[4]:
die.move_die('S')
elif q_pips[0] == die.pips[5]:
die.move_die('N')
die.move_die('N')
while die.get_frontside() != q_pips[1]:
die.spin_die_clockwise()
print((die.get_rightside()))
def main():
die = init_die()
question_rightside(die)
if __name__ == '__main__':
main() | #!usr/bin/env python3
import sys
class Die:
def __init__(self, pips):
self.pips = pips
def move_die(self, direction):
if direction == 'N':
tmp = self.pips[0]
self.pips[0] = self.pips[1]
self.pips[1] = self.pips[5]
self.pips[5] = self.pips[4]
self.pips[4] = tmp
del tmp
elif direction == 'S':
tmp = self.pips[0]
self.pips[0] = self.pips[4]
self.pips[4] = self.pips[5]
self.pips[5] = self.pips[1]
self.pips[1] = tmp
del tmp
elif direction == 'E':
tmp = self.pips[0]
self.pips[0] = self.pips[3]
self.pips[3] = self.pips[5]
self.pips[5] = self.pips[2]
self.pips[2] = tmp
del tmp
elif direction == 'W':
tmp = self.pips[0]
self.pips[0] = self.pips[2]
self.pips[2] = self.pips[5]
self.pips[5] = self.pips[3]
self.pips[3] = tmp
del tmp
def spin_die_clockwise(self):
tmp = self.pips[1]
self.pips[1] = self.pips[2]
self.pips[2] = self.pips[4]
self.pips[4] = self.pips[3]
self.pips[3] = tmp
del tmp
def init_die():
pips = [int(pip) for pip in sys.stdin.readline().strip('\n').split()]
die = Die(pips)
return die
def roll_die(die):
directions = list(sys.stdin.readline().strip('\n'))
for direction in directions:
die.move_die(direction)
return die
def question_rightside(die):
q = int(sys.stdin.readline().strip('\n'))
for question in range(q):
q_pips = [int(pip) for pip in sys.stdin.readline().strip('\n').split()]
if q_pips[0] == die.pips[1]:
die.move_die('N')
elif q_pips[0] == die.pips[2]:
die.move_die('W')
elif q_pips[0] == die.pips[3]:
die.move_die('E')
elif q_pips[0] == die.pips[4]:
die.move_die('S')
elif q_pips[0] == die.pips[5]:
die.move_die('N')
die.move_die('N')
while die.pips[1] != q_pips[1]:
die.spin_die_clockwise()
print((die.pips[2]))
def main():
die = init_die()
question_rightside(die)
if __name__ == '__main__':
main() | 104 | 95 | 2,628 | 2,432 | #!usr/bin/env python3
import sys
class Die:
def __init__(self, pips):
self.pips = pips
def move_die(self, direction):
if direction == "N":
tmp = self.pips[0]
self.pips[0] = self.pips[1]
self.pips[1] = self.pips[5]
self.pips[5] = self.pips[4]
self.pips[4] = tmp
del tmp
elif direction == "S":
tmp = self.pips[0]
self.pips[0] = self.pips[4]
self.pips[4] = self.pips[5]
self.pips[5] = self.pips[1]
self.pips[1] = tmp
del tmp
elif direction == "E":
tmp = self.pips[0]
self.pips[0] = self.pips[3]
self.pips[3] = self.pips[5]
self.pips[5] = self.pips[2]
self.pips[2] = tmp
del tmp
elif direction == "W":
tmp = self.pips[0]
self.pips[0] = self.pips[2]
self.pips[2] = self.pips[5]
self.pips[5] = self.pips[3]
self.pips[3] = tmp
del tmp
def spin_die_clockwise(self):
tmp = self.pips[1]
self.pips[1] = self.pips[2]
self.pips[2] = self.pips[4]
self.pips[4] = self.pips[3]
self.pips[3] = tmp
del tmp
def get_upside(self):
return self.pips[0]
def get_frontside(self):
return self.pips[1]
def get_rightside(self):
return self.pips[2]
def init_die():
pips = [int(pip) for pip in sys.stdin.readline().strip("\n").split()]
die = Die(pips)
return die
def roll_die(die):
directions = list(sys.stdin.readline().strip("\n"))
for direction in directions:
die.move_die(direction)
return die
def question_rightside(die):
q = int(sys.stdin.readline().strip("\n"))
for question in range(q):
q_pips = [int(pip) for pip in sys.stdin.readline().strip("\n").split()]
if q_pips[0] == die.pips[1]:
die.move_die("N")
elif q_pips[0] == die.pips[2]:
die.move_die("W")
elif q_pips[0] == die.pips[3]:
die.move_die("E")
elif q_pips[0] == die.pips[4]:
die.move_die("S")
elif q_pips[0] == die.pips[5]:
die.move_die("N")
die.move_die("N")
while die.get_frontside() != q_pips[1]:
die.spin_die_clockwise()
print((die.get_rightside()))
def main():
die = init_die()
question_rightside(die)
if __name__ == "__main__":
main()
| #!usr/bin/env python3
import sys
class Die:
def __init__(self, pips):
self.pips = pips
def move_die(self, direction):
if direction == "N":
tmp = self.pips[0]
self.pips[0] = self.pips[1]
self.pips[1] = self.pips[5]
self.pips[5] = self.pips[4]
self.pips[4] = tmp
del tmp
elif direction == "S":
tmp = self.pips[0]
self.pips[0] = self.pips[4]
self.pips[4] = self.pips[5]
self.pips[5] = self.pips[1]
self.pips[1] = tmp
del tmp
elif direction == "E":
tmp = self.pips[0]
self.pips[0] = self.pips[3]
self.pips[3] = self.pips[5]
self.pips[5] = self.pips[2]
self.pips[2] = tmp
del tmp
elif direction == "W":
tmp = self.pips[0]
self.pips[0] = self.pips[2]
self.pips[2] = self.pips[5]
self.pips[5] = self.pips[3]
self.pips[3] = tmp
del tmp
def spin_die_clockwise(self):
tmp = self.pips[1]
self.pips[1] = self.pips[2]
self.pips[2] = self.pips[4]
self.pips[4] = self.pips[3]
self.pips[3] = tmp
del tmp
def init_die():
pips = [int(pip) for pip in sys.stdin.readline().strip("\n").split()]
die = Die(pips)
return die
def roll_die(die):
directions = list(sys.stdin.readline().strip("\n"))
for direction in directions:
die.move_die(direction)
return die
def question_rightside(die):
q = int(sys.stdin.readline().strip("\n"))
for question in range(q):
q_pips = [int(pip) for pip in sys.stdin.readline().strip("\n").split()]
if q_pips[0] == die.pips[1]:
die.move_die("N")
elif q_pips[0] == die.pips[2]:
die.move_die("W")
elif q_pips[0] == die.pips[3]:
die.move_die("E")
elif q_pips[0] == die.pips[4]:
die.move_die("S")
elif q_pips[0] == die.pips[5]:
die.move_die("N")
die.move_die("N")
while die.pips[1] != q_pips[1]:
die.spin_die_clockwise()
print((die.pips[2]))
def main():
die = init_die()
question_rightside(die)
if __name__ == "__main__":
main()
| false | 8.653846 | [
"- def get_upside(self):",
"- return self.pips[0]",
"-",
"- def get_frontside(self):",
"- return self.pips[1]",
"-",
"- def get_rightside(self):",
"- return self.pips[2]",
"-",
"- while die.get_frontside() != q_pips[1]:",
"+ while die.pips[1] != q_pips[1]:",
"- print((die.get_rightside()))",
"+ print((die.pips[2]))"
] | false | 0.041117 | 0.044978 | 0.91414 | [
"s018134608",
"s720248100"
] |
u608088992 | p02757 | python | s801657371 | s428087632 | 494 | 327 | 5,412 | 10,040 | Accepted | Accepted | 33.81 | import sys
def solve():
input = sys.stdin.readline
N, P = list(map(int, input().split()))
S = list(input().strip("\n"))
if P == 2 or P == 5:
count = 0
for i in range(N):
s = int(S[N - 1 - i])
if s % P == 0: count += N - i
print(count)
else:
modDict = dict()
modDict[0] = 1
sSum = 0
for i in range(N):
s = int(S[N - 1 - i])
sSum += s * pow(10, i, P)
sSum %= P
if sSum in modDict: modDict[sSum] += 1
else: modDict[sSum] = 1
count = 0
for key in modDict:
count += modDict[key] * (modDict[key] - 1) // 2
print(count)
return 0
if __name__ == "__main__":
solve() | import sys
from collections import defaultdict
def solve():
input = sys.stdin.readline
N, P = list(map(int, input().split()))
S = input().strip("\n")
modSum = 0
modDict = defaultdict(int)
modDict[0] += 1
ans = 0
if P == 2 or P == 5:
for i in range(N):
if int(S[i]) % P == 0:
ans += i + 1
else:
for i in range(N):
modSum += int(S[N-i-1]) * pow(10, i, P)
modSum %= P
modDict[modSum] += 1
for key in modDict:
v = modDict[key]
ans += v * (v - 1) // 2
print(ans)
return 0
if __name__ == "__main__":
solve() | 33 | 33 | 803 | 706 | import sys
def solve():
input = sys.stdin.readline
N, P = list(map(int, input().split()))
S = list(input().strip("\n"))
if P == 2 or P == 5:
count = 0
for i in range(N):
s = int(S[N - 1 - i])
if s % P == 0:
count += N - i
print(count)
else:
modDict = dict()
modDict[0] = 1
sSum = 0
for i in range(N):
s = int(S[N - 1 - i])
sSum += s * pow(10, i, P)
sSum %= P
if sSum in modDict:
modDict[sSum] += 1
else:
modDict[sSum] = 1
count = 0
for key in modDict:
count += modDict[key] * (modDict[key] - 1) // 2
print(count)
return 0
if __name__ == "__main__":
solve()
| import sys
from collections import defaultdict
def solve():
input = sys.stdin.readline
N, P = list(map(int, input().split()))
S = input().strip("\n")
modSum = 0
modDict = defaultdict(int)
modDict[0] += 1
ans = 0
if P == 2 or P == 5:
for i in range(N):
if int(S[i]) % P == 0:
ans += i + 1
else:
for i in range(N):
modSum += int(S[N - i - 1]) * pow(10, i, P)
modSum %= P
modDict[modSum] += 1
for key in modDict:
v = modDict[key]
ans += v * (v - 1) // 2
print(ans)
return 0
if __name__ == "__main__":
solve()
| false | 0 | [
"+from collections import defaultdict",
"- S = list(input().strip(\"\\n\"))",
"+ S = input().strip(\"\\n\")",
"+ modSum = 0",
"+ modDict = defaultdict(int)",
"+ modDict[0] += 1",
"+ ans = 0",
"- count = 0",
"- s = int(S[N - 1 - i])",
"- if s % P == 0:",
"- count += N - i",
"- print(count)",
"+ if int(S[i]) % P == 0:",
"+ ans += i + 1",
"- modDict = dict()",
"- modDict[0] = 1",
"- sSum = 0",
"- s = int(S[N - 1 - i])",
"- sSum += s * pow(10, i, P)",
"- sSum %= P",
"- if sSum in modDict:",
"- modDict[sSum] += 1",
"- else:",
"- modDict[sSum] = 1",
"- count = 0",
"+ modSum += int(S[N - i - 1]) * pow(10, i, P)",
"+ modSum %= P",
"+ modDict[modSum] += 1",
"- count += modDict[key] * (modDict[key] - 1) // 2",
"- print(count)",
"+ v = modDict[key]",
"+ ans += v * (v - 1) // 2",
"+ print(ans)"
] | false | 0.037115 | 0.072057 | 0.515078 | [
"s801657371",
"s428087632"
] |
u057109575 | p03212 | python | s089666695 | s041806767 | 228 | 150 | 43,624 | 76,368 | Accepted | Accepted | 34.21 | N = int(eval(input()))
def dfs(value, use):
if int(value) > N:
return 0
res = int(use == 0b111)
res += dfs(value + "7", use | 0b001)
res += dfs(value + "5", use | 0b010)
res += dfs(value + "3", use | 0b100)
return res
print((dfs("0", 0)))
|
N = int(eval(input()))
def dfs(s):
if int(s) > N:
return 0
res = 1 if all(s.count(c) > 0 for c in "357") else 0
for c in "357":
res += dfs(s + c)
return res
print((dfs("0")))
| 14 | 15 | 280 | 219 | N = int(eval(input()))
def dfs(value, use):
if int(value) > N:
return 0
res = int(use == 0b111)
res += dfs(value + "7", use | 0b001)
res += dfs(value + "5", use | 0b010)
res += dfs(value + "3", use | 0b100)
return res
print((dfs("0", 0)))
| N = int(eval(input()))
def dfs(s):
if int(s) > N:
return 0
res = 1 if all(s.count(c) > 0 for c in "357") else 0
for c in "357":
res += dfs(s + c)
return res
print((dfs("0")))
| false | 6.666667 | [
"-def dfs(value, use):",
"- if int(value) > N:",
"+def dfs(s):",
"+ if int(s) > N:",
"- res = int(use == 0b111)",
"- res += dfs(value + \"7\", use | 0b001)",
"- res += dfs(value + \"5\", use | 0b010)",
"- res += dfs(value + \"3\", use | 0b100)",
"+ res = 1 if all(s.count(c) > 0 for c in \"357\") else 0",
"+ for c in \"357\":",
"+ res += dfs(s + c)",
"-print((dfs(\"0\", 0)))",
"+print((dfs(\"0\")))"
] | false | 0.115539 | 0.147972 | 0.780817 | [
"s089666695",
"s041806767"
] |
u946424121 | p02923 | python | s048298747 | s351900912 | 89 | 67 | 14,528 | 14,252 | Accepted | Accepted | 24.72 | from itertools import groupby
n = int(eval(input()))
h = list(map(int,input().split()))
h_diff = []
for i in range(len(h)-1):
h_diff.append(h[i+1] - h[i])
result = [sum(item) for val, item in groupby([1 if x > 0 else -1 for x in h_diff])] + [0]
print((-min(result))) | ##模範を受けて自分で書いてみる
n = int(eval(input()))
h = list(map(int,input().split()))
cnt = 0 #移動できる分のカウンター
cnt_list =[] #移動できた分を格納しておくカウンター
for i in range(0,len(h)-1):
if h[i] >= h[i+1]:
cnt += 1 #移動できる場合はカウンターに+1
else:
cnt_list.append(cnt) #移動できなくなったら、リストに保存。カウンターを元に戻す。
cnt = 0
cnt_list.append(cnt)
print((max(cnt_list))) | 10 | 14 | 277 | 352 | from itertools import groupby
n = int(eval(input()))
h = list(map(int, input().split()))
h_diff = []
for i in range(len(h) - 1):
h_diff.append(h[i + 1] - h[i])
result = [sum(item) for val, item in groupby([1 if x > 0 else -1 for x in h_diff])] + [
0
]
print((-min(result)))
| ##模範を受けて自分で書いてみる
n = int(eval(input()))
h = list(map(int, input().split()))
cnt = 0 # 移動できる分のカウンター
cnt_list = [] # 移動できた分を格納しておくカウンター
for i in range(0, len(h) - 1):
if h[i] >= h[i + 1]:
cnt += 1 # 移動できる場合はカウンターに+1
else:
cnt_list.append(cnt) # 移動できなくなったら、リストに保存。カウンターを元に戻す。
cnt = 0
cnt_list.append(cnt)
print((max(cnt_list)))
| false | 28.571429 | [
"-from itertools import groupby",
"-",
"+##模範を受けて自分で書いてみる",
"-h_diff = []",
"-for i in range(len(h) - 1):",
"- h_diff.append(h[i + 1] - h[i])",
"-result = [sum(item) for val, item in groupby([1 if x > 0 else -1 for x in h_diff])] + [",
"- 0",
"-]",
"-print((-min(result)))",
"+cnt = 0 # 移動できる分のカウンター",
"+cnt_list = [] # 移動できた分を格納しておくカウンター",
"+for i in range(0, len(h) - 1):",
"+ if h[i] >= h[i + 1]:",
"+ cnt += 1 # 移動できる場合はカウンターに+1",
"+ else:",
"+ cnt_list.append(cnt) # 移動できなくなったら、リストに保存。カウンターを元に戻す。",
"+ cnt = 0",
"+cnt_list.append(cnt)",
"+print((max(cnt_list)))"
] | false | 0.04431 | 0.074824 | 0.592192 | [
"s048298747",
"s351900912"
] |
u729133443 | p02791 | python | s816486240 | s394052115 | 241 | 134 | 65,904 | 17,808 | Accepted | Accepted | 44.4 | _,p=open(0)
m=10**18
c=0
for p in map(int,p.split()):
c+=p<m
m=min(m,p)
print(c) | _,p=open(0)
m=9e9
c=0
for p in map(int,p.split()):c+=p<m;m=min(m,p)
print(c) | 7 | 5 | 94 | 80 | _, p = open(0)
m = 10**18
c = 0
for p in map(int, p.split()):
c += p < m
m = min(m, p)
print(c)
| _, p = open(0)
m = 9e9
c = 0
for p in map(int, p.split()):
c += p < m
m = min(m, p)
print(c)
| false | 28.571429 | [
"-m = 10**18",
"+m = 9e9"
] | false | 0.052594 | 0.056767 | 0.926499 | [
"s816486240",
"s394052115"
] |
u991567869 | p02678 | python | s263257297 | s331609631 | 691 | 388 | 35,044 | 34,548 | Accepted | Accepted | 43.85 | from collections import deque
n, m = list(map(int, input().split()))
rooms = [[] for i in range(n + 1)] #直接行ける部屋を記録
for i in range(m):
a, b = list(map(int, input().split()))
rooms[a].append(b)
rooms[b].append(a)
route = [-1]*(n + 1)
route[1] = 0
q = deque()
q.append(1)
while q:
v = q.popleft()
for i in rooms[v]:
if route[i] == -1:
route[i] = v
q.append(i)
print("Yes")
for i in route[2:]:
print(i) | from collections import deque
import sys
input = sys.stdin.readline
def main():
N, M = list(map(int, input().split()))
R = [[] for i in range(N + 1)]
for i in range(M):
A, B = list(map(int, input().split()))
R[A].append(B)
R[B].append(A)
P = [-1] * (N + 1)
P[1] = 0
Q = deque()
Q.append(1)
while Q:
v = Q.popleft()
for r in R[v]:
if P[r] == -1:
P[r] = v
Q.append(r)
print('Yes')
for p in P[2:]:
print(p)
main() | 26 | 28 | 474 | 561 | from collections import deque
n, m = list(map(int, input().split()))
rooms = [[] for i in range(n + 1)] # 直接行ける部屋を記録
for i in range(m):
a, b = list(map(int, input().split()))
rooms[a].append(b)
rooms[b].append(a)
route = [-1] * (n + 1)
route[1] = 0
q = deque()
q.append(1)
while q:
v = q.popleft()
for i in rooms[v]:
if route[i] == -1:
route[i] = v
q.append(i)
print("Yes")
for i in route[2:]:
print(i)
| from collections import deque
import sys
input = sys.stdin.readline
def main():
N, M = list(map(int, input().split()))
R = [[] for i in range(N + 1)]
for i in range(M):
A, B = list(map(int, input().split()))
R[A].append(B)
R[B].append(A)
P = [-1] * (N + 1)
P[1] = 0
Q = deque()
Q.append(1)
while Q:
v = Q.popleft()
for r in R[v]:
if P[r] == -1:
P[r] = v
Q.append(r)
print("Yes")
for p in P[2:]:
print(p)
main()
| false | 7.142857 | [
"+import sys",
"-n, m = list(map(int, input().split()))",
"-rooms = [[] for i in range(n + 1)] # 直接行ける部屋を記録",
"-for i in range(m):",
"- a, b = list(map(int, input().split()))",
"- rooms[a].append(b)",
"- rooms[b].append(a)",
"-route = [-1] * (n + 1)",
"-route[1] = 0",
"-q = deque()",
"-q.append(1)",
"-while q:",
"- v = q.popleft()",
"- for i in rooms[v]:",
"- if route[i] == -1:",
"- route[i] = v",
"- q.append(i)",
"-print(\"Yes\")",
"-for i in route[2:]:",
"- print(i)",
"+input = sys.stdin.readline",
"+",
"+",
"+def main():",
"+ N, M = list(map(int, input().split()))",
"+ R = [[] for i in range(N + 1)]",
"+ for i in range(M):",
"+ A, B = list(map(int, input().split()))",
"+ R[A].append(B)",
"+ R[B].append(A)",
"+ P = [-1] * (N + 1)",
"+ P[1] = 0",
"+ Q = deque()",
"+ Q.append(1)",
"+ while Q:",
"+ v = Q.popleft()",
"+ for r in R[v]:",
"+ if P[r] == -1:",
"+ P[r] = v",
"+ Q.append(r)",
"+ print(\"Yes\")",
"+ for p in P[2:]:",
"+ print(p)",
"+",
"+",
"+main()"
] | false | 0.041724 | 0.07715 | 0.540813 | [
"s263257297",
"s331609631"
] |
u590825760 | p02779 | python | s254493308 | s141605121 | 281 | 100 | 25,172 | 25,172 | Accepted | Accepted | 64.41 | n = int(eval(input()))
li = [int(x) for x in input().split()]
nozoki = sorted(list(set(li)))
li.sort()
if (nozoki == li):
print("YES")
else:
print("NO") | n = int(eval(input()))
li = [int(x) for x in input().split()]
a = len(li)
se = set(li)
b = len(se)
if (a==b):
print("YES")
else:
print("NO") | 9 | 9 | 163 | 150 | n = int(eval(input()))
li = [int(x) for x in input().split()]
nozoki = sorted(list(set(li)))
li.sort()
if nozoki == li:
print("YES")
else:
print("NO")
| n = int(eval(input()))
li = [int(x) for x in input().split()]
a = len(li)
se = set(li)
b = len(se)
if a == b:
print("YES")
else:
print("NO")
| false | 0 | [
"-nozoki = sorted(list(set(li)))",
"-li.sort()",
"-if nozoki == li:",
"+a = len(li)",
"+se = set(li)",
"+b = len(se)",
"+if a == b:"
] | false | 0.037023 | 0.092188 | 0.401604 | [
"s254493308",
"s141605121"
] |
u422104747 | p03329 | python | s740805379 | s748026777 | 524 | 197 | 3,956 | 44,912 | Accepted | Accepted | 62.4 | l=[100000 for i in range(100001)]
l[0]=0
dif=[1,6,9,36,81,216,729,1296,6561,7776,46656,59049]
for i in range(1,100001):
for j in dif:
if j>i:
break
l[i]=min(l[i],l[i-j]+1)
n=int(eval(input()))
print((l[n])) | dp=[100000 for i in range(100001)]
dp[0]=0
l=[1]
i=6
while i<=100000:
l.append(i)
i*=6
i=9
while i<=100000:
l.append(i)
i*=9
for i in range(1,100001):
for j in l:
if j<=i and dp[i-j]+1<dp[i]:
dp[i]=dp[i-j]+1
print((dp[int(eval(input()))]))
| 10 | 16 | 215 | 287 | l = [100000 for i in range(100001)]
l[0] = 0
dif = [1, 6, 9, 36, 81, 216, 729, 1296, 6561, 7776, 46656, 59049]
for i in range(1, 100001):
for j in dif:
if j > i:
break
l[i] = min(l[i], l[i - j] + 1)
n = int(eval(input()))
print((l[n]))
| dp = [100000 for i in range(100001)]
dp[0] = 0
l = [1]
i = 6
while i <= 100000:
l.append(i)
i *= 6
i = 9
while i <= 100000:
l.append(i)
i *= 9
for i in range(1, 100001):
for j in l:
if j <= i and dp[i - j] + 1 < dp[i]:
dp[i] = dp[i - j] + 1
print((dp[int(eval(input()))]))
| false | 37.5 | [
"-l = [100000 for i in range(100001)]",
"-l[0] = 0",
"-dif = [1, 6, 9, 36, 81, 216, 729, 1296, 6561, 7776, 46656, 59049]",
"+dp = [100000 for i in range(100001)]",
"+dp[0] = 0",
"+l = [1]",
"+i = 6",
"+while i <= 100000:",
"+ l.append(i)",
"+ i *= 6",
"+i = 9",
"+while i <= 100000:",
"+ l.append(i)",
"+ i *= 9",
"- for j in dif:",
"- if j > i:",
"- break",
"- l[i] = min(l[i], l[i - j] + 1)",
"-n = int(eval(input()))",
"-print((l[n]))",
"+ for j in l:",
"+ if j <= i and dp[i - j] + 1 < dp[i]:",
"+ dp[i] = dp[i - j] + 1",
"+print((dp[int(eval(input()))]))"
] | false | 1.122667 | 0.789326 | 1.422311 | [
"s740805379",
"s748026777"
] |
u077291787 | p03761 | python | s174244822 | s341163880 | 25 | 20 | 3,768 | 3,060 | Accepted | Accepted | 20 | # ABC058C - 怪文書 / Dubious Document (ARC071C)
from string import ascii_lowercase
def main():
N = int(eval(input()))
S = tuple(eval(input()) for _ in range(N))
ans = ""
for i in ascii_lowercase:
if all(i in s for s in S):
ans += i * min(s.count(i) for s in S)
print(ans)
if __name__ == "__main__":
main() | # ABC058C - 怪文書 / Dubious Document (ARC071C)
def main():
N = int(eval(input()))
S = tuple(eval(input()) for _ in range(N))
ans = ""
for i in "abcdefghijklmnopqrstuvwxyz":
if all(i in s for s in S):
ans += i * min(s.count(i) for s in S)
print(ans)
if __name__ == "__main__":
main() | 16 | 13 | 353 | 326 | # ABC058C - 怪文書 / Dubious Document (ARC071C)
from string import ascii_lowercase
def main():
N = int(eval(input()))
S = tuple(eval(input()) for _ in range(N))
ans = ""
for i in ascii_lowercase:
if all(i in s for s in S):
ans += i * min(s.count(i) for s in S)
print(ans)
if __name__ == "__main__":
main()
| # ABC058C - 怪文書 / Dubious Document (ARC071C)
def main():
N = int(eval(input()))
S = tuple(eval(input()) for _ in range(N))
ans = ""
for i in "abcdefghijklmnopqrstuvwxyz":
if all(i in s for s in S):
ans += i * min(s.count(i) for s in S)
print(ans)
if __name__ == "__main__":
main()
| false | 18.75 | [
"-from string import ascii_lowercase",
"-",
"-",
"- for i in ascii_lowercase:",
"+ for i in \"abcdefghijklmnopqrstuvwxyz\":"
] | false | 0.054871 | 0.047559 | 1.153743 | [
"s174244822",
"s341163880"
] |
u285891772 | p02596 | python | s881398376 | s886893506 | 1,993 | 421 | 17,844 | 72,804 | Accepted | Accepted | 78.88 | 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(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10
K = INT()
tmp = 7
ans = 1
p = 1
mo = tmp%K
checked = [0]*(K+1)
checked[mo] = 1
while mo != 0:
mo += 7*pow(10, p, K)
mo %= K
p += 1
if checked[mo]:
print((-1))
break
checked[mo] = 1
else:
print(p)
| 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(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10
K = INT()
a = 0
for i in range(K):
a = (a+7*pow(10, i, K))%K
if a == 0:
print((i+1))
break
else:
print((-1))
| 42 | 35 | 1,223 | 1,127 | 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(int, input().split()))
def TUPLE():
return tuple(map(int, input().split()))
def ZIP(n):
return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
# mod = 998244353
from decimal import *
# import numpy as np
# decimal.getcontext().prec = 10
K = INT()
tmp = 7
ans = 1
p = 1
mo = tmp % K
checked = [0] * (K + 1)
checked[mo] = 1
while mo != 0:
mo += 7 * pow(10, p, K)
mo %= K
p += 1
if checked[mo]:
print((-1))
break
checked[mo] = 1
else:
print(p)
| 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(int, input().split()))
def TUPLE():
return tuple(map(int, input().split()))
def ZIP(n):
return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
# mod = 998244353
from decimal import *
# import numpy as np
# decimal.getcontext().prec = 10
K = INT()
a = 0
for i in range(K):
a = (a + 7 * pow(10, i, K)) % K
if a == 0:
print((i + 1))
break
else:
print((-1))
| false | 16.666667 | [
"-tmp = 7",
"-ans = 1",
"-p = 1",
"-mo = tmp % K",
"-checked = [0] * (K + 1)",
"-checked[mo] = 1",
"-while mo != 0:",
"- mo += 7 * pow(10, p, K)",
"- mo %= K",
"- p += 1",
"- if checked[mo]:",
"- print((-1))",
"+a = 0",
"+for i in range(K):",
"+ a = (a + 7 * pow(10, i, K)) % K",
"+ if a == 0:",
"+ print((i + 1))",
"- checked[mo] = 1",
"- print(p)",
"+ print((-1))"
] | false | 0.399052 | 0.38941 | 1.02476 | [
"s881398376",
"s886893506"
] |
u597455618 | p02642 | python | s644091589 | s584853059 | 381 | 250 | 42,956 | 42,956 | Accepted | Accepted | 34.38 | from sys import stdin
n = int(eval(input()))
a = list(map(int, stdin.readline().split()))
a.sort()
amax = max(a)+1
e = [True]*amax
Alice = set()
Bob = set()
ans = 0
for i in range(n):
if e[a[i]] == True:
Alice.add(a[i])
for j in range(a[i], amax, a[i]):
e[j] = False
else:
if a[i] in Alice:
Bob.add(a[i])
print((len(Alice - Bob))) | def main():
from sys import stdin
n = int(eval(input()))
a = list(map(int, stdin.readline().split()))
a.sort()
amax = max(a)+1
e = [True]*amax
Alice = set()
Bob = set()
ans = 0
for i in range(n):
if e[a[i]] == True:
Alice.add(a[i])
for j in range(a[i], amax, a[i]):
e[j] = False
else:
if a[i] in Alice:
Bob.add(a[i])
print((len(Alice - Bob)))
if __name__ == "__main__":
main() | 20 | 23 | 399 | 532 | from sys import stdin
n = int(eval(input()))
a = list(map(int, stdin.readline().split()))
a.sort()
amax = max(a) + 1
e = [True] * amax
Alice = set()
Bob = set()
ans = 0
for i in range(n):
if e[a[i]] == True:
Alice.add(a[i])
for j in range(a[i], amax, a[i]):
e[j] = False
else:
if a[i] in Alice:
Bob.add(a[i])
print((len(Alice - Bob)))
| def main():
from sys import stdin
n = int(eval(input()))
a = list(map(int, stdin.readline().split()))
a.sort()
amax = max(a) + 1
e = [True] * amax
Alice = set()
Bob = set()
ans = 0
for i in range(n):
if e[a[i]] == True:
Alice.add(a[i])
for j in range(a[i], amax, a[i]):
e[j] = False
else:
if a[i] in Alice:
Bob.add(a[i])
print((len(Alice - Bob)))
if __name__ == "__main__":
main()
| false | 13.043478 | [
"-from sys import stdin",
"+def main():",
"+ from sys import stdin",
"-n = int(eval(input()))",
"-a = list(map(int, stdin.readline().split()))",
"-a.sort()",
"-amax = max(a) + 1",
"-e = [True] * amax",
"-Alice = set()",
"-Bob = set()",
"-ans = 0",
"-for i in range(n):",
"- if e[a[i]] == True:",
"- Alice.add(a[i])",
"- for j in range(a[i], amax, a[i]):",
"- e[j] = False",
"- else:",
"- if a[i] in Alice:",
"- Bob.add(a[i])",
"-print((len(Alice - Bob)))",
"+ n = int(eval(input()))",
"+ a = list(map(int, stdin.readline().split()))",
"+ a.sort()",
"+ amax = max(a) + 1",
"+ e = [True] * amax",
"+ Alice = set()",
"+ Bob = set()",
"+ ans = 0",
"+ for i in range(n):",
"+ if e[a[i]] == True:",
"+ Alice.add(a[i])",
"+ for j in range(a[i], amax, a[i]):",
"+ e[j] = False",
"+ else:",
"+ if a[i] in Alice:",
"+ Bob.add(a[i])",
"+ print((len(Alice - Bob)))",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.03879 | 0.038076 | 1.018766 | [
"s644091589",
"s584853059"
] |
u670180528 | p03945 | python | s922380783 | s375887036 | 27 | 18 | 3,964 | 3,188 | Accepted | Accepted | 33.33 | from itertools import*;print((len([k for k,g in groupby(eval(input()))])-1)) | x=eval(input());print((x.count("WB")+x.count("BW"))) | 1 | 1 | 68 | 44 | from itertools import *
print((len([k for k, g in groupby(eval(input()))]) - 1))
| x = eval(input())
print((x.count("WB") + x.count("BW")))
| false | 0 | [
"-from itertools import *",
"-",
"-print((len([k for k, g in groupby(eval(input()))]) - 1))",
"+x = eval(input())",
"+print((x.count(\"WB\") + x.count(\"BW\")))"
] | false | 0.043414 | 0.04359 | 0.995952 | [
"s922380783",
"s375887036"
] |
u699089116 | p03200 | python | s197823850 | s155587698 | 185 | 107 | 41,180 | 12,580 | Accepted | Accepted | 42.16 | s = eval(input())
ans = 0
b_count = 0
for i,c in enumerate(s):
if c == "W":
ans += b_count
else:
b_count += 1
print(ans) | S = eval(input())
b_cumsum = [0] * len(S)
now = 0
for i in range(len(S)):
if S[i] == "B":
b_cumsum[i] = now + 1
now += 1
else:
b_cumsum[i] = now
S = S[::-1]
b_cumsum = b_cumsum[::-1]
ans = 0
for i, s in enumerate(S):
if s == "W":
ans += b_cumsum[i]
print(ans)
| 11 | 19 | 150 | 319 | s = eval(input())
ans = 0
b_count = 0
for i, c in enumerate(s):
if c == "W":
ans += b_count
else:
b_count += 1
print(ans)
| S = eval(input())
b_cumsum = [0] * len(S)
now = 0
for i in range(len(S)):
if S[i] == "B":
b_cumsum[i] = now + 1
now += 1
else:
b_cumsum[i] = now
S = S[::-1]
b_cumsum = b_cumsum[::-1]
ans = 0
for i, s in enumerate(S):
if s == "W":
ans += b_cumsum[i]
print(ans)
| false | 42.105263 | [
"-s = eval(input())",
"+S = eval(input())",
"+b_cumsum = [0] * len(S)",
"+now = 0",
"+for i in range(len(S)):",
"+ if S[i] == \"B\":",
"+ b_cumsum[i] = now + 1",
"+ now += 1",
"+ else:",
"+ b_cumsum[i] = now",
"+S = S[::-1]",
"+b_cumsum = b_cumsum[::-1]",
"-b_count = 0",
"-for i, c in enumerate(s):",
"- if c == \"W\":",
"- ans += b_count",
"- else:",
"- b_count += 1",
"+for i, s in enumerate(S):",
"+ if s == \"W\":",
"+ ans += b_cumsum[i]"
] | false | 0.044524 | 0.044872 | 0.992255 | [
"s197823850",
"s155587698"
] |
u674574659 | p03775 | python | s396836389 | s576237464 | 101 | 34 | 3,060 | 3,060 | Accepted | Accepted | 66.34 | N = int(eval(input()))
ans = float("inf")
c = 1
while c <= int(N**(1/2)//1):
if N%c == 0:
ans = min(ans,max(len(str(c)),len(str(N//c))))
c += 1
print(ans) | N = int(eval(input()))
ans = float("inf")
for i in range(1,int(N**(1/2)//1)+1):
if N%i == 0:
ans = min(ans,len(str(N//i)))
print(ans) | 8 | 6 | 165 | 138 | N = int(eval(input()))
ans = float("inf")
c = 1
while c <= int(N ** (1 / 2) // 1):
if N % c == 0:
ans = min(ans, max(len(str(c)), len(str(N // c))))
c += 1
print(ans)
| N = int(eval(input()))
ans = float("inf")
for i in range(1, int(N ** (1 / 2) // 1) + 1):
if N % i == 0:
ans = min(ans, len(str(N // i)))
print(ans)
| false | 25 | [
"-c = 1",
"-while c <= int(N ** (1 / 2) // 1):",
"- if N % c == 0:",
"- ans = min(ans, max(len(str(c)), len(str(N // c))))",
"- c += 1",
"+for i in range(1, int(N ** (1 / 2) // 1) + 1):",
"+ if N % i == 0:",
"+ ans = min(ans, len(str(N // i)))"
] | false | 0.073876 | 0.052446 | 1.408596 | [
"s396836389",
"s576237464"
] |
u790710233 | p03645 | python | s279485787 | s967199735 | 639 | 586 | 18,992 | 18,892 | Accepted | Accepted | 8.29 | n, m = list(map(int, input().split()))
transit_a = set()
transit_b = set()
for _ in range(m):
a, b = list(map(int, input().split()))
if a == 1:
transit_b |= {b}
elif b == n:
transit_a |= {a}
print(('POSSIBLE' if len(transit_a & transit_b) else 'IMPOSSIBLE')) | n, m = list(map(int, input().split()))
transit_a = set()
transit_b = set()
for _ in range(m):
a, b = list(map(int, input().split()))
if a == 1:
transit_b.add(b)
elif b == n:
transit_a.add(a)
print(('POSSIBLE' if len(transit_a & transit_b) else 'IMPOSSIBLE'))
| 11 | 11 | 283 | 284 | n, m = list(map(int, input().split()))
transit_a = set()
transit_b = set()
for _ in range(m):
a, b = list(map(int, input().split()))
if a == 1:
transit_b |= {b}
elif b == n:
transit_a |= {a}
print(("POSSIBLE" if len(transit_a & transit_b) else "IMPOSSIBLE"))
| n, m = list(map(int, input().split()))
transit_a = set()
transit_b = set()
for _ in range(m):
a, b = list(map(int, input().split()))
if a == 1:
transit_b.add(b)
elif b == n:
transit_a.add(a)
print(("POSSIBLE" if len(transit_a & transit_b) else "IMPOSSIBLE"))
| false | 0 | [
"- transit_b |= {b}",
"+ transit_b.add(b)",
"- transit_a |= {a}",
"+ transit_a.add(a)"
] | false | 0.038176 | 0.053466 | 0.714033 | [
"s279485787",
"s967199735"
] |
u723711163 | p02803 | python | s067891488 | s920646370 | 594 | 242 | 3,188 | 43,740 | Accepted | Accepted | 59.26 | row,col=list(map(int,input().split()))
maze=[list(eval(input())) for _ in range(row)]
result = []
def create_next_adj_list(point):
cur_x, cur_y, cur_depth = point
return [(cur_x, cur_y+1, cur_depth+1), (cur_x+1, cur_y, cur_depth+1), (cur_x, cur_y-1, cur_depth+1), (cur_x-1, cur_y, cur_depth+1)]
for r in range(row):
for c in range(col):
if maze[r][c] == '.':
visited = [ [0]*col for _ in range(row)]
visited[r][c] = -1
adj_list = [(r, c+1, 0), (r+1, c, 0), (r, c-1, 0), (r-1, c, 0)]
while adj_list:
point = adj_list.pop(0)
if 0<=point[0]<row and 0<=point[1]<col and visited[point[0]][point[1]] != -1:
visited[point[0]][point[1]] = -1
if maze[point[0]][point[1]] != '#':
for adj in create_next_adj_list(point):
adj_list.append(adj)
result.append(point[-1])
print((max(result))) | from collections import deque
H,W = list(map(int,input().split()))
maze = []
for _ in range(H):
maze.append(list(eval(input())))
res = 0
move = [(1,0),(0,1),(0,-1),(-1,0)]
for i in range(H):
for j in range(W):
if maze[i][j] == ".":
visited = [[False]*W for _ in range(H) ]
q = deque([(i,j)])
depth = -1
while q:
depth += 1
L = len(q)
new = deque([])
for _ in range(L):
i,j = q.popleft()
if visited[i][j]: continue
visited[i][j] = True
for y,x in move:
if 0<=i+y<H and 0<=j+x<W and not visited[i+y][j+x]:
if maze[i+y][j+x] == ".":
new.append((i+y,j+x))
q = new
res = max(res, depth)
print(res) | 29 | 30 | 907 | 771 | row, col = list(map(int, input().split()))
maze = [list(eval(input())) for _ in range(row)]
result = []
def create_next_adj_list(point):
cur_x, cur_y, cur_depth = point
return [
(cur_x, cur_y + 1, cur_depth + 1),
(cur_x + 1, cur_y, cur_depth + 1),
(cur_x, cur_y - 1, cur_depth + 1),
(cur_x - 1, cur_y, cur_depth + 1),
]
for r in range(row):
for c in range(col):
if maze[r][c] == ".":
visited = [[0] * col for _ in range(row)]
visited[r][c] = -1
adj_list = [(r, c + 1, 0), (r + 1, c, 0), (r, c - 1, 0), (r - 1, c, 0)]
while adj_list:
point = adj_list.pop(0)
if (
0 <= point[0] < row
and 0 <= point[1] < col
and visited[point[0]][point[1]] != -1
):
visited[point[0]][point[1]] = -1
if maze[point[0]][point[1]] != "#":
for adj in create_next_adj_list(point):
adj_list.append(adj)
result.append(point[-1])
print((max(result)))
| from collections import deque
H, W = list(map(int, input().split()))
maze = []
for _ in range(H):
maze.append(list(eval(input())))
res = 0
move = [(1, 0), (0, 1), (0, -1), (-1, 0)]
for i in range(H):
for j in range(W):
if maze[i][j] == ".":
visited = [[False] * W for _ in range(H)]
q = deque([(i, j)])
depth = -1
while q:
depth += 1
L = len(q)
new = deque([])
for _ in range(L):
i, j = q.popleft()
if visited[i][j]:
continue
visited[i][j] = True
for y, x in move:
if (
0 <= i + y < H
and 0 <= j + x < W
and not visited[i + y][j + x]
):
if maze[i + y][j + x] == ".":
new.append((i + y, j + x))
q = new
res = max(res, depth)
print(res)
| false | 3.333333 | [
"-row, col = list(map(int, input().split()))",
"-maze = [list(eval(input())) for _ in range(row)]",
"-result = []",
"+from collections import deque",
"-",
"-def create_next_adj_list(point):",
"- cur_x, cur_y, cur_depth = point",
"- return [",
"- (cur_x, cur_y + 1, cur_depth + 1),",
"- (cur_x + 1, cur_y, cur_depth + 1),",
"- (cur_x, cur_y - 1, cur_depth + 1),",
"- (cur_x - 1, cur_y, cur_depth + 1),",
"- ]",
"-",
"-",
"-for r in range(row):",
"- for c in range(col):",
"- if maze[r][c] == \".\":",
"- visited = [[0] * col for _ in range(row)]",
"- visited[r][c] = -1",
"- adj_list = [(r, c + 1, 0), (r + 1, c, 0), (r, c - 1, 0), (r - 1, c, 0)]",
"- while adj_list:",
"- point = adj_list.pop(0)",
"- if (",
"- 0 <= point[0] < row",
"- and 0 <= point[1] < col",
"- and visited[point[0]][point[1]] != -1",
"- ):",
"- visited[point[0]][point[1]] = -1",
"- if maze[point[0]][point[1]] != \"#\":",
"- for adj in create_next_adj_list(point):",
"- adj_list.append(adj)",
"- result.append(point[-1])",
"-print((max(result)))",
"+H, W = list(map(int, input().split()))",
"+maze = []",
"+for _ in range(H):",
"+ maze.append(list(eval(input())))",
"+res = 0",
"+move = [(1, 0), (0, 1), (0, -1), (-1, 0)]",
"+for i in range(H):",
"+ for j in range(W):",
"+ if maze[i][j] == \".\":",
"+ visited = [[False] * W for _ in range(H)]",
"+ q = deque([(i, j)])",
"+ depth = -1",
"+ while q:",
"+ depth += 1",
"+ L = len(q)",
"+ new = deque([])",
"+ for _ in range(L):",
"+ i, j = q.popleft()",
"+ if visited[i][j]:",
"+ continue",
"+ visited[i][j] = True",
"+ for y, x in move:",
"+ if (",
"+ 0 <= i + y < H",
"+ and 0 <= j + x < W",
"+ and not visited[i + y][j + x]",
"+ ):",
"+ if maze[i + y][j + x] == \".\":",
"+ new.append((i + y, j + x))",
"+ q = new",
"+ res = max(res, depth)",
"+print(res)"
] | false | 0.041263 | 0.040877 | 1.009446 | [
"s067891488",
"s920646370"
] |
u644907318 | p02755 | python | s375222386 | s785902339 | 188 | 64 | 38,896 | 62,188 | Accepted | Accepted | 65.96 | A,B = list(map(int,input().split()))
a1 = A/0.08
a2 = (A+1)/0.08
X = []
for i in range(13,1263):
if a1<=i<a2:
X.append(i)
b1 = B/0.1
b2 = (B+1)/0.1
x = -1
for y in X:
if b1<=y<b2:
x = y
break
print(x) | A,B = list(map(int,input().split()))
flag = 0
for i in range(1,1001):
if int(i*0.08)==A and int(i*0.1)==B:
ans = i
flag = 1
break
if flag==0:
print((-1))
else:
print(ans) | 15 | 11 | 240 | 208 | A, B = list(map(int, input().split()))
a1 = A / 0.08
a2 = (A + 1) / 0.08
X = []
for i in range(13, 1263):
if a1 <= i < a2:
X.append(i)
b1 = B / 0.1
b2 = (B + 1) / 0.1
x = -1
for y in X:
if b1 <= y < b2:
x = y
break
print(x)
| A, B = list(map(int, input().split()))
flag = 0
for i in range(1, 1001):
if int(i * 0.08) == A and int(i * 0.1) == B:
ans = i
flag = 1
break
if flag == 0:
print((-1))
else:
print(ans)
| false | 26.666667 | [
"-a1 = A / 0.08",
"-a2 = (A + 1) / 0.08",
"-X = []",
"-for i in range(13, 1263):",
"- if a1 <= i < a2:",
"- X.append(i)",
"-b1 = B / 0.1",
"-b2 = (B + 1) / 0.1",
"-x = -1",
"-for y in X:",
"- if b1 <= y < b2:",
"- x = y",
"+flag = 0",
"+for i in range(1, 1001):",
"+ if int(i * 0.08) == A and int(i * 0.1) == B:",
"+ ans = i",
"+ flag = 1",
"-print(x)",
"+if flag == 0:",
"+ print((-1))",
"+else:",
"+ print(ans)"
] | false | 0.078536 | 0.041548 | 1.890239 | [
"s375222386",
"s785902339"
] |
u526094365 | p02659 | python | s449392447 | s641004109 | 27 | 24 | 10,004 | 9,168 | Accepted | Accepted | 11.11 | from decimal import Decimal
A, B = list(map(Decimal, input().split()))
print((int(A*B)))
| A, B = list(map(str, input().split()))
A = int(A)
B = int(''.join(B.split('.')))
print((A*B//100))
| 4 | 5 | 85 | 96 | from decimal import Decimal
A, B = list(map(Decimal, input().split()))
print((int(A * B)))
| A, B = list(map(str, input().split()))
A = int(A)
B = int("".join(B.split(".")))
print((A * B // 100))
| false | 20 | [
"-from decimal import Decimal",
"-",
"-A, B = list(map(Decimal, input().split()))",
"-print((int(A * B)))",
"+A, B = list(map(str, input().split()))",
"+A = int(A)",
"+B = int(\"\".join(B.split(\".\")))",
"+print((A * B // 100))"
] | false | 0.045582 | 0.043999 | 1.035976 | [
"s449392447",
"s641004109"
] |
u814986259 | p03425 | python | s969998267 | s073961229 | 188 | 149 | 12,344 | 10,112 | Accepted | Accepted | 20.74 | import fractions
import itertools
N = int(eval(input()))
M =[]
A = []
R = []
C = []
H = []
for i in range(N):
name = eval(input())
initial = name[0]
if initial == "M":
M.append(name)
elif initial == "A":
A.append(name)
elif initial == "R":
R.append(name)
elif initial == "C":
C.append(name)
elif initial == "H":
H.append(name)
count = 0
S = []
if len(M) > 0:
S.append(len(M))
if len(A) > 0:
S.append(len(A))
if len(R) > 0:
S.append(len(R))
if len(C) > 0:
S.append(len(C))
if len(H) > 0:
S.append(len(H))
if len(S) < 3:
print("0")
exit(0)
a = itertools.combinations(S,3)
ans = 0
for x in list(a):
tmp = 1
for y in x:
tmp *= y
ans += tmp
print(ans)
| from itertools import combinations
import collections
N = int(eval(input()))
S = [eval(input()) for i in range(N)]
table = collections.defaultdict(int)
for x in S:
table[x[0]] += 1
tmp = ["M", "A", "R", "C", "H"]
ans = 0
for x in combinations(tmp, 3):
ans += table[x[0]]*table[x[1]]*table[x[2]]
print(ans)
| 53 | 16 | 812 | 321 | import fractions
import itertools
N = int(eval(input()))
M = []
A = []
R = []
C = []
H = []
for i in range(N):
name = eval(input())
initial = name[0]
if initial == "M":
M.append(name)
elif initial == "A":
A.append(name)
elif initial == "R":
R.append(name)
elif initial == "C":
C.append(name)
elif initial == "H":
H.append(name)
count = 0
S = []
if len(M) > 0:
S.append(len(M))
if len(A) > 0:
S.append(len(A))
if len(R) > 0:
S.append(len(R))
if len(C) > 0:
S.append(len(C))
if len(H) > 0:
S.append(len(H))
if len(S) < 3:
print("0")
exit(0)
a = itertools.combinations(S, 3)
ans = 0
for x in list(a):
tmp = 1
for y in x:
tmp *= y
ans += tmp
print(ans)
| from itertools import combinations
import collections
N = int(eval(input()))
S = [eval(input()) for i in range(N)]
table = collections.defaultdict(int)
for x in S:
table[x[0]] += 1
tmp = ["M", "A", "R", "C", "H"]
ans = 0
for x in combinations(tmp, 3):
ans += table[x[0]] * table[x[1]] * table[x[2]]
print(ans)
| false | 69.811321 | [
"-import fractions",
"-import itertools",
"+from itertools import combinations",
"+import collections",
"-M = []",
"-A = []",
"-R = []",
"-C = []",
"-H = []",
"-for i in range(N):",
"- name = eval(input())",
"- initial = name[0]",
"- if initial == \"M\":",
"- M.append(name)",
"- elif initial == \"A\":",
"- A.append(name)",
"- elif initial == \"R\":",
"- R.append(name)",
"- elif initial == \"C\":",
"- C.append(name)",
"- elif initial == \"H\":",
"- H.append(name)",
"-count = 0",
"-S = []",
"-if len(M) > 0:",
"- S.append(len(M))",
"-if len(A) > 0:",
"- S.append(len(A))",
"-if len(R) > 0:",
"- S.append(len(R))",
"-if len(C) > 0:",
"- S.append(len(C))",
"-if len(H) > 0:",
"- S.append(len(H))",
"-if len(S) < 3:",
"- print(\"0\")",
"- exit(0)",
"-a = itertools.combinations(S, 3)",
"+S = [eval(input()) for i in range(N)]",
"+table = collections.defaultdict(int)",
"+for x in S:",
"+ table[x[0]] += 1",
"+tmp = [\"M\", \"A\", \"R\", \"C\", \"H\"]",
"-for x in list(a):",
"- tmp = 1",
"- for y in x:",
"- tmp *= y",
"- ans += tmp",
"+for x in combinations(tmp, 3):",
"+ ans += table[x[0]] * table[x[1]] * table[x[2]]"
] | false | 0.039545 | 0.048106 | 0.822032 | [
"s969998267",
"s073961229"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.