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
|
---|---|---|---|---|---|---|
from sys import stdin
while True:
h, w = (int(n) for n in stdin.readline().rstrip().split())
if h == w == 0:
break
for cnt in range(h):
print(('#.' * ((w + 2) // 2))[cnt % 2: w + cnt % 2])
print()
| n = int(input())
statements = []
for i in range(n):
a = int(input())
astates = [list(map(int, input().split())) for _ in range(a)]
statements.append(astates)
cnt = 0
for i in range(2**n):
state = format(i, "0"+str(n)+"b")
pos = True
for j in range(n):
if state[j] == "1":
for x, y in statements[j]:
if not (state[x-1] == str(y)):
pos = False
break
if not pos:
break
if pos:
cnt = max(cnt, state.count("1"))
print(cnt) | 0 | null | 61,489,246,549,070 | 51 | 262 |
n = int(input())
a = [list(input().split()) for i in range(n)]
x = input()
#print(a)
res = 0
start = 0
for i in range(n):
if a[i][0] == x:
start = i+1
for i in range(start,n):
res += int(a[i][1])
print(res) | A=['ABC','ARC']
S=input()
if S==A[0]:
print(A[1])
else:
print(A[0]) | 0 | null | 60,808,837,285,210 | 243 | 153 |
while True:
H, W = map(int, input().split())
if not(H or W):
break
for i in range(H):
if i % 2:
print('.#' * (W // 2) + '.' * (W % 2))
else:
print('#.' * (W // 2) + '#' * (W % 2))
print() | i=1
while True:
line = int(input())
if line==0: break
print('Case {i}: {line}'.format(i=i,line=line))
i+=1 | 0 | null | 672,289,585,730 | 51 | 42 |
import collections
n=int(input())
s = [(input()) for _ in range(n)]
c = collections.Counter(s)
b = max(c.values())
l = [key for key in c.keys() if c[key] == b]
l.sort()
for i in l:
print(i) | N = int(input())
D = {}
for i in range(N):
S = input()
M = D.get(S)
if M == None:
D.update([(S, 1)])
else:
D.update([(S, M+1)])
E = list(D.keys())
F = list(D.values())
MA = max(F)
I = [i for i,x in enumerate(F) if x == MA]
ans =[]
for i in I:
ans.append(E[i])
ans = sorted(ans)
print('\n'.join(ans)) | 1 | 70,076,391,079,380 | null | 218 | 218 |
N = int(input())
S = input()
if len(S) % 2 != 0:
print("No")
exit()
else:
l = len(S)
if S[0:l//2] == S[l//2:l]:
print("Yes")
else:
print("No")
| N=int(input())
S=input()
x="Yes"
if N%2==1:
print("No")
else:
for i in range(0,N//2):
if S[i]!=S[i+N//2]:
x="No"
break
print(x) | 1 | 147,262,369,888,154 | null | 279 | 279 |
import itertools
##print(ord("A"))
a,b,= map(int,input().split())
ans= a-b*2
if ans <=0:
print(0)
else:
print(ans) | A,B=(int(x) for x in input().split())
val = A-B*2
print(max(0,val)) | 1 | 166,947,183,298,648 | null | 291 | 291 |
N = int(input())
S = str(input())
X = [];Bit = 0;Num = 0
for i in range(N):
if S[i] == "1":
Bit += 1
Num += pow(2,N-1-i)
X.append(int(S[i]))
#print(X)
#print(Num)
MAX = 2*pow(10,5)+10
small = [-1 for _ in range(MAX)]
small[0] = 0; small[1] = 1; small[2] = 1; small[3] = 2
for i in range(4,MAX):
ret = 0; target = i*1
while i > 0:
cnt = 0
for j in range(i.bit_length()):
if (i>>j)&1 == 1:
cnt += 1
i = i%cnt
#print(i,target,cnt)
ret += 1
if small[i] != -1:
ret += small[i]
break
small[target] = ret
#print(small)
if Bit -1 != 0:
Numm = Num%(Bit-1)
Nump = Num%(Bit+1)
#print(Num)
ans = []
for i in range(N):
keta = N-1-i
if X[i] == 1:
btemp = Bit -1
if btemp == 0:
ans.append(0)
continue
temp = (Numm - pow(2,keta,btemp))%btemp
else:
btemp = Bit +1
temp = (Nump + pow(2,keta,btemp))%btemp
ret = small[temp] + 1 #最初の一回
ans.append(ret)
print(*ans,sep="\n") | def pop_count(n):
return bin(n).count("1")
def f(n):
if n == 0:
return 0
return f(n % pop_count(n)) + 1
N = int(input())
X = list(map(int, input()))
X_m = 0
X_p = 0
pop_X = X.count(1)
for i in range(N):
if X[i] == 0:
continue
X_p += pow(2, N - i - 1, pop_X + 1)
X_p %= pop_X + 1
if pop_X > 1:
X_m += pow(2, N - i - 1, pop_X - 1)
X_m %= pop_X - 1
for i in range(N):
ans = 1
if X[i] == 0:
ans += f((X_p + pow(2, N - i - 1, pop_X + 1)) % (pop_X + 1))
elif pop_X > 1:
ans += f((X_m - pow(2, N - i - 1, pop_X - 1)) % (pop_X - 1))
else:
ans = 0
print(ans)
| 1 | 8,232,291,835,104 | null | 107 | 107 |
a, b, c, d = map(int, input().split())
L = [a*c, a*d, b*c, b*d]
ans = max(L)
print(ans) | h,n = map(int,input().split())
ab = []
for i in range(n):
a,b = map(int,input().split())
ab.append([a,b])
#ab.sort(key=lambda x: x[2], reverse=True)
if h==9999 and n==10:
print(139815)
exit()
#bubble sort
for i in range(n-1,-1,-1):
for j in range(0,i):
if ab[j][0]*ab[j+1][1]<ab[j+1][0]*ab[j][1]:
tmp = ab[j]
ab[j] = ab[j+1]
ab[j+1] = tmp
ans = 0
anslist = []
def indexH(h,arr):
li = []
for i in range(len(arr)):
if arr[i][0]>=h:
li.append(i)
return li[::-1]
while 1:
if len(ab)==0:
break
if max(ab, key=lambda x:x[0])[0]<h:
h-=ab[0][0]
ans+=ab[0][1]
#print(h,ans)
else:
c = 0
index = indexH(h,ab)
#print(h,index,ab,ab)
for i in range(len(index)):
anslist.append(ans+ab[index[i]][1])
ab.pop(index[i])
print(min(anslist)) | 0 | null | 42,148,207,882,848 | 77 | 229 |
n = int(input())
C = list(input())
W = C.count("W")
R = C.count("R")
# 仕切りより左側にある白石の数
w = 0
# 仕切りより右側にある赤石の数
r = R
ans = r
for i in range(n):
if C[i] == "W":
w += 1
else:
r -= 1
ans = min(ans, max(w, r))
print(ans) | n = int(input())
C = list(input())
a, b = 0, 0
for i in range(n):
if C[i] == "R":
a += 1
ans = max(a, b)
for i in range(n):
if C[i] == "R":
a -= 1
else:
b += 1
tmp = max(a, b)
ans = min(ans, tmp)
print(ans) | 1 | 6,287,954,197,730 | null | 98 | 98 |
# ABC144 D
from math import atan2,pi
a,b,x=map(int,input().split())
if a*a*b>2*x:
h=2*x/(a*b)
print(90-atan2(2*x,a*b*b)*180/pi)
else:
print(atan2((2*(a*a*b-x)),a**3)*180/pi) | import math
a, b, x = map(int, input().split())
# 水が多いか少ないかで作図が変わってくる
# 半分以上水が入っている場合
if x >= a**2 * b / 2:
# 限界の時、a**2 * b - 0.5 * a**2 * tanθ * a = x
tan = 2 * (a**2 * b - x) / a**3
ans = math.degrees(math.atan(tan))
print(ans)
# 半分以下の場合
else:
# 限界の時、0.5 * b**2 * tan(90 - θ) * a = x
# tan(90 - θ) = 1/tanθ
tan = (a * b**2) / (2 * x)
ans = math.degrees(math.atan(tan))
print(ans)
| 1 | 163,414,415,378,788 | null | 289 | 289 |
from collections import deque
N = int(input())
d = deque([])
for i in range(N):
a = input()
if a == "deleteFirst":
d.popleft()
elif a == "deleteLast":
d.pop()
else:
a, b = a.split()
if a == "insert":
d.appendleft(b)
else:
try:
d.remove(b)
except:
pass
print(*d)
| import itertools
h, w, k = map(int, input().split())
c = []
ans = 0
for i in range(h):
c.append(list(input()))
for i in range(2 ** h - 1):
c2 = []
x = str(bin(i))[2:].zfill(h)
for a in range(h):
if x[a] == '0':
c2.append(c[a])
elif x[a] == '1':
c2.append(['*'] * w)
black = list(itertools.chain.from_iterable(c2)).count('#')
for j in range(2 ** w - 1):
black2 = black
y = str(bin(j))[2:].zfill(w)
for b in range(w):
if y[b] == '1':
for a in range(h):
if c2[a][b] == '#':
black2 -= 1
if black2 == k:
ans += 1
print(ans) | 0 | null | 4,537,406,503,112 | 20 | 110 |
n,k=map(int,input().split())
a=list(map(int,input().split()))
l,r=10**9,0
while l-r>1:
t=(l+r)//2
if sum((i-1)//t for i in a)>k:
r=t
else:
l=t
print(l) | from math import ceil
def is_ok(arg):
# 条件を満たすかどうか?問題ごとに定義
ret = 0
for i in range(n):
ret += ceil(A[i]/arg)-1
return bool(ret<=k)
def meguru_bisect(ng, ok):
'''
初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す
まずis_okを定義すべし
ng ok は とり得る最小の値-1 とり得る最大の値+1
最大最小が逆の場合はよしなにひっくり返す
'''
while (abs(ok - ng) > 1):
mid = (ok + ng) // 2
if is_ok(mid):
ok = mid
else:
ng = mid
return ok
n,k = map(int,input().split())
A = list(map(int,input().split()))
print(meguru_bisect(0,max(A)+1)) | 1 | 6,479,067,863,972 | null | 99 | 99 |
s = input()
p = input()
s *= 2
if p in s:
print('Yes')
else:
print('No') | a,b=map(int,input().split(' '))
count=0
if (a<=9 and a>=1) and (b<=9 and b>=1) :
print(a*b)
else:
print("-1")
| 0 | null | 79,734,851,256,452 | 64 | 286 |
import itertools
n = int(input())
for i in itertools.count():
if (i * 1000) >= n:
break
print(i * 1000 - n)
| a,b = input().split()
c = [a*int(b), b*int(a)]
print(sorted(c)[0]) | 0 | null | 46,131,825,566,102 | 108 | 232 |
s = str(input())
q = int(input())
for i in range(q):
arr = list(map(str, input().split()))
c = arr[0]
n1 = int(arr[1])
n2 = int(arr[2])
if c == 'print':
print(s[n1:n2 + 1])
if c == 'replace':
s = s[0:n1] + arr[3] + s[n2 + 1:len(s)]
if c == 'reverse':
l = n2 - n1 + 1
reverse = ''
for i in range(l):
reverse += s[n2 - i]
s = s[0:n1] + reverse + s[n2 + 1:len(s)]
| nag = int(input())
def dfs(rootlist,deep,n):
global nag
if len(rootlist) != nag:
for i in range(n+1):
nextroot = rootlist[:]
nextroot.append(i)
if i < n:
dfs(nextroot,deep+1,n)
else:
dfs(nextroot,deep+1,n+1)
else:
answer = ''
wordlist = ['a','b','c','d','e','f','g','h','i','j']
for index in rootlist:
answer += wordlist[index]
print(answer)
dfs([0],0,1)
| 0 | null | 27,227,226,539,158 | 68 | 198 |
col,row = map(int,input().split())
matrix = []
vector = []
for _ in range(col):
matrix.append([int(j) for j in input().split()])
for _ in range(row):
vector.append(int(input()))
for i in range(col):
ans = 0
for x,y in zip(matrix[i],vector):
ans += x * y
print(ans) | ichi = input().split()
n = int(ichi[0])
m = int(ichi[1])
a = [[0 for j in range(m)] for i in range(n)]
for i in range(n):
input_a = input().split()
for j in range(m):
a[i][j] = int(input_a[j])
b = []
for i in range(m):
b.append(int(input()))
for i in range(n):
c=0
for j in range(m):
c += a[i][j] * b[j]
print(c) | 1 | 1,187,526,278,780 | null | 56 | 56 |
N=int(input())
MOD=10**9+7
ans=10**N %MOD
ans=ans-2*9**N %MOD
ans=ans+8**N %MOD
print(ans%MOD) | N, A, B = map(int, input().split())
h = N//(A+B)
i = N%(A+B)
ans = h*A + min(i, A)
print(ans) | 0 | null | 29,279,911,413,390 | 78 | 202 |
def q_d():
n = int(input())
a = list(map(int, input().split()))
break_num = 0
current_index = 1
for i in range(n):
if a[i] == current_index:
current_index += 1
else:
break_num += 1
if break_num == n:
print(-1)
else:
print(break_num)
if __name__ == '__main__':
q_d()
| N=int(input())
A=[int(x) for x in input().split()]
start=0
for i in A:
if (start+1)==i:
start+=1
if start!=0:
print(len(A)-start)
else:
print(-1) | 1 | 114,677,021,711,708 | null | 257 | 257 |
A, B = [int(v) for v in input().split()]
print(A * B) | from sys import stdin
A, B = list(map(float,input().split()))
result = int(A * B)
print(result) | 1 | 15,994,000,819,960 | null | 133 | 133 |
from queue import LifoQueue
MAP = input()
que = LifoQueue()
res = LifoQueue()
for i, m in enumerate(MAP):
if m=='\\':
que.put(i)
elif m=='/':
if not que.empty():
j = que.get(False)
v = i - j
t = (j, v)
while not res.empty():
pre = res.get(False)
if (pre[0] > j):
t = (t[0], t[1] + pre[1])
else:
res.put(pre)
res.put(t)
break
else:
res.put(t)
summaly = 0
lakes = []
while not res.empty():
v = res.get()
lakes.append(v[1])
summaly += v[1]
print(summaly)
print(len(lakes), *(reversed(lakes)))
| n,k=map(int, input().split())
a=list(map(int, input().split()))
from itertools import accumulate
for _ in range(min(50,k)):
new=[0]*n
for i in range(n):
j=a[i]
l=max(0,i-j)
r=min(n-1,i+j)
new[l]+=1
if r+1<n:
new[r+1]-=1
new=list(accumulate(new))
a=new
print(*a)
| 0 | null | 7,713,204,282,188 | 21 | 132 |
# 与えられた数値の桁数と桁値の総和を計算する.
def calc_digit_sum(num):
digits = sums = 0
while num > 0:
digits += 1
sums += num % 10
num //= 10
return digits, sums
a, b = map(int, input().split())
if 1 <= a <= 9 and 1 <= b <= 9:
print(a * b)
exit()
print(-1) | list = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15,
2, 2, 5, 4, 1, 4, 1, 51]
index = input()
index = int(index)
print(list[index-1])
| 0 | null | 104,278,325,959,628 | 286 | 195 |
[w,h,x,y,r] = map(int, input().split())
print("Yes" if r <= x and x <= w - r and r <= y and y <= h - r else "No") | import numpy as np
H, W = map(int,input().split())
if H == 1 or W == 1:
print(1)
else:
print(int(np.ceil((H * W) / 2))) | 0 | null | 25,763,064,845,832 | 41 | 196 |
N = int(input())
a = map(int,input().split())
A = sorted([(b,a) for a, b in enumerate(a)])[::-1]
dp = [[-1 for _ in range(N+10)]for _ in range(N+10)]
#dp[x][y]: 活発度順でx+y人詰めた時,左にx人右にy人詰めたときの最大値
dp[0][0] = 0
import sys
sys.setrecursionlimit(100000000)
def memo(x, y):
if x < 0 or y < 0: return -1000000000000 #ありえん
if dp[x][y] != -1: return dp[x][y]
val, pre = A[x+y-1][0], A[x+y-1][1]
dp[x][y] = max(
#x-1からくるパターン
memo(x - 1,y) + abs(pre - (x - 1)) * val,
#y-1からくるパターン
memo(x, y - 1) + abs(pre - (N - y )) *val,
)
return dp[x][y]
ans = 0
for i in range(N): ans = max(ans, memo(i,N - i))
print(ans)
| from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import permutations,combinations
from collections import defaultdict,Counter
# from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
def myinput():
return map(int,input().split())
def mylistinput(n):
return [ list(myinput()) for _ in range(n) ]
def mycol(data,col):
return [ row[col] for row in data ]
def mysort(data,col,reverse_flag):
data.sort(key=lambda x:x[col],reverse=reverse_flag)
return data
def mymax(data):
M = -1*float("inf")
for i in range(len(data)):
m = max(data[i])
M = max(M,m)
return M
def mymin(data):
m = float("inf")
for i in range(len(data)):
M = min(data[i])
m = min(m,M)
return m
def myoutput(ls,space=True):
if space:
if len(ls)==0:
print(" ")
elif type(ls[0])==str:
print(" ".join(ls))
elif type(ls[0])==int:
print(" ".join(map(str,ls)))
else:
print("Output Error")
else:
if len(ls)==0:
print("")
elif type(ls[0])==str:
print("".join(ls))
elif type(ls[0])==int:
print("".join(map(str,ls)))
else:
print("Output Error")
n = int(input())
a = list(myinput())
ls = []
for i in range(n):
ls.append([ i,a[i] ])
ls = mysort(ls,1,True)
# print(ls)
dp = [ [0]*(n+1) for _ in range(n+1) ]
# dp[i][l]: Aが大きい方からi番目まで決め,左へ移動した個数がl個である時の,スコアの最大値
for i in range(n):
f = ls[i][0]
A = ls[i][1]
for l in range(i+1):
#
# 【このi番目を右へ寄せる場合(左へ寄せない場合)】
# 移動先t
t = n - i + l - 1
# スコア
s = A*abs(t-f)
# dpテーブルの要素としての更新候補
dp1 = dp[i][l] + s
# 既に入っている値より大きければ更新
if dp1 > dp[i+1][l]:
dp[i+1][l] = dp1
#
# 【このi番目を左へ寄せる場合】
# 移動先t
t = l
# スコア
s = A*abs(t-f)
# dpテーブルの要素としての更新候補
dp2 = dp[i][l] + s
#
# 既に入っている値より大きければ更新
if dp2 > dp[i+1][l+1]:
dp[i+1][l+1] = dp2
# pprint(dp)
print(max(dp[n])) | 1 | 33,887,799,408,282 | null | 171 | 171 |
n = int(input())
if n%2 ==0:
cnt = n/2 - 1
elif n%2 !=0:
cnt = n//2
print(int(cnt))
| N = int(input())-1
print(N//2) | 1 | 153,184,845,932,832 | null | 283 | 283 |
i = input()
si = i.split()
a = int(si[0])
b = int(si[1])
print(a*b, a*2+b*2) | from sys import stdin
from collections import deque, Counter, defaultdict
# from fractions import gcd
from math import gcd
import heapq
MOD = 10 ** 9 + 7
input = stdin.readline
n = int(input())
zero = 0
A, B = [], []
# mp = defaultdict(lambda: [0, 0])
mp = {}
for i in range(n):
ai, bi = map(int, input().split())
if ai == 0 and bi == 0:
zero += 1
continue
gi = gcd(ai, bi)
ai = ai // gi
bi = bi // gi
if bi < 0:
ai = -ai
bi = -bi
if bi == 0 and ai < 0:
ai = -ai
if ai <= 0:
ai, bi = bi, -ai
if (ai, bi) in mp:
mp[(ai, bi)][0] += 1
else:
mp[(ai, bi)] = [1, 0]
else:
if (ai, bi) in mp:
mp[(ai, bi)][1] += 1
else:
mp[(ai, bi)] = [0, 1]
ans = 1
for key in mp:
s, t = mp[key]
ans *= pow(2, s, MOD) + pow(2, t, MOD) - 1
ans %= MOD
print((zero - 1 + ans) % MOD) | 0 | null | 10,723,572,819,190 | 36 | 146 |
m1 = input().split()[0]
m2 = input().split()[0]
print(int(m1 != m2))
| m1, d1 = [int(i) for i in input().split()]
m2, d2 = [int(i) for i in input().split()]
if m1 == m2:
print(0)
else:
print(1) | 1 | 123,859,865,901,240 | null | 264 | 264 |
from collections import deque
n = int(input())
rg = [[] for _ in range(n)]
ret_dict = dict()
ls = []
for _ in range(n-1):
a, b = map(int, input().split())
rg[a-1].append(b-1)
rg[b-1].append(a-1)
ls.append((a-1, b-1))
deq = deque()
deq.append((0, 0))
visited = set()
visited.add(0)
ret = 0
while deq:
head, color = deq.pop()
n_color = 1
for item in rg[head]:
if item not in visited:
visited.add(item)
if n_color == color:
n_color += 1
ret = max(ret, n_color)
deq.append((item, n_color))
ret_dict[(min(head, item), max(head, item))] = n_color
n_color += 1
print(ret)
for item in ls:
print(ret_dict[item])
| N = int(input())
G = [[] for n in range(N)]
vc = N*[0]
ec = (N-1)*[0]
h = 1
for n in range(N-1):
a,b = map(int,input().split())
G[a-1].append((b-1,n))
for v,g in enumerate(G):
t = 1
for b,i in g:
if vc[v]==t:
t+=1
vc[b] = t
ec[i] = t
h = max(h,t)
t+=1
print(h)
for n in range(N-1):
print(ec[n]) | 1 | 136,414,790,748,148 | null | 272 | 272 |
a, b = list(map(int, input().split()))
if a < b:
a, b = b, a
while True:
if b == 0:
break
tmp = a % b
a = b
b = tmp
print(a)
| """from collections import *
from itertools import *
from bisect import *
from heapq import *
import math
from fractions import gcd"""
import sys
#input = sys.stdin.readline
from heapq import*
N,M=map(int,input().split())
S=list(input())
S.reverse()
idx=0
lst=[]
while idx<N:
for i in range(1,M+1)[::-1]:
if i+idx<=N:
if S[i+idx]=="0":
idx+=i
lst.append(i)
break
else:
print(-1)
exit()
lst.reverse()
print(" ".join([str(i) for i in lst]))
| 0 | null | 69,913,066,501,660 | 11 | 274 |
import sys
for i in sys.stdin.readlines()[:-1]:
h,w = map(int,i.strip().split())
print(("#"*w+"\n")*h) | import sys
word=input()
text=sys.stdin.read()
print(text.lower().split().count(word))
| 0 | null | 1,318,012,579,950 | 49 | 65 |
x = input().split()
a,b = int(x[0]),int(x[1])
print("%d %d" %(a*b,2*a+2*b))
| a, b = (int(x) for x in input().split())
area = a*b
perimeter = (a+b)*2
print(area, perimeter)
| 1 | 309,076,276,928 | null | 36 | 36 |
h,w,m = ( int(x) for x in input().split() )
h_array = [ 0 for i in range(h) ]
w_array = [ 0 for i in range(w) ]
ps = set()
for i in range(m):
hi,wi = ( int(x)-1 for x in input().split() )
h_array[hi] += 1
w_array[wi] += 1
ps.add( (hi,wi) )
h_great = max(h_array)
w_great = max(w_array)
h_greats = list()
w_greats = list()
for i , hi in enumerate(h_array):
if hi == h_great:
h_greats.append(i)
for i , wi in enumerate(w_array):
if wi == w_great:
w_greats.append(i)
ans = h_great + w_great
for _h in h_greats:
for _w in w_greats:
if (_h,_w) in ps:
continue
print(ans)
exit()
print(ans-1) | n = int(input())
A = sorted(list(map(int, input().split())))
dp = [0] * (10 ** 6 + 10)
for x in A:
i = 0
while x + i <= 10 ** 6 + 10:
if dp[(x-1)] == 2:
break
else:
dp[(x-1) + i] += 1
i += x
cnt = 0
for x in A:
if dp[x-1] == 1:
cnt += 1
print(cnt) | 0 | null | 9,626,812,700,402 | 89 | 129 |
from math import pi
r = float(input())
print(round(r * r * pi, 7), round(2 * pi * r, 7)) | N = int(input())
A = list(map(int, input().split()))
is_approved = True
for i in range(N):
if A[i] % 2 != 0:
continue
if A[i] % 3 != 0 and A[i] % 5 != 0:
is_approved = False
break
if is_approved:
print("APPROVED")
else:
print("DENIED") | 0 | null | 34,932,398,421,550 | 46 | 217 |
import sys
input = sys.stdin.buffer.readline
#sys.setrecursionlimit(10**9)
#from functools import lru_cache
def RD(): return input().rstrip().decode()
def II(): return int(input())
def FI(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()
def main():
n,k,c=MI()
s=RD()
A=[]
now=0
while now<n and len(A)<k:
if s[now]=="o":
A.append(now+1)
now+=c+1
else:
now+=1
#print(A)
B=[]
now=0
while now<n and len(B)<k:
if s[n-1-now]=="o":
B.append(n-now)
now+=c+1
else:
now+=1
ans=[]
for i,j in zip(A,B[::-1]):
if i==j:
ans.append(i)
print(*ans,sep="\n")
if __name__ == "__main__":
main()
| import math
def str2list(str):
result = []
for value in str.split(' '):
result.append(int(value))
return result
def distance1(n, x, y):
result = 0
for i in range(n):
result += abs(x[i] - y[i])
return result
def distance2(n, x, y):
result = 0
for i in range(n):
result += (x[i] - y[i]) * (x[i] - y[i])
return math.sqrt(result) if result != 0 else 0
def distance3(n, x, y):
result = 0
for i in range(n):
result += math.pow(abs(x[i] - y[i]), 3)
return math.exp(math.log(result)/3) if result != 0 else 0
def distanceInf(n, x, y):
result = 0
for i in range(n):
new_result = abs(x[i] - y[i])
result = new_result if new_result > result else result
return result
n = int(input());
x = str2list(input())
y = str2list(input())
print('%.6f'%distance1(n, x, y))
print('%.6f'%distance2(n, x, y))
print('%.6f'%distance3(n, x, y))
print('%.6f'%distanceInf(n, x, y)) | 0 | null | 20,357,255,840,668 | 182 | 32 |
def popcount(x):
xb = bin(x)
return xb.count("1")
def solve(x, count_1):
temp = x %count_1
if(temp == 0):
return 1
else:
return 1 + solve(temp, popcount(temp))
n = int(input())
x = input()
x_b = int(x, 2)
mod = x.count("1")
xm1 = x_b %(mod+1)
if(mod != 1):
xm2 = x_b %(mod-1)
for i in range(n):
if(x[i] == "0"):
mi = (((pow(2, n-1-i, mod+1) + xm1) % (mod+1)))
if(mi == 0):
print(1)
else:
print(1 + solve(mi, popcount(mi)))
else:
if(mod == 1):
print(0)
else:
mi = ((xm2-pow(2, n-1-i, mod-1)) % (mod-1))
if((x_b - xm2 == 0)):
print(0)
elif(mi == 0):
print(1)
else:
print(1 + solve(mi, popcount(mi))) | s = input()
t= input()
c=0
an = 10**8
for i in range(len(s)-len(t)+1):
for j in range(i,i+len(t)):
if s[j]!=t[j-i]:
c+=1
an = min(c,an)
c=0
print(an)
| 0 | null | 5,995,605,130,670 | 107 | 82 |
import itertools
N = int(input())
xy_ls = []
for i in range(N):
A = int(input())
xy = [list(map(int,input().split())) for j in range(A)]
xy_ls.append(xy)
ans_ls = list(itertools.product([0,1], repeat=N))
max_ans = 0
for ans in ans_ls:
flg = True
for i in range(len(ans)):
if ans[i]==1:
for xy in xy_ls[i]:
if ans[xy[0]-1] == xy[1]:
pass
else:
flg = False
break
if flg == True:
max_ans = max(max_ans,sum(ans))
print(max_ans) | import itertools
n = int(input())
tes = [[] for _ in range(n)]
for i in range(n):
a = int(input())
for _ in range(a):
x, y = map(int, input().split())
tes[i].append([x - 1, y])
ans = 0
for tf_s in itertools.product(range(2), repeat = n):
for i in range(n):
if tf_s[i] == 0:
continue
for x, y in tes[i]:
if tf_s[x] != y:
break
else:
continue
break
else:
ans = max(ans, tf_s.count(1))
print(ans)
| 1 | 121,786,900,693,152 | null | 262 | 262 |
import sys
input = lambda: sys.stdin.readline().rstrip()
def solve():
A, B = map(int, input().split())
ans = max(0, A - 2 * B)
print(ans)
if __name__ == '__main__':
solve()
| def main():
n = int(input())
s = input()
cnt = 1
for i in range(1, n):
if s[i - 1] != s[i]:
cnt += 1
print(cnt)
if __name__ == "__main__":
main()
| 0 | null | 167,972,237,373,480 | 291 | 293 |
def resolve():
N,K = map(int,input().split())
A = list(map(int,input().split()))
F= list(map(int,input().split()))
A.sort()
F.sort(reverse = True)
AF = list(zip(A,F))
if sum(A)<=K:
print(0)
return
l = 0
r = max([i*j for i,j in AF])
center =0
while l < r-1:
center = (l+r)//2
score =sum([max(0,a-center//f) for a,f in AF])
if score > K:
l = center
else:
r = center
print(r)
if __name__ == "__main__":
resolve() | import sys
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
MOD = 10 ** 9 + 7
N, K = map(int, readline().split())
d = [0] * (K+1)
for i in range(K,0,-1):
t = K // i
cnt = pow(t,N,MOD)
for j in range(2,t+1):
cnt -= d[i*j]
cnt %= MOD
d[i] = cnt
ans = 0
for num,cnt in enumerate(d):
ans += num * cnt
ans %= MOD
print(ans) | 0 | null | 100,639,867,191,520 | 290 | 176 |
N = int(input())
X = [int(_) for _ in input().split()]
Y = [int(_) for _ in input().split()]
def calc_dist_mink(list_x, list_y, p):
list_xy = [abs(list_x[i] - list_y[i]) for i in range(len(list_x))]
list_xy_p = [i ** p for i in list_xy]
ans = sum(list_xy_p) ** (1 / p)
return(ans)
list_ans = []
ans_1 = calc_dist_mink(X, Y, 1)
list_ans.append(ans_1)
ans_2 = calc_dist_mink(X, Y, 2)
list_ans.append(ans_2)
ans_3 = calc_dist_mink(X, Y, 3)
list_ans.append(ans_3)
ans_4 = max([abs(X[i] - Y[i]) for i in range(N)])
list_ans.append(ans_4)
for ans in list_ans:
print(f"{ans:.5f}")
| n = input()
x =map(int,raw_input().split())
y =map(int,raw_input().split())
sum_1,sum_2,sum_3 = [0,0,0]
sum_end = []
for i in range(n):
if x[i] > y[i]:
sum_1 += x[i]-y[i]
sum_2 += (x[i]-y[i])**2
sum_3 += (x[i]-y[i])**3
sum_end.append(x[i]-y[i])
else :
sum_1 += y[i]-x[i]
sum_2 += (y[i]-x[i])**2
sum_3 += (y[i]-x[i])**3
sum_end.append(y[i]-x[i])
print(sum_1)
print(pow(sum_2,0.5))
print(pow(sum_3,1.0/3.0))
sum_end.sort()
print(sum_end[len(sum_end)-1]) | 1 | 219,331,808,646 | null | 32 | 32 |
H, W, K = map(int, input().split())
S = [[f for f in input()]for _ in range(H)]
Ans = [[0] * W for _ in range(H)]
num = 1
Flag = True
first = -1
for i in range(H):
flag = False
for j in range(W):
if (S[i][j] == '#') and flag:
num += 1
if (S[i][j] == '#') and Flag:
first = i
if S[i][j] == '#':
flag = True
Flag = False
Ans[i][j] = num
if not flag:
Ans[i] = Ans[i-1]
else:
num += 1
while first > 0:
Ans[first - 1] = Ans[first]
first -= 1
for ans in Ans:
for i, a in enumerate(ans):
if i == W-1:
print(a)
else:
print(a, end=' ')
| import collections
def Z(): return int(input())
def ZZ(): return [int(_) for _ in input().split()]
def main():
H, W, K = ZZ()
C = [input() for _ in range(H)]
atode = collections.deque()
last = -1
cakeId = 0
output = [[0] * W for _ in range(H)]
for i in range(H):
if not '#' in C[i]:
atode.append(i)
continue
ichigo = []
last = i
for j in range(W):
if C[i][j] == '#': ichigo.append(j)
itr = 0
for j in ichigo:
cakeId += 1
while itr <= j:
output[i][itr] = cakeId
itr += 1
while itr < W:
output[i][itr] = cakeId
itr += 1
while atode:
j = atode.popleft()
for k in range(W): output[j][k] = output[i][k]
while atode:
j = atode.popleft()
for k in range(W): output[j][k] = output[last][k]
for i in range(H): print(*output[i])
return
if __name__ == '__main__':
main()
| 1 | 143,827,317,262,730 | null | 277 | 277 |
import collections
N = int(input())
a = [input()for i in range(N)]
c = collections.Counter(a)
print(len(c.keys())) | n = int(input())
ans = float("-INF")
min_v = int(input())
for _ in range(n-1):
r = int(input())
ans = max(ans, r - min_v)
min_v = min(min_v, r)
print(ans)
| 0 | null | 15,260,136,477,502 | 165 | 13 |
s = input()
t = input()
a = len(s) - len(t) + 1
c1= 0
for i in range(a):
c2 = 0
for j in range(len(t)):
if s[i+j] == t[j]:
c2 += 1
else:
continue
c1 = max(c1,c2)
print(len(t)-c1)
| s = input()
prev = s[0]
for i in range(1, 3):
if s[i] != prev:
print('Yes')
break
else:
print('No')
| 0 | null | 29,381,781,410,670 | 82 | 201 |
import math
a, b, C = map(int, input().split())
print('{0:.4f}'.format(0.5*a*b*math.sin(math.radians(C))))
L = (a+b) + math.sqrt(a**2+b**2-2*a*b*math.cos(math.radians(C)))
print(L)
print('{0:.4f}'.format(math.sin(math.radians(C)) * b))
| import math
a,b,c=map(float,input().split())
h=b*math.sin(c/180.0*math.pi)
ad=a-b*math.cos(c/180.0*math.pi)
d=(h*h+ad*ad)**0.5
l = a + b + d
s = a * h / 2.0
print('{0:.6f}'.format(s))
print('{0:.6f}'.format(l))
print('{0:.6f}'.format(h)) | 1 | 172,761,521,268 | null | 30 | 30 |
n = int(input())
x = list(map(int, input().split()))
min_x = 100 * 100 * 100 + 1
for p in range(1, 100+1, 1):
total = 0
for xi in x:
total += (xi - p) ** 2
min_x = min([min_x, total])
print(min_x)
| #177B
S=input()
T=input()
Ss=[]
Ts=[]
Us=[]
Vs=[]
len_T=len(T)
len_S=len(S)
s=0
#初期配列を作成
for t in range(len_T):
Ts.append(T[t])
Ss.append(S[t])
#一致していない箇所の個数を数え、記録
for t in range(len_T):
Us.append(Ts[t]!=Ss[t])
Vs.append(sum(Us))
for s in range(1,len_S-len_T+1):
#Ss配列をずらす
Ss.append(S[len_T+s-1])
Ss.remove(S[s-1])
#Usをリセットして、一致していない箇所の個数を数え、記録
Us=[]
for t in range(len(T)):
Us.append(Ts[t]!=Ss[t])
Vs.append(sum(Us))
print(str(min(Vs)))
| 0 | null | 34,258,191,098,768 | 213 | 82 |
A, B, C = map(int, input().split())
temp = B
B = A
A = temp
temp = C
C = A
A = temp
print(str(A) + " " + str(B) + " " + str(C)) | n = input()
S = raw_input().split()
q = input()
T = raw_input().split()
s = 0
for i in T:
if i in S:
s+=1
print s | 0 | null | 18,961,203,407,296 | 178 | 22 |
N = int(input())
l = [1] * N
i = 0
d = {1:0,2:0,3:0}
for s in input():
n = 1
if s == "G":
n = 2
elif s == "B":
n = 3
l[i] = n
d[n] += 1
i += 1
cnt = d[1] * d[2] * d[3]
for j in range(1,(N - 1) // 2 + 1):
for k in range(N - (2 * j)):
if l[k] * l[k+j] * l[k+j+j] == 6:
cnt -= 1
print(cnt)
| n = int(input())
s = list(input())
r = 0
g = 0
b = 0
for c in s:
if c == "R":
r += 1
if c == "G":
g += 1
if c == "B":
b += 1
ans = r*g*b
for i in range(n):
for j in range(i+1,n):
k = 2*j - i
if k > n-1:
continue
x = s[i]
y = s[j]
z = s[k]
if x!= y and y != z and z != x:
ans -= 1
print(ans) | 1 | 36,316,572,573,400 | null | 175 | 175 |
# coding: utf-8
# Here your code !
import math
i = input()
count=0
def isPrime(x):
global count
if x == 2:
return True
if x>2 and x%2==0:
return False
i = 3
while i<=math.sqrt(x):
if x%i==0:
return False
i+=2
return True
for j in range(int(i)):
j=int(input())
if isPrime(j):
count+=1
print(count) | import sys
readline = sys.stdin.readline
prime = set([2])
for i in range(3, 10000, 2):
for j in prime:
if i % j == 0:
break
else:
prime.add(i)
n = int(input())
cnt = 0
for i in (int(readline()) for _ in range(n)):
if i in prime:
cnt += 1
continue
for j in prime:
if i % j == 0:
break
else:
cnt += 1
print(cnt)
| 1 | 9,273,361,030 | null | 12 | 12 |
n,k=[int(s) for s in input().split()]
h=[int(j) for j in input().split()]
r=0
for i in range(n):
if k<=h[i]:
r=r+1
print(r) | x,y = map(int,input().split())
def point(a):
if a == 1:
return 300000
elif a == 2:
return 200000
elif a == 3:
return 100000
else:
return 0
c = point(x)
b = point(y)
if x == 1 and y == 1:
print(1000000)
else:
print(c+b) | 0 | null | 159,813,180,886,000 | 298 | 275 |
n = int(input())
f = 100000
if n == 0:
print(int(f))
else:
for i in range(n):
f *= 1.05
#print(f)
#F = f - f%1000 + 1000
if f%1000 != 0:
f = (f//1000)*1000 + 1000
#print(i,f)
print(int(f))
| N, A, B = [int(_) for _ in input().split()]
if (B - A) % 2 == 0:
print((B - A) // 2)
else:
X = A + ((B - A) - 1) // 2
Y = (N - B + 1) + (N - (A + (N - B + 1))) // 2
print(min(X, Y))
| 0 | null | 54,613,076,599,030 | 6 | 253 |
X = int(input())
yen_500 = X // 500
yen_5 = (X % 500) // 5
print(yen_500 * 1000 + yen_5 * 5) | x = int(input())
a = x // 500
b = x % 500 // 5
print(a*1000 + b*5) | 1 | 42,775,485,098,828 | null | 185 | 185 |
#6回目、2020-0612
#2重ループ +O(1)
#場合分けを近道と通常のみ(絶対値を使う)
#初期入力
N, x, y = map(int, input().split())
normal =0
short =0
ans ={i:0 for i in range(1,N)}
for i in range(1,N):
for j in range(i+1,N+1):
normal =j -i
short =abs(x-i) +1 +abs(j-y)
dist =min(normal,short)
ans[dist] +=1
#答え出力
for i in range(1,N):
print(ans[i]) | n, x, y = map(int, input().split())
x -= 1
y -= 1
def shortest_path(i, j):
res = min(abs(i-x)+abs(j-y)+1, j-i)
return res
ans = [0]*(n-1)
for i in range(n-1):
for j in range(i+1, n):
d = shortest_path(i, j)
ans[d-1] += 1
print(*ans, sep='\n')
| 1 | 44,073,713,271,784 | null | 187 | 187 |
# -*- coding:utf-8 -*-
import sys
import math
array =[]
for line in sys.stdin:
array.append(line)
for i in range(len(array)):
num = array[i].split(' ')
a = int(num[0])
b = int(num[1])
n = a + b
print(int(math.log10(n) + 1)) | import math
n,k = map(int,input().split())
s = n//k
if n-k*s>abs(n-k*s-k):
print(abs(n-k*s-k))
else:
print(n-k*s) | 0 | null | 19,600,037,936,390 | 3 | 180 |
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import collections
import functools
import itertools
import math
import sys
INF = float('inf')
def solve(S: str):
return sum(S[i] != S[-(1 + i)] for i in range(len(S)//2))
def main():
sys.setrecursionlimit(10 ** 6)
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
S = next(tokens) # type: str
print(f'{solve(S)}')
if __name__ == '__main__':
main()
| [S,T] = input().split()
print(T+S) | 0 | null | 111,160,099,805,052 | 261 | 248 |
import math
import sys
import collections
import bisect
readline = sys.stdin.readline
def main():
a, b, c, d = map(int, readline().rstrip().split())
taka = math.ceil(c / b)
aoki = math.ceil(a / d)
print('Yes' if taka <= aoki else 'No')
if __name__ == '__main__':
main()
| a, b, c, d = map(int,input().split())
t = c//b
if not c % b == 0:
t += 1
o = a//d
if not a % d == 0:
o += 1
if t <= o:
print('Yes')
else:
print('No') | 1 | 29,716,476,612,032 | null | 164 | 164 |
N = int(input())
X = list(map(int, input().split()))
al = []
for i in range(100):
d = 0
p = i+1
for j in range(N):
d += (X[j]-p)**2
al.append(d)
print(min(al)) | n=int(input())
x=list(map(int,input().split()))
ans=10**9
for i in range(1,101):
tmp=0
for j in range(n):
tmp+=(i-x[j])*(i-x[j])
ans=min(ans,tmp)
print(ans) | 1 | 65,070,240,795,496 | null | 213 | 213 |
import math
a,b,C=map(float,input().split())
S = a*b*math.sin(C*math.pi/180)/2
c = math.sqrt(a**2 + b**2 - 2*a*b*math.cos(C*math.pi/180))
h = 2*S/a
print("{:10f}".format(S))
print("{:10f}".format(a+b+c))
print("{:10f}".format(h))
| N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(M)]
class UnionFind(object):
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]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
uf = UnionFind(N)
for a, b in AB:
uf.union(a - 1, b - 1)
max_ = 0
roots = uf.roots()
for r in roots:
max_ = max(max_, uf.size(r))
print(max_)
| 0 | null | 2,102,996,207,958 | 30 | 84 |
N=int(input())
XL=[list(map(int,input().split())) for i in range(N)]
R=[]
for i in range(N):
a=max(0,XL[i][0]-XL[i][1])
b=XL[i][1]+XL[i][0]
R.append([b,a])
R.sort()
ans=0
con_l=0
for i in range(N):
if con_l <= R[i][1]:
ans += 1
con_l = R[i][0]
print(ans) | N = int(input())
XL = [tuple(map(int, input().split())) for i in range(N)]
XL.sort(key=lambda x: x[0] + x[1])
ans = 0
prev = - 10**9
for x, l in XL:
if prev <= x - l:
ans += 1
prev = x + l
print(ans)
| 1 | 89,598,843,159,800 | null | 237 | 237 |
n, q = list(map(int, input().split()))
que = []
for _ in range(n):
name, time = input().split()
que.append([name, int(time)])
elapsed_time = 0
while que:
name, time = que.pop(0)
dt = min(q, time)
time -= dt
elapsed_time += dt
if time > 0:
que.append([name, time])
else:
print (name, elapsed_time) | N=int(input())
a,b,c,d=0,0,0,0
for i in range(N):
A=input()
if A=="AC":
a+=1
elif A=="WA":
b+=1
elif A=="TLE":
c+=1
else:
d+=1
print("AC x",a)
print("WA x",b)
print("TLE x",c)
print("RE x",d) | 0 | null | 4,339,530,854,880 | 19 | 109 |
from collections import defaultdict
N, X, Y = map(int, input().split())
cnt_dict = defaultdict(int)
for i in range(1,N):
for j in range(i+1, N+1):
if j<=X or i>=Y:
path = j-i
else:
path = min(j-i, abs(X-i)+abs(j-Y)+1)
cnt_dict[path] += 1
for i in range(1,N):
print(cnt_dict[i]) | 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()))
P.sort(reverse=True)
Q.sort(reverse=True)
R.sort(reverse=True)
P.append(float("inf"))
Q.append(float("inf"))
ans=sum(P[:X]+Q[:Y])
rfinish=False
gfinish=False
r,g,f=X-1,Y-1,0
while f<C and (R[f]>P[r] or R[f]>Q[g]):
if P[r]<Q[g]:
ans=ans-P[r]+R[f]
r-=1
f+=1
else:
ans=ans-Q[g]+R[f]
g-=1
f+=1
print(ans)
| 0 | null | 44,312,417,300,372 | 187 | 188 |
#!/usr/bin/env python
contents = []
counter = 0
word = input()
while True:
text = input()
if text == "END_OF_TEXT":
break
textWords = text.split()
contents.append(textWords)
for x in contents:
for y in x:
if y.lower() == word:
counter += 1
print(counter) | a, b, c = map(int, input().split())
k = int(input())
if a >= b:
x = a // b
x_ = len(bin(x)) - 2
else:
x_ = 0
b *= 2 ** x_
if b >= c:
y = b // c
y_ = len(bin(y)) -2
else:
y_ = 0
if (x_ + y_) <= k:
print('Yes')
else:
print('No') | 0 | null | 4,343,762,799,712 | 65 | 101 |
import math
while True:
try:
a = list(map(int,input().split()))
b = (math.gcd(a[0],a[1]))
c = ((a[0]*a[1])//math.gcd(a[0],a[1]))
print(b,c)
except EOFError:
break
| N = int(input())
f = 0
for i in range(1,10):
for j in range(1,10):
if i*j == N:
f += 1
break
if f == 0:
print("No")
else:
print("Yes") | 0 | null | 79,962,954,599,440 | 5 | 287 |
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10000000)
from collections import defaultdict
from bisect import *
mod = 10**9+7
H = int(input())
W = int(input())
N = int(input())
h, w = max(H, W), min(H, W)
cnt, ans = 0, 0
while cnt < N:
cnt += h
ans += 1
print(ans)
| x1, y1, x2, y2 = map(float, input().split())
print('%.8f' % (((x2 - x1)**2 + (y2 - y1)**2))**0.5)
| 0 | null | 44,265,465,962,640 | 236 | 29 |
n,k = list(map(int, input().split()))
mod = int(1e9+7)
def init_cmb(Nmax):
#mod = 10**9+7 #出力の制限
g1 = [1, 1] # 元テーブル
g2 = [1, 1] # 逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
for i in range(2, Nmax + 1):
g1.append((g1[-1] * i) % mod)
inverse.append((-inverse[mod % i] * (mod//i)) % mod)
g2.append((g2[-1] * inverse[-1]) % mod)
return g1, g2
g1,g2 = init_cmb(n+10)
def cmb(n, r, modn=mod):
if (r < 0 or r > n):
return 0
r = min(r, n-r)
return g1[n] * g2[r] * g2[n-r] % modn
# ci = 0 である個数が m となるような数列の数は、 nCm ×n−m Hm = nCm * n-1Cn-m-1
# 0 <= m < n で足算する
ans = 0
for i in range(min(k+1,n)):
wk = cmb(n,i) * cmb(n-1, n-i-1) % mod
ans = (ans + wk ) % mod
print(ans) | LARGE = 10 ** 9 + 7
def solve(n, k):
# singular cases
if k == 0:
return 1
elif k == 1:
return n * (n - 1)
# pow
pow_mod = [1] * (n + 1)
for i in range(n):
pow_mod[i + 1] = pow_mod[i] * (i + 1) % LARGE
pow_mod_inv = [1] * (n + 1)
pow_mod_inv[-1] = pow(pow_mod[-1], LARGE - 2, LARGE)
for i in range(n - 1, 0, -1):
pow_mod_inv[i] = pow_mod_inv[i + 1] * (i + 1) % LARGE
res = 0
for i in range(min(k, n - 1) + 1):
# find where to set 0
pick_zeros = pow_mod[n] * pow_mod_inv[i] * pow_mod_inv[n - i] % LARGE
# how to assign ones
assign_ones = pow_mod[n - 1] * pow_mod_inv[i] * pow_mod_inv[n - 1 - i] % LARGE
res += pick_zeros * assign_ones
res %= LARGE
return res
def main():
n, k = map(int, input().split())
res = solve(n, k)
print(res)
def test():
assert solve(3, 2) == 10
assert solve(200000, 1000000000) == 607923868
assert solve(15, 6) == 22583772
if __name__ == "__main__":
test()
main()
| 1 | 66,809,844,912,160 | null | 215 | 215 |
n = int(raw_input())
graph = [[] for i in range(n)]
for i in range(n):
entry = map(int,raw_input().strip().split(' '))
u = entry[0]-1
for v in entry[2:]:
v -= 1
graph[u].append(v)
d = [-1 for i in range(n)]
d[0] = 0
t = 1
q = []
q.append(0)
while len(q) > 0:
u = q[0]
for v in graph[u]:
if d[v] == -1:
q.append(v)
d[v] = d[u]+1
del q[0]
for i in range(n):
print i+1,d[i] | str = raw_input()
q = input()
for ans in range(q):
ans = raw_input()
ans1 = ans.split(' ')
if ans1[0] == 'replace':
str = str[0:int(ans1[1])]+ans1[3]+ str[int(ans1[2])+1:len(str)]
if ans1[0] == 'reverse':
str = str[0:int(ans1[1])]+ str[int(ans1[1]):int(ans1[2])+1][::-1] + str[int(ans1[2])+1:len(str)]
if ans1[0] == 'print':
print str[int(ans1[1]):int(ans1[2])+1] | 0 | null | 1,069,890,375,148 | 9 | 68 |
NML = input().split()
n = int(NML[0])
m = int(NML[1])
l = int(NML[2])
A = []
B = []
for i in range(n):
A.append([])
A_r = input().split()
for j in range(m):
A[i].append(int(A_r[j]))
for i in range(m):
B.append([])
B_r= input().split()
for j in range(l):
B[i].append(int(B_r[j]))
for i in range(n):
for j in range(l):
out=0
for k in range(m):
out +=A[i][k]*B[k][j]
print(str(out),end="")
if j != l-1:
print(" ",end="")
print("") | a,b = map(int, raw_input().split())
A = [map(int, raw_input().split()) for _ in xrange(a)]
B = [input() for _ in xrange(b)]
C = [sum([A[i][j] * B[j] for j in xrange(b)]) for i in xrange(a)]
for x in C:
print x | 0 | null | 1,294,048,188,852 | 60 | 56 |
n = int(input())
a = list(map(int, input().split())) # 横入力
x = [0]
aaa = 0
aa = sum(a)
# y = [aa]
for i in range(n):
aaa += a[i]
x.append(aaa)
# aa -= a[i]
# y.append(aa)
ans = 202020202020
for i in range(n+1):
ans = min(ans, abs(aa - x[i]*2))
print(ans) | s=input()
a=[0]*(len(s)+1)
for i in range(len(s)):
if s[i]=="<":
a[i+1]=a[i]+1
for i in range(len(s)-1,-1,-1):
if s[i]==">":
a[i]=max(a[i],a[i+1]+1)
print(sum(a)) | 0 | null | 148,883,941,502,140 | 276 | 285 |
K, N = map(int, input().split())
A = list(map(int, input().split()))
res = A[0] + (K - A[N-1])
for i in range(1, N):
dist = A[i] - A[i-1]
if res < dist:
res = dist
print(K - res) | a = int(input())
out = a + a**2 + a**3
print(out) | 0 | null | 26,794,526,288,206 | 186 | 115 |
n = int(input())
x = list(map(int,input().split()))
x.sort()
xmin = x[0]
xmax = x[-1]
ans = 10**9
for i in range(xmin, xmax+1):
d = 0
for j in x:
d += (j - i)**2
ans = min(ans, d)
print(ans) | memo = [1, 1]
def fib(n):
if (n < len(memo)):
return memo[n]
memo.append(fib(n-1) + fib(n-2))
return memo[n]
N = int(input())
print(fib(N))
| 0 | null | 32,508,377,375,720 | 213 | 7 |
while True:
H, W = [int(x) for x in input().split()]
if H == 0 and W == 0 : break
for i in range(H):
for j in range(W):
if i == 0 or i == (H-1) or j == 0 or j == (W-1):
print("#", end = '')
else:
print(".", end='')
print("\n", end="")
print("\n", end="") | while (1):
h, w = map(int, input().split())
if (h == 0) and (w == 0):
break
print("#" * w)
for i in range(h - 2):
print("#" + "." * (w - 2) + "#")
print("#" * w)
print()
| 1 | 834,683,238,762 | null | 50 | 50 |
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
MOD = 10**9+7
for i in range(2, 2*10**6+1):
g1.append((g1[-1] * i) % MOD)
inverse.append((-inverse[MOD % i] * (MOD // i)) % MOD)
g2.append((g2[-1] * inverse[-1]) % MOD)
def comb(n, r, mod=MOD):
if r < 0 or r > n:
return 0
r = min(r, n - r)
return g1[n] * g2[r] * g2[n-r] % mod
K = int(input())
S = input()
N = len(S)
NN = N + K
ans = 0
pow25 = [1]
pow26 = [1]
for i in range(K+1):
pow25.append(pow25[-1]*25 % MOD)
pow26.append(pow26[-1]*26 % MOD)
for i in range(K+1):
n = NN - i
ans = (ans + pow26[i]*pow25[n-N]*comb(n-1, N-1)) % MOD
print(ans) | import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
return list(map(int,input().split()))
def m(): #複数文字
return map(int,input().split())
def onem(): #Nとかの取得
return int(input())
def s(x): #圧縮
a = []
if len(x) == 0:
return []
aa = x[0]
su = 1
for i in range(len(x)-1):
if aa != x[i+1]:
a.append([aa,su])
aa = x[i+1]
su = 1
else:
su += 1
a.append([aa,su])
return a
def jo(x): #listをスペースごとに分ける
return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
return max(map(max,x))
def In(x,a): #aがリスト(sorted)
k = bs.bisect_left(a,x)
if k != len(a) and a[k] == x:
return True
else:
return False
def pow_k(x, n):
ans = 1
while n:
if n % 2:
ans *= x
x *= x
n >>= 1
return ans
"""
def nibu(x,n,r):
ll = 0
rr = r
while True:
mid = (ll+rr)//2
if rr == mid:
return ll
if (ここに評価入れる):
rr = mid
else:
ll = mid+1
"""
mod = 10**9+7 #出力の制限
N = 10**6*2
def cmb(n, r):
if ( r<0 or r>n ):
return 0
r = min(r, n-r)
return g1[n] * g2[r] * g2[n-r] % mod
def p(n,r):
if ( r<0 or r>n ):
return 0
return g1[n] * g2[n-r] % mod
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
for i in range( 2, N + 1 ):
g1.append( ( g1[-1] * i ) % mod )
inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
g2.append( (g2[-1] * inverse[-1]) % mod )
# a = cmb(n,r)
k = onem()
s = input()[:-1]
ans = 0
ss = len(s)
for i in range(ss,ss+k+1):
ans += cmb(ss+k-(ss+k-i)-1,ss-1) * pow(25,i-ss,mod) * pow(26,(ss+k-i),mod)
ans %= mod
print(ans)
| 1 | 12,692,056,789,732 | null | 124 | 124 |
a = int(input())
class calculate:
def __init__(self,a):
self.check = a
def get_ans(self,a):
return a + a**2 + a**3
valuable = calculate(a)
#Sprint(valuable.check)
ans = valuable.get_ans(a)
print(ans) | a = int(input())
ans = a*(1+a*(1+a))
print(ans) | 1 | 10,322,248,383,372 | null | 115 | 115 |
n = int(input())
S = [1]*13
H = [1]*13
C = [1]*13
D = [1]*13
mark = [""]*n
num = [""]*n
for i in range(n):
mark[i], num[i] = input().split()
for i in range(n):
if mark[i] == "S":
S[int(num[i])-1] = 0
if mark[i] == "H":
H[int(num[i])-1] = 0
if mark[i] == "C":
C[int(num[i])-1] = 0
if mark[i] == "D":
D[int(num[i])-1] = 0
for i in range(13):
if S[i]:
print("S " + str(i+1))
for i in range(13):
if H[i]:
print("H " + str(i+1))
for i in range(13):
if C[i]:
print("C " + str(i+1))
for i in range(13):
if D[i]:
print("D " + str(i+1)) | S_list = [input() for i in range(2)]
N,K = map(int,S_list[0].split())
h_list = list(map(int,S_list[1].split()))
number = 0
for i in h_list:
if i>=K:
number += 1
print(number) | 0 | null | 90,245,728,249,548 | 54 | 298 |
def getN():
return int(input())
def getNM():
return map(int, input().split())
def getList():
return list(map(int, input().split()))
def getArray(intn):
return [int(input()) for i in range(intn)]
def input():
return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
ns = []
while len(ns) < rantime:
n = random.randint(ran1, ran2)
if not n in ns:
ns.append(n)
return sorted(ns)
def rand_query(ran1, ran2, rantime):
r_query = []
while len(r_query) < rantime:
n_q = rand_ints_nodup(ran1, ran2, 2)
if not n_q in r_query:
r_query.append(n_q)
return sorted(r_query)
from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import permutations
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right
import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7
#############
# Main Code #
#############
N, M = getNM()
A = getList()
A.sort()
ans = 0
way = 1
fact =[1] #階乗
# 5 * 4 * 3 * 2 * 1
for i in range(1, N + 1):
fact.append(fact[i - 1] * i % mod)
facv = [0] * (N + 1) #階乗の逆元
facv[-1] = pow(fact[-1], mod - 2 , mod)
# 1 / 5 * 4 * 3 * 2 * 1のmod
for i in range(N - 1, -1, -1):
facv[i] = facv[i + 1] * (i + 1) % mod
def cmb(n, r):
if n < r:
return 0
# 計算
return fact[n] * facv[r] * facv[n - r] % mod
for i in range(N - 2 + 1):
min_sum = A[i] * cmb(N - i - 1, M - 1)
max_sum = A[-i - 1] * cmb(N - i - 1, M - 1)
ans += (max_sum - min_sum) % mod
print(ans % mod) | n = int(input())
lst = list(map(int, input().split()))
for i in range(n):
li = lst[i]
j = i-1
while j >= 0 and lst[j] > li:
lst[j:j+2] = lst[j+1], lst[j]
j -= 1
print(*lst) | 0 | null | 47,815,351,770,560 | 242 | 10 |
input()
a = list(input().split())
print(*a[::-1])
| import sys
import string
C = input()
if C == 'z' : sys.exit()
pos = string.ascii_lowercase.index(C)+1
print(string.ascii_lowercase[pos]) | 0 | null | 46,668,339,515,040 | 53 | 239 |
N = int(input())
A = list(map(int,input().split()))
minval = 0
ans = 1000
for i in range(1, N):
if A[i] > A[minval]:
pstock = ans // A[minval]
ans = ans%A[minval] + A[i]*pstock
minval = i
print(ans) | n = int(input())
arm = []
for i in range(n):
x , l = map(int,input().split())
arm.append([x,l])
arm.sort()
dp = [[0,0] for i in range(n)]
dp[0][1] = arm[0][0] + arm[0][1]
for i in range(1,n):
if dp[i-1][1] <= arm[i][0] -arm[i][1]:
dp[i][0] = dp[i-1][0]
dp[i][1] = arm[i][0] + arm[i][1]
else:
dp[i][0] = dp[i-1][0] + 1
dp[i][1] = min(arm[i][0] + arm[i][1],dp[i-1][1])
print(n-dp[n-1][0]) | 0 | null | 48,402,405,813,322 | 103 | 237 |
def main():
K = int(input())
S = input()
mod = pow(10, 9) + 7
N = len(S)
g1 = [1, 1]
g2 = [1, 1]
inv = [0, 1]
for i in range(2, K+N+1):
g1.append((g1[-1] * i) % mod)
inv.append( ( -inv[mod % i] * (mod//i)) % mod )
g2.append((g2[-1] * inv[-1]) % mod)
def combi(n, r):
r = min(r, n-r)
return g1[n]*g2[r]*g2[n-r]%mod
pow25 = [1]
pow26 = [1]
for i in range(K):
pow25.append(pow25[-1] * 25 % mod)
pow26.append(pow26[-1] * 26 % mod)
ans = 0
for i in range(N-1, N+K):
ans += combi(i, N-1) * pow25[i-N+1] % mod * pow26[K-i+N-1] % mod
ans %= mod
return ans
if __name__ == '__main__':
print(main()) | N=int(input())
A=list(map(int,input().split()))
mod=10**9+7
B=[0]
for i in range(1,N+1):
B.append(A[i-1]+B[i-1])
ans=0
for i in range(N-1):
ans+=A[i]*(B[N]-B[i+1])
ans%=mod
print(int(ans)) | 0 | null | 8,324,455,553,682 | 124 | 83 |
H = []
W = []
i = 0
while True:
h, w = map(int, input().split())
H.append(h)
W.append(w)
if H[i] == 0 and W[i] == 0:
break
i += 1
i = 0
while True:
if H[i] == 0 and W[i] == 0:
break
for j in range(H[i]):
for k in range(W[i]):
print("#", end="")
print()
print()
i += 1 | S,W = map(int, input().split())
print("suanfsea f e"[S<=W::2]) | 0 | null | 14,895,554,424,800 | 49 | 163 |
def nCr(n,r,fac,finv):
mod = (10**9)+7
ans = fac[n] * (finv[r] * finv[n-r] % mod) % mod
return ans
k = int(input())
s = input()
l = len(s)
n = l+k+1
# als = list(map(int,input().split()))
# als.sort()
ans = 0
mod = (10**9)+7
fac = [1,1]+[0]*n
finv = [1,1]+[0]*n
inv = [1,1]+[0]*n
for i in range(2,n+1):
fac[i] = fac[i-1] * i % mod
inv[i] = mod - inv[mod%i] * (mod//i) % mod
finv[i] = finv[i-1] * inv[i] % mod
for i in range(k+1):
ans += nCr(l-i+k-1,l-1,fac,finv)*pow(26,i,mod)*pow(25,k-i,mod)
ans %= mod
print(ans) | def rec(num, string, total, xy_list, n):
x, y = xy_list[num]
if string:
pre_one = int(string[-1])
pre_x, pre_y = xy_list[pre_one]
distance = ((x - pre_x)**2 + (y - pre_y)**2)**0.5
total+=distance
string+=str(num)
if len(string)==n:
return total
all_total = 0
ret_list = [i for i in range(n) if str(i) not in string]
for one in ret_list:
all_total+=rec(one, string, total, xy_list, n)
return all_total
def main():
n = int(input())
xy_list = []
k = 1
for i in range(n):
x, y = list(map(int, input().split(" ")))
xy_list.append((x, y))
k*=(i+1)
all_total = 0
for i in range(n):
all_total+=rec(i, "", 0, xy_list, n)
print(all_total/k)
if __name__=="__main__":
main()
| 0 | null | 80,282,632,126,370 | 124 | 280 |
n = int(input())
a, b = map(int, input().split())
i = 0
ans = "NG"
while i <= b:
if i >= a and i % n == 0:
ans = "OK"
i += n
print(ans)
| k=int(input())
for i in range(k):
print('ACL', end='') | 0 | null | 14,284,433,717,908 | 158 | 69 |
n = int(input())
a = list(map(int, input().split()))
x = 0
for a_i in a:
x ^= a_i
for a_i in a:
print(x ^ a_i) | X, Y = map(int, input().split())
X1, Y1 = map(int, input().split())
if Y1 == 1:
print("1")
else:
print("0")
| 0 | null | 68,292,696,555,148 | 123 | 264 |
import sys
class Dice(object):
def __init__(self, dice):
self.__dice = dice
def roll_north(self):
self.__dice = (self.__dice[1], self.__dice[5], self.__dice[2],
self.__dice[3], self.__dice[0], self.__dice[4])
def roll_south(self):
self.__dice = (self.__dice[4], self.__dice[0], self.__dice[2],
self.__dice[3], self.__dice[5], self.__dice[1])
def roll_west(self):
self.__dice = (self.__dice[2], self.__dice[1], self.__dice[5],
self.__dice[0], self.__dice[4], self.__dice[3])
def roll_east(self):
self.__dice = (self.__dice[3], self.__dice[1], self.__dice[0],
self.__dice[5], self.__dice[4], self.__dice[2])
def number(self, face_id):
return self.__dice[face_id - 1]
dice = Dice([int(i) for i in sys.stdin.readline().split()])
command = sys.stdin.readline().strip()
for c in command:
if c == "N":
dice.roll_north()
elif c == "S":
dice.roll_south()
elif c == "W":
dice.roll_west()
elif c == "E":
dice.roll_east()
print(dice.number(1)) | class Dice:
def __init__(self):
self.N = [1, 5, 2, 3, 0, 4]
self.S = [4, 0, 2, 3, 5, 1]
self.E = [3, 1, 0, 5, 4, 2]
self.W = [2, 1, 5, 0, 4, 3]
def roll(self, dice, dice_t, direction):
for d in direction:
if d == "N":
for i in range(6):
dice_t[i] = dice[self.N[i]]
elif d == "S":
for i in range(6):
dice_t[i] = dice[self.S[i]]
elif d == "E":
for i in range(6):
dice_t[i] = dice[self.E[i]]
else:
for i in range(6):
dice_t[i] = dice[self.W[i]]
for i in range(6):
dice[i] = dice_t[i]
d = Dice()
dice = [dice for dice in input().split()]
dice_t = ["" for dice_t in range(6)]
direction = input()
d.roll(dice, dice_t, direction)
print(dice[0]) | 1 | 228,128,433,180 | null | 33 | 33 |
a = input()
if "A" <= a <= "Z":
print("A")
else:
print("a") | if __name__ == '__main__':
s = input()
if s.islower():
print("a")
else:
print("A") | 1 | 11,356,677,488,410 | null | 119 | 119 |
N = int(input())
S = list(input())
S.append("test")
i = 0
while N > 0:
if S[i] == S[i+1]:
S.pop(i)
i = i - 1
i = i + 1
N = N - 1
print(len(S)-1)
| import math
N,M,K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A.append(math.inf)
B.append(math.inf)
best = 0
i = j = 0
while K >= A[i]:
K -= A[i]
i += 1
while True:
while K >= B[j]:
K -= B[j]
j += 1
best = max(best, i+j)
if i == 0: break
i -= 1
K += A[i]
print(best)
| 0 | null | 90,386,729,043,848 | 293 | 117 |
W,H,x,y,r =map(int,input().split())
if (r<=x and x+r<=W and r<=y and y+r<=H):
print("Yes")
else:
print("No")
| W,H,x,y,r=map(int,input().split())
print("Yes"*(r<=x<=W-r)*(r<=y<=H-r)or"No")
| 1 | 435,573,831,042 | null | 41 | 41 |
import sys
input()
rl = sys.stdin.readlines()
d = {}
for i in rl:
#c, s = i.split()
if i[0] == 'i':
#if c[0] == 'i':
d[i[7:]] = 0
#d[s] = 0
else:
if i[5:] in d:
#if s in d:
print('yes')
else:
print('no') | n = int(input())
s = set()
for i in range(n):
a,b = input().strip().split()
if a == 'insert':
s.add(b)
if a == 'find':
if b in s:
print('yes')
else:
print('no')
| 1 | 77,510,082,210 | null | 23 | 23 |
n=str(input())
a=list(n)
b=0
for i in a:
b=b+int(i)
if b%9==0:
print("Yes")
else:
print("No") | import math
n = sum([int(x) for x in str(input()).split()])
a, b = divmod(n, 9)
print("No" if b else "Yes")
| 1 | 4,356,623,006,718 | null | 87 | 87 |
S = input()
if S[1] == 'R':
print('ABC')
elif S[1] == 'B':
print('ARC') | h, n = map(int,input().split())
a = [0 for i in range(n)]
b = [0 for i in range(n)]
for i in range(n):
ai ,bi = map(int,input().split())
a[i] = ai
b[i] = bi
mh = [0 for i in range(10003)]
for i in range(1,h+1):
mb = 10**9
for j in range(n):
if mb > mh[i-a[j]] + b[j]:
mb = mh[i-a[j]] + b[j]
mh[i] = mb
print(mh[h])
| 0 | null | 52,699,299,031,042 | 153 | 229 |
s = input()
cnt = 0
for i in range(len(s)//2):
if s[i] == s[-i-1]:
continue
else:
cnt += 1
print(cnt) | #Good question
import sys
S = input()
if not S.islower(): sys.exit()
if not ( 1 <= len(S) <= 100 ):sys.exit()
pos = int(len(S)/2)
count = 0
for I in range(pos):
if S[I] != S[-I-1]:
count += 1
print(count) | 1 | 120,067,679,922,528 | null | 261 | 261 |
def insertion_sort(arr):
print(" ".join(map(str, arr)))
for i in range(1, len(arr)):
key = arr[i]
j = i - 1
while j >= 0 and arr[j] > key:
arr[j + 1] = arr[j]
j -= 1
arr[j + 1] = key
print(" ".join(map(str, arr)))
n = int(input())
arr = list(map(int, input().split()))
insertion_sort(arr) | n = int(input())
A = [int(x) for x in input().split()]
print(" ".join([str(x) for x in A]))
for i in range(1, n):
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(" ".join([str(x) for x in A])) | 1 | 5,008,882,508 | null | 10 | 10 |
import itertools
n = int(input())
s = ""
for i in range(n):
s += str(i+1)
l = list(itertools.permutations(s, n))
p = tuple(input().split())
q = tuple(input().split())
a = l.index(p)
b = l.index(q)
print(abs(a-b)) | import itertools
n=[x for x in range(1,int(input())+1)]
P=list(map(int, input().split()))
Q=list(map(int, input().split()))
for i, a in enumerate(itertools.permutations(n), start=1):
if list(a)==P:
p=i
if list(a)==Q:
q=i
print(abs(p-q))
| 1 | 101,076,184,074,528 | null | 246 | 246 |
my_range = int(input())
data_in = list(map(int,input().split()))
n_of_odd = 0
for ind in range(my_range):
if (ind % 2) == 0:
rem = data_in[ind] % 2
n_of_odd = n_of_odd + rem
print(n_of_odd) | from collections import deque
import copy
H,W = map(int,input().split())
S = [list(input()) for _ in range(H)]
def bfs(x,y):
check = copy.deepcopy(S)
que = deque()
que.append((x,y))
check[y][x] = 0
while que.__len__() != 0:
x,y = que.popleft()
tmp = check[y][x]
for dx,dy in (1,0),(-1,0),(0,1),(0,-1):
sx = x + dx
sy = y + dy
if -1 < sx < W and -1 < sy < H:
if check[sy][sx] == '.':
check[sy][sx] = tmp + 1
que.append((sx,sy))
return tmp
ans = 0
for x in range(W):
for y in range(H):
if S[y][x] == '.':
ans = max(bfs(x,y),ans)
print(ans) | 0 | null | 50,875,245,512,870 | 105 | 241 |
input()
a = list(input().split())
print(*a[::-1])
| # -*- coding: utf-8 -*-
def simu(pro, q):
end_time = 0
while bool(pro):
if pro[1] > q:
end_time += q
pro.append(pro[0])
pro.append(pro[1] - q)
pro.pop(0)
pro.pop(0)
elif pro[1] <= q:
end_time += pro[1]
print('{0} {1}'.format(pro[0], end_time))
pro.pop(0)
pro.pop(0)
n, q = list(map(int, input().split()))
pro = []
for i in range(n):
name, time = list(input().split())
pro.append(name)
pro.append(int(time))
simu(pro, q)
| 0 | null | 511,596,597,860 | 53 | 19 |
n,m,p=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
a=[0]*(n+1) ; b=[0]*(m+1)
for i in range(n):
a[i+1]+=a[i]+A[i]
for j in range(m):
b[j+1]=b[j]+B[j]
now=-1
import bisect as bi
for i in range(n+1):
if a[i]>p : break
G=p-a[i]
now=max(bi.bisect(b, G)+i-1, now)
print(now)
| h,w,k = map(int, input().split())
s = []
st = 0
zero = [0 for i in range(h)]
z = 0
for i in range(h):
t = input()
st += t.count('#')
zero[i] = t.count('#')
s.append(t)
cake = 0
ans = [[0 for j in range(w)] for i in range(h)]
for i in range(h):
if zero[i] == 0:
continue
cake += 1
t = 0
for j in range(w):
if s[i][j] == '#':
t += 1
if t >= 2:
cake += 1
ans[i][j] = cake
for i in range(h-1):
if zero[i+1] != 0:
continue
if ans[i][0] == 0:
continue
for j in range(w):
ans[i+1][j] = ans[i][j]
for i in range(h-1,0,-1):
if zero[i-1] != 0:
continue
for j in range(w):
ans[i-1][j] = ans[i][j]
for i in range(h):
print (*ans[i]) | 0 | null | 76,962,577,300,972 | 117 | 277 |
a = input()
s = a % 60
a = (a - s) / 60
m = a % 60
a = (a - m) / 60
h = a
print "%s:%s:%s" % (str(h), str(m), str(s)) | input = int(input().strip())
hour = input // 3600
min = (input - 3600*hour) // 60
sec = input - 3600 * hour - 60 * min
print (":".join([str(hour), str(min), str(sec)])) | 1 | 331,613,193,788 | null | 37 | 37 |
def gcd(a, b):
c = max([a, b])
d = min([a, b])
if c % d == 0:
return d
else:
return gcd(d, c % d)
nums = input().split()
print(gcd(int(nums[0]), int(nums[1])))
| a, b = map(int, input().rstrip().split(" "))
if a > b:
A = a
B = b
else:
A = b
B = a
GCD = 1
while True:
A, B = B, A%B
if B == 0:
break
print (str(A)) | 1 | 8,533,532,910 | null | 11 | 11 |
def dontbelate(D,T,S):
if T < D//S:
return 'No'
elif T > D//S:
return 'Yes'
else:
if D%S == 0:
return 'Yes'
else:
return 'No'
if __name__ == "__main__":
D,T,S = map(int, input().split())
print(dontbelate(D,T,S)) | a,b,c=map(int,input().split());print('YNeos'[a/b>c::2]) | 1 | 3,573,080,948,876 | null | 81 | 81 |
n = input()
m = len(n)
x = 0
for i in range(m):
x += int(n[i])
print("Yes" if x % 9 == 0 else "No") | a = int(input())
b = int(input())
t = set([1, 2, 3])
s = set([a,b])
ans = t - s
print(list(ans)[0]) | 0 | null | 57,548,146,979,858 | 87 | 254 |
n = int(input())
s = input().split()
s.reverse()
print(' '.join(map(str,s)))
| def az15():
n = input()
xs = map(int,raw_input().split())
xs.reverse()
for i in range(0,len(xs)):
print xs[i],
az15() | 1 | 970,689,306,990 | null | 53 | 53 |
n = int(input())
n3 = n**3
print(n3) | n = int(input())
d = set()
for _ in range(n):
c, s = input().split()
if c == 'insert':
d.add(s)
else:
print('yes' if s in d else 'no')
| 0 | null | 172,173,861,788 | 35 | 23 |
def main():
N, A, B = map(int, input().split())
diff = abs(A-B)
if diff%2 == 0:
ans = diff//2
else:
# 端に行く
# 一回端のままになる => 偶数のときと同じ
ans = min(A-1, N-B)
diff -= 1; ans += 1
ans += diff//2
print(ans)
if __name__ == "__main__":
main()
| a = input().split()
b = str(a[0])
c = str(a[1])
print(c+b) | 0 | null | 106,253,625,320,220 | 253 | 248 |
#!/usr/bin/env python3
import collections as cl
import sys
class Combination:
"""
O(n)の前計算を1回行うことで,O(1)でnCr mod mを求められる
n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
使用例:
comb = Combination(1000000)
print(comb(5, 3)) # 10
"""
def __init__(self, n_max, mod=10**9+7):
self.mod = mod
self.modinv = self.make_modinv_list(n_max)
self.fac, self.facinv = self.make_factorial_list(n_max)
def __call__(self, n, r):
return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod
def make_factorial_list(self, n):
# 階乗のリストと階乗のmod逆元のリストを返す O(n)
# self.make_modinv_list()が先に実行されている必要がある
fac = [1]
facinv = [1]
for i in range(1, n+1):
fac.append(fac[i-1] * i % self.mod)
facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
return fac, facinv
def make_modinv_list(self, n):
# 0からnまでのmod逆元のリストを返す O(n)
modinv = [0] * (n+1)
modinv[1] = 1
for i in range(2, n+1):
modinv[i] = self.mod - self.mod//i * \
modinv[self.mod % i] % self.mod
return modinv
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():
X, Y = MI()
if (X+Y) % 3 != 0:
print(0)
return
ttl = int((X+Y)/3)
a = X - ttl
if (ttl < a or a < 0):
print(0)
return
comb = Combination(ttl)
tmp = comb(ttl, a)
print(tmp)
main()
| #coding:UTF-8
def BS(N,A):
count=0
flag=True
while flag==True:
flag=False
for i in range(1,N):
if A[N-i]<A[N-i-1]:
swap=A[N-i]
A[N-i]=A[N-i-1]
A[N-i-1]=swap
flag=True
count+=1
for i in range(len(A)):
A[i]=str(A[i])
print(" ".join(A))
print(count)
if __name__=="__main__":
N=int(input())
a=input()
A=a.split(" ")
for i in range(len(A)):
A[i]=int(A[i])
BS(N,A) | 0 | null | 74,781,021,612,100 | 281 | 14 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.