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
|
---|---|---|---|---|---|---|
from __future__ import print_function
import sys
officalhouse = [0]*4*3*10
n = int( sys.stdin.readline() )
for i in range( n ):
b, f, r, v = [ int( val ) for val in sys.stdin.readline().split( " " ) ]
bfr = (b-1)*30+(f-1)*10+(r-1)
officalhouse[bfr] = officalhouse[bfr] + v;
output = []
for b in range( 4 ):
for f in range( 3 ):
for r in range( 10 ):
output.append( " {:d}".format( officalhouse[ b*30 + f*10 + r ] ) )
output.append( "\n" )
if b < 3:
output.append( "####################\n" )
print( "".join( output ), end="" ) | #from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from math import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
import heapq
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
INF = float('inf')
from sys import stdin
readline = stdin.readline
def readInts():
return list(map(int,readline().split()))
def readTuples():
return tuple(map(int,readline().split()))
def I():
return int(readline())
class UnionFind:
def __init__(self,n): # 頂点数 親ならばその集合に∉頂点数に-1をかけたもの
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 unite(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)]
n,m = readInts()
uni = UnionFind(n)
for i in range(m):
a,b = map(lambda x:int(x)-1, input().split())
uni.unite(a,b)
ans = -1
for i in range(n):
ans = max(ans, uni.size(i)) # 一番大きいサイズを全部分割する必要があるため
print(ans)
| 0 | null | 2,516,438,008,058 | 55 | 84 |
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7
# 個数制限なしナップサック問題
W,N = map(int,readline().split())
dp = [INF]*(W+1)
dp[0] = 0
for i in range(N):
w,v = map(int,readline().split())
# dp[j] = 重さj以下でつくれる最大の価値
for j in range(W+1):
dp[j] = min(dp[j],dp[max(j-w,0)] + v)
print(dp[W])
| import sys
def gcd(inta, intb):
large = max(inta, intb)
small = min(inta,intb)
mod = large % small
if mod ==0:
return small
else:
return gcd(small, mod)
def lcm(inta, intb, intgcd):
return (inta * intb // intgcd)
sets = sys.stdin.readlines()
for line in sets:
a, b = map(int, line.split())
c = gcd(a, b)
print(c, lcm(a, b, c)) | 0 | null | 40,814,587,860,660 | 229 | 5 |
import sys
sys.setrecursionlimit(10**6)
n = int(input())
graph = []
chart = [[int(i)] for i in range(1,n+1)]
for i in range(n):
z = [c-1 for c in list(map(int,input().split()))][2:]
graph.append(z)
time = 0
def dfs(nod):
global graph
global time
#break condition
if len(chart[nod]) != 1:
return
#end condition not necessary
#if not graph[nod]:
# time += 1
# chart[nod].append(time)
# return
# command
time += 1
chart[nod].append(time)
# move
for dis in graph[nod]:
dfs(dis)
# post-command
time += 1
chart[nod].append(time)
for i in range(n):
dfs(i)
for i in range(n):
print(*chart[i])
| order=[]
for number in range(10):
hight=int(input())
order.append(hight)
for j in range(9):
for i in range(9):
if order[i] < order[i+1]:
a = order[i]
b = order[i+1]
order[i] = b
order[i+1] = a
for i in range(3):
print(order[i]) | 0 | null | 1,601,022,938 | 8 | 2 |
n = int(input())
import math
for i in range (50000):
x = i*1.08
if math.floor(x) == n:
print(i)
exit()
print(":(") | import math
N = int(input())
X = N/1.08
Y = math.ceil(X)
Z = math.floor(Y*1.08)
if N == Z:
print(Y)
else:
print(':(') | 1 | 125,643,418,064,010 | null | 265 | 265 |
from math import ceil
N, X, T = [int(s) for s in input().split()]
print(ceil(N/X) * T) | import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7
def resolve():
n, t = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(n)]
AB.sort()
res = 0
dp = [[0] * (t + 1) for _ in range(n + 1)]
for i in range(1, n + 1):
a, b = AB[i - 1]
for j in range(1, t + 1):
if j - a >= 0:
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - a] + b)
else:
dp[i][j] = dp[i - 1][j]
for k in range(i, n):
_, b = AB[k]
res = max(res, dp[i][j - 1] + b)
print(res)
if __name__ == '__main__':
resolve()
| 0 | null | 77,937,571,509,170 | 86 | 282 |
h, n = map(int, input().split())
aa = [int(a) for a in input().split()]
all = sum(aa)
if h <= all :
print("Yes")
else :
print("No") | N = int(input())
alph = ['z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',\
'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',\
'x', 'y']
seq = []
while N > 0:
s = N % 26
N = (N - 1) // 26
seq.append(s)
L = len(seq)
name = ''
for i in range(L):
name = alph[seq[i]] + name
print(name) | 0 | null | 44,981,695,963,370 | 226 | 121 |
stack = []
res = []
area = input()
for i, terrain in enumerate(area):
if terrain == '\\':
stack.append(i)
elif terrain == '/' and len(stack)>0:
left = stack.pop()
pond = i - left
if len(res) == 0 or left >= res[-1][0]:
res.append([left,pond])
else:
while len(res) > 0 and left < res[-1][0] :
pond += res[-1][1]
res.pop()
res.append([left,pond])
total = 0
ponds = []
for i in res:
ponds.append(i[1])
total += i[1]
ans = [len(res)]
ans += ponds
ans_new = " ".join(map(str,ans))
print(total)
print(ans_new)
| f = list(input())
s = []
for i, v in enumerate(f):
if v == '\\':
s.append([v, i])
elif v == '/' and len(s) > 0:
n = s.pop()
if n[0] == '\\':
t = i-n[1]
s.append(['.', t])
elif len(s) > 0:
j = len(s)-1
n1 = n[1]
while j >= 0 and s[j][0] == '.':
#print(n1, s[j][1])
n1 += s[j][1]
j -= 1
if j >= 0:
m = s[j]
# print(m)
n1 += i-m[1]
s = s[:j]
s.append(['.', n1])
else:
# print("err")
s.append(n)
else:
s.append(n)
#print(v, s, i)
a = [v[1] for v in s if v[0] == '.']
print(sum(a))
a.insert(0, len(a))
print(" ".join([str(v) for v in a]))
| 1 | 59,759,342,710 | null | 21 | 21 |
n = int(input())
lis = list(map(int,input().split()))
num = [0 for i in range(n)]
ans = 1
for nu in lis:
if nu == 0:
ans *= (3-num[0])
else:
ans *= (num[nu-1]-num[nu])
ans %= 10 ** 9 + 7
num[nu] += 1
print(ans) | # coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
from heapq import heappop, heappush
from collections import defaultdict
sys.setrecursionlimit(10**7)
import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque
#from decimal import Decimal
#from numba import jit
INF = 1 << 50
EPS = 1e-8
mod = 10 ** 9 + 7
def mapline(t = int):
return map(t, sysread().split())
def mapread(t = int):
return map(t, read().split())
def run():
N, *A = mapread()
ans = 1
current = [0,0,0]
for a in A:
transition = 0
cache = 0
for i, c in enumerate(current):
if c == a:
transition += 1
cache = i
ans *= transition
ans %= mod
current[cache] += 1
#print(current)
print(ans)
if __name__ == "__main__":
run()
| 1 | 130,687,410,785,568 | null | 268 | 268 |
N,K=map(int,input().split())
ans=list()
for i in range(K):
D=int(input())
L=list(map(int,input().split()))
ans+=L
ans=list(set(ans))
print(N-len(ans)) | n,k = map(int,input().split())
treat = [1]*n
for i in range(k):
d = int(input())
c = list(map(int,input().split()))
for j in c:
treat[j-1] = 0
print(sum(treat)) | 1 | 24,627,799,595,488 | null | 154 | 154 |
A, B = map(int, input().split())
if A == 1 or B == 1:
print(1)
elif (A*B) % 2 == 0:
print(A*B//2)
else:
print(A*B//2+1) | n = int(input())
h = int(n / 3600)
m = int((n-h*3600) / 60)
s = n - h * 3600 - m * 60
print(':'.join(map(str, [h,m,s]))) | 0 | null | 25,413,669,635,902 | 196 | 37 |
import numpy as np
n = int(input())
a = np.zeros(n,dtype=int)
b = np.zeros(n,dtype=int)
for i in range(n):
a[i],b[i] = map(float, input().split())
#listをsortする
a.sort()
b.sort()
if n%2 == 1:
a0cen = a[(n-1)//2]
b0cen = b[(n-1)//2]
nn = b0cen - a0cen + 1
else:
a0cen1 = a[(n-2)//2]+a[n//2]
b0cen1 = b[(n-2)//2]+b[n//2]
nn = int(b0cen1 -a0cen1 +1)
print(nn)
| #coding:utf-8
#1_6_A 2015.4.1
n = int(input())
numbers = list(map(int,input().split()))
for i in range(n):
if i == n - 1:
print(numbers[-i-1])
else:
print(numbers[-i-1], end = ' ') | 0 | null | 9,169,937,616,608 | 137 | 53 |
n = int(input()[-1])
if n in [2,4,5,7,9]:
print("hon")
elif n in [0,1,6,8]:
print("pon")
else:
print("bon") | N = input()
print('hon') if N[-1] in ["2","4","5","7","9"] else print('bon') if N[-1]=="3" else print('pon') | 1 | 19,347,752,318,490 | null | 142 | 142 |
N = int(input())
A = list(map(int,input().split()))
a = 0
for i in range(1, N):
b = A[i]-A[i-1]
if b < 0:
A[i] = A[i-1]
a -= b
print(a) | S,T=input().split()
print(T+S)
| 0 | null | 53,883,136,209,672 | 88 | 248 |
N, K = map(int, input().split())
hlist = list(map(int, input().split()))
print(len([x for x in hlist if x >= K]))
| i = int(input())
print(i ** 3) | 0 | null | 89,322,025,583,882 | 298 | 35 |
import bisect
n, m, k = map(int, input().split())
alist = list(map(int, input().split()))
blist = list(map(int, input().split()))
for i in range(len(alist)-1):
alist[i+1] += alist[i]
for i in range(len(blist)-1):
blist[i+1] += blist[i]
x = bisect.bisect_right(alist, k)
ans = bisect.bisect_right(blist, k)
for i in range(x):
d = k - alist[i]
y = bisect.bisect_right(blist, d) + i + 1
if ans < y:
ans = y
print(ans) | N, M, K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
sumA = [0]
sumB = [0]
tmp = 0
answer = 0
st = 0
for i in range(N):
tmp = tmp + A[i]
sumA.append(tmp)
tmp = 0
for i in range(M):
tmp = tmp + B[i]
sumB.append(tmp)
for i in range(N, -1, -1):
booktmp = 0
for j in range(st, M + 1):
if sumA[i] + sumB[j] <= K:
booktmp = i + j
else:
st = j
break
answer = max(answer, booktmp)
if j == M:
break
print(answer)
| 1 | 10,766,602,780,188 | null | 117 | 117 |
def GCD(m, n):
while n != 0:
m, n = n, m % n
return m
def gcd_all(a):
n = len(a)
gcd = a[0]
for i in range(1, n):
gcd = GCD(gcd, a[i])
return gcd
def f(a):
mx = 10**6
p = set([])
sieve = [i for i in range(mx + 1)]
for i in range(2, int(mx**0.5 + 1)):
for j in range(2 * i, mx + 1, i):
if sieve[j] > i:
sieve[j] = i
pairwise_coprime = True
for i in a:
p2 = set([])
while i > 1:
p2.add(sieve[i])
i //= sieve[i]
for j in p2:
if j in p:
pairwise_coprime = False
break
p.add(j)
if pairwise_coprime == False:
break
gcd = gcd_all(a)
if pairwise_coprime == False and gcd == 1:
return 'setwise coprime'
elif pairwise_coprime:
return 'pairwise coprime'
else:
return 'not coprime'
n = int(input())
a = list(map(int, input().split()))
print(f(a))
| N=int(input())
*A,=map(int,input().split())
M=max(A)
B=[1]*(M+1)
B[0]=B[1]=1
i=2
while i<=M:
if B[i]:
j=2
while i*j<=M:
B[i*j]=0
j+=1
i+=1
C=[0]*(M+1)
for a in A:
C[a]=1
from math import*
now=A[0]
for a in A:
now=gcd(now,a)
if now==1:
ans='pairwise coprime'
i=2
while i<=M:
if B[i]:
count=0
j=1
while i*j<=M:
count+=C[i*j]
j+=1
if count>1:
ans='setwise coprime'
i+=1
print(ans)
else:
print('not coprime') | 1 | 4,052,438,438,400 | null | 85 | 85 |
inp=list(map(int,input().strip().split()))[:2]
n,r=inp[0],inp[1]
if(n <= 9):
print(100*(10-n)+r)
else:
print(r)
| h=int(input())
w=int(input())
n=int(input())
if h>w:
print(-(n//-h))
else:
print(-(n//-w))
| 0 | null | 76,024,480,979,902 | 211 | 236 |
N = int(input())
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5)+1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n//i)
# divisors.sort()
return divisors
K = []
# N = K**n*(K*m+1)
# n >= 1
K1 = make_divisors(N)
K1.pop(0)
# print(K1)
for k in K1:
# print("k=",k)
n=0
while N-k**n >= 0:
# print((N-k**n)%(k**(n+1)))
# print("n=",n)
if (N-k**n)%(k**(n+1))==0:
K.append(k)
n += 1
# print(K)
# n == 0
K2 = make_divisors(N-1)
K2.pop(0)
K += K2
# print(K)
print(len(K))
| x,n=map(int,input().split())
*p,=map(int,input().split())
q=[0]*(102)
for pp in p:
q[pp]=1
diff=1000
ans=-1
for i in range(0,102):
if q[i]:
continue
cdiff=abs(i-x)
if cdiff<diff:
diff=cdiff
ans=i
print(ans) | 0 | null | 27,512,835,538,656 | 183 | 128 |
D = list(input())
ans = 0
cnt = 0
for i in D:
if i == 'R':
cnt += 1
else:
cnt = 0
if ans < cnt:
ans = cnt
print(ans) | s = input()
ans = 0
for i in range(3):
if s[i] == 'R':
ans += 1
else:
if ans == 1:
break
print(ans) | 1 | 4,930,099,281,358 | null | 90 | 90 |
from copy import deepcopy
d=int(input())
c=list(map(int,input().split()))
s=[]
for i in range(d):
a=list(map(int,input().split()))
s.append(a)
def score_calculator(l):
score=0
last=[0]*26
for i in range(d):
for j in range(26):
last[j]+=1
last[l[i]]=0
for j in range(26):
score-=last[j]*c[j]
score+=s[i][l[i]]
return score
for i in range(1,26):
highest_sum_score=-1000000000000
last=[0]*26
temp_ans_lst=[]
for j in range(d):
daily_highest_score=-10000000000000
for k in range(26):
temp_score=s[j][k]
temp_last=deepcopy(last)
for p in range(26):
temp_last[p]+=1
temp_last[k]=0
for p in range(26):
down=temp_last[p]
for q in range(i):
qdown=down+i+1
down+=qdown
temp_score-=down*c[p]
if temp_score>daily_highest_score:
daily_highest_score=temp_score
daily_choice=k
temp_ans_lst.append(daily_choice)
if score_calculator(temp_ans_lst)>highest_sum_score:
ans_lst=temp_ans_lst
for i in ans_lst:
print(i+1) | import sys
import random
test = False
def solve(c_list, days, now):
r = sum(c_list[i]*(now-days[i]) for i in range(26))
return r
if test == True:
seed = 94
random.seed(seed)
d = 365
c = [random.randrange(0, 101) for _ in range(26)]
s = [[random.randrange(0, 20001) for _ in range(26)] for _ in range(d)]
c_ = ' '.join(map(str, c))
s_ = '\n'.join([' '.join(map(str, i)) for i in s])
with open('./input.txt', 'w') as f:
f.write('\n'.join([str(d), c_, s_]))
else:
d = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _i in range(d)]
last_days = [-1 for _i in range(26)]
result = []
score = 0
for today in range(d):
checker = [c[j]*(today-last_days[j]) for j in range(26)]
y = sum(checker)
finder = [s[today][j]-(y-checker[j]) for j in range(26)]
x = finder.index(max(finder))
last_days[x] = today
result.append(x+1)
score += s[today][x] - solve(c, last_days, today)
#print(score)
if test == True:
with open('./output.txt', 'w') as f:
f.write('\n'.join(map(str, result)))
else:
for i in result:
print(i) | 1 | 9,658,249,885,070 | null | 113 | 113 |
# ?????????????????±??????????????????????????¢???????????????????????°?????°??????????????°??????
# ?¨??????\??????????????????????????????
import sys
# ???????????????????????????????????????
input_char = []
for line in sys.stdin:
input_char.append(line)
# ???????????????????????????
count_char = "".join(input_char)
# print(count_char[2])
# ????????????????????¨???????????????
countingChar = [0 for i in range(26)]
# ??????????????¢????????????
for i in range(0, len(count_char)):
if ord(count_char[i].lower()) - ord("a") > -1 and ord(count_char[i].lower()) - ord("a") < 27:
countingChar[ord(count_char[i].lower()) - ord("a")] += 1
# ??????
for i in range(0, 26):
print("{0} : {1}".format(chr(ord("a") + i), countingChar[i])) | D,T,S=map(int,input().split())
print("Yes" if D<=T*S else "No") | 0 | null | 2,622,695,360,350 | 63 | 81 |
N,X,T = map(int, input().split())
if X >= N:
print(T)
elif N % X == 0:
print(N//X*T)
else:
print((N//X+1)*T) | while True:
try:
a, b = map(int, input().split())
if a < b:
b, a = a, b
x, y = a, b
while b: a, b = b, a%b
gcd = a
lcm = (x*y)//gcd
print(gcd, lcm)
except:
break | 0 | null | 2,141,497,573,220 | 86 | 5 |
A, B = map(int, input().split())
ans = max(A-B*2,0)
print(ans)
| N = int(input())
S = input()
print('Yes' if S[:len(S)//2] == S[len(S)//2:] else 'No') | 0 | null | 156,769,082,026,436 | 291 | 279 |
import sys
stdin = sys.stdin
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))
n, k, c = nm()
a = ns()
ans = []
al = []
count = 0
dey = 1
for i in a:
if i is "o" and count <= 0:
al.append(dey)
count = c + 1
dey += 1
count -= 1
ar = []
count = 0
dey = n
for i in reversed(a):
if i is "o" and count <= 0:
ar.append(dey)
count = c + 1
dey -= 1
count -= 1
al = al[:k]
ar = ar[:k]
for i in al:
j = ar.pop(-1)
if i == j:
ans.append(i)
for i in ans:
print(i)
| import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush,heapify
import math
from copy import deepcopy
import queue
import numpy as np
# sympy as syp(素因数分解とか)
Mod = 1000000007
def sieve_of_eratosthenes(n):
if not isinstance(n,int):
raise TypeError("n is not int")
if n<2:
raise ValueError("n is not effective")
prime = [1]*(n+1)
for i in range(2,int(math.sqrt(n))+1):
if prime[i] == 1:
for j in range(2*i,n+1):
if j%i == 0:
prime[j] = 0
res = []
for i in range(2,n+1):
if prime[i] == 1:
res.append(i)
return res
class UnionFind:
def __init__(self,n):
self.parent = [i for i in range(n+1)]
self.rank = [0 for i in range(n+1)]
def findroot(self,x):
if x == self.parent[x]:
return x
else:
y = self.parent[x]
y = self.findroot(self.parent[x])
return y
def union(self,x,y):
px = self.findroot(x)
py = self.findroot(y)
if px < py:
self.parent[y] = px
else:
self.parent[px] = py
def same_group_or_no(self,x,y):
return self.findroot(x) == self.findroot(y)
def main(): #startline-------------------------------------------
n, k, c = map(int, input().split())
def sub(s):
n = len(s)
cur = 0
last = -(c + 1)
res = [0] * (n + 1)
for i in range(n):
if (i - last > c and s[i] == "o"):
cur += 1
last = i
res[i + 1] = cur
return res
s = input()
left = sub(s)
t = s
t = t[::-1]
right = sub(t)
for i in range(n):
if s[i] == "x": continue
if left[i] + right[n - i - 1] < k:
print(i+1)
if __name__ == "__main__":
main() #endline=============================================== | 1 | 40,717,576,155,562 | null | 182 | 182 |
n = int(input())
buf = list(map(int,input().split()))
a = []
for i in range(n):
a.append([buf[i],i])
a = sorted(a,reverse=True)
dp = [[0]*(n+1) for i in range(n+1)]
for i in range(n):
for j in range(n-i):
cur = i+j
temp1 = dp[i][j]+a[cur][0]*abs(n-1-a[cur][1]-j)
temp2 = dp[i][j]+a[cur][0]*abs(a[cur][1]-i)
dp[i+1][j] = max(dp[i+1][j],temp2)
dp[i][j+1] = max(dp[i][j+1],temp1)
print(max([max(i) for i in dp])) | n=int(input())
a=list(enumerate(map(int,input().split())))
a.sort(key=lambda x: -x[1])
dp=[[0]*(n+1) for i in range(n+1)]
for idx,ix in enumerate(a):
i,x=ix
for j in range(idx+1):
dp[j+1][idx-j]=max(dp[j+1][idx-j],dp[j][idx-j]+(i-j)*x)
dp[j][idx-j+1]=max(dp[j][idx-j+1],dp[j][idx-j]+((n-1-(idx-j))-i)*x)
print(max([dp[i][n-i] for i in range(n+1)])) | 1 | 33,680,556,936,000 | null | 171 | 171 |
N = int(input())
A = map(int, input().split())
curr = 0
ans = 0
for a in A:
if curr > a:
ans += curr - a
else:
curr = a
print(ans) | import sys
read = sys.stdin.read
#readlines = sys.stdin.readlines
def main():
n, *a = map(int, read().split())
r = 0
maxtall = a[0]
for i1 in range(1, n):
if a[i1] > maxtall:
maxtall = a[i1]
else:
r += maxtall - a[i1]
print(r)
if __name__ == '__main__':
main()
| 1 | 4,610,451,928,180 | null | 88 | 88 |
dic = set()
n = int(input())
for i in range(n):
cmd, val = input().split()
if cmd == "insert":
dic.add(val)
elif cmd == "find":
print("yes" if val in dic else "no")
else:
print("wrong command")
| import math
N = int(input())
Z = [int(input()) for i in range(N)]
ctr = 0
for j in range(N):
if Z[j] == 2:
ctr += 1
elif Z[j] < 2 or (Z[j] % 2) == 0:
pass
else:
Up = math.sqrt(Z[j])
k = 3
while k<= Up:
if (Z[j] % k) == 0:
break
else:
k += 1
else:
ctr += 1
print(ctr) | 0 | null | 45,621,916,158 | 23 | 12 |
H=int(input())
ans=0
i=0
while 2**i<=H:
ans+=2**i
i+=1
print(ans) |
bil_date = []
flag = 0
for i in range(4):
bil_date.append([[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0]])
all_date_amo = int(input())
for i in range(all_date_amo):
date = [int(indate) for indate in input().split()]
bil_date[date[0]-1][date[1]-1][date[2]-1] = bil_date[date[0]-1][date[1]-1][date[2]-1] + date[3]
if bil_date[date[0]-1][date[1]-1][date[2]-1] < 0:
bil_date[date[0]-1][date[1]-1][date[2]-1] = 0
if bil_date[date[0]-1][date[1]-1][date[2]-1] > 9:
bil_date[date[0]-1][date[1]-1][date[2]-1] = 9
for bil in bil_date:
for flo in bil:
for room in flo:
print(' {}'.format(room),end='')
print('')
if flag == 3:
pass
else:
for i in range(20):
print('#',end='')
print('')
flag = flag + 1
| 0 | null | 40,352,452,156,058 | 228 | 55 |
str = input().split();
a = int(str[0]);
b = int(str[1]);
c = int(str[2]);
if a < b & b < c:
print("Yes");
else:
print("No"); | x = raw_input().split()
m = map(int,x)
a = x[0]
b = x[1]
c = x[2]
if a < b and b< c:
print "Yes"
else:
print"No" | 1 | 392,559,270,050 | null | 39 | 39 |
from collections import deque
def calculate_area(lines):
q = deque()
partial_area = 0
areas = []
total_area = 0
for i, line in enumerate(lines):
if line == "\\":
q.append(i)
elif line == "/":
if q:
num = q.pop()
partial_area = i - num
total_area += partial_area
for p_area in areas[::-1]:
if p_area[0] > num:
partial_area += areas.pop()[1]
else:
break
areas.append([num, partial_area])
areas_strigified = [str(v) for i, v in areas]
print(total_area)
if total_area:
print("{} {}".format(len(areas), ' '.join(areas_strigified)))
else:
print(0)
if __name__ == "__main__":
data = input()
calculate_area(data)
| s=0
j=0
a=[]
k=[]
l=[]
for i,x in enumerate(input()):
if x=='\\':
a+=[i]
elif x=='/' and a:
j=a.pop()
y=i-j;s+=y
while k and k[-1]>j:
y+=l.pop()
k.pop()
k+=[j]
l+=[y]
print(s)
print(len(k),*(l))
| 1 | 55,197,627,808 | null | 21 | 21 |
# -*- coding: utf-8 -*-
from scipy.sparse.csgraph import floyd_warshall
N, M, L = map(int,input().split())
d = [[0 for i in range(N)] for j in range(N)]
for i in range(M):
x,y,z = map(int,input().split())
d[x-1][y-1] = z
d[y-1][x-1] = z
for i in range(N):
d[i][i] = 0
d = floyd_warshall(d, directed = False)
LN = [[0 for i in range(N)] for j in range(N)]
for i in range(N):
for j in range(N):
if d[i][j] <= L:
LN[i][j] = 1
LN[j][i] = 1
LN = floyd_warshall(LN, directed = False)
s = []
t = []
Q = int(input())
for i in range(Q):
s1, t1 = map(int,input().split())
s.append(s1)
t.append(t1)
for i in range(Q):
if LN[s[i]-1][t[i]-1] == float("inf"):
print(-1)
else:
print(int(LN[s[i]-1][t[i]-1]-1)) | import sys
input = sys.stdin.buffer.readline
n, m, limit = map(int, input().split())
infi = 10 ** 15
graph = [[infi] * (n + 1) for _ in range(n + 1)]
step = [[infi] * (n + 1) for _ in range(n + 1)]
for _ in range(m):
a, b, c = map(int, input().split())
graph[a][b] = c
graph[b][a] = c
for k in range(1, n + 1):
for i in range(1, n + 1):
for j in range(1, n + 1):
graph[i][j] = min(graph[i][k] + graph[k][j], graph[i][j])
for i in range(1, n + 1):
for j in range(1, n + 1):
if graph[i][j] <= limit:
graph[i][j] = 1
elif graph[i][j] == 0:
graph[i][j] = 0
else:
graph[i][j] = infi
for k in range(1, n + 1):
for i in range(1, n + 1):
for j in range(1, n + 1):
graph[i][j] = min(graph[i][k] + graph[k][j], graph[i][j])
q = int(input())
for _ in range(q):
a, b = map(int, input().split())
if graph[a][b] == infi:
graph[a][b] = 0
print(graph[a][b] - 1 if graph[a][b] != infi else -1) | 1 | 173,589,497,957,070 | null | 295 | 295 |
N=int(input())
A=list(map(int,input().split()))
m=int(input())
q=list(map(int,input().split()))
num_list=set()
for i in range(2**N):
ans=0
for j in range(N):
if i>>j&1:
ans+=A[j]
num_list.add(ans)
for i in q:
if i in num_list:
print("yes")
else:print("no")
| N = int(input())
A = list(map(int, input().split()))
B = [0 for i in range(max(A)+1)]
for i in range(2, len(B)):
if B[i] != 0:
continue
for j in range(i, len(B), i):
B[j] = i
def func(X):
buf = set()
while X>1:
x = B[X]
buf.add(x)
while X%x==0:
X = X//x
#print(buf)
return buf
set1 = func(A[0])
set2 = func(A[0])
totallen = len(set1)
for a in A[1:]:
set3 = func(a)
totallen += len(set3)
#print(a, set1, set2)
set1 |= set3
set2 &= set3
#print(set1, set2, set3)
#print(totallen, set1, set2)
if len(set2)!=0:
print("not coprime")
elif len(set1)==totallen:
print("pairwise coprime")
else:
print("setwise coprime") | 0 | null | 2,114,758,306,820 | 25 | 85 |
n = input()
res = 0
for i in range(len(n)):
res += int(n[i])
print("Yes" if res%9 == 0 else "No") | n = list(input())
i = len(n) - 1
if n[i] == '3':
print('bon')
elif n[i] == '0' or n[i] == '1' or n[i] == '6' or n[i] == '8':
print('pon')
else:
print('hon')
| 0 | null | 11,766,701,529,788 | 87 | 142 |
import math
k = int(input())
ans = "NG"
pi = math.pi
print(2*k*pi) | import math
radius=int(input())
print(2*math.pi*radius) | 1 | 31,355,370,126,368 | null | 167 | 167 |
A = list(map(int, input().split()))
#print(A)
def hantei(list):
for a in range(len(list)):
if list[a] == 0:
return a+1
print(hantei(A)) | N = int(input())
P = list(map(int,input().split()))
T = [P[0]]+[10**10]*(N-1)
ans = 0
for i in range(N):
T[i] = min(T[i-1],P[i])
for i in range(N):
if P[i] <= T[i]:
ans += 1
print(ans) | 0 | null | 49,402,468,181,190 | 126 | 233 |
data = input().split()
n = data[0]
m = data[1]
if n == m:
print("Yes")
else:
print("No") | def main():
from itertools import permutations
from math import hypot
N = int(input())
xys = []
for _ in range(N):
x, y = map(int, input().split())
xys.append((x, y))
ans = 0
for perm in permutations(xys, r=2):
x1, y1 = perm[0]
x2, y2 = perm[1]
d = hypot(x2 - x1, y2 - y1)
ans += d
ans /= N
print(ans)
if __name__ == '__main__':
main()
| 0 | null | 116,124,608,592,964 | 231 | 280 |
def resolve():
N, M = list(map(int, input().split()))
SC = [list(map(int, input().split())) for _ in range(M)]
value = [None for _ in range(N)]
for s, c in SC:
if not (value[s-1] is None or value[s-1] == c):
print(-1)
return
value[s-1] = c
for i in range(N):
if value[i] is None:
if i == 0:
if N > 1:
value[i] = 1
else:
value[i] = 0
else:
value[i] = 0
if N > 1 and value[0] == 0:
print(-1)
else:
print("".join(map(str, value)))
if '__main__' == __name__:
resolve() | import sys
import math
n, m, l = map(int, raw_input().split())
A = [[0 for i in xrange(m)] for j in xrange(n)]
B = [[0 for i in xrange(l)] for j in xrange(m)]
for i in xrange(n):
A[i] = map(int, raw_input().split())
for i in xrange(m):
B[i] = map(int, raw_input().split())
for i in xrange(n):
for j in xrange(l):
sm = 0
for k in xrange(m):
sm += A[i][k] * B[k][j]
sys.stdout.write(str(sm))
if j < l-1:
sys.stdout.write(" ")
print | 0 | null | 31,033,309,584,690 | 208 | 60 |
*abc, k = map(int, input().split())
n = [0] * 3
for i, v in enumerate(abc):
if k >= v:
n[i] = v
k -= v
else:
n[i] = k
break
print(n[0] + n[2] * -1) | a, b = input().split()
c = a
a = a*int(b)
b = b*int(c)
for i in range(len(a)):
if a[i]<b[i]:
print(a)
break
elif a==b:
print(a)
break
else:
print(b)
break
| 0 | null | 53,013,172,886,440 | 148 | 232 |
m = input("")
s = m.split(".")
sum = 0
if len(s) == 1 and int(m)>=0 and int(m)<10**200000:
for i in m :
sum = sum+int(i)
if sum % 9 == 0:
print("Yes")
else:
print("No") | N = str(input())
a = []
for n in range(len(N)):
a.append(int(N[n]))
if sum(a) % 9 == 0:
print('Yes')
else:
print('No') | 1 | 4,425,604,821,494 | null | 87 | 87 |
import collections
def main():
N, K = map(int, input().split())
A = list(map(int, input().split()))
d = collections.defaultdict(int)
prefix = [0]
for i in range(N):
prefix.append(prefix[-1] + A[i])
ans = 0
for j in range(N+1):
v = (prefix[j] - j) % K
ans += d[v]
d[v] += 1
if j >= K-1:
d[(prefix[j-K+1] - (j-K+1)) % K] -= 1
# print(ans)
return ans
if __name__ == '__main__':
print(main()) | import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
N, T, *AB = map(int, read().split())
A = AB[::2]
B = AB[1::2]
dp1 = [[0] * T for _ in range(N + 1)]
for i in range(N):
for t in range(T):
if 0 <= t - A[i]:
dp1[i + 1][t] = dp1[i][t - A[i]] + B[i]
if dp1[i + 1][t] < dp1[i][t]:
dp1[i + 1][t] = dp1[i][t]
dp2 = [[0] * T for _ in range(N + 1)]
for i in range(N - 1, -1, -1):
for t in range(T):
if 0 <= t - A[i]:
dp2[i][t] = dp2[i + 1][t - A[i]] + B[i]
if dp2[i][t] < dp2[i + 1][t]:
dp2[i][t] = dp2[i + 1][t]
ans = 0
for i in range(N):
tmp = max(dp1[i][t] + dp2[i + 1][T - t - 1] for t in range(T)) + B[i]
if ans < tmp:
ans = tmp
print(ans)
return
if __name__ == '__main__':
main()
| 0 | null | 145,122,308,006,270 | 273 | 282 |
arr = list(map(int,input().split()))
print(int(arr[0])*int(arr[1])) | a,b=map(float,input().split())
import decimal
a=decimal.Decimal(a)
b=decimal.Decimal(b)
print(int(a*b)) | 1 | 15,862,538,829,030 | null | 133 | 133 |
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):
d = int(S[i])
if d % P == 0:
ans += i + 1
print(ans)
else:
ans = 0
count = defaultdict(int)
count[0] = 1
num = 0
factor = 1
for i in range(N)[::-1]:
num = (num + int(S[i]) * factor) % P
factor = factor * 10 % P
ans += count[num]
count[num] += 1
print(ans)
| from collections import defaultdict
def main():
N, P = list(map(int, input().split()))
S = input()
if P in [2, 5]:
ans = 0
# P = 2, 5の時は一番下の位の数だけ見ればカウント可能
for right in range(N - 1, - 1, - 1):
if int(S[right]) % P == 0:
ans += right + 1
print(ans)
return
# 例:S = 3543, P = 3
# 左からn番目 ~ 1番右の数のmod Pの値を計算
# C = [3543, 543, 43, 3] % P = [0, 0, 1, 0]
# C[m] == C[n] なる m < nのペア数 + C[n] == 0なるnの個数を求める
# 3 + 3 = 6
cur_c = 0
C = [0] * N
pw = 1
for n, s in enumerate(S[::-1]):
cur_c = (cur_c + pw * int(s)) % P
C[N - 1 - n] = cur_c
pw = (pw * 10) % P
counter = defaultdict(int)
for c in C:
counter[c] += 1
ans = 0
for c in C:
counter[c] -= 1
ans += counter[c]
ans += len([c for c in C if c == 0])
print(ans)
if __name__ == '__main__':
main() | 1 | 58,419,210,074,108 | null | 205 | 205 |
def minkovsky(A,B,n = 0):
C = [abs(a - b) for a , b in zip(A,B)]
if n == 0:
return max(C)
else:
d = 0
for c in C:
d += c ** n
d = d ** (1 / n)
return d
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
print(minkovsky(A,B,1))
print(minkovsky(A,B,2))
print(minkovsky(A,B,3))
print(minkovsky(A,B))
| import math
def hoge(x, y, p):
s = 0
for x_i, y_i in zip(x, y):
s += math.pow(math.fabs(x_i - y_i), p)
return math.pow(s, 1/p)
_ = input()
x = [int(e) for e in input().split()]
y = [int(e) for e in input().split()]
print (hoge(x, y, 1))
print (hoge(x, y, 2))
print (hoge(x, y, 3))
print (max([math.fabs(x_i - y_i) for x_i, y_i in zip(x,y)]))
| 1 | 204,875,788,886 | null | 32 | 32 |
from math import gcd
import sys
input=sys.stdin.readline
n=int(input())
a=list(map(int,input().split()))
x=[-1]*(10**6+5)
x[0]=0
x[1]=1
i=2
while i<=10**6+1:
j=2*i
if x[i]==-1:
x[i]=i
while j<=10**6+1:
if x[j]==-1:x[j]=i
j+=i
i+=1
z=[0]*(10**6+5)
g=gcd(a[0],a[0])
for i in range(n):
g=gcd(g,a[i])
if g!=1:
print("not coprime")
else:
f=0
for i in range(n):
p=1
while a[i]>=2:
if p==x[a[i]]:
a[i]=a[i]//p
continue
else:
p=x[a[i]]
z[p]+=1
a[i]=a[i]//p
for i in range(10**6+1):
if z[i]>=2:
f=1
print("pairwise coprime" if f==0 else "setwise coprime")
| from math import gcd
from functools import reduce
from collections import defaultdict
n=int(input())
a=list(map(int,input().split()))
g=reduce(gcd,a)
if g!=1:
print("not coprime")
exit()
def isPrimeMR(n):
d = n - 1
d = d // (d & -d)
L = [2]
for a in L:
t = d
y = pow(a, t, n)
if y == 1: continue
while y != n - 1:
y = (y * y) % n
if y == 1 or t == n - 1: return 0
t <<= 1
return 1
def findFactorRho(n):
m = 1 << n.bit_length() // 8
for c in range(1, 99):
f = lambda x: (x * x + c) % n
y, r, q, g = 2, 1, 1, 1
while g == 1:
x = y
for i in range(r):
y = f(y)
k = 0
while k < r and g == 1:
ys = y
for i in range(min(m, r - k)):
y = f(y)
q = q * abs(x - y) % n
g = gcd(q, n)
k += m
r <<= 1
if g == n:
g = 1
while g == 1:
ys = f(ys)
g = gcd(abs(x - ys), n)
if g < n:
if isPrimeMR(g): return g
elif isPrimeMR(n // g): return n // g
return findFactorRho(g)
def primeFactor(n):
i = 2
ret = {}
rhoFlg = 0
while i*i <= n:
k = 0
while n % i == 0:
n //= i
k += 1
if k: ret[i] = k
i += 1 + i % 2
if i == 101 and n >= 2 ** 20:
while n > 1:
if isPrimeMR(n):
ret[n], n = 1, 1
else:
rhoFlg = 1
j = findFactorRho(n)
k = 0
while n % j == 0:
n //= j
k += 1
ret[j] = k
if n > 1: ret[n] = 1
if rhoFlg: ret = {x: ret[x] for x in sorted(ret)}
return ret
def primes(x):
ret=[]
for i in range(1,int(x**0.5)+1):
if x%i==0:
ret.append(i)
if x//i!=i:
ret.append(x//i)
ret.sort()
return ret[1:]
d=defaultdict(int)
for q in a:
#p=primeFactor(q)
p=primes(q)
for j in p:
if d[j]==1:
print("setwise coprime")
exit()
d[j]+=1
print("pairwise coprime") | 1 | 4,152,673,515,060 | null | 85 | 85 |
n=int(input())
k=int(input())
if n<10:
if k==0:
print(1)
elif k==1:
print(n)
else:
print(0)
exit()
#10
#0の数は高々3つまでなので、jは0,1,2,3の配列だけ持てば良い
#i桁目までは高々100
#
#dp[i][j][smaller]=
lenn=len(str(n))
dp=[[[0]*2 for _ in range(4)] for _ in range(lenn)]
#smallerは、0::通常、1:未満の2パターン
if int(str(n)[0])==1:
dp[0][0][0]=1
dp[0][1][1]=1
else:
dp[0][0][0]=1
dp[0][1][0]=int(str(n)[0])-1
dp[0][1][1]=1
#print(dp)
for i in range(lenn-1):
dp[i+1][0][0]+=dp[i][0][0]
dp[i+1][1][0]+=dp[i][0][0]*9+dp[i][1][0] #+dp[i][0][1]*max(0,(int(str(n)[i])-1))
dp[i+1][2][0]+=dp[i][1][0]*9+dp[i][2][0] #+dp[i][1][1]*max(0,(int(str(n)[i])-1))
dp[i+1][3][0]+=dp[i][2][0]*9+dp[i][3][0] #+dp[i][2][1]*max(0,(int(str(n)[i])-1))
#print(dp)
if int(str(n)[i+1])==0:
dp[i+1][0][1]+=dp[i][0][1]
dp[i+1][1][1]+=dp[i][1][1]
dp[i+1][2][1]+=dp[i][2][1]
dp[i+1][3][1]+=dp[i][3][1]
elif int(str(n)[i+1])==1:
dp[i+1][1][1]+=dp[i][0][1]
dp[i+1][2][1]+=dp[i][1][1]
dp[i+1][3][1]+=dp[i][2][1]
dp[i+1][1][0]+=dp[i][1][1]
dp[i+1][2][0]+=dp[i][2][1]
dp[i+1][3][0]+=dp[i][3][1]
else:
dp[i+1][1][1]+=dp[i][0][1]
dp[i+1][2][1]+=dp[i][1][1]
dp[i+1][3][1]+=dp[i][2][1]
dp[i+1][1][0]+=dp[i][1][1]
dp[i+1][2][0]+=dp[i][2][1]
dp[i+1][3][0]+=dp[i][3][1]
dp[i+1][1][0]+=dp[i][0][1]*(int(str(n)[i+1])-1)
dp[i+1][2][0]+=dp[i][1][1]*(int(str(n)[i+1])-1)
dp[i+1][3][0]+=dp[i][2][1]*(int(str(n)[i+1])-1)
#print(dp)
print(sum(dp[-1][k])) | n,K=input(),int(input())
m=len(n)
DP=[[[0]*(K+2) for _ in range(2)] for _ in range(m+1)]
DP[0][0][0]=1
for i in range(1,m+1):
for flag in range(2):
num=9 if flag else int(n[i-1])
for j in range(K+1):
for k in range(num+1):
if k!=0:DP[i][flag or k<num][j+1] +=DP[i-1][flag][j]
else:DP[i][flag or k<num][j] +=DP[i-1][flag][j]
print(DP[m][0][K]+DP[m][1][K]) | 1 | 75,778,632,168,668 | null | 224 | 224 |
T1,T2 = map(int,input().split())
A1,A2 = map(int,input().split()) #高橋君
B1,B2 = map(int,input().split()) #青木君
# 時間配列
T = [T1]
f = 1
for i in range(3):
if f:
Tn = T2
f = 0
else:
Tn = T1
f = 1
T.append(T[-1]+Tn)
# print(T)
class runner():
def __init__(self,v1,v2):
self.v1 = v1
self.v2 = v2
def distance(self,t):
d = t//(T1+T2)*(self.v1*T1 + self.v2*T2)
tm = t % (T1+T2)
# print("d",d,"tm",tm)
if tm < T1:
d += self.v1 * tm
else:
d += self.v2*(tm-T1) + self.v1*T1
return d
dif = runner(A1-B1,A2-B2)
c = -1
D = 0
DL = [0]
for t in T:
pD = D
D = dif.distance(t)
DL.append(D)
# print(D)
if pD*D <= 0:
c += 1
# print(c)
# print(DL)
if DL[1]*DL[2] > 0:
print(0)
else:
if DL[2] == 0:
print("infinity")
else:
a = DL[2]
if a>0:
if -DL[1]%a == 0:
print(-DL[1]//a*2)
else:
print(-DL[1]//a*2+1)
else:
if -DL[1]%a == 0:
print(-DL[1]//a*2)
else:
print(-DL[1]//a*2+1) | #!/usr/bin/env python3
from itertools import combinations
import sys
input = sys.stdin.readline
MOD = 10**9 + 7
t1, t2 = [int(item) for item in input().split()]
a1, a2 = [int(item) for item in input().split()]
b1, b2 = [int(item) for item in input().split()]
a1 *= t1
b1 *= t1
a2 *= t2
b2 *= t2
if a1 + a2 == b1 + b2:
print("infinity")
exit()
if a1 + a2 > b1 + b2:
a1, a2, b1, b2 = b1, b2, a1, a2
diff = (b1 + b2) - (a1 + a2)
mid_diff = b1 - a1
if mid_diff > 0:
print(0)
else:
ans = (abs(mid_diff) + diff - 1) // diff * 2
if abs(mid_diff) % diff == 0:
ans += 1
print(ans - 1) | 1 | 131,507,193,292,608 | null | 269 | 269 |
n = int(input())
s = input()
ans = 0
for i in range(n - 2):
a = s[i:i + 3]
if a == "ABC":
ans += 1
print(ans) | n,m = map(int,input().split())
a = list(map(int,input().split()))
m_count = 0
a_sum = sum(a)
for i in a:
if i >= (a_sum/(4*m)):
m_count += 1
else:
continue
if m_count >= m:
print("Yes")
else:
print("No") | 0 | null | 68,716,637,696,448 | 245 | 179 |
n=int(input())
a=False
for i in range(200):
for j in range(200):
if i**5-j**5==n:
print(i,j)
a=True
elif i**5+j**5==n:
print(i,-j)
a=True
if a:
break | x = int(input().strip())
for i in range(120):
for j in range(120):
y = i**5 + j**5
z = i**5 - j**5
if z == x:
a = i
b = j
print("{} {}".format(a, b))
exit()
if y == x:
a = i
b = -j
print("{} {}".format(a, b))
exit()
| 1 | 25,619,400,176,908 | null | 156 | 156 |
N,M,X=[int(s) for s in input().split()]
Book=[[int(s) for s in input().split()] for _ in range(N)]
INF=10**7
ans=set()
ans.add(INF)
for n in range(2**N):
#Bit全探索
Xls=[0 for i in range(M)]
cost=0
for i in range(N):
if ((n>>i)&1)==1:
cost+=Book[i][0]
for b in range(M):
Xls[b]+=Book[i][b+1]
if min(Xls)>=X:
ans.add(cost)
if min(ans)==INF:
print(-1)
else:
print(min(ans)) | def main():
S = ''
while True:
try:
S = S + input()
except:
break
s = S.lower()
for i in range(97, 123):
c = chr(i)
n = s.count(c)
print('{} : {}'.format(c, n))
main() | 0 | null | 11,974,051,329,158 | 149 | 63 |
a,b=map(str,input().split())
a=int(a)
b=100*int(b[0])+10*int(b[2])+1*int(b[3]) #bを100倍した値(整数)に直す
print((a*b)//100) | A, B = input().split()
# 方針:少数の計算を避け、整数の範囲で計算する
# [A*B] = [A*(100*B)/100]と見る
# Bを100倍して整数に直す操作は、文字列のまま行う
A = int(A)
B = int(B.replace('.', ''))
# 100で割った整数部分を求める操作は、100で割った商を求めることと同じ
ans = (A*B) // 100
print(ans) | 1 | 16,446,898,188,140 | null | 135 | 135 |
N = int(input())
ans = 0
if N%2 == 1:
print(0)
else:
for i in range(1,len(str(N))+100):
ans += N//(2*5**i)
print(ans) | import math
weeks = int(input())
money = 100
for i in range(0, weeks):
money = math.ceil(money * 1.05)
print(money * 1000) | 0 | null | 58,240,165,244,820 | 258 | 6 |
N,K=map(int,input().split())
*A,=map(int,input().split())
def C(x):
return sum([(A[i]-.5)//x for i in range(N)]) <= K
def binary_search2(func, n_min, n_max):
left,right=n_min,n_max
while right-left>1:
middle = (left+right)//2
y_middle = func(middle)
if y_middle: right=middle
else: left=middle
return right
print(binary_search2(C, 0, max(A)+1)) | from collections import defaultdict
from collections import deque
from collections import Counter
import math
def readInt():
return int(input())
def readInts():
return list(map(int, input().split()))
def readChar():
return input()
def readChars():
return input().split()
n,k = readInts()
a = readInts()
a.sort(reverse=True)
if n==1:
print(math.ceil(a[0]/(k+1)))
exit()
def get(left, right):
l = (right-left)//2+left
ans = 0
for i in a:
ans+=math.ceil(i/l)-1
#print(l, ans, left, right)
return ans,l
def nibu(left,right):
ans,l = get(left, right)
if left<right:
if ans<=k:
return nibu(left,l)
else:
return nibu(l+1, right)
else:
return right
print(nibu(1,a[0]))
| 1 | 6,450,885,977,700 | null | 99 | 99 |
n = input()
min_num = 1000001
max_num = -1000001
sum = 0
tmp = map(int, raw_input().split())
for i in xrange(n):
min_num = min(min_num, tmp[i])
max_num = max(max_num, tmp[i])
sum += tmp[i]
print "%d %d %d" % (min_num, max_num, sum) | #import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left, bisect_right #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')
N = int(input())
A = list(map(int, input().split()))
A.sort()
C = Counter(A)
S = set(A)
maxA = A[-1]
chk = [0] * (maxA+1)
for s in S:
for i in range(s, maxA+1, s):
chk[i] += 1
res = [s for s in S if chk[s] == 1 and C[s] == 1]
# print(res)
print(len(res)) | 0 | null | 7,653,279,324,108 | 48 | 129 |
def cal_puddle(puddle):
depth = 0
score = 0
for s in puddle:
if s == "\\":
score += depth + 0.5
depth += 1
elif s == "/":
depth -= 1
score += depth + 0.5
elif s == "_":
score += depth
if depth == 0:
return int(score)
return int(score)
def get_puddles(diagram):
hight = 0
top_list = []
in_puddle = True
for index, s in enumerate(diagram + "\\"):
if s == "/":
in_puddle = True
hight += 1
if s == "\\":
if in_puddle:
in_puddle = False
top_list.append([hight, index])
hight -= 1
puddles = []
prev_hight = 0
hight_list = [h for h, i in top_list]
i = 0
while i < len(top_list) - 1:
cur_top = top_list[i]
next_tops = list(filter(lambda top:cur_top[0] <= top[0], top_list[i + 1:]))
#print(next_tops)
if next_tops:
next_top = next_tops[0]
puddles.append((cur_top[1], next_top[1]))
i = top_list.index(next_top)
else:
cur_top[0] -= 1
cur_top[1] += diagram[cur_top[1] + 1:].index("\\") + 1
#print(hight_list)
#print(top_list)
#print(puddles)
return puddles
def main():
diagram = input()
result = []
for s,e in get_puddles(diagram):
result.append(cal_puddle(diagram[s:e]))
print(sum(result))
print(str(len(result)) + "".join([" " + str(i) for i in result]))
if __name__ == "__main__":
main() | def main():
n = int(input()) + 1
a = [int(x) for x in input().split()]
q = [0] * n
for i in range(n):
q[i] = (q[i - 1] - a[i - 1]) * 2 if i != 0 else 1
# print(q[i])
if q[i] <= 0:
print(-1)
return
if q[n - 1] < a[n - 1]:
print(-1)
return
q[n - 1] = a[n - 1]
s = q[n - 1]
# print('--')
# print(q[n - 1])
for i in range(n - 2, -1, -1):
q[i] = min(q[i], q[i + 1] + a[i])
if q[i] == 0:
print(-1)
return
# print(q[i])
s += q[i]
print(s)
main()
| 0 | null | 9,546,318,673,440 | 21 | 141 |
s,t = map(str,input().split())
print("".join(t+s)) | ln = input().split()
print(ln[1]+ln[0]) | 1 | 102,775,276,619,360 | null | 248 | 248 |
def breadth_first_search(G):
n = len(G)
d = [-1] * (n + 1)
d[1] = 0
queue = [1]
while len(queue) > 0:
v = queue.pop(0)
for c in G[v]:
if d[c] < 0:
d[c] = d[v] + 1
queue.append(c)
for i in range(1, n + 1):
print(i, d[i])
G = {}
for i in range(int(input())):
x = list(map(int, input().split()))
G[x[0]] = x[2:]
breadth_first_search(G) | import math
r = float(input())
m = r ** 2 * math.pi
l = r * 2 * math.pi
print('{:.6f} {:.6f}'.format(m, l)) | 0 | null | 319,955,130,230 | 9 | 46 |
N=int(input())
ls={}
max_ch=0
for i in range(N):
ch=input()
if not ch in ls:
ls[ch]=1
else:
ls[ch]+=1
if max_ch<ls[ch]:
max_ch=ls[ch]
S=[]
for j in ls:
if max_ch==ls[j]:
S.append(j)
S=sorted(S)
for i in S:
print(i) | #!/usr/bin/env python3
def main():
from collections import defaultdict
N = int(input())
S = [input() for _ in range(N)]
d = defaultdict(int)
for s in S:
d[s] += 1
# d = sorted(d.items())
d = sorted(d.items(), key=lambda d: d[1], reverse=True)
res = d[0][1]
lst = []
for i in d:
if res > i[1]:
break
lst.append(i[0])
res = i[1]
for i in sorted(lst):
print(i)
if __name__ == '__main__':
main()
| 1 | 69,934,848,590,642 | null | 218 | 218 |
inp = input().split(" ")
count = 0
for x in range(int(inp[0]),int(inp[1])+1):
if x % int(inp[2]) == 0:
count = count+1
print(count)
| l,r,d=[int(x) for x in input().split()]
x=(r-l)//d
if l%d==0 or r%d==0:
x+=1
print(x) | 1 | 7,553,487,212,178 | null | 104 | 104 |
n = int(input())
ans = 0
flag = 0
for i in range(0, n):
x, y = input().split()
if x == y:
ans = ans + 1
else:
ans = 0
if ans >= 3:
flag = 1
if flag == 1:
print("Yes")
else :
print("No")
| x, y = map(int, input().split())
ans = 4 if x == 1 and y == 1 else 0
ans += max(0, 4-x)+max(0, 4-y)
print(ans*100000)
| 0 | null | 71,741,947,119,070 | 72 | 275 |
N,R=map(int,input().split())
if 10<=N:
print(R)
else:
a=R+100*(10-N)
print(a) | dic = {}
l = []
n = int(input())
for i in range(n):
s = input()
#sが新規キーか否かで操作を変える
if s in dic:
dic[s] += 1
#新規ではないならvalueを1増やす
else:
dic[s] = 1
m = max(dic.values())
for i in dic:
if dic[i] == m:
l += [i]
print(*sorted(l)) | 0 | null | 66,966,761,337,828 | 211 | 218 |
# -*- coding:utf-8 -*-
import math
n = int(input())
ret_just = math.floor(n/1.08)
ret_minus1 = ret_just - 1
ret_plus1 = ret_just + 1
if math.floor(ret_just*1.08) == n:
print(ret_just)
elif math.floor(ret_minus1*1.08) == n:
print(ret_minus1)
elif math.floor(ret_plus1*1.08) == n:
print(ret_plus1)
else:
print(":(")
| N=input()
N=float(N)
import math
X=math.ceil(N/1.08)
if int(X*1.08)==N:
print(X)
else:
print(':(') | 1 | 125,752,721,155,702 | null | 265 | 265 |
# coding: utf-8
# 63
import math
a,b,c,d= map(float,input().split())
A = (a-c)**2+(b-d)**2
if A<0:
A = math.fabs(A)
print(math.sqrt(A))
| import sys
input = sys.stdin.readline
#n = int(input())
#l = list(map(int, input().split()))
'''
a=[]
b=[]
for i in range():
A, B = map(int, input().split())
a.append(A)
b.append(B)'''
def cal(n,li):
lis=[True]*(n+1)
for item in li:
if lis[item]:
for i in range(item*2,n+1,item):
lis[i]=False
return lis
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
a.sort()
l=cal(a[-1],a)
ll=Counter(a)
#print(l,ll)
ans=0
for i in range(n):
if ll[a[i]]==1:
if l[a[i]]:
ans+=1
print(ans)
| 0 | null | 7,258,249,212,480 | 29 | 129 |
n = list(input())
if '7' in n:
print('Yes')
else:
print('No')
| N = input()
ans = 'No'
for i in range(3):
if int(N[i]) == 7:
ans = 'Yes'
print(ans) | 1 | 34,349,370,284,570 | null | 172 | 172 |
n = int(input())
MOD = 10**9+7
a=10
b=9
c=8
for i in range(n-1):
a*=10
b*=9
c*=8
if i%10==0:
a=a%MOD
b=b%MOD
c=c%MOD
a=a%MOD
b=b%MOD
c=c%MOD
ans = (a-2*b+c)%MOD
print(ans) | class GCD:
def __init__(self, N, K, MOD):
self.N = N
self.K = K
self.MOD = MOD
self.gcd_count_list = []
self.gcd_count_list2 = [0]*self.K
for d in range(1,self.K+1):
self.gcd_count_list.append(self.gcd_count(d))
self.gcd_count2()
def gcd_count(self, d):
""" d, 2d, 3d,... の最大公約数を持つ K 以下の整数 N 個の組の数 """
return pow(self.K//d,self.N,self.MOD)
def gcd_count2(self):
""" dの最大公約数を持つ K 以下の整数 N 個の組の数 """
res = []
i = 1
while K//i > 0:
for j in range(K//(i+1)+1,K//i+1):
self.gcd_count_list2[j-1] = self.gcd_count_list[j-1] \
- sum(self.gcd_count_list2[j*k-1] for k in range(2, i+1))
i += 1
def solve(self):
return sum(d*self.gcd_count_list2[d-1] for d in range(1,K+1))%MOD
N, K = map(int, input().split())
MOD = 10**9 + 7
g = GCD(N, K, MOD)
print(g.solve()) | 0 | null | 19,934,057,507,800 | 78 | 176 |
k=int(input())
v='ACL'
print(k*v) | # coding=utf-8
inputs = raw_input().rstrip().split()
nums = [int(x) for x in inputs]
print ' '.join([str(x) for x in sorted(nums)]) | 0 | null | 1,285,320,179,858 | 69 | 40 |
import sys
from operator import add
for i in sys.stdin:
print(len(str(add(*list(map(int, i.split())))))) | n, m = map(int, input().split())
a = list(map(int, input().split()))
def cumsum(s):
n = len(s)
cs = [0] * (n+1)
for i in range(n):
cs[i+1] = cs[i] + s[i]
return cs
def bs_list(a, f):
l, r = -1, len(a)
while r - l > 1:
x = (l + r) // 2
if f(a[x]): r = x
else: l = x
return None if r == len(a) else r
a.sort()
ca = cumsum(a)
def detect(x):
num = 0
for b in a[::-1]:
res = bs_list(a, lambda y: y >= x - b)
if res is None: break
num += n - res
return num <= m
l, r = -1, 10**5*2+10
while r - l > 1:
x = (l+r) // 2
if detect(x): r = x
else: l = x
s, c = 0, 0
for b in a[::-1]:
res = bs_list(a, lambda x: x >= r - b)
if res is None: break
c += (n - res)
s += b * (n - res) + (ca[n] - ca[res])
print(s + (m - c) * l)
| 0 | null | 54,345,275,602,988 | 3 | 252 |
n,m = map(int,input().split())
#行列a、ベクトルb、行列積cの初期化
a = [0 for i in range(n)]
b = [0 for j in range(m)]
c = []
#a,bの読み込み
for i in range(n):
a[i] = input().split()
a[i] = [int(x) for x in a[i]]
for j in range(m):
b[j] = int(input())
#行列積計算
temp = 0
for i in range(n):
for j in range(m):
temp += a[i][j]*b[j]
c.append(temp)
temp = 0
#結果の表示
for num in c:print(num)
| A = []
b = []
n, m = map(int,input().split())
for i in range(n):
A.append(list(map(int,input().split())))
for i in range(m):
b.append(int(input()))
for i in range(n):
c = 0
for s in range(m):
c += A[i][s] * b[s]
print(c) | 1 | 1,170,874,062,072 | null | 56 | 56 |
#! -*- coding: utf-8 -*-
import random
import math
s = input()
nums = len(s) - 3
index = math.floor(random.random() * nums)
print(s[index: index + 3])
| N = int(raw_input())
A = map(int, raw_input().split())
def bubbleSort(A, N):
count = 0
flag = 1
while flag:
flag = 0
for i in range(N-1, 0, -1):
if A[i] < A[i-1]:
temp = A[i]
A[i] = A[i-1]
A[i-1] = temp
flag = 1
count += 1
return count
count = bubbleSort(A, N)
print " ".join(map(str, A))
print count | 0 | null | 7,425,025,480,168 | 130 | 14 |
nn, kk = list(map(int,input().split()))
pp = list(map(int,input().split()))
expectation = [0]*(nn-kk+1)
expectation[0] = sum(pp[0:kk])
for i in range(1,nn-kk+1):
expectation[i] = expectation[i-1] - pp[i-1] + pp[i+kk-1]
print((max(expectation)+kk)/2)
| #!/usr/bin/env python
# coding: utf-8
# In[43]:
N,K = map(int, input().split())
p = list(map(int, input().split()))
# In[44]:
le = [(x+1)/2 for x in p]
e = sum(le[:K])
ans = e
for i in range(N-K):
e -= le[i]
e += le[i+K]
ans = max(ans ,e)
print(ans)
# In[ ]:
| 1 | 74,989,083,355,820 | null | 223 | 223 |
N = int(input())
ans = 0
ans = -(-N//2)
print(ans) | import math
r = float(input())
print(float(r ** 2 * math.pi), float(r * 2 * math.pi))
| 0 | null | 29,641,794,518,060 | 206 | 46 |
n, m, l = map(int, raw_input().split(" "))
a = [map(int, raw_input().split(" ")) for j in range(n)]
b = [map(int, raw_input().split(" ")) for i in range(m)]
c = [[0 for k in range(l)] for j in range(n)]
for j in range(n):
for k in range(l):
for i in range(m):
c[j][k] += a[j][i] * b[i][k]
for j in range(n):
print " ".join(map(str, (c[j]))) | from collections import defaultdict
d = defaultdict(lambda: 0)
N = int(input())
for _ in range(N):
ord, str = input().split()
if ord == 'insert':
d[str] = 1
else:
if str in d:
print('yes')
else:
print('no') | 0 | null | 746,812,226,160 | 60 | 23 |
num = list(map(int,input().split()))
print("%d %d %f" %(num[0]/num[1],num[0]%num[1],num[0]/num[1] ))
| a, b = map(int, input().split())
print(a //b , a % b, "{0:.5f}".format(a / b)) | 1 | 604,495,593,318 | null | 45 | 45 |
import math
n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
tmp = [[0 for i in range(6)] for j in range(n+1)]
absDiff = abs(x[0]-y[0])
tmp[0][3] = tmp[0][0] = absDiff
tmp[0][4] = tmp[0][1] = absDiff ** 2
tmp[0][5] = tmp[0][2] = absDiff ** 3
max = absDiff
for i in range(1, n, 1):
absDiff = abs(x[i]-y[i])
tmp[i][0] = absDiff
tmp[i][1] = absDiff ** 2
tmp[i][2] = absDiff ** 3
tmp[i][3] = tmp[i-1][3] + tmp[i][0]
tmp[i][4] = tmp[i-1][4] + tmp[i][1]
tmp[i][5] = tmp[i-1][5] + tmp[i][2]
if absDiff > max:
max = absDiff
print(tmp[n-1][3])
print(math.sqrt(tmp[n-1][4]))
print(tmp[n-1][5] ** (1/3))
print(max) | #
# 10d
#
import math
def main():
n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
d1 = 0
d2 = 0
d3 = 0
dn = 0
for i in range(n):
d1 += abs(x[i] - y[i])
d2 += (x[i] - y[i])**2
d3 += abs(x[i] - y[i])**3
dn = max(dn, abs(x[i] - y[i]))
d2 = math.sqrt(d2)
d3 = math.pow(d3, 1/3)
print(f"{d1:.5f}")
print(f"{d2:.5f}")
print(f"{d3:.5f}")
print(f"{dn:.5f}")
if __name__ == '__main__':
main()
| 1 | 211,778,872,580 | null | 32 | 32 |
N,K = map(int,input().split())
A = list(map(int,input().split()))
if K==0:
high = max(A)
else:
low = 0
high = 10**9
while high-low>1:
mid = (high+low)//2
cnt = 0
for i in range(N):
if A[i]%mid==0:
cnt += A[i]//mid-1
else:
cnt += A[i]//mid
if K>=cnt:
high = mid
else:
low = mid
print(high) | def main():
a,b = input().split()
b = b[0] + b[2:]
print(int(a)*int(b)//100)
if __name__ == "__main__":
main()
| 0 | null | 11,438,347,826,712 | 99 | 135 |
s = str(input())
if s.count('RRR') == 1:
print(3)
elif s.count('RR') == 1:
print(2)
elif 1 <= s.count('R'):
print(1)
else:
print(0) | def resolve():
data = [len(x) for x in input().split("S") if x]
print(max(data) if data else 0)
resolve() | 1 | 4,884,242,559,772 | null | 90 | 90 |
results=[]
from sys import stdin
for line in stdin:
a, b = (int(i) for i in line.split())
results.append(len(str(a+b)))
for i in results:
print i | while 1:
try:
a,b=map(int,raw_input().split())
print len("%d"%(a+b))
except:break | 1 | 147,283,972 | null | 3 | 3 |
N, R = (int(x) for x in input().split())
if N >= 10:
result = R
else:
result = R + 100*(10-N)
print(result) | x,y=map(int,input().split())
ans=0
if x<=3:
ans+=(4-x)*100000
if y<=3:
ans+=(4-y)*100000
if ans==600000:
ans=1000000
print(ans) | 0 | null | 102,271,979,830,310 | 211 | 275 |
# coding: utf-8
# マージソート
INFTY = int(1E20)
count = 0
def merge(A, left, mid, right):
global INFTY
global count
L = [i for i in A[left:mid]]
R = [i for i in A[mid:right]]
L.append(INFTY)
R.append(INFTY)
idx_L = 0
idx_R = 0
for idx in range(left, right):
count += 1
if L[idx_L] <= R[idx_R]:
A[idx] = L[idx_L]
idx_L += 1
else:
A[idx] = R[idx_R]
idx_R += 1
def mergeSort(A, left, right):
if left + 1 < right:
mid = (left + right) // 2
mergeSort(A, left, mid)
mergeSort(A, mid, right)
merge(A, left, mid, right)
else:
return
if __name__ == "__main__":
n = int(input())
A = [int(i) for i in input().split()]
mergeSort(A, 0, n)
print(' '.join([str(i) for i in A]))
print(count)
| import sys
def merge(A, left, mid, right):
L = A[left: mid] + [sys.maxsize]
R = A[mid: right] + [sys.maxsize]
i = j = count = 0
k = left
while k < right:
count += 1
if L[i] <= R[j]:
A[k] = L[i]
i += 1
else:
A[k] = R[j]
j += 1
k += 1
return count
def merge_sort(A, left, right):
if right - left > 1:
mid = (left + right) // 2
lcost = merge_sort(A, left, mid)
rcost = merge_sort(A, mid, right)
tot = merge(A, left, mid, right)
return tot + lcost + rcost
else:
return 0
if __name__ == '__main__':
n = int(input())
A = [int(i) for i in input().split()]
count = merge_sort(A, 0, n)
print(str(A).replace(',', '').replace('[', '').replace(']', ''))
print(count)
| 1 | 112,129,706,972 | null | 26 | 26 |
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())
arr=list(map(int,input().split()))
xors = 0
for val in arr: #あらかじめすべての要素のxorを求めておく
xors^=val #(ai xor aj = bi xor bj)となるのですべてのxorを合わせると、b0^b1^b2^...^bn
ans=[]
for i in range(n): #各aiについて、ai xor (すべての要素のxor)がi番目に書かれた値に等しい
ans.append(xors^arr[i])
print(*ans) | 1 | 12,438,705,916,140 | null | 123 | 123 |
def Find(x, par):
if par[x] < 0:
return x
else:
par[x] = Find(par[x], par)
return par[x]
def Unite(x, y, par, rank):
x = Find(x, par)
y = Find(y, par)
if x != y:
if rank[x] < rank[y]:
par[y] += par[x]
par[x] = y
else:
par[x] += par[y]
par[y] = x
if rank[x] == rank[y]:
rank[x] += 1
def Same(x, y, par):
return Find(x, par) == Find(y, par)
def Size(x, par):
return -par[Find(x, par)]
import sys
input = sys.stdin.readline
n, m, k = map(int, input().split())
par = [-1]* n
rank = [0]*n
C = [0]*n
for i in range(m):
a, b = map(int, input().split())
a, b = a-1, b-1
C[a] += 1
C[b] += 1
Unite(a, b, par, rank)
ans = [0]*n
for i in range(n):
ans[i] = Size(i, par)-1-C[i]
for i in range(k):
c, d = map(int, input().split())
c, d = c-1, d-1
if Same(c, d, par):
ans[c] -= 1
ans[d] -= 1
print(*ans)
| nums = [int(e) for e in input().split()]
if (nums[2]+nums[4])<=nums[0] and (nums[3]+nums[4])<=nums[1] and (nums[2]-nums[4])>=0 and (nums[3]-nums[4])>=0:
print("Yes")
else:
print("No")
| 0 | null | 31,145,877,707,710 | 209 | 41 |
#!/usr/bin/env python3
def main():
N, K = map(int, input().split())
mod = 7 + 10 ** 9
res = 0
for k in range(K, N + 2):
res += ((k * (2 * N - k + 1) / 2) - (k * (k - 1) / 2) + 1)
res %= mod
print(int(res))
if __name__ == '__main__':
main()
| import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
N = INT()
A = LIST()
if reduce(gcd, A) != 1:
print("not coprime")
exit()
ma = max(A)
p = list(range(ma+1))
for x in range(2, int(ma ** 0.5) + 1):
if p[x]:
# xは素数,それがpの要素にあるうちは続ける
for i in range(2 * x, ma + 1, x):
p[i] = x
s = [set() for _ in range(N)]
t = set()
for i, x in enumerate(A):
while x != 1:
s[i].add(x)
t.add(x)
# 割り続けるとs[i]にその素数がたまっていく
x //= p[x]
l = sum(len(x) for x in s)
print("pairwise coprime" if l == len(t) else "setwise coprime")
| 0 | null | 18,596,101,839,740 | 170 | 85 |
n=int(input())
a=[]
from collections import deque as dq
for i in range(n):
aaa=list(map(int,input().split()))
aa=aaa[2:]
a.append(aa)
dis=[-1]*n
dis[0]=0
queue=dq([0])
while queue:
p=queue.popleft()
for i in range(len(a[p])):
if dis[a[p][i]-1]==-1:
queue.append(a[p][i]-1)
dis[a[p][i]-1]=dis[p]+1
for i in range(n):
print(i+1,dis[i])
| h = int(input())
w = int(input())
n = int(input())
all_cell = 0
count = 0
while all_cell < n:
if h > w:
all_cell += h
w -= 1
else:
all_cell += w
h -= 1
count += 1
print(count) | 0 | null | 44,307,444,169,508 | 9 | 236 |
import sys
import decimal # 10進法に変換,正確な計算
def input():
return sys.stdin.readline().strip()
def main():
r = int(input())
print(r**2)
main()
| """
author : halo2halo
date : 9, Jan, 2020
"""
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
N = int(readline())
print(int(N**2))
| 1 | 145,337,775,473,280 | null | 278 | 278 |
from math import floor
S = input()
K = int(input())
# Sが1文字しかない
if len(set(S)) == 1:
print(floor(len(S) * K / 2))
exit()
ans = 0
if S[0] != S[-1]:
# Sの中での答え × K回数
c = "0"
count = 0
for i in range(len(S)):
if c == S[i]:
count += 1
else:
# floor(連続した文字の回数 / 2)だけ書き換える
ans += count // 2
c = S[i] # 情報更新
count = 1
ans += count // 2 # 最後の分
ans = ans * K
else:
# 先頭と末端もある
c1 = 1
for i in range(1, len(S)):
if S[i] == S[0]:
c1 += 1
else:
break
c2 = 1
for j in reversed(range(len(S) - 1)):
if S[j] == S[-1]:
c2 += 1
else:
break
ans = (c1 // 2) + (c2 // 2) + ((c1 + c2) // 2 * (K - 1))
c3 = 0
c = "0"
for k in range(i, j + 1):
if S[k] == c:
c3 += 1
else:
ans += c3 // 2 * K
c = S[k]
c3 = 1
ans += c3 // 2 * K
print(ans) | n,m = map(int,input().split())
if n % 2 == 1:
ans = [[1+i,n-i] for i in range(n//2)]
else:
ans = [[1+i,n-i] for i in range(n//4)]+[[n//2+1+i,n//2-1-i] for i in range(n//2-n//4-1)]
for i in range(m):
print(ans[i][0],ans[i][1]) | 0 | null | 102,241,346,028,800 | 296 | 162 |
def BFS(s = 0):
Q.pop(0)
color[s] = 2
for j in range(len(color)):
if A[s][j] == 1 and color[j] == 0:
Q.append(j)
color[j] = 1
d[j] = d[s] + 1
if len(Q) != 0:
BFS(Q[0])
n = int(raw_input())
A = [0] * n
for i in range(n):
A[i] = [0] * n
for i in range(n):
value = map(int, raw_input().split())
u = value[0] - 1
k = value[1]
nodes = value[2:]
for j in range(k):
v = nodes[j] - 1
A[u][v] = 1
color = [0] * n
Q = [0]
d = [-1] * n
d[0] = 0
BFS(0)
for i in range(n):
print(str(i + 1) + " " + str(d[i])) | n = int(input())
adj = [None]
for i in range(n):
adji = list(map(int, input().split()[2:]))
adj.append(adji)
isSearched = [None] + [False] * n
distance = [None] + [-1] * n
def BFS(u):
d = 0
isSearched[u] = True
distance[u] = d
edge = [u]
while edge:
q = list(edge)
edge = []
d += 1
for ce in q:
for ne in adj[ce]:
if not isSearched[ne]:
isSearched[ne] = True
edge.append(ne)
distance[ne] = d
BFS(1)
for i, x in enumerate(distance[1:], start=1):
print(i, x) | 1 | 4,301,222,852 | null | 9 | 9 |
n = int(input())
cn= 1
an= [1]
i = 1
while cn < n / 4:
an.append(cn*3+1)
cn=cn*3+1
an.sort(reverse=True)
def insertionSort(a,n,g):
cnt=0
for i in range(g,n):
v = a[i]
j = i - g
while j>= 0 and a[j]>v:
a[j + g]= a[j]
j = j-g
cnt+=1
a[j + g]=v
return cnt
def shellSort(a,n,an):
cnt=0
m = len(an)
g = an
for i in an:
cnt += insertionSort(a,n,i)
return cnt
x=[]
for i in range(n):
x.append(int(input()))
print(len(an))
print(" ".join([str(i) for i in an]))
y= shellSort(x,n,an)
print(y)
for i in range(n):
print(x[i]) | import sys
A, B, C, D = (int(x) for x in input().split())
while A>0 and C>0:
C-=B
if C<=0:
print("Yes")
sys.exit(0)
A-=D
if A<=0:
print("No") | 0 | null | 14,776,244,201,212 | 17 | 164 |
import math
L = int(input())
print(math.pow(L / 3, 3)) | L = int(input())
num = L / 3
print(num**3) | 1 | 46,991,521,440,986 | null | 191 | 191 |
# from sys import stdin
# input = stdin.readline
from collections import Counter
def solve():
x,n = map(int,input().split())
if n != 0:
p = set(map(int,input().split()))
if n == 0 or x not in p:
print(x)
return
else:
for i in range(100):
if x - i not in p:
print(x - i)
return
if x + i not in p:
print(x + i)
return
if __name__ == '__main__':
solve()
| X, N = map(int, input().split())
p_list = list(map(int, input().split()))
if N == 0:
print(X)
else:
for i in range(0,100):
if not X-i in p_list:
print(X-i)
break
elif not X+i in p_list:
print(X+i)
break | 1 | 14,021,289,352,892 | null | 128 | 128 |
#!usr/bin/env python3
import sys
def init_card_deck():
# S: spades
# H: hearts
# C: clubs
# D: diamonds
card_deck = {'S': [], 'H': [], 'C': [], 'D': []}
n = int(sys.stdin.readline())
for i in range(n):
lst = [card for card in sys.stdin.readline().split()]
card_deck[lst[0]].append(lst[1])
return card_deck
def print_missing_cards(card_deck):
card_symbols = ['S', 'H', 'C', 'D']
for i in card_symbols:
for card in range(1, 14):
if not str(card) in card_deck[i]:
print(i, card)
def main():
print_missing_cards(init_card_deck())
if __name__ == '__main__':
main() | import re
stt = ""
line = input()
for i in range(len(line)):
if re.compile("[A-Z]").search(line[i]):
stt += line[i].lower()
elif re.compile("[a-z]").search(line[i]):
stt += line[i].upper()
else:
stt += line[i]
print(stt) | 0 | null | 1,260,959,346,850 | 54 | 61 |
print("".join([_.upper() if _.islower() else _.lower() for _ in input()])) | from itertools import starmap
print("".join(starmap(lambda c: c.lower() if 'A' <= c <= 'Z' else c.upper(), input()))) | 1 | 1,518,387,469,930 | null | 61 | 61 |
def gcd(a, b):
if a < b:
a, b = b, a
while b != 0:
a, b = b, a % b
return a
print(gcd(*map(int, input().split())))
| W, H, x, y, r = map(int, raw_input().split())
if x < r:
print 'No'
elif W - x < r:
print 'No'
elif y < r:
print 'No'
elif H - y < r:
print 'No'
else:
print 'Yes' | 0 | null | 232,944,810,670 | 11 | 41 |
N = int(input())
A = list(map(int, input().split()))
count = 0
for i in range(N):
for j in range(N - 1, i, -1):
if A[j] < A[j-1]:
A[j], A[j - 1] = A[j -1], A[j]
count += 1
print(*A)
print(count) | Suits = ['S', 'H', 'C', 'D']
Taro = []
Missing = []
n = int(input())
for i in range(n):
Taro.append(input())
for j in range(52):
card = Suits[j//13] + ' ' + str(j % 13 + 1)
if card not in Taro:
Missing.append(card)
if Missing != []:
print('\n'.join(Missing)) | 0 | null | 535,638,577,510 | 14 | 54 |
H ,W = map(int,input().split())
from collections import deque
S = [input() for i in range(H)]
directions = [[0,1],[1,0],[-1,0],[0,-1]]
counter = 0
#インデックス番号 xが行番号 yが列番号
for x in range(H):
for y in range(W):
if S[x][y]=="#":
continue
que = deque([[x,y]])
memory = [[-1]*W for _ in range(H)]
memory[x][y]=0
while True:
if len(que)==0:
break
h,w = que.popleft()
for i,k in directions:
x_new,y_new = h+i,w+k
if not(0<=x_new<=H-1) or not(0<=y_new<=W-1) :
continue
elif not memory[x_new][y_new]==-1 or S[x_new][y_new]=="#":
continue
memory[x_new][y_new] = memory[h][w]+1
que.append([x_new,y_new])
counter = max(counter,max(max(i) for i in memory))
print(counter)
| import sys
from collections import deque
H,W=map(int,input().split())
S=list(sys.stdin)
ans=0
for i in range(H):
for j in range(W):
if S[i][j]=='#':
continue
dist=[[-1]*W for _ in range(H)]
dist[i][j]=0
que=deque()
que.append((i,j))
while que:
i,j=que.popleft()
ans=max(ans,dist[i][j])
for ni,nj in (i-1,j),(i,j+1),(i+1,j),(i,j-1):
if not (0<=ni<H and 0<=nj<W):
continue
if S[ni][nj]=='#' or dist[ni][nj]!=-1:
continue
dist[ni][nj]=dist[i][j]+1
que.append((ni,nj))
print(ans)
| 1 | 94,361,818,308,640 | null | 241 | 241 |
a_b_c=input().split()
a=int(a_b_c[0])
b=int(a_b_c[1])
c=int(a_b_c[2])
count=0
yakusuu_list=[]
for i in range(1,c+1):
if c%i==0:
yakusuu_list.append(i)
for i in yakusuu_list:
if i in range(a,b+1):
count+=1
print(count)
| val = map(int,raw_input().split())
count = 0
for x in xrange(val[0], val[1] + 1):
pass
if val[2] % x == 0:
count+=1
print count | 1 | 557,059,486,600 | null | 44 | 44 |
n, k = map(int, input().split())
print(sum([i >= k for i in list(map(int,input().split()))])) | N, K = map(int, input().split())
H = list(map(int, input().split()))
print(len(list(filter(lambda x: x >= K, H)))) | 1 | 179,259,846,405,120 | null | 298 | 298 |
s = int(input())
if s >= 30:
print("Yes")
else:
print("No")
| x = int(input())
print("Yes") if x >= 30 else print("No") | 1 | 5,789,127,011,652 | null | 95 | 95 |
N = int(input())
A = [int(x) for x in input().split()]
cnt = [0 for x in range(N)]
for i in range(len(A)) :
cnt[A[i]-1] += 1
for i in range(N) :
print(cnt[i]) | import sys
for i in sys.stdin:
a, b = map(int, i.split())
p, q = max(a, b), min(a, b)
while True:
if p % q == 0:
break
else:
p, q = q, p % q
print("{} {}".format(q, int(a * b / q)))
| 0 | null | 16,210,033,061,150 | 169 | 5 |
op = 'a'
while op != '?':
a, op, b = input().split()
if op == '+':
print(int(a)+int(b))
elif op == '-':
print(int(a)-int(b))
elif op == '*':
print(int(a)*int(b))
elif op == '/':
print(int(a)//int(b))
else:
break
| def cal(a, op, b):
if op == '+':
r = a + b
elif op == '-':
r = a - b
elif op == '*':
r = a * b
else:
r = a / b
return r
while 1:
a,op,b = raw_input().split()
if op == '?':
break
else:
print(cal(int(a), op, int(b))) | 1 | 679,870,688,686 | null | 47 | 47 |
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
input:
15 6
1 2 7 8 12 50
output:
2
"""
import sys
def solve():
rec[0] = 0
for i in range(c_num):
for j in range(money - coins[i] + 1):
rec[j + coins[i]] = min(rec[j + coins[i]], rec[j] + 1)
return rec
if __name__ == '__main__':
_input = sys.stdin.readlines()
money, c_num = map(int, _input[0].split())
coins = list(map(int, _input[1].split()))
assert len(coins) == c_num
rec = [float('inf')] * (money + 1)
ans = solve()
print(ans[-1]) | inf=10**9
n,m=map(int,input().split())
C=list(map(int,input().split()))
DP=[inf]*(n+1)
DP[0]=0
for i in range(n+1):
for c in C:
if 0<=i+c<=n:
DP[i+c]=min(DP[i+c],DP[i]+1)
print(DP[n])
| 1 | 143,545,530,872 | null | 28 | 28 |
k = int(input())
a,b = map(int,input().split())
for i in range(1000):
if a <= k*i <= b:
print("OK")
exit()
elif b < k*i:
print("NG")
exit() | k = int(input())
a, b = map(int, input().split())
i = 1
ans = "NG"
while k*i <= b:
if a <= k*i:
ans = "OK"
break
i += 1
print(ans) | 1 | 26,622,464,560,780 | null | 158 | 158 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.