s_id
stringlengths
10
10
p_id
stringlengths
6
6
u_id
stringlengths
10
10
date
stringlengths
10
10
language
stringclasses
1 value
original_language
stringclasses
11 values
filename_ext
stringclasses
1 value
status
stringclasses
1 value
cpu_time
stringlengths
1
5
memory
stringlengths
1
7
code_size
stringlengths
1
6
code
stringlengths
1
539k
s792445931
p03964
u118605645
1532164522
Python
Python (3.4.3)
py
Runtime Error
17
3060
208
import math N = int(input()) x = 1 y = 1 for i in range(N): a, t = map(int, input().split()) m = math.ceil(x / a) n = math.ceil(y / b) k = max(m, n) x, y = (a * k, t * k) print(x + y)
s491561495
p03964
u952708174
1525893593
Python
Python (3.4.3)
py
Runtime Error
20
3188
422
def c_atcodeer_and_election_report(N, R): t, a = 1, 1 # 高橋, 青木の票数 for x, y in R: # t<=nx ∧ a<=ny を満たす最小のnを求める n = max(t // x, a // y) if t > n * x or a > n * y: n += 1 t = n * x a = n * y return t + a N = int(input()) R = [[int(i) for i in input().split()] for j in range(N)] print(c_AtCoDeer_and_ElectionReport(N, R))
s005112099
p03964
u503901534
1525809599
Python
Python (3.4.3)
py
Runtime Error
17
2940
240
n = int(input()) import math as m tt , aa = map(int,input().split()) vote = tt + aa for i in range(n-1): t, a = map(int,input().split()) n = m.flo-or((max((tt/t),(aa/a)))) tt = t * n aa = a * n vote = tt + aa print(vote)
s433562943
p03964
u503901534
1525759460
Python
Python (3.4.3)
py
Runtime Error
17
3060
211
n = int(input()) import math as m tt , aa = map(int,input().split()) vote = tt + aa for i in range(n-1): t, a = map(int,input().split()) n = max(m.cail(tt/t),m.ceil(aa/a)) vote = vote * n print(vote)
s463055711
p03964
u503901534
1525759061
Python
Python (3.4.3)
py
Runtime Error
17
2940
444
n = int(input()) vote = 0 tt = 0 aa = 0 for i in range(n): t, a = map(int,input().split()) if (tt < t and aa = a) or (tt = t and aa < a) or (tt< t and aa <a): tt = t aa = a vote = t + a else: count = 1 s = t + a while vote > s: count = count + 1 s = s * count vote = s tt = count * t ss = count * a print(vote)
s579975053
p03964
u125205981
1524387164
Python
Python (3.4.3)
py
Runtime Error
20
3064
360
def main(): N = int(input()) A = tuple(tuple(map(int, input().split())) for _ in [0] * N) before_t = A[0][0] before_a = A[0][1] for t, a in A[1:]: n1 = -(-before_t // t) n2 = -(-before_a // a) n = max(n1, n2) taka, aoki = t * n, a * n before_t, before_a = taka, aoki print(taka + aoki) main()
s275355749
p03964
u075012704
1515784151
Python
Python (3.4.3)
py
Runtime Error
51
5472
359
from fractions import gcd N = int(input()) TA = [list(map(int, input().split())) for i in range(N)] ans = 0 pre_t = 0 pre_a = 0 for t, a in TA: gcd = gcd(t, a) t = t * gcd a = a * gcd first_t = t first_a = a while (pre_t > t) or(pre_a > a): t += first_t a += first_a pre_t = t pre_a = a print(t + a)
s746865517
p03964
u075012704
1515784073
Python
Python (3.4.3)
py
Runtime Error
51
5560
361
from fractions import _gcd N = int(input()) TA = [list(map(int, input().split())) for i in range(N)] ans = 0 pre_t = 0 pre_a = 0 for t, a in TA: gcd = _gcd(t, a) t = t * gcd a = a * gcd first_t = t first_a = a while (pre_t > t) or(pre_a > a): t += first_t a += first_a pre_t = t pre_a = a print(t + a)
s479405876
p03964
u190405389
1507506301
Python
Python (3.4.3)
py
Runtime Error
18
2940
257
n = int(input()) ta = [list(map(int, input().split())) for i in range(n)] t = 1 a = 1 for i in range(n): x = max(t//ta[i][0], a//ta[i][1]) if t > ta[i][0] * x or a > ta[i][1] * x x += 1 t = ta[i][0] * x a = ta[i][1] * x print(t+a)
s982148726
p03964
u190405389
1507504382
Python
Python (3.4.3)
py
Runtime Error
17
3064
263
= int(input()) ta = [list(map(int, input().split())) for i in range(n)] t = ta[0][0] a = ta[0][1] for i in range(n): tt = ta[i][0] aa = ta[i][1] while t > tt or a > aa: tt += ta[i][0] aa += ta[i][1] t = tt a = aa print(t+a)
s585574317
p03964
u816631826
1506437049
Python
Python (2.7.6)
py
Runtime Error
11
2692
234
t = int(raw_input()) A, B = 1, 1 for _ in range(t): a, b = tuple(map(int, raw_input().split())) c, d = int(ceil(float(A) / float(a))), int(ceil(float(B) / float(b))) e = max(c, d) A, B = a * e, b * e print sum((A, B))
s737210454
p03964
u559722042
1489908273
Python
Python (3.4.3)
py
Runtime Error
18
3060
206
import sys import math n = map(int,input().split()) T,A = 1,1 for i in range(n): t,a = map(int,input().split()) coef = max((T+t-1)//t,(A+a-1)//a) T,A = coef * t, coef * a print(T+A)
s088004219
p03964
u559722042
1489908257
Python
Python (3.4.3)
py
Runtime Error
17
3060
198
import sys import math n = map(int,input()) T,A = 1,1 for i in range(n): t,a = map(int,input().split()) coef = max((T+t-1)//t,(A+a-1)//a) T,A = coef * t, coef * a print(T+A)
s491979539
p03964
u348405655
1486689879
Python
Python (3.4.3)
py
Runtime Error
26
3064
282
N = int(input()) T = [] A = [] Nb = 0 for i in range(N): a, b = map(int,input().split()) T.append(a) A.append(b) Tn = 1 An = 1 for i in range(N): tmp = max(math.ceil(Tn / T[i]), math.ceil(An / A[i])) Tn = T[i] * tmp An = A[i] * tmp print(Tn + An)
s062088877
p03964
u405509847
1478407499
Python
Python (2.7.6)
py
Runtime Error
247
19264
290
import numpy as np import math N=input() T=[] A=[] for i in range(N): Ti,Ai=map(int,raw_input().split()) T.append(Ti) A.append(Ai) Tn=1 An=1 dp = np.zeros(N) dp[0] = 1 for i in range(1,N): dp[i] = math.ceil(max(A[i]/A[i-1],T[i]/T[i-1])*dp[i-1]) print (T[N]+A[N])*dp[N]
s382559118
p03964
u405509847
1478406613
Python
Python (3.4.3)
py
Runtime Error
600
21268
291
import numpy as np import math N=input() T=[] A=[] for i in range(N): Ti,Ai=map(int,raw_input().split()) T.append(Ti) A.append(Ai) Tn=1 An=1 dp = np.zeros(N) dp[0] = 1 for i in range(1,N): dp[i] = math.ceil(max(A[i]/A[i-1],T[i]/T[i-1])*dp[i-1]) print((T[-1]+A[-1])*dp[-1])
s171197891
p03964
u733618878
1477941059
Python
Python (3.4.3)
py
Runtime Error
23
3064
310
import math n = int(input()) i = 0 list = [] while i < n: list.append(input().split()) i += 1 h = 0 th = 1.0 ah = 1.0 while h < n: listh = list[h] x = int(listh[0]) y = int(listh[1]) m = max(math.ceil(th/x)),math.ceil(ah/y))) th = m*x ah = m*y h += 1 print(long(th+ah))
s418809025
p03964
u425448230
1477516315
Python
Python (3.4.3)
py
Runtime Error
23
3064
228
# C from math import ceil #N = int(input()) #T = [[int(i) for i in input().split()] for n in range(N)] m = T[0] for n in range(1, N): a = ceil(max(m[0]/T[n][0], m[1]/T[n][1])) m = [T[n][0] * a, T[n][1] * a] print(sum(m))
s429436095
p03964
u831695469
1476725751
Python
Python (3.4.3)
py
Runtime Error
24
3064
2417
import math N = input() t = [] a = [] for i in range(int(N)): t_n, a_n = input().split() t.append(int(t_n)) a.append(int(a_n)) ma = 0 t_prev = 0 a_prev = 0 t_ans = 0 a_ans = 0 for t_n, a_n in zip(t, a): summ = t_n + a_n summ_cp = summ #i = 0 #while 1: # i += 1 # summ = summ_cp * i # if summ >= ma and ((t_n*i) >= t_prev) and ((a_n*i) >= a_prev): # ma = summ # break #summ = summ_cp * i k = max(math.ceil(t_ans/t_n), math.ceil(a_ans/a_n)) if not k: k = 1 t_ans = k*t_n a_ans = k*a_n print(float((t_ans+a_ans))
s958830687
p03964
u647537044
1476594120
Python
Python (3.4.3)
py
Runtime Error
22
3064
275
import math from decimal import Decimal N = int(input()) T, A = [Decimal(x) for x in input().split()] for i in range(1,N): T2, A2 = [Decimal(x) for x in input().split()] n = max(math.ceil(T/T2),math.ceil(A/A2) T = T2*n A = A2*n print(T + A)
s223291921
p03964
u647537044
1476593679
Python
Python (3.4.3)
py
Runtime Error
22
3064
303
import math from decimal import Decimal N = int(input()) T, A = [int(x) for x in input().split()] for i in range(1,N): T2, A2 = [int(x) for x in input().split()] n = max(math.ceil(Decimal(T)/Decimal(T2)),math.ceil(Decimal(A)/Decimal(A2)) T = T2*n A = A2*n print(T + A)
s804899678
p03964
u647537044
1476593636
Python
Python (3.4.3)
py
Runtime Error
23
3064
395
import math from decimal import Decimal N = int(input()) T, A = [int(x) for x in input().split()] for i in range(1,N): T2, A2 = [int(x) for x in input().split()] print('i= ',i) n = max(math.ceil(Decimal(T)/Decimal(T2)),math.ceil(Decimal(A)/Decimal(A2)) print('n= ',n) T = T2*n A = A2*n print('T= ',T) print('A= ',A) print(T + A)
s588102268
p03964
u813098295
1476586597
Python
Python (2.7.6)
py
Runtime Error
19
2696
265
import math N = int(raw_input()) T, A = map(float, raw_input().split()) for i in range(N - 1): t, a = map(float, raw_input().split()) s1 = math.ceil(T / t) s2 = math.ceil(A / a) s = max(s1, s2) T = s * t A = s * a print "%d" % T + A
s319542199
p03964
u619384481
1476585598
Python
Python (2.7.6)
py
Runtime Error
16
2572
201
time=input() aok=1 tak=1 for i in time: l=map(int, raw_input().split()) if l[0]>=l[1]: tak=(tak/l[1]+1)*l[1] aok=tak/l[1]*l[0] else: aok=(aok/l[0]+1)*l[0] tak=aok/l[0]*l[1] print aok+tak
s538708258
p03964
u140672616
1476585439
Python
Python (3.4.3)
py
Runtime Error
57
5688
161
import fractions n = int(input()) t = 1 a = 1 for i in range(n): x,y = map(int, input().split()) t = fractions.gcd(x) a = fractions.gcd(y) print(t + a)
s752112672
p03964
u813098295
1476585248
Python
Python (2.7.6)
py
Runtime Error
16
2568
476
import math N = int(raw_input()) ans = [0, 0] T, A = [0] * 1001, [0] * 1001 for i in range(N): T[i], A[i] = map(float, raw_input().split()) if i != 0 and T[i - 1] - T[i] >= 0 or A[i - 1] - A[i] >= 0: if (math.ceil(T[i - 1] / T[i]) >= (math.ceil(A[i - 1] / A[i])): m = math.ceil(T[i - 1] / T[i]) else: m = math.ceil(A[i - 1] / A[i]) T[i] *= m A[i] *= m ans = [T[i], A[i]] print "%d" % sum(ans)
s425281343
p03964
u813098295
1476584275
Python
Python (2.7.6)
py
Runtime Error
16
2696
487
import math N = int(raw_input()) ans = [0, 0] T, A = [0] * 1001, [0] * 1001 for i in range(N): T[i], A[i] = map(float, raw_input().split()) if (i != 0) and ((T[i - 1] - T[i] > 0) or (A[i - 1] - A[i] > 0)): if (T[i - 1] / T[i]) > (A[i - 1] / A[i]): m = math.ceil(T[i - 1] / T[i]) else: m = math.ceil(A[i - 1] / A[i]) T[i] *= m A[i] *= m ans = [T[i], A[i]] T[i] /= m A[i] /= m print "%d" % sum(ans)
s631718022
p03964
u813098295
1476582553
Python
Python (2.7.6)
py
Runtime Error
16
2568
475
import math N = int(raw_input()) ans = [] T, A = [0] * 1000, [0] * 1000 for i in range(N): T[i], A[i] = map(int, raw_input().split()) if (i != 0) and ((T[i -1] - T[i] > 0) or (A[i - 1] - A[i] > 0)): if (T[i -1] / T[i]) > (A[i - 1] / A[i]): m = math.ceil(T[i -1] / T[i]) else: m = math.ceil(A[i - 1] / A[i]) T[i] *= m A[i] *= m ans = [T[i], A[i]] print "%d" % sum(ans)
s184389308
p03965
u381585104
1600075705
Python
Python (3.8.2)
py
Runtime Error
33
9068
82
s = input() n = len(s) p = 0 for e in s: if e == 'p': p += 1 print(s//2 - p)
s987606692
p03965
u589969467
1598653199
Python
Python (3.8.2)
py
Runtime Error
54
9988
560
def dfs(i,gu,pa,kati,make): global ans if i==len(s): ans.append(kati-make) return else: if pa==gu: if s[i]=='g': dfs(i+1,gu+1,pa,kati,make) else: dfs(i+1,gu+1,pa,kati,make+1) else: if s[i]=='g': dfs(i+1,gu+1,pa,kati,make) dfs(i+1,gu,pa+1,kati+1,make) else: dfs(i+1,gu+1,pa,kati,make+1) dfs(i+1,gu,pa+1,kati,make) ans = [] s = str(input()) dfs(0,0,0,0,0) print(max(ans))
s876815179
p03965
u074220993
1597077661
Python
Python (3.8.2)
py
Runtime Error
47
9144
164
s = input() N = len(s) D = {} for i in range(N): if s[i] in D: D[s[i]] += 1 else: D[s[i]] = 1 my_p = N//2 score = my_p - D["p"] print(score)
s122478196
p03965
u074220993
1597076682
Python
Python (3.8.2)
py
Runtime Error
49
9192
180
s = input() N = len(s) D = {} for i in range(N): if s[i] in D: D[s[i]] += 1 else: D[s[i]] = 1 my_g = (N+1)//2 my_p = N//2 score = my_p - D["p"] print(score)
s475353351
p03965
u308918401
1591317583
Python
Python (3.4.3)
py
Runtime Error
18
3188
82
s=input() n=len(s) t=0 for i in range(n): if s[i]==p: t+=1 print(int(n/2)-t)
s127703097
p03965
u920543723
1591049260
Python
Python (3.4.3)
py
Runtime Error
18
3060
555
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> P; const long double PI = (acos(-1)); #define rep(i, x, n) for (int i = x; i < (int)(n); i++) #define sc(x) scanf("%d",&x) #define scll(x) scanf("%lld",&x) int main(){ string s; cin >> s; int n = s.size(), p = 0, g = 0, ans = 0; rep(i, 0, n){ if (s[i]=='p'){ if (p < g) p++; else ans--, g++; }else { if (p < g) ans++, p++; else g++; } } cout << ans << endl; return 0; }
s223742714
p03965
u325282913
1590304462
Python
Python (3.4.3)
py
Runtime Error
18
3188
43
print(input().count('g')-(-((-len(s))//2)))
s791512395
p03965
u198062737
1587683242
Python
Python (3.4.3)
py
Runtime Error
121
43140
347
s = input() dp = {i:dict() for i in range(len(s))} def f(i, g): if i == len(s): return 0 if g in dp[i]: return dp[i][g] p = i - g ans = (-1 if s[i] == 'p' else 0) + f(i + 1, g + 1) if p + 1 <= g: ans = max(ans, (1 if s[i] == 'g' else 0) + f(i + 1, g)) dp[i][g] = ans return ans print(f(0, 0))
s301845024
p03965
u096616343
1583804230
Python
Python (3.4.3)
py
Runtime Error
17
2940
117
s = input() g = 0 p = 0 for i in s: if i = "g": g += 1 if i = "p": p += 1 print((g - p) // 2)
s193535120
p03965
u096616343
1583804126
Python
Python (3.4.3)
py
Runtime Error
18
2940
117
s = input() g = 0 p = 0 for i in s: if i = "g": g += 1 if i = "p": p += 1 print((g - p) // 2)
s948852264
p03965
u445624660
1580178812
Python
Python (3.4.3)
py
Runtime Error
2374
1797048
1331
# dpぽい気がするのでそうする # なぜかREなる.... # pythonだとrecursion limitがアレなのを忘れていた... # なぜかTLEなる.... import sys sys.setrecursionlimit(10 ** 8) s = input() dp = {} def rec(i, cur_g, cur_p, tmp, g, p): if i in dp: return dp[i] if i == len(s): ret = p - g dp[i] = ret return ret if cur_g > cur_p: # パーを出せる(出さなくてもいい) if s[i] == "g": ret = max( rec(i + 1, cur_g, cur_p + 1, tmp + "p", g, p + 1), rec(i + 1, cur_g + 1, cur_p, tmp + "g", g, p), ) dp[i] = ret return ret elif s[i] == "p": ret = max( rec(i + 1, cur_g, cur_p + 1, tmp + "p", g, p), rec(i + 1, cur_g + 1, cur_p, tmp + "g", g + 1, p), ) dp[i] = ret return ret else: # 勝てるかどうかにかかわらずグーを出すしか無い if s[i] == "g": ret = rec(i + 1, cur_g + 1, cur_p, tmp + "g", g, p) dp[i] = ret return ret elif s[i] == "p": ret = rec(i + 1, cur_g + 1, cur_p, tmp + "g", g + 1, p) dp[i] = ret return ret print(rec(0, 0, 0, "", 0, 0))
s471534192
p03965
u445624660
1580178229
Python
Python (3.4.3)
py
Runtime Error
84
4692
857
# dpぽい気がするのでそうする # なぜかREなる.... s = input() dp = {} def rec(i, cur_g, cur_p, tmp): # if i in dp: # return dp[i] if i == len(s): ret = 0 for j in range(len(s)): if tmp[j] == "p" and s[j] == "g": ret += 1 elif tmp[j] == "g" and s[j] == "p": ret -= 1 return ret if cur_g > cur_p: # パーを出せる(出さなくてもいい) ret = max( rec(i + 1, cur_g, cur_p + 1, tmp + "p"), rec(i + 1, cur_g + 1, cur_p, tmp + "g"), ) # dp[i] = ret return ret else: # 勝てるかどうかにかかわらずグーを出すしか無い ret = rec(i + 1, cur_g + 1, cur_p, tmp + "g") # dp[i] = ret return ret print(rec(0, 0, 0, ""))
s729210498
p03965
u445624660
1580174579
Python
Python (3.4.3)
py
Runtime Error
84
4616
849
# dpぽい気がするのでそうする # なぜかREなる.... s = input() dp = {} def rec(i, cur_g, cur_p, tmp): if i in dp: return dp[i] if i == len(s): ret = 0 for j in range(len(s)): if tmp[j] == "p" and s[j] == "g": ret += 1 elif tmp[j] == "g" and s[j] == "p": ret -= 1 return ret if cur_g > cur_p: # パーを出せる(出さなくてもいい) ret = max( rec(i + 1, cur_g, cur_p + 1, tmp + "p"), rec(i + 1, cur_g + 1, cur_p, tmp + "g"), ) dp[i] = ret return ret else: # 勝てるかどうかにかかわらずグーを出すしか無い ret = rec(i + 1, cur_g + 1, cur_p, tmp + "g") dp[i] = ret return ret print(rec(0, 0, 0, ""))
s203928184
p03965
u445624660
1580174325
Python
Python (3.4.3)
py
Runtime Error
85
4620
1084
# dpぽい気がするのでそうする s = input() dp = {} def rec(i, cur_g, cur_p, tmp): if i in dp: return dp[i] if i == len(s): ret = 0 for j in range(len(s)): if tmp[j] == "p" and s[j] == "g": ret += 1 elif tmp[j] == "g" and s[j] == "p": ret -= 1 return ret if cur_g > cur_p: # パーを出せる(出さなくてもいい) if s[i] == "g": ret = max( rec(i + 1, cur_g, cur_p + 1, tmp + "p"), rec(i + 1, cur_g + 1, cur_p, tmp + "g"), ) dp[i] = ret return ret else: ret = max( rec(i + 1, cur_g, cur_p + 1, tmp + "p"), rec(i + 1, cur_g + 1, cur_p, tmp + "g"), ) dp[i] = ret return ret else: # 勝てるかどうかにかかわらずグーを出すしか無い ret = rec(i + 1, cur_g + 1, cur_p, tmp + "g") dp[i] = ret return ret print(rec(0, 0, 0, ""))
s528313585
p03965
u097317219
1574600630
Python
PyPy3 (2.4.0)
py
Runtime Error
177
45936
264
s = list(input()) n = len(s) ans = 0 for i in range(n): if s[i] == "g" and flag == 0: flag+=1 elif s[i] == "g" and flag != 0: flag -= 1 ans += 1 elif s[i] == "p" and flag == 0: flag += 1 ans -= 1 else: flag -= 1 print(ans)
s992839991
p03965
u780962115
1573791275
Python
Python (3.4.3)
py
Runtime Error
25
3444
142
#D-atcoderくんと変なジャンケン s=input() import collections S=dict(collections.Counter(s)) a=S["p"] b=S["g"] x=((a+b)//2) print(x-a)
s778967620
p03965
u945181840
1573752290
Python
Python (3.4.3)
py
Runtime Error
622
631460
627
import numpy as np s = input() N = len(s) # 縦:じゃんけんの回数(0回含む)、横:パーを出した回数 そのときの最大スコア # 1回目のじゃんけんではパーは出せない scores = np.zeros((N + 1, N + 1), np.int64) for i in range(2, N + 1): if s[i - 1] == 'g': scores[i, 0] = scores[i - 1, 0] scores[i, 1:i // 2 + 1] = np.maximum(scores[i - 1, :i // 2] + 1, scores[i - 1, 1:i // 2 + 1]) else: scores[i, 0] = scores[i - 1, 0] - 1 scores[i, 1:i // 2 + 1] = np.maximum(scores[i - 1, :i // 2], scores[i - 1, 1:i // 2 + 1] - 1) print(scores[-1].max())
s933614571
p03965
u945181840
1573752239
Python
Python (3.4.3)
py
Runtime Error
415
362936
632
import numpy as np s = input() N = len(s) # 縦:じゃんけんの回数(0回含む)、横:パーを出した回数 そのときの最大スコア # 1回目のじゃんけんではパーは出せない scores = np.zeros((N + 1, N // 2 + 1), np.int64) for i in range(2, N + 1): if s[i - 1] == 'g': scores[i, 0] = scores[i - 1, 0] scores[i, 1:i // 2 + 1] = np.maximum(scores[i - 1, :i // 2] + 1, scores[i - 1, 1:i // 2 + 1]) else: scores[i, 0] = scores[i - 1, 0] - 1 scores[i, 1:i // 2 + 1] = np.maximum(scores[i - 1, :i // 2], scores[i - 1, 1:i // 2 + 1] - 1) print(scores[-1].max())
s159407668
p03965
u945181840
1573751092
Python
Python (3.4.3)
py
Runtime Error
410
362660
614
import numpy as np s = input() N = len(s) # 縦:じゃんけんの回数、横:パーを出した回数 そのときの最大スコア # 1回目のじゃんけんではパーは出せない scores = np.zeros((N, N // 2 + 1), np.int64) for i in range(1, N): if s[i] == 'g': scores[i, 0] = scores[i - 1, 0] scores[i, 1:i // 2 + 2] = np.maximum(scores[i - 1, :i // 2 + 1] + 1, scores[i - 1, 1:i // 2 + 2]) else: scores[i, 0] = scores[i - 1, 0] - 1 scores[i, 1:i // 2 + 2] = np.maximum(scores[i - 1, :i // 2 + 1], scores[i - 1, 1:i // 2 + 2] - 1) print(scores[-1].max())
s225538019
p03965
u084324798
1565401156
Python
Python (3.4.3)
py
Runtime Error
77
4200
296
tcd = input() def dp(i, cnt, g, p): if g == p: if tcd[i] == "p": cnt -= 1 g += 1 else: if tcd[i] == "g": cnt += 1 p += 1 if i == len(tcd)-1: return cnt else: return dp(i+1, cnt, g, p) print(dp(1, 0, 1, 0))
s131998818
p03965
u265626775
1555642281
Python
Python (3.4.3)
py
Runtime Error
17
2940
469
#include<bits/stdc++.h> using namespace std; #define ll long long // #define pair pair<ll,ll> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> const ll mod =1e9+7; int main(){ string s; cin>>s; ll g=0,p=0; ll ans=0; for(ll i=0;s[i];i++){ if(g>p){ p++; ans+=(s[i]=='g'); } else{ g++; ans-=(s[i]=='p'); } } cout<<ans<<endl; }
s330705764
p03965
u268516119
1553454693
Python
PyPy3 (2.4.0)
py
Runtime Error
174
38640
440
# coding: utf-8 # Your code here! import copy S=list(input()) N=len(S) point=0 hand=copy.deepcopy(S) panum=sum([j=="p" for j in hand]) pamax=N//2#ポイントの上限 for i in range(N): if S[i]=="g": pa=sum([hand[j]=="p" for j in range(i+1)])#今まで出したパーの数 if pa<(i+1)//2 and point<pamax-panum: hand[i]="p" point+=1 if point=>pamax-panum: break print(point)
s540006033
p03965
u018679195
1548820818
Python
Python (3.4.3)
py
Runtime Error
17
2940
339
#include<cstdio> #include<iostream> #include<cstring> using namespace std; int main() { string s; cin>>s; int len = s.size(); //nump <= numg int nump = 0, numg = 0; for(int i = 0 ; i < len; i++){ if(s[i] == 'p')nump++; else if(s[i] == 'g')numg++; } cout<<(nump+numg)/2-nump; return 0; }
s643176015
p03965
u903722062
1546465258
Python
Python (3.4.3)
py
Runtime Error
18
2940
786
#include<bits/stdc++.h> #define MAX_N 100001 #define INF_INT 2147483647 #define INF_LL 9223372036854775807 #define REP(i,n) for(int i=0;i<(int)(n);i++) using namespace std; typedef long long int ll; typedef pair<ll,ll> P; void init(int n); int find(int n); void unite(int x,int y); bool same(int x, int y); ll bpow(ll,ll,ll); typedef vector<int> vec; typedef vector<vec> mat; mat mul(mat &A,mat &B); mat pow(mat A,ll n); int dx[4] = {1,0,0,-1}; int dy[4] = {0,1,-1,0}; const int MOD = 1000000007; int main() { int N,T=0; string S; cin >> S; REP(i,S.size()){ if(i%2 == 1){ if(S[i] == 'g'){ T++; }else continue; }else{ if(S[i] == 'g'){ continue; }else{ T--; } } } cout << T << endl; return 0; }
s722482242
p03965
u060392346
1542889479
Python
Python (3.4.3)
py
Runtime Error
17
2940
152
s = input() score = 0 for i in range(len(s)): if i % 2 == 0 and s[i] = "p": score -= 1 elif i % 2 != 0 and s[i] = "g": score += 1 print(s)
s668284602
p03965
u334712262
1534404852
Python
Python (3.4.3)
py
Runtime Error
2110
90172
1409
# -*- coding: utf-8 -*- import bisect import heapq import math import random import sys from collections import Counter, defaultdict, deque from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal from functools import lru_cache, reduce from itertools import combinations, combinations_with_replacement, product, permutations from operator import add, mul, sub sys.setrecursionlimit(10000) def read_int(): return int(input()) def read_int_n(): return list(map(int, input().split())) def read_float(): return float(input()) def read_float_n(): return list(map(float, input().split())) def read_str(): return input().strip() def read_str_n(): return list(map(str, input().split())) def error_print(*args): print(*args, file=sys.stderr) def mt(f): import time def wrap(*args, **kwargs): s = time.time() ret = f(*args, **kwargs) e = time.time() error_print(e - s, 'sec') return ret return wrap @mt def slv(S): N = len(S) @lru_cache(maxsize=None) def f(i, g): r = -sys.maxsize if i == N: return 0 if g > 0: r = max(r, f(i+1, g-1) + (1 if S[i] == 'g' else 0)) r = max(r, f(i+1, g+1) + (-1 if S[i] == 'p' else 0)) return r return f(0, 0) def main(): S = read_str() print(slv(S)) if __name__ == '__main__': main()
s015581976
p03965
u334712262
1534404761
Python
PyPy3 (2.4.0)
py
Runtime Error
2113
119384
1409
# -*- coding: utf-8 -*- import bisect import heapq import math import random import sys from collections import Counter, defaultdict, deque from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal from functools import lru_cache, reduce from itertools import combinations, combinations_with_replacement, product, permutations from operator import add, mul, sub sys.setrecursionlimit(10000) def read_int(): return int(input()) def read_int_n(): return list(map(int, input().split())) def read_float(): return float(input()) def read_float_n(): return list(map(float, input().split())) def read_str(): return input().strip() def read_str_n(): return list(map(str, input().split())) def error_print(*args): print(*args, file=sys.stderr) def mt(f): import time def wrap(*args, **kwargs): s = time.time() ret = f(*args, **kwargs) e = time.time() error_print(e - s, 'sec') return ret return wrap @mt def slv(S): N = len(S) @lru_cache(maxsize=None) def f(i, g): r = -sys.maxsize if i == N: return 0 if g > 0: r = max(r, f(i+1, g-1) + (1 if S[i] == 'g' else 0)) r = max(r, f(i+1, g+1) + (-1 if S[i] == 'p' else 0)) return r return f(0, 0) def main(): S = read_str() print(slv(S)) if __name__ == '__main__': main()
s452722024
p03965
u667024514
1523926506
Python
Python (3.4.3)
py
Runtime Error
17
2940
246
lis = list(input()) cou = 0 ans = 0 for i in range(len(lis)): if lis[i] == "g": if cou > 0: cou -= 1 ans += 1 else: cou += 1 else: if cou > 0: cou -= 1 else: cou += 1 ans -= 1 print(max(0,ans))
s538720672
p03965
u667024514
1523926410
Python
Python (3.4.3)
py
Runtime Error
18
3060
270
lis = list(input()) cou = 0 ans = 0 for i in range(len(lis)): if lis[i] == "g": if cou > 0: cou -= 1 ans += 1 else: cou += 1 else: if cou > 0: cou -= 1 else: cou += 1 ans -= 1 print(max(0,ans))
s798770939
p03965
u425351967
1507932902
Python
Python (3.4.3)
py
Runtime Error
30
3188
73
s = input() P = 0 for c in s: if c == 'p': P += 1 print(N//2 - P)
s158154969
p03965
u597792534
1479244068
Python
Python (3.4.3)
py
Runtime Error
118
4936
459
#coding:utf-8 def win(p,e): if p=="g" and e=="p": return -1 elif p=="p" and e=="g": return 1 else: return 0 def f(e_str,pt,gt,i): if len(e_str)<=i: return 0 if pt+1<=gt: point_p=f(e_str,pt+1,gt,i+1)+win("p",e_str[i]) else: point_p=-0xffff point_g=f(e_str,pt,gt+1,i+1)+win("g",e_str[i]) return max(point_p,point_g) e_str=list(input()) print(f(e_str,0,0,0))
s030921097
p03965
u752513456
1478461145
Python
Python (3.4.3)
py
Runtime Error
46
3316
154
# -*- coding: utf-8 -*- s = str(input()) n = len(s) dic = dict() for c in s: dic[c] = dic.get(c, 0) + 1 ans = (dic['g'] - dic['p']) // 2 print(ans)
s128300476
p03965
u752513456
1478461042
Python
Python (3.4.3)
py
Runtime Error
47
3316
230
# -*- coding: utf-8 -*- s = str(input()) n = len(s) G = 0 P = 0 dic = dict() for c in s: dic[c] = dic.get(c, 0) + 1 if n % 2 == 0: ans = (dic['g'] - dic['p']) / 2 else: ans = (dic['g'] - dic['p'] - 1) / 2 print(int(ans))
s547212334
p03965
u752513456
1478460548
Python
Python (3.4.3)
py
Runtime Error
48
3316
214
# -*- coding: utf-8 -*- s = str(input()) n = len(s) G = 0 P = 0 dic = dict() for c in s: dic[c] = dic.get(c, 0) + 1 if n % 2 == 0: ans = n / 2 - dic['p'] else: ans = (n - 1) / 2 - dic['p'] print(int(ans))
s328763122
p03965
u405509847
1478407291
Python
Python (3.4.3)
py
Runtime Error
23
3064
101
s=raw_input() p=0 for i in range(len(s)): if s[i] == 'p': p += 1 print (len(s)//2 - p)
s566921579
p03966
u706414019
1600687678
Python
Python (3.8.2)
py
Runtime Error
26
9240
715
import math N = int(input()) t= 1 a= 1 def t_small(t,a,t1,a1): gain = -(-t//t1) t = gain*t1 a_tmp=gain*a1 if a_tmp<a: gain_a = -(-a//a_tmp) t *= gain_a a = a_tmp*gain_a else: a = a_tmp return t,a,t+a def a_small(t,a,t1,a1): gain = -(-a//a1) a = gain*a1 t_tmp=gain*t1 if t_tmp<t: gain_t = -(-t//t_tmp) a *= gain_t t = t_tmp*gain_t else: t = t_tmp return t,a,t+a ans = 0 for _ in range(N): t1,a1 = map(int,input().split()) tt1,aa1,sta1 = t_small(t,a,t1,a1) tt2,aa2,sta2 = a_small(t,a,t1,a1) if sta1<=sta2: t=tt1;a=aa1,ans = sta1 else: t=tt2,a=aa2,ans=sta2 print(ans)
s792431864
p03966
u644907318
1594124917
Python
PyPy3 (7.3.0)
py
Runtime Error
98
74960
497
import math def f(x1,y1,x2,y2,z): a = gcd(x1,x2) z = max(z,math.ceil((x2+y2)*x1/x2)) x = x2+y2 n = z//x k = z%x if k==0: z = n*x x1 = (z*x2)//x y1 = (z*y2)//x return z,x1,y1 else: z = (n+1)*x x1 = (z*x2)//x y1 = (z*y2)//x return z,x1,y1 N = int(input()) A = [list(map(int,input().split())) for _ in range(N)] x1,y1 = A[0] s = x1+y1 for i in range(1,N): t,a = A[i] s,x1,y1 = f(x1,y1,t,a,s) print(s)
s774394862
p03966
u008229752
1590629231
Python
Python (3.4.3)
py
Runtime Error
17
2940
506
#include <iostream> using namespace std; using ex = int; #define ar(i,n) for(ex i=0;i<(n);++i) #define ebmr >> #define ebar << ex arsalmal = 1; ex main(){ ex albio ,ars = 0 ,almal = 0; cin ebmr albio; ar(i,albio){ ex eb, mr; cin ebmr eb ebmr mr; if(i==0){ ars = eb; almal = mr; } else{ ex exalbio = max((ars - arsalmal)/ eb + arsalmal,( almal - arsalmal) / mr + arsalmal); ars = eb * exalbio;almal = mr * exalbio; } } cout ebar ars + almal ebar endl; }
s824697964
p03966
u703950586
1589660574
Python
PyPy3 (2.4.0)
py
Runtime Error
185
40684
499
import sys,queue,math,copy,itertools,bisect,collections,heapq def main(): LI = lambda : [int(x) for x in sys.stdin.readline().split()] NI = lambda : int(sys.stdin.readline()) N = NI() b = [LI() for _ in range(N)] for i in range(1,N): if b[i][0] < b[i-1][0] or b[i][1] < b[i-1][1]: r = max(math.ceil([i-1][0]/b[i][0]),math.ceil([i-1][1]/b[i][1])) b[i][0] *= r b[i][1] *= r print(sum(b[-1])) if __name__ == '__main__': main()
s579799080
p03966
u210440747
1586053883
Python
Python (3.4.3)
py
Runtime Error
23
3064
407
#!/usr/bin/python3 # -*- coding:utf-8 -*- from math import ceil def main(): n = int(input()) for i in range(n): t, a = map(int, input().split()) if i == 0: nt, na = t, a continue cands = list(filter(lambda x: x[0] >= nt and x[1] >= na, [(ceil(nt/t)*t, ceil(nt/t)*a), (ceil(na/a)*t, ceil(na/a)*a)])) nt, na = min(cands) print(nt + na) if __name__=='__main__': main()
s345195653
p03966
u318042557
1573781354
Python
PyPy3 (2.4.0)
py
Runtime Error
178
38384
175
N = int(input()) T, A = map(int, input().split()) for i in range(N-1): t, a = map(int, input().split()) n = max(-(-T//t), -(-A//a)) T, A = n * t, n, * a print(T+A)
s038787239
p03966
u426108351
1563977530
Python
Python (3.4.3)
py
Runtime Error
18
3060
150
N = int(input()) x, y = 0 for i in range(N): a, b = map(int, input().split()) mul = max((x-1)//a+1, (y-1)//b+1) x = mul*a y = mul*b print(x+y)
s885441508
p03966
u585704797
1562451868
Python
Python (3.4.3)
py
Runtime Error
17
2940
643
N=int(input()) X=[] for i in range(N): a=input().split() X.append([int(a[0]),int(a[1])]) a=X[0][0] b=X[0][1] for i in range(1,N): c=X[i][0] d=X[i][1] x= (a + (c - 1)) // c y= (b + (d -1))) // d a1=1000000000000000000 b1=1000000000000000000 a2=1000000000000000000 b2=1000000000000000000 if d*x-b>=0: a1=c*x b1=d*x if c*y-a>=0: a2=c*y b2=d*y if (a1+b1)<(a2+b2): a=a1 b=b1 else: a=a2 b=b2 #print("i = "+str(i)+" a = "+str(a)+" b = "+str(b)+" a1 = "+str(a1)+" b1 = "+str(b1)+" a2 = "+str(a2)+" b2 = "+str(b2)+" c = "+str(c)+" d = "+str(d)) print(a+b)
s351355336
p03966
u585704797
1562450701
Python
Python (3.4.3)
py
Runtime Error
22
3188
496
N=int(input()) X=[] for i in range(N): a=input().split() X.append([int(a[0]),int(a[1])]) def ceil(x): if int(x)==x: return int(x) else: return int(x//1+1) a=X[0][0] b=X[0][1] for i in range(1,N): c=X[i][0] d=X[i][1] #print("i = "+str(i)+" a = "+str(a)+" b = "+str(b)+" c = "+str(c)+" d = "+str(d)) x=ceil(a/c) y=ceil(b/d) if d*x-b>=0: a=c*x b=d*x t=a+b if c*y-a>=0: if c*y+d*y<t: a=c*y b=d*y print(a+b)
s243828839
p03966
u585704797
1562450154
Python
Python (3.4.3)
py
Runtime Error
2104
4080
707
import sys sys.setrecursionlimit(100000) N=int(input()) X=[] for i in range(N): a=input().split() X.append([int(a[0]),int(a[1])]) def ceil(x): if int(x)==x: return int(x) else: return int(x//1+1) a=X[0][0] b=X[0][1] def f(a,b,i): c=X[i+1][0] d=X[i+1][1] x=ceil(a/c) y=ceil(b/d) ans=1000000000000 if i!=N-2: if c*y-a>=0: a=c*y b=d*y ans=min(ans,f(a,b,i+1)) if d*x-b>=0: z=f(c*x,d*x,i+1) if z<ans: a=c*x b=d*x ans=z elif i==N-2: if c*y-a>=0: a=c*y b=d*y ans=min(ans,a+b) if d*x-b>=0: a=c*x b=d*x ans=min(ans,a+b) return ans print(f(a,b,0))
s520746596
p03966
u585704797
1562449746
Python
Python (3.4.3)
py
Runtime Error
2103
4244
638
N=int(input()) X=[] for i in range(N): a=input().split() X.append([int(a[0]),int(a[1])]) def ceil(x): if int(x)==x: return int(x) else: return int(x//1+1) a=X[0][0] b=X[0][1] def f(a,b,i): c=X[i+1][0] d=X[i+1][1] x=ceil(a/c) y=ceil(b/d) ans=1000000000000 if i!=N-2: if c*y-a>=0: a=c*y b=d*y ans=min(ans,f(a,b,i+1)) if d*x-b>=0: a=c*x b=d*x ans=min(ans,f(a,b,i+1)) elif i==N-2: if c*y-a>=0: a=c*y b=d*y ans=min(ans,a+b) if d*x-b>=0: a=c*x b=d*x ans=min(ans,a+b) return ans print(f(a,b,0))
s279826494
p03966
u585704797
1562449585
Python
Python (3.4.3)
py
Runtime Error
2104
4240
685
N=int(input()) X=[] for i in range(N): a=input().split() X.append([int(a[0]),int(a[1])]) def ceil(x): if int(x)==x: return int(x) else: return int(x//1+1) a=X[0][0] b=X[0][1] def f(a,b,i): c=X[i+1][0] d=X[i+1][1] x=ceil(a/c) y=ceil(b/d) if i!=N-2: ans=100000000000 if c*y-a>=0: a=c*y b=d*y ans=min(ans,f(a,b,i+1)) if d*x-b>=0: a=c*x b=d*x ans=min(ans,f(a,b,i+1)) return ans elif i==N-2: ans=100000000 if c*y-a>=0: a=c*y b=d*y ans=min(ans,a+b) if d*x-b>=0: a=c*x b=d*x ans=min(ans,a+b) return ans print(f(a,b,0))
s683111277
p03966
u585704797
1562443352
Python
Python (3.4.3)
py
Runtime Error
20
3188
506
N=int(input()) X=[] for i in range(N): a=input().split() X.append([int(a[0]),int(a[1])]) def ceil(x): if int(x)==x: return int(x) else: return int(x//1+1) a=X[0][0] b=X[0][1] for i in range(1,N): c=X[i][0] d=X[i][1] a1=a*d/c if a1<b: y=math.ceil(a/c)*d-b else: y=math.ceil(a/c)*d-b while y<0: y+=d x=c*(b+y)//d-a #print("i = "+str(i)+" a = "+str(a)+" b = "+str(b)+" c = "+str(c)+" d = "+str(d)+" x = "+str(x)+" y = "+str(y)) a=a+x b=b+y print(a+b)
s897512496
p03966
u874212030
1562435644
Python
Python (3.4.3)
py
Runtime Error
17
2940
583
#include <bits/stdc++.h> using namespace std; const int N = 1005; int n, t, a; long long int ans = 0; long long int tWahl, aWahl; int main() { ios_base::sync_with_stdio(false); cin >> n; tWahl = aWahl = 0; for(int i = 0; i < n; i++) { cin >> t >> a; if(aWahl == 0 || aWahl % a != 0) { aWahl += a; aWahl -= (aWahl % a); } if(tWahl == 0 || tWahl % t != 0) { tWahl += t; tWahl -= (tWahl % t); } if(tWahl/t > aWahl/a) { aWahl = (tWahl/t)*a; } else if(tWahl/t < aWahl/a) { tWahl = (aWahl/a)*t; } } cout << aWahl + tWahl << endl; return 0; }
s544184017
p03966
u350997995
1560708705
Python
Python (3.4.3)
py
Runtime Error
17
3060
211
import math N = int(input()) for i in range(N): a,t = map(int,input().split()) if i == 0: x,y = a,t else: xa = math.ceil(x/a) yb = math.ceil(y/b) c = max(xa,yb) x,y = a*c,b*c print(x+b)
s409561844
p03966
u350997995
1560708647
Python
Python (3.4.3)
py
Runtime Error
17
2940
208
import math N = int(input()) for i range(N): a,t = map(int,input().split()) if i == 0: x,y = a,t else: xa = math.ceil(x/a) yb = math.ceil(y/b) c = max(xa,yb) x,y = a*c,b*c print(x+y)
s815306585
p03966
u350997995
1560708564
Python
Python (3.4.3)
py
Runtime Error
17
2940
208
import math N = int(input()) for i range(N): a,t = map(int,input().split()) if i == 0: x,y = a,t else: xa = math.ceil(x/a) yb = math.ceil(y/b) c = max(xa,yb) x,y = a*c,b*c print(x+b)
s401427231
p03966
u127844950
1556944614
Python
Python (3.4.3)
py
Runtime Error
18
3064
405
N = int(input()) lia=[int(it) for it in input().split()] lib=[int(it) for it in input().split()] lip=[lia[i]-lib[i] for i in range(N)] sb = 0 for i in range(N): if (lip[i]>0): sb+=lip[i] sa2 = 0 sas = 0 for i in range(N): if (lip[i]<0): sa2=(-lip[i])//2 sas+=(-lip[i]) sas-=sb*2 x = sum(lib)-sum(lia) if (sa2>=sb and sb+sas == x): print ("Yes") else: print ("No")
s945013552
p03966
u756388720
1556673812
Python
Python (3.4.3)
py
Runtime Error
21
3064
351
N = int(input()) T = [] A = [] for i in range(N): a, b = map(int, input().split()) T.append(a) A.append(b) t = T[0] a = A[0] for i in range(1, N): if t < T[i] and a < A[i]: t = t[i] a = A[i] else: x = int((t + T[i] - 1) / T[i]) y = int((a + A[i] - 1) / A[i]) t = T[i] * max(x, y) a = A[i] * max(x, y) print(t + a)
s938753035
p03966
u450339194
1554596075
Python
Python (3.4.3)
py
Runtime Error
78
4124
385
import math N = int(input()) ratios = [] for i in range(N): t, a = map(int, input().split()) ratios.append([t, a]) def min_vote(index): if index == N-1: return ratios[N-1-index] mt, ma = min_vote(index+1) t, a = ratios[N-1-index] min_ratio = max(math.ceil(mt / t), math.ceil(ma / a)) return [t * min_ratio, a * min_ratio] print(sum(min_vote(0)))
s500333441
p03966
u455696302
1553640097
Python
Python (3.4.3)
py
Runtime Error
37
5204
338
import math from decimal import * N = int(input()) _input = [] for i in range(N): _input.append(list(map(int,input().split()))) total_T = 1 total_A = 1 for t,a in _input: #n = max(math.ceil(total_T/t),math.ceil(total_A/a)) n = max(-(-t//Ti), -(-a//Ai)) total_T = int(t*n) total_A = int(a*n) print(total_A+total_T)
s594017679
p03966
u543954314
1552866245
Python
Python (3.4.3)
py
Runtime Error
18
2940
176
n = int(input()) ts, as = map(int, input().split()) for _ in range(n-1): t, a = map(int, input().split()) m = max((ts-1)//t, (as-1)//a)+1 ts = m*t as = m*a print(ts+as)
s787994241
p03966
u619819312
1548775148
Python
Python (3.4.3)
py
Runtime Error
17
2940
159
from math import gcd n=int(input()) a,b=map(int,input().split()) d=a+b for i in range(n-1): e,f=map(int,input().split()) d=d*(e+f)//gcd(d,e+f) print(d)
s535292322
p03966
u619819312
1548775130
Python
Python (3.4.3)
py
Runtime Error
19
3060
164
from itertools import gcd n=int(input()) a,b=map(int,input().split()) d=a+b for i in range(n-1): e,f=map(int,input().split()) d=d*(e+f)//gcd(d,e+f) print(d)
s621300780
p03966
u813102292
1548017568
Python
Python (3.4.3)
py
Runtime Error
17
3064
232
n = int(input()) t,a = [],[] for i in range(n): tmp = [int(i) for i in input().split()] t.append(tmp[0]) a.append(tmp[1]) p,q = 0,0 for zip(x,y) in t,a: tmp = max(p//x,q//y) p = x*tmp q = y*tmp print(p+q)
s423115519
p03966
u813102292
1548017516
Python
Python (3.4.3)
py
Runtime Error
20
3060
227
n = int(input()) t,a = [],[] for i in range(n): tmp = [int(i) for i in input().split()] t.append(tmp[0]) a.append(tmp[1]) p,q = 0,0 for x,y in t,a: tmp = max(p//x,q//y) p = x*tmp q = y*tmp print(p+q)
s365922089
p03966
u766407523
1526171875
Python
Python (3.4.3)
py
Runtime Error
19
3316
475
import math N = int(input()) ans = 2 tp, ap = 0, 0 for i in range(N):#ans以上での比からの最小値でans更新, #A+Tのn倍、ただしn>=ans/(t+a) t, a = map(int, input().split()) k = max(math.ceil(tp/t), math.ceil(ap/a)) t, a = t*k, a*k c = math.ceil(ans/(t+a)) while True:#ansが前回のans以上になるようにする if (t+a)*c >= ans: ans = (t+a)*c break c += 1 tp, ap = t*c, a*c print(ans)
s510276571
p03966
u319612498
1520731764
Python
Python (3.4.3)
py
Runtime Error
36
5332
214
from math import ceil from decimal import * n=int(input()) prea=1.0 pret=1.0 for i in range(n): t,a=map(Decimal,input().split()) i=max(ceil(prea/a),ceil(pret/t)) pret,prea=t*i,a*i print(pret+prea)
s330394251
p03966
u066394624
1490753383
Python
Python (3.4.3)
py
Runtime Error
18
3064
1323
# -*- coding: utf-8 -*- import itertools n = input() input_lines = list(input()) pairs = [input_line.split(' ') for input_line in input_lines] t_i = [pair[0] for pair in pairs] a_i = [pair[1] for pair in pairs] def satisfy_conditions(total_votes): votes_t_i = total_votes * a_i[-i] votes_a_i = total_votes * t_i[-i] for i in range(1, n+1): constraint = (votes_t_i, votes_a_i) possible_combination = is_possible(constraint, a_i[-i], t_i[-i]) if possible_combination is None: return False else: votes_t_i = possible_combination[0] votes_a_i = possible_combination[1] return True def is_possible(constraint, t_i, a_i): votes_t_i_plus_1 = constraint[0] votes_a_i_plus_1 = constraint[1] combinations = list(itertools.product(list(range(1, votes_t_i_plus_1 + 1)), list(range(1, votes_a_i_plus_1 + 1)))) combinations.reverse() for combination in combinations: if combination[0] / combination[1] == t_i / a_i: return (combination[0], combination[1]) return None max_iter = 1000000 answer = None unit = t_i[-1] + a_i[-1] for k in range(1, max_iter): if satisfy_conditions(unit * k): answer = unit * k break print(answer)
s878220096
p03966
u104282757
1476660548
Python
PyPy2 (5.6.0)
py
Runtime Error
65
10480
3580
# X2 # X1 X0 X4 X5 # X3 # # C0 C1 # X0 # C3 C2 # # C1 C0 # 5X # C2 C3 # N = int(raw_input()) # N = 6 # N = 8 C_list = [] for n in range(N): C_list.append(map(int, raw_input().split())) """ C_list = [ [0, 1, 2, 3], [0, 4, 6, 1], [1, 6, 7, 2], [2, 7, 5, 3], [6, 4, 5, 7], [4, 0, 3, 5] ] C_list = [ [0, 0, 0, 0], [0, 0, 1, 1], [0, 1, 0, 1], [0, 1, 1, 0], [1, 0, 0, 1], [1, 0, 1, 0], [1, 1, 0, 0], [1, 1, 1, 1] ] C_list = [ [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0] ] """ res = 0 def rotate(A, n): if n == 0: return A elif n == 1: return [A[1], A[2], A[3], A[0]] elif n == 2: return [A[2], A[3], A[0], A[1]] elif n == 3: return [A[3], A[0], A[1], A[2]] C_list_1 = [rotate(C, 1) for C in C_list] C_list_2 = [rotate(C, 2) for C in C_list] C_list_3 = [rotate(C, 3) for C in C_list] for i in range(N-1): X0_ = C_list[i] for j in range(i+1, N): X5 = [C_list[j][1], C_list[j][0], C_list[j][3], C_list[j][2]] for k in range(4): X0 = rotate(X0_, k) X1 = [X5[0], X5[1], X0[1], X0[0]] X2 = [X5[1], X5[2], X0[2], X0[1]] X3 = [X5[2], X5[3], X0[3], X0[2]] X4 = [X5[3], X5[0], X0[0], X0[3]] # drop duplicate c1 = 0 c2 = 0 c3 = 0 c4 = 0 if X2 in [rotate(X1, l) for l in range(4)]: c2 += 1 if X3 in [rotate(X1, l) for l in range(4)]: c3 += 1 if X3 in [rotate(X2, l) for l in range(4)]: c3 += 1 if X4 in [rotate(X1, l) for l in range(4)]: c4 += 1 if X4 in [rotate(X2, l) for l in range(4)]: c4 += 1 if X4 in [rotate(X3, l) for l in range(4)]: c4 += 1 # count how many fits r1 = 0 r1 += max(sum([C_list[m] == X1 for m in range(i+1, N) if m != j]) - c1, 0) r1 += max(sum([C_list_1[m] == X1 for m in range(i+1, N) if m != j]) - c1, 0) r1 += max(sum([C_list_2[m] == X1 for m in range(i+1, N) if m != j]) - c1, 0) r1 += max(sum([C_list_3[m] == X1 for m in range(i+1, N) if m != j]) - c1, 0) r2 = 0 r2 += max(sum([C_list[m] == X2 for m in range(i+1, N) if m != j]) - c2, 0) r2 += max(sum([C_list_1[m] == X2 for m in range(i+1, N) if m != j]) - c2, 0) r2 += max(sum([C_list_2[m] == X2 for m in range(i+1, N) if m != j]) - c2, 0) r2 += max(sum([C_list_3[m] == X2 for m in range(i+1, N) if m != j]) - c2, 0) r3 = 0 r3 += max(sum([C_list[m] == X3 for m in range(i+1, N) if m != j]) - c3, 0) r3 += max(sum([C_list_1[m] == X3 for m in range(i+1, N) if m != j]) - c3, 0) r3 += max(sum([C_list_2[m] == X3 for m in range(i+1, N) if m != j]) - c3, 0) r3 += max(sum([C_list_3[m] == X3 for m in range(i+1, N) if m != j]) - c3, 0) r4 = 0 r4 += max(sum([C_list[m] == X4 for m in range(i+1, N) if m != j]) - c4, 0) r4 += max(sum([C_list_1[m] == X4 for m in range(i+1, N) if m != j]) - c4, 0) r4 += max(sum([C_list_2[m] == X4 for m in range(i+1, N) if m != j]) - c4, 0) r4 += max(sum([C_list_3[m] == X4 for m in range(i+1, N) if m != j]) - c4, 0) res += r1*r2*r3*r4 print res
s936748404
p03967
u792078574
1601340935
Python
Python (3.8.2)
py
Runtime Error
26
8892
49
s=input() print((s.count("g")-s.count("p"))//2)
s601349693
p03967
u046158516
1592467093
Python
PyPy3 (2.4.0)
py
Runtime Error
168
39152
94
s=input() counter=0 for i in range(n): if s[i]=='p': counter+=1 print(len(s)//2-counter)
s223734959
p03967
u780475861
1589836210
Python
Python (3.4.3)
py
Runtime Error
26
4860
779
s = input() grid = [0 if i == 'g' else 1 for i in s] def biggest(grid): dist = [float('-inf')] * len(s) move = (0, 1) st = deque([[0, 0, 0, 0]]) while st: g, p, idx, cur = st.popleft() if idx > len(s) - 1: continue for a in move: if a: if p + 1 > g: continue tmpg, tmpp = g, p + 1 else: tmpg, tmpp = g + 1, p if a > grid[idx]: tmp = cur + 1 elif a < grid[idx]: tmp = cur - 1 else: tmp = cur if dist[idx] < tmp: dist[idx] = tmp st.append([tmpg, tmpp, idx + 1, tmp]) return dist[-1] print(biggest(grid))
s579124344
p03967
u946996108
1586335176
Python
PyPy3 (2.4.0)
py
Runtime Error
175
41452
6804
mod = 10 ** 9 + 7 mod2 = 2 ** 61 + 1 from collections import deque import heapq import time from bisect import bisect_left, insort_left, bisect_right import sys input = sys.stdin.readline _NUMINT_ALL = list(range(10)) def main(): ans = solve() if ans is True or ans is False: YesNo(ans) elif ans is not None: print(ans) def solve(): s = iip() d = count_elements(s) #print(d) a = d["g"] b = d["p"] p_saizente = (a+b) // 2 diff = (a+b) // 2 -p_saizente print(diff // 2) #####################################################ライブラリ集ここから def kiriage_warizan(a, b): return -(-a//b) def iip(listed=True): # 数字のinputをlistで受け取る d = input().rstrip("\n").split() try: ret = [int(i) for i in d] except: ret = [int(i) if i in _NUMINT_ALL else i for i in d] if len(ret) == 1: return ret[0] if len(ret) == 1 and not listed: return ret[0] return ret def iipt(l, listed=False, num_only=True): # 縦向きに並んでいるデータをリストに落とし込む(iip利用) ret = [] for i in range(l): ret.append(iip(listed=listed)) return ret def saidai_kouyakusuu(A): # 最大公約数 l = len(A) while True: m = min(A) mx = max(A) if m == mx: return m for i in range(l): if A[i] % m == 0: A[i] = m else: A[i] %= m def make_graph_edge_flat(N): # グラフ作成のための辺をリストで返す ret = [] for i in range(N-1): a, b, c = iip() a -= 1 b -= 1 ret[a].append((b, c)) ret[b].append((a, c)) return ret def sort_tuples(l, index): # タプルのリストを特定のインデックスでソートする if isinstance(l, list): l.sort(key=lambda x: x[index]) return l else: l = list(l) return sorted(l, key=lambda x: x[index]) def count_elements(l): # リストの中身の個数を種類分けして辞書で返す d = {} for i in l: if i in d: d[i] += 1 else: d[i] = 1 return d def safeget(l, index, default="exception"): # listの中身を取り出す時、listからはみ出たり if index >= len(l): # マイナスインデックスになったりするのを防ぐ if default == "exception": raise Exception("".join(["safegetに不正な値 ", index, "が渡されました。配列の長さは", len(l), "です"])) else: return default elif index < 0: if default == "exception": raise Exception("".join(["safegetに不正な値 ", index, "が渡されました。負の値は許可されていません"])) else: return default else: return l[index] def sortstr(s): # 文字列をソートする return "".join(sorted(s)) def iip_ord(startcode="a"): # 文字列を数字の列に変換する(数字と文字は1:1対応) if isinstance(startcode, str): startcode = ord(startcode) return [ord(i) - startcode for i in input()] def YesNo(s): # TrueFalseや1, 0をYesNoに変換する if s: print("Yes") else: print("No") def fprint(s): # リストを平たくしてprintする(二次元リストを見やすくしたりとか) for i in s: print(i) def bitall(N): # ビット全探索用のインデックスを出力 ret = [] for i in range(2 ** N): a = [] for j in range(N): a.append(i % 2) i //= 2 ret.append(a) return ret def split_print_space(s): # リストの中身をスペース区切りで出力する print(" ".join([str(i) for i in s])) def split_print_enter(s): # リストの中身を改行区切りで出力する print("\n".join([str(i) for i in s])) def soinsuu_bunkai(n): # 素因数分解 ret = [] for i in range(2, int(n ** 0.5) + 1): while n % i == 0: n //= i ret.append(i) if i > n: break if n != 1: ret.append(n) return ret def conbination(n, r, mod, test=False): # nCrをmodを使って計算する if n <= 0: return 0 if r == 0: return 1 if r < 0: return 0 if r == 1: return n ret = 1 for i in range(n - r + 1, n + 1): ret *= i ret = ret % mod bunbo = 1 for i in range(1, r + 1): bunbo *= i bunbo = bunbo % mod ret = (ret * inv(bunbo, mod)) % mod if test: # print(f"{n}C{r} = {ret}") pass return ret def inv(n, mod): # modnにおける逆元を計算 return power(n, mod - 2) def power(n, p, mod_=mod): # 繰り返し二乗法でn**p % modを計算 if p == 0: return 1 if p % 2 == 0: return (power(n, p // 2, mod_) ** 2) % mod_ if p % 2 == 1: return (n * power(n, p - 1, mod_)) % mod_ def nibutan_func(func, target, left, right, side="left"): # 関数を二分探索 l = left r = right x = (l + r) // 2 while r-l > 1: x = (l+r)//2 if func(x) == target: return x elif func(x) > target: r = x else: l = x if side == "left" or func(x) == target: return l else: return r def nibutan_list(list_, target, side="left"): # リストを二分探索 if not isinstance(list_, list): list_ = list(list_) l = 0 r = len(list_) x = (l + r) // 2 while r-l > 1: x = (l+r)//2 if list_[x] == target: return x elif list_[x] > target: r = x else: l = x if side == "left" or list_[x] == target: return l else: return r class UfTree(): def __init__(self, maxnum): self.parent = list(range(maxnum)) self._size = [1] * maxnum self.rank = [0] * maxnum def size(self, a): return self._size[self.root(a)] def root(self, a): rank = 0 cur = a while True: if self.parent[cur] == cur: #for i in path: # 経路圧縮 # self.parent[i] = cur return cur else: self.parent[cur] = self.parent[self.parent[cur]] cur = self.parent[cur] rank += 1 def unite(self, a, b): ra = self.root(a) rb = self.root(b) if ra == rb: return self self._size[ra] += self._size[rb] self.parent[rb] = ra return self if __name__ == "__main__": main()
s986511357
p03967
u102960641
1574808846
Python
Python (3.4.3)
py
Runtime Error
17
3188
63
s = input() t_s = n.count("p") a_s = len(s) // 2 print(a_s-t_s)
s077486261
p03967
u937642029
1574266696
Python
PyPy3 (2.4.0)
py
Runtime Error
189
38636
1362
from collections import Counter,defaultdict,deque import sys import bisect import math import itertools import queue import copy import numpy as np from heapq import heappop, heappush sys.setrecursionlimit(10**8) mod = 10**9+7 def inp(): # n=1 return int(input()) def inpm(): # x=1,y=2 return map(int,input().split()) def inpl(): # a=[1,2,3,4,5,...,n] return list(map(int, input().split())) def inpls(): # a=['1','2','3',...,'n'] return list(input().split()) def inplm(n): # x=[] 複数行 return list(int(input()) for _ in range(n)) def inpll(n): # [[1,1,1,1],[2,2,2,2],[3,3,3,3]] return sorted([list(map(int, input().split())) for _ in range(n)]) def sortx(x,n,k): if k == 0:x.sort(key=lambda y:y[1,n]) else:x.sort(reversed=True, key=lambda y:y[1,n]) def main(): s = input() NG = 1 NP = 0 did = ["g"] point = 0 for i in range(1,len(s)): if s[i] == "g": if NP + 1 <= NG: did.append("p") NP += 1 point += 1 else: did.append("g") NG += 1 else: if NP + 1 <= NG: did.append("p") NP += 1 else: did.append("g") NG += 1 point -= 1 print(point) if __name__ == "__main__": main()
s865953711
p03967
u937642029
1574266586
Python
PyPy3 (2.4.0)
py
Runtime Error
186
38792
1389
from collections import Counter,defaultdict,deque import sys import bisect import math import itertools import queue import copy import numpy as np from heapq import heappop, heappush input = sys.stdin.readline sys.setrecursionlimit(10**8) mod = 10**9+7 def inp(): # n=1 return int(input()) def inpm(): # x=1,y=2 return map(int,input().split()) def inpl(): # a=[1,2,3,4,5,...,n] return list(map(int, input().split())) def inpls(): # a=['1','2','3',...,'n'] return list(input().split()) def inplm(n): # x=[] 複数行 return list(int(input()) for _ in range(n)) def inpll(n): # [[1,1,1,1],[2,2,2,2],[3,3,3,3]] return sorted([list(map(int, input().split())) for _ in range(n)]) def sortx(x,n,k): if k == 0:x.sort(key=lambda y:y[1,n]) else:x.sort(reversed=True, key=lambda y:y[1,n]) def main(): s = input() NG = 1 NP = 0 did = ["g"] point = 0 for i in range(1,len(s)): if s[i] == "g": if NP + 1 <= NG: did.append("p") NP += 1 point += 1 else: did.append("g") NG += 1 else: if NP + 1 <= NG: did.append("p") NP += 1 else: did.append("g") NG += 1 point -= 1 print(point) if __name__ == "__main__": main()