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
|
---|---|---|---|---|---|---|
#coding:utf-8
n = int(input())
A = list(map(int, input().split()))
times = 0
for i in range(n):
minj = i
for j in range(i,n):
if A[j] < A[minj]:
minj = j
if i != minj:
A[i], A[minj] = A[minj], A[i]
times += 1
B = " ".join([str(num) for num in A])
print(B)
print(times)
|
def selectionSort(A,N,cnt=0):
for i in range(N):
minj = i
for j in range(i,N):
if A[j] < A[minj]:
minj = j
A[i] , A[minj] = A[minj] , A[i]
if A[i] != A[minj]:
cnt += 1
return A , cnt
N = int(input())
A = list(map(int,input().split()))
X , cnt = selectionSort(A,N)
print(*X)
print(cnt)
| 1 | 20,709,753,398 | null | 15 | 15 |
n = int(input())
given_list = list(map(int, input().split()))
for i in range(n):
if i == n-1:
print(given_list[n-i-1])
else:
print(given_list[n-i-1], end=" ")
|
house1 = [[0 for x in range(10)], [0 for x in range(10)], [0 for x in range(10)]]
house2 = [[0 for x in range(10)], [0 for x in range(10)], [0 for x in range(10)]]
house3 = [[0 for x in range(10)], [0 for x in range(10)], [0 for x in range(10)]]
house4 = [[0 for x in range(10)], [0 for x in range(10)], [0 for x in range(10)]]
houses = [house1, house2, house3, house4]
n = int(input())
for i in range(n):
b, f, r, v = [int(x) for x in input().split()]
houses[b - 1][f - 1][r - 1] += v
cnt = 0
for house in houses:
for floor in house:
floor = [str(x) for x in floor]
print(' ' + ' '.join(floor))
if cnt != 3:
print('#' * 20)
cnt += 1
| 0 | null | 1,067,658,916,050 | 53 | 55 |
M = 1000000007
n = int(input())
a = list(map(int,input().split()))
S = [0]
for i in range(n):
S.append((S[-1]+a[i])%M)
sum = 0
for i in range(n-1):
sum += (a[i]*(S[n]-S[i+1]))%M
print(sum%M)
|
import math
deg = int(input())
li_x = list(map(int,input().split()))
li_y = list(map(int, input().split()))
p1_dis = 0.0
p2_dis = 0.0
p2_temp = 0.0
p3_dis = 0.0
p3_temp = 0.0
p4_dis = 0.0
p4_temp = [ ]
for i in range(deg):
p1_dis += math.fabs(li_x[i] - li_y[i])
p2_temp += (li_x[i] - li_y[i]) **2.0
p3_temp += math.fabs(li_x[i] - li_y[i]) **3.0
p4_temp.append( math.fabs(li_x[i] - li_y[i]) )
p2_dis = math.sqrt( p2_temp )
p3_dis = math.pow(p3_temp, 1.0/3.0)
p4_dis = max(p4_temp)
print('{0:.6f}'.format(p1_dis))
print('{0:.6f}'.format(p2_dis))
print('{0:.6f}'.format(p3_dis))
print('{0:.6f}'.format(p4_dis))
| 0 | null | 2,052,074,727,180 | 83 | 32 |
X, N = map(int,input().split())
p_n = list(map(int,input().split()))
p = list(range(102))
for i in p_n:
for j in range(len(p)):
if p[j] == i:
p.pop(j)
break
p_X = list(map(lambda x: x - X, p))
p_abs = list(map(abs,p_X))
print(p[p_abs.index(min(p_abs))])
|
def main():
n, m = map(int, input().split())
qry = [list(map(int, input().split())) for _ in range(m)]
ans = -1
for v in range(0, 1000):
s = str(v)
if len(s) != n:
continue
f = True
for p, x in qry:
if s[p-1] != str(x):
f = False
break
if f:
ans = v
break
print(ans)
if __name__ == "__main__":
main()
| 0 | null | 37,426,520,540,402 | 128 | 208 |
import sys
input = sys.stdin.readline
A = list(map(int, input().split()))
if sum(A) >= 22:
print('bust')
else:
print('win')
|
#!/usr/bin/env python3
print("bwuisnt"[eval(input().replace(" ", "+")) < 22::2])
| 1 | 118,958,192,402,180 | null | 260 | 260 |
n,x,m=map(int,input().split())
# 一定回数を経ると循環するので最後にかければよい
a_i = x
log = [x]
app=[-1]*m
app[x]=0
last = x
for i in range(1,n):
a_i = (a_i**2)%m
if app[a_i] > -1:
last = a_i
break
app[a_i] = i
log.append(a_i)
# ループの手前(or最後)まで足し合わせる
ans = sum(log[:min(n, app[last])])
if n > app[last]:
# ループ中合計
ans += sum(log[app[last]:]) * ((n-app[last]) // (len(log) - app[last]))
# 末端合計
ans += sum(log[app[last]:app[last] + (n-app[last]) % (len(log) - app[last])])
print(ans)
|
def solve(N, X, M):
x = X
table = [-1] * M
a = []
length = 0
# ループするまで配列に値を入れていく
while table[x] == -1:
a.append(x)
table[x] = length
length += 1
x = x**2 % M
# ループの開始位置とループの合計値を求める
start = table[x]
loop_total = 0
for i in range(table[x], length):
loop_total += a[i]
# 答えの計算
ans = 0
if N <= length:
for i in range(N):
ans += a[i]
else:
# フルで何周するかを計算
count = N - start
count //= (length-start)
ans += count * loop_total
count *= (length-start)
count = N - count
for i in range(count):
ans += a[i]
return ans
if __name__ == "__main__":
N, X, M = map(int, input().split())
print(solve(N, X, M))
| 1 | 2,803,843,499,888 | null | 75 | 75 |
a = int(input())
print(int(a**2))
|
import sys
def II(): return str(input())
def MI(): return map(int,input().split())
def MI2(): return map(str,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))
def RN(N): return [input().strip() for i in range(N)]
def main():
S, T = MI2()
A, B = MI()
U = II()
if U == S:
A = A-1
elif U == T:
B = B-1
print(A, B)
if __name__ == "__main__":
main()
| 0 | null | 108,660,606,278,280 | 278 | 220 |
#!/usr/bin/env python
# encoding: utf-8
from __future__ import print_function
class Solution:
"""
@param prices: Given an integer array
@return: Maximum profit
"""
@staticmethod
def insertion_sort():
# write your code here
array_length = int(input())
unsorted_array = [int(x) for x in input().split()]
for i in range(array_length):
v = unsorted_array[i]
j = i - 1
while j >= 0 and unsorted_array[j] > v:
unsorted_array[j + 1] = unsorted_array[j]
j -= 1
unsorted_array[j + 1] = v
print(" ".join(map(str, unsorted_array)))
if __name__ == '__main__':
solution = Solution()
solution.insertion_sort()
|
def insert_sort(A):
for i in range(1, len(A)):
k = A[i]
j = i - 1
while j >= 0 and A[j] > k:
A[j + 1] = A[j]
j -= 1
A[j + 1] = k
show(A)
def show(A):
for i in range(len(A) - 1):
print(A[i], end=" ")
print(A[len(A) - 1])
n = int(input())
line = input()
A = list(map(int, line.split()))
show(A)
insert_sort(A)
| 1 | 5,280,898,400 | null | 10 | 10 |
[a,b,c] = list(map(int,input().split()))
if c-a-b<0:
print('No')
else:
left = 4*a*b
right = (c-a-b)**2
if left<right:
print('Yes')
else:
print('No')
|
import math
a, b, c = [int(n) for n in input().split()]
if 4*a*b < (c - a - b) ** 2 and c > a + b:
print('Yes')
else:
print('No')
| 1 | 51,669,760,603,188 | null | 197 | 197 |
pi = 3.14159265358979
r = float(raw_input())
print '%.6f %.6f'%(pi*r*r, 2*pi*r)
|
r=float(raw_input())
p=float(3.14159265358979323846264338327950288)
s=p*r**2.0
l=2.0*p*r
print"%.5f %.5f"%(float(s),float(l))
| 1 | 640,470,687,898 | null | 46 | 46 |
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)
|
import itertools # accumulate, compress, permutations(nPr), combinations(nCr)
import bisect # bisect_left(insert位置), bisect_right(slice用)
# import math # factorical(階乗) # hypot(距離)
# import heapq
# from fractions import gcd # Python3.5以前 # lcm(最小公倍数) = (a*b)//gcd(a,b)
# from fractions import Fraction
# from math import gcd # Python3.6以降
# --------------------------------------------------------------
n = int(input())
bo = list(map(int,input().split()))
cnt = 0
bo.sort()
for a in range(n-1):
for b in range(a+1,n):
cnt += bisect.bisect_left(bo, bo[a]+bo[b]) - (b+1)
print(cnt)
| 1 | 172,327,034,570,192 | null | 294 | 294 |
n = int(input())
r = n // 2
a = n % 2
print(r + a)
|
N = int(input())
ans = N//2 + N%2
print(ans)
| 1 | 58,858,634,727,712 | null | 206 | 206 |
n = int(input())
s = input()
for i in range(n-1):
if s[i] == s[i+1]:
s = s[:i] + " " + s[i+1:]
print(len(s.replace(" ", "")))
|
S=input()
ans=[]
for i in range(len(S)):
if S[i]=="?":
ans.append("D")
else:
ans.append(S[i])
print("".join(ans))
| 0 | null | 94,333,372,773,120 | 293 | 140 |
n, m = map(int, input().split())
c = sorted([int(i) for i in input().split()])
dp = [[0 for j in range(n+1)] for i in range(m+1)]
dp[1] = [int(i) for i in range(n+1)]
for i in range(2, m+1):
for j in range(n+1):
if j - c[i-1] > -1:
dp[i][j] = min(dp[i-1][j], dp[i][j-c[i-1]]+1)
else:
dp[i][j] = dp[i-1][j]
print(dp[m][n])
|
n,m=map(int,input().split())
C=list(map(int,input().split()))
inf=float('inf')
DP=[[inf]*(n+1) for i in range(m+1)]
DP[0][0]=0
for i in range(m):
for j in range(n+1):
if j-C[i]<0:
DP[i+1][j]=DP[i][j]
else:
DP[i+1][j]=min(DP[i][j],DP[i+1][j-C[i]]+1)
print(DP[m][n])
| 1 | 137,609,981,080 | null | 28 | 28 |
N=int(input())
S=input()
S=list(S)
ans=[]
color = ''
for s in S:
if color != s:
ans.append(s)
color = s
print(len(ans))
|
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")
n = k()
d=l()
for i in itertools.combinations(d,2):
ans += i[0]*i[1]
print(ans)
| 0 | null | 169,295,010,804,548 | 293 | 292 |
a=list(map(int,input().split()))
if a[0]+a[1]+a[2]>=22:
print("bust")
else:
print("win")
|
a1, a2, a3 = (map(int, input().split()))
if sum([a1, a2, a3]) >= 22:
print('bust')
else:
print('win')
| 1 | 118,724,721,065,432 | null | 260 | 260 |
from itertools import accumulate
from collections import defaultdict
N, K = map(int, input().split())
A = list(map(int, input().split()))
B = accumulate([0]+ A)
C = [(b-i)%K for i, b in enumerate(B)]
cnt = defaultdict(int)
cnt[C[0]] = 1
res = 0
for i in range(1, N+1):
if i >= K:
cnt[C[i-K]] -= 1
res += cnt[C[i]]
cnt[C[i]] += 1
print(res)
|
print(' '.join((lambda x:[str((x[2]-1)) if x[4] == x[0] else str(x[2]),str((x[3]-1)) if x[4] == x[1] else str(x[3])])(input().split()+list(map(int,input().split()))+[input()])))
| 0 | null | 105,207,525,283,968 | 273 | 220 |
N,K=map(int,input().split())
D=[0]*(K+1)
D[K]=1
mod=10**9+7
for i in range(K,0,-1):
D[i]=pow(K//i,N,mod)
for j in range(2*i,K+1,i):
D[i]=(D[i]-D[j])%mod
c=0
for i in range(len(D)):
c+=D[i]*i
print(c%mod)
|
#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify
import itertools, bisect
import math, fractions
import sys, copy
def L(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline().rstrip())
def S(): return list(sys.stdin.readline().rstrip())
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def LIR1(n): return [LI1() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
def LR(n): return [L() for _ in range(n)]
def perm(n, r): return math.factorial(n) // math.factorial(r)
def comb(n, r): return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))
alphabets = "abcdefghijklmnopqrstuvwxyz"
ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
sys.setrecursionlimit(1000000)
dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
MOD = 1000000007
INF = float("inf")
class Eratosthenes:
# https://cp-algorithms.com/algebra/prime-sieve-linear.html
def __init__(self, n):
primes = []
lp = [0] * (n + 1)
for i in range(2, n + 1):
if lp[i] == 0:
primes.append(i)
lp[i] = i
for pj in primes:
if pj > lp[i] or i * pj > n:
break
lp[i * pj] = pj
self.primes = primes
self.lp = lp
def is_prime(self, x):
return self.lp[x] == x
def factrization(self, x):
ret = []
while x > 1:
ret.append(self.lp[x])
x //= self.lp[x]
return ret
def main():
N, K = LI()
era = Eratosthenes(K)
count = [0] * (K + 1)
for i in range(1, K + 1):
count[i] = pow((K // i), N, MOD)
for i in range(1, K + 1)[::-1]:
divs = era.factrization(i)
candedates = [l for l in set(reduce(lambda x, y:x * y, ll, 1) for r in range(1, len(divs) + 1) for ll in itertools.combinations(divs, r))]
for v in candedates:
count[i // v] -= count[i]
ans = 0
for i in range(1, K + 1):
ans = (ans + i * count[i]) % MOD
print(ans % MOD)
if __name__ == '__main__':
main()
| 1 | 36,736,797,444,330 | null | 176 | 176 |
x,y = map(str,input().split())
a = {'1':300000,'2':200000,'3':100000}
if int(x) > 3 or int(y) > 3:
if int(x) <= 3:
print(a[x])
elif int(y) <= 3:
print(a[y])
else:
print(0)
else:
if x == y == '1':
print(1000000)
else:
print(a[x]+a[y])
|
XY= list(map(int,input().split()))
X=XY[0]
Y=XY[1]
if X==1:
syokinx=300000
elif X==2:
syokinx=200000
elif X==3:
syokinx=100000
else:
syokinx=0
if Y==1:
syokiny=300000
elif Y==2:
syokiny=200000
elif Y==3:
syokiny=100000
else:
syokiny=0
if X==1 and Y==1:
syokinz=400000
else:
syokinz=0
print(syokinx+syokiny+syokinz)
| 1 | 141,110,181,396,976 | null | 275 | 275 |
import math
N = int(input())
n_max = int(math.sqrt(N))
a = []
for i in range(1,n_max + 1):
if N % i == 0:
a.append(i)
ans = 2 * N
for i in a:
if (i + (N // i) - 2) < ans:
ans = i + (N // i) - 2
print(ans)
|
import sys
from collections import deque
sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7
def input():
return sys.stdin.readline().strip()
def main():
N = input()
length = len(N)
K = int(input())
# 左からi桁目まで見て,N以下が確定していて,0でない数字がk個ある数字の個数
dp_1 = [[0] * (10) for _ in range(length)]
# 左からi桁目まで見て,N以下が確定していなくて,0でない数字がk個ある数字の個数
dp_2 = [[0] * (10) for _ in range(length)]
dp_1[0][0] = 1
dp_1[0][1] = int(N[0]) - 1
dp_2[0][1] = 1
for i in range(1, length):
# 小さいのが確定しているものに対して,0以外のものを追加
for k in range(1, K + 2):
dp_1[i][k] += dp_1[i - 1][k - 1] * 9
# 小さいものが確定しているものに対して,0を追加
for k in range(0, K + 2):
dp_1[i][k] += dp_1[i - 1][k]
# 大小がわからないものから,小さいのが確定する
if N[i] == "0":
for k in range(K + 2):
dp_2[i][k] += dp_2[i - 1][k]
else:
# 0を追加する
for k in range(K + 2):
dp_1[i][k] += dp_2[i - 1][k]
# その他の数字を追加
for k in range(1, K + 2):
dp_1[i][k] += dp_2[i - 1][k - 1] * (int(N[i]) - 1)
# 依然として大小関係がわからない
for k in range(1, K + 2):
dp_2[i][k] += dp_2[i - 1][k - 1]
ans = dp_1[-1][K] + dp_2[-1][K]
print(ans)
if __name__ == "__main__":
main()
| 0 | null | 118,375,438,285,852 | 288 | 224 |
x,k,d = map(int,input().split())
def judge():
l = x if x > 0 else -x
i = l//d
r = l%d
if (k - i)%2 == 0:
print(r)
else:
print(d - r)
'''
if x > 0:
for r in range(d):
if (x - r)/d == (x - r)//d:
i = (x - r)//d
if (k - i)%2 == 0:
print(r)
else:
print(d-r)
exit()
else:
l = -x
for r in range(d):
if (l - r)/d == (l - r)//d:
i = (l - r)//d
if (k - i)%2 == 0:
print(r)
else:
print(d-r)
exit()
'''
if x == 0:
if k%2 == 0:
print(0)
else:
print(d)
elif x < 0:
if k*d + x > 0:
judge()
else:
print(abs(k*d + x))
else:
if x - k*d < 0:
judge()
else:
print(abs(x - k*d))
|
# https://atcoder.jp/contests/sumitrust2019/tasks/sumitb2019_e
n = int(input())
A = list(map(int, input().split()))
MOD = 1000000007
counts = [0, 0, 0]
result = 1
for i in range(n):
a = A[i]
# print(a, counts, result)
cnt = counts.count(a)
result *= cnt
result %= MOD
for j in range(len(counts)):
if counts[j] == a:
counts[j] += 1
break
print(result)
| 0 | null | 67,543,566,594,208 | 92 | 268 |
def main():
N = int(input())
# K > 1
def divisor_set(x):
ret = set()
if x > 1:
ret.add(x)
d = 2
while d * d <= x:
if x % d == 0:
ret.add(d)
ret.add(x // d)
d += 1
return ret
# N % K == 1
# (N-1) % K == 0
# K > 1
ans = 0
ans += len(divisor_set(N - 1))
# N % K == 0
# N //= K ---> M
# (M-1) % K == 0
for k in divisor_set(N):
x = N
while x % k == 0:
x //= k
if x % k == 1:
ans += 1
print(ans)
if __name__ == '__main__':
main()
# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())
|
# coding: utf-8
def check_divide(n):
max_v = int(n ** (1/2))
divide_nums = []
for i in range(1,max_v + 1):
if n % i == 0:
divide_nums.append(i)
return divide_nums
def check_divide2(n):
divide_nums = []
for K in range(2,n+1):
tmp = n
while True:
if tmp % K ==0:
tmp = tmp // K
else:break
if tmp % K == 1:
divide_nums.append(K)
return divide_nums
if __name__ == '__main__':
N = int(input())
tmp1 = check_divide(N-1)
if tmp1[-1] ** 2 == N-1:
tmp1 = len(tmp1) * 2 - 2
else:
tmp1 = len(tmp1) * 2 - 1
candidates = check_divide(N)[1:]
tmp2 = [N]
for val in candidates:
N_ = N
while True:
if N_ % val == 0:
N_ = N_ / val
else:break
if N_ % val == 1:
tmp2.append(val)
tmp2 = len(tmp2)
print(tmp1 + tmp2)
| 1 | 41,309,004,362,978 | null | 183 | 183 |
H, W, m = map(int, input().split())
hw = [list(map(int, input().split())) for _ in range(m)]
row, col = [0] * H, [0] * W
for h, w in hw:
row[h - 1] += 1
col[w - 1] += 1
rowmax, colmax = max(row), max(col)
cnt = row.count(rowmax) * col.count(colmax)
for h, w in hw:
if row[h - 1] == rowmax and col[w - 1] == colmax:
cnt -= 1
print(rowmax + colmax - (cnt == 0))
|
import string
L = string.split(raw_input())
a = int(L[0])
b = int(L[1])
if a == b:
print "a == b"
elif a > b:
print "a > b"
elif a < b:
print "a < b"
| 0 | null | 2,560,337,073,968 | 89 | 38 |
n,k=map(int,input().split())
ar=list(map(int,input().split()))
for i in range(k,n):
print("Yes" if ar[i]>ar[i-k] else "No")
|
def resolve():
X, Y, Z = list(map(int, input().split()))
print(Z, X, Y)
if '__main__' == __name__:
resolve()
| 0 | null | 22,464,124,116,988 | 102 | 178 |
import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
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)]
M = 26
last = [0]*M
score = 0
for i in range(D):
score += S[i][t[i]-1]
last[t[i]-1] = i+1
for m in range(M):
score -= C[m]*(i+1-last[m])
print(score)
|
D=int(input())
c=list(map(int,input().split()))
c_memo=[0]*26
s=[]
for i in range(D):
ss=list(map(int,input().split()))
s.append(ss)
ans_b=[]
for i in range(D):
t=int(input())
c_down=0
for j in range(26):
if j==t-1:
c_memo[t-1]=i+1
continue
else:
c_down+=(i+1-c_memo[j])*c[j]
ans=s[i][t-1]-c_down
ans_b.append(ans)
ans=0
for x in ans_b:
ans+=x
print(ans)
| 1 | 9,871,165,382,080 | null | 114 | 114 |
from sys import exit
import math
import collections
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))
s = input()
cnt = 0
for i in range(len(s)//2):
if s[i] != s[-1-i]:
cnt += 1
print(cnt)
|
s = input()
n = len(s)
c = 0
for i in range((n+1)//2):
if s[i] != s[n-i-1]:
c += 1
print(c)
| 1 | 120,182,394,362,240 | null | 261 | 261 |
import sys
input = sys.stdin.readline
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def main():
mod=10**9+7
T=LI()
A=LI()
B=LI()
d1=(A[0]-B[0])*T[0]
d2=(A[1]-B[1])*T[1]
if d1>=0:
#最初は必ず正の方向へいかないように調整
d1*=-1
d2*=-1
if d1+d2==0:
print("infinity")
elif d1==0:#d1=0のパターンを排除した
print(0)
elif d1+d2<=0:
print(0)
else:
cnt=(-1*d1)//(d1+d2)
ans=cnt*2+1
if cnt*(d1+d2)==-1*d1:
ans-=1
print(ans)
main()
|
import math
def main():
t1, t2 = map(int, input().split())
a1, a2 = map(int, input().split())
b1, b2 = map(int, input().split())
sumA = t1 * a1 + t2 * a2
sumB = t1 * b1 + t2 * b2
if sumA == sumB:
return 'infinity'
if sumA < sumB:
sumA, sumB = sumB, sumA
a1, b1 = b1, a1
a2, b2 = b2, a2
# A の方が sum が大きいとする
halfA = t1 * a1
halfB = t1 * b1
if halfA > halfB:
return 0
div, mod = divmod(halfB - halfA, sumA - sumB)
if mod == 0:
return div * 2
return div * 2 + 1
print(main())
| 1 | 132,069,657,259,100 | null | 269 | 269 |
N, K, S = map(int, input().split())
if S == 10**9:
ans = [1]*N
else:
ans = [S+1] * N
for i in range(K):
ans[i] = S
print(" ".join(map(str, ans)))
|
N, K, S = map(int, input().split())
if S < 10**9:
T = S + 1
else:
T = S - 1
ans = [S]*K + [T]*(N-K)
print(*ans)
| 1 | 91,435,183,917,282 | null | 238 | 238 |
def cmb(n, r, mod):
if ( r<0 or r>n ):
return 0
r = min(r, n-r)
return g1[n] * g2[r] * g2[n-r] % mod
s = int(input())
mod = 10 **9 + 7
N = s
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 )
l = s//3
ans = 0
if s <= 2:
print(0)
else:
for i in range(l):
ans += cmb(s%3 + 3 * i +(l-i)-1, (l-i)-1,mod)
print(ans%mod)
|
#! /usr/bin/env python3
import sys
get = sys.stdin.read().split('\n')
for g in get:
nums = list(map(int, g.split()))
output = ''
if (nums != []):
# print(nums)
[a, b] = nums
while ((a != 0) and (b != 0)):
larger = max([a, b])
smaller = min([a, b])
a = larger - smaller
b = smaller
output += str(max([a, b])) + ' ' + str((nums[0]*nums[1])//max([a,b]))
print(output)
| 0 | null | 1,615,968,303,160 | 79 | 5 |
N, K = map(int, input().split())
Range = [None] * K
for i in range(K):
Range[i] = list(map(int, input().split()))
sweep = {1: 1}
M = 998244353
value = 0
for cell in range(1, N+1):
value += sweep.get(cell, 0)
value = (value + M) % M
for r in range(K):
sweep[cell + Range[r][0]] = (sweep.get(cell + Range[r][0], 0) + value + M) % M
sweep[cell + Range[r][1] + 1] = (sweep.get(cell + Range[r][1] + 1, 0) - value + M) % M
print(sweep.get(N, 0))
|
W = raw_input().lower()
doc = []
while True:
tmp = raw_input()
if tmp == 'END_OF_TEXT':
break
doc.extend(tmp.lower().split())
print doc.count(W)
| 0 | null | 2,266,216,610,018 | 74 | 65 |
import sys
import numpy as np
N = input()
print(N[0:3])
|
import random
name = list(input())
i = random.randint(0,len(name)-3)
print(name[i],end="")
print(name[i+1],end="")
print(name[i+2])
| 1 | 14,877,730,020,708 | null | 130 | 130 |
S, T = input().split()
A, B = map(int, input().split())
U = input()
if U == S:
A -= 1
else:
B -= 1
print(A, B, sep=' ')
|
s,t=map(str,input().split())
a,b=map(int,input().split())
u=input()
print(str(a-1) + " " + str(b) if s==u else str(a) + " " + str(b-1))
| 1 | 72,227,458,371,936 | null | 220 | 220 |
s = input()
s_list = list(s)
if s_list[-1] == 's':
output = s + 'es'
else:
output = s + 's'
print(output)
|
def run(s):
'''
'''
print('{}{}'.format(s, 'es' if s[-1] == 's' else 's'))
if __name__ == '__main__':
s = input()
run(s)
| 1 | 2,382,500,791,212 | null | 71 | 71 |
def main():
n = input()
A = map(int,raw_input().split())
c = mergeSort(A,0,n)
for i in range(n-1):
print A[i],
print A[-1]
print c
def merge(A,left,mid,right):
n1 = mid - left
n2 = right - mid
L = [A[left+i] for i in range(n1)]
L += [float("inf")]
R = [A[mid+i] for i in range(n2)]
R += [float("inf")]
i = 0
j = 0
for k in range(left,right):
if L[i] <= R[j]:
A[k] = L[i]
i += 1
else:
A[k] = R[j]
j += 1
return i+j
def mergeSort(A,left,right):
if left+1 < right:
mid = (left+right)/2
k1 = mergeSort(A,left,mid)
k2 = mergeSort(A,mid,right)
k3 = merge(A,left,mid,right)
return k1+k2+k3
else:
return 0
if __name__ == "__main__":
main()
|
D = int(input())
c = list(map(int, input().split()))
s_matrix = [list(map(int, input().split())) for _ in range(D)]
t = [int(input()) for _ in range(D)]
last = [0] * 26
satis = 0
for i in range(D):
test = t[i] - 1
satis += s_matrix[i][test]
last[test] = i + 1
for j in range(26):
satis -= c[j] * (i+1 - last[j])
print(satis)
| 0 | null | 4,972,801,611,360 | 26 | 114 |
from collections import deque
n=int(input())
arr=[[] for _ in range(n)]
for i in range(n-1):
a,b=map(int,input().split())
arr[a-1].append([b-1,i])
arr[b-1].append([a-1,i])
que=deque([0])
ans=[0]*(n-1)
par=[0]*n
par[0]=-1
while que:
x=que.popleft()
p=par[x]
color=1
for tup in arr[x]:
if p==color:
color+=1
if ans[tup[1]]==0:
ans[tup[1]]=color
par[tup[0]]=color
color+=1
que.append(tup[0])
print(max(ans))
print(*ans,sep='\n')
|
def solve(n, k, a):
for i in range(k, n):
print("Yes" if a[i-k] < a[i] else "No")
n, k = map(int, input().split())
a = list(map(int, input().split()))
solve(n, k, a)
| 0 | null | 71,198,858,451,968 | 272 | 102 |
n = list(map(int, list(input())))
k = int(input())
dp0 = [[0]*3]*len(n)
dp1 = [[0]*3]*len(n)
dp0[0][0] = 1
dp1[0][0] = max(0, n[0]-1)
for i in range(1, len(n)):
if n[i]==0:
dp0[i] = dp0[i-1]
else:
dp0[i] = [0]+dp0[i-1][:2]
dp1[i] = [
dp1[i-1][0]+dp0[i-1][0]*(n[i]!=0)+9,
dp1[i-1][1]+dp0[i-1][1]*(n[i]!=0)+dp0[i-1][0]*max(0, n[i]-1)+dp1[i-1][0]*9,
dp1[i-1][2]+dp0[i-1][2]*(n[i]!=0)+dp0[i-1][1]*max(0, n[i]-1)+dp1[i-1][1]*9,
]
print(dp0[-1][k-1]+dp1[-1][k-1])
|
# input
N = int(input())
K = int(input())
# defnition
N_bin = str(N)
digit_len_N = len(N_bin)
DP = [[[0]*(K+2) for _ in range(2)] for _ in range(digit_len_N+1)]
# DP[i][j][k]は、上位i桁目までで、(j==0 ?Nと同じになる可能性あり:必ずNより小さくなる)の時に、0以外の数がkこ出現する、数字の数
# initialize
DP[0][0][0] = 1
# solve with けたDP
for digit in range(digit_len_N):
max_digit = int(N_bin[digit])
for smaller in range(2): # smaller=0?Nと同じになる可能性あり:Nより小さいの確定
for k in range(K+1):
cand_digits = max_digit+1 if smaller == 0 else 10 # 小さい確定なら0~9の全部が候補
for next in range(cand_digits):
if next == max_digit and smaller == 0: # Nと同じになる可能性を残しつつ
if next == 0: # 0のときは,kの値が増えないので特別扱い
DP[digit+1][0][k] += DP[digit][0][k]
else:
DP[digit+1][0][k+1] += DP[digit][0][k]
else: # ここで、Nより必ず小さい道に行く
if next == 0: # 0のときは,kの値が増えないので特別扱い
DP[digit+1][1][k] += DP[digit][smaller][k]
else:
DP[digit+1][1][k+1] += DP[digit][smaller][k]
print(DP[-1][0][K]+DP[-1][1][K])
| 1 | 75,751,105,260,358 | null | 224 | 224 |
H, W, K = map(int, input().split())
S = [input() for _ in range(H)]
# chocoのj列目の0(white)の個数を数える
def count_col_whites(choco, j):
res = 0
for c in choco:
if c[j]=="1":
res += 1
return res
# チョコレートをヨコ方向にカットする
def cut_chocolate(i):
if i == 0:
return [S]
else:
res = []
pre = 0
tmp = 0
while i > 0:
tmp += 1
if i%2 == 1:
res.append(S[pre:tmp])
pre = tmp
i //= 2
res.append(S[pre:len(S)])
return res
def is_less_than_or_equal_to_K(cut):
for c in cut:
for j in range(W):
tmp = 0
for i in range(len(c)):
if c[i][j] == "1":
tmp += 1
if tmp > K:
return False
return True
ans = 10**10
for i in range(2**(H-1)):
# 横方向にカットしたときのかたまりをcutに格納
cut = cut_chocolate(i)
tmp_ans = len(cut)-1
# 縦方向にみていって、1列中の白チョコの個数がK個より大きければそもそも無理
if not is_less_than_or_equal_to_K(cut):
continue
# 縦方向にみていって、白チョコがK個以下のかたまりになるようカットする
current_white_nums = [0 for _ in range(len(cut))]
for j in range(W):
for i in range(len(cut)):
white_num = count_col_whites(cut[i], j)
if white_num + current_white_nums[i] <= K:
current_white_nums[i] += white_num
else:
current_white_nums = [count_col_whites(cut[_], j) for _ in range(len(cut))]
tmp_ans += 1
break
ans = min(ans, tmp_ans)
print(ans)
|
import sys
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
nf = lambda: float(ns())
nfn = lambda y: [nf() for _ in range(y)]
nfa = lambda: list(map(float, stdin.readline().split()))
nfan = lambda y: [nfa() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()
h, w, k = na()
s = nsn(h)
ans = inf
for bits in range(2 ** (h - 1)):
binf = "{0:b}".format(bits)
res = sum([int(b) for b in binf])
divcnt = res + 1
cnt = [0] * divcnt
flag = True
j = 0
while j < w:
cur = 0
for i in range(h):
if (s[i][j] == '1'):
cnt[cur] += 1
if bits >> i & 1:
cur += 1
if max(cnt) > k:
if flag:
res = inf
break
res += 1
for i in range(divcnt):
cnt[i] = 0
flag = True
else:
flag = False
j += 1
ans = min(ans, res)
print(ans)
| 1 | 48,377,951,537,090 | null | 193 | 193 |
m1,_ = input().split()
m2,_ = input().split()
ans = 0
if m1 != m2:
ans = 1
print(ans)
|
def cal(a, op, b):
if op == '+':
r = a + b
elif op == '-':
r = a - b
elif op == '*':
r = a * b
else:
r = a / b
return r
while 1:
a,op,b = raw_input().split()
if op == '?':
break
else:
print(cal(int(a), op, int(b)))
| 0 | null | 62,390,989,476,126 | 264 | 47 |
def main():
N, D = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(N)]
cnt = 0
for a in A:
if (a[0]**2 + a[1]**2)**0.5 <= D:
cnt += 1
print(cnt)
if __name__ == '__main__':
main()
|
n, x, t = map(int, input().split())
print((n // x + (n % x != 0)) * t)
| 0 | null | 5,105,603,852,008 | 96 | 86 |
n=[int(i) for i in input().split()]
if sum(n)%9==0:
print("Yes")
else:
print("No")
|
a,b,c=map(int,input().split(" "))
count=0
while(a<=b):
if c%a==0:
count+=1
a+=1
print(count)
| 0 | null | 2,475,986,001,060 | 87 | 44 |
data = list(map(int, input().split()))
n = int(input())
dice = ['12431', '03520', '01540', '04510', '02530', '13421']
for i in range(n):
up, front = map(int, input().split())
u = data.index(up)
f = data.index(front)
a = dice[u].find(str(f))
print(data[int(dice[u][a+1])])
|
# -*- coding: utf-8 -*-
while True:
x, y = map(int, raw_input().split())
if x+y:
if x < y:
print "%d %d" %(x, y)
else:
print "%d %d" %(y, x)
else:
break;
| 0 | null | 379,479,543,222 | 34 | 43 |
def main():
S = input()
def an_area(S):
ans = 0
stack_in = []
stack_out = []
for i,ch in enumerate(S):
if ch == '\\':
stack_in.append(i)
elif stack_in and ch == '/':
j = stack_in.pop()
cur = i - j
stack_out.append((j,i,cur))
ans += cur
return ans,stack_out
ans, l = an_area(S)
if ans == 0:
print(ans)
print(len(l))
return
l.sort()
pre_le, pre_ri = l[0][0], l[0][1]
pre_ar = 0
areas = []
for le,ri,ar in l:
if pre_le <= ri <= pre_ri:
pre_ar += ar
else:
areas.append(pre_ar)
pre_ar = ar
pre_le, pre_ri = le, ri
else:
areas.append(pre_ar)
print(ans)
print(len(areas),*areas)
if __name__ == '__main__':
main()
|
s1 = [] #/????????????????????§??????????????????
s2 = [] #??????????°´??????????????¢??????[????????????\???????????????????°´??????????????¢???]?????¢??§????????§??????????????????
su = 0 #?????¢???
st = list(input()) #??\?????????????????????????´????????????????
for i in range(len(st)): #???????????????????????????????????£????????¢????¨????
if st[i] == '\\':
s1.append(i)
elif st[i] == '/' and len(s1) != 0:
left = s1.pop()
su += i - left
area = 0
while len(s2) != 0 and left < s2[-1][0]:
area += s2.pop()[1]
s2.append([left,area + i -left])
print(su)
print(' '.join([str(len(s2))] + [str(i[1]) for i in s2]))
| 1 | 58,314,036,102 | null | 21 | 21 |
import math
a, b, C = map(int, input().split())
print('{0:.4f}'.format(0.5*a*b*math.sin(math.radians(C))))
L = (a+b) + math.sqrt(a**2+b**2-2*a*b*math.cos(math.radians(C)))
print(L)
print('{0:.4f}'.format(math.sin(math.radians(C)) * b))
|
import math
a,b,c = [int(x) for x in input().split()]
c = math.radians(c)
s = a * b * math.sin(c) / 2
l = a + b + math.sqrt(a**2 + b**2 - 2*a*b*math.cos(c))
h = 2 * s / a
for i in [s,l,h]:
print('{:.12f}'.format(i))
| 1 | 175,134,634,388 | null | 30 | 30 |
x = input()
print(x*x*x)
|
print input() ** 3
| 1 | 288,167,915,610 | null | 35 | 35 |
import sys
def input():
return sys.stdin.readline().strip()
n, d, a = map(int, input().split())
x = []
h = {} # x:h
for _ in range(n):
i, j = map(int, input().split())
x.append(i)
h[i] = j
x.sort()
x.append(x[-1] + 2*d + 1)
# attackで累積和を用いる
ans = 0
attack = [0 for _ in range(n+1)]
for i in range(n):
attack[i] += attack[i-1]
if attack[i] >= h[x[i]]:
continue
if (h[x[i]] - attack[i]) % a == 0:
j = (h[x[i]] - attack[i]) // a
else:
j = (h[x[i]] - attack[i]) // a + 1
attack[i] += a * j
ans += j
# 二分探索で、x[y] > x[i] + 2*d、を満たす最小のyを求める
# start <= y <= stop
start = i + 1
stop = n
k = stop - start + 1
while k > 1:
if x[start + k//2 - 1] <= x[i] + 2*d:
start += k//2
else:
stop = start + k//2 - 1
k = stop - start + 1
attack[start] -= a * j
print(ans)
|
#import sys
#sys.setrecursionlimit(10**9)
H, N = map(int, input().split())
magic = [_ for _ in range(N)]
for k in range(N):
magic[k] = list(map(int, input().split()))
magic[k].append(magic[k][0]/magic[k][1])
magic.sort(key = lambda x: x[2], reverse=True)
ans = [0 for _ in range(H+1)]
visited = [0]
anskouho = [float('inf')]
ans2 = float('inf')
"""
def solve(start, power, point, maryoku):
if start == H:
print(min(point, min(anskouho)))
exit()
elif start > H:
anskouho.append(point)
return 0
elif ans[start] != 0:
return 0
else:
visited.append(start)
ans[start] = point
solve(start+power, power, point+maryoku, maryoku)
"""
for k in range(N):
for item in visited:
#solve(item+magic[k][0], magic[k][0], ans[item] + magic[k][1], magic[k][1])
start = item+magic[k][0]
power = magic[k][0]
point = ans[item]+ magic[k][1]
maryoku = magic[k][1]
for _ in range(10**5):
if start == H:
print(min(point, ans2))
exit()
elif start > H:
ans2 = min(ans2, point)
break
elif ans[start]!=0:
break
else:
visited.append(start)
ans[start] = point
start += power
point += maryoku
print(ans2)
| 0 | null | 81,756,304,407,630 | 230 | 229 |
n, k = map(int, input().split())
P = list(map(int, input().split()))
P_ac = [sum(P[:k])]
for i in range(n-k):
P_ac.append(P_ac[-1]-P[i]+P[i+k])
print((max(P_ac)+k)/2)
|
import math
#入力
x = int(input())
x_upper = (x+1) / 1.08
x_lower = x / 1.08
x_candidate = math.ceil(x_lower)
if x_lower <= x_candidate < x_upper:
print(x_candidate)
else:
print(":(")
| 0 | null | 100,356,616,143,640 | 223 | 265 |
from collections import deque
N = 100
WHITE = 0
GRAY = 1
BLACK = 2
M = [[0 for _ in range(N)] for _ in range(N)]
color = [0 for _ in range(N)]
d = [0 for _ in range(N)]
f = [0 for _ in range(N)]
nt = [0 for _ in range(N)]
tt = 0
def main():
n = int(input())
for _ in range(n):
u, k, *v_s = map(int, input().split(' '))
for j in range(k):
M[u-1][v_s[j-1]-1] = 1
dfs(n)
for i in range(n):
print('{} {} {}'.format(i+1, d[i], f[i]))
def dfs(n):
for u in range(n):
if color[u] == WHITE:
dfs_visit(n, u)
def dfs_visit(n, r):
global tt
color[r] = GRAY
tt += 1
d[r] = tt
for v in range(0, n):
if M[r][v] == 0:
continue
if color[v] == WHITE:
dfs_visit(n, v)
color[r] = BLACK
tt += 1
f[r] = tt
if __name__ == '__main__':
main()
|
from math import gcd
N = int(input())
num_lis = list(map(int, input().split()))
def osa_k(max_num):
lis = [i for i in range(max_num+1)]
p = 2
while p**2 <= max_num:
if lis[p] == p:
for q in range(2*p, max_num+1, p):
if lis[q] == q:
lis[q] = p
p += 1
return lis
hoge = 0
for i in num_lis:
hoge = gcd(hoge, i)
if hoge > 1:
print("not coprime")
exit()
d_lis = osa_k(max(num_lis))
tmp = set()
for i in num_lis:
num = i
new_tmp = set()
while num > 1:
d = d_lis[num]
new_tmp.add(d)
num //= d
for j in new_tmp:
if j in tmp:
print("setwise coprime")
exit()
else:
tmp.add(j)
print("pairwise coprime")
| 0 | null | 2,075,409,056,318 | 8 | 85 |
import math
n, m = map(int,input().split())
a = list(map(int,input().split()))
sum = sum(a)
x = 0
for i in a:
if i * 4 * m >= sum:
x += 1
if x >= m:
print('Yes')
else:
print('No')
|
N,M=map(int,input().split())
L=[list(input().split()) for i in range(M)]
W=[0]*N
A=[0]*N
a=0
w=0
for i in range(M):
if L[i][1]=="AC":
A[int(L[i][0])-1]=1
elif L[i][1]=="WA" and A[int(L[i][0])-1]==0:
W[int(L[i][0])-1]+=1
#for i in A:
#a+=i
#for i in W:
#w+=i
for i in range(N):
if A[i]>0:
a+=1
w+=W[i]
print(a,w)
| 0 | null | 66,372,149,884,280 | 179 | 240 |
n=int(input())
if n%2==1:
print("0")
exit()
count=0
for i in range(1,30):
count+=n//(2*5**i)
print(count)
|
import sys
import bisect
import itertools
import collections
import fractions
import heapq
import math
from operator import mul
from functools import reduce
from functools import lru_cache
def solve():
readline = sys.stdin.buffer.readline
mod = 10 ** 9 + 7
N = int(readline())
if N % 2 == 1:
print(0)
else:
count2 = 0
count5 = 0
compare = 1
while N >= compare * 2:
compare *= 2
count2 += N // compare
compare = 1
N //= 2
while N >= compare * 5:
compare *= 5
count5 += N // compare
ans = min(count2, count5)
print(ans)
if __name__ == '__main__':
solve()
| 1 | 115,714,648,595,068 | null | 258 | 258 |
mod = 10**9 + 7
n = int(input())
dp = [0]*(n+1)
dp[0] = 1
if n >= 3:
for i in range(3,n+1):
dp[i] = dp[i-1] + dp[i-3]
print(dp[n] % mod)
|
import sys
S = int(sys.stdin.readline())
mod = 10**9 + 7
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]
for i in range(2, 2*S+1):
fact.append((fact[-1] * i) % mod)
inv.append((-inv[mod % i] * (mod // i)) % mod)
factinv.append((factinv[-1] * inv[-1]) % mod)
def nCr(n, r, mod=10**9+7):
if (r < 0) or (n < r):
return 0
r = min(r, n - r)
return fact[n] * factinv[r] * factinv[n-r] % mod
ans = 0
n = 1
n_max = S // 3
while n <= n_max:
res = S - 3 * n
tmp = nCr(res + n - 1, n - 1)
# print(n, res, tmp)
ans += tmp
ans %= mod
n += 1
print(ans)
| 1 | 3,321,701,261,790 | null | 79 | 79 |
from sys import stdin,stdout
n,k=map(int,stdin.readline().split())
a=list(map(int,stdin.readline().split()))
for i in range(k,n):
print('Yes' if a[i]>a[i-k] else 'No')
|
import math
import collections
import fractions
import itertools
import functools
import operator
def solve():
n, k = map(int, input().split())
a = list(map(int, input().split()))
for i in range(k, n):
if a[i] > a[i-k]:
print("Yes")
else:
print("No")
return 0
if __name__ == "__main__":
solve()
| 1 | 7,155,432,043,682 | null | 102 | 102 |
num = int(input())
word = input()
for i in range(num):
print(word[i],end="")
if i+1 >= len(word):
break
if len(word) > num:
print("...")
|
import math
a, b, x = map(int, input().split())
c = x/a**2 # c : height of water
if c >= b/2:
tanth = 2*(b-c)/a
deg = math.atan(tanth)*180/math.pi
else:
tanth = b**2/(2*a*c)
deg = math.atan(tanth)*180/math.pi
print(deg)
| 0 | null | 91,400,681,878,660 | 143 | 289 |
import math
import sys
import os
from operator import mul
sys.setrecursionlimit(10**7)
def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))
if os.getenv("LOCAL"):
inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
sys.stdin = open(inputFile, "r")
INF = float("inf")
N = I()
A = LI()
A.sort(reverse=True)
# print(A)
# half = math.ceil(len(A)/2)
q, mod = divmod(len(A),2)
if mod == 0:
ans = A[0]
for i in range(1,q):
ans += 2 * A[i]
else:
ans = A[0]
for i in range(1,q):
ans += 2 * A[i]
ans += A[q]
print(ans)
|
import math
n = int(input())
values = list(map(int, input().split(' ')))
values.sort(reverse=True)
sum = 0
for i in range(1, n):
sum += values[math.floor(i/2)]
print(sum)
| 1 | 9,235,668,869,680 | null | 111 | 111 |
import sys
input = sys.stdin.readline
R, L, K = map(int, input().split())
V = [0]*(R*L)
for _ in range(K):
r, c, v = map(int, input().split())
V[(c-1)*R+(r-1)] = v
A, B, C, D = [[0]*(R+1) for _ in range(4)]
for i in range(L):
for j in range(R):
A[j] = max(A[j-1],B[j-1],C[j-1],D[j-1])
v = V[i*R+j]
if v != 0:
D[j], C[j], B[j] = max(C[j]+v,D[j]), max(B[j]+v,C[j]), max(A[j]+v,B[j])
print(max(A[-2],B[-2],C[-2],D[-2]))
|
import numpy as np
def main() -> None:
n, m, x = map(int, input().split())
books = [tuple(map(int, input().split())) for _ in range(n)]
is_able = False
answer = float('inf')
for i in range(2**n):
money = 0
skills = np.zeros(m)
for j in range(n):
if ((i >> j) & 1):
money += books[j][0]
skills += books[j][1:]
if x <= skills.min():
is_able = True
answer = min(answer, money)
print(answer if is_able else -1)
return
if __name__ == '__main__':
main()
| 0 | null | 13,961,555,714,182 | 94 | 149 |
N = int(input())
if N%1000 == 0:
print(0)
else:
print(1000-(N%1000))
|
import math
from itertools import permutations
N=int(input())
XYlist=[]
indexlist=[i for i in range(N)]
for _ in range(N):
XYlist.append(tuple(map(int,input().split())))
ans=0
num=0
for indexes in permutations(indexlist,N):
for i in range(N-1):
ans+=math.sqrt((XYlist[indexes[i]][0]-XYlist[indexes[i+1]][0])**2+
(XYlist[indexes[i]][1]-XYlist[indexes[i+1]][1])**2)
num+=1
print(ans/num)
| 0 | null | 78,437,930,390,080 | 108 | 280 |
#!/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()
|
S = input()
Q = int(input())
Query = [input() for _ in range(Q)]
inv = False
add = ['','']
for query in Query:
if query[0]=='1':
inv = not inv
else:
add[(query[2] == '1') ^ inv] += query[-1]
ans = add[1][::-1] + S + add[0]
if inv:
ans = ans[::-1]
print(ans)
| 0 | null | 109,346,870,911,808 | 288 | 204 |
a = list(input().split())
n = len(a)
s = []
for i in a:
if i=="+":
a = s.pop()
b = s.pop()
s.append(b + a)
elif i=="-":
a = s.pop()
b = s.pop()
s.append(b - a)
elif i=="*":
a = s.pop()
b = s.pop()
s.append(b * a)
else:
s.append(int(i))
print(s[0])
|
#ALDS_11_B - 深さ優先探索
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**9)#再帰回数の上限
def DFS(u, cnt):
visited.add(u)
first_contact = cnt
cnt += 1
for nb in edge[u]:
if nb not in visited:
cnt = DFS(nb, cnt)
stamp[u] = first_contact, cnt
return cnt+1
N = int(input())
edge = [[] for i in range(N)]
for _ in range(N):
tmp = list(map(int,input().split()))
if tmp[1] != 0:
edge[tmp[0]-1] = list(map(lambda x: int(x-1),tmp[2:]))
stamp = [None]*N
visited = set()
c = 1
for i in range(N):
if i not in visited:
c = DFS(i, c)
for i,s in enumerate(stamp):
print(i+1,*s)
| 0 | null | 20,585,825,888 | 18 | 8 |
n = int(input())
R = []
for i in range(n):
R.append(int(input()))
minv = R[0]
maxv = R[1] - R[0]
for r in R[1:]:
maxv = max(maxv, r - minv)
minv = min(minv, r)
print(maxv)
|
n,m,k = map(int,input().split())
import collections
par = []
for i in range(n):
par.append(i) #初期親
rank = [1 for i in range(n)] #初期ランク
flist = [[] for i in range(n)]
blist = [[] for i in range(n)]
cut = []
def find(n): #親検索andランク短縮
global cut
if par[n] == n:
for i in range(len(cut)):
par[cut[i]] = n
cut = []
return n
else:
cut.append(n)
find(par[n])
return find(par[n])
def shorten(n): # ランクを2にする
global cut
if par[n] == n:
for i in range(len(cut)):
par[cut[i]] = n
cut = []
else:
cut.append(n)
shorten(par[n])
def unite(a,b): #グループ併合
x = find(a)
y = find(b) #根っこ同士をくっつける
if x == y:
return #既に同一ユニオンなら何もしない
if rank[x] < rank[y]:
par[x] = y
elif rank[x] == rank[y]:
par[y] = x
rank[x] += 1
else:
par[y] = x
for i in range(m):
a,b = map(int,input().split())
a -= 1
b -= 1
flist[a].append(b)
flist[b].append(a)
unite(a,b)
for i in range(n):
shorten(i)
for i in range(k):
a,b = map(int,input().split())
a -= 1
b -= 1
if par[a] == par[b]:
blist[a].append(b)
blist[b].append(a)
c = collections.Counter(par)
for i in range(n):
ans = c[par[i]] -len(flist[i])-len(blist[i])-1
print(ans,end = ' ')
| 0 | null | 30,880,036,507,932 | 13 | 209 |
import queue
def main():
h, w = map(int, input().split())
st = [[1]*(w+2) for _ in range(h+2)]
for i in range(h):
s = input()
for j in range(w):
if s[j] == ".":
st[i+1][j+1] = 0
ans = 0
for i in range(1, h+2):
for j in range(1, w+2):
if st[i][j] == 0:
fs = [[float("inf")]*(w+2) for _ in range(h+2)]
q = queue.Queue()
fs[i][j] = 0
q.put([i, j])
while not q.empty():
y, x = q.get()
if st[y-1][x] == 0 and fs[y-1][x] > fs[y][x] + 1:
fs[y-1][x] = fs[y][x] + 1
q.put([y-1, x])
if st[y+1][x] == 0 and fs[y+1][x] > fs[y][x] + 1:
fs[y+1][x] = fs[y][x] + 1
q.put([y+1, x])
if st[y][x-1] == 0 and fs[y][x-1] > fs[y][x] + 1:
fs[y][x-1] = fs[y][x] + 1
q.put([y, x-1])
if st[y][x+1] == 0 and fs[y][x+1] > fs[y][x] + 1:
fs[y][x+1] = fs[y][x] + 1
q.put([y, x+1])
if ans < fs[y][x]:
ans = fs[y][x]
print(ans)
if __name__ == "__main__":
main()
|
import numpy as np
from numba import njit
import sys
sys.setrecursionlimit(10**9)
def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))
@njit(cache=True)
def pos(W,h,w):
return h*W+w
def solve(H,W,G):
N = H*W+W
INF=10**18
dp = np.full((N,N),INF)
for i in range(N):
dp[i][i] = 0
for h in range(H):
for w in range(W):
if G[h][w]: continue
for i in range(4):
dh = [0,1,0,-1][i]
dw = [1,0,-1,0][i]
if 0<=h+dh<H and 0<=w+dw<W:
if G[h+dh][w+dw]: continue
dp[pos(W,h,w)][pos(W,h+dh,w+dw)] = 1
dp[pos(W,h+dh,w+dw)][pos(W,h,w)] = 1
ans = 0
for k in range(N):
for i in range(N):
for j in range(N):
dp[i][j] = min(dp[i][j],dp[i][k]+dp[k][j])
for i in range(N):
for j in range(N):
if dp[i][j] != INF:
ans = max(ans,dp[i][j])
return ans
def main():
H,W=mi()
G = [[0] * W for _ in range(H)]
for h in range(H):
S = list(input())
for w in range(W):
G[h][w] = S[w] == "#"
print(solve(H,W,np.array(G,bool)))
def cc_export():
from numba.pycc import CC
cc = CC('my_module')
# basic types: https://numba.pydata.org/numba-doc/0.13/types.html
cc.export('pos', '(i8,i8,i8,)')(pos)
cc.export('solve', '(i8,i8,b1[:,:],)')(solve)
cc.compile()
if __name__ == '__main__':
try:
from my_module import solve
from my_module import pos
except:
cc_export()
exit()
main()
| 1 | 94,401,149,618,088 | null | 241 | 241 |
N=int(input())
d=list(map(int,input().split()))
a=0
for i in range(N):
for k in range(1,N-i):
a=a+d[i]*d[i+k]
print(a)
|
a=[]
for i in range(2):
m=input().split()
a.append(m)
list_1=[int(l) for l in a[0]]
list_2=[int(l) for l in a[1]]
total=0
largest=list_2[0]
smallest=list_2[0]
for x in range(list_1[0]):
if largest<list_2[x]:
largest=list_2[x]
if smallest>list_2[x]:
smallest=list_2[x]
for x in list_2:
total+=x
print(smallest,largest,total)
| 0 | null | 84,768,245,966,598 | 292 | 48 |
a,b=map(int,input().split())
l=list(map(int,input().split()))
for i in range(b):
a-=l[i]
print("Yes" if a<=0 else"No")
|
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7
def resolve():
h, n = map(int, input().split())
A = list(map(int, input().split()))
print("Yes" if h <= sum(A) else "No")
if __name__ == '__main__':
resolve()
| 1 | 78,126,944,219,000 | null | 226 | 226 |
num = raw_input()
num_list = raw_input().split()
num_list = map(int, num_list)
count = 0
def bubble_sort(num_list, count):
flag = True
i = 0
while flag:
flag = False
for j in range(len(num_list)-1, i, -1):
if num_list[j-1] > num_list[j]:
temp = num_list[j]
num_list[j] = num_list[j-1]
num_list[j-1] = temp
count += 1
flag = True
i += 1
return count
count = bubble_sort(num_list, count)
num_list = map(str, num_list)
print " ".join(num_list)
print count
|
def bubble_sort(A, N):
sw = 0
flag = True
while flag:
flag = False
for j in reversed(range(1, N)):
if A[j - 1] > A[j]:
A[j - 1], A[j] = A[j], A[j - 1]
sw += 1
flag = True
return sw
def main():
N = int(input().rstrip())
A = list(map(int, input().rstrip().split()))
sw = bubble_sort(A, N)
print(' '.join(map(str, A)))
print(sw)
if __name__ == '__main__':
main()
| 1 | 15,175,573,170 | null | 14 | 14 |
s, t = input().split()
a, b = map(int,input().split())
u = input()
if s == u:
print(a - 1, b)
elif t == u:
print(a, b - 1)
|
a = input().split()
b = list(map(int, input().split()))
c = input()
if a[0]==c:
print(b[0]-1, b[1])
else:
print(b[0], b[1]-1)
| 1 | 71,707,708,095,972 | null | 220 | 220 |
from math import sqrt
N=int(input())
for i in range(int(sqrt(N)),0,-1):
j = N/i
if j == int(j):
print(int(i+j-2))
break
|
h,n=map(int,input().split())
ab = [list(map(int,input().split())) for i in range(n)]
dp=[float('inf')]*(h+1)
dp[0]=0
for i in range(h):
for j in range(n):
next=i+ab[j][0] if i+ab[j][0]<=h else h
dp[next]=min(dp[next],dp[i]+ab[j][1])
print(dp[-1])
| 0 | null | 121,301,162,077,210 | 288 | 229 |
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
#import numpy as np
def main():
n = int(input())
if n == 1:
print(1)
sys.exit()
r = 0
for i1 in range(1, n + 1):
num_of_div = n // i1
r += num_of_div * (num_of_div + 1) // 2 * i1
print(r)
if __name__ == '__main__':
main()
|
def num_divisors_table(n):
table = [0] * (n + 1)
for i in range(1, n + 1):
for j in range(i, n + 1, i):
table[j] += j
return table
n=int(input())
print(sum(num_divisors_table(n)))
| 1 | 11,007,076,699,148 | null | 118 | 118 |
n = int(input())
titles = []
times = []
for i in range(n):
title,m = input().split()
titles.append(title)
times.append(int(m))
print(sum(times[titles.index(input())+1:]))
|
N = int(input())
X = []
for i in range(N):
X.append(input().split())
S = input()
flg = False
ans = 0
for x in X:
if flg:
ans += int(x[1])
if S == x[0]:
flg = True
print(ans)
| 1 | 96,667,911,487,466 | null | 243 | 243 |
# -*- coding: utf-8 -*-
N=int(input())
x,y=map(int,input().split())
R=x
L=x
U=y
B=y
P=[(x,y)]
for i in range(1,N):
x,y=map(int,input().split())
P.append((x,y))
if R<x:R=x
if L>x:L=x
if U<y:U=y
if B>y:B=y
p=P[0]
UR=p
dUR=abs(R-p[0])+abs(U-p[1])
UL=p
dUL=abs(L-p[0])+abs(U-p[1])
BR=p
dBR=abs(R-p[0])+abs(B-p[1])
BL=p
dBL=abs(L-p[0])+abs(B-p[1])
for p in P[1:]:
if dUR>abs(R-p[0])+abs(U-p[1]):
UR=p
dUR=abs(R-p[0])+abs(U-p[1])
if dUL>abs(L-p[0])+abs(U-p[1]):
UL=p
dUL=abs(L-p[0])+abs(U-p[1])
if dBR>abs(R-p[0])+abs(B-p[1]):
BR=p
dBR=abs(R-p[0])+abs(B-p[1])
if dBL>abs(L-p[0])+abs(B-p[1]):
BL=p
dBL=abs(L-p[0])+abs(B-p[1])
ans=abs(UR[0]-BL[0])+abs(UR[1]-BL[1])
ans2=abs(UL[0]-BR[0])+abs(UL[1]-BR[1])
if ans2>ans: ans=ans2
print(ans)
|
N = int(input())
L = [[int(l) for l in input().split()] for _ in range(N)]
L1 = [0]*N
L2 = [0]*N
for i in range(N):
L1[i] = L[i][0]+L[i][1]
L2[i] = L[i][0]-L[i][1]
L1.sort()
L2.sort()
print(max(L1[-1]-L1[0], L2[-1]-L2[0]))
| 1 | 3,398,037,546,570 | null | 80 | 80 |
house = [[[0 for r in range(10)] for f in range(3)] for b in range(4)]
for i in range(int(input())):
b, f, r, v = map(int, input().split())
house[b-1][f-1][r-1] += v
for b in range(4):
for f in range(3):
house[b][f] = ' ' + ' '.join(map(str, house[b][f]))
house[b] = '\n'.join(map(str, house[b])) + '\n'
border = '#' * 20 + '\n'
house = border.join(map(str, house))
print(house.rstrip())
|
data = [[[0 for r in range(10)] for f in range(3)] for b in range(4)]
count = int(input())
for c in range(count):
(b, f, r, v) = [int(x) for x in input().split()]
data[b - 1][f - 1][r - 1] += v
for b in range(4):
for f in range(3):
for r in range(10):
print('',data[b][f][r], end='')
print()
print('#' * 20) if b < 4 - 1 else print(end='')
| 1 | 1,110,457,813,532 | null | 55 | 55 |
import numpy as np
N, K = map(int, input().split())
As = np.array(sorted(map(int, input().split())))
Fs = np.array(sorted(map(int, input().split()), reverse = True))
times = As * Fs
ng = -1
ok = np.amax(times)+1
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
k = np.sum(np.maximum(np.ceil((times - mid) / Fs), 0))
if k > K:
ng = mid
else:
ok = mid
print(ok)
|
n, k = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a.sort()
f.sort(reverse = True)
cost = max([a[i] * f[i] for i in range(n)])
cost2 = 0
while True:
cost3 = (cost + cost2) // 2
count = 0
for i in range(n):
count += max((a[i] * f[i] - cost3 - 1) // f[i] + 1, 0)
if count <= k:
cost = cost3
else:
cost2 = cost3 + 1
if cost == cost2:
break
print(cost)
| 1 | 164,807,494,060,000 | null | 290 | 290 |
n = int(input())
ans = 0
if n%2 == 0:
i = 10
while i <= n:
ans += n//i
i *= 5
print(ans)
|
n=int(input())
if n%2==1:
print(0)
else:
cnt=1
ans=0
while 2*5**cnt<=n:
ans+=n//(2*5**cnt)
cnt+=1
print(ans)
| 1 | 116,110,162,639,914 | null | 258 | 258 |
S = input()
T = input()
Ns = len(S)
Nt = len(T)
ans = 0
for i in range(Ns - Nt + 1):
tmp = 0
for j in range(Nt):
if S[i + j] == T[j]:
tmp += 1
ans = max(ans, tmp)
print(Nt - ans)
|
x,y = list(input().split())
x = int(x)
y = int(y[0]+y[2]+y[3])
print(x*y//100)
| 0 | null | 10,050,813,025,498 | 82 | 135 |
a,b=map(int,input().split())
x=a%b
while x>0:
a=b
b=x
x=a%b
print(b)
|
print(7 - ['SUN','MON','TUE','WED','THU','FRI','SAT'].index(input()))
| 0 | null | 66,291,545,128,172 | 11 | 270 |
n, m = map(int, input().split())
c = list(map(int, input().split()))
dp = [[0 for _ in range(n + 1)] for _ in range(m + 1)]
for i in range(m + 1):
for j in range(n + 1):
if i == 0 and j == 0:
dp[i][j] = 0
elif i == 0:
dp[i][j] = 1000000000
elif j == 0:
dp[i][j] = 0
else:
if j - c[i - 1] >= 0:
dp[i][j] = min(dp[i - 1][j], dp[i][j - c[i - 1]] + 1)
else:
dp[i][j] = dp[i - 1][j]
ans = 10 ** 10
for i in range(m + 1):
ans = min(ans, dp[i][n])
print(ans)
|
ma = lambda :map(int,input().split())
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
x = ni()
if x>=30:
f=True
else:
f=False
yn(f)
| 0 | null | 2,939,735,318,028 | 28 | 95 |
a, b= map(int, input().split())
if a<b:print( "a < b")
if a>b:print ("a > b")
if a==b:print ("a == b")
|
a,b=input().split()
c=int(a);d=int(b)
if c>=-1000 and d<=1000:
if c>d:
print("a > b")
elif c<d:
print("a < b")
else:
print("a == b")
| 1 | 350,389,672,832 | null | 38 | 38 |
import numpy as np
import sys
from numba import njit, i4
read = sys.stdin.read
@njit((i4[:],), cache=True)
def solve(stdin):
h, w, m = stdin[:3]
row = np.zeros(h, np.int32)
col = np.zeros(w, np.int32)
for i in range(3, m * 2 + 3, 2):
y, x = stdin[i: i + 2] - 1
row[y] += 1
col[x] += 1
max_cnt_y = max(row)
max_cnt_x = max(col)
max_pair = np.sum(row == max_cnt_y) * np.sum(col == max_cnt_x)
for i in range(3, m * 2 + 3, 2):
y, x = stdin[i: i + 2] - 1
if row[y] == max_cnt_y and col[x] == max_cnt_x:
max_pair -= 1
return max_cnt_y + max_cnt_x - (max_pair == 0)
print(solve(np.fromstring(read(), dtype=np.int32, sep=' ')))
|
h,w,m=map(int,input().split())
hl=[0]*(h)
wl=[0]*(w)
bom=[]
for i in range(m):
h1,w1=map(int,input().split())
bom.append([h1-1,w1-1])
hl[h1-1]+=1
wl[w1-1]+=1
mh=max(hl)
mw=max(wl)
ans=mh+mw
mhl=set()
mwl=set()
for i in range(h):
if mh==hl[i]:
mhl.add(i)
for i in range(w):
if mw==wl[i]:
mwl.add(i)
count=len(mhl)*len(mwl)
for i in range(len(bom)):
if bom[i][0] in mhl and bom[i][1] in mwl:
count-=1
if count>0:
print(ans)
else:
print(ans-1)
| 1 | 4,790,155,937,698 | null | 89 | 89 |
while True:
a, op, b = map(str, input().split())
if op =='?':
break
a = int(a)
b = int(b)
if op =='+':
print(a+b)
elif op == '-':
print(a-b)
elif op == '*':
print(a*b)
elif op == '/':
print(a//b)
|
K = int(input())
A, B = list(map(int, input().split()))
i = 1
flag = False
while K * i <= B:
if K * i >= A:
flag = True
i += 1
if flag:
print("OK")
else:
print("NG")
| 0 | null | 13,710,055,495,588 | 47 | 158 |
a,b,c = map(int, input().split())
print("Yes") if b * c >= a else print("No")
|
D, T, S = map(int, input().split())
print("Yes" if D <= (T*S) else 'No')
| 1 | 3,590,772,047,620 | null | 81 | 81 |
if __name__ == "__main__":
t0 = int(raw_input())
h = t0 / 60 / 60
t1 = t0 - ( h * 60 * 60 )
m = t1 / 60
s = t1 - ( m * 60 )
print "{0}:{1}:{2}".format(h,m,s)
|
def solve():
X = [int(i) for i in input().split()]
for i in range(len(X)):
if X[i] == 0:
print(i+1)
break
if __name__ == "__main__":
solve()
| 0 | null | 6,928,475,828,548 | 37 | 126 |
N = int(input())
D = list(map(int,input().split()))
power = 0
for i in range(N-1):
for j in range(i+1,N):
power += D[i]*D[j]
print(power)
|
import sys
input = sys.stdin.readline
from collections import *
N = int(input())
d = list(map(int, input().split()))
ans = 0
for i in range(N):
for j in range(i+1, N):
ans += d[i]*d[j]
print(ans)
| 1 | 168,528,489,274,460 | null | 292 | 292 |
import sys
l = sys.stdin.readlines()
for i in range(len(l)-1):
print('Case {}: {}'.format(i+1,l[i].strip()))
|
x=input()
x=str.swapcase(x)
print(x)
| 0 | null | 985,391,953,560 | 42 | 61 |
def isPrime(n):
if (n == 1): return False
if (n == 2): return True
if (0 == n % 2) : return False
i = 2
while(n >= i * i):
if (0 == n % i): return False
i += 1
return True
def main():
c = 0
n = input()
for i in range(n):
if (isPrime(input())):
c += 1
print(c)
main()
|
def isPrime(n):
for i in range(2, n):
if i * i > n:
return 1
if n % i == 0:
return 0
return 1
ans = 0
n = int(input())
for i in range(n):
x = int(input())
ans = ans + isPrime(x)
print(ans)
| 1 | 9,374,947,000 | null | 12 | 12 |
time=1
n=int(input())
A=[[] for i in range(n)]
d=[0 for i in range(n)]
f=[0 for i in range(n)]
for i in range(n):
a=list(map(int,input().split()))
for j in range(a[1]):
A[i].append(a[2+j]-1)
def dfs(q,num):
global d,f,time
d[num]=time
for nx in q[num]:
if d[nx]==0:
time+=1
dfs(q,nx)
time+=1
f[num]=time
for i in range(n):
if d[i]==0:#unvisit
dfs(A,i)
time+=1
for i in range(n):
print(i+1,d[i],f[i])
|
S = list(input())
T = list(input())
s, t = len(S), len(T)
ans = s
for i in range(s-t+1):
tmp = S[i:i+t]
cnt = 0
for i, j in zip(T, tmp):
if i != j:
cnt += 1
ans = min(ans, cnt)
print(ans)
| 0 | null | 1,843,218,723,500 | 8 | 82 |
n = int(input().split()[0])
c = list(map(int,input().split()))
minimum = [ i for i in range(n+1) ]
for i in range(2,n+1):
for j in c:
if j <= i and minimum[i-j] + 1 < minimum[i]:
minimum[i] = minimum[i-j]+1
print(minimum[n])
|
N,M=list(map(int,input().split()))
C=list(map(int,input().split()))
dp=[0]+[50001 for _ in range(N)]
for i in range(M):
for j in range(C[i],N+1):
if C[i] > N:
break
elif dp[j-C[i]] != 50001:
dp[j] = min(dp[j],dp[j-C[i]] + 1)
print(dp[N])
| 1 | 141,553,682,118 | null | 28 | 28 |
n,s = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
mod = 998244353
dp = [[0 for i in range(s+1)] for j in range(n+1)]
dp[0][0] = 1
for i in range(n):
for x in range(s+1):
dp[i+1][x] = 2*dp[i][x]
if x-a[i] >= 0:
dp[i+1][x] += dp[i][x-a[i]]
dp[i+1][x] %= mod
print(dp[n][s])
|
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()
n,s = na()
a = na()
mod = 998244353
dp = [0]*(s+1)
dp[0] = 1
for i in range(n):
pd = [0]*(s+1)
for j in range(s+1):
if j+a[i] <= s:
pd[j+a[i]] += dp[j]
pd[j] += dp[j]*2%mod
dp = pd
print(dp[s]%mod)
| 1 | 17,846,397,862,462 | null | 138 | 138 |
N,K = [int(x) for x in input().split()]
P = [int(x) for x in input().split()]
sorted_P = sorted(P)
print(sum(sorted_P[:K]))
|
n,k=(int(i) for i in input().split())
a=list(map(int, input().split()))
a.sort()
sum=0
for i in range(k):
sum+=a[i]
print(sum)
| 1 | 11,684,423,972,352 | null | 120 | 120 |
from bisect import bisect_left
import numpy
def main():
def isOK(score):
count = 0
for a in reversed(A):
border_score = score - a
index = bleft(A, border_score)
count += N - index
if count >= M:
return True
return False
N, M = map(int, input().split())
A = sorted(map(int, input().split()))
ans = 0
ng = A[-1] + A[-1] + 1
ok = A[0] + A[0]
bleft = bisect_left
while(abs(ok-ng) > 1):
#print(ok, ng)
mid = (ok+ng) // 2
f = isOK(mid)
if f:
ok = mid
else:
ng = mid
#print(f)
#print(ok, ng)
C = [0,] + A
C = numpy.cumsum(C[::-1])
#print(C)
min_score = float('inf')
count = 0
for a in reversed(A):
index = bleft(A, ok-a)
if index < N:
min_score = min(a+A[index], min_score)
ans += C[N-index-1] + (N-index) * a
count += N-index
ans -= min_score * (count-M)
print(ans)
if __name__ == '__main__':
main()
|
from collections import Counter
#N, K = map(int, input().split( ))
#L = list(map(int, input().split( )))
N = int(input())
A = list(map(int, input().split( )))
Q = int(input())
Sum = sum(A)
#Counterなるものがあるらしい
coun = Counter(A)
#Q個の整数の組(B,C)が与えられてB \to Cとして合計を計算
#合計は(Ci-Bi)*(A.count(Bi))変化する.
for _ in range(Q):
b, c = map(int, input().split( ))
Sum += (c-b)*coun[b]
coun[c] += coun[b]
coun[b] = 0
print(Sum)
# replaceするとタイムエラーになるのか…
# A = [c if a == b else a for a in A]
| 0 | null | 59,927,537,919,314 | 252 | 122 |
# -*- coding: utf-8 -*-
n = int(input())
t_point, h_point = 0, 0
for i in range(n):
t_card, h_card = map(str, input().split())
if t_card == h_card:
t_point += 1
h_point += 1
elif t_card > h_card:
t_point += 3
elif t_card < h_card:
h_point += 3
print('{0} {1}'.format(t_point, h_point))
|
n,k,s = map(int, input().split())
if s < 10**9:
ans = [s+1] * n
else:
ans = [1]*n
ans[:k] = [s]*k
print(" ".join(map(str,ans)))
| 0 | null | 46,354,274,318,672 | 67 | 238 |
d = {}
for _ in range(int(input())):
d[input()] = ""
print(len(d))
|
'''
研究室PCでの解答
'''
import math
#import numpy as np
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
#setrecursionlimit(10**7)
mod = 10**9+7
dir = [(-1,0),(1,0),(0,-1),(0,1)]
alp = "abcdefghijklmnopqrstuvwxyz"
def main():
n,k = map(int,ipt().split())
a = [int(i) for i in ipt().split()]
memo = deque()
memo.append(0)
d = defaultdict(int)
ans = 0
nv = 0
d[0] += 1
for i,ai in enumerate(a):
nv += ai-1
nv %= k
memo.append(nv)
if i >= k-1:
pi = memo.popleft()
d[pi] -= 1
ans += d[nv]
d[nv] += 1
print(ans)
return None
if __name__ == '__main__':
main()
| 0 | null | 84,005,848,075,802 | 165 | 273 |
a,b,c=map(int,raw_input().split())
if a+b >= c:
print "No"
else:
ans1 = 4 * a * b;
ans2 = (c - a - b) * (c - a - b)
if ans1 < ans2:
print "Yes"
else:
print "No"
|
N = int(input())
S = [int(x) for x in input().split()]
T = int(input())
Q = [int(x) for x in input().split()]
c = set()
for s in S:
for q in Q:
if s == q:
c.add(s)
print(len(c))
| 0 | null | 25,806,123,708,158 | 197 | 22 |
n = int(input())
s = 0
for i in range(n):
x,y = map(int,input().split())
if x == y:
s += 1
if s == 3:
print("Yes")
quit()
else:
s = 0
print("No")
|
N = int(input())
zoro_count = 0
zoro = False
for n in range(N):
dn1,dn2 = map(int, input().split())
if dn1 == dn2:
zoro_count += 1
else:
zoro_count = 0
if zoro_count >= 3:
zoro = True
if zoro:
print('Yes')
else:
print('No')
| 1 | 2,517,334,413,348 | null | 72 | 72 |
# coding: utf-8
# Your code here!
num = int(input())
a=0
b=0
for _ in range(num):
input2 = input().split()
if input2[0]>input2[1]:
a=a+3
elif input2[0]<input2[1]:
b=b+3
else:
a=a+1
b=b+1
print(a,b)
|
cnt = [0 for i in range (26)]
alphabet = 'abcdefghijklmnopqrstuvwxyz'
str = open(0).read()
for x in str:
for k in range(len(alphabet)):
if x == alphabet[k] or x == alphabet[k].upper():
cnt[k] = cnt[k] + 1
break
for i in range(26):
print(alphabet[i], ':', cnt[i])
| 0 | null | 1,825,756,374,760 | 67 | 63 |
str1=input()
str2=str1.swapcase()
print(str2)
|
w=input()
print(w.swapcase())
| 1 | 1,511,828,272,252 | null | 61 | 61 |
Moji = 'ACL'
K = int(input())
Answer = (Moji * K)
print(Answer)
|
K=int(input())
for i in range(K):
print("ACL",end="")
print("")
| 1 | 2,171,555,573,760 | null | 69 | 69 |
#coding:utf-8
#1_5_B
def merge_sort(array):
if len(array) > 1:
L, countL = merge_sort(array[0:len(array)//2])
R, countR = merge_sort(array[len(array)//2:])
return merge(L, R, countL+countR)
if len(array) == 1:
return [array, 0]
def merge(L, R, count=0):
L.append(10**9+1)
R.append(10**9+1)
response = []
i = 0
j = 0
for k in range(len(L)-1 + len(R)-1):
if L[i] <= R[j]:
response.append(L[i])
i += 1
count += 1
else:
response.append(R[j])
j += 1
count += 1
return [response, count]
n = int(input())
S = list(map(int, input().split()))
numbers, count = merge_sort(S)
print(*numbers)
print(count)
|
x=int(input())
if 29>x>(-40):
print('No')
elif x>=30:
print('Yes')
elif x<-40:
print('No')
else:
print('No')
| 0 | null | 2,942,890,006,892 | 26 | 95 |
N, M = map(int, input().split(' '))
ac_set = set()
wa_cnt_list = [0] * N
ac_cnt, wa_cnt = 0, 0
for i in range(M):
num, res = input().split(' ')
num = int(num) - 1
if num not in ac_set:
if res == 'AC':
ac_cnt += 1
wa_cnt += wa_cnt_list[num]
ac_set.add(num)
else:
wa_cnt_list[num] += 1
print(ac_cnt, wa_cnt)
|
print(10-int(input())//200)
| 0 | null | 50,256,719,824,216 | 240 | 100 |
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10000000)
from collections import defaultdict
from bisect import *
mod = 10**9+7
N = int(input())
A = list(map(int, input().split()))
cnt = [0]*3
ans = 1
for i, x in enumerate(A):
T = len([c for c in cnt if c == x])
for i, c in enumerate(cnt):
if c == x:
cnt[i] += 1
break
ans = ans * T % mod
print(ans)
|
n = int(input())
a = list(map(int, input().split()))
que = [-1, -1, -1]
ans = 1
for i in range(n):
if que[0]+1 == a[i]:
if que[0] == que[1] and que[0] == que[2]:
ans *= 3
ans %= (10**9 + 7)
elif que[0] == que[1]:
ans *= 2
ans %= (10**9 + 7)
que[0] = a[i]
elif que[1]+1 == a[i]:
if que[1] == que[2]:
ans *= 2
ans %= (10**9 + 7)
que[1] = a[i]
elif que[2]+1 == a[i]:
que[2] = a[i]
else:
ans = 0
break
print(ans)
| 1 | 129,508,323,533,106 | null | 268 | 268 |
def main():
X,Y = map(int,input().split())
for x in range(101):
for y in range(101):
if x+y==X and 2*x+4*y==Y:
return True
return False
if __name__ == '__main__':
print("Yes" if main() else "No")
|
X,Y = map(int,input().split())
ans='No'
for i in range(0,X+1):
#print(i)
if i * 2 + (X - i) * 4 == Y and X>=i:
ans = 'Yes'
break
print(ans)
| 1 | 13,658,526,018,380 | null | 127 | 127 |
A = []
b = []
n, m = map(int,input().split())
for i in range(n):
A.append(list(map(int,input().split())))
for i in range(m):
b.append(int(input()))
for i in range(n):
c = 0
for s in range(m):
c += A[i][s] * b[s]
print(c)
|
s =int(list(input())[-1])
if s in [2,4,5,7,9]:print('hon')
elif s in [0,1,6,8]:print('pon')
else:print('bon')
| 0 | null | 10,188,458,961,252 | 56 | 142 |
s = input()
while s[:2] == 'hi':
s = s[2:]
if s == '': print('Yes')
else: print('No')
|
s=input()
if len(s)%2!=0:
print("No")
exit()
for i,c in enumerate(s):
if (i%2==0 and c=="h") or (i%2==1 and c=="i"):
continue
else:
print("No")
exit()
print("Yes")
| 1 | 53,191,486,744,798 | null | 199 | 199 |
from collections import deque
N = int(input())
d = {i:[] for i in range(1, N+1)}
q = deque([(1, "a")])
while q:
pos, s = q.popleft()
if pos == N+1:
break
d[pos].append(s)
size = len(set(s))
for i in range(size+1):
q.append((pos+1, s+chr(97+i)))
for i in d[N]:
print(i)
|
N=int(input())
A=["a","b","c","d","e","f","g","h","i","j"]
L=[{}for i in range(N+1)]
L[1]["a"]=1
#print(L)
for i in range(2,N+1):
for j,k in L[i-1].items():
for l in range(k+1):
L[i][j+A[l]]=max(l+1,k)
#print(L[N])
ans=L[N].keys()
ans=list(ans)
ans.sort()
for i in range(len(ans)):
print(ans[i])
| 1 | 52,330,020,756,250 | null | 198 | 198 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.