code1
stringlengths 16
24.5k
| code2
stringlengths 16
24.5k
| similar
int64 0
1
| pair_id
int64 2
181,637B
⌀ | question_pair_id
float64 3.71M
180,628B
⌀ | code1_group
int64 1
299
| code2_group
int64 1
299
|
---|---|---|---|---|---|---|
def main():
N = int(input())
A = list(map(int, input().split()))
if 1 not in A:
print(-1)
exit()
next = 1
for a in A:
if a == next:
next += 1
print(N - next + 1)
if __name__ == '__main__':
main()
| n=int(input())
s=list(map(int,input().split()))
ans=0
j=1
for i in s:
if i!=j :
ans+=1
else:
j+=1
print(ans) if ans<n else print(-1)
| 1 | 114,641,358,217,858 | null | 257 | 257 |
import sys
input = sys.stdin.readline
a, b = input()[:-1].split()
print(min(''.join(a for i in range(int(b))), ''.join(b for i in range(int(a))))) | h, w, k = map(int, input().split())
s = []
for _ in range(h):
s.append(input())
cnt = 1
rflg = False
rcnt = 1
for r in s:
if r.count('#')>0:
if rflg:
cnt += 1
rcnt = 1
rflg = True
elif rflg:
print(*ans)
continue
else:
rcnt += 1
continue
cflg = False
ans = []
for e in r:
if e=='#':
if cflg:
cnt += 1
cflg = True
ans.append(cnt)
for _ in range(rcnt):
print(*ans) | 0 | null | 114,154,887,591,030 | 232 | 277 |
import sys
input = sys.stdin.readline
def main():
n,a,b = [int(i) for i in input().strip().split()]
if (b-a) % 2 == 0:
print(abs(b - a) // 2)
else:
ans = min(a - 1, n - b) + 1 + (b - a - 1) // 2
print(ans)
return
if __name__ == "__main__":
main() | N,A,B = [int(x) for x in input().split()];
#print(A);
#print(B);
#print(N);
#lm = int(A + (B-A-1)/2);
lm = A + (B-A-1)//2;
#print(lm);
#rm = int(N-B+1 + (B-A-1)/2);
rm = N-B+1 + (B-A-1)//2;
#print(rm);
if (B-A)%2 == 0 :
print((B-A)//2);
else :
print(min(lm,rm)); | 1 | 109,082,553,933,290 | null | 253 | 253 |
n=int(input())
d={}
for i in range(1,n+1):
f=i//(10**(len(str(i))-1))
l=i-(i//10)*10
if l!=0:
c=f*10+l
if c in d:
d[c]+=1
else:
d[c]=1
ans=0
for i in d:
if int(str(i)[::-1]) in d:
ans+=d[i]*d[int(str(i)[::-1])]
print(ans) | # !/usr/bin/python3
"""
https://atcoder.jp/contests/abc152/tasks/abc152_d
Low Elements.
"""
def solve(n):
res = 0
for num in range(n+1):
start = int(str(num)[0])
end = int(str(num)[-1])
for i in range(1, 10):
for j in range(1, 10):
if i == start and j == end: dp[i][j] += 1
for i in range(1, 10):
for j in range(1, 10):
res += dp[i][j]*dp[j][i]
# for each in dp: print(each)
return res
if __name__ == "__main__":
n = int(input())
dp = [[0 for _ in range(10)] for _ in range(10)]
print(solve(n))
| 1 | 86,506,354,440,040 | null | 234 | 234 |
N = int(input())
S = str(input())
flag = False
half = (N+1) // 2
if S[:half] == S[half:N]:
flag = True
if flag:
print("Yes")
else:
print("No") | x=list(input().split())
print(x[1]+x[0])
| 0 | null | 125,077,918,721,408 | 279 | 248 |
from math import atan, radians, degrees
a, b, x = map(int, input().split())
h = x/(a**2)
he = b - h
if 2*h >= b:
ans = degrees(atan((2*b-2*h)/a))
print(ans)
else:
ans = degrees(atan(b**2/(2*h*a)))
print(ans)
| a, b, x = map(int, input().split())
if x > (a**2)*b/2:
t = 2*((a**2)*b-x)/(a**3)
else:
t = a*(b**2)/(2*x)
import math
ans = math.degrees(math.atan(t))
print(ans)
| 1 | 162,770,787,380,800 | null | 289 | 289 |
#coding:utf-8
#?????¬???????????????
def draw_topbottom(n):
a = ""
for i in range(n):
a += "#"
print a
def draw_middle(n):
a = "#"
for i in range(n-2):
a += "."
a += "#"
print a
while 1:
HW = raw_input().split()
H = int(HW[0])
W = int(HW[1])
if H == 0 and W == 0:
break
draw_topbottom(W)
for i in range(H-2):
draw_middle(W)
draw_topbottom(W)
print "" | while True:
H, W = [int(x) for x in input().split() if x.isdigit()]
if H ==0 and W == 0:
break
else:
for i in range(H):
print("#", end='')
if i == 0 or i == H-1:
for j in range(W-2):
print("#", end='')
else:
for j in range(W-2):
print(".", end='')
print("#")
print("") | 1 | 805,202,590,192 | null | 50 | 50 |
n=int(input())
s=input()
mid=n//2
if(s[:mid]==s[mid:]):
print("Yes")
else:
print("No")
| R = int(input())
print(R*2*3.14159265358979)
| 0 | null | 88,661,860,891,090 | 279 | 167 |
a=input()
if a in "abcdefgeijklmnopqrstuvwxyz":
print('a')
else:
print('A') | s = input()
S = list(s)
if S[2] == S[3] and S[4] == S[5]:
print('Yes')
else:
print('No') | 0 | null | 26,715,133,545,320 | 119 | 184 |
a=input()
b=int(input())
while b>0:
tmp=input().split(" ")
if tmp[0]=="replace":
a=a[:int(tmp[1])]+tmp[3]+a[int(tmp[2])+1:]
if tmp[0]=="reverse":
tmp2="".join(list(a)[int(tmp[1]):int(tmp[2])+1])[::-1]
a=a[:int(tmp[1])]+tmp2+a[int(tmp[2])+1:]
if tmp[0]=="print":
print(a[int(tmp[1]):int(tmp[2])+1])
b-=1
| x,y,z = map(int, input().split())
x = x^y
y = x^y
x = x^y
x = z^x
z = z^x
x = z^x
print("{} {} {}".format(x,y,z)) | 0 | null | 19,925,156,766,278 | 68 | 178 |
import sys
import numpy as np
sys.setrecursionlimit(10 ** 7)
N, K = map(int, input().split())
MOD = 10 ** 9 + 7
# 階乗、Combinationコンビネーション(numpyを使う)
def cumprod(arr, MOD):
L = len(arr)
Lsq = int(L**.5+1)
arr = np.resize(arr, Lsq**2).reshape(Lsq, Lsq)
for n in range(1, Lsq):
arr[:, n] *= arr[:, n-1]
arr[:, n] %= MOD
for n in range(1, Lsq):
arr[n] *= arr[n-1, -1]
arr[n] %= MOD
return arr.ravel()[:L]
def make_fact(U, MOD):
x = np.arange(U, dtype=np.int64)
x[0] = 1
fact = cumprod(x, MOD)
x = np.arange(U, 0, -1, dtype=np.int64)
x[0] = pow(int(fact[-1]), MOD-2, MOD)
fact_inv = cumprod(x, MOD)[::-1]
return fact, fact_inv
U = 10**6
fact, fact_inv = make_fact(N * 2 + 10, MOD)
fact, fact_inv = fact.tolist(), fact_inv.tolist()
def mod_comb_k(n, k, mod):
return fact[n] * fact_inv[k] % mod * fact_inv[n - k] % mod
ans = 0
for i in range(N):
if K < i:
continue
if N - 1 <= K:
ans = mod_comb_k(N + N - 1, N - 1, MOD)
break
if i == 0:
ans += 1
continue
a = int(mod_comb_k(N - 1, i, MOD)) * int(mod_comb_k(N, i, MOD))
a %= MOD
ans += a
ans %= MOD
'''
a = int(fact[N]) * int(fact_inv[i]) % MOD * int(fact_inv[N - 1])
a = a * int(fact[N-1]) % MOD * int(fact_inv[i]) % MOD * \
int(fact_inv[N-i-1]) % MOD
ans = (a + ans) % MOD
'''
print(ans)
| n, k = map(int, input().split())
def modinv(a, mod=10**9+7):
return pow(a, mod-2, mod)
def combination(n, r, mod=10**9+7):
r = min(r, n-r)
res = 1
for i in range(r):
res = res * (n - i) * modinv(i+1, mod) % mod
return res
def com(n, r, mod):
r = min(r, n - r)
if r == 0:
return 1
res = ilist[n] * iinvlist[n-r] * iinvlist[r] % mod
return res
mod = 10**9+7
ilist = [0]
iinvlist = [1]
tmp = 1
for i in range(1, n+1):
tmp *= i
tmp %= mod
ilist.append(tmp)
iinvlist.append(modinv(tmp, mod))
ans = 0
k = min(n-1, k)
for i in range(k+1):
tmp = com(n, i, mod)
tmp *= com(n-1, i, mod)
ans += tmp
ans %= mod
print(ans) | 1 | 67,477,999,471,962 | null | 215 | 215 |
n=int(input())
a=list(map(int,input().split()))
score=0
mod=10**9+7
b=sum(a)
for i in range(0,n-1):
b-=a[i]
score+=a[i]*b
print(score%mod) | N = int(input())
Al = input().split()
A = list( map((lambda x: int(x)), Al))
num = 0
ma = 10**9 + 7
li = 0
for i in range(N-1, 0, -1):
li += A[i]
num += A[i-1] * li
num = num % ma
print(num)
| 1 | 3,847,024,878,846 | null | 83 | 83 |
a = [list(map(int, input().split())) for _ in range(3)]
N=int(input())
b = [int(input()) for _ in range(N)]
cnt=0
for i in range(N):
for j in range(3):
for k in range(3):
if b[i] == a[j][k]:
a[j][k] =1000
if sum(a[j]) ==3000 or a[0][k]+a[1][k]+a[2][k]==3000 or a[0][0]+a[1][1]+a[2][2]==3000 or a[0][2]+a[1][1]+a[2][0]==3000:
cnt +=1
print('Yes' if cnt>0 else 'No') | 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())
def main():
A = [[]for _ in range(3)]
for i in range(3):
A[i] = LI()
A_ = [[]for _ in range(3)]
for i in range(3):
for j in range(3):
A_[j].append(A[i][j])
A__ = [[]for _ in range(2)]
for i in range(3):
A__[0].append(A[i][i])
A__[1].append(A[i][2 - i])
N = I()
B = []
for i in range(N):
b = I()
B.append(b)
for i in range(3):
if b in A[i]:
ind = A[i].index(b)
A[i][ind] = 0
if b in A_[i]:
ind = A_[i].index(b)
A_[i][ind] = 0
for j in range(2):
if b in A__[j]:
ind = A__[j].index(b)
A__[j][ind] = 0
ans_list = []
for i in range(3):
ans_list.append(sum(A[i]))
ans_list.append(sum(A_[i]))
for j in range(2):
ans_list.append(sum(A__[j]))
if 0 in ans_list:
print('Yes')
else:
print('No')
if __name__ == "__main__":
main() | 1 | 59,734,931,998,220 | null | 207 | 207 |
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush,heapify
import math
from copy import deepcopy
import queue
#import numpy as np
# sympy as syp(素因数分解とか)
Mod = 1000000007
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]
for i in range(2, 10**5 + 1):
fact.append((fact[-1] * i) % Mod)
inv.append((-inv[Mod % i] * (Mod // i)) % Mod)
factinv.append((factinv[-1] * inv[-1]) % Mod)
def cmb(n, r, p):
if (r < 0) or (n < r):
return 0
r = min(r, n - r)
return fact[n] * factinv[r] * factinv[n - r] % p
def sieve_of_eratosthenes(n):
if not isinstance(n,int):
raise TypeError("n is not int")
if n<2:
raise ValueError("n is not effective")
prime = [1]*(n+1)
for i in range(2,int(math.sqrt(n))+1):
if prime[i] == 1:
for j in range(2*i,n+1):
if j%i == 0:
prime[j] = 0
res = []
for i in range(2,n+1):
if prime[i] == 1:
res.append(i)
return res
class UnionFind:
def __init__(self,n):
self.parent = [i for i in range(n+1)]
self.rank = [0 for i in range(n+1)]
def findroot(self,x):
if x == self.parent[x]:
return x
else:
y = self.parent[x]
y = self.findroot(self.parent[x])
return y
def union(self,x,y):
px = self.findroot(x)
py = self.findroot(y)
if px < py:
self.parent[y] = px
else:
self.parent[px] = py
def same_group_or_no(self,x,y):
return self.findroot(x) == self.findroot(y)
def pow_k(x, n):
if n == 0:
return 1
K = 1
while n > 1:
if n % 2 != 0:
K *= x
x *= x
n //= 2
return K * x
def main(): #startline-------------------------------------------
n = int(input())
a = list(map(int, input().split()))
accum = sum(a)
ans = 1
b = [0] * (n + 1)
b[0] = 1
for i in range(1, n + 1):
accum -= a[i]
b[i] = min(2 * b[i - 1] - a[i], accum)
if b[i] < 0:
ans = -1
break
ans += b[i] + a[i]
if a[0] == 1:
ans = -1
if n == 0:
if a[0] == 1:
ans = 1
else:
ans = -1
print(ans)
if __name__ == "__main__":
main() #endline=============================================== | from itertools import accumulate
n = int(input())
As = list(map(int, input().split()))
# ノードが1個しかないとき
if n == 0:
if As[0] == 1:print(1)
else:print(-1)
exit()
# 深さが2以上のとき、初め0ならアウト
if As[0] != 0:
print(-1)
exit()
acc_r = list(accumulate(As[::-1]))
acc_r = acc_r[::-1]
# 一個ずれる
acc = acc_r[1:] + [acc_r[-1]]
p = 1
ans = 1
for s, a in zip(acc,As):
p = min((p-a)*2, s)
if p < 0:
print(-1)
exit()
ans += p
print(ans) | 1 | 19,009,130,508,370 | null | 141 | 141 |
#!/usr/bin/env python3
(n, ), *r = [[*map(int, i.split())] for i in open(0)]
s = sorted([[x + l, x - l] for x, l in r])
c = 1
p = s[0][0]
for i in s[1:]:
if i[1] >= p:
c += 1
p = i[0]
print(c)
| 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()))
## dp ##
def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]
## math ##
def to_bin(x: int) -> str: return format(x, 'b') # rev => int(res, 2)
def to_oct(x: int) -> str: return format(x, 'o') # rev => int(res, 8)
def to_hex(x: int) -> str: return format(x, 'x') # rev => int(res, 16)
MOD=10**9+7
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
while y: x,y = y,x%y
return x
def lcm(x,y): return x*y//gcd(x,y)
def enumerate_divs(n):
"""Return a tuple list of divisor of n"""
return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
def get_primes(MAX_NUM=10**3):
"""Return a list of prime numbers n or less"""
is_prime = [True]*(MAX_NUM+1)
is_prime[0] = is_prime[1] = False
for i in range(2, int(MAX_NUM**0.5)+1):
if not is_prime[i]: continue
for j in range(i*2, MAX_NUM+1, i): is_prime[j] = False
return [i for i in range(MAX_NUM+1) if is_prime[i]]
def prime_factor(n):
"""Return a list of prime factorization numbers of n"""
res = []
for i in range(2,int(n**0.5)+1):
while n%i==0: res.append(i); n //= i
if n != 1: res.append(n)
return res
## libs ##
from itertools import accumulate as acc, combinations as combi, product, combinations_with_replacement as combi_dup
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left
#======================================================#
def main():
n = II()
xl = [MII() for _ in range(n)]
lr_x = [[x-l, x+l] for x, l in xl]
lr_x.sort(key=lambda x: x[1])
now = -(10**9)
cnt = 0
for l, r in lr_x:
if now <= l:
cnt += 1
now = r
print(cnt)
if __name__ == '__main__':
main() | 1 | 89,424,833,414,628 | null | 237 | 237 |
mod=pow(10,9)+7
n,k=map(int,input().split())
a=[0 for i in range(100000+1)]
ans=0
for i in range(k,0,-1):
a[i]=k//i
a[i]=pow(a[i],n,mod)
j=2*i
while j<=k:
a[i]=(a[i]-a[j]+mod)%mod
j += i
ans=(ans+a[i]*i)%mod
print(ans) | import sys
sys.setrecursionlimit(10**7)
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 LI2(): return list(map(int,sys.stdin.readline().rstrip())) #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split()) #空白あり
def LS2(): return list(sys.stdin.readline().rstrip()) #空白なし
S = LS2()
N = len(S)+1
ANS = [0]*N
for i in range(N-1):
if S[i] == '<':
ANS[i+1] = ANS[i]+1
for i in range(N-2,-1,-1):
if S[i] == '>':
ANS[i] = max(ANS[i],ANS[i+1]+1)
print(sum(ANS))
| 0 | null | 96,609,900,335,828 | 176 | 285 |
from collections import deque
N, u, v = map(int, input().split())
u -= 1
v -= 1
edge = [[] for _ in range(N)]
for _ in range(N - 1):
A, B = map(int, input().split())
edge[A - 1].append(B - 1)
edge[B - 1].append(A - 1)
INF = 10 ** 6
lenA = [INF] * N
q = deque()
q.append((v, 0))
lenA[v] = 0
while len(q) > 0:
p, step = q.popleft()
for np in edge[p]:
if lenA[np] == INF:
lenA[np] = step + 1
q.append((np, step + 1))
lenT = [INF] * N
q = deque()
q.append((u, 0))
lenT[u] = 0
ans = 0
while len(q) > 0:
p, step = q.popleft()
if len(edge[p]) == 1:
ans = max(ans, step + (lenA[p] - step) - 1)
for np in edge[p]:
if lenT[np] == INF and lenA[np] > step + 1:
lenT[np] = step + 1
q.append((np, step + 1))
print(ans)
| import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
def pri(x): print('\n'.join(map(str, x)))
def prime_decomposition(n):
i = 2
table = []
while i*i <= n:
while n%i == 0:
n //= i
table.append(i)
i += 1
if n > 1:
table.append(n)
return table
def prime_decomposition2(n):
i = 2
table = defaultdict(int)
while i*i <= n:
while n%i == 0:
n //= i
table[i] += 1
i += 1
if n > 1:
table[n] += 1
return table
def make_divisor(n):
divisors = []
for i in range(1, int(n**0.5)+1):
if n%i == 0:
divisors.append(i)
if i != n//i:
divisors.append(n//i)
return divisors
N = int(input())
list_pd1 = make_divisor(N)
list_pd1.sort()
dict_pd2 = prime_decomposition2(N-1)
#print(N, ':', list_pd1)
#print(N-1, ':', dict_pd2)
cnt = 1
# -1 nohou
for val in dict_pd2.values():
cnt *= (val+1)
cnt -= 1
#print(cnt)
for k in list_pd1[1:]:
#print('k:', k)
sN = N
while sN >= k:
if sN%k==0:
sN //= k
else:
sN %= k
if sN == 1:
cnt += 1
print(cnt)
| 0 | null | 79,246,353,908,922 | 259 | 183 |
import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())
from math import ceil
t1, t2 = li()
a1, a2 = li()
b1, b2 = li()
# 交互になる
if (b1 - a1) * t1 + (b2 - a2) * t2 == 0:
print('infinity')
# 高橋君が先を行く
elif (b1 - a1) * t1 + (b2 - a2) * t2 < 0:
# ずっと高橋君の方が速い
if (b1 - a1) * t1 < 0 and (b2 - a2) * t2 < 0:
print(0)
# T2分間は追いつかれる
elif (b1 - a1) * t1 < 0 and (b2 - a2) * t2 > 0:
print(0)
# T1分間は追いつかれる
else:
cross = ceil((b1-a1)*t1 / ((a1-b1)*t1 + (a2-b2)*t2)) - 1
#print(((b1-a1)*t1 + (b2-a2)*t2) * (cross+1) + (a1-b1)*t1)
if ((a1-b1)*t1 + (a2-b2)*t2) * (cross+1) + (a1-b1)*t1 == 0:
print(2* (cross+ 1))
else:
print(2 * cross + 1)
# 高橋君が遅れる
else:
# ずっと高橋君のほうが遅い
if (b1 - a1) * t1 > 0 and (b2 - a2) * t2 > 0:
print(0)
# T2分間は追い上げる
elif (b1 - a1) * t1 > 0 and (b2 - a2) * t2 < 0:
print(0)
# T1分間は追い上げる
else:
cross = ceil((b1-a1)*t1 / ((a1-b1)*t1 + (a2-b2)*t2)) - 1
#print(((a1-b1)*t1 + (a2-b2)*t2) * (cross+1) + (a1-b1)*t1)
if ((a1-b1)*t1 + (a2-b2)*t2) * (cross+1) + (a1-b1)*t1 == 0:
print(2 * (cross + 1))
else:
print(2 * cross + 1)
| import sys
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)
sys.exit()
if A1 * T1 + A2 * T2 == B1 * T1 + B2 * T2:
print('infinity')
sys.exit()
N = (T1 * (A1 - B1) - 1) // (T1 * (B1 - A1) + T2 * (B2 - A2)) + 1
ans = N * 2 - 1
if N * (T1 * (B1 - A1) + T2 * (B2 - A2)) == T1 * (A1 - B1):
ans += 1
print(ans) | 1 | 131,458,584,925,372 | null | 269 | 269 |
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)])
a,b,c = inpm()
k = inp()
for i in range(k):
if b <= a:
b *= 2
elif c <= b:
c *= 2
if a < b < c:
ans = 'Yes'
else:
ans = 'No'
print(ans)
| import math
a, b = list(map(int, input().split()))
for i in range(1, 1250):
p8 = math.floor(i * 0.08)
p10 = math.floor(i * 0.10)
if p8 == a and p10 == b:
print(i)
exit()
print(-1) | 0 | null | 31,756,518,824,970 | 101 | 203 |
a, b, c = map(int, input().split())
d = 0
if a > b:
d = a
a = b
b = d
else: pass
d = 0
if b > c:
d = b
b = c
c = d
else: pass
d = 0
if a > b:
d = a
a = b
b = d
else: pass
print(a, b, c)
| n = int(input())
cl = str(input())
cl_R = cl.count("R")
# print(cl_R)
cl_leftR = cl[:cl_R].count("R")
# print(cl_leftR)
print(cl_R-cl_leftR) | 0 | null | 3,316,875,584,298 | 40 | 98 |
number=list(map(int,input().split()))
count_l=number[0]
count_t=number[1]
luggage=[int(input()) for i in range(count_l)]
min_P=max(max(luggage),sum(luggage)//count_t)
max_P=sum(luggage)
left=min_P
right=max_P
while left<right:
mid=(left+right)//2
count_track=1
flag=1
load=0
for i in range(count_l):
load+=luggage[i]
if load>mid:
count_track+=1
load=luggage[i]
if count_track>count_t:
flag=0
break
if flag:
right=mid
else:
left=mid+1
print(left)
| n, k = map(int, input().split())
W = [int(input()) for _ in range(n)]
def can_load(W, k, q, n):
i = 0
for _ in range(k):
s = 0
while i < n and s + W[i] <= q:
s += W[i]
i += 1
if i == n:
return True
else:
return False
# 積載量をmidと仮定して二分探索
hi = 10 ** 9 # OK
lo = 0 # NG
while hi - lo > 1:
mid = (hi + lo) // 2
if can_load(W, k, mid, n):
hi = mid
else:
lo = mid
print(hi)
| 1 | 87,597,259,112 | null | 24 | 24 |
from math import gcd
n, m = map(int, input().split())
A = list(map(int, input().split()))
A = [a//2 for a in A]
lcm = 1
for i in range(n):
lcm = lcm * A[i] // gcd(lcm, A[i])
if lcm > m:
print(0)
exit()
for a in A:
if lcm // a % 2 == 0:
print(0)
exit()
print((m//lcm + 1) // 2)
| # ABC150D
import sys
input=sys.stdin.readline
from math import gcd,ceil
def main():
N,M=map(int,input().split())
A=list(map(lambda x: int(x)//2,input().split()))
lcm=A[0]
for i in range(1,N):
lcm=lcm*A[i]//gcd(lcm,A[i])
allo=1
for i in range(N):
allo&=(lcm//A[i])%2
if allo:
print(ceil(int(M//lcm)/2))
else:
print(0)
if __name__=="__main__":
main()
| 1 | 101,890,618,393,158 | null | 247 | 247 |
def lcm(x, y):
from fractions import gcd
return (x * y) // gcd(x, y)
a,b = map(int,input().split())
print(lcm(a,b)) | def lcm(x, y):
import math
return (x * y) // math.gcd(x, y)
def abc148c_snack():
a, b = map(int, input().split())
print(lcm(a, b))
abc148c_snack()
| 1 | 113,427,850,132,690 | null | 256 | 256 |
s = []
while True:
hoge = input()
if hoge == '-':
break
num = int(input())
for i in range(num):
h = int(input())
hoge = hoge.replace(hoge,hoge[h:] + hoge[:h])
s += [hoge]
for i in s: print(i) | #coding:utf-8
nyu =""
moji =[]
s1 =[]
s2 =[]
n= 0
a= 0
while nyu != "-":
nyu = input().rstrip()
if nyu =="-":
# print("".join(moji))
break
n = int(input().rstrip())
moji = list(nyu)
for i in range(n):
a = input().rstrip()
s1 =moji[:int(a)]
s2 =moji[int(a):]
moji= list("".join(s2) + "".join(s1))
# print(moji)
print("".join(moji)) | 1 | 1,915,171,175,100 | null | 66 | 66 |
import sys
input = sys.stdin.readline
'''
n, m = map(int, input().split())
n = int(input())
A = list(map(int, input().split()))
for test in range(int(input())):
'''
inf = 100000000000000000 # 1e17
s = input().strip()
if s[2] == s[3] and s[4] == s[5]:
print("Yes")
else:
print("No")
| a,b,c,d,e,f=input()
if c==d and e==f:
print('Yes')
else:
print('No') | 1 | 42,049,391,181,600 | null | 184 | 184 |
s=[_ for _ in input()]
print(''.join(s[:3])) | S = input()
A = ''
P = 0
for s in range(len(S)):
if P < 3:
A += S[s]
P += 1
print(A) | 1 | 14,733,260,872,540 | null | 130 | 130 |
s = input()
l = []
for i in range(len(s)):
l.append(s[i])
if l[len(l)-1] == "s":
print(s+str("es"))
else:
print(s+str("s"))
| h, w = map(int, input().split())
hd, hm, wd, wm = h // 2, h % 2, w // 2, w % 2
s = hd * wd * 2 + hm * wd + wm * hd + hm * wm
if h == 1 or w == 1:
s = 1
print(s)
| 0 | null | 26,644,766,170,528 | 71 | 196 |
n = int(input())
if 360%n:
print(360//(360%n)*(360//n))
else:
print(360//n) | import math
a,b=map(float,input().split())
a=int(a)
b=round(b*100)
print((a*b)//100) | 0 | null | 14,761,884,475,030 | 125 | 135 |
N, K = (int(i) for i in input().split())
l, r = [0]*K, [0]*K
for k in range(K):
l[k], r[k] = (int(x) for x in input().split())
# dp : マスiまで移動する方法のパターン数
# TLE
'''
import numpy as np
dp = [0]*N
dp[0] = 1
for i in range(N):
for k in range(K):
for j in range(l[k], r[k]+1):
if (i+j < N):
dp[i+j] = dp[i+j] + dp[i]
if j == r[k]:
print(i, (l[k], r[k]), dp, np.diff(dp))
print(dp[-1]%998244353)
'''
# dp : マスiまで移動する方法のパターン数
# dps : dp[i] と dp[i+1] の 差
dp = [0]*N
dps = [0]*(N-1)
dp[0] = 1
dps[0] = -1
for i in range(N-1):
for k in range(K):
if i + l[k] - 1 < (N - 1):
dps[i + l[k] - 1] += dp[i]
if i + r[k] < (N - 1):
dps[i + r[k] ] -= dp[i]
#print(i, (l[k], r[k]), dp, dps)
dp[i+1] = (dps[i] + dp[i])%998244353
print(dp[-1]%998244353) | while True:
m,f,r=map(int,input().split())
if m==f==r==-1: break
ret = 'F'
score = m + f
if -1 in (m,f): pass
elif score >= 80: ret = 'A'
elif score >= 65: ret = 'B'
elif score >= 50: ret = 'C'
elif score >= 30:
ret = 'D'
if r >= 50:ret = 'C'
print(ret) | 0 | null | 1,944,176,221,160 | 74 | 57 |
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from collections import defaultdict
def main():
n, x, y = map(int, input().split())
x -= 1
y -= 1
dis = defaultdict(int)
for i1 in range(n):
for i2 in range(i1+1, n):
d = min(abs(i2-i1), abs(x-i1)+abs(y-i2)+1, abs(x-i2)+abs(y-i1)+1)
dis[d] += 1
for k1 in range(1, n):
print(dis[k1])
if __name__ == '__main__':
main() | from collections import deque
n, x, y = map(int, input().split())
inf = 100100100
x -= 1
y -= 1
ans = [0] * n
for i in range(n):
dist = [inf] * n
queue = deque()
queue.append(i)
dist[i] = 0
while queue:
current = queue.popleft()
d = dist[current]
if current - 1 >= 0 and dist[current - 1] == inf:
queue.append(current - 1)
dist[current - 1] = d + 1
if current + 1 < n and dist[current + 1] == inf:
queue.append(current + 1)
dist[current + 1] = d + 1
if current == x and dist[y] == inf:
queue.append(y)
dist[y] = d + 1
if current == y and dist[x] == inf:
queue.append(x)
dist[x] = d + 1
for j in range(n):
ans[dist[j]] += 1
for k in range(1, n):
print(ans[k] // 2)
| 1 | 44,447,186,416,190 | null | 187 | 187 |
import numpy as np
from numba import njit
@njit
def myfunc(n, k, A):
for _ in range(k):
l = np.zeros((n + 1,), dtype=np.int64)
for i, a in enumerate(A[:-1]):
l[max(0, i - a)] += 1
l[min(n, i + a + 1)] -= 1
A = np.cumsum(l)
if np.all(A[:-1] == n):
break
return A
def main():
n, k = map(int, input().split())
A = np.array(list(map(int, input().split())), dtype=np.int64)
A = np.append(A, 0)
print(*myfunc(n, k, A)[:-1])
if __name__ == "__main__":
main() | import sys
def input(): return sys.stdin.readline().rstrip()
def main():
n, k =map(int,input().split())
A = list(map(int,input().split())) + [0]
while k > 0:
B = [0] * (n + 1)
for i, a in enumerate(A):
B[max(0, i - a)] += 1
B[min(n, i + a + 1)] -= 1
if B[0] == n:
flag = True
for i in range(1, n+1):
B[i] += B[i-1]
if B[i] != n and i < n:
flag = False
A = B[:]
if flag:
break
k -= 1
print(" ".join(map(str, B[:-1])))
if __name__=='__main__':
main() | 1 | 15,318,717,370,880 | null | 132 | 132 |
n = int(input())
ans = (n+2-1)//2
print(ans) | print(1-int(input()))
| 0 | null | 31,035,203,850,082 | 206 | 76 |
N = int(input())
A = [int(a) for a in input().split()]
xor = 0
for x in A:
xor ^= x
for v in A:
print(xor^v, end=' ') | N = int(input())
a = list(map(int, input().split()))
x = 0
for r in a:
x ^= r
print(' '.join([str(x^r) for r in a])) | 1 | 12,443,793,640,390 | null | 123 | 123 |
# -*- coding: utf-8 -*-
N = int(input())
if N % 2 == 1:
N += 1
print(N // 2 - 1) | n = int(input())
print(n//2-1 + n % 2) | 1 | 153,791,499,288,992 | null | 283 | 283 |
import math
A, B, N = map(int, input().split())
ans = []
if B-1<N:
sahen = math.floor(A*(B-1)//B)
uhen = math.floor((B-1)//B)
uhen = uhen*A
ans.append(sahen-uhen)
sahen = math.floor(A*N//B)
uhen = math.floor(N//B)
uhen = uhen*A
ans.append(sahen-uhen)
print(max(ans))
| def inN():
return int(input())
def inL():
return list(map(int,input().split()))
def inNL(n):
return [list(map(int,input().split())) for i in range(n)]
a,b,n = inL()
x = min(b-1,n)
print(int(a*x/b)-a*int(x/b))
| 1 | 28,160,948,953,280 | null | 161 | 161 |
import sys
for i in sys.stdin:
a, b = map(int, i.split())
print len(str(a+b)) | # -*- coding: utf-8 -*-
import sys
for s in sys.stdin:
print len(str(int(s.rstrip().split()[0])+int(s.rstrip().split()[1])))
| 1 | 97,373,640 | null | 3 | 3 |
N,M=map(int,input().split())
a=N//2
b=a+1
print(a,b)
if M==1:
exit(0)
c=1
d=N-1
print(c,d)
for i in range(M-2):
if i%2==0:
a,b=a-1,b+1
print(a,b)
else:
c,d=c+1,d-1
print(c,d)
| n=int(input())
l=[0]*(n+1)
for i in range(1,101):
for j in range(1,101):
for k in range(1,101):
s=i**2+j**2+k**2+i*k+i*j+j*k
if(s<=n):
l[s]+=1
for i in range(1,n+1):
print(l[i])
| 0 | null | 18,269,945,319,630 | 162 | 106 |
k=int(input())
if k%2==0 or k%5==0:
print(-1)
else:
i=1
t=7
while t%k!=0:
i+=1
t=(t*10+7)%k
print(i) | import math
a, b, x = map(int, input().split())
if a*a*b >= 2*x:
print(math.degrees(math.atan2(a*b*b,2*x)))
else:
print(math.degrees(math.atan2(2*(a*a*b-x),a**3))) | 0 | null | 84,523,564,359,068 | 97 | 289 |
import sys
def main():
input = sys.stdin.buffer.readline
n = int(input())
ab = [map(int, input().split()) for _ in range(n)]
a, b = [list(i) for i in zip(*ab)]
new_a = sorted(a)
new_b = sorted(b)
if n % 2 == 1:
min_m = new_a[(n + 1) // 2 - 1]
max_m = new_b[(n + 1) // 2 - 1]
print((max_m - min_m) + 1)
else:
min_m = (new_a[n // 2 - 1] + new_a[n // 2])
max_m = (new_b[n // 2 - 1] + new_b[n // 2])
print((max_m - min_m) + 1)
if __name__ == '__main__':
main()
| #distance
import math
x1,y1,x2,y2=map(float,input().split())
distance = math.sqrt((x2-x1)**2+(y2-y1)**2)
print(distance) | 0 | null | 8,661,304,087,930 | 137 | 29 |
def insertionSort(a, n):
print " ".join(map(str, a))
for i in xrange(1, n):
v = a[i]
j = i - 1
# print "i = " + str(i) + ", j = " + str(j)
while j >= 0 and v < a[j]:
a[j + 1] = a[j]
j -= 1
a[j + 1] = v
print " ".join(map(str, a))
n = int(raw_input())
a = map(int, raw_input().split(" "))
insertionSort(a, n) |
def InsertionSort(A, N):
print(*A)
for i in range(1, N):
v = A[i]
j = i - 1
while j >= 0 and A[j] > v:
A[j + 1] = A[j]
j -= 1
A[j + 1] = v
print(*A)
N = int(input())
A = [int(a) for a in input().split()]
InsertionSort(A, N) | 1 | 5,285,231,140 | null | 10 | 10 |
# WA
N = int(input())
A = [int(_) for _ in input().split()]
dp = [1000]
K = [0]
C = [0]
for i in range(N):
k, c = divmod(dp[-1], A[i])
v = dp[-1]
for j in range(i+1):
u = K[j] * A[i] + C[j]
v = max(u, v)
K.append(k)
C.append(c)
dp.append(v)
print(dp[-1])
| n = int(input())
a = list(map(int, input().split()))
money = 1000
kabu = 0
for i in range(n-1):
if a[i] < a[i+1]:
kabu += money//a[i]
money %= a[i]
else:
money += kabu * a[i]
kabu = 0
if kabu > 0:
money += kabu*a[n-1]
print(money) | 1 | 7,375,271,866,138 | null | 103 | 103 |
from collections import defaultdict
def readInt():
return int(input())
def readInts():
return list(map(int, input().split()))
def readChar():
return input()
def readChars():
return input().split()
x = readInt()
for i in range(int(x//105),int(x//100)+2):
t = x-100*i
if 0<=t and t<=5*i:
print(1)
exit()
print(0) | h,w,m=map(int,input().split())
item=[list(map(int,input().split())) for i in range(m)]
row=[0]*h
col=[0]*w
for i in range(m):
x,y=item[i]
row[x-1]+=1
col[y-1]+=1
mr,mc=max(row),max(col)
xr=set([i for i in range(h) if row[i]==mr])
xc=set([i for i in range(w) if col[i]==mc])
check=len(xr)*len(xc)
for i in range(m):
r,c=item[i]
if r-1 in xr and c-1 in xc:
check-=1
print(mr+mc if check>0 else mr+mc-1) | 0 | null | 66,051,286,964,582 | 266 | 89 |
import sys
n = int(sys.stdin.readline())
points = [0, 0]
for i in range(n):
(taro, hanako) = sys.stdin.readline().split()
if taro < hanako:
points[1] += 3
elif taro > hanako:
points[0] += 3
else:
points[0] += 1
points[1] += 1
print(points[0], points[1]) | #!/usr/bin/env python3
from bisect import bisect_right
n, *L = map(int, open(0).read().split())
L.sort()
ans = 0
for i in range(n):
for j in range(i + 1, n):
ans += (bisect_right(L, L[i] + L[j] - 1) -
bisect_right(L, L[j] - L[i]) - 1 - (L[j] - L[i] * 2 < 0))
print(ans // 3)
| 0 | null | 87,130,136,308,046 | 67 | 294 |
n = int(input())
x = [int(i) for i in input().split()]
hp = []
for p in range(min(x), max(x)+1):
sum = 0
for i in x:
sum = sum + (i-p)**2
hp.append(sum)
print(min(hp)) | n,m=map(int,input().split())
#Union-Find木
#par[i]:iの親 deep[i]:iの深さ size[i]:iの大きさ
par=[i for i in range(n)]
deep=[1]*n
size=[1]*n
#親を見つける
def find(x):
if par[x]==x:
return x
else:
return find(par[x])
#二つのグループを統合する
def unite(x,y):
x=find(x)
y=find(y)
if x==y:
return
if deep[x]<deep[y]:
par[x]=y
size[y]+=size[x]
else:
par[y]=x
size[x]+=size[y]
if deep[x]==deep[y]:
deep[x]+=1
#xとyが同じグループに属するかどうか
def same(x,y):
return find(x)==find(y)
#xが属するグループの要素数を返す
def group_count(x):
return size[find(x)]
#連結成分の個数を返す
def count():
check=set()
for i in range(n):
parent=find(i)
if parent not in check:
check.add(parent)
return len(check)
for i in range(m):
a,b=map(int,input().split())
unite(a-1,b-1)
s=count()
print(s-1)
| 0 | null | 33,567,513,584,770 | 213 | 70 |
from sys import stdin, stdout
def main():
N = int(stdin.readline())
A = [0] + list(map(int, stdin.readline().rstrip().split()))
dp = [0] * (N+1)
prefix = [0] * (N+1)
dp[1], prefix[1] = 0, A[1]
for i in range(3, N, 2):
prefix[i] = prefix[i-2]+A[i]
for i in range(2, N+1):
if i & 1:
dp[i] = max(dp[i-1], A[i] + dp[i-2])
else:
dp[i] = max(dp[i-2] + A[i], prefix[i-1])
stdout.write(str(dp[N])+"\n")
main()
| n = int(input())
a = [0]+[int(x) for x in input().split()]
kosuu=[0]*(n+10)
kumiawase=[0]*(n+10)
for i in a:
kosuu[i]+=1
for i in range(n+1):
if kosuu[i]>0:
kumiawase[i]=(kosuu[i]*(kosuu[i]-1))/2
ans=sum(kumiawase)
for i in range(1,n+1):
print(int(ans-(kosuu[a[i]]-1))) | 0 | null | 42,585,640,073,768 | 177 | 192 |
#!/usr/bin/env python3
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()))
def main():
N = II()
A = LI()
A.sort()
MAX = A[-1]+1
All = [0 for i in range(MAX)]
setA = set(A)
for i in A:
k = i
All[k] += 1
k += i
if All[i] == 2:
continue
while k < MAX and i in setA:
All[k] += 1
k += i
ans = 0
for i in range(1, MAX):
if All[i] == 1 and i in setA:
ans += 1
print(ans)
# oj t -c "pypy3 main.py"
# acc s main.py -- --guess-python-interpreter pypy
main()
| n = int(input())
G = {}
D = [-1] * n
for _ in range(n):
A = list(map(int, input().split()))
G[A[0] - 1] = [a - 1 for a in A[2:]]
# print(G)
q = [(0, 0)]
while len(q) > 0:
v, d = q[0]
del q[0]
if D[v] >= 0:
continue
D[v] = d
for nv in G[v]:
q.append((nv, d+1))
for i in range(n):
print(i+1, D[i])
| 0 | null | 7,227,816,936,452 | 129 | 9 |
coffee = input()
if coffee[2] == coffee[3] and coffee[4] == coffee[5]:
print("Yes")
else:
print("No") | import sys
sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline
def solve():
s = input()
if s[2] == s[3] and s[4] == s[5]:
print('Yes')
else:
print('No')
if __name__ == '__main__':
solve()
| 1 | 41,834,860,208,458 | null | 184 | 184 |
import collections
n= int(input())
g=[]
for _ in range(n):
v,k,*varray= map(int,input().split())
g.append(varray)
d= [-1]* (n+10)
d[0]=0
q= collections.deque()
q.append(0)
while len(q)> 0:
cur = q.popleft()
for next in g[cur]:
if d[next-1]== -1:
d[next-1]= d[cur]+1
q.append(next-1)
for i in range(n):
print(i+1,d[i])
| from collections import deque
Q=deque()
n=int(input())
graph={}
d=[0 for i in range(n+1)]
for i in range(n):
tmp=list(map(int,input().split()))
graph[tmp[0]]=[0 for j in range(n+1)]
for j in range(tmp[1]):
graph[tmp[0]][tmp[2+j]]=1
Q.append(1)
while len(Q) is not 0:
number=Q[0]
if 1 in graph[number]:
for i in range(graph[number].count(1)):
Q.append(graph[number].index(1))
if d[graph[number].index(1)] is 0:
d[graph[number].index(1)]=d[number]+1
graph[number][graph[number].index(1)]=0
Q.popleft()
for i in range(n):
if i==0:
print(i+1,0)
else:
if d[i+1]==0:
print(i+1,-1)
else:
print(i+1,d[i+1])
| 1 | 4,414,438,812 | null | 9 | 9 |
while True:
t = input().split()
a = int(t[0])
b = int(t[1])
if (a == 0) and (b == 0):
break
if (a < b):
print(str(a) + " " + str(b))
else:
print(str(b) + " " + str(a)) | while True:
x, y = map(int, raw_input().split())
if x == 0 and y == 0:
break
elif x <= y:
print("%d %d" % (x, y))
elif x > y:
print("%d %d" % (y, x)) | 1 | 508,610,164,042 | null | 43 | 43 |
n=int(input())
ps=[0 for j in range(n+1)]
for i in range(n):
p,d,*vs=[int(j) for j in input().split()]
ps[p]=vs
dist=[-1 for i in range(n+1)]
d=0
queue=[1]
while queue:
pos=queue.pop(0)
if dist[pos] == -1:
dist[pos]=d
for i in ps[pos]:
if dist[i]==-1:
queue.append(i)
dist[i]=dist[pos]+1
for i in range(1,n+1):
print(i,dist[i])
| import collections
N = int(input())
P = [[0 for _ in range(N)] for _ in range(N)]
for i in range(N):
u,k,*varray = map(int,input().split()) # u,k は数, varray は配列
for v in varray:
P[u-1][v-1] = 1
D = [-1 for _ in range(N)]
D[0] = 0 # 始点への距離は 0, 他の距離は-1
Q = collections.deque()
Q.append(0)
while len(Q) > 0:
c = Q.popleft()
for i in range(N):
if P[c][i]==1 and D[i]==-1:
D[i] = D[c]+1
Q.append(i)
for v in range(N):
print(v+1, D[v])
| 1 | 4,135,768,228 | null | 9 | 9 |
import sys
ERROR_INPUT = 'input is invalid'
def main():
n = get_length()
arr = get_array(length=n)
sourtLi, count = selectionSort(li=arr, length=n)
print(*sourtLi)
print(count)
return 0
def get_length():
n = int(input())
if n < 0 or n > 100:
print(ERROR_INPUT)
sys.exit(1)
else:
return n
def get_array(length):
nums = input().split(' ')
return [str2int(string=n) for n in nums]
def str2int(string):
n = int(string)
if n < 0 or n > 100:
print(ERROR_INPUT)
sys.exit(1)
else:
return n
def selectionSort(li, length):
count = 0
for i in range(0, length - 1):
min_index = i
for j in range(i, length):
if li[j] < li[min_index]:
min_index = j
if i != min_index:
li[i], li[min_index] = li[min_index], li[i]
count += 1
return li, count
main() | N = int(raw_input())
A = map(int, raw_input().split())
def selectionSort(A, N):
count = 0
for i in range(0, N):
minj = i
for j in range(i, N):
if A[j] < A[minj]:
minj = j
if i != minj:
temp = A[i]
A[i] = A[minj]
A[minj] = temp
count += 1
return count
count = selectionSort(A, N)
print " ".join(map(str, A))
print count | 1 | 19,307,973,386 | null | 15 | 15 |
print('x'*len(input())) |
ret = [3,14,39,84,155,258,399,584,819,1110]
s = int(input())
print(ret[s-1])
| 0 | null | 41,510,632,067,230 | 221 | 115 |
N,K=map(int,input().split())
A=[int(x)-1 for x in input().split()]
seen={0}
town=0
while K>0:
town=A[town]
K-=1
if town in seen:
break
seen.add(town)
start=town
i=0
while K>0:
town=A[town]
i+=1
K-=1
if town is start:
break
K=K%i if i>0 else 0
while K>0:
town=A[town]
i+=1
K-=1
print(town+1)
| import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)
N, K = mapint()
As = list(mapint())
dv = []
for _ in range(K.bit_length() + 1):
l = [0] * N
dv.append(l)
dv[0] = list(map(lambda x: x-1, As))
for k in range(1, K.bit_length() + 1):
for n in range(N):
dv[k][n] = dv[k - 1][dv[k - 1][n]]
a = []
for i in range(K.bit_length() + 1):
if (K>>i)&1:
a.append(i)
now = 0
for i in a:
now = dv[i][now]
print(now+1) | 1 | 22,699,339,291,530 | null | 150 | 150 |
def main():
x=list(map(int,input().split()))
for i in range(5):
if x[i] == 0:
print(i+1)
main() | a, b, c, d = map(int,input().split())
while True:
c = c - b
a = a - d
if c <= 0:
print('Yes')
break
elif a <= 0:
print('No')
break
else:
pass | 0 | null | 21,549,720,322,978 | 126 | 164 |
from collections import defaultdict
n, k = map(int, input().split())
A = list(map(int, input().split()))
accm = [0] * (n + 1)
for i in range(n):
accm[i + 1] = accm[i] + A[i]
li = [(val - itr) % k for itr, val in enumerate(accm)]
ans = 0
box = defaultdict(int)
for i in range(n + 1):
if i >= k:
box[li[i - k]] -= 1
ans += box[li[i]]
box[li[i]] += 1
print(ans)
| N = int(input())
a = []
b = []
for i in range(N):
x,y = (list(map(int,input().split())))
a.append(x+y)
b.append(x-y)
a.sort()
b.sort()
ans = max(a[-1]-a[0],b[-1]-b[0])
print(ans)
| 0 | null | 70,740,974,852,518 | 273 | 80 |
import re
s = input()
bl = re.fullmatch(r"^(hi)+$", s) is not None
print("Yes" if bl else "No") | N=int(input())
A=["a"]
if N==1:
print("a")
exit()
else:
S="abcdefghijklmn"
slist=list(S)
for i in range(2,N+1):
temp=[[] for _ in range(N)]
for j in range(i-1):
for w in A[j]:
for u in slist[:j+1]:
temp[j].append(w+u)
temp[j+1].append(w+slist[j+1])
A=temp
B=[]
for j in range(N):
for t in A[j]:
B.append(t)
B.sort()
for i in range(len(B)):
print(B[i]) | 0 | null | 52,778,654,365,752 | 199 | 198 |
#!/usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.buffer.readline
INF = 10 ** 9 + 1 # sys.maxsize # float("inf")
def debug(*x):
print(*x, file=sys.stderr)
def solve(N, K, AS):
for _i in range(K):
d = [0] * (N + 1)
for i in range(N):
x = AS[i]
d[max(i - x, 0)] += 1
d[min(i + x + 1, N)] -= 1
cur = 0
ret = [0] * N
for i in range(N):
cur += d[i]
ret[i] = cur
AS = ret
if all(x == N for x in ret):
return ret
return ret
def main():
N, K = map(int, input().split())
AS = list(map(int, input().split()))
print(*solve(N, K, AS))
T1 = """
5 1
1 0 0 1 0
"""
def test_T1():
"""
>>> as_input(T1)
>>> main()
1 2 2 1 2
"""
T2 = """
5 2
1 0 0 1 0
"""
def test_T2():
"""
>>> as_input(T2)
>>> main()
3 3 4 4 3
"""
def _test():
import doctest
doctest.testmod()
def as_input(s):
"use in test, use given string as input file"
import io
global read, input
f = io.StringIO(s.strip())
def input():
return bytes(f.readline(), "ascii")
def read():
return bytes(f.read(), "ascii")
USE_NUMBA = False
if (USE_NUMBA and sys.argv[-1] == 'ONLINE_JUDGE') or sys.argv[-1] == '-c':
print("compiling")
from numba.pycc import CC
cc = CC('my_module')
cc.export('solve', solve.__doc__.strip().split()[0])(solve)
cc.compile()
exit()
else:
input = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
if (USE_NUMBA and sys.argv[-1] != '-p') or sys.argv[-1] == "--numba":
# -p: pure python mode
# if not -p, import compiled module
from my_module import solve # pylint: disable=all
elif sys.argv[-1] == "-t":
print("testing")
_test()
sys.exit()
elif sys.argv[-1] != '-p' and len(sys.argv) == 2:
# input given as file
input_as_file = open(sys.argv[1])
input = input_as_file.buffer.readline
read = input_as_file.buffer.read
main()
| def isKaibun(ss):
return ss==ss[::-1]
s = input()
ans=True
n=len(s)
if not isKaibun(s):
ans=False
if not isKaibun(s[:((n-1)//2)]):
ans=False
if ans:
print("Yes")
else:
print("No")
| 0 | null | 30,713,072,149,248 | 132 | 190 |
for i in range(1,10):
for j in range(1,10):
a=i*j
print(f'{i}x{j}={a}')
| x = list(map(int, input().split()))
if 0 in x:
ans = x.index(0) + 1
print(ans) | 0 | null | 6,781,320,018,512 | 1 | 126 |
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import fractions
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)
#2で何回割れるかを数える関数
def t_per2(k):
return format(k,'b')[::-1].find('1')
def main():
n,m = map(int,ipt().split())
a = [int(i) for i in ipt().split()]
k2 = t_per2(a[0])
l = a[0]//2
for ai in a[1::]:
if not k2 == t_per2(ai):
print(0)
exit()
l = l*(ai//2)//(fractions.gcd(l,ai//2))
if l > m:
print(0)
exit()
print((m+l)//(2*l))
return
if __name__ == '__main__':
main()
| # 最大公約数
def gcd(a, b):
while b != 0:
a, b = b, a % b
return a
# 最小公倍数
def lcm(a, b):
return a * b // gcd(a, b)
N, M = map(int, input().split())
A = list(map(int, input().split()))
cnt = [0] * N
for i in range(N):
a = A[i]
while a % 2 == 0:
a = a // 2
cnt[i] += 1
if len(set(cnt)) != 1:
print(0)
exit()
x = A[0] // 2
for a in A[1:]:
x = lcm(x, a // 2)
ans = M // x
print(ans - ans // 2) | 1 | 101,301,893,184,998 | null | 247 | 247 |
s, w = list(map(int, input().split()))
output = "safe"
if s <= w:
output = "un" + output
print(output) | N = int(input())
dp = [[0]*10 for _ in range(10)]
for i in range(1, N+1):
if i%10==0: continue
strI = str(i)
f,l = strI[-1], strI[0]
dp[int(f)][int(l)] += 1
res = 0
for i in range(1,10):
for j in range(1,10):
res += dp[i][j] * dp[j][i]
print(res) | 0 | null | 57,982,050,999,272 | 163 | 234 |
def report(k, r):
print('{} x {}'.format(k, r[k]))
ans = {'AC': 0, 'WA': 0, 'TLE': 0, 'RE': 0}
N = int(input().rstrip())
for i in range(N):
S = input().rstrip()
ans[S] += 1
report('AC', ans)
report('WA', ans)
report('TLE', ans)
report('RE', ans)
| import numpy as np
n=int(input())
a=np.array([0]*4)
for i in range(n):
s= str(input())
if s=='AC':
a[0]+=1
elif s=='WA':
a[1]+=1
elif s=='TLE':
a[2]+=1
elif s=='RE':
a[3]+=1
print('AC x '+str(a[0]))
print('WA x '+str(a[1]))
print('TLE x '+str(a[2]))
print('RE x '+str(a[3])) | 1 | 8,632,115,249,840 | null | 109 | 109 |
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import collections
import functools
import itertools
import math
import sys
INF = float('inf')
def solve(X: int):
return X//500*1000 + X % 500//5*5
def main():
sys.setrecursionlimit(10 ** 6)
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
X = int(next(tokens)) # type: int
print(f'{solve(X)}')
if __name__ == '__main__':
main()
| import math
a, b, C = map(float, input().split())
S = (a * b * math.sin(math.radians(C))) / 2
L = a + b + (math.sqrt(a**2 + b**2 - 2*a*b*math.cos(math.radians(C))))
h = b * math.sin(math.radians(C))
print("{:.8f}".format(S))
print("{:.8f}".format(L))
print("{:.8f}".format(h))
| 0 | null | 21,561,562,763,468 | 185 | 30 |
#a=int(input())
#b,c=int(input()),int(input())
# c=[]
# for i in b:
# c.append(i)
H,N = map(int,input().split())
f = list(map(int,input().split()))
#j = [input() for _ in range(a)]
# h = []
# for i in range(e1):
# h.append(list(map(int,input().split())))
if sum(f)>=H:
print("Yes")
else:
print("No") | s = list(input())
num = 0
n = len(s)
l = []
i = 0
while i < n:
if s[i] == '<':
l.append(num)
num+=1
i+=1
if i==n:
l.append(num)
else:
cur = 0
while i < n and s[i]=='>':
i+=1
cur+=1
if cur <= num:
l.append(num)
cur-=1
l.append((cur*(cur+1))//2)
num = 0
print(sum(l)) | 0 | null | 116,955,687,861,090 | 226 | 285 |
n,m = map(int,input().split())
#行列a、ベクトルb、行列積cの初期化
a = [0 for i in range(n)]
b = [0 for j in range(m)]
c = []
#a,bの読み込み
for i in range(n):
a[i] = input().split()
a[i] = [int(x) for x in a[i]]
for j in range(m):
b[j] = int(input())
#行列積計算
temp = 0
for i in range(n):
for j in range(m):
temp += a[i][j]*b[j]
c.append(temp)
temp = 0
#結果の表示
for num in c:print(num)
| n,m = [int(x) for x in input().split()]
a=[]
b=[]
for i in range(n): a.append([int(x) for x in input().split()])
for j in range(m): b.append(int(input()))
for a_row in a:
print(sum([x*y for x,y in zip(a_row,b)]))
| 1 | 1,174,675,236,948 | null | 56 | 56 |
H = int(input())
W = int(input())
N = int(input())
A_div, A_mod = divmod(N, H)
if A_mod != 0:
A_div += 1
B_div, B_mod = divmod(N, W)
if B_mod != 0:
B_div += 1
print(min(A_div, B_div)) | import sys
def input(): return sys.stdin.readline().rstrip()
def main():
h=int(input())
w=int(input())
n=int(input())
print(-(-n//max(h,w)))
if __name__=='__main__':
main() | 1 | 88,333,316,411,168 | null | 236 | 236 |
n, m = map(int, input().split())
if n % 2 == 1:
a = [i for i in range(1, m+1)]
b = [i for i in reversed(range(m+1, 2*m+1))]
ab = [(x, y) for x, y in zip(a, b)]
else:
ab = []
x, y = (n-1)//2, n//2
if x % 2 != 0:
x, y = y, x
evenl = 1
evenr = x
while evenl < evenr:
ab.append((evenl, evenr))
evenl += 1
evenr -= 1
oddl = x+1
oddr = n-1
while oddl < oddr:
ab.append((oddl, oddr))
oddl += 1
oddr -= 1
ab = ab[:m]
for a, b in ab:
print(a, b) | N, M = map(int, input().split())
ans = []
n = M // 2
m = 2 * n + 1
l = 2 * M + 1
for i in range(n):
ans.append([i + 1, m - i])
for i in range(M - n):
ans.append([m + i + 1, l - i])
for v in ans:
print(*v)
| 1 | 28,775,893,673,152 | null | 162 | 162 |
X,Y,Z = map(str,input().split())
print(Z+' '+X+' '+Y) | def ABC_swap():
# 入力
X, Y, Z = map(int, input().split())
A = X
B = Y
C = Z
# 入れ替え処理
A, B = B, A
A, C = C, A
# 表示
print(A, B, C)
ABC_swap() | 1 | 38,130,395,637,478 | null | 178 | 178 |
#coding: utf-8
#ALDS1_2B
def pnt(s):
for i in xrange(len(s)):
print s[i],
print
n=int(raw_input())
a=map(int,raw_input().split())
cnt=0
for i in xrange(n):
mini = i
for j in xrange(i + 1, n):
if a[j] < a[mini]:
mini = j
if i != mini:
a[i], a[mini] = a[mini], a[i]
if i!=mini:
cnt+=1
pnt(a)
print cnt | s = raw_input()
if s == 'ABC':
print 'ARC'
else:
print 'ABC' | 0 | null | 12,047,435,145,240 | 15 | 153 |
H = ''
W = ''
i = j = 0
while True:
line = input()
line = line.split()
H = int(line[0])
W = int(line[1])
if H == 0 and W == 0:
break
while i < H:
if i == 0 or i == H-1:
print('#'*W)
else:
print('#',end='')
print('.'*(W-2),end='')
print('#')
i += 1
i = 0
print() | while True:
h,w=map(int,input().split())
if h==0 and w==0:
break
for i in range(h):
for j in range(w):
if i==0 or j==0 or i==h-1 or j==w-1:
print("#",end="")
else:
print(".",end="")
print("")
print("")
| 1 | 836,717,522,652 | null | 50 | 50 |
def f(c):
"""
入力に対する勝ち手を出力
"""
if c=="r":
return "p"
elif c=="s":
return "r"
else:
return "s"
def main():
"""
まずは全て勝つ組み合わせを作って、合計ポイントを求める。
iを0からN-Kまで変化させ、T(i)=T(k+i)となる時、
T(k+i)をT(i)、T(i+2K)と異なる手に変更する。
※T(i)を変更すると、T(i)=T(i+k)=T(i+2K)=...=と連続した時に、
全て変更されてスコアが最大にならない。
T(k+i)は勝ちから"あいこまたは負け"に変化するので、合計ポイントから差っ引く。
"""
#input
N,K=map(int,input().strip().split())
R,S,P=map(int,input().strip().split())
T=list(input())
win_T=list(map(lambda x:f(x),T))
point={"r":R,"s":S,"p":P}
score=sum([point[win_T[n]] for n in range(N)])
for i in range(N-K):
l=["r","s","p"]
if win_T[i]==win_T[i+K]:
score-=point[win_T[i+K]]
l.remove(win_T[i])
if i<=N-2*K-1 and win_T[i]!=win_T[i+2*K]:
l.remove(win_T[i+2*K])
win_T[i+K]=l[0]
return score
if __name__=="__main__":
print(main()) | N = int(input())
X = list(map(int, input().split()))
P = round(sum(X)/N)
ans = sum(list(map(lambda x: (x-P)**2, X)))
print(ans) | 0 | null | 85,644,636,529,110 | 251 | 213 |
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=998244353
N,M,K=MI()
def cmb(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
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)
p=[1]*(N+3)#(M-1)^i
for i in range(N+2):
p[i+1]=(p[i]*(M-1))%mod
ans=0
for i in range(K+1):
temp=M*p[N-1-i]*cmb(N-1,i,mod)
temp%=mod
ans=(ans+temp)%mod
print(ans)
main()
| def combs_mod(n,k,mod):
#nC0からnCkまで
inv = [1]*(k+1)
for i in range(1,k+1):
inv[i] = pow(i,mod-2,mod)
ans = [1]*(k+1)
for i in range(1,k+1):
ans[i] = ans[i-1]*(n+1-i)*inv[i]%mod
return ans
def solve():
ans = 0
mod = 998244353
N, M, K = map(int, input().split())
top = min(K,N-1)
combs = combs_mod(N-1,top,mod)
for k in range(top+1):
ans += M*combs[k]*pow(M-1,N-1-k,mod)
ans %= mod
return ans
print(solve()) | 1 | 23,200,592,030,780 | null | 151 | 151 |
from collections import Counter
s = input()
ls = len(s)
t = [0]
j = 1
for i in range(ls):
u = (int(s[ls-1-i])*j + t[-1]) % 2019
t.append(u)
j = (j * 10) % 2019
c = Counter(t)
k = list(c.keys())
ans = 0
for i in k:
ans += c[i]*(c[i]-1)/2
print(int(ans)) | # -*- coding: utf-8 -*-
def selection_sort(n, a):
cnt = 0
for i in range(n):
minj = i
for j in range(i, n):
if a[j] < a[minj]:
minj = j
if i != minj:
tmp = a[minj]
a[minj] = a[i]
a[i] = tmp
cnt += 1
return a, cnt
if __name__ == '__main__':
n = int(input())
a = [int(n) for n in input().split()]
ans, cnt = selection_sort(n, a)
print(' '.join(map(str, ans)))
print(cnt) | 0 | null | 15,367,331,456,410 | 166 | 15 |
import sys
import collections
import bisect
readline = sys.stdin.readline
def main():
n = int(readline().rstrip())
aList = sorted(list(map(int, readline().rstrip().split())))
z = [0] * n
for a in aList:
z[a-1] += 1
for i in range(n):
print(z[i])
if __name__ == '__main__':
main()
| #!/usr/bin/env python3
import sys
from itertools import chain
def solve(N: int, A: "List[int]"):
s = [0 for _ in range(N)]
for Ai in A:
s[Ai - 1] += 1
return "\n".join(map(str, s))
def main():
tokens = chain(*(line.split() for line in sys.stdin))
N = int(next(tokens)) # type: int
A = [
int(next(tokens)) for _ in range(N - 2 + 1)
] # type: "List[int]"
answer = solve(N, A)
print(answer)
if __name__ == "__main__":
main()
| 1 | 32,494,284,082,920 | null | 169 | 169 |
import math
x1, y1, x2, y2 = map(float, input().split())
x = abs(x1 - x2)
y = abs(y1 - y2)
ans = math.sqrt(x**2 + y**2)
print('{:.5f}'.format(ans))
| import math
x1, y1, x2, y2 = map(float, raw_input().split())
L = math.sqrt((x1-x2)**2 + (y1-y2)**2)
print L | 1 | 156,092,698,608 | null | 29 | 29 |
S, T = input().split()
A, B = map(int, input().split())
U = input()
if U == S:
print("%d %d" % (A-1, B))
else:
print("%d %d" % (A, B-1)) | import os, sys, re, math
(S, T) = [n for n in input().split()]
(A, B) = [int(n) for n in input().split()]
U = input()
if U == S:
A -= 1
else:
B -= 1
print('%s %s' % (A, B))
| 1 | 71,815,412,799,228 | null | 220 | 220 |
input_line = input().split(" ")
S = int(input_line[0])
W = int(input_line[1])
if S > W:
print("safe")
else:
print("unsafe") | #!/usr/bin/env python3
def solve(S: int, W: int):
if W >= S:
return "unsafe"
return "safe"
def main():
S, W = map(int, input().split())
answer = solve(S, W)
print(answer)
if __name__ == "__main__":
main()
| 1 | 29,243,454,303,492 | null | 163 | 163 |
from itertools import permutations
import math
n = int(input())
x,y = [],[]
for _ in range(n):
x_, y_ =map(int,input().split())
x.append(x_)
y.append(y_)
c = list(permutations([i for i in range(1,n+1)],n))
g = [[-1]*(n+1) for _ in range(n+1)]
sum = 0
for ci in (c):
tmp = 0
for i in range(len(ci)-1):
if g[ci[i]][ci[i+1]] == -1:
tmp += math.sqrt((x[ci[i]-1]-x[ci[i+1]-1])**2
+ (y[ci[i]-1]-y[ci[i+1]-1])**2)
else:
tmp += g[ci[i]][ci[i+1]]
sum += tmp
print(sum/len(c)) | n = int(input())
xy = [list(map(int, input().split())) for i in range(n)]
def distance(i, j):
xi, yi = xy[i]
xj, yj = xy[j]
return (xi-xj)**2 + (yi-yj)**2
visited = [False] * n
ans = 0
def dfs(route, length):
global ans
if len(route)==n:
ans += length
return
else:
for i in range(n):
if visited[i]: continue
next_distance = distance(route[-1], i)**0.5
visited[i] = True
dfs(route+[i], length+next_distance)
visited[i] = False
cnt = 1
for i in range(n):
cnt*=i+1
visited[i] = True
dfs([i], 0)
visited[i] = False
print(ans/cnt)
| 1 | 148,966,035,375,430 | null | 280 | 280 |
while True:
data = input()
if data == '0':
break
sum = 0
for c in data:
sum += int(c)
print(sum) | N = input()
K = int(input())
if len(N) < K:
print(0)
exit()
ans = [1, int(N[-1]), 0, 0];
def combination(N,K):
if N < K:
return 0
else:
p = 1
for k in range(K):
p *= N
N -= 1
for k in range(1, K+1):
p //= k
return p
for k in range(1, len(N)):
if int(N[-k-1]) > 0:
a = [1, 0, 0, 0]
for j in range(1, K+1):
a[j] += (9**(j))*combination(k, j)
a[j] += (int(N[-k-1])-1)*combination(k, j-1)*(9**(j-1)) + ans[j-1]
ans = a
print(ans[K]) | 0 | null | 38,618,287,470,770 | 62 | 224 |
def showrooms(building,floor,rooms):
for x in xrange(0,floor):
for y in xrange(0,rooms):
if y==0:
print "",
print building[x][y],
elif y ==rooms-1:
print building[x][y]
else:
print building[x][y],
FLOOR = 3
ROOMS = 10
n = input()
building1 = [[0 for i in range(ROOMS)] for j in range(FLOOR)]
building2 = [[0 for i in range(ROOMS)] for j in range(FLOOR)]
building3 = [[0 for i in range(ROOMS)] for j in range(FLOOR)]
building4 = [[0 for i in range(ROOMS)] for j in range(FLOOR)]
# for x in xrange(0,n):
for x in xrange(0,n):
b,f,r,v = map(int,raw_input().split())
f=f-1
r=r-1
if b==1:
building1[f][r] += v
elif b==2:
building2[f][r] += v
elif b==3:
building3[f][r] += v
elif b==4:
building4[f][r] += v
else:
print "your input is invalid format."
break
showrooms(building1,FLOOR,ROOMS)
print "####################"
showrooms(building2,FLOOR,ROOMS)
print "####################"
showrooms(building3,FLOOR,ROOMS)
print "####################"
showrooms(building4,FLOOR,ROOMS) | N = int(input())
m=[]
line = ''
m = [[[0 for k in range(10)] for j in range(3)] for i in range(10)]
for i in range(N):
n = input().split()
b = int(n[0])
f = int(n[1])
r = int(n[2])
v = int(n[3])
m[b-1][f-1][r-1] += v
for i in range(4):
for j in range(3):
for k in range(10):
line += ' {0}'.format(m[i][j][k])
print(line)
line = ''
if i < 3:
print('#'*20) | 1 | 1,084,124,811,418 | null | 55 | 55 |
X = raw_input()
S1 = []
S2 = []
total = 0
for i, x in enumerate(X):
if x == '\\':
S1.append(i)
elif x == '/' and len(S1) > 0:
left = S1.pop()
s = i - left
total += s
while len(S2) > 0:
prev = S2.pop()
if prev[0] < left:
S2.append(prev)
break
else:
s += prev[1]
S2.append((left, s))
print total
result = [len(S2)]
for i in S2:
result.append(i[1])
print ' '.join(map(str, result)) | g = list(input())
sum, d, r, p = 0, 0, 0, 0
f = 0
lake_list = []
for c in g:
if c == "\\":
if f == 0:
f, d, r = 1, 1, 1
else:
d += 1
r += (1 + (d-1))
elif c == "_":
if f == 1:
r += d
else:
if f == 1:
d -= 1
r += d
if d == 0:
f = 0
sum += r
lake_list.append([p, r])
r = 0
p += 1
d, r, p = 0, 0, len(g)-1
f = 0
g.reverse()
for c in g:
if c == "/":
if f == 0:
f, d, r = 1, 1, 1
pr = p
else:
d += 1
r += (1 + (d-1))
elif c == "_":
if f == 1:
r += d
else:
if f == 1:
d -= 1
r += d
if d == 0:
if [pr, r] not in lake_list:
sum += r
lake_list.append([pr, r])
f = 0
r = 0
p -= 1
lake_list.sort()
print(sum)
print(len(lake_list), end="")
i = 0
while i != len(lake_list):
print(" {}".format(lake_list[i][1]), end="")
i += 1
print()
| 1 | 56,857,618,552 | null | 21 | 21 |
h = int(input())
w = int(input())
n = int(input())
if n % max(h, w) == 0:
print(n // max(h,w))
elif n % max(h,w) !=0 :
print(n // max(h, w) + 1) | import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
return list(map(int,input().split()))
def m(): #複数文字
return map(int,input().split())
def onem(): #Nとかの取得
return int(input())
def s(x): #圧縮
a = []
if len(x) == 0:
return []
aa = x[0]
su = 1
for i in range(len(x)-1):
if aa != x[i+1]:
a.append([aa,su])
aa = x[i+1]
su = 1
else:
su += 1
a.append([aa,su])
return a
def jo(x): #listをスペースごとに分ける
return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
return max(map(max,x))
def In(x,a): #aがリスト(sorted)
k = bs.bisect_left(a,x)
if k != len(a) and a[k] == x:
return True
else:
return False
def pow_k(x, n):
ans = 1
while n:
if n % 2:
ans *= x
x *= x
n >>= 1
return ans
def nibu(x,n,r):
ll = 1
rr = r
while True:
mid = (ll+rr)//2
if rr == mid:
return ll
if cou(x,mid) <= n:
rr = mid
else:
ll = mid+1
def cou(x,le):
co = 0
for i in range(len(x)):
if le != 0:
co += -(-x[i]//le) - 1
return co
n,k = m()
a = l()
left = 0
right = 10**9
aaa = nibu(a,k,right)
print(aaa)
| 0 | null | 47,404,882,924,800 | 236 | 99 |
a,b =map(str, input().split())
print(str(b+a)) | w = input()
t = []
count = 0
while True:
line = input()
if line == 'END_OF_TEXT':
break
for x in line.split():
if w.lower() == x.lower():
count += 1
print(count) | 0 | null | 52,589,731,662,846 | 248 | 65 |
H, W = map(int, input().split())
stage = []
scores = []
for _ in range(H):
stage.append(list(input()))
scores.append([float('inf')] * W)
if stage[0][0] == '#':
scores[0][0] = 1
else:
scores[0][0] = 0
move = [[0, 1], [1, 0]]
for y in range(H):
for x in range(W):
for dx, dy in move:
nx, ny = x + dx, y + dy
if H <= ny or W <= nx:
continue
if stage[ny][nx] == '#' and stage[y][x] == '.':
scores[ny][nx] = min(scores[ny][nx], scores[y][x] + 1)
else:
scores[ny][nx] = min(scores[ny][nx], scores[y][x])
# print(*scores, sep='\n')
print(scores[-1][-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,459,887,219,252 | null | 194 | 194 |
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)
class Graph():
def __init__(self, v):
from heapq import heappop, heappush
self.v = v
self.graph = [[] for _ in range(v)]
self.INF = 10 ** 9
def addEdge(self, start, end, itr):
self.graph[start].append((end, itr))
self.graph[end].append((start, itr))
def BFS(self, start):
from collections import deque
dist = [-1] * self.v
ret = [0] * (self.v-1)
que = deque()
que.append((start, -1))
dist[start] = 0
while que:
now, _color = que.popleft()
color = 1
if _color == color: color += 1
for to, itr in self.graph[now]:
if dist[to] == -1:
que.append((to, color))
dist[to] = dist[now] + 1
ret[itr] = color
color += 1
if color == _color: color += 1
return ret
def color_types(self):
ret = len(self.graph[0])
for x in self.graph[1:]:
ret = max(ret, len(x))
return ret
def Main():
n = read_int()
g = Graph(n)
for i in range(n - 1):
a, b = read_ints()
g.addEdge(~-a, ~-b, i)
print(g.color_types())
print(*g.BFS(0), sep='\n')
if __name__ == '__main__':
Main() | import sys
args = input()
print(args[:3]) | 0 | null | 75,182,040,579,620 | 272 | 130 |
from sys import stdin
a, b, c = (int(n) for n in stdin.readline().rstrip().split())
cnt = 0
for n in range(a, b + 1):
if c % n == 0:
cnt += 1
print(cnt)
| x = input().split(" ")
a = 0
for i in range(int(x[0]),int(x[1]) + 1):
if int(x[2]) % int(i) == 0:
a += 1
print(a)
| 1 | 560,585,857,312 | null | 44 | 44 |
# ABC162F - Select Half
import sys
input = sys.stdin.buffer.readline
def main():
n=int(input())
a=list(map(int,input().split()))
if n<4:
print(max(a))
sys.exit()
if n%2:
#dp[位置][個数]
dp=[[0,0,0]for i in range(n-2)]
dp[0]=a[:3]
for i in range(2,n-1,2):
dp[i][0]=dp[i-2][0]+a[i]
dp[i][1]=max(dp[i-2][0],dp[i-2][1])+a[i+1]
dp[i][2]=max(dp[i-2][0],dp[i-2][1],dp[i-2][2])+a[i+2]
print(max(dp[-1]))
else:
#dp[位置][個数]
dp=[[0,0]for i in range(n-1)]
dp[0]=a[:2]
for i in range(2,n-1,2):
dp[i][0]=dp[i-2][0]+a[i]
dp[i][1]=max(dp[i-2][0],dp[i-2][1])+a[i+1]
print(max(dp[-1]))
main() | n = int(input())
a = list(map(int, input().split()))
INF = 10 ** 18
if n % 2:
dp = [[[-INF,-INF,-INF] for i in range(2)] for i in range(n+1)]
dp[0][0][0] = 0
# 初期化条件考える
for i,v in enumerate(a):
for j in range(2):
if j:
dp[i+1][0][0] = max(dp[i+1][0][0],dp[i][1][0])
dp[i+1][0][1] = max(dp[i+1][0][1],dp[i][1][1])
dp[i+1][0][2] = max(dp[i+1][0][2],dp[i][1][2])
else:
dp[i+1][1][0] = max(dp[i+1][1][0],dp[i][0][0] + v)
dp[i+1][0][1] = max(dp[i+1][0][1],dp[i][0][0])
dp[i+1][1][1] = max(dp[i+1][1][1],dp[i][0][1] + v)
dp[i+1][0][2] = max(dp[i+1][0][2],dp[i][0][1])
dp[i+1][1][2] = max(dp[i+1][1][2],dp[i][0][2] + v)
print(max(max(dp[n][0]),max(dp[n][1][1:])))
else:
odd_sum,even_sum = 0,0
cumsum = []
for k,v in enumerate(a):
if k % 2:
odd_sum += v
cumsum.append(odd_sum)
else:
even_sum += v
cumsum.append(even_sum)
ans = max(cumsum[n-2],cumsum[n-1])
for i in range(2,n,2):
ans = max(ans, cumsum[i-2]+cumsum[n-1]-cumsum[i-1])
print(ans) | 1 | 37,307,903,144,314 | null | 177 | 177 |
import sys
read = sys.stdin.read
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 a in A:
if a == R == G == B:
ans *= 3
ans %= MOD
R += 1
else:
if a == R == G:
ans *= 2
ans %= MOD
R += 1
elif a == G == B:
ans *= 2
ans %= MOD
G += 1
elif a == B == R:
ans *= 2
ans %= MOD
B += 1
else:
if a == R:
R += 1
elif a == G:
G += 1
elif a == B:
B += 1
else:
print(0)
sys.exit()
print(ans % MOD)
if __name__ == '__main__':
main()
| N = int(input())
memo = []
memo = [1,1] + [0] * (N - 1)
def f(n):
if memo[n] == 0:
memo[n] = f(n-1) + f(n-2)
return(memo[n])
if memo[n] != 0:
return(memo[n])
print(f(N))
| 0 | null | 65,014,259,887,452 | 268 | 7 |
def main():
n = int(input())
s = input()
r_set, g_set, b_set = set(), set(), set()
for i, c in enumerate(s):
if c == "R":
r_set.add(i)
elif c == "G":
g_set.add(i)
elif c == "B":
b_set.add(i)
cnt = 0
for j in range(1, n):
for i in range(j):
k = 2 * j - i
if k >= n:
continue
if s[i] == s[j] or s[j] == s[k] or s[k] == s[i]:
continue
cnt += 1
print(len(r_set) * len(g_set) * len(b_set) - cnt)
if __name__ == "__main__":
main()
| # -*- coding: utf-8 -*-
N = int(input().strip())
XL_list = [list(map(int, input().rstrip().split())) for i in range(N)]
#-----
section = []
for X,L in XL_list:
section.append( ( X - L , X + L ) )
section.sort(key= lambda x: x[1])
prev_tail = -float("inf")
cnt = 0
for left,right in section:
if prev_tail <= left:
cnt += 1
prev_tail = right
print(cnt)
| 0 | null | 63,283,599,694,400 | 175 | 237 |
n,p=map(int,input().split())
s=list(input())
if p==2 or p==5:
ans=0
for i in range(n):
if int(s[n-i-1])%p==0:
ans+=n-i-1+1
print(ans)
exit()
mods=[0]*p
mods[0]=1
num=0
fac=1
for i in range(n):
num+=(int(s[n-i-1])*fac)
num%=p
fac=(fac*10)
fac%=p
mods[num]+=1
#print(mods)
ans=0
for item in mods:
ans+=(item*(item-1))//2
#print(len(s))
#print(mods)
print(ans)
| from collections import defaultdict
import sys
def input():return sys.stdin.readline().strip()
def main():
N, P = map(int, input().split())
S = input()
ans = 0
if P in [2, 5]:
for i, c in enumerate(S[::-1]):
if int(c) % P == 0:
ans += N-i
else:
d = defaultdict(int)
d[0] = 1
num = 0
ten = 1
for c in S[::-1]:
num += int(c) * ten
num %= P
d[num] += 1
ten *= 10
ten %= P
ans = sum([d[i]*(d[i]-1)//2 for i in range(P)])
print(ans)
if __name__ == "__main__":
main() | 1 | 58,024,934,897,520 | null | 205 | 205 |
n, m, l = map(int, input().split())
a = []
b = []
c = []
for i in range(n):
ai = list(map(int, input().split()))
a.append(ai)
for i in range(m):
bi = list(map(int, input().split()))
b.append(bi)
for i in range(n):
ci = []
for j in range(l):
cij = 0
for k in range(m):
cij += a[i][k] * b[k][j]
ci.append(cij)
c.append(ci)
for i in range(n):
print(" ".join(list(map(str, c[i])))) | n, m, l = map(int, raw_input().split())
matrix_a = []
matrix_b = []
for i in range(n):
line = map(int, raw_input().split())
matrix_a.append(line)
for i in range(m):
line = map(int, raw_input().split())
matrix_b.append(line)
for i in range(n):
result = []
for j in range(l):
tmp = 0
for k in range(m):
tmp += matrix_a[i][k] * matrix_b[k][j]
result.append(tmp)
print " ".join(map(str, result)) | 1 | 1,405,667,615,678 | null | 60 | 60 |
h, a = map(int,input().split())
print(h//a + min(h%a,1))
| #!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: A
# CreatedDate: 2020-06-27 15:30:40 +0900
# LastModified: 2020-06-27 15:33:43 +0900
#
import os
import sys
# import numpy as np
# import pandas as pd
def main():
h, a = map(int, input().split())
if float(h/a).is_integer():
print(h//a)
else:
print(h//a+1)
if __name__ == "__main__":
main()
| 1 | 77,057,939,049,700 | null | 225 | 225 |
while True:
H, W = list(map(int, input().split()))
if H == 0 and W == 0:
break
for h in range(H):
for w in range(W):
if w == (W - 1):
print('#')
break
print('#', end="")
print()
| N = int(input())
a = [int(x) for x in input().split()]
MOD = 10**9 + 7
ans = 1
lst = [0] * 3
for aa in a:
cnt = 0
j = -1
for i, l in enumerate(lst):
if l == aa:
cnt += 1
j = i
if j == -1:
ans = 0
break
ans *= cnt
ans %= MOD
lst[j] += 1
print(ans) | 0 | null | 65,494,483,480,670 | 49 | 268 |
X, Y, A, B, C = map(int, input().split())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
R = list(map(int, input().split()))
P.sort()
Q.sort()
R.sort()
P = P[::-1]
Q = Q[::-1]
R = R[::-1]
D = P[:X] + Q[:Y] + R
D.sort()
D = D[::-1]
D = D[:X+Y]
ans = sum(D)
print(ans) | import sys
sys.setrecursionlimit(10**9)
def main():
X,Y,A,B,C = map(int,input().split())
P = sorted(list(map(int,input().split())),reverse=True)
Q = sorted(list(map(int,input().split())),reverse=True)
R = list(map(int,input().split()))
print(sum(sorted(P[:X]+Q[:Y]+R,reverse=True)[:X+Y]))
if __name__ == "__main__":
main()
| 1 | 44,916,082,948,968 | null | 188 | 188 |
n=int(input())
a=list(map(int,input().split()))
for i in range(n):
if a[i]%2==0:
if (a[i]%3==0 or a[i]%5==0): pass
else: print('DENIED'); exit()
print('APPROVED') | n = int(input())
l = list(map(int, input().split()))
mod_check=0
mod_check_ =0
for i in l:
if i % 2 == 0 :
mod_check += 1
if i % 3 == 0 or i % 5 == 0:
mod_check_ += 1
else:
pass
else:
pass
print('APPROVED') if mod_check==mod_check_ else print('DENIED')
| 1 | 69,047,532,095,740 | null | 217 | 217 |
# 41m AC
from collections import Counter
import sys
def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()
INF = float('inf')
n = I()
if n % 2 != 0:
print(0)
exit()
ans = 0
i = 10
while i <= n:
ans += n // i
i *= 5
print(ans)
| A,B = map(int,input().split())
print(max(0,A-B*2)) | 0 | null | 141,450,137,476,220 | 258 | 291 |
N=int(input());a=10;b=0
if N&1==0:
while a<=N:b+=N//a;a*=5
print(b) | n = int(input())
if n % 2 == 1:
print(0)
quit()
d = 10
ans = 0
while n >= d:
ans += n // d
d *= 5
print(ans) | 1 | 116,047,169,979,572 | null | 258 | 258 |
from collections import defaultdict
def main():
N, P = map(int, input().split())
S = list(map(int,list(input())))
S_mod = [0] * N
if P == 2:
for i in range(N-1,-1,-1):
if S[i] % 2 == 0:
S_mod[i] = 1
S_mod.reverse()
ans = 0
cnt = 0
for i in range(N):
if S_mod[i] == 1:
cnt += 1
ans += cnt
else:
ans += cnt
print(ans)
exit()
if P == 5:
for i in range(N-1,-1,-1):
if S[i] % 5 == 0:
S_mod[i] = 1
S_mod.reverse()
ans = 0
cnt = 0
for i in range(N):
if S_mod[i] == 1:
cnt += 1
ans += cnt
else:
ans += cnt
print(ans)
exit()
ten = 1
for i in range(N-1,-1,-1):
S_mod[i] = (S[i] * ten) % P
ten *= 10
ten %= P
S_mod.reverse()
S_acc = [0] * (N+1)
for i in range(N):
S_acc[i+1] = (S_acc[i] + S_mod[i]) % P
d = defaultdict(int)
for i in range(N+1):
d[S_acc[i]] += 1
ans = 0
for i, j in d.items():
if j >= 2:
ans += (j * (j-1)) // 2
print(ans)
if __name__ == "__main__":
main() | ls = sorted(list(map(int,input().split())))
if ls[0] == ls[1] and ls[0] != ls[2]:
print('Yes')
elif ls[1] == ls[2] and ls[0] != ls[1]:
print('Yes')
elif ls[0] == ls[2] and ls[0] != ls[1]:
print('Yes')
else:
print('No') | 0 | null | 63,090,425,069,474 | 205 | 216 |
n = int(input())
ans_count = [0] * 4
ans = ['AC','WA','TLE','RE']
for s in range(n):
tmp = input()
for t in range(4):
if tmp == ans[t]:
ans_count[t] += 1
for s in range(4):
print('%s x %d' % (ans[s],ans_count[s])) | x=int(input())
x=x+x*x+x*x*x
print(x) | 0 | null | 9,538,774,019,462 | 109 | 115 |
N, M = map(int,input().split())
H = list(map(int,input().split()))
MAX = [0 for _ in range(N)]
for _ in range(M):
a, b = map(int,input().split())
MAX[a-1] = max(MAX[a-1],H[b-1])
MAX[b-1] = max(MAX[b-1],H[a-1])
ans = 0
for i in range(N):
if H[i] > MAX[i]:
ans += 1
print(ans)
| # -*- coding: utf-8 -*-
def main():
n, m = map(int, input().split())
h = list(map(int, input().split()))
h_dict = {}
for i in range(len(h)):
h_dict[i+1] = h[i]
out = []
for k in range(m):
a, b = map(int, input().split())
ha = h_dict[a]
hb = h_dict[b]
if ha > hb:
out.append(b)
elif ha < hb:
out.append(a)
else:
out.append(a)
out.append(b)
out = set(out)
print(n - len(out))
if __name__ == '__main__':
main() | 1 | 24,998,750,186,410 | null | 155 | 155 |
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 1
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"
a,b = I()
A = str(a)*b
B = str(b)*a
print(min(A,B)) | import itertools
import math
s, w = map(int, input().split())
if s <= w:
print("unsafe")
else:
print("safe") | 0 | null | 56,691,248,908,672 | 232 | 163 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.