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
|
---|---|---|---|---|---|---|
# -*- coding: utf-8 -*-
import sys
import os
def gcd(a, b):
# big - small
while a != b:
if a > b:
a, b = b, a
a, b = b - a, a
return a
def lcm(a, b):
return a * b // gcd(a, b)
lst = sys.stdin.readlines()
for s in lst:
a, b = map(int, s.split())
G = gcd(a, b)
L = lcm(a, b)
print(G, L) | def gcd(a,b):
if a%b==0:
return b
return gcd(b,a%b)
while True:
try:
a,b=sorted(map(int,input().split()))
except:
break
print(gcd(a,b),a//gcd(a,b)*b) | 1 | 706,307,832 | null | 5 | 5 |
def fn(x):
return [x[0], int(x[1])]
N, q = map(int, input().split())
name_time = list(map(fn, [ input().split() for n in range(N) ]))
sec = 0; finish =[];
while True:
if len(name_time) == 0:
break
elif name_time[0][1] > q:
sec += q
name_time[0][1] -= q
name_time.append(name_time.pop(0))
else:
sec += name_time[0][1]
finish.append([name_time.pop(0)[0],sec])
for f in finish:
print(*f)
| X,Y,Z=map(int,input().split())
print(str(Z)+' '+str(X)+' '+str(Y)) | 0 | null | 19,172,738,605,312 | 19 | 178 |
S=list(str(input()))
ans=0
sofar=0
j=1
nax=0
for i in range(len(S)-1):
if S[i]==S[i+1]:
ans+=j
j+=1
elif S[i]=='<' and S[i+1]=='>':
ans+=j
nax=j
j=1
else:
ans+=j
if nax!=0:
ans-=j
j=1
nax=0
if j>nax:
ans-=nax
nax=0
if j>nax:
ans+=j
ans-=nax
print(ans) | class Dice :
def __init__(self,num):
self.num = num
def move_E(self):
self.copy = self.num.copy()
for i,j in zip([0,2,5,3],[3,0,2,5]):
self.num[i] = self.copy[j]
def move_W(self):
self.copy = self.num.copy()
for i,j in zip([0,3,5,2],[2,0,3,5]):
self.num[i] = self.copy[j]
def move_N(self):
self.copy = self.num.copy()
for i,j in zip([0,1,5,4],[1,5,4,0]):
self.num[i] = self.copy[j]
def move_S(self):
self.copy = self.num.copy()
for i,j in zip([0,1,5,4],[4,0,1,5]):
self.num[i] = self.copy[j]
number = list(map(int,input().split()))
#number = [1,2,4,8,16,32]
#print("1 2 3 4 5 6")
# ?????????????????????
dice = Dice(number)
for order in input():
if order == 'S':
dice.move_S()
elif order == 'N':
dice.move_N()
elif order == 'W':
dice.move_W()
else:
dice.move_E()
# ?????????????????¶????????????
#print(dice.num)
print(dice.num[0]) | 0 | null | 78,312,832,945,020 | 285 | 33 |
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
S = readline().decode().rstrip()
if S[2] == S[3] and S[4] == S[5]:
print('Yes')
else:
print('No') | def aizu004():
xs = map(int,raw_input().split())
W = xs[0]
H = xs[1]
x = xs[2]
y = xs[3]
r = xs[4]
if (r <= x <= W-r) and (r <= y <= H-r):
print "Yes"
else:
print "No"
aizu004() | 0 | null | 21,248,114,060,178 | 184 | 41 |
n = int( input() )
A = []
B = []
for i in range(n):
a, b = map( int, input().split() )
A.append( a )
B.append( b )
A = sorted( A )
B = sorted( B )
ret = 0
if n % 2 == 0:
i = n // 2 - 1
ret = B[ i + 1 ] + B[ i ] - ( A[ i + 1 ] + A[ i ] ) + 1
else:
i = ( n + 1 ) // 2 - 1
ret = B[ i ] - A[ i ] + 1
print( ret ) | import sys
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
from collections import deque
from bisect import bisect_left
from itertools import product
def I(): 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 LI2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
#文字列を一文字ずつ数字に変換、'5678'を[5,6,7,8]とできる
def LSI(): return list(map(int, list(sys.stdin.readline().rstrip())))
def LSI2(N): return [list(map(int, list(sys.stdin.readline().rstrip()))) for i in range(N)]
#文字列として取得
def ST(): return sys.stdin.readline().rstrip()
def LST(): return sys.stdin.readline().rstrip().split()
def LST2(N): return [sys.stdin.readline().rstrip().split() for i in range(N)]
def FILL(i,h): return [i for j in range(h)]
def FILL2(i,h,w): return [FILL(i,w) for j in range(h)]
def FILL3(i,h,w,d): return [FILL2(i,w,d) for j in range(h)]
def FILL4(i,h,w,d,d2): return [FILL3(i,w,d,d2) for j in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)
#'0.01'や'1E1'などで指定、整数に戻すならintをかます
MOD = 1000000007
INF = float("inf")
sys.setrecursionlimit(10**6+10)
N = I()
L = LI2(N)
A = [i[0] for i in L]
B = [i[1] for i in L]
A.sort()
B.sort()
if N%2==0:
medA = (A[N//2-1]+A[N//2])
medB = (B[N//2-1]+B[N//2])
print((medB-medA)+1)
else:
medA = A[(N-1)//2]
medB = B[(N-1)//2]
print(medB-medA+1)
| 1 | 17,245,716,158,788 | null | 137 | 137 |
n = int(input())
ans = ""
for i in range(11):
n2 = (n-1)%26
ans = chr(97+n2)+ans
n = int((n-1)/26)
#print(n)
if n == 0:
break
print(ans)
| n = int(input())
abc = 'abcdefghijklmnopqrstuvwxyz'
ans = ''
while n != 0:
n -= 1
ans += abc[n%26]
n //= 26
print(ans[::-1]) | 1 | 11,946,216,768,192 | null | 121 | 121 |
while True:
n, x = map(int, input().split())
if n == x == 0:
break
count = 0
for i in range(1,n+1):
for j in range(1,n+1):
for k in range(1,n+1):
if (i < j < k):
if i+j+k == x:
count += 1
print(count) | ret = []
while True:
n, x = map(int, raw_input().split())
num_arr = [i for i in range(1, n+1)]
if (n, x) == (0, 0):
break
cnt = 0
for i in range(n, 0, -1):
for j in range(i -1, 0, -1):
if 0 < x - i - j < j:
cnt += 1
ret += [cnt]
for i in ret:
print i | 1 | 1,277,688,800,050 | null | 58 | 58 |
import sys
input = sys.stdin.readline
from collections import deque
def main():
n = int(input().strip())
v = [[] for _ in range(n)]
for i in range(n):
v[i] = list(map(int, input().strip().split()))
l = [-1] * (n+1)
q = deque()
q.append((1, 0))
while len(q) != 0:
id, d = q.popleft()
# print("id", id)
if l[id] != -1:
# print("b")
continue
l[id] = d
# l[id] = min(d, l[id])
# print(id, d)
for i in range(v[id-1][1]):
q.append((v[id-1][2+i], d+1))
# if id == 8:
# print("##", id, v[id-1][2+i])
# print(repr(q))
for i in range(1, n+1):
print(i, l[i])
if __name__ == '__main__':
main()
| from collections import deque
n = int(input())
G = [[] for _ in range(n)]
for i in range(n):
u, k, *vs = map(int, input().split())
u -= 1
vs = list(map(lambda x: x - 1, vs))
for v in vs:
G[u].append(v)
dist = [-1] * n
dist[0] = 0
que = deque([0])
while len(que) > 0:
now_v = que.popleft()
now_dist = dist[now_v]
next_vs = G[now_v]
for next_v in next_vs:
if dist[next_v] == -1:
dist[next_v] = now_dist + 1
que.append(next_v)
for i, x in enumerate(dist):
print(i + 1, x)
| 1 | 4,180,592,720 | null | 9 | 9 |
import sys
input = sys.stdin.readline
def main():
S, T = input().split()
A, B = map(int, input().split())
U = input().strip()
print(A-1, B) if S == U else print(A, B-1)
if __name__ == '__main__':
main()
| s,t=list(input().split())
a,b=list(map(int,input().split()))
u=input()
if u==s:
print(str(a-1)+" "+str(b))
else:
print(str(a)+" "+str(b-1)) | 1 | 72,135,821,511,040 | null | 220 | 220 |
"""
タグ:区間
"""
import sys
input = sys.stdin.readline
N, P = map(int, input().split())
S = input().strip()
if P == 5:
res = 0
i = 0
for s in reversed(S):
if int(s)%5==0:
res += N-i
i += 1
print(res)
elif P == 2:
res = 0
i = 0
for s in reversed(S):
if int(s)%2==0:
res += N-i
i += 1
print(res)
else:
T = [0]
p = 1
for s in reversed(S):
T.append(int(s)*p + T[-1])
p = p*10%P
cnt = [0]*P
for i in range(N+1):
cnt[T[i]%P] += 1
res = 0
for c in cnt:
res += c*(c-1)//2
print(res) | import sys
# import bisect
# from collections import Counter, deque, defaultdict
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter
# import math
# from numba import jit
# from scipy import
# import numpy as np
# import networkx as nx
# import matplotlib.pyplot as plt
readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)
def main():
n, p = list(map(int, readline().split()))
s = input()
ans = 0
if p == 2 or p == 5:
for i in range(n):
if int(s[i]) % p == 0:
ans += (i + 1)
else:
c = [0] * p
prev = 0
c[0] = 1
for i in range(n):
num = int(s[n - i - 1])
m = (num * pow(10, i, p) + prev) % p
c[m] += 1
prev = m
for i in range(p):
cnt = c[i]
ans += cnt * (cnt - 1) // 2
print(ans)
if __name__ == '__main__':
main()
| 1 | 58,004,746,879,720 | null | 205 | 205 |
N = int(input())
A,B = [], []
for i in range(N):
a,b = map(int, input().split())
A.append(a)
B.append(b)
A.sort()
B.sort()
cnt = 0
if(N % 2 == 1):
l = A[N//2]
r = B[N//2]
cnt = r - l + 1
else:
l = A[N//2-1] + A[N//2]
r = B[N//2-1] + B[N//2]
cnt = r - l + 1
print(cnt)
| N=int(input())
A,B=[],[]
for i in range(N):
a,b=map(int,input().split())
A.append(a)
B.append(b)
A.sort()
B.sort()
I=~-N//2
print(B[I]-A[I]+1 + (B[I+1]-A[I+1] if N%2==0 else 0))
| 1 | 17,299,752,369,270 | null | 137 | 137 |
k = int(input())
a, b = map(int, input().split())
if a <= k <= b or k <= b/2:
print('OK')
else:
print('NG')
| def main():
N, P = map(int, input().split())
S = input()
if P == 2 or P == 5:
ans = 0
for i in range(N):
if int(S[i]) % P == 0:
ans += (i + 1)
print(ans)
exit()
sum_rem = [0] * N
sum_rem[0] = int(S[N - 1]) % P
ten = 10
for i in range(1, N):
a = (int(S[N - 1 - i]) * ten) % P
sum_rem[i] = (a + sum_rem[i - 1]) % P
ten = (ten * 10) % P
ans = 0
count = [0] * P
count[0] = 1
for i in range(N):
ans += count[sum_rem[i]]
count[sum_rem[i]] += 1
print(ans)
if __name__ == '__main__':
main()
| 0 | null | 42,212,121,158,548 | 158 | 205 |
from functools import reduce
N = int(input())
A_list = list(map(int, input().split()))
sums = [A_list[0]]
for i in range(1, N):
sums.append(sums[i-1] + A_list[i])
result = 0
for i in range(1, N):
result += sums[i-1] * A_list[i]
result %= 10**9 + 7
print(result)
| from math import ceil
A, B, C, D = map(int, input().split())
E = ceil(C/B)
F = ceil(A/D)
print('Yes' if E <= F else 'No')
| 0 | null | 16,735,903,578,240 | 83 | 164 |
h,n=map(int,input().split())
a=[int(x) for x in input().split()]
if sum(a) >= h:
print("Yes")
else:
print("No") | h, hoge = list(map(int, input().split(' ')))
l = list(map(int, input().split(' ')))
print('Yes' if h <= sum(l) else 'No')
| 1 | 78,206,525,216,160 | null | 226 | 226 |
N = int(input())
A = list(map(int, input().split()))
L = 1000000007
state = [0,0,0]
M = [0,0,0]
for a in A:
t = None
n = 0
for i,s in enumerate(state):
if s == a:
t = i
n += 1
if n == 0:
break
M[n-1] += 1
state[t] += 1
if n > 0:
x = 2**30 % L
y = 3**19 % L
k = M[1] % x
l = M[2] % y
r = 2**k * 3**l % L
print(r)
else:
print(0)
| import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
MOD = 10**9+7
def main():
N,*A = map(int, read().split())
cnt = [0] * N
ans = 1
for a in A:
if a == 0:
cnt[0] += 1
continue
ans *= cnt[a - 1] - cnt[a]
ans %= MOD
cnt[a] += 1
if cnt[0] == 1:
ans *= 3
elif cnt[0] <= 3:
ans *= 6
else:
ans = 0
ans %= MOD
print(ans)
if __name__ == "__main__":
main()
| 1 | 129,522,834,025,452 | null | 268 | 268 |
n=int(input())
s=100000
for i in range(n):
s=int(s*1.05)
if s % 1000>0:
s=s//1000*1000+1000
print(s)
| n=int(input())
s,t=map(str,input().split())
a=""
for i in range(2*n):
if i%2==0:
a=a+s[(i)//2]
else:
a=a+t[(i-1)//2]
print (a) | 0 | null | 56,011,091,847,620 | 6 | 255 |
arr = map(int,raw_input().split())
arr.sort()
arr = map(str,arr)
print ' '.join(arr) | a,b,c =map(int, input().split())
if a<b and b<c:
print(a,b,c)
elif a>b:
if b>=c:
a,c = c,a
print(a,b,c)
else:
a,b = b,a
b,c = c,b
print(a,b,c)
else:
if a>c:
a,b = b,a
a,c = c,a
print(a,b,c)
else:
b,c = c,b
print(a,b,c)
| 1 | 414,949,423,360 | null | 40 | 40 |
a = int(raw_input())
b, c = divmod(a, 3600)
d, e = divmod(c, 60)
print ("%d:%d:%d") % (b,d,e) | sec = int(input())
m, s = divmod(sec, 60)
h, m = divmod(m, 60)
print('%d:%d:%d' % (h, m, s)) | 1 | 325,196,896,768 | null | 37 | 37 |
x, y, z = map(int, input().split())
x, y = y, x
x, z = z, x
print(str(x) + ' ' + str(y) + ' ' + str(z))
| def main():
s, w = map(int, input().split())
if s <= w:
ans = 'unsafe'
else:
ans = 'safe'
print(ans)
if __name__ == "__main__":
main()
| 0 | null | 33,519,399,274,090 | 178 | 163 |
n = int(input())
a = [int(x) for x in input().split()]
s = 0
for i in a:
s ^= i
print(*[x ^ s for x in a]) | from bisect import bisect_left
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
def count(x):
ret = 0
for a in A:
ret += N - bisect_left(A, x - a)
return ret
overEq = 0
less = 10**7
while less - overEq > 1:
mid = (less + overEq) // 2
if count(mid) >= M:
overEq = mid
else:
less = mid
ans = 0
cnt = [0] * N
for a in A:
i = (N - bisect_left(A, overEq - a))
ans += i * a
if i > 0:
cnt[-i] += 1
for i in range(1, N):
cnt[i] += cnt[i - 1]
for a, c in zip(A, cnt):
ans += a * c
ans -= overEq * (count(overEq) - M)
print(ans)
| 0 | null | 60,553,499,352,544 | 123 | 252 |
from functools import reduce
N = int(input())
A = list(map(int, input().split()))
B = reduce(lambda x, y: x^y, A)
ans = []
for a in A:
ans.append(B^a)
print(*ans) | S=input()
S=list(reversed(S))
m=2019
cnt=[0 for i in range(m)]
len_S=len(S)
x=1
tot=0
ans=0
for i in range(len(S)):
cnt[tot]+=1
tot+=(ord(S[i])-ord('0'))*x
tot %= m
ans+=cnt[tot]
x=x*10%m
print(ans) | 0 | null | 21,728,653,238,668 | 123 | 166 |
#!/usr/bin/env python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]
def inside(y, x, H, W):
return 0 <= y < H and 0 <= x < W
def ceil(a, b):
return (a + b - 1) // b
def sum_of_arithmetic_progression(s, d, n):
return n * (2 * s + (n - 1) * d) // 2
def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b)
def lcm(a, b):
g = gcd(a, b)
return a / g * b
def solve():
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
tmp_time = 0
last_i = -1
for i in range(N):
if tmp_time + A[i] <= K:
tmp_time += A[i]
last_i = i
else:
break
last_j = -1
for j in range(M):
if tmp_time + B[j] <= K:
tmp_time += B[j]
last_j = j
else:
break
ans = last_i + last_j + 2
now = ans
while last_i >= 0:
tmp_time -= A[last_i]
now -= 1
last_i -= 1
while last_j + 1 < M and tmp_time + B[last_j + 1] <= K:
tmp_time += B[last_j + 1]
last_j += 1
now += 1
ans = max(ans, now)
print(ans)
def main():
solve()
if __name__ == '__main__':
main()
| def main():
x = int(input())
ans=int(x/500)*1000
x-=int(x/500)*500
ans+=int(x/5)*5
print(ans)
main() | 0 | null | 26,708,676,906,784 | 117 | 185 |
N, M, K = map(int, input().split())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
total = 0
Asum = sum(A)
nA = len(A)
Bsum = 0
ans = 0
for nB in range(len(B) + 1):
if nB != 0:
Bsum += B[nB-1]
if Bsum > K:
break
while Asum + Bsum > K:
nA -= 1
Asum -= A[nA]
ans = max(nA + nB, ans)
print(ans)
| def sep():
return map(int,input().strip().split(" "))
def lis():
return list(sep())
n,m,k=sep()
a=lis()
b=lis()
from bisect import bisect_right
a_c=[a[0]]
b_c=[b[0]]
for i in range(1,n):
a_c.append(a_c[-1]+ a[i])
for i in range(1,m):
b_c.append(b_c[-1] + b[i])
m=-1
m=max(m,bisect_right(b_c,k))
for i in range(n):
if a_c[i]<=k:
t=k-a_c[i]
t2=bisect_right(b_c,t)
m=max(i+1+t2,m)
else:
break
print(max(0,m))
| 1 | 10,693,087,575,884 | null | 117 | 117 |
n = int(input())
if n%2:
print(0)
else:
ans = 0
for i in range(1,100):
ans += (n//(5**i*2))
if n < 5**i:
break
print(ans) | n=int(input())
if n%2!=0:
print(0)
exit(0)
n//=10
def Base_10_to_n(X, n):
X_dumy = X
out = ''
while X_dumy>0:
out = str(X_dumy%n)+out
X_dumy = X_dumy//n
return out
n=Base_10_to_n(n,5)
n=reversed(list(n))
tmp=1
ans=0
for i in n:
ans+=int(i)*tmp
tmp=tmp*5+1
print(ans)
| 1 | 116,353,087,399,392 | null | 258 | 258 |
def linear_search(num_list,target):
for num in num_list:
if num == target:
return 1
return 0
n = input()
num_list = list(map(int,input().split()))
q = input()
target_list = list(map(int,input().split()))
ans = 0
for target in target_list:
ans += linear_search(num_list,target)
print(ans)
| n = int(input())
S = list(map(int, input().split()))
S = list(set(S))
q = int(input())
T = list(map(int, input().split()))
T = list(set(T))
C = 0
for i in range(len(S)):
if S[i] in T:
C += 1
print(C)
| 1 | 67,726,173,398 | null | 22 | 22 |
n = int(input())
s = input()
res = "No"
if n%2 == 0 and s[:n//2] *2 ==s:res ="Yes"
print(res) | if(int(input()) %2 == 1):
print("No")
exit()
t = input()
if(t[:len(t)//2] == t[len(t)//2:]):
print("Yes")
else:
print("No")
| 1 | 146,935,866,631,510 | null | 279 | 279 |
cnt = 0
a, b, c = map(int, input().split())
if (a >= 1 and a <= 10000) and (b >= 1 and b <= 10000) and (c >= 1 and c <= 10000):
if a <= b:
for i in range(a, b+1):
if c % i == 0:
cnt += 1
print("{0}".format(str(cnt)))
else:
pass
else:
pass | N=int(input())
b=0
x = N //100
for y in range(100*x,105*x+1):
if N==y:
print(1)
exit()
print(0)
| 0 | null | 63,897,188,721,902 | 44 | 266 |
import sys
input = sys.stdin.readline
def main():
N = int(input())
A = list(map(int, input().split()))
node_count = [0] * (N+1)
for i, a in enumerate(A[::-1]):
if i == 0:
node_count[N] = a
continue
node_count[N-i] = node_count[N-i+1] + a
can_build = True
for i, a in enumerate(A):
if i == 0:
if N > 0 and a > 0:
can_build = False
break
if N == 0 and a > 1:
can_build = False
break
node_count[0] = min(node_count[0], 1)
continue
if (i < N and a >= node_count[i-1]*2) or (i == N and a > node_count[i-1]*2):
can_build = False
break
node_count[i] = min(node_count[i], node_count[i-1]*2-A[i-1]*2)
if can_build:
ans = sum(node_count)
else:
ans = -1
print(ans)
if __name__ == "__main__":
main() | #
import sys
import math
import numpy as np
import itertools
n = int(input())
# n行の複数列ある数値をそれぞれの配列へ
a, b = [0]*n, [0]*n
for i in range(n): a[i], b[i] = map(int, input().split())
#print(a,b)
a.sort()
b.sort()
if n % 2 == 0:
t = a[n//2-1] + a[n//2]
s = b[n//2-1] + b[n//2]
print(s-t+1)
else:
t = a[n//2]
s = b[n//2]
print(s-t+1)
| 0 | null | 18,156,316,770,240 | 141 | 137 |
import sys
sys.setrecursionlimit(300000)
from math import sqrt, ceil
from collections import defaultdict
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI0(): return map(lambda s: int(s) - 1, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
def LMI0(): return list(map(lambda s: int(s) - 1, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')
N = I()
n = ceil(sqrt(N))
d = defaultdict(int)
for x in range(1, n + 1):
for y in range(1, n + 1):
for z in range(1, n + 1):
a = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x
if a <= N:
d[a] += 1
for i in range(1, N + 1):
print(d[i]) | num_limit = int(input())
num_list = [0] * num_limit
j_limit = int(num_limit ** 0.5)
for j in range(1,j_limit+1):
for k in range(1,j + 1):
for l in range(1,k+1):
if num_limit >= j**2 + k**2 + l**2 + j*k + k*l + l*j:
if j > k:
if k > l:
num_list[j**2 + k**2 + l**2 + j*k + k*l + l*j-1] += 6
else:
num_list[j**2 + k**2 + l**2 + j*k + k*l + l*j-1] += 3
elif k > l:
num_list[j**2 + k**2 + l**2 + j*k + k*l + l*j-1] += 3
else:
num_list[j**2 + k**2 + l**2 + j*k + k*l + l*j-1] += 1
for i in num_list:
print(i) | 1 | 7,957,078,895,458 | null | 106 | 106 |
first=0
second=0
third=0
for i in range(10):
mountain=int(input())
if mountain>first:
third=second
second=first
first=mountain
elif mountain>second:
third=second
second=mountain
elif mountain>third:
third=mountain
print(first)
print(second)
print(third) | hill = []
while True:
try:
hill.append(int(input()))
except:
break
for i in range(1, len(hill)):
key = hill[i]
j = i-1
while j >= 0 and hill[j] < key:
hill[j+1] = hill[j]
j -= 1
hill[j+1] = key
for i in range(3):
print(hill[i]) | 1 | 29,267,462 | null | 2 | 2 |
N, K = map(int, input().split())
S = []
for _ in range(K):
l, r = map(int, input().split())
S.append((l, r))
mod = 998244353
dp = [0] * (N+1)
cumsum_dp = [0] * (N+1)
dp[1] = 1
cumsum_dp[1] = 1
for i in range(2, N+1):
for s in S:
fr = max(0, i-s[1]-1)
to = max(0, i-s[0])
dp[i] += (cumsum_dp[to]-cumsum_dp[fr]) % mod
cumsum_dp[i] = (cumsum_dp[i-1] + dp[i]) % mod
print(dp[N]%mod) | mod = 998244353
n,k =map(int,input().split())
step =[0]*(n+1)
# step[0]=1
step[1]=1
stepsum=[0]*(n+1)
stepsum[1]=1
l=[0]*k
r=[0]*k
for i in range(k):
l[i],r[i]=map(int,input().split())
for i in range(2,n+1):
for j in range(k):
li = i - r[j]
ri = i - l[j]
if ri <= 0:
continue
# li = max(1,li)
step[i] += stepsum[ri] - stepsum[max(0,li-1)]
# step[i] %= mod
# print(step)
stepsum[i] = ( stepsum[i-1] + step[i] )%mod
print(step[n]%mod) | 1 | 2,682,045,560,920 | null | 74 | 74 |
import collections
n=int(input())
box=[]
for i in range(n):
tmp=str(input())
box.append(tmp)
l=len(collections.Counter(box))
print(l) | 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()))
seen = set()
t = ini()
for _ in range(t):
s = ins()
seen.add(s)
print(len(seen)) | 1 | 30,432,276,815,640 | null | 165 | 165 |
# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
return map(int, open(0).read().split())
n,*A = get_all_int()
# dp[i][j] = 活発度高い順のi人目まで処理し、左にjに置いた場合のうれしさの最大
dp = [ [0] * (n+1) for _ in range(n+1) ]
AA = list(enumerate(A))
AA.sort(key=(lambda t: t[1]), reverse=True)
for i, t in enumerate(AA):
# k 移動前の位置
# a 活発度
k,a = t
for j in range(i+1):
# 左に置く (すでに左端にj人居る)
move = abs(k - j)
dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j] + a*move)
# 右に置く (すでに右端にi-j人居る)
move = abs(k - (n-(i-j)-1))
dp[i+1][j] = max(dp[i+1][j], dp[i][j] + a*move)
ans = 0
for j in range(n+1):
ans = max(ans, dp[n][j])
print(ans)
| N = int(input())
A = list(map(int, input().split()))
A = sorted([(a, p) for p, a in enumerate(A)], reverse=True)
dp = [[0]*(i+1) for i in range(N+1)]
for z in range(N):
for y in range(z+1):
dp[z+1][y] = max(A[z][0]*(A[z][1]-(z-y))+dp[z][y],dp[z+1][y])
dp[z+1][y+1]= A[z][0]*((N-y-1)-A[z][1])+dp[z][y]
print(max(dp[-1])) | 1 | 33,556,506,037,308 | null | 171 | 171 |
r=input().split()
a=int(r[0])
b=int(r[1])
if a>=b:
ans=""
for i in range(a):
ans+=str(b)
print(int(ans))
else:
ans=""
for i in range(b):
ans+=str(a)
print(int(ans)) | a, b = map(int, input().split())
if a > b:
print(str(b) * a)
elif a < b:
print(str(a) * b)
else:
print(str(a) * a) | 1 | 84,513,845,749,540 | null | 232 | 232 |
a, b, c, d = map(int, input().split())
if a == b and c == d:
print(a*c)
else:
p1 = a*c
p2 = a*d
p3 = b*c
p4 = b*d
print(max(p1,p2,p3,p4)) | a = list(map(int, input().split()))
print(max((a[0] * a[2]),(a[0] * a[3]),(a[1] * a[3]),(a[1] * a[2]))) | 1 | 3,041,018,686,596 | null | 77 | 77 |
n = input()
S = set([int(s) for s in raw_input().split()])
m = input()
T = set([int(s) for s in raw_input().split()])
print len(T & S) | n = int(input())
a = input()
s=list(map(int,a.split()))
q = int(input())
a = input()
t=list(map(int,a.split()))
i = 0
for it in t:
if it in s:
i = i+1
print(i) | 1 | 70,457,417,228 | null | 22 | 22 |
n,m = map(int,input().split())
a = [int(s) for s in input().split()]
daycount = 0
for i in range(m):
daycount += a[i]
if n - daycount >= 0:
print(n - daycount)
else:
print(-1) | N, M = map(int, input().split())
A = list(map(int, input().split()))
print(max(-1, N-sum(A)))
| 1 | 32,017,826,176,260 | null | 168 | 168 |
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15
N = int(input())
ans = []
const = 2*3**0.5
def korch_curve(Lx,Ly,Rx,Ry,i):
if i == 0:
ans.append((Lx,Ly))
return
third_y = (Ly*2 + Ry)/3
third_x = (Lx*2 + Rx)/3
korch_curve(Lx,Ly,third_x,third_y,i - 1)
middle_x = (Lx + Rx)/2 - (Ry - Ly)/const
middle_y = (Ly + Ry)/2 + (Rx - Lx)/const
korch_curve(third_x,third_y,middle_x,middle_y,i - 1)
third_second_x = (Lx + Rx*2)/3
third_second_y = (Ly + Ry*2)/3
korch_curve(middle_x,middle_y,third_second_x,third_second_y,i - 1)
korch_curve(third_second_x,third_second_y,Rx,Ry,i - 1)
korch_curve(0,0,100,0,N)
ans.append((100,0))
for a in ans:
print(*a)
| n = int(input())
cnt = 0
flg = False
for i in range(n):
a,b = map(int,input().split())
if a == b:
cnt += 1
if cnt == 3:
flg = True
else:
cnt = 0
if flg:
print('Yes')
else:
print('No')
| 0 | null | 1,318,080,262,620 | 27 | 72 |
nums = [int(e) for e in input().split()]
if (nums[2]+nums[4])<=nums[0] and (nums[3]+nums[4])<=nums[1] and (nums[2]-nums[4])>=0 and (nums[3]-nums[4])>=0:
print("Yes")
else:
print("No")
| a=int(input())
ans=a+a**2+a**3
print(ans) | 0 | null | 5,323,098,086,808 | 41 | 115 |
import itertools
n=int(input())
ab = []
for _ in range(n):
a, b = (int(x) for x in input().split())
ab.append([a, b])
memo = []
for i in range(n):
memo.append(i)
ans = 0
count = 0
for v in itertools.permutations(memo, n):
count += 1
tmp_root = 0
for i in range(1, n):
tmp_root += ((ab[v[i-1]][0]-ab[v[i]][0])**2+(ab[v[i-1]][1]-ab[v[i]][1])**2)**0.5
ans += tmp_root
print(ans/count) | def abc145c_average_length():
import itertools
import math
n = int(input())
x = []
y = []
for _ in range(n):
a, b = map(int, input().split())
x.append(a)
y.append(b)
result = 0
cnt = 0
for p in itertools.permutations(range(n)):
total = 0
for i in range(n-1):
total += math.sqrt(pow(x[p[i]]-x[p[i+1]], 2)+pow(y[p[i]]-y[p[i+1]], 2))
result += total
cnt += 1
print(result/cnt)
abc145c_average_length() | 1 | 148,620,981,841,332 | null | 280 | 280 |
import sys
input = sys.stdin.readline
from collections import *
def bfs():
q = deque([0])
pre = [-1]*N
pre[0] = 0
while q:
v = q.popleft()
for nv in G[v]:
if pre[nv]==-1:
pre[nv] = v
q.append(nv)
return pre
N, M = map(int, input().split())
G = [[] for _ in range(N)]
for _ in range(M):
A, B = map(int, input().split())
G[A-1].append(B-1)
G[B-1].append(A-1)
pre = bfs()
print('Yes')
for pre_i in pre[1:]:
print(pre_i+1) | #!/usr/bin/env python3
import sys
from collections import deque
YES = "Yes" # type: str
def solve(N: int, M: int, A: "List[int]", B: "List[int]"):
dq = deque([])
traversed = [False for _ in range(N+1)]
ans = [None for _ in range(N+1)]
G = {n : set([]) for n in range(1, N+1)}
for a, b in zip(A,B):
G[a].add(b)
G[b].add(a)
dq.append(1)
traversed[1] = True
while dq:
s = dq.popleft()
for node in G[s]:
if not traversed[node]:
dq.append(node)
traversed[node] = True
ans[node] = s
print(YES)
for s in ans:
if s != None:
print(s)
return
# Generated by 1.1.7.1 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
M = int(next(tokens)) # type: int
A = [int()] * (M) # type: "List[int]"
B = [int()] * (M) # type: "List[int]"
for i in range(M):
A[i] = int(next(tokens))
B[i] = int(next(tokens))
solve(N, M, A, B)
if __name__ == '__main__':
main()
| 1 | 20,368,926,145,240 | null | 145 | 145 |
def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
# from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx as nx
# from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
a,b,m=n1()
A=n1()
B=n1()
X=n3(m)
A2=sorted(A)
B2=sorted(B)
ans=A2[0]+B2[0]
for a,b,c in X:
if A[a-1]+B[b-1]-c<ans:
ans=A[a-1]+B[b-1]-c
print(ans) | a,b,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ans = 123456789012345
for i in range(m):
x,y,c=map(int,input().split())
ans = min(ans, a[x-1]+b[y-1]-c)
a.sort()
b.sort()
ans = min(ans,a[0]+b[0])
print(ans) | 1 | 53,935,873,717,320 | null | 200 | 200 |
# 二項係数のmod (大量のmod計算が必要なとき)
def cmb(n, r, mod):
if (r < 0 or r > n):
return 0
r=min(r,n-r)
return g1[n] * g2[r] * g2[n - r] % mod
mod=998244353
N = 10 ** 6 # 出力の制限
g1 = [1, 1] # 元テーブル
g2 = [1, 1] # 逆元テーブル
inverse = [0, 1] # 逆元テーブル計算用テーブル
for i in range(2, N + 1):
g1.append((g1[-1] * i) % mod)
inverse.append((-inverse[mod % i] * (mod // i)) % mod)
g2.append((g2[-1] * inverse[-1]) % mod)
n,m,k= map(int, input().split())
ans=0
# 同じ色で塗る組数で場合分け
for i in range(k,-1,-1):
# 同色の組の色の割り当て
if i==k:
v1 = m * pow(m - 1, n - i - 1, mod)
else:
v1*=m-1
v1%=mod
# グループの分け方
v2=cmb(n-1,i,mod)
ans+=v1*v2
ans%=mod
print(ans) | # https://kmjp.hatenablog.jp/entry/2020/05/10/0900
# 数学的な問題
mod = 998244353
class COM:
def __init__(self, n, MOD):
self.n = n
self.MOD = MOD
self.fac = [0] * (n+1)
self.finv = [0] * (n+1)
self.inv = [0] * (n+1)
self.fac[0] = self.fac[1] = 1
self.finv[0] = self.finv[1] = 1
self.inv[1] = 1
for i in range(2, n+1):
self.fac[i] = self.fac[i-1] * i % MOD
self.inv[i] = MOD - self.inv[MOD % i] * (MOD // i) % MOD
self.finv[i] = self.finv[i-1] * self.inv[i] % MOD
def calc(self, k):
if k < 0:
return 0
return self.fac[self.n] * (self.finv[k] * self.finv[self.n-k] % self.MOD) % self.MOD
def main():
N, M, K = map(int,input().split())
# 隣り合う組がK以下のパターンを総当たりして解く
if N > 1:
cmbclass = COM(N-1, mod)
cmb = cmbclass.calc
else:
cmb = lambda x:1
res = 0
for i in range(K+1):
res += M * cmb(i) % mod * pow(M-1, N-i-1, mod)
print(res % mod)
if __name__ == "__main__":
main()
| 1 | 23,357,128,880,192 | null | 151 | 151 |
# -*- coding: utf-8 -*-
# Next Prime
import sys
TEST_INPUT = \
"""
100000
"""
TEST_OUTPUT = \
"""
100003
"""
def primes(n):
if n == 0 or n == 1: return []
ps = [2]
for odd in range(3, n + 1, 2):
for p in ps:
if odd % p == 0:
break
if p ** 2 > odd:
ps.append(odd)
break
return ps
def isprime(n):
if n == 0 or n == 1: return False
last = int(n**.5)
for m in primes(last):
if n % m == 0:
return False
return True
def nextprime(n):
if n in primes(n):
return n
else:
i = n
while not isprime(i):
i += 1
return i
def main(stdin):
n = int(stdin)
print(nextprime(n))
if __name__ == "__main__":
main(sys.stdin.read().strip()) | N,K=map(int,input().split())
A=[]
people=list(range(1,N+1,1))
for idx in range(K):
d=int(input())
X=list((map(int,input().split())))
for i in range(len(X)):
A.append(X[i])
ans =[i for i in people if not i in A]
print(len(ans)) | 0 | null | 65,359,991,252,978 | 250 | 154 |
n = int(input())
ret = 0
b = 1
while n > 0:
ret += b
n //= 2
b *= 2
print(ret)
| import math
h=int(input())
print(2**(math.floor(math.log2(h))+1)-1)
| 1 | 79,950,897,880,140 | null | 228 | 228 |
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_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()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
N = INT()
A = LIST()
A_c = Counter(A)
A_c_c = 0
for i in A_c.values():
A_c_c += i*(i-1)//2
for k in range(N):
ans = A_c_c - (A_c[A[k]] - 1)
print(ans)
| #!/usr/bin/env python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]
def inside(y, x, H, W):
return 0 <= y < H and 0 <= x < W
def ceil(a, b):
return (a + b - 1) // b
def sum_of_arithmetic_progression(s, d, n):
return n * (2 * s + (n - 1) * d) // 2
def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b)
def lcm(a, b):
g = gcd(a, b)
return a / g * b
def solve():
N = int(input())
A = list(map(int, input().split()))
c = defaultdict(int)
for a in A:
c[a] += 1
ans = 0
for k, v in c.items():
ans += v * (v - 1) // 2
for k in range(N):
tmp = ans
tmp -= c[A[k]] * (c[A[k]] - 1) // 2
tmp += max(0, (c[A[k]] - 1) * (c[A[k]] - 2) // 2)
print(tmp)
def main():
solve()
if __name__ == '__main__':
main()
| 1 | 47,763,615,630,470 | null | 192 | 192 |
import sys
i,j = input().split()
matrixa = []
for _ in range(int(i)):
matrixa += [[int(n) for n in sys.stdin.readline().split()]]
matrixb =[ int(num) for num in sys.stdin.readlines() ]
matrixc = [ 0 for _ in range(int(i))]
for n in range(int(i)):
for a,b in zip(matrixa[n],matrixb):
matrixc[n] += a*b
for c in matrixc:
print(c)
| #from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
# d = m - k[i] - k[j]
# if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
return list(map(int,input().split()))
def I():
return int(input())
NUM = [0] * 500000
for x in range(1,101):
for y in range(1,101):
for z in range(1,101):
nya = x**2 + y**2 + z**2 + x*y + y*z + z*x
NUM[nya] += 1
n = I()
for i in range(1,n+1):
print(NUM[i])
| 0 | null | 4,560,254,566,598 | 56 | 106 |
def result(x):
return x + x ** 2 + x ** 3;
n = int(input())
print(result(n)) | def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
n,m=n1()
if n%2==0:
if m>=2:
e=n//2
s=1
l=e-s
c=0
while e>s and c<m:
print(s,e)
s+=1
e-=1
c+=1
e=n
s=n-l+1
while e>s and c<m:
print(s,e)
s+=1
e-=1
c+=1
else:
print(1,2)
else:
if m>=2:
e=n//2+1
s=1
l=e-s
c=0
while e>s and c<m :
print(s,e)
s+=1
e-=1
c+=1
e=n
s=n-l+1
while e>s and c<m:
print(s,e)
s+=1
e-=1
c+=1
else:
print(1,2) | 0 | null | 19,427,524,943,620 | 115 | 162 |
N = int(input())
c = input()
l = len(c)
a = 0
b = 0
for i in range(l):
if c[i] == "R":
a += 1
for i in range(a, l):
if c[i] == "R":
b += 1
print(b) | n = int(input())
s = input()
res = 0
tem = s.find('WR')
if tem == -1:
print(res)
else:
i, j = 0, len(s)-1
while i<j:
while i < j and s[i] != 'W': i+=1
while i < j and s[j] != 'R':j -= 1
if s[i] == 'W' and s[j] == 'R':
res += 1
i += 1
j -= 1
print(res)
| 1 | 6,276,250,644,062 | null | 98 | 98 |
A, B, C, K = [int(i) for i in input().split(' ')]
print(min(A, K) - max(K - B - A, 0))
| A, B, C, K = map(int, input().split())
if (K - A) <= 0:
print(K)
else:
if (K - A - B) <= 0:
print(A)
else:
c = (K - A - B)
print(A - c)
| 1 | 21,805,407,318,892 | null | 148 | 148 |
import numpy as np
from numba import njit
N = np.array([int(_) for _ in input()])
dp = np.array([[0, 0] for _ in range(len(N))])
@njit
def solve(N, dp):
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])
solve(N, dp)
| n = input()
a, b = 0, 100
for i in n:
j = int(i)
a, b = min(a+j,b+j), min(a+11-j,b+9-j)
if j == 0:
b = a+100
print(min(a,b)) | 1 | 70,989,036,397,760 | null | 219 | 219 |
n = int(input())
A = []
B = []
for i in range(n):
a,b = list(map(int, input().split()))
A.append(a)
B.append(b)
A.sort()
B.sort()
j = n//2
if n%2 == 0:
print((B[j]+B[j-1])-(A[j]+A[j-1])+1)
else:
print(B[j]-A[j]+1) | w, h, x, y, r = map(int, raw_input().split())
if x < r or y < r:
print "No"
elif x+r>w or y+r>h:
print "No"
else:
print "Yes" | 0 | null | 8,836,876,230,560 | 137 | 41 |
n=int(input())
arr=list(map(int,input().split()))
c=0
for i in range(0,n,2):
if arr[i]%2!=0:
c+=1
print(c) | N = int(input())
L = list(map(int,input().split()))
cnt = 0
for n in range(N):
if (n + 1) % 2 == 1 and L[n] % 2 == 1:
cnt += 1
print(cnt) | 1 | 7,679,313,716,732 | null | 105 | 105 |
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
#import bisect
#
# d = m - k[i] - k[j]
# if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
return list(map(int,input().split()))
def I():
return int(input())
s = input()
if s == 'ABC':
print('ARC')
else:
print('ABC')
| N = input()
ans = 'ABC' if N == 'ARC' else 'ARC'
print(ans) | 1 | 24,032,243,827,510 | null | 153 | 153 |
K = int(input())
A, B = list(map(int, input().split()))
check = False
for k in range(A, B+1):
if k % K == 0:
check = True
else:
continue
if check:
print("OK")
else:
print("NG") | s=input()
if s[-1]!='s':print(s+'s')
else:print(s+'es') | 0 | null | 14,595,276,288,850 | 158 | 71 |
import random
S = input()
x = random.randrange(len(S)-2)
print(S[x] + S[x + 1] + S[x + 2]) | a=input()
b=list(a)
c=b[0:3]
d="".join(c)
print(d)
| 1 | 14,784,425,010,880 | null | 130 | 130 |
import copy
H, W, K = list(map(int, input().split()))
c = [0]*H
for i in range(H):
char = input()
c[i] = []
for j in range(W):
if char[j] == "#":
c[i].append(1)
else:
c[i].append(0)
count = 0
for i in range(2**H):
for j in range(2**W):
d = copy.deepcopy(c)
i2 = i
j2 = j
for k in range(H):
if i2 & 1:
d[k] = [0]*W
i2 >>= 1
for l in range(W):
if j2 & 1:
for m in range(H):
d[m][l] = 0
j2 >>= 1
s = sum(map(sum, d))
if s == K:
count += 1
print(count) | h,w,k = map(int, input().split())
s = [list(input()) for _ in range(h)]
ans = 0
for row in range(2**h):
for col in range(2**w):
c = 0
for i in range(h):
for j in range(w):
if (row >> i)&1 == 0 and (col >> j)&1 == 0:
if s[i][j]=='#':
c += 1
if c == k:
ans += 1
print(ans) | 1 | 8,915,085,153,760 | null | 110 | 110 |
import sys
l = []
for i in sys.stdin:
l.append(i.split())
def bubble_sort(data):
count = 0
for i in range(0,len(data)):
for j in range(len(data)-1,i,-1):
if data[j] < data[j-1]:
count += 1
temp = data[j]
data[j] = data[j-1]
data[j-1] = temp
for i in range(0,len(data)):
print(data[i],end='')
print(" ",end='') if i < len(data)-1 else print()
print(count)
for i in range(0,len(l[1])):
l[1][i] = int(l[1][i])
bubble_sort(l[1])
| import sys
input = sys.stdin.readline
MAX = 2*10**6+100
MOD = 10**9+7
fact = [0]*MAX #fact[i]: i!
inv = [0]*MAX #inv[i]: iの逆元
finv = [0]*MAX #finv[i]: i!の逆元
fact[0] = 1
fact[1] = 1
finv[0] = 1
finv[1] = 1
inv[1] = 1
for i in range(2, MAX):
fact[i] = fact[i-1]*i%MOD
inv[i] = MOD-inv[MOD%i]*(MOD//i)%MOD
finv[i] = finv[i-1]*inv[i]%MOD
def C(n, r):
if n<r:
return 0
if n<0 or r<0:
return 0
return fact[n]*(finv[r]*finv[n-r]%MOD)%MOD
K = int(input())
S = input()[:-1]
L = len(S)
ans = 0
for i in range(L, L+K+1):
ans += C(i-1, L-1)*pow(25, i-L, MOD)*pow(26, L+K-i, MOD)
ans %= MOD
print(ans) | 0 | null | 6,433,072,734,230 | 14 | 124 |
n,k = map(int, input().split())
ans = 0
while n > 0:
n /= k
n = int(n)
ans += 1
print(ans)
| def main():
n = int(stdinput())
st = [None] * (4**12)
for _ in range(n):
cmd, value = stdinput().split()
if cmd == 'insert':
st[get_hash(value)] = 1
elif cmd == 'find':
if st[get_hash(value)] == 1:
print('yes')
else:
print('no')
CODES = {'A' : 1, 'C' : 2, 'G' : 3, 'T' : 4}
def get_hash(s):
base = 1
h = 0
for c in s:
code = CODES[c]
h += code * base
base *= 4
return h
def stdinput():
from sys import stdin
return stdin.readline().strip()
if __name__ == '__main__':
main()
# import cProfile
# cProfile.run('main()')
| 0 | null | 32,215,045,921,652 | 212 | 23 |
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import sys
in_str = sys.stdin.readline().strip()
q = int(sys.stdin.readline())
for i in range(q):
command = sys.stdin.readline().split()
pos_a = int(command[1])
pos_b = int(command[2])
if command[0] == 'print':
print(in_str[pos_a:pos_b+1])
elif command[0] == 'reverse':
if pos_a == 0: to_pos = None
else: to_pos = pos_a - 1
in_str = in_str[:pos_a] + in_str[pos_b:to_pos:-1] + in_str[pos_b+1:]
elif command[0] == 'replace':
in_str = in_str[:pos_a] + command[3] + in_str[pos_b+1:]
else:
raise ValueError
| A1, A2, A3 = map(int,input().split())
if A1+A2+A3<=21:
print("win")
else:
print("bust") | 0 | null | 60,516,165,264,572 | 68 | 260 |
#C - Replacing Intege
N,K = map(int, input().split())
for i in range(N):
if N % K == 0:
N = 0
break
N = N % K
if abs(N-K) < N:
N = abs(N-K)
else :
break
print(N) | n,k =map(int,input().split())
if n%k==0:
print(0)
else:
print(min(n%k,abs((n%k)-k))) | 1 | 39,464,500,372,560 | null | 180 | 180 |
N, M, K = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
min = 0
cnt = 0
for k in b:
min += k
j = M
for i in range(N+1):
while(j > 0 and min > K):
j -= 1
min -= b[j]
if(min > K):
break
cnt = max(cnt, i + j)
if(i == N):
break
min += a[i]
print(cnt)
| 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) | 0 | null | 23,690,323,943,972 | 117 | 176 |
ans=[]
for i in range (0,10):
ans.append(int(input()))
ans.sort(reverse=True)
for i in range (0,3):
print(ans[i]) | spam = [int(input()) for i in range(0, 10)]
spam.sort()
spam.reverse()
for i in range(0,3):
print(spam[i]) | 1 | 26,343,030 | null | 2 | 2 |
# coding: utf-8
# Your code here!
class dice(object):
def __init__(self, arr):
self.top = arr[0]
self.side_s = arr[1]
self.side_e = arr[2]
self.side_w = arr[3]
self.side_n = arr[4]
self.bottom = arr[5]
def roll(self, s):
if s=='S':
tmp = self.bottom
self.bottom = self.side_s
self.side_s = self.top
self.top = self.side_n
self.side_n = tmp
elif s=='E':
tmp = self.bottom
self.bottom = self.side_e
self.side_e = self.top
self.top = self.side_w
self.side_w = tmp
elif s=='W':
tmp = self.bottom
self.bottom = self.side_w
self.side_w = self.top
self.top = self.side_e
self.side_e = tmp
elif s=='N':
tmp = self.bottom
self.bottom = self.side_n
self.side_n = self.top
self.top = self.side_s
self.side_s = tmp
s = input().split()
# s = '1 2 4 8 16 32'.split()
dice = dice(s)
arr = input()
for a in arr:
dice.roll(a)
# print(type(dice))
print(dice.top)
| class Dice:
def __init__(self,t,f,r,l,b,u):
self.t=t
self.f=f
self.r=r
self.l=l
self.b=b
self.u=u
def roll(self,i):
if d=='S':
key=self.t
self.t=self.b
self.b=self.u
self.u=self.f
self.f=key
elif d=='E':
key=self.t
self.t=self.l
self.l=self.u
self.u=self.r
self.r=key
elif d=='N':
key=self.t
self.t=self.f
self.f=self.u
self.u=self.b
self.b=key
else:
key=self.t
self.t=self.r
self.r=self.u
self.u=self.l
self.l=key
t,f,r,l,b,u=map(int,input().split())
a=list(input())
dice=Dice(t,f,r,l,b,u)
for d in a:
dice.roll(d)
print(dice.t)
| 1 | 229,520,599,540 | null | 33 | 33 |
import math
r = float(input())
pi = float(math.pi)
print("{0:.8f} {1:.8f}".format(r*r*pi,r * 2 * pi)) | from collections import Counter
def f(n):
if n<2:
return 0
return n*(n-1)//2
N = int(input())
A = list(map(int, input().split()))
cnt = Counter(A)
ans = 0
for c in cnt.values():
ans += f(c)
for a in A:
print(ans-cnt[a]+1) | 0 | null | 24,230,172,750,602 | 46 | 192 |
from operator import itemgetter
import bisect
N, D, A = map(int, input().split())
enemies = sorted([list(map(int, input().split())) for i in range(N)], key=itemgetter(0))
d_enemy = [enemy[0] for enemy in enemies]
b_left = bisect.bisect_left
logs = []
logs_S = [0, ]
ans = 0
for i, enemy in enumerate(enemies):
X, hp = enemy
start_i = b_left(logs, X-2*D)
count = logs_S[-1] - logs_S[start_i]
hp -= count * A
if hp > 0:
attack_num = (hp + A-1) // A
logs.append(X)
logs_S.append(logs_S[-1]+attack_num)
ans += attack_num
print(ans)
| n = int(input())
x = list(map(int, input().split()))
ans = 1000000
for i in range(1, 101):
s = 0
for j in range(n):
s += (x[j] - i)*(x[j] - i)
ans = min(ans, s)
print(str(ans))
| 0 | null | 73,980,351,882,592 | 230 | 213 |
import sys
import math
import itertools as it
def I():return int(sys.stdin.readline().replace("\n",""))
def I2():return map(int,sys.stdin.readline().replace("\n","").split())
def S():return str(sys.stdin.readline().replace("\n",""))
def L():return list(sys.stdin.readline().replace("\n",""))
def Intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def Lx(k):return list(map(lambda x:int(x)*-k,sys.stdin.readline().replace("\n","").split()))
if __name__ == "__main__":
n = I()
a = Intl()
for i in range(n):
if a[i]%2 == 0:
if a[i]%3 == 0 or a[i]%5 == 0:pass
else:
print("DENIED")
exit()
print("APPROVED") | from sys import exit
N = int(input())
for i in input().split():
if int(i) % 2 == 0:
if int(i) % 3 != 0 and int(i) % 5 != 0:
print('DENIED')
exit()
print('APPROVED')
| 1 | 68,719,664,073,020 | null | 217 | 217 |
# coding=utf-8
a, b = map(int, input().split())
if a > b:
big_num = a
sml_num = b
else:
big_num = b
sml_num = a
while True:
diviser = big_num % sml_num
if diviser == 0:
break
else:
big_num = sml_num
sml_num = diviser
print(sml_num) | a = list(map(int, input().split()))
a.sort()
while a[0] > 0:
b = a[1]%a[0]
a[1] = a[0]
a[0] = b
print(a[1]) | 1 | 7,544,745,248 | null | 11 | 11 |
a = list(input())
if a[-1] == 's':
a.append('e')
a.append('s')
else:
a.append('s')
print(''.join(a)) | import sys
def input(): return sys.stdin.readline().rstrip()
def main():
s = input()
if s[-1] != 's':
print(s+'s')
else:
print(s+'es')
if __name__=='__main__':
main() | 1 | 2,373,630,216,650 | null | 71 | 71 |
n,m = map(int,input().split())
h = list(map(int,input().split()))
l = list({i} for i in range(n+1))
for i in range(m):
a,b = map(int,input().split())
l[a].add(b)
l[b].add(a)
for i in range(len(l)):
l[i] = list(l[i])
good = set()
for i in range(1,len(l)):
l[i].remove(i)
for j in range(len(l[i])):
if h[l[i][j]-1] >= h[i-1]:
break
else:
good.add(i)
print(len(good)) | N, M = map(int, input().split())
H = list(map(int, input().split()))
OK = [True] * N
for _ in range(M):
A, B = map(lambda x: int(x)-1, input().split())
if H[A] < H[B]:
OK[A] = False
elif H[A] > H[B]:
OK[B] = False
else:
OK[A] = False
OK[B] = False
ans = sum(OK)
print(ans) | 1 | 25,073,277,996,900 | null | 155 | 155 |
a = input()
print('Yes' if input() in a+a else 'No') | ###綺麗になったよ!!!!!
def y_solver(tmp):
l=len(tmp)
rev=tmp[::-1]+"0"
ans=0
next_bit=0
kuri_cal=0
for i in range(l-1):
num=int(rev[i])+next_bit
next_num=int(rev[i+1])
if (num<5) or (num==5 and next_num<5):
ans+=(kuri_cal+num)
kuri_cal=0
next_bit=0
else:
kuri_cal+=10-num
next_bit=1
last=int(tmp[0])+next_bit
ans+=kuri_cal+min(last,11-last)
return ans
n=input()
ans=y_solver(n)
print(ans) | 0 | null | 36,178,743,476,010 | 64 | 219 |
N, M, K = map(int, input().split())
friend = {}
for i in range(M):
A, B = map(lambda x: x-1, map(int, input().split()))
if A not in friend:
friend[A] = []
if B not in friend:
friend[B] = []
friend[A].append(B)
friend[B].append(A)
block = {}
for i in range(K):
C, D = map(lambda x: x-1, map(int, input().split()))
if C not in block:
block[C] = []
if D not in block:
block[D] = []
block[C].append(D)
block[D].append(C)
first = {}
for i in range(N):
if i not in first:
first[i] = i
if i in friend:
queue = []
queue.extend(friend[i])
counter = 0
while counter < len(queue):
item = queue[counter]
first[item] = i
if item in friend:
for n in friend[item]:
if n not in first:
queue.append(n)
counter += 1
size = {}
for key in first:
if first[key] not in size:
size[first[key]] = 1
else:
size[first[key]] += 1
for i in range(N):
if i not in friend:
print(0)
continue
no_friend = 0
if i in block:
for b in block[i]:
if first[b] == first[i]:
no_friend += 1
print(size[first[i]] - len(friend[i]) - no_friend - 1) | # Air Conditioner
X = int(input())
print(['No', 'Yes'][X >= 30]) | 0 | null | 33,566,701,614,080 | 209 | 95 |
n = input()
data = list(map(str, input().split()))
print(*data[::-1]) | import sys
sys.setrecursionlimit(2000)
def joken(a,n):
if n==1:
return 0
elif a%n==0 and a//n>=n:
return joken(a//n,n)
elif a%n==1:
return 1
elif a%n==0 and a//n==1:
return 1
else:
return 0
def make_divisors(n):
lower_divisors , upper_divisors = [], []
i = 1
while i*i <= n:
if n % i == 0:
lower_divisors.append(i)
if i != n // i:
upper_divisors.append(n//i)
i += 1
return lower_divisors + upper_divisors[::-1]
N=int(input())
c=len(make_divisors(N-1))
d=make_divisors(N)
a=0
for i in range(len(d)):
a+=joken(N,d[i])
print(a+c-1) | 0 | null | 21,004,804,273,760 | 53 | 183 |
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip.split())
def main():
sys.setrecursionlimit(10**5)
n = I()
s = S()
global cnt
cnt = 0
def tansaku(st,depth):
global cnt
for i in range(10):
index = st.find(str(i))
if index != -1:
if depth == 0:
cnt += 1
# print(i)
# print(st,i,index,depth)
else:
tansaku(st[index+1:],depth-1)
tansaku(s,2)
print(cnt)
main() | N = int(input())
R = [int(input()) for _ in range(N)]
maxv = -2000000000
minv = R[0]
for i in range(1,N):
maxv = max([maxv, R[i] - minv ])
minv = min([minv, R[i]])
print(maxv)
| 0 | null | 63,983,036,785,082 | 267 | 13 |
n = int(input())
x = list(map(int,input().split()))
ans = 1000000000000
for i in range(1,101):
b = 0
for num in x:
b += (num - i)**2
ans = min(b,ans)
print(ans)
| import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []
def main():
n = i_input()
xs = i_list()
min_list = []
for i in range(1, 101):
tmp = 0
for x in xs:
tmp += (i - x)**2
min_list.append(tmp)
print(min(min_list))
if __name__ == '__main__':
main()
| 1 | 65,116,076,614,612 | null | 213 | 213 |
s = input()
if s[1] == 'R':
print('ABC')
else:
print('ARC') | #!/usr/bin/env python3
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a = [0]
b = [0]
for i in range(N):
a.append(a[i] + A[i])
for i in range(M):
b.append(b[i] + B[i])
count = 0
j = M
for i in range(N+1):
if a[i] > K:
break
while b[j] > K - a[i]:
j -= 1
count = max(count, i+j)
print(count)
| 0 | null | 17,386,487,866,020 | 153 | 117 |
#!/usr/bin/env python3
import sys
def input():
return sys.stdin.readline()[:-1]
def main():
N, K = map(int, input().split())
ans = N % K
ans = min(ans, abs(ans - K))
print(ans)
if __name__ == '__main__':
main()
| N,K = map(int,input().split())
m = N%K
print(min(m,K-m)) | 1 | 39,056,275,067,530 | null | 180 | 180 |
def solve():
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][int(input())-1])
return 0
if __name__ == '__main__':
solve() | s = "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"
S = s.split(", ")
k = int(input())
print(S[k-1]) | 1 | 50,289,507,301,692 | null | 195 | 195 |
#!/usr/bin/env python
# coding: utf-8
# In[5]:
H,N = map(int, input().split())
A = []; B = []
for _ in range(N):
a,b = map(int, input().split())
A.append(a)
B.append(b)
# In[12]:
a_max = max(A)
dp = [0]*(H+a_max)
for i in range(H+a_max):
dp[i] = min(dp[i-a] + b for a,b in zip(A,B))
print(min(dp[H-1:]))
# In[ ]:
| import sys
input = sys.stdin.readline
def main():
H, N = map(int, input().split())
A = []
B = []
for _ in range(N):
a, b = map(int, input().split())
A.append(a)
B.append(b)
A_max = max(A)
dp = [1e14] * (H+A_max + 1) # ダメージ量がiの最小コスト
dp[0] = 0
for i in range(H):
for j in range(N):
dp[i+A[j]] = min(dp[i+A[j]], dp[i]+B[j])
ans = 1e30
for i in range(H, H+A_max+1):
ans = min(ans, dp[i])
print(ans)
main() | 1 | 81,046,518,397,432 | null | 229 | 229 |
h,w,m=map(int,input().split())
bomb=[list(map(int,input().split())) for i in range(m)]
num_h = [0] * (h+1)
num_w = [0] * (w+1)
bomb_set = set()
for hi,wi in bomb:
num_h[hi] += 1
num_w[wi] += 1
bomb_set.add((hi,wi))
max_h = max(num_h)
max_w = max(num_w)
max_hs = [k for k,v in enumerate(num_h) if v == max_h]
max_ws = [k for k,v in enumerate(num_w) if v == max_w]
result = max_h + max_w
for i in max_hs:
for j in max_ws:
if (i,j) not in bomb_set:
print(result)
exit(0)
print(result-1)
| def solve():
N = int(input())
XLs = [list(map(int, input().split())) for _ in range(N)]
XLs.sort(key = lambda x:(x[0],-1*x[1]))
interval = (XLs[0][0]-XLs[0][1],XLs[0][0]+XLs[0][1])
ret = 0
for XL in XLs[1:]:
interval_ = (XL[0]-XL[1], XL[0]+XL[1])
if interval_[0] < interval[1]:
interval = (max(interval[0], interval_[0]),min(interval[1], interval_[1]))
ret += 1
else:
interval = interval_
print(N-ret)
solve() | 0 | null | 47,243,683,848,830 | 89 | 237 |
import sys
input = sys.stdin.readline
def inpl():
return list(map(int, input().split()))
N, M = inpl()
coins = inpl()
dp = [i for i in range(N + 1)]
coins.sort()
for n in range(coins[1], N + 1):
for c in coins[1:]:
if c > n:
continue
dp[n] = min(dp[n], dp[n - c] + 1)
# print(dp[N])
print(dp[N])
| N = int(input())
a = list(map(int, input().split()))
x = 0
for r in a:
x ^= r
a = [str(x^r) for r in a]
a = ' '.join(a)
print(a) | 0 | null | 6,329,563,121,140 | 28 | 123 |
N = int(input())
N1 = N % 10
if N1 == 3:
print("bon")
elif (N1 == 0) or (N1 == 1) or (N1 == 6) or (N1 == 8):
print("pon")
else:
print("hon") | import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)
N, K = mapint()
Hs = list(mapint())
lis = [1 if a>=K else 0 for a in Hs]
print(sum(lis)) | 0 | null | 98,981,880,227,360 | 142 | 298 |
n,k=map(int,input().split())
lst_1=list(map(int,input().split()))
# print(lst_1)
lst_2=[]
for i in range(n-k):
temp=1
temp=lst_1[i+k]/lst_1[i]
lst_2.append(temp)
for i in lst_2:
if i>1:
print("Yes")
else:print("No")
| n=int(input())
p=10**9+7
A=list(map(int,input().split()))
binA=[]
for i in range(n):
binA.append(format(A[i],"060b"))
lis=[0 for i in range(60)]
for binAi in binA:
for j in range(60):
lis[j]+=int(binAi[j])
binary=[0 for i in range(60)]
for i in range(n):
for j in range(60):
if binA[i][j]=="0":
binary[j]+=lis[j]
else:
binary[j]+=n-lis[j]
binary[58]+=binary[59]//2
binary[59]=0
explis=[1]
for i in range(60):
explis.append((explis[i]*2)%p)
ans=0
for i in range(59):
ans=(ans+binary[i]*explis[58-i])%p
print(ans)
| 0 | null | 64,892,128,564,952 | 102 | 263 |
n = int(input())
A = list(map(int, input().split()))
print(' '.join(list(map(str, A))))
for i in range(1,n):
key = A[i]
j = i - 1
while j >= 0 and A[j] > key:
A[j+1] = A[j]
j -= 1
A[j+1] = key
print(' '.join(list(map(str, A)))) | key = raw_input().upper()
c = ''
while True:
s = raw_input()
if s == 'END_OF_TEXT':
break
c = c + ' ' + s.upper()
cs = c.split()
total = 0
for w in cs:
if w == key:
total = total + 1
print total | 0 | null | 913,065,283,484 | 10 | 65 |
A, B, C = map(int, input().split())
temp = B
B = A
A = temp
temp = C
C = A
A = temp
print(str(A) + " " + str(B) + " " + str(C)) | import numpy as np
n = int(input())
print(int(np.ceil(n / 2))) | 0 | null | 48,226,020,507,716 | 178 | 206 |
import math
a,b,h,m = map(int,input().split())
x_h = a * math.sin(math.radians(0.5 * (60 * h + m)))
y_h = a * math.cos(math.radians(0.5 * (60 * h + m)))
x_m = b * math.sin(math.radians(6 * m))
y_m = b * math.cos(math.radians(6 * m))
print(math.sqrt((x_h-x_m)**2 + (y_h-y_m)**2)) | import math
a,b,h,m=map(int,input().split())
lrad=6*m
srad=30*h+0.5*m
if abs(lrad-srad)<=180:
do=abs(lrad-srad)
else:
do=360-abs(lrad-srad)
rad=math.radians(do)
print(math.sqrt(a**2+b**2-2*a*b*math.cos(rad))) | 1 | 20,084,700,000,072 | null | 144 | 144 |
import math
k = int(input())
a, b = list(map(int, input().split()))
mul = math.floor(b/k) * k
if(mul >= a and (mul >= a and mul <= b)):
print('OK')
else:
print('NG') | 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') | 1 | 26,570,339,711,840 | null | 158 | 158 |
def getN():
return int(input())
def getNM():
return map(int, input().split())
def getList():
return list(map(int, input().split()))
def getArray(intn):
return [int(input()) for i in range(intn)]
def input():
return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
ns = []
while len(ns) < rantime:
n = random.randint(ran1, ran2)
if not n in ns:
ns.append(n)
return sorted(ns)
def rand_query(ran1, ran2, rantime):
r_query = []
while len(r_query) < rantime:
n_q = rand_ints_nodup(ran1, ran2, 2)
if not n_q in r_query:
r_query.append(n_q)
return sorted(r_query)
from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right
import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7
#############
# Main Code #
#############
# 余りの平均が1のもの
N, K = getNM()
A = getList()
A = [(i % K) - 1 for i in A]
for i in range(N - 1):
A[i + 1] += A[i]
A.insert(0, 0)
A = [i % K if i >= 0 else i for i in A]
num = defaultdict(list)
for i in range(N + 1):
num[A[i]].append(i)
cnt = 0
for key, opt in num.items():
for i in range(len(opt)):
index = bisect_right(opt, opt[i] + K - 1)
cnt += index - i - 1
print(cnt) | from itertools import accumulate
from collections import Counter
N,K,*A = map(int, open(0).read().split())
A = [a-1 for a in A]
B = [b%K for b in accumulate(A)]
if K>N:
Cnt = Counter(B)
ans = Cnt[0]+sum(v*(v-1)//2 for v in Cnt.values())
else:
Cnt = Counter(B[:K])
ans = Cnt[0]+sum(v*(v-1)//2 for v in Cnt.values())
if B[K-1]==0:
ans -= 1
for i in range(N-K):
Cnt[B[i]] -= 1
ans += Cnt[B[i+K]]
Cnt[B[i+K]] += 1
print(ans) | 1 | 137,469,320,900,548 | null | 273 | 273 |
# Minor Change
S = input()
T = input()
ans = 0
for e in zip(S,T):
ans += [0,1][e[0]!=e[1]]
print(ans)
| N = int(input())
A = list(map(int, input().split()))
cnt = [0] * (100001)
ans = sum(A)
for a in A:
cnt[a] += 1
Q = int(input())
for _ in range(Q):
B, C = map(int, input().split())
cnt[C] += cnt[B]
ans += cnt[B] * (C-B)
cnt[B] = 0
print(ans) | 0 | null | 11,286,663,027,344 | 116 | 122 |
#n = int(input())
from collections import deque
n, m = map(int, input().split())
# n=200000
# m=200000
#al = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
adjl = [[] for _ in range(n+1)]
NIL = -1
appear = {}
isalone = {}
for i in range(m):
a, b = map(int, input().split())
if appear.get((a, b), False) or appear.get((a, b), False):
continue
appear[(a, b)] = True
appear[(b, a)] = True
isalone[a] = False
isalone[b] = False
adjl[a].append(b)
adjl[b].append(a)
NIL = -1 # 未発見を示す値
d = [-1 for i in range(n+1)] # 頂点1からの距離を格納するリスト
color = [NIL for i in range(n+1)] # 未到達かを示すリスト
def bfs(start_node, color_id): # uは探索の開始点
global color, d
q = deque([start_node])
d[start_node] = 0
color[start_node] = color_id
while len(q) != 0:
u = q.popleft()
for v in adjl[u]:
if color[v] == NIL:
d[v] = d[u]+1
color[v] = color_id
q.append(v)
color_id = 0
for u in range(1, n+1):
if color[u] == NIL:
color_id += 1
bfs(u, color_id)
group = {}
for i in range(1, n+1):
if isalone.get(i, True):
continue
group[color[i]] = group.get(color[i], 0)+1
mx = 1
for k, v in group.items():
mx = max(mx, v)
print(mx)
| """
UnionFindにはいろいろな実装があるが, 本問ではparents配列にノード数を保持する実装だと非常に簡単に解ける.
以下のようにしてノード数を保持する.
自身が子のとき, 親ノード番号を格納する.
自身が根のとき, ノード数を負の数で格納する.
つまり, 負の数のときは自身が根であり, その絶対値がその木のノード数を表す.
初期化時は、すべてのノードを−1で初期化する.
"""
N,M = map(int,input().split())
#UnionFind木の実装
#-1で初期化し、併合のたびに-1していく
par = [-1] * N #親
rank = [0] * N #木の深さ
#木の根を求める
def find(x):
#par[x]が負のとき(自分が代表のとき)、自身を返す
if par[x] < 0:
return x
else:
return find(par[x])
#xとyの属する集合を併合
def unite(x,y):
x = find(x)
y = find(y)
#もとから同じ集合のときは何もしない
if (x == y):
return
#x側を常に小さくする
if par[x] > par[y]:
x, y = y, x
#x側に併合する、その際xの代表にノード数を加算する
par[x] += par[y]
par[y] = x
#xとyが同じ集合に属するかどうか
def same(x,y):
return find(x) == find(y)
for i in range(M):
x,y = map(int,input().split())
x -= 1; y -= 1
unite(x,y)
ans = min(par)
print(abs(ans))
| 1 | 3,934,524,450,080 | null | 84 | 84 |
# Belongs to : midandfeed aka asilentvoice
n, m, l = [int(x) for x in input().split()]
a = [[int(x) for x in input().split()] for i in range(n)]
b = [[int(x) for x in input().split()] for i in range(m)]
ans = []
for i in range(n):
rtemp = []
for j in range(l):
temp = 0
for k in range(m):
temp += (a[i][k] * b[k][j])
rtemp.append(temp)
ans.append(rtemp)
for row in ans:
print(" ".join(map(str, row))) | #!/usr/bin/env python3
def solve(S: str):
return sum([a != b for a, b in zip(S, reversed(S))]) // 2
def main():
S = input().strip()
answer = solve(S)
print(answer)
if __name__ == "__main__":
main()
| 0 | null | 60,812,558,055,130 | 60 | 261 |
def is_prime(n):
for i in range(2, n + 1):
if i * i > n:
break
if n % i == 0:
return False
return n != 1
x = int(input())
while not is_prime(x):
x += 1
print(x) | h = int(input())
w = int(input())
n = int(input())
ma = max(h, w)
print(n // ma) if n // ma == n / ma else print(n // ma + 1) | 0 | null | 97,638,392,202,272 | 250 | 236 |
n = int(input())
tp = 0
hp = 0
for i in range(n):
tarou, hanako = map(str,input().split())
if(tarou > hanako):
tp += 3
elif(tarou < hanako):
hp += 3
else:
tp += 1
hp += 1
print("%d %d" %(tp,hp))
| input()
print(' '.join(reversed(input().split())))
| 0 | null | 1,463,994,518,208 | 67 | 53 |
# A - Station and Bus
# https://atcoder.jp/contests/abc158/tasks/abc158_a
s = input()
if len(set(s)) == 2:
print('Yes')
else:
print('No')
| N = int(input())
data = [input() for _ in range(N)]
def f(s):
c = len([x for x in data if x in s])
print(f"{s} x {c}")
f("AC")
f("WA")
f("TLE")
f("RE")
| 0 | null | 31,873,565,135,840 | 201 | 109 |
n = input()
num = map(int, raw_input().split())
for i in range(n):
if i == n-1:
print num[n-i-1]
break
print num[n-i-1], | n = int(input())
a = [int(i) for i in input().split()]
print(' '.join(map(str, reversed(a)))) | 1 | 985,334,024,180 | null | 53 | 53 |
k = input()
s = input()
print("Yes" if s[:-1] == k else "No") | s = input()
t = input()
c = 0
for i in range(len(s)):
if s[i]==t[i] and len(t)==len(s)+1:
c+=1
if c==len(s):
print("Yes")
else:
print("No") | 1 | 21,437,350,857,600 | null | 147 | 147 |
import collections
N = int(input())
A = list(map(int, input().split()))
c = collections.Counter(A)
ans = 0
for i in c:
ans+=c[i]*(c[i]-1)//2
for i in range(N):
print(ans-(c[A[i]]-1)) | n,k = map(int, input().split())
al = list(map(int, input().split()))
fl = list(map(int, input().split()))
al.sort()
fl.sort(reverse=True)
afl = []
for a,f in zip(al,fl):
afl.append((a,f))
ok, ng = 10**12, -1
while abs(ok-ng) > 1:
mid = (ok+ng) // 2
cnt = 0
for a,f in afl:
val = a*f
train_cnt = (val-mid-1)//f + 1
cnt += max(train_cnt, 0)
if cnt <= k:
ok = mid
else:
ng = mid
print(ok) | 0 | null | 106,545,412,898,480 | 192 | 290 |
import math
x_1, y_1, x_2, y_2 = map(float, input().split())
l = math.sqrt((x_1 - x_2)**2 + (y_1 - y_2)**2)
print(l)
| s = input()
t = input()
cnt = 0
for i in range (len(s)):
if s[i] == t[i]:
cnt += 1
if cnt == len(s) and len(t) - len(s) == 1:
print("Yes")
else:
print("No")
| 0 | null | 10,765,248,202,800 | 29 | 147 |
import sys
official_house = {}
for b in range(1, 5):
for f in range(1, 4):
for r in range(1, 11):
official_house[(b, f, r)] = 0
n = int(sys.stdin.readline())
for line in sys.stdin:
(b, f, r, v) = [int(i) for i in line.split()]
official_house[(b, f, r)] += v
for b in range(1, 5):
if b != 1:
print("####################")
for f in range(1, 4):
for r in range(1, 11):
print(" %d" % official_house[(b, f, r)], end="")
print() | #!/usr/bin/env python3
n = int(input())
matrix = []
while n > 0:
values = [int(x) for x in input().split()]
matrix.append(values)
n -= 1
official_house = [[[0 for z in range(10)] for y in range(3)] for x in range(4)]
Min = 0
Max = 9
for b, f, r, v in matrix:
num = official_house[b - 1][f - 1][r - 1]
if Min >= num or Max >= num:
official_house[b - 1][f - 1][r - 1] += v
for i in range(4):
for j in range(3):
print('',' '.join(str(x) for x in official_house[i][j]))
if 3 > i:
print('#' * 20) | 1 | 1,085,498,484,900 | null | 55 | 55 |
n = int(input())
x = list(map(int,input().split()))
x.sort()
ans = 10 ** 8
for p in range(x[0],x[-1]+1):
m = 0
z = 0
for i in range(n):
z = x[i] - p
m += (z ** 2)
ans = min(ans,m)
print(ans) | n = int(input())
A = list(map(int,input().split()))
b = 1
B=[0]*(n+1)
count = 0
t=len(A)-1
for i in range(t):
B[i] = b
if 2*(b - A[i]) < A[i+1]:
count += 1
break
b = 2*(b - A[i])
B[n] = b
if n == 0 and A[0] > 1:
count += 1
j = 0
while count == 0 and A[t] > B[j]:
if j == n:
break
j += 1
total = 0
for i in range(j):
total += B[i]
s = A[t]
for i in range(t-1,j-1,-1):
total += min(B[i],s+A[i])
s+=A[i]
if count==0:
print(total+A[t])
else:
print('-1') | 0 | null | 42,056,010,988,134 | 213 | 141 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.