code1
stringlengths 16
427k
| code2
stringlengths 16
427k
| similar
int64 0
1
| pair_id
int64 6.82M
181,637B
⌀ | question_pair_id
float64 101M
180,471B
⌀ | code1_group
int64 2
299
| code2_group
int64 2
299
|
---|---|---|---|---|---|---|
import math
N = int(input())
A = list(map(int, input().split()))
dic = {}
for a in A:
if not a in dic:
dic[a] = 1
else:
dic[a] += 1
ans = 0
for a in dic:
if dic[a] > 1:
ans += dic[a] * (dic[a] - 1) // 2
ansdic = {}
for a in dic:
ansdic[a] = ans
if dic[a] > 1:
ansdic[a] = ans - (dic[a] - 1)
for a in A:
print(ansdic[a])
| n = int(input())
str1 = ""
while n > 0:
n -= 1
m = n % 26
n = n // 26
str1 += chr(m+ord("a"))
ans = str1[::-1]
print(ans) | 0 | null | 29,680,795,599,132 | 192 | 121 |
def main():
N = int(input())
result = []
while N > 0:
N -= 1
mod = N % 26
result.append(chr(mod + ord('a')))
N //= 26
result_str = ""
for i in range(len(result)-1, -1, -1):
result_str += result[i]
print(result_str)
main()
| def factorize(n):
b = 2
fct = []
while b * b <= n:
while n % b == 0:
n //= b
fct.append(b)
b = b + 1
if n > 1:
fct.append(n)
return fct
def getpattern(x):
pattern = 0
d = 0
for i in range(1, 1000000):
d += i
if x < d:
break
pattern += 1
return pattern
n = int(input())
f = factorize(n)
fu = set(factorize(n))
r = 0
for fui in fu:
r += getpattern(f.count(fui))
print(r) | 0 | null | 14,515,110,803,710 | 121 | 136 |
from collections import deque
N, K = map(int, input().split())
towns = [0] + list(map(int, input().split()))
checked = [-1 for _ in range(N+1)]
checked[1] = 0
next = towns[1]
count = 1
while(checked[next] < 0):
checked[next] = count
count += 1
next = towns[next]
loop = count - checked[next]
pos = 0
if K >= count:
pos = checked[next] + (K-checked[next])%loop
else:
pos = K
for i in range(1, N+1):
if checked[i] == pos:
print(i)
exit() | mod = 998244353
# 貰うDP
def main(N, S):
dp = [0 if n != 0 else 1 for n in range(N)] # dp[i]はマスiに行く通り数. (答えはdp[-1]), dp[0] = 1 (最初にいる場所だから1通り)
A = [0 if n != 0 else 1 for n in range(N)] # dp[i] = A[i] - A[i-1] (i >= 1), A[0] = dp[0] = 1 (i = 0) が成り立つような配列を考える.
for i in range(1, N): # 今いる点 (注目点)
for l, r in S: # 選択行動範囲 (l: 始点, r: 終点)
if i - l < 0: # 注目点が選択行動範囲の始点より手前の場合 → 注目点に来るために使用することはできない.
break
else: # 注目点に来るために使用することができる場合
dp[i] += A[i-l] - A[max(i-r, 0)-1] # lからrの間で,注目点に行くために使用できる点を逆算. そこに行くことができる = 選択行動範囲の値を選択することで注目点に達することができる通り数.
dp[i] %= mod
A[i] = (A[i-1] + dp[i]) % mod
print(dp[-1])
if __name__ == '__main__':
N, K = list(map(int, input().split()))
S = {tuple(map(int, input().split())) for k in range(K)}
S = sorted(list(S), key = lambda x:x[0]) # 始点でsort (範囲の重複がないため)
main(N, S) | 0 | null | 12,729,054,547,520 | 150 | 74 |
class UnionFind:
def __init__(self, size):
self.parent = list(range(size))
self.height = [0] * size
self.size = [1] * size
self.componentCount = size
def root(self, index):
if self.parent[index] == index: # 根の場合
return index
rootIndex = self.root(self.parent[index]) # 葉の場合親の根を取得
self.parent[index] = rootIndex # 親の付け直し
return rootIndex
def union(self, index1, index2): # 結合
root1 = self.root(index1)
root2 = self.root(index2)
if root1 == root2: # 連結されている場合
return
self.componentCount -= 1 # 連結成分を減らす
if self.height[root1] < self.height[root2]:
self.parent[root1] = root2 # root2に結合
self.size[root2] += self.size[root1]
else:
self.parent[root2] = root1 # root1に結合
self.size[root1] += self.size[root2]
if self.height[root1] == self.height[root2]:
self.height[root1] += 1
return
def isSameRoot(self, index1, index2):
return self.root(index1) == self.root(index2)
def sizeOfSameRoot(self, index):
return self.size[self.root(index)]
N, M = map(int, input().split())
tree = UnionFind(N)
for _ in range(M):
a, b = map(lambda a: int(a) - 1, input().split())
tree.union(a, b)
print(tree.componentCount - 1)
| n = int(input())
s = input()
cnt = 0
for i in range(1000):
c = [i // 100, (i // 10) % 10, i % 10]
f = 0
for j in range(n):
if s[j] == str(c[f]): f+=1
if f == 3: break
if f == 3: cnt += 1
print(cnt) | 0 | null | 65,770,803,849,772 | 70 | 267 |
from collections import defaultdict
n = int(input())
results = defaultdict(lambda: 0)
for _ in range(n):
s = input()
results[s] += 1
for judge in ['AC', 'WA', 'TLE', 'RE']:
print(judge, ' x ', results[judge])
| n=int(input())
ans=[]
for i in range(n):
ans.append(input())
def func(ans,moji):
num=ans.count(moji)
print(moji,"x",str(num))
mojis=["AC","WA","TLE","RE"]
for moji in mojis:
func(ans,moji) | 1 | 8,679,942,953,846 | null | 109 | 109 |
digits = [int(i) for i in list(input())]
Sum = 0
for i in digits:
Sum += i
if Sum%9 == 0:
print("Yes")
else:
print("No") | row_c, col_c = [int(x) for x in input().split(" ")]
nums =[]
col_sums = []
for i in range(row_c):
nums.append([int(x) for x in input().split(" ")])
#calc each col
for i in range(col_c):
s = 0
for n in nums:
s += n[i]
col_sums.append(s)
col_sums.append(sum(col_sums))
#calc each row
for i, num in enumerate(nums):
nums[i].append(sum(num))
#outpu
for row in nums:
print(" ".join(map(str, row)))
print(" ".join(map(str, col_sums))) | 0 | null | 2,877,600,780,220 | 87 | 59 |
suit = {"S": 0, "H": 1, "C": 2, "D": 3}
suit_keys = list(suit.keys())
deck = [[suit_keys[i] + " " + str(j + 1) for j in range(13)] for i in range(4)]
for _ in range(int(input())):
card = input().split()
deck[suit[card[0]]][int(card[1]) - 1] = ""
for i in range(4):
for j in range(13):
if deck[i][j] != "":
print(deck[i][j])
| n=int(input())
arr = [[False for i in range(13)] for j in range(4)]
for count in range(n):
code = input().split()
if (code[0]=="S"):
arr[0][int(code[1])-1]=True
elif (code[0]=="H"):
arr[1][int(code[1])-1]=True
elif(code[0]=="C"):
arr[2][int(code[1])-1]=True
else:
arr[3][int(code[1])-1]=True
for i in range(4):
if(i==0):
img="S"
elif(i==1):
img="H"
elif(i==2):
img="C"
else:
img="D"
for j in range(13):
if(arr[i][j]==False):
print(img+" "+str(j+1)) | 1 | 1,050,945,050,650 | null | 54 | 54 |
import math
a,aa,b,bb=map(float,input().split())
A=(math.sqrt(abs(a-b)**2+abs(aa-bb)**2))
print(A)
| #import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
from fractions import gcd
#input=sys.stdin.readline
#import bisect
n=int(input())
ans=0
for i in range(1,n+1):
num=n//i
ans+=(num*(i+num*i))//2
print(ans) | 0 | null | 5,653,829,215,918 | 29 | 118 |
import collections
import sys
input = sys.stdin.readline
def main():
N = int(input())
S = [input().rstrip() for _ in range(N)]
c = collections.Counter(S).most_common()
max_freq = None
max_S = []
for s, freq in c:
if max_freq is None:
max_freq = freq
max_S.append(s)
elif freq == max_freq:
max_S.append(s)
else:
break
print('\n'.join(sorted(max_S)))
if __name__ == "__main__":
main()
| n=int(input())
adj=[]
for i in range(n):
adj.append(list(map(int, input().split())))
edge=[[0 for i2 in range(n)]for i1 in range(n)]
#??£??\???????????????
for i in range(n):
for j in range(adj[i][1]):
edge[i][adj[i][j+2]-1]=1
time=1
discover=[0 for i in range(n)]
final=[0 for i in range(n)]
stack=[]
def dfs(id,time):
for i in range(n):
c=0
if edge[id][i]==1 and discover[i]==0:
stack.append(id)
discover[i]=time
c+=1
#print(discover,final,i,stack)
dfs(i,time+1)
else:
pass
if c==0:
if len(stack)>0:
if final[id]==0:
final[id] = time
#print("back",discover,final,id,stack)
dfs(stack.pop(), time + 1)
else:
#print("back", discover, final, id, stack)
dfs(stack.pop(),time)
discover[0]=time
stack.append(0)
dfs(0,time+1)
for i in range(n):
if discover[i]==0:
discover[i]=final[0]+1
stack.append(i)
dfs(i,final[0]+2)
break
for i in range(n):
print(i+1,discover[i],final[i]) | 0 | null | 35,114,740,379,120 | 218 | 8 |
n = int(input())
a = list(map(int, input().split()))
total = sum(a)
s = 0
for bar in a:
if (s + bar) * 2 <= total:
s += bar
else:
ans = min((s + bar) * 2 - total, total - s * 2)
break
print(ans)
| n = int(input())
a = list(map(int, input().split()))
result = 2020202020
num_left = 0
num_right = sum(a)
for i in range(n):
num_left += a[i]
num_right -= a[i]
result = min(result, abs(num_left - num_right))
print(result) | 1 | 142,642,180,788,882 | null | 276 | 276 |
N,K=map(int,input().split())
A=list(map(int,input().split()))
B=[0]*N
B[0]=1
if B[0] in A:c=B[0]
for i in range(1,N):
B[i]=A[B[i-1]-1]
d=B.index(B[-1])+1
if K<=N:print(B[K]);exit()
print(B[d-1+(K+1-d)%(N-d)])
| import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])
n,m = inpm()
way = [[] for _ in range(n+1)]
for i in range(m):
a,b = inpm()
way[a].append(b)
way[b].append(a)
ans = [0 for i in range(n+1)]
q = queue.Queue()
q.put((1,0))
while not q.empty():
room,sign = q.get()
if ans[room] != 0:
continue
ans[room] = sign
for i in way[room]:
q.put((i,room))
print('Yes')
for i in range(2,n+1):
print(ans[i]) | 0 | null | 21,538,325,026,032 | 150 | 145 |
n, k = map(int, input().split())
w = [int(input()) for _ in range(n)]
# k台以内のトラックで運べる荷物の個数
# P: ひとつのトラックに積載できる最大量
def check(P):
i = 0
for j in range(k):
s = 0
while s + w[i] <= P:
s += w[i]
i += 1
if i == n:
return n
return i
# 二部探索
left = 0
right = 100000 * 10000
while right - left > 1:
mid = (left + right) // 2
v = check(mid)
if v >= n:
right = mid
else:
left = mid
print(right)
| import sys
import collections
N = int(input())
L = collections.deque()
for _ in range(N):
com = (sys.stdin.readline().rstrip()).split()
if com[0] == 'insert':
L.appendleft(int(com[1]))
elif com[0] == 'delete':
try:
L.remove(int(com[1]))
except:
pass
elif com[0] == 'deleteFirst':
L.popleft()
elif com[0] == 'deleteLast':
L.pop()
print(*L)
| 0 | null | 71,706,300,808 | 24 | 20 |
a5=[]
while True:
x=int(input())
if x==0:
break
a5.append(x)
j = 0
for i in a5:
print("Case " + str(j+1)+": "+ str(i))
j=j+1
| # 3
A,B,C=map(int,input().split())
K=int(input())
def f(a,b,c,k):
if k==0:
return a<b<c
return f(a*2,b,c,k-1) or f(a,b*2,c,k-1) or f(a,b,c*2,k-1)
print('Yes' if f(A,B,C,K) else 'No')
| 0 | null | 3,654,727,818,898 | 42 | 101 |
import sys
input = sys.stdin.readline
import numpy as np
from scipy.sparse.csgraph import floyd_warshall
n,m,l=map(int,input().split())
ans=[[0]*n for i in range(n)]
for i in range(m):
a,b,c=[int(j) for j in input().split()]
ans[a-1][b-1]=c
ans[b-1][a-1]=c
q=int(input())
st=[]
for i in range(q):
st.append([int(j)-1 for j in input().split()])
ans=floyd_warshall(ans)
for i in range(n):
for j in range(n):
if ans[i][j]<=l:
ans[i][j]=1
else:
ans[i][j]=0
ans=floyd_warshall(ans)
for i,j in st:
if ans[i][j]==float("inf"):
print(-1)
else:
print(int(ans[i][j])-1)
| n, m = map(int, input().split())
print('Yes' if m >= n else 'No') | 0 | null | 128,123,741,648,770 | 295 | 231 |
s = 'abcdefghijklmnopqrstuvwxyz'
c = input()
for i in range(26):
if c == s[i]:
print(s[i+1])
exit()
exit() | def resolve():
word=input()
print(chr(ord(word)+1))
resolve() | 1 | 92,247,092,129,900 | null | 239 | 239 |
from collections import deque
n = int(input())
l = list(map(int,input().split()))
l.sort()
largest = l[-1]
que = deque(l)
cnt = n
ans = 0
while cnt > 0:
x = que.pop()
ans += x
cnt -= 1
if cnt != 0:
ans += x
cnt -= 1
print(ans-largest) | n = int(input())
arr = list(map(int, input().split()))
arr.sort(reverse=True)
ans = arr[0]
i = 1
j = 1
while i < n-1:
ans += arr[j]
#print (arr[j])
if i % 2 == 0:
j += 1
i += 1
print (ans) | 1 | 9,220,710,838,468 | null | 111 | 111 |
N = int(input())
def dist(A, B):
return abs(A[0] - B[0]) + abs(A[1] - B[1])
XY = [tuple(map(int, input().split())) for _ in range(N)]
INF = -10**10
ans = 0
for O in [(INF, INF), (-INF, INF)]:
S = XY[0]
for xy in XY:
if dist(O, S) < dist(O, xy):
S = xy
O = S
for xy in XY:
if dist(O, S) < dist(O, xy):
S = xy
ans = max(ans, dist(O, S))
print(ans)
| # coding:UTF-8
import sys
def resultSur97(x):
return x % (1000000000 + 7)
if __name__ == '__main__':
# ------ 入力 ------#
# 1行入力
n = int(input()) # 数字
# a = input() # 文字列
# aList = list(map(int, input().split())) # スペース区切り連続数字
# aList = input().split() # スペース区切り連続文字列
# aList = [int(c) for c in input()] # 数字→単数字リスト変換
# 定数行入力
x = n
# aList = [int(input()) for _ in range(x)] # 数字
# aList = [input() for _ in range(x)] # 文字
aList = [list(map(int, input().split())) for _ in range(x)] # スペース区切り連続数字(行列)
# aList = [input().split() for _ in range(x)] # スペース区切り連続文字
# aList = [[int(c) for c in input()] for _ in range(x)] # 数字→単数字リスト変換(行列)
# スペース区切り連続 数字、文字列複合
# aList = []
# for _ in range(x):
# aa, bb = input().split()
# a.append((int(aa), bb))
# ------ 処理 ------#
zmin = aList[0][0] + aList[0][1]
zmax = aList[0][0] + aList[0][1]
wmin = aList[0][0] - aList[0][1]
wmax = aList[0][0] - aList[0][1]
for i in range(len(aList)):
x = aList[i][0]
y = aList[i][1]
z = x + y
w = x - y
if z < zmin:
zmin = z
if z > zmax:
zmax = z
if w < wmin:
wmin = w
if w > wmax:
wmax = w
disMax = max(zmax-zmin, wmax-wmin)
# ------ 出力 ------#
print("{}".format(disMax))
# if flg == 0:
# print("YES")
# else:
# print("NO")
| 1 | 3,443,963,077,984 | null | 80 | 80 |
import sys
import string
C = input()
if C == 'z' : sys.exit()
pos = string.ascii_lowercase.index(C)+1
print(string.ascii_lowercase[pos]) | alp = [chr(i) for i in range(97, 97+26)]
print(alp[alp.index(input())+1]) | 1 | 92,416,762,595,190 | null | 239 | 239 |
s =input()
t =input()
for i in range(len(s)):
if s[i] != t[i]:
print('No')
exit()
if len(t) == len(s)+1:
print('Yes')
else:
print('No') | N,M = map(int,input().split())
t = [[i+1] for i in range(N)]
for i in range(M):
A,B = map(int,input().split())
t[A-1].append(B)
t[B-1].append(A)
from collections import deque
d = deque()
ans = [-1]*(N)
d.append(t[0])
while len(d) > 0:
z = d.popleft()
x = z[0]
for i in range(1,len(z)):
if ans[z[i]-1] == -1:
ans[z[i]-1] = x
d.append(t[z[i]-1])
print("Yes")
for i in range(1,len(ans)):
print(ans[i]) | 0 | null | 21,116,493,591,802 | 147 | 145 |
def abc156c_rally():
n = int(input())
x = list(map(int, input().split()))
min_x, max_x = min(x), max(x)
best = float('inf')
for i in range(min_x, max_x + 1):
total = 0
for v in x:
total += (v - i) * (v - i)
if best > total:
best = total
print(best)
abc156c_rally() | n = int(input())
info = []
for _ in range(n):
temp = [int(x) for x in input().split( )]
info.append(temp)
state = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]
for a in info:
state[a[0]-1][a[1]-1][a[2]-1] += a[3]
for b in range(4):
for f in range(3):
string = ''
for k in range(10):
string += ' ' + str(state[b][f][k])
print(string)
if b < 3:
print('#'*20)
| 0 | null | 33,271,795,099,652 | 213 | 55 |
n = int(input())
x = list(map(int,input().split()))
ans = 100**2 * n
for i in range(1,101):
energy = 0
for j in x:
energy += (i-j)**2
ans = min(ans, energy)
print(ans) | def main():
num, target = map(int, input().split())
if num * 500 >= target:
print('Yes')
else:
print('No')
if __name__ == '__main__':
main() | 0 | null | 81,518,612,078,012 | 213 | 244 |
D=int(input())
c=[int(x) for x in input().split()]
s=[[0]*i for i in range(D)]
t=[]
last_d=[0]*26
for i in range(D):
s[i]=[int(x) for x in input().split()]
for i in range(D):
t.append(int(input()))
v=0
for i in range(D):
a=0
for j in range(26):
if j!=t[i]-1:
n=i+1-last_d[j]
a+=c[j]*n
v=v+s[i][t[i]-1]-a
print(v)
last_d[t[i]-1]=i+1 | a, b, k = map(int, input().split())
a = a-k
if a < 0:
b += a
print(max(a, 0), max(b, 0)) | 0 | null | 57,010,542,927,520 | 114 | 249 |
n = int(input())
a = [int(x) for x in input().split()]
ans = sum(a)
ans_li = []
q = int(input())
d = {}
for i in range(len(a)):
if a[i] not in d:
d[a[i]] = 0
d[a[i]] += 1
for i in range(q):
B,C = map(int,input().split())
if B not in d:
ans_li.append(ans)
else:
num = d[B]
dis = abs(B - C)
if B >= C:
ans_li.append(ans - (num * dis))
ans = ans_li[-1]
else:
ans_li.append(ans + (num * dis))
ans = ans_li[-1]
if C not in d:
d[C] = num
d[B] = 0
else:
d[C] += num
d[B] = 0
for aa in ans_li:
print(aa)
| A,B= list(input().split())
a = int(B[0])
b = int(B[2])
c = int(B[3])
if int(A) > 1000:
e = int(A[-2])
f = int(A[-1])
d = int((int(A)- 10 * e - f)/100)
error = 10 * (c * e + b * f) + c * f
error = int(error/100)
ans = int(A) * a + 10 * d * b + e * b + c * d + error
print(int(ans))
else:
print(int(int(A)*float(B))) | 0 | null | 14,389,315,131,900 | 122 | 135 |
class UnionFind():
def __init__(self, n):
self.par = [i for i in range(n+1)]
self.rank = [0] * (n+1)
def find(self, x):
if self.par[x] == x:
return x
else:
self.par[x] = self.find(self.par[x])
return self.par[x]
def unite(self, x, y):
x = self.find(x)
y = self.find(y)
if self.rank[x] < self.rank[y]:
self.par[x] = y
else:
self.par[y] = x
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
def same(self, x, y):
return self.find(x) == self.find(y)
N,M=map(int,input().split())
city=UnionFind(N)
for i in range(M):
A,B=map(int,input().split())
city.unite(A,B)
ck=[0]*(N+10)
for i in range(1,N+1):
root=city.find(i)
if ck[root]==0:
ck[root]=1
#print(city.par)
#print(ck)
Ans=sum(ck)-1
print(Ans)
| from collections import defaultdict
N, P = map(int,input().split())
S = input()
if P==5:
ans = 0
for i,m in enumerate(S):
if m == '5' or m == '0':
ans += i+1
elif P==2:
ans = 0
for i,m in enumerate(S):
if int(m) % 2 ==0:
ans += i+1
else:
S = S[::-1]
primdic = defaultdict(int)
before = 0
for i in range(0,N):
now = (int(S[i])*pow(10,i,P)+before)%P
primdic[now] += 1
before = now
# 文字なしの時はあまり0なので
primdic[0] += 1
ans = 0
for value in primdic.values():
ans += value*(value-1)//2
print(ans) | 0 | null | 30,246,729,909,300 | 70 | 205 |
h1,m1,h2,m2,k=map(int,input().split())
x1 = h1 * 60 + m1
x2 = h2 * 60 + m2
print(x2 - x1 - k)
| a,b,c,d,e=map(int,input().split())
x=a*60+b
y=c*60+d
print(y-x-e) | 1 | 18,096,782,438,112 | null | 139 | 139 |
line = '#.'*150
while True:
H, W = map(int, raw_input().split())
if H == W == 0: break
for i in range(H):
print line[i%2:i%2+W]
print '' | # C - Next Prime
N = 110000
p = [0]*N
x = int(input())
for i in range(2,N):
if p[i]:
continue
if i>=x:
print(i)
break
tmp = i
while tmp<N:
p[tmp] = 1
tmp += i | 0 | null | 53,417,897,555,440 | 51 | 250 |
#a,b,c = map(int,input().split())
a = int(input())
b = input()
c = b[:a//2]
d = b[a//2:a]
print("Yes" if c == d else "No") | N = int(input())
S = input()
print("Yes" if S[:N//2] == S[N//2:] else "No") | 1 | 146,594,274,508,800 | null | 279 | 279 |
from sys import stdin
n, m, l = [int(x) for x in stdin.readline().rstrip().split()]
a = [[int(x) for x in stdin.readline().rstrip().split()] for _ in range(n)]
b = [[int(x) for x in stdin.readline().rstrip().split()] for _ in range(m)]
c = [[0] *l for _ in range(n)]
for i in range(n):
for j in range(l):
for k in range(m):
c[i][j] += a[i][k]*b[k][j]
for i in range(n):
print(*c[i])
| [n, m, l] = [int(x) for x in raw_input().split()]
A = []
B = []
C = []
counter = 0
while counter < n:
A.append([int(x) for x in raw_input().split()])
counter += 1
counter = 0
while counter < m:
B.append([int(x) for x in raw_input().split()])
counter += 1
counter = 0
while counter < n:
C.append([0] * l)
counter += 1
for i in range(n):
for j in range(l):
for k in range(m):
C[i][j] += (A[i][k] * B[k][j])
for data in C:
print(' '.join([str(x) for x in data])) | 1 | 1,448,127,592,718 | null | 60 | 60 |
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())
xy = []
for index in range(n):
x, y = map(int, input().split())
xy.append([x, y])
pos_max = xy[0][0]+xy[0][1]
pos_min = xy[0][0]+xy[0][1]
neg_max = xy[0][0]-xy[0][1]
neg_min = xy[0][0]-xy[0][1]
for item in xy:
pos_v = item[0] + item[1]
neg_v = item[0] - item[1]
pos_max = pos_v if pos_v > pos_max else pos_max
pos_min = pos_v if pos_v < pos_min else pos_min
neg_max = neg_v if neg_v > neg_max else neg_max
neg_min = neg_v if neg_v < neg_min else neg_min
pos_result = pos_max - pos_min
neg_result = neg_max - neg_min
print(pos_result if pos_result >= neg_result else neg_result) | 0 | null | 7,640,490,334,402 | 121 | 80 |
from itertools import permutations
from bisect import bisect_left
n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
perm = list(permutations(p))
perm.sort()
a = bisect_left(perm, p)
b = bisect_left(perm, q)
print(abs(a- b))
| #!/usr/bin/env python
# -*- coding: utf-8 -*-
def main():
values = []
total = 0
open_chars = 0
close_chars = 0
for _ in range(int(input())):
s = input().strip()
open_required = len(s)
close_required = len(s)
open_close = 0
for i, c in enumerate(s):
if c == '(':
open_required = min(i, open_required)
open_close += 1
else:
close_required = min(len(s) - i - 1, close_required)
open_close -= 1
if open_required == 0 and close_required == 0 and open_close == 0:
continue
elif open_close == len(s):
open_chars += len(s)
continue
elif -open_close == len(s):
close_chars += len(s)
continue
total += open_close
values.append([open_required, close_required, open_close, 0])
if total + open_chars - close_chars != 0:
print('No')
return
fvals = values.copy()
bvals = values
fvals.sort(key=lambda x: (x[0], -x[2]))
bvals.sort(key=lambda x: (x[1], x[2]))
findex = 0
bindex = 0
while True:
while findex < len(fvals) and fvals[findex][3] != 0:
findex += 1
while bindex < len(bvals) and bvals[bindex][3] != 0:
bindex += 1
if findex >= len(fvals) and bindex >= len(bvals):
break
fvals[findex][3] = 1
bvals[bindex][3] = -1
values = [v for v in fvals if v[3] == 1] + [v for v in bvals if v[3] == -1][::-1]
open_close_f = 0
open_close_b = 0
for (oreq_f, _, ocval_f, _), (_, creq_b, ocval_b, _) in zip(values, values[::-1]):
if oreq_f > open_close_f + open_chars:
print('No')
return
if creq_b > open_close_b + close_chars:
print('No')
return
open_close_f += ocval_f
open_close_b -= ocval_b
print('Yes')
if __name__ == '__main__':
main()
| 0 | null | 62,327,617,785,862 | 246 | 152 |
import datetime
h,m,eh,em,k = map(int,input().split())
start = h*60 + m
end = eh*60 + em
if end - start > k:
print(end - k - start)
else:
print(0) | import math
a = float(input())
print(str("{0:.6f}".format((a * a) * math.pi)) + " " + str("{0:.5f}".format((a + a) * math.pi)))
| 0 | null | 9,384,904,913,440 | 139 | 46 |
from collections import defaultdict
def dfs(N, tree, v):
s = []
done = [False for _ in range(N)]
dist = [0 for _ in range(N)]
done[v] = True
dist[v] = 0
s.append(v)
while 0 < len(s):
v = s.pop()
# process
# print(v, tree[v], dist[v])
for i in tree[v]:
if not done[i]:
done[i] = True
dist[i] = dist[v] + 1
s.append(i)
return dist
def main():
N, u, v = map(int, input().split())
u -= 1
v -= 1
tree = defaultdict(list)
for _ in range(N - 1):
A, B = map(int, input().split())
A -= 1
B -= 1
tree[A].append(B)
tree[B].append(A)
u_dist = dfs(N, tree, u)
v_dist = dfs(N, tree, v)
# print(u_dist)
# print(v_dist)
ans = 0
for u1, v1 in zip(u_dist, v_dist):
if u1 < v1:
ans = max(ans, v1 - 1)
print(ans)
main()
| n = int(input())
s, t = map(str, input().split())
ans = ''
for a, b in zip(s, t):
ans += a+b
print(ans) | 0 | null | 114,473,908,360,328 | 259 | 255 |
select = list(range(1, 4))
a = int(input())
b = int(input())
ans = next(s for s in select if s != a and s != b)
print(ans) | #k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
a = int(input())
b = int(input())
if (a == 1 and b == 2):
print(3)
elif(a == 1 and b == 3):
print(2)
elif (a == 2 and b == 1):
print(3)
elif (a == 2 and b == 3):
print(1)
elif (a == 3 and b == 1):
print(2)
elif (a == 3 and b == 2):
print(1)
| 1 | 110,944,442,741,120 | null | 254 | 254 |
import sys
n=int(input())
li=[int(x) for x in input().split()]
h=0
k=0
for i in range(n):
if h<=li[i]:
h=max(h,li[i])
else:
k=k+(h-li[i])
h=max(h,li[i])
print(k) | def II(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
N=II()
A=LI()
L=[0]*N
TM=A[0]
for i in range(N):
TM=max(TM,A[i])
L[i]=TM-A[i]
#print(L[i],TM,A[i])
ans=sum(L)
print(ans) | 1 | 4,562,431,249,440 | null | 88 | 88 |
h,w,k = map(int,input().split())
lst = []
cut1 = []
for i in range(h):
l = input()
if '#' in l:
cut1.append(i)
lst.append(l)
res = [[float('inf')]*w for _ in range(h)]
cut2 = []
for c in cut1:
tmp_cut = []
for j in range(len(lst[c])):
if lst[c][j]=='#':
tmp_cut.append(j)
cut2.append(tmp_cut)
cnt = 1
for e,i in enumerate(cut1):
for j in cut2[e]:
res[i][j] = cnt
cnt += 1
for r in res:
mn = min(r)
mx = max(r)
if (mn==mx) and (mn==float('inf')):
pass
else:
mx = max(set(r) - {float('inf')})
if mn==mx:
for i in range(w):
if r[i] == float('inf'):
r[i] = mn
else:
for i in range(w):
if r[i] == float('inf'):
r[i] = mn
else:
mn = min(mx, r[i])
for i in range(w):
tmp = []
for j in range(h):
if res[j][i] != float('inf'):
tmp.append(res[j][i])
num = min(tmp)
for j in range(h):
if res[j][i] == float('inf'):
res[j][i] = num
else:
num = res[j][i]
for r in res:
print(*r) | import sys
import math
from collections import defaultdict
sys.setrecursionlimit(10**7)
def input():
return sys.stdin.readline()[:-1]
mod = 10**9 + 7
def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
if N<=0:
return [[] for _ in range(num)]
elif num==1:
return [I() for _ in range(N)]
else:
read_all = [tuple(II()) for _ in range(N)]
return map(list, zip(*read_all))
#################
H,W,K = II()
s = [str(input()) for _ in range(H)]
ans = [[0]*W for _ in range(H)]
count = 0
no_row = []
for i in range(H):
p = []
for j in range(W):
if s[i][j]=='#':
p.append(j)
if len(p):
count += 1
for j in range(W):
if s[i][j] == '#' and j!=p[0]:
count += 1
ans[i][j] = count
else:
no_row.append(i)
for i in no_row:
for j in range(W):
for k in range(i+1,H):
if ans[k][j]:
ans[i][j] = ans[k][j]
break
for k in range(i)[::-1]:
if ans[k][j]:
ans[i][j] = ans[k][j]
break
for a in ans:
print(*a) | 1 | 144,382,735,580,004 | null | 277 | 277 |
#coding: UTF-8
N = int(input())
a = [int(input()) for i in range(N)]
ans = set()
maxv = -9999999999
minv = a[0]
for i in range(1,N):
if (a[i] - minv) > maxv:
maxv = a[i] - minv
if a[i] < minv:
minv = a[i]
print(maxv) | n=input()
min = None
max = None
cand=None
for x in xrange(n):
v = input()
# print "#### %s %s %s %s" % (str(max), str(min), str(cand), str(v))
if min is None:
min = v
# print "min is None"
continue
if min > v:
# print "min > v"
if (cand is None) or (cand < v-min):
# print "cand None"
cand = v-min
min = v
max = None
continue
elif (max is None) or (max < v):
# print "max is None"
max = v
if cand < max - min:
cand = max - min
continue
print cand | 1 | 13,504,551,262 | null | 13 | 13 |
n = int(input())
a = list(map(int,input().split()))
q = int(input())
m = list(map(int,input().split()))
cnt = [0] * (2000 * 20)
for i in range(1, 2**n + 1):
SUM = 0
for j in range(n):
if i>>j & 1:
SUM += a[j]
cnt[SUM] = 1
for _m in m:
if cnt[_m] == 1:
print("yes")
else:
print("no")
| n = int(input())
(*a, ) = map(int, input().split())
q = int(input())
(*m, ) = map(int, input().split())
s = set()
for j in range(2 << n):
c = 0
for k in range(n):
if j >> k & 1:
c += a[k]
s.add(c)
for i in m:
print("yneos"[i not in s::2])
| 1 | 102,047,267,362 | null | 25 | 25 |
'''
Created on 2020/08/23
@author: harurun
'''
def f(n):
arr=[]
temp=n
for c in range(2,int(-(-n**0.5//1))+1):
if temp%c==0:
cnt=0
while temp%c==0:
cnt+=1
temp//=c
arr.append([c,cnt])
if temp!=1:
arr.append([temp,1])
return arr
def main():
import math
import sys
pin=sys.stdin.readline
pout=sys.stdout.write
perr=sys.stderr.write
N=int(pin())
r=f(N)
ans=0
for i in r:
ans+=int((math.sqrt(1+8*i[1])-1)/2)
print(ans)
return
main() | N = int(input())
hash = {}
end = int(N ** (1/2))
for i in range(2, end + 1):
while N % i == 0:
hash[i] = hash.get(i, 0) + 1
N = N // i
if N != 1:
hash[i] = hash.get(i, 0) + 1
count = 0
trans = [1, 3, 6, 10, 15, 21, 28, 36, 45, 55]
res = 0
for i in hash.values():
for j in range(len(trans)):
if i > trans[j]:
continue
elif i == trans[j]:
res += (j + 1)
break
else:
res += j
break
print(res) | 1 | 16,901,352,013,494 | null | 136 | 136 |
n, k = map(int, input().split())
a = list(map(int, input().split()))
def is_ok(l):
cnt = 0
for L in a:
cnt += L // l - 1
if L % l != 0:
cnt += 1
return cnt <= k
def meguru_bisect(ng, ok):
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
if is_ok(mid):
ok = mid
else:
ng = mid
return ok
print(meguru_bisect(0, max(a))) | n,k = map(int,input().split())
L = list(map(int,input().split()))
ok = 0
ng = 10**9
while abs(ok-ng) > 1:
mid = (ok+ng)//2
cur = 0
for i in range(n):
cur += L[i]//mid
if cur > k:
ok = mid
elif cur <= k:
ng = mid
K = [mid-1, mid, mid+1]
P = []
for i in range(3):
res = 0
if K[i] > 0:
for j in range(n):
res += (L[j]-1)//K[i]
if res <= k:
P.append(K[i])
print(min(P))
| 1 | 6,514,693,860,818 | null | 99 | 99 |
n=int(input())
A=list(map(int,input().split()))
q=int(input())
M=list(map(int,input().split()))
pattern=[]
for i in range(2**n):
s=0
for j in range(n):
if i >> j & 1:
s+=A[j]
pattern.append(s)
P=set(pattern)
for m in M:
print('yes' if m in P else 'no')
| def main():
import sys, itertools as ite
n = int(sys.stdin.readline())
A = tuple(map(int, sys.stdin.readline().split()))
#print(A)
q = int(sys.stdin.readline())
M = map(int, sys.stdin.readline().split())
bit = ite.product([0,1], repeat=n)
ans = []
for b in bit:
tmp = 0
for i in range(n):
tmp +=b[i]*A[i]
ans += [tmp]
for m in M:
if m in ans:
print('yes')
else:
print('no')
if __name__=='__main__':
main()
| 1 | 104,052,723,682 | null | 25 | 25 |
def main():
K = int(input())
ans = False
if K % 2 == 0:
print(-1)
exit()
cnt = 7 % K
for i in range(1, K+1):
if cnt == 0:
ans = True
print(i)
exit()
cnt = (10 * cnt + 7) % K
if ans == False:
print(-1)
exit()
main() | k = int(input())
num = 7 % k
ans = 1
mod = [0 for _ in range(k)]
mod[num] = 1
while(num):
num = (num * 10 + 7) % k
if mod[num] > 0:
ans = -1
break
ans += 1
mod[num] += 1
print(ans)
| 1 | 6,116,485,081,540 | null | 97 | 97 |
X, K, D = map(int, input().split())
X = abs(X)
if X >= K * D:
ans = X - K * D
else:
n, d = divmod(X, D)
ans = d
if (K - n) % 2:
ans = D - d
print(ans) | def rect(h, w):
a = '#.' * 150
b = '.#' * 150
while h > 0:
print(a[:w])
a, b = b, a
h -= 1
print()
return
while True:
n = list(map(int, input().split()))
H = n[0]
W = n[1]
if (H == 0 and W == 0):
break
rect(H, W) | 0 | null | 3,023,557,337,270 | 92 | 51 |
n=int(raw_input())
ls=[int(i) for i in raw_input().split()]
ls.sort()
print ls[0],
print ls[len(ls)-1],
sum=0
for j in ls:
sum+=j
print sum | import math
class Pos:
def __init__(self, x, y):
self.x = x
self.y = y
def __str__(self):
return str(self.x) + ' ' + str(self.y)
def koch_curve(i, n, start, end):
if i < n:
f = get_pos(start, end, 1/3)
t = get_pos(start, end, 2/3)
s = get_sec_pos(start, end, f, t)
koch_curve(i + 1, n, start, f)
print(f)
koch_curve(i + 1, n, f, s)
print(s)
koch_curve(i + 1, n, s, t)
print(t)
koch_curve(i + 1, n, t, end)
def get_pos(start, end, m):
dX = (end.x - start.x) * m
dY = (end.y - start.y) * m
return Pos(start.x + dX, start.y + dY)
def get_sec_pos(start, end, f, t):
x = y = 0
if f.y == t.y:
x = start.x + (end.x - start.x) / 2
len = math.fabs(t.x - f.x)
h = math.sqrt(len**2 - (len/2)**2)
if start.x < end.x:
y = start.y + h
else:
y = start.y - h
elif f.x < t.x and f.y < t.y:
x = start.x
y = t.y
elif f.x > t.x and f.y < t.y:
x = end.x
y = f.y
elif f.x > t.x and f.y > t.y:
x = start.x
y = t.y
else:
x = end.x
y = f.y
return Pos(x, y)
n = int(input())
start = Pos(0, 0)
end = Pos(100, 0)
print(start)
koch_curve(0, n, start, end)
print(end)
| 0 | null | 434,769,207,100 | 48 | 27 |
import sys
input = sys.stdin.readline
INF = 10**18
sys.setrecursionlimit(10**6)
def li():
return [int(x) for x in input().split()]
N = int(input())
xs, ys = [], []
for i in range(N):
x, y = li()
xs.append(x)
ys.append(y)
def get_max_manhattan_distanse(xs, ys):
X = [xs[i] + ys[i] for i in range(len(xs))]
Y = [xs[i] - ys[i] for i in range(len(xs))]
# return max(max(X) - min(X), max(Y) - min(Y))
X.sort()
Y.sort()
return max(X[-1] - X[0], Y[-1] - Y[0])
ans = get_max_manhattan_distanse(xs, ys)
print(ans) | import math
while True:
n = int(input())
if n == 0:
break
s = list(map(int, input().split()))
m = sum(s)/n
v = 0
for i in s:
v += (i - m) ** 2
ans = math.sqrt(v/n)
print("{:.5f}".format(ans))
| 0 | null | 1,827,587,649,020 | 80 | 31 |
n = int(input())
s = input()
out = ""
for i in s:
if ord(i) + n > 90:
out += chr(64+n-(90-ord(i)))
else:
out += chr(ord(i)+n)
print(out) | n,*d=map(int,open(0).read().split())
ans=0
for i in range(n):
for j in range(i+1,n):
ans+=d[i]*d[j]
print(ans) | 0 | null | 152,057,766,653,440 | 271 | 292 |
w = input()
t = []
count = 0
while True:
line = input()
if line == 'END_OF_TEXT':
break
for x in line.split():
if w.lower() == x.lower():
count += 1
print(count) | X,K,D=(int(x) for x in input().split())
x=abs(X)
a=x//D
b=x-a*D
B=abs(x-(a+1)*D)
if b>B:
a=a+1
if a>=K:
print(abs(x-K*D))
else:
c=K-a
if c%2 == 0:
print(abs(x-a*D))
else:
d=abs(x-(a-1)*D)
e=abs(x-(a+1)*D)
print(min(d,e)) | 0 | null | 3,502,169,994,148 | 65 | 92 |
import math
a, b, C = map(float, input().split())
theta = math.radians(C)
S = 0.5 * a * b * math.sin(theta)
c = math.sqrt(a**2 + b**2 - 2*a*b*math.cos(theta))
h = b * math.sin(theta)
print("{:.9f}\n{:.9f}\n{:.9f}".format(S, a+b+c, h))
| import math
a,b,C=map(float,input().split())
print(f'{a*b/2*math.sin(math.radians(C)):.6f}')
print(f'{a+b+(a**2+b**2-2*a*b*math.cos(math.radians(C)))**0.5:.6f}')
print(f'{b*math.sin(math.radians(C)):.6f}')
| 1 | 172,870,384,100 | null | 30 | 30 |
x = input().split()
a,b = int(x[0]),int(x[1])
print("%d %d" %(a*b,2*a+2*b))
| def rectangle(a, b):
S = a * b
L = a*2 + b*2
print(S, L)
a, b =[int(x) for x in input().split()]
rectangle(a, b) | 1 | 308,287,643,990 | null | 36 | 36 |
a=input()
print('Yes' if '7' in a else 'No') | n = int(input())
lst = list(input())
r = lst.count('R')
count = 0
for i in range(0, r):
if lst[i] == 'R':
count += 1
print(r-count) | 0 | null | 20,242,010,645,690 | 172 | 98 |
def linearSearch(S, T):
cnt = 0
for e in T:
if e in S:
cnt += 1
return cnt
def main():
n = int(input())
s = list(map(int, input().split()))
q = int(input())
t = list(map(int, input().split()))
print(linearSearch(s, t))
if __name__ == "__main__":
main() | N = int(input())
S = list(map(int, input().split()))
Q = int(input())
T = list(map(int, input().split()))
S = set(S)
T = set(T)
C = list(S & T)
print(len(C)) | 1 | 68,258,036,110 | null | 22 | 22 |
n = int(input())
ACs = 0
WAs = 0
TLEs = 0
REs = 0
for i in range(n):
result = input()
if result == "AC":
ACs += 1
elif result == "WA":
WAs += 1
elif result == "TLE":
TLEs += 1
else:
REs += 1
print("AC x " + str(ACs))
print("WA x " + str(WAs))
print("TLE x " + str(TLEs))
print("RE x " + str(REs))
| def resolve():
N = int(input())
import math
print(math.ceil(N/2))
if '__main__' == __name__:
resolve() | 0 | null | 33,819,662,051,932 | 109 | 206 |
import sys
for i in sys.stdin.readlines()[:-1]:
h,w = map(int,i.strip().split())
print("#"*w)
for i in range(h-2):
print("#"+("."*(w-2))+"#")
if h > 1:
print("#"*w)
print() | while True:
H, W = map(int, input().split())
if not(H or W):
break
for i in range(H):
print('#', end='')
for j in range(W-2):
if i > 0 and i < H - 1:
print('.', end='')
else:
print('#', end='')
print('#')
print() | 1 | 812,435,370,908 | null | 50 | 50 |
n = int(input())
a = [int(i) for i in input().split()]
s = 0
for i in a:
s ^= i
for i in a:
print(s^i,end = ' ') | # n=int(input())
# n,k=map(int,input().split())
# arr=list(map(int,input().split()))
#ls=list(map(int,input().split()))
#for i in range(m):
# for _ in range(int(input())):
#from collections import Counter
#from fractions import Fraction
n=int(input())
arr=list(map(int,input().split()))
var=arr[0]
for i in range(1,n):
var^=arr[i]
for i in range(n):
print(arr[i]^var,end=" ")
#ls = [list(map(int, input().split())) for i in range(n)]
#for _ in range(int(input())):
| 1 | 12,560,857,711,200 | null | 123 | 123 |
A = int(input())
B = int(input())
print(3 if A+B==3 else 2 if A+B==4 else 1) | a = int(input())
b = int(input())
l = [a, b]
if not 1 in l:
print('1')
elif not 2 in l:
print('2')
else:
print('3') | 1 | 110,721,801,273,800 | null | 254 | 254 |
num = int(input())
A = input().split(" ")
B = A.copy()
#bubble sort
for i in range(num):
for j in range(num-1,i,-1):
#英字ではなく、数字で比較する
m1 = int(A[j][1:])
m2 = int(A[j-1][1:])
if m1 < m2:
A[j],A[j-1] = A[j-1],A[j]
print(*A)
print("Stable")
#selection sort
for i in range(num):
minv = i
for j in range(i+1,num):
m1 = int(B[minv][1:])
m2 = int(B[j][1:])
if m1 > m2:
minv = j
B[i],B[minv] = B[minv],B[i]
print(*B)
if A == B:
print("Stable")
else:
print("Not stable")
| n = int(input())
s, t = map(str, input().split())
s = list(s)
t = list(t)
c = ""
for i in range(n):
c += s[i]+t[i]
print(c) | 0 | null | 55,983,552,556,878 | 16 | 255 |
N=int(input())
print(sum(j*(N//j)*(N//j+1)//2 for j in range(1,N+1))) | n = int(input())
dp = [0]*(n+1)
for i in range(1,n+1):
x = n//i
for j in range(1,x+1):
dp[i*j]+=1
sum_div = 0
for i in range(1,n+1):
sum_div += i*dp[i]
print(sum_div) | 1 | 11,027,732,810,470 | null | 118 | 118 |
from collections import Counter
s = input()
MOD = 2019
ts = [0]
cur = 0
for i, j in enumerate(s[::-1], 1):
cur = (cur + pow(10, i, MOD) * int(j)) % MOD
ts.append(cur)
ct = Counter(ts)
res = 0
for k, v in ct.items():
if v > 1:
res += v * (v-1) // 2
print(res) | s=input()
ls=len(s)
m=[0]*(2019)
m[0]+=1
cnt = 0
b = 0
for i in range(ls):
a = (b + pow(10,cnt,2019)*int(s[ls - i -1])) % 2019
m[a] += 1
b = a
cnt += 1
ans = 0
for i in m:
if i <= 1:
continue
ans += i*(i-1)//2
print(ans)
| 1 | 30,893,524,098,582 | null | 166 | 166 |
# FizzBuzz Sum
N = int(input())
ans = ((1+N) * N)/2 - ((3 + 3*(N//3)) * (N//3))/2 - ((5 + 5*(N//5)) * (N//5))/2 + ((15 + 15*(N//15)) * (N//15))/2
print(int(ans)) | l=int(input())
m=l/3
s=m**3
print(s) | 0 | null | 40,969,824,491,608 | 173 | 191 |
n = int(input())
a = sorted([int(x) for x in input().split()])
print(a[0],a[-1],sum(a))
| import math
from functools import reduce
def gcd(*numbers):
return reduce(math.gcd, numbers)
k = int(input())
ans = 0
for a in range(1, k+1):
for b in range(a, k+1):
for c in range(b, k+1):
t = len({a,b,c})
if t == 3:
ans += gcd(a,b,c) * 6
elif t == 2:
ans += gcd(a,b,c) * 3
else:
ans += gcd(a,b,c)
print(ans) | 0 | null | 18,261,147,373,570 | 48 | 174 |
a, b = map(int, input().split())
aa = ""
for i in range(b):
aa += str(a)
bb = ""
for i in range(a):
bb += str(b)
if a <= b :
print(aa)
else :
print(bb) | # 152 B
a, b = input().split()
s1 = a * int(b)
s2 = b * int(a)
if s1 <= s2:
print(s1)
elif s1 > s2:
print(s2) | 1 | 84,365,256,569,028 | null | 232 | 232 |
X = int(input())
i = 1
while (360*i) % X != 0:
i += 1
ans = 360*i//X
print(ans)
| #cording; UTF-8
a,b=[int(x) for x in input().split()]
S = a*b
L = 2*(a+b)
print(S,L)
| 0 | null | 6,711,810,231,134 | 125 | 36 |
N, A, B = map(int, input().split())
dif = abs(A - B)
ans = 0
if dif % 2 == 0:
ans = dif // 2
else:
ans = min(A - 1, N - B) + 1 + dif // 2
print(ans) | n, a, b = [int(i) for i in input().split()]
a,b=max(a,b),min(a,b)
if (a - b) % 2 == 0:
print((a - b) // 2)
else:
c = b + (a -1- b) // 2
d = n - a + 1 + (n - (n - a + 1) - b) // 2
print(min(c,d))
| 1 | 109,458,363,860,102 | null | 253 | 253 |
N, K = map(int, input().split())
ans = 0
bigint = 10**9+7
for k in range(K,N+2):
ans += N-k+2+(N-k+1)*(k-1)
ans %= bigint
print(ans) | N, K = map(int, input().split())
preans = []
for n in range(K, N+2):
MIN = (0+n-1) * n / 2
MAX = (N + (N-n+1)) * n / 2
preans.append(MAX - MIN+1)
print(int(sum(preans)%(10**9 + 7))) | 1 | 33,114,037,355,800 | null | 170 | 170 |
#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, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
from sys import stdin
readline = stdin.readline
def readInts():
return list(map(int,readline().split()))
def readTuples():
return tuple(map(int,readline().split()))
def I():
return int(readline())
n = I()
def yaku(m):
ans = []
i = 1
while i*i <= m:
if m % i == 0:
j = m // i
ans.append(i)
i += 1
ans = sorted(ans)
return ans
a = yaku(n)
#print(a)
ans = float('inf')
for v in a:
ans = min(ans, (v-1)+(n//v)-1)
print(ans)
| # -*- coding: utf-8 -*-
"""
Created on Wed Sep 9 01:55:56 2020
@author: liang
"""
import math
N = int(input())
key = int(math.sqrt(N))
ans = 10**12
for i in reversed(range(1,key+1)):
if N%i == 0:
ans = i-1 + N//i -1
break
print(ans) | 1 | 161,960,909,473,792 | null | 288 | 288 |
while True:
s=input()
if s=="0":
break
n=list(map(int, list(s)))
print(sum(n)) | import numpy as np
N = int(input())
X = np.zeros([N,4], dtype=int)
for i in range(N):
X[i,0], X[i,1] = map(int, input().split())
X[i,2], X[i,3] = X[i,0] - X[i,1], X[i,0] + X[i,1]
col_num = 3
X = X[np.argsort(X[:, col_num])]
cnt = 1
r_min = X[0,3]
for i in range(1,N):
if X[i,2] >= r_min:
cnt += 1
r_min = X[i,3]
print(cnt) | 0 | null | 45,724,139,030,670 | 62 | 237 |
from collections import defaultdict, deque
import sys, heapq, bisect, math, itertools, string, queue, copy, time
from fractions import gcd
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7
EPS = 10**-7
h, w = map(int, input().split())
ini_grid = []
ans = 0
for i in range(h):
s = list(input())
ini_grid.append(s)
dd = [(1, 0), (-1, 0), (0, 1), (0, -1)]
for i in range(h):
for j in range(w):
if ini_grid[i][j] == '.':
temp_grid = [row[:] for row in ini_grid]
dis_grid = [[-1]*w for i in range(h)]
dis_grid[i][j] = 0
dq = deque([(i, j, 0)])
temp_grid[i][j] = '#'
while dq:
curr = dq.popleft()
for di, dj in dd:
ni = curr[0] + di
nj = curr[1] + dj
if (0 <= ni <= h-1) and (0 <= nj <= w-1) and temp_grid[ni][nj] == '.':
temp_grid[ni][nj] = '#'
dis_grid[ni][nj] = curr[2] + 1
dq.append((ni, nj, curr[2] + 1))
if curr[2] + 1 > ans:
ans = curr[2] + 1
print(ans) | s = input()
q = int(input())
for _ in range(q):
x = input().split()
a, b = int(x[1]), int(x[2])
if x[0] == 'print':
print(s[a:b+1])
if x[0] == 'reverse':
s = s[:a] + ''.join(reversed(s[a:b+1])) + s[b+1:]
if x[0] == 'replace':
s = s[:a] + x[3] + s[b+1:] | 0 | null | 48,218,906,400,714 | 241 | 68 |
s = set()
for _ in range(int(input())):
s.add(input())
print(len(s))
| n = int(input())
x = [input() for i in range(n)]
print(len(list(set(x))))
| 1 | 30,375,174,243,052 | null | 165 | 165 |
import sys
from collections import Counter
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
l = read().decode().split()
c = Counter(l)
max = c.most_common()[0][1]
ans = [i[0] for i in c.items() if i[1] >= max]
print('\n'.join(sorted(ans))) | import sys
s = sys.stdin
cnt = 1
for i in s:
if int(i)== 0:
break
print("Case {0}: {1}".format(cnt,i),end="")
cnt += 1 | 0 | null | 35,240,796,000,482 | 218 | 42 |
a,b,c,d = map(int, input().split())
m = a*c
n = a*d
o = b*c
p = b*d
if(m>n and m>o and m>p):
print(m)
elif (n>m and n>o and n>p):
print(n)
elif (o> m and o>n and o>p):
print(o)
else:
print(p) | def A():
n = int(input())
print(-(-n//2))
A() | 0 | null | 31,240,697,932,492 | 77 | 206 |
num_list = list(map(int, input().split()))
num = num_list[0]
distance = num_list[1]
res = 0
for i in range(num):
nmb_list = list(map(int, input().split()))
if(nmb_list[0]*nmb_list[0]+nmb_list[1]*nmb_list[1] <= distance*distance):
res += 1
print(res) | #B問題
import math
distance = 0
ans = 0
n, d = map(int, input().split())
x = [input().split() for l in range(n)]
#リストの中にリストがある時→A[i][j]のように表現
for i in range(n):
distance = math.sqrt(pow(int(x[i][0]),2)+pow(int(x[i][1]),2))
if distance <= d:
ans += 1
print(ans) | 1 | 5,919,541,944,910 | null | 96 | 96 |
def resolve():
INF = 10 ** 18
N, M, L = map(int, input().split())
G = [[INF] * N for _ in range(N)]
for _ in range(M):
a, b, c = map(int, input().split())
a -= 1
b -= 1
G[a][b] = G[b][a] = c
for k in range(N):
for i in range(N):
for j in range(N):
G[i][j] = min(G[i][j], G[i][k] + G[k][j])
Cost = [[INF] * N for _ in range(N)]
for i in range(N):
for j in range(N):
if G[i][j] <= L:
Cost[i][j] = 1
for k in range(N):
for i in range(N):
for j in range(N):
Cost[i][j] = min(Cost[i][j], Cost[i][k] + Cost[k][j])
Q = int(input())
for _ in range(Q):
a, b = map(lambda x: int(x) - 1, input().split())
if Cost[a][b] == INF:
print(-1)
else:
print(Cost[a][b] - 1)
if __name__ == "__main__":
resolve()
| import numpy as np
from scipy.sparse.csgraph import floyd_warshall
N,M,L=map(int,input().split())
INF = 1 << 31
dist=np.array([[INF for _ in range(N)] for _ in range(N)])
for i in range(N):
dist[i][i]=0
for i in range(M):
a,b,c=map(int,input().split())
a-=1
b-=1
dist[a][b]=c
dist[b][a]=c
dist = floyd_warshall(dist)
for i in range(N):
for j in range(N):
if dist[i][j]<=L:
dist[i][j]=1
else:
dist[i][j]=INF
dist = floyd_warshall(dist)
dist[dist==INF]=0
#dist=dist.astype(int)
#print(dist)
Q=int(input())
ans=[0]*Q
for q in range(Q):
s,t=map(int,input().split())
s-=1
t-=1
ans[q]=int(dist[s][t]-1)
print(*ans,sep='\n')
| 1 | 173,112,654,475,710 | null | 295 | 295 |
N = int(input())
x = y = z = 1
ans = [0]*N
while True:
if x**2 + y**2 + z**2 + x*y + y*z + z*x > N:
break
while True:
if x**2 + y**2 + z**2 + x*y + y*z + z*x > N:
break
while True:
a = x**2 + y**2 + z**2 + x*y + y*z + z*x
if a <= N:
if x != y and y != z and z != x:
ans[a-1] += 6
elif x == y and y == z:
ans[a-1] += 1
else:
ans[a-1] += 3
z += 1
else:
break
y += 1
z = y
x += 1
z = y = x
for n in ans:
print(n) | from collections import Counter
N=int(input())
list1=list(map(int,input().split()))
dic1=Counter(list1)
def choose2(n):
return n*(n-1)/2
sum=0
for key in dic1:
sum+=choose2(dic1[key])
for i in list1:
print(int(sum-dic1[i]+1)) | 0 | null | 27,748,710,846,428 | 106 | 192 |
x = int(input())
y = x
while y % 360:
y += x
print(y//x) | # -*- coding: utf-8 -*-
x=int(input())
a=360
b=x
r=a%b
while r!=0:
a=b
b=r
r=a%b
lcm=x*360/b
k=int(lcm/x)
print(k) | 1 | 13,223,718,056,842 | null | 125 | 125 |
import sys
K=input()
if int(K)%2==0:
print(-1)
sys.exit()
S=int('7'*(len(K)))
ans=len(K)
K=int(K)
for i in range(10**6):
if S%K==0:
print(ans)
break
else:
S=(S*10)%K+7
ans+=1
else:
print(-1) | K = int(input())
mod = 7
for i in range(K):
mod = mod % K
if(mod == 0):
print(i+1)
exit()
else:
mod *=10
mod += 7
print("-1") | 1 | 6,071,486,832,852 | null | 97 | 97 |
N = int(input())
p_list = []
for i in range(N):
s = input().split(' ')
p_list.append(s)
X = input()
flg = False
time = 0
count = 0
for sound in p_list:
if sound[0] == X:
time = int(sound[1])
flg = True
if flg:
count += int(sound[1])
print(count-time) | n=int(input())
s=[]
t=[]
for i in range(n):
st,tt=input().split()
s.append(st)
t.append(int(tt))
x=str(input())
temp=0
ans=sum(t)
for i in range(n):
temp=temp+t[i]
if s[i]==x:
break
print(ans-temp) | 1 | 96,891,274,669,968 | null | 243 | 243 |
from collections import Counter
s = input()
n = len(s)
dp = [0]
mod = 2019
a = 0
for i in range(n):
a = a + int(s[n-i-1]) * pow(10, i, mod)
a %= mod
dp.append(a%mod)
ans = 0
c = Counter(dp)
for value in c.values():
ans += value * (value-1) / 2
print(int(ans)) | N = int(input())
S,T = input().split()
L = []
for n in range(N):
L.append(S[n])
L.append(T[n])
print(*L,sep="") | 0 | null | 71,229,645,645,872 | 166 | 255 |
def inverse(a, p):
a_, p_ = a, p
x, y = 1, 0
while p_:
t = a_ // p_
a_ -= t * p_
a_, p_ = p_, a_
x -= t * y
x, y = y, x
x %= p
return x
def solve():
N, M, K = map(int, input().split())
mod = 998244353
nCi = [1]
for i in range(1, N):
nCi.append(nCi[i - 1] * (N - i) * inverse(i, mod) % mod)
ans = 0
for k in range(K + 1):
n = N - k
ans += M * int(pow((M - 1), n - 1, mod)) * nCi[k]
ans %= mod
print(ans)
if __name__ == '__main__':
solve()
| MOD = 998244353
factorial = None
inverse_factorial = None
def modpow(a, p):
ans = 1
while p:
if p&1 == 1:
ans = (ans*a)%MOD
a = (a*a)%MOD
p >>= 1
return ans
def nCr(n, r):
if r == 0 or r == n:
return 1
return (((factorial[n]*inverse_factorial[n-r])%MOD)*inverse_factorial[r])%MOD
def init_nCr(max_n):
global factorial, inverse_factorial
factorial = [1]*(max_n+1)
inverse_factorial = [0]*(max_n+1)
for i in range(1, max_n+1):
factorial[i] = (factorial[i-1]*i)%MOD
inverse_factorial[i] = modpow(factorial[i], MOD-2)
init_nCr(2*10**5+1)
def read_int():
return int(input().strip())
def read_ints():
return list(map(int, input().strip().split(' ')))
def solve():
N, M, K = read_ints()
answer = 0
for k in range(0, K+1):
answer = (answer+M*modpow(M-1, N-1-k)*nCr(N-1, k))%MOD
return answer
if __name__ == '__main__':
print(solve())
| 1 | 23,209,211,438,720 | null | 151 | 151 |
D = int(input())
c = [int(i) for i in input().split()]
s = [[int(i) for i in input().split()] for _ in range(D)]
t = [int(input())-1 for _ in range(D)]
ans = 0
llst = [0]*26
def last(d,i): return llst[i]
for day,i in enumerate(range(D),1):
llst[t[i]] = day
ans += s[i][t[i]]
for j in range(26): ans -= c[j]*(day-last(day,j))
print(ans) | D = int(input())
c = [int(x) for x in input().split()]
s = []
for i in range(D):
s.append([int(x) for x in input().split()])
ans = 0
nissuu = [0] * 26
for i in range(D):
t = int(input())
for j in range(26):
if j == t-1:
nissuu[j] = 0
else:
nissuu[j] += 1
ans -= c[j]*nissuu[j]
ans += s[i][t-1]
print(ans) | 1 | 9,973,429,089,052 | null | 114 | 114 |
w=input()
c=0
while True:
t=input()
if t=='END_OF_TEXT':
print(c)
break
c+=t.lower().split().count(w)
| word = raw_input()
text = []
while True:
raw = raw_input()
if raw == "END_OF_TEXT":
break
text += raw.lower().split()
print(text.count(word))
# print(text.lower().split().count(word)) | 1 | 1,833,412,588,800 | null | 65 | 65 |
def main():
N = int(input())
if N%2==0:
print(N//2-1)
else:
print((N-1)//2)
if __name__ == '__main__':
main() | N = int(input())
cnt = 0
for i in range(1,N//2 + 1):
if N - i != i:
cnt += 1
print(cnt) | 1 | 153,206,991,580,940 | null | 283 | 283 |
board=[0,0,0,0,0,0,0,0,0]
board[0],board[1],board[2] = map(int,input().split())
board[3],board[4],board[5] = map(int,input().split())
board[6],board[7],board[8] = map(int,input().split())
for _ in range(int(input())):
x = int(input())
if x in board:
board[board.index(x)] = "X"
found = "No"
if board[0] == "X":
if board[1] == "X" and board[2] == "X":
found = "Yes"
elif board[4] == "X" and board[8] == "X":
found = "Yes"
elif board[3] == "X" and board[6] == "X":
found = "Yes"
if board[8] == "X":
if board[5] == "X" and board[2] == "X":
found = "Yes"
elif board[7] == "X" and board[6] == "X":
found = "Yes"
if board[4] == "X":
if board[1] == "X" and board[7] == "X":
found = "Yes"
elif board[3] == "X" and board[5] == "X":
found = "Yes"
elif board[2] == "X" and board[6] == "X":
found = "Yes"
print(found) | a,b = map(int, input().split())
if (a>b):
op = '>'
elif (a<b):
op = '<'
else:
op = '=='
print('a %s b' % op) | 0 | null | 30,274,297,089,864 | 207 | 38 |
import sys
def input():
return sys.stdin.readline().strip()
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7
def main():
N = int(input())
A = list(map(int, input().split()))
RGB = [1, 0, 0]
ans = 1
if A[0] !=0:
print(0)
return
for i in range(1, N):
a = A[i]
if a == 0:
if 0 in RGB:
j = RGB.index(a)
RGB[j] += 1
else:
print(0)
return
elif a not in RGB:
print(0)
return
else:
k = RGB.count(a)
ans *= k
ans %= MOD
j = RGB.index(a)
RGB[j] += 1
z = RGB.count(0)
if z == 0:
ans *= 6
ans %= MOD
elif z == 1:
ans *= 6
ans %= MOD
else:
ans *= 3
ans %= MOD
print(ans)
if __name__ == "__main__":
main()
| N=int(input())
l=list(map(int,input().split()))
ans=1
cnt=[0]*(N+1)
mod=10**9+7
cnt[0]=3
for i in l:
ans=ans*cnt[i]%mod
cnt[i]-=1
cnt[i+1]+=1
print(ans) | 1 | 130,424,786,723,868 | null | 268 | 268 |
a,b,c=map(int,input().split())
print(['No','Yes'][a<b<c]) | N=int(input())
K=set(input().split())
i=len(K)
if i==N:
print('YES')
else:
print('NO') | 0 | null | 36,969,695,360,112 | 39 | 222 |
N = int(input())
L = [i for i in range(1, N + 1) if i % 2 != 0]
A = len(L) / N
print(A) | n = int(input())
if n % 2 == 0:
print("{:.10f}".format((n/2)/n))
else:
print("{:.10f}".format((n//2+1)/n))
| 1 | 177,075,266,481,920 | null | 297 | 297 |
import sys
readline = sys.stdin.buffer.readline
a,b,c,k =list(map(int,readline().rstrip().split()))
if k <= a:
print(k)
elif k > a and k <= a + b:
print(a)
else:
print(a -(k-(a+b)))
| m = input("")
s = m.split(".")
sum = 0
if len(s) == 1 and int(m)>=0 and int(m)<10**200000:
for i in m :
sum = sum+int(i)
if sum % 9 == 0:
print("Yes")
else:
print("No") | 0 | null | 13,047,549,003,072 | 148 | 87 |
N,K = map(int,input().split())
def solve(n,k):
n %= k
return min(n,abs(n-k))
print(solve(N,K)) | N = int(input())
S, T = input().split()
L = [S[i]+T[i] for i in range(N)]
print(*L, sep="") | 0 | null | 75,574,882,672,500 | 180 | 255 |
n,k=map(int,input().split())
A=[int(input()) for i in range(n)]
def track_num(n):
cnt,track=0,1
for i in A:
if cnt+i>n:
track +=1
cnt=i
else:
cnt +=i
return track
def Binaryserch():
left,right=max(A),sum(A)+1
ans=0
while left<right:
mid=(left+right)//2
track=track_num(mid)
if track<=k:
ans=mid
right=mid
elif track>k:
left=mid+1
return ans
print(Binaryserch())
| def ok(a, n, k, p):
t = 0
t_cnt = 0
for w in a:
if p < w:
return -1
if t + w > p:
t_cnt += 1
if t_cnt >= k:
return -1
t = w
else:
t += w
return 0
n, k = map(int, input().split())
a = [int(input()) for _ in range(n)]
P_max = n * 10000 // k + 10001
l = 0
r = P_max
m = 0
while l < r - 1:
m = (l + r) // 2
if ok(a, n, k, m) == 0:
r = m
else:
l = m
print(r)
| 1 | 91,216,914,010 | null | 24 | 24 |
N, M = map(int, input().split())
S = list(reversed(input()))
ans = []
cur = 0
while cur < N:
for m in range(M, 0, -1):
ncur = cur + m
if ncur <= N and S[ncur] == '0':
ans.append(m)
cur = ncur
break
else:
print(-1)
exit()
print(*reversed(ans))
| N,M,K=map(int,input().split())
*A,=map(int,input().split())
*B,=map(int,input().split())
def binary_search(func, array, left=0, right=-1):
if right==-1:right=len(array)-1
y_left, y_right = func(array[left]), func(array[right])
while True:
middle = (left+right)//2
y_middle = func(array[middle])
if y_left==y_middle: left=middle
else: right=middle
if right-left==1:break
return left
cumA = [0]
for i in range(N):
cumA.append(cumA[-1]+A[i])
cumB = [0]
for i in range(M):
cumB.append(cumB[-1]+B[i])
cumB.append(10**20)
if cumA[-1]+cumB[-1]<=K:
print(N+M)
exit()
if A[0] > K and B[0] > K:
print(0)
exit()
ans = 0
for i in range(N+1):
if K-cumA[i]<0:break
idx = binary_search(lambda x:x<=K-cumA[i],cumB)
res = max(0,i+idx)
ans = max(ans, res)
print(ans) | 0 | null | 75,030,790,965,020 | 274 | 117 |
n=int(input())
print('Yes' if n>=30 else 'No') | import sys
N,M = map(int,input().split())
s = [0] * M
c = [0] * M
a = ["-1"] * (N)
if N == 1 and M == 0:
print(0)
sys.exit()
for i in range(M):
s[i],c[i] = map(int,input().split())
for j in range(M):
if s[j] == 1 and c[j] == 0 and N != 1:
print(-1)
sys.exit()
elif a[s[j]-1] == "-1":
a[s[j]-1] = str(c[j])
elif a[s[j]-1] == str(c[j]):
pass
else:
print(-1)
sys.exit()
if a[0] == "-1":
a[0] = "1"
for h in range(1,N):
if a[h] == "-1":
a[h] = "0"
ans = "".join(a)
print(int(ans)) | 0 | null | 33,201,125,749,408 | 95 | 208 |
import sys
from time import time
from random import randrange, random
input = lambda: sys.stdin.buffer.readline()
DEBUG_MODE = False
st = time()
def get_time():
return time() - st
L = 26
D = int(input())
C = list(map(int, input().split()))
S = [list(map(int, input().split())) for _ in range(D)]
ans = [randrange(L) for _ in range(D)]
class BinaryIndexedTree:
def __init__(self, n):
self.n = n
self.data = [0] * (self.n+1)
def sum(self, i):
res = 0
while i > 0:
res += self.data[i]
i -= i & -i
return res
def add(self, i, x):
if i <= 0: raise IndexError
while i <= self.n:
self.data[i] += x
i += i & -i
def lower_bound(self, x):
if x <= 0: return 0
cur, s, k = 0, 0, 1 << (self.n.bit_length()-1)
while k:
nxt = cur + k
if nxt <= self.n and s + self.data[nxt] < x:
s += self.data[nxt]
cur = nxt
k >>= 1
return cur + 1
def rsum(x):
return x*(x+1)//2
b = [BinaryIndexedTree(D) for _ in range(L)]
score = 0
for d, cont in enumerate(ans):
b[cont].add(d+1, 1)
score += S[d][cont]
for i in range(L):
m = b[i].sum(D)
tmp = 0
s = [0]
for j in range(1, m+1):
s.append(b[i].lower_bound(j))
s.append(D+1)
for j in range(len(s)-1):
x = s[j+1] - s[j] - 1
tmp += rsum(x)
score -= tmp*C[i]
def chg(d, p, q):
diff = 0
d += 1
o = b[p].sum(d)
d1 = b[p].lower_bound(o-1)
d2 = b[p].lower_bound(o+1)
diff += rsum(d-d1) * C[p]
diff += rsum(d2-d) * C[p]
diff -= rsum(d2-d1) * C[p]
o = b[q].sum(d)
d1 = b[q].lower_bound(o)
d2 = b[q].lower_bound(o+1)
diff += rsum(d2-d1) * C[q]
diff -= rsum(d-d1) * C[q]
diff -= rsum(d2-d) * C[q]
d -= 1
diff -= S[d][p]
diff += S[d][q]
ans[d] = q
b[p].add(d+1, -1)
b[q].add(d+1, 1)
return diff
while True:
if random() >= 0.8:
d, q = randrange(D), randrange(L)
p = ans[d]
diff = chg(d, p, q)
if diff > 0:
score += diff
else:
chg(d, q, p)
else:
d1 = randrange(D-1)
d2 = randrange(d1+1, min(d1+3, D))
p, q = ans[d1], ans[d2]
diff = chg(d1, p, q)
diff += chg(d2, q, p)
if diff > 0:
score += diff
else:
chg(d1, q, p)
chg(d2, p, q)
if DEBUG_MODE: print(score)
if get_time() >= 1.7: break
if DEBUG_MODE: print(score)
else:
for x in ans: print(x+1)
| H,A=map(int,input().split())
if H%A>0:
print((H//A)+1)
elif H%A==0:
print(H//A) | 0 | null | 43,504,071,453,380 | 113 | 225 |
def main3():
N = int(input())
ans = 0
for a in range(1, N):
ans += (N-1)//a
print(ans)
if __name__ == "__main__":
main3() | n=int(input())
A=list(map(int,input().split()) )
q=int(input())
B=[]
C=[]
a_sum = sum(A)
counter = [0]*10**5
for a in A:
counter[a-1] += 1
for i in range(q):
b,c = map(int,input().split())
a_sum += (c-b) * counter[b-1]
counter[c-1]+=counter[b-1]
counter[b-1]=0
print(a_sum)
| 0 | null | 7,449,091,849,262 | 73 | 122 |
import sys
MOD = 10**9+7
def main():
input = sys.stdin.readline
N,K=map(int, input().split())
ans=Mint()
cnt=[Mint() for _ in range(K+1)]
for g in range(K,0,-1):
cnt[g]+=pow(K//g,N,MOD)
for h in range(g+g,K+1,g):
cnt[g]-=cnt[h]
ans+=g*cnt[g]
print(ans)
class Mint:
def __init__(self, value=0):
self.value = value % MOD
if self.value < 0: self.value += MOD
@staticmethod
def get_value(x): return x.value if isinstance(x, Mint) else x
def inverse(self):
a, b = self.value, MOD
u, v = 1, 0
while b:
t = a // b
b, a = a - t * b, b
v, u = u - t * v, v
if u < 0: u += MOD
return u
def __repr__(self): return str(self.value)
def __eq__(self, other): return self.value == other.value
def __neg__(self): return Mint(-self.value)
def __hash__(self): return hash(self.value)
def __bool__(self): return self.value != 0
def __iadd__(self, other):
self.value = (self.value + Mint.get_value(other)) % MOD
return self
def __add__(self, other):
new_obj = Mint(self.value)
new_obj += other
return new_obj
__radd__ = __add__
def __isub__(self, other):
self.value = (self.value - Mint.get_value(other)) % MOD
if self.value < 0: self.value += MOD
return self
def __sub__(self, other):
new_obj = Mint(self.value)
new_obj -= other
return new_obj
def __rsub__(self, other):
new_obj = Mint(Mint.get_value(other))
new_obj -= self
return new_obj
def __imul__(self, other):
self.value = self.value * Mint.get_value(other) % MOD
return self
def __mul__(self, other):
new_obj = Mint(self.value)
new_obj *= other
return new_obj
__rmul__ = __mul__
def __ifloordiv__(self, other):
other = other if isinstance(other, Mint) else Mint(other)
self *= other.inverse()
return self
def __floordiv__(self, other):
new_obj = Mint(self.value)
new_obj //= other
return new_obj
def __rfloordiv__(self, other):
new_obj = Mint(Mint.get_value(other))
new_obj //= self
return new_obj
if __name__ == '__main__':
main() | x = input()
y = x.split(" ")
y[0] = int(y[0])
y[1] = int(y[1])
if y[0] < y[1]:
print("a < b")
elif y[0] > y[1]:
print("a > b")
else:
print("a == b") | 0 | null | 18,536,904,487,012 | 176 | 38 |
from math import ceil
from bisect import bisect_right
n, d, a = map(int, input().split())
l = []
l2 = []
l3 = []
l4 = [0 for i in range(n+1)]
l5 = [0 for i in range(n+1)]
ans = 0
for i in range(n):
x, h = map(int, input().split())
l.append([x, h])
l2.append(x + 2 * d)
l3.append(x)
l.sort(key=lambda x: x[0])
l2.sort()
l3.sort()
for i in range(n):
cnt = ceil((l[i][1] - l4[i] * a) / a)
if cnt > 0:
ans += cnt
ind = bisect_right(l3, l2[i])
l5[ind] += cnt
l4[i] += cnt
l4[i+1] = l4[i] - l5[i+1]
print(ans) | if __name__ == '__main__':
N, M = map(int, input().split())
A = list(map(int, input().split()))
A = sorted(A)[::-1]
s = sum(A)
cnt = 0
for i in range(M):
if s<=4*M*A[i]:
cnt += 1
if cnt==M:
print("Yes")
else:
print("No")
| 0 | null | 60,456,385,546,780 | 230 | 179 |
a = input()
b = a.split(' ')
b[0] = int(b[0])
b[1] = int(b[1])
b[2] = int(b[2])
b.sort()
print(str(b[0])+' '+str(b[1])+' '+str(b[2])) | a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(range(1,a[0]+1))
dict = dict(zip(b,c))
for i in range(len(b)):
print(dict.get(i+1),end=" ") | 0 | null | 90,886,621,437,042 | 40 | 299 |
n = int(input())
x = n%10
if (x == 2 or x == 4 or x == 5 or x == 7 or x == 9):
print("hon")
elif (x == 0 or x == 1 or x == 6 or x == 8):
print("pon")
else:
print("bon") | d = {n: 'hon' for n in "24579"}
d.update({n: 'pon' for n in "0168"})
d.update({"3": 'bon'})
print(d[input()[-1]]) | 1 | 19,186,135,428,608 | null | 142 | 142 |
N=int(input())
L=list(map(int,input().split()))
L.sort()
from bisect import bisect_left
ans = 0
for i1 in range(N-2):
for i2 in range(i1+1,N-1):
l1,l2 = L[i1],L[i2]
#th = bisect_left(L[i2+1:],l1+l2)
#print(l1,l2,L[i2+1:],(l2-l1+1)*(-1),th)
th = bisect_left(L,l1+l2)
ans += max(th-i2-1,0)
print(ans) | import bisect
N = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
for i in range(N - 1):
for j in range(i + 1, N):
p = l[:i]
a, b = l[i], l[j]
low = b - a + 1
high = a + b
ans += bisect.bisect_left(p, high) - bisect.bisect_left(p, low)
print(ans) | 1 | 172,403,044,828,312 | null | 294 | 294 |
def resolve():
N, X, M = map(int,input().split())
A_list = [X]
preA = X
A_set = set(A_list)
for i in range(N-1):
A = preA**2%M
if A == 0:
answer = sum(A_list)
break
elif A in A_set:
finished_count = len(A_list)
# 何番目か確認
same_A_index = A_list.index(A)
one_loop = A_list[same_A_index:]
loop_count, part_loop = divmod(N-finished_count, len(one_loop))
answer = sum(A_list) + sum(one_loop)*loop_count + sum(one_loop[:part_loop])
break
A_list.append(A)
A_set.add(A)
preA = A
else:
answer = sum(A_list)
print(answer)
resolve() | W,H,x,y,r =map(int,input().split())
if (r<=x and x+r<=W and r<=y and y+r<=H):
print("Yes")
else:
print("No")
| 0 | null | 1,628,312,992,702 | 75 | 41 |
import sys
for e in sys.stdin:
a, b = map(int, e.split())
p = a * b
while b:
a, b = b, a%b
pass
print (a,p//a)
| a=int(input())
b = int(input())
s = set([1,2,3])
s.remove(a)
s.remove(b)
print(*s) | 0 | null | 55,459,182,449,582 | 5 | 254 |
a=input()
print(a.replace("?","D"))
| pd = list(input())
for i in range(len(pd)):
if '?' in pd[i]:
pd[i] = 'D'
print(pd[i], end = '') | 1 | 18,495,637,775,420 | null | 140 | 140 |
w,h,x,y,r=map(int,raw_input().split())
if min(x,y,w-x,h-y)<r:
print 'No'
else:
print 'Yes' | import math
a,b,c=map(int,input().split())
if 4*a*b < (c-a-b)**2 and c > a+b:
print('Yes')
else:
print('No') | 0 | null | 25,994,883,184,502 | 41 | 197 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.