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())
As = []
Bs = []
for _ in range(N):
c = 0
m = 0
for s in input():
if s == '(':
c += 1
elif s == ')':
c -= 1
m = min(m, c)
if c >= 0:
As.append((-m, c - m))
else:
Bs.append((-m, c - m))
As.sort(key=lambda x: x[0])
Bs.sort(key=lambda x: x[1], reverse=True)
f = True
c = 0
for (l, r) in As:
if c < l:
f = False
break
c += r - l
if f:
for (l, r) in Bs:
if c < l:
f = False
break
c += r - l
f = f and (c == 0)
if f:
print('Yes')
else:
print('No')
|
# AOJ ITP1_9_B
def main():
while True:
string = input()
if string == "-": break
n = int(input()) # シャッフル回数
for i in range(n):
h = int(input())
front = string[0 : h] # 0番からh-1番まで
back = string[h : len(string)] # h番からlen-1番まで
string = back + front
print(string)
if __name__ == "__main__":
main()
| 0 | null | 12,686,020,446,080 | 152 | 66 |
a = int(input())
ans = a >= 30 and 'Yes' or 'No'
print(ans)
|
def main():
X = int(input())
if X >=30: return "Yes"
return "No"
if __name__ == '__main__':
print(main())
| 1 | 5,790,418,075,630 | null | 95 | 95 |
X,N = map(int,input().split())
p = list(map(int, input().split()))
i = 0
if X not in p:
print(X)
else:
while True:
i += 1
if X - i not in p:
print(X-i)
break
if X+i not in p:
print(X+i)
break
|
x, n = map(int, input().split())
p = list(map(int, input().split()))
n = list(i for i in range(-1, 110) if i not in p)
diff = 110
ans = 0
for i in n:
if diff > abs(x-i):
diff = abs(x-i)
ans = i
print(ans)
| 1 | 14,011,404,554,378 | null | 128 | 128 |
seen = [0,0,0,0,0,0,0,0,0]
seen[0],seen[1],seen[2] = (map(int,input().split()))
seen[3],seen[4],seen[5] = (map(int,input().split()))
seen[6],seen[7],seen[8] = (map(int,input().split()))
over = False
N = int(input())
for x in range(N):
num = int(input())
if num in seen:
seen[seen.index(num)] = "O"
if seen[0] == "O":
if seen[1] == seen[2] == "O":
over = True
elif seen[3] == seen[6] == "O":
over = True
elif seen[4] == seen[8] == "O":
over = True
elif seen[4] == "O":
if seen[2] == seen[6] == "O":
over = True
elif seen[1] == seen[7] == "O":
over = True
elif seen[3] == seen[5] == "O":
over = True
elif seen[8] == "O":
if seen[6] == seen[7] == "O":
over = True
if seen[2] == seen[5] == "O":
over = True
if not over:
print("No")
else:
print("Yes")
|
import sys
input = sys.stdin.readline
N, K = map(int, input().split())
A = sorted(list(map(int, input().split())))
F = tuple(map(int, input().split()))
def can_eat(t):
F_time = sorted([t // f for f in F])
training = 0
for i in range(N):
training += max(0, A[i] - F_time[i])
return training <= K
# bisect
l, r = -1, 10 ** 12
while r - l > 1:
m = (r + l) // 2
if can_eat(m):
r = m
else:
l = m
print(r)
| 0 | null | 112,706,125,812,282 | 207 | 290 |
string = input()
for i in range(int(input())):
lst = list(map(str, input().split()))
if lst[0] == "replace":
string = string[:int(lst[1])] + lst[3] + string[int(lst[2])+1:]
if lst[0] == "reverse":
rev_str = str(string[int(lst[1]):int(lst[2])+1])
string = string[:int(lst[1])] + rev_str[::-1] + string[int(lst[2])+1:]
if lst[0] == "print":
print(string[int(lst[1]):int(lst[2])+1])
|
s = input()
q = int(input())
for i in range(q):
inp = input().split()
com = inp[0]
a = int(inp[1])
b = int(inp[2])+1
if com =="print":
print(s[a:b])
elif com =="reverse":
s_rev = s[a:b]
s = s[:a] + s_rev[::-1] + s[b:]
elif com =="replace":
s = s[:a] + inp[3] + s[b:]
| 1 | 2,084,258,108,898 | null | 68 | 68 |
N = int(input())
pos = []
for _ in range(N):
x, l = map(int,input().split())
pos.append((x+l, x-l))
pos.sort()
ans = 0
cur = float('-inf')
for i in range(N):
if cur <= pos[i][1]:
ans += 1
cur = pos[i][0]
print(ans)
|
n = int(input())
for i in range(3,n+1):
x = i
if x % 3 == 0:
print(' {0}'.format(i), end='')
continue
while x != 0:
if x % 10 == 3:
print(' {0}'.format(i),end='')
break
x //= 10
print()
| 0 | null | 45,264,422,335,020 | 237 | 52 |
numbers = raw_input()
input_numbers = raw_input().split()
print(" ".join(input_numbers[::-1]))
|
import sys
import math
from collections import defaultdict, deque
from copy import deepcopy
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 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 fib(num):
d = defaultdict(int)
d[0] = 1
d[1] = 1
if num <= 1:
return d[num]
else:
for i in range(1,num):
d[i+1] = d[i]+d[i-1]
return d[num]
def main():
num = I()
print(fib(num))
if __name__ == "__main__":
main()
| 0 | null | 501,447,685,148 | 53 | 7 |
while True:
cards=input()
if cards=="-":break
for i in range(int(input())):
h=int(input())
cards=cards[h:]+cards[:h]
print(cards)
|
while True:
st = list(raw_input())
if st[0] == '-':
break
m = int(raw_input())
for k in range(m):
h = int(raw_input())
st = st + st[:h]
del st[:h]
print ''.join(st)
| 1 | 1,881,833,766,550 | null | 66 | 66 |
def SelectionSort(A, N):
for i in range(N):
minj = i
for j in range(i, N):
if A[j][1:] < A[minj][1:]:
minj = j
#if i != minj:
#times += 1
A[i], A[minj] = A[minj], A[i]
#print(*A)
return A
def BubbleSort(A, N):
for i in range(N):
for j in reversed(range(i+1, N)):
if A[j][1:] < A[j-1][1:]:
A[j], A[j-1] = A[j-1], A[j]
return A
N= int(input())
A = [str(x) for x in input().split()]
B = [0 for i in range(N)]
for i in range(N):
B[i] = A[i]
bubble = BubbleSort(A, N)
selection = SelectionSort(B, N)
#print(A, B)
#print(*A)
print(*bubble)
print('Stable')
print(*selection)
if bubble == selection:
print('Stable')
else:
print('Not stable')
|
n=int(input())
A=[]
for i in range(n):
for _ in range(int(input())):
x,y=map(int,input().split())
A+=[(i,x-1,y)]
a=0
for i in range(2**n):
if all(i>>j&1<1 or i>>x&1==y for j,x,y in A):
a=max(a,sum(map(int,bin(i)[2:])))
print(a)
| 0 | null | 60,534,817,842,912 | 16 | 262 |
def print_frame(h,w):
if h == 1:
print("#"*w)
return
if h == 2:
print("#"*w)
print("#"*w)
return
print("#"*w)
for i in range(h-2):
print("#",end="")
for j in range(w-2):
print(".",end="")
print("#")
print("#"*w)
while True:
h,w = map(int,input().split())
if h == 0 and w == 0:
break;
else :
print_frame(h,w)
print()
|
print(sum(map(lambda x:int(x)*(int(x)-1)//2,input().split())))
| 0 | null | 23,189,229,403,960 | 50 | 189 |
print((int(input())+1)//2-1)
|
from numba import njit
import numpy as np
@njit("i8(i8,i8,i8[:])")
def f(n,ans,l):
for i in range(2,n+1):
for j in range(i,n+1,i):
l[j] += 1
ans += (l[i]*i)
return ans
n = int(input())
l = [1]*(n+1)
l[0] = 0
ans = l[1]
l_np = np.array(l,dtype="i8")
print(f(n,ans,l_np))
| 0 | null | 82,012,745,370,364 | 283 | 118 |
import sys
def insertionSort( nums, n, g ):
cnt = 0
i = g
while i < n:
v = nums[i]
j = i - g
while 0 <= j and v < nums[j]:
nums[ j+g ] = nums[j]
j -= g
cnt += 1
nums[ j+g ] = v
i += 1
return cnt
def shellSort( nums, n ):
g = []
val =0
for i in range( n ):
val = 3*val+1
if n < val:
break
g.append( val )
g.reverse( )
m = len( g )
print( m )
print( " ".join( map( str, g ) ) )
cnt = 0
for i in range( m ):
cnt += insertionSort( nums, n, g[i] )
print( cnt )
n = int( sys.stdin.readline( ) )
nums = []
for i in range( n ):
nums.append( int( sys.stdin.readline( ) ) )
cnt = 0
shellSort( nums, n )
print( "\n".join( map( str, nums ) ) )
|
class solve:
def __init__(self, n):
pass
def insertionsort(self, A, n, g):
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
self.cnt += 1
A[j + g] = v
def shellsort(self, A, n):
self.cnt = 0
self.G = [1]
f = 1
while f * 3 + 1 <= n:
f = f * 3 + 1
self.G.append(f)
self.G = list(reversed(self.G))
self.m = len(self.G)
for g in self.G:
self.insertionsort(A, n, g)
n, *A = map(int, open(0).read().split())
solver = solve(n)
solver.shellsort(A, n)
print(solver.m)
print(' '.join(map(str, solver.G)))
print(solver.cnt)
print('\n'.join(map(str, A)))
| 1 | 29,884,977,152 | null | 17 | 17 |
while True:
a = input()
b = a.split(' ')
b.sort(key=int)
if int(b[0]) == 0 and int(b[1]) == 0:
break
print('%s %s' % (b[0],b[1]))
|
n = int(input())
print(input().count("ABC"))
| 0 | null | 49,820,809,105,958 | 43 | 245 |
n = int(input())
ns = []
max_profit = -1000000000
min_value = 1000000000
for i in range(n):
num = int(input())
if i > 0:
max_profit = max(max_profit, num-min_value)
min_value = min(num, min_value)
print(max_profit)
|
def main():
N = input()
a = [input() for y in range(N)]
a_max = -10**9
a_min = a[0]
for j in xrange(1,len(a)):
if a[j] - a_min > a_max:
a_max = a[j] - a_min
if a[j] < a_min:
a_min = a[j]
print a_max
main()
| 1 | 13,466,285,180 | null | 13 | 13 |
N,M=map(int,input().split())
ans=0
if N>1:
ans += N*(N-1)//2
else:
pass
if M>1:
ans += M*(M-1)//2
else:
pass
print(ans)
|
a, b = map(int, input().split())
x = int(a*(a-1)/2)
y = int(b*(b-1)/2)
print(x+y)
| 1 | 45,419,416,990,794 | null | 189 | 189 |
input()
a = map(int, raw_input().split())
print min(a), max(a), sum(a)
|
import sys
import time
import math
import itertools as it
def inpl():
return list(map(int, input().split()))
st = time.perf_counter()
# ------------------------------
A, B, H, M = inpl()
h = 360 * H / 12 + 30 * M / 60
m = 360 * M / 60
sa = abs(h - m)
sa = min(sa, 360-sa)
print((A*A + B*B - 2*A*B*math.cos(sa*math.pi/180))**0.5)
# ------------------------------
ed = time.perf_counter()
print('time:', ed-st, file=sys.stderr)
| 0 | null | 10,389,039,706,002 | 48 | 144 |
N, S = int(input()), input()
print("Yes" if N%2 == 0 and S[:(N//2)] == S[(N//2):] else "No")
|
N = int(input())
S = input()
if N%2 == 1:
print("No")
else:
print("Yes") if S[:len(S)//2] == S[len(S)//2:] else print("No")
| 1 | 147,278,261,038,340 | null | 279 | 279 |
from collections import Counter
s = input()
n = len(s)
dp = [0]
mod = 2019
a = 0
for i in range(n):
a = a + int(s[n-i-1]) * pow(10, i, mod)
a %= mod
dp.append(a%mod)
ans = 0
c = Counter(dp)
for value in c.values():
ans += value * (value-1) / 2
print(int(ans))
|
import sys
input = sys.stdin.readline
K, X = map(int, input().split())
print('Yes' if X <= 500 * K else 'No')
| 0 | null | 64,424,046,316,674 | 166 | 244 |
N = int(input())
for i in range(N):
a,b,c = map(int,input().split())
if a*a + b*b == c*c or b*b+c*c == a*a or a*a+c*c == b*b:
print("YES")
else:
print("NO")
|
n = int(input())
s = ""
for i in range(n):
l = list(map(lambda x:x*x,map(int, input().split())))
l.sort()
if l[0] + l[1] == l[2]:
s += "YES\n"
else:
s += "NO\n"
print(s,end="")
| 1 | 351,207,102 | null | 4 | 4 |
class Human:
def __init__(self, name, card = "", point = 0):
self.name = name
self.card = card
self.point = point
def add_point(self, opponent):
if self.card > opponent:
self.point += 3
elif self.card == opponent:
self.point += 1
else:
pass
Taro = Human('Taro')
Hanako = Human('Hanako')
N = int(input())
for n in range(N):
Taro.card, Hanako.card = input().split()
Taro.add_point(Hanako.card)
Hanako.add_point(Taro.card)
print(Taro.point, Hanako.point)
|
n = int(input())
x, y = 0, 0
for _ in range(n):
info = input().split()
if info[0] > info[1]:
x += 3
elif info[0] < info[1]:
y += 3
else:
x += 1
y += 1
print(x, y)
| 1 | 1,996,513,052,992 | null | 67 | 67 |
import math
x = int(input())
y = x
while True:
flg = 0
for i in range(2,math.ceil(y**0.5)):
if y%i == 0:
flg = 1
break
if flg == 0:
print(y)
break
y += 1
|
X = int(input())
a = [-1] * 2 * X
a[0] = 0
a[1] = 1
for i in range(2, X):
if a[i] == -1:
for j in range(i, 2*X, i):
a[j] = i
for ans in range(X, 2*X):
if a[ans] == -1:
break
print(ans)
| 1 | 105,051,646,292,970 | null | 250 | 250 |
import sys
import time
import math
import itertools as it
def inpl():
return list(map(int, input().split()))
st = time.perf_counter()
# ------------------------------
N, M = inpl()
ac = [False] * (N+10)
wa = [0] * (N+10)
a = 0
w = 0
for _ in range(M):
p, S = input().split()
p = int(p)
if S == 'WA':
if not ac[p]:
wa[p] += 1
else:
if not ac[p]:
ac[p] = True
a += 1
w += wa[p]
print(a, w)
# ------------------------------
ed = time.perf_counter()
print('time:', ed-st, file=sys.stderr)
|
N,M=map(int, input().split())
a=[0]*(N+1)
w=[0]*(N+1)
for _ in range(M):
p,s=input().split()
p=int(p)
if s=='AC':
a[p]=1
else:
if a[p]==0:
w[p]+=1
a2=0
w2=0
for n in range(N+1):
if a[n]==1:
a2+=a[n]
w2+=w[n]
print(a2, w2)
| 1 | 93,409,998,785,450 | null | 240 | 240 |
n, k = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort(reverse=True)
l = -1
r = 10 ** 13
while r - l > 1:
m = (l + r) // 2
if sum([(a - m // f) if a * f > m else 0 for a, f in zip(A, F)]) <= k:
r = m
else:
l = m
print(r)
|
from collections import Counter
S = input()
S = S[::-1]
N = len(S)
counter = Counter()
counter[0] = 1
prev = 0
MOD = 2019
for i in range(N):
c = (int(S[i]) * pow(10, i, MOD) )%MOD
prev = (prev+c)%MOD
counter[prev] += 1
ans = 0
for k,v in counter.items():
ans += (v * (v-1))//2
print(ans)
| 0 | null | 97,854,631,405,718 | 290 | 166 |
A_int_list = list(map(int, input().split()))
if 22 <= sum(A_int_list):
print('bust')
else:
print('win')
|
K = int(input())
S = input()
l = list(S)
if len(l) <= K: print(S)
else:
ans = ''
for i in range(K):
ans += l[i]
ans += '...'
print(ans)
| 0 | null | 68,895,899,385,830 | 260 | 143 |
def main():
n = int(input())
ans = 0
for k in range(2,int(n**0.5)+1):
if n%k==0:
cnt,mx = 0,0
while n%k==0:
n = n//k
cnt += 1
if cnt > mx:
ans += 1
mx += 1
cnt = 0
if n!=1:
ans += 1
print(ans)
if __name__ == "__main__":
main()
|
from collections import deque
N, M = map(int, input().split())
route = [[] for i in range(N)]
for i in range(M):
a, b = map(int, input().split())
route[a - 1].append(b - 1)
route[b - 1].append(a - 1)
print('Yes')
q = deque()
d = [-1] * N
d[0] = 0
q.append(0)
while q:
x = q.popleft()
for i in route[x]:
if d[i] == -1:
d[i] = x + 1
q.append(i)
for i in range(1, N):
print(d[i])
| 0 | null | 18,738,868,688,068 | 136 | 145 |
#coding:UTF-8
while True:
a,op,b = map(str,raw_input().split())
a = int(a)
b = int(b)
if op == '+':
print(a+b)
elif op == '-':
print(a-b)
elif op == '*':
print(a*b)
elif op == '/':
print(a/b)
else:
break
|
class Dice(object):
def __init__(self, top, south, east, west, north, bottom):
self.top = top
self.south = south
self.east = east
self.west = west
self.north = north
self.bottom = bottom
def get_top(self):
return self.top
def rotate(self, directions):
for direction in directions:
if direction == 'S':
self.prev_top = self.top
self.top = self.north
self.north = self.bottom
self.bottom = self.south
self.south = self.prev_top
elif direction == 'E':
self.prev_top = self.top
self.top = self.west
self.west = self.bottom
self.bottom = self.east
self.east = self.prev_top
elif direction == 'W':
self.prev_top = self.top
self.top = self.east
self.east = self.bottom
self.bottom = self.west
self.west = self.prev_top
elif direction == 'N':
self.prev_top = self.top
self.top = self.south
self.south = self.bottom
self.bottom = self.north
self.north = self.prev_top
dice = Dice(*map(int, input().split()))
dice.rotate(input())
print(dice.get_top())
| 0 | null | 453,373,014,342 | 47 | 33 |
a, b = map(int, input().split())
for n in range(1500):
xa = int(n * 0.08)
xb = int(n * 0.1)
if a == xa and b == xb:
print(n)
exit()
print(-1)
|
N, K, S = map(int, input().split())
print(" ".join([str(S)] * K + [str(S+1)] * (N-K)) if S<10**9 else " ".join([str(S)] * K + ['1'] * (N-K)))
| 0 | null | 73,868,134,521,312 | 203 | 238 |
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())
a,b,c = MI()
if c < a+b:
print('No')
else:
print('Yes' if 4*a*b < (c-a-b)**2 else 'No')
|
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
def gcd(a, b):
while b:
a, b = b, a % b
return a
def lcm(a, b):
return a * b // gcd(a, b)
def main():
N, M = map(int, readline().split())
A = list(set(map(int, readline().split())))
B = A[::]
while not any(b % 2 for b in B):
B = [b // 2 for b in B]
if not all(b % 2 for b in B):
print(0)
return
semi_lcm = 1
for a in A:
semi_lcm = lcm(semi_lcm, a // 2)
if semi_lcm > M:
print(0)
return
print((M // semi_lcm + 1) // 2)
return
if __name__ == '__main__':
main()
| 0 | null | 76,756,903,812,098 | 197 | 247 |
s=input()
sss=list(s)
sss.reverse()
if sss[0]=="s":
print(s+"es")
else:
print(s+"s")
|
string = input('')
if string.endswith('s'):
print(string + 'es')
else:
print(string + 's')
| 1 | 2,379,962,922,026 | null | 71 | 71 |
f=lambda:[*map(int,input().split())]
k,n=f()
l=f()
l+=[l[0]+k]
a=0
for i in range(n):
a=max(a,l[i+1]-l[i])
print(k-a)
|
import sys
def gcd(a,b):
if(b):
return gcd(b,(a%b))
else:
return a
def lcm(a,b):
return a*b/gcd(a,b)
a = ""
for input in sys.stdin:
a += input
l = a.split()
for i in range(0,len(l),2):
if(int(l[i]) > int(l[i+1])):
print gcd(int(l[i]),int(l[i+1])),lcm(int(l[i]),int(l[i+1]))
else:
print gcd(int(l[i+1]),int(l[i])),lcm(int(l[i+1]),int(l[i]))
| 0 | null | 21,788,048,453,390 | 186 | 5 |
n=int(input())
s,t=input().split()
ans=str()
for i in range(n):
ans+=s[i]+t[i]
print(ans)
|
n=int(input())
s,t=input().split()
ans=''
for i in range(2*n):
ans=ans+(s[i//2] if i%2==0 else t[(i-1)//2])
print(ans)
| 1 | 112,346,231,141,508 | null | 255 | 255 |
def main():
N = int(input())
shougen = []
for _ in range(N):
A = int(input())
shougen.append([list(map(int, input().split())) for _ in range(A)])
ans = 0
for i in range(2**N):
state = [1]*N
for j in range(N):
if (i >> j) & 1:
state[j] = 0
flag = True
for k in range(N):
if not flag:
break
if state[k] == 1:
for ele in shougen[k]:
if state[ele[0]-1] != ele[1]:
flag = False
break
if flag:
ans = max(ans, sum(state))
print(ans)
if __name__ == '__main__':
main()
|
from sys import stdin
input = stdin.buffer.readline
a, b, c = map(int, input().split())
k = int(input())
cnt = 0
while b <= a:
cnt += 1
b *= 2
while c <= b:
cnt += 1
c *= 2
if cnt <= k:
print('Yes')
else:
print('No')
| 0 | null | 64,320,708,873,132 | 262 | 101 |
input_line = input()
a,b = input_line.strip().split(' ')
a = int(a)
b = int(b)
if a < b:
print("a < b")
elif a > b:
print("a > b")
elif a == b:
print("a == b")
|
import math
a,b=[int(i) for i in input().split()]
c=a//b
e=abs(a-(b*c))
f=abs(a-(b*(c+1)))
print(min(e,f))
| 0 | null | 19,829,618,125,972 | 38 | 180 |
while True:
s = raw_input()
if '-' == s:
break
m = input()
for a in range(m):
h = input()
s = s[h:len(s)]+s[:h]
print s
|
import sys
input = lambda: sys.stdin.readline().rstrip()
def solve():
A, B = map(int, input().split())
ans = max(0, A - 2 * B)
print(ans)
if __name__ == '__main__':
solve()
| 0 | null | 84,290,124,398,920 | 66 | 291 |
import math
class vec2d(object):
def __init__(self, x, y) -> None:
self.x = float(x)
self.y = float(y)
def rot(self, theta: float):
newx = self.x * math.cos(theta) - self.y * math.sin(theta)
newy = self.x * math.sin(theta) + self.y * math.cos(theta)
return vec2d(newx, newy)
def __str__(self):
return ' '.join(map(str, [self.x, self.y]))
def __format__(self, format_spec):
return ' '.join(map(lambda x: format(x, format_spec), [self.x, self.y]))
def __add__(self, other):
return vec2d(self.x + other.x, self.y + other.y)
def __sub__(self, other):
return vec2d(self.x - other.x, self.y - other.y)
def __mul__(self, k):
return vec2d(self.x * k, self.y * k)
def __truediv__(self, k):
return self.__mul__(1 / k)
def prod(self, other):
return self.x * other.x + self.y * other.y
def cochcurve(p1, p2, n):
if n > 0:
pd = (p2 - p1) / 3
ps = p1 + pd
pu = ps + pd.rot(math.pi / 3)
pt = ps + pd
cochcurve(p1, ps, n-1)
print(f'{ps:>12.6f}')
cochcurve(ps, pu, n-1)
print(f'{pu:>12.6f}')
cochcurve(pu, pt, n-1)
print(f'{pt:>12.6f}')
cochcurve(pt, p2, n-1)
n = int(input())
S = vec2d(0, 0)
T = vec2d(100, 0)
print(f'{S:>12.6f}')
cochcurve(S, T, n)
print(f'{T:>12.6f}')
|
import math
a,b,c,d = map(int,input().split())
def death_time(hp,atack):
if hp%atack == 0:
return hp/atack
else:
return hp//atack + 1
takahashi_death = death_time(a,d)
aoki_death = death_time(c,b)
if aoki_death<=takahashi_death:
print("Yes")
else:
print("No")
| 0 | null | 15,047,725,075,630 | 27 | 164 |
s = input()
p = input()
flg = False
for i in range(len(s)):
s = s[1:] + s[:1]
if p in s:
flg = True
break
if flg:
print('Yes')
else:
print('No')
|
import math
a,b,c=map(float,input().split())
h=b*math.sin(c/180.0*math.pi)
ad=a-b*math.cos(c/180.0*math.pi)
d=(h*h+ad*ad)**0.5
l = a + b + d
s = a * h / 2.0
print('{0:.6f}'.format(s))
print('{0:.6f}'.format(l))
print('{0:.6f}'.format(h))
| 0 | null | 947,118,516,252 | 64 | 30 |
import sys
#input = sys.stdin.buffer.readline
#sys.setrecursionlimit(10**9)
#from functools import lru_cache
def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode('utf-8')
class BinaryIndexedTree:
def __init__(self,n,default=0):
self.s=[default]*(n+1)
self.n=n
def add(self,val,idx):
while idx<self.n+1:
self.s[idx]=self.s[idx]+val
idx+=idx&(-idx)
return
def get(self,idx):
res=0
while idx>0:
res=res+self.s[idx]
idx-=idx&(-idx)
return res
from collections import defaultdict
def main():
n=II()
s=input()
S=[0]+list(s)
d=defaultdict(lambda:BinaryIndexedTree(n))
for i,si in enumerate(s):
#print(i,si)
d[si].add(1,i+1)
q=II()
for _ in range(q):
f,a,b=input().split()
if int(f)==1:
a=int(a)
d[S[a]].add(-1,a)
d[b].add(1,a)
S[a]=b
else:
#print(S,a,b)
a=int(a)
b=int(b)
cnt=0
for bit in d.values():
if bit.get(b)-bit.get(a-1)>0:
cnt+=1
print(cnt)
if __name__=="__main__":
main()
|
def main():
import bisect
n = int(input())
s = list(input())
q = int(input())
d = {}
for i in range(26):
d[chr(ord('a')+i)] = []
for i in range(n):
d[s[i]].append(i)
#print(d)
for i in range(q):
t,a,b = input().split()
if t == '1':
a = int(a)-1
if s[a] == b:
continue
#idx = bisect.bisect_left(d[s[a]],a)
#d[s[a]].pop(idx)
d[s[a]].remove(a)
bisect.insort_left(d[b],a)
s[a] = b
else:
a = int(a)-1
b = int(b)-1
c = 0
for i in range(26):
idx = bisect.bisect_left(d[chr(ord('a')+i)],a)
if idx < len(d[chr(ord('a')+i)]) and d[chr(ord('a')+i)][idx] <= b:
c += 1
print(c)
main()
| 1 | 62,651,926,314,208 | null | 210 | 210 |
from itertools import combinations
n = int(input())
d = list(map(int, input().split()))
ans = 0
sum = sum(d)
for i in d:
sum -= i
ans += i*sum
print(ans)
|
n = int(input())
x = list(input())
sx = len(set(x))
if sx == 1:
print(0)
exit()
cnt_r = x.count("R")
cnt = 0
for i in range(cnt_r):
if x[i] == "W":
cnt += 1
print(cnt)
| 0 | null | 87,358,718,967,630 | 292 | 98 |
a, b, c = list(map(int, input().split()))
if a < b and b < c:
print("Yes")
else:
print("No")
|
if __name__ == "__main__":
a, b, c = map( int, input().split() )
if a < b < c:
print("Yes")
else:
print("No")
| 1 | 378,351,785,562 | null | 39 | 39 |
n = int(input())
count_taro = 0
count_hanako = 0
for i in range(n):
taro,hanako = map(str, input().split())
if taro > hanako:
count_taro += 3
if hanako > taro:
count_hanako += 3
if hanako == taro:
count_hanako += 1
count_taro += 1
print(count_taro, count_hanako)
|
N=int(input())
right=0
left=0
for i in range(N):
a,b=input().split()
if a>b:
left+=3
elif a<b:
right+=3
else:
left+=1
right+=1
print(f"{left} {right}")
| 1 | 1,994,316,357,878 | null | 67 | 67 |
import sys
sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7
class BIT:
def __init__(self, L):
self.n = len(L)
self.bit = [0] * (self.n + 1)
def update(self, idx, x):
while idx <= self.n:
self.bit[idx] += x
idx += idx & (-idx)
def query(self, idx):
res = 0
while idx > 0:
res += self.bit[idx]
idx -= idx & (-idx)
return res
def sec_sum(self, left, right):
return self.query(right) - self.query(left - 1)
def debug(self):
print(*[self.sec_sum(i, i) for i in range(1, self.n + 1)])
def resolve():
n = int(input())
S = list(input().rstrip())
q = int(input())
bits = [BIT(S) for _ in range(26)]
for idx in range(1, n + 1):
s = S[idx - 1]
bits[ord(s) - ord("a")].update(idx, 1)
for _ in range(q):
query = list(input().split())
if query[0] == "1":
i, c = int(query[1]), query[2]
prev = S[i - 1]
bits[ord(prev) - ord("a")].update(i, -1)
bits[ord(c) - ord("a")].update(i, 1)
S[i - 1] = c
else:
l, r = int(query[1]), int(query[2])
res = 0
for j in range(26):
if bits[j].sec_sum(l, r):
res += 1
print(res)
if __name__ == '__main__':
resolve()
|
def gcd(a, b):
if b == 0:
return a
else:
return gcd(b,a%b)
a,b = map(int, input().split())
print(a*b//gcd(a,b))
| 0 | null | 87,830,499,060,108 | 210 | 256 |
l = [x+' '+y for x in['S','H','C','D']for y in[str(i+1)for i in range(13)]]
for n in range(int(input())):
l.remove(input())
for i in l:
print(i)
|
n = int(raw_input())
C = {'S':range(13), 'H':range(13), 'C':range(13), 'D':range(13)}
for i in range(n):
suit, num = raw_input().split()
num = int(num)
C[suit][num-1] = 14
for i in ['S', 'H', 'C', 'D']:
for j in range(13):
if C[i][j] != 14:
print "%s %d" %(i, j+1)
| 1 | 1,043,527,836,168 | null | 54 | 54 |
import sys
readline = sys.stdin.buffer.readline
h1, m1, h2, m2, k = map(int, readline().split())
print(60 * (h2 - h1) + m2 - m1 - k)
|
import sys
dic = {}
for i in range(ord('a'), ord('z') + 1):
dic[chr(i)] = 0
for line in sys.stdin:
for i in range(len(line)):
char = line[i].lower()
if char in dic.keys():dic[char] += 1
for i in range(ord('a'), ord('z') + 1):
print("{} : {}".format(chr(i), dic[chr(i)]))
| 0 | null | 9,783,832,894,980 | 139 | 63 |
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1
K=int(input())
S=len(input())
def COMinit(n,MOD):
fac,finv,inv=[0]*max(2,n+1),[0]*max(2,n+1),[0]*max(2,n+1)
fac[0]=fac[1]=1
finv[0]=finv[1]=1
inv[1]=1
for i in range(2,(n+1)):
fac[i]=fac[i-1]*i%MOD
inv[i]=MOD-inv[MOD%i]*(MOD//i)%MOD
finv[i]=finv[i-1]*inv[i]%MOD
return fac,finv,inv
fac,finv,inv=COMinit(K+S,MOD)
def COM(n, k, MOD=MOD):
if n<k or n<0 or k<0:
return 0
return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD
ans=0
for i in range(K+1):
ans+=pow(26,i,MOD)*pow(25,K-i,MOD)*COM(K+S-i-1,S-1)
ans%=MOD
print(ans)
|
k = int(input())
s = input()
n = len(s)
MOD = 10**9+7
ans = 0
def comb(n, r, MOD):
if (r < 0) or (n < r):
return 0
r = min(r, n - r)
return fact[n] * factinv[r] * factinv[n-r] % MOD
N = 2 * (10 ** 6) + 100
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]
for i in range(2, N + 1):
fact.append((fact[-1] * i) % MOD)
inv.append((-inv[MOD % i] * (MOD // i)) % MOD)
factinv.append((factinv[-1] * inv[-1]) % MOD)
for i in range(k+1):
b = pow(26, k-i, MOD)
b *= pow(25, i, MOD)
b *= comb(i+n-1, n-1, MOD)
ans += (b % MOD)
print(ans%MOD)
| 1 | 12,841,813,351,902 | null | 124 | 124 |
x, y, a, b, c = map(int, input().split())
red = list(map(int, input().split()))
green = list(map(int, input().split()))
colorless = list(map(int, input().split()))
red.sort(reverse = True)
green.sort(reverse = True)
colorless.sort(reverse = True)
ret = red[:x] + green[:y]
ret.sort()
for i in range(len(colorless)):
if ret[i] < colorless[i]:
ret[i] = colorless[i]
else:
break
print(sum(ret))
|
N = int(input())
a_list = list(map(int, input().split()))
MOD = 10**9 + 7
cnts = [0,0,0]
sames = 0
ind = -1
res = 1
for a in a_list:
for i, cnt in enumerate(cnts):
if cnt == a:
sames += 1
ind = i
res *= sames
res %= MOD
cnts[ind] += 1
sames = 0
print(res)
| 0 | null | 87,600,384,574,432 | 188 | 268 |
n,m = input().split()
print(((int(n) * (int(n) - 1)) + (int(m) * (int(m) - 1))) // 2)
|
[N, M] = [int(i) for i in input().split()]
print(int(N*max(N-1, 0)/2) + int(M*max(M-1, 0)/2))
| 1 | 45,340,005,963,072 | null | 189 | 189 |
import sys
import itertools
input = sys.stdin.readline
def SI(): return str(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def main():
H, W, K = MI()
grid = [SI().rstrip('\n') for _ in range(H)]
n = H + W
ans = 0
for i in itertools.product(range(2),repeat = H):
for j in itertools.product(range(2),repeat = W):
count = 0
for k in range(H):
if i[k] == 1:
continue
for l in range(W):
if j[l] == 1:
continue
if grid[k][l] == "#":
count += 1
if count == K:
ans +=1
print(ans)
main()
|
from itertools import product
h, w, k = map(int, input().split())
c = [input() for i in range(h)]
ans = 0
for maskR in product([0,1], repeat=h):
for maskC in product([0,1], repeat=w):
b = 0
for i in range(h):
for j in range(w):
if maskR[i] == 1 and maskC[j] == 1 and c[i][j] == '#':
b += 1
if b ==k:
ans += 1
print(ans)
| 1 | 8,990,799,876,592 | null | 110 | 110 |
import sys
sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7
def resolve():
n = int(input())
X = input()
cnt_init = X.count("1")
x_init = int(X, 2)
a = x_init % (cnt_init + 1)
if cnt_init - 1 != 0:
b = x_init % (cnt_init - 1)
for i in range(n):
if X[i] == "0":
cnt = cnt_init + 1
x = (a + pow(2, (n - i - 1), cnt)) % cnt
res = 1
else:
cnt = cnt_init - 1
if cnt != 0:
x = (b - pow(2, (n - i - 1), cnt)) % cnt
res = 1
else:
x = 0
res = 0
while x:
cnt = bin(x).count("1")
x %= cnt
res += 1
print(res)
if __name__ == '__main__':
resolve()
|
l = []
for i in range(int(input())): l.append(input())
print(len(set(l)))
| 0 | null | 19,240,904,109,500 | 107 | 165 |
import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])
n = inp()
ans = 0
n_ketasuu = len(str(n))
sta_max = int(str(n)[0])
end_max = int(str(n)[n_ketasuu-1])
for i in range(1,n+1):
sta = int(str(i)[len(str(i))-1])
end = int(str(i)[0])
if sta == 0:
continue
#1桁
if sta == end:
ans +=1
#2桁
if n_ketasuu >= 2 and sta*10 + end <= n:
ans += 1
#3桁
if n_ketasuu > 3 or (n_ketasuu == 3 and sta < sta_max):
ans += 10
elif n_ketasuu == 3 and sta == sta_max:
ans += int(str(n)[1:n_ketasuu-1])
if end <= end_max:
ans += 1
#4桁
if n_ketasuu > 4 or (n_ketasuu == 4 and sta < sta_max):
ans += 100
elif n_ketasuu == 4 and sta == sta_max:
ans += int(str(n)[1:n_ketasuu-1])
if end <= end_max:
ans += 1
#5桁
if n_ketasuu > 5 or (n_ketasuu == 5 and sta < sta_max):
ans += 1000
elif n_ketasuu == 5 and sta == sta_max:
ans += int(str(n)[1:n_ketasuu-1])
if end <= end_max:
ans += 1
#6桁
if n_ketasuu > 6 or (n_ketasuu == 6 and sta < sta_max):
ans += 10000
elif n_ketasuu == 6 and sta == sta_max:
ans += int(str(n)[1:n_ketasuu-1])
if end <= end_max:
ans += 1
print(ans)
|
N=int(input())
import copy
raw=[0]*10
a=[]
for i in range(10):
a.append(copy.deepcopy(raw))
ans=0
#print(a)
for i in range(1,N+1):
temp=str(i)
#print(temp)
a[int(temp[0])][int(temp[-1])]+=1
#print(a)
for i in range(10):
for j in range(10):
ans+=a[i][j]*a[j][i]
print(ans)
| 1 | 86,872,060,832,128 | null | 234 | 234 |
n, a, b = map(int, input().split())
ans = pow(2,n,10**9+7)-1
A = 1
for i in range(1,a+1):
A = (A*(n-i+1))%(10**9+7)
x = pow(i,10**9+5,10**9+7)
A *= x
B = 1
for i in range(1,b+1):
B = (B*(n-i+1))%(10**9+7)
y = pow(i,10**9+5,10**9+7)
B *= y
ans = ans-A-B
if ans < 0:
ans = ans+10**9+7
ans = int(ans%(10**9+7))
print(ans)
|
N = int(input())
for i in range(10):
for j in range(10):
if i * j == N:
print("Yes")
exit(0)
else:
print("No")
| 0 | null | 112,643,469,466,190 | 214 | 287 |
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()
|
x = int(input())
print((x//500)*1000+((x-500*(x//500))//5)*5)
| 1 | 42,553,924,233,920 | null | 185 | 185 |
# 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
|
S=input()
T=input()
N=len(S)
c=0
for i in range(N):
if S[i]!=T[i]:
c=c+1
print(c)
| 0 | null | 5,521,937,258,250 | 42 | 116 |
#!/usr/bin/env python3
import collections as cl
import sys
def II():
return int(sys.stdin.readline())
def MI():
return map(int, sys.stdin.readline().split())
def LI():
return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
def main():
N = II()
targets = LI()
colors = [0] * 3
ans = 1
for i in range(N):
count = 0
for k in range(3):
if colors[k] == targets[i]:
if count == 0:
colors[k] += 1
count += 1
ans *= count
ans %= MOD
print(ans)
main()
|
s,t=input().split()
x=t+s
print(x)
| 0 | null | 116,398,166,666,980 | 268 | 248 |
N = int(input())
say = {}
for i in range(N):
say[i] = []
A = int(input())
for j in range(A):
x, y = map(int, input().split())
x -= 1
say[i].append((x, y))
ans = 0
for i in range(1 << N):
ok = True
Honecount = 0
for j in range(N):
if((i >> j) & 1 == 0):
continue
Honecount += 1
for k in say[j]:
if ((i >> k[0]) & 1) != k[1]:
ok = False
break
if ok == False:
break
if ok == True:
ans = max(ans, Honecount)
print(ans)
|
i = 1
a = []
while True:
x = input()
if x == 0:
break
a.append(x)
for i in range(len(a)):
print 'Case ' + str(i+1) + ': ' + str(a[i])
| 0 | null | 60,775,369,860,652 | 262 | 42 |
N=int(input())
if N%2==1:
print(int((N-1)/2+1))
else:
print(int(N/2))
|
import sys
input = sys.stdin.readline
def main():
N = int(input())
print(N//2+1) if N % 2 else print(N//2)
if __name__ == '__main__':
main()
| 1 | 59,016,747,340,782 | null | 206 | 206 |
def resolve():
N = int(input())
ans = 0
for i in range(1, N+1):
n = N//i
ans += (n*(n+1)*i)//2
print(ans)
if '__main__' == __name__:
resolve()
|
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7
n = int(readline())
# O(N)解法
ans = 0
for i in range(1,n+1):
a = n//i
ans += a*(a+1)*i//2
print(ans)
| 1 | 10,930,530,999,612 | null | 118 | 118 |
n, q = list(map(int, input().split()))
que = []
for _ in range(n):
name, time = input().split()
que.append([name, int(time)])
elapsed_time = 0
while que:
name, time = que.pop(0)
dt = min(q, time)
time -= dt
elapsed_time += dt
if time > 0:
que.append([name, time])
else:
print (name, elapsed_time)
|
#coding: utf-8
import math
a, b, C = (float(i) for i in input().split())
C = math.pi * C / 180
S = a * b * math.sin(C) / 2
h = b * math.sin(C)
L = a + b + math.sqrt(a**2 + b ** 2 - 2 * a * b * math.cos(C))
print("{:.8f}".format(S))
print("{:.8f}".format(L))
print("{:.8f}".format(h))
| 0 | null | 107,608,339,488 | 19 | 30 |
import sys
input()
numbers = map(int, input().split())
evens = [number for number in numbers if number % 2 == 0]
if len(evens) == 0:
print('APPROVED')
sys.exit()
for even in evens:
if even % 3 != 0 and even % 5 != 0:
print('DENIED')
sys.exit()
print('APPROVED')
|
a,b,k=map(int,input().split())
if a>=k:
print(a-k,b)
else:
print(0,max(b+a-k,0))
| 0 | null | 86,639,133,604,240 | 217 | 249 |
print(['No','Yes'][int(input())>=30])
|
X = int(input())
if X >= 30:
print('Yes')
else:
print('No')
| 1 | 5,749,113,693,030 | null | 95 | 95 |
# 数値の取得
holi,hw = map(int,input().split())
hw_day = list(map(int,input().split()))
# 判定結果を出力
hw_sum = sum(hw_day)
if hw_sum <= holi:
print(holi - hw_sum)
else:
print("-1")
|
def main():
N, M = map(int, input().split())
A = list(map(int, input().split()))
if sum(A) > N:
print(-1)
else:
print(N - sum(A))
if __name__ == '__main__':
main()
| 1 | 31,872,903,180,580 | null | 168 | 168 |
import sys
input = lambda: sys.stdin.readline().rstrip()
class SegTree:
def __init__(self, init_val, segfunc, ide_ele):
n = len(init_val)
self.ide_ele = ide_ele
self.segfunc = segfunc
self.num = 2**(n - 1).bit_length()
self.seg = [self.ide_ele] * 2 * self.num
for i in range(n):
self.seg[i + self.num - 1] = init_val[i]
for i in range(self.num - 2, -1, -1):
self.seg[i] = self.segfunc(self.seg[2 * i + 1], self.seg[2 * i + 2])
def update(self, k, x):
k += self.num - 1
self.seg[k] = x
while k:
k = (k - 1) // 2
self.seg[k] = self.segfunc(self.seg[k * 2 + 1], self.seg[k * 2 + 2])
def query(self, p, q):
if q <= p:
return self.ide_ele
p += self.num - 1
q += self.num - 2
res = self.ide_ele
while q - p > 1:
if p & 1 == 0:
res = self.segfunc(res, self.seg[p])
if q & 1 == 1:
res = self.segfunc(res, self.seg[q])
q -= 1
p = p // 2
q = (q - 1) // 2
if p == q:
res = self.segfunc(res, self.seg[p])
else:
res = self.segfunc(self.segfunc(res, self.seg[p]), self.seg[q])
return res
def solve():
N = int(input())
S = list(input())
Q = int(input())
seg = [[0 for _ in range(N)] for _ in range(26)]
for i in range(N):
al = ord(S[i]) - ord('a')
seg[al][i] = 1
segtree = []
segfunc = lambda a, b: a | b
for i in range(26):
segtree.append(SegTree(seg[i], segfunc, 0))
ans = []
for i in range(Q):
a, b, c = input().split()
a = int(a)
if a == 1:
b = int(b) - 1
ps = S[b]
S[b] = c
segtree[ord(ps) - ord('a')].update(b, 0)
segtree[ord(c) - ord('a')].update(b, 1)
elif a == 2:
b, c = int(b) - 1, int(c)
count = 0
for i in range(26):
count += segtree[i].query(b, c)
ans.append(count)
print('\n'.join(map(str, ans)))
if __name__ == '__main__':
solve()
|
import random
import time
import copy
def down_score(d, c, last_d, score):
sum = 0
for i in range(26):
sum = sum + c[i]*(d-last_d[i])
return int(score - sum)
def main():
D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for i in range(D)]
start = time.time()
last_d = [0 for i in range(26)]
ans = []
score1 = 0
for i in range(D):
max = 0
idx = 0
for j in range(26):
if max < (s[i][j] + c[j] * (i-last_d[j])*(i-last_d[j]+1)/2) and c[j] != 0:
max = s[i][j] + c[j] * (i-last_d[j])*(i-last_d[j]+1)/2
idx = j
elif max == (s[i][j] + c[j] * (i-last_d[j])*(i-last_d[j]+1)/2) and c[j] * (i-last_d[j])*(i-last_d[j]+1)/2 > c[idx]* (i-last_d[idx])*(i-last_d[idx]+1)/2 and c[j] != 0:
idx = j
last_d[idx] = i+1
score1 += s[i][idx]
score1 = down_score(i+1,c,last_d,score1)
ans.append(idx)
while time.time() - start < 1.9:
cp = ans.copy()
last_d = [0 for i in range(26)]
score2 = 0
idx1 = random.randint(0,25)
idx2 = random.randint(0,25)
idx3 = random.randint(0,25)
if random.randint(0,1):
d1 = random.randint(0,D-1)
d2 = random.randint(0,D-1)
d3 = random.randint(0,D-1)
if idx1 == idx2 or idx1 == idx3 or idx2 == idx3:
continue
if random.randint(0,1):
ans[d1] = idx1
elif random.randint(0,1):
ans[d1] = idx1
ans[d2] = idx2
else:
ans[d1] = idx1
ans[d2] = idx2
ans[d3] = idx3
#2値入れ替え
elif random.randint(0,1):
d1 = random.randint(0,D-8)
d2 = random.randint(d1+1,d1+7)
tmp1 = ans[d1]
tmp2 = ans[d2]
if random.randint(0,1):
ans[d1] = tmp2
ans[d2] = tmp1
#3値入れ替え
else:
d1 = random.randint(0,D-11)
d2 = random.randint(d1+1,d1+5)
d3 = random.randint(d2+1,d2+5)
tmp1 = ans[d1]
tmp2 = ans[d2]
tmp3 = ans[d3]
if random.randint(0,1):
ans[d1] = tmp2
ans[d2] = tmp3
ans[d3] = tmp1
else:
ans[d1] = tmp3
ans[d2] = tmp1
ans[d3] = tmp2
for i in range(D):
score2 += s[i][ans[i]]
last_d[ans[i]] = i+1
score2 = down_score(i+1, c, last_d, score2)
if score1 > score2:
ans = cp.copy()
else:
score1 = score2
for i in range(D):
print(ans[i]+1)
if __name__ == "__main__":
main()
| 0 | null | 35,947,965,509,912 | 210 | 113 |
n=int(input())
s,t=input().split()
a=str()
for i in range(n):
a=a+s[i]+t[i]
print(a)
|
x = input()
for i in xrange(x):
inp = map(int ,raw_input().split())
inp.sort()
if inp[2]**2 == inp[0]**2 + inp[1]**2:
print "YES"
else:
print "NO"
| 0 | null | 55,712,501,493,422 | 255 | 4 |
def f(d, D):
i = 0
while i < 6:
if d == D[i]:
return i
else:
i += 1
Q0 = [1,2,4,3,1]
Q1 = [0,3,5,2,0]
Q2 = [0,1,5,4,0]
ans = ''
D = list(map(int, input().split(' ')))
n = int(input())
i = 0
while i < n:
d0, d1 = map(int, input().split(' '))
L0 = f(d0, D)
L1 = f(d1, D)
if L0 == 0:
q = 0
while q < 4:
if L1 == Q0[q]:
ans += str(D[Q0[q + 1]]) + '\n'
break
q += 1
elif L0 == 1:
q = 0
while q < 4:
if L1 == Q1[q]:
ans += str(D[Q1[q + 1]]) + '\n'
break
q += 1
elif L0 == 2:
q = 0
while q < 4:
if L1 == Q2[q]:
ans += str(D[Q2[q + 1]]) + '\n'
break
q += 1
elif L0 == 3:
q = 0
while q < 4:
if L1 == Q2[4-q]:
ans += str(D[Q2[4-q-1]]) + '\n'
break
q += 1
elif L0 == 4:
q = 0
while q < 4:
if L1 == Q1[4-q]:
ans += str(D[Q1[4-q-1]]) + '\n'
break
q += 1
elif L0 == 5:
q = 0
while q < 4:
if L1 == Q0[4-q]:
ans += str(D[Q0[4-q-1]]) + '\n'
break
q += 1
i += 1
if ans != '':
print(ans[:-1])
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
POSITIONS = ["top", "south", "east", "west", "north", "bottom"]
class Dice(object):
def __init__(self, initial_faces):
self.faces = {p: initial_faces[i] for i, p in enumerate(POSITIONS)}
self.store_previous_faces()
def store_previous_faces(self):
self.previous_faces = self.faces.copy()
def change_face(self, after, before):
self.faces[after] = self.previous_faces[before]
def change_faces(self, rotation):
self.change_face(rotation[0], rotation[1])
self.change_face(rotation[1], rotation[2])
self.change_face(rotation[2], rotation[3])
self.change_face(rotation[3], rotation[0])
def roll(self, direction):
self.store_previous_faces()
if direction == "E":
self.change_faces(["top", "west", "bottom", "east"])
elif direction == "N":
self.change_faces(["top", "south", "bottom", "north"])
elif direction == "S":
self.change_faces(["top", "north", "bottom", "south"])
elif direction == "W":
self.change_faces(["top", "east", "bottom", "west"])
def rolls(self, directions):
for d in directions:
self.roll(d)
def main():
dice = Dice(input().split())
q = int(input())
for x in range(q):
[qtop, qsouth] = input().split()
if qsouth == dice.faces["west"]:
dice.roll("E")
elif qsouth == dice.faces["east"]:
dice.roll("W")
while qsouth != dice.faces["south"]:
dice.roll("N")
while qtop != dice.faces["top"]:
dice.roll("W")
print(dice.faces["east"])
if __name__ == "__main__":
main()
| 1 | 264,834,227,868 | null | 34 | 34 |
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 ) )
|
a, b, c = list(map(int, input().split()))
ans = 0
for i in range(a, b+1):
if i == 1 or c % i == 0:
ans += 1
print(ans)
| 1 | 558,843,072,800 | null | 44 | 44 |
from time import *
from random import *
t=time()
T0,T1=2000,600
Tt=2000
D=int(input())
C=list(map(int,input().split()))
S=[list(map(int,input().split())) for i in range(D)]
X=[0]*26
XX=[0]*26
P=[]
for i in range(D):
for j in range(26):
X[j]+=C[j]
XX[j]+=X[j]
P.append([])
for j in range(26):
P[i].append(j)
P[i].sort(reverse=True,key=lambda x:X[x]+S[i][x])
XX[P[i][0]]-=X[P[i][0]]
X[P[i][0]]=0
SC,SC2=0,0
for i in range(D):
SC+=S[i][P[i][0]]
YY=[]
Y=[]
A,B=0,0
e=0
E=1
for i in range(50):
e+=E
E*=1/(i+1)
def f(x):
global e,Tt
if x>=0:
return True
else:
return randrange(0,10000000)<=pow(e,x/Tt)
for l in range(12):
for k in range(25):
for i in range(D):
SC2=SC
YY=XX[:]
Y=X[:]
SC2-=S[i][P[i][0]]
SC2+=S[i][P[i][k+1]]
for j in range(26):
Y[j]=0
YY[P[i][0]],YY[P[i][k+1]]=0,0
for j in range(D):
if j==i:
Z=P[j][k+1]
else:
Z=P[j][0]
Y[P[i][0]]+=C[P[i][0]]
Y[P[i][k+1]]+=C[P[i][k+1]]
Y[Z]=0
YY[P[i][0]]+=Y[P[i][0]]
YY[P[i][k+1]]+=Y[P[i][k+1]]
if f((SC2-sum(YY))-(SC-sum(XX))):
P[i].insert(0,P[i][k+1])
del P[i][k+2]
XX=YY[:]
SC=SC2
for i in range(D-1):
SC2=SC
YY=XX[:]
Y=X[:]
A=i
B=randrange(A+1,D)
SC2-=S[A][P[A][0]]+S[B][P[B][0]]
SC2+=S[A][P[B][0]]+S[B][P[A][0]]
for j in range(26):
Y[j]=0
YY[P[A][0]],YY[P[B][0]]=0,0
for j in range(D):
if j==A:
Z=P[B][0]
elif j==B:
Z=P[A][0]
else:
Z=P[j][0]
Y[P[A][0]]+=C[P[A][0]]
Y[P[B][0]]+=C[P[B][0]]
Y[Z]=0
YY[P[A][0]]+=Y[P[A][0]]
YY[P[B][0]]+=Y[P[B][0]]
if f((SC2-sum(YY))-(SC-sum(XX))):
P[A],P[B]=P[B][:],P[A][:]
XX=YY[:]
SC=SC2
Tt=pow(T0,1-(time()-t))*pow(T1,time()-t)
for i in range(D):
print(P[i][0]+1)
|
#昔はtleの回答、今は通る?
import sys
input=sys.stdin.readline
n=int(input())
lists=list(map(int,input().split()))
aa=[0 for i in range(n)]
bb=[0 for i in range(n)]
length=61
use=[0 for i in range(61)]
for j in range(n):
k=format(lists[j],"0%ib"%length)
k=k[::-1]
aa[j]=k[:30]
bb[j]=k[30:]
for p in aa:
for some in range(30):
use[some]+=int(p[some])
for q in bb:
for some in range(31):
use[some+30]+=int(q[some])
answer=0
for j in range(61):
answer+=(2**j)*use[j]*(n-use[j])%(10**9+7)
print(answer%(10**9+7))
| 0 | null | 66,415,672,918,560 | 113 | 263 |
#
import sys
input=sys.stdin.readline
def main():
K=int(input())
lunlun=[1,2,3,4,5,6,7,8,9]
ind=0
lll=9
for dig in range(12):
l=lll
for i in lunlun[ind:]:
s=str(i)
x=int(s[dig])
if 0<=x-1<=9:
lunlun+=[int(s+str(x-1))]
lll+=1
if 0<=x<=9:
lunlun+=[int(s+str(x))]
lll+=1
if 0<=x+1<=9:
lunlun+=[int(s+str(x+1))]
lll+=1
if lll>K:
break
ind=l
lunlun.sort()
print(lunlun[K-1])
if __name__=="__main__":
main()
|
n, x, m = map(int, input().split())
flag = [False]*m
a = []
while not flag[x]:
flag[x] = True
a.append(x)
x = pow(x, 2, m)
loop_start_idx = a.index(x)
loop_len = len(a) - loop_start_idx
loop_count = (n - loop_start_idx)//loop_len
loop_amari = (n-loop_start_idx)%loop_len
ans = sum(a[:loop_start_idx])
ans += sum(a[loop_start_idx:])*loop_count
ans += sum(a[loop_start_idx: loop_start_idx + loop_amari])
print(ans)
| 0 | null | 21,296,048,634,268 | 181 | 75 |
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")
n = int(input())
ans = float("inf")
for i in range(1, n+1):
if n%i==0:
ans = min(ans, i+n//i)
if i*i>n:
break
print(ans-2)
|
import sys
input = sys.stdin.readline
mm = 10**10
k = mm.bit_length()
K = 1<<k
nu = lambda L: int("".join([bin(K+a)[-k:] for a in L[::-1]]), 2)
st = lambda n: bin(n)[2:] + "0"
li = lambda s: [int(a, 2) if len(a) else 0 for a in [s[-(i+1)*k-1:-i*k-1] for i in range(200001)]]
n,m = map(int, input().split())
a = [int(i) for i in input().split()]
b = [0]*100001
for i in a:
b[i] += 1
c = li(st(nu(b)*nu(b)))
ans = 0
for i in range(200001)[::-1]:
if c[i] > 0:
p = min(m,c[i])
m -= p
ans += i*p
if m == 0:
break
print(ans)
| 0 | null | 135,079,684,682,138 | 288 | 252 |
H, W=map(int, input().split())
S=[]
from math import ceil
for h in range(H):
s=list(input())
S.append(s)
dp = [[float("INF")]*W for _ in range(H)]
if S[0][0]=="#":
dp[0][0]=1
else:
dp[0][0]=0
for h in range(H):
for w in range(W):
if w==0 and h==0:
continue
if h==0:
if S[h][w] == S[h][w-1]:
now=0
else:
now=1
dp[h][w]=min(dp[h][w-1]+now, dp[h][w])
elif w==0:
if S[h][w] == S[h-1][w]:
now=0
else:
now=1
dp[h][w]=min(dp[h-1][w]+now, dp[h][w])
else:
if S[h][w]==S[h][w-1]:
noww = 0
else:
noww=1
if S[h][w]==S[h-1][w]:
nowh = 0
else:
nowh=1
dp[h][w] = min(dp[h][w], dp[h][w-1]+noww, dp[h-1][w]+nowh)
ans = ceil(dp[-1][-1]/2)
print(ans)
|
def resolve():
'''
code here
'''
import collections
import numpy as np
H, W = [int(item) for item in input().split()]
grid = [[item for item in input()] for _ in range(H)]
dp = [[300 for _ in range(W+1)] for _ in range(H+1)]
for i in range(H):
for j in range(W):
if i == 0 and j == 0:
if grid[0][0] == '#':
dp[i+1][j+1] = 1
else:
dp[i+1][j+1] = 0
else:
add_v = 0
add_h = 0
if grid[i][j] != grid[i][j-1]:
add_h = 1
if grid[i][j] != grid[i-1][j]:
add_v = 1
dp[i+1][j+1] = min(dp[i+1][j]+add_h, dp[i][j+1]+add_v)
# print(dp)
if grid[H-1][W-1] == '#':
print(dp[H][W]//2+1)
else:
print(dp[H][W]//2)
if __name__ == "__main__":
resolve()
| 1 | 49,363,203,770,342 | null | 194 | 194 |
n=int(input())
p=[input().split() for _ in range(n)]
x=input()
ans=0
flag=False
for i in p:
if i[0]==x:
flag=True
continue
if flag:
ans+=int(i[1])
print(ans)
|
import itertools
n=int(input())
ab = []
for _ in range(n):
a, b = (int(x) for x in input().split())
ab.append([a, b])
memo = []
for i in range(n):
memo.append(i)
ans = 0
count = 0
for v in itertools.permutations(memo, n):
count += 1
tmp_root = 0
for i in range(1, n):
tmp_root += ((ab[v[i-1]][0]-ab[v[i]][0])**2+(ab[v[i-1]][1]-ab[v[i]][1])**2)**0.5
ans += tmp_root
print(ans/count)
| 0 | null | 123,005,787,624,342 | 243 | 280 |
def make_bit(n):
bit = []
for i in range(2**n):
bit.append(bin(i)[2::])
i = 0
while i < len(bit):
while len(bit[i]) < len(bin(2**n-1)[2::]):
bit[i] = "0" + bit[i]
i += 1
return bit
h, w, k = map(int, input().split())
c = [list(input()) for _ in range(h)]
h_pats = make_bit(h)
w_pats = make_bit(w)
ans = 0
for h_pat in h_pats:
for w_pat in w_pats:
cnt = 0
for i in range(h):
for j in range(w):
if h_pat[i] == "1" or w_pat[j] == "1":
continue
if c[i][j] == "#":
cnt += 1
if cnt == k:
ans += 1
print(ans)
|
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
from collections import defaultdict
from collections import Counter
import bisect
def main():
H, W, K = MI()
C = []
for i in range(H):
c = S()
C.append(c)
A = []
for i in range(2 ** (H + W)):
A_bit = []
for j in range(H + W):
# 二進数表記でj回右にシフトして0桁目(一番下の桁)が1であればTrue
if ((i >> j) & 1):
A_bit.append(j)
A.append(A_bit)
Ans_list = []
for a in A:
cnt = 0
for i in range(H):
if i in a:
continue
else:
for j in range(H, W + H):
if j not in a and C[i][j - H] == '#':
cnt += 1
Ans_list.append(cnt)
ans = Counter(Ans_list)[K]
print(ans)
if __name__ == "__main__":
main()
| 1 | 8,870,472,352,640 | null | 110 | 110 |
import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
n, u, v = map(int, input().split())
u, v = u - 1, v - 1
graph = [[] for _ in range(n)]
for _ in range(n - 1):
a, b = map(int, input().split())
a, b = a - 1, b - 1
graph[a].append(b)
graph[b].append(a)
def dfs(v, d, count):
count[v] = d
for v_next in graph[v]:
if count[v_next] >= 0:
continue
dfs(v_next, d + 1, count)
count_tak = [-1] * n
dfs(u, 0, count_tak)
count_aok = [-1] * n
dfs(v, 0, count_aok)
ans = 0
for i in range(n):
if count_tak[i] < count_aok[i]:
ans = max(ans, count_aok[i] - 1)
print(ans)
|
from collections import deque
N,u,v=map(int,input().split())
G=[[] for _ in range(N)]
for _ in range(N-1):
a,b = map(int,input().split())
G[a-1].append(b-1)
G[b-1].append(a-1)
def bfs(s):
seen = [0]*N
d = [0]*N
todo = deque()
seen[s]=1
todo.append(s)
while len(todo):
a = todo.popleft()
for b in G[a]:
if seen[b] == 0:
seen[b] = 1
todo.append(b)
d[b] += d[a] + 1
return d
d1 = bfs(u-1)
d2 = bfs(v-1)
print(max([d2[i] for i in range(N) if d1[i]<=d2[i]])-1)
| 1 | 116,975,889,451,818 | null | 259 | 259 |
from collections import defaultdict
dd = defaultdict(int)
n,p=map(int, input().split())
S = list(input().rstrip())
tmp = 0
r=1
su=0
dd[0]=1
if p==2 or p==5:
c=n
for s in S[::-1]:
if int(s)%p==0:
su+=c
c-=1
print(su)
else:
for s in S[::-1]:
tmp+=int(s)*r
tmp%=p
dd[tmp]+=1
r*=10
r%=p
for i in dd.values():
su += (i*(i-1))//2
print(su)
|
import sys
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
nf = lambda: float(ns())
nfn = lambda y: [nf() for _ in range(y)]
nfa = lambda: list(map(float, stdin.readline().split()))
nfan = lambda y: [nfa() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()
from collections import defaultdict
n, p = na()
s = ns()
if 10 % p == 0:
ans = 0
for i in range(n - 1, -1, -1):
if int(s[i]) % p == 0:
ans += i + 1
print(ans)
exit(0)
c = [0] * (n + 1)
m = 1
for i in range(n - 1, -1, -1):
t = int(s[i]) * m % p
c[i] = (c[i + 1] + t) % p
m *= 10
m %= p
ans = 0
dic = defaultdict(int)
for i in range(n, -1, -1):
ans += dic[c[i]]
dic[c[i]] += 1
print(ans)
| 1 | 58,163,693,896,448 | null | 205 | 205 |
from math import gcd
def lcm(a, b):
return a * b // gcd(a, b)
n, m = map(int, input().split())
a = list(map(int, input().split()))
l = [0] * n
for i in range(n):
tmp = a[i]
while tmp % 2 == 0:
tmp //= 2
l[i] += 1
if i > 0 and l[i] != l[i - 1]:
print(0)
exit(0)
res = 1
for i in range(n):
res = lcm(res, a[i] // 2)
print(m // res - m // (res * 2))
|
# ABC150 D
from math import gcd
N,M=map(int,input().split())
A=list(map(int,input().split()))
g=A[0]
check=g&-g
for a in A:
if check!=a&-a:
check=-1
break
g=g*a//gcd(a,g)
if check>=0:
g//=2
print((M//g+1)//2)
else:
print(0)
| 1 | 102,063,924,722,760 | null | 247 | 247 |
n, u, v = map(int, input().split())
tree = [[] for i in range(n+1)]
for i in range(n-1):
a, b = map(int, input().split())
tree[a].append(b)
tree[b].append(a)
dist1 = [100005]*(n+1)
q = []
q.append(v)
dist1[v] = 0
while q:
now = q.pop()
for next in tree[now]:
if dist1[next] == 100005:
q.append(next)
dist1[next] = dist1[now] + 1
dist2 = [100005]*(n+1)
q = []
q.append(u)
dist2[u] = 0
while q:
now = q.pop()
for next in tree[now]:
if dist2[next] == 100005:
q.append(next)
dist2[next] = dist2[now] + 1
for i in range(1, n+1):
if dist1[i] <= dist2[i]:
dist2[i] = -1
for i in range(1, n+1):
if dist2[i] != -1:
dist2[i] = 100005
q = []
q.append(u)
dist2[u] = 0
while q:
now = q.pop()
for next in tree[now]:
if dist2[next] == 100005:
q.append(next)
dist2[next] = dist2[now] + 1
ans = 0
for i in range(1, n+1):
if dist2[i] != -1:
ans = max(ans, dist1[i])
print(ans-1)
|
N = int(input())
S = 0
for i in range(1, N+1):
if i % 3 == 0 and i % 5 == 0:
i = "FizzBuzz"
elif i % 3 == 0:
i = "Fizz"
elif i % 5 == 0:
i = "Buzz"
else:
S += i
print(S)
| 0 | null | 76,428,676,590,700 | 259 | 173 |
readline = open(0).readline
write = open(1, 'w').write
while 1:
x = readline()
if x == "0\n":
break
write("%d\n" % sum(map(int, x.strip())))
|
# coding: utf-8
while True:
strnum = input().rstrip()
if strnum == "0":
break
answer = sum(map(int, strnum))
print(answer)
| 1 | 1,578,656,392,512 | null | 62 | 62 |
N = int(input())
A_ls = map(int, input().split(' '))
rst = set()
for i in A_ls:
rst.add(i)
if len(rst) == N:
print('YES')
else:
print('NO')
|
N=int(input())
S=input()
res=0
R=[]
G=[]
B=[]
r,g,b=0,0,0
for i in range(N):
if S[i]=='R':
r+=1
elif S[i]=='G':
g+=1
else:
b+=1
R.append(r)
G.append(g)
B.append(b)
for i in range(N):
for j in range(N):
if not i<j:
continue
k=S[2*j-i] if 2*j-i<N else 'A'
if set([S[i],S[j]])==set(['R','G']):
res+=B[-1]-B[j]-(k=='B')
elif set([S[i],S[j]])==set(['B','G']):
res+=R[-1]-R[j]-(k=='R')
elif set([S[i],S[j]])==set(['R','B']):
res+=G[-1]-G[j]-(k=='G')
print(res)
| 0 | null | 55,196,945,082,000 | 222 | 175 |
import sys
import numpy as np
n, k = map(int,input().split())
a = np.array(sorted(list(map(int, input().split()))))
f = np.array(sorted(list(map(int, input().split())), reverse=True))
asum = a.sum()
l,r = 0, 10**13
while l != r:
mid = (l+r)//2
can = (asum - np.minimum(mid//f, a).sum()) <= k
if can:
r = mid
else:
l = mid +1
print(l)
|
#import sys
import numpy as np
#input = sys.stdin.readline
def main():
n, k=map(int, input().split())
a=np.array(list(map(int, input().split())), dtype=np.int64)
f=np.array(list(map(int, input().split())), dtype=np.int64)
a=np.sort(a)
f=np.sort(f)[::-1]
l,r=0,10**12
while l<=r:
m=(l+r)//2
tr=np.clip(a-m//f,0,None).sum()
if tr>k:
l=m+1
else:
r=m-1
print(l)
if __name__ == '__main__':
main()
| 1 | 165,159,985,500,398 | null | 290 | 290 |
from _collections import deque
from _ast import Num
def parser():
while 1:
data = list(input().split(' '))
for number in data:
if len(number) > 0:
yield (number)
input_parser = parser()
def gw():
global input_parser
return next(input_parser)
def gi():
data = gw()
return int(data)
MOD = int(1e9 + 7)
import numpy
from collections import deque
from math import sqrt
from math import floor
# https://atcoder.jp/contests/abc145/tasks/abc145_e
#E - All-you-can-eat
"""
"""
N = gi()
M = gi()
S = gw()
lis = [0] * (N + 5)
li = 0
all_good = 1
for i in range(1, N + 1):
while (i - li > M or (li < i and S[li] == "1")):
li += 1
if li == i:
all_good = 0
break
lis[i] = li
if all_good:
ans = []
ci = N
while ci > 0:
step = ci - lis[ci]
ans.append(step)
ci -= step
ans.reverse()
for a in ans:
print(a, end=" ")
else:
print(-1)
|
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
n,m = inpl()
s = list(input())[::-1]
res = []
now = 0
while now != n:
nex = min(now + m, n)
while s[nex] == '1':
nex -= 1
if nex == now:
print(-1)
quit()
res += [nex - now]
now = nex
print(*res[::-1])
| 1 | 139,319,812,214,464 | null | 274 | 274 |
n=int(input())
p=list(map(int,input().split()))
check=200001
cnt=0
for i in range(n):
if check > p[i]:
check = p[i]
cnt+=1
print(cnt)
|
inp = input().split()
A = int(inp[0])
B = int(inp[1].replace('.',''))
print(A*B//100)
| 0 | null | 50,711,847,236,700 | 233 | 135 |
n=int(input())
cnt=0
Arm=[]
for i in range(n):
x,l=map(int,input().split())
Arm.append([x+l,x-l])
Arm.sort()
dis=-float('inf')
for i in range(n):
if dis<=Arm[i][1]:
cnt+=1
dis=Arm[i][0]
print(cnt)
|
n = int(input())
arms = []
for _ in range(n):
x, l = map(int, input().split())
arms.append((x - l, x + l))
arms.sort(key = lambda x : x[1])
last_right = arms[0][1]
ans = 1
for i in range(1, n):
left, right = arms[i]
if left < last_right:
continue
last_right = right
ans += 1
print(ans)
| 1 | 90,008,154,092,660 | null | 237 | 237 |
print('bust') if sum(map(int, input().split())) >= 22 else print('win')
|
from sys import exit
import math
import collections
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))
a,b,c = mi()
if a + b + c >=22:
print('bust')
else:
print('win')
| 1 | 119,090,359,940,118 | null | 260 | 260 |
K, N = map(int, input().split())
nums = list(map(int, input().split()))
before = 0
max_n = 0
for num in nums:
dist = num - before
max_n = max(max_n, dist)
before = num
max_n = max(max_n, K-nums[-1]+nums[0])
print(K-max_n)
|
K,N=map(int,input().split())
array=input().split()
A=[]
for i in array:
A.append(int(i))
dist=[]
for i in range(N):
if i!=N-1:
dist.append(A[i+1]-A[i])
else:
dist.append((K-A[i])+A[0])
dist=sorted(dist)
ans=0
for i in range(N-1):
ans+=dist[i]
print(ans)
| 1 | 43,512,389,621,322 | null | 186 | 186 |
def read_int():
return int(input().strip())
def read_ints():
return list(map(int, input().strip().split(' ')))
def solve():
N = read_int()
D = read_ints()
S = sum(D)
answer = 0
for d in D:
S -= d
answer += d*S
return answer
if __name__ == '__main__':
print(solve())
|
S=input()
if S[-1] == 's':
print(S+"es")
else:
print(S+"s")
| 0 | null | 85,310,845,299,200 | 292 | 71 |
n = int(input())
array = list(map(int, input().split()))
print("{} {} {}".format(min(array), max(array), sum(array)))
|
def main():
s, t = input().split()
print(t, s, sep='')
if __name__ == '__main__':
main()
| 0 | null | 52,148,792,024,670 | 48 | 248 |
s = input()
q = int(input())
count = 0
a = []
b = []
for _ in range(q):
Q = list(map(str, input().split()))
if Q[0] == "1":
count += 1
else:
if (int(Q[1])+count)%2 == 1:
a.append(Q[2])
else:
b.append(Q[2])
a = "".join(a[::-1])
b = "".join(b)
s = a + s + b
if count%2 == 1 and count != 0:
s = s[::-1]
print("".join(s))
|
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)
def main():
h,w,k = LI()
aa = [[int(c) for c in S()] for _ in range(h)]
def f(hs):
l = len(hs)
c = [0] * l
r = l - 1
for i in range(w):
nc = [0] * l
bf = False
for j in range(l):
for h in hs[j]:
nc[j] += aa[h][i]
if nc[j] > k:
return -1
if nc[j] + c[j] > k:
bf = True
if bf:
r += 1
c = nc
else:
for j in range(l):
c[j] += nc[j]
return r
r = inf
for bi in range(2**(h-1)):
hs = [[0]]
for i in range(h-1):
if 2**i & bi > 0:
hs.append([])
hs[-1].append(i+1)
t = f(hs)
if t >= 0 and r > t:
r = t
return r
print(main())
| 0 | null | 53,205,783,665,740 | 204 | 193 |
n = int(input())
a = 0
b = 0
d1 = 0
d2 = 0
for i in range(n):
d1,d2 = map(int,input().split())
if(a==0 and d1 ==d2):
a+=1
elif(a==1 and d1 ==d2):
a+=1
elif(a==2 and d1 ==d2):
b +=1
break
else:
a =0
if(b>=1):
print("Yes")
else:
print("No")
|
import sys
n=int(input())
d=[]
cnt=0
for i in range(n):
D=[int(x) for x in input().split()]
d.append(D)
for d1,d2 in d:
if d1==d2:
cnt+=1
else:
cnt=0
if 3<=cnt:
print("Yes")
sys.exit()
print("No")
| 1 | 2,471,192,901,958 | null | 72 | 72 |
1
2
a,b = map(int, input().split())
print("a "+("==" if a == b else "<" if a < b else ">")+" b")
|
# -*- coding:utf-8 -*-
def solve():
N, X, M = list(map(int, input().split()))
def f(x, m):
return x%m
# A[i]の値は必ず mod Mの範囲に収まる
# ということはたかだかMの周期でループする
# ただし、ループして戻るのはA[0]とは限らず、適当なA[?]に戻る
# 注意として、A[i]=0になったら、A[i+1]以降は必ず0
A = [0]*(10**5+2) # A[i]
Ar = [0]*(10**5+2) # Ar[i] := A[i]以下の累積和
A[0], Ar[0] = X, X
Adic = {X:0} # Adic[A[i]]=i => 過去のA[i]はi番目に出現した
stop_i = 0
is_zero = False
for i in range(1, N):
A[i] = f(pow(A[i-1], 2, M), M)
Ar[i] = Ar[i-1] + A[i]
if A[i] == 0:
is_zero = True
stop_i = i
break
if A[i] in Adic:
stop_i = i
break
Adic[A[i]] = i
if stop_i == 0:
print(Ar[N-1])
elif is_zero:
print(Ar[stop_i])
else:
start_i = Adic[A[stop_i]]
t = stop_i - start_i
restN = N - start_i
if start_i-1 >= 0:
ans = Ar[start_i-1]
ans += (Ar[stop_i-1] - Ar[start_i-1]) * (restN//t)
ans += Ar[start_i-1+(restN%t)] - Ar[start_i-1]
else:
ans = Ar[stop_i-1] * (restN//t)
ans += Ar[start_i-1+(restN%t)]
print(ans)
if __name__ == "__main__":
solve()
| 0 | null | 1,573,090,808,240 | 38 | 75 |
student_info = []
while True:
s = map(int,raw_input().split(" "))
if s[0] is s[1] is s[2] is -1:
break
student_info.append(s)
score_info = []
for s in student_info:
if s[0] == -1 or s[1] == -1:
score_info.append("F")
elif s[0]+s[1] >= 80:
score_info.append("A")
elif 65 <= s[0]+s[1] < 80:
score_info.append("B")
elif 50 <= s[0]+s[1] < 65:
score_info.append("C")
elif 30<= s[0]+s[1] < 50:
if s[2] >= 50:
score_info.append("C")
else:
score_info.append("D")
else:
score_info.append("F")
for i in score_info:
print i
|
while(True):
m, f, r = map(int, input().split())
if(m == f == r == -1): break
score = m + f
if(m==-1 or f==-1): print('F')
elif(score >= 80): print('A')
elif(score >= 65): print('B')
elif(score >= 50): print('C')
elif(score >= 30):
if(r >= 50): print('C')
else: print('D')
else: print('F')
| 1 | 1,245,057,088,340 | null | 57 | 57 |
#create date: 2020-06-30 14:42
import sys
stdin = sys.stdin
from itertools import combinations_with_replacement
def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))
def main():
n, m, q = na()
matrix = list()
for i in range(q):
matrix.append(na())
l = list(combinations_with_replacement(range(1, m+1), n))
ans = 0
for li in l:
res = 0
for q in matrix:
a, b, c, d = q
if li[b-1] - li[a-1] == c:
res += d
ans = max(ans, res)
print(ans)
if __name__ == "__main__":
main()
|
n = int(input())
a = list(map(int, input().split())) # 横入力
x = [0]
aaa = 0
for i in range(n):
aaa += a[i]
x.append(aaa)
aa = sum(a)
y = [aa]
for i in range(n):
aa -= a[i]
y.append(aa)
ans = 202020202020
for i in range(n+1):
ans = min(ans, abs(x[i] - y[i]))
print(ans)
| 0 | null | 85,050,377,458,012 | 160 | 276 |
K = int(input())
verbose = False
path = set()
a = 0
step = 0
while True:
step += 1
a = (a*10 + 7) % K
if verbose: print (step, ':', a)
if a == 0:
print (step)
break
if a in path:
print ('-1')
break
path.add(a)
|
from itertools import product
n = int(input())
memo = [[] for _ in range(n)]
for i in range(n):
for _ in range(int(input())):
x, y = map(int, input().split())
memo[i].append((x-1, y))
ans = 0
for a in product([0,1], repeat=n):
REAL = True
for i in range(n):
if a[i] == 1:
for x, y in memo[i]:
if a[x] != y:
REAL = False
break
if REAL == False:
break
if REAL:
ans = max(ans, sum(a))
print(ans)
| 0 | null | 63,550,792,356,740 | 97 | 262 |
from decimal import Decimal
a, b, c = [Decimal(x) for x in input().split()]
result = a.sqrt() + b.sqrt() < c.sqrt()
print('Yes' if result else 'No')
|
N = input()
list = []
for i in range(len(N)):
list.append(int(N[i]))
if sum(list) % 9 ==0:
print('Yes')
else:
print('No')
| 0 | null | 28,184,777,554,848 | 197 | 87 |
a,b,c=map(int,input().split())
if (4*a*b)<(c-a-b)**2 and c-a-b>0: print('Yes')
else: print('No')
|
a,b,c=map(int,raw_input().split())
if a+b >= c:
print "No"
else:
ans1 = 4 * a * b;
ans2 = (c - a - b) * (c - a - b)
if ans1 < ans2:
print "Yes"
else:
print "No"
| 1 | 51,530,338,633,658 | null | 197 | 197 |
A, B = input().split()
A = int(A)
B = int(''.join([b for b in B if b != '.']))
print(A * B // 100)
|
n = int(input())
s = input()
count = 1
for h in range(len(s)-1):
if s[h] != s[h+1]:
count += 1
print(count)
| 0 | null | 93,786,005,770,532 | 135 | 293 |
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
import numpy as np
#======================================================#
MOD=10**9+7
def main():
n = II()
aa = np.array(MII())
ans = 0
for i in range(60):
cnt1 = int((aa&1).sum())
ans += cnt1*(n-cnt1)*(2**i)
aa >>= 1
print(ans%MOD)
if __name__ == '__main__':
main()
|
n = int(input())
s = list(map(int, input().strip().split(' ')))
t = n // 2
for i in range(0, n // 2):
s[i], s[n - i - 1] = s[n - i - 1], s[i]
for i in range(0, len(s)):
if i != len(s) - 1:
print(s[i], end=" ")
else:
print(s[i])
| 0 | null | 61,968,952,862,740 | 263 | 53 |
N, A = input(), [int(v) for v in input().split()]
# max(abs(x-y) for x, y in zip(A, A[1:]))
stool = A[0]
ans = 0
for i, h in enumerate(A):
if h < stool:
ans += stool - h
stool = max(stool, h)
print(ans)
|
def main():
N, A = int(input()), list(map(int, input().split()))
ans = 0
for idx in range(1, N):
if A[idx] < A[idx - 1]:
diff = A[idx - 1] - A[idx]
ans += diff
A[idx] = A[idx - 1]
print('{}'.format(ans))
if __name__ == '__main__':
main()
| 1 | 4,547,631,811,268 | null | 88 | 88 |
i = list(map(int, input().split()))
a = i[0]
b = i[1]
print('{0} {1} {2:.5f}'.format(a // b, a % b, float(a / b)))
|
a, b = input().split()
a = int(a)
b = int(b)
print(a//b, a%b, "{0:.5f}".format(a/b))
| 1 | 601,884,208,658 | null | 45 | 45 |
N,K = map(int,input().split())
i = N // K
N = N - K * i
ans = N
while True:
N = abs(N - K)
if ans > N:
ans = N
else:
break
print(ans)
|
N = int(input())
A = [list(map(int, (input().split(' ')))) for i in range(N)]
hoge = [sum(a) for a in A]
fuga = [a[0] - a[1] for a in A]
print(max(max(hoge) - min(hoge), max(fuga) - min(fuga)))
| 0 | null | 21,303,262,386,160 | 180 | 80 |
x = list(map(int, input().split()))
if len(set(x))==2:
kotae='Yes'
else:
kotae='No'
print(kotae)
|
#1,2,3,4,5,6,7,8,9
#10,11,12,21,22,23,32,33,34,43,44,45,54,55,56,....,98,99
#100,101,110,111,112,121,122,123
#210,211,212,221,222,223,232,233,234
#321,322,323,332,333,334,343,344,345
#1000,1001,1010,1011,1012,
from collections import deque
def main():
K=int(input())
lnln=deque([i for i in range(1,10)])
for _ in range(K):
n=lnln.popleft()
if n%10!=0:
lnln.append(n*10+(n%10)-1)
lnln.append(n*10+(n%10))
if n%10!=9:
lnln.append(n*10+(n%10)+1)
print(n)
if __name__=="__main__":
main()
| 0 | null | 54,222,073,916,190 | 216 | 181 |
def dfs(seq):
ans = 0
if len(seq) == n:
score = 0
for a, b, c, d in req:
if seq[b-1] - seq[a-1] == c:
score += d
return score
else:
for i in range(seq[-1], m+1):
next_seq = seq + (i,)
score = dfs(next_seq)
ans = max(ans, score)
return ans
n, m, q = list(map(int, input().split()))
req = [list(map(int, input().split())) for _ in range(q)]
print(dfs((1,)))
|
import sys
k = int(input())
ans = [0]*(k+1)
ans[0] = 7 % k
if ans[0] == 0:
print(1)
else:
for i in range(k):
ans[i+1] = (ans[i]*10 + 7) % k
if ans[i+1] == 0:
print(i+2)
sys.exit()
print(-1)
| 0 | null | 16,889,307,481,732 | 160 | 97 |
#from collections import defaultdict, deque
#import itertools
#import numpy as np
#import re
import bisect
def main():
N = int(input())
SS = []
for _ in range(N):
SS.append(input())
S = []
for s in SS:
while '()' in s:
s = s.replace('()', '')
S.append(s)
#print(S)
S = [s for s in S if s != '']
sum_op = 0
sum_cl = 0
S_both_op = []
S_both_cl = []
for s in S:
if not ')' in s:
sum_op += len(s)
elif not '(' in s:
sum_cl += len(s)
else:
pos = s.find('(')
if pos <= len(s) - pos:
S_both_op.append((pos, len(s)-pos)) #closeのほうが少ない、'))((('など -> (2,3)
else:
S_both_cl.append((pos, len(s)-pos)) #closeのほうが多い、')))(('など -> (3,2)
# S_both_opは、耐えられる中でより伸ばす順にしたほうがいい?
#S_both_op.sort(key=lambda x: (x[0], x[0]-x[1])) #closeの数が小さい順にsortかつclose-openが小さい=伸ばす側にsort
#S_both_cl.sort(key=lambda x: (x[0], x[0]-x[1])) #これもcloseの数が小さい順にsortかつclose-openが小さい=あまり縮まない順にsort
S_both_op.sort(key=lambda x: x[0])
S_both_cl.sort(key=lambda x: -x[1])
for p in S_both_op:
sum_op -= p[0]
if(sum_op < 0 ):
print('No')
exit()
sum_op += p[1]
for p in S_both_cl:
sum_op -= p[0]
if(sum_op < 0 ):
print('No')
exit()
sum_op += p[1]
if sum_op == sum_cl:
print('Yes')
else:
print('No')
if __name__ == "__main__":
main()
|
from collections import deque
import sys
n,m = map(int,input().split())
turo = [[] for i in range(n)]
q = deque()
his = [False]*n
for i in range(m):
a,b = map(int,input().split())
turo[a-1].append(b-1)
turo[b-1].append(a-1)
par = [i for i in range(n)]
rank = [sys.maxsize for i in range(n)]
rank[0] = 0
q.append(0)
while len(q) > 0:
#print(q)
room = q.popleft()
if not his[room] :
his[room] = True
else:
continue
for room2 in turo[room]:
if rank[room] < rank[room2]:
q.append(room2)
par[room2] = room
rank[room2] = rank[room]+1
if len(his) < n:
print("No")
exit()
print("Yes")
for i in range(1,n):
print(par[i]+1)
| 0 | null | 21,959,699,459,360 | 152 | 145 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.