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
|
---|---|---|---|---|---|---|
n = int(input())
n3 = n**3
print(n3) | k = int(input())
s = input()
s = s if len(s) <= k else s[0:k] + '...'
print(s) | 0 | null | 10,029,586,831,456 | 35 | 143 |
n = int(input())
a = list(map(int, input().split()))
mod = 1000000007
def add(a, b):
return (a + b) % mod
def mul(a, b):
return (a * b) % mod
def pow(p, k):
ret = 1
b = p
while k > 0:
if k % 2 == 1:
ret = mul(ret, b)
b = mul(b, b)
k //= 2
return ret
def inv(p, k):
return pow(p, mod - k - 1)
lcm = {}
ps = []
for i in range(n):
ai = a[i]
p = 2
ps.append({})
while ai > 1:
if ai % p == 0:
ps[i][p] = 0
while ai % p == 0:
ps[i][p] += 1
ai //= p
lcm[p] = max(lcm.get(p, 0), ps[i][p])
p = p + 1 if p * p < ai else ai
lcmv = 1
for p in lcm:
lcmv = mul(lcmv, pow(p, lcm[p]))
ret = 0
for i in range(n):
prod = lcmv
for p in ps[i]:
prod = mul(prod, inv(p, ps[i][p]))
ret = add(ret, prod)
print(ret)
| a = input ()
numbers = map(int,raw_input().split())
numbers.reverse()
print ' '.join(map(str,numbers)) | 0 | null | 44,078,654,608,534 | 235 | 53 |
def main():
N = input_int()
S = input()
count = 1
for i in range(1, N):
if S[i-1] != S[i]:
count += 1
print(count)
def input_int():
return int(input())
# def input_int_tuple():
# return map(int, input().split())
# def input_int_list():
# return list(map(int, input().split()))
main()
| N = int(input())
a = list(input())
count = 1
for i in range(N):
if i>0:
if a[i-1]==a[i]:
pass
elif a[i-1]!=a[i]:
count+=1
print(count) | 1 | 170,600,442,607,720 | null | 293 | 293 |
def main():
n,k = map(int,input().split())
A = list(map(int,input().split()))
left = 0
right = max(A)
while abs(right-left)>1:
cent = (right+left)//2
ct = 0
for a in A:
ct+=(a-0.1)//cent
if ct <= k:
right=cent
else:
left=cent
print(right)
main() | N,K = map(int,input().split())
A = list(map(int,input().split()))
def f(n):
now = 0
for i in range(N):
now += (A[i]-1)//x
if now <= K:
return True
else:
return False
l = 0; r = 10**10
while r-l > 1:
x = (l+r)//2
if f(x):
r = x
else:
l = x
print(r) | 1 | 6,548,330,745,770 | null | 99 | 99 |
N, K, S = map(int, input().split())
INF = int(1e9)
if S == INF:
ans = [INF]*K + [INF-1]*(N-K)
else:
ans = [S]*K + [INF]*(N-K)
for e in ans:
print(e, end=" ") | debt = 100000.0
a = int(input())
for i in range(a):
debt = debt * 1.05
if(debt % 1000):
debt = (debt // 1000) * 1000 + 1000
print(int(debt))
| 0 | null | 45,603,247,557,820 | 238 | 6 |
import sys
input = sys.stdin.readline
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def main():
mod=10**9+7
N=I()
a=LI()
ALL=0
for i in range(N):
ALL=ALL^a[i]
ans=[0]*N
for i in range(N):
ans[i]=ALL^a[i]
print(' '.join(map(str, ans)))
main()
| n = int(input())
s = input()
total = 1
for c in 'RGB':
total *= s.count(c)
for i in range(1, n - 1):
for j in range(1, min(i + 1, n - i)):
if s[i] != s[i - j] and s[i - j] != s[i + j] and s[i] != s[i + j]:
total -= 1
print(total) | 0 | null | 24,315,008,610,852 | 123 | 175 |
n=int(input());print(str(n//3600)+":"+str((n//60)%60)+":"+str(n%60))
| N = int(input())
result = [0] * (N + 1)
for i in list(map(int, input().split())):
result[i] += 1
result.pop(0)
for r in result:
print(r)
| 0 | null | 16,518,352,972,320 | 37 | 169 |
def main():
h, n = map(int, input().split())
a = [int(x) for x in input().split()]
if h > sum(a):
print('No')
else:
print('Yes')
if __name__ == '__main__':
main() | n = str(input())
tmp = 0
for i in n:
tmp += int(i)
if tmp % 9 == 0:
print("Yes")
else:
print("No") | 0 | null | 41,244,009,350,180 | 226 | 87 |
a,b,c,k=map(int,open(0).read().split())
for i in' '*k:
if a>=b:b*=2
elif b>=c:c*=2
print('NYoe s'[a<b<c::2]) | a, b, c = map(int, input().split())
k = int(input())
p = "No"
for i in range(k):
if not(a < b and b < c):
if b <= a:
b = b * 2
else:
c = c * 2
if a < b and b < c:
p = "Yes"
print(p) | 1 | 6,917,720,604,612 | null | 101 | 101 |
from math import gcd
K = int(input())
sum = 0
for a in range(1, K+1):
for b in range(1, K+1):
p = gcd(a, b)
for c in range(1, K+1):
sum += gcd(p, c)
print(sum) | import numpy
a,b,x=map(int,input().split())
V=a*a*b
if x<=V/2:
y=2*x/b/a
theta=numpy.arctan(b/y)
print(theta*360/2/numpy.pi)
else:
x=V-x
y=2*x/a/a
theta=numpy.arctan(y/a)
print(theta*360/2/numpy.pi)
| 0 | null | 99,136,807,703,122 | 174 | 289 |
N,K=map(int,input().split())
A=list(map(int,input().split()))
a=0
b=10**9+1
while a+1<b:
mid=(a+b)//2
ans=0
for i in A:
ans+=(i-1)//mid
if K<ans:
a=mid
else:
b=mid
print(b) | n,k=list(map(int,input().split()))
alst=list(map(int,input().split()))
ok=max(alst)
ng=0
while abs(ok-ng)>1:
cen=(ok+ng)//2
cnt=0
for a in alst:
cnt+=(a+cen-1)//cen-1
if cnt<=k:
ok=cen
else:
ng=cen
print(ok) | 1 | 6,496,083,745,452 | null | 99 | 99 |
# Problem E - Dividing Chocolate
# input
H, W, K = map(int, input().split())
board = [['']*W for i in range(H)]
for i in range(H):
s = list(input())
for j in range(W):
board[i][j] = s[j]
# initialization
min_divide = 10**10
s = [0]*(H-1) # 横線の入り方 0:無 1:有
is_ok = True
# search
for i in range(2**(H-1)): # bit全探索
# sの初期化
h_count = 0
w_count = 0
for j in range(H-1):
if ((i>>j)&1):
s[j] = 1
h_count += 1
else:
s[j] = 0
# 列の全探索
s_score = [0]*H # 各区域のスコア
s_cur = [0]*H
for j in range(W):
c = 0
s_cur = [0]*H
for k in range(H):
if board[k][j]=='1':
s_cur[c] += 1
# Kを超えていないかのチェック
if s_cur[c]>K:
is_ok = False
break
# 次の遷移先(横線の有無でグループが別れる)
if k+1<H:
if s[k]==1:
c += 1
# Kを超えていたらループ中止
if not is_ok:
break
# 前の列のグループと足してみてKを超えていないかチェック
# 超えていれば縦線分割を施す
group_smaller = True
if j>0:
for c_num in range(c+1):
if s_score[c_num]+s_cur[c_num]>K:
group_smaller = False
else:
group_smaller = True
if group_smaller:
for c_num in range(c+1):
s_score[c_num] += s_cur[c_num]
else:
w_count += 1
for c_num in range(c+1):
s_score[c_num] = s_cur[c_num]
if not is_ok:
is_ok = True
continue
# for c_num in range(h_count+1):
# if s_score[c_num]>K:
# h_count = 10 ** 6
# 縦線と横線の合計でmin_divideを更新
min_divide = min(min_divide, w_count + h_count)
# output
print(min_divide)
| #!/usr/bin/env python3
import sys
# import math
# import re # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from collections import deque # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict # subclass of dict. defaultdict(facroty)
# from collections import Counter # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product # product(iter, repeat=n)
# from itertools import accumulate # accumulate(iter[, f])
# from functools import reduce # reduce(f, iter[, init])
# from functools import lru_cache # @lrucache ...arguments of functions should be able to be keys of dict
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy # to copy multi-dimentional matrix without reference
# from fractions import gcd # for Python 3.4
def main():
mod = 1000000007 # 10^9+7
inf = float('inf')
sys.setrecursionlimit(10**6) # 1000 -> 1000000
def input(): return sys.stdin.readline().rstrip()
def ii(): return int(input())
def mi(): return map(int, input().split())
def mi_0(): return map(lambda x: int(x)-1, input().split())
def lmi(): return list(map(int, input().split()))
def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
def li(): return list(input())
h, w, k = mi()
L = []
for _ in range(h):
L.append(list(map(int, li())))
L_trans = [[None] * h for _ in range(w)]
for i in range(h):
for j in range(w):
L_trans[j][i] = L[i][j]
d = 2 ** (h-1)
cost = [float('inf')] * d
for state in range(d):
bit_count = bin(state)[2:].count('1')
separated = [[0] * (bit_count + 1) for _ in range(w)]
for i in range(w):
current = 0
for j in range(h):
if j >= 1 and 1 << (j-1) & state:
current += 1
if L_trans[i][j]:
separated[i][current] += 1
previous = [0] * (bit_count + 1)
cnt = 0
# print(separated)
for i in range(w):
if any(map(lambda x: x > k, separated[i])):
break
if all(map(lambda x: x <= k, [elm + previous[ind] for ind, elm in enumerate(separated[i])])):
# print(f"just add: {previous} {separated[i]}")
for ind, elm in enumerate(separated[i]):
previous[ind] += elm # 追加
else:
cnt += 1
# print(f"count up: {previous} {separated[i]}")
for ind, elm in enumerate(separated[i]):
previous[ind] = elm # 上書き
else:
cost[state] = bit_count + cnt
# print(cost)
print(min(cost))
if __name__ == "__main__":
main()
| 1 | 48,800,714,105,738 | null | 193 | 193 |
N = int(input())
count = {}
max_count = 0
for _ in range(N):
s = input()
if s not in count:
count[s] = 0
count[s] += 1
max_count = max(max_count, count[s])
longest = []
for s, c in count.items():
if c == max_count:
longest.append(s)
longest.sort()
for s in longest:
print(s) | N = int(input())
S = [str(input()) for i in range(N)]
gocha = {}
for s in S:
gocha[s] = 1
print(len(gocha)) | 0 | null | 49,964,986,158,080 | 218 | 165 |
import string as st
string=[]
try:
while True:
s = input()#入力
string =list(string)#list変換
if not s :#空入力のときループぬける
break
string.extend(s)#list追加
string=map(str,string)
string="".join(string).lower()#str型変換と小文字
except EOFError:
for i in range(len(st.ascii_lowercase)):
print("{} : {}".format(st.ascii_lowercase[i],string.count(st.ascii_lowercase[i])))
| import sys
chash = {}
for i in range( ord( 'a' ), ord( 'z' )+1 ):
chash[ chr( i ) ] = 0
while True:
line = sys.stdin.readline().rstrip()
if not line:
break
for i in range( len( line ) ):
if line[i].isalpha():
chash[ line[i].lower() ] += 1
for i in range( ord( 'a' ), ord( 'z' )+1 ):
print( "{:s} : {:d}".format( chr( i ), chash[ chr( i ) ] ) ) | 1 | 1,638,218,806,312 | null | 63 | 63 |
import math
n = int(input())
a,b = 1,n
for i in range(1,int(math.sqrt(n)+1)):
if n%i == 0:
q = n//i
if abs(a-b) > abs(q-i):
a,b = i,q
print((a-1) + (b-1)) | N=int(input())
S=input()
a=ord("A")
z=ord("Z")
result=""
for i in range(len(S)):
word=ord(S[i])+N
if word>z:
word=word-z-1+a
x=chr(word)
result+=x
print(result)
| 0 | null | 148,504,375,878,508 | 288 | 271 |
def factorization(n):
res = []
tmp = n
for i in range(2, int(-(-n**0.5//1))+1):
if tmp % i == 0:
cnt = 0
while tmp % i == 0:
cnt += 1
tmp //= i
res.append([i, cnt])
if tmp!=1:
res.append([tmp, 1])
return res
N = int(input())
ans = 0
for tmp,cnt in factorization(N):
i = 1
while i<=cnt:
ans += 1
cnt-=i
i += 1
print(ans) | N = int(input())
def factorization(n):
arr = []
temp = n
for i in range(2, int(-(-n**0.5//1))+1):
if temp%i==0:
cnt=0
while temp%i==0:
cnt+=1
temp //= i
arr.append([i, cnt])
if temp!=1:
arr.append([temp, 1])
if arr==[]:
arr.append([n, 1])
return arr
def add(X):
counter = 0
while True:
if counter * (counter + 1) <= X * 2:
counter += 1
else:
counter -= 1
break
# print(X, counter)
return counter
facts = factorization(N)
answer = 0
for f in facts:
if f[0] != 1:
answer += add(f[1])
print(answer) | 1 | 16,904,583,245,760 | null | 136 | 136 |
n = int(input())
for i in range(n):
a,b,c = list(map(int, input().split()))
M = max([a,b,c])
result = False
if a == M:
result = (a * a == b * b + c * c)
elif b == M:
result = (b * b == a * a + c * c)
elif c == M:
result = (c * c == a * a + b * b)
if result:
print("YES")
else:
print("NO") | import bisect
N = int(input())
L = [int(n) for n in input().split()]
L = sorted(L)
total = 0
for i in range(N - 2):
a = L[i]
for j in range(i + 1, N - 1):
b = L[j]
right_endpoint = bisect.bisect_left(L, a+b, j)
total += right_endpoint - j - 1
print(total) | 0 | null | 85,556,412,198,838 | 4 | 294 |
list=list()
for i in range(10):
t=input()
list.append(int(t))
list.sort(reverse=True)
for i in range(3):
print(list[i]) | def qsort(l):
if l == []: return []
else:
pv = l[0]
left = []
right = []
for i in range(1, len(l)):
if l[i] > pv:
left.append(l[i])
else:
right.append(l[i])
left = qsort(left)
right = qsort(right)
left.append(pv)
return left + right
def main():
lst = []
for i in range(0, 10):
lst.append(int(raw_input()))
lst = qsort(lst)
for i in range(0, 3):
print(lst[i])
main() | 1 | 22,441,828 | null | 2 | 2 |
N = int(input())
S = input()
rgb = [0]*3
for i in range(N):
if S[i] == "R":
rgb[0] += 1
elif S[i] == "G":
rgb[1] += 1
else:
rgb[2] += 1
ans = 0
for i in range(N):
for h in range(N):
j = i+h
k = i+2*h
if k >= N:
break
if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
ans += 1
print(rgb[0]*rgb[1]*rgb[2]-ans)
| n,m,q=map(int,input().split())
A=[]
B=[]
C=[]
D=[]
for i in range(q):
a,b,c,d=map(int,input().split())
A.append(a)
B.append(b)
C.append(c)
D.append(d)
ans=0
#print(A)
#print(B)
#print(C)
#print(D)
#mCn
def dfs(l):
global ans # UnboundLocalError: local variable 'ans' referenced before assignment
if len(l)==n+1:
#print(l)
tmp=0
for i in range(q):
#print(l[B[i]],l[A[i]],C[i])
if l[B[i]]-l[A[i]]==C[i]:
tmp+=D[i]
ans=max(ans,tmp)
return
x=l[len(l)-1]
while x<=m:
y=l[:]
y.append(x)
dfs(y)
x+=1
dfs([1])
print(ans)
| 0 | null | 32,000,621,209,820 | 175 | 160 |
n = int(input())
graph = [[] for _ in range(n)]
for i in range(n):
in_list = list(map(int, input().split()))
u = in_list[0]
graph[u - 1] = in_list[2:]
d = [0 for _ in range(n)]
f = [0 for _ in range(n)]
time = 0
def dfs(now, prev, graph, d, f):
if d[now] != 0:
return d, f
global time
time += 1
d[now] = time
if not graph[now]:
f[now] = time + 1
time += 1
return
for k in graph[now]:
if k - 1 == prev or d[k-1] !=0:
continue
dfs(k - 1, now, graph, d, f)
else:
time += 1
f[now] = time
return d, f
for i in range(n):
d, f = dfs(i, 0, graph, d, f)
print(i+1, d[i], f[i])
| n=int(input())
G=[]
for i in range(n):
L=list(map(int,input().split()))
G.append(L[2:])
for j in range(len(G[-1])):
G[-1][j]-=1
Forder=[-1]*n
Lorder=[-1]*n
ptr=1
def dfs(v):
#print(v)
#print(G[v])
#print()
global ptr
Forder[v]=ptr
ptr+=1
for next in G[v]:
if Forder[next]!=-1:
continue
dfs(next)
Lorder[v]=ptr
ptr+=1
#while True:
# #print(Forder,Lorder)
# for i in range(n):
# if Forder[i]!=-1 and Lorder[i]!=-1:
# pass
# else:
# dfs(i)
# continue
#
# if i==n-1:
# break
# else:
# continue
# break
#
#for i in range(n):
# print(i+1,Forder[i],Lorder[i])
##########
for i in range(n):
if Forder[i]==-1 or Lorder[i]==-1:
dfs(i)
for i in range(n):
print(i+1,Forder[i],Lorder[i])
| 1 | 2,715,267,192 | null | 8 | 8 |
n = int(input())
robot = [0]*n
for i in range(n):
x,l = map(int,input().split())
robot[i] = (x+l, x-l)
robot.sort()
#print(robot)
ans = 1
right = robot[0][0]
for i in range(1,n):
if right <= robot[i][1]:
right = robot[i][0]
ans += 1
print(ans) |
fibo_list=[0 for i in range(48)]
def fibo(n):
f=fibo_list[n]
if f:
return f
else:
if n==0 or n==1:
return 1
else:
f=fibo(n-1)+(fibo(n-2))
fibo_list[n]=f
return f
n=input()
print(fibo(n)) | 0 | null | 44,997,408,669,070 | 237 | 7 |
def getN():
return int(input())
def getNM():
return map(int, input().split())
def getList():
return list(map(int, input().split()))
def getArray(intn):
return [int(input()) for i in range(intn)]
def input():
return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
ns = []
while len(ns) < rantime:
n = random.randint(ran1, ran2)
if not n in ns:
ns.append(n)
return sorted(ns)
def rand_query(ran1, ran2, rantime):
r_query = []
while len(r_query) < rantime:
n_q = rand_ints_nodup(ran1, ran2, 2)
if not n_q in r_query:
r_query.append(n_q)
return sorted(r_query)
from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right
import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7
#############
# Main Code #
#############
N = getN()
divisors = []
def make_divisors(n):
for i in range(1, int(math.sqrt(n)) + 1):
a, b = 0, 0
if n % i == 0:
a = i
b = n // i
divisors.append([a, b])
make_divisors(N)
ans = float('inf')
for i in divisors:
a, b = i
ans = min(ans, a + b - 2)
print(ans) | from __future__ import division, print_function
from sys import stdin
word = stdin.readline().rstrip().lower()
cnt = 0
for line in stdin:
if line.startswith('END_OF_TEXT'):
break
cnt += line.lower().split().count(word)
print(cnt) | 0 | null | 81,911,326,241,668 | 288 | 65 |
def m(L,R):
global c;c+=len(L)+len(R)
T=[];j=0
for l in L:
while j<len(R)and R[j]<l:T+=[R[j]];j+=1
T+=[l]
while j<len(R):T+=[R[j]];j+=1
return T
def d(A):s=len(A)//2;return m(d(A[:s]),d(A[s:])) if len(A)>1 else A
c=0
input()
print(*d(list(map(int,input().split()))))
print(c)
| N =int(input())
A = sorted(list(map(int,input().split())))
B = 1
C = 10 ** 18
for i in range(N):
B = B * A[i]
if B == 0:
break
elif B > C:
B = -1
break
print(B)
| 0 | null | 8,190,506,456,480 | 26 | 134 |
x = input()
print(int(x)*int(x)*int(x)) | x = input()
if 1 <= x <= 100:
print(x*x*x) | 1 | 275,916,952,612 | null | 35 | 35 |
N = int(input())
A = list(map(int, input().split()))
if N == 0 and A[0] == 1:
print(1)
exit()
if A[0] != 0:
print(-1)
exit()
sum_leaf = sum(A)
ans = 1
before_top = 1
for i in range(1, len(A)):
if A[i] <= before_top*2:
ans += min(sum_leaf, before_top*2)
before_top = min(sum_leaf, before_top*2) - A[i]
sum_leaf -= A[i]
else:
print(-1)
exit()
print(ans) | n,m=map(int,input().split())
ans=["#"]*n
for _ in range(m):
s,c=map(int,input().split())
# 同じ桁に複数の指示が飛んできたら狩猟
if not ans[s-1] in["#",c]:
print(-1)
exit()
ans[s-1]=c
# nが一桁の時の対応
if len(ans)==1:
print(0 if ans[0]=="#" else ans[0])
exit()
#頭の数字について
if ans[0]==0:
print(-1)
exit()
if ans[0]=="#":
ans[0]=1
for num in ans:
print(num if num!="#" else 0,end="")
| 0 | null | 39,686,482,958,558 | 141 | 208 |
H,W = map(int,input().split())
if((H != 1)and(W != 1)):
cnt1 = ((H+1)//2)*((W+1)//2)
cnt2 = (H//2)*(W//2)
ans = cnt1 + cnt2
else:
ans = 1
print(ans) | H, W = map(int, input().split())
if min(H,W) == 1:
print(1)
elif H*W % 2 == 0:
print(int(H*W/2))
else:
print(int(H*W/2)+1)
| 1 | 50,632,751,303,102 | null | 196 | 196 |
tmp = int(input())
if tmp>=30:
print("Yes")
else:
print("No") | def my_eval(ar,str):
res = True
n = len(str)
# print(n)
# print("start")
for i in range(n):
# print(i)
if(ar[str[i][0]] == 1):
# print(str[i][0])
# print(str[i][1])
# print(str[i][2])
# print(ar[str[i][1]-1])
# print(ar[str[i][1]-1] == str[i][2])
# print(ar)
# print()
if(ar[str[i][1]] != str[i][2]):
res = False
# print("end")
# print()
return res
if __name__ == "__main__":
# 全探索
n = int(input())
str = []
for i in range(n):
a = int(input())
for j in range(a):
x = list(map(int,input().split()))
x.insert(0,i+1)
str.append(x)
ar = [0] * (n+1)
res = 0
# print(str)
count = 0
for i in range(2**n):
count = 0
for j in range(n):
if(i >> j & 1 == 1):
ar[j+1] = 1
count += 1
else:
ar[j+1] = 0
# print(ar)
if(my_eval(ar,str)):
res = max(res,count)
print(res)
| 0 | null | 63,760,751,222,138 | 95 | 262 |
n = int(raw_input())
s = ''
for i in range(1,n+1):
if (i % 3) == 0:
s = s + ' ' + str(i)
else:
x = i
while True:
if (x % 10) == 3:
s = s + ' ' + str(i)
break
x = x / 10
if x == 0:
break
print s |
N=int(raw_input())
s=[int(raw_input()) for x in range(N)]
def is_prime(n):
i = 2
while i * i <=n:
if n % i == 0:
return False
i += 1
return True
a=filter(is_prime,s)
print len(a) | 0 | null | 475,979,278,928 | 52 | 12 |
r = float(input())
pi = 3.141592653589
S = r * r * pi
L = 2 * r * pi
print(str(S) + " " + str(L)) | #!/usr/bin/env python3
D = int(input())
c = list(map(int, input().split()))
s = []
for d in range(D):
s.append(list(map(int, input().split())))
def get_objective_function(output):
objective_function = 0
last = [[-1 for i in range(26)] for d in range(D)]
for d in range(D):
objective_function += s[d][output[d]]
last[d][output[d]] = d
if d < D-1:
for i in range(26):
last[d+1][i] = max(last[d][i], last[d+1][i])
for i in range(26):
objective_function -= c[i] * (d-last[d][i])
print(objective_function)
point = max(10 ** 6 + objective_function, 0)
## outputの作成
# IOに基づくパターン
output = []
for _ in range(D):
output.append(int(input())-1)
# 最大効用での戦略
#output = []
#for d in range(D):
# output.append(s[d].index(max(s[d])))
#for d in output:
# print(d+1)
## 目的関数の確認
get_objective_function(output) | 0 | null | 5,325,966,341,882 | 46 | 114 |
while True:
m, f, r = (int(x) for x in input().split())
if (m, f, r) == (-1, -1, -1):
break
sum_score = m + f
if m == -1 or f == -1:
print("F")
elif sum_score >= 80:
print("A")
elif 65 <= sum_score < 80:
print("B")
elif 50 <= sum_score < 65:
print("C")
elif 30 <= sum_score < 50:
print("C") if r >= 50 else print("D")
else:
print("F") | #coding: utf-8
while True:
m, f, r = (int(i) for i in input().split())
if m == f == r == -1:
break
if m == -1 or f == -1:
print("F")
elif m + f >= 80:
print("A")
elif m + f >= 65 and m + f < 80:
print("B")
elif (m + f >= 50 and m + f < 65) or r >= 50:
print("C")
elif m + f >= 30 and m + f < 50:
print("D")
elif m + f < 30:
print("F")
| 1 | 1,238,529,908,198 | null | 57 | 57 |
K=int(input())
S=input()
l=[]
if len(S)<=K:
print(S)
else:
for i in range(K):
l.append(S[i])
print("".join(l)+'...') | k=int(input())
n=input()
x=len(n)
if(x>k):
print(n[0:k]+"...")
else:
print(n) | 1 | 19,580,164,109,530 | null | 143 | 143 |
import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])
n = inp()
P = inpl()
min = 10**5 * 2 + 10
cnt = 0
for p in P:
if min >= p:
min = p
cnt += 1
print(cnt) | n=int(input())
l=list(map(int,input().split()))
prod=0
for i in range(n):
for j in range(i+1,n):
prod=prod+(l[i]*l[j])
print(prod)
| 0 | null | 126,971,195,659,950 | 233 | 292 |
K = str(input())
print(K[0:3]) | N,K=map(int,input().split())
H=list(map(int, input().split()))
#Nモンスターの数、K必殺回数(モンスターは体力ゼロになる)、Hモンスターの数と各々の体力
H=sorted(H)
if K>=len(H):
print(0)
else:
for i in range(0,K):
del H[-1]
result=sum(H)
print(result) | 0 | null | 46,728,336,186,140 | 130 | 227 |
from math import gcd
N = int(input())
A = list(map(int,input().split()))
def lcm(a,b):
return a*b//gcd(a,b)
lcm_a = 1
for i in A:
lcm_a = lcm(lcm_a,i)
ans = 0
for i in A:
ans += lcm_a//i
print(ans%(10**9+7))
| import math
n=int(input())
ans=0
num=int(math.sqrt(n)+1)
for i in range(1,num)[::-1]:
if n%i==0:
ans=i+(n//i)-2
break
print(ans) | 0 | null | 124,558,588,509,420 | 235 | 288 |
s , t = map(str, input().strip().split())
print(t+s) | s1,s2=map(str,input().split(' '))
print(s2+s1) | 1 | 102,795,912,308,208 | null | 248 | 248 |
def resolve():
S = input()
print("No" if S in ["AAA", "BBB"] else "Yes")
if '__main__' == __name__:
resolve() | from decimal import Decimal
T = tuple(map(Decimal, input().split()))
A = list(map(Decimal, input().split()))
B = list(map(Decimal, input().split()))
ans = 0
if A[0] < B[0]:
tmp = (A[0], A[1])
A[0], A[1] = B[0], B[1]
B[0], B[1] = tmp[0], tmp[1]
a = abs(T[0]*A[0] - T[0]*B[0])
b = T[0]*(B[0]-A[0])+T[1]*(B[1]-A[1])
if b == 0:
print("infinity")
elif b < 0:
print(0)
exit(0)
else:
ans += 1
if b > a:
print(1)
elif b == a:
print("infinity")
else:
if a % b == 0:
print((a//b)*2)
else:
print((a//b)*2 + 1)
| 0 | null | 92,758,558,005,152 | 201 | 269 |
l = input()
stack1 = []
stack2 = []
all_area = 0
for val in range(len(l)):
if l[val] == "\\":
stack1.append(val)
elif l[val] == "/" and stack1 != []:
temp = stack1.pop(-1)
all_area = all_area + (val - temp)
each_area = val - temp
while stack2 != [] and stack2[-1][0] > temp:
each_area = each_area + stack2.pop(-1)[1]
stack2.append([temp, each_area])
else:
pass
print(all_area)
print(len(stack2), end="")
for i in range(len(stack2)):
print(" ", end="")
print(stack2[i][1],end="")
print("")
| import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque
import copy
sys.setrecursionlimit(10000000)
ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]
iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]
lcm = lambda x, y: (x * y) // math.gcd(x, y)
MOD = 10 ** 9 + 7
MAX = float('inf')
def calc_water(u, l, h):
return ((u + l) * h) // 2
def main():
if os.getenv("LOCAL"):
sys.stdin = open("input.txt", "r")
S = iss()
stack = []
water = []
sum = 0
for i in range(len(S)):
s = S[i]
if s == '\\':
stack.append(i)
elif s == '/' and len(stack) > 0:
j = stack.pop()
sum += i - j
area = i - j
while len(water) > 0 and water[-1][0] > j:
w = water.pop()
area += w[1]
water.append([j, area])
ret = []
for i, w in water:
ret.append(w)
print(sum)
print(len(ret), *ret)
if __name__ == '__main__':
main()
| 1 | 59,931,789,878 | null | 21 | 21 |
ans = ''
r, c = map(int, input().split(' '))
i = 0
L = [0] * (c + 1)
while i < r:
a = list(map(int, input().split(' ')))
atot = 0
j = 0
while j < c:
atot += a[j]
L[j] += a[j]
j += 1
ans += ' '.join(map(str, a)) + ' ' + str(atot) + '\n'
L[c] += atot
i += 1
if ans != '':
ans += ' '.join(map(str, L))
print(ans)
| r_c_str=input().split()
r_c=list(map(lambda i :int(i),r_c_str))
r=r_c[0]
c=r_c[1]
s_str=[input() for i in range(r)]
s_str=[i.split() for i in s_str]
s=[]
for i in s_str:
s.append(list(map(lambda j :int(j),i)))
for i in range(r):
s[i].append(sum(s[i]))
s.append([])
for i in range(c+1):
s[-1].append(0)
for i in range(c):
for j in range(r):
s[r][i]+=s[j][i]
s[-1][-1]+=sum(s[r])
for i in s:
print(*i)
| 1 | 1,358,083,786,528 | null | 59 | 59 |
x1, y1, x2, y2 = map(float,input().split())
r = ((x1-x2)**2+(y1-y2)**2)**.5
print("{:.8f}".format(r))
| import sys
alphabet = ['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', 'z']
cnt = 26 * [0]
Input = ""
loop = True
#while loop:
# I = input()
# if not I:
# loop = False
# Input += I
for I in sys.stdin:
Input += I
for i1 in range(len(alphabet)):
for i2 in range(len(Input)):
if 'A' <= Input[i2] <= 'Z':
w = Input[i2].lower()
else:
w = Input[i2]
if alphabet[i1] == w:
cnt[i1] += 1
print(alphabet[i1] + " : " + str(cnt[i1])) | 0 | null | 918,628,825,410 | 29 | 63 |
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
????§???¢
????§???¢????????? a, b ??¨?????????????§? C ?????????
??????????§???¢?????¢??? S?????¨????????? L,
a ???????????¨????????¨???????????? h
????±???????????????°?????????????????????????????????
"""
import math
a, b, C = map(float,input().strip().split())
theta = math.radians(C) # ?????????????????¢??????
h = math.sin(theta) * b
S = a * h / 2
a1 = math.cos(theta) * b
a2 = a - a1
x = math.sqrt((h * h) + (a2 * a2))
L = a + b + x
print(S)
print(L)
print(h) | a,b,c = [int(x) for x in input().split()]
import math
si = math.sin(math.radians(c))
co = math.cos(math.radians(c))
s = a*b*si/2
l = a + b + (a**2 + b**2 - 2*a*b*co)**(1/2)
h = 2*s/a
print("{:.6f}".format(s))
print("{:.6f}".format(l))
print("{:.6f}".format(h))
| 1 | 176,867,901,540 | null | 30 | 30 |
import sys
read = sys.stdin.buffer.read
input = sys.stdin.readline
input = sys.stdin.buffer.readline
#sys.setrecursionlimit(10**9)
#from functools import lru_cache
def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode('utf-8')
#2325
#import numpy as np
import math
def main():
a,b,x=MI()
k=0
if b/2<=x/a**2:
k=2/a*(b-x/a**2)
else:
k=a*b**2/(2*x)
print(math.degrees(math.atan(k)))
if __name__ == "__main__":
main() | N,M = map(int ,input().split())
S = input()
ans = []
i = N
while i > 0:
prev = i
for j in range(max(0, i-M), i):
if S[j] == "0":
ans.append(str(i-j))
i = j
break
if i == prev:
ans = -1
break
if ans == -1:
print(ans)
else:
ans.reverse()
print(*ans) | 0 | null | 151,769,401,434,948 | 289 | 274 |
while 1:
a, op, b = input().split()
a = int(a)
b = int(b)
if op == '?': break
if op == '+': print(a + b)
if op == '-': print(a - b)
if op == '*': print(a * b)
if op == '/': print(a // b) | # def merge(arr, l, mid, r):
# L = [arr[i] for i in range(l, mid)]
# R = [arr[i] for i in range(mid, r)]
# L.append(int(1e9 + 10))
# R.append(int(1e9 + 10))
# i, j = 0, 0
# cnt = 0
# for k in range(l, r):
# if L[i] <= R[j]:
# arr[k] = L[i]
# i += 1
# else:
# arr[k] = R[j]
# j += 1
# cnt += 1
# return cnt
# def mergeSort(arr, l, r):
# cnt = 0
# if l + 1 < r:
# mid = (l + r) >> 1
# cnt += mergeSort(arr, l, mid)
# cnt += mergeSort(arr, mid, r)
# cnt += merge(arr, l, mid, r)
# return cnt
# triky
def count(l, r):
cnt = 0
if l + 1 < r:
mid = (l + r) >> 1
cnt += count(l, mid)
cnt += count(mid, r)
cnt += r - l
return cnt
cnt = count(0, int(input()))
arr = list(map(int, input().split()))
arr.sort()
print(*arr)
print(cnt)
| 0 | null | 404,107,770,636 | 47 | 26 |
a,b = map(int,input().split())
if a<=b:
[print(a,end="") for _ in range(b)]
else:
[print(b,end="") for _ in range(a)]
| a,b=input().split()
c = str(a)*int(b)
d = str(b)*int(a)
if a<b:
print(c)
else:
print(d) | 1 | 84,412,211,993,372 | null | 232 | 232 |
str_search = input().upper()
int_cnt = 0
len_search = len(str_search)
while True:
str_line = input()
if str_line == "END_OF_TEXT":
break
str_line = str_line.upper()
int_cnt = int_cnt + str_line.split().count(str_search)
print(str(int_cnt)) | import sys
W = sys.stdin.readline().strip()
num = 0
while True:
T = sys.stdin.readline().strip()
if T == 'END_OF_TEXT':
break
t = T.lower()
T_line = t.split()
for i in T_line:
if W == i:
num += 1
print(num)
| 1 | 1,838,941,657,696 | null | 65 | 65 |
import sys
import heapq
from decimal import Decimal
input = sys.stdin.readline
a, b, c = map(str, input().split())
root_a = Decimal(a)**Decimal('0.5')
root_b = Decimal(b)**Decimal('0.5')
root_c = Decimal(c)**Decimal('0.5')
if root_a + root_b < root_c:
print("Yes")
else:
print("No") | print(int(input().strip('\n'))**2) | 0 | null | 98,513,486,607,700 | 197 | 278 |
N = str(input())
bruh = 0
for i in N :
bruh += int(i)
if bruh %9 == 0 :
print ("Yes")
else :
print ("No")
| count = input()
#print(len(count))
num = 0
for i in range(len(count)):
num += int(count[i])
if num % 9 == 0:
print("Yes")
else:
print("No") | 1 | 4,445,488,910,720 | null | 87 | 87 |
N, M = map(int, input().split())
a = list(map(int, input().split()))
for k in range(N):
a[k] //= 2
foo = 1
while a[0]%2 == 0:
foo *= 2
a[0] //= 2
for k in range(1, N):
if a[k] % foo == 0 and a[k]%(2*foo) !=0:
a[k] //= foo
continue
else:
print(0)
exit()
ans = 0
for odd in [3, 5, 7, 11]:
flag = False
for k in range(N):
if a[k]%odd == 0:
a[k] //= odd
flag = True
if flag:
foo *= odd
def euclid(a, b):
while b:
a, b = b, a%b
return a
lcm = a.pop()
for k in range(1, N):
b = a.pop()
lcm = lcm * b // euclid(lcm, b)
if lcm* foo > M:
print(0)
exit()
lcm *= foo
ans = int((M / lcm -1)//2 + 1)
print(ans)
| x, n = map(int, input().split())
p = sorted(list(map(int, input().split())))
a = 100
b = 0
for i in range(0, 102):
if i not in p and abs(x - i) < a:
a = abs(x - i)
b = i
print(b)
| 0 | null | 58,140,188,034,968 | 247 | 128 |
n, k = map(int, input().split())
a_nums = list(map(int, input().split()))
f_point = sum(a_nums[:k])
for i in range(n - k):
if a_nums[i] < a_nums[i + k]:
print("Yes")
else:
print("No") | val = input()
valf=val[-1]
if(valf=="s"):
print(val+"es")
else:
print(val+"s") | 0 | null | 4,732,501,008,190 | 102 | 71 |
count = int(input())
point = {'taro': 0, 'hanako': 0}
for i in range(count):
(taro, hanako) = [s for s in input().split()]
if (taro > hanako) - (taro < hanako) == 0:
point['taro'] += 1
point['hanako'] += 1
elif (taro > hanako) - (taro < hanako) > 0:
point['taro'] += 3
else:
point['hanako'] += 3
print(point['taro'], point['hanako']) | s = input()
ans = [0 for i in range(len(s)+1)]
for i in range(len(s)):
if s[i] == '<':
ans[i+1] = max(ans[i+1],ans[i]+1)
for i in range(len(s)-1,-1,-1):
if s[i] == '>':
ans[i] = max(ans[i],ans[i+1]+1)
print(sum(ans))
| 0 | null | 78,943,739,337,188 | 67 | 285 |
N = int(input())
kotae = []
for i in range(1,N+1):
for j in range(1,N+1):
for k in range(1,N+1):
s = i
t = j
u = k
x = 1
while x != 0:
v = t%s
if v != 0:
t = s
s = v
else:
t = s
x = u%t
if x != 0:
u = t
t = x
else:
kotae.append(t)
print(sum(kotae)) | N = int(input())
A = []
B = []
for i in range(N):
a, b = map(int, input().split())
A.append(a)
B.append(b)
A.sort()
B.sort()
if N % 2 == 1:
A_median = A[N // 2]
B_median = B[N // 2]
print(B_median - A_median + 1)
else:
A_median2 = A[(N - 1) // 2] + A[N // 2]
B_median2 = B[(N - 1) // 2] + B[N // 2]
print(B_median2 - A_median2 + 1) | 0 | null | 26,467,138,991,870 | 174 | 137 |
# -*- coding: utf-8 -*-
import sys
from math import ceil
for line in sys.stdin.readlines():
List = map(int, line.strip().split())
n = List[0]
yen = 100000
for i in xrange(n):
yen *= 1.05
yen = int(ceil(yen/1000)) * 1000
print yen | a = 100000
b = 1000
for i in range(input()):
a *= 1.05
if a % b > 0:
a = a - a % b + b
print int(a) | 1 | 1,312,188,858 | null | 6 | 6 |
k=int(input())
count=1
num=7
for _ in range(k):
if num%k == 0:
print(count)
break
else:
count += 1
num = (num % k)*10 + 7
else:
print(-1) | def gcd(n, m):
if m == 0:
return n
return gcd(m, n % m)
N = int(input())
A = list(map(int,input().split()))
mod = 10**9+7
kbs = A[0]
for i in range(1,N):
kbs = kbs*A[i]//gcd(kbs,A[i])
kbs %= mod
ans = 0
for i in range(N):
ans += pow(A[i],mod-2,mod)
ans %= mod
print(kbs*ans%mod) | 0 | null | 47,108,453,932,482 | 97 | 235 |
n = int(input())
ans = 0
for a in range(1, n+1):
b=1
while n-a*b>0:
ans += 1
b+=1
print(ans)
| import sys
input = sys.stdin.buffer.readline
N = int(input())
ans = 0
for a in range(1, N+1):
maxb = (N-1)//a
ans += maxb
print(ans) | 1 | 2,603,275,550,238 | null | 73 | 73 |
print("bust" if sum(map(int, input().split())) > 21 else "win")
| import numpy as np
import scipy as sp
import math
a, b, c = map(int, input().split())
d = a + b + c
if(d<22):
print("win")
else:
print("bust") | 1 | 118,953,568,856,892 | null | 260 | 260 |
x = int(input())
def sanjo(x):
return x**3
print(sanjo(x)) | import bisect
def roller_coaster(n, k, hli):
hli.sort()
lenght = len(hli)
ans = lenght - bisect.bisect_left(hli, k)
return ans
def main():
n, k = map(int, input().split())
hli = list(map(int, input().split()))
print(roller_coaster(n, k, hli))
if __name__ == '__main__':
main() | 0 | null | 89,606,917,050,572 | 35 | 298 |
a = [int(c) for c in input().split()]
r = a[0]*a[1]
if a[0] == 1 or a[1] == 1:
print(1)
elif r % 2 == 0:
print(int(r/2))
else:
print(int(r/2+1))
| H,W = map(int, input().split())
if H == 1 or W == 1:
print(1)
else:
t = H * W
print(t // 2) if t % 2 == 0 else print((t // 2) + 1) | 1 | 50,803,632,590,600 | null | 196 | 196 |
from collections import Counter
n, p = map(int, input().split())
s = input()
ans = 0
if p in {2, 5}:
lst = set(i for i in range(0, 10, p))
for i, num in enumerate(s):
if int(num) in lst:
ans += i + 1
else:
num = [int(s[-1]) % p]
for i in range(1, len(s)):
tmp = num[-1] + pow(10, i, p) * int(s[-i - 1])
num.append(tmp % p)
mod = [1] + [0] * (p - 1)
for i in num:
ans += mod[i]
mod[i] += 1
print(ans)
| from collections import defaultdict
N, P = map(int, input().split())
S = input().strip()[::-1]
if P in [2, 5]:
ans = 0
for r in range(N):
if int(S[r]) % P == 0:
ans += N - r
print(ans)
exit()
cum = [0] * (N + 1)
for i in range(N):
now = int(S[i]) * pow(10, i, P)
cum[i + 1] = (cum[i] + now) % P
cnt = defaultdict(int)
for _cum in cum:
cnt[_cum] += 1
ans = 0
for k, v in cnt.items():
ans += v * (v - 1) // 2
print(ans)
| 1 | 58,120,924,652,750 | null | 205 | 205 |
import math
if __name__ == "__main__":
r = float(input())
print("%.6f %.6f"%(math.pi*r**2,math.pi*2*r)) | import math
r = float(raw_input())
print '%.5f %.5f' % (r*r*math.pi, 2*r*math.pi) | 1 | 628,175,165,110 | null | 46 | 46 |
K = int(input())
A, B = [int(i) for i in input().split(' ')]
for i in range(A, B+1):
if i % K == 0:
print('OK')
exit()
print('NG')
| N = int(input())
RMax = 0
R = []
for i in range(N):
r = int(input())
if i == 0:
rmi = r
if i == 1:
RMax = r - R[0]
if i > 0:
rdif = (r - rmi)
if rdif >= RMax:
RMax = rdif
R.append(r)
if r < rmi:
rmi = r
print(RMax) | 0 | null | 13,244,607,716,792 | 158 | 13 |
import sys
# input = sys.stdin.readline
def main():
N = int(input())
d = list(map(int,input().split()))
ans = 0
for i in range(N):
for j in range(N):
if i !=j:
ans += d[i]*d[j]
print(int(ans/2))
if __name__ == "__main__":
main() | n = str(input())
if '7' in n :
print('Yes')
if '7' not in n :
print('No') | 0 | null | 101,465,110,905,312 | 292 | 172 |
s = input()
if s.replace('hi', '') == '':
print('Yes')
else:
print('No') | import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
import numpy as np
def main():
n = int(input())
if n == 1:
print(1)
sys.exit()
divs = np.arange(1, n + 1)
divs2 = n // divs
divs3 = divs2 * (divs2 + 1) // 2
divs3 = divs3 * divs
r = divs3.sum()
print(r)
if __name__ == '__main__':
main()
| 0 | null | 32,214,473,924,708 | 199 | 118 |
import os, sys, re, math
A = [int(n) for n in input().split()]
print('win' if sum(A) <= 21 else 'bust')
| import math
k = int(input())
wa = 0
aa = 0
for i in range(1,k+1):
for j in range(1,k+1):
aa =math.gcd(i,j)
for l in range(1,k+1):
wa +=math.gcd(aa,l)
print(wa) | 0 | null | 76,803,857,048,870 | 260 | 174 |
N,K = map(int,input().split())
P = list(map(int,input().split()))
# 累積和
s = [0] * (N+1)
for i in range(N):# O(N)
s[i+1] = s[i] + P[i]
# [j,j+K) の和の最大値と j を保持
m = 0
midx = 0
for j in range(N-K+1):# O(N)
v = s[j+K] - s[j]
if v > m:
m = v
midx = j
E = 0
for k in range(midx,midx+K):# O(K)
x = P[k]
E += (1/x)*(x*(x+1)/2)
print(E) | import sys
s = ''
for line in sys.stdin:
s += line
s = s.lower()
count = {letter: s.count(letter) for letter in set(s)}
for c in range(97,97+26):
if chr(c) in count:
print("%c : %d" % (chr(c), count[chr(c)]))
else:
print("%c : 0" % chr(c)) | 0 | null | 38,379,078,068,352 | 223 | 63 |
n,m=map(int,input().split())
a =map(int,input().split())
x = sum(a)
if x > n:
print('-1')
else:
print(n-x) | def mlt(): return map(int, input().split())
x, a, b = mlt()
dp = [0 for n in range(x)]
for n in range(1, x+1):
for k in range(n+1, x+1):
d1 = k-n
d2 = abs(a-n)+1+abs(b-k)
ds = min(d1, d2)
dp[ds] += 1
print(*dp[1:], sep='\n')
| 0 | null | 38,194,914,626,782 | 168 | 187 |
import sys
def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))
def RN(N): return [input().strip() for i in range(N)]
def main():
N, M = MI()
if N == M:
print("Yes")
else:
print("No")
if __name__ == "__main__":
main() | print("Yes" if len(set(map(int,input().split())))==1 else "No") | 1 | 83,488,405,198,352 | null | 231 | 231 |
list = []
n = int(raw_input())
list = map(int, raw_input().split(' '))
list.reverse()
for i in range(len(list)):
print list[i], | # -*- coding: utf-8 -*-
n = int(raw_input())
num = map(int, raw_input().split())
for e in num[::-1]:
if e == num[0]:
print e
break
print e, | 1 | 996,045,955,772 | null | 53 | 53 |
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
n,x,y=nii()
x-=1
y-=1
ans=[0 for i in range(n)]
for i in range(n-1):
for j in range(i+1,n):
dist1=j-i
dist2=abs(i-x)+1+abs(j-y)
dist=min(dist1,dist2)
ans[dist]+=1
for i in ans[1:]:
print(i) | from collections import deque
n, x, y = map(int, input().split())
g = [[] for _ in range(n)]
# make graph
for i in range(n - 1):
g[i].append(i + 1)
g[i + 1].append(i)
g[x - 1].append(y - 1)
g[y - 1].append(x - 1)
def bfs(g, n_node, start_node):
dist = [-1] * n_node
dist[start_node] = 0
queue = deque([start_node])
while queue:
node = queue.popleft()
for n in g[node]:
if dist[n] != -1:
continue
dist[n] = dist[node] + 1
queue.append(n)
return dist
ans_array = [0] * n
for i in range(n):
dist = bfs(g, n, i)
for d in dist:
ans_array[d] += 1
for i in ans_array[1:]:
print(i // 2) | 1 | 44,009,947,364,680 | null | 187 | 187 |
x, y=map(int, input().split())
s=0
if (x==3): s+=100000
if (x==2): s+=200000
if (x==1): s+=300000
if (y==3): s+=100000
if (y==2): s+=200000
if (y==1): s+=300000
if (s==600000): s+=400000
print(s) | x, y = map(int, input().split())
ans = 0
for i in [x, y]:
if i <= 3:
ans += 4 - i
if x == 1 and y == 1:
ans += 4
print(ans * 100000) | 1 | 140,414,652,634,730 | null | 275 | 275 |
from collections import deque
def bfs(sy,sx):
q=deque([[sy,sx]])
visited[sy][sx]=0
while q:
y,x=q.popleft()
for dy,dx in ([1,0],[-1,0],[0,1],[0,-1]):
ny,nx=y+dy,x+dx
if ny<0 or ny>h-1 or nx<0 or nx>w-1 or path[ny][nx]=="#":continue
if path[ny][nx]=="." and visited[ny][nx]==-1:
visited[ny][nx]=visited[y][x]+1
q.append([ny,nx])
res=-1
for i in range(h):
for j in range(w):
res=max(visited[i][j],res)
return res
h,w=map(int,input().split())
path=[input() for i in range(h)]
visited=[[-1]*w for i in range(h)]
sy,sx=0,0
gy,gx=0,0
ans=0
for i in range(h):
for j in range(w):
if path[i][j]=="#":continue
sy=i
sx=j
visited=[[-1]*w for _ in range(h)]
t=bfs(sy,sx)
ans=max(t,ans)
print(ans)
| from collections import deque
n, m = map(int, input().split())
name = ['']*n
time = ['']*n
for i in range(n):
name[i], time[i] = input().split()
time = list(map(int, time))
Q = deque([i for i in range(n)])
t = 0
while Q!=deque([]):
q = Q.popleft()
if time[q]<=m:
t += time[q]
print(name[q] + ' ' + str(t))
else:
t += m
time[q] -= m
Q.append(q)
| 0 | null | 47,438,620,570,800 | 241 | 19 |
import math
z = raw_input()
x1, y1, x2, y2 = z.split()
x1 = float(x1)
x2 = float(x2)
y1 = float(y1)
y2 = float(y2)
d = math.sqrt((x2 - x1) * (x2-x1) + (y2 - y1) * (y2 - y1))
print ("%lf" %(d)) | n, k = map( int, input().split() )
p = list( map( int, input().split() ) )
sum_k = sum( p[ : k ] )
max_sum_k = sum_k
for i in range( k, n ):
sum_k += p[ i ] - p[ i - k ]
if sum_k > max_sum_k:
max_sum_k = sum_k
print( ( max_sum_k + k ) / 2 ) | 0 | null | 37,616,951,652,238 | 29 | 223 |
from functools import lru_cache
def popcnt(x):
return bin(x).count("1")
@lru_cache(maxsize=None)
def rec(n):
if n == 0:
return 0
else:
return rec(n % popcnt(n)) + 1
n = int(input())
x = int(input(), 2)
# 事前計算
cnt = popcnt(x)
init_big = x % (cnt + 1)
if cnt == 1:
init_small = 0
else:
init_small = x % (cnt - 1)
# 差分計算
result = []
for i in range(n):
if not (x >> i) & 1:
result.append((init_big + pow(2, i, cnt + 1)) % (cnt + 1))
elif x == 1 << i or cnt - 1 == 0:
result.append("x")
else:
result.append((init_small - pow(2, i, cnt - 1)) % (cnt - 1))
ans = []
for x in result[::-1]:
if x == "x":
ans.append(0)
else:
ans.append(rec(x) + 1)
print(*ans, sep="\n") | import random
s = str(input()).lower()
t = random.randint(0, len(s)-3)
print(s[t:t+3]) | 0 | null | 11,507,018,017,150 | 107 | 130 |
a = ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"]
a = a * 2
c = 0
z = input()
for i in range(0,7):
if z == a[i]:
for j in range(i + 1, 14):
if a[j] == "SUN":
print(j - i )
| S=str(input())
if 'SUN'in S:
print(7)
elif 'MON' in S:
print(6)
elif 'TUE' in S:
print(5)
elif 'WED' in S:
print(4)
elif 'THU' in S:
print(3)
elif 'FRI' in S:
print(2)
elif 'SAT' in S:
print(1) | 1 | 132,825,807,868,402 | null | 270 | 270 |
import sys, os, math, bisect, itertools, collections, heapq, queue, copy, array
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
# from decimal import Decimal
# from collections import defaultdict, deque
sys.setrecursionlimit(10000000)
ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]
iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]
lcm = lambda x, y: (x * y) // math.gcd(x, y)
MOD = 10 ** 9 + 7
INF = float('inf')
def main():
if os.getenv("LOCAL"):
sys.stdin = open("input.txt", "r")
S = ii()
dp = [0] * (S + 1)
dp[0] = 1
# 1 <= i <= Sの範囲を探索
for i in range(1, S + 1):
# 0 <= j <= i - 3の範囲で、
# 間仕切りを置くことができる個数の合計を集計
if i > 2:
dp[i] = sum(dp[0:i - 2])
dp[i] %= MOD
print(dp[-1])
if __name__ == '__main__':
main() | N, M = map(int, input().split())
A = sorted([int(x) for x in input().split()], reverse=True)
sumA = sum(A)
if A[M - 1] >= sumA / (4 * M):
print("Yes")
else:
print('No')
| 0 | null | 20,821,453,627,212 | 79 | 179 |
import sys
input = sys.stdin.readline
def main():
N = int( input())
U = []
V = []
for _ in range(N):
x, y = map( int, input().split())
u, v = x+y, x-y
U.append(u)
V.append(v)
U.sort()
V.sort()
print( max(U[-1]-U[0], V[-1]-V[0]))
if __name__ == '__main__':
main()
| n = int(input())
ph = 0
pl = 10**10
mh = -10**10
ml = 10**10
for _ in range(n):
x,y = map(int,input().split())
ph = max(ph,x+y)
pl = min(pl,x+y)
mh = max(mh,x-y)
ml = min(ml,x-y)
print(max(ph-pl,mh-ml)) | 1 | 3,393,339,558,620 | null | 80 | 80 |
# Https://atcoder.jp/contests/abc151/tasks/abc151_d
from collections import deque
H, W = map(int, input().split())
maze = [list(input()) for i in range(H)]
def bfs(sx, sy):
result = 0
count = [[-1] * W for i in range(H)]
count[sx][sy] = 0
d = deque()
d.append((sx, sy))
while d:
x, y = d.popleft()
result = count[x][y]
for i, j in ([1, 0], [0, 1], [-1, 0], [0, -1]):
tx, ty = x + i, y + j
if (
not (0 <= tx < H)
or not (0 <= ty < W)
or maze[tx][ty] == "#"
or count[tx][ty] != -1
):
continue
else:
count[tx][ty] = count[x][y] + 1
d.append((tx, ty))
return result
ans = 0
for i in range(W):
for j in range(H):
if maze[j][i] == ".":
ans = max(ans, bfs(j, i))
print(ans)
| import sys
buff=sys.stdin.read()
buff=buff.lower()
alp="abcdefghijklmnopqrstuvwxyz"
for i in range(len(alp)):
print(alp[i],':',buff.count(alp[i]))
| 0 | null | 48,219,497,663,710 | 241 | 63 |
from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
# d = m - k[i] - k[j]
# if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
def readInts():
return list(map(int,input().split()))
def main():
a,b = readInts()
print(a - b*2 if a - b*2 >= 0 else 0)
if __name__ == '__main__':
main()
| あ,い=map(int,input().split())
print(max(0,あ-い*2)) | 1 | 166,483,995,162,598 | null | 291 | 291 |
a,b,c =raw_input().split()
a,b,c = map(int,(a,b,c))
ls = list((a,b,c))
ls.sort()
string_ans=''
for k in ls:
string=''
string = str(k)+" "
string_ans = string_ans + string
print string_ans.strip() | array = list(map(int, input().split()))
array.sort()
print("{} {} {}".format(array[0], array[1], array[2]))
| 1 | 413,392,256,200 | null | 40 | 40 |
num = int(input())
if num%2 == 0:
ans = float(1/2)
else:
ans = float((num//2 + 1)/num)
print(ans) | def resolve():
k = int(input())
x = 7 % k
for i in range(1, k + 1):
if x == 0:
print(i)
return
x = (x * 10 + 7) % k
print(-1)
resolve() | 0 | null | 92,031,277,164,190 | 297 | 97 |
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
a_sum = [0 for i in range(N+1)]
for i in range(N):
a_sum[i+1] = a_sum[i] + A[i]
b_sum = [0 for i in range(M+1)]
for i in range(M):
b_sum[i+1] = b_sum[i] + B[i]
ans = 0
for i in range(N+1):
t = a_sum[i]
l = 0
r = len(b_sum)
while(l+1<r):
c = (l+r)//2
if t+b_sum[c]<=K:
l = c
else:
r = c
if a_sum[i]+b_sum[l]<=K:
ans = max(ans,i+l)
print(ans) | def main():
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
cum_A = [0]
for a in A:
if a + cum_A[-1] <= K:
cum_A.append(a + cum_A[-1])
else:
break
cum_B = [0]
for b in B:
if b + cum_B[-1] <= K:
cum_B.append(b + cum_B[-1])
else:
break
ans = 0
max_b_idx = len(cum_B) - 1
for a_idx, a in enumerate(cum_A):
if a <= K and a_idx > ans:
ans = a_idx
for b_idx in reversed(range(max_b_idx + 1)):
if a + cum_B[b_idx] <= K:
max_b_idx = b_idx
if a_idx + b_idx > ans:
ans = a_idx + b_idx
break
print(ans)
if __name__ == '__main__':
main()
| 1 | 10,669,274,427,268 | null | 117 | 117 |
# -*- coding: utf-8 -*-
# A
import sys
from collections import defaultdict, deque
from heapq import heappush, heappop
import math
import bisect
input = sys.stdin.readline
# 再起回数上限変更
# sys.setrecursionlimit(1000000)
N = int(input())
if N % 2 == 0:
print(0.5)
else:
a = N//2
b = N - a
print(b/N)
| X, N = list(map(int, input().split()))
p = list(map(int, input().split()))
integer = [i for i in range(102)]
for i in range(N):
integer.remove(p[i])
l = len(integer)
ans = -200
for i in range(l):
if abs(ans) > abs(integer[i]-X):
ans = integer[i] - X
print(ans + X) | 0 | null | 95,888,879,535,302 | 297 | 128 |
from fractions import gcd
N, M = map(int, input().split())
S = list(map(int, input().split()))
temp = S[0]
cnt = 0
while temp%2 == 0:
temp //= 2
cnt += 1
temp = S[0]
for i in range(1, N):
temp = temp*S[i]//gcd(temp, S[i])
if S[i]%(2**cnt) == 1 or (S[i]//(2**cnt))%2 == 0:
print(0)
break
else:
if temp//2 > M:
print(0)
else:
print((M-temp//2)//temp+1) | from decimal import Decimal
a, b = map(Decimal,input().split())
ans = int(a * b)
print(ans) | 0 | null | 58,960,448,387,680 | 247 | 135 |
# -*- coding: utf-8 -*-
def solve():
S = input()
return S[:3]
if __name__ == '__main__':
print(solve())
| import random
import time
import copy
start = time.time()
D = int(input())
s = [[0 for j in range(26)] for i in range(D)]
c = list(map(int, input().split(" ")))
result = []
total = -10000000
for i in range(D):
a = list(map(int, input().split(" ")))
for j, k in enumerate(a):
s[i][j] = int(k)
#while(1):
for t in range(26):
result_tmp = []
total_tmp = 0
last = [0 for i in range(26)]
for i in range(D):
score = [0 for i in range(26)]
score_tmp = [0 for i in range(26)]
for j in range(26):
score[j] = s[i][j]
score_tmp[j] = s[i][j]
for k in range(26):
if j != k:
score_tmp[j] -= (i + 1 + t - last[k]) * c[k]
score[j] -= (i + 1 - last[k]) * c[k]
score_sort = sorted(score_tmp, reverse=True)
score_max = score_sort[0]
tmp = []
for j in range(26):
if score_max == score_tmp[j]:
score_max = j
result_tmp.append(score_max)
last[score_max] = i + 1
total_tmp += score[score_max]
if total < total_tmp:
total = total_tmp
result = result_tmp.copy()
end = time.time()
if end - start > 1.8:
break
for i in range(D):
print(result[i]+1) | 0 | null | 12,220,291,800,252 | 130 | 113 |
T=int(input())
a=T//1000
T=T-1000*a
if T==0:
print(0)
else:
print(1000-T) | N = int(input())
for i in range(10):
pay = (i + 1) * 1000
if(pay >= N):
break
if(pay < N):
print("たりません")
else:
print(pay - N) | 1 | 8,530,654,879,240 | null | 108 | 108 |
import math
r=input()
print "{0:0.6f} {1:0.6f}".format(r*r*math.pi, 2*r*math.pi) | import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(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
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10
N = INT()
x = []
for _ in range(N):
X, L = MAP()
x.append([X-L, X+L])
x.sort(key = lambda x: x[1])
ans = 0
tmp = -INF
for l, r in x:
if tmp <= l:
tmp = r
ans += 1
print(ans) | 0 | null | 45,271,010,919,112 | 46 | 237 |
s=input()
if len(s)&1:
print('No')
exit()
for i in list(s[i*2:i*2+2] for i in range(len(s)//2)):
if i!='hi':
print('No')
exit()
print('Yes') | n = int(input())
branch = [[] for _ in range(n)]
a, b, inda, indb = [], [], [], []
for _ in range(n-1):
i, j = map(int, input().split())
i -= 1
j -= 1
branch[i].append(j)
branch[j].append(i)
a.append(i)
b.append(j)
inda.append(len(branch[i])-1)
indb.append(len(branch[j])-1)
kind = max([len(i) for i in branch])
print(kind)
# DFS
color = [0 for _ in range(n)]
todo = [0]
color[0] = 1
while len(todo) > 0:
num = todo.pop(-1)
col = color[num]
if col == kind:
col = 1
else:
col = col + 1
for i in range(len(branch[num])):
if color[branch[num][i]] == 0:
color[branch[num][i]] = col
todo.append(branch[num][i])
branch[num][i] = -col
if col == kind:
col = 1
else:
col = col + 1
for i in range(n-1):
if branch[a[i]][inda[i]] < 0:
print(-branch[a[i]][inda[i]])
else:
print(-branch[b[i]][indb[i]]) | 0 | null | 94,948,643,049,348 | 199 | 272 |
import random
s = input()
num = random.randint(0,len(s)-3)
print(s[num:num+3]) | N,M,K = list(map(int, input().split()))
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
uf = UnionFind(N)
V = [[] for _ in range(N)]
for _ in range(M):
a,b = map(int, input().split())
a,b = a-1, b-1
V[a].append(b)
V[b].append(a)
uf.union(a,b)
for _ in range(K):
a,b = map(int, input().split())
a,b = a-1, b-1
if uf.same(a,b):
V[a].append(b)
V[b].append(a)
ans = [-1] * N
for i in range(N):
ans[i] = uf.size(i) - len(V[i]) - 1
print(" ".join(list(map(str, ans))))
| 0 | null | 38,081,072,190,340 | 130 | 209 |
def abc173d_chat_in_the_circle():
n = int(input())
a = sorted(map(int, input().split()), reverse=True)
if n <= 1:
print(0)
return
val = 0
for i in range(0, n-1):
idx = (i+1) // 2
val += a[idx]
print(val)
abc173d_chat_in_the_circle() | #!/usr/bin/env python3
import sys
from itertools import chain
import numpy as np
import math
# from itertools import combinations as comb
# form bisect import bisect_left, bisect_right, insort_left, insort_right
# from collections import Counter
# import numpy as np
def factorize(n: int):
"""nを素因数分解する"""
# 2
count = 0
while n % 2 == 0:
count += 1
n = n // 2
if count > 0:
arr = [(2, count)]
else:
arr = []
# 3 以降
for facter in range(3, n + 1, 2):
if facter * facter > n:
if n > 1:
arr.append((n, 1))
break
count = 0
while n % facter == 0:
count += 1
n = n // facter
if count > 0:
arr.append((facter, count))
return arr
def case(n):
t = 0
i = 1
while True:
t += i
if t > n:
return i - 1
i += 1
def solve(N: int):
factors = factorize(N)
answer = 0
for f, count in factors:
answer += case(count)
return answer
def main():
tokens = chain(*(line.split() for line in sys.stdin))
# N = map(int, line.split())
N = int(next(tokens)) # type: int
answer = solve(N)
print(answer)
if __name__ == "__main__":
main()
| 0 | null | 13,030,687,940,720 | 111 | 136 |
N,X,Y = list(map(int,input().split()))
ans_dict={}
for n in range(1,N):
ans_dict[n]=0
for n1 in range(1,N+1):
for n2 in range(n1+1,N+1):
ans_1 = abs(n1-n2)
ans_2 = abs(n1-X)+abs(n2-Y)+1
ans_3 = abs(n2-X)+abs(n1-Y)+1
ans=min(ans_1,ans_2,ans_3)
ans_dict[ans]+=1
for k in ans_dict.keys():
print(ans_dict[k]) | n,x,y = map(int, input().split())
lis = [0] * n
x -= 1
y -= 1
for i in range(n):
for j in range(i+1, n):
t = min(abs(i-j), abs(i-x)+abs(j-y)+1,abs(i-y)+abs(j-x)+1)
lis[t] += 1
for i in range(1,n):
print(lis[i]) | 1 | 44,231,810,986,788 | null | 187 | 187 |
s,t = input().split()
a,b = [int(x) for x in input().split()]
u = input()
if s == u:
print(str(a-1) + " " + str(b))
else:
print(str(a) + " " + str(b-1)) | X, Y= map(int, input().strip().split())
if Y%2==0 and 2*X<=Y and Y<=4*X:print('Yes')
else:print('No') | 0 | null | 43,058,848,281,970 | 220 | 127 |
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
from collections import defaultdict
n,m=map(int,input().split())
visited=[0]*n
d=defaultdict(list)
def dfs(n):
visited[n]=1
#print(visited)
for i in d[n]:
if visited[i]==0:
dfs(i)
for i in range(m):
a,b=map(int,input().split())
a,b=a-1,b-1
d[a].append(b)
d[b].append(a)
r=-1
for i in range (n):
if visited[i]==0:
dfs(i)
r+=1
print(r) | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
import collections
import sys
def count_connected_components(max_v, adj_list):
result = 0
visited = collections.defaultdict(bool)
def depth_first_search(start_v):
visited[start_v] = True
for v in adj_list[start_v]:
if not visited[v]:
depth_first_search(v)
for u in range(max_v):
if not visited[u]:
depth_first_search(u)
result += 1
return result
def main():
sys.setrecursionlimit(50000)
n, m = map(int, input().split())
adj_list = collections.defaultdict(set)
for _ in range(m):
a, b = map(lambda x: int(x) - 1, input().split())
adj_list[a].add(b)
adj_list[b].add(a)
print(count_connected_components(n, adj_list) - 1)
if __name__ == '__main__':
main()
| 1 | 2,256,224,112,660 | null | 70 | 70 |
N = int(input())
A = list(map(int, input().split()))
for i, a in enumerate(A.copy(), 1):
A[a - 1] = i
for a in A:
print(str(a) + ' ', end='')
print()
| x = int(input())
balance = 100
cnt = 0
while balance < x:
balance += int(balance//100)
cnt += 1
print(cnt) | 0 | null | 104,362,340,248,456 | 299 | 159 |
import sys
input = sys.stdin.readline
def p_count(n):
return bin(n)[2:].count('1')
n = int(input())
x = input().rstrip()
x_dec = int(x,base = 2)
pop_cnt = x.count('1')
pop_cnt_0 = (pop_cnt + 1)
pop_cnt_1 = (pop_cnt - 1)
x_0 = pow(x_dec,1,pop_cnt_0)
x_1 = pow(x_dec,1,pop_cnt_1) if pop_cnt_1 > 0 else 0
x_bit = [0]*n
for i in range(n-1,-1,-1):
if x[i] == '0':
x_bit[i] = (x_0 + pow(2,n-1-i,pop_cnt_0))%pop_cnt_0
#x_bit[i] = (x_dec + pow(2,n-1-i))%pop_cnt_0
else:
if pop_cnt_1 > 0:
x_bit[i] = (x_1 - pow(2,n-1-i,pop_cnt_1))
x_bit[i] = x_bit[i] if x_bit[i] >= 0 else x_bit[i] + pop_cnt_1
else:
x_bit[i] = -1
anslist = []
for i in range(n):
if x_bit[i] == -1:
anslist.append(0)
continue
ans = 1
now = x_bit[i]
while True:
if now == 0:
break
now = now%p_count(now)
ans += 1
anslist.append(ans)
for ans in anslist:
print(ans)
| import sys
sys.setrecursionlimit(10**8)
N = int(input())
X = input()
if X == '0':
for _ in range(N):
print(1)
exit()
mem = [None] * (200005)
mem[0] = 0
def f(n):
if mem[n] is not None: return mem[n]
c = bin(n).count('1')
r = 1 + f(n%c)
mem[n] = r
return r
for i in range(200005):
f(i)
cnt = X.count('1')
a,b = cnt+1, cnt-1
ans = [None] * N
n = 0
for c in X:
n *= 2
n += int(c)
n %= a
for i,c in reversed(list(enumerate(X))):
if c=='1': continue
ans[i] = mem[(n+pow(2,N-i-1,a))%a] + 1
if b:
n = 0
for c in X:
n *= 2
n += int(c)
n %= b
for i,c in reversed(list(enumerate(X))):
if c=='0': continue
ans[i] = mem[(n-pow(2,N-i-1,b))%b] + 1
else:
for i in range(N):
if ans[i] is None:
ans[i] = 0
print(*ans, sep='\n') | 1 | 8,117,729,643,662 | null | 107 | 107 |
while True:
h, w = map(int, input().split())
if h == w == 0: break
for i in range(0, h):
print(''.join(['#' for x in range(0, w)]))
print('') | N = int(input())
while N > 0:
N -= 1000
if N < 0:
N *= -1
print(N) | 0 | null | 4,662,436,876,008 | 49 | 108 |
def resolve():
N=int(input())
A=list(map(int,input().split()))
d={}
for i in range(N):
d[A[i]]=i+1
dict2=sorted(d.items())
for i in range(N):
print(dict2[i][1], end=" ")
resolve() | # https://atcoder.jp/contests/abc168/tasks/abc168_a
N = int(input())
last_num = int(str(N)[-1])
if last_num in {2, 4, 5, 7, 9}:
print('hon')
elif last_num in {0, 1, 6, 8}:
print('pon')
else:
print('bon') | 0 | null | 99,592,339,010,902 | 299 | 142 |
wd = ['SUN','MON','TUE','WED','THU','FRI','SAT']
s = input()
print(str(7 - wd.index(s) % 7)) | a=[int(x) for x in input().split(" ")]
print(a.index(0)+1) | 0 | null | 73,113,197,540,740 | 270 | 126 |
n = sum(map(int, list(input())))
if n%9==0:
print('Yes')
else:
print('No') | while True:
try:
a,b = map(int,input().split(" "))
print(len(str(a+b)))
except: break
| 0 | null | 2,215,899,983,518 | 87 | 3 |
A = map(int, input().split())
if sum(A) > 21:
print('bust')
else:
print('win') | a, b, c = map(int, input().split())
print("bust" if (a+b+c) >= 22 else "win") | 1 | 118,716,361,816,864 | null | 260 | 260 |
import sys
sys.setrecursionlimit(10 ** 7)
N = int(input())
X = input()
pc = X.count("1")
if pc == 1:
if X[-1] == "0":
for i, s in enumerate(X):
if i == N - 1:
print(2)
elif s == "0":
print(1)
else:
print(0)
else:
ans = [2] * (N - 1) + [0]
print(*ans, sep="\n")
exit()
m01 = 0
m10 = 0
b01 = 1
b10 = 1
for i, s in enumerate(X[::-1]):
if s == "1":
m01 += b01
m01 %= pc + 1
m10 += b10
m10 %= pc - 1
b01 *= 2
b01 %= pc + 1
b10 *= 2
b10 %= pc - 1
def pop_count(T):
T = (T & 0x55555555) + ((T >> 1) & 0x55555555)
T = (T & 0x33333333) + ((T >> 2) & 0x33333333)
T = (T & 0x0F0F0F0F) + ((T >> 4) & 0x0F0F0F0F)
T = (T & 0x00FF00FF) + ((T >> 8) & 0x00FF00FF)
T = (T & 0x0000FFFF) + ((T >> 16) & 0x0000FFFF)
return T
memo = [0] * (N + 10)
for i in range(1, N + 10):
p = pop_count(i)
memo[i] = memo[i % p] + 1
ans = [0] * N
b01 = 1
b10 = 1
for i, s in enumerate(X[::-1]):
if s == "0":
m = m01
m += b01
m %= pc + 1
else:
m = m10
m -= b10
m %= pc - 1
ans[i] = memo[m] + 1
b01 *= 2
b01 %= pc + 1
b10 *= 2
b10 %= pc - 1
print(*ans[::-1], sep="\n") | N=int(input())
ans=0
for i in range(1,N):
if N%i!=0:
for j in range(1,N//i+1):
ans+=1
else:
for j in range(1,N//i):
ans+=1
print(ans) | 0 | null | 5,479,602,162,518 | 107 | 73 |
def II(): return int(input())
def MI(): return map(int, input().split())
N=II()
a=[0]*N
x=[[0]*N for i in range(N)]
y=[[0]*N for i in range(N)]
for i in range(N):
a[i]=II()
for j in range(a[i]):
x[i][j],y[i][j]=MI()
x[i][j]-=1
def check(honest):
for i in range(N):
if not honest[i]:
continue
for j in range(a[i]):
if y[i][j]==0 and honest[x[i][j]]:
return False
if y[i][j]==1 and not honest[x[i][j]]:
return False
return True
def dfs(honest):
if len(honest)==N:
if check(honest):
return sum(honest)
else:
return 0
return max(dfs(honest+[True]),dfs(honest+[False]))
print(dfs([])) | class UnionFind():
def __init__(self, n):
self.n = n
self.par = list(range(self.n))
self.rank = [1] * n
self.cnt = n
def find(self, x):
if self.par[x] == x:
return x
else:
self.par[x] = self.find(self.par[x])
return self.par[x]
def unite(self, x, y):
p = self.find(x)
q = self.find(y)
if p == q:
return None
if p > q:
p, q = q, p
self.rank[p] += self.rank[q]
self.par[q] = p
self.cnt -= 1
def same(self, x, y):
return self.find(x) == self.find(y)
def size(self, x):
return self.rank[x]
def count(self):
return self.cnt
n, m = map(int, input().split())
UF = UnionFind(n)
for _ in range(m):
a, b = map(int, input().split())
UF.unite(a - 1, b - 1)
print(UF.count() - 1) | 0 | null | 61,764,913,950,348 | 262 | 70 |
N, M, L = map(int, input().split())
INF = 10**12
dp = [[INF]*N for i in range(N)]
fp = [[INF]*N for i in range(N)]
for i in range(N):
dp[i][i]=0
fp[i][i]=0
k = [[0]*N for i in range(N)]
for i in range(M):
a, b, c = map(int, input().split())
dp[a-1][b-1] = c
dp[b-1][a-1] = c
for i in range(N):
for j in range(N):
for h in range(N):
dp[j][h] = min(dp[j][h], dp[j][i]+dp[i][h])
for j in range(N):
for h in range(N):
if dp[j][h]<=L:
fp[j][h] = 1
for i in range(N):
for j in range(N):
for h in range(N):
fp[j][h] = min(fp[j][h], fp[j][i]+fp[i][h])
Q = int(input())
for i in range(Q):
s, t = map(int, input().split())
s = s-1
t = t-1
if fp[s][t]==INF:
print(-1)
else:
print(fp[s][t]-1)
| lst = [True for i in range(52)]
n = int(input())
for i in range (n):
suit, rank = input().split()
rankn = int(rank)
if suit == 'S':
lst[rankn-1] = False
elif suit == 'H':
lst[rankn+12] = False
elif suit == 'C':
lst[rankn+25] = False
else:
lst[rankn+38] = False
for i in range(52):
tf = lst[i]
if i <= 12 and tf:
print ('S %d' % (i+1))
elif 12 < i <= 25 and tf:
print ('H %d' % (i-12))
elif 25 < i <= 38 and tf:
print ('C %d' % (i-25))
elif tf:
print ('D %d' % (i-38))
| 0 | null | 87,347,068,352,808 | 295 | 54 |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.