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
|
---|---|---|---|---|---|---|
H = int(input())
W = int(input())
N = int(input())
big = max(H,W)
bigsum = 0
ans = 0
while bigsum < N:
bigsum += big
ans += 1
print(ans)
| #!/usr/bin/env python3
import collections as cl
import sys
class Combination:
"""
O(n)の前計算を1回行うことで,O(1)でnCr mod mを求められる
n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
使用例:
comb = Combination(1000000)
print(comb(5, 3)) # 10
"""
def __init__(self, n_max, mod=10**9+7):
self.mod = mod
self.modinv = self.make_modinv_list(n_max)
self.fac, self.facinv = self.make_factorial_list(n_max)
def __call__(self, n, r):
return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod
def make_factorial_list(self, n):
# 階乗のリストと階乗のmod逆元のリストを返す O(n)
# self.make_modinv_list()が先に実行されている必要がある
fac = [1]
facinv = [1]
for i in range(1, n+1):
fac.append(fac[i-1] * i % self.mod)
facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
return fac, facinv
def make_modinv_list(self, n):
# 0からnまでのmod逆元のリストを返す O(n)
modinv = [0] * (n+1)
modinv[1] = 1
for i in range(2, n+1):
modinv[i] = self.mod - self.mod//i * \
modinv[self.mod % i] % self.mod
return modinv
def II():
return int(sys.stdin.readline())
def MI():
return map(int, sys.stdin.readline().split())
def LI():
return list(map(int, sys.stdin.readline().split()))
def main():
X, Y = MI()
if (X+Y) % 3 != 0:
print(0)
return
ttl = int((X+Y)/3)
a = X - ttl
if (ttl < a or a < 0):
print(0)
return
comb = Combination(ttl)
tmp = comb(ttl, a)
print(tmp)
main()
| 0 | null | 119,127,112,455,008 | 236 | 281 |
N = int(input())
A_ls = map(int, input().split(' '))
rst = { i for i in A_ls }
if len(rst) == N:
print('YES')
else:
print('NO') | from collections import Counter
N,*A = map(int, open(0).read().split())
ac = Counter(A)
if len(ac) == N:
print('YES')
else:
print('NO') | 1 | 73,732,730,926,788 | null | 222 | 222 |
H,W,M=map(int,input().split())
L=[]
bh=[0]*(H+1)
bw=[0]*(W+1)
for _ in range(M):
h,w=map(int,input().split())
L.append((h,w))
bh[h]+=1
bw[w]+=1
p,q=max(bh),max(bw)
num=len(list(filter(p.__eq__, bh)))*len(list(filter(q.__eq__,bw)))
num-=len(list(filter(lambda x: bh[x[0]]==p and bw[x[1]]==q, L)))
ans=p+q-1
if num>0:
ans+=1
print(ans) | x,n= map(int,input().split())
p = list(map(int,input().split()))
ans=0
i=0
while True:
if x-i not in p:
ans=x-i
break
elif x+i not in p:
ans=x+i
break
else:
i+=1
continue
print(ans) | 0 | null | 9,430,943,840,588 | 89 | 128 |
from collections import Counter
from itertools import combinations
N, X, Y = map(int, input().split(' '))
c = Counter()
for i, j in combinations(range(1, N + 1), r=2):
c[min(j - i, abs(X - i) + 1 + abs(j - Y))] += 1
for n in range(1, N):
print(c[n])
| from typing import List
# 人iの証言を人jに対する証言をリストで格納。1:正直者, 0:不親切, -1:言及なし
def io_info() -> List[List[int]]:
N = int(input())
res = [[-1] * N for _ in range(N)]
for n in range(N):
a = int(input())
for _ in range(a):
x, y = map(int, input().split())
res[n][x-1] = y
return res
def main():
infos = io_info()
n = len(infos)
ans = 0
for i in range(1 << n):
d = [0] * n
for j in range(n):
# iのj+1ビット目が1かどうか,d[j]が正直なら1を割り当てる
if (i >> j) & 1:
d[j] = 1
ok = True
for j in range(n):
if d[j]:
for k in range(n):
if infos[j][k] == -1: continue
if infos[j][k] != d[k]: ok = False
if ok: ans = max(ans, bin(i).count("1"))
print(ans)
if __name__ == '__main__':
main()
| 0 | null | 83,165,061,883,808 | 187 | 262 |
firstLine = input()
numOfPoints, limitDisatnce = list(map(int,firstLine.split(' ')))[0], list(map(int,firstLine.split(' ')))[1]
points = []
for i in range(0, numOfPoints):
cordinate = list(map(int,input().split(' ')))
points.append(cordinate)
count = 0
for i in range(0, len(points)):
distance = (points[i][0] ** 2) + (points[i][1] ** 2)
if (limitDisatnce ** 2) >= distance:
count = count + 1
print(count) | n,d=map(int, input().split())
xy=[]
ans = 0
for i in range(n):
x,y = map(int, input().split())
xy.append([x,y])
if d**2>=x**2+y**2:
ans += 1
print(ans)
| 1 | 6,013,744,448,108 | null | 96 | 96 |
def linearSearch(t):
i=0
s=S[:]+[t]
while s[i]!=t:
i+=1
if i==n:
return 0
return 1
n=int(input())
S=list(map(int,input().split()))
q=int(input())
T=list(map(int,input().split()))
C=0
for t in T:
C+=linearSearch(t)
print(C) | S=[]
T=[]
S_num=int(input())
S=input().split()
T_num=int(input())
T=input().split()
cnt=0
for i in range(T_num):
for j in range(S_num):
if(S[j]==T[i]):
cnt+=1
break
print(cnt)
| 1 | 65,760,166,600 | null | 22 | 22 |
from sys import stdin
X = [ 0 for i in range(100) ]
d = [ 0 for i in range(100) ]
f = [ 0 for i in range(100) ]
G = [[ 0 for i in range(100) ] for i in range(100)]
t = 0
def DFS(i) :
global t
t += 1
d[i] = t
for j in range(n) :
if G[i][j] != 0 and d[j] == 0 : DFS(j)
t += 1
f[i] = t
n = int(input())
for i in range(n) :
X[i] = stdin.readline().strip().split()
for i in range(n) :
for j in range(int(X[i][1])) :
G[int(X[i][0])-1][int(X[i][j+2])-1] = 1
for i in range(n) :
if d[i] == 0 : DFS(i)
for i in range(n) : print(i+1,d[i],f[i]) | X,Y = map(int, input().split())
ans = "No"
for turtle in range(X+1):
crain = X - turtle
if 2 * crain + 4 * turtle == Y:
ans = "Yes"
print(ans) | 0 | null | 6,813,870,966,852 | 8 | 127 |
s = int(input())
t = h = 0
for _ in range(s):
tc, hc = input().split()
if tc == hc:
t += 1
h += 1
elif tc > hc :
t += 3
else:
h += 3
print(t, h) | N = int(input())
list1, list2 = input().split()
str = ''
for i, j in zip(list1, list2):
str += f'{i}{j}'
print(str) | 0 | null | 57,242,651,423,360 | 67 | 255 |
MODINT = 10**9+7
n, k = map(int, input().split())
ans = 0
"""
dp[i] = gdc がi となる場合のgcdの総和
"""
dp = [0] * (k+100)
for i in range(k, 0, -1):
dp[i] = pow(k//i, n, MODINT)
for j in range(i*2, k+1, i):
dp[i] -= dp[j]
ans += (dp[i]*i)%MODINT
print(ans%MODINT) | S = input()
A = S.count("R")
B = S.count("RR")
if A==2:
if B==1:
print(2)
if B==0:
print(1)
elif A==1:
print(1)
elif A==3:
print(3)
else :
print(0) | 0 | null | 20,779,574,895,590 | 176 | 90 |
n = int(input())
S = set(input().split())
q = int(input())
T = set(input().split())
print(len(S & T))
| input()
S = set(input().split())
input()
T = set(input().split())
print(len(S & T))
| 1 | 66,161,650,260 | null | 22 | 22 |
def solve(ls):
n = len(ls)
s = 0
for i in range(n):
s ^= ls[i]
result = [0] * n
for i in range(n):
result[i] = s ^ ls[i]
return result
def main(istr, ostr):
(n,) = list(map(int, istr.readline().strip().split()))
ls = list(map(int, istr.readline().strip().split()))
result = solve(ls)
print(*result, file=ostr)
if __name__ == "__main__":
import sys
main(sys.stdin, sys.stdout)
| print('Yes' if ['A','B'] == sorted(set(input())) else 'No') | 0 | null | 33,761,507,997,130 | 123 | 201 |
numbers = input()
numbers = numbers.split(" ")
W = int(numbers[0])
H = int(numbers[1])
x = int(numbers[2])
y = int(numbers[3])
r = int(numbers[4])
if (r <= x <= W - r) and (r <= y <= H - r):
print("Yes")
else:
print("No") | W, H, x, y, r = map(int, input().split())
delta = [[r, 0], [-r, 0], [0, r], [0, -r]]
for dx, dy in delta:
if 0 <= x + dx <= W and 0 <= y + dy <= H:
pass
else:
print('No')
exit(0)
print('Yes')
| 1 | 445,878,502,340 | null | 41 | 41 |
n, m, k =map(int, input().split())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
ta=sum(a)
a.append(0)
tb=0
ans=0
j=0
for i in range(n+1):
ta -= a[n-i]
if ta>k:
continue
while tb + ta<=k:
if j ==m:
ans=max(ans,n-i+j)
break
ans=max(ans,n-i+j)
tb += b[j]
j +=1
print(ans)
| class UnionFind():
# 作りたい要素数nで初期化
# 使用するインスタンス変数の初期化
def __init__(self, n):
self.n = n
# root[x]<0ならそのノードが根かつその値が木の要素数
# rootノードでその木の要素数を記録する
self.root = [-1]*(n+1)
# 木をくっつける時にアンバランスにならないように調整する
self.rnk = [0]*(n+1)
# ノードxのrootノードを見つける
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):
# 入力ノードのrootノードを見つける
x = self.Find_Root(x)
y = self.Find_Root(y)
# すでに同じ木に属していた場合
if(x == y):
return
# 違う木に属していた場合rnkを見てくっつける方を決める
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
# rnkが同じ(深さに差がない場合)は1増やす
if(self.rnk[x] == self.rnk[y]):
self.rnk[y] += 1
# xとyが同じグループに属するか判断
def isSameGroup(self, x, y):
return self.Find_Root(x) == self.Find_Root(y)
# ノードxが属する木のサイズを返す
def Count(self, x):
return -self.root[self.Find_Root(x)]
n,m = map(int,input().split())
uf = UnionFind(n)
for i in range(m):
a,b = map(int,input().split())
a -= 1
b -= 1
uf.Unite(a,b)
s = set()
for i in range(n):
s.add(uf.Find_Root(i))
print(len(s)-1) | 0 | null | 6,518,021,247,742 | 117 | 70 |
n=int(input())
a=[0,1,2,0,4,0,0,7,8,0,0,11,0,13,14]
s=0
for i in range(n+1):
if a[i%15]!=0:
s+=a[i%15]+i//15*15
print(s) | R = int(input())
import math
nagasa = R*2 * math.pi
print(nagasa) | 0 | null | 33,254,993,585,770 | 173 | 167 |
mount_list = []
for i in range(10):
mount_list.append(int(input()))
mount_list.sort(reverse = True)
for i in range(3):
print(mount_list[i])
| import sys
import math
from collections import deque
sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()
def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]
def main():
H, W = NMI()
grid = [SI() for _ in range(H)]
DH = [-1, 1, 0, 0]
DW = [0, 0, -1, 1]
def bfs(sh, sw):
queue = deque()
seen = make_grid(H, W, -1)
queue.append([sh, sw])
seen[sh][sw] = 0
while queue:
now_h, now_w = queue.popleft()
for dh, dw in zip(DH, DW):
next_h = now_h + dh
next_w = now_w + dw
if not(0 <= next_h < H and 0 <= next_w < W):
continue
if seen[next_h][next_w] != -1 or grid[next_h][next_w] == "#":
continue
queue.append([next_h, next_w])
seen[next_h][next_w] = seen[now_h][now_w] + 1
return max([max(l) for l in seen])
ans = 0
for h in range(H):
for w in range(W):
if grid[h][w] == ".":
ans = max(ans, bfs(h, w))
print(ans)
if __name__ == "__main__":
main() | 0 | null | 47,473,329,654,808 | 2 | 241 |
n = int(input())
arr = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]
for i in range(n):
s = input().split(" ")
nums = list(map(int, s))
arr[nums[0]-1][nums[1]-1][nums[2]-1] += nums[3]
for k in range(4):
for j in range(3):
for i in range(10):
print(" {0}".format(arr[k][j][i]),end="")
print("")
if k < 3:
for l in range(20):
print("#",end="")
print("") | h = [[[0]*10 for i in range(3)] for j in range(4)]
n = int(input())
for i in range(n):
b,f,r,v = map(int,input().split())
h[b-1][f-1][r-1] += v
s = ""
for i in range(4):
for j in range(3):
for k in range(10):
s += " " + str(h[i][j][k])
s += "\n"
if i < 3:
s += "####################\n"
print(s,end="") | 1 | 1,100,960,979,140 | null | 55 | 55 |
import math
r = float(raw_input())
print "{0:.10f} {1:.10f}".format(r*r*math.pi, 2*r*math.pi) | import sys
import math
#r = map(int,input().split())
r = float(input())
print ('%.5f %.5f'% (r**2*math.pi, 2*r*math.pi)) | 1 | 640,200,415,680 | null | 46 | 46 |
x = int(input())
p = sorted(list(map(int,input().split())))
d = [True]*(p[-1]+1)
e = [False]*(p[-1]+1)
for i in p:
if e[i]:
d[i] = False
continue
else:
e[i] = True
idx = 2*i
while idx < len(d):
d[idx] = False
idx += i
cnt = 0
for i in p:
cnt += int(d[i])
print(cnt) | n = int(input())
oh = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]
for tr in range(n):
b, f, r, v = map(int, input().split())
oh[b - 1][f - 1][r - 1] += v
for k in range(4):
for j in range(3):
tmp = ''
for i in range(10):
tmp += (' ' + str(oh[k][j][i]))
print(tmp)
if k < 3:
print('#' * 20) | 0 | null | 7,711,516,090,588 | 129 | 55 |
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
K, X = map(int, input().split())
if 500 * K >= X:
print('Yes')
else:
print('No') | a,b=map(int,input().split())
print("Yes" if (a*500>=b) else "No") | 1 | 98,357,720,112,600 | null | 244 | 244 |
n, m = map(int, input().split())
a = list(map(int, input().split()))
print(max(-1, n - sum(a)))
| import math
N, D = map(int,input().split())
a = []
n = 0
for i in range(N):
p,q = map(int, input().split())
z = math.sqrt(p**2+q**2)
if z <= D:
n+=1
#print (a)
print (n) | 0 | null | 18,946,016,300,662 | 168 | 96 |
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
INF = float("inf")
import bisect
import statistics
# mod = 10**9+7
mod = 998244353
N ,S = list(map(int, input().split()))
A = [0] + list(map(int, input().split()))
dp = [[0 for j in range(S+1)] for i in range(N+1)]
dp[0][0] = 1
for i in range(1,N+1):
for y in range(S+1):
dp[i][y] = (dp[i][y] + dp[i-1][y] * 2) % mod
if y - A[i] >= 0:
dp[i][y] = (dp[i][y] + dp[i-1][y-A[i]]) % mod
print(dp[N][S] % mod)
| n_max, m_max, l_max = (int(x) for x in input().split())
a = []
b = []
c = []
for n in range(n_max):
a.append([int(x) for x in input().split()])
for m in range(m_max):
b.append([int(x) for x in input().split()])
for n in range(n_max):
c.append( [sum(a[n][m] * b[m][l] for m in range(m_max)) for l in range(l_max)])
for n in range(n_max):
print(" ".join(str(c[n][l]) for l in range(l_max))) | 0 | null | 9,600,172,697,620 | 138 | 60 |
N, K = [int(v) for v in input().strip().split(" ")]
A = [int(v) for v in input().strip().split(" ")]
for i in range(N - K):
if A[i+K] > A[i]:
print("Yes")
else:
print("No") | N, K = map(int, input().split())
A = list(map(int, input().split()))
ans = ['Yes' if A[i] > A[i - K] else 'No' for i in range(K, N)]
print("\n".join(ans)) | 1 | 7,203,972,140,636 | null | 102 | 102 |
N,D = map(int,input().split())
A=[[int(i) for i in input().split()] for _ in range(N)]
ans=int()
for i in range(N):
if A[i][0]*A[i][0]+A[i][1]*A[i][1]<=D*D:
ans+=1
print(ans)
| n = int(input())
result = []
for i in range(3, n+1):
if i % 3 == 0 or '3' in str(i):
result.append(i)
print(" ", end="")
print(*result)
| 0 | null | 3,381,394,708,428 | 96 | 52 |
from itertools import accumulate
n,k = map(int,input().split())
l = [0] + list(map(int,input().split()))
for i in range(n):
l[i+1] = (l[i+1]+1)/2
acc = list(accumulate(l))
# print(acc)
maxi = 0
for i in range(n-k+1):
maxi = max(maxi,acc[i+k]-acc[i])
print(maxi) | n,k=map(int,input().split())
p=list(map(int,input().split()))
li=[sum(p[0:k])]
for i in range(n-k):
li.append(li[i]-p[i]+p[i+k])
print((max(li)+k)/2) | 1 | 74,932,105,724,890 | null | 223 | 223 |
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
from copy import deepcopy
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 ** 20
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return S().split()
def S(): return sys.stdin.readline().strip()
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)]
mod = 1000000007
class BIT:
def __init__(self, size):
self.bit = [0] * size
self.size = size
self.total = 0
def add(self, i, w):
x = i + 1
self.total += w
while x <= self.size:
self.bit[x - 1] += w
x += x & -x
return
def sum(self, i):
res = 0
x = i + 1
while x:
res += self.bit[x - 1]
x -= x & -x
return res
def interval_sum(self, i, j): # i <= x < j の区間
return self.sum(j - 1) - self.sum(i - 1) if i else self.sum(j - 1)
n = I()
s = list(S())
q = I()
D = defaultdict(lambda:BIT(n))
for j in range(n):
D[s[j]].add(j, 1)
for _ in range(q):
qi, i, c = LS()
if qi == "1":
i = int(i) - 1
D[s[i]].add(i, -1)
D[c].add(i, 1)
s[i] = c
else:
l, r = int(i) - 1, int(c)
ret = 0
for k in range(97, 123):
if D[chr(k)].interval_sum(l, r):
ret += 1
print(ret)
| def main():
import sys
b=sys.stdin.buffer
input=b.readline
n=int(input())
d=[set()for _ in range(n)]+[{c}for c in input()]
for i in range(n-1,0,-1):d[i]=d[i+i]|d[i-~i]
r=[]
add=r.append
input()
for q,a,b in zip(*[iter(b.read().split())]*3):
i=int(a)+n-1
if q<b'2':
d[i]={b[0]}
while i:
i>>=1
d[i]=d[i+i]|d[i-~i]
continue
j=int(b)+n
s=set()
while i<j:
if i&1:
s|=d[i]
i+=1
if j&1:
j-=1
s|=d[j]
i>>=1
j>>=1
add(len(s))
print(' '.join(map(str,r)))
main() | 1 | 62,372,171,951,672 | null | 210 | 210 |
import math
def caracal_vs_monster():
"""
2**0 個 5
/ \
2**1 個 2.5 2.5
/ \ / \
2**2 個 1.25 1.25 1.25 1.25
/ \ / \ / \ / \
2**3 個 0.625 0.625 ...
"""
# 入力
H = int(input())
# H / 2 の何回目で1になるか
count = int(math.log2(H))
# 攻撃回数
attack_count = 0
for i in range(count+1):
attack_count += 2 ** i
return attack_count
result = caracal_vs_monster()
print(result) | H = int(input())
p = 0
for i in range(50):
if 2**i <= H and H < 2**(i + 1):
p = i
break
# print(p)
print(2**(p + 1) - 1)
| 1 | 79,965,028,355,378 | null | 228 | 228 |
# AOJ ITP1_9_C
def numinput():
a = input().split()
for i in range(len(a)):
a[i] = int(a[i])
return a
def main():
SCORE_taro = 0
SCORE_hanako = 0
n = int(input())
for i in range(n):
words = input().split()
if words[0] > words[1]: SCORE_taro += 3
elif words[0] < words[1]: SCORE_hanako += 3
else:
SCORE_taro += 1; SCORE_hanako += 1
print(str(SCORE_taro) + " " + str(SCORE_hanako))
if __name__ == "__main__":
main()
| # coding: utf-8
# Your code here!
n = int(input())
ta = 0
ha = 0
for i in range(n):
a, b = list(input().split())
if a == b:
ta += 1
ha += 1
elif a > b:
ta += 3
else:
ha += 3
print(ta,ha)
| 1 | 2,001,824,611,070 | null | 67 | 67 |
import math
N = int(input())
print(math.floor((N - 1)/2)) | n=int(input())
a=[]
for i in range(1,n+1):
if not(i%3==0 or i%5==0):
a.append(i)
print(sum(a)) | 0 | null | 94,295,438,530,160 | 283 | 173 |
import sys
input = sys.stdin.readline
import numpy as np
from scipy.sparse.csgraph import floyd_warshall
n,m,l=map(int,input().split())
ans=[[0]*n for i in range(n)]
for i in range(m):
a,b,c=[int(j) for j in input().split()]
ans[a-1][b-1]=c
ans[b-1][a-1]=c
q=int(input())
st=[]
for i in range(q):
st.append([int(j)-1 for j in input().split()])
ans=floyd_warshall(ans)
for i in range(n):
for j in range(n):
if ans[i][j]<=l:
ans[i][j]=1
else:
ans[i][j]=0
ans=floyd_warshall(ans)
for i,j in st:
if ans[i][j]==float("inf"):
print(-1)
else:
print(int(ans[i][j])-1)
| S = input()
q = int(input())
for i in range(q):
L = input().split()
a = int(L[1])
b = int(L[2])
slice1 = S[:a]
slice2 = S[a:b+1]
slice3 = S[b+1:]
if L[0] == 'print':
print(slice2)
elif L[0] == 'reverse':
S = slice1 + slice2[::-1] + slice3
elif L[0] == 'replace':
S = slice1 + L[3] + slice3 | 0 | null | 87,465,371,989,110 | 295 | 68 |
n=int(input())
x=(n%500)
print((n//500)*1000+x - x%5) | x = int(input())
n_500 = x//500
n_5 = (x%500)//5
print(n_500*1000 + n_5*5) | 1 | 42,784,793,307,520 | null | 185 | 185 |
n,m = map(int,input().split())
a = list(map(int,input().split()))
b = [x for x in a if x >= sum(a)/4/m]
if len(b)>=m:
print("Yes")
else:
print("No")
| n,m = input().split()
n = int(n)
m = int(m)
arr = list(map(int,input().split()))
minn = sum(arr)*(1/(4*m))
t = 0
for i in arr:
if i >= minn:
t += 1
#print(t)
if t >= m:
print("Yes")
else:
print("No") | 1 | 38,687,598,784,992 | null | 179 | 179 |
N, K = map(int, input().split())
d = list()
have = list()
for i in range(K):
d.append(int(input()))
holders = list(map(int, input().split()))
for holder in holders:
if holder not in have:
have.append(holder)
print(N - len(have))
| a = int(input())
i = 1
while a!=0:
print("Case "+str(i)+":",a)
a = int(input())
i = i+1 | 0 | null | 12,515,260,453,460 | 154 | 42 |
import sys
input = sys.stdin.readline
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def main():
mod=10**9+7
N=I()
cnt=0
flag=0
for _ in range(N):
a,b=MI()
if a==b:
cnt+=1
else:
cnt=0
if cnt==3:
flag=1
break
if flag==1:
print("Yes")
else:
print("No")
main()
| n = int(input())
d = [list(map(int,input().split())) for i in range(n)]
count = 0
# [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6]]
for i in d:
if i[0] == i[1]:
count += 1
else:
count = 0
if count == 3:
print('Yes')
exit()
print('No') | 1 | 2,478,420,552,130 | null | 72 | 72 |
input()
a=list(map(int, input().split()))
a.reverse()
print(*a)
| import math
N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort(reverse=True)
def solve(X):
s = 0
for i in range(N):
if A[i]*F[i]>X:
s += math.ceil((A[i]*F[i]-X)/F[i])
# print(X, s)
return s <= K
if sum(A) <= K:
print(0)
else:
l, r = 0, 10**12+10
while l+1<r:
mid = (l+r)//2
if solve(mid):
r = mid
else:
l = mid
print(r) | 0 | null | 82,918,514,996,928 | 53 | 290 |
import math
r = input()
print '%.6f' % (r*r*math.pi), '%.6f' % (2*r*math.pi) | r=input();p=3.141592653589;print "%.9f"%(p*r*r),r*2*p | 1 | 637,928,497,020 | null | 46 | 46 |
A, B, C = map(int, input().split())
K = int(input())
for i in range((K + 1)):
for j in range((K + 1) - i):
for k in range((K + 1) - i - j):
if A * (2 ** i) < B * (2 ** j) < C * (2 ** k):
print("Yes")
exit()
print("No")
| A,B,C = map(int, input().split())
K = int(input())
n = 0
while (A >= B):
B = 2*B
n +=1
while B>=C:
C = 2*C
n += 1
#print(A,B,C,n)
if n <= K:
print('Yes')
else:
print('No')
| 1 | 6,964,868,157,870 | null | 101 | 101 |
import math
def is_prime(n):
global primes
if n == 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
s = int(math.sqrt(n))
for x in range(3, s + 1, 2):
if n % x == 0:
return False
else:
return True
N = int(input())
d = [int(input()) for _ in range(N)]
d.sort()
print([is_prime(x) for x in d].count(True)) | def is_prime(x):
if x <= 1:
return False
i = 2
while i * i <= x:
if x % i == 0:
return False
i += 1
return True
cnt = 0
for _ in range(int(input())):
if is_prime(int(input())):
cnt += 1
print(cnt) | 1 | 9,829,472,928 | null | 12 | 12 |
num = input().split(" ")
num_all = int(num[0])
count = int(num[1])
cost = list(map(int, input().split()))
cost.sort()
last = 0
for i in range(count):
last += cost[i]
print(last) | N, K = map(int, input().split())
p_list = list(map(int, input().split()))
p_list = sorted(p_list)
print(sum(p_list[:K])) | 1 | 11,600,050,092,828 | null | 120 | 120 |
n=int(input())
n=n-1
a=[]
q=n//26
r=n%26
a.insert(0,r)
while q>=26:
q=q-1
r=q%26
a.insert(0,r)
q=q//26
a.insert(0,q-1)
b=[]
for i in range(len(a)):
x=int(a[i])
if x<0:
x=0
else:
x=chr(x+97)
b.append(x)
c="".join(b)
print(c) | def main():
n = int(input())
alp = 'abcdefghijklmnopqrstuvwxyz'
answer = ''
while n >= 1:
n -= 1
answer += alp[n % 26]
n //= 26
real_answer = ''
for i in range(1, len(answer) + 1):
real_answer += answer[-i]
print(real_answer)
if __name__ == '__main__':
main() | 1 | 11,927,468,023,408 | null | 121 | 121 |
import sys
for line in sys.stdin:
n = [int(i) for i in line.replace("\n", "").split(" ")]
n.sort()
low = n[0]
hi = n[1]
while hi % low:
hi, low = low, hi % low
print("%d %d" % (low, n[0] / low * n[1])) | while True:
try:
a, b = map(int, input().split(" "))
if a < b:
key = a
a = b
b = key
A = a
B = b
while a % b != 0:
key = a % b
a = b
b = key
key = int(A * B / b)
print(b, key)
except:
break
| 1 | 575,884,320 | null | 5 | 5 |
#!/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()))
def root(x):
if par[x] == x:
return x
par[x] = root(par[x])
return par[x]
def union(x,y):
x = root(x)
y = root(y)
if rank[x] < rank[y]:
par[x] = y
else:
par[y] = x
if rank[x] == rank[y]:
rank[x] += 1
n, m = LI()
par = [i for i in range(n)]
rank = [0] * n
for _ in range(m):
a, b = LI()
if root(a-1) != root(b-1):
union(a-1, b-1)
s = set()
for i in range(n):
s.add(root(i))
ans = len(s)-1
print(ans) | def connected_components(graph):
seen = set()
def component(n):
nodes = set([n])
while nodes:
n = nodes.pop()
seen.add(n)
nodes |= set(graph[n]) - seen
yield n
for n in graph:
if n not in seen:
yield component(n)
def print_gen(gen):
print(len([list(x) for x in gen]) - 1)
n, m = map(int, input().split())
graph = [[] for _ in range(n)]
for _ in range(m):
a, b = map(int, input().split())
graph[a-1].append(b-1)
graph[b-1].append(a-1) # 有向グラフなら消す
graphA = {}
for i in range(n):
graphA[i] = graph[i]
print_gen(connected_components(graphA)) | 1 | 2,304,396,585,960 | null | 70 | 70 |
for x in range(1, 10):
for y in range(1, 10):
print(x , "x" , y , "=" , x*y, sep = "")
| import sys
input = sys.stdin.readline
h,w,m = map(int,input().split())
h_array = [ 0 for i in range(h) ]
w_array = [ 0 for i in range(w) ]
ps = set()
for i in range(m):
hi,wi = map( lambda x : int(x) - 1 , input().split() )
h_array[hi] += 1
w_array[wi] += 1
ps.add( (hi,wi) )
h_great = max(h_array)
w_great = max(w_array)
h_greats = list()
w_greats = list()
for i , hi in enumerate(h_array):
if hi == h_great:
h_greats.append(i)
for i , wi in enumerate(w_array):
if wi == w_great:
w_greats.append(i)
ans = h_great + w_great
for _h in h_greats:
for _w in w_greats:
if (_h,_w) in ps:
continue
print(ans)
exit()
print(ans-1) | 0 | null | 2,321,466,183,610 | 1 | 89 |
N = int(input())
alph = ['z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',\
'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',\
'x', 'y']
seq = []
while N > 0:
s = N % 26
N = (N - 1) // 26
seq.append(s)
L = len(seq)
name = ''
for i in range(L):
name = alph[seq[i]] + name
print(name) | def solve(n):
import math
m = 26
nn = n - 1
for i in range(1, m + 1):
p = m ** i
if p > nn:
break
nn -= p
s = ''
for j in range(1, i + 1):
p = m ** (i - j)
x, nn = divmod(nn, p)
s += chr(x + ord('a'))
return s
def main(istr, ostr):
n, = list(map(int, istr.readline().strip().split()))
result = solve(n)
print(result, file=ostr)
if __name__ == "__main__":
import sys
main(sys.stdin, sys.stdout)
| 1 | 11,851,639,483,008 | null | 121 | 121 |
def resolve():
X = int(input())
for a in range(200):
for b in range(-199, 199):
if (a**5 - b**5) == X:
print(a, b)
return
if __name__ == "__main__":
resolve() |
# ABC152
a, b = map(int, input().split())
print(min(str(a)*b, str(b)*a))
| 0 | null | 54,852,827,936,012 | 156 | 232 |
n=int(input())
s=[str(input()) for _ in range(n)]
from collections import Counter
results = Counter(s)
max_num = results.most_common()[0][1]
max_key_list = [kv[0] for kv in results.items() if kv[1] == max_num]
for i in sorted(max_key_list):
print(i)
| n, x, m = map(int, input().split())
lis = set()
loop_lis = []
cnt = 0
while x not in lis:
cnt += 1
lis.add(x)
loop_lis.append(x)
x = pow(x, 2) % m
if cnt == n:
print(sum(lis))
exit()
start = loop_lis.index(x)
length = len(loop_lis) - start
loop_sum = sum(loop_lis[start:])
before = sum(loop_lis[:start])
loop = loop_sum * ((n - start) // length)
remain = sum(loop_lis[start : (start + (n - start) % length)])
print(before + loop + remain)
| 0 | null | 36,144,627,635,470 | 218 | 75 |
def insertionSort(A, n, g):
for i in range(g,n):
v = A[i]
j = i - g
while j >= 0 and A[j] > v:
A[j+g] = A[j]
j = j - g
global cnt
cnt += 1
A[j+g] = v
def shellSort(A, n):
global cnt
cnt = 0
G =[]
g = 0
for h in range(100):
g = 3*g + 1
if g <= n:
G.insert(0,g)
m = len(G)
for i in range(m):
insertionSort(A, n, G[i])
print(m)
print(*G)
print(cnt)
print(*A,sep="\n")
n = int(input())
A = [int(input()) for i in range(n)]
shellSort(A, n)
| N, K = map(int, input().split())
count = 0
num_people = []
num_people_snacks = []
for i in range(1, N + 1):
num_people.append(i)
while K > count:
d = int(input())
A = list(map(int, input().split()))
for k in A:
num_people_snacks.append(k)
count += 1
ans = 0
for j in range(N):
if num_people[j] not in num_people_snacks:
ans += 1
print(ans) | 0 | null | 12,365,417,121,360 | 17 | 154 |
import sys
class UnionFind:
def __init__(self, n):
self.table = [-1] * n
def _root(self, x):
stack = []
tbl = self.table
while tbl[x] >= 0:
stack.append(x)
x = tbl[x]
for y in stack:
tbl[y] = x
return x
def find(self, x, y):
return self._root(x) == self._root(y)
def union(self, x, y):
r1 = self._root(x)
r2 = self._root(y)
if r1 == r2:
return
d1 = self.table[r1]
d2 = self.table[r2]
if d1 <= d2:
self.table[r2] = r1
self.table[r1] += d2
else:
self.table[r1] = r2
self.table[r2] += d1
def roots(self):
return [i for i, x in enumerate(self.table) if x < 0]
def group_count(self):
return len(self.roots())
def main():
n, m = map(int, sys.stdin.buffer.readline().split())
U = UnionFind(n)
for i in sys.stdin.buffer.readlines():
a, b = map(lambda x: int(x) - 1, i.split())
U.union(a, b)
print(U.group_count() - 1)
if __name__ == "__main__":
main()
| import math
a,b,x = map(int,input().split())
if x >= 0.5 * a**2 * b:
tan_x = 2*(b*a**2 -x)/a**3
else:
tan_x = (b**2 * a)/(2*x)
print(math.degrees(math.atan(tan_x)))
| 0 | null | 83,144,277,168,940 | 70 | 289 |
A = map(int, input().split())
print('bust' if(sum(A) >= 22) else 'win')
| a = [int(v) for v in input().rstrip().split()]
r = 'bust' if sum(a) >= 22 else 'win'
print(r)
| 1 | 118,505,862,676,652 | null | 260 | 260 |
from itertools import permutations
n = int(input())
p = tuple(map(int,input().split()))
q = tuple(map(int,input().split()))
per = [0] + list(permutations(list(range(1,n+1))))
pnum = per.index(p)
qnum = per.index(q)
ans = abs(pnum-qnum)
print(ans) | import bisect
N = int(input())
Ls = list(map(int, input().split(" ")))
Ls.sort()
ans = 0
for i in range(0,N-2):
for j in range(i+1,N-1):
k = bisect.bisect_left(Ls,Ls[i]+Ls[j])
ans += k - (j + 1)
print(ans) | 0 | null | 135,677,351,899,050 | 246 | 294 |
X, K, D =map(int,input().split())
X = abs(X)
if X > K*D:
print(X-K*D)
else:
greed = X//D
if (K - greed)%2 == 0:
print(X-greed*D)
else:
print((1+greed)*D -X) | import math
x, k, d = map(int, input().split())
x = abs(x)
straight = min(k, math.floor(x / d))
k -= straight
x -= straight * d
if(k % 2 == 0):
print(x)
else:
print(abs(x - d)) | 1 | 5,215,152,622,560 | null | 92 | 92 |
from collections import defaultdict
from collections import deque
from collections import Counter
import itertools
import math
def readInt():
return int(input())
def readInts():
return list(map(int, input().split()))
def readChar():
return input()
def readChars():
return input().split()
n,k = readInts()
r,s,p = readInts()
t = list(input())
his = ["-1"]
ans = 0
for i in range(len(t)):
if t[i]=="r":
me = "p"
point = p
elif t[i]=="s":
me = "r"
point = r
else:
me = "s"
point = s
if his[max(0,i-k+1)]==me:
his.append(i)
else:
ans+=point
his.append(me)
print(ans) | n = int(input())
left = []
midplus = []
midzero = []
midminus = []
right = []
L = []
R = []
for i in range(n):
s = input()
l = 0
r = 0
for x in s:
if x == '(':
l += 1
else:
if l > 0:
l -= 1
else:
r += 1
if l > 0 and r == 0:
left.append((l, r))
elif l > 0 and r > 0:
if l > r:
midplus.append((r, l)) # a,b-a
elif l == r:
midzero.append((r,l))
else:
midminus.append((r, l))
elif l == 0 and r > 0:
right.append((l, r))
L.append(l)
R.append(r)
if sum(L) != sum(R):
print('No')
exit()
A = 0
B = 0
for x in left:
A += x[0]
for x in right:
B += x[1]
midplus = sorted(midplus, key=lambda x: (x[0], -x[1]))
midminus = sorted(midminus, key=lambda x: -x[1])
mid = midplus + midzero + midminus
l = A
r = 0
for a, b in mid:
if l < a:
print('No')
exit()
l -= a
l += b
print('Yes')
| 0 | null | 65,235,342,150,798 | 251 | 152 |
K = int(input())
if K % 2 == 0 or K % 5 == 0:
print(-1)
else:
i = 1
r = 7 % K
while(True):
if r == 0:
print(i)
break
r = (r * 10 + 7) % K
i += 1
| from itertools import combinations
N = int(input())
L = list(map(int, input().split()))
ans = 0
for a, b, c in combinations(L, 3):
if a == b or b ==c or a == c:
continue
if a + b + c - max(a, b, c) > max(a, b, c):
ans += 1
print(ans) | 0 | null | 5,589,699,462,060 | 97 | 91 |
n = int(input())
s = input()
total = 1
for c in 'RGB':
total *= s.count(c)
for i in range(1, n - 1):
for j in range(1, min(i + 1, n - i)):
if s[i] != s[i - j] and s[i - j] != s[i + j] and s[i] != s[i + j]:
total -= 1
print(total) | n, m = map(int, input().split())
a = list(map(int, input().split()))
dp = [float('inf') for _ in range(n+1)]
dp[0] = 0
for i in range(n):
for money in a:
next_money = i + money
if next_money > n:
continue
dp[next_money] = min(dp[i] + 1, dp[next_money])
print(dp[n])
| 0 | null | 18,189,253,305,952 | 175 | 28 |
n=int(input())
a=list(map(int,input().split()))
cnt=[0]*(max(a)+4)
cnt[0]=3
mod=10**9+7
ans=1
for i in range(n):
ans*=cnt[a[i]]
ans%=mod
cnt[a[i]]-=1
cnt[a[i]+1]+=1
print(ans)
| N=int(input())
A=map(int, input().split())
P=1000000007
ans = 1
cnt = [3 if i == 0 else 0 for i in range(N + 1)]
for a in A:
ans=ans*cnt[a]%P
if ans==0:
break
cnt[a]-=1
cnt[a+1]+=1
print(ans) | 1 | 129,673,004,336,870 | null | 268 | 268 |
X,Y=map(int,input().split())
M=[0]*206
M[0],M[1],M[2]=300000,200000,100000
if X+Y==2:
print(1000000)
else:
print(M[X-1]+M[Y-1]) | def main():
X, Y = map(int, input().split())
ans = 0;
if X == 1:
ans += 300000
elif X == 2:
ans += 200000
elif X == 3:
ans += 100000
if Y == 1:
ans += 300000
elif Y == 2:
ans += 200000
elif Y == 3:
ans += 100000
if X == 1 and Y == 1:
ans += 400000
print(ans)
if __name__ == '__main__':
main() | 1 | 140,282,053,985,668 | null | 275 | 275 |
#akash mandal: jalpaiguri government engineering college
import sys,math
def ii(): return int(input())
def mii(): return map(int,input().split())
def lmii(): return list(mii())
def main():
A,B,C=mii()
print("Yes" if B*C>=A else "No")
if __name__=="__main__":
main() | N = int(input())
A = list(map(int, input().split()))
Q = int(input())
d = {}
v = 0
ans = []
for a in A:
d[a] = d.get(a, 0) + 1
v += a
for i in range(Q):
B, C = map(int, input().split())
v += d.get(B, 0) * (C - B)
d[C] = d.get(C, 0) + d.get(B, 0)
d[B] = 0
ans.append(v)
for a in ans:
print(a)
| 0 | null | 7,861,310,343,262 | 81 | 122 |
N = int(input())
L = list(map(int, input().split()))
L.sort(reverse=True)
ans = 0
for i in range(N-2):
for j in range(i+1, N-1):
ok = i
ng = N
while ng - ok > 1:
mid = (ok + ng) // 2
if L[mid] > L[i] - L[j]:
ok = mid
else:
ng = mid
if ok > j:
ans += ok - j
print(ans)
| import math
n = int(input())
s = 0
for a in range(n):
for b in range(n):
d = math.gcd(a + 1, b + 1)
for c in range(n):
s += math.gcd(c + 1, d)
print(s) | 0 | null | 103,628,008,531,420 | 294 | 174 |
n, k = map(int, input().split())
ans = 0
for i in range(k, n+2):
l = (i*(i-1))*0.5
h = (i*(2*n-i+1))*0.5
ans += (h-l+1)
print(int(ans) % (10**9+7)) | from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT() : return int(input())
def MAP() : return map(int,input().split())
def LIST() : return list(MAP())
def dfs(s,d,i):
for j in range(i+1):
s[d] = chr(ord('a')+j)
if d < len(s) - 1:
dfs(s, d+1, max(j+1, i))
else:
a.add("".join(s))
n = INT()
s = ['a']*n
a = set()
dfs(s, 0, 0)
b = sorted(list(a))
for x in b:
print(x) | 0 | null | 42,803,968,992,708 | 170 | 198 |
s = input()
s = '0' + s[::-1]
dp = [[0, 0] for _ in range(len(s) + 1)]
for i in range(len(s)):
for j in range(2):
if j == 0: #ぴったり
dp[i + 1][j] = min(dp[i]) + int(s[i])
else: #1枚多めに払う
dp[i + 1][j] = min(dp[i][1] + 9 - int(s[i]), dp[i][0] + 11 - int(s[i]))
print(min(dp[-1])) | import sys
n=int(input())
a=list(map(int,input().split()))
b=a[:]
for i in range(len(a)):
if a[i]%2!=0:
b.remove(a[i])
for i in b:
if i%3!=0:
if i%5!=0:
print('DENIED')
sys.exit()
print('APPROVED') | 0 | null | 69,963,136,111,238 | 219 | 217 |
def main():
a, b = map(int, input().split())
str_a = str(a) * b
str_b = str(b) * a
if str_a < str_b:
print(str_a)
else:
print(str_b)
if __name__ == '__main__':
main()
| n = int(input())
A = [[0 for i in range(n)] for j in range(n)]
for i in range(n):
u, k, *v = list(map(int, input().split()))
for j in v:
A[int(u)-1][int(j)-1] = 1
# A[int(j)-1][int(u)-1] = 1
# for row in A:
# msg = ' '.join(map(str, row))
# # print(msg)
d = [-1] * n
f = [-1] * n
t = 0
# recursive
def dfs(u):
global t
# print('visit:', str(u), str(t))
t += 1
d[u] = t
for i in range(len(A[u])):
if A[u][i] == 1 and d[i] == -1:
dfs(i)
t += 1
f[u] = t
for i in range(n):
if d[i] == -1:
# print('start from:', str(i))
dfs(i)
for i in range(n):
print(str(i+1), str(d[i]), str(f[i]))
| 0 | null | 42,411,622,128,160 | 232 | 8 |
a=list(map(int,input().split()))
print('bust' if sum(a)>21 else 'win') | #!/usr/bin/env python3
print("bwuisnt"[eval(input().replace(" ", "+")) < 22::2])
| 1 | 118,857,919,623,552 | null | 260 | 260 |
import sys, itertools
print(len(set(itertools.islice(sys.stdin.buffer, 1, None)))) | import random
D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for i in range(D)]
t = [int(input()) for i in range(D)]
A = [0]*26
ret = 0
for i in range(D):
ret += s[i][t[i]-1]
# print(ret)
A[t[i]-1] = i+1
for j in range(26):
ret -= c[j] * (i+1 - A[j])
print(ret)
| 0 | null | 20,193,464,337,970 | 165 | 114 |
def main():
# a, b = list(map(float, input().split()))
s = input()
return s[:3]
if __name__ == '__main__':
result = main()
print(result) | def main():
s = input()
if s.count('hi') == len(s) // 2 and len(s) % 2 == 0:
print('Yes')
else:
print('No')
if __name__ == '__main__':
main() | 0 | null | 33,966,057,322,780 | 130 | 199 |
import heapq
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
L = []
ans = 0
heapq.heappush(L, -A[0])
for i in range(1, N):
max = heapq.heappop(L)
max *= -1
ans += max
heapq.heappush(L, -A[i])
heapq.heappush(L, -A[i])
print(ans)
| import sys
from collections import defaultdict as dd
from collections import deque
from functools import *
from fractions import Fraction as f
from copy import *
from bisect import *
from heapq import *
#from math import *
from itertools import permutations ,product
def eprint(*args):
print(*args, file=sys.stderr)
zz=1
#sys.setrecursionlimit(10**6)
if zz:
input=sys.stdin.readline
else:
sys.stdin=open('input.txt', 'r')
sys.stdout=open('all.txt','w')
def inc(d,c):
d[c]=d[c]+1 if c in d else 1
def bo(i):
return ord(i)-ord('A')
def li():
return [int(xx) for xx in input().split()]
def fli():
return [float(x) for x in input().split()]
def comp(a,b):
if(a>b):
return 2
return 2 if a==b else 0
def gi():
return [xx for xx in input().split()]
def fi():
return int(input())
def pro(a):
return reduce(lambda a,b:a*b,a)
def swap(a,i,j):
a[i],a[j]=a[j],a[i]
def si():
return list(input().rstrip())
def mi():
return map(int,input().split())
def gh():
sys.stdout.flush()
def isvalid(i,j):
return 0<=i<n and 0<=j<n
def bo(i):
return ord(i)-ord('a')
def graph(n,m):
for i in range(m):
x,y=mi()
a[x].append(y)
a[y].append(x)
t=1
def find(a,i):
if i==a[i]:
return a[i]
a[i]=find(a,a[i])
return a[i]
def union(a,x,y):
xs=find(a,x)
ys=find(a,y)
if xs!=ys:
if rank[xs]<rank[ys]:
xs,ys=ys,xs
a[ys]=xs
rank[xs]+=1
while t>0:
t-=1
n,m=mi()
a=[i for i in range(n+1)]
rank=[0]*(n+1)
for i in range(m):
x,y=mi()
union(a,x,y)
d=[0]*(n+1)
for i in range(1,n+1):
a[i]=find(a,i)
d[a[i]]+=1
print(max(d))
| 0 | null | 6,533,504,233,982 | 111 | 84 |
n=int(input())
a=("")
for _ in range(n):
a=a+"ACL"
print(a) | N = int(input())
S = input()
if N%2 == 1:
print("No")
else:
a = 0
for i in range(N//2):
if S[i] != S[N//2+i]:
a += 1
if a == 0:
print("Yes")
else:
print("No") | 0 | null | 74,191,731,491,290 | 69 | 279 |
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
A.sort()
A_max = A[-1]
dp = [1]*(A_max+1)
# dp[i] = 1: iはAのどの要素の倍数でもない
# dp[i] = 0: iはAの要素の倍数である
for a in A:
if not dp[a]:
continue
y = a*2
while y <= A_max:
dp[y] = 0
y += a
# Aの要素それぞれについて、dp[a] = 1ならよいが
# Aの要素ai,ajでai=ajとなる場合、上の篩では通過しているのに
# 条件を満たさない
cnt = dict(Counter(A))
ans = 0
for a in A:
if cnt[a] >= 2:
continue
if dp[a]:
ans += 1
print(ans) | # でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
import sys
def main(N, A):
C = [0] * (10**6 + 1)
for a in A:
if C[a] == 1:
C[a] = -1
continue
if C[a] == -1:
continue
C[a] = 1
for b in range(a + a, 10 ** 6 + 1, a):
C[b] = -1
ans = 0
for a in A:
if C[a] == 1:
ans += 1
print(ans)
if __name__ == '__main__':
input = sys.stdin.readline
N = int(input())
*A, = map(int, input().split())
main(N, A)
| 1 | 14,470,243,211,970 | null | 129 | 129 |
S = str(input())
L = len(S)
ans = "x" * L
print(ans) | import math
x,k,d = map(int,input().split())
d = abs(d)
x = abs(x)
if k*d<=x:
print(x-k*d)
else:
e = math.floor(x/d)
k -= e
x = x-e*d
if k%2 == 0:
print(x)
else:
print(abs(x-d))
| 0 | null | 38,881,051,256,752 | 221 | 92 |
s = list(input())
q = int(input())
rvs = []
i = 0
j = 0
p = []
order = []
for i in range(q):
order.append(input().split())
if order[i][0] == "replace":
p = []
p = list(order[i][3])
for j in range(int(order[i][1]), int(order[i][2]) + 1):
s[j] = p[j - int(order[i][1])]
elif order[i][0] == "reverse":
ss = "".join(s[int(order[i][1]):int(order[i][2]) + 1])
rvs = list(ss)
rvs.reverse()
for j in range(int(order[i][1]), int(order[i][2]) + 1):
s[j] = rvs[j - int(order[i][1])]
# temp = s[int(order[i][1])]
# s[int(order[i][1])] = s[int(order[i][2])]
# s[int(order[i][2])] = temp
elif order[i][0] == "print":
ss = "".join(s)
print("%s" % ss[int(order[i][1]):int(order[i][2]) + 1])
| s = input()
n = int(input())
for _ in range(n):
O = list(map(str, input().split()))
i = int(O[1])
j = int(O[2])
if O[0] == 'print':
print(s[i:j + 1])
elif O[0] == 'reverse':
ss = s[i:j + 1]
s = s[:i] + ss[::-1] + s[j + 1:]
else:
p = O[3]
s = s[:i] + p + s[j + 1:]
| 1 | 2,068,643,376,570 | null | 68 | 68 |
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *
_, D1 = MAP()
_, D2 = MAP()
if D1+1 == D2:
print("0")
else:
print("1")
| def main():
day = [list(map(int, input().split())) for _ in range(2)]
print(1 if day[0][0] + 1 == day[1][0] else 0)
if __name__ == '__main__':
main()
| 1 | 124,076,357,020,142 | null | 264 | 264 |
N=int(input())
mod=10**9+7
print((pow(10,N,mod)-pow(9,N,mod)-pow(9,N,mod)+pow(8,N,mod))%mod)
| K = int(input())
moji = 'ACL'
for i in range(K):
print(moji, end='')
| 0 | null | 2,699,005,205,224 | 78 | 69 |
A, B = map(int, input().split())
ans = A*B
if A > 9 or B > 9:
ans = -1
print(ans) | a, b = map(int, input().split())
ans = '-1'
if a < 10 and b < 10:
ans = a*b
print(ans) | 1 | 157,454,890,606,750 | null | 286 | 286 |
N, R = list(map(int, input().split(' ')))
i = R if N >= 10 else R+100*(10-N)
print(i) | import sys
sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline
def solve():
n, r = map(int,input().split())
if 10 > n:
print(r + (100 * (10 - n)))
else:
print(r)
if __name__ == '__main__':
solve()
| 1 | 63,430,700,738,474 | null | 211 | 211 |
S = ['0'] + list(input()) + ['0']
N = len(S)
flag = False
ans = 0
for i in range(N - 1, 0, -1):
j = int(S[i])
if flag:
j += 1
S[i] = j
if j <= 5:
if j == 5 and int(S[i - 1]) >= 5:
ans += j
flag = True
else:
ans += j
flag = False
else:
ans += 10 - j
flag = True
if flag:
ans += 1
# print (ans)
count = 0
for s in S:
if s == 5:
count += 1
else:
ans -= max(0, count - 2)
count = 0
print (ans)
| # -*- coding: utf-8 -*-
import sys
A,B,C,K = list(map(int, input().rstrip().split()))
#-----
sum_num = 0
for num,cnt in [(1,A), (0,B), (-1,C)]:
if cnt <= K:
K -= cnt
sum_num += num*cnt
else:
print( sum_num + num*K )
sys.exit()
print(sum_num)
| 0 | null | 46,332,360,060,900 | 219 | 148 |
MOD = 10 ** 9 + 7
INF = 10 ** 10
import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)
from bisect import bisect_left,bisect_right
from collections import deque
def main():
n,k = map(int,input().split())
ans = 0
G = [0] * (1 + k)
for g in range(k,0,-1):
ret = pow((k//g),n,MOD)
for j in range(2 * g,k + 1,g):
ret -= G[j]
G[g] = ret
ans += ret * g
ans %= MOD
print(ans)
if __name__ =='__main__':
main() | s = input()
a = len(s)//2
count = 0
for i in range(a):
if s[i] != s[-i-1]:
count += 1
print(count)
| 0 | null | 78,787,308,693,284 | 176 | 261 |
a,b=map(int,input().split())
if a<b:
print(str(a)*b)
elif a>b:
print(str(b)*a)
elif a==b:
print(str(a)*b)
| A,B = map(int, input().split())
A1,B1 = str(A), str(B)
A2 = int(str(A)*B)
B2 = int(str(B)*A)
if A2 >= B2:
print(A2)
else:
print(B2) | 1 | 84,038,062,427,088 | null | 232 | 232 |
n = int(raw_input().strip())
commands = []
for i in range(n):
commands.append(raw_input().strip())
d = [False]*67108870
def hash(s):
ret = 0
i = 0
for dg in s:
if dg == 'A':
ret += 0 * 4**i
elif dg == 'C':
ret += 1 * 4**i
elif dg == 'G':
ret += 2 * 4**i
elif dg == 'T':
ret += 3 * 4**i
i += 1
return ret
def insert(d,s):
h = hash(s)
d[h] = True
def find(d,s):
h = hash(s)
if d[h]: print 'yes'
else: print 'no'
for c in commands:
c += 'C'
if c[0] == 'i':
insert(d,c[7:])
else:
find(d,c[5:]) | from collections import defaultdict
n = int(input())
dic = defaultdict(lambda: 0)
for _ in range(n):
com = input().split(' ')
if com[0]=='insert':
dic[com[1]] = 1
else:
if com[1] in dic:
print('yes')
else:
print('no') | 1 | 75,495,021,782 | null | 23 | 23 |
from collections import defaultdict
iim = lambda: map(int, input().rstrip().split())
def resolve():
N = int(input())
A = list(iim())
ans = 0
dp = [0]*N
for i, ai in enumerate(A):
x = i + ai
if x < N:
dp[x] += 1
x = i - ai
if x >= 0:
ans += dp[x]
print(ans)
resolve() | import math
def lcm_base(x, y):
return (x * y) // math.gcd(x, y)
x = int(input())
lcm = lcm_base(360, x)
print(lcm//x) | 0 | null | 19,658,091,774,230 | 157 | 125 |
from math import gcd
def main():
a, b = map(int, input().split())
r = (a * b) // gcd(a, b)
print(r)
if __name__ == '__main__':
main() | if __name__ == '__main__':
x = int(input())
print(x ** 3) | 0 | null | 56,851,907,501,152 | 256 | 35 |
n=int(input())
ans=10**n
ans-=2*9**n
ans+=8**n
ans%=10**9+7
print(ans) | t = int(input())
mod = 10**9 + 7
if t==1:
print(0)
else:
kans = 1
for i in range(t):
kans *= 10
kans = kans % mod
ans = 1
for i in range(t):
ans *= 9
ans = ans % mod
bans = 1
for i in range(t):
bans *= 8
bans = bans % mod
f = kans - ans*2 + bans
f = f%mod
print(f)
| 1 | 3,157,866,784,842 | null | 78 | 78 |
def bubble_sort(List):
cnt=0
l=len(List)
for i in range(l):
for j in range(l-1,i,-1):
if List[j]<List[j-1]:
temp=List[j]
List[j]=List[j-1]
List[j-1]=temp
cnt+=1
return cnt
def main():
N=input()
N_List=map(int,raw_input().split())
cnt=bubble_sort(N_List)
for k in range(len(N_List)):
N_List[k]=str(N_List[k])
print(" ".join(N_List))
print(cnt)
if __name__=='__main__':
main() | N, K = map(int, input().split())
A = sorted(list(map(int, input().split())))
F = sorted(list(map(int, input().split())), reverse=True)
# にぶたん := N人のメンバーそれぞれが完食にかかる時間のうち最大値をxに以下にできるか?
ok, ng = 10 ** 12 + 1, -1
while ok - ng > 1:
x = (ok + ng) // 2
need_training = 0
for a, f in zip(A, F):
need_training += max(0, a - x // f)
if need_training > K:
ng = x
break
else:
ok = x
print(ok)
| 0 | null | 82,628,721,502,316 | 14 | 290 |
n = input()
if '7' in n:
print('Yes')
exit()
else:
print('No') | import numpy as np
N, S = map(int, input().split())
A = list(map(int, input().split()))
mod = 998244353
f = np.zeros(3100, np.int64)
ans = 0
f[0] = 1
for a in A:
g = f.copy()
f[a:] += g[:-a]
f += g
f %= mod
print(f[S])
| 0 | null | 25,937,242,538,272 | 172 | 138 |
n,m = map(int,input().split())
if n % 2 == 1:
ans = [[1+i,n-i] for i in range(n//2)]
else:
ans = [[1+i,n-i] for i in range(n//4)]+[[n//2+1+i,n//2-1-i] for i in range(n//2-n//4-1)]
for i in range(m):
print(ans[i][0],ans[i][1]) | M=[]
F=[]
R=[]
while True:
m,f,r=map(int,raw_input().split())
if (m,f,r)==(-1,-1,-1):
break
else:
M.append(m)
F.append(f)
R.append(r)
for i in range(len(M)):
sum=M[i]+F[i]
if M[i]==-1 or F[i]==-1:
print('F')
elif sum>=80:
print('A')
elif sum>=65:
print('B')
elif sum>=50:
print('C')
elif sum>=30:
if R[i]>=50:
print('C')
else:
print('D')
else:
print('F') | 0 | null | 15,053,343,510,392 | 162 | 57 |
S = int(input())
s = S%60
m = (S-s)/60%60
h = S/3600%24
answer = str(int(h))+":"+str(int(m))+":"+str(s)
print(answer)
| s = int(input())
m = 0
h = 0
if s >= 60:
m = int(s / 60)
s = s % 60
if m >= 60:
h = int(m / 60)
m = m % 60
print(h,end = ":")
print(m,end = ":")
print(s)
| 1 | 334,389,746,720 | null | 37 | 37 |
x, y, z = map(int, input().split())
print("{0} {1} {2}".format(z, x, y)) | import sys
num = int(sys.stdin.readline())
ans = num ** 3
print ans | 0 | null | 19,054,184,100,160 | 178 | 35 |
m1, d1 = map(int, input().split())
m2, d2 = map(int, input().split())
print(1 if m2 == m1 % 12 + 1 and d2 == 1 else 0) | M1, D1 = input().split()
M2, D2 = input().split()
M1 = int(M1)
M2 = int(M2)
if M1!=M2:
print('1')
else:
print('0') | 1 | 124,391,814,811,798 | null | 264 | 264 |
dicpos = {}
dicneg = {}
N = int(input())
for i in range(N):
buf = [0]
for s in input():
if s=="(":
buf.append(buf[-1] + 1)
else:
buf.append(buf[-1] - 1)
low = min(buf)
last = buf[-1]
if last>0:
if low in dicpos:
dicpos[low].append(last)
else:
dicpos[low] = [last]
else:
if low-last in dicneg:
dicneg[low-last].append(-last)
else:
dicneg[low-last] = [-last]
neg_sorted = sorted(dicneg.items(), key=lambda x:x[0], reverse=True)
pos_sorted = sorted(dicpos.items(), key=lambda x:x[0], reverse=True)
#print(neg_sorted)
#print(pos_sorted)
summ = 0
flag = 0
for i in pos_sorted:
if flag == 1:
break
for j in i[1]:
if summ + i[0] < 0:
flag = 1
print("No")
break
summ += j
summ2 = 0
if flag == 0:
for i in neg_sorted:
if flag == 1:
break
for j in i[1]:
if summ2 + i[0] < 0:
flag = 1
print("No")
break
summ2 += j
if flag == 0:
if summ == summ2:
print("Yes")
else:
print("No") | a,b,c= (int(x) for x in input().split())
A = int(a)
B = int(b)
C = int(c)
if A+B+C >= 22:
print("bust")
else:
print("win") | 0 | null | 71,292,413,852,000 | 152 | 260 |
import math
a = raw_input()
for i, b in enumerate(a.split()):
if i==0:
W=int(b)
elif i==1:
H=int(b)
elif i==2:
x=int(b)
elif i==3:
y=int(b)
else:
r=int(b)
if r<=x<=W-r and r<=y<=H-r:
print 'Yes'
else:
print 'No' | W,H,x,y,r = map(int,input().split())
cr = x+r
cl = x-r
ct = y+r
cb = y-r
if ct <= H and cb >= 0 and cl >= 0 and cr <= W:
print('Yes')
else:
print('No') | 1 | 443,364,533,152 | null | 41 | 41 |
x, y = map(int, input().split())
for a in range(x+1):
for b in range(x+1-a):
if a + b == x and 2*a + 4*b == y:
print("Yes")
exit()
print("No") | n, m = map(int, input().split())
*A, = map(int, input().split())
A.sort()
# Aの累積和を求めておく
S = [0]
x = 0
for a in A:
x += a
S.append(x)
def lower(x):
# A[i]<xなるiの個数
left = -1
right = n
while right-left > 1:
mid = (left+right)//2
if A[mid] < x:
left = mid
else:
right = mid
return right
def lower_pair(x):
# A[i]+A[j]<xなる(i,j)の個数
cnt = 0
for a in A:
cnt += lower(x-a)
return cnt
# A[i]+A[j]のm番目に大きい値を求める
# lower_pair(x)<n**2-mなる最大のxを求めればよい
left = 2*min(A)
right = 2*max(A)
while right-left > 1:
mid = (left+right)//2
if lower_pair(mid) < n**2-m:
left = mid
else:
right = mid
x = left
# A[i]+A[j]>=xとなる(i,j)の個数とA[i]+A[j]の総和を求める
k = n**2-lower_pair(x)
s = 0
for a in A:
cnt = lower(x-a)
s += (n-cnt)*a+S[n]-S[cnt]
print(s-(k-m)*x)
| 0 | null | 61,236,582,924,608 | 127 | 252 |
# B - Papers, Please
N = int(input())
my_list = list(input().split())
j = 0
for i in range(0, N):
if int(my_list[i]) % 2 == 0:
if int(my_list[i]) % 3 != 0 and int(my_list[i]) % 5 != 0:
j += 1
if j != 0:
print('DENIED')
else:
print('APPROVED')
| n=int(input())
a=[int(i) for i in input().split()]
flag=0
for i in range(0,len(a)):
if(a[i]%2==0 and (a[i]%3==0 or a[i]%5==0)):
pass
elif(a[i]%2==0 and (a[i]%3!=0 or a[i]%5!=0)):
flag=1
break
if(flag==1):
print('DENIED')
else:
print('APPROVED') | 1 | 68,811,671,458,752 | null | 217 | 217 |
N = int(input())
a = list(map(int, input().split()))
x = 0
for r in a:
x ^= r
print(' '.join([str(x^r) for r in a])) | n=int(input())
arr=list(map(int,input().split()))
x=0
for i in arr:
x^=i
ans=[]
for i in arr:
ans.append(x^i)
print(*ans) | 1 | 12,535,463,541,250 | null | 123 | 123 |
MOD = int(1e+9 + 7)
N, K = map(int, input().split())
cnt = [0] * (K + 1) # 要素が全てXの倍数となるような数列の個数をXごとに求める
for x in range(1, K + 1):
cnt[x] = pow(K // x, N, MOD)
for x in range(K, 0, -1): # 2X, 3Xの個数を求めてひく
for i in range(2, K // x + 1):
cnt[x] -= cnt[x * i]
ans = 0
for k in range(K+1):
ans += cnt[k] * k
ans = ans % MOD
print(ans) | import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
#from collections import defaultdict
#d = defaultdict(int)
#import fractions
#import math
#import collections
#from collections import deque
#from bisect import bisect_left
#from bisect import insort_left
#N = int(input())
#A = list(map(int,input().split()))
#S = list(input())
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
#import itertools
#import heapq
#import numpy as np
#INF = float("inf")
#MOD = 10**9+7
MOD = 10**9+7
import math
N,K = map(int,input().split())
ans = [0]*K
for i in range(K):
p = K-i
a = pow(math.floor(K/p),N,MOD)
x = 1
while p*(x+1) <= K:
a -= ans[p*(x+1)-1]
x = x+1
ans[p-1] = a%MOD
s = 0
for i in range(K):
s += (i+1)*ans[i]
s = s%MOD
print(s) | 1 | 36,774,586,263,540 | null | 176 | 176 |
i = input()
print(i.swapcase())
| line = input()
for ch in line:
n = ord(ch)
if ord('a') <= n <= ord('z'):
n -= 32
elif ord('A') <= n <= ord('Z'):
n += 32
print(chr(n), end='')
print() | 1 | 1,478,521,310,772 | null | 61 | 61 |
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import collections
import itertools
import math
import sys
INF = float('inf')
def solve(N: int, A: "List[int]"):
c = collections.Counter(A+[i+1 for i in range(N)])
return "\n".join([f'{c[i+1]-1}' for i in range(N)])
def main():
sys.setrecursionlimit(10 ** 6)
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
A = [int(next(tokens)) for _ in range(N - 2 + 1)] # type: "List[int]"
print(solve(N, A))
if __name__ == '__main__':
main()
| import collections
n = int(input())
x = list(map(int, input().split()))
y = collections.Counter(x)
for i in range(1, len(x)+2):
print(y[i], end = "\n") | 1 | 32,774,149,996,400 | null | 169 | 169 |
n = int(input())
a = list(map(int, input().split()))
sum = 0
k = a[0]
for i in range(n - 1):
if k >= a[i + 1]:
sum += k - a[i + 1]
else:
k = a[i + 1]
print(sum)
| n = int(input())
a = list(map(int, input().split()))
dic = {}
ans = ''
for i in range(n):
dic[a[i]] = i+1
for i in range(n):
ans = ans + str(dic[i+1]) + ' '
print(ans) | 0 | null | 92,468,120,429,048 | 88 | 299 |
n,k=map(int,input().split())
a=list(map(int,input().split()))
current=[0]
dic={}
dic[0]=1
ans=0
for i in range(n):
current.append((current[-1]+a[i]-1)%k)
if i>=k-1:
dic[current[-k-1]]-=1
if current[-1] in dic:
ans+=dic[current[-1]]
dic[current[-1]]+=1
else:
dic[current[-1]]=1
print(ans) | N = input()
print(('Yes', 'No')[N[0] == N[1] == N[2]]) | 0 | null | 96,367,563,924,292 | 273 | 201 |
import sys
import resource
sys.setrecursionlimit(10000)
n,k=map(int,input().rstrip().split())
p=list(map(int,input().rstrip().split()))
c=list(map(int,input().rstrip().split()))
def find(start,now,up,max,sum,count,flag):
if start==now:
flag+=1
if start==now and flag==2:
return [max,sum,count]
elif count==up:
return [max,sum,count]
else:
count+=1
sum+=c[p[now-1]-1]
if max<sum:
max=sum
return find(start,p[now-1],up,max,sum,count,flag)
kara=[-10000000000]
for i in range(1,n+1):
m=find(i,i,n,c[p[i-1]-1],0,0,0)
if m[2]>=k:
m=find(i,i,k,c[p[i-1]-1],0,0,0)
if m[0]>kara[0]:
kara[0]=m[0]
result=kara[0]
elif m[1]<=0:
if m[0]>kara[0]:
kara[0]=m[0]
result=kara[0]
else:
w=k%m[2]
if w==0:
w=m[2]
spe=find(i,i,w,c[p[i-1]-1],0,0,0)[0]
if m[1]+spe>m[0] and m[1]*(k-w)//m[2]+spe>kara[0]:
kara[0]=m[1]*(k-w)//m[2]+spe
elif m[1]+spe<=m[0] and m[1]*((k-w)//m[2]-1)+m[0]>kara[0]:
kara[0]=m[1]*((k-w)//m[2]-1)+m[0]
result=kara[0]
print(result) | s = input()
k = int(input())
def seqcnt(s):
cnt=1
ans=0
bk=''
for c in s+' ':
if bk==c:
cnt+=1
else:
ans+=(cnt)//2
cnt=1
bk=c
return ans
cnt=seqcnt(s)
cnt2=seqcnt(s*2)
if len(set(list(s)))==1:
print(len(s)*k//2)
else:
print(cnt+(cnt2-cnt)*(k-1)) | 0 | null | 90,024,450,273,460 | 93 | 296 |
n=int(input())
a=list(map(int,input().split()))
b=[]
c=[]
for i in range(n):
b.append(a[i]-(i+1))
c.append(-(a[i]+i+1))
from collections import defaultdict
#cnt_b=Counter(b)
cnt_c=defaultdict(int)
ans=0
for i in range(n):
v=cnt_c[b[i]]
ans+=v
cnt_c[c[i]]+=1
print(ans) | import collections
n = int(input())
a = list(map(int, input().split()))
l = []
r = []
for i in range(n):
l.append(i+a[i])
r.append(i-a[i])
count_l = collections.Counter(l)
count_r = collections.Counter(r)
ans = 0
for i in count_l:
ans += count_r.get(i,0) * count_l[i]
print(ans) | 1 | 26,033,713,856,150 | null | 157 | 157 |
import math
a,b,x = map(int, input().split())
x /= a
if 2* x > a * b:
temp = 2*(a*b - x)/(a**2)
else:
temp = b**2/(2*x)
print(math.degrees(math.atan(temp))) | n = int(input())
a = input()
print(a.count("ABC")) | 0 | null | 130,991,471,723,350 | 289 | 245 |
N = int(input())
A = list(map(int, input().split()))
MOD = 10**9+7
ans = 1
dp = [0]*3
for a in A:
cnt = 0
for i in range(3):
if a == dp[i]:
cnt += 1
for i in range(3):
if a == dp[i]:
dp[i] += 1
break
ans = ans*cnt % MOD
print(ans)
| MOD = 10**9 + 7
def main():
N = int(input())
A = [int(i) for i in input().split()]
B = [0]*N
ans = 3
for a in A:
if a == 0:
if B[a] == 1:
ans *= 2
else:
ans *= B[a-1] - B[a]
B[a] += 1
if 3 < B[a] or (a != 0 and B[a-1] < B[a]):
ans = 0
break
ans %= MOD
print(ans)
if __name__ == '__main__':
main()
| 1 | 130,293,567,330,900 | null | 268 | 268 |
sum=0
s=0
A=input().split()
n=(int)(A[0])
t=(int)(A[1])
x=[0 for i in range(2*n)]
for i in range(n):
B=input().split()
k=2*i
x[k]=(B[0])
x[k+1]=(int)(B[1])
while len(x)>0:
s=x[1]-t
if s>0:
sum+=t
x.append(x[0])
x.append(s)
del x[0]
del x[0]
if s<=0:
sum+=x[1]
print( x[0],sum)
del x[0]
del x[0]
| import collections
calc_time = 0
hoge = collections.deque()
num, q = [int(x) for x in input().split()]
for _ in range(num):
name, t = input().split()
hoge.append([name, int(t)])
while hoge:
name, t = hoge.popleft()
if t - q > 0:
hoge.append([name, t-q])
calc_time += q
elif t == q:
calc_time += q
print ('{} {}'.format(name, calc_time))
elif t - q < 0:
calc_time += t
print ('{} {}'.format(name, calc_time))
| 1 | 43,670,298,620 | null | 19 | 19 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.