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
|
---|---|---|---|---|---|---|
n,k=map(int,input().split())
a=list(map(int,input().split()))
dp=[0]
mp={0:1}
ans=0
for t in range(n):
i=a[t]
if t>=k-1:
mp[dp[-k]]-=1
num=(dp[-1]+i-1)%k
if num in mp.keys():
ans += mp[num]
mp[num] += 1
else:
mp[num] = 1
dp.append(num)
print(ans) | N = int(input())
A = list(map(int,input().split()))
MOD = 10**9 + 7
S = sum(A)
ans = 0
for i in range(N):
S = S - A[i]
ans += A[i]*S
print(ans%MOD) | 0 | null | 70,747,835,430,622 | 273 | 83 |
rc=list(map(int,input().split()))
sheet=[list(map(int,input().split()))+[0] for i in range(rc[0])]
sheet.append([0 for i in range(rc[1]+1)])
for s in sheet:
s[-1]=sum(s[0:-1])
for i in range(rc[1]+1):
r=sum([n[i] for n in sheet[0:-1]])
sheet[-1][i]=r
for sh in sheet:
print(*sh) | # -*- coding: utf-8 -*-
r, c = map(int, raw_input().split())
cl= [0] * c
for i in xrange(r):
t = map(int, raw_input().split())
for i, a in enumerate(t): cl[i] += a
print ' '.join(map(str, t)), sum(t)
print ' '.join(map(str, cl)), sum(cl) | 1 | 1,333,884,115,588 | null | 59 | 59 |
def find(X):
rate = X//200
return 10-rate
print(find(int(input()))) | #!usr/bin/env python3
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007
def solve():
x = I()
if 599 >= x >= 400:
print(8)
elif 799 >= x >= 600:
print(7)
elif 999 >= x >= 800:
print(6)
elif 1199 >= x >= 1000:
print(5)
elif 1399 >= x >= 1200:
print(4)
elif 1599 >= x >= 1400:
print(3)
elif 1799 >= x >= 1600:
print(2)
elif 1999 >= x >= 1800:
print(1)
return
# Solve
if __name__ == "__main__":
solve()
| 1 | 6,745,306,927,720 | null | 100 | 100 |
s = input().split()
st = []
for i in range(len(s)):
c = s.pop(0)
if c == '+':
b = st.pop(0)
a = st.pop(0)
ans = a + b
st.insert(0,ans)
elif c == '-':
b = st.pop(0)
a = st.pop(0)
ans = a - b
st.insert(0,ans)
elif c == '*':
b = st.pop(0)
a = st.pop(0)
ans = a * b
st.insert(0,ans)
else:
st.insert(0, int(c))
print(st.pop(0))
| # -*- coding:utf-8 -*-
stack = list()
def deal_expression(x):
if x.isdigit():
stack.append(int(x))
else:
a = stack.pop()
b = stack.pop()
if x == '+':
stack.append(b + a)
elif x == '-':
stack.append(b - a)
elif x == '*':
stack.append(b * a)
elif x == '/':
stack.append(b / a)
for x in input().split():
deal_expression(x)
print(stack[0]) | 1 | 34,648,312,050 | null | 18 | 18 |
import sys
from bisect import *
from heapq import *
from collections import *
from itertools import *
from functools import *
sys.setrecursionlimit(100000000)
def input(): return sys.stdin.readline().rstrip()
N = int(input())
def f(x):
ans = set()
i = 1
while i * i <= x:
if x % i == 0:
ans.add(i)
i += 1
for i in ans.copy():
ans.add(x // i)
return ans
ans = set()
for K in f(N) | f(N - 1):
if K == 1:
continue
n = N
while n % K == 0:
n //= K
if n % K == 1:
ans.add(K)
print(len(ans))
| def getN():
return int(input())
def getNM():
return map(int, input().split())
def getList():
return list(map(int, input().split()))
def getArray(intn):
return [int(input()) for i in range(intn)]
def input():
return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
ns = []
while len(ns) < rantime:
n = random.randint(ran1, ran2)
if not n in ns:
ns.append(n)
return sorted(ns)
def rand_query(ran1, ran2, rantime):
r_query = []
while len(r_query) < rantime:
n_q = rand_ints_nodup(ran1, ran2, 2)
if not n_q in r_query:
r_query.append(n_q)
return sorted(r_query)
from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right
import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7
#############
# Main Code #
#############
def prime_factorize(n):
divisors = []
# 27(2 * 2 * 7)の7を出すためにtemp使う
temp = n
for i in range(2, int(math.sqrt(n)) + 1):
if temp % i == 0:
cnt = 0
while temp % i == 0:
cnt += 1
# 素因数を見つけるたびにtempを割っていく
temp //= i
divisors.append([i, cnt])
if temp != 1:
divisors.append([temp, 1])
if divisors == []:
divisors.append([n, 1])
return divisors
def make_divisors(n):
divisors = []
for i in range(1, int(math.sqrt(n)) + 1):
if n % i == 0:
divisors.append(i)
# √nで無い数についてもう一個プラス
if i != n // i:
divisors.append(n // i)
return sorted(divisors)
N = getN()
# 手順としては
# ① kで出来るだけ割る
# ② kで引いていく N = mk + d(d = 1, 2, 3...)とすると, 引いて残る数はm(k - 1) + d
# つまりkで割り切れず、引いても引いても永遠に①に戻ることはない
# N = k ** i * (mk + 1)となるkの数を求める
# i == 0の時
# N - 1の約数の数 - 1(1)
ans = set()
for i in make_divisors(N - 1):
if i != 1:
ans.add(i)
# 割れるだけ割る関数
def dividor(x, k):
if k == 1:
return 0
n = x
while True:
if n % k == 0:
n //= k
else:
break
return n
# i >= 1の時
for prim in make_divisors(N):
if prim == 1:
continue
# Nを割れるだけ割る
alta = dividor(N, prim)
if alta == 1:
ans.add(prim)
continue
if alta >= prim and alta % prim == 1:
ans.add(prim)
# Nが素数でない場合はN自身が追加されない
ans.add(N)
print(len(ans)) | 1 | 41,399,008,377,700 | null | 183 | 183 |
import statistics
def stddev(values):
""" calculate standard deviation
>>> s = stddev([70, 80, 100, 90, 20])
>>> print('{:.5f}'.format(s))
27.85678
>>> s = stddev([80, 80, 80])
>>> print('{:.5f}'.format(s))
0.00000
"""
return statistics.pstdev(values)
def run():
while True:
c = int(input()) # flake8: noqa
if c == 0:
break
values = [int(i) for i in input().split()]
print(stddev(values))
if __name__ == '__main__':
run()
| if __name__ == '__main__':
from statistics import pstdev
while True:
# ??????????????\???
data_count = int(input())
if data_count == 0:
break
scores = [int(x) for x in input().split(' ')]
# ?¨??????????????¨????
result = pstdev(scores)
# ???????????????
print('{0:.8f}'.format(result)) | 1 | 190,392,565,740 | null | 31 | 31 |
from collections import deque,defaultdict,Counter
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from bisect import bisect_left,bisect_right
from math import sqrt,gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
from statistics import mean,median,mode
import sys
sys.setrecursionlimit(10 ** 6)
INF = float("inf")
def mycol(data,col):
return [ row[col] for row in data ]
def mysort(data,col,reverse=False):
data.sort(key=lambda x:x[col],reverse=revese)
return data
def mymax(data):
M = -1*float("inf")
for i in range(len(data)):
m = max(data[i])
M = max(M,m)
return M
def mymin(data):
m = float("inf")
for i in range(len(data)):
M = min(data[i])
m = min(m,M)
return m
def mycount(ls,x):
# lsはソート済みであること
l = bisect_left(ls,x)
r = bisect_right(ls,x)
return (r-l)
def mydictvaluesort(dictionary):
return sorted( dictionary.items(), key=lambda x:x[1] )
def mydictkeysort(dictionary):
return sorted( dictionary.items(), key=lambda x:x[0] )
def myoutput(ls,space=True):
if space:
if len(ls)==0:
print(" ")
elif type(ls[0])==str:
print(" ".join(ls))
elif type(ls[0])==int:
print(" ".join(map(str,ls)))
else:
print("Output Error")
else:
if len(ls)==0:
print("")
elif type(ls[0])==str:
print("".join(ls))
elif type(ls[0])==int:
print("".join(map(str,ls)))
else:
print("Output Error")
def I():
return int(input())
def MI():
return map(int,input().split())
def RI():
return list(map(int,input().split()))
def CI(n):
return [ int(input()) for _ in range(n) ]
def LI(n):
return [ list(map(int,input().split())) for _ in range(n) ]
def S():
return input()
def MS():
return input().split()
def RS():
return list(input())
def CS(n):
return [ input() for _ in range(n) ]
def LS(n):
return [ list(input()) for _ in range(n) ]
# ddict = defaultdict(lambda: 0)
# ddict = defaultdict(lambda: 1)
# ddict = defaultdict(lambda: int())
# ddict = defaultdict(lambda: list())
# ddict = defaultdict(lambda: float())
n,k = MI()
a = RI()
L = max(a)
def mycheck(l):
count = 0
for i in range(n):
count += a[i]//l
return count <= k
lb = 0
ub = L
for i in range(100):
# print(ub,lb)
mid = (lb+ub)/2
# print(mid)
flag = mycheck(mid)
# print(flag)
if flag:
ub = mid
else:
lb = mid
ans = ceil(lb)
print(ans) | n = int(input())
dic = set()
for i in range(n):
x = input()
if 'insert' in x:
dic.add(x.strip('insert '))
else :
if x.strip('find ') in dic:
print('yes')
else :
print('no')
| 0 | null | 3,296,476,538,140 | 99 | 23 |
from decimal import Decimal
l=int(input())
print(Decimal((l/3)**3)) | r = input()
if len(r) & 1:
print("No")
else:
for i in range(0, len(r), 2):
if not (r[i] == 'h' and r[i + 1]=='i'):
print("No")
exit()
print("Yes") | 0 | null | 50,383,665,971,548 | 191 | 199 |
# -*- coding: utf-8 -*-
import math
import itertools
import sys
import copy
# 入力
#A, B, C, D = map(int, input().split())
#L = list(map(int, input().split()))
#S = list(str(input()))
#N = int(input())
X, Y = map(int, input().split())
sum = 0
if X == 1 :
sum += 300000
elif X == 2 :
sum += 200000
elif X == 3 :
sum += 100000
if Y == 1 :
sum += 300000
elif Y == 2 :
sum += 200000
elif Y == 3 :
sum += 100000
if X == 1 and Y == 1 :
sum += 400000
print (sum)
| import math
x_1,y_1,x_2,y_2 =map(float,raw_input().split())
print (math.sqrt(math.pow(x_2-x_1,2)+math.pow(y_2-y_1,2))) | 0 | null | 70,286,854,360,612 | 275 | 29 |
def fibonacciDP(i):
if i == 0:
return 1
elif i == 1:
return 1
else:
if dp[i-1] is None and dp[i-2] is None:
dp[i-1] = fibonacciDP(i-1)
dp[i-2] = fibonacciDP(i-2)
elif dp[i-1] is None:
dp[i-1] = fibonacciDP(i-1)
elif dp[i-2] is None:
dp[i-2] = fibonacciDP(i-2)
return dp[i-1]+ dp[i-2]
def fibonacci(i):
if i == 0:
return 1
elif i == 1:
return 1
else:
return fibonacci(i-1)+fibonacci(i-2)
n = int(input())
dp = [None]*n
print(fibonacciDP(n)) | a=b=1
for _ in range(int(input())):a,b=b,a+b
print(a) | 1 | 2,061,791,780 | null | 7 | 7 |
n = int(input())
ans = 0
for a in range(1,n):
if n%a == 0:
ans += n//a -1
else:
ans += n//a
print(ans)
| r, c = [int(s) for s in input().split()]
rows = [[0 for i in range(c + 1)] for j in range(r + 1)]
for rc in range(r):
in_row = [int(s) for s in input().split()]
for cc, val in enumerate(in_row):
rows[rc][cc] = val
rows[rc][-1] += val
rows[-1][cc] += val
rows[-1][-1] += val
for row in rows:
print(' '.join([str(i) for i in row])) | 0 | null | 1,998,469,501,370 | 73 | 59 |
import bisect
N=int(input())
L=list(map(int,input().split()))
L=sorted(L)
ans=0
for i in range(N-1):
for k in range(i+1,N-1):
a=L[i]+L[k]
b=bisect.bisect_left(L,a)
ans=ans+(b-k-1)
print(ans) |
def findnumberofTriangles(arr):
n = len(arr)
arr.sort()
count = 0
for i in range(0, n-2):
k = i + 2
for j in range(i + 1, n):
while (k < n and arr[i] + arr[j] > arr[k]):
k += 1
if(k>j):
count += k - j - 1
return count
n = int(input())
arr=[int(x) for x in input().split()]
print(findnumberofTriangles(arr))
| 1 | 172,338,749,516,010 | null | 294 | 294 |
days, num = map(int, input().split())
hw = list(map(int, input().split()))
hang = days - sum(hw)
if hang < 0:
print("-1")
else:
print(hang) | X,Y = map(int, input().split())
if X * 2 > Y:
print('No')
elif X * 4 < Y:
print('No')
else:
for i in range(0,X+1):
if Y == (X * 2) + (i * 2):
print('Yes')
break
else:
print('No')
| 0 | null | 22,833,660,075,278 | 168 | 127 |
n = -100
i = 1
while n != 0:
n = int(raw_input())
if n != 0:
print 'Case %d: %d' %(i,n)
i = i + 1 | # -*- coding: utf-8 -*-
x = []
while ( 1 ):
temp = int( input() )
if (temp == 0):
break
x.append(temp)
index = 1
for i in x:
print('Case {0}: {1}'.format(index, i))
index += 1 | 1 | 490,629,102,560 | null | 42 | 42 |
#!/usr/bin/env python3
S = input()
total = 0
for i in range(len(S)):
if "R" * (i + 1) in S:
total = i + 1
ans = total
print(ans)
| a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())
if v <= w:
print('NO')
elif (abs(a-b) / (v-w)) <= t:
print('YES')
else:
print('NO') | 0 | null | 10,036,681,374,850 | 90 | 131 |
from itertools import accumulate
from bisect import *
n, m, *a = map(int, open(0).read().split())
a = [-x for x in a]
a.sort()
acc = list(accumulate(a)) + [0]
l = 0
r = 2 * 10 ** 5 + 1
while r - l > 1:
mid = (l + r) // 2
border = n - 1
cnt = 0
for x in a:
while x + a[border] > -mid:
border -= 1
if border < 0:
break
if border < 0:
break
cnt += border + 1
if cnt >= m:
break
if cnt >= m:
l = mid
else:
r = mid
ans = tot = 0
for x in a:
b = bisect(a, -l - x)
tot += b
ans += acc[b - 1] + x * b
ans += l * (tot - m)
print(-ans)
| def merge(A,left,mid,right):
global cnt
L=A[left:mid]
R=A[mid:right]
L.append(float("inf"))
R.append(float("inf"))
i=0
j=0
for k in range(left, right):
cnt+=1
if L[i]<=R[j]:
A[k]=L[i]
i+=1
else:
A[k]=R[j]
j+=1
def mergeSort(A,left,right):
if left+1<right:
mid=(left+right)//2
mergeSort(A,left,mid)
mergeSort(A,mid,right)
merge(A,left,mid,right)
n = int(input())
S=list(map(int,input().split()))
cnt=0
mergeSort(S,0,n)
print(" ".join(map(str,S)))
print(cnt) | 0 | null | 54,123,946,479,330 | 252 | 26 |
import sys
from scipy.sparse.csgraph import floyd_warshall
N, M, L = map(int, input().split())
INF = 10 **9 +1
G = [[float('inf')] * N for i in range(N)]
for i in range(M):
a, b, c = map(int, input().split())
a, b, = a - 1, b -1
G[a][b] = c
G[b][a] = c
#全点間最短距離を計算
G = floyd_warshall(G)
#コストL以下で移動可能な頂点間のコスト1の辺を張る
E = [[float('inf')] * N for i in range(N)]
for i in range(N):
for j in range(N):
if G[i][j] <= L:
E[i][j] = 1
#全点間最短距離を計算
E = floyd_warshall(E)
#クエリに答えていく
Q = int(input())
for i in range(Q):
s, t = map(int, input().split())
s, t = s - 1, t-1
print(int(E[s][t] - 1) if E[s][t] != float('inf') else -1) | import sys
readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)
def main():
from collections import defaultdict
n, m, l = map(int, readline().split())
dist = [[INF] * n for _ in range(n)]
for _ in range(m):
a, b, c = map(int, readline().split())
a, b = a - 1, b - 1
dist[a][b] = c
dist[b][a] = c
for k in range(n):
for i in range(n):
for j in range(n):
dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
dist2 = [[INF] * n for _ in range(n)]
for i in range(n):
for j in range(n):
if dist[i][j] <= l:
dist2[i][j] = 1
for k in range(n):
for i in range(n):
for j in range(n):
dist2[i][j] = min(dist2[i][j], dist2[i][k] + dist2[k][j])
q = int(readline())
for _ in range(q):
s, t = map(int, readline().split())
s, t = s - 1, t - 1
if dist2[s][t] == INF:
print(-1)
else:
print(dist2[s][t] - 1)
if __name__ == '__main__':
main()
| 1 | 173,959,477,040,700 | null | 295 | 295 |
x, n = map(int, input().split())
lis = []
if n == 0:
print(x)
else:
lis = list(map(int, input().split()))
if x not in lis:
print(x)
else:
y = x + 1
z = x - 1
while True:
if y in lis and z in lis:
y += 1
z -= 1
elif z not in lis:
print(z)
break
elif y not in lis:
print(y)
break
| from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
# INF = float("inf")
INF = 10**18
import bisect
import statistics
mod = 10**9+7
# mod = 998244353
A = map(int, input().split())
if sum(A) >= 22:
print("bust")
else:
print("win")
| 0 | null | 66,213,457,099,662 | 128 | 260 |
from typing import List
class Dice:
def __init__(self, surface: List[int]):
self.surface = surface
def get_upper_sursurface(self) -> int:
return self.surface[0]
def invoke_method(self, mkey: str) -> None:
if mkey == 'S':
self.S()
return None
if mkey == 'N':
self.N()
return None
if mkey == 'E':
self.E()
return None
if mkey == 'W':
self.W()
return None
raise ValueError(f'This method does not exist. : {mkey}')
def S(self) -> None:
tmp = [i for i in self.surface]
self.surface[0] = tmp[4]
self.surface[1] = tmp[0]
self.surface[2] = tmp[2]
self.surface[3] = tmp[3]
self.surface[4] = tmp[5]
self.surface[5] = tmp[1]
def N(self) -> None:
tmp = [i for i in self.surface]
self.surface[0] = tmp[1]
self.surface[1] = tmp[5]
self.surface[2] = tmp[2]
self.surface[3] = tmp[3]
self.surface[4] = tmp[0]
self.surface[5] = tmp[4]
def E(self) -> None:
tmp = [i for i in self.surface]
self.surface[0] = tmp[3]
self.surface[1] = tmp[1]
self.surface[2] = tmp[0]
self.surface[3] = tmp[5]
self.surface[4] = tmp[4]
self.surface[5] = tmp[2]
def W(self) -> None:
tmp = [i for i in self.surface]
self.surface[0] = tmp[2]
self.surface[1] = tmp[1]
self.surface[2] = tmp[5]
self.surface[3] = tmp[0]
self.surface[4] = tmp[4]
self.surface[5] = tmp[3]
# 提出用
data = [int(i) for i in input().split()]
order = list(input())
# # 動作確認用
# data = [int(i) for i in '1 2 4 8 16 32'.split()]
# order = list('EESWN')
dice = Dice(data)
for o in order:
dice.invoke_method(o)
print(dice.get_upper_sursurface())
| class Dice:
def __init__(self,t,f,r,l,b,u):
self.t=t
self.f=f
self.r=r
self.l=l
self.b=b
self.u=u
def roll(self,i):
if d=='S':
key=self.t
self.t=self.b
self.b=self.u
self.u=self.f
self.f=key
elif d=='E':
key=self.t
self.t=self.l
self.l=self.u
self.u=self.r
self.r=key
elif d=='N':
key=self.t
self.t=self.f
self.f=self.u
self.u=self.b
self.b=key
else:
key=self.t
self.t=self.r
self.r=self.u
self.u=self.l
self.l=key
t,f,r,l,b,u=map(int,input().split())
a=list(input())
dice=Dice(t,f,r,l,b,u)
for d in a:
dice.roll(d)
print(dice.t)
| 1 | 231,643,746,730 | null | 33 | 33 |
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
b = 0
tb = 0
for i in range(M):
if tb + B[i] > K:
break
tb += B[i]
b = i+1
ans = [0, b]
m = b
a = 0
ta = 0
for i in range(N):
if ta + A[i] > K:
break
a = i+1
ta += A[i]
while True:
if ta + tb > K:
if b == 0:break
b -= 1
tb -= B[b]
else:
if a + b > m:
m = a + b
ans = [a, b]
break
print(ans[0]+ans[1])
| import itertools
import bisect
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a_acc = [0] + list(itertools.accumulate(a))
b_acc = [0] + list(itertools.accumulate(b))
ans = 0
for i in range(n+1):
if k - a_acc[i] >= 0:
ans = max(ans, i + bisect.bisect(b_acc, k - a_acc[i])-1)
print(ans)
| 1 | 10,770,467,915,312 | null | 117 | 117 |
# 2020-05-22
def main():
n, m, k = [int(x) for x in input().split()]
friends = [set() for _ in range(n)]
blocks = [set() for _ in range(n)]
for _ in range(m):
a, b = [int(x) - 1 for x in input().split()]
friends[a].add(b)
friends[b].add(a)
for _ in range(k):
a, b = [int(x) - 1 for x in input().split()]
blocks[a].add(b)
blocks[b].add(a)
networks = {} # The dict of networks as sets. Keys are leaders.
net_leaders = [-1] * n # The leaders of the networks that the ones joined.
visited = [False] * n
for person in range(n):
if visited[person]:
continue
network = set()
stack = [person]
while stack:
new = stack.pop()
visited[new] = True
net_leaders[new] = person
network.add(new)
for adj in friends[new]:
if visited[adj]:
continue
stack.append(adj)
networks[person] = network
answers = []
for person in range(n):
net = networks[net_leaders[person]]
ans = len(net) - len(friends[person]) - 1
for block in blocks[person]:
if block in net:
ans -= 1
answers.append(ans)
print(*answers)
return
if __name__ == '__main__':
main()
| import sys
class UnionFind:
def __init__(self, n):
self.table = [-1] * n
def _root(self, x):
stack = []
tbl = self.table
while tbl[x] >= 0:
stack.append(x)
x = tbl[x]
for y in stack:
tbl[y] = x
return x
def find(self, x, y):
return self._root(x) == self._root(y)
def union(self, x, y):
r1 = self._root(x)
r2 = self._root(y)
if r1 == r2:
return
d1 = self.table[r1]
d2 = self.table[r2]
if d1 <= d2:
self.table[r2] = r1
self.table[r1] += d2
else:
self.table[r1] = r2
self.table[r2] += d1
def main():
n, m, k = map(int, sys.stdin.buffer.readline().split())
uf = UnionFind(n)
fb = [0]*n
i = 0
for x in sys.stdin.buffer.readlines():
if i < m:
a, b = map(int, x.split())
fb[a-1] += 1
fb[b-1] += 1
uf.union(a-1, b-1)
else:
c, d = map(int, x.split())
if uf._root(c-1) == uf._root(d-1):
fb[c-1] += 1
fb[d-1] += 1
i += 1
ans = [-uf.table[uf._root(i)]-1-fb[i] for i in range(n)]
print(*ans)
if __name__ == "__main__":
main()
| 1 | 61,818,075,857,340 | null | 209 | 209 |
S = input()
if "A" in S and "B" in S:
print("Yes")
else:
print("No")
| S = input()
if S[0] == S[1] == S[2]:
print("No")
else:
print("Yes") | 1 | 54,762,385,849,288 | null | 201 | 201 |
number, base = map(int, input().split())
result_list = []
while number / base > 0:
mod = number % base
result_list.append(str(mod))
number = number // base
result_list.reverse()
result = "".join(result_list)
print(len(result))
| N,K=map(int,input().split())
ans=0
while N>=K**ans:
ans+=1
print(ans) | 1 | 64,658,313,731,206 | null | 212 | 212 |
a = 1; b = 1
while True:
print(a,"x",b,"=",a*b,sep="")
b += 1
if b == 10:
a += 1; b = 1
if a == 10:
break
| import string
alphabets = {k:0 for k in string.ascii_lowercase}
while True:
try:
for c in input().lower():
if alphabets.get(c) is None:
continue
alphabets[c] += 1
except:
break
for c, n in sorted(alphabets.items()):
print("{} : {}".format(c, n)) | 0 | null | 839,629,392,356 | 1 | 63 |
N = input()
K = int(input())
# K = 1の時の組み合わせを求める関数
def func_1(N):
Nm = int(N[0])
return Nm + 9 * (len(N) - 1)
# K = 2の時の組み合わせを求める関数
def func_2(N):
#NはStringなので
#print(N[0])
Nm = int(N[0])
m = len(N)
#if m == 1:
# print("0")
#print((Nm-1)*(m-1)*9)
#print((m - 1) * (m - 2) * 9 * 9 / 2)
x = int(N) - Nm * pow(10, m-1)
#print(x)
#print(1)
#print(func_1(str(x)))
return int((Nm-1)*(m-1)*9+(m-1)*(m-2)*9*9/2+func_1(str(x)))
def func_3(N):
#print("OK")
Nm = int(N[0])
m = len(N)
# if m == 1 or m == 2:
# print("0")
return int(pow(9,3)*(m-1)*(m-2)*(m-3)/6+(Nm-1)*(m-1)*(m-2)*9*9/2+func_2(str(int(N)-Nm*(10**(m-1)))))
if K == 1:
print(func_1(N))
elif K == 2:
print(func_2(N))
elif K == 3:
print(func_3(N)) | n=int(input())
a=input()
s=list(a)
b=list(a)
j=0
for i in range(0,n-1):
if s[i]==s[i+1]:
b.pop(i-j)
j=j+1
else:
pass
print(len(b)) | 0 | null | 122,904,093,959,648 | 224 | 293 |
n,k=map(int, input().split())
def cmb(n, r, p):
if (r < 0) or (n < r):
return 0
r = min(r, n - r)
return fact[n] * factinv[r] * factinv[n-r] % p
p = 10 ** 9 + 7
N = 2*(10 ** 5 ) # N は必要分だけ用意する
fact = [1, 1] # fact[n] = (n! mod p) 階乗のmod
factinv = [1, 1] # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1] # factinv 計算用
for i in range(2, N + 1):
fact.append((fact[-1] * i) % p)
inv.append((-inv[p % i] * (p // i)) % p)
factinv.append((factinv[-1] * inv[-1]) % p)
#0の数がmin(n-1,k)
MAX=min(n-1,k)
dp=[0]*(MAX+1)
dp[0]=1
ans=1
for i in range(1,MAX+1):
ans+=cmb(n,i,p)*cmb(n-i+i-1,i,p)
ans%=p
#print(ans)
print(ans)
| from sys import stdin
from copy import deepcopy
input = stdin.readline
N = int(input())
A = [int(input()) for _ in range(N)]
B = deepcopy(A)
S = deepcopy(A)
def p(N):
for i in range(len(N)):
if i == len(N) - 1:
print(N[i])
else:
print(N[i], end=" ")
cnt = 0
def insertionsort(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 = j - g
cnt += 1
A[j + g] = v
def shellsort(n):
h = 1
G = []
while h <= n:
G.append(h)
h = 3 * h + 1
G.reverse()
m = len(G)
print(m)
p(G)
for i in range(0, m):
insertionsort(n, G[i])
shellsort(N)
print(cnt)
for a in A:
print(a)
| 0 | null | 33,481,324,252,452 | 215 | 17 |
n,m = [int(i) for i in input().split()]
a = [[int(i) for i in input().split()] for j in range(n)]
b = [0 for i in range(m)]
c = [0 for i in range(n)]
for i in range(m):
b[i] = int(input())
for i in range(n):
for j in range(m):
c[i] += a[i][j] * b[j]
print('\n'.join(map(str,c))) | N = int(input())
print(-(N%-1000)) | 0 | null | 4,832,656,578,092 | 56 | 108 |
while True:
try:
print(int(eval(input())))
except:
break
| n=int(input())
l=list(map(int,input().split()))
ans=[0]*n
for i in range(len(l)):
ans[l[i]-1]=i+1
print(*ans) | 0 | null | 90,924,889,072,508 | 47 | 299 |
N = int(input())
As = []
Bs = []
for _ in range(N):
c = 0
m = 0
for s in input():
if s == '(':
c += 1
elif s == ')':
c -= 1
m = min(m, c)
if c >= 0:
As.append((-m, c - m))
else:
Bs.append((-m, c - m))
As.sort(key=lambda x: x[0])
Bs.sort(key=lambda x: x[1], reverse=True)
f = True
c = 0
for (l, r) in As:
if c < l:
f = False
break
c += r - l
if f:
for (l, r) in Bs:
if c < l:
f = False
break
c += r - l
f = f and (c == 0)
if f:
print('Yes')
else:
print('No') | from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
INF = float("inf")
import bisect
def count(s):
a = 0
aa = 0
b = 0
bb = 0
for i in range(len(s)):
if s[i] == ")":
if aa == 0:
a = a + 1
else:
aa = aa - 1
if s[i] == "(":
aa = aa + 1
if s[len(s)-1-i] == "(":
if bb == 0:
b = b + 1
else:
bb = bb - 1
if s[len(s)-1-i] == ")":
bb = bb + 1
return [a, b]
N = int(input())
c = []
d = []
for i in range(N):
s = input()
e = count(s)
if e[1] - e[0] >= 0: c.append(e)
if e[0] - e[1] > 0: d.append(e)
c.sort(key=lambda x: x[0])
d.sort(key=lambda x: x[1], reverse=True)
c = c + d
# print(c)
f = 0
for cc in c:
f = f - cc[0]
if f < 0:
print("No")
sys.exit()
f = f + cc[1]
if f == 0:
print("Yes")
else:
print("No")
| 1 | 23,529,041,567,408 | null | 152 | 152 |
N = int(input())
P = list(map(int, input().split()))
mini = N + 1
ans = 0
for i in range(N):
if P[i] < mini:
ans += 1
mini = P[i]
print(ans) | n, q = map(int, input().split())
l = []
for i in range(n):
t = []
for j in input().split():
t += [j]
t[1] = int(t[1])
l += [t]
c = 0
while len(l) > 0:
if l[0][1] > q:
l[0][1] -= q
l += [l[0]]
l.pop(0)
c += q
else:
c += l[0][1]
print(l[0][0], c)
l.pop(0)
| 0 | null | 42,539,458,678,070 | 233 | 19 |
while True:
s = input().rstrip().split(' ')
a = int(s[0])
b = int(s[2])
op = s[1]
if op == "?":
break
elif op == "+":
print(str(a + b))
elif op == "-":
print(str(a - b))
elif op == "*":
print(str(a * b))
elif op == "/":
print(str(int(a / b))) | # encoding:utf-8
while True:
a, op, b = raw_input().split()
if op == "?":
break
a, b = map(int, (a,b))
if op == "+":
print(a+b)
elif op == "-":
print(a-b)
elif op == "*":
print(a*b)
else:
print(a/b) | 1 | 683,086,742,632 | null | 47 | 47 |
n, k = map(int, input().split())
d = [0] * k
a = []
for i in range(k):
d[i] = int(input())
a_in = list(map(int, input().split()))
a.extend(a_in)
num = len(set(a))
print(n-num) | import itertools
N, K = map(int, input().split())
d = []
A = []
for i in range(K):
d.append(int(input()))
A.append(list(map(int, input().split())))
A = list(itertools.chain.from_iterable(A))
ans = 0
for i in range(1, N + 1):
if i in A:
continue
else:
ans += 1
print(ans) | 1 | 24,430,947,948,322 | null | 154 | 154 |
a = int(input())
if a % 2 == 0 :
print((a - a / 2 ) / a)
else:
print((a - a // 2) / a)
# 5 ,4 ,3 ,2 ,1
# 3 /5 | n=int(input())
even=n//2
a=(n-even)/n
print(a) | 1 | 176,456,206,012,672 | null | 297 | 297 |
S,T=map(str, input().split())
A,B=map(int,input().split())
U=input()
if S==U:
a=1
b=0
else:
a=0
b=1
print(A-a,B-b) | while 1:
a, b, c = raw_input().split()
if b == "?":
break
a = int(a)
c = int(c)
if b == "+":
print a+c
elif b == "-":
print a-c
elif b == "*":
print a*c
elif b == "/":
print a//c
| 0 | null | 36,253,719,017,348 | 220 | 47 |
from copy import deepcopy
from copy import copy
class Dice:
def __init__(self, labels):
self.surface = {x: labels[x-1] for x in range(1, 6+1)}
def move_towards(self, direction):
if direction == 'N':
self._move(1, 2, 6, 5)
elif direction == 'S':
self._move(1, 5, 6, 2)
elif direction == 'E':
self._move(1, 4, 6, 3)
elif direction == 'W':
self._move(1, 3, 6, 4)
def get_upper(self):
return self.surface[1]
def _move(self, i, j, k, l):
temp_label = self.surface[i]
self.surface[i] = self.surface[j]
self.surface[j] = self.surface[k]
self.surface[k] = self.surface[l]
self.surface[l] = temp_label
def find_pattern(self, pattern):
dice = deepcopy(self)
if dice.surface[1] == pattern[0] and dice.surface[2] == pattern[1]:
return dice.surface[3]
pattern_tested = {'original': dice.surface}
moves = ['N', 'S', 'E', 'W']
def find(dice, moves):
next_moves = []
for move in moves:
if len(move) == 1:
start = 'original'
else:
start = move[:-1]
dice.surface =pattern_tested[start]
dice.move_towards(move[-1])
if dice.surface[1] == pattern[0] and dice.surface[2] == pattern[1]:
right_label = dice.surface[3]
return right_label
else:
move_tested = move
pattern_tested[move_tested] = copy(dice.surface)
next_moves.extend([move+'N', move+'S', move+'E', move+'W'])
return find(dice, next_moves)
return find(dice, moves)
labels = list(map(int, input().split()))
num_questions = int(input())
questions = [list(map(int, input().split())) for _ in range(num_questions)]
dice = Dice(labels)
results = []
for question in questions:
right_label = dice.find_pattern(question)
results.append(right_label)
for result in results:
print(result)
| dct = {
0: (0, 0, 1),
5: (0, 0, -1),
2: (0, 1, 0),
3: (0, -1, 0),
1: (1, 0, 0),
4: (-1, 0, 0)
}
def calc(x, y):
res = (
x[1] * y[2] - x[2] * y[1],
x[2] * y[0] - x[0] * y[2],
x[0] * y[1] - x[1] * y[0]
)
return res
if __name__ == "__main__":
a = [int(x) for x in input().split()]
Q = int(input())
for _ in range(Q):
x, y = map(int, input().split())
for i, value in enumerate(a):
if x == value:
x_ind = i
elif y == value:
y_ind = i
s, t = dct[x_ind], dct[y_ind]
res = calc(s,t)
for key in dct:
if dct[key] == res:
print(a[key])
break
| 1 | 253,624,679,634 | null | 34 | 34 |
N = int(input())
S = input()
r = S.count('R')
g = S.count('G')
b = S.count('B')
ans = r*g*b
for i in range(0,N):
for j in range(i,N):
k = 2*j - i
if j < k <= N-1:
if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
ans -= 1
print(ans) | from collections import Counter
n = int(input())
s = input()
cnt = Counter(s)
ans = cnt["R"]*cnt["G"]*cnt["B"]
for i in range(n):
for j in range(i+1,n):
k = 2*j-i
if k >= n: continue
if s[i] != s[j] and s[i] != s[k] and s[j] != s[k]: ans -= 1
print(ans) | 1 | 36,177,851,718,812 | null | 175 | 175 |
S=str(input())
print('x'*len(S)) | import math
H, W = map(int, input().split())
A = math.ceil((H * W)/2)
if H == 1 or W == 1:
print(1)
else:
print(A)
| 0 | null | 62,004,860,187,552 | 221 | 196 |
A = input()
B = input()
KAI = "123"
KAI1 = KAI.replace(A,"")
KAI2 = KAI1.replace(B,"")
print(KAI2) | A = int(input())
B = int(input())
print(6//(A*B)) | 1 | 110,395,141,903,100 | null | 254 | 254 |
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from math import ceil
def main():
n, k = map(int, input().split())
a = tuple(map(int, input().split()))
def kaisu(long):
return(sum([ceil(ae/long) - 1 for ae in a]))
def bs_meguru(key):
def isOK(index, key):
if kaisu(index) <= key:
return True
else:
return False
ng = 0
ok = max(a)
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
if isOK(mid, key):
ok = mid
else:
ng = mid
return ok
print(bs_meguru(k))
if __name__ == '__main__':
main()
| print(input().find('0')//2+1) | 0 | null | 9,930,599,619,560 | 99 | 126 |
N = int(raw_input())
A = map(int, raw_input().split())
def selectionSort(A, N):
count = 0
for i in range(0, N):
minj = i
for j in range(i, N):
if A[j] < A[minj]:
minj = j
if i != minj:
temp = A[i]
A[i] = A[minj]
A[minj] = temp
count += 1
return count
count = selectionSort(A, N)
print " ".join(map(str, A))
print count | input()
nlist=map(int, raw_input().split())
input()
qlist=map(int, raw_input().split())
n = len(nlist)
dic = {}
def func(idx, m):
try:
return dic[m][idx]
except:
pass
if m==0:
tmp=dic.get(m,{})
tmp.update({idx: True})
dic.update({m:tmp})
elif idx > n-1:
tmp=dic.get(m,{})
tmp.update({idx: False})
dic.update({m:tmp})
elif func(idx+1, m):
tmp=dic.get(m,{})
tmp.update({idx: True})
dic.update({m:tmp})
elif func(idx+1, m-nlist[idx]):
tmp=dic.get(m,{})
tmp.update({idx: True})
dic.update({m:tmp})
else:
tmp=dic.get(m,{})
tmp.update({idx: False})
dic.update({m:tmp})
return dic[m][idx]
for q in qlist:
# print dic
print "yes" if func(0, q) else "no" | 0 | null | 62,897,259,236 | 15 | 25 |
P = [1 for _ in range(10**6)]
P[0]=0
P[1]=0
for i in range(2,10**3):
for j in range(i*i,10**6,i):
P[j] = 0
Q = []
for i in range(2,10**6):
if P[i]==1:
Q.append(i)
N = int(input())
C = {}
for q in Q:
if N%q==0:
C[q] = 0
while N%q==0:
N = N//q
C[q] += 1
if N>1:
C[N] = 1
cnt = 0
for q in C:
k = C[q]
n = 1
while k>(n*(n+1))//2:
n += 1
if k==(n*(n+1))//2:
cnt += n
else:
cnt += n-1
print(cnt)
| h, w = map(int, input().split())
L = [str(input()) for _ in range(h)]
dp = [[float('inf')] * w for _ in range(h)]
dp[0][0] = 1 if L[0][0] =='#' else 0
for i in range(h):
for j in range(w):
if L[i][j] == '.':
if i < h - 1:
dp[i+1][j] = min(dp[i+1][j], dp[i][j] if L[i+1][j] == '.' else dp[i][j] + 1)
if j < w - 1:
dp[i][j+1] = min(dp[i][j+1], dp[i][j] if L[i][j+1] == '.' else dp[i][j] + 1)
else:
if i < h - 1:
dp[i+1][j] = min(dp[i+1][j], dp[i][j])
if j < w - 1:
dp[i][j+1] = min(dp[i][j+1], dp[i][j])
print(dp[h-1][w-1])
| 0 | null | 33,201,376,593,408 | 136 | 194 |
s = input()
for _ in range(int(input())):
o = list(map(str, input().split()))
a = int(o[1])
b = int(o[2])
if o[0] == "print":
print(s[a:b+1])
elif o[0] == "reverse":
s = s[:a] + s[a:b+1][::-1] + s[b+1:]
else:
s = s[:a] + o[3] + s[b+1:]
| a,b,c,d=map(int,input().split())
temp_q=(c+b-1)//b
temp_g=(a+d-1)//d
if temp_q>temp_g:
print("No")
else:
print("Yes") | 0 | null | 15,770,054,886,168 | 68 | 164 |
# -*- coding: utf-8 -*-
import io
import sys
import math
def solve():
# implement process
pass
def main():
# input
m, n = map(int, input().split())
# process
ans = "Yes" if m == n else "No"
# output
print(ans)
return ans
### DEBUG I/O ###
_DEB = 0 # 1:ON / 0:OFF
_INPUT = """\
2 3
"""
_EXPECTED = """\
Yes
"""
def logd(str):
"""usage:
if _DEB: logd(f"{str}")
"""
if _DEB: print(f"[deb] {str}")
### MAIN ###
if __name__ == "__main__":
if _DEB:
sys.stdin = io.StringIO(_INPUT)
print("!! Debug Mode !!")
ans = main()
if _DEB:
print()
if _EXPECTED.strip() == ans.strip(): print("!! Success !!")
else: print(f"!! Failed... !!\nANSWER: {ans}\nExpected: {_EXPECTED}") | def main():
N,M = map(int,input().split())
if M == N:
return 'Yes'
else:
return 'No'
print(main())
| 1 | 83,581,908,772,740 | null | 231 | 231 |
import numpy as np
import sys
input = sys.stdin.readline
def main():
n, s = map(int, input().split())
A = np.array([int(i) for i in input().split()])
MOD = 998244353
dp = np.zeros(s + 1, dtype="int32")
dp[0] = 1
for i in range(n):
p = (dp * 2) % MOD
p %= MOD
p[A[i]:] += dp[:-A[i]]
dp = p % MOD
print(dp[s])
if __name__ == '__main__':
main() | n = int(input())
for i in range(1,n+1):
x = i
if x % 3 == 0:
print('', i, end='')
else:
while True:
if x % 10 == 3:
print('', i, end='')
break
x //= 10
if x == 0:
break
print() | 0 | null | 9,392,119,108,898 | 138 | 52 |
import collections
n = int(input())
a = list(map(int, input().split()))
l = []
r = []
for i in range(n):
l.append(i+a[i])
r.append(i-a[i])
count = collections.Counter(r)
ans = 0
for i in l:
ans += count.get(i,0)
print(ans) | import sys
import numpy as np
from numba import njit, void, i8
input = sys.stdin.buffer.readline
def main():
R, C, K = map(int, input().split())
cell = np.full((R+1, C+1), 0, dtype=np.int64)
for i in range(K):
x, y, c = map(int, input().split())
cell[x-1, y-1] = c
print(calc(cell, R, C))
@njit(i8(i8[:,:],i8,i8))
def calc(cell, R, C):
L_INF = int(1e17)
dp = np.full((R+1, C+1, 4), -L_INF, dtype=np.int64)
dp[0, 1, 0] = dp[1, 0, 0] = 0
for i in range(1, R + 1):
for j in range(1, C + 1):
for k in range(4):
dp[i, j, k] = max(dp[i, j, k], dp[i, j-1, k])
if k > 0:
dp[i, j, k] = max(dp[i, j, k], dp[i, j, k-1])
dp[i, j, k] = max(dp[i, j, k], dp[i, j-1, k-1] + cell[i-1, j-1])
if k == 1:
dp[i, j, 1] = max(dp[i, j, 1], dp[i-1, j, 3] + cell[i-1, j-1])
return dp[R, C, 3]
if __name__ == "__main__":
main()
| 0 | null | 15,908,963,024,900 | 157 | 94 |
N, X, T = list(map(int, input().split()))
if N%X == 0:
print((N//X)*T)
else:
print(((N//X)+1)*T) | import math
n,x,t = map(int,input().strip().split(" "))
ans = math.ceil(n/x)
ans = ans*t
print(ans) | 1 | 4,204,657,954,430 | null | 86 | 86 |
import sys
read = sys.stdin.read
readline = sys.stdin.readline
count = 0
l, r, d= [int(x) for x in readline().rstrip().split()]
#print(l,r,d)
for i in range(l,r+1):
if i % d == 0:
count += 1
print(count)
| L, R, d = map(int, input().split())
if L%d == 0 or R%d == 0 :
print((R-L)//d + 1)
else:
print((R - L)//d) | 1 | 7,602,397,840,856 | null | 104 | 104 |
import itertools
n,m,q=map(int,input().split())
a=[]
b=[]
c=[]
d=[]
for i in range(q):
a1,b1,c1,d1=map(int,input().split())
a.append(a1)
b.append(b1)
c.append(c1)
d.append(d1)
l=list(range(1,m+1))
ans=0
for A in list(itertools.combinations_with_replacement(l, n)):
sum=0
for i in range(q):
if A[b[i]-1]-A[a[i]-1]==c[i]:
sum+=d[i]
ans=max(ans,sum)
print(ans)
| # D - String Equivalence
def dfs(s, mx):
if len(s)==n:
print(s)
return
for c in range(ord('a'),ord(mx)+1):
dfs(s+chr(c),(chr(ord(mx)+1) if ord(mx)==c else mx))
n=int(input())
dfs('','a')
| 0 | null | 40,089,957,424,330 | 160 | 198 |
N, T = map(int, input().split())
A = [0]*N
B = [0]*N
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort(key=lambda x: x[0])
dp = [[0]*(T) for _ in range(N+1)]
ans = 0
for i in range(N):
for j in range(T):
dp[i+1][j] = dp[i][j]
ans = max(ans, dp[i][j] + AB[i][1])
# 上は この時刻jまでで商品i-1個を入れた後に時間制約の無いi個目の商品を追加している
if j - AB[i][0] >= 0:
dp[i+1][j] = max(dp[i][j], dp[i][j-AB[i][0]] + AB[i][1])
print(ans)
| import sys
import math
import fractions
from collections import defaultdict
import heapq
from bisect import bisect_left,bisect
stdin = sys.stdin
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))
N,K=nm()
A=nl()
l=0
r=10**9
mid=0
if(K==0):
print(max(A))
sys.exit(0)
while(l+1<r):
mid=(l+r)//2
tmp=0
for i in range(len(A)):
tmp+=((A[i]-1)//mid)
if(tmp<=K):
r=mid
else:
l=mid
print(r) | 0 | null | 78,884,626,056,388 | 282 | 99 |
# -*- coding: utf-8 -*-
"""
D - Xor Sum 4
https://atcoder.jp/contests/abc147/tasks/abc147_d
"""
import sys
def solve(N, A):
MOD = 10**9 + 7
bit_len = max(map(int.bit_length, A))
ans = 0
for i in range(bit_len):
zeros, ones = 0, 0
for a in A:
if (a & 1<<i):
ones += 1
else:
zeros += 1
ans = (ans + (ones * zeros * 2**i)) % MOD
return ans % MOD
def main(args):
N = int(input())
A = list(map(int, input().split()))
ans = solve(N, A)
print(ans)
if __name__ == '__main__':
main(sys.argv[1:])
| from collections import defaultdict
N, K = [int(i) for i in input().split()]
mod = 10 ** 9 + 7
dd = defaultdict(int)
ans = 0
for i in range(K, 0, -1):
dd[i] = pow(K // i, N, mod)
for temp in range(i * 2, K + 1, i):
dd[i] -= dd[temp]
ans += dd[i] * i
ans %= mod
print(ans)
| 0 | null | 79,938,636,786,720 | 263 | 176 |
import math
import collections
import fractions
import itertools
import functools
import operator
import numpy as np
def solve():
h, w = map(int, input().split())
maze = [input() for _ in range(h)]
ans = 0
can_move = [[1, 0], [0, 1], [-1, 0], [0, -1]]
for x in range(h):
for y in range(w):
if maze[x][y] == "#":
continue
dist = [[0]*w for _ in range(h)]
stack = collections.deque()
stack.append([x,y])
while stack:
h2, w2 = stack.popleft()
for i, j in can_move:
newh, neww = h2+i, w2+j
if newh < 0 or neww < 0 or newh >= h or neww >= w:
continue
elif maze[newh][neww] != "#" and dist[newh][neww] == 0:
dist[newh][neww] = dist[h2][w2]+1
stack.append([newh, neww])
dist[x][y] = 0
ans = max(ans, np.max(dist))
print(ans)
return 0
if __name__ == "__main__":
solve() | from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
# INF = float("inf")
INF = 10**18
import bisect
import statistics
mod = 10**9+7
# mod = 998244353
H, W = list(map(int, input().split()))
S = []
for i in range(H):
S.append(input())
def bfs(u):
stack = deque([u])
visited = set()
seen = set()
p = [[INF for j in range(W)] for i in range(H)]
p[u[0]][u[1]] = 0
for i in range(H):
for j in range(W):
if S[i][j] == "#":
p[i][j] = -1
while len(stack) > 0:
v = stack.popleft()
###
visited.add(v)
###
a = (v[0] + 1, v[1])
b = (v[0] , v[1] + 1)
c = (v[0] - 1, v[1])
d = (v[0] , v[1] - 1)
e = [a, b, c, d]
for ee in e:
if ee[0] >= 0 and ee[0] <= H-1 and ee[1] >= 0 and ee[1] <= W-1:
if S[ee[0]][ee[1]] == ".":
if ee not in visited:
p[ee[0]][ee[1]] = min(p[ee[0]][ee[1]], p[v[0]][v[1]] + 1)
if ee not in seen:
stack.append(ee)
seen.add(ee)
ans = 0
for i in range(H):
ans = max(ans, max(p[i]))
return ans
sol = 0
for i in range(H):
for j in range(W):
if S[i][j] == ".":
sol = max(sol, bfs((i,j)))
print(sol) | 1 | 94,546,044,849,152 | null | 241 | 241 |
import sys
#input = sys.stdin.buffer.readline
#sys.setrecursionlimit(10**9)
#from functools import lru_cache
def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()
#import numpy as np
def main():
n=II()
A=LI()
B=[0]*(n+1)
ans=1
B[0]=3
for i in range(n):
ans*=(B[A[i]])-(B[A[i]+1])
ans%=10**9+7
B[A[i]+1]+=1
print(ans)
if __name__ == "__main__":
main()
| list = map(int,raw_input().split())
list.sort()
print'%d %d %d' %(list[0],list[1],list[2]) | 0 | null | 65,146,995,531,980 | 268 | 40 |
import itertools
N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
patterns = itertools.permutations(list(range(1, N+1)), N)
p_i = 0
q_i = 0
for i, ptn in enumerate(patterns):
p_same = True
q_same = True
for j, num in enumerate(ptn):
if P[j] != num:
p_same = False
if Q[j] != num:
q_same = False
if p_same:
p_i = i
if q_same:
q_i = i
print(abs(p_i-q_i)) | X, Y = map(int, input().split())
if Y%2==1 or 4*X<Y or 2*X>Y:
print("No")
else:
print("Yes")
| 0 | null | 57,071,070,976,992 | 246 | 127 |
n = int(input())
a = 0
b = 0
d1 = 0
d2 = 0
for i in range(n):
d1,d2 = map(int,input().split())
if(a==0 and d1 ==d2):
a+=1
elif(a==1 and d1 ==d2):
a+=1
elif(a==2 and d1 ==d2):
b +=1
break
else:
a =0
if(b>=1):
print("Yes")
else:
print("No") | N = int(input())
memo = [1]*(N+1)
for i in range(2,N+1):
tmp = i
while tmp <= N:
memo[tmp] += 1
tmp += i
ans = 0
for key,val in enumerate(memo):
ans += key*val
print(ans) | 0 | null | 6,727,214,014,630 | 72 | 118 |
import math
from sys import stdin,stdout
#% 998244353
from heapq import heapify,heappop,heappush
import collections
s = stdin.readline()[:-1]
print(s[:3])
| k = int(input())
s = str(input())
if len(s) <= k:
print(s)
else:
ans = s[0:k] + '...'
print(ans) | 0 | null | 17,151,832,984,450 | 130 | 143 |
N=int(input())
B=[int(a) for a in input().split()]
sum=0
ans=0
for i in range(len(B)-1):
sum+=B[i]
ans+=sum*B[i+1]
print(ans%1000000007)
| S,T=input().split()
print(T+S)
| 0 | null | 53,517,045,690,020 | 83 | 248 |
n = int(input())
def dfs(s, mx):
if len(s) == n:
print(s)
return
for c in range(ord("a"), mx+2):
dfs(s+chr(c), max(mx, c))
dfs("", ord("a")-1) | 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,383,031,687,910 | null | 198 | 198 |
import sys
n = int(input())
for i in range(1, n + 1):
x = i
if x % 3 == 0:
sys.stdout.write(" %d" % i)
else:
while x > 1:
if x % 10 == 3:
sys.stdout.write(" %d" % i)
break
x //= 10
print() | n = int(input())
for i in range(1,n+1):
if i % 3 == 0:
print(" {0}".format(i), end="")
else:
x = i
while x != 0:
if x % 10 == 3:
print(" {0}".format(i), end="")
break;
x //= 10;
print("")
| 1 | 923,960,059,012 | null | 52 | 52 |
# abc149_d.py
def janken(idx,mine):
if i >= K:
if flg[i-K] and T[i-K]==T[i]:
return 0
flg[i] = True
if mine=="r":
return R
if mine=="p":
return P
if mine=="s":
return S
N, K = map(int,input().split())
R,S,P = map(int,input().split())
T = input()
flg = [False]*N
ans = 0
for i,v in enumerate(T):
if v=="s":
ans += janken(i,"r")
elif v=="r":
ans += janken(i,"p")
elif v=="p":
ans += janken(i,"s")
print(ans) | import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
H, N, *AB = map(int, read().split())
magic = [0] * N
for i, (a, b) in enumerate(zip(*[iter(AB)] * 2)):
magic[i] = (a, b)
dp = [[INF] * (H + 1) for _ in range(N + 1)]
for i in range(N + 1):
dp[i][0] = 0
for i in range(N):
a, b = magic[i]
for j in range(H + 1):
dp[i + 1][j] = min(dp[i][j], dp[i + 1][max(j - a, 0)] + b)
print(dp[N][H])
return
if __name__ == '__main__':
main()
| 0 | null | 93,678,500,696,780 | 251 | 229 |
N = int(input())
S = input()
if N % 2 !=0:
print('No')
else:
n = int(N/2)
s1 = S[:n]
s2 = S[n:]
if s1 == s2:
print('Yes')
else:
print('No') | from math import floor, ceil
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
l = 0
r = max(a)
while r - l > 1:
c = (l+r)//2
cnt = 0
for i in a:
cnt += max(ceil(i/c) - 1, 0)
if cnt <= k:
r = c
else:
l = c
print(r) | 0 | null | 76,544,078,599,940 | 279 | 99 |
while True:
x, y = map(int, raw_input().split())
if x==0 and y==0:
break
if x<y:
print '%d %d' %(x, y)
else:
print '%d %d' %(y, x) | #!/usr/bin/python3
# -*- coding: utf-8 -*-
n, k, c = map(int, input().split())
S = [1 if a == "o" else 0 for a in input()]
count = 0
X = [0] * n
Y = [0] * n
i = 0
while i < n:
if S[i]:
count += 1
X[i] = 1
i += c + 1
else:
i += 1
if count > k:
exit()
i = n - 1
while i >= 0:
if S[i]:
Y[i] = 1
i -= c + 1
else:
i -= 1
for i in range(0, n):
if X[i] and Y[i]:
print(i + 1) | 0 | null | 20,576,535,906,212 | 43 | 182 |
n = int(input())
a = [int(i) for i in input().split()]
print(' '.join(map(str, reversed(a)))) | # coding=utf-8
n = int(raw_input())
nums = raw_input().split()
print ' '.join(reversed(nums)) | 1 | 993,026,999,238 | null | 53 | 53 |
S=input()
S=list(reversed(S))
m=2019
cnt=[0 for i in range(m)]
len_S=len(S)
x=1
tot=0
ans=0
for i in range(len(S)):
cnt[tot]+=1
tot+=(ord(S[i])-ord('0'))*x
tot %= m
ans+=cnt[tot]
x=x*10%m
print(ans) | l = ['SUN','MON','TUE','WED','THU','FRI','SAT']
s = input()
if s in l:
print(7-l.index(s))
else:
pass | 0 | null | 81,925,255,710,948 | 166 | 270 |
import math
x_1,y_1,x_2,y_2 = map(float,input().split())
print(math.sqrt((x_1-x_2)**2+(y_1-y_2)**2))
| import math
x1, y1, x2, y2 = list(map(float, input().split()))
d = math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)
print("{:.5f}".format(d)) | 1 | 155,096,518,720 | null | 29 | 29 |
import sys
sen=[]
for line in sys.stdin:
sen.append(line)
Sen=''.join(sen)
a=[]
b=[]
c=[]
d=[]
e=[]
f=[]
g=[]
h=[]
i=[]
j=[]
k=[]
l=[]
m=[]
n=[]
o=[]
p=[]
q=[]
r=[]
s=[]
t=[]
u=[]
v=[]
x=[]
y=[]
z=[]
w=[]
count={'a':a,'b':b,'c':c,'d':d,'e':e,'f':f,'g':g,'h':h,'i':i,'j':j,'k':k,'l':l,'m':m,'n':n,'o':o,'p':p,'q':q,'r':r,'s':s,'t':t,'u':u,'v':v,'w':w,'x':x,'y':y,'z':z}
for i in range(len(Sen)):
if Sen[i].isalpha():
count[Sen[i].lower()].append('#')
for char in sorted(count.keys()):
print('%s : %d'%(char,len(count[char]))) | #coding: utf-8
import sys
c = [0 for i in range(26)]
in_list = []
for line in sys.stdin:
in_list.append(line)
for s in in_list:
for i in range(len(s)):
if ord(s[i]) >= ord('a') and ord(s[i]) <= ord('z'):
c[ord(s[i])-97] += 1
elif ord(s[i]) >= ord('A') and ord(s[i]) <= ord('Z'):
c[ord(s[i])-65] += 1
for i in range(26):
print(chr(ord('a')+i) + " : " + str(c[i]))
| 1 | 1,663,039,630,410 | null | 63 | 63 |
import sys
n = int(input())
for a in range(-200, 201):
for b in range(-200, 201):
if a * a * a * a * a - b * b * b * b * b == n:
print(a, b)
sys.exit(0) | x = int(input())
n = 120
for i in range(n):
for j in range(i):
if x == i**5-j**5:
print(i,j)
exit(0)
if x == i**5+j**5:
print(i,-j)
exit(0) | 1 | 25,665,362,717,928 | null | 156 | 156 |
import sys
sys.setrecursionlimit(10**7)
n = int(input())
def dfs(s):
if len(s) == n:
print(s)
return 0
for x in map(chr, range(97, ord(max(s))+2)):
dfs(s+x)
dfs('a') | import math
x1,y1,x2,y2=input().split()
x1=float(x1)
y1=float(y1)
x2=float(x2)
y2=float(y2)
r=math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))
print(r) | 0 | null | 26,183,471,883,072 | 198 | 29 |
IDX_TABLE=\
{1:[4,2,3,5],
2:[1,4,6,3],
3:[1,2,6,5],
4:[1,5,6,2],
5:[4,1,3,6],
6:[3,2,4,5]}
nums = ["dummy"] + [int(x) for x in raw_input().split(" ")]
n = int(raw_input())
for i in range(n):
up, front = tuple([int(x) for x in raw_input().split(" ")])
up_idx = nums.index(up)
front_idx = nums.index(front)
ring_list = IDX_TABLE[up_idx]
ring_idx = ring_list.index(front_idx)
print nums[ring_list[(ring_idx+1) % 4]] | import sys
import math
def str_input():
S = raw_input()
if S[len(S)-1] == "\r":
return S[:len(S)-1]
return S
def float_to_str(num):
return str("{:.10f}".format(num))
def list_input(tp):
return map(tp, str_input().split())
# # # # # # # # # # # # # # # # # # # # # # # # #
class Dice:
pip = [0 for i in xrange(6)]
def __init__(self, arg):
self.pip = arg
def rollDir(self, dr):
nextPip = [0 for i in xrange(6)]
if dr == "N":
nextPip[0] = self.pip[1]
nextPip[1] = self.pip[5]
nextPip[2] = self.pip[2]
nextPip[3] = self.pip[3]
nextPip[4] = self.pip[0]
nextPip[5] = self.pip[4]
elif dr == "E":
nextPip[0] = self.pip[3]
nextPip[1] = self.pip[1]
nextPip[2] = self.pip[0]
nextPip[3] = self.pip[5]
nextPip[4] = self.pip[4]
nextPip[5] = self.pip[2]
self.pip = nextPip
def roll(self, dr):
if dr == "N" or dr == "E":
self.rollDir(dr)
elif dr == "S":
self.rollDir("N")
self.rollDir("N")
self.rollDir("N")
elif dr == "W":
self.rollDir("E")
self.rollDir("E")
self.rollDir("E")
dice = Dice(list_input(int))
for i in xrange(input()):
a, b = list_input(int)
while dice.pip[0] != a:
if dice.pip[2] != a and dice.pip[3] != a:
dice.roll("N")
else:
dice.roll("N")
dice.roll("W")
dice.roll("S")
while dice.pip[1] != b:
dice.roll("N")
dice.roll("W")
dice.roll("S")
print dice.pip[2] | 1 | 256,132,584,098 | null | 34 | 34 |
SN=[5,1,2,6]
WE=[4,1,3,6]
def EWSN(d):
global SN,WE
if d == "S" :
SN = SN[3:4] + SN[0:3]
WE[3] = SN[3]
WE[1] = SN[1]
elif d == "N":
SN = SN[1:4] + SN[0:1]
WE[3] = SN[3]
WE[1] = SN[1]
elif d == "E":
WE = WE[3:4] + WE[0:3]
SN[3] = WE[3]
SN[1] = WE[1]
elif d == "W":
WE = WE[1:4] + WE[0:1]
SN[3] = WE[3]
SN[1] = WE[1]
dice = list(map(int,input().split(" ")))
op = input()
for i in op:
EWSN(i)
print(dice[SN[1] - 1])
| mask = {'N':(1, 5, 2, 3, 0, 4), 'E':(3, 1, 0, 5, 4, 2), 'S':(4, 0, 2, 3, 5, 1), 'W':(2, 1, 5, 0, 4,3)}
dice = input().split()
for c in input():
dice = [dice[i] for i in mask[c]]
print(dice[0]) | 1 | 229,655,028,230 | null | 33 | 33 |
s = input()
x = s.replace('<>', '<|>').split('|')
def func(t):
c1 = t.count('>')
c2 = len(t) - c1
return list(reversed(range(1, c1 + 1))) + list(range(c2 + 1))
a = func(x[0])
for i in range(1, len(x)):
ai = func(x[i])
a[-1] = max(a[-1], ai[0])
a.extend(ai[1:])
# print(a)
ans = sum(a)
print(ans)
| N, M =map(int,input().split())
A = list(map(int, input().split()))
# x = 宿題をする日の合計
x = sum(A)
if N >= x:
print(N - x)
else:
print("-1")
| 0 | null | 94,238,878,677,514 | 285 | 168 |
L, R, d = map(int, input().split())
a = 1
ans = 0
while a*d <= R:
if a*d >= L:
ans += 1
a += 1
print(ans) | from math import pi
x=float(input())
ans=2*pi*x
print(ans) | 0 | null | 19,321,596,977,510 | 104 | 167 |
x = int(input())
ans = 0
div_500, x = divmod(x, 500)
div_5, x = divmod(x, 5)
ans = div_500 * 1000 + div_5 * 5
print(ans) | from fractions import gcd
from functools import reduce
def l(a,b):return a*b//gcd(a,b)
def L(N):return reduce(l,N)
n,m=map(int,input().split())
A=list(map(lambda x:int(x)//2,input().split()))
a=A[0]
c=0
while(a%2==0):
a//=2
c+=1
if any([(a%(2**c)==0 and a//(2**c))%2==0 for a in A]):
print(0)
exit()
a=L(A)
print((m+a)//(2*a))
| 0 | null | 72,241,221,388,258 | 185 | 247 |
N=list(map(int,input()))
K=int(input())
L = len(N)
dp = [[[0]*(L+1) for _ in range(4)] for _ in range(2)]
dp[0][0][0] = 1
for i in range(2):
for j in range(4):
for k in range(L):
for d in range(10 if i else N[k]+1):
fl = 1 if i == 1 or d < N[k] else 0
cnt = j+1 if d != 0 else j
if cnt > K:
continue
dp[fl][cnt][k+1] += dp[i][j][k]
print(dp[0][K][L]+dp[1][K][L]) | import math
def isMore(N,K):#- N以上の数で、0でないのが丁度K個
#-len(N)よりもKがおおきかったら0 埋められない
if len(N) < K:
return 0
#最高位の数字を1つ繰り上げれば、なんでも大きい。ただし、Kは1以上
if K>=1:
tmp = (9-int(N[0]))*fact[len(N)-1]//((fact[len(N)-K])*(fact[K-1]))*(9**(K-1))
#一桁ならtmpを返す
if len(N)==1:
return tmp
#2桁以上あるなら&最高位が0なら、最高桁繰り上げ+最高桁同じ+0でないものがK個
elif len(N)>1 and N[0]=='0':
return tmp + isMore(N[1:],K)
#2桁以上あるなら&最高位が0以外なら、最高桁繰り上げ+最高桁同じ+0でないものがK-1個
elif len(N)>1 and N[0]!='0':
return tmp + isMore(N[1:],K-1)
#Kが0ならどうやってもNより大きいものが作れない0
if K == 0:
return 0
N = input()
K = int(input())
lenN = len(N)
fact = [1]*101
for i in range(1,101):
fact[i] = fact[i-1]*i
ans = fact[lenN]//((fact[lenN-K])*fact[K])*(9**K)
ans -= isMore(N,K)
print(ans)
| 1 | 75,771,370,523,380 | null | 224 | 224 |
#!/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():
N, R = MI()
if N >= 10:
print(R)
else:
print(R + 100 * (10 - N))
main()
| #--Beginner
#1行1列
number, rate = map(int, input().split())
if (number < 10):
print(rate+(100*(10-number)))
elif (number >= 10):
print(rate)
| 1 | 63,214,012,809,380 | null | 211 | 211 |
n, m = map(int,input().split())
a = list(map(int,input().split()))
a.sort(reverse=True)
total = sum(a)
flg = True
for i in range(m):
if a[i] * 4 * m < total:
flg = False
print('Yes') if flg else print('No') | 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")
| 1 | 38,499,893,144,988 | null | 179 | 179 |
A, B, C, D = input().split()
A = int(A)
B = int(B)
C = int(C)
D = int(D)
i = 0
for i in range(100):
C = (C - B)
if C <= 0:
print('Yes')
break
else:
A = A - D
if A <= 0:
print('No')
break
| A,B,C,D = (int(x) for x in input().split())
while True:
C -= B
if C <= 0:
print('Yes')
break
else:
A -= D
if A <= 0:
print('No')
break | 1 | 29,859,362,737,270 | null | 164 | 164 |
from operator import mul
D=int(input())
clist=list(map(int,input().split()))
slist=[]
for i in range (D):
s=list(map(int,input().split()))
slist.append(s)
tlist=[]
for i in range(D):
t=int(input())
tlist.append(t)
# print(clist,slist,tlist)
# D=5
# clist=[86, 90, 69, 51, 2, 96, 71, 47, 88, 34, 45, 46, 89, 34, 31, 38, 97, 84, 41, 80, 14, 4, 50, 83, 7, 82]
# slist=[[19771, 12979, 18912, 10432, 10544, 12928, 13403, 3047, 10527, 9740, 8100, 92, 2856, 14730, 1396, 15905, 6534, 4650, 11469, 3628, 8433, 2994, 10899, 16396, 18355, 11424], [6674, 17707, 13855, 16407, 12232, 2886, 11908, 1705, 5000, 1537, 10440, 10711, 4917, 10770, 17272, 15364, 19277, 18094, 3929, 3705, 7169, 6159, 18683, 15410, 9092, 4570], [6878, 4239, 19925, 1799, 375, 9563, 3445, 5658, 19857, 11401, 6997, 6498, 19933, 3848, 2426, 2146, 19745, 16880, 17773, 18359, 3921, 14172, 16730, 11157, 5439, 256], [8633, 15862, 15303, 10749, 18499, 7792, 10317, 5901, 9395, 11433, 3514, 3959, 5202, 19850, 19469, 9790, 5653, 784, 18500, 10552, 17975, 16615, 7852, 197, 8471, 7452], [19855, 17918, 7990, 10572, 4333, 438, 9140, 9104, 12622, 4985, 12319, 4028, 19922, 12132, 16259, 17476, 2976, 547, 19195, 19830, 16285, 4806, 4471, 9457, 2864, 2192]]
# tlist=[1, 17, 13, 14, 13]
noheldsday=[0]*26
benefit=0
for i in range (D):
_noheldsday=list(map(lambda x: x+1,noheldsday))
_noheldsday[tlist[i]-1]=0
unpleasant=list(map(mul,clist,_noheldsday))
v=slist[i][tlist[i]-1]-sum(unpleasant)
benefit+=v
noheldsday=_noheldsday
print(benefit)
| d = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(d)]
t = [int(input()) for _ in range(d)]
TYPES = 26
history = [-1] * TYPES
satisfaction_level = [0] * (d+1)
def last(day, i):
if history[i] == -1:
return 0
else:
return history[i]
def satisfaction(day, typ):
# コンテスト実施記録を更新
history[typ] = day
# 満足度の減少
decrease = sum((c[i]*(day-last(day,i)) for i in range(TYPES)))
value = s[day-1][typ] - decrease + satisfaction_level[day-1]
satisfaction_level[day] = value
return value
for day, typ in enumerate(t):
print(satisfaction(day+1, typ-1)) | 1 | 9,940,895,474,468 | null | 114 | 114 |
import sys
input = sys.stdin.readline
from collections import defaultdict
x = int(input())
pre = [i ** 5 for i in range(1001)] # Fuck it
for i in range(1001):
for j in range(i + 1):
if pre[i] - pre[j] == x: print(i, j); exit()
elif pre[i] + pre[j] == x: print(i, -j); exit()
| from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007
n, k = LI()
A = [0] + LI()
for i in range(1, n + 1):
A[i] = (A[i] + A[i - 1] - 1) % k
ans = 0
D = defaultdict(int)
for j in range(n, -1, -1):
ans += D[A[j]]
D[A[j]] += 1
if j + k - 1 < n + 1:
D[A[j + k - 1]] -= 1
if k == 1:
print(0)
else:
print(ans)
| 0 | null | 81,198,846,259,592 | 156 | 273 |
x,y = map(int,input().split())
for i in range(x+1):
turu = i
kame = x-i
if 2 * turu + 4 * kame == y:
print("Yes")
break
else :
print("No") | a, b = list(map(int, input().split()))
if b % 2 == 0 and 2 * a <= b <= 4 * a:
print('Yes')
else:
print('No') | 1 | 13,747,430,916,010 | null | 127 | 127 |
N = int(input())
A = list(map(int, input().split()))
MOD = 1000000007
cnt = [0,0,0] # 現在割り当てられている人数
ans = 1 # 現時点での組み合わせ
for a in A:
idx = []
for i in range(3):
if cnt[i] == a: # 割り当て可能
idx.append(i)
if len(idx)==0: # 割り当て不能
print(0)
exit()
cnt[idx[0]]+=1 # 任意の色で良いので、一番番号が若い色とする
ans *= len(idx) # 割り当て可能な人数をかける
ans %= MOD
print (ans) | #!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import collections
import functools as fts
import itertools as its
import math
import sys
INF = float('inf')
def solve(N: int):
def manhattan_distance(x1, y1, x2, y2):
return abs(x1-x2) + abs(y1-y2)
return min(manhattan_distance(1, 1, i, N//i) for i in range(1, int(math.sqrt(N))+1) if N % i == 0)
def main():
sys.setrecursionlimit(10 ** 6)
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
print(f'{solve(N)}')
if __name__ == '__main__':
main()
| 0 | null | 145,641,229,588,758 | 268 | 288 |
class Dice :
def __init__(self,num):
self.num = num
def move_E(self):
self.copy = self.num.copy()
for i,j in zip([0,2,5,3],[3,0,2,5]):
self.num[i] = self.copy[j]
def move_W(self):
self.copy = self.num.copy()
for i,j in zip([0,3,5,2],[2,0,3,5]):
self.num[i] = self.copy[j]
def move_N(self):
self.copy = self.num.copy()
for i,j in zip([0,1,5,4],[1,5,4,0]):
self.num[i] = self.copy[j]
def move_S(self):
self.copy = self.num.copy()
for i,j in zip([0,1,5,4],[4,0,1,5]):
self.num[i] = self.copy[j]
number = list(map(int,input().split()))
#number = [1,2,4,8,16,32]
#print("1 2 3 4 5 6")
# ?????????????????????
dice = Dice(number)
for order in input():
if order == 'S':
dice.move_S()
elif order == 'N':
dice.move_N()
elif order == 'W':
dice.move_W()
else:
dice.move_E()
# ?????????????????¶????????????
#print(dice.num)
print(dice.num[0]) | class Dice:
def __init__(self, label: list):
self.top, self.front, self.right, self.left, self.back, self.bottom = label
def roll(self, direction: str):
if direction == "N":
self.top, self.front, self.right, self.left, self.back, self.bottom = (
self.front,
self.bottom,
self.right,
self.left,
self.top,
self.back,
)
elif direction == "W":
self.top, self.front, self.right, self.left, self.back, self.bottom = (
self.right,
self.front,
self.bottom,
self.top,
self.back,
self.left,
)
elif direction == "S":
self.top, self.front, self.right, self.left, self.back, self.bottom = (
self.back,
self.top,
self.right,
self.left,
self.bottom,
self.front,
)
elif direction == "E":
self.top, self.front, self.right, self.left, self.back, self.bottom = (
self.left,
self.front,
self.top,
self.bottom,
self.back,
self.right,
)
def output_top(self):
print(self.top)
(*label,) = map(int, input().split())
dice = Dice(label)
for i in input():
dice.roll(i)
dice.output_top()
| 1 | 229,453,690,190 | null | 33 | 33 |
import sys
import fractions
from functools import reduce
readline = sys.stdin.buffer.readline
def main():
gcd = fractions.gcd
def lcm(a, b):
return a * b // gcd(a, b)
N, M = map(int, readline().split())
A = list(set(map(int, readline().split())))
B = A[::]
while not any(b % 2 for b in B):
B = [b // 2 for b in B]
if not all(b % 2 for b in B):
print(0)
return
semi_lcm = reduce(lcm, (a // 2 for a in A))
print((M // semi_lcm + 1) // 2)
return
if __name__ == '__main__':
main()
| def main():
from fractions import gcd
from math import ceil
n, m, *a = map(int, open(0).read().split())
b = [0 for _ in range(n)]
a.sort()
for i, j in enumerate(a):
c = 0
while j % 2 == 0:
c += 1
j = j // 2
a[i] = j
b[i] = c
if len(set(b)) > 1:
print(0)
exit()
lcm = 1
for i in a:
lcm = (lcm * i) // gcd(lcm, i)
k = b[0] - 1
ans = ceil(m // 2 ** k // lcm / 2)
print(ans)
if __name__ == "__main__":
main()
| 1 | 102,063,632,957,088 | null | 247 | 247 |
# 解説
import sys
pin = sys.stdin.readline
pout = sys.stdout.write
perr = sys.stderr.write
N, M, K = map(int, pin().split())
A = list(map(int, pin().split()))
B = list(map(int, pin().split()))
a = [0]
b = [0]
for i in range(N):
a.append(a[i] + A[i])
for i in range(M):
b.append(b[i] + B[i])
ans = 0
for i in range(N + 1):
#Aの合計がKを超えるまで比較する
if a[i] > K:
break
# 超えていた場合に本の個数を減らす
while b[M] > K - a[i]:
M -= 1
ans = max(ans, M + i)
print(ans)
| a, b, m = map(int, input().split())
li_a = list(map(int, input().split()))
li_b = list(map(int, input().split()))
li_c = []
for _ in range(m):
x, y, c = map(int, input().split())
x, y = x-1, y-1
li_c.append(li_a[x]+li_b[y]-c)
li_a.sort()
li_b.sort()
li_c.sort()
ans = min(li_a[0]+li_b[0], li_c[0])
print(ans)
| 0 | null | 32,428,497,670,822 | 117 | 200 |
n = int(input())
s = input()
rinds, ginds, binds = [], [], set()
for i in range(n):
if s[i] == 'R': rinds.append(i)
elif s[i] == 'G': ginds.append(i)
else: binds.add(i)
rlen, glen, blen = len(rinds), len(ginds), len(binds)
ans = 0
for i in rinds:
for j in ginds:
dist = abs(i-j)
i_ = min(i, j)
j_ = max(i, j)
ans += blen
# i' < j' < k
if j_ + dist in binds:
ans -= 1
if dist%2==0 and i_ + dist//2 in binds:
ans -= 1
if i_ - dist in binds:
ans -= 1
# if binsearch_same(binds, blen, dist, j_):
# ans -= 1
# # i'< k < j'
# if dist%2==0 and binsearch_same(binds, blen, dist//2, i_):
# ans -= 1
# # # k < i' < j'
# if binsearch_same(binds, blen, -dist, i_):
# ans -= 1
print(ans)
# n = input()
# print('Yes' if '7' in n else 'No')
# n = int(input())
# ans = 0
# for i in range(1, n+1):
# if i%3 == 0 or i%5==0:
# pass
# else:
# ans += i
# print(ans)
# k = int(input())
# def gcd(a, b):
# if b == 0:
# return a
# return gcd(b, a%b)
# ans = 0
# for a in range(1, k+1):
# for b in range(1, k+1):
# for c in range(1, k+1):
# ans += gcd(gcd(a, b), c)
# print(ans) | import sys
sys.setrecursionlimit(10**7)
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 LI2(): return list(map(int,sys.stdin.readline().rstrip())) #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split()) #空白あり
def LS2(): return list(sys.stdin.readline().rstrip()) #空白なし
N = I()
S = [''] + LS2()
R = [0]*(N+1)
G = [0]*(N+1)
B = [0]*(N+1)
for i in range(1,N+1):
s = S[i]
R[i] = R[i-1]
G[i] = G[i-1]
B[i] = B[i-1]
if s == 'R':
R[i] += 1
elif s == 'G':
G[i] += 1
else:
B[i] += 1
ans = 0
for i in range(2,N):
if S[i] == 'R':
ans += G[i-1]*(B[-1]-B[i])
ans += B[i-1]*(G[-1]-G[i])
for j in range(1,N+1):
if 1 <= i-j <= N and 1 <= i+j <= N:
if (S[i-j] == 'G' and S[i+j] == 'B') or (S[i-j] == 'B' and S[i+j] == 'G'):
ans -= 1
elif S[i] == 'G':
ans += R[i-1]*(B[-1]-B[i])
ans += B[i-1]*(R[-1]-R[i])
for j in range(1,N+1):
if 1 <= i-j <= N and 1 <= i+j <= N:
if (S[i-j] == 'R' and S[i+j] == 'B') or (S[i-j] == 'B' and S[i+j] == 'R'):
ans -= 1
else:
ans += G[i-1]*(R[-1]-R[i])
ans += R[i-1]*(G[-1]-G[i])
for j in range(1,N+1):
if 1 <= i-j <= N and 1 <= i+j <= N:
if (S[i-j] == 'R' and S[i+j] == 'G') or (S[i-j] == 'G' and S[i+j] == 'R'):
ans -= 1
print(ans)
| 1 | 36,130,641,036,166 | null | 175 | 175 |
n = int(input())
p = list(map(int, input().split()))
min_val = n + 1
count = 0
for x in p:
if x < min_val:
min_val = x
count += 1
print(count)
| N = int(input())
P = list(map(int, input().split()))
mmin = P[0]
ans = 0
for i in range(N):
if mmin < P[i]:
continue
else:
mmin = P[i]
ans += 1
print(ans) | 1 | 85,669,404,095,442 | null | 233 | 233 |
class Queue:
def __init__(self, n):
self.values = [None]*n
self.n = n
self.s = 0
self.t = 0
def next(self, p):
ret = p+1
if ret >= self.n:
ret = 0
return ret
def enqueue(self, x):
if self.next(self.s) == self.t:
raise Exception("Overflow")
self.values[self.s] = x
self.s = self.next(self.s)
def dequeue(self):
if self.s == self.t:
raise Exception("Underflow")
ret = self.values[self.t]
self.t = self.next(self.t)
return ret
n, q = map(int, raw_input().split(' '))
queue = Queue(n+1)
for _ in range(n):
name, time = raw_input().split(' ')
time = int(time)
queue.enqueue((name, time))
completed = []
cur = 0
while len(completed) < n:
name, time = queue.dequeue()
res = time-q
if res <= 0:
cur += time
completed.append((name, cur))
else:
cur += q
queue.enqueue((name, res))
for name, time in completed:
print name, time | from collections import deque
import itertools
h, w = map(int, input().split())
g = [input() for _ in range(h)]
# x,yはスタートの座標
def bfs(x, y):
# 最初は全て未訪問なので-1で初期化
d = [[-1] * w for _ in range(h)]
# スタート地点への距離は0
d[x][y] = 0
q = deque([(x, y)])
while q:
tx, ty = q.popleft()
# 右、上、左、下
for dx, dy in [(1, 0), (0, 1), (-1, 0), (0, -1)]:
nx, ny = tx + dx, ty + dy
# グリッドの範囲(縦方向, 横方向)内、通路(壁ではない)、未訪問(== -1)の場合
if 0 <= nx < h and 0 <= ny < w and g[nx][ny] == '.' and d[nx][ny] < 0:
d[nx][ny] = d[tx][ty] + 1
q.append((nx, ny))
# 最終的なdを平坦化して最大値を返す
return max(list(itertools.chain.from_iterable(d)))
# 全てのマスについて
max_count = 0
for x in range(h):
for y in range(w):
# スタートが通路であるかチェックする必要がある
if g[x][y] == ".":
max_count = max(max_count, bfs(x, y))
print(max_count)
| 0 | null | 47,322,962,246,880 | 19 | 241 |
import os, sys, re, math
(N, K) = [int(n) for n in input().split()]
H = [int(n) for n in input().split()]
print(len(list(filter(lambda h: h >= K, H))))
| S_list = [input() for i in range(2)]
N,K = map(int,S_list[0].split())
h_list = list(map(int,S_list[1].split()))
number = 0
for i in h_list:
if i>=K:
number += 1
print(number) | 1 | 179,199,443,000,620 | null | 298 | 298 |
k=int(input())
a,b=map(int,input().split())
cnt=0
for i in range(a, b+1):
if i%k==0:
cnt+=1
if cnt>0:
print('OK')
else :
print('NG')
| n, m = map(int, input().split())
L = list(map(int, input().split()))
a = 0
for i in range(len(L)):
a = a + L[i]
a = a / (4*m)
nL = sorted(L, reverse=True)
if a <= nL[m-1]:
print("Yes")
else:
print("No") | 0 | null | 32,805,751,530,170 | 158 | 179 |
N,K=map(int,input().split())
ans=0
for i in range(K,N+2):
if i!=(N+1):
anssub=N*(N+1)//2 -(N-i)*(N-i+1)//2 - i*(i-1)//2+1
else:
anssub=1
ans+=anssub
ans=ans%(10**9+7)
print(ans) | x,y,r=map(int,raw_input().split())
c=0
for i in range(x,y+1):
if r%i==0:
c=c+1
print c | 0 | null | 16,821,721,091,890 | 170 | 44 |
import itertools
from math import sqrt
n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]
ans = 0
cnt = 0
for v in itertools.permutations(list(range(n))):
for i in range(n-1):
x = (xy[v[i]][0]-xy[v[i+1]][0]) ** 2
y = (xy[v[i]][1]-xy[v[i+1]][1]) ** 2
ans += sqrt(x+y)
cnt += 1
print(ans/cnt) | input = raw_input().split(" ")
a = int(input[0])
b = int(input[1])
c = int(input[2])
if a < b:
if b < c:
print "Yes"
else:
print "No"
else:
print "No" | 0 | null | 74,441,985,131,292 | 280 | 39 |
n, k = map(int, input().split())
p = list(map(int, input().split()))
sortPrice = sorted(p)
# print(sortPrice)
price = []
for i in range(0, k):
price.append(sortPrice[i])
print(sum(price)) | S = input()
l = len(S)
x = [0]*(l+1)
y = [0]*(l+1)
for i in range(l):
if S[i] == "<":
x[i+1] = x[i]+1
for i in range(l):
if S[l-i-1] == ">":
y[l-i-1] = y[l-i]+1
res = 0
for a, b in zip(x, y):
res += max(a, b)
print(res) | 0 | null | 84,009,599,256,560 | 120 | 285 |
X = int(input())
happy = 0
happy += X // 500 * 1000
X = X % 500
happy += X //5 * 5
print(happy) | x = int(input())
n_500 = int(x / 500)
h = 1000 * n_500
x -= 500 * n_500
n_5 = int(x / 5)
h += 5 * n_5
print(int(h))
| 1 | 43,025,580,735,008 | null | 185 | 185 |
W = raw_input().lower()
s = []
ans = 0
while True:
T = map(str, raw_input().split())
if(T[0] == "END_OF_TEXT"):
break
else:
for i in range(len(T)):
if(W == T[i].lower()):
ans += 1
print(ans) | a,b,c,d,e=input().split()
a=int(a)
b=int(b)
c=int(c)
d=int(d)
e=int(e)
if a==0:
print('1')
elif b==0:
print('2')
elif c==0:
print('3')
elif d==0:
print('4')
elif e==0:
print('5') | 0 | null | 7,541,798,131,900 | 65 | 126 |
#!/usr/bin/env python3
import sys
from typing import NamedTuple, List
class Game(NamedTuple):
c: List[int]
s: List[List[int]]
def solve(D: int, c: "List[int]", s: "List[List[int]]", t: "List[int]"):
from functools import reduce
ans = [0]
lasts = [0] * 26
adjust = 0
sum_c = sum(c)
daily_loss = sum_c
for day, tt in enumerate(t, 1):
a = s[day-1][tt-1]
adjust += day * c[tt-1] - lasts[tt-1] * c[tt-1]
lasts[tt-1] = day
a -= daily_loss
a += adjust
ans.append(ans[-1]+a)
daily_loss += sum_c
return ans[1:]
# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
D = int(next(tokens)) # type: int
c = [int(next(tokens)) for _ in range(26)] # type: "List[int]"
s = [[int(next(tokens)) for _ in range(26)] for _ in range(D)] # type: "List[List[int]]"
t = [int(next(tokens)) for _ in range(D)] # type: "List[int]"
print(*solve(D, c, s, t), sep="\n")
def test():
import doctest
doctest.testmod()
if __name__ == '__main__':
#test()
main()
| r,c = map(int,input().split())
a = [list(map(int,input().split(" "))) for i in range(r)]
for i in range(r):
r_total = sum(a[i])
a[i].append(r_total)
c_total = []
for j in range(c+1):
s = 0
for k in range(r):
s += a[k][j]
c_total.append(s)
a.append(c_total)
for z in range(r+1):
for w in range(c+1):
print(a[z][w],end="")
if w != c:
print(" ",end="")
print() | 0 | null | 5,659,908,914,660 | 114 | 59 |
# -*- coding: utf-8 -*-
input_list = input().split(" ")
print(int(input_list[0]) * int(input_list[1])) | import sys
stdin = sys.stdin
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))
def naa(N): return [na() for _ in range(N)]
def ns(): return stdin.readline().rstrip() # ignore trailing spaces
A, B = na()
print(A * B)
| 1 | 15,767,334,806,540 | null | 133 | 133 |
N = input()
sum_n = 0
for n in N:
num = int(n)
sum_n += num
if(sum_n % 9 == 0):
print("Yes")
else:
print("No")
| N = str(input())
bruh = 0
for i in N :
bruh += int(i)
if bruh %9 == 0 :
print ("Yes")
else :
print ("No")
| 1 | 4,383,424,927,492 | null | 87 | 87 |
def GCD(a, b):
b %= a
return b if a%b == 0 else GCD(b, a)
while True:
try:
a, b = list(map(float, input().split()))
except EOFError:
break
if a >= b:
a, b = b, a
gcd = GCD(a, b) if b%a != 0 else a
print("{0} {1}".format(int(gcd), int(a*b/gcd))) | import sys
def gcd(m, n):
r = m % n
if r == 0:
return n
else:
return gcd(n, r)
lines = sys.stdin.readlines()
for line in lines:
a, b = map(int, line.split())
m = max(a, b)
n = min(a, b)
print(gcd(m, n), m * n // gcd(m, n)) | 1 | 582,912,550 | null | 5 | 5 |
def nCr(n, r, mod):
x, y = 1, 1
for r_ in range(1, r+1):
x = x*(n+1-r_)%mod
y = y*r_%mod
return x*pow(y, mod-2, mod)%mod
x, y = map(int, input().split())
mod = 10**9+7
if (x+y)%3 or 2*x<y or 2*y<x:
print(0)
else:
print(nCr((x+y)//3,(2*x-y)//3, mod)) | #####################################################
# 組み合わせを10**9+7で割った余り、を高速に求めるアルゴリズム
# https://drken1215.hatenablog.com/entry/2018/06/08/210000
# https://qiita.com/derodero24/items/91b6468e66923a87f39f
# 全然理解できていない
MOD = 10**9 + 7
def comb(n, r):
if (r < 0 and r > n):
return 0
r = min(r, n - r)
return g1[n] * g2[r] * g2[n - r] % MOD
N = 10**6
# 元テーブル
g1 = [1, 1]
# 逆元テーブル
g2 = [1, 1]
# 逆元テーブル計算用テーブル
inverse = [0, 1]
for i in range(2, N + 1):
g1.append((g1[-1] * i) % MOD)
inverse.append((-inverse[MOD % i] * (MOD // i)) % MOD)
g2.append((g2[-1] * inverse[-1]) % MOD)
#####################################################
X, Y = map(int, input().split())
# X+Yが3の倍数のマスしか通りえない
if not (X + Y) % 3:
# (1,2)移動をn回、(2,1)移動をm回したとする
# n+2m = X, 2n+m = Y
# → n+m = (X+Y)/3
# n = (2n+m)-(n+m) = X - (X+Y)/3 = (-X+2Y)/3
# mも同様
n = (2 * Y - X) // 3
m = (2 * X - Y) // 3
if n >= 0 and m >= 0:
print(comb(n + m, n))
else:
print(0)
# X+Yが3の倍数でない場合
else:
print(0)
| 1 | 149,913,849,219,468 | null | 281 | 281 |
def show(nums):
for i in range(len(nums)):
if i != len(nums) - 1:
print(nums[i],end=' ')
else:
print(nums[i])
def bubbleSort(A,N):
flag = 1
count = 0
while flag:
flag = 0
for j in range(N-1,0,-1):
if A[j] < A[j-1]:
tmp = A[j]
A[j] = A[j-1]
A[j-1] = tmp
flag = 1
count += 1
show(A)
print(count)
N = int(input())
A = list(map(int,input().split()))
bubbleSort(A,N)
| # -*- coding: utf-8 -*-
def bubbleSort(num_list):
flag = True
length = len(num_list)
count = 0
while flag:
flag = False
for j in range(length-1, 0, -1):
if num_list[j] < num_list[j-1]:
num_list[j], num_list[j-1] = num_list[j-1], num_list[j]
flag = True
count += 1
return num_list, count
input_num = int(input())
num_list = [int(i) for i in input().split()]
bubble_list, swap_num = bubbleSort(num_list)
for i in range(len(num_list)):
if i > 0:
print(" ", end="")
print(num_list[i], end="")
print()
print(swap_num) | 1 | 16,401,067,200 | null | 14 | 14 |
a = list(map(int,input().split()))
print(a[0]*a[1] if a[0] <= 9 and a[1] <= 9 else -1) | A,B = map(int, input().split())
if A > 9 or B > 9 or A < 1 or B < 1:
print(-1)
else:
print(A*B) | 1 | 158,244,223,501,838 | null | 286 | 286 |
Subsets and Splits