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
|
---|---|---|---|---|---|---|
H, N = map(int, input().split())
l = []
for i in range(N):
l.append(list(map(int, input().split())))
dp = [0] * 20000
for i in range(1, 20001):
dp[i] = min(dp[i-a]+b for a, b in l)
if i == H:
break
print(dp[H]) | def solve():
H, N = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(N)]
dp = [float('inf')]*(H+10**4)
dp[0] = 0
for h in range(1,H+10**4):
for i in range(N):
if A[i][0]<=h:
dp[h] = min(dp[h],dp[h-A[i][0]]+A[i][1])
ans = min(dp[H:])
return ans
print(solve()) | 1 | 81,164,078,038,312 | null | 229 | 229 |
x = int(input())
for i in range(1, 100000):
if x * i % 360 == 0:
print(i)
exit()
| # coding: utf-8
import math
import numpy as np
#N = int(input())
#A = list(map(int,input().split()))
x = int(input())
#x, y = map(int,input().split())
for i in range(1,10**5):
if (i*x)%360==0:
print(i)
break | 1 | 13,230,063,632,032 | null | 125 | 125 |
N=int(input())
A=list(map(int,input().split()))
mlt=0
for a in A:
mlt^=a
for i in range(N):
print(mlt^A[i],end=" ") | def main():
n = int(input())
l = list(map(int, input().split()))
if 0 in l:
print(0)
return
prod = 1
for i in l:
prod *= i
if prod > 1000000000000000000:
print(-1)
return
print(prod)
if __name__ == '__main__':
main() | 0 | null | 14,452,981,344,060 | 123 | 134 |
import sys
def input():
return sys.stdin.buffer.readline()[:-1]
n = int(input())
d = [list(map(int, input().split())) for _ in range(n)]
ans1 = max(x[0] + x[1] for x in d) - min(x[0] + x[1] for x in d)
ans2 = max(x[0] - x[1] for x in d) - min(x[0] - x[1] for x in d)
print(max(ans1, ans2)) | import sys
#from collections import deque
#from functools import *
#from fractions import Fraction as f
from copy import *
from bisect import *
#from heapq import *
#from math import ceil
#from itertools import permutations ,product
def eprint(*args):
print(*args, file=sys.stderr)
zz=1
#sys.setrecursionlimit(10**6)
if zz:
input=sys.stdin.readline
else:
sys.stdin=open('input.txt', 'r')
sys.stdout=open('all.txt','w')
di=[[-1,0],[1,0],[0,1],[0,-1]]
def inc(d,c,x=1):
d[c]=d[c]+x if c in d else x
def bo(i):
return ord(i)-ord('A')
def li():
return [int(xx) for xx in input().split()]
def fli():
return [float(x) for x in input().split()]
def comp(a,b):
if(a>b):
return 2
return 2 if a==b else 0
def gi():
return [xx for xx in input().split()]
def fi():
return int(input())
def pro(a):
return reduce(lambda a,b:a*b,a)
def swap(a,i,j):
a[i],a[j]=a[j],a[i]
def si():
return list(input().rstrip())
def mi():
return map(int,input().split())
def gh():
sys.stdout.flush()
def isvalid(i,j):
return 0<=i<n and 0<=j<m and a[i][j]!="."
def bo(i):
return ord(i)-ord('a')
def graph(n,m):
for i in range(m):
x,y=mi()
a[x].append(y)
a[y].append(x)
mod=10**9+7
t=1
while t>0:
t-=1
n=fi()
a=[]
b=[]
for i in range(n):
x,y=mi()
a.append(x+y)
b.append(x-y)
p=max(a)-min(a)
q=max(b)-min(b)
print(max(p,q))
| 1 | 3,417,923,415,338 | null | 80 | 80 |
nums = list(input().split())
for i, j in enumerate(nums):
if j == '0':
print(i+1) | a = input().replace(' ', '')
print(a.find('0') + 1) | 1 | 13,465,123,061,390 | null | 126 | 126 |
from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
# d = m - k[i] - k[j]
# if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
def readInts():
return list(map(int,input().split()))
def main():
a,b = readInts()
print(a - b*2 if a - b*2 >= 0 else 0)
if __name__ == '__main__':
main()
| a, b = [int(x) for x in input().split()]
temp = a - 2 * b
ans = temp if temp > 0 else 0
print(ans) | 1 | 165,923,445,053,052 | null | 291 | 291 |
from collections import defaultdict
n = int(input())
dic = defaultdict(lambda: 0)
for _ in range(n):
com = input().split(' ')
if com[0]=='insert':
dic[com[1]] = 1
else:
if com[1] in dic:
print('yes')
else:
print('no') | n = int(input())
A = {}
for i in range(n):
a, b = input().split()
if a[0] == "i":
A[b] = 1
elif a[0] == "f":
if b in A:
print("yes")
else:
print("no")
| 1 | 76,856,248,702 | null | 23 | 23 |
def main():
X = int(input())
p, r = divmod(X, 500)
q, r = divmod(r, 5)
print(p * 1000 + q * 5)
if __name__ == '__main__':
main()
| S = input()
ans = []
for i in range(len(S)+1):
if i <= 2 :
ans += S[i]
else:
print(''.join(ans))
exit()
| 0 | null | 28,932,187,466,264 | 185 | 130 |
import math
H, W = map(int, input().split(' '))
if H == 1 or W == 1:
print(1)
exit()
res = math.ceil((H*W)/2)
print(res)
| H,W=map(int,input().split())
import sys
N=1
if W==1 or H==1:
print(1)
sys.exit()
if (W-1)%2==0:
N+=(W-1)//2
N+=(W-1)//2
elif (W-1)%2==1:
N+=(W-2)//2
N+=W//2
if H%2==0:
NN=N*(H//2)
elif H%2==1:
if (W-1)%2==0:
NN=N*((H-1)//2)+(W-1)//2+1
elif (W-1)%2==1:
NN=N*((H-1)//2)+(W-2)//2+1
print(NN) | 1 | 50,826,964,755,062 | null | 196 | 196 |
n = int(input())
A = list(map(int, input().split()))
q = int(input())
m = list(map(int, input().split()))
"""
def exhaustive_search(m, i):
if i == n:
return 0
if m < 0:
return 0
if m == A[i]:
return 1
return max(exhaustive_search(m, i + 1), exhaustive_search(m - A[i], i + 1))
"""
def dp_search(m):
dp = [[1] + [0] * m for _ in range(n + 1)] # dp[i][j] i番目まででjを作れるか
for i in range(1, n+1):
for j in range(1, m+1):
if j >= A[i-1]:
dp[i][j] = max(dp[i-1][j], dp[i-1][j - A[i-1]])
else:
dp[i][j] = dp[i-1][j]
return dp[n][m]
for mi in m:
if dp_search(mi):
print("yes")
else:
print("no")
| import time
def sum_A(A, n):
dic = {}
#A_ = A
#n_ = n
def solve(i, m):
if (i, m) in dic:
return dic[(i, m)]
if m == 0:
dic[(i, m)] = True
elif i >= n:
dic[(i, m)] = False
elif solve(i+1, m):
dic[(i, m)] = True
elif solve(i+1, m-A[i]):
dic[(i, m)] = True
else:
dic[(i, m)] = False
return dic[(i, m)]
return solve
if __name__ == '__main__':
n = int(raw_input())
A = map(int, raw_input().split())
q = int(raw_input())
m = map(int, raw_input().split())
#A = sorted(A)
start = time.time()
solve = sum_A(A, n)
for m_i in m:
print "yes" if solve(0, m_i) else "no"
end = time.time()
#print end - start | 1 | 101,973,448,440 | null | 25 | 25 |
def main():
s = int(input())
if s < 3:
print(0)
else:
total = [0]*(s+1)
total[3] = 1
mod = 10**9+7
for i in range(4, s+1):
total[i] = (total[i-3] + 1) + total[i-1]
total[i] %= mod
print((total[s-3]+1)%mod)
if __name__ == "__main__":
main() | def main():
n = int(input())
MOD = int(1e9 + 7)
dp = [0 for _ in range(n + 1)]
dp[0] = 1
for i in range(3 , n+1):
dp[i] = 1
for j in range(3,i - 2):
if i - j < 3:
break
dp[i] = (dp[i] + dp[i - j])%MOD
print(dp[n])
if __name__ == "__main__":
main() | 1 | 3,295,266,968,508 | null | 79 | 79 |
# ABC 173 D
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)
ind=[(i+1)//2 for i in range(N-1)]
print(sum([A[i] for i in ind])) | import sys
input = sys.stdin.readline
#n = int(input())
#l = list(map(int, input().split()))
'''
a=[]
b=[]
for i in range():
A, B = map(int, input().split())
a.append(A)
b.append(B)'''
n=int(input())
a=list(map(int,input().split()))
a.sort()
#print(a)
ans=0
from math import floor
for i in range(1,n):
ans+=a[n-1-floor(i/2)]
#print(ans)
print(ans)
| 1 | 9,208,472,144,248 | null | 111 | 111 |
n = input()
list = []
list = map(str, raw_input().split())
list.reverse()
print " ".join(list) | H, W = list(map(int, input().split()))
S =[list(input()) for _ in range(H)]
N=H*W
INF=float('inf')
L=[[INF]*N for _ in range(N)]
for i in range(N):
h=i//W
w=i%W
# print(i,h,w)
if S[h][w]=='.':
L[i][i]=0
if w>0 and S[h][w-1]=='.':
L[i][i-1]=1
if w<W-1 and S[h][w+1]=='.':
L[i][i+1]=1
if h>0 and S[h-1][w]=='.':
L[i][i-W]=1
if h<H-1 and S[h+1][w]=='.':
L[i][i+W]=1
# print(L)
for i in range(N):
via=L[i]
if via[i]==INF:
continue
for j in range(N):
st=L[j]
if st[j]==INF:
continue
for k in range(N):
L[j][k]=min(st[i]+via[k], st[k])
# print(L)
ans=0
for i in range(N):
for j in range(N):
if L[i][j]!=INF:
ans=max(ans,L[i][j])
print(ans) | 0 | null | 47,493,124,961,498 | 53 | 241 |
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) | def main():
def find(target):
if parent[target] < 0:
return target
else:
parent[target] = find(parent[target])
return parent[target]
def is_same(x, y):
return find(x) == find(y)
def union(x, y):
root_x = find(x)
root_y = find(y)
if root_x == root_y:
return
if parent[root_x] > parent[root_y]:
root_x, root_y = root_y, root_x
parent[root_x] += parent[root_y]
parent[root_y] = root_x
# 今回これ使わないけど、どこに誰がいるのかはこれでわかる
def members(n, x):
root = find(x)
return [i for i in range(n) if find(i) == root]
def get_size(x):
return -parent[find(x)]
def get_root():
return [i for i, root in enumerate(parent) if root < 0]
n, m = map(int, input().split())
parent = [-1 for _ in range(n)]
for _ in range(m):
a, b = map(lambda x: int(x) - 1, input().split())
union(a, b)
ans = len(get_root()) - 1
print(ans)
if __name__ == '__main__':
main() | 0 | null | 6,630,754,441,280 | 118 | 70 |
INF = 1145141919810364364334
n,m = map(int,input().split())
c = list(map(int,input().split()))
dp = [INF] * (n+1)
dp[0] = 0
for i in range(m):
for j in range(n+1):
if c[i] > j:
continue
else:
dp[j] = min(dp[j] , dp[j-c[i]] + 1)
print(dp[n])
| #!/usr/bin/env python
from math import *
n, m = list(map(int, input().split()))
c = list(map(int, input().split()))
DP = [n for i in range(n + 1)]
DP[0] = 0
for cost in c:
for i in range(cost, n + 1):
DP[i] = min(DP[i], DP[i - cost] + 1)
print(DP[n])
| 1 | 144,609,000,524 | null | 28 | 28 |
import itertools
import copy
n = int(input())
P = list(map(int, input().split()))
Q = tuple(list(map(int, input().split())))
P_ = copy.copy(P)
P_.sort()
p_list = list(itertools.permutations(P_))
P = tuple(P)
a = p_list.index(P)
b = p_list.index(Q)
print(abs(a-b)) | def main():
n = int(input())
print(b(n))
def b(n: int) -> int:
m = 100
i = 0
while True:
m = m * 101 // 100
i += 1
if m >= n:
break
return i
if __name__ == '__main__':
main()
| 0 | null | 63,533,962,765,490 | 246 | 159 |
N = int(input())
L = list(map(int,input().split()))
d = {}
for i in range(N):
d[L[i]] = i + 1
for j in range(1 , N + 1):
print(d[j] , end = ' ')
| def main():
n = int(input())
for i in range(1, 11):
if n > i * 1000:
continue
print(i * 1000 - n)
return
if __name__ == '__main__':
main()
| 0 | null | 94,223,554,810,824 | 299 | 108 |
n = int(input())
for i in range(n):
li = sorted(map(int, input().split()))
if(pow(li[0], 2) + pow (li[1], 2) == pow(li[2], 2)):
print('YES')
else:
print('NO')
| # usr/bin/python
# coding: utf-8
################################################################################
# Is it a Right Triangle?
# Write a program which judges wheather given length of three side form a right triangle.
# Print "YES" if the given sides (integers) form a right triangle, "NO" if not so.
#
# Input
# Input consists of several data sets. In the first line, the number of data set,
# N is given. Then, N lines follow, each line corresponds to a data set.
# A data set consists of three integers separated by a single space.
#
# Constraints
# 1 ??? length of the side ??? 1,000
# N ??? 1,000
# Output
# For each data set, print "YES" or "NO".
#
# Sample Input
# 3
# 4 3 5
# 4 3 6
# 8 8 8
# Output for the Sample Input
# YES
# NO
# NO
#
################################################################################
if __name__ == "__main__":
num = int(input())
inputline = [""]*num
for i in range(0,num):
inputline[i] = input()
for line in inputline:
a = int(line.split(" ")[0])
b = int(line.split(" ")[1])
c = int(line.split(" ")[2])
if (a*a+b*b == c*c or b*b+c*c == a*a or c*c+a*a == b*b):
print("YES")
else:
print("NO") | 1 | 218,615,212 | null | 4 | 4 |
n=int(input())
a=list()
for i in range(n):
s,t=input().split()
a.append([s,int(t)])
x=input()
flag=False
ans=0
for i in a:
if flag:
ans+=i[1]
if i[0]==x:
flag=True
print(ans) | def show(array):
for i in range(len(array)):
if i != len(array) - 1:
print(array[i], end=' ')
else:
print(array[i])
def bubbleSort(array):
flag = True
count = 0
while flag:
flag = False
for j in sorted(range(1, len(array)), reverse=True):
if array[j] < array[j - 1]:
array[j], array[j - 1] = [array[j - 1], array[j]]
flag = True
count += 1
show(array)
return count
input()
array = [int(x) for x in input().split()]
print(bubbleSort(array))
| 0 | null | 48,590,983,568,546 | 243 | 14 |
while 1:
data = input()
if "?" in data:
break
print(eval(data.replace("/","//"))) | import sys
import bisect as bi
import math
from collections import defaultdict as dd
import heapq
input=sys.stdin.readline
##import numpy as np
#sys.setrecursionlimit(10**7)
mo=10**9+7
def cin():
return map(int,sin().split())
def ain():
return list(map(int,sin().split()))
def sin():
return input()
def inin():
return int(input())
##def power(x, y):
## if(y == 0):return 1
## temp = power(x, int(y / 2))%mo
## if (y % 2 == 0):return (temp * temp)%mo
## else:
## if(y > 0):return (x * temp * temp)%mo
## else:return ((temp * temp)//x )%mo
##
##for _ in range(inin()):
n=inin()
if(n%1000==0):
print(0)
else:
print(1000-n%1000)
##
##def msb(n):n|=n>>1;n|=n>>2;n|=n>>4;n|=n>>8;n|=n>>16;n|=n>>32;n|=n>>64;return n-(n>>1) #2 ki power
##def pref(a,n,f):
## pre=[0]*n
## if(f==0): ##from beginning
## pre[0]=a[0]
## for i in range(1,n):
## pre[i]=a[i]+pre[i-1]
## else: ##from end
## pre[-1]=a[-1]
## for i in range(n-2,-1,-1):
## pre[i]=pre[i+1]+a[i]
## return pre
##maxint=10**24
##def kadane(a,size):
## max_so_far = -maxint - 1
## max_ending_here = 0
##
## for i in range(0, size):
## max_ending_here = max_ending_here + a[i]
## if (max_so_far < max_ending_here):
## max_so_far = max_ending_here
##
## if max_ending_here < 0:
## max_ending_here = 0
## return max_so_far
| 0 | null | 4,554,830,814,688 | 47 | 108 |
n = list(map(int, input().split(' ')))
m = list(map(int, input().split(' ')))
if n[0] >= sum(m):
print(n[0] - sum(m))
else:
print(-1)
| list = []
n, m = map(int, input().split())
a = input().split()[0:m]
for num in a:
num = int(num)
list.append(num)
answer = n - sum(list)
if n < sum(list):
answer = -1
print(answer) | 1 | 32,088,175,951,490 | null | 168 | 168 |
x, y = list(map(int, input().split()))
if y > x * 4 or y < x * 2 or y % 2 == 1:
print('No')
else:
print('Yes') | X,Y=map(int,input().split())
print("Yes" if Y%2==0 and 2*X<=Y<=4*X else "No") | 1 | 13,796,184,295,648 | null | 127 | 127 |
n, x, y = map(int,input().split())
cnt = [0] * (n - 1)
for i in range(1, n):
for j in range(i + 1, n + 1):
temp1 = j - i
temp2 = abs(i - x) + abs(j - y) + 1
dis = min(temp1, temp2)
cnt[dis - 1] += 1
print(*cnt, sep='\n') | r = int(input())
n = (r*r) / 3.14
print(int(n / (1/3.14))) | 0 | null | 94,618,689,970,500 | 187 | 278 |
import numpy as np
n = int(input())
A, B = [], [] # AにはXがとりうる値の最小値、Bには最大値を入れていく
for _ in range(n):
a, b = map(int, input().split())
A.append(a if n % 2 == 1 else a * 2) # nが偶数だと、medianがとりうる値が0.5刻みになるので最初から2倍にしておく
B.append(b if n % 2 == 1 else b * 2)
a = np.median(A)
b = np.median(B)
# medianのとりうる値の最小値と最大値の間に、カウントしたいmedianが1刻みで存在する
print(int(max(a, b) - min(a, b) + 1)) | N = int(input())
t = N//2
la, lb = [], []
for _ in range(N):
A, B = map(int, input().split())
la.append(A)
lb.append(B)
la.sort()
lb.sort()
print(lb[t]-la[t]+1 if N%2 else lb[t-1]-la[t]+lb[t]-la[t-1]+1)
| 1 | 17,239,133,664,300 | null | 137 | 137 |
print("Yes") if int(input()) % 9 == 0 else print("No") | A,B = map(int,input().split())
print(max(A-B-B,0))
| 0 | null | 85,184,838,876,940 | 87 | 291 |
i=0
for i in range(1,10):
for j in range(1,10):
print(f'{i}x{j}={i*j}')
j+=1
i+=1
| numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9]
for num in numbers:
for num2 in numbers:
print('{0}x{1}={2}'.format(num, num2, num * num2))
| 1 | 2,138,500 | null | 1 | 1 |
from functools import lru_cache
@lru_cache(maxsize=None)
def Fib(n):
if n==0:
return 1
elif n==1:
return 1
else:
return Fib(n-1)+Fib(n-2)
n=int(input())
print(Fib(n))
| x=input()
if x[-1]==("s"):
print(x+"es")
elif x[-1]!=("s"):
print(x+"s") | 0 | null | 1,183,002,346,372 | 7 | 71 |
import math
a,b = map(int,input().split())
def lcm(a,b):
y = a*b / math.gcd(a,b)
return int(y)
print(lcm(a,b)) | # -*- coding: utf-8 -*-
n = int(raw_input())
num = map(int, raw_input().split())
for e in num[::-1]:
if e == num[0]:
print e
break
print e, | 0 | null | 56,911,977,257,390 | 256 | 53 |
n=int(input())
ar=3
sv=[0]*(10**6+2)
for i in range(2,len(sv)):
if not sv[i]:
sv[i]=i
for j in range(2*i,len(sv),i):
sv[j]=i
def di(x):
an=1
if sv[x]==x:
return 2
while x>1:
ct=0;cr=sv[x]
while x%cr==0:
ct+=1;x//=cr
an*=(ct+1)
return an
for i in range(4,n+1):
ar=ar+di(i-1)
if n==2:
ar=1
print(ar)
| n=int(input())
an=0
for j in range(1,n):
an+=int((n-1)/j)
print(an) | 1 | 2,632,000,344,148 | null | 73 | 73 |
a, b, k = map(int, input().split())
t_fin = max(0, a - k)
a_fin = max(0, b - (k - (a - t_fin)))
print('{} {}'.format(t_fin, a_fin))
| def solve(a,b,k):
if k <= a: return a - k, b
elif k <= a + b: return 0, b - (k - a)
else: return 0, 0
a,b,k = map(int,input().split())
ans_1, ans_2 = solve(a,b,k)
print(f"{ans_1} {ans_2}") | 1 | 104,396,954,707,980 | null | 249 | 249 |
[print(y) for y in sorted([int(input()) for x in range(10)], reverse=True)[:3]] | import sys
mount_list = map(int, sys.stdin.readlines())
mount_list.sort(reverse=True)
for x in mount_list[:3]:
print x | 1 | 24,034,812 | null | 2 | 2 |
while True:
H, W = map(int, input().split())
if not(H or W):
break
print(('#' * W + '\n') * H) | n=int(input())
a=[int(i) for i in input().split()]
sum=0
for i in range(0,len(a)-1):
for j in range(i+1,len(a)):
sum=sum+(a[i]*a[j])
print(sum) | 0 | null | 84,825,973,836,800 | 49 | 292 |
mount = []
for i in range(0, 10):
n = input()
mount.append(n)
mount.sort(reverse = True)
for i in range(0, 3):
print mount[i] | import sys
import math
MAX_INT = int(10e15)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()
T1, T2 = IL()
a1, a2 = IL()
b1, b2 = IL()
if a1*T1 + a2*T2 > b1*T1 + b2*T2:
pass
else:
a1,a2,b1,b2 = b1,b2,a1,a2
if a1*T1 + a2*T2 == b1*T1 + b2*T2:
print("infinity")
elif a1*T1 >= b1*T1:
print(0)
else:
half = b1*T1 - a1*T1
x = (a1*T1 + a2*T2 - (b1*T1 + b2*T2))
# half/x >= n
loop = half//x + 1
if (loop - 1)*x == half:
print(loop*2 -2)
else:
print(loop*2 -1) | 0 | null | 65,665,453,235,158 | 2 | 269 |
# -*- coding:utf-8 -*-
import sys
data = []
count = 0
for i in sys.stdin:
data.append(int(i))
count = count+1
if count == 10:
break
N = len(data)
m = 100
for i in range(m):
for n in range(N-1):
a = data[n]
b = data[n+1]
if a <= b:
data[n] = b
data[n+1] = a
else:
pass
for i in range(3):
print(data[i]) | a = []
for i in range(10) :
a.append(int(input()))
a.sort()
a.reverse()
print("%d\n%d\n%d" % (a[0], a[1], a[2])) | 1 | 20,798,426 | null | 2 | 2 |
a,b=(int(x) for x in input().split())
print(a*b) | data = input().split(' ')
print(int(data[0]) * int(data[1]))
| 1 | 15,846,905,509,120 | null | 133 | 133 |
n=int(input())
T,H=0,0
for i in range(n):
t_card,h_card=input().split()
if t_card>h_card:
T+=3
elif t_card<h_card:
H+=3
else:
T+=1
H+=1
print(str(T)+" "+str(H)) | # https://atcoder.jp/contests/abc166/tasks/abc166_e
"""
変数分離すれば互いに独立なので、
連想配列でO(N)になる。
"""
import sys
input = sys.stdin.readline
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
P = (j+1-A[j] for j in range(N))
M = (i+1+A[i] for i in range(N))
dic = Counter(P)
res = 0
for m in M:
res += dic.get(m,0)
print(res) | 0 | null | 14,110,442,667,552 | 67 | 157 |
N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
for i in range(N-2):
for j in range(i,N-1):
for k in range(j,N):
if L[i] + L[j] > L[k] and L[i]!=L[j] and L[j]!=L[k]:
ans += 1
print(ans)
| n = int(input())
arr = list(map(int, input().split()))
ans = 0
for i in range(n):
for j in range(i + 1, n):
for k in range(j + 1, n):
if arr[i] != arr[j] and arr[i] != arr[k] and arr[j] != arr[k]:
if (arr[i] + arr[j]) > arr[k] and (arr[i] + arr[k]) > arr[j] and (arr[j] + arr[k]) > arr[i]:
ans += 1
print(ans)
| 1 | 5,018,213,591,268 | null | 91 | 91 |
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
price_list = []
for i in range(M):
x, y, c = map(int, input().split())
price = a[x-1] + b[y-1] - c
price_list.append(price)
a.sort()
b.sort()
price_list.append(a[0]+b[0])
min_price = price_list[0]
for n in price_list:
if min_price >= n:
min_price = n
elif min_price < n:
pass
print(min_price) | from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
from fractions import gcd
import bisect
#
# d = m - k[i] - k[j]
# if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
def readInts():
return list(map(int,input().split()))
def main():
a,b,m = readInts()
A = readInts()
B = readInts()
ans = float('inf')
for i in range(m):
x,y,c = readInts()
x -=1
y -=1
ans = min(ans,A[x] + B[y] - c)
# Aの商品の中で1番最小のやつを買うだけでもいいかもしれない
# Bの商品の中で1番最小のやつを買うだけでもいいかもしれない
ans = min(ans,min(A) + min(B))
print(ans)
if __name__ == '__main__':
main()
| 1 | 54,016,688,448,732 | null | 200 | 200 |
from enum import IntEnum
class Direction(IntEnum):
NORTH = 0
EAST = 1
SOUTH = 2
WEST = 3
class Dice:
"""Dice class implements the structure of a dice
having six faces.
"""
def __init__(self, v1, v2, v3, v4, v5, v6):
self.top = 1
self.heading = Direction.NORTH
self.values = [v1, v2, v3, v4, v5, v6]
def to_dice_axis(self, d):
return (d - self.heading) % 4
def to_plain_axis(self, d):
return (self.heading + d) % 4
def roll(self, d):
faces = [[(2, Direction.NORTH), (6, Direction.NORTH),
(6, Direction.WEST), (6, Direction.EAST),
(6, Direction.SOUTH), (5, Direction.SOUTH)],
[(4, Direction.EAST), (4, Direction.NORTH),
(2, Direction.NORTH), (5, Direction.NORTH),
(3, Direction.NORTH), (4, Direction.WEST)],
[(5, Direction.SOUTH), (1, Direction.NORTH),
(1, Direction.EAST), (1, Direction.WEST),
(1, Direction.SOUTH), (2, Direction.NORTH)],
[(3, Direction.WEST), (3, Direction.NORTH),
(5, Direction.NORTH), (2, Direction.NORTH),
(4, Direction.NORTH), (3, Direction.EAST)]]
f, nd = faces[self.to_dice_axis(d)][self.top-1]
self.top = f
self.heading = self.to_plain_axis(nd)
def value(self):
return self.values[self.top-1]
def run():
values = [int(v) for v in input().split()]
dice = Dice(*values)
for d in input():
if d == 'N':
dice.roll(Direction.NORTH)
if d == 'E':
dice.roll(Direction.EAST)
if d == 'S':
dice.roll(Direction.SOUTH)
if d == 'W':
dice.roll(Direction.WEST)
print(dice.value())
if __name__ == '__main__':
run()
| dice = list(map(int, input().split()))
directions = input()
for direction in directions:
if direction == 'N':
dice = [dice[1], dice[5], dice[2], dice[3], dice[0], dice[4]]
elif direction == 'S':
dice = [dice[4], dice[0], dice[2], dice[3], dice[5], dice[1]]
elif direction == 'W':
dice = [dice[2], dice[1], dice[5], dice[0], dice[4], dice[3]]
else:
dice = [dice[3], dice[1], dice[0], dice[5], dice[4], dice[2]]
print(dice[0])
| 1 | 232,248,262,860 | null | 33 | 33 |
import math
a, b, c, d = map(int, input().split())
if math.ceil(c / b) <= math.ceil(a / d):
print('Yes')
else:
print('No') | import sys
n = int( sys.stdin.readline() )
s = [ False ] * 13
h = [ False ] * 13
c = [ False ] * 13
d = [ False ] * 13
for i in range( 0, n ):
pattern, num = sys.stdin.readline().split( " " )
if "S" == pattern:
s[ int( num )-1 ] = True
elif "H" == pattern:
h[ int( num )-1 ] = True
elif "C" == pattern:
c[ int( num )-1 ] = True
elif "D" == pattern:
d[ int( num )-1 ] = True
for i in range( 0, 13 ):
if not s[i]:
print( "S {:d}".format( i+1 ) )
for i in range( 0, 13 ):
if not h[i]:
print( "H {:d}".format( i+1 ) )
for i in range( 0, 13 ):
if not c[i]:
print( "C {:d}".format( i+1 ) )
for i in range( 0, 13 ):
if not d[i]:
print( "D {:d}".format( i+1 ) ) | 0 | null | 15,292,271,428,964 | 164 | 54 |
#ABC161-A
x,y,z=map(int,input().split())
print(z,x,y)
| n = int(input())
X = list(map(int, input().split()))
Y = list(map(int, input().split()))
C = [abs(X[i] - Y[i]) for i in range(n)]
D = []
def distance(X, Y):
for k in range(1, 4):
d = 0
for j in range(len(X)):
d += C[j] ** k
d = d ** (1 / k)
D.append(d)
D.append(max(C))
return D
distance(X, Y)
for i in range(4):
print('{:.08f}'.format(D[i]))
| 0 | null | 19,130,206,879,228 | 178 | 32 |
N, M, X = list(map(int, input().split()))
C = [list() for _ in range(N)]
for i in range(N):
C[i] = list(map(int, input().split()))
INF = 10**9 + 7
minpr = INF
for i in range(2**N):
buy = list()
for j in range(N):
if i&1==1: buy.append(j)
i >>= 1
skill = [0]*M
price = 0
for k in range(len(buy)):
price += C[buy[k]][0]
for l in range(M):
skill[l] += C[buy[k]][l+1]
for m in range(M):
if skill[m] < X: break
else:
if minpr > price: minpr = price
if minpr==INF:
print(-1)
else:
print(minpr)
| n = int(input())
if n % 2 == 0:
print("{:.10f}".format((n/2)/n))
else:
print("{:.10f}".format((n//2+1)/n))
| 0 | null | 99,633,147,948,470 | 149 | 297 |
a, b = map(int, input().split())
if a > b:
print('safe')
else:
print('unsafe') | def resolve():
s, w = map(int, input().split())
if s <= w:
print("unsafe")
else:
print("safe")
resolve()
| 1 | 29,423,056,460,132 | null | 163 | 163 |
import sys
num = map(int, raw_input().split())
if num[0] < num[1]:
if num[1] < num[2]:
print "Yes"
else:
print "No"
else:
print "No" | a,b = map(int, input().split())
print(f'{a//b} {a%b} {(a/b):.6f}')
| 0 | null | 486,515,346,020 | 39 | 45 |
N=int(input())
count=0
#N未満の値がaで割り切れさえすればいい
for a in range(1,N):
count = count + (N-1)//a
print(count) | import math
def makelist(n, m):
return [[0 for _ in range(m)] for _ in range(n)]
N, M = list(map(int, input().split()))
a = list(map(int, input().split()))
# 最小公倍数
# ユークリッドの互除法
def lcm(a, b):
def gcd(a, b): # a >= b
if b == 0:
return a
else:
return gcd(b, a % b)
return a * b // gcd(a, b)
c = 1
for e in a:
c = lcm(c, e // 2)
hoge = [ (c // (e // 2)) % 2 == 1 for e in a ]
if all(hoge):
ans = 0
if c <= M:
ans += 1
M -= c
ans += M // (c * 2)
print(ans)
else:
print(0)
| 0 | null | 52,427,203,068,770 | 73 | 247 |
n = int(input())
left = []
mid = []
midminus = []
right = []
L = []
R = []
for i in range(n):
s = input()
l = 0
r = 0
for x in s:
if x == '(':
l += 1
else:
if l > 0:
l -= 1
else:
r += 1
if l > 0 and r == 0:
left.append((l, r))
elif l > 0 and r > 0:
if l > r:
mid.append((r, l)) # a,b-a
else:
midminus.append((r,l))
elif l == 0 and r > 0:
right.append((l, r))
L.append(l)
R.append(r)
if sum(L) != sum(R):
print('No')
exit()
A = 0
B = 0
for x in left:
A += x[0]
for x in right:
B += x[1]
mid = sorted(mid, key=lambda x: (x[0],-x[1]))
midminus = sorted(midminus,key= lambda x:x[0]-x[1])
mid += midminus
l = A
r = 0
for a, b in mid:
if l < a:
print('No')
exit()
l -= a
l += b
print('Yes') | input()
s = set(map(int,input().split()))
n = int(input())
t = tuple(map(int,input().split()))
c = 0
for i in range(n):
if t[i] in s:
c += 1
print(c) | 0 | null | 11,756,242,748,160 | 152 | 22 |
S = input()
week = ['SUN','MON','TUE','WED','THU','FRI','SAT']
day = [7, 6, 5, 4, 3, 2, 1]
ans = week.index(S)
print(day[ans])
| import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()
def resolve():
S = SS()
d = ('SUN' ,'MON' ,'TUE' ,'WED' ,'THU' ,'FRI' ,'SAT')
ans = 7 - d.index(S)
print(ans)
if __name__ == '__main__':
resolve()
| 1 | 132,747,250,784,018 | null | 270 | 270 |
N=int(input())
arr=[list(map(int,input().split())) for i in range(N)]
za,wa=-10**10,-10**10
zi,wi=10**10,10**10
for i in range(N):
z=arr[i][0]+arr[i][1]
w=arr[i][0]-arr[i][1]
za=max(z,za)
zi=min(z,zi)
wa=max(w,wa)
wi=min(w,wi)
print(max(za-zi,wa-wi)) | n=int(input())
a= [list(map(int, input().split())) for i in range(n)]
a1=float('inf')
a2=-float('inf')
a3=float('inf')
a4=-float('inf')
for i in range(n):
cnt=a[i][0]+a[i][1]
cnt1=a[i][0]-a[i][1]
a1=min(a1,cnt)
a2=max(a2,cnt)
a3=min(cnt1,a3)
a4=max(cnt1,a4)
print(max(a2-a1,a4-a3)) | 1 | 3,460,755,661,012 | null | 80 | 80 |
s = input()
iters = len(s) // 2
count=0
for i in range(iters):
if s[i] != s[-(i+1)]:
count+=1
print(count) | S = input()
N = len(S)
count = 0
n = N//2
for i in range(n):
if S[i] != S[N-1-i]:
count +=1
print(count) | 1 | 119,709,016,336,338 | null | 261 | 261 |
import os
import sys
from collections import defaultdict, Counter
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush,heapify
from math import ceil, floor, sqrt
from copy import deepcopy
def main():
n = int(input())
ans = 0
for i in range(1,n):
ans += (n-1)//i
print(ans)
if __name__ == "__main__":
main() | 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 = set()
ans = 0
for i in range(K) :
for j in range(len(A[i])) :
a.add(A[i][j])
for i in range(1,N+1):
if i not in a :
ans += 1
print(ans) | 0 | null | 13,708,746,627,820 | 73 | 154 |
x,y=map(int,input().split())
a=(4*x-y)/2
b=(2*x-y)/(-2)
if a>=0 and b>=0 and a.is_integer() and b.is_integer():
print("Yes")
else:
print("No") | xy = [int(s) for s in input().split()]
x = xy[0]
y = xy[1]
if y % 2 == 0 and y<=4*x and y>=2*x:
print('Yes')
else:
print('No') | 1 | 13,800,502,006,188 | null | 127 | 127 |
import sys
input = sys.stdin.readline
def main():
N, M, X = map(int, input().split())
ca = [list(map(int, input().split())) for _ in range(N)]
ans = sys.maxsize
for mask in range(2 ** N):
C = 0
A = [0] * N
for i in range(N):
if ((mask >> i) & 1):
C += ca[i][0]
A = [a + c for a, c in zip(A, ca[i][1:])]
if all([i >= X for i in A]):
ans = min(ans, C)
if ans != sys.maxsize:
print(ans)
else:
print("-1")
main() | import itertools
n,m,x = (int(i) for i in input().split())
A = []
for i in range(n):
A.append([int(i) for i in input().split()])
ans = float('inf')
for p in itertools.product(range(2), repeat=n):
knowledges = [0 for _ in range(m)]
tmp = 0
for i,a in zip(p,A):
if i == 0: continue
tmp += a[0]
for j,anm in enumerate(a[1:]): knowledges[j] += anm
if all([a >= x for a in knowledges]):
ans = min(ans, tmp)
if ans == float('inf'):
print(-1)
else:
print(ans)
| 1 | 22,249,556,531,540 | null | 149 | 149 |
k=int(input());s=input();print(s[:k]+"..." if len(s)>k else s) | k = int(input())
s = input()
if len(s) <= k:
print(s)
else:
print("{}...".format(s[0:k]))
| 1 | 19,678,143,749,792 | null | 143 | 143 |
import sys
import math # noqa
import bisect # noqa
import queue # noqa
def input():
return sys.stdin.readline().rstrip()
def main():
N = int(input())
que = queue.Queue()
que.put(('a', ord('a')))
while not que.empty():
res, m = que.get()
if len(res) < N:
for i in range(ord('a'), min(ord('z'), m + 1) + 1):
que.put((res + chr(i), max(m, i)))
elif len(res) == N:
print(res)
else:
break
if __name__ == '__main__':
main()
| N=int(input())
if N==1:
print("a")
exit()
from collections import deque
from collections import Counter
abc="abcdefghijklmnopqrstuvwxyz"
ans=["a"]
for i in range(1,N):
d=deque(ans)
ans=[]
while d:
temp=d.popleft()
temp2=list(temp)
cnt=Counter(temp2)
L=len(cnt)
for j in range(L+1):
ans.append(temp+abc[j])
for a in ans:
print(a)
| 1 | 52,245,560,227,902 | null | 198 | 198 |
k=int(input())
k+=1
o=''
a='ACL'
if k==1:
print('')
exit()
else:
for i in range(1,k):
o=o+a
print(o) | x=list(map(int,input().split()))
for i in range(len(x)):
if x[i]==0:
su=i+1
print(su) | 0 | null | 7,872,033,767,026 | 69 | 126 |
X = int(input())
total = 100
count = 0
while total < X:
total += total//100
count += 1
print(count)
| from math import floor
from decimal import Decimal
x = int(input())
amount = 100
count = 0
while amount < x:
amount += floor(Decimal(amount) / Decimal(100))
count += 1
print(count) | 1 | 27,131,449,728,580 | null | 159 | 159 |
import sys
input = sys.stdin.readline
n, m = [int(x) for x in input().split()]
s = input().rstrip()[::-1]
ans = []
left, right = 0, 0 + m
while True:
if right >= n:
ans.append(n - left)
break
for i in range(right, left, -1):
flag = 1
if s[i] == "0":
ans.append(i - left)
flag = 0
break
if flag:
print(-1)
sys.exit()
else:
left = i
right = left + m
print(*ans[::-1])
| import copy
H,W,K=map(int,input().split())
S=[]
for _ in range(H):
S.append([int(x) for x in list(input())])
ans=(H-1)+(W-1)
for i in range(2**(H-1)):
check=[0]*H
for j in range(H-1):
if ((i>>j)&1):
check[j+1]=check[j]+1
else:
check[j+1]=check[j]
g=check[H-1]+1
A=[0]*g
c=0
f=0
for j in range(W):
B=[0]*g
for k in range(H):
if S[k][j]==1:
B[check[k]]+=1
if B[check[k]]>K:
c=10**4
f=1
break
if f:
break
#print("AB",A,B)
for l in range(g):
if B[l]==0:
continue
elif A[l]+B[l]>K:
c+=1
A=copy.copy(B)
break
else:
A[l]+=B[l]
ans=min(ans,c+g-1)
print(ans)
| 0 | null | 94,019,627,609,112 | 274 | 193 |
print(len(str(input())) * 'x') | s=list(input())
n=len(s)
ans=['x']*n
print(''.join(ans)) | 1 | 73,024,062,766,300 | null | 221 | 221 |
s = raw_input().rstrip().split(" ")
W = int(s[0])
H = int(s[1])
x = int(s[2])
y = int(s[3])
r = int(s[4])
if (x-r)>=0 and (x+r)<=W and (y-r)>=0 and (y+r)<=H:print "Yes"
else:print "No" | W,H,x,y,r = list(map(int,input().split()))
print("No" if x<r or x+r>W or y<r or y+r>H else "Yes")
| 1 | 441,794,871,570 | null | 41 | 41 |
S, T = [input() for x in range(2)]
lenT = len(T)
max_match_len = 0
for i in range(len(S)-lenT+1):
compareS = S[i:i+lenT]
match_len = 0
for j in range(lenT):
if compareS[j] == T[j]:
match_len += 1
else:
if max_match_len < match_len:
max_match_len = match_len
print(lenT - max_match_len)
| s = input()
t = input()
ans = 1e+9
for si in range(len(s)):
if si + len(t) > len(s):
continue
cnt = 0
for ti in range(len(t)):
if s[si+ti] != t[ti]:
cnt += 1
ans = min(ans, cnt)
print(ans) | 1 | 3,676,537,228,000 | null | 82 | 82 |
a, b, c = map(int, input().split())
d = c - a - b
if d > 0 and d ** 2 > 4 * a * b:
print('Yes')
else:
print('No') | import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")
s = input()
if s[-1]=="s":
s += "es"
else:
s += "s"
print(s) | 0 | null | 27,012,551,833,888 | 197 | 71 |
print('Yes' if sum(map(int, input()))%9 == 0 else 'No')
| N,K,C=list(map(int,input().split()))
S=input()
R=[]
L=[]
i=0
while i<N:
if S[i]=="o":
R.append(i)
i+=C+1
else:
i+=1
i=N-1
while i>=0:
if S[i]=="o":
L.append(i)
i-=(C+1)
else:
i-=1
R=R[:K+1]
L=L[:K+1]
L.reverse()
for i in range(K):
if R[i]==L[i]:
print(str(R[i]+1),end=" ")
| 0 | null | 22,405,391,439,332 | 87 | 182 |
N, K = [int(x) for x in input().split()]
R, S, P = [int(x) for x in input().split()]
T = input()
point = {'r':P, 's':R, 'p':S}
win = [False] * N
total = 0
for i in range(N):
if i < K or T[i] != T[i - K] or win[i - K] == False:
total += point[T[i]]
win[i] = True
print(total) | x = input().split()
W, H, x, y, r = int(x[0]), int(x[1]), int(x[2]), int(x[3]), int(x[4])
if r <= x and r <= y and x + r <= W and y + r <= H:
print('Yes')
else:
print('No')
| 0 | null | 53,619,535,239,688 | 251 | 41 |
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import collections
def process(commands):
queue = collections.deque()
for c in commands:
if "insert" in c:
queue.appendleft(int(c[7:]))
elif "deleteFirst" in c:
try:
_ = queue.popleft()
except IndexError as e:
pass
elif "deleteLast" in c:
try:
_ = queue.pop()
except IndexError as e:
pass
elif "delete" in c:
try:
queue.remove(int(c[7:]))
except ValueError as e:
pass
print(" ".join(list(map(str, queue))))
def main():
n = int(input())
process([input() for i in range(n)])
if __name__ == "__main__":
main() | def mod_pow(a, n):
res = 1
while n > 0:
if n & 1:
res = res * a % mod
a = a * a % mod
n >>= 1
return res
n = int(input())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7
cnt = [0] * 60
for v in a:
for i in range(60):
if (v >> i) & 1:
cnt[i] += 1
pow_2 = [1]
for i in range(60):
pow_2.append(pow_2[-1] * 2 % mod)
res = 0
for v in a:
for i in range(60):
if (v >> i) & 1:
res = (res + (n - cnt[i]) * pow_2[i] % mod) % mod
else:
res = (res + cnt[i] * pow_2[i] % mod) % mod
print(res * mod_pow(2, mod - 2) % mod) | 0 | null | 61,486,959,695,370 | 20 | 263 |
# -*- coding: utf-8 -*-
sen = ''
while True:
try:
buf = raw_input()
except:
break
sen += buf.lower()
for i in range(ord('a'), ord('z')+1):
print "%s : %d" %(chr(i), sen.count(chr(i))) | N = int(input())
array = list(map(int, input().split()))
cnt = 0
for i in range(N):
minij = i
for j in range(i, N):
if array[j] < array[minij]:
minij = j
if minij != i:
array[i], array[minij] = array[minij], array[i]
cnt += 1
print(' '.join(map(str, array)))
print( "%d" % (cnt))
| 0 | null | 859,725,626,490 | 63 | 15 |
N=int(input())
Alist=list(map(int,input().split()))
ans=0
for i in range(N):
if Alist[i]%2==0:
if Alist[i]%3!=0 and Alist[i]%5!=0:
ans=1
break
print("APPROVED"*(1+(-1)*ans)+"DENIED"*ans) | n = int(input())
lst = list(map(int, input().split()))
a = list()
count = 0
for i in range(n):
if lst[i] % 2 == 0:
a.append(lst[i])
for i in range(len(a)):
if a[i] % 3 == 0 or a[i] % 5 == 0:
count += 1
if count == len(a):
print("APPROVED")
else:
print("DENIED") | 1 | 69,164,781,362,280 | null | 217 | 217 |
n, k = map(int, input().split())
mod = 10**9+7
def power(a, n, mod):
bi=str(format(n,"b")) #2進数
res=1
for i in range(len(bi)):
res=(res*res) %mod
if bi[i]=="1":
res=(res*a) %mod
return res
D = [0]*(k+1)
ans = 0
for i in reversed(range(1, k+1)):
a = k//i
d = power(a, n, mod)
j = 1
while i*j <= k:
d -= D[i*j]
j += 1
D[i] = d
ans += (d*i)%mod
print(ans%mod) | n, k = map(int, input().split())
P = [int(x) for x in input().split()]
p_e = list()
exp = 0
for p in P:
# 期待値
# 累積和
exp += (1+p)/2
p_e.append(exp)
# この後差を取るので
# n==kの時とそうでない時でやり方を分けないとだめ
if n == k:
print(p_e[-1])
else:
# 初期値
maxv = p_e[k-1] - 0
for i in range(1, n-k):
# 隣接するk個の期待値の和
p_sum = p_e[k+i] - p_e[i]
maxv = max(maxv, p_sum)
print(maxv) | 0 | null | 55,948,980,971,520 | 176 | 223 |
def main():
n = int(input())
pt = []
for _ in range(n):
x,y = map(int,input().split())
pt.append([x,y])
a,b,c = [],[],[]
for p in pt:
a.append(p[0]+p[1])
b.append(p[0]-p[1])
c.append(p[1]-p[0])
ans = 0
if max(a)-min(a)>ans:
ans = max(a)-min(a)
if max(b)-min(b)>ans:
ans = max(b)-min(b)
if max(c)-min(c)>ans:
ans = max(c)-min(c)
print(ans)
if __name__ == "__main__":
main() | n = int(input())
xy = []
for _ in range(n):
xy.append(list(map(int, input().split())))
tmp1 = []
tmp2 = []
for i in range(n):
tmp1.append([xy[i][0]+xy[i][1], xy[i][0], xy[i][1]])
tmp2.append([xy[i][0]-xy[i][1], xy[i][0], xy[i][1]])
tmp1.sort()
tmp2.sort()
ans = 0
if (tmp1[-1][2]-tmp1[0][2])*(tmp1[-1][1]-tmp1[0][1]) >= 0:
tmp = tmp1[-1][0]-tmp1[0][0]
ans = max(tmp, ans)
if (tmp2[-1][2]-tmp2[0][2])*(tmp2[-1][1]-tmp2[0][1]) <= 0:
tmp = tmp2[-1][0]-tmp2[0][0]
ans = max(tmp, ans)
print(ans)
| 1 | 3,425,128,216,440 | null | 80 | 80 |
k=int(input())
a,b=map(int,input().split(' '))
flag=0
for i in range(a,b+1):
if i%k==0:
flag=1
if flag==1:
print('OK')
else:
print('NG')
| k=int(input())
a,b=map(int,input().split())
flag=0
for i in range(1001):
if a<=k*i<=b:
print("OK")
flag+=1
break
if flag==0:
print("NG") | 1 | 26,365,471,411,702 | null | 158 | 158 |
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
s = S()
k = I()
same = len(set(list(s)))==1
ans = None
if same:
ans = len(s)*k//2
else:
if s[0]!=s[-1]:
cnt = 0
change = False
for i in range(1,len(s)):
if s[i] == s[i-1] and not change:
cnt += 1
change = True
else:
change = False
ans = cnt*k
else:
char = s[0]
start = len(s)
goal = -1
cnt = 0
while s[start-1] == char:
start -= 1
while s[goal+1] == char:
goal += 1
lenth = len(s)-start + goal+1
cnt += lenth//2 * (k-1)
ccnt = 0
change = False
for i in range(goal+1+1,start):
if s[i] == s[i-1] and not change:
ccnt += 1
change = True
else:
change = False
cnt += ccnt * (k-2)
ccnt = 0
change = False
for i in range(1,start):
if s[i] == s[i-1] and not change:
ccnt += 1
change = True
else:
change = False
cnt += ccnt
ccnt = 0
change = False
for i in range(goal+1+1, len(s)):
if s[i] == s[i-1] and not change:
ccnt += 1
change = True
else:
change = False
cnt += ccnt
ans = cnt
print(ans)
main()
| s = input()
k = int(input())
from itertools import groupby
n=len(s)
cnt =0
gp = groupby(s)
Keys=[]
values=[]
for key,value in gp:
Keys.append(key)
values.append(len(list(value)))
if len(Keys)==1:
print(values[0]*k//2)
exit(0)
if k==1:
for i in values:
cnt+=i//2
print(cnt)
exit(0)
if k>=2:
if Keys[0]==Keys[-1]:
values2=list(reversed(values))
m=len(values)
for i in range(m-1):
if values[i]>=2:
cnt+=values[i]//2
if values2[i]>=2:
cnt+=values2[i]//2
cnt+= (k-1) * ((values[0]+values[-1])//2)
for j in range(m):
if j==0 or j==m-1:
continue
else:
cnt+= (k-2)*(values[j]//2)
print(cnt)
exit(0)
for i in values:
if i>1:
cnt += k*(i//2)
print(cnt)
| 1 | 175,217,024,504,148 | null | 296 | 296 |
from random import randint
import sys
input = sys.stdin.readline
INF = 9223372036854775808
def calc_score(D, C, S, T):
"""
開催日程Tを受け取ってそこまでのスコアを返す
コンテストi 0-indexed
d 0-indexed
"""
score = 0
last = [0]*26 # コンテストiを前回開催した日
for d, t in enumerate(T):
last[t] = d + 1
for i in range(26):
score -= (d + 1 - last[i]) * C[i]
score += S[d][t]
return score
def update_score(D, C, S, T, score, ct, ci):
"""
ct日目のコンテストをコンテストciに変更する
スコアを差分更新する
ct: change t 変更日 0-indexed
ci: change i 変更コンテスト 0-indexed
"""
new_score = score
last = [0]*26 # コンテストiを前回開催した日
prei = T[ct] # 変更前に開催する予定だったコンテストi
for d, t in enumerate(T, start=1):
last[t] = d
new_score += (d - last[prei])*C[prei]
new_score += (d - last[ci])*C[ci]
last = [0]*26
for d, t in enumerate(T, start=1):
if d-1 == ct:
last[ci] = d
else:
last[t] = d
new_score -= (d - last[prei])*C[prei]
new_score -= (d - last[ci])*C[ci]
new_score -= S[ct][prei]
new_score += S[ct][ci]
return new_score
def evaluate(D, C, S, T, k):
"""
d日目終了時点での満足度を計算し,
d + k日目終了時点での満足度の減少も考慮する
"""
score = 0
last = [0]*26
for d, t in enumerate(T):
last[t] = d + 1
for i in range(26):
score -= (d + 1 - last[i]) * C[i]
score += S[d][t]
for d in range(len(T), min(len(T) + k, D)):
for i in range(26):
score -= (d + 1 - last[i]) * C[i]
return score
def greedy(D, C, S):
Ts = []
for k in range(5, 13):
T = [] # 0-indexed
max_score = -INF
for d in range(D):
# d+k日目終了時点で満足度が一番高くなるようなコンテストiを開催する
max_score = -INF
best_i = 0
for i in range(26):
T.append(i)
score = evaluate(D, C, S, T, k)
if max_score < score:
max_score = score
best_i = i
T.pop()
T.append(best_i)
Ts.append((max_score, T))
return max(Ts, key=lambda pair: pair[0])
def local_search(D, C, S, score, T):
# ct 日目のコンテストをciに変更
for k in range(50000):
ct = randint(0, D-1)
ci = randint(0, 25)
ori = T[ct]
new_score = update_score(D, C, S, T, score, ct, ci)
T[ct] = ci
if score < new_score:
score = new_score
else:
T[ct] = ori
return T
if __name__ == '__main__':
D = int(input())
C = [int(i) for i in input().split()]
S = [[int(i) for i in input().split()] for j in range(D)]
init_score, T = greedy(D, C, S)
T = local_search(D, C, S, init_score, T)
for t in T:
print(t+1)
| from random import randint, random
from math import exp
import sys
input = sys.stdin.readline
INF = 9223372036854775808
def calc_score(D, C, S, T):
"""
開催日程Tを受け取ってそこまでのスコアを返す
コンテストi 0-indexed
d 0-indexed
"""
score = 0
last = [0]*26 # コンテストiを前回開催した日
for d, t in enumerate(T):
last[t] = d + 1
for i in range(26):
score -= (d + 1 - last[i]) * C[i]
score += S[d][t]
return score
def update_score(D, C, S, T, score, ct, ci):
"""
ct日目のコンテストをコンテストciに変更する
スコアを差分更新する
ct: change t 変更日 0-indexed
ci: change i 変更コンテスト 0-indexed
"""
new_score = score
last = [0]*26 # コンテストiを前回開催した日
prei = T[ct] # 変更前に開催する予定だったコンテストi
for d, t in enumerate(T, start=1):
last[t] = d
new_score += (d - last[prei])*C[prei]
new_score += (d - last[ci])*C[ci]
last = [0]*26
for d, t in enumerate(T, start=1):
if d-1 == ct:
last[ci] = d
else:
last[t] = d
new_score -= (d - last[prei])*C[prei]
new_score -= (d - last[ci])*C[ci]
new_score -= S[ct][prei]
new_score += S[ct][ci]
return new_score
def evaluate(D, C, S, T, k):
"""
d日目終了時点での満足度を計算し,
d + k日目終了時点での満足度の減少も考慮する
"""
score = 0
last = [0]*26
for d, t in enumerate(T):
last[t] = d + 1
for i in range(26):
score -= (d + 1 - last[i]) * C[i]
score += S[d][t]
for d in range(len(T), min(len(T) + k, D)):
for i in range(26):
score -= (d + 1 - last[i]) * C[i]
return score
def greedy(D, C, S):
Ts = []
for k in range(7, 10):
T = [] # 0-indexed
max_score = -INF
for d in range(D):
# d+k日目終了時点で満足度が一番高くなるようなコンテストiを開催する
max_score = -INF
best_i = 0
for i in range(26):
T.append(i)
score = evaluate(D, C, S, T, k)
if max_score < score:
max_score = score
best_i = i
T.pop()
T.append(best_i)
Ts.append((max_score, T))
return max(Ts, key=lambda pair: pair[0])
def local_search(D, C, S, score, T):
T0 = 2e3
T1 = 6e2
Temp = T0
for k in range(500, 95000):
if k % 100:
t = (k/95000) / 1.9
Temp = pow(T0, 1-t) * pow(T1, t)
sel = randint(1, 2)
if sel == 1:
# ct 日目のコンテストをciに変更
ct = randint(0, D-1)
ci = randint(0, 25)
new_score = update_score(D, C, S, T, score, ct, ci)
lim = random()
if score < new_score or \
(new_score > 0 and exp((score - new_score)/Temp) > lim):
T[ct] = ci
score = new_score
else:
# ct1 日目と ct2 日目のコンテストをswap
ct1 = randint(0, D-1)
ct2 = randint(0, D-1)
ci1 = T[ct1]
ci2 = T[ct2]
new_score = update_score(D, C, S, T, score, ct1, ci2)
new_score = update_score(D, C, S, T, new_score, ct2, ci1)
lim = random()
if score < \
(new_score > 0 and exp((score - new_score)/Temp) > lim):
score = new_score
T[ct1] = ci2
T[ct2] = ci1
return T
if __name__ == '__main__':
D = int(input())
C = [int(i) for i in input().split()]
S = [[int(i) for i in input().split()] for j in range(D)]
init_score, T = greedy(D, C, S)
T = local_search(D, C, S, init_score, T)
for t in T:
print(t+1)
| 1 | 9,672,604,861,734 | null | 113 | 113 |
# coding: utf-8
string = raw_input()
new_string = ""
for s in string:
if s.islower():
new_string += s.upper()
elif s.isupper():
new_string += s.lower()
else:
new_string += s
print new_string | var=input()
print(var.swapcase())
| 1 | 1,494,785,975,100 | null | 61 | 61 |
while True:
try:
(h,w)=map(int,raw_input().split())
if h==0 and w==0: break
for i in xrange(h):
print ''.join(['#' for j in xrange(w)])
print
except EOFError: break | week = ['MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT', 'SUN']
S = input()
print(6 - week.index(S)) if week.index(S) != 6 else print(7) | 0 | null | 66,620,304,874,238 | 49 | 270 |
import sys
import time
import math
import itertools as it
def inpl():
return list(map(int, input().split()))
st = time.perf_counter()
# ------------------------------
A, B = map(int, input().split())
print(int(A*B))
# ------------------------------
ed = time.perf_counter()
print('time:', ed-st, file=sys.stderr)
| if __name__ == "__main__":
a,b = map(int, input().split(" "))
print(a*b) | 1 | 15,847,082,421,184 | null | 133 | 133 |
N = int(input())
S = input()
if S == S[:N//2]*2:
print("Yes")
else:
print("No") | N = int(input())
q = input()
a = list(q)
if N % 2 == 1:
print('No')
elif N % 2 == 0:
b = [a] * int(N/2)
c = [a] * int(N/2)
for i in range(int(N/2)):
b[i] = a[i]
for j in range(int(N/2)):
c[j] = a[int(j)+int(N/2)]
if b == c:
print('Yes')
else:
print('No') | 1 | 146,936,248,097,320 | null | 279 | 279 |
N = int(input())
A = list(map(int,input().split()))
cnt = 0
for i in range(N):
minj = i
for j in range(i+1,N):
if A[j] < A[minj]:
minj = j
if i != minj:
A[i],A[minj] = A[minj],A[i]
cnt += 1
print(*A)
print(cnt)
| N = int(input())
A = list(map(int, input().split()))
count = 0
for i in range(N):
mini = i
for j in range(i, N):
if A[j] < A[mini]:
mini = j
if i != mini:
A[i], A[mini] = A[mini], A[i]
count += 1
print(*A)
print(count) | 1 | 20,683,368,288 | null | 15 | 15 |
D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for i in range(D)]
t = [0]*D
for i in range(D):
t[i] =int(input())
m=[0]*D
last_day=[0]*26
a=[[0 for i in range(26)] for j in range(D)]
for u in range(D):
i=t[u]
for y in range(u,D):
a[y][i-1]=u+1
if u==0:
m[u]=s[u][i-1]
else:
m[u]=m[u-1]+s[u][i-1]
mm=[0]*D
for d in range(D):
for i in range(26):
mm[d]+=c[i]*(d+1-a[d][i])
if not d==0:
mm[d]+=mm[d-1]
for d in range(D):
m[d]-=mm[d]
print(m[d]) | import math
N, K=map(int, input().split())
A=list(map(int, input().split()))
F=list(map(int, input().split()))
A=sorted(A, reverse=False)
F=sorted(F, reverse=True)
a=-1
b=max([A[i]*F[-i-1] for i in range(N)])
while b-a>1:
tmp=(a+b)//2
c=sum([max(0, math.ceil(A[i]-tmp/F[i])) for i in range(N)])
if c<=K:
b=tmp
else:
a=tmp
print(b) | 0 | null | 87,639,725,673,318 | 114 | 290 |
T=input()
ans=""
if T=="?":
print("D")
exit()
for i in range(len(T)):
if T[i]=="P" or T[i]=="D":
ans+=T[i]
else:
if i==0:
if T[i+1]=="P":
ans+="D"
elif T[i+1]=="D":
ans+="P"
elif T[i+1]=="?":
ans+="P"
elif i!=len(T)-1:
if ans[-1]=="P" and T[i+1]=="P":
ans+="D"
elif ans[-1]=="P" and T[i+1]=="D":
ans+="D"
elif ans[-1]=="P" and T[i+1]=="?":
ans+="D"
elif ans[-1]=="D" and T[i+1]=="P":
ans+="D"
elif ans[-1]=="D" and T[i+1]=="D":
ans+="P"
elif ans[-1]=="D" and T[i+1]=="?":
ans+="P"
else:
if ans[-1]=="P":
ans+="D"
else:
ans+="D"
print(ans) | import copy
D = int( input() )
c = list( map( int, input().split() ) )
s = []
for _ in range( D ):
s_i = list( map( int, input().split() ) )
s.append( s_i )
t = []
for _ in range( D ):
t_i = int( input() )
t.append( t_i - 1 )
last = []
last_i = [ -1 for _ in range( 26 ) ]
for i in range( D ):
last_i[ t[ i ] ] = i
last.append( copy.deepcopy( last_i ) )
# def satisfy( D, c, s, t, last, d ):
satisfy = [ 0 for _ in range( D ) ]
for d in range( D ):
satisfy[ d ] += s[ d ][ t[ d ] ]
for i in range( 26 ):
satisfy[ d ] -= c[ i ] * ( d - last[ d ][ i ] )
v = 0
for v_i in satisfy:
v += v_i
print( v )
| 0 | null | 14,271,258,721,398 | 140 | 114 |
# encoding:utf-8
import math as ma
# math.pi
x = float(input())
pi = (x * x) * ma.pi
# Circumference
pi_line = (x + x) * ma.pi
print("{0} {1}".format(pi,pi_line)) | h,w = map(int,input().split())
a = h*w
if h ==1 or w ==1:
print(1)
elif a%2 == 1:
print(round(a//2+1))
else:
print(round(a/2)) | 0 | null | 25,723,794,369,520 | 46 | 196 |
N,K = map(int,input().split())
log_ls = list(map(int,input().split()))
Max = max(log_ls)
def less_k(min_length,log_ls = log_ls,K=K):
times = 0
for log in log_ls:
if log % min_length == 0:
times += log // min_length -1
else:
times += log // min_length
if times <= K:
return True
else:
return False
#print(less_k(5,[10,10],2))
def return_min_length():
r = Max
l = -1
while True:
next_length = (r+l) // 2
if next_length == 0 or not less_k(next_length):
l = next_length
else:
r = next_length
if r - l == 1:
return r
ans = return_min_length()
print(ans)
| def main():
n, k = map(int, input().split())
arr = list(map(int, input().split()))
L, R = 0, max(arr)
while L+1 < R:
P = (L+R+1)//2
cnt = 0
for a in arr:
if P < a:
if a % P == 0:
cnt += a//P - 1
else:
cnt += a//P
if cnt <= k:
R = P
else:
L = P
print(R)
if __name__ == "__main__":
main()
| 1 | 6,540,278,155,268 | null | 99 | 99 |
# -*- coding: utf-8 -*-
import math
s = list(input())
q = int(input())
for i in range(q):
n = list(input().split())
if 'print' in n:
for j in range(int(n[1]), int(n[2]) + 1):
print(str(s[j]), end='')
print()
elif 'reverse' in n:
for k in range(math.floor((int(n[2]) - int(n[1]) + 1) / 2)):
s[int(n[1]) + k], s[int(n[2]) - k] = s[int(n[2]) - k], s[int(n[1]) + k]
elif 'replace' in n:
for l in range(int(n[1]), int(n[2]) + 1):
s.pop(int(n[1]))
count = int(n[1])
for m in list(n[3]):
s.insert(count, m)
count += 1
| a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())
yes = True
if v <= w:
yes = False
elif abs(b - a) / (v - w) > t:
yes = False
if yes:
print("YES")
else:
print("NO") | 0 | null | 8,628,741,264,800 | 68 | 131 |
n=int(input())
l=[['a1']]+[[] for _ in range(9)]
for i in range(9):
for b in l[i]:
t=b[-1]
for p in range(int(t)):
l[i+1].append(b[:-1]+chr(97+p)+t)
l[i+1].append(b[:-1]+chr(97+int(t))+str(int(t)+1))
for i in l[n-1]:
if len(i)==12:
print(i[:-2])
else:
print(i[:-1]) | import sys
sys.setrecursionlimit(10**7)
readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))
n = readint()
ans = [[[0],[0]]]
i = 0
while len(ans[i][0])<n:
a = ans[i]
for x in a[1]:
ans.append([a[0]+[x],a[1]])
x = a[1][-1]+1
ans.append([a[0]+[x],a[1] + [x]])
i+=1
a_ = ord('a')
for i in range(len(ans)):
a = ans[i][0]
if len(a)<n:
continue
for x in a[:-1]:
print(chr(x+a_),end='')
print(chr(a[-1]+a_))
| 1 | 52,391,047,750,862 | null | 198 | 198 |
N = int(input())
s = list(input())
cnt = 0
for i in range(N-2):
if s[i] == 'A':
if s[i+1] == 'B':
if s[i+2] == 'C':
cnt += 1
print(cnt) | A, B, M = map(int,input().split())
A = [a for a in map(int,input().split())]
B = [b for b in map(int,input().split())]
C = []
for m in range(M):
C.append([c for c in map(int,input().split())])
ans = min(A) + min(B)
for c in C:
if (A[c[0]-1]+B[c[1]-1]-c[2])<ans:
ans = A[c[0]-1]+B[c[1]-1]-c[2]
print(ans) | 0 | null | 76,726,806,287,840 | 245 | 200 |
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)) | import math
while True:
a = int(input())
if a == 0:
break
b = list(map(float, input().split()))
m = sum(b)/a
s = 0
for i in range(int(a)):
s += (b[i]-m)**2
s = s / (int(a))
s = math.sqrt(s)
print(s) | 1 | 197,201,484,418 | null | 31 | 31 |
import sys
k1 = [[0 for i in xrange(10)] for j in xrange(3)]
k2 = [[0 for i in xrange(10)] for j in xrange(3)]
k3 = [[0 for i in xrange(10)] for j in xrange(3)]
k4 = [[0 for i in xrange(10)] for j in xrange(3)]
n = input()
for i in xrange(n):
m = map(int,raw_input().split())
if m[0] == 1:
k1[m[1]-1][m[2]-1] = k1[m[1]-1][m[2]-1] + m[3]
elif m[0] == 2:
k2[m[1]-1][m[2]-1] = k2[m[1]-1][m[2]-1] + m[3]
elif m[0] == 3:
k3[m[1]-1][m[2]-1] = k3[m[1]-1][m[2]-1] + m[3]
elif m[0] == 4:
k4[m[1]-1][m[2]-1] = k4[m[1]-1][m[2]-1] + m[3]
for i in xrange(3):
for j in xrange(10):
x = ' ' + str(k1[i][j])
sys.stdout.write(x)
if j == 9:
print ""
print"#"*20
for i in xrange(3):
for j in xrange(10):
y = ' ' + str(k2[i][j])
sys.stdout.write(y)
if j == 9:
print ""
print"#"*20
for i in xrange(3):
for j in xrange(10):
z = ' ' + str(k3[i][j])
sys.stdout.write(z)
if j == 9:
print ""
print"#"*20
for i in xrange(3):
for j in xrange(10):
zz = ' ' + str(k4[i][j])
sys.stdout.write(zz)
if j == 9:
print "" | from collections import defaultdict,Counter
h,w,m = map(int,input().split())
w_list = []
h_list = []
se = set()
for _ in range(m):
nh,nw = map(int,input().split())
se.add((nh,nw))
w_list.append(nw)
h_list.append(nh)
w_count = Counter(w_list)
h_count = Counter(h_list)
max_w = 0
max_h = 0
ch = []
cw = []
for i in w_count.values():
max_w = max(max_w,i)
cw.append(i)
for i in h_count.values():
max_h = max(max_h,i)
ch.append(i)
ma = ch.count(max_h)*cw.count(max_w)
result = max_h+max_w
point = 0
for i,j in se:
if w_count[j] == max_w and h_count[i] == max_h:
point += 1
if point == ma:
print(result-1)
else:
print(result) | 0 | null | 2,944,365,147,550 | 55 | 89 |
import sys
s=0
N=int(input())
if N%2==1:
print(0)
sys.exit()
N=N//2
while True:
N=N//5
s+=N
if N==0:
break
print(s) | class Combination:
def __init__(self, mod, max_n):
self.MOD = mod
self.MAX_N = max_n
self.f = self.factorial(self.MAX_N)
self.f_inv = [self.inv(x) for x in self.f]
def inv(self,x):
return pow(x, self.MOD-2, self.MOD)
def factorial(self, n):
res = [1]
for i in range(1,n+1):
res.append(res[-1] * i % self.MOD)
return res
def comb(self, n, r):
return (self.f[n] * self.f_inv[r] % self.MOD) * self.f_inv[n-r] % self.MOD
X, Y = map(int,input().split())
k, l = (2*Y-X)//3, (2*X-Y)//3
if (X + Y) % 3 != 0 or k < 0 or l < 0:
print(0)
exit()
CB = Combination(10**9+7, k+l)
print(CB.comb(k+l,k)) | 0 | null | 133,321,201,925,410 | 258 | 281 |
# coding: utf-8
# ?????????????????¨????????????
class Dice(object):
def __init__(self):
# ????????¶???
self.dice = (2, 5), (3, 4), (1, 6) # x, y, z
self.ax = [[0, False], [1, False], [2, False]]
self.axmap = [0, 1, 2]
self.mm = {"N": (0, 2), "S": (2, 0), "E": (1, 2), "W": (2, 1), "R": (0, 1), "L": (1, 0)}
def rotate(self, dir):
def rot(k, r):
t = self.axmap[r]
self.axmap[k], self.axmap[r] = t, self.axmap[k]
self.ax[t][1] = not self.ax[t][1]
rot(*self.mm[dir])
def front(self): return self.value(0, True)
def rear(self): return self.value(0, False)
def right(self): return self.value(1, True)
def left(self): return self.value(1, False)
def top(self): return self.value(2, True)
def bottom(self): return self.value(2, False)
def value(self, ax, d):
a = self.ax[self.axmap[ax]]
return self.dice[a[0]][a[1] if d else not a[1]]
if __name__=="__main__":
dice = Dice()
labels = input().split()
q = int(input())
def tf(p, f, d):
for _ in range(4):
if p==f(): break
dice.rotate(d)
for _ in range(q):
a, b = input().split()
p = labels.index(a) + 1
f = dice.top
tf(p, f, "N")
tf(p, f, "E")
p = labels.index(b) + 1
f = dice.front
tf(p, f, "R")
print(labels[dice.right()-1]) | s = list(map(int, input().split()))
q = int(input())
# 上面をnとして時計回りにサイコロを回したときの正面のindexの一覧[a_1,a_2,a_3,a_4]
# 正面がa_nのとき右面はa_n+1
dm = {0: [1, 2, 4, 3, 1],
1: [0, 3, 5, 2, 0],
2: [0, 1, 5, 4, 0],
3: [0, 4, 5, 1, 0],
4: [0, 2, 5, 3, 0],
5: [1, 3, 4, 2, 1]}
for i in range(q):
t, f = map(lambda x: s.index(int(x)), input().split())
print(s[dm[t][dm[t].index(f)+1]])
| 1 | 258,729,319,240 | null | 34 | 34 |
n = int(input())
x = 100000
for i in range(n):
x = int(x * 1.05)
if(x % 1000 != 0):
x = x/1000 + 1
x = x * 1000
print x | # 解説AC
import sys
input = sys.stdin.buffer.readline
n = int(input())
A = list(map(int, input().split()))
B = []
for i, e in enumerate(A):
B.append((e, i + 1))
B.sort(reverse=True)
# dp[i][j]: Aiまで入れた時、左にj個決めた時の最大値
dp = [[-1] * (n + 1) for _ in range(n + 1)]
dp[0][0] = 0
for i in range(n):
for j in range(i + 1): # 左の個数
k = i - j # 右の個数
ni = i + 1
val, idx = B[i]
dp[ni][j] = max(dp[ni][j], dp[i][j] + abs(n - k - idx) * val)
dp[ni][j + 1] = max(dp[ni][j + 1], dp[i][j] + abs(idx - (j + 1)) * val)
ans = 0
for i in range(n + 1):
ans = max(ans, dp[n][i])
print(ans)
| 0 | null | 16,844,810,069,608 | 6 | 171 |
d1=[0 for i in range(6)]
d1[:]=(int(x) for x in input().split())
t1=[0 for i in range(6)]
order=input()
for i in range(len(order)):
if order[i]=='N':
t1[0]=d1[1]
t1[1]=d1[5]
t1[2]=d1[2]
t1[3]=d1[3]
t1[4]=d1[0]
t1[5]=d1[4]
if order[i]=='S':
t1[0]=d1[4]
t1[1]=d1[0]
t1[2]=d1[2]
t1[3]=d1[3]
t1[4]=d1[5]
t1[5]=d1[1]
if order[i]=='E':
t1[0]=d1[3]
t1[1]=d1[1]
t1[2]=d1[0]
t1[3]=d1[5]
t1[4]=d1[4]
t1[5]=d1[2]
if order[i]=='W':
t1[0]=d1[2]
t1[1]=d1[1]
t1[2]=d1[5]
t1[3]=d1[0]
t1[4]=d1[4]
t1[5]=d1[3]
d1=list(t1)
print(d1[0])
| n = int(input())
strList = []
timeList = []
for x in range(n):
s, t = map(str, input().split())
strList.append(s)
timeList.append(int(t))
x = input()
id = strList.index(x)
if timeList.count == id: print(0)
else: print(sum(timeList[id + 1:])) | 0 | null | 48,604,891,937,938 | 33 | 243 |
import re
n = int(input())
s = input()
a = []
ans = 0
for i in range(n):
if s[i] == 'A':
a.append(i)
for i in a:
if s[i:i+3] == 'ABC':
ans += 1
print(ans) | n = int(input())
s = input()
ans = 0
for i in range(n-2):
if s[i] == 'A':
if s[i+1] == 'B':
if s[i+2] == 'C':
ans += 1
print(ans)
| 1 | 99,214,042,812,718 | null | 245 | 245 |
N, K, S = map(int, input().split())
ans = [None] * N
for i in range(N):
if i < K:
ans[i] = S
else:
if S + 1 <= 1000000000:
ans[i] = S + 1
else:
ans[i] = 1
print(' '.join(map(str, ans))) | from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
# d = m - k[i] - k[j]
# if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
def readInts():
return list(map(int,input().split()))
def main():
n,k,s = readInts()
ans = []
for i in range(k):
ans.append(s)
for i in range(k,n):
if s >= 100:
ans.append(s-1)
else:
ans.append(s+1)
print(*ans)
if __name__ == '__main__':
main()
| 1 | 90,830,624,872,172 | null | 238 | 238 |
def BubbleSort(C,N):
for i in range(N):
for j in range(i+1, N)[::-1]:
if int(C[j][1]) < int(C[j - 1][1]):
C[j],C[j-1] = C[j-1],C[j]
def SelectionSort(C,N):
for i in range(N):
minj = i
for j in range(i,N):
if int(C[j][1]) < int(C[minj][1]):
minj = j
C[i],C[minj] = C[minj],C[i]
N = int(input())
C = (input()).split()
ORG = C[:]
BubbleSort(C,N)
print (" ".join(C))
print ("Stable")
C2=ORG
SelectionSort(C2,N)
print(" ".join(C2))
if C == C2:
print ("Stable")
else:
print ("Not stable") | n, k = map(int, input().split())
a = [int(x) for x in input().split()]
for i in range(n-k):
if a[i+k] > a[i]:
print("Yes")
else:
print("No") | 0 | null | 3,519,413,313,000 | 16 | 102 |
s = input()
n = len(s)+1
ls = [0]*n
rs = [0]*n
for i in range(n-1):
if s[i] == "<":
ls[i+1] = ls[i]+1
for i in range(n-1):
if s[-1-i] == ">":
rs[-2-i] = rs[-1-i]+1
ans = 0
for i,j in zip(ls,rs):
ans += max(i,j)
print(ans) | s=input()
ans=0
up=0
down=0
if(s[0]=='>'):
down+=1
else:
up+=1
for i in range(1,len(s)):
if(s[i]=='>'):
down+=1
else:
if(s[i-1]=='>'):
high=max(up,down)
low=min(up,down)
ans+=(high+1)*(0+high)//2
low-=1
ans+=(low+1)*(0+low)//2
up=1
down=0
else:
up+=1
else:
high=max(up,down)
low=min(up,down)
ans+=(high+1)*(0+high)//2
low-=1
ans+=(low+1)*(0+low)//2
print(ans) | 1 | 156,196,633,709,942 | null | 285 | 285 |
import itertools
import functools
import math
from collections import Counter
from itertools import combinations
import re
N,K=map(int,input().split())
cnt = 1
while True:
if cnt > 10000:
break
if N // K**cnt == 0:
print(cnt)
exit()
cnt += 1
| N, K = map(int,input().split())
def abc(n,m):
a,b = divmod(n,m)
return a,b
count = 0
a = 1
while a !=0 :
a,b = abc(N,K)
N = a
count += 1
print(count) | 1 | 64,655,240,168,288 | null | 212 | 212 |
import sys
H, N = map(int, input().split())
data = [int(i) for i in input().split()]
DATA = sorted(data, reverse=True)
count = 0
for i in range(N):
H = H - DATA[i]
if H <= 0:
print("Yes")
sys.exit()
else:
print("No") | n = int(input())
s = list(map(int, input().strip().split(' ')))
t = n // 2
for i in range(0, n // 2):
s[i], s[n - i - 1] = s[n - i - 1], s[i]
for i in range(0, len(s)):
if i != len(s) - 1:
print(s[i], end=" ")
else:
print(s[i])
| 0 | null | 39,496,468,976,120 | 226 | 53 |
n,k=map(int,input().split())
r,s,p = map(int,input().split())
T=list(input())
a=[[] for i in range(k)]
for i in range(n):
a[i%k].append(T[i])
score=0
for j in range(k):
b=a[j]
flg=0
for l in range(len(b)):
if l==0:
if b[l]=='r':
score+=p
elif b[l]=='s':
score+=r
elif b[l]=='p':
score+=s
else:
if b[l-1]==b[l] and flg==0:
flg=1
continue
elif b[l-1]==b[l] and flg==1:
if b[l]=='r':
score+=p
elif b[l]=='s':
score+=r
elif b[l]=='p':
score+=s
flg=0
elif b[l-1]!=b[l]:
if b[l]=='r':
score+=p
elif b[l]=='s':
score+=r
elif b[l]=='p':
score+=s
flg=0
print(score)
| n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=list(input())
rsp={"r":p,"s":r,"p":s}
sumt=0
chk=[1]*n
for i in range(len(t)):
sumt+=rsp[t[i]]
if i>=k and t[i]==t[i-k]:
chk[i]=chk[i-k]+1
chk[i-k]=1
ans=sumt
for i in range(len(chk)):
if chk[i]!=1:
chg=chk[i]//2
ans-=(rsp[t[i]])*chg
print(ans) | 1 | 106,569,513,475,840 | null | 251 | 251 |
numberOfArray=int(input())
arrayList=list(map(int,input().split()))
def bubbleSort():
frag=1
count=0
while frag:
frag=0
for i in range(1,numberOfArray):
if arrayList[i-1]>arrayList[i]:
arrayList[i-1],arrayList[i]=arrayList[i],arrayList[i-1]
frag=1
count+=1
arrayForReturn=str(arrayList[0])
for i2 in range(1,numberOfArray):
arrayForReturn+=" "+str(arrayList[i2])
print(arrayForReturn)
print(count)
#------------------main--------------
bubbleSort()
| n = int(input())
x = n%10
a = [0,1,6,8]
if x == 3:
print('bon')
elif x in a:
print('pon')
else:
print('hon') | 0 | null | 9,714,366,289,152 | 14 | 142 |
N = int(input())
ans = 0
cnt = 1
while N > 0:
if N == 1:
ans += cnt
break
N //= 2
ans += cnt
cnt *= 2
print(ans)
| n,k = map(int,input().split())
h = list(map(int,input().split()))
m = sorted(h,reverse=True)
if n <= k:
print(0)
exit()
q = sum(m[k:n])
print(q) | 0 | null | 79,510,080,321,822 | 228 | 227 |
import sys
for index, line in enumerate(sys.stdin):
value = int(line.strip())
if value == 0:
break
print("Case {0}: {1}".format(index+1, value)) | count = 1
while True:
x = int(input())
if x == 0:
break
print('Case %d: %d' % (count, x))
count += 1
| 1 | 482,325,792,896 | null | 42 | 42 |
print(*sorted(map(int, input().split())),sep=' ')
| A=range(1,10)
for i in A:
x=i
for j in A:
print "%dx%d=%d" %(i,j,x)
x+=i | 0 | null | 215,029,463,612 | 40 | 1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.