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
|
---|---|---|---|---|---|---|
n = int(input())
a = [int(i) for i in input().split()]
num = 0
is_swapped = True
i = 0
while is_swapped:
is_swapped = False
for j in range(n-1, i, -1):
if a[j] < a[j-1]:
tmp = a[j]
a[j] = a[j-1]
a[j-1] = tmp
is_swapped = True
num += 1
i += 1
print(' '.join([str(i) for i in a]))
print(num)
|
def main():
a, b = map(int, input().split())
if a < 10 and b < 10:
print(a*b)
else:
print(-1)
main()
| 0 | null | 79,255,718,341,792 | 14 | 286 |
X,N=map(int,input().split())
p=list(map(int,input().split()))
i=0
j=0
while X+i in p:
i+=1
while X-j in p:
j+=1
if i>j:
print(X-j)
elif i<j:
print(X+i)
else:
print(min([X+i,X-j]))
|
x, n = map(int, input().split())
p = list(map(int, input().split()))
i = 0
while True:
if x-i not in p:
print(x-i)
break
if x+i not in p:
print(x+i)
break
i += 1
| 1 | 13,959,837,495,460 | null | 128 | 128 |
#coding:utf-8
n = int(input())
numbers = list(map(int, input().split()))
count = 0
for i in range(n-1):
for j in range(n-1, i, -1):
if numbers[j] < numbers[j-1]:
numbers[j], numbers[j-1] = numbers[j-1], numbers[j]
count += 1
print(*numbers)
print(count)
|
q = int(input())
sort1 = list(map(int, input().split()))
def bubblesort(ary):
cnt = 0
for i in range(q):
for j in range(q-1, i, -1):
if ary[j] < ary[j-1]:
ary[j-1], ary[j] = ary[j], ary[j-1]
cnt += 1
return (ary, cnt)
ary, cnt = bubblesort(sort1)
print(" ".join(map(str, ary)))
print(cnt)
| 1 | 18,234,271,012 | null | 14 | 14 |
n = int(input())
for i in range(1,10):
if n // i == n/i and n//i in range(1,10):
print('Yes')
break
else:
print('No')
|
kuku = [i * j for i in range(1,10) for j in range(1,10)]
N = int(input())
print('Yes' if N in kuku else 'No')
| 1 | 159,386,008,996,980 | null | 287 | 287 |
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect, heapq
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1
n = int(input())
A = list(map(int,input().split()))
data = [(ai,i) for i,ai in enumerate(A)]
data.sort(reverse = True)
dp = [[0]*(n+1) for i in range(n+1)]
for i in range(n):
for l in range(i+1):
r = i-l
dp[l+1][r] = max(dp[l+1][r], dp[l][r] + data[i][0] * abs(data[i][1] - l))
dp[l][r+1] = max(dp[l][r+1], dp[l][r] + data[i][0] * abs(data[i][1] - (n-1-r)))
ans = 0
for i in range(n):
ans = max(ans,dp[i][n-i])
print(ans)
|
from collections import deque
n,u,v=map(int,input().split())
g=[set([]) for _ in range(n+1)]
for i in range(n-1):
a,b=map(int,input().split())
g[a].add(b)
g[b].add(a)
leaf=[]
for i in range(1,n+1):
if(len(g[i])==1):
leaf.append(i)
d_u=[-1 for _ in range(n+1)]
d_v=[-1 for _ in range(n+1)]
def bfs(start,d):
d[start]=0
q=deque([start])
while(len(q)>0):
qi=q.popleft()
di=d[qi]
next_qi=g[qi]
for i in next_qi:
if(d[i]==-1):
d[i]=di+1
q.append(i)
return d
d_u=bfs(u, d_u)
d_v=bfs(v, d_v)
if(u in leaf and list(g[u])[0]==v):
print(0)
else:
ans=0
for li in leaf:
if(d_u[li]<d_v[li]):
ans=max(ans,d_v[li]-1)
print(ans)
| 0 | null | 75,422,852,937,412 | 171 | 259 |
import math
n=input()
m=math.radians(60)
def kock(n, p1x, p1y, p2x, p2y):
if(n == 0):
return
sx=(2*p1x+1*p2x)/3
sy=(2*p1y+1*p2y)/3
tx=(1*p1x+2*p2x)/3
ty=(1*p1y+2*p2y)/3
ux=(tx-sx)*math.cos(m)-(ty-sy)*math.sin(m)+sx
uy=(tx-sx)*math.sin(m)+(ty-sy)*math.cos(m)+sy
kock(n-1, p1x, p1y, sx, sy)
print round(sx,8),round(sy, 8)
kock(n-1, sx, sy, ux, uy)
print round(ux, 8),round(uy, 8)
kock(n-1, ux, uy, tx, ty)
print round(tx, 8),round(ty, 8)
kock(n-1, tx, ty, p2x, p2y)
p1x = 0.00000000
p1y = 0.00000000
p2x = 100.00000000
p2y = 0.00000000
print p1x, p1y
kock(n, p1x, p1y, p2x, p2y)
print p2x, p2y
|
l = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT']
s = input()
for i, day in enumerate(l):
if day == s:
if i == 0:
print(7)
else:
print(7-i)
| 0 | null | 66,643,622,652,992 | 27 | 270 |
#UnionFind
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
n,m,k = map(int,input().split())
V = [[] for i in range(n+1)]
W = [0]*(n+1)
uf = UnionFind(n+1)
for _ in range(m):
a,b = map(int,input().split())
V[a].append(b)
V[b].append(a)
uf.union(a,b)
for _ in range(k):
c,d = map(int,input().split())
if uf.find(d) == uf.find(c):
W[c] += 1
W[d] += 1
for i in range(1,n+1):
ans = uf.size(i) - len(V[i]) - W[i] - 1
print(ans,end="")
print(" ",end="")
print()
|
X,Y = map(int,input().split())
ans = 0
shokin = [-1,300000,200000,100000]
if X in (1,2,3):
ans += shokin[X]
if Y in (1,2,3):
ans += shokin[Y]
if X == 1 and Y == 1:
ans += 400000
print(ans)
| 0 | null | 101,351,131,185,052 | 209 | 275 |
arr = map(int, raw_input().split())
print("%d %d" % (arr[0] * arr[1], arr[0] * 2 + arr[1] * 2))
|
a, b = [int(x) for x in input().split(' ')]
area = a * b
length = 2 * a + 2 * b
print("%s %s" % (area, length))
| 1 | 296,912,137,110 | null | 36 | 36 |
n,k = map(int,input().split())
person = [0]*n
for i in range(k):
d = int(input())
A = list(map(int,input().split()))
for j in range(len(A)):
person[A[j]-1] = 1
print(person.count(0))
|
N = int(input())
def aa(s, n, t):
if n == N:
print(s)
return
for i in range(t):
aa(s+chr(97+i), n+1, t)
aa(s+chr(97+t), n+1, t+1)
return
aa("a", 1, 1)
| 0 | null | 38,563,444,759,710 | 154 | 198 |
H1,M1,H2,M2,K = map(int,input().split())
A1 = H1*60+M1
A2 = H2*60+M2
print(max(0,A2-A1-K))
|
a, b, m = map(int, input().split())
re = list(map(int, input().split()))
de = list(map(int, input().split()))
mre = min(re)
mde = min(re)
list1 = []
for i in range(m):
x, y, c = map(int, input().split())
price = re[x-1] + de[y-1] -c
list1.append(price)
mlist = min(list1)
m1 = mre + mde
if m1 < mlist:
print(m1)
else:
print(mlist)
| 0 | null | 35,880,835,208,108 | 139 | 200 |
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT() : return int(input())
def MAP() : return map(int,input().split())
def LIST() : return list(MAP())
n = INT()
ans = ''
while n != 0:
x = ( n - 1 ) % 26
n = ( n - x + 1 ) // 26
ans = chr( ord('a') + x ) + ans
print(ans)
|
def main():
import sys
input = sys.stdin.readline
n, d, a = [int(i) for i in input().split()]
chk = []
for i in range(n):
x, h = [int(i) for i in input().split()]
chk.append((x, 0, h))
from heapq import heapify, heappop, heappush
heapify(chk)
atk_cnt = 0; ans = 0
while chk:
x, t, h = heappop(chk)
if t == 0:
if atk_cnt * a >= h:
continue
remain = h - atk_cnt * a
new_atk = (remain - 1) // a + 1
heappush(chk, (x + 2 * d, 1, new_atk))
ans += new_atk
atk_cnt += new_atk
else:
atk_cnt -= h
print(ans)
if __name__ == '__main__':
main()
| 0 | null | 46,856,255,937,938 | 121 | 230 |
n=int(input())
a=list(map(int,input().split()))
res=1000
for i in range(1,n):
if a[i]>a[i-1]:
t=(res//a[i-1])*a[i]+res%a[i-1]
res=t
print(res)
|
N = int(input())
A = list(map(int,input().split()))
ans = 1000
for i in range(N-1):
if A[i] < A[i+1]:
ans += ans // A[i] * (A[i+1] - A[i])
print(ans)
| 1 | 7,333,747,759,832 | null | 103 | 103 |
from collections import Counter
MOD = 998244353
N = int(input())
D = [int(i) for i in input().split()]
counter = Counter(D)
# print("counter: {}".format(counter))
if D[0] != 0:
ans = 0
else:
ans = 1
count = 1
for i, item in enumerate(sorted(counter.items(), key=lambda x: x[0])):
# print("ans: {}".format(ans))
# print("i: {}, item: {}".format(i, item))
if i != item[0]:
ans = 0
break
if item[0] == 0 and item[1] != 1:
ans = 0
break
ans *= (count ** item[1]) % MOD
count = item[1]
print(ans % MOD)
|
n=int(input())
d=list(map(int,input().split()))
mx=max(d)
l=[0]*(10**5)
mx=0
for i in range(n):
if (i==0 and d[i]!=0) or (i!=0 and d[i]==0):
print(0)
exit()
l[d[i]]+=1
mx=max(mx,d[i])
t=1
ans=1
for i in range(1,mx+1):
ans *= t**l[i]
t=l[i]
print(ans%998244353)
| 1 | 155,310,094,410,020 | null | 284 | 284 |
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))
A_odd = A[::2]
print(np.sum(A_odd % 2))
|
N = int(input())
i = list(map(int, input().split())) #i_1 i_2を取得し、iに値を入れる
s = 0
for j in range(0,N,2):
if i[j] % 2 == 1 :
s += 1
print(s)
| 1 | 7,785,747,920,060 | null | 105 | 105 |
s = input()
t = input()
x = len(s)
num = 0
for i in range(0, x):
if s[i] != t[i]:
num += 1
print(num)
|
H,W = map(int,input().split())
if H == 1 or W == 1:
print(1)
exit(0)
else:
result = H * W
if result % 2 == 0:
print(result // 2)
else:
print(result // 2 + 1)
| 0 | null | 30,597,110,935,868 | 116 | 196 |
import sys
from collections import deque
data = list(sys.stdin.readline()[:-1])
ponds = deque()
result = deque()
index = 0
amount = 0
lefs = deque()
for i in data:
if i == "\\" or i == "_":
ponds.append([i, index])
else:
count = 0
while 1 <= len(ponds):
pond, ind = ponds.pop()
if pond == "\\":
count += (index - ind)
amount += count
pre_pond = 0
pre_left = 0
while 0 < len(lefs) and ind < lefs[-1]:
pre_left = lefs.pop()
pre_pond += result.pop()
lefs.append(ind)
result.append(count + pre_pond)
break
index += 1
print(amount)
if 0 == len(result):
print(0)
else:
print(len(result), ' '.join(map(str, result)))
|
visited = {0: -1}
height = 0
pools = []
for i, c in enumerate(input()):
if c == '\\':
height -= 1
elif c == '/':
height += 1
if height in visited:
width = i - visited[height]
sm = 0
while pools and pools[-1][0] > visited[height]:
x, l = pools.pop()
sm += l
pools.append((i, sm + width - 1))
visited[height] = i
print(sum(l for x, l in pools))
if pools:
print(len(pools), ' '.join(str(l) for x, l in pools))
else:
print(0)
| 1 | 57,315,155,488 | null | 21 | 21 |
N, M = map(int, input().split(' '))
A_ls = list(map(int, input().split(' ')))
if sum(A_ls) > N:
print(-1)
else:
print(N - sum(A_ls))
|
a, b, c, k = map(int, input().split())
print(max(min(k, a) ,0) - max(min(k - (a + b), c), 0))
| 0 | null | 26,967,092,022,340 | 168 | 148 |
n = int(input())
d = list(map(int,input().split()))
MOD = 998244353
if d[0] != 0:
print(0)
exit()
d.sort()
for i in range(1,n):
if d[i] - d[i-1] > 1:
print(0)
exit()
if d[i] == 0:
print(0)
exit()
count = 1
tmp = 1
ans = 1
for i in range(2,n):
if d[i] != d[i-1]:
ans *= pow(tmp,count,MOD)
#print(tmp,count)
tmp = count
count = 1
else:
count+=1
ans *= pow(tmp,count,MOD)
ans %= MOD
#print(tmp,count)
print(ans)
|
def prepare(n):
global MOD
modFacts = [0] * (n + 1)
modFacts[0] = 1
for i in range(n):
modFacts[i + 1] = (modFacts[i] * (i + 1)) % MOD
invs = [1] * (n + 1)
invs[n] = pow(modFacts[n], MOD - 2, MOD)
for i in range(n, 1, -1):
invs[i - 1] = (invs[i] * i) % MOD
return modFacts, invs
MOD = 10 ** 9 + 7
K = int(input())
S = input()
L = len(S)
modFacts, invs = prepare(K + L)
pow25 = [1] * max(L + 1, K + 1)
pow26 = [1] * max(L + 1, K + 1)
for i in range(max(L, K)):
pow25[i + 1] = (pow25[i] * 25) % MOD
pow26[i + 1] = (pow26[i] * 26) % MOD
ans = 0
for n in range(L, L + K + 1):
nonSi = (pow25[n - L] * pow26[L + K - n]) % MOD
Si = (modFacts[n - 1] * invs[L - 1] * invs[n - 1 - (L - 1)]) % MOD
ans += nonSi * Si
ans %= MOD
print(ans)
| 0 | null | 84,098,030,309,620 | 284 | 124 |
n,k,*a = map(int,open(0).read().split())
def func(b):
c = k
for i in a:
c -= (i-1)//b
if c < 0:
return False
return True
l = 1
r = max(a)
while(r>l):
lr = (l+r)//2
if func(lr):
r = lr
else:
l = lr + 1
print(r)
|
x, num_of_nums = map(int, input().split(' '))
if num_of_nums == 0:
print(x)
exit()
nums = set(map(int, input().split(' ')))
diff = 0
while True:
n1 = x - diff
n2 = x + diff
if n1 not in nums:
print(n1)
break
if n2 not in nums:
print(n2)
break
diff += 1
| 0 | null | 10,355,671,967,102 | 99 | 128 |
days = ["SUN", 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT']
days.reverse()
d = input()
print(days.index(d)+1)
|
S=str(input())
W=['SUN','MON','TUE','WED','THU','FRI','SAT']
for i in range(len(W)):
if S==W[i]:
print(7-i)
| 1 | 133,279,036,157,390 | null | 270 | 270 |
def sep():
return map(int,input().strip().split(" "))
def lis():
return list(sep())
n=int(input())
ar=lis()
temp=[0]*(n+5)
for i in range(n-1):
#print(ar[i],temp)
temp[ar[i]]+=1
for i in range(1,n+1):
print(temp[i])
|
nn = int(input())
aa = list(map(int,input().split()))
joushi = [0]*nn
for i in range(len(aa)):
joushi[aa[i]-1] += 1
for j in range(len(joushi)):
print(joushi[j])
| 1 | 32,772,224,650,368 | null | 169 | 169 |
A,B,C=map(int,input().split())
if len(set([A,B,C]))==2:print('Yes')
else:print('No')
|
A, B, C = map(int, input().split())
isPoor = False
if A == B and A != C :
isPoor = True
if B == C and B != A :
isPoor = True
if C == A and C != B :
isPoor = True
if isPoor :
print('Yes')
else :
print('No')
| 1 | 68,365,156,962,636 | null | 216 | 216 |
lis = list(map(int,input().split(" ")))
print(lis[0] * lis[1])
|
from itertools import*
c=[f'{x} {y}'for x,y in product('SHCD',range(1,14))]
exec('c.remove(input());'*int(input()))
if c:print(*c,sep='\n')
| 0 | null | 8,372,314,665,562 | 133 | 54 |
x=int(input())
x=x+(x**2)+(x**3)
print(x)
|
a = int(input())
print(int(a + (a * a) + (a * a * a)))
| 1 | 10,181,355,980,390 | null | 115 | 115 |
import string
a=string.ascii_lowercase
A=string.ascii_uppercase
n=input()
if n in a :
print("a")
else :
print("A")
|
s=input()
print("A" if s.upper()==s else "a")
| 1 | 11,352,889,125,470 | null | 119 | 119 |
# -*- coding: utf-8 -*-
"""
D - Knight
https://atcoder.jp/contests/abc145/tasks/abc145_d
"""
import sys
def modinv(a, m):
b, u, v = m, 1, 0
while b:
t = a // b
a -= t * b
a, b = b, a
u -= t * v
u, v = v, u
u %= m
return u if u >= 0 else u + m
def solve(X, Y):
MOD = 10**9 + 7
if (X + Y) % 3:
return 0
n = (X - 2 * Y) / -3.0
m = (Y - 2 * X) / -3.0
if not n.is_integer() or not m.is_integer() or n < 0 or m < 0:
return 0
n, m = int(n), int(m)
x1 = 1
for i in range(2, n + m + 1):
x1 = (x1 * i) % MOD
x2 = 1
for i in range(2, n+1):
x2 = (x2 * i) % MOD
for i in range(2, m+1):
x2 = (x2 * i) % MOD
ans = (x1 * modinv(x2, MOD)) % MOD
return ans
def main(args):
X, Y = map(int, input().split())
ans = solve(X, Y)
print(ans)
if __name__ == '__main__':
main(sys.argv[1:])
|
[X,Y] = list(map(int,input().split()))
n = (-1*X+2*Y)//3
m = (2*X-Y)//3
if (X+Y)%3 !=0:
print(0)
elif n<0 or m<0:
print(0)
else:
MAXN = (10**6)+10
MOD = 10**9 + 7
f = [1]
for i in range(MAXN):
f.append(f[-1] * (i+1) % MOD)
def nCr(n, r, mod=MOD):
return f[n] * pow(f[r], mod-2, mod) * pow(f[n-r], mod-2, mod) % mod
print(nCr(n+m,n,10**9 + 7))
| 1 | 149,977,239,428,250 | null | 281 | 281 |
def main():
altitude_lis = []
for i in range(10):
input_line = raw_input()
altitude = int(input_line)
altitude_lis.append(altitude)
altitude_lis.sort()
altitude_lis.reverse()
for i in range(3):
print(altitude_lis[i])
if __name__ == '__main__':
main()
|
list = []
for i in range(0, 10):
t = int(raw_input())
list.append(t)
list.sort(reverse=True)
for i in range(0, 3):
print list[i]
| 1 | 32,972,002 | null | 2 | 2 |
#!/usr/bin/env python3
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def main():
A, B = map(int, readline().split())
if (A <= 9) & (B <= 9):
print(A * B)
else:
print(-1)
if __name__ == '__main__':
main()
|
a,b=[int(i)for i in input().split()]
if a<10 and b<10:
print(a*b)
else:
print('-1')
| 1 | 158,244,519,207,122 | null | 286 | 286 |
def resolve():
N = int(input())
X = input()
if N == 1:
if X.count("1"):
print(0)
else:
print(1)
return True
base_1_count = X.count("1")
if base_1_count == 0:
for _ in range(N):
print(1)
return True
X_int = int(X, 2)
X_int_p = X_int%(base_1_count + 1)
# RE 対策
if base_1_count == 1:
for i in range(N):
if X[i] == "1":
print(0)
else:
if i == N - 1:
Xi = X_int_p + 1
else:
Xi = X_int_p
count = 1
while Xi != 0:
Xi %= bin(Xi).count("1")
count += 1
print(count)
return True
X_int_m = X_int%(base_1_count - 1)
for i in range(N):
# 初期値計算を高速にやる
if X[i] == "1":
temp_1_count = base_1_count-1
pow_2 = pow(2, N-i-1, base_1_count-1)
if X_int_m <= pow_2:
Xi = X_int_m - pow_2 + base_1_count-1
else:
Xi = X_int_m - pow_2
else:
temp_1_count = base_1_count+1
Xi = X_int_p + pow(2, N-i-1, base_1_count+1)
while Xi >= base_1_count+1:
Xi %= base_1_count+1
# print("1_c={0}".format(temp_1_count))
if temp_1_count == Xi:
print(1)
continue
count = 1
while Xi != 0:
num_of_1 = bin(Xi).count("1")
Xi %= num_of_1
count += 1
print(count)
if __name__ == "__main__":
resolve()
|
n = int(input())
x = str(input())
one = x.count("1")
X = int(x, 2)
if one==1:
for i in range(n):
if x[i]=="1":
print(0)
elif i==n-1:
print(2)
else:
print(1)
elif one>1:
Xp = X % (one+1)
Xm = X % (one-1)
def f(x):
if x==0:
return 0
return 1+f(x%bin(x).count("1"))
for i in range(n):
if x[i]=="0":
c = pow(2, n-i-1, one+1)
print(f((Xp+c)%(one+1))+1)
else:
c = pow(2, n-i-1, one-1)
print(f((Xm-c)%(one-1))+1)
else:
for i in range(n):
print(1)
| 1 | 8,261,326,263,010 | null | 107 | 107 |
from heapq import *
import sys
from collections import *
from itertools import *
from decimal import *
import copy
from bisect import *
import time
import math
def gcd(a,b):
if(a%b==0):return(b)
return (gcd(b,a%b))
N=int(input())
A=list(map(int,input().split()))
A=[[A[i],i] for i in range(N)]
A.sort(reverse=True)
dp=[[0 for i in range(N+1)] for _ in range(N+1)]
for n in range(N):
a,p=A[n]
for x in range(1,n+2):
y=n+1-x
dp[x][y]=max(dp[x][y],dp[x-1][y]+round(abs(x-1 - p))*a)
for y in range(1,n+2):
x=n+1-y
dp[x][y]=max(dp[x][y],dp[x][y-1]+round(abs(N-y - p))*a)
#print(dp)
print(max([dp[x][y] for x in range(N+1) for y in range(N+1) if x+y==N]))
|
a,b=map(str, input().split())
s=b+a
print(s)
| 0 | null | 68,189,663,673,930 | 171 | 248 |
n, k = map(int,input().split())
count = 0
while True:
n = n//k
count += 1
if n <1:
break
print(count)
|
def main():
n, k = map(int, input().split())
cnt = 0
i = 1
# nが大きい
while n >= i:
i *= k
cnt += 1
print(cnt)
if __name__ == '__main__':
main()
| 1 | 64,018,020,427,100 | null | 212 | 212 |
spam = [int(input()) for i in range(0, 10)]
spam.sort()
spam.reverse()
for i in range(0,3):
print(spam[i])
|
import sys
l = []
for i in sys.stdin:
l.append(i)
for i in range(0,len(l)):
if int(l[i]) == 0:
break
count = 0
for j in range(0,len(l[i])-1):
count += int(l[i][j])
print(count)
| 0 | null | 783,792,710,460 | 2 | 62 |
for a in [1,2,3,4,5,6,7,8,9]:
for b in [1,2,3,4,5,6,7,8,9]:
print ("{0}x{1}={2}".format(a,b,a*b))
|
l = [i for i in range(1,10)]
for i in l:
for j in l:
print(str(i)+ 'x' + str(j) + '=' + str(i*j))
| 1 | 370,172 | null | 1 | 1 |
s=input()
a=s[:len(s)//2+1//2]
b=s[len(s)//2+1:]
if s==s[::-1] and a==a[::-1] and b==b[::-1]:
print("Yes")
else:
print("No")
|
num_list=[]
while True:
num = input()
if num == 0:
break
num_list.append(num)
for num in num_list:
print sum(map(int,list(str(num))))
| 0 | null | 23,926,531,175,780 | 190 | 62 |
n,m,l = map(int,input().split())
g = [[1<<30]*n for _ in range(n)]
for _ in range(m):
a,b,c = map(int,input().split())
g[a-1][b-1] = c
g[b-1][a-1] = c
for i in range(n):
g[i][i] = 0
def bell(g,n):
for k in range(n):
for i in range(n-1):
for j in range(i+1,n):
if g[i][j] > g[i][k] + g[k][j]:
g[i][j] = g[i][k] + g[k][j]
g[j][i] = g[i][j]
return g
g = bell(g,n)
for i in range(n):
for j in range(n):
if i == j:
g[i][j] = 0
elif g[i][j] <= l:
g[i][j] = 1
else:
g[i][j] = 1<<30
g = bell(g,n)
q = int(input())
for _ in range(q):
s,t = map(int,input().split())
if g[s-1][t-1]>>30:
print(-1)
else:
print(g[s-1][t-1]-1)
|
while True:
n, x = map(int, input().split())
if (n, x) == (0, 0): break
ans = []
for i in range(n, 1, -1):
for j in range(1, n):
tmp = x-(i+j)
if tmp > n: continue
if tmp > 0 and i > 0 and j > 0:
if tmp != j and tmp != i and i != j:
pmt = sorted([i, j, tmp])
if not pmt in ans: ans.append(pmt)
print(len(ans))
| 0 | null | 87,801,233,426,988 | 295 | 58 |
import math
h = int(input())
w = int(input())
n = int(input())
ans = math.ceil(n/max(h,w))
print(ans)
|
H = int(input())
W = int(input())
N = int(input())
X = max(H, W)
print((N + X - 1) // X)
| 1 | 88,848,732,794,682 | null | 236 | 236 |
x=int(input())
S=x*x*x
print(S)
|
# coding: utf-8
i = input()
j = int(i) ** 3
print(j)
| 1 | 283,426,401,190 | null | 35 | 35 |
D, T, S = list(map(int, input().split()))
print("Yes" if T*S>=D else "No")
|
import itertools
n = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
N = [i for i in range(1,n+1)]
N_dict = {v:(i+1) for i,v in enumerate(itertools.permutations(N, n))}
#print(N_dict)
print(abs(N_dict[P] - N_dict[Q]))
| 0 | null | 52,099,334,210,020 | 81 | 246 |
a, b = map(int, input().split())
answer = (a * b)
print(answer)
|
import collections
N = int(input())
S = [input() for _ in range(N)]
c = collections.Counter(S)
d = c.most_common()
cnt = 0
for i in range(len(c)-1):
if d[i][1] == d[i+1][1]:
cnt += 1
else:
break
e = []
for j in range(cnt+1):
e.append(d[j][0])
e.sort()
for k in range(len(e)):
print(e[k])
| 0 | null | 43,035,693,090,236 | 133 | 218 |
def main():
num=map(int,input().split())
print(" ".join([str(x) for x in sorted(num)]))
if __name__=='__main__':
main()
|
s = input().split()
a = s[1] + s[0]
a.join('')
print(a)
| 0 | null | 52,015,621,274,620 | 40 | 248 |
import math
N = int(input())
if N%2 == 1:
print(0)
exit()
ans = 0
i = 1
while 1:
a = 2*5**i
if N//a == 0:
break
ans += (N//a)
i += 1
print(ans)
|
N = int(input())
if N % 2 == 1:
print(0)
exit()
ans = 0
N //= 2
i = 1
while N >= 5 ** i:
ans += (N // 5 ** i)
i += 1
print(ans)
| 1 | 115,854,391,925,580 | null | 258 | 258 |
#!/usr/bin/env python3
s = input()
n = len(s)+1
a = [0 for _ in range(n)]
for i in range(n-1):
if s[i] == '<':
a[i+1] = max(a[i+1], a[i]+1)
for i in reversed(range(1, n)):
if s[i-1] == '>':
a[i-1] = max(a[i-1], a[i]+1)
ans = sum(a)
#print('a = ', a)
print(ans)
|
import sys
input = sys.stdin.readline
def main():
a, b = input().split()
c, d = b.split(".")
if len(d) == 1:
d = d + '0'
p, q = int(a), int(c) * 100 + int(d)
ans = p * q // 100
print(ans)
if __name__ == "__main__":
main()
| 0 | null | 86,752,082,660,572 | 285 | 135 |
# -*- coding: utf-8 -*-
#https://mathtrain.jp/tyohukuc
n, m, k = map(int,input().split())
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
p = 998244353
N = n+1 # N は必要分だけ用意する
fact = [1, 1] # fact[n] = (n! mod p)
factinv = [1, 1] # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1] # factinv 計算用
for i in range(2, N + 1):
fact.append((fact[-1] * i) % p)
inv.append((-inv[p % i] * (p // i)) % p)
factinv.append((factinv[-1] * inv[-1]) % p)
ans = 0
beki = [1,m-1]
for i in range(2,N+1):
beki.append(((beki[-1]*(m-1)) % p))
for x in range(k+1):
ans += m * beki[n-x-1] %p * cmb(n-1,x,p) %p
ans = ans % p
print(ans)
|
from itertools import permutations
def same(l1, l2, n):
for i in range(n):
if l1[i] != l2[i]:
return False
return True
N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
P = [p-1 for p in P]
Q = [q-1 for q in Q]
for i,pattern in enumerate(permutations(range(N))):
if same(P, pattern, N):
i_p = i
if same(Q, pattern, N):
i_q = i
print(abs(i_p - i_q))
| 0 | null | 62,118,080,848,268 | 151 | 246 |
x, y = map(int, input().split())
mod = 10 ** 9 + 7
if (x + y) % 3 != 0:
ans = 0
else:
n, m = (2 * x - y) / 3, (2 * y - x) / 3
ans = 0
if n >= 0 and m >= 0:
n, m = int(n), int(m)
ans = 1
for i in range(min(m, n)):
ans = ans * (n + m - i) % mod
ans *= pow(i + 1, mod - 2, mod)
print(ans % mod)
|
X,Y=map(int,input().split())
MOD=10**9+7
def modinv(a):
return pow(a,MOD-2,MOD)
x=(2*Y-X)//3
y=(2*X-Y)//3
if (2*Y-X)%3!=0 or (2*X-Y)%3!=0 or x<0 or y<0:
print(0)
else:
r=1
n=x+y
k=min(x,y)
for i in range(k):
r*=(n-i)
r*=modinv(i+1)
r%=MOD
print(r)
| 1 | 150,170,124,487,500 | null | 281 | 281 |
def main():
n = int(input())
s_list = [None for _ in range(n)]
t_list = [None for _ in range(n)]
for i in range(n):
s, t = input().split()
s_list[i] = s
t_list[i] = int(t)
x = input()
x_index = s_list.index(x)
ans = sum(t_list[x_index + 1:])
print(ans)
if __name__ == "__main__":
main()
|
def main():
N = int(input())
S = [0] * N
T = [0] * N
for i in range(N):
S[i], T[i] = input().split()
X = input()
idx = S.index(X)
ans = sum(map(int, T[idx+1:]))
print(ans)
if __name__ == "__main__":
main()
| 1 | 96,978,741,524,042 | null | 243 | 243 |
N,K = map(int,input().split())
R,S,P = map(int,input().split())
T = input()
ans = 0
memo = [0 for i in range(N)]
for i in range(N):
check = T[i]
if i >= K and T[i-K] == check and memo[i-K] == 0:
memo[i] = 1
continue
if check == "r":
ans += P
elif check == "p":
ans += S
elif check == "s":
ans += R
print(ans)
|
N,K = map(int,input().split())
R,S,P = map(int,input().split())
dp = []
order = input()
def jcount(x):
if x=='r':
ans = P
elif x=='s':
ans = R
else:
ans = S
return ans
counter = 0
for i in range(N):
if i < K:
counter += jcount(order[i])
dp.append(order[i])
elif order[i] != dp[i-K]:
counter += jcount(order[i])
dp.append(order[i])
else:
dp.append('x')
print(counter)
| 1 | 106,841,755,637,472 | null | 251 | 251 |
#もらうDPで考える
N, K = map(int, input().split())
l = []
r = []
MOD = 998244353
for i in range(K):
a,b = map(int, input().split())
l.append(a)
r.append(b)
dp = [0] * (N+1)
#スタート地点が1なので、dp[1]を1とする
dp[1] = 1
dpsum = [0] * (N+1)
dpsum[1] = 1
for i in range(2, N+1):
for j in range(K):
#[l[i], r[i]]
li = i - r[j]
ri = i - l[j]
if ri < 0: continue
# l1が負になるケースをハンドリング
li = max(1, li)
dp[i] += (dpsum[ri] - dpsum[li-1])%MOD #dp[li] ~ dp[ri]の和を足す
dpsum[i] = (dpsum[i-1] + dp[i])%MOD
print(dp[N]%MOD)
|
n = int(input())
S = map(int,raw_input().split())
q = int(input())
T = map(int,raw_input().split())
count = 0
for v in T:
for i in range(n):
if S[i] == v:
count += 1
break
print count
| 0 | null | 1,368,012,916,670 | 74 | 22 |
while True:
line = input()
if line == '0':
break
print(sum(map(int, list(line))))
|
while True:
s = input()
if s=="0":
break
print(sum(map(int,s)))
| 1 | 1,606,926,650,176 | null | 62 | 62 |
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.readline
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
import math
#from itertools import combinations
def run():
n,k = map(int, input().split())
mod = 10 ** 9 + 7
ret = 0
inv = generate_inv(n, mod)
if k >= n-1:
k = n-1
left = 1
right = 1
ret = 1
for h in range(1, k+1):
right *= (n - h) * inv[h]
right %= mod
left *= (n - h + 1) * inv[h]
left %= mod
ret += right * left
ret %= mod
print(ret)
def generate_inv(n,mod):
"""
逆元行列
n >= 2
"""
ret = [0, 1]
for i in range(2,n+1):
next = -ret[mod%i] * (mod // i)
next %= mod
ret.append(next)
return ret
def comb_mod(n, a, mod):
"""
return: [n, a] % mod
Note: mod must be a prime number
"""
up = 1
down = 1
for i in range(a):
up *= n - i
up %= mod
down *= i + 1
down %= mod
down = pow_mod(down, mod - 2, mod)
return (up * down) % mod
def pow_mod(n, k, mod):
res = 1
while True:
if k // 2 >= 1:
if k % 2 == 1:
res = (res * n) % mod
n = (n ** 2) % mod
k = k // 2
else:
break
return (n * res) % mod
if __name__ == "__main__":
run()
|
n,k=map(int,input().split())
mod=10**9+7
f=[1]
for i in range(2*n):f+=[f[-1]*(i+1)%mod]
def comb(a,b):return f[a]*pow(f[b],mod-2,mod)*pow(f[a-b],mod-2,mod)%mod
ans=comb(2*n-1,n-1)
for i in range(n-1,k,-1):ans=(ans-comb(n,n-i)*comb(n-1,i))%mod
print(ans)
| 1 | 67,034,148,554,548 | null | 215 | 215 |
import itertools
import math
n = int(input())
points = [list(map(int, input().split())) for _ in range(n)]
numbers = list(range(1, n + 1))
diff = 0
count = 0
for pattern in itertools.permutations(numbers):
count += 1
for j in range(n - 1):
points_index = pattern[j] - 1
next_index = pattern[j + 1] - 1
diff += math.sqrt((points[points_index][0] - points[next_index][0]) ** 2 + (points[points_index][1] - points[next_index][1]) ** 2)
print(diff / count)
|
import itertools
import math
N=int(input())
z=[]
for _ in range(N):
z.append(list(map(int,input().split())))
sum=0
for per in itertools.permutations(list(range(N))):
for i in range(N-1):
sum+=math.sqrt((z[per[i]][0]-z[per[i+1]][0])**2+(z[per[i]][1]-z[per[i+1]][1])**2)
ans=sum/math.factorial(N)
print(ans)
| 1 | 148,663,609,674,880 | null | 280 | 280 |
import sys
input = sys.stdin.readline
#l = list(map(int, input().split()))
#import numpy as np
#arr = np.array([int(i) for i in input().split()])
'''
a,b=[],[]
for i in range(n):
A, B = map(int, input().split())
a.append(A)
b.append(B)'''
n=int(input())
a,x=[],[]
for i in range(n):
A = int(input())
a.append(A)
B=[]
for j in range(A):
B.append(list(map(int, input().split())))
x.append(B)
ma=0
for i in range(2**n):
now=0
flg=True
e=[0]*n
for j in range(n):
if (i>>j)&1:
now+=1
e[j]=1
for j in range(n):
#print(e)
if (i>>j)&1:
if e[j]==0:
flg=False
break
elif not flg:
break
for k in range(a[j]):
"""if e[x[j][k][0]-1]==-1:
if x[j][k][1] and
e[x[j][k][0]-1]=x[j][k][1]"""
if (e[x[j][k][0]-1]==0 and x[j][k][1]==1) or (e[x[j][k][0]-1]==1 and x[j][k][1]==0):
flg=False
break
if flg and ma<now:
ma=now
#print(ma)
print(ma)
|
List=list(input())
if List[2]==List[3] and List[4]==List[5]:
print("Yes")
else:print("No")
| 0 | null | 81,867,610,761,160 | 262 | 184 |
R=int(input())
N=R*2*3.141592
print(N)
|
r = int(input())
print(2*r*3.14159265358)
| 1 | 31,468,323,176,708 | null | 167 | 167 |
# AOJ ITP1_10_D
import math
def intinput():
a = input().split()
for i in range(len(a)):
a[i] = int(a[i])
return a
def main():
n = int(input())
x = intinput()
y = intinput()
sum_1 = 0
sum_2 = 0
sum_3 = 0
MD_INFTY = 0
for i in range(n):
MD_INFTY = max(MD_INFTY, abs(x[i] - y[i]))
sum_1 += abs(x[i] - y[i])
sum_2 += abs(x[i] - y[i]) ** 2
sum_3 += abs(x[i] - y[i]) ** 3
MD_1 = sum_1
MD_2 = math.sqrt(sum_2)
MD_3 = sum_3 ** (1 / 3)
print(MD_1); print(MD_2); print(MD_3); print(float(MD_INFTY))
if __name__ == "__main__":
main()
|
input()
d=[abs(s-t)for s,t in zip(*[list(map(int,input().split()))for _ in'12'])]
f=lambda n:sum(s**n for s in d)**(1/n)
print(f(1),f(2),f(3),max(d),sep='\n')
| 1 | 207,581,332,530 | null | 32 | 32 |
n=int(input())
if n%2!=0:
print(0)
else:
ans=0
t=10
while True:
ans=ans+n//t
t=t*5
if n//t==0:
break
print(ans)
|
H=int(input())
x=0
while True:
x+=1
if 2**x>H:
x-=1
break
ans=0
for i in range(x+1):
ans+=2**i
print(ans)
| 0 | null | 97,918,904,731,072 | 258 | 228 |
import math
n = input()
A = 0
def is_prime(m):
for i in range(2, int(math.sqrt(m)) + 1):
if (m % i == 0):
return False
return True
for i in range(n):
k = input()
if is_prime(k):
A += 1
print A
|
def main():
h,w,k = map(int,input().split())
maze = [['.' for j in range(6)] for i in range(6)]
for i in range(h):
line = list(input())
for j in range(w):
maze[i][j] = line[j]
# print(maze)
ver = [0 for i in range(6)]
hor = [0 for i in range(6)]
horver = [[0 for i in range(6)] for j in range(6)]
total = 0
for i in range(6):
for j in range(6):
if maze[i][j] == '#':
ver[j] += 1
hor[i] += 1
horver[i][j] = 1
total += 1
# print(ver,hor,horver)
ans = 0
for bit in range(2**(h+w)):
tmp = total
valid_hor = []
for i in range(h):
if (bit >> i & 1) == 1:
valid_hor.append(i)
tmp -= hor[i]
for j in range(h,h+w):
if (bit >> j & 1) == 1:
tmp -= ver[j-h]
for i in valid_hor:
tmp += horver[i][j-h]
if tmp == k:
ans += 1
print(ans)
return
if __name__ == '__main__':
main()
| 0 | null | 4,437,389,386,472 | 12 | 110 |
S = input()
S = S.replace('><','> <').split()
ans = 0
for i in S:
j = max(i.count('>'),i.count('<'))
k = min(i.count('>'),i.count('<'))-1
for a in range(1,j+1):
ans += a
for b in range(1,k+1):
ans += b
print(ans)
|
S = input().rstrip() + "#"
s0 = S[0]
A, cnt = [], 1
for s in S[1:]:
if s==s0: cnt+=1
else: A.append(cnt); cnt=1
s0 = s
res, st = 0, 0
if S[0]==">":
res += A[0]*(A[0]+1)//2
st=1
for i in range(st,len(A),2):
if i+1==len(A): res += A[i]*(A[i]+1)//2; break
p, q = A[i], A[i+1]
if p < q:
res += q*(q+1)//2 + p*(p-1)//2
else:
res += q*(q-1)//2 + p*(p+1)//2
print(res)
| 1 | 156,640,739,642,810 | null | 285 | 285 |
def main():
N, K = map(int, input().split())
A = list(map(int, input().split()))
for k in range(K):
A_temp=[0]*(N+1)
for i in range(N):
A_temp[max(0,i-A[i])]+=1
if i+A[i]+1<=N-1:
A_temp[i+A[i]+1]-=1
A[0]=A_temp[0]
for j in range(1,N):
A_temp[j]+=A_temp[j-1]
A[j]=A_temp[j]
for ai in A:
if ai != N:
break
else:
break
print(' '.join([str(a) for a in A]))
if __name__ == "__main__":
main()
|
def main():
a, b = tuple(map(int,input().split()))
print(gcd(a, b))
def gcd(x, y):
# x > y となるように並べ替え
if x < y:
(x, y) = (y, x)
return x if y == 0 else gcd(y, x%y)
if __name__ == '__main__':
main()
| 0 | null | 7,742,090,410,428 | 132 | 11 |
n = int(input())
A = list(map(int, input().split()))
q = int(input())
S = []
for _ in range(q):
x, y = map(int, input().split())
S.append((x, y))
sum = sum(A)
# print(sum)
R = [0 for _ in range(10**5+1)]
for a in A:
R[a-1] += 1
for (x,y) in S:
sum += (y-x)*R[x-1]
R[y-1] += R[x-1]
R[x-1] = 0
print(sum)
|
x, k, d = map(int, input().split())
x = -x if x <= 0 else x
if x - d * k >= 0:
print(x - d * k)
else:
a = x // d
b = a + 1
rest_cnt = k - a
if rest_cnt % 2 == 0:
print(abs(x - d * a))
else:
print(abs(x - d * b))
| 0 | null | 8,723,255,668,622 | 122 | 92 |
a = input()
if a == "AAA" :
print("No")
elif a == "BBB":
print("No")
else:
print("Yes")
|
S = input()
print('Yes' if len(set(S)) != 1 else 'No')
| 1 | 54,541,813,618,600 | null | 201 | 201 |
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
Q = int(input())
ans = sum(A)
num = Counter(A)
for i in range(Q):
b,c = map(int,input().split())
ans += (c-b)*num[b]
num[c] += num[b]
num[b] = 0
print(ans)
|
n = int(input())
a = list(map(int, input().split()))
d = dict()
for i in range(n):
d[i] = 0
for e in a:
d[e-1] += 1
for i in range(n):
print(d[i])
| 0 | null | 22,517,055,001,710 | 122 | 169 |
def gcd(x, y):
if x == 0:
return y
return gcd(y % x, x)
def lcm(x, y):
return x // gcd(x, y) * y
n, m = map(int, input().split())
a = list(map(int, input().split()))
aa = [e // 2 for e in a]
for i, e in enumerate(aa):
if i == 0:
base = 0
while e % 2 == 0:
e //= 2
base += 1
else:
cnt = 0
while e % 2 == 0:
e //= 2
cnt += 1
if cnt != base:
print(0)
exit()
c = 1
for e in aa:
c = lcm(c, e)
if c > m:
print(0)
exit()
ans = (m - c) // (2 * c) + 1
print(ans)
|
from fractions import gcd
n, m = map(int, input().split())
a = list(map(int, input().split()))
def lcm(a, b):
return a*b // gcd(a, b)
"""
akが偶数だから、bk=2akとして、
bk × (2p + 1)を満たすpが存在すれば良い
2p+1は奇数のため、Xとbkの2の素因数は一致しなければならない
akに含まれる最大の2^kを探す。
"""
if len(a) == 1: lcm_all = a[0]//2
else: lcm_all = lcm(a[0]//2, a[1]//2)
amax = 0
for i in range(1, n):
lcm_all = lcm(lcm_all, a[i]//2)
amax = max(amax, a[i]//2)
f = True
if lcm_all > m:
f = False
for i in range(n):
if n == 1: break
if (lcm_all//(a[i]//2))%2 == 0:
# akの2の約数の数がそろわないので、どんな奇数を掛けても共通のXを作れない
f = False
if f:
# amaxの奇数倍でmを超えないもの
ans = (m // lcm_all + 1)//2
print(ans)
else:
print(0)
| 1 | 101,844,979,467,758 | null | 247 | 247 |
h,a = map(int,input().split())
ans = 0
for _ in range(h):
h -= a
ans += 1
if h <= 0:
break
print(ans)
|
i = 1
while True:
a = int(input())
if (a == 0):
break
else:
print("Case " + str(i) + ": " + str(a))
i += 1
| 0 | null | 38,661,015,627,730 | 225 | 42 |
N=int(input());S,T=map(str,input().split())
for i in range(N):print(S[i],end='');print(T[i],end='')
|
N = int(input())
S, T = input().split()
print("".join(s + t for s, t in zip(S, T)))
| 1 | 112,416,825,741,908 | null | 255 | 255 |
#文字列をリストに変換
list_coffee = list(input())
#判別
if list_coffee[2] == list_coffee[3] and list_coffee[4] == list_coffee[5]:
text = "Yes"
else:
text = "No"
#結果の表示
print(text)
|
import sys
S = input()
cond = (S[2]==S[3]) & (S[4]==S[5])
ans = "Yes" if cond else "No"
print(ans)
| 1 | 42,120,057,440,978 | null | 184 | 184 |
import math
r = [float(x) for x in input().split()]
print("{0:f} {1:f}".format(r[0] * r[0] * math.pi, r[0] * 2 * math.pi))
|
import math
pai = math.pi
r = float(input())
print('{:.6f} {:.6f}'.format(pai*r**2,2*pai*r))
| 1 | 629,285,662,400 | null | 46 | 46 |
def solve():
N = int(input())
lfs = list(map(int, input().strip().split()))
ans = 0
L = 1 << N
lo = lfs[-1]
hi = lfs[-1]
memo = [0] * (N + 1)
for i in range(N - 1, -1, -1):
if lo > L:
return -1
memo[i + 1] = hi
lo = (lo + 1) // 2 + lfs[i]
hi = hi + lfs[i]
L = L >> 1
if lo > L:
return -1
memo[0] = hi
curr = 1
for i in range(N + 1):
ans += min(memo[i], curr)
curr = (curr - lfs[i]) << 1
return ans
print(solve())
|
import sys
input = sys.stdin.readline
def main():
N = int(input())
A = list(map(int, input().split()))
node_count = [0] * (N+1)
for i, a in enumerate(A[::-1]):
if i == 0:
node_count[N] = a
continue
node_count[N-i] = node_count[N-i+1] + a
can_build = True
for i, a in enumerate(A):
if i == 0:
if N > 0 and a > 0:
can_build = False
break
if N == 0 and a > 1:
can_build = False
break
node_count[0] = min(node_count[0], 1)
continue
if (i < N and a >= node_count[i-1]*2) or (i == N and a > node_count[i-1]*2):
can_build = False
break
node_count[i] = min(node_count[i], node_count[i-1]*2-A[i-1]*2)
if can_build:
ans = sum(node_count)
else:
ans = -1
print(ans)
if __name__ == "__main__":
main()
| 1 | 18,908,439,472,540 | null | 141 | 141 |
N,M = map(int,input().split())
S = input()
ans = []
i = N
while i > 0:
for m in range(M,0,-1):
if i-m <= 0:
ans.append(i)
i = 0
break
if S[i-m]=='0':
ans.append(m)
i -= m
break
else:
print(-1)
exit()
print(*ans[::-1])
|
import sys
#+++++
def main():
n, m = map(int, input().split())
s=input()
s=s[::-1]
#arch=[len(s)+100]*len(s)
pos=0
ret=[]
while pos < len(s)-1:
for mi in range(m,0,-1):
if pos+mi >= len(s):
pass
elif s[pos+mi]=='0':
pos += mi
ret.append(mi)
#print(pos)
break
else:
pass
else:
return -1
r=ret[::-1]
print(*r)
'''
def main2():
n, m = map(int, input().split())
s = input()
tt=[-1]*len(s)
t_parent=[-1]*len(s)
rs=s[::-1]
open_list=[0]
max_dist = 0
while True#len(open_list) > 0:
st, parent, count = open_list.pop()
for i in range(m, 0, -1):
aa = st + i
if aa > n+1:
pass
#gmマス
if rs[aa] == 1:
continue
#アクセス済み
if tt[aa] > 0:
break
tt[aa] = count+1
t_parent[aa] = st
open_list.append(aa, st, count+1)
print(1)
'''
#+++++
isTest=False
def pa(v):
if isTest:
print(v)
if __name__ == "__main__":
if sys.platform =='ios':
sys.stdin=open('inputFile.txt')
isTest=True
else:
pass
#input = sys.stdin.readline
ret = main()
if ret is not None:
print(ret)
| 1 | 139,015,881,697,120 | null | 274 | 274 |
def solve(N, a):
count = 0
for i in range(1,N+1):
if i % 2 == 1 and a[i] % 2 ==1:
count += 1
return count
N = int(input())
a = [0] + list(map(int, input().split()))
print(solve(N, a))
|
import sys
#DEBUG=True
DEBUG=False
if DEBUG:
f=open("202007_2nd/B_input.txt")
else:
f=sys.stdin
N=int(f.readline().strip())
A=list(map(int,f.readline().split()))
ans=0
for _ in range(N):
ans=ans+1 if (_+1)%2 and (A[_]%2) else ans
print(ans)
f.close()
| 1 | 7,755,033,625,280 | null | 105 | 105 |
X,Y = map(int, input().split())
if Y - 2*X >= 0 and 4*X - Y >= 0 and (Y - 2*X) % 2 == 0 and (4*X - Y) % 2 == 0:
print('Yes')
else:
print('No')
|
def main():
x,y = list(map(int,input().split()))
ans=0
for i in range(0,x+1):
if 2*i+4*(x-i)==y:
ans=1
if ans==1:
print("Yes")
else:
print("No")
main()
| 1 | 13,732,136,569,590 | null | 127 | 127 |
def main():
s = list(input())
for i in range(len(s)):
s[i] = "x"
L = "".join(s)
print(L)
if __name__ == "__main__":
main()
|
# B - I miss you...
# S
S = input()
answer = '0'
for i in range(0, len(S)):
answer += 'x'
print(answer[1:len(S) + 1])
| 1 | 73,023,604,155,100 | null | 221 | 221 |
a = list(input())
if a[1] == "B":
print("ARC")
else:
print("ABC")
|
import heapq
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
f = list(map(int, input().split()))
f.sort(reverse=True)
asum = sum(a)
def test(x):
t = [min(a[i], x//f[i]) for i in range(n)]
return asum - sum(t)
ng = -1
ok = 10**13
while abs(ok-ng)>1:
mid = (ok+ng)//2
if test(mid) <= k:
ok = mid
else:
ng = mid
print(ok)
| 0 | null | 94,812,403,780,948 | 153 | 290 |
if __name__ == '__main__':
N, A, B = map(int, input().split())
base = pow(10, 100)
C = A+B
mod = N%C
n = N//C
if mod>A:
print(A*n+A)
else:
print(A*n+mod)
|
def gcd(a, b):
if a > b:
a, b = b, a
if a == 0:
return b
else:
return gcd(b % a, a)
try:
while 1:
a,b = list(map(int,input().split()))
c = gcd(a, b)
print('{} {}'.format(c,int(c * (a/c) * (b/c))))
except Exception:
pass
| 0 | null | 27,771,718,126,688 | 202 | 5 |
def solution1():
# https://www.youtube.com/watch?v=aRdGRrsRo7I
n = int(input())
s = input()
r, g, b = 0, 0, 0
for i in s:
if i == 'R': r += 1
elif i == 'G': g += 1
else: b += 1
total = r*g*b
# all permutations of rgb are valid, to check if s[i], s[j], s[k] is a permutation of 'rgb' we could use counter. Or neat trick: ASCII value of the sum of s[i] + s[j] + s[k] is same.
is_rgb = ord('R') + ord('G') + ord('B')
for i in range(n):
for j in range(i+1, n):
# Condition 2 fails when: i - j = k - j --> k = 2*j - i
k = 2*j - i
if k < n:
if ord(s[i]) + ord(s[j]) + ord(s[2*j-i]) == is_rgb:
total -= 1
print(total)
solution1()
|
n=input()
h=n/3600
m=(n-h*3600)/60
print ':'.join(map(str,[h,m,n%60]))
| 0 | null | 18,382,113,578,154 | 175 | 37 |
a, b = 1, 1
for i in range(int(input())):
a, b = b, a + b
print(a)
|
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce, lru_cache # @lru_cache(None)
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**6)
# ----------------------------------------------------------- #
s = input()
print(s[:3])
| 0 | null | 7,390,834,067,568 | 7 | 130 |
# C - 100 to 105
# https://atcoder.jp/contests/sumitrust2019/tasks/sumitb2019_c
x = int(input())
d, m = divmod(x, 100)
D = [0] * 5
for i in range(4, -1, -1):
D[i], m = divmod(m, i + 1)
if d >= sum(D):
print(1)
else:
print(0)
|
x = int(input())
if x%100 == 0 or x%101 == 0 or x%102 == 0 or x%103 == 0 or x%104 == 0 or x%105 == 0:
print (1)
else:
for i in range(100000):
if 100*i <= x <= 105*i:
print (1)
exit ()
else:
print (0)
| 1 | 127,812,892,824,400 | null | 266 | 266 |
#!/usr/bin/env python
# -*- coding: utf-8 -*-
def print_array(a):
print(" ".join(map(str, a)))
def bubblesort(a, n):
swap = 0
flag = True
while flag:
flag = False
for j in range(n - 1, 0, -1):
if a[j] < a[j - 1]:
(a[j], a[j - 1]) = (a[j - 1], a[j])
swap += 1
flag = True
return (a, swap)
def main():
n = int(input())
a = list(map(int, input().split()))
(b, swap) = bubblesort(a, n)
print_array(b)
print(swap)
if __name__ == "__main__":
main()
|
import sys
lines = sys.stdin.readlines()
N = lines[0]
A = lines[1].strip().split(" ")
flag = 1
c = 0
i = 0
while flag == 1:
flag = 0
for j in reversed(range(i+1,len(A))):
if int(A[j]) < int(A[j-1]):
a = A[j]
b = A[j-1]
A[j] = b
A[j-1] = a
flag = 1
c += 1
i += 1
print " ".join(A)
print c
| 1 | 17,936,403,720 | null | 14 | 14 |
X = int(input())
if X >= 400 and 599 >= X:
print("8")
elif X >= 600 and 799 >= X:
print("7")
elif X >= 800 and 999 >= X:
print("6")
elif X >= 1000 and 1199 >= X:
print("5")
elif X >= 1200 and 1399 >= X:
print("4")
elif X >= 1400 and 1599 >= X:
print("3")
elif X >= 1600 and 1799 >= X:
print("2")
elif X >= 1800 and 1999 >= X:
print("1")
|
N = int(input())
A = list(map(int,input().split()))
Q = int(input())
S = [list(map(int, input().split())) for l in range(Q)]
l = [0] * 10**6
tot = 0
for i in range(N) :
l[A[i]]+=1
tot += A[i]
for i in range(Q):
s0 = S[i][0]
s1 = S[i][1]
tot += s1 * (l[s0] + l[s1]) - (s0 * l[s0] + s1*l[s1])
l[s1] += l[s0]
l[s0] = 0
print(tot)
| 0 | null | 9,445,446,068,308 | 100 | 122 |
N, K = map(int, input().split())
answer = 0
while N // (K ** answer) >= 1:
answer += 1
print(answer)
|
N,K=input().split()
N=int(N)
K=int(K)
n=0
i=1
while i<=N:
n=n+1
i=K**n
print(n)
| 1 | 64,336,226,522,348 | null | 212 | 212 |
N = input()
S = list(map(int, input()[:]))
ans = 0
for num in range(1000):
n1,n2,n3 = 0, 0, num%10
n2= (num %100-n3)// 10
n1 = (num-n2*10- n3) //100
f1 = False
f2 = False
f3 = False
for n in S:
if not f1:
if n == n1:
f1 = True
elif not f2:
if n == n2:
f2 = True
elif not f3:
if n == n3:
f3 = True
break
if f1 and f2 and f3:
ans += 1
print(ans)
|
import sys
readline = sys.stdin.readline
N = int(readline())
S = readline().rstrip()
ans = 0
numlist = [[] for i in range(10)]
for i in range(len(S)):
numlist[int(S[i])].append(i)
ans = 0
import bisect
for i in range(1000):
target = str(i).zfill(3)
now = 0
for j in range(len(target)):
tar = int(target[j])
pos = bisect.bisect_left(numlist[tar], now)
if pos >= len(numlist[tar]):
break
now = numlist[tar][pos] + 1
else:
ans += 1
print(ans)
| 1 | 128,890,055,223,230 | null | 267 | 267 |
n = int(input()[-1])
if n in [2, 4, 5, 7, 9]:
print("hon")
elif n == 3:
print("bon")
else:
print("pon")
|
n=int(input())
if n%10==3:
print("bon")
elif n%10==0 or n%10==1 or n%10==6 or n%10==8:
print("pon")
else:
print("hon")
| 1 | 19,428,101,084,380 | null | 142 | 142 |
N=int(input())
list1 = list(map(int, input().split()))
list2=[]
for i in list1:
if i%2==0:
list2.append(i)
else:
continue
list3=[]
for j in list2:
if j%3==0 or j%5==0:
list3.append(j)
else:
continue
x=len(list2)
y=len(list3)
if x==y:
print('APPROVED')
else:
print('DENIED')
|
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,304,809,446,368 | null | 217 | 217 |
from math import factorial
n,a,b=map(int,input().split())
mod=10**9+7
nCa=1
nCb=1
tmp=n
for i in range(a):
nCa*=tmp
tmp-=1
nCa%=mod
nCa=nCa*pow(factorial(a),mod-2,mod)%mod
tmp=n
for i in range(b):
nCb*=tmp
tmp-=1
nCb%=mod
nCb=nCb*pow(factorial(b),mod-2,mod)%mod
print(((pow(2,n,mod))-nCa-nCb-1)%mod)
|
N ,a, b = map(int,input().split())
MOD = pow(10,9) + 7
A = 1
for i in range(a):
A = A*(N-i)*pow(i+1,MOD-2,MOD)%MOD
B = 1
for i in range(b):
B = B*(N-i)*pow(i+1,MOD-2,MOD)%MOD
alll = pow(2,N,MOD) -1
#nota = cmb(N,a,MOD)
#notb = cmb(N,b,MOD)
ans = alll - (A+B)
ans = ans%MOD
print(ans)
| 1 | 66,044,640,783,560 | null | 214 | 214 |
T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())
d1 = (A1 - B1) * T1
d2 = d1 + (A2 - B2) * T2
if (d1 > 0 and d2 > 0) or (d1 < 0 and d2 < 0):
print(0)
exit()
if d2 == 0:
print('infinity')
exit()
d1 = abs(d1)
d2 = abs(d2)
if d1 % d2 == 0:
print(d1 // d2 * 2)
else:
print(1 + d1 // d2 * 2)
|
a = int(input())
b = int(input())
ans = list(filter(lambda x: x != a and x != b, [1, 2, 3]))
print(ans[0])
| 0 | null | 121,628,849,026,172 | 269 | 254 |
from collections import deque
K=int(input())
queue=deque(list(range(1,10)))
for i in range(K):
k=queue.popleft()
mod=k%10
for diff in range(mod-1,mod+2):
if diff<0 or 9<diff:
continue
queue.append(10*k+diff)
print(k)
|
def main():
import sys
input = sys.stdin.readline
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in range(n)]
ab = [(x,y) for x,y in zip(a,b)]
from operator import itemgetter
ab = sorted(ab,key=itemgetter(0),reverse=True)
dp = [[-10**14]*(n+1) for i in range(n+1)]
dp[0][0] = 0
for i in range(n):
for j in range(i+2):
if j >= 1:
dp[i+1][j] = max(dp[i][j]+ab[i][0]*abs(ab[i][1]-(n-1-(i-j))),dp[i][j-1]+ab[i][0]*abs(ab[i][1]+1-j))
if j == 0:
dp[i+1][0] = dp[i][0] + ab[i][0]*abs(ab[i][1]-(n-1-i))
print(max(dp[n]))
if __name__ == '__main__':
main()
| 0 | null | 36,841,745,011,722 | 181 | 171 |
n,m=map(int,input().split())
ans=[0 for i in range(n+1)]
list_tonari=[[] for i in range(n+1)]
for i in range(m):
a,b=map(int,input().split())
list_tonari[a].append(b)
list_tonari[b].append(a)
const=list()
const.append(1)
const_vary=list()
while True:
const_vary=const
const=[]
while len(const_vary):
get=const_vary.pop()
for n in list_tonari[get]:
if ans[n] ==0:
ans[n]=get
list_tonari[n].remove(get)
const.append(n)
if len(const)==0:
break
print("Yes")
for n in ans[2:]:
print(n)
|
from collections import deque
N,M = map(int,input().split())
grap = [[] for _ in range(N+1)]
for i in range(M):
a,b = map(int,input().split())
grap[a].append(b)
grap[b].append(a)
dist = [-1] * (N +1)
dist[0] = 0
dist[1] = 0
d = deque()
d.append(1)
while d:
v = d.popleft()
for i in grap[v]:
if dist[i] != -1:
continue
dist[i] = v
d.append(i)
if -1 in dist:
print('No')
else:
print('Yes',*dist[2:],sep='\n')
| 1 | 20,554,285,477,286 | null | 145 | 145 |
N,M = map(int, input().split())
S = input()
cnt = 0
for s in S:
if s == "0":
cnt = 0
else:
cnt += 1
if cnt >= M:
print(-1)
exit()
"""
辞書順最小
・より少ない回数でゴール
・同じ回数なら、低い数字ほど左にくる
N歩先がゴール → 出目の合計がNになったらOK
iマス目を踏むとゲームオーバー → 途中で出目の合計がiになるとアウト
ただ、辞書順が厄介
N=4, 00000があったとして、M=3の場合、3->1より1->3の方が辞書順で若い。なので、スタート地点から貪欲に進めるだけ進む、は条件を満たさない。
→ ゴールからスタートに帰る。移動方法は貪欲にする。
"""
ans = []
rS = S[::-1]
l = 0
r = 1
while l < N:
r = l + 1
stoppable = l
while r - l <= M and r <= N:
if rS[r] == "0":
stoppable = r
r += 1
ans.append(stoppable - l)
l = stoppable
print(*ans[::-1])
|
#
# m_solutions2020 b
#
import sys
from io import StringIO
import unittest
class TestClass(unittest.TestCase):
def assertIO(self, input, output):
stdout, stdin = sys.stdout, sys.stdin
sys.stdout, sys.stdin = StringIO(), StringIO(input)
resolve()
sys.stdout.seek(0)
out = sys.stdout.read()[:-1]
sys.stdout, sys.stdin = stdout, stdin
self.assertEqual(out, output)
def test_入力例_1(self):
input = """7 2 5
3"""
output = """Yes"""
self.assertIO(input, output)
def test_入力例_2(self):
input = """7 4 2
3"""
output = """No"""
self.assertIO(input, output)
def resolve():
A, B, C = map(int, input().split())
K = int(input())
for i in range(K):
if A >= B:
B *= 2
elif B >= C:
C *= 2
if A < B < C:
print("Yes")
break
else:
print("No")
if __name__ == "__main__":
# unittest.main()
resolve()
| 0 | null | 72,975,272,686,080 | 274 | 101 |
import math
N = int(input())
result = N
for i in range(1, int(math.sqrt(N))+2):
if N % i == 0:
result = min(result, i - 1 + N//i - 1)
print(result)
|
S, T = [input() for x in range(2)]
max_match_len = 0
for i in range(len(S)):
if len(S) - len(T) < i:
break
compare_s = S[i:i+len(T)]
match_len = 0
for j in range(len(T)):
if compare_s[j] == T[j]:
match_len += 1
else:
if max_match_len < match_len:
max_match_len = match_len
print(len(T) - max_match_len)
| 0 | null | 82,378,317,967,440 | 288 | 82 |
def main():
N,M = map(int,input().split())
A = list(map(int,input().split()))
cnt = 0
for i in range(M):
cnt += A[i]
if N < cnt:
return -1
else:
return N - cnt
print(main())
|
list = []
n, m = map(int, input().split())
a = input().split()[0:m]
for num in a:
num = int(num)
list.append(num)
answer = n - sum(list)
if n < sum(list):
answer = -1
print(answer)
| 1 | 32,063,445,741,180 | null | 168 | 168 |
import sys
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
N, u, v = map(int, input().split())
u -= 1
v -= 1
Tree = [[] for _ in range(N)]
for _ in range(N-1):
A, B = map(lambda x:int(x)-1, input().split())
Tree[A].append(B)
Tree[B].append(A)
#u-v間の単純pathを用意する
path = []
def connected(v, tv, p=-1):
if v == tv:
return True
for w in Tree[v]:
if w == p:
continue
elif connected(w, tv, v):
path.append(w)
return True
return False
connected(v, u)
path.append(v)
#u-v間の点からvとは逆方向にdfs
#u-vの中点から調べれば十分(中点よりvに寄ると、青木君は捕まってしまう)
def dfs(v, p):
d = -1
for w in Tree[v]:
if w == p:
continue
else:
d = max(d, dfs(w, v))
return d + 1
dist = len(path)
mid = path[dist//2 - 1]
par = path[dist//2]
ans = dfs(mid, par)
print(ans + (dist-1)//2)
|
import sys
sys.setrecursionlimit(10 ** 8)
n, u, v = map(int, input().split())
to = [[] for _ in range(n + 1)]
for _ in range(n - 1):
a, b = map(int, input().split())
to[a].append(b)
to[b].append(a)
def DFS(s, dist, to, d = 0, p = -1):
dist[s] = d
for v in to[s]:
if v == p:
continue
DFS(v, dist, to, d + 1, s)
def calcDist(s, dist, to):
DFS(s, dist, to)
distU = [0] * (n + 1)
distV = [0] * (n + 1)
calcDist(u, distU, to)
calcDist(v, distV, to)
ans = 0
for i in range(n + 1):
if distU[i] < distV[i]:
ans = max(ans, distV[i])
print(ans - 1)
| 1 | 117,097,905,201,282 | null | 259 | 259 |
import math
def caracal_vs_monster():
"""
2**0 個 5
/ \
2**1 個 2.5 2.5
/ \ / \
2**2 個 1.25 1.25 1.25 1.25
/ \ / \ / \ / \
2**3 個 0.625 0.625 ...
"""
# 入力
H = int(input())
# H / 2 の何回目で1になるか
count = int(math.log2(H))
# 攻撃回数
attack_count = 0
for i in range(count+1):
attack_count += 2 ** i
return attack_count
result = caracal_vs_monster()
print(result)
|
from functools import lru_cache
@lru_cache(maxsize=None)
def solve(n):
if n == 1:
return 1
else:
return solve(n//2) * 2 + 1
H = int(input())
print(solve(H))
| 1 | 80,130,454,341,012 | null | 228 | 228 |
N = int(input())
a = list(map(int, input().split()))
s = 0
for i in range(N):
s ^= a[i]
for i in range(N):
a[i] ^= s
for i in range(N):
print(a[i])
|
H, W = map(int, input().split())
S = []
for _ in range(H):
S.append(input())
import queue, itertools
dxy = ((1,0), (-1,0), (0,1), (0,-1))
ans = 0
for s in itertools.product(range(H), range(W)):
if S[s[0]][s[1]] == '#': continue
q = queue.Queue()
dist = [[-1]*W for _ in range(H)]
q.put(s)
dist[s[0]][s[1]] = 0
while not q.empty():
y, x = q.get()
for dx, dy in dxy:
nx, ny = x+dx, y+dy
if nx<0 or ny<0 or nx>=W or ny>=H or S[ny][nx] == '#' or dist[ny][nx] >= 0:
continue
dist[ny][nx] = dist[y][x] + 1
q.put((ny, nx))
ans = max(ans, max(map(max, dist)))
print(ans)
| 0 | null | 53,430,662,695,520 | 123 | 241 |
N = int(input())
A = list(map(int,input().split()))
from collections import Counter
ctr = Counter(A)
ans = [ctr[i+1] for i in range(N)]
print(*ans, sep='\n')
|
N, K = map(int, input().split())
MOD = 10 ** 9 + 7
ans = 0
ctr = [0] * (K + 1)
for x in reversed(range(1, K + 1)):
ctr[x] = pow(K // x, N, MOD)
for y in range(2 * x, K + 1, x):
ctr[x] -= ctr[y]
ans = 0
for n in range(1, K + 1):
ans += n * ctr[n]
ans %= MOD
print(ans)
| 0 | null | 34,661,214,475,260 | 169 | 176 |
a,b = (input().split())
print(int(a)*int(b))
|
print(eval(input().replace(' ','*')))
| 1 | 15,936,506,113,750 | null | 133 | 133 |
command_num = int(input())
dict = set([])
for i in range(command_num):
in_command, in_str = input().rstrip().split(" ")
if in_command == "insert":
dict.add(in_str)
elif in_command == "find":
if in_str in dict:
print("yes")
else:
print("no")
|
"""
n=int(input())
s=[int(x) for x in input().split()]
q=int(input())
t=[int(x) for x in input().split()]
#print(s)
c=0
for i in t:
if i in s:
c+=1
print(c)
"""
"""
n=int(input())
s=[int(x) for x in input().split()]
q=int(input())
t=[int(x) for x in input().split()]
#binary search
a=0
for i in range(q):
L=0
R=n-1#探索する方の配列(s)はソート済みでないといけない
while L<=R:
M=(L+R)//2
if s[M]<t[i]:
L=M+1
elif s[M]>t[i]:
R=M-1
else:
a+=1
break
print(a)
"""
#Dictionary
#dict型オブジェクトに対しinを使うとキーの存在確認になる
n=int(input())
d={}
for i in range(n):
command,words=input().split()
if command=='find':
if words in d:
print('yes')
else:
print('no')
else:
d[words]=0
| 1 | 76,541,413,742 | null | 23 | 23 |
def abc164_d():
# 解説放送
s = str(input())
n = len(s)
m = 2019
srev = s[::-1] # 下の位から先に見ていくために反転する
x = 1 # 10^i ??
total = 0 # 累積和 (mod 2019 における累積和)
cnt = [0] * m # cnt[k] : 累積和がkのものが何個あるか
ans = 0
for i in range(n):
cnt[total] += 1
total += int(srev[i]) * x
total %= m
ans += cnt[total]
x = x*10 % m
print(ans)
abc164_d()
|
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)]
s = input()
n = int(s)
l = len(s)
cnt = 0
mod = [0]*2019
m = 0
for i in range(l):
m = (int(s[l-1-i])*pow(10,i,2019) + m)%2019
mod[m] += 1
cnt += mod[0]
for i in range(2019):
if mod[i] > 1:
cnt += (mod[i]*(mod[i]-1))/2
#print(i)
print(int(cnt))
| 1 | 30,896,998,800,772 | null | 166 | 166 |
A,B = [int(v) for v in input().split()]
if A > 0 and A < 10 and B > 0 and B < 10:
print(A*B)
else:
print(-1)
|
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop, heapify
from functools import reduce, lru_cache
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10
N = INT()
A = LIST()
LR = [[A[-1], A[-1]]]
for b in A[::-1][1:]:
LR.append([-(-LR[-1][0]//2)+b, LR[-1][1]+b])
LR = LR[::-1]
if LR[0][0] <= 1 <= LR[0][1]:
pass
else:
print(-1)
exit()
ans = 1
tmp = 1
for i, (L, R) in enumerate(LR[1:], 1):
tmp = min(2*tmp-A[i], R-A[i])
ans += tmp+A[i]
print(ans)
| 0 | null | 88,608,528,480,196 | 286 | 141 |
def main():
x, y, z = map(int, input().split(" "))
print(f"{z} {x} {y}")
if __name__ == "__main__":
main()
|
import sys
readline = sys.stdin.readline
H1,M1,H2,M2,K = map(int,readline().split())
print(max(0,(H2 * 60 + M2) - (H1 * 60 + M1 + K)))
| 0 | null | 28,103,211,867,810 | 178 | 139 |
word = input()
n = len(word)
hanbun = int((n-1)/2)
notk = 0
for i in range(hanbun):
if word[i] != word[n-i-1]:
notk = 1
break
if hanbun % 2 == 0:
hanbun2 = int(hanbun/2)
else:
hanbun2 = int((hanbun-1)/2)
for j in range(hanbun2):
if word[j] != word[hanbun-j-1]:
notk = 1
break
if notk == 1:
print('No')
else:
print('Yes')
|
a = str(input())
if a.isupper() == True:
print('A')
else:
print('a')
| 0 | null | 28,764,467,015,372 | 190 | 119 |
n = int(input())
al = 26
alf='abcdefghijklmnopqrstuvwxyz'
na = ''
while n >26:
na = alf[(n-1)%al]+na
n = (n-1)//al
na = alf[(n-1)%al]+na
print(na)
|
n = int(input())
def calc(m, res):
q, mod = divmod(m, 26)
if (mod == 0):
q = q - 1
mod = 26
res = chr(ord("a") + (mod - 1)) + res
else:
res = chr(ord("a") + (mod - 1)) + res
if (q > 0):
calc(q, res)
else:
print(res)
return
calc(n, "")
| 1 | 11,954,085,894,088 | null | 121 | 121 |
# D - Prediction and Restriction
N,K = map(int,input().split())
RSP = tuple(map(int,input().split()))
T = input()
# じゃんけんの勝敗を返す関数
def judge(a,b):
if a == 'r' and b == 2:
return True
elif a == 's' and b == 0:
return True
elif a == 'p' and b == 1:
return True
return False
# dp[i][j]: i 回目のじゃんけんで j を出したときの最大値
# グー:0, チョキ:1, パー:2
dp = [[0]*3 for _ in range(N+1)]
# 初期条件 v < K のときは全て勝つ
for i in range(1,K+1):
for j in range(3):
if judge(T[i-1],j):
dp[i][j] = RSP[j]
# K 以下の数字について
for v in range(1,K+1):
# w = v, v+K, v+2K,...
for w in range(v+K,N+1,K):
# w 回目に出した手
for l in range(3):
# w-K 回目に出した手
for m in range(3):
if l == m:
continue
# じゃんけんで勝ったとき
if judge(T[w-1],l):
if w-K>=0:
dp[w][l] = max(dp[w][l],dp[w-K][m] + RSP[l])
# じゃんけんで負けか引き分けたとき
dp[w][l] = max(dp[w][l],dp[w-K][m])
# K 個に分けた各グループの部分和の最大値の総和を求める
ans = 0
for a in range(1,K+1):
ans += max(dp[-a])
print(ans)
|
N,K = map(int,input().split())
R,S,P = map(int,input().split())
T = input()
ans = 0
memo = [0 for i in range(N)]
for i in range(N):
check = T[i]
if i >= K and T[i-K] == check and memo[i-K] == 0:
memo[i] = 1
continue
if check == "r":
ans += P
elif check == "p":
ans += S
elif check == "s":
ans += R
print(ans)
| 1 | 106,480,277,645,542 | null | 251 | 251 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.