code1
stringlengths 16
427k
| code2
stringlengths 16
427k
| similar
int64 0
1
| pair_id
int64 6.82M
181,637B
⌀ | question_pair_id
float64 101M
180,471B
⌀ | code1_group
int64 2
299
| code2_group
int64 2
299
|
---|---|---|---|---|---|---|
from collections import deque
import sys
input = sys.stdin.readline
N = int(input())
G = [[] for _ in range(N)]
for _ in range(N):
ls = list(map(int, input().split()))
u = ls[0] - 1
for v in ls[2:]:
G[u].append(v - 1)
time = 1
d = [None for _ in range(N)]
f = [None for _ in range(N)]
def dfs(v):
global time
d[v] = time
time += 1
for u in range(N):
if u in G[v]:
if d[u] is None:
dfs(u)
f[v] = time
time += 1
for v in range(N):
if d[v] is None:
dfs(v)
for v in range(N):
print("{} {} {}".format(v + 1, d[v], f[v]))
|
s = input()
ans = chk = 0
ans = [-1] * (len(s)+1)
if s[0] == "<":
ans[0] = 0
if s[-1] == ">":
ans[-1] = 0
for i in range(len(s) - 1):
if s[i] == ">" and s[i+1] == "<":
ans[i+1] = 0
for i in range(len(s)):
if s[i] == "<":
ans[i+1] = ans[i] + 1
for i in range(-1, -len(s)-1,-1):
if s[i] == ">":
ans[i-1] = max(ans[i-1], ans[i]+1)
print(sum(ans))
| 0 | null | 78,233,878,224,516 | 8 | 285 |
il = [int(k) for k in input().split()]
K = il[0]
X = il[1]
if 500 * K >= X:
print("Yes")
else:
print("No")
|
l = input().split()
n,x = int(l[0]), int(l[1])
if 500*n >= x:
print("Yes")
else:
print("No")
| 1 | 98,273,425,937,412 | null | 244 | 244 |
s = int(input())
mod = 10**9 + 7
dp = [0]*(s+1)
dp[0] = 1
for i in range(1,s+1):
if i >= 3:
dp[i] = dp[i-3] + dp[i-1]
dp[i] %= mod
print(dp[s])
|
def main():
S=int(input())
mod=10**9+7
resList=[1,0,0,1,1,1]
n=6
if S>=n:
for i in range(n,S+1):
resList.append(resList[i-1]+resList[i-3])
print(resList[len(resList)-1]%mod)
else:
print(resList[S])
if __name__=="__main__":
main()
| 1 | 3,250,698,409,310 | null | 79 | 79 |
H, N = map(int, input().split())
A = list(map(int, input().split()))
A = sum(A)
if H > A:
ans = "No"
else:
ans = "Yes"
print(ans)
|
r=input().split()
H=int(r[0])
N=int(r[1])
data_pre=input().split()
data=[int(s) for s in data_pre]
if sum(data)>=H:
print("Yes")
else:
print("No")
| 1 | 77,854,865,710,908 | null | 226 | 226 |
#!/usr/bin/env python3
import sys
def solve(a: int):
poly = a + a**2 + a**3
return poly
# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template)
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
a = int(next(tokens)) # type: int
print(solve(a))
if __name__ == '__main__':
main()
|
x, y = map(int, input().split())
if x >= 10:
print(y)
else:
print(y+100*(10-x))
| 0 | null | 36,765,724,065,980 | 115 | 211 |
N=input().rstrip()
if N == "ABC":
print("ARC")
else:
print("ABC")
|
A, B, C = map(int, input().split())
if A == B or B == C or C == A:
if A == B and B == C:
print('No')
else:
print('Yes')
else:
print('No')
| 0 | null | 46,376,335,336,700 | 153 | 216 |
N, K = map(int, input().split())
A = list(map(int, input().split()))
def is_ok(n):
cnt = 0
for a in A:
if n >= a:
continue
cnt += a // n
return cnt <= K
def meguru_bisect(ng, ok):
while (abs(ok - ng) > 1):
mid = (ok + ng) // 2
if is_ok(mid):
ok = mid
else:
ng = mid
return ok
print(meguru_bisect(0, 10**9+1))
|
import math
N, K = map(int,input().split())
A = list(map(int, input().split()))
l, r = 0, max(A)
while r - l > 1:
x = (l + r) // 2
cnt = 0
for a in A:
n = math.ceil(a / x)
# n = (a + x - 1) // x
cnt += n - 1
if cnt > K:
l = x
else:
r = x
print(r)
| 1 | 6,481,177,874,780 | null | 99 | 99 |
A,B,H,M = map(int, input().split())
m = M/60*360
h = H/12*360+M/60*30
kakudo = (h-m)%360
import math
cos = math.cos(math.radians(kakudo))
print(math.sqrt(A*A+B*B-2*A*B*cos))
|
import sys
input = sys.stdin.readline
input = sys.stdin.buffer.readline
#sys.setrecursionlimit(10**9)
#from functools import lru_cache
def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()
#import numpy as np
from math import gcd
from collections import defaultdict
def main():
n=II()
mod=10**9+7
ans=1
cnt=0
d=defaultdict(int)
for _ in range(n):
a,b=MI()
if a==b==0:
cnt+=1
elif a==0:
d[(1,0)]+=1
elif b==0:
d[(0,-1)]+=1
else:
g=gcd(abs(a),abs(b))
if a*b>0:
d[(abs(a//g),abs(b//g))]+=1
else:
d[(abs(a//g),-abs(b//g))]+=1
s=set()
for a,b in list(d):
#print(a,b,s)
if (a,b) in s:
continue
if b>=0:
x=d[(a,b)]
y=d[(b,-a)]
s.add((a,b))
s.add((b,-a))
else:
x=d[(a,b)]
y=d[(-b,a)]
s.add((a,b))
s.add((-b,a))
ans*=2**x+2**y-1
ans%=mod
ans+=cnt-1
print(ans%mod)
if __name__ == "__main__":
main()
| 0 | null | 20,562,134,941,168 | 144 | 146 |
n, k = map(int, input().split())
p = list(map(int, input().split()))
pp = sorted(p)
ans = sum(pp[:k])
print(ans)
|
N,M = map(int, input().split())
prices = list(map(int,input().split()))
prices.sort()
print(sum(prices[0:M]))
| 1 | 11,556,440,603,232 | null | 120 | 120 |
a = input()
if a.isupper() == True:
print("A")
else:
print("a")
|
n = int(input())
ans = ['a']
for i in range(n-1):
buf = []
for j in ans:
l = len(set(j))
for c in range(l+1):
buf.append(j+chr(ord('a')+c))
ans = buf
for i in ans:
print(i)
| 0 | null | 31,668,613,409,202 | 119 | 198 |
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7
N = int(input())
lst1 = [('a', 0)]
lst2 = []
for i in range(N - 1):
if i % 2 == 0: #lst1 -->lst2
lst2 = []
for s, t in lst1:
last = max(ord(s[i]) - ord('a'), t)
for j in range(last + 2):
lst2.append((s + chr(j + ord('a')), max(t, j)))
else:
lst1 = []
for s, t in lst2:
last = max(ord(s[i]) - ord('a'), t)
for j in range(last + 2):
lst1.append((s + chr(j + ord('a')), (max(t, j))))
if len(lst2) > len(lst1):
lst2.sort()
for s, t in lst2:
print (s)
else:
lst1.sort()
for s, t in lst1:
print (s)
|
r=input().split()
H=int(r[0])
N=int(r[1])
data_pre=input().split()
data=[int(s) for s in data_pre]
if sum(data)>=H:
print("Yes")
else:
print("No")
| 0 | null | 65,211,596,441,628 | 198 | 226 |
import math
import numpy as np
import numba
from numba import njit, b1, i4, i8, f8
from numba import jit
import collections
import bisect
from collections import deque
from copy import copy, deepcopy
import time
def main():
N,X,T = map(int,input().split())
print(math.ceil(N/X) * T)
if __name__ == '__main__':
main()
|
from collections import Counter
def solve():
N = int(input())
S = list(input())
c = Counter(S)
ans = c['R']*c['G']*c['B']
for i in range(N):
for j in range(i+1,N):
k = j*2-i
if k>N-1:
break
if S[i]!=S[j] and S[j]!=S[k] and S[i]!=S[k]:
ans -= 1
return ans
print(solve())
| 0 | null | 20,176,507,862,662 | 86 | 175 |
if __name__ == "__main__":
A,B = map(int,input().split())
for i in range(1,1251):
A_tmp,B_tmp = int(i*0.08),int(i*0.10)
if A is A_tmp and B is B_tmp:
print(i)
exit()
print(-1)
|
A, B = map(int, input().split())
ans1 = 0
ans2 = 0
for i in range(10000):
ans1 = int(i * 0.08)
ans2 = int(i * 0.10)
if (ans1) == A and int(ans2) == B:
print(i)
exit()
print(-1)
| 1 | 56,222,245,435,744 | null | 203 | 203 |
import sys
def input(): return sys.stdin.readline().strip()
def resolve():
x,y=map(int, input().split())
ans=0
if x<=3:
ans+=100000
if x<=2:
ans+=100000
if x==1:
ans+=100000
if y<=3:
ans+=100000
if y<=2:
ans+=100000
if y==1:
ans+=100000
if x==1 and y==1:
ans+=400000
print(ans)
resolve()
|
import collections
import sys
A = []
n = int(input())
for i in range(1,100):
for j in range(1,100):
for k in range(1,100):
A.append(i**2+j**2+k**2+i*j+j*k+k*i)
c = collections.Counter(A)
for x in range(1,n+1):
print(c[x])
sys.exit()
| 0 | null | 74,131,426,435,300 | 275 | 106 |
print('ABC' if 'R' in input() else 'ARC')
|
N = int(input())
S = list(map(int, input().split()))
def f():
if 0 in S:
return 0
elif 10 ** 18 in S:
return -1
else:
ans = 1
for s in S:
ans *= s
if ans > 10 ** 18:
return -1
return ans
print(f())
| 0 | null | 20,285,714,077,530 | 153 | 134 |
s=input()
tex=[]
while 1:
a=input()
if a=="END_OF_TEXT":
break
else:
tex.extend([x.lower() for x in a.split()])
c=0
tex
for i in tex:
if i==s:
c+=1
print(c)
|
W = input().rstrip().lower()
ans = 0
while True:
line = input().rstrip()
if line == 'END_OF_TEXT': break
line = line.lower().split(' ')
for word in line:
if word == W: ans += 1
print(ans)
| 1 | 1,806,503,359,520 | null | 65 | 65 |
import sys
sys.setrecursionlimit(4100000)
import math
INF = 10**9
def main():
n = int(input())
s,t = input().split()
ans = ''
for i in range(n):
ans += s[i] + t[i]
print(ans)
if __name__ == '__main__':
main()
|
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")
# 処理内容
def main():
H, N = map(int, input().split())
A = [0]*N
B = [0]*N
for i in range(N):
A[i], B[i] = map(int, input().split())
dp = [INF] * 10000100
dp[0] = 0
for i in range(H):
if dp[i] == INF:
continue
for n in range(N):
dp[i+A[n]] = min(dp[i+A[n]], dp[i] + B[n])
ans = INF
for i in range(H, 10000100):
ans = min(ans, dp[i])
print(ans)
if __name__ == '__main__':
main()
| 0 | null | 96,518,118,830,580 | 255 | 229 |
def main():
N,M = map(int,input().split())
A = list(map(int,input().split()))
cnt = 0
for i in range(M):
cnt += A[i]
if N < cnt:
return -1
else:
return N - cnt
print(main())
|
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
x = [0] * (N + 1)
y = [0] * (M + 1)
for i in range(N):
x[i + 1] = x[i] + A[i]
for i in range(M):
y[i + 1] = y[i] + B[i]
j = M
ans = 0
for i in range(N + 1):
if x[i] > K:
continue
while j >= 0 and x[i] + y[j] > K:
j -= 1
ans = max(ans, i + j)
print(ans)
| 0 | null | 21,339,646,819,260 | 168 | 117 |
N = int(input())
ls = []
for i in range(N):
s = input()
ls.append(s)
newLs = list(set(ls))
print(len(newLs))
|
import math
PI = math.pi
r = input()
men = r*r * PI
sen = r*2 * PI
print('%.6f %.6f' % (men, sen))
| 0 | null | 15,481,226,656,982 | 165 | 46 |
def bubble_sort(r, n):
flag = True # ??£??\????´?????????¨????????°
while flag:
flag = False
for i in range(n - 1, 0, -1):
if r[i - 1][1] > r[i][1]:
r[i - 1], r[i] = r[i], r[i - 1]
flag = True
return r
def select_sort(r, n):
for i in range(0, n):
minj = i
for j in range(i, n):
if r[j][1] < r[minj][1]:
minj = j
if i != minj:
r[i], r[minj] = r[minj], r[i]
return r
def stable_sort(r, sort_r):
for i in range(len(r)):
for j in range(i + 1, len(r)):
for a in range(len(sort_r)):
for b in range(a + 1, len(sort_r)):
if r[i][1] == r[j][1] and r[i] == sort_r[b] and r[j] == sort_r[a]:
return "Not stable"
return "Stable"
N = int(input())
R = list(input().split())
C = R[:]
BS_R = bubble_sort(R, N)
SS_R = select_sort(C, N)
print(*BS_R)
print(stable_sort(R, BS_R))
print(*SS_R)
print(stable_sort(R, SS_R))
|
a = []
while True:
d = list(map(int,input().split()))
if d == [0,0]:
break
a.append(d)
for H,W in a:
print('#'*W)
for i in range(0,H-2):
print('#'+'.'*(W-2)+'#')
print('#'*W)
print('')
| 0 | null | 419,092,689,576 | 16 | 50 |
n, p = map(int,input().split())
D = input()
out = 0
if 10 % p == 0:
for i in range(n):
if int(D[i]) % p == 0:
out += i + 1
else:
mod = 0
count = [0] * p
ten = 1
count[mod] += 1
for i in range(n):
mod = (mod + int(D[n-i-1]) * ten) % p
ten = ten * 10 % p
count[mod] += 1
for c in count:
out += (c * (c - 1)) // 2
print(out)
|
import sys
input = sys.stdin.readline
N, P = map(int, input().split())
S = list(input().rstrip())
if P in {2, 5}:
ans = 0
for i, s in enumerate(S):
if int(s) % P == 0:
ans += i+1
else:
ans = 0
T = [0]*P
T[0] = 1
tmp = 0
k = 1
for s in reversed(S):
tmp = (tmp + k * int(s)) % P
k = k * 10 % P
ans += T[tmp]
T[tmp] += 1
print(ans)
| 1 | 58,285,703,250,160 | null | 205 | 205 |
while True:
m = map(int,raw_input().split())
if m[0] == 0 and m[1] == 0:
break
if m[0] >= m[1]:
print m[1],m[0]
else:
print m[0],m[1]
|
n = int(raw_input())
S = []
S = map(int, raw_input().split())
q = int(raw_input())
T = []
T = map(int, raw_input().split())
count = 0
for i in T:
if i in S:
count += 1
print count
| 0 | null | 293,289,302,198 | 43 | 22 |
#!/usr/bin/env python3
n = int(input())
matrix = []
while n > 0:
values = [int(x) for x in input().split()]
matrix.append(values)
n -= 1
official_house = [[[0 for z in range(10)] for y in range(3)] for x in range(4)]
Min = 0
Max = 9
for b, f, r, v in matrix:
num = official_house[b - 1][f - 1][r - 1]
if Min >= num or Max >= num:
official_house[b - 1][f - 1][r - 1] += v
for i in range(4):
for j in range(3):
print('',' '.join(str(x) for x in official_house[i][j]))
if 3 > i:
print('#' * 20)
|
Adr = [[[0 for r in range(10)]for f in range(3)]for b in range(4)]
n = input()
for i in range(n):
Inf = map(int, raw_input().split())
Adr[Inf[0]-1][Inf[1]-1][Inf[2]-1] += Inf[3]
for b in range(4):
for f in range(3):
print "",
for r in range(10):
if r != 9:
print Adr[b][f][r],
if r == 9:
if f == 3:
print Adr[b][f][r],
if f != 3:
print Adr[b][f][r]
if b < 3:
print "####################"
| 1 | 1,098,916,731,278 | null | 55 | 55 |
import sys
import copy
N, M, L = list(map(int, sys.stdin.readline().strip().split(" ")))
INF = 10**10
def warshall_floyd(g_mat):
dp = copy.copy(g_mat)
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])
return dp
graph = [[INF for _ in range(N)] for _ in range(N)]
for _ in range(M):
a, b, c = list(map(int, sys.stdin.readline().strip().split(" ")))
graph[a-1][b-1] = c
graph[b-1][a-1] = c
dist_graph = warshall_floyd(graph)
bool_graph = [[INF for _ in range(N)] for _ in range(N)]
for i in range(N):
for j in range(N):
if dist_graph[i][j] <= L:
bool_graph[i][j] = 1
ans_graph = warshall_floyd(bool_graph)
Q = int(sys.stdin.readline().strip())
for _ in range(Q):
s, t = list(map(int, sys.stdin.readline().strip().split(" ")))
ans = ans_graph[s-1][t-1]
print(ans-1 if ans != INF else -1)
|
X,Y,A,B,C=map(int,input().split())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))
p.sort()
p.reverse()
q.sort()
q.reverse()
while len(p)>X:
p.pop()
while len(q)>Y:
q.pop()
s=p+q+r
s.sort()
s.reverse()
c=0
for i in range(X+Y):
c+=s[i]
print(c)
| 0 | null | 109,315,889,834,580 | 295 | 188 |
N=int(input())
A=list(map(int,input().split()))
l=[0]*60
for i in A:
for j in range(60):
if i&(1<<j):l[j]+=1
ans=0
for i in range(60):
ans+=l[i]*(N-l[i])*(1<<i)
ans%=10**9+7
print(ans)
|
def main():
n = int(input())
p = [int(i) for i in input().split()]
Min = [10**9]
ans = 0
for i in range(n):
Min.append(min(Min[-1],p[i]))
for i in range(n):
if Min[i]>p[i]:
ans += 1
print(ans)
main()
| 0 | null | 104,182,643,545,178 | 263 | 233 |
S=input()
result=0
count=0
for i in S:
if i == "R":
count+=1
if count>result:
result=count
else:
count=0
print(result)
|
n = int(input())
a = 0
b = 0
d1 = 0
d2 = 0
for i in range(n):
d1,d2 = map(int,input().split())
if(a==0 and d1 ==d2):
a+=1
elif(a==1 and d1 ==d2):
a+=1
elif(a==2 and d1 ==d2):
b +=1
break
else:
a =0
if(b>=1):
print("Yes")
else:
print("No")
| 0 | null | 3,677,208,867,070 | 90 | 72 |
A = [[]]*3
for row in range(3):
A[row] = list(map(int, input().split()))
n = int(input())
B = [0]*n
for i in range(n):
B[i] = int(input())
flag = False
def check_bingo(A, B):
for row in range(3):
if A[row][0] and A[row][1] and A[row][2]:
return True
for col in range(3):
if A[0][col] and A[1][col] and A[2][col]:
return True
if A[0][0] and A[1][1] and A[2][2]:
return True
if A[0][2] and A[1][1] and A[2][0]:
return True
return False
for row in range(3):
for col in range(3):
if A[row][col] in B:
A[row][col] = True
else:
A[row][col] = False
print("Yes" if check_bingo(A, B) else "No")
|
A = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
B = [int(input()) for _ in range(N)]
for b in B:
for y in range(3):
for x in range(3):
if A[y][x] == b:
A[y][x] = -1
for y in range(3):
if sum(A[y]) == -3:
print("Yes")
exit()
for x in range(3):
if A[0][x] == A[1][x] == A[2][x] == -1:
print("Yes")
exit()
if A[0][0] == A[1][1] == A[2][2] == -1 or A[2][0] == A[1][1] == A[0][2] == -1:
print("Yes")
exit()
print("No")
| 1 | 60,050,366,122,138 | null | 207 | 207 |
class Dice:
def __init__(self):
d = map(int, raw_input().split(" "))
self.c = raw_input()
self.rows = [d[0], d[4], d[5], d[1]]
self.cols = [d[0], d[2], d[5], d[3]]
def __move_next(self, x, y):
temp = y.pop(0)
y.append(temp)
x[0] = y[0]
x[2] = y[2]
def __move_prev(self, x, y):
temp = y.pop(3)
y.insert(0, temp)
x[0] = y[0]
x[2] = y[2]
def execute(self):
for i in self.c:
self.__move(i, self.rows, self.cols)
def __move(self, com, x, y):
if com == "N":
self.__move_prev(y, x)
elif com == "S":
self.__move_next(y, x)
elif com == "E":
self.__move_prev(x, y)
elif com == "W":
self.__move_next(x, y)
def print_top(self):
print self.rows[0]
dice = Dice()
dice.execute()
dice.print_top()
|
n=int (input())
a=list(input().split(" "))
for i in range(0,n):
print(a[0][i]+a[1][i],end="")
| 0 | null | 55,819,317,354,628 | 33 | 255 |
import math
a,b=[int(i) for i in input().split()]
c=a//b
e=abs(a-(b*c))
f=abs(a-(b*(c+1)))
print(min(e,f))
|
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)
N, K = mapint()
v = N//K
print(min(N-v*K, K-(N-v*K)))
| 1 | 39,368,221,155,632 | null | 180 | 180 |
X, N = map(int, input().split())
if N == 0:
print(X)
else:
P = list(map(int, input().split()))
A = [0]
for i in range(1, 102):
if (i in P) == False:
A.append(i)
c = 101
for j in range(len(A)):
if abs(X - A[len(A)-int(j)-1]) <= abs(X - c):
c = A[len(A)-int(j)-1]
else:
c = c
print(c)
|
x, n = map(int, input().split())
p = list(map(int, input().split()))
for i in range(n):
if p[i] - x >= 0:
p[i] = 2 * (p[i] - x)
else:
p[i] = (x - p[i]) * 2 - 1
p = sorted(p)
i = 0
while i in p:
i += 1
if i % 2 == 0:
j = round(i / 2) + x
else:
j = x - round((i + 1) / 2)
print(j)
| 1 | 14,036,679,638,628 | null | 128 | 128 |
from collections import deque
n, m = map(int, input().split())
name = ['']*n
time = ['']*n
for i in range(n):
name[i], time[i] = input().split()
time = list(map(int, time))
Q = deque([i for i in range(n)])
t = 0
while Q!=deque([]):
q = Q.popleft()
if time[q]<=m:
t += time[q]
print(name[q] + ' ' + str(t))
else:
t += m
time[q] -= m
Q.append(q)
|
n=input()
cnt=0
for i in range(3):
if n[i]=="7":
cnt+=1
if cnt==0:
print("No")
else:
print("Yes")
| 0 | null | 17,179,883,797,780 | 19 | 172 |
import sys
def insertionSort(A, n, g):
for i in range(g, n):
global cnt
v = A[i]
j = i - g
while j >= 0 and A[j] > v:
A[j+g] = A[j]
j = j - g
cnt += 1
A[j+g] = v
def shellSort(A, n):
global m
global G
for i in range(0, m):
insertionSort(A, n, G[i])
n = int(input())
A = []
for i in range(n):
A.append(int(input()))
if n == 1:
print(1)
print(1)
print(0)
print(A[0])
sys.exit()
t = n - 1
G = []
G.append(t)
while t != 1:
t = t//2
G.append(t)
m = len(G)
cnt = 0
shellSort(A, n)
print(m)
print(' '.join(map(str, G)))
print(cnt)
for i in range(n):
print(A[i])
|
def insertion_sort(A, n, g):
cnt = 0
for i in range(g, n):
v = A[i]
j = i - g
while j >= 0 and A[j] > v:
A[j + g] = A[j]
j -= g
cnt += 1
A[j + g] = v
return cnt
def shell_sort(A, n):
cnt = 0
G = [1]
for i in range(1, 100):
# https://web.archive.org/web/20170212072405/http://www.programming-magic.com/20100507074241/
# 間隔
delta = 4 ** i + 3 * 2 ** (i - 1) + 1
if delta >= n:
break
G.append(delta)
G.reverse()
m = len(G)
for i in range(m):
cnt += insertion_sort(A, n, G[i])
return m, G, cnt
n = int(input())
A = [int(input()) for _ in range(n)]
m, G, cnt = shell_sort(A, n)
print(m)
print(*G)
print(cnt)
print(*A, sep='\n')
| 1 | 28,959,699,580 | null | 17 | 17 |
def Bfun():
vals = [int(i) for i in input().split()]
a = vals[0]
b = vals[1]
c = vals[2]
d = vals[3]
res2 = a//d + (1 if(a % d > 0) else 0)
res1 = c//b + (1 if(c % b > 0) else 0)
res = "Yes" if(res1 <= res2) else "No"
print(res)
Bfun()
|
N = int(input())
X = list(map(int, input().split()))
def cost(p):
res = 0
for x in X:
res += (x - p)**2
return res
m = sum(X) // N
print(min(cost(m), cost(m+1)))
| 0 | null | 47,316,703,893,710 | 164 | 213 |
r=int(input())
print(2*r*3.14159265358979)
|
n = int(input())
s = []
t = []
for i in range(n):
si, ti = input().split()
s.append(si)
t.append(int(ti))
x = input()
insleep = s.index(x)
ans = sum(t[insleep+1:])
print(ans)
| 0 | null | 64,032,034,865,568 | 167 | 243 |
#174 A
X = input()
print('Yes') if int(X)> 29 else print('No')
|
import sys
N,K=map(int,input().split())
plist=[0]+list(map(int,input().split()))
clist=[-float("inf")]+list(map(int,input().split()))
if max(clist)<=0:
print(max(clist))
sys.exit(0)
if K<=N:
max_answer=0
for i in range(1,N+1):
pos=i
max_score=0
score=0
for c in range(K):
pos=plist[pos]
score+=clist[pos]
max_score=max(score,max_score)
#print(i,max_score)
max_answer=max(max_answer,max_score)
print(max_answer)
sys.exit(0)
max_answer=0
for i in range(1,N+1):
pos=i
cycle_list=[]
score_list=[]
for _ in range(N):
pos=plist[pos]
cycle_list.append(pos)
score_list.append(clist[pos])
if pos==i:
break
num_cycle=K//len(cycle_list)
cycle_score=sum(score_list)
#print(cycle_list,score_list,num_cycle,cycle_score)
score=0
max_score=0
if cycle_score>=0:
score+=(num_cycle-1)*cycle_score
K2=K-len(cycle_list)*(num_cycle-1)
for _ in range(K2):
pos=plist[pos]
score+=clist[pos]
max_score=max(score,max_score)
#print(i,max_score)
max_answer=max(max_answer,max_score)
print(max_answer)
| 0 | null | 5,572,206,002,812 | 95 | 93 |
#python2.7
A=raw_input().split()
B=[]
for i in A:
if i.isdigit():
B.append(i)
else:
if i=="+":
B[-1]=str(int(B[-1])+int(B[-2]))
del B[-2]
elif i=="-":
B[-1]=str(int(B[-2])-int(B[-1]))
del B[-2]
elif i=="*":
B[-1]=str(int(B[-1])*int(B[-2]))
del B[-2]
print B[0]
|
X = int(input())
happy = X // 500 * 1000
happy += X % 500 // 5 * 5
print(happy)
| 0 | null | 21,494,756,253,252 | 18 | 185 |
def solve():
ans = 10**12
for i in range(1, int(N**0.5)+1):
if N % i == 0:
ans = min(ans, i + (N//i) -2)
if N == 2:
print(1)
elif N == 3:
print(2)
else:
print(ans)
if __name__ == "__main__":
N = int(input())
solve()
|
R, C, K = map(int, input().split())
item = {}
for _ in range(K):
r, c, v = map(int, input().split())
item[(r, c)] = v
dp = [[0] * 4 for _ in range(3010)]
ndp = [[0] * 4 for _ in range(3010)]
for r in range(1, R+1):
for c in range(1, C+1):
prer = max(dp[c])
ndp[c][0] = max(prer, ndp[c-1][0])
ndp[c][1] = max(prer, ndp[c-1][1])
ndp[c][2] = max(prer, ndp[c-1][2])
ndp[c][3] = max(prer, ndp[c-1][3])
if item.get((r, c)):
ndp[c][1] = max(ndp[c][1], max(prer, ndp[c-1][0]) + item[(r,c)])
ndp[c][2] = max(ndp[c][2], max(prer, ndp[c-1][1]) + item[(r,c)])
ndp[c][3] = max(ndp[c][3], max(prer, ndp[c-1][2]) + item[(r,c)])
dp = ndp
ndp = [[0] * 4 for _ in range(3010)]
#print(dp)
print(max(dp[C]))
| 0 | null | 83,455,495,157,792 | 288 | 94 |
N = int(input())
S = input()
print(f'{S if len(S)<=N else S[:N] + "..."}')
|
input_int = input()
input_str = input()
K = int(input_int)
S = str(input_str)
if len(S)<=K:
print(S)
elif len(S)>K:
print(S[:K]+'...')
| 1 | 19,629,573,753,580 | null | 143 | 143 |
# 入力
# 値は全てint
# Nは本数、Kは切る回数、AはN本の木のそれぞれの長さ(リスト)
N,K = map(int,input().split())
A = list(map(int,input().split()))
# 二分探索
# lが左端、rが右端
l,r = 0, 10**9
# 整数で返すので、差が1より大きい時はループする
while r - l > 1:
# 真ん中を設定
x = (r+l) // 2
# 切る回数をc
c = 0
for a in A:
# それぞれの丸太の(長さ-1)をxで割った値の合計が、切る回数
c += (a-1) // x
# 切る回数がKよりも小さい時はOKなので右端を寄せる
if c <= K:
r = x
else:
l = x
print(r)
|
from bisect import bisect_left, bisect_right, insort_left
import sys
readlines = sys.stdin.readline
def main():
n = int(input())
s = list(input())
q = int(input())
d = {}
flag = {}
for i in list('abcdefghijklmnopqrstuvwxyz'):
d.setdefault(i, []).append(-1)
flag.setdefault(i, []).append(-1)
for i in range(n):
d.setdefault(s[i], []).append(i)
for i in range(q):
q1,q2,q3 = map(str,input().split())
if q1 == '1':
q2 = int(q2) - 1
if s[q2] != q3:
insort_left(flag[s[q2]],q2)
insort_left(d[q3],q2)
s[q2] = q3
else:
ans = 0
q2 = int(q2) - 1
q3 = int(q3) - 1
if q2 == q3:
print(1)
continue
for string,l in d.items():
res = 0
if d[string] != [-1]:
left = bisect_left(l,q2)
right = bisect_right(l,q3)
else:
left = 0
right = 0
if string in flag:
left2 = bisect_left(flag[string],q2)
right2 = bisect_right(flag[string],q3)
else:
left2 = 0
right2 = 0
if left != right:
if right - left > right2 - left2:
res = 1
ans += res
#print(string,l,res)
print(ans)
if __name__ == '__main__':
main()
| 0 | null | 34,658,266,231,570 | 99 | 210 |
N = int(input())
XYList = []
for i in range(N):
A = int(input())
XY = []
for j in range(A):
XY.append(list(map(int, input().split())))
XYList.append(XY)
maxSum = 0
for i in range(2**N):
sum = 0
for j in range(N):
if i >> j & 1:
honest = True
for XY in XYList[j]:
if ((i >> (XY[0]-1)) & 1) != XY[1]:
honest = False
break
if honest:
sum += 1
else:
sum = 0
break
if maxSum < sum:
maxSum = sum
print(maxSum)
|
import sys
BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001
table = [0]*26
letters = "abcdefghijklmnopqrstuvwxyz"
input_str = sys.stdin.read()
for A in input_str:
index = 0
for B in letters:
if A == B or A == B.upper():
table[index] += 1
index += 1
for i in range(len(letters)):
print("%s : %d"%(letters[i],table[i]))
| 0 | null | 61,795,953,359,636 | 262 | 63 |
n = int(input())
alpha = "abcdefghij"
lst = []
def f(s,k):
if len(s) == n:
print(s)
return
for i in range(k+1):
if i == k: f(s+alpha[i],k+1)
else: f(s+alpha[i],k)
f("",0)
|
n = int(input())
alp = [chr(i) for i in range(97, 97+26)]
def dfs(i):
if i == 1:
return [("a", 1)]
else:
ret = []
for i in dfs(i-1):
nowstr, nowmax = i
for j in range(nowmax+1):
ret.append((nowstr+alp[j], max(j+1,nowmax)))
return ret
ans = dfs(n)
#print(ans)
for i in range(len(ans)):
print(ans[i][0])
| 1 | 52,504,982,354,488 | null | 198 | 198 |
x = int(input())
n=1
while 1:
angle_n = 360*n
if angle_n % x == 0:
ans = angle_n // x
break
else:
n += 1
print(ans)
|
ope = list(input().split())
stack = []
for o in ope:
if o == '+':
b, a = stack.pop(), stack.pop()
stack.append(a + b)
elif o == '-':
b, a = stack.pop(), stack.pop()
stack.append(a - b)
elif o == '*':
b, a = stack.pop(), stack.pop()
stack.append(a * b)
else:
stack.append(int(o))
print(stack[0])
| 0 | null | 6,568,754,727,418 | 125 | 18 |
x = int(input())
for i1 in range(x//105, -1, -1):
x2 = x - 105*i1
for i2 in range(x2//104, -1, -1):
x3 = x2 - 104*i2
for i3 in range(x3//103, -1, -1):
x4 = x3 - 103*i3
for i4 in range(x4//102, -1, -1):
x5 = x4 - 102*i4
for i5 in range(x5//101, -1, -1):
x6 = x5 -101*i5
for i6 in range(x6//100, -1, -1):
if x5 - 100*i6 == 0:
print(1)
exit()
print(0)
|
x = int(input())
c = 1
while True:
if c*100 <= x <= c*105:
print(1)
break
if c*100 > x:
print(0)
break
c += 1
| 1 | 126,994,659,084,220 | null | 266 | 266 |
from collections import deque
N,U,V = map(int, input().split())
U,V = U-1, V-1
E = [[] for _ in range(N)]
for _ in range(N-1):
a,b = map(int, input().split())
a,b = a-1, b-1
E[a].append(b)
E[b].append(a)
def BFS(root):
D = [ 0 for _ in range(N) ]
visited = [False for _ in range(N)]
willSearch = [ False for _ in range(N)]
Q = deque()
Q.append(root)
willSearch[root] = True
while len(Q) > 0:
now = Q.pop()
visited[now] = True
for nx in E[now]:
if visited[nx] or willSearch[nx]:
continue
willSearch[nx] = True
D[nx] = D[now] + 1
Q.append(nx)
return D
UD = BFS(U)
VD = BFS(V)
#print(UD)
#print(VD)
#初手で青木くんのPOINTにしか行けないケース
if E[U] == [V]:
print(0)
exit(0)
ans=0
for i in range(N):
if UD[i]<=VD[i]:
ans=max(ans,VD[i]-1)
print(ans)
|
N,K=map(int,input().split())
*A,=map(int,input().split())
vis=[0]*(N+1)
now=1
vis[now] = 1
his=[now]
while 1:
new = A[now-1]
if vis[new]==0:
vis[new]=1
his.append(new)
now = new
else:
idx = his.index(new)
cycle = his[idx:]
margin = his[:idx]
break
if K <= len(margin):
print(his[K])
exit()
K -= len(margin)
K %= len(cycle)
print(cycle[K])
| 0 | null | 69,728,806,879,368 | 259 | 150 |
inList = input().split()
stack = []
for i in inList:
if i in ['+', '-', '*']:
b, a = stack.pop(), stack.pop()
if i == '+':
stack.append(b + a)
if i == '-':
stack.append(a - b)
if i == '*':
stack.append(b * a)
else:
stack.append(int(i))
print(stack.pop())
|
N = int(input())
arr = sorted(list(map(int, input().split())),reverse=True)
arr2 = [arr[0]]
for i in range(1,N,1):
arr2.append(arr[i])
arr2.append(arr[i])
ans = 0
for i in range(N-1):
ans += arr2[i]
print(ans)
| 0 | null | 4,567,319,993,180 | 18 | 111 |
N, K = map(int ,input().split())
A = [int(x) for x in input().split()]
checked = [False] * N
root=[0]
idx = 0
checked[0]=True
for k in range(K):
root.append(A[idx]-1)
idx = A[idx]-1
if (checked[idx]):
break
checked[idx]=True
else:
print(idx+1)
exit(0)
for i, r in enumerate(root):
if r == root[-1]:
break
root2=root[i:]
l = len(root2)-1
idx = root2[(K-i)%(l)]
print(idx+1)
|
a, b = map(int, input().split())
print("%d %d" % (int(a * b), int(a + a + b + b)))
| 0 | null | 11,569,662,887,200 | 150 | 36 |
import sys
H, W, K = map(int, sys.stdin.readline().rstrip().split())
grid = [list(sys.stdin.readline().rstrip()) for _ in range(H)]
ans = [[-1] * W for _ in range(H)]
color = 0
for h in range(H):
flag = False
color += 1
for w in range(W):
if grid[h][w] == "#":
if not flag:
flag = True
else:
color += 1
ans[h][w] = color
if not flag:
for w in range(W):
ans[h][w] = -1
color -= 1
for w in range(W):
idx = []
color = -1
for h in range(H):
if ans[h][w] == -1:
if color != -1:
ans[h][w] = color
else:
idx.append(h)
else:
color = ans[h][w]
if idx:
for i in idx:
ans[i][w] = color
idx = []
for a in ans:
print(" ".join(map(str, a)))
|
import sys
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')
H, W, K = MI()
S = [None] * H
empty = set()
padding = [(0, 0)] * H
pad = 0
for i in range(H):
S[i] = list(input())
if all(c == '.' for c in S[i]):
empty.add(i)
pad += 1
else:
padding[i] = (pad, 0)
pad = 0
if pad > 0:
up, _ = padding[-pad - 1]
padding[-pad - 1] = (up, pad)
color = 1
ans = [[0] * W for _ in range(H)]
for i in range(H):
if i in empty:
continue
up, lp = padding[i]
last = 0
for j in range(W):
if S[i][j] == '#':
for x in range(last, j + 1):
for y in range(-up, lp + 1):
ans[i + y][x] = color
color += 1
last = j + 1
if S[i][-1] == '.':
for x in range(last, W):
for y in range(-up, lp + 1):
ans[i + y][x] = color - 1
for l in ans:
print(' '.join(str(c) for c in l))
| 1 | 143,386,845,395,640 | null | 277 | 277 |
n = int(input())
a = list(map(int, input().split()))
x = 0
for i in a:
x ^= i
for i in range(n):
a[i] ^= x
print(*a)
|
S=str(input())
print('ARC' if S=='ABC' else 'ABC')
| 0 | null | 18,345,913,422,410 | 123 | 153 |
n=int(input())
s=input()
num=n
for i in range(1,n):
if s[i-1]==s[i]:
num-=1
print(num)
|
# coding:utf-8
while True:
m,f,r = map(int, raw_input().split())
if m == -1 and f == -1 and r == -1:
break
if m == -1 or f == -1:
print 'F'
elif m + f >= 80:
print 'A'
elif m + f >= 65:
print 'B'
elif m + f >= 50:
print 'C'
elif m + f >= 30:
if r >= 50:
print 'C'
else:
print 'D'
else:
print 'F'
| 0 | null | 86,061,430,062,592 | 293 | 57 |
a,b,c,k=map(int,input().split())
if(k<=a):
print(k)
else:
print(a-(k-a-b))
|
import bisect
N, M = map(int, input().split())
A = [int(x) for x in input().split()]
A.sort()
INF = 10 ** 9
A.append(INF)
left, right = 0, 2 * max(A)
while left + 1 < right:
mid = (left + right) >> 1
cnt = sum(N - bisect.bisect_left(A, mid-A[i]) for i in range(N))
if cnt >= M:
left = mid
else:
right = mid
acc = [0]
for i in range(N):
acc.append(acc[-1] + A[i])
ans = 0
cnt, min_val = 0, INF
for i in range(N):
idx = bisect.bisect_left(A, left-A[i])
cnt += N - idx
min_val = min(min_val, A[i] + A[idx])
ans += (N - idx) * A[i] + acc[N] - acc[idx]
ans -= (cnt - M) * min_val
print(ans)
| 0 | null | 64,734,744,792,894 | 148 | 252 |
n, a, b = map(int, input().split())
if (b - a) % 2 == 0:
print(-(-(b - a) // 2))
else:
print(min(a - 1 + -(-(b - a + 1) // 2), n - b + -(-(b - a) // 2)))
|
N,A,B=map(int,input().split())
ans=min(A-1,N-B)+1+(B-A-1)//2
sum=0
if (B-A)%2==0:
sum=(B-A)//2
ans=min(sum,ans)
print(ans)
| 1 | 109,229,834,304,838 | null | 253 | 253 |
MOD = (10 ** 9) + 7
n, k = map(int, input().split())
a = list(map(int, input().split()))
negs = [-x for x in a if x < 0]
non_negs = [x for x in a if x >= 0]
if len(non_negs) == 0 and k % 2 == 1:
negs.sort()
ans = 1
for i in range(k):
ans = ans * -negs[i] % MOD
print(ans)
exit()
negs_p, non_negs_p = 0, 0
negs.sort(reverse = True)
non_negs.sort(reverse = True)
for i in range(k):
if negs_p == len(negs):
non_negs_p += 1
elif non_negs_p == len(non_negs):
negs_p += 1
elif negs[negs_p] > non_negs[non_negs_p]:
negs_p += 1
else:
non_negs_p += 1
if negs_p % 2 == 0 or k == n:
ans = 1
for i in range(negs_p):
ans = ans * -negs[i] % MOD
for i in range(non_negs_p):
ans = ans * non_negs[i] % MOD
print(ans)
exit()
if negs_p == len(negs) or non_negs_p == 0:
negs_p -= 1
non_negs_p += 1
ans = 1
for i in range(negs_p):
ans = ans * -negs[i] % MOD
for i in range(non_negs_p):
ans = ans * non_negs[i] % MOD
print(ans)
exit()
if non_negs_p == len(non_negs) or negs_p == 0:
negs_p += 1
non_negs_p -= 1
ans = 1
for i in range(negs_p):
ans = ans * -negs[i] % MOD
for i in range(non_negs_p):
ans = ans * non_negs[i] % MOD
print(ans)
exit()
a = negs[negs_p - 1]
b = negs[negs_p]
c = non_negs[non_negs_p - 1]
d = non_negs[non_negs_p]
if a * b > c * d:
negs_p += 1
non_negs_p -= 1
else:
negs_p -= 1
non_negs_p += 1
ans = 1
for i in range(negs_p):
ans = ans * -negs[i] % MOD
for i in range(non_negs_p):
ans = ans * non_negs[i] % MOD
print(ans)
|
a = [list(map(int,input().split())) for i in range(3)]
n = int(input())
b = [int(input()) for i in range(n)]
for i in range(3):
for j in range(3):
if a[i][j] in b:
a[i][j] = "o"
for i in range(3):
if a[i][0] == a[i][1] == a[i][2]:
print("Yes")
exit()
elif a[0][i] == a[1][i] == a[2][i]:
print("Yes")
exit()
elif a[0][0] == a[1][1] == a[2][2]:
print("Yes")
exit()
elif a[0][2] == a[1][1] == a[2][0]:
print("Yes")
exit()
elif i == 2:
print("No")
| 0 | null | 34,913,882,479,960 | 112 | 207 |
from collections import deque
N, M = map(int, input().split())
G = [[] for _ in range(N+1)]
for _ in range(M):
a, b = map(int, input().split())
G[a].append(b)
G[b].append(a)
q = deque([1])
closed = [False] * (N+1)
closed[1] = True
Ans = [0] * (N+1)
while q:
v = q.popleft()
for u in G[v]:
if not closed[u]:
closed[u] = True
q.append(u)
Ans[u] = v
print("Yes")
print("\n".join(map(str, Ans[2:])))
|
from collections import deque
N,M=map(int,input().split())
A=[0]*M;B=[0]*M
C=[[] for i in range(N+1)]
for i in range(M):
A[i],B[i]=sorted(list(map(int,input().split())))
C[A[i]].append(B[i])
C[B[i]].append(A[i])
d=[-1]*(N+1)
d[0]=0
d[1]=0
queue=deque()
queue.append(1)
while queue:
now = queue.popleft()
for i in C[now]:
if d[i]!=-1:continue
d[i]=d[now]+1
queue.append(i)
#print(d)
E=[0]*(N+1)
for i in range(M):
# print(d[A[i]],d[B[i]])
if d[B[i]]-d[A[i]]==1 and E[B[i]]==0:E[B[i]]=A[i]
elif d[A[i]]-d[B[i]]==1 and E[A[i]]==0:E[A[i]]=B[i]
if E.count(0)>2:print('No');exit
print('Yes')
for i in range(2,N+1):
print(E[i])
| 1 | 20,566,896,738,464 | null | 145 | 145 |
import sys
import math
input = sys.stdin.readline
A, B = map(int, input().split())
X = A / 0.08
Y = B/0.1
for i in range(math.floor(min(X, Y)), math.ceil(max(X, Y)) + 1):
if int(i * 0.08) == A and int(i * 0.10) == B:
print(i)
exit()
print(-1)
|
import math
A, B = map(int, input().split())
ans = -1
for a in range(math.ceil(A/0.08), math.ceil((A+1)/0.08)):
if int(a*0.1) == B:
ans = a
break
print(ans)
| 1 | 56,205,697,565,182 | null | 203 | 203 |
A, B, K = [int(x) for x in input().split()]
if K <= A:
print(A - K, B)
else:
print(0, max(0, A + B - K))
|
a,b,k=map(int,input().split())
if a<=k:
k-=a
a=0
if b<=k:
print(0,0)
else:
b-=k
print(a,b)
elif k<a:
a-=k
print(a,b)
| 1 | 104,434,898,533,020 | null | 249 | 249 |
S = input()
from collections import defaultdict
d = defaultdict(int)
before = 0
for i in range(1,len(S)+1):
now = (int(S[-i])*pow(10,i,2019)+before) % 2019
d[now] += 1
before = now
d[0] += 1
ans = 0
for i in d.values():
ans += i*(i-1)//2
print(ans)
|
from collections import deque
INF = 1000000
N,T,A=map(int,input().split())
T -= 1
A -= 1
G = [ [] for i in range(N) ]
DT = [ INF for _ in range(N) ]
DA = [ INF for _ in range(N) ]
for i in range(N-1):
h1,h2=map(int,input().split())
h1 -= 1
h2 -= 1
G[h1].append(h2);
G[h2].append(h1);
DT[T] = 0
DA[A] = 0
q = deque()
# BFS
q.append(T)
while len(q) > 0:
v = q.popleft()
for nv in G[v]:
if DT[nv] == INF:
DT[nv] = DT[v] + 1
q.append(nv)
q.clear()
q.append(A)
while len(q) > 0:
v = q.popleft()
for nv in G[v]:
if DA[nv] == INF:
DA[nv] = DA[v] + 1
q.append(nv)
max_da = 0
for i in range(N):
#print(i, " T:", DT[i], " A:", DA[i])
if DA[i] - DT[i] >= 1 :
max_da = max(DA[i], max_da)
print(max_da-1)
| 0 | null | 74,128,405,709,908 | 166 | 259 |
import random
import time
def search(day, schedule, c, s, satisfy):
score = 0
date = [0] * 26
for d in range(day):
tmp = 0
contest = 0
nmax = -float('inf')
for i in range(26):
tmp += c[i] * (d + 1 - date[i])
for i in range(26):
tmp2 = s[d][i] - tmp + c[i] * (d + 1 - date[i])
if nmax < tmp2:
nmax = tmp2
contest = i
date[contest] = d + 1
satisfy.append(tmp - c[contest] * (d + 1 - date[contest]))
schedule.append(contest)
score += s[d][contest] - satisfy[d]
return score
# def decrease(day, schedule, c, s, satisfy):
# ret = 0
# date = [0] * 26
# for d in range(day):
# now = schedule[d] + 1
# date[now - 1] = d + 1
# tmp = 0
# for i in range(26):
# tmp += c[i] * (d+1 - date[i])
# ret += tmp
# satisfy.append(tmp)
# return ret
def change(_from, _to, schedule, c, s, satisfy):
ret = 0
date = [0] * 26
for d in range(_to):
if d < _from-1:
ret += satisfy[d]
continue
now = schedule[d] + 1
date[now - 1] = d + 1
tmp = 0
for i in range(26):
tmp += c[i] * (d+1 - date[i])
ret += tmp
satisfy[d] = tmp
return ret
def Main():
D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(D)]
dissatisfy=[]
schedule = []
score = 0
start = time.time()
#最大値を足すだけ
# for i in range(D):
# schedule.append(np.argmax(s[i]))
# score += np.max(s[i])
ans = search(D, schedule, c, s, dissatisfy)
for i in range(D):
score+=s[i][schedule[i]]
while time.time() - start < 1.8:
contest = random.randint(0, 25)
day = random.randint(0, D - 1)
if schedule[day] == contest:
continue
save = dissatisfy.copy()
dec2 = change(day + 1, D, schedule, c, s, dissatisfy)
score2 = score - s[day][schedule[day]] + s[day][contest]
if ans < score2 - dec2:
ans = score2 - dec2
score = score2
schedule[day] = contest
else:
dissatisfy = save
for i in range(D):
print(schedule[i] + 1)
if __name__ == "__main__":
Main()
|
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
from time import time
from random import randint
from copy import deepcopy
start_time = time()
def calcScore(t, s, c):
scores = [0]*26
lasts = [0]*26
for i in range(1, len(t)):
scores[t[i]] += s[i][t[i]]
dif = i - lasts[t[i]]
scores[t[i]] -= c[t[i]] * dif * (dif-1) // 2
lasts[t[i]] = i
for i in range(26):
dif = len(t) - lasts[i]
scores[i] -= c[i] * dif * (dif-1) // 2
return scores
def greedy(c, s):
day_lim = len(s)
socres = [0]*26
t = [0]*day_lim
lasts = [0]*26
for i in range(1, day_lim):
pls = [v for v in socres]
mns = [v for v in socres]
for j in range(26):
pls[j] += s[i][j]
mns[j] -= c[j] * (i - lasts[j])
sum_mns = sum(mns)
pt = sum_mns - mns[0] + pls[0]
idx = 0
for j in range(1, 26):
tmp = sum_mns - mns[j] + pls[j]
if pt < tmp:
pt = tmp
idx = j
t[i] = idx
lasts[idx] = i
for j in range(26):
if j == idx:
socres[j] = pls[j]
else:
socres[j] = mns[j]
return socres, t
def subGreedy(c, s, t, day):
day_lim = len(s)
socres = [0]*26
t = [0]*day_lim
lasts = [0]*26
for i in range(1, day_lim):
if day <= i:
pls = [v for v in socres]
mns = [v for v in socres]
for j in range(26):
pls[j] += s[i][j]
mns[j] -= c[j] * (i - lasts[j])
sum_mns = sum(mns)
pt = sum_mns - mns[0] + pls[0]
idx = 0
for j in range(1, 26):
tmp = sum_mns - mns[j] + pls[j]
if pt < tmp:
pt = tmp
idx = j
t[i] = idx
lasts[idx] = i
for j in range(26):
if j == idx:
socres[j] = pls[j]
else:
socres[j] = mns[j]
else:
scores[t[i]] += s[i][t[i]]
lasts[t[i]] = i
for j in range(26):
dif = i - lasts[j]
scores[j] -= c[j] * dif
return socres, t
D = int(input())
c = list(map(int, input().split()))
s = [[0]*26 for _ in range(D+1)]
for i in range(1, D+1):
s[i] = list(map(int, input().split()))
scores, t = greedy(c, s)
sum_score = sum(scores)
while time() - start_time < 1.86:
typ = randint(1, 90)
if typ <= 70:
for _ in range(100):
tmp_t = deepcopy(t)
tmp_t[randint(1, D)] = randint(0, 25)
tmp_scores = calcScore(tmp_t, s, c)
sum_tmp_score = sum(tmp_scores)
if sum_score < sum_tmp_score:
sum_score = sum_tmp_score
t = deepcopy(tmp_t)
scores = deepcopy(tmp_scores)
elif typ <= 90:
for _ in range(30):
tmp_t = deepcopy(t)
dist = randint(1, 20)
p = randint(1, D-dist)
q = p + dist
tmp_t[p], tmp_t[q] = tmp_t[q], tmp_t[p]
tmp_scores = calcScore(tmp_t, s, c)
sum_tmp_score = sum(tmp_scores)
if sum_score < sum_tmp_score:
sum_score = sum_tmp_score
t = deepcopy(tmp_t)
scores = deepcopy(tmp_scores)
elif typ <= 100:
tmp_t = deepcopy(t)
day = randint(D//4*3, D)
tmp_scores, tmp_t = subGreedy(c, s, tmp_t, day)
sum_tmp_score = sum(tmp_scores)
if sum_score < sum_tmp_score:
sum_score = sum_tmp_score
t = tmp_t
scores = tmp_scores
for v in t[1:]:
print(v+1)
| 1 | 9,714,636,958,478 | null | 113 | 113 |
def comb(n,r,m):
if 2*r > n:
r = n - r
nume,deno = 1,1
for i in range(1,r+1):
nume *= (n-i+1)
nume %= m
deno *= i
deno %= m
return (nume * pow(deno,m-2,m)) % m
def main():
N,M,K = map(int,input().split())
mod = 998244353
ans,comb_r = pow(M-1,N-1,mod),1
for r in range(1,K+1):
comb_r = (comb_r * (N-r) * pow(r,mod-2,mod)) % mod
ans = (ans + comb_r * pow(M-1,N-r-1,mod)) % mod
ans = (ans * M) % mod
print(ans)
if __name__ == "__main__":
main()
|
# coding: utf-8
# Your code here!
n,M,K=map(int,input().split())
mod=998244353
fac = [1] * (n + 1)
inv = [1] * (n + 1)
for j in range(1, n + 1):
fac[j] = fac[j-1] * j % mod
inv[n] = pow(fac[n], mod-2, mod)
for j in range(n-1, -1, -1):
inv[j] = inv[j+1] * (j+1) % mod
def comb(n, r):
if r > n or n < 0 or r < 0:
return 0
return fac[n] * inv[n - r] * inv[r] % mod
ans=0
temp=(M*(M-1)**(n-K-1))%mod#1乗
for k in range(K+1)[::-1]:
ans=(ans+temp*comb(n-1,k))%mod
temp=(temp*(M-1))%mod
print(ans)
| 1 | 23,278,429,492,850 | null | 151 | 151 |
str_in = input()
print(str_in.swapcase())
|
s = input()
m = {}
for k in 'abcdefghijklmnopqrstuvwxyz':
upper = k.upper()
m[k] = upper
m[upper] = k
r = ''
for t in s:
if t in m:
r += m[t]
else:
r += t
print(r)
| 1 | 1,513,158,183,232 | null | 61 | 61 |
k = int(input())
s = input()
a = len(s) - k
if a <= 0:
print(s)
else:
#a >0
print(s[:k] + "...")
|
A = [[int(x) for x in input().split()] for _ in range(3)]
N = int(input())
b = [int(input()) for _ in range(N)]
Bingo = [[0, 0, 0] for _ in range(3)]
for i in range(3):
for j in range(3):
for l in range(N):
if(A[i][j] == b[l]):
Bingo[i][j] = 1
bingo = 0
for i in range(3):
if(Bingo[i][0]+Bingo[i][1]+Bingo[i][2])==3:
bingo += 1
elif(Bingo[0][i]+Bingo[1][i]+Bingo[2][i])==3:
bingo += 1
if(Bingo[0][0]+Bingo[1][1]+Bingo[2][2])==3:
bingo += 1
elif(Bingo[0][2]+Bingo[1][1]+Bingo[2][0])==3:
bingo += 1
if(bingo!=0):
print('Yes')
else:
print('No')
| 0 | null | 39,578,388,752,028 | 143 | 207 |
from collections import OrderedDict
import sys
cnt = OrderedDict()
for i in range(ord('a'), ord('z') + 1):
cnt[chr(i)] = 0
S = sys.stdin.readlines()
for s in S:
s = s.lower()
for i in s:
if i in cnt:
cnt[i] += 1
for k, v in cnt.items():
print('{} : {}'.format(k, v))
|
n, m, l = map(int, input().split())
A = [list(map(int, input().split())) for i in range(n)]
B = [list(map(int, input().split())) for j in range(m)]
c = [[0] * l for i in range(n)]
for i in range(n):
for j in range(l):
for k in range(m):
c[i][j] += A[i][k] * B[k][j]
print(*c[i])
| 0 | null | 1,544,103,698,364 | 63 | 60 |
S = list(input())
if S[-1] == 's':
S.append('e')
S.append('s')
else:
S.append('s')
strS = ''.join(S)
print(strS)
|
def main():
S = input()
if S.endswith('s'):
answer = S + 'es'
else:
answer = S + 's'
print(answer)
if __name__ == "__main__":
main()
| 1 | 2,366,629,071,338 | null | 71 | 71 |
N = int(input())
A = [int(i) for i in input().split()]
possess = 1000
for i in range(N-1):
if A[i] < A[i+1]:
stock = possess//A[i]
possess = possess % A[i] + A[i+1] * stock
print(possess)
|
INF = 300
n = int(input())
a = [INF] + list(map(int, input().split())) + [-INF]
money = 1000
stock = 0
for e1, e2 in zip(a, a[1:]):
if e1 < e2:
buy = money // e1
money -= buy * e1
stock += buy
else:
money += stock * e1
stock = 0
print(money)
| 1 | 7,372,330,126,460 | null | 103 | 103 |
while True:
st = list(raw_input())
if st[0] == '-':
break
m = int(raw_input())
for k in range(m):
h = int(raw_input())
st = st + st[:h]
del st[:h]
print ''.join(st)
|
while True:
deck = input()
if deck == '-':
break
m = int(input())
h = [int(input()) for i in range(m)]
for i in h:
deck = deck[i:] + deck[:i]
print(deck)
| 1 | 1,902,346,774,718 | null | 66 | 66 |
a,b=map(int,raw_input().split())
print a/b,a%b,'%.8f'%(1.*a/b)
|
A = int(input())
B = int(input())
if A*B==2:
print(3)
elif A*B==3:
print(2)
else:
print(1)
| 0 | null | 55,828,376,661,798 | 45 | 254 |
s = input()
for _ in range(int(input())):
o = input().split()
a, b = map(int, o[1:3])
b += 1
c = o[0][2]
if c == 'p':
s = s[:a]+o[3]+s[b:]
elif c == 'i':
print(s[a:b])
elif c == 'v':
s = s[:a]+s[a:b][::-1]+s[b:]
|
a, b, c = map(int, raw_input().split())
if a > b > c or a < b < c:
print "Yes"
else:
print "No"
| 0 | null | 1,226,934,711,098 | 68 | 39 |
n=input().split()
a=int(n[0])
b=int(n[1])
if a>=2*b:
print(a-2*b)
else:
print("0")
|
a, b = [int(i) for i in input().split()]
if a >= b*2:
print(a - b*2)
else:
print(0)
| 1 | 166,157,734,911,532 | null | 291 | 291 |
N=int(input())
Taro=0
Hanako=0
for i in range(N):
T,H=map(str,input().split())
if T<H:
Hanako+=3
elif H<T:
Taro+=3
else:
Hanako+=1
Taro+=1
print(Taro,Hanako)
|
t=0
h=0
for i in range(int(input())):
l=input().split()
if l[0]==l[1]:
t+=1
h+=1
elif l[0]>l[1]: t+=3
else: h+=3
print(t,h)
| 1 | 1,989,221,604,412 | null | 67 | 67 |
N = int(input())
def f(l, r):
cnt = 0
if l == r and l <= N:
cnt += 1
if l*10 + r <= N:
cnt += 1
for c in range(1, 5):
x = l*10**(c+1) + r
i = 0
I = int("9"*c)
while x <= N and i <= I:
cnt += 1
x += 10
i += 1
return cnt
C = [[0]*9 for _ in range(9)]
ans = 0
for i in range(9):
for j in range(9):
C[i][j] = f(i+1, j+1)
for i in range(9):
for j in range(9):
ans += C[i][j] * C[j][i]
print(ans)
|
N=int(input())
n=len(str(N))
res=0
for a in range(1,N+1):
a0=str(a)[0]
a1=str(a)[-1]
if a0=='0' or a1=='0':
a_res=res
continue
for i in range(1,n+1):
if i==1:
if a0==a1:
res+=1
elif i==2:
if 10*int(a1)+int(a0)<=N:
res+=1
elif i==n:
n0=str(N)[0]
n1=str(N)[-1]
if n0<a1:
res+=0
elif n0>a1:
res+=10**(i-2)
else:
res+=(N-int(a1)*10**(i-1))//10+1
if n1<a0:
res-=1
else:
res+=10**(i-2)
print(res)
| 1 | 86,169,643,037,258 | null | 234 | 234 |
import math
n=int(input())
#def koch(p1,p2,n):
def koch(d,p1,p2):
if d==0:
return
#3等分する
s=[(2*p1[0]+1*p2[0])/3,(2*p1[1]+1*p2[1])/3]
t=[(1*p1[0]+2*p2[0])/3,(1*p1[1]+2*p2[1])/3]
#正三角形の頂点のひとつである座標を求める
u=[
(t[0]-s[0])*math.cos(math.radians(60))-(t[1]-s[1])*math.sin(math.radians(60))+s[0],
(t[0]-s[0])*math.sin(math.radians(60))+(t[1]-s[1])*math.cos(math.radians(60))+s[1]
]
koch(d-1,p1,s)
print(*s)
koch(d-1,s,u)
print(*u)
koch(d-1,u,t)
print(*t)
koch(d-1,t,p2)
print('0 0')
koch(n,[0,0],[100,0])
print('100 0')
|
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
return sys.stdin.readline()[:-1]
def ruiseki(lst):
return [0]+list(accumulate(lst))
mod=pow(10,9)+7
n,k=map(int,input().split())
a=list(map(int,input().split()))
f=list(map(int,input().split()))
left,right=-1,10**12+1
a.sort()
f.sort()
# print(a)
while right-left>1:
mid=(right+left)//2
tmp=0
for i in range(n):
tmp+=max(0,a[i]-mid//f[-1-i])
if tmp<=k:
right=mid
else:
left=mid
print(right)
| 0 | null | 82,590,691,191,182 | 27 | 290 |
N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
if sum(A) <= K:
print(0)
exit()
def ok(c):
s = 0
for i in range(N):
s += max(0, A[i] - c // F[i])
return s <= K
A.sort()
F.sort(reverse=True)
l, r = -1, 10 ** 12
while l + 1 < r:
c = (l + r) // 2
if ok(c):
r = c
else:
l = c
print(r)
|
import sys
def solve():
input = sys.stdin.readline
N, K = map(int, input().split())
A = [int(a) for a in input().split()]
F = [int(f) for f in input().split()]
A.sort(reverse = True)
F.sort()
low, high = -1, 10 ** 13
while high - low > 1:
mid = (low + high) // 2
count = 0
for i in range(N):
counterF = mid // F[i]
if counterF < A[i]: count += A[i] - counterF
if count <= K: high = mid
else: low = mid
print(high)
return 0
if __name__ == "__main__":
solve()
| 1 | 164,927,725,729,672 | null | 290 | 290 |
#coding: UTF-8
import math
def RN(n,a):
ans=""
for i in range(int(n)):
ans+=a[int(n)-1-i]+" "
print(ans[:-1])
if __name__=="__main__":
n=input()
a=input()
List=a.split(" ")
RN(n,List)
|
Alp = input()
if Alp.isupper() == True :
print('A')
else:
print('a')
| 0 | null | 6,128,851,988,700 | 53 | 119 |
pages=int(input())
papers=pages/2
res=int(papers)
if pages%2==0:
print(res)
else:
print(res+1)
|
nml=input().split()
n,m,l=int(nml[0]),int(nml[1]),int(nml[2])
A_=[input() for i in range(n)]
B_=[input() for i in range(m)]
A,B=[],[]
for i in range(n):
A_[i]=A_[i].split()
for i in A_:
A.append(list(map(lambda i:int(i),i)))
for i in range(m):
B_[i]=B_[i].split()
for i in B_:
B.append(list(map(lambda i:int(i),i)))
AB=[]
for i in range(n):
AB.append([])
for i in range(n):
for j in range(l):
AB[i].append(0)
for i in range(n):
for j in range(l):
for k in range(m):
AB[i][j]+=(A[i][k]*B[k][j])
for i in AB:
print(*i)
| 0 | null | 30,160,400,384,708 | 206 | 60 |
XY=list(map(int,input().split()))
prize=0
for xy in XY:
if xy==1:
prize+=300000
elif xy==2:
prize+=200000
elif xy==3:
prize+=100000
if sum(XY)==2:
prize+=400000
print(prize)
|
ri = lambda S: [int(v) for v in S.split()]
N, A, B = ri(input())
q, r = divmod(N, A+B)
blue = (A * q) + r if r <= A else (A * q) + A
print(blue)
| 0 | null | 97,673,155,001,280 | 275 | 202 |
n,m = map(int,raw_input().split())
A = [[0 for i in range(m)] for i in range(n)]
B = [ 0 for i in range(m)]
for i in range(n):
A[i] = map(int,raw_input().split())
for i in range(m):
B[i] = input()
for i in range(n):
sum = 0
for j in range(m):
sum += A[i][j] * B[j]
print sum
|
行数, 列数 = map(int, input().split())
#行列の初期化
行列 = [[0 for _ in range(列数)] for __ in range(行数)]
#データをもとに行列を作成
for 現在行 in range(行数):
行データ = list(map(int, input().split()))
for 現在列 in range(列数):
行列[現在行][現在列] = 行データ[現在列]
#ベクトルデータを取得
ベクトル = [0 for _ in range(列数)]
for 現在行 in range(列数):
ベクトル[現在行] = int(input())
答え = []
#ベクトルを掛ける
for i in range(行数):
c = 0
for j in range(列数):
c += 行列[i][j] * ベクトル[j]
答え.append(c)
#表示
for i in range(len(答え)):
print(答え[i])
| 1 | 1,154,640,484,452 | null | 56 | 56 |
x1, y1, x2, y2 = map(float, raw_input().split())
print ((x1-x2)**2 + (y1-y2)**2)**0.5
|
x1, y1, x2, y2 = map(float, input().split())
X = (x2 - x1)**2
Y = (y2 - y1)**2
distance = (X + Y)**(1/2)
print("%.8f" % (float(distance)))
| 1 | 156,922,024,260 | null | 29 | 29 |
import sys
sys.setrecursionlimit(2*10**5)
n, u, v = map(int, input().split())
edge = [tuple(map(int, input().split())) for _ in range(n-1)]
u -= 1
v -= 1
connect = [set() for _ in range(n)]
for a, b in edge:
connect[a-1].add(b-1)
connect[b-1].add(a-1)
du = [0] * n
dv = [0] * n
def dfs(v, dis, ng, d):
d[v] = dis
ng.add(v)
for w in connect[v]:
if w not in ng:
dfs(w, dis+1, ng, d)
dfs(u, 0, set(), du)
dfs(v, 0, set(), dv)
ans = 0
for i in range(n):
if du[i] < dv[i]:
ans = max(ans, dv[i]-1)
print(ans)
|
s = str(input())
#s = "<>>><<><<<<<>>><"
ans = 0
def leftmore(ln):
ret = [0]
cur = 0
for c in ln:
if c == "<":
cur += 1
else:
cur = 0
ret.append(cur)
return ret
def rightless(ln):
revl = reversed(ln)
ret = [0]
cur = 0
for c in revl:
if c == ">":
cur += 1
else:
cur = 0
ret.append(cur)
return list(reversed(ret))
lm = leftmore(s)
rl = rightless(s)
for i in range(len(s)+1):
ans += max(lm[i],rl[i])
print(ans)
| 0 | null | 137,099,998,034,048 | 259 | 285 |
def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b)
import fileinput
import math
for line in fileinput.input():
a, b = map(int, line.split())
g = gcd(a, b)
lcm = a * b // g
print(g, lcm)
|
N=int(input())
A=list(map(int,input().split()))
p=round(sum(A)/N)
print(sum(map(lambda x: (x-p)**2, A)))
| 0 | null | 32,666,994,388,380 | 5 | 213 |
def print_residence(residence):
for i in range(4):
for j in range(3):
print " " +" ".join(map(str, residence[i][j]))
if i != 3:
print "####################"
n = int(raw_input())
residence = [[[0] * 10 for i in range(3)] for j in range(4)]
#print_residence(residence)
for i in range(n):
info = map(int, raw_input().split())
#print info
#print residence
residence[info[0]-1][info[1]-1][info[2]-1] += info[3]
#print residence
print_residence(residence)
|
'''
いちばん簡単なのは建物とフロアごとにリスト作って、足し引き
'''
#部屋、フロア、建物をクラスで定義。まあ、クラスにしなくてもいいんだけど
a = int(input())
n = 10
m = 3
o = 4
h = [
[
[0 for i in range(n)]
for j in range(m)]
for k in range(o)]
#w, x, y, z = 3, 1, 8, 4
for i in range(a):
w,x,y,z = map(int, input().split())
h[w-1][x-1][y-1] += z
#print(h[1][1])
#建物と建物仕切り
def makeFence():
fence = '#' * 20
print(fence)
#部屋を表示する関数
def showRoom(f):
for k in range(len(f)-1):
print(' ' + str(f[k]), end='')
print(' ' + str(f[len(f)-1]))
#フロアを表示する関数
def showFloor(b):
j = 0
while j < len(b):
f = b[j]
showRoom(f)
j += 1
def statusShow(h):
for i in range(len(h)-1):
b = h[i]
showFloor(b)
makeFence()
showFloor(h[len(h)-1])
statusShow(h)
#b = statusShow(h)
#makeFence()
#print(b)
| 1 | 1,092,167,950,134 | null | 55 | 55 |
import sys
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, d=DVSR): return pow(x, d - 2, d)
def DIV(x, y, d=DVSR): return (x * INV(y, d)) % d
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())
N,P=LI()
S=input()
if P == 2 or P == 5:
res = 0
for i in range(N):
if int(S[i])%P == 0:
res += i+1
print(res)
else:
RESTS=[0]*(P+1)
RESTS[0] = 1
POWS=[0]*(N+1)
POWS[0]=1
res = 0
for i in range(N): POWS[i+1] = (POWS[i]*10)%P
cur = 0
for i in range(N):
cur += (int(S[N-1-i])*POWS[i])
cur %= P
res += RESTS[cur]
RESTS[cur] += 1
print(res)
|
n=int (input())
a=list(input().split(" "))
for i in range(0,n):
print(a[0][i]+a[1][i],end="")
| 0 | null | 84,891,708,531,652 | 205 | 255 |
def insertion_sort(A,n,g):
cnt = 0
for i in range(g,n):
v = A[i]
j = i - g
while (j>=0)&(A[j]>v):
A[j+g] = A[j]
j = j - g
cnt += 1
A[j+g] = v
return A, cnt
def shell_sort(A,n):
G = []
g = 1
while True:
G.append(g)
g = 3*g+1
if g>n:
break
m = len(G)
G = G[::-1]
cnt = 0
for i in range(m):
A,cnt_tmp = insertion_sort(A,n,G[i])
cnt += cnt_tmp
return G,A,cnt
n = int(input())
A = [int(input()) for i in range(n)]
G,A,cnt = shell_sort(A,n)
print(len(G))
print(*G)
print(cnt)
for i in range(n):
print(A[i])
|
def insertionSort(A, n, g):
cnt = 0
for i in xrange(g, n):
v = A[i]
j = i - g
while (j >= 0) and (A[j] > v):
A[j+g] = A[j]
j = j - g
cnt += 1
A[j+g] = v
return cnt
def shellSort(A, n):
# variables
cnt, m, t = 0, 1, n
# getting m
while (t-1)/3 > 0:
t, m = (t-1)/3, m+1
print m
# creating and printing G
G = [1]
for i in xrange(1,m):
G.append(1+G[i-1]*3)
G = list(reversed(G))
print " ".join( map(str, G) )
# sorting
for i in xrange(0, m):
cnt += insertionSort(A, n, G[i])
return cnt
# MAIN
n = input()
A = [input() for i in xrange(n)]
cnt = shellSort(A, n)
print cnt
for i in xrange(n):
print A[i]
| 1 | 30,827,255,488 | null | 17 | 17 |
import string
print raw_input().translate(string.maketrans("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'))
|
import math
a, b, C = map(float, input().split(' '))
rad = math.radians(C)
c = math.sqrt(a**2+b**2-2*a*b*math.cos(rad))
S = a*b*math.sin(rad)*1/2
L = a+b+c
h = abs(b*math.sin(rad))
print('{:.5f} {:.5f} {:.5f}'.format(S, L, h))
| 0 | null | 839,054,109,428 | 61 | 30 |
a=int(input())
b=0
c=list(map(int,input().split()))
for i in range(a):
for k in range(a):
b=b+c[i]*c[k]
for u in range(a):
b=b-c[u]*c[u]
print(int(b/2))
|
#atcoder template
def main():
import sys
imput = sys.stdin.readline
#文字列入力の時は上記はerrorとなる。
#ここにコード
#input
N, S = map(int, input().split())
A = list(map(int, input().split()))
#output
mod = 998244353
dp = [[0] * ( S+1) for _ in range(N+1)]
#dp[i, j]を、A[0]...A[i]までを使って、Tの空でない部分集合
#{x_1, x_2, ..., x_k}であって、Ax_1 + A_x_2 + ... + A_x_k = jを満たすものの個数とする。
dp[0][0] = 1
#iまででjが作られている時、i+1ではA[i]がどのような値であっても、部分集合としてjは作れる。
#iまででjが作られない時、j-A[i]が作られていれば、A[i]を足せばjは作れる。
for i in range(N):
for j in range(S+1):
dp[i+1][j] += dp[i][j] * 2
dp[i+1][j] %= mod
if j >= A[i]:
dp[i+1][j] += dp[i][j-A[i]]
dp[i+1][j] %= mod
print(dp[N][S] % mod)
#N = 1のときなどcorner caseを確認!
if __name__ == "__main__":
main()
| 0 | null | 92,693,997,065,098 | 292 | 138 |
N = int(input())
A = list(map(int, input().split()))
A.sort()
result = 1
for i in range(N):
result *= A[i]
if result > 10**18:
result = -1
break
print(result)
|
n,m=map(int,input().split())
if(n==m):print("Yes")
else: print("No")
| 0 | null | 49,940,969,981,200 | 134 | 231 |
#!/usr/bin/env python3
import sys
import collections as cl
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def main():
x, y, a, b, c = MI()
p = LI()
q = LI()
r = LI()
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
p_selected = p[:x]
q_selected = q[:y]
ans = [*p_selected, *q_selected]
ans.sort()
i = 0
while i < x + y and i < c and ans[i] < r[i]:
ans[i] = r[i]
i += 1
print(sum(ans))
main()
|
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.insert(0, 10**6)
b.insert(0, 10**6)
xyc = [list(map(int, input().split())) for _ in range(M)]
ans = min(a) + min(b)
for n in xyc:
ans = min(ans, a[n[0]] + b[n[1]] - n[2])
print(ans)
| 0 | null | 49,219,304,094,272 | 188 | 200 |
pages=int(input())
papers=pages/2
res=int(papers)
if pages%2==0:
print(res)
else:
print(res+1)
|
n = int(input())
print(n//2 + (n % 2)*1)
| 1 | 59,110,678,041,468 | null | 206 | 206 |
N = input()
n = int(N[-1])
if n in [2,4,5,7,9]:
print('hon')
elif n == 3:
print('bon')
else:
print('pon')
|
N = input()[-1]
if N == "3":
print("bon")
elif N in {"2", "4", "5", "7", "9"}:
print("hon")
else:
print("pon")
| 1 | 19,178,001,419,570 | null | 142 | 142 |
name=input()
len_n=len(name)
name2=input()
len_n2=len(name2)
if name==name2[:-1] and len_n+1==len_n2:
print("Yes")
else:
print("No")
|
import sys
import copy
a = [int(c) for c in input().split()]
N=a[0]
K=a[1]
#まずK*10*i<Nとなる最大のiを探す
while True:
i = 0
while K*10**(i+1)<N:
i+=1
N = abs(N-K*10**i)
if K*10 >= N:
break
Nmin = 10**18
while True:
N = abs(N-K)
if Nmin>N:
Nmin=N
else:
print(Nmin)
sys.exit(0)
| 0 | null | 30,416,963,481,870 | 147 | 180 |
N = int(input())
A = tuple(map(int, input().split()))
L = [0] * N
for i in range(N):
L[A[i]-1] = i + 1
print(*L)
|
import sys
input = sys.stdin.readline
a, b = input()[:-1].split()
print(min(''.join(a for i in range(int(b))), ''.join(b for i in range(int(a)))))
| 0 | null | 132,521,485,044,660 | 299 | 232 |
N, K, S = map(int, input().split())
a = [str(S)] * K
if S == 10**9:
b = [str(1)] * (N-K)
else:
b = [str(S+1)] * (N-K)
ans = a + b
print(*ans)
|
N,K,S=[int(x) for x in input().rstrip().split()]
ans=[]
if S==10**9:
for i in range(N):
if i+1<=K:
ans.append(S)
else:
ans.append(1)
else:
for i in range(N):
if i+1<=K:
ans.append(S)
else:
ans.append(S+1)
print(*ans)
| 1 | 90,949,144,915,918 | null | 238 | 238 |
n, k, c = map(int, input().split())
s = input()
l = [0 for i in range(k+1)]
r = [0 for i in range(k+1)]
cnt = 0
kaime = 1
for i in range(n):
if kaime > k: break
if cnt > 0:
cnt -= 1
else:
if s[i] == 'o':
l[kaime] = i
kaime += 1
cnt = c
cnt = 0
kaime = k
for j in range(n):
i = n-1 - j
if kaime < 1: break
if cnt > 0:
cnt -= 1
else:
if s[i] == 'o':
r[kaime] = i
kaime -= 1
cnt = c
for i in range(1, k+1):
if l[i] == r[i]:
print(l[i]+1)
|
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())
N,K,S = MI()
if S == 10**9:
ANS = [10**9]*K + [1]*(N-K)
else:
ANS = [S]*K + [10**9]*(N-K)
print(*ANS)
| 0 | null | 65,575,007,826,390 | 182 | 238 |
n,d=map(int,input().split())
ans=0
for _ in range(n):
x,y=map(int,input().split())
dist=x**2+y**2
dist=dist**(1/2)
if dist<=d:
ans+=1
print(ans)
|
n = int(input())
p = [input().split() for i in range(n)]
x = input()
ans = 0
f = False
for l in p:
if f:
ans+=int(l[1])
if l[0]==x:
f = True
print(ans)
| 0 | null | 51,331,987,738,450 | 96 | 243 |
s = list(input())
q = int(input())
rvs = []
i = 0
j = 0
p = []
order = []
for i in range(q):
order.append(input().split())
if order[i][0] == "replace":
p = []
p = list(order[i][3])
for j in range(int(order[i][1]), int(order[i][2]) + 1):
s[j] = p[j - int(order[i][1])]
elif order[i][0] == "reverse":
ss = "".join(s[int(order[i][1]):int(order[i][2]) + 1])
rvs = list(ss)
rvs.reverse()
for j in range(int(order[i][1]), int(order[i][2]) + 1):
s[j] = rvs[j - int(order[i][1])]
# temp = s[int(order[i][1])]
# s[int(order[i][1])] = s[int(order[i][2])]
# s[int(order[i][2])] = temp
elif order[i][0] == "print":
ss = "".join(s)
print("%s" % ss[int(order[i][1]):int(order[i][2]) + 1])
|
import sys
heights = [int(i) for i in sys.stdin.read().split()]
heights.sort(reverse=True)
print("\n".join(map(str, heights[:3])))
| 0 | null | 1,023,597,711,000 | 68 | 2 |
n, m = map(int, input().split())
a = sorted(list(map(int, input().split())), reverse=True)
s = [0]
for ai in a:
s.append(ai + s[-1])
def count(x, accum=False):
ret = 0
for ai in a:
lo, hi = -1, n
while hi - lo > 1:
mid = (lo + hi) // 2
if ai + a[mid] >= x:
lo = mid
else:
hi = mid
ret += ai * hi + s[hi] if accum else hi
return ret
lo, hi = 0, 1000000000
while hi - lo > 1:
mid = (lo + hi) // 2
if count(mid) >= m:
lo = mid
else:
hi = mid
print(count(lo, accum=True) - (count(lo) - m) * lo)
|
import sys
import bisect
import itertools
def solve():
readline = sys.stdin.buffer.readline
mod = 10 ** 9 + 7
n, m = list(map(int, readline().split()))
a = list(map(int, readline().split()))
a.sort()
cor_v = -1
inc_v = a[-1] * 2 + 1
while - cor_v + inc_v > 1:
bin_v = (cor_v + inc_v) // 2
cost = 0
#条件を満たすcostを全検索
p = n
for v in a:
p = bisect.bisect_left(a, bin_v - v, 0, p)
cost += n - p
if cost > m:
break
#costが制約を満たすか
if cost >= m:
cor_v = bin_v
else:
inc_v = bin_v
acm = [0] + list(itertools.accumulate(a))
c = 0
t = 0
for v in a:
p = bisect.bisect_left(a, cor_v - v)
c += n - p
t += acm[-1] - acm[p] + v * (n - p)
print(t - (c - m) * cor_v)
if __name__ == '__main__':
solve()
| 1 | 108,531,210,177,208 | null | 252 | 252 |
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import itertools
import math
import sys
INF = float('inf')
def solve(K: int, S: str):
return S[:K] + ['...', ''][len(S) <= K]
def main():
sys.setrecursionlimit(10 ** 6)
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
K = int(next(tokens)) # type: int
S = next(tokens) # type: str
print(solve(K, S))
if __name__ == '__main__':
main()
|
# -*- coding: utf-8 -*-
def main():
K = int(input())
S = input()
if len(S) <= K:
ans = S
else:
ans = S[:K] + '...'
print(ans)
if __name__ == "__main__":
main()
| 1 | 19,611,804,552,800 | null | 143 | 143 |
#!/usr/bin/env python3
x, y = [int(x) for x in input().split()]
p = [300000, 200000, 100000]
if x == 1 and y == 1:
print(1000000)
elif x <= 3 and y <= 3:
print(p[x - 1] + p[y - 1])
elif x <= 3:
print(p[x - 1])
elif y <= 3:
print(p[y - 1])
else:
print(0)
|
s = list(input())
q = int(input())
rvs = []
i = 0
j = 0
p = []
order = []
for i in range(q):
order.append(input().split())
if order[i][0] == "replace":
p = []
p = list(order[i][3])
for j in range(int(order[i][1]), int(order[i][2]) + 1):
s[j] = p[j - int(order[i][1])]
elif order[i][0] == "reverse":
ss = "".join(s[int(order[i][1]):int(order[i][2]) + 1])
rvs = list(ss)
rvs.reverse()
for j in range(int(order[i][1]), int(order[i][2]) + 1):
s[j] = rvs[j - int(order[i][1])]
# temp = s[int(order[i][1])]
# s[int(order[i][1])] = s[int(order[i][2])]
# s[int(order[i][2])] = temp
elif order[i][0] == "print":
ss = "".join(s)
print("%s" % ss[int(order[i][1]):int(order[i][2]) + 1])
| 0 | null | 71,019,236,685,970 | 275 | 68 |
from operator import mul
from functools import reduce
def comb(n, r):
if n<r:
return 0
r = min(r, n - r)
numer = reduce(mul, range(n, n - r, -1), 1)
denom = reduce(mul, range(1, r + 1), 1)
return numer // denom
N,M=map(int,input().split())
# odd+odd
odd_odd = comb(M,2)
# even+even
even_even = comb(N,2)
print(odd_odd+even_even)
|
n,m = map(int,input().split())
even = n * (n-1) // 2
odd = m * (m-1) // 2
print(even + odd)
| 1 | 45,672,443,238,660 | null | 189 | 189 |
st= input().split()
s=st[0]
t=st[1]
print(t+s)
|
strs = list(input().split())
print(strs[1]+strs[0])
| 1 | 102,970,654,751,916 | null | 248 | 248 |
a = []
for i in range(3):
a.extend(list(map(int,input().split())))
n = int(input())
b = []
cnt=[]
pattern=[[0,1,2],[3,4,5],[6,7,8],[0,3,6],[1,4,7],[2,5,8],[0,4,8],[2,4,6]]
for i in range(n):
b.append(int(input()))
for j , x in enumerate(a):
if x == b[i]:
cnt.append(j)
for q,w,e in pattern:
if q in cnt and w in cnt and e in cnt:
print('Yes')
break
else:
print('No')
|
a=[]
for i in range(3):
da=list(map(int,input().split()))
for j in da:
a.append(j)
n=int(input())
for i in range (n):
b=int(input())
for j in range(len(a)):
if a[j] == b:
a[j]=0
for i in range (3):
if a[i] == a[i+3] and a[i+3]==a[i+6]:
print('Yes')
exit()
for i in range(3):
if a[3*i]==a[3*i+1] and a[3*i]==a[3*i+2]:
print('Yes')
exit()
if a[0]==a[4] and a[0]==a[8]:
print('Yes')
exit()
if a[2]==a[4] and a[2]==a[6]:
print('Yes')
exit()
print('No')
| 1 | 59,818,786,100,730 | null | 207 | 207 |
#import numpy as np
#import math
#from decimal import *
#from numba import njit
#@njit
def main():
N = int(input())
s = set()
for _ in range(N):
s.add(input())
print(len(s))
main()
|
import sys
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().split())
inl = lambda: list(map(int, input().split()))
seen = set()
t = ini()
for _ in range(t):
s = ins()
seen.add(s)
print(len(seen))
| 1 | 30,334,977,697,274 | null | 165 | 165 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.