code1
stringlengths 17
427k
| code2
stringlengths 17
427k
| similar
int64 0
1
| pair_id
int64 2
181,637B
⌀ | question_pair_id
float64 3.7M
180,677B
⌀ | code1_group
int64 1
299
| code2_group
int64 1
299
|
---|---|---|---|---|---|---|
x,y = map(int,input().split())
A =(-y+4.0*x)/2.0
B = (y-2.0*x)/2.0
if A>=0 and B>=0 and A.is_integer() and B.is_integer():
print("Yes")
else:
print("No") | import math
def is_prime(n):
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
return False
return n != 1
n = int(input())
answer = 0
for _ in range(0, n):
m = int(input())
if is_prime(m):
answer = answer + 1
print(answer)
| 0 | null | 6,962,973,553,030 | 127 | 12 |
import itertools as itr
def call(n):
def devided_3(x):
return x % 3 == 0
def has_3(x):
return '3' in str(x)
data = filter(lambda x: devided_3(x) or has_3(x), range(1, n+1))
[print(' {0}'.format(i), end='') for i in data]
print()
if __name__ == '__main__':
n = int(input())
call(n) | #!/usr/bin/env python3
# from numba import njit
# input = stdin.readline
# @njit
def solve(a,b,c):
return c-a-b >= 0 and pow(c-a-b,2) > 4*a*b
def main():
a,b,c = map(int,input().split())
print("Yes" if solve(a,b,c) else "No")
return
if __name__ == '__main__':
main()
| 0 | null | 26,314,892,611,660 | 52 | 197 |
#coding:utf-8
while True:
h, w = map(int, raw_input(). split())
if h == w == 0:
break
for i in xrange(h):
print("#" * w)
print("") | N=int(input())
S=input()
while True:
x=''
ans=''
for i in S:
if (x==''):
x=i
continue
if x!=i:
#print("p:",x,i,ans)
ans+=x
x=i
#print("a:",x,i,ans)
ans+=x
#print('ans:',ans)
if ans==S:
break
else:
S=ans
print(len(ans)) | 0 | null | 85,140,758,829,982 | 49 | 293 |
from collections import Counter
n = int(input())
s = input()
cnt = Counter(s)
ans = cnt["R"]*cnt["G"]*cnt["B"]
for i in range(n):
for j in range(i+1,n):
k = 2*j-i
if k >= n: continue
if s[i] != s[j] and s[i] != s[k] and s[j] != s[k]: ans -= 1
print(ans) | n = int(input())
s = input()
al=s.count("R")*s.count("G")*s.count("B")
for i in range(n-2):
for k in range(i+1,n-1):
l=k+(k-i)
if l>=n:
continue
if s[i]!=s[k] and s[i]!=s[l] and s[k]!=s[l]:
al-=1
print(al)
| 1 | 36,318,742,031,088 | null | 175 | 175 |
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()
def resolve():
N,S=map(int,input().split())
A=list(map(int,input().split()))
# https://qiita.com/drken/items/dc53c683d6de8aeacf5a#%E9%A1%9E%E9%A1%8C-3
INF = 10**10 # INF+INFを計算してもオーバーフローしない範囲で大きく
MOD=998244353
I, J =N,S
# dpテーブル dp[i][j]:=i番目以下で選ばれしa_kの和がjになる通り数
dp = [[0]*(J+1) for _ in range(I+1)]
# 初期条件
dp[0][0] = 1
# ループ
for i in range(I):
for j in range(J+1):
dp[i+1][j]+=2*dp[i][j]
dp[i+1][j]%=MOD
if j+A[i]<=S:
dp[i+1][j+A[i]]+=dp[i][j]
dp[i+1][j+A[i]]%=MOD
print(dp[I][J])
resolve() | s = str(input())
num = [int(s[-1])]
for i in range(1, len(s)):
tmp = num[-1] + pow(10, i, 2019) * int(s[-i - 1])
num.append(tmp % 2019)
mod = [1] + [0] * 2018
ans = 0
for i in num:
m = i % 2019
ans += mod[m]
mod[m] += 1
print(ans)
| 0 | null | 24,184,361,646,302 | 138 | 166 |
N = int(input())
a, b = 0, 0
for i in range(int(N**(1/2)), 0, -1):
if N % i == 0:
a = i
b = N / a
break
print(int(a+b-2)) | def calculator(op, x, y):
if op == '+':
return x + y
elif op == '-':
return y - x
else:
return x * y
raw = [r for r in input().split()]
for i in range(len(raw)):
try:
raw[i] = int(raw[i])
except:
continue
arr = []
buff = 0
for i in range(len(raw)):
if isinstance(raw[i], int):
arr.append(raw[i])
else:
buff = calculator(raw[i], arr.pop(), arr.pop())
arr.append(buff)
print(*arr)
| 0 | null | 80,526,560,696,010 | 288 | 18 |
N, K, S = map(int, input().split())
a = [S for i in range(K)]
if S == 10 ** 9:
S -= 2
for i in range(N - K):
a.append(S + 1)
print(*a)
| if __name__ == '__main__':
n,m = map(int,input().split())
A = [-1 for _ in range(n)]
B = []
for i in range(m):
x,y = map(int,input().split())
B.append([x,y])
flg = True
for a in B:
x = a[0]
y = a[1]
if A[x-1] == -1:
A[x-1] = y
else:
if A[x-1] != y:
flg = False
break
ans = 0
if flg:
#穴埋め
for i,j in enumerate(A):
if j == -1:
if i == 0 and len(A) != 1:
A[i] = 1
else:
A[i] = 0
tmp = ""
for k in range(n):
tmp += str(A[k])
tmp = str(int(tmp))
if len(tmp) == n :
ans = int(tmp)
else:
ans = -1
else:
ans = -1
print(ans)
| 0 | null | 76,129,414,001,472 | 238 | 208 |
import itertools
N = int(input())
c = []
d = 0
for i in range(N):
x1, y1 = map(int, input().split())
c.append((x1,y1))
cp = list(itertools.permutations(c))
x = len(cp)
for i in range(x):
for j in range(N-1):
d += ((cp[i][j][0]-cp[i][j+1][0])**2 + (cp[i][j][1] - cp[i][j+1][1])**2)**0.5
print(d/x) | s = input()
k = int(input())
li = list(s)
lee = len(s)
if len(list(set(li))) == 1:
print((lee)*k//2)
exit()
def motome(n,list):
count = 0
kaihi_flag = False
li = list*n
for i,l in enumerate(li):
if i == 0:
continue
if l == li[i-1] and not kaihi_flag:
count += 1
kaihi_flag = True
else:
kaihi_flag = False
#print(count)
#print(count*k)
return count
if k >= 5 and k%2 == 1:
a = motome(3,li)
b = motome(5,li)
diff = b - a
ans = b + (k-5)//2*diff
print(ans)
elif k >=5 and k%2 == 0:
a = motome(2,li)
b = motome(4,li)
diff = b - a
ans = b + (k-4)//2*diff
print(ans)
else:
count = 0
kaihi_flag = False
li = li*k
for i,l in enumerate(li):
if i == 0:
continue
if l == li[i-1] and not kaihi_flag:
count += 1
kaihi_flag = True
else:
kaihi_flag = False
#print(count)
#print(count*k)
print(count)
| 0 | null | 162,439,254,220,080 | 280 | 296 |
n = int(input())
a = list(map(int, input().split()))
a = [(i, j) for i, j in enumerate(a, start=1)]
a.sort(key=lambda x: x[1])
a = [str(i) for i, j in a]
print(' '.join(a)) | n=int(input())
a=list(map(int,input().split()))
import numpy as np
x = np.argsort(a)
for i in range(n):
print(x[i]+1)
| 1 | 180,790,556,247,802 | null | 299 | 299 |
while True:
try:
x = map(int, raw_input().split(' '))
if x[0] < x[1]:
m = x[1]
n = x[0]
else:
m = x[0]
n = x[1]
# m is greatrer than n
while n !=0:
m,n = n,m % n
print m,x[0]*x[1]/m
except EOFError:
break | while(True):
try:
(a, b) = map(int, input().split(" "))
(x, y) = (a, b)
while (x != 0):
(x, y) = (y%x, x)
print("%s %s" %(y, a*b//y))
except:
break | 1 | 674,093,562 | null | 5 | 5 |
k , x = (int(a) for a in input().split())
if k*500 >= x :
print("Yes")
else : print("No") | K, X = input().split()
K = int(K)
X = int(X)
if 500*K >= X:
print("Yes")
else:
print("No") | 1 | 98,285,136,838,800 | null | 244 | 244 |
#!/usr/bin/env python3
import sys
def solve(N: int, K: int, C: int, S: str):
l = [None] * N
r = [None] * N
pre = -float('inf')
k = -1
for cur in range(N):
if cur - pre > C and S[cur] == 'o':
k += 1
pre = cur
l[k] = cur
pre = float('inf')
k = K
for cur in range(N-1, -1, -1):
if pre - cur > C and S[cur] == 'o':
k -= 1
pre = cur
r[k] = cur
return [ll+1 for ll, rr in zip(l[:K], r[:K]) if ll == rr]
# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template)
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
K = int(next(tokens)) # type: int
C = int(next(tokens)) # type: int
S = next(tokens) # type: str
print(*solve(N, K, C, S), sep='\n')
if __name__ == '__main__':
main()
| # coding: utf-8
list = []
for i in range(10):
list.append(int(input()))
slist = sorted(list)
for i in range(3):
print(slist[9-i]) | 0 | null | 20,498,853,607,408 | 182 | 2 |
from collections import defaultdict, deque
import sys, heapq, bisect, math, itertools, string, queue, copy, time
from fractions import gcd
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7
EPS = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
n = int(input())
l_list = list(map(int, input().split()))
l_combo = itertools.combinations(l_list, 3)
ans = 0
for i in l_combo:
if i[0] + i[1] > i[2] and i[1]+i[2] > i[0] and i[0] + i[2] > i[1] and i[0] != i[1] and i[1] != i[2] and i[0] != i[2]:
ans += 1
print(ans)
| import sys
for stdin in sys.stdin:
inlist = stdin.split()
a = int(inlist[0])
b = int(inlist[2])
op = inlist[1]
if op == "?":
break
elif op == "+":
print(a + b)
elif op == "-":
print(a - b)
elif op == "/":
print(a // b)
elif op == "*":
print(a * b) | 0 | null | 2,860,993,829,210 | 91 | 47 |
n,k=map(int,(input().split()))
ans=0
max=sum(range(n-k+1,n+1))*(n-k+2)
min=sum(range(k))*(n-k+2)
for i in range(1,n-k+2):
min+=(k-1+i)*(n-k+2-i)
for i in range(1,n-k+2):
max+=(n-k+1-i)*(n-k+2-i)
ans=(max-min+n-k+2)%(10**9+7)
print(ans) | # https://atcoder.jp/contests/abc163/tasks/abc163_d
def main():
n, k = map(int, input().split(" "))
# このやり方だと当然TLE
# total = 0
# for i in range(k, n + 2):
# a = 0
# b = 0
# for j in range(i):
# a += j
# b += n - j
# total += b - a + 1
# print(total)
max_num = sum(range(n - k + 1, n + 1))
min_num = sum(range(k))
c = max_num - min_num + 1
total = c
for i in range(k, n + 1):
max_num += n - i
min_num += i
c = max_num - min_num + 1
total += c
print(total % 1000000007)
if __name__ == '__main__':
main()
| 1 | 32,968,072,570,900 | null | 170 | 170 |
n=int(input())
l=sorted(list(map(int,input().split())))
for i,x in enumerate(l):
l[i]=format(x,'63b')
memo=[0]*63
for i in range(63):
for j in range(n):
if l[j][i]=='1':
memo[-i-1]+=1
now=1
ans=0
mod=10**9+7
for x in memo:
ans+=(now*x*(n-x))%mod
now*=2
print(ans%mod)
| #!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
n = I()
a = LI()
L = [1]
if a[-1] > 2**n:
print(-1)
quit()
if n == 0:
if a[0] == 0:
print(-1)
quit()
L2 = [a[-1]]
for i in range(n)[::-1]:
L2.append(min(L2[-1] + a[i], 2**i))
L2 = L2[::-1]
ans = 0
for i in range(n+1):
if i == 0:
tmp = 1
else:
tmp = (L[-1] - a[i-1]) * 2
if tmp <= 0:
print(-1)
quit()
ans += min(tmp, L2[i])
L.append(tmp)
if L[-1] - a[-1] < 0:
print(-1)
quit()
print(ans)
| 0 | null | 70,693,374,961,760 | 263 | 141 |
n,k = map(int, input().split())
mod = 10**9+7
def prepare():
fact = []
f = 1
for m in range(1, n):
f *= m
f %= mod
fact.append(f)
f *= n
f %= mod
fact.append(f)
factinv = [1, 1]
inv = [0, 1]
for i in range(2, n + 1):
inv.append((-inv[mod % i] * (mod // i)) % mod)
factinv.append((factinv[-1] * inv[-1]) % mod)
return fact, factinv
def cmb(a, r, p):
if (r < 0) or (n < r):
return 0
if a == 1:
return f[a] * v[r] * v[n - r] % mod
else:
return f[a] * v[r] * v[n - r - 1] % mod
f,v = prepare()
ans = 1
for i in range(1, min(k + 1, n)):
ans += cmb(0, i, mod) * cmb(1, i, mod)
ans %= mod
print(ans)
| s = input()
ret = s[:3]
print("{}".format(ret)) | 0 | null | 40,927,376,283,818 | 215 | 130 |
h, n = map(int, input().split())
li = list(map(int, input().split()))
if sum(li) >= h:
print('Yes')
else:
print('No') | N, K = map(int, input().split())
p = list(map(int, input().split()))
p.sort()
print(sum(p[:K])) | 0 | null | 44,944,306,622,700 | 226 | 120 |
def main():
n=int(input())
A=list(zip(list(map(int,input().split())),range(n)))
A.sort(reverse=True)
DP=[[0]*(n+1) for _ in range(n+1)]
for i in range(n+1):
for j in range(n+1):
if i+j>n:
break
a,idx=A[i+j-1]
if i>0:
DP[i][j]=max(DP[i][j],DP[i-1][j]+a*abs(idx-(i-1)))
if j>0:
DP[i][j]=max(DP[i][j],DP[i][j-1]+a*abs(idx-(n-j)))
ans=0
for i in range(n+1):
ans=max(ans,DP[i][n-i])
print(ans)
if __name__=='__main__':
main() | n = int(input())
dic_A = set()
dic_C = set()
dic_G = set()
dic_T = set()
for i in range(n) :
p, string = input().split()
if p == 'insert' :
if string[0] == 'A' :
dic_A.add(string)
elif string[0] == 'C' :
dic_C.add(string)
elif string[0] == 'G' :
dic_G.add(string)
else :
dic_T.add(string)
else :
if string[0] == 'A' :
if string in dic_A :
print('yes')
else :
print('no')
elif string[0] == 'C' :
if string in dic_C :
print('yes')
else :
print('no')
elif string[0] == 'G' :
if string in dic_G :
print('yes')
else :
print('no')
else :
if string in dic_T :
print('yes')
else :
print('no')
| 0 | null | 16,964,711,197,354 | 171 | 23 |
n = input()
for i in xrange(n):
a, b, c = sorted(map(int, raw_input().split()))
print 'YES' if a*a+b*b==c*c else 'NO' | N = int(input())
ToF = []
for i in range(N):
A = list(map(int,input().split()))
A.sort()
if A[0]**2 + A[1]**2 == A[2]**2:
ToF.append("YES")
else:
ToF.append("NO")
for i in ToF:
print(i) | 1 | 297,494,890 | null | 4 | 4 |
n,m,l=map(int,input().split())
abcs=[list(map(int,input().split())) for _ in range(m)]
for i in range(m):
abcs[i][0]-=1
abcs[i][1]-=1
inf =1234567890123456
dist = [[inf for i in range(n)] for j in range(n)]
for i in range(n):
dist[i][i] = 0
for i in range(m):
a=abcs[i][0]
b=abcs[i][1]
c=abcs[i][2]
dist[a][b] = dist[b][a] = c
for k in range(n):
for i in range(n):
for j in range(n):
dist[i][j] = min(dist[i][j],dist[i][k]+dist[k][j])
ans = [[inf for i in range(n)] for j in range(n)]
for i in range(n):
ans[i][i]=0
for i in range(n):
for j in range(i+1,n):
if dist[i][j]<=l:
ans[i][j]=ans[j][i]=1
for k in range(n):
for i in range(n):
for j in range(n):
ans[i][j] = min(ans[i][j],ans[i][k]+ans[k][j])
for _ in range(int(input())):
f,t=map(int,input().split())
f-=1
t-=1
print(ans[f][t]-1 if ans[f][t]!=inf else -1) | N, X, Y = [int(x) for x in input().split()]
counter = [0] * N
for i in range(1, N + 1):
for j in range(i + 1, N + 1):
d = min(abs(i - j), abs(i - X) + abs(j - Y) + 1, abs(i - Y) + abs(j - X) + 1)
counter[d] += 1
for i in range(1, N):
print(counter[i]) | 0 | null | 109,286,514,129,780 | 295 | 187 |
N,K = map(int,input().split())
R,S,P = map(int,input().split())
T = list(input())
for n in range(N-K):
if T[n+K]==T[n]:
T[n+K]=""
print(P*T.count("r")+R*T.count("s")+S*T.count("p")) | from collections import deque
n=int(input())
que=deque()
for i in range(n):
command=input()
if command=="deleteFirst":
que.popleft()
elif command=="deleteLast":
que.pop()
else:
command,num=command.split()
num=int(num)
if command=="insert":
que.appendleft(num)
else:
if num in que:
que.remove(num)
print(*que,sep=" ")
| 0 | null | 53,755,449,848,900 | 251 | 20 |
N, M = map(int, input().split())
data = [0]*N
solved = [False]*N
for _ in range(M):
p, S = input().split()
p = int(p) - 1
if solved[p] == False and S == "WA":
data[p] += 1
if solved[p] == False and S == "AC":
solved[p] = True
print(sum(solved),sum( x*y for x, y in zip(data, solved)) )
| import itertools
import functools
import math
from collections import Counter
from itertools import combinations
N=int(input())
print((N+1)//2)
| 0 | null | 76,214,883,206,692 | 240 | 206 |
n = int(input())
low = [0]*n
high = [0]*n
for i in range(n):
a, b = [int(x) for x in input().split(" ")]
low[i] = a
high[i] = b
low.sort()
high.sort()
if n%2 == 1:
print(high[n//2]-low[n//2]+1)
else:
x = (low[(n-1)//2] + low[n//2])/2
y = (high[(n-1)//2] + high[n//2])/2
print(int(2*y - 2*x + 1))
| N = int(input())
A = [0]*N
B = [0]*N
for n in range(N):
A[n],B[n] = map(int,input().split())
A.sort()
B.sort()
if N % 2 == 1:
print(B[N//2]-A[N//2]+1)
else:
Am = (A[N//2]+A[N//2-1])/2
Bm = (B[N//2]+B[N//2-1])/2
print(int((Bm-Am)*2)+1) | 1 | 17,274,560,496,230 | null | 137 | 137 |
input()
a = list(map(int, input().split()))
c = 1000000007
print(((sum(a)**2-sum(map(lambda x: x**2, a)))//2)%c) | d=list(map(int,input().split()))
c=list(input())
class dice(object):
def __init__(self, d):
self.d = d
def roll(self,com):
a1,a2,a3,a4,a5,a6=self.d
if com=="E":
self.d = [a4,a2,a1,a6,a5,a3]
elif com=="W":
self.d = [a3,a2,a6,a1,a5,a4]
elif com=="S":
self.d = [a5,a1,a3,a4,a6,a2]
elif com=="N":
self.d = [a2,a6,a3,a4,a1,a5]
dice1=dice(d)
for com in c:
dice1.roll(com)
print(dice1.d[0]) | 0 | null | 2,026,551,441,990 | 83 | 33 |
n = int(input())
output = ""
for i in range(1,n+1):
if i % 3 == 0:
output += " %s" % (i,)
continue
elif i % 10 == 3:
output += " %s" % (i,)
continue
x = i
while x > 1:
x = int(x/10)
if x % 10 == 3:
output += " %s" % (i,)
break
print(output) | x, y = map(int, input().split())
ans = max(4 - x, 0) + max(4 - y, 0)
print(ans * 10**5 if ans != 6 else 10**6)
| 0 | null | 70,993,499,611,548 | 52 | 275 |
N = input()
if int(N[(len(N)-1)]) in [2,4,5,7,9]:print('hon')
elif int(N[(len(N)-1)]) in [0,1,6,8]:print('pon')
elif int(N[(len(N)-1)]) in [3]:print('bon') | n = int(input())
a = [int(s) for s in input().split()]
if len(set(a)) == n:
print("YES")
else:
print("NO") | 0 | null | 46,749,428,505,374 | 142 | 222 |
N=int(input())
A=list(map(int,input().split()))
mod=10**9+7
buf=0
s=0
for k in range(N-1):
buf=(buf+A[N-1-k])%mod
s=(s+A[N-2-k]*buf)%mod
print(s)
| mod = 10**9+7
def main():
n = int(input())
a = list(map(int, input().split()))
wa = sum(a)%mod
ans = 0
for i in range(n):
wa -= a[i]%mod
ans += (a[i]*wa)
ans %= mod
print(ans)
if __name__ == "__main__":
main() | 1 | 3,767,768,714,668 | null | 83 | 83 |
def inpl(): return list(map(int, input().split()))
print((int(input())-1)//2) | X = int(input())
deposit = 100
y_later = 0
while deposit < X:
y_later += 1
deposit += deposit // 100
print(y_later) | 0 | null | 89,833,884,745,628 | 283 | 159 |
# coding: utf-8
# Here your code !
def func():
try:
line = input()
except:
print("input error")
return -1
marks = ("S","H","C","D")
cards = []
while(True):
try:
line = input().rstrip()
elements = line.split(" ")
if(elements[0] in marks):
elements[1]=int(elements[1])
cards.append(elements)
else:
print("1input error")
return -1
except EOFError:
break
except :
print("input error")
return -1
result=""
for mark in marks:
for i in range(1,14):
if([mark,i] not in cards):
result += mark+" "+str(i)+"\n"
if(len(result)>0):
print(result.rstrip())
func() | import sys
n = int(input()) # ?????£?????????????????????????????°
pic_list = ['S', 'H', 'C', 'D']
card_dict = {'S':[], 'H':[], 'C':[], 'D':[]} # ?????£?????????????????\?????????????????°
lost_card_dict = {'S':[], 'H':[], 'C':[], 'D':[]} # ?¶??????????????????\?????????????????°
# ?????????????¨??????\???????????????
for i in range(n):
pic, num = input().split()
card_dict[pic].append(int(num))
# ?¶???????????????????????¨??????\????¨????
for pic in card_dict.keys():
for j in range(1, 14):
if not j in card_dict[pic]:
lost_card_dict[pic].append(j)
# ?????????????????????
for pic in card_dict.keys():
lost_card_dict[pic] = sorted(lost_card_dict[pic])
# ?¶????????????????????????????
for pic in pic_list:
for k in range(len(lost_card_dict[pic])):
print(pic, lost_card_dict[pic][k]) | 1 | 1,052,504,475,608 | null | 54 | 54 |
r = int(input())
print(r * 2 * 3.1415926535897932384626433) | from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce, lru_cache
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT() : return int(input())
def MAP() : return map(int,input().split())
def MAP1() : return map(lambda x:int(x)-1,input().split())
def LIST() : return list(MAP())
def LIST1() : return list(MAP1())
n = INT()
a = LIST()
c = [0]*(10**6+1)
for x in a:
c[x] += 1
k = max(sum(c[i::i]) for i in range(2, 10**6+1))
if k <= 1:
print("pairwise coprime")
elif k < n:
print("setwise coprime")
else:
print("not coprime") | 0 | null | 17,648,311,358,128 | 167 | 85 |
x,k,d=map(int,input().split())
cur=abs(x)
count=min(cur//d,k)
cur-=d*count
k-=count
if k%2==1:
cur-=d
print(abs(cur))
| a,k,d = map(int, input().split())
if a < 0:
x = -a
else:
x = a
y = x % d
l = x // d
m = k - l
if m < 0:
ans = x - (k * d)
elif m % 2 ==0:
ans = y
else :
ans = y - d
print(abs(ans)) | 1 | 5,170,449,605,218 | null | 92 | 92 |
def get_ints():
return map(int, input().split())
def get_list():
return list(map(int, input().split()))
l, r, d = get_ints()
c = 0
for i in range(l, r + 1):
if i % d == 0:
c += 1
print(c) | H = int(input())
W = int(input())
N = int(input())
p = -1
if H > W:
p = H
else:
p = W
count = 1
result = 1
while True:
result = count * p
if result >= N:
print(count)
break
else:
count += 1
| 0 | null | 48,145,882,211,270 | 104 | 236 |
# -*- coding: utf-8 -*-
r, c = map(int, raw_input().split())
cl= [0] * c
for i in xrange(r):
t = map(int, raw_input().split())
for i, a in enumerate(t): cl[i] += a
print ' '.join(map(str, t)), sum(t)
print ' '.join(map(str, cl)), sum(cl) | height,width=map(int,input().split())
A=[]
for i in range(height):
A.append([int(j) for j in input().split()])
for i in range(height):
print(' '.join(map(str,A[i])),str(sum(A[i])))
B=[]
C=[0 for _ in range(width)]
for i in range(width):
for j in range(height):
s=0
s+=A[j][i]
B.append(s)
C[i]=sum(B)
B=[]
print(' '.join(map(str,C)),str(sum(C))) | 1 | 1,340,305,085,220 | null | 59 | 59 |
A = int(input())
print(A**2) | def calc_r(r):
return r*r
r = int(input())
result = calc_r(r)
print(result)
| 1 | 145,802,132,561,152 | null | 278 | 278 |
import math
foo = []
while True:
n = int(input())
if n == 0:
break
a = [int(x) for x in input().split()]
ave = sum(a)/len(a)
hoge = 0
for i in a:
hoge += (i - ave) ** 2
hoge /= len(a)
foo += [math.sqrt(hoge)]
for i in foo:
print(i) | import statistics
while True:
n = int(input())
if n == 0:
break
s = map(int, input().split())
print('{:.5f}'.format(statistics.pstdev(s))) | 1 | 193,567,302,940 | null | 31 | 31 |
# PDF参考
# スタックS1
S1 = []
# スタックS2
S2 = []
tmp_total = 0
counter = 0
upper = 0
# 総面積
total_layer = 0
for i,symbol in enumerate(input()):
if (symbol == '\\'):
S1.append(i)
elif (symbol == '/') and S1:
i_p = S1.pop()
total_layer = i - i_p
if S2 :
while S2 and S2[-1][0] > i_p:
cal = S2.pop()
total_layer += cal[1]
S2.append((i, total_layer))
print(sum([j[1] for j in S2]))
if (len(S2) != 0):
print(str(len(S2)) + ' ' + ' '.join([str(i[1]) for i in S2]))
else:
print(str(len(S2)))
| N = int(input())
M = 1000000007
t, t1, t2 = 1, 1, 1
for _ in range(N):
t, t1, t2 = t*10, t1*9, t2*8
t, t1, t2 = t%M, t1%M, t2%M
print((t - t1*2 + t2) % M)
| 0 | null | 1,626,376,256,992 | 21 | 78 |
import sys
from functools import reduce
from math import gcd
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
mod = 10 ** 9 + 7
N = int(readline())
A = list(map(int,readline().split()))
lcm = reduce(lambda x,y:x*y//gcd(x,y),A)
ans = 0
ans = sum(lcm//x for x in A)
print(ans%mod) | import sys
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())
N = NI()
data = [[a,i] for i,a in enumerate(LI())]
data.sort(reverse=True)
dp = [[0] * (N+1) for _ in range(N+1)]
for i in range(N):
a, p = data[i]
for j in range(i+1):
dp[i+1][j+1] = max(dp[i+1][j+1],dp[i][j] + abs(N-1-j-p)*a)
dp[i+1][j] = max(dp[i+1][j], dp[i][j] + abs(i-j-p)*a)
print(max(dp[-1]))
| 0 | null | 60,770,878,595,540 | 235 | 171 |
A,B,C,K = map(int,input().split())
SCO = 0
if A>K:
SCO+=K
else:
SCO+=A
if B<=(K-A):
if C<=(K-A-B):
SCO-=C
else:
SCO-=K-A-B
print(SCO) | a, b, c, d = map(int, input().split())
x = 0
y = 0
while c > 0:
c -= b
x += 1
while a > 0:
a -= d
y += 1
if x <= y:
print('Yes')
else:
print('No')
| 0 | null | 25,920,326,164,360 | 148 | 164 |
def minkowsuki(x, y, n):
return sum(abs(x[i] - y[i]) ** n for i in range(len(x))) ** (1 / n)
n = int(input())
x = list(map(float, input().split()))
y = list(map(float, input().split()))
print(minkowsuki(x, y, 1))
print(minkowsuki(x, y, 2))
print(minkowsuki(x, y, 3))
print(max(abs(x[i] - y[i]) for i in range(n))) | n, x, y = int(input()), list(map(int, input().split())), list(map(int, input().split()))
def dist(p):
return pow(sum(pow(abs(a - b), p) for a, b in zip(x, y)), 1.0 / p)
for i in [1, 2, 3]:
print(dist(i))
print(max(abs(a - b) for a, b in zip(x, y))) | 1 | 205,942,627,318 | null | 32 | 32 |
# import numpy as np
import itertools
if __name__ == "__main__":
N,K = map(int,input().split())
P = [ int(p)-1 for p in input().split() ]
C = list(map(int,input().split()))
# print(P)
# 一度計算したサイクル情報をキャッシュしておくための配列
# cycleIDs = np.full( N, -1, np.int64 )
cycleIDs = [ -1 for _ in range(N)]
cycleInfs = []
cycleID = 0
procCnt = 0
for n in range(N):
v = n
if cycleIDs[v] != -1:
continue
else:
currentCycleCosts = []
while True:
# 全頂点について、属するサイクルを計算する
currentCycleCosts.append( C[v] )
cycleIDs[v] = cycleID
v = P[v]
if cycleIDs[v] != -1:
# サイクル終了
# ループを含めない最大の処理回数
procCnt = K % len( currentCycleCosts )
# それで足りてるのかわからないが、Last2周分は、ループ合計がプラスでも必ずしもループするとは限らない
# その部分は、ちゃんと計算する
# -------------------------------------------------
# 4 101
# 2 3 4 1
# 50 -49 -50 50
# 上記のようなパターンの場合、
# 最大25回ループ + 1回処理可能だが、その場合、25 + 50 = 75
# 24回ループ + 2回処理でやめると、124になる
# 無条件でループする回数は、ループ可能な最大の回数-1らしい
# -------------------------------------------------
# 割り切れて、尚且つサイクル合計がマイナスのパターンで、最低1個は処理するのにもここで対応
if len( currentCycleCosts ) + procCnt <= K:
procCnt += len( currentCycleCosts )
cycleInfs.append( ( procCnt, len(currentCycleCosts), currentCycleCosts * 3 ) )
cycleID += 1
break
# scores = []
# procCnt = 0
ans = -10 ** 9
for procCnt, currentCycleSize, currentCycleCosts in cycleInfs:
# サイクル内でループしてスコアを稼ぐ場合の考慮
loopScore = 0
if sum(currentCycleCosts) > 0:
cycleLoopCnt = ( K - procCnt ) // currentCycleSize
loopScore = cycleLoopCnt * sum(currentCycleCosts[:currentCycleSize])
# print("loopScore",loopScore,procCnt)
# このサイクルに属する全頂点分をまとめて計算する
for i in range(currentCycleSize):
# print(np.roll( currentCycleCosts, i ).cumsum()[:procCnt])
score = max( itertools.accumulate( currentCycleCosts[i:i+procCnt] ) )
if ans < score + loopScore:
ans = score + loopScore
# ans = max( ans, score + loopScore )
print(ans)
# print(max(scores))
| from functools import reduce
from operator import xor
# via https://drken1215.hatenablog.com/entry/2020/06/22/122500
N, *A = map(int, open(0).read().split())
B = reduce(xor, A)
print(*map(lambda a: B^a, A)) | 0 | null | 9,027,855,753,052 | 93 | 123 |
h = int(input())
cnt = 1
ans = 0
while h:
ans += cnt
h //= 2
cnt *= 2
print(ans)
| import math;print(2**(int(math.log2(int(input())))+1)-1) | 1 | 79,982,370,561,090 | null | 228 | 228 |
from fractions import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import product, combinations,permutations
from copy import deepcopy
import sys
sys.setrecursionlimit(4100000)
if __name__ == '__main__':
N, K = map(int, input().split())
cnt = 0
while N!=0:
N //= K
cnt += 1
print(cnt) | N,K=map(int,input().split())
ans=0
while N>=K**ans:
ans+=1
print(ans) | 1 | 64,448,861,880,928 | null | 212 | 212 |
# https://atcoder.jp/contests/abc144/tasks/abc144_d
import math
a, b, x = list(map(int, input().split()))
if a * a * b * (1/2) <= x:
tmp = 2 * (a*a*b-x) / (a*a*a)
print(math.degrees(math.atan(tmp)))
else:
tmp = a*b*b / (2*x)
print(math.degrees(math.atan(tmp)))
| n = int(input())
a = list(map(int, input().split()))
count = 0
for i in a:
if i % 2 ==0:
if i % 3 != 0 and i % 5 != 0:
count+= 1
if count >= 1:
print("DENIED")
else:
print("APPROVED")
| 0 | null | 116,407,262,684,000 | 289 | 217 |
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#l = list(map(int, input().split()))
n, k = map(int, input().split())
temp = [0] * n
for i in range(k):
d = int(input())
l = list(map(int, input().split()))
for j in l:
temp[j-1] += 1
ans = 0
for i in temp:
if (i == 0):
ans += 1
print (ans)
| def resolve():
N, K = map(int, input().split())
candy_counter = [0] * N
for _ in range(K):
d = int(input())
A = list(map(int, input().split()))
for i in A:
candy_counter[i-1] += 1
ans = 0
for i in candy_counter:
if i == 0:
ans += 1
print(ans)
if __name__ == "__main__":
resolve() | 1 | 24,488,438,165,998 | null | 154 | 154 |
MOD = 1000000007
n = int(input())
aas = list(map(int, input().split()))
KET = 60
arr_0 = [0]*KET
arr_1 = [0]*KET
for i in aas:
bits = format(i,'060b')
for j in reversed(range(KET)):
if bits[j] == '0':
arr_0[KET-j-1] += 1
else:
arr_1[KET-j-1] += 1
res = 0
for i in range(KET):
res += (arr_0[i]%MOD * arr_1[i]%MOD)%MOD * pow(2,i,MOD)
res %= MOD
print(res) | def main():
n = int(input())
s_list = [None for _ in range(n)]
t_list = [None for _ in range(n)]
for i in range(n):
s, t = input().split()
s_list[i] = s
t_list[i] = int(t)
x = input()
x_index = s_list.index(x)
ans = sum(t_list[x_index + 1:])
print(ans)
if __name__ == "__main__":
main()
| 0 | null | 110,195,653,229,742 | 263 | 243 |
from math import ceil
n = int(input())
dept = 100000
for i in range(n):
dept += dept*0.05
dept = int(int(ceil(dept/1000)*1000))
print(dept) | A, B, C, K = input().split()
IA = int(A)
IB = int(B)
IC = int(C)
IK = int(K)
ALL = IA + IB + IC
cn = 0
if IA <= IK:
cn = cn + IA
D = IK - IA
if IB <= D:
E = D - IB
cn = cn - E
print(cn)
else:
print(cn)
else:
print(IK)
| 0 | null | 10,934,222,697,180 | 6 | 148 |
import numpy as np
N = int(input())
X_low = N // 1.08
X_high = int(X_low + 1)
if np.floor(X_low * 1.08) == N:
print(X_low)
elif np.floor(X_high * 1.08) == N:
print(X_high)
else:
print(':(')
| n=int(input())
ans=':('
for i in range(1,n+1):
if int((i*1.08)//1)==n:
ans=i
break
print(ans)
| 1 | 126,094,604,255,968 | null | 265 | 265 |
a,b = raw_input().strip().split(" ")
a = int(a)
b = int(b)
if a > b:
print "a > b"
elif a < b:
print "a < b"
else:
print "a == b" | # -*- coding: utf-8 -*-
list = map(int, raw_input().split())
a = list[0]
b = list[1]
if a < b:
print "a < b"
elif a > b:
print "a > b"
else:
print "a == b" | 1 | 356,141,494,208 | null | 38 | 38 |
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007
def solve():
n = I()
a = [input() for i in range(n)]
sp,sm = [],[]
for i in range(n):
p = 0
m = 0
for j in a[i]:
if j == "(":
p += 1
else:
p -= 1
if p < m:
m = p
if p > 0:
sp.append((m,p))
else:
sm.append((m,p))
sp.sort(reverse = True)
sm.sort(key = lambda x:x[0]-x[1])
k = 0
for m,p in sp:
if k+m < 0:
print("No")
return
k += p
for m,p in sm:
if k+m < 0:
print("No")
return
k += p
if k != 0:
print("No")
else:
print("Yes")
return
#Solve
if __name__ == "__main__":
solve()
| from collections import deque
import sys
input = sys.stdin.readline
def main():
N,X,Y = map(int,input().split())
edge = [[] for _ in range(N)]
for i in range(N):
if i == 0:
edge[i].append(i+1)
elif i == N-1:
edge[i].append(i-1)
else:
edge[i].append(i-1)
edge[i].append(i+1)
edge[X-1].append(Y-1)
edge[Y-1].append(X-1)
ans = [0]*(N-1)
for i in range(N):
visited = [0]*N
dist = [0]*N
q = deque([i])#i番目のノードを根とする探索
visited[i] = 1
while q:
now = q.popleft()
for connection in edge[now]:
if visited[connection]:
dist[connection] = min(dist[connection],dist[now]+1)
else:
visited[connection] = 1
dist[connection] = dist[now] + 1
q.append(connection)
for d in dist:
if d == 0:
continue
ans[d-1] += 1
ans = list(map(lambda x: x//2,ans))
print(*ans,sep="\n")
if __name__ == '__main__':
main() | 0 | null | 33,708,392,089,170 | 152 | 187 |
a,b=map(int,input().split())
if a>b:print('a > b')
elif a<b:print('a < b')
else:print('a == b') | a,b = map(int,input().split())
if a > b:
op = '>'
elif a < b:
op = '<'
else:
op = '=='
print("a %s b"%op)
| 1 | 363,288,755,270 | null | 38 | 38 |
import numpy as np
def solve():
dp = np.zeros((2, N+1))
# print(dp)
ac = 0
wa = 0
for i in range(M):
if (dp[0][S[i][0]] == 0):
if(S[i][1] == "WA"):
dp[1][S[i][0]] += 1
elif(S[i][1] == "AC"):
ac += 1
dp[0][S[i][0]] = 1
wa += dp[1][S[i][0]]
print(ac, int(wa))
if __name__=="__main__":
N, M = list(map(int, input().split()))
S = []
for i in range(M):
a,b = input().split()
S.append([int(a), b])
# print(S)
solve()
| N, M = map(int, input().split(' '))
ac_set = set()
wa_cnt, wa_cnt_ls = 0, [ 0 for i in range(N) ]
for i in range(M):
p, s = input().split(' ')
idx = int(p) - 1
if not idx in ac_set:
if s == 'AC':
ac_set.add(idx)
wa_cnt += wa_cnt_ls[idx]
else:
wa_cnt_ls[idx] += 1
print(len(ac_set), wa_cnt) | 1 | 93,518,473,078,522 | null | 240 | 240 |
n = int(input())
x_i = [float(i) for i in input().split()]
y_i = [float(i) for i in input().split()]
abs_sub = []
D1,D2,D3=0.0,0.0,0.0
for i in range(len(x_i)):
#p==1
D1 += ((x_i[i]-y_i[i])**2)**(1/2)
#p==2
D2 +=(x_i[i]-y_i[i])**2
#p==3
D3 +=(((x_i[i]-y_i[i])**2)**(1/2))**3
#p==inf
abs_sub.append(((x_i[i]-y_i[i])**2)**(1/2))
D2 = D2**(1/2)
D3 = D3**(1/3)
D_inf=abs_sub[0]
for i in range(len(abs_sub)):
if D_inf < abs_sub[i]:
D_inf = abs_sub[i]
print("{:.6f}\n{:.6f}\n{:.6f}\n{:.6f}".format(D1,D2,D3,D_inf))
| n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
for p in range(3):
print(sum(abs(x[i] - y[i]) ** (p+1) for i in range(n)) ** (1/(p+1)))
print(max(abs(x[i] - y[i]) for i in range(n)))
| 1 | 213,060,445,160 | null | 32 | 32 |
s = int(input())
print(s*s) | a, b, c, k = map(int, input().split())
if k - a <= 0:
print(k)
elif k - a > 0 and k - a - b <= 0:
print(a)
else:
s = k - a - b
print(a - s)
| 0 | null | 83,744,851,870,592 | 278 | 148 |
n, m = list(map(int, input().split()))
c = list(map(int, input().split()))
DP = [i for i in range(n + 1)]
for cost in c:
for i in range(cost, n + 1):
DP[i] = min(DP[i], DP[i - cost] + 1)
print(DP[n])
| n, m = map(int, input().split())
c = list(map(int, input().split()))
INF = 10**9
MAX = n + 1
dp = [INF for _ in range(MAX)]
dp[0] = 0
for i in range(m):
for j in range(len(dp)):
if j + c[i] < MAX:
dp[j+c[i]] = min(dp[j] + 1, dp[j+c[i]])
min_v = dp[-1]
for i in range(len(dp)):
idx = len(dp) - 1 - i
min_v = min(min_v, dp[idx])
dp[idx] = min_v
print(dp[n])
| 1 | 142,033,211,138 | null | 28 | 28 |
def popcount(x):
c = 0
while x > 0:
if x & 1: c += 1
x //= 2
return c
def f(x):
if x==0: return 0
return f(x % popcount(x)) + 1
n = int(input())
X = input()
po = X.count('1')
pp = po + 1
pm = max(1, po - 1)
rp = rm = 0
for x in X:
rp = (rp*2 + int(x)) % pp
rm = (rm*2 + int(x)) % pm
bp = [0]*(n) # 2^i % (po+1)
bm = [0]*(n) # 2^i % (po-1)
bp[n-1] = 1 % pp
bm[n-1] = 1 % pm
for i in range(n-1, 0, -1):
bp[i-1] = bp[i]*2 % pp
bm[i-1] = bm[i]*2 % pm
for i in range(n):
if X[i] == '0': ri = (rp + bp[i]) % pp
else:
if po-1 != 0: ri = (rm - bm[i]) % pm
else:
print(0)
continue
print(f(ri) + 1)
| import sys
sys.setrecursionlimit(10**8)
n = int(input())
x = list(input())
bit_cnt = x.count('1')
# bitを一つ増やす場合
pos = [0] * n
pos_total = 0
# bitを一つ減らす場合
neg = [0] * n
neg_total = 0
base = 1
for i in range(n):
pos[-i-1] = base%(bit_cnt+1)
if x[-i-1] == '1':
# 同時にmod(bit_cnt+1)の法でトータルを作成
pos_total = (pos_total + base) % (bit_cnt+1)
base = (base*2) % (bit_cnt+1)
base = 1
if bit_cnt == 1:
# mod取れない
pass
else:
for i in range(n):
neg[-i-1] = base%(bit_cnt-1)
if x[-i-1] == '1':
# 同時にmod(bit_cnt-1)の法でトータルを作成
neg_total = (neg_total + base) % (bit_cnt-1)
base = (base*2) % (bit_cnt-1)
def popcount(n):
s = list(bin(n)[2:])
return s.count('1')
memo = {}
memo[0] = 0
def dfs(n, depth=0):
if n in memo:
return depth + memo[n]
else:
ret = dfs(n%popcount(n), depth+1)
# memo[n] = ret
return ret
ans = []
for i in range(n):
if x[i] == '0':
st = (pos_total + pos[i]) % (bit_cnt+1)
print(dfs(st, depth=1))
elif bit_cnt == 1:
# コーナーケース:すべてのbitが0となる
print(0)
else:
st = (neg_total - neg[i]) % (bit_cnt-1)
print(dfs(st, depth=1))
| 1 | 8,198,928,980,410 | null | 107 | 107 |
import math
A, B, C, D = map(int, input().split())
if math.ceil(C/B) <= math.ceil(A/D):
print('Yes')
else:
print('No')
| from math import ceil
a, b, c, d = map(int, input().split())
x = ceil(c/b)
y = ceil(a/d)
if x <= y:
print('Yes')
else:
print('No') | 1 | 29,935,777,755,478 | null | 164 | 164 |
N = int(input())
S, T = [x for x in input().split()]
result = []
while T:
if len(S) == len(T):
result.append(S[0])
S = S[1:]
else:
result.append(T[0])
T = T[1:]
print(''.join(result))
| def solve():
N = int(input())
S, T = map(str, input().split())
ans = ""
for i in range(N): ans += S[i] + T[i]
print(ans)
if __name__ == "__main__":
solve() | 1 | 111,740,216,471,652 | null | 255 | 255 |
N, K = map(int, input().split())
P = int(1e9+7)
cnt = [0]*(K+1)
ans = 0
for i in range(K, 0, -1):
c = pow(K//i, N, P) - sum(cnt[::i])
cnt[i] = c
ans = (ans+i*c)%P
print(ans%P)
| import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N, M, L = lr()
INF = 10 ** 19
dis = [[INF for _ in range(N+1)] for _ in range(N+1)]
for _ in range(M):
a, b, c = lr()
if c > L:
continue
dis[a][b] = c
dis[b][a] = c
for k in range(N+1): # kが中継地点
for i in range(N+1):
for j in range(i+1, N+1):
x = dis[i][k] + dis[k][j]
if x < dis[i][j]:
dis[i][j] = dis[j][i] = x
supply = [[INF] * (N+1) for _ in range(N+1)]
for i in range(N+1):
for j in range(i+1, N+1):
if dis[i][j] <= L:
supply[i][j] = supply[j][i] = 1
for k in range(N+1): # kが中継地点
for i in range(N+1):
for j in range(i+1, N+1):
y = supply[i][k] + supply[k][j]
if y < supply[i][j]:
supply[i][j] = supply[j][i] = y
Q = ir()
for _ in range(Q):
s, t = lr()
if supply[s][t] == INF:
print(-1)
else:
print(supply[s][t] - 1)
# 59 | 0 | null | 105,598,864,541,280 | 176 | 295 |
n=int(input())
A=[]
for i in range(n):
for _ in range(int(input())):
x,y=map(int,input().split())
A+=[(i,x-1,y)]
a=0
for i in range(2**n):
if all(i>>j&1<1 or i>>x&1==y for j,x,y in A):
a=max(a,sum(map(int,bin(i)[2:])))
print(a) | n,k=map(int,input().split())
mod=10**9+7
ans=0
for x in range(k,n+2):
min_a=(0+x-1)*x//2
max_a=(n-x+1+n)*x//2
aa=max_a-min_a+1
ans+=aa
print(ans%mod) | 0 | null | 77,031,857,325,300 | 262 | 170 |
arr = list([])
for i in range(10):
arr.append(int(input()))
arr.sort(reverse=True)
for i in range(3):
print arr[i]
| # coding: utf-8
# Here your code !
import sys
n = [int(input()) for i in range (1,11)]
#t = [int(input()) for i in range(n)]
n.sort()
n.reverse()
for j in range (0,3):
print(n[j]) | 1 | 25,801,200 | null | 2 | 2 |
import typing
class DSU:
'''
Implement (union by size) + (path compression)
Reference:
Zvi Galil and Giuseppe F. Italiano,
Data structures and algorithms for disjoint set union problems
'''
def __init__(self, n: int = 0):
self._n = n
self.parent_or_size = [-1] * n
def merge(self, a: int, b: int) -> int:
assert 0 <= a < self._n
assert 0 <= b < self._n
x = self.leader(a)
y = self.leader(b)
if x == y:
return x
if -self.parent_or_size[x] < -self.parent_or_size[y]:
x, y = y, x
self.parent_or_size[x] += self.parent_or_size[y]
self.parent_or_size[y] = x
return x
def same(self, a: int, b: int) -> bool:
assert 0 <= a < self._n
assert 0 <= b < self._n
return self.leader(a) == self.leader(b)
def leader(self, a: int) -> int:
assert 0 <= a < self._n
if self.parent_or_size[a] < 0:
return a
self.parent_or_size[a] = self.leader(self.parent_or_size[a])
return self.parent_or_size[a]
def size(self, a: int) -> int:
assert 0 <= a < self._n
return -self.parent_or_size[self.leader(a)]
def groups(self) -> typing.List[typing.List[int]]:
leader_buf = [self.leader(i) for i in range(self._n)]
result = [[] for _ in range(self._n)]
for i in range(self._n):
result[leader_buf[i]].append(i)
return list(filter(lambda r: r, result))
n, m = map(int, input().split())
uf = DSU(n)
for _ in range(m):
a, b = map(int, input().split())
uf.merge(a - 1, b - 1)
ans = 0
for i in range(n):
ans = max(ans, uf.size(i))
print(ans)
| x=input()
x=int(x)
if x>=30:
print('Yes')
else:
print("No") | 0 | null | 4,915,891,424,060 | 84 | 95 |
import sys
input = sys.stdin.readline
############ ---- Input Functions ---- ############
def inp():
return(int(input()))
def inlt():
return(list(map(int,input().split())))
def insr():
s = input()
return(list(s[:len(s) - 1]))#might need to remove the -1
def invr():
return(map(int,input().split()))
d, t, s = invr()
if d/s<=t:
print('Yes')
else:
print('No') | a = input().split()
D = int(a[0])
T = int(a[1])
S = int(a[2])
jikan = D / S
if(jikan > T):
print("No")
else:
print("Yes") | 1 | 3,543,148,232,800 | null | 81 | 81 |
def bubbleSort(A, N):
flag = 1
i = 0
swapnum = 0
while flag:
flag = 0
for j in range(N-1, i, -1):
if A[j] < A[j-1]:
temp = A[j-1]
A[j-1] = A[j]
A[j] = temp
swapnum += 1
flag = 1
i = i + 1
return swapnum
def showlist(A):
for i in range(len(A)):
if i==len(A)-1:
print(A[i])
else:
print(A[i], end=' ')
N = eval(input())
A = list(map(int, input().split()))
swapnum = bubbleSort(A, N)
showlist(A)
print(swapnum)
|
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = [int(x)-48 for x in read().rstrip()]
ans = 0
dp = [[0]*(len(N)+1) for i in range(2)]
dp[1][0] = 1
dp[0][0] = 0
for i in range(1, len(N)+1):
dp[0][i] = min(dp[0][i-1] + N[i-1],
dp[1][i-1] + (10 - N[i-1]))
dp[1][i] = min(dp[0][i-1] + N[i-1] + 1,
dp[1][i-1] + (10 - (N[i-1] + 1)))
print(dp[0][len(N)])
| 0 | null | 35,626,525,705,770 | 14 | 219 |
import sys
sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline
def popcount(x):
x = x - ((x >> 1) & 0x5555555555555555)
x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
x = x + (x >> 8)
x = x + (x >> 16)
x = x + (x >> 32)
return x & 0x0000007f
def solve():
_ = int(rl())
X = list(map(int, rl().rstrip()))[::-1]
ones = X.count(1)
upmod = X[0] % (ones + 1)
c = 1
for xi in X[1:]:
c = c * 2 % (ones + 1)
upmod = (upmod + c * xi) % (ones + 1)
botmod = 0
if ones - 1 != 0:
botmod = X[0] % (ones - 1)
c = 1
for xi in X[1:]:
c = c * 2 % (ones - 1)
botmod = (botmod + c * xi) % (ones - 1)
ans = []
for i, xi in enumerate(X):
if ones == 1 and xi == 1:
ans.append(0)
continue
if xi == 0:
xmod = (upmod + pow(2, i, ones + 1)) % (ones + 1)
else:
xmod = (botmod - pow(2, i, ones - 1)) % (ones - 1)
cnt = 1
while xmod != 0:
xmod = xmod % popcount(xmod)
cnt += 1
ans.append(cnt)
print(*ans[::-1], sep='\n')
if __name__ == '__main__':
solve()
| def input_int():
return map(int, input().split())
def one_int():
return int(input())
def one_str():
return input()
def many_int():
return list(map(int, input().split()))
N=one_int()
S=one_str()
bit_count = S.count("1")
S_num = int(S,2)
S_min = S_num % (bit_count-1) if bit_count-1!=0 else 0
S_plu = S_num % (bit_count+1)
# calc_dict = {i:-1 for i in range(10000)}
# res_dict = {i:-1 for i in range(10**4)}
# for i in range(1, 10000):
# if calc_dict[i]==-1:
# calc_dict[i] = bin(i).count("1")
# res_dict[i] = i%calc_dict[i]+1
def mods(temp, count):
count+=1
if temp!=0:
# if temp in res_dict:
# return count+res_dict[temp]
# if temp not in calc_dict:
# calc_dict[temp]= bin(temp).count("1")
count = mods(temp%bin(temp).count("1") , count)
return count
for i in range(N):
if S[i]=="0":
part = pow(2, (N-i-1), bit_count+1)
num = (S_plu + part ) % (bit_count+1)
print(mods(num, 0))
else:
if S_num == 2**(N-i-1):
print(0)
continue
part = pow(2, (N-i-1), bit_count-1)
num = (S_min - part)%(bit_count-1)
print(mods(num, 0))
| 1 | 8,233,719,858,958 | null | 107 | 107 |
from collections import defaultdict
INF = float("inf")
N, *A = map(int, open(0).read().split())
I = defaultdict(lambda: -INF)
O = defaultdict(lambda: -INF)
O[(0, 0)] = 0
for i, a in enumerate(A, 1):
j = (i - 1) // 2
for n in [j, j + 1]:
I[(i, n)] = a + O[(i - 1, n - 1)]
O[(i, n)] = max(O[(i - 1, n)], I[(i - 1, n)])
print(max(I[(N, N // 2)], O[(N, N // 2)])) | N, K, S = map(int, input().split())
ans = [S] * K
if S != 10**9:
for i in range(N-K):
ans.append(S+1)
else:
for j in range(N-K):
ans.append(1)
print(" ".join([str(x) for x in ans])) | 0 | null | 64,372,471,435,690 | 177 | 238 |
import math
r=float(input())
print('%f %f' %(math.pi*r*r, 2*math.pi*r)) | import math
r = float(input())
s = r * r * math.pi
l = r * 2.0 * math.pi
print("{:f} {:f}".format(s, l))
| 1 | 649,343,417,628 | null | 46 | 46 |
if __name__ == "__main__":
while True:
nums = map( int, raw_input().split())
H = nums[0]
W = nums[1]
if H == 0:
if W == 0:
break
s = ""
j = 0
while j < W:
s += "#"
j += 1
i = 0
while i < H:
print s
i += 1
print | # ALDS1_11_C.py
import queue
def printNode():
for i, node in enumerate(glaph):
print(i, node)
N = int(input())
glaph = [[] for i in range(N+1)]
for i in range(1, N+1):
glaph[i] = list(map(int, input().split()))[2:]
# printNode()
step = [-1]*(N+1)
step[1] = 0
q = queue.Queue()
q.put(1)
while not q.empty():
now = q.get()
next_node = glaph[now]
# print("now is ", now, ", next is", next_node)
for i in next_node:
if step[i] != -1:
continue
q.put(i)
step[i] = step[now] + 1
for i, v in enumerate(step):
if i != 0:
print(i, v)
| 0 | null | 385,031,592,910 | 49 | 9 |
n = int(input())
a = list(map(int, input().split()))
b = a[0]
for v in a[1:]:
b ^= v
print(*map(lambda x: x ^ b, a))
| N = int(input())
aaa = [int(i) for i in input().split()]
sumxor = 0
for a in aaa:
sumxor = sumxor^a
bbb = [a^sumxor for a in aaa]
print(" ".join([str(b) for b in bbb])) | 1 | 12,540,738,375,440 | null | 123 | 123 |
def insertion_sort(seq):
print(' '.join(map(str, seq)))
for i in range(1, len(seq)):
key = seq[i]
j = i - 1
while j >= 0 and seq[j] > key:
seq[j+1] = seq[j]
j -= 1
seq[j+1] = key
print(' '.join(map(str, seq)))
return seq
n = int(input())
seq = list(map(int, input().split()))
insertion_sort(seq) | # your code goes here
N=int(input())
A=[int(i) for i in input().split()]
B=""
for k in range(N-1):
B+=str(A[k])+" "
B+=str(A[N-1])
print(B)
for i in range(1,N):
j=i-1
v=A[i]
while j>=0 and A[j]>v:
A[j+1]=A[j]
j-=1
A[j+1]=v
B=""
for k in range(N-1):
B+=str(A[k])+" "
B+=str(A[N-1])
print(B) | 1 | 5,508,378,948 | null | 10 | 10 |
n = int(input())
if n % 2 == 1:
print(0)
exit(0)
cnt = 0
five = 2 * 5
while n // five > 0:
cnt += n // five
five *= 5
print(cnt) | n = int(input())
ans = 0
if n%2 == 0:
i = 10
while i <= n:
ans += n//i
i *= 5
print(ans)
| 1 | 115,669,909,808,672 | null | 258 | 258 |
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値)
from heapq import heapify, heappop, heappush
from math import *
sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7
def mint():
return map(int,input().split())
def lint():
return list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
print(l[0] if x else l[1])
def lprint(l, sep='\n'):
for x in l:
print(x, end=sep)
N,M = mint()
C = []
for _ in range(M):
s,c = mint()
C.append([s,c])
for x in range(10**(N-1)-(N==1),10**N):
x = str(x)
if all([x[s-1]==str(c) for s,c in C]):
print(x)
exit()
print(-1) | n,r=map(int,input().split())
inn=0
if n<10:
inn=100*(10-n)
print(r+inn)
else:
print(r) | 0 | null | 62,058,474,463,220 | 208 | 211 |
n, u, v = map(int, input().split())
u -= 1
v -= 1
ab = [list(map(int, input().split())) for _ in range(n - 1)]
adj = [[] for _ in range(n)]
for a, b in ab:
a -= 1
b -= 1
adj[a].append(b)
adj[b].append(a)
def dfs(s):
d = [-1] * n
d[s] = 0
stack = [s]
while stack:
frm = stack.pop()
for to in adj[frm]:
if d[to] == -1:
d[to] = d[frm] + 1
stack.append(to)
return d
du = dfs(u)
dv = dfs(v)
ans = 0
for eu, ev in zip(du, dv):
if eu < ev:
ans = max(ans, ev - 1)
print(ans)
| S = input()
Q = int(input())
flag = True
from collections import deque
que=deque(S)
for i in range(Q):
a = input().split()
if a[0]=="1":
flag = not flag
else:
f = a[1]
c = a[2]
if f=="1":
if flag:
que.appendleft(c)
else:
que.append(c)
else:
if flag:
que.append(c)
else:
que.appendleft(c)
if not flag:
que.reverse()
print("".join(que)) | 0 | null | 87,042,293,766,020 | 259 | 204 |
n,m = map(int,input().split())
li = list(map(int,input().split()))
sum_vote = sum(li)
kijun = sum_vote / (4 * m)
sum_above = len([i for i in li if i >= kijun])
if sum_above >= m:
print("Yes")
else:
print("No")
| l,r,d = map(int,input().split())
a = r // d
b = l // d
ans = a - b
c = r % d
e = l % d
if c == 0 and e == 0:
print(ans + 1)
else:
print(ans) | 0 | null | 23,053,534,319,796 | 179 | 104 |
l = int(input())
print("{:.9f}".format((l ** 3) / 27)) | # -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_8_A
??§????????¨?°????????????\?????????
????????????????????????????°?????????¨??§???????????\????????????????????°????????????????????????????????????
"""
if __name__ == '__main__':
# ???????????????????????\???
raw_input = input()
# ??§??????????°????????????\??????????????????
print(raw_input.swapcase()) | 0 | null | 24,364,310,013,970 | 191 | 61 |
n, u, v = map(int, input().split())
u -= 1
v -= 1
g = [[] for _ in range(n)]
for i in range(n-1):
a, b = map(int, input().split())
a, b = a-1, b-1
g[a].append(b)
g[b].append(a)
from collections import deque
q = deque()
q.append(u)
t = [-1]*n
t[u] = 0
while q:
x = q.popleft()
for new_x in g[x]:
if t[new_x] == -1:
t[new_x] = t[x]+1
q.append(new_x)
q = deque()
q.append(v)
a = [-1]*n
a[v] = 0
while q:
x = q.popleft()
for new_x in g[x]:
if a[new_x] == -1:
a[new_x] = a[x]+1
q.append(new_x)
max_ = 0
for i in range(n):
if t[i] < a[i]:
max_ = max(max_, a[i])
print(max_-1) | import sys
import math
import itertools
import collections
sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()
def main():
N = NI()
xy = [NLI() for _ in range(N)]
ls = [p for p in range(N)]
p_list = list(itertools.permutations(ls))
full_course = ["" for _ in range(len(p_list))]
for k in range(len(p_list)):
distance = 0
for l in range(N-1):
departure = p_list[k][l]
goal = p_list[k][l+1]
Xd = xy[departure][0]
Yd = xy[departure][1]
Xg = xy[goal][0]
Yg = xy[goal][1]
distance += ((Xd-Xg)**2 + (Yd-Yg)**2)**(1/2)
full_course[k] = distance
print(sum(full_course)/len(p_list))
if __name__ == '__main__':
main() | 0 | null | 132,984,151,169,946 | 259 | 280 |
# import numpy as np
import itertools
if __name__ == "__main__":
N,K = map(int,input().split())
P = [ int(p)-1 for p in input().split() ]
C = list(map(int,input().split()))
# print(P)
# 一度計算したサイクル情報をキャッシュしておくための配列
# cycleIDs = np.full( N, -1, np.int64 )
cycleIDs = [ -1 for _ in range(N)]
cycleInfs = []
cycleID = 0
procCnt = 0
for n in range(N):
v = n
if cycleIDs[v] != -1:
continue
else:
currentCycleCosts = []
while True:
# 全頂点について、属するサイクルを計算する
currentCycleCosts.append( C[v] )
cycleIDs[v] = cycleID
v = P[v]
if cycleIDs[v] != -1:
# サイクル終了
# ループを含めない最大の処理回数
procCnt = K % len( currentCycleCosts )
# それで足りてるのかわからないが、Last2周分は、ループ合計がプラスでも必ずしもループするとは限らない
# その部分は、ちゃんと計算する
# -------------------------------------------------
# 4 101
# 2 3 4 1
# 50 -49 -50 50
# 上記のようなパターンの場合、
# 最大25回ループ + 1回処理可能だが、その場合、25 + 50 = 75
# 24回ループ + 2回処理でやめると、124になる
# 無条件でループする回数は、ループ可能な最大の回数-1らしい
# -------------------------------------------------
# 割り切れて、尚且つサイクル合計がマイナスのパターンで、最低1個は処理するのにもここで対応
if len( currentCycleCosts ) + procCnt <= K:
procCnt += len( currentCycleCosts )
cycleInfs.append( ( procCnt, len(currentCycleCosts), currentCycleCosts * 3 ) )
cycleID += 1
break
# scores = []
# procCnt = 0
ans = -10 ** 9
for procCnt, currentCycleSize, currentCycleCosts in cycleInfs:
# サイクル内でループしてスコアを稼ぐ場合の考慮
loopScore = 0
if sum(currentCycleCosts) > 0:
cycleLoopCnt = ( K - procCnt ) // currentCycleSize
loopScore = cycleLoopCnt * sum(currentCycleCosts[:currentCycleSize])
# print("loopScore",loopScore,procCnt)
# このサイクルに属する全頂点分をまとめて計算する
for i in range(currentCycleSize):
# print(np.roll( currentCycleCosts, i ).cumsum()[:procCnt])
score = max( itertools.accumulate( currentCycleCosts[i:i+procCnt] ) )
if ans < score + loopScore:
ans = score + loopScore
# ans = max( ans, score + loopScore )
print(ans)
# print(max(scores))
| import sys
read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7
def main():
H, W, M = map(int, readline().split())
row = [0] * H
column = [0] * W
grid = set()
for _ in range(M):
h, w = map(int, readline().split())
row[h-1] += 1
column[w-1] += 1
grid.add((h-1,w-1))
max_row = max(row)
max_column = max(column)
idx_row = [i for i,x in enumerate(row) if x == max_row]
idx_column = [i for i,x in enumerate(column) if x == max_column]
ans = max_row+max_column
flag = False
for h in idx_row:
for w in idx_column:
if not (h,w) in grid:
flag = True
break
if flag:
print(ans)
else:
print(ans-1)
if __name__ == '__main__':
main()
| 0 | null | 5,056,875,210,432 | 93 | 89 |
class Solution(object):
def is_hitachi_string(self, string):
if len(string) == 0:
print 'No'
return
hi_str = 'hi'
hi_idx = 0
for idx in xrange(len(string)):
if idx > 9:
print 'No'
return
if string[idx] != hi_str[hi_idx]:
print 'No'
return
hi_idx = (hi_idx + 1) % 2
if hi_idx == 0:
print 'Yes'
else:
print 'No'
if __name__ == '__main__':
sol = Solution()
string = raw_input()
sol.is_hitachi_string(string) | s = input()
flg = True
while len(s) > 0:
if s.startswith("hi"):
s = s[2::]
else:
flg = False
break
if flg:
print("Yes")
else:
print("No") | 1 | 53,188,983,904,196 | null | 199 | 199 |
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy
sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip() # ignore trailing spaces
h, w = na()
m = []
m = [ns() for _ in range(h)]
dp = [[inf] * w for _ in range(h)]
dp[0][0] = int(m[0][0] == '#')
for x in range(1, w):
dp[0][x] = dp[0][x-1] + (int(m[0][x]=="#") if m[0][x-1]=="." else 0)
for y in range(1, h):
dp[y][0] = dp[y-1][0] + (int(m[y][0]=="#") if m[y-1][0]=="." else 0)
for x in range(1, w):
dp[y][x] = min(
dp[y][x-1] + (int(m[y][x]=="#") if m[y][x-1]=="." else 0),
dp[y-1][x] + (int(m[y][x]=="#") if m[y-1][x]=="." else 0)
)
print(dp[-1][-1]) | H,W=map(int,input().split())
s=[]
dp=[[10**9]*W for _ in range(H)]
dp[0][0]=0
for _ in range(H):
s.append(list(input()))
for i in range(H):
for j in range(W):
if j!=W-1:
if s[i][j]=="." and s[i][j+1]=="#":
dp[i][j+1]=min(dp[i][j]+1,dp[i][j+1])
else:
dp[i][j+1]=min(dp[i][j],dp[i][j+1])
if i!=H-1:
if s[i][j]=="." and s[i+1][j]=="#":
dp[i+1][j]=min(dp[i][j]+1,dp[i+1][j])
else:
dp[i+1][j]=min(dp[i][j],dp[i+1][j])
ans=dp[H-1][W-1]
if s[0][0]=="#":
ans+=1
print(ans) | 1 | 49,388,620,649,458 | null | 194 | 194 |
n = int(input())
ans = "No"
count = 0
for i in range(n):
D1,D2 = map(int,input().split())
count=count+1 if D1==D2 else 0
ans="Yes" if count>=3 else ans
print(ans) | def main():
S = input()
if "7" in S:
print("Yes")
else:
print("No")
if __name__ == '__main__':
main()
| 0 | null | 18,348,333,700,700 | 72 | 172 |
# coding: utf-8
import sys
from operator import itemgetter
sysread = sys.stdin.readline
read = sys.stdin.read
from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import combinations, product
#import bisect# lower_bound etc
#import numpy as np
#import queue# queue,get(), queue.put()
def run():
N = int(input())
current = 0
ways = []
dic = {'(': 1, ')': -1}
SS = read().split()
for S in SS:
path = [0]
for s in S:
path.append(path[-1]+ dic[s])
ways.append((path[-1], min(path)))
ways_pos = sorted([(a,b) for a,b in ways if a >= 0], key = lambda x:x[0], reverse=True)
ways_neg = sorted([(a,b) for a,b in ways if a < 0], key = lambda x:(x[0] - x[1]), reverse=True)
tmp = []
for go, max_depth in ways_pos:
if current + max_depth >= 0:
current += go
else:
tmp.append((go, max_depth))
for go, max_depth in tmp:
if current + max_depth >= 0:
current += go
else:
print('No')
return None
tmp =[]
for go, max_depth in ways_neg:
if current + max_depth >= 0:
current += go
else:
tmp.append((go, max_depth))
for go, max_depth in tmp:
if current + max_depth >= 0:
current += go
else:
print('No')
return None
if current == 0:
print('Yes')
else:
print('No')
if __name__ == "__main__":
run() | l=map(int,raw_input().split())
a=l[0]
b=l[1]
c=l[2]
if a<b<c:
print 'Yes'
else:
print 'No' | 0 | null | 12,032,627,641,342 | 152 | 39 |
# print(max([len(v) for v in input().split('S')]))
d = {
'RRR': 3,
'RRS': 2,
'RSR': 1,
'RSS': 1,
'SRR': 2,
'SRS': 1,
'SSR': 1,
'SSS': 0,
}
print(d[input()])
| a=input()
if(a=="RSS")|(a=="SRS")|(a=="SSR")|(a=="RSR"):
print(1)
elif(a=="SRR")|(a=="RRS"):
print(2)
elif(a=="RRR"):
print(3)
else:
print(0) | 1 | 4,921,911,734,050 | null | 90 | 90 |
import sys
l = []
for i in sys.stdin:
l.append(i.split())
taro = 0
hanako = 0
for i in range(1,len(l)):
if l[i][1] > l[i][0]:
hanako += 3
elif l[i][0] > l[i][1]:
taro += 3
else:
hanako += 1
taro += 1
print(taro,hanako)
| def main():
k = int(input())
for _ in range(k):
print("ACL",end='')
print()
if __name__ == "__main__":
main() | 0 | null | 2,055,485,017,962 | 67 | 69 |
if __name__ == "__main__":
while True:
nums = map( int, raw_input().split())
H = nums[0]
W = nums[1]
if H == 0:
if W == 0:
break
s = ""
j = 0
while j < W:
s += "#"
j += 1
i = 0
while i < H:
print s
i += 1
print | while True:
H,W = (int(x) for x in input().split())
if H == 0 and W == 0:
break
i = 0
while i < H:
j = 0
while j < W:
print ("#", end='')
j += 1
print ('')
i += 1
print ('')
| 1 | 781,986,885,280 | null | 49 | 49 |
def merge(A, left, mid, right):
inf = float('inf')
L = A[left:mid]+[inf]
R = A[mid:right] + [inf]
i = j = 0
for k in range(left,right):
if L[i] <= R[j]:
A[k] = L[i]
i += 1
else:
A[k] = R[j]
j += 1
return right - left
def mergeSort(A, left, right, count = 0):
if left+1 < right:
mid = (left + right)//2
count = mergeSort(A, left, mid, count)
count = mergeSort(A, mid, right, count)
count += merge(A, left, mid, right)
return count
n = int(input())
A = list(map(int, input().split()))
ans = mergeSort(A, 0, n)
s = list(map(str, A))
print(' '.join(s))
print(ans)
| [print('{}x{}={}'.format(i, j, i * j)) for i in range(1, 10) for j in range(1, 10)] | 0 | null | 58,320,850,940 | 26 | 1 |
import sys
from collections import deque
input = sys.stdin.readline
def bfs(S, sh, sw, dist):
dist[sh][sw] = 0
queue = deque([(sh, sw)])
while queue:
h, w = queue.popleft()
for i, j in ((0, 1), (0, -1), (1, 0), (-1, 0)):
y, x = h + i, w + j
if S[y][x] == "#":
continue
if dist[y][x] == -1:
dist[y][x] = dist[h][w] + 1
queue.append((y, x))
def main():
H, W = map(int, input().split())
S = [None] * (H + 2)
S[0] = S[-1] = "#" * (W + 2)
for i in range(1, H + 1):
S[i] = "".join(["#", input().rstrip(), "#"])
ans = 0
for sh in range(1, H + 1):
for sw in range(1, W + 1):
if S[sh][sw] == "#":
continue
dist = [[-1] * (W + 2) for _ in range(H + 2)]
bfs(S, sh, sw, dist)
max_dist = max(map(max, dist))
ans = max(ans, max_dist)
print(ans)
if __name__ == "__main__":
main()
| #!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**7)
import bisect
import heapq
import itertools
import math
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from math import gcd
from operator import add, itemgetter, mul, xor
def cmb(n,r,mod):
bunshi=1
bunbo=1
for i in range(r):
bunbo = bunbo*(i+1)%mod
bunshi = bunshi*(n-i)%mod
return (bunshi*pow(bunbo,mod-2,mod))%mod
mod = 10**9+7
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]
#bisect.bisect_left(list,key)はlistのなかでkey未満の数字がいくつあるかを返す
#つまりlist[i] < x となる i の個数
#bisect.bisect_right(list, key)はlistのなかでkey以下の数字がいくつあるかを返す
#つまりlist[i] <= x となる i の個数
#これを応用することで
#len(list) - bisect.bisect_left(list,key)はlistのなかでkey以上の数字がいくつあるかを返す
#len(list) - bisect.bisect_right(list,key)はlistのなかでkeyより大きい数字がいくつあるかを返す
#これらを使うときはあらかじめlistをソートしておくこと!
def maze_solve(S_1,S_2,maze_list):
d = deque()
d.append([S_1,S_2])
dx = [0,0,1,-1]
dy = [1,-1,0,0]
while d:
v = d.popleft()
x = v[0]
y = v[1]
for i in range(4):
nx = x + dx[i]
ny = y + dy[i]
if nx < 0 or nx >= h or ny < 0 or ny >= w:
continue
if dist[nx][ny] == -1:
dist[nx][ny] = dist[x][y] + 1
d.append([nx,ny])
return max(list(map(lambda x: max(x), dist)))
h,w = MI()
if h==1 and w == 2:
print(1)
elif h == 2 and w == 1:
print(1)
else:
ans = 0
maze = [list(input()) for _ in range(h)]
dist = [[-1]*w for _ in range(h)]
start_list = []
for i in range(h):
for j in range(w):
if maze[i][j] == "#":
dist[i][j] = 0
else:
start_list.append([i,j])
dist_copy = deepcopy(dist)
for k in start_list:
dist = deepcopy(dist_copy)
ans = max(ans,maze_solve(k[0],k[1],maze))
print(ans+1) | 1 | 94,683,801,091,212 | null | 241 | 241 |
lis=[]
for i in range(10):
h=int(input())
lis.append(h)
for i in range(10):
for j in range(i+1,10):
if lis[i]<lis[j]:
a=lis[i]
lis[i]=lis[j]
lis[j]=a
for i in range(3):
print(lis[i]) | import sys
import math
from enum import Enum
while True:
n=int(input())
if n==0:
break
s=list(map(int,input().split()))
sum1=0
for i in range(len(s)):
sum1+=s[i]
a=sum1/len(s)
sum2=0
for i in range(len(s)):
sum2+=s[i]*s[i]
b=sum2/len(s)
print("%.10f"%(math.sqrt(b-a*a)))
| 0 | null | 94,635,525,280 | 2 | 31 |
# coding: utf-8
import sys
from collections import deque
readline = sys.stdin.readline
sr = lambda: readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
# 左からgreedyに
N, D, A = lr()
monsters = []
for _ in range(N):
x, h = lr()
monsters.append((x, h))
monsters.sort()
bomb = deque()
answer = 0
attack = 0
for x, h in monsters:
while bomb:
if bomb[0][0] + D < x:
attack -= bomb[0][1]
bomb.popleft()
else:
break
h -= attack
if h > 0:
t = -(-h//A)
answer += t
bomb.append((x + D, A * t))
attack += A * t
print(answer)
| #silver fox
n,d,a=map(int,input().split())
from collections import deque
import math
data=[]
for i in range(n):
x,h=map(int,input().split())
data.append((x,h))
data=sorted(data,key=lambda x:x[0])
#data を位置の順番にソートしておく
add=0
damage_sum=0
damage_map=deque([])
for i in range(n):
if damage_map:
while damage_map and damage_map[0][0]<data[i][0]:
k=damage_map.popleft()
damage_sum-=k[1]
if damage_sum<data[i][1]:
p=math.ceil((data[i][1]-damage_sum)/a)
damage_sum+=p*a
add+=p
#少なくともp回の攻撃を加えなくてはならない
damage_map.append((data[i][0]+2*d,p*a))
#data[i][0]+2*dのところまではp*aのダメージがプラスとして加算される
print(add) | 1 | 82,316,694,991,972 | null | 230 | 230 |
s = [0] * 13
h = [0] * 13
c = [0] * 13
d = [0] * 13
num = int(input())
for i in range(num):
m, n = input().split()
x = int(n) - 1
if m == "S":
s[x] = 1
elif m == "H":
h[x] = 1
elif m == "C":
c[x] = 1
elif m == "D":
d[x] = 1
else:
break
for i in range(13):
if s[i] == 0:
print("S %d" % (i+1))
for i in range(13):
if h[i] == 0:
print("H %d" % (i+1))
for i in range(13):
if c[i] == 0:
print("C %d" % (i+1))
for i in range(13):
if d[i] == 0:
print("D %d" % (i+1))
| n = int(input())
deck = []
for i in range(n):
mark, num = input().split()
deck.append((mark, int(num)))
for mark, num in [(mark, num) for mark in 'SHCD' for num in range(1,14) if (mark, num) not in deck]:
print(mark, num) | 1 | 1,038,277,735,362 | null | 54 | 54 |
import copy
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
count = 0
for i in range(len(a)-1):
count += a[(i+1)//2]
print(count) | #!/usr/bin/python3
# -*- coding:utf-8 -*-
def main():
n = int(input())
la = list(map(int, input().strip().split()))
la.sort(reverse=True)
ans = sum(la[:(n+1)//2]) * 2 - la[0] - (la[(n+1)//2-1] if n%2==1 else 0)
print(ans)
if __name__=='__main__':
main()
| 1 | 9,182,639,701,508 | null | 111 | 111 |
n = int(input())
str_list = list(map(list,input().split(' ')))
ans_list = []
for i in range(n):
ans_list.append(str_list[0][i])
ans_list.append(str_list[1][i])
ans_str = ''.join(ans_list)
print(ans_str)
| a = int(input())
b = input().split()
c = []
for i in range(a * 2):
if i % 2 == 0:
c.append(b[0][i // 2])
else:
c.append(b[1][(i - 1) // 2])
for f in c:
print(f,end="") | 1 | 112,315,428,859,228 | null | 255 | 255 |
n = int(input())
A = [int(i) for i in input().split()]
product = 1
A.sort()
for i in range(n):
product *= A[i]
if(product > 10**18):
print("-1")
break
if(product <= 10**18):
print(product) | def resolve():
n = int(input())
ans = 0
for i in range(1,n+1):
if i%3!=0 and i%5!=0:
ans += i
print(ans)
resolve() | 0 | null | 25,660,725,998,840 | 134 | 173 |
from collections import defaultdict
N,P=map(int,input().split())
S=input()
if P==2 or P==5:
ans=0
for i in range(N):
if int(S[i])%P==0:
ans+=i+1
print(ans)
else:
d=defaultdict(int)
a=0
for i in range(N):
a+=int(S[N-i-1])*pow(10,i,P)
a%=P
d[a]+=1
ans=d[0]
for v in d.values():
ans+=v*(v-1)//2
print(ans)
| def sol(s, p):
n = len(s)
cnt = 0
if p == 2 or p == 5:
for i in range(n):
if (s[i] % p == 0):
cnt += i + 1
else:
pre = [0] * (n+2)
pre[n+1] = 0
b = 1
for i in range(n, 0, -1):
pre[i] = (pre[i+1] + s[i-1] * b) % p
b = (b * 10) % p
rec = [0] * p
rec[0] = 1
for i in range(n, 0, -1):
cnt += rec[pre[i]]
rec[pre[i]] += 1
return cnt
if __name__ == "__main__":
n, p = map(int, input().split())
s = input()
print (sol([int(i) for i in s], p)) | 1 | 57,925,476,178,880 | null | 205 | 205 |
#!/usr/bin/env python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]
def inside(y, x, H, W):
return 0 <= y < H and 0 <= x < W
def ceil(a, b):
return (a + b - 1) // b
def sum_of_arithmetic_progression(s, d, n):
return n * (2 * s + (n - 1) * d) // 2
def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b)
def lcm(a, b):
g = gcd(a, b)
return a / g * b
def ok(t, s):
N = len(t)
for i in range(N):
if t[i]:
for x, y in s[i]:
if y == 1:
if not t[x]:
return False
elif y == 0:
if t[x]:
return False
return True
def solve():
N = int(input())
s = defaultdict(list)
for i in range(N):
A = int(input())
for _ in range(A):
X, Y = map(int, input().split())
X -= 1
s[i].append((X, Y))
ans = 0
for b in range(2 ** N):
t = [0] * N
num = 0
for i in range(N):
if (b >> i) & 1:
t[i] = 1
num += 1
if ok(t, s):
ans = max(ans, num)
print(ans)
def main():
solve()
if __name__ == '__main__':
main()
| 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,550,864,192,982 | null | 262 | 262 |
N = int(input())
S,T = input().split()
print(''.join([X+Y for (X,Y) in zip(S,T)])) | n=int(input())
a,b=list(input().split())
ans=[]
for i in range(2*n):
if i%2==0:
ans.append(a[i//2])
else:
ans.append(b[i//2])
ansl=""
for i in ans:
ansl+=i
print(ansl) | 1 | 111,981,380,817,470 | null | 255 | 255 |
n,k = map(int,input().split())
li = list(map(int,input().split()))
if n==k:
ans = 0
for i in li:
ans += i*0.5+0.5
print(ans)
exit()
K = sum(li[:k])
ans = K
t = 0
for i in range(n-k):
K += li[i+k] - li[i]
if K > ans:
ans = K
t = i
ans = 0
for i in range(k):
ans += li[t+i+1]*0.5 + 0.5
print(ans) | import sys
N,M=map(int,input().split())
slist=list(map(int,input()))
seq=0
for s in slist:
if s==0:
seq=0
else:
seq+=1
if seq==M:
print(-1)
sys.exit(0)
class SegTree:
#init(init_val, ide_ele): 配列init_valで初期化 O(N)
def __init__(self, init_val, segfunc, ide_ele):
#init_val: 配列の初期値
#segfunc: 区間にしたい操作
#ide_ele: 単位元
#n: 要素数
#num: n以上の最小の2のべき乗
#tree: セグメント木(1-index)
n = len(init_val)
self.segfunc = segfunc
self.ide_ele = ide_ele
self.num = 1 << (n - 1).bit_length()
self.tree = [ide_ele] * 2 * self.num
# 配列の値を葉にセット
for i in range(n):
self.tree[self.num + i] = init_val[i]
# 構築していく
for i in range(self.num - 1, 0, -1):
self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])
#update(k, x): k番目の値をxに更新 O(logN)
def update(self, k, x):
#k番目の値をxに更新
#k: index(0-index)
#x: update value
k += self.num
self.tree[k] = x
while k > 1:
self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
k >>= 1
#query(l, r): 区間[l, r)をsegfuncしたものを返す O(logN)
def query(self, l, r):
#[l, r)のsegfuncしたものを得る
#l: index(0-index)
#r: index(0-index)
res = self.ide_ele
l += self.num
r += self.num
while l < r:
if l & 1:
res = self.segfunc(res, self.tree[l])
l += 1
if r & 1:
res = self.segfunc(res, self.tree[r - 1])
l >>= 1
r >>= 1
return res
#segfunc
def segfunc(x,y):
return min(x,y) #最小値
#ide_ele
ide_ele=float("inf") #最小値
#init
seg=SegTree([float("inf")]*(N+1), segfunc, ide_ele)
dist_list=[float("inf")]*(N+1)
seg.update(N,0)
dist_list[N]=0
for i in reversed(range(N)):
if slist[i]==0:
left=i+1
right=min(i+M,N)
dist=seg.query(left,right+1)+1
seg.update(i,dist)
dist_list[i]=dist
answer_list=[]
i=0
while i<N:
for j in range(1,M+1):
if dist_list[i]>dist_list[i+j]:
answer_list.append(j)
i+=j
break
print(*answer_list) | 0 | null | 106,811,724,169,358 | 223 | 274 |
# coding: utf-8
# Your code here!
n,k=map(int,input().split())
a=list(map(int,input().split()))
cnt=a[k-1]
for i in range(n-k):
if a[i]<a[i+k]:
print('Yes')
else:
print('No')
| N,K = map(int,input().split())
A = list(map(int,input().split()))
for i in range(K,N):
if A[i] > A[i-K]:
print("Yes")
else:
print("No") | 1 | 7,034,722,829,248 | null | 102 | 102 |
n,k=map(int,input().split())
p=list(map(int,input().split()))
c=list(map(int,input().split()))
ans=[]
for i in range(n):
ct=0
score=0
s=[]
pos=i
while ct<k:
ct+=1
pos=p[pos]-1
score+=c[pos]
s.append(score)
if pos==i:
break
if s[-1]<0:
ans.append(max(s))
elif pos!=i:
ans.append(max(s))
elif k%len(s)==0:
ans.append(s[-1]*(k//len(s)-1)+max(s))
else:
ans.append(max(s[-1]*(k//len(s)-1)+max(s),s[-1]*(k//len(s))+max(s[0:k%len(s)])))
print(max(ans)) | def gcd(a, b):
# ?????§??¬?´???°
while b > 0:
a, b = b, a % b
return a
a, b = map(int, input().split())
print(gcd(a, b)) | 0 | null | 2,696,259,398,624 | 93 | 11 |
x,y,k=map(int,input().split())
if(k<=x):
x=x-k
k=0
else:
k-=x
x=0
if(k<=y):
y-=k
k=0
else:
k-=y
y=0
print(x,y)
| import bisect,collections,copy,heapq,itertools,math,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
a, b, k = M()
if k >= a:
k -= a
a = 0
else:
a -= k
k = 0
if k >= b:
b = 0
else:
b -= k
print(a, b) | 1 | 104,539,180,601,132 | null | 249 | 249 |
# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
from collections import deque
# from decorator import stop_watch
#
#
# @stop_watch
def solve(H, W, Ss):
Ss = ['#' + S + '#' for S in Ss]
Ss = ['#' * (W + 2)] + Ss + ['#' * (W + 2)]
# for S in Ss:
# print(S)
ans = 0
for i in range(1, H + 1):
for j in range(1, W + 1):
if Ss[i][j] == '#':
continue
visited = [[-1] * (W + 2) for _ in range(H + 2)]
now = 0
visited[i][j] = now
q = deque([(i, j, now)])
while q:
x, y, n = q.popleft()
# for v in visited:
# print(v)
# input()
if Ss[x + 1][y] == '.' \
and visited[x + 1][y] < 0:
q.append((x + 1, y, n + 1))
visited[x + 1][y] = n + 1
if Ss[x - 1][y] == '.' \
and visited[x - 1][y] < 0:
q.append((x - 1, y, n + 1))
visited[x - 1][y] = n + 1
if Ss[x][y + 1] == '.' \
and visited[x][y + 1] < 0:
q.append((x, y + 1, n + 1))
visited[x][y + 1] = n + 1
if Ss[x][y - 1] == '.' \
and visited[x][y - 1] < 0:
q.append((x, y - 1, n + 1))
visited[x][y - 1] = n + 1
ans = max(ans, max([max(v) for v in visited]))
print(ans)
if __name__ == '__main__':
H, W = map(int, input().split())
Ss = [input() for _ in range(H)]
solve(H, W, Ss)
| def solve():
N, K = map(int, input().split())
mod = 10**9+7
ans = 0
for k in range(K,N+2):
ans += (N+N-k+1)*k//2-k*(k-1)//2+1
ans %= mod
return ans
print(solve()) | 0 | null | 63,947,491,700,324 | 241 | 170 |
n = int(input())
A = list(map(int,input().split()))
dp = [[[0,0,0] for i in range(2)] for i in range(n+1)]
for i in range(1,n+1):
if i%2 == 1:
if i > 1:
dp[i][0][1] = dp[i-1][1][0]+A[i-1]
dp[i][0][2] = dp[i-1][1][1]+A[i-1]
dp[i][1][0] = max(dp[i-1][0][0],dp[i-1][1][0])
dp[i][1][1] = max(dp[i-1][0][1],dp[i-1][1][1])
else:
dp[i][0][2] = A[0]
else:
dp[i][0][0] = dp[i-1][1][0]+A[i-1]
dp[i][0][1] = dp[i-1][1][1]+A[i-1]
dp[i][1][0] = max(dp[i-1][0][1],dp[i-1][1][1])
dp[i][1][1] = dp[i-1][0][2]
if n%2 == 0:
print(max(dp[n][0][1],dp[n][1][1]))
else:
print(max(dp[n][0][1],dp[n][1][1])) | n = int(input())
a = list(map(int, input().split()))
iseven=(n%2==0)
if n==2:
print(max(a))
exit()
dp = [[-float("inf") for _ in range(3)] for _ in range(n)]
dp[0][0]=a[0]
dp[1][1]=a[1]
if n>2:
dp[2][2]=a[2]
for i in range(n):
for k in range(3):
if i+2<n:
dp[i+2][k] = max(dp[i+2][k], dp[i][k] + a[i+2])
if k<=1 and i+3<n:
dp[i+3][k+1] = max(dp[i+3][k+1], dp[i][k] + a[i+3])
if not iseven and k==0 and i+4<n:
dp[i+4][k+2] = max(dp[i+4][k+2], dp[i][k] + a[i+4])
if iseven:
ans=max([dp[-1][0],dp[-1][1]])
else:
ans=max([dp[-3][0],dp[-2][1],dp[-1][2]])
print(ans) | 1 | 37,339,464,036,898 | null | 177 | 177 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.