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())
memo = [[0] * (n+1) for x in range(n+1)]
def gcd(x,y):
if y == 0:
return x
if not memo[x][y] == 0:
return memo[x][y]
memo[x][y] = gcd(y,x % y)
return gcd(y,x % y)
res = 0
for i in range(1,n+1):
for j in range(1,n+1):
q = gcd(i,j)
if q == 1:
res += n
else:
for k in range(1,n+1):
p = gcd(q,k)
res += p
print(res)
|
import math
k = int(input())
s = 0
def gcd3(a, b, c):
d = math.gcd(a, b)
e = math.gcd(d, c)
return e
for a in range(1, k+1):
for b in range(a, k+1):
for c in range(b, k+1):
d = gcd3(a, b, c)
if a == b and b == c:
s += d
elif a == b or b == c:
s += d * 3
else:
s += d * 6
print(s)
| 1 | 35,330,848,902,112 | null | 174 | 174 |
n = int( input() )
x = input()
x_pop = x.count( "1" )
x_pls = x_pop + 1
x_mns = x_pop - 1
# 2の冪乗のリスト.ただし後々に備えてpopcountで割った余りにしてある
rp = [ pow( 2, i, x_pls ) for i in range( n + 1 ) ]
if x_mns > 0:
rm = [ pow( 2, i, x_mns ) for i in range( n + 1 ) ]
else:
rm = [ 0 ] * ( n + 1 )
x = x[ : : -1 ]
rem_p = 0
rem_m = 0
for i in range( n ):
if x[ i ] == "1":
rem_p += rp[ i ]
rem_m += rm[ i ]
for i in range( n - 1, -1, -1 ):
if x[ i ] == "0":
tmp = ( rem_p + rp[ i ] ) % x_pls
elif x_mns > 0:
tmp = ( rem_m - rm[ i ] ) % x_mns
else: # popcount( X_i ) == 0
print( 0 )
continue
ans = 1
while tmp > 0:
tmp = tmp % bin( tmp ).count( "1" )
ans += 1
print( ans )
|
N=int(input())
testimonies=[]
for i in range(N):
A=int(input())
testimony=[]
for j in range(A):
testimony.append(list(map(int,input().split())))
testimony[-1][0]-=1
testimonies.append(testimony)
ans=0
for i in range(2**N):
isContradiction=False
for j in range(N):
if not i&1<<j:continue
for x,y in testimonies[j]:
if i&1<<x:x=1
else:x=0
if not x==y:
isContradiction=True
break
if not isContradiction:
ans=max(ans,bin(i).count("1"))
print(ans)
| 0 | null | 65,135,474,807,370 | 107 | 262 |
n = int(input())
d = {}
for i in range(n):
[b, f, r, v] = list(map(int,input().split()))
key = f'{b} {f} {r}'
if key in d:
d[key] += v
else:
d[key] = v
for b in range(1,5):
for f in range(1,4):
for r in range(1,11):
key = f'{b} {f} {r}'
if key in d:
print(" "+str(d[key]),end="")
else:
print(" "+str(0),end="")
if r == 10:
print()
if r == 10 and f == 3 and b != 4:
print('####################')
|
import math
a = float(input())
b = math.acos(-1)
print "%f %f" % (a * a * b , 2 * a * b)
| 0 | null | 858,499,001,188 | 55 | 46 |
import time as ti
class MyQueue(object):
"""
My Queue class
Attributes:
queue: queue
head
tail
"""
def __init__(self):
"""Constructor
"""
self.length = 50010
self.queue = [0] * self.length
# counter = 0
# while counter < self.length:
# self.queue.append(Process())
# counter += 1
self.head = 0
self.tail = 0
# def enqueue(self, name, time):
def enqueue(self, process):
"""enqueue method
Args:
name: enqueued process name
time: enqueued process time
Returns:
None
"""
self.queue[self.tail] = process
# self.queue[self.tail].name = name
# self.queue[self.tail].time = time
self.tail = (self.tail + 1) % self.length
def dequeue(self):
"""dequeue method
Returns:
None
"""
# self.queue[self.head].name = ""
# self.queue[self.head].time = 0
self.queue[self.head] = 0
self.head = (self.head + 1) % self.length
def is_empty(self):
"""check queue is empty or not
Returns:
Bool
"""
if self.head == self.tail:
return True
else:
return False
def is_full(self):
"""chech whether queue is full or not"""
if self.tail - self.head >= len(self.queue):
return True
else:
return False
class Process(object):
"""process class
"""
def __init__(self, name="", time=0):
"""constructor
Args:
name: name
time: time
"""
self.name = name
self.time = time
def forward_time(self, time):
"""time forward method
Args:
time: forward time interval
Returns:
remain time
"""
self.time -= time
return self.time
def time_forward(my_queue, interval, current_time,):
"""
Args:
my_queue: queue
interval: time step interval
current_time: current time
"""
value = my_queue.queue[my_queue.head].forward_time(interval)
if value <= 0:
current_time += (interval + value)
print my_queue.queue[my_queue.head].name, current_time
my_queue.dequeue()
elif value > 0:
current_time += interval
name, time = my_queue.queue[my_queue.head].name, \
my_queue.queue[my_queue.head].time
my_queue.enqueue(my_queue.queue[my_queue.head])
my_queue.dequeue()
return current_time
my_queue = MyQueue()
n, q = [int(x) for x in raw_input().split()]
counter = 0
while counter < n:
name, time = raw_input().split()
my_queue.enqueue(Process(name, int(time)))
counter += 1
# end_time_list = []
current_time = 0
while not my_queue.is_empty():
current_time = time_forward(my_queue, q, current_time)
|
n, a, b = map(int, input().split())
MOD = 10**9+7
def comb(n, k, MOD):
x = 1
for i in range(k):
x *= (n-i)
x *= pow(i+1, MOD-2, MOD)
x %= MOD
return x
ans = pow(2, n, MOD) - 1 - comb(n, a, MOD) - comb(n, b, MOD)
ans += MOD
ans %= MOD
print(ans)
| 0 | null | 33,002,684,601,188 | 19 | 214 |
N=int(input())
ans=0
for num in range(1,N+1):
count=N//num
ans+=count*(count+1)//2*num
print(ans)
|
def main():
n = int(input())
ans = 0
for i in range(1, n+1):
tmp = n//i
ans += i*tmp*(tmp+1)//2
print(ans)
return
if __name__ == "__main__":
main()
| 1 | 11,165,826,641,440 | null | 118 | 118 |
import math
from functools import reduce
def gcd_list(numbers):
return reduce(math.gcd, numbers)
N=int(input())
A=list(map(int,input().split()))
mA = max(A)
D = [-1]*(mA+1)
D[0]=1
D[1]=1
for i in range(2,mA+1):
if D[i] != -1: continue
D[i] = i
cnt = 2*i
while cnt < mA+1:
if D[cnt] == -1:
D[cnt]=i
cnt += i
done = set()
for a in A:
tmp = set()
while a > 1:
tmp.add(D[a])
a //= D[a]
if len(done&tmp) > 0:
if gcd_list(A) == 1: print('setwise coprime')
else: print('not coprime')
exit()
done |= tmp
print('pairwise coprime')
|
import math
from functools import reduce
def getD(num):
input_list = [2 if i % 2 == 0 else i for i in range(num+1)]
input_list[0] = 0
bool_list = [False if i % 2 == 0 else True for i in range(num+1)]
sqrt = int(math.sqrt(num))
for serial in range(3, sqrt + 1, 2):
if bool_list[serial]:
for s in range(serial ** 2, num+1, serial):
if bool_list[s]:
input_list[s] = serial
bool_list[s] = False
return input_list
N = int(input())
A = list(map(int, input().split()))
D = getD(max(A))
pairwise_coprime = True
use_divnum = set()
for k in A:
while k != 1:
div = D[k]
if div in use_divnum:
pairwise_coprime = False
break
else:
use_divnum.add(div)
while k % div == 0 and k > 1:
k = k // div
if pairwise_coprime:
print('pairwise coprime')
exit()
if reduce(math.gcd, A) == 1:
print('setwise coprime')
else:
print('not coprime')
| 1 | 4,087,659,796,760 | null | 85 | 85 |
from math import gcd
K = int(input())
goukei = 0
for a in range(1,K+1):
for b in range(1,K+1):
G = gcd(a,b)
for c in range(1,K+1):
goukei += gcd(G,c)
print(goukei)
|
#d=日数, c=満足低下度, s=満足上昇度, t=コンテストの日程
d = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for i in range(d)]
t = [int(input()) for j in range(d)]
last = [0 for i in range(26)]
#print(c)
res = 0
count = 0
#while count != len(t):
for day in range(d):
res += s[day][t[day]-1]
last[t[day]-1] = day+1
#print(last)
#print(c[last[t[day]-1]])
for i in range(26):
#print(c[i] * (day + 1 - last[i]))
res -= c[i] * (day + 1 - last[i])
print(res)
| 0 | null | 22,699,298,691,500 | 174 | 114 |
# -*- coding: utf-8 -*-
while True:
x, y = map(int, raw_input().split())
if x+y:
if x < y:
print "%d %d" %(x, y)
else:
print "%d %d" %(y, x)
else:
break;
|
# coding:utf-8
# ??\??????????????´??°????°???????????????????
i = 1
x = 1
y = 1
while x != 0 or y != 0:
xy = raw_input().split()
x = int(xy[0])
y = int(xy[1])
if x == 0 and y ==0:
break
if x < y :
print x,y
else:
print y,x
| 1 | 516,403,969,830 | null | 43 | 43 |
import sys
while True:
try:
a,b = map(int,raw_input().split())
tempa = a
tempb = b
while tempa % tempb != 0 :
tempa , tempb = (tempb,tempa%tempb)
gcd = tempb
lcm = a * b / gcd
print "%d %d" % ( gcd, lcm)
except EOFError:
break
|
import math,sys
for e in sys.stdin:
a,b=list(map(int,e.split()));g=math.gcd(a,b)
print(g,a*b//g)
| 1 | 490,814,048 | null | 5 | 5 |
def main():
x = int(input())
ans = "Yes" if x >= 30 else "No"
print(ans)
if __name__ == "__main__":
main()
|
from collections import deque
K = int(input())
Q = deque()
for i in range(1, 10):
Q.append(i)
temp = 0
for i in range(K):
temp = Q.popleft()
if temp%10 != 0:
Q.append(temp*10+temp%10-1)
Q.append(temp*10+temp%10)
if temp%10 != 9:
Q.append(temp*10+temp%10+1)
print(temp)
| 0 | null | 22,983,023,395,872 | 95 | 181 |
x = int(input())
cx = int(x/100)
dx = x%100
while cx>0:
cx-=1
if dx>5:
dx-=5
else:
print(1)
exit()
print(0)
|
from functools import reduce
n = int(input())
a = list(map(int, input().split()))
b = reduce(lambda ac, x: ac ^ x, a)
print(*map(lambda x: x ^ b, a))
| 0 | null | 70,209,309,633,802 | 266 | 123 |
import sys
import itertools
import collections
def solve():
input = sys.stdin.readline
mod = 10 ** 9 + 7
n, k = list(map(int, input().rstrip('\n').split()))
ls = [0] + list(map(lambda x: int(x) - 1, input().rstrip('\n').split()))
ls = [i % k for i in list(itertools.accumulate(ls))]
d = collections.defaultdict(int)
t = 0
for i, x in enumerate(ls):
t += d[x]
d[x] += 1
if i >= k - 1:
d[ls[i - k + 1]] -= 1
print(t)
if __name__ == '__main__':
solve()
|
from sys import stdin
input = stdin.buffer.readline
print('No' if int(input()) < 30 else 'Yes')
| 0 | null | 71,713,388,850,884 | 273 | 95 |
#Take input separated by space(?)
h,a = map(int, input().split())
#Divide, just round off and add 1 if decimal
hit = round(h//a)
if h%a != 0:
hit = hit + 1
print(hit)
|
s = []
while True:
x = int(input())
if x == 0:
break
s.append(x)
for (i,num) in enumerate(s):
print('Case {0}: {1}'.format(i+1,num))
| 0 | null | 38,754,959,486,090 | 225 | 42 |
from sys import stdin
n = int(stdin.readline())
ans = 0
dp = [0]*(n+1)
for i in range(1,n+1):
j = i
while j <= n:
dp[j] += 1
j += i
for i in range(1,n+1):
ans += dp[i]*i
print(ans)
|
x = input()
while x !='0':
x_list = list(x)
#print(x_list)
#print("{0}".format(len(x_list)))
sum = 0
for i in range(len(x_list)):
sum += int(x_list[i])
print(sum)
x = input()
| 0 | null | 6,280,511,767,332 | 118 | 62 |
X = int(input())
for i in range(1, 1000):
if 100 * i <= X and X <= 105 * i:
print(1)
exit()
print(0)
|
num = int(input())
num_list = list(map(int,input().split(" ")))
print(min(num_list),max(num_list),sum(num_list))
| 0 | null | 63,805,415,516,030 | 266 | 48 |
def main():
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse = True)
ans = A[0]
kazu = (N-2)//2
amari = (N-2)%2
for i in range(1,kazu+1,1):
#print(i)
ans += (A[i]*2)
if amari==1:
ans += A[i+1]*amari
print(ans)
main()
|
#coding:utf-8
N = int(input())
A = [int(i) for i in input().split()]
A.sort(reverse = True)
k = N-2
index = 1
ans = A[0]
while k > 0:
if k > 1:
k -= 2
ans += A[index] * 2
elif k == 1:
k -= 1
ans += A[index]
index += 1
print("{}".format(ans))
| 1 | 9,127,967,687,450 | null | 111 | 111 |
from itertools import permutations as p
N = int(input())
P = tuple(map(int,input().split()))
Q = tuple(map(int,input().split()))
j = 0
for i in p(range(1, N + 1)):
j += 1
if i == P: a = j
if i == Q: b = j
if a - b >= 0: print(a - b)
else: print(b - a)
|
import itertools
N = int(input())
P = tuple(map(int,input().split()))
Q = tuple(map(int,input().split()))
lis = list(itertools.permutations(range(1,N+1)))
a = lis.index(P)+1
b = lis.index(Q)+1
ans = abs(a-b)
print(ans)
| 1 | 100,826,519,746,132 | null | 246 | 246 |
n=int(input())
P=list(map(int,input().split()))
m = n + 1
cnt = 0
for i in range(n):
if m >= P[i]:
m = P[i]
cnt += 1
print(cnt)
|
n,m,x=map(int,input().split())
c=[list(map(int,input().split())) for _ in range(n)]
import itertools
sum_min=10**7
for i in itertools.product([0,1],repeat=n):
level=[0]*m
for j in range(m):
level[j]=sum(i[k]*c[k][j+1] for k in range(n))
for l in range(m):
if level[l]<x:
break
else:
sum_min=min(sum_min,sum(i[k]*c[k][0] for k in range(n)))
print(sum_min if sum_min!=10**7 else -1)
| 0 | null | 53,996,957,785,430 | 233 | 149 |
import math
import sys
# sys.setrecursionlimit(100000)
def input():
return sys.stdin.readline().strip()
def input_int():
return int(input())
def input_int_list():
return [int(i) for i in input().split()]
def main():
n = input_int()
_x = []
_y = []
for _ in range(n):
x, y = input_int_list()
# 座標系を45度回転させて考える
_x.append(x - y)
_y.append(x + y)
ans = max(max(_x) - min(_x), max(_y) - min(_y))
print(ans)
return
if __name__ == "__main__":
main()
|
N = int(input())
a,b = [], []
for i in range(N):
x,y = map(int, input().split())
a.append(x-y)
b.append(x+y)
a.sort()
b.sort()
ans = max(a[-1] - a[0], b[-1] - b[0])
print(ans)
| 1 | 3,422,264,562,880 | null | 80 | 80 |
a = input()
b = input()
ans = '123'
ans = ans.replace(a, '').replace(b, '')
print(ans)
|
a = int(input())
b = int(input())
ans = {1,2,3} - {a,b}
print(ans.pop())
| 1 | 111,109,887,006,258 | null | 254 | 254 |
a,b,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
l=[list(map(int,input().split())) for _ in range(m)]
ans=min(a)+min(b)
for x,y,c in l:
ans=min(ans,a[x-1]+b[y-1]-c)
print(ans)
|
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 999999
for i in range(M):
x, y, c = map(int, input().split())
if x <= A and y <= B:
d = a[x - 1] + b[y - 1] - c
if d < ans:
ans = d
if (min(a) + min(b)) < ans:
ans = min(a) + min(b)
print(ans)
| 1 | 54,014,273,494,390 | null | 200 | 200 |
n = int(input())
cnt = 0
for i in range(1, n//2+1):
if i != n - i and n - i > 0:
cnt += 1
print(cnt)
|
n = int(input())
if n%2 :
print(n//2)
else:
print(n//2 - 1)
| 1 | 153,244,911,273,520 | null | 283 | 283 |
from collections import Counter
def main():
n = int(input())
s = input()
cnt = Counter(s)
ans = cnt["R"] * cnt["G"] * cnt["B"]
for gap in range(1, (n - 1) // 2 + 1):
for i in range(n - gap * 2):
if set([s[i], s[i + gap], s[i + 2 * gap]]) == {"R", "G", "B"}:
ans -= 1
print(ans)
if __name__ == "__main__":
main()
|
N = int(input())
S = list(input())
R = []
G = []
B = [0 for _ in range(N)]
b_cnt = 0
for i in range(N):
if S[i] == 'R':
R.append(i)
elif S[i] == 'G':
G.append(i)
else:
B[i] = 1
b_cnt += 1
answer = 0
for r in R:
for g in G:
answer += b_cnt
if (g-r)%2 == 0 and B[(r+g)//2] == 1:
answer -= 1
if 0 <= 2*g-r < N and B[2*g-r] == 1:
answer -= 1
if 0 <= 2*r-g < N and B[2*r-g] == 1:
answer -= 1
print(answer)
| 1 | 36,171,899,075,396 | null | 175 | 175 |
n,k = map(int,input().split())
if n < k:
rival_n = k - n
if n >= rival_n:
print(rival_n)
else:
print(n)
elif n == k:
print(0)
else:
n = n % k
rival_n = k - n
if n >= rival_n:
print(rival_n)
else:
print(n)
|
A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())
d = abs(A-B)
if d-(V-W)*T<=0:
print("YES")
else:
print("NO")
| 0 | null | 27,126,874,151,370 | 180 | 131 |
def main():
a, b, c = map(int, input().split())
if(a+b+c >= 22):
print('bust')
else:
print('win')
return 0
if __name__ == '__main__':
main()
|
v = sum(map(int,list(input().split())))
if(v > 21):
print('bust')
else:
print('win')
| 1 | 118,756,980,993,508 | null | 260 | 260 |
s = int(input())
MOD = 10**9 + 7
b3 = 1; b2 = 0; now = 0 # now == b1
for _ in range(s-2):
b1 = now
now = (b1 + b3) % MOD
b3, b2 = b2, b1
print(now)
|
s = int(input())
dp = [0] * (s + 11)
mod = 10 ** 9 + 7
dp[0] = 1
dp[1] = 0
dp[2] = 0
dp[3] = 1
c = 2
for i in range(4, s + 1):
dp[i] = (c - dp[i - 1] - dp[i - 2]) % mod
c = (c + dp[i]) % mod
print(dp[s])
| 1 | 3,277,393,946,332 | null | 79 | 79 |
x,y=map(int,input().split())
print("{0} {1} {2:.8f}".format(x//y,x%y,x/y))
|
a,b = map(int,input().split())
d,r = divmod(a,b)
print("{} {} {:.6f}".format(d,r,a/b))
| 1 | 592,816,546,140 | null | 45 | 45 |
N = int(input())
result = {}
result["AC"] = 0
result["WA"] = 0
result["TLE"] = 0
result["RE"] = 0
for i in range(N):
judge = input()
result[judge] += 1
for key, value in result.items():
print(f"{key} x {value}")
|
#!/usr/bin/env python3
import sys
from itertools import chain
from collections import Counter
# form bisect import bisect_left, bisect_right, insort_left, insort_right
# import numpy as np
def solve(N: int, S: "List[str]"):
d = Counter(S)
for key in ("AC", "WA", "TLE", "RE"):
print(f"{key} x {d.get(key, 0)}")
def main():
tokens = chain(*(line.split() for line in sys.stdin))
# N, S = map(int, line.split())
N = int(next(tokens)) # type: int
S = [next(tokens) for _ in range(N)] # type: "List[str]"
solve(N, S)
if __name__ == "__main__":
main()
| 1 | 8,682,281,758,172 | null | 109 | 109 |
from bisect import bisect_left, bisect, insort
def main():
n = int(input())
s = list(input())
q = int(input())
_is = {chr(i):[] for i in range(ord("a"), ord("a")+27)}
for i, si in enumerate(s):
_is[si].append(i)
for _ in range(q):
t, i, c = input().split()
i = int(i)-1
if t == "1":
if s[i] != c:
index = bisect_left(_is[s[i]], i)
del _is[s[i]][index]
insort(_is[c], i)
s[i] = c
else:
c = int(c) - 1
cnt = 0
for _isi in _is.values():
if _isi:
is_in = bisect(_isi, c)-bisect_left(_isi, i)
if is_in:
cnt += 1
print(cnt)
if __name__ == "__main__":
main()
|
count = input()
Ss = []
Hs = []
Cs = []
Ds = []
for i in range(int(count)):
mark, num = input().split()
if mark is 'S':
Ss.append(num)
elif mark is 'H':
Hs.append(num)
elif mark is 'C':
Cs.append(num)
elif mark is 'D':
Ds.append(num)
for i in range(1,14):
if not(str(i) in Ss):
print("S {0}".format(str(i)))
for i in range(1,14):
if not(str(i) in Hs):
print("H {0}".format(str(i)))
for i in range(1,14):
if not(str(i) in Cs):
print("C {0}".format(str(i)))
for i in range(1,14):
if not(str(i) in Ds):
print("D {0}".format(str(i)))
| 0 | null | 31,969,196,857,480 | 210 | 54 |
import sys
s1=raw_input()
s2=raw_input()
for idx, s in enumerate(s1):
if s2[0] != s:
continue
s1_idx = idx
s2_idx = 0
while True:
s1_now = s1[s1_idx:]
s2_now = s2[s2_idx:]
if len(s1_now) >= len(s2_now):
if s1_now.startswith(s2_now):
print "Yes"
sys.exit(0)
else:
break
else:
if s2_now.startswith(s1_now):
s1_idx = 0
s2_idx += len(s1_now)
else:
break
print "No"
|
s = int(input())
#最後に切った場所がiであるようなパターンの数をdp[i]とする
dp=[0]*(s+1)
dp[0]=1
if s<3:
print("0")
else:
for i in range(3,s+1):
dp[i]=dp[i-1]+dp[i-3]
dp.append(dp[i])
score=dp[s]%(10**9+7)
print(score)
| 0 | null | 2,506,248,403,332 | 64 | 79 |
X = int(input())
if X == 2:
print(2)
exit()
for i in range(X,2*X):
for j in range(2,i):
if i % j == 0:
break
if j == i-1:
print(i)
exit()
|
X = int(input())
a = []
c = []
if X % 2 == 1:
while a == []:
for i in range(3,X,2):
b = X % i
a.append(b)
if 0 in a:
a = []
X += 1
else:
print(X)
elif X == 2:
print(X)
else:
X += 1
while c == []:
for i in range(3,X,2):
d = X % i
c.append(d)
if 0 in c:
c = []
X += 1
else:
print(X)
| 1 | 105,810,885,371,532 | null | 250 | 250 |
import sys
for i, x in enumerate(map(int, sys.stdin)):
if not x: break
print("Case {0}: {1}".format(i + 1, x))
|
x = int(input())
i=1
while x!=0:
print('Case {0}: {1}'.format(i,x))
x = int(input())
i+=1
| 1 | 487,288,799,272 | null | 42 | 42 |
N = int(input())
S = str(input())
print(S.count("ABC"))
|
ans=-10**18
a,b,c,d=map(int,input().split())
if a<=0<=b or c<=0<=d:
ans=0
ans=max(ans,a*c,a*d,b*c,b*d)
print(ans)
| 0 | null | 51,192,137,765,220 | 245 | 77 |
n, d = map(int, input().split())
xy = [map(int, input().split()) for _ in range(n)]
x, y = [list(i) for i in zip(*xy)]
ans = 0
d = d ** 2
for i in range(n):
if ( x[i] ** 2 + y[i] ** 2 ) <= d:
ans += 1
print(ans)
|
import sys
input = sys.stdin.readline
def main():
N, D = map(int, input().split())
D = D ** 2
ans = 0
for _ in range(N):
X, Y = map(int, input().split())
if X ** 2 + Y ** 2 <= D:
ans += 1
print(ans)
if __name__ == '__main__':
main()
| 1 | 5,960,922,733,350 | null | 96 | 96 |
n,*d=map(int,open(0).read().split())
ans=0
for i in range(n):
for j in range(i+1,n):
ans+=d[i]*d[j]
print(ans)
|
def popcount(x):
c = 0
while x > 0:
if x & 1: c += 1
x //= 2
return c
def f(x):
if x==0: return 0
return f(x % popcount(x)) + 1
n = int(input())
X = input()
po = X.count('1')
pp = po + 1
pm = max(1, po - 1)
rp = rm = 0
for x in X:
rp = (rp*2 + int(x)) % pp
rm = (rm*2 + int(x)) % pm
bp = [0]*(n) # 2^i % (po+1)
bm = [0]*(n) # 2^i % (po-1)
bp[n-1] = 1 % pp
bm[n-1] = 1 % pm
for i in range(n-1, 0, -1):
bp[i-1] = bp[i]*2 % pp
bm[i-1] = bm[i]*2 % pm
for i in range(n):
if X[i] == '0': ri = (rp + bp[i]) % pp
else:
if po-1 != 0: ri = (rm - bm[i]) % pm
else:
print(0)
continue
print(f(ri) + 1)
| 0 | null | 88,653,913,174,330 | 292 | 107 |
cnt = 0
def insertionSort(A, n, g):
global 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 = j - g
cnt += 1
A[j + g] = v
def shellSort(A, n):
G = [1]
for i in range(1, 100):
G.append(G[i - 1] * 3 + 1)
G = list(reversed([g for g in G if g <= n]))
m = len(G)
print(m)
if G:
print(*G)
for i in range(m):
insertionSort(A, n, G[i])
print(cnt)
n = int(input())
A = [int(input()) for _ in range(n)]
shellSort(A, n)
[print(a) for a in A]
|
import math
def print_list(a):
out = ''
for ai in a:
out += str(ai) + ' '
else:
out = out[:-1]
print(out)
def insertion_sort(a, n, g):
cnt = 0
for i in range(g, n):
v = a[i]
j = i - g
while j >= 0 and a[j] > v:
a[j + g] = a[j]
j = j - g
cnt += 1
a[j + g] = v
return cnt
def shell_sort(a, n):
cnt = 0
m = 0
g = []
h = 1
while True:
if h > n:
break
m += 1
g.append(h)
h = 3 * h + 1
g.reverse()
for i in range(m):
cnt += insertion_sort(a, n, g[i])
print(m)
print_list(g)
print(cnt)
for i in a:
print(i)
n = int(input())
a = [0] * n
for i in range(n):
a[i] = int(input())
shell_sort(a, n)
| 1 | 28,540,606,248 | null | 17 | 17 |
def main():
import sys
asa = sys.stdin.readline
n = int(input())
s = list(map(int, asa().split()))
q = int(input())
t = list(map(int, asa().split()))
c = 0
s.append(0)
for i in t: # tの中のiを探索
j = 0
s[n] = i
while s[j] != i:
j += 1
if j < n:
c += 1
print(c)
if __name__ == '__main__':
main()
|
n =int(input())
S = list(map(int, input().split(' ')))
q = int(input())
T = list(map(int, input().split(' ')))
count = 0
for t in T:
if t in S:
count += 1
print(count)
| 1 | 68,125,633,050 | null | 22 | 22 |
n = int(input())
num = int(n / 2)
if n % 2 == 1:
num += 1
print(num)
|
N = int(input())
A = list(map(int,input().split()))
B = set()
for a in A:
if a in B:
print('NO')
exit()
else:
B.add(a)
print('YES')
| 0 | null | 66,180,268,646,048 | 206 | 222 |
S = int(input())
dp = [0] * (S + 1)
dp[0] = 1
M = 10 ** 9 + 7
for i in range(1, S + 1):
num = 0
for j in range(i - 2):
num += dp[j]
dp[i] = num % M
print(dp[S])
|
from copy import deepcopy
h,w,k = map(int, input().split())
strawberry_count = [0 for i in range(h)]
cakes = []
for i in range(h):
cakes.append(list(input()))
strawberry_count[i] = cakes[i].count('#')
ans = []
first_index = 10000
use_number = 0
for i in range(h):
append_array = []
if strawberry_count[i] >= 2:
first_index = min(first_index,i)
use_number += 1
first = True
for j in range(w):
if cakes[i][j] == '#':
if first:
first = False
else:
use_number += 1
append_array.append(use_number)
elif strawberry_count[i] == 1:
use_number += 1
first_index = min(first_index,i)
append_array = [use_number for i in range(w)]
else:
append_array = []
ans.append(append_array)
print_count = 0
pre_array = []
for i in range(h):
if len(ans[i]) == 0:
if print_count > 0:
print(" ".join(map(str,pre_array)))
else:
print(" ".join(map(str,ans[first_index])))
pre_array = ans[first_index]
print_count += 1
else:
print(" ".join(map(str, ans[i])))
pre_array = ans[i]
print_count += 1
| 0 | null | 73,566,401,264,160 | 79 | 277 |
import sys
import math
import itertools
import collections
from collections import deque
from collections import defaultdict
sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
MOD2 = 998244353
INF = float('inf')
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()
def main():
N, X, M = NMI()
tmp = X%M
ls = []
ls.append(tmp)
for n in range(N-1):
tmp = (tmp ** 2)%M
if tmp in ls:
ls_before_loop = ls[:ls.index(tmp)]
ls_in_loop = ls[ls.index(tmp):]
break
else:
ls.append(tmp)
if len(ls) == N:
print(sum(ls))
else:
sum_before_loop = sum(ls_before_loop)
sum_in_loop = ((N-len(ls_before_loop))//(len(ls_in_loop)))*sum(ls_in_loop)
sum_after_loop = sum(ls_in_loop[:(N-((N-len(ls_before_loop))//(len(ls_in_loop)))*len(ls_in_loop))-len(ls_before_loop)])
print(sum_before_loop+sum_in_loop+sum_after_loop)
if __name__ == '__main__':
main()
|
N,A,B = (int(x) for x in input().split())
if (B - A) % 2 == 0:
print((B-A)//2)
else:
if B - A == 1:
if A == 1 or B == N:
print('1')
else:
print('2')
else:
if A <= N-B:
print((A+B-1)//2)
else:
print((2*N-A-B+1)//2)
| 0 | null | 56,016,926,608,932 | 75 | 253 |
from sys import stdin
X = [ 0 for i in range(100) ]
d = [ 0 for i in range(100) ]
f = [ 0 for i in range(100) ]
G = [[ 0 for i in range(100) ] for i in range(100)]
t = 0
def DFS(i) :
global t
t += 1
d[i] = t
for j in range(n) :
if G[i][j] != 0 and d[j] == 0 : DFS(j)
t += 1
f[i] = t
n = int(input())
for i in range(n) :
X[i] = stdin.readline().strip().split()
for i in range(n) :
for j in range(int(X[i][1])) :
G[int(X[i][0])-1][int(X[i][j+2])-1] = 1
for i in range(n) :
if d[i] == 0 : DFS(i)
for i in range(n) : print(i+1,d[i],f[i])
|
n,k = map(int, input().split())
h = [int(x) for x in input().split()]
if n<=k:
print(0)
exit()
h.sort()
print(sum(h[:n-k]))
| 0 | null | 39,360,848,784,514 | 8 | 227 |
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT() : return int(input())
def MAP() : return map(int,input().split())
def LIST() : return list(MAP())
n = INT()
x = [[0]*2 for i in range(n)]
for i in range(n):
x[i][0], x[i][1] = MAP()
x.sort()
tmp = -inf
ans = n
for i in range(n):
if tmp > x[i][0] - x[i][1]:
ans -= 1
tmp = min(tmp, x[i][0] + x[i][1])
else:
tmp = x[i][0] + x[i][1]
print(ans)
|
def resolve():
"""
典型的な区間スケジューリング問題
各スケジュールの終了時間が短いものから選択していけば,
選択するスケジュール数が最大になる.
今回は腕の可動範囲上限の小さいものから選択していく.
"""
import sys
readline = sys.stdin.readline
N = int(readline())
XL = [list(map(int, readline().split())) for _ in [0] * N]
# 腕の可動範囲の(上限, 下限)のリスト生成
t = [(x + length, x - length) for x, length in XL]
# 複数要素を含む要素のsortではインデックスの小さい要素から比較していきソート
t.sort() # リストを腕の上限の昇順(小さい順)でソート
time = -float('inf') # time=0でもおk
ans = 0
for i in range(N):
end, start = t[i] # tはソート済故,上限が小さい順に選出される
if time <= start: # 腕の下限が既存の腕と重ならないか判定
ans += 1
time = end # 現在の腕の上限を記録
print(ans)
if __name__ == "__main__":
resolve()
| 1 | 89,913,249,946,410 | null | 237 | 237 |
inData = int(input())
inSeries = [int(i) for i in input().split()]
outData =[0]*inData
for i in range(inData):
outData[i] = inSeries[inData-1-i]
print(" ".join(map(str,outData)))
|
stack = input().split()
temp = []
num=0
for loop in stack:
a = loop
if a is "+":
num = temp.pop() + temp.pop()
temp.append(num)
elif a is "-":
b=temp.pop()
c=temp.pop()
num = c-b
temp.append(num)
elif a is "*":
num = temp.pop() * temp.pop()
temp.append(num)
else:
temp .append(int(a))
print(temp[0])
| 0 | null | 505,064,987,492 | 53 | 18 |
cnt = 0
for i in range(int(input())):
c_num = int(input())
if cnt == 0:
r_min = c_num
elif cnt == 1:
p_max = c_num - r_min
if c_num < r_min:
r_min = c_num
else:
if p_max < c_num - r_min:
p_max = c_num - r_min
if c_num < r_min:
r_min = c_num
cnt += 1
print(p_max)
|
from sys import stdin
n = int(input())
r=[int(input()) for i in range(n)]
rv = r[::-1][:-1]
m = None
p_r_j = None
for j,r_j in enumerate(rv):
if p_r_j == None or p_r_j < r_j:
p_r_j = r_j
if p_r_j > r_j:
continue
r_i = min(r[:-(j+1)])
t = r_j - r_i
if m == None or t > m:
m = t
print(m)
| 1 | 13,345,638,400 | null | 13 | 13 |
A,B = map(str,input().split())
A = int(A)
B1 = int(B[0])
B2 = int(B[-2])
B3 = int(B[-1])
ans = A*(100*B1+10*B2+B3)//100
print(int(ans))
|
A,B = list(input().split())
A = int(A)
B = int((float(B)+0.005)*100)
print(A*B//100)
| 1 | 16,589,420,071,860 | null | 135 | 135 |
ring = input() * 2
s = input()
if s in ring:
print('Yes')
else:
print('No')
|
s=[ord(i) for i in input()]
n=[ord(i) for i in input()]
flag=0
flack=0
for i in range(len(s)):
flack=0
if n[0]==s[i]:
flack=1
for j in range(1,len(n)):
if i+j>=len(s):
if n[j]==s[i+j-len(s)]:
flack=flack+1
else:
break
else:
if n[j]==s[i+j]:
flack=flack+1
else:
break
if flack==len(n):
flag=1
break
if flag:
print('Yes')
else:
print('No')
| 1 | 1,732,704,543,140 | null | 64 | 64 |
N = input()
ans = "Yes" if (N[2] == N[3]) and (N[4] == N[5]) else "No"
print(ans)
|
from math import ceil
N,K = list(map(int, input().split()))
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort(reverse=True)
F.sort()
wk = 0
for i in range(N):
wk += A[i] * F[i]
#print(wk)
def is_ok(arg):
# 条件を満たすかどうか?問題ごとに定義
cnt = 0
for i in range(N):
a,f = A[i], F[i]
if a*f <= arg:
continue
else:
#(a-k) * f <= arg
# a - arg/f <= k
cnt += ceil(a-arg/f)
return cnt <= K
def meguru_bisect(ng, ok):
'''
初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す
まずis_okを定義すべし
ng ok は とり得る最小の値-1 とり得る最大の値+1
最大最小が逆の場合はよしなにひっくり返す
'''
while (abs(ok - ng) > 1):
mid = (ok + ng) // 2
if is_ok(mid):
ok = mid
else:
ng = mid
return ok
ng = -1
ok = 10**12 + 10
ans = meguru_bisect(ng,ok)
print(ans)
| 0 | null | 103,378,270,216,640 | 184 | 290 |
m_one = list(map(int, input().split()))
m_two = list(map(int,input().split()))
print(1 if m_one[1] > m_two[1] else 0)
|
import sys
stdin = sys.stdin
ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))
sys.setrecursionlimit(10 ** 7)
def main():
m, d = na()
n, s = na()
if s == 1:
print(1)
else:
print(0)
if __name__ == '__main__':
main()
| 1 | 124,170,047,575,122 | null | 264 | 264 |
s=input()
print(('RRR'in s)+('RR'in s)+('R'in s))
|
n,k=map(int,input().split())
p=list(map(int,input().split()))
c=list(map(int,input().split()))
for i in range(n):
p[i]-=1
ans=max(c)
for i in range(n):
f=i
r=0
l=[]
while True:
f=p[f]
l.append(c[f])
r+=c[f]
if f==i:
break
t=0
for j in range(len(l)):
t+=l[j]
ret=t
if r>0:
e=(k-j-1)//len(l)
ret+=r*e
ans=max(ans,ret)
print(ans)
| 0 | null | 5,132,507,848,610 | 90 | 93 |
# coding: utf-8
a = int(input())
b = int(input())
if a + b == 3:
print("3")
elif a + b == 4:
print("2")
else:
print("1")
|
A=int(input())
#pr#print(A)
int(A)
B=int(input())
if A + B == 3:
print(3)
elif A+B==4:
print(2)
else:
print(1)
| 1 | 110,673,662,956,078 | null | 254 | 254 |
#
import sys
input=sys.stdin.readline
def main():
H,W,K=map(int,input().split())
mas=[input().strip("\n") for i in range(H)]
mincut=H*W
for bit in range(2**(H-1)):
sep=[]
for s in range(H-1):
if (bit>>s)&1:
sep.append(s)
cutcnt=len(sep)
cnt=[0]*(len(sep)+1)
for j in range(W):
ci=0
cntt=cnt[:]
for i in range(H):
if mas[i][j]=="1":
cnt[ci]+=1
if i in sep:
ci+=1
if max(cnt)>K:
for i in range(len(sep)+1):
cnt[i]-=cntt[i]
cutcnt+=1
if max(cnt)>K:
cutcnt=10000000000
if cutcnt<mincut:
mincut=cutcnt
print(mincut)
if __name__=="__main__":
main()
|
import itertools
H,W,K = map(int,input().split())
S = []
for i in range(H):
s= map(int,input())
S.append(list(s))
l = list(itertools.product([0,1], repeat=H-1))
l = [list(li) for li in l]
for i in range(len(l)):
l[i] = [j+1 for j in range(len(l[i])) if l[i][j] > 0]
S_t = [list(x) for x in zip(*S)]
for i in range(W):
for j in range(1,H):
S_t[i][j] += S_t[i][j-1]
flag = False
min_cnt = H*W
for i in range(len(l)):
cnt = 0
bh = [0]+[li for li in l[i] if li > 0]+[H]
white = [0]*(len(bh)-2+1)
j = 0
while j < W:
if flag == True:
white = [0]*(len(bh)-2+1)
cnt += 1
flag = False
for k in range(len(bh)-1):
if bh[k] == 0:
su = S_t[j][bh[k+1]-1]
else:
su = S_t[j][bh[k+1]-1]-S_t[j][max(0,bh[k]-1)]
if white[k] + su > K:
if su > K:
j = W
cnt = H*W+1
flag = False
else:
flag = True
break
white[k] += su
if flag == False:
j += 1
min_cnt = min(cnt+len(bh)-2,min_cnt)
print(min_cnt)
| 1 | 48,383,231,070,492 | null | 193 | 193 |
N=int(input())
c=input()
R=c.count('R')
RR=c[0:R].count('R')
print(min(R-RR,R,N-R))
|
n,k,*l=map(int,open(0).read().split())
for _ in range(k):
s=[0]*(n+1)
for i in range(n):
s[max(i-l[i],0)]+=1
s[min(i+l[i]+1,n)]-=1
for i in range(n):
s[i+1]+=s[i]
s.pop()
if s==l: break
l=s
print(*l)
| 0 | null | 10,853,028,366,192 | 98 | 132 |
while True:
h, w=map(int, input().split())
if h == 0 and w==0: break
print("#"*w)
for i in range(h-2):
print("#"+"."*(w-2)+"#")
print("#"*w)
print()
|
for i in range(10000):
x = input().split()
h = int(x[0])
w = int(x[1])
if h == 0 and w ==0:
break
for i in range(w):
print("#",end="")
print()
for i in range(h-2):
print("#",end="")
for i in range(w-2):
print(".",end="")
print("#",end="")
print()
for i in range(w):
print("#",end="")
print()
print()
| 1 | 822,652,401,400 | null | 50 | 50 |
operand = ["+", "-", "*"]
src = [x if x in operand else int(x) for x in input().split(" ")]
stack = []
for s in src:
if isinstance(s, int):
stack.append(s)
continue
b, a = stack.pop(), stack.pop()
if s == "+":
stack.append(a+b)
elif s == "-":
stack.append(a-b)
elif s == "*":
stack.append(a*b)
print(stack[0])
|
import collections
n=int(input())
a=list(map(int,input().split()))
if a[0]==0 and a.count(0)==1:
ans=1
else:
ans=0
a=collections.Counter(a)
for i in range(max(a)):
ans*=a[i]**a[i+1]
ans%=998244353
print(ans)
| 0 | null | 77,714,722,010,432 | 18 | 284 |
A, B = map(int, input().split())
if A <= 2 * B:
print('0')
else:
print(A - 2 * B)
|
from sys import stdin,stdout
def INPUT():return list(int(i) for i in stdin.readline().split())
import math
def inp():return stdin.readline()
def out(x):return stdout.write(x)
import math as M
MOD=10**9+7
import sys
#####################################
a,b=INPUT()
if a>=2*b:
print(a-2*b)
else:
print(0)
| 1 | 166,930,378,256,812 | null | 291 | 291 |
letter = input()
if letter == letter.upper():
print("A")
else:
print("a")
|
s=input()
if s<='Z':print('A')
else:print('a')
| 1 | 11,296,981,504,732 | null | 119 | 119 |
# ABC168D
# https://atcoder.jp/contests/abc168/tasks/abc168_d
n,m=map(int, input().split())
ab=[[]for _ in range(n)]
for i in range(m):
a,b = list(map(int, input().split()))
a,b = a-1, b-1
ab[a].append(b)
ab[b].append(a)
'''
まず両方を追加する考えがなかった。
浅い部屋からも深い部屋からも参照できる。
その代わりに visitedで考えなくて良い部屋を記録している。
部屋1につながっているのはもっとも浅い部屋でそこから考えることがきっかけになる?
'''
#print(ab)
ans = [0]*n
visited={0}
stack=[0]
for i in stack:
'''
現在考えている部屋を stack、そこにつながる部屋 ab[i]として考える。
stack=[0]なので1の部屋から始める。なので深さ1の部屋が ab[i](ab[0])で分かる。
i==0の始めの一周では、ab[i]は深さ1の部屋のリストであり、それぞれの部屋を jとして順番に考える。
(このように深さ1から考えられる+次に深さ2の部屋を求めるというのが上手くいく)
その現在考えている部屋 i(stackの循環)とそこにつながる部屋 j(abの循環)なので、
部屋 jはより浅い部屋 iを道しるべにすればよい。
しかし、ab[a], ab[b]と両方を追加しているので、浅い部屋も深い部屋も abには含まれている。
浅い部屋から順に考えているので、過去に調べた abの値は無視するために visitedを導入する。たぶん。
'''
for j in ab[i]:
#print(i,j,'----------------------')
if j in visited:
continue
stack.append(j)
visited.add(j)
ans[j]=i+1
#print('stack', stack)
#print('visited', visited)
#print('ans', ans)
check=0
for i in ans[1:]:
if i==0:check==1
if check:
print('No')
else:
print("Yes")
print(*ans[1:])
|
def main():
X, Y, Z = map(int, input().split())
return " ".join(map(str, [Z, X, Y]))
if __name__ == '__main__':
print(main())
| 0 | null | 29,252,090,080,040 | 145 | 178 |
import sys
import fractions
input = sys.stdin.readline
mod = 10 ** 9 + 7
N = int(input().strip())
A = list(map(int, input().strip().split(" ")))
lcm = 1
for a in A:
lcm = a // fractions.gcd(a, lcm) * lcm
print(sum([lcm // a for a in A]) % mod)
|
def gcd(n, m):
if m == 0:
return n
return gcd(m, n % m)
N = int(input())
A = list(map(int,input().split()))
mod = 10**9+7
kbs = A[0]
for i in range(1,N):
kbs = kbs*A[i]//gcd(kbs,A[i])
kbs %= mod
ans = 0
for i in range(N):
ans += pow(A[i],mod-2,mod)
ans %= mod
print(kbs*ans%mod)
| 1 | 87,724,127,996,100 | null | 235 | 235 |
n, x, m = map(int, input().split())
v = list(range(m))
p = [-1 for _ in range(m)]
a = x
p[a - 1] = 0
s = [x]
l, r = n, n
for i in range(n):
a = a ** 2 % m
if p[a - 1] >= 0:
l, r = p[a - 1], i + 1
break
else:
s.append(a)
p[a - 1] = i + 1
ans = sum(s[:l])
if l != r:
b = (n - 1 - i) // (r - l) + 1
c = (n - 1 - i) % (r - l)
ans += b * sum(s[l:r]) + sum(s[l:l + c])
print(ans)
|
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
sum_res = sum(A)
counter = [0 for _ in range(10 ** 5 + 1)]
for a in A:
counter[a] += 1
for _ in range(Q):
B, C = map(int, input().split())
sum_res += (C - B) * counter[B]
counter[C] += counter[B]
counter[B] = 0
print(sum_res)
| 0 | null | 7,544,849,397,344 | 75 | 122 |
# usr/bin/python
# coding: utf-8
################################################################################
# Is it a Right Triangle?
# Write a program which judges wheather given length of three side form a right triangle.
# Print "YES" if the given sides (integers) form a right triangle, "NO" if not so.
#
# Input
# Input consists of several data sets. In the first line, the number of data set,
# N is given. Then, N lines follow, each line corresponds to a data set.
# A data set consists of three integers separated by a single space.
#
# Constraints
# 1 ??? length of the side ??? 1,000
# N ??? 1,000
# Output
# For each data set, print "YES" or "NO".
#
# Sample Input
# 3
# 4 3 5
# 4 3 6
# 8 8 8
# Output for the Sample Input
# YES
# NO
# NO
#
################################################################################
if __name__ == "__main__":
num = int(input())
inputline = [""]*num
for i in range(0,num):
inputline[i] = input()
for line in inputline:
a = int(line.split(" ")[0])
b = int(line.split(" ")[1])
c = int(line.split(" ")[2])
if (a*a+b*b == c*c or b*b+c*c == a*a or c*c+a*a == b*b):
print("YES")
else:
print("NO")
|
def kochfunc(n1, x1, y1, x2, y2): #関数作成
if n1 > n-1: #breakの条件
return
root3 = 1.732050807
sx = (x1*2 + x2)/3 ; sy = (y1*2 + y2)/3
tx = (x1 + x2*2)/3 ; ty = (y1 + y2*2)/3
vx = tx-sx; vy = ty-sy
ux = sx + (vx - vy*root3)/2
uy = sy + (vx*root3 + vy)/2
kochfunc(n1+1, x1, y1, sx, sy) #再帰関数
print('{:.8f}'.format(sx), '{:.8f}'.format(sy))
kochfunc(n1+1, sx, sy, ux, uy)
print('{:.8f}'.format(ux), '{:.8f}'.format(uy))
kochfunc(n1+1, ux, uy, tx, ty)
print('{:.8f}'.format(tx), '{:.8f}'.format(ty))
kochfunc(n1+1, tx, ty, x2, y2)
n = int(input())
print('{:.8f}'.format(0), '{:.8f}'.format(0))
kochfunc(0, 0, 0, 100, 0)
print('{:.8f}'.format(100), '{:.8f}'.format(0))
| 0 | null | 63,635,994,732 | 4 | 27 |
a,b=open(0);c=1;
for i in sorted(b.split()):
c*=int(i)
if c>10**18:print(-1);exit()
print(c)
|
a1,a2,a3=(int(x) for x in input().split())
if a1+a2+a3>=22:
print("bust")
else:
print("win")
| 0 | null | 67,768,108,063,968 | 134 | 260 |
def main():
N, M = map(int, input().split())
digits = [-1] * N
for _ in range(M):
s, c = map(int, input().split())
s -= 1
if ~digits[s] and digits[s] != c:
print(-1)
return
digits[s] = c
if N == 1:
print(max(0, digits[0]))
return
if digits[0] == 0:
print(-1)
return
if digits[0] == -1:
digits[0] = 1
ans = ''.join(map(str, (d if ~d else 0 for d in digits)))
print(ans)
if __name__ == '__main__':
main()
|
a, b, c, d = [int(e) for e in input().split(" ")]
print(max((a*c), (a*d), (b*c), (b*d)))
| 0 | null | 31,721,723,327,312 | 208 | 77 |
n,a,b=map(int,input().split())
s=a+b
if n%s==0:
print(int(n/s)*a)
else:
if n%s>=a:
print(int(n//s+1)*a)
else:
print(int(n//s)*a+n%s)
|
import math
N, A, B = map(int, input().split())
K = math.floor(N // (A + B))
blue = A * K
L = N % (A + B)
if L > A:
blue += A
else:
blue += L
print(blue)
| 1 | 55,559,392,729,984 | null | 202 | 202 |
N = int(input())
R = [int(input()) for i in range(N)]
maxv = -20000000000
minv = R[0]
for i in range(1, N):
maxv = max(R[i] - minv, maxv)
minv = min(R[i], minv)
print(maxv)
|
n = int(input())
sum = 0
for i in range(n + 1):
if i % 3 != 0 and i % 5 != 0 and i % 15 != 0:
sum += i
print(sum)
| 0 | null | 17,371,909,569,222 | 13 | 173 |
a = []
while True:
n = int(raw_input())
if n == 0:
break
a.append(n)
for i in range(len(a)):
print "Case " + str(i +1) + ": " + str(a[i])
|
flag = "go"
cnt = 0
while flag == "go":
cnt += 1
x = int(input())
if x == 0:
flag = "stop"
else:
print("Case " + str(cnt) + ": " + str(x))
| 1 | 490,921,065,570 | null | 42 | 42 |
N = int(input())
D = list(map(int, input().split()))
mod = 998244353
from collections import Counter, deque
def solve(N,D):
if D[0]!=0:
return 0
c = Counter(D)
if c[0]>1:
return 0
ans = 1
m = max(D)
for i in range(1,m):
if c[i]==0:
ans = 0
continue
ans *= pow(c[i],c[i+1],mod)
ans %= mod
return ans
print(solve(N,D))
|
a,b=map(int,input().split())
s=[''.join([str(a)]*b),''.join([str(b)]*a)]
print(sorted(s)[0])
| 0 | null | 119,706,119,556,480 | 284 | 232 |
import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7
def main():
N = int(readline())
A = list(map(int, readline().split()))
R = 0
G = 0
B = 0
ans = 1
for i in range(N):
a = A[i]
count = 0
if R==a:
R+=1
count+=1
if G==a:
count+=1
if B==a:
count+=1
else:
if G==a:
G+=1
count+=1
if B==a:
count+=1
else:
if B==a:
B+=1
count+=1
else:
print(0)
exit()
ans*=count
ans%=MOD
print(ans)
if __name__ == '__main__':
main()
|
import sys
n=int(input())
A=list(map(int,input().split()))
p=10**9+7
status=[1,0,0]
ans=3
if A[0]!=0:
print(0)
sys.exit()
for i in range(1,n):
count=status.count(A[i])
if count==0:
print(0)
sys.exit()
ans=(ans*count)%p
status[status.index(A[i])]+=1
print(ans)
| 1 | 130,274,704,525,978 | null | 268 | 268 |
while True:
data=map(int,list(raw_input()))
if data==[0]: break
print sum(data)
|
n, d = [int(s) for s in input().split()]
d2 = d ** 2
ans = 0
for _ in range(n):
x, y = [int(s) for s in input().split()]
if x ** 2 + y ** 2 <= d2:
ans += 1
print(ans)
| 0 | null | 3,790,084,106,720 | 62 | 96 |
import math
while True:
try:
a,b=list(map(int,input().split()))
x=math.gcd(a,b)
y=int(a*b/x)
print("%d %d"%(x,y))
except:
break
|
import sys
def gcd(a, b):
while b:
a, b = b, a % b
return a
def lcm(a, b):
return a * b / gcd(a, b)
for s in sys.stdin:
a, b = map(int, s.split())
print "%d %d"%(gcd(a, b), lcm(a, b))
| 1 | 823,823,760 | null | 5 | 5 |
N = int(input())
multiple_list = {i*j for i in range(1,10) for j in range(1,10)}
print(['No','Yes'][N in multiple_list])
|
import sys
a, b, c = [ int( val ) for val in sys.stdin.readline().split( " " ) ]
cnt = 0
for i in range( a, b+1 ):
if 0 == c%i:
cnt += 1
print( "{}".format( cnt ) )
| 0 | null | 79,888,206,955,616 | 287 | 44 |
N = int(input())
count = 0
if N % 2 == 0:
for i in range(1,int(N/2)):
if i != N-i:
count+=1
else:
for i in range(1,int(N/2)+1):
if i != N:
count+=1
print(count)
|
#!/usr/bin/env python3
import sys
from itertools import chain
# from itertools import combinations as comb
# form bisect import bisect_left, bisect_right, insort_left, insort_right
# from collections import Counter
# import numpy as np
YES = "Yes" # type: str
def solve(N: int, M: int, A: "List[int]", B: "List[int]"):
routes = [set() for _ in range(N)]
marks = [None for _ in range(N)]
for a, b in zip(A, B):
a = a - 1
b = b - 1
routes[a].add(b)
routes[b].add(a)
marks[0] = -1
cur_rooms = [0]
count = 1
while count < N:
new_cur_rooms = []
for cur_room in cur_rooms:
next_rooms = list(routes[cur_room])
for next_room in next_rooms:
if marks[next_room] is None:
marks[next_room] = cur_room
new_cur_rooms.append(next_room)
count += 1
cur_rooms = new_cur_rooms
answer = "Yes\n" + "\n".join((str(n + 1) for n in marks[1:]))
return answer
def main():
tokens = chain(*(line.split() for line in sys.stdin))
# N, M, A, B = map(int, line.split())
N = int(next(tokens)) # type: int
M = int(next(tokens)) # type: int
A = [int()] * (M) # type: "List[int]"
B = [int()] * (M) # type: "List[int]"
for i in range(M):
A[i] = int(next(tokens))
B[i] = int(next(tokens))
answer = solve(N, M, A, B)
print(answer)
if __name__ == "__main__":
main()
| 0 | null | 87,133,874,842,640 | 283 | 145 |
N, U, V = map(int, input().split())
edge = [[] for _ in range(N + 1)]
for _ in range(N - 1):
x, y = map(int, input().split())
edge[x].append(y)
edge[y].append(x)
def dist(s):
dist = [-1] * (N + 1)
node = [s]
dist[s] = 0
while node:
s = node.pop()
for t in edge[s]:
if dist[t] == -1:
dist[t] = dist[s] + 1
node.append(t)
return dist
taka = dist(U)
aoki = dist(V)
can_go = taka[V]
ans = 0
for t, a in zip(taka[1:], aoki[1:]):
if t <= a:
ans = max(ans, a - 1)
print(ans)
|
def resolve():
def dfs(v):
dist = [-1] * N
stack = [v]
dist[v] = 0
while stack:
v = stack.pop()
for to in G[v]:
if dist[to] != -1:
continue
dist[to] = dist[v] + 1
stack.append(to)
return dist
N, taka, aoki = map(int, input().split())
taka -= 1
aoki -= 1
G = [[] for _ in range(N)]
for i in range(N - 1):
a, b = map(lambda x: int(x) - 1, input().split())
G[a].append(b)
G[b].append(a)
dist_Tk = dfs(taka)
dist_Ao = dfs(aoki)
ans = 0
for i in range(N):
if dist_Tk[i] < dist_Ao[i]:
ans = max(ans, dist_Ao[i] - 1)
print(ans)
if __name__ == "__main__":
resolve()
| 1 | 117,343,353,219,840 | null | 259 | 259 |
import sys
import numpy as np # noqa
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
K = int(readline())
C = readline().rstrip().decode()
a = 0 # a: 赤から白に変える操作
b = 0 # b: 白から赤に変える操作
for i in range(len(C)):
if C[i] == 'R':
a += 1
mn = a
for i in range(len(C)):
if C[i] == 'R':
a -= 1
else:
b += 1
mn = min(mn, min(a, b) + abs(a-b))
print(mn)
|
n = int(input())
s = input()
num_r = s.count("R")
count = 0
for i in range(num_r):
if s[i] != "R":
count += 1
print(count)
| 1 | 6,316,193,192,376 | null | 98 | 98 |
X=int(input())
div=X//100
mod=X%100
print(1 if 5*div>=mod else 0)
|
x = int(input())
a = x%100
b = x//100
if 0<=a and a<=5*b:
print(1)
else:
print(0)
| 1 | 127,129,008,832,530 | null | 266 | 266 |
import sys
from functools import reduce
import copy
import math
from pprint import pprint
import collections
import bisect
import itertools
import heapq
sys.setrecursionlimit(4100000)
def inputs(num_of_input):
ins = [input() for i in range(num_of_input)]
return ins
def int_inputs(num_of_input):
ins = [int(input()) for i in range(num_of_input)]
return ins
def solve(input):
nums = string_to_int(input)
def euclid(large, small):
if small == 0:
return large
l = large % small
return euclid(small, l)
nums.sort(reverse=True)
eee = euclid(nums[0], nums[1])
return int((nums[0] * nums[1]) / eee)
def string_to_int(string):
return list(map(lambda x: int(x), string.split()))
if __name__ == "__main__":
ret = solve(input())
print(ret)
|
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
# INF = float("inf")
INF = 10**18
import bisect
import statistics
mod = 10**9+7
# mod = 998244353
A, B = map(int, input().split())
# リストのlcm
def lcm_base(x, y):
return (x * y) // math.gcd(x, y)
print(lcm_base(A, B))
| 1 | 112,870,666,575,520 | null | 256 | 256 |
def gcd(a,b):
if b ==0:
return a
else:
return gcd(b, a%b)
A,B = map(int, input().split())
A,B = (A,B) if A>B else (B,A)
print(int(A/gcd(A,B)*B))
|
if __name__ == "__main__":
n = int(input())
ops = []
words = []
for _ in range(n):
op, word = input().split()
ops.append(op)
words.append(word)
db = set()
for op, word in zip(ops, words):
if op=='insert':
db.add(word)
else:
if word in db:
print("yes")
else:
print("no")
| 0 | null | 56,713,128,410,312 | 256 | 23 |
#!/usr/bin/env python3
import sys
def input():
return sys.stdin.readline()[:-1]
def main():
N = int(input())
S = {'0'}
for i in range(N):
S.add(input())
print(len(S) - 1)
if __name__ == '__main__':
main()
|
n=int(input())
s={}
for i in range(n):
si = input()
if si not in s:
s[si] = 1
else:
s[si]+=1
sa = sorted(s.items())
ma = max(s.values())
for a in sorted(a for a in s if s[a]==ma):
print(a)
| 0 | null | 50,144,546,432,100 | 165 | 218 |
import numpy as np
import math
n=int(input())
a=[]
for i in range(n):
a.append(list(map(int,input().split())))
a=np.array(a, dtype=object)
ans=0
for i in range(n):
for j in range(n):
if i==j:
continue
else:
x= (a[i]-a[j])**2
hei=math.sqrt(sum(x))
ans+= hei/n
print(ans)
|
def main():
N, S = map(int, input().split())
A = list(map(int, input().split()))
return solve(N, S, A)
def solve(N, S, A):
mod = 998244353
dp = [0] * (S + 1)
dp[0] = pow(2, N, mod)
div2 = pow(2, mod - 2, mod)
m = 0
for a in A:
m += a
for i in reversed(range(a, min(S, m) + 1)):
dp[i] = (dp[i] + dp[i - a] * div2) % mod
return dp[S]
print(main())
| 0 | null | 83,205,991,739,026 | 280 | 138 |
r = int(input())
print(int(r**2))
|
r=int(input())
print(r**2)
| 1 | 145,331,725,412,578 | null | 278 | 278 |
import math
X=int(input())
def ans165(X:int):
cash=100#当初の預金額
count=0
while True:
# cash=int(cash*1.01) #元本に1パーセントの利子をつけ小数点以下切り捨て # WA
# cash = cash * 1.01 * 100 // 100 # 1%の利子をつけて100倍した後に100で割って整数部のみ取り出す # WA
# cash += cash * 0.01 * 100 // 100 # 1%の利子を計算して100倍した後に100で割って整数部のみ取り出す # WA
# cash += cash // 100 # 元本に100で割った整数部を足す # AC
# cash += math.floor(cash * 0.01) # WA
# cash += math.floor(cash / 100) # WA
cash += math.floor(cash // 100) # WA
count += 1#利子をつける回数だけcountを増やす
if cash>=X:#cashがXの値以上になったらループ終了
break
return count
print(ans165(X))
|
X = int(input())
P = 100
year = 0
while X > P:
P += P // 100
year += 1
print(year)
| 1 | 27,032,732,442,518 | null | 159 | 159 |
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
n, m = map(int, readline().split())
if n == m:
print('Yes')
else:
print('No')
|
n = input()
(p,q) = n.split()
a='Yes'
b='No'
if p == q:
print(a)
else:
print(b)
| 1 | 83,585,542,385,060 | null | 231 | 231 |
N = int(input())
A = [int(x) for x in input().split()]
M = max(A)
count = [0 for _ in range(M + 1)]
for i in range(N):
count[A[i]] += 1
S = 0
for i in range(M + 1):
m = count[i]
S += (m * (m - 1)) // 2
ans = [S for _ in range(N)]
for i in range(N):
m = count[A[i]]
ans[i] -= m - 1
for i in range(N):
print(ans[i])
|
X = int(input())
m = 100
y = 0
while m < X :
m = m*101//100
y += 1
print(y)
| 0 | null | 37,408,918,339,338 | 192 | 159 |
a = input()
print("Yes" if (a[2] == a[3]) and (a[4] == a[5]) else "No")
|
def is_prime(num: int) -> bool:
# 6k +- 1 <= √n
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i+2) == 0:
return False
i += 6
return True
x = int(input())
for i in range(x,1000000):
if is_prime(i):
print(i)
break
| 0 | null | 73,509,800,919,632 | 184 | 250 |
import sys
def solve():
readline = sys.stdin.buffer.readline
mod = 10 ** 9 + 7
d, t, s = list(map(int, readline().split()))
print("Yes" if d <= t * s else "No")
if __name__ == '__main__':
solve()
|
from collections import Counter
N, P = map(int, input().split())
S = input()
sum = 0
if P == 2 or P == 5:
for i in range(N):
if int(S[i]) % P == 0:
sum += i+1
print(sum)
exit()
m = []
t = 1
q = 0
for i in range(N,0,-1):
q = ((int(S[i-1]) % P) * t + q) % P
m.append(q)
t = (10 * t) % P
mc = Counter(m)
for v in mc.values():
if v > 1:
sum += v*(v-1)//2
sum += mc[0]
print(sum)
| 0 | null | 30,763,965,325,962 | 81 | 205 |
a,b=[int(i) for i in input().split(" ")]
while b!=0:
t = min(a,b)
b = max(a,b) % min(a,b)
a = t
print(a)
|
x,y=map(int,input().split())
c=x%y
while c!=0:
x=y
y=c
c=x%y
print(y)
| 1 | 7,046,626,412 | null | 11 | 11 |
H=int(input())
Q=[]
import math
for i in range(10000):
if H>1:
H=H//2
Q.append(H)
elif H==1:
break
Q.sort()
S=0
a=1
for i in range(len(Q)):
a=2*a+1
print(a)
|
H = int(input())
res, cnt = 0, 1
while H > 1:
H = H // 2
res += cnt
cnt *= 2
print(res + cnt)
| 1 | 79,607,534,320,694 | null | 228 | 228 |
import math
def kock(n,p1x,p1y,p2x,p2y):
if n==0:
pass
else:
sx=(2*p1x+p2x)/3
sy=(2*p1y+p2y)/3
tx=(p1x+2*p2x)/3
ty=(p1y+2*p2y)/3
ux=(tx-sx)*math.cos(math.pi*1/3)-(ty-sy)*math.sin(math.pi*1/3)+sx
uy=(tx-sx)*math.sin(math.pi*1/3)+(ty-sy)*math.cos(math.pi*1/3)+sy
kock(n-1,p1x,p1y,sx,sy)
print(sx,sy)
kock(n - 1, sx, sy, ux, uy)
print(ux,uy)
kock(n - 1, ux, uy, tx, ty)
print(tx,ty)
kock(n - 1, tx, ty, p2x, p2y)
n=int(input().strip())
zero=0.0
hundred=100.0
print(zero,zero)
kock(n,0,0,100,0)
print(hundred,zero)
|
import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop
#------------------------------------------#
BIG_NUM = 2000000000
HUGE_NUM = 9999999999999999
MOD = 1000000007
EPS = 0.000000001
def MIN(A,B):
if A <= B:
return A
else:
return B
def MAX(A,B):
if A >= B:
return A
else:
return B
#------------------------------------------#
class Point:
def __init__(self,arg_x,arg_y):
self.x = arg_x
self.y = arg_y
def roll(div1,div2):
tmp_start = Point(div2.x-div1.x,div2.y-div1.y)
tmp_end = Point(tmp_start.x*math.cos(math.pi/3) -tmp_start.y*math.sin(math.pi/3),
tmp_start.x*math.sin(math.pi/3) + tmp_start.y*math.cos(math.pi/3))
ret = Point(tmp_end.x + div1.x,tmp_end.y + div1.y)
return ret;
def outPut(point):
print("%.8f %.8f"%(point.x,point.y))
def calc(left,right,count):
div1 = Point((2*left.x + right.x)/3,(2*left.y + right.y)/3)
div2 = Point((2*right.x + left.x)/3,(2*right.y + left.y)/3)
peek = roll(div1,div2)
if count > 1:
calc(left,div1,count-1)
calc(div1,peek,count-1)
calc(peek,div2,count-1)
calc(div2,right,count-1)
else:
outPut(left);
outPut(div1);
outPut(peek);
outPut(div2);
N = int(input())
left = Point(0,0)
right = Point(100,0)
if N == 0:
outPut(left)
outPut(right)
else:
calc(left,right,N)
outPut(right)
| 1 | 131,977,096,074 | null | 27 | 27 |
ans = [0 for _ in range(10001)]
for x in range(1, 101):
for y in range(1, 101):
for z in range(1, 101):
w = x*x + y*y + z*z + x*y + y*z + z*x
if w <= 10000:
ans[w] += 1
print(*ans[1:int(input())+1], sep="\n")
|
N = int(input())
ans = [0]*(N+1)
for x in range(1,100):
for y in range(1,100):
for z in range(1,100):
num = x*x + y*y + z*z + x*y + y*z + z*x
if num>N:
break
ans[num] = ans[num] + 1
for m in ans[1:]:
print(m)
| 1 | 8,003,826,422,612 | null | 106 | 106 |
x = int(input())
def answer(x: int) -> int:
ans = 1000 * (x // 500)
x %= 500
ans += 5 * ((x - 500 * (x // 500)) // 5)
return ans
print(answer(x))
|
s = int(input())
mod = 10**9 + 7
dp = [0]*(s+1)
dp[0] = 1
for i in range(1,s+1):
if i >= 3:
dp[i] = dp[i-3] + dp[i-1]
dp[i] %= mod
print(dp[s])
| 0 | null | 22,926,670,540,318 | 185 | 79 |
x,k,d=map(int,input().split())
if abs(x) >=k*d:
print(abs(x)-k*d)
else:
c = x//d
k -= c
x %= d
if k % 2:print(d-x)
else:print(x)
|
a, b, k = map(int, input().split())
print(a - min(a, k), b - min(b, k - min(a, k)))
| 0 | null | 54,611,426,357,420 | 92 | 249 |
def main():
h, n = list(map(int, input().split()))
A, B = [], []
for _ in range(n):
a, b = list(map(int, input().split()))
A.append(a)
B.append(b)
mx = max(A)
INF = float('inf')
dp = [INF] * (h + mx + 1)
dp[0] = 0
for i in range(1, h + mx + 1):
for a, b in zip(A, B):
if i - a < 0:
dp[i] = min(dp[i], b)
else:
dp[i] = min(dp[i], dp[i - a] + b)
print(min(dp[h:h + mx + 1]))
if __name__ == '__main__':
main()
|
from itertools import accumulate
def main():
N, K = map(int, input().split())
A = list(map(int, input().split()))
for _ in range(K):
arr = [0]*(N+1)
for i, a in enumerate(A):
left = max(0, i-a)
right = min(N, i+a+1)
arr[left] += 1
arr[right] -= 1
A = list(accumulate(arr[:-1]))
if all(a == N for a in A):
break
print(*A, sep=" ")
if __name__ == "__main__":
main()
| 0 | null | 48,264,071,253,022 | 229 | 132 |
import Queue
import sys
class Proc:
def __init__(self, name, time):
self.time = time
self.name = name
def main():
array = map(lambda x: int(x), sys.stdin.readline().strip().split(" "))
p_num = array[0]
q_time = array[1]
p_queue = Queue.Queue()
for i in range(0, p_num):
array = sys.stdin.readline().strip().split(" ")
p_queue.put(Proc(array[0], int(array[1])))
t = 0
while not p_queue.empty():
p = p_queue.get()
if p.time > q_time:
p.time = p.time - q_time
p_queue.put(p)
t += q_time
else:
t += p.time
print p.name + " " + str(t)
if __name__ == "__main__":
main()
|
rows, cols = [int(x) for x in input().split()]
matrix = []
vector = []
for i in range(rows):
matrix.append([int(x) for x in input().split()])
for i in range(cols):
vector.append(int(input()))
for row in matrix:
result = 0
for x, y in zip(row, vector):
result += x*y
print(result)
| 0 | null | 604,179,147,648 | 19 | 56 |
n = int(input())
a = list(map(int, input().split()))
ans = 0
for x in a[::2]:
ans += x % 2
print(ans)
|
SENTINEL = 10**9 + 1
def merge_sort(alist):
"""Sort alist using mergesort.
Returns a tuple of the number of comparisons and sorted list.
>>> merge_sort([8, 5, 9, 2, 6, 3, 7, 1, 10, 4])
(34, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
"""
def _sort(left, right):
count = 0
if left + 1 < right:
mid = (left + right) // 2
count += _sort(left, mid)
count += _sort(mid, right)
count += merge(left, mid, right)
return count
def merge(left, mid, right):
count = 0
ll = alist[left:mid] + [SENTINEL]
rl = alist[mid:right] + [SENTINEL]
i = j = 0
for k in range(left, right):
count += 1
if ll[i] <= rl[j]:
alist[k] = ll[i]
i += 1
else:
alist[k] = rl[j]
j += 1
return count
comp = _sort(0, len(alist))
return (comp, alist)
def run():
_ = int(input()) # flake8: noqa
li = [int(i) for i in input().split()]
(c, s) = merge_sort(li)
print(" ".join([str(i) for i in s]))
print(c)
if __name__ == '__main__':
run()
| 0 | null | 3,993,636,800,100 | 105 | 26 |
M1, D1 = [int(_) for _ in input().split(" ")]
M2, D2 = [int(_) for _ in input().split(" ")]
if M1 == M2:
print (0)
else:
print (1)
|
m,d=map(int,input().split())
if m in [1,3,5,7,8,10,12] and d==31:
print(1)
elif m ==2 and d==28:
print(1)
elif m in [4,6,9,11] and d==30:
print(1)
else:
print(0)
| 1 | 124,669,694,969,300 | null | 264 | 264 |
def main():
n = int(input())
Ss = [input() for _ in range(n)]
U = [[0, 0] for _ in range(n)]
for i in range(n):
for c in Ss[i]:
if c == "(":
U[i][1] += 1
else:
if U[i][1] == 0:
U[i][0] += 1
else:
U[i][1] -= 1
L, R = 0, 0
P = []
for i in range(n):
if U[i][0] == 0 and U[i][1] > 0:
L += U[i][1]
elif U[i][0] > 0 and U[i][1] == 0:
R += U[i][0]
elif U[i][0] > 0 and U[i][1] > 0:
P.append([U[i][0], U[i][1]])
P.sort(key=lambda x: (x[0]-x[1], x[0], -x[1]))
if L == 0 and R == 0 and len(P) == 0:
print("Yes")
elif (L == 0 or R == 0) and len(P) > 0:
print("No")
else:
f = True
for i in range(len(P)):
L -= P[i][0]
if L < 0:
f = False
break
L += P[i][1]
if L == R and f:
print("Yes")
else:
print("No")
if __name__ == "__main__":
main()
|
# Stable Sort
length = int(input())
cards = input().rstrip().split()
cards1 = [card for card in cards]
cards2 = [card for card in cards]
def value(n):
number = n[1:]
return int(number)
def char(cards):
charSets = [[] for i in range(10)]
for i in range(length):
char = cards[i][:1]
val = value(cards[i])
# print('絵柄: ' + char + ', 数字: ' + str(val))
charSets[val].append(char)
return charSets
def bubble(cards):
for i in range(length):
j = length - 1
while j > i:
if value(cards[j]) < value(cards[j - 1]):
cards[j], cards[j - 1] = cards[j - 1], cards[j]
j -= 1
return cards
def selection(cards):
# count = 0
for i in range(length):
minj = i
for j in range(i, length):
if value(cards[j]) < value(cards[minj]):
minj = j
#if minj != i:
# count += 1
cards[i], cards[minj] = cards[minj], cards[i]
return cards
def stable(cards1, cards2):
if char(cards1) == char(cards2):
return 'Stable'
else:
return 'Not stable'
c = cards
b = bubble(cards1)
s = selection(cards2)
print(' '.join(b))
print(stable(c, b))
print(' '.join(s))
print(stable(c, s))
| 0 | null | 11,937,546,829,952 | 152 | 16 |
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
s, t = map(str, input().split())
print(t+s)
|
#入力:N,M(int:整数)
def input2():
return map(str,input().split())
#入力:[n1,n2,...nk](int:整数配列)
def input_array():
return list(map(int,input().split()))
s,t=input2()
print("{}{}".format(t,s))
| 1 | 102,630,074,174,602 | null | 248 | 248 |
x = int(input())
a = x // 500
x = x - a * 500
b = x // 5
print(1000*a+5*b)
|
N = int(input())
a = N // 500
N -= 500 * a
b = N // 5
print(a * 1000 + b * 5)
| 1 | 42,775,858,832,540 | null | 185 | 185 |
import math
a,b,C=list(map(int,input().split()))
C_radian=math.radians(C)
S=a*b*math.sin(C_radian)/2
L=a+b+(a**2+b**2-2*a*b*math.cos(C_radian))**0.5
h=b*math.sin(C_radian)
print(S)
print(L)
print(h)
|
a,b,c=list(map(float,input().split()))
import math
print(math.sin((2*c*math.pi)/360)*a*b*(1/2))
print(math.sqrt(a**2+b**2-2*a*b*math.cos(2*c*math.pi/360))+a+b)
print(math.sin(2*c*math.pi/360)*b)
| 1 | 176,587,717,280 | null | 30 | 30 |
a, b, c = map(int, input().split())
k = int(input())
cnt = 0
while a >= b:
cnt += 1
b *= 2
while b >= c:
cnt += 1
c *= 2
if cnt <= k: print("Yes")
else: print("No")
|
import sys
r,g,b=map(int,input().split())
k=int(input())
for i in range(k+1):
if r<g<b:
print("Yes")
sys.exit()
else:
if r<=b<=g:
b*=2
elif b<=r<=g:
b*=2
elif b<=g<=r:
b*=2
elif g<=r<=b:
g*=2
elif g<=b<=r:
b*=2
print("No")
| 1 | 6,972,453,177,028 | null | 101 | 101 |
import bisect
a, b, k = [int(i) for i in input().split()]
print(max(a-k,0), max(0,min(b,a+b-k)))
|
class Queue(object):
def __init__(self, _max):
if type(_max) != int:
raise ValueError
self._array = [None for i in range(0, _max)]
self._head = 0
self._tail = 0
self._cnt = 0
def enqueue(self, value):
if self.is_full():
raise IndexError
self._array[self._head] = value
self._cnt += 1
if self._head + 1 >= len(self._array):
self._head = 0
else:
self._head += 1
def dequeue(self):
if self.is_empty():
raise IndexError
value = self._array[self._tail]
self._cnt -= 1
if self._tail + 1 >= len(self._array):
self._tail = 0
else:
self._tail += 1
return value
def is_empty(self):
return self._cnt <= 0
def is_full(self):
return self._cnt >= len(self._array)
def round_robin(quantum, jobs):
queue = Queue(100000)
total = 0
for job in jobs:
queue.enqueue(job)
while not queue.is_empty():
name, time = queue.dequeue()
if time > quantum:
total += quantum
queue.enqueue((name, time - quantum))
else:
total += time
print("{0} {1}".format(name, total))
if __name__ == "__main__":
n, quantum = input().split()
jobs = [input().split() for i in range(0, int(n))]
jobs = [(job[0], int(job[1])) for job in jobs]
round_robin(int(quantum), jobs)
| 0 | null | 52,167,229,256,142 | 249 | 19 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.