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
|
---|---|---|---|---|---|---|
n = int(input())
str1 = ""
while n > 0:
n -= 1
m = n % 26
n = n // 26
str1 += chr(m+ord("a"))
ans = str1[::-1]
print(ans) | n=int(input())
alphabet="abcdefghijklmnopqrstuvwxyz"
def get_keta(n):
i=1
check=26
while True:
if n<=check:
return i
check=check*26+26
i+=1
def get_new_n(n, keta):
new_n = n
for i in range(1, keta):
new_n -= 26 ** i
return new_n
keta=get_keta(n)
n=get_new_n(n,keta)-1
ans=[]
for i in range(keta):
ans.append(alphabet[n%26])
n-=n%26
n=n//26
print("".join(ans)[::-1])
| 1 | 11,964,002,660,892 | null | 121 | 121 |
n, m = map(int, input().split())
mat_A = []
vec_b = []
for j in range(n):
mat_A.append(list(map(int, input().split())))
for i in range(m):
vec_b.append(int(input()))
for j in range(n):
tmp = 0
for i in range(m):
tmp += mat_A[j][i] * vec_b[i]
print(tmp) | while True:
H, W = map(int, input().split())
if not(H or W):
break
print('#' * W)
for i in range(H-2):
print('#' + '.' * (W - 2) + '#')
print('#' * W, end='\n\n') | 0 | null | 999,361,536,600 | 56 | 50 |
n = int(input())
def cal(i):
s = (i + i*(n//i))*(n//i)*0.5
return s
ans = 0
for i in range(1, n+1):
ans += cal(i)
print(int(ans))
| from collections import deque
LIM=200004
L=[0]*LIM
def bin_sum(Y):
S=bin(Y)[2:]
count=0
for i in range(len(S)):
count+=int(S[i])
return count
def bin_sum2(Y):
count=0
for i in range(len(Y)):
count+=int(Y[i])
return count
for i in range(1,LIM):
L[i]+=bin_sum(i)
def pop_num(N,b,L):
if N==0:
return 0
v=N%b
return pop_num(v,L[v],L)+1
M=[0]*200005
for i in range(1,200004):
M[i]+=pop_num(i,L[i],L)
X=int(input())
Y=input()
d=bin_sum2(Y)
e=int(Y,2)%(d+1)
f=int(Y,2)%max(1,(d-1))
O=[1]*(X+2)
P=[1]*(X+2)
q=max(d-1,1)
for i in range(1,X+1):
O[i]=O[i-1]*2%q
P[i]=P[i-1]*2%(d+1)
for i in range(X):
if int(Y[i])==1:
b=max(d-1,1)
flag=max(0,d-1)
g=(f-O[X-1-i]+b)%b
else:
b=d+1
flag=1
g=(e+P[X-1-i])%b
if flag==0:
print(0)
elif g==0:
print(1)
else:
print(M[g]+1) | 0 | null | 9,677,502,468,292 | 118 | 107 |
n,q = map(int,raw_input().split())
task = []
lst = []
a = 0
for i in range(n):
name,time = raw_input().split()
task.append(int(time))
lst.append(name)
while True:
if task[0] > q:
task[0] = task[0] - q
task.append(task.pop(0))
lst.append(lst.pop(0))
a += q
else:
a += task[0]
print lst[0],a
task.pop(0)
lst.pop(0)
if len(lst) == 0:
break | n,m = map(int,input().split())
a = [0]*n
ac =0
wa = 0
for i in range(m):
p,s = map(str,input().split())
p = int(p)
if s == "AC" and a[p-1] !=-1:
ac +=1
wa += a[p-1]
a[p-1] = -1
elif s =="WA" and a[p-1] != -1:
a[p-1] += 1
print(ac,wa) | 0 | null | 46,500,651,645,848 | 19 | 240 |
N = int(input())
A = list(map(int,input().split()))
minm = A[0]
ans = 0
for i in range(1,N):
if A[i] < minm:
ans += minm - A[i]
if A[i] > minm:
minm = A[i]
print(ans) | N = int(input())
A = list(map(int, input().split()))
ans = 0
for i in range(N - 1):
if A[i] > A[i + 1]:
ans += A[i] - A[i + 1]
A[i + 1] = max(A[i], A[i + 1])
print(ans)
| 1 | 4,523,556,348,792 | null | 88 | 88 |
a,b,c,d = map(int, input().split())
z = 'BATTLE'
while z == 'BATTLE':
c -= b
if c <= 0:
z = 'Yes'
break
a -= d
if a <= 0:
z ='No'
break
print(z) | N, M, L = map(int, input().split())
INF = float('inf')
d1 = [[INF]*N for _ in range(N)]
for _ in range(M):
a, b, c = map(int, input().split())
a -= 1
b -= 1
d1[a][b] = c
d1[b][a] = c
for i in range(N):
d1[i][i] = 0
for k in range(N):
for i in range(N):
for j in range(N):
d1[i][j] = min(d1[i][k] + d1[k][j], d1[i][j])
d2 = [[INF]*N for _ in range(N)]
for i in range(N):
for j in range(N):
if i == j:
d2[i][j] = 0
if d1[i][j] <= L and i != j:
d2[i][j] = 1
for k in range(N):
for i in range(N):
for j in range(N):
d2[i][j] = min(d2[i][k] + d2[k][j], d2[i][j])
Q = int(input())
for _ in range(Q):
s, t = map(int, input().split())
s -= 1
t -= 1
if d2[s][t] == INF:
print(-1)
else:
print(d2[s][t]-1)
| 0 | null | 101,507,579,636,440 | 164 | 295 |
K = int(input())
ans = -1
keep = 0
check = 7
for i in range(K):
keep = (keep + check) % K
if keep == 0:
ans = i + 1
break
check = (check * 10) % K
print(ans) | import sys
K=input()
if int(K)%2==0:
print(-1)
sys.exit()
S=int('7'*(len(K)))
ans=len(K)
K=int(K)
for i in range(10**6):
if S%K==0:
print(ans)
break
else:
S=(S*10)%K+7
ans+=1
else:
print(-1) | 1 | 6,035,645,527,428 | null | 97 | 97 |
#!/usr/bin python3
# -*- coding: utf-8 -*-
n = int(input())
print(int(not n))
| x = int(input())
a = 0
b = 0
flg = True
while True:
a += 1
for i in range(a):
if a**5 - i**5 == x:
a = a
b = i
flg = False
break
elif a**5 + i**5 == x:
a = a
b = -i
flg = False
break
if flg == False:
break
a = str(a)
b = str(b)
print(a+' '+b) | 0 | null | 14,139,145,202,852 | 76 | 156 |
import sys
input = sys.stdin.readline
from collections import *
X = int(input())
dp = [False]*(X+1)
dp[0] = True
for i in range(X+1):
for j in range(100, 106):
if i-j>=0:
dp[i] |= dp[i-j]
if dp[X]:
print(1)
else:
print(0) | x=int(input())
if x<100:
print(0)
else:
n=x//100
y=x%100
if y==0:
print(1)
else:
if int((y+4)//5)<=n:
print(1)
else:
print(0) | 1 | 127,267,114,452,280 | null | 266 | 266 |
N,X,Y = (int(x) for x in input().split())
A = [0]*(N)
for i in range(1,N):
for j in range(i+1,N+1):
if j <= X or i >= Y:
A[j-i] += 1
else:
A[min((j-i),(abs(i-X)+abs(j-Y)+1))] += 1
for i in range(1,N):
print(A[i])
| from collections import defaultdict
N, X, Y = map(int, input().split())
cnt_dict = defaultdict(int)
for i in range(1,N):
for j in range(i+1, N+1):
if j<=X or i>=Y:
path = j-i
else:
path = min(j-i, abs(X-i)+abs(j-Y)+1)
cnt_dict[path] += 1
for i in range(1,N):
print(cnt_dict[i]) | 1 | 44,123,099,557,252 | null | 187 | 187 |
N=int(input())
DP=[]
DP.append(1)
DP.append(1)
for i in range(2,N+1):
DP.append(DP[i-1]+DP[i-2])
print(DP[N])
| n=input()
fn_first=1
fn_second=1
if n >= 2:
for x in xrange(n-1):
tmp = fn_first
fn_first = fn_first + fn_second
fn_second = tmp
print fn_first | 1 | 1,622,337,992 | null | 7 | 7 |
#162B
#FizzBuzz Sum
n=int(input())
print(sum(x for x in range(1,n+1) if x%3!=0 and x%5!=0)) | m1, d1 = map(int, input().split())
m2, d2 = map(int, input().split())
print("1" if d1 > d2 else "0") | 0 | null | 79,953,744,390,172 | 173 | 264 |
n, m = map(int, input().split())
s = input()
s = ''.join(reversed(s))
ans = []
index = 0
while index < n:
next_index = -1
for j in range(min(index + m, n), index, -1):
if s[j] == '0':
next_index = j
break
if next_index == -1:
ans = [-1]
break
ans.append(next_index - index)
index = next_index
print(' '.join(list(map(str, list(reversed(ans)))))) | # author: Taichicchi
# created: 12.09.2020 17:49:24
from itertools import permutations
import sys
N = int(input())
P = int("".join(input().split()))
Q = int("".join(input().split()))
perm = permutations([str(i) for i in range(1, N + 1)], N)
ls = []
for i in perm:
ls.append(int("".join(i)))
print(abs(ls.index(P) - ls.index(Q)))
| 0 | null | 119,735,325,701,312 | 274 | 246 |
n,m,l=map(int,input().split())
abc=[list(map(int,input().split())) for _ in [0]*m]
q=int(input())
st=[list(map(int,input().split())) for _ in [0]*q]
inf=10**12
dist=[[inf]*n for _ in [0]*n]
for i in range(n):
dist[i][i]=0
for a,b,c in abc:
dist[a-1][b-1]=c
dist[b-1][a-1]=c
for k in range(n):
for i in range(n):
for j in range(n):
dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j])
inf=10**3
dist2=[[inf]*n for _ in [0]*n]
for i in range(n):
for j in range(n):
if dist[i][j]<=l:
dist2[i][j]=1
for k in range(n):
for i in range(n):
for j in range(n):
dist2[i][j]=min(dist2[i][j],dist2[i][k]+dist2[k][j])
for i in range(n):
for j in range(n):
if dist2[i][j]==inf:
dist2[i][j]=-1
else:
dist2[i][j]-=1
for s,t in st:
print(dist2[s-1][t-1]) | import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N, M, L = lr()
INF = 10 ** 19
dis = [[INF for _ in range(N+1)] for _ in range(N+1)]
for _ in range(M):
a, b, c = lr()
if c > L:
continue
dis[a][b] = c
dis[b][a] = c
for k in range(N+1): # kが中継地点
for i in range(N+1):
for j in range(i+1, N+1):
x = dis[i][k] + dis[k][j]
if x < dis[i][j]:
dis[i][j] = dis[j][i] = x
supply = [[INF] * (N+1) for _ in range(N+1)]
for i in range(N+1):
for j in range(i+1, N+1):
if dis[i][j] <= L:
supply[i][j] = supply[j][i] = 1
for k in range(N+1): # kが中継地点
for i in range(N+1):
for j in range(i+1, N+1):
y = supply[i][k] + supply[k][j]
if y < supply[i][j]:
supply[i][j] = supply[j][i] = y
Q = ir()
for _ in range(Q):
s, t = lr()
if supply[s][t] == INF:
print(-1)
else:
print(supply[s][t] - 1)
# 59 | 1 | 174,300,860,755,040 | null | 295 | 295 |
n = int(input())
num = int(n / 2)
if n % 2 == 1:
num += 1
print(num) | N = int(input())
if N%2 == 0:
print(N//2)
elif N%2 != 0:
print(N//2+1) | 1 | 58,824,240,080,800 | null | 206 | 206 |
N = int(input())
alpha=list('abcdefghijklmnopqrstuvwxyz')
res=['']
for i in range(N):
tmp = []
for j in res:
for k in alpha[:len(set(list(j))) +1]:
tmp.append(j+k)
res = tmp
for i in res:
print(i) | r, c = map(int, input().split())
A = []
for line in range(r):
A.append(list(map(int, input().split())))
[A[i].append(sum(A[i])) for i in range(r)]
trans = []
for i in range(c+1):
trans.append([A[j][i] for j in range(r)])
trans[i].append(sum(trans[i]))
ret = []
for i in range(r+1):
ret.append([trans[j][i] for j in range(c+1)])
print(' '.join(map(str, ret[i]))) | 0 | null | 26,965,772,862,348 | 198 | 59 |
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
n,k=nii()
a=lnii()
a.sort()
mod=10**9+7
MAX_N = n+5
fac = [1,1] + [0]*MAX_N
finv = [1,1] + [0]*MAX_N
inv = [0,1] + [0]*MAX_N
for i in range(2,MAX_N):
fac[i] = fac[i-1] * i % mod
inv[i] = mod - inv[mod % i] * (mod // i) % mod
finv[i] = finv[i-1] * inv[i] % mod
def nCk(n,k):
if n<k:
return 0
if n<0 or k<0:
return 0
return fac[n] * (finv[k] * finv[n-k] % mod) % mod
min_X=0
for i in range(n-k+1):
min_X+=a[i]*nCk(n-i-1,k-1)
min_X%=mod
max_X=0
for i in range(k-1,n):
max_X+=a[i]*nCk(i,k-1)
max_X%=mod
ans=max_X-min_X
ans%=mod
print(ans) | T1,T2=map(int,input().split())
a,b=map(int,input().split())
c,d=map(int,input().split())
e=T1*a
f=T1*c
if e>f:
g=e-f
e=T2*b
f=T2*d
if e>f:
print(0)
else:
h=f-e
if g==h:
print("infinity")
elif g>h:
print(0)
else:
k=h-g
if k>g:
print(1)
elif (g/k)%1!=0:
print(1+(g//k)*2)
else:
print((g//k)*2)
elif e<f:
g=f-e
e=T2*b
f=T2*d
if e<f:
print(0)
else:
h=e-f
if g==h:
print("infinity")
elif g>h:
print(0)
else:
k=h-g
if k>g:
print(1)
elif (g/k)%1!=0:
print(1+(g//k)*2)
else:
print((g//k)*2) | 0 | null | 113,738,634,519,762 | 242 | 269 |
# abc168_a.py
# https://atcoder.jp/contests/abc168/tasks/abc168_a
# A - ∴ (Therefore) /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点: 100点
# 問題文
# いろはちゃんは、人気の日本製ゲーム「ÅtCoder」で遊びたい猫のすぬけ君のために日本語を教えることにしました。
# 日本語で鉛筆を数えるときには、助数詞として数の後ろに「本」がつきます。この助数詞はどんな数につくかで異なる読み方をします。
# 具体的には、999以下の正の整数 N について、「N本」と言うときの「本」の読みは
# Nの 1 の位が 2,4,5,7,9のとき hon
# Nの 1 の位が 0,1,6,8のとき pon
# Nの 1 の位が 3のとき bon
# です。
# Nが与えられるので、「N本」と言うときの「本」の読みを出力してください。
# 制約
# Nは 999以下の正の整数
# 入力
# 入力は以下の形式で標準入力から与えられる。
# N
# 出力
# 答えを出力せよ。
# 入力例 1
# 16
# 出力例 1
# pon
# 16の 1 の位は 6なので、「本」の読みは pon です。
# 入力例 2
# 2
# 出力例 2
# hon
# 入力例 3
# 183
# 出力例 3
# bon
global FLAG_LOG
FLAG_LOG = False
def log(value):
# FLAG_LOG = True
FLAG_LOG = False
if FLAG_LOG:
print(str(value))
def calculation(lines):
# S = lines[0]
N = int(lines[0])
# N, M = list(map(int, lines[0].split()))
# values = list(map(int, lines[1].split()))
# values = list(map(int, lines[2].split()))
# values = list()
# for i in range(N):
# values.append(int(lines[i]))
# valueses = list()
# for i in range(N):
# valueses.append(list(map(int, lines[i+1].split())))
amari = N % 10
result = 'hon'
if amari == 3:
result = 'bon'
elif amari in [0, 1, 6, 8]:
result = 'pon'
return [result]
# 引数を取得
def get_input_lines(lines_count):
lines = list()
for _ in range(lines_count):
lines.append(input())
return lines
# テストデータ
def get_testdata(pattern):
if pattern == 1:
lines_input = ['16']
lines_export = ['pon']
if pattern == 2:
lines_input = ['2']
lines_export = ['hon']
if pattern == 3:
lines_input = ['183']
lines_export = ['bon']
return lines_input, lines_export
# 動作モード判別
def get_mode():
import sys
args = sys.argv
global FLAG_LOG
if len(args) == 1:
mode = 0
FLAG_LOG = False
else:
mode = int(args[1])
FLAG_LOG = True
return mode
# 主処理
def main():
import time
started = time.time()
mode = get_mode()
if mode == 0:
lines_input = get_input_lines(1)
else:
lines_input, lines_export = get_testdata(mode)
lines_result = calculation(lines_input)
for line_result in lines_result:
print(line_result)
# if mode > 0:
# print(f'lines_input=[{lines_input}]')
# print(f'lines_export=[{lines_export}]')
# print(f'lines_result=[{lines_result}]')
# if lines_result == lines_export:
# print('OK')
# else:
# print('NG')
# finished = time.time()
# duration = finished - started
# print(f'duration=[{duration}]')
# 起動処理
if __name__ == '__main__':
main()
| N = input()
N = int(N)
for a in range(0,100):
n = N-10*a
if n <=9:
break;
if n == 2 or n == 4 or n == 5 or n == 7 or n == 9:
print('hon')
elif n == 0 or n == 1 or n == 6 or n == 8:
print('pon')
elif n == 3:
print('bon') | 1 | 19,213,461,383,508 | null | 142 | 142 |
n, k = map(int, input().split())
an = list(map(int, input().split()))
bn = [-1]*(n+1)
now=1
bn[1]=0
for i in range(1, k+1):
# print(bn)
now = an[now-1]
if bn[now] >0:
rp =i-bn[now]
p= (k-i)%rp
for j in range(p):
now = an[now-1]
print(now)
exit(0)
bn[now]=i
print(now) | def main():
n, k = map(int, input().split())
# ダブリング
d = 60
to = [[0 for _ in range(n)]
for _ in range(d)] # to[i][j] : 町jから2**i回ワープした町
to[0] = list(map(int, input().split()))
for i in range(1, d):
for j in range(n):
to[i][j] = to[i - 1][to[i - 1][j] - 1]
v = 1
for i in range(d, -1, -1):
l = 2 ** i # 2**i回ワープする
if l <= k:
v = to[i][v - 1]
k -= l
if k == 0:
break
print(v)
if __name__ == "__main__":
main()
| 1 | 22,860,346,750,304 | null | 150 | 150 |
n = input()
x = input().split()
x_int = [int(i) for i in x]
print('{} {} {}'.format(min(x_int),max(x_int),sum(x_int))) | N = int(input())
list_A = [int(m) for m in input().split()]
for i in list_A:
if i % 2 != 0:
continue
elif not (i % 3 == 0 or i % 5 == 0):
print("DENIED")
exit()
else:
print("APPROVED") | 0 | null | 34,929,546,036,210 | 48 | 217 |
import math
r = input()
print '%.10f %.10f' %(r*r*math.pi , r*2*math.pi) | # coding=utf-8
from math import pi
r = float(raw_input().strip())
print "{0:f} {1:f}".format(pi * r * r, 2 * pi * r) | 1 | 635,629,013,696 | null | 46 | 46 |
num = int(input())
table = list(map(int, input().split()))
count = 0
list.sort(table)
if num == 2:
if table[0] == table[1]:
count += 1
else:
for i in range(1, num-1):
if num == 2:
if table[0] == table[1]:
count += 1
elif table[i] == table[i+1] or table[i-1] == table[i]:
count += 1
else:
continue
if count == 0:
print('YES')
else:
print('NO') | from collections import deque
n,limit = map(int,input().split())
total_time = 0
queue = deque()
for _ in range(n):
p,t = input().split()
queue.append([p,int(t)])
while len(queue) > 0:
head = queue.popleft()
if head[1] <= limit:
total_time += head[1]
print('{} {}'.format(head[0],total_time))
else:
head[1] -= limit
total_time += limit
queue.append(head)
| 0 | null | 37,206,539,129,100 | 222 | 19 |
import sys
def gcd(a, b):
return gcd(b, a % b) if a % b else b
def lcm(a, b):
return a * b / gcd(a, b)
for line in sys.stdin:
data = map(int, line.split())
a, b = data
print "%d %d" % (gcd(a, b), lcm(a, b)) | a, b = map(float, input().split())
a = round(a)
b = round(b*100)
ans = a*b
ans = str(ans)[:-2]
if ans == "":
ans = 0
print(ans) | 0 | null | 8,251,351,525,628 | 5 | 135 |
n = int(input())
mod = 10**9+7
dp = [1]*(n+1)
if n <= 2:
print(0)
exit()
for i in range(3):
dp[i] = 0
for j in range(3, 10):
if j <= n:
dp[j] = 1
for i in range(3, n+1):
for j in range(3, n):
if i+j <= n:
dp[i+j] += dp[i]
dp[i+j] %= mod
print(dp[-1])
| s = int(input())
dp = [0]*(2001)
dp[3] = 1
mod = 10**9+7
for i in range(4,s+1):
dp[i] = (dp[i-1] + dp[i-3]) % mod
print(dp[s]) | 1 | 3,266,070,114,304 | null | 79 | 79 |
while True:
n,x = map(int, input().split())
if n==0 and x==0:
break
ans=0
for i in range(1,n+1):
for j in range(i+1,n+1):
for k in range(j+1,n+1):
if i+j+k==x:
ans=ans+1
print(ans)
| def main():
while True:
n, x = map(int, input().split())
if n == x == 0:
break
number = 0
for i in range(n):
j = i + 1
if x - j > n*2 - 1:
continue
elif x - j <= j:
break
else:
for k in range(x - j):
m = k + 1
if k < j:
continue
elif (x - j - m) > m and x - j - m <= n:
number += 1
print(number)
return
if __name__ == '__main__':
main()
| 1 | 1,302,399,941,390 | null | 58 | 58 |
def run():
s_n = int(input())
S = set(map(int, input().split()))
t_n = int(input())
T = set(map(int, input().split()))
print(len(S&T))
if __name__ == '__main__':
run()
| import math
def koch(n, p1, p2):
if n == 0:
return
s = [(2 * p1[0] + p2[0]) / 3, (2 * p1[1] + p2[1]) / 3]
t = [(p1[0] + 2 * p2[0]) / 3, (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(n - 1, p1, s)
print(s[0], s[1])
koch(n - 1, s, u)
print(u[0], u[1])
koch(n - 1, u, t)
print(t[0], t[1])
koch(n - 1, t, p2)
n = int(input())
p1 = (0, 0)
p2 = (100, 0)
print(p1[0], p1[1])
koch(n, p1, p2)
print(p2[0], p2[1]) | 0 | null | 93,808,264,672 | 22 | 27 |
n, k = map(int, input().split())
A = list(map(int, input().split()))
bottom, top = 0, max(A)
def cut(x):
cnt = 0
for Length in A:
if Length % x == 0:
cnt += Length // x
else:
cnt += Length // x + 1
cnt -= 1
return cnt <= k
while top - bottom > 1:
middle = (top + bottom) // 2
if cut(middle):
top = middle
else:
bottom = middle
print(top) | import math
N, K = map(int, input().split())
A = list(map(float, input().split()))
min_A = 0
max_A = 10**10
while( max_A - min_A > 1):
now = (min_A + max_A) // 2
temp = 0
for i in A:
if i > now:
temp += (i // now)
if temp > K:
min_A = now
else:
max_A = now
print(int(min_A) + 1) | 1 | 6,485,585,984,290 | null | 99 | 99 |
import bisect
n = int(input())
s = list(input())
q = int(input())
pos = [[] for i in range(26)]
alp = "abcdefghijklmnopqrstuvwxyz"
atoi = {}
for i in range(26):
atoi[alp[i]] = i
for i in range(n):
pos[atoi[s[i]]].append(i)
for i in range(q):
a, b, c = input().split()
if a == "1":
b = int(b)-1
if c == s[b]:
continue
index = bisect.bisect_left(pos[atoi[s[b]]], b)
del pos[atoi[s[b]]][index]
bisect.insort_left(pos[atoi[c]], b)
s[b] = c
else:
l, r = int(b)-1, int(c)
ans = 0
for i in range(26):
cnt = bisect.bisect_left(pos[i], r) - bisect.bisect_left(pos[i], l)
if cnt > 0:
ans += 1
print(ans) | def main():
a, b, c = map(int, input().split())
if a == b == c:
print('No')
elif a != b and b != c and c != a:
print('No')
else:
print('Yes')
if __name__ == '__main__':
main() | 0 | null | 65,133,055,344,230 | 210 | 216 |
N = int(input())
a = list(map(int,input().split()))
print(sum(i%2 for i in a[0::2])) | N = int(input())
a = list(map(int,input().split()))
i=0
for x,y in enumerate (a):
b=x+1
if b%2!=0 and y%2!=0:
i+=1
print(i) | 1 | 7,711,121,960,608 | null | 105 | 105 |
X, N = map(int, input().split())
if N:
lst = list(map(int, input().split()))
for i in range(100):
if X-i not in lst:
print(X-i)
break
if X+i not in lst:
print(X+i)
break
else:
print(X) | [N, K] = list(map(int, input().split()))
P = list(map(int, input().split()))
P.sort(reverse=True)
total = 0
for i in range(K):
total += P.pop()
print (total)
| 0 | null | 12,770,855,505,902 | 128 | 120 |
# coding:utf-8
while True:
array = map(int, list(raw_input()))
if array[0] == 0:
break
print sum(array)
| import random
class Cube:
def __init__(self, u, s, e, w, n, d):
self.u = u
self.s = s
self.e = e
self.w = w
self.n = n
self.d = d
def rotate(self, dic):
if dic == "N":
tmp = self.u
self.u = self.s
self.s = self.d
self.d = self.n
self.n = tmp
elif dic == "E":
tmp = self.u
self.u = self.w
self.w = self.d
self.d = self.e
self.e = tmp
elif dic == "W":
tmp = self.u
self.u = self.e
self.e = self.d
self.d = self.w
self.w = tmp
else:
tmp = self.u
self.u = self.n
self.n = self.d
self.d = self.s
self.s = tmp
def main():
u, s, e, w, n, d = map(int, input().split())
cube = Cube(u, s, e, w, n, d)
q = int(input())
for i in range(q):
upper, front = map(int, input().split())
while True:
cube.rotate(random.choice("NWES"))
if upper == cube.u and front == cube.s:
print(cube.e)
break
if __name__ == '__main__':
main()
| 0 | null | 910,266,436,388 | 62 | 34 |
W, H, x, y ,r = [int(i) for i in input().split()]
if x <= 0 or y <= 0:
print("No")
elif W - x >= r and H - y >= r:
print("Yes")
else:
print("No") | import sys
(W, H, x, y, r) = [int(i) for i in sys.stdin.readline().split()]
if r <= x <= W - r and r <= y <= H - r:
print("Yes")
else:
print("No") | 1 | 450,348,048,298 | null | 41 | 41 |
import os, sys, re, math
(K, X) = (int(n) for n in input().split())
if 500 * K >= X:
print('Yes')
else:
print('No')
| import sys
from itertools import accumulate
from collections import defaultdict
input = sys.stdin.readline
n,k = map(int,input().split())
a = list(map(int,input().split()))
a = [i-1 for i in a]
suma = [0]+list(accumulate(a))
suma = [i%k for i in suma]
rem = defaultdict(int)
ans = 0
if k > n:
for i in range(n+1):
x = suma[i]
rem[x] += 1
for s in rem.values():
ans += s*(s-1)//2
print(ans)
exit()
for i in range(k):
x = suma[i]
rem[x] += 1
for s in rem.values():
ans += s*(s-1)//2
for i in range(n-k+1):
rem[suma[i]%k] -= 1
rem[suma[i+k]%k] += 1
ans += rem[suma[i+k]] -1
print(ans) | 0 | null | 117,398,714,883,772 | 244 | 273 |
# coding: utf-8
# Your code here!
n = int(input())
ta = 0
ha = 0
for i in range(n):
a, b = list(input().split())
if a == b:
ta += 1
ha += 1
elif a > b:
ta += 3
else:
ha += 3
print(ta,ha)
| N=int(input())
S=str(input())
ls = []
for i in range(len(S)):
ls.append(S[i])
for i in range(len(S)):
x = S[i]
#print(ord(x)+N,ord("Z"))
if ord(x)+N > ord("Z"):
#print("if")
#print(ord("A")-ord("Z")+(ord(x)+N))
ls[i]=chr(ord("A")-ord("Z")+(ord(x)+N)-1)
else:
#print("else")
ls[i]=chr((ord(x)+N))
print("".join(ls))
| 0 | null | 68,070,092,910,302 | 67 | 271 |
import fractions
A,B=map(int, input().split())
print(int(A*B/fractions.gcd(A,B))) | import bisect,collections,copy,heapq,itertools,math,string
import numpy as np
import sys
sys.setrecursionlimit(10**7)
def _S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
N,K = LI()
H = LI()
Hs = np.array(sorted(H, reverse=True))
ans = np.sum(Hs[K:])
print(ans) | 0 | null | 96,390,310,338,152 | 256 | 227 |
#Euclidean Algorithm
x, y = map(int, input().split(' '))
q = x % y
while q != 0:
t = y
y = q
x = t
q = x % y
print(y)
| def main():
a, b = tuple(map(int,input().split()))
print(gcd(a, b))
def gcd(x, y):
# x > y となるように並べ替え
if x < y:
(x, y) = (y, x)
return x if y == 0 else gcd(y, x%y)
if __name__ == '__main__':
main()
| 1 | 7,813,677,020 | null | 11 | 11 |
import sys
N = int(input())
A = list(map(int, input().split()))
LA = len(A)
ans = A[0]
for j in range(LA):
if A[j] == 0:
print('0')
sys.exit()
for i in range(LA-1):
ans = ans*A[i+1]
if ans > 10**18:
print('-1')
sys.exit()
print(ans)
| N = int(input())
A = list(map(int,input().split()))
Ans = 1
if 0 in A:
Ans = 0
else:
for i in range(0,N):
Ans *= A[i]
if Ans > 1000000000000000000:
Ans = -1
break
print(Ans)
| 1 | 16,114,299,902,910 | null | 134 | 134 |
n = int(input())
even = n // 2
odd = n - even
print(odd/n)
| def resolve():
N = int(input())
print((N//2+1)/N if N%2==1 else 0.5)
if '__main__' == __name__:
resolve() | 1 | 177,469,060,287,428 | null | 297 | 297 |
def main():
n = int(input())
A = sorted(map(int, input().split()), reverse=True)
ans = 0
mod = 10 ** 9 + 7
m=A[0]
for i in range(61):
cnt0 = cnt1 = 0
if m < 2 ** i:
break
for j, a in enumerate(A):
if a < 2 ** i:
cnt0 += n - j
break
if (a >> i) & 1:
cnt1 += 1
else:
cnt0 += 1
ans += (((2 ** i) % mod) * ((cnt1 * cnt0) % mod)) % mod
ans %= mod
print(ans)
if __name__ == "__main__":
main() | N,M=map(int,input().split())
H=list(map(int,input().split()))
L=[0]*N
for i in range(M):
A,B=map(int,input().split())
L[A-1]=max(L[A-1],H[B-1])
L[B-1]=max(L[B-1],H[A-1])
ans=0
for j in range(N):
if H[j]>L[j]:
ans+=1
print(ans)
| 0 | null | 73,966,109,849,492 | 263 | 155 |
N, D = map(int,input().split())
cnt = 0
for i in range(N):
X,Y = map(int,input().split())
S = (X**2+Y**2)**0.5
if S <= D:
cnt += 1
else:
continue
print(cnt)
|
def main():
r = int(input())
print(r**2)
if __name__ == "__main__":
main()
| 0 | null | 75,618,513,747,132 | 96 | 278 |
def Divisors(n):
L=[]
k=1
while k*k <= n:
if n%k== 0:
L.append(k)
k+=1
return L
N=int(input())
T=Divisors(N)
M=10**20
for a in T:
M=min(M,a+(N//a)-2)
print(M)
| # -*- coding: utf-8 -*-
"""
Created on Wed Sep 9 01:55:56 2020
@author: liang
"""
import math
N = int(input())
key = int(math.sqrt(N))
ans = 10**12
for i in reversed(range(1,key+1)):
if N%i == 0:
ans = i-1 + N//i -1
break
print(ans) | 1 | 161,803,905,716,000 | null | 288 | 288 |
def main():
d, t, s = map(int, input().split())
print("Yes" if d / s <= t else "No")
if __name__ == "__main__":
main() | D, T, S = tuple(int(x) for x in input().split())
if S*T >= D:
print('Yes')
else:
print('No') | 1 | 3,512,469,406,340 | null | 81 | 81 |
n = int(input())
A = list(map(int, input().split()))
A = sorted(A)
ans = 0
def q(k):
if A[k] < A[i] + A[j]:
return True
else:
return False
for i in range(n):
for j in range(i + 1, n):
l = j
r = n
while r - l > 1:
mid = (l + r) // 2
if q(mid):
l = mid
else:
r = mid
ans += (l - j)
print(ans)
| n = int(input())
l = sorted(list(map(int, input().split())))
ans = 0
import bisect
for i in range(n-2):
for j in range(i+1, n-1):
ab = l[i]+l[j]
idx = bisect.bisect_left(l, ab)
ans += max(0, idx-j-1)
print(ans) | 1 | 171,246,515,467,720 | null | 294 | 294 |
n, m = map(int, input().split())
nl = [i for i in range(1000)]
if m == 0:
for i in range(1000):
st = str(i)
if len(st) != n:
nl[i] = 1000
print(min(nl) if min(nl) < 1000 else -1)
exit()
for h in range(m):
s, c = map(int, input().split())
for i in range(1000):
st = str(i)
if len(st) != n or st[s - 1] != str(c):
nl[i] = 1000
print(min(nl) if min(nl) < 1000 else -1) | n,m = map(int,input().split())
li = [list(map(int,input().split())) for _ in range(m)]
if n==1 and all([i[1]==0 for i in li]):
print(0)
exit()
for i in range(10**(n-1),10**n):
p = list(map(int,list(str(i))))
for s,c in li:
if p[s-1] != c:break
else:
print(i)
exit()
print(-1) | 1 | 60,851,212,586,600 | null | 208 | 208 |
import math
x = int(input())
print(math.ceil(x/2)) | import sys
sys.setrecursionlimit(10**9)
N, P = list(map(int, input().split()))
S = input()
if P == 2 or P == 5:
ans = 0
for i in range(N):
if int(S[i]) % P == 0:
ans += i + 1
print(ans)
sys.exit()
num = [0] * P
num[0] = 1
now, ans = 0, 0
_10 = 1
for i in range(N-1, -1, -1):
now = (now + int(S[i]) * _10) % P
_10 *= 10
_10 %= P
ans += num[now]
num[now] += 1
print(ans)
| 0 | null | 58,481,389,135,970 | 206 | 205 |
N = int(input())
S = str(input())
cnt = 1
for i in range(1,N):
if S[i] == S[i-1]:
pass
else:
cnt += 1
print(cnt)
| [n, m, l] = [int(x) for x in raw_input().split()]
A = []
B = []
C = []
counter = 0
while counter < n:
A.append([int(x) for x in raw_input().split()])
counter += 1
counter = 0
while counter < m:
B.append([int(x) for x in raw_input().split()])
counter += 1
counter = 0
while counter < n:
C.append([0] * l)
counter += 1
for i in range(n):
for j in range(l):
for k in range(m):
C[i][j] += (A[i][k] * B[k][j])
for data in C:
print(' '.join([str(x) for x in data])) | 0 | null | 85,533,897,835,828 | 293 | 60 |
X=int(input())
C=X//500
c=(X-X//500*500)//5
print(C*1000+c*5) | n = int(input())
d = {}
for i in range(n):
s = input()
d[s] = d.get(s, 0) + 1
m = max(d.values())
for s in sorted(s for s in d if d[s] == m):
print(s)
| 0 | null | 56,293,068,397,562 | 185 | 218 |
def resolve():
S = list(input())
ans = [0 for _ in range(len(S) + 1)]
cnt = 0
for i in range(len(S)):
if S[i] == "<":
cnt += 1
ans[i + 1] = max(cnt, ans[i + 1])
else:
cnt = 0
cnt = 0
for i in range(len(S), 0, -1):
if S[i - 1] == ">":
cnt += 1
ans[i - 1] = max(cnt, ans[i - 1])
else:
cnt = 0
print(sum(ans))
resolve()
| def main():
s = input()
arr = [0]*(len(s)+1)
for i in range(len(s)):
c = s[i]
if c == "<":
arr[i+1] = arr[i]+1
for i in reversed(range(len(s))):
c = s[i]
if c == ">":
arr[i] = max(arr[i], arr[i+1]+1)
print(sum(arr))
if __name__ == "__main__":
main()
| 1 | 156,169,149,857,308 | null | 285 | 285 |
import sys
import numba as nb
import numpy as np
input = sys.stdin.readline
@nb.njit("i8(i8,i8,i8[:,:])", cache=True)
def solve(H, N, AB):
INF = 10 ** 18
dp = np.full(shape=(H + 1), fill_value=INF, dtype=np.int64)
dp[0] = 0
for i in range(N):
A, B = AB[i]
for d in range(H + 1):
if d < A:
dp[d] = min(dp[d], B)
else:
dp[d] = min(dp[d], dp[d - A] + B)
ans = dp[-1]
return ans
def main():
H, N = map(int, input().split())
AB = np.zeros(shape=(N, 2), dtype=np.int64)
for i in range(N):
AB[i] = input().split()
ans = solve(H, N, AB)
print(ans)
if __name__ == "__main__":
main()
| import sys
#input = sys.stdin.buffer.readline
def main():
N,M = map(int,input().split())
s = str(input())
s = list(reversed(s))
ans = []
now = 0
while now < N:
for i in reversed(range(min(M,N-now))):
i += 1
if s[now+i] == "0":
now += i
ans.append(i)
break
if i == 1:
print(-1)
exit()
print(*reversed(ans))
if __name__ == "__main__":
main()
| 0 | null | 110,054,856,409,888 | 229 | 274 |
n = int(input())
a = [int(i) for i in input().split()]
new_a = set(a)
if len(new_a) != n:
print("NO")
else:
print("YES") | from collections import Counter
n = int(input())
a = list(map(int, input().split()))
ac = Counter(a)
if len(ac) == n:
print("YES")
else:
print("NO")
| 1 | 73,762,741,001,196 | null | 222 | 222 |
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
from heapq import heappop, heappush
from collections import defaultdict
sys.setrecursionlimit(10**7)
import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque
#from decimal import Decimal
#from numba import jit
INF = 1 << 50
EPS = 1e-8
mod = 10 ** 9 + 7
def mapline(t = int):
return map(t, sysread().split())
def mapread(t = int):
return map(t, read().split())
def run():
N, *A = mapread()
dp = [defaultdict(lambda:0) for _ in range(N+1)]
dp[0][(0,0,0)] = 1
for i in range(N):
a = A[i]
k = i + 1
for key in dp[k-1].keys():
for ii, v in enumerate(key):
if v == a:
tmp = list(key)
tmp[ii] += 1
dp[k][tuple(tmp)] += dp[k-1][key] % mod
ans = 0
for key in dp[N].keys():
ans = (ans + dp[N][key]) % mod
#print(dp)
print(ans)
if __name__ == "__main__":
run()
| print('Yes' if sum(map(int, input()))%9 == 0 else 'No')
| 0 | null | 67,004,734,284,620 | 268 | 87 |
import numpy as np
import sys
N,K = map(int, input().split())
A = np.array(sys.stdin.readline().split(), np.int64)
maxa = np.max(A)
mina = maxa // (K+1)
while maxa > mina + 1:
mid = (maxa + mina)// 2
div = np.sum(np.ceil(A/mid-1))
if div > K:
mina = mid
else:
maxa = mid
print(maxa)
| import math
pai = math.pi
r = float(input())
print('{:.6f} {:.6f}'.format(pai*r**2,2*pai*r))
| 0 | null | 3,594,968,965,482 | 99 | 46 |
a, b = map(int, input().split())
print("{} {} {:.12f}".format(a // b, a % b, a * 1.0 / b)) | L = raw_input().split()
a = int(L[0])
b = int(L[1])
d = int(0)
r = int(0)
f = float(0)
d = a / b
r = a % b
f = float(a) / float(b)
print "{0} {1} {2:f}".format(d,r,f) | 1 | 605,324,155,572 | null | 45 | 45 |
from operator import itemgetter
import bisect
N, D, A = map(int, input().split())
enemies = sorted([list(map(int, input().split())) for i in range(N)], key=itemgetter(0))
d_enemy = [enemy[0] for enemy in enemies]
b_left = bisect.bisect_left
logs = []
logs_S = [0, ]
ans = 0
for i, enemy in enumerate(enemies):
X, hp = enemy
start_i = b_left(logs, X-2*D)
count = logs_S[-1] - logs_S[start_i]
hp -= count * A
if hp > 0:
attack_num = (hp + A-1) // A
logs.append(X)
logs_S.append(logs_S[-1]+attack_num)
ans += attack_num
print(ans)
| from collections import deque
#入力:N,M(int:整数)
def input2():
return map(int,input().split())
#入力:[n1,n2,...nk](int:整数配列)
def input_array():
return list(map(int,input().split()))
n,m=input2()
g=[[] for _ in range(n+1)] #引数->要素で道しるべを保存
for i in range(m):
a,b=input2()
g[a].append(b)
g[b].append(a)
q=deque() #bfs用
q.append(1) #始点
check=[0]*(n+1) #既に訪問している(1)か否(0)か
check[1]=1
ans=[0]*(n+1) #始点に近い側の,一つ前の要素(解答)
ans[1]=1
for _ in range(10**5+1):
if len(q)==0:
break
v=q.popleft() #頂点を一つ取り出す
for u in g[v]: #vとの通路を全て探索
if check[u]==0:
check[u]=1 #探索済み==1
ans[u]=v
q.append(u)
print("Yes")
for i in range(2,n+1):
print(ans[i]) | 0 | null | 51,529,151,509,760 | 230 | 145 |
D,T,S = (int(x) for x in input().split())
if D/S <= T:
print('Yes')
else:
print('No') | a = input().split()
dist = int(a[0])
time = int(a[1])
speed = int(a[2])
if(speed * time < dist):
print("No")
else:
print("Yes") | 1 | 3,525,211,508,808 | null | 81 | 81 |
#!/usr/bin/env python3
l = int(input())
q = l / 3
print(q ** 3)
| roll = {"N": (1, 5, 2, 3, 0, 4),
"S": (4, 0, 2, 3, 5, 1),
"E": (3, 1, 0, 5, 4, 2),
"W": (2, 1, 5, 0, 4, 3)}
dice = input().split()
for direction in input():
dice = [dice[i] for i in roll[direction]]
print(dice[0])
| 0 | null | 23,451,098,050,274 | 191 | 33 |
import math
def toRad(theta):
return theta * math.pi / 180
def calc_S(_a, _b, _c):
return (_a * _b * math.sin(toRad(_c))) / 2
def calc_L(_a, _b, _c):
return _a + _b + math.sqrt(_a**2 + _b**2 - 2*a*b*math.cos(toRad(_c)))
def calc_H(_a, _b, _c):
return _b * math.sin(toRad(_c))
a, b, c = map(int, input().split())
print(calc_S(a, b, c))
print(calc_L(a, b, c))
print(calc_H(a, b, c)) | N = int(input())
A = list(map(int,input().split()))
dic = {}
for a in A:
if a not in dic:
dic[a]=1
else:
print('NO');exit()
print('YES') | 0 | null | 36,922,283,200,390 | 30 | 222 |
n=int(input())
print(len(set([input() for _ in range(n)]))) | def srch(u, cnt, Dst, Fst, Lst):
S = [u]
Fst[u] = cnt
while(len(S) > 0):
cnt += 1
u = S.pop()
if Dst[u] is not None and len(Dst[u]) > 0:
while(len(Dst[u])):
u1 = Dst[u].pop()
if Fst[u1] == 0:
S.append(u)
S.append(u1)
Fst[u1] = cnt
break
else:
Lst[u] = cnt
else:
Lst[u] = cnt
return cnt + 1
def main():
num = int(input())
Dst = [None for i in range(num + 1)]
Fst = [0] * (num + 1)
Lst = Fst[:]
for n in range(1, num+1):
a = list(map(int,input().split()))
u = a[0]
if a[1] > 0:
Dst[u] = a[2:]
Dst[u].reverse()
cnt = 1
for i in range(1,num):
if Fst[i] == 0:
cnt = srch(i, cnt, Dst, Fst, Lst)
for n in range(1, num+1):
print("{} {} {}".format(n,Fst[n],Lst[n]))
if __name__ == '__main__':
main() | 0 | null | 15,121,827,298,742 | 165 | 8 |
N,K = map(int,input().split())
A = list(map(int,input().split()))
A = sorted(A)
mod = 10**9+7
def p(m,n):
a = 1
for i in range(n):
a = a*(m-i)
return a
def p_mod(m,n,mod):
a = 1
for i in range(n):
a = a*(m-i) % mod
return a
def c(m,n):
return p(m,n) // p(n,n)
def c_mod(m,n,mod):
return (p_mod(m,n,mod)*pow(p_mod(n,n,mod),mod-2,mod)) % mod
C = [0]*(N-K+1) #C[i] = (N-i-1)C_(K-1),予め二項係数を計算しておく
for i in range(N-K+1):
if i == 0:
C[i] = c_mod(N-1,K-1,mod)
else:
C[i] = (C[i-1]*(N-K-i+1)*pow(N-i,mod-2,mod)) % mod
#各Aの元が何回max,minに採用されるかを考える
ans = 0
for i in range(N-K+1):
ans -= (A[i]*C[i]) % mod
A.reverse()
for i in range(N-K+1):
ans += (A[i]*C[i]) % mod
print(ans % mod) | import itertools
n=int(input())
p=tuple(map(int, input().split()))
q=tuple(map(int, input().split()))
per=itertools.permutations(range(1, n+1), n)
for i, v in enumerate(per):
if(p==v): pi=i
if(q==v): qi=i
print(abs(pi-qi))
| 0 | null | 98,132,394,640,590 | 242 | 246 |
def resolve():
X = int(input())
if X >= 2100:
print("1")
else:
if X%100 > (X//100)*5:
print("0")
else:
print("1")
resolve() | import math
alen, blen, cang = map(float, input().split())
h = math.sin(math.radians(cang)) * blen
#print(h)
S = 0.5 * alen * h
if cang < 90.0:
L = alen + blen + math.sqrt((alen - math.sqrt(blen**2.0 - h**2.0)) ** 2.0 + h**2.0)
else:
L = alen + blen + math.sqrt((alen + math.sqrt(blen**2.0 - h**2.0)) ** 2.0 + h**2.0)
print(S)
print(L)
print(h)
| 0 | null | 63,858,712,352,950 | 266 | 30 |
import sys
chash = {}
for i in range( ord( 'a' ), ord( 'z' )+1 ):
chash[ chr( i ) ] = 0
lines = sys.stdin.readlines()
for i in range( len( lines ) ):
for j in range( len( lines[i] ) ):
if lines[i][j].isalpha():
chash[ lines[i][j].lower() ] += 1
for i in range( ord( 'a' ), ord( 'z' )+1 ):
print( "{:s} : {:d}".format( chr( i ), chash[ chr( i ) ] ) ) | from collections import defaultdict as dd
from collections import deque
import bisect
import heapq
def ri():
return int(input())
def rl():
return list(map(int, input().split()))
def solve():
a, v = rl()
b, w = rl()
t = ri()
d = abs(a - b)
s = v - w
if t * s >= d:
print ("YES")
else:
print ("NO")
mode = 's'
if mode == 'T':
t = ri()
for i in range(t):
solve()
else:
solve()
| 0 | null | 8,296,117,247,830 | 63 | 131 |
import math
def kock(n,p1,p2):
a=math.radians(60)
if n==0:
return 0
s=[(2*p1[0]+p2[0])/3,(2*p1[1]+p2[1])/3]
t=[(p1[0]+2*p2[0])/3,(p1[1]+2*p2[1])/3]
u=[((t[0]-s[0])*math.cos(a)-(t[1]-s[1])*math.sin(a))+s[0],(t[0]-s[0])*math.sin(a)+(t[1]-s[1])*math.cos(a)+s[1]]
kock(n-1,p1,s)
print(" ".join(map(str,s)))
kock(n-1,s,u)
print(" ".join(map(str,u)))
kock(n-1,u,t)
print(" ".join(map(str,t)))
kock(n-1,t,p2)
n=int(input())
start=[float(0),float(0)]
end=[float(100),float(0)]
print(" ".join(map(str,start)))
kock(n,start,end)
print(" ".join(map(str,end)))
| def koch(n, ax, ay, bx, by):
if n == 0:
return
th = math.pi * 60.0 / 180.0
xx = (2.0 * ax + bx)/3.0
xy = (2.0 * ay + by)/3.0
zx = (ax + 2.0 * bx)/3.0
zy = (ay + 2.0 * by)/3.0
yx = (zx - xx)*math.cos(th) - (zy - xy)*math.sin(th) + xx
yy = (zx - xx)*math.sin(th) + (zy - xy)*math.cos(th) + xy
koch(n-1, ax, ay, xx, xy)
print xx,xy
koch(n-1, xx, xy, yx, yy)
print yx,yy
koch(n-1, yx, yy, zx, zy)
print zx,zy
koch(n-1, zx, zy, bx, by)
import math
n = int(raw_input())
ax = 0.0
ay = 0.0
bx = 100.0
by = 0.0
print ax,ay
koch(n, ax, ay, bx, by)
print bx,by | 1 | 129,302,560,258 | null | 27 | 27 |
n, k = map(int, input().split())
LR = [tuple(map(int, input().split())) for _ in range(k)]
mod = 998244353
dp = [1]
acc = [0, 1]
for i in range(1, n):
new = 0
for l, r in LR:
if i < l:
continue
r = min(r, i)
new += acc[i-l+1] - acc[i-r]
new %= mod
dp.append(new)
acc.append((acc[-1]+new) % mod)
print(dp[-1]) | import sys
write=sys.stdout.write
while True:
h,w=map(int,raw_input().split())
if h==w==0: break
for i in xrange(h):
l=[('#' if i%2==j%2==0 else ('.' if (i%2==1 and j%2==0) or (i%2==0 and j%2==1) else '#')) for j in xrange(w)]
for i in l:
write(i)
print ""
print "" | 0 | null | 1,807,984,217,600 | 74 | 51 |
a = str(input().split())
b = list(a)
if b[4] == b[5] and b[7] == b[6]:
print("Yes")
else :
print("No") | n=int(input())
a=[int(x) for x in input().split()]
count=0
for i in range(0,n,2):
if a[i]%2==1:
count+=1
print(count) | 0 | null | 24,737,654,670,810 | 184 | 105 |
#!/usr/bin/env python3
from collections import Counter
n, *d = map(int, open(0).read().split())
c = Counter(d[1:])
c = [(0, 1)] + sorted(c.items())
ans = d[0] == 0
for i in range(1, len(c)):
if i != c[i][0]:
ans = 0
break
ans *= pow(c[i - 1][1],c[i][1], 998244353)
print(ans%998244353)
| S = input()
T = input()
ans = 0
for i,y in zip(S,T):
if i != y:
ans += 1
print(ans) | 0 | null | 82,600,540,197,188 | 284 | 116 |
def insert_sort(A, n, g, cnt):
for i in range(g, n):
v = A[i]
j = i - g
while j >= 0 and A[j] > v:
A[j+g] = A[j]
j -= g
cnt += 1
A[j+g] = v
return cnt
def shellSort(A, n):
cnt = 0
G = []; h = 0
while h <= n:
if 3 * h + 1 <= n:
h = 3 * h + 1
G.append(h)
else: break
G = sorted(G, reverse=True)
m = len(G)
for i in range(m):
cnt = insert_sort(A, n, G[i], cnt)
return m, cnt, G
A = []
n = int(input())
for i in range(n):
A.append(int(input()))
m, cnt, G = shellSort(A, n)
print(m)
for i in range(m):
if i == m - 1:
print(G[i])
else:
print(G[i], end=" ")
print(cnt)
for i in A:
print(i)
| """from collections import *
from itertools import *
from bisect import *
from heapq import *
import math
from fractions import gcd"""
import sys
#input = sys.stdin.readline
from heapq import*
N,M=map(int,input().split())
S=list(input())
S.reverse()
idx=0
lst=[]
while idx<N:
for i in range(1,M+1)[::-1]:
if i+idx<=N:
if S[i+idx]=="0":
idx+=i
lst.append(i)
break
else:
print(-1)
exit()
lst.reverse()
print(" ".join([str(i) for i in lst]))
| 0 | null | 69,923,471,650,240 | 17 | 274 |
x=input().split()
a,b,c=int(x[0]),int(x[1]),int(x[2])
if a<b<c:
print("Yes")
else:
print("No")
| #!usr/bin/env python3
def string_three_numbers_spliter():
a, b, c = [int(i) for i in input().split()]
return a, b, c
def main():
a, b, c = string_three_numbers_spliter()
if a < b and a < c:
print('Yes')
else:
print('No')
if __name__ == '__main__':
main() | 1 | 378,958,772,010 | null | 39 | 39 |
k = int(input())
s = input()
a = len(s) - k
if a <= 0:
print(s)
else:
#a >0
print(s[:k] + "...")
| H, W, K = map(int, input().split())
S = [input() for _ in range(H)]
ans = [[0] * W for _ in range(H)]
cur = 1
for i in range(H):
has_st = []
for j in range(W):
if S[i][j] == "#":
has_st.append(j)
if not has_st:
continue
elif len(has_st) == 1:
ans[i] = [cur] * W
cur += 1
else:
for j in range(has_st[-1] + 1):
ans[i][j] = cur
if S[i][j] == "#":
cur += 1
ans[i][has_st[-1] + 1 :] = [cur - 1] * (W - has_st[-1] - 1)
for i in range(H - 1):
if ans[i + 1] == [0] * W:
ans[i + 1] = ans[i][:]
for i in range(H - 1, 0, -1):
if ans[i - 1] == [0] * W:
ans[i - 1] = ans[i][:]
[print(" ".join(map(str, row))) for row in ans]
| 0 | null | 81,865,288,849,888 | 143 | 277 |
N = int(input())
A = list(map(int, input().split()))
ans = 0
for i in range(N - 1):
if A[i] > A[i + 1]:
ans += A[i] - A[i + 1]
A[i + 1] = max(A[i], A[i + 1])
print(ans)
| m = ""
while True:
S = input()
if S == "-":
break
S = list(S)
L = S
n = int(input())
for i in range(n):
m = int(input())
for j in range(m):
t = L.pop(0)
L.append(t)
L = "".join(L)
print(L) | 0 | null | 3,246,206,589,110 | 88 | 66 |
def main():
import sys
input = sys.stdin.readline
N = int(input())
plus = []
minus = []
total = 0
for _ in range(N):
s = input().strip()
h = 0
bottom = 0
for ss in s:
if ss == "(":
h += 1
else:
h -= 1
bottom = min(bottom, h)
total += h
if h > 0:
plus.append((bottom, h))
else:
minus.append((bottom-h, -h))
if total != 0:
print("No")
sys.exit()
plus.sort(reverse=True)
minus.sort(reverse=True)
height = 0
for b, h in plus:
if height + b < 0:
print("No")
sys.exit()
height += h
height = 0
for b, h in minus:
if height + b < 0:
print("No")
sys.exit()
height += h
print("Yes")
if __name__ == '__main__':
main() |
N = int(input())
As = list(map(int, input().split()))
ans = 0
tall = int(As[0])
for A in As:
if(tall > A):
ans += tall - A
else:
tall = A
print(ans) | 0 | null | 14,138,232,678,040 | 152 | 88 |
print( 1 if int(input()) < 1 else 0) | import sys
def main():
input = sys.stdin.buffer.readline
k = int(input())
a = [
1,
1,
1,
2,
1,
2,
1,
5,
2,
2,
1,
5,
1,
2,
1,
14,
1,
5,
1,
5,
2,
2,
1,
15,
2,
2,
5,
4,
1,
4,
1,
51,
]
print(a[k - 1])
if __name__ == "__main__":
main()
| 0 | null | 26,602,888,337,582 | 76 | 195 |
h1, m1, h2, m2, k = list(map(int, input().split()))
okiteru = h2 * 60 + m2 - (h1 * 60 + m1)
print(okiteru - k)
| import itertools
n=int(input())
ab = []
for _ in range(n):
a, b = (int(x) for x in input().split())
ab.append([a, b])
narabi = [0+i for i in range(n)]
ans = 0
count = 0
for v in itertools.permutations(narabi, n):
count += 1
tmp_len = 0
for i in range(1,n):
x, y = abs(ab[v[i-1]][0]-ab[v[i]][0])**2, abs(ab[v[i-1]][1]-ab[v[i]][1])**2
tmp_len += (x + y)**0.5
ans += tmp_len
print(ans/count) | 0 | null | 83,275,867,962,990 | 139 | 280 |
X = input()
if X.isupper():
print("A")
else:
print("a") | s = input()
if s.lower() == s:
print("a")
else:
print("A") | 1 | 11,361,653,652,188 | null | 119 | 119 |
from collections import Counter
N=int(input())
if N==1:
print(0)
exit()
def factorize(n):
out=[]
i = 2
while 1:
if n%i==0:
out.append(i)
n //= i
else:
i += 1
if n == 1:break
if i > int(n**.5+3):
out.append(n)
break
return out
c = Counter(factorize(N))
def n_unique(n):
out = 0
while 1:
if out*(out+1)//2 > n:
return out-1
out += 1
ans = 0
for k in c.keys():
ans += n_unique(c[k])
print(ans) | import math
a, b, C = map(int, raw_input().split())
S = a * b * math.sin(math.radians(C)) / 2
L = math.sqrt(a**2 + b**2 - 2*a*b*math.cos(math.radians(C))) + a + b
h = 2*S/a
print S
print L
print h | 0 | null | 8,506,952,438,320 | 136 | 30 |
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 math
n = int(input())
a = [0] * 2
b = [0] * 2
a[0] = 0
b[0] = 100
def koch(n, a, b):
if n == 0:
return
s = [0] * 2
t = [0] * 2
u =[0] * 2
s[0] = (2.0 * a[0] + 1.0 * b[0]) / 3.0
s[1] = (2.0 * a[1] + 1.0 * b[1]) / 3.0
t[0] = (1.0 * a[0] + 2.0 * b[0]) / 3.0
t[1] = (1.0 * a[1] + 2.0 * b[1]) / 3.0
u[0] = (t[0] - s[0]) * math.cos(math.pi/3) - (t[1] - s[1]) * math.sin(math.pi/3) + s[0]
u[1] = (t[0] - s[0]) * math.sin(math.pi/3) + (t[1] - s[1]) * math.cos(math.pi/3) + s[1]
koch(n - 1, a, s)
print(s[0], s[1])
koch(n - 1, s, u)
print(u[0], u[1])
koch(n - 1, u, t)
print(t[0], t[1])
koch(n - 1, t, b)
print(a[0], a[1])
koch(n, a, b)
print(b[0], b[1])
| 1 | 127,459,475,572 | null | 27 | 27 |
def havec(x_list, y):
x_list[y-1] = 1
def printc(x_list, s):
for i in range(13):
if x_list[i] == 0:
print("%s %d" %(s, i+1))
n = input()
Sp = [0,0,0,0,0,0,0,0,0,0,0,0,0]
Ha = [0,0,0,0,0,0,0,0,0,0,0,0,0]
Cl = [0,0,0,0,0,0,0,0,0,0,0,0,0]
Di = [0,0,0,0,0,0,0,0,0,0,0,0,0]
for i in range(n):
incard = raw_input()
a, b = incard.split(" ")
b = int(b)
if a == "S":
havec(Sp, b)
elif a == "H":
havec(Ha, b)
elif a == "C":
havec(Cl, b)
else:
havec(Di, b)
printc(Sp, "S")
printc(Ha, "H")
printc(Cl, "C")
printc(Di, "D") | import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *
H, W = MAP()
S = [input() for _ in range(H)]
dy = (1, 0, -1, 0)
dx = (0, -1, 0, 1)
def diff_max(start_y, start_x):
check = [[-1]*W for _ in range(H)]
check[start_y][start_x] = 0
q = deque([(start_y, start_x)])
while q:
y, x = q.popleft()
for i in range(4):
ny = y + dy[i]
nx = x + dx[i]
if 0 <= ny < H and 0 <= nx < W:
if check[ny][nx] == -1 and S[ny][nx] == ".":
check[ny][nx] = check[y][x] + 1
q.append((ny, nx))
return max([max(x) for x in check])
ans = -INF
for i in range(H):
for j in range(W):
if S[i][j] == ".":
ans = max(ans, diff_max(i, j))
print(ans)
| 0 | null | 47,757,000,721,572 | 54 | 241 |
billdings = [[[0 for _ in range(10)] for _ in range(3)] for _ in range(4)]
def printstate(billdings):
"""
for billnum, billding in enumerate(billdings):
for flooor in billding:
for room in flooor:
print(" {}".format(room), end="")
print()
print("#"*20 if billnum != len(billdings)-1 else "")
"""
for i in range(len(billdings)):
for j in range(len(billdings[0])):
for k in range(len(billdings[0][0])):
print(" "+str(billdings[i][j][k]), end="")
print()
if i != len(billdings)-1:
print("#"*20)
n = int(input())
for _ in range(n):
b, f, r, v = map(int, input().split())
b, f, r = b-1, f-1, r-1
billdings[b][f][r] += v
printstate(billdings)
| n = int(input())
cards = set()
for _ in range(n):
cards |= {input()}
for s in ["S","H","C","D"]:
for n in range(1,14):
needle = s + " " + str(n)
if not needle in cards:
print(needle) | 0 | null | 1,091,807,916,408 | 55 | 54 |
from sys import stdin
n = int(stdin.readline())
ans = 0
for j in range(1,n+1):
a = n//j
ans += a*(a+1)*j//2
print(ans) | import math
n,m=map(int,input().split())
print(math.ceil(n/m)) | 0 | null | 44,026,671,034,150 | 118 | 225 |
n = int(input())
cout = ""
for i in range(1,n+1):
x = i
if x%3 == 0:
cout += " " + str(i)
else:
while x > 0:
if x%10 == 3:
cout += " " + str(i)
break
x //= 10
print (cout) | n = int(input())
s = input()
res = 'Yes' if s[0:n//2] == s[n//2:] else 'No'
print(res) | 0 | null | 73,566,624,886,440 | 52 | 279 |
N = int(input())
T = []
try:
while True:
t = input()
t=int(t)
T_temp=[]
for t_ in range(t) :
temp = list(map(int,input().split()))
T_temp.append(temp)
T.append(T_temp)
except EOFError:
pass
def check_Contradiction(true_list):
S = {}
for n in range(N):
if n in true_list:
S[n]=set([1])
else:
S[n]=set([0])
for t in true_list:
for T_ in T[t]:
S[T_[0]-1].add(T_[1])
ok=True
for s in S.keys():
if len(S[s])!=1:
ok='False'
break
return ok
ok_max = -1
for i in range(2**N):
# print('=====',i)
true_list=[]
for j in range(N):
if i>>j&1 ==True:
true_list.append(j)
# print(true_list)
# print(check_Contradiction(true_list))
if check_Contradiction(true_list)==True:
if ok_max < len(true_list):
ok_max=len(true_list)
print(ok_max) | 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():
N = I()
A = []
xy = []
for _ in range(N):
A.append(I())
xy.append([LI() for _ in range(A[-1])])
ans = 0
for i in range(2 ** N):
# まず正直者を仮定し、正直者の証言に矛盾がないか判定
is_ok = True
num = 0
for j in range(N):
if i >> j & 1:
num += 1
for k in xy[j]:
x, y = k
x -= 1
if i >> x & 1 != y:
is_ok = False
if is_ok:
ans = max(num, ans)
print(ans)
if __name__ == '__main__':
resolve()
| 1 | 121,596,543,121,562 | null | 262 | 262 |
m,f,r = 0,0,0
table = []
i = 0
while m != -1 or f != -1 or r != -1:
m,f,r = (int(x) for x in input().split())
table.append([m,f,r])
for p in table:
m,f,r = p[0],p[1],p[2]
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')
| _ = input()
s = input()
x = s.count('ABC')
print(x) | 0 | null | 50,420,856,822,482 | 57 | 245 |
N, M, X = map(int, input().split())
CA = [list(map(int, input().split())) for _ in range(N)]
sum_money = float("inf")
for i in range(2 ** N):
money = 0
algorithm = [0]*M
for j in range(N):
if (i >> j) & 1 == 1:
money += CA[j][0]
for k in range(M):
algorithm[k] += CA[j][k+1]
check = True
for l in algorithm:
if l < X:
check = False
if check:
sum_money = min(sum_money, money)
print(sum_money if sum_money != float("inf") else -1) | N, M, X = map(int, input().split())
C=[]
A=[]
for _ in range(N):
c, *a = map(int, input().split())
C.append(c)
A.append(a)
ans=10**5*N+1
for maskN in range(1<<N):
cost=0
level=[0]*M
for n in range(N):
if (maskN>>n&1):
cost+=C[n]
for m in range(M):
level[m] += A[n][m]
for l in level:
if l < X:
break
else:
ans=min(ans, cost)
print(f'{ans if ans!=10**5*N+1 else "-1"}')
| 1 | 22,330,175,349,320 | null | 149 | 149 |
n, x, m = map(int, input().split())
def solve(n, x, m):
if n == 1:
return x
arr = [x]
for i in range(1, n):
x = x*x % m
if x in arr:
rem = n-i
break
else:
arr.append(x)
else:
rem = 0
sa = sum(arr)
argi = arr.index(x)
roop = arr[argi:]
nn, r = divmod(rem, len(roop))
return sa + nn*sum(roop) + sum(roop[:r])
print(solve(n, x, m)) | n,x,m = map(int, input().split())
be = x % m
ans = be
memo = [[0,0] for i in range(m)]
am = [be]
memo[be-1] = [1,0] #len-1
for i in range(n-1):
be = be**2 % m
if be == 0:
break
elif memo[be-1][0] == 1:
kazu = memo[be-1][1]
l = len(am) - kazu
syou = (n-i-1) // l
amari = (n-i-1)%l
sum = 0
for k in range(kazu, len(am)):
sum += am[k]
ans = ans + syou*sum
if amari > 0:
for j in range(kazu,kazu + amari):
ans += am[j]
break
else:
ans += be
am.append(be)
memo[be-1][0] = 1
memo[be-1][1] = len(am) -1
print(ans)
| 1 | 2,810,615,450,204 | null | 75 | 75 |
N = int(input())
def make_divisors(n):
lower_divisors , upper_divisors = [], []
i = 1
while i*i <= n:
if n % i == 0:
lower_divisors.append(i)
if i != n // i:
upper_divisors.append(n//i)
i += 1
return lower_divisors + upper_divisors[::-1]
mdn = make_divisors(N)
aa = []
for x in mdn:
aa.append(x+N//x)
print(min(aa)-2) | A,B,K = map(int, input().split())
print(A-K, B) if K <= A else print(0,0) if (A+B) <= K else print(0, A+B-K)
| 0 | null | 133,153,597,929,590 | 288 | 249 |
n=int(input())
d=list(map(int,input().split()))
l=[x for x in range(n)]
import itertools
p=list(itertools.combinations(l,2))
ans=0
for pp in p:
ans+=d[pp[0]]*d[pp[1]]
print(ans) | N = int(input())
d = list(map(int, input().split()))
import itertools
ans = 0
pairs = list(itertools.combinations(d, 2))
for pair in pairs:
ans += pair[0] * pair[1]
print(ans) | 1 | 168,683,502,828,062 | null | 292 | 292 |
a, b, c = map(int, input().split())
k = int(input())
count = 0
while True:
if b > a:
break
b *= 2
count += 1
while True:
if c > b:
break
c *= 2
count += 1
if count <= k:
print('Yes')
else:
print('No')
| N = int(input())
SUM = 0
for i in range(1, N + 1):
if i % 3 != 0:
if i % 5 != 0:
SUM += i
print(SUM) | 0 | null | 20,900,017,047,908 | 101 | 173 |
import math
N = int(input())
ans = [0]*(N+1)
Nruto = math.sqrt(N)
Nruto = math.floor(Nruto)+1
for x in range(1, Nruto):
for y in range(1, Nruto):
for z in range(1, Nruto):
n = x**2+y**2+z**2+x*y+y*z+z*x
if n <= N:
ans[n] += 1
for i in range(1, N+1):
print(ans[i])
| n=int(input())
A=[0]*(n+1)
for x in range(1,101):
for y in range(1,101):
if x**2+y**2+x*y>n :break
for z in range(1,101):
qq= x**2+y**2+z**2+x*y+y*z+z*x
if qq>n:break
A[qq]+=1
print(*A[1:],sep="\n") | 1 | 8,013,094,933,460 | null | 106 | 106 |
while True:
H, W = map(int, input().split())
if not(H or W):
break
for j in range(W):
print('#', end='')
print()
for i in range(H-2):
print('#', end='')
for j in range(W-2):
print('.', end='')
print('#')
for j in range(W):
print('#', end='')
print('\n') | #!/usr/bin/env python
#coding: UTF-8
while True:
h,w = map(int,raw_input().split())
if h+w==0:
break
else:
print w*'#'# ??????####
for hight in range(h-2):
print '#'+(w-2)*'.'+'#'
print w*'#'#????????????####
print | 1 | 828,505,534,288 | null | 50 | 50 |
import string
n = int(input())
s = ''
lowCase = string.ascii_lowercase
while n > 0:
n -= 1
s += lowCase[int(n % 26)]
n //= 26
print(s[::-1])
| n = int(input())
ans = ""
check = "abcdefghijklmnopqrstuvwxyz"
while n != 0:
n -= 1
ans += check[n % 26]
n //= 26
print(ans[::-1])
| 1 | 11,790,817,318,940 | null | 121 | 121 |
import copy
class Card:
def __init__(self, suit, number):
self.suit = suit
self.number = number
self.view = self.suit + str(self.number)
def bubble_sort(A):
count = 0
while True:
swapped = False
for i in range(len(A)-1):
if A[i+1].number < A[i].number:
A[i+1], A[i] = A[i], A[i+1]
count += 1
swapped = True
if not swapped:
return count
def selection_sort(A):
count = 0
for i in range(len(A)):
min_value = A[i].number
min_value_index = i
# print('- i:', i, 'A[i]', A[i], '-')
for j in range(i, len(A)):
# print('j:', j, 'A[j]:', A[j])
if A[j].number < min_value:
min_value = A[j].number
min_value_index = j
# print('min_value', min_value, 'min_value_index', min_value_index)
if i != min_value_index:
count += 1
A[i], A[min_value_index] = A[min_value_index], A[i]
# print('swap!', A)
return count
n = int(input())
A = []
for row in input().split():
suit, number = list(row)
A.append(Card(suit, int(number)))
def is_stable(A, B):
N = len(A)
for i_A in range(N-1):
for j_A in range(i_A+1, N):
for i_B in range(N-1):
for j_B in range(i_B+1, N):
if A[i_A].number == A[j_A].number and A[i_A].view == B[j_B].view and A[j_A].view == B[i_B].view:
return False
return B
bubble_sort_A = copy.deepcopy(A)
selection_sort_A = copy.deepcopy(A)
bubble_sort(bubble_sort_A)
print(*[elem.view for elem in bubble_sort_A])
if is_stable(A, bubble_sort_A):
print('Stable')
else:
print('Not stable')
selection_sort(selection_sort_A)
print(*[elem.view for elem in selection_sort_A])
if is_stable(A, selection_sort_A):
print('Stable')
else:
print('Not stable')
| k = int(input())
svn = 7
cnt = 1
for i in range(10**7):
svn %= k
if svn == 0:
print(cnt)
exit()
svn *= 10
svn += 7
cnt += 1
print(-1) | 0 | null | 3,117,671,464,192 | 16 | 97 |
n = int(input())
for i in range(1,10):
if (n%i==0) and ((n//i) in range(1,10)):
print("Yes")
break
else:
print("No") | n = int(input())
for i in range(9, 0, -1):
if n % i == 0 and n // i <= 9:
print('Yes')
exit()
print('No') | 1 | 160,371,425,890,752 | null | 287 | 287 |
import itertools
n=int(input())
list1=list(map(int,input().split()))
q=int(input())
list2=list(map(int,input().split()))
sum1=set()
for i in range(1,n+1):
x=list(itertools.combinations(list1,i))
for j in x:
sum1.add(sum(j))
for i in list2:
if i in sum1:
print("yes")
else:
print("no")
| def solve_knapsack_problem(A,n,m):
a=[[0 for i in range(m+1)]for j in range(n+1)]
for i in range(1,n+1):
for j in range(1,m+1):
if A[i-1]<=j:
a[i][j] = max(a[i-1][j-A[i-1]]+A[i-1],a[i-1][j])
else:
a[i][j] = a[i-1][j]
if a[i][j] == m:
return True
return False
if __name__ == "__main__":
n=int(input())
A=list(map(int,input().split()))
q=int(input())
m=list(map(int,input().split()))
result=[]
for i in range(q):
if solve_knapsack_problem(A,n,m[i]):
print("yes")
else:
print("no")
| 1 | 99,996,652,264 | null | 25 | 25 |
N, M = map(int, input().split())
S = ['a'] * (N+1)
for i in range(M):
s, c = list(map(int, input().split()))
if S[s] != 'a' and S[s] != str(c):
print(-1)
exit()
S[s] = str(c)
if S[1] == '0' and N > 1:
print(-1)
exit()
for i in range(1, N+1):
if S[i] == 'a':
if i == 1 and N > 1:
S[i] = '1'
else:
S[i] = '0'
print(int(''.join(S[1:])))
| def main():
a,b = input().split()
b = b[0] + b[2:]
print(int(a)*int(b)//100)
if __name__ == "__main__":
main()
| 0 | null | 38,761,940,045,950 | 208 | 135 |
n = int(input())
c = input()
d = c.count('R')
e = c[:d].count('R')
print(d-e) |
# 初期入力
from bisect import bisect_left
import sys
#input = sys.stdin.readline #文字列では使わない
N = int(input())
c =input().strip()
ans =0
r =[i for i, x in enumerate(c) if x == 'R'] #全体の中でRのIndex
r_num =len(r) #全体でRの数
ans =bisect_left(r,r_num) #呪われないためのRとWの境界
print(r_num -ans) #境界より右側のRの数 | 1 | 6,235,796,866,250 | null | 98 | 98 |
import numpy as np
n = int(input())
print(int(np.ceil(n / 2))) | import itertools
import functools
import math
from collections import Counter
from itertools import combinations
N=int(input())
print((N+1)//2)
| 1 | 58,933,437,633,188 | null | 206 | 206 |
from collections import *
x,y,a,b,c=map(int,input().split())
p=list(map(int,input().split()))
p.sort(reverse=True)
q=list(map(int,input().split()))
q.sort(reverse=True)
r=list(map(int,input().split()))
r.sort(reverse=True)
r=r+p[:x]+q[:y]
r.sort(reverse=True)
r=r[:x+y]
print(sum(r))
| (x, y, a, b, c), p, q, r = [map(int, o.split()) for o in open(0)]
print(sum(sorted(sorted(p)[-x:] + sorted(q)[-y:] + list(r))[-x-y:])) | 1 | 44,875,539,809,090 | null | 188 | 188 |
import numpy as np
MOD = 10 ** 9 + 7
N = int(input())
A = np.array(input().split(), dtype=np.int64)
total = 0
for shamt in range(65):
bits = np.count_nonzero(A & 1)
total += (bits * (N - bits)) << shamt
A >>= 1
if not A.any():
break
print(total % MOD) | 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])) | 0 | null | 61,737,611,375,508 | 263 | 2 |
import collections
def resolve():
n = int(input())
s = [input() for _ in range(n)]
c = collections.Counter(s)
max_count = c.most_common()[0][1]
ans = [i[0] for i in c.items() if i[1]==max_count]
for i in sorted(ans): print(i)
resolve() | # row = [int(x) for x in input().rstrip().split(" ")]
# n = int(input().rstrip())
# s = input().rstrip()
def resolve():
import sys
input = sys.stdin.readline
n = int(input().rstrip())
s_list = [input().rstrip() for _ in range(n)]
from collections import Counter
c = Counter(s_list)
max_count = c.most_common()[0][1]
words = [word for word, count in c.most_common() if count == max_count]
words.sort()
print("\n".join(words))
if __name__ == "__main__":
resolve()
| 1 | 70,044,135,264,430 | null | 218 | 218 |
# -*- coding: utf-8 -*-
import sys
from itertools import accumulate
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7
N, K, C = MAP()
S = input()
L = [0] * K
cur = 0
idx = 0
while idx < K:
if S[cur] == 'o':
L[idx] = cur
idx += 1
cur += C + 1
else:
cur += 1
R = [0] * K
cur = N - 1
idx = K - 1
while idx >= 0:
if S[cur] == 'o':
R[idx] = cur
idx -= 1
cur -= C + 1
else:
cur -= 1
ans = []
for i in range(K):
if L[i] == R[i]:
ans.append(L[i])
[print(a+1) for a in ans]
| import sys, bisect, math, itertools, heapq, collections
from operator import itemgetter
# a.sort(key=itemgetter(i)) # i番目要素でsort
from functools import lru_cache
# @lru_cache(maxsize=None)
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp():
'''
一つの整数
'''
return int(input())
def inpl():
'''
一行に複数の整数
'''
return list(map(int, input().split()))
n, k, c = inpl()
s = list(input())[:-1]
q = collections.deque()
cool = 0
left = [0] * n
right = [0] * n
val=-1
for i in range(n):
if cool<=0 and s[i]=="o" and val<k:
val += 1
cool = c
else:
cool-=1
left[i] = val
cool = 0
val+=1
for i in range(n-1,-1,-1):
if cool<=0 and s[i]=="o" and val>0:
val -= 1
cool = c
else:
cool-=1
right[i]=val
# print(left)
# print(right)
for i in range(n):
if left[i]==right[i] and (i == 0 or left[i] - left[i - 1] == 1) and (i == n - 1 or right[i + 1] - right[i] == 1):
print(i + 1)
| 1 | 40,606,114,827,252 | null | 182 | 182 |
N,A,B=map(int,input().split())
if (A-B)%2==0:
print(abs(A-B)//2)
else:
if (A+B)>N:
print((abs(A-B)-1)//2+(min(N-A,N-B)+1))
else:
print((abs(A-B)-1)//2+(min(A-1,B-1)+1)) | from collections import defaultdict
def readInt():
return int(input())
def readInts():
return list(map(int, input().split()))
def readChar():
return input()
def readChars():
return input().split()
n,a,b = readInts()
if (b-a)%2==0:
print((b-a)//2)
else:
print(min(b-1,n-a,a+(b-a-1)//2,n-(a+b-1)//2)) | 1 | 109,432,442,722,016 | null | 253 | 253 |
End of preview. Expand
in Dataset Viewer.
No dataset card yet
New: Create and edit this dataset card directly on the website!
Contribute a Dataset Card- Downloads last month
- 46