code1
stringlengths 16
24.5k
| code2
stringlengths 16
24.5k
| similar
int64 0
1
| pair_id
int64 2
181,637B
⌀ | question_pair_id
float64 3.71M
180,628B
⌀ | code1_group
int64 1
299
| code2_group
int64 1
299
|
---|---|---|---|---|---|---|
#!/usr/bin/env python3
def main():
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()
c = ""
ans = 0
for i in range(n):
if t[i] == "r":
if i >= k and c[i-k] == 'p':
c += 'x'
else:
c += "p"
ans += p
elif t[i] == "s":
if i >= k and c[i-k] == 'r':
c += 'x'
else:
c += "r"
ans += r
else:
if i >= k and c[i-k] == 's':
c += 'x'
else:
c += "s"
ans += s
print(ans)
if __name__ == "__main__":
main()
| N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = list(input())
ans = 0
commands = [''] * N
for i, t in enumerate(T):
if t == 'r':
command = 'p'
point = P
elif t == 's':
command = 'r'
point = R
elif t == 'p':
command = 's'
point = S
if (i - K >= 0) and (commands[i - K] == command):
command = ''
point = 0
ans += point
commands[i] = command
print(ans) | 1 | 106,658,919,380,848 | null | 251 | 251 |
def solve(m, f, r):
if (m == -1 or f == -1) or m + f < 30:
return "F"
for a, b in ((80, "A"), (65, "B"), (50, "C")):
if m + f >= a:
return b
if r >= 50:
return "C"
return "D"
while True:
m, f, r = map(int, input().split())
if m == f == r == -1:
break
print(solve(m, f, r))
| import sys
import numpy as np
import math as mt
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n, a, b = map(int, readline().split())
ans = a * (n//(a + b))
if n%(a+b) < a:
ans += n%(a+b)
else:
ans += a
print(ans)
| 0 | null | 28,650,102,952,888 | 57 | 202 |
s = input()
if s.isupper():
print("A")
else:
print("a")
| s = input()
if (s.isupper()):
print('A')
else:
print('a') | 1 | 11,234,036,555,104 | null | 119 | 119 |
from math import sqrt
N = int(input())
search_max = int(sqrt(N))
min_number = 10**12
for x in range(1, search_max + 1):
if N % x == 0:
y = N // x
if x + y < min_number:
min_number = x + y
print(min_number-2) | n = int(input())
point = [0, 0]
for i in range(n):
a, b = input().split()
if a > b:
point[0] += 3
elif a < b:
point[1] += 3
else:
point[0] += 1
point[1] += 1
print(*point)
| 0 | null | 81,667,078,683,232 | 288 | 67 |
# coding: utf-8
a, b = input().split()
aaa = ""
bbb = ""
for i in range(int(b)):
aaa += a
for i in range(int(a)):
bbb += b
if aaa > bbb:
print(bbb)
else:
print(aaa) |
import numpy as np
from functools import *
import sys
sys.setrecursionlimit(100000)
input = sys.stdin.readline
def array(size, init=0):
return [[init for j in range(size[1])] for i in range(size[0])]
def acinput():
return list(map(int, input().split(" ")))
def II():
return int(input())
def nitti(x, y):
count = 0
for i in range(len(x)):
if x[i] == y[i]:
count += 1
return count
x = acinput()
res = 10**20*(-1)
for i in range(2):
for j in range(2, 4):
res = max(res, x[i]*x[j])
print(res)
| 0 | null | 43,732,182,842,542 | 232 | 77 |
import datetime
from sys import stdin
h1, m1, h2, m2, k = [int(x) for x in stdin.readline().rstrip().split()]
d1 = datetime.datetime(year=2018, month=1, day=7, hour=h1, minute=m1, second=0, microsecond=0)
d2 = datetime.datetime(year=2018, month=1, day=7, hour=h2, minute=m2, second=0, microsecond=0)
delta = d2 - d1
dt2 = delta.seconds / 60
dt2 -= k
if dt2 < 0 :
dt2 = 0
print(int(dt2)) | h1, m1, h2, m2, k = map(int, input().split())
s = h1 * 60 + m1
e = h2 * 60 + m2
print(e - k - s) | 1 | 18,012,289,970,858 | null | 139 | 139 |
N = int(input())
A = [int(i) for i in input().split()]
P = [0]*N
for i in range(N-1):
P[A[i]-1] += 1
for i in range(N):
print(P[i]) | n,m,l=map(int,input().split())
A=[list(map(int,input().split())) for i in range(n)]
B=[list(map(int,input().split())) for i in range(m)]
C=[[0]*l for i in range(n)]
for x in range(n):
for y in range(l):
for z in range(m):
C[x][y] += A[x][z]*B[z][y]
for row in range(n):
print("%d"%(C[row][0]),end="")
for col in range(1,l):
print(" %d"%(C[row][col]),end="")
print()
| 0 | null | 17,095,011,957,472 | 169 | 60 |
import sys
N = int(input())
if N % 2 != 0:
print(0)
sys.exit()
N //= 2
ans = 0
while N != 0:
ans += N//5
N //= 5
print(ans)
| import math
n = int(input())
ten_counter = 0
exp_index = math.log(10 ** 18, 5)
if n % 2 == 0:
n //= 2
# rangeの範囲をlogとったら if: break 不要
for i in range(1, int(exp_index) + 1):
if n // (5 ** i) == 0:
break
else:
ten_counter += n // (5 ** i)
# else:
# print("finish")
else:
pass
print(ten_counter) | 1 | 116,276,584,301,762 | null | 258 | 258 |
from sys import stdin
input = stdin.readline().rstrip
#x = input().rstrip()
#n = int(input())
#a,b,c = input().split()
#a,b,c = map(int, input().split())
D,T,S = map(int, input().split(" "))
if(T * S >= D):
print("Yes")
else:
print("No")
| N, k = map(int, input().split())
dp = [0] * (N+1)
dp[1] = 1
S = []
for i in range(k):
S.append(list(map(int, input().split())))
for i in range(2, N+1):
for l, r in S:
dp[i] += (dp[max(i-l, 0)] - dp[max(i-r-1, 0)])
dp[i] += dp[i-1]
dp[i] %= 998244353
print((dp[N] - dp[N-1])%998244353) | 0 | null | 3,074,964,323,772 | 81 | 74 |
# ???????????????.
roomDict = {}
for b in range(1, 4 + 1):
for f in range(1, 3 + 1):
for r in range(1, 10 + 1):
roomNum = b * 100 + f * 10 + r
roomDict[roomNum] = 0
# ??\???????????????????????????.
n = int(input())
for i in range(n):
input_b, input_f, input_r, input_v = map(int, input().split()) # b?£?f??????r???????????¨?±????v?????\?±?.v???????????????????????????.
roomNum = input_b * 100 + input_f * 10 + input_r
numOfPeople = roomDict[roomNum]
roomDict[roomNum] = numOfPeople + input_v
# ???????????¨?????????.
isFirst = True
for b in range(1, 4 + 1):
if isFirst:
isFirst = False
else:
print("####################")
for f in range(1, 3 + 1):
for r in range(1, 10 + 1):
roomNum = b * 100 + f * 10 + r
print(" {0}".format(roomDict[roomNum]), end='')
print('') | import math
r = float(input())
a = math.pi * r**2
b = math.pi * r * 2
print(str(a) + " " + str(b)) | 0 | null | 871,091,762,258 | 55 | 46 |
#ITP1_10-A Distance
x1,y1,x2,y2 = input().split(" ")
x1=float(x1)
y1=float(y1)
x2=float(x2)
y2=float(y2)
print ( ((x1-x2)**2.0 + (y1-y2)**2.0 )**0.5) | import math
x1,y1,x2,y2=map(float,input().split())
z = (x2-x1)**2 + (y2-y1)**2
kyori = math.sqrt(z)
print(kyori)
| 1 | 158,740,822,468 | null | 29 | 29 |
import math
a,b, C = map(int, input().split())
C = math.radians(C)
S = (a * b * math.sin(C))/2
l = a + b + math.sqrt(a**2 + b**2 - 2*a*b*math.cos(C))
h = b * math.sin(C)
print(S)
print(l)
print(h) | # coding=utf-8
inputs = raw_input().rstrip().split()
W, H, x, y, r = [int(x) for x in inputs]
if 0 <= x - r and x + r <= W and 0 <= y - r and y + r <= H:
print 'Yes'
else:
print 'No' | 0 | null | 312,786,182,198 | 30 | 41 |
#!/usr/bin/env python3
# coding: utf-8
class Dice() :
mask = {'N':(1,5,2,3,0,4), 'E':(3,1,0,5,4,2),
'W':(2,1,5,0,4,3), 'S':(4,0,2,3,5,1)}
def __init__(self, data):
self.label = data
def move(self, data):
self.label = [self.label[idx] for idx in self.mask[data]]
def get_up(self):
return self.label[0]
dicedata = input().split()
orderdata = input()
newdice = Dice(dicedata)
[newdice.move(orderdata[idx]) for idx in range(0, len(orderdata))]
print(newdice.get_up())
| class dice:
top = 1
flont = 2
right = 3
def do_N(self):
temp = self.flont
self.flont = 7-self.top
self.top = temp
def do_S(self):
temp = 7-self.flont
self.flont = self.top
self.top = temp
def do_E(self):
temp = self.top
self.top = 7-self.right
self.right = temp
def do_W(self):
temp = 7-self.top
self.top = self.right
self.right = temp
num1 = list(map(int, input().split()))
order1 = input()
dice1 = dice()
for i in range(len(order1)):
if order1[i] == "N":
dice1.do_N()
elif order1[i] == "S":
dice1.do_S()
elif order1[i] == "E":
dice1.do_E()
elif order1[i] == "W":
dice1.do_W()
print(str(num1[dice1.top-1]))
| 1 | 238,120,506,622 | null | 33 | 33 |
n = int(input())
R =[]
for i in range(n):
R.append(int(input()))
maxR = R[1]
minR = R[0]
maxB = R[1] - R[0]
for i in range(1,n):
if R[i] < minR:
minR = R[i]
maxR = R[i] - 1
elif minR <= R[i] and R[i] <= maxR:
continue
else:
maxR = R[i]
if maxR - minR > maxB:
maxB = maxR - minR
print(str(maxB)) | n, a, b = map(int, input().split())
if (b - a) % 2 == 0:
print((b-a) // 2)
exit()
else:
c = min(a - 1, n - b)
print(c + (b - a + 1) // 2)
exit()
| 0 | null | 54,827,110,342,180 | 13 | 253 |
n=int(input())
a_tmp=list(map(int,input().split()))
a=[]
for i in range(n):
a.append([a_tmp[i],i+1])
a.sort(key=lambda x:x[0])
for i in range(n):
print(a[i][1],end=" ")
| import math
T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())
if A1 > B1:
F1, F2 = A1, A2
S1, S2 = B1, B2
else:
F1, F2 = B1, B2
S1, S2 = A1, A2
oi = F1 * T1 - S1 * T1
nuki = S2 * T2 - F2 * T2 - oi
if nuki == 0:
print("infinity")
elif nuki > 0:
enc = oi // nuki * 2
if oi % nuki != 0:
enc = enc + 1
print(enc)
else:
print(0) | 0 | null | 156,063,632,567,150 | 299 | 269 |
n, k = (int(i) for i in input().split())
m = n % k
ans = min(m, k - m)
print(ans) | from sys import stdin
input = stdin.readline
def main():
N, K = list(map(int, input().split()))
surp = N % K
print(min(surp, abs(surp-K)))
if(__name__ == '__main__'):
main()
| 1 | 39,528,196,362,082 | null | 180 | 180 |
import sys
import math
import fractions
import bisect
import queue
import heapq
from collections import deque
sys.setrecursionlimit(4100000)
MOD = int(1e9+7)
PI = 3.14159265358979323846264338327950288
INF = 1e18
'''
1行のint
N, K = map(int, input().split())
1行のstring
S, T = input().split()
1行の整数配列
P = list(map(int,input().split()))
改行あり
x = []
y = []
for i in range(N):
x1,y1=[int(i) for i in input().split()]
x.append(x1)
y.append(y1)
N行M列の初期化
dp = [[INF] * M for i in range(N)]
'''
N, D, A = map(int, input().split())
XH = []
for i in range(N):
x1,y1=[int(i) for i in input().split()]
XH.append([x1, y1])
def counting(hp):
if hp < 0:
return 0
return hp//A + int(hp%A!=0)
XH.sort()
bombs = deque([]) # 有効な爆弾の威力と範囲を保存する
power = 0 # 有効な爆弾の威力の合計
ans = 0
for i in range(N):
# 使えない爆弾を捨てる
while len(bombs)>0 and bombs[0][0] < XH[i][0]:
power -= bombs.popleft()[1]
# パワーの不足分の爆弾
add = counting(XH[i][1]-power)
ans += add
# 追加した爆弾をキューに加える
bombs.append((XH[i][0] + 2*D, add*A))
power += add*A
print(ans)
"""
ATTENTION: Pythonで間に合うか??
<目安>
文字列結合、再帰関数を含む→Python
上を含まず時間が不安→PyPy3
""" | inp = input().split(" ")
count = 0
for x in range(int(inp[0]),int(inp[1])+1):
if x % int(inp[2]) == 0:
count = count+1
print(count)
| 0 | null | 45,129,451,367,760 | 230 | 104 |
n, m = map(int,input().split())
par = [-1 for i in range(n + 1)]
par[0] = 0
def find(x):
if (par[x] < 0):
return x
else:
x = par[x]
return find(x)
def unit(x, y):
if (find(x) == find(y)):
pass
else:
x = find(x)
y = find(y)
if (x > y):
x, y = y, x
s = par[y]
par[y] = x
par[x] = par[x] + s
for i in range(m):
a, b = map(int,input().split())
unit(a, b)
par.sort()
print(-par[0])
| import sys
#import time
from collections import deque, Counter, defaultdict
#from fractions import gcd
import bisect
import heapq
#import math
import itertools
import numpy as np
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
inf = 10**18
MOD = 1000000007
ri = lambda : int(input())
rs = lambda : input().strip()
rl = lambda : list(map(int, input().split()))
class UnionFind():
def __init__(self, n):
self.n = n
self.root = [-1]*(n+1)
self.rnk = [0]*(n+1)
# ノードxのrootノードを見つける
def find(self, x):
if(self.root[x] < 0):
return x
else:
self.root[x] = self.find(self.root[x])
return self.root[x]
# 木の併合、入力は併合したい各ノード
def unite(self, x, y):
x = self.find(x)
y = self.find(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
# xとyが同じグループに属するか判断
def same(self, x, y):
return self.find(x) == self.find(y)
# ノードxが属する木のサイズを返す
def size(self, x):
return -self.root[self.find(x)]
n,m = rl()
uf = UnionFind(n)
for i in range(m):
a,b = rl()
uf.unite(a,b)
print(-min(uf.root)) | 1 | 3,950,500,164,238 | null | 84 | 84 |
import sys
input = sys.stdin.readline
def main():
n , m = map( int , input().split() )
h = list( map( int , input().split() ) )
goods = [ 1 for i in range(n) ]
for i in range( m ):
a , b = map( lambda x : int(x) - 1 , input().split() )
if ( h[a] > h[b] ):
goods[ b ] = 0
if ( h[a] < h[b] ):
goods[ a ] = 0
if ( h[a] == h[b] ):
goods[ a ] = 0
goods[ b ] = 0
print( sum(goods) )
main() | H,W=map(int,input().split())
ans=0
if H==1 or W==1:
ans=1
else:
if H%2==0:
ans=H*W//2
else:
if W%2!=0:
ans = H*(W-1)//2+(H//2+1)
else:
ans=H*W//2
print(ans) | 0 | null | 38,095,314,340,950 | 155 | 196 |
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce, lru_cache # @lru_cache(None)
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**6)
# ----------------------------------------------------------- #
s = input()
print(s[:3]) | r=input().split()
N=int(r[0])
d_pre=input().split()
d=[int(s) for s in d_pre]
ans=N-sum(d)
if ans>=0:
print(ans)
else:
print(-1) | 0 | null | 23,265,510,875,600 | 130 | 168 |
n,k = input().split()
n = int(n)
k = int(k)
a = [True for i in range(n)]
while k>0:
d = int(input())
b = input().split()
for e in b:
a[int(e)-1] = False
k-=1
print(sum(a)) | N, K = list(map(int, input().split(' ')))
A=[0]*N
D=[0]*K
for i in range(K):
D[i]=int(input())
a=list(map(int, input().split(' ')))
for index in a:
A[index-1]=A[index-1]+1
print(A.count(0)) | 1 | 24,669,062,199,140 | null | 154 | 154 |
# usr/bin/python
# coding: utf-8
################################################################################
#Write a program which prints multiplication tables in the following format:
#
#1x1=1
#1x2=2
#.
#.
#9x8=72
#9x9=81
#
################################################################################
if __name__ == "__main__":
for i in range(1, 10):
for j in range(1, 10):
print("{0}x{1}={2}".format(i,j,i*j))
exit(0) | #coding:utf-8
import itertools
r = range(1,10)
for (x,y) in itertools.product(r,r):
print('{}x{}={}'.format(x,y,x*y)) | 1 | 4,467,786 | null | 1 | 1 |
import sys
input = sys.stdin.readline
MOD = pow(10, 9) + 7
n = int(input())
a = list(map(int, input().split()))
m = max(a)
num = [0] * 61
for x in a:
for j in range(61):
if (x >> j) & 1:
num[j] += 1
s = 0
#print(num)
for i in range(61):
s += (n - num[i]) * num[i] * pow(2, i, MOD) % MOD
print(s % MOD) | data = [
[[0 for k in range(10)] for j in range(3)] for i in range(4)
]
count = int(input())
for x in range(count):
(b,f,r,v) = [int(i) for i in input().split()]
data[b - 1][f - 1][r - 1] += v
for b in range(4):
for f in range(3):
print(' ',end='')
for r in range(10):
if r == 9:
print(data[b][f][r], end='')
else:
print(data[b][f][r], '', end='')
print()
if b == 3:
break
for x in range(20):
print('#',end='')
print() | 0 | null | 62,095,474,830,048 | 263 | 55 |
s = input()
n = ans = 0
for c in s:
if c == "S":
n = 0
continue
n += 1
if n > ans:
ans = n
print(ans) | integers=[]
i=0
j=0
while True:
num=int(input())
integers.append(num)
if integers[i]==0:
del integers[i]
break
i+=1
while j<i:
print('Case {}: {}'.format(j+1,integers[j]))
j+=1
| 0 | null | 2,716,622,033,020 | 90 | 42 |
n,a,b=map(int,input().split())
s=a+b
if n%s==0:
print(int(n/s)*a)
else:
if n%s>=a:
print(int(n//s+1)*a)
else:
print(int(n//s)*a+n%s) | #B
N, A, B=map(int, input().split())
quotient=N//(A+B)
remainder=N%(A+B)
quo_bball=quotient*A
if remainder <=A:
rem_bball=remainder
else:
rem_bball=A
print(quo_bball+rem_bball) | 1 | 55,639,453,838,852 | null | 202 | 202 |
N = input()
dp0 = 0
dp1 = 1
for n in N:
n = int(n)
dp0_new = min(dp0 + n, dp1 + (10 - n))
n = n + 1 #繰り上げさせてる
dp1_new = min(dp0 + n, dp1 + (10 - n))
dp0, dp1 = dp0_new, dp1_new
print(dp0) | N = [int(_) for _ in input()]
dp = [[0, 0] for _ in range(len(N))]
dp[0][0] = min(N[0], 11 - N[0])
dp[0][1] = min(N[0] + 1, 10 - N[0])
for i in range(1, len(N)):
dp[i][0] = min(dp[i - 1][0] + N[i], dp[i - 1][1] + 10 - N[i])
dp[i][1] = min(dp[i - 1][0] + N[i] + 1, dp[i - 1][1] + 9 - N[i])
print(dp[-1][0])
| 1 | 71,044,220,829,780 | null | 219 | 219 |
a,b = map(int,input().split())
s = list(map(int,input().split()))
num1 =0
num2 =0
if b ==0:
print(a)
exit()
for i in range(100):
num1 = a-i
num2 = a+i
if not num1 in s and not num2 in s:
print(num1)
exit()
if not num1 in s:
print(num1)
exit()
if not num2 in s:
print(num2)
exit() | x, n = map(int, input().split())
if n == 0:
print(x)
else:
a = [int(x) for x in input().split()]
ans1 = x
while ans1 in a :
ans1 -= 1
ans2 = x
while ans2 in a :
ans2 += 1
if abs(x - ans1) <= abs(x - ans2):
print(ans1)
else:
print(ans2)
| 1 | 14,033,404,693,722 | null | 128 | 128 |
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()
def resolve():
s=str(input())
print(s[:3])
resolve() | S, W = map(int, input().split())
print("unsafe" if W >= S else "safe" )
| 0 | null | 22,058,543,254,660 | 130 | 163 |
t1, t2 = map(int, input().split())
a1, a2 = map(int, input().split())
b1, b2 = map(int, input().split())
if (a1 > b1 and a2 > b2) or (a1 < b1 and a2 < b2):
print(0)
else:
if a1 * t1 + a2 * t2 == b1 * t1 + b2 * t2:
print("infinity")
else:
d_all = (a1 * t1 + a2 * t2) - (b1 * t1 + b2 * t2)
d_1 = a1 * t1 - b1 * t1
if (d_all > 0 and d_1 > 0) or (d_all < 0 and d_1 < 0):
print(0)
else:
if abs(d_all) > abs(d_1):
print(1)
else:
ans = 1
ans += abs(d_1) // abs(d_all) * 2 - (1 if d_1 % d_all == 0 else 0)
print(ans) | from collections import deque
def print_list(que):
for i, q in enumerate(que):
if i != len(que)-1:
print(q, end=' ')
else:
print(q)
def main():
List = deque()
n = int(input())
for i in range(n):
order = input().split()
if order[0] == "insert":
List.appendleft(order[1])
elif order[0] == "delete":
try:
List.remove(order[1])
except ValueError:
pass
elif order[0] == "deleteFirst":
List.popleft()
elif order[0] == "deleteLast":
List.pop()
print_list(List)
if __name__ == "__main__":
main()
| 0 | null | 65,985,987,127,798 | 269 | 20 |
l = [1,2,3]
l.remove(int(input()))
l.remove(int(input()))
print(l[0])
| import math
N = int(input())
Ans = math.ceil(N/2)
print(Ans) | 0 | null | 84,583,489,114,982 | 254 | 206 |
n = int(input())
x = 7
ans = 1
#print(7%1)
for i in range(3*n):
if x%n==0:
break
ans+=1
x= x*10 + 7
x=x%n
if ans < 3*n:
print(ans)
else:
print(-1) | K = int(input())
mod = 7
number = 1
for i in range(K):
if mod % K == 0:
break
number += 1
mod = (mod * 10 + 7) % K
if mod % K == 0:
print(number)
else:
print(-1) | 1 | 6,075,281,246,070 | null | 97 | 97 |
a,b,c=map(int,input().split())
k=int(input())
x=0
while a>=b:
b=b*2
x=x+1
while b>=c:
c=c*2
x=x+1
if k>=x:
print('Yes')
else:
print('No') | from collections import deque
n = int(input())
q = deque()
for _ in range(n):
com = input()
if com[0] == "i":
q.appendleft(com[7:])
elif len(com) == 11:
q.popleft()
elif len(com) == 10:
q.pop()
else:
try:
q.remove(com[7:])
except:
pass
print(*q)
| 0 | null | 3,466,979,705,972 | 101 | 20 |
n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = input()
ans = 0
memo = [0]*(n+1)
for i in range(n):
if t[i] == "r":
if i-k >= 0 and memo[i-k] == 1:
pass
else:
ans += p
memo[i] = 1
elif t[i] == "s":
if i-k >= 0 and memo[i-k] == 2:
pass
else:
ans += r
memo[i] = 2
else:
if i-k >= 0 and memo[i-k] == 3:
pass
else:
ans += s
memo[i] = 3
print(ans) | n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = input()
point = {"r":(p,"p"), "s":(r,"r"), "p":(s,"s")}
ans = 0
hand = ""
for i in range(n):
if i < k:
ans += point[t[i]][0]
hand += point[t[i]][1]
else:
if (t[i-k] != t[i]):
ans += point[t[i]][0]
hand += point[t[i]][1]
else:
if hand[i-k] != point[t[i]][1]:
ans += point[t[i]][0]
hand += point[t[i]][1]
else:
if (i+k) < n:
hand += "rsp".replace(point[t[i+k]][1],"").replace(hand[i-k],"")[0]
else:
hand += "rsp".replace(hand[i-k],"")[0]
print(ans) | 1 | 106,982,647,314,624 | null | 251 | 251 |
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#l = list(map(int, input().split()))
x = int(input())
yokin = 100
for i in range(1, 100000000000):
yokin *= 101
yokin = yokin //100
if (yokin >= x):
print(i)
break
| target_word = raw_input()
text = ''
while True:
raw = raw_input()
if raw == "END_OF_TEXT":
break
# text += raw.strip('.') + ' '
text += raw + ' '
# ans = 0
print(text.lower().split().count(target_word))
# for word in text.lower().split():
# if word == target_word:
# ans += 1
# print(ans) | 0 | null | 14,432,093,104,462 | 159 | 65 |
n = input()
daylist = {'SUN':7,'MON':6,'TUE':5,'WED':4,'THU':3,'FRI':2,'SAT':1}
print(daylist[n]) | A=[]
fp =0
bp =0
n=int(raw_input())
while n:
s = raw_input()
if s[0] == 'i':
A.append(int(s[7:]))
fp += 1
elif s[6] == ' ':
try:
i = A[::-1].index(int(s[7:]))
if i!=-1:
del A[-i-1]
fp -=1
except:
pass
elif s[6] == 'F':
A.pop()
fp -=1
elif s[6] == 'L':
bp +=1
n -=1
for e in A[bp:fp+1][::-1]:
print int(e), | 0 | null | 66,823,185,269,600 | 270 | 20 |
T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())
d1 = T1 * (A1 - B1)
d2 = T2 * (A2 - B2)
if d1 > 0 and d1 + d2 > 0:
print(0)
elif d1 < 0 and d1 + d2 < 0:
print(0)
elif d1 + d2 == 0:
print("infinity")
else:
if d1 < 0:
d1 = -d1
d2 = -d2
ok = 0
ng = (d1 + d1) // (-d1 - d2) + 1
x = 0
while ok + 1 < ng:
mid = (ok + ng) // 2
s = mid * (d1 + d2)
if s + d1 > 0:
ok = mid
elif s + d1 == 0:
ok = mid
ng = ok + 1
x = -1
else:
ng = mid
print(ng * 2 - 1 + x) | T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())
if A1 < B1:
A1, A2, B1, B2 = B1, B2, A1, A2
if A1*T1+A2*T2 == B1*T1+B2*T2:
print('infinity')
exit()
if (A1-B1)*T1 > (B2-A2)*T2:
print(0)
exit()
d = abs(A1*T1+A2*T2 - B1*T1-B2*T2) # T1,T2が終わった後に開く距離
L = abs(A1-B1)*T1 # T1の間に開く距離
# print(d, L)
if L % d == 0:
print(L//d*2)
else:
ans = L//d*2+1
print(ans)
# if d*L//d <= L:
# ans += 1
| 1 | 131,111,287,091,076 | null | 269 | 269 |
i = 0
while 1:
x = raw_input()
i += 1
if x == '0':
break
print 'Case %s: %s' % (i,x) | import sys
i = 1
for line in sys.stdin.readlines():
x = line.strip()
if x != "0":
print("Case {}: {}".format(i, x))
i += 1 | 1 | 502,479,232,480 | null | 42 | 42 |
mod = 10 ** 9 + 7
n, k = map(int, input().split())
a = sorted(map(int, input().split()))
fact = [1] * n
inv = [1] * n
inv_fact = [1] * n
for i in range(2, n):
fact[i] = fact[i-1] * i % mod
inv[i] = -inv[mod % i] * (mod // i) % mod
inv_fact[i] = inv_fact[i-1] * inv[i] % mod
max_sum = 0
for i in range(k-1, n):
max_sum = (max_sum + a[i] * fact[i] * inv_fact[i-k+1]) % mod
max_sum = (max_sum * inv_fact[k-1]) % mod
min_sum = 0
for i in range(n-k+1):
min_sum = (min_sum + a[i] * fact[n-i-1] * inv_fact[n-k-i]) % mod
min_sum = (min_sum * inv_fact[k-1]) % mod
print((max_sum - min_sum) % mod) | #!/usr/bin/env python3
import sys
MOD = 1000000007 # type: int
class Factorial:
def __init__(self, MOD):
self.MOD = MOD
self.factorials = [1, 1] # 階乗を求めるためのキャッシュ
self.invModulos = [0, 1] # n^-1のキャッシュ
self.invFactorial_ = [1, 1] # (n^-1)!のキャッシュ
def calc(self, n):
if n <= -1:
print("Invalid argument to calculate n!")
print("n must be non-negative value. But the argument was " + str(n))
exit()
if n < len(self.factorials):
return self.factorials[n]
nextArr = [0]*(n+1-len(self.factorials))
initialI = len(self.factorials)
prev = self.factorials[-1]
m = self.MOD
for i in range(initialI, n+1):
prev = nextArr[i-initialI] = prev * i % m
self.factorials += nextArr
return self.factorials[n]
def inv(self, n):
if n <= -1:
print("Invalid argument to calculate n^(-1)")
print("n must be non-negative value. But the argument was " + str(n))
exit()
p = self.MOD
pi = n % p
if pi < len(self.invModulos):
return self.invModulos[pi]
nextArr = [0]*(n+1-len(self.invModulos))
initialI = len(self.invModulos)
for i in range(initialI, min(p, n+1)):
next = -self.invModulos[p % i]*(p//i) % p
self.invModulos.append(next)
return self.invModulos[pi]
def invFactorial(self, n):
if n <= -1:
print("Invalid argument to calculate (n^(-1))!")
print("n must be non-negative value. But the argument was " + str(n))
exit()
if n < len(self.invFactorial_):
return self.invFactorial_[n]
self.inv(n) # To make sure already calculated n^-1
nextArr = [0]*(n+1-len(self.invFactorial_))
initialI = len(self.invFactorial_)
prev = self.invFactorial_[-1]
p = self.MOD
for i in range(initialI, n+1):
prev = nextArr[i-initialI] = (prev * self.invModulos[i % p]) % p
self.invFactorial_ += nextArr
return self.invFactorial_[n]
class Combination:
def __init__(self, MOD):
self.MOD = MOD
self.factorial = Factorial(MOD)
def choose_k_from_n(self, n, k):
if k < 0 or n < k:
return 0
k = min(k, n-k)
f = self.factorial
return f.calc(n)*f.invFactorial(max(n-k, k))*f.invFactorial(min(k, n-k)) % self.MOD
def solve(N: int, K: int, A: "List[int]"):
c = Combination(MOD)
A.sort()
minSum = 0
for i in range(N-K+1):
remain = N-i-1
minSum = (minSum + A[i]*c.choose_k_from_n(remain, K-1)) % MOD
maxSum = 0
A.reverse()
for i in range(N-K+1):
remain = N-i-1
maxSum = (maxSum + A[i]*c.choose_k_from_n(remain, K-1)) % MOD
print((maxSum - minSum + MOD) % MOD)
return
# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template)
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
K = int(next(tokens)) # type: int
A = [int(next(tokens)) for _ in range(N)] # type: "List[int]"
solve(N, K, A)
if __name__ == '__main__':
main()
| 1 | 96,072,047,431,040 | null | 242 | 242 |
N = int(input())
import math
print(int(math.ceil(N / 1000) * 1000 - N)) | print('1,1,1,2,1,2,1,5,2,2,1,5,1,2,1,14,1,5,1,5,2,2,1,15,2,2,5,4,1,4,1,51'.split(',')[int(input())-1]) | 0 | null | 29,046,166,391,030 | 108 | 195 |
#-------------------- fast io --------------------
import sys
sys.setrecursionlimit(500005)
stdin = sys.stdin
ns = lambda: stdin.readline().strip()
na = lambda: list(map(int, stdin.readline().split()))
ni = lambda: int(ns())
m = {'AC': 0, 'WA': 0, 'TLE': 0, 'RE': 0}
n = ni()
for i in range(n):
m[ns()] += 1
print(f"AC x {m['AC']}")
print(f"WA x {m['WA']}")
print(f"TLE x {m['TLE']}")
print(f"RE x {m['RE']}")
| l = list(map(int, input().split()))
s = input()
for c in s:
if c == "S":
l = [l[4], l[0], l[2], l[3], l[5], l[1]]
elif c == "N":
l = [l[1], l[5], l[2], l[3], l[0], l[4]]
elif c == "E":
l = [l[3], l[1], l[0], l[5], l[4], l[2]]
else:
l = [l[2], l[1], l[5], l[0], l[4], l[3]]
print(l[0])
| 0 | null | 4,419,923,709,152 | 109 | 33 |
a, b, c, d = map(int, input().split())
ans = 10**20 * -1
ans = max(ans, a * c)
ans = max(ans, a * d)
ans = max(ans, b * c)
ans = max(ans, b * d)
print(ans)
| import sys
input = sys.stdin.readline
N = int(input())
robo_range = []
for _ in range(N):
X, L = map(int,input().rstrip().split())
robo_range.append((X-L,X+L))
robo_range_sort = sorted(robo_range,key = lambda x:x[1])
ans = 0
cut = -float('inf')
for i in range(N):
if cut <= robo_range_sort[i][0]:
ans += 1
cut = robo_range_sort[i][1]
print(ans) | 0 | null | 46,629,700,866,222 | 77 | 237 |
def warshall_floid(d):
for k in range(1,n+1):
for i in range(1,n+1):
for j in range(1,n+1):
d[i][j] = min(d[i][j],d[i][k]+d[k][j])
return d
n,m,l = map(int,input().split())
d = [[10**13]*(n+1) for i in range(n+1)]
for i in range(m):
a,b,c = map(int,input().split())
d[a][b] = c
d[b][a] = c
for i in range(1,n+1):
d[i][i] = 0
d = warshall_floid(d)
for i in range(1,n+1):
for j in range(1,n+1):
if d[i][j] <= l:
d[i][j] = 1
else:
d[i][j] = 10**13
d = warshall_floid(d)
q = int(input())
for i in range(q):
s,t = map(int,input().split())
if d[s][t] >= 10**13:
print(-1)
else:
print(d[s][t]-1)
| from heapq import heappush, heappop
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations
import sys
import bisect
import string
#import math
#import time
#import random # randome is not available at Codeforces
def I():
return int(input())
def MI():
return map(int,input().split())
def LI():
return [int(i) for i in input().split()]
def LI_():
return [int(i)-1 for i in input().split()]
def StoI():
return [ord(i)-97 for i in input()]
def show(*inp,end='\n'):
if show_flg:
print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
#eps=10**(-10)
#ts=time.time()
#sys.setrecursionlimit(10**6)
input=lambda: sys.stdin.readline().rstrip()
show_flg=False
show_flg=True
def wf(d):
n=len(d)
for k in range(n):# // 経由する頂点
for i in range(n):# // 始点
for j in range(n):# // 終点
d[i][j] = min(d[i][j], d[i][k] + d[k][j])
return d
n,m,l=MI()
d=[[inf]*n for _ in range(n)]
for i in range(m):
a,b,c=LI_()
d[a][b]=c+1
d[b][a]=c+1
d=wf(d)
g=[[inf]*n for i in range(n)]
for i in range(n):
for j in range(i+1,n):
if d[i][j]<=l:
g[i][j]=1
g[j][i]=1
g=wf(g)
q=I()
for _ in range(q):
s,t=LI_()
if g[s][t]==inf:
ans=-1
else:
ans=g[s][t]-1
print(ans)
| 1 | 173,276,936,153,540 | null | 295 | 295 |
n = int(input())
s = 100000
for i in range(n):
s = int((s*1.05)/1000+0.9999)*1000
print(s)
| N = input().strip()
INFTY = 10**8
dp = [[INFTY for _ in range(2)] for _ in range(len(N)+1)]
a = int(N[-1])
for i in range(10):
if i<a:
dp[1][1] = min(dp[1][1],i+10-a)
else:
dp[1][0] = min(dp[1][0],i+i-a)
for k in range(2,len(N)+1):
a = int(N[-k])
for i in range(10):
if i>=a:
dp[k][0] = min(dp[k][0],dp[k-1][0]+i+i-a)
if i-1>=a:
dp[k][0] = min(dp[k][0],dp[k-1][1]+i+i-1-a)
if i<a:
dp[k][1] = min(dp[k][1],dp[k-1][0]+i+10-a)
if i==0:
dp[k][1] = min(dp[k][1],dp[k-1][1]+9-a)
if 0<=i-1<a:
dp[k][1] = min(dp[k][1],dp[k-1][1]+i+10-a+i-1)
print(min(dp[len(N)][0],dp[len(N)][1]+1)) | 0 | null | 35,336,500,899,392 | 6 | 219 |
n = int(input())
l = 0
r = 0
cntl = 0
cntr = 0
fl = 0
fr = 0
exl = 0
exr = 0
only_r = 0
only_l = 0
maxl = 0
maxr = 0
exlr = []
for i in range(n):
s = input()
templ = 0
tempr = 0
temp_exl = 0
temp_exr = 0
fl = 0
fr = 0
for i in s:
if i == "(":
tempr += 1
elif i == ")":
tempr -= 1
if tempr < 0:
tempr = 0
templ += 1
fl = 1
temp_exl += templ
if tempr > 0:
temp_exr += tempr
fr = 1
if fl == 1 and fr == 0:
only_l += temp_exl
elif fr == 1 and fl == 0:
only_r += temp_exr
elif temp_exl + temp_exr > 0:
exl += temp_exl
exr += temp_exr
exlr.append([temp_exl-temp_exr, temp_exl,temp_exr])
# maxl = max(maxl,temp_exl)
# maxr = max(maxr,temp_exr)
# print (exr,exl,only_r,only_l)
a = only_r
b = only_l
# print(exlr)
exlr.sort()
# exlr.sort(key=lambda x: x[1])
# print(exlr)
# for i in range(len(exlr)):
# if exlr[i][1] <= a and exlr[i][0] <= 0:
# a -= exlr[i][0]
# exlr[i] = [0,0,0]
# print(exlr)
for i in exlr:
a -= i[1]
if a<0:
print("No")
exit()
a += i[2]
if a-b == 0:
print("Yes")
else:
print("No")
# if exl+only_l == exr+only_r and exl-exr == only_r-only_l and only_l > 0 and only_r > 0:
# print("Yes")
# elif exr+exl+only_l+only_r == 0:
# print("Yes")
# else:
# print("No")
| n,d,a=[int(j) for j in input().split()]
xh=[[int(j) for j in input().split()] for i in range(n)]
xh.sort()
from collections import deque
q=deque()
ans=0
dmg=0
for x,h in xh:
while q and q[0][0]<x:
i,j=q.popleft()
dmg-=j
r=h-dmg
if r<=0:
continue
p=-(-r//a)
dmg+=p*a
ans+=p
q.append((x+2*d,p*a))
print(ans)
| 0 | null | 52,972,931,216,828 | 152 | 230 |
import numpy as np
def is_good(mid, key):
x = A - mid // F
return x[x > 0].sum() <= key
def binary_search(key):
bad, good = -1, 10 ** 18
while good - bad > 1:
mid = (bad + good) // 2
if is_good(mid, key):
good = mid
else:
bad = mid
return good
N, K = map(int, input().split())
A = np.array(input().split(), dtype=np.int64)
F = np.array(input().split(), dtype=np.int64)
A.sort()
F[::-1].sort()
print(binary_search(K))
| import sys
import re
import math
import collections
import decimal
import bisect
import itertools
import fractions
import functools
import copy
import heapq
import decimal
import statistics
import queue
# import numpy as np
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353
ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))
# ===CODE===
def main():
worst_score = 10 ** 12
n, k = ns()
a = na()
f = na()
a.sort()
f.sort(reverse=True)
score = [ai * fi for ai, fi in zip(a, f)]
l = 0
r = worst_score
while True:
middle = (l + r) // 2
tmp_k = k
for i in range(n):
tmp = (score[i] - middle + f[i] - 1) // f[i]
tmp_k -= max(0, tmp)
if tmp_k < 0:
break
if r - l == 1:
print(middle if tmp_k >= 0 else middle + 1)
exit(0)
if tmp_k < 0:
l = middle
else:
r = middle
if __name__ == '__main__':
main()
| 1 | 164,933,246,443,812 | null | 290 | 290 |
S = input()
T = input()
if T.startswith(S):
if len(T)-len(S)==1:
print("Yes")
else:
print("No")
else:
print("No") | S = input()
T = input()
if T.startswith(S) and len(T) == len(S) + 1:
print("Yes")
else:
print("No") | 1 | 21,382,250,908,028 | null | 147 | 147 |
while True:
l=list(input())
if l==["0"]:
break
print(sum(map(int,l))) | def main():
N = int(input())
result = []
while N > 0:
N -= 1
mod = N % 26
result.append(chr(mod + ord('a')))
N //= 26
result_str = ""
for i in range(len(result)-1, -1, -1):
result_str += result[i]
print(result_str)
main()
| 0 | null | 6,745,546,126,202 | 62 | 121 |
import sys
while True:
xy=sys.stdin.readline()
nums=xy.split( ' ' )
for i in range( len( nums) ):
nums[i] = int( nums[i] )
if nums[0] == 0 and nums[1] == 0:
break
else:
if nums[1] < nums[0]:
t=nums[0]
nums[0]=nums[1]
nums[1]=t
print( "{} {}".format( nums[0], nums[1] ) ) | import sys
import math
input=sys.stdin.buffer.readline
h,w=map(int,input().split())
ans=math.ceil(h*w/2)
print(1 if min(h,w)==1 else ans) | 0 | null | 25,627,354,378,778 | 43 | 196 |
a,b=map(int,input().split())
print((a//b)+1 if a%b!=0 else a//b) | a,b = map(int, input().split())
print(0--a//b) | 1 | 76,746,710,597,060 | null | 225 | 225 |
a = [list(map(int, input().split())) for _ in range(3)]
n = int(input())
b = [int(input()) for _ in range(n)]
bingo = 'No'
for t in zip(*a):
a.append(list(t))
a.append([a[i][i] for i in range(3)])
a.append([a[i][2-i]for i in range(3)])
for line in a:
if all(item in b for item in line):
bingo = 'Yes'
break
print(bingo)
| import sys,queue,math,copy
input = sys.stdin.readline
MOD = 10**9 + 7
LI = lambda : [int(x) for x in input().split()]
N = int(input())
A = LI()
c =[0,0,0]
cnt = [0 for _ in range(N)]
for i in range(N):
cnt[i] = c.count(A[i])
if cnt[i] == 0: break
c[c.index(A[i])] += 1
ans = 1
for i in range(N):
ans = (ans * cnt[i]) % MOD
print (ans) | 0 | null | 94,945,680,832,140 | 207 | 268 |
import sys
num = int(input())
dic = set()
for i in range(num):
order = sys.stdin.readline().split()
if order[0] == 'insert':
dic.add(order[1])
else:
if order[1] in dic:
print('yes')
else:
print('no') | import collections
li = list(map(int,input().split()))
c = collections.Counter(li)
if len(c) == 2:
print('Yes')
else:
print('No')
| 0 | null | 33,942,014,775,620 | 23 | 216 |
N = int(input())
S = [input() for _ in range(N)]
S.sort()
check = [True]*N
item = ""
item_ = ""
dict_item = {}
cnt = 0
for i in range(N):
item_ = S[i]
if item_ != item:
item = item_
cnt += 1
print(cnt) | n=int(input())
l =[]
for i in range(n):
s =input()
l.append(s)
l = set(l)
print(len(l)) | 1 | 30,230,152,490,300 | null | 165 | 165 |
N, K = map(int, input().split())
mod = 1000000007
ans = 0
for i in range(K, N+1+1):
num_min = i*(i-1)//2
num_max = i*(N+N-i+1)//2
# print(num_min, num_max)
ans += (num_max - num_min + 1)%mod
print(ans%mod) | def main():
n, k = map(int, input().split())
mod = 10 ** 9 + 7
cnt = 0
for i in range(k, n+2):
l = (i-1)*i//2
h = (n+n-i+1)*i//2
cnt += h - l + 1
print(cnt % mod)
if __name__ == '__main__':
main() | 1 | 33,147,544,389,440 | null | 170 | 170 |
import numpy as np
N,M = map(int,input().split())
A = list(map(int,input().split()))
Amax=max(A)
n0 = 2**int(np.ceil(np.log2(2*Amax+1)))#Amax+1以上となる最小の2のべき乗数
Afre=np.zeros(n0).astype(int)#パワーの頻度(1~Amax+1)
for i in range(N):
Afre[A[i]]+=1
#astype(int)は切り捨てなので,rintで四捨五入してから.
S = np.rint(np.fft.irfft(np.fft.rfft(Afre)*np.fft.rfft(Afre))).astype(int)
Scum =S.cumsum()#累積和
bd = N*N-M#上からM個を取り出したい
i=np.searchsorted(Scum,bd)#価値iを生み出せる組みがM個以上ある
#価値iが生み出せる選び方の余分なものを引きたい
remove=((Scum[-1]-Scum[i])-M)*i
ans=0
for j in range(i+1,n0):
ans+=S[j]*j
print(ans-remove) | from bisect import bisect_left
def calc(N, A, cumsum, x):
num = N ** 2
total = cumsum[N] * N * 2
for a in A:
idx = bisect_left(A, x - a)
num -= idx
total -= cumsum[idx] + idx * a
return num, total
def main():
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
cumsum = [0] * (N+1)
for i in range(N):
cumsum[i+1] = cumsum[i] + A[i]
lo = 0
hi = int(2e5+1)
while lo < hi:
mid = (lo + hi) // 2
num, total = calc(N, A, cumsum, mid)
if num <= M:
hi = mid
else:
lo = mid + 1
num, total = calc(N, A, cumsum, lo)
ans = total - (num - M) * (lo - 1)
print(ans)
if __name__ == "__main__":
main()
| 1 | 108,101,816,122,718 | null | 252 | 252 |
from bisect import bisect_left
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
def doesOver(k):
cnt = 0
for a in A:
cnt += N - bisect_left(A, k - a)
return cnt >= M
overEq = 0
less = A[-1] * 2 + 100
while less - overEq > 1:
mid = (less + overEq) // 2
if doesOver(mid):
overEq = mid
else:
less = mid
accA = [0] * (N + 1)
for i in range(1, N + 1):
accA[i] = accA[i - 1] + A[i - 1]
ans = 0
cnt = 0
for a in A:
left = bisect_left(A, overEq - a)
ans += accA[N] - accA[left]
ans += (N - left) * a
cnt += N - left
ans -= (cnt - M) * overEq
print(ans)
| X=int(input())
h500=X//500
h5=(X-h500*500)//5
print(h500*1000+h5*5) | 0 | null | 75,503,154,486,750 | 252 | 185 |
s = input()
if "B" in s:
print("ARC")
else:
print("ABC") | S = input()
if S == 'ABC':
print('ARC')
else:print('ABC') | 1 | 24,105,129,951,420 | null | 153 | 153 |
n,k = map(int, input().split())
ans=n % k
if abs(ans-k)<ans:
print(abs(ans-k))
else:
print(ans)
| N = int(input())
A = list(map(int, input().split()))
m=1000
s=0
if A[0]<A[1]:
s=int(1000/A[0])
m=m-s*A[0]
for i in range(1,N-1,1):
m=m+s*A[i]
s=0
if A[i+1]>A[i]:
s=int(m/A[i])
m=m-s*A[i]
m=m+max(A[N-1],A[N-2])*s
print(m) | 0 | null | 23,418,606,489,418 | 180 | 103 |
if __name__ == "__main__":
X, K, D = map(lambda x: abs(int(x)), input().split())
if X - K*D >= 0:
print(X - K*D)
else:
xdd = X // D
k = xdd + (K - xdd) % 2
print(abs(X - k*D))
|
startX, countK, distanceD = map(int, input().split())
n = int(abs(startX) / distanceD)
ans = abs(startX) % distanceD
if n > countK:
ans += distanceD * (n - countK)
else:
if (countK - n) % 2 == 1:
ans= abs(ans - distanceD)
print(ans)
| 1 | 5,222,585,012,942 | null | 92 | 92 |
N=int(input())
print(int((N+2-1)/2))
| #!/usr/bin/env python
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**6)
INF = float("inf")
def popcount(n):
ret = 0
for i in range(18):
if n>>i & 1:
ret += 1
return ret
def main():
N = int(input())
X = input().decode().rstrip()
# X に含まれる "1" の数
x_cnt = X.count("1")
# i 桁目が 0 : x_cnt += 1
# i 桁目が 1 : x_cnt -= 1
# より, X mod x_cnt +1, X mod x_cnt-1 を事前計算しておく
x_mod_pl,x_mod_mi = 0,0
d_pl,d_mi = 1,1
mod_pl,mod_mi = x_cnt+1,max(1,x_cnt-1)
for i in range(N-1,-1,-1):
if X[i]=="1":
x_mod_pl = (x_mod_pl + d_pl) % mod_pl
x_mod_mi = (x_mod_mi + d_mi) % mod_mi
d_pl = (d_pl*2) % mod_pl
d_mi = (d_mi*2) % mod_mi
for i in range(N):
ans = 1
if X[i] == "1":
# 1 -> 0 に変換した結果, 1が全く存在しない場合
if x_cnt == 1:
print(0)
continue
a = (x_mod_mi - pow(2,(N-1-i), mod_mi)) % mod_mi
else:
a = (x_mod_pl + pow(2,(N-1-i), mod_pl)) % mod_pl
while a > 0:
pop_cnt = popcount(a)
a %= pop_cnt
ans += 1
print(ans)
if __name__ == "__main__":
main() | 0 | null | 33,496,408,500,478 | 206 | 107 |
import math
import collections
N, D, A = map(int, input().split())
XH = [tuple(map(int, input().split())) for i in range(N)]
XH.sort()
q = collections.deque()
c = 0
ans = 0
for x, h in XH:
while(q):
if q[0][0] < x:
t = q.popleft()
c -= t[1]
else:
break
h -= c*A
k = math.ceil(max(h, 0) / A)
ans += k
c += k
if k > 0:
q.append((x+(2*D), k))
print(ans)
| # coding: utf-8
import sys
from collections import deque
readline = sys.stdin.readline
sr = lambda: readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
# 左からgreedyに
N, D, A = lr()
monsters = []
for _ in range(N):
x, h = lr()
monsters.append((x, h))
monsters.sort()
bomb = deque()
answer = 0
attack = 0
for x, h in monsters:
while bomb:
if bomb[0][0] + D < x:
attack -= bomb[0][1]
bomb.popleft()
else:
break
h -= attack
if h > 0:
t = -(-h//A)
answer += t
bomb.append((x + D, A * t))
attack += A * t
print(answer)
| 1 | 82,002,505,252,460 | null | 230 | 230 |
X, Y = tuple(map(int, input().split()))
# Calculate prize for "Coding Contest"
prize_code = 0;
if X == 1:
prize_code = 300000;
elif X == 2:
prize_code = 200000;
elif X == 3:
prize_code = 100000;
# Calculate prize for "Robot Maneuver"
prize_device = 0;
if Y == 1:
prize_device = 300000;
elif Y == 2:
prize_device = 200000;
elif Y == 3:
prize_device = 100000;
# Calculate prize for "two victories"
prize_both = 0
if X == 1 and Y == 1:
prize_both = 400000
# Calculate the sum and print the answer
prize_total = prize_code + prize_device + prize_both
print(prize_total) | def solve(h, w, m, hw_list):
h_count = [0] * (h + 1)
w_count = [0] * (w + 1)
for h_, w_ in hw_list:
h_count[h_] += 1
w_count[w_] += 1
h_max = max(h_count)
w_max = max(w_count)
res = h_max + w_max
h_max_count = 0
w_max_count = 0
for i in range(h + 1):
if h_count[i] == h_max:
h_max_count += 1
for j in range(w + 1):
if w_count[j] == w_max:
w_max_count += 1
max_count = h_max_count * w_max_count
max_count_cross = 0
for h_, w_ in hw_list:
if h_count[h_] == h_max and w_count[w_] == w_max:
max_count_cross += 1
if max_count_cross == max_count:
return res - 1
else:
return res
def main():
h, w, m = map(int, input().split())
hw_list = []
for _ in range(m):
hw_list.append(list(map(int, input().split())))
res = solve(h, w, m, hw_list)
print(res)
def test():
assert solve(2, 3, 3, [[2, 2], [1, 1], [1, 3]]) == 3
assert solve(3, 3, 4, [[3, 3], [3, 1], [1, 1], [1, 2]]) == 3
assert solve(5, 5, 10, [[2, 5], [4, 3], [2, 3], [5, 5], [2, 2], [5, 4], [5, 3], [5, 1], [3, 5], [1, 4]]) == 6
if __name__ == "__main__":
test()
main()
| 0 | null | 72,481,858,992,452 | 275 | 89 |
import math
L,R,d = map(int, input().strip().split())
x=math.ceil(L/d)
y=math.floor(R/d)
print(y-x+1)
| L,R,d = list(map(int, input().split()))
print(R//d - (L-1)//d)
| 1 | 7,576,860,256,210 | null | 104 | 104 |
n = int(input())
a = list(map(int,input().split()))
ans = [0 for i in range(n)]
for i in a:
ans[i-1] += 1
for i in ans:
print(i) | import sys
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().split())
inl = lambda: list(map(int, input().split()))
out = lambda x: print('\n'.join(map(str, x)))
n = ini()
a = inl()
ans = [0] * n
for i in a:
ans[i-1] += 1
out(ans) | 1 | 32,513,745,751,040 | null | 169 | 169 |
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
return sys.stdin.readline()[:-1]
mod=10**9+7
n,d,a=map(int,input().split())
xh=[list(map(int,input().split())) for i in range(n)]
xh.sort()
r,tama=[],[0]
for i in range(n):
x,h=xh[i]
tmpr=bisect.bisect_left(r,x)
h-=(tama[-1]-tama[tmpr])*a
tmp=0
if h>0:
tmp=math.ceil(h/a)
tama.append(tmp)
tama[i+1]+=tama[i]
r.append(x+2*d)
print(tama[-1])
# print(r) | import bisect
def main():
N, D, A = list(map(int, input().split()))
monsters = [list(map(int, input().split())) for _ in range(N)]
monsters.sort()
X = [m[0] for m in monsters]
# 端から貪欲に攻撃していく
ans = 0
damages = [0] * (N + 1)
for n, monster in enumerate(monsters):
x, h = monster
h = max(0, h - damages[n])
to_n = bisect.bisect_right(X, x + 2 * D)
cnt = (h + A - 1) // A # ceil(h / A)
ans += cnt
damages[n] += A * cnt
damages[to_n] -= A * cnt
damages[n + 1] += damages[n]
print(ans)
if __name__ == '__main__':
main() | 1 | 82,416,870,273,822 | null | 230 | 230 |
H, W = map(int, input().split())
S = [input() for _ in range(H)]
INF = 10 ** 18
dp = [[INF for _ in range(W)] for _ in range(H)]
if S[0][0] == "#":
dp[0][0] = 1
else:
dp[0][0] = 0
for i in range(H):
for j in range(W):
if S[i][j] == ".":
dp[i][j] = min(dp[i][j], dp[i - 1][j], dp[i][j - 1])
else:
dp[i][j] = min(dp[i][j],
dp[i - 1][j] if S[i - 1][j] == "#" else dp[i - 1][j] + 1,
dp[i][j - 1] if S[i][j - 1] == "#" else dp[i][j - 1] + 1)
print(dp[-1][-1]) | while True:
string = str(input())
box = ""
if string == "-":
break
shuffle = int(input())
h = [0]*shuffle
for a in range(shuffle):
h[a] = int(input())
for b in range(shuffle):
box = string[0:h[b]]
string = string[h[b]:]
string = string+box
box = ""
print(string)
| 0 | null | 25,518,533,091,172 | 194 | 66 |
a,b,m = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
xyc = [list(map(int,input().split())) for nesya in range(m)]
cheap = min(a)+min(b)
for hoge in xyc:
ch = a[hoge[0]-1]+b[hoge[1]-1]-hoge[2]
cheap = min(ch,cheap)
print(cheap) | a, b, m = map(int, input().split())
li_a = list(map(int, input().split()))
li_b = list(map(int, input().split()))
li_c = []
for _ in range(m):
x, y, c = map(int, input().split())
x, y = x-1, y-1
li_c.append(li_a[x]+li_b[y]-c)
li_a.sort()
li_b.sort()
li_c.sort()
ans = min(li_a[0]+li_b[0], li_c[0])
print(ans)
| 1 | 53,921,781,122,972 | null | 200 | 200 |
N=int(input())
A=list(map(int,input().split()))
import itertools
ACU=itertools.accumulate(A)
B=list(ACU)
MAX=B[-1]
tmp=10**10
for i in B:
tmp=min(tmp,abs(2*i-MAX))
print(tmp) | N=int(input())
A=list(map(int,input().split()))
B=sum(A)
b=0
ans=202020202020
for a in A:
b+=a
ans=min(ans,abs(B-b*2))
print(ans) | 1 | 142,307,049,901,088 | null | 276 | 276 |
n,m = map(int, raw_input().split())
a = []
b = [0]*m
for i in xrange(n):
x = map(int,raw_input().split(" "))
a.append(x)
for i in xrange(m):
b[i] = input()
result = [0]*n
for i in xrange(n):
for j in xrange(m):
result[i] += a[i][j]*b[j]
print result[i] | x, y = map(int, input().split())
for i in range(x + 1):
if 2 * (x - i) + 4 * i == y:
print("Yes")
break
else:
print("No") | 0 | null | 7,455,377,001,240 | 56 | 127 |
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7
n = I()
x = input()
cnt = x.count("1")
if cnt == 1:
for i in range(n):
if x[i] == "1":
print(0)
elif i == n - 1:
print(2)
else:
print(1)
exit()
def f(x):
if x==0:
return 0
return 1+f(x%bin(x).count('1'))
xx = int(x, 2)
Y = xx % (cnt + 1)
Z = xx % (cnt - 1)
for i in range(n):
if x[i] == '1':
print(1 + f((Z - pow(2, n - i - 1, cnt - 1)) % (cnt - 1)))
else:
print(1 + f((Y + pow(2, n - i - 1, cnt + 1)) % (cnt + 1))) | X = int(input())
year = 0
amount = 100
while amount < X:
risi = amount // 100
amount += risi
year += 1
print(year)
| 0 | null | 17,665,591,116,540 | 107 | 159 |
# AOJ ALDS1_4_C Dictionary
# Python3 2018.7.3 bal4u
import sys
from sys import stdin
input = stdin.readline
dic = {}
n = int(input())
for i in range(n):
s = input()
if s[0] == 'i': dic[s[7:]] = 1
else: print("yes" if s[5:] in dic else "no")
| class HashTable:
def __init__(self, size = 1000003):
self.size = size
self.hash_table = [None] * size
def _gen_key(self, val):
raw_hash_val = hash(val)
h1 = raw_hash_val % self.size
h2 = 1 + (raw_hash_val % (self.size - 1))
for i in range(self.size):
candidate_key = (h1 + i * h2) % self.size
if not self.hash_table[candidate_key] or self.hash_table[candidate_key] == val:
return candidate_key
def insert(self, val):
key = self._gen_key(val)
self.hash_table[key] = val
def search(self, val):
key = self._gen_key(val)
if self.hash_table[key]:
print('yes')
else:
print('no')
import sys
n = int(sys.stdin.readline())
simple_dict = HashTable()
ans = ''
for i in range(n):
operation = sys.stdin.readline()
if operation[0] == 'i':
simple_dict.insert(operation[7:])
else:
simple_dict.search(operation[5:]) | 1 | 73,587,883,040 | null | 23 | 23 |
x,k,d = map(int,input().split())
count = abs(x)//d
if x<0:
before_border = x+d*count
after_border = x+d*(count+1)
else:
before_border = x-d*count
after_border = x-d*(count+1)
if count >= k:
if x<0:
print(abs(x+d*k))
else:
print(abs(x-d*k))
else:
if (count-k)%2 == 0:
print(abs(before_border))
else:
print(abs(after_border)) | n=int(input())
r=[int(input()) for i in range(n)]
maxv=r[1]-r[0]
minv=r[0]
for i in range(1,n):
maxv=max(maxv,r[i]-minv)
minv=min(minv,r[i])
print(maxv)
| 0 | null | 2,577,142,168,858 | 92 | 13 |
n = int(raw_input())
s = ["S"]
h = ["H"]
c = ["C"]
d = ["D"]
card_list = [s,h,c,d]
for i in range(n):
card = raw_input().split()
for v in card_list:
if v[0] == card[0]:
v.append(int(card[1]))
# print card_list
for i in card_list:
for j in range(1, 14):
if not j in i:
print "%s %d" % (i[0], j) | K = int(input())
A, B = [int(x) for x in input().split(" ")]
i = 1
while 1:
if A <= i * K <= B:
print("OK")
break
elif i * K > B:
print("NG")
break
i += 1 | 0 | null | 13,869,835,333,912 | 54 | 158 |
A, B, M = [int(_) for _ in input().split()]
a = [int(_) for _ in input().split()]
b = [int(_) for _ in input().split()]
xyc = [[int(_) for _ in input().split()] for i in range(M)]
rets = [min(a) + min(b)]
for x, y, c in xyc:
rets += [a[x-1] + b[y-1] - c]
print(min(rets)) | #coding: UTF-8
import sys
import math
class Algo:
@staticmethod
def insertionSort(r, n):
count = 0
for i in range(0,n):
minj = i
for j in range(i,n):
if r[j] < r[minj]:
minj = j
if r[i] != r[minj]:
r[i], r[minj] = r[minj], r[i]
count += 1
for i in range(0,n):
if i == n-1:
print(r[i])
else:
print(r[i], " ", sep="", end="")
print(count)
N = int(input())
R= list(map(int, input().split()))
Algo.insertionSort(R, N) | 0 | null | 26,981,237,190,336 | 200 | 15 |
X,Y=map(int,input().split())
if Y%2 == 0:
if X*2 <= Y and Y <= X*4:
print("Yes")
else:
print("No")
else:
print("No") | #!/usr/bin/env python
# coding: utf-8
# In[15]:
N = int(input())
A = list(map(int, input().split()))
# In[17]:
total = sum(A)
ans = total
left = 0
for i in A:
left += i
right = total - left
ans = min(ans, abs(left - right))
# print(left, right, ans)
print(ans)
# In[ ]:
| 0 | null | 78,314,078,864,960 | 127 | 276 |
def main():
s = input()
t = input()
if s == t[:-1]:
print("Yes")
else:
print("No")
if __name__ == "__main__":
main() | word1 = input()
word2 = input()
if word1 == word2[:-1]:
print('Yes')
else:
print('No') | 1 | 21,558,441,437,920 | null | 147 | 147 |
n = int(input())
c = input()
r = c.count("R")
ans = 0
for i in range(r):
if c[i] == "W": ans += 1
print(ans) | N = int(input())
C = input()
T = 'R' * C.count('R') + 'W' * C.count('W')
ans = sum([1 for a, b in zip(C, T) if a != b]) // 2
print(ans) | 1 | 6,282,003,592,370 | null | 98 | 98 |
a=int(input())
b=list(map(int,input().split()))
n=1
result=0
for i in range(a):
if b[i]!=n:
result+=1
elif b[i]==n:
n+=1
if result==a:
print(-1)
else:
print(result) | n = int(input())
a = list(map(int,input().split()))
if 1 not in a:
print(-1)
exit()
num_break = 0
pos = 1
for i in a:
if i == pos:
pos += 1
else:
num_break += 1
print(num_break) | 1 | 114,582,961,250,252 | null | 257 | 257 |
def main():
N, M = tuple([int(_x) for _x in input().split()])
print(N*(N-1)//2 + M*(M-1)//2)
main()
| h = int(input())
ans = 0
n = 0
while h != 0:
ans += 2**n
n += 1
h = h//2
print(ans) | 0 | null | 62,841,831,999,362 | 189 | 228 |
def mod_pow(a, n, mod):
"""
二分累乗法による a^n (mod m)の実装
:param a: 累乗の底
:param n: 累乗の指数
:param mod: 法
:return: a^n (mod m)
"""
result = 1
a_n = a
while n > 0:
if n & 1:
result = result * a_n % mod
a_n = a_n * a_n % mod
n >>= 1
return result
def mod_inverse(a, mod):
"""
フェルマーの小定理による a^-1 ≡ 1 (mod m)の実装
aの逆元を計算する
a^-1 ≡ 1 (mod m)
a * a^-2 ≡ 1 (mod m)
a^-2 ≡ a^-1 (mod m)
:param a: 逆元を計算したい数
:param mod: 法
:return: a^-1 ≡ 1 (mod m)
"""
return mod_pow(a=a, n=mod - 2, mod=mod)
def mod_combination(n, k, mod):
fact_n = 1
fact_k = 1
for i in range(k):
fact_n *= (n - i)
fact_n %= mod
fact_k *= (i + 1)
fact_k %= mod
fact_n *= mod_inverse(fact_k, mod)
return fact_n % mod
N, A, B = map(int, input().split(' '))
MOD = 10 ** 9 + 7
print((mod_pow(2, N, MOD) - 1 - mod_combination(N, A, MOD) - mod_combination(N, B, MOD)) % MOD)
| X, Y = list(map(int, input().split()))
print(X*Y) | 0 | null | 41,064,757,813,464 | 214 | 133 |
import math
n = float(input())
m = n / 1.08
if math.floor(math.floor(m) * 1.08) == n:
print(math.floor(m))
elif math.floor(math.ceil(m) * 1.08) == n:
print(math.ceil(m))
else:
print(':(') | import math
f = True
N = int(input())
for i in range(N+1):
if math.floor(i*1.08) == N:
print(i)
f = False
break
if f:
print(":(")
| 1 | 125,586,716,820,828 | null | 265 | 265 |
(a,b,m),x,y,*c=[list(map(int, i.split())) for i in open(0)]
print(min([x[~-i]+y[~-j]-k for i,j,k in c]+[min(x)+min(y)])) | A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
result = min(a) + min(b)
for _ in range(M):
x, y, c = map(int, input().split())
discount = a[x-1] + b[y-1] - c
result = min(result, discount)
print(result) | 1 | 53,897,711,290,178 | null | 200 | 200 |
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
from operator import or_
class SegmentTree:
def __init__(self, orig, func, unit):
_len = len(orig)
self.func = func
self.size = 1 << (_len - 1).bit_length()
self.tree = [unit] * self.size + orig + [unit] * (self.size - _len)
self.unit = unit
for i in range(self.size - 1, 0, -1):
self.tree[i] = func(self.tree[i * 2], self.tree[i * 2 + 1])
def update(self, i, v):
i += self.size
self.tree[i] = v
while i:
i //= 2
self.tree[i] = self.func(self.tree[i * 2], self.tree[i * 2 + 1])
def find(self, l, r):
l += self.size
r += self.size
ret = self.unit
while l < r:
if l & 1:
ret = self.func(ret, self.tree[l])
l += 1
if r & 1:
r -= 1
ret = self.func(ret, self.tree[r])
l //= 2
r //= 2
return ret
n = readline()
s = readline()
q = int(readline())
li = [1 << ord(x) - 97 for x in s[:-1]]
seg = SegmentTree(li, or_, 0)
ans = []
for _ in range(q):
f, x, y = readline().split()
x = int(x)
if f == '1':
seg.update(x - 1, 1 << ord(y) - 97)
else:
y = int(y)
z = seg.find(x - 1, y)
cnt = bin(z).count('1')
ans.append(cnt)
print(*ans)
| n = int(input())
S = list(str(input()))
S = [{ord(c)-ord('a')} for c in S]
def segfunc(x, y):
return x | y
def init(init_val):
# set_val
for i in range(n):
seg[i+num-1] = 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] = x
while k:
k = (k-1)//2
seg[k] = segfunc(seg[2*k+1], seg[2*k+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
# identity element
ide_ele = set()
# num: n以上の最小の2のべき乗
num = 2**(n-1).bit_length()
seg = [ide_ele]*2*num
init(S)
import sys
input = sys.stdin.readline
q = int(input())
for i in range(q):
t, x, y = map(str, input().split())
if t == '1':
x = int(x)
y = ord(y)-ord('a')
update(x-1, {y})
else:
x = int(x)
y = int(y)
print(len(query(x-1, y)))
| 1 | 62,494,050,197,802 | null | 210 | 210 |
#!/usr/bin/env python3
import bisect
import heapq
import itertools
import math
import numpy as np
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from math import gcd
from operator import add, itemgetter, mul, xor
def cmb(n,r,mod):
bunshi=1
bunbo=1
for i in range(r):
bunbo = bunbo*(i+1)%mod
bunshi = bunshi*(n-i)%mod
return (bunshi*pow(bunbo,mod-2,mod))%mod
mod = 10**9+7
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]
#いまいるところ,
#listとnが与えられたときn回テレポートしたところを出力する
def now_place(li,n):
now = 1
for i in range(n):
now = li[now-1]
return now
#p回のテレポートでたどってきた道筋のルートを返す
def root(li,p):
ans = []
now = 1
for j in range(p):
ans.append(now_place(li,j+1))
return ans
n,k = MI()
a = LI()
#訪れたところのメモがtown
town = []
#訪れたかどうかを0と1で管理
visit=[0]*n
p = 1
while visit[p-1] == 0:
town.append(p)
visit[p-1] = 1
p = a[p-1]
#香りだかい町がいつでてきたか→周期に入るまでのテレポート回数
#len(town[l:])は周期を表す
l = town.index(p)
if k <len(town):
print(town[k])
else:
print(town[l + (k-l)%(len(town[l:]))])
| n,k=map(int,input().split())
A = list(map(int,input().split()))
C=[0]*n
C[0]=1
c=0
loopc=0
i=0
io=0
while c<k :
newi = A[i]-1
C[newi]+=1
if C[newi]>=3 :
rs=newi
break
elif C[newi]==2 :
loopc+=1
io=i
i=newi
c+=1
if (k-c)<0 or loopc==0 :
print(i+1)
exit()
mod = (k-c)%(loopc)
# print( k, c, loopc, i, mod)
# i=rs
while mod>0 :
newi = A[i]-1
i=newi
mod-=1
print( i+1 )
| 1 | 22,701,412,033,748 | null | 150 | 150 |
import bisect,collections,copy,heapq,itertools,math,string
from collections import defaultdict as D
from functools import reduce
import numpy as np
import sys
import os
from operator import mul
sys.setrecursionlimit(10**7)
def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))
if os.getenv("LOCAL"):
inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
sys.stdin = open(inputFile, "r")
# k: number of transfer
_,k = LI()
a = LI()
# 街の番号を0始まりに変更
a = list(map(lambda x:x-1,a))
# print(a)
s = set([0])
# 再帰関数
def rec(visited,next):
if next in s:
# print(visited)
return visited,visited.index(next)
else:
s.add(next)
visited.append(next)
return rec(visited,a[next])
visited = [0]
# 訪れた街、初めて2度訪れた街のインデックスを取得
visited,loopStart = rec(visited,a[0])
# print(visited,loopStart)
if k < len(visited):
townIndex = visited[k]
else:
visitedLoop = visited[loopStart:]
# print(visitedLoop)
# 残り回数を循環配列の長さで割った余り
index = (k-(loopStart))%len(visitedLoop)
# print(index)
townIndex = visitedLoop[index]
print(townIndex+1) | N, K = map(int, input().split())
A = list(map(lambda x:int(x)-1, input().split()))
cnts = [None] * N
pos = 0
cnt = 0
while cnt < K:
if cnts[pos] != None:
loop_size = cnt - cnts[pos]
cnt += ((K-cnt-1) // loop_size) * loop_size
cnts = [None] * N
cnts[pos] = cnt
pos = A[pos]
cnt += 1
print(pos+1)
| 1 | 22,776,796,185,684 | null | 150 | 150 |
n, k = [int(i) for i in input().split()]
cnt = 0
if n == 0:
print(1)
exit()
while n != 0:
n = n // k
cnt += 1
print(cnt) | N,K=list(map(int, input().split()))
ct=0
while N>0:
N=N//K
ct+=1
print(ct) | 1 | 64,366,881,697,714 | null | 212 | 212 |
# ITP1_10_B
import math
a, b, c = map(float, input().split())
s = a * b * math.sin(math.radians(c)) / 2
l = a + b + math.sqrt(a**2 + b**2 - 2 * a * b * math.cos(math.radians(c)))
h = b * math.sin(math.radians(c))
print(s)
print(l)
print(h)
| import sys
sys.setrecursionlimit(2147483647)
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
input = lambda:sys.stdin.readline().rstrip()
class modfact(object):
def __init__(self, n):
fact, invfact = [1] * (n + 1), [1] * (n + 1)
for i in range(1, n + 1): fact[i] = i * fact[i - 1] % MOD
invfact[n] = pow(fact[n], MOD - 2, MOD)
for i in range(n - 1, -1, -1): invfact[i] = invfact[i + 1] * (i + 1) % MOD
self._fact, self._invfact = fact, invfact
def inv(self, n):
return self._fact[n - 1] * self._invfact[n] % MOD
def fact(self, n):
return self._fact[n]
def invfact(self, n):
return self._invfact[n]
def comb(self, n, k):
if k < 0 or n < k: return 0
return self._fact[n] * self._invfact[k] % MOD * self._invfact[n - k] % MOD
def perm(self, n, k):
if k < 0 or n < k: return 0
return self._fact[n] * self._invfact[n - k] % MOD
def resolve():
n, k = map(int, input().split())
mf = modfact(n)
res = 0
for i in range(min(k + 1, n)):
res += mf.comb(n, i) * mf.comb(n - 1, i) % MOD
res %= MOD
print(res)
resolve() | 0 | null | 33,784,032,944,508 | 30 | 215 |
import sys
N, K = map(int, sys.stdin.readline().rstrip().split())
P = [int(x) for x in sys.stdin.readline().rstrip().split()]
# 目が 1 ... p のときの期待値
def kitaichi(p):
return (p + 1) / 2
goukei = 0
for i in range(K):
goukei += kitaichi(P[i])
gmax = goukei
for i in range(N - K):
goukei = goukei + kitaichi(P[K + i]) - kitaichi(P[i]) # 次の区間の合計
gmax = max(goukei, gmax)
print(gmax)
| N,K=map(int,input().split())
P=list(map(int,input().split()))
L=[]
M=[0]
c=0
m=0
x=0
for i in range(200100):
c+=i
L.append(c)
for i in P:
m+=L[i]/i
M.append(m)
if N!=K:
for i in range(N-K+1):
x=max(M[K+i]-M[i],x)
else:
x=M[K]-M[0]
print(x) | 1 | 74,784,333,749,112 | null | 223 | 223 |
#!/usr/bin/env python3
def main():
if int(input()) >= 30:
print('Yes')
else:
print('No')
if __name__ == "__main__":
main()
| # -*- coding: utf-8 -*-
x = int(input())
if x >= 30:
print('Yes')
else:
print('No')
| 1 | 5,811,087,720,942 | null | 95 | 95 |
S =input()
if len(S) % 2 != 0:
print('No')
exit()
for i in range(0,len(S),2):
if S[i:i+2] != 'hi':
print('No')
exit()
print('Yes') | s=input()
for i in range(len(s)):
if s=="hi"*i:
print("Yes")
exit()
print("No")
| 1 | 53,242,884,095,502 | null | 199 | 199 |
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
T=LI()
A=LI()
B=LI()
d1=(A[0]-B[0])*T[0]
d2=(A[1]-B[1])*T[1]
if d1>=0:
#最初は必ず正の方向へいかないように調整
d1*=-1
d2*=-1
if d1+d2==0:
print("infinity")
elif d1==0:#d1=0のパターンを排除した
print(0)
elif d1+d2<=0:
print(0)
else:
cnt=(-1*d1)//(d1+d2)
ans=cnt*2+1
if cnt*(d1+d2)==-1*d1:
ans-=1
print(ans)
main()
| t1,t2=map(int,input().split())
a1,a2=map(int,input().split())
b1,b2=map(int,input().split())
x=(a1-b1)*t1
y=(a2-b2)*t2
if x>0:
x*=-1
y*=-1
if x+y<0:print(0)
elif x+y==0:print("infinity")
else:
ans=(-x)//(x+y)
if (-x)%(x+y):print(ans*2+1)
else:print(ans*2) | 1 | 132,005,906,870,658 | null | 269 | 269 |
n,m,k=map(int,input().split())
BAD=[0 for i in range(n+1)]
E=[]
for inp in range(m):
a,b=map(int,input().split())
E.append((a,b))
BAD[a]-=1
BAD[b]-=1
B=[]
for inp in range(k):
a,b=map(int,input().split())
B.append((a,b))
uf=[i for i in range(n+1)]
def uf_find(x,uf=uf):
while uf[x]!=x:
x=uf[x]
return x
res=[]
for ele in E:
if uf_find(ele[0]) == uf_find(ele[1]):
continue
else:
res.append((ele[0],ele[1])) #write result
if uf_find(ele[0])>uf_find(ele[1]):
uf[uf_find(ele[0])]=uf_find(ele[1])
else:
uf[uf_find(ele[1])]=uf_find(ele[0])
SCO=[0 for i in range(n+1)]
for i in range(1,n+1):
SCO[uf_find(i)]+=1
for bl in B:
if uf_find(bl[0])==uf_find(bl[1]):
BAD[bl[0]]-=1
BAD[bl[1]]-=1
ANS=[str(SCO[uf_find(i)] + BAD[i] -1) for i in range(1,n+1)]
print(" ".join(ANS))
| # coding=utf-8
import math
def cut_into_three(start: list, end: list) -> list:
x1 = (2*start[0]+end[0])/3
y1 = (2*start[1]+end[1])/3
mid_point1 = [x1, y1]
x2 = (start[0]+2*end[0])/3
y2 = (start[1]+2*end[1])/3
mid_point2 = [x2, y2]
points_list = [start, mid_point1, mid_point2, end]
return points_list
def equil_triangle(point1: list, point2: list) -> list:
cos60 = math.cos(math.pi / 3)
sin60 = math.sin(math.pi / 3)
x = (point2[0] - point1[0])*cos60 - (point2[1]-point1[1])*sin60 + point1[0]
y = (point2[0] - point1[0])*sin60 + (point2[1]-point1[1])*cos60 + point1[1]
return [x, y]
def make_projection(start: list, end: list) -> list:
points_list = cut_into_three(start, end)
projection_point = equil_triangle(points_list[1], points_list[2])
points_list.insert(2, projection_point)
return points_list
def koch_curve(start: list, end: list, number: int) -> list:
if number == 0:
return [start, end]
else:
points_list = make_projection(start, end)
list1 = koch_curve(points_list[0], points_list[1], number-1)
list2 = koch_curve(points_list[1], points_list[2], number-1)
list3 = koch_curve(points_list[2], points_list[3], number-1)
list4 = koch_curve(points_list[3], points_list[4], number-1)
new_points_list = list1 + list2[1:] + list3[1:] + list4[1:]
return new_points_list
if __name__ == '__main__':
n = int(input())
p1 = [0, 0]
p2 = [100, 0]
fractal_points = koch_curve(p1, p2, n)
for i in fractal_points:
print(' '.join(map(str, i))) | 0 | null | 31,055,908,334,770 | 209 | 27 |
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 = input()
alpha2num = lambda c: ord(c) - ord('a') + 1
num2alpha = lambda c: chr(c+96+1)
a = alpha2num(x)
b = num2alpha(a)
print(b) | 0 | null | 136,826,298,253,856 | 299 | 239 |
N = int(input())
G = [[-1] * N for i in range(N)]
ans = 0
for i in range(N):
A = int(input())
for j in range(A):
x, y = map(int, input().split())
G[i][x-1] = y
for bit in range(2**N):
honests = []
for i in range(N):
if bit & (1<<i):
honests.append(i)
flag = True
for j in honests:
for k in range(N):
if (k in honests) and G[j][k] == 0:
flag = False
elif(k not in honests) and G[j][k] == 1:
flag = False
if flag:
ans = max(ans, len(honests))
print(ans)
| N=int(input())
A=[[]for _ in range(N)]
for i in range(N):
for _ in range(int(input())):
A[i].append(list(map(int,input().split())))
ans=[]
for i in range(2**N):
Bit = [1]*N
for j in range(N):
if (i >> j) & 1:
Bit[j] = 0
i=0
no=0
while i<N:
if Bit[i]==1:
for x,y in A[i]:
if Bit[x-1]!=y:
no=1
i+=1
if no:
ans.append(0)
else:
ans.append(Bit.count(1))
print(max(ans)) | 1 | 121,550,371,164,072 | null | 262 | 262 |
# Comparing Strings
a, b = map(int, input().split())
a, b = min(a, b), max(a, b)
ans = ''.join([str(a) for e in range(b)])
print(ans)
| import math
def kock(n,p1,p2):
a=math.radians(60)
if n==0:
return 0
s=[(2*p1[0]+p2[0])/3,(2*p1[1]+p2[1])/3]
t=[(p1[0]+2*p2[0])/3,(p1[1]+2*p2[1])/3]
u=[((t[0]-s[0])*math.cos(a)-(t[1]-s[1])*math.sin(a))+s[0],(t[0]-s[0])*math.sin(a)+(t[1]-s[1])*math.cos(a)+s[1]]
kock(n-1,p1,s)
print(" ".join(map(str,s)))
kock(n-1,s,u)
print(" ".join(map(str,u)))
kock(n-1,u,t)
print(" ".join(map(str,t)))
kock(n-1,t,p2)
n=int(input())
start=[float(0),float(0)]
end=[float(100),float(0)]
print(" ".join(map(str,start)))
kock(n,start,end)
print(" ".join(map(str,end)))
| 0 | null | 42,437,685,404,578 | 232 | 27 |
import copy
H, W, K = map(int, input().split())
tiles = [list(input()) for _ in range(H)]
answer = 0
for h in range(2**H):
for w in range(2**W):
b_cnt = 0
for i in range(H):
for j in range(W):
if not (h>>i&1 or w>>j&1) and tiles[i][j] == '#':
b_cnt += 1
if b_cnt == K:
answer += 1
print(answer) | h,w,k = map(int, input().split())
s = [list(map(str,list(input()))) for i in range(h)]
ans =0
for ii in range(1<<h):
for jj in range(1<<w):
cnt = 0
for i in range(h):
for j in range(w):
if (ii >> i & 1):
continue
if (jj >> j & 1):
continue
if (s[i][j] == '#'):
cnt += 1
if cnt == k:
ans += 1
print(ans)
| 1 | 8,919,460,283,360 | null | 110 | 110 |
def main():
n = int(input())
plus = []
minus = []
for _ in range(n):
x, y = map(int, input().split())
plus.append(x + y)
minus.append(x - y)
plus_max = max(plus)
plus_min = min(plus)
minus_max = max(minus)
minus_min = min(minus)
print(max(plus_max - plus_min, minus_max - minus_min))
if __name__ == "__main__":
main() | N = int(input())
def dist(A, B):
return abs(A[0] - B[0]) + abs(A[1] - B[1])
XY = [tuple(map(int, input().split())) for _ in range(N)]
INF = -10**10
ans = 0
for O in [(INF, INF), (-INF, INF)]:
S = XY[0]
for xy in XY:
if dist(O, S) < dist(O, xy):
S = xy
O = S
for xy in XY:
if dist(O, S) < dist(O, xy):
S = xy
ans = max(ans, dist(O, S))
print(ans)
| 1 | 3,389,153,922,912 | null | 80 | 80 |
res_list = [[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]],
[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]],
[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]],
[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]]
n = int(input())
for i in range(n):
io_rec = list(map(int, input().split(" ")))
bld_num = io_rec[0] - 1
floor_num = io_rec[1] - 1
room_num = io_rec[2] - 1
io_headcnt = io_rec[3]
res_list[bld_num][floor_num][room_num] += io_headcnt
for i in range(4):
if i:
print("#" * 20)
bld = res_list[i]
for j in bld:
floor_str = map(str, j)
print(" " + " ".join(floor_str)) | while True:
h,w = map(int,input().split())
if h==0 and w==0: break
for i in range(h):
s = ''
for j in range(w):
if (i+j)%2==0: s += '#'
else: s+='.'
print(s)
print()
| 0 | null | 1,003,854,450,250 | 55 | 51 |
import math
r = [float(x) for x in input().split()]
print("{0:f} {1:f}".format(r[0] * r[0] * math.pi, r[0] * 2 * math.pi)) | import queue
K = int(input())
q = queue.Queue()
for i in range(1, 10):
q.put(i)
for _ in range(K):
x = q.get()
r = x%10
y = 10*x+r
if r != 0: q.put(y-1)
q.put(y)
if r != 9: q.put(y+1)
print(x) | 0 | null | 20,160,527,919,740 | 46 | 181 |
int=input()
int=int**3
print int | num = input()
num = int(num)
print(num**3) | 1 | 282,160,504,472 | null | 35 | 35 |
N = int(input())
import collections
a = []
for i in range(N):
S = input()
a.append(S)
l = collections.Counter(a)
x = max(l.values())
ans = [k for k, v in l.items() if v == x]
ans = sorted(ans)
for i in ans:
print(i)
| n=int(input())
s=list()
for i in range(n):
s.append(input())
import collections
c=collections.Counter(s)
l=list()
max_=0
for cc in c.values():
max_=max(cc, max_)
for ca,cb in c.items():
if max_==cb:
l.append(ca)
l.sort()
for ll in l:
print(ll)
| 1 | 69,697,656,814,138 | null | 218 | 218 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.