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=g... | 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... | 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
ta... | 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):
... | 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):
pr... | 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(ne... | # 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.inde... | 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 ra... | 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 ... | 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... | 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 - i... | 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:
... | 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 の位... | 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[n... | 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 | 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... | 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_t... | 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:
... | 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]) ... | 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... | 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... | 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
... | 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):
... | 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("e... | 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.r... | 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
... | 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... | 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 =... | 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):
no... | 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... | 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] == ">":
... | 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__":
... | 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):
... | 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
... | 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
#... | 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 ... | 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... | 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().... | 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)
... | 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(... | 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*... | 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 ):
pri... | 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"... | 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(" "... | 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 - x... | 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) ... | 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 <=... | """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]:
... | 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
... | 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
... |
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,
... | 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 | 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)
... | 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... | 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 | 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(... | 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, mu... | 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... | 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:
... | 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 [... | 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 >= 6... | _ = 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... | 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 i... | 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)
... | 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
amar... | 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... | 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('#', e... | #!/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:
... | 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]... | 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 ... | 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_c... | 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)] fo... | 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():
'''
一つの整数
... | 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 Data Studio
No dataset card yet
- Downloads last month
- 25