code1
stringlengths 17
427k
| code2
stringlengths 17
427k
| similar
int64 0
1
| pair_id
int64 2
181,637B
⌀ | question_pair_id
float64 3.7M
180,677B
⌀ | code1_group
int64 1
299
| code2_group
int64 1
299
|
---|---|---|---|---|---|---|
N,M=map(int,input().split())
A=[int(x) for x in input().split()]
s=sum(A)
l=len(A)
m=0
for i in range(l):
if A[i]>=s/(4*M):
m+=1
if M<=m:
print('Yes')
else:
print('No')
|
N, M = map(int, input().split())
A = list(map(int, input().split()))
s = sum(A)
ans = 0
for a in A:
if a * 4 * M >= s:
ans += 1
print("Yes" if ans >= M else "No")
| 1 | 38,847,920,406,970 | null | 179 | 179 |
n = int(input())
odd = n//2 + n%2
print(odd/n)
|
#!/usr/bin/env python3
from itertools import combinations
import sys
input = sys.stdin.readline
MOD = 10**9 + 7
t1, t2 = [int(item) for item in input().split()]
a1, a2 = [int(item) for item in input().split()]
b1, b2 = [int(item) for item in input().split()]
a1 *= t1
b1 *= t1
a2 *= t2
b2 *= t2
if a1 + a2 == b1 + b2:
print("infinity")
exit()
if a1 + a2 > b1 + b2:
a1, a2, b1, b2 = b1, b2, a1, a2
diff = (b1 + b2) - (a1 + a2)
mid_diff = b1 - a1
if mid_diff > 0:
print(0)
else:
ans = (abs(mid_diff) + diff - 1) // diff * 2
if abs(mid_diff) % diff == 0:
ans += 1
print(ans - 1)
| 0 | null | 154,931,155,772,460 | 297 | 269 |
dice = list(map(int, input().split()))
directions = input()
for direction in directions:
if direction == 'N':
dice = [dice[1], dice[5], dice[2], dice[3], dice[0], dice[4]]
elif direction == 'S':
dice = [dice[4], dice[0], dice[2], dice[3], dice[5], dice[1]]
elif direction == 'W':
dice = [dice[2], dice[1], dice[5], dice[0], dice[4], dice[3]]
else:
dice = [dice[3], dice[1], dice[0], dice[5], dice[4], dice[2]]
print(dice[0])
|
s=input()
n=len(s)
from collections import Counter
c=Counter()
m=0
c[m]+=1
d=1
s=s[::-1]
for i in range(n):
m+=int(s[i])*d
m%=2019
d*=10
d%=2019
c[m]+=1
ans=0
for v in c.values():
ans+=v*(v-1)//2
print(ans)
| 0 | null | 15,558,656,451,510 | 33 | 166 |
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse = True)
if n % 2:
print(a[0]+a[n//2]+2*(sum(a[1:(n-1)//2])))
else:
print(a[0]+2*(sum(a[1:n//2])))
|
i = 0
x = int(input())
while x != 0:
i += 1
print("Case ", i, ": ", x, sep="")
x = int(input())
| 0 | null | 4,772,309,669,088 | 111 | 42 |
S = 0
N,D = input().split()
N = int(N)
D = int(D)
X = [0]*N
Y = [0]*N
for i in range(N):
X[i],Y[i] = map(int, input().split())
if ((X[i])**2 + (Y[i])**2) <= (D)**2:
S = S + 1
print(S)
|
import itertools
n,m,x=[int(x) for x in input().split()]
book=[]
for i in range(n):
b=[int(x) for x in input().split()]
book.append(b)
l=[]
a=itertools.product(range(2),repeat=n)
for i in a:
l.append(i)
price=[]
for i in range(2**n):
check_list=[0]*(m+1)
for j in range(n):
if l[i][j]==1:
for k in range(m+1):
check_list[k]+=book[j][k]
check=[]
for p in range(1,m+1):
if check_list[p]<x:
check.append(False)
if check==[]:
price.append(check_list[0])
if price==[]:
print("-1")
else:
print(min(price))
| 0 | null | 14,173,388,633,220 | 96 | 149 |
import sys
read = sys.stdin.buffer.read
def main():
N, K, *AF = map(int, read().split())
A = AF[:N]
F = AF[N:]
A.sort()
F.sort(reverse=True)
ok = pow(10, 12)
ng = -1
while ok - ng > 1:
mid = (ok + ng) // 2
k = 0
for i in range(N):
if A[i] * F[i] > mid:
k += A[i] - mid // F[i]
if k <= K:
ok = mid
else:
ng = mid
print(ok)
return
if __name__ == '__main__':
main()
|
n = int(input())
a = list(map(int,input().split()))
ans = 0
m = a[0]
for i in range(1,n):
if a[i] <= m:
ans += -a[i]+m
else:
m = a[i]
print(ans)
| 0 | null | 84,377,384,964,532 | 290 | 88 |
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()
|
n = int(input())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7
ans, cnt = 1, [0, 0, 0]
for i in a:
ans = ans * cnt.count(i) % mod
for j in range(3):
if cnt[j] == i:
cnt[j] += 1
break
print(ans)
| 1 | 129,929,656,843,200 | null | 268 | 268 |
import itertools
import functools
import math
from collections import Counter
from itertools import combinations
import re
N,R=map(int,input().split())
if N >= 10:
print(R)
else:
print( R + ( 100 * ( 10 - N )))
|
a,b=map(int,input().split())
c=0
res = 0
if a >=10:
print(b)
else:
c = 100 * (10-a)
res = b+c
print(res)
| 1 | 63,165,928,281,690 | null | 211 | 211 |
n = int(input())
x = 100000
for i in range(n):
x = x*1.05
if x % 1000 == 0:
pass
else:
x = x//1000
x = x+1
x = x*1000
print('{:.0f}'.format(x))
|
import math
d=100
for _ in[0]*int(input()):
d=math.ceil(d*1.05)
print(int(d*1e3))
| 1 | 947,479,132 | null | 6 | 6 |
def chebyshev_0(a, b):
return a - b
def chebyshev_1(a, b):
return a + b
N = int(input())
X = [0] * N
Y = [0] * N
for i in range(N):
X[i], Y[i] = map(int, input().split())
max_0 = - (10 ** 9) - 1
min_0 = 2 * (10 ** 9)
for x, y in zip(X, Y):
if chebyshev_0(x, y) > max_0:
max_0 = chebyshev_0(x, y)
if chebyshev_0(x, y) < min_0:
min_0 = chebyshev_0(x, y)
l0 = abs(max_0 - min_0)
max_1 = - (10 ** 9) - 1
min_1 = 2 * (10 ** 9)
for x, y in zip(X, Y):
if chebyshev_1(x, y) > max_1:
max_1 = chebyshev_1(x, y)
if chebyshev_1(x, y) < min_1:
min_1 = chebyshev_1(x, y)
l1 = abs(max_1 - min_1)
print(max([l0, l1]))
|
import math
n = int(input())
ans = 100000
for i in range(n):
ans += ans * 0.05
ans = int(math.ceil(ans / 1000) * 1000)
print(ans)
| 0 | null | 1,710,021,938,260 | 80 | 6 |
n = int(input())
nums = input().split()
max = int(nums[0])
min = int(nums[0])
sum = int(nums[0])
for i in range(n-1):
m = int(nums[i+1])
if m > max:
max = m
if m < min:
min = m
sum = sum + m
print(min, max, sum)
|
splited = input().split(" ")
f = int(splited[0])/int(splited[1])
r = int(splited[0])%int(splited[1])
d = int(splited[0])//int(splited[1])
print(d, r, "{0:.5f}".format(f))
| 0 | null | 670,280,931,500 | 48 | 45 |
def main():
H = int( input())
W = int( input())
N = int( input())
if H < W:
H, W = W, H
ans = N//H
if N%H != 0:
ans += 1
print(ans)
if __name__ == '__main__':
main()
|
n=int(input())
s=input()
s1=n//2
ans="No"
if n&1!=1:
if s[:s1]==s[s1:]:
ans="Yes"
print(ans)
| 0 | null | 118,034,056,222,952 | 236 | 279 |
(N,M),*AB=[list(map(int, x.split())) for x in open(0).readlines() if len(x)>1]
class UnionFind:
def __init__(self, n):
self.n=n
self.parents=[-1 for i in range(n)]
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
rx = self.find(x)
ry = self.find(y)
if rx == ry:
return
if self.parents[rx] > self.parents[ry]:
rx,ry=ry,rx
self.parents[rx] = self.parents[ry]
self.parents[ry] = rx
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i,x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
d=UnionFind(N)
for a,b in AB:
d.union(a-1,b-1)
print(d.group_count() - 1)
|
f = lambda x: x if p[x]<0 else f(p[x])
N,M = map(int,input().split())
p = [-1]*N
for _ in range(M):
A,B = map(lambda x:f(int(x)-1),input().split())
if A==B: continue
elif A<B: A,B=B,A
p[A] += p[B]
p[B] = A
print(sum(i<0 for i in p)-1)
| 1 | 2,298,908,989,700 | null | 70 | 70 |
import numpy as np
H,W = input().split()
H,W=int(H),int(W)
P=[0]*H
for i in range(H):
P[i] = input()
dp=np.zeros((H,W),dtype='u8')
if P[0][0]=='#':
dp[0][0]=1
else:
dp[0][0]=0
def DP(y,x):
global dp
if 0<=x<=W-1 and 0<=y<=H-1:
return dp[y][x]
else:
return 9999999
for l in range(1,H+W):
for i in range(l+1):
if i<H and l-i<W:
if P[i][l-i]=='#':
a=DP(i-1,l-i)
b=DP(i,l-i-1)
if a < 9999999:
if P[i-1][l-i]=='.':
a+=1
if b < 9999999:
if P[i][l-i-1]=='.':
b+=1
dp[i][l-i]=min(a,b)
else:
#print(i,l-i,DP(i-1,l-i),DP(i,l-i-1))
dp[i][l-i]=min(DP(i-1,l-i),DP(i,l-i-1))
print(dp[H-1][W-1])
|
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
return sys.stdin.readline()[:-1]
def ruiseki(lst):
return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
h,w=map(int,input().split())
s=[input() for i in range(h)]
d=deque([[0,0]])
itta=[[float('inf')]*w for i in range(h)]
if s[0][0]=="#":
itta[0][0]=1
else:
itta[0][0]=0
# print(itta)
ans=0
for i in range(h+w-2):
# print(itta)
for j in range(len(d)):
now=d.popleft()
nh,nw=now
cnt=itta[nh][nw]
if nh+1<h:
tmp=cnt
if s[nh][nw]=="." and s[nh+1][nw]=="#":
tmp+=1
if itta[nh+1][nw]==float('inf'):
d.append([nh+1,nw])
itta[nh+1][nw]=min(itta[nh+1][nw],tmp)
if nw+1<w:
tmp=cnt
if s[nh][nw]=="." and s[nh][nw+1]=="#":
tmp+=1
if itta[nh][nw+1]==float('inf'):
d.append([nh,nw+1])
itta[nh][nw+1]=min(itta[nh][nw+1],tmp)
# print(itta)
# for i in range(len(d)):
print(itta[-1][-1])
| 1 | 49,221,562,313,950 | null | 194 | 194 |
import os, sys, re, math
S = input()
dow = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT']
print(7 - dow.index(S))
|
def main():
x = int(input())
coin_500 = x // 500
coin_5 = x % 500 // 5
ans = coin_500 * 1000 + coin_5 * 5
print(ans)
if __name__ == "__main__":
main()
| 0 | null | 87,719,148,509,970 | 270 | 185 |
from sys import stdin
inp = lambda : stdin.readline().strip()
d, t, s = [int(x) for x in inp().split()]
if d / s <= t:
print('Yes')
else:
print('No')
|
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
d,t,s=nii()
print('Yes' if d/s<=t else 'No')
| 1 | 3,518,158,037,380 | null | 81 | 81 |
a, b, c = map(int, input().split())
x = c - b - a
if x > 0 and a * b * 4 < x * x:
print("Yes")
else:
print("No")
|
import math
while True:
n = int(input())
if n == 0:
break
s = [int(s) for s in input().split()]
ave = sum(s) / n
a = 0
for N in s:
a += (N - ave)**2
a = math.sqrt((a / n))
print(a)
| 0 | null | 25,847,651,858,524 | 197 | 31 |
def main():
N = int(input())
a = list(map(int, input().split()))
a.sort(reverse = True)
ans = a[0]
t = N - 2
for i in range(1, N):
for _ in range(2):
if t > 0:
ans += a[i]
t -= 1
print(ans)
if __name__ == "__main__":
main()
|
import sys
import math
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')
def LCM(a, b):
return a * b // math.gcd(a, b)
def main():
N, M = in_nn()
a = in_nl()
lcm = 1
for i in range(N):
lcm = LCM(lcm, a[i])
if lcm > M * 2:
print(0)
exit()
for i in range(N):
if lcm // a[i] % 2 == 0:
print(0)
exit()
lcm = lcm // 2
q = M // lcm
if q % 2 == 0:
ans = q // 2
else:
ans = q // 2 + 1
print(ans)
if __name__ == '__main__':
main()
| 0 | null | 55,721,737,255,008 | 111 | 247 |
import bisect
n = int(input())
l = list(map(int, input().split()))
sort_l = sorted(l)
count = 0
for a in range(n):
for b in range(a+1, n):
c = bisect.bisect_left(sort_l, sort_l[a] + sort_l[b])
if c > b:
count += c - b -1
else:
pass
print(count)
|
import math
import sys
from collections import deque
import heapq
import copy
import itertools
from itertools import permutations
from itertools import combinations
import bisect
def mi() : return map(int,sys.stdin.readline().split())
def ii() : return int(sys.stdin.readline().rstrip())
def i() : return sys.stdin.readline().rstrip()
a=ii()
l=list(mi())
l=sorted(l)
ans=0
for i in range(a-2):
for j in range(i+1,a-1):
s=bisect.bisect_left(l,l[i]+l[j])
ans+=s-j-1
print(ans)
| 1 | 172,128,195,024,060 | null | 294 | 294 |
import sys
input = sys.stdin.readline
from collections import deque
def bfs(s):
dist = [-1]*N
dist[s] = 0
q = deque([s])
while q:
v = q.popleft()
for nv in adj_list[v]:
if dist[nv]==-1:
dist[nv] = dist[v]+1
q.append(nv)
return dist
N, u, v = map(int, input().split())
adj_list = [[] for _ in range(N)]
for _ in range(N-1):
Ai, Bi = map(int, input().split())
adj_list[Ai-1].append(Bi-1)
adj_list[Bi-1].append(Ai-1)
d1 = bfs(u-1)
d2 = bfs(v-1)
ans = 0
for i in range(N):
if d1[i]<d2[i]:
ans = max(ans, d2[i]-1)
print(ans)
|
n = int(input())
print(0.5) if n%2==0 else print(int(n/2+1)/n)
| 0 | null | 147,294,042,836,732 | 259 | 297 |
a = int(input())
res = a > 29 and 'Yes' or 'No'
print(res)
|
n = int(input())
s = 0
a = 1
b = 1
while a*b < n:
while a*b < n and b <= a:
if a == b:
s += 1
else:
s += 2
b += 1
a += 1
b = 1
print(s)
| 0 | null | 4,174,651,055,888 | 95 | 73 |
N=int(input())
S=input()
ans=0
for i in range(N-2):
if S[i]=='A':
i+=1
if S[i]=='B':
i+=1
if S[i]=='C':
ans+=1
print(ans)
|
import sys
sys.setrecursionlimit(1000000000)
import math
from math import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations, chain
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7
def meg(f, ok, ng):
while abs(ok-ng)>1:
mid = (ok+ng)//2
if f(mid):
ok=mid
else:
ng=mid
return ok
def get_inv(n, modp):
return pow(n, modp-2, modp)
def factorials_list(n, modp): # 10**6
fs = [1]
for i in range(1, n+1):
fs.append(fs[-1] * i % modp)
return fs
def invs_list(n, fs, modp): # 10**6
invs = [get_inv(fs[-1], modp)]
for i in range(n, 1-1, -1):
invs.append(invs[-1] * i % modp)
invs.reverse()
return invs
def comb(n, k, modp):
num = 1
for i in range(n, n-k, -1):
num = num * i % modp
den = 1
for i in range(2, k+1):
den = den * i % modp
return num * get_inv(den, modp) % modp
def comb_from_list(n, k, modp, fs, invs):
return fs[n] * invs[n-k] * invs[k] % modp
#
class UnionFindEx:
def __init__(self, size):
#正なら根の番号、負ならグループサイズ
self.roots = [-1] * size
def getRootID(self, i):
r = self.roots[i]
if r < 0: #負なら根
return i
else:
r = self.getRootID(r)
self.roots[i] = r
return r
def getGroupSize(self, i):
return -self.roots[self.getRootID(i)]
def connect(self, i, j):
r1, r2 = self.getRootID(i), self.getRootID(j)
if r1 == r2:
return False
if self.getGroupSize(r1) < self.getGroupSize(r2):
r1, r2 = r2, r1
self.roots[r1] += self.roots[r2] #サイズ更新
self.roots[r2] = r1
return True
Yes = 'Yes'
No = 'No'
def main():
N=ii()
up = []
down = []
for _ in range(N):
S = input()
h = 0
b = 0
for s in S:
if s=='(':
h += 1
else:
h -= 1
b = min(b, h)
#
if h>=0:
up.append((h, b))
else:
down.append((h, b))
#
up.sort(key=lambda t: t[1], reverse=True)
down.sort(key=lambda t: t[0]-t[1], reverse=True)
H = 0
for h, b in up:
if H+b>=0:
H += h
else:
print(No)
return
for h, b in down:
if H+b>=0:
H += h
else:
print(No)
return
#
if H == 0:
print(Yes)
else:
print(No)
main()
| 0 | null | 61,602,453,936,140 | 245 | 152 |
def BubbleSort(A, N):
cnt = 0 # swap???????????£????????°????¨???????????????°
flag = 1 # flag = 1????????????????????????????????£??????????????¨?????????
while flag:
flag = 0
for j in range(N - 1, 0, -1):
if A[j] < A[j - 1]:
A[j] , A[j - 1] = A[j - 1], A[j]
cnt += 1
flag = 1
# swap???????????£????????°?????????
return cnt
N = int(input())
A = [int(a) for a in input().split()]
cnt = BubbleSort(A, N)
print(*A)
print(cnt)
|
import math
n = int(input())
x = list(map(float, (input().split())))
y = list(map(float, (input().split())))
l = [0.0]*n
for i in range(n):
l[i] = abs(x[i]-y[i])
print(sum(l))
che = max(l)
for i in range(n):
l[i] = abs(x[i]-y[i])**2
print(math.sqrt(sum(l)))
for i in range(n):
l[i] = abs(x[i]-y[i])**3
print(math.pow(sum(l), 1.0/3.0))
print(che)
| 0 | null | 112,726,640,908 | 14 | 32 |
import math
n = int(input())
if n%2==0:
print(round(((n-2)/2)))
else:
print(round(((n+1)/2)-1))
|
import sys
import math
# import bisect
# import numpy as np
# from decimal import Decimal
# from numba import njit, i8, u1, b1 #JIT compiler
# from itertools import combinations, product
# from collections import Counter, deque, defaultdict
# sys.setrecursionlimit(10 ** 6)
MOD = 10 ** 9 + 7
INF = 10 ** 9
PI = 3.14159265358979323846
def read_str(): return sys.stdin.readline().strip()
def read_int(): return int(sys.stdin.readline().strip())
def read_ints(): return map(int, sys.stdin.readline().strip().split())
def read_ints2(x): return map(lambda num: int(num) - x, sys.stdin.readline().strip().split())
def read_str_list(): return list(sys.stdin.readline().strip().split())
def read_int_list(): return list(map(int, sys.stdin.readline().strip().split()))
def GCD(a: int, b: int) -> int: return b if a%b==0 else GCD(b, a%b)
def LCM(a: int, b: int) -> int: return (a * b) // GCD(a, b)
def Main():
n, m = read_ints()
a = read_int_list()
a = [x // 2 for x in a]
lcm = 1
for x in a:
lcm *= x // math.gcd(lcm, x)
for x in a:
if lcm // x % 2 == 0:
print(0)
exit()
print(math.ceil((m // lcm) / 2))
if __name__ == '__main__':
Main()
| 0 | null | 127,669,619,003,758 | 283 | 247 |
import sys
def sieve(N):
is_prime = [True] * (N + 1)
prime_list = []
is_prime[0] = is_prime[1] = False
prime_list.append(2)
for i in range(3, N + 1, 2):
if is_prime[i]:
prime_list.append(i)
for j in range(i * i, N, i):
is_prime[j] = False
return prime_list
primes = sieve(10001)
primes_set = set(primes)
def is_prime(num):
if num in primes_set:
return True
elif num <= 10000:
return False
else:
for prime in primes:
if num % prime == 0:
return False
return True
if __name__ == '__main__':
N = sys.stdin.readline()
N = int(N)
ans = 0
for i in range(N):
num = sys.stdin.readline()
num = int(num)
if is_prime(num): ans += 1
sys.stdout.write(str(ans) + '\n')
|
a,b = map(int, raw_input().split())
print a/b,a%b,"%.5f" % (a/float(b))
| 0 | null | 300,099,633,340 | 12 | 45 |
t1,t2=map(int,input().split())
a1,a2=map(int,input().split())
b1,b2=map(int,input().split())
x=(a1-b1)*t1
y=(a2-b2)*t2
if x+y==0:
print('infinity')
elif x*(x+y)>0:
print(0)
else:
k=x//(-x-y)
if x%(-x-y)==0:
print(k*2)
else:
print(k*2+1)
|
T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())
if A1 < B1:
A1, B1 = B1, A1
A2, B2 = B2, A2
if A1 * T1 + A2 * T2 > B1 * T1 + B2 * T2:
print (0)
exit()
if A1 * T1 + A2 * T2 == B1 * T1 + B2 * T2:
print ('infinity')
exit()
bunshi = (B1 - A1) * T1
bunbo = (A1 * T1 + A2 * T2) - (B1 * T1 + B2 * T2)
# print (bunshi)
# print (bunbo)
n = 1 + bunshi // bunbo
if bunshi % bunbo == 0:
print (int(n) * 2 - 2)
else:
print (int(n) * 2 - 1)
| 1 | 131,472,569,595,640 | null | 269 | 269 |
sum = 0
while 1:
x = int(raw_input())
sum = sum + 1
if x == 0:
break
print 'Case %s: %s' %(sum, x)
|
n = -100
i = 1
while n != 0:
n = int(raw_input())
if n != 0:
print 'Case %d: %d' %(i,n)
i = i + 1
| 1 | 482,598,618,428 | null | 42 | 42 |
a,b=input().split()
a=int(a)
b=int(b)
e=a
d=b
c=1
if a>b:
for i in range(1,e):
if a%(e-i)==0 and b%(e-i)==0:
a=a/(e-i)
b=b/(e-i)
c=c*(e-i)
print(int(a*b*c))
if a<b:
for i in range(1,d):
if a%(d-i)==0 and b%(d-i)==0:
a=a/(d-i)
b=b/(d-i)
c=c*(d-i)
print(int(a*b*c))
|
a,b=map(int,input().split())
import fractions
r=(a*b)//fractions.gcd(a,b)
print(r)
| 1 | 113,344,003,100,060 | null | 256 | 256 |
# Problem D - String Equivalence
from collections import deque
# input
N = int(input())
char_list = [chr(i) for i in range(97, 97+26)]
def dfs(a_list, a_len):
if a_len==N:
print("".join(a_list))
return
else:
biggest = 97
count = len(set(a_list)) # N<=10だからさほど時間はかからない
for c in range(biggest, biggest + count + 1):
ch = chr(c)
a_list.append(ch)
dfs(a_list, a_len+1)
a_list.pop()
# initialization
a_nums = deque([])
# dfs search
dfs(a_nums, 0)
|
# パナソニック2020D
import sys
def write(x):
sys.stdout.write(x)
sys.stdout.write("\n")
from queue import deque
n = int(input())
q = deque([("a", "a")])
while True:
s, m = q.pop()
if len(s)==n:
write(s)
elif len(s)>=n+1:
break
for o in range(ord("a"), ord(m)+2):
if ord(m)<o:
m = chr(o)
q.appendleft((s + chr(o), m))
| 1 | 52,092,421,317,190 | null | 198 | 198 |
n, m = map(int, input().split())
Penalty = [0]*(n+1)
AC = [False]*(n+1)
correct = 0
penalty = 0
for i in range(m):
ans = input().split()
problem = int(ans[0])
result = ans[1]
if AC[problem] == False:
if result == 'AC':
AC[problem] = True
correct += 1
penalty += Penalty[problem]
else:
Penalty[problem] += 1
print(correct, penalty)
|
N, M = list(map(int, input().split()))
p = [0]*M
s = [0]*M
b = [0]*N
pena = 0
corr = 0
for i in range(M):
p[i], s[i] = input().split()
p[i] = int(p[i])
if b[p[i]-1] != -1:
if s[i] == "AC":
pena += b[p[i]-1]
corr += 1
b[p[i]-1] = -1
else:
b[p[i]-1] += 1
print(corr, pena)
| 1 | 93,285,337,518,352 | null | 240 | 240 |
W=input()
a=0
while True:
T=input()
if T=='END_OF_TEXT':
break
else:
a +=T.lower().split().count(W)
print(a)
|
a = len(input())
print("x"*a)
| 0 | null | 37,628,178,049,800 | 65 | 221 |
n, k = map(int, input().split())
xs = [i for i in range(1, k + 1)]
xs.reverse()
dict_x = {}
mod = 10 ** 9 + 7
def pow(x, y):
global mod
a = 1
b = x
c = y
while c > 0:
if c & 1:
a = (a * b) % mod
b = (b * b) % mod
c = c >> 1
return a
answer = 0
for x in xs:
num = k // x
a = pow(num, n)
# print(a)
s = 2
while x * s <= k:
a -= dict_x[x * s]
s += 1
dict_x[x] = a
answer = (answer + a * x) % mod
print(answer)
|
class DoublyLinkedList:
def __init__(self):
self.nil = self.make_node(None)
self.nil['next'] = self.nil
self.nil['prev'] = self.nil
def make_node(self,v):
return {'key':v, 'next':None, 'prev':None}
def dump(self):
n = self.nil['next']
while True:
if n['key'] == None:
break
else:
print str(n['key']),
n = n['next']
print
def insert(self,v):
n = self.make_node(v)
n['next'] = self.nil['next']
self.nil['next']['prev'] = n
n['prev'] = self.nil
self.nil['next'] = n
def delete(self,v):
self.delete_node(self.list_search(v))
def delete_node(self,n):
if n['key'] == None: return
n['next']['prev'] = n['prev']
n['prev']['next'] = n['next']
def list_search(self,v):
cur = self.nil['next']
while (cur['key'] != None) and (cur['key'] != v):
cur = cur['next']
return cur
def deleteFirst(self):
self.delete_node(self.nil['next'])
def deleteLast(self):
self.delete_node(self.nil['prev'])
n = int(raw_input())
commands = []
for i in range(n):
commands.append(raw_input())
l = DoublyLinkedList()
for c in commands:
a = c[6]
if a == "F":
l.deleteFirst()
elif a == "L":
l.deleteLast()
else:
val = int(c[7:])
op = c[0]
if op == "i":
l.insert(val)
else:
l.delete(val)
l.dump()
| 0 | null | 18,307,794,013,948 | 176 | 20 |
n=int(input())
i=0
x=100000
for i in range(n):
x=int(x*1.05)
if x%1000==0:
x=x
else:
x=x+1000-x%1000
i+=1
print(x)
|
import sys, math
for line in sys.stdin.readlines():
line = line.strip()
n = int(line)
value = 100000.0
for week in xrange(n):
value = value * 1.05
value = math.ceil(value / 1000) * 1000
print int(value)
| 1 | 1,074,722,522 | null | 6 | 6 |
import itertools as itr
def call(n):
def devided_3(x):
return x % 3 == 0
def has_3(x):
return '3' in str(x)
data = filter(lambda x: devided_3(x) or has_3(x), range(1, n+1))
[print(' {0}'.format(i), end='') for i in data]
print()
if __name__ == '__main__':
n = int(input())
call(n)
|
n = int(input())
l = []
for i in range(3, n + 1):
if i % 3 == 0 or "3" in str(i):
l.append(i)
print("",*l)
| 1 | 945,653,083,348 | null | 52 | 52 |
n=int(input())
l=list(map(int,input().split()))
sum_l=sum(l)
ans=0
mod=10**9+7
for i in range(n):
sum_l-=l[i]
ans+=l[i]*sum_l
print(ans%mod)
|
input()
a = list(map(int, input().split()))
c = 1000000007
print(((sum(a)**2-sum(map(lambda x: x**2, a)))//2)%c)
| 1 | 3,795,327,403,318 | null | 83 | 83 |
import itertools
n = int(input())
s = list(map(int, input().split(' ')))
t = list(map(int, input().split(' ')))
hoge = list(itertools.permutations(range(1, n+1)))
p = 0
q = 0
for i in range(len(hoge)):
if list(hoge[i]) == s:
p = i
if list(hoge[i]) == t:
q = i
print(abs(p - q))
|
from math import factorial
from itertools import permutations
n = int(input())
p = tuple(map(str, input().split()))
q = tuple(map(str, input().split()))
num = [str(i) for i in range(1, n+1)]
allnum = list(i for i in permutations(num, n))
print(abs(allnum.index(p) - allnum.index(q)))
| 1 | 101,010,594,560,032 | null | 246 | 246 |
mod = 1000000007
n = int(input())
A = list(map(int,input().split()))
d = {-1:3}
ans = 1
for a in A:
if a not in d:
d[a] = 1
else:
d[a] += 1
if a-1 not in d:
print(0)
exit()
ans = ans*d[a-1]%mod
d[a-1] -= 1
#print(d)
print(ans)
|
n = int(input())
A = list(map(int,input().split()))
data = [0]*3
ans = 1
mod = pow(10,9)+7
for i in A:
ans *= data.count(i)
ans %= mod
if ans == 0:
break
data[data.index(i)] += 1
print(ans)
| 1 | 130,031,952,669,762 | null | 268 | 268 |
# coding: utf-8
import sys
strings = input()
for s in strings:
if s.islower():
sys.stdout.write(s.upper())
else:
sys.stdout.write(s.lower())
print()
|
i = str(input())
w =''
for let in i:
if(let == let.upper()):
w = w + let.lower()
elif(let == let.lower()):
w = w + let.upper()
else:
w = w + let
print(w)
| 1 | 1,489,120,397,354 | null | 61 | 61 |
import sys
N=input()
i = 1
for i in range(1,N+1):
if (i % 3) == 0 :
sys.stdout.write(" ")
sys.stdout.write("%d" % i)
else:
if (i % 10 ) == 3 :
sys.stdout.write(' ')
sys.stdout.write("%d" % i)
else:
if (i/10)%10 == 3:
#print (i/10)%10,"a"
sys.stdout.write(' ')
sys.stdout.write("%d" % i)
else:
if (i/100)%10 == 3:
sys.stdout.write(' ')
sys.stdout.write("%d" % i)
else:
if (i/100)%10 == 3:
sys.stdout.write(' ')
sys.stdout.write("%d" % i)
else:
if(i/1000)%10 == 3:
sys.stdout.write(' ')
sys.stdout.write("%d" % i)
print ""
|
n = int(input())
i = 1
ret = ""
while True:
x = i
if x % 3 == 0:
ret += " " + str(i)
elif x % 10 == 3:
ret += " " + str(i)
else:
x //= 10
while x != 0:
if x % 10 == 3:
ret += " " + str(i)
break
x //= 10
i+=1
if i > n:
break
print(ret)
| 1 | 926,282,077,822 | null | 52 | 52 |
#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl = lambda: list(map(int, input().split()))
inm = lambda: map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7
#R = 998244353
def ddprint(x):
if DBG:
print(x)
# # # # unionfind.py # # # #
# usage: uf = Unionfind(n) ; x = uf.root(y); uf.conn(a,b)
class Unionfind:
def __init__(s,n):
s.sz = [1] * n
s.ances = [i for i in range(n)]
def root(s,x):
a = []
y = x
while s.ances[y] != y:
a.append(y)
y = s.ances[y]
for z in a:
s.ances[z] = y
return y
def conn(s,x,y):
i = s.root(x)
j = s.root(y)
if i==j:
return
#k = [i,j].min
k = j if (s.sz[i]<s.sz[j]) else i
if k==j:
s.ances[i] = j
else:
s.ances[j] = i
s.sz[k] = s.sz[i] + s.sz[j]
# # # # end unionfind.py # # # #
n,m = inm()
uf = Unionfind(n)
for i in range(m):
a,b = inm()
uf.conn(a-1,b-1)
h = {}
x = 0
for i in range(n):
r = uf.root(i)
if r not in h:
h[r] = 1
else:
h[r] += 1
x = max(x,h[r])
print(x)
|
input()
print(*list(map(int,input().split()))[::-1])
| 0 | null | 2,435,742,057,220 | 84 | 53 |
n = int(input())
ans = 360 / n
i = 1
while int(ans * i) != ans * i:
i += 1
print(int(ans * i))
|
def resolve():
N, M = list(map(int, input().split()))
SC = [list(map(int, input().split())) for _ in range(M)]
value = [None for _ in range(N)]
for s, c in SC:
if not (value[s-1] is None or value[s-1] == c):
print(-1)
return
value[s-1] = c
for i in range(N):
if value[i] is None:
if i == 0:
if N > 1:
value[i] = 1
else:
value[i] = 0
else:
value[i] = 0
if N > 1 and value[0] == 0:
print(-1)
else:
print("".join(map(str, value)))
if '__main__' == __name__:
resolve()
| 0 | null | 36,892,676,049,320 | 125 | 208 |
a,b=map(int,input().split())
s1=str(a)*b
s2=str(b)*a
print(s1 if s2>s1 else s2)
|
a, b = map(int, input().split())
ans = ""
if a <= b:
for i in range(b):
ans += str(a)
elif b < a:
for i in range(a):
ans += str(b)
print(ans)
| 1 | 84,506,711,590,080 | null | 232 | 232 |
n = int(input())
A, B = map(list,zip(*[map(int,input().split()) for i in range(n)]))
A.sort()
B.sort()
if n&1:
print(B[n//2]-A[n//2]+1)
else:
print(B[n//2]+B[n//2-1]-(A[n//2]+A[n//2-1])+1)
|
class Dice():
def __init__(self, a, b, c, d, e, f):
"""面の数字とindexを一致させるために0を挿入"""
self.s = [0, a, b, c, d, e, f]
def rotate(self, dir):
if dir == "N":
self.s[0] = self.s[1] #s[0]に一時的にs[1]を保持
self.s[1] = self.s[2]
self.s[2] = self.s[6]
self.s[6] = self.s[5]
self.s[5] = self.s[0]
return
elif dir == "W":
self.s[0] = self.s[1]
self.s[1] = self.s[3]
self.s[3] = self.s[6]
self.s[6] = self.s[4]
self.s[4] = self.s[0]
return
elif dir == "S":
self.s[0] = self.s[1]
self.s[1] = self.s[5]
self.s[5] = self.s[6]
self.s[6] = self.s[2]
self.s[2] = self.s[0]
return
elif dir == "E":
self.s[0] = self.s[1]
self.s[1] = self.s[4]
self.s[4] = self.s[6]
self.s[6] = self.s[3]
self.s[3] = self.s[0]
return
elif dir == "R":
self.s[0] = self.s[2]
self.s[2] = self.s[3]
self.s[3] = self.s[5]
self.s[5] = self.s[4]
self.s[4] = self.s[0]
return
elif dir == "L":
self.s[0] = self.s[2]
self.s[2] = self.s[4]
self.s[4] = self.s[5]
self.s[5] = self.s[3]
self.s[3] = self.s[0]
return
else:
return
dice = Dice(*list(map(int, input().split())))
for _ in range(int(input())):
t, s = map(int, input().split())
while dice.s[1] != t:
dice.rotate("S")
if dice.s[1] != t:
dice.rotate("E")
while dice.s[2] != s:
dice.rotate("R")
print(dice.s[3])
| 0 | null | 8,724,250,130,948 | 137 | 34 |
# -*- coding: utf-8 -*-
def main():
A, B, C, K = map(int, input().split())
ans = 0
if K <= A:
ans = K
else:
if K <= A + B:
ans = A
else:
ans = A + (-1 * (K - A - B))
print(ans)
if __name__ == "__main__":
main()
|
n = int(input())
x = list(map(float, input().split()))
y = list(map(float, input().split()))
def minc_dis(n, x, y, p):
sum = 0
for i in range(n):
sum = sum + (abs(x[i] - y[i])) ** p
return sum ** (1/p)
def cheb_dis(n, x, y):
dis = 0
for i in range(n):
dif = abs(x[i] - y[i])
if dis < dif:
dis = dif
return dis
for p in range(1 , 4):
print(minc_dis(n, x, y, p))
print(cheb_dis(n, x, y))
#print(cheb_dis(2, [1, 2, 3], [2, 0, 4]))
| 0 | null | 11,007,212,328,250 | 148 | 32 |
N=int(input())
S,T=map(list,input().split())
U=[]
for i in range(N):
U.append("")
for i in range(N):
U[i]=S[i]+T[i]
print(''.join(U))
|
def abc154d_dice_in_line():
n, k = map(int, input().split())
p = list(map(lambda x: (int(x)+1)*(int(x)/2)/int(x), input().split()))
ans = sum(p[0:k])
val = ans
for i in range(k, len(p)):
val = val - p[i-k] + p[i]
ans = max(ans, val)
print(ans)
abc154d_dice_in_line()
| 0 | null | 93,565,176,504,020 | 255 | 223 |
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
n = int(readline())
st = [readline().rstrip().decode().split() for _ in range(n)]
x = readline().rstrip().decode()
cnt = 0
flag = False
for s, t in st:
if flag:
cnt += int(t)
if x == s:
flag = True
print(cnt)
|
string = input()
q = int(input())
for i in range(q):
order = list(input().split())
a, b = int(order[1]), int(order[2])
if order[0] == "print":
print(string[a:b+1])
elif order[0] == "reverse":
string = string[:a] + (string[a:b+1])[::-1] + string[b+1:]
else:
string = string[:a] + order[3] + string[b+1:]
| 0 | null | 49,330,993,939,022 | 243 | 68 |
#!/usr/bin/env python3
def main():
n = int(input())
S, T = input().split()
print(*[s + t for s, t in zip(S, T)], sep="")
if __name__ == "__main__":
main()
|
n = input()
a, b = input().split(" ")
output = ""
for s, t in zip(a, b):
output += s
output += t
print(output)
| 1 | 112,179,106,056,380 | null | 255 | 255 |
x = int(input())
for i in range(1, 10**5):
if 360 * i % x == 0:
print(360 * i // x)
break
|
import math
x = int(input())
y = 360
lcm = x * y // math.gcd(x, y)
print(lcm//x)
| 1 | 13,255,446,723,520 | null | 125 | 125 |
import numpy as np
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
from numba import njit
def getInputs():
D = int(readline())
CS = np.array(read().split(), np.int32)
C = CS[:26]
S = CS[26:].reshape((-1, 26))
return D, C, S
def _compute_score(output, i, d, last):
mask = np.ones((26, ), np.int32)
mask[i] = 0
score = S[d][i] - np.sum(C * (d + 1 - last) * mask)
return score
def _evaluate(output, i, d, last, k):
score = _compute_score(output, i, d, last)
score -= np.sum(C * (d + k + 1 - last))
return score
def solve(k):
output = np.array([], np.int32)
last = np.zeros((26, ), np.int32)
SCORE = 0
for d in range(D):
max_score = float('-inf')
best_i = 0
for i in range(26):
output = np.append(output, i)
#score = _compute_score(output, i, d, last)
score = _evaluate(output, i, d, last, k)
if max_score < score:
max_score = score
best_i = i + 1
output = output[:-1]
output = np.append(output, best_i)
last[best_i - 1] = d + 1
SCORE += max_score
return output, SCORE
D, C, S = getInputs()
max_score = float('-inf')
for k in range(7, 14):
ans, score = solve(k)
if max_score < score:
max_score = score
ANS = ans
print('\n'.join(ANS.astype(str).tolist()))
|
# https://atcoder.jp/contests/abc144/tasks/abc144_d
import math
a, b, x = list(map(int, input().split()))
if a * a * b * (1/2) <= x:
tmp = 2 * (a*a*b-x) / (a*a*a)
print(math.degrees(math.atan(tmp)))
else:
tmp = a*b*b / (2*x)
print(math.degrees(math.atan(tmp)))
| 0 | null | 86,643,298,196,652 | 113 | 289 |
import math
import sys
import collections
import bisect
readline = sys.stdin.readline
def main():
n = int(readline().rstrip())
S = [readline().rstrip() for _ in range(n)]
c = collections.Counter(S)
keys = sorted(c.keys())
maxS = c.most_common()[0][1]
for key in keys:
if c[key] == maxS:
print(key)
if __name__ == '__main__':
main()
|
from math import floor
s = input()
k = int(input())
if len(set(s)) == 1:
print(floor(len(s) * k / 2))
exit(0)
x = s[0]
y = 1
ans = 0
for i in s[1:]:
if i == x:
y += 1
else:
ans += floor(y / 2)
x = i
y = 1
ans += floor(y / 2)
if s[0] != s[-1]:
print(ans * k)
else:
x = s[0]
y = 1
for i in s[1:]:
if x == i:
y += 1
else:
a = y
break
y = 0
for i in s[::-1]:
if x == i:
y += 1
else:
b = y
break
print(ans * k - ((floor(a / 2) + floor(b / 2) - floor((a + b) / 2)) * (k - 1)))
| 0 | null | 122,838,934,276,054 | 218 | 296 |
N = int(input())
A = [int(s) - 1 for s in input().split()]
M = {}
result = 'YES'
for a in A:
if a in M.keys():
result = 'NO'
M[a] = a
print(result)
|
n=int(input())
a=list(map(int,input().split()))
a.sort()
for i in range(n-1):
if a[i]==a[i+1]:
print("NO")
exit()
print("YES")
| 1 | 74,265,365,868,512 | null | 222 | 222 |
n,u,v=map(int,input().split())
tree=[[]for _ in range(n)]
for i in range(n-1):
a,b = map(int,input().split())
tree[a-1].append(b-1)
tree[b-1].append(a-1)
va=[-1]*n
q=[v-1]
va[v-1]=0
while q:
x=q.pop()
for j in tree[x]:
if va[j]==-1:
q.append(j)
va[j]=va[x]+1
q=[u-1]
vt=[-1]*n
vt[u-1]=0
ans=0
while q:
x=q.pop()
ans=max(ans,va[x])
for j in tree[x]:
if vt[j]==-1:
if vt[x]+1<va[j]:
q.append(j)
vt[j]=vt[x]+1
elif vt[x]+1==va[j]:
vt[j]=vt[x]+1
print(ans-1)
|
n=int(input())
a,b=input().split()
s=""
for i in range(n):
s+=a[i]+b[i]
print(s)
| 0 | null | 115,043,204,129,352 | 259 | 255 |
N=int(input())
S,T=input().split()
ans=''
for i in range(N):
ans += S[i]
for j in range(N):
if i==j:
ans +=T[j]
print(ans)
|
def solve():
N = int(input())
S, T = map(str, input().split())
ans = ""
for i in range(N): ans += S[i] + T[i]
print(ans)
if __name__ == "__main__":
solve()
| 1 | 111,819,056,694,528 | null | 255 | 255 |
N = int(input())
L = list("abcdefghijklmnopqrstuvwxyz")
a = 1
while N > 26**a:
N = N - 26**a
a += 1
pre = []
for i in reversed(range(1,a)):
r = (N-1) // 26**i
pre.append(r)
N = int(N%(26**i))
ans = ''
for i in pre:
ans += L[i]
print(ans+L[N-1])
|
num = int(input())
def num2alpha(num):
if num<=26:
return chr(96+num)
elif num%26==0:
return num2alpha(num//26-1)+chr(122)
else:
return num2alpha(num//26)+chr(96+num%26)
print(num2alpha(num))
| 1 | 11,905,904,709,698 | null | 121 | 121 |
N = int(input())
d = {}
for n in range(N):
s = input()
d[s] = True
print(len(d))
|
s=input()
if s=="RSR":
print("1")
else:
ans=s.count("R")
print(ans)
| 0 | null | 17,707,650,022,920 | 165 | 90 |
n = int(input())
output = 'ACL'*n
print(output)
|
num = int(input())
a = ""
for _ in range(num):
a += "ACL"
print(a)
| 1 | 2,172,432,153,738 | null | 69 | 69 |
A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())
if A > B:
x = A
A = B
B = x
if V <= W:
ans="NO"
elif T*V+A-B >= T*W:
ans="YES"
else:
ans="NO"
print(ans)
|
while True:
H, W = map(int, raw_input().split())
if H == 0 or W == 0:
break
for _ in range(H):
print '#' * W
print ''
| 0 | null | 8,023,690,714,838 | 131 | 49 |
import math
k = int(input())
ans =0
da =0
for i in range(1,k+1):
for j in range(1,k+1):
for n in range(1,k+1):
da = math.gcd(i,j)
ans += math.gcd(da,n)
print(ans)
|
abc = input().split()
if(int(abc[0]) < int(abc[1]) and int(abc[1]) < int(abc[2])):
print('Yes')
else:
print('No')
| 0 | null | 17,894,480,956,640 | 174 | 39 |
s = "hi"
S = input()
flag = False
for i in range(5):
if S==s:
flag=True
break
s = s+"hi"
if flag:
print("Yes")
else:
print("No")
|
class Dice():
def __init__(self, dice_labels):
self.top = dice_labels[0]
self.south = dice_labels[1]
self.east = dice_labels[2]
self.west = dice_labels[3]
self.north = dice_labels[4]
self.bottom = dice_labels[5]
def roll(self, str_direction):
if str_direction == 'E':
self.__roll_to_east()
elif str_direction == 'W':
self.__roll_to_west()
elif str_direction == 'S':
self.__roll_to_south()
elif str_direction == 'N':
self.__roll_to_north()
def turn(self, str_direction):
if str_direction == 'L':
self.__turn_left()
elif str_direction == 'R':
self.__turn_right()
def __roll_to_east(self):
self.top, self.east, self.west, self.bottom = (self.west, self.top, self.bottom, self.east)
def __roll_to_west(self):
self.top, self.east, self.west, self.bottom = (self.east, self.bottom, self.top, self.west)
def __roll_to_south(self):
self.top, self.south, self.north, self.bottom = (self.north, self.top, self.bottom, self.south)
def __roll_to_north(self):
self.top, self.south, self.north, self.bottom = (self.south, self.bottom, self.top, self.north)
def __turn_right(self):
self.south, self.east, self.west, self.north = (self.east, self.north, self.south, self.west)
def __turn_left(self):
self.south, self.east, self.west, self.north = (self.west, self.south, self.north, self.east)
dice_labels = input().split(' ')
num_question = int(input())
dice = Dice(dice_labels)
for i in range(0, num_question):
target_top_label, target_for_label = tuple(input().split(' '))
for j in range(0, 2):
for k in range(0, 4):
if dice.top != target_top_label:
dice.roll('N')
dice.turn('R')
for j in range(0, 4):
if dice.south != target_for_label:
dice.turn('R')
print(dice.east)
| 0 | null | 26,875,485,374,052 | 199 | 34 |
import math
n = int(input())
A = list(map(int,input().split()))
count = 0
def merge(A, left, mid, right):
global count
L = A[left:mid]
L.append(math.inf)
R = A[mid:right]
R.append(math.inf)
i = 0
j = 0
for k in range(left,right):
count += 1
if L[i] <= R[j]:
A[k] = L[i]
i = i + 1
else:
A[k] = R[j]
j = j + 1
def mergeSort(A,left,right):
if left +1 < right:
mid = (left+right) // 2
mergeSort(A,left,mid)
mergeSort(A,mid,right)
merge(A,left,mid,right)
mergeSort(A,0,n)
x = list(map(str,A))
print(" ".join(x))
print(count)
|
N = int(input())
A_ = input().split()
A = [int(i) for i in A_]
S = 0
a = A[0]
for i in range(len(A)-1):
if a > A[i+1]:
S += a-A[i+1]
else:
a = A[i+1]
print(S)
| 0 | null | 2,351,930,799,054 | 26 | 88 |
n = int(raw_input())
dp = {}
def fib(n):
if n in dp: return dp[n]
if n == 0:
dp[n] = 1
return 1
elif n == 1:
dp[n] = 1
return 1
else:
dp[n] = fib(n-1)+fib(n-2)
return dp[n]
print fib(n)
|
s = input()
ans = s[0:3]
print(ans)
| 0 | null | 7,428,365,791,672 | 7 | 130 |
from math import ceil
def main():
n,x,t=map(int,input().split())
print(ceil(n/x)*t)
main()
|
time=1
n=int(input())
A=[[] for i in range(n)]
d=[0 for i in range(n)]
f=[0 for i in range(n)]
for i in range(n):
a=list(map(int,input().split()))
for j in range(a[1]):
A[i].append(a[2+j]-1)
def dfs(q,num):
global d,f,time
d[num]=time
for nx in q[num]:
if d[nx]==0:
time+=1
dfs(q,nx)
time+=1
f[num]=time
for i in range(n):
if d[i]==0:#unvisit
dfs(A,i)
time+=1
for i in range(n):
print(i+1,d[i],f[i])
| 0 | null | 2,162,047,049,410 | 86 | 8 |
import sys
input = lambda: sys.stdin.readline().rstrip()
def main():
a = list(map(int, input().split()))
if sum(a) >= 22:
print('bust')
else:
print('win')
if __name__ == '__main__':
main()
|
cards = list(map(int, input().split()))
print('win' if sum(cards) <= 21 else 'bust')
| 1 | 118,688,203,023,748 | null | 260 | 260 |
# ABC152
a, b = map(int, input().split())
print(min(str(a)*b, str(b)*a))
|
def solve():
A,B, M = map(int, input().split())
a_kind = list(map(int, input().split()))
b_kind = list(map(int, input().split()))
Coupon = [list(map(int, input().split())) for _ in range(M)]
ans = min(a_kind) + min(b_kind)
for x,y,disc in Coupon:
ans = min(ans, a_kind[x-1] + b_kind[y-1] - disc)
print(ans)
if __name__ == '__main__':
solve()
| 0 | null | 69,333,740,741,812 | 232 | 200 |
import math
a,b,c=map(float,raw_input().split())
c = c / 180 * math.pi
print "%.10f" % float(a*b*math.sin(c)/2)
x = math.sqrt(a**2 + b**2 - 2 * a * b * math.cos(c))
print "%.10f" % float(a + b + x)
print "%.10f" % float(b*math.sin(c))
|
import math
a,b,C=map(int,input().split())
c=C/180*math.pi
d=math.sqrt(a**2+b**2-2*a*b*math.cos(c))
S=1/2*a*b*math.sin(c)
L=a+b+d
h=2*S/a
print("{:.8f}".format(S))
print("{:.8f}".format(L))
print("{:.8f}".format(h))
| 1 | 180,266,219,364 | null | 30 | 30 |
N, K = [int(i) for i in input().split()]
R, S, P = [int(i) for i in input().split()]
T = input()
def addScore(hand):
if hand == 'r':
return P
elif hand == 's':
return R
else :
return S
score = 0
score_flag = [0 for i in range(N)]
for l in range(len(T)):
if l < K:
score += addScore(T[l])
score_flag[l] = 1
else :
if T[l] == T[l-K] and score_flag[l-K] == 1:
continue
else :
score += addScore(T[l])
score_flag[l] = 1
print(score)
|
s,t = map(str, input().split())
a,b = map(int, input().split())
u = input()
print(a-1 if s==u else a, b if s==u else b-1)
| 0 | null | 89,502,688,794,460 | 251 | 220 |
import copy
n = int(raw_input())
cards = raw_input().split()
cards1 = copy.deepcopy(cards)
cards2 = copy.deepcopy(cards)
def isbig(card1, card2):
if int(card1[1]) > int(card2[1]):
return 2
elif int(card1[1]) == int(card2[1]):
return 1
else:
return 0
def BubbleSort(c, n):
temp = 0
for i in range(n):
for j in reversed(range(i+1,n)):
if isbig(c[j], c[j-1]) == 0:
temp = c[j]
c[j] = c[j-1]
c[j-1] = temp
return c
def SelectionSort(c, n):
temp = 0
for i in range(n):
minj = i
for j in range(i,n):
if isbig(c[j], c[minj]) == 0:
minj = j
temp = c[i]
c[i] = c[minj]
c[minj] = temp
#print("*{:}".format(c))
return c
def isstable(unsort, sort):
for i in range(n):
for j in range(i+1,n):
for k in range(n):
for l in range(k+1,n):
if isbig(unsort[i], unsort[j]) == 1 and unsort[i] == sort[l] and unsort[j] == sort[k]:
return 0
return 1
for i in range(n):
if i != n-1:
print BubbleSort(cards1, n)[i],
else:
print BubbleSort(cards1, n)[i]
if isstable(cards, BubbleSort(cards1, n)) == 1:
print("Stable")
else:
print("Not stable")
for i in range(n):
if i != n-1:
print SelectionSort(cards2, n)[i],
else:
print SelectionSort(cards2, n)[i]
if isstable(cards, SelectionSort(cards2, n)) == 1:
print("Stable")
else:
print("Not stable")
|
n, k, s = map(int, input().split())
for i in range(n):
if k == 0:
if s-1 > 0:
print(s-1, end=' ')
else:
print(s+1, end=' ')
else:
print(s, end=' ')
k -= 1
print()
| 0 | null | 45,504,410,213,180 | 16 | 238 |
n = int(input())
lis = input().split()
dic = {}
for i in range(n):
if lis[i] not in dic:
dic[lis[i]] = 1
else:
dic[lis[i]] += 1
for x in dic.values():
if x != 1:
print("NO")
exit()
print("YES")
|
import sys
input = sys.stdin.readline
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def main():
mod=10**9+7
N=I()
A=LI()
A.sort()
flag=1
for i in range(N-1):
if A[i]==A[i+1]:
flag=0
break
if flag:
print("YES")
else:
print("NO")
main()
| 1 | 73,486,760,585,810 | null | 222 | 222 |
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])
|
N=int(input())
DP=[0]*(N+1)
tmp=0
mod=10**9+7
if N<3:
print(0)
exit()
DP[3]=1
for i in range(4,N+1):
DP[i]=(DP[i-1]+DP[i-3])%mod
print(DP[N]%mod)
| 1 | 3,315,952,082,342 | null | 79 | 79 |
from sys import stdin
from collections import deque
n = int(input())
d = [-1] * (n + 1)
def bfs():
d[1] = 0
dq = deque([1])
while len(dq) != 0:
v = dq.popleft()
for c in G[v]:
if d[c] != -1 : continue
d[c] = d[v] + 1
dq.append(c)
for i, x in enumerate(d[1:], start=1):
print(i, x)
G = [0] + [list(map(int, input().split()[2:])) for i in range(n)]
bfs()
|
from collections import deque
n=int(input())
edge=[[] for _ in range(n+1)]
for i in range(n):
v,k,*u=map(int,input().split())
edge[v]=u
p=[-1]*(n+1)
p[1]=0
q=deque([])
q.append(1)
v=[1]*(n+1)
v[1]=0
while q:
now=q.popleft()
for i in edge[now]:
if v[i]:
q.append(i)
p[i]=p[now]+1
v[i]=0
for i in range(1,n+1):
print(i,p[i])
| 1 | 4,711,162,128 | null | 9 | 9 |
import math
n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
d_1 = 0
d_2 = 0
d_3 = 0
d_4 = []
for i in range(n):
d_1 += abs(x[i] - y[i])
d_2 += abs(x[i] - y[i]) ** 2
d_3 += abs(x[i] - y[i]) ** 3
d_4.append(abs(x[i] - y[i]))
print("{0:8f}".format(d_1))
print("{0:8f}".format(math.sqrt(d_2)))
print("{0:8f}".format(d_3 ** (1/3)))
print("{0:8f}".format(max(d_4)))
|
n = int(input())
x = [float(s) for s in input().split()]
y = [float(s) for s in input().split()]
xy = [abs(xi-yi) for xi,yi in zip(x,y)]
D = lambda p:sum([xyi**p for xyi in xy])**(1/p)
print(D(1.0))
print(D(2.0))
print(D(3.0))
print(max(xy))
| 1 | 214,978,390,112 | null | 32 | 32 |
H, W, K = map(int, input().split())
m = []
for h in range(H):
m.append(list(map(int, list(input()))))
ans = float('inf')
for hb in range(2**(H-1)):
hl = []
for i in range(H-1):
if hb & (1 << i) > 0:
hl.append(i+1)
t = len(hl)
hl = [0]+hl+[H]
w, pw = 0, 0
wl = [0]*len(hl)
while w < W:
ok = True
for i in range(len(hl)-1):
sh, eh = hl[i], hl[i+1]
for h in range(sh, eh):
wl[i] += m[h][w]
if wl[i] > K:
ok = False
break
if not ok:
break
if not ok:
if pw == w:
t = float('inf')
break
pw, w = w, w
t += 1
wl = [0]*len(hl)
else:
w += 1
ans = min(t, ans)
print(ans)
|
N=int(input())
x=(10**N-2*(9**N)+8**N)%(10**9+7)
print(x)
| 0 | null | 25,835,143,059,268 | 193 | 78 |
import collections
n = []
while True:
try:
N = input()
except EOFError:
break
N = N.lower()
N.replace('', ' ')
n.extend(N)
c = collections.Counter(n)
for i in range(97, 97+26):
print("%s : %d" % (chr(i),c[chr(i)]) )
|
def main():
n = int(input())
A = list(map(int, input().split()))
B = [0] * (n+1)
if n == 0:
x = A[0]
if x == 1:
print(1)
else:
print(-1)
exit()
# Adが葉の個数、Bdが葉でないものの個数
# A0 + B0 = 1
# Bd ≤ Ad+1 + Bd+1 ≤ 2Bd --> B[d-1] - A[d] ≤ B[d] ≤ 2B[d-1] - A[d]
# Bd ≤ Ad+1 + Ad+2 + · · · + AN = s - (A1 + ... + Ad)
# now_s :葉の数
now_s = sum(A)
s = now_s
for i in range(n+1):
if i == 0:
B[i] = 1 - A[i]
else:
now_s -= A[i]
B[i] = min(now_s, 2 * B[i - 1] - A[i])
#print(A,B,now_s)
if B[i] < 0:
print(-1)
exit()
print(sum(B) + s)
if __name__ == "__main__":
main()
| 0 | null | 10,159,338,055,392 | 63 | 141 |
x,y = map(int,input().split())
def point(a):
if a == 1:
return 300000
elif a == 2:
return 200000
elif a == 3:
return 100000
else:
return 0
c = point(x)
b = point(y)
if x == 1 and y == 1:
print(1000000)
else:
print(c+b)
|
n, k = map(int, input().split())
h = sorted(map(int, input().split()))
print([0, sum(h[: n - k])][n > k])
| 0 | null | 109,508,347,528,118 | 275 | 227 |
n=input()
m = 100000
for _ in xrange(n):
m = m + m*0.05
if m % 1000:
m = m + 1000 - m % 1000
print int(m)
|
i = int(input())
x = 100000
for _ in range(i):
x *= 1.05
x = int((x+999) / 1000) * 1000
print(x)
| 1 | 1,205,687,736 | null | 6 | 6 |
N = int(input())
A = list(map(int,input().split()))
Q = int(input())
C = (10**5+1)*[0]
T = sum(A)
for a in A:
C[a]+=1
for q in range(Q):
b,c = map(int,input().split())
T+=C[b]*(c-b)
C[c]+=C[b]
C[b]=0
print(T)
|
# -*= coding: utf-8 -*-
from collections import deque
S = input()
Q = int(input())
query = list()
for i in range(Q):
query.append(list(map(str, input().split())))
d = deque()
for s in S:
d.append(s) # 右からsを追加
is_reverse = False
for q in query:
if len(q) == 1:
# Tiが1の場合
is_reverse = not is_reverse
else:
# Tiが2の場合
if q[1] == '1':
# Fiが1の場合
if is_reverse == False:
d.appendleft(q[2])
else:
d.append(q[2])
else:
# Fiが2の場合
if is_reverse == False:
d.append(q[2])
else:
d.appendleft(q[2])
ans = ''
if is_reverse == True:
d.reverse()
ans = ''.join(d)
print(ans)
| 0 | null | 34,648,348,965,750 | 122 | 204 |
n = int(input())
data = [input().split() for i in range(n)]
for i in range(n - 2):
if int(data[i][0]) == int(data[i][1]) and int(data[i + 1][0]) == int(data[i+1][1]) and int(data[i+2][0]) == int(data[i+2][1]):
print('Yes')
break
else:
print('No')
|
ans = 0
s = []
for i in range(int(input())):
a,b = map(int,input().split())
if a==b:
ans += 1
s.append(ans)
else:
ans = 0
if len(s)!=0 and max(s)>=3:
print('Yes')
elif len(s)==0:
print('No')
else:
print('No')
| 1 | 2,470,087,072,036 | null | 72 | 72 |
import sys
import math
from collections import defaultdict, deque, Counter
from copy import deepcopy
from bisect import bisect, bisect_right, bisect_left
from heapq import heapify, heappop, heappush
input = sys.stdin.readline
def RD(): return input().rstrip()
def F(): return float(input().rstrip())
def I(): return int(input().rstrip())
def MI(): return map(int, input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def LF(): return list(map(float,input().split()))
def Init(H, W, num): return [[num for i in range(W)] for j in range(H)]
def main():
N = I()
res = 0
for i in range(N):
a,b = MI()
if a==b:
res+=1
if res==3:
print("Yes")
exit()
else:
res=0
print("No")
if __name__ == "__main__":
main()
|
a = int(input())
b = int(input())
for i in range(1,4):
if i !=a and i!= b:
print(i)
| 0 | null | 56,446,963,391,322 | 72 | 254 |
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)
def solve(L: int):
ret = (L / 3) ** 3
print(ret)
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
L = int(next(tokens)) # type: int
solve(L)
if __name__ == '__main__':
main()
|
L = int(input())
L = L/3
V=1
for i in range (3):
V*=L
print (V)
| 1 | 46,934,700,038,380 | null | 191 | 191 |
def merge(A, left, mid, right, c):
global counter
n1 = mid - left
n2 = right - mid
L = [0] * (n1+1)
R = [0] * (n2+1)
for i in range(n1):
L[i] = A[left + i]
for i in range(n2):
R[i] = A[mid + i]
L[n1] = 1000000000
R[n2] = 1000000000
i = 0
j = 0
for k in range(left,right):
c += 1
if L[i] <= R[j]:
A[k] = L[i]
i += 1
else :
A[k] = R[j]
j += 1
L.pop()
R.pop()
return c
def mergeSort(A, left, right, c):
if left+1 < right:
mid = int((left + right)/2)
c = mergeSort(A, left, mid, c)
c = mergeSort(A, mid, right, c)
c = merge(A, left, mid, right, c)
return c
if __name__ == '__main__':
num = int(input())
m = list(map(int,input().split()))
c = 0
c = mergeSort(m, 0, num, c)
print(' '.join(map(str,m)))
print(str(c))
|
k = int(input())
ans = 0
ai = 0
for i in range(k+2):
ai = ((ai * 10) + 7) % k
if ai == 0:
ans = i + 1
print(ans)
exit()
ans = -1
print(ans)
| 0 | null | 3,107,847,722,990 | 26 | 97 |
import queue
def main():
n = int(input())
A = list(map(int,input().split()))
A = sorted(A,reverse=True)
q = queue.PriorityQueue()
q.put([-1*A[0],-1*A[0]])
ans = 0
for a in A[1:]:
_min, _max = map(lambda x:-1*x,q.get())
ans += _min
q.put([-1*a,-1*_min])
q.put([-1*a,-1*_max])
print(ans)
return
if __name__ == "__main__":
main()
|
from collections import deque
n = int(input())
linked_list = deque([])
for i in range(n):
line = input().split()
cmd = line[0]
if len(line) == 2:
value = line[1]
if cmd == "insert":
linked_list.appendleft(value)
elif cmd == "delete":
if value in linked_list:
linked_list.remove(value)
elif cmd == "deleteFirst":
linked_list.popleft()
elif cmd == "deleteLast":
linked_list.pop()
print(*linked_list)
| 0 | null | 4,566,717,268,680 | 111 | 20 |
import math
N = int(input())
A = list(map(int,input().split()))
up = [[] for _ in range(N+1)] # 葉から考慮した場合の、最小値
up[N] = [A[N],A[N]]
#print(up)
for i in reversed(range(N)):
Min, Max = up[i+1]
#print(Min,Max)
Min_n = math.ceil(Min/2) + A[i]
Max_n = Max + A[i]
#print(A[i],i)
up[i] = [Min_n, Max_n]
#print(up)
if up[0][0] >= 2:
print(-1)
else:
down = 1
#print(down)
ans = 1
for i in range(1, N+1):
down *= 2
down = min(down,up[i][1]) - A[i]
ans += down + A[i]
print(ans)
|
print(sum([i//500*1000+i%500//5*5 for i in [int(input())]]))
| 0 | null | 30,768,885,488,260 | 141 | 185 |
class Stack():
def __init__(self):
self.stack = [0 for _ in range(200)]
self.top = 0
def isEmpty(self):
return self.top == 0
def isFull(self):
return self.top >= len(self.stack) - 1
def push(self, x):
if self.isFull():
print "error"
return exit()
self.top += 1
self.stack[self.top] = x
def pop(self):
if self.isEmpty():
print "error"
return exit()
a = self.stack[self.top]
del self.stack[self.top]
self.top -= 1
return a
def lol(self):
return self.stack[self.top]
def main():
st = Stack()
data = raw_input().split()
for i in data:
if i == '+':
b = int(st.pop())
a = int(st.pop())
st.push(a + b)
elif i == '-':
b = int(st.pop())
a = int(st.pop())
st.push(a - b)
elif i == '*':
b = int(st.pop())
a = int(st.pop())
st.push(a * b)
else:
st.push(i)
print st.lol()
if __name__ == '__main__':
main()
|
list = input().split(' ')
OPERATOR = {
'+': lambda a, b: a + b,
'*': lambda a, b: a * b,
'-': lambda a, b: a - b,
'/': lambda a, b: a / b,
}
stack = []
for item in list:
if item in OPERATOR:
b = stack.pop()
a = stack.pop()
stack.append(OPERATOR[item](a, b))
else:
stack.append(int(item))
print(stack.pop())
| 1 | 34,429,198,748 | null | 18 | 18 |
import itertools
a, b, c = map(int, input().split(" "))
k = int(input())
f = False
for conb in list(itertools.combinations_with_replacement([0, 1, 2], k)):
a_i = conb.count(0)
b_i = conb.count(1)
c_i = conb.count(2)
if (a * (2 ** a_i) < b * (2 **b_i)) and (b * (2 ** b_i) < c * (2 ** c_i)):
f = True
if f:
print("Yes")
else:
print("No")
|
import os
import sys
from collections import defaultdict, Counter
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush,heapify
from math import ceil, floor, sqrt
from copy import deepcopy
def main():
a,b,c = map(int, input().split())
k = int(input())
flag = False
if a < b < c:
print("Yes")
sys.exit()
for i in range(k):
if a < b < c:
c *= 2
if a >= b:
if b >= c:
c *= 2
else:
b *= 2
else:
if b >= c:
c *= 2
else:
b *= 2
if a < b < c:
print("Yes")
else:
print("No")
if __name__ == '__main__':
main()
| 1 | 6,847,723,856,640 | null | 101 | 101 |
n = input()
n = n.split()
k = int(n[1])
n = int(n[0])
c = [0]
for f in range(n-1):
c.append(0)
for b in range(k):
d = int(input())
a = input()
a = a.split()
for e in range(d):
c[int(a[e])-1] = 1
h = 0
for g in range(n):
if c[g] == 0:
h = h + 1
print(h)
|
n,q = [int(s) for s in input().split()]
queue = []
for i in range(n):
name,time = input().split()
queue.append([name,int(time)])
time = 0
while queue:
processing = queue.pop(0)
t = min(processing[1], q)
time += t
processing[1] -= t
if processing[1] == 0:
print(processing[0],time)
else:
queue.append(processing)
| 0 | null | 12,373,505,655,268 | 154 | 19 |
N, X, Y = [int(x) for x in input().split()]
counter = [0] * N
for i in range(1, N + 1):
for j in range(i + 1, N + 1):
d = min(abs(i - j), abs(i - X) + abs(j - Y) + 1, abs(i - Y) + abs(j - X) + 1)
counter[d] += 1
for i in range(1, N):
print(counter[i])
|
N = int(input())
s, t = [], []
for i in range(N):
s_i, t_i = input().split(" ")
t_i = int(t_i)
s.append(s_i)
t.append(t_i)
X = input()
idx = 0
while idx < N:
if s[idx] == X:
idx += 1
break
idx += 1
ans = 0
for i in range(idx, N):
ans += t[i]
print(ans)
| 0 | null | 70,535,279,579,388 | 187 | 243 |
import sys
import math
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
a,b,x = map(int, input().split())
s = a * b
theta = 0
if a * a * b / 2 < x:
theta = math.atan(2 * (a**2 * b - x) / a**3)
else:
theta = math.atan((a * b**2) / (2 * x))
deg = math.degrees(theta)
print('{:.10f}'.format(deg))
|
K = int(input())
if K%2==0:
print(-1)
elif K==1:
print(1)
elif K==7:
print(1)
else:
if K%7==0:
K = K//7
a = 1
cnt = 1
ind = -1
for i in range(K):
a = (a*10)%K
cnt += a
if cnt%K==0:
ind = i
break
if ind<0:
print(-1)
else:
print(ind+2)
| 0 | null | 84,633,243,665,160 | 289 | 97 |
N = int(input())
A = list(map(int, input().split()))
max_a = max(A) + 1
counter = [0 for _ in range(max_a)]
for i in A:
for j in range(i, max_a, i):
counter[j] += 1
res = 0
for a in A:
if counter[a] == 1:
res += 1
#print(counter)
print(res)
|
a,b,c=[int(i) for i in input().split()]
if((a+b+c)>=22):
print('bust')
else:
print('win')
| 0 | null | 66,738,518,883,548 | 129 | 260 |
# Python 3+
#-------------------------------------------------------------------------------
import sys
#ff = open("test.txt", "r")
ff = sys.stdin
cnt = 1
for line in ff :
if int(line) == 0 : break
print("Case {0}: {1}".format(cnt, line), end="")
cnt += 1
|
n = 0
while True:
x = input()
if x==0:
break
n+=1
print 'Case %d: %d' %(n, x)
| 1 | 481,754,427,648 | null | 42 | 42 |
def linear_search(num_list,target):
for num in num_list:
if num == target:
return 1
return 0
n = input()
num_list = list(map(int,input().split()))
q = input()
target_list = list(map(int,input().split()))
ans = 0
for target in target_list:
ans += linear_search(num_list,target)
print(ans)
|
def linear_search(search_list, target):
i = 0
search_list.append(target)
while search_list[i] != target:
i += 1
if i == len(search_list) - 1:
return -1
else:
return i
if __name__ == '__main__':
n = int(input())
S = [int(x) for x in input().split()]
q = int(input())
T = [int(x) for x in input().split()]
count = 0
for x in T:
if linear_search(S, x) > -1:
count += 1
print(count)
| 1 | 68,442,739,732 | null | 22 | 22 |
import math
def lcm(a, b):
return int(a * b/ math.gcd(a, b))
a, b = map(int, input().split())
print(lcm(a,b))
|
import math
def lcm(A, B):
return int((A * B) / math.gcd(A, B))
A, B = map(int, input().split())
print(lcm(A,B))
| 1 | 113,406,421,290,852 | null | 256 | 256 |
a,b,k = map(int,input().split())
t1 = min(a,k)
k -= t1
a -= t1
t2 = min(b,k)
k -= t2
b -= t2
print(a,b)
|
A, B, K = map(int, input().split())
if A > K:
after_A = A - K
after_K = 0
else:
after_A = 0
after_K = K - A
if B > after_K:
after_B = B - after_K
final_K = 0
else:
after_B = 0
final_K = after_K - B
print(after_A, after_B)
| 1 | 104,091,537,704,128 | null | 249 | 249 |
def answer(x: int) -> int:
dict = {500: 1000, 5: 5}
happiness = 0
for coin in sorted(dict, reverse=True):
q, x = divmod(x, coin)
happiness += dict[coin] * q
return happiness
def main():
x = int(input())
print(answer(x))
if __name__ == '__main__':
main()
|
# ABC160 B
x = int(input())
a,moda = divmod(x,500)
b,modb = divmod(moda,5)
print(a*1000+b*5)
| 1 | 42,655,477,289,568 | null | 185 | 185 |
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque
n,k = [int(x) for x in stdin.readline().rstrip().split()]
p = [(int(x)+1)/2 for x in stdin.readline().rstrip().split()]
m = sum(p[0:k])
maxm = m
for i in range(1,n-k+1):
m = m - p[i-1] + p[i+k-1]
maxm = max([maxm,m])
print(maxm)
|
def getN():
return int(input())
def getNM():
return map(int, input().split())
def getList():
return list(map(int, input().split()))
def getArray(intn):
return [int(input()) for i in range(intn)]
def input():
return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
ns = []
while len(ns) < rantime:
n = random.randint(ran1, ran2)
if not n in ns:
ns.append(n)
return sorted(ns)
def rand_query(ran1, ran2, rantime):
r_query = []
while len(r_query) < rantime:
n_q = rand_ints_nodup(ran1, ran2, 2)
if not n_q in r_query:
r_query.append(n_q)
return sorted(r_query)
from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right
import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7
#############
# Main Code #
#############
def segfunc(x, y):
return min(x, y)
ide_ele = float('inf')
class SegTree:
def __init__(self, init_val, segfunc, ide_ele):
n = len(init_val)
self.segfunc = segfunc
self.ide_ele = ide_ele
self.num = 1 << (n - 1).bit_length()
self.tree = [ide_ele] * 2 * self.num
# 配列の値を葉にセット
for i in range(n):
self.tree[self.num + i] = init_val[i]
# 構築していく
for i in range(self.num - 1, 0, -1):
self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])
def update(self, k, x):
k += self.num
self.tree[k] = x
while k > 1:
self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
k >>= 1
def query(self, l, r):
res = self.ide_ele
l += self.num
r += self.num
while l < r:
if l & 1:
res = self.segfunc(res, self.tree[l])
l += 1
if r & 1:
res = self.segfunc(res, self.tree[r - 1])
l >>= 1
r >>= 1
return res
# 最短手数k回でクリアできるとすると、
# 1 ~ M の内1つをk回選んで合計をNにする
N, M = getNM()
S = input()
trap = set()
for i in range(len(S)):
if S[i] == '1':
trap.add(i)
# これABC011 123引き算と同じでは
# 案1 dpを使う
# dp[i]: iマスに止まる時の最短手順
# dp[i]の時 dp[i + 1] ~ dp[i + M]についてmin(dp[i] + 1, dp[i + j])を見ていく
# 決まったらdpを前から見ていき最短手順がdp[i] - 1になるものを探す(辞書順)
# → M <= 10 ** 5より多分無理
# セグ木使えばいける?
# dp[i] = dp[i - M] ~ dp[i - 1]の最小値 + 1
# dp[i - M] ~ dp[i - 1]の最小値はlogNで求められるので全体でNlogN
dp = [float('inf')] * (N + 1)
dp[0] = 0
seg = SegTree([float('inf')] * (N + 1), segfunc, ide_ele)
seg.update(0, 0)
# dp[i]をレコード
for i in range(1, N + 1):
# もしドボンマスなら飛ばす(float('inf')のまま)
if i in trap:
continue
# dp[i - M] ~ dp[i - 1]の最小値をサーチ
min_t = seg.query(max(0, i - M), i)
seg.update(i, min_t + 1)
dp[i] = min_t + 1
# goalに到達できないなら
if dp[-1] == float('inf'):
print(-1)
exit()
# 何回の試行で到達できるかをグルーピング
dis = [[] for i in range(dp[-1] + 1)]
for i in range(len(dp)):
if dp[i] == float('inf'):
continue
dis[dp[i]].append(i)
# ゴールから巻き戻っていく
now = dp[-1]
now_index = N
ans = []
# 辞書順で1 4 4 < 3 3 3なので
# 一番前にできるだけ小さい数が来るようにする
for i in range(now, 0, -1):
# dp[i] - 1回で到達できる
# 現在地点からMマス以内
# で最も現在地点から遠いところが1つ前のマス
index = bisect_left(dis[i - 1], now_index - M)
# サイコロの目を決める
ans.append(now_index - dis[i - 1][index])
# 現在地点更新
now_index = dis[i - 1][index]
for i in ans[::-1]:
print(i)
| 0 | null | 107,107,940,206,378 | 223 | 274 |
N=int(input())
x=list(map(int,input().split()))
sum=0
for i in range(1,N):
if x[i]<x[i-1]:
t=x[i-1]-x[i]
sum+=t
x[i]=x[i-1]
print(sum)
|
def main():
N = int(input())
A = [int(i) for i in input().split()]
ma = A[0]
ans = 0
for a in A:
ma = max(ma, a)
ans += ma - a
print(ans)
if __name__ == '__main__':
main()
| 1 | 4,581,235,185,852 | null | 88 | 88 |
import sys,queue,math,copy,itertools,bisect,collections,heapq
def main():
sys.setrecursionlimit(10**7)
INF = 10**5 + 1
MOD = 10**9 + 7
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())
SI = lambda : sys.stdin.readline().rstrip()
N,M = LI()
S = SI()
N0 = 2 ** N.bit_length()
st = [INF] * (2*N0)
def update(i,x):
i += N0-1
st[i] = x
while i > 0:
i = (i-1) // 2
st[i] = min(st[i*2+1], st[i*2+2])
def query(l,r):
L = l+N0; R = r+N0
ret = INF
while L < R:
if L % 2:
ret = min(ret,st[L-1])
L += 1
if R % 2:
R -= 1
ret = min(ret,st[R-1])
L //= 2; R //= 2
return ret
update(0,0)
for i in range(1,N+1):
if S[i] == '1': continue
else:
if i <= M:
update(i,1)
else:
x = query(i-M,i)
update(i,x+1)
if st[N+N0-1] >= INF:
print(-1)
else:
ans = []
f = N
last_i = N
s = st[N+N0-1]
d = 1
cnt = 0
for i in range(N-1,-1,-1):
cnt += 1
if st[i+N0-1] == s-1:
d = f - i
last_i = i
if cnt == M:
ans.append(d)
f = last_i
s -= 1
cnt = f - i
if f > 0:
ans.append(f)
print(*reversed(ans),sep=' ')
if __name__ == '__main__':
main()
|
str = input()
cnt = 0
if str[0]=="R" and str[1]=="R" and str[2]=="R":
cnt = 3
elif (str[0]=="R" and str[1]=="R") or (str[1]=="R" and str[2]=="R"):
cnt = 2
elif str[0]=="R" or str[1]=="R" or str[2]=="R":
cnt = 1
print(cnt)
| 0 | null | 71,892,492,868,240 | 274 | 90 |
OFFSET = 97
def main():
n,m,k = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
total = 0
a_index = 0
b_index = 0
while a_index != len(A):
if total + A[a_index] <= k:
total += A[a_index]
a_index += 1
else:
break
while b_index != len(B):
if total + B[b_index] <= k:
total += B[b_index]
b_index += 1
else:
break
ans = a_index + b_index
a_index -= 1
while a_index != -1:
total -= A[a_index]
a_index -= 1
while b_index != len(B):
if total + B[b_index] <= k:
total += B[b_index]
b_index += 1
else:
break
if ans < a_index + 1 + b_index :
ans = a_index + 1 + b_index
print(ans)
if __name__ == '__main__':
main()
|
n,m,k=[int(i) for i in input().split()]
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
def make_sumlist(book_list):
sumnum=0
container=[0]
for i in book_list:
container.append(sumnum+i)
sumnum+=i
return container
total_a=make_sumlist(a)
total_b=make_sumlist(b)
# print(n,m,k)
# print(total_a)
# print(total_b)
#r個読めるか
def readable(r):
#全部読んでも無理
if r>n+m:
return False
if r==0:
return True
max_book=100000000000
for a_n in range(max(0,r-m),min(n,r)+1):
b_n=r-a_n
# print(a_n,b_n)
book_sum=total_a[a_n]+total_b[b_n]
# print(book_sum)
max_book=min(max_book,book_sum)
if max_book<=k:
return True
return False
def nibuntansaku(start,end):
if start==end:
return start
middle=(start+end)//2+1
if readable(middle):
start=middle
else:
end=middle-1
return nibuntansaku(start,end)
print(nibuntansaku(0,k))
| 1 | 10,806,268,642,580 | null | 117 | 117 |
print((lambda x:int(x[1])+max(0,100*(10-int(x[0]))))(input().split()))
|
import sys
prm = sys.stdin.readline()
prm = prm.split()
prm.sort()
a = int(prm[0])
b = int(prm[1])
c = int(prm[2])
print a, b, c
| 0 | null | 31,709,865,231,230 | 211 | 40 |
N,K=map(int,input().split())
A=list(map(int,input().split()))
point=[1]*N
for i in range(N-K):
if(A[K+i]>A[i]):
print("Yes")
else:
print("No")
|
n = int(input())
movies = {}
summize = 0
for i in range(n):
input_str = input().split()
summize += int(input_str[1])
movies.setdefault(input_str[0], summize)
title = input()
print(summize - movies[title])
| 0 | null | 51,769,964,335,508 | 102 | 243 |
MOD = 10 **9 + 7
INF = 10 ** 10
def main():
n,m,l = map(int,input().split())
dist = [[INF] * n for _ in range(n)]
for _ in range(m):
a,b,c = map(int,input().split())
a -= 1
b -= 1
dist[a][b] = c
dist[b][a] = c
for k in range(n):
for i in range(n):
for j in range(n):
dist[i][j] = min(dist[i][j],dist[i][k] + dist[k][j])
cnt = [[INF] * n for _ in range(n)]
for i in range(n):
for j in range(n):
if dist[i][j] <= l:
cnt[i][j] = 1
for k in range(n):
for i in range(n):
for j in range(n):
cnt[i][j] = min(cnt[i][j],cnt[i][k] + cnt[k][j])
q = int(input())
for _ in range(q):
s,t = map(int,input().split())
s -= 1
t -= 1
print(cnt[s][t] - 1 if cnt[s][t] != INF else -1)
if __name__ == '__main__':
main()
|
H, W, M = map(int, input().split())
h_list = [0] * H
w_list = [0] * W
target = []
for _ in range(M):
h, w = map(int, input().split())
h_list[h-1] += 1
w_list[w-1] += 1
target += [[h-1,w-1]]
h_max = max(h_list)
w_max = max(w_list)
h_max_list = set([i for i, v in enumerate(h_list) if v == h_max])
w_max_list = set([i for i, v in enumerate(w_list) if v == w_max])
place = len(h_max_list) * len(w_max_list)
candidate = 0
for h,w in target:
if (h in h_max_list) and (w in w_max_list):
candidate +=1
print(h_max+w_max-(place == candidate))
| 0 | null | 89,617,633,988,710 | 295 | 89 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.