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
from functools import reduce N = int(input()) A = [int(x) for x in input().split()] SUM=reduce(lambda a, b: a^b, A) [print(SUM^A[i]) for i in range(N)]
x=int(input()) syo=x//100 amari=int(str(x)[-2:]) if amari/5<=syo: print(1) exit() print(0)
0
null
69,868,914,817,412
123
266
a,b,c,d = map(int,input().split()) x1 = a*c x2 = a*d x3 = b*c x4 = b*d x = [x1,x2,x3,x4] print(max(x))
#! /usr/bin/python3 m=[int(input()) for i in range(10)] m.sort() m.reverse() print("{0}\n{1}\n{2}".format(m[0], m[1], m[2]))
0
null
1,544,006,784,508
77
2
#!/usr/bin/env python3 import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) n, a, b = map(int, input().split()) MOD = 10**9 + 7 # 二項展開より 2**n - 1 - nCa - nCb を MOD 10**9 + 7 で求めればよい def combination(n, a): # nCk = n! / k! (n-k)! のうち、 n!/(n-k)! を計算する res = 1 div = 1 for i in range(a): res *= n-i res %= MOD div *= a - i div %= MOD # print(f'n {n}, a {a}, res {res}, div {div}') res = (res * pow(div, MOD-2, MOD)) % MOD return res count = (pow(2, n, MOD) - 1 - combination(n, a) - combination(n, b)) % MOD print(count)
n=int(input()) s=str(input()) ans="Yes" if len(s)%2==1: ans="No" for i in range(len(s)//2): if s[i]!=s[len(s)//2+i]: ans="No" break print(ans)
0
null
106,701,687,874,000
214
279
h1, m1, h2, m2, k = list(map(int, input().split())) okiteru = h2 * 60 + m2 - (h1 * 60 + m1) print(okiteru - k)
h1,m1,h2,m2,k=map(int,input().split()) r=((h2-h1)*60)+m2-m1-k if r>=0: print(r) else: print(0)
1
18,130,698,889,180
null
139
139
def soinsu(n): insu = [] tmp = n if n == 1: insu.append([1,0]) return insu for i in range(2,int(n**0.5)+1): cnt = 0 if tmp % i == 0: while(tmp % i == 0): tmp //= i cnt += 1 insu.append([i,cnt]) if tmp != 1: insu.append([tmp,1]) if len(insu) == 0: insu.append([n,1]) return insu n = int(input()) a = [0]*(int(n**0.5)+1) cnt=1 for i in range(1,len(a)): for j in range(cnt,cnt+i+1): if j < len(a): a[j] = i cnt += 1 else: break sum = 0 insu = soinsu(n) for i in range(len(insu)): sum += a[insu[i][1]] print(sum)
import sys def factorization(n): arr = [] temp = n for i in range(2, int(-(-n**0.5//1))+1): if temp%i==0: cnt=0 while temp%i==0: cnt+=1 temp //= i arr.append([i, cnt]) if temp!=1: arr.append([temp, 1]) if arr==[]: arr.append([n, 1]) return arr n=int(input()) if n==1: print(0) sys.exit() l=factorization(n) ans =0 for x in l: a=x[0] #素数 b=x[1] #素数の個数 k=0 t=0 while(True): t += 1 k += t if k==b: ans += t break elif k > b: ans += t-1 break print(ans)
1
17,005,621,614,630
null
136
136
H = int(input()) count = 0 ans = 0 while H>1: H = H//2 ans += 2**count count += 1 ans += 2**count print(ans)
import sys h, w = map(int, input().split()) s = [list(x.rstrip()) for x in sys.stdin.readlines()] dp = [[10**6]*w for _ in range(h)] if s[0][0] == "#": dp[0][0] = 1 else: dp[0][0] = 0 for j in range(h): for i in range(w): for k in range(2): nx, ny = i + (k + 1)%2, j + k%2 if nx >= w or ny >= h: continue else: add = 0 if s[ny][nx] == "#" and s[j][i] == ".": add = 1 dp[ny][nx] = min(dp[ny][nx], dp[j][i] + add) print(dp[h-1][w-1])
0
null
64,272,217,637,262
228
194
import math def is_prime(x): if x == 2: return True if (x % 2 == 0): return False m = math.ceil(math.sqrt(x)) for i in range(3, m + 1): if x % i == 0: return False return True n = int(input()) prime = 0 for i in range(n): x = int(input()) if is_prime(x): prime += 1 print(prime)
def miller_rabin(n): """ primality Test if n < 3,825,123,056,546,413,051, it is enough to test a = 2, 3, 5, 7, 11, 13, 17, 19, and 23. Complexity: O(log^3 n) """ if n == 2: return True if n <= 1 or not n&1: return False primes = [2, 3, 5, 7, 11, 13, 17, 19, 23] d = n - 1 s = 0 while not d&1: d >>= 1 s += 1 for prime in primes: if prime >= n: break x = pow(prime, d, n) if x == 1: break for r in range(s): if x == n - 1: break if r + 1 == s: return False x = x * x % n return True N = int(input()) print(sum(1 for _ in range(N) if miller_rabin(int(input()))))
1
10,593,974,830
null
12
12
from math import sqrt as r from math import floor as f X = int(input()) going = True def judge(X): for i in range(3, f(r(X)) + 1, 2): if X % i == 0: return False return True if X == 2 or X == 3: print(X) going = False elif X % 2 == 0: X += 1 while going: if judge(X): print(X) break X += 2
MD1 = list(map(int, input().split())) MD2 = list(map(int, input().split())) if MD1[0] == MD2[0]: print(0) else: print(1)
0
null
115,360,196,499,750
250
264
import sys from itertools import product def main(): input = sys.stdin.buffer.readline card = [[0] * 3 for _ in range(3)] for i in range(3): line = list(map(int, input().split())) card[i] = line mark = [[0] * 3 for _ in range(3)] n = int(input()) for _ in range(n): b = int(input()) for i, j in product(range(3), repeat=2): if card[i][j] == b: mark[i][j] = 1 break for i in range(3): s = 0 for j in range(3): s += mark[i][j] if s == 3: print("Yes") sys.exit() for j in range(3): s = 0 for i in range(3): s += mark[i][j] if s == 3: print("Yes") sys.exit() s = 0 for i in range(3): s += mark[i][i] if s == 3: print("Yes") sys.exit() s = 0 for i in range(3): s += mark[i][2 - i] if s == 3: print("Yes") sys.exit() print("No") if __name__ == "__main__": main()
N, S = int(input()), input() print("Yes" if N%2 == 0 and S[:(N//2)] == S[(N//2):] else "No")
0
null
103,609,984,896,640
207
279
X,K,D=list(map(int,input().split())) X=abs(X) import sys if X > 0 and X-K*D>=0: print(X-K*D) sys.exit() M=X//D Q=X%D if M%2 == K%2: print(Q) else: print(D-Q)
import sys import collections #https://python.ms/factorize/ def factorize(n): b = 2 fct = [] while b * b <= n: while n % b == 0: n //= b fct.append(b) b = b + 1 if n > 1: fct.append(n) return fct def main(): input = sys.stdin.readline change_to_count_list = [] for i in range(62): if i == 0: change_to_count_list.append(1) else: change_to_count_list.append(change_to_count_list[i-1]+i+1) N = int(input()) yakusu_list = factorize(N) c = collections.Counter(yakusu_list) result = 0 for count in c.values(): for i in range(62): if change_to_count_list[i] == count: if i == 0: result += 1 break else: result += i + 1 break elif change_to_count_list[i-1] < count and change_to_count_list[i] > count: result += i break print(result) if __name__ == '__main__': main()
0
null
11,098,878,202,720
92
136
x,y,z=map(int,raw_input().split());c=0 for i in range(x,y+1): if z%i==0: c+=1 print c
#coding:utf-8 buff = [int(x) for x in input().split()] a = buff[0] b = buff[1] c = buff[2] print(len([x for x in [x+a for x in range(b - a + 1)] if c%x==0]))
1
542,936,895,550
null
44
44
xyz = input().split() print(xyz[2]+ " " + xyz[0] + " " + xyz[1])
N, M = map(int, input().split()) H = [int(x) for x in input().split()] good = [1]*N for k in range(M): A, B = map(int, input().split()) if H[A - 1] >= H[B - 1]: good[B - 1] = 0 if H[A - 1] <= H[B - 1]: good[A - 1] = 0 print(sum(good))
0
null
31,447,771,424,512
178
155
t=0 h=0 for i in range(int(input())): l=input().split() if l[0]==l[1]: t+=1 h+=1 elif l[0]>l[1]: t+=3 else: h+=3 print(t,h)
import sys input = sys.stdin.readline h,n = map(int,input().split()) a = [] b = [] for i in range(n): x,y = map(int,input().split()) a.append(x) b.append(y) dp = [10**10]*(h+1) dp[0] = 0 for i in range(n): for j in range(h+1): dp[j] = min(dp[j],dp[max(0,j-a[i])]+b[i]) print(dp[h])
0
null
41,385,316,353,570
67
229
class Dice: def __init__(self,s1,s2,s3,s4,s5,s6): self.s1 = s1 self.s2= s2 self.s3= s3 self.s4= s4 self.s5 = s5 self.s6= s6 def east(self): prev_s1 = self.s1 #prev_s1を固定していないと以前の値が後述でs1に値を代入するとき変わってしまう。 prev_s3 = self.s3 prev_s4 = self.s4 prev_s6 = self.s6 self.s1 = prev_s4 self.s3 = prev_s1 self.s4 = prev_s6 self.s6 = prev_s3 def west(self): prev_s1 = self.s1 prev_s3 = self.s3 prev_s4 = self.s4 prev_s6 = self.s6 self.s1 = prev_s3 self.s3 = prev_s6 self.s4 = prev_s1 self.s6 = prev_s4 def south(self): prev_s1 = self.s1 prev_s2 = self.s2 prev_s5 = self.s5 prev_s6 = self.s6 self.s1 = prev_s5 self.s2 = prev_s1 self.s5 = prev_s6 self.s6 = prev_s2 def north(self): prev_s1 = self.s1 prev_s2 = self.s2 prev_s5 = self.s5 prev_s6 = self.s6 self.s1 = prev_s2 self.s2 = prev_s6 self.s5 = prev_s1 self.s6 = prev_s5 def top(self): return self.s1 s1,s2,s3,s4,s5,s6 = map(int,input().split()) dice = Dice(s1,s2,s3,s4,s5,s6) order = input() for c in order: if c =='N': dice.north() elif c =='S': dice.south() elif c =='E': dice.east() elif c == 'W': dice.west() print(dice.top())
from typing import List class Dice(): def __init__(self, lst): self.top = lst[0] self.front = lst[1] self.right = lst[2] self.left = lst[3] self.back = lst[4] self.bottom = lst[5] def rotate(self, direction): if direction == "E": self.top, self.right, self.bottom, self.left = self.left, self.top, self.right, self.bottom if direction == "N": self.top, self.back, self.bottom, self.front = self.front, self.top, self.back, self.bottom if direction == "S": self.top, self.front, self.bottom, self.back = self.back, self.top, self.front, self.bottom if direction == "W": self.top, self.left, self.bottom, self.right = self.right, self.top, self.left, self.bottom def main(): dice_nums: List[int] = list(map(int, input().split())) directions: str = input() dice = Dice(dice_nums) for direction in directions: dice.rotate(direction) print(dice.top) if __name__ == "__main__": main()
1
226,409,493,150
null
33
33
# -*- coding: utf-8 -*- N,M,K = list(map(int, input().rstrip().split())) #----- # Calculate the Factorial and it's Inverse Element fact = [0]*(N+1) fact_inv = [0]*(N+1) inv = [0]*(N+1) mod = 998244353 fact[0] = fact[1] = 1 fact_inv[0] = fact_inv[1] = 1 inv[1] = 1 for i in range(2, N+1): fact[i] = (fact[i-1] * i) % mod inv[i] = mod - ( inv[mod%i] * (mod // i) ) % mod fact_inv[i] = ( fact_inv[i-1] * inv[i] ) % mod #----- # Calculate (M-1) raised to the power of "0 to N-1" pow_M1 = [0]*N pow_M1[0] = 1 for i in range(1, N): pow_M1[i] = ( pow_M1[i-1] * (M-1) ) % mod #----- ans = 0 for i in range(K+1): comb = ( fact[N-1] * fact_inv[i] * fact_inv[N-1-i] ) % mod ans += ( comb * M * pow_M1[N-i-1] ) % mod ans %= mod print(ans)
class Dice(): def __init__(self, nums): self.nums = nums self.top, self.front, self.right = 0, 1, 2 def move(self, op): for c in op: if c == 'N': self.top, self.front = self.front, 5 - self.top elif c == 'S': self.top, self.front = 5 - self.front, self.top elif c == 'E': self.top, self.right = 5 - self.right, self.top else: self.top, self.right = self.right, 5 - self.top dice = Dice([int(n) for n in input().split()]) dice.move(input()) print(dice.nums[dice.top])
0
null
11,722,088,787,160
151
33
def resolve(): H, W, K = map(int, input().split()) c = [list(input()) for _ in range(H)] ans = 0 for i in range(2**H): for j in range(2**W): now = 0 for x in range(H): for y in range(W): if 2**x & i > 0 and 2**y & j > 0: if c[x][y] == "#": now += 1 if now == K: ans += 1 print(ans) resolve()
H, W, K = map(lambda x: int(x), input().split()) matrix = [] for i in range(H): row = input() dots = [] for j in range(W): dots.append(row[j]) matrix.append(dots) ans = 0 for bitR in range(1 << H): for bitC in range(1 << W): black = 0 for i in range(H): for j in range(W): if ((bitR >> i) & 1) == 0 and ((bitC >> j) & 1) == 0 and matrix[i][j] == '#': black += 1 if black == K: ans += 1 print(ans)
1
8,957,325,438,270
null
110
110
a, b, c = input().split() count_devisors = 0 for number in range(int(a), int(b)+1): if int(c) % number == 0: count_devisors += 1 print(count_devisors)
x = input().split() a = int(x[0]) b = int(x[1]) c = int(x[2]) count = 0 # a =< b for i in range(a,b+1): if c % i == 0: count += 1 print(count)
1
557,409,696,232
null
44
44
import math Max = 1000001 prime = Max*[1] def sieve(): prime[0] = 0 prime[1] = 0 for i in range(2,Max): if prime[i]==1: j = 2*i while j < Max: prime[j] = 0 j += i def Howmany(x): res = 1 while x>=res: x -= res res += 1 return res-1 N = int(input()) sieve() ans = 0 R = int(math.sqrt(N)) for i in range(2, R): if prime[i]==1 and N%i==0: cnt = 0 while N%i==0: N //= i cnt+=1 ans += Howmany(cnt) if N!=1: ans += 1 print(ans)
import collections def prime_factorize(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: a.append(n) return a N=int(input()) D = collections.Counter(prime_factorize(N)) A=0 for d in D: e=D[d] for i in range(40): if (i+1)*(i+2)>2*e: A=A+i break print(A)
1
16,913,416,420,334
null
136
136
N = int(input()) S = input() R = set() G = set() B = set() for i, s in enumerate(S): if s == 'R': R.add(i) elif s == 'G': G.add(i) elif s == 'B': B.add(i) ans = 0 for r in R: for g in G: ans += len(B) d = abs(r-g) if (r+g) % 2 == 0 and (r+g)//2 in B: ans -= 1 if r+d in B or g+d in B: ans -= 1 if r-d in B or g-d in B: ans -= 1 print(ans)
import sys input = sys.stdin.buffer.readline import math n = int(input()) mod = 1000000007 AB = [] for i in range(n): a, b = map(int, input().split()) AB.append((a, b)) def power(a, n, mod): bi=str(format(n,"b")) #2進数 res=1 for i in range(len(bi)): res=(res*res) %mod if bi[i]=="1": res=(res*a) %mod return res def toid(a, b): flag = False if a == 0 and b == 0: return (0, 0) elif a == 0: return (0, 1) elif b == 0: return (1, 0) else: if a > 0 and b > 0: g = math.gcd(a, b) a //= g b //= g elif a > 0 and b < 0: b = -b g = math.gcd(a, b) a //= g b //= g b = -b elif a < 0 and b > 0: a = -a g = math.gcd(a, b) a //= g b //= g b = -b else: a = -a b = -b g = math.gcd(a, b) a //= g b //= g return (a, b) def totg(a, b): if a == 0 and b == 0: return (0, 0) elif a == 0: return (1, 0) elif b == 0: return (0, 1) else: if a > 0 and b > 0: g = math.gcd(a, b) a //= g b //= g t = (b, -a) elif a > 0 and b < 0: b = -b g = math.gcd(a, b) a //= g b //= g b = -b t = (-b, a) elif a < 0 and b > 0: a = -a g = math.gcd(a, b) a //= g b //= g a = -a t = (b, -a) else: a = -a b = -b g = math.gcd(a, b) a //= g b //= g a = -a b = -b t = (-b, a) return t d = {} ans = 0 for i in range(n): a, b = AB[i] s = toid(a, b) if s not in d: d[s] = 1 else: d[s] += 1 ans = 1 used = set() for k1, v1 in d.items(): if k1 in used: continue if k1 == (0, 0): continue a, b = k1 k2 = totg(a, b) if k2 in d: v2 = d[k2] else: v2 = 0 temp = power(2, v1, mod)-1+power(2, v2, mod)-1+1 ans *= temp ans %= mod used.add(k1) used.add(k2) ans -= 1 if (0, 0) in d: ans += d[(0, 0)] print(ans%mod)
0
null
28,667,123,555,642
175
146
K = int(input()) a = [] def DFS(n): if n > 3234566667: return a.append(n) l = n % 10 if l == 0: DFS(10 * n) DFS(10 * n + 1) elif l == 9: DFS(10 * n + 9) DFS(10 * n + 8) else: DFS(10 * n + l) DFS(10 * n + l + 1) DFS(10 * n + l - 1) for i in range(1, 10): DFS(i) a = sorted(a) print(a[K-1])
import sys def solve(): readline = sys.stdin.buffer.readline mod = 10 ** 9 + 7 a = int(readline()) print(a + a ** 2 + a ** 3) if __name__ == '__main__': solve()
0
null
25,209,591,664,410
181
115
M1,D1 = map(int,input().split()) M2,D2 = map(int,input().split()) print(1) if(M1 != M2) else print(0)
m=input().split() M=input().split() if int(M[0]) - int(m[0]) == 1: print('1') else: print('0')
1
123,986,740,668,390
null
264
264
def main(): num = list(map(int,input().split())) if num[0]<10 and num[1]<10: print(num[0]*num[1]) else: print(-1) main()
def ri(): return int(input()) def rii(): return [int(v) for v in input().split()] def solve(x): return 0 if x else 1 if __name__ == "__main__": print(solve(ri()))
0
null
80,766,177,875,130
286
76
Row = int(input()) List = [] for i in range (Row): List.append(input()) s_l = set(List) print(len(s_l))
n = int(input()) s = 100000 for i in range(n): s = int((s*1.05)/1000+0.9999)*1000 print(s)
0
null
15,177,981,025,440
165
6
def main(): N = int(input()) X = input() XINT = int(X,2) ANS = [0]*N TEMP = [0]*N CHAIND = [0]*N cnt = count_ones_by_bitmask(XINT) if cnt == 0: for i in range(N): print(1) return if cnt ==1: for i in range(N): if X[i] == '1': print(0) #全てが0になる else: if i==N-1: print((int(X[N-1])+1)%2+1) # 2の剰余の反転 else: print((int(X[N-1]))%2+1) # 2の剰余 return p = XINT % (cnt+1) m = XINT % (cnt-1) pmod = 1 mmod = 1 for i in range(N): ANS[i] = 1 if (X[N-i-1] == '0'): TEMP[i] = (p + pmod) % (cnt+1) else: TEMP[i] = (m - mmod) % (cnt-1) pmod = (pmod*2) % (cnt+1) mmod = (mmod*2) % (cnt-1) CHA = list(set(TEMP)) for i in range(len(CHA)): an = 0 cha = CHA[i] cnt = count_ones_by_bitmask(CHA[i]) while cnt>0: an += 1 cha = cha%cnt cnt = count_ones_by_bitmask(cha) CHAIND[CHA[i]] = an for i in reversed(range(N)): print(ANS[i]+CHAIND[TEMP[i]]) def count_ones_by_bitmask(num): count = 0 while num: count += num & 1 num >>= 1 return count if __name__ == '__main__': main()
N = int(input()) X = int(input(),2) def popcount(n): return bin(n).count('1') def f(n): if n== 0: return 1 count = 1 while n!=0: n = n%popcount(n) count += 1 return count X_popcount = popcount(X) X_mod_p = X%(X_popcount+1) if X_popcount != 1: X_mod_m = X%(X_popcount-1) for i in range(N): X_i = X ^ (1<<(N-i-1)) if X_i == 0: ans = 0 elif X>>(N-i-1)&1 == 1: if X_popcount == 1: ans = 1 else: ans = f((X_mod_m-pow(2, N-i-1, X_popcount-1))%(X_popcount-1)) else: ans = f((X_mod_p+pow(2, N-i-1, X_popcount+1))%(X_popcount+1)) print(ans)
1
8,248,232,461,362
null
107
107
n = int(input()) if n % 2 == 0: ans = n / 2 - 1 else: ans = n / 2 print(int(ans))
S = 13 * 0 H = 13 * 1 C = 13 * 2 D = 13 * 3 #???????????????????¨??????????????????????????????????????????????????????????,???????????????:1??? #??????????????????????????????5???S(???0)+5???????????????11???D(???39)+11??§??¨?????? #?????????0???????????¨ card_count = [0 for i in range(53)] n = int(input()) for i in range(n): card_type, card_num = input().split() card_count[eval(card_type)+int(card_num)] += 1 #???????????£????¨??????¨???????????????????????°???1????¶???? for s in ['S','H','C','D']: for i in range(1, 13+1): if card_count[eval(s)+i] == 0: #??????????????°???0?????? print("{0} {1}".format(s,i)) #?¨??????¨?????????????????????
0
null
77,402,680,898,200
283
54
import sys from itertools import accumulate read = sys.stdin.buffer.read input = sys.stdin.buffer.readline inputs = sys.stdin.buffer.readlines import bisect n,m=map(int,input().split()) A=list(map(int,input().split())) A.sort() def hand(x): cnt=0 for i in range(n): k=n-bisect.bisect_left(A,x-A[-i-1]) if k==0: break cnt+=k if cnt>=m: break return cnt def main(): l=0 h=2*10**5+1 mid=(l+h)//2 while l+1<h: mid=(l+h)//2 if hand(mid)<m: h=mid else: l=mid B = list(accumulate(A[::-1]))[::-1] ans=0 cnt=0 for i in range(n): index=bisect.bisect_left(A,l-A[-i-1]+1) if n==index: break else: ans+=(n-index)*A[-i-1]+B[index] cnt+=(n-index) ans+=(m-cnt)*l print(ans) if __name__ == "__main__": main()
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import numpy as np MOD = 10 ** 9 +7 n,m = map(int,readline().split()) a = np.array(read().split(),np.int64) a.sort() def shake_cnt(x): X=np.searchsorted(a,x-a) return n*n-X.sum() left = 0 right = 10 ** 6 while left+1 <right: x = (left + right)//2 if shake_cnt(x) >= m: left = x else: right = x left,right X=np.searchsorted(a,right-a) Acum = np.zeros(n+1,np.int64) Acum[1:] = np.cumsum(a) shake = n * n -X.sum() happy = (Acum[-1]-Acum[X]).sum()+(a*(n-X)).sum() happy += (m-shake)*left print(happy)
1
107,711,969,381,352
null
252
252
x=[] y=[] while True: i,j=map(int,raw_input().split()) if (i,j)==(0,0): break; x.append(i) y.append(j) X=iter(x) Y=iter(y) for a in X: b=Y.next() if a<b: print('%d %d'%(a,b)) else: print('%d %d'%(b,a))
n=int(input()) x=int(100000) for i in range(1,n+1) : x = x*1.05 if x%1000 == 0 : continue else : x = x//1000*1000+1000 print("{:.0f}".format(x))
0
null
269,328,710,908
43
6
import bisect, collections, copy, heapq, itertools, math, string import sys def I(): return int(sys.stdin.readline().rstrip()) def MI(): return map(int, sys.stdin.readline().rstrip().split()) def LI(): return list(map(int, sys.stdin.readline().rstrip().split())) def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) N = I() A = LI() c = collections.Counter(A) cnt = 0 for _ in c: cnt += c[_] * (c[_] - 1) // 2 for i in range(N): a = c[A[i]] print(cnt - (a - 1))
S = list("abcdefghijklmnopqrstuvwxyz") N = int(input()) P = 0 for i in range(1,15): if P+26**i >= N: n = i break else: P += 26**i X = [0]*n NN = N - P - 1###0-indexedの26進法なので for i in range(n): X[n-i-1] = S[NN % 26] NN //= 26 print("".join(X))
0
null
29,982,433,429,788
192
121
if __name__ == "__main__": A,B = map(int,input().split()) for i in range(1,1251): A_tmp,B_tmp = int(i*0.08),int(i*0.10) if A is A_tmp and B is B_tmp: print(i) exit() print(-1)
import numpy as np n = int(input()) a = [x for x in range(1,10)] for i in a: for j in a: if i * j == n: print('Yes') exit() print('No')
0
null
108,165,951,774,984
203
287
H = int(input()) W = int(input()) N = int(input()) big = max(H,W) bigsum = 0 ans = 0 while bigsum < N: bigsum += big ans += 1 print(ans)
N = int(input()) A = list(map(int,input().split())) DP = [0,0,0] m = N//2*2 if N%2 == 0: for i in range(0,m,2): DP[0] += A[i] DP[1] += A[i+1] DP[1] = max(DP[0],DP[1]) print(DP[1]) else: for i in range(0,m,2): DP[0] += A[i] DP[1] += A[i+1] DP[2] += A[i+2] DP[1] = max(DP[0],DP[1]) DP[2] = max(DP[1],DP[2]) print(DP[2])
0
null
63,046,254,755,548
236
177
from collections import deque import sys sys.setrecursionlimit(20000000) N = int(input()) ab = [list(map(int, input().split())) for _ in range(N-1)] routes = [[] for _ in range(N)] for i in range(len(ab)): routes[ab[i][0]-1].append([ab[i][1]-1, i]) routes[ab[i][1]-1].append([ab[i][0]-1, i]) route_color = [-10e+10 for _ in range(len(ab))] route_num = [0]*N max_route = 0 for i in range(N): num = len(routes[i]) route_num[i] = num if max_route < num: max_route = num seen = [False for _ in range(N)] def function(num,pre_color): color_num = -1 for route in routes[num]: color_num += 1 if color_num == pre_color: color_num+=1 if route_color[route[1]] != -10e+10: color_num-=1 pass else: route_color[route[1]] = color_num if seen[route[0]] == False: seen[route[0]] = True function(route[0],route_color[route[1]]) return function(0,-1) print(max_route) for color in route_color: print(color+1)
n,x,y=map(int,input().split()) x,y=x-1,y-1 c=[0 for i in range(n-1)] for i in range(n): for j in range(i+1,n): l=min(j-i,abs(i-x)+abs(j-y)+1) c[l-1]+=1 for i in range(n-1): print(c[i])
0
null
90,095,802,592,840
272
187
import sys input = sys.stdin.readline sys.setrecursionlimit(10000000) from collections import defaultdict from bisect import * mod = 10**9+7 N = int(input()) A = list(map(int, input().split())) cnt = [0]*3 ans = 1 for i, x in enumerate(A): T = len([c for c in cnt if c == x]) for i, c in enumerate(cnt): if c == x: cnt[i] += 1 break ans = ans * T % mod print(ans)
N = int(input()) A = list(map(int, input().split())) mod = 10**9+7 G = [0]*3 ans = 1 for i in range(N): x = 0 cnt = 0 for j, g in enumerate(G): if g == A[i]: x = j if cnt == 0 else x cnt += 1 G[x] += 1 ans *= cnt ans = ans % mod print(ans)
1
129,692,442,136,078
null
268
268
def solve(): from sys import stdin input_lines = stdin from math import log10 for line in input_lines: a, b = map(int, line.split()) if (a == 0 and b == 0): break print(int(log10(a + b)) + 1) solve()
#!/usr/bin/python #-coding:utf8- import sys for s in sys.stdin: data = map(int,s.split()) print len(str(data[0]+data[1]))
1
122,926,200
null
3
3
def maybe_prime(d,s,n): for a in (2,3,5,7): p = False x = pow(a,d,n) if x==1 or x==n-1: continue for i in range(1,s): x = x*x%n if x==1: return False elif x == n-1: p = True break if not p: return False return True def is_prime(n): if n in (2,3,5,7): return True elif n%2==0: return False else: d,s = n-1, 0 while not d%2: d,s = d>>1,s+1 return maybe_prime(d,s,n) cnt = 0 n = int(input()) for i in range(n): n = int(input()) if is_prime(n): cnt+=1 print(cnt)
import math Num = input() N = [input() for _ in range(Num)] pnum_count = Num for n in N: if n == 2: continue if n % 2 == 0: pnum_count -= 1 continue i = 2 while i <= math.sqrt(n): if n % i == 0: pnum_count -= 1 break i += 1 print pnum_count
1
9,662,316,468
null
12
12
import sys input = lambda: sys.stdin.readline().rstrip() def solve(): N, K = map(int, input().split()) h = list(map(int, input().split())) ans = 0 for i in range(N): if h[i] >= K: ans += 1 print(ans) if __name__ == '__main__': solve()
A1, A2, A3 = map(int, input().split()) if A1+A2+A3 >= 22: print('bust') else: print('win')
0
null
149,389,663,797,760
298
260
#!usr/bin/env python3 import sys import copy def main(): n = int(sys.stdin.readline()) separator = '####################' room, floor = 10, 3; building1 = [[0 for col in range(room)] for row in range(floor)] building2 = copy.deepcopy(building1) building3 = copy.deepcopy(building1) building4 = copy.deepcopy(building1) buildings = {1 : building1, 2 : building2, 3 : building3, 4 : building4 } for i in range(n): lst = [int(num) for num in sys.stdin.readline().split()] buildings[lst[0]][lst[1]-1][lst[2]-1] += lst[3] for idx, (key, value) in enumerate(buildings.items()): for floor in value: print(' %s %s %s %s %s %s %s %s %s %s' % tuple(floor)) if idx < 3: print(separator) if __name__ == '__main__': main()
n = int(input()) person = [[0 for _ in range(10)] for _ in range(12)] for _ in range(n): b, f, r, v = [int(m) for m in input().split()] person[3*(b-1)+f-1][r-1] += v for index, p in enumerate(person): print(" "+" ".join([str(m) for m in p])) if (index+1)%3 == 0 and index < len(person)-1: print("####################")
1
1,110,824,709,720
null
55
55
from collections import deque N, M = list(map(int, input().split())) # N個の空の配列 # g[0]は空のまま path_list = [[] for i in range(N + 1)] # 繋がっている部屋をメモ for i in range(M): a, b = list(map(int, input().split())) path_list[a].append(b) path_list[b].append(a) queue = deque([1]) d = [None] * (N + 1) while queue: # popleft()で先頭の要素を返しつつ削除 v = queue.popleft() # vから行ける全ての部屋について for i in path_list[v]: if d[i] is None: d[i] = v queue.append(i) print("Yes") # 2番以降の部屋について for i in d[2:]: print(i)
x = list(input().split()) for i in range(5): # logging.debug("i = {},x[i] = {}".format(i, x[i])) # if x[i] == "0": print(i + 1) exit() # logging.debug("n = {},f = {},f**b = {}".format(n, f, f**b)) # #logging.debug("デバッグ終了")#
0
null
16,979,549,859,140
145
126
N = int(input()) xys = set([tuple(map(int, input().split())) for _ in range(N)]) z = [] w = [] for xy in xys: z.append(xy[0]+xy[1]) w.append(xy[0]-xy[1]) #print(z) #print(w) print(max(abs(max(z) - min(z)), abs(max(w) - min(w))))
N = int(input()) l0 = [[int(i) for i in input().split()] for _ in range(N)] l1 = [0] * N l2 = [0] * N for cnt, val in enumerate(l0): l1[cnt] = val[0] + val[1] l2[cnt] = val[0] - val[1] l1.sort() l2.sort() print(max(l1[-1] - l1[0], l2[-1] - l2[0]))
1
3,389,985,632,830
null
80
80
n = int(input()) numbers = input() lst = set() ans = [] for i in range(n): pin = '' if numbers[i] not in lst: pin += numbers[i] lst.add(pin) lst2 = set() for j in range(i+1, n): pin += numbers[j] if pin[1] not in lst2: lst2.add(pin[1]) lst3 = set() for k in range(j+1, n): pin += numbers[k] if pin[2] not in lst3: lst3.add(pin[2]) ans.append(pin) if ('0' in lst3) and ('1' in lst3) and ('2' in lst3) and ('3' in lst3) and ('4' in lst3) and ('5' in lst3) and ('6' in lst3) and ('7' in lst3) and ('8' in lst3) and ('9' in lst3): break pin = pin[0] + pin[1] if ('0' in lst2) and ('1' in lst2) and ('2' in lst2) and ('3' in lst2) and ('4' in lst2) and ('5' in lst2) and ('6' in lst2) and ('7' in lst2) and ('8' in lst2) and ('9' in lst2): break pin = pin[0] if ('0' in lst) and ('1' in lst) and ('2' in lst) and ('3' in lst) and ('4' in lst) and ('5' in lst) and ('6' in lst) and ('7' in lst) and ('8' in lst) and ('9' in lst): break print(len(ans))
X = int(input()) a = [-1] * 2 * X a[0] = 0 a[1] = 1 for i in range(2, X): if a[i] == -1: for j in range(i, 2*X, i): a[j] = i for ans in range(X, 2*X): if a[ans] == -1: break print(ans)
0
null
116,781,454,488,832
267
250
n,k=map(int,input().split()) a=list(map(int,input().split())) b=[0]*n c=[0]*n cnt=0 while cnt<min(k,101): cnt+=1 for i in range(n): b[max(0,i-a[i])]+=1 if i+a[i]<n-1: b[i+a[i]+1]-=1 c[0]=b[0] for j in range(n-1): c[j+1]=c[j]+b[j+1] a=c b=[0]*n c=[0]*n print(*a)
import math X = int(input()) N = 100 t = 0 while N<X: t+=1 N = N*101//100 print(t)
0
null
21,327,102,272,698
132
159
def num2alpha(num): if num<=26: return chr(64+num) elif num%26==0: return num2alpha(num//26-1)+chr(90) else: return num2alpha(num//26)+chr(64+num%26) print(num2alpha(int(input())).lower())
from collections import deque k=int(input()) d=deque() for i in range(1,10): d.append(i) for i in range(k-1): x=d.popleft() if x%10!=0: d.append(10*x+(x%10)-1) d.append(10*x+(x%10)) if x%10!=9: d.append(10*x+(x%10)+1) print(d.popleft())
0
null
25,985,662,306,670
121
181
n = int(input()) aas = list(map(int, input().split())) if n == 1 and aas == [1]: print(0) exit() t = 0 for i in aas: if i == t + 1: t += 1 print(n-t if t > 0 else -1)
S=[] T=[] n=int(input()) s=input().split() for i in range(n): S.append(s[i]) q=int(input()) t=input().split() for j in range(q): T.append(t[j]) cnt=0 for i in range(q): for j in range(n): if T[i]==S[j]: cnt+=1 break print(cnt)
0
null
57,507,880,272,124
257
22
import math r = int(input()) h = 2 * r * math.pi print(h)
from math import pi def main(): S = int(input()) print(2 * pi * S) if __name__ == "__main__": main()
1
31,302,534,858,540
null
167
167
def main(): S, T = input().split() print(T + S) main()
a,b=list(input().split()) c = b+a print(''.join(c))
1
103,298,518,396,124
null
248
248
c=0 for _ in[0]*int(input()): x=int(input()) if 2 in[x,pow(2,x,x)]:c+=1 print(c)
from itertools import permutations import math N = int(input()) XY = [list(map(int, input().split())) for _ in range(N)] sum_roots = 0 for points in permutations(XY): for point_idx in range(1, N): before_x = points[point_idx-1][0] before_y = points[point_idx-1][1] x = points[point_idx][0] y = points[point_idx][1] sum_roots += math.sqrt((x-before_x) ** 2 + (y-before_y)**2) print(sum_roots/math.factorial(N))
0
null
74,495,586,093,434
12
280
k = int(input()) a, b = map(int, input().split()) for n in range(a, b+1): if n % k == 0: print('OK') break if n == b: print('NG')
k=int(input()) a,b=map(int,input().split()) cnt=0 for i in range(a, b+1): if i%k==0: cnt+=1 if cnt>0: print('OK') else : print('NG')
1
26,745,684,401,328
null
158
158
s=list(input()) count=0 if 'R' in s: count+=1 for i in range(len(s)-1): if s[i]==s[i+1] and s[i]=='R': count+=1 print(count)
s = input() n = ans = 0 for c in s: if c == "S": n = 0 continue n += 1 if n > ans: ans = n print(ans)
1
4,903,424,346,272
null
90
90
N = int(input()) result = [0] * (N + 1) for i in list(map(int, input().split())): result[i] += 1 result.pop(0) for r in result: print(r)
N = int(input()) divisor = [N] ans = 0 #Nの約数の列挙 for i in range(2,N+1,1): if i*i < N: if N % i == 0: divisor.append(i) divisor.append(N//i) elif i*i == N: divisor.append(i) else: break #N-1の約数の列挙 yakusuuu = [N-1] for i in range(2,N,1): if i*i < (N-1): if (N - 1)% i == 0: yakusuuu.append(i) yakusuuu.append((N-1)//i) elif i*i == (N-1): yakusuuu.append(i) else: break for i in yakusuuu: if N % i == 1: ans += 1 #print(divisor) #print(yakusuuu) M = N for K in divisor: #print(K) while M % K == 0: M = M//K if M == 1: ans += 1 else: M = M % K if M == 1: ans += 1 M = N print(ans)
0
null
36,896,058,570,810
169
183
N,A,B = map(int, input().split()) div, mod = divmod(N, A+B) print(div*A + min(mod,A))
N,A,B=map(int,input().split()) div=N//(A+B) mod=N%(A+B) print(div*A+min(mod,A))
1
55,457,647,335,830
null
202
202
n, m = map(int, input().split()) h = [0] + list(map(int, input().split())) eg = [[] for _ in range(n + 1)] for _ in range(m): a, b = map(int, input().split()) eg[a].append(b) eg[b].append(a) ans = 0 for i in range(1, n + 1): high = True for t in eg[i]: if h[t] >= h[i]: high = False break if high: ans += 1 print(ans)
n,m = map(int,input().split()) h = list(map(int,input().split())) flg = [1]*n for _ in range(m): a,b = map(int,input().split()) if h[a-1] > h[b-1]: flg[b-1] = 0 elif h[a-1] == h[b-1]: flg[a-1],flg[b-1] = 0,0 else: flg[a-1] = 0 print(flg.count(1))
1
24,998,655,221,320
null
155
155
while 1: x=raw_input() if x=='0':break sum=0 for i in x: sum+=int(i) print sum
out_grade = "" while True: m, f, r = map(int, input().split(" ")) if m==f==r==-1: #EOF break if m==-1 or f==-1: out_grade = "F" elif m + f >= 80: out_grade = "A" elif m + f >= 65: out_grade = "B" elif m + f >= 50: out_grade = "C" elif m + f >= 30: if r >= 50: out_grade = "C" else: out_grade = "D" else: out_grade = "F" print(out_grade)
0
null
1,377,127,059,670
62
57
n=int(input("")) a=[] b=[] for i in range(n): cc=input("").split(" ") a+=[int(cc[0])] b+=[int(cc[1])] s=0 a.sort() b.sort() if (n%2==0): s=(a[int(n/2)]+a[int(n/2)-1]-b[int(n/2)]-b[int(n/2)-1]) else: s=a[int((n-1)/2)]-b[int((n-1)/2)] print(int(-s+1))
import math x1,y1,x2,y2 = map(float,raw_input().split()) a = math.sqrt((x1-x2)**2+(y1-y2)**2) print '%f'%a
0
null
8,744,785,702,170
137
29
import sys input = lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(max(1000, 10**9)) write = lambda x: sys.stdout.write(x+"\n") n,t = list(map(int, input().split())) ab = [None]*n for i in range(n): ab[i] = tuple(map(int, input().split())) ab.sort() dp = [[0]*(t) for _ in range(n)] for i in range(1, n): a,b = ab[i-1] for j in range(t-1, 0, -1): dp[i][j] = dp[i-1][j] if j>=a and dp[i][j]<dp[i-1][j-a]+b: dp[i][j] = dp[i-1][j-a]+b ans = max((dp[i][t-1] + ab[i][1]) for i in range(n)) print(ans)
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 MOD = 1000000007 def main(): N, T, *AB = map(int, read().split()) D = [(a, b) for a, b in zip(*[iter(AB)] * 2)] D.sort() dp = [0] * T ans = 0 for i, (a, b) in enumerate(D[:-1]): for t in range(T - 1, a - 1, -1): if dp[t] < dp[t - a] + b: dp[t] = dp[t - a] + b if ans < dp[T - 1] + D[i + 1][1]: ans = dp[T - 1] + D[i + 1][1] print(ans) return if __name__ == '__main__': main()
1
151,411,512,347,198
null
282
282
import sys sys.setrecursionlimit(2147483647) INF = 1 << 60 MOD = 10**9 + 7 # 998244353 input = lambda:sys.stdin.readline().rstrip() class SegmentTree(object): def __init__(self, A, dot, unit): n = 1 << (len(A) - 1).bit_length() tree = [unit] * (2 * n) for i, v in enumerate(A): tree[i + n] = v for i in range(n - 1, 0, -1): tree[i] = dot(tree[i << 1], tree[i << 1 | 1]) self._n = n self._tree = tree self._dot = dot self._unit = unit def __getitem__(self, i): return self._tree[i + self._n] def update(self, i, v): i += self._n self._tree[i] = v while i != 1: i >>= 1 self._tree[i] = self._dot(self._tree[i << 1], self._tree[i << 1 | 1]) def add(self, i, v): self.update(i, self[i] + v) def sum(self, l, r): l += self._n r += self._n l_val = r_val = self._unit while l < r: if l & 1: l_val = self._dot(l_val, self._tree[l]) l += 1 if r & 1: r -= 1 r_val = self._dot(self._tree[r], r_val) l >>= 1 r >>= 1 return self._dot(l_val, r_val) def resolve(): n = int(input()) trees = [[0] * n for _ in range(26)] character = [None] * n for i, c in enumerate(input()): c = ord(c) - ord('a') character[i] = c trees[c][i] = 1 for i in range(26): trees[i] = SegmentTree(trees[i], max, 0) for _ in range(int(input())): q, *A = input().split() if q == '1': i, c = A i = int(i) - 1 c = ord(c) - ord('a') trees[character[i]].update(i, 0) character[i] = c trees[c].update(i, 1) else: l, r = map(int, A) l -= 1 print(sum(trees[i].sum(l, r) for i in range(26))) resolve()
#!python3 import sys input = sys.stdin.readline def resolve(): N = int(input()) S = list(input()) Q = int(input()) c0 = ord('a') smap = [1<<(i-c0) for i in range(c0, ord('z')+1)] T = [0]*N + [smap[ord(S[i])-c0] for i in range(N)] for i in range(N-1, 0, -1): i2 = i << 1 T[i] = T[i2] | T[i2|1] ans = [] #print(T) for cmd, i, j in zip(*[iter(sys.stdin.read().split())]*3): i = int(i) - 1 if cmd == "1": if S[i] == j: continue S[i] = j i0 = N + i T[i0] = smap[ord(j)-c0] while i0 > 1: i0 = i0 >> 1 T[i0] = T[i0+i0] | T[i0-~i0] elif cmd == "2": i += N j = int(j) + N d1 = 0 while i < j: if i & 1: d1 |= T[i] i += 1 if j & 1: j -= 1 d1 |= T[j] i >>= 1; j >>=1 ans.append(bin(d1).count('1')) print(*ans, sep="\n") if __name__ == "__main__": resolve()
1
62,702,805,480,608
null
210
210
import sys, math, itertools input = lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(10**7) INF = 10**20 MOD = 998244353 def I(): return int(input()) def F(): return float(input()) def S(): return input() def LI(): return [int(x) for x in input().split()] def LI_(): return [int(x)-1 for x in input().split()] def LF(): return [float(x) for x in input().split()] def LS(): return input().split() def factorialMod(n, p): fact = [0] * (n+1) fact[0] = fact[1] = 1 factinv = [0] * (n+1) factinv[0] = factinv[1] = 1 inv = [0] * (n+1) inv[1] = 1 for i in range(2, n + 1): fact[i] = (fact[i-1] * i) % p inv[i] = (-inv[p % i] * (p // i)) % p factinv[i] = (factinv[i-1] * inv[i]) % p return fact, factinv def combMod(n, r, fact, factinv, p): if (r < 0) or (n < r): return 0 r = min(r, n - r) return fact[n] * factinv[r] * factinv[n-r] % p def resolve(): N, M, K = LI() ans = 0 fact, factinv = factorialMod(N, MOD) for i in range(K + 1): ans += combMod(N - 1, i, fact, factinv, MOD) * M * pow(M - 1, N - 1 - i, MOD) ans %= MOD print(ans) if __name__ == '__main__': resolve()
import math from operator import mul from functools import reduce n, m, k = map(int, input().split()) mod = 998244353 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 fact = [1, 1] factinv = [1, 1] inv = [0, 1] for i in range(2, n+1): fact.append((fact[-1] * i) % mod) inv.append((-inv[mod % i] * (mod // i)) % mod) factinv.append((factinv[-1] * inv[-1]) % mod) ans = 0 for i in range(k+1): ans += m*cmb(n-1, i, mod)*pow(m-1, n-1-i, mod)%mod ans %= mod print(ans)
1
23,160,375,448,000
null
151
151
while True: m,f,r = map(int, input().split()) if(m==-1 or f == -1): if (m == -1 and f == -1 and r == -1): break else: print('F') else: score = m + f if(score >= 80): print('A') elif(score >= 65): print('B') elif(score >= 50): print('C') elif(score >= 30): if(r >= 50): print('C') else: print('D') else: print('F')
nn, kk = list(map(int,input().split())) sum = 0 for i in range(kk, nn+2): min = (0+i-1)*i/2 max = (nn+nn-i+1)*i/2 sum += (max-min)+1 sum = sum % (10**9+7) print(int(sum))
0
null
17,175,698,572,692
57
170
n = int(input()) cards = { 'S': [], 'H': [], 'C': [], 'D': [] } for _ in range(n): color, rank = input().split() cards[color].append(rank) for color in ['S', 'H', 'C', 'D']: for rank in [x for x in range(1, 14) if str(x) not in cards[color]]: print(color, rank)
MOD = (10 ** 9) + 7 n, k = map(int, input().split()) a = list(map(int, input().split())) negs = [-x for x in a if x < 0] non_negs = [x for x in a if x >= 0] if len(non_negs) == 0 and k % 2 == 1: negs.sort() ans = 1 for i in range(k): ans = ans * -negs[i] % MOD print(ans) exit() negs_p, non_negs_p = 0, 0 negs.sort(reverse = True) non_negs.sort(reverse = True) for i in range(k): if negs_p == len(negs): non_negs_p += 1 elif non_negs_p == len(non_negs): negs_p += 1 elif negs[negs_p] > non_negs[non_negs_p]: negs_p += 1 else: non_negs_p += 1 if negs_p % 2 == 0 or k == n: ans = 1 for i in range(negs_p): ans = ans * -negs[i] % MOD for i in range(non_negs_p): ans = ans * non_negs[i] % MOD print(ans) exit() if negs_p == len(negs) or non_negs_p == 0: negs_p -= 1 non_negs_p += 1 ans = 1 for i in range(negs_p): ans = ans * -negs[i] % MOD for i in range(non_negs_p): ans = ans * non_negs[i] % MOD print(ans) exit() if non_negs_p == len(non_negs) or negs_p == 0: negs_p += 1 non_negs_p -= 1 ans = 1 for i in range(negs_p): ans = ans * -negs[i] % MOD for i in range(non_negs_p): ans = ans * non_negs[i] % MOD print(ans) exit() a = negs[negs_p - 1] b = negs[negs_p] c = non_negs[non_negs_p - 1] d = non_negs[non_negs_p] if a * b > c * d: negs_p += 1 non_negs_p -= 1 else: negs_p -= 1 non_negs_p += 1 ans = 1 for i in range(negs_p): ans = ans * -negs[i] % MOD for i in range(non_negs_p): ans = ans * non_negs[i] % MOD print(ans)
0
null
5,301,334,870,822
54
112
l = [int(x.strip()) for x in input().split()] print(l.index(0)+1)
# n,k = map(int,input().split()) # A = list(map(int,input().split())) # c = 0 # from collections import Counter # d = Counter() # d[0] = 1 # ans = 0 # r = [0]*(n+1) # for i,x in enumerate(A): # if i>=k-1: # d[r[i-(k-1)]]-=1#ここで範囲kからはみ出たものの数を減らす # c = (c+x-1)%k # ans += d[c] # d[c] += 1 # r[i+1] = c # print(ans) n,k = map(int,input().split()) A = list(map(int,input().split())) S = [0] for a in A: S.append(S[-1] + a) # print(S) from collections import defaultdict dic = defaultdict(int) ans = 0 for i,s in enumerate(S): if i >=k: dic[(S[i-k] - (i-k))%k]-=1 ans += dic[(S[i]- i)%k] # print(i,s,(S[i]- i)%k,dic[(S[i]- i)%k],ans) dic[(S[i]- i)%k] += 1 print(ans) #(12-6)%4
0
null
75,170,935,180,320
126
273
n, k = map(int, input().split()) a = list(map(int, input().split())) mod = 10 ** 9 + 7 plus = [] minus = [] for i in a: if i >= 0: plus.append(i) if i < 0: minus.append(-i) plus.sort(reverse=True) minus.sort(reverse=True) ans = 1 if k == n: for x in a: ans = (ans * x) % mod elif n == len(plus): for x in plus[:k]: ans = (ans * x) % mod elif n == len(minus): if k % 2 == 1: ans = -1 minus.sort() for x in minus[:k]: ans = (ans * x) % mod else: i, j = 0, 0 if k % 2 == 1: ans = plus[0] i += 1 while i + j != k: x_p = plus[i] * plus[i + 1] if i < len(plus) - 1 else 0 x_m = minus[j] * minus[j + 1] if j < len(minus) - 1 else 0 if x_p > x_m: ans = (ans * x_p) % mod i += 2 else: ans = (ans * x_m) % mod j += 2 print(ans)
n, k = map(int, input().split()) a = list(map(int, input().split())) mod = 10**9 + 7 res = 1 a.sort(reverse=True) if a[0]<0 and k%2==1: for i in range(k): res = (res*a[i])%mod else: right = n-1 left = 0 while k > 1: if a[right]*a[right-1] < a[left]*a[left+1]: res = (res*a[left])%mod left += 1 k -= 1 else: res = (res*a[right]*a[right-1])%mod right -= 2 k -= 2 if k == 1: res = (res*a[left])%mod print(res)
1
9,374,480,094,222
null
112
112
n=int(input()) s=str(input()) if(n%2!=0): print('No') else: if(s[0:len(s)//2]==s[len(s)//2:]): print('Yes') else: print('No')
def main(): import sys readline = sys.stdin.buffer.readline n = int(readline()) s = readline().rstrip().decode('utf-8') print('Yes' if s[:n//2] == s[n//2:] else 'No') if __name__ == '__main__': main()
1
146,983,355,935,318
null
279
279
while True: card = str(input()) if card == '-': break S = int(input()) for i in range(S): h = int(input()) card = card[h:] + card[:h] print(card)
while True: data = input() if(data == "-"):break m = int(input()) tmp = [] for i in range(m): num = int(input()) if(len(tmp) == 0): tmp = data[num:] + data[:num] data = "" else: data = tmp[num:] + tmp[:num] tmp = "" if(data): print(data) else: print(tmp)
1
1,888,152,831,360
null
66
66
a,b,c=map(int,input().split()) d=0 while b<=a: b*=2 d+=1 while c<=b: c*=2 d+=1 print("Yes"if d<=int(input())else"No")
N = int(input()) n = 1 S = [] while n <= N: s = str(input()) S.append(s) n += 1 print("AC x", S.count("AC")) print("WA x", S.count("WA")) print("TLE x", S.count("TLE")) print("RE x", S.count("RE"))
0
null
7,802,702,688,224
101
109
i = 0 while True: i += 1 num = raw_input() if num == "0": break print "Case %d: %s" % (i,num)
import sys def main(): i = 1 while True: x = int(sys.stdin.readline()) if x != 0: print("Case {0}: {1}".format(i, x)) i += 1 else: break return if __name__ == '__main__': main()
1
485,030,741,984
null
42
42
#!/usr/bin/env python3 import sys def main(): N, M = map(int, input().split()) if M % 2 == 1: for i in range(M//2): print(i+1,M-i) for j in range(M//2 + 1): print(M+1+j,2*M+1-j) else: for i in range(M//2): print(i+1, M+1-i) for j in range(M//2): print(M+2+j,2*M+1-j) if __name__ == '__main__': main()
def n0():return int(input()) def n1():return [int(x) for x in input().split()] def n2(n):return [int(input()) for _ in range(n)] def n3(n):return [[int(x) for x in input().split()] for _ in range(n)] n,m=n1() if n%2==0: if m>=2: e=n//2 s=1 l=e-s c=0 while e>s and c<m: print(s,e) s+=1 e-=1 c+=1 e=n s=n-l+1 while e>s and c<m: print(s,e) s+=1 e-=1 c+=1 else: print(1,2) else: if m>=2: e=n//2+1 s=1 l=e-s c=0 while e>s and c<m : print(s,e) s+=1 e-=1 c+=1 e=n s=n-l+1 while e>s and c<m: print(s,e) s+=1 e-=1 c+=1 else: print(1,2)
1
28,496,343,438,750
null
162
162
from collections import defaultdict h,w,m = map(int,input().split()) dh = defaultdict(int) dw = defaultdict(int) l=defaultdict(tuple) for _ in range(m): x,y = map(int,input().split()) dh[x]+=1 dw[y]+=1 l[(x,y)]=1 m = 0 for i in range(1,h+1): if dh[i]>m: m = dh[i] hi=i c=m m = 0 for i in range(1,w+1): d = dw[i] if l[(hi,i)]==1: d-=1 m = max(m,d) c+=m m = 0 wi=0 for i in range(1,w+1): if dw[i]>m: m = dw[i] wi=i c2=m m = 0 for i in range(1,h+1): d = dh[i] if l[(i,wi)]==1: d-=1 m = max(m,d) c2+=m print(max(c,c2))
import math a,b = [int(x) for x in input().split()] ma = int(a//0.08) mb = int(b//0.1) fmindi = False mindi = 9999999999999 for x in range(min(ma,mb),max(ma,mb)+2): j = math.floor(x*0.08) e = math.floor(x*0.1) if j == a and e == b: fmindi = True mindi = min(mindi,x) print(mindi if fmindi else -1)
0
null
30,495,385,228,000
89
203
n, q = map(int, input().split()) l = [] for i in range(n): t = [] for j in input().split(): t += [j] t[1] = int(t[1]) l += [t] c = 0 while len(l) > 0: if l[0][1] > q: l[0][1] -= q l += [l[0]] l.pop(0) c += q else: c += l[0][1] print(l[0][0], c) l.pop(0)
# -*- coding: utf-8 -*- """ Created on Sun Apr 29 18:04:22 2018 ALDS1_3b_r リングバッファによる実装 @author: maezawa """ def fifo_enque(data): global tail global fifo fifo[tail] = data tail = (tail+1)%fifo_size def fifo_deque(): global head global fifo data = fifo[head] head = (head+1)%fifo_size return data fifo_size = 100000 fifo = [0 for _ in range(fifo_size)] head = 0 tail = 0 n, q = list(map(int, input().split())) for i in range(n): s = input().split() data = [s[0], int(s[1])] fifo_enque(data) current_time = 0 finished = [] fin_time = [] while True: data = fifo_deque() if data[1] > q: current_time += q data[1] -= q fifo_enque(data) else: current_time += data[1] finished.append(data[0]) fin_time.append(current_time) if head == tail: break for i in range(n): print("{} {}".format(finished[i], fin_time[i]))
1
42,253,307,030
null
19
19
def main(): a, b = map(int, input().split()) import math print(int(a*b/math.gcd(a,b))) if __name__ == "__main__": main()
A, B = map(int, input().split()) n = 1 while True: A_ = A * n if A_ % B == 0: print(A_) exit() n += 1
1
113,437,010,091,782
null
256
256
A, B, C, K = map(int, input().split()) if K<=A: print(1*K) elif A<K<=A+B: print(1*A) else: print(1*A-1*(K-A-B))
A, B, C = map(int, input().split()) if A == B == C or A != B and B != C and A != C: print("No") else: print("Yes")
0
null
44,908,101,512,438
148
216
import math a, b, C = map(int, input().split()) C = C / 180 * math.pi S = a * b * math.sin(C) / 2 print(S) print(a + b + math.sqrt(a**2 + b**2 - 2*a*b*math.cos(C))) print(2 * S / a)
n = int(input()) state10 = 1 state9 = 1 state8 = 1 mod = 10**9 + 7 for _ in range(n): state10 *= 10 state10 %= mod state9 *= 9 state9 %= mod state8 *= 8 state8 %= mod ans = state10 - 2*state9 + state8 ans %= mod print(ans)
0
null
1,662,516,556,320
30
78
cc = input().rstrip() r = 'a' if ord('a') <= ord(cc) and ord(cc) <= ord('z') else 'A' print(r)
x,y=map(int,input().split()) if ((4*x-y)%2==0 and (-2*x+y)%2==0) and (1<=(4*x-y)//2<=100 and 1<=(-2*x+y)//2<=100): print('Yes') elif ((4*x-y)%2==0 and (-2*x+y)%2==0) and (1<=(4*x-y)//2<=100 and (-2*x+y)//2==0): print('Yes') elif ((4*x-y)%2==0 and (-2*x+y)%2==0) and ((4*x-y)//2==0 and 1<=(-2*x+y)//2<=100): print('Yes') else : print('No')
0
null
12,576,027,798,360
119
127
import math as m h,w = map(int, input().split()) if (h==1) or (w==1): print(1) else: print(m.ceil(h*w/2))
x = list(map(int,input().split())) H = x[0] W = x[1] if H == 1 or W == 1: print(1) else: if W % 2 == 0: print(int(H*W/2)) else: if H % 2 == 0: print(int(H*(W-1)/2 + H/2)) else: print(int(H*(W-1)/2 + (H+1)/2))
1
51,060,723,197,582
null
196
196
#!/usr/bin/env python3 n = int(input()) print(int((n - 1) / 2) if n % 2 == 1 else int(n / 2) - 1)
import math a = float(input()) print("{0:.6f} {1:.6f}".format(a*a*math.pi, a*2.0*math.pi))
0
null
77,083,258,413,090
283
46
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 MOD = 1000000007 def main(): N, *A = map(int, read().split()) M = 61 C = [0] * M for a in A: a = str(format(a, 'b')) for i, d in enumerate(reversed(a)): if d == '1': C[i] += 1 ans = 0 p = 1 for c in C: ans = (ans + c * (N - c) * p) % MOD p = p * 2 % MOD print(ans) return if __name__ == '__main__': main()
import sys input = sys.stdin.readline MOD = pow(10, 9) + 7 n = int(input()) a = list(map(int, input().split())) m = max(a) num = [0] * 61 for x in a: for j in range(61): if (x >> j) & 1: num[j] += 1 s = 0 #print(num) for i in range(61): s += (n - num[i]) * num[i] * pow(2, i, MOD) % MOD print(s % MOD)
1
122,745,925,922,620
null
263
263
# # author sidratul Muntaher # date: Aug 19 2020 # n = int(input()) from math import pi print(pi* (n*2))
from sys import stdin input = stdin.readline def main(): N, K = map(int, input().rstrip().split()) A = list(map(int, input().rstrip().split())) F = list(map(int, input().rstrip().split())) A.sort() F.sort(reverse=True) l = -1 r = 10 ** 12 while(r - l > 1): c = (l + r) // 2 s = 0 for i in range(N): d = A[i] - (c // F[i]) s += max(0, d) if s <= K: r = c else: l = c print(r) if __name__ == "__main__": main()
0
null
97,821,833,876,730
167
290
N, K, C = map(int, input().split()) S = input() L = [0] * K i = 0 x = 0 while i<K and x<N: if S[x] == 'o': L[i] = x i += 1 x += C+1 else: x += 1 R = [0] * K i = K-1 x = N-1 while i>=0 and x>=0: if S[x] == 'o': R[i] = x i -= 1 x -= C+1 else: x -= 1 ans = [] for i in range(K): if L[i] == R[i]: ans.append(L[i]) for a in ans: print(a+1)
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy sys.setrecursionlimit(10**7) inf = 10**20 mod = 10**9 + 7 stdin = sys.stdin ni = lambda: int(ns()) na = lambda: list(map(int, stdin.readline().split())) ns = lambda: stdin.readline().rstrip() # ignore trailing spaces n, a, b = na() if a == 0: print(0) else: print((n//(a+b))*a + min(n%(a+b), a))
0
null
48,297,038,773,408
182
202
a,b,c = map(int, raw_input().split()) value = [a,b,c] value.sort() value_str = map(str, value) print " ".join(value_str)
print(*sorted(map(int,input().split())))
1
418,710,695,000
null
40
40
import sys line = sys.stdin.readline() s = int(line) % 60 i = int(line) / 60 m = i % 60 h = i /60 print str(h) + ":" + str(m) + ":" + str(s)
S = input() h = S/3600 m = (S - 3600*h)/60 s = S -3600*h -60*m print "%d:%d:%d" %(h, m, s)
1
330,855,810,028
null
37
37
def prime_factorize(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: a.append(n) return a dum = prime_factorize(int(input())) dum_len = len(dum) num = 0 ans = 0 cnt = 0 check = 0 for i in range(dum_len): if num == dum[i]: cnt += 1 if cnt >= check: check += 1 ans += 1 cnt = 0 else: num = dum[i] ans += 1 cnt = 0 check = 2 print(ans)
def divideprime(n): ret = [] i = 2 while i*i <= n: cnt = 0 if(n%i != 0): i += 1 continue while n % i == 0: cnt += 1 n //= i ret.append([i,cnt]) i += 1 if n != 1: ret.append([n,1]) return ret N = int(input()) divp = divideprime(N) ans = 0 for t in divp: cnt = 0 e = 0 s = set([]) while (t[1]-e > 0) and (t[1]-e not in s): ans += 1 cnt += 1 e += cnt s.add(cnt) print(ans)
1
17,066,907,100,910
null
136
136
nstr=input() keta=len(nstr) wa=0 for i in range(keta): wa+=int(nstr[i]) ans="No" if wa%9==0: ans="Yes" print(ans)
H1, M1, H2, M2, K = list(map(int,input().split())) a = 60*H1 + M1 b = 60*H2 + M2 print(b - a - K)
0
null
11,323,412,464,180
87
139
import sys h, w, m = map(int, input().split(' ')) H = [0 for _ in range(h+1)] W = [0 for _ in range(w+1)] bomb = set() for m in range(m): i, j = map(int, input().split(' ')) bomb.add((i, j)) H[i] += 1 W[j] += 1 max_h = max(H) max_w = max(W) target_h = [i for i, v in enumerate(H) if v == max_h] target_w = [i for i, v in enumerate(W) if v == max_w] for m in target_h: for n in target_w: if (m, n) not in bomb: print(max_h + max_w) sys.exit() print(max_h + max_w - 1)
from collections import defaultdict H, W, M = map(int, input().split()) row_bom_cnt = defaultdict(int) col_bom_cnt = defaultdict(int) row_max = 0 col_max = 0 boms = [list(map(int, input().split())) for _ in range(M)] for rm, cm in boms: row_bom_cnt[rm] += 1 col_bom_cnt[cm] += 1 row_max = max(row_max, row_bom_cnt[rm]) col_max = max(col_max, col_bom_cnt[cm]) target_row = set() for r, val in row_bom_cnt.items(): if val == row_max: target_row.add(r) target_col = set() for c, val in col_bom_cnt.items(): if val == col_max: target_col.add(c) cnt = 0 for rm, cm in boms: if rm in target_row and cm in target_col: cnt += 1 if len(target_row) * len(target_col) == cnt: print(row_max + col_max - 1) else: print(row_max + col_max)
1
4,694,350,234,672
null
89
89
def main(): s = list(input()) for i in range(len(s)): s[i] = "x" L = "".join(s) print(L) if __name__ == "__main__": main()
N = int(input()) dic = {} for i in range(N): s = str(input()) if s in dic: dic[s] += 1 else: dic[s] = 1 S = sorted(dic.values()) t = S[-1] X = [] for key in dic: if dic[key] == t: X.append(key) x = sorted(X) for i in range(len(X)): print(x[i])
0
null
71,200,257,880,768
221
218
l = len(input()) print("".join(["x" for x in range(l)]))
import sys x, y = map(int, input().split()) ans = 0 for i in range(x+1): if y == i*2 + (x - i)* 4: ans = 1 break if ans == 1: print("Yes") else: print("No")
0
null
43,458,465,371,540
221
127
n,m,k=map(int,input().split()) mod=998244353 ans=m*pow(m-1,n-1,mod) ans%=mod if k==0: print(ans) exit() lst=[1]+[1] for i in range(2,n+10): lst.append((lst[-1]*i)%mod) def combinations(n,r): xxx=lst[n] xxx*=pow(lst[n-r],mod-2,mod) xxx%=mod xxx*=pow(lst[r],mod-2,mod) xxx%=mod return xxx for i in range(1,k+1): ans+=(m*pow(m-1,n-1-i,mod)*combinations(n-1,i))%mod ans%=mod print(ans)
N=int(input()) S,T=map(str,input().split()) l=[] a,b=0,0 for i in range(N*2): if (i+1)%2!=0: l.append(S[a]) a+=1 else: l.append(T[b]) b+=1 print(''.join(l))
0
null
67,410,130,055,008
151
255
N = int(input()) A = list(map(int,input().split())) for i in range(N): A[i] = (A[i],i+1) A.sort() ans = '' for tup in A: v, i = tup ans+=str(i)+' ' print(ans)
from heapq import heappush,heappop n=int(input()) a=list(map(int,input().split())) b=[] for i in range(n): heappush(b,(a[i],i+1)) a=[] for i in range(n): c,d=heappop(b) a.append(d) print(*a)
1
180,162,241,064,520
null
299
299
import copy from sys import exit n, k = map(int, input().split()) A = list(map(int, input().split())) mod = 10**9 + 7 plus = [] minus = [] for a in A: if a >= 0: plus.append(a) else: minus.append(a) plus.sort() minus.sort(reverse=True) def is_ans_plus(): if len(plus) > 0: if n == k: if len(minus) % 2 == 0: return True else: return False else: return True else: if k % 2 == 0: return True else: return False ans = 1 if is_ans_plus(): if k % 2 == 1: ans *= plus.pop() k -= 1 for i in range(k // 2): plus_pair, minus_pair = -1, -1 if len(plus) >= 2: plus_pair = plus[-1] * plus[-2] if len(minus) >= 2: minus_pair = minus[-1] * minus[-2] if plus_pair >= minus_pair: ans *= plus_pair plus.pop() plus.pop() else: ans *= minus_pair minus.pop() minus.pop() ans %= mod else: ans = -1 A = sorted([abs(a) for a in A]) for i in range(k): ans *= A[i] ans %= mod print(ans)
def solve(): can_positive = False if len(P) > 0: if k < n: can_positive = True else: can_positive = len(M)%2 == 0 else: can_positive = k%2 == 0 if not can_positive: return sorted(P+M, key=lambda x:abs(x))[:k] P.sort() M.sort(reverse=True) a = [P.pop()] if k%2 else [1] while len(P) >= 2: a.append(P.pop() * P.pop()) while len(M) >= 2: a.append(M.pop() * M.pop()) return a[:1] + sorted(a[1:], reverse=True)[:(k-k%2)//2] n, k = map(int, input().split()) P, M = [], [] for a in map(int, input().split()): if a < 0: M.append(a) else: P.append(a) ans, MOD = 1, 10**9 + 7 for a in solve(): ans *= a; ans %= MOD ans += MOD; ans %= MOD print(ans)
1
9,431,214,440,090
null
112
112
import numpy as np h, a = map(int, input().split()) print(int(np.ceil(h / a)))
n, k = map(int, input().split()) p = list(map(int, input().split())) q = [0] m = 0 for i in p: m += (1+i)/2 q.append(m) ans = 0 for i in range(k, n+1): ans = max(q[i]-q[i-k], ans) #あまり深く事を考えずに print(ans)
0
null
76,098,988,932,500
225
223
INF=float('inf') def solve1(): dp=[[-INF]*2 for i in range(N+1)] dp[0][0]=0;dp[1][0]=A[0];dp[2][1]=A[1] for i in range(N): if dp[i+1][0]==-INF: if i-1>=0: dp[i+1][0]=max(dp[i+1][0],dp[i-1][0]+A[i]) if dp[i+1][1]==-INF: if i-1>=0: dp[i+1][1]=max(dp[i+1][1],dp[i-1][1]+A[i]) if i-2>=0: dp[i+1][1]=max(dp[i+1][1],dp[i-2][0]+A[i]) print(max(dp[N][1],dp[N-1][0])) return def solve2(): dp=[[-INF]*3 for i in range(N+1)] dp[0][0]=0;dp[1][0]=A[0];dp[2][1]=A[1];dp[3][2]=A[2] for i in range(N): if dp[i+1][0]==-INF: if i-1>=0: dp[i+1][0]=max(dp[i+1][0],dp[i-1][0]+A[i]) if dp[i+1][1]==-INF: if i-1>=0: dp[i+1][1]=max(dp[i+1][1],dp[i-1][1]+A[i]) if i-2>=0: dp[i+1][1]=max(dp[i+1][1],dp[i-2][0]+A[i]) if dp[i+1][2]==-INF: if i-1>=0: dp[i+1][2]=max(dp[i+1][2],dp[i-1][2]+A[i]) if i-2>=0: dp[i+1][2]=max(dp[i+1][2],dp[i-2][1]+A[i]) if i-3>=0: dp[i+1][2]=max(dp[i+1][2],dp[i-3][0]+A[i]) print(max(dp[N][2],dp[N-1][1],dp[N-2][0])) return N=int(input()) A=list(map(int,input().split())) if N%2==0: solve1() else: solve2()
s = input() if 'A' in s and 'B' in s: print('Yes') else: print('No')
0
null
46,398,782,456,348
177
201
n = input() R = [input() for i in xrange(n)] m = R[0] ans = -1e10 for r in R[1:]: ans = max(ans, r - m) m = min(m, r) print ans
N = int(input()) List = [list(map(str, input().split())) for i in range(0,N)] X = str(input()) yoroshiosu = 0 samu = 0 for i in range (0, N): if X == List[i][0]: yoroshiosu =1 elif yoroshiosu == 0: continue else: samu+=int(List[i][1]) print(samu)
0
null
48,242,815,598,108
13
243
from collections import deque import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines def bfs(field, sx, sy, seen): queue = deque([(sx, sy)]) seen[sx][sy] += 1 while queue: x, y = queue.popleft() for dx, dy in [(-1, 0), (0, 1), (1, 0), (0, -1)]: nx = x + dx ny = y + dy if seen[nx][ny] == -1 and field[nx][ny] != "#": seen[nx][ny] = seen[x][y] + 1 queue.append((nx, ny)) return seen[x][y] def main(): H,W = map(int, readline().split()) c = ["#" * (W + 2)] for _ in range(H): c.append("#" + readline().strip() + "#") c.append("#" * (W + 2)) ans = 0 for sx in range(1,H+1): for sy in range(1,W+1): if c[sx][sy] == ".": seen = [[-1] * (W + 2) for i in range(H+2)] dist = bfs(c, sx, sy, seen) ans = max(ans, dist) print(ans) if __name__ == "__main__": main()
n = int(input()) s = input() ans = s.count('R') * s.count('G') * s.count('B') for i in range(n): for j in range(i + 1, n): if j * 2 - i >= n: continue if s[i] == s[j] or s[j] == s[2 * j - i] or s[i] == s[2 * j - i]: continue ans -= 1 print(ans)
0
null
65,156,292,492,640
241
175
import sys def input(): return sys.stdin.readline().strip() def main(): N, T = map(int, input().split()) cv = [tuple(map(int, input().split())) for _ in range(N)] dp1 = [[0]*(T+1) for _ in range(N+2)] # [0, i] dp2 = [[0]*(T+1) for _ in range(N+2)] # [i, N] # 貰うdp for i in range(N): cost, value = cv[i] # dp1 for now in range(min(T+1, cost)): dp1[i+1][now] = dp1[i][now] for now in range(cost, T+1): old = now - cost dp1[i+1][now] = max(dp1[i][now], dp1[i][old] + value) # dp2 cost, value = cv[(N-i)-1] for now in range(min(T+1, cost)): dp2[N-i][now] = dp2[N-(i-1)][now] for now in range(cost, T+1): old = now - cost dp2[N-i][now] = max(dp2[N-(i-1)][now], dp2[N-(i-1)][old] + value) ans = 0 for i in range(1, N+1): i_value = cv[i-1][1] i_max = max([dp1[i-1][j] + dp2[i+1][(T-1)-j] + i_value for j in range(T)]) ans = max(ans, i_max) print(ans) if __name__ == "__main__": main()
import sys global status, d status = {} d=0 def bfs(keys, GRAPH, depth=0): global status if depth>10: quit buf =[] for e in keys: if status[e]==-1: status[e]=depth for e2 in GRAPH[e]: try: if status[e2] == -1: buf.append(e2) except: pass if buf !=[]: bfs(buf, GRAPH, depth+1) return n = int(raw_input()) x = {} for i in range(n): seq = map(int,raw_input().split()) key = seq[0] if key != 0: x[key] = seq[2:] else: x[key]=[] status[key] = -1 for e in x.keys(): if e == 1: bfs([e], x) for e in x.keys(): print e, status[e]
0
null
75,624,844,806,350
282
9
a, b = map(int, input().split()) if 1<=a<=9 and 1<=b<=9: print(a*b) else: print(-1)
A,B=map(int,input().split()) print(A*B if 1<=A<=9 and 0<B<10 else -1)
1
158,332,705,326,070
null
286
286
S = input() def kaibun(S): for i in range(len(S) // 2): if S[i] != S[len(S) - i - 1]: return False return True if kaibun(S) and kaibun(S[:(len(S) - 1)//2]) and kaibun(S[(len(S) + 3) // 2-1:]): print('Yes') else: print('No')
X, K, D = map(int, input().split()) X = abs(X) a = K*D if X >= a: result = X-a else: b = X//D c = (X-b*D) d = abs(X-(b+1)*D) if c < d: if b%2==K%2: result = c else: result = d else: if (b+1)%2==K%2: result=d else: result=c print(result)
0
null
25,530,540,442,460
190
92
S = input() N = len(S) count1,count2,count3 = 0,0,0 flg1,flg2,flg3 = False,False,False for i in range(N): #print(S[i],S[-1-i]) if S[i] == S[-1-i]: count1 += 1 if count1 == N: flg1 = True #print(count1,flg1) a = int((N-1)/2) for i in range(a): #print(S[i],S[a-1-i]) if S[i] == S[a-1-i]: count2 += 1 if count2 == int((N-1)/2): flg2 = True #print(count2,flg2,a) b = int((N+3)/2) #print(b) for i in range(N-b+1): #print(S[b+i-1],S[N-1-i]) if S[b+i-1] == S[N-i-1]: count3 += 1 if count3 == N-b+1 : flg3 = True if flg1 == True and flg2 == True and flg3 == True: print("Yes") else: print("No")
from math import ceil n=int(input()) s=100000 for i in range(n): s +=(s*0.05) s=int(int(ceil(s/1000)*1000)) print(s)
0
null
23,049,885,542,460
190
6
A, B = input().split() # 方針:少数の計算を避け、整数の範囲で計算する # [A*B] = [A*(100*B)/100]と見る # Bを100倍して整数に直す操作は、文字列のまま行う A = int(A) B = int(B.replace('.', '')) # 100で割った整数部分を求める操作は、100で割った商を求めることと同じ ans = (A*B) // 100 print(ans)
def lcm(x, y): import math return (x * y) // math.gcd(x, y) def main(): A, B = map(int, input().split()) ans = lcm(A, B) print(ans) main()
0
null
65,022,307,536,348
135
256
#j-i=Ai+Aj(j>i) #j-Aj=Ai+i #Lj=Ri=X from bisect import bisect_left def main(): N=int(input()) A=list(map(int,input().split())) L={} R={} res=0 for i in range(N): l=(i+1)-A[i] r=A[i]+i+1 if (l in R.keys()): res+=len(R[l]) if (r in R.keys()): R[r].append(i+1) else: R[r]=[i+1] print(res) if __name__=="__main__": main()
N = int(input()) A_list = map(int, input().split()) # [活発度, もとの番号] のリストを降順に並べる A_list = [[A, index] for index, A in enumerate(A_list)] A_list.sort(reverse=True) # print(A_list) dp = [[0 for i in range(N+1)] for j in range(N+1)] # print(dp) for left in range(0, N): for right in range(0, N - left): # print(f'left, righte: { left, right }') # print(A_list[left + right - 1][0]) activity = A_list[left + right][0] distance_from_left = A_list[left + right][1] - left # print(f'distance_from_left: { distance_from_left }') distance_from_right = (N - 1 - right) - A_list[left + right][1] # print(f'distance_from_right: { distance_from_right }') dp[left + 1][right]\ = max(dp[left + 1][right], dp[left][right] + activity * distance_from_left) dp[left][right + 1]\ = max(dp[left][right + 1], dp[left][right] + activity * distance_from_right) # print('dp---') # print(dp) # print('---dp') # print(dp) dp_list = [flatten for inner in dp for flatten in inner] print(max(dp_list))
0
null
29,837,875,435,332
157
171
def prime_factorize(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: a.append(n) return a x = int(input()) while True: p = prime_factorize(x) if len(p) == 1: print(p[0]) break x += 1
import sys readline = sys.stdin.readline MOD = 10 ** 9 + 7 INF = float('INF') sys.setrecursionlimit(10 ** 5) def main(): X = int(readline()) def enum_primes(n): flag_num = (n + 1) // 2 prime_flag = [True] * flag_num for num in range(3, int(n ** 0.5) + 1, 2): idx = (num - 1) // 2 - 1 if prime_flag[idx]: for j in range(idx + num, flag_num, num): prime_flag[j] = False primes = [2] temp = [(i + 1) * 2 + 1 for i in range(flag_num) if prime_flag[i]] primes.extend(temp) return primes primes = enum_primes(10 ** 6) for prime in primes: if prime >= X: return print(prime) if __name__ == '__main__': main()
1
106,035,078,836,710
null
250
250
S=list(str(input())) ans=0 sofar=0 j=1 nax=0 for i in range(len(S)-1): if S[i]==S[i+1]: ans+=j j+=1 elif S[i]=='<' and S[i+1]=='>': ans+=j nax=j j=1 else: ans+=j if nax!=0: ans-=j j=1 nax=0 if j>nax: ans-=nax nax=0 if j>nax: ans+=j ans-=nax print(ans)
n,k = map(int,input().split()) mod = 1000000007 def comb(n,k): if n < k: return 0 if n < 0 or k < 0: return 0 return fac[n]*finv[k]%mod*finv[n-k]%mod fac = [1]*(n+1) finv = [1]*(n+1) for i in range(1,n+1): fac[i] = fac[i-1]*i%mod finv[i] = pow(fac[i],mod-2,mod) ans = 0 for i in range(min(k+1,n)): ans += comb(n,i)*comb(n-1,i)%mod ans %= mod print(ans)
0
null
111,635,634,617,622
285
215
N = int(input()) ST = [] for i in range(N): X, L = map(int, input().split()) ST.append((X - L, X + L)) ST.sort(key=lambda x: x[1]) ans = 0 cur = -1e9 for i in range(N): S, T = ST[i] if cur <= S: ans += 1 cur = T print(ans)
def main(): n = int(input()) A = [] for _ in range(n): x, l = map(int, input().split()) A.append([x - l, x + l]) A.sort(key = lambda x: x[1]) ans, lmax = 0, -10 ** 11 for a in A: if lmax <= a[0]: ans += 1 lmax = a[1] print(ans) if __name__ == '__main__': main()
1
89,959,795,386,048
null
237
237
# ABC178D Manhattan n = int(input()) z = [] w = [] for i in range(n): x,y = map(int, input().split()) z.append(x-y) w.append(x+y) z_ans = max(z)-min(z) w_ans = max(w)-min(w) print(max(z_ans,w_ans))
# -*- coding: utf-8 -*- # 入力を整数に変換して受け取る def input_int(): return int(input()) # マイナス1した値を返却 def int1(x): return int(x) - 1 # 半角スペース区切り入力をIntに変換してMapで受け取る def input_to_int_map(): return map(int, input().split()) # 半角スペース区切り入力をIntに変換して受け取る def input_to_int_tuple(): return tuple(map(int, input().split())) # 半角スペース区切り入力をIntに変換してマイナス1した値を受け取る def input_to_int_tuple_minus1(): return tuple(map(int1, input().split())) def main(): n = input_int() cnt = [[0] * 10 for i in range(10)] for n in range(1, n + 1): cnt[int(str(n)[0])][int(str(n)[-1])] += 1 ret = 0 for i in range(10): for j in range(10): ret += cnt[i][j] * cnt[j][i] return ret if __name__ == "__main__": print(main())
0
null
44,983,937,614,580
80
234
suit = ['S', 'H', 'C', 'D'] cards = [[i, j] for i in suit for j in map(str, range(1, 14))] for i in range(input()): cards.remove(raw_input().split()) for i in cards: print i[0],i[1]
all = [suit + ' ' + str(rank) for suit in 'SHCD' for rank in range(1, 14)] for _ in range(int(input())): all.remove(input()) for card in all: print(card)
1
1,038,563,119,100
null
54
54