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())
print(- n % 1000) | S, T = map(str, input().split())
A, B = map(int, input().split())
U = input()
if U == S:
A -= 1
A = str(A)
B = str(B)
print(A+' '+B)
else :
B -= 1
A = str(A)
B = str(B)
print(A+' '+B) | 0 | null | 40,315,717,648,508 | 108 | 220 |
n, a, b = list(map(int, input().split()))
whole = n // (a + b)
rest = n % (a + b)
blue = whole * a
if rest <= a:
blue += rest
else:
blue += a
print(blue) | N,A,B=map(int,input().split())
print(A*(N//(A+B))+min(A,N%(A+B))) | 1 | 55,589,613,676,412 | null | 202 | 202 |
S = input()
ans = {0:1}
memo = [0]
last = 1
for ind, s in enumerate(S[::-1]):
memo.append((int(s) * last + memo[-1]) % 2019)
last *= 10
last %= 2019
if(memo[-1] in ans):
ans[memo[-1]] += 1
else:
ans[memo[-1]] = 1
res = 0
for key in ans.keys():
res += ans[key]*(ans[key]-1)//2
pri... | import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from collections import defaultdict
def main():
s = tuple(map(int, input()))
lens = len(s)
d1 = defaultdict(int)
ss = 0
num10 = 1
for se in s[::-1]:
ss += (int(se) * num10) % 2019
ss = ss % 2019
d1[ss] += 1... | 1 | 30,850,728,417,212 | null | 166 | 166 |
import sys
def solve():
n = int(sys.stdin.readline())
ans = 0
for i in range(n):
num = int(sys.stdin.readline())
ans += is_prime(num)
print(ans)
def is_prime(n):
if n < 2:
return False
for p in range(2, n + 1):
if p*p > n:
break
if n % p ... | # -*- coding: utf-8 -*-
import math
def prime_number_identifier(num):
for candidate in range(2, int(math.sqrt(num)) + 1):
if num % candidate == 0:
return False
return True
input_num = int(raw_input())
counter = 0
found_number = 0
while counter < input_num:
candidate_number = int(raw_i... | 1 | 10,578,811,410 | null | 12 | 12 |
a2=list(input())
if a2[0]!=a2[1] and a2[2]==a2[3] and a2[4]==a2[5]:
print('Yes')
else:
print('No') | import sys
sys.setrecursionlimit(10**7)
input = lambda: sys.stdin.readline().strip()
def main():
S = input()
print("Yes" if S[2]==S[3] and S[4]==S[5] else "No")
main()
| 1 | 42,076,931,863,020 | null | 184 | 184 |
n=int(input())
m=int(n/1.08)
for i in range(-2,3):
if int((m+i)*1.08)==n:
print(m+i)
exit()
print(":(") | n = int(input())
if n/1.08==n//1.08:
print(n//1.08)
elif int(-(-n//1.08) * 1.08) == n:
print(int(-(-n//1.08)))
else:
print(':(') | 1 | 126,051,815,446,888 | null | 265 | 265 |
data = input()
#data = '\\\\///\\_/\\/\\\\\\\\/_/\\\\///__\\\\\\_\\\\/_\\/_/\\'
diff = {'\\':-1, '_':0, '/':1}
height = [0]
[height.append(height[-1]+diff[i]) for i in data]
bottom = min(height)
height = [h-bottom for h in height]
m = max(height)
water = [m for h in height]
height00 = [0] + height + [0]
water00 = [0]... | f = list(input())
s = []
for i, v in enumerate(f):
if v == '\\':
s.append([v, i])
elif v == '/' and len(s) > 0:
n = s.pop()
if n[0] == '\\':
t = i-n[1]
s.append(['.', t])
elif len(s) > 0:
j = len(s)-1
n1 = n[1]
while j ... | 1 | 58,048,545,860 | null | 21 | 21 |
#!/usr/bin/env python3
import sys
from collections import deque
YES = "Yes" # type: str
def solve(N: int, M: int, A: "List[int]", B: "List[int]"):
dq = deque([])
traversed = [False for _ in range(N+1)]
ans = [None for _ in range(N+1)]
G = {n : set([]) for n in range(1, N+1)}
for a, b in zip(A,B... | import sys
import math
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import defaultdict
MOD = 10**9+7
N = int(input())
dic = defaultdict(int)
zero = 0
left_zero = 0
right_zero = 0
for i in range(N):
a, b = map(int, input().split())
if b < 0:
a = -a
b = -b
if a == ... | 0 | null | 20,630,106,229,008 | 145 | 146 |
#! /usr/bin/env python
#-*- coding: utf-8 -*-
''' ?????\????????? '''
#
# ?¨??????????O()
def insertion_sort(A, N):
for i in range(N):
tmp = A[i]
j = i - 1
while j >= 0 and A[j] > tmp:
A[j + 1] = A[j]
j -= 1
A[j + 1] = tmp
print(' '.join(map(str... | from collections import defaultdict
N = int(input())
dic = defaultdict(int)
for n in range(1,N+1):
s = str(n)
dic[(int(s[0]), int(s[-1]))] += 1
res = 0
for key, value in dic.items():
a, b = key
cnt = dic.get((b,a),0)
res += value * cnt
print(res)
| 0 | null | 43,168,874,475,168 | 10 | 234 |
N = int(input())
A = list(map(int, input().split()))
assert len(A) == N
total = 0
sum_A = sum(A)
for i,ai in enumerate(A):
sum_A -= ai
total += ai * sum_A
print(total % (10 ** 9 + 7)) | import bisect
N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
for i in range(N-1, 1, -1):
for j in range(i-1, 0, -1):
a, b = L[i], L[j]
c = a - b + 1
if c > b: continue
ans += (j - bisect.bisect_left(L, c))
print(ans) | 0 | null | 87,591,900,464,992 | 83 | 294 |
N = int(input())
if N % 2 == 1:
print(0)
exit()
ans = 0
i = 1
while 5 ** i * 2 <= N:
ans += N // (5 ** i * 2)
i += 1
print(ans)
| import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
n = int(input())
if n & 1:
print(0)
exit()
ans = 0
n //= 2
while n:
ans += n // 5
n //= 5
print(ans)
| 1 | 115,853,859,362,010 | null | 258 | 258 |
class diceClass:
label = []
def __init__(self,l):
if len(l) == 6:
self.label = l
def move(self,c):
if c.upper() == 'N':
buf = []
buf.append(self.label[1])
buf.append(self.label[5])
buf.append(self.label[2])
buf.append(se... |
import sys
input = sys.stdin.readline
class Dice:
"""
0:top, 1:south, 2:east, 3:west, 4:north, 5:bottom
"""
def __init__(self, surfaces):
self.surface = surfaces
def roll(self, direction: str):
if direction == "E":
self.surface = [self.surface[3], self.surface[1], se... | 1 | 239,952,423,528 | null | 33 | 33 |
s=list(map(int,input().split()))
ans="Yes" if len(set(s))==2 else "No"
print(ans) | N= int(input())
n = N % 10
if n == 2 or n==4 or n ==5 or n == 7 or n == 9:
print('hon')
elif n == 0 or n ==1 or n == 6 or n == 8:
print('pon')
elif n == 3:
print('bon') | 0 | null | 43,902,238,948,572 | 216 | 142 |
W = input()
ans = 0
count = 0
for i in range(len(W)):
if W[i] == "R":
count += 1
ans = max(ans,count)
else:
count = 0
print(ans) | s = input()
cnt = 0
if s == 'RSR':
cnt = 1
else:
for i in range(3):
if s[i] == 'R':
cnt += 1
print(cnt) | 1 | 4,872,310,555,250 | null | 90 | 90 |
import math
r = float(input())
a = math.pi * r * r
l = 2 * math.pi * r
print(f'{a} {l}')
| # coding=utf-8
from math import pi
r = float(raw_input().strip())
print "{0:f} {1:f}".format(pi * r * r, 2 * pi * r) | 1 | 634,527,398,560 | null | 46 | 46 |
n = int(input())
a = list(map(int,input().split()))
a.reverse()
for i in range(n-1):
print(a[i],end = " ")
print(a[n-1]) | count = int(raw_input())
arr = map(int, raw_input().split())
arr.reverse()
print(" ".join(map(str, arr))) | 1 | 959,361,917,728 | null | 53 | 53 |
se = set([])
n = int(raw_input())
for i in range(n):
s = raw_input().split()
if s[0] == 'insert':
se.add(s[1])
elif s[0] == 'find':
if s[1] in se:
print 'yes'
else:
print 'no' | dic = set()
n = int(input())
for i in range(n):
s = input()
if s[0] == 'i':
dic.add(s[7:])
else: print("yes" if s[5:] in dic else "no")
| 1 | 77,469,898,110 | null | 23 | 23 |
string = input()
if string == "ARC": print("ABC")
else: print("ARC") | read = lambda: list(map(int, input().split()))
d, t, s = read()
if d / s > t:
print("No")
else:
print("Yes") | 0 | null | 13,874,118,991,520 | 153 | 81 |
while True:
n,x = map(int,input().split(" "))
if n == 0 and x == 0:
break
#データリスト作成
data = [m for m in range(1,n+1)]
data_list = []
cnt = 0
#n種類の数字があって、xになる組み合わせは?
for i in range(1,n+1):
for j in range(1+i,n+1):
for k in range(1+j,n+1):
if i+j+k == x:
cnt += 1
print(cnt)
| while True:
(n, x) = [int(i) for i in input().split()]
if n == x == 0:
break
dataset = []
for a in range(1, n + 1):
for b in range(a + 1, n + 1):
for c in range(b + 1, n + 1):
dataset.append([a,b,c])
count = 0
for data in dataset:
if sum(data... | 1 | 1,302,982,983,356 | null | 58 | 58 |
nn=int(input())
nc = [0] * (nn + 1)
for x in range(1, 100):
for y in range(1, 100):
for z in range(1, 100):
a = x * x + y * y + z * z + x * y + x * z + y * z
if a > nn:
break
nc[a] += 1
for i in range(1, nn + 1):
print(nc[i]) | N = int(input())
ans = 0
if N % 1000 == 0:
print(ans)
else:
a = N // 1000
ans = (a+1)*1000 - N
print(ans) | 0 | null | 8,214,994,288,082 | 106 | 108 |
n = int(input())
x = list(map(int,input().split()))
a = min(x)
b = max(x) + 1
ans = 10 ** 8
for p in range(a,b):
m = 0
for i in range(n):
m += (x[i] - p) ** 2
ans = min(ans,m)
print(ans) | N=int(input())
X=list(map(int,input().split()))
Y=[]
for i in range(1,101):
tot=0
for n in range(N):
tot+=(X[n]-i)**2
Y.append(tot)
print(min(Y)) | 1 | 65,109,918,848,352 | null | 213 | 213 |
n=int(input())
if n%2==0:
print("0.5")
if n%2==1:
print((int(n/2)+1)/n) | #!/usr/bin/env python3
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(read())
odd = 0
for n in range(N):
n += 1
if n%2==1:
odd += 1
print(odd/N) | 1 | 177,254,185,202,810 | null | 297 | 297 |
n, k = map(int, input().split())
print(sum(int(i) >= k for i in input().split())) | n,k = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
res = 0
for i in range(n):
if k <= a[i]:
res += 1
print(res) | 1 | 178,587,492,295,126 | null | 298 | 298 |
d = list(map(int, input().split()))
op = list(input())
for o in op:
b = [x for x in d]
if o == "S":
b[0] = d[4]
b[1] = d[0]
b[4] = d[5]
b[5] = d[1]
elif o == "E":
b[0] = d[3]
b[2] = d[0]
b[3] = d[5]
b[5] = d[2]
elif o == "W":
b[0] ... | a,b,c,d = list(map(int,(input().split())))
ans=''
for i in range(100):
c-=b
if c<=0:
ans='Yes'
break
a-=d
if a<=0:
ans='No'
break
print(ans) | 0 | null | 14,962,662,125,020 | 33 | 164 |
MOD = 1000000007
def mod_pow(x , y):
if y == 0:
return 1
if y == 1:
return x
r = mod_pow(x , y // 2)
r2 = (r * r) % MOD
if y % 2 == 0:
return r2 % MOD
else:
return (r2 * x) % MOD
N , K = map(int , input().split())
result = 0
memo = {}
for g in range(K , 0 , -1):
... | from math import *
n = input()
x = map(float, raw_input().split())
y = map(float, raw_input().split())
for i in range(1,4):
temp = 0
for j in range(n):
temp += fabs(x[j]-y[j])**i
print pow(temp,1.0/i)
d = 0
for i in range(n):
if(fabs(x[i]-y[i]) > d):
d = fabs(x[i]-y[i])
print d | 0 | null | 18,368,176,857,370 | 176 | 32 |
K=int(input())
A,B=map(int,input().split())
print("OK" if B//K*K >= A else "NG") | K = int(input())
A, B = map(int, input().split())
if (B // K)*K >= A: print('OK')
else: print('NG') | 1 | 26,565,295,793,570 | null | 158 | 158 |
def Base_10_to_n(X, n):
if int(X/n):
return Base_10_to_n(int(X/n), n) + str(X%n)
return str(X%n)
N, K = map(int, input().split())
print(len(Base_10_to_n(N,K)))
| import math
N, K = map(int, input().split())
if N != 1:
res = math.log(N, K)
else:
res = 1
print(math.ceil(res)) | 1 | 64,296,802,540,818 | null | 212 | 212 |
def find(x):
if par[x] == x:
return x
else:
par[x] = find(par[x]) #経路圧縮
return par[x]
def same(x,y):
return find(x) == find(y)
def unite(x,y):
x = find(x)
y = find(y)
if x == y:
return 0
par[x] = y
size[y] = size[x] + size[y]
size[x] = 0
N,M = map(int... | class UnionFind():
# 作りたい要素数nで初期化
# 使用するインスタンス変数の初期化
def __init__(self, n):
self.n = n
# root[x]<0ならそのノードが根かつその値が木の要素数
# rootノードでその木の要素数を記録する
self.root = [-1]*(n+1)
# 木をくっつける時にアンバランスにならないように調整する
self.rnk = [0]*(n+1)
# ノードxのrootノードを見つける
def Find_Root(se... | 1 | 2,293,722,742,302 | null | 70 | 70 |
#E
N,K = map(int,input().split())
A = list(map(int,input().split()))
F = list(map(int,input().split()))
A.sort(reverse=True)
F.sort()
left = 0
right = 10**12
while True:
mid = (left+right)//2
if right - left <= 1:
count = 0
for i in range(N):
a = left//F[i]
count+=max(0... | import sys
import collections
s=sys.stdin.readlines()
n,q=map(int,s[0].split())
d=collections.deque(e.split()for e in s[1:])
t=0
while d:
k,v=d.popleft()
v=int(v)
if v>q:
v-=q
t+=q
d.append([k,v])
else:
t+=v
print(k,t)
| 0 | null | 82,739,537,236,512 | 290 | 19 |
n = int(input())
r = [int(input()) for _ in range(n)]
mi = r[0]
mx = -1e10
for j in range(1, len(r)):
mx = max(mx, (r[j] - mi))
mi = min(mi, r[j])
print(mx) | while(True):
h,w=map(int,input().split())
if h==0 and w==0:
break
rect='#'*w+'\n'
rect+=('#'+'.'*(w-2)+'#\n')*(h-2)
rect+='#'*w+'\n'
print(rect) | 0 | null | 430,959,479,240 | 13 | 50 |
x = int(input())
print((x == 0) * 1 + (x == 1) * 0) | N = int(input())
if N%2 == 1 or N <= 9:
print(0)
else:
t = 10
ans = 0
while N >= t:
ans += N//t
t *= 5
print(ans) | 0 | null | 59,266,126,364,032 | 76 | 258 |
import math
def koch(d, a, b):
if d== 0:
return
s=[0,0]
t=[0,0]
u=[0,0]
s[0] = (2.0*a[0]+1.0*b[0])/3.0
s[1] = (2.0*a[1]+1.0*b[1])/3.0
t[0] = (1.0*a[0]+2.0*b[0])/3.0
t[1] = (1.0*a[1]+2.0*b[1])/3.0
u[0] = (t[0] - s[0])*math.cos(math.radians(60))-(t[1] - s[1])*math.sin(mat... | import math
dig_six = math.radians(60)
def koch(d, p1, p2):
if d == 0:
return d
#calc s, u, t from p1, p2
s_x = (2*p1[0]+1 * p2[0]) / 3
s_y = (2*p1[1]+1 * p2[1]) / 3
s = (s_x, s_y)
t_x = (1*p1[0]+2 * p2[0]) / 3
t_y = (1*p1[1]+2 * p2[1]) / 3
t = (t_x, t_y)
u_x = (t_x - s_x)*m... | 1 | 120,288,492,672 | null | 27 | 27 |
n = [int(x) for x in input().split()]
print(*sorted(n)) | arr = map(int,raw_input().split())
arr.sort()
arr = map(str,arr)
print ' '.join(arr) | 1 | 411,393,977,468 | null | 40 | 40 |
# -*- coding: utf-8 -*-
import math
errerN=1
while errerN:
try:
a=list(map(int, input().split()))
gcdN=math.gcd(a[0],a[1])
print(gcdN, int(a[0]*a[1]/gcdN))
except :
errerN=0
| def get_depth(graph,tmp_depth,vertex_list,depth_list):
new_vertex_list=[]
for vertex in vertex_list:
for j in range(len(depth_list)):
if(graph[vertex][j]!=0 and depth_list[j]==-1):
depth_list[j]=tmp_depth + 1
new_vertex_list.append(j)
if(len(new_vertex_lis... | 0 | null | 2,725,928,842 | 5 | 9 |
import math
r=input()
a=r*r*math.pi
b=2*r*math.pi
print "%f %f"%(a,b) | N = int(input())
mod = 10 ** 9 +7
x = (10**N)%mod
y = (2*(9**N))%mod
z = (8**N)%mod
print((x-y+z)%mod)
| 0 | null | 1,913,998,605,508 | 46 | 78 |
import numpy as np #numpyの練習がてら
n = int(input())
tmp = list(map(int,input().split()))
mod = 10**9 + 7
a = np.array(tmp,np.int64)
ans = 0
for i in range(60 + 1):
b = (a >> i) & 1 #すべてのaについて2**n乗目のビットが1か否か
iti = np.count_nonzero(b) #すべてのaのうち2**n乗目が1であるものの個数
zero = n - iti #同様に0であるものの個数
ans += (iti * zer... | n,k=map(int,input().split())
ans=[1]*n
for _ in range(k):
d=int(input())
li=list(map(int,input().split()))
for i in li:
ans[i-1]=0
print(sum(ans)) | 0 | null | 74,140,716,070,080 | 263 | 154 |
S, W = [int(n) for n in input().split()]
print('unsafe' if S <= W else 'safe') | n=int(input())
s=list(input())
ans=0
for i in range(10):
if str(i) in s:
first=s.index(str(i))
ss=s[first+1:]
for j in range(10):
if str(j) in ss:
sec=ss.index(str(j))
for k in range(10):
if str(k) in ss[sec+1:]:
... | 0 | null | 79,167,990,217,120 | 163 | 267 |
n = int(input())
print(sum([(n-1)//a for a in range(1, n)]))
| import sys
def input(): return sys.stdin.readline().rstrip()
class mod_comb3:
def __init__(self,mod=10**9+7,n_max=1):
self.mod,self.n_max=mod,n_max
self.fact,self.inv,self.factinv=[1,1],[0,1],[1,1]
if 1<n_max:setup_table(n_max)
def comb(self,n,r):
if r<0 or n<r:return 0
i... | 0 | null | 49,040,580,280,242 | 73 | 242 |
import sys
# import re
# import math
# import collections
# import decimal
# import bisect
# import itertools
# import fractions
# import functools
import copy
# import heapq
# import decimal
# import statistics
import queue
sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7
ni = lambda: int(sys.stdin.... | import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy
sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline(... | 1 | 143,075,957,805,450 | null | 277 | 277 |
n=input()
count=0
while 1 :
x=[i for i in input().split()]
if x[0]=="END_OF_TEXT":
break
for i in range(len(x)):
if x[i].lower()==n.lower():
count=count+1
print(count) | a = input().lower()
cnt = 0
while 1:
c = input()
if c == 'END_OF_TEXT':
break
cnt += c.lower().split().count(a)
print(cnt)
| 1 | 1,799,811,739,652 | null | 65 | 65 |
n=int(input())
s=input()
c=n
for i in range(0,n-1):
if s[i]==s[i+1]:
c-=1
print(c) | N = int(input())
S = input()
count = 1
check = S[0]
for c in S:
if c != check:
count += 1
check = c
print(count) | 1 | 170,112,627,560,788 | null | 293 | 293 |
x = int(input())
c1 = x//500
x -= 500*c1
c2 = x//5
print(1000*c1 + 5*c2) | X = int(input())
answer = (X // 500) * 1000
X %= 500
answer += (X // 5) * 5
print(answer) | 1 | 42,667,462,473,502 | null | 185 | 185 |
user_input = int(input())
print(user_input + user_input**2 + user_input**3) | from itertools import accumulate
from collections import defaultdict
n, k = map(int, input().split())
a = list(map(int, input().split()))
acc = [0] + list(accumulate(a))
sm = [(e - i) % k for i, e in enumerate(acc)]
d = defaultdict(int)
ans = 0
for r in range(1, n + 1):
if r - k >= 0:
e = sm[r - k]
... | 0 | null | 74,132,872,205,500 | 115 | 273 |
A,B,N = map(int,input().split())
if B<=N:
print(int((A*(B-1))/B)-(A*int((B-1)/B)))
else:
print(int((A*N)/B)-(A*int(N/B))) | """
最大限傾けたとき、水と接している面は横から見ると台形ないし三角形となる
水と接している面の面積 x/a が a*b/2 より大きい場合は台形となり、以下の場合は三角形となる
台形の場合
最大限傾けたとき、水と接している台形の上辺の長さをnとすると
(n+b)*a/2 = x/a
n = 2*x/(a**2) - b
求める角度をthetaとすると
tan(theta) = (b-n)/a
theta = arctan((b-n)/a)
三角形の場合
最大限傾けたとき、水と接している三角形の底辺の長さをnとすると
n*b/2 = x/a
n = 2*x/(a*b)
求める角度をthetaとすると
tan(theta) ... | 0 | null | 95,978,647,537,660 | 161 | 289 |
n = int(input())
a = [int(i) for i in input().split()]
if n // 2 == 1:
print(max(a))
exit()
if n < 20:
d = a.copy()
for i in range(1, n // 2):
b = [0] * n
c = -10 ** 24
ans = -10 ** 24
for j in range(i * 2, n):
c = max(c, a[j - 2])
b[j] = c +... | n = int(input())
al = list(map(int, input().split()))
if n%2 == 1:
dp = [ [0]*4 for _ in range(n//2+1) ]
for i in range(n//2):
dp[i+1][0] = dp[i][0] + al[i*2]
dp[i+1][1] = max(dp[i][1]+al[i*2+1], dp[i][0]+al[i*2+1])
dp[i+1][2] = max(dp[i][2]+al[i*2+2], dp[i][0]+al[i*2+2])
dp[i... | 1 | 37,453,737,624,292 | null | 177 | 177 |
x = int(input())
b = x
a = 1
while b%360!=0:
a += 1
b += x
print(a) | #from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl = lambda: list(map(int, input().split()))
inm = lambda: map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7
#R = 998244353
def ddprint(x):
if D... | 0 | null | 8,441,337,660,158 | 125 | 82 |
import sys
x,k,d=map(int,input().split())
x=abs(x)
a=x//d
if a>=k:
ans=x-k*d
elif (k-a)%2==0:
ans=x-d*a
else:
ans=x-d*a-d
print(abs(ans)) | x,k,d = list(map(int,input().split()))
x = abs(x)
point =x % d
num = x//d
if num<k:
rest = k - num
if rest%2==0:
pass
else:
point = d -point
else:
point = x - k*d
print(point) | 1 | 5,180,565,757,114 | null | 92 | 92 |
N, K = [int(a) for a in input().split()]
num_count = (N-N%K)//K
ans = min(abs(N - num_count*K), abs(N - (num_count+1)*K))
if num_count > 0:
ans = min(abs(N - (num_count-1)*K), ans)
print(ans) | import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): r... | 1 | 39,302,851,103,918 | null | 180 | 180 |
def award(x):
return max(0, 4*(10**5) - x*(10**5))
x,y = map(int,input().split())
ans = award(x)
ans += award(y)
if x == 1 and y == 1:
ans += 4*(10**5)
print(ans) | X, Y = map(int, input().split())
ans = 0
if X <= 3:
ans += (4-X) * 100000
if Y <= 3:
ans += (4-Y) * 100000
if X == Y == 1:
ans += 400000
print(ans) | 1 | 140,399,367,902,048 | null | 275 | 275 |
# -*- 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 ... | n, m = map(int, input().split())
if n%2 == 1:
a = 1
b = n+1
ans = []
for i in range(m):
a += 1
b -= 1
ans.append((a, b))
else:
a = 1
b = n+1
S = set()
ans = []
for i in range(m):
a += 1
b -= 1
r = min(b-a, n-(b-a))
if r in S or ... | 0 | null | 14,441,328,215,620 | 15 | 162 |
# --*-coding:utf-8-*--
def main():
N, K = map(int, input().split())
A = list(map(int, input().split()))
B = [0]*(N+1)
b = 0
for i, a in enumerate(A):
b += a - 1
b %= K
B[i+1] = b
Q = {}
X = 0
for i, b in enumerate(B):
if i>=K:
Q[B[i-K]] -=... | import sys
input = sys.stdin.readline
from collections import deque
N, K = map(int, input().split())
A = list(map(int, input().split()))
B = [0]
for a in A:
b = (B[-1] + (a-1)) % K
B.append(b)
ans = 0
dic = {}
for i, b in enumerate(B):
if b in dic:
dic[b].append(i)
else:
dic[b] = dequ... | 1 | 138,038,822,384,468 | null | 273 | 273 |
N = int(input())
a = [int(i) for i in input().split()]
cnt = 0
for i,v in enumerate(a,1):
if i%2 != 0 and v%2 != 0:
cnt += 1
print(cnt) | N = int(input())
A = list(map(int, input().split()))
ct = 0
for n in range(N + 1):
if n % 2:
if A[n - 1] % 2:
ct +=1
print(ct) | 1 | 7,730,316,470,930 | null | 105 | 105 |
# coding=utf-8
def solve_gcd(number1: int, number2: int) -> int:
two_list = [number1, number2]
two_list.sort()
if two_list[1] % two_list[0] == 0:
return two_list[0]
r = two_list[1] % two_list[0]
return solve_gcd(two_list[0], r)
def solve_lcm(number1: int, number2: int, number3: int) -> i... | def comb(n, k):
nu, de = 1, 1
for i in range(k):
de *= n - i
nu *= i + 1
return de // nu
def ans(N, K):
if K == 0:
return 1
N = str(int(N))
if len(N) < K or int(N) == 0:
return 0
ret = sum([9 ** K * comb(max(dig - 1, 1), K - 1)
for dig in rang... | 0 | null | 37,855,539,614,300 | 5 | 224 |
N = int(input())
D = list(map(int, input().split()))
mod = 998244353
counter = [0] * N
for d in D:
counter[d] += 1
if counter[0] != 1:
print(0)
exit()
ans = 1
for d in D[1:]:
ans = ans * counter[d-1] % mod
print(ans) | 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 | 154,809,243,970,180 | null | 284 | 284 |
H, W, K = map(int, input().split())
grid = [input() for _ in range(H)]
ans = [[0]*W for _ in range(H)]
empty_index = [False]*H
first_flg = False
cnt = 0
for i in range(H):
if '#' not in grid[i]:
empty_index[i] = True
for i in range(H):
if not empty_index[i] and not first_flg:
first_flg = True
... | H,W,K = map(int,input().split())
S = [input().strip() for _ in range(H)]
Ar = []
for i in range(H):
for j in range(W):
if S[i][j]=="#":
Ar.append(i)
break
Ar.append(H)
if len(Ar)==2:
Ac = []
for j in range(W):
if S[Ar[0]][j]=="#":
Ac.append(j)
A = [[1 ... | 1 | 143,169,035,515,452 | null | 277 | 277 |
N = int(input())
X = list(map(int,input().split()))
minimum = 10000000
for n in range(1,max(X)+1):
kyori = 0
for i in range(N):
kyori += (X[i]-n)**2
if kyori < minimum:
minimum = kyori
print(minimum) | day = ["SUN","MON","TUE","WED","THU","FRI","SAT" ]
s = input()
pos = day.index(s)
print(7-pos) | 0 | null | 99,241,154,834,540 | 213 | 270 |
n = int(input())
dictionary = {}
for i in range(n):
a = input().split()
if a[0] == "insert":
dictionary[a[1]] = 0
if a[0] == "find":
if a[1] in dictionary:
print("yes")
else:
print("no") | import math
a, b, x = map(int, input().split())
theta = math.atan((-2) * x / (a ** 3) + 2 * b / a)
if a * math.tan(theta) > b:
theta = math.atan2(a * b * b, 2 * x)
print(math.degrees(theta)) | 0 | null | 81,400,623,500,930 | 23 | 289 |
import sys
input = lambda: sys.stdin.readline().rstrip()
n = int(input())
a = [int(x) for x in input().split()]
from itertools import accumulate
a_csum = list(accumulate(a))
ans = 10**10
for i in range(n - 1):
ans = min(ans, abs(a_csum[i] - (a_csum[-1] - a_csum[i])))
print(ans) | def resolve():
N = int(input())
A = list(map(int, input().split()))
diff = 10 ** 10
partA = 0
partB = sum(A)
for i in range(N):
diff = min(diff, abs(partA-partB))
partA += A[i]
partB -= A[i]
print(diff)
return
resolve() | 1 | 142,513,202,319,328 | null | 276 | 276 |
n, *s = open(0).read().split()
n = int(n)
c0 = s.count('AC')
c1 = s.count('WA')
c2 = s.count('TLE')
c3 = n - (c0 + c1 + c2)
print('AC x ' + str(c0), 'WA x ' + str(c1), sep='\n')
print('TLE x ' + str(c2), 'RE x ' + str(c3), sep='\n')
| import math
a, b, x = map(int, input().split(' '))
x = x / a
if x > a * b / 2:
print(math.atan2((a * b - x) * 2, a ** 2) * 180 / math.pi)
else:
print(math.atan2(b ** 2, x * 2) * 180 / math.pi)
| 0 | null | 85,896,981,922,180 | 109 | 289 |
H,A = map(int,input().split())
ans = H // A
if H % A != 0: ans += 1
print(ans) | x = int(input())
xSum = 0
cnt = 1
while True:
xSum += x
if xSum%360 == 0:
break
cnt += 1
print(cnt) | 0 | null | 44,871,246,870,858 | 225 | 125 |
#template
def inputlist(): return [int(j) for j in input().split()]
#template
N = int(input())
lis = ['0']*N
time = [0]*N
for i in range(N):
lis[i],time[i] = input().split()
sing = input()
index = -1
for i in range(N):
if lis[i] == sing:
index = i
break
ans = 0
for i in range(index+1,N):
ans... | n = int(input())
title = []
length = []
for i in range(n):
a, b = input().split()
title.append(a)
length.append(int(b))
i = title.index(input())
print(sum((length[i+1:]))) | 1 | 96,987,541,073,010 | null | 243 | 243 |
H=int(input())
W=int(input())
N=int(input())
if N%max(H,W)==0:
print(N//max(H,W))
else:
print(N//max(H,W)+1) | N,M=map(int,input().split())
S,r,s=input(),[],N
for _ in range(2*N):
if S[s]=='1':
s += 1
else:
r.append(str(N-s))
N,s=s,max(0,s-M)
if N == 0:
break
print(*[-1] if s else r[1:][::-1]) | 0 | null | 114,234,256,224,800 | 236 | 274 |
from collections import Counter
N = int(input())
D = list(map(int, input().split()))
mod = 998244353
c = Counter(D)
m = max(c.keys())
if D[0] == 0 and c[0] == 1:
ans = 1
for i in range(1, m+1):
ans *= c[i-1]**c[i]
ans %= mod
print(ans)
else:
print(0) | def check(k, p, w_list):
i_w = 0
for i_k in range(k):
sum_w = 0
while True:
if i_w >= len(w_list):
return len(w_list)
if sum_w + w_list[i_w] > p:
break
sum_w += w_list[i_w]
i_w += 1
return i_w
n, k = list(map(in... | 0 | null | 77,803,821,956,058 | 284 | 24 |
# coding: UTF-8
line = str(raw_input()*2)
word = str(raw_input())
if line.count(word):
print "Yes"
else: print "No"
| s=input()
p=input()
s2=s*2
ren=s2.count(p)
if ren==0:
print('No')
else:
print('Yes')
| 1 | 1,743,154,127,520 | null | 64 | 64 |
from collections import deque
import copy
N, K, C = map(int,input().split())
S = input().split()[0]
TW = 0
q = []
for s in range(len(S)):
if S[s] == 'o':
q.append(s+1)
WD = []
LD = 0
for s in q:
if len(WD) > K:
break
if LD == 0:
WD.append(s)
LD = s
elif s-LD <= C:
... | N, K, C = map(int, input().split())
S = input()
L, R = [-1] * K, [-1] * K
k = 0; temp = -C
for i, s in enumerate(S, 1):
if s == 'o' and i > temp + C: L[k] = i; k += 1; temp = i
if k == K: break
k = K - 1; temp = N + C + 1
for i, s in reversed(list(enumerate(S, 1))):
if s == 'o' and i < temp - C: R[k] = i; k... | 1 | 40,581,271,199,900 | null | 182 | 182 |
t,T,a,A,b,B=map(int, open(0).read().split())
x,y=(a-b)*t,(A-B)*T
if x+y==0:
r="infinity"
else:
s,t=divmod(-x, x+y)
r=0 if s<0 else s*2+(1 if t else 0)
print(r) | import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def main():
t1, t2 = LI()... | 1 | 131,551,113,769,932 | null | 269 | 269 |
x = input().strip()
if x[-1] == 's':
x += "es"
else:
x += 's'
print(x) | ans = ""
k = int(input())
for a in range(k):
ans = ans + "ACL"
print(ans) | 0 | null | 2,270,663,097,444 | 71 | 69 |
S = input()
N = len(S)
flag = True
if S!=S[::-1]:
flag=False
if S[:int((N-1)/2)]!=S[:int((N-1)/2)][::-1]:
flag=False
print("Yes" if flag else "No")
| while True:
H,W = map(int,input().split())
if H == 0 and W == 0:
break
for i in range(H):
for k in range(W):
if i == 0 or i == H-1 or k == 0 or k == W-1:
print("#",end = "")
else:
print(".",end = "")
print()
print()
| 0 | null | 23,652,729,025,988 | 190 | 50 |
a, b, c, k = map(int, input().split())
if k <= a:
ans = k
elif k <= a + b:
ans = a
else:
ans = a * 2 + b - k # a-(k-(a+b))
print(ans) | A,B,C,K = map(int,input().split())
if K<=A:
Ans = K
elif K<=A+B:
Ans = A
elif K<=A+B+C:
Ans = A-(K-A-B)
else:
Ans = A-C
print(Ans)
| 1 | 21,786,240,901,490 | null | 148 | 148 |
#!/usr/local/bin/python3
# https://atcoder.jp/contests/agc014/tasks/agc014_a
# int(input())
# input().split()
# map(int, input().split())
# list(map(int, input().split()))
S = input()
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,181,851,041,330 | null | 184 | 184 |
from decimal import Decimal
import math
AB = input().split()
A, B = int(AB[0]), Decimal(AB[1])
print(math.floor(A*B))
| import decimal
a, b = input().split()
x, y = decimal.Decimal(a), decimal.Decimal(b)
print(int(x * y)) | 1 | 16,434,763,063,752 | null | 135 | 135 |
n = int(input())
def memoize(f):
memo = [1, 1] + [0] * max(0, n - 1)
def main(i):
if memo[i]:
return memo[i]
result = memo[i] = f(i)
return result
return main
@memoize
def fibonacci(i):
return fibonacci(i - 1) + fibonacci(i - 2)
print(fibonacci(n)) | # http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_10_A&lang=ja
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
def main():
n = int(readline())
dp = [0] * (n+1)
dp[0] = 1
dp[1] = 1
for i in range(2,n+1):
dp[i] = dp[i-1] + dp[i-2... | 1 | 1,650,594,848 | null | 7 | 7 |
# coding: UTF-8
import sys
import numpy as np
# f = open("input.txt", "r")
# sys.stdin = f
s = str(input())
t = str(input())
ans = 0
for i, j in zip(s,t):
if i != j:
ans += 1
print(ans)
| ans=0
for i,j in zip(input(),input()):
if i!=j:ans+=1
print(ans) | 1 | 10,527,954,560,790 | null | 116 | 116 |
import sys
input = sys.stdin.readline
'''
'''
s = input().rstrip()
if s == "MON": print(6)
elif s == "SAT": print(1)
elif s == "FRI": print(2)
elif s == "THU": print(3)
elif s == "WED": print(4)
elif s == "TUE": print(5)
else:
print(7) | s = input()
dl = ["SUN","MON","TUE","WED","THU","FRI","SAT"]
for i in range(7):
if s == dl[i]:
print(7-i) | 1 | 132,801,244,815,372 | null | 270 | 270 |
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, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter... | n = int(input())
s = input()
res = "No"
if n%2 == 0 and s[:n//2] *2 ==s:res ="Yes"
print(res) | 0 | null | 148,254,425,725,462 | 281 | 279 |
import sys
from bisect import bisect_left
input = sys.stdin.readline
def main():
N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
for a in range(N - 2):
for b in range(a + 1, N - 1):
x = bisect_left(L, L[a] + L[b])
ans += (x - 1 - b)
prin... |
def main():
N = int(input())
zoro = []
for i in range(N):
a, b = map(int, input().split())
if a == b:
zoro.append(1)
if i >= 2:
if zoro[i-2] == zoro[i-1] and zoro[i-1] == zoro[i]:
print('Yes')
return
e... | 0 | null | 86,800,518,221,332 | 294 | 72 |
N=int(input())
def cf(n):
a=[]
for f in range(1,int(n**(1/2)+1)):
if n%f==0:
a.append(f)
if n//f!=f:
a.append(n//f)
return a
def pf(n):
a=[]
while n%2==0:
a.append(2)
n//=2
f=3
while f*f<=n:
if n%f==0:
a.append(f)
n//=f
else:
f+=2
if n!=1:
... | N = int(input())
if N == 2:
print(1)
exit()
def factorization(n):
arr = []
temp = n
for i in range(2, int(-(-n**0.5//1))+100):
if i > temp / i:
break
if i * i == temp:
arr.append(i)
break
if temp % i == 0:
arr.append(i)
... | 1 | 41,428,390,617,558 | null | 183 | 183 |
D, T, S = list(map(int, input().split()))
if D <= S * T:
print("Yes")
else:
print("No")
| n = int(input())
ans = 1
while ans <= n:
ans *= 2
print(ans -1) | 0 | null | 41,988,282,334,270 | 81 | 228 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.