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
|
---|---|---|---|---|---|---|
def main():
""""ここに今までのコード"""
N, K = map(int, input().split())
dice_list = list(map(int, input().split()))
max, s = 0, 0
for i in range(K):
s += (dice_list[i] + 1) / 2
max = s
for i in range(N-K):
s -= (dice_list[i] + 1) / 2
s += (dice_list[i+K] + 1) / 2
if s > max:
max = s
print(max)
if __name__ == '__main__':
main() | N, K = map(int, input().split())
P = list(map(int, input().split()))
S = [0]
sum_ = 0
for i, p in enumerate(P):
sum_ += p
S.append(sum_)
max_sum = 0
for i in range(N-K+1):
max_sum = max(max_sum, S[i+K] - S[i])
res = (max_sum + K) / 2
print(res) | 1 | 74,946,004,405,860 | null | 223 | 223 |
#coding:utf-8
while True:
try:
a, b = map(int, raw_input(). split())
x = a * b
while True:
c = a % b
a = b
b = c
if b == 0:
break
x = x / a
print("%d %d" % (a, x))
except:
break | def ncr(n, r):
num, den = 1, 1
if n - r < r:
r = n - r
for i in range(1, r + 1):
num *= n - i + 1
num %= MOD
den *= i
den %= MOD
return num * pow(den, MOD - 2, MOD) % MOD
MOD = 10 ** 9 + 7
X, Y = map(int, input().split())
Z = X + Y
if Z % 3 or Y > 2 * X or Y < X // 2:
print(0)
else:
print(ncr(Z // 3, X - Z // 3))
| 0 | null | 75,231,923,247,042 | 5 | 281 |
import sys
for i, x in enumerate(map(int, sys.stdin)):
if not x: break
print("Case {0}: {1}".format(i + 1, x)) | # C - Sum of product of pairs
from itertools import accumulate
def main():
N, *A = map(int, open(0).read().split())
rev_cumsum = list(accumulate(reversed(A[1:])))[::-1]
MOD = 10 ** 9 + 7
res = sum(a * c for a, c in zip(A[:-1], rev_cumsum)) % MOD
print(res)
if __name__ == "__main__":
main()
| 0 | null | 2,116,615,840,420 | 42 | 83 |
from collections import deque
N = int(input())
def dfs(str):
if len(str) == N:
print(*str, sep="")
return
M = max(str)
for i in range(ord(M) - ord("a") + 2):
char = alpha[i]
str.append(char)
dfs(str)
str.pop()
alpha = 'abcdefghijklmnopqrstuvwxyz'
s = deque(["a"])
dfs(s)
| str = input()
for char in str:
if char.islower():
print(char.upper(), end='')
else:
print(char.lower(), end='')
print(""); | 0 | null | 27,105,915,709,928 | 198 | 61 |
X,K,D = map(int,input().split())
ans = 0
if X == 0:
if K % 2 == 0:
ans = 0
else:
ans = D
if X > 0:
if K*D <= X:
ans = X - K*D
else:
n = X // D
if X % D != 0:
n += 1
if (K - n) % 2 == 0:
ans = abs(X-D*n)
else:
ans = abs(X-D*(n-1))
if X < 0:
if K*D + X <= 0:
ans = abs(K*D+X)
else:
n = -X // D
if -X % D != 0:
n += 1
if (K-n) % 2 == 0:
ans = abs(X+n*D)
else:
ans = abs(X+(n-1)*D)
print(ans) | from itertools import product
H, W, K = map(int, input().split())
grid = ""
for _ in range(H):
grid += input()
ans = 10000
for Hcut in product((0, 1), repeat = H-1):
Gr_num = sum(Hcut) + 1
old = [0]*Gr_num
cnt = 0
for i in range(W):
#縦一列のchocoを見る
choco = grid[i::W]
new = [0]*Gr_num
gr = 0
for j in range(H):
new[gr] += int(choco[j])
if j < H-1:
if Hcut[j] == 1:
gr += 1
#そもそも一列でオーバーしてたら詰み。
if max(new) > K:
cnt += 10000
break
#新しい一列を追加しても大丈夫か確認
check = [old[gr] + new[gr] for gr in range(Gr_num)]
if max(check) > K:
old = new[:]
cnt += 1
else:
old = check[:]
ans = min(ans, cnt+sum(Hcut))
print(ans) | 0 | null | 26,808,456,748,932 | 92 | 193 |
import sys
input = sys.stdin.readline
n = int(input())
A = tuple(int(x) for x in input().split())
_ = int(input())
M = tuple(int(x) for x in input().split())
S = set()
def Check(i, s):
if i == n:
S.add(s)
return
Check(i + 1, s + A[i])
Check(i + 1, s)
Check(0, 0)
for m in M:
if m in S:
print('yes')
else:
print('no')
| n = int(input())
info = []
for i in range(n):
b, f, r, v = input().split()
b = int(b)
f = int(f)
r = int(r)
v = int(v)
if info == []:
info.append([b, f, r, v])
else:
for x in info:
if b == x[0] and f == x[1] and r == x[2]:
x[3] += v
isAdded = True
break
else:
isAdded = False
if isAdded == False:
info.append([b, f, r, v])
for building in range(4):
for floor in range(3):
for room in range(10):
print(" ", end = '')
arePeople = False
for y in info:
if building + 1 == y[0] and floor + 1 == y[1] and room + 1 == y[2]:
print(y[3], end = '')
arePeople = True
if arePeople == False:
print("0", end = '')
print('')
if building < 3:
print("####################") | 0 | null | 612,913,959,580 | 25 | 55 |
k=int(input())
s=input()
l=len(s)
if l<=k:
print(s)
else:
s=list(s)
t=[]
for i in range(k):
t.append(s[i])
t.append('...')
print(''.join(t))
| k=int(input())
s=input()
if len(s)<=k:
print(s)
else:
for i in range(k):
print(s[i],end="")
print("...",end="") | 1 | 19,687,474,396,690 | null | 143 | 143 |
# ABC170
n = int(input())
a = list(map(int, input().split()))
a.sort()
a_max = max(a)
dp = [True for _ in range(a_max+1)]
ans = 0
for i in range(n):
if dp[a[i]]:
for j in range(0, a_max+1, a[i]):
dp[j] = False
if i > 0:
if a[i] == a[i-1]:
continue
if i < n-1:
if a[i] == a[i+1]:
continue
ans += 1
print(ans)
| import sys
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())
def solve():
m = a[-1]+1
ava = [0]*m
for rep in a:
ava[rep] += 1
if ava[rep]==1:
for item in range(2*rep,m,rep):
ava[item] += 2
print(ava.count(1))
return
if __name__=='__main__':
n = I()
a = list(IL())
a.sort()
solve() | 1 | 14,413,916,755,040 | null | 129 | 129 |
n = int(input())
x = input()
f = [-1] * (n+10)
f[0] = 0
for i in range(1, n+10):
# python bitcount で見つけたこれを参考に https://ameblo.jp/316228/entry-10518720149.html
f[i] = f[i % bin(i).count('1')] + 1
init_bitcount = x.count('1')
# Xを init_bitcount+1とinit_bitcount-1で割った余り
x_mod_01 = 0
for digit in x:
x_mod_01 *= 2
if digit == '1':
x_mod_01 += 1
x_mod_01 %= (init_bitcount+1)
if init_bitcount != 1:
x_mod_10 = 0
for digit in x:
x_mod_10 *= 2
if digit == '1':
x_mod_10 += 1
x_mod_10 %= (init_bitcount-1)
# print(x_mod_01, x_mod_10, init_bitcount)
power_mod_01 = [-1] * (n+10)
power_mod_01[0] = 1
for i in range(1, n+10):
power_mod_01[i] = power_mod_01[i-1] * 2 % (init_bitcount + 1)
if init_bitcount != 1:
power_mod_10 = [-1] * (n+10)
power_mod_10[0] = 1
for i in range(1, n+10):
power_mod_10[i] = power_mod_10[i-1] * 2 % (init_bitcount - 1)
for i in range(n):
if x[i] == '0':
# 0→1
first_residue = (x_mod_01 + power_mod_01[n - i - 1]) % (init_bitcount+1)
print(f[first_residue] + 1)
else:
if init_bitcount == 1:
# 立っているビットの数は0桁、つまりX_i = 0なのでf(X_i) = 0
print(0)
continue
# 1→0
first_residue = (x_mod_10 - power_mod_10[n - i - 1]) % (init_bitcount-1)
print(f[first_residue] + 1)
# https://twitter.com/kyopro_friends/status/1281949470100353024
# https://atcoder.jp/contests/aising2020/editorial 公式
# 1回の操作で桁数以下に落ちることに注意すると、操作の繰り返しで急速に値が小さくなり、少ない回数で0に到着する。
# したがってfの表を作るのは今回不要。愚直にやってもできるので。初回の高速化だけが必要。
| from itertools import product
from collections import deque
class ZeroOneBFS:
def __init__(self, N):
self.N = N # #vertices
self.E = [[] for _ in range(N)]
def add_edge(self, init, end, weight, undirected=False):
assert weight in [0, 1]
self.E[init].append((end, weight))
if undirected: self.E[end].append((init, weight))
def distance(self, s):
INF = float('inf')
E, N = self.E, self.N
dist = [INF] * N # the distance of each vertex from s
prev = [-1] * N # the previous vertex of each vertex on a shortest path from s
dist[s] = 0
dq = deque([(0, s)]) # (dist, vertex)
n_visited = 0 # #(visited vertices)
while dq:
d, v = dq.popleft()
if dist[v] < d: continue # (s,v)-shortest path is already calculated
for u, c in E[v]:
temp = d + c
if dist[u] > temp:
dist[u] = temp; prev[u] = v
if c == 0: dq.appendleft((temp, u))
else: dq.append((temp, u))
n_visited += 1
if n_visited == N: break
self.dist, self.prev = dist, prev
return dist
def shortest_path(self, t):
P = []
prev = self.prev
while True:
P.append(t)
t = prev[t]
if t == -1: break
return P[::-1]
H, W = map(int, input().split())
zobfs = ZeroOneBFS(H * W)
def vtx(i, j): return i*W + j
def coord(n): return divmod(n, W)
grid = [input() for _ in range(H)] # |string| = W
E = [[] for _ in range(H * W)]
ans = 0 if grid[0][0] == '.' else 1
for i, j in product(range(H), range(W)):
v = vtx(i, j)
check = [vtx(i+dx, j+dy) for dx, dy in [(1, 0), (0, 1)] if i+dx <= H-1 and j+dy <= W-1]
for u in check:
x, y = coord(u)
if grid[i][j] == '.' and grid[x][y] == '#':
zobfs.add_edge(v, u, 1)
else:
zobfs.add_edge(v, u, 0)
dist = zobfs.distance(0)
ans += dist[vtx(H-1, W-1)]
print(ans) | 0 | null | 28,697,619,184,532 | 107 | 194 |
from collections import defaultdict
import itertools
N = int(input())
L = list(map(int, input().split()))
dic = defaultdict(int)
for num in L:
dic[num] += 1
set_L = set(L)
comb = list(itertools.combinations(set_L, 3))
ans = 0
for a,b,c in comb:
if a+b <= c or b+c<=a or c+a <= b: continue
ans += dic[a] * dic[b] * dic[c]
print(ans)
| n = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
ans = A[0]
if n%2 == 0:
ans += sum(A[1:n//2])*2
else:
ans += sum(A[1:n//2])*2 + A[n//2]
print(ans) | 0 | null | 7,107,979,160,272 | 91 | 111 |
# -*- coding: utf-8 -*-
import sys
from math import ceil
for line in sys.stdin.readlines():
List = map(int, line.strip().split())
n = List[0]
yen = 100000
for i in xrange(n):
yen *= 1.05
yen = int(ceil(yen/1000)) * 1000
print yen | #!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import collections
import itertools
import math
import sys
INF = float('inf')
YES = "Yes" # type: str
NO = "No" # type: str
def solve(N: int, M: int, A: "List[int]"):
t = sum(A)/4/M
return [YES, NO][len([a for a in A if a >= t]) < M]
def main():
sys.setrecursionlimit(10 ** 6)
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
M = int(next(tokens)) # type: int
A = [int(next(tokens)) for _ in range(N)] # type: "List[int]"
print(f'{solve(N, M, A)}')
if __name__ == '__main__':
main()
| 0 | null | 19,340,084,127,428 | 6 | 179 |
h,w=map(int,input().split())
field=[list(input()) for i in range(h)]
ans=[[0 for i in range(w)]for j in range(h)]
if field[0][0]=='#':
ans[0][0]=1
def black(i,j,f):
if f==1:
if field[i][j]=='#' and field[i-1][j]=='.':
return 1
else:
return 0
else:
if field[i][j]=='#' and field[i][j-1]=='.':
return 1
else:
return 0
for i in range(h):
for j in range(w):
if i==0 and j==0:
continue
elif i==0:
ans[i][j]=ans[i][j-1]+black(i,j,2)
elif j==0:
ans[i][j]=ans[i-1][j]+black(i,j,1)
else:
ans[i][j]=min(ans[i-1][j]+black(i,j,1),ans[i][j-1]+black(i,j,2))
print(ans[-1][-1]) | def main():
# a,b,k = map(int,input().split())
# n,k = map(int,input().split())
s = int(input())
# a = list(map(int,input().split()))
# rsp = list(str(input()))
# l = [list(map(int, input().split())) for _ in range(n-1)]
# s = list(s)
print(int(s**2))
if __name__ == '__main__':
main() | 0 | null | 97,166,319,201,732 | 194 | 278 |
k=int(input())
count=1
num=7
for _ in range(k):
if num%k == 0:
print(count)
break
else:
count += 1
num = (num % k)*10 + 7
else:
print(-1) |
K = int(input())
if K % 2 == 0:
print(-1)
else:
seen = set()
ans = 1
num = 7
while ans <= K:
mod = num % K
if mod in seen:
ans = -1
break
else:
seen.add(mod)
if mod == 0:
break
else:
num = mod * 10 + 7
ans += 1
print(ans)
| 1 | 6,169,438,649,842 | null | 97 | 97 |
n=int(input())
m=1000000007
print(((pow(10,n,m)-2*pow(9,n,m)+pow(8,n,m))+m)%m)
| def gcd(a, b):
c = max([a, b])
d = min([a, b])
if c % d == 0:
return d
else:
return gcd(d, c % d)
nums = input().split()
print(gcd(int(nums[0]), int(nums[1])))
| 0 | null | 1,579,125,205,980 | 78 | 11 |
I=raw_input()
O=str()
list_upper="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#list_lower="abcdefghijklmnopqrstuvwxyz"
for i in I:
if i in list_upper:
O+=i.lower()
else:
O+=i.upper()
print O | # -*- coding: utf-8 -*-
import sys
def func2(x):
if not x.isalpha():
return x
else:
if x.isupper():
return x.lower()
else:
return x.upper()
print("".join(map(lambda x:func2(x),sys.stdin.readline().rstrip())))
| 1 | 1,502,191,147,680 | null | 61 | 61 |
while 1:
m,f,r=map(int,input().split());s=m+f
if r<0>s:break
print('F'if m*f<0 or s<30 else'D'if(s<50)*(r<50)else'C'if s<65 else'B'if s<80 else'A')
| while True:
try:
m,f,r = map(int,raw_input().split())
if all(k == -1 for k in [m,f,r]):
break
except EOFError:
break
if m == -1 or f == -1:
print 'F'
elif m + f >= 80:
print 'A'
elif 65 <= m + f <80:
print 'B'
elif 50 <= m + f < 65:
print 'C'
elif 30 <= m + f < 50:
if r >= 50:
print 'C'
else:
print 'D'
elif m + f < 30:
print 'F' | 1 | 1,201,568,634,848 | null | 57 | 57 |
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import itertools
import random
from decimal import *
input = sys.stdin.readline
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
def inputStr(): return input()[:-1]
inf = float('inf')
mod = 1000000007
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
def main():
D = inputInt()
C = inputList()
S = []
for i in range(D):
s = inputList()
S.append(s)
ans1 = []
ans2 = []
for i in range(D):
bestSco1 = 0
bestSco2 = 0
bestI1 = 1
bestI2 = 1
for j,val in enumerate(S[i]):
if j == 0:
tmpAns = ans1 + [j+1]
tmpSco = findScore(tmpAns, S, C)
if bestSco1 < tmpSco:
bestSco2 = bestSco1
bestI2 = bestI1
bestSco1 = tmpSco
bestI1 = j+1
else:
tmpAns1 = ans1 + [j+1]
tmpAns2 = ans2 + [j+1]
tmpSco1 = findScore(tmpAns1, S, C)
tmpSco2 = findScore(tmpAns2, S, C)
if bestSco1 < tmpSco1:
bestSco2 = bestSco1
bestI2 = bestI1
bestSco1 = tmpSco1
bestI1 = j+1
if bestSco1 < tmpSco2:
bestSco2 = bestSco1
bestI2 = bestI1
bestSco1 = tmpSco2
bestI1 = j+1
ans1.append(bestI1)
ans2.append(bestI2)
for i in ans1:
print(i)
def findScore(ans, S, C):
scezhu = [inf for i in range(26)]
sco = 0
for i,val in enumerate(ans):
tmp = S[i][val-1]
scezhu[val-1] = i
mins = 0
for j,vol in enumerate(C):
if scezhu[j] == inf:
mins = mins + (vol * (i+1))
else:
mins = mins + (vol * ((i+1)-(scezhu[j]+1)))
tmp -= mins
sco += tmp
return sco
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
if __name__ == "__main__":
main()
| import copy
import random
import sys
import time
from collections import deque
t1 = time.time()
readline = sys.stdin.buffer.readline
global NN
NN = 26
def evaluate(D, C, S, out, k):
score = 0
last = [0 for _ in range(NN)]
for d in range(len(out)):
last[out[d]] = d + 1
for i in range(NN):
score -= (d + 1 - last[i]) * C[i]
score += S[d][out[d]]
for d in range(len(out), min(D, len(out) + k)):
for i in range(NN):
score -= (d + 1 - last[i]) * C[i]
return score
def compute_score(D, C, S, out):
score = 0
last = [0 for _ in range(NN)]
for d in range(len(out)):
p = out[d]
last[p] = d + 1
last[out[d]] = d + 1
for i in range(NN):
score -= (d + 1 - last[i]) * C[i]
score += S[d][out[d]]
return score
def solve(D, C, S, k):
out = deque()
for _ in range(D):
max_score = -10 ** 8
best_i = 0
for i in range(NN):
out.append(i)
score = evaluate(D, C, S, out, k)
if max_score < score:
max_score = score
best_i = i
out.pop()
out.append(best_i)
return out, score
# 1箇所ランダムに変える
def random_change(D, C, S, out, score):
new_out = copy.deepcopy(out)
d = random.randrange(0, D)
new_out[d] = random.randrange(0, NN)
new_score = compute_score(D, C, S, new_out)
if new_score > score:
score = new_score
out = new_out
return out, score
def random_change0(D, C, S, out, score):
new_out = copy.deepcopy(out)
d = random.randrange(0, 10)
new_out[d] = random.randrange(0, NN)
new_score = compute_score(D, C, S, new_out)
if new_score > score:
score = new_score
out = new_out
return out, score
# N箇所ランダムに変える
def random_changeN(D, C, S, out, score, N):
new_out = copy.deepcopy(out)
for _ in range(N):
d = random.randrange(0, D)
new_out[d] = random.randrange(0, NN)
new_score = compute_score(D, C, S, new_out)
if new_score > score:
score = new_score
out = new_out
return out, score
# 2つswap
def random_swap2(D, C, S, out, score):
d1 = random.randrange(0, D - 1)
d2 = random.randrange(d1 + 1, min(d1 + 16, D))
new_out = copy.deepcopy(out)
new_out[d1], new_out[d2] = out[d2], out[d1]
new_score = compute_score(D, C, S, out)
if new_score > score:
score = new_score
out = new_out
return out, score
# 3つswap
def random_swap3(D, C, S, out, score):
d1 = random.randrange(0, D - 1)
d2 = random.randrange(d1 + 1, min(d1 + 8, D))
d3 = random.randrange(max(d1 - 8, 0), d1 + 1)
new_out = copy.deepcopy(out)
new_out[d1], new_out[d2], new_out[d3] = out[d2], out[d3], out[d1]
new_score = compute_score(D, C, S, out)
if new_score > score:
score = new_score
out = new_out
return out, score
def random_swap0(D, C, S, out, score):
d1 = random.randrange(0, 6)
d2 = random.randrange(6, 13)
new_out = copy.deepcopy(out)
new_out[d1], new_out[d2] = out[d2], out[d1]
new_score = compute_score(D, C, S, out)
if new_score > score:
score = new_score
out = new_out
return out, score
def main():
D = int(readline())
C = list(map(int, readline().split()))
S = [list(map(int, readline().split())) for _ in range(D)]
# ランダムな初期値
# out = [random.randrange(0, NN) for _ in range(D)]
# 貪欲法で初期値を決める
max_score = -10 ** 8
max_k = 0
for k in range(6):
out, score = solve(D, C, S, k)
if score > max_score:
max_score = score
max_out = out
max_k = k
# # local minimumを避けるため,outを少し変える
out = max_out
score = max_score
out, score = solve(D, C, S, max_k)
out[0] = random.randrange(NN)
for cnt in range(10 ** 10):
out, score = random_changeN(D, C, S, out, score, N=1)
out, score = random_swap3(D, C, S, out, score)
t2 = time.time()
if t2 - t1 > 1.85:
break
ans = [str(i + 1) for i in out]
print("\n".join(ans))
main()
| 1 | 9,669,112,597,426 | null | 113 | 113 |
def bubbleSort( cards ):
n = len( cards )
for i in range( 0, n ):
for j in range( n-1 , i, -1 ):
if int( cards[j][1] ) < int( cards[ j-1 ][1] ):
cards[j], cards[ j-1 ] = cards[ j-1 ], cards[j]
print( " ".join( map( str, cards ) ) )
def selectionSort( cards ):
n = len( cards )
for i in range( 0, n ):
mini = i
for j in range( i , n ):
if int( cards[j][1] ) < int( cards[ mini ][1] ):
mini = j
if mini != i:
cards[i], cards[ mini ] = cards[ mini ], cards[i]
print( " ".join( map( str, cards ) ) )
n = int( raw_input( ) )
cards = raw_input( ).split( " " )
cards2 = list( cards )
bubbleSort( cards )
print( "Stable" )
selectionSort( cards2 )
if cards2 == cards:
print( "Stable" )
else:
print( "Not stable" ) | 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)) | 1 | 24,831,168,798 | null | 16 | 16 |
T1,T2=map(int,input().split())
A1,A2=map(int,input().split())
B1,B2=map(int,input().split())
OU=T1*(A1-B1)
HUKU=T2*(A2-B2)
TOTAL=OU+HUKU
if TOTAL==0:
print("infinity")
elif (OU>0 and TOTAL>0) or (OU<0 and TOTAL<0):
print(0)
elif (OU>0 and TOTAL*(-1)>OU) or (OU<0 and TOTAL*(-1)<OU):
print(1)
else:
K=int(OU/TOTAL)*-1
if (OU%TOTAL)==0:
print(K*2)
else:
print(K*2+1)
| T = [int(t) for t in input().split()]
A = [int(t) for t in input().split()]
B = [int(t) for t in input().split()]
d1 = T[0]*(A[0]-B[0])
d2 = d1 + T[1]*(A[1]-B[1])
if d2 == 0:
ans = "infinity"
elif d1 > 0 and d2 > 0:
ans = 0
elif d1 < 0 and d2 < 0:
ans = 0
else:
d1 = abs(d1)
d2 = abs(d2)
ans = d1 // d2 * 2
if d1%d2 != 0:
ans += 1
print(ans) | 1 | 131,570,447,797,328 | null | 269 | 269 |
####
n = int(input())
memo = [-1]*(n+10)
def fib(i):
if i==0 or i == 1:
return 1
if memo[i] != -1:
return memo[i]
memo[i] = fib(i-1) + fib(i-2)
return memo[i]
print(fib(n))
| count = 0
m = 0
G = []
def insertionSort(A, n, g):
global count
for i in range(g,n):
v = A[i]
j = i - g
while j >= 0 and A[j] > v:
A[j+g] = A[j]
j = j - g
count += 1
A[j+g] = v
def shellSort(A, n):
global count
global m
global G
count = 0
g = 1
while g <= n:
G.append(g)
g = 3*g + 1
G.reverse()
m = len(G)
for g in G:
insertionSort(A, n, g)
A = []
n = int(input())
for _ in range(n):
A.append(int(input()))
shellSort(A,n)
print(m)
print(" ".join(map(str, G)))
print(count)
for a in A:
print(a)
| 0 | null | 14,922,631,598 | 7 | 17 |
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
# d = m - k[i] - k[j]
# if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
return list(map(int,input().split()))
def I():
return int(input())
n = I()
A = readInts()
nya = []
for i in range(n):
nya.append((i+1,A[i]))
nya = sorted(nya,key = lambda x:x[1])
ans = []
for (idx,po) in nya:
ans.append(idx)
print(*ans)
| h,n=list(map(int ,input().split()))
l=list(map(int ,input().split()))
ans=0
count=0
for i in range(0,n):
ans+=l[i]
if(ans==h or ans>h):
count+=1
else:
count+=0
if(count>0):
print("Yes")
else:
print("No") | 0 | null | 129,839,063,162,240 | 299 | 226 |
import math
def fact(n):
ans = 1
for i in range(2, n+1):
ans*= i
return ans
def comb(n, c):
return fact(n)//(fact(n-c)*c)
r = float(input())
print("%.20f"%(2.0*math.pi*r))
| import numpy as np
n = int(input())
cnt = 0
for k in range(1,n+1):
d = n//k
if d == 1:
cnt += (k+n)*(n-k+1)//2
break
cnt += k*d*(d+1)//2
print(cnt) | 0 | null | 21,328,209,008,884 | 167 | 118 |