code1
stringlengths 16
24.5k
| code2
stringlengths 16
24.5k
| similar
int64 0
1
| pair_id
int64 2
181,637B
⌀ | question_pair_id
float64 3.71M
180,628B
⌀ | code1_group
int64 1
299
| code2_group
int64 1
299
|
---|---|---|---|---|---|---|
n=int(input())
lst=list(map(int,input().split()))
dist=[[] for _ in range(n)]
for i in range(n):
dist[lst[i]].append(i)
if len(dist[0])!=1:
print(0)
exit()
if not 0 in dist[0]:
print(0)
exit()
switch=0
for i in range(-1,-n-1,-1):
if switch==0:
if len(dist[i])>=1:
switch=1
if switch==1:
if len(dist[i])==0:
print(0)
exit()
ans=1
rem=1
for i in range(n):
num=len(dist[i])
ans*=pow(rem,num,998244353)
ans%=998244353
rem=num
print(ans) | import sys
readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)
def main():
n, m = map(int, readline().split())
s = input()
t = [0] * (n + 1)
cur = n
for i in range(n, -1, -1):
if s[i] == "0":
cur = i
t[i] = cur
else:
t[i] = cur
res = []
i = n
while i > 0:
nx = max(0, i - m)
if t[nx] == i:
return print(-1)
else:
res.append(i - t[nx])
i = t[nx]
print(*res[::-1])
if __name__ == '__main__':
main()
| 0 | null | 146,546,388,642,410 | 284 | 274 |
strN = input()
s = 0
for c in strN:
s += int(c)
if s % 9 == 0:
print("Yes")
else:
print("No") | N = input()
answer = 0
for keta in N:
answer = (answer + int(keta))%9
if not answer:
print("Yes")
else:
print("No")
| 1 | 4,446,948,695,072 | null | 87 | 87 |
n = int(input())
s = input()
r = [0] * (n+1)
g = [0] * (n+1)
b = [0] * (n+1)
for i, c in enumerate(reversed(s), 1):
if c == 'R':
r[i] += r[i-1] + 1
else:
r[i] += r[i-1]
if c == 'G':
g[i] += g[i-1] + 1
else:
g[i] += g[i-1]
if c == 'B':
b[i] += b[i-1] + 1
else:
b[i] += b[i-1]
r = r[:-1][::-1]
g = g[:-1][::-1]
b = b[:-1][::-1]
ans=0
for i in range(n-2):
for j in range(i+1, n-1):
if s[i] == s[j]:
continue
se = set('RGB') - set(s[i] + s[j])
c = se.pop()
if c == 'R':
ans += r[j]
if 2*j-i < n and s[2*j-i] == 'R':
ans -= 1
elif c == 'G':
# print('j=',j,'g[j]=',g[j])
ans += g[j]
if 2*j-i < n and s[2*j-i] == 'G':
ans -= 1
elif c == 'B':
ans += b[j]
if 2*j-i < n and s[2*j-i] == 'B':
ans -= 1
# print('i=',i,'j=',j,'c=',c, 'ans=',ans)
print(ans) | n=int(input())
s='*'+input()
r=s.count('R')
g=s.count('G')
b=s.count('B')
cnt=0
for i in range(1,n+1):
for j in range(i,n+1):
k=2*j-i
if k>n:
continue
if s[i]!=s[j] and s[j]!=s[k] and s[k]!=s[i]:
cnt+=1
print(r*g*b-cnt) | 1 | 36,182,062,958,316 | null | 175 | 175 |
word = input()
n = len(word)
hanbun = int((n-1)/2)
notk = 0
for i in range(hanbun):
if word[i] != word[n-i-1]:
notk = 1
break
if hanbun % 2 == 0:
hanbun2 = int(hanbun/2)
else:
hanbun2 = int((hanbun-1)/2)
for j in range(hanbun2):
if word[j] != word[hanbun-j-1]:
notk = 1
break
if notk == 1:
print('No')
else:
print('Yes') | S = input()
s = list(S)
f = s[:int((len(s)-1)/2)]
l = s[int((len(s)+3)/2-1):]
if f == l:
while len(f) > 1:
if f[0] == f[-1]:
f.pop(0)
f.pop()
if len(f) <= 1:
while len(l) > 1:
if l[0] == l[-1]:
l.pop(0)
l.pop()
if len(l) <= 1:
print('Yes')
else:
print('No')
else:
print('No')
else:
print('No') | 1 | 46,369,290,560,908 | null | 190 | 190 |
def main():
H1, M1, H2, M2, K = map(int, input().split())
t1 = 60*H1 + M1
t2 = 60*H2 + M2
d = 0
if t1 <= t2:
d = t2 - t1
else:
d = 60*24 - t1 + t2
print(max(0, d - K))
if __name__ == "__main__":
main() | h1, m1, h2, m2, k = map(int, input().split())
s = h1 * 60 + m1
e = h2 * 60 + m2
print(e - k - s) | 1 | 18,038,190,996,618 | null | 139 | 139 |
from math import gcd
# X * K = 360 * n
lcm = lambda x, y: (x * y) // gcd(x, y)
X = int(input())
print(lcm(X, 360) // X) | X = int(input())
ROTATION = 360
K = 1
while K * X % 360 != 0:
K += 1
print(K)
| 1 | 13,050,250,961,440 | null | 125 | 125 |
from bisect import bisect_left, bisect, insort
def main():
n = int(input())
s = list(input())
q = int(input())
_is = {chr(i):[] for i in range(ord("a"), ord("a")+27)}
for i, si in enumerate(s):
_is[si].append(i)
for _ in range(q):
t, i, c = input().split()
i = int(i)-1
if t == "1":
if s[i] != c:
index = bisect_left(_is[s[i]], i)
del _is[s[i]][index]
insort(_is[c], i)
s[i] = c
else:
c = int(c) - 1
cnt = 0
for _isi in _is.values():
if _isi:
is_in = bisect(_isi, c)-bisect_left(_isi, i)
if is_in:
cnt += 1
print(cnt)
if __name__ == "__main__":
main()
| from collections import Counter
N=int(input())
if N==1:
print(0)
exit()
def factorize(n):
out=[]
i = 2
while 1:
if n%i==0:
out.append(i)
n //= i
else:
i += 1
if n == 1:break
if i > int(n**.5+3):
out.append(n)
break
return out
c = Counter(factorize(N))
def n_unique(n):
out = 0
while 1:
if out*(out+1)//2 > n:
return out-1
out += 1
ans = 0
for k in c.keys():
ans += n_unique(c[k])
print(ans) | 0 | null | 39,876,189,176,030 | 210 | 136 |
from collections import deque
n,x,y = map(int,input().split())
adj = [[] for i in range(n)]
adj[x-1].append(y-1)
adj[y-1].append(x-1)
for i in range(n-1):
adj[i].append(i+1)
adj[i+1].append(i)
ans = [0]*(n-1)
for i in range(n):
q = deque([])
q.append(i)
dist = [-1]*n
dist[i] = 0
while len(q) > 0:
v = q.popleft()
for nv in adj[v]:
if dist[nv] != -1:
continue
dist[nv] = dist[v] + 1
q.append(nv)
for i in dist:
if i != 0:
ans[i-1] += 1
for i in ans:
print(i//2) | import sys
from collections import Counter
def main():
input = sys.stdin.buffer.readline
n, x, y = map(int, input().split())
k_cnt = Counter()
for i in range(1, n):
for j in range(i + 1, n + 1):
if i <= x:
if j < y:
dist = min(j - i, (x - i) + 1 + (y - j))
elif y <= j:
dist = (x - i) + 1 + (j - y)
elif x < i < y:
dist = min(j - i, (i - x) + 1 + abs(j - y))
else:
dist = j - i
k_cnt[dist] += 1
for i in range(1, n):
print(k_cnt[i])
if __name__ == "__main__":
main()
| 1 | 44,241,313,924,460 | null | 187 | 187 |
def main():
s=input()
ans=0
for i in range(0,int(len(s)/2)):
if s[i]!=s[-1*(i+1)]:
ans+=1
print(ans)
main() | S = input()
L = len(S)
cnt = 0
for i in range(L//2):
if S[i] == S[-1-i]:
continue
else:
cnt += 1
print(cnt) | 1 | 119,626,415,999,592 | null | 261 | 261 |
m = input()
c = m[-1]
if c == 's':
print(m+'es')
else:
print(m+'s') | s = input()
ans = s
if s[-1] == "s":
ans += "e"
print(ans+"s") | 1 | 2,374,001,062,072 | null | 71 | 71 |
N = int(input())
A = list(map(int, input().split()))
ans = float('inf')
sum_A = sum(A)
hoge = 0
for i in range(N-1):
hoge = hoge + A[i]
ans = min(ans,abs(sum_A - (hoge*2)))
print(ans)
| import itertools
n = int(input())
a = [input() for _ in range(n)]
suits = ['S', 'H', 'C', 'D']
cards = ["%s %d" % (s, r) for s, r in itertools.product(suits, range(1, 14))]
answers = [c for c in cards if c not in a]
for card in answers:
print(card)
| 0 | null | 71,856,513,631,042 | 276 | 54 |
lis=list(input().split())
num=list(map(int,input().split()))
num[lis.index(input())]-=1
print(str(num[0])+" "+str(num[1]))
| import os, sys, re, math
(S, T) = [n for n in input().split()]
(A, B) = [int(n) for n in input().split()]
U = input()
if U == S:
A -= 1
else:
B -= 1
print('%s %s' % (A, B))
| 1 | 71,773,063,975,672 | null | 220 | 220 |
def main():
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
target = 1
for i in A:
if i == target:
target += 1
if target == 1:
print(-1)
return
print(N - target + 1)
main() | K, N = map(int, input().split())
A = list(map(int, input().split()))
c = abs(K - A[N-1] + A[0])
for i in range(N-1):
d = abs(A[i] - A[i+1])
if c < d:
c = d
else:
c = c
print(K-c) | 0 | null | 79,247,111,434,780 | 257 | 186 |
n=int(input())
a=list(map(int,input().split()))
s=sum(a)
res=0
m=1
for i in a:
b=m-i
if b<0:
print(-1)
exit(0)
res+=i
res+=b
s-=i
m=min(b*2,s)
print(res)
| import sys
def input():
return sys.stdin.readline().rstrip()
def main():
n = int(input())
items = {input() for _ in range(n)}
print(len(items))
if __name__ == "__main__":
main() | 0 | null | 24,620,660,880,140 | 141 | 165 |
N = int(input())
A = list(map(int, input().split()))
a = [0]
for i in range(N):
a.append(a[i] + A[i])
cnt = 0
for i in range(N-1):
cnt += A[i] * (a[N] - a[i+1])
mod = 10 ** 9 + 7
ans = cnt % mod
print(ans)
| N = int(input())
S = input()
count_R = 0
count_G = 0
count_B = 0
count = 0
for i in range(N):
if S[i] == 'R':
count_R = count_R+1
elif S[i] == 'G':
count_G = count_G+1
else:
count_B = count_B+1
count = count_R*count_G*count_B
for i in range(N):
for j in range(i+1,N):
if S[i] != S[j]:
k = 2*j-i
if k>=N:
break
else:
if S[i] != S[k] and S[j] != S[k]:
count = count-1
print(count) | 0 | null | 19,942,989,198,588 | 83 | 175 |
import collections
def Z(): return int(input())
def ZZ(): return [int(_) for _ in input().split()]
def main():
N, M, K = ZZ()
F = [0] * (N+1)
output = []
par = [i for i in range(N+1)]
rank = [0] * (N+1)
# 要素xの親ノードを返す
def find(x):
if par[x] == x:
return x
par[x] = find(par[x])
return par[x]
# 要素x, yの属する集合を併合
def unite(x, y):
x, y = find(x), find(y)
if x == y:
return
if rank[x] < rank[y]:
par[x] = y
else:
par[y] = x
if rank[x] == rank[y]:
rank[x] += 1
return
# xとyが同じ集合に属するか?
def same(x, y):
return find(x) == find(y)
for _ in range(M):
a, b = ZZ()
F[a] += 1
F[b] += 1
unite(a, b)
for i in range(1, N+1): find(i)
cnt = collections.Counter(par)
for _ in range(K):
c, d = ZZ()
if same(c, d):
F[c] += 1
F[d] += 1
for i in range(1, N+1):
cc = cnt[par[i]] - F[i] - 1
output.append(cc)
print(*output)
return
if __name__ == '__main__':
main()
| from collections import defaultdict
from collections import deque
n,m,k = map(int,input().split())
f_set = {tuple(map(int,input().split())) for _ in range(m)}
b_set = {tuple(map(int,input().split())) for _ in range(k)}
friends_counts = {key:[] for key in range(1,n+1)}
blocks_counts = {key:[] for key in range(1,n+1)}
for f in f_set:
friends_counts[f[0]].append(f[1])
friends_counts[f[1]].append(f[0])
for b in b_set:
blocks_counts[b[0]].append(b[1])
blocks_counts[b[1]].append(b[0])
friends_groups_list = [set() for _ in range(n+1)]
#dfs
que = deque()
groups_count = 0
checked_dict = {key:0 for key in range(1,n+1)}
#que.appendleft(1)
for i in range(1,n+1):
if checked_dict[i] == 1:
continue
que.appendleft(i)
checked_dict[i] = 1
while que:
x = que.popleft()
friends_groups_list[groups_count].add(x)
for i in range(len(friends_counts[x])):
if checked_dict[friends_counts[x][i]] == 0:
que.appendleft(friends_counts[x][i])
checked_dict[friends_counts[x][i]] = 1
groups_count += 1
result_list=[0]*n
#print(blocks_counts)
#print(friends_groups_list)
for i in range(len(friends_groups_list)):
mini_set = friends_groups_list[i]
for ms in mini_set:
result_list[ms-1] = len(mini_set) - 1 - len(friends_counts[ms])
block_counter_in_minilist = 0
for k in blocks_counts[ms]:
if k in mini_set:
block_counter_in_minilist += 1
result_list[ms-1] -= block_counter_in_minilist
print(" ".join(map(str,result_list)))
#cの配列の解釈が違ったらしい。。。
#f_set = {tuple(map(int,input().split())) for _ in range(m)}
#
#b_set = {tuple(map(int,input().split())) for _ in range(k)}
#
#c_list = [0] * (n-1)
#
#result_dict = {key:0 for key in range(1,n+1)}
#
#for f in f_set:
# if abs(f[0]-f[1]) == 1:
# c_list[min(f[0],f[1]) - 1] = 1
# #ここでelseで飛び石での友達のsetを作ってもよいが、そもそもsetなのでinでの探索にそんなに時間かからないし、いったんこのままやってみる。
#
#for start in range(0,n-2):
# if c_list[start] == 0:
# #c[start]が1になるまで飛ばす
# continue
#
# for end in range(start+1,n-1):
# if c_list[end] == 0:
# #友人同士ではないペアまできたらstartをインクリメント
# break
#
# #もし「友人候補」の候補者が、「友人関係でない」かつ「ブロック関係でない」ことをチェックしている。
# if not (start+1,end+2) in f_set and not (end+2,start+1) in f_set and not (start+1,end+2) in b_set and not (end+2,start+1) in b_set:
# result_dict[start+1] += 1
# result_dict[end+2] += 1
#
#for i in range(1,n+1):
# print(result_dict[i])
#
#print(c_list)
| 1 | 61,903,507,799,530 | null | 209 | 209 |
N = int(input())
A = list(map(int,input().split()))
ans = "APPROVED"
for n in range(N):
if A[n] %2 == 0:
if A[n] % 3 != 0 and A[n] % 5 != 0:
ans = "DENIED"
break
print(ans) | import numpy as np
N, *A = map(int, open(0).read().split())
A = np.array(A, dtype=np.int64)
mod = 10**9 + 7
ans = 0
for i in range(60):
mask = 1 << i
cnt = np.count_nonzero(A&mask)
x = cnt * (N-cnt)
x *= mask % mod
ans += x
ans %= mod
print(ans) | 0 | null | 95,946,427,736,092 | 217 | 263 |
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
N, M, K = map(int,input().split())
uf = UnionFind(N)
f_b = [set() for _ in range(N)]
ans = []
for i in range(M):
A, B = map(int,input().split())
A -= 1
B -= 1
uf.union(A, B)
f_b[A].add(B)
f_b[B].add(A)
for i in range(K):
C, D = map(int,input().split())
C -= 1
D -= 1
if uf.same(C, D):
f_b[C].add(D)
f_b[D].add(C)
for i in range(N):
ans.append(uf.size(i) - len(f_b[i]) - 1)
print(*ans) | N, M, K = map(int, input().split())
class UnionFind:
def __init__(self, n):
self.ps = [-1] * (n + 1)
def find(self, x):
if self.ps[x] < 0:
return x
else:
self.ps[x] = self.find(self.ps[x])
return self.ps[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return False
if self.ps[x] > self.ps[y]:
x, y = y, x
self.ps[x] += self.ps[y]
self.ps[y] = x
return True
def same(self, x, y):
return self.find(x) == self.find(y)
def size(self, x):
x = self.find(x)
return -self.ps[x]
uf = UnionFind(N)
friends = [0]*(N+1)
chain = [0]*(N+1)
for _ in range(M):
A, B = map(int, input().split())
friends[A] += 1
friends[B] += 1
uf.union(A, B)
for _ in range(K):
C, D = map(int, input().split())
if uf.same(C, D):
friends[C] += 1
friends[D] += 1
ans = []
for i in range(1, N+1):
ans.append(uf.size(i) - friends[i] - 1)
print(*ans) | 1 | 61,434,464,448,028 | null | 209 | 209 |
import sys
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
ans = 0
for i in range(1,N+1):
if i % 3 == 0 or i % 5 == 0:
continue
ans += i
print(ans) | votos = dict()
quantidade = int(input())
for i in range(0, quantidade):
nome = input()
if(len(votos) == 0):
votos[nome] = 1
elif nome in votos:
votos[nome] += 1
else:
votos[nome] = 1
maior = 0
for i in votos:
if(votos[i] > maior):
maior = votos[i]
nome = list()
for i in votos:
if(votos[i] == maior):
nome.append(i)
nome.sort()
for i in nome:
print(i) | 0 | null | 52,191,691,060,972 | 173 | 218 |
a, b = map(int, input().rstrip().split())
r = -1 if 10 <= a or 10 <= b else a * b
print(r)
| import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")
a,b = list(map(int, input().split()))
if 1<=a<=9 and 1<=b<=9:
ans = a*b
else:
ans = -1
print(ans) | 1 | 158,283,464,448,940 | null | 286 | 286 |
price = int(input())
amari = price % 1000
if amari == 0:
print(0)
else:
print(1000 - amari) | s=input()
ans = 0
for i in range(len(s)):
j = len(s)-i-1
if i > j: break
if s[i] != s[j]: ans += 1
print(ans) | 0 | null | 64,284,065,409,760 | 108 | 261 |
while 1:
h,w=map(int,input().split())
if h==0 and w==0: break
for y in range(h): print(('#.'*w)[y % 2:][:w])
print('') | while True:
H,W=[int(i) for i in input().split(" ")]
if H==W==0:
break
for h in range(H):
s="#" if h%2==0 else "."
for w in range(W-1):
s+="#" if s[-1]=="." else "."
print(s)
print() | 1 | 877,803,927,542 | null | 51 | 51 |
n=int(input())
import bisect
L=[]
for i in range(n):
x,l=map(int,input().split())
a=x-l+0.1
b=x+l-0.1
L.append((b,a))
L=sorted(L)
rob=1
bottom=L[0][0]
for i in range(1,n):
if L[i][1]>bottom:
rob += 1
bottom=L[i][0]
print(rob) | N = int(input())
R = sorted([list(map(int, input().split())) for i in range(N)])
T = []
for i in range(N):
T.append([R[i][0] + R[i][1], R[i][0] - R[i][1]])
T.sort(reverse=True)
while len(T) - 1 > 0:
t = T.pop()
i = 1
while len(T) and t[0] > T[-1][1]:
N -= 1
i += 1
T.pop()
print(N) | 1 | 90,027,144,529,020 | null | 237 | 237 |
H, N = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(N)]
limit = H + max(A[i][0] for i in range(N))
dp = [int(1e18) for _ in range(limit+1)]
dp[0] = 0
for i in range(1, limit+1):
for j in range(N):
if A[j][0] > i:
dp[i] = min(dp[i], A[j][1])
else:
dp[i] = min(dp[i], dp[i-A[j][0]]+A[j][1])
M = min(dp[i] for i in range(H, limit+1))
print(dp[H])
| h,n = map(int,input().split())
a = [0 for _ in range(n)]
b = [0 for _ in range(n)]
for i in range(n):
a[i],b[i] = map(int,input().split())
cost = [int(1e+9) for _ in range(h+1)]
cost[0] = 0
for i in range(h):
for j in range(n):
if i+a[j] <= h:
cost[i+a[j]] = min(cost[i+a[j]],cost[i]+b[j])
else:
cost[-1] = min(cost[-1],cost[i]+b[j])
print(cost[-1]) | 1 | 81,082,315,323,108 | null | 229 | 229 |
li = []
for i, s in enumerate(input()):
if s == "\\":
li.append([i, 0])
elif s == "/":
if li:
if li[-1][1] == 0:
li[-1][1] = i - li[-1][0]
else:
for j in range(len(li) - 1, -1, -1):
if li[j][1] == 0:
li = li[:j] + [[li[j][0], sum(tuple(zip(*li[j + 1:]))[1]) + i - li[j][0]]]
break
ans = []
for a in li:
if a[1] != 0:
ans.append(a[1])
print(sum(ans))
print(len(ans), *ans)
| N, K = [int(n) for n in input().split()]
NUM = 1000000007
def modpow(a, b): # (a ** b) % NUM
ans = 1
while b != 0:
if b % 2 == 1:
ans *= a
ans %= NUM
a = a * a
a %= NUM
b //= 2
return ans
C = [0 for _ in range(K+1)]
for d in range(K):
k = K - d # K ... 1
L = K // k
C[k] = modpow(L, N) # A = 1*k ... L*k
for l in range(2, L+1):
C[k] -= C[l*k]
if C[k] < 0:
C[k] += NUM
C[k] %= NUM
ans = 0
for k in range(1, K+1):
ans += k * C[k]
ans %= NUM
print(ans)
| 0 | null | 18,510,740,968,746 | 21 | 176 |
import sys
from collections import deque
def main():
h, w = map(int, input().split())
area = [[s for s in sys.stdin.readline().strip()] for _ in range(h)]
start_point = {0:set(), 1:set(), 2:set(), 3:set(), 4:set()}
min_neighbor = 4
for i in range(h):
for j in range(w):
if area[i][j] == '#':
continue
roads = 0
if i > 0 and area[i - 1][j] == '.':
roads += 1
if i < h - 1 and area[i + 1][j] == '.':
roads += 1
if j > 0 and area[i][j - 1] == '.':
roads += 1
if j < w - 1 and area[i][j + 1] == '.':
roads += 1
min_neighbor = min(min_neighbor, roads)
start_point[roads].add((i, j))
max_cost = 0
for start in start_point[min_neighbor]:
queue = deque()
queue.append(start)
cost = 0
visited = set()
while len(queue) > 0:
roads = len(queue)
found = False
for i in range(roads):
s = queue.popleft()
if s in visited:
continue
found = True
visited.add(s)
i = s[0]
j = s[1]
if i > 0 and area[i - 1][j] == '.':
queue.append((i - 1, j))
if i < h - 1 and area[i + 1][j] == '.':
queue.append((i + 1, j))
if j > 0 and area[i][j - 1] == '.':
queue.append((i, j - 1))
if j < w - 1 and area[i][j + 1] == '.':
queue.append((i, j + 1))
if not found:
cost -= 1
max_cost = max(cost, max_cost)
if found:
cost += 1
print(max_cost)
if __name__ == '__main__':
main() | import queue
h,w = map(int,input().split())
v = [(1, 0), (0, 1), (-1, 0), (0, -1)]
s = [input() for i in range(h)]
ans = 0
que = queue.Queue()
for i in range(h * w):
c = 0
d = [[h*w] * w for i in range(h)]
p = (i//w, i%w)
if s[p[0]][p[1]] == '#':
continue
d[p[0]][p[1]] = 0
que.put(p)
while not que.empty():
y,x = que.get()
c = d[y][x]
for dy, dx in v:
yy = y + dy
xx = x + dx
if yy < 0 or xx < 0 or h <= yy or w <= xx:
continue
if s[yy][xx] == '#':
continue
if d[yy][xx] < h*w:
continue
que.put((yy, xx))
d[yy][xx] = c + 1
ans = max(ans, c)
print(ans) | 1 | 94,432,511,643,208 | null | 241 | 241 |
import sys; input = sys.stdin.readline
n = int(input())
ac, wa, tle, re = 0, 0, 0, 0
for i in range(n):
a = input().strip()
if a == 'AC': ac+=1
elif a == 'WA': wa += 1
elif a == 'TLE': tle += 1
elif a == 'RE': re += 1
print(f"AC x {ac}")
print(f"WA x {wa}")
print(f"TLE x {tle}")
print(f"RE x {re}") | t="qwertyuioplkjhgfdsazxcvbnm"
T="QWERTYUIOPLKJHGFDSAZXCVBNM"
a=str(input())
if a in t:
print('a')
else:
print('A') | 0 | null | 9,921,216,247,040 | 109 | 119 |
s=input()
t=input()
lent=len(t)
num=lent
ls=[]
count=0
for i in range(len(s)-lent+1):
st=s[i:i+num]
num+=1
for j in range(lent):
if st[j]!=t[j]:
count+=1
ls.append(count)
count=0
print(min(ls)) | """B."""
import sys
input = sys.stdin.readline # noqa: A001
S = input()[:-1]
T = input()[:-1]
S_L = len(S)
T_L = len(T)
ans = T_L
for i in range(S_L - T_L + 1):
S_2 = S[i:i + T_L]
match = 0
for v1, v2 in zip(S_2, T):
match += bool(v1 != v2)
ans = min(ans, match)
print(ans)
exit(0) | 1 | 3,688,463,128,868 | null | 82 | 82 |
n = input()
n += n
if input() in n:
print("Yes")
else:
print("No") | def draw(h,w):
t = "#." * (w/2)
if w%2 == 0:
s = t
k = t.strip("#") + "#"
else:
s = t + "#"
k = "." + t
for i in range(0,h/2):
print s
print k
if h%2==1:
print s
print
if __name__ == "__main__":
while True:
h,w = map(int, raw_input().split())
if h==0 and w==0:
break
else:
draw(h,w) | 0 | null | 1,311,804,117,460 | 64 | 51 |
k = int(input())
if k % 2 == 0 or k % 5 == 0:
x = -1
else:
m = 7
n = 7
x = 1
while n % k != 0:
m = (m * 10) % k
n += m
x += 1
print(x) | K = int(input())
seven_number = 0
ality = 0
for ans in range(1,10**7):
if ans > K:
print("-1")
break
else:
seven_number = (seven_number*10+7) % K
if seven_number ==0:
print(ans)
break
| 1 | 6,075,864,421,340 | null | 97 | 97 |
N = int(input())
if N % 2 == 1:
print(0)
else:
ans = 0
div = 10
for _ in range(100):
ans += N // div
div *= 5
print(ans)
| import sys
input = sys.stdin.readline
a,b=map(int,input().split())
if a>b:
print(str(b)*a)
else:
print(str(a)*b)
| 0 | null | 100,496,711,558,162 | 258 | 232 |
N, M, K = map(int, input().split())
A=list(map(int, input().split()))
B=list(map(int, input().split()))
Asum=[0]
Bsum=[0]
for i, a in enumerate(A):
Asum.append(Asum[i]+a)
for i, b in enumerate(B):
Bsum.append(Bsum[i]+b)
ans, b = 0, M
for a, asum in enumerate(Asum):
if asum > K:
break
while Bsum[b]>K - asum:
b-=1
ans = max(ans, a+b)
print(ans)
| import sys
from operator import itemgetter
N = int(input())
V = set()
for s in sys.stdin.readlines():
x, y = map(int, s.split())
V.add((x + y, x - y))
y_max = max(V, key=itemgetter(1))[1]
y_min = min(V, key=itemgetter(1))[1]
x_max = max(V, key=itemgetter(0))[0]
x_min = min(V, key=itemgetter(0))[0]
print(max(x_max - x_min, y_max - y_min))
| 0 | null | 7,063,465,821,732 | 117 | 80 |
k = int(input())
a, b = map(int, input().split())
for n in range(a, b+1):
if n % k == 0:
print('OK')
break
if n == b:
print('NG') | K = int(input())
A, B = map(int,input().split())
C = A % K
if B - A >= K - 1:
print('OK')
elif C == 0:
print('OK')
elif C + B - A >= K:
print('OK')
else:
print('NG') | 1 | 26,696,637,815,276 | null | 158 | 158 |
N, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
mod = 10 ** 9 + 7
fac = [1, 1]
finv = [1, 1]
inv = [0, 1]
ans = 0
def comb(n, r):
if n >= r:
return fac[n] * ( finv[r] * finv[n-r] % mod ) % mod
else:
return 0
for i in range(2, N + 1):
fac.append( ( fac[-1] * i ) % mod )
inv.append( mod - ( inv[mod % i] * (mod // i) % mod ) )
finv.append( finv[-1] * inv[-1] % mod )
if K == 1:
print(0)
else:
for i, x in enumerate(A):
cnt = x * ( comb(i, K-1) - comb(N-1-i, K-1) ) % mod
ans += cnt
ans %= mod
print(ans) | import math
H = int(input())
W = int(input())
N = int(input())
Max = max(H,W)
print(math.ceil(N/Max)) | 0 | null | 92,474,656,655,330 | 242 | 236 |
import sys
input = sys.stdin.readline
from bisect import bisect_left
from itertools import accumulate
def func(A, N, M, x):
count = 0
for Ai in A:
idx = bisect_left(A, x - Ai)
count += N - idx
if count >= M:
return True
else:
return False
def main():
N, M = map(int, input().split())
A = sorted(list(map(int, input().split())))
A_rev = list(reversed(A))
B = [0] + list(accumulate(A_rev))
min_ = 0
max_ = 2 * 10 ** 5 + 1
while max_ - min_ > 1:
mid = (min_ + max_) // 2
if func(A, N, M, mid):
min_ = mid
else:
max_ = mid
ans = 0
count = 0
for Ai in A_rev:
idx = bisect_left(A, min_-Ai)
ans += Ai * (N - idx) + B[N-idx]
count += N - idx
print(ans-(count-M)*min_)
if __name__ == '__main__':
main() | # B - Common Raccoon vs Monster
H,N = map(int,input().split())
A = list(map(int,input().split()))
ans = 'Yes' if H<=sum(A) else 'No'
print(ans) | 0 | null | 93,405,252,249,888 | 252 | 226 |
N,K = map(int,input().split())
import numpy as np
arr = np.array(input().split(),np.int64)
print(np.count_nonzero(arr>=K)) | N=int(input())
S,T=input().split()
ans=S[0]+T[0]
for i in range(1,N):
ans=ans+S[i]+T[i]
print(ans) | 0 | null | 145,015,637,763,450 | 298 | 255 |
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
# d = m - k[i] - k[j]
# if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
return list(map(int,input().split()))
def I():
return int(input())
ln = len(input())
print('x'*ln)
| string = input()
replaced_string = ''
while len(replaced_string) < len(string):
replaced_string += 'x'
print(replaced_string) | 1 | 73,017,342,427,500 | null | 221 | 221 |
a = [int(v) for v in input().rstrip().split()]
r = 'bust' if sum(a) >= 22 else 'win'
print(r)
| X = int(input())
print(1000 * (X // 500) + 5 * ((X - 500 * (X // 500)) // 5))
| 0 | null | 80,590,964,292,370 | 260 | 185 |
class PrimeFactor():
def __init__(self, n): # エラトステネス O(N loglog N)
self.n = n
self.table = list(range(n+1)) # 最小素因数のリスト
self.table[2::2] = [2]*(n//2)
for p in range(3, int(n**0.5) + 2, 2):
if self.table[p] == p:
for q in range(p * p, n + 1, 2 * p):
if self.table[q] == q:
self.table[q] = p
def is_prime(self, x): # 素数判定 O(1)
if x < 2:
return False
return self.table[x] == x
p = PrimeFactor(10**6)
X = int(input())
while True:
if p.is_prime(X):
print(X)
exit()
else:
X += 1
| import math
def is_prime(x):
root = int(math.sqrt(x))+1
if x == 2:
return True
else:
for i in range(2, root+1):
if x % i == 0:
return False
return True
'''
def find_prime(x):
while True:
if x == 2:
return x
else:
for i in range(2, x+1):
if x % i == 0:
if i == x:
return x
else:
break
else:
continue
x += 1
'''
def main():
x = int(input())
while True:
if is_prime(x) == False:
x += 1
else:
print(x)
break
if __name__ == "__main__":
main()
| 1 | 105,422,474,868,932 | null | 250 | 250 |
rate = int(input())
if 400 <= rate < 600:
print("8")
elif 600 <= rate <800:
print("7")
elif 800 <= rate <1000:
print("6")
elif 1000 <= rate <1200:
print("5")
elif 1200 <= rate <1400:
print("4")
elif 1400 <= rate <1600:
print("3")
elif 1600 <= rate <1800:
print("2")
elif 1800 <= rate <2000:
print("1")
| X = int(input())
up = 599
down = 400
i=8
while(i>=1):
if(X <= up and X >= down):
print(i)
break
else:
up += 200
down += 200
i -= 1 | 1 | 6,721,075,051,198 | null | 100 | 100 |
import math
import numpy as np
import sys
import os
from operator import mul
from operator import itemgetter
sys.setrecursionlimit(10**7)
def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))
if os.getenv("LOCAL"):
inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
sys.stdin = open(inputFile, "r")
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353
N,M = LI()
H = LI()
AB = [LI() for _ in range(M)]
p = []
d = {}
for i in range(N):
# p.append((i,H[i]))
d[i]=H[i]
# p.sort(key=itemgetter(1),reverse=True)
# print(p)
# print(d)
# g = np.zeros(shape=(N,N),dtype='int')
g = [set()] * N
a = [True] * N
for i in range(M):
f = AB[i][0]-1
t = AB[i][1]-1
if d[t]>d[f]:
a[f]=False
elif d[f]>d[t]:
a[t]=False
else:
a[f]=False
a[t]=False
# print(a)
print(sum(a))
# print(g[f])
# g[f] = np.append(g[f],t)
# g[t] = np.append(g[t],f)
# g[f][t]=1
# g[t][f]=1
# print(g)
# list.sort(key=itemgetter(0))
# for i in range(N):
# a = np.where(g[0]==1)
# print(a) | S = input()
ans = 0
for i in range(int(len(S) / 2)):
if S[i] != S[-1-i]:
ans += 1
print(ans) | 0 | null | 72,924,656,233,422 | 155 | 261 |
mt = []
for i in range(10):
mt.append(int(input()))
mt.sort()
print( mt[9] )
print( mt[8] )
print( mt[7] ) | n = int(input())
maximum_profit = -10**9
r0 = int(input())
r_min = r0
for i in range(1, n):
r1 = int(input())
if r0 < r_min:
r_min = r0
profit = r1 - r_min
if profit > maximum_profit:
maximum_profit = profit
r0 = r1
print(maximum_profit) | 0 | null | 6,202,528,192 | 2 | 13 |
ans = 0
x, y = map(int,input().split())
ans += 100000*max((4-x),0)
ans += 100000*max((4-y),0)
if x == y == 1:
ans += 400000
print(ans) | def sel_sort(A, N):
''' 選択ソート '''
count = 0
for n in range(N):
minm = n
for m in range(n, N):
if A[m] < A[minm]:
minm = m
if minm != n:
A[n], A[minm] = A[minm], A[n]
count += 1
return (A, count)
if __name__ == '__main__':
N = int(input())
A = list(map(int, input().split(' ')))
ans = sel_sort(A, N)
print(' '.join([str(x) for x in ans[0]]))
print(ans[1])
| 0 | null | 70,194,708,836,678 | 275 | 15 |
K = int(input())
s = 'ACL'
print(s * K)
|
def main():
s = input()
week = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT']
ind = week.index(s)
print(7 - (ind % 7))
if __name__ == "__main__":
main()
| 0 | null | 67,646,265,054,852 | 69 | 270 |
N, A, B = map(int, input().split())
q = N // (A + B)
r = N % (A + B)
if r <= A:
print(q * A + r)
else:
print(q * A + A) | import math
def main():
v = list(map(int, input().split()))
n = v[0]
a = v[1]
b = v[2]
answer = 0
if n < a:
answer = n
elif n < a+b:
answer = a
elif a == 0 and b == 0:
answer = 0
else:
answer += math.floor(n / (a+b)) * a
rest = n % (a+b)
if rest <= a:
answer += rest
else:
answer += a
print(answer)
if __name__ == "__main__":
main()
| 1 | 55,609,306,476,070 | null | 202 | 202 |
from math import sqrt
n=int(input())
m=int(sqrt(n)//1)
for i in range(m,0,-1):
if n%i==0:
m=i
o=n//m
break
print(m+o-2) | n=int(input())
import math
for i in range(int(math.sqrt(n)),0,-1):
if n%i==0:
print(i+n//i-2)
break | 1 | 161,523,246,825,850 | null | 288 | 288 |
from sys import stdin
from itertools import accumulate
input = stdin.readline
n = int(input())
a = list(map(int,input().split()))
p = [0] + list(accumulate(a))
res = 0
for i in range(n-1,-1,-1):
res += (a[i] * p[i])%(10**9 + 7)
print(res % (10**9 + 7)) | a,b,c = map(float,input().split())
import math
h = b * math.sin(math.radians(c))
S = ( a * h ) / 2
L = a + b + ( math.sqrt( a**2 + b**2 - 2*a*b*math.cos(math.radians(c)) ) )
print('{0:.8f}'.format(S))
print('{0:.8f}'.format(L))
print('{0:.8f}'.format(h))
| 0 | null | 2,033,092,818,548 | 83 | 30 |
for i in xrange(1, 10):
for j in xrange(1, 10):
print "%sx%s=%s" % (i,j, i*j) | # -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub
import sys
# sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline
INF = 2**62-1
def read_int():
return int(buff_readline())
def read_int_n():
return list(map(int, buff_readline().split()))
def read_float():
return float(buff_readline())
def read_float_n():
return list(map(float, buff_readline().split()))
def read_str():
return readline().strip()
def read_str_n():
return readline().strip().split()
def error_print(*args):
print(*args, file=sys.stderr)
def mt(f):
import time
def wrap(*args, **kwargs):
s = time.time()
ret = f(*args, **kwargs)
e = time.time()
error_print(e - s, 'sec')
return ret
return wrap
class UnionFind():
def __init__(self):
self.__table = {}
self.__size = defaultdict(lambda: 1)
self.__rank = defaultdict(lambda: 1)
def __root(self, x):
if x not in self.__table:
self.__table[x] = x
elif x != self.__table[x]:
self.__table[x] = self.__root(self.__table[x])
return self.__table[x]
def same(self, x, y):
return self.__root(x) == self.__root(y)
def union(self, x, y):
x = self.__root(x)
y = self.__root(y)
if x == y:
return False
if self.__rank[x] < self.__rank[y]:
self.__table[x] = y
self.__size[y] += self.__size[x]
else:
self.__table[y] = x
self.__size[x] += self.__size[y]
if self.__rank[x] == self.__rank[y]:
self.__rank[x] += 1
return True
def size(self, x):
return self.__size[self.__root(x)]
def num_of_group(self):
g = 0
for k, v in self.__table.items():
if k == v:
g += 1
return g
@mt
def slv(N, M, AB):
uf = UnionFind()
p = set()
for a, b in AB:
uf.union(a, b)
p.add(a)
p.add(b)
ans = 1
for c in p:
ans = max(ans, uf.size(c))
return ans
def main():
N, M = read_int_n()
AB = [read_int_n() for _ in range(M)]
print(slv(N, M, AB))
if __name__ == '__main__':
main()
| 0 | null | 1,968,165,542,580 | 1 | 84 |
import numpy as np
n, k = map(int, input().split())
a = np.array(list(map(int, input().split())))
a.sort()
l, r = 0, 10000000000
while r - l > 1:
m = (l + r) // 2
res = n * n - a.searchsorted(m - a).sum()
if res >= k:
l = m
else:
r = m
b = np.array([0] * (n + 1))
for i in range(1, n + 1):
b[i] = b[i - 1] + a[n - i]
cnt = 0
ans = 0
for x in a:
t = n - a.searchsorted(l - x)
ans += b[t] + x * t
cnt += t
print(ans - (cnt - k) * l)
| import math
MOD = 10**9 + 7
n = int(input())
mp = {}
ans1 = 0
def process(lst):
a = lst[0]
b = lst[1]
gcd = math.gcd(a, b)
a //= gcd
b //= gcd
if b < 0:
a *= -1
b *= -1
a = abs(a) if b == 0 else a
b = abs(b) if a == 0 else b
lst[0] = a
lst[1] = b
return lst
for _ in range(n):
a, b = map(int, input().split())
if a == 0 and b == 0:
ans1 += 1
continue
a, b = process([a, b])
mp.setdefault((a, b), 0)
mp[(a, b)] += 1
a, b = process([-b, a])
y = mp.setdefault( (a, b), 0)
ans = 1
taken = {}
for a, b in mp:
if taken.get((a, b), 0):
continue
taken.setdefault((a, b), 0)
taken[(a, b)] = 1
x = mp.get( (a, b), 0)
# print(a, b, x, end=" + ")
a, b = process([-b, a])
y = mp.get( (a, b), 0)
taken.setdefault((a, b), 0)
taken[(a, b)] = 1
# print(a, b, y)
ans = (ans * ( pow(2, x, MOD) + pow(2, y, MOD) - 1 + MOD) % MOD ) % MOD
# print(ans)
ans = ( ans - 1 + ans1 + MOD ) % MOD
print(ans)
| 0 | null | 64,563,396,806,310 | 252 | 146 |
X,Y,A,B,C=map(int, input().split())
p=list(map(int, input().split()))
q=list(map(int, input().split()))
r=list(map(int, input().split()))
x=X-1
y=Y-1
p=sorted(p,reverse=True)
q=sorted(q,reverse=True)
r=sorted(r,reverse=True)
#print(p[:X],q[:Y])
if p[x]>=q[y]:
a=q[y]
f=1
else:
a=p[x]
f=2
while len(r)>=1 and a<r[0]:
# print(a,r[0])
if f==1 :
# print('f=1')
q[y]=r[0]
y-=1
r.pop(0)
elif f==2 :
# print('f=2')
p[x]=r[0]
x-=1
r.pop(0)
else:
# print('break1')
break
# print(x,y,p[x],q[y])
if (y==-1 and x>=0) or (x>=0 and p[x]<q[y]):
# print('a=p[x]')
a=p[x]
f=2
elif (x==-1 and y>=0) or (y>=0 and p[x]>=q[y]):
# print('a=q[y]')
a=q[y]
f=1
else:
# print('break2')
break
ans=0
#print(p[:X],q[:Y])
for i in p[:X]:
ans+=i
for i in q[:Y]:
ans+=i
print(ans) | from collections import deque
n = int(input())
dq = deque()
for _ in range(n):
query = input()
if query == "deleteFirst":
dq.popleft()
elif query == "deleteLast":
dq.pop()
else:
op, arg = query.split()
if op == "insert":
dq.appendleft(arg)
else:
tmp = deque()
while dq:
item = dq.popleft()
if item == arg:
break
else:
tmp.append(item)
while tmp:
dq.appendleft(tmp.pop())
print(*dq)
| 0 | null | 22,547,477,438,440 | 188 | 20 |
n=int(input())
ans=[]
tes=[[] for _ in range(n)]
for j in range(n):
a=int(input())
for h in range(a):
x,y=map(int,input().split())
tes[j].append(x)
tes[j].append(y)
for i in range(2**n):
f=0
m=0
rel=[0 for _ in range(n)]
for j in range(n):
if (i>>j)&1:
rel[j]=1
m+=1
for j in range(n):
for q in range(len(tes[j])//2):
if rel[j]==1 and tes[j][2*q+1]!=rel[tes[j][2*q]-1]:
f=1
if f==0:
ans.append(m)
print(max(ans))
| N = int(input())
table = []
for i in range(N):
A = int(input())
dic = {}
for j in range(A):
x,y = map(int, input().split())
dic[x-1] = y
table.append(dic)
res = 0
for i in range(2**N):
bi = [j for j in range(N) if (i >> j &1)]
dic = {}
for b in bi:
dic[b] = 1
endfor = False
for b1 in bi:
if endfor:
break
said = table[b1]
for k in said.keys():
if k not in dic.keys():
if said[k]:
endfor = True
break
dic[k] = said[k]
elif dic[k] == said[k]:
continue
else:
endfor = True
break
if not endfor:
res = max(res, len(bi))
print(res) | 1 | 121,935,243,353,440 | null | 262 | 262 |
n, m = map(int,input().split())
a = [[0]*m for i in range(n)]
b = [0]*m
for i in range(n):
a[i] = list(map(int,input().split()))
for j in range(m):
b[j] = int(input())
c = [0]*n
for i in range(n):
for j in range(m):
c[i] += a[i][j] * b[j]
for i in c:
print(i)
| [n, m] = [int(x) for x in raw_input().split()]
A = [[0] * m for x in range(n)]
B = [0] * m
counter = 0
while counter < n:
A[counter] = [int(x) for x in raw_input().split()]
counter += 1
counter = 0
while counter < m:
B[counter] = int(raw_input())
counter += 1
counter = 0
while counter < n:
result = 0
for j in range(m):
result += A[counter][j] * B[j]
print(result)
counter += 1 | 1 | 1,140,916,890,600 | null | 56 | 56 |
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def main():
N = INT()
A = LI()
RGB = [0,0,0]
answer = 1
MOD = 10**9+7
for i in range(N):
if RGB.count(A[i]) == 0:
print(0)
return
answer *= RGB.count(A[i])
answer %= MOD
for j in range(3):
if RGB[j] == A[i]:
RGB[j] += 1
break
print(answer)
return
if __name__ == '__main__':
main()
| from collections import *
from heapq import *
import sys
input=lambda :sys.stdin.readline().rstrip()
N=int(input())
A=list(map(int,input().split()))
mod=10**9+7
count=1
lst=[0,0,0]
for a in A:
data=[i for i in range(3) if lst[i] == a]
if not data:
count=0
break
count*=len(data)
count%=mod
i=data[0]
lst[i]+=1
print(count)
| 1 | 130,274,728,184,452 | null | 268 | 268 |
def main():
N = int(input())
*A, = map(int, input().split())
ans = sum(A[i] & 1 for i in range(0, N, 2))
print(ans)
if __name__ == '__main__':
main()
| a=[input() for i in range(2)]
a1=int(a[0])
a2=[int(i) for i in a[1].split()]
money=1000
kabu=0
for i in range(a1-1):
if a2[i]<a2[i+1]:
kabu=int(money/a2[i])
money+=kabu*(a2[i+1]-a2[i])
print(money) | 0 | null | 7,537,199,221,188 | 105 | 103 |
def f(nums, K, w):
h=len(nums)
counter=[nums[x][0] for x in range(h)]
if max(counter)>K:
return float('inf')
out=0
for i in range(1, w):
for x in range(h):
counter[x]+=nums[x][i]
if max(counter)>K:
out+=1
counter=[nums[x][i] for x in range(h)]
return out
H, W, K=map(int, input().split())
S=[input() for _ in range(H)]
S=[[int(S[i][j]) for j in range(W)] for i in range(H)]
ans=float('inf')
for p in range(2**(H-1)):
q='0'+format(p, '0'+str(H-1)+'b')+'1'
i=0
c=0
nums=[]
while i<H:
j=1
while i+j<H and q[i+j]=='0':
j+=1
tmp=S[i:i+j]
nums.append([sum([tmp[y][x] for y in range(j)]) for x in range(W)])
i+=j
cand=f(nums, K, W)+q.count('1')-1
if ans>cand:
ans=cand
print(ans) | # import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque
# from decorator import stop_watch
#
#
# @stop_watch
def solve(H, W, K, Si):
Si = [[int(i) for i in S] for S in Si]
ans = H + W
for i in range(2 ** (H - 1)):
h_border = bin(i).count('1')
w_border = 0
white_counts = [0] * (h_border + 1)
choco_w = 0
for w in range(W):
choco_w += 1
wc_num = 0
tmp_count = [0] * (h_border + 1)
for h in range(H):
white_counts[wc_num] += Si[h][w]
tmp_count[wc_num] += Si[h][w]
if i >> h & 1:
wc_num += 1
if max(white_counts) > K:
if choco_w == 1:
break # 1列の時点で > K の場合は条件を達成できない
w_border += 1
white_counts = tmp_count
choco_w = 1
else:
ans = min(ans, h_border + w_border)
print(ans)
if __name__ == '__main__':
H, W, K = map(int, input().split())
Si = [input() for _ in range(H)]
solve(H, W, K, Si)
# # test
# from random import randint
# from func import random_str
#
# H, W, K = 10, 1000, randint(1, 100)
# Si = [random_str(W, '01') for _ in range(H)]
# print(H, W, K)
# for S in Si:
# print(S)
# solve(H, W, K, Si)
| 1 | 48,823,428,849,692 | null | 193 | 193 |
n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=input()
t2 = [[] for _ in range(k)]
score = [0]*n
for i,c in enumerate(t):
t2[i%k].append(c)
score = {'r':p,'s':r,'p':s}
total = 0
for t3 in t2:
if len(t3)==0: continue
if len(t3)==1:
total += score[t3[0]]
continue
for i in range(len(t3)-1):
if t3[i] == 'e': continue
total += score[t3[i]]
if t3[i] == t3[i+1]:
t3[i+1]='e'
if t3[-1] != 'e':
total += score[t3[-1]]
print(total)
| n, k = map(int,input().split())
a = list(map(int,input().split()))
l = [0]*n
i=0
cnt=0
while l[i]==0:
l[i] = a[i]
i = a[i]-1
cnt += 1
start = i+1
i = 0
pre = 0
while i+1!=start:
i = a[i]-1
pre += 1
loop = cnt-pre
if pre+loop<k:
k=(k-pre)%loop+pre
i = 0
for _ in range(k):
i = a[i]-1
print(i+1) | 0 | null | 64,773,654,057,190 | 251 | 150 |
import collections
N=int(input())
S=[""]*N
for i in range(N):
S[i]=input()
print(len(collections.Counter(S))) | 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
n = int(input())
if is_prime(n):
print(n -1)
exit()
ans = n
for k in range(2, int(math.sqrt(n)) + 1):
if n % k == 0:
temp_1 = n/k
temp_2 = k
ans = min(ans,temp_1 + temp_2)
print(int(ans-2))
| 0 | null | 96,320,944,397,450 | 165 | 288 |
# Reference: https://qiita.com/dn6049949/items/afa12d5d079f518de368
# self.data: 1-indexed
# __1__
# _2_ _3_
# 4 5 6 7
# f(f(a, b), c) == f(a, f(b, c))
class SegmentTree:
# a = [default] * n
# O(n)
def __init__(self, n, f=max, default=-2**30):
self.num_leaf = 2 ** (n-1).bit_length()
self.data = [default] * (2*self.num_leaf)
self.f = f
# a[i] = x
# O(log(n))
def update(self, i, x):
i += self.num_leaf
self.data[i] = x
i >>= 1
while i > 0:
self.data[i] = self.f(self.data[2*i], self.data[2*i+1])
i >>= 1
# return f(a[l:r])
# O(log(n))
def query(self, l, r):
l += self.num_leaf
r += self.num_leaf - 1
lres, rres = self.data[0], self.data[0] # self.data[0] == default
while l < r:
if l & 1:
lres = self.f(lres, self.data[l])
l += 1
if not r & 1:
rres = self.f(self.data[r], rres)
r -= 1
l >>= 1
r >>= 1
if l == r:
res = self.f(self.f(lres, self.data[l]), rres)
else:
res = self.f(lres, rres)
return res
# You can use min_index only if f == max.
# return min({i | x <= i and v <= a[i]}, self.num_leaf)
# O(log(n))
def min_index(self, x, v):
x += self.num_leaf
while self.data[x] < v:
if x & 1:
if x.bit_length() == (x+1).bit_length():
x += 1
else:
return self.num_leaf
else:
x >>= 1
while x < self.num_leaf:
if self.data[2*x] >= v:
x = 2*x
else:
x = 2*x + 1
return x - self.num_leaf
from sys import stdin
def input():
return stdin.readline().strip()
def main():
n = int(input())
s = list(input())
forest = [SegmentTree(n, f=max, default=0) for _ in range(26)]
for ind, si in enumerate(s):
forest[ord(si) - 97].update(ind, 1)
q = int(input())
ans = []
for _ in range(q):
typ, l, r = input().split()
l = int(l) - 1
if typ == '1':
forest[ord(s[l]) - 97].update(l, 0)
s[l] = r
forest[ord(r) - 97].update(l, 1)
else:
cnt = 0
for tree in forest:
if tree.min_index(l, 1) < int(r):
cnt += 1
ans.append(cnt)
for i in ans:
print(i)
main() | n = int(input())
s = input()
table = {x: 2**i for i, x in enumerate(map(chr, range(97, 123)))}
SEG_LEN = n
SEG = [0]*(SEG_LEN*2)
def update(i, x):
i += SEG_LEN
SEG[i] = table[x]
while i > 0:
i //= 2
SEG[i] = SEG[i*2] | SEG[i*2+1]
def find(left, right):
left += SEG_LEN
right += SEG_LEN
ans = 0
while left < right:
if left % 2 == 1:
ans = SEG[left] | ans
left += 1
left //= 2
if right % 2 == 1:
ans = SEG[right-1] | ans
right -= 1
right //= 2
return format(ans, 'b').count('1')
for i, c in enumerate(s):
update(i, c)
q = int(input())
for _ in range(q):
com, *query = input().split()
if com == '1':
idx, x = query
update(int(idx)-1, x)
else:
L, R = map(int, query)
print(find(L-1, R))
| 1 | 62,690,532,027,540 | null | 210 | 210 |
a,b,c,d = map(int, input().split())
ans = -10**18
ans = max(ans, a*c)
ans = max(ans, a*d)
ans = max(ans, b*c)
ans = max(ans, b*d)
print(ans) | a, b, c , d = map(int, input().split())
M = b * d;
if M < a * c:
M = a*c;
if M < b * c:
M = b*c;
if M < a * d:
M = a * d;
print (M); | 1 | 3,080,445,966,120 | null | 77 | 77 |
n, k = map(int, input().split()); m = 998244353; a = []
for i in range(k): a.append(list(map(int, input().split())))
b = [0]*n; b.append(1); c = [0]*n; c.append(1)
for i in range(1, n):
d = 0
for j in range(k): d = (d+c[n+i-a[j][0]]-c[n+i-a[j][1]-1])%m
b.append(d); c.append(c[-1]+d)
print(b[-1]%m) | import sys
# input = sys.stdin.readline
def main():
A,B = map(int,input().split())
if A//10 +B//10 >0:
print(-1)
else:
print(A*B)
if __name__ == "__main__":
main() | 0 | null | 80,676,254,706,200 | 74 | 286 |
N = int(input())
A = list(map(int,input().split()))
count = 0
for i in range(0,N,2):
if A[i]%2 != 0:
count += 1
print(count) | from math import floor,ceil,sqrt,factorial,log
from collections import Counter, deque
from functools import reduce
import numpy as np
import itertools
def S(): return input()
def I(): return int(input())
def MS(): return map(str,input().split())
def MI(): return map(int,input().split())
def FLI(): return [int(i) for i in input().split()]
def LS(): return list(MS())
def LI(): return list(MI())
def LLS(): return [list(map(str, l.split() )) for l in input()]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def LLSN(n: int): return [LS() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
N = I()
A = LI()
cnt = 0
for i in range(N):
if (i+1) % 2 != 1:
continue
if A[i] % 2 == 1:
cnt += 1
print(cnt)
| 1 | 7,816,208,384,910 | null | 105 | 105 |
n = int(input())
res = {"AC": 0, "WA": 0, "TLE": 0, "RE": 0}
for _ in range(n):
seq = input()
res[seq] += 1
for key in res.keys():
print(f"{key} x {res[key]}") | import sys
import numpy as np
from math import ceil as C, floor as F, sqrt
from collections import defaultdict as D, Counter as CNT
from functools import reduce as R
ALP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
alp = 'abcdefghijklmnopqrstuvwxyz'
def _X(): return sys.stdin.readline().rstrip().split(' ')
def _S(ss): return tuple(ss) if len(ss) > 1 else ss[0]
def S(): return _S(_X())
def Ss(): return list(S())
def _I(ss): return tuple([int(s) for s in ss]) if isinstance(ss, tuple) else int(ss)
def I(): return _I(S())
def _Is(ss): return list(ss) if isinstance(ss, tuple) else [ss]
def Is(): return _Is(I())
n = I()
ans = D(int)
for _ in range(n):
s = S()
ans[s] += 1
for x in ['AC', 'WA', 'TLE', 'RE']:
print('{} x {}'.format(x, ans[x])) | 1 | 8,606,661,933,310 | null | 109 | 109 |
# -*- coding: utf-8 -*-
N = int(input().strip())
A_list = list(map(int, input().rstrip().split()))
#-----
# A_index[i] = ( value of A , index of A)
A_index = [ (A_list[i], i) for i in range(len(A_list)) ]
A_index.sort(reverse=True)
# dp[left][right] = score
dp = [ [0]*(N+1) for _ in range(N+1) ]
for L in range(N):
for R in range(N-L):
i = L + R
append_L = dp[L][R] + A_index[i][0] * abs(L - A_index[i][1])
append_R = dp[L][R] + A_index[i][0] * abs((N-1-R) - A_index[i][1])
dp[L+1][R] = max(dp[L+1][R], append_L)
dp[L][R+1] = max(dp[L][R+1], append_R)
ans = max( [ dp[i][N-i] for i in range(N+1)] )
print(ans)
| # 素因数分解
N=int(input())
cand=[]
def check(N0,K0):
if N0%K0==0:
return check(int(N0/K0),K0)
elif N0%K0==1:
return 1
else:
return 0
def check0(N0,K0):
while N0%K0==0:
N0=int(N0/K0)
if N0%K0==1:
return 1
else:
return 0
# N-1の約数の数
for i in range(2,int((N-1)**0.5)+1):#O(N**0.5)
if (N-1)%i==0:
cand.append(i)
if i!=int((N-1)/i):
cand.append(int((N-1)/i))
if N>2:
cand.append(N-1)
# Nの約数
for i in range(2,int(N**0.5)+1):#O(N**0.5)
if N%i==0:
cand.append(i)
if i!=int(N/i):
cand.append(int(N/i))
cand.append(N)
#print(cand)
count=0
for i in range(len(cand)):
if check(N,cand[i]):
count+=1
print(count) | 0 | null | 37,559,750,133,860 | 171 | 183 |
ini = lambda : int(input())
inm = lambda : map(int,input().split())
inl = lambda : list(map(int,input().split()))
gcd = lambda x,y : gcd(y,x%y) if x%y else y
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 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()
return divisors
n,m = inm()
h = inl()
p = [True] * n
for i in range(m):
a,b = inm()
a -= 1
b -= 1
if h[a] >= h[b]:
p[b] = False
if h[b] >= h[a]:
p[a] = False
ans = sum(p)
print(ans) | def main():
today = input().split()
tomo = input().split()
if today[0] == tomo[0]:
print(0)
else:
print(1)
if __name__ == '__main__':
main()
| 0 | null | 74,459,726,220,148 | 155 | 264 |
n = int(input())
lst = list(input())
ans = []
for i in range(1000):
s = str(i).zfill(3)
pos = 0
is_exist = True
for j in range(3):
if s[j] in lst[pos:]:
pos += lst[pos:].index(s[j]) + 1
else:
is_exist = False
break
if is_exist:
ans.append(s)
print(len(ans))
| def main():
n = int(input())
s = input()
one_set = set([])
two_set = set([])
three_set = set([])
count = 0
for i in range(n):
if i==0:
one_set.add(s[0])
continue
if 2<=i:
for two in two_set:
if two + s[i] not in three_set:
three_set.add(two + s[i])
count+=1
for one in one_set:
two_set.add(one + s[i])
one_set.add(s[i])
print(count)
if __name__=="__main__":
main()
| 1 | 128,756,049,626,820 | null | 267 | 267 |
from collections import Counter
n = int(input())
A = list(map(int, input().split()))
ANS = sum(A)
A = Counter(A)
Q = int(input())
for i in range(Q):
B, C = map(int, input().split())
print(ANS + (C - B) * A[B])
ANS += (C - B) * A[B]
A[C] = A[C] + A[B]
A[B] = 0
| import collections
def main():
n = int(input())
a = list(map(int, input().split()))
q = int(input())
a_dict = collections.Counter(a)
a_dict = {key: key*value for key, value in a_dict.items()}
answer = sum(a_dict.values())
for _ in range(q):
b, c = map(int, input().split())
diff = 0
if b in a_dict:
b_sum = a_dict.pop(b)
c_add = b_sum//b * c
diff = c_add - b_sum
if c in a_dict:
a_dict[c] += c_add
else:
a_dict[c] = c_add
answer += diff
print(answer)
if __name__ == '__main__':
main()
| 1 | 12,211,125,316,978 | null | 122 | 122 |
n=int(input())
a=list(map(int,input().split()))
tot=sum(a)
b=0
c=10**10
d=0
for i in range(n):
b+=a[i]
d=abs(tot/2 - b)
if d<c:
c=d
print(int(2*c)) | n,k = map(int, input().split())
for i in range(50):
if n < pow(k,i):
print(i)
exit() | 0 | null | 103,526,902,458,708 | 276 | 212 |
import math
a,b=map(int,input().split())
for i in range (11000):
if a <= i*0.08 <a+1:
if b<= i*0.1 <b+1:
print(i)
exit()
print(-1) | a, b = map(int,input().split())
cnt = 0
for i in range(1,1010):
A = int(i * 8 //100)
B = int(i * 10 //100)
if (A == a) and (B == b):
print(i)
cnt += 1
break
if cnt == 0:
print(-1) | 1 | 56,494,689,771,740 | null | 203 | 203 |
N,K = map(int,input().split())
A = list(map(int,input().split()))
wa = [0] * (N+1)
for i in range(N):
wa[i+1] = wa[i] + (A[i]+1)/2
Max = 0
for i in range(N-K+1):
Max = max(Max,wa[K+i]-wa[i])
print(Max)
| N=int(input())
right=0
left=0
for i in range(N):
a,b=input().split()
if a>b:
left+=3
elif a<b:
right+=3
else:
left+=1
right+=1
print(f"{left} {right}")
| 0 | null | 38,529,280,715,548 | 223 | 67 |
N,A,B=map(int,input().split())
sho,amri = divmod(N,(A+B))
if amri > A:
amri = A
print(A*sho+amri) | a, b, c, d = map(int, input().split())
x = [a, b]
y = [c, d]
ans = -1e30
for i in x:
for j in y:
ans = max(ans, i*j)
print(ans) | 0 | null | 29,476,602,441,790 | 202 | 77 |
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
a, b = input().split()
a = int(a)
b = int(b[0]+b[2:4])
print(a*b//100)
if __name__=='__main__':
main() | import math
#A , B = map(float,input().split())
a , b = input().split()
a = int(a)
b = round(100*float(b))
#ans = int (A *(B*100)/100)
print(a*b//100)
| 1 | 16,614,923,352,018 | null | 135 | 135 |
# coding:UTF-8
import sys
from math import factorial
MOD = 998244353
INF = 10000000000
def main():
n, k = list(map(int, input().split())) # スペース区切り連続数字
lrList = [list(map(int, input().split())) for _ in range(k)] # スペース区切り連続数字(行列)
s = []
for l, r in lrList:
for i in range(l, r+1):
s.append(i)
s.sort()
sum = [0] * (n + 1)
Interm = [0] * (2 * n + 1)
sum[1] = 1
for i in range(1, n):
for j in range(k):
l, r = lrList[j][0], lrList[j][1]
Interm[i+l] += sum[i]
Interm[i+r+1] -= sum[i]
sum[i+1] = (sum[i] + Interm[i+1]) % MOD
# result = Interm[n]
result = (sum[n] - sum[n-1]) % MOD
# ------ 出力 ------#
print("{}".format(result))
if __name__ == '__main__':
main()
| # -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from fractions import Fraction
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations, accumulate
from operator import add, mul, sub, itemgetter, attrgetter
import sys
sys.setrecursionlimit(10**6)
# readline = sys.stdin.buffer.readline
readline = sys.stdin.readline
INF = 1 << 60
def read_int():
return int(readline())
def read_int_n():
return list(map(int, readline().split()))
def read_float():
return float(readline())
def read_float_n():
return list(map(float, readline().split()))
def read_str():
return readline().strip()
def read_str_n():
return readline().strip().split()
def ep(*args):
print(*args, file=sys.stderr)
def mt(f):
import time
def wrap(*args, **kwargs):
s = time.perf_counter()
ret = f(*args, **kwargs)
e = time.perf_counter()
ep(e - s, 'sec')
return ret
return wrap
@mt
def slv(N, K, LR):
M = 998244353
memo = [0] *(N+2)
memo[1] = 1
memo[1+1] = -1
for i in range(1, N+1):
memo[i] += memo[i-1]
memo[i] %= M
for l, r in LR:
ll = min(N+1, i+l)
rr = min(N+1, i+r+1)
memo[ll] += memo[i]
memo[ll] %= M
memo[rr] -= memo[i]
memo[rr] %= M
return memo[N]
def main():
N, K = read_int_n()
LR = [read_int_n() for _ in range(K)]
print(slv(N, K, LR))
if __name__ == '__main__':
main()
| 1 | 2,709,156,058,142 | null | 74 | 74 |
# -*- coding: utf-8 -*-
from sys import stdin
input = stdin.readline
def main():
a, b, c, d = list(map(int,input().split()))
print(max([a*c, a*d, b*c, b*d]))
if __name__ == "__main__":
main()
| a, b, c, d = map(int, input().split(" "))
print(max([i for i in [i*j for i in (a, b) for j in (c,d)]])) | 1 | 3,020,088,312,410 | null | 77 | 77 |
S=list(input())
n=len(S)
for i in range(n):
S[i]=int(S[i])
k=int(input())
dp0=[[0]*(n+1) for i in range(k+1)]
dp0[0][0]=1
s=0
for i in range(n):
if S[i]!=0:
s=s+1
if s==k+1:
break
dp0[s][i+1]=1
else:
dp0[s][i+1]=1
dp1=[[0]*(n+1) for i in range(k+1)]
for i in range(1,n+1):
if dp0[0][i]==0:
dp1[0][i]=1
for i in range(1,k+1):
for j in range(1,n+1):
if S[j-1]==0:
dp1[i][j]=dp0[i-1][j-1]*0+dp0[i][j-1]*0+dp1[i-1][j-1]*9+dp1[i][j-1]
else:
dp1[i][j]=dp0[i-1][j-1]*(S[j-1]-1)+dp0[i][j-1]+dp1[i-1][j-1]*9+dp1[i][j-1]
print(dp0[-1][-1]+dp1[-1][-1]) | s = input()
n = len(s)
t = s[:(n-1)//2]
u = s[(n+3)//2-1:]
if (s == s[::-1]
and t == t[::-1]
and u == u[::-1]):
print('Yes')
else:
print('No')
| 0 | null | 61,038,455,855,062 | 224 | 190 |
from math import *
def modpow(a,n,m):
res=1
while n>0:
if n&1:res=res*a%m
a=a*a%m
n//=2
return res
n,a,b=map(int,input().split())
mod=10**9+7
ans=modpow(2,n,mod)-1
na=1
nb=1
for i in range(a):
na*=(n-i)%mod
na%=mod
fa=1
for i in range(1,a+1):
fa*=i
fa%=mod
na*=modpow(fa,mod-2,mod)
for i in range(b):
nb*=(n-i)%mod
nb%=mod
fb=1
for i in range(1,b+1):
fb*=i
fb%=mod
nb*=modpow(fb,mod-2,mod)
print((ans-nb-na)%mod) | def mod_pow(a, n, mod):
"""
二分累乗法による a^n (mod m)の実装
:param a: 累乗の底
:param n: 累乗の指数
:param mod: 法
:return: a^n (mod m)
"""
result = 1
a_n = a
while n > 0:
if n & 1:
result = result * a_n % mod
a_n = a_n * a_n % mod
n >>= 1
return result
def mod_inverse(a, mod):
"""
フェルマーの小定理による a^-1 ≡ 1 (mod m)の実装
aの逆元を計算する
a^-1 ≡ 1 (mod m)
a * a^-2 ≡ 1 (mod m)
a^-2 ≡ a^-1 (mod m)
:param a: 逆元を計算したい数
:param mod: 法
:return: a^-1 ≡ 1 (mod m)
"""
return mod_pow(a=a, n=mod - 2, mod=mod)
def mod_combination(n, k, mod):
fact_n = 1
fact_k = 1
for i in range(k):
fact_n *= (n - i)
fact_n %= mod
fact_k *= (i + 1)
fact_k %= mod
fact_n *= mod_inverse(fact_k, mod)
return fact_n % mod
N, A, B = map(int, input().split(' '))
MOD = 10 ** 9 + 7
print((mod_pow(2, N, MOD) - 1 - mod_combination(N, A, MOD) - mod_combination(N, B, MOD)) % MOD)
| 1 | 66,334,924,779,292 | null | 214 | 214 |
#!/usr/bin/env python3
import collections as cl
import sys
def II():
return int(sys.stdin.readline())
def MI():
return map(int, sys.stdin.readline().split())
def LI():
return list(map(int, sys.stdin.readline().split()))
def main():
N = II()
counter = cl.Counter()
for i in range(N):
s = input()
counter.update({s: 1})
item, value = zip(*counter.most_common())
ans = []
max_num = value[0]
for i in range(len(value)):
if value[i] == max_num:
ans.append(item[i])
ans.sort()
print(*ans, sep="\n")
main()
| from collections import Counter
n = int(input())
d = list(input() for _ in range(n))
D = Counter(d)
m = max(D.values())
l = []
for i,j in D.most_common():
if m != j:
break
l.append(i)
l.sort()
for i in l:
print(i) | 1 | 69,992,541,596,042 | null | 218 | 218 |
K = int(input())
Ans = 'ACL'
for i in range(K-1):
Ans += 'ACL'
print(Ans) | K = int(input())
a = "ACL"
ans = ""
for i in range(K):
ans += a
print(ans)
| 1 | 2,211,694,963,074 | null | 69 | 69 |
n,m=map(int,input().split())
h=list(map(int,input().split()))
AB=[list(map(int,input().split())) for _ in range(m)]
from math import gcd
ans=[1 for _ in range(n)]
for ab in AB:
if h[ab[0]-1]>h[ab[1]-1]:
ans[ab[1]-1]=0
elif h[ab[0]-1]<h[ab[1]-1]:
ans[ab[0]-1]=0
else:
ans[ab[0]-1]=0
ans[ab[1]-1]=0
print(sum(ans)) | n,a,b = map(int,input().split())
if (a+b) % 2 == 0:
print(b - (a+b)//2)
else:
if a <= n-b+1:
b -= a
print(a + b-(1+b)//2)
else:
a += n-b+1
print(n-b+1 + n - (n+a)//2)
| 0 | null | 67,423,992,605,540 | 155 | 253 |
number, base = map(int, input().split())
result_list = []
while number / base > 0:
mod = number % base
result_list.append(str(mod))
number = number // base
result_list.reverse()
result = "".join(result_list)
print(len(result))
| import itertools
import functools
import math
from collections import Counter
from itertools import combinations
import re
N,K=map(int,input().split())
cnt = 1
while True:
if cnt > 10000:
break
if N // K**cnt == 0:
print(cnt)
exit()
cnt += 1
| 1 | 64,612,631,747,146 | null | 212 | 212 |
N = int(input())
arr = list(map(int, input().split()))
s = 0
for i in range(N):
s ^= arr[i]
for i in range(N):
arr[i] ^= s
print(' '.join(map(str, arr))) | print(sum(map(lambda x:int(x)*(int(x)-1)//2,input().split()))) | 0 | null | 29,095,922,130,928 | 123 | 189 |
N,M = map(int,input().split())
H = list(map(int,input().split()))
mx = [0 for i in range(N)]
for _ in range(M):
a,b = map(int,input().split())
a -= 1
b -= 1
mx[a] = max(mx[a], H[b])
mx[b] = max(mx[b], H[a])
ans = 0
for i in range(N):
if H[i] > mx[i]:
ans += 1
print(ans) | n=input()
a=input().split()
sum=0
for i in range(len(a)):
a[i]=(int)(a[i])
for i in a:
sum+=i
ans=0
ans+=(sum**2)
for i in a:
ans-=i*i
print((ans//2)%(10**9+7)) | 0 | null | 14,500,000,844,890 | 155 | 83 |
#!/usr/bin/env python3
import sys
import math
# from string import ascii_lowercase, ascii_upper_case, ascii_letters, digits, hexdigits
# import re # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from operator import itemgetter # itemgetter(1), itemgetter('key')
# from collections import deque # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict # subclass of dict. defaultdict(facroty)
# from collections import Counter # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
from itertools import starmap # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
from itertools import product, permutations # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate # accumulate(iter[, f])
# from functools import reduce # reduce(f, iter[, init])
# from functools import lru_cache # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy # to copy multi-dimentional matrix without reference
# from fractions import gcd # for Python 3.4 (previous contest @AtCoder)
def main():
mod = 1000000007 # 10^9+7
inf = float('inf') # sys.float_info.max = 1.79...e+308
# inf = 2 ** 64 - 1 # (for fast JIT compile in PyPy) 1.84...e+19
sys.setrecursionlimit(10**6) # 1000 -> 1000000
def input(): return sys.stdin.readline().rstrip()
def ii(): return int(input())
def mi(): return map(int, input().split())
def mi_0(): return map(lambda x: int(x)-1, input().split())
def lmi(): return list(map(int, input().split()))
def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
def li(): return list(input())
n = ii()
# naive, O(nlgn)
# cnt = 0
# for k in range(2, n + 1):
# tmp = n
# if tmp % k == 1:
# cnt += 1
# elif tmp % k == 0:
# while tmp >= k and tmp % k == 0:
# tmp //= k
# if tmp % k == 1:
# cnt += 1
# print(cnt)
class Eratos:
def __init__(self, num):
assert(num >= 1)
self.table_max = num
# self.table[i] は i が素数かどうかを示す (bool)
self.table = [False if i == 0 or i == 1 else True for i in range(num+1)]
for i in range(2, int(math.sqrt(num)) + 1):
if self.table[i]:
for j in range(i ** 2, num + 1, i): # i**2 からスタートすることで定数倍高速化できる
self.table[j] = False
# self.table_max 以下の素数を列挙したリスト
self.prime_numbers = [2] if self.table_max >= 2 else []
for i in range(3, self.table_max + 1, 2):
if self.table[i]:
self.prime_numbers.append(i)
def is_prime(self, num):
"""
>>> e = Eratos(100)
>>> [i for i in range(1, 101) if e.is_prime(i)]
[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]
"""
assert(num >= 1)
if num > self.table_max:
raise ValueError('Eratos.is_prime(): exceed table_max({}). got {}'.format(self.table_max, num))
return self.table[num]
def prime_factorize(self, num):
"""
>>> e = Eratos(10000)
>>> e.prime_factorize(6552)
{2: 3, 3: 2, 7: 1, 13: 1}
"""
assert(num >= 1)
if int(math.sqrt(num)) > self.table_max:
raise ValueError('Eratos.prime_factorize(): exceed prime table size. got {}'.format(num))
factorized_dict = dict() # 素因数分解の結果を記録する辞書
candidate_prime_numbers = [i for i in range(2, int(math.sqrt(num)) + 1) if self.is_prime(i)]
# n について、√n 以下の素数で割り続けると最後には 1 or 素数となる
# 背理法を考えれば自明 (残された数が √n より上の素数の積であると仮定。これは自明に n を超えるため矛盾)
for p in candidate_prime_numbers:
# これ以上調査は無意味
if num == 1:
break
while num % p == 0:
num //= p
try:
factorized_dict[p]
except KeyError:
factorized_dict[p] = 0
finally:
factorized_dict[p] += 1
if num != 1:
factorized_dict[num] = 1
return factorized_dict
eratos = Eratos(int(math.sqrt(n)))
d_1 = eratos.prime_factorize(n - 1)
# n = k + 1, 2k + 1, 3k + 1, ...
cnt = 0
tmp = 1
for _, v in d_1.items():
tmp *= (v + 1)
tmp -= 1
cnt += tmp
d_2 = eratos.prime_factorize(n)
# 全約数 x (除: 1) について (n // x) ≡ 1 (mod x) なら cnt += 1とすればいいのでは
# 約数の個数は高々 2√n 個なので間に合いそう?
L = [range(v + 1) for _, v in d_2.items()]
power_list = list(product(*L))
prime_list = list(d_2.keys())
for elm in power_list:
# elm は具体的な各素数の指数を指定したリストである
div = 1
for i in range(len(prime_list)):
div *= pow(prime_list[i], elm[i])
# print(f"div: {div}")
if div != 1:
assert(n % div == 0)
copy_n = n
while copy_n % div == 0:
copy_n //= div
if copy_n % div == 1:
cnt += 1
print(cnt)
if __name__ == "__main__":
main()
| j = 0
i = 1
k = int(raw_input())
while j < 3:
i *= k
j = j + 1
print i | 0 | null | 20,925,269,340,874 | 183 | 35 |
A,B,M=map(int,input().split())
aa=list(map(int,input().split()))
bb=list(map(int,input().split()))
XC=[]
for i in range(M):
XC.append(list(map(int,input().split())))
ans=min(aa)+min(bb)
for i in range(M):
ans=min(ans,aa[XC[i][0]-1]+bb[XC[i][1]-1]-XC[i][2])
print(ans) | a,b,C=map(float,input().split())
import math
S=0.5*a*b*math.sin(math.radians(C))
print('{:.8f}'.format(S))
print('{:.8f}'.format(a+b+math.sqrt(pow(a,2)+pow(b,2)-2*a*b*math.cos(math.radians(C)))))
print('{:.8f}'.format(S*2/a))
| 0 | null | 27,173,077,764,248 | 200 | 30 |
def main():
n = int(input())
points = [0, 0]
for i in range(n):
t, h = input().split(' ')
points = map(lambda x, y: x+y, points, judge(t, h))
print("{0[0]} {0[1]}".format(list(points)))
def judge(t, h):
if t < h:
return (0, 3)
elif t > h:
return (3, 0)
return (1, 1)
if __name__ == '__main__': main() | import sys
n = int(sys.stdin.readline())
points = [0, 0]
for i in range(n):
(taro, hanako) = sys.stdin.readline().split()
if taro < hanako:
points[1] += 3
elif taro > hanako:
points[0] += 3
else:
points[0] += 1
points[1] += 1
print(points[0], points[1]) | 1 | 2,028,350,189,238 | null | 67 | 67 |
n = int(input())
cnt = [0] * (n+100)
A = list(map(int, input().split()))
for a in A:
cnt[a] += 1
for i in range(n):
print(cnt[i+1])
| n = int(input())
a = list(map(int, input().split()))
sub_list = [0] * n
for i in (a):
sub_list[i - 1] += 1
for i in range(n):
print(sub_list[i], sep = ',')
| 1 | 32,579,165,333,638 | null | 169 | 169 |
S = str(input())
T = "x" * len(S)
print(T) | s=input()
lis=list(s)
n=len(lis)
X=["x" for i in range(n)]
print("".join(X)) | 1 | 72,825,611,841,220 | null | 221 | 221 |
import sys
def gcd(m, n):
if n != 0:
return gcd(n, m % n)
else:
return m
for line in sys.stdin.readlines():
m, n = map(int, line.split())
g = gcd(m, n)
l = m * n // g # LCM
print(g, l) | #coding:utf-8
while True:
try:
a, b = map(int, raw_input(). split())
x = a * b
while True:
c = a % b
a = b
b = c
if b == 0:
break
x = x / a
print("%d %d" % (a, x))
except:
break | 1 | 528,173,282 | null | 5 | 5 |
import math
def main():
a, b, C = map(int, input().split())
C /= 180
C *= math.pi
S = 1 / 2 * a * b * math.sin(C)
L = math.sqrt(a ** 2 + b ** 2 - 2 * a * b * math.cos(C)) + a + b
h = 2 * S / a
print(S)
print(L)
print(h)
if __name__ == "__main__":
main() | import math
a, b, C = [int(x) for x in input().split()]
C = math.radians(C)
l = a + b + math.sqrt(a * a + b * b - 2 * a * b * math.cos(C))
h = b * math.sin(C)
s = a * h / 2
print(s)
print(l)
print(h) | 1 | 171,785,031,968 | null | 30 | 30 |
import sys
from itertools import product
sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7
def resolve():
H, W, K = map(int, input().split())
grid = [list(input()) for _ in range(H)]
R = [[0] * (W + 1) for _ in range(H + 1)]
for h in range(H):
for w in range(W):
R[h + 1][w + 1] = R[h][w + 1] + R[h + 1][w] - R[h][w] + int(grid[h][w])
res = f_inf
for pattern in product([0, 1], repeat=H-1):
cut_H = [idx + 1 for idx, p in enumerate(pattern) if p == 1] + [H]
cnt_cut = sum(pattern)
left = 0
right = 1
flg = 1
while right <= W:
if not flg:
break
up = 0
for bottom in cut_H:
cnt_w = R[bottom][right] - R[bottom][left] - R[up][right] + R[up][left]
if cnt_w > K:
if right - left == 1:
flg = False
cnt_cut += 1
left = right - 1
break
else:
up = bottom
else:
right += 1
else:
res = min(res, cnt_cut)
print(res)
if __name__ == '__main__':
resolve()
| n = input()
A = list(map(int, input().split()))
print(*A)
for i in range(1, len(A)):
key = A[i]
j = i - 1
while j >= 0 and A[j] > key:
A[j+1] = A[j]
j -= 1
A[j+1] = key
print(*A) | 0 | null | 24,175,809,065,948 | 193 | 10 |
import sys
n, m, l = [ int( val ) for val in sys.stdin.readline().split( " " ) ]
matrixA = [ [ int( val ) for val in sys.stdin.readline().split( " " ) ] for row in range( n ) ]
matrixB = [ [ int( val ) for val in sys.stdin.readline().split( " " ) ] for row in range( m ) ]
matrixC = [ [ 0 for row in range( l ) ] for row in range( n ) ]
output = []
for i in range( n ):
for j in range( l ):
for k in range( m ):
matrixC[i][j] += ( matrixA[i][k] * matrixB[k][j] )
output.append( "{:d}".format( matrixC[i][j] ) )
output.append( " " )
output.pop()
output.append( "\n" )
output.pop()
print( "".join( output ) ) | n, m, l = map(int, input().split())
A = []
B = []
C = [[] for i in range(n)]
for i in range(n):
tmp_row = list(map(int, input().split()))
A.append(tmp_row)
for i in range(m):
tmp_row = list(map(int, input().split()))
B.append(tmp_row)
for i in range(n):
for j in range(l):
ab = sum([A[i][k] * B[k][j] for k in range(m)])
C[i].append(ab)
for i in C:
print(" ".join(map(str, i))) | 1 | 1,440,639,794,016 | null | 60 | 60 |
n = int(input())
h = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]
for _ in range(n):
b, f, r, v = [int(e) for e in input().split()]
h[b-1][f-1][r-1] += v
for i, b in enumerate(h):
if i != 0:
print('#'*20)
for f in b:
print(' ', end='')
print(*f) | # ??¬????????±
room = [[[0 for a in range(10)] for b in range(3)] for c in range(4)]
n = int(input())
for cnt0 in range(n):
# ?????°??????????????????
a,b,c,d = map(int,input().split())
room[a-1][b-1][c-1]+=d
# ???????????±??????
for cnt1 in range(4):
for cnt2 in range(3):
for cnt3 in range(10):
# OutputPrit
print(" "+str(room[cnt1][cnt2][cnt3]),end="")
# ??????
print ()
if cnt1<3:
# ????£???????####################(20??????#)?????????
print("#"*20) | 1 | 1,086,913,805,630 | null | 55 | 55 |
from os.path import split
def main():
X, Y, Z = map(int, input().split())
print(Z, X, Y)
if __name__ == '__main__':
main()
| import sys
sys.setrecursionlimit(10**9)
def main():
X,Y,A,B,C = map(int,input().split())
P = sorted(list(map(int,input().split())),reverse=True)
Q = sorted(list(map(int,input().split())),reverse=True)
R = list(map(int,input().split()))
print(sum(sorted(P[:X]+Q[:Y]+R,reverse=True)[:X+Y]))
if __name__ == "__main__":
main()
| 0 | null | 41,664,285,292,040 | 178 | 188 |
h, w, k = map(int, input().split())
tizu = [list(input()) for _ in range(h)]
ans = [[0 for _ in range(w)] for _ in range(h)]
pos = 0
bef = 0
bef_flg = True
for i in range(h):
pos_tmp = pos
f_st = False
if "#" in tizu[i]:
bef_flg = False
pos += 1
for j in range(w):
if tizu[i][j] == "#":
if f_st:
pos += 1
f_st = True
ans[i][j] = pos
else:
if bef_flg:
bef += 1
else:
for j in range(w):
ans[i][j] = ans[i - 1][j]
for i in range(bef - 1, -1, -1):
for j in range(w):
ans[i][j] = ans[i + 1][j]
for row in ans:
print(*row)
|
def resolve():
H, W, K = map(int, input().split())
G = [list(input()) for _ in range(H)]
ans = [[None] * W for _ in range(H)]
cnt = 1
for h in range(H):
for w in range(W):
if G[h][w] == "#":
ans[h][w] = cnt
cnt += 1
# 左から右
for h in range(H):
for w in range(1, W):
if ans[h][w] is None:
if ans[h][w - 1] is not None:
ans[h][w] = ans[h][w - 1]
# 右から左
for h in range(H):
for w in range(W - 1)[::-1]:
if ans[h][w] is None:
if ans[h][w + 1] is not None:
ans[h][w] = ans[h][w + 1]
# 上から下
for h in range(1, H):
for w in range(W):
if ans[h][w] is None:
ans[h][w] = ans[h - 1][w]
# 下から上
for h in range(H - 1)[::-1]:
for w in range(W):
if ans[h][w] is None:
if ans[h + 1][w] is not None:
ans[h][w] = ans[h + 1][w]
for h in range(H):
print(*ans[h])
if __name__ == "__main__":
resolve() | 1 | 144,070,973,593,878 | null | 277 | 277 |
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from collections import defaultdict
def main():
n, x, m = map(int, input().split())
d1 = defaultdict(int)
r = 0
while n:
if d1[x]:
cycle = d1[x] - n
t0 = 0
cycle2 = cycle
while cycle2:
t0 += x
x = x**2 % m
cycle2 -= 1
c, rem = divmod(n, cycle)
r += c * t0
while rem:
r += x
x = x**2 % m
rem -= 1
print(r)
sys.exit()
else:
d1[x] = n
r += x
x = x**2 % m
n -= 1
print(r)
if __name__ == '__main__':
main() | N, X, M = map(int, input().split())
id = [-1] * M
a = []
l = 0
tot = 0
while id[X] == -1:
a.append(X)
id[X] = l
l += 1
tot += X
X = X ** 2 % M
c = l - id[X]
s = 0
for i in range(id[X], l):
s += a[i]
ans = 0
if N <= l:
for i in range(N):
ans += a[i]
else:
ans += tot
N -= l
ans += s * (N // c)
N %= c
for i in range(N):
ans += a[id[X] + i]
print(ans)
| 1 | 2,824,595,245,882 | null | 75 | 75 |
from decimal import Decimal
p=3.141592653589
r=float(raw_input())
print Decimal(r*r*p),Decimal(r*2*p) | import math
r = input()
S = math.pi * r ** 2
L = math.pi * r * 2
print "%f %f" %(S, L) | 1 | 647,419,267,124 | null | 46 | 46 |
import sys
def dump(x):
print(x, file=sys.stderr)
n = int(input())
print(1-n)
| from math import ceil
def enum_divisor(n):
res = []
for i in range(1, int(n ** 0.5) + 1):
if n % i != 0:
continue
res.append(i)
if i * i != n:
res.append(n // i)
return res
ans = 0
n = int(input())
for x in enum_divisor(n):
if x == 1:
continue
tmp = n
while tmp % x == 0:
tmp //= x
if tmp % x == 1:
ans += 1
ans += len(enum_divisor(n - 1)) - 1
print(ans) | 0 | null | 22,003,564,328,902 | 76 | 183 |
x1, x2, x3, x4, x5 = map(int, input().split())
l = [x1, x2, x3, x4, x5]
print(l.index(0)+1) | x1, x2, x3, x4, x5 = map(int, input().split())
if (x1 == 0):
ans = 1
if (x2 == 0):
ans = 2
if (x3 == 0):
ans = 3
if (x4 == 0):
ans = 4
if (x5 == 0):
ans = 5
print(int(ans)) | 1 | 13,457,582,400,486 | null | 126 | 126 |
K=int(input())
A=0
for i in range(K):
A=(A*10+7)%K
if A%K==0:
print(i+1)
break
if i==K-1:print(-1) | ##未完成
N = int(input())
K = str(N)
l = len(str(N))
ans = 0
def tp(i,j,p):
tmp = 0
if p >= 2:
if l == p:
if i == int(K[0]):
if j > int(K[l-1]):
tmp = (N-int(K[0])*10**(l-1)-int(K[l-1]))//10
else:
tmp = (N-int(K[0])*10**(l-1)-int(K[l-1]))//10+1
elif i >= int(K[0]):
tmp = 0
else:
tmp = 10**(p-2)
elif l > p:
tmp = 10**(p-2)
return tmp
else:
if i == j and i <= N:
return 1
else:
return 0
for i in range(1,10):
for j in range(1,10):
for p in range(1,l+1):
for q in range(1,l+1):
ans += tp(i,j,p)*tp(j,i,q)
print(ans) | 0 | null | 46,386,773,773,952 | 97 | 234 |
# coding=utf-8
from math import floor, ceil, sqrt, factorial, log, gcd
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement, chain
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heappushpop, heapify
import copy
import sys
INF = float('inf')
mod = 10**9+7
sys.setrecursionlimit(10 ** 6)
def lcm(a, b): return a * b / gcd(a, b)
# 1 2 3
# a, b, c = LI()
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
# a = I()
def I(): return int(sys.stdin.buffer.readline())
# abc def
# a, b = LS()
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
# a = S()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
# 2
# 1
# 2
# [1, 2]
def IR(n): return [I() for i in range(n)]
# 2
# 1 2 3
# 4 5 6
# [[1,2,3], [4,5,6]]
def LIR(n): return [LI() for i in range(n)]
# 2
# abc
# def
# [abc, def]
def SR(n): return [S() for i in range(n)]
# 2
# abc def
# ghi jkl
# [[abc,def], [ghi,jkl]]
def LSR(n): return [LS() for i in range(n)]
# 2
# abcd
# efgh
# [[a,b,c,d], [e,f,g,h]]
def SRL(n): return [list(S()) for i in range(n)]
h, w = LI()
s = SRL(h)
ans = []
for i in range(h):
for j in range(w):
if s[i][j] == "#":
continue
v = [[-1] * w for _ in range(h)]
q = deque()
q.append((i, j))
v[i][j] = 1
goal = tuple()
while q:
r, c = q.popleft()
for x, y in ((1, 0), (-1, 0), (0, -1), (0, 1)):
if r + x < 0 or r + x > h - 1 or c + y < 0 or c + y > w - 1 or s[r + x][c + y] == "#" or v[r + x][c + y] > 0:
continue
v[r + x][c + y] = v[r][c] + 1
q.append((r + x, c + y))
ans.append(max(chain.from_iterable(v)) - 1)
print(max(ans))
| h, w = map(int, input().split())
s = [input() for _ in range(h)]
def bfs(x, y):
q = []
dp = {}
def qpush(x, y, t):
if 0 <= x < w and 0 <= y < h and s[y][x] != '#' and (x, y) not in dp:
q.append((x, y))
dp[(x, y)] = t
qpush(x, y, 0)
while len(q) > 0:
(x, y) = q.pop(0)
qpush(x + 1, y, dp[(x, y)] + 1)
qpush(x, y - 1, dp[(x, y)] + 1)
qpush(x - 1, y, dp[(x, y)] + 1)
qpush(x, y + 1, dp[(x, y)] + 1)
return dp.get((x, y), 0)
t = 0
for y in range(h):
for x in range(w):
t = max(t, bfs(x, y))
print(t) | 1 | 94,934,979,354,320 | null | 241 | 241 |
from sys import stdin, setrecursionlimit
def main():
s, t = map(str, stdin.readline().split())
a, b = map(int, stdin.readline().split())
u = stdin.readline()[:-1]
if s == u:
a -= 1
else:
b -= 1
print(a, b)
if __name__ == "__main__":
setrecursionlimit(10000)
main() | s,t=input().split()
S,T=map(int,input().split())
dis=input()
if s==dis:
print(S-1,T)
else:
print(S,T-1) | 1 | 71,652,130,038,368 | null | 220 | 220 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.