code1 stringlengths 16 427k | code2 stringlengths 16 427k | similar int64 0 1 | pair_id int64 2 178,025B ⌀ | question_pair_id float64 27.1M 177,113B ⌀ | code1_group int64 1 297 | code2_group int64 1 297 |
|---|---|---|---|---|---|---|
K=int(input())
A,B=map(int, input().split())
cnt=0
for i in range(B//K+1):
if A<=K*i and K*i<=B:
cnt+=1
print('OK' if cnt>0 else 'NG') | N,K,S=[int(x) for x in input().rstrip().split()]
ans=[]
if S==10**9:
for i in range(N):
if i+1<=K:
ans.append(S)
else:
ans.append(1)
else:
for i in range(N):
if i+1<=K:
ans.append(S)
else:
ans.append(S+1)
print(*ans)
| 0 | null | 58,940,405,135,890 | 158 | 238 |
num = list(map(int,input().split()))
sum = 500*num[0]
if num[1] <= sum:
print("Yes")
else:
print("No") | n = int(input())
s = input()
if(n % 2 == 0 and s[n//2:] * 2 == s):
print("Yes")
else:
print("No") | 0 | null | 121,942,056,117,540 | 244 | 279 |
import copy
import random
D = list(map(int, input().split()))
q = int(input())
for x in range(q):
y, z = map(int, input().split())
while True:
r = random.randint(0,3)
if r == 0:
Dt = copy.copy(D)
temp = Dt[0]
Dt[0] = Dt[4]
Dt[4] = Dt[5]
... | class Dice:
def __init__(self, state):
self.state = state
def vertical(self, direction):
s = self.state
state = [s[1], s[5], s[0], s[4]]
if direction < 0:
s[0], s[1], s[4], s[5] = state
elif 0 < direction:
s[0], s[1], s[4], s[5] = reversed(state)
return self
def lateral(sel... | 1 | 256,052,136,922 | null | 34 | 34 |
n=int(input())
a=list(map(int,input().split()))
f={}
f2={}
for i in range(n):
z=i+a[i]
z1=i-a[i]
#print(z,z1)
try:
f[z]+=1
except:
f[z]=1
try:
f2[z1]+=1
except:
f2[z1]=1
s=0
for i in f.keys():
if(i in f2):
s+=f[i]*f2[i]
print(s)
| import collections
N = int(input())
hList = list(map(int, input().split()))
count = 0
n_p = collections.Counter([ i + hList[i] for i in range(len(hList))])
for i in range(N):
if i - hList[i] > 0:
count += n_p.get(i - hList[i], 0)
print(count) | 1 | 26,023,876,098,818 | null | 157 | 157 |
n = int(input())
graph = [-1] + [list(map(int, input().split())) for _ in range(n)]
seen = [False]*(n+1)
seen[0] = True
d = [-1]*(n+1)
f = [-1]*(n+1)
time = 0
def dfs(v):
global time
time += 1
d[v] = time
seen[v] = True
k = graph[v][1]
if k > 0:
for i in range(k):
w = graph... | # AtCoder
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
... | 0 | null | 31,025,943,910,328 | 8 | 209 |
n=int(input())
s=str(input())
d=s.count('ABC')
print(d) | n = int(raw_input())
for i in range(n):
num = map(int, raw_input().split())
num.sort(reverse=True)
if num[0]**2 == num[1]**2 + num[2]**2:
print "YES"
else:
print "NO"
| 0 | null | 49,528,045,604,338 | 245 | 4 |
from collections import Counter
P = 998244353
N = int(input())
D = [int(x) for x in input().split()]
def solve():
if D[0] != 0:
return 0
total = 1
max_d = max(D)
counter = Counter(D)
if counter[0] != 1:
return 0
for i in range(max_d + 1):
if i not in counter:
return 0
if i > 1:
... | import sys
for n in sys.stdin:
l=map(int,n.split())
b=l[0]*l[1]
u=[max(l),min(l)]
while u[1]!=0:
u=[u[1],u[0]%u[1]]
print "%d %d"%(u[0],b/u[0]) | 0 | null | 77,303,586,731,136 | 284 | 5 |
N, K = map(int, input().split())
c = 1
while N//K != 0:
N = N//K
c += 1
print(c) | from sys import stdin, stdout
import math,sys,heapq
from itertools import permutations, combinations
from collections import defaultdict,deque,OrderedDict
from os import path
import bisect as bi
def yes():print('YES')
def no():print('NO')
if (path.exists('input.txt')):
#------------------Sublime-------------------... | 0 | null | 35,459,132,807,790 | 212 | 100 |
x = input()
a = x[::-1]
b = 0
c = 0
d = int(len(x))
while b + 1 <= d:
if x[b] == a[b]:
c = c
b = b + 1
else:
c = c + 1
b = b + 1
c = int(c/2)
print(c) | X = input()
if X.isupper():
print("A")
else:
print("a") | 0 | null | 65,511,639,358,880 | 261 | 119 |
while True:
H, W = map(int, raw_input().split())
if H == 0 or W == 0:
break
for _ in range(H):
print '#' * W
print '' | mod = 10**9 + 7
max_N = 2 * 10**5
def power(b, e):
if e == 0: return 1
half = power(b, e // 2)
if e % 2 == 0:
return (half * half) % mod
else:
return (((half * half) % mod) * b) % mod
def mod_inv(n):
return power(n, mod - 2)
fac = [1] * (max_N + 1)
for i in range(1, max_N + 1):
fac[i] = (i * fac[i - 1]) ... | 0 | null | 33,741,617,180,778 | 49 | 215 |
# Binary Search
def isOK(i, key):
'''
問題に応じて返り値を設定
'''
cnt = 0
for v in a:
cnt += (v + i - 1) // i - 1
return cnt <= key
def binary_search(key):
'''
条件を満たす最小/最大のindexを求める
O(logN)
'''
ok = 10 ** 9 # 条件を満たすindexの上限値/下限値
ng = 0 # 条件を満たさないindexの下限値-1/上限値+1... | from math import ceil
N, K = map(int, input().split())
A = list(map(int, input().split()))
def f(x):
cnt = 0
for a in A:
cnt += ceil(a / x) - 1
return True if cnt <= K else False
OK, NG = 10**9, 0
while OK - NG > 1:
mid = (OK + NG) // 2
if f(mid):
OK = mid
else:
NG = ... | 1 | 6,500,083,699,500 | null | 99 | 99 |
def resolve():
k,n = map(int,input().split())
a = list(map(int,input().split()))
l = a[0]+k-a[-1]
for i in range(1,n):
l = max(l,a[i]-a[i-1])
print(k-l)
resolve() | from sys import stdin, stdout
rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: map(int, stdin.readline().split())
INF, NINF = float('inf'), float('-inf')
def binom_tables(n, q):
fact = [1 for _ in range(n + 1)]
inv = [1 for _ in range(n + 1)]
for i in range(1, n+1):
fact[i] = (... | 0 | null | 33,456,205,462,452 | 186 | 151 |
# 171 A
X = input()
print('a') if X.islower() else print('A') | c = input()
if c.isupper():
print('A')
else:
print('a') | 1 | 11,284,498,304,480 | null | 119 | 119 |
n=int(input())
al='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ans=[]
s=input()
for i in range(len(s)):
ans.append(al[(ord(s[i])-65+n)%26])
print(''.join(ans)) | import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7 # 998244353
input=lambda:sys.stdin.readline().rstrip()
def resolve():
just, less = 0, INF
for d in input()[::-1]:
d = int(d)
njust = min(just + d, less + d + 1)
nless = min(just + (10-d), less + (9-d))
just... | 0 | null | 102,173,972,142,592 | 271 | 219 |
def resolve():
N, K = map(int, input().split())
H = list(map(int, input().split()))
h = sorted(H)[::-1]
ans = h[K:]
print(sum(ans))
resolve() | a, b = [int(i) for i in input().split(' ')]
answer1 = a // b
answer2 = a % b
answer3 = round(float(a) / float(b), 5)
print(answer1, answer2, answer3)
| 0 | null | 39,978,801,065,280 | 227 | 45 |
def insertion_sort(a, n, g, cnt):
for i in range(g,n,1):
v = a[i]
j = i - g #initial value
while j>=0 and a[j]>v:
a[j+g]=a[j]
j -= g
cnt += 1
a[j+g] = v
return a, cnt
def shell_sort(a,n,m,g):
cnt = 0
for i in range(m):
sorted_l... | n = int(input())
l = list(map(int, input().split()))
l.sort(reverse=True)
ans = 0
c = n - 1
for a in range(n - 2):
c = n - 1
for b in range(a + 1, n - 1):
# 各a,bに対してのcを尺取法で探索
while l[a] >= l[b] + l[c]:
c -= 1
if c <= b:
break
else:
# pr... | 0 | null | 85,619,209,092,730 | 17 | 294 |
MOD = 998244353
def main():
# もらうdp + 累積和
N, K = (int(i) for i in input().split())
LR = [[int(i) for i in input().split()] for j in range(K)]
dp = [0] * (N+2)
dpsum = [0] * (N+1)
dp[1] = 1
dpsum[1] = 1
for i in range(2, N+1):
for le, ri in LR:
L = max(0, i - ri - 1... | pi = 3.1415926535897
r = float(input())
print(pi*r**2, 2*pi*r)
| 0 | null | 1,692,157,650,672 | 74 | 46 |
N = int(input())
A = list(map(int, input().split()))
B = []
if N == 0:
if A[0] != 1:
print(-1)
exit()
else:
print(1)
exit()
else:
if A[0] != 0:
print(-1)
exit()
else:
B.append(1)
for i in range(1, N + 1):
B.append((B[i - 1] -... | # coding: utf-8
def solve(*args: str) -> str:
n = int(args[0])
A = list(map(int, args[1].split()))
if 0 < A[0]:
return '1' if n == 0 and A[0] == 1 else '-1'
R = [0]*(n+1)
R[0] = 1
for i in range(1, n+1):
R[i] = 2*(R[i-1]-A[i-1])
prev = 0
ret = 0
for i in range(n,... | 1 | 18,854,946,285,500 | null | 141 | 141 |
import sys
num = []
for i in sys.stdin:
H, W = i.split()
if H == W == '0':
break
num.append((int(H), int(W)))
for cnt in range(len(num)):
for h in range(num[cnt][0]):
for w in range(num[cnt][1]):
if w == 0 or w == num[cnt][1] - 1 or h == 0 or h == num[cnt][0] - 1:
... | while True:
h, w = map(int, raw_input().split())
if h == 0 and w == 0:
break
print(("#" * w + "\n") + ("#" + "." * (w-2) + "#" + "\n") * (h-2) + ("#" * w + "\n")) | 1 | 825,824,773,076 | null | 50 | 50 |
N, M, L = map(int, raw_input().split())
nm = [map(int, raw_input().split()) for n in range(N)]
ml = [map(int, raw_input().split()) for m in range(M)]
ml_t = []
for l in range(L):
tmp = []
for m in range(M):
tmp.append(ml[m][l])
ml_t.append(tmp)
for n in range(N):
tmp1 = nm[n]
col = [0]*L
... | n,m,l=map(int,raw_input().split())
matA=[map(int,raw_input().split()) for i in range(n)]
matB=[map(int,raw_input().split()) for j in range(m)]
for i in range(n):
for j in range(l):
print sum([matA[i][k]*matB[k][j] for k in range(m)]),
print | 1 | 1,401,400,680,992 | null | 60 | 60 |
import sys
input = sys.stdin.readline
import math
def INT(): return int(input())
def MAPINT(): return map(int, input().split())
def LMAPINT(): return list(map(int, input().split()))
def STR(): return input()
def MAPSTR(): return map(str, input().split())
def LMAPSTR(): return list(map(str, input().split()))
f_inf = f... | x=list(map(int,input().split()))
for i in range(len(x)):
if x[i]==0:
su=i+1
print(su) | 1 | 13,478,010,968,048 | null | 126 | 126 |
N = int(input())
ans = 0
if N % 2 == 0:
ans += N//10
ans += N//50
N //= 50
while N > 0:
N //= 5
ans += N
print(ans) | class queue():
def __init__(self):
self.head = 0
self.tail = 0
self.MAX = 100000
self.Q = [[0] for i in range(self.MAX)]
def is_empty(self):
return self.head == self.tail
def is_full(self):
return self.head == (self.tail + 1) % self.MAX
def enqueue(self... | 0 | null | 57,999,716,226,258 | 258 | 19 |
S = input()
a = S[0] == 'S'
b = S[1] == 'S'
c = S[2] == 'S'
if (a and b and c ):
print(0)
elif ( b or(a and c)):
print(1)
elif(a or c):
print(2)
else:
print(3) | s = input()
ans = 0
strek = 0
for i in range(3):
if s[i] == 'R':
tmp = "R"
strek += 1
ans = max(strek, ans)
else:
strek = 0
print(ans) | 1 | 4,904,429,178,660 | null | 90 | 90 |
x,y=map(int,input().split())
if ((4*x-y)%2==0 and (-2*x+y)%2==0) and (1<=(4*x-y)//2<=100 and 1<=(-2*x+y)//2<=100):
print('Yes')
elif ((4*x-y)%2==0 and (-2*x+y)%2==0) and (1<=(4*x-y)//2<=100 and (-2*x+y)//2==0):
print('Yes')
elif ((4*x-y)%2==0 and (-2*x+y)%2==0) and ((4*x-y)//2==0 and 1<=(-2*x+y)//2<=100):
... | s, t = input(), input()
print('Yes' if s == t[:-1] else 'No') | 0 | null | 17,535,195,986,322 | 127 | 147 |
# C - management
n = int(input())
al = list(map(int,input().split()))
s = [0]*n
level = 1
al.sort()
for i in range(len(al)):
if al[i] == level:
s[level-1] += 1
elif al[i] >= level:
level = al[i]
s[level-1] += 1
for j in s:
print(j)
| import sys
input()
for a,b,c in map(lambda x:sorted(map(int,x.split())),sys.stdin):
print(['NO','YES'][a*a+b*b==c*c])
| 0 | null | 16,342,788,485,220 | 169 | 4 |
def main():
n=int(input())
d=[0]+[-10**18]*n
for j,(a,i)in enumerate(sorted((-a,i)for i,a in enumerate(map(int,input().split())))):
d=[max(t-a*abs(~i-j+k+n),d[k-1]-a*abs(~i+k))for k,t in enumerate(d)]
print(max(d))
main() | import sys
n = int(input())
for i in range(1, n + 1):
x = i
if x % 3 == 0:
sys.stdout.write(" %d" % i)
else:
while x > 1:
if x % 10 == 3:
sys.stdout.write(" %d" % i)
break
x //= 10
print() | 0 | null | 17,250,188,531,524 | 171 | 52 |
A = str(input())
B = str(input())
sum=0
for i in range(len(A)):
if A[i]!=B[i]:
sum+=1
print(sum) | s = input()
t = input()
n = len(s)
ans = n
for i in range(n):
if s[i] == t[i]:
ans -= 1
print(ans) | 1 | 10,508,990,014,020 | null | 116 | 116 |
n,m,x = map(int,input().split())
ca = [list(map(int,input().split())) for i in range(n)]
c = [0]*n
a = [0]*n
for i in range(n):
c[i],a[i] = ca[i][0],ca[i][1:]
INF = 10**9
ans = INF
for i in range(1<<n):
understanding = [0]*m
cost = 0
for j in range(n):
if ((i>>j)&1):
cost += c[j... | n, m, x = map(int,input().split())
c = [0] *(n)
a = [[0] for _ in range(n)]
ans = 10**10
for i in range(n):
ca = list(map(int,input().split()))
c[i] = ca[0]
a[i] = ca[1:]
for i in range(1 << n):
skill = [0] * m
total_cost = 0
for j in range(n):
if (i>>j) & 1:
total_cost +=... | 1 | 22,186,835,934,230 | null | 149 | 149 |
n = int(input())
S = input()
r = S.count('R')
w = 0
ans = r
for i in range(n):
if S[i] == "W":
w += 1
elif S[i] == "R":
r -= 1
ans = min(ans,max(r,w))
print(ans) | from sys import stdin
rs = stdin.readline
ri = lambda : int(rs())
ril = lambda : list(map(int, rs().split()))
def main():
N = ri()
c = rs()
x = 0
y = c.count('R')
for e in c:
if x == y:
break
elif e == 'W':
x += 1
else:
y -= 1
print(... | 1 | 6,330,590,801,360 | null | 98 | 98 |
H, N = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(N)]
dp = [10 ** 18] * (H + 1)
dp[0] = 0
for i in range(H + 1):
for A, B in AB:
if i + A >= H:
dp[H] = min(dp[H], dp[i] + B)
else:
dp[i + A] = min(dp[i + A], dp[i] + B)
res = dp[H]
prin... | # This code is generated by [Atcoder_base64](https://github.com/kyomukyomupurin/AtCoder_base64)
import base64
import subprocess
import zlib
exe_bin = "c%1E9e{@q-p1&_iX@NEgTA-*55euhXAQC9p3e|+B@ZzS>fiQyzKGGy@Gqy=hUZ6PaSWl?(wi9Gr*X4}Pk>l>!(b;occh2tmW1O|6NR>HzmNI8XX4DnkQBzUD6|w%H+3)whd(-z`6ZAOyr<X&%_xpL@@ArQ1_ulut@7;HMce... | 0 | null | 41,819,699,109,830 | 229 | 74 |
import functools
from math import gcd
N = int(input())
A = list(map(int, input().split()))
MAX = 10 ** 6 + 10
if functools.reduce(gcd, A) != 1:
print("not coprime")
exit()
prime_list = [i for i in range(MAX + 1)]
p = 2
while p * p <= MAX:
if prime_list[p] == p:
for q in range(2*p, MAX+1, p):
... | def li():
return [int(x) for x in input().split()]
N = int(input())
A = li()
import math
from functools import reduce
from collections import defaultdict
# 最大公約数(リスト引数)
# 空のリストを渡さないよう注意
def GCD_list(numbers):
return reduce(math.gcd, numbers)
# 数列全ての高速素因数分解
MAX = 10 ** 6
is_prime = [True] * (MAX + 1)
divs ... | 1 | 4,062,542,321,892 | null | 85 | 85 |
import sys
sys.setrecursionlimit(9**9)
n=int(input())
T=[[] for _ in range(n)]
for i in range(n-1):
a,b=map(int,input().split())
T[a-1].append([b-1,i])
C=[0]*(n-1)
def f(i,r):
c=1
for (x,y) in T[i]:
c+=(c==r)
C[y]=c
f(x,c)
c+=1
f(0,0)
print(max(C))
for c in C:
print(c... | N = int(input())
graph = [[] for _ in range(N+1)]
AB = []
for _ in range(N-1):
a, b = map(int, input().split())
graph[a].append(b)
graph[b].append(a)
AB.append((a, b))
root = 1
parent = [0] * (N+1)
order = []
stack = [root]
while stack:
x = stack.pop()
order.append(x)
for y in graph[x]:
i... | 1 | 135,754,738,006,768 | null | 272 | 272 |
K = input(str())
a = 'ACL'
if K == '1':
print(a)
if K == '2':
print(a * 2)
if K == '3':
print(a * 3)
if K == '4':
print(a * 4)
if K == '5':
print(a * 5)
| Lists = [1, 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]
x = int(input())
print(Lists[x]) | 0 | null | 25,965,510,380,180 | 69 | 195 |
n = int(input().rstrip())
ans = [0 for x in range(10000)]
for x in range(1,101):
for y in range(1,101):
for z in range(1,101):
f = ((x+y)**2 + (y+z)**2 + (z+x)**2)//2
if f <= 10000:
ans[f-1] += 1
for i in range(n):
print(ans[i]) | N,K=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
mod=10**9+7
ans=1
if K%2==1 and A[-1]<0:
for i in range(K):
ans=ans*A[N-(i+1)]%mod
print(ans)
exit()
l=0
r=N-1
if K%2==1:
ans=ans*A[r]
r-=1
for _ in range(K//2):
ml=A[l]*A[l+1]
mr=A[r]*A[r-1]
if ml>mr:
... | 0 | null | 8,751,860,571,312 | 106 | 112 |
s = list(input())
t = list(input())
leng = len(s)
if s[0:leng] == t[0:leng]:
print("Yes")
else:
print("No") | li = []
for i, s in enumerate(input()):
if s == "\\":
li.append([i, 0])
elif s == "/":
if li:
if li[-1][1] == 0:
li[-1][1] = i - li[-1][0]
else:
for j in range(len(li) - 1, -1, -1):
if li[j][1] == 0:
... | 0 | null | 10,826,123,847,098 | 147 | 21 |
n = int(input())
lis = input().split()
dic = {}
for i in range(n):
if lis[i] not in dic:
dic[lis[i]] = 1
else:
dic[lis[i]] += 1
for x in dic.values():
if x != 1:
print("NO")
exit()
print("YES") | N = input()
A = list(int(x) for x in input().split())
if len(set(A)) == len(A):
print('YES')
else:
print('NO')
| 1 | 73,913,035,333,842 | null | 222 | 222 |
from math import *
PI = 3.1415926535898
while True:
try:
a, b = map(float, raw_input().strip().split(' '))
print "%d %d" % (a*b, 2*(a+b))
except EOFError:
break | N,M,K = list(map(int, input().split()))
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]... | 0 | null | 30,884,362,373,370 | 36 | 209 |
N, M = map(int, input().split())
print('Yes') if N == M else print('No') | A, B = map(int, input().split())
if A == B:
print('Yes')
else:
print('No') | 1 | 83,289,614,288,352 | null | 231 | 231 |
import sys
input = lambda: sys.stdin.readline().rstrip()
def main():
s = input()
days = ['','SAT','FRI','THU','WED','TUE','MON','SUN']
print(days.index(s))
if __name__ == '__main__':
main() | s = input()
day = ['SAT','FRI','THU','WED','TUE','MON','SUN']
for i in range(7):
if s == day[i]:
print(i + 1)
exit() | 1 | 133,372,783,197,328 | null | 270 | 270 |
n,k = map(int,input().split())
A = [int(i) for i in input().split()]
A.sort()
F = [int(i) for i in input().split()]
F.sort(reverse=True)
left = -1
right = 10**12
def f(x): return sum(max(A[i]-x//F[i],0) for i in range(n)) <= k
while right - left > 1:
mid = (left+right)//2
if f(mid): right = mid
else: ... | import sys,math
input = sys.stdin.readline
n,k = map(int,input().split())
a = [int(i) for i in input().split()]
f = [int(i) for i in input().split()]
a.sort()
f.sort(reverse=True)
c = [(i*j,j) for i,j in zip(a,f)]
m = max(c)
def is_ok(arg):
# 条件を満たすかどうか?問題ごとに定義
chk = 0
for i,j in c:
chk += math.ceil... | 1 | 164,910,108,257,650 | null | 290 | 290 |
def to_fizzbuzz(num: int) -> str:
if num % 15 == 0:
return 'FizzBuzz'
if num % 3 == 0:
return 'Fizz'
if num % 5 == 0:
return 'Buzz'
return str(num)
N = int(input())
answer = 0
for i in range(1, N + 1):
fb_str = to_fizzbuzz(i)
if fb_str.isdecimal():
answer += int... | N = int(input())
A = 0
for i in range(1, N+1):
if i%3 > 0 and i%5 > 0:
A += i
print(A) | 1 | 34,973,997,371,208 | null | 173 | 173 |
k= int(input())
s= input()
if len(s)>k:
r=s[:k]+"..."
print(r)
else:
print(s) | k = int(input())
s = input()
if len(s)>k:
print(s[0:k]+'...')
else:
print(s) | 1 | 19,749,528,829,660 | null | 143 | 143 |
n=int(input())
a=list(map(int,input().split()))
m=max(a)
b=[0]
b*=m
for i in range(n):
b[a[i]-1]+=1
c=[]
for i in range(m):
if b[i]>=2:
c.append(int(b[i]*(b[i]-1)/2))
else:
c.append(0)
d=sum(c)
for i in range(n):
if c[a[i]-1]>=1:
e=c[a[i]-1]-int((b[a[i]-1]-1)*(b[a[i]-1]-2)/2)
... | n=int(input())
arr=list(map(int,input().split()))
tt=[0]*(n+7)
total=0
for a in arr:
tt[a]+=1
for t in tt:
total += (t*(t-1)//2)
for i in range(n):
n = tt[arr[i]]
d = (n*(n-1)//2) - ((n-1)*(n-2)//2)
print(total-d)
# x * x-1 // 2
| 1 | 47,962,670,380,950 | null | 192 | 192 |
k=int(input())
v='ACL'
print(k*v) | k=int(input())
print("ACL"*k)
| 1 | 2,168,957,804,420 | null | 69 | 69 |
# -*- coding: utf-8
s = list(map(str,input().split()))
sum = 0
for i in range(len(s)):
sum += (int) (s[i])
if sum %9 == 0:
print("Yes")
else:
print("No") | import sys
input = lambda: sys.stdin.readline().rstrip()
class SegTree:
def __init__(self, init_val, segfunc, ide_ele):
n = len(init_val)
self.ide_ele = ide_ele
self.segfunc = segfunc
self.num = 2**(n - 1).bit_length()
self.seg = [self.ide_ele] * 2 * self.num
fo... | 0 | null | 33,299,511,595,740 | 87 | 210 |
k = int(input())
hp = [i for i in range(k+4)]
r, w = 1, 10
while w <= k:
n = hp[r]
r += 1
nm = n % 10
val = n * 10 + nm
if nm != 0:
hp[w] = val - 1
w += 1
hp[w] = val
w += 1
if nm != 9:
hp[w] = val + 1
w += 1
print(hp[k]) | def main():
N, M = map(int, input().split())
digits = [-1] * N
for _ in range(M):
s, c = map(int, input().split())
s -= 1
if ~digits[s] and digits[s] != c:
print(-1)
return
digits[s] = c
if N == 1:
print(max(0, digits[0]))
return
... | 0 | null | 50,107,602,939,114 | 181 | 208 |
nk=list(map(int, input().split()))
a=list(map(int, input().split()))
n=nk[0]
k=nk[1]
for i in range(n-k):
if(a[i]<a[i+k]):
print("Yes")
else:
print("No") | # cook your dish here
n,k=input().split()
n=int(n)
k=int(k)
l=list(map(int,input().split()))
for j in range(n):
if k+j==n:
break
if l[k+j]>l[j]:
print("Yes")
else:
print("No")
| 1 | 7,191,985,719,802 | null | 102 | 102 |
import math
import sys
x=input()
x0=x.split()
a=int(x0[0])
b=int(x0[1])
n=int(x0[2])
b0=n%b
b1=0
q1=0
if b==1:
print(0)
sys.exit()
for i in range(1,math.floor(n/b)+1):
b1=b*i-1
q1=max(q1,math.floor(a*b1/b)-a*math.floor(b1/b))
q2=math.floor(a*b0/b)-a*math.floor(b0/b)
print(max(q1,q2)) | n,k = map(int,input().split())
w = []
for _ in range(n):
w.append(int(input()))
def enough(p,k,w):
count = 0
in_truck = 0
for x in w:
if x > p:
return False
else:
if in_truck + x > p:
count += 1
in_truck = x
else:
... | 0 | null | 14,155,183,940,260 | 161 | 24 |
n = int(input())
c = list(input())
r = c.count('R')
w = c.count('W')
ans = 0
for i in range(r):
if c[i] == 'R':
pass
elif c[i] == 'W':
ans += 1
print(ans) | n = int(input())
stones = input()
r = stones.count("R")
w = stones.count("W")
ans = stones[0:r].count("W")
print(ans) | 1 | 6,326,570,616,410 | null | 98 | 98 |
import math
r = input()
S = math.pi * r ** 2
L = math.pi * r * 2
print "%f %f" %(S, L) | class UFTree:
def __init__(self, N):
self.nodes = [Node(i) for i in range(N)]
self.N = N
def find_max_child_num(self):
result = 0
for i in range(self.N):
result = max(result, self.nodes[i].child_num)
return result
class Node:
def __init__(self, ID):
... | 0 | null | 2,334,986,400,064 | 46 | 84 |
line = ""
while line != "0":
line = input()
x = 0
for i in range(len(line)):
x += int(line[i])
if x != 0:
print(x)
| N = list(input().split())
A = int(N[0])
b1,b2 = N[1].split('.')
B = int(b1+b2)
prd = list(str(A*B))
ans = 0
if len(prd) < 3:
ans = 0
else:
prd.pop()
prd.pop()
ans = int(''.join(prd))
print(ans)
| 0 | null | 9,035,340,307,728 | 62 | 135 |
import math
r = input()
print ("%.5f " "%.5f")% (r*r*math.pi, 2*r*math.pi) | s =input()
t =input()
for i in range(len(s)):
if s[i] != t[i]:
print('No')
exit()
if len(t) == len(s)+1:
print('Yes')
else:
print('No') | 0 | null | 11,102,012,651,744 | 46 | 147 |
from collections import deque
n = int(input())
rg = [[] for _ in range(n)]
ret_dict = dict()
ls = []
for _ in range(n-1):
a, b = map(int, input().split())
rg[a-1].append(b-1)
rg[b-1].append(a-1)
ls.append((a-1, b-1))
deq = deque()
deq.append((0, 0))
visited = set()
visited.add(0)
ret = 0
while de... | from collections import deque
N = int(input())
X = [list(map(int, input().split())) for _ in range(N - 1)]
tree = [[] for _ in range(N + 1)]
for i, (a, b) in enumerate(X):
tree[a].append((b, i))
tree[b].append((a, i))
visited = [False] * (N + 1)
visited[1] = True
color = [0] * (N - 1)
stack = deque()
stack.a... | 1 | 136,484,976,639,770 | null | 272 | 272 |
N = int(input())
As = list(map(int, input().split()))
P = 10**9 + 7
rlt = 0
pw = 1
for i in range(61):
c0 = 0
c1 = 0
for j in range(N):
a = As[j]
if a % 2 == 0:
c0 += 1
else:
c1 += 1
As[j] = a//2
rlt += c0*c1*pw % P
rlt %= P
pw *= 2
print(rlt) | class UnionFindTree():
def __init__(self, n):
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
... | 0 | null | 63,395,468,784,362 | 263 | 84 |
a = int(input())
s = 100000
for i in range(a):
s = s * 1.05
if s % 1000:
s = s - (s % 1000) + 1000
print(int(s))
| import sys
def compoundInterest(x, i, n):
if n == 0:
return x
ans = int(x * (1 + i))
hasu = ans % 1000
if hasu != 0:
ans -= hasu
ans += 1000
return compoundInterest(ans, i, n-1)
if __name__ == "__main__":
n = int(input())
ans = compoundInterest(100000, 0.05, n)
... | 1 | 1,141,417,090 | null | 6 | 6 |
#!/usr/bin/env python3
import sys
import collections as cl
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():
N = II()
print((N/3)**3)
main()
| import sys
sys.setrecursionlimit(4100000)
import math
INF = 10**9
def main():
l = int(input())
print((l/3)**3)
if __name__ == '__main__':
main()
| 1 | 47,122,213,810,272 | null | 191 | 191 |
N, K = map(int, input().split())
A = [int(x) for x in input().split()]
K = min(K, 41)
# imos
for _ in range(K):
B = [0 for _ in range(N)]
for i in range(N):
l = max(0, i-A[i])
r = min(N-1, i+A[i])
B[l] += 1
if r+1 < N:
B[r+1] -= 1
for i in range(1, N):
B... | n,k=map(int,input().split())
a=list(map(int,input().split()))
for _ in range(min(k,41)):
b=[0]*(n+1)
for i in range(n):
l=max(0,i-a[i])
r=min(n,i+a[i]+1)
b[l]+=1
b[r]-=1
for i in range(n-1):
b[i+1]+=b[i]
a=b[:n]
print(*a) | 1 | 15,575,495,652,710 | null | 132 | 132 |
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right
sys.setrecursionlimit(10**7)
def input():
return sys.stdin.readline()[:-1]
mod = 10**9 + 7
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
if row <= 0:
... | N, X, M = map(int, input().split())
tmp = X
seq = []
ans = 0
for i in range(N):
if X in seq:
break
seq.append(X)
X = (X ** 2) % M
ans = sum(seq[:min(N, len(seq))])
N -= len(seq)
if N < 1:
print(ans)
exit()
i = seq.index(X)
l = len(seq) - i
ans += sum(seq[i:]) * (N//l)
N %= l
ans += sum(seq[i:i+N])
pr... | 1 | 2,792,582,503,370 | null | 75 | 75 |
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=map(int,input().split())
ans=list()
for i in range(K):
D=int(input())
L=list(map(int,input().split()))
ans+=L
ans=list(set(ans))
print(N-len(ans)) | 0 | null | 44,245,980,159,492 | 212 | 154 |
N = int(input())
import math
o = math.ceil(N / 2)
print(o / N)
| def main():
N,P = map(int,input().split())
S = input()[::-1]
ans = 0
if P == 2 or P == 5:
for i,s in enumerate(S):
if int(s) % P == 0:
ans += N - i
else:
mods = [0] * P
mods[0] = 1
current = 0
x = 1
for s in S:
c... | 0 | null | 117,687,609,844,518 | 297 | 205 |
n=int(input())
from math import gcd
m=gcd(360,n)
print(360//m) | def main():
import sys
from collections import Counter
input = sys.stdin.readline
input()
a = list(map(int, input().split()))
ans = sum(a)
a = Counter(a)
for _ in range(int(input())):
b, c = map(int, input().split())
if b in a:
ans += (c - b) * a[b]
... | 0 | null | 12,705,102,321,248 | 125 | 122 |
nk=list(map(int, input().split()))
a=list(map(int, input().split()))
n=nk[0]
k=nk[1]
for i in range(n-k):
if(a[i]<a[i+k]):
print("Yes")
else:
print("No") | n=int(input())
if n%10==7:
print("Yes")
exit()
n//=10
if n%10==7:
print("Yes")
exit()
n//=10
if n%10==7:
print("Yes")
exit()
print("No") | 0 | null | 20,879,217,710,550 | 102 | 172 |
import math
H = int(input())
W = int(input())
N = int(input())
Max = max(H,W)
print(math.ceil(N/Max)) | import math
A = int(input())
B = int(input())
N = int(input())
if A> B:
print(math.ceil(N/A))
else:
print(math.ceil(N/B)) | 1 | 88,644,808,828,758 | null | 236 | 236 |
H,W = map(int,input().split())
if H == 1 or W == 1:
print(1)
a = H * W
b = a // 2
if b != a / 2:
b += 1
if H != 1 and W != 1:
print(b)
| from itertools import accumulate
N, K = list(map(int, input().split()))
P = list(map(lambda x: int(x) + 1, input().split()))
P_cumsum = [0] + list(accumulate(P))
print(max([P_cumsum[i+K]-P_cumsum[i] for i in range(N-K+1)])/2) | 0 | null | 62,582,181,863,872 | 196 | 223 |
d=int(input())
c=list(map(int,input().split()))
s=[]
for _ in range(d):
s_i=list(map(int,input().split()))
s.append(s_i)
t=[]
for _ in range(d):
t_i=int(input())
t.append(t_i)
dp=[0]*26
ans=0
for i in range(d):
s_i = s[i][t[i]-1]
ans+=s_i
dp[t[i]-1]=i+1
tmp=0
for j in range(26):
... | D = int(input())
c = list(map(int, input().split()))
s = []
for i in range(D):
s.append(list(map(int, input().split())))
t = []
for i in range(D):
t.append(int(input())-1)
v = 0
last = [-1 for _ in range(26)]
for d in range(D):
v += s[d][t[d]]
last[t[d]]=d
for i in range(26):
v -= c[i] * (d... | 1 | 10,050,523,585,374 | null | 114 | 114 |
cnt = 0
def merge(A, left, mid, right):
global cnt
L = A[left:mid]
R = A[mid:right]
L.append(10000000000)
R.append(10000000000)
i = 0
j = 0
for k in range(left, right):
if L[i] <= R[j]:
A[k] = L[i]
i += 1
else:
A[k] = R[j]
... | def merge(A, left, mid, right):
global cnt
L = A[left:mid] + [1000000001]
R = A[mid:right] + [1000000001]
i = j = 0
for k in range(left, right):
if L[i] <= R[j]:
A[k] = L[i]
i += 1
else:
A[k] = R[j]
j += 1
cnt += right - left
def mergeSort(A, left, right):
if left + 1 < right:
mid = (left + ... | 1 | 112,631,915,402 | null | 26 | 26 |
def resolve():
n,k = map(int,input().split())
ans = 0
while n!=0:
n = n//k
ans += 1
print(ans)
resolve() | N = int(input())
A = []
B = []
for _ in range(N):
a, b = map(int, input().split())
A.append(a)
B.append(b)
def median(arr):
arr.sort()
n = len(arr)
if n % 2 == 1:
return arr[(n + 1) // 2 - 1]
else:
return (arr[n//2 - 1] + arr[n//2]) / 2
med_a = median(A)
med_b = median(B)
i... | 0 | null | 40,849,645,127,470 | 212 | 137 |
while True:
h, w = map(int, input().split())
if h == 0 and w == 0:
break
for y in range(h):
isOddLine = True
if y % 2 == 0:
isOddLine = False
else:
isOddLine = True
for x in range(w):
if isOddLine:
if x % 2 == 0:
... | import math
a,b,x = map(int,input().split())
if x <= a*a*b//2:
theta = (math.pi/2) - math.atan((2*x)/(a*b*b))
else:
theta = math.atan(2*(a*a*b-x)/(a*a*a))
degree = math.degrees(theta)
print(degree) | 0 | null | 82,236,993,902,392 | 51 | 289 |
#!/usr/bin python3
# -*- coding: utf-8 -*-
def main():
N = int(input())
A = list(map(int, input().split()))
cnt = 0
for i, a in enumerate(A):
if (i+1)%2==1 and a%2==1:
cnt += 1
print(cnt)
if __name__ == '__main__':
main() | D = int(input())
C = list(map(int, input().split()))
S = [list(map(int, input().split())) for _ in range(D)]
import copy
MAX_SCORE = -float('inf')
MAX_ANS = -1
for K in range(26):
v = 0
ans = [0]*D
L = [0]*26
for i in range(1, D+1):
max_score = -float('inf')
max_idx = 0
for j in... | 0 | null | 8,733,886,785,638 | 105 | 113 |
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from s... | N = int(input())
s = "a"
ans = []
def dfs(s,n):
if len(s) == n:
ans.append(s)
return
last = 0
for i in range(len(s)):
last = max(last,ord(s[i]))
limit = chr(last+1)
for i in range(26):
temp = chr(97+i)
if temp <= limit:
dfs(s+temp,n)
dfs(s,N)
print(*ans,sep="\n") | 0 | null | 28,890,969,733,202 | 94 | 198 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.