code1
stringlengths 17
427k
| code2
stringlengths 17
427k
| similar
int64 0
1
| pair_id
int64 2
181,637B
⌀ | question_pair_id
float64 3.7M
180,677B
⌀ | code1_group
int64 1
299
| code2_group
int64 1
299
|
---|---|---|---|---|---|---|
import statistics as st
while True:
n=int(input())
if n==0:
break
s=list(map(int,input().split()))
print(f'{st.pstdev(s):.5f}')
| import math
while True:
n = int(input())
if n == 0:
break
s = [int(s) for s in input().split()]
ave = sum(s) / n
a = 0
for N in s:
a += (N - ave)**2
a = math.sqrt((a / n))
print(a) | 1 | 187,279,758,524 | null | 31 | 31 |
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
import resource
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub
from copy import deepcopy
sys.setrecursionlimit(1000000)
s, h = resource.getrlimit(resource.RLIMIT_STACK)
# resource.setrlimit(resource.RLIMIT_STACK, (h, h))
input = sys.stdin.readline
INF = 2**62-1
def read_int():
return int(input())
def read_int_n():
return list(map(int, input().split()))
def read_float():
return float(input())
def read_float_n():
return list(map(float, input().split()))
def read_str():
return input().strip()
def read_str_n():
return list(map(str, input().split()))
def error_print(*args):
print(*args, file=sys.stderr)
def mt(f):
import time
def wrap(*args, **kwargs):
s = time.time()
ret = f(*args, **kwargs)
e = time.time()
error_print(e - s, 'sec')
return ret
return wrap
@mt
def slv(N, M, S):
def f(s, p):
if p == 0:
return s
elif p < 0:
return None
for i in range(M, 0, -1):
j = p - i
if j < 0 or j >= len(S):
continue
if S[j] == '1':
continue
s.append(i)
v = f(s, j)
if v:
return v
s.pop()
return None
m = 0
mm = 0
for c in S:
if c == '1':
mm += 1
m = max(mm, m)
else:
mm = 0
if m >= M:
return -1
ans = f([], N)
if ans:
return ' '.join(map(str, reversed(ans)))
return -1
def main():
N, M = read_int_n()
S = read_str()
print(slv(N, M, S))
if __name__ == '__main__':
main()
| #!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1
n = int(input())
A = list(map(int,input().split()))
dp0 = [0] * (n+11)
dp1 = [0] * (n+11)
dp2 = [0] * (n+11)
for i,ai in enumerate(A):
dp2[i+11] = (max(dp0[i+7] + ai, dp1[i+8] + ai, dp2[i+9] + ai) if i >= 2 else 0)
dp1[i+11] = (max(dp0[i+8] + ai, dp1[i+9] + ai) if i >= 1 else 0)
dp0[i+11] = dp0[i+9] + ai
if n % 2 == 0:
print(max(dp0[n + 9], dp1[n + 10]))
else:
print(max(dp0[n + 8], dp1[n + 9], dp2[n + 10]))
# debug
# print(dp0,dp1,dp2,sep="\n")
| 0 | null | 88,082,979,208,220 | 274 | 177 |
n=int(input())
l=[int(i) for i in input().split()]
l.sort()
def func(one,two,three):
if len({one,two,three})==3 and one+two>three:
return True
return False
ans=0
for i in range(n-2):
for j in range(i+1,n-1):
for k in range(j+1,n):
one=l[i]
two=l[j]
three=l[k]
if func(one,two,three):
ans+=1
print(ans) | n = int(input())
s = list(input())
cnt = 1
for i in range(n-1):
if s[i]!=s[i+1]:
cnt += 1
print(cnt) | 0 | null | 87,747,891,090,912 | 91 | 293 |
class Solution:
def solve(self, N: int, P: int, S: str):
if P == 2 or P == 5:
answer = 0
for idx, s in enumerate(S):
if int(s) % P == 0:
answer += idx + 1
else:
answer = 0
U = [0] * P # int(S[i,N] mod P
U[0] += 1
num = 0
base10_mod_p = 1
for i in range(N):
num = (num + int(S[N-i-1]) * base10_mod_p) % P
base10_mod_p = (base10_mod_p * 10) % P
U[num] += 1
for u in U:
answer += u * (u-1) // 2
return answer
if __name__ == '__main__':
# standard input
N, P = map(int, input().split())
S = input()
# solve
solution = Solution()
answer = solution.solve(N, P, S)
print(answer)
|
def resolve():
R, C, K = map(int, input().split())
G = [[0] * (C + 1) for _ in range(R + 1)]
for _ in range(K):
r, c, v = map(int, input().split())
G[r][c] = v
dp = [[[0] * (C + 1) for _ in range(R + 1)] for _ in range(4)]
for i in range(R + 1):
for j in range(C + 1):
for k in range(4):
here = dp[k][i][j]
# 次の行に移動する場合
if i + 1 <= R:
# 移動先のアイテムを取らない場合
dp[0][i + 1][j] = max(dp[0][i + 1][j], here)
# 移動先のアイテムを取る場合
dp[1][i + 1][j] = max(dp[1][i + 1][j], here + G[i + 1][j])
# 次の列に移動する場合
if j + 1 <= C:
# 移動先のアイテムを取らない場合
dp[k][i][j + 1] = max(dp[k][i][j + 1], here)
# 現在のkが3未満のときのみ, 移動先のアイテムを取ることが可能
if k < 3:
dp[k + 1][i][j + 1] = max(dp[k + 1][i][j + 1], here + G[i][j + 1])
ans = 0
for k in range(4):
ans = max(ans, dp[k][-1][-1])
print(ans)
if __name__ == "__main__":
resolve() | 0 | null | 31,884,316,580,662 | 205 | 94 |
n,k =map(int,input().split())
l = list(map(int,input().split()))
l = sorted(l)
print(sum(l[0:k]))
| N,K=input().split()
N=int(N)
K=int(K)
p = [int(i) for i in input().split()]
p.sort()
print(sum(p[0:K]))
| 1 | 11,616,441,390,328 | null | 120 | 120 |
import math
import sys
readline = sys.stdin.readline
def main():
a, b, c = map(int, readline().rstrip().split())
print(c, a, b)
if __name__ == '__main__':
main()
| n,k=map(int,input().split())
h=list(map(int,input().split()))
h=sorted(h)
ans=0
for i in range(len(h)-k):
ans+=h[i]
print(ans) | 0 | null | 58,918,794,702,990 | 178 | 227 |
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30
def main():
n, m = list(map(int, input().strip().split()))
c = [0] + sorted(list(map(int, input().strip().split())))
dp = [[0] * (n+1) for _ in range(m+1)]
dp[0] = [INF] * (n+1)
dp[0][0] = 0
for i in range(1, m+1):
for j in range(n+1):
if j-c[i] < 0:
dp[i][j] = dp[i-1][j]
else:
dp[i][j] = min(dp[i-1][j], dp[i][j-c[i]]+1)
print(dp[m][n])
if __name__ == '__main__':
main()
|
url = "https://atcoder.jp//contests/abc160/tasks/abc160_c"
import itertools
def main():
n, m , X = list(map(int, input().split()))
books = []
ans = -1
for _ in range(n):
books.append(list(map(int, input().split())))
for i in range(n):
for row in itertools.combinations(range(0, n), i+1):
cost = 0
rikai = [0] * m
for idx in row:
cost += books[idx][0]
for idx2 in range(1, len(books[idx])):
rikai[idx2 - 1] += books[idx][idx2]
if len(list(filter(lambda x: x >= X, rikai))) == len(rikai):
ans = min(ans, cost) if ans != -1 else cost
print(ans)
if __name__ == '__main__':
main()
| 0 | null | 11,197,120,365,134 | 28 | 149 |
n = int(input())
a = list(map(int,input().split()))
mod = 1000000007
ans = 1
l = []
for i in range(n):
if a[i] == 0:
l.append(0)
ans = ans*(4-len(l))%mod
else:
id = -1
count = 0
for j in range(len(l)):
if l[j] == a[i] - 1:
count += 1
id = j
if id == -1:
ans = 0
break
ans = (ans*count)%mod
l[id] = a[i]
if ans == 0:
break
print(ans%mod) | n = int(input())
a = list(map(int, input().split()))
mod = 1000000007
ans, cnt = 1, [0, 0, 0]
for i in a:
ans = ans * cnt.count(i) % mod
for j in range(3):
if cnt[j] == i:
cnt[j] += 1
break
print(ans)
| 1 | 130,249,902,053,148 | null | 268 | 268 |
X, Y = map(int,input().split())
multiple = X * Y
print(multiple) | def az8():
xs = map(int,raw_input().split())
a,b = xs[0],xs[1]
print (a/b),(a%b), "%5f"%(float(a)/b)
az8() | 0 | null | 8,140,400,530,650 | 133 | 45 |
# coding=utf-8
import math
N = int(input())
for i in range(N):
length_list = list(map(int, input().split()))
length_list.sort()
if math.pow(length_list[0], 2) + math.pow(length_list[1], 2) == math.pow(length_list[2], 2):
print('YES')
else:
print('NO') | n = int(input())
i = 0
while (i < n):
L = map(int, raw_input().split())
L.sort(reverse = True)
if (pow(L[0], 2) == pow(L[1], 2) + pow(L[2], 2)):
print "YES"
else:
print "NO"
i += 1 | 1 | 239,322,798 | null | 4 | 4 |
import random
name = str(input())
a = len(name)
if 3<= a <= 20:
b = random.randint(0,a-3)
ada_1 = name[b]
ada_2 = name[b+1]
ada_3 = name[b+2]
print(ada_1+ada_2+ada_3)
else:
None | import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()
def resolve():
s=str(input())
print(s[:3])
resolve() | 1 | 14,760,494,118,412 | null | 130 | 130 |
n = int(input())
a = []
for i in range(n):
x,l = map(int,input().split())
s = x-l
g = x+l
a.append((s,g))
a = sorted(a, reverse=False, key=lambda x: x[1])
tmp = a[0][1]
ans = 1
for i in range(1,len(a)):
if tmp <= a[i][0]:
tmp = a[i][1]
ans += 1
print(ans) | import sys
input = sys.stdin.readline
N,M=map(int,input().split());S=input()[:-1]
if S.find("1"*M)>0:
print(-1)
exit()
k=[N+1]*(N+1)
k[0]=N
c=1
for i in range(N-1,-1,-1):
if int(S[i])==0:
if k[c-1]-i <= M:
k[c]=i
else:
c+=1
k[c]=i
print(*[j-i for i,j in zip(k[c::-1],k[c-1::-1])]) | 0 | null | 114,619,327,146,500 | 237 | 274 |
def main():
r,c = map(int, input().split())
chart = [list(map(int, input().split())) for i in range(r)]
total = [0 for i in range(c)]
for row in chart:
print((' '.join(map(str, row))) + ' ' + str(sum(row)))
total = [x + y for (x, y) in zip(total, row)]
print((' '.join(map(str, total))) + ' ' + str(sum(total)))
main() | import sys
from collections import defaultdict, Counter, namedtuple, deque
import itertools
import functools
import bisect
import heapq
import math
MOD = 10 ** 9 + 7
# MOD = 998244353
# sys.setrecursionlimit(10**8)
n, k, c = map(int, input().split())
s = input()
left = [-1]*k
right = [-1]*k
d = w = 0
while w < k:
if s[d] == "o":
left[w] = d
w += 1
d += c+1
else:
d += 1
d, w = n-1, k-1
while w >= 0:
if s[d] == "o":
right[w] = d
w -= 1
d -= c+1
else:
d -= 1
# print(left, right)
for i in range(k):
if left[i] == right[i]:
print(left[i]+1)
| 0 | null | 21,006,194,216,230 | 59 | 182 |
s = input()
n = len(s)
if n % 2 == 1:
print("No")
exit(0)
for i in range(n):
if i % 2 == 0:
if s[i] != "h":
print("No")
break
elif s[i] != "i":
print("No")
break
else:
print("Yes")
| num =raw_input()
num = int(num)
h = num/3600
m = (num-h*3600)/60
s = num-h*3600-m*60
h,m,s = map(str,(h,m,s))
print h+':'+m+':'+s | 0 | null | 26,611,504,141,560 | 199 | 37 |
from decimal import *
import math
getcontext().prec=1000
a,b,c=map(int,input().split())
if a+b+2*Decimal(a*b).sqrt()<c:
print("Yes")
else:
print("No")
| a, b, c = [int(n) for n in input().split()]
d = c-a-b
if d < 0:
print("No")
elif 4*a*b < d*d:
print("Yes")
else:
print("No")
#a + 2sqrt(ab) + b < c
#sqrt(4ab) < c-a-b
#4ab < d^2
| 1 | 51,682,306,038,832 | null | 197 | 197 |
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
A.sort()
A_max = A[-1]
dp = [1]*(A_max+1)
# dp[i] = 1: iはAのどの要素の倍数でもない
# dp[i] = 0: iはAの要素の倍数である
for a in A:
if not dp[a]:
continue
y = a*2
while y <= A_max:
dp[y] = 0
y += a
# Aの要素それぞれについて、dp[a] = 1ならよいが
# Aの要素ai,ajでai=ajとなる場合、上の篩では通過しているのに
# 条件を満たさない
cnt = dict(Counter(A))
ans = 0
for a in A:
if cnt[a] >= 2:
continue
if dp[a]:
ans += 1
print(ans) | def resolve():
n=int(input())
a=list(map(int,input().split()))
a.sort()
M=int(1e6+1)
f=[0]*M
for x in a:
if f[x]!=0:
f[x]+=1
continue
for nx in range(x,M,x):
f[nx]+=1
ans=0
for x in a:
if f[x]==1:ans+=1
print(ans)
resolve()
| 1 | 14,424,086,828,192 | null | 129 | 129 |
ans = 0
l,r,d = [int(x) for x in input().split()]
for i in range(l,r+1):
if i % d == 0:
ans = ans + 1
print(ans)
| L, R, d = map(int, input().split())
ans = list(map((lambda x: x % d == 0) , [i for i in range(L, R+1)])).count(True)
print(ans) | 1 | 7,528,770,603,808 | null | 104 | 104 |
n=int(input())
print(len(set([input() for _ in range(n)]))) | N=int(input())
print(len(set([input() for _ in range(N)]))) | 1 | 30,338,490,297,402 | null | 165 | 165 |
N = list(input())
num = 0
ans = 0
for i in range(len(N)-1, -1, -1):
n = int(N[i])
if n+num == 5 and i > 0 and int(N[i-1]) >= 5:
ans += 5
num = 1
elif n+num < 6:
ans += n+num
num = 0
else:
ans += 10-(n+num)
num = 1
ans += num
print(ans) | N=input()
dp0=[0]*(len(N)+1)
dp1=[0]*(len(N)+1)
dp1[0]=1
for i in range(len(N)):
n=int(N[i])
dp0[i+1]=min(dp0[i]+n, dp1[i]+(10-n))
n+=1
dp1[i+1]=min(dp0[i]+n, dp1[i]+(10-n))
#print(dp0)
#print(dp1)
print(dp0[-1])
| 1 | 71,125,338,955,580 | null | 219 | 219 |
s, t = map(str, input().split())
print(str(t)+str(s)) |
def resolve():
l, P = map(int, input().split())
S = input()
ans = 0
# 10^r: 2^r * 5^r の為、10と同じ素数
if P == 2 or P == 5:
for i, s in enumerate(S):
if int(s) % P == 0:
ans += i + 1
return print(ans)
cnts = [0] * P
cnts[0] = 1
num, d = 0, 1
for s in S[::-1]:
s = int(s)
num = (num + (s * d)) % P
d = (10 * d) % P
cnts[num] += 1
for cnt in cnts:
ans += cnt * (cnt - 1) // 2
print(ans)
if __name__ == "__main__":
resolve() | 0 | null | 80,997,928,923,252 | 248 | 205 |
count = 0
for i in input():
if i == '7':
count += 1
if count == 0:
print('No')
else:
print('Yes') | n = list(map(int,list(input())))
if 7 in n:
print("Yes")
else:
print("No")
| 1 | 34,369,003,564,000 | null | 172 | 172 |
a = []
while True:
m,n,o = input().split()
m=int(m)
o=int(o)
if n == "?":
break
if n=="+":
a.append(m+o)
elif n=="-":
a.append(m-o)
elif n=="*":
a.append(m*o)
elif n=="/":
a.append(int(m/o))
for i in a:
print(i) | # -*- coding: utf-8 -*-
loop = 1
while(loop):
l = list(input().strip().split())
a = int(l[0])
b = int(l[2])
op = l[1]
if(op == "?"):
loop = 0
break;
elif(op == "+"):
ret = a + b
elif(op == "-"):
ret = a - b
elif(op == "*"):
ret = a * b
elif(op == "/"):
ret = a / b
else:
continue
print(int(ret)) | 1 | 684,648,957,470 | null | 47 | 47 |
class Solver():
def __init__(self, A: [int]):
self.A = A
self.max_depth = len(A)
def solve(self, tgt):
self.tgt = tgt
self.history = (self.max_depth+1)*[4000 * [None]]
self.history = [[None for i in range(4000)] for x in range(self.max_depth + 1)]
if self._rec_solve(0, 0):
return 'yes'
else:
return 'no'
def _rec_solve(self, _sum, index):
if self.history[index][_sum] is not None:
return self.history[index][_sum]
if _sum == self.tgt:
self.history[index][_sum] = True
return True
if index >= self.max_depth or _sum > self.tgt:
self.history[index][_sum] = False
return False
self.history[index][_sum] = self._rec_solve(_sum + self.A[index], index + 1) or self._rec_solve(_sum, index + 1)
return self.history[index][_sum]
if __name__ == '__main__':
n = int(input())
A = [int(i) for i in input().rstrip().split()]
q = int(input())
m_ary = [int(i) for i in input().rstrip().split()]
s = Solver(A)
for val in m_ary:
print(s.solve(val)) | input()
A = [int(x) for x in input().split()]
input()
ms = [int(x) for x in input().split()]
enable_create = [False]*2000
for bit in range(1 << len(A)):
n = 0
for i in range(len(A)):
if 1 & (bit >> i) == 1:
n += A[i]
enable_create[n] = True
for m in ms:
print("yes" if enable_create[m] else "no") | 1 | 100,445,988,148 | null | 25 | 25 |
def main():
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse = True)
ans = A[0]
kazu = (N-2)//2
amari = (N-2)%2
for i in range(1,kazu+1,1):
#print(i)
ans += (A[i]*2)
if amari==1:
ans += A[i+1]*amari
print(ans)
main()
| #D - Chat in a Circle
N = int(input())
A = list(map(int,input().split()))
#ソート
arr = []
arr = sorted(A,reverse = True)
Friend_min_max_wa = 0
i =0
j = 0
for i in range(N -1):
if i % 2 != 0 : j = j + 1
Friend_min_max_wa = Friend_min_max_wa + arr[j]
# 出力
print(Friend_min_max_wa) | 1 | 9,174,440,466,642 | null | 111 | 111 |
n = int(input())
s = [input() for _ in range(n)]
uniq = set(s)
print(len(uniq)) | #!/usr/bin/env python3
import sys
input=sys.stdin.readline
mod=998244353
n,k=map(int,input().split())
arr=[list(map(int,input().split())) for i in range(k)]
dp=[0]*(n+1)
dp[1]=1
acum=[0]*(n+1)
for i in range(k):
l,r=arr[i]
if 1+l<=n:
acum[1+l]+=1
if 1+r+1<=n:
acum[1+r+1]-=1
for i in range(2,n+1):
acum[i]+=acum[i-1]
acum[i]%=mod
dp[i]=acum[i]
for j in range(k):
l,r=arr[j]
if i+l<=n:
acum[i+l]+=dp[i]
if i+r+1<=n:
acum[i+r+1]-=dp[i]
print(dp[n]%mod) | 0 | null | 16,484,531,759,538 | 165 | 74 |
kotae = [1,2,3]
A = int(input())
B = int(input())
kotae.remove(A)
kotae.remove(B)
print(kotae[0]) | class UnionFind:
def __init__(self, sz: int):
self._par: list[int] = [-1] * sz
def root(self, a: int):
if self._par[a] < 0:
return a
self._par[a] = self.root(self._par[a])
return self._par[a]
def size(self, a: int):
return -self._par[self.root(a)]
def unite(self, a, b):
a = self.root(a)
b = self.root(b)
if a != b:
if self.size(a) < self.size(b):
a, b = b, a
self._par[a] += self._par[b]
self._par[b] = a
if __name__ == '__main__':
N, M = map(int, input().split())
uf = UnionFind(N + 1)
for i in range(M):
a, b = map(int, input().split())
uf.unite(a, b)
ans = 1
for i in range(1, N + 1):
ans = max(ans, uf.size(i))
print(ans) | 0 | null | 57,090,812,748,870 | 254 | 84 |
n = int(input())
s = input()
ans = 0
for i in range(n-2):
if s[i] == 'A':
if s[i+1] == 'B':
if s[i+2] == 'C':
ans += 1
print(ans)
| import sys
from itertools import combinations
import math
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())
n = I()
s = S()
# print(s.count('ABC'))
ans = 0
for i in range(len(s)-2):
if s[i] == 'A' and s[i+1] == 'B' and s[i+2] == 'C':
ans += 1
print(ans)
| 1 | 99,692,454,627,570 | null | 245 | 245 |
mod = 998244353
N, S = map(int, input().split())
A = list(map(int, input().split()))
dp = [[0]*(S+1) for _ in range(N+1)]
dp[0][0] = 1
for i in range(1,N+1):
dp[i][0] = dp[i-1][0]*2%mod
for i in range(1,N+1):
for j in range(1,S+1):
dp[i][j] = dp[i-1][j]*2%mod
if j>=A[i-1]:
dp[i][j] += dp[i-1][j-A[i-1]]
ans = dp[-1][-1]%mod
print(ans) | while True:
L = map(int,raw_input().split())
H = (L[0])
W = (L[1])
if H == 0 and W == 0:break
for x in range(0,H):print "#" * W
print "" | 0 | null | 9,162,698,668,550 | 138 | 49 |
X = list(map(int, input().split()))
sum = X[0] + X[1] + X[2] + X[3] + X[4]
print(15 - sum)
| def main():
x=list(map(int,input().split()))
for i in range(5):
if x[i] == 0:
print(i+1)
main() | 1 | 13,551,943,101,038 | null | 126 | 126 |
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):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
n, m, k = map(int, input().split())
u = UnionFind(n + 1)
already = [0] * (n + 1)
for i in range(m):
a, b = map(int, input().split())
u.union(a, b)
already[a] += 1
already[b] += 1
for i in range(k):
c, d = map(int, input().split())
if u.same(c, d):
already[c] += 1
already[d] += 1
for i in range(1, n + 1):
print(u.size(i) - already[i] - 1)
| import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()
def resolve():
class UnionFind(object):
def __init__(self, n=1):
# 木の親要素を管理するリストparをつくります。
# par[x] == xの場合には、そのノードが根であることを示します。
# 初期状態では一切グループ化されていないので、すべてのノードが根になりますね。
self.par = [i for i in range(n)]
# 木の高さを持っておき、あとで低い方を高い方につなげる。初期状態は0
self.rank = [0 for _ in range(n)]
self.size = [1 for _ in range(n)]
def find(self, x):
"""
x が属するグループを探索:
ある2つの要素が属する木の根が同じかどうかをチェックすればよい。
つまり、親の親の親の・・・と根にたどり着くまで走査すればよい。
再帰。
"""
# 根ならその番号を返す
if self.par[x] == x:
return x
# 根でないなら、親の要素で再検索
else:
# 一度見た値については根に直接繋いで経路圧縮
# 親を書き換えるということ
self.par[x] = self.find(self.par[x])
return self.par[x]
def union(self, x, y):
"""
x と y のグループを結合
"""
# 根を探す
x = self.find(x)
y = self.find(y)
# 小さい木に結合して経路圧縮
if x != y:
if self.rank[x] < self.rank[y]:
x, y = y, x
# 同じ長さの場合rankが1増える
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
# 低い方の木の根を高い方の根とする
self.par[y] = x
self.size[x] += self.size[y]
def is_same(self, x, y):
"""
x と y が同じグループか否か
"""
return self.find(x) == self.find(y)
def get_size(self, x):
"""
x が属するグループの要素数
"""
x = self.find(x)
return self.size[x]
N,M,K=map(int,input().split())
uf = UnionFind(N) # ノード数Nでクラス継承
friends_cnt=[0]*N
for i in range(M):
# A,Bはノード
A, B = map(int, input().split())
A-=1
B-=1
friends_cnt[A]+=1
friends_cnt[B]+=1
# 連結クエリ union
uf.union(A, B)
blocks=[[] * N for i in range(N)]
for i in range(K):
x, y = map(int, input().split())
x, y = x - 1, y - 1
blocks[x].append(y)
blocks[y].append(x) # 有向ならコメントアウト
for i in range(N):
ans=uf.get_size(i)-friends_cnt[i]-1
for j in blocks[i]:
if uf.is_same(i,j):
ans-=1
print(ans,end=' ')
print()
resolve() | 1 | 61,699,667,465,470 | null | 209 | 209 |
import sys
sys.setrecursionlimit(10**7)
def input(): return sys.stdin.readline()[:-1]
mod = 10**9 + 7
def readInt():return int(input())
def readIntList():return list(map(int,input().split()))
def readStringList():return list(input())
def readStringListWithSpace():return list(input().split())
def readString():return input()
x = readInt()
print("Yes" if x >= 30 else "No") | now = int(input())
if now >= 30:
print('Yes')
else:
print('No')
| 1 | 5,724,243,921,692 | null | 95 | 95 |
K=input()
r='ACL'
for i in range(1,int(K)):
r='ACL'+ r
print(r) | #
# ACL_A
#
n = input()
n = int(n)
for i in range(n):
print("ACL", end='') | 1 | 2,180,266,501,302 | null | 69 | 69 |
N = int(input())
S = sorted([input() for x in range(N)])
word = [S[0]]+[""]*(N-1) #単語のリスト
kaisuu = [0]*N #単語の出た回数のリスト
k = 0 #今wordリストのどこを使っているか
for p in range(N): #wordとkaisuuのリスト作成
if word[k] != S[p]:
k += 1
word[k] = S[p]
kaisuu[k] += 1
else:
kaisuu[k] += 1
m = max(kaisuu) #m:出た回数が最大のもの
ansnum = [] #出た回数が最大のもののwordリストでの位置
for q in range(N):
if kaisuu[q] == m:
ansnum += [q]
for r in range(len(ansnum)):
print(word[ansnum[r]]) | N = int(input())
As = list(map(int,input().split()))
Q = int(input())
count_array = [0]*(10**5+1)
for i in range(N):
count_array[As[i]] += 1
sum = 0
for i in range(len(As)):
sum += As[i]
for i in range(Q):
x,y = map(int,input().split())
sum += count_array[x]*(y-x)
print(sum)
count_array[y] += count_array[x]
count_array[x] = 0
| 0 | null | 41,180,737,714,470 | 218 | 122 |
a, b, c, k = map(int, input().split())
if k <= a:
print(int(k))
elif k <= a + b:
print(int(a))
else:
print(int(2*a + b - k)) | n, k = map(int, input().split())
ans = 0
for i in range(k, n+2):
l = (i*(i-1))*0.5
h = (i*(2*n-i+1))*0.5
ans += (h-l+1)
print(int(ans) % (10**9+7)) | 0 | null | 27,591,594,891,238 | 148 | 170 |
def lotate(dic, dire):
if dire == 'N':
x,y,z,w = dic['up'], dic['back'], dic['bottom'], dic['front']
dic['back'], dic['bottom'], dic['front'], dic['up'] = x,y,z,w
elif dire == 'S':
x, y, z, w = dic['up'], dic['back'], dic['bottom'], dic['front']
dic['front'], dic['up'], dic['back'], dic['bottom'] = x, y, z, w
elif dire == 'W':
x, y, z, w = dic['up'], dic['left'], dic['bottom'], dic['right']
dic['left'], dic['bottom'], dic['right'], dic['up'] = x, y, z, w
elif dire == 'E':
x, y, z, w = dic['up'], dic['left'], dic['bottom'], dic['right']
dic['right'], dic['up'], dic['left'], dic['bottom'] = x, y, z, w
return dic
a,b,c,d,e,f = map(int, input().split())
n = int(input())
for _ in range(n):
dic = {'up': a, 'front': b, 'right': c, 'left': d, 'back': e, 'bottom': f}
x, y = map(int, input().split())
s = 'EEENEEENEEESEEESEEENEEEN'
for i in s:
if dic['up'] == x and dic['front'] == y:
print(dic['right'])
break
dic = lotate(dic, i)
| import sys
H, W, M = map(int, sys.stdin.readline().strip().split())
h = [0] * H
w = [0] * W
# g = [[False] * W for _ in range(H)]
S = set()
for _ in range(M):
Th, Tw = map(int, sys.stdin.readline().strip().split())
h[Th - 1] += 1
w[Tw - 1] += 1
# g[Th - 1][Tw - 1] = True
S.add((Th - 1, Tw - 1))
max_h = max(h)
max_w = max(w)
ans = max_h + max_w
index_h = [n for n, v in enumerate(h) if v == max_h]
index_w = [n for n, v in enumerate(w) if v == max_w]
sub = 1
# for ih in index_h:
# for iv in index_w:
# if g[ih][iv] is False:
# sub = 0
# break
# else:
# continue
# break
# ans -= sub
# print(ans)
for ih in index_h:
for iv in index_w:
if not (ih, iv) in S:
print(ans)
exit()
print(ans - 1)
| 0 | null | 2,501,267,167,162 | 34 | 89 |
n, m, q = map(int,input().split())
a, b, c, d = [0] * q, [0] * q, [0] * q, [0] * q
for i in range(q):
a[i], b[i], c[i], d[i] = map(int,input().split())
def score(l):
res = 0
for i in range(q):
temp = l[b[i] - 1] - l[a[i] - 1]
if temp == c[i]:res += d[i]
return res
def dfs(l):
global ans
if len(l) == n:
ans = max(ans, score(l))
return #中で使われている関数の終了
if l:
temp = l[-1]
else:
temp = 1
for v in range(temp, m + 1):
l.append(v)
dfs(l)
l.pop()
ans = 0
dfs([])
print(ans) | L = int(input())
x = L/3
print(x*x*x) | 0 | null | 37,401,964,443,856 | 160 | 191 |
import math
a,b = map(int,input().split())
c = a*b//math.gcd(a,b)
print(c) | def gcd(m,n):
x = max(m,n)
y = min(m,n)
while x%y != 0:
z = x%y
x = y
y = z
else:
return y
def lcm(m,n):
return int(m * n /gcd(m,n))
A,B = map( int ,input().split())
print(lcm(A,B)) | 1 | 113,600,692,889,920 | null | 256 | 256 |
import sys, math
from functools import lru_cache
from collections import deque
sys.setrecursionlimit(500000)
MOD = 10**9+7
def input():
return sys.stdin.readline()[:-1]
def mi():
return map(int, input().split())
def ii():
return int(input())
def i2(n):
tmp = [list(mi()) for i in range(n)]
return [list(i) for i in zip(*tmp)]
def solve(d):
if d == 1:
return ['a']
l = solve(d-1)
rsl = []
for w in l:
m = ord(max(w))
for i in range(ord('a'), m+2):
rsl.append(w+chr(i))
return rsl
def main():
print(*solve(ii()), sep='\n')
if __name__ == '__main__':
main() | N = int(input())
a_num = 97
def dfs(s, n, cnt): #s: 現在の文字列, n: 残りの文字数, cnt: 現在の文字列の最大の値
if n == 0:
print(s)
return
for i in range(cnt+2):
if i == cnt+1:
dfs(s+chr(a_num+i), n-1, cnt+1)
else:
dfs(s+chr(a_num+i), n-1, cnt)
dfs("a", N-1, 0) | 1 | 52,467,643,921,158 | null | 198 | 198 |
z=list(map(int,input().split()))
z.sort()
a=0
while True:
if z[1]==z[0]:
break
a=z[1]-z[0]
if z[0]%a==0:
z[1] = z[0]
z[0] = a
z.sort()
break
z[1]=z[0]
z[0]=a
z.sort()
print(z[0]) | N = int(input())
def powmod(x, y):
ret = 1
for _ in range(1, y+1):
ret = ret * x % (10**9+7)
return ret
ans = powmod(10, N) - powmod(9, N)*2 + powmod(8, N)
print(ans % (10**9+7)) | 0 | null | 1,589,950,302,280 | 11 | 78 |
sum = 0
for i in map(int,input().split()):
sum += i
print(15-sum) | from collections import *
n=int(input())
l=[]
for i in range(n):
l.append(input())
c=Counter(l)
m=max(c.values())
d=[]
for i in c:
if(c[i]==m):
d.append(i)
d.sort()
for i in d:
print(i)
| 0 | null | 41,529,072,232,284 | 126 | 218 |
def main():
N = int(input())
S = str(input())
ans = ''
alphabet = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
for i in range(len(S)):
c = alphabet.index(S[i]) + N
if c > 25:
c = c - 26
ans = ans + alphabet[c]
print(ans)
main() | n, m = map(int, input().split())
lis = sorted(list(map(int, input().split())), reverse=True)
limit = sum(lis) / (4 * m)
judge = 'Yes'
for i in range(m):
if lis[i] < limit:
judge = 'No'
break
print(judge) | 0 | null | 87,021,245,403,872 | 271 | 179 |
n = int(input())
a = list(map(int, input().split()))
a.sort()
if n % 2 == 0:
suma = 2*sum(a[-int((n/2)):])-a[-1]
else:
suma = 2*sum(a[-int(((n+1)/2)):])-a[-1]-a[-int(((n+1)/2))]
print(suma) | def main():
s = input()
if s.count('hi') == len(s) // 2 and len(s) % 2 == 0:
print('Yes')
else:
print('No')
if __name__ == '__main__':
main() | 0 | null | 31,101,690,599,420 | 111 | 199 |
n = input()
lst = list(map(int, input().split()))
print(min(lst), max(lst), sum(lst))
| n = input()
xi = map(int, raw_input().split())
print ("%d %d %d") %(min(xi), max(xi), sum(xi)) | 1 | 719,312,608,146 | null | 48 | 48 |
import itertools, math
N = int(input())
ls, L = [], 0
for i in range(N):
x, y = map(int, input().split(' '))
ls.append([x, y])
perms = itertools.permutations(range(N))
for perm in perms:
for i in range(N - 1):
L += math.sqrt((ls[perm[i + 1]][0] - ls[perm[i]][0]) ** 2 + (ls[perm[i + 1]][1] - ls[perm[i]][1]) ** 2)
print(L / math.factorial(N)) | import math
import itertools
# 与えられた数値の桁数と桁値の総和を計算する.
def calc_digit_sum(num):
digits = sums = 0
while num > 0:
digits += 1
sums += num % 10
num //= 10
return digits, sums
n = int(input())
distances = []
for _ in range(n):
points = list(map(int, input().split()))
distances.append(points)
total = 0
routes = list(itertools.permutations(range(n), n))
for route in routes:
distance = 0
for index in range(len(route)-1):
idx1 = route[index]
idx2 = route[index+1]
distance += math.sqrt((distances[idx1][0] - distances[idx2][0]) ** 2 + (distances[idx1][1] - distances[idx2][1]) ** 2)
total += distance
print(total / len(routes))
| 1 | 147,874,568,342,472 | null | 280 | 280 |
s = input()
a = [0] * (len(s)+1)
larger_count = 0
for i in range(len(s)):
if s[i] == '>':
larger_count += 1
continue
for j in range(larger_count+1):
a[i-j] = max(a[i-j], j)
larger_count = 0
a[i+1] = a[i] + 1
for j in range(larger_count+1):
a[len(a)-j-1] = max(a[len(a)-j-1], j)
print(sum(a)) | import sys
input = lambda: sys.stdin.readline().rstrip()
def main():
s = input()
ans, i, j = 0, 0, 0
while i < len(s):
if s[i] == '<':
j = 0
while i<len(s) and s[i] == '<':
ans += j
j += 1
i += 1
else:
k = 1
while i<len(s) and s[i] == '>':
ans += k
k += 1
i += 1
if j > k - 1:
ans = ans - (k - 1) + j
if s[-1] == '<':
ans += j
print(ans)
if __name__ == '__main__':
main() | 1 | 156,410,678,947,616 | null | 285 | 285 |
n = int(input())
robot = [0]*n
for i in range(n):
x,l = map(int,input().split())
robot[i] = (x+l, x-l)
robot.sort()
#print(robot)
ans = 1
right = robot[0][0]
for i in range(1,n):
if right <= robot[i][1]:
right = robot[i][0]
ans += 1
print(ans) | dates = [list(map(int, input().split())) for _ in range(2)]
print("{}".format("1" if dates[0][0] < dates[1][0] or (dates[0][0] == 12 and dates[0][1] == 1) else "0")) | 0 | null | 107,439,655,359,890 | 237 | 264 |
x, y, z = map(int, input().split())
y, x = x, y
z, x = x, z
print(x, y, z)
| xyz = list(map(int,input().split()))
print("{} {} {}".format(xyz[2],xyz[0],xyz[1])) | 1 | 37,891,261,153,064 | null | 178 | 178 |
from collections import defaultdict as d
from collections import deque
def bfs(adj, start, n):
visited = [0] * (n + 1)
tab = [0] * n
q = deque([start])
visited[start] = 1
while q:
s = q.popleft()
for i in adj[s]:
if visited[i] == 0:
q.append(i)
visited[i] = 1
tab[i - 1] = tab[s - 1] + 1
return tab
n, u, v = map(int, input().split())
adj = d(list)
for i in range(n - 1):
a, b = map(int, input().split())
adj[a].append(b)
adj[b].append(a)
takahashi = bfs(adj, u, n)
aoki = bfs(adj, v, n)
res = -1
for i in range(n):
if takahashi[i] <= aoki[i]:
res = max(res, aoki[i] - 1)
print(res) | x, y = map(int, input().split())
if y % 2 != 0:
print("No")
else:
if 2 * x <= y <= 4 * x:
print("Yes")
else:
print("No") | 0 | null | 65,787,875,278,806 | 259 | 127 |
H = int(input())
cnt = 0
res = 0
while H > 1:
H = H //2
cnt += 1
res += 2**cnt
print(res+1) | import math
def main():
R = int(input())
print(math.pi*2.0*R)
main()
| 0 | null | 55,889,012,038,720 | 228 | 167 |
def insert_sort():
n = int(input())
A = [int(x) for x in input().split()]
print(*A)
for i in range(1,n):
v = A[i]
j = i - 1
while j >= 0 and A[j] > v:
A[j+1] = A[j]
j -= 1
A[j+1] = v
print(*A)
if __name__ == "__main__":
insert_sort() | #! /usr/bin/env python
# -*- coding : utf-8 -*-
input()
seq = [int(x) for x in input().split()]
for i in range(0, len(seq)):
key = seq[i]
j = i - 1
assert isinstance(i, int)
while j >= 0 and seq[j] > key:
seq[j + 1] = seq[j]
j -= 1
seq[j + 1] = key
print(' '.join(map(str,seq))) | 1 | 5,289,743,620 | null | 10 | 10 |
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))
n,t = mi()
data = []
for i in range(n):
data.append(li())
data.sort()
dp = [[0]*t for i in range(n+1)]
for i in range(n):
for k in range(t):
dp[i+1][k] = max(dp[i+1][k],dp[i][k])
if k + data[i][0] <= t-1:
dp[i+1][k+data[i][0]] = max(dp[i+1][k+data[i][0]],dp[i][k] + data[i][1])
ans = 0
for i in range(n):
ans = max(ans,dp[i][t-1] + data[i][1])
print(ans)
| def main():
N = int(input())
count = 0
for a in range(N) :
a += 1
for b in range(N):
b += 1
c = N - a * b
if c <= 0 :
break
else :
count += 1
print(count)
if __name__ == '__main__':
main()
| 0 | null | 77,206,701,481,158 | 282 | 73 |
n, m = map(int, input().split())
a =[[0 for i in range(m)]for j in range(n)]
for i in range(n):
a[i] = list(map(int, input().split()))
b = [0 for j in range(m)]
for j in range(m):
b[j] = int(input())
c = [0 for i in range(n)]
for i in range(n):
for j in range(m):
c[i] += a[i][j] * b[j]
print(c[i]) | n,m = map(int,input().split())
a = []
b = []
c = []
for i in range(n):
a.append([int(j) for j in input().split()])
for k in range(m):
b.append(int(input()))
for x in range(n):
z = 0
for y in range(m):
z += a[x][y] * b[y]
c.append(z)
for i in c:
print(i)
| 1 | 1,150,822,840,890 | null | 56 | 56 |
N = int(input())
import math
ans = []
for i in range(1,round((N-1)**0.5)+1):
if (N-1)%i == 0:
ans.append(i)
if (N-1)//i != i:
ans.append((N-1)//i)
ans.remove(1)
ans.append(N)
for i in range(2,round(N**0.5)+1):
if N%i == 0:
n = N
while n%i==0:
n//=i
if n%i==1:
ans.append(i)
print(len(ans))
| n,m,k=map(int,raw_input().split())
a=map(int,raw_input().split())
b=map(int,raw_input().split())
cnt1=0
cnt2=0
a1=[0]
b1=[0]
for i in range(n):
a1.append(a1[-1]+a[i])
for i in range(m):
b1.append(b1[-1]+b[i])
ans=0
j=m
for i in range(n+1):
if a1[i]>k:
break
while b1[j]>k-a1[i]:
j-=1
ans=max(ans,i+j)
print ans | 0 | null | 26,083,743,705,000 | 183 | 117 |
N = int(input())
P = list(map(int,input().split()))
count = 1
minP = P[0]
for i in range(1,N):
if minP > P[i]:
count += 1
minP = min(minP,P[i])
print(count) | #!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
????????????
"""
inp = input().strip().split(" ")
n = int(inp[0])
m = int(inp[1])
l = int(inp[2])
# ?????????????????????????¢????
# A[n][m] B[m][l] C[n][l]
A = [[0 for i in range(m)] for j in range(n)]
B = [[0 for i in range(l)] for j in range(m)]
C = [[0 for i in range(l)] for j in range(n)]
# A???????????°??????????????????
for i in range(n):
inp = input().strip().split(" ")
for j in range(m):
A[i][j] = int(inp[j])
# B???????????°??????????????????
for i in range(m):
inp = input().strip().split(" ")
for j in range(l):
B[i][j] = int(inp[j])
# A x B
for i in range(n):
for j in range(l):
for k in range(m):
C[i][j] += A[i][k] * B[k][j]
print(" ".join(map(str,C[i]))) | 0 | null | 43,439,094,433,010 | 233 | 60 |
S,T = input().split()
a = T + S
print(a) | _ = input()
a = list(map(int, input().split()))
count = 0
for i in range(len(a)):
minj = i
for j in range(i+1, len(a)):
#print('taiget {} in list {}'.format(a[i], a[j:]))
if a[j] < a[minj]:
minj = j
#print('change[{}] to [{}]'.format(a[i], a[minj]))
if a[i] != a[minj]:
a[i], a[minj] = a[minj], a[i]
count += 1
print(' '.join(map(str, a)))
print(count)
| 0 | null | 51,236,323,663,710 | 248 | 15 |
N = int(input())
S = str(input())
count = 1
for i in range(N-1):
if S[i]!=S[i+1]:
count += 1
print(count) | # https://atcoder.jp/contests/abc165/tasks/abc165_c
from itertools import combinations_with_replacement
N, M, Q = map(int, input().split())
data = []
for _ in range(Q):
data.append(list(map(int, input().split())))
res = []
for A in combinations_with_replacement(range(1,M+1), N):
score = 0
for i in range(Q):
a,b,c,d = data[i]
if A[b-1] - A[a-1] == c:
score += d
res.append(score)
print(max(res)) | 0 | null | 98,837,058,541,442 | 293 | 160 |
N = int(input())
a = [int(i) for i in input().split()]
frag = 1
i = 0
count = 0
while frag:
frag = 0
for j in range(N-1,i,-1):
if a[j] < a[j-1]:
a[j], a[j-1] = a[j-1], a[j]
count += 1
frag = 1
i += 1
print(" ".join(map(str, a)))
print(count) | numberOfArray=int(input())
arrayList=list(map(int,input().split()))
def bubbleSort():
frag=1
count=0
while frag:
frag=0
for i in range(1,numberOfArray):
if arrayList[i-1]>arrayList[i]:
arrayList[i-1],arrayList[i]=arrayList[i],arrayList[i-1]
frag=1
count+=1
arrayForReturn=str(arrayList[0])
for i2 in range(1,numberOfArray):
arrayForReturn+=" "+str(arrayList[i2])
print(arrayForReturn)
print(count)
#------------------main--------------
bubbleSort()
| 1 | 16,230,104,282 | null | 14 | 14 |
A, B = map(int, input().split())
print(A * B) if len(str(A)) == 1 and len(str(B)) == 1 else print(-1) | a, b = list(map(int, input().split(' ')))
print(a * b if a < 10 and b < 10 else -1) | 1 | 157,962,433,890,980 | null | 286 | 286 |
import sys
from collections import deque, defaultdict, Counter
from itertools import accumulate, product, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right
from heapq import heappop, heappush
from math import ceil, floor, sqrt, gcd, inf
from copy import deepcopy
import numpy as np
import scipy as sp
INF = inf
MOD = 1000000007
k = int(input())
s = input()
tmp = 0
res = 0
if len(s) <= k:
res = s
else:
res = s[:k] + "..."
print(res)
| Sum = input().split()
cou = 1
while len(Sum) != 1 :
cou += 1
if Sum[cou] == '+' :
del Sum[cou]
Sum.insert((cou - 2) ,int(Sum.pop(cou - 2)) + int(Sum.pop(cou - 2)))
cou -= 2
elif Sum[cou] == '-' :
del Sum[cou]
Sum.insert((cou - 2) ,int(Sum.pop(cou - 2)) - int(Sum.pop(cou - 2)))
cou -= 2
elif Sum[cou] == '*' :
del Sum[cou]
Sum.insert((cou - 2) ,int(Sum.pop(cou - 2)) * int(Sum.pop(cou - 2)))
cou -= 2
print(Sum[0]) | 0 | null | 9,884,719,443,868 | 143 | 18 |
i = list(map(int, input().split()))
print(i[0]*i[1]) | number = list(map(int, input().split()))
print(number[0]*number[1]) | 1 | 15,887,503,700,892 | null | 133 | 133 |
import math
r=input()
print "%.9f"%(math.pi*r*r), math.pi*r*2 | import collections
def prime_factorize(n):
a = []
while n % 2 == 0:
a.append(2)
n //= 2
f = 3
while f * f <= n:
if n % f == 0:
a.append(f)
n //= f
else:
f += 2
if n != 1:
a.append(n)
return a
N=int(input())
D = collections.Counter(prime_factorize(N))
A=0
for d in D:
e=D[d]
for i in range(40):
if (i+1)*(i+2)>2*e:
A=A+i
break
print(A) | 0 | null | 8,825,387,237,660 | 46 | 136 |
# C - Guess The Number
N, M = map(int, input().split())
SC = [list(map(int, input().split())) for _ in range(M)]
ans = [0,0,0]
# 条件だけで不適がわかるものは弾く
for i in range(M):
for j in range(i+1,M):
if (SC[i][0] == SC[j][0]) and (SC[i][1] != SC[j][1]):
print(-1)
quit()
# 各桁を指定をする
for k in range(M):
ans[SC[k][0]-(N-2)] = str(SC[k][1])
# 頭の桁が0で指定されると不適(str型かどうかで判定する)
if (ans[3-N] == "0") and (N == 1):
print(0)
quit()
elif ans[3-N] == "0":
print(-1)
quit()
# N桁の文字列にする
ans = [str(ans[i]) for i in range(3)]
res = "".join(ans)
res = res[(3-N):4]
# 頭の桁が指定無しの0だったら1に変える
if (res[0] == "0") and (N == 1):
res = "0"
elif res[0] == "0":
ref = list(res)
ref[0] = "1"
res = "".join(ref)
print(res)
| # 入出力から得点を計算する
import sys
input = lambda: sys.stdin.readline().rstrip()
D = int(input())
c = list(map(int, input().split()))
s = [[int(i) for i in input().split()] for _ in range(D)]
t = []
for i in range(D):
tmp = int(input())
t.append(tmp)
# 得点
result = 0
# 最後に開催された日を保存しておく
last_day = [0 for _ in range(26)]
for i in range(len(t)):
# 選んだコンテスト
choose = t[i] - 1
# 最終開催日を更新
last_day[choose] = i + 1
# そのコンテストを選んだ時の本来のポイント
result += s[i][choose]
# そこから満足度低下分をマイナス
for j in range(26):
result -= c[j] * ((i+1) - last_day[j])
# result += tmp_point
print(result)
# print(c,s,t)
| 0 | null | 35,488,872,007,872 | 208 | 114 |
def resolve():
S, T = input().split()
A, B = list(map(int, input().split()))
U = input()
if S == U:
A -= 1
else:
B -= 1
print(A, B)
if '__main__' == __name__:
resolve() | s,t,a,b,u=open(0).read().split()
if s==u:
print(int(a)-1,b)
elif t==u:
print(a,int(b)-1) | 1 | 71,903,408,313,360 | null | 220 | 220 |
while True:
try:
m,f,r = map(int,input().split(" "))
if m == -1:
if f == -1:
if r == -1:
break
if m == -1 or f == -1:
print("F")
continue
if m+f >= 80:
print("A")
if m+f >= 65 and m+f < 80:
print("B")
if m+f >= 50 and m+f < 65:
print("C")
if m+f >= 30 and m+f < 50:
if r >= 50:
print("C")
else:
print("D")
if m+f < 30:
print("F")
except EOFError:
break | import sys
while True:
n = sys.stdin.readline()[:-1]
if n == '-1 -1 -1':
break
marks = [ int(m) for m in n.split() ]
mt_points,retest = marks[0] + marks[1],marks[2]
if -1 in marks[:-1]:
print('F')
continue
elif mt_points >= 80:
print('A')
continue
elif mt_points >= 65 and 80 > mt_points:
print('B')
continue
elif mt_points >= 50 and 65 > mt_points:
print('C')
continue
elif mt_points >= 30 and 50 > mt_points:
if retest >= 50:
print('C')
continue
print('D')
continue
elif 30 > mt_points:
print('F')
| 1 | 1,211,025,802,680 | null | 57 | 57 |
import math
N = int(input())
A = list(map(int,input().split()))
B = [0] * (N)
lcmall = A[0]
for i in range(1,N):
gcdall = math.gcd(lcmall,A[i])
lcmall = lcmall*A[i] // gcdall
sum = 0
for i in range(N):
B[i] =int(lcmall // A[i])
sum += B[i]
print(sum % (10 ** 9 + 7)) | import sys
sys.setrecursionlimit(10000000)
input=sys.stdin.readline
n = int(input())
a = list(map(int,input().split()))
def gcd(a, b):
return a if b == 0 else gcd(b, a%b)
def lcm(a, b):
return a // gcd(a, b) * b
mod = 10**9+7
x=a[0]
for i in a[1:]:
x=lcm(x,i)
ans=0
for i in range(n):
ans+= x//a[i]
print(ans%mod)
| 1 | 87,537,398,654,930 | null | 235 | 235 |
d = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(d)]
t = []
for _ in range(d):
t.append(int(input()))
cl = sum(c)
D = [0]*26
sas = 0
for i in range(d):
for j in range(26):
D[j] += 1
T = t[i]
S = s[i][T-1]
C = c[T-1]
D[T-1] = 0
dc = 0
for j in range(26):
dc += D[j]*c[j]
sas += S - dc
print(sas) | d = int(input())
c = list(map(int,input().split()))
s = []
for i in range(d):
si = list(map(int,input().split()))
s.append(si)
lastd = [-1 for _ in range(26)]
ans = 0
for i in range(d):
di = int(input())
lastd[di-1] = i
ans += s[i][di-1]
for j in range(26):
ans -= (i-lastd[j])*c[j]
print(ans) | 1 | 9,949,651,977,814 | null | 114 | 114 |
import numpy as np
n = int(input())
st = [input().split() for _ in range(n)]
x = input()
s, t = zip(*st)
i = s.index(x)
print(sum(map(int, t[i+1:])))
| N,K = map(int,input().split())
R,S,P = map(int,input().split())
T = input()
V = {"s":R, "p":S, "r":P}
ans = 0
for i in range(K):
check = T[i]
ans += V[T[i]]
while True:
i += K
if i >= N:
break
if check == T[i]:
check = -1
else:
ans += V[T[i]]
check = T[i]
print(ans) | 0 | null | 101,645,058,109,842 | 243 | 251 |
def main():
while True:
m, f, r = tuple(map(int, input().split()))
if m == f == r == -1:
break
elif m == -1 or f == -1:
print('F')
elif m + f >= 80:
print('A')
elif m + f >= 65:
print('B')
elif m + f >= 50:
print('C')
elif m + f >= 30:
if r >= 50:
print('C')
else:
print('D')
else:
print('F')
if __name__ == '__main__':
main()
| import math
from functools import reduce
def lcm_base(x, y):
return (x * y) // math.gcd(x, y)
def lcm_list(numbers):
return reduce(lcm_base, numbers, 1)
N = int(input())
A = list(map(int,input().split()))
ans = 0
lcm = lcm_list(A)
for i in range(N):
ans += lcm//A[i]
print(ans%1000000007) | 0 | null | 44,465,714,211,712 | 57 | 235 |
N, D, A = map(int, input().split())
monster = []
for k in range(N):
monster.append(list(map(int, input().split())))
monster.sort(key = lambda x: x[0])
for k in range(N):
monster[k][1] = int((monster[k][1]-0.1)//A + 1)
ans = 0
final = monster[-1][0]
ruiseki = 0
minuslist = []
j = 0
for k in range(N):
while (j < len(minuslist)):
if monster[k][0] >= minuslist[j][0]:
ruiseki -= minuslist[j][1]
j += 1
else:
break
if ruiseki < monster[k][1]:
ans += monster[k][1] - ruiseki
if monster[k][0] + 2*D +1 <= final:
minuslist.append([monster[k][0]+2*D+1, monster[k][1] - ruiseki])
ruiseki = monster[k][1]
print(ans)
| N, S = map(int, input().split())
As = list(map(int, input().split()))
P = 998244353
memo = [[0 for _ in range(N+1)] for _ in range(S+1)]
for i in range(N+1):
memo[0][i] = (2**i) % P
for i, a in enumerate(As):
for j in range(S+1):
if j - a < 0:
memo[j][i+1] = memo[j][i]*2 % P
else:
memo[j][i+1] = (memo[j][i]*2 + memo[j-a][i]) % P
print(memo[S][N]) | 0 | null | 50,211,582,394,232 | 230 | 138 |
class card:
def __init__(self,cv):
c = cv[0:1]
v = int(cv[1:2])
self.c = c
self.v = v
def self_str(self):
q = str(str(self.c) + str(self.v))
return q
n = int(input())
a = list(map(card, input().split()))
b = a[:]
c = a[:]
for i in range(n):
for j in range(n-1, i, -1):
if b[j].v < b[j-1].v:
b[j], b[j-1] = b[j-1],b[j]
print(" ".join(x.self_str() for x in b))
coua = ["" for i in range(10)]
coub = ["" for i in range(10)]
conb = ""
for i in range(n):
for j in range(n):
if i != j:
if a[i].v == a[j].v:
coua[a[i].v] += a[i].c
if b[i].v == b[j].v:
coub[b[i].v] += b[i].c
if coua == coub:
conb = "Stable"
else:
conb = "Not stable"
print(conb)
for i in range(n):
mini = i
for j in range(i, n):
if c[j].v < c[mini].v:
mini = j
c[mini], c[i] = c[i], c[mini]
print(" ".join(x.self_str() for x in c))
couc = ["" for i in range(10)]
conc = ""
for i in range(n):
for j in range(n):
if i != j:
if c[i].v == c[j].v:
couc[c[i].v] += c[i].c
if coua == couc:
conc = "Stable"
else:
conc = "Not stable"
print(conc) | 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 = mid
print(OK)
| 0 | null | 3,278,415,951,020 | 16 | 99 |
n,m=map(int,input().split())
a=[[0,0] for _ in range(n+1)]
x=[]
for i in range(m):
x.append(list(input().split()))
x[i][0]=int(x[i][0])
for i in range(m):
if x[i][1]=="AC":
a[x[i][0]][1]=1
else:
if a[x[i][0]][1]==1:
continue
else:
a[x[i][0]][0]+=1
c=0
d=0
for i in range(n+1):
c+=a[i][1]
if a[i][1]:
d+=a[i][0]
print(c,d) | from collections import deque
n,u,v=map(int,input().split())
g=[set([]) for _ in range(n+1)]
for i in range(n-1):
a,b=map(int,input().split())
g[a].add(b)
g[b].add(a)
leaf=[]
for i in range(1,n+1):
if(len(g[i])==1):
leaf.append(i)
d_u=[-1 for _ in range(n+1)]
d_v=[-1 for _ in range(n+1)]
def bfs(start,d):
d[start]=0
q=deque([start])
while(len(q)>0):
qi=q.popleft()
di=d[qi]
next_qi=g[qi]
for i in next_qi:
if(d[i]==-1):
d[i]=di+1
q.append(i)
return d
d_u=bfs(u, d_u)
d_v=bfs(v, d_v)
if(u in leaf and list(g[u])[0]==v):
print(0)
else:
ans=0
for li in leaf:
if(d_u[li]<d_v[li]):
ans=max(ans,d_v[li]-1)
print(ans)
| 0 | null | 105,159,187,126,314 | 240 | 259 |
# -*- coding: utf-8 -*-
def insertionSort(A, n, g):
global cnt
for i in range(g, n):
v = A[i]
j = i - g
while j >= 0 and A[j] > v:
A[j+g] = A[j]
j -= g
cnt += 1
A[j+g] = v
def shellSort(A, n):
def func(m):
if m == 0:
return 1
else:
return func(m-1)*3 + 1
G = []
i = 0
while True:
gi = func(i)
if gi <= n:
G.append(gi)
i += 1
else:
break
G = G[::-1]
for g in G:
insertionSort(A, n , g)
return A, G
if __name__ == '__main__':
n = int(input())
A = [int(input()) for i in range(n)]
cnt = 0
A, G = shellSort(A, n)
print(len(G))
print(" ".join(map(str, G)))
print(cnt)
for i in range(n):
print(A[i])
| #coding:utf-8
from copy import deepcopy
n = int(input())
A = list(input().split())
B = deepcopy(A)
def BubbleSort(A,N):
for i in range(N):
for j in range(N-1,i,-1):
if A[j][1] < A[j-1][1]:
A[j], A[j-1] = A[j-1], A[j]
def SelectionSort(A,N):
for i in range(N):
minj = i
for j in range(i,N):
if A[j][1] < A[minj][1]:
minj = j
A[i], A[minj] = A[minj], A[i]
BubbleSort(A,n)
SelectionSort(B,n)
A = " ".join([data for data in A])
B = " ".join([data for data in B])
print(A)
print("Stable")
print(B)
if A == B:
print("Stable")
else:
print("Not stable")
| 0 | null | 27,485,584,918 | 17 | 16 |
n, m = map(int, input().split())
a = list(map(int, input().split()))
dp = [float('inf') for _ in range(n+1)]
dp[0] = 0
for i in range(n):
for money in a:
next_money = i + money
if next_money > n:
continue
dp[next_money] = min(dp[i] + 1, dp[next_money])
print(dp[n])
| # -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: print('Yes' if b else 'No')
YESNO=lambda b: print('YES' if b else 'NO')
def main():
N,M=map(int,input().split())
c=list(map(int,input().split()))
dp=[[INF]*10**6 for _ in range(M+1)]
dp[0][0]=0
ans=INF
for i in range(M):
for money in range(N+1):
dp[i+1][money]=min(dp[i+1][money],dp[i][money])
if money-c[i]>=0:
dp[i+1][money]=min(dp[i+1][money],dp[i][money-c[i]]+1,dp[i+1][money-c[i]]+1)
print(dp[M][N])
if __name__ == '__main__':
main()
| 1 | 139,122,650,800 | null | 28 | 28 |
a = list(reversed(sorted([int(raw_input()) for _ in range(10)])))
print a[0]
print a[1]
print a[2] | i = 0
x = []
for i in range(10):
mount = int(input())
x.append(mount)
sorted_x = sorted(x)
print(sorted_x[-1])
print(sorted_x[-2])
print(sorted_x[-3])
| 1 | 29,469,242 | null | 2 | 2 |
# -*- coding: utf-8 -*-
def check(r,g,b):
if g > r and b > g:
return True
else:
return False
A,B,C = map(int, input().split())
K = int(input())
for i in range(K+1):
for j in range(K+1-i):
for k in range(K+1-i-j):
if i+j+k==0:
continue
r = A*(2**i)
g = B*(2**j)
b = C*(2**k)
if check(r, g, b):
print("Yes")
exit()
print("No")
| # -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=2019
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1
def main():
N,P=map(int,input().split())
A=list(map(int,list(input())[::-1]))
ans=0
if P==2 or P==5:
if P==2:
s=set([i*2 for i in range(5)])
else:
s=set([i*5 for i in range(2)])
for i,x in enumerate(A[::-1],1):
if x in s:
ans+=i
else:
S=[0]*(N+1)
for i in range(N):
S[i+1]=(S[i]+A[i]*pow(10,i,P))%P
l=[0]*P
for i in range(N+1):
ans+=l[S[i]]
l[S[i]]+=1
print(ans)
if __name__ == '__main__':
main()
| 0 | null | 32,341,367,208,756 | 101 | 205 |
import math
def insertion_sort(alist, step):
size = len(alist)
count = 0
for i in range(step, size):
v = alist[i]
j = i - step
while j >= 0 and alist[j] > v:
alist[j+step] = alist[j]
j -= step
count += 1
alist[j+step] = v
return (count, alist)
def shell_sort(alist, steps):
total_count = 0
sorted_list = alist
for step in steps:
(count, sorted_list) = insertion_sort(sorted_list, step)
total_count += count
return (total_count, sorted_list)
def run():
n = int(input())
nums = []
for i in range(n):
nums.append(int(input()))
steps = create_steps(n)
(cnt, nums) = shell_sort(nums, steps)
print(len(steps))
print(" ".join([str(s) for s in steps]))
print(cnt)
for n in nums:
print(n)
def create_steps(n):
steps = []
k = 1
while True:
steps = [k] + steps
k = 2 * k + int(math.sqrt(k)) + 1
if k >= n:
break
return steps
if __name__ == '__main__':
run()
| a, b = map(int, raw_input().split())
if a < b:
print('a < b')
elif b < a:
print('a > b')
else:
print('a == b') | 0 | null | 192,768,761,712 | 17 | 38 |
import sys
input = sys.stdin.readline
def main():
N, K, S = map(int, input().split())
if S == 10**9:
ans = [S] * K + [1] * (N-K)
else:
ans = [S] * K + [10**9] * (N-K)
print(*ans)
if __name__ == "__main__":
main()
| N, K = map(int, input().split())
ls1 = list(map(int, input().split()))
d = dict()
ls2 = ['r', 's', 'p']
for x, y in zip(ls1, ls2):
d[y] = x
T = input()
S = T.translate(str.maketrans({'r': 'p', 's': 'r', 'p': 's'}))
ans = 0
for i in range(K):
cur = ''
for j in range(i, N, K):
if cur != S[j]:
ans += d[S[j]]
cur = S[j]
else:
cur = ''
print(ans) | 0 | null | 99,180,261,769,590 | 238 | 251 |
N, K = map(int, input().split())
R, S, P = map(int, input().split())
dic = {'r':P, 's':R, 'p':S}
flag = [0]*N
rlt = 0
T = input()
for i in range(N):
if i < K or T[i] != T[i-K] or flag[i-K] == 1:
rlt += dic[T[i]]
else:
flag[i] = 1
print(rlt) | n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()
flag = [False for i in range(n)]
score = {"r":p, "s":r, "p":s}
ans = 0
for i in range(n):
if i >= k:
if t[i] == t[i-k]:
if flag[i-k] == True:
ans += score[t[i]]
else:
flag[i] = True
else:
ans += score[t[i]]
else:
ans += score[t[i]]
print(ans) | 1 | 106,727,154,781,908 | null | 251 | 251 |
n,s=map(int,input().split())
a=list(map(int,input().split()))
mod=998244353
dp=[[0 for i in range(s+1)] for j in range(n+1)]
dp[0][0]=1
for i in range(1,n+1):
see=a[i-1]
for j in range(s+1):
dp[i][j]=dp[i-1][j]*2
dp[i][j]%=mod
if see>j:
continue
dp[i][j]+=dp[i-1][j-see]
dp[i][j]%=mod
print(dp[-1][-1])
| mod = 998244353
N, S, *A = map(int, open(0).read().split())
dp = [1] + [0] * S
for i, a in enumerate(A, 1):
dp = [(2 * dp[j] + (dp[j - a] if j >= a else 0)) % mod for j in range(S + 1)]
print(dp[S]) | 1 | 17,586,973,739,510 | null | 138 | 138 |
A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())
d = abs(A-B)
if d-(V-W)*T<=0:
print("YES")
else:
print("NO") | A = raw_input().split()
S = []
for x in A:
if x in ['+', '-', '*']:
b = int(S.pop())
a = int(S.pop())
if x == '+':
S.append(a + b)
elif x == '-':
S.append(a - b)
else:
S.append(a * b)
else:
S.append(x)
print S.pop() | 0 | null | 7,538,407,835,530 | 131 | 18 |
N = int(input())
ans = []
while N > 0:
N -= 1
a = N%26
ans.append(chr(97+a))
N = N//26
#print(ans)
ret = ""
for i in range(len(ans)):
ret += ans[-1-i]
#print(ret)
print(ret) | import math
N = int(input())
digit = math.ceil(math.log((25 * N / 26 + 1), 26))
alphabet = list("abcdefghijklmnopqrstuvwxyz")
name = []
for i in range(digit):
name.append((N % 26 - 1) % 26)
N = (N - (N % 26 - 1) % 26) // 26
name.reverse()
print("".join([alphabet[s] for s in name]))
| 1 | 11,794,746,566,302 | null | 121 | 121 |
INFTY = 10 ** 10
import queue
def bfs(s):
q = queue.Queue()
q.put(s)
d = [INFTY] * n
d[s] = 0
while not q.empty():
u = q.get()
for v in range(n):
if M[u][v] == 0:
continue
if d[v] != INFTY:
continue
d[v] = d[u] + 1
q.put(v)
for i in range(n):
if d[i] == INFTY:
print(i+1, -1)
else:
print(i+1, d[i])
n = int(input())
M = [[0] * n for _ in range(n)]
for i in range(n):
nums = list(map(int, input().split()))
u = nums[0] - 1
k = nums[1]
for j in range(k):
v = nums[j+2] - 1
M[u][v] = 1
bfs(0)
| from collections import deque
n=int(input())
edge=[[] for _ in range(n+1)]
for i in range(n):
v,k,*u=map(int,input().split())
edge[v]=u
p=[-1]*(n+1)
p[1]=0
q=deque([])
q.append(1)
v=[1]*(n+1)
v[1]=0
while q:
now=q.popleft()
for i in edge[now]:
if v[i]:
q.append(i)
p[i]=p[now]+1
v[i]=0
for i in range(1,n+1):
print(i,p[i])
| 1 | 4,679,846,370 | null | 9 | 9 |
import sys
def input():
return sys.stdin.readline()[:-1]
N,D,A=map(int,input().split())
s=[tuple(map(int, input().split())) for i in range(N)]
s.sort()
d=2*D+1
t=0
p=0
l=[0]*N
a=0
for n,i in enumerate(s):
while 1:
if t<N and s[t][0]<i[0]+d:
t+=1
else:
break
h=i[1]-p*A
if h>0:
k=-(-h//A)
a+=k
p+=k
l[t-1]+=k
p-=l[n]
print(a) | import sys
import bisect
from math import ceil
from itertools import accumulate
n, d, a = [int(i) for i in sys.stdin.readline().split()]
monsters = []
max_x = 0
for i in range(n):
x, h = [int(i) for i in sys.stdin.readline().split()]
max_x = max(x, max_x)
monsters.append([x, h])
monsters.sort(key=lambda x:x[0])
x, h = zip(*monsters)
x_ls = []
for i, (_x, _h) in enumerate(zip(x, h)):
ind = bisect.bisect_right(x, _x + 2 * d)
x_ls.append([i, ind, _h])
h = list(h) + [0]
ls = [0 for i in range(n+1)]
cur = 0
res = 0
for i, ind, _h in x_ls:
if h[i] > 0:
cur -= ls[i]
h[i] -= cur
if h[i] > 0:
hoge = ceil(h[i] / a)
res += hoge
cur += hoge * a
ls[ind] += hoge * a
print(res)
| 1 | 82,359,568,826,440 | null | 230 | 230 |
import queue
N = int(input())
def common_divisors(n):
i = 1
res = []
while i*i <= n:
if n % i == 0:
res.append(i)
res.append(n//i)
if i*i == n:
res.pop()
i += 1
return res
ans = 0
ans += len(common_divisors(N-1))-1
for i in common_divisors(N):
if i == 1:
continue
n = N
while n % i == 0:
n /= i
if n % i == 1:
ans += 1
print(ans)
| from collections import deque
inf=10**9
def BFS(num):
color=["white" for _ in range(n+1)]
D=[inf for _ in range(n+1)]
queue=deque([num])
color[num]="gray"
D[num]=0
while len(queue)>0:
u=queue.popleft()
for i in M[u]:
if color[i]=="white" and D[u]+1<D[i]:
D[i]=D[u]+1
color[i]="gray"
queue.append(i)
color[u]="black"
return D
n,x,y=map(int,input().split())
M=[[] for _ in range(n+1)]
for i in range(1,n):
M[i].append(i+1)
M[i+1].append(i)
M[x].append(y)
M[y].append(x)
ans=[0 for _ in range(n-1)]
for i in range(1,n+1):
for j in BFS(i)[i+1:]:
ans[j-1] +=1
for i in ans:
print(i) | 0 | null | 42,800,350,936,982 | 183 | 187 |
import sys
#input = sys.stdin.buffer.readline
def main():
S = input()
print(S[:3])
if __name__ == "__main__":
main() | from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce, lru_cache # @lru_cache(None)
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**6)
# ----------------------------------------------------------- #
s = input()
print(s[:3]) | 1 | 14,751,195,714,960 | null | 130 | 130 |
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() | S = input()
K = int(input())
N = len(S)
bef = ""
start = 0
l = []
for i, s in enumerate(S):
if bef=="":
start = i
elif bef!=s:
l.append(i-start)
start = i
bef = s
l.append(i-start+1)
if len(set(S))==1:
print((N*K)//2)
else:
if S[0]==S[-1]:
ans = (l[0]//2)+(l[-1]//2)+((l[0]+l[-1])//2)*(K-1)
else:
ans = (l[0]//2)*K+(l[-1]//2)*K
for i in l[1:-1]:
ans += (i//2)*K
print(ans)
| 0 | null | 132,406,374,139,082 | 237 | 296 |
import math
char = str(input())
char = char.replace('?','D')
print(char)
| t = list(input())
t.reverse()
tmptmp = "P"
for i in range(len(t)):
if i == 0:
tmp = t[i]
continue
if tmp == "?" and tmptmp != "D":
t[i-1] = "D"
elif tmp == "?" and tmptmp == "D" and t[i] != "D":
t[i-1] = "D"
elif tmp == "?" and tmptmp == "D" and t[i] == "D":
t[i-1] = "P"
tmptmp = t[i-1]
tmp = t[i]
t.reverse()
if len(t) > 1:
if t[0] == "?" and t[1] == "D":
t[0] = "P"
elif t[0] == "?" and t[1] == "P":
t[0] = "D"
if len(t) == 1:
t[0] = "D"
t = "".join(t)
print(t)
| 1 | 18,522,315,042,000 | null | 140 | 140 |
import math
x1,y1,x2,y2 = (float(x) for x in input().split())
print(round(math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2), 8))
| import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
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())
N = I()
A = LI()
ans_list = [0] * N
for a in A:
ans_list[a - 1] += 1
for i in range(N):
print(ans_list[i]) | 0 | null | 16,322,828,973,220 | 29 | 169 |
n = int(input())
s = input()
t = s[:len(s)//2]
if 2*t == s:
print("Yes")
else:
print("No") | N = int(input())
S = input()
if N%2!=0:
print("No")
elif N%2 == 0:
if S[0:N//2]==S[N//2:N+1]:
print("Yes")
else:
print("No") | 1 | 146,773,106,564,252 | null | 279 | 279 |
# import bisect
# from collections import Counter, defaultdict, deque
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter
# import math
import sys
# import numpy as np
ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)
def main():
x, y = list(map(int,ipti().split()))
prize = [300000, 200000, 100000, 0]
if x == y == 1:
print(1000000)
else:
x = 4 if x > 3 else x
y = 4 if y > 3 else y
print(prize[x-1]+prize[y-1])
if __name__ == '__main__':
main() | X,Y = map(int,input().split())
ans = 0
shokin = [-1,300000,200000,100000]
if X in (1,2,3):
ans += shokin[X]
if Y in (1,2,3):
ans += shokin[Y]
if X == 1 and Y == 1:
ans += 400000
print(ans)
| 1 | 140,971,885,293,472 | null | 275 | 275 |
n=int(input())
A=list(map(int,input().split()))
for i in A:
if i%2==1 or i%3==0 or i%5==0:
continue
print("DENIED")
exit()
print("APPROVED") | n = int(input())
a = list(map(int, input().split()))
approved = True
for i in range(n):
if a[i] % 2 == 0 and (a[i] % 3 != 0 and a[i] % 5 != 0):
approved = False
break
print("APPROVED" if approved else "DENIED")
| 1 | 69,260,216,725,470 | null | 217 | 217 |
n, m = map(int, input().split())
print(int(n*m) if (n<=9 and m<=9) else -1) | x = int(input())
money1 = x // 500
x %= 500
money2 = x // 5
ans = money1 * 1000 + money2 * 5
print(ans) | 0 | null | 100,537,261,531,520 | 286 | 185 |
a=int(input())
b=0
c=list(map(int,input().split()))
for i in range(a):
for k in range(a):
b=b+c[i]*c[k]
for u in range(a):
b=b-c[u]*c[u]
print(int(b/2)) | import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))
n=int(input())
a=lmp()
ans=0
for i in range(n-1):
for j in range(i+1,n):
ans+=a[i]*a[j]
print(ans) | 1 | 167,940,273,424,220 | null | 292 | 292 |
#!/usr/bin/env python3
import collections as cl
import sys
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():
k = II()
ans = ""
for i in range(k):
ans += "ACL"
print(ans)
main()
| import sys
def input(): return sys.stdin.readline().strip()
def resolve():
x,y=map(int, input().split())
ans=0
if x<=3:
ans+=100000
if x<=2:
ans+=100000
if x==1:
ans+=100000
if y<=3:
ans+=100000
if y<=2:
ans+=100000
if y==1:
ans+=100000
if x==1 and y==1:
ans+=400000
print(ans)
resolve()
| 0 | null | 71,239,238,915,780 | 69 | 275 |
count=int(raw_input())
for i in range(0,count):
a,b,c=map(int,raw_input().split())
if pow(a,2)+pow(b,2)==pow(c,2):
print 'YES'
elif pow(a,2)+pow(c,2)==pow(b,2):
print 'YES'
elif pow(b,2)+pow(c,2)==pow(a,2):
print 'YES'
else:
print 'NO' | M1, _ = map(int, input().split())
M2, _ = map(int, input().split())
ans = 1 if M1 != M2 else 0
print(ans) | 0 | null | 62,471,704,692,768 | 4 | 264 |
n,m = map(int,input().split())
mat=[]
v=[]
for i in range(n):
a=list(map(int,input().split()))
mat.append(a)
for j in range(m):
v.append(int(input()))
for i in range(n):
w = 0
for j in range(m):
w += mat[i][j]*v[j]
print(w)
| r, c = map(int, input().split())
a, b, ans = [], [], []
for i in range(r):
a.append([int(x) for x in input().split()])
for i in range(c):
b.append(int(input()))
for i in range(r):
tmp = 0
for j in range(c):
tmp += a[i][j] * b[j]
ans.append(tmp)
for x in ans:
print(x) | 1 | 1,168,810,474,192 | null | 56 | 56 |
print("Yes" if input().count("7") > 0 else "No") | N = int(input())
print('Yes') if '7' in str(N) else print('No') | 1 | 34,331,199,908,000 | null | 172 | 172 |
MOD = 10 **9 + 7
INF = 10 ** 10
import numpy as np
from scipy.sparse.csgraph import floyd_warshall
from scipy.sparse import csr_matrix
def main():
n,m,l = map(int,input().split())
dist = [[INF] * n for _ in range(n)]
for _ in range(m):
a,b,c = map(int,input().split())
a -= 1
b -= 1
dist[a][b] = c
dist[b][a] = c
csr = csr_matrix(dist)
dist1 = floyd_warshall(csr)
dist1 = np.where(dist1 <= l,1,INF)
cnt = floyd_warshall(dist1)
q = int(input())
for _ in range(q):
s,t = map(int,input().split())
s -= 1
t -= 1
print(-1 if cnt[s][t] == INF else int(cnt[s][t]) - 1)
if __name__ == '__main__':
main() | import sys
input = sys.stdin.readline
n,m=map(int,input().split())
M=set(tuple(map(int,input().split())) for _ in range(m))
d={i:set() for i in range(1,n+1)}
for i,j in M:
d[i].add(j)
d[j].add(i)
vis=set()
res = 0
for i in range(1,n+1):
if i not in vis:
stack = [i]
ans = 1
vis.add(i)
while stack:
curr = stack.pop()
for j in d[curr]:
if j not in vis:
stack.append(j)
ans+=1
vis.add(j)
res = max(ans,res)
print(res)
| 0 | null | 88,492,416,140,228 | 295 | 84 |
n = int(input())
lis = list(map(int, input().split()))
t = lis[0]
for i in range(1, n):
t ^= lis[i]
ans = [0] * n
for i , j in enumerate(lis):
ans[i] = t ^ j
print(*ans) | n=map(int,input().split())
*p,=map(int,input().split())
lmin=10**10
ans=0
for pp in p:
ans+=1 if pp<=lmin else 0
lmin=min(pp,lmin)
print(ans)
| 0 | null | 48,723,880,552,930 | 123 | 233 |
n,m=map(int,input().split())
matA=[list(map(int,input().split())) for i in range(n)]
matB=[int(input()) for i in range(m)]
for obj in matA:
print(sum(obj[i] * matB[i] for i in range(m))) | N = int(input())
ans = (N - (N//2)) / N
print(ans) | 0 | null | 89,168,247,297,568 | 56 | 297 |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.