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
|
---|---|---|---|---|---|---|
import math
a, b, x = map(int, input().split())
if x < a ** 2 * b / 2:
theta = math.atan2(b, 2 * x / b / a)
else:
theta = math.atan2(2 * b - 2 * x / a / a, a)
deg = math.degrees(theta)
print(deg)
| # 500 Yen Coins
K, X = map(int, input().split())
if K * 500 >= X:
ans = 'Yes'
else:
ans = 'No'
print(ans) | 0 | null | 131,052,339,308,230 | 289 | 244 |
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10 ** 9)
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()))
INF=float('inf')
N=INT()
nodes=[[] for i in range(N)]
for i in range(N):
l=LIST()
u=l[0]
l=l[2:]
for v in l:
nodes[u-1].append(v-1)
nodes[u-1].sort()
ans=[[0]*2 for i in range(N)]
visited=[False]*N
time=0
def rec(u):
if visited[u]:
return
visited[u]=True
global time
time+=1
ans[u][0]=time
for v in nodes[u]:
rec(v)
time+=1
ans[u][1]=time
for i in range(N):
rec(i)
for i in range(N):
d,f=ans[i]
print(i+1, d, f)
| n=int(input())
adj=[]
for i in range(n):
a=list(map(int,input().split()))
for j in range(2,len(a)):
a[j]-=1
adj.append(a[2:])
visit_time1=[0]*n
visit_time2=[0]*n
visited=[0]*n
def dfs(now):
global time
visit_time1[now]=time
time+=1
for next in adj[now]:
if not visited[next]:
visited[next]=True
dfs(next)
visit_time2[now]=time
time+=1
time=1
for i in range(n):
if not visited[i]:
visited[i]=True
dfs(i)
for i in range(n):
print(i+1,visit_time1[i],visit_time2[i])
| 1 | 2,710,027,122 | null | 8 | 8 |
n, quantum = list(map(int, input().split()))
queue = []
sumOfTime = 0
for _ in range(n):
name, time = input().split()
queue.append([name, int(time)])
while len(queue) > 0:
name, time = queue.pop(0)
if time > quantum:
sumOfTime += quantum
queue.append([name, time - quantum])
else:
sumOfTime += time
print(name, sumOfTime)
| n=int(input())
a=n%10
if a==2 or a==4 or a==5 or a==7 or a==9:
print("hon")
elif a==0 or a==1 or a==6 or a==8:
print("pon")
else:
print("bon") | 0 | null | 9,643,323,286,510 | 19 | 142 |
n = int(input())
s = list(str(n))
r = list(reversed(s))
if r[0] in ["2","4","5","7","9"]:
print("hon")
elif r[0] in ["0","1","6","8"]:
print("pon")
else:
print("bon") | def judge(a, b, c):
return 'Yes' if a < b < c else 'No'
if __name__ == '__main__':
a, b, c = map(int, input().split(' '))
print(judge(a, b, c))
| 0 | null | 9,809,995,184,418 | 142 | 39 |
"""
Given N, D, A, N means no. of monsters, D means distances of bombs, A attack of the bombs
Find the minimum of bombs required to win.
Each monster out of N pairs - pair[0] = position, pair[1] = health
"""
from collections import deque
mod = 1e9+7
def add(a, b):
c = a + b
if c >= mod:
c -= mod
return c
def main():
N, D, A = [int(x) for x in raw_input().split()]
D *= 2
monsters = []
for _ in range(N):
pos, health = [int(x) for x in raw_input().split()]
monsters.append([pos, health])
monsters.sort(key = lambda x : x[0])
remain_attacks_queue = deque([])
remain_attack = 0
ans = 0
for monster in monsters:
# monster[0] - pos, monster[1] - health
# queue[0] - position, queue[1] - attack points
while len(remain_attacks_queue) and monster[0] - D > remain_attacks_queue[0][0]:
remain_attack -= remain_attacks_queue.popleft()[1]
if remain_attack < monster[1]:
remained_health = monster[1] - remain_attack
times = remained_health / A if remained_health % A == 0 else remained_health // A + 1
#print(times)
attack = times * A
remain_attacks_queue.append([monster[0], attack])
ans += times
remain_attack += attack
print(ans)
main() | from random import random
class Node:
def __init__(self, key, value:int=-1):
self.left = None
self.right = None
self.key = key
self.value = value
self.priority = int(random()*10**7)
# self.count_partial = 1
self.sum_partial = value
class Treap:
#Node [left, right, key, value, priority, num_partial, sum_partial]
def __init__(self):
self.root = None
def update(self, node) -> Node:
if node.left is None:
# left_count = 0
left_sum = 0
else:
# left_count = node.left.count_partial
left_sum = node.left.sum_partial
if node.right is None:
# right_count = 0
right_sum = 0
else:
# right_count = node.right.count_partial
right_sum = node.right.sum_partial
# node.count_partial = left_count + right_count + 1
node.sum_partial = left_sum + node.value + right_sum
return node
def merge(self, left :Node, right:Node):
if left is None or right is None:
return left if right is None else right
if left.priority > right.priority:
left.right = self.merge(left.right,right)
return self.update(left)
else:
right.left = self.merge(left,right.left)
return self.update(right)
# def node_size(self, node:Node) -> int:
# return 0 if node is None else node.count_partial
def node_key(self, node: Node) -> int:
return -1 if node is None or node.key is None else node.key
def node_sum(self, node: Node) -> int:
return 0 if node is None else node.sum_partial
#指定された場所のノードは右の木に含まれる
def split(self, node:None, key:int) -> (Node, Node):
if node is None:
return None,None
if key <= self.node_key(node):
left,right = self.split(node.left, key)
node.left = right
return left, self.update(node)
else:
left,right = self.split(node.right, key)
node.right = left
return self.update(node),right
def insert(self, key:int, value:int =-1):
value = value if value > 0 else key
left, right = self.split(self.root, key)
new_node = Node(key,value)
self.root = self.merge(self.merge(left,new_node),right)
def erase(self, key:int):
# print('erase pos=',pos,'num=',self.search(pos),'num_nodes=',self.root.count_partial)
middle,right = self.split(self.root, key+1)
# print(middle.value if middle is not None else -1,middle.count_partial if middle is not None else -1,right.value if right is not None else -1,right.count_partial if right is not None else -1)
left,middle = self.split(middle, key)
# print(left.value if left is not None else -1,left.count_partial if left is not None else -1, middle.value if middle is not None else -1,middle.count_partial if middle is not None else -1,)
self.root = self.merge(left,right)
def printTree(self, node=None, level=0):
node = self.root if node is None else node
if node is None:
print('level=',level,'root is None')
return
else:
print('level=',level,'k=',node.key,'v=',node.value, 'p=',node.priority)
if node.left is not None:
print('left')
self.printTree(node.left,level+1)
if node.right is not None:
print('right')
self.printTree(node.right,level+1)
def find(self, key):
#return self.search_recursively(pos,self.root)
v = self.root
while v:
v_key = self.node_key(v)
if key == v_key:
return v.value
elif key < v_key:
v = v.left
else:
v = v.right
return -1
def interval_sum(self, left_key, right_key):
lt_left, ge_left = self.split(self.root,left_key)
left_to_right, gt_right = self.split(ge_left, right_key + 1)
res = self.node_sum(left_to_right)
self.root = self.merge(lt_left, self.merge(left_to_right, gt_right))
return res
def main():
from sys import setrecursionlimit, stdin, stderr
from os import environ
from collections import defaultdict, deque, Counter
from math import ceil, floor
from itertools import accumulate, combinations, combinations_with_replacement
setrecursionlimit(10**6)
dbg = (lambda *something: stderr.write("\033[92m{}\033[0m".format(str(something)+'\n'))) if 'TERM_PROGRAM' in environ else lambda *x: 0
input = lambda: stdin.readline().rstrip()
LMIIS = lambda: list(map(int,input().split()))
II = lambda: int(input())
P = 10**9+7
INF = 10**18+10
N,D,A = LMIIS()
enemies = []
for i in range(N):
x, h = LMIIS()
enemies.append((x, ceil(h/A)))
enemies.sort()
bomb = Treap()
ans = 0
for i, (x, h) in enumerate(enemies):
left = x - D
right = x + D
remain_h = h - bomb.interval_sum(left, right)
if remain_h <= 0:
continue
ans += remain_h
bomb.insert(x + D, remain_h)
print(ans)
main() | 1 | 82,009,486,614,330 | null | 230 | 230 |
N = int(input())
d_ls=[]
for vakawkawelkn in range(N):
D1,D2=map(int, input().split())
if D1==D2:
d_ls+=[1]
else:
d_ls+=[0]
flag=0
for i in range(N-2):
if d_ls[i]*d_ls[i+1]*d_ls[i+2]==1:
flag=1
if flag==0:
print("No")
else:
print("Yes")
# 2darray [[0] * 4 for i in range(3)]
# import itertools | # Euclidean algorithm
def gcd(x, y):
if x < y:
x, y = y, x
while y > 0:
r = x % y
x = y
y = r
return x
print(gcd(*map(int, input().split()))) | 0 | null | 1,250,889,936,500 | 72 | 11 |
n, k = map(int, input().split())
p = list(map(int, input().split()))
e = []
for i in range(n):
e.append(p[i] + 1)
sum_e = [0]
for i in range(1,n+1):
sum_e.append(sum_e[i-1]+e[i-1])
ans = []
for i in range(n-k+1):
ans.append(sum_e[i+k]-sum_e[i])
print(max(ans)/2) | import sys
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n, k = map(int, readline().split())
p = list(map(int, readline().split()))
tmp = [(i+1)/2 for i in p]
cs = list(np.cumsum(tmp))
if n == k:
print(cs[-1])
exit()
ans = 0
for i in range(n - k):
ans = max(ans, cs[i + k] - cs[i])
print(ans) | 1 | 75,022,944,881,950 | null | 223 | 223 |
X = int(input())
lack = X % 1000
if lack == 0:
print(0)
else:
print(1000 - lack) | i = int(input())
k = 1000
while k < i:
k += 1000
if k > i:
print(k - i)
elif k == i:
print(0) | 1 | 8,463,002,785,608 | null | 108 | 108 |
n, k = map(int, input().split())
MOD = 10 ** 9 + 7
a = [0] *(k+1)
for x in range(1, k + 1):
a[x] = pow(k // x, n, MOD)
for x in range(k, 0, -1):
for i in range(2, k // x + 1):
a[x] -= a[x * i]
answer = sum([i * x for i,x in enumerate(a)])
print(answer % MOD) | N=int(input());A=sorted((int(x),i)for i,x in enumerate(input().split()));t=[0]*N**2
for w in range(N):
a,j=A[w]
for l in range(N-w):
r=l+w;p=a*abs(j-l);t[l*N+r]=max(p+t[(l+1)*N+r],a*abs(j-r)+t[l*N+r-1])if w else p
print(t[N-1]) | 0 | null | 35,317,574,108,648 | 176 | 171 |
from collections import deque
que = deque()
n = int(input())
for loop in range(n):
input_command = input()
if input_command == 'deleteFirst':
que.popleft()
elif input_command == 'deleteLast':
que.pop()
else:
command, x = input_command.split()
if command == 'insert':
que.appendleft(x)
elif command == 'delete':
try:
que.remove(x)
except:
pass
print(' '.join(que))
| from collections import deque
n = int(input())
li = deque()
for i in range(n):
command = input().split()
if command[0] == 'insert':
li.appendleft(command[1])
elif command[0] == 'delete':
if command[1] in li:
li.remove(command[1])
elif command[0] == 'deleteFirst':
li.popleft()
else:
li.pop()
print(*li) | 1 | 49,239,857,570 | null | 20 | 20 |
n = input()
S = raw_input().split()
q = input()
T = raw_input().split()
s = 0
for i in T:
if i in S:
s+=1
print s | from collections import deque
n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = list(input())
points = {"r":r,"s":s,"p":p}
d = {"r":"p","s":"r","p":"s"}
que = deque([None]*k)
ans = 0
for ti in t:
x = que.popleft()
if d[ti] != x:
#print(d[ti])
que.append(d[ti])
ans+=points[d[ti]]
else:
#print(None)
que.append(None)
#que.popleft()
#print(que,ti)
print(ans) | 0 | null | 53,307,877,191,708 | 22 | 251 |
def main():
n = [x for x in input().split(' ')]
s = []
for i in n:
if i == '+':
a = s.pop()
b = s.pop()
s.append(a + b)
elif i == '-':
b = s.pop()
a = s.pop()
s.append(a - b)
elif i == '*':
a = s.pop()
b = s.pop()
s.append(a * b)
else:
s.append(int(i))
print(s.pop())
if __name__ == '__main__':
main() | a = list(input().split())
n = len(a)
s = []
for i in a:
if i=="+":
a = s.pop()
b = s.pop()
s.append(b + a)
elif i=="-":
a = s.pop()
b = s.pop()
s.append(b - a)
elif i=="*":
a = s.pop()
b = s.pop()
s.append(b * a)
else:
s.append(int(i))
print(s[0]) | 1 | 36,833,274,518 | null | 18 | 18 |
import sys
def getTheNumberOfCoin(n, m, c):
T = {}
for j in range(0, n+1):
T[j] = 100000
T[0] = 0
for i in range(0, m):
for j in range(c[i], n+1):
T[j] = min(T[j], T[j-c[i]]+1)
return T[n]
n, m = (int(x) for x in sys.stdin.readline().split())
c = sorted([int(x) for x in sys.stdin.readline().split()])
print(getTheNumberOfCoin(n, m, c)) | #!/usr/bin/env python
# -*- coding: utf-8 -*-
import itertools as ite
import math
import random
import sys
import codecs
from collections import defaultdict
sys.setrecursionlimit(1000000)
INF = 10 ** 18
MOD = 10 ** 9 + 7
n, m = map(int, input().split())
c = list(map(int, input().split()))
DP = [0] + [n] * n
for i in range(m):
for j in range(c[i], n + 1):
DP[j] = min(DP[j], DP[j - c[i]] + 1)
print(DP[n])
| 1 | 141,330,149,376 | null | 28 | 28 |
import math
a,b,C=map(float,input().split())
S=(a*b*math.sin(math.radians(C)))/2
c=a**2+b**2-2*a*b*math.cos(math.radians(C))
L=a+b+c**(1/2)
if C==90:
h=b
else:
h=(2*S)/a
print(f'{S:10.8f}')
print(f'{L:10.8f}')
print(f'{h:10.8f}')
| #coding: utf-8
n = int(input())
for i in range(1, n+1):
x = i
if x % 3 == 0:
print(" " + str(x), end = '')
continue
for j in range(6):
if int(x / (10**j)) % 10 == 3:
print(" " + str(x), end = '')
break
print("")
| 0 | null | 561,132,620,158 | 30 | 52 |
N, M = map(int, input().split())
ans = []
if M%2 == 0:
for i in range(1, M//2+1):
ans.append([i, M+1-i])
ans.append([M+i, 2*M+2-i])
else:
for i in range(1, M//2+1):
ans.append([i, M+1-i])
for i in range(1, (M+1)//2+1):
ans.append([M+i, 2*M+2-i])
for i in range(len(ans)):
print(*ans[i]) | N, M = map(int, input().split())
ans = []
n = M // 2
m = 2 * n + 1
l = 2 * M + 1
for i in range(n):
ans.append([i + 1, m - i])
for i in range(M - n):
ans.append([m + i + 1, l - i])
for v in ans:
print(*v)
| 1 | 28,834,436,421,988 | null | 162 | 162 |
from itertools import accumulate
N, K = map(int, input().split())
P = list(map(int, input().split()))
P = [((x+1) * x / 2) / x for x in P]
A = list(accumulate(P))
ans = A[K-1]
for i in range(K, N):
ans = max(ans, A[i] - A[i-K])
print(ans)
| n = int(input())
testimony = []
for i in range(n):
a = int(input())
test = []
for j in range(a):
x,y = map(int,input().split())
test.append([x-1,y])
testimony.append(test)
ans = 0
for i in range(2**n):
good = [0]*n
f = 1
for j in range(n):
if (i>>j)&1:
good[j] = 1
for k in range(n):
if good[k]:
for l,m in testimony[k]:
if good[l] != m:
f = 0
if f:
ans = max(ans,sum(good))
print(ans) | 0 | null | 98,109,606,867,488 | 223 | 262 |
n = int(input())
li = ["#"*20 if i%4==0 else "0"*10 for i in range(1, 16)]
for _ in range(n):
b, f, r, v = map(int, input().split())
h = 4*b-(4-f)-1
li[h] = li[h].replace(li[h], ''.join([str(int(list(li[h])[r-1])+v) if i == r-1 else list(li[h])[i] for i in range(10)]))
li = [' '+' '.join(li[i]) if (i+1)%4!=0 else li[i] for i in range(len(li))]
print('\n'.join(li))
| a = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]
n = int(input())
for i in range(1, n + 1):
b, f, r, v = map(int, input().split())
a[b-1][f-1][r-1] += v
for i in range(4):
for j in range(3):
for k in range(10):
print("", a[i][j][k], end="")
if k == 9:
print()
if j == 2 and i != 3:
print("####################") | 1 | 1,081,309,221,570 | null | 55 | 55 |
S = int(input())
if S == 1:
print(0)
exit()
MOD = 10**9 + 7
A = [0] * (S + 1)
A[0] = 1
A[1] = 0
A[2] = 0
cumsum = 1
for i in range(3, len(A)):
A[i] = (A[i - 1] + A[i - 3]) % MOD
print(A[-1])
| 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 *
from heapq import heapify, heappop, heappush
import math
import random
import string
from copy import deepcopy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right
import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7
#############
# Main Code #
#############
N = getN()
logk = N.bit_length()
# 漸化式にできるなら行列計算に落とし込める
# A[n] = A[n - 1] + A[n - 3]なので
# [a2, a1, a0] = [0, 0, 1]
# [[1, 1, 0], [0, 0, 1], [1, 0, 0]]のN乗をすれば
# [an+2, an+1, an] が出る
dp = [[[0, 0, 0] for i in range(3)] for i in range(logk)]
dp[0] = [
[1, 1, 0],
[0, 0, 1],
[1, 0, 0]
]
# 行列掛け算 O(n3)かかる
def array_cnt(ar1, ar2):
h = len(ar1)
w = len(ar2[0])
row = ar1
col = []
for j in range(w):
opt = []
for i in range(len(ar2)):
opt.append(ar2[i][j])
col.append(opt)
res = [[[0, 0] for i in range(w)] for i in range(h)]
for i in range(h):
for j in range(w):
cnt = 0
for x, y in zip(row[i], col[j]):
cnt += x * y
res[i][j] = cnt
res[i][j] %= mod
return res
for i in range(1, logk):
dp[i] = array_cnt(dp[i - 1], dp[i - 1])
ans = [[0, 0, 1]]
for i in range(logk):
if N & (1 << i):
ans = array_cnt(ans, dp[i])
print(ans[0][2] % mod) | 1 | 3,264,905,655,430 | null | 79 | 79 |
d = list(map(int, input().split()))
order = input()
class Dice():
def __init__(self, d):
self.dice = d
def InsSN(self, one, two, five, six):
self.dice[0] = one
self.dice[1] = two
self.dice[4] = five
self.dice[5] = six
def InsWE(self, one, three, four, six):
self.dice[0] = one
self.dice[2] = three
self.dice[3] = four
self.dice[5] = six
def S(self):
one = self.dice[4]
two = self.dice[0]
five = self.dice[5]
six = self.dice[1]
self.InsSN(one, two, five, six)
def N(self):
one = self.dice[1]
two = self.dice[5]
five = self.dice[0]
six = self.dice[4]
self.InsSN(one, two, five, six)
def W(self):
one = self.dice[2]
three = self.dice[5]
four = self.dice[0]
six = self.dice[3]
self.InsWE(one, three, four, six)
def E(self):
one = self.dice[3]
three = self.dice[0]
four = self.dice[5]
six = self.dice[2]
self.InsWE(one, three, four, six)
def roll(self, order):
if order == 'S':
self.S()
elif order == 'N':
self.N()
elif order == 'E':
self.E()
elif order == 'W':
self.W()
d = Dice(d)
for o in order:
d.roll(o)
print(d.dice[0]) | if __name__ == "__main__":
n = int(raw_input())
v = map( int, raw_input().split())
min = 1000000
max = -1000000
s = 0
i = 0
while i < n:
if min > v[i]:
min = v[i]
if max < v[i]:
max = v[i]
s += v[i]
i += 1
print "{0} {1} {2}".format( min, max, s) | 0 | null | 486,231,943,808 | 33 | 48 |
n = input()
S = map(int,raw_input().split())
q = input()
T = map(int,raw_input().split())
ans = 0
for t in T:
if t in S:
ans+=1
print ans | n = int(input())
ai = [int(i) for i in input().split()]
tmp = 0
ans = 0
old = 0
a_mnmx = [[0 for i in range(2)] for j in range(n+1)]
#print(a_max)
old = ai[n]
a_mnmx[n][0] = old
a_mnmx[n][1] = old
for i in range(n):
a_mnmx[n-i-1][0] = (a_mnmx[n-i][0]+1)//2 + ai[n-i-1]
a_mnmx[n-i-1][1] = a_mnmx[n-i][1] + ai[n-i-1]
#print(a_mnmx)
if a_mnmx[0][1] < 1 or a_mnmx[0][0] > 1:
print(-1)
exit()
old = 1
ans = 1
for i in range(n):
old = min(a_mnmx[i+1][1],old*2)
ans += old
old -= ai[i+1]
#print(old)
print(ans) | 0 | null | 9,548,884,333,660 | 22 | 141 |
a,b,c = map(int, input().split())
if 4*a*b < (c-a-b)**2 and c > a + b:
print('Yes')
else:
print('No') | a, b, c = map(int, input().split())
d = c - a - b
if d > 0 and d ** 2 > 4 * a * b:
print('Yes')
else:
print('No') | 1 | 51,580,079,002,660 | null | 197 | 197 |
D = int(input())
c = [int(i) for i in input().split()]
s = []
for i in range(D):
tmp = [int(j) for j in input().split()]
s.append(tmp)
t = []
for i in range(D):
t.append(int(input()))
sat = 0
lst = [0 for i in range(26)]
for i in range(D):
sat += s[i][t[i]-1]
lst[t[i]-1] = i + 1
for j in range(26):
sat -= c[j] * ((i + 1) - lst[j])
print(sat) | X = list(map(int, input().split()))
print(X.index(0) + 1)
| 0 | null | 11,691,795,823,270 | 114 | 126 |
K = int(input())
ans = -1
num7 = 7
for i in range(1000000):
if (num7 % K) == 0:
ans = i+1
break
else:
num7 = (num7*10+7)%K
i+=1
print(ans) | #from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, 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())
k = I()
# 0 ~ k-1の値を取る場合がある。
i = 0
value = 7%k
while i < k:
if value == 0:
print(i+1)
exit()
value = (10*value + 7)%k
i += 1
print(-1)
| 1 | 6,064,529,345,696 | null | 97 | 97 |
# -*- coding: utf-8 -*-
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
print('ACL'*N) | #!/usr/bin/env python3
import sys
import itertools
sys.setrecursionlimit(10**8)
INF = float("inf")
MOD = 10**9+7
N = int(input())
A = list(map(int, input().split()))
AA = [(a, i) for i, a in enumerate(A, start=1)]
AA.sort(reverse=True)
# print(AA)
DP = [[0]*(N+1) for _ in range(N+1)]
for wa in range(1, N+1):
# AA[:wa]までを考える
for x in range(wa+1):
y = wa - x
a, i = AA[wa-1]
if x - 1 >= 0:
DP[x][y] = max(DP[x][y], DP[x-1][y]+a*(i-x))
if y - 1 >= 0:
DP[x][y] = max(DP[x][y], DP[x][y-1]+a*(N-y-i+1))
# print(wa, (x, y), (a, i), DP[x][y])
M = -INF
for x in range(N):
y = N-x
M = max(DP[x][y], M)
print(M)
| 0 | null | 17,961,758,038,080 | 69 | 171 |
rooms = [0] * (4*3*10)
n = input();
for i in xrange(n):
b,f,r,v = map(int, raw_input().split())
rooms[(b-1)*30+(f-1)*10+(r-1)] += v
sep = "#" * 20
for b in xrange(4):
for f in xrange(3):
t = 30*b + 10*f
print ""," ".join(map(str, rooms[t:t+10]))
if b < 3: print sep | a=b=ab=[]
n, m, l = map(int, input().strip().split())
for i in range(m+n):
ab.append(list(map(int, input().strip().split())))
a,b=ab[:n],ab[n:]
for i in range(n):
c = [sum(a[i][k]*b[k][j] for k in range(m)) for j in range(l)]
print(*c) | 0 | null | 1,285,294,266,230 | 55 | 60 |
def call(n):
ans = []
for i, x in enumerate(range(1, n + 1), 1):
if x % 3 == 0:
ans.append(i)
continue
while x:
if x % 10 == 3:
ans.append(i)
break
x //= 10
print(" " + " ".join(map(str, ans)))
if __name__ == '__main__':
from sys import stdin
n = int(stdin.readline().rstrip())
call(n)
| r = int(input())
if 1 <= r <= 100:
print(int(r*r)) | 0 | null | 73,269,457,549,960 | 52 | 278 |
from fractions import gcd
n = int(input())
a = list(map(int, input().split()))
mod = 1000000007
l = 1
for i in range(n):
l = l * a[i] // gcd(l, a[i])
ans = 0
for i in range(n):
ans += l // a[i]
print(ans % mod) | 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 = readline().strip()
if N.count('7') > 0:
print('Yes')
else:
print('No')
return
if __name__ == '__main__':
main()
| 0 | null | 60,802,434,776,160 | 235 | 172 |
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
def input():
return sys.stdin.readline()
def down_pleasure(c_list, day_num, contest_last_day):
"""その日の満足度低下を返す"""
sum_down_pl = 0
for i in range(26):
sum_down_pl += c_list[i] * (day_num - contest_last_day[i])
return sum_down_pl
def calc_pleasure(s_list, t_list, d, c_list, contest_last_day):
pleasure = 0
for day, t_num in zip(range(d), t_list):
pleasure += s_list[day][t_num-1]
contest_last_day[t_num-1] = day + 1
pleasure -= down_pleasure(c_list, day+1, contest_last_day)
print(pleasure)
return pleasure
def resolve():
d = int(input().rstrip())
c_list = list(map(int, input().split()))
s_list = [list(map(int, input().split())) for i in range(d)]
t_list = []
for i in range(d):
t_list.append(int(input().rstrip()))
contest_last_day = []
for i in range(26):
contest_last_day.append(0)
pleasure = calc_pleasure(s_list, t_list, d, c_list, contest_last_day)
if __name__ == "__main__":
resolve()
| D = int(input())
c = list(map(int, input().split()))
s = []
t = []
for _ in range(D):
s.append(list(map(int, input().split())))
for _ in range(D):
t.append(int(input()))
ans = 0
last_date = [0]*26
for day in range(D):
contest = t[day]-1
ans += s[day][contest]
last_date[contest] = day+1
for j in range(26):
ans -= c[j] * (day+1 - last_date[j])
print(ans)
| 1 | 9,948,931,098,458 | null | 114 | 114 |
T1,T2 = map(int, input().split())
A1,A2 = map(int, input().split())
B1,B2 = map(int, input().split())
d1 = (A1-B1)*T1
d2 = (A2-B2)*T2
if d1<0: d1,d2 = -d1,-d2
if d1+d2==0: print("infinity")
elif d1+d2>0: print(0)
elif d1%(-d1-d2) == 0: print(2*(d1//(-d1-d2)))
else: print(2*(d1//(-d1-d2))+1) | n, k, s = map(int, input().split())
#%%
billion = 1000000000
if s == billion:
front = [s] * k
back = [1] * (n - k)
else:
front = [s] * k
back = [s+1] * (n - k)
front.extend(back)
print(*front) | 0 | null | 111,449,671,573,178 | 269 | 238 |
N = int(input())
S = list(input())
M = len(S)
A = [""]*M
for i in range(M):
ref = 65 + (ord(S[i]) + N - 65) % 26
A[i] = chr(ref)
ans = "".join(A)
print(ans) | #!/usr/bin/env python3
a, b = map(int, input().split())
print(a * b * (a < 10 and b < 10) or -1)
| 0 | null | 146,428,642,687,206 | 271 | 286 |
# https://atcoder.jp/contests/panasonic2020/tasks/panasonic2020_c
from decimal import Decimal
import sys
# sys.setrecursionlimit(100000)
def input():
return sys.stdin.readline().strip()
def input_int():
return int(input())
def input_int_list():
return [int(i) for i in input().split()]
def main():
a, b, c = input_int_list()
sqrt_a = Decimal(a)**Decimal("0.5")
sqrt_b = Decimal(b)**Decimal("0.5")
sqrt_c = Decimal(c)**Decimal("0.5")
if sqrt_a + sqrt_b < sqrt_c:
print("Yes")
else:
print("No")
return
if __name__ == "__main__":
main()
| #!/usr/bin/env python
from sys import stdin, stderr
def main():
a, b, c = map(int, stdin.readline().split())
print('Yes' if c-a-b >= 0 and 4*a*b < (c-a-b)**2 else 'No')
return 0
if __name__ == '__main__': main()
| 1 | 51,664,176,746,588 | null | 197 | 197 |
turn = int(input())
point_taro = point_hanako = 0
for i in range(turn):
taro,hanako = input().split()
if taro > hanako:
point_taro += 3
elif hanako > taro:
point_hanako += 3
else:
point_taro += 1
point_hanako += 1
print("{} {}".format(point_taro,point_hanako))
| t,h=0,0
for _ in range(int(input())):
a,b=input().split()
if a>b:t+=3
if a<b:h+=3
if a==b:t+=1;h+=1
print(t,h) | 1 | 1,996,018,808,100 | null | 67 | 67 |
a,b,m=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=[list(map(int,input().split())) for i in range(m)]
lis=[min(A)+min(B)]
for i in range(m):
lis.append(A[C[i][0]-1]+B[C[i][1]-1]-C[i][2])
print(min(lis))
| def selectionSort(A,N):
count = 0
for i in range(0,N-1):
minj = i
for j in range(i+1,N):
if A[j] < A[minj]:
minj = j
tmp = A[minj]
A[minj] = A[i]
A[i] = tmp
if i != minj:
count += 1
return A,count
N = int(input())
A = list(map(int,input().split(' ')))
A,count = selectionSort(A,N)
for i in range(len(A)): # output
if i == len(A) - 1:
print(A[i])
else:
print(A[i], end=' ')
print(count) | 0 | null | 26,950,252,837,832 | 200 | 15 |
# C - Count Order
N = int(input())
P = list(map(int,input().split()))
Q = list(map(int,input().split()))
L = []
def rec(l,s):
if len(l)==N:
L.append(l)
else:
for x in s:
tmp_l = l[:]
tmp_l.append(x)
tmp_s = s[:]
tmp_s.remove(x)
rec(tmp_l,tmp_s)
rec(list(),[i+1 for i in range(N)])
a = 0
while P!=L[a]:
a += 1
b = 0
while Q!=L[b]:
b += 1
print(abs(a-b)) |
def main():
n, k = map(int, input().split(" "))
h = list(map(int, input().split(" ")))
h.sort(reverse = True)
print(sum(h[k:]))
if __name__ == "__main__":
main() | 0 | null | 89,881,875,419,072 | 246 | 227 |
print(eval(input().replace(' ','*'))) | N, M = map(int, input().split())
A = list(map(int, input().split()))
print(max(-1, N-sum(A)))
| 0 | null | 24,088,602,052,320 | 133 | 168 |
n=int(input())
if n<3:
print(0)
elif n%2==0:
print(int((n/2)-1))
else:
print(int(n//2)) | #python 3.7.1
N=int(input())
if (N%2)==0:
ans=N//2-1
else:
ans=N//2
print(ans) | 1 | 152,952,395,036,782 | null | 283 | 283 |
def main():
n = int(input()) % 10
hon = [2, 4, 5, 7, 9]
pon = [0, 1, 6, 8]
bon = [3]
if n in hon:
print("hon")
elif n in pon:
print("pon")
elif n in bon:
print("bon")
if __name__ == '__main__':
main()
| text=input()
n=int(input())
for i in range(n):
order=input().split()
a,b=map(int,order[1:3])
if order[0]=="print":
print(text[a:b+1])
elif order[0]=="reverse":
re_text=text[a:b+1]
text=text[:a]+re_text[::-1]+text[b+1:]
else :
text=text[:a]+order[3]+text[b+1:]
| 0 | null | 10,695,806,034,742 | 142 | 68 |
N, K = [int(v) for v in input().split()]
S = [0] * N
for _ in range(K):
snack = int(input())
snukes = [int(v) for v in input().split()]
for snuke in snukes:
S[snuke-1] = 1
print(sum(x == 0 for x in S))
| n,k = map(int,input().split())
sunuke = []
for _ in range(k):
d = input()
tmp = [int(s) for s in input().split()]
for i in range(len(tmp)):
sunuke.append(tmp[i])
print(n - len(set(sunuke))) | 1 | 24,542,885,778,018 | null | 154 | 154 |
[a, b] = [str(i) for i in input().split()]
A = a*int(b)
B = b*int(a)
s = [A, B]
S = sorted(s)
print(S[0]) | s = input().split()
n = list(map(int, input().split()))
U = input()
n[s.index(U)] -= 1
print(n[0], n[1]) | 0 | null | 78,393,579,217,860 | 232 | 220 |
nums = list(map(int, input().strip()))
nums = nums[::-1]
nums.append(0)
ans = 0
for i in range(len(nums) - 1):
if nums[i] > 5:
ans += 10 - nums[i]
nums[i+1] += 1
elif nums[i] == 5:
if nums[i + 1] >= 5:
nums[i + 1] += 1
ans += 5
else:
ans += nums[i]
ans += nums[-1]
print(ans)
| N = int(input())
P = list(map(int, input().split()))
dp = [0] * N
dp[0] = P[0]
for i in range(1, N):
dp[i] = min(dp[i - 1], P[i])
res = 0
for i in range(N):
if dp[i] >= P[i]:
res += 1
print(res) | 0 | null | 78,145,903,924,292 | 219 | 233 |
H = int(input())
count = 1
ans = 0
while H>0:
H = int(H//2)
ans += count
count *= 2
print(ans) | H=int(input())
m=1
while (m<=H):
m*=2
print(m-1) | 1 | 80,003,484,619,200 | null | 228 | 228 |
#!/usr/bin/python
# -*- coding: utf-8 -*-
# def
def int_mtx(N):
x = []
for _ in range(N):
x.append(list(map(int,input().split())))
return np.array(x)
def str_mtx(N):
x = []
for _ in range(N):
x.append(list(input()))
return np.array(x)
def int_map():
return map(int,input().split())
def int_list():
return list(map(int,input().split()))
def print_space(l):
return print(" ".join([str(x) for x in l]))
# import
import numpy as np
import collections as col
from scipy.sparse.csgraph import connected_components
from scipy.sparse import csr_matrix
# main
N,M =int_map()
AB = int_mtx(M)
n, _ = connected_components(csr_matrix(([1]*M, (AB[:,0]-1, AB[:,1]-1)),(N,N)))
print(n-1) | #!/usr/bin/env python3
class UnionFind():
def __init__(self, n):
self.n = n
self.root = [-1] * (n + 1)
self.rnk = [0] * (n + 1)
def Find_Root(self, x):
if self.root[x] < 0:
return x
else:
self.root[x] = self.Find_Root(self.root[x])
return self.root[x]
def Unite(self, x, y):
x = self.Find_Root(x)
y = self.Find_Root(y)
if x == y:
return
elif self.rnk[x] > self.rnk[y]:
self.root[x] += self.root[y]
self.root[y] = x
else:
self.root[y] += self.root[x]
self.root[x] = y
if self.rnk[x] == self.rnk[y]:
self.rnk[y] += 1
def roots(self):
return [i for i, x in enumerate(self.root) if x < 0]
def group_count(self):
return len(self.roots())
def main():
n, m = map(int, input().split())
UF = UnionFind(n)
for _ in range(m):
a, b = map(int, input().split())
UF.Unite(a, b)
print(UF.group_count() - 2)
if __name__ == "__main__":
main()
| 1 | 2,243,244,908,140 | null | 70 | 70 |
X,N = map(int,input().split())
p = list(map(int,input().split()))
if not X in p:
print(X)
else:
for i in range(100):
if not (X-i) in p:
print(X-i)
break
elif not (X+i) in p:
print(X+i)
break
| X,N = map(int,input().split())
p = list(map(int,input().split()))
count = -1
while True:
count +=1
if X-count not in p:
print(X-count)
break
elif X+count not in p:
print(X+count)
break | 1 | 14,042,224,652,680 | null | 128 | 128 |
# 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 math
x1,y1,x2,y2 = tuple(float(n) for n in input().split())
D = math.sqrt((x2-x1)**2 + (y2-y1)**2)
print("{:.8f}".format(D))
| 1 | 151,597,925,312 | null | 29 | 29 |
a, b, c, k = map(int, input().split())
if k - a <= 0:
print(k)
elif k - a > 0 and k - a - b <= 0:
print(a)
else:
s = k - a - b
print(a - s)
| a, b, m = map(int, input().split())
re = list(map(int, input().split()))
de = list(map(int, input().split()))
mre = min(re)
mde = min(re)
list1 = []
for i in range(m):
x, y, c = map(int, input().split())
price = re[x-1] + de[y-1] -c
list1.append(price)
mlist = min(list1)
m1 = mre + mde
if m1 < mlist:
print(m1)
else:
print(mlist)
| 0 | null | 37,844,317,087,148 | 148 | 200 |
n = int(input())
dp = [1, 1]
for i in range(2, n + 1):
dp = [dp[-1], dp[-2] + dp[-1]]
print(dp[-1])
| n = int(input())
for i in range(1,n+1):
if i % 3 == 0 or i % 10 == 3:
print(" {}".format(i), end='')
else:
x = i
while True:
x = x // 10
if x == 0:
break
elif x % 10 == 3:
print(" {}".format(i), end='')
break
print("") | 0 | null | 469,524,186,548 | 7 | 52 |
x = input()
print pow(x, 3) | num = input()
num = int(num)
print(num**3) | 1 | 288,580,204,210 | null | 35 | 35 |
h , w , k = map(int,input().split())
cho = [list(input()) for i in range(h)]
ans = 10**9
for i in range(2**(h-1)):
cut = [0 for i in range(h)]
for j in range(h-1):
if i >> j & 1 == 1:
cut[j+1] = cut[j]+1
else:
cut[j+1] = cut[j]
maxcut = max(cut)+1
cou = [0 for i in range(maxcut)]
ccho = [[0 for i in range(w)] for j in range(maxcut)]
for j in range(h):
for l in range(w):
ccho[cut[j]][l] += int(cho[j][l])
tyu = maxcut - 1
hukanou = False
for j in range(w):
flag = True
for l in range(maxcut):
if cou[l] + ccho[l][j] > k:
flag = False
break
if flag:
for l in range(maxcut):
cou[l] += ccho[l][j]
elif not flag:
tyu += 1
for l in range(maxcut):
if ccho[l][j] > k:
hukanou = True
break
cou[l] = ccho[l][j]
if hukanou:
break
if hukanou:
continue
ans = min(ans,tyu)
print(ans) |
from bisect import bisect_right
N, D, A = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
X.sort()
place = []
hps = []
for x, h in X:
place.append(x)
hps.append(h)
buf = [0] * (N + 2)
ans = 0
for i in range(N):
# Update
buf[i + 1] += buf[i]
# Calc count
tmp = -(-max(0, hps[i] - buf[i + 1] * A) // A)
ans += tmp
# Calc range
j = bisect_right(place, place[i] + D * 2)
buf[i + 1] += tmp
buf[min(j + 1, N + 1)] -= tmp
print(ans)
| 0 | null | 65,355,286,536,192 | 193 | 230 |
n = input()
K = int(input())
L = len(n)
dp = [[[0] * (K + 2) for _ in range(2)] for __ in range(L + 1)]
dp[0][1][0] = 1
for i in range(L):
d = int(n[i])
for j in [0, 1]:
for k in range(K + 1):
if j == 0:
dp[i + 1][j][k] += dp[i][j][k]
dp[i + 1][j][k + 1] += dp[i][j][k] * 9
else:
if d > 0:
dp[i + 1][0][k] += dp[i][j][k]
dp[i + 1][0][k + 1] += dp[i][j][k] * (d - 1)
dp[i + 1][1][k + 1] += dp[i][j][k]
else:
dp[i + 1][1][k] += dp[i][j][k]
print(dp[L][0][K] + dp[L][1][K])
| def main():
l = int(input())
num = l / 3
print(num**3)
if __name__ == "__main__":
main()
| 0 | null | 61,592,933,668,992 | 224 | 191 |
def main(S):
rains = S.split('S')
return max([len(r) for r in rains])
if __name__ == '__main__':
S = input()
ans = main(S)
print(ans)
| N = int(input())
A = [int(a) for a in input().split(" ")]
swop = 0
for i, a in enumerate(A):
j = N - 1
while j >= i + 1:
if A[j] < A[j - 1]:
tmp = A[j]
A[j] = A[j - 1]
A[j - 1] = tmp
swop += 1
j -= 1
print(" ".join([str(a) for a in A]))
print(swop) | 0 | null | 2,436,444,935,300 | 90 | 14 |
N,M = map(int, input().split())
S = input()
cnt = 0
for s in S:
if s == "0":
cnt = 0
else:
cnt += 1
if cnt >= M:
print(-1)
exit()
"""
辞書順最小
・より少ない回数でゴール
・同じ回数なら、低い数字ほど左にくる
N歩先がゴール → 出目の合計がNになったらOK
iマス目を踏むとゲームオーバー → 途中で出目の合計がiになるとアウト
ただ、辞書順が厄介
N=4, 00000があったとして、M=3の場合、3->1より1->3の方が辞書順で若い。なので、スタート地点から貪欲に進めるだけ進む、は条件を満たさない。
→ ゴールからスタートに帰る。移動方法は貪欲にする。
"""
ans = []
rS = S[::-1]
l = 0
r = 1
while l < N:
r = l + 1
stoppable = l
while r - l <= M and r <= N:
if rS[r] == "0":
stoppable = r
r += 1
ans.append(stoppable - l)
l = stoppable
print(*ans[::-1]) | import sys
input = sys.stdin.readline
N, M = map(int, input().split())
S = input().rstrip()
A = [0]*N
cnt = 0
S = reversed(S)
for i, s in enumerate(S):
if s=="1":
cnt += 1
A[i] = cnt
else:
cnt = 0
dp = 0
res = []
while dp+M <= N-1:
t = M - A[dp+M]
if t>0:
dp += t
else:
print(-1)
exit()
res.append(t)
res.append(N-dp)
res.reverse()
print(*res) | 1 | 139,076,157,424,672 | null | 274 | 274 |
N, M = map(int, input().split())
A = sum(map(int, input().split()))
if N-A >= 0:
print(N-A)
else:
print(-1)
| N, M = input().split()
N = int(N)
M = int(M)
A = list(map(int, input().split()))
LA = len(A)
i = 0
SUM = 0
for i in range(LA):
SUM = SUM + A[i]
if SUM > N:
print('-1')
else:
print(N - SUM) | 1 | 32,154,846,110,052 | null | 168 | 168 |
# input
N, M = map(int, list(input().split()))
A = list(map(int, input().split()))
# process
A.sort(reverse=True)
# 1回の握手の幸福度がx以上となるものの数、幸福度の合計を求める
def calc(x):
count, sum = 0, 0
j, t = 0, 0
for i in reversed(range(N)):
while j < N and A[i]+A[j] >= x:
t += A[j]
j += 1
count += j
sum += A[i]*j + t
return (count, sum)
# 2分探索で答えを求める
def binary_search(x, y):
mid = (x+y)//2
count, sum = calc(mid)
if count < M:
return binary_search(x, mid)
else:
if x == mid:
print(sum-(count-M)*mid)
else:
return binary_search(mid, y)
# 実行
binary_search(0, A[0]*2+1)
| while True:
x,y =map(int, raw_input().split())
if(x==0 and y==0):
break
elif(x>y):
print y,x
elif(x<=y):
print x,y | 0 | null | 54,059,484,140,160 | 252 | 43 |
N = int(input())
data = [input() for _ in range(N)]
def f(s):
c = len([x for x in data if x in s])
print(f"{s} x {c}")
f("AC")
f("WA")
f("TLE")
f("RE")
| d=input()
arr = [int(i) for i in d.split()]
t1 = arr[0]/arr[-1]
if t1<= arr[1]:
print("Yes")
else:
print("No")
| 0 | null | 6,134,759,082,690 | 109 | 81 |
a, b = map(int, input().split())
print("a < b" if a < b else "a > b" if a > b else "a == b")
| input()
print(1 if int(input().split()[1])==1 else 0) | 0 | null | 62,509,153,688,830 | 38 | 264 |
def main(h: int, w: int, n: int):
m = max(h, w)
if n % m == 0:
print(n // m)
else:
print((n // m) + 1)
if __name__ == "__main__":
h = int(input())
w = int(input())
n = int(input())
main(h, w, n)
| import sys
def input(): return sys.stdin.readline().rstrip()
def main():
h=int(input())
w=int(input())
n=int(input())
print(-(-n//max(h,w)))
if __name__=='__main__':
main() | 1 | 88,329,568,285,980 | null | 236 | 236 |
n = int(input())
arm = []
for _ in range(n):
x, l = map(int,input().split())
arm.append([x-l, x+l])
arm.sort(key=lambda x: x[1])
cnt = 0
pr = -float('inf')
for a in arm:
if pr <= a[0]:
cnt += 1
pr = a[1]
print(cnt)
| #!/usr/bin/env python3
x, y = map(int, input().split())
ans = (x == y == 1) * 400000
ans += 100000 * max(0, 4 - x)
ans += 100000 * max(0, 4 - y)
print(ans)
| 0 | null | 115,861,405,570,108 | 237 | 275 |
n,k=map(int,input().split())
cnt=[0]*(k+1)
mod=10**9+7
for i in range(1,k+1):
cnt[i]=pow(k//i,n,mod)
#print(cnt)
for i in range(k):
baisu=k//(k-i)
for j in range(2,baisu+1):
cnt[k-i]=(cnt[k-i]-cnt[(k-i)*j]+mod)%mod
ans=0
for i in range(1,k+1):
ans+=i*cnt[i]
ans%=mod
print(ans) | import sys
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, d=DVSR): return pow(x, d - 2, d)
def DIV(x, y, d=DVSR): return (x * INV(y, d)) % d
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())
N,K=LI()
BUF=[0]*(K+1)
for i in reversed(range(1, K+1)):
pat = POW(K//i, N)
for j in range(2, K+1):
if i*j <= K:
pat -= BUF[i*j]
else:
break
# print("pat:{} i:{}".format(pat, i))
BUF[i] = pat
res = 0
for i, j in enumerate(BUF):
res += (i*j) % DVSR
print(res%DVSR)
| 1 | 36,812,061,531,102 | null | 176 | 176 |
S = input()
T = input()
lt, ls = len(T), len(S)
def diff(s1, s2):
d = len(s1)
d -= len([i for i,j in zip(s1, s2) if i == j])
return d
dlen = min([diff(T, S[i:i+lt]) for i in range(ls) if i + lt <= ls])
print(dlen)
| S = input()
T = input()
min_dist = 10**10
for i in range(len(S) - len(T) + 1):
for k in range(len(T)):
dist = 0
for s, t in zip(S[i:i + len(T)], T):
if s != t:
dist += 1
if dist >= min_dist:
break
min_dist = min(dist, min_dist)
if min_dist == 0:
print(0)
exit()
print(min_dist)
| 1 | 3,686,369,390,158 | null | 82 | 82 |
N,K = map(int,input().split())
R,S,P = map(int,input().split())
T = input()
li = [-1]*N #グー、チョキ、パー
se = set(["r","s","p"])
dic = {"r":"p","s":"r","p":"s"}
score = {"r":0,"s":0,"p":0}
#iはあまりでi+k*a
num = N//K
for i in range(K):
for a in range(num+1):
nex = i + K*a
if nex>N-1:
break
rival = T[nex]
kati = dic[rival]
if nex<K:
li[nex]=kati
score[kati]+=1
elif not kati==li[nex-K]:
li[nex]=kati
score[kati]+=1
#elif kati==li[nex-k]:
# if nex+k>N-1:
# else:
print(score["r"]*R+score["s"]*S+score["p"]*P)
| n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=input()
a=[]
for i in range(k):
a.append([])
for i in range(n):
a[i%k].append(t[i])
for i in range(k):
for j in range(len(a[i])):
if j>=1:
if a[i][j]==a[i][j-1]:
a[i][j]=0
ans=0
for i in range(k):
for j in range(len(a[i])):
if a[i][j]=="r":
ans+=p
elif a[i][j]=="s":
ans+=r
elif a[i][j]=="p":
ans+=s
print(ans) | 1 | 106,769,425,228,178 | null | 251 | 251 |
# ゴール:3.5.15の倍数 以外の数字を合計したい
N = int(input())
sum_exclusion = 0 # 計算結果を入れる変数
for i in range(1, N + 1):
if not (i % 15 == 0 or i % 3 == 0 or i % 5 == 0):
sum_exclusion += i # rangeが空になるまで、条件に合う数値が足されていく
print(sum_exclusion)
| n = int(input())
ans = sum(x for x in range(1, n+1) if x % 3 != 0 and x % 5 != 0)
print(ans)
| 1 | 34,828,676,680,320 | null | 173 | 173 |
#!/usr/bin/env python3
def pow(N,R,mod):
ans = 1
i = 0
while((R>>i)>0):
if (R>>i)&1:
ans *= N
ans %= mod
N = (N*N)%mod
i += 1
return ans%mod
def main():
N,K = map(int,input().split())
li = [0 for _ in range(K)]
mod = 10**9+7
ans = 0
for i in range(K,0,-1):
mm = K//i
mm = pow(mm,N,mod)
for j in range(2,(K//i)+1):
mm -= li[i*j-1]
li[i-1] = mm
ans += (i*mm)%mod
ans %= mod
print(ans)
if __name__ == '__main__':
main()
| n,k=map(int,input().split())
MOD=10**9+7
ans=0
baig=[0]*(10**5+1)
exg=[0]*(10**5+1)
for i in range(1,k+1):
baig[i]=pow(k//i,n,MOD)
for j in range(k,0,-1):
exg[j]=baig[j]
for jj in range(2*j,k+1,j):
exg[j]-=exg[jj]
exg[j]%=MOD
ans+=exg[j]*j
ans%=MOD
print(int(ans))
| 1 | 36,787,014,044,802 | null | 176 | 176 |
import sys
from bisect import bisect_left, bisect_right, insort
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N = ir()
S = list('-' + sr())
d = [[] for _ in range(26)]
for i in range(1, N+1):
s = S[i]
o = ord(s) - ord('a')
d[o].append(i)
Q = ir()
for _ in range(Q):
q, a, b = sr().split()
if q == '1':
a = int(a)
if S[a] == b:
continue
prev = ord(S[a]) - ord('a')
d[prev].pop(bisect_left(d[prev], a))
next = ord(b) - ord('a')
insort(d[next], a)
S[a] = b
else:
a = int(a); b = int(b)
ans = 0
for alpha in range(26):
if bisect_right(d[alpha], b) - bisect_left(d[alpha], a) >= 1:
ans += 1
print(ans)
| # Binary Indexed Tree (Fenwick Tree)
class BIT:
def __init__(self, n):
self.n = n
self.bit = [0]*(n+1)
self.el = [0]*(n+1)
def sum(self, i):
s = 0
while i > 0:
s += self.bit[i]
i -= i & -i
return s
def add(self, i, x):
# assert i > 0
self.el[i] += x
while i <= self.n:
self.bit[i] += x
i += i & -i
def get(self, i, j=None):
if j is None:
return self.el[i]
return self.sum(j) - self.sum(i-1)
def lower_bound(self,x):
w = i = 0
k = 1<<((self.n).bit_length())
while k:
if i+k <= self.n and w + self.bit[i+k] < x:
w += self.bit[i+k]
i += k
k >>= 1
return i+1
def alph_to_num(s):
return ord(s)-ord('a')
def solve():
N = int(input())
S = list(map(alph_to_num,list(input())))
Q = int(input())
bits = [BIT(N) for _ in range(26)]
for i in range(N):
bits[S[i]].add(i+1,1)
ans = []
for _ in range(Q):
x,y,z = input().split()
y = int(y)
if x=='1':
z = alph_to_num(z)
bits[S[y-1]].add(y,-1)
S[y-1] = z
bits[z].add(y,1)
if x=='2':
z = int(z)
ans.append(sum([bits[i].get(y,z)>0 for i in range(26)]))
return ans
print(*solve(),sep='\n') | 1 | 62,297,777,653,200 | null | 210 | 210 |
from itertools import accumulate
from bisect import bisect
n, m, k = map(int, input().split())
a = [0] + list(map(int, input().split()))
b = [0] + list(map(int, input().split()))
a = list(accumulate(a))
b = list(accumulate(b))
ans = 0
for i in range(n+1):
if a[i] > k:
break
ans = max(ans, i+bisect(b, k-a[i])-1)
print(ans) | N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
sumA=[0]
for i in range(N):
sumA.append(sumA[-1]+A[i])
sumB=[0]
for i in range(M):
sumB.append(sumB[-1]+B[i])
ans=0
for i in range(N+1):
k=K-sumA[i]
if k<0:
break
left=0
right=M
while right>=left:
mid=(right+left)//2
if sumB[mid]>k:
right=mid-1
else:
left=mid+1
l=right
ans=max(ans,i+l)
print(ans) | 1 | 10,635,363,093,488 | null | 117 | 117 |
def main() :
n = int(input())
nums = [int(i) for i in input().split()]
flag = True
count = 0
index = 0
while flag :
flag = False
for i in reversed(range(index+1, n)) :
if nums[i-1] > nums[i] :
nums[i-1], nums[i] = nums[i], nums[i-1]
count += 1
flag = True
index += 1
nums_str = [str(i) for i in nums]
print(" ".join(nums_str))
print(count)
if __name__ == '__main__' :
main() |
def prime_factorization(n):
"""do prime factorization using trial division
Returns:
[[prime1,numbers1],[prime2,numbers2],...]
"""
res = []
for i in range(2,int(n**0.5)+1):
if n%i==0:
cnt=0
while n%i==0:
cnt+=1
n//=i
res.append([i,cnt])
if n!=1:
res.append([n,1])
return res
def main():
import sys
input = sys.stdin.readline
N = int(input())
prime_factors = prime_factorization(N)
ans = 0
for p in prime_factors:
i = 1
while i <= p[1]:
ans += 1
N /= p[0]**i
p[1] -= i
i += 1
print(ans)
if __name__ == '__main__':
main()
| 0 | null | 8,413,170,657,710 | 14 | 136 |
n, t = map(int, input().split())
ab = []
for _ in range(n):
ab.append(list(map(int, input().split())))
ab.sort(key=lambda x:x[0])
dp = [-1]*(t+1)
dp[0] = 0
for a, b in ab:
tmp = dp[:]
for i in range(t):
if dp[i] >= 0 and dp[i]+b > tmp[min(i+a, t)]:
tmp[min(i+a, t)] = dp[i]+b
dp = tmp
print(max(dp)) | import sys
def input():
return sys.stdin.readline()[:-1]
n, p = map(int, input().split())
snacks = sorted([list(map(int, input().split())) for _ in range(n)], key=lambda x: x[0])
dp = [0 for _ in range(p)]
ans = snacks[0][1]
for i in range(1, n):
x, y = snacks[i-1]
z = snacks[i][1]
for j in range(p-1, 0, -1):
if j >= x:
dp[j] = max(dp[j], dp[j-x]+y)
ans = max(ans, dp[j]+z)
print(ans) | 1 | 151,245,243,239,520 | null | 282 | 282 |
# -*- coding:utf-8 -*-
import sys
import math
array =[]
for line in sys.stdin:
array.append(line)
for i in range(len(array)):
num = array[i].split(' ')
a = int(num[0])
b = int(num[1])
n = a + b
print(int(math.log10(n) + 1)) | import sys
values = []
for line in sys.stdin:
values.append([int(x) for x in line.split()])
digit = 0
for x, y in values:
sum = x + y; digit = 0
while sum >= 1:
sum //= 10
digit += 1
print(digit) | 1 | 69,875,650 | null | 3 | 3 |
n, k = map(int, input().split())
h = list(map(int, input().split()))
h.sort()
s = min(k, n)
if s:
answer = sum(h[:-s])
else:
answer = sum(h)
print(answer)
| ord_list = []
str_in = input()
n = int(input())
for i in range(n):
try:
l = list(map(str,input().split()))
except ValueError:
l = list(map(str,input().split()))
ord_list.append(l)
for l in ord_list:
o = l[0]
a,b = int(l[1]), int(l[2])
if o == 'replace':
str_in= str_in[:a] + l[3] + str_in[b+1:]
elif o == 'reverse':
str_in= str_in[:a] + str_in[a:b+1][::-1] + str_in[b+1:]
elif o == 'print':
print(str_in[a:b+1]) | 0 | null | 40,507,979,687,068 | 227 | 68 |
a, b = map(int, input().split())
if (a >= 1 and a <= 1000000000) and (b >= 1 and b <= 1000000000):
d = int(a / b)
r = int(a % b)
f = float(a / b)
print("{0:d} {1:d} {2:f}".format(d, r, f))
else:
pass | sum = 0
for s in input():
sum += int(s)
print('Yes' if sum%9==0 else 'No') | 0 | null | 2,520,839,069,506 | 45 | 87 |
h, w = map(int, input().split())
if h == 1 or w == 1:
print(1)
else:
print((-(-w//2)) * (-(-h//2)) + (w//2) * (h//2))
| n = int(input())
a = list(map(int, input().split()))
def num_left(pos):
if pos % 2 == 0:
return (n - pos) // 2 + 1
else:
return (n - pos - 1) // 2 + 1
d = [{} for i in range(n)]
for i in range(n):
if i < 2:
d[i][0] = 0
d[i][1] = a[i]
else:
left = num_left(i + 2)
#print("i = ", i, left)
j = i - 2
while j >= 0:
max_count = max(d[j].keys())
if max_count + left + 1 < n // 2:
break
else:
for count, v in d[j].items():
#print(count, v)
if count + left + 1 >= n // 2:
if count + 1 in d[i]:
d[i][count + 1] = max(d[i][count + 1], v + a[i])
else:
d[i][count + 1] = v + a[i]
j -= 1
if 1 + left >= n // 2:
d[i][0] = 0
best = None
for i in range(n):
for count, result in d[i].items():
if count == n // 2:
if best is None:
best = result
else:
best = max(best, result)
#print(d)
print(best)
| 0 | null | 43,920,461,151,200 | 196 | 177 |
while True:
h, w = map(int, input().split(" "))
if h == 0 and w == 0:
break
print(("#"*w + "\n") * h) | while True:
H, W = map(int, input().split())
if H == 0 and W == 0:
break
square = [['#'] * W] * H
for row in square:
print(''.join(row))
print()
| 1 | 772,457,746,260 | null | 49 | 49 |
n = int(input())
result = [""]
for i in range(3, n + 1):
if i % 3 == 0:
result.append(i)
elif "3" in list((str(i))):
result.append(i)
print(*result) | L,R,d=map(int,input().split());print(R//d-(L-1)//d) | 0 | null | 4,256,972,341,952 | 52 | 104 |
n = int(input())
s = input()
if(n % 2 == 0 and s[n//2:] * 2 == s):
print("Yes")
else:
print("No") | def getList():
return list(map(int, input().split()))
a, b = getList()
if a > 9 or b > 9:
print(-1)
else:
print(a*b) | 0 | null | 152,338,302,250,912 | 279 | 286 |
# 1 <= N <= 1000000
N = int(input())
total = []
# N項目までに含まれる->N項目は含まない。だからN項目は+1で外す。
for x in range(1, N+1):
if x % 15 == 0:
"FizzBuzz"
elif x % 5 == 0:
"Buzz"
elif x % 3 == 0:
"Fizz"
else:
total.append(x) #リストに加える
print(sum(total)) | def main():
n = int(input())
ans = 0
for i in range(1, n + 1):
if (i % 3 != 0) and (i % 5 != 0):
ans += i
print(ans)
main()
| 1 | 34,994,053,365,050 | null | 173 | 173 |
x = input()
num = int(x)
print(num*num*num) | x = input()
n = int(x)*int(x)*int(x)
print(n)
| 1 | 273,360,242,454 | null | 35 | 35 |
def solve():
N, P = map(int, input().split())
S = input()
if P == 2 or P == 5:
res = 0
for i in range(N):
if int(S[i]) % P == 0:
res += i + 1
print(res)
else:
res = 0
count = [0] * P
r = 0
for i in range(N-1, -1, -1):
r = (int(S[i]) * pow(10, N-1 - i, P) + r) % P
if r == 0: res += 1
res += count[r]
count[r] += 1
print(res)
if __name__ == '__main__':
solve()
| #!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
"""
[解法メモ]
各桁(桁数iとする)を10**i mod pの形で持っておく.
それの累積和をとって, 再びmod pをとると, 同じ数のペアの範囲はpの倍数になっていることが分かる.(他の問題でもこの解法あった気がする)
よって, 答えは同じ数のペアの数をすべて足したもの.
pが2や5の場合, *10が付くと必ず割り切れるので注意.
つまり, 1桁目が割り切れたら必ず割り切れる.⇒各桁を見ていってpで割り切れるならそれ以前の数を足せば良い.
(例)p=5, s=100のとき
1は割り切れないからx
0は割り切れるからo ⇒ 2桁目なので+2(10,0の場合)
0は割り切れるからo ⇒ 3桁目なので+3(100,00,0の場合)
⇒答えは5
"""
n, p = LI()
s = list(map(int,list(input())))
t = []
ans = 0
if p == 2 or p == 5:
for i in range(n):
if s[i] % p == 0:
ans += i+1
print(ans)
quit()
for i in range(n):
t.append(s[i]*pow(10,n-i-1,p))
t = list(accumulate(t))
u = [i % p for i in t]
u = list(Counter(u).items())
ans = 0
for i,j in u:
if i == 0:
ans += j
if j >= 2:
ans += j*(j-1) // 2
print(ans)
| 1 | 58,550,136,461,920 | null | 205 | 205 |
n = int(input())
full_set=set([x for x in range(1,14)])
cards={"S":[],"H":[],"C":[],"D":[]}
for i in range(n):
suit,num = input().split()
cards[suit].append(int(num))
for suit in ["S","H","C","D"]:
suit_set = set(cards[suit])
for num in sorted(list(full_set - suit_set)): print(suit,num) | n=input()
s1= input()
count=0
for i in range(len(s1)-2):
if(s1[i]=='A' and s1[i+1]=='B' and s1[i+2]=='C'):
count=count+1
print(count) | 0 | null | 50,367,866,802,110 | 54 | 245 |
n=int(input())
A=[int(x) for x in input().split()]
u=10**6+1
C=[0]*u
D=[0]*2+[1]*(u-2)
def gcd(a,b):
while a%b:
a,b=b,a%b
return b
n=4
while n<u:
D[n]=0
n+=2
i=3
while i*i<u:
if D[i]:
n=i*2
while n<u:
D[n]=0
n+=i
i+=2
for a in A:
C[a]+=1
for i in [x for x in range(2,u) if D[x]==1]:
if sum(C[i::i])>1:
break
else:
print('pairwise coprime')
exit()
c=A[0]
for a in A:
c=gcd(c,a)
if c==1:
break
else:
print('not coprime')
exit()
print('setwise coprime')
| from math import gcd
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:
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")
| 1 | 4,080,340,186,142 | null | 85 | 85 |
n,m=map(int,input().split())
s=input()
ans=[]
now=n
while now>0:
for i in range(m,0,-1):
if now-i<0:
continue
if s[now-i]=='0':
ans.append(str(i))
now-=i
break
else:
print(-1)
exit()
print(' '.join(ans[::-1])) |
N,M = map(int, input().split())
S = input()
cnt = 0
for s in S:
if s == "0":
cnt = 0
else:
cnt += 1
if cnt >= M:
print(-1)
exit()
"""
辞書順最小
・より少ない回数でゴール
・同じ回数なら、低い数字ほど左にくる
N歩先がゴール → 出目の合計がNになったらOK
iマス目を踏むとゲームオーバー → 途中で出目の合計がiになるとアウト
ただ、辞書順が厄介
N=4, 00000があったとして、M=3の場合、3->1より1->3の方が辞書順で若い。なので、スタート地点から貪欲に進めるだけ進む、は条件を満たさない。
→ ゴールからスタートに帰る。移動方法は貪欲にする。
"""
ans = []
rS = S[::-1]
l = 0
r = 1
while l < N:
r = l + 1
stoppable = l
while r - l <= M and r <= N:
if rS[r] == "0":
stoppable = r
r += 1
ans.append(stoppable - l)
l = stoppable
print(*ans[::-1]) | 1 | 138,767,144,747,072 | null | 274 | 274 |
import sys
from collections import defaultdict
sys.setrecursionlimit(10**8)
N = int(input())
graph = [[] for _ in range(N)]
numOfEdges = [0 for _ in range(N)]
visited = [0 for _ in range(N)]
edges = defaultdict(int)
for i in range(1, N):
a, b = map(int, input().split())
a -= 1; b -= 1;
numOfEdges[a] += 1
numOfEdges[b] += 1
edges[(a, b)] = 0
graph[a].append(b)
graph[b].append(a)
def dfs(prev, now, col):
if visited[now]:
return
visited[now] = 1
i = 1
for adj in graph[now]:
if adj == prev:
continue
if now < adj:
edges[(now, adj)] = col + i
else:
edges[(adj, now)] = col + i
dfs(now, adj, col+i)
i += 1
dfs(-1, 0, 1)
maxColor = max(numOfEdges)
print(maxColor)
for k, i in edges.items():
e = i % maxColor
if e:
print(e)
else:
print(maxColor)
| a,b = map(int, input().split())
print(f'{a//b} {a%b} {(a/b):.6f}')
| 0 | null | 68,033,977,140,708 | 272 | 45 |
n = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
ans = A[0]
if n%2 == 0:
ans += sum(A[1:n//2])*2
else:
ans += sum(A[1:n//2])*2 + A[n//2]
print(ans) | s = input()
week = ["SUN","MON","TUE","WED","THU","FRI","SAT"]
idx = week.index(s)
print(7-idx) | 0 | null | 70,935,699,796,720 | 111 | 270 |
N = int(input())
a = [int(i) for i in input().split()]
count = 0
for i in range(N):
minj = i
for j in range(i,N):
if a[j] < a[minj]:
minj = j
if i != minj:
count += 1
a[i], a[minj] = a[minj], a[i]
print(" ".join(map(str, a)))
print(count) | import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
def resolve():
l, r, d = map(int, input().split())
print(r // d - (l - 1) // d)
resolve() | 0 | null | 3,800,642,948,872 | 15 | 104 |
n = input()
#a,b = map(str,raw_input().split())
a = [raw_input() for i in range(n)]
j=0
for i in range(1,14):
for j in range(n):
if a[j] == 'S %s' % i:
break
elif j==n-1:
print 'S %s' % i
for i in range(1,14):
for j in range(n):
if a[j] == 'H %s' % i:
break
elif j==n-1:
print 'H %s' % i
for i in range(1,14):
for j in range(n):
if a[j] == 'C %s' % i:
break
elif j==n-1:
print 'C %s' % i
for i in range(1,14):
for j in range(n):
if a[j] == 'D %s' % i:
break
elif j==n-1:
print 'D %s' % i | pictures = ['S','H','C','D']
card_li = []
for i in range(4):
for j in range(1,14):
card_li.append(pictures[i] + ' ' + str(j))
n = int(input())
for i in range(n): del card_li[card_li.index(input())]
for i in card_li:
print(i) | 1 | 1,060,527,681,600 | null | 54 | 54 |
s = input()
t = input()
ans = len(t)
for i in range(len(s)-len(t)+1):
count = 0
for j in range(len(t)):
if s[i+j]!=t[j]:
count += 1
# print(count)
ans = min(ans, count)
print(ans)
| # import itertools
# import math
# import sys
# sys.setrecursionlimit(500*500)
# import numpy as np
N = int(input())
S = input()
# n, *a = map(int, open(0))
# N, M = map(int, input().split())
# A = list(map(int, input().split()))
# B = list(map(int, input().split()))
# tree = [[] for _ in range(N + 1)]
# B_C = [list(map(int,input().split())) for _ in range(M)]
# S = input()
# B_C = sorted(B_C, reverse=True, key=lambda x:x[1])
# all_cases = list(itertools.permutations(P))
# a = list(itertools.combinations_with_replacement(range(1, M + 1), N))
# itertools.product((0,1), repeat=n)
# A = np.array(A)
# cum_A = np.cumsum(A)
# cum_A = np.insert(cum_A, 0, 0)
# def dfs(tree, s):
# for l in tree[s]:
# if depth[l[0]] == -1:
# depth[l[0]] = depth[s] + l[1]
# dfs(tree, l[0])
# dfs(tree, 1)
all = S.count("R") * S.count("G") * S.count("B")
cnt = 0
for i in range(N):
for j in range(i, N):
k = 2 * j - i
if k >= N:
continue
if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
cnt += 1
print(all - cnt) | 0 | null | 19,823,636,870,270 | 82 | 175 |
n, d = map(int, input().split())
cnt = 0
for i in range(n):
Z = list(map(int, input().split()))
X = Z[0]
Y = Z[1]
if X**2 + Y**2 <= d**2:
cnt += 1
print(cnt)
| N,D = map(int,input().split())
count = 0
for i in range(N):
x,y = map(int,input().split())
if x**2+y**2 <= D**2:
count = count + 1
else:
count = count + 0
print(count) | 1 | 5,941,740,829,558 | null | 96 | 96 |
d=int(input())
a=[0 for i in range(26)]
c=list(map(int,input().split()))
l=[]
for i in range(d):
l.append(list(map(int,input().split())))
#print(c.index(max(c))+1)
p=[0]
for i in range(1,d+1):
t=int(input())-1
a[t]=i
k=0
for j in range(26):
k+=c[j]*(i-a[j])
p.append(p[i-1]+l[i-1][t]-k)
print(*p[1:],sep='\n') | D = int(input())
Cs = list(map(int,input().split()))
Ss = [list(map(int,input().split())) for i in range(D)]
ts = []
for i in range(D):
ts.append(int(input()))
last = [0]*26
satisfy = 0
for day,t in enumerate(ts):
day += 1
last[t-1] = day
satisfy += Ss[day-1][t-1]
for i in range(26):
satisfy -= Cs[i]*(day-last[i])
print(satisfy) | 1 | 10,025,911,238,512 | null | 114 | 114 |
import sys
sys.setrecursionlimit(1000000)
n=int(input())
a=[0]*(n-1)
b=[0]*(n-1)
edge=[[] for i in range(n)]
k=0
for i in range(n-1):
a[i],b[i]=map(int,input().split())
a[i]-=1
b[i]-=1
edge[b[i]].append(a[i])
edge[a[i]].append(b[i])
color_dict={}
def dfs(x, last=-1, ban_color=-1):
global k
color=1
for to in edge[x]:
if to==last:
continue
if color==ban_color:
color+=1
color_dict[(x,to)]=color
k=max(k,color)
dfs(to,x,color)
color+=1
dfs(0)
print(k)
for i in range(n-1):
if (a[i],b[i]) in color_dict:
print(color_dict[(a[i],b[i])])
else:
print(color_dict[(b[i],a[i])]) | # 木なので親から繋がっている1辺のみ色が塗られている状態(根に限っては何も塗られていない)
N = int(input())
AB = [list(map(int, input().split())) for _ in range(N-1)]
g = dict()
for i, (a, b) in enumerate(AB):
a, b = a-1, b-1
if a not in g:
g[a] = set()
if b not in g:
g[b] = set()
g[a].add((b, i))
g[b].add((a, i))
col = [-1]*N
col[0] = -2
e_col = [-1]*(N-1)
q = [0]
while q:
par = q.pop()
par_col = col[par]
c = 0
for child, e_i in g[par]:
# print(child, c)
if col[child] != -1:
continue
while c == par_col:
c += 1
e_col[e_i] = c
col[child] = c
c += 1
q.append(child)
# print(col)
# print(e_col)
print(max(e_col)+1)
for e_col_i in e_col:
print(e_col_i+1) | 1 | 136,324,851,777,130 | null | 272 | 272 |
N, K = map(int, input().split())
ppp = list(map(int, input().split()))
acc = 0
for i in range(K):
acc += (ppp[i] + 1) / 2
ans = acc
for i in range(K, N):
acc -= (ppp[i - K] + 1) / 2
acc += (ppp[i] + 1 ) / 2
ans = max(ans, acc)
print(ans)
| import sys
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n, k = map(int, readline().split())
p = list(map(int, readline().split()))
tmp = [(i+1)/2 for i in p]
cs = list(np.cumsum(tmp))
if n == k:
print(cs[-1])
exit()
ans = 0
for i in range(n - k):
ans = max(ans, cs[i + k] - cs[i])
print(ans) | 1 | 74,976,026,810,232 | null | 223 | 223 |
N, M = map(int, raw_input().split())
matrix = [map(int, raw_input().split()) for n in range(N)]
array = [input() for m in range(M)]
for n in range(N):
c = 0
for m in range(M):
c += matrix[n][m] * array[m]
print c | n, m = map(int, input().split())
a = []
b = []
for i in range(n):
ai = list(map(int, input().split()))
a.append(ai)
for i in range(m):
bi = int(input())
b.append(bi)
for i in range(n):
ci = 0
for j in range(m):
ci += a[i][j] * b[j]
print(ci) | 1 | 1,173,201,844,540 | null | 56 | 56 |
S = input()
T = input()
a = len(T)
for i in range(len(S)-len(T)+1):
c = 0
for j, t in enumerate(T):
if S[i+j] != t:
c += 1
a = min(a, c)
print(a) | import math
a,b=map(float,input().split())
a=int(a)
b=round(b*100)
print((a*b)//100) | 0 | null | 10,052,100,791,908 | 82 | 135 |
m1, _ = list(map(int, input().split()))
m2, _ = list(map(int, input().split()))
if m1 == m2:
print(0)
else:
print(1) | from sys import stdin
input = stdin.readline
def main():
N = int(input())
A = list(map(int, input().split()))
order = sorted(range(1, N+1), key=lambda i: A[i-1])
print(*order, sep=' ')
if(__name__ == '__main__'):
main()
| 0 | null | 152,093,171,785,632 | 264 | 299 |
import sys
for i in sys.stdin:
try:
sidelen = [int(j) for j in i.split(" ")]
sidelen.sort(reverse=True)
if(sidelen[0]**2 == sidelen[1]**2 + sidelen[2]**2):
print("YES")
else:
print("NO")
except:
continue | n = int(raw_input())
for i in range(n):
temp = [int(x) for x in raw_input().split()]
temp.sort(reverse = True)
if temp[0] ** 2 == temp[1] ** 2 + temp[2] ** 2:
print "YES"
else:
print "NO" | 1 | 252,384,890 | null | 4 | 4 |
M1, D1 = [int(_) for _ in input().split(" ")]
M2, D2 = [int(_) for _ in input().split(" ")]
if M1 == M2:
print (0)
else:
print (1)
| def resolve():
n = int(input())
a = tuple(map(int,input().split()))
attend = [0]*n
for i,j in enumerate(a):
attend[j-1] = i+1
print(*attend)
resolve() | 0 | null | 152,429,373,414,852 | 264 | 299 |
N=input()
L=[int(N[i]) for i in range(len(N))]
P=0
OT=0
for i in range(len(L)-1):
if 0 <= L[i] <= 3:
P += L[i] + OT
OT = 0
elif L[i] == 4:
if OT == 1 and L[i+1]>=5:
P += 5
else:
P += OT+L[i]
OT = 0
elif L[i] == 5:
if OT == 1:
P += 4
else:
if L[i+1] >= 5:
P += 1 + 4
OT = 1
else:
P += 5
else:
if OT == 1:
P += 9-L[i]
OT = 1
else:
P += 10 - L[i]
OT = 1
Pone = 0
if OT==0:
Pone = min(L[-1],11-L[-1])
elif OT==1 and L[-1]<=4:
Pone = 1+L[-1]
else:
Pone = 10-L[-1]
print(P+Pone) |
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = [int(x)-48 for x in read().rstrip()]
ans = 0
dp = [[0]*(len(N)+1) for i in range(2)]
dp[1][0] = 1
dp[0][0] = 0
for i in range(1, len(N)+1):
dp[0][i] = min(dp[0][i-1] + N[i-1],
dp[1][i-1] + (10 - N[i-1]))
dp[1][i] = min(dp[0][i-1] + N[i-1] + 1,
dp[1][i-1] + (10 - (N[i-1] + 1)))
print(dp[0][len(N)])
| 1 | 70,979,620,946,300 | null | 219 | 219 |
from sys import stdin
input = stdin.readline
def main():
N = int(input())
S = input()[:-1]
pre = S[0]
cnt = 1
for i in range(1, N):
if pre == S[i]:
pre = S[i]
continue
cnt += 1
pre = S[i]
print(cnt)
if(__name__ == '__main__'):
main()
| n=int(input())
s=input()
c=n
for i in range(0,n-1):
if s[i]==s[i+1]:
c-=1
print(c) | 1 | 169,689,500,633,786 | null | 293 | 293 |
#####segfunc######
def segfunc(x, y):
return x | y
def init(init_val):
# set_val
for i in range(n):
seg[i + num - 1] = set(init_val[i])
# built
for i in range(num - 2, -1, -1):
seg[i] = segfunc(seg[2 * i + 1], seg[2 * i + 2])
def update(k, x):
k += num - 1
seg[k] = set(x)
while k:
k = (k - 1) // 2
seg[k] = segfunc(seg[k * 2 + 1], seg[k * 2 + 2])
def query(p, q):
if q <= p:
return ide_ele
p += num - 1
q += num - 2
res = ide_ele
while q - p > 1:
if p & 1 == 0:
res = segfunc(res, seg[p])
if q & 1 == 1:
res = segfunc(res, seg[q])
q -= 1
p = p // 2
q = (q - 1) // 2
if p == q:
res = segfunc(res, seg[p])
else:
res = segfunc(segfunc(res, seg[p]), seg[q])
return res
#####単位元######
ide_ele = set()
n = int(input())
S = input().strip()
Q = int(input())
num = 2 ** (n - 1).bit_length()
seg = [set()] * 2 * num
init(S)
for _ in range(Q):
a, b, c = [x for x in input().split()]
if a == "1":
update(int(b) - 1, c)
else:
print(len(query(int(b) - 1, int(c))))
| import sys
def input(): return sys.stdin.readline().rstrip()
from bisect import bisect_left,bisect
def main():
n=int(input())
S=list(input())
q=int(input())
set_s={chr(ord('a')+i):[] for i in range(26)}
for i,s in enumerate(S):
set_s[s].append(i)
for _ in range(q):
query=input().split()
if query[0]=="1":
i,c=int(query[1])-1,query[2]
if S[i]==c:continue
set_s[S[i]].remove(i)
set_s[c].insert(bisect_left(set_s[c],i),i)
S[i]=c
else:
l,r=int(query[1])-1,int(query[2])-1
ans=0
for i in range(26):
ss=chr(ord('a')+i)
if bisect(set_s[ss],r)>bisect_left(set_s[ss],l):
ans+=1
print(ans)
if __name__=='__main__':
main() | 1 | 62,699,472,958,122 | null | 210 | 210 |
n,m=map(int,input().split())
data=[0]*n
s=set()
for i in range(m):
p,a=input().split()
p=int(p)-1
if p in s:
continue
else:
if a=='WA':
data[p]-=1
else:
data[p]*=-1
s.add(p)
print(len(s),sum([data[i] for i in range(n) if data[i]>0])) | lit=input()
print(lit.swapcase())
| 0 | null | 47,311,410,821,052 | 240 | 61 |
import numpy as np
import math
from decimal import *
#from numba import njit
def getVar():
return map(int, input().split())
def getArray():
return list(map(int, input().split()))
def getNumpy():
return np.array(list(map(int, input().split())), dtype='int64')
def factorization(n):
d = {}
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
d.update({i: cnt})
if temp!=1:
d.update({temp: 1})
if d==[]:
d.update({n:1})
return d
def main():
N = int(input())
d = factorization(N)
count = 0
for v in d.values():
i = 1
while(v >= i):
v -= i
i += 1
count += 1
print(count)
main() | #!/usr/bin/env python3
n,p = map(int,input().split())
s=input()
ans = 0
l = [0 for i in range(p)]
l[0] = 1
z = 0
ten = 1
tmp = 0
if p == 2 or p == 5:
if p == 2:
for i in range(n):
if int(s[i])%2 == 0:
ans+=i+1
if p == 5:
for i in range(n):
if int(s[i])%5 == 0:
ans+= i+1
else:
for i in s[::-1]:
i = int(i)
tmp=(tmp+i*ten)%p
ten = (ten*10)%p
l[tmp]+=1
for i in l:
ans+= i*(i-1)//2
print(ans)
| 0 | null | 37,712,109,318,730 | 136 | 205 |
N, K, S = map(int, input().split())
ans = [None] * N
for i in range(N):
if i < K:
ans[i] = S
else:
if S + 1 <= 1000000000:
ans[i] = S + 1
else:
ans[i] = 1
print(' '.join(map(str, ans))) | N,K = map(int,input().split())
mod = 10**9+7
ans = [0]*(K+1)
result = 0
for i in range(K,0,-1):
c = K//i
ans[i] += pow(c,N,mod)
for j in range(i,K+1,i):
if i != j:
ans[i] -= ans[j]
result += i*ans[i] % mod
print(result%mod) | 0 | null | 63,664,257,624,968 | 238 | 176 |
r, b = input().split()
a, b = map(int, input().split())
u = input()
if r == u:
print(a-1, b)
else:
print(a, b-1) | import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")
p = L()
a,b = I()
u = s()
if u == p[0]:
a -=1
else:
b-=1
print("{} {}".format(a,b))
| 1 | 71,900,262,999,136 | null | 220 | 220 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.